@heybox/hb-sdk 0.6.8-alpha.2 → 0.6.9-alpha.0

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 (38) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +2 -0
  3. package/dist/cli-chunks/{build-CglqyB9Z.cjs → build-9hbhrRbU.cjs} +29 -25
  4. package/dist/cli-chunks/{context-CP7W_8aR.cjs → context-7rmakzS_.cjs} +122 -23
  5. package/dist/cli-chunks/{create-DldsTIVt.cjs → create-BkX4rtRP.cjs} +1 -1
  6. package/dist/cli-chunks/{dev-BG0icySa.cjs → dev-DiZGT4FQ.cjs} +142 -108
  7. package/dist/cli-chunks/{doctor-Cd6Xq0m-.cjs → doctor-BcpqXVRh.cjs} +1 -1
  8. package/dist/cli-chunks/{index-jXyfZKy2.cjs → index-6HfcwZ_r.cjs} +3 -3
  9. package/dist/cli-chunks/{index-paN77avR.cjs → index-DofTxdoX.cjs} +14 -14
  10. package/dist/cli-chunks/{login-DlD9n_AF.cjs → login-DUiejZcD.cjs} +2 -2
  11. package/dist/cli-chunks/{project-vite-vHezGsg7.cjs → project-vite-CfD8Bp1K.cjs} +1 -1
  12. package/dist/cli-chunks/{remote-O5_nRdZN.cjs → remote-A4-PKgOn.cjs} +462 -190
  13. package/dist/cli-chunks/{runtime-gate-DfMJQGH9.cjs → runtime-gate-BWlU-R4h.cjs} +3 -3
  14. package/dist/cli-chunks/{index-v4-6fbXX.cjs → runtime-permission-env-DKrhgVM3.cjs} +276 -49
  15. package/dist/cli-chunks/{session-CiQplems.cjs → session-D5u3XzHN.cjs} +1 -1
  16. package/dist/cli.cjs +1 -1
  17. package/dist/devtools/mock-host/main.js +609 -6
  18. package/dist/index.cjs.js +403 -7
  19. package/dist/index.esm.js +403 -7
  20. package/dist/miniapp-publish.cjs.js +205 -0
  21. package/dist/miniapp-publish.esm.js +201 -1
  22. package/dist/vite.cjs.js +17 -2
  23. package/dist/vite.esm.js +17 -2
  24. package/package.json +2 -2
  25. package/skill/SKILL.md +7 -6
  26. package/skill/references/api-root.md +7 -2
  27. package/skill/references/cli.md +12 -0
  28. package/skill/references/examples.md +17 -2
  29. package/skill/references/safety-boundaries.md +2 -0
  30. package/skill/scripts/sync-references.mjs +17 -2
  31. package/skill/skill.json +4 -4
  32. package/types/core/network-sanitize.d.ts +31 -0
  33. package/types/miniapp-publish/index.d.ts +77 -0
  34. package/types/modules/network/index.d.ts +2 -0
  35. package/types/modules/network/observability.d.ts +39 -0
  36. package/types/modules/network/request-shape.d.ts +44 -0
  37. package/types/vite/html-policy.d.ts +1 -0
  38. package/types/vite/runtime-permission-env.d.ts +9 -0
@@ -51,3 +51,80 @@ export interface ValidateUploadTotalSizeOptions {
51
51
  }
52
52
  export declare function validateUploadTotalSize(items: UploadSizeItem[], options?: ValidateUploadTotalSizeOptions): "构建产物总大小超过 100MB,请删除未引用资源或压缩图片后重新 deploy" | undefined;
53
53
  export declare function shouldUploadDistFile(relativePath: string): boolean;
