@heybox/hb-sdk 0.9.1-alpha.4 → 0.9.1-alpha.6

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 (112) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/README.md +33 -0
  3. package/dist/card-controller.cjs.js +194 -0
  4. package/dist/card-controller.esm.js +159 -0
  5. package/dist/cli-chunks/browser-DUdEZCyq.cjs +15 -0
  6. package/dist/cli-chunks/{build-BZg2rHkW.cjs → build-DYYWRiaY.cjs} +22 -10
  7. package/dist/cli-chunks/{context-YrzmEOau.cjs → context-Bo4L-Cx_.cjs} +12 -12
  8. package/dist/cli-chunks/{create-fPvlqLbS.cjs → create-CKC4yp0J.cjs} +12 -5
  9. package/dist/cli-chunks/{dev-X8_kbp78.cjs → dev-BMX6UXUe.cjs} +58 -13
  10. package/dist/cli-chunks/{doctor-DdiucYs9.cjs → doctor-DqEYRo4I.cjs} +13 -6
  11. package/dist/cli-chunks/{index-BdbwsefW.cjs → index-DmCWB_hF.cjs} +4 -7
  12. package/dist/cli-chunks/{index-BGh-Izf8.cjs → index-J4uQvKT_.cjs} +8780 -4464
  13. package/dist/cli-chunks/{index.esm-WYIrPjkF.cjs → index.esm-eNPTDv6W.cjs} +18 -19
  14. package/dist/cli-chunks/{login-DWmNuhWc.cjs → login-BL2OE6r9.cjs} +32 -33
  15. package/dist/cli-chunks/{project-vite-BVDIeoHB.cjs → project-vite-Du1m7Y_3.cjs} +1 -1
  16. package/dist/cli-chunks/{remote-BHJFxXyc.cjs → remote-ZHJUtx6l.cjs} +49 -38
  17. package/dist/cli-chunks/runtime-gate-DedD3ynE.cjs +201950 -0
  18. package/dist/cli-chunks/{runtime-permission-env-eiq8vE62.cjs → runtime-permission-env-DWaPlchd.cjs} +9396 -2929
  19. package/dist/cli-chunks/{skill-DC3cfPj2.cjs → skill-D4z_a_BH.cjs} +14 -7
  20. package/dist/cli-chunks/{version-DYFkOykv.cjs → version-tzrFwpkl.cjs} +1 -1
  21. package/dist/cli.cjs +14 -6
  22. package/dist/devtools/browser-dev-host/assets/browser-dev-host-BL1URvGR.js +102 -0
  23. package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-CZsodKbP.js → desktop-app-launch-D6QZYpUq.js} +3 -3
  24. package/dist/devtools/browser-dev-host/assets/{index-B9tOX3zG.js → index-Bqsp608m.js} +4 -4
  25. package/dist/devtools/browser-dev-host/index.html +2 -2
  26. package/dist/index.cjs.js +6224 -275
  27. package/dist/index.esm.js +6224 -276
  28. package/dist/miniapp-publish.cjs.js +6612 -168
  29. package/dist/miniapp-publish.esm.js +6612 -169
  30. package/dist/protocol.cjs.js +5805 -0
  31. package/dist/protocol.esm.js +5805 -0
  32. package/dist/vite.cjs.js +7475 -217
  33. package/dist/vite.esm.js +7474 -218
  34. package/dist/workspace-card-build-sandbox-worker.mjs +72 -0
  35. package/package.json +25 -11
  36. package/skill/SKILL.md +15 -0
  37. package/skill/skill.json +5 -5
  38. package/types/card-controller.d.ts +3682 -0
  39. package/types/index.d.ts +7532 -35
  40. package/types/miniapp-publish/index.d.ts +542 -64
  41. package/types/protocol.d.ts +2083 -9
  42. package/types/vite/index.d.ts +25 -12
  43. package/dist/cli-chunks/browser-RAy8e8cV.cjs +0 -635
  44. package/dist/cli-chunks/runtime-gate-CR0dRMpQ.cjs +0 -65
  45. package/dist/cli-chunks/session-Dz1cGg0E.cjs +0 -3403
  46. package/dist/devtools/browser-dev-host/assets/browser-dev-host-CO2_03W0.js +0 -102
  47. package/types/core/client.d.ts +0 -108
  48. package/types/core/csp-violation.d.ts +0 -5
  49. package/types/core/errors.d.ts +0 -78
  50. package/types/core/event-bus.d.ts +0 -11
  51. package/types/core/handshake-state.d.ts +0 -54
  52. package/types/core/history-observer.d.ts +0 -4
  53. package/types/core/mini-dev-console.d.ts +0 -36
  54. package/types/core/network-sanitize.d.ts +0 -31
  55. package/types/core/sdk.d.ts +0 -104
  56. package/types/core/singleton.d.ts +0 -372
  57. package/types/core/utils.d.ts +0 -10
  58. package/types/core/version.d.ts +0 -2
  59. package/types/devtools/device-logs.d.ts +0 -48
  60. package/types/miniapp-manifest/basic-info-browser.d.ts +0 -37
  61. package/types/miniapp-manifest/basic-info-image-header.d.ts +0 -6
  62. package/types/miniapp-manifest/basic-info-node.d.ts +0 -17
  63. package/types/miniapp-manifest/basic-info-placeholder.d.ts +0 -1
  64. package/types/miniapp-manifest/basic-info.d.ts +0 -33
  65. package/types/miniapp-manifest/bindings.d.ts +0 -70
  66. package/types/miniapp-manifest/category.d.ts +0 -11
  67. package/types/miniapp-manifest/companion-directory.d.ts +0 -2
  68. package/types/miniapp-manifest/companion-executable.d.ts +0 -4
  69. package/types/miniapp-manifest/companion-types.d.ts +0 -63
  70. package/types/miniapp-manifest/companions.d.ts +0 -17
  71. package/types/miniapp-manifest/index.d.ts +0 -7
  72. package/types/miniapp-manifest/node.d.ts +0 -22
  73. package/types/miniapp-manifest/permissions.d.ts +0 -48
  74. package/types/miniapp-manifest/runtime-gate.d.ts +0 -12
  75. package/types/miniapp-manifest/schema.d.ts +0 -302
  76. package/types/modules/auth/index.d.ts +0 -204
  77. package/types/modules/cloud/index.d.ts +0 -669
  78. package/types/modules/companion/index.d.ts +0 -1619
  79. package/types/modules/device/index.d.ts +0 -269
  80. package/types/modules/environment/index.d.ts +0 -238
  81. package/types/modules/files/index.d.ts +0 -5
  82. package/types/modules/files/registry.d.ts +0 -35
  83. package/types/modules/files/types.d.ts +0 -1548
  84. package/types/modules/navigation/app-pages/index.d.ts +0 -4
  85. package/types/modules/navigation/app-pages/types.d.ts +0 -135
  86. package/types/modules/navigation/index.d.ts +0 -312
  87. package/types/modules/network/index.d.ts +0 -457
  88. package/types/modules/network/observability.d.ts +0 -38
  89. package/types/modules/network/request-shape.d.ts +0 -44
  90. package/types/modules/share/copy-link.d.ts +0 -46
  91. package/types/modules/share/extra.d.ts +0 -5
  92. package/types/modules/share/index.d.ts +0 -294
  93. package/types/modules/share/screenshot.d.ts +0 -34
  94. package/types/modules/share/show-share-menu.d.ts +0 -29
  95. package/types/modules/share/types.d.ts +0 -201
  96. package/types/modules/storage/index.d.ts +0 -214
  97. package/types/modules/ui/index.d.ts +0 -315
  98. package/types/modules/user/get-info.d.ts +0 -44
  99. package/types/modules/user/index.d.ts +0 -245
  100. package/types/modules/user/revoke-authorization.d.ts +0 -31
  101. package/types/modules/user/steam-game-list.d.ts +0 -153
  102. package/types/modules/user/types.d.ts +0 -2
  103. package/types/modules/viewport/index.d.ts +0 -319
  104. package/types/protocol/capabilities.d.ts +0 -2
  105. package/types/protocol/constants.d.ts +0 -1
  106. package/types/protocol/dev-session.d.ts +0 -74
  107. package/types/protocol/guards.d.ts +0 -1
  108. package/types/protocol/runtime-permissions.d.ts +0 -2
  109. package/types/protocol/types.d.ts +0 -22
  110. package/types/skill-metadata.d.ts +0 -18
  111. package/types/vite/html-policy.d.ts +0 -6
  112. package/types/vite/runtime-permission-env.d.ts +0 -9
