@koushuang/im 0.1.1-preview.3

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.
Files changed (200) hide show
  1. package/dist/_virtual/_plugin-vue_export-helper.cjs +2 -0
  2. package/dist/_virtual/_plugin-vue_export-helper.cjs.map +1 -0
  3. package/dist/_virtual/_plugin-vue_export-helper.mjs +10 -0
  4. package/dist/_virtual/_plugin-vue_export-helper.mjs.map +1 -0
  5. package/dist/api/auth.cjs +2 -0
  6. package/dist/api/auth.cjs.map +1 -0
  7. package/dist/api/auth.d.ts +48 -0
  8. package/dist/api/auth.mjs +30 -0
  9. package/dist/api/auth.mjs.map +1 -0
  10. package/dist/core/client.cjs +2 -0
  11. package/dist/core/client.cjs.map +1 -0
  12. package/dist/core/client.d.ts +38 -0
  13. package/dist/core/client.mjs +117 -0
  14. package/dist/core/client.mjs.map +1 -0
  15. package/dist/core/createClient.cjs +2 -0
  16. package/dist/core/createClient.cjs.map +1 -0
  17. package/dist/core/createClient.d.ts +6 -0
  18. package/dist/core/createClient.mjs +9 -0
  19. package/dist/core/createClient.mjs.map +1 -0
  20. package/dist/core/events.d.ts +36 -0
  21. package/dist/core/index.d.ts +4 -0
  22. package/dist/core/types.d.ts +127 -0
  23. package/dist/http/createHttp.cjs +2 -0
  24. package/dist/http/createHttp.cjs.map +1 -0
  25. package/dist/http/createHttp.d.ts +5 -0
  26. package/dist/http/createHttp.mjs +29 -0
  27. package/dist/http/createHttp.mjs.map +1 -0
  28. package/dist/http/types.cjs +2 -0
  29. package/dist/http/types.cjs.map +1 -0
  30. package/dist/http/types.d.ts +14 -0
  31. package/dist/http/types.mjs +9 -0
  32. package/dist/http/types.mjs.map +1 -0
  33. package/dist/index.cjs +2 -0
  34. package/dist/index.cjs.map +1 -0
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.mjs +38 -0
  37. package/dist/index.mjs.map +1 -0
  38. package/dist/mock.cjs +2 -0
  39. package/dist/mock.cjs.map +1 -0
  40. package/dist/mock.d.ts +2 -0
  41. package/dist/mock.mjs +7 -0
  42. package/dist/mock.mjs.map +1 -0
  43. package/dist/node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.cjs +2 -0
  44. package/dist/node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.cjs.map +1 -0
  45. package/dist/node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs +20 -0
  46. package/dist/node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs.map +1 -0
  47. package/dist/protocol/envelope.cjs +2 -0
  48. package/dist/protocol/envelope.cjs.map +1 -0
  49. package/dist/protocol/envelope.d.ts +3 -0
  50. package/dist/protocol/envelope.mjs +19 -0
  51. package/dist/protocol/envelope.mjs.map +1 -0
  52. package/dist/protocol/guards.cjs +2 -0
  53. package/dist/protocol/guards.cjs.map +1 -0
  54. package/dist/protocol/guards.d.ts +2 -0
  55. package/dist/protocol/guards.mjs +7 -0
  56. package/dist/protocol/guards.mjs.map +1 -0
  57. package/dist/protocol/index.d.ts +2 -0
  58. package/dist/shared/index.d.ts +1 -0
  59. package/dist/shared/visibility.cjs +2 -0
  60. package/dist/shared/visibility.cjs.map +1 -0
  61. package/dist/shared/visibility.d.ts +2 -0
  62. package/dist/shared/visibility.mjs +10 -0
  63. package/dist/shared/visibility.mjs.map +1 -0
  64. package/dist/style.cjs +2 -0
  65. package/dist/style.cjs.map +1 -0
  66. package/dist/style.css +12 -0
  67. package/dist/style.d.ts +1 -0
  68. package/dist/style.mjs +2 -0
  69. package/dist/style.mjs.map +1 -0
  70. package/dist/tui/mapper.cjs +2 -0
  71. package/dist/tui/mapper.cjs.map +1 -0
  72. package/dist/tui/mapper.d.ts +3 -0
  73. package/dist/tui/mapper.mjs +25 -0
  74. package/dist/tui/mapper.mjs.map +1 -0
  75. package/dist/tui/store.cjs +2 -0
  76. package/dist/tui/store.cjs.map +1 -0
  77. package/dist/tui/store.d.ts +2 -0
  78. package/dist/tui/store.mjs +19 -0
  79. package/dist/tui/store.mjs.map +1 -0
  80. package/dist/tui/tim.cjs +2 -0
  81. package/dist/tui/tim.cjs.map +1 -0
  82. package/dist/tui/tim.d.ts +2 -0
  83. package/dist/tui/tim.mjs +116 -0
  84. package/dist/tui/tim.mjs.map +1 -0
  85. package/dist/ui/components/FontSizeControl.vue.cjs +2 -0
  86. package/dist/ui/components/FontSizeControl.vue.cjs.map +1 -0
  87. package/dist/ui/components/FontSizeControl.vue.d.ts +13 -0
  88. package/dist/ui/components/FontSizeControl.vue.mjs +8 -0
  89. package/dist/ui/components/FontSizeControl.vue.mjs.map +1 -0
  90. package/dist/ui/components/FontSizeControl.vue2.cjs +2 -0
  91. package/dist/ui/components/FontSizeControl.vue2.cjs.map +1 -0
  92. package/dist/ui/components/FontSizeControl.vue2.mjs +45 -0
  93. package/dist/ui/components/FontSizeControl.vue2.mjs.map +1 -0
  94. package/dist/ui/components/ImChatRoom.vue.cjs +2 -0
  95. package/dist/ui/components/ImChatRoom.vue.cjs.map +1 -0
  96. package/dist/ui/components/ImChatRoom.vue.d.ts +38 -0
  97. package/dist/ui/components/ImChatRoom.vue.mjs +55 -0
  98. package/dist/ui/components/ImChatRoom.vue.mjs.map +1 -0
  99. package/dist/ui/components/ImChatRoom.vue2.cjs +2 -0
  100. package/dist/ui/components/ImChatRoom.vue2.cjs.map +1 -0
  101. package/dist/ui/components/ImChatRoom.vue2.mjs +5 -0
  102. package/dist/ui/components/ImChatRoom.vue2.mjs.map +1 -0
  103. package/dist/ui/components/ImKit.vue.cjs +2 -0
  104. package/dist/ui/components/ImKit.vue.cjs.map +1 -0
  105. package/dist/ui/components/ImKit.vue.d.ts +17 -0
  106. package/dist/ui/components/ImKit.vue.mjs +17 -0
  107. package/dist/ui/components/ImKit.vue.mjs.map +1 -0
  108. package/dist/ui/components/ImKit.vue2.cjs +2 -0
  109. package/dist/ui/components/ImKit.vue2.cjs.map +1 -0
  110. package/dist/ui/components/ImKit.vue2.mjs +5 -0
  111. package/dist/ui/components/ImKit.vue2.mjs.map +1 -0
  112. package/dist/ui/components/ImMessageInput.vue.cjs +2 -0
  113. package/dist/ui/components/ImMessageInput.vue.cjs.map +1 -0
  114. package/dist/ui/components/ImMessageInput.vue.d.ts +22 -0
  115. package/dist/ui/components/ImMessageInput.vue.mjs +5 -0
  116. package/dist/ui/components/ImMessageInput.vue.mjs.map +1 -0
  117. package/dist/ui/components/ImMessageInput.vue2.cjs +2 -0
  118. package/dist/ui/components/ImMessageInput.vue2.cjs.map +1 -0
  119. package/dist/ui/components/ImMessageInput.vue2.mjs +33 -0
  120. package/dist/ui/components/ImMessageInput.vue2.mjs.map +1 -0
  121. package/dist/ui/components/PcConversationListSplit.vue.cjs +2 -0
  122. package/dist/ui/components/PcConversationListSplit.vue.cjs.map +1 -0
  123. package/dist/ui/components/PcConversationListSplit.vue.d.ts +8 -0
  124. package/dist/ui/components/PcConversationListSplit.vue.mjs +8 -0
  125. package/dist/ui/components/PcConversationListSplit.vue.mjs.map +1 -0
  126. package/dist/ui/components/PcConversationListSplit.vue2.cjs +2 -0
  127. package/dist/ui/components/PcConversationListSplit.vue2.cjs.map +1 -0
  128. package/dist/ui/components/PcConversationListSplit.vue2.mjs +90 -0
  129. package/dist/ui/components/PcConversationListSplit.vue2.mjs.map +1 -0
  130. package/dist/ui/components/SysMessage.vue.cjs +2 -0
  131. package/dist/ui/components/SysMessage.vue.cjs.map +1 -0
  132. package/dist/ui/components/SysMessage.vue.d.ts +19 -0
  133. package/dist/ui/components/SysMessage.vue.mjs +8 -0
  134. package/dist/ui/components/SysMessage.vue.mjs.map +1 -0
  135. package/dist/ui/components/SysMessage.vue2.cjs +2 -0
  136. package/dist/ui/components/SysMessage.vue2.cjs.map +1 -0
  137. package/dist/ui/components/SysMessage.vue2.mjs +42 -0
  138. package/dist/ui/components/SysMessage.vue2.mjs.map +1 -0
  139. package/dist/ui/index.d.ts +8 -0
  140. package/dist/ui/layouts/ChatLayoutH5.vue.cjs +2 -0
  141. package/dist/ui/layouts/ChatLayoutH5.vue.cjs.map +1 -0
  142. package/dist/ui/layouts/ChatLayoutH5.vue.d.ts +22 -0
  143. package/dist/ui/layouts/ChatLayoutH5.vue.mjs +8 -0
  144. package/dist/ui/layouts/ChatLayoutH5.vue.mjs.map +1 -0
  145. package/dist/ui/layouts/ChatLayoutH5.vue2.cjs +2 -0
  146. package/dist/ui/layouts/ChatLayoutH5.vue2.cjs.map +1 -0
  147. package/dist/ui/layouts/ChatLayoutH5.vue2.mjs +49 -0
  148. package/dist/ui/layouts/ChatLayoutH5.vue2.mjs.map +1 -0
  149. package/dist/ui/layouts/ChatLayoutPc.vue.cjs +2 -0
  150. package/dist/ui/layouts/ChatLayoutPc.vue.cjs.map +1 -0
  151. package/dist/ui/layouts/ChatLayoutPc.vue.d.ts +39 -0
  152. package/dist/ui/layouts/ChatLayoutPc.vue.mjs +8 -0
  153. package/dist/ui/layouts/ChatLayoutPc.vue.mjs.map +1 -0
  154. package/dist/ui/layouts/ChatLayoutPc.vue2.cjs +2 -0
  155. package/dist/ui/layouts/ChatLayoutPc.vue2.cjs.map +1 -0
  156. package/dist/ui/layouts/ChatLayoutPc.vue2.mjs +66 -0
  157. package/dist/ui/layouts/ChatLayoutPc.vue2.mjs.map +1 -0
  158. package/dist/ui/mock/consultMeta.cjs +2 -0
  159. package/dist/ui/mock/consultMeta.cjs.map +1 -0
  160. package/dist/ui/mock/consultMeta.d.ts +9 -0
  161. package/dist/ui/mock/consultMeta.mjs +29 -0
  162. package/dist/ui/mock/consultMeta.mjs.map +1 -0
  163. package/dist/ui/mock/mock-driver.cjs +2 -0
  164. package/dist/ui/mock/mock-driver.cjs.map +1 -0
  165. package/dist/ui/mock/mock-driver.d.ts +2 -0
  166. package/dist/ui/mock/mock-driver.mjs +51 -0
  167. package/dist/ui/mock/mock-driver.mjs.map +1 -0
  168. package/dist/ui/mock/mock.d.ts +2 -0
  169. package/dist/ui/renderers/MessageProxy.cjs +2 -0
  170. package/dist/ui/renderers/MessageProxy.cjs.map +1 -0
  171. package/dist/ui/renderers/MessageProxy.d.ts +24 -0
  172. package/dist/ui/renderers/MessageProxy.mjs +36 -0
  173. package/dist/ui/renderers/MessageProxy.mjs.map +1 -0
  174. package/dist/ui/renderers/createMessageComponent.cjs +2 -0
  175. package/dist/ui/renderers/createMessageComponent.cjs.map +1 -0
  176. package/dist/ui/renderers/createMessageComponent.d.ts +4 -0
  177. package/dist/ui/renderers/createMessageComponent.mjs +15 -0
  178. package/dist/ui/renderers/createMessageComponent.mjs.map +1 -0
  179. package/dist/ui/renderers/historyFilter.cjs +2 -0
  180. package/dist/ui/renderers/historyFilter.cjs.map +1 -0
  181. package/dist/ui/renderers/historyFilter.d.ts +10 -0
  182. package/dist/ui/renderers/historyFilter.mjs +41 -0
  183. package/dist/ui/renderers/historyFilter.mjs.map +1 -0
  184. package/dist/ui/renderers/registry.cjs +2 -0
  185. package/dist/ui/renderers/registry.cjs.map +1 -0
  186. package/dist/ui/renderers/registry.d.ts +3 -0
  187. package/dist/ui/renderers/registry.mjs +17 -0
  188. package/dist/ui/renderers/registry.mjs.map +1 -0
  189. package/dist/ui/renderers/resolve.cjs +2 -0
  190. package/dist/ui/renderers/resolve.cjs.map +1 -0
  191. package/dist/ui/renderers/resolve.d.ts +2 -0
  192. package/dist/ui/renderers/resolve.mjs +8 -0
  193. package/dist/ui/renderers/resolve.mjs.map +1 -0
  194. package/dist/ui/styles/style.d.ts +0 -0
  195. package/dist/utils/log.cjs +2 -0
  196. package/dist/utils/log.cjs.map +1 -0
  197. package/dist/utils/log.d.ts +1 -0
  198. package/dist/utils/log.mjs +7 -0
  199. package/dist/utils/log.mjs.map +1 -0
  200. package/package.json +65 -0
