@skillbuilder/miniapp-simulator 0.0.0-beta-20261023084421 → 0.2.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.
- package/README.md +52 -2
- package/dist/sw/miniapp-simulator-service-worker.js +487 -371
- package/dist/sw/miniapp-simulator-service-worker.min.js +1 -1
- package/docs/external-cli-workbench.md +5 -7
- package/docs/npm-integration-verification.md +1 -11
- package/docs/remote-architecture.md +3 -2
- package/docs/worker-runtime.md +62 -0
- package/lib/{client-BZtD2VtP.mjs → client-CO-UjIY3.mjs} +141 -138
- package/lib/index-B5oixYXr.mjs +574 -0
- package/lib/index.js +1152 -1075
- package/lib/remote-client.js +2 -2
- package/lib/types/capabilities/constants.d.ts +1 -0
- package/lib/types/capabilities/csp-snippet.d.ts +2 -0
- package/lib/types/capabilities/security-head-snippet.d.ts +3 -2
- package/lib/types/index.d.ts +8 -1
- package/lib/types/injection/types.d.ts +2 -0
- package/lib/types/remote/protocol.d.ts +7 -2
- package/lib/types/renderer/content-host/iframe-content-host.d.ts +1 -0
- package/lib/types/sw/protocol.d.ts +3 -1
- package/lib/types/sw/served-entry.d.ts +1 -1
- package/lib/types/sw/service-worker-host.d.ts +1 -0
- package/lib/types/sw/worker/globals.d.ts +1 -0
- package/lib/types/sw/worker/mount-store.d.ts +5 -0
- package/lib/types/types/options.d.ts +8 -1
- package/lib/types/workbench/server/index.d.ts +1 -1
- package/lib/types/worker/adapters/csp-policy.d.ts +7 -0
- package/lib/types/worker/adapters/host-lifecycle.d.ts +5 -0
- package/lib/types/worker/adapters/mount-recovery.d.ts +2 -0
- package/lib/types/worker/adapters/package-policy.d.ts +12 -0
- package/lib/types/worker/adapters/page-lifecycle.d.ts +1 -0
- package/lib/types/worker/adapters/protocol.d.ts +49 -0
- package/lib/types/worker/adapters/scripts.d.ts +2 -0
- package/lib/types/worker/adapters/service-worker.d.ts +2 -0
- package/lib/workbench-server.mjs +1 -1
- package/lib/workbench.js +1 -1
- package/package.json +1 -1
- package/lib/index-BW85h7kT.mjs +0 -505
package/lib/remote-client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { R as r, a as O, c as e } from "./client-
|
|
1
|
+
import { R as r, a as O, c as e } from "./client-CO-UjIY3.mjs";
|
|
2
2
|
import { B as s, M as _ } from "./business-line-CMb3ehRn.mjs";
|
|
3
|
-
import { M } from "./index-
|
|
3
|
+
import { M } from "./index-B5oixYXr.mjs";
|
|
4
4
|
export {
|
|
5
5
|
s as BusinessLine,
|
|
6
6
|
_ as MINIAPP_SCREENSHOT_ERROR_CODE,
|
|
@@ -4,6 +4,7 @@ import type { CspDirective } from "../types";
|
|
|
4
4
|
*
|
|
5
5
|
* - 资源类(script/style/img/font/media):按资源类型配置 `'self'`、`data:`、`blob:`。
|
|
6
6
|
* - 请求类(connect-src):仅 `'self'`,消费方按需增加接口域名。
|
|
7
|
+
* - worker-src:默认关闭,Worker 开关启用时允许同源资源。
|
|
7
8
|
* - `base-uri`:仅 `'self'`(跨域远程入口的 `<base href>` 由构建时内部补入口 origin)。
|
|
8
9
|
* - `'none'` 四项:禁插件 / 禁表单外发 / 禁子 frame,锁死。
|
|
9
10
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type MiniAppCapability } from "../seal-config";
|
|
2
2
|
import type { CspDirective } from "../types";
|
|
3
|
+
import type { WorkerGuardConfig } from "../worker/adapters/protocol";
|
|
3
4
|
export interface BuildSecurityMetaSnippetOptions {
|
|
4
5
|
/** 已解析的 Permissions-Policy meta 内容串(来自 normalized security.permissionsPolicy)。 */
|
|
5
6
|
permissionsPolicy?: string;
|
|
@@ -16,5 +17,5 @@ export interface BuildSecurityMetaSnippetOptions {
|
|
|
16
17
|
}
|
|
17
18
|
/** 安全 meta:Permissions-Policy → CSP(`csp:false` 时不出,改走响应头)。 */
|
|
18
19
|
export declare function buildSecurityMetaSnippet(options?: BuildSecurityMetaSnippetOptions): string;
|
|
19
|
-
/** seal
|
|
20
|
-
export declare function buildSealScriptSource(sealAllow?: ReadonlyArray<MiniAppCapability
|
|
20
|
+
/** seal 裸源:宿主配置(早于 IIFE)+ 静态 seal 文件 + Worker 生命周期接线。 */
|
|
21
|
+
export declare function buildSealScriptSource(sealAllow?: ReadonlyArray<MiniAppCapability>, workerContext?: WorkerGuardConfig): string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,10 +2,16 @@ export { createMiniAppSimulator } from "./core/simulator";
|
|
|
2
2
|
export { BusinessLine } from "./business-line";
|
|
3
3
|
export { MiniAppSimulatorError } from "./errors";
|
|
4
4
|
export { MiniAppJsApiErrorCode } from "./types";
|
|
5
|
+
export { WORKER_CONTENT_SECURITY_POLICY } from "./worker/adapters/protocol";
|
|
6
|
+
export type { WorkerGuardConfig } from "./worker/adapters/protocol";
|
|
7
|
+
export declare const WORKER_RUNTIME_METADATA: Readonly<import("./worker/adapters/protocol").WorkerRuntimeMetadata>;
|
|
8
|
+
export { WORKER_RUNTIME_PROTOCOL_VERSION } from "./worker/adapters/protocol";
|
|
9
|
+
export type { MiniAppWorkerOptions } from "./worker/adapters/package-policy";
|
|
10
|
+
export type { WorkerCspPolicy } from "./worker/adapters/csp-policy";
|
|
5
11
|
export { detectEnvironment, getSimulatorContext, type SimulatorEnvironment, type SimulatorRuntimeContext, } from "./runtime/context";
|
|
6
12
|
/**
|
|
7
13
|
* 设备能力白名单枚举与元数据,供 `security.sealAllow` 配置 / UI 枚举渲染 / 校验。
|
|
8
|
-
*
|
|
14
|
+
* 由模拟器维护,供消费方一处引入。
|
|
9
15
|
*/
|
|
10
16
|
export { ALL_MINI_APP_CAPABILITIES, HOST_CONTROLLED_CAPABILITIES, MINI_APP_CAPABILITIES, MiniAppCapability, type MiniAppCapabilityControlledBy, type MiniAppCapabilityDescriptor, SEAL_CONTROLLED_CAPABILITIES, isMiniAppCapability, sanitizeCapabilityList, } from "./seal-config";
|
|
11
17
|
export type {
|
|
@@ -47,3 +53,4 @@ MiniAppTrackerInput, MiniAppTrackerOptions, MiniAppDefaultTrackerOptions, MiniAp
|
|
|
47
53
|
export { buildElementSelection, computeSelector } from "./inspector";
|
|
48
54
|
/** `screenShot` 失败码常量(notLoaded / renderFailed / timeout / unsupported) */
|
|
49
55
|
export { MINIAPP_SCREENSHOT_ERROR_CODE } from "./types";
|
|
56
|
+
export type { WorkerTerminateFlag, WorkerTerminateCallback, WorkerRuntimeState, } from "./worker/adapters/protocol";
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { NormalizedMiniAppSimulatorOptions } from "../types";
|
|
14
14
|
export interface InjectionContext {
|
|
15
|
+
/** 资源宿主已按当前包校验的 Worker 准入配置。 */
|
|
16
|
+
workerGuard?: import("../worker/adapters/protocol").WorkerGuardConfig;
|
|
15
17
|
/** 当前渲染介质 */
|
|
16
18
|
rendererType: "iframe" | "webview";
|
|
17
19
|
/** 归一化后的 simulator options(供模块按需读取 jsapi/security 等配置) */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BusinessLine } from "../business-line";
|
|
2
2
|
import type { ManagedRequestChunk, ManagedRequestHeaders, ManagedRequestOptions, ManagedRequestResult } from "../runtime/request/request-types";
|
|
3
|
-
import type { MiniAppContentMode, MiniAppFileMap, MiniAppHostApiRequest, MiniAppInspectorSelectionMode, MiniAppLoadFilesOptions, MiniAppLoadZipOptions, MiniAppRedirectOptions, MiniAppSimulatorOptions, MiniAppSimulatorRoute, MiniAppViewport } from "../types";
|
|
3
|
+
import type { MiniAppContentMode, MiniAppFileMap, MiniAppHostApiRequest, MiniAppInspectorSelectionMode, MiniAppLoadFilesOptions, MiniAppLoadZipOptions, MiniAppRedirectOptions, MiniAppSecurityOptions, MiniAppSimulatorOptions, MiniAppSimulatorRoute, MiniAppViewport } from "../types";
|
|
4
4
|
/**
|
|
5
5
|
* 远程模拟器通信协议版本。单一来源是同目录的 protocol-version.json,
|
|
6
6
|
* 发布脚本(scripts/publish-assets.mjs)、server dev 接口与压测脚本都从该文件读取。
|
|
@@ -12,6 +12,8 @@ export declare const REMOTE_INSPECTOR_PAUSE_RUNTIME_CAPABILITY = "inspectorPause
|
|
|
12
12
|
export declare const REMOTE_SIMULATOR_CAPABILITIES: string[];
|
|
13
13
|
export type RemoteSimulatorSerializableOptions = Omit<MiniAppSimulatorOptions, "mount" | "appId" | "renderer" | "serviceWorker" | "security" | "jsapi" | "hostApi" | "tracker" | "runtimeLimits" | "onEvent" | "onReady" | "onBeforeLoad" | "onLoad" | "onRenderDone" | "onError" | "onNavigation" | "onConsole" | "onNetwork" | "onDestroy" | "onRouterChange" | "onScreenShot"> & {
|
|
14
14
|
appUrl?: string;
|
|
15
|
+
/** 包会话 Worker 开关;Worker CSP 由 Runtime 服务配置。 */
|
|
16
|
+
security?: Pick<MiniAppSecurityOptions, "worker">;
|
|
15
17
|
};
|
|
16
18
|
export interface RemoteSimulatorGatewayOptions {
|
|
17
19
|
edith: string;
|
|
@@ -107,7 +109,10 @@ export interface RemoteHostRequestEventMessage {
|
|
|
107
109
|
event: "headers" | "chunk";
|
|
108
110
|
payload: ManagedRequestHeaders | ManagedRequestChunk;
|
|
109
111
|
}
|
|
110
|
-
export type RemoteSimulatorPortMessage =
|
|
112
|
+
export type RemoteSimulatorPortMessage = {
|
|
113
|
+
type: "worker-visibility";
|
|
114
|
+
visible: boolean;
|
|
115
|
+
} | RemoteSimulatorReadyMessage | RemoteSimulatorRequestMessage | RemoteSimulatorResponseMessage | RemoteSimulatorEventMessage | RemoteHostApiRequestMessage | RemoteHostApiResponseMessage | RemoteHostRequestMessage | RemoteHostRequestResponseMessage | RemoteHostRequestAbortMessage | RemoteHostRequestEventMessage;
|
|
111
116
|
export type RemoteSimulatorMethod = "load" | "loadZip" | "loadFiles" | "loadApp" | "unload" | "reload" | "setViewport" | "switchContentMode" | "switchPhoneFrame" | "switchDevice" | "setTouchEmulation" | "permissionSheet.show" | "permissionSheet.hide" | "notePreview.update" | "notePreview.updateUser" | "notePreview.updateAppCard" | "widgetCover.update" | "router.redirectTo" | "router.getRoute" | "inspector.enable" | "inspector.disable" | "inspector.toggle" | "inspector.clear" | "inspector.setSelectionMode" | "inspector.getSelectionMode" | "inspector.getSceneTree" | "inspector.selectByRef" | "capture" | "screenShot" | "setAutoScreenShot" | "hostApi.sync" | "hostApi.emit" | "destroy";
|
|
112
117
|
export interface RemoteLoadZipArgs {
|
|
113
118
|
buffer: ArrayBuffer;
|
|
@@ -12,6 +12,7 @@ export declare class IframeContentHost implements ContentHost {
|
|
|
12
12
|
private iframe;
|
|
13
13
|
protected readonly ctx: ContentHostContext;
|
|
14
14
|
private currentUrl;
|
|
15
|
+
private detachWorkerLifecycle?;
|
|
15
16
|
private loadStartedAt;
|
|
16
17
|
private renderDoneEmitted;
|
|
17
18
|
private gestureBus;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Runtime 与 Service Worker 随同一 release 发布,协议版本必须精确一致。 */
|
|
2
|
-
export declare const SERVICE_WORKER_PROTOCOL_VERSION =
|
|
2
|
+
export declare const SERVICE_WORKER_PROTOCOL_VERSION = 5;
|
|
3
|
+
/** 资源 SW 重启后,向持有包快照的可信宿主请求恢复 Worker 挂载。 */
|
|
4
|
+
export declare const SW_WORKER_MOUNT_RECOVERY = "miniapp:restore-worker-mount";
|
|
3
5
|
/** 当前 Service Worker 提供的文件系统操作。 */
|
|
4
6
|
export declare const SW_FS_OPS: readonly ["fsWriteTempFile", "fsSaveFile", "fsWriteFile", "fsAppendFile", "fsReadFile", "fsReadDir", "fsStatFile", "fsUnlink", "fsMkdir", "fsGetStorageInfo"];
|
|
5
7
|
export type ServiceWorkerFileSystemOperation = (typeof SW_FS_OPS)[number];
|
|
@@ -6,4 +6,4 @@ export interface SwInjectionPayload {
|
|
|
6
6
|
/** SW 响应头下发的 CSP。 */
|
|
7
7
|
csp: string;
|
|
8
8
|
}
|
|
9
|
-
export declare function buildSwInjectionPayload(options: NormalizedMiniAppSimulatorOptions, injection: InjectionRegistry, appUrl: string, rawHtml: string, extraOrigins?: string[], frameAncestors?: string[], userDataPath?: string, gateways?: Record<string, string>, businessLine?: string): Promise<SwInjectionPayload>;
|
|
9
|
+
export declare function buildSwInjectionPayload(options: NormalizedMiniAppSimulatorOptions, injection: InjectionRegistry, appUrl: string, rawHtml: string, extraOrigins?: string[], frameAncestors?: string[], userDataPath?: string, gateways?: Record<string, string>, businessLine?: string, workerGuard?: import("../worker/adapters/protocol").WorkerGuardConfig): Promise<SwInjectionPayload>;
|
|
@@ -8,6 +8,7 @@ import { type ServiceWorkerFileSystemArgs, type ServiceWorkerFileSystemOperation
|
|
|
8
8
|
/** 是否具备启用 SW 模式的运行环境(API 可用 + 安全上下文)。 */
|
|
9
9
|
export declare function isServiceWorkerHostSupported(): boolean;
|
|
10
10
|
export interface ServiceWorkerMountInput {
|
|
11
|
+
worker?: import("../worker/adapters/package-policy").WorkerMountPolicy;
|
|
11
12
|
id: string;
|
|
12
13
|
/** 入口文件包内路径(如 `index.html`),用于生成虚拟 URL。 */
|
|
13
14
|
entryPath: string;
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
* 挂载表 —— id → 已挂载小工具实例。多预览实例 / 多 iframe 共用一个 SW,按 id 前缀隔离。
|
|
3
3
|
* 负责 MOUNT/UNMOUNT 的存储,以及请求路径 → 实例的两级归属查找(`/<id>/` 标记 + clientId 反查)。
|
|
4
4
|
*/
|
|
5
|
+
import type { WorkerMountPolicy } from "../../worker/adapters/package-policy";
|
|
5
6
|
export interface MountedFile {
|
|
6
7
|
bytes: ArrayBuffer;
|
|
7
8
|
mime: string;
|
|
8
9
|
}
|
|
9
10
|
export interface MountedApp {
|
|
11
|
+
worker?: WorkerMountPolicy;
|
|
12
|
+
/** 以包内文件路径为键缓存原始字节及独立 CSP 响应。 */
|
|
13
|
+
workerResponses: Map<string, Response>;
|
|
10
14
|
files: Map<string, MountedFile>;
|
|
11
15
|
/** 注入到 HTML `<head>` 的片段(seal/jsapi/render-done 等)。 */
|
|
12
16
|
injectHead: string;
|
|
@@ -21,6 +25,7 @@ export interface MountedApp {
|
|
|
21
25
|
}
|
|
22
26
|
export declare const STORE: Map<string, MountedApp>;
|
|
23
27
|
export interface MountInput {
|
|
28
|
+
worker?: WorkerMountPolicy;
|
|
24
29
|
id: string;
|
|
25
30
|
files: Record<string, ArrayBuffer>;
|
|
26
31
|
injectHead: string;
|
|
@@ -160,6 +160,10 @@ export type CspDirective = 'default-src' | 'script-src' | 'style-src' | 'img-src
|
|
|
160
160
|
* 增一项 / 删默认项(详见各字段)。取值有效的键按各自分隔符拼接成最终串。
|
|
161
161
|
*/
|
|
162
162
|
export interface MiniAppSecurityOptions {
|
|
163
|
+
/** Worker 入口响应 CSP 覆盖,独立于页面 CSP;未配置的指令沿用内置值。 */
|
|
164
|
+
workerCsp?: import("../worker/adapters/csp-policy").WorkerCspPolicy;
|
|
165
|
+
/** 包会话 Worker 开关;网络由 Worker 脚本响应 CSP 控制。 */
|
|
166
|
+
worker?: import("../worker/adapters/package-policy").MiniAppWorkerOptions;
|
|
163
167
|
/**
|
|
164
168
|
* iframe `sandbox` 标志表(`token → boolean`)。
|
|
165
169
|
* 默认 `allow-scripts/allow-forms/allow-modals/allow-downloads/allow-same-origin`。
|
|
@@ -179,7 +183,8 @@ export interface MiniAppSecurityOptions {
|
|
|
179
183
|
permissionsPolicy?: Record<string, boolean | string | string[]>;
|
|
180
184
|
/**
|
|
181
185
|
* CSP 逐指令 token 表覆盖:`{ 'connect-src': { 'https://cdn.jsdelivr.net': true }, 'img-src': { 'data:': false } }`。
|
|
182
|
-
* `true` 加一个源/关键字,`false` 删掉某个默认 token
|
|
186
|
+
* `true` 加一个源/关键字,`false` 删掉某个默认 token。锁定指令忽略此处输入;
|
|
187
|
+
* worker-src 由 security.worker 开关控制,开放时允许同源资源。
|
|
183
188
|
*/
|
|
184
189
|
cspDirectives?: Partial<Record<CspDirective, Record<string, boolean>>>;
|
|
185
190
|
/**
|
|
@@ -193,6 +198,8 @@ export interface MiniAppSecurityOptions {
|
|
|
193
198
|
* 最终串(sandbox 属性 / iframe allow / permissions-policy / CSP)在消费处按需序列化。
|
|
194
199
|
*/
|
|
195
200
|
export interface NormalizedMiniAppSecurityOptions {
|
|
201
|
+
workerCsp?: import("../worker/adapters/csp-policy").WorkerCspPolicy;
|
|
202
|
+
worker?: import("../worker/adapters/package-policy").MiniAppWorkerOptions;
|
|
196
203
|
/** 合并后的 iframe `sandbox` 标志表(取值 `true` 的 flag 序列化为 sandbox 属性) */
|
|
197
204
|
sandbox: Record<string, boolean>;
|
|
198
205
|
/** 合并后的 iframe `allow` 表(feature → allowlist) */
|
|
@@ -3,7 +3,7 @@ export { BusinessLine } from "../../business-line";
|
|
|
3
3
|
export interface StartWorkbenchServerOptions {
|
|
4
4
|
/** 包含可运行 HTML 及静态资源的调试根目录。 */
|
|
5
5
|
rootDir: string;
|
|
6
|
-
/**
|
|
6
|
+
/** 接入方可提供真实运行上下文;省略时连接正式 Simulator 服务。 */
|
|
7
7
|
remote?: {
|
|
8
8
|
serviceUrl?: string;
|
|
9
9
|
appId?: string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const DIRECTIVES: readonly ["default-src", "script-src", "connect-src", "worker-src", "child-src"];
|
|
2
|
+
export type WorkerCspPolicy = Partial<Record<(typeof DIRECTIVES)[number], string>>;
|
|
3
|
+
/** Apollo 与本地配置共用;非法配置整体回退,不产生部分放开的策略。 */
|
|
4
|
+
export declare function parseWorkerCspPolicy(input: unknown): WorkerCspPolicy | undefined;
|
|
5
|
+
/** 缺失字段沿用内置值;每个 directive 的配置值完整替换该项。 */
|
|
6
|
+
export declare function resolveWorkerContentSecurityPolicy(input: unknown): string;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** 仅由 Runtime 已建立的私有 MessagePort 更新外层宿主可见性。 */
|
|
2
|
+
export declare function updateWorkerHostVisibility(visible: boolean): void;
|
|
3
|
+
export declare function observeWorkerHostVisibility(element: HTMLElement, notify: (visible: boolean) => void): () => void;
|
|
4
|
+
/** 宿主文档与容器 CSS 可见性接线;会话握手避免消息早于页面封印安装而丢失。 */
|
|
5
|
+
export declare function attachWorkerHostLifecycle(iframe: HTMLIFrameElement, getUrl: () => string): () => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WorkerCspPolicy } from "./csp-policy";
|
|
2
|
+
import type { WorkerGuardConfig } from "./protocol";
|
|
3
|
+
export interface MiniAppWorkerOptions {
|
|
4
|
+
/** 仅 loadZip/loadFiles 的包内 classic Worker 可启用,默认 false。 */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** 随 MOUNT 发送给资源 Service Worker 的会话策略。 */
|
|
8
|
+
export interface WorkerMountPolicy {
|
|
9
|
+
sessionId: string;
|
|
10
|
+
csp?: WorkerCspPolicy;
|
|
11
|
+
}
|
|
12
|
+
export declare function createPackageWorkerConfig(options: MiniAppWorkerOptions | undefined, sessionId: string): WorkerGuardConfig | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** 宿主在业务代码前提供本次页面会话的 Worker 配置。 */
|
|
2
|
+
export interface WorkerGuardConfig {
|
|
3
|
+
protocolVersion: number;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
/** 宿主初始可见性;默认 visible,与 document.hidden 共同判断。 */
|
|
7
|
+
initialState?: "visible" | "hidden";
|
|
8
|
+
}
|
|
9
|
+
export interface WorkerRuntimeMetadata {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly version: string;
|
|
12
|
+
readonly protocolVersion: number;
|
|
13
|
+
readonly workerCsp: string;
|
|
14
|
+
}
|
|
15
|
+
/** 模拟器维护的安全脚本接入协议;与资源 Service Worker 协议独立。 */
|
|
16
|
+
export declare const WORKER_RUNTIME_METADATA: WorkerRuntimeMetadata;
|
|
17
|
+
export declare const WORKER_RUNTIME_PROTOCOL_VERSION: number;
|
|
18
|
+
export declare const WORKER_CONTENT_SECURITY_POLICY: string;
|
|
19
|
+
export declare const WORKER_BACKGROUND_TIMEOUT_MS = 30000;
|
|
20
|
+
export type WorkerTerminateFlag = "主动" | "system";
|
|
21
|
+
export type WorkerTerminateCallback = (flag: WorkerTerminateFlag) => void;
|
|
22
|
+
export interface WorkerRuntimeState {
|
|
23
|
+
readonly protocolVersion: number;
|
|
24
|
+
readonly sessionId: string;
|
|
25
|
+
readonly enabled: boolean;
|
|
26
|
+
readonly maxWorkers: number;
|
|
27
|
+
readonly state: "visible" | "hidden" | "destroyed";
|
|
28
|
+
readonly recycled: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface WorkerGuardController {
|
|
31
|
+
readonly supported: boolean;
|
|
32
|
+
readonly context: WorkerRuntimeState;
|
|
33
|
+
updateVisibility(visible: boolean): void;
|
|
34
|
+
reclaim(): void;
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
37
|
+
declare global {
|
|
38
|
+
interface Worker {
|
|
39
|
+
/** 平台终止通知;浏览器/系统直接结束进程及 self.close 不保证可观测。 */
|
|
40
|
+
onTerminate(callback: WorkerTerminateCallback): void;
|
|
41
|
+
offTerminate(callback?: WorkerTerminateCallback): void;
|
|
42
|
+
}
|
|
43
|
+
interface Window {
|
|
44
|
+
/** 宿主在安全脚本前注入的 Worker 配置,只读、同一页面会话固定。 */
|
|
45
|
+
readonly __MINITOOL_WORKER_CONTEXT__?: Readonly<WorkerGuardConfig>;
|
|
46
|
+
/** 运行时输出;业务只读,不能作为控制入口。 */
|
|
47
|
+
readonly __MINITOOL_WORKER_STATE__: WorkerRuntimeState;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/lib/workbench-server.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { send as S } from "@koa/send";
|
|
|
8
8
|
import F from "koa";
|
|
9
9
|
import { PassThrough as _ } from "node:stream";
|
|
10
10
|
import { watch as L } from "chokidar";
|
|
11
|
-
const O = "https://miniapp-sandbox.
|
|
11
|
+
const O = "https://miniapp-sandbox.xiaohongshu.com/simulator/";
|
|
12
12
|
var b = /* @__PURE__ */ ((e) => (e.skillDesignable = "skill-designable", e.creator = "creator", e.mars = "mars", e.dev = "dev", e))(b || {});
|
|
13
13
|
function C(e, t) {
|
|
14
14
|
const s = e.filter(
|
package/lib/workbench.js
CHANGED
package/package.json
CHANGED