@vercel/sandbox 0.0.22 → 0.0.23

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.22 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.23 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.22 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.23 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
3
3
  > tsc --noEmit
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vercel/sandbox
2
2
 
3
+ ## 0.0.23
4
+
5
+ ### Patch Changes
6
+
7
+ - Add `Sandbox.extendTimeout()` ([#148](https://github.com/vercel/sandbox-sdk/pull/148))
8
+
3
9
  ## 0.0.22
4
10
 
5
11
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { BaseClient, type Parsed, type RequestParams } from "./base-client";
2
- import { SandboxResponse, CommandResponse, CommandFinishedResponse, LogLine } from "./validators";
2
+ import { SandboxResponse, CommandResponse, CommandFinishedResponse, LogLine, ExtendTimeoutResponse } from "./validators";
3
3
  import { FileWriter } from "./file-writer";
4
4
  import { z } from "zod";
5
5
  import { WithPrivate } from "../utils/types";
@@ -218,4 +218,9 @@ export declare class APIClient extends BaseClient {
218
218
  sandboxId: string;
219
219
  signal?: AbortSignal;
220
220
  }): Promise<Parsed<z.infer<typeof SandboxResponse>>>;
221
+ extendTimeout(params: {
222
+ sandboxId: string;
223
+ duration: number;
224
+ signal?: AbortSignal;
225
+ }): Promise<Parsed<z.infer<typeof ExtendTimeoutResponse>>>;
221
226
  }
@@ -212,6 +212,14 @@ class APIClient extends base_client_1.BaseClient {
212
212
  const url = `/v1/sandboxes/${params.sandboxId}/stop`;
213
213
  return (0, base_client_1.parseOrThrow)(validators_1.SandboxResponse, await this.request(url, { method: "POST", signal: params.signal }));
214
214
  }
215
+ async extendTimeout(params) {
216
+ const url = `/v1/sandboxes/${params.sandboxId}/extend-timeout`;
217
+ return (0, base_client_1.parseOrThrow)(validators_1.ExtendTimeoutResponse, await this.request(url, {
218
+ method: "POST",
219
+ body: JSON.stringify({ duration: params.duration }),
220
+ signal: params.signal,
221
+ }));
222
+ }
215
223
  }
216
224
  exports.APIClient = APIClient;
217
225
  async function pipe(readable, output) {
@@ -540,3 +540,90 @@ export declare const SandboxesResponse: z.ZodObject<{
540
540
  prev: number | null;
541
541
  };
542
542
  }>;
543
+ export declare const ExtendTimeoutResponse: z.ZodObject<{
544
+ sandbox: z.ZodObject<{
545
+ id: z.ZodString;
546
+ memory: z.ZodNumber;
547
+ vcpus: z.ZodNumber;
548
+ region: z.ZodString;
549
+ runtime: z.ZodString;
550
+ timeout: z.ZodNumber;
551
+ status: z.ZodEnum<["pending", "running", "stopping", "stopped", "failed"]>;
552
+ requestedAt: z.ZodNumber;
553
+ startedAt: z.ZodOptional<z.ZodNumber>;
554
+ requestedStopAt: z.ZodOptional<z.ZodNumber>;
555
+ stoppedAt: z.ZodOptional<z.ZodNumber>;
556
+ duration: z.ZodOptional<z.ZodNumber>;
557
+ createdAt: z.ZodNumber;
558
+ cwd: z.ZodString;
559
+ updatedAt: z.ZodNumber;
560
+ }, "strip", z.ZodTypeAny, {
561
+ region: string;
562
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
563
+ timeout: number;
564
+ cwd: string;
565
+ id: string;
566
+ memory: number;
567
+ vcpus: number;
568
+ runtime: string;
569
+ requestedAt: number;
570
+ createdAt: number;
571
+ updatedAt: number;
572
+ duration?: number | undefined;
573
+ startedAt?: number | undefined;
574
+ requestedStopAt?: number | undefined;
575
+ stoppedAt?: number | undefined;
576
+ }, {
577
+ region: string;
578
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
579
+ timeout: number;
580
+ cwd: string;
581
+ id: string;
582
+ memory: number;
583
+ vcpus: number;
584
+ runtime: string;
585
+ requestedAt: number;
586
+ createdAt: number;
587
+ updatedAt: number;
588
+ duration?: number | undefined;
589
+ startedAt?: number | undefined;
590
+ requestedStopAt?: number | undefined;
591
+ stoppedAt?: number | undefined;
592
+ }>;
593
+ }, "strip", z.ZodTypeAny, {
594
+ sandbox: {
595
+ region: string;
596
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
597
+ timeout: number;
598
+ cwd: string;
599
+ id: string;
600
+ memory: number;
601
+ vcpus: number;
602
+ runtime: string;
603
+ requestedAt: number;
604
+ createdAt: number;
605
+ updatedAt: number;
606
+ duration?: number | undefined;
607
+ startedAt?: number | undefined;
608
+ requestedStopAt?: number | undefined;
609
+ stoppedAt?: number | undefined;
610
+ };
611
+ }, {
612
+ sandbox: {
613
+ region: string;
614
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
615
+ timeout: number;
616
+ cwd: string;
617
+ id: string;
618
+ memory: number;
619
+ vcpus: number;
620
+ runtime: string;
621
+ requestedAt: number;
622
+ createdAt: number;
623
+ updatedAt: number;
624
+ duration?: number | undefined;
625
+ startedAt?: number | undefined;
626
+ requestedStopAt?: number | undefined;
627
+ stoppedAt?: number | undefined;
628
+ };
629
+ }>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.ExtendTimeoutResponse = 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(),
@@ -74,3 +74,6 @@ exports.SandboxesResponse = zod_1.z.object({
74
74
  sandboxes: zod_1.z.array(exports.Sandbox),
75
75
  pagination: exports.Pagination,
76
76
  });
