@heybox/hb-sdk 0.8.1 → 0.8.2-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.
Files changed (64) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -2
  3. package/dist/cli-chunks/{build-DPe1Ycjd.cjs → build-bVThH3Z5.cjs} +4 -4
  4. package/dist/cli-chunks/{context-BSUhAv3Z.cjs → context-DpKqGnjp.cjs} +2 -2
  5. package/dist/cli-chunks/{create-CaiKrGnb.cjs → create-BWC2343y.cjs} +1 -1
  6. package/dist/cli-chunks/{dev-BG1o8Q-0.cjs → dev-t14YpHHY.cjs} +9 -9
  7. package/dist/cli-chunks/{doctor-DutO2P5H.cjs → doctor-BWkrE0Hj.cjs} +1 -1
  8. package/dist/cli-chunks/{index-CKIyipP9.cjs → index-CDtcZVWv.cjs} +15 -15
  9. package/dist/cli-chunks/{index-Bur0U2z1.cjs → index-D3FMcOZq.cjs} +2 -2
  10. package/dist/cli-chunks/{index.esm-BPlpP-O0.cjs → index.esm-BrJBaJWS.cjs} +7 -7
  11. package/dist/cli-chunks/{login-C1JlLEza.cjs → login-DRMl7nFH.cjs} +2 -2
  12. package/dist/cli-chunks/{project-vite-Bd0WzAqQ.cjs → project-vite-CXgdzIYw.cjs} +1 -1
  13. package/dist/cli-chunks/{remote-DTFEf3Dj.cjs → remote-ibQybNiM.cjs} +6 -6
  14. package/dist/cli-chunks/{runtime-permission-env-C2S34ldj.cjs → runtime-permission-env-DiTeD75Q.cjs} +576 -20
  15. package/dist/cli-chunks/{session-zXVkHuhY.cjs → session-CIoBspg-.cjs} +1 -1
  16. package/dist/cli-chunks/{skill-CCB3DyXk.cjs → skill-5labzuWk.cjs} +2 -2
  17. package/dist/cli-chunks/{version-0qwlEyZC.cjs → version-QiVEs76a.cjs} +1 -1
  18. package/dist/cli.cjs +1 -1
  19. package/dist/devtools/browser-dev-host/assets/browser-dev-host-DxzOkljJ.js +101 -0
  20. package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-DOfl5YvO.js → desktop-app-launch-B4KsgItx.js} +1 -1
  21. package/dist/devtools/browser-dev-host/assets/{index-CFr28-0O.js → index-9Nb3XhtI.js} +3 -3
  22. package/dist/devtools/browser-dev-host/index.html +2 -2
  23. package/dist/index.cjs.js +948 -44
  24. package/dist/index.esm.js +948 -44
  25. package/dist/miniapp-publish.cjs.js +536 -30
  26. package/dist/miniapp-publish.esm.js +536 -30
  27. package/dist/protocol.cjs.js +807 -2
  28. package/dist/protocol.esm.js +807 -2
  29. package/dist/vite.cjs.js +184 -1
  30. package/dist/vite.esm.js +184 -1
  31. package/package.json +7 -7
  32. package/skill/references/api-root.md +192 -8
  33. package/skill/references/recipes.md +45 -7
  34. package/skill/skill.json +5 -5
  35. package/types/core/errors.d.ts +33 -9
  36. package/types/core/handshake-state.d.ts +32 -2
  37. package/types/core/singleton.d.ts +265 -6
  38. package/types/miniapp-manifest/bindings.d.ts +65 -0
  39. package/types/miniapp-manifest/schema.d.ts +136 -19
  40. package/types/miniapp-publish/index.d.ts +425 -29
  41. package/types/modules/auth/index.d.ts +159 -5
  42. package/types/modules/cloud/index.d.ts +514 -40
  43. package/types/modules/companion/index.d.ts +1518 -17
  44. package/types/modules/device/index.d.ts +140 -9
  45. package/types/modules/environment/index.d.ts +172 -4
  46. package/types/modules/files/types.d.ts +1396 -21
  47. package/types/modules/navigation/app-pages/types.d.ts +81 -24
  48. package/types/modules/navigation/index.d.ts +230 -7
  49. package/types/modules/network/index.d.ts +297 -26
  50. package/types/modules/share/copy-link.d.ts +35 -5
  51. package/types/modules/share/index.d.ts +210 -0
  52. package/types/modules/share/screenshot.d.ts +23 -5
  53. package/types/modules/share/show-share-menu.d.ts +18 -5
  54. package/types/modules/share/types.d.ts +148 -23
  55. package/types/modules/storage/index.d.ts +139 -9
  56. package/types/modules/ui/index.d.ts +249 -18
  57. package/types/modules/user/get-info.d.ts +29 -8
  58. package/types/modules/user/index.d.ts +157 -0
  59. package/types/modules/user/revoke-authorization.d.ts +26 -2
  60. package/types/modules/user/steam-game-list.d.ts +96 -15
  61. package/types/modules/viewport/index.d.ts +158 -22
  62. package/types/protocol/types.d.ts +19 -1
  63. package/types/vite/index.d.ts +159 -1
  64. package/dist/devtools/browser-dev-host/assets/browser-dev-host-pUcws1MK.js +0 -101
@@ -1,94 +1,425 @@
1
+ /** CDN 上传接口使用的小程序产物业务 scope。 */
1
2
  export declare const MINIAPP_UPLOAD_SCOPE = "activity";
3
+ /** 完整 CDN 上传 key 的默认长度上限;旧固定版本流程按字符计数,上传会话流程按 UTF-8 bytes 计数。 */
2
4
  export declare const ACTIVITY_UPLOAD_KEY_MAX_LENGTH = 64;
