From df7557b77f0725da0f0e1a12223e052d6d8367f1 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sat, 16 May 2026 14:12:47 +0800 Subject: [PATCH] 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 --- package.json | 4 ++-- src/im/ImClient.ts | 6 ++++-- vite.config.ts | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index df773d0..7f2c5f0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/im/ImClient.ts b/src/im/ImClient.ts index da9af0a..aa58283 100644 --- a/src/im/ImClient.ts +++ b/src/im/ImClient.ts @@ -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(() => { diff --git a/vite.config.ts b/vite.config.ts index 4b31f9e..bc859d9 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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: {