@@ -0,0 +1,2 @@
1
+ "use strict";const e=(t,r)=>{const o=t.__vccOpts||t;for(const[s,c]of r)o[s]=c;return o};module.exports=e;
2
+ //# sourceMappingURL=_plugin-vue_export-helper.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_plugin-vue_export-helper.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ const s = (t, e) => {
2
+ const o = t.__vccOpts || t;
3
+ for (const [r, c] of e)
4
+ o[r] = c;
5
+ return o;
6
+ };
7
+ export {
8
+ s as default
9
+ };
10
+ //# sourceMappingURL=_plugin-vue_export-helper.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_plugin-vue_export-helper.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../http/types.cjs");function r(t){if(!t)throw new o.ApiError(-1,"Empty response");if(t.code!==0)throw new o.ApiError(t.code,t.message||"Request failed",t);return t}function a(t,c){const n=c?.prefix??"/hl-link";return{async accountLogin(e){const i=await t.post(`${n}/account/login?accountId=${e.accountId}`);return r(i)},async getAppConfig(){const e=await t.get(`${n}/system/app-config`);return r(e)},async getUserSig(){const e=await t.post(`${n}/im/user-sig`);return r(e)}}}exports.createAuthApi=a;
2
+ //# sourceMappingURL=auth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.cjs","sources":["../../src/api/auth.ts"],"sourcesContent":["import type { ApiResp, HttpClient } from '../http/types'\nimport { ApiError } from '../http/types'\n\nexport interface LoginData {\n code: number\n message: string\n data: {\n token?: string\n [k: string]: any\n }\n}\n\nexport interface AppConfigData {\n code: number\n message: string\n data: {\n tencentImAppId: number\n [k: string]: any\n }\n}\n\nexport interface UserSigData {\n code: number\n message: string\n data: {\n userSig: string\n tencentImAccountId: string\n }\n}\n\nfunction unwrap<T>(resp: ApiResp<T>): ApiResp<T> {\n if (!resp) throw new ApiError(-1, 'Empty response')\n if (resp.code !== 0) throw new ApiError(resp.code, resp.message || 'Request failed', resp)\n return resp\n}\n\nexport function createAuthApi(http: HttpClient, opts?: { prefix?: string }) {\n const p = opts?.prefix ?? '/hl-link'\n\n return {\n /** 1) 账户登录(业务端给 accountId) */\n async accountLogin(data: { accountId: string }) {\n const resp = await http.post<ApiResp<LoginData>>(`${p}/account/login?accountId=${data.accountId}`)\n return unwrap(resp)\n },\n\n /** 2) 获取基础配置(业务端给 appKey) */\n async getAppConfig() {\n const resp = await http.get<ApiResp<AppConfigData>>(`${p}/system/app-config`)\n return unwrap(resp)\n },\n\n /** 3) 获取 userSig(accountId) */\n async getUserSig() {\n const resp = await http.post<ApiResp<UserSigData>>(`${p}/im/user-sig`)\n return unwrap(resp)\n },\n }\n}\n\nexport type AuthApi = ReturnType<typeof createAuthApi>\n\nexport async function bootstrapImLogin(p: { auth: AuthApi; accountId: string; appKey: string }) {\n // 1) 业务登录(拿 token)\n const login = await p.auth.accountLogin({ accountId: p.accountId })\n\n // 2) 配置:拿 tencentImAppId\n const cfg = await p.auth.getAppConfig()\n\n // 3) userSig\n const sig = await p.auth.getUserSig()\n\n return {\n login,\n tencentImAppId: cfg.data.tencentImAppId,\n userSig: sig.data.userSig,\n tencentImAccountId: sig.data.tencentImAccountId,\n }\n}\n"],"names":["unwrap","resp","ApiError","createAuthApi","http","opts","p","data"],"mappings":"qHA8BA,SAASA,EAAUC,EAA8B,CAC/C,GAAI,CAACA,EAAM,MAAM,IAAIC,EAAAA,SAAS,GAAI,gBAAgB,EAClD,GAAID,EAAK,OAAS,EAAG,MAAM,IAAIC,EAAAA,SAASD,EAAK,KAAMA,EAAK,SAAW,iBAAkBA,CAAI,EACzF,OAAOA,CACT,CAEO,SAASE,EAAcC,EAAkBC,EAA4B,CAC1E,MAAMC,EAAID,GAAM,QAAU,WAE1B,MAAO,CAEL,MAAM,aAAaE,EAA6B,CAC9C,MAAMN,EAAO,MAAMG,EAAK,KAAyB,GAAGE,CAAC,4BAA4BC,EAAK,SAAS,EAAE,EACjG,OAAOP,EAAOC,CAAI,CACpB,EAGA,MAAM,cAAe,CACnB,MAAMA,EAAO,MAAMG,EAAK,IAA4B,GAAGE,CAAC,oBAAoB,EAC5E,OAAON,EAAOC,CAAI,CACpB,EAGA,MAAM,YAAa,CACjB,MAAMA,EAAO,MAAMG,EAAK,KAA2B,GAAGE,CAAC,cAAc,EACrE,OAAON,EAAOC,CAAI,CACpB,CAAA,CAEJ"}
@@ -0,0 +1,48 @@
1
+ import { ApiResp, HttpClient } from '../http/types';
2
+ export interface LoginData {
3
+ code: number;
4
+ message: string;
5
+ data: {
6
+ token?: string;
7
+ [k: string]: any;
8
+ };
9
+ }
10
+ export interface AppConfigData {
11
+ code: number;
12
+ message: string;
13
+ data: {
14
+ tencentImAppId: number;
15
+ [k: string]: any;
16
+ };
17
+ }
18
+ export interface UserSigData {
19
+ code: number;
20
+ message: string;
21
+ data: {
22
+ userSig: string;
23
+ tencentImAccountId: string;
24
+ };
25
+ }
26
+ export declare function createAuthApi(http: HttpClient, opts?: {
27
+ prefix?: string;
28
+ }): {
29
+ /** 1) 账户登录(业务端给 accountId) */
30
+ accountLogin(data: {
31
+ accountId: string;
32
+ }): Promise<ApiResp<LoginData>>;
33
+ /** 2) 获取基础配置(业务端给 appKey) */
34
+ getAppConfig(): Promise<ApiResp<AppConfigData>>;
35
+ /** 3) 获取 userSig(accountId) */
36
+ getUserSig(): Promise<ApiResp<UserSigData>>;
37
+ };
38
+ export type AuthApi = ReturnType<typeof createAuthApi>;
39
+ export declare function bootstrapImLogin(p: {
40
+ auth: AuthApi;
41
+ accountId: string;
42
+ appKey: string;
43
+ }): Promise<{
44
+ login: ApiResp<LoginData>;
45
+ tencentImAppId: any;
46
+ userSig: any;
47
+ tencentImAccountId: any;
48
+ }>;
@@ -0,0 +1,30 @@
1
+ import { ApiError as r } from "../http/types.mjs";
2
+ function e(n) {
3
+ if (!n) throw new r(-1, "Empty response");
4
+ if (n.code !== 0) throw new r(n.code, n.message || "Request failed", n);
5
+ return n;
6
+ }
7
+ function s(n, c) {
8
+ const o = c?.prefix ?? "/hl-link";
9
+ return {
10
+ /** 1) 账户登录(业务端给 accountId) */
11
+ async accountLogin(t) {
12
+ const i = await n.post(`${o}/account/login?accountId=${t.accountId}`);
13
+ return e(i);
14
+ },
15
+ /** 2) 获取基础配置(业务端给 appKey) */
16
+ async getAppConfig() {
17
+ const t = await n.get(`${o}/system/app-config`);
18
+ return e(t);
19
+ },
20
+ /** 3) 获取 userSig(accountId) */
21
+ async getUserSig() {
22
+ const t = await n.post(`${o}/im/user-sig`);
23
+ return e(t);
24
+ }
25
+ };
26
+ }
27
+ export {
28
+ s as createAuthApi
29
+ };
30
+ //# sourceMappingURL=auth.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.mjs","sources":["../../src/api/auth.ts"],"sourcesContent":["import type { ApiResp, HttpClient } from '../http/types'\nimport { ApiError } from '../http/types'\n\nexport interface LoginData {\n code: number\n message: string\n data: {\n token?: string\n [k: string]: any\n }\n}\n\nexport interface AppConfigData {\n code: number\n message: string\n data: {\n tencentImAppId: number\n [k: string]: any\n }\n}\n\nexport interface UserSigData {\n code: number\n message: string\n data: {\n userSig: string\n tencentImAccountId: string\n }\n}\n\nfunction unwrap<T>(resp: ApiResp<T>): ApiResp<T> {\n if (!resp) throw new ApiError(-1, 'Empty response')\n if (resp.code !== 0) throw new ApiError(resp.code, resp.message || 'Request failed', resp)\n return resp\n}\n\nexport function createAuthApi(http: HttpClient, opts?: { prefix?: string }) {\n const p = opts?.prefix ?? '/hl-link'\n\n return {\n /** 1) 账户登录(业务端给 accountId) */\n async accountLogin(data: { accountId: string }) {\n const resp = await http.post<ApiResp<LoginData>>(`${p}/account/login?accountId=${data.accountId}`)\n return unwrap(resp)\n },\n\n /** 2) 获取基础配置(业务端给 appKey) */\n async getAppConfig() {\n const resp = await http.get<ApiResp<AppConfigData>>(`${p}/system/app-config`)\n return unwrap(resp)\n },\n\n /** 3) 获取 userSig(accountId) */\n async getUserSig() {\n const resp = await http.post<ApiResp<UserSigData>>(`${p}/im/user-sig`)\n return unwrap(resp)\n },\n }\n}\n\nexport type AuthApi = ReturnType<typeof createAuthApi>\n\nexport async function bootstrapImLogin(p: { auth: AuthApi; accountId: string; appKey: string }) {\n // 1) 业务登录(拿 token)\n const login = await p.auth.accountLogin({ accountId: p.accountId })\n\n // 2) 配置:拿 tencentImAppId\n const cfg = await p.auth.getAppConfig()\n\n // 3) userSig\n const sig = await p.auth.getUserSig()\n\n return {\n login,\n tencentImAppId: cfg.data.tencentImAppId,\n userSig: sig.data.userSig,\n tencentImAccountId: sig.data.tencentImAccountId,\n }\n}\n"],"names":["unwrap","resp","ApiError","createAuthApi","http","opts","p","data"],"mappings":";AA8BA,SAASA,EAAUC,GAA8B;AAC/C,MAAI,CAACA,EAAM,OAAM,IAAIC,EAAS,IAAI,gBAAgB;AAClD,MAAID,EAAK,SAAS,EAAG,OAAM,IAAIC,EAASD,EAAK,MAAMA,EAAK,WAAW,kBAAkBA,CAAI;AACzF,SAAOA;AACT;AAEO,SAASE,EAAcC,GAAkBC,GAA4B;AAC1E,QAAMC,IAAID,GAAM,UAAU;AAE1B,SAAO;AAAA;AAAA,IAEL,MAAM,aAAaE,GAA6B;AAC9C,YAAMN,IAAO,MAAMG,EAAK,KAAyB,GAAGE,CAAC,4BAA4BC,EAAK,SAAS,EAAE;AACjG,aAAOP,EAAOC,CAAI;AAAA,IACpB;AAAA;AAAA,IAGA,MAAM,eAAe;AACnB,YAAMA,IAAO,MAAMG,EAAK,IAA4B,GAAGE,CAAC,oBAAoB;AAC5E,aAAON,EAAOC,CAAI;AAAA,IACpB;AAAA;AAAA,IAGA,MAAM,aAAa;AACjB,YAAMA,IAAO,MAAMG,EAAK,KAA2B,GAAGE,CAAC,cAAc;AACrE,aAAON,EAAOC,CAAI;AAAA,IACpB;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.cjs"),c=require("../api/auth.cjs");class h{constructor(t){this.emitter=o(),this.accountId=null,this._tencentImAccountId=null,this._conversations=[],this._activeConversationId=null,this.convMetaMap={},this._pendingMetaNeed=new Set,this._metaNeedTimer=null,this.accountId=t.accountId,this.driver=t.driver,this.logger=t.logger??console,this.initApi(t),this.driver.init(),this.driver.onConnectionState(e=>this.emitter.emit("connection:state",e)),this.driver.onError(e=>this.emitter.emit("error",e)),this.driver.onActiveConversationChanged(({conversationId:e})=>{this._activeConversationId=e,this.emitter.emit("conversation:active",{conversationId:e})}),this.driver.onConversationListChanged(({conversations:e})=>{this._conversations=e,this.emitter.emit("conversation:list",{conversations:e});const n=e.map(i=>i.conversationID||i.id||i.conversationId);this._requestConversationMeta(n,"list")}),this.driver.onMessageReceived(({conversationId:e,messages:n})=>{this.emitter.emit("message:received",{conversationId:e,messages:n})})}initApi(t){if(t.api?.auth){this.api={auth:t.api.auth};return}if(t.http){const e=t.apiPrefix??"/hl-link";this.api={auth:c.createAuthApi(t.http,{prefix:e})};return}this.api=void 0}_requestConversationMeta(t,e="list"){const n=[];for(const i of t)i&&(this.convMetaMap[i]||this._pendingMetaNeed.has(i)||(this._pendingMetaNeed.add(i),n.push(i)));n.length&&(this._metaNeedTimer||(this._metaNeedTimer=setTimeout(()=>{this._metaNeedTimer=null;const i=Array.from(this._pendingMetaNeed);this._pendingMetaNeed.clear(),i.length&&this.emitter.emit("conversation:meta-need",{conversationIds:i,reason:e})},200)))}on(t,e){this.emitter.on(t,e)}off(t,e){e&&this.emitter.off(t,e)}get tencentImAccountId(){return this._tencentImAccountId??""}get activeConversationId(){return this._activeConversationId}get conversations(){return this._conversations}getConversationMeta(t){return console.log("getConversationMeta","id",t,"this.convMetaMap",this.convMetaMap),this.convMetaMap[t]}setConversationMeta(t,e){this.convMetaMap[t]=e}mergeConversationMetaMap(t){if(!t)return;const e=Object.keys(t);e.forEach(n=>{this.convMetaMap[n]={...this.convMetaMap[n]||{},...t[n]||{}}}),this.emitter.emit("conversation:meta-updated",{ids:e})}async login(){this.emitter.emit("connection:state",{state:"connecting"});const t=await this.api?.auth.accountLogin({accountId:this.accountId??""});t?.code===0&&this.emitter.emit("basic:account",{data:t.data});const e=await this.api?.auth.getAppConfig();e?.code===0&&this.emitter.emit("basic:config",{data:e.data});const n=await this.api?.auth.getUserSig(),{tencentImAppId:i}={tencentImAppId:e?.data?.tencentImAppId??""},{userSig:s,tencentImAccountId:a}={userSig:n?.data?.userSig,tencentImAccountId:n?.data?.tencentImAccountId};this._tencentImAccountId=a,await this.driver.login({userID:a??"",userSig:s??"",SDKAppID:i??""});try{this._conversations=await this.driver.getConversations(),this.emitter.emit("conversation:list",{conversations:this._conversations})}catch(r){this.logger.warn("[im] getConversations failed:",r)}}async logout(){await this.driver.logout(),this._activeConversationId=null}async switchConversation(t){this._activeConversationId=t,this._requestConversationMeta([t],"active"),this.emitter.emit("conversation:active",{conversationId:t}),await this.driver.switchConversation(t)}async sendText(t,e){await this.driver.sendText({conversationId:t,text:e})}async sendCustom(t){await this.driver.sendCustom({envelope:t})}async updateNick(t){await this.driver.updateNick(t)}async updateMyNameCard(t,e){await this.driver.updateMyNameCard(t,e)}async createGroup(t,e){await this.driver.createGroup(t,e)}}exports.IMClient=h;
2
+ //# sourceMappingURL=client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.cjs","sources":["../../src/core/client.ts"],"sourcesContent":["import mitt from 'mitt'\nimport type { CreateClientOptions, IMConversation, IMDriver, ConversationMeta } from './types'\nimport { createAuthApi, type AuthApi } from '../api/auth'\nimport type { IMEventMap, IMEventName } from './events'\n\nexport class IMClient {\n private emitter = mitt<IMEventMap>()\n private driver: IMDriver\n private logger: Pick<Console, 'log' | 'warn' | 'error'>\n\n private accountId: string | null = null\n private _tencentImAccountId: string | null = null\n private _conversations: IMConversation[] = []\n private _activeConversationId: string | null = null\n convMetaMap: Record<string, ConversationMeta> = {}\n _pendingMetaNeed = new Set()\n _metaNeedTimer = null\n\n public api?: { auth: AuthApi }\n constructor(opts: CreateClientOptions) {\n this.accountId = opts.accountId\n this.driver = opts.driver\n this.logger = opts.logger ?? console\n this.initApi(opts)\n this.driver.init()\n // driver -> client 事件桥接\n this.driver.onConnectionState((p) => this.emitter.emit('connection:state', p))\n this.driver.onError((e) => this.emitter.emit('error', e))\n this.driver.onActiveConversationChanged(({ conversationId }) => {\n this._activeConversationId = conversationId\n this.emitter.emit('conversation:active', { conversationId })\n })\n this.driver.onConversationListChanged(({ conversations }) => {\n this._conversations = conversations\n this.emitter.emit('conversation:list', { conversations })\n // 新会话出现时自动补 meta(用 conversationID 作为 key)\n const ids = conversations.map((c) => (c as any).conversationID || (c as any).id || (c as any).conversationId)\n this._requestConversationMeta(ids, 'list')\n })\n this.driver.onMessageReceived(({ conversationId, messages }) => {\n this.emitter.emit('message:received', { conversationId, messages })\n })\n }\n\n private initApi(opts: CreateClientOptions) {\n // 1) 如果外部直接注入了 api,优先用外部的\n if (opts.api?.auth) {\n this.api = { auth: opts.api.auth }\n return\n }\n\n // 2) 否则:如果注入了 http,就用默认实现 createAuthApi\n if (opts.http) {\n const prefix = opts.apiPrefix ?? '/hl-link'\n this.api = { auth: createAuthApi(opts.http, { prefix }) }\n return\n }\n\n // 3) 都没给:不初始化\n this.api = undefined\n }\n\n /** 收集缺失的会话 meta 并节流触发 conversation:meta-need */\n private _requestConversationMeta(\n ids: Array<string | null | undefined>,\n reason: 'list' | 'active' | 'manual' = 'list'\n ) {\n const missing: string[] = []\n\n for (const id of ids) {\n if (!id) continue\n // 已有 meta 就不请求\n if (this.convMetaMap[id]) continue\n // 已在 pending 中也不重复加\n if (this._pendingMetaNeed.has(id)) continue\n\n this._pendingMetaNeed.add(id)\n missing.push(id)\n }\n\n if (!missing.length) return\n\n // 200ms 内合并成一批触发一次\n if (this._metaNeedTimer) return\n\n this._metaNeedTimer = setTimeout(() => {\n this._metaNeedTimer = null\n const batch = Array.from(this._pendingMetaNeed)\n this._pendingMetaNeed.clear()\n\n if (!batch.length) return\n this.emitter.emit('conversation:meta-need', {\n conversationIds: batch as string[],\n reason,\n })\n }, 200) as any\n }\n\n on<K extends IMEventName>(event: K, cb: (payload: IMEventMap[K]) => void) {\n this.emitter.on(event, cb as any)\n }\n\n off<K extends IMEventName>(event: K, cb?: (payload: IMEventMap[K]) => void) {\n if (!cb) return\n this.emitter.off(event, cb as any)\n }\n\n get tencentImAccountId(): string {\n return this._tencentImAccountId ?? ''\n }\n\n get activeConversationId() {\n return this._activeConversationId\n }\n\n get conversations() {\n return this._conversations\n }\n\n getConversationMeta(id: string): ConversationMeta {\n console.log('getConversationMeta', 'id', id, 'this.convMetaMap', this.convMetaMap)\n return this.convMetaMap[id as string]\n }\n\n setConversationMeta(id: string, meta: ConversationMeta) {\n this.convMetaMap[id] = meta\n }\n\n mergeConversationMetaMap(patch) {\n if (!patch) return\n const ids = Object.keys(patch)\n ids.forEach((id) => {\n this.convMetaMap[id] = { ...(this.convMetaMap[id] || {}), ...(patch[id] || {}) }\n })\n this.emitter.emit('conversation:meta-updated', { ids })\n }\n\n async login() {\n this.emitter.emit('connection:state', { state: 'connecting' })\n // 1) 拿 token\n const res = await this.api?.auth.accountLogin({ accountId: this.accountId ?? '' })\n if (res?.code === 0) {\n this.emitter.emit('basic:account', { data: res.data })\n }\n // 2) 拿 appConfig => tencentImAppId\n const appConfigData = await this.api?.auth.getAppConfig()\n if (appConfigData?.code === 0) {\n this.emitter.emit('basic:config', { data: appConfigData.data })\n }\n\n // 3) 拿 userSig & userID\n const sigData = await this.api?.auth.getUserSig()\n const { tencentImAppId } = {\n tencentImAppId: appConfigData?.data?.tencentImAppId ?? '',\n }\n const { userSig, tencentImAccountId } = {\n userSig: sigData?.data?.userSig,\n tencentImAccountId: sigData?.data?.tencentImAccountId,\n }\n this._tencentImAccountId = tencentImAccountId\n await this.driver.login({\n userID: tencentImAccountId ?? '',\n userSig: userSig ?? '',\n SDKAppID: tencentImAppId ?? '',\n })\n\n // // 拉一次会话列表\n try {\n this._conversations = await this.driver.getConversations()\n this.emitter.emit('conversation:list', { conversations: this._conversations })\n } catch (e) {\n this.logger.warn('[im] getConversations failed:', e)\n }\n }\n\n async logout() {\n await this.driver.logout()\n this._activeConversationId = null\n }\n\n async switchConversation(conversationId: string) {\n this._activeConversationId = conversationId\n this._requestConversationMeta([conversationId], 'active')\n // 兜底逻辑:点进某个会话也会触发一次补 meta\n this.emitter.emit('conversation:active', { conversationId })\n await this.driver.switchConversation(conversationId)\n }\n\n async sendText(conversationId: string, text: string) {\n await this.driver.sendText({ conversationId, text })\n }\n\n async sendCustom(envelope: any) {\n await this.driver.sendCustom({ envelope })\n }\n\n async updateNick(nick: string) {\n await this.driver.updateNick(nick)\n }\n\n async updateMyNameCard(groupID: string, nameCard: string) {\n await this.driver.updateMyNameCard(groupID, nameCard)\n }\n\n async createGroup(groupName: string, memberList: any[]) {\n await this.driver.createGroup(groupName, memberList)\n }\n}\n"],"names":["IMClient","opts","mitt","p","conversationId","conversations","ids","c","messages","prefix","createAuthApi","reason","missing","id","batch","event","cb","meta","patch","res","appConfigData","sigData","tencentImAppId","userSig","tencentImAccountId","e","text","envelope","nick","groupID","nameCard","groupName","memberList"],"mappings":"iMAKO,MAAMA,CAAS,CAcpB,YAAYC,EAA2B,CAbvC,KAAQ,QAAUC,EAAA,EAIlB,KAAQ,UAA2B,KACnC,KAAQ,oBAAqC,KAC7C,KAAQ,eAAmC,CAAA,EAC3C,KAAQ,sBAAuC,KAC/C,KAAA,YAAgD,CAAA,EAChD,KAAA,qBAAuB,IACvB,KAAA,eAAiB,KAIf,KAAK,UAAYD,EAAK,UACtB,KAAK,OAASA,EAAK,OACnB,KAAK,OAASA,EAAK,QAAU,QAC7B,KAAK,QAAQA,CAAI,EACjB,KAAK,OAAO,KAAA,EAEZ,KAAK,OAAO,kBAAmBE,GAAM,KAAK,QAAQ,KAAK,mBAAoBA,CAAC,CAAC,EAC7E,KAAK,OAAO,QAAS,GAAM,KAAK,QAAQ,KAAK,QAAS,CAAC,CAAC,EACxD,KAAK,OAAO,4BAA4B,CAAC,CAAE,eAA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 import { CreateClientOptions, IMConversation, ConversationMeta } from './types';
2
+ import { AuthApi } from '../api/auth';
3
+ import { IMEventMap, IMEventName } from './events';
4
+ export declare class IMClient {
5
+ private emitter;
6
+ private driver;
7
+ private logger;
8
+ private accountId;
9
+ private _tencentImAccountId;
10
+ private _conversations;
11
+ private _activeConversationId;
12
+ convMetaMap: Record<string, ConversationMeta>;
13
+ _pendingMetaNeed: Set<unknown>;
14
+ _metaNeedTimer: null;
15
+ api?: {
16
+ auth: AuthApi;
17
+ };
18
+ constructor(opts: CreateClientOptions);
19
+ private initApi;
20
+ /** 收集缺失的会话 meta 并节流触发 conversation:meta-need */
21
+ private _requestConversationMeta;
22
+ on<K extends IMEventName>(event: K, cb: (payload: IMEventMap[K]) => void): void;
23
+ off<K extends IMEventName>(event: K, cb?: (payload: IMEventMap[K]) => void): void;
24
+ get tencentImAccountId(): string;
25
+ get activeConversationId(): string | null;
26
+ get conversations(): IMConversation[];
27
+ getConversationMeta(id: string): ConversationMeta;
28
+ setConversationMeta(id: string, meta: ConversationMeta): void;
29
+ mergeConversationMetaMap(patch: any): void;
30
+ login(): Promise<void>;
31
+ logout(): Promise<void>;
32
+ switchConversation(conversationId: string): Promise<void>;
33
+ sendText(conversationId: string, text: string): Promise<void>;
34
+ sendCustom(envelope: any): Promise<void>;
35
+ updateNick(nick: string): Promise<void>;
36
+ updateMyNameCard(groupID: string, nameCard: string): Promise<void>;
37
+ createGroup(groupName: string, memberList: any[]): Promise<void>;
38
+ }
@@ -0,0 +1,117 @@
1
+ import o from "../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs";
2
+ import { createAuthApi as c } from "../api/auth.mjs";
3
+ class u {
4
+ constructor(t) {
5
+ this.emitter = o(), this.accountId = null, this._tencentImAccountId = null, this._conversations = [], this._activeConversationId = null, this.convMetaMap = {}, this._pendingMetaNeed = /* @__PURE__ */ new Set(), this._metaNeedTimer = null, this.accountId = t.accountId, this.driver = t.driver, this.logger = t.logger ?? console, this.initApi(t), this.driver.init(), this.driver.onConnectionState((e) => this.emitter.emit("connection:state", e)), this.driver.onError((e) => this.emitter.emit("error", e)), this.driver.onActiveConversationChanged(({ conversationId: e }) => {
6
+ this._activeConversationId = e, this.emitter.emit("conversation:active", { conversationId: e });
7
+ }), this.driver.onConversationListChanged(({ conversations: e }) => {
8
+ this._conversations = e, this.emitter.emit("conversation:list", { conversations: e });
9
+ const n = e.map((i) => i.conversationID || i.id || i.conversationId);
10
+ this._requestConversationMeta(n, "list");
11
+ }), this.driver.onMessageReceived(({ conversationId: e, messages: n }) => {
12
+ this.emitter.emit("message:received", { conversationId: e, messages: n });
13
+ });
14
+ }
15
+ initApi(t) {
16
+ if (t.api?.auth) {
17
+ this.api = { auth: t.api.auth };
18
+ return;
19
+ }
20
+ if (t.http) {
21
+ const e = t.apiPrefix ?? "/hl-link";
22
+ this.api = { auth: c(t.http, { prefix: e }) };
23
+ return;
24
+ }
25
+ this.api = void 0;
26
+ }
27
+ /** 收集缺失的会话 meta 并节流触发 conversation:meta-need */
28
+ _requestConversationMeta(t, e = "list") {
29
+ const n = [];
30
+ for (const i of t)
31
+ i && (this.convMetaMap[i] || this._pendingMetaNeed.has(i) || (this._pendingMetaNeed.add(i), n.push(i)));
32
+ n.length && (this._metaNeedTimer || (this._metaNeedTimer = setTimeout(() => {
33
+ this._metaNeedTimer = null;
34
+ const i = Array.from(this._pendingMetaNeed);
35
+ this._pendingMetaNeed.clear(), i.length && this.emitter.emit("conversation:meta-need", {
36
+ conversationIds: i,
37
+ reason: e
38
+ });
39
+ }, 200)));
40
+ }
41
+ on(t, e) {
42
+ this.emitter.on(t, e);
43
+ }
44
+ off(t, e) {
45
+ e && this.emitter.off(t, e);
46
+ }
47
+ get tencentImAccountId() {
48
+ return this._tencentImAccountId ?? "";
49
+ }
50
+ get activeConversationId() {
51
+ return this._activeConversationId;
52
+ }
53
+ get conversations() {
54
+ return this._conversations;
55
+ }
56
+ getConversationMeta(t) {
57
+ return console.log("getConversationMeta", "id", t, "this.convMetaMap", this.convMetaMap), this.convMetaMap[t];
58
+ }
59
+ setConversationMeta(t, e) {
60
+ this.convMetaMap[t] = e;
61
+ }
62
+ mergeConversationMetaMap(t) {
63
+ if (!t) return;
64
+ const e = Object.keys(t);
65
+ e.forEach((n) => {
66
+ this.convMetaMap[n] = { ...this.convMetaMap[n] || {}, ...t[n] || {} };
67
+ }), this.emitter.emit("conversation:meta-updated", { ids: e });
68
+ }
69
+ async login() {
70
+ this.emitter.emit("connection:state", { state: "connecting" });
71
+ const t = await this.api?.auth.accountLogin({ accountId: this.accountId ?? "" });
72
+ t?.code === 0 && this.emitter.emit("basic:account", { data: t.data });
73
+ const e = await this.api?.auth.getAppConfig();
74
+ e?.code === 0 && this.emitter.emit("basic:config", { data: e.data });
75
+ const n = await this.api?.auth.getUserSig(), { tencentImAppId: i } = {
76
+ tencentImAppId: e?.data?.tencentImAppId ?? ""
77
+ }, { userSig: s, tencentImAccountId: a } = {
78
+ userSig: n?.data?.userSig,
79
+ tencentImAccountId: n?.data?.tencentImAccountId
80
+ };
81
+ this._tencentImAccountId = a, await this.driver.login({
82
+ userID: a ?? "",
83
+ userSig: s ?? "",
84
+ SDKAppID: i ?? ""
85
+ });
86
+ try {
87
+ this._conversations = await this.driver.getConversations(), this.emitter.emit("conversation:list", { conversations: this._conversations });
88
+ } catch (r) {
89
+ this.logger.warn("[im] getConversations failed:", r);
90
+ }
91
+ }
92
+ async logout() {
93
+ await this.driver.logout(), this._activeConversationId = null;
94
+ }
95
+ async switchConversation(t) {
96
+ this._activeConversationId = t, this._requestConversationMeta([t], "active"), this.emitter.emit("conversation:active", { conversationId: t }), await this.driver.switchConversation(t);
97
+ }
98
+ async sendText(t, e) {
99
+ await this.driver.sendText({ conversationId: t, text: e });
100
+ }
101
+ async sendCustom(t) {
102
+ await this.driver.sendCustom({ envelope: t });
103
+ }
104
+ async updateNick(t) {
105
+ await this.driver.updateNick(t);
106
+ }
107
+ async updateMyNameCard(t, e) {
108
+ await this.driver.updateMyNameCard(t, e);
109
+ }
110
+ async createGroup(t, e) {
111
+ await this.driver.createGroup(t, e);
112
+ }
113
+ }
114
+ export {
115
+ u as IMClient
116
+ };
117
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","sources":["../../src/core/client.ts"],"sourcesContent":["import mitt from 'mitt'\nimport type { CreateClientOptions, IMConversation, IMDriver, ConversationMeta } from './types'\nimport { createAuthApi, type AuthApi } from '../api/auth'\nimport type { IMEventMap, IMEventName } from './events'\n\nexport class IMClient {\n private emitter = mitt<IMEventMap>()\n private driver: IMDriver\n private logger: Pick<Console, 'log' | 'warn' | 'error'>\n\n private accountId: string | null = null\n private _tencentImAccountId: string | null = null\n private _conversations: IMConversation[] = []\n private _activeConversationId: string | null = null\n convMetaMap: Record<string, ConversationMeta> = {}\n _pendingMetaNeed = new Set()\n _metaNeedTimer = null\n\n public api?: { auth: AuthApi }\n constructor(opts: CreateClientOptions) {\n this.accountId = opts.accountId\n this.driver = opts.driver\n this.logger = opts.logger ?? console\n this.initApi(opts)\n this.driver.init()\n // driver -> client 事件桥接\n this.driver.onConnectionState((p) => this.emitter.emit('connection:state', p))\n this.driver.onError((e) => this.emitter.emit('error', e))\n this.driver.onActiveConversationChanged(({ conversationId }) => {\n this._activeConversationId = conversationId\n this.emitter.emit('conversation:active', { conversationId })\n })\n this.driver.onConversationListChanged(({ conversations }) => {\n this._conversations = conversations\n this.emitter.emit('conversation:list', { conversations })\n // 新会话出现时自动补 meta(用 conversationID 作为 key)\n const ids = conversations.map((c) => (c as any).conversationID || (c as any).id || (c as any).conversationId)\n this._requestConversationMeta(ids, 'list')\n })\n this.driver.onMessageReceived(({ conversationId, messages }) => {\n this.emitter.emit('message:received', { conversationId, messages })\n })\n }\n\n private initApi(opts: CreateClientOptions) {\n // 1) 如果外部直接注入了 api,优先用外部的\n if (opts.api?.auth) {\n this.api = { auth: opts.api.auth }\n return\n }\n\n // 2) 否则:如果注入了 http,就用默认实现 createAuthApi\n if (opts.http) {\n const prefix = opts.apiPrefix ?? '/hl-link'\n this.api = { auth: createAuthApi(opts.http, { prefix }) }\n return\n }\n\n // 3) 都没给:不初始化\n this.api = undefined\n }\n\n /** 收集缺失的会话 meta 并节流触发 conversation:meta-need */\n private _requestConversationMeta(\n ids: Array<string | null | undefined>,\n reason: 'list' | 'active' | 'manual' = 'list'\n ) {\n const missing: string[] = []\n\n for (const id of ids) {\n if (!id) continue\n // 已有 meta 就不请求\n if (this.convMetaMap[id]) continue\n // 已在 pending 中也不重复加\n if (this._pendingMetaNeed.has(id)) continue\n\n this._pendingMetaNeed.add(id)\n missing.push(id)\n }\n\n if (!missing.length) return\n\n // 200ms 内合并成一批触发一次\n if (this._metaNeedTimer) return\n\n this._metaNeedTimer = setTimeout(() => {\n this._metaNeedTimer = null\n const batch = Array.from(this._pendingMetaNeed)\n this._pendingMetaNeed.clear()\n\n if (!batch.length) return\n this.emitter.emit('conversation:meta-need', {\n conversationIds: batch as string[],\n reason,\n })\n }, 200) as any\n }\n\n on<K extends IMEventName>(event: K, cb: (payload: IMEventMap[K]) => void) {\n this.emitter.on(event, cb as any)\n }\n\n off<K extends IMEventName>(event: K, cb?: (payload: IMEventMap[K]) => void) {\n if (!cb) return\n this.emitter.off(event, cb as any)\n }\n\n get tencentImAccountId(): string {\n return this._tencentImAccountId ?? ''\n }\n\n get activeConversationId() {\n return this._activeConversationId\n }\n\n get conversations() {\n return this._conversations\n }\n\n getConversationMeta(id: string): ConversationMeta {\n console.log('getConversationMeta', 'id', id, 'this.convMetaMap', this.convMetaMap)\n return this.convMetaMap[id as string]\n }\n\n setConversationMeta(id: string, meta: ConversationMeta) {\n this.convMetaMap[id] = meta\n }\n\n mergeConversationMetaMap(patch) {\n if (!patch) return\n const ids = Object.keys(patch)\n ids.forEach((id) => {\n this.convMetaMap[id] = { ...(this.convMetaMap[id] || {}), ...(patch[id] || {}) }\n })\n this.emitter.emit('conversation:meta-updated', { ids })\n }\n\n async login() {\n this.emitter.emit('connection:state', { state: 'connecting' })\n // 1) 拿 token\n const res = await this.api?.auth.accountLogin({ accountId: this.accountId ?? '' })\n if (res?.code === 0) {\n this.emitter.emit('basic:account', { data: res.data })\n }\n // 2) 拿 appConfig => tencentImAppId\n const appConfigData = await this.api?.auth.getAppConfig()\n if (appConfigData?.code === 0) {\n this.emitter.emit('basic:config', { data: appConfigData.data })\n }\n\n // 3) 拿 userSig & userID\n const sigData = await this.api?.auth.getUserSig()\n const { tencentImAppId } = {\n tencentImAppId: appConfigData?.data?.tencentImAppId ?? '',\n }\n const { userSig, tencentImAccountId } = {\n userSig: sigData?.data?.userSig,\n tencentImAccountId: sigData?.data?.tencentImAccountId,\n }\n this._tencentImAccountId = tencentImAccountId\n await this.driver.login({\n userID: tencentImAccountId ?? '',\n userSig: userSig ?? '',\n SDKAppID: tencentImAppId ?? '',\n })\n\n // // 拉一次会话列表\n try {\n this._conversations = await this.driver.getConversations()\n this.emitter.emit('conversation:list', { conversations: this._conversations })\n } catch (e) {\n this.logger.warn('[im] getConversations failed:', e)\n }\n }\n\n async logout() {\n await this.driver.logout()\n this._activeConversationId = null\n }\n\n async switchConversation(conversationId: string) {\n this._activeConversationId = conversationId\n this._requestConversationMeta([conversationId], 'active')\n // 兜底逻辑:点进某个会话也会触发一次补 meta\n this.emitter.emit('conversation:active', { conversationId })\n await this.driver.switchConversation(conversationId)\n }\n\n async sendText(conversationId: string, text: string) {\n await this.driver.sendText({ conversationId, text })\n }\n\n async sendCustom(envelope: any) {\n await this.driver.sendCustom({ envelope })\n }\n\n async updateNick(nick: string) {\n await this.driver.updateNick(nick)\n }\n\n async updateMyNameCard(groupID: string, nameCard: string) {\n await this.driver.updateMyNameCard(groupID, nameCard)\n }\n\n async createGroup(groupName: string, memberList: any[]) {\n await this.driver.createGroup(groupName, memberList)\n }\n}\n"],"names":["IMClient","opts","mitt","p","conversationId","conversations","ids","c","messages","prefix","createAuthApi","reason","missing","id","batch","event","cb","meta","patch","res","appConfigData","sigData","tencentImAppId","userSig","tencentImAccountId","e","text","envelope","nick","groupID","nameCard","groupName","memberList"],"mappings":";;AAKO,MAAMA,EAAS;AAAA,EAcpB,YAAYC,GAA2B;AAbvC,SAAQ,UAAUC,EAAA,GAIlB,KAAQ,YAA2B,MACnC,KAAQ,sBAAqC,MAC7C,KAAQ,iBAAmC,CAAA,GAC3C,KAAQ,wBAAuC,MAC/C,KAAA,cAAgD,CAAA,GAChD,KAAA,uCAAuB,IAAA,GACvB,KAAA,iBAAiB,MAIf,KAAK,YAAYD,EAAK,WACtB,KAAK,SAASA,EAAK,QACnB,KAAK,SAASA,EAAK,UAAU,SAC7B,KAAK,QAAQA,CAAI,GACjB,KAAK,OAAO,KAAA,GAEZ,KAAK,OAAO,kBAAkB,CAACE,MAAM,KAAK,QAAQ,KAAK,oBAAoBA,CAAC,CAAC,GAC7E,KAAK,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ,KAAK,SAAS,CAAC,CAAC,GACxD,KAAK,OAAO,4BAA4B,CAAC,EAAE,gBAAAC,QAAqB;AAC9D,WAAK,wBAAwBA,GAC7B,KAAK,QAAQ,KAAK,uBAAuB,EAAE,gBAAAA,GAAgB;AAAA,IAC7D,CAAC,GACD,KAAK,OAAO,0BAA0B,CAAC,EAAE,eAAAC,QAAoB;AAC3D,WAAK,iBAAiBA,GACtB,KAAK,QAAQ,KAAK,qBAAqB,EAAE,eAAAA,GAAe;AAExD,YAAMC,IAAMD,EAAc,IAAI,CAACE,MAAOA,EAAU,kBAAmBA,EAAU,MAAOA,EAAU,cAAc;AAC5G,WAAK,yBAAyBD,GAAK,MAAM;AAAA,IAC3C,CAAC,GACD,KAAK,OAAO,kBAAkB,CAAC,EAAE,gBAAAF,GAAgB,UAAAI,QAAe;AAC9D,WAAK,QAAQ,KAAK,oBAAoB,EAAE,gBAAAJ,GAAgB,UAAAI,GAAU;AAAA,IACpE,CAAC;AAAA,EACH;AAAA,EAEQ,QAAQP,GAA2B;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AAW;AAAA,MACpB,UAAUD,KAAkB;AAAA,IAAA,CAC7B;AAGD,QAAI;AACF,WAAK,iBAAiB,MAAM,KAAK,OAAO,iBAAA,GACxC,KAAK,QAAQ,KAAK,qBAAqB,EAAE,eAAe,KAAK,gBAAgB;AAAA,IAC/E,SAASG,GAAG;AACV,WAAK,OAAO,KAAK,iCAAiCA,CAAC;AAAA,IACrD;AAAA,EACF;AAAA,EAEA,MAAM,SAAS;AACb,UAAM,KAAK,OAAO,OAAA,GAClB,KAAK,wBAAwB;AAAA,EAC/B;AAAA,EAEA,MAAM,mBAAmBrB,GAAwB;AAC/C,SAAK,wBAAwBA,GAC7B,KAAK,yBAAyB,CAACA,CAAc,GAAG,QAAQ,GAExD,KAAK,QAAQ,KAAK,uBAAuB,EAAE,gBAAAA,GAAgB,GAC3D,MAAM,KAAK,OAAO,mBAAmBA,CAAc;AAAA,EACrD;AAAA,EAEA,MAAM,SAASA,GAAwBsB,GAAc;AACnD,UAAM,KAAK,OAAO,SAAS,EAAE,gBAAAtB,GAAgB,MAAAsB,GAAM;AAAA,EACrD;AAAA,EAEA,MAAM,WAAWC,GAAe;AAC9B,UAAM,KAAK,OAAO,WAAW,EAAE,UAAAA,GAAU;AAAA,EAC3C;AAAA,EAEA,MAAM,WAAWC,GAAc;AAC7B,UAAM,KAAK,OAAO,WAAWA,CAAI;AAAA,EACnC;AAAA,EAEA,MAAM,iBAAiBC,GAAiBC,GAAkB;AACxD,UAAM,KAAK,OAAO,iBAAiBD,GAASC,CAAQ;AAAA,EACtD;AAAA,EAEA,MAAM,YAAYC,GAAmBC,GAAmB;AACtD,UAAM,KAAK,OAAO,YAAYD,GAAWC,CAAU;AAAA,EACrD;AACF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./client.cjs");function n(t){return new e.IMClient(t)}exports.IMClient=e.IMClient;exports.createClient=n;
2
+ //# sourceMappingURL=createClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createClient.cjs","sources":["../../src/core/createClient.ts"],"sourcesContent":["import { IMClient } from './client'\nimport type { CreateClientOptions } from './types'\n\nexport function createClient(opts: CreateClientOptions) {\n return new IMClient(opts)\n}\n\nexport * from './client'\nexport * from './events'\nexport * from './types'\n"],"names":["createClient","opts","IMClient"],"mappings":"gHAGO,SAASA,EAAaC,EAA2B,CACtD,OAAO,IAAIC,EAAAA,SAASD,CAAI,CAC1B"}
@@ -0,0 +1,6 @@
1
+ import { IMClient } from './client';
2
+ import { CreateClientOptions } from './types';
3
+ export declare function createClient(opts: CreateClientOptions): IMClient;
4
+ export * from './client';
5
+ export * from './events';
6
+ export * from './types';
@@ -0,0 +1,9 @@
1
+ import { IMClient as t } from "./client.mjs";
2
+ function r(e) {
3
+ return new t(e);
4
+ }
5
+ export {
6
+ t as IMClient,
7
+ r as createClient
8
+ };
9
+ //# sourceMappingURL=createClient.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createClient.mjs","sources":["../../src/core/createClient.ts"],"sourcesContent":["import { IMClient } from './client'\nimport type { CreateClientOptions } from './types'\n\nexport function createClient(opts: CreateClientOptions) {\n return new IMClient(opts)\n}\n\nexport * from './client'\nexport * from './events'\nexport * from './types'\n"],"names":["createClient","opts","IMClient"],"mappings":";AAGO,SAASA,EAAaC,GAA2B;AACtD,SAAO,IAAIC,EAASD,CAAI;AAC1B;"}
@@ -0,0 +1,36 @@
1
+ import { ConnectionState, IMConversation, IMMessage } from './types';
2
+ export type IMEventMap = {
3
+ 'connection:state': {
4
+ state: ConnectionState;
5
+ reason?: string;
6
+ };
7
+ 'conversation:list': {
8
+ conversations: IMConversation[];
9
+ };
10
+ 'basic:config': {
11
+ data: any;
12
+ };
13
+ 'basic:account': {
14
+ data: any;
15
+ };
16
+ 'conversation:active': {
17
+ conversationId: string;
18
+ };
19
+ 'conversation:meta-need': {
20
+ conversationIds: string[];
21
+ reason?: 'list' | 'active' | 'manual';
22
+ };
23
+ 'conversation:meta-updated': {
24
+ ids: string[];
25
+ };
26
+ 'message:received': {
27
+ conversationId: string;
28
+ messages: IMMessage[];
29
+ };
30
+ error: {
31
+ code: string;
32
+ message: string;
33
+ detail?: any;
34
+ };
35
+ };
36
+ export type IMEventName = keyof IMEventMap;
@@ -0,0 +1,4 @@
1
+ export { createClient } from './createClient';
2
+ export { IMClient } from './client';
3
+ export type * from './types';
4
+ export type { IMEventMap, IMEventName } from './events';
@@ -0,0 +1,127 @@
1
+ import { Component } from 'vue';
2
+ import { HttpClient } from '../http/types';
3
+ import { AuthApi } from '../api/auth';
4
+ export type ConversationId = string;
5
+ export type ConnectionState = 'idle' | 'connecting' | 'connected' | 'disconnected';
6
+ export interface SysPayload {
7
+ title?: string;
8
+ text: string;
9
+ actions?: Array<{
10
+ id: string;
11
+ text: string;
12
+ kind: 'open_url' | 'open_route' | 'copy' | 'ack' | 'call_api';
13
+ url?: string;
14
+ route?: {
15
+ name?: string;
16
+ path?: string;
17
+ query?: Record<string, any>;
18
+ };
19
+ payload?: any;
20
+ style?: 'primary' | 'default' | 'danger';
21
+ }>;
22
+ }
23
+ export interface Envelope<T = any> {
24
+ version: number;
25
+ type: string;
26
+ traceId?: string;
27
+ visibleTo?: string[];
28
+ invisibleTo?: string[];
29
+ payload: T;
30
+ extension?: Record<string, any>;
31
+ }
32
+ export type IMMessage = {
33
+ type: 'text';
34
+ payload: {
35
+ text: string;
36
+ };
37
+ raw?: any;
38
+ } | {
39
+ type: 'TIMCustomElem';
40
+ payload: Envelope;
41
+ raw?: any;
42
+ } | {
43
+ type: 'image';
44
+ payload: {
45
+ url?: string;
46
+ file?: File;
47
+ };
48
+ raw?: any;
49
+ } | {
50
+ type: 'unknown';
51
+ payload: any;
52
+ raw?: any;
53
+ };
54
+ export type ActionItem = string | {
55
+ key: string;
56
+ label?: string;
57
+ component: Component;
58
+ };
59
+ export interface IMConversation {
60
+ id: ConversationId;
61
+ type?: 'c2c' | 'group';
62
+ title?: string;
63
+ avatar?: string;
64
+ unreadCount?: number;
65
+ lastMessage?: IMMessage;
66
+ lastTime?: number;
67
+ raw?: any;
68
+ }
69
+ export interface IMDriver {
70
+ init(): Promise<void>;
71
+ login(opts: {
72
+ userID: string;
73
+ userSig: string;
74
+ SDKAppID: string;
75
+ }): Promise<void>;
76
+ logout(): Promise<void>;
77
+ switchConversation(conversationId: ConversationId): Promise<void>;
78
+ getActiveConversationId(): string;
79
+ getConversations(): any;
80
+ sendText(opts: {
81
+ conversationId: ConversationId;
82
+ text: string;
83
+ }): Promise<void>;
84
+ sendCustom(opts: {
85
+ envelope: Envelope;
86
+ }): Promise<void>;
87
+ createGroup(groupName: string, memberList: any[]): Promise<void>;
88
+ updateNick(nick: string): Promise<void>;
89
+ updateMyNameCard(groupID: string, nameCard: string): Promise<void>;
90
+ onMessageReceived(cb: (p: {
91
+ conversationId: ConversationId;
92
+ messages: IMMessage[];
93
+ }) => void): () => void;
94
+ onActiveConversationChanged(cb: (p: {
95
+ conversationId: ConversationId;
96
+ }) => void): () => void;
97
+ onConversationListChanged(cb: (p: {
98
+ conversations: IMConversation[];
99
+ }) => void): () => void;
100
+ onConnectionState(cb: (p: {
101
+ state: ConnectionState;
102
+ reason?: string;
103
+ }) => void): () => void;
104
+ onError(cb: (p: {
105
+ code: string;
106
+ message: string;
107
+ detail?: any;
108
+ }) => void): () => void;
109
+ }
110
+ export interface CreateClientOptions {
111
+ appKey: string;
112
+ accountId: string;
113
+ driver: IMDriver;
114
+ http?: HttpClient;
115
+ apiPrefix?: string;
116
+ api?: {
117
+ auth?: AuthApi;
118
+ };
119
+ logger?: Pick<Console, 'log' | 'warn' | 'error'>;
120
+ }
121
+ export type ConversationMeta = {
122
+ deptName?: string;
123
+ consultType?: string;
124
+ status?: 'todo' | 'done';
125
+ extra?: any;
126
+ [key: string]: any;
127
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(n){async function s(r,t,e,o){const u=n.baseUrl+t,c={...n.headers??{},...o?.headers??{}},i=e!=null;i&&(c["Content-Type"]="application/json");const a=await fetch(u,{method:r,credentials:"include",...o,headers:c,body:i?JSON.stringify(e):void 0});if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.json()}return{get(r,t){const e=t?.params?"?"+new URLSearchParams(t.params).toString():"";return s("GET",r+e,void 0,t)},post(r,t,e){return s("POST",r,t,e)}}}exports.createFetchHttp=l;
2
+ //# sourceMappingURL=createHttp.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHttp.cjs","sources":["../../src/http/createHttp.ts"],"sourcesContent":["import type { HttpClient } from './types'\n\nexport function createFetchHttp(opts: { baseUrl: string; headers?: Record<string, string> }): HttpClient {\n async function request<T>(method: string, url: string, body?: any, config?: any): Promise<T> {\n const full = opts.baseUrl + url\n const headers = { ...(opts.headers ?? {}), ...(config?.headers ?? {}) } as Record<string, string>\n\n // ✅ 只有有 body 才加 Content-Type,避免 GET 预检\n const hasBody = body !== undefined && body !== null\n if (hasBody) headers['Content-Type'] = 'application/json'\n\n const res = await fetch(full, {\n method,\n credentials: 'include', // ✅ 关键\n ...config,\n headers,\n body: hasBody ? JSON.stringify(body) : undefined,\n })\n\n if (!res.ok) throw new Error(`HTTP ${res.status}`)\n return res.json()\n }\n\n return {\n get(url, config: any) {\n const params = config?.params ? '?' + new URLSearchParams(config.params).toString() : ''\n return request('GET', url + params, undefined, config)\n },\n post(url, data, config: any) {\n return request('POST', url, data, config)\n },\n }\n}\n"],"names":["createFetchHttp","opts","request","method","url","body","config","full","headers","hasBody","res","params","data"],"mappings":"gFAEO,SAASA,EAAgBC,EAAyE,CACvG,eAAeC,EAAWC,EAAgBC,EAAaC,EAAYC,EAA0B,CAC3F,MAAMC,EAAON,EAAK,QAAUG,EACtBI,EAAU,CAAE,GAAIP,EAAK,SAAW,CAAA,EAAK,GAAIK,GAAQ,SAAW,EAAC,EAG7DG,EAAgCJ,GAAS,KAC3CI,IAASD,EAAQ,cAAc,EAAI,oBAEvC,MAAME,EAAM,MAAM,MAAMH,EAAM,CAC5B,OAAAJ,EACA,YAAa,UACb,GAAGG,EACH,QAAAE,EACA,KAAMC,EAAU,KAAK,UAAUJ,CAAI,EAAI,MAAA,CACxC,EAED,GAAI,CAACK,EAAI,GAAI,MAAM,IAAI,MAAM,QAAQA,EAAI,MAAM,EAAE,EACjD,OAAOA,EAAI,KAAA,CACb,CAEA,MAAO,CACL,IAAIN,EAAKE,EAAa,CACpB,MAAMK,EAASL,GAAQ,OAAS,IAAM,IAAI,gBAAgBA,EAAO,MAAM,EAAE,SAAA,EAAa,GACtF,OAAOJ,EAAQ,MAAOE,EAAMO,EAAQ,OAAWL,CAAM,CACvD,EACA,KAAKF,EAAKQ,EAAMN,EAAa,CAC3B,OAAOJ,EAAQ,OAAQE,EAAKQ,EAAMN,CAAM,CAC1C,CAAA,CAEJ"}
@@ -0,0 +1,5 @@
1
+ import { HttpClient } from './types';
2
+ export declare function createFetchHttp(opts: {
3
+ baseUrl: string;
4
+ headers?: Record<string, string>;
5
+ }): HttpClient;
@@ -0,0 +1,29 @@
1
+ function d(s) {
2
+ async function a(r, t, e, o) {
3
+ const u = s.baseUrl + t, c = { ...s.headers ?? {}, ...o?.headers ?? {} }, i = e != null;
4
+ i && (c["Content-Type"] = "application/json");
5
+ const n = await fetch(u, {
6
+ method: r,
7
+ credentials: "include",
8
+ // ✅ 关键
9
+ ...o,
10
+ headers: c,
11
+ body: i ? JSON.stringify(e) : void 0
12
+ });
13
+ if (!n.ok) throw new Error(`HTTP ${n.status}`);
14
+ return n.json();
15
+ }
16
+ return {
17
+ get(r, t) {
18
+ const e = t?.params ? "?" + new URLSearchParams(t.params).toString() : "";
19
+ return a("GET", r + e, void 0, t);
20
+ },
21
+ post(r, t, e) {
22
+ return a("POST", r, t, e);
23
+ }
24
+ };
25
+ }
26
+ export {
27
+ d as createFetchHttp
28
+ };
29
+ //# sourceMappingURL=createHttp.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHttp.mjs","sources":["../../src/http/createHttp.ts"],"sourcesContent":["import type { HttpClient } from './types'\n\nexport function createFetchHttp(opts: { baseUrl: string; headers?: Record<string, string> }): HttpClient {\n async function request<T>(method: string, url: string, body?: any, config?: any): Promise<T> {\n const full = opts.baseUrl + url\n const headers = { ...(opts.headers ?? {}), ...(config?.headers ?? {}) } as Record<string, string>\n\n // ✅ 只有有 body 才加 Content-Type,避免 GET 预检\n const hasBody = body !== undefined && body !== null\n if (hasBody) headers['Content-Type'] = 'application/json'\n\n const res = await fetch(full, {\n method,\n credentials: 'include', // ✅ 关键\n ...config,\n headers,\n body: hasBody ? JSON.stringify(body) : undefined,\n })\n\n if (!res.ok) throw new Error(`HTTP ${res.status}`)\n return res.json()\n }\n\n return {\n get(url, config: any) {\n const params = config?.params ? '?' + new URLSearchParams(config.params).toString() : ''\n return request('GET', url + params, undefined, config)\n },\n post(url, data, config: any) {\n return request('POST', url, data, config)\n },\n }\n}\n"],"names":["createFetchHttp","opts","request","method","url","body","config","full","headers","hasBody","res","params","data"],"mappings":"AAEO,SAASA,EAAgBC,GAAyE;AACvG,iBAAeC,EAAWC,GAAgBC,GAAaC,GAAYC,GAA0B;AAC3F,UAAMC,IAAON,EAAK,UAAUG,GACtBI,IAAU,EAAE,GAAIP,EAAK,WAAW,CAAA,GAAK,GAAIK,GAAQ,WAAW,GAAC,GAG7DG,IAAgCJ,KAAS;AAC/C,IAAII,MAASD,EAAQ,cAAc,IAAI;AAEvC,UAAME,IAAM,MAAM,MAAMH,GAAM;AAAA,MAC5B,QAAAJ;AAAA,MACA,aAAa;AAAA;AAAA,MACb,GAAGG;AAAA,MACH,SAAAE;AAAA,MACA,MAAMC,IAAU,KAAK,UAAUJ,CAAI,IAAI;AAAA,IAAA,CACxC;AAED,QAAI,CAACK,EAAI,GAAI,OAAM,IAAI,MAAM,QAAQA,EAAI,MAAM,EAAE;AACjD,WAAOA,EAAI,KAAA;AAAA,EACb;AAEA,SAAO;AAAA,IACL,IAAIN,GAAKE,GAAa;AACpB,YAAMK,IAASL,GAAQ,SAAS,MAAM,IAAI,gBAAgBA,EAAO,MAAM,EAAE,SAAA,IAAa;AACtF,aAAOJ,EAAQ,OAAOE,IAAMO,GAAQ,QAAWL,CAAM;AAAA,IACvD;AAAA,IACA,KAAKF,GAAKQ,GAAMN,GAAa;AAC3B,aAAOJ,EAAQ,QAAQE,GAAKQ,GAAMN,CAAM;AAAA,IAC1C;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class o extends Error{constructor(r,e,t){super(e),this.code=r,this.detail=t}}exports.ApiError=o;
2
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sources":["../../src/http/types.ts"],"sourcesContent":["export interface ApiResp<T = any> {\n code: number\n data: T\n message: string\n}\n\nexport class ApiError extends Error {\n code: number\n detail?: any\n constructor(code: number, message: string, detail?: any) {\n super(message)\n this.code = code\n this.detail = detail\n }\n}\n\nexport interface HttpClient {\n get<T = any>(url: string, config?: any): Promise<T>\n post<T = any>(url: string, data?: any, config?: any): Promise<T>\n}\n"],"names":["ApiError","code","message","detail"],"mappings":"gFAMO,MAAMA,UAAiB,KAAM,CAGlC,YAAYC,EAAcC,EAAiBC,EAAc,CACvD,MAAMD,CAAO,EACb,KAAK,KAAOD,EACZ,KAAK,OAASE,CAChB,CACF"}
@@ -0,0 +1,14 @@
1
+ export interface ApiResp<T = any> {
2
+ code: number;
3
+ data: T;
4
+ message: string;
5
+ }
6
+ export declare class ApiError extends Error {
7
+ code: number;
8
+ detail?: any;
9
+ constructor(code: number, message: string, detail?: any);
10
+ }
11
+ export interface HttpClient {
12
+ get<T = any>(url: string, config?: any): Promise<T>;
13
+ post<T = any>(url: string, data?: any, config?: any): Promise<T>;
14
+ }
@@ -0,0 +1,9 @@
1
+ class o extends Error {
2
+ constructor(r, s, t) {
3
+ super(s), this.code = r, this.detail = t;
4
+ }
5
+ }
6
+ export {
7
+ o as ApiError
8
+ };
9
+ //# sourceMappingURL=types.mjs.map