5
+ /** 单次向 CDN 申请上传信息时包含的最大文件数;当前合同固定为 `50`。 */
3
6
  export declare const MINIAPP_UPLOAD_BATCH_SIZE = 50;
7
+ /** Web 构建产物的默认总大小上限,单位为 bytes;当前为 100 MiB。 */
4
8
  export declare const MINIAPP_UPLOAD_TOTAL_SIZE_LIMIT_BYTES: number;
5
- /** 与 Activity 上传后端合同一致的 Companion 归档总大小上限。 */
9
+ /** Companion 归档的临时总大小上限,单位为 bytes;当前为 500 MiB。 */
6
10
  export declare const MINIAPP_COMPANION_UPLOAD_TEMPORARY_SIZE_LIMIT_BYTES: number;
11
+ /** 查询当前开发者账号是否具备小程序访问资格的开放平台 API 路径。 */
7
12
  export declare const USER_MINIPROGRAM_ACCESS_STATUS_API_PATH = "/mall/developer/user_miniprogram/access_status";
13
+ /** 查询当前开发者可管理主体列表的开放平台 API 路径。 */
8
14
  export declare const DEVELOPER_ENTITY_LIST_API_PATH = "/mall/developer/entity/list";
15
+ /** 切换当前开发者主体的开放平台 API 路径。 */
9
16
  export declare const DEVELOPER_ENTITY_SWITCH_API_PATH = "/mall/developer/entity/switch";
17
+ /** 查询当前主体下小程序列表的开放平台 API 路径。 */
10
18
  export declare const LIST_USER_MINIPROGRAM_API_PATH = "/mall/developer/user_miniprogram/list";
19
+ /** 创建小程序的开放平台 API 路径。 */
11
20
  export declare const CREATE_USER_MINIPROGRAM_API_PATH = "/mall/developer/user_miniprogram/create";
21
+ /** 查询单个小程序详情的开放平台 API 路径。 */
12
22
  export declare const DETAIL_USER_MINIPROGRAM_API_PATH = "/mall/developer/user_miniprogram/detail";
23
+ /** 创建本地开发启动凭据的开放平台 API 路径。 */
13
24
  export declare const CREATE_USER_MINIPROGRAM_LOCAL_DEV_LAUNCH_TOKEN_API_PATH = "/mall/developer/user_miniprogram/local_dev_launch_token";
25
+ /** 查询小程序预览白名单的开放平台 API 路径。 */
14
26
  export declare const USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = "/mall/developer/user_miniprogram/preview_allowlist";
27
+ /** 更新小程序预览白名单的开放平台 API 路径。 */
15
28
  export declare const UPDATE_USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = "/mall/developer/user_miniprogram/preview_allowlist/update";
29
+ /** 创建小程序云排行榜的开放平台 API 路径。 */
16
30
  export declare const CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = "/mall/developer/user_miniprogram/leaderboard/create";
31
+ /** 查询单个小程序云排行榜详情的开放平台 API 路径。 */
17
32
  export declare const DETAIL_USER_MINIPROGRAM_LEADERBOARD_API_PATH = "/mall/developer/user_miniprogram/leaderboard/detail";
33
+ /** 查询小程序云排行榜列表的开放平台 API 路径。 */
18
34
  export declare const LIST_USER_MINIPROGRAM_LEADERBOARD_API_PATH = "/mall/developer/user_miniprogram/leaderboard/list";
35
+ /** 删除小程序云排行榜的开放平台 API 路径。 */
19
36
  export declare const DELETE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = "/mall/developer/user_miniprogram/leaderboard/delete";
37
+ /** 在上传或复用版本前执行发布预检的开放平台 API 路径。 */
20
38
  export declare const PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH = "/mall/developer/user_miniprogram/version/precheck";
39
+ /** 将小程序版本提交审核的开放平台 API 路径。 */
21
40
  export declare const SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH = "/mall/developer/user_miniprogram/version/submit_audit";
41
+ /** 查询小程序版本预览信息的开放平台 API 路径。 */
22
42
  export declare const USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = "/mall/developer/user_miniprogram/version/preview_info";
43
+ /** 撤回待审核小程序版本的开放平台 API 路径。 */
23
44
  export declare const WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH = "/mall/developer/user_miniprogram/version/withdraw";
45
+ /** 发布审核通过的小程序版本的开放平台 API 路径。 */
24
46
  export declare const RELEASE_USER_MINIPROGRAM_VERSION_API_PATH = "/mall/developer/user_miniprogram/version/release";
47
+ /** 下架当前线上小程序的开放平台 API 路径。 */
25
48
  export declare const TAKE_DOWN_USER_MINIPROGRAM_API_PATH = "/mall/developer/user_miniprogram/take_down";
49
+ /** 重新开放已下架小程序的开放平台 API 路径。 */
26
50
  export declare const REOPEN_USER_MINIPROGRAM_API_PATH = "/mall/developer/user_miniprogram/reopen";
51
+ /** 更新小程序广场展示状态的开放平台 API 路径。 */
27
52
  export declare const UPDATE_SQUARE_DISPLAY_API_PATH = "/mall/developer/user_miniprogram/square_display/update";
53
+ /** 查询小程序历史版本列表的开放平台 API 路径。 */
28
54
  export declare const LIST_USER_MINIPROGRAM_VERSION_API_PATH = "/mall/developer/user_miniprogram/version/list";
29
55
  export { isValidMiniappManifestVersion as isValidVersion } from '../miniapp-manifest/schema';
30
56
  export { MINIAPP_LEGACY_MOBILE_PLATFORM_VALUES, MINIAPP_PLATFORM_HARD_CUT_SDK_VERSION, resolveMiniappManifestPlatforms, type MiniappPlatformPolicy, type MiniappPlatformResolution, } from '../miniapp-manifest/schema';