77
+ exports.ExtendTimeoutResponse = zod_1.z.object({
78
+ sandbox: exports.Sandbox,
79
+ });
package/dist/sandbox.d.ts CHANGED
@@ -130,10 +130,14 @@ export declare class Sandbox {
130
130
  * The status of the sandbox.
131
131
  */
132
132
  get status(): SandboxMetaData["status"];
133
+ /**
134
+ * The timeout of the sandbox in milliseconds.
135
+ */
136
+ get timeout(): number;
133
137
  /**
134
138
  * Internal metadata about this sandbox.
135
139
  */
136
- private readonly sandbox;
140
+ private sandbox;
137
141
  /**
138
142
  * Allow to get a list of sandboxes for a team narrowed to the given params.
139
143
  * It returns both the sandboxes and the pagination metadata to allow getting
@@ -294,5 +298,19 @@ export declare class Sandbox {
294
298
  stop(opts?: {
295
299
  signal?: AbortSignal;
296
300
  }): Promise<void>;
301
+ /**
302
+ * Extend the timeout of the sandbox by the specified duration.
303
+ *
304
+ * This allows you to extend the lifetime of a sandbox up until the maximum
305
+ * execution timeout for your plan.
306
+ *
307
+ * @param duration - The duration in milliseconds to extend the timeout by
308
+ * @param opts - Optional parameters.
309
+ * @param opts.signal - An AbortSignal to cancel the operation.
310
+ * @returns A promise that resolves when the timeout is extended
311
+ */
312
+ extendTimeout(duration: number, opts?: {
313
+ signal?: AbortSignal;
314
+ }): Promise<void>;
297
315
  }
298
316
  export {};
package/dist/sandbox.js CHANGED
@@ -24,6 +24,12 @@ class Sandbox {
24
24
  get status() {
25
25
  return this.sandbox.status;
26
26
  }
27
+ /**
28
+ * The timeout of the sandbox in milliseconds.
29
+ */
30
+ get timeout() {
31
+ return this.sandbox.timeout;
32
+ }
27
33
  /**
28
34
  * Allow to get a list of sandboxes for a team narrowed to the given params.
29
35
  * It returns both the sandboxes and the pagination metadata to allow getting
@@ -242,5 +248,25 @@ class Sandbox {
242
248
  signal: opts?.signal,
243
249
  });
244
250
  }
251
+ /**
252
+ * Extend the timeout of the sandbox by the specified duration.
253
+ *
254
+ * This allows you to extend the lifetime of a sandbox up until the maximum
255
+ * execution timeout for your plan.
256
+ *
257
+ * @param duration - The duration in milliseconds to extend the timeout by
258
+ * @param opts - Optional parameters.
259
+ * @param opts.signal - An AbortSignal to cancel the operation.
260
+ * @returns A promise that resolves when the timeout is extended
261
+ */
262
+ async extendTimeout(duration, opts) {
263
+ const response = await this.client.extendTimeout({
264
+ sandboxId: this.sandbox.id,
265
+ duration,
266
+ signal: opts?.signal,
267
+ });
268
+ // Update the internal sandbox metadata with the new timeout value
269
+ this.sandbox = response.json.sandbox;
270
+ }
245
271
  }
246
272
  exports.Sandbox = Sandbox;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.0.22";
1
+ export declare const VERSION = "0.0.23";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // Autogenerated by inject-version.ts
5
- exports.VERSION = "0.0.22";
5
+ exports.VERSION = "0.0.23";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/sandbox",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,6 +12,7 @@ import {
12
12
  EmptyResponse,
13
13
  LogLine,
14
14
  SandboxesResponse,
