sandboxedjs 0.1.30 → 0.1.32
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 +85 -92
- package/bin/sandboxedjs-serve.mjs +24 -0
- package/dist/browser-host.cjs +112 -0
- package/dist/browser-host.cjs.map +1 -0
- package/dist/browser-host.d.cts +25 -0
- package/dist/browser-host.d.ts +25 -0
- package/dist/browser-host.js +109 -0
- package/dist/browser-host.js.map +1 -0
- package/dist/index.cjs +504 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -26
- package/dist/index.d.ts +26 -26
- package/dist/index.js +504 -198
- package/dist/index.js.map +1 -1
- package/dist/worker-entry.js +130 -109
- package/dist/worker-entry.js.map +1 -1
- package/package.json +9 -3
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ interface ChildHandle {
|
|
|
6
6
|
pid: number;
|
|
7
7
|
state: "starting" | "running" | "exited";
|
|
8
8
|
exitCode: number | undefined;
|
|
9
|
-
on(event: "stdout" | "stderr" | "exit", listener: (...args: any[]) => void): unknown;
|
|
9
|
+
on(event: "stdout" | "stderr" | "exit" | "rawmode", listener: (...args: any[]) => void): unknown;
|
|
10
10
|
exec(): void;
|
|
11
11
|
sendStdin(data: string): void;
|
|
12
12
|
/**
|
|
@@ -442,7 +442,10 @@ declare class Pipe implements InputStream, OutputStream {
|
|
|
442
442
|
* whole line on every keystroke — so the terminal must stop echoing, or
|
|
443
443
|
* every character appears twice.
|
|
444
444
|
*/
|
|
445
|
-
|
|
445
|
+
private raw;
|
|
446
|
+
onRawMode?: (enabled: boolean) => void;
|
|
447
|
+
get rawMode(): boolean;
|
|
448
|
+
set rawMode(enabled: boolean);
|
|
446
449
|
columns: number | undefined;
|
|
447
450
|
rows: number | undefined;
|
|
448
451
|
get closed(): boolean;
|
|
@@ -1391,6 +1394,8 @@ declare class Shell {
|
|
|
1391
1394
|
constructor(init: ShellInit);
|
|
1392
1395
|
/** Parse and run a script fragment. Returns the last exit status. */
|
|
1393
1396
|
execute(source: string, io: ShellIO): Promise<number>;
|
|
1397
|
+
/** Signal the current terminal pipeline without terminating the interactive shell. */
|
|
1398
|
+
interruptForeground(signal: string, stdin: InputStream): void;
|
|
1394
1399
|
get isExiting(): boolean;
|
|
1395
1400
|
/** True when `source` is not yet a complete command (for REPL continuation). */
|
|
1396
1401
|
static isIncomplete(source: string): boolean;
|
|
@@ -1674,12 +1679,15 @@ interface ContainerOptions {
|
|
|
1674
1679
|
/**
|
|
1675
1680
|
* Where guest programs run.
|
|
1676
1681
|
*
|
|
1677
|
-
* `"
|
|
1678
|
-
*
|
|
1679
|
-
*
|
|
1680
|
-
* `"realm"`
|
|
1682
|
+
* `"auto"` (the default) tries the worker runtime and reports any fallback.
|
|
1683
|
+
* `"worker"` requires a working guest worker and shared-memory channel: boot
|
|
1684
|
+
* rejects with the cause if either is unavailable, rather than letting
|
|
1685
|
+
* synchronous child-process calls fail later. `"realm"` opts out explicitly.
|
|
1686
|
+
* Processes requiring host-native modules can still run in the host realm.
|
|
1681
1687
|
*/
|
|
1682
|
-
isolation?: "worker" | "realm";
|
|
1688
|
+
isolation?: "auto" | "worker" | "realm";
|
|
1689
|
+
/** Receives the reason for an automatic fallback; defaults to console.warn. */
|
|
1690
|
+
onRuntimeFallback?: (error: Error) => void;
|
|
1683
1691
|
/**
|
|
1684
1692
|
* Where to load the guest worker bundle from.
|
|
1685
1693
|
*
|
|
@@ -2466,6 +2474,7 @@ declare class VirtualHttpServer extends EventEmitter {
|
|
|
2466
2474
|
readonly owner: string;
|
|
2467
2475
|
listening: boolean;
|
|
2468
2476
|
private portValue;
|
|
2477
|
+
private referenced;
|
|
2469
2478
|
constructor(router: VirtualHttpRouter, owner: string, listener?: (req: VirtualIncomingMessage, res: VirtualServerResponse) => void);
|
|
2470
2479
|
listen(...args: any[]): this;
|
|
2471
2480
|
close(callback?: (error?: Error) => void): this;
|
|
@@ -2476,17 +2485,20 @@ declare class VirtualHttpServer extends EventEmitter {
|
|
|
2476
2485
|
} | null;
|
|
2477
2486
|
ref(): this;
|
|
2478
2487
|
unref(): this;
|
|
2488
|
+
hasRef(): boolean;
|
|
2479
2489
|
setTimeout(_milliseconds: number, callback?: () => void): this;
|
|
2480
2490
|
}
|
|
2481
2491
|
declare class VirtualHttpRouter {
|
|
2482
2492
|
private readonly servers;
|
|
2483
2493
|
/** Notified when a server begins listening, for `onServerReady`. */
|
|
2484
2494
|
onListen: ((port: number) => void) | undefined;
|
|
2495
|
+
onClose: ((port: number) => void) | undefined;
|
|
2485
2496
|
register(port: number, server: VirtualHttpServer, owner: string): void;
|
|
2486
2497
|
unregister(port: number, server: VirtualHttpServer): void;
|
|
2487
2498
|
/** Whether anything in this container is listening on `port`. */
|
|
2488
2499
|
activePortsIncludes(port: number): boolean;
|
|
2489
2500
|
activePorts(owner?: string): number[];
|
|
2501
|
+
referencedPorts(owner: string): number[];
|
|
2490
2502
|
closeOwner(owner: string): void;
|
|
2491
2503
|
closeAll(): void;
|
|
2492
2504
|
request(port: number, init?: VirtualRequestInit): Promise<RuntimeHttpResponse>;
|
|
@@ -2743,6 +2755,7 @@ declare class LocalRuntimePod implements RuntimePod {
|
|
|
2743
2755
|
spawn(config: ChildSpawnConfig): ChildHandle;
|
|
2744
2756
|
};
|
|
2745
2757
|
private disposed;
|
|
2758
|
+
private readonly running;
|
|
2746
2759
|
protected readonly workdir: string;
|
|
2747
2760
|
protected readonly env: Record<string, string>;
|
|
2748
2761
|
protected readonly aliases: Record<string, string>;
|
|
@@ -2814,16 +2827,10 @@ declare class WorkerRuntimePod extends LocalRuntimePod {
|
|
|
2814
2827
|
/** Live workers, so teardown can stop them all. */
|
|
2815
2828
|
private readonly live;
|
|
2816
2829
|
protected constructor(options: WorkerRuntimeOptions);
|
|
2817
|
-
/**
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
* isolation, a bundler may have made the guest script unreachable, and a host
|
|
2822
|
-
* that supplied its own module objects has handed over things no thread
|
|
2823
|
-
* boundary can carry. In every case the caller falls back to the in-realm pod
|
|
2824
|
-
* and keeps working.
|
|
2825
|
-
*/
|
|
2826
|
-
static tryBoot(options?: WorkerRuntimeOptions): Promise<WorkerRuntimePod | null>;
|
|
2830
|
+
/** Boot without silently dropping synchronous child-process support. */
|
|
2831
|
+
static boot(options?: WorkerRuntimeOptions): Promise<WorkerRuntimePod>;
|
|
2832
|
+
/** Compatibility mode, with an observable explanation for every fallback. */
|
|
2833
|
+
static tryBoot(options?: WorkerRuntimeOptions, onFallback?: (error: Error) => void): Promise<WorkerRuntimePod | null>;
|
|
2827
2834
|
spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
|
|
2828
2835
|
private spawnInWorker;
|
|
2829
2836
|
/** Start an asynchronous child on the host's behalf and relay its events. */
|
|
@@ -2908,8 +2915,8 @@ declare function extractNpmTarball(volume: RuntimeVolume, compressed: Uint8Array
|
|
|
2908
2915
|
* own dependency cache, where no such file exists. That is the same trap
|
|
2909
2916
|
* Rolldown's WASI binding falls into, and it surfaces just as obliquely.
|
|
2910
2917
|
*
|
|
2911
|
-
* So this never assumes it worked.
|
|
2912
|
-
*
|
|
2918
|
+
* So this never assumes it worked. Strict boot surfaces the failure; automatic mode reports
|
|
2919
|
+
* the cause before choosing the in-realm pod.
|
|
2913
2920
|
*/
|
|
2914
2921
|
interface RuntimeWorker {
|
|
2915
2922
|
postMessage(message: unknown): void;
|
|
@@ -2930,13 +2937,6 @@ declare function startRuntimeWorker(options?: {
|
|
|
2930
2937
|
timeoutMs?: number;
|
|
2931
2938
|
}): Promise<RuntimeWorker>;
|
|
2932
2939
|
|
|
2933
|
-
/**
|
|
2934
|
-
* Can this environment support a blocking client at all?
|
|
2935
|
-
*
|
|
2936
|
-
* `SharedArrayBuffer` needs cross-origin isolation in a browser, and
|
|
2937
|
-
* `Atomics.wait` is forbidden on a browser's main thread — which is why the
|
|
2938
|
-
* client is always the Worker.
|
|
2939
|
-
*/
|
|
2940
2940
|
declare function syncChannelSupported(): boolean;
|
|
2941
2941
|
|
|
2942
2942
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface ChildHandle {
|
|
|
6
6
|
pid: number;
|
|
7
7
|
state: "starting" | "running" | "exited";
|
|
8
8
|
exitCode: number | undefined;
|
|
9
|
-
on(event: "stdout" | "stderr" | "exit", listener: (...args: any[]) => void): unknown;
|
|
9
|
+
on(event: "stdout" | "stderr" | "exit" | "rawmode", listener: (...args: any[]) => void): unknown;
|
|
10
10
|
exec(): void;
|
|
11
11
|
sendStdin(data: string): void;
|
|
12
12
|
/**
|
|
@@ -442,7 +442,10 @@ declare class Pipe implements InputStream, OutputStream {
|
|
|
442
442
|
* whole line on every keystroke — so the terminal must stop echoing, or
|
|
443
443
|
* every character appears twice.
|
|
444
444
|
*/
|
|
445
|
-
|
|
445
|
+
private raw;
|
|
446
|
+
onRawMode?: (enabled: boolean) => void;
|
|
447
|
+
get rawMode(): boolean;
|
|
448
|
+
set rawMode(enabled: boolean);
|
|
446
449
|
columns: number | undefined;
|
|
447
450
|
rows: number | undefined;
|
|
448
451
|
get closed(): boolean;
|
|
@@ -1391,6 +1394,8 @@ declare class Shell {
|
|
|
1391
1394
|
constructor(init: ShellInit);
|
|
1392
1395
|
/** Parse and run a script fragment. Returns the last exit status. */
|
|
1393
1396
|
execute(source: string, io: ShellIO): Promise<number>;
|
|
1397
|
+
/** Signal the current terminal pipeline without terminating the interactive shell. */
|
|
1398
|
+
interruptForeground(signal: string, stdin: InputStream): void;
|
|
1394
1399
|
get isExiting(): boolean;
|
|
1395
1400
|
/** True when `source` is not yet a complete command (for REPL continuation). */
|
|
1396
1401
|
static isIncomplete(source: string): boolean;
|
|
@@ -1674,12 +1679,15 @@ interface ContainerOptions {
|
|
|
1674
1679
|
/**
|
|
1675
1680
|
* Where guest programs run.
|
|
1676
1681
|
*
|
|
1677
|
-
* `"
|
|
1678
|
-
*
|
|
1679
|
-
*
|
|
1680
|
-
* `"realm"`
|
|
1682
|
+
* `"auto"` (the default) tries the worker runtime and reports any fallback.
|
|
1683
|
+
* `"worker"` requires a working guest worker and shared-memory channel: boot
|
|
1684
|
+
* rejects with the cause if either is unavailable, rather than letting
|
|
1685
|
+
* synchronous child-process calls fail later. `"realm"` opts out explicitly.
|
|
1686
|
+
* Processes requiring host-native modules can still run in the host realm.
|
|
1681
1687
|
*/
|
|
1682
|
-
isolation?: "worker" | "realm";
|
|
1688
|
+
isolation?: "auto" | "worker" | "realm";
|
|
1689
|
+
/** Receives the reason for an automatic fallback; defaults to console.warn. */
|
|
1690
|
+
onRuntimeFallback?: (error: Error) => void;
|
|
1683
1691
|
/**
|
|
1684
1692
|
* Where to load the guest worker bundle from.
|
|
1685
1693
|
*
|
|
@@ -2466,6 +2474,7 @@ declare class VirtualHttpServer extends EventEmitter {
|
|
|
2466
2474
|
readonly owner: string;
|
|
2467
2475
|
listening: boolean;
|
|
2468
2476
|
private portValue;
|
|
2477
|
+
private referenced;
|
|
2469
2478
|
constructor(router: VirtualHttpRouter, owner: string, listener?: (req: VirtualIncomingMessage, res: VirtualServerResponse) => void);
|
|
2470
2479
|
listen(...args: any[]): this;
|
|
2471
2480
|
close(callback?: (error?: Error) => void): this;
|
|
@@ -2476,17 +2485,20 @@ declare class VirtualHttpServer extends EventEmitter {
|
|
|
2476
2485
|
} | null;
|
|
2477
2486
|
ref(): this;
|
|
2478
2487
|
unref(): this;
|
|
2488
|
+
hasRef(): boolean;
|
|
2479
2489
|
setTimeout(_milliseconds: number, callback?: () => void): this;
|
|
2480
2490
|
}
|
|
2481
2491
|
declare class VirtualHttpRouter {
|
|
2482
2492
|
private readonly servers;
|
|
2483
2493
|
/** Notified when a server begins listening, for `onServerReady`. */
|
|
2484
2494
|
onListen: ((port: number) => void) | undefined;
|
|
2495
|
+
onClose: ((port: number) => void) | undefined;
|
|
2485
2496
|
register(port: number, server: VirtualHttpServer, owner: string): void;
|
|
2486
2497
|
unregister(port: number, server: VirtualHttpServer): void;
|
|
2487
2498
|
/** Whether anything in this container is listening on `port`. */
|
|
2488
2499
|
activePortsIncludes(port: number): boolean;
|
|
2489
2500
|
activePorts(owner?: string): number[];
|
|
2501
|
+
referencedPorts(owner: string): number[];
|
|
2490
2502
|
closeOwner(owner: string): void;
|
|
2491
2503
|
closeAll(): void;
|
|
2492
2504
|
request(port: number, init?: VirtualRequestInit): Promise<RuntimeHttpResponse>;
|
|
@@ -2743,6 +2755,7 @@ declare class LocalRuntimePod implements RuntimePod {
|
|
|
2743
2755
|
spawn(config: ChildSpawnConfig): ChildHandle;
|
|
2744
2756
|
};
|
|
2745
2757
|
private disposed;
|
|
2758
|
+
private readonly running;
|
|
2746
2759
|
protected readonly workdir: string;
|
|
2747
2760
|
protected readonly env: Record<string, string>;
|
|
2748
2761
|
protected readonly aliases: Record<string, string>;
|
|
@@ -2814,16 +2827,10 @@ declare class WorkerRuntimePod extends LocalRuntimePod {
|
|
|
2814
2827
|
/** Live workers, so teardown can stop them all. */
|
|
2815
2828
|
private readonly live;
|
|
2816
2829
|
protected constructor(options: WorkerRuntimeOptions);
|
|
2817
|
-
/**
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
* isolation, a bundler may have made the guest script unreachable, and a host
|
|
2822
|
-
* that supplied its own module objects has handed over things no thread
|
|
2823
|
-
* boundary can carry. In every case the caller falls back to the in-realm pod
|
|
2824
|
-
* and keeps working.
|
|
2825
|
-
*/
|
|
2826
|
-
static tryBoot(options?: WorkerRuntimeOptions): Promise<WorkerRuntimePod | null>;
|
|
2830
|
+
/** Boot without silently dropping synchronous child-process support. */
|
|
2831
|
+
static boot(options?: WorkerRuntimeOptions): Promise<WorkerRuntimePod>;
|
|
2832
|
+
/** Compatibility mode, with an observable explanation for every fallback. */
|
|
2833
|
+
static tryBoot(options?: WorkerRuntimeOptions, onFallback?: (error: Error) => void): Promise<WorkerRuntimePod | null>;
|
|
2827
2834
|
spawn(command: string, args?: string[], options?: Record<string, unknown>): Promise<RuntimeProcess>;
|
|
2828
2835
|
private spawnInWorker;
|
|
2829
2836
|
/** Start an asynchronous child on the host's behalf and relay its events. */
|
|
@@ -2908,8 +2915,8 @@ declare function extractNpmTarball(volume: RuntimeVolume, compressed: Uint8Array
|
|
|
2908
2915
|
* own dependency cache, where no such file exists. That is the same trap
|
|
2909
2916
|
* Rolldown's WASI binding falls into, and it surfaces just as obliquely.
|
|
2910
2917
|
*
|
|
2911
|
-
* So this never assumes it worked.
|
|
2912
|
-
*
|
|
2918
|
+
* So this never assumes it worked. Strict boot surfaces the failure; automatic mode reports
|
|
2919
|
+
* the cause before choosing the in-realm pod.
|
|
2913
2920
|
*/
|
|
2914
2921
|
interface RuntimeWorker {
|
|
2915
2922
|
postMessage(message: unknown): void;
|
|
@@ -2930,13 +2937,6 @@ declare function startRuntimeWorker(options?: {
|
|
|
2930
2937
|
timeoutMs?: number;
|
|
2931
2938
|
}): Promise<RuntimeWorker>;
|
|
2932
2939
|
|
|
2933
|
-
/**
|
|
2934
|
-
* Can this environment support a blocking client at all?
|
|
2935
|
-
*
|
|
2936
|
-
* `SharedArrayBuffer` needs cross-origin isolation in a browser, and
|
|
2937
|
-
* `Atomics.wait` is forbidden on a browser's main thread — which is why the
|
|
2938
|
-
* client is always the Worker.
|
|
2939
|
-
*/
|
|
2940
2940
|
declare function syncChannelSupported(): boolean;
|
|
2941
2941
|
|
|
2942
2942
|
/**
|