31
57
  export { parseMiniappBindAppIds, type ParseMiniappBindAppIdsOptions } from '../miniapp-manifest/bindings';
58
+ /**
59
+ * 将扫描到的相对路径转换为统一的 `/` 分隔形式。
60
+ *
61
+ * @param relativePath - 待整理的构建产物路径。TypeScript 入口声明为字符串;JavaScript 运行时会
62
+ * 先计算 `relativePath || ''`,再通过 `String(...)` 强制转换。
63
+ * @returns 仅统一分隔符形态的新字符串:所有 `\\` 转为 `/`,所有前导 `/` 被删除,其余连续
64
+ * `/` 合并为一个。空字符串以及运行时传入的 `undefined`、`null`、`false`、`0`、`NaN` 等
65
+ * falsy 值返回 `''`;truthy 非字符串按标准 `String(value)` 结果继续整理。
66
+ *
67
+ * @remarks
68
+ * 这是面向 build/deploy 文件扫描结果的**格式 helper**,不是路径安全校验或 canonical path
69
+ * parser。它不会 trim、URL decode、Unicode normalize、解析盘符,也不会拒绝或消解 `.` / `..`
70
+ * segment、控制字符、Windows drive prefix 或尾随 `/`。例如 `/etc/passwd` 会变成
71
+ * `etc/passwd`,`C:\\temp\\app.js` 会变成 `C:/temp/app.js`,`assets/../secret/` 仍保留点段
72
+ * 和尾随 slash;调用方不能根据返回值推断原输入是安全相对路径。
73
+ *
74
+ * SDK 的 build/deploy 流程会把扫描路径先用本函数统一分隔符,再分别使用
75
+ * {@link relativePathContainsNodeModulesSegment} 排除完整 `node_modules` 目录段、用
76
+ * {@link shouldUploadDistFile} 过滤根 `manifest.json` / `.DS_Store` / source map。`hb-sdk build`
77
+ * 随后校验大小预算;`hb-sdk remote deploy` 还会在签名和上传前通过
78
+ * `validateUploadPaths()`、`prepareMiniappArtifactFiles()` 或
79
+ * `validateMiniappUploadPathLengths()` 执行真正的空路径、点段、控制字符、重复和长度校验。
80
+ * 这些步骤不能由本函数单独替代;`shouldUploadDistFile()` 也不会自行检查 `node_modules`。
81
+ *
82
+ * 不要把本函数与 `@heybox/hb-sdk/protocol` 的 `isMiniProgramRelativePath()` 混用:协议 guard
83
+ * 不做转换,只接受已经规范的非空字符串,并拒绝前导/尾随 `/`、反斜杠、空 segment、`.`、
84
+ * `..` 与控制字符;本函数则会改写部分非法形态并保留其余不安全内容。
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * import { normalizeRelativePath } from '@heybox/hb-sdk/miniapp-publish';
89
+ *
90
+ * normalizeRelativePath('///dist\\assets//app.js'); // 'dist/assets/app.js'
91
+ * normalizeRelativePath('assets/../secret///'); // 'assets/../secret/',仍需安全校验
92
+ * normalizeRelativePath(123 as unknown as string); // '123',JavaScript 运行时强制转换
93
+ * normalizeRelativePath(0 as unknown as string); // '',falsy 值先回退为空串
94
+ * ```
95
+ *
96
+ * @see {@link relativePathContainsNodeModulesSegment}
97
+ * @see {@link shouldUploadDistFile}
98
+ * @see {@link https://docs.xiaoheihe.cn/hb_sdk/reference/symbols/protocol/functions/isMiniProgramRelativePath | isMiniProgramRelativePath}
99
+ */
32
100
  export declare function normalizeRelativePath(relativePath: string): string;
101
+ /**
102
+ * 判断路径中是否包含大小写不敏感的完整 `node_modules` 目录段。
103
+ *
104
+ * @param relativePath - 待检查的构建产物路径。函数先通过 {@link normalizeRelativePath} 把
105
+ * 反斜杠改为 `/`、删除前导 `/` 并合并连续 `/`,再按 `/` 分段。
106
+ * @returns 至少一个非空段大小写不敏感地等于完整 `node_modules` 时返回 `true`;空路径、
107
+ * 空段及 `node_modules.txt`、`node_modules-old`、`@node_modules` 等相似名称返回 `false`。
108
+ *
109
+ * @remarks
110
+ * 比较使用每个非空 segment 的 `toLowerCase() === 'node_modules'`,因此根目录或任意深度的
111
+ * `node_modules`、`NODE_MODULES`、`Node_Modules` 都会命中。前导和重复 slash 会先被
112
+ * `normalizeRelativePath` 整理;尾随 slash 产生的空段会被忽略。
113
+ *
114
+ * 这是同步、无副作用的**单一 predicate**,只回答“规范化后的文本是否包含该完整段”。它
115
+ * 不 trim segment、不进行 URL/percent decode、Unicode normalize 或文件系统解析。例如
116
+ * `node_modules%2Fpkg/index.js`、`%6eode_modules/pkg.js` 和 `node_modules.txt` 都不会命中;调用方
117
+ * 不应传 URL,也不能把未命中解释为路径安全。
118
+ *
119
+ * 本函数不会拒绝或消解 `.` / `..`、绝对路径、Windows drive prefix、控制字符、空路径、
120
+ * symlink、重复路径或超长路径。`assets/../node_modules/pkg.js` 仍会命中,因为点段保持原样;
121
+ * 不含 `node_modules` 的危险路径则仍可能返回 `false`。签名或上传前必须继续执行对应的上传
122
+ * 路径规范、唯一性和长度校验。
123
+ *
124
+ * SDK build/deploy 会在文件扫描后用本函数拒绝整个 `node_modules` 树,再用
125
+ * {@link shouldUploadDistFile} 排除根 `manifest.json`、`.DS_Store` 和 source map。build 随后
126
+ * 校验大小预算;deploy 还会执行上传路径安全、唯一性、长度与签名校验。这些步骤互不替代:`shouldUploadDistFile()` 本身不检查
127
+ * `node_modules`,本函数也不决定普通文件是否应该上传。
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { relativePathContainsNodeModulesSegment } from '@heybox/hb-sdk/miniapp-publish';
132
+ *
133
+ * relativePathContainsNodeModulesSegment('dist\\NODE_MODULES/pkg/index.js'); // true
134
+ * relativePathContainsNodeModulesSegment('dist//vendor///node_modules/'); // true
135
+ * relativePathContainsNodeModulesSegment('dist/node_modules.txt'); // false
136
+ * relativePathContainsNodeModulesSegment('dist/node_modules%2Fpkg.js'); // false,不做 URL decode
137
+ * relativePathContainsNodeModulesSegment('assets/../secret.js'); // false,但这不代表路径安全
138
+ * ```
139
+ *
140
+ * @see [normalizeRelativePath](/reference/symbols/miniapp-publish/functions/normalizeRelativePath)
141
+ * @see [shouldUploadDistFile](/reference/symbols/miniapp-publish/functions/shouldUploadDistFile)
142
+ * @see [miniapp-publish](/reference/miniapp-publish/)
143
+ */
33
144
  export declare function relativePathContainsNodeModulesSegment(relativePath: string): boolean;
