@vercel/sandbox 0.0.4 → 0.0.5

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.4 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.5 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.4 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
2
+ > @vercel/sandbox@0.0.5 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/sandbox
3
3
  > tsc --noEmit
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @vercel/sandbox
2
2
 
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Allow specifying env vars and cwd when running commands ([#25](https://github.com/vercel/sandbox-sdk/pull/25))
8
+
9
+ - createSandbox: do not require ports to be specified ([#27](https://github.com/vercel/sandbox-sdk/pull/27))
10
+
3
11
  ## 0.0.4
4
12
 
5
13
  ### Patch Changes
package/README.md CHANGED
@@ -13,6 +13,7 @@ Vercel Sandbox is in private beta. These examples will not work unless these
13
13
  APIs are enabled for your team.
14
14
 
15
15
  - Go to your team settings, and copy the team ID.
16
+ - Go to a project's settings, and copy the project ID.
16
17
  - Go to your Vercel account settings and [create a token][create-token]. Make
17
18
  sure it is scoped to the team ID from the previous step.
18
19
  - Create a new project:
@@ -31,7 +32,7 @@ Now create `next-dev.ts`:
31
32
  Run it like this:
32
33
 
33
34
  ```sh
34
- VERCEL_TEAM_ID=<team_id> VERCEL_TOKEN=<token> node --experimental-strip-types ./next-dev.ts
35
+ VERCEL_TEAM_ID=<team_id> VERCEL_TOKEN=<token> VERCEL_PROJECT_ID=<project_id> node --experimental-strip-types ./next-dev.ts
35
36
  ```
36
37
 
37
38
  This will:
@@ -28,6 +28,7 @@ export declare class SandboxClient extends APIClient {
28
28
  cwd?: string;
29
29
  command: string;
30
30
  args: string[];
31
+ env: Record<string, string>;
31
32
  }): Promise<import("./base-client").Parsed<{
32
33
  cmdId: string;
33
34
  }>>;
@@ -50,6 +50,7 @@ class SandboxClient extends base_client_1.APIClient {
50
50
  command: params.command,
51
51
  args: params.args,
52
52
  cwd: params.cwd,
53
+ env: params.env,
53
54
  }),
54
55
  }));
55
56
  }
@@ -40,7 +40,7 @@ export declare class SDK {
40
40
  * @param params.source - The source of the sandbox, currently supports Git repositories only.
41
41
  * @param params.source.type - Type of source, must be `"git"`.
42
42
  * @param params.source.url - The URL of the public Git repository to clone.
43
- * @param config.projectId - The Vercel project ID used to link the Sandbox to.
43
+ * @param params.projectId - The Vercel project ID used to link the Sandbox to.
44
44
  * @param params.ports - Array of port numbers to expose from the sandbox.
45
45
  * @param params.timeout - (Optional) Timeout in seconds before the sandbox auto-terminates.
46
46
  *
@@ -52,7 +52,7 @@ export declare class SDK {
52
52
  url: string;
53
53
  };
54
54
  projectId: string;
55
- ports: number[];
55
+ ports?: number[];
56
56
  timeout?: number;
57
57
  }): Promise<Sandbox>;
58
58
  /** @hidden */
@@ -64,6 +64,17 @@ export declare class SDK {
64
64
  sandboxId: string;
65
65
  }): Promise<Sandbox>;
66
66
  }
67
+ /** @inline */
68
+ interface RunCommandParams {
69
+ /** The command to execute */
70
+ cmd: string;
71
+ /** Arguments to pass to the command */
72
+ args?: string[];
73
+ /** Working directory to execute the command in */
74
+ cwd?: string;
75
+ /** Environment variables to set for this command */
76
+ env?: Record<string, string>;
77
+ }
67
78
  /**
68
79
  * A Sandbox is an isolated Linux MicroVM that you can your experiments on.
69
80
  *
@@ -91,11 +102,22 @@ export declare class Sandbox {
91
102
  });
92
103
  /**
93
104
  * Start executing a command in this sandbox.
94
- * @param command
95
- * @param args
96
- * @returns
105
+ *
106
+ * @param command - The command to execute.
107
+ * @param args - Arguments to pass to the command.
108
+ *
109
+ * @returns A {@link Command} instance.
97
110
  */
