@vercel/sandbox 0.0.8 → 0.0.10

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,82 +1,375 @@
1
1
  import { z } from "zod";
2
- export declare const CreatedSandbox: z.ZodObject<{
2
+ export type SandboxData = z.infer<typeof Sandbox>;
3
+ export declare const Sandbox: z.ZodObject<{
4
+ id: z.ZodString;
5
+ memory: z.ZodNumber;
6
+ vcpus: z.ZodNumber;
7
+ region: z.ZodString;
8
+ runtime: z.ZodString;
9
+ timeout: z.ZodNumber;
10
+ status: z.ZodEnum<["pending", "running", "stopping", "stopped", "failed"]>;
11
+ requestedAt: z.ZodNumber;
12
+ startedAt: z.ZodOptional<z.ZodNumber>;
13
+ requestedStopAt: z.ZodOptional<z.ZodNumber>;
14
+ stoppedAt: z.ZodOptional<z.ZodNumber>;
15
+ duration: z.ZodOptional<z.ZodNumber>;
16
+ createdAt: z.ZodNumber;
17
+ updatedAt: z.ZodNumber;
18
+ }, "strip", z.ZodTypeAny, {
19
+ region: string;
20
+ timeout: number;
21
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
22
+ id: string;
23
+ memory: number;
24
+ vcpus: number;
25
+ runtime: string;
26
+ requestedAt: number;
27
+ createdAt: number;
28
+ updatedAt: number;
29
+ duration?: number | undefined;
30
+ startedAt?: number | undefined;
31
+ requestedStopAt?: number | undefined;
32
+ stoppedAt?: number | undefined;
33
+ }, {
34
+ region: string;
35
+ timeout: number;
36
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
37
+ id: string;
38
+ memory: number;
39
+ vcpus: number;
40
+ runtime: string;
41
+ requestedAt: number;
42
+ createdAt: number;
43
+ updatedAt: number;
44
+ duration?: number | undefined;
45
+ startedAt?: number | undefined;
46
+ requestedStopAt?: number | undefined;
47
+ stoppedAt?: number | undefined;
48
+ }>;
49
+ export type SandboxRouteData = z.infer<typeof SandboxRoute>;
50
+ export declare const SandboxRoute: z.ZodObject<{
51
+ url: z.ZodString;
52
+ subdomain: z.ZodString;
53
+ port: z.ZodNumber;
54
+ }, "strip", z.ZodTypeAny, {
55
+ port: number;
56
+ url: string;
57
+ subdomain: string;
58
+ }, {
59
+ port: number;
60
+ url: string;
61
+ subdomain: string;
62
+ }>;
63
+ export type CommandData = z.infer<typeof Command>;
64
+ export declare const Command: z.ZodObject<{
65
+ id: z.ZodString;
66
+ name: z.ZodString;
67
+ args: z.ZodArray<z.ZodString, "many">;
68
+ cwd: z.ZodString;
3
69
  sandboxId: z.ZodString;
70
+ exitCode: z.ZodNullable<z.ZodNumber>;
71
+ startedAt: z.ZodNumber;
72
+ }, "strip", z.ZodTypeAny, {
73
+ name: string;
74
+ cwd: string;
75
+ args: string[];
76
+ id: string;
77
+ startedAt: number;
78
+ sandboxId: string;
79
+ exitCode: number | null;
80
+ }, {
81
+ name: string;
82
+ cwd: string;
83
+ args: string[];
84
+ id: string;
85
+ startedAt: number;
86
+ sandboxId: string;
87
+ exitCode: number | null;
88
+ }>;
89
+ export declare const SandboxResponse: z.ZodObject<{
90
+ sandbox: z.ZodObject<{
91
+ id: z.ZodString;
92
+ memory: z.ZodNumber;
93
+ vcpus: z.ZodNumber;
94
+ region: z.ZodString;
95
+ runtime: z.ZodString;
96
+ timeout: z.ZodNumber;
97
+ status: z.ZodEnum<["pending", "running", "stopping", "stopped", "failed"]>;
98
+ requestedAt: z.ZodNumber;
99
+ startedAt: z.ZodOptional<z.ZodNumber>;
100
+ requestedStopAt: z.ZodOptional<z.ZodNumber>;
101
+ stoppedAt: z.ZodOptional<z.ZodNumber>;
102
+ duration: z.ZodOptional<z.ZodNumber>;
103
+ createdAt: z.ZodNumber;
104
+ updatedAt: z.ZodNumber;
105
+ }, "strip", z.ZodTypeAny, {
106
+ region: string;
107
+ timeout: number;
108
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
109
+ id: string;
110
+ memory: number;
111
+ vcpus: number;
112
+ runtime: string;
113
+ requestedAt: number;
114
+ createdAt: number;
115
+ updatedAt: number;
116
+ duration?: number | undefined;
117
+ startedAt?: number | undefined;
118
+ requestedStopAt?: number | undefined;
119
+ stoppedAt?: number | undefined;
120
+ }, {
121
+ region: string;
122
+ timeout: number;
123
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
124
+ id: string;
125
+ memory: number;
126
+ vcpus: number;
127
+ runtime: string;
128
+ requestedAt: number;
129
+ createdAt: number;
130
+ updatedAt: number;
131
+ duration?: number | undefined;
132
+ startedAt?: number | undefined;
133
+ requestedStopAt?: number | undefined;
134
+ stoppedAt?: number | undefined;
135
+ }>;
136
+ }, "strip", z.ZodTypeAny, {
137
+ sandbox: {
138
+ region: string;
139
+ timeout: number;
140
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
141
+ id: string;
142
+ memory: number;
143
+ vcpus: number;
144
+ runtime: string;
145
+ requestedAt: number;
146
+ createdAt: number;
147
+ updatedAt: number;
148
+ duration?: number | undefined;
149
+ startedAt?: number | undefined;
150
+ requestedStopAt?: number | undefined;
151
+ stoppedAt?: number | undefined;
152
+ };
153
+ }, {
154
+ sandbox: {
155
+ region: string;
156
+ timeout: number;
157
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
158
+ id: string;
159
+ memory: number;
160
+ vcpus: number;
161
+ runtime: string;
162
+ requestedAt: number;
163
+ createdAt: number;
164
+ updatedAt: number;
165
+ duration?: number | undefined;
166
+ startedAt?: number | undefined;
167
+ requestedStopAt?: number | undefined;
168
+ stoppedAt?: number | undefined;
169
+ };
170
+ }>;
171
+ export declare const SandboxAndRoutesResponse: z.ZodObject<{
172
+ sandbox: z.ZodObject<{
173
+ id: z.ZodString;
174
+ memory: z.ZodNumber;
175
+ vcpus: z.ZodNumber;
176
+ region: z.ZodString;
177
+ runtime: z.ZodString;
178
+ timeout: z.ZodNumber;
179
+ status: z.ZodEnum<["pending", "running", "stopping", "stopped", "failed"]>;
180
+ requestedAt: z.ZodNumber;
181
+ startedAt: z.ZodOptional<z.ZodNumber>;
182
+ requestedStopAt: z.ZodOptional<z.ZodNumber>;
183
+ stoppedAt: z.ZodOptional<z.ZodNumber>;
184
+ duration: z.ZodOptional<z.ZodNumber>;
185
+ createdAt: z.ZodNumber;
186
+ updatedAt: z.ZodNumber;
187
+ }, "strip", z.ZodTypeAny, {
188
+ region: string;
189
+ timeout: number;
190
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
191
+ id: string;
192
+ memory: number;
193
+ vcpus: number;
194
+ runtime: string;
195
+ requestedAt: number;
196
+ createdAt: number;
197
+ updatedAt: number;
198
+ duration?: number | undefined;
199
+ startedAt?: number | undefined;
200
+ requestedStopAt?: number | undefined;
201
+ stoppedAt?: number | undefined;
202
+ }, {
203
+ region: string;
204
+ timeout: number;
205
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
206
+ id: string;
207
+ memory: number;
208
+ vcpus: number;
209
+ runtime: string;
210
+ requestedAt: number;
211
+ createdAt: number;
212
+ updatedAt: number;
213
+ duration?: number | undefined;
214
+ startedAt?: number | undefined;
215
+ requestedStopAt?: number | undefined;
216
+ stoppedAt?: number | undefined;
217
+ }>;
218
+ } & {
4
219
  routes: z.ZodArray<z.ZodObject<{
220
+ url: z.ZodString;
5
221
  subdomain: z.ZodString;
6
222
  port: z.ZodNumber;
7
223
  }, "strip", z.ZodTypeAny, {
8
224
  port: number;
225
+ url: string;
9
226
  subdomain: string;
10
227
  }, {
11
228
  port: number;
229
+ url: string;
12
230
  subdomain: string;
13
231
  }>, "many">;
14
232
  }, "strip", z.ZodTypeAny, {
15
- sandboxId: string;
233
+ sandbox: {
234
+ region: string;
235
+ timeout: number;
236
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
237
+ id: string;
238
+ memory: number;
239
+ vcpus: number;
240
+ runtime: string;
241
+ requestedAt: number;
242
+ createdAt: number;
243
+ updatedAt: number;
244
+ duration?: number | undefined;
245
+ startedAt?: number | undefined;
246
+ requestedStopAt?: number | undefined;
247
+ stoppedAt?: number | undefined;
248
+ };
16
249
  routes: {
17
250
  port: number;
251
+ url: string;
18
252
  subdomain: string;
19
253
  }[];
20
254
  }, {
21
- sandboxId: string;
255
+ sandbox: {
256
+ region: string;
257
+ timeout: number;
258
+ status: "pending" | "running" | "stopping" | "stopped" | "failed";
259
+ id: string;
260
+ memory: number;
261
+ vcpus: number;
262
+ runtime: string;
263
+ requestedAt: number;
264
+ createdAt: number;
265
+ updatedAt: number;
266
+ duration?: number | undefined;
267
+ startedAt?: number | undefined;
268
+ requestedStopAt?: number | undefined;
269
+ stoppedAt?: number | undefined;
270
+ };
22
271
  routes: {
23
272
  port: number;
273
+ url: string;
24
274
  subdomain: string;
25
275
  }[];
26
276
  }>;
27
- export declare const CreatedCommand: z.ZodObject<{
28
- cmdId: z.ZodString;
29
- }, "strip", z.ZodTypeAny, {
30
- cmdId: string;
31
- }, {
32
- cmdId: string;
33
- }>;
34
- export declare const Command: z.ZodObject<{
35
- args: z.ZodArray<z.ZodString, "many">;
36
- cmdId: z.ZodString;
37
- cwd: z.ZodString;
38
- exitCode: z.ZodNullable<z.ZodNumber>;
39
- name: z.ZodString;
40
- }, "strip", z.ZodTypeAny, {
41
- name: string;
42
- cwd: string;
43
- args: string[];
44
- cmdId: string;
45
- exitCode: number | null;
46
- }, {
47
- name: string;
48
- cwd: string;
49
- args: string[];
50
- cmdId: string;
51
- exitCode: number | null;
52
- }>;
53
- export declare const CommandFinished: z.ZodObject<{
54
- args: z.ZodArray<z.ZodString, "many">;
55
- cmdId: z.ZodString;
56
- cwd: z.ZodString;
57
- exitCode: z.ZodNumber;
58
- name: z.ZodString;
277
+ export declare const CommandResponse: z.ZodObject<{
278
+ command: z.ZodObject<{
279
+ id: z.ZodString;
280
+ name: z.ZodString;
281
+ args: z.ZodArray<z.ZodString, "many">;
282
+ cwd: z.ZodString;
283
+ sandboxId: z.ZodString;
284
+ exitCode: z.ZodNullable<z.ZodNumber>;
285
+ startedAt: z.ZodNumber;
286
+ }, "strip", z.ZodTypeAny, {
287
+ name: string;
288
+ cwd: string;
289
+ args: string[];
290
+ id: string;
291
+ startedAt: number;
292
+ sandboxId: string;
293
+ exitCode: number | null;
294
+ }, {
295
+ name: string;
296
+ cwd: string;
297
+ args: string[];
298
+ id: string;
299
+ startedAt: number;
300
+ sandboxId: string;
301
+ exitCode: number | null;
302
+ }>;
59
303
  }, "strip", z.ZodTypeAny, {
60
- name: string;
61
- cwd: string;
62
- args: string[];
63
- cmdId: string;
64
- exitCode: number;
304
+ command: {
305
+ name: string;
306
+ cwd: string;
307
+ args: string[];
308
+ id: string;
309
+ startedAt: number;
310
+ sandboxId: string;
311
+ exitCode: number | null;
312
+ };
65
313
  }, {
66
- name: string;
67
- cwd: string;
68
- args: string[];
69
- cmdId: string;
70
- exitCode: number;
314
+ command: {
315
+ name: string;
316
+ cwd: string;
317
+ args: string[];
318
+ id: string;
319
+ startedAt: number;
320
+ sandboxId: string;
321
+ exitCode: number | null;
322
+ };
71
323
  }>;
72
- export declare const WrittenFile: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
73
- export declare const StoppedSandbox: z.ZodObject<{
74
- sandboxId: z.ZodString;
324
+ export declare const CommandFinishedResponse: z.ZodObject<{
325
+ command: z.ZodObject<{
326
+ id: z.ZodString;
327
+ name: z.ZodString;
328
+ args: z.ZodArray<z.ZodString, "many">;
329
+ cwd: z.ZodString;
330
+ sandboxId: z.ZodString;
331
+ startedAt: z.ZodNumber;
332
+ } & {
333
+ exitCode: z.ZodNumber;
334
+ }, "strip", z.ZodTypeAny, {
335
+ name: string;
336
+ cwd: string;
337
+ args: string[];
338
+ id: string;
339
+ startedAt: number;
340
+ sandboxId: string;
341
+ exitCode: number;
342
+ }, {
343
+ name: string;
344
+ cwd: string;
345
+ args: string[];
346
+ id: string;
347
+ startedAt: number;
348
+ sandboxId: string;
349
+ exitCode: number;
350
+ }>;
75
351
  }, "strip", z.ZodTypeAny, {
76
- sandboxId: string;
352
+ command: {
353
+ name: string;
354
+ cwd: string;
355
+ args: string[];
356
+ id: string;
357
+ startedAt: number;
358
+ sandboxId: string;
359
+ exitCode: number;
360
+ };
77
361
  }, {
78
- sandboxId: string;
362
+ command: {
363
+ name: string;
364
+ cwd: string;
365
+ args: string[];
366
+ id: string;
367
+ startedAt: number;
368
+ sandboxId: string;
369
+ exitCode: number;
370
+ };
79
371
  }>;
372
+ export declare const EmptyResponse: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
80
373
  export declare const LogLine: z.ZodObject<{
81
374
  stream: z.ZodEnum<["stdout", "stderr"]>;
82
375
  data: z.ZodString;
@@ -1,32 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LogLine = exports.StoppedSandbox = exports.WrittenFile = exports.CommandFinished = exports.Command = exports.CreatedCommand = exports.CreatedSandbox = void 0;
3
+ exports.LogLine = exports.EmptyResponse = exports.CommandFinishedResponse = exports.CommandResponse = exports.SandboxAndRoutesResponse = exports.SandboxResponse = exports.Command = exports.SandboxRoute = exports.Sandbox = void 0;
4
4
  const zod_1 = require("zod");
5
- exports.CreatedSandbox = zod_1.z.object({
6
- sandboxId: zod_1.z.string(),
7
- routes: zod_1.z.array(zod_1.z.object({ subdomain: zod_1.z.string(), port: zod_1.z.number() })),
5
+ exports.Sandbox = zod_1.z.object({
6
+ id: zod_1.z.string(),
7
+ memory: zod_1.z.number(),
8
+ vcpus: zod_1.z.number(),
9
+ region: zod_1.z.string(),
10
+ runtime: zod_1.z.string(),
11
+ timeout: zod_1.z.number(),
12
+ status: zod_1.z.enum(["pending", "running", "stopping", "stopped", "failed"]),
13
+ requestedAt: zod_1.z.number(),
14
+ startedAt: zod_1.z.number().optional(),
15
+ requestedStopAt: zod_1.z.number().optional(),
16
+ stoppedAt: zod_1.z.number().optional(),
17
+ duration: zod_1.z.number().optional(),
18
+ createdAt: zod_1.z.number(),
19
+ updatedAt: zod_1.z.number(),
8
20
  });
9
- exports.CreatedCommand = zod_1.z.object({
10
- cmdId: zod_1.z.string(),
21
+ exports.SandboxRoute = zod_1.z.object({
22
+ url: zod_1.z.string(),
23
+ subdomain: zod_1.z.string(),
24
+ port: zod_1.z.number(),
11
25
  });
12
26
  exports.Command = zod_1.z.object({
27
+ id: zod_1.z.string(),
28
+ name: zod_1.z.string(),
13
29
  args: zod_1.z.array(zod_1.z.string()),
14
- cmdId: zod_1.z.string(),
15
30
  cwd: zod_1.z.string(),
31
+ sandboxId: zod_1.z.string(),
16
32
  exitCode: zod_1.z.number().nullable(),
17
- name: zod_1.z.string(),
33
+ startedAt: zod_1.z.number(),
18
34
  });
19
- exports.CommandFinished = zod_1.z.object({
20
- args: zod_1.z.array(zod_1.z.string()),
21
- cmdId: zod_1.z.string(),
22
- cwd: zod_1.z.string(),
35
+ const CommandFinished = exports.Command.extend({
23
36
  exitCode: zod_1.z.number(),
24
- name: zod_1.z.string(),
25
37
  });
26
- exports.WrittenFile = zod_1.z.object({});
27
- exports.StoppedSandbox = zod_1.z.object({
28
- sandboxId: zod_1.z.string(),
38
+ exports.SandboxResponse = zod_1.z.object({
39
+ sandbox: exports.Sandbox,
40
+ });
41
+ exports.SandboxAndRoutesResponse = exports.SandboxResponse.extend({
42
+ routes: zod_1.z.array(exports.SandboxRoute),
43
+ });
44
+ exports.CommandResponse = zod_1.z.object({
45
+ command: exports.Command,
46
+ });
47
+ exports.CommandFinishedResponse = zod_1.z.object({
48
+ command: CommandFinished,
29
49
  });
50
+ exports.EmptyResponse = zod_1.z.object({});
30
51
  exports.LogLine = zod_1.z.object({
31
52
  stream: zod_1.z.enum(["stdout", "stderr"]),
32
53
  data: zod_1.z.string(),
package/dist/command.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { APIClient } from "./api-client";
1
+ import { APIClient, type CommandData } from "./api-client";
2
+ import { Signal } from "./utils/resolveSignal";
2
3
  /**
3
4
  * A command executed in a Sandbox.
4
5
  *
@@ -19,20 +20,24 @@ export declare class Command {
19
20
  * ID of the sandbox this command is running in.
20
21
  */
21
22
  private sandboxId;
23
+ /**
24
+ * Data for the command execution.
25
+ */
26
+ private cmd;
22
27
  /**
23
28
  * ID of the command execution.
24
29
  */
25
- cmdId: string;
30
+ get cmdId(): string;
26
31
  /**
27
32
  * @param params - Object containing the client, sandbox ID, and command ID.
28
33
  * @param params.client - API client used to interact with the backend.
29
34
  * @param params.sandboxId - The ID of the sandbox where the command is running.
30
35
  * @param params.cmdId - The ID of the command execution.
31
36
  */
32
- constructor({ client, sandboxId, cmdId, }: {
37
+ constructor({ client, sandboxId, cmd, }: {
33
38
  client: APIClient;
34
39
  sandboxId: string;
35
- cmdId: string;
40
+ cmd: CommandData;
36
41
  });
37
42
  /**
38
43
  * Iterate over the output of this command.
@@ -97,6 +102,14 @@ export declare class Command {
97
102
  * @returns The standard error output of the command.
98
103
  */
99
104
  stderr(): Promise<string>;
105
+ /**
106
+ * Kill a running command in a sandbox.
107
+ *
108
+ * @param params - commandId and the signal to send the running process.
109
+ * Defaults to SIGTERM.
110
+ * @returns Promise<void>.
111
+ */
112
+ kill(signal?: Signal): Promise<void>;
100
113
  }
101
114
  /**
102
115
  * A command that has finished executing.
@@ -121,7 +134,7 @@ export declare class CommandFinished extends Command {
121
134
  constructor(params: {
122
135
  client: APIClient;
123
136
  sandboxId: string;
124
- cmdId: string;
137
+ cmd: CommandData;
125
138
  exitCode: number;
126
139
  });
127
140
  }
package/dist/command.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandFinished = exports.Command = void 0;
4
+ const resolveSignal_1 = require("./utils/resolveSignal");
4
5
  /**
5
6
  * A command executed in a Sandbox.
6
7
  *
@@ -12,16 +13,22 @@ exports.CommandFinished = exports.Command = void 0;
12
13
  * @hideconstructor
13
14
  */
14
15
  class Command {
16
+ /**
17
+ * ID of the command execution.
18
+ */
19
+ get cmdId() {
20
+ return this.cmd.id;
21
+ }
15
22
  /**
16
23
  * @param params - Object containing the client, sandbox ID, and command ID.
17
24
  * @param params.client - API client used to interact with the backend.
18
25
  * @param params.sandboxId - The ID of the sandbox where the command is running.
19
26
  * @param params.cmdId - The ID of the command execution.
20
27
  */
21
- constructor({ client, sandboxId, cmdId, }) {
28
+ constructor({ client, sandboxId, cmd, }) {
22
29
  this.client = client;
23
30
  this.sandboxId = sandboxId;
24
- this.cmdId = cmdId;
31
+ this.cmd = cmd;
25
32
  }
26
33
  /**
27
34
  * Iterate over the output of this command.
@@ -44,7 +51,7 @@ class Command {
44
51
  logs() {
45
52
  return this.client.getLogs({
46
53
  sandboxId: this.sandboxId,
47
- cmdId: this.cmdId,
54
+ cmdId: this.cmd.id,
48
55
  });
49
56
  }
50
57
  /**
@@ -62,14 +69,14 @@ class Command {
62
69
  async wait() {
63
70
  const command = await this.client.getCommand({
64
71
  sandboxId: this.sandboxId,
65
- cmdId: this.cmdId,
72
+ cmdId: this.cmd.id,
66
73
  wait: true,
67
74
  });
68
75
  return new CommandFinished({
69
76
  client: this.client,
70
77
  sandboxId: this.sandboxId,
71
- cmdId: command.json.cmdId,
72
- exitCode: command.json.exitCode,
78
+ cmd: command.json.command,
79
+ exitCode: command.json.command.exitCode,
73
80
  });
74
81
  }
75
82
  /**
@@ -112,6 +119,20 @@ class Command {
112
119
  async stderr() {
113
120
  return this.output("stderr");
114
121
  }
122
+ /**
123
+ * Kill a running command in a sandbox.
124
+ *
125
+ * @param params - commandId and the signal to send the running process.
126
+ * Defaults to SIGTERM.
127
+ * @returns Promise<void>.
128
+ */
129
+ async kill(signal) {
130
+ await this.client.killCommand({
131
+ sandboxId: this.sandboxId,
132
+ commandId: this.cmd.id,
133
+ signal: (0, resolveSignal_1.resolveSignal)(signal ?? "SIGTERM"),
134
+ });
135
+ }
115
136
  }
116
137
  exports.Command = Command;
117
138
  /**