145
+ /**
146
+ * 为小程序 ID 计算稳定、紧凑的上传路径别名。
147
+ *
148
+ * @param miniProgramId - 小程序 ID。
149
+ * @returns 基于 32-bit FNV-1a 结果生成的 base36 字符串。
150
+ * @remarks 该别名只用于缩短上传 key,不是加密摘要,也不能用于鉴权或隐藏小程序身份。
151
+ * @example
152
+ * ```ts
153
+ * const alias = getMiniProgramUploadAlias('mp_example');
154
+ * console.log(/^[a-z0-9]+$/.test(alias)); // true
155
+ * ```
156
+ */
34
157
  export declare function getMiniProgramUploadAlias(miniProgramId: string): string;
158
+ /** 生成旧版固定版本上传 key 所需的输入。 */
35
159
  export interface MiniappUploadKeyInput {
160
+ /** 小程序 ID;函数会将其转换为稳定上传别名。 */
36
161
  miniProgramId: string;
162
+ /** 要写入上传 key 的版本字符串;调用方应先完成版本合法性校验。 */
37
163
  version: string;
164
+ /** 构建产物相对路径;生成 key 前会整理路径分隔符。 */
38
165
  relativePath: string;
39
166
  }
167
+ /**
168
+ * 生成旧版固定版本 CDN 上传 key。
169
+ *
170
+ * @param input - 小程序 ID、版本和构建产物相对路径。
171
+ * @returns `/u/{alias}/{version}/{relativePath}` 形式的上传 key。
172
+ * @remarks 此函数不会校验版本、路径安全性或 key 长度;批量上传前应调用 {@link validateUploadPaths}。
173
+ * @example
174
+ * ```ts
175
+ * getMiniappUploadKey({
176
+ * miniProgramId: 'mp_example',
177
+ * version: '1.2.3',
178
+ * relativePath: 'assets\\app.js',
179
+ * }); // /u/<alias>/1.2.3/assets/app.js
180
+ * ```
181
+ */
40
182
  export declare function getMiniappUploadKey(input: MiniappUploadKeyInput): string;
183
+ /** 参与旧版上传路径校验的构建产物条目。 */
41
184
  export interface UploadPathItem {
185
+ /** 构建产物相对路径。 */
42
186
  relativePath: string;
43
187
  }
188
+ /** 旧版固定版本上传路径的校验选项。 */
44
189
  export interface ValidateUploadPathsOptions {
190
+ /** 小程序 ID,用于计算上传 key 中的稳定别名。 */
45
191
  miniProgramId: string;
192
+ /** 要写入上传 key 的版本字符串。 */
46
193
  version: string;
194
+ /** 完整上传 key 的最大字符数,默认 {@link ACTIVITY_UPLOAD_KEY_MAX_LENGTH}。 */
47
195
  maxLength?: number;
48
196
  }
197
+ /**
198
+ * 校验旧版固定版本上传路径的格式、唯一性和完整 key 长度。
199
+ *
200
+ * @param items - 待上传条目;按数组顺序检查。
201
+ * @param options - 小程序 ID、版本和可选的 key 长度上限。
202
+ * @returns 第一个校验错误的中文提示;全部合法时返回 `undefined`。
203
+ * @remarks
204
+ * 路径会先统一分隔符,因此 `assets\\app.js` 与 `assets/app.js` 视为重复。
205
+ * 长度按 JavaScript 字符串 `length` 计算;上传会话的 UTF-8 字节限制应使用 {@link validateMiniappUploadPathLengths}。
206
+ * @example
207
+ * ```ts
208
+ * const error = validateUploadPaths(
209
+ * [{ relativePath: 'index.html' }, { relativePath: 'assets/app.js' }],
210
+ * { miniProgramId: 'mp_example', version: '1.2.3' },
211
+ * );
212
+ * if (error) throw new Error(error);
213
+ * ```
214
+ */
49
215
  export declare function validateUploadPaths(items: UploadPathItem[], options: ValidateUploadPathsOptions): string | undefined;