15
+ ExtendTimeoutResponse,
15
16
  } from "./validators";
16
17
  import { APIError } from "./api-error";
17
18
  import { FileWriter } from "./file-writer";
@@ -393,6 +394,22 @@ export class APIClient extends BaseClient {
393
394
  await this.request(url, { method: "POST", signal: params.signal }),
394
395
  );
395
396
  }
397
+
398
+ async extendTimeout(params: {
399
+ sandboxId: string;
400
+ duration: number;
401
+ signal?: AbortSignal;
402
+ }): Promise<Parsed<z.infer<typeof ExtendTimeoutResponse>>> {
403
+ const url = `/v1/sandboxes/${params.sandboxId}/extend-timeout`;
404
+ return parseOrThrow(
405
+ ExtendTimeoutResponse,
406
+ await this.request(url, {
407
+ method: "POST",
408
+ body: JSON.stringify({ duration: params.duration }),
409
+ signal: params.signal,
410
+ }),
411
+ );
412
+ }
396
413
  }
397
414
 
398
415
  async function pipe(
@@ -89,3 +89,7 @@ export const SandboxesResponse = z.object({
89
89
  sandboxes: z.array(Sandbox),
90
90
  pagination: Pagination,
91
91
  });
92
+
93
+ export const ExtendTimeoutResponse = z.object({
94
+ sandbox: Sandbox,
95
+ });
@@ -1,6 +1,8 @@
1
1
  import { it, beforeEach, afterEach, expect } from "vitest";
2
2
  import { consumeReadable } from "./utils/consume-readable";
3
3
  import { Sandbox } from "./sandbox";
4
+ import { APIError } from "./api-client/api-error";
5
+ import ms from "ms";
4
6
 
5
7
  const PORTS = [3000, 4000];
6
8
  let sandbox: Sandbox;
@@ -64,3 +66,26 @@ for (const port of ports) {
64
66
 
65
67
  await server.kill();
66
68
  });
69
+
70
+ it("allows extending the sandbox timeout", async () => {
71
+ const originalTimeout = sandbox.timeout;
72
+ const extensionDuration = ms("5m");
73
+
74
+ await sandbox.extendTimeout(extensionDuration);
75
+ expect(sandbox.timeout).toEqual(originalTimeout + extensionDuration);
76
+ });
77
+
78
+ it("raises an error when the timeout cannot be updated", async () => {
79
+ try {
80
+ await sandbox.extendTimeout(ms("5d"));
81
+ expect.fail("Expected extendTimeout to throw an error");
82
+ } catch (error) {
83
+ expect(error).toBeInstanceOf(APIError);
84
+ expect(error).toMatchObject({
85
+ response: { status: 400 },
86
+ json: {
87
+ error: { code: "sandbox_timeout_invalid" },
88
+ },
89
+ });
90
+ }
91
+ });
package/src/sandbox.ts CHANGED
@@ -142,10 +142,17 @@ export class Sandbox {
142
142
  return this.sandbox.status;
143
143
  }
144
144
 
145
+ /**
146
+ * The timeout of the sandbox in milliseconds.
147
+ */
148
+ public get timeout(): number {
149
+ return this.sandbox.timeout;
150
+ }
151
+
145
152
  /**
146
153
  * Internal metadata about this sandbox.
147
154
  */
148
- private readonly sandbox: SandboxMetaData;
155
+ private sandbox: SandboxMetaData;
149
156
 
150
157
  /**
151
158
  * Allow to get a list of sandboxes for a team narrowed to the given params.
@@ -444,4 +451,29 @@ export class Sandbox {
444
451
  signal: opts?.signal,
445
452
  });
446
453
  }
454
+
455
+ /**
456
+ * Extend the timeout of the sandbox by the specified duration.
457
+ *
458
+ * This allows you to extend the lifetime of a sandbox up until the maximum
459
+ * execution timeout for your plan.
460
+ *
461
+ * @param duration - The duration in milliseconds to extend the timeout by
462
+ * @param opts - Optional parameters.
463
+ * @param opts.signal - An AbortSignal to cancel the operation.
464
+ * @returns A promise that resolves when the timeout is extended
465
+ */
466
+ async extendTimeout(
467
+ duration: number,
468
+ opts?: { signal?: AbortSignal },
469
+ ): Promise<void> {
470
+ const response = await this.client.extendTimeout({
471
+ sandboxId: this.sandbox.id,
472
+ duration,
473
+ signal: opts?.signal,
474
+ });
475
+
476
+ // Update the internal sandbox metadata with the new timeout value
477
+ this.sandbox = response.json.sandbox;
478
+ }
447
479
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Autogenerated by inject-version.ts
2
- export const VERSION = "0.0.22";
2
+ export const VERSION = "0.0.23";