fix(ImClient): make sendSync/scheduleReconnect safe when SDK not initialized

ImClient.sendSync() called getConfig() which throws when init() hasn't been
called, breaking headless usage (e.g. platform event listeners). Now wraps
the call in a try-catch and skips the sync frame if appKey is unavailable.
Same fix for scheduleReconnect's debug log.

Also: add vite-plugin-dts to generate TypeScript declarations on every build,
fixing the missing dist/index.d.ts that broke IDE type resolution. Bump to 0.2.3.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
XuqmGroup 2026-05-16 14:12:47 +08:00
父节点 a68550e576
当前提交 df7557b77f
共有 3 个文件被更改,包括 8 次插入4 次删除

查看文件

@ -1,6 +1,6 @@
{
"name": "@xuqm/vue3-sdk",
"version": "0.2.2",
"version": "0.2.3",
"description": "XuqmGroup Vue3 SDK — IM & platform integration for web",
"private": false,
"publishConfig": {
@ -21,7 +21,7 @@
],
"scripts": {
"dev": "vite build --watch",
"build": "tsc --emitDeclarationOnly && vite build",
"build": "vite build",
"type-check": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",

查看文件

@ -227,7 +227,8 @@ export class ImClient {
private sendSync(): void {
if (this.ws?.readyState !== WebSocket.OPEN) return
const config = getConfig()
const config = (() => { try { return getConfig() } catch { return null } })()
if (!config?.appKey) return
this.ws.send(
buildStompFrame(
'SEND',
@ -261,7 +262,8 @@ export class ImClient {
private scheduleReconnect(): void {
if (this.destroyed) return
if (getConfig().debug) {
const debug = (() => { try { return getConfig().debug } catch { return false } })()
if (debug) {
console.log(`[ImClient] reconnect in ${this.reconnectDelay}ms`)
}
this.reconnectTimer = setTimeout(() => {

查看文件

@ -1,10 +1,12 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import dts from 'vite-plugin-dts'
import { resolve } from 'path'
export default defineConfig({
plugins: [
vue(),
dts({ include: ['src'], insertTypesEntry: true }),
],
build: {
lib: {