216
+ /**
217
+ * 参与上传总大小计算的构建产物条目。
218
+ *
219
+ * @remarks
220
+ * {@link validateUploadTotalSize} 只读取 `size`,不会读取或校验 `relativePath`。同一类型也供
221
+ * `validateMiniappUploadSizeBudgets()` 使用,后者才根据规范化路径区分 Web 与 Companion 预算。
222
+ */
50
223
  export interface UploadSizeItem {
224
+ /**
225
+ * 构建产物相对路径。直接调用 {@link validateUploadTotalSize} 时该字段不参与计算;预算包装
226
+ * 函数会把规范化后以 `companions/` 开头的路径归入 Companion 组。
227
+ */
51
228
  relativePath: string;
229
+ /**
230
+ * 调用方提供的文件大小,单位为 bytes。函数内部执行 `Number(size)`,仅有限且大于 `0` 的
231
+ * 数值加入总和;`NaN`、正负 `Infinity`、负数和 `0` 均按 `0` 处理,不会单独报错。
232
+ */
52
233
  size: number;
53
234
  }
235
+ /** {@link validateUploadTotalSize} 的总量上限选项。 */
54
236
  export interface ValidateUploadTotalSizeOptions {
237
+ /**
238
+ * 总大小上限,单位为 bytes;省略时使用 `MINIAPP_UPLOAD_TOTAL_SIZE_LIMIT_BYTES`,当前为
239
+ * `104857600` bytes(100 MiB)。总和恰好等于上限仍合法,只有严格大于才算超限。
240
+ *
241
+ * @remarks
242
+ * 本函数不校验自定义上限。调用方应传有限且大于等于 `0` 的 number;`NaN`、负数或
243
+ * `Infinity` 会直接参与 JavaScript 的 `>` 比较,不应作为受支持配置使用。
244
+ */
55
245
  limitBytes?: number;
56
246
  }
247
+ /**
248
+ * 校验一组构建产物的总大小是否超过给定上限。
249
+ *
250
+ * @param items - 要累计的条目。函数按数组顺序读取每项 `size`,经 `Number(...)` 转换后仅
251
+ * 累加有限且大于 `0` 的值;不修改、过滤或排序输入数组,也不读取 `relativePath`。
252
+ * @param options - 可选 byte 上限;默认 `104857600` bytes(100 MiB)。自定义上限不会改变
253
+ * 固定错误文案。
254
+ * @returns 总和严格大于上限时返回唯一固定字符串
255
+ * `构建产物总大小超过 100MB,请删除未引用资源或压缩图片后重新 deploy`;总和小于或等于
256
+ * 上限时返回 `undefined`。函数不会因超限抛异常,调用方决定是否把返回文本转成 `Error`。
257
+ *
258
+ * @remarks
259
+ * 计算等价于把每项规范成 `Number.isFinite(Number(size)) && Number(size) > 0 ? Number(size) : 0`
260
+ * 后求和,不取整、不去重,也不设置单文件上限。因此一个文件可以占满全部预算,多个同路径
261
+ * 条目会重复计数,正小数会按 JavaScript number 原值加入;总和恰等 `limitBytes` 时通过,
262
+ * 多 1 byte 才返回错误。
263
+ *
264
+ * 在声明的 TypeScript 输入契约内,该函数以返回值报告预算结果,不为非有限/非正 size 抛错。
265
+ * 固定错误文本不包含首个文件、实际总量或自定义上限,即使测试/集成传了其他 `limitBytes`,
266
+ * 文案仍写 `100MB` 和 `重新 deploy`。`hb-sdk build` 的调用方会把末尾提示改成 `重新 build`。
267
+ *
268
+ * 该函数只校验一个未分组列表的总量,不读取文件系统,不执行 stat,也不校验路径、安全性、
269
+ * 文件数量、重复项、单文件大小或内容。调用方应先用
270
+ * [shouldUploadDistFile](/reference/symbols/miniapp-publish/functions/shouldUploadDistFile) 选择真正
271
+ * 上传的文件,并完成 `node_modules`、路径规范/唯一性/长度等校验;被提前过滤的 Manifest、
272
+ * `.DS_Store` 和 source map 才不会计入总量。
273
+ *
274
+ * Web 与 Companion 需要独立预算时使用 `validateMiniappUploadSizeBudgets()`:它按
275
+ * `relativePath` 的 `companions/` 前缀分组,Web 组复用本函数的默认 100 MiB 规则,Companion
276
+ * 组使用独立 500 MiB 上限。直接调用本函数不会识别或分开这些路径。
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * import { validateUploadTotalSize } from '@heybox/hb-sdk/miniapp-publish';
281
+ *
282
+ * const atLimit = validateUploadTotalSize(
283
+ * [
284
+ * { relativePath: 'assets/app.js', size: 1_024 },
285
+ * { relativePath: 'assets/ignored-negative.js', size: -1 },
286
+ * { relativePath: 'assets/ignored-nan.js', size: Number.NaN },
287
+ * ],
288
+ * { limitBytes: 1_024 },
289
+ * )
290
+ * console.log(atLimit) // undefined,恰等上限
291
+ *
292
+ * const overLimit = validateUploadTotalSize(
293
+ * [{ relativePath: 'assets/app.js', size: 1_025 }],
294
+ * { limitBytes: 1_024 },
295
+ * )
296
+ * if (overLimit) throw new Error(overLimit)
297
+ * ```
298
+ *
299
+ * @see {@link UploadSizeItem}
300
+ * @see {@link ValidateUploadTotalSizeOptions}
301
+ * @see [shouldUploadDistFile](/reference/symbols/miniapp-publish/functions/shouldUploadDistFile)
302
+ * @see [miniapp-publish](/reference/miniapp-publish/)
303
+ */
57
304
  export declare function validateUploadTotalSize(items: UploadSizeItem[], options?: ValidateUploadTotalSizeOptions): "构建产物总大小超过 100MB,请删除未引用资源或压缩图片后重新 deploy" | undefined;
