@vercel/sandbox 1.0.4 → 1.1.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +5 -5
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +16 -0
- package/README.md +4 -4
- package/dist/api-client/api-client.d.ts +25 -5
- package/dist/api-client/api-client.js +13 -0
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/base-client.d.ts +1 -0
- package/dist/api-client/base-client.js +1 -1
- package/dist/api-client/base-client.js.map +1 -1
- package/dist/api-client/validators.d.ts +244 -23
- package/dist/api-client/validators.js +26 -2
- package/dist/api-client/validators.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +3 -0
- package/dist/constants.js.map +1 -0
- package/dist/sandbox.d.ts +29 -7
- package/dist/sandbox.js +26 -1
- package/dist/sandbox.js.map +1 -1
- package/dist/snapshot.d.ts +67 -0
- package/dist/snapshot.js +78 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/api-client/api-client.ts +50 -3
- package/src/api-client/base-client.ts +7 -2
- package/src/api-client/validators.ts +30 -1
- package/src/constants.ts +1 -0
- package/src/sandbox.ts +47 -7
- package/src/snapshot.ts +110 -0
- package/src/version.ts +1 -1
package/dist/sandbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":";;;AAEA,6CAAyC;AACzC,uCAA0D;AAC1D,6DAA2E;AAC3E,yCAA8D;
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":";;;AAEA,6CAAyC;AACzC,uCAA0D;AAC1D,6DAA2E;AAC3E,yCAA8D;AAG9D,yCAAsC;AAoHtC;;;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CAAC;QAC5C,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CAAC,IAA+B;QACxC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC5B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YAC1B,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,aAAa,CACjB,QAAgB,EAChB,IAA+B;QAE/B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;YAC/C,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YAC1B,QAAQ;YACR,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC;QAEH,kEAAkE;QAClE,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;IACvC,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,QAAQ,CAAC,IAA+B;QAC5C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;YAChD,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YAC1B,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;QAErC,OAAO,IAAI,mBAAQ,CAAC;YAClB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ;SACjC,CAAC,CAAC;IACL,CAAC;CACF;AAtZD,0BAsZC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { SnapshotMetadata } from "./api-client";
|
|
2
|
+
import { APIClient } from "./api-client";
|
|
3
|
+
import { Credentials } from "./utils/get-credentials";
|
|
4
|
+
/** @inline */
|
|
5
|
+
interface GetSnapshotParams {
|
|
6
|
+
/**
|
|
7
|
+
* Unique identifier of the snapshot.
|
|
8
|
+
*/
|
|
9
|
+
snapshotId: string;
|
|
10
|
+
/**
|
|
11
|
+
* An AbortSignal to cancel the operation.
|
|
12
|
+
*/
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
|
|
17
|
+
*
|
|
18
|
+
* Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
|
|
19
|
+
* @hideconstructor
|
|
20
|
+
*/
|
|
21
|
+
export declare class Snapshot {
|
|
22
|
+
private readonly client;
|
|
23
|
+
/**
|
|
24
|
+
* Unique ID of this snapshot.
|
|
25
|
+
*/
|
|
26
|
+
get snapshotId(): string;
|
|
27
|
+
/**
|
|
28
|
+
* The ID the sandbox from which this snapshot was created.
|
|
29
|
+
*/
|
|
30
|
+
get sourceSandboxId(): string;
|
|
31
|
+
/**
|
|
32
|
+
* The status of the snapshot.
|
|
33
|
+
*/
|
|
34
|
+
get status(): SnapshotMetadata["status"];
|
|
35
|
+
/**
|
|
36
|
+
* Internal metadata about this snapshot.
|
|
37
|
+
*/
|
|
38
|
+
private snapshot;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new Snapshot instance.
|
|
41
|
+
*
|
|
42
|
+
* @param client - API client used to communicate with the backend
|
|
43
|
+
* @param snapshot - Snapshot metadata
|
|
44
|
+
*/
|
|
45
|
+
constructor({ client, snapshot, }: {
|
|
46
|
+
client: APIClient;
|
|
47
|
+
snapshot: SnapshotMetadata;
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Retrieve an existing snapshot.
|
|
51
|
+
*
|
|
52
|
+
* @param params - Get parameters and optional credentials.
|
|
53
|
+
* @returns A promise resolving to the {@link Sandbox}.
|
|
54
|
+
*/
|
|
55
|
+
static get(params: GetSnapshotParams | (GetSnapshotParams & Credentials)): Promise<Snapshot>;
|
|
56
|
+
/**
|
|
57
|
+
* Delete this snapshot.
|
|
58
|
+
*
|
|
59
|
+
* @param opts - Optional parameters.
|
|
60
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
61
|
+
* @returns A promise that resolves once the snapshot has been deleted.
|
|
62
|
+
*/
|
|
63
|
+
delete(opts?: {
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
export {};
|
package/dist/snapshot.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Snapshot = void 0;
|
|
4
|
+
const api_client_1 = require("./api-client");
|
|
5
|
+
const get_credentials_1 = require("./utils/get-credentials");
|
|
6
|
+
/**
|
|
7
|
+
* A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
|
|
8
|
+
*
|
|
9
|
+
* Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
|
|
10
|
+
* @hideconstructor
|
|
11
|
+
*/
|
|
12
|
+
class Snapshot {
|
|
13
|
+
/**
|
|
14
|
+
* Unique ID of this snapshot.
|
|
15
|
+
*/
|
|
16
|
+
get snapshotId() {
|
|
17
|
+
return this.snapshot.id;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The ID the sandbox from which this snapshot was created.
|
|
21
|
+
*/
|
|
22
|
+
get sourceSandboxId() {
|
|
23
|
+
return this.snapshot.sourceSandboxId;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The status of the snapshot.
|
|
27
|
+
*/
|
|
28
|
+
get status() {
|
|
29
|
+
return this.snapshot.status;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a new Snapshot instance.
|
|
33
|
+
*
|
|
34
|
+
* @param client - API client used to communicate with the backend
|
|
35
|
+
* @param snapshot - Snapshot metadata
|
|
36
|
+
*/
|
|
37
|
+
constructor({ client, snapshot, }) {
|
|
38
|
+
this.client = client;
|
|
39
|
+
this.snapshot = snapshot;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Retrieve an existing snapshot.
|
|
43
|
+
*
|
|
44
|
+
* @param params - Get parameters and optional credentials.
|
|
45
|
+
* @returns A promise resolving to the {@link Sandbox}.
|
|
46
|
+
*/
|
|
47
|
+
static async get(params) {
|
|
48
|
+
const credentials = await (0, get_credentials_1.getCredentials)(params);
|
|
49
|
+
const client = new api_client_1.APIClient({
|
|
50
|
+
teamId: credentials.teamId,
|
|
51
|
+
token: credentials.token,
|
|
52
|
+
});
|
|
53
|
+
const sandbox = await client.getSnapshot({
|
|
54
|
+
snapshotId: params.snapshotId,
|
|
55
|
+
signal: params.signal,
|
|
56
|
+
});
|
|
57
|
+
return new Snapshot({
|
|
58
|
+
client,
|
|
59
|
+
snapshot: sandbox.json.snapshot,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Delete this snapshot.
|
|
64
|
+
*
|
|
65
|
+
* @param opts - Optional parameters.
|
|
66
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
67
|
+
* @returns A promise that resolves once the snapshot has been deleted.
|
|
68
|
+
*/
|
|
69
|
+
async delete(opts) {
|
|
70
|
+
const response = await this.client.deleteSnapshot({
|
|
71
|
+
snapshotId: this.snapshot.id,
|
|
72
|
+
signal: opts?.signal,
|
|
73
|
+
});
|
|
74
|
+
this.snapshot = response.json.snapshot;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Snapshot = Snapshot;
|
|
78
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AACzC,6DAAsE;AActE;;;;;GAKG;AACH,MAAa,QAAQ;IAGnB;;OAEG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI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FD,4BAuFC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.1.1";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
LogLine,
|
|
14
14
|
SandboxesResponse,
|
|
15
15
|
ExtendTimeoutResponse,
|
|
16
|
+
SnapshotResponse,
|
|
17
|
+
CreateSnapshotResponse,
|
|
16
18
|
} from "./validators";
|
|
17
19
|
import { APIError } from "./api-error";
|
|
18
20
|
import { FileWriter } from "./file-writer";
|
|
@@ -25,16 +27,27 @@ import { Readable } from "stream";
|
|
|
25
27
|
import { normalizePath } from "../utils/normalizePath";
|
|
26
28
|
import { JwtExpiry } from "../utils/jwt-expiry";
|
|
27
29
|
import { getPrivateParams, WithPrivate } from "../utils/types";
|
|
30
|
+
import { RUNTIMES } from "../constants";
|
|
31
|
+
|
|
32
|
+
export interface WithFetchOptions {
|
|
33
|
+
fetch?: typeof globalThis.fetch;
|
|
34
|
+
}
|
|
28
35
|
|
|
29
36
|
export class APIClient extends BaseClient {
|
|
30
37
|
private teamId: string;
|
|
31
38
|
private tokenExpiry: JwtExpiry | null;
|
|
32
39
|
|
|
33
|
-
constructor(params: {
|
|
40
|
+
constructor(params: {
|
|
41
|
+
baseUrl?: string;
|
|
42
|
+
teamId: string;
|
|
43
|
+
token: string;
|
|
44
|
+
fetch?: typeof globalThis.fetch;
|
|
45
|
+
}) {
|
|
34
46
|
super({
|
|
35
47
|
baseUrl: params.baseUrl ?? "https://vercel.com/api",
|
|
36
48
|
token: params.token,
|
|
37
49
|
debug: false,
|
|
50
|
+
fetch: params.fetch,
|
|
38
51
|
});
|
|
39
52
|
|
|
40
53
|
this.teamId = params.teamId;
|
|
@@ -99,10 +112,11 @@ export class APIClient extends BaseClient {
|
|
|
99
112
|
username?: string;
|
|
100
113
|
password?: string;
|
|
101
114
|
}
|
|
102
|
-
| { type: "tarball"; url: string }
|
|
115
|
+
| { type: "tarball"; url: string }
|
|
116
|
+
| { type: "snapshot"; snapshotId: string };
|
|
103
117
|
timeout?: number;
|
|
104
118
|
resources?: { vcpus: number };
|
|
105
|
-
runtime?:
|
|
119
|
+
runtime?: RUNTIMES | (string & {});
|
|
106
120
|
signal?: AbortSignal;
|
|
107
121
|
}>,
|
|
108
122
|
) {
|
|
@@ -415,6 +429,39 @@ export class APIClient extends BaseClient {
|
|
|
415
429
|
}),
|
|
416
430
|
);
|
|
417
431
|
}
|
|
432
|
+
|
|
433
|
+
async createSnapshot(params: {
|
|
434
|
+
sandboxId: string;
|
|
435
|
+
signal?: AbortSignal;
|
|
436
|
+
}): Promise<Parsed<z.infer<typeof CreateSnapshotResponse>>> {
|
|
437
|
+
const url = `/v1/sandboxes/${params.sandboxId}/snapshot`;
|
|
438
|
+
return parseOrThrow(
|
|
439
|
+
CreateSnapshotResponse,
|
|
440
|
+
await this.request(url, { method: "POST", signal: params.signal }),
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async deleteSnapshot(params: {
|
|
445
|
+
snapshotId: string;
|
|
446
|
+
signal?: AbortSignal;
|
|
447
|
+
}): Promise<Parsed<z.infer<typeof SnapshotResponse>>> {
|
|
448
|
+
const url = `/v1/sandboxes/snapshots/${params.snapshotId}`;
|
|
449
|
+
return parseOrThrow(
|
|
450
|
+
SnapshotResponse,
|
|
451
|
+
await this.request(url, { method: "DELETE", signal: params.signal }),
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
async getSnapshot(params: {
|
|
456
|
+
snapshotId: string;
|
|
457
|
+
signal?: AbortSignal;
|
|
458
|
+
}): Promise<Parsed<z.infer<typeof SnapshotResponse>>> {
|
|
459
|
+
const url = `/v1/sandboxes/snapshots/${params.snapshotId}`;
|
|
460
|
+
return parseOrThrow(
|
|
461
|
+
SnapshotResponse,
|
|
462
|
+
await this.request(url, { signal: params.signal }),
|
|
463
|
+
);
|
|
464
|
+
}
|
|
418
465
|
}
|
|
419
466
|
|
|
420
467
|
async function pipe(
|
|
@@ -25,8 +25,13 @@ export class BaseClient {
|
|
|
25
25
|
private baseUrl: string;
|
|
26
26
|
private agent: Agent;
|
|
27
27
|
|
|
28
|
-
constructor(params: {
|
|
29
|
-
|
|
28
|
+
constructor(params: {
|
|
29
|
+
debug?: boolean;
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
token?: string;
|
|
32
|
+
fetch?: typeof globalThis.fetch;
|
|
33
|
+
}) {
|
|
34
|
+
this.fetch = withRetry(params.fetch ?? globalThis.fetch);
|
|
30
35
|
this.baseUrl = params.baseUrl;
|
|
31
36
|
this.debug = params.debug ?? process.env.DEBUG_FETCH === "true";
|
|
32
37
|
this.token = params.token;
|
|
@@ -9,7 +9,14 @@ export const Sandbox = z.object({
|
|
|
9
9
|
region: z.string(),
|
|
10
10
|
runtime: z.string(),
|
|
11
11
|
timeout: z.number(),
|
|
12
|
-
status: z.enum([
|
|
12
|
+
status: z.enum([
|
|
13
|
+
"pending",
|
|
14
|
+
"running",
|
|
15
|
+
"stopping",
|
|
16
|
+
"stopped",
|
|
17
|
+
"failed",
|
|
18
|
+
"snapshotting",
|
|
19
|
+
]),
|
|
13
20
|
requestedAt: z.number(),
|
|
14
21
|
startedAt: z.number().optional(),
|
|
15
22
|
requestedStopAt: z.number().optional(),
|
|
@@ -29,6 +36,19 @@ export const SandboxRoute = z.object({
|
|
|
29
36
|
port: z.number(),
|
|
30
37
|
});
|
|
31
38
|
|
|
39
|
+
export type SnapshotMetadata = z.infer<typeof Snapshot>;
|
|
40
|
+
|
|
41
|
+
export const Snapshot = z.object({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
sourceSandboxId: z.string(),
|
|
44
|
+
region: z.string(),
|
|
45
|
+
status: z.enum(["created", "deleted", "failed"]),
|
|
46
|
+
sizeBytes: z.number(),
|
|
47
|
+
expiresAt: z.number(),
|
|
48
|
+
createdAt: z.number(),
|
|
49
|
+
updatedAt: z.number(),
|
|
50
|
+
});
|
|
51
|
+
|
|
32
52
|
export const Pagination = z.object({
|
|
33
53
|
/**
|
|
34
54
|
* Amount of items in the current page.
|
|
@@ -94,3 +114,12 @@ export const SandboxesResponse = z.object({
|
|
|
94
114
|
export const ExtendTimeoutResponse = z.object({
|
|
95
115
|
sandbox: Sandbox,
|
|
96
116
|
});
|
|
117
|
+
|
|
118
|
+
export const CreateSnapshotResponse = z.object({
|
|
119
|
+
snapshot: Snapshot,
|
|
120
|
+
sandbox: Sandbox,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export const SnapshotResponse = z.object({
|
|
124
|
+
snapshot: Snapshot,
|
|
125
|
+
});
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type RUNTIMES = "node24" | "node22" | "python3.13";
|
package/src/sandbox.ts
CHANGED
|
@@ -4,9 +4,12 @@ import { APIClient } from "./api-client";
|
|
|
4
4
|
import { Command, type CommandFinished } from "./command";
|
|
5
5
|
import { type Credentials, getCredentials } from "./utils/get-credentials";
|
|
6
6
|
import { getPrivateParams, WithPrivate } from "./utils/types";
|
|
7
|
+
import { WithFetchOptions } from "./api-client/api-client";
|
|
8
|
+
import { RUNTIMES } from "./constants";
|
|
9
|
+
import { Snapshot } from "./snapshot";
|
|
7
10
|
|
|
8
11
|
/** @inline */
|
|
9
|
-
export interface
|
|
12
|
+
export interface BaseCreateSandboxParams {
|
|
10
13
|
/**
|
|
11
14
|
* The source of the sandbox.
|
|
12
15
|
*
|
|
@@ -50,10 +53,10 @@ export interface CreateSandboxParams {
|
|
|
50
53
|
resources?: { vcpus: number };
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
|
-
* The runtime of the sandbox, currently only `node22` and `python3.13` are supported.
|
|
56
|
+
* The runtime of the sandbox, currently only `node24`, `node22` and `python3.13` are supported.
|
|
54
57
|
* If not specified, the default runtime `node22` will be used.
|
|
55
58
|
*/
|
|
56
|
-
runtime?:
|
|
59
|
+
runtime?: RUNTIMES | (string & {});
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
62
|
* An AbortSignal to cancel sandbox creation.
|
|
@@ -61,6 +64,12 @@ export interface CreateSandboxParams {
|
|
|
61
64
|
signal?: AbortSignal;
|
|
62
65
|
}
|
|
63
66
|
|
|
67
|
+
export type CreateSandboxParams =
|
|
68
|
+
| BaseCreateSandboxParams
|
|
69
|
+
| (Omit<BaseCreateSandboxParams, "runtime" | "source"> & {
|
|
70
|
+
source: { type: "snapshot"; snapshotId: string };
|
|
71
|
+
});
|
|
72
|
+
|
|
64
73
|
/** @inline */
|
|
65
74
|
interface GetSandboxParams {
|
|
66
75
|
/**
|
|
@@ -164,12 +173,15 @@ export class Sandbox {
|
|
|
164
173
|
* the next page of results.
|
|
165
174
|
*/
|
|
166
175
|
static async list(
|
|
167
|
-
params: Parameters<APIClient["listSandboxes"]>[0] &
|
|
176
|
+
params: Parameters<APIClient["listSandboxes"]>[0] &
|
|
177
|
+
Partial<Credentials> &
|
|
178
|
+
WithFetchOptions,
|
|
168
179
|
) {
|
|
169
180
|
const credentials = await getCredentials(params);
|
|
170
181
|
const client = new APIClient({
|
|
171
182
|
teamId: credentials.teamId,
|
|
172
183
|
token: credentials.token,
|
|
184
|
+
fetch: params.fetch,
|
|
173
185
|
});
|
|
174
186
|
return client.listSandboxes({
|
|
175
187
|
...params,
|
|
@@ -186,12 +198,14 @@ export class Sandbox {
|
|
|
186
198
|
static async create(
|
|
187
199
|
params?: WithPrivate<
|
|
188
200
|
CreateSandboxParams | (CreateSandboxParams & Credentials)
|
|
189
|
-
|
|
201
|
+
> &
|
|
202
|
+
WithFetchOptions,
|
|
190
203
|
): Promise<Sandbox> {
|
|
191
204
|
const credentials = await getCredentials(params);
|
|
192
205
|
const client = new APIClient({
|
|
193
206
|
teamId: credentials.teamId,
|
|
194
207
|
token: credentials.token,
|
|
208
|
+
fetch: params?.fetch,
|
|
195
209
|
});
|
|
196
210
|
|
|
197
211
|
const privateParams = getPrivateParams(params);
|
|
@@ -201,7 +215,7 @@ export class Sandbox {
|
|
|
201
215
|
ports: params?.ports ?? [],
|
|
202
216
|
timeout: params?.timeout,
|
|
203
217
|
resources: params?.resources,
|
|
204
|
-
runtime: params?.runtime,
|
|
218
|
+
runtime: params && "runtime" in params ? params?.runtime : undefined,
|
|
205
219
|
signal: params?.signal,
|
|
206
220
|
...privateParams,
|
|
207
221
|
});
|
|
@@ -220,12 +234,14 @@ export class Sandbox {
|
|
|
220
234
|
* @returns A promise resolving to the {@link Sandbox}.
|
|
221
235
|
*/
|
|
222
236
|
static async get(
|
|
223
|
-
params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)
|
|
237
|
+
params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)> &
|
|
238
|
+
WithFetchOptions,
|
|
224
239
|
): Promise<Sandbox> {
|
|
225
240
|
const credentials = await getCredentials(params);
|
|
226
241
|
const client = new APIClient({
|
|
227
242
|
teamId: credentials.teamId,
|
|
228
243
|
token: credentials.token,
|
|
244
|
+
fetch: params.fetch,
|
|
229
245
|
});
|
|
230
246
|
|
|
231
247
|
const privateParams = getPrivateParams(params);
|
|
@@ -494,4 +510,28 @@ export class Sandbox {
|
|
|
494
510
|
// Update the internal sandbox metadata with the new timeout value
|
|
495
511
|
this.sandbox = response.json.sandbox;
|
|
496
512
|
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Create a snapshot from this currently running sandbox. New sandboxes can
|
|
516
|
+
* then be created from this snapshot using {@link Sandbox.createFromSnapshot}.
|
|
517
|
+
*
|
|
518
|
+
* Note: this sandbox will be stopped as part of the snapshot creation process.
|
|
519
|
+
*
|
|
520
|
+
* @param opts - Optional parameters.
|
|
521
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
522
|
+
* @returns A promise that resolves to the Snapshot instance
|
|
523
|
+
*/
|
|
524
|
+
async snapshot(opts?: { signal?: AbortSignal }): Promise<Snapshot> {
|
|
525
|
+
const response = await this.client.createSnapshot({
|
|
526
|
+
sandboxId: this.sandbox.id,
|
|
527
|
+
signal: opts?.signal,
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
this.sandbox = response.json.sandbox;
|
|
531
|
+
|
|
532
|
+
return new Snapshot({
|
|
533
|
+
client: this.client,
|
|
534
|
+
snapshot: response.json.snapshot,
|
|
535
|
+
});
|
|
536
|
+
}
|
|
497
537
|
}
|
package/src/snapshot.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { SnapshotMetadata } from "./api-client";
|
|
2
|
+
import { APIClient } from "./api-client";
|
|
3
|
+
import { Credentials, getCredentials } from "./utils/get-credentials";
|
|
4
|
+
|
|
5
|
+
/** @inline */
|
|
6
|
+
interface GetSnapshotParams {
|
|
7
|
+
/**
|
|
8
|
+
* Unique identifier of the snapshot.
|
|
9
|
+
*/
|
|
10
|
+
snapshotId: string;
|
|
11
|
+
/**
|
|
12
|
+
* An AbortSignal to cancel the operation.
|
|
13
|
+
*/
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
|
|
19
|
+
*
|
|
20
|
+
* Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
|
|
21
|
+
* @hideconstructor
|
|
22
|
+
*/
|
|
23
|
+
export class Snapshot {
|
|
24
|
+
private readonly client: APIClient;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Unique ID of this snapshot.
|
|
28
|
+
*/
|
|
29
|
+
public get snapshotId(): string {
|
|
30
|
+
return this.snapshot.id;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The ID the sandbox from which this snapshot was created.
|
|
35
|
+
*/
|
|
36
|
+
public get sourceSandboxId(): string {
|
|
37
|
+
return this.snapshot.sourceSandboxId;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The status of the snapshot.
|
|
42
|
+
*/
|
|
43
|
+
public get status(): SnapshotMetadata["status"] {
|
|
44
|
+
return this.snapshot.status;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Internal metadata about this snapshot.
|
|
49
|
+
*/
|
|
50
|
+
private snapshot: SnapshotMetadata;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Create a new Snapshot instance.
|
|
54
|
+
*
|
|
55
|
+
* @param client - API client used to communicate with the backend
|
|
56
|
+
* @param snapshot - Snapshot metadata
|
|
57
|
+
*/
|
|
58
|
+
constructor({
|
|
59
|
+
client,
|
|
60
|
+
snapshot,
|
|
61
|
+
}: {
|
|
62
|
+
client: APIClient;
|
|
63
|
+
snapshot: SnapshotMetadata;
|
|
64
|
+
}) {
|
|
65
|
+
this.client = client;
|
|
66
|
+
this.snapshot = snapshot;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Retrieve an existing snapshot.
|
|
71
|
+
*
|
|
72
|
+
* @param params - Get parameters and optional credentials.
|
|
73
|
+
* @returns A promise resolving to the {@link Sandbox}.
|
|
74
|
+
*/
|
|
75
|
+
static async get(
|
|
76
|
+
params: GetSnapshotParams | (GetSnapshotParams & Credentials),
|
|
77
|
+
): Promise<Snapshot> {
|
|
78
|
+
const credentials = await getCredentials(params);
|
|
79
|
+
const client = new APIClient({
|
|
80
|
+
teamId: credentials.teamId,
|
|
81
|
+
token: credentials.token,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const sandbox = await client.getSnapshot({
|
|
85
|
+
snapshotId: params.snapshotId,
|
|
86
|
+
signal: params.signal,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return new Snapshot({
|
|
90
|
+
client,
|
|
91
|
+
snapshot: sandbox.json.snapshot,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Delete this snapshot.
|
|
97
|
+
*
|
|
98
|
+
* @param opts - Optional parameters.
|
|
99
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
100
|
+
* @returns A promise that resolves once the snapshot has been deleted.
|
|
101
|
+
*/
|
|
102
|
+
async delete(opts?: { signal?: AbortSignal }): Promise<void> {
|
|
103
|
+
const response = await this.client.deleteSnapshot({
|
|
104
|
+
snapshotId: this.snapshot.id,
|
|
105
|
+
signal: opts?.signal,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
this.snapshot = response.json.snapshot;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Autogenerated by inject-version.ts
|
|
2
|
-
export const VERSION = "1.
|
|
2
|
+
export const VERSION = "1.1.1";
|