From 3c7ae4d7669b3f87ead7d744256d62c17f6b4b03 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Sat, 2 May 2026 11:29:50 +0800 Subject: [PATCH] =?UTF-8?q?docs(deploy):=20=E6=B7=BB=E5=8A=A0=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=96=87=E6=A1=A3=E5=B9=B6=E6=9B=B4=E6=96=B0SDK=20API?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增完整的XuqmGroup部署文档,包含服务器配置、Docker Compose部署策略 - 更新SDK API重设计规范至V2.0,统一各端SDK初始化和登录接口 - 添加安全设计规范文档,涵盖密码安全、AppSecret验证等内容 - 新增离线推送架构设计文档,定义厂商推送集成方案 - 重构SDK登录流程,统一使用userId + userSig鉴权模式 - 移除dbName等外部配置参数,实现零感知平台地址配置 - 完善部署架构图和配置示例文件 --- README.md | 4 +-- packages/im/src/ImSDK.ts | 51 ++++----------------------------------- packages/im/src/upload.ts | 2 +- src/sdk.ts | 2 +- 4 files changed, 9 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 260ab8e..3222f8f 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ yarn add @xuqm/rn-common @xuqm/rn-im @xuqm/rn-push @xuqm/rn-update ## 入口 -- `XuqmSDK.initialize({ appKey, debug })` -- `XuqmSDK.login({ userId, userSig, profile, expiresAt, refreshUserSig })` +- `XuqmSDK.initialize({ appKey, logLevel })` +- `XuqmSDK.login({ userId, userSig })` - `XuqmSDK.logout()` - `ImSDK` - `PushSDK` diff --git a/packages/im/src/ImSDK.ts b/packages/im/src/ImSDK.ts index 80caf9d..cefae04 100644 --- a/packages/im/src/ImSDK.ts +++ b/packages/im/src/ImSDK.ts @@ -283,33 +283,18 @@ function resolveMimeTypeFromUri(uri: string, fallback: string): string { export const ImSDK = { /** - * Login to IM service. Fetches a token internally and opens the WebSocket connection. - * Pass dbName to enable local SQLite message caching (requires @nozbe/watermelondb). + * Login to IM service with a pre-obtained userSig and open the WebSocket connection. */ - async login(userId: string, dbName?: string): Promise { + async login(userId: string, userSig: string): Promise { const config = getConfig() - const device = await getDeviceInfo() client?.disconnect() - const res = await apiRequest<{ token: string }>('/api/im/auth/login', { - method: 'POST', - skipAuth: true, - params: { - appId: config.appId, - userId, - deviceId: device.deviceId, - platform: device.platform, - brand: device.brand, - model: device.model, - osVersion: device.osVersion, - }, - }) - await _saveToken(res.token) + await _saveToken(userSig) _currentUserId = userId setCommonUserId(userId) - ImDatabase.init(dbName ?? buildDbName(config.appKey, userId)) + ImDatabase.init(buildDbName(config.appKey, userId)) - client = new ImClient(config.imWsUrl, res.token, config.appId) + client = new ImClient(config.imWsUrl, userSig, config.appId) client.addListener({ onConnected: () => { _syncHistoryForAllConversations().catch(() => {}) @@ -318,32 +303,6 @@ export const ImSDK = { void client.connect() }, - /** - * Login with a pre-obtained IM token (e.g. from demo-service). - * Sets up the IM connection without calling the auth endpoint. - */ - async loginWithToken(userId: string, token: string, dbName?: string): Promise { - const config = getConfig() - client?.disconnect() - await _saveToken(token) - _currentUserId = userId - setCommonUserId(userId) - - ImDatabase.init(dbName ?? buildDbName(config.appKey, userId)) - - client = new ImClient(config.imWsUrl, token, config.appId) - client.addListener({ - onConnected: () => { - _syncHistoryForAllConversations().catch(() => {}) - }, - }) - void client.connect() - }, - - async loginWithUserSig(userId: string, userSig: string, dbName?: string): Promise { - return ImSDK.loginWithToken(userId, userSig, dbName) - }, - async reconnect(): Promise { const config = getConfig() const token = await _getToken() diff --git a/packages/im/src/upload.ts b/packages/im/src/upload.ts index f59a85c..8160644 100644 --- a/packages/im/src/upload.ts +++ b/packages/im/src/upload.ts @@ -24,7 +24,7 @@ export async function uploadFile( const config = getConfig() const token = await _getToken() if (!token) { - throw new Error('[uploadFile] No active session — call ImSDK.loginWithToken() first.') + throw new Error('[uploadFile] No active session — call XuqmSDK.login() first.') } const form = new FormData() diff --git a/src/sdk.ts b/src/sdk.ts index dad5230..b341d07 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -12,7 +12,7 @@ let currentSession: UnifiedLoginOptions | null = null async function applyLoginSession(session: UnifiedLoginOptions): Promise { setCommonUserId(session.userId) try { - await ImSDK.loginWithUserSig(session.userId, session.userSig) + await ImSDK.login(session.userId, session.userSig) } catch (error) { setCommonUserId(null) currentSession = null