305
+ /**
306
+ * 分别校验 Web 构建产物与 Companion 归档的总大小预算。
307
+ *
308
+ * @param items - 全部待上传文件;规范化后以 `companions/` 开头的路径计入 Companion 预算,其余计入 Web 预算。
309
+ * @param options - 可选测试或集成覆盖项:`webLimitBytes` 为 Web 上限,`companionLimitBytes` 为 Companion 上限,单位均为 bytes。
310
+ * @returns Web 或 Companion 的第一个超限提示;两类总量均不超过各自上限时返回 `undefined`。
311
+ * @remarks Web 默认上限为 100 MiB,Companion 默认上限为 500 MiB;两类预算不会相互借用。
312
+ * @example
313
+ * ```ts
314
+ * const error = validateMiniappUploadSizeBudgets([
315
+ * { relativePath: 'index.html', size: 1_024 },
316
+ * { relativePath: 'companions/runner/windows-x64.zip', size: 8_192 },
317
+ * ]);
318
+ * if (error) throw new Error(error);
319
+ * ```
320
+ */
58
321
  export declare function validateMiniappUploadSizeBudgets(items: UploadSizeItem[], options?: {
59
322
  webLimitBytes?: number;
60
323
  companionLimitBytes?: number;
61
324
  }): "构建产物总大小超过 100MB,请删除未引用资源或压缩图片后重新 deploy" | "Companion 归档总大小超过 500MiB 上限,请缩减归档后重新 deploy" | undefined;
325
+ /**
326
+ * 判断 `dist` 中的文件是否应作为版本产物上传。
327
+ *
328
+ * @param relativePath - `dist` 根目录下的文件路径。判断前先经 {@link normalizeRelativePath}
329
+ * 统一斜杠、删除前导 `/` 并合并连续 `/`;函数不读取文件系统或文件内容。
330
+ * @returns 以下规范化结果返回 `false`:空路径、精确等于根 `manifest.json`、精确 basename 为
331
+ * `.DS_Store` 的任意层级路径,以及以大小写不敏感 `.map` 结尾的路径。其他值返回 `true`。
332
+ *
333
+ * @remarks
334
+ * 过滤顺序以 `normalizeRelativePath(relativePath)` 的结果为准:
335
+ *
336
+ * - `''` 返回 `false`。
337
+ * - 只有精确根路径 `manifest.json` 返回 `false`;`/manifest.json` 规范化后也会命中。
338
+ * `assets/manifest.json` 会保留,因为它不是根文件。匹配大小写敏感,所以
339
+ * `Manifest.json` 不会作为生成 Manifest 被过滤。
340
+ * - 根或任意子目录中精确名为 `.DS_Store` 的最终 segment 返回 `false`,匹配大小写敏感;
341
+ * `.ds_store`、`.DS_Store.bak` 会保留。
342
+ * - 整条规范化路径经 `toLowerCase()` 后以 `.map` 结尾即返回 `false`,因此 `.map`、
343
+ * `app.js.map`、`app.js.MAP` 都会过滤,而 `app.js.map.txt` 会保留。
344
+ *
345
+ * 根 `manifest.json` 是发布流水线单独读取并上送后台的版本元数据,不作为 CDN 文件上传;
346
+ * 子目录同名文件仍被视为普通业务产物。该 predicate 只做上传集合选择,不验证输入确实是
347
+ * 文件,也不检查扩展名白名单、文件存在性或内容。
348
+ *
349
+ * `true` 不代表路径安全。本函数不会 URL decode,也不会拒绝 `node_modules`、symlink、绝对
350
+ * 路径、Windows drive prefix、`.` / `..`、空 segment、控制字符、重复路径或超长路径。
351
+ * build/deploy 必须另外使用 {@link relativePathContainsNodeModulesSegment} 拒绝依赖目录;deploy
352
+ * 还需在签名/上传前执行路径规范、唯一性和长度校验。
353
+ *
354
+ * build/deploy 会先扫描并完成上述独立边界,再以本函数过滤候选文件。build 对保留文件校验
355
+ * 上传大小预算;deploy 额外执行 artifact 排序/签名与路径长度校验。因此被过滤的根 Manifest、Finder
356
+ * 元数据和 source map 不计入上传文件数或大小;本函数自身不读取 `size`,也不能替代
357
+ * `validateUploadTotalSize()` / `validateMiniappUploadSizeBudgets()`。
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * import { shouldUploadDistFile } from '@heybox/hb-sdk/miniapp-publish';
362
+ *
363
+ * shouldUploadDistFile('/manifest.json'); // false,规范化后是根 manifest.json
364
+ * shouldUploadDistFile('assets/manifest.json'); // true
365
+ * shouldUploadDistFile('assets/.DS_Store'); // false
366
+ * shouldUploadDistFile('assets/.ds_store'); // true,.DS_Store 区分大小写
367
+ * shouldUploadDistFile('assets/app.js.MAP'); // false,.map 后缀不区分大小写
368
+ * shouldUploadDistFile('assets/app.js.map.txt'); // true
369
+ * shouldUploadDistFile('node_modules/pkg/index.js'); // true,必须另做 node_modules 检查
370
+ * shouldUploadDistFile('assets/../secret.js'); // true,但这不代表路径安全
371
+ * ```
372
+ *
373
+ * @see [normalizeRelativePath](/reference/symbols/miniapp-publish/functions/normalizeRelativePath)
374
+ * @see [relativePathContainsNodeModulesSegment](/reference/symbols/miniapp-publish/functions/relativePathContainsNodeModulesSegment)
375
+ * @see [validateUploadTotalSize](/reference/symbols/miniapp-publish/functions/validateUploadTotalSize)
376
+ * @see [miniapp-publish](/reference/miniapp-publish/)
377
+ */
62
378
  export declare function shouldUploadDistFile(relativePath: string): boolean;
