@sandbox-engine/sdk 0.2.0 → 0.2.1
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/dist/index.d.mts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +26 -3
- package/dist/index.mjs +26 -3
- package/package.json +8 -2
package/dist/index.d.mts
CHANGED
|
@@ -129,10 +129,21 @@ interface FileWatchOptions {
|
|
|
129
129
|
recursive?: boolean;
|
|
130
130
|
onEvent: (event: FileWatchEvent) => void;
|
|
131
131
|
}
|
|
132
|
+
interface ExposePortOptions {
|
|
133
|
+
/** Human-readable label for this port (e.g. 'api', 'frontend'). */
|
|
134
|
+
name?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Access token embedded in the preview URL.
|
|
137
|
+
* Use a stable value to get a consistent URL across sandbox restarts.
|
|
138
|
+
* When set, the URL becomes: https://{port}-{id}-{token}.{domain}
|
|
139
|
+
*/
|
|
140
|
+
token?: string;
|
|
141
|
+
}
|
|
132
142
|
interface PortMapping {
|
|
133
143
|
containerPort: number;
|
|
134
|
-
hostPort: number;
|
|
135
144
|
url: string;
|
|
145
|
+
name?: string;
|
|
146
|
+
token?: string;
|
|
136
147
|
}
|
|
137
148
|
type WsMessageType = 'stdout' | 'stderr' | 'exit' | 'error' | 'input' | 'resize';
|
|
138
149
|
interface WsMessage {
|
|
@@ -243,9 +254,27 @@ declare class Sandbox {
|
|
|
243
254
|
getProxyEnv: (secretNames: string[]) => Promise<ProxyEnvResult>;
|
|
244
255
|
};
|
|
245
256
|
readonly ports: {
|
|
257
|
+
/**
|
|
258
|
+
* List all currently exposed ports for this sandbox.
|
|
259
|
+
*/
|
|
246
260
|
list: () => Promise<PortMapping[]>;
|
|
247
|
-
|
|
261
|
+
/**
|
|
262
|
+
* Expose any port (1024–65535) and get a public HTTPS URL.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* const { url } = await sandbox.ports.expose(5173, { name: 'vite', token: 'my-token' })
|
|
266
|
+
* // https://5173-{sandboxId}-my-token.preview.yourdomain.com
|
|
267
|
+
*/
|
|
268
|
+
expose: (containerPort: number, opts?: ExposePortOptions) => Promise<PortMapping>;
|
|
269
|
+
/**
|
|
270
|
+
* Remove a port from public access.
|
|
271
|
+
*/
|
|
248
272
|
unexpose: (containerPort: number) => Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* Check whether a token grants access to an exposed port.
|
|
275
|
+
* Returns true if the port has no token requirement or if the token matches.
|
|
276
|
+
*/
|
|
277
|
+
validateToken: (containerPort: number, token: string) => Promise<boolean>;
|
|
249
278
|
};
|
|
250
279
|
info(): Promise<SandboxApiResponse>;
|
|
251
280
|
keepalive(timeout?: number): Promise<SandboxApiResponse>;
|
package/dist/index.d.ts
CHANGED
|
@@ -129,10 +129,21 @@ interface FileWatchOptions {
|
|
|
129
129
|
recursive?: boolean;
|
|
130
130
|
onEvent: (event: FileWatchEvent) => void;
|
|
131
131
|
}
|
|
132
|
+
interface ExposePortOptions {
|
|
133
|
+
/** Human-readable label for this port (e.g. 'api', 'frontend'). */
|
|
134
|
+
name?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Access token embedded in the preview URL.
|
|
137
|
+
* Use a stable value to get a consistent URL across sandbox restarts.
|
|
138
|
+
* When set, the URL becomes: https://{port}-{id}-{token}.{domain}
|
|
139
|
+
*/
|
|
140
|
+
token?: string;
|
|
141
|
+
}
|
|
132
142
|
interface PortMapping {
|
|
133
143
|
containerPort: number;
|
|
134
|
-
hostPort: number;
|
|
135
144
|
url: string;
|
|
145
|
+
name?: string;
|
|
146
|
+
token?: string;
|
|
136
147
|
}
|
|
137
148
|
type WsMessageType = 'stdout' | 'stderr' | 'exit' | 'error' | 'input' | 'resize';
|
|
138
149
|
interface WsMessage {
|
|
@@ -243,9 +254,27 @@ declare class Sandbox {
|
|
|
243
254
|
getProxyEnv: (secretNames: string[]) => Promise<ProxyEnvResult>;
|
|
244
255
|
};
|
|
245
256
|
readonly ports: {
|
|
257
|
+
/**
|
|
258
|
+
* List all currently exposed ports for this sandbox.
|
|
259
|
+
*/
|
|
246
260
|
list: () => Promise<PortMapping[]>;
|
|
247
|
-
|
|
261
|
+
/**
|
|
262
|
+
* Expose any port (1024–65535) and get a public HTTPS URL.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* const { url } = await sandbox.ports.expose(5173, { name: 'vite', token: 'my-token' })
|
|
266
|
+
* // https://5173-{sandboxId}-my-token.preview.yourdomain.com
|
|
267
|
+
*/
|
|
268
|
+
expose: (containerPort: number, opts?: ExposePortOptions) => Promise<PortMapping>;
|
|
269
|
+
/**
|
|
270
|
+
* Remove a port from public access.
|
|
271
|
+
*/
|
|
248
272
|
unexpose: (containerPort: number) => Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* Check whether a token grants access to an exposed port.
|
|
275
|
+
* Returns true if the port has no token requirement or if the token matches.
|
|
276
|
+
*/
|
|
277
|
+
validateToken: (containerPort: number, token: string) => Promise<boolean>;
|
|
249
278
|
};
|
|
250
279
|
info(): Promise<SandboxApiResponse>;
|
|
251
280
|
keepalive(timeout?: number): Promise<SandboxApiResponse>;
|
package/dist/index.js
CHANGED
|
@@ -469,22 +469,45 @@ var Sandbox = class _Sandbox {
|
|
|
469
469
|
}
|
|
470
470
|
};
|
|
471
471
|
ports = {
|
|
472
|
+
/**
|
|
473
|
+
* List all currently exposed ports for this sandbox.
|
|
474
|
+
*/
|
|
472
475
|
list: async () => {
|
|
473
476
|
const res = await this.client.get(
|
|
474
477
|
`/api/sandboxes/${this.id}/ports`
|
|
475
478
|
);
|
|
476
479
|
return res.ports;
|
|
477
480
|
},
|
|
478
|
-
|
|
479
|
-
|
|
481
|
+
/**
|
|
482
|
+
* Expose any port (1024–65535) and get a public HTTPS URL.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* const { url } = await sandbox.ports.expose(5173, { name: 'vite', token: 'my-token' })
|
|
486
|
+
* // https://5173-{sandboxId}-my-token.preview.yourdomain.com
|
|
487
|
+
*/
|
|
488
|
+
expose: async (containerPort, opts = {}) => {
|
|
489
|
+
return this.client.post(
|
|
480
490
|
`/api/sandboxes/${this.id}/ports/${containerPort}/expose`,
|
|
481
|
-
|
|
491
|
+
opts
|
|
482
492
|
);
|
|
483
493
|
},
|
|
494
|
+
/**
|
|
495
|
+
* Remove a port from public access.
|
|
496
|
+
*/
|
|
484
497
|
unexpose: async (containerPort) => {
|
|
485
498
|
await this.client.delete(
|
|
486
499
|
`/api/sandboxes/${this.id}/ports/${containerPort}/expose`
|
|
487
500
|
);
|
|
501
|
+
},
|
|
502
|
+
/**
|
|
503
|
+
* Check whether a token grants access to an exposed port.
|
|
504
|
+
* Returns true if the port has no token requirement or if the token matches.
|
|
505
|
+
*/
|
|
506
|
+
validateToken: async (containerPort, token) => {
|
|
507
|
+
const res = await this.client.get(
|
|
508
|
+
`/api/sandboxes/${this.id}/ports/${containerPort}/validate?token=${encodeURIComponent(token)}`
|
|
509
|
+
);
|
|
510
|
+
return res.valid;
|
|
488
511
|
}
|
|
489
512
|
};
|
|
490
513
|
async info() {
|
package/dist/index.mjs
CHANGED
|
@@ -428,22 +428,45 @@ var Sandbox = class _Sandbox {
|
|
|
428
428
|
}
|
|
429
429
|
};
|
|
430
430
|
ports = {
|
|
431
|
+
/**
|
|
432
|
+
* List all currently exposed ports for this sandbox.
|
|
433
|
+
*/
|
|
431
434
|
list: async () => {
|
|
432
435
|
const res = await this.client.get(
|
|
433
436
|
`/api/sandboxes/${this.id}/ports`
|
|
434
437
|
);
|
|
435
438
|
return res.ports;
|
|
436
439
|
},
|
|
437
|
-
|
|
438
|
-
|
|
440
|
+
/**
|
|
441
|
+
* Expose any port (1024–65535) and get a public HTTPS URL.
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* const { url } = await sandbox.ports.expose(5173, { name: 'vite', token: 'my-token' })
|
|
445
|
+
* // https://5173-{sandboxId}-my-token.preview.yourdomain.com
|
|
446
|
+
*/
|
|
447
|
+
expose: async (containerPort, opts = {}) => {
|
|
448
|
+
return this.client.post(
|
|
439
449
|
`/api/sandboxes/${this.id}/ports/${containerPort}/expose`,
|
|
440
|
-
|
|
450
|
+
opts
|
|
441
451
|
);
|
|
442
452
|
},
|
|
453
|
+
/**
|
|
454
|
+
* Remove a port from public access.
|
|
455
|
+
*/
|
|
443
456
|
unexpose: async (containerPort) => {
|
|
444
457
|
await this.client.delete(
|
|
445
458
|
`/api/sandboxes/${this.id}/ports/${containerPort}/expose`
|
|
446
459
|
);
|
|
460
|
+
},
|
|
461
|
+
/**
|
|
462
|
+
* Check whether a token grants access to an exposed port.
|
|
463
|
+
* Returns true if the port has no token requirement or if the token matches.
|
|
464
|
+
*/
|
|
465
|
+
validateToken: async (containerPort, token) => {
|
|
466
|
+
const res = await this.client.get(
|
|
467
|
+
`/api/sandboxes/${this.id}/ports/${containerPort}/validate?token=${encodeURIComponent(token)}`
|
|
468
|
+
);
|
|
469
|
+
return res.valid;
|
|
447
470
|
}
|
|
448
471
|
};
|
|
449
472
|
async info() {
|
package/package.json
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandbox-engine/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "SDK for creating and managing isolated sandbox environments",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sandbox",
|
|
7
|
+
"docker",
|
|
8
|
+
"code-execution",
|
|
9
|
+
"isolated",
|
|
10
|
+
"e2b"
|
|
11
|
+
],
|
|
6
12
|
"license": "MIT",
|
|
7
13
|
"main": "dist/index.js",
|
|
8
14
|
"module": "dist/index.mjs",
|