@vercel/sandbox 2.0.0-beta.2 → 2.0.0-beta.20
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 +48 -1
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/api-client/api-client.cjs +445 -0
- package/dist/api-client/api-client.cjs.map +1 -0
- package/dist/api-client/api-client.d.cts +6235 -0
- package/dist/api-client/api-client.d.ts +6229 -706
- package/dist/api-client/api-client.js +436 -472
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/api-error.cjs +32 -0
- package/dist/api-client/api-error.cjs.map +1 -0
- package/dist/api-client/api-error.d.cts +29 -0
- package/dist/api-client/api-error.d.ts +21 -16
- package/dist/api-client/api-error.js +28 -32
- package/dist/api-client/api-error.js.map +1 -1
- package/dist/api-client/base-client.cjs +126 -0
- package/dist/api-client/base-client.cjs.map +1 -0
- package/dist/api-client/base-client.d.cts +38 -0
- package/dist/api-client/base-client.d.ts +31 -36
- package/dist/api-client/base-client.js +114 -118
- package/dist/api-client/base-client.js.map +1 -1
- package/dist/api-client/file-writer.cjs +62 -0
- package/dist/api-client/file-writer.cjs.map +1 -0
- package/dist/api-client/file-writer.d.cts +66 -0
- package/dist/api-client/file-writer.d.ts +56 -42
- package/dist/api-client/file-writer.js +57 -61
- package/dist/api-client/file-writer.js.map +1 -1
- package/dist/api-client/index.cjs +2 -0
- package/dist/api-client/index.d.ts +2 -2
- package/dist/api-client/index.js +4 -21
- package/dist/api-client/validators.cjs +229 -0
- package/dist/api-client/validators.cjs.map +1 -0
- package/dist/api-client/validators.d.cts +26885 -0
- package/dist/api-client/validators.d.ts +26732 -3706
- package/dist/api-client/validators.js +198 -191
- package/dist/api-client/validators.js.map +1 -1
- package/dist/api-client/with-retry.cjs +89 -0
- package/dist/api-client/with-retry.cjs.map +1 -0
- package/dist/api-client/with-retry.d.cts +10 -0
- package/dist/api-client/with-retry.d.ts +9 -13
- package/dist/api-client/with-retry.js +81 -102
- package/dist/api-client/with-retry.js.map +1 -1
- package/dist/auth/api.cjs +29 -0
- package/dist/auth/api.cjs.map +1 -0
- package/dist/auth/api.js +26 -25
- package/dist/auth/api.js.map +1 -1
- package/dist/auth/error.cjs +13 -0
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.js +11 -11
- package/dist/auth/error.js.map +1 -1
- package/dist/auth/file.cjs +64 -0
- package/dist/auth/file.cjs.map +1 -0
- package/dist/auth/file.d.cts +26 -0
- package/dist/auth/file.d.ts +19 -15
- package/dist/auth/file.js +49 -64
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/index.cjs +11 -0
- package/dist/auth/index.d.cts +5 -0
- package/dist/auth/index.d.ts +5 -6
- package/dist/auth/index.js +6 -27
- package/dist/auth/linked-project.cjs +38 -0
- package/dist/auth/linked-project.cjs.map +1 -0
- package/dist/auth/linked-project.js +30 -64
- package/dist/auth/linked-project.js.map +1 -1
- package/dist/auth/oauth.cjs +205 -0
- package/dist/auth/oauth.cjs.map +1 -0
- package/dist/auth/oauth.d.cts +135 -0
- package/dist/auth/oauth.d.ts +113 -109
- package/dist/auth/oauth.js +185 -252
- package/dist/auth/oauth.js.map +1 -1
- package/dist/auth/poll-for-token.cjs +82 -0
- package/dist/auth/poll-for-token.cjs.map +1 -0
- package/dist/auth/poll-for-token.d.cts +28 -0
- package/dist/auth/poll-for-token.d.ts +23 -15
- package/dist/auth/poll-for-token.js +79 -64
- package/dist/auth/poll-for-token.js.map +1 -1
- package/dist/auth/project.cjs +178 -0
- package/dist/auth/project.cjs.map +1 -0
- package/dist/auth/project.d.cts +40 -0
- package/dist/auth/project.d.ts +19 -19
- package/dist/auth/project.js +169 -72
- package/dist/auth/project.js.map +1 -1
- package/dist/auth/zod.cjs +22 -0
- package/dist/auth/zod.cjs.map +1 -0
- package/dist/auth/zod.js +18 -17
- package/dist/auth/zod.js.map +1 -1
- package/dist/command.cjs +328 -0
- package/dist/command.cjs.map +1 -0
- package/dist/command.d.cts +289 -0
- package/dist/command.d.ts +265 -171
- package/dist/command.js +323 -226
- package/dist/command.js.map +1 -1
- package/dist/constants.d.cts +5 -0
- package/dist/constants.d.ts +5 -1
- package/dist/filesystem.cjs +499 -0
- package/dist/filesystem.cjs.map +1 -0
- package/dist/filesystem.d.cts +258 -0
- package/dist/filesystem.d.ts +258 -0
- package/dist/filesystem.js +497 -0
- package/dist/filesystem.js.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.js +8 -17
- package/dist/network-policy.d.cts +156 -0
- package/dist/network-policy.d.ts +88 -28
- package/dist/sandbox.cjs +816 -0
- package/dist/sandbox.cjs.map +1 -0
- package/dist/sandbox.d.cts +2847 -0
- package/dist/sandbox.d.ts +2834 -628
- package/dist/sandbox.js +808 -557
- package/dist/sandbox.js.map +1 -1
- package/dist/session.cjs +527 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +410 -0
- package/dist/session.d.ts +403 -368
- package/dist/session.js +524 -489
- package/dist/session.js.map +1 -1
- package/dist/snapshot.cjs +204 -0
- package/dist/snapshot.cjs.map +1 -0
- package/dist/snapshot.d.cts +161 -0
- package/dist/snapshot.d.ts +152 -92
- package/dist/snapshot.js +201 -114
- package/dist/snapshot.js.map +1 -1
- package/dist/utils/array.cjs +17 -0
- package/dist/utils/array.cjs.map +1 -0
- package/dist/utils/array.js +12 -15
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/consume-readable.cjs +18 -0
- package/dist/utils/consume-readable.cjs.map +1 -0
- package/dist/utils/consume-readable.js +13 -12
- package/dist/utils/consume-readable.js.map +1 -1
- package/dist/utils/decode-base64-url.cjs +15 -0
- package/dist/utils/decode-base64-url.cjs.map +1 -0
- package/dist/utils/decode-base64-url.js +10 -9
- package/dist/utils/decode-base64-url.js.map +1 -1
- package/dist/utils/dev-credentials.cjs +142 -0
- package/dist/utils/dev-credentials.cjs.map +1 -0
- package/dist/utils/dev-credentials.js +126 -184
- package/dist/utils/dev-credentials.js.map +1 -1
- package/dist/utils/get-credentials.cjs +123 -0
- package/dist/utils/get-credentials.cjs.map +1 -0
- package/dist/utils/get-credentials.d.cts +21 -0
- package/dist/utils/get-credentials.d.ts +19 -61
- package/dist/utils/get-credentials.js +106 -140
- package/dist/utils/get-credentials.js.map +1 -1
- package/dist/utils/log.cjs +25 -0
- package/dist/utils/log.cjs.map +1 -0
- package/dist/utils/log.js +15 -17
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/network-policy.cjs +49 -0
- package/dist/utils/network-policy.cjs.map +1 -0
- package/dist/utils/network-policy.js +42 -77
- package/dist/utils/network-policy.js.map +1 -1
- package/dist/utils/normalizePath.cjs +27 -0
- package/dist/utils/normalizePath.cjs.map +1 -0
- package/dist/utils/normalizePath.js +21 -28
- package/dist/utils/normalizePath.js.map +1 -1
- package/dist/utils/paginator.cjs +41 -0
- package/dist/utils/paginator.cjs.map +1 -0
- package/dist/utils/paginator.d.cts +16 -0
- package/dist/utils/paginator.d.ts +16 -0
- package/dist/utils/paginator.js +40 -0
- package/dist/utils/paginator.js.map +1 -0
- package/dist/utils/resolveSignal.cjs +20 -0
- package/dist/utils/resolveSignal.cjs.map +1 -0
- package/dist/utils/resolveSignal.d.cts +15 -0
- package/dist/utils/resolveSignal.d.ts +12 -10
- package/dist/utils/resolveSignal.js +14 -17
- package/dist/utils/resolveSignal.js.map +1 -1
- package/dist/utils/sandbox-snapshot.cjs +14 -0
- package/dist/utils/sandbox-snapshot.cjs.map +1 -0
- package/dist/utils/sandbox-snapshot.d.cts +10 -0
- package/dist/utils/sandbox-snapshot.d.ts +11 -0
- package/dist/utils/sandbox-snapshot.js +14 -0
- package/dist/utils/sandbox-snapshot.js.map +1 -0
- package/dist/utils/types.cjs +13 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +11 -0
- package/dist/utils/types.d.ts +5 -7
- package/dist/utils/types.js +8 -8
- package/dist/utils/types.js.map +1 -1
- package/dist/version.cjs +7 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +5 -5
- package/dist/version.js.map +1 -1
- package/package.json +23 -3
- package/dist/api-client/index.js.map +0 -1
- package/dist/auth/api.d.ts +0 -6
- package/dist/auth/error.d.ts +0 -11
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/linked-project.d.ts +0 -10
- package/dist/auth/zod.d.ts +0 -5
- package/dist/constants.js +0 -3
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/network-policy.js +0 -3
- package/dist/network-policy.js.map +0 -1
- package/dist/utils/array.d.ts +0 -9
- package/dist/utils/consume-readable.d.ts +0 -5
- package/dist/utils/convert-sandbox.d.ts +0 -6
- package/dist/utils/convert-sandbox.js +0 -14
- package/dist/utils/convert-sandbox.js.map +0 -1
- package/dist/utils/decode-base64-url.d.ts +0 -7
- package/dist/utils/dev-credentials.d.ts +0 -37
- package/dist/utils/log.d.ts +0 -2
- package/dist/utils/network-policy.d.ts +0 -7
- package/dist/utils/normalizePath.d.ts +0 -17
- package/dist/version.d.ts +0 -1
package/dist/snapshot.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { WithFetchOptions } from "./api-client/api-client";
|
|
4
|
-
import
|
|
1
|
+
import { Paginator } from "./utils/paginator.js";
|
|
2
|
+
import { SnapshotMetadata } from "./api-client/validators.js";
|
|
3
|
+
import { APIClient, WithFetchOptions } from "./api-client/api-client.js";
|
|
4
|
+
import "./api-client/index.js";
|
|
5
|
+
import { Credentials } from "./utils/get-credentials.js";
|
|
6
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
7
|
+
|
|
8
|
+
//#region src/snapshot.d.ts
|
|
9
|
+
interface SerializedSnapshot {
|
|
10
|
+
snapshot: SnapshotMetadata;
|
|
11
|
+
}
|
|
5
12
|
/** @inline */
|
|
6
13
|
interface GetSnapshotParams {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Unique identifier of the snapshot.
|
|
16
|
+
*/
|
|
17
|
+
snapshotId: string;
|
|
18
|
+
/**
|
|
19
|
+
* An AbortSignal to cancel the operation.
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
15
22
|
}
|
|
16
23
|
/**
|
|
17
24
|
* A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
|
|
@@ -19,84 +26,137 @@ interface GetSnapshotParams {
|
|
|
19
26
|
* Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
|
|
20
27
|
* @hideconstructor
|
|
21
28
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
29
|
+
declare class Snapshot {
|
|
30
|
+
private _client;
|
|
31
|
+
/**
|
|
32
|
+
* Lazily resolve credentials and construct an API client.
|
|
33
|
+
* This is used in step contexts where the Snapshot was deserialized
|
|
34
|
+
* without a client (e.g. when crossing workflow/step boundaries).
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
private ensureClient;
|
|
38
|
+
/**
|
|
39
|
+
* Unique ID of this snapshot.
|
|
40
|
+
*/
|
|
41
|
+
get snapshotId(): string;
|
|
42
|
+
/**
|
|
43
|
+
* The ID of the session from which this snapshot was created.
|
|
44
|
+
*/
|
|
45
|
+
get sourceSessionId(): string;
|
|
46
|
+
/**
|
|
47
|
+
* The status of the snapshot.
|
|
48
|
+
*/
|
|
49
|
+
get status(): SnapshotMetadata["status"];
|
|
50
|
+
/**
|
|
51
|
+
* The size of the snapshot in bytes, or null if not available.
|
|
52
|
+
*/
|
|
53
|
+
get sizeBytes(): number;
|
|
54
|
+
/**
|
|
55
|
+
* The creation date of this snapshot.
|
|
56
|
+
*/
|
|
57
|
+
get createdAt(): Date;
|
|
58
|
+
/**
|
|
59
|
+
* The expiration date of this snapshot, or undefined if it does not expire.
|
|
60
|
+
*/
|
|
61
|
+
get expiresAt(): Date | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Internal metadata about this snapshot.
|
|
64
|
+
*/
|
|
65
|
+
private snapshot;
|
|
66
|
+
/**
|
|
67
|
+
* Serialize a Snapshot instance to plain data for @workflow/serde.
|
|
68
|
+
*
|
|
69
|
+
* @param instance - The Snapshot instance to serialize
|
|
70
|
+
* @returns A plain object containing snapshot metadata
|
|
71
|
+
*/
|
|
72
|
+
static [WORKFLOW_SERIALIZE](instance: Snapshot): SerializedSnapshot;
|
|
73
|
+
/**
|
|
74
|
+
* Deserialize a Snapshot from serialized data.
|
|
75
|
+
*
|
|
76
|
+
* The deserialized instance uses the serialized metadata synchronously and
|
|
77
|
+
* lazily creates an API client only when methods perform API requests.
|
|
78
|
+
*
|
|
79
|
+
* @param data - The serialized snapshot data
|
|
80
|
+
* @returns The reconstructed Snapshot instance
|
|
81
|
+
*/
|
|
82
|
+
static [WORKFLOW_DESERIALIZE](data: SerializedSnapshot): Snapshot;
|
|
83
|
+
constructor({
|
|
84
|
+
client,
|
|
85
|
+
snapshot
|
|
86
|
+
}: {
|
|
87
|
+
client?: APIClient;
|
|
88
|
+
snapshot: SnapshotMetadata;
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* Allow to get a list of snapshots for a team narrowed to the given params.
|
|
92
|
+
* It returns both the snapshots and the pagination metadata to allow getting
|
|
93
|
+
* the next page of results.
|
|
94
|
+
*
|
|
95
|
+
* The returned object is async-iterable to auto-paginate through all pages:
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* const result = await Snapshot.list({ name: "my-sandbox" });
|
|
99
|
+
* for await (const snapshot of result) { ... }
|
|
100
|
+
* // or: await result.toArray();
|
|
101
|
+
* // or: for await (const page of result.pages()) { ... }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
static list(params?: Partial<Parameters<APIClient["listSnapshots"]>[0]> & Partial<Credentials> & WithFetchOptions): Promise<Paginator<{
|
|
105
|
+
pagination: {
|
|
106
|
+
count: number;
|
|
107
|
+
next: string | null;
|
|
108
|
+
};
|
|
109
|
+
snapshots: {
|
|
110
|
+
status: "failed" | "created" | "deleted";
|
|
111
|
+
region: string;
|
|
112
|
+
createdAt: number;
|
|
113
|
+
updatedAt: number;
|
|
114
|
+
id: string;
|
|
115
|
+
sourceSessionId: string;
|
|
116
|
+
sizeBytes: number;
|
|
117
|
+
expiresAt?: number | undefined;
|
|
118
|
+
}[];
|
|
119
|
+
}, "snapshots">>;
|
|
120
|
+
/**
|
|
121
|
+
* Resolve the current snapshot ID of an existing sandbox by name.
|
|
122
|
+
*
|
|
123
|
+
* Useful to feed into {@link Sandbox.create} as `source.snapshotId` without
|
|
124
|
+
* having to first look up the sandbox yourself.
|
|
125
|
+
*
|
|
126
|
+
* @param name - The name of the source sandbox.
|
|
127
|
+
* @param opts - Optional credentials, fetch override, and abort signal.
|
|
128
|
+
* @returns The current snapshot ID of the named sandbox.
|
|
129
|
+
* @throws If the sandbox has no current snapshot.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* const sandbox = await Sandbox.create({
|
|
133
|
+
* source: {
|
|
134
|
+
* type: "snapshot",
|
|
135
|
+
* snapshotId: await Snapshot.fromSandbox("my-sandbox"),
|
|
136
|
+
* },
|
|
137
|
+
* });
|
|
138
|
+
*/
|
|
139
|
+
static fromSandbox(name: string, opts?: Partial<Credentials> & WithFetchOptions & {
|
|
140
|
+
signal?: AbortSignal;
|
|
141
|
+
}): Promise<string>;
|
|
142
|
+
/**
|
|
143
|
+
* Retrieve an existing snapshot.
|
|
144
|
+
*
|
|
145
|
+
* @param params - Get parameters and optional credentials.
|
|
146
|
+
* @returns A promise resolving to the {@link Sandbox}.
|
|
147
|
+
*/
|
|
148
|
+
static get(params: GetSnapshotParams | (GetSnapshotParams & Credentials)): Promise<Snapshot>;
|
|
149
|
+
/**
|
|
150
|
+
* Delete this snapshot.
|
|
151
|
+
*
|
|
152
|
+
* @param opts - Optional parameters.
|
|
153
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
154
|
+
* @returns A promise that resolves once the snapshot has been deleted.
|
|
155
|
+
*/
|
|
156
|
+
delete(opts?: {
|
|
157
|
+
signal?: AbortSignal;
|
|
158
|
+
}): Promise<void>;
|
|
101
159
|
}
|
|
102
|
-
|
|
160
|
+
//#endregion
|
|
161
|
+
export { SerializedSnapshot, Snapshot };
|
|
162
|
+
//# sourceMappingURL=snapshot.d.ts.map
|
package/dist/snapshot.js
CHANGED
|
@@ -1,116 +1,203 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { APIClient } from "./api-client/api-client.js";
|
|
2
|
+
import "./api-client/index.js";
|
|
3
|
+
import { getCredentials } from "./utils/get-credentials.js";
|
|
4
|
+
import { attachPaginator } from "./utils/paginator.js";
|
|
5
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from "@workflow/serde";
|
|
6
|
+
|
|
7
|
+
//#region src/snapshot.ts
|
|
6
8
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Snapshot {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
9
|
+
* A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
|
|
10
|
+
*
|
|
11
|
+
* Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
|
|
12
|
+
* @hideconstructor
|
|
13
|
+
*/
|
|
14
|
+
var Snapshot = class Snapshot {
|
|
15
|
+
/**
|
|
16
|
+
* Lazily resolve credentials and construct an API client.
|
|
17
|
+
* This is used in step contexts where the Snapshot was deserialized
|
|
18
|
+
* without a client (e.g. when crossing workflow/step boundaries).
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
async ensureClient() {
|
|
22
|
+
"use step";
|
|
23
|
+
if (this._client) return this._client;
|
|
24
|
+
const credentials = await getCredentials();
|
|
25
|
+
this._client = new APIClient({
|
|
26
|
+
teamId: credentials.teamId,
|
|
27
|
+
token: credentials.token
|
|
28
|
+
});
|
|
29
|
+
return this._client;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Unique ID of this snapshot.
|
|
33
|
+
*/
|
|
34
|
+
get snapshotId() {
|
|
35
|
+
return this.snapshot.id;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The ID of the session from which this snapshot was created.
|
|
39
|
+
*/
|
|
40
|
+
get sourceSessionId() {
|
|
41
|
+
return this.snapshot.sourceSessionId;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The status of the snapshot.
|
|
45
|
+
*/
|
|
46
|
+
get status() {
|
|
47
|
+
return this.snapshot.status;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The size of the snapshot in bytes, or null if not available.
|
|
51
|
+
*/
|
|
52
|
+
get sizeBytes() {
|
|
53
|
+
return this.snapshot.sizeBytes;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The creation date of this snapshot.
|
|
57
|
+
*/
|
|
58
|
+
get createdAt() {
|
|
59
|
+
return new Date(this.snapshot.createdAt);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The expiration date of this snapshot, or undefined if it does not expire.
|
|
63
|
+
*/
|
|
64
|
+
get expiresAt() {
|
|
65
|
+
if (this.snapshot.expiresAt === void 0) return;
|
|
66
|
+
return new Date(this.snapshot.expiresAt);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Serialize a Snapshot instance to plain data for @workflow/serde.
|
|
70
|
+
*
|
|
71
|
+
* @param instance - The Snapshot instance to serialize
|
|
72
|
+
* @returns A plain object containing snapshot metadata
|
|
73
|
+
*/
|
|
74
|
+
static [WORKFLOW_SERIALIZE](instance) {
|
|
75
|
+
return { snapshot: instance.snapshot };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Deserialize a Snapshot from serialized data.
|
|
79
|
+
*
|
|
80
|
+
* The deserialized instance uses the serialized metadata synchronously and
|
|
81
|
+
* lazily creates an API client only when methods perform API requests.
|
|
82
|
+
*
|
|
83
|
+
* @param data - The serialized snapshot data
|
|
84
|
+
* @returns The reconstructed Snapshot instance
|
|
85
|
+
*/
|
|
86
|
+
static [WORKFLOW_DESERIALIZE](data) {
|
|
87
|
+
return new Snapshot({ snapshot: data.snapshot });
|
|
88
|
+
}
|
|
89
|
+
constructor({ client, snapshot }) {
|
|
90
|
+
this._client = null;
|
|
91
|
+
this._client = client ?? null;
|
|
92
|
+
this.snapshot = snapshot;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Allow to get a list of snapshots for a team narrowed to the given params.
|
|
96
|
+
* It returns both the snapshots and the pagination metadata to allow getting
|
|
97
|
+
* the next page of results.
|
|
98
|
+
*
|
|
99
|
+
* The returned object is async-iterable to auto-paginate through all pages:
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* const result = await Snapshot.list({ name: "my-sandbox" });
|
|
103
|
+
* for await (const snapshot of result) { ... }
|
|
104
|
+
* // or: await result.toArray();
|
|
105
|
+
* // or: for await (const page of result.pages()) { ... }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
static async list(params) {
|
|
109
|
+
"use step";
|
|
110
|
+
const credentials = await getCredentials(params);
|
|
111
|
+
const client = new APIClient({
|
|
112
|
+
teamId: credentials.teamId,
|
|
113
|
+
token: credentials.token,
|
|
114
|
+
fetch: params?.fetch
|
|
115
|
+
});
|
|
116
|
+
const fetchPage = async (cursor) => {
|
|
117
|
+
return (await client.listSnapshots({
|
|
118
|
+
...credentials,
|
|
119
|
+
...params,
|
|
120
|
+
...cursor !== void 0 && { cursor }
|
|
121
|
+
})).json;
|
|
122
|
+
};
|
|
123
|
+
return attachPaginator(await fetchPage(params?.cursor), {
|
|
124
|
+
itemsKey: "snapshots",
|
|
125
|
+
fetchNext: fetchPage,
|
|
126
|
+
signal: params?.signal
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Resolve the current snapshot ID of an existing sandbox by name.
|
|
131
|
+
*
|
|
132
|
+
* Useful to feed into {@link Sandbox.create} as `source.snapshotId` without
|
|
133
|
+
* having to first look up the sandbox yourself.
|
|
134
|
+
*
|
|
135
|
+
* @param name - The name of the source sandbox.
|
|
136
|
+
* @param opts - Optional credentials, fetch override, and abort signal.
|
|
137
|
+
* @returns The current snapshot ID of the named sandbox.
|
|
138
|
+
* @throws If the sandbox has no current snapshot.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* const sandbox = await Sandbox.create({
|
|
142
|
+
* source: {
|
|
143
|
+
* type: "snapshot",
|
|
144
|
+
* snapshotId: await Snapshot.fromSandbox("my-sandbox"),
|
|
145
|
+
* },
|
|
146
|
+
* });
|
|
147
|
+
*/
|
|
148
|
+
static async fromSandbox(name, opts) {
|
|
149
|
+
"use step";
|
|
150
|
+
const credentials = await getCredentials(opts);
|
|
151
|
+
const snapshotId = (await new APIClient({
|
|
152
|
+
teamId: credentials.teamId,
|
|
153
|
+
token: credentials.token,
|
|
154
|
+
fetch: opts?.fetch
|
|
155
|
+
}).getSandbox({
|
|
156
|
+
name,
|
|
157
|
+
projectId: credentials.projectId,
|
|
158
|
+
resume: false,
|
|
159
|
+
signal: opts?.signal
|
|
160
|
+
})).json.sandbox.currentSnapshotId;
|
|
161
|
+
if (!snapshotId) throw new Error(`Sandbox "${name}" has no current snapshot.`);
|
|
162
|
+
return snapshotId;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Retrieve an existing snapshot.
|
|
166
|
+
*
|
|
167
|
+
* @param params - Get parameters and optional credentials.
|
|
168
|
+
* @returns A promise resolving to the {@link Sandbox}.
|
|
169
|
+
*/
|
|
170
|
+
static async get(params) {
|
|
171
|
+
"use step";
|
|
172
|
+
const credentials = await getCredentials(params);
|
|
173
|
+
const client = new APIClient({
|
|
174
|
+
teamId: credentials.teamId,
|
|
175
|
+
token: credentials.token
|
|
176
|
+
});
|
|
177
|
+
return new Snapshot({
|
|
178
|
+
client,
|
|
179
|
+
snapshot: (await client.getSnapshot({
|
|
180
|
+
snapshotId: params.snapshotId,
|
|
181
|
+
signal: params.signal
|
|
182
|
+
})).json.snapshot
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Delete this snapshot.
|
|
187
|
+
*
|
|
188
|
+
* @param opts - Optional parameters.
|
|
189
|
+
* @param opts.signal - An AbortSignal to cancel the operation.
|
|
190
|
+
* @returns A promise that resolves once the snapshot has been deleted.
|
|
191
|
+
*/
|
|
192
|
+
async delete(opts) {
|
|
193
|
+
"use step";
|
|
194
|
+
this.snapshot = (await (await this.ensureClient()).deleteSnapshot({
|
|
195
|
+
snapshotId: this.snapshot.id,
|
|
196
|
+
signal: opts?.signal
|
|
197
|
+
})).json.snapshot;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
//#endregion
|
|
202
|
+
export { Snapshot };
|
|
116
203
|
//# sourceMappingURL=snapshot.js.map
|
package/dist/snapshot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.js","
|
|
1
|
+
{"version":3,"file":"snapshot.js","names":[],"sources":["../src/snapshot.ts"],"sourcesContent":["import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from \"@workflow/serde\";\nimport type { WithFetchOptions } from \"./api-client/api-client.js\";\nimport type { SnapshotMetadata } from \"./api-client/index.js\";\nimport { APIClient } from \"./api-client/index.js\";\nimport { type Credentials, getCredentials } from \"./utils/get-credentials.js\";\nimport { attachPaginator } from \"./utils/paginator.js\";\n\nexport interface SerializedSnapshot {\n snapshot: SnapshotMetadata;\n}\n\n/** @inline */\ninterface GetSnapshotParams {\n /**\n * Unique identifier of the snapshot.\n */\n snapshotId: string;\n /**\n * An AbortSignal to cancel the operation.\n */\n signal?: AbortSignal;\n}\n\n/**\n * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes\n *\n * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.\n * @hideconstructor\n */\nexport class Snapshot {\n private _client: APIClient | null = null;\n\n /**\n * Lazily resolve credentials and construct an API client.\n * This is used in step contexts where the Snapshot was deserialized\n * without a client (e.g. when crossing workflow/step boundaries).\n * @internal\n */\n private async ensureClient(): Promise<APIClient> {\n \"use step\";\n if (this._client) return this._client;\n const credentials = await getCredentials();\n this._client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n return this._client;\n }\n\n /**\n * Unique ID of this snapshot.\n */\n public get snapshotId(): string {\n return this.snapshot.id;\n }\n\n /**\n * The ID of the session from which this snapshot was created.\n */\n public get sourceSessionId(): string {\n return this.snapshot.sourceSessionId;\n }\n\n /**\n * The status of the snapshot.\n */\n public get status(): SnapshotMetadata[\"status\"] {\n return this.snapshot.status;\n }\n\n /**\n * The size of the snapshot in bytes, or null if not available.\n */\n public get sizeBytes(): number {\n return this.snapshot.sizeBytes;\n }\n\n /**\n * The creation date of this snapshot.\n */\n public get createdAt(): Date {\n return new Date(this.snapshot.createdAt);\n }\n\n /**\n * The expiration date of this snapshot, or undefined if it does not expire.\n */\n public get expiresAt(): Date | undefined {\n if (this.snapshot.expiresAt === undefined) {\n return undefined;\n }\n\n return new Date(this.snapshot.expiresAt);\n }\n\n /**\n * Internal metadata about this snapshot.\n */\n private snapshot: SnapshotMetadata;\n\n /**\n * Serialize a Snapshot instance to plain data for @workflow/serde.\n *\n * @param instance - The Snapshot instance to serialize\n * @returns A plain object containing snapshot metadata\n */\n static [WORKFLOW_SERIALIZE](instance: Snapshot): SerializedSnapshot {\n return {\n snapshot: instance.snapshot,\n };\n }\n\n /**\n * Deserialize a Snapshot from serialized data.\n *\n * The deserialized instance uses the serialized metadata synchronously and\n * lazily creates an API client only when methods perform API requests.\n *\n * @param data - The serialized snapshot data\n * @returns The reconstructed Snapshot instance\n */\n static [WORKFLOW_DESERIALIZE](data: SerializedSnapshot): Snapshot {\n return new Snapshot({\n snapshot: data.snapshot,\n });\n }\n\n constructor({\n client,\n snapshot,\n }: {\n client?: APIClient;\n snapshot: SnapshotMetadata;\n }) {\n this._client = client ?? null;\n this.snapshot = snapshot;\n }\n\n /**\n * Allow to get a list of snapshots for a team narrowed to the given params.\n * It returns both the snapshots and the pagination metadata to allow getting\n * the next page of results.\n *\n * The returned object is async-iterable to auto-paginate through all pages:\n *\n * ```ts\n * const result = await Snapshot.list({ name: \"my-sandbox\" });\n * for await (const snapshot of result) { ... }\n * // or: await result.toArray();\n * // or: for await (const page of result.pages()) { ... }\n * ```\n */\n static async list(\n params?: Partial<Parameters<APIClient[\"listSnapshots\"]>[0]> &\n Partial<Credentials> &\n WithFetchOptions,\n ) {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n const fetchPage = async (cursor?: string) => {\n const response = await client.listSnapshots({\n ...credentials,\n ...params,\n ...(cursor !== undefined && { cursor }),\n });\n return response.json;\n };\n const firstPage = await fetchPage(params?.cursor);\n return attachPaginator(firstPage, {\n itemsKey: \"snapshots\",\n fetchNext: fetchPage,\n signal: params?.signal,\n });\n }\n\n /**\n * Resolve the current snapshot ID of an existing sandbox by name.\n *\n * Useful to feed into {@link Sandbox.create} as `source.snapshotId` without\n * having to first look up the sandbox yourself.\n *\n * @param name - The name of the source sandbox.\n * @param opts - Optional credentials, fetch override, and abort signal.\n * @returns The current snapshot ID of the named sandbox.\n * @throws If the sandbox has no current snapshot.\n *\n * @example\n * const sandbox = await Sandbox.create({\n * source: {\n * type: \"snapshot\",\n * snapshotId: await Snapshot.fromSandbox(\"my-sandbox\"),\n * },\n * });\n */\n static async fromSandbox(\n name: string,\n opts?: Partial<Credentials> & WithFetchOptions & { signal?: AbortSignal },\n ): Promise<string> {\n \"use step\";\n const credentials = await getCredentials(opts);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: opts?.fetch,\n });\n\n const response = await client.getSandbox({\n name,\n projectId: credentials.projectId,\n resume: false,\n signal: opts?.signal,\n });\n\n const snapshotId = response.json.sandbox.currentSnapshotId;\n if (!snapshotId) {\n throw new Error(`Sandbox \"${name}\" has no current snapshot.`);\n }\n return snapshotId;\n }\n\n /**\n * Retrieve an existing snapshot.\n *\n * @param params - Get parameters and optional credentials.\n * @returns A promise resolving to the {@link Sandbox}.\n */\n static async get(\n params: GetSnapshotParams | (GetSnapshotParams & Credentials),\n ): Promise<Snapshot> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n\n const sandbox = await client.getSnapshot({\n snapshotId: params.snapshotId,\n signal: params.signal,\n });\n\n return new Snapshot({\n client,\n snapshot: sandbox.json.snapshot,\n });\n }\n\n /**\n * Delete this snapshot.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves once the snapshot has been deleted.\n */\n async delete(opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n const response = await client.deleteSnapshot({\n snapshotId: this.snapshot.id,\n signal: opts?.signal,\n });\n\n this.snapshot = response.json.snapshot;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA6BA,IAAa,WAAb,MAAa,SAAS;;;;;;;CASpB,MAAc,eAAmC;AAC/C;AACA,MAAI,KAAK,QAAS,QAAO,KAAK;EAC9B,MAAM,cAAc,MAAM,gBAAgB;AAC1C,OAAK,UAAU,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AACF,SAAO,KAAK;;;;;CAMd,IAAW,aAAqB;AAC9B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,kBAA0B;AACnC,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,SAAqC;AAC9C,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,YAAoB;AAC7B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,YAAkB;AAC3B,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;;;;CAM1C,IAAW,YAA8B;AACvC,MAAI,KAAK,SAAS,cAAc,OAC9B;AAGF,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;;;;;;;CAc1C,QAAQ,oBAAoB,UAAwC;AAClE,SAAO,EACL,UAAU,SAAS,UACpB;;;;;;;;;;;CAYH,QAAQ,sBAAsB,MAAoC;AAChE,SAAO,IAAI,SAAS,EAClB,UAAU,KAAK,UAChB,CAAC;;CAGJ,YAAY,EACV,QACA,YAIC;OAvGK,UAA4B;AAwGlC,OAAK,UAAU,UAAU;AACzB,OAAK,WAAW;;;;;;;;;;;;;;;;CAiBlB,aAAa,KACX,QAGA;AACA;EACA,MAAM,cAAc,MAAM,eAAe,OAAO;EAChD,MAAM,SAAS,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACnB,OAAO,QAAQ;GAChB,CAAC;EACF,MAAM,YAAY,OAAO,WAAoB;AAM3C,WALiB,MAAM,OAAO,cAAc;IAC1C,GAAG;IACH,GAAG;IACH,GAAI,WAAW,UAAa,EAAE,QAAQ;IACvC,CAAC,EACc;;AAGlB,SAAO,gBADW,MAAM,UAAU,QAAQ,OAAO,EACf;GAChC,UAAU;GACV,WAAW;GACX,QAAQ,QAAQ;GACjB,CAAC;;;;;;;;;;;;;;;;;;;;;CAsBJ,aAAa,YACX,MACA,MACiB;AACjB;EACA,MAAM,cAAc,MAAM,eAAe,KAAK;EAc9C,MAAM,cAPW,MANF,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACnB,OAAO,MAAM;GACd,CAAC,CAE4B,WAAW;GACvC;GACA,WAAW,YAAY;GACvB,QAAQ;GACR,QAAQ,MAAM;GACf,CAAC,EAE0B,KAAK,QAAQ;AACzC,MAAI,CAAC,WACH,OAAM,IAAI,MAAM,YAAY,KAAK,4BAA4B;AAE/D,SAAO;;;;;;;;CAST,aAAa,IACX,QACmB;AACnB;EACA,MAAM,cAAc,MAAM,eAAe,OAAO;EAChD,MAAM,SAAS,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AAOF,SAAO,IAAI,SAAS;GAClB;GACA,WAPc,MAAM,OAAO,YAAY;IACvC,YAAY,OAAO;IACnB,QAAQ,OAAO;IAChB,CAAC,EAIkB,KAAK;GACxB,CAAC;;;;;;;;;CAUJ,MAAM,OAAO,MAAgD;AAC3D;AAOA,OAAK,YALY,OADF,MAAM,KAAK,cAAc,EACV,eAAe;GAC3C,YAAY,KAAK,SAAS;GAC1B,QAAQ,MAAM;GACf,CAAC,EAEuB,KAAK"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/array.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array from the given item. If the item is an array it will be
|
|
5
|
+
* returned as a it is, otherwise it will be returned as a single item array.
|
|
6
|
+
* If the item is undefined or null an empty array will be returned.
|
|
7
|
+
*
|
|
8
|
+
* @param item The item to convert to an array.
|
|
9
|
+
* @returns An array.
|
|
10
|
+
*/
|
|
11
|
+
function array(item) {
|
|
12
|
+
return item !== void 0 && item !== null ? Array.isArray(item) ? item : [item] : [];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.array = array;
|
|
17
|
+
//# sourceMappingURL=array.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.cjs","names":[],"sources":["../../src/utils/array.ts"],"sourcesContent":["/**\n * Returns an array from the given item. If the item is an array it will be\n * returned as a it is, otherwise it will be returned as a single item array.\n * If the item is undefined or null an empty array will be returned.\n *\n * @param item The item to convert to an array.\n * @returns An array.\n */\nexport function array<T>(item?: null | T | T[]): T[] {\n return item !== undefined && item !== null\n ? Array.isArray(item)\n ? item\n : [item]\n : [];\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,MAAS,MAA4B;AACnD,QAAO,SAAS,UAAa,SAAS,OAClC,MAAM,QAAQ,KAAK,GACjB,OACA,CAAC,KAAK,GACR,EAAE"}
|