k2-im 0.1.0 → 0.1.2
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/dist/browser.d.ts +365 -0
- package/dist/browser.js +1 -0
- package/dist/chat-kit-pinia.d.ts +28 -7
- package/dist/chat-kit-pinia.js +1 -1
- package/dist/chat-kit-vue.js +1 -1
- package/dist/chat-kit.d.ts +28 -7
- package/dist/chat-kit.js +1 -1
- package/dist/chunk-FO2MMPPT.js +7 -0
- package/dist/{chunk-I6FUD7EW.js → chunk-JUJCY6DH.js} +1 -1
- package/dist/chunk-QGGCU24I.js +1 -0
- package/dist/chunk-VSMNRAAM.js +1 -0
- package/dist/{chunk-YMH6LM5Q.js → chunk-WYHMM3QR.js} +1 -1
- package/dist/chunk-ZJBW4MOG.js +2 -0
- package/dist/{chunk-RZFMPR6C.js → chunk-ZXNH42G2.js} +1 -1
- package/dist/i18n.js +1 -1
- package/dist/index.d.ts +28 -7
- package/dist/index.js +1 -1
- package/dist/sdk.d.ts +28 -7
- package/dist/sdk.js +1 -1
- package/package.json +5 -1
- package/dist/chunk-BRHUZPIB.js +0 -1
- package/dist/chunk-UWQHGBMV.js +0 -1
- package/dist/chunk-VKSMKG6Q.js +0 -7
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 后端协议的目标服务命名。
|
|
3
|
+
*
|
|
4
|
+
* `core`、`wallet`、`bi` 沿用当前 H5/BFF 已接入的服务分组;`im` 用于后续 IM
|
|
5
|
+
* HTTP 业务接口直连。调用方应优先通过 `target` 切换服务,而不是在业务代码里手动拼接
|
|
6
|
+
* baseURL 或 prefix,这样未来从 BFF 迁移到客户端直连时可以只调整运行时配置。
|
|
7
|
+
*/
|
|
8
|
+
type ApiProtocolTarget = 'core' | 'wallet' | 'bi' | 'im';
|
|
9
|
+
/**
|
|
10
|
+
* 单个目标服务的直连地址配置。
|
|
11
|
+
*
|
|
12
|
+
* `baseUrl` 通常来自 Nuxt public runtime config 或客户端构建配置;`prefix` 是该服务在后端
|
|
13
|
+
* 网关下的默认业务前缀,例如核心业务的 `/api/h5`。单次请求可以通过 request options 覆盖它们。
|
|
14
|
+
*/
|
|
15
|
+
interface ApiProtocolTargetConfig {
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
prefix?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 客户端直连协议所需的公开运行时配置。
|
|
21
|
+
*
|
|
22
|
+
* 这份配置只包含允许公开给浏览器的协议字段。签名和 AES 规则由 `@k2/crypto` wasm 提供,
|
|
23
|
+
* 不要求调用方传入额外密钥。
|
|
24
|
+
*/
|
|
25
|
+
interface ApiProtocolRuntimeConfig {
|
|
26
|
+
/** 应用版本,同时写入 `app_version` 和加密版本请求头。 */
|
|
27
|
+
appVersion: string;
|
|
28
|
+
/** 品牌 ID,对应现有 H5/BFF 协议里的 `brand-id`。 */
|
|
29
|
+
brandId: string;
|
|
30
|
+
/** 商户 ID,对应协议请求头 `mch-id`。 */
|
|
31
|
+
merchantId: string;
|
|
32
|
+
/** 默认渠道 ID;单次请求可通过 `channelId` 覆盖。 */
|
|
33
|
+
channelId: string;
|
|
34
|
+
/** 签名算法需要的环境标识,例如 `prod`、`dev` 等。 */
|
|
35
|
+
envType: string;
|
|
36
|
+
/** 所有可请求目标的 baseURL/prefix 映射。 */
|
|
37
|
+
targets: Record<ApiProtocolTarget, ApiProtocolTargetConfig>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 与 `@k2/crypto` wasm 实现对齐的协议加解密能力。
|
|
41
|
+
*
|
|
42
|
+
* 通过依赖注入而不是在核心 request 中直接加载 wasm,可以让 Node 测试、浏览器插件、
|
|
43
|
+
* Nuxt client plugin 或未来客户端容器按自己的生命周期加载 crypto。
|
|
44
|
+
*/
|
|
45
|
+
interface ApiProtocolCryptoDriver {
|
|
46
|
+
/** 计算普通 MD5,主要用于兼容 BI feedback 签名。 */
|
|
47
|
+
cryptMd5: (input: string) => string;
|
|
48
|
+
/**
|
|
49
|
+
* 生成后端协议签名。
|
|
50
|
+
*
|
|
51
|
+
* @param signType 当前业务请求固定为 `api`。
|
|
52
|
+
* @param envType 运行环境标识,来自 `ApiProtocolRuntimeConfig.envType`。
|
|
53
|
+
* @param businessParams 已合并公共参数且完成字符串化的业务请求参数。
|
|
54
|
+
* @param eTag 本次请求头中的 `Content-ETag`,缺省时按 crypto 实现约定处理。
|
|
55
|
+
*/
|
|
56
|
+
generateSign: (signType: string, envType: string, businessParams: Record<string, string>, eTag?: string | null) => string;
|
|
57
|
+
/** 将 UTF-8 JSON bytes 加密为后端要求的二进制请求体。 */
|
|
58
|
+
encryptAes: (payload: Uint8Array) => Uint8Array;
|
|
59
|
+
/** 将后端返回的二进制响应体解密为 UTF-8 JSON bytes。 */
|
|
60
|
+
decryptAes: (payload: Uint8Array) => Uint8Array;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 协议请求头需要的浏览器/设备信息。
|
|
64
|
+
*
|
|
65
|
+
* Web 端默认从 userAgent 和本地随机设备号派生;原生客户端或桌面容器可以注入更稳定的设备信息。
|
|
66
|
+
*/
|
|
67
|
+
interface ApiProtocolBrowserInfo {
|
|
68
|
+
deviceBrand: string;
|
|
69
|
+
deviceInfo: string;
|
|
70
|
+
deviceNumber: string;
|
|
71
|
+
deviceToken: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 上传进度事件的协议层抽象。
|
|
75
|
+
*
|
|
76
|
+
* 默认 axios transport 会从 AxiosProgressEvent 映射到该结构;如果未来接入原生容器网络层,
|
|
77
|
+
* 也只需要按相同字段回调业务层即可。
|
|
78
|
+
*/
|
|
79
|
+
interface ApiProtocolUploadProgress {
|
|
80
|
+
/** 已上传字节数。 */
|
|
81
|
+
loaded: number;
|
|
82
|
+
/** 总字节数;部分运行时无法拿到时为空。 */
|
|
83
|
+
total?: number;
|
|
84
|
+
/** 0 到 1 之间的上传比例;无法计算时为空。 */
|
|
85
|
+
progress?: number;
|
|
86
|
+
/** 底层 transport 的原始进度事件,供调试或特殊场景读取。 */
|
|
87
|
+
event?: unknown;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 单次协议请求的可覆盖项。
|
|
91
|
+
*
|
|
92
|
+
* 默认请求会按当前 H5/BFF 协议自动补公共参数、签名、AES 加密、token、语言和设备头。
|
|
93
|
+
* 只有上传、特殊回调或兼容接口这类非标准请求,才需要显式传 `body`、关闭 `encrypt/sign`
|
|
94
|
+
* 或使用 `customUrl`。
|
|
95
|
+
*/
|
|
96
|
+
interface ApiProtocolRequestOptions {
|
|
97
|
+
/** HTTP method,默认 `POST`;`GET` 请求会把协议参数拼到 query。 */
|
|
98
|
+
method?: string;
|
|
99
|
+
/** 目标后端服务,默认 `core`。IM 业务请求应传 `im`。 */
|
|
100
|
+
target?: ApiProtocolTarget;
|
|
101
|
+
/** 业务参数。数字会按现有协议转换为字符串,避免大整数在 JSON 中丢精度。 */
|
|
102
|
+
data?: Record<string, unknown>;
|
|
103
|
+
/** 自定义请求体。传入后默认不做协议加密/签名,适合 FormData 或已编码内容。 */
|
|
104
|
+
body?: BodyInit | null;
|
|
105
|
+
/** 追加或覆盖请求头;需要特殊端类型等场景可覆盖公共协议头。 */
|
|
106
|
+
headers?: HeadersInit;
|
|
107
|
+
/** 覆盖目标服务默认 prefix。 */
|
|
108
|
+
prefix?: string;
|
|
109
|
+
/** 覆盖目标服务默认 baseURL,常用于灰度环境或临时调试。 */
|
|
110
|
+
baseUrl?: string;
|
|
111
|
+
/** 覆盖默认渠道 ID。 */
|
|
112
|
+
channelId?: string;
|
|
113
|
+
/** 是否对普通请求体执行 AES 加密;默认在无自定义 body 时开启。 */
|
|
114
|
+
encrypt?: boolean;
|
|
115
|
+
/** 是否生成协议签名;默认在无自定义 body 时开启。 */
|
|
116
|
+
sign?: boolean;
|
|
117
|
+
/** 客户端超时时间,默认 60 秒。 */
|
|
118
|
+
timeoutMs?: number;
|
|
119
|
+
/** 覆盖依赖注入中的 token 读取结果;传空字符串可主动发起未登录请求。 */
|
|
120
|
+
token?: string | null;
|
|
121
|
+
/** 覆盖依赖注入中的 locale 读取结果。 */
|
|
122
|
+
locale?: string | null;
|
|
123
|
+
/** 覆盖浏览器 userAgent 派生逻辑,主要用于测试或容器环境。 */
|
|
124
|
+
userAgent?: string | null;
|
|
125
|
+
/** `true` 时 `path` 被视为完整 URL,不再拼接 target baseURL/prefix。 */
|
|
126
|
+
customUrl?: boolean;
|
|
127
|
+
/** 外部取消信号,会和内部 timeout 信号合并。 */
|
|
128
|
+
signal?: AbortSignal;
|
|
129
|
+
/** 上传进度回调;默认浏览器客户端的 axios transport 支持该能力。 */
|
|
130
|
+
onUploadProgress?: (progress: ApiProtocolUploadProgress) => void;
|
|
131
|
+
/**
|
|
132
|
+
* 响应解析模式。
|
|
133
|
+
* - `'json'`(默认):按 content-type 走 JSON / 文本 / AES-JSON 解析,返回业务响应对象。
|
|
134
|
+
* - `'raw'`:原样返回响应字节(`data` 为 `Uint8Array`),不做 JSON / 文本解析;用于
|
|
135
|
+
* protobuf 等二进制接口(如 IM CM 离线消息)。通常与二进制 `body` 搭配使用。
|
|
136
|
+
*/
|
|
137
|
+
responseMode?: 'json' | 'raw';
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* 后端业务响应体。
|
|
141
|
+
*
|
|
142
|
+
* @template T 业务数据 `data` 的类型;当接口无数据或失败时,`data` 可能为空。
|
|
143
|
+
*/
|
|
144
|
+
interface ApiProtocolResponse<T = unknown> {
|
|
145
|
+
code: number;
|
|
146
|
+
data?: T | null;
|
|
147
|
+
msg?: string;
|
|
148
|
+
time?: number;
|
|
149
|
+
[key: string]: unknown;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* transport 层收到的标准化请求。
|
|
153
|
+
*
|
|
154
|
+
* 核心协议只关心“发送一个 HTTP 请求并返回原始响应”,axios、fetch 或原生容器网络栈都可以适配成
|
|
155
|
+
* 这个形状,从而避免业务协议绑定具体 HTTP 库。
|
|
156
|
+
*/
|
|
157
|
+
interface ApiProtocolTransportRequest {
|
|
158
|
+
url: string;
|
|
159
|
+
method: string;
|
|
160
|
+
headers: Record<string, string>;
|
|
161
|
+
body?: BodyInit;
|
|
162
|
+
signal?: AbortSignal;
|
|
163
|
+
timeoutMs?: number;
|
|
164
|
+
onUploadProgress?: (progress: ApiProtocolUploadProgress) => void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* transport 层返回的原始 HTTP 响应。
|
|
168
|
+
*
|
|
169
|
+
* `data` 应尽量保持未解析形态,例如 ArrayBuffer 或二进制 bytes;协议层会根据 content-type
|
|
170
|
+
* 决定是否 JSON 解析、文本解析或 AES 解密。
|
|
171
|
+
*/
|
|
172
|
+
interface ApiProtocolTransportResponse {
|
|
173
|
+
status: number;
|
|
174
|
+
statusText: string;
|
|
175
|
+
headers?: Headers | Record<string, unknown>;
|
|
176
|
+
data?: unknown;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* HTTP 发送适配器。
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* const transport: ApiProtocolTransport = async request => ({
|
|
184
|
+
* status: 200,
|
|
185
|
+
* statusText: 'OK',
|
|
186
|
+
* headers: { 'content-type': 'application/json' },
|
|
187
|
+
* data: '{"code":0,"data":null}',
|
|
188
|
+
* });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
type ApiProtocolTransport = (request: ApiProtocolTransportRequest) => Promise<ApiProtocolTransportResponse>;
|
|
192
|
+
/**
|
|
193
|
+
* 业务响应副作用回调的上下文。
|
|
194
|
+
*
|
|
195
|
+
* 这里故意不暴露 BFF 层曾经用于调试的 `meta`,因为客户端调用方只应关心业务响应和本次请求的
|
|
196
|
+
* 基础定位信息。登录态失效、全局 toast、埋点等副作用可以通过该上下文判断来源。
|
|
197
|
+
*/
|
|
198
|
+
interface ApiProtocolBusinessResponseContext {
|
|
199
|
+
request: {
|
|
200
|
+
path: string;
|
|
201
|
+
method: string;
|
|
202
|
+
target: ApiProtocolTarget;
|
|
203
|
+
url: string;
|
|
204
|
+
};
|
|
205
|
+
options: ApiProtocolRequestOptions;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 业务响应统一处理器。
|
|
209
|
+
*
|
|
210
|
+
* 典型用途是沿用当前全局登录态处理:例如 `401`、`501` 时清理 token 并跳转登录。
|
|
211
|
+
*/
|
|
212
|
+
type ApiProtocolBusinessResponseHandler = (response: ApiProtocolResponse<unknown>, context: ApiProtocolBusinessResponseContext) => void | Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* 协议客户端内部调试事件。
|
|
215
|
+
*
|
|
216
|
+
* 事件只通过可选 debug hook 暴露给开发工具,不会混入公开业务响应。它刻意包含加密前请求参数、
|
|
217
|
+
* 解密后的响应体和真实请求/响应头,方便类似 Network 面板的插件还原协议请求。
|
|
218
|
+
*
|
|
219
|
+
* @template T 当前请求业务响应 `data` 的类型。
|
|
220
|
+
*/
|
|
221
|
+
interface ApiProtocolDebugEvent<T = unknown> {
|
|
222
|
+
requestId: string;
|
|
223
|
+
eTag: string;
|
|
224
|
+
method: string;
|
|
225
|
+
upstreamUrl: string;
|
|
226
|
+
requestHeaders?: Record<string, string>;
|
|
227
|
+
/** 协议层自动补齐并参与签名/发送的公共参数,例如 app_id、timestamp、nonce、sign。 */
|
|
228
|
+
requestCommonParams?: unknown;
|
|
229
|
+
/** 调用方通过 `options.data` 显式传入并归一化后的业务参数。 */
|
|
230
|
+
requestBusinessParams?: unknown;
|
|
231
|
+
/** 加密、签名或拼 query 前的最终请求参数;通常等于公共参数与业务参数的合并结果。 */
|
|
232
|
+
requestParams?: unknown;
|
|
233
|
+
transportStatus: 'success' | 'http_error' | 'network_error' | 'invalid_response';
|
|
234
|
+
httpStatus?: number;
|
|
235
|
+
contentType?: string | null;
|
|
236
|
+
responseHeaders?: Record<string, string>;
|
|
237
|
+
rawBody?: unknown;
|
|
238
|
+
timings: {
|
|
239
|
+
totalMs: number;
|
|
240
|
+
upstreamMs: number;
|
|
241
|
+
parseMs?: number;
|
|
242
|
+
decryptMs?: number;
|
|
243
|
+
};
|
|
244
|
+
response: ApiProtocolResponse<T>;
|
|
245
|
+
error?: {
|
|
246
|
+
name?: string;
|
|
247
|
+
message: string;
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/** 接收协议调试事件的可选回调,用于应用内调试面板或测试环境观测。 */
|
|
251
|
+
type ApiProtocolDebugHandler = (event: ApiProtocolDebugEvent) => void | Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* 创建协议客户端所需的依赖集合。
|
|
254
|
+
*
|
|
255
|
+
* 所有与具体运行时相关的读取行为都放在这里:token/locale/设备信息/随机数/时间/transport。
|
|
256
|
+
* 这样核心 request 可以在浏览器、H5、PC、单元测试或未来原生客户端中复用。
|
|
257
|
+
*/
|
|
258
|
+
interface ApiProtocolClientDependencies {
|
|
259
|
+
/** 公开协议配置。 */
|
|
260
|
+
config: ApiProtocolRuntimeConfig;
|
|
261
|
+
/** 协议签名和 AES 加解密能力。 */
|
|
262
|
+
crypto: ApiProtocolCryptoDriver;
|
|
263
|
+
/** HTTP 发送适配器。 */
|
|
264
|
+
transport: ApiProtocolTransport;
|
|
265
|
+
/** 每次请求前读取最新 token,避免客户端登录态刷新后 request 持有旧值。 */
|
|
266
|
+
getToken?: () => string | null | undefined | Promise<string | null | undefined>;
|
|
267
|
+
/** 每次请求前读取当前语言,并由协议层转换为后端短码。 */
|
|
268
|
+
getLocale?: () => string | null | undefined;
|
|
269
|
+
/** 覆盖默认浏览器设备信息推导。 */
|
|
270
|
+
getBrowserInfo?: () => ApiProtocolBrowserInfo;
|
|
271
|
+
/** 注入时间源,方便测试签名与时间戳。 */
|
|
272
|
+
now?: () => Date;
|
|
273
|
+
/** 注入 nonce,方便测试或兼容特定容器随机数实现。 */
|
|
274
|
+
randomNonce?: () => string;
|
|
275
|
+
/** 注入请求 ID 生成器。 */
|
|
276
|
+
randomRequestId?: () => string;
|
|
277
|
+
/** 注入 ETag 生成器,参与签名和请求头。 */
|
|
278
|
+
randomETag?: () => string;
|
|
279
|
+
/** 业务响应统一副作用处理器。 */
|
|
280
|
+
onBusinessResponse?: ApiProtocolBusinessResponseHandler;
|
|
281
|
+
/** 可选调试事件回调。只用于开发/测试面板,不改变公开 API 返回值。 */
|
|
282
|
+
onDebugRecord?: ApiProtocolDebugHandler;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* 协议客户端函数。
|
|
286
|
+
*
|
|
287
|
+
* @template T 业务响应 `data` 类型。
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* const response = await client<{ nickname: string }>('/v1/user/profile', {
|
|
291
|
+
* target: 'im',
|
|
292
|
+
* data: { userId: '10001' },
|
|
293
|
+
* });
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
type ApiProtocolClient = <T = unknown>(path: string, options?: ApiProtocolRequestOptions) => Promise<ApiProtocolResponse<T>>;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 创建运行时协议配置的输入。
|
|
300
|
+
*
|
|
301
|
+
* 这里同时支持扁平的 `coreBaseUrl/imBaseUrl` 和完整的 `targets` 覆盖,方便 Nuxt public runtime
|
|
302
|
+
* config 使用简单字段,也方便未来客户端容器一次性传入完整服务映射。
|
|
303
|
+
*/
|
|
304
|
+
interface CreateApiProtocolRuntimeConfigInput {
|
|
305
|
+
/** 应用版本,会进入公共参数和加密版本请求头。 */
|
|
306
|
+
appVersion?: string;
|
|
307
|
+
/** 品牌 ID。 */
|
|
308
|
+
brandId?: string;
|
|
309
|
+
/** 商户 ID。 */
|
|
310
|
+
merchantId?: string;
|
|
311
|
+
/** 默认渠道 ID。 */
|
|
312
|
+
channelId?: string;
|
|
313
|
+
/** 签名环境标识。 */
|
|
314
|
+
envType?: string;
|
|
315
|
+
/** core 服务 baseURL。 */
|
|
316
|
+
coreBaseUrl?: string;
|
|
317
|
+
/** wallet 服务 baseURL。 */
|
|
318
|
+
walletBaseUrl?: string;
|
|
319
|
+
/** BI 服务 baseURL。 */
|
|
320
|
+
biBaseUrl?: string;
|
|
321
|
+
/** IM 服务 baseURL。 */
|
|
322
|
+
imBaseUrl?: string;
|
|
323
|
+
/** 更细粒度的 target 覆盖,优先级高于上面的扁平 baseURL 字段。 */
|
|
324
|
+
targets?: Partial<Record<ApiProtocolTarget, Partial<ApiProtocolTargetConfig>>>;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 浏览器便捷客户端的创建参数。
|
|
329
|
+
*
|
|
330
|
+
* 与底层 `createApiProtocolClient` 相比,这里默认补齐 wasm crypto 和 axios transport。
|
|
331
|
+
* Nuxt/React/Vue 等应用只需要注入运行时配置、token/locale 读取器和业务响应处理器。
|
|
332
|
+
*/
|
|
333
|
+
interface CreateBrowserApiProtocolClientInput extends Omit<ApiProtocolClientDependencies, 'config' | 'crypto' | 'transport'> {
|
|
334
|
+
/** 允许传入不完整配置,内部会通过 `createApiProtocolRuntimeConfig` 补齐默认 prefix。 */
|
|
335
|
+
config?: CreateApiProtocolRuntimeConfigInput;
|
|
336
|
+
/** 覆盖默认 axios transport,例如测试、埋点代理或客户端容器网络层。 */
|
|
337
|
+
transport?: ApiProtocolTransport;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* 延迟创建并复用浏览器 API 协议客户端的账号运行时 helper。
|
|
342
|
+
* 初始化失败会清除 rejected 缓存允许重试;凭据始终从当前调用方读取,不固化旧账号闭包。
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* 创建按首次请求初始化的浏览器协议客户端。
|
|
347
|
+
*
|
|
348
|
+
* @remarks
|
|
349
|
+
* SDK client 的构造必须保持同步,wasm crypto 与 axios transport 则只能异步初始化。本代理把初始化推迟到
|
|
350
|
+
* 第一次 core JSON 请求,并复用同一个 client;每次业务请求仍由底层 client 调用动态 `getToken`,不会捕获
|
|
351
|
+
* 创建时的账号凭据。初始化失败会清除缓存,允许宿主修复运行环境后重试。
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```ts
|
|
355
|
+
* const client = createLazyBrowserApiProtocolClient({
|
|
356
|
+
* config: { coreBaseUrl: 'https://core.example.com' },
|
|
357
|
+
* getToken: async () => auth.getToken(),
|
|
358
|
+
* })
|
|
359
|
+
* await client('/user/info/other', { target: 'core', data: { user_id: '42' } })
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
declare function createLazyBrowserApiProtocolClient(input: CreateBrowserApiProtocolClientInput, createClient?: (input: CreateBrowserApiProtocolClientInput) => Promise<ApiProtocolClient>): ApiProtocolClient;
|
|
363
|
+
|
|
364
|
+
export { createLazyBrowserApiProtocolClient };
|
|
365
|
+
export type { ApiProtocolClient };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{A as createLazyBrowserApiProtocolClient}from'./chunk-FO2MMPPT.js';import'./chunk-VSMNRAAM.js';import'./chunk-WOT6VMZA.js';
|
package/dist/chat-kit-pinia.d.ts
CHANGED
|
@@ -2083,7 +2083,7 @@ type ImEvent = {
|
|
|
2083
2083
|
createdAt: number;
|
|
2084
2084
|
expired: boolean;
|
|
2085
2085
|
}
|
|
2086
|
-
/** 对端应答 0x4008;accept
|
|
2086
|
+
/** 对端应答 0x4008;accept 后仍须等匹配的首帧事件才算接通。 */
|
|
2087
2087
|
| {
|
|
2088
2088
|
type: 'call:answered';
|
|
2089
2089
|
conversation: ConversationRef<'direct'>;
|
|
@@ -2099,13 +2099,20 @@ type ImEvent = {
|
|
|
2099
2099
|
peerId: string;
|
|
2100
2100
|
outcome: ImCallOutcome;
|
|
2101
2101
|
}
|
|
2102
|
-
/** 对端 PEER_AUDIO_BEGIN(5)
|
|
2102
|
+
/** 对端 PEER_AUDIO_BEGIN(5)。Android TrackSubscribed 后发送;iOS LiveKit 不发此包。收到才算语音接通,不把 accept 当成接通。 */
|
|
2103
2103
|
| {
|
|
2104
2104
|
type: 'call:peer-audio-begin';
|
|
2105
2105
|
conversation: ConversationRef<'direct'>;
|
|
2106
2106
|
callId: string;
|
|
2107
2107
|
peerId: string;
|
|
2108
2108
|
}
|
|
2109
|
+
/** 对端 PEER_VIDEO_BEGIN(6)。Android TrackSubscribed 后发送;iOS LiveKit 不发此包。收到才算视频接通,不把 accept 当成接通。 */
|
|
2110
|
+
| {
|
|
2111
|
+
type: 'call:peer-video-begin';
|
|
2112
|
+
conversation: ConversationRef<'direct'>;
|
|
2113
|
+
callId: string;
|
|
2114
|
+
peerId: string;
|
|
2115
|
+
}
|
|
2109
2116
|
/** 主叫 invite ACK 失败(对端离线等);本机已写入 cancelled 记录。 */
|
|
2110
2117
|
| {
|
|
2111
2118
|
type: 'call:failed';
|
|
@@ -3379,7 +3386,7 @@ interface ImApplicationsApi {
|
|
|
3379
3386
|
}
|
|
3380
3387
|
|
|
3381
3388
|
/**
|
|
3382
|
-
* 单聊 1v1
|
|
3389
|
+
* 单聊 1v1 音视频信令产品门面。
|
|
3383
3390
|
*
|
|
3384
3391
|
* 宿主先完成 LiveKit Connected,再 `invite`;来电订阅 `call:incoming`。
|
|
3385
3392
|
* SDK 不持有 getUserMedia / LiveKit;token 与进房留在宿主。
|
|
@@ -3388,6 +3395,8 @@ interface ImApplicationsApi {
|
|
|
3388
3395
|
interface ImDirectCallInviteInput {
|
|
3389
3396
|
peerId: string;
|
|
3390
3397
|
callId: string;
|
|
3398
|
+
/** 默认 audio。视频发信令 callType=0。接通仍等对端首帧事件,不把 accept 当成接通。 */
|
|
3399
|
+
callKind?: ImCallKind;
|
|
3391
3400
|
}
|
|
3392
3401
|
interface ImDirectCallTargetInput {
|
|
3393
3402
|
peerId: string;
|
|
@@ -3402,13 +3411,13 @@ interface ImDirectCallNotifyAudioInput extends ImDirectCallTargetInput {
|
|
|
3402
3411
|
interface ImDirectCallsApi {
|
|
3403
3412
|
/**
|
|
3404
3413
|
* 主叫在 LiveKit Connected 之后发送 0x4001。
|
|
3405
|
-
*
|
|
3414
|
+
* `callKind` 默认 audio;video 发 callType=0。
|
|
3406
3415
|
*/
|
|
3407
3416
|
invite: (input: ImDirectCallInviteInput) => {
|
|
3408
3417
|
callId: string;
|
|
3409
3418
|
conversation: ConversationRef<'direct'>;
|
|
3410
3419
|
};
|
|
3411
|
-
/** 被叫同意:发 0x4005 NON_ERR
|
|
3420
|
+
/** 被叫同意:发 0x4005 NON_ERR。接通仍等匹配的首帧事件。 */
|
|
3412
3421
|
accept: (input: ImDirectCallTargetInput) => void;
|
|
3413
3422
|
/** 被叫拒绝:发 0x4005 0x8400,并插入 rejected 记录。 */
|
|
3414
3423
|
reject: (input: ImDirectCallTargetInput) => void;
|
|
@@ -3417,10 +3426,17 @@ interface ImDirectCallsApi {
|
|
|
3417
3426
|
/** 挂断:发 0x400d,并插入通话记录(msgId=callId)。 */
|
|
3418
3427
|
hangup: (input: ImDirectCallHangupInput) => void;
|
|
3419
3428
|
/**
|
|
3420
|
-
*
|
|
3429
|
+
* 语音 TrackSubscribed 后通知对端 PEER_AUDIO_BEGIN(5)。
|
|
3421
3430
|
* `role` 映射 Android notifyValue:caller=1 / callee=2。
|
|
3431
|
+
* iOS LiveKit 现行不发此包;宿主不得因对端是 iOS 而改发或不发。
|
|
3422
3432
|
*/
|
|
3423
3433
|
notifyPeerAudioBegin: (input: ImDirectCallNotifyAudioInput) => void;
|
|
3434
|
+
/**
|
|
3435
|
+
* 视频 TrackSubscribed 后通知对端 PEER_VIDEO_BEGIN(6)。
|
|
3436
|
+
* `role` 映射与语音相同。当前通话不是视频时 fail-fast。
|
|
3437
|
+
* iOS LiveKit 现行不发此包。
|
|
3438
|
+
*/
|
|
3439
|
+
notifyPeerVideoBegin: (input: ImDirectCallNotifyAudioInput) => void;
|
|
3424
3440
|
}
|
|
3425
3441
|
|
|
3426
3442
|
/**
|
|
@@ -4579,6 +4595,11 @@ interface ImProductEventMap {
|
|
|
4579
4595
|
callId: string;
|
|
4580
4596
|
peerId: string;
|
|
4581
4597
|
}>;
|
|
4598
|
+
'call:peer-video-begin': Readonly<{
|
|
4599
|
+
ref: ConversationRef<'direct'>;
|
|
4600
|
+
callId: string;
|
|
4601
|
+
peerId: string;
|
|
4602
|
+
}>;
|
|
4582
4603
|
'call:failed': Readonly<{
|
|
4583
4604
|
ref: ConversationRef<'direct'>;
|
|
4584
4605
|
callId: string;
|
|
@@ -5259,7 +5280,7 @@ interface ImProductClient {
|
|
|
5259
5280
|
* 普通宿主只使用 `ImProductClient`;官方 Chat Kit 和受控诊断从 internal 子入口取得 `ImAdvancedClient`。
|
|
5260
5281
|
*/
|
|
5261
5282
|
interface ImClient extends Omit<ImProductClient, 'capabilities' | 'channels' | 'contacts' | 'conversations' | 'groups'> {
|
|
5262
|
-
/** internal/testing
|
|
5283
|
+
/** internal/testing 与高级宿主使用的单聊音视频信令;稳定 default 产品门面不暴露此能力。 */
|
|
5263
5284
|
readonly calls: ImDirectCallsApi;
|
|
5264
5285
|
/**
|
|
5265
5286
|
* 打开一个拥有独立连续窗口与生命周期的 direct、GROUP 或 CHANNEL 会话句柄。
|