54
+ /** 参与整包签名和上传会话映射的构建产物文件。 */
55
+ export interface MiniappArtifactFile {
56
+ /** 使用 `/` 分隔的构建产物相对路径。 */
57
+ relativePath: string;
58
+ /** 文件字节数。 */
59
+ size: number;
60
+ }
61
+ /** 服务端上传会话返回的文件映射。 */
62
+ export interface MiniappUploadSessionFile {
63
+ /** 与创建会话时提交值一致的相对路径。 */
64
+ relative_path: string;
65
+ /** 服务端签发的完整上传 key。 */
66
+ key: string;
67
+ /** 服务端记录的文件字节数。 */
68
+ size: number;
69
+ }
70
+ /**
71
+ * 校验构建产物路径和大小,并按路径 UTF-8 字节序排序。
72
+ *
73
+ * @param files 待处理的构建产物文件。
74
+ * @returns 保留输入附加字段的有序文件列表。
75
+ * @throws 路径不规范、路径重复或文件大小非法时抛出错误。
76
+ */
77
+ export declare function prepareMiniappArtifactFiles<T extends MiniappArtifactFile>(files: readonly T[]): (T & {
78
+ relativePath: string;
79
+ })[];
80
+ /**
81
+ * 按服务端 session key 前缀校验最终上传路径的 UTF-8 字节长度。
82
+ *
83
+ * @param files 待上传的构建产物文件。
84
+ * @param options 小程序和长度限制配置。
85
+ * @returns 第一个超长路径的错误提示;全部合法时返回 `undefined`。
86
+ */
87
+ export declare function validateMiniappUploadPathLengths(files: readonly Pick<MiniappArtifactFile, 'relativePath'>[], options: {
88
+ miniProgramId: string;
89
+ maxLength?: number;
90
+ }): string | undefined;
91
+ /**
92
+ * 创建 v1 整包签名头。
93
+ *
94
+ * @param fileCount 参与签名的文件数量。
95
+ * @returns 包含协议标识和文件数量的字节数组。
96
+ * @throws 文件数量超出协议范围时抛出错误。
97
+ */
98
+ export declare function createMiniappArtifactSignatureHeader(fileCount: number): Uint8Array<ArrayBuffer>;
99
+ /**
100
+ * 创建单个文件的 v1 framing header。
101
+ *
102
+ * @param file 已规范化或待校验的构建产物文件。
103
+ * @returns 包含路径长度、路径和文件大小的字节数组。
104
+ * @throws 文件路径或大小非法时抛出错误。
105
+ */
106
+ export declare function createMiniappArtifactFileHeader(file: MiniappArtifactFile): Uint8Array<ArrayBuffer>;
107
+ /**
108
+ * 校验服务端 session 文件映射,并计算仍需上传的文件。
109
+ *
110
+ * @param localFiles 本地构建产物文件。
111
+ * @param serverFiles 服务端签发的文件映射。
112
+ * @param uploadedKeys 服务端已确认上传成功的 key。
113
+ * @returns 完整映射、待上传文件和已确认 key。
114
+ * @throws 服务端映射与本地产物不一致时抛出错误。
115
+ */
116
+ export declare function resolveMiniappUploadSessionFiles<T extends MiniappArtifactFile>(localFiles: readonly T[], serverFiles: readonly MiniappUploadSessionFile[], uploadedKeys: readonly string[]): {
117
+ files: {
118
+ file: T & {
119
+ relativePath: string;
120
+ };
121
+ key: string;
122
+ }[];
123
+ missingFiles: {
124
+ file: T & {
125
+ relativePath: string;
126
+ };
127
+ key: string;
128
+ }[];
129
+ uploadedKeys: string[];
130
+ };
@@ -1,5 +1,7 @@
1
1
  import type { MiniProgramRequester } from '../../core/client';
2
2
  export { NETWORK_REQUEST_METHOD } from '../../protocol/capabilities';
3
+ export { createNetworkRequestFailureLog, formatNetworkRequestFailureMessage, logNetworkRequestFailure, previewNetworkData, sanitizeNetworkHeaders, sanitizeNetworkRequestUrl, } from './observability';
4
+ export { describeHostNetworkFailure, isMultipartContentType, isUnsupportedMultipartNetworkRequest, looksLikeMultipartBody, NETWORK_REQUEST_MULTIPART_UNSUPPORTED_MESSAGE, readNetworkContentType, } from './request-shape';
3
5
  /** `network.request` 请求头。 */
4
6
  export type MiniProgramNetworkHeaders = Record<string, string>;
5
7
  /** `network.request` 查询参数。 */