63
- /** 参与整包签名和上传会话映射的构建产物文件。 */
379
+ /**
380
+ * 参与整包签名和上传会话映射的构建产物文件。
381
+ *
382
+ * 路径必须是规范相对路径,大小必须是大于或等于 `0` 的 safe integer。
383
+ */
64
384
  export interface MiniappArtifactFile {
65
- /** 使用 `/` 分隔的构建产物相对路径。 */
385
+ /** 使用 `/` 分隔的构建产物相对路径;不能包含绝对路径、点目录段、控制字符、逗号或通配符。 */
66
386
  relativePath: string;
67
- /** 文件字节数。 */
387
+ /** 文件大小,单位为 bytes;必须是大于或等于 `0` 的 safe integer。 */
68
388
  size: number;
69
389
  }
70
- /** 上传会话 v1 使用的逐文件完整性凭据。 */
390
+ /** 上传会话 v1 使用的逐文件完整性凭据,由本地文件内容计算。 */
71
391
  export interface MiniappArtifactFileReceipt extends MiniappArtifactFile {
72
- /** 文件内容 SHA-256,小写十六进制。 */
392
+ /** 文件内容 SHA-256,使用 64 位小写十六进制字符串。 */
73
393
  sha256: string;
74
394
  }
75
- /** 服务端上传会话返回的文件映射。 */
395
+ /** 服务端上传会话返回的单个文件映射。 */
76
396
  export interface MiniappUploadSessionFile {
77
- /** 与创建会话时提交值一致的相对路径。 */
397
+ /** 与创建会话时提交值一致的规范相对路径。 */
78
398
  relative_path: string;
79
- /** 服务端签发的完整上传 key。 */
399
+ /** 服务端签发的非空完整 CDN 上传 key;同一会话内必须唯一。 */
80
400
  key: string;
81
- /** 服务端记录的文件字节数。 */
401
+ /** 服务端记录的文件大小,单位为 bytes;必须是大于或等于 `0` 的 safe integer。 */
82
402
  size: number;
83
- /** 服务端固化的文件内容 SHA-256。 */
403
+ /** 服务端固化的文件内容 SHA-256,使用 64 位小写十六进制字符串。 */
84
404
  sha256: string;
85
405
  }
86
406
  /**
87
- * 校验构建产物路径和大小,并按路径 UTF-8 字节序排序。
407
+ * 校验构建产物路径和大小,并按路径的 UTF-8 字节序稳定排序。
88
408
  *
89
- * @param files - 待处理的构建产物文件。
90
- * @returns 保留输入附加字段的有序文件列表。
91
- * @throws 路径不规范、路径重复或文件大小非法时抛出错误。
409
+ * @param files - 待处理的构建产物文件;允许携带 `absolutePath`、`sha256` 等附加字段。
410
+ * @returns 新建的有序文件列表;每个结果保留输入条目的附加字段,输入数组顺序不变。
411
+ * @throws `Error` 当文件数超过 uint32、路径为空或不规范、路径重复,或大小不是非负 safe integer 时抛出。
412
+ * @remarks 路径必须已经使用规范 `/` 分隔形式;此函数不会把反斜杠或点目录段自动改写为其他路径。
413
+ * @example
414
+ * ```ts
415
+ * const files = prepareMiniappArtifactFiles([
416
+ * { relativePath: 'index.html', size: 15, absolutePath: '/tmp/dist/index.html' },
417
+ * { relativePath: 'assets/app.js', size: 42, absolutePath: '/tmp/dist/assets/app.js' },
418
+ * ]);
419
+ *
420
+ * console.log(files.map((file) => file.relativePath));
421
+ * // ['assets/app.js', 'index.html']
422
+ * ```
92
423
  */
