@heybox/hb-sdk 0.8.0-alpha → 0.8.0-alpha.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/CHANGELOG.md +36 -1
- package/README.md +67 -14
- package/THIRD_PARTY_NOTICES.md +1755 -0
- package/dist/cli-chunks/{build-DJWFSM1B.cjs → build-CCLWgXyA.cjs} +2 -2
- package/dist/cli-chunks/{context-DV2UK1Nz.cjs → context-Brh56h56.cjs} +1 -26
- package/dist/cli-chunks/{create-2HfoB48V.cjs → create-BZ-hi2s1.cjs} +1 -1
- package/dist/cli-chunks/{dev-Dgt2zS9k.cjs → dev-CoSXtEYa.cjs} +335 -516
- package/dist/cli-chunks/{doctor-C95gIao_.cjs → doctor-EsCYJGhV.cjs} +1 -1
- package/dist/cli-chunks/{index-D62ANeBv.cjs → index-BL5eEPap.cjs} +14 -14
- package/dist/cli-chunks/{index-BjoSXl8C.cjs → index-CS6Q0o5C.cjs} +1 -1
- package/dist/cli-chunks/{index.esm-CigcxJ2B.cjs → index.esm-BoBHPfpq.cjs} +5 -5
- package/dist/cli-chunks/{login-Cumknwdx.cjs → login-CILLxGuf.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-CcE-HMmd.cjs → project-vite-Qu6Xe9Dn.cjs} +1 -1
- package/dist/cli-chunks/{remote-DDdP3xcE.cjs → remote-DRuTQ51u.cjs} +4 -4
- package/dist/cli-chunks/{session-BDi_AZSv.cjs → session-D-_N3WVL.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-uq-Wac6k.js +97 -0
- package/dist/devtools/browser-dev-host/assets/heybox-logo-CogNENsk.svg +6 -0
- package/dist/devtools/browser-dev-host/assets/index-CeP6SLB3.js +567 -0
- package/dist/devtools/browser-dev-host/assets/index-KD2f3Jdz.css +1 -0
- package/dist/devtools/browser-dev-host/assets/workbench-state-D-1U0JRq.js +5 -0
- package/dist/devtools/browser-dev-host/index.html +6 -435
- package/dist/index.cjs.js +924 -28
- package/dist/index.esm.js +924 -29
- package/dist/protocol.cjs.js +208 -6
- package/dist/protocol.esm.js +182 -7
- package/dist/vite.cjs.js +1 -1
- package/dist/vite.esm.js +1 -1
- package/package.json +23 -9
- package/skill/SKILL.md +9 -5
- package/skill/references/api-protocol.md +99 -3
- package/skill/references/api-root.md +141 -14
- package/skill/references/cli.md +21 -17
- package/skill/references/examples.md +29 -0
- package/skill/references/recipes.md +105 -1
- package/skill/references/safety-boundaries.md +11 -0
- package/skill/scripts/sync-references.mjs +34 -2
- package/skill/skill.json +4 -4
- package/types/core/client.d.ts +17 -1
- package/types/core/sdk.d.ts +3 -0
- package/types/core/singleton.d.ts +3 -0
- package/types/index.d.ts +4 -2
- package/types/modules/files/index.d.ts +5 -0
- package/types/modules/files/registry.d.ts +35 -0
- package/types/modules/files/types.d.ts +159 -0
- package/types/modules/network/index.d.ts +50 -3
- package/types/protocol/capabilities.d.ts +2 -2
- package/types/protocol/constants.d.ts +1 -1
- package/types/protocol/guards.d.ts +1 -1
- package/types/protocol/types.d.ts +1 -1
- package/types/protocol.d.ts +4 -3
- package/dist/devtools/browser-dev-host/main.js +0 -12263
|
@@ -37,7 +37,7 @@ import hbSDK, { type MiniProgramSDKHandshakeState } from '@heybox/hb-sdk'
|
|
|
37
37
|
import { computed, onUnmounted, ref } from 'vue'
|
|
38
38
|
|
|
39
39
|
const handshakeState = ref<MiniProgramSDKHandshakeState>(hbSDK.getHandshakeState())
|
|
40
|
-
const stopHandshakeState = hbSDK.onHandshakeStateChange(
|
|
40
|
+
const stopHandshakeState = hbSDK.onHandshakeStateChange(state => {
|
|
41
41
|
handshakeState.value = state
|
|
42
42
|
})
|
|
43
43
|
const sdkReady = computed(() => handshakeState.value.status === 'ready')
|
|
@@ -93,6 +93,102 @@ async function loginFromUserAction() {
|
|
|
93
93
|
|
|
94
94
|
返回值与边界以[用户身份与登录](https://docs.xiaoheihe.cn/hb_sdk/guide/auth)为准。页面只把 `code` 提交给自己的服务端。不要在页面初始化阶段自动调用 `auth.login()`。
|
|
95
95
|
|
|
96
|
+
## 文件与下载
|
|
97
|
+
|
|
98
|
+
`files.sandbox` 是当前小程序隔离的逻辑根。`file()` / `directory()` 只创建 lazy proxy,不执行
|
|
99
|
+
I/O;第一次真实 I/O 仍由 Runtime 和 Host 校验当前 session、授权、mode、kind 和路径。
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import hbSDK, { HbMiniProgramSDKError } from '@heybox/hb-sdk'
|
|
103
|
+
|
|
104
|
+
const exportDirectory = hbSDK.files.sandbox.directory('exports')
|
|
105
|
+
await exportDirectory.create({ recursive: true })
|
|
106
|
+
|
|
107
|
+
const controller = new AbortController()
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const file = await hbSDK.network.download({
|
|
111
|
+
url: 'https://cdn.example.com/report.json',
|
|
112
|
+
to: exportDirectory,
|
|
113
|
+
suggestedName: 'report.json',
|
|
114
|
+
overwrite: true,
|
|
115
|
+
maxBytes: 8 * 1024 * 1024,
|
|
116
|
+
signal: controller.signal,
|
|
117
|
+
onProgress({ loaded, total, lengthComputable }) {
|
|
118
|
+
console.log(lengthComputable ? `${loaded}/${total}` : loaded)
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
console.log(await file.readText())
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (error instanceof HbMiniProgramSDKError && error.code === 'METHOD_FORBIDDEN') {
|
|
125
|
+
// 当前 Host 不支持 V1 文件能力。
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
throw error
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
当前平台状态如下:
|
|
133
|
+
|
|
134
|
+
| Host | `files.sandbox` | 外部 picker | `network.download()` |
|
|
135
|
+
| ---------------- | --------------- | ----------- | -------------------- |
|
|
136
|
+
| 旧版 PC | 不支持 | 不支持 | 不支持 |
|
|
137
|
+
| Mobile | 不支持 | 不支持 | 不支持 |
|
|
138
|
+
| Web | 不支持 | 不支持 | 不支持 |
|
|
139
|
+
| Browser Dev Host | 不支持 | 不支持 | 不支持 |
|
|
140
|
+
|
|
141
|
+
当前 Runtime 认识但 Host 未实现时返回 `METHOD_FORBIDDEN`;旧 Runtime 收到新 method 时返回
|
|
142
|
+
`METHOD_NOT_FOUND`。此前曾实现面向旧版小黑盒 PC 的 Host 适配;由于新版 PC 即将启用,该适配
|
|
143
|
+
不再发布。文件/下载 API、协议和 Runtime 体系保持不变,后续直接按照新版 PC Host 架构接入。
|
|
144
|
+
当前任何 Host 都不提供 Blob 或内存假下载。
|
|
145
|
+
|
|
146
|
+
### 路径与创建
|
|
147
|
+
|
|
148
|
+
- 逻辑相对路径统一使用 `/`。拒绝空字符串、绝对路径、空 segment、`.`、`..`、反斜杠、尾分隔符、NUL 和控制字符。
|
|
149
|
+
- `create()` 的 `recursive` 与 `exclusive` 默认均为 `false`。默认行为是不截断内容的 ensure-exists;`exclusive: true` 在同名实体已存在时失败。
|
|
150
|
+
- `writeText()` / `writeBytes()` 可以在父目录存在时隐式创建目标,但不会自动创建父目录。
|
|
151
|
+
- `exists()` 在祖先/目标缺失或 kind mismatch 时返回 `false`;授权撤销、quota 与 I/O 错误仍抛出。
|
|
152
|
+
- `file.remove()` 与 `directory.remove()` 只删除 sandbox 对象;外部 picker/saveFile 授权调用删除时抛出 `FILE_ACCESS_DENIED`。
|
|
153
|
+
- 非空目录默认不能删除并抛出 `DIRECTORY_NOT_EMPTY`;确认删除整个目录树后显式调用 `directory.remove({ recursive: true })`。
|
|
154
|
+
- `directory.list()` 默认最多返回 1000 项,显式 `limit` 也不能超过 1000;超限抛出 `DIRECTORY_LIST_LIMIT_EXCEEDED`。
|
|
155
|
+
- Host 文件错误只暴露稳定 code 与 canonical 安全文案;原始 message、data、native path 和 credential 不会进入小程序。
|
|
156
|
+
- `FileStat.size` 是字节数;`modifiedAt` / `createdAt` 若存在,单位为 Unix epoch milliseconds。
|
|
157
|
+
|
|
158
|
+
### 外部授权与保存
|
|
159
|
+
|
|
160
|
+
`pickFiles()`、`pickDirectory()` 和 `saveFile()` 必须直接从按钮点击等可信用户操作调用。picker
|
|
161
|
+
取消会抛 `FILE_PICKER_CANCELLED`,不会返回空数组或 `undefined`。
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
async function saveFromUserAction(text: string) {
|
|
165
|
+
const file = await hbSDK.files.saveFile({ suggestedName: 'report.json' })
|
|
166
|
+
await file.writeText(text)
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
`saveFile()` 打开系统保存对话框并返回精确 File 授权,不会同时创建或保留 Directory
|
|
171
|
+
授权。V1 不接受 `accept`;扩展名过滤只属于 `pickFiles({ accept: ['.json'] })`。外部授权仅在当前
|
|
172
|
+
Runtime session 有效。
|
|
173
|
+
|
|
174
|
+
`pickFiles()` / `pickDirectory()` 默认返回 `mode: 'read'` 的授权;只有显式传入
|
|
175
|
+
`multiple: true` 时,`pickFiles()` 才允许 Host 返回多个文件。需要修改文件、在所选目录中创建
|
|
176
|
+
文件,或把外部授权用作下载目标时,必须在 picker options 中显式请求 `mode: 'readwrite'`。
|
|
177
|
+
|
|
178
|
+
单个 Runtime session 最多保留 1024 个 picker/saveFile direct handle;整批选择超过剩余额度时抛出 `FILE_QUOTA_EXCEEDED`,不会保留部分授权。Sandbox 派生项与目录枚举结果使用逻辑引用,不持续占用该额度。
|
|
179
|
+
|
|
180
|
+
### 下载边界
|
|
181
|
+
|
|
182
|
+
- 下载固定使用 GET,不接受 method、body、上传或 Range 字段。
|
|
183
|
+
- File target 必须已存在且为 `readwrite`,成功后返回同一个 File proxy;Directory target 必须存在且为 `readwrite`,成功后返回新的子 File proxy。
|
|
184
|
+
- Directory 默认不覆盖同名文件;只有显式 `overwrite: true` 才允许原子替换。
|
|
185
|
+
- Directory target 的子文件名按安全的 `Content-Disposition filename*` / `filename`、`suggestedName`、URL basename、`download.bin` 依次选择。
|
|
186
|
+
- `timeout` 是网络空闲超时,不是整个下载总时长。取消或失败不会改动原目标。
|
|
187
|
+
- `AbortSignal` 只发出取消意图并等待 Host 终态;如果 Host 已先完成原子提交,Promise 仍以成功结果 resolve,否则抛出 `DOWNLOAD_CANCELLED`。
|
|
188
|
+
- 公开 request 与 download 都不跟随重定向;3xx 或 partial representation 会失败。
|
|
189
|
+
- 进度从 `loaded: 0` 开始并单调不减;原子提交后、Promise resolve 前会再发送一次 final progress,因此空文件或 Host 已报告最终值时允许相邻值相同。只有无歧义、identity-encoded 的 `Content-Length` 才使 `lengthComputable=true`;压缩、chunked 或重复长度都视为未知 total,可信长度必须在提交前与实际字节数一致。
|
|
190
|
+
- `onProgress` 在本地同步执行;回调异常不会中断下载。成功时最后一次回调发生在文件提交后、Promise resolve 前。
|
|
191
|
+
|
|
96
192
|
## 默认单例
|
|
97
193
|
|
|
98
194
|
大多数小程序页面都应该使用默认实例。0.6 起不再对业务代码提供独立实例工厂。
|
|
@@ -316,6 +412,10 @@ try {
|
|
|
316
412
|
- `USER_GESTURE_REQUIRED` 表示潜在授权 UI 缺少可信用户手势,应让用户点击按钮后重试。
|
|
317
413
|
- `AUTHORIZATION_CANCELLED` 表示用户取消、拒绝或关闭授权页面,应正常结束当前操作。
|
|
318
414
|
- `SERVER_API_REQUIRED` 表示当前用户数据必须经开发者服务端 OpenAPI 获取,不应在页面重试对应 Host API。
|
|
415
|
+
- `METHOD_FORBIDDEN` 表示当前 Host 未实现或关闭对应能力。V1 files/download 在 Mobile、Web 和 Browser Dev Host 都会得到该错误。
|
|
416
|
+
- `FILE_PICKER_CANCELLED` 表示用户取消了外部文件或目录选择,应正常结束当前操作。
|
|
417
|
+
- `DOWNLOAD_CANCELLED` 表示取消意图先于 Host 提交生效;Host 已完成提交时仍返回成功。`DOWNLOAD_TIMEOUT` 表示网络空闲超时,失败不会改动原目标。
|
|
418
|
+
- `DOWNLOAD_HTTP_STATUS` 的 `data` 只包含脱敏后的 `status`、可选 `statusText` 和安全响应头。
|
|
319
419
|
- 超时或运行环境不可用时,允许用户重试或退出当前流程。
|
|
320
420
|
- 上报 `code`、`message` 和必要的业务上下文,不要上报用户凭据或敏感数据。
|
|
321
421
|
|
|
@@ -364,6 +464,10 @@ function reportSDKError(errorCode: string, message: string, data?: unknown) {
|
|
|
364
464
|
|
|
365
465
|
授权码在取得后立即交给开发者服务端交换,不要写入页面状态、DOM、日志或持久化存储。UI 只处理服务端会话是否建立成功。
|
|
366
466
|
|
|
467
|
+
文件与下载仍使用 `HbMiniProgramSDKError`,不会新增第三种错误类。业务根据 `error.code` 处理
|
|
468
|
+
picker 取消、授权撤销、文件缺失、quota、下载状态或取消,不依赖 `message` 文案,也不要记录
|
|
469
|
+
真实路径、内部 handle 或响应凭据头。
|
|
470
|
+
|
|
367
471
|
## Login gate recipe
|
|
368
472
|
|
|
369
473
|
|
|
@@ -21,8 +21,19 @@
|
|
|
21
21
|
- `user.revokeAuthorization()` 在两种网络模式下都要求可信用户手势;成功后必须停止使用并清理业务缓存的旧身份、资料和服务端会话。
|
|
22
22
|
- `on()` 返回取消监听函数,组件卸载或页面销毁时需要调用。
|
|
23
23
|
- 业务网络请求使用 `network.request()`,不要依赖浏览器原生网络出口。
|
|
24
|
+
- 公开 `network.request()` 与 `network.download()` 均使用 no-follow redirect policy;3xx 不会在 Host 内静默跳转。
|
|
24
25
|
- `network.request()` 不能访问平台保留的 runtime auth 与 OpenAPI 内部路径;页面不得持有或交换服务端应用凭据。
|
|
25
26
|
- `network.request` 不支持 `multipart/form-data`;App Host 仅支持 form(`application/x-www-form-urlencoded`)与 JSON。表单请用 `URLSearchParams#toString()` 作为 `data`,文件上传请走专用上传能力。
|
|
27
|
+
- 当前 Host(包括旧版 PC、Mobile、Web 与 Browser Dev Host)均未开放 `files` / `network.download()`;新版 PC 将按同一公开合同重新接入,期间不提供内存或 Blob 假实现。
|
|
28
|
+
- picker 必须来自可信用户手势;取消选择返回 `FILE_PICKER_CANCELLED`。`saveFile()` 只接受 `suggestedName`,不接受 `accept`。
|
|
29
|
+
- `pickFiles()` / `pickDirectory()` 默认只读;`pickFiles()` 仅在显式传入 `multiple: true` 时允许 Host 返回多个文件。要写入或作为下载目标时显式请求 `mode: 'readwrite'`。
|
|
30
|
+
- `file()` / `directory()` 只接受以 `/` 分隔的规范相对路径;拒绝绝对路径、空 segment、`.`、`..`、反斜杠、尾分隔符和控制字符。
|
|
31
|
+
- `create()` 的 `recursive` / `exclusive` 默认都是 `false`;`exists()` 仅把缺失祖先、缺失目标或 kind mismatch 归一为 `false`,不会吞授权和 I/O 错误。
|
|
32
|
+
- `remove()` 只允许删除 sandbox 对象;外部 picker/saveFile 授权返回 `FILE_ACCESS_DENIED`。非空目录默认返回 `DIRECTORY_NOT_EMPTY`,需显式调用 `remove({ recursive: true })`。
|
|
33
|
+
- `directory.list()` 默认最多返回 1000 项,`limit` 也不能超过 1000;超限返回 `DIRECTORY_LIST_LIMIT_EXCEEDED`。
|
|
34
|
+
- 单个 Runtime session 最多保留 1024 个 picker/saveFile direct handle;整批授权超限时返回 `FILE_QUOTA_EXCEEDED`,不会保留部分结果。
|
|
35
|
+
- Host 文件错误只保留稳定 code 与 canonical 安全文案;原始 message、data、native path 和 credential 不会进入小程序。
|
|
36
|
+
- `FileStat.size` 是非负 safe integer;`modifiedAt` / `createdAt` 若存在,单位为 Unix epoch milliseconds。
|
|
26
37
|
- 仅当远端已启用 `network.request` 时,`hb-sdk dev` 与 `hb-sdk remote deploy` 构建才会跳过平台 CSP;其他构建继续注入平台 CSP。`useOfficialDomain` 不参与 CSP 跳过判定。
|
|
27
38
|
- 构建必须启用 `miniappManifest({ platforms })` 并显式声明实际承诺适配的平台,推荐统一使用 `hb-sdk build`。新项目模板中的 `['android', 'ios', 'ohos']` 只是初始配置,不代表已经完成真机验收。
|
|
28
39
|
|
|
@@ -383,7 +383,7 @@ files.set(
|
|
|
383
383
|
['Update reminders', 'update-reminders'],
|
|
384
384
|
])}## When to use the CLI
|
|
385
385
|
|
|
386
|
-
Use the bundled \`hb-sdk\` CLI to create a workshop mini-program, open the local debugging
|
|
386
|
+
Use the bundled \`hb-sdk\` CLI to create a workshop mini-program, open the local Browser debugging workbench, test in the Heybox mobile App, or manage and publish a remote mini-program.
|
|
387
387
|
|
|
388
388
|
\`hb-sdk login\` is for development and publishing commands only. It does not authorize mini-program users and does not change \`auth.login()\`, \`user.getInfo()\`, or \`network.request()\` inside a mini-program.
|
|
389
389
|
|
|
@@ -408,7 +408,9 @@ Agent rules:
|
|
|
408
408
|
|
|
409
409
|
${cliDevSection}
|
|
410
410
|
|
|
411
|
-
Use \`hb-sdk dev\` to open the local
|
|
411
|
+
Use \`hb-sdk dev\` to open the local Vue 3 debugging workbench. Browser debugging can start without CLI login, project binding, or a remote Dev Context; capabilities that need them fail explicitly. The upper-right QR popover is the only Mobile entry and requires selecting a LAN interface the phone can reach.
|
|
412
|
+
|
|
413
|
+
The workbench offers iPhone 16 Pro Max (\`440 x 956\`) and Pixel 9 Pro (\`410 x 914\`) presets. Switching presets preserves the iframe, Runtime session, and page state. Authorization/action dialogs, Toast, Loading, and vibration feedback render inside the preview. Do not suggest a debugging-page permission editor; it does not exist, and the validated remote permission snapshot remains canonical.
|
|
412
414
|
|
|
413
415
|
Browser Mock uses the Node \`hb-sdk login\` session to send Host \`heybox-session\` requests. Mini-program code must still call \`auth.login()\`; the debug page only shows an authorization dialog. Never copy pkey, cookies, tokens, or credential-bearing URLs into page JavaScript or logs. Phone debugging continues to use the App login, not the CLI session.
|
|
414
416
|
|
|
@@ -694,6 +696,34 @@ try {
|
|
|
694
696
|
}`,
|
|
695
697
|
)}
|
|
696
698
|
|
|
699
|
+
### Sandbox download contract (Host pending)
|
|
700
|
+
|
|
701
|
+
${fenced(
|
|
702
|
+
'ts',
|
|
703
|
+
`import { files, network, HbMiniProgramSDKError } from '@heybox/hb-sdk';
|
|
704
|
+
|
|
705
|
+
export async function downloadReport() {
|
|
706
|
+
const directory = files.sandbox.directory('exports');
|
|
707
|
+
await directory.create({ recursive: true });
|
|
708
|
+
|
|
709
|
+
try {
|
|
710
|
+
return await network.download({
|
|
711
|
+
url: 'https://cdn.example.com/report.json',
|
|
712
|
+
to: directory,
|
|
713
|
+
suggestedName: 'report.json',
|
|
714
|
+
onProgress: ({ loaded, total, lengthComputable }) => {
|
|
715
|
+
console.log(lengthComputable ? [loaded, total].join('/') : loaded);
|
|
716
|
+
},
|
|
717
|
+
});
|
|
718
|
+
} catch (error) {
|
|
719
|
+
if (error instanceof HbMiniProgramSDKError && error.code === 'METHOD_FORBIDDEN') {
|
|
720
|
+
return undefined;
|
|
721
|
+
}
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
}`,
|
|
725
|
+
)}
|
|
726
|
+
|
|
697
727
|
### Host/runtime protocol import
|
|
698
728
|
|
|
699
729
|
${fenced(
|
|
@@ -751,6 +781,8 @@ export default defineConfig({
|
|
|
751
781
|
- Do not call unsupported storage delete/clear/info operations.
|
|
752
782
|
- Do not pass raw internal share/network protocol fields from mini-program code.
|
|
753
783
|
- Do not send \`multipart/form-data\` (or handcrafted multipart bodies) through \`network.request\`; use form-urlencoded string body or a dedicated upload capability.
|
|
784
|
+
- Do not pass string paths, browser File System Access handles, Blob targets, Range/resume fields, or upload bodies to \`network.download\`; use SDK-created File/Directory handles after a supporting Host is available.
|
|
785
|
+
- Do not treat any current Host, including legacy PC or Browser Dev Host, as evidence for files/download support. They return \`METHOD_FORBIDDEN\` and provide no memory fallback; the new PC Host will integrate the retained contract separately.
|
|
754
786
|
- Do not treat \`hb-sdk login\` as iframe SDK authentication state.
|
|
755
787
|
- Do not create a second mock runtime package when \`hb-sdk dev\` is the supported local mock workflow.
|
|
756
788
|
- Do not import \`@heybox/hb-sdk/vite\` from iframe business code or fetch a deployed \`manifest.json\` directly.
|
package/skill/skill.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hb-sdk",
|
|
3
|
-
"skillVersion": "0.8.0-alpha+skill.
|
|
3
|
+
"skillVersion": "0.8.0-alpha.2+skill.417e5072238c",
|
|
4
4
|
"sdk": {
|
|
5
5
|
"package": "@heybox/hb-sdk",
|
|
6
|
-
"version": "0.8.0-alpha",
|
|
7
|
-
"compatibility": "0.8.0-alpha"
|
|
6
|
+
"version": "0.8.0-alpha.2",
|
|
7
|
+
"compatibility": "0.8.0-alpha.2"
|
|
8
8
|
},
|
|
9
9
|
"source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
|
|
10
|
-
"integrity": "sha256-
|
|
10
|
+
"integrity": "sha256-417e5072238c0b2a53836824d60639046935ad28ca337a63d82016421c97127b"
|
|
11
11
|
}
|
package/types/core/client.d.ts
CHANGED
|
@@ -25,8 +25,18 @@ export interface MiniProgramRequester {
|
|
|
25
25
|
/** 向父容器调用指定开放能力。 */
|
|
26
26
|
request<Method extends MiniProgramBridgeMethod>(method: Method, ...args: MiniProgramRequesterArgs<Method>): Promise<MiniProgramCapabilityResult<Method>>;
|
|
27
27
|
}
|
|
28
|
+
/** 长操作使用的本地 observer 与取消配置,不进入 bridge payload。 */
|
|
29
|
+
export interface MiniProgramOperationOptions<TProgress = unknown> {
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
onProgress?: (progress: TProgress) => void;
|
|
32
|
+
createAbortError?: () => unknown;
|
|
33
|
+
}
|
|
34
|
+
/** 支持 request-scoped progress/cancel 的 bridge requester。 */
|
|
35
|
+
export interface MiniProgramOperationRequester extends MiniProgramRequester {
|
|
36
|
+
requestOperation<Method extends MiniProgramBridgeMethod, TProgress = unknown>(method: Method, payload: MiniProgramCapabilityPayload<Method>, options?: MiniProgramOperationOptions<TProgress>): Promise<MiniProgramCapabilityResult<Method>>;
|
|
37
|
+
}
|
|
28
38
|
/** 底层 bridge client,负责握手、请求响应、事件分发与超时清理。 */
|
|
29
|
-
export declare class MiniProgramBridgeClient implements
|
|
39
|
+
export declare class MiniProgramBridgeClient implements MiniProgramOperationRequester {
|
|
30
40
|
private readonly timeout;
|
|
31
41
|
private readonly selfWindow?;
|
|
32
42
|
private readonly targetWindow;
|
|
@@ -64,6 +74,9 @@ export declare class MiniProgramBridgeClient implements MiniProgramRequester {
|
|
|
64
74
|
off<T extends MiniProgramEventName>(eventName: T, handler: MiniProgramEventHandler<T>): void;
|
|
65
75
|
/** 调用父容器开放能力。 */
|
|
66
76
|
request<Method extends MiniProgramBridgeMethod>(method: Method, ...args: MiniProgramRequesterArgs<Method>): Promise<MiniProgramCapabilityResult<Method>>;
|
|
77
|
+
/** 发起不使用固定总时长 timer 的长操作。 */
|
|
78
|
+
requestOperation<Method extends MiniProgramBridgeMethod, TProgress = unknown>(method: Method, payload: MiniProgramCapabilityPayload<Method>, options?: MiniProgramOperationOptions<TProgress>): Promise<MiniProgramCapabilityResult<Method>>;
|
|
79
|
+
private performRequest;
|
|
67
80
|
/** 销毁 SDK 实例,并拒绝尚未完成的请求。 */
|
|
68
81
|
destroy(): void;
|
|
69
82
|
private ensureStarted;
|
|
@@ -73,6 +86,9 @@ export declare class MiniProgramBridgeClient implements MiniProgramRequester {
|
|
|
73
86
|
private postCSPViolation;
|
|
74
87
|
private handleEvent;
|
|
75
88
|
private handleResponse;
|
|
89
|
+
private handleOperationProgress;
|
|
90
|
+
private sendCancel;
|
|
91
|
+
private cleanupPending;
|
|
76
92
|
private postMessage;
|
|
77
93
|
private resolveHandshakeOnce;
|
|
78
94
|
private failHandshake;
|
package/types/core/sdk.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type MiniProgramCloudModule } from '../modules/cloud';
|
|
|
4
4
|
import { type MiniProgramShareModule } from '../modules/share';
|
|
5
5
|
import { type MiniProgramStorageModule } from '../modules/storage';
|
|
6
6
|
import { type MiniProgramNetworkModule } from '../modules/network';
|
|
7
|
+
import { type FilesModule } from '../modules/files';
|
|
7
8
|
import { type MiniProgramViewportModule } from '../modules/viewport';
|
|
8
9
|
import { type MiniProgramUserModule } from '../modules/user';
|
|
9
10
|
import { type MiniProgramUiModule } from '../modules/ui';
|
|
@@ -37,6 +38,8 @@ export declare class MiniProgramSDK {
|
|
|
37
38
|
readonly storage: MiniProgramStorageModule;
|
|
38
39
|
/** 网络请求相关开放能力。 */
|
|
39
40
|
readonly network: MiniProgramNetworkModule;
|
|
41
|
+
/** 受控文件与目录能力。 */
|
|
42
|
+
readonly files: FilesModule;
|
|
40
43
|
/** UI 交互相关开放能力。 */
|
|
41
44
|
readonly ui: MiniProgramUiModule;
|
|
42
45
|
/** 设备相关开放能力。 */
|
|
@@ -3,6 +3,7 @@ import type { MiniProgramCloudModule } from '../modules/cloud';
|
|
|
3
3
|
import type { MiniProgramShareModule } from '../modules/share';
|
|
4
4
|
import type { MiniProgramStorageModule } from '../modules/storage';
|
|
5
5
|
import type { MiniProgramNetworkModule } from '../modules/network';
|
|
6
|
+
import type { FilesModule } from '../modules/files';
|
|
6
7
|
import type { MiniProgramViewportModule } from '../modules/viewport';
|
|
7
8
|
import type { MiniProgramUserModule } from '../modules/user';
|
|
8
9
|
import type { MiniProgramUiModule } from '../modules/ui';
|
|
@@ -92,6 +93,8 @@ export declare const viewport: MiniProgramViewportModule;
|
|
|
92
93
|
export declare const storage: MiniProgramStorageModule;
|
|
93
94
|
/** 默认 SDK 实例的 network 模块。 */
|
|
94
95
|
export declare const network: MiniProgramNetworkModule;
|
|
96
|
+
/** 默认 SDK 实例的 files 模块。 */
|
|
97
|
+
export declare const files: FilesModule;
|
|
95
98
|
/** 默认 SDK 实例的 UI 模块。 */
|
|
96
99
|
export declare const ui: MiniProgramUiModule;
|
|
97
100
|
/** 默认 SDK 实例的 device 模块。 */
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { HbMiniProgramSDKError, HbMiniProgramNetworkError } from './core/errors';
|
|
2
|
-
export { getHandshakeState, onHandshakeStateChange, on, off, auth, user, share, viewport, storage, network, ui, device, navigation, cloud, } from './core/singleton';
|
|
2
|
+
export { getHandshakeState, onHandshakeStateChange, on, off, auth, user, share, viewport, storage, files, network, ui, device, navigation, cloud, } from './core/singleton';
|
|
3
3
|
export type { MiniProgramSDKHandshakeState, MiniProgramSDKHandshakeStateHandler } from './core/handshake-state';
|
|
4
4
|
export type { MiniProgramEventHandler, MiniProgramEventName, MiniProgramEventPayloadMap } from './protocol/types';
|
|
5
5
|
export type { LoginOptions, LoginPayload, LoginResult, LoginScope, MiniProgramAuthModule } from './modules/auth';
|
|
@@ -10,7 +10,8 @@ export type { UserInfoAuthorizationScope } from './modules/user';
|
|
|
10
10
|
export type { CopyLinkPayload, CopyLinkResult, MiniProgramCopyLinkOptions, MiniProgramScreenshotOptions, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareExtraValue, MiniProgramShareModule, MiniProgramSharePostOptions, MiniProgramShowShareMenuOptions, ScreenshotPayload, ScreenshotResult, ShowShareMenuPayload, ShowShareMenuResult, } from './modules/share';
|
|
11
11
|
export type { GetWindowInfoPayload, GetWindowInfoResult, MiniProgramNavigationBarForegroundStyle, MiniProgramSafeArea, MiniProgramSetNavigationBarStyleOptions, MiniProgramViewportModule, MiniProgramWindowInfoResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, } from './modules/viewport';
|
|
12
12
|
export type { GetStoragePayload, GetStorageResult, MiniProgramStorageModule, SetStoragePayload } from './modules/storage';
|
|
13
|
-
export type { MiniProgramNetworkHeaders, MiniProgramNetworkModule, MiniProgramNetworkParams, MiniProgramNetworkRequestConfig, MiniProgramNetworkRequestMethod, MiniProgramNetworkResponse, MiniProgramNetworkValidateStatus, NetworkRequestPayload, NetworkResponsePayload, } from './modules/network';
|
|
13
|
+
export type { DownloadBaseOptions, DownloadOptions, DownloadProgress, MiniProgramNetworkHeaders, MiniProgramNetworkModule, MiniProgramNetworkParams, MiniProgramNetworkRequestConfig, MiniProgramNetworkRequestMethod, MiniProgramNetworkResponse, MiniProgramNetworkValidateStatus, NetworkRequestPayload, NetworkResponsePayload, } from './modules/network';
|
|
14
|
+
export type { CreateOptions, DirectoryHandle, FileHandle, FileMode, FileStat, FileSystem, FileSystemEntity, FilesModule, ListOptions, PathRoot, PickDirectoryOptions, PickFilesOptions, RemoveOptions, SaveFileOptions, } from './modules/files';
|
|
14
15
|
export type { HideLoadingPayload, HideLoadingResult, MiniProgramToastStatus, MiniProgramUiModule, ShowLoadingPayload, ShowLoadingResult, ShowToastPayload, ShowToastResult, } from './modules/ui';
|
|
15
16
|
export type { MiniProgramDeviceModule, MiniProgramVibrateIntensity, SetClipboardPayload, SetClipboardResult, VibratePayload, VibrateResult, } from './modules/device';
|
|
16
17
|
export type { ClosePayload, CloseResult, MiniProgramAppPageTarget, MiniProgramGameDetailGameType, MiniProgramGameDetailPage, MiniProgramNavigationModule, OpenAppPageOptions, OpenAppPagePayload, OpenAppPageResult, OpenGameDetailAppPagePayload, OpenGameDetailAppPageOptions, OpenPostDetailAppPagePayload, OpenPostDetailAppPageOptions, OpenUserDetailAppPagePayload, OpenUserDetailAppPageOptions, ReloadPayload, ReloadResult, } from './modules/navigation';
|
|
@@ -25,6 +26,7 @@ declare const hbSDK: {
|
|
|
25
26
|
share: import(".").MiniProgramShareModule;
|
|
26
27
|
viewport: import(".").MiniProgramViewportModule;
|
|
27
28
|
storage: import(".").MiniProgramStorageModule;
|
|
29
|
+
files: import(".").FilesModule;
|
|
28
30
|
network: import(".").MiniProgramNetworkModule;
|
|
29
31
|
ui: import(".").MiniProgramUiModule;
|
|
30
32
|
device: import(".").MiniProgramDeviceModule;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MiniProgramRequester } from '../../core/client';
|
|
2
|
+
import type { FilesModule } from './types';
|
|
3
|
+
export type { CreateOptions, DirectoryHandle, FileHandle, FileMode, FileStat, FileSystem, FileSystemEntity, FilesModule, ListOptions, PathRoot, PickDirectoryOptions, PickFilesOptions, RemoveOptions, SaveFileOptions, } from './types';
|
|
4
|
+
/** 创建当前 SDK session 的 files 模块。 */
|
|
5
|
+
export declare function createFilesModule(requester: MiniProgramRequester): FilesModule;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MiniProgramRequester } from '../../core/client';
|
|
2
|
+
import type { MiniProgramDirectoryDescriptor, MiniProgramDirectoryRef, MiniProgramFileDescriptor, MiniProgramFileMode, MiniProgramFileRef, MiniProgramFileSystemEntityDescriptor } from '@heybox/hb-sdk-protocol';
|
|
3
|
+
import type { DirectoryHandle, FileHandle, FileSystem, FileSystemEntity } from './types';
|
|
4
|
+
interface FileHandleState {
|
|
5
|
+
ref: MiniProgramFileRef;
|
|
6
|
+
mode: MiniProgramFileMode;
|
|
7
|
+
}
|
|
8
|
+
interface DirectoryHandleState {
|
|
9
|
+
ref: MiniProgramDirectoryRef;
|
|
10
|
+
mode: MiniProgramFileMode;
|
|
11
|
+
}
|
|
12
|
+
/** 校验并返回平台无关的 `/` 分隔逻辑相对路径。 */
|
|
13
|
+
export declare function normalizeRelativePath(value: unknown): string;
|
|
14
|
+
export declare class MiniProgramFileHandleRegistry {
|
|
15
|
+
private readonly requester;
|
|
16
|
+
private readonly fileStates;
|
|
17
|
+
private readonly directoryStates;
|
|
18
|
+
private readonly pathRootStates;
|
|
19
|
+
private sandboxRoot?;
|
|
20
|
+
constructor(requester: MiniProgramRequester);
|
|
21
|
+
getSandbox(): FileSystem;
|
|
22
|
+
createFile(descriptor: MiniProgramFileDescriptor): FileHandle;
|
|
23
|
+
createDirectFile(descriptor: MiniProgramFileDescriptor): FileHandle;
|
|
24
|
+
createDirectory(descriptor: MiniProgramDirectoryDescriptor): DirectoryHandle;
|
|
25
|
+
createDirectDirectory(descriptor: MiniProgramDirectoryDescriptor): DirectoryHandle;
|
|
26
|
+
createEntity(descriptor: MiniProgramFileSystemEntityDescriptor): FileSystemEntity;
|
|
27
|
+
requireFile(handle: unknown): FileHandleState;
|
|
28
|
+
requireDirectory(handle: unknown): DirectoryHandleState;
|
|
29
|
+
private definePathRootMethods;
|
|
30
|
+
private assertFileDescriptor;
|
|
31
|
+
private assertDirectoryDescriptor;
|
|
32
|
+
}
|
|
33
|
+
export declare function getFileHandleRegistry(requester: MiniProgramRequester): MiniProgramFileHandleRegistry;
|
|
34
|
+
export declare function isMiniProgramFileSystemValue(value: unknown): value is FileSystem | FileSystemEntity;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/** File/Directory 访问模式。 */
|
|
2
|
+
export type FileMode = 'read' | 'readwrite';
|
|
3
|
+
export interface PickFilesOptions {
|
|
4
|
+
mode?: FileMode;
|
|
5
|
+
accept?: string[];
|
|
6
|
+
multiple?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface PickDirectoryOptions {
|
|
9
|
+
mode?: FileMode;
|
|
10
|
+
}
|
|
11
|
+
export interface SaveFileOptions {
|
|
12
|
+
suggestedName: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CreateOptions {
|
|
15
|
+
recursive?: boolean;
|
|
16
|
+
exclusive?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface RemoveOptions {
|
|
19
|
+
/** 是否递归删除目录内容,默认 `false`。 */
|
|
20
|
+
recursive?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ListOptions {
|
|
23
|
+
limit?: number;
|
|
24
|
+
}
|
|
25
|
+
/** 可同步派生 lazy File/Directory proxy 的逻辑根。 */
|
|
26
|
+
export interface PathRoot {
|
|
27
|
+
/**
|
|
28
|
+
* 按规范相对路径派生文件代理。
|
|
29
|
+
*
|
|
30
|
+
* @param relativePath - 使用 `/` 分隔的规范相对路径。
|
|
31
|
+
* @returns 延迟访问对应文件的代理。
|
|
32
|
+
* @since 0.8.0-alpha.2
|
|
33
|
+
* @hbPlatform android
|
|
34
|
+
* @hbPlatform ios
|
|
35
|
+
* @hbPlatform ohos
|
|
36
|
+
* @hbPlatform windows
|
|
37
|
+
* @hbPlatform macos
|
|
38
|
+
* @hbClient android none
|
|
39
|
+
* @hbClient ios none
|
|
40
|
+
* @hbClient ohos none
|
|
41
|
+
* @hbClient windows none
|
|
42
|
+
* @hbClient macos none
|
|
43
|
+
*/
|
|
44
|
+
file(relativePath: string): FileHandle;
|
|
45
|
+
/**
|
|
46
|
+
* 按规范相对路径派生目录代理。
|
|
47
|
+
*
|
|
48
|
+
* @param relativePath - 使用 `/` 分隔的规范相对路径。
|
|
49
|
+
* @returns 延迟访问对应目录的代理。
|
|
50
|
+
* @since 0.8.0-alpha.2
|
|
51
|
+
* @hbPlatform android
|
|
52
|
+
* @hbPlatform ios
|
|
53
|
+
* @hbPlatform ohos
|
|
54
|
+
* @hbPlatform windows
|
|
55
|
+
* @hbPlatform macos
|
|
56
|
+
* @hbClient android none
|
|
57
|
+
* @hbClient ios none
|
|
58
|
+
* @hbClient ohos none
|
|
59
|
+
* @hbClient windows none
|
|
60
|
+
* @hbClient macos none
|
|
61
|
+
*/
|
|
62
|
+
directory(relativePath: string): DirectoryHandle;
|
|
63
|
+
}
|
|
64
|
+
/** Mini-program 私有 sandbox 的逻辑根。 */
|
|
65
|
+
export interface FileSystem extends PathRoot {
|
|
66
|
+
}
|
|
67
|
+
/** 当前 SDK session 中的文件代理。 */
|
|
68
|
+
export interface FileHandle {
|
|
69
|
+
readonly kind: 'file';
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly mode: FileMode;
|
|
72
|
+
create(options?: CreateOptions): Promise<FileHandle>;
|
|
73
|
+
/** 删除 sandbox 文件;外部授权文件不允许删除。 */
|
|
74
|
+
remove(): Promise<void>;
|
|
75
|
+
exists(): Promise<boolean>;
|
|
76
|
+
readText(): Promise<string>;
|
|
77
|
+
writeText(content: string): Promise<void>;
|
|
78
|
+
readBytes(): Promise<Uint8Array>;
|
|
79
|
+
writeBytes(content: Uint8Array): Promise<void>;
|
|
80
|
+
stat(): Promise<FileStat>;
|
|
81
|
+
}
|
|
82
|
+
/** 当前 SDK session 中的目录代理。 */
|
|
83
|
+
export interface DirectoryHandle extends PathRoot {
|
|
84
|
+
readonly kind: 'directory';
|
|
85
|
+
readonly name: string;
|
|
86
|
+
readonly mode: FileMode;
|
|
87
|
+
create(options?: CreateOptions): Promise<DirectoryHandle>;
|
|
88
|
+
/** 删除 sandbox 目录;非空目录需要显式设置 `recursive`,外部授权目录不允许删除。 */
|
|
89
|
+
remove(options?: RemoveOptions): Promise<void>;
|
|
90
|
+
exists(): Promise<boolean>;
|
|
91
|
+
list(options?: ListOptions): Promise<FileSystemEntity[]>;
|
|
92
|
+
}
|
|
93
|
+
export type FileSystemEntity = FileHandle | DirectoryHandle;
|
|
94
|
+
export interface FileStat {
|
|
95
|
+
kind: 'file';
|
|
96
|
+
size: number;
|
|
97
|
+
/** Unix epoch milliseconds。 */
|
|
98
|
+
modifiedAt?: number;
|
|
99
|
+
/** Unix epoch milliseconds。 */
|
|
100
|
+
createdAt?: number;
|
|
101
|
+
}
|
|
102
|
+
/** Mini-program 对外文件能力。 */
|
|
103
|
+
export interface FilesModule {
|
|
104
|
+
readonly sandbox: FileSystem;
|
|
105
|
+
/**
|
|
106
|
+
* 让用户选择一个或多个文件并返回当前 session 的授权代理。
|
|
107
|
+
*
|
|
108
|
+
* @param options - 访问模式、扩展名筛选与多选设置。
|
|
109
|
+
* @returns 用户选择的文件代理。
|
|
110
|
+
* @since 0.8.0-alpha.2
|
|
111
|
+
* @hbPlatform android
|
|
112
|
+
* @hbPlatform ios
|
|
113
|
+
* @hbPlatform ohos
|
|
114
|
+
* @hbPlatform windows
|
|
115
|
+
* @hbPlatform macos
|
|
116
|
+
* @hbClient android none
|
|
117
|
+
* @hbClient ios none
|
|
118
|
+
* @hbClient ohos none
|
|
119
|
+
* @hbClient windows none
|
|
120
|
+
* @hbClient macos none
|
|
121
|
+
*/
|
|
122
|
+
pickFiles(options?: PickFilesOptions): Promise<FileHandle[]>;
|
|
123
|
+
/**
|
|
124
|
+
* 让用户选择目录并返回当前 session 的授权代理。
|
|
125
|
+
*
|
|
126
|
+
* @param options - 目录访问模式。
|
|
127
|
+
* @returns 用户选择的目录代理。
|
|
128
|
+
* @since 0.8.0-alpha.2
|
|
129
|
+
* @hbPlatform android
|
|
130
|
+
* @hbPlatform ios
|
|
131
|
+
* @hbPlatform ohos
|
|
132
|
+
* @hbPlatform windows
|
|
133
|
+
* @hbPlatform macos
|
|
134
|
+
* @hbClient android none
|
|
135
|
+
* @hbClient ios none
|
|
136
|
+
* @hbClient ohos none
|
|
137
|
+
* @hbClient windows none
|
|
138
|
+
* @hbClient macos none
|
|
139
|
+
*/
|
|
140
|
+
pickDirectory(options?: PickDirectoryOptions): Promise<DirectoryHandle>;
|
|
141
|
+
/**
|
|
142
|
+
* 让用户选择一个精确的文件保存目标。
|
|
143
|
+
*
|
|
144
|
+
* @param options - 建议文件名。
|
|
145
|
+
* @returns 具备读写权限的目标文件代理。
|
|
146
|
+
* @since 0.8.0-alpha.2
|
|
147
|
+
* @hbPlatform android
|
|
148
|
+
* @hbPlatform ios
|
|
149
|
+
* @hbPlatform ohos
|
|
150
|
+
* @hbPlatform windows
|
|
151
|
+
* @hbPlatform macos
|
|
152
|
+
* @hbClient android none
|
|
153
|
+
* @hbClient ios none
|
|
154
|
+
* @hbClient ohos none
|
|
155
|
+
* @hbClient windows none
|
|
156
|
+
* @hbClient macos none
|
|
157
|
+
*/
|
|
158
|
+
saveFile(options: SaveFileOptions): Promise<FileHandle>;
|
|
159
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { MiniProgramRequester } from '../../core/client';
|
|
2
|
-
|
|
1
|
+
import type { MiniProgramOperationRequester, MiniProgramRequester } from '../../core/client';
|
|
2
|
+
import type { DirectoryHandle, FileHandle } from '../files';
|
|
3
|
+
export { NETWORK_DOWNLOAD_METHOD, NETWORK_REQUEST_METHOD } from '../../protocol/capabilities';
|
|
3
4
|
export { createNetworkRequestFailureLog, formatNetworkRequestFailureMessage, logNetworkRequestFailure, previewNetworkData, sanitizeNetworkHeaders, sanitizeNetworkRequestUrl, } from './observability';
|
|
4
5
|
export { describeHostNetworkFailure, isMultipartContentType, isUnsupportedMultipartNetworkRequest, looksLikeMultipartBody, NETWORK_REQUEST_MULTIPART_UNSUPPORTED_MESSAGE, readNetworkContentType, } from './request-shape';
|
|
5
6
|
/** `network.request` 请求头。 */
|
|
@@ -42,6 +43,32 @@ export interface MiniProgramNetworkRequestConfig {
|
|
|
42
43
|
/** SDK 侧状态校验;不会跨 bridge 传输函数值。 */
|
|
43
44
|
validateStatus?: MiniProgramNetworkValidateStatus;
|
|
44
45
|
}
|
|
46
|
+
/** 流式下载的 request-scoped 进度。 */
|
|
47
|
+
export interface DownloadProgress {
|
|
48
|
+
loaded: number;
|
|
49
|
+
total?: number;
|
|
50
|
+
lengthComputable: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface DownloadBaseOptions {
|
|
53
|
+
url: string;
|
|
54
|
+
params?: MiniProgramNetworkParams;
|
|
55
|
+
headers?: MiniProgramNetworkHeaders;
|
|
56
|
+
timeout?: number;
|
|
57
|
+
withCredentials?: boolean;
|
|
58
|
+
maxBytes?: number;
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
onProgress?: (progress: DownloadProgress) => void;
|
|
61
|
+
}
|
|
62
|
+
/** File target 原子替换,Directory target 创建或替换子文件。 */
|
|
63
|
+
export type DownloadOptions = DownloadBaseOptions & ({
|
|
64
|
+
to: FileHandle;
|
|
65
|
+
suggestedName?: never;
|
|
66
|
+
overwrite?: never;
|
|
67
|
+
} | {
|
|
68
|
+
to: DirectoryHandle;
|
|
69
|
+
suggestedName?: string;
|
|
70
|
+
overwrite?: boolean;
|
|
71
|
+
});
|
|
45
72
|
/**
|
|
46
73
|
* bridge / runtime 可消费的网络请求 payload。
|
|
47
74
|
*
|
|
@@ -100,6 +127,24 @@ export interface MiniProgramNetworkModule {
|
|
|
100
127
|
* @hbClient macos none
|
|
101
128
|
*/
|
|
102
129
|
request<T = unknown>(config: MiniProgramNetworkRequestConfig): Promise<MiniProgramNetworkResponse<T>>;
|
|
130
|
+
/**
|
|
131
|
+
* 将 GET 响应流式写入受控 File/Directory target。
|
|
132
|
+
*
|
|
133
|
+
* @param options - 下载地址、写入目标、取消信号与进度回调。
|
|
134
|
+
* @returns 原子提交完成后的目标文件代理。
|
|
135
|
+
* @since 0.8.0-alpha.2
|
|
136
|
+
* @hbPlatform android
|
|
137
|
+
* @hbPlatform ios
|
|
138
|
+
* @hbPlatform ohos
|
|
139
|
+
* @hbPlatform windows
|
|
140
|
+
* @hbPlatform macos
|
|
141
|
+
* @hbClient android none
|
|
142
|
+
* @hbClient ios none
|
|
143
|
+
* @hbClient ohos none
|
|
144
|
+
* @hbClient windows none
|
|
145
|
+
* @hbClient macos none
|
|
146
|
+
*/
|
|
147
|
+
download(options: DownloadOptions): Promise<FileHandle>;
|
|
103
148
|
}
|
|
104
149
|
/**
|
|
105
150
|
* 发起网络请求并返回标准化响应。
|
|
@@ -123,10 +168,12 @@ export interface MiniProgramNetworkModule {
|
|
|
123
168
|
* ```
|
|
124
169
|
*/
|
|
125
170
|
export declare function request<T = unknown>(requester: MiniProgramRequester, config: MiniProgramNetworkRequestConfig): Promise<MiniProgramNetworkResponse<T>>;
|
|
171
|
+
/** 发起不使用 bridge 固定总时长 timer 的流式下载。 */
|
|
172
|
+
export declare function download(requester: MiniProgramOperationRequester, options: DownloadOptions): Promise<FileHandle>;
|
|
126
173
|
/**
|
|
127
174
|
* 创建 network 模块。
|
|
128
175
|
*
|
|
129
176
|
* @param requester - 底层 bridge 请求能力。
|
|
130
177
|
* @returns 面向业务层的网络模块对象。
|
|
131
178
|
*/
|
|
132
|
-
export declare function createNetworkModule(requester:
|
|
179
|
+
export declare function createNetworkModule(requester: MiniProgramOperationRequester): MiniProgramNetworkModule;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AUTH_LOGIN_METHOD, CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_INFO_METHOD, CLOUD_LEADERBOARD_GET_LIST_METHOD, CLOUD_LEADERBOARD_SUBMIT_METHOD, DEVICE_SET_CLIPBOARD_METHOD, DEVICE_VIBRATE_METHOD, MINI_PROGRAM_PROTOCOL_CAPABILITIES, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_REQUEST_METHOD, SHARE_COPY_LINK_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, UI_HIDE_LOADING_METHOD, UI_SHOW_LOADING_METHOD, UI_SHOW_TOAST_METHOD, USER_GET_INFO_METHOD, USER_GET_STEAM_GAME_LIST_METHOD, USER_REVOKE_AUTHORIZATION_METHOD, VIEWPORT_GET_WINDOW_INFO_METHOD, VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD, } from '@heybox/hb-sdk-protocol';
|
|
2
|
-
export type { MiniProgramAuthMethod, MiniProgramBridgeMethod, MiniProgramCapabilityDefinition, MiniProgramCapabilityModule, MiniProgramCapabilityPayload, MiniProgramCapabilityPayloadMap, MiniProgramCapabilityResult, MiniProgramCapabilityResultMap, MiniProgramCapabilityRisk, MiniProgramCloudMethod, MiniProgramDeviceMethod, MiniProgramNavigationMethod, MiniProgramNetworkMethod, MiniProgramShareMethod, MiniProgramStorageMethod, MiniProgramUiMethod, MiniProgramUserMethod, MiniProgramViewportMethod, } from '@heybox/hb-sdk-protocol';
|
|
1
|
+
export { AUTH_LOGIN_METHOD, CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_INFO_METHOD, CLOUD_LEADERBOARD_GET_LIST_METHOD, CLOUD_LEADERBOARD_SUBMIT_METHOD, DIRECTORY_CREATE_METHOD, DIRECTORY_EXISTS_METHOD, DIRECTORY_LIST_METHOD, DIRECTORY_REMOVE_METHOD, DEVICE_SET_CLIPBOARD_METHOD, DEVICE_VIBRATE_METHOD, FILES_PICK_DIRECTORY_METHOD, FILES_PICK_FILES_METHOD, FILES_SAVE_FILE_METHOD, FILE_CREATE_METHOD, FILE_EXISTS_METHOD, FILE_READ_BYTES_METHOD, FILE_READ_TEXT_METHOD, FILE_REMOVE_METHOD, FILE_STAT_METHOD, FILE_WRITE_BYTES_METHOD, FILE_WRITE_TEXT_METHOD, MINI_PROGRAM_PROTOCOL_CAPABILITIES, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_REQUEST_METHOD, NETWORK_DOWNLOAD_METHOD, SHARE_COPY_LINK_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, UI_HIDE_LOADING_METHOD, UI_SHOW_LOADING_METHOD, UI_SHOW_TOAST_METHOD, USER_GET_INFO_METHOD, USER_GET_STEAM_GAME_LIST_METHOD, USER_REVOKE_AUTHORIZATION_METHOD, VIEWPORT_GET_WINDOW_INFO_METHOD, VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD, } from '@heybox/hb-sdk-protocol';
|
|
2
|
+
export type { MiniProgramAuthMethod, MiniProgramBridgeMethod, MiniProgramCapabilityDefinition, MiniProgramCapabilityModule, MiniProgramCapabilityPayload, MiniProgramCapabilityPayloadMap, MiniProgramCapabilityResult, MiniProgramCapabilityResultMap, MiniProgramCapabilityRisk, MiniProgramCloudMethod, MiniProgramDeviceMethod, MiniProgramDirectoryMethod, MiniProgramFileMethod, MiniProgramFilesMethod, MiniProgramNavigationMethod, MiniProgramNetworkMethod, MiniProgramShareMethod, MiniProgramStorageMethod, MiniProgramUiMethod, MiniProgramUserMethod, MiniProgramViewportMethod, } from '@heybox/hb-sdk-protocol';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, } from '@heybox/hb-sdk-protocol';
|
|
1
|
+
export { MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_OPERATION_PROGRESS_METHOD, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, } from '@heybox/hb-sdk-protocol';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { isMiniProgramBridgeMessage } from '@heybox/hb-sdk-protocol';
|
|
1
|
+
export { isMiniProgramBridgeMessage, isMiniProgramByteArray, isMiniProgramDirectoryDescriptor, isMiniProgramDirectoryRef, isMiniProgramDownloadProgressPayload, isMiniProgramFileDescriptor, isMiniProgramFileRef, isMiniProgramFileStat, isMiniProgramFileSystemEntityDescriptor, isMiniProgramPathRootRef, isMiniProgramRelativePath, } from '@heybox/hb-sdk-protocol';
|