@@ -0,0 +1,39 @@
1
+ import type { MiniProgramNetworkHeaders, MiniProgramNetworkRequestConfig } from './index';
2
+ export { previewNetworkData, redactNetworkLogValue, sanitizeDiagnosticMessage, sanitizeNetworkHeaders, sanitizeNetworkRequestUrl, } from '../../core/network-sanitize';
3
+ export type NetworkRequestFailureKind = 'http_status' | 'invalid_response' | 'bridge_error' | 'unknown';
4
+ export interface NetworkRequestFailureLog {
5
+ kind: NetworkRequestFailureKind;
6
+ method: string;
7
+ url: string;
8
+ status?: number;
9
+ statusText?: string;
10
+ code?: string;
11
+ message?: string;
12
+ headers?: MiniProgramNetworkHeaders;
13
+ dataPreview?: unknown;
14
+ timeout?: number;
15
+ withCredentials?: boolean;
16
+ }
17
+ /**
18
+ * 记录 `network.request` 失败,保证异常路径在开发者控制台可观测。
19
+ *
20
+ * @remarks
21
+ * - 仅用于诊断,不改变错误抛出语义。
22
+ * - 会脱敏 token/cookie 等敏感头与字段,并截断 body 预览。
23
+ * - detail 构造与 logger 调用均包在 try 内,日志失败不得影响业务错误抛出。
24
+ */
25
+ export declare function logNetworkRequestFailure(config: MiniProgramNetworkRequestConfig, error: unknown, extras: {
26
+ kind: NetworkRequestFailureKind;
27
+ status?: number;
28
+ statusText?: string;
29
+ data?: unknown;
30
+ headers?: MiniProgramNetworkHeaders;
31
+ }): void;
32
+ export declare function createNetworkRequestFailureLog(config: MiniProgramNetworkRequestConfig, error: unknown, extras: {
33
+ kind: NetworkRequestFailureKind;
34
+ status?: number;
35
+ statusText?: string;
36
+ data?: unknown;
37
+ headers?: MiniProgramNetworkHeaders;
38
+ }): NetworkRequestFailureLog;
39
+ export declare function formatNetworkRequestFailureMessage(detail: NetworkRequestFailureLog): string;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * network.request 请求体形态校验与宿主失败诊断文案。
3
+ *
4
+ * @remarks
5
+ * App Host 的 heybox 客户端代发 transport 仅声明 form/json,不支持 multipart。
6
+ * 本地 Mock 若直接走 fetch 会“能通”,上线后却变成难以理解的 500 network_error。
7
+ * 因此在 SDK 侧统一提前拒绝 multipart,并在宿主伪装 HTTP 失败时给出可操作提示。
8
+ */
9
+ /** multipart 不被 App Host 支持时的稳定说明(开发者可见)。 */
10
+ export declare const NETWORK_REQUEST_MULTIPART_UNSUPPORTED_MESSAGE = "network.request \u4E0D\u652F\u6301 multipart/form-data\u3002App Host \u5BA2\u6237\u7AEF\u4EE3\u53D1\u4EC5\u652F\u6301 application/x-www-form-urlencoded\uFF08form\uFF09\u4E0E application/json\uFF1B\u8BF7\u5C06 data \u7F16\u7801\u4E3A form \u5B57\u7B26\u4E32\uFF08\u4F8B\u5982 new URLSearchParams({...}).toString()\uFF09\u5E76\u8BBE\u7F6E Content-Type: application/x-www-form-urlencoded\u3002\u6587\u4EF6\u4E0A\u4F20\u8BF7\u4F7F\u7528\u4E13\u7528\u4E0A\u4F20\u80FD\u529B\uFF0C\u52FF\u624B\u5199 multipart boundary\u3002";
11
+ /**
12
+ * 读取请求头中的 Content-Type(大小写不敏感)。
13
+ */
14
+ export declare function readNetworkContentType(headers: Record<string, string> | undefined): string | undefined;
15
+ /**
16
+ * 判断 Content-Type 是否声明为 multipart/form-data。
17
+ */
18
+ export declare function isMultipartContentType(contentType: string | undefined): boolean;
19
+ /**
20
+ * 判断字符串 body 是否像手写 multipart 实体。
21
+ */
22
+ export declare function looksLikeMultipartBody(data: unknown): boolean;
23
+ /**
24
+ * 判断公开请求配置是否使用了 Host 不支持的 multipart 形态。
25
+ */
26
+ export declare function isUnsupportedMultipartNetworkRequest(config: {
27
+ data?: unknown;
28
+ headers?: Record<string, string>;
29
+ }): boolean;
30
+ /**
31
+ * 从宿主返回的“完成态”响应中提取更清晰的失败原因。
32
+ *
33
+ * @remarks
34
+ * Host 可能把 transport 不支持等内部错误包装成 HTTP 500 + `{ status: 'network_error', msg }`。
35
+ * 此时 `status=500` 并不代表目标站点返回了 500。
36
+ */
37
+ export declare function describeHostNetworkFailure(response: {
38
+ config?: {
39
+ data?: unknown;
40
+ headers?: Record<string, string>;
41
+ };
42
+ data?: unknown;
43
+ status: number;
44
+ }): string | undefined;
@@ -1,4 +1,5 @@
1
1
  export declare const PRODUCTION_CSP: string;
2
2
  export declare function enforceMiniappHtmlPolicy(html: string, options?: {
3
3
  hmrWebSocketUrl?: string;
4
+ skipPlatformCsp?: boolean;
4
5
  }): string;
@@ -0,0 +1,9 @@
1
+ export declare const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = "HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN";
2
+ export declare const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = "HB_SDK_RUNTIME_PERMISSION_CONTEXT";
3
+ export declare function shouldSkipMiniappPlatformCspFromEnv(env?: NodeJS.ProcessEnv): boolean;
4
+ export declare function createMiniappPlatformCspEnv(env: NodeJS.ProcessEnv, skipPlatformCsp: boolean): {
5
+ HB_SDK_RUNTIME_PERMISSION_CONTEXT: string;
6
+ HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN: string;
7
+ TZ?: string | undefined;
8
+ };
9
+ export declare function withMiniappPlatformCspEnv<T>(skipPlatformCsp: boolean, action: () => Promise<T>, env?: NodeJS.ProcessEnv): Promise<T>;