@@ -1,108 +0,0 @@
1
- import { type MiniProgramSDKHandshakeState, type MiniProgramSDKHandshakeStateHandler } from './handshake-state';
2
- import { type MiniProgramEnvironmentInfo, type MiniProgramEnvironmentReader } from '../modules/environment';
3
- import type { MiniProgramBridgeMethod, MiniProgramCapabilityPayload, MiniProgramCapabilityResult } from '../protocol/capabilities';
4
- import type { MiniProgramEventHandler, MiniProgramEventName } from '../protocol/types';
5
- /**
6
- * 创建 SDK bridge client 的配置项。
7
- *
8
- * @remarks
9
- * 该配置主要用于独立实例、自定义宿主环境注入和测试场景。
10
- */
11
- export interface MiniProgramSDKOptions {
12
- /** 请求与握手超时时间,单位毫秒。 */
13
- timeout?: number;
14
- /** 父容器注入的 bridge nonce;默认从 URL query 读取。 */
15
- nonce?: string;
16
- /** 当前 iframe 内的 window,测试环境可注入。 */
17
- selfWindow?: Window;
18
- /** 父窗口,测试环境可注入;显式传 null 可模拟非 iframe 环境。 */
19
- targetWindow?: Window | null;
20
- /** 精准 postMessage 目标 origin;未传时尝试推断,失败则回退为 `*`。 */
21
- targetOrigin?: string;
22
- }
23
- type MiniProgramRequesterArgs<Method extends MiniProgramBridgeMethod> = MiniProgramCapabilityPayload<Method> extends void ? [payload?: MiniProgramCapabilityPayload<Method>] : undefined extends MiniProgramCapabilityPayload<Method> ? [payload?: MiniProgramCapabilityPayload<Method>] : [payload: MiniProgramCapabilityPayload<Method>];
24
- /** 模块 API 发起请求所需的最小能力。 */
25
- export interface MiniProgramRequester {
26
- /** 向父容器调用指定开放能力。 */
27
- request<Method extends MiniProgramBridgeMethod>(method: Method, ...args: MiniProgramRequesterArgs<Method>): Promise<MiniProgramCapabilityResult<Method>>;
28
- }
29
- /** 长操作使用的本地 observer 与取消配置,不进入 bridge payload。 */
30
- export interface MiniProgramOperationOptions<TProgress = unknown> {
31
- signal?: AbortSignal;
32
- onProgress?: (progress: TProgress) => void;
33
- createAbortError?: () => unknown;
34
- /** Long Host operations can survive observer teardown. */
35
- cancelOnAbort?: boolean;
36
- }
37
- /** 支持 request-scoped progress/cancel 的 bridge requester。 */
38
- export interface MiniProgramOperationRequester extends MiniProgramRequester {
39
- requestOperation<Method extends MiniProgramBridgeMethod, TProgress = unknown>(method: Method, payload: MiniProgramCapabilityPayload<Method>, options?: MiniProgramOperationOptions<TProgress>): Promise<MiniProgramCapabilityResult<Method>>;
40
- }
41
- /** 底层 bridge client,负责握手、请求响应、事件分发与超时清理。 */
42
- export declare class MiniProgramBridgeClient implements MiniProgramOperationRequester, MiniProgramEnvironmentReader {
43
- private readonly timeout;
44
- private readonly selfWindow?;
45
- private readonly targetWindow;
46
- private readonly targetOrigin;
47
- private readonly nonce;
48
- private readonly pendingRequests;
49
- private readonly eventBus;
50
- private readonly handleMessage;
51
- private readonly handlePopState;
52
- private readonly handleHashChange;
53
- private readonly handlePageShow;
54
- private readonly handleSecurityPolicyViolation;
55
- private unsubscribeHistoryChanges?;
56
- private started;
57
- private readonly handshakeState;
58
- private handshakeSettled;
59
- private handshakePromise;
60
- private resolveHandshake;
61
- private rejectHandshake;
62
- private handshakeTimer?;
63
- private handshakeRetryTimer?;
64
- private destroyed;
65
- private runtimeUnavailable;
66
- private runtimeUnavailableError?;
67
- private environmentInfo?;
68
- constructor(options?: MiniProgramSDKOptions);
69
- /** 等待父容器握手完成。 */
70
- waitForHandshake(): Promise<void>;
71
- /** 获取当前握手状态。 */
72
- getHandshakeState(): MiniProgramSDKHandshakeState;
73
- /** 订阅握手状态,并立即接收当前状态。 */
74
- onHandshakeStateChange(handler: MiniProgramSDKHandshakeStateHandler): () => void;
75
- /** 等待握手后读取当前实例的环境快照。 */
76
- getEnvironmentInfo(): Promise<MiniProgramEnvironmentInfo>;
77
- /** 同步读取握手期间缓存的环境快照。 */
78
- getEnvironmentInfoSync(): MiniProgramEnvironmentInfo;
79
- /** 注册小程序事件监听。 */
80
- on<T extends MiniProgramEventName>(eventName: T, handler: MiniProgramEventHandler<T>): () => void;
81
- /** 移除小程序事件监听。 */
82
- off<T extends MiniProgramEventName>(eventName: T, handler: MiniProgramEventHandler<T>): void;
83
- /** 调用父容器开放能力。 */
84
- request<Method extends MiniProgramBridgeMethod>(method: Method, ...args: MiniProgramRequesterArgs<Method>): Promise<MiniProgramCapabilityResult<Method>>;
85
- /** 发起不使用固定总时长 timer 的长操作。 */
86
- requestOperation<Method extends MiniProgramBridgeMethod, TProgress = unknown>(method: Method, payload: MiniProgramCapabilityPayload<Method>, options?: MiniProgramOperationOptions<TProgress>): Promise<MiniProgramCapabilityResult<Method>>;
87
- private performRequest;
88
- /** 销毁 SDK 实例,并拒绝尚未完成的请求。 */
89
- destroy(): void;
90
- private ensureStarted;
91
- private postHandshake;
92
- private onMessage;
93
- private postLocationReport;
94
- private postCSPViolation;
95
- private handleEvent;
96
- private handleResponse;
97
- private handleOperationProgress;
98
- private sendCancel;
99
- private cleanupPending;
100
- private postMessage;
101
- private resolveHandshakeOnce;
102
- private failHandshake;
103
- private clearHandshakeTimers;
104
- private markRuntimeUnavailable;
105
- private getRuntimeUnavailableError;
106
- private rejectAllPending;
107
- }
108
- export {};
@@ -1,5 +0,0 @@
1
- import type { SDKCSPViolationPayload } from '../protocol/types';
2
- type CSPViolationLike = Pick<SecurityPolicyViolationEvent, 'blockedURI' | 'disposition' | 'effectiveDirective' | 'violatedDirective'>;
3
- /** 将浏览器 CSP 事件转换为不包含原始 URL 敏感部分的 bridge 载荷。 */
4
- export declare function createCSPViolationPayload(event: CSPViolationLike, baseHref: string, sdkVersion: string, cryptoImplementation: Crypto): Promise<SDKCSPViolationPayload>;
5
- export {};
@@ -1,78 +0,0 @@
1
- import type { MiniProgramBridgeError } from '../protocol/types';
2
- import type { MiniProgramNetworkRequestConfig, MiniProgramNetworkResponse } from '../modules/network';
3
- /**
4
- * SDK 对外抛出的标准 bridge / runtime 错误类型。
5
- *
6
- * @remarks
7
- * 该错误用于表示握手失败、bridge 调用失败、父容器运行时错误等
8
- * 非 HTTP 结果错误。其 `code` 字段可用于业务分支处理,
9
- * `data` 仅作为可选调试信息,不保证结构稳定。错误码是跨 Host 的分支契约;
10
- * `message` 只用于日志和开发者提示,不应作为机器判断条件。
11
- *
12
- * 常见处理类别包括:`INVALID_PARAMS`(修正调用参数)、`PERMISSION_NOT_DECLARED`
13
- * 或 `PERMISSION_DENIED`(检查 Manifest/平台批准)、`USER_GESTURE_REQUIRED`
14
- *(改为用户点击后重试)、`AUTHORIZATION_CANCELLED`(结束当前流程),以及
15
- * `METHOD_FORBIDDEN`(当前 Host 不支持该能力)。具体能力还可能返回模块专属错误码。
16
- * 不要把所有错误都当作可重试错误,也不要把 `data` 当成稳定的序列化协议。
17
- *
18
- * @example
19
- * ```ts
20
- * import hbSDK, { HbMiniProgramSDKError } from '@heybox/hb-sdk'
21
- *
22
- * try {
23
- * await hbSDK.auth.login({ scopes: ['profile'] })
24
- * } catch (error) {
25
- * if (error instanceof HbMiniProgramSDKError && error.code === 'USER_GESTURE_REQUIRED') {
26
- * showRetryButton()
27
- * return
28
- * }
29
- * throw error
30
- * }
31
- * ```
32
- */
33
- export declare class HbMiniProgramSDKError extends Error {
34
- /** 稳定错误码;业务分支应比较该字段,不要比较 `message`。 */
35
- code: string;
36
- /** 可选调试数据;结构由具体错误码决定,可能随 Host 版本变化。 */
37
- data?: unknown;
38
- constructor(error: MiniProgramBridgeError);
39
- }
40
- /**
41
- * 创建 SDK 标准错误。
42
- *
43
- * @param code - 稳定错误码。
44
- * @param message - 面向开发者的错误说明。
45
- * @param data - 可选调试数据。
46
- * @returns 标准化 `HbMiniProgramSDKError` 实例。
47
- *
48
- * @remarks
49
- * 仅供 SDK 内部或同仓运行时层统一构造 bridge / runtime 错误。
50
- */
51
- export declare function createSDKError(code: string, message: string, data?: unknown): HbMiniProgramSDKError;
52
- /**
53
- * SDK 对外抛出的 HTTP 错误类型。
54
- *
55
- * @remarks
56
- * 仅在请求已经成功走完 bridge / runtime / 宿主调用链、但最终 HTTP 状态不满足
57
- * `validateStatus` 时抛出。它不表示握手失败或 bridge 级错误。网络请求没有收到
58
- * 可判定的 HTTP 响应时,SDK 会抛出 `HbMiniProgramSDKError` 或原始 transport 错误,
59
- * 不应把本类当作网络不可达的统一错误类型。
60
- *
61
- * @typeParam T - 标准化响应数据的类型。
62
- */
63
- export declare class HbMiniProgramNetworkError<T = unknown> extends Error {
64
- /** HTTP 状态码;由 `validateStatus` 判定为失败的响应状态。 */
65
- status: number;
66
- /** 标准化响应数据;类型由 `network.request<T>()` 的泛型参数决定。 */
67
- data: T;
68
- /** 标准化响应头;敏感响应头会在进入错误对象前被脱敏或移除。 */
69
- headers: Record<string, string>;
70
- /** SDK 公共请求配置快照;可能含原始 URL、请求头或请求数据,记录日志前必须自行脱敏。 */
71
- config: MiniProgramNetworkRequestConfig;
72
- /** 完整标准化响应,包含状态、头、数据和请求配置。 */
73
- response: MiniProgramNetworkResponse<T>;
74
- /**
75
- * @param response - 已完成请求的标准化网络响应。
76
- */
77
- constructor(response: MiniProgramNetworkResponse<T>);
78
- }
@@ -1,11 +0,0 @@
1
- import type { MiniProgramEventHandler, MiniProgramEventName } from '../protocol/types';
2
- /** SDK 内部事件总线,负责管理沙盒生命周期与业务事件监听。 */
3
- export declare class MiniProgramEventBus {
4
- private readonly eventHandlers;
5
- /** 注册事件监听,并返回取消监听函数。 */
6
- on<T extends MiniProgramEventName>(eventName: T, handler: MiniProgramEventHandler<T>): () => void;
7
- /** 移除事件监听。 */
8
- off<T extends MiniProgramEventName>(eventName: T, handler: MiniProgramEventHandler<T>): void;
9
- /** 派发事件。 */
10
- emit(eventName: MiniProgramEventName, payload: unknown): void;
11
- }
@@ -1,54 +0,0 @@
1
- import type { HbMiniProgramSDKError } from './errors';
2
- /**
3
- * SDK 与 Host 握手的持久状态。
4
- *
5
- * @remarks
6
- * 状态是按 `status` 判别的只读联合类型:
7
- *
8
- * - `connecting`:默认 SDK 已开始初始握手但尚未落定;
9
- * - `ready`:初始握手已成功;
10
- * - `failed`:初始握手已失败,`error` 是导致失败的原始
11
- * [HbMiniProgramSDKError](/reference/symbols/root/classes/HbMiniProgramSDKError)。
12
- *
13
- * 新实例只会从 `connecting` 迁移一次到 `ready` 或 `failed`,终态不会回退或互相转换;重复的
14
- * `ready` 事件也不会建立第二次状态迁移。每个状态 wrapper 都经过 `Object.freeze()`,调用方不能
15
- * 替换 `status` 或 `failed.error`;冻结是浅层的,`error` 保留原始实例而不是克隆或冻结副本。
16
- *
17
- * `ready` 只记录初始握手已经成功,不是 Runtime 的持续存活探针;后续收到 `unload` 或销毁实例时
18
- * 仍不会回退。该持久状态适合驱动交互控件;生命周期 `ready` 事件只是一条不会向晚订阅者重放的
19
- * 边沿通知,不能替代当前状态。
20
- */
21
- export type MiniProgramSDKHandshakeState = {
22
- readonly status: 'connecting';
23
- } | {
24
- readonly status: 'ready';
25
- } | {
26
- readonly status: 'failed';
27
- readonly error: HbMiniProgramSDKError;
28
- };
29
- /**
30
- * SDK 握手状态变化处理函数。
31
- *
32
- * @param state - 当前冻结的
33
- * [MiniProgramSDKHandshakeState](/reference/symbols/root/types/MiniProgramSDKHandshakeState):
34
- * `connecting` 表示尚未落定,`ready` 表示初始握手成功,`failed.error` 保留原始握手错误。
35
- *
36
- * @remarks
37
- * [onHandshakeStateChange()](/reference/sdk/lifecycle/onHandshakeStateChange) 会在注册过程中同步调用
38
- * handler 一次;若当前为 `connecting`,状态落定时至多再同步调用一次。SDK 会隔离 handler 的同步
39
- * 异常,使其不阻断状态落定或其他订阅者;返回值会被忽略且 Promise 不会被等待,因此异步 handler
40
- * 必须自行处理 rejected Promise。
41
- */
42
- export type MiniProgramSDKHandshakeStateHandler = (state: MiniProgramSDKHandshakeState) => void;
43
- /** 保存握手终态,并向订阅者同步派发唯一一次状态迁移。 */
44
- export declare class MiniProgramSDKHandshakeStateStore {
45
- private state;
46
- private readonly handlers;
47
- getState(): MiniProgramSDKHandshakeState;
48
- subscribe(handler: MiniProgramSDKHandshakeStateHandler): () => void;
49
- clear(): void;
50
- settle(state: Extract<MiniProgramSDKHandshakeState, {
51
- status: 'ready' | 'failed';
52
- }>): void;
53
- private notify;
54
- }
@@ -1,4 +0,0 @@
1
- type HistoryChangeListener = () => void;
2
- /** 共享同一个 History patch,并在最后一个订阅者退出时精确恢复原属性。 */
3
- export declare function subscribeHistoryChanges(history: History, listener: HistoryChangeListener): () => void;
4
- export {};
@@ -1,36 +0,0 @@
1
- /**
2
- * iframe 与调试台页面的开发期 console 捕获转发。
3
- *
4
- * 双条件门控(iframe 转发):
5
- * 1. 构建期:`hb-sdk dev`(vite serve)注入 `__HB_SDK_DEV_LOGGING__`;`hb-sdk build` /
6
- * `vite build`(生产)永不注入或替换为 `false`,本模块被死代码消除。
7
- * 2. 运行期:仅在 `window.name` 为 `__hb_sdk_mini_dev__` 的调试 iframe 中激活,
8
- * 用户设备上的正式运行环境没有该标记。
9
- *
10
- * 无侵入 patch `console.log/debug/info/warn/error`:原样放行(DevTools 不受影响)+
11
- * 通过 `window.parent.postMessage` 转发给调试台(CSP 的 connect-src 不约束 postMessage,
12
- * 网络上报由调试台页面代理)。发送全程静默:失败不得回打 console,避免自触发死循环。
13
- *
14
- * 激活时机:由 SDK 默认单例初始化时调用(业务 `import '@heybox/hb-sdk'` 即生效);
15
- * iframe 标记由调试台 `iframe.name` 与 vite dev 注入的无依赖 bootstrap 共同设置。
16
- * 调试台页面自身(runtime 跑在这里,`[hb-sdk-runtime]` 日志不经过 iframe)另用
17
- * `installMiniDevConsoleSelfCapture` 接入「日志」页签(source: 'host')。
18
- */
19
- export declare const MINI_DEV_IFRAME_WINDOW_NAME = "__hb_sdk_mini_dev__";
20
- export declare const MINI_DEV_CONSOLE_EVENT_TYPE = "hb-sdk:mini-dev-console";
21
- /** 对外契约:调试台监听该 postMessage 读取转发日志;message 结构必须稳定。 */
22
- export interface MiniDevConsoleMessage {
23
- type: typeof MINI_DEV_CONSOLE_EVENT_TYPE;
24
- detail: MiniDevConsoleEventDetail;
25
- }
26
- export type MiniDevConsoleLevel = 'log' | 'debug' | 'info' | 'warn' | 'error';
27
- export interface MiniDevConsoleEventDetail {
28
- level: MiniDevConsoleLevel;
29
- args: unknown[];
30
- timestamp: number;
31
- }
32
- /** 调试台页面与 iframe bootstrap 共用的已安装标记(window/console 上的属性名)。 */
33
- export declare const MINI_DEV_CONSOLE_INSTALL_FLAG = "__hb_sdk_mini_dev_console_installed__";
34
- /** 调试台页面(非 iframe)自捕获:runtime/host 侧 console 直接进「日志」页签。 */
35
- export declare function installMiniDevConsoleSelfCapture(onLog: (level: MiniDevConsoleLevel, args: unknown[]) => void, consoleRef?: Console): void;
36
- export declare function installMiniDevConsoleForwarding(consoleRef?: Console): void;
@@ -1,31 +0,0 @@
1
- /**
2
- * network.request 诊断日志的纯脱敏工具。
3
- *
4
- * @remarks
5
- * 放在 `core` 而非 `modules/network`:无错误类型依赖,供 SDK 错误文案、
6
- * modules observability、devtools Browser Dev Host / proxy 共用,并满足 boundary
7
- *(devtools 不得直接 import runtime capability modules)。
8
- */
9
- export type MiniProgramNetworkHeadersLike = Record<string, string>;
10
- /**
11
- * 脱敏请求 URL:去掉 userinfo,并将 query / fragment 中的敏感参数值替换为 `[redacted]`。
12
- */
13
- export declare function sanitizeNetworkRequestUrl(url: string): string;
14
- /**
15
- * 脱敏请求/响应头;敏感名(含 heybox 前缀)替换为 `[redacted]`。
16
- */
17
- export declare function sanitizeNetworkHeaders(headers?: MiniProgramNetworkHeadersLike): MiniProgramNetworkHeadersLike;
18
- /**
19
- * 预览请求/响应 data:递归脱敏敏感字段,截断长文本与大数组。
20
- */
21
- export declare function previewNetworkData(data: unknown): unknown;
22
- /**
23
- * 递归脱敏日志对象(payload / result):敏感 key、headers、url 字段统一处理。
24
- */
25
- export declare function redactNetworkLogValue(value: unknown): unknown;
26
- /**
27
- * 诊断 message 中的 URL 片段做脱敏,避免 error.message 二次泄漏 query secrets。
28
- */
29
- export declare function sanitizeDiagnosticMessage(message: string): string;
30
- export declare function isSensitiveNetworkHeaderName(headerName: string): boolean;
31
- export declare function isSensitiveNetworkKey(key: string): boolean;
@@ -1,104 +0,0 @@
1
- import { type MiniProgramSDKOptions } from './client';
2
- import { type MiniProgramAuthModule } from '../modules/auth';
3
- import { type MiniProgramCloudModule } from '../modules/cloud';
4
- import { type MiniProgramCompanionModule } from '../modules/companion';
5
- import { type MiniProgramShareModule } from '../modules/share';
6
- import { type MiniProgramStorageModule } from '../modules/storage';
7
- import { type MiniProgramNetworkModule } from '../modules/network';
8
- import { type FilesModule } from '../modules/files';
9
- import { type MiniProgramViewportModule } from '../modules/viewport';
10
- import { type MiniProgramUserModule } from '../modules/user';
11
- import { type MiniProgramUiModule } from '../modules/ui';
12
- import { type MiniProgramDeviceModule } from '../modules/device';
13
- import { type MiniProgramEnvironmentModule } from '../modules/environment';
14
- import { type MiniProgramNavigationModule } from '../modules/navigation';
15
- import type { MiniProgramEventHandler, MiniProgramEventName } from '../protocol/types';
16
- import type { MiniProgramSDKHandshakeState, MiniProgramSDKHandshakeStateHandler } from './handshake-state';
17
- /**
18
- * 外部小程序 SDK 实例。
19
- *
20
- * @remarks
21
- * 该实例负责组织授权、用户、分享、容器、存储与网络等开放能力,并维护
22
- * iframe 内小程序与父容器之间的 bridge 生命周期。
23
- *
24
- * 多数业务页直接使用默认单例即可;只有在测试、多实例或需要定制运行参数时,
25
- * 才建议显式创建独立实例。
26
- *
27
- * 能力调用会自动等待与父容器完成握手。
28
- */
29
- export declare class MiniProgramSDK {
30
- private readonly client;
31
- /** 授权相关开放能力。 */
32
- readonly auth: MiniProgramAuthModule;
33
- /** 用户资料相关开放能力。 */
34
- readonly user: MiniProgramUserModule;
35
- /** 分享相关开放能力。 */
36
- readonly share: MiniProgramShareModule;
37
- /** 视口相关开放能力。 */
38
- readonly viewport: MiniProgramViewportModule;
39
- /** Storage 相关开放能力。 */
40
- readonly storage: MiniProgramStorageModule;
41
- /** 网络请求相关开放能力。 */
42
- readonly network: MiniProgramNetworkModule;
43
- /** 受控文件与目录能力。 */
44
- readonly files: FilesModule;
45
- /** UI 交互相关开放能力。 */
46
- readonly ui: MiniProgramUiModule;
47
- /** 设备相关开放能力。 */
48
- readonly device: MiniProgramDeviceModule;
49
- /** 导航与容器控制相关开放能力。 */
50
- readonly navigation: MiniProgramNavigationModule;
51
- /** 云端数据相关开放能力。 */
52
- readonly cloud: MiniProgramCloudModule;
53
- /** 受管桌面程序能力。 */
54
- readonly companion: MiniProgramCompanionModule;
55
- /** 当前实例的环境信息。 */
56
- readonly environment: MiniProgramEnvironmentModule;
57
- constructor(options?: MiniProgramSDKOptions);
58
- /** 获取当前握手状态。 */
59
- getHandshakeState(): MiniProgramSDKHandshakeState;
60
- /** 订阅握手状态,并立即接收当前状态。 */
61
- onHandshakeStateChange(handler: MiniProgramSDKHandshakeStateHandler): () => void;
62
- /**
63
- * 注册小程序生命周期或业务事件。
64
- *
65
- * @param eventName - 要监听的事件名。
66
- * @param handler - 事件处理函数。
67
- * @returns 事件解绑函数。
68
- */
69
- on<T extends MiniProgramEventName>(eventName: T, handler: MiniProgramEventHandler<T>): () => void;
70
- /**
71
- * 移除小程序生命周期或业务事件。
72
- *
73
- * @param eventName - 要移除的事件名。
74
- * @param handler - 对应的事件处理函数。
75
- */
76
- off<T extends MiniProgramEventName>(eventName: T, handler: MiniProgramEventHandler<T>): void;
77
- /**
78
- * 销毁 SDK 实例。
79
- *
80
- * @remarks
81
- * 销毁后会移除 message 监听,并拒绝尚未完成的 bridge 请求。
82
- * 已销毁实例不应继续复用。
83
- */
84
- destroy(): void;
85
- }
86
- /**
87
- * 创建独立 SDK 实例。
88
- *
89
- * @param options - SDK 运行配置,例如超时时间、nonce 或测试环境注入的 window。
90
- * @returns 可独立管理生命周期的 `MiniProgramSDK` 实例。
91
- *
92
- * @remarks
93
- * 适用于测试、多实例场景,或需要自定义 `timeout`、`targetWindow` 等运行参数的场景。
94
- *
95
- * @example
96
- * ```ts
97
- * import { createMiniProgramSDK } from '@heybox/hb-sdk'
98
- *
99
- * const sdk = createMiniProgramSDK({
100
- * timeout: 15000,
101
- * })
102
- * ```
103
- */
104
- export declare function createMiniProgramSDK(options?: MiniProgramSDKOptions): MiniProgramSDK;