@workopilot/webapp-sdk 0.1.4 → 0.1.5

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 CHANGED
@@ -1,129 +1,176 @@
1
- # @workopilot/webapp-sdk
2
-
3
- WiseAI 三方前端应用 SDK,适用于挂载在宿主项目中的 iframe 应用。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install @workopilot/webapp-sdk
9
- ```
10
-
11
- ## 初始化
12
-
13
- ```ts
14
- import { createWiseAiFrontSdk } from '@workopilot/webapp-sdk';
15
-
16
- const sdk = createWiseAiFrontSdk({
17
- appCode: 'third-party-mysql-demo',
18
- env: 'prod',
19
- javaBasePath: '/prod-api',
20
- netBasePath: '/net-api',
21
- secureStoreKey: 'please-replace-me-with-your-own-key',
22
- });
23
-
24
- await sdk.init();
25
- ```
26
-
27
- 初始化参数:
28
-
29
- | 参数 | 必填 | 默认值 | 说明 |
30
- | --- | --- | --- | --- |
31
- | `appCode` | 是 | 无 | 三方应用编号 |
32
- | `env` | 否 | 自动判断 | `dev` 或 `prod` |
33
- | `javaBasePath` | 否 | `''` | Java 接口前缀 |
34
- | `netBasePath` | 否 | `/net-api` | NET 接口前缀 |
35
- | `enableEncrypt` | 否 | 读取环境变量 | 是否启用开发环境登录请求加密 |
36
- | `clientId` | 否 | 读取环境变量 | 登录请求使用的客户端编号 |
37
- | `rsaPublicKey` | 否 | 读取环境变量 | 启用加密时使用的 RSA 公钥 |
38
- | `accessToken` | 否 | 空 | 调用方直接提供的 token |
39
- | `tokenProvider` | 否 | 无 | 自定义同步或异步 token 获取函数 |
40
- | `tokenQueryParam` | 否 | `runtimeToken` | iframe URL 中承载 token 的 Query 参数名 |
41
- | `secureStoreKey` | 否 | 读取环境变量 | 解密 WiseAI 生产环境 SecureLS 登录态的密钥 |
42
- | `secureStoreNamespace` | 否 | 自动扫描 | 明确指定宿主 Pinia 持久化命名空间 |
43
-
44
- 生产环境建议由宿主项目的 `.env.*` 文件管理环境参数,再传给 SDK:
45
-
46
- ```text
47
- VITE_WISEAI_ENV=prod
48
- VITE_WISEAI_APP_CODE=third-party-mysql-demo
49
- VITE_WISEAI_JAVA_BASE_PATH=/prod-api
50
- VITE_WISEAI_NET_BASE_PATH=/net-api
51
- VITE_GLOB_ENABLE_ENCRYPT=true
52
- VITE_GLOB_RSA_PUBLIC_KEY=...
53
- VITE_GLOB_APP_CLIENT_ID=...
54
- VITE_APP_STORE_SECURE_KEY=please-replace-me-with-your-own-key
55
- ```
56
-
57
- ## 提供能力
58
-
59
- ### Token 和登录
60
-
61
- - 按显式 token、`tokenProvider`、URL `runtimeToken`、明文存储、WiseAI SecureLS 存储的顺序获取 token。
62
- - 兼容参考项目生产环境带版本号的 `*-prod-core-access` 加密 Pinia 登录态。
63
- - 自动读取和保存开发环境的 `accessToken`。
64
- - 自动检查 JWT 是否过期。
65
- - 生产环境没有 token 时,通过 iframe `postMessage` 通知宿主重新登录。
66
- - 开发环境没有 token 时,自动请求 `{javaBasePath}/auth/code` 获取验证码配置并弹出登录窗口。
67
- - 根据 `captchaEnabled` 决定是否显示验证码。
68
- - 登录接口默认使用 `POST {javaBasePath}/auth/login`,请求体不包含 `appCode`。
69
- - 支持按参考项目规则使用 AES + RSA 加密登录请求。
70
- - 业务请求自动携带 `Authorization: Bearer <token>`。
71
-
72
- ### 接口请求
73
-
74
- ```ts
75
- const user = await sdk.get('/plugins/third-party-mysql-demo/me');
76
-
77
- const result = await sdk.postJson('/some/api', {
78
- name: 'demo',
79
- });
80
-
81
- const data = await sdk.request('/some/api', {
82
- base: 'net',
83
- method: 'PATCH',
84
- params: { id: 1 },
85
- body: { name: 'demo' },
86
- bodyType: 'json',
87
- headers: {
88
- 'X-Custom-Header': 'value',
89
- },
90
- });
91
- ```
92
-
93
- 支持 `get`、`postJson` 和泛化 `request`。泛化请求支持自定义接口前缀、请求方法、查询参数、请求体类型和请求头。
94
-
95
- ### 文件上传
96
-
97
- ```ts
98
- const result = await sdk.uploadFile(file, {
99
- path: '/api/smart_classify/upload',
100
- fileFieldName: 'file',
101
- extraData: {
102
- businessType: 'smart_classify',
103
- },
104
- });
105
- ```
106
-
107
- 上传请求使用 `FormData` 并自动携带 token。默认上传地址为 `/api/file/upload`,可通过 `path` 覆盖。
108
-
109
- ### 路由权限
110
-
111
- ```ts
112
- const menus = await sdk.getRoutePermissions();
113
- ```
114
-
115
- 默认调用:
116
-
117
- ```text
118
- GET {netBasePath}/api/PluginApp/GetRouters?appCode={appCode}
119
- ```
120
-
121
- 返回路由菜单权限数据,宿主项目可以根据结果生成左侧菜单和受保护路由。
122
-
123
- ### Token 清理
124
-
125
- ```ts
126
- sdk.clearToken();
127
- ```
128
-
129
- 完整的 SDK 开发维护说明见 [SDK-DEVELOPMENT.md](./SDK-DEVELOPMENT.md)。
1
+ # @workopilot/webapp-sdk
2
+
3
+ WiseAI 三方前端应用 SDK,适用于挂载在宿主项目中的 iframe 应用。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @workopilot/webapp-sdk
9
+ ```
10
+
11
+ ## 初始化
12
+
13
+ ```ts
14
+ import { createWiseAiFrontSdk } from '@workopilot/webapp-sdk';
15
+
16
+ const sdk = createWiseAiFrontSdk({
17
+ appCode: 'third-party-mysql-demo',
18
+ env: 'prod',
19
+ javaBasePath: '/prod-api',
20
+ netBasePath: '/net-api',
21
+ secureStoreKey: 'please-replace-me-with-your-own-key',
22
+ });
23
+
24
+ await sdk.init();
25
+ ```
26
+
27
+ 初始化参数:
28
+
29
+ | 参数 | 必填 | 默认值 | 说明 |
30
+ | --- | --- | --- | --- |
31
+ | `appCode` | 是 | 无 | 三方应用编号 |
32
+ | `env` | 否 | 自动判断 | `dev` 或 `prod` |
33
+ | `javaBasePath` | 否 | `''` | Java 接口前缀 |
34
+ | `netBasePath` | 否 | `/net-api` | NET 接口前缀 |
35
+ | `enableEncrypt` | 否 | 读取环境变量 | 是否启用开发环境登录请求加密 |
36
+ | `clientId` | 否 | 读取环境变量 | 登录请求使用的客户端编号 |
37
+ | `rsaPublicKey` | 否 | 读取环境变量 | 启用加密时使用的 RSA 公钥 |
38
+ | `accessToken` | 否 | 空 | 调用方直接提供的 token |
39
+ | `tokenProvider` | 否 | 无 | 自定义同步或异步 token 获取函数 |
40
+ | `tokenQueryParam` | 否 | `runtimeToken` | iframe URL 中承载 token 的 Query 参数名 |
41
+ | `secureStoreKey` | 否 | 读取环境变量 | 解密 WiseAI 生产环境 SecureLS 登录态的密钥 |
42
+ | `secureStoreNamespace` | 否 | 自动扫描 | 明确指定宿主 Pinia 持久化命名空间 |
43
+
44
+ 生产环境建议由宿主项目的 `.env.*` 文件管理环境参数,再传给 SDK:
45
+
46
+ ```text
47
+ VITE_WISEAI_ENV=prod
48
+ VITE_WISEAI_APP_CODE=third-party-mysql-demo
49
+ VITE_WISEAI_JAVA_BASE_PATH=/prod-api
50
+ VITE_WISEAI_NET_BASE_PATH=/net-api
51
+ VITE_GLOB_ENABLE_ENCRYPT=true
52
+ VITE_GLOB_RSA_PUBLIC_KEY=...
53
+ VITE_GLOB_APP_CLIENT_ID=...
54
+ VITE_APP_STORE_SECURE_KEY=please-replace-me-with-your-own-key
55
+ ```
56
+
57
+ ## 提供能力
58
+
59
+ ### Token 和登录
60
+
61
+ - 按显式 token、`tokenProvider`、URL `runtimeToken`、明文存储、WiseAI SecureLS 存储的顺序获取 token。
62
+ - 兼容参考项目生产环境带版本号的 `*-prod-core-access` 加密 Pinia 登录态。
63
+ - 自动读取和保存开发环境的 `accessToken`。
64
+ - 自动检查 JWT 是否过期。
65
+ - 生产环境没有 token 时,通过 iframe `postMessage` 通知宿主重新登录。
66
+ - 开发环境没有 token 时,自动请求 `{javaBasePath}/auth/code` 获取验证码配置并弹出登录窗口。
67
+ - 根据 `captchaEnabled` 决定是否显示验证码。
68
+ - 登录接口默认使用 `POST {javaBasePath}/auth/login`,请求体不包含 `appCode`。
69
+ - 支持按参考项目规则使用 AES + RSA 加密登录请求。
70
+ - 业务请求自动携带 `Authorization: Bearer <token>`。
71
+
72
+ ### 接口请求
73
+
74
+ ```ts
75
+ const user = await sdk.get('/plugins/third-party-mysql-demo/me');
76
+
77
+ const result = await sdk.postJson('/some/api', {
78
+ name: 'demo',
79
+ });
80
+
81
+ const data = await sdk.request('/some/api', {
82
+ base: 'net',
83
+ method: 'PATCH',
84
+ params: { id: 1 },
85
+ body: { name: 'demo' },
86
+ bodyType: 'json',
87
+ headers: {
88
+ 'X-Custom-Header': 'value',
89
+ },
90
+ });
91
+ ```
92
+
93
+ 支持 `get`、`postJson` 和泛化 `request`。泛化请求支持自定义接口前缀、请求方法、查询参数、请求体类型和请求头。
94
+
95
+ ### 文件上传
96
+
97
+ ```ts
98
+ const result = await sdk.uploadFile(file, {
99
+ path: '/api/smart_classify/upload',
100
+ fileFieldName: 'file',
101
+ extraData: {
102
+ businessType: 'smart_classify',
103
+ },
104
+ });
105
+ ```
106
+
107
+ 上传请求使用 `FormData` 并自动携带 token。默认上传地址为 `/api/file/upload`,可通过 `path` 覆盖。
108
+
109
+ ### 路由权限
110
+
111
+ ```ts
112
+ const menus = await sdk.getRoutePermissions();
113
+ ```
114
+
115
+ 默认调用:
116
+
117
+ ```text
118
+ GET {netBasePath}/api/PluginApp/GetRouters?appCode={appCode}
119
+ ```
120
+
121
+ 返回路由菜单权限数据,宿主项目可以根据结果生成左侧菜单和受保护路由。
122
+
123
+ ### Token 清理
124
+
125
+ ```ts
126
+ sdk.clearToken();
127
+ ```
128
+
129
+ 完整的 SDK 开发维护说明见 [SDK-DEVELOPMENT.md](./SDK-DEVELOPMENT.md)。
130
+
131
+ ## 文件下载与流式接收(webapp-sdk 0.1.5)
132
+
133
+ 文件接口需要生产宿主 1.0.3 或开发宿主 0.1.9,以及 API SDK 0.1.7。
134
+
135
+ ```ts
136
+ const result = await sdk.downloadFile('/plugins/my-app/export', {
137
+ base: 'absolute',
138
+ timeoutMs: 300000
139
+ });
140
+ // result.blob 是文件内容,result.filename 是响应头中的文件名,result.contentType 是文件类型。
141
+ ```
142
+
143
+ `downloadFile()` 读取完整 Blob,不自动触发浏览器保存;大文件应使用流式接收:
144
+
145
+ ```ts
146
+ const abort = new AbortController();
147
+ const stream = await sdk.request<ReadableStream<Uint8Array>>('/plugins/my-app/export', {
148
+ base: 'absolute',
149
+ responseType: 'stream',
150
+ timeoutMs: 300000,
151
+ signal: abort.signal
152
+ });
153
+ const reader = stream.getReader();
154
+ try {
155
+ for (;;) {
156
+ const { value, done } = await reader.read();
157
+ if (done) {
158
+ break;
159
+ }
160
+ // 按块处理 value,不在这里累积整个大文件。
161
+ }
162
+ } finally {
163
+ await reader.cancel();
164
+ reader.releaseLock();
165
+ }
166
+ ```
167
+
168
+ - `responseType` 支持 json、text、blob、arrayBuffer、stream 和 response;response 返回含受管 body 的 Response,可读取响应头。
169
+ - 显式类型优先于 Content-Type,例如 CSV 下载可指定 blob,避免被自动解析为字符串。
170
+ - 超时在收到响应头后继续生效,直到响应体消费完成;单次 timeoutMs 不传时沿用 SDK requestTimeoutMs(默认 30 秒)。
171
+ - 用户取消可调用 abort.abort(),或 reader.cancel()/stream.cancel();结束后释放 reader。
172
+ - 不再需要响应体时必须取消,不能只拿到响应头后遗弃流。
173
+ - 大文件接收要同步处理或写入目标,避免使用 arrayBuffer/Blob 或自行累积全部字节。
174
+ - uploadFile() 同样支持 base、signal 和 timeoutMs,插件接口使用 base: 'absolute'。
175
+ - 浏览器上传仍可用 FormData 或 Blob;直接上传原始文件时设置 bodyType: 'raw' 和正确的 Content-Type。
176
+ - 流式传输开始后,服务端错误可能体现为读取异常,应在读取循环外捕获;不要只检查 HTTP 状态。
package/dist/http.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MenuPermissionNode, RequestOptions, UploadOptions, WiseAiFrontSdkOptions, WiseAiFrontSdkState } from './types';
1
+ import type { DownloadResult, MenuPermissionNode, RequestOptions, UploadOptions, WiseAiFrontSdkOptions, WiseAiFrontSdkState } from './types';
2
2
  export declare class WiseAiFrontSdk {
3
3
  private readonly appCode;
4
4
  private readonly captchaPath;
@@ -36,6 +36,8 @@ export declare class WiseAiFrontSdk {
36
36
  private buildHeaders;
37
37
  private resolveBase;
38
38
  request<T = unknown>(path: string, options?: RequestOptions): Promise<T>;
39
+ /** 接收文件及下载文件名;不自动触发浏览器保存。 */
40
+ downloadFile(path: string, options?: RequestOptions): Promise<DownloadResult>;
39
41
  private resolveRequestBody;
40
42
  get<T = unknown>(path: string, params?: Record<string, unknown>, options?: Omit<RequestOptions, 'body' | 'method' | 'params'>): Promise<T>;
41
43
  postJson<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'body' | 'method'>): Promise<T>;
package/dist/http.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { fetchManagedResponse, getDownloadFilename, readResponse } from './response-stream';
1
2
  import { notifyReloginRequired, } from './bridge';
2
3
  import { encryptRequestBody, } from './encryption';
3
4
  import { isJwtExpired, } from './jwt';
@@ -66,16 +67,6 @@ function toQueryString(params) {
66
67
  const query = search.toString();
67
68
  return query ? `?${query}` : '';
68
69
  }
69
- async function parseResponse(response) {
70
- const contentType = response.headers.get('content-type') || '';
71
- if (contentType.includes('application/json')) {
72
- return (await response.json());
73
- }
74
- if (contentType.includes('text/')) {
75
- return (await response.text());
76
- }
77
- return (await response.blob());
78
- }
79
70
  function unwrapEnvelope(body) {
80
71
  if (body &&
81
72
  typeof body === 'object' &&
@@ -275,23 +266,26 @@ export class WiseAiFrontSdk {
275
266
  const url = options.base === 'absolute' || /^https?:\/\//i.test(path)
276
267
  ? path
277
268
  : `${joinPath(base, path)}${toQueryString(options.params)}`;
278
- const controller = new AbortController();
279
- const timeout = window.setTimeout(() => controller.abort(), this.requestTimeoutMs);
280
- try {
281
- const response = await fetch(url, {
282
- body: this.resolveRequestBody(options.body, options.bodyType),
283
- headers: this.buildHeaders(options.headers, token, options.bodyType),
284
- method: options.method || 'GET',
285
- signal: controller.signal,
286
- });
287
- if (!response.ok) {
288
- throw new Error(`WiseAiFrontSDK: request failed with ${response.status}`);
289
- }
290
- return await parseResponse(response);
291
- }
292
- finally {
293
- window.clearTimeout(timeout);
269
+ const response = await fetchManagedResponse(url, {
270
+ body: this.resolveRequestBody(options.body, options.bodyType),
271
+ headers: this.buildHeaders(options.headers, token, options.bodyType),
272
+ method: options.method || 'GET',
273
+ signal: options.signal,
274
+ }, options.timeoutMs ?? this.requestTimeoutMs);
275
+ if (!response.ok) {
276
+ await response.body?.cancel();
277
+ throw new Error(`WiseAiFrontSDK: request failed with ${response.status}`);
294
278
  }
279
+ return readResponse(response, options.responseType);
280
+ }
281
+ /** 接收文件及下载文件名;不自动触发浏览器保存。 */
282
+ async downloadFile(path, options = {}) {
283
+ const response = await this.request(path, { ...options, responseType: 'response' });
284
+ return {
285
+ blob: await response.blob(),
286
+ filename: getDownloadFilename(response.headers.get('content-disposition')),
287
+ contentType: response.headers.get('content-type') || 'application/octet-stream',
288
+ };
295
289
  }
296
290
  resolveRequestBody(body, bodyType) {
297
291
  if (body === undefined || body === null || bodyType === undefined) {
@@ -345,6 +339,9 @@ export class WiseAiFrontSdk {
345
339
  formData.append(key, value);
346
340
  });
347
341
  return this.request(options.path || this.uploadPath, {
342
+ base: options.base,
343
+ signal: options.signal,
344
+ timeoutMs: options.timeoutMs,
348
345
  body: formData,
349
346
  bodyType: 'raw',
350
347
  headers: options.headers,
package/dist/index.d.ts CHANGED
@@ -2,6 +2,6 @@ export { decodeJwtPayload, isJwtExpired } from './jwt';
2
2
  export { notifyReloginRequired } from './bridge';
3
3
  import { WiseAiFrontSdk } from './http';
4
4
  export { persistToken, resolveTokenFromLocation, resolveTokenFromStorage, resolveTokensFromSecureStore, } from './storage';
5
- export type { ApiBase, HttpMethod, JwtPayload, LoginCredentials, LoginModalOptions, LoginResult, MenuPermissionNode, MenuRouteMeta, RequestBodyType, RequestOptions, UploadOptions, WiseAiEnvironment, WiseAiFrontSdkOptions, WiseAiFrontSdkState, } from './types';
5
+ export type { ApiBase, DownloadResult, HttpMethod, JwtPayload, LoginCredentials, LoginModalOptions, LoginResult, MenuPermissionNode, MenuRouteMeta, RequestBodyType, RequestOptions, UploadOptions, WiseAiEnvironment, WiseAiFrontSdkOptions, WiseAiFrontSdkState, } from './types';
6
6
  export { WiseAiFrontSdk } from './http';
7
7
  export declare function createWiseAiFrontSdk(options: import('./types').WiseAiFrontSdkOptions): WiseAiFrontSdk;
@@ -0,0 +1,7 @@
1
+ import type { RequestOptions } from './types';
2
+ /** 获取响应后仍保留超时及外部取消,直到响应体读完或主动 cancel。 */
3
+ export declare function fetchManagedResponse(url: string, options: RequestInit, timeoutMs: number): Promise<Response>;
4
+ /** 显式响应类型优先,文件即使使用 text 或 JSON 媒体类型也能按字节读取。 */
5
+ export declare function readResponse<T>(response: Response, type?: RequestOptions['responseType']): Promise<T>;
6
+ /** 优先解析 UTF-8 文件名;无效编码回退到普通 filename。 */
7
+ export declare function getDownloadFilename(disposition: string | null): string | undefined;
@@ -0,0 +1,112 @@
1
+ /** 获取响应后仍保留超时及外部取消,直到响应体读完或主动 cancel。 */
2
+ export async function fetchManagedResponse(url, options, timeoutMs) {
3
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
4
+ throw new Error('Request timeoutMs must be positive.');
5
+ }
6
+ const controller = new AbortController();
7
+ const signal = options.signal;
8
+ const onAbort = () => controller.abort(signal?.reason);
9
+ signal?.addEventListener('abort', onAbort, { once: true });
10
+ if (signal?.aborted) {
11
+ onAbort();
12
+ }
13
+ const timer = setTimeout(() => controller.abort(new DOMException('Request timed out.', 'TimeoutError')), timeoutMs);
14
+ const cleanup = () => {
15
+ clearTimeout(timer);
16
+ signal?.removeEventListener('abort', onAbort);
17
+ };
18
+ controller.signal.addEventListener('abort', cleanup, { once: true });
19
+ try {
20
+ const response = await fetch(url, { ...options, signal: controller.signal });
21
+ if (!response.body) {
22
+ cleanup();
23
+ return response;
24
+ }
25
+ const reader = response.body.getReader();
26
+ const body = new ReadableStream({
27
+ async pull(destination) {
28
+ try {
29
+ const { value, done } = await reader.read();
30
+ if (done) {
31
+ cleanup();
32
+ reader.releaseLock();
33
+ destination.close();
34
+ }
35
+ else {
36
+ destination.enqueue(value);
37
+ }
38
+ }
39
+ catch (error) {
40
+ cleanup();
41
+ reader.releaseLock();
42
+ destination.error(error);
43
+ }
44
+ },
45
+ async cancel(reason) {
46
+ try {
47
+ await reader.cancel(reason);
48
+ }
49
+ finally {
50
+ controller.abort(reason);
51
+ cleanup();
52
+ reader.releaseLock();
53
+ }
54
+ }
55
+ });
56
+ return new Response(body, {
57
+ status: response.status,
58
+ statusText: response.statusText,
59
+ headers: response.headers
60
+ });
61
+ }
62
+ catch (error) {
63
+ cleanup();
64
+ throw error;
65
+ }
66
+ }
67
+ /** 显式响应类型优先,文件即使使用 text 或 JSON 媒体类型也能按字节读取。 */
68
+ export async function readResponse(response, type) {
69
+ if (type === 'response') {
70
+ return response;
71
+ }
72
+ if (type === 'stream') {
73
+ return response.body;
74
+ }
75
+ if (type === 'arrayBuffer') {
76
+ return (await response.arrayBuffer());
77
+ }
78
+ if (type === 'blob') {
79
+ return (await response.blob());
80
+ }
81
+ if (type === 'json') {
82
+ return (await response.json());
83
+ }
84
+ if (type === 'text') {
85
+ return (await response.text());
86
+ }
87
+ const contentType = response.headers.get('content-type') || '';
88
+ if (contentType.includes('application/json')) {
89
+ return (await response.json());
90
+ }
91
+ if (contentType.includes('text/')) {
92
+ return (await response.text());
93
+ }
94
+ return (await response.blob());
95
+ }
96
+ /** 优先解析 UTF-8 文件名;无效编码回退到普通 filename。 */
97
+ export function getDownloadFilename(disposition) {
98
+ if (!disposition) {
99
+ return undefined;
100
+ }
101
+ const encoded = /filename\*\s*=\s*UTF-8''([^;]+)/i.exec(disposition);
102
+ if (encoded) {
103
+ try {
104
+ return decodeURIComponent(encoded[1].trim());
105
+ }
106
+ catch {
107
+ // 回退到不带编码的文件名。
108
+ }
109
+ }
110
+ const plain = /filename\s*=\s*(?:"([^"]*)"|([^;]*))/i.exec(disposition);
111
+ return plain ? (plain[1] ?? plain[2]).trim() : undefined;
112
+ }
package/dist/types.d.ts CHANGED
@@ -59,9 +59,18 @@ export interface RequestOptions {
59
59
  headers?: Record<string, string>;
60
60
  method?: HttpMethod;
61
61
  params?: Record<string, unknown>;
62
- responseType?: 'arrayBuffer' | 'blob' | 'json' | 'text';
62
+ responseType?: 'arrayBuffer' | 'blob' | 'json' | 'text' | 'stream' | 'response';
63
+ /** 外部取消信号,流式响应在消费完成或取消前保持有效。 */
64
+ signal?: AbortSignal;
65
+ /** 本次请求的总时限,包含响应体读取时间。 */
66
+ timeoutMs?: number;
63
67
  }
64
- export interface UploadOptions {
68
+ export interface DownloadResult {
69
+ blob: Blob;
70
+ filename?: string;
71
+ contentType: string;
72
+ }
73
+ export interface UploadOptions extends Pick<RequestOptions, 'base' | 'signal' | 'timeoutMs'> {
65
74
  extraData?: Record<string, string | Blob>;
66
75
  fileFieldName?: string;
67
76
  headers?: Record<string, string>;
package/package.json CHANGED
@@ -1,34 +1,35 @@
1
- {
2
- "name": "@workopilot/webapp-sdk",
3
- "version": "0.1.4",
4
- "description": "WiseAI front-end SDK for iframe-hosted third-party apps",
5
- "keywords": "wiseai,workopilot",
6
- "author": "workopilot",
7
- "license": "MIT",
8
- "type": "module",
9
- "main": "dist/index.js",
10
- "module": "dist/index.js",
11
- "types": "dist/index.d.ts",
12
- "exports": {
13
- ".": {
14
- "types": "./dist/index.d.ts",
15
- "import": "./dist/index.js"
16
- }
17
- },
18
- "files": [
19
- "dist",
20
- "README.md"
21
- ],
22
- "scripts": {
23
- "build": "tsc -p tsconfig.json"
24
- },
25
- "dependencies": {
26
- "crypto-js": "^4.2.0",
27
- "jsencrypt": "^3.3.2",
28
- "secure-ls": "^2.0.0"
29
- },
30
- "devDependencies": {
31
- "@types/crypto-js": "^4.2.2",
32
- "typescript": "^5.7.2"
33
- }
34
- }
1
+ {
2
+ "name": "@workopilot/webapp-sdk",
3
+ "version": "0.1.5",
4
+ "description": "WiseAI front-end SDK for iframe-hosted third-party apps",
5
+ "keywords": "wiseai,workopilot",
6
+ "author": "workopilot",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc -p tsconfig.json",
24
+ "test": "npm run build && node --test test/*.test.mjs"
25
+ },
26
+ "dependencies": {
27
+ "crypto-js": "^4.2.0",
28
+ "jsencrypt": "^3.3.2",
29
+ "secure-ls": "^2.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/crypto-js": "^4.2.2",
33
+ "typescript": "^5.7.2"
34
+ }
35
+ }