98
111
  runCommand(command: string, args?: string[]): Promise<Command>;
112
+ /**
113
+ * Start executing a command in this sandbox.
114
+ *
115
+ * @param params - What should be executed.
116
+ *
117
+ * @returns A {@link Command} instance.
118
+ */
119
+ runCommand(params: RunCommandParams): Promise<Command>;
120
+ _runCommand(params: RunCommandParams): Promise<Command>;
99
121
  /**
100
122
  * Write files to the filesystem of this sandbox.
101
123
  */
@@ -194,3 +216,4 @@ export declare class Command {
194
216
  */
195
217
  stderr(): Promise<string>;
196
218
  }
219
+ export {};
@@ -37,7 +37,7 @@ class SDK {
37
37
  * @param params.source - The source of the sandbox, currently supports Git repositories only.
38
38
  * @param params.source.type - Type of source, must be `"git"`.
39
39
  * @param params.source.url - The URL of the public Git repository to clone.
40
- * @param config.projectId - The Vercel project ID used to link the Sandbox to.
40
+ * @param params.projectId - The Vercel project ID used to link the Sandbox to.
41
41
  * @param params.ports - Array of port numbers to expose from the sandbox.
42
42
  * @param params.timeout - (Optional) Timeout in seconds before the sandbox auto-terminates.
43
43
  *
@@ -48,7 +48,7 @@ class SDK {
48
48
  const sandbox = await client.createSandbox({
49
49
  source: params.source,
50
50
  projectId: params.projectId,
51
- ports: params.ports,
51
+ ports: params.ports ?? [],
52
52
  timeout: params.timeout,
53
53
  });
54
54
  return new Sandbox({
@@ -79,17 +79,18 @@ class Sandbox {
79
79
  this.routes = routes;
80
80
  this.sandboxId = sandboxId;
81
81
  }
82
- /**
83
- * Start executing a command in this sandbox.
84
- * @param command
85
- * @param args
86
- * @returns
87
- */
88
- async runCommand(command, args = []) {
82
+ async runCommand(commandOrParams, args) {
83
+ return typeof commandOrParams === "string"
84
+ ? this._runCommand({ cmd: commandOrParams, args })
85
+ : this._runCommand(commandOrParams);
86
+ }
87
+ async _runCommand(params) {
89
88
  const commandResponse = await this.client.runCommand({
90
89
  sandboxId: this.sandboxId,
91
- command,
92
- args,
90
+ command: params.cmd,
91
+ args: params.args ?? [],
92
+ cwd: params.cwd,
93
+ env: params.env ?? {},
93
94
  });
94
95
  return new Command({
95
96
  client: this.client,
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export { SDK, Sandbox, Command } from "./create-sandbox";
2
- export { SandboxClient } from "./client/client";
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SandboxClient = exports.Command = exports.Sandbox = exports.SDK = void 0;
3
+ exports.Command = exports.Sandbox = exports.SDK = void 0;
4
4
  var create_sandbox_1 = require("./create-sandbox");
5
5
  Object.defineProperty(exports, "SDK", { enumerable: true, get: function () { return create_sandbox_1.SDK; } });
6
6
  Object.defineProperty(exports, "Sandbox", { enumerable: true, get: function () { return create_sandbox_1.Sandbox; } });
7
7
  Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return create_sandbox_1.Command; } });
8
- var client_1 = require("./client/client");
9
- Object.defineProperty(exports, "SandboxClient", { enumerable: true, get: function () { return client_1.SandboxClient; } });
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.0.4";
1
+ export declare const VERSION = "0.0.5";
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.4";
5
+ exports.VERSION = "0.0.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/sandbox",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -65,6 +65,7 @@ export class SandboxClient extends APIClient {
65
65
  cwd?: string;
66
66
  command: string;
67
67
  args: string[];
68
+ env: Record<string, string>;
68
69
  }) {
69
70
  return parseOrThrow(
70
71
  CreatedCommand,
@@ -74,6 +75,7 @@ export class SandboxClient extends APIClient {
74
75
  command: params.command,
75
76
  args: params.args,
76
77
  cwd: params.cwd,
78
+ env: params.env,
77
79
  }),
78
80
  }),
79
81
  );
@@ -42,7 +42,7 @@ export class SDK {
42
42
  * @param params.source - The source of the sandbox, currently supports Git repositories only.
43
43
  * @param params.source.type - Type of source, must be `"git"`.
44
44
  * @param params.source.url - The URL of the public Git repository to clone.
45
- * @param config.projectId - The Vercel project ID used to link the Sandbox to.
45
+ * @param params.projectId - The Vercel project ID used to link the Sandbox to.
46
46
  * @param params.ports - Array of port numbers to expose from the sandbox.
47
47
  * @param params.timeout - (Optional) Timeout in seconds before the sandbox auto-terminates.
48
48
  *
@@ -51,14 +51,14 @@ export class SDK {
51
51
  async createSandbox(params: {
52
52
  source: { type: "git"; url: string };
53
53
  projectId: string;
54
- ports: number[];
54
+ ports?: number[];
55
55
  timeout?: number;
56
56
  }) {
57
57
  const { client } = this;
58
58
  const sandbox = await client.createSandbox({
59
59
  source: params.source,
60
60
  projectId: params.projectId,
61
- ports: params.ports,
61
+ ports: params.ports ?? [],
62
62
  timeout: params.timeout,
63
63
  });
64
64
 
@@ -85,6 +85,18 @@ export class SDK {
85
85
  }
86
86
  }
87
87
 
88
+ /** @inline */
89
+ interface RunCommandParams {
90
+ /** The command to execute */
91
+ cmd: string;
92
+ /** Arguments to pass to the command */
93
+ args?: string[];
94
+ /** Working directory to execute the command in */
95
+ cwd?: string;
96
+ /** Environment variables to set for this command */
97
+ env?: Record<string, string>;
98
+ }
99
+
88
100
  /**
89
101
  * A Sandbox is an isolated Linux MicroVM that you can your experiments on.
90
102
  *
@@ -118,15 +130,39 @@ export class Sandbox {
118
130
 
119
131
  /**
120
132
  * Start executing a command in this sandbox.
121
- * @param command
122
- * @param args
123
- * @returns
133
+ *
134
+ * @param command - The command to execute.
135
+ * @param args - Arguments to pass to the command.
136
+ *
137
+ * @returns A {@link Command} instance.
124
138
  */
125
- async runCommand(command: string, args: string[] = []) {
139
+ async runCommand(command: string, args?: string[]): Promise<Command>;
140
+
141
+ /**
142
+ * Start executing a command in this sandbox.
143
+ *
144
+ * @param params - What should be executed.
145
+ *
146
+ * @returns A {@link Command} instance.
147
+ */
148
+ async runCommand(params: RunCommandParams): Promise<Command>;
149
+
150
+ async runCommand(
151
+ commandOrParams: string | RunCommandParams,
152
+ args?: string[],
153
+ ): Promise<Command> {
154
+ return typeof commandOrParams === "string"
155
+ ? this._runCommand({ cmd: commandOrParams, args })
156
+ : this._runCommand(commandOrParams);
157
+ }
158
+
159
+ async _runCommand(params: RunCommandParams) {
126
160
  const commandResponse = await this.client.runCommand({
127
161
  sandboxId: this.sandboxId,
128
- command,
129
- args,
162
+ command: params.cmd,
163
+ args: params.args ?? [],
164
+ cwd: params.cwd,
165
+ env: params.env ?? {},
130
166
  });
131
167
 
132
168
  return new Command({
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
1
  export { SDK, Sandbox, Command } from "./create-sandbox";
2
- export { SandboxClient } from "./client/client";
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Autogenerated by inject-version.ts
2
- export const VERSION = "0.0.4";
2
+ export const VERSION = "0.0.5";