@vercel/sandbox 0.0.17 → 0.0.19

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @vercel/sandbox@0.0.17 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.19 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
3
3
  > tsc
4
4
 
@@ -1,4 +1,4 @@
1
1
 
2
- > @vercel/sandbox@0.0.17 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.19 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
3
3
  > tsc --noEmit
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @vercel/sandbox
2
2
 
3
+ ## 0.0.19
4
+
5
+ ### Patch Changes
6
+
7
+ - https://github.com/vercel/sandbox-sdk/pull/104/files introduced `Sandbox.list` ([#119](https://github.com/vercel/sandbox-sdk/pull/119))
8
+
9
+ - support interrupting the log consuming ([#123](https://github.com/vercel/sandbox-sdk/pull/123))
10
+
11
+ - using [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) with `cmd.logs({ signal })`
12
+ - using [`Disposable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using) with `using logs = cmd.logs()`
13
+
14
+ ## 0.0.18
15
+
16
+ ### Patch Changes
17
+
18
+ - refresh oidc token if stale in development ([#106](https://github.com/vercel/sandbox-sdk/pull/106))
19
+
3
20
  ## 0.0.17
4
21
 
5
22
  ### Patch Changes
@@ -2,13 +2,16 @@ import { BaseClient, type Parsed, type RequestParams } from "./base-client";
2
2
  import { SandboxResponse, CommandResponse, CommandFinishedResponse, LogLine } from "./validators";
3
3
  import { FileWriter } from "./file-writer";
4
4
  import { z } from "zod";
5
+ import { WithPrivate } from "../utils/types";
5
6
  export declare class APIClient extends BaseClient {
6
7
  private teamId;
8
+ private tokenExpiry;
7
9
  constructor(params: {
8
10
  host?: string;
9
11
  teamId: string;
10
12
  token: string;
11
13
  });
14
+ private ensureValidToken;
12
15
  protected request(path: string, params?: RequestParams): Promise<Response>;
13
16
  getSandbox(params: {
14
17
  sandboxId: string;
@@ -36,7 +39,7 @@ export declare class APIClient extends BaseClient {
36
39
  port: number;
37
40
  }[];
38
41
  }>>;
39
- createSandbox(params: {
42
+ createSandbox(params: WithPrivate<{
40
43
  ports?: number[];
41
44
  projectId: string;
42
45
  source?: {
@@ -55,7 +58,7 @@ export declare class APIClient extends BaseClient {
55
58
  vcpus: number;
56
59
  };
57
60
  runtime?: "node22" | "python3.13" | (string & {});
58
- }): Promise<Parsed<{
61
+ }>): Promise<Parsed<{
59
62
  sandbox: {
60
63
  region: string;
61
64
  status: "pending" | "running" | "stopping" | "stopped" | "failed";
@@ -119,6 +122,51 @@ export declare class APIClient extends BaseClient {
119
122
  response: Promise<Response>;
120
123
  writer: FileWriter;
121
124
  };
125
+ listSandboxes(params: {
126
+ /**
127
+ * The ID or name of the project to which the sandboxes belong.
128
+ * @example "my-project"
129
+ */
130
+ projectId: string;
131
+ /**
132
+ * Maximum number of sandboxes to list from a request.
133
+ * @example 10
134
+ */
135
+ limit?: number;
136
+ /**
137
+ * Get sandboxes created after this JavaScript timestamp.
138
+ * @example 1540095775941
139
+ */
140
+ since?: number | Date;
141
+ /**
142
+ * Get sandboxes created before this JavaScript timestamp.
143
+ * @example 1540095775951
144
+ */
145
+ until?: number | Date;
146
+ }): Promise<Parsed<{
147
+ sandboxes: {
148
+ region: string;
149
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
150
+ id: string;
151
+ memory: number;
152
+ vcpus: number;
153
+ runtime: string;
154
+ timeout: number;
155
+ requestedAt: number;
156
+ createdAt: number;
157
+ cwd: string;
158
+ updatedAt: number;
159
+ duration?: number | undefined;
160
+ startedAt?: number | undefined;
161
+ requestedStopAt?: number | undefined;
162
+ stoppedAt?: number | undefined;
163
+ }[];
164
+ pagination: {
165
+ count: number;
166
+ next: number | null;
167
+ prev: number | null;
168
+ };
169
+ }>>;
122
170
  writeFiles(params: {
123
171
  sandboxId: string;
124
172
  cwd: string;
@@ -151,7 +199,10 @@ export declare class APIClient extends BaseClient {
151
199
  getLogs(params: {
152
200
  sandboxId: string;
153
201
  cmdId: string;
154
- }): AsyncIterable<z.infer<typeof LogLine>>;
202
+ signal?: AbortSignal;
203
+ }): AsyncGenerator<z.infer<typeof LogLine>, void, void> & Disposable & {
204
+ close(): void;
205
+ };
155
206
  stopSandbox(params: {
156
207
  sandboxId: string;
157
208
  }): Promise<Parsed<z.infer<typeof SandboxResponse>>>;
@@ -14,6 +14,8 @@ const jsonlines_1 = __importDefault(require("jsonlines"));
14
14
  const os_1 = __importDefault(require("os"));
15
15
  const stream_1 = require("stream");
16
16
  const normalizePath_1 = require("../utils/normalizePath");
17
+ const jwt_expiry_1 = require("../utils/jwt-expiry");
18
+ const types_1 = require("../utils/types");
17
19
  class APIClient extends base_client_1.BaseClient {
18
20
  constructor(params) {
19
21
  super({
@@ -22,8 +24,24 @@ class APIClient extends base_client_1.BaseClient {
22
24
  debug: false,
23
25
  });
24
26
  this.teamId = params.teamId;
27
+ this.tokenExpiry = jwt_expiry_1.JwtExpiry.fromToken(params.token);
28
+ }
29
+ async ensureValidToken() {
30
+ if (!this.tokenExpiry) {
31
+ return;
32
+ }
33
+ const newExpiry = await this.tokenExpiry.tryRefresh();
34
+ if (!newExpiry) {
35
+ return;
36
+ }
37
+ this.tokenExpiry = newExpiry;
38
+ this.token = this.tokenExpiry.token;
39
+ if (this.tokenExpiry.payload) {
40
+ this.teamId = this.tokenExpiry.payload?.owner_id;
41
+ }
25
42
  }
26
43
  async request(path, params) {
44
+ await this.ensureValidToken();
27
45
  return super.request(path, {
28
46
  ...params,
29
47
  query: { teamId: this.teamId, ...params?.query },
@@ -38,6 +56,7 @@ class APIClient extends base_client_1.BaseClient {
38
56
  return (0, base_client_1.parseOrThrow)(validators_1.SandboxAndRoutesResponse, await this.request(`/v1/sandboxes/${params.sandboxId}`));
39
57
  }
40
58
  async createSandbox(params) {
59
+ const privateParams = (0, types_1.getPrivateParams)(params);
41
60
  return (0, base_client_1.parseOrThrow)(validators_1.SandboxAndRoutesResponse, await this.request("/v1/sandboxes", {
42
61
  method: "POST",
43
62
  body: JSON.stringify({
@@ -47,6 +66,7 @@ class APIClient extends base_client_1.BaseClient {
47
66
  timeout: params.timeout,
48
67
  resources: params.resources,
49
68
  runtime: params.runtime,
69
+ ...privateParams,
50
70
  }),
51
71
  }));
52
72
  }
@@ -89,6 +109,21 @@ class APIClient extends base_client_1.BaseClient {
89
109
  writer,
90
110
  };
91
111
  }
112
+ async listSandboxes(params) {
113
+ return (0, base_client_1.parseOrThrow)(validators_1.SandboxesResponse, await this.request(`/v1/sandboxes`, {
114
+ query: {
115
+ project: params.projectId,
116
+ limit: params.limit,
117
+ since: typeof params.since === "number"
118
+ ? params.since
119
+ : params.since?.getTime(),
120
+ until: typeof params.until === "number"
121
+ ? params.until
122
+ : params.until?.getTime(),
123
+ },
124
+ method: "GET",
125
+ }));
126
+ }
92
127
  async writeFiles(params) {
93
128
  const { writer, response } = this.getFileWriter({
94
129
  sandboxId: params.sandboxId,
@@ -126,22 +161,42 @@ class APIClient extends base_client_1.BaseClient {
126
161
  body: JSON.stringify({ signal: params.signal }),
127
162
  }));
128
163
  }
129
- async *getLogs(params) {
130
- const url = `/v1/sandboxes/${params.sandboxId}/cmd/${params.cmdId}/logs`;
131
- const response = await this.request(url, { method: "GET" });
132
- if (response.headers.get("content-type") !== "application/x-ndjson") {
133
- throw new api_error_1.APIError(response, {
134
- message: "Expected a stream of logs",
164
+ getLogs(params) {
165
+ const self = this;
166
+ const disposer = new AbortController();
167
+ const signal = !params.signal
168
+ ? disposer.signal
169
+ : mergeSignals(params.signal, disposer.signal);
170
+ const generator = (async function* () {
171
+ const url = `/v1/sandboxes/${params.sandboxId}/cmd/${params.cmdId}/logs`;
172
+ const response = await self.request(url, {
173
+ method: "GET",
174
+ signal,
135
175
  });
136
- }
137
- if (response.body === null) {
138
- throw new api_error_1.APIError(response, {
139
- message: "No response body",
176
+ if (response.headers.get("content-type") !== "application/x-ndjson") {
177
+ throw new api_error_1.APIError(response, {
178
+ message: "Expected a stream of logs",
179
+ });
180
+ }
181
+ if (response.body === null) {
182
+ throw new api_error_1.APIError(response, {
183
+ message: "No response body",
184
+ });
185
+ }
186
+ const jsonlinesStream = jsonlines_1.default.parse();
187
+ pipe(response.body, jsonlinesStream).catch((err) => {
188
+ console.error("Error piping logs:", err);
140
189
  });
141
- }
142
- for await (const chunk of stream_1.Readable.fromWeb(response.body).pipe(jsonlines_1.default.parse())) {
143
- yield validators_1.LogLine.parse(chunk);
144
- }
190
+ for await (const chunk of jsonlinesStream) {
191
+ yield validators_1.LogLine.parse(chunk);
192
+ }
193
+ })();
194
+ return Object.assign(generator, {
195
+ [Symbol.dispose]() {
196
+ disposer.abort("Disposed");
197
+ },
198
+ close: () => disposer.abort("Disposed"),
199
+ });
145
200
  }
146
201
  async stopSandbox(params) {
147
202
  const url = `/v1/sandboxes/${params.sandboxId}/stop`;
@@ -149,3 +204,40 @@ class APIClient extends base_client_1.BaseClient {
149
204
  }
150
205
  }
151
206
  exports.APIClient = APIClient;
207
+ async function pipe(readable, output) {
208
+ const reader = readable.getReader();
209
+ try {
210
+ while (true) {
211
+ const read = await reader.read();
212
+ if (read.value) {
213
+ output.write(Buffer.from(read.value));
214
+ }
215
+ if (read.done) {
216
+ break;
217
+ }
218
+ }
219
+ }
220
+ catch (err) {
221
+ output.emit("error", err);
222
+ }
223
+ finally {
224
+ output.end();
225
+ }
226
+ }
227
+ function mergeSignals(...signals) {
228
+ const controller = new AbortController();
229
+ const onAbort = () => {
230
+ controller.abort();
231
+ for (const signal of signals) {
232
+ signal.removeEventListener("abort", onAbort);
233
+ }
234
+ };
235
+ for (const signal of signals) {
236
+ if (signal.aborted) {
237
+ controller.abort();
238
+ break;
239
+ }
240
+ signal.addEventListener("abort", onAbort);
241
+ }
242
+ return controller.signal;
243
+ }
@@ -63,6 +63,31 @@ export declare const SandboxRoute: z.ZodObject<{
63
63
  subdomain: string;
64
64
  port: number;
65
65
  }>;
66
+ export declare const Pagination: z.ZodObject<{
67
+ /**
68
+ * Amount of items in the current page.
69
+ * @example 20
70
+ */
71
+ count: z.ZodNumber;
72
+ /**
73
+ * Timestamp that must be used to request the next page.
74
+ * @example 1540095775951
75
+ */
76
+ next: z.ZodNullable<z.ZodNumber>;
77
+ /**
78
+ * Timestamp that must be used to request the previous page.
79
+ * @example 1540095775951
80
+ */
81
+ prev: z.ZodNullable<z.ZodNumber>;
82
+ }, "strip", z.ZodTypeAny, {
83
+ count: number;
84
+ next: number | null;
85
+ prev: number | null;
86
+ }, {
87
+ count: number;
88
+ next: number | null;
89
+ prev: number | null;
90
+ }>;
66
91
  export type CommandData = z.infer<typeof Command>;
67
92
  export declare const Command: z.ZodObject<{
68
93
  id: z.ZodString;
@@ -393,3 +418,125 @@ export declare const LogLine: z.ZodObject<{
393
418
  stream: "stdout" | "stderr";
394
419
  data: string;
395
420
  }>;
421
+ export declare const SandboxesResponse: z.ZodObject<{
422
+ sandboxes: z.ZodArray<z.ZodObject<{
423
+ id: z.ZodString;
424
+ memory: z.ZodNumber;
425
+ vcpus: z.ZodNumber;
426
+ region: z.ZodString;
427
+ runtime: z.ZodString;
428
+ timeout: z.ZodNumber;
429
+ status: z.ZodEnum<["pending", "running", "stopping", "stopped", "failed"]>;
430
+ requestedAt: z.ZodNumber;
431
+ startedAt: z.ZodOptional<z.ZodNumber>;
432
+ requestedStopAt: z.ZodOptional<z.ZodNumber>;
433
+ stoppedAt: z.ZodOptional<z.ZodNumber>;
434
+ duration: z.ZodOptional<z.ZodNumber>;
435
+ createdAt: z.ZodNumber;
436
+ cwd: z.ZodString;
437
+ updatedAt: z.ZodNumber;
438
+ }, "strip", z.ZodTypeAny, {
439
+ region: string;
440
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
441
+ id: string;
442
+ memory: number;
443
+ vcpus: number;
444
+ runtime: string;
445
+ timeout: number;
446
+ requestedAt: number;
447
+ createdAt: number;
448
+ cwd: string;
449
+ updatedAt: number;
450
+ duration?: number | undefined;
451
+ startedAt?: number | undefined;
452
+ requestedStopAt?: number | undefined;
453
+ stoppedAt?: number | undefined;
454
+ }, {
455
+ region: string;
456
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
457
+ id: string;
458
+ memory: number;
459
+ vcpus: number;
460
+ runtime: string;
461
+ timeout: number;
462
+ requestedAt: number;
463
+ createdAt: number;
464
+ cwd: string;
465
+ updatedAt: number;
466
+ duration?: number | undefined;
467
+ startedAt?: number | undefined;
468
+ requestedStopAt?: number | undefined;
469
+ stoppedAt?: number | undefined;
470
+ }>, "many">;
471
+ pagination: z.ZodObject<{
472
+ /**
473
+ * Amount of items in the current page.
474
+ * @example 20
475
+ */
476
+ count: z.ZodNumber;
477
+ /**
478
+ * Timestamp that must be used to request the next page.
479
+ * @example 1540095775951
480
+ */
481
+ next: z.ZodNullable<z.ZodNumber>;
482
+ /**
483
+ * Timestamp that must be used to request the previous page.
484
+ * @example 1540095775951
485
+ */
486
+ prev: z.ZodNullable<z.ZodNumber>;
487
+ }, "strip", z.ZodTypeAny, {
488
+ count: number;
489
+ next: number | null;
490
+ prev: number | null;
491
+ }, {
492
+ count: number;
493
+ next: number | null;
494
+ prev: number | null;
495
+ }>;
496
+ }, "strip", z.ZodTypeAny, {
497
+ sandboxes: {
498
+ region: string;
499
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
500
+ id: string;
501
+ memory: number;
502
+ vcpus: number;
503
+ runtime: string;
504
+ timeout: number;
505
+ requestedAt: number;
506
+ createdAt: number;
507
+ cwd: string;
508
+ updatedAt: number;
509
+ duration?: number | undefined;
510
+ startedAt?: number | undefined;
511
+ requestedStopAt?: number | undefined;
512
+ stoppedAt?: number | undefined;
513
+ }[];
514
+ pagination: {
515
+ count: number;
516
+ next: number | null;
517
+ prev: number | null;
518
+ };
519
+ }, {
520
+ sandboxes: {
521
+ region: string;
522
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
523
+ id: string;
524
+ memory: number;
525
+ vcpus: number;
526
+ runtime: string;
527
+ timeout: number;
528
+ requestedAt: number;
529
+ createdAt: number;
530
+ cwd: string;
531
+ updatedAt: number;
532
+ duration?: number | undefined;
533
+ startedAt?: number | undefined;
534
+ requestedStopAt?: number | undefined;
535
+ stoppedAt?: number | undefined;
536
+ }[];
537
+ pagination: {
538
+ count: number;
539
+ next: number | null;
540
+ prev: number | null;
541
+ };
542
+ }>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LogLine = exports.EmptyResponse = exports.CommandFinishedResponse = exports.CommandResponse = exports.SandboxAndRoutesResponse = exports.SandboxResponse = exports.Command = exports.SandboxRoute = exports.Sandbox = void 0;
3
+ exports.SandboxesResponse = exports.LogLine = exports.EmptyResponse = exports.CommandFinishedResponse = exports.CommandResponse = exports.SandboxAndRoutesResponse = exports.SandboxResponse = exports.Command = exports.Pagination = exports.SandboxRoute = exports.Sandbox = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.Sandbox = zod_1.z.object({
6
6
  id: zod_1.z.string(),
@@ -24,6 +24,23 @@ exports.SandboxRoute = zod_1.z.object({
24
24
  subdomain: zod_1.z.string(),
25
25
  port: zod_1.z.number(),
26
26
  });
27
+ exports.Pagination = zod_1.z.object({
28
+ /**
29
+ * Amount of items in the current page.
30
+ * @example 20
31
+ */
32
+ count: zod_1.z.number(),
33
+ /**
34
+ * Timestamp that must be used to request the next page.
35
+ * @example 1540095775951
36
+ */
37
+ next: zod_1.z.number().nullable(),
38
+ /**
39
+ * Timestamp that must be used to request the previous page.
40
+ * @example 1540095775951
41
+ */
42
+ prev: zod_1.z.number().nullable(),
43
+ });
27
44
  exports.Command = zod_1.z.object({
28
45
  id: zod_1.z.string(),
29
46
  name: zod_1.z.string(),
@@ -53,3 +70,7 @@ exports.LogLine = zod_1.z.object({
53
70
  stream: zod_1.z.enum(["stdout", "stderr"]),
54
71
  data: zod_1.z.string(),
55
72
  });
73
+ exports.SandboxesResponse = zod_1.z.object({
74
+ sandboxes: zod_1.z.array(exports.Sandbox),
75
+ pagination: exports.Pagination,
76
+ });
package/dist/command.d.ts CHANGED
@@ -58,15 +58,21 @@ export declare class Command {
58
58
  * }
59
59
  * ```
60
60
  *
61
+ * @param opts - Optional parameters.
62
+ * @param opts.signal - An AbortSignal to cancel log streaming.
61
63
  * @returns An async iterable of log entries from the command output.
62
64
  *
63
65
  * @see {@link Command.stdout}, {@link Command.stderr}, and {@link Command.output}
64
66
  * to access output as a string.
65
67
  */
66
- logs(): AsyncIterable<{
68
+ logs(opts?: {
69
+ signal?: AbortSignal;
70
+ }): AsyncGenerator<{
67
71
  stream: "stdout" | "stderr";
68
72
  data: string;
69
- }>;
73
+ }, void, void> & Disposable & {
74
+ close(): void;
75
+ };
70
76
  /**
71
77
  * Wait for a command to exit and populate its exit code.
72
78
  *
package/dist/command.js CHANGED
@@ -53,15 +53,18 @@ class Command {
53
53
  * }
54
54
  * ```
55
55
  *
56
+ * @param opts - Optional parameters.
57
+ * @param opts.signal - An AbortSignal to cancel log streaming.
56
58
  * @returns An async iterable of log entries from the command output.
57
59
  *
58
60
  * @see {@link Command.stdout}, {@link Command.stderr}, and {@link Command.output}
59
61
  * to access output as a string.
60
62
  */
61
- logs() {
63
+ logs(opts) {
62
64
  return this.client.getLogs({
63
65
  sandboxId: this.sandboxId,
64
66
  cmdId: this.cmd.id,
67
+ signal: opts?.signal,
65
68
  });
66
69
  }
67
70
  /**
package/dist/sandbox.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { Writable } from "stream";
3
3
  import { APIClient } from "./api-client";
4
4
  import { Command, type CommandFinished } from "./command";
5
5
  import { type Credentials } from "./utils/get-credentials";
6
+ import { WithPrivate } from "./utils/types";
6
7
  /** @inline */
7
8
  export interface CreateSandboxParams {
8
9
  /**
@@ -121,13 +122,42 @@ export declare class Sandbox {
121
122
  * Internal metadata about this sandbox.
122
123
  */
123
124
  private readonly sandbox;
125
+ /**
126
+ * Allow to get a list of sandboxes for a team narrowed to the given params.
127
+ * It returns both the sandboxes and the pagination metadata to allow getting
128
+ * the next page of results.
129
+ */
130
+ static list(params: Parameters<APIClient["listSandboxes"]>[0] & Partial<Credentials>): Promise<import("./api-client/base-client").Parsed<{
131
+ sandboxes: {
132
+ region: string;
133
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
134
+ id: string;
135
+ memory: number;
136
+ vcpus: number;
137
+ runtime: string;
138
+ timeout: number;
139
+ requestedAt: number;
140
+ createdAt: number;
141
+ cwd: string;
142
+ updatedAt: number;
143
+ duration?: number | undefined;
144
+ startedAt?: number | undefined;
145
+ requestedStopAt?: number | undefined;
146
+ stoppedAt?: number | undefined;
147
+ }[];
148
+ pagination: {
149
+ count: number;
150
+ next: number | null;
151
+ prev: number | null;
152
+ };
153
+ }>>;
124
154
  /**
125
155
  * Create a new sandbox.
126
156
  *
127
157
  * @param params - Creation parameters and optional credentials.
128
158
  * @returns A promise resolving to the created {@link Sandbox}.
129
159
  */
130
- static create(params?: CreateSandboxParams | (CreateSandboxParams & Credentials)): Promise<Sandbox>;
160
+ static create(params?: WithPrivate<CreateSandboxParams | (CreateSandboxParams & Credentials)>): Promise<Sandbox>;
131
161
  /**
132
162
  * Retrieve an existing sandbox.
133
163
  *
package/dist/sandbox.js CHANGED
@@ -4,6 +4,7 @@ exports.Sandbox = void 0;
4
4
  const api_client_1 = require("./api-client");
5
5
  const command_1 = require("./command");
6
6
  const get_credentials_1 = require("./utils/get-credentials");
7
+ const types_1 = require("./utils/types");
7
8
  /**
8
9
  * A Sandbox is an isolated Linux MicroVM to run commands in.
9
10
  *
@@ -23,6 +24,19 @@ class Sandbox {
23
24
  get status() {
24
25
  return this.sandbox.status;
25
26
  }
27
+ /**
28
+ * Allow to get a list of sandboxes for a team narrowed to the given params.
29
+ * It returns both the sandboxes and the pagination metadata to allow getting
30
+ * the next page of results.
31
+ */
32
+ static async list(params) {
33
+ const credentials = await (0, get_credentials_1.getCredentials)(params);
34
+ const client = new api_client_1.APIClient({
35
+ teamId: credentials.teamId,
36
+ token: credentials.token,
37
+ });
38
+ return client.listSandboxes(params);
39
+ }
26
40
  /**
27
41
  * Create a new sandbox.
28
42
  *
@@ -30,11 +44,12 @@ class Sandbox {
30
44
  * @returns A promise resolving to the created {@link Sandbox}.
31
45
  */
32
46
  static async create(params) {
33
- const credentials = (0, get_credentials_1.getCredentials)(params);
47
+ const credentials = await (0, get_credentials_1.getCredentials)(params);
34
48
  const client = new api_client_1.APIClient({
35
49
  teamId: credentials.teamId,
36
50
  token: credentials.token,
37
51
  });
52
+ const privateParams = (0, types_1.getPrivateParams)(params);
38
53
  const sandbox = await client.createSandbox({
39
54
  source: params?.source,
40
55
  projectId: credentials.projectId,
@@ -42,6 +57,7 @@ class Sandbox {
42
57
  timeout: params?.timeout,
43
58
  resources: params?.resources,
44
59
  runtime: params?.runtime,
60
+ ...privateParams,
45
61
  });
46
62
  return new Sandbox({
47
63
  client,
@@ -56,7 +72,7 @@ class Sandbox {
56
72
  * @returns A promise resolving to the {@link Sandbox}.
57
73
  */
58
74
  static async get(params) {
59
- const credentials = (0, get_credentials_1.getCredentials)(params);
75
+ const credentials = await (0, get_credentials_1.getCredentials)(params);
60
76
  const client = new api_client_1.APIClient({
61
77
  teamId: credentials.teamId,
62
78
  token: credentials.token,
@@ -1,3 +1,4 @@
1
+ import { z } from "zod";
1
2
  export interface Credentials {
2
3
  /**
3
4
  * Authentication token for the Vercel API. It could be an OIDC token
@@ -23,4 +24,24 @@ export interface Credentials {
23
24
  * If both methods are used, the object properties take precedence over the
24
25
  * environment variable. If neither method is used, an error is thrown.
25
26
  */
26
- export declare function getCredentials<T>(params?: T | Credentials): Credentials;
27
+ export declare function getCredentials(params?: unknown): Promise<Credentials>;
28
+ /**
29
+ * Schema to validate the payload of the Vercel OIDC token where we expect
30
+ * to find the `teamId` and `projectId`.
31
+ */
32
+ export declare const schema: z.ZodObject<{
33
+ exp: z.ZodOptional<z.ZodNumber>;
34
+ iat: z.ZodOptional<z.ZodNumber>;
35
+ owner_id: z.ZodString;
36
+ project_id: z.ZodString;
37
+ }, "strip", z.ZodTypeAny, {
38
+ owner_id: string;
39
+ project_id: string;
40
+ exp?: number | undefined;
41
+ iat?: number | undefined;
42
+ }, {
43
+ owner_id: string;
44
+ project_id: string;
45
+ exp?: number | undefined;
46
+ iat?: number | undefined;
47
+ }>;