@zjw-jszn/platform-imsdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Platform IMSDK
2
+
3
+ 平台 SDK(基于共用内核 `@zjw-jszn/shared-imsdk`):
4
+
5
+ - API 前缀:`/site/IM`
6
+ - WebSocket controller:`Site`
7
+ - WebSocket platform:`site`
8
+ - 能力范围:基础会话能力 + 平台扩展接口(结束会话、客服会话、会话配置、AI 配置)
9
+ 平台 API 文档:`docs/API/平台.md`
10
+
11
+ 安装:
12
+
13
+ ```bash
14
+ pnpm add @zjw-jszn/platform-imsdk
15
+ ```
16
+
17
+ 使用:
18
+
19
+ ```ts
20
+ import { IMSDK } from '@zjw-jszn/platform-imsdk'
21
+
22
+ IMSDK.init({
23
+ phone: '18888888888', // 当前测试约定值(平台)
24
+ })
25
+ ```
26
+
27
+ 说明:
28
+
29
+ - 平台端 `getAuthorization.phone` 需使用 `im-backend-web`「系统设置/管理员管理(system/admin)」中的管理员手机号。
30
+ - 上述示例值仅为当前联调值(2026-03-24);若后台管理员手机号变更需同步更新。
@@ -0,0 +1,16 @@
1
+ import { IMSDKConfig as SharedIMSDKConfig, getUserInfo } from '@zjw-jszn/shared-imsdk';
2
+ export type { PlatformChatConfig, PlatformCloseSessionParams, PlatformPageResponse, PlatformSession } from './runtime-api';
3
+ export { closeSession, getChatConfig, getCustomerChatList } from './runtime-api';
4
+ export * from '@zjw-jszn/shared-imsdk';
5
+ export interface IMSDKConfig extends SharedIMSDKConfig {
6
+ }
7
+ export declare function initIM(config?: IMSDKConfig): Promise<{
8
+ show: () => void;
9
+ hide: () => void;
10
+ }>;
11
+ declare const IMSDK: {
12
+ init: typeof initIM;
13
+ getUserInfo: typeof getUserInfo;
14
+ };
15
+ export default IMSDK;
16
+ export { IMSDK };
@@ -0,0 +1,67 @@
1
+ import { IMSDK as e, applyModeDefaults as t, getUserInfo as n, http as r, initIM as i, warnModeOverrides as a } from "@zjw-jszn/shared-imsdk";
2
+ export * from "@zjw-jszn/shared-imsdk";
3
+ //#region src/runtime-api.ts
4
+ var o = "/site/IM";
5
+ function s(e) {
6
+ return `${o}${e.startsWith("/") ? e : `/${e}`}`;
7
+ }
8
+ function c(e) {
9
+ if (!r.getAuth()) throw Error(`未登录,禁止请求 ${e},请先完成鉴权`);
10
+ }
11
+ function l(e, t) {
12
+ if (e.result === void 0 || e.result === null) throw Error(`${t} 接口返回 result 为空`);
13
+ return e.result;
14
+ }
15
+ async function u() {
16
+ return c("getChatConfig"), l(await r.post(s("/chatConfig/getConfig")), "getChatConfig");
17
+ }
18
+ async function d(e) {
19
+ c("closeSession");
20
+ let t = e.uid !== void 0 && e.uid !== null, n = e.session_id !== void 0 && e.session_id !== null;
21
+ if (!t && !n) throw Error("结束会话失败:uid 和 session_id 不能同时为空");
22
+ let i = t ? { uid: e.uid } : { session_id: e.session_id };
23
+ return await r.post(s("/chat/closeSession"), i), !0;
24
+ }
25
+ async function f(e) {
26
+ return c("getCustomerChatList"), l(await r.post(s("/customer/getChatList"), e), "getCustomerChatList");
27
+ }
28
+ //#endregion
29
+ //#region src/index.ts
30
+ var p = {
31
+ api: {
32
+ prefix: "/site/IM",
33
+ userType: 4
34
+ },
35
+ ws: {
36
+ controller: "Site",
37
+ platform: "site"
38
+ }
39
+ };
40
+ function m(e) {
41
+ a("platform-imsdk", e, p);
42
+ let t = e.runtimeApi;
43
+ (t?.getChatConfig || t?.closeSession || t?.getCustomerChatList) && console.warn("[platform-imsdk] 已忽略 runtimeApi 的平台扩展覆盖配置,平台扩展接口由内置实现提供");
44
+ }
45
+ function h(e = {}) {
46
+ m(e);
47
+ let n = e;
48
+ return {
49
+ ...t(e, p),
50
+ runtimeApi: {
51
+ ...n.runtimeApi || {},
52
+ getChatConfig: u,
53
+ closeSession: d,
54
+ getCustomerChatList: f
55
+ }
56
+ };
57
+ }
58
+ async function g(e = {}) {
59
+ return i(h(e));
60
+ }
61
+ var _ = {
62
+ ...e,
63
+ init: g,
64
+ getUserInfo: n
65
+ };
66
+ //#endregion
67
+ export { _ as IMSDK, _ as default, d as closeSession, u as getChatConfig, f as getCustomerChatList, g as initIM };
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@zjw-jszn/shared-imsdk`)):typeof define==`function`&&define.amd?define([`exports`,`@zjw-jszn/shared-imsdk`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.PlatformIMSDK={},e.SharedIMSDK))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=`/site/IM`;function r(e){return`${n}${e.startsWith(`/`)?e:`/${e}`}`}function i(e){if(!t.http.getAuth())throw Error(`未登录,禁止请求 ${e},请先完成鉴权`)}function a(e,t){if(e.result===void 0||e.result===null)throw Error(`${t} 接口返回 result 为空`);return e.result}async function o(){return i(`getChatConfig`),a(await t.http.post(r(`/chatConfig/getConfig`)),`getChatConfig`)}async function s(e){i(`closeSession`);let n=e.uid!==void 0&&e.uid!==null,a=e.session_id!==void 0&&e.session_id!==null;if(!n&&!a)throw Error(`结束会话失败:uid 和 session_id 不能同时为空`);let o=n?{uid:e.uid}:{session_id:e.session_id};return await t.http.post(r(`/chat/closeSession`),o),!0}async function c(e){return i(`getCustomerChatList`),a(await t.http.post(r(`/customer/getChatList`),e),`getCustomerChatList`)}var l={api:{prefix:`/site/IM`,userType:4},ws:{controller:`Site`,platform:`site`}};function u(e){(0,t.warnModeOverrides)(`platform-imsdk`,e,l);let n=e.runtimeApi;(n?.getChatConfig||n?.closeSession||n?.getCustomerChatList)&&console.warn(`[platform-imsdk] 已忽略 runtimeApi 的平台扩展覆盖配置,平台扩展接口由内置实现提供`)}function d(e={}){u(e);let n=e;return{...(0,t.applyModeDefaults)(e,l),runtimeApi:{...n.runtimeApi||{},getChatConfig:o,closeSession:s,getCustomerChatList:c}}}async function f(e={}){return(0,t.initIM)(d(e))}var p={...t.IMSDK,init:f,getUserInfo:t.getUserInfo};e.IMSDK=p,e.default=p,e.closeSession=s,e.getChatConfig=o,e.getCustomerChatList=c,e.initIM=f,Object.keys(t).forEach(function(n){n!==`default`&&!Object.prototype.hasOwnProperty.call(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})});
@@ -0,0 +1,39 @@
1
+ export interface PlatformChatConfig {
2
+ quick_receive?: string[] | string;
3
+ default_voice?: string;
4
+ }
5
+ export interface PlatformCloseSessionParams {
6
+ uid?: number;
7
+ session_id?: string;
8
+ }
9
+ export interface PlatformPageResponse<T> {
10
+ list: T[];
11
+ count: number;
12
+ }
13
+ export interface PlatformSession {
14
+ session_id: string;
15
+ friend: Record<string, unknown>;
16
+ friend_type: number;
17
+ user: Record<string, unknown>;
18
+ user_type: number;
19
+ content: string;
20
+ create_time: string;
21
+ count: number;
22
+ read_count: number;
23
+ }
24
+ /**
25
+ * 获取会话配置(平台扩展)
26
+ */
27
+ export declare function getChatConfig(): Promise<PlatformChatConfig>;
28
+ /**
29
+ * 结束会话并清理缓存(平台扩展)
30
+ */
31
+ export declare function closeSession(data: PlatformCloseSessionParams): Promise<boolean>;
32
+ /**
33
+ * 获取客服会话聊天列表(平台扩展)
34
+ */
35
+ export declare function getCustomerChatList(data: {
36
+ page: number;
37
+ limit: number;
38
+ phone?: string;
39
+ }): Promise<PlatformPageResponse<PlatformSession>>;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@zjw-jszn/platform-imsdk",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "exports": {
6
+ ".": {
7
+ "types": {
8
+ "development": "./src/index.ts",
9
+ "default": "./dist/index.d.ts"
10
+ },
11
+ "import": {
12
+ "development": "./src/index.ts",
13
+ "default": "./dist/platform-imsdk.es.js"
14
+ }
15
+ },
16
+ "./style.css": "./style.css"
17
+ },
18
+ "types": "./dist/index.d.ts",
19
+ "files": [
20
+ "dist",
21
+ "style.css"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public",
25
+ "registry": "https://registry.npmjs.org/"
26
+ },
27
+ "dependencies": {
28
+ "@zjw-jszn/shared-imsdk": "1.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "~5.9.3",
32
+ "vite": "^8.0.1",
33
+ "vite-plugin-dts": "^4.5.4",
34
+ "vue-tsc": "^3.2.5"
35
+ },
36
+ "scripts": {
37
+ "typecheck": "vue-tsc --noEmit",
38
+ "build": "vue-tsc && vite build"
39
+ }
40
+ }
package/style.css ADDED
@@ -0,0 +1 @@
1
+ @import '@zjw-jszn/shared-imsdk/style.css';