93
424
  export declare function prepareMiniappArtifactFiles<T extends MiniappArtifactFile>(files: readonly T[]): (T & {
94
425
  relativePath: string;
@@ -96,9 +427,19 @@ export declare function prepareMiniappArtifactFiles<T extends MiniappArtifactFil
96
427
  /**
97
428
  * 按服务端 session key 前缀校验最终上传路径的 UTF-8 字节长度。
98
429
  *
99
- * @param files - 待上传的构建产物文件。
100
- * @param options - 小程序和长度限制配置。
430
+ * @param files - 待上传的构建产物文件;每个路径都必须是规范相对路径。
431
+ * @param options - `miniProgramId` 用于计算上传别名,`maxLength` 是完整 key 的最大 UTF-8 bytes,默认 {@link ACTIVITY_UPLOAD_KEY_MAX_LENGTH}。
101
432
  * @returns 第一个超长路径的错误提示;全部合法时返回 `undefined`。
433
+ * @throws `Error` 当任一文件路径为空或不符合构建产物路径规则时抛出。
434
+ * @remarks 会话引用按固定 10 个 ASCII 字符估算,因此该校验不依赖真实 session ID。
435
+ * @example
436
+ * ```ts
437
+ * const error = validateMiniappUploadPathLengths(
438
+ * [{ relativePath: 'assets/app.js' }],
439
+ * { miniProgramId: 'mp_example' },
440
+ * );
441
+ * if (error) throw new Error(error);
442
+ * ```
102
443
  */
103
444
  export declare function validateMiniappUploadPathLengths(files: readonly Pick<MiniappArtifactFile, 'relativePath'>[], options: {
104
445
  miniProgramId: string;
@@ -107,27 +448,56 @@ export declare function validateMiniappUploadPathLengths(files: readonly Pick<Mi
107
448
  /**
108
449
  * 创建 v1 整包签名头。
109
450
  *
110
- * @param fileCount - 参与签名的文件数量。
111
- * @returns 包含协议标识和文件数量的字节数组。
112
- * @throws 文件数量超出协议范围时抛出错误。
451
+ * @param fileCount - 参与签名的文件数量;必须是 `0` 到 `0xffffffff` 的整数。
452
+ * @returns 新的字节数组,依次包含固定协议标识和 big-endian uint32 文件数。
453
+ * @throws `Error` 当文件数不是整数、为负数或超出 uint32 范围时抛出。
454
+ * @example
455
+ * ```ts
456
+ * const header = createMiniappArtifactSignatureHeader(2);
457
+ * // 将 header 写入 SHA-256,再按排序结果依次写入文件 header 和内容。
458
+ * ```
113
459
  */
114
460
  export declare function createMiniappArtifactSignatureHeader(fileCount: number): Uint8Array<ArrayBuffer>;
115
461
  /**
116
462
  * 创建单个文件的 v1 framing header。
117
463
  *
118
- * @param file - 已规范化或待校验的构建产物文件。
119
- * @returns 包含路径长度、路径和文件大小的字节数组。
120
- * @throws 文件路径或大小非法时抛出错误。
464
+ * @param file - 构建产物文件;路径必须规范,大小必须是非负 safe integer。
465
+ * @returns 新的字节数组,依次包含 big-endian uint32 路径字节数、UTF-8 路径和 big-endian uint64 文件大小。
466
+ * @throws `Error` 当路径为空或不规范,或大小不是非负 safe integer 时抛出。
467
+ * @example
468
+ * ```ts
469
+ * const header = createMiniappArtifactFileHeader({
470
+ * relativePath: 'assets/app.js',
471
+ * size: 42,
472
+ * });
473
+ * ```
121
474
  */
122
475
  export declare function createMiniappArtifactFileHeader(file: MiniappArtifactFile): Uint8Array<ArrayBuffer>;
123
476
  /**
124
477
  * 校验服务端 session 文件映射,并计算仍需上传的文件。
125
478
  *
126
- * @param localFiles - 本地构建产物文件。
127
- * @param serverFiles - 服务端签发的文件映射。
128
- * @param uploadedKeys - 服务端已确认上传成功的 key。
129
- * @returns 完整映射、待上传文件和已确认 key。
130
- * @throws 服务端映射与本地产物不一致时抛出错误。
479
+ * @param localFiles - 本地构建产物 receipt;除 `relativePath` 和 `size` 外,每项必须包含 64 位小写十六进制 `sha256`。
480
+ * @param serverFiles - 服务端签发的文件映射;数量、路径、大小和 SHA-256 必须与本地产物一一一致。
481
+ * @param uploadedKeys - 服务端已确认上传成功的 key;每个值都必须属于当前会话,重复值会被去重。
482
+ * @returns
483
+ * 包含三个字段的对象:`files` 是按路径 UTF-8 字节序排列的全部 `{ file, key }` 映射,
484
+ * `missingFiles` 是其中尚未确认上传的映射,`uploadedKeys` 是去重后的已上传 key。
485
+ * @throws `Error` 当本地产物不规范,服务端映射数量或字段无效、重复或不匹配,或已上传 key 不属于当前产物时抛出。
486
+ * @example
487
+ * ```ts
488
+ * const resolved = resolveMiniappUploadSessionFiles(
489
+ * [{ relativePath: 'index.html', size: 15, sha256: 'a'.repeat(64) }],
490
+ * [{
491
+ * relative_path: 'index.html',
492
+ * key: '/u/abc/sessionref/index.html',
493
+ * size: 15,
494
+ * sha256: 'a'.repeat(64),
495
+ * }],
496
+ * [],
497
+ * );
498
+ *
499
+ * console.log(resolved.missingFiles.length); // 1
500
+ * ```
131
501
  */
132
502
  export declare function resolveMiniappUploadSessionFiles<T extends MiniappArtifactFile>(localFiles: readonly T[], serverFiles: readonly MiniappUploadSessionFile[], uploadedKeys: readonly string[]): {
133
503
  files: {
@@ -144,5 +514,31 @@ export declare function resolveMiniappUploadSessionFiles<T extends MiniappArtifa
144
514
  }[];
145
515
  uploadedKeys: string[];
146
516
  };
147
- /** 校验 Manifest 中所有 Companion 归档都精确属于当前上传 receipt。 */
517
+ /**
518
+ * 校验 Manifest 中所有 Companion 归档都精确属于当前上传 receipt。
519
+ *
520
+ * @param companions - `manifest.companions` 原始值;没有 Companion 时传 `undefined`。
521
+ * @param files - 当前版本的逐文件上传 receipt;只有 `companions/` 前缀文件参与本校验。
522
+ * @returns 校验成功时不返回值。
523
+ * @throws `Error` 当必要的 `targets`/artifact 字段缺失,引用不存在的归档、大小或 SHA-256 不一致,
524
+ * 或 receipt 中存在未被 Manifest 引用的 Companion 归档时抛出。
525
+ * @remarks 本函数只交叉校验 Companion 声明与上传 receipt,不替代完整 Manifest schema 校验。
526
+ * 非 Companion Web 文件会被忽略;`companions` 省略时 receipt 中也不能存在 Companion 归档。
527
+ * @example
528
+ * ```ts
529
+ * const receipt = [{
530
+ * relativePath: 'companions/runner/windows-x64.zip',
531
+ * size: 42,
532
+ * sha256: 'a'.repeat(64),
533
+ * }];
534
+ *
535
+ * validateMiniappCompanionFileReceipts({
536
+ * runner: {
537
+ * targets: {
538
+ * 'windows-x64': { path: receipt[0].relativePath, size: 42, sha256: receipt[0].sha256 },
539
+ * },
540
+ * },
541
+ * }, receipt);
542
+ * ```
543
+ */
148
544
  export declare function validateMiniappCompanionFileReceipts(companions: unknown, files: readonly MiniappArtifactFileReceipt[]): void;