@vercel/sandbox 1.1.9 → 1.2.1

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.
Files changed (66) hide show
  1. package/dist/api-client/api-client.d.ts +18 -13
  2. package/dist/api-client/api-client.js +46 -0
  3. package/dist/api-client/api-client.js.map +1 -1
  4. package/dist/api-client/validators.d.ts +1 -0
  5. package/dist/api-client/validators.js.map +1 -1
  6. package/dist/sandbox.d.ts +39 -5
  7. package/dist/sandbox.js +111 -23
  8. package/dist/sandbox.js.map +1 -1
  9. package/dist/version.d.ts +1 -1
  10. package/dist/version.js +1 -1
  11. package/package.json +6 -1
  12. package/.turbo/turbo-build.log +0 -4
  13. package/.turbo/turbo-test.log +0 -24
  14. package/.turbo/turbo-typecheck.log +0 -4
  15. package/CHANGELOG.md +0 -267
  16. package/__mocks__/picocolors.ts +0 -13
  17. package/scripts/inject-version.ts +0 -11
  18. package/src/api-client/api-client.test.ts +0 -176
  19. package/src/api-client/api-client.ts +0 -520
  20. package/src/api-client/api-error.ts +0 -46
  21. package/src/api-client/base-client.ts +0 -171
  22. package/src/api-client/file-writer.ts +0 -90
  23. package/src/api-client/index.ts +0 -2
  24. package/src/api-client/validators.ts +0 -144
  25. package/src/api-client/with-retry.ts +0 -131
  26. package/src/auth/api.ts +0 -31
  27. package/src/auth/error.ts +0 -8
  28. package/src/auth/file.ts +0 -69
  29. package/src/auth/index.ts +0 -9
  30. package/src/auth/infer-scope.test.ts +0 -178
  31. package/src/auth/linked-project.test.ts +0 -86
  32. package/src/auth/linked-project.ts +0 -40
  33. package/src/auth/oauth.ts +0 -333
  34. package/src/auth/poll-for-token.ts +0 -89
  35. package/src/auth/project.ts +0 -92
  36. package/src/auth/zod.ts +0 -16
  37. package/src/command.test.ts +0 -103
  38. package/src/command.ts +0 -287
  39. package/src/constants.ts +0 -1
  40. package/src/index.ts +0 -4
  41. package/src/sandbox.test.ts +0 -93
  42. package/src/sandbox.ts +0 -572
  43. package/src/snapshot.ts +0 -110
  44. package/src/utils/array.ts +0 -15
  45. package/src/utils/consume-readable.ts +0 -12
  46. package/src/utils/decode-base64-url.ts +0 -14
  47. package/src/utils/dev-credentials.test.ts +0 -217
  48. package/src/utils/dev-credentials.ts +0 -196
  49. package/src/utils/get-credentials.test.ts +0 -20
  50. package/src/utils/get-credentials.ts +0 -183
  51. package/src/utils/jwt-expiry.test.ts +0 -125
  52. package/src/utils/jwt-expiry.ts +0 -105
  53. package/src/utils/log.ts +0 -20
  54. package/src/utils/normalizePath.test.ts +0 -114
  55. package/src/utils/normalizePath.ts +0 -33
  56. package/src/utils/resolveSignal.ts +0 -24
  57. package/src/utils/types.test.js +0 -7
  58. package/src/utils/types.ts +0 -23
  59. package/src/version.ts +0 -2
  60. package/test-utils/mock-response.ts +0 -12
  61. package/tsconfig.json +0 -16
  62. package/turbo.json +0 -9
  63. package/typedoc.json +0 -13
  64. package/vercel.json +0 -9
  65. package/vitest.config.ts +0 -9
  66. package/vitest.setup.ts +0 -4
package/CHANGELOG.md DELETED
@@ -1,267 +0,0 @@
1
- # @vercel/sandbox
2
-
3
- ## 1.1.9
4
-
5
- ### Patch Changes
6
-
7
- - rename internal property outputCachePromise to outputCache, removing the old outputCache which was the unwrapped version of the promise. ([#230](https://github.com/vercel/sandbox-sdk/pull/230))
8
-
9
- - Update OIDC error messages ([#234](https://github.com/vercel/sandbox-sdk/pull/234))
10
-
11
- - support `await using sbx = await Sandbox.create()` ([#203](https://github.com/vercel/sandbox-sdk/pull/203))
12
-
13
- ## 1.1.8
14
-
15
- ### Patch Changes
16
-
17
- - Improve CLI error messages and support env var punning (`-e VAR`) ([#231](https://github.com/vercel/sandbox-sdk/pull/231))
18
-
19
- ## 1.1.7
20
-
21
- ### Patch Changes
22
-
23
- - Change default runtime to node24 ([#212](https://github.com/vercel/sandbox-sdk/pull/212))
24
-
25
- ## 1.1.6
26
-
27
- ### Patch Changes
28
-
29
- - Fixed race in stdout/stderr buffering ([#213](https://github.com/vercel/sandbox-sdk/pull/213))
30
-
31
- ## 1.1.5
32
-
33
- ### Patch Changes
34
-
35
- - prompt to login on local machines to make it seamless to use ([#185](https://github.com/vercel/sandbox-sdk/pull/185))
36
-
37
- ## 1.1.4
38
-
39
- ### Patch Changes
40
-
41
- - Update @vercel/oidc to 3.1.0 ([#204](https://github.com/vercel/sandbox-sdk/pull/204))
42
-
43
- ## 1.1.3
44
-
45
- ### Patch Changes
46
-
47
- - don't require projectId in Sandbox.list ([#200](https://github.com/vercel/sandbox-sdk/pull/200))
48
-
49
- - add Sandbox.createdAt Date property ([#192](https://github.com/vercel/sandbox-sdk/pull/192))
50
-
51
- - Add support for stream errors ([#183](https://github.com/vercel/sandbox-sdk/pull/183))
52
-
53
- ## 1.1.2
54
-
55
- ### Patch Changes
56
-
57
- - allow Sandbox.list to omit the argument ([#186](https://github.com/vercel/sandbox-sdk/pull/186))
58
-
59
- ## 1.1.1
60
-
61
- ### Patch Changes
62
-
63
- - Add experimental support for snapshots ([#162](https://github.com/vercel/sandbox-sdk/pull/162))
64
-
65
- ## 1.1.0
66
-
67
- ### Minor Changes
68
-
69
- - Add support for node24 runtime. ([#179](https://github.com/vercel/sandbox-sdk/pull/179))
70
-
71
- ### Patch Changes
72
-
73
- - allow to override the fetch implementation ([#177](https://github.com/vercel/sandbox-sdk/pull/177))
74
-
75
- ## 1.0.4
76
-
77
- ### Patch Changes
78
-
79
- - add jsdoc example for sandbox.extendTimeout ([#171](https://github.com/vercel/sandbox-sdk/pull/171))
80
-
81
- - change license to MIT (more permissive, therefore not breaking change) ([#169](https://github.com/vercel/sandbox-sdk/pull/169))
82
-
83
- - when streaming stdout/stderr on command creation, don't throw AbortError when AbortSignal is done. Instead silently exit the loop. It's fine. ([#172](https://github.com/vercel/sandbox-sdk/pull/172))
84
-
85
- - Make interactive sandbox command execution use WebSocket instead of WebRTC to support more diverse network conditions. ([#164](https://github.com/vercel/sandbox-sdk/pull/164))
86
-
87
- ## 1.0.3
88
-
89
- ### Patch Changes
90
-
91
- - upgrade `@vercel/oidc` to version 3.0.5 to fix OIDC expiry bug (see https://github.com/vercel/vercel/pull/14306) ([#165](https://github.com/vercel/sandbox-sdk/pull/165))
92
-
93
- ## 1.0.0
94
-
95
- ## 1.0.0-beta.0
96
-
97
- ### Major Changes
98
-
99
- - starting a beta ([#147](https://github.com/vercel/sandbox-sdk/pull/147))
100
-
101
- ## 0.0.24
102
-
103
- ### Patch Changes
104
-
105
- - Change base URL to vercel.com/api ([#150](https://github.com/vercel/sandbox-sdk/pull/150))
106
-
107
- ## 0.0.23
108
-
109
- ### Patch Changes
110
-
111
- - Add `Sandbox.extendTimeout()` ([#148](https://github.com/vercel/sandbox-sdk/pull/148))
112
-
113
- ## 0.0.22
114
-
115
- ### Patch Changes
116
-
117
- - add AbortSignal support in public interface ([#137](https://github.com/vercel/sandbox-sdk/pull/137))
118
-
119
- - add AbortSignal support to command.wait ([#136](https://github.com/vercel/sandbox-sdk/pull/136))
120
-
121
- ## 0.0.21
122
-
123
- ### Patch Changes
124
-
125
- - Disable Undici body timeout ([#126](https://github.com/vercel/sandbox-sdk/pull/126))
126
-
127
- ## 0.0.20
128
-
129
- ### Patch Changes
130
-
131
- - Update max timeouts limit ([#125](https://github.com/vercel/sandbox-sdk/pull/125))
132
-
133
- ## 0.0.19
134
-
135
- ### Patch Changes
136
-
137
- - https://github.com/vercel/sandbox-sdk/pull/104/files introduced `Sandbox.list` ([#119](https://github.com/vercel/sandbox-sdk/pull/119))
138
-
139
- - support interrupting the log consuming ([#123](https://github.com/vercel/sandbox-sdk/pull/123))
140
-
141
- - using [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) with `cmd.logs({ signal })`
142
- - using [`Disposable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using) with `using logs = cmd.logs()`
143
-
144
- ## 0.0.18
145
-
146
- ### Patch Changes
147
-
148
- - refresh oidc token if stale in development ([#106](https://github.com/vercel/sandbox-sdk/pull/106))
149
-
150
- ## 0.0.17
151
-
152
- ### Patch Changes
153
-
154
- - Sandboxes can now expose up to 4 ports ([#99](https://github.com/vercel/sandbox-sdk/pull/99))
155
-
156
- This applies to all SDK versions, but this SDK release documents the limit.
157
-
158
- - Fix bug in Sandbox.writeFile, add support for absolute paths ([#97](https://github.com/vercel/sandbox-sdk/pull/97))
159
-
160
- ## 0.0.16
161
-
162
- ### Patch Changes
163
-
164
- - Add sandbox.status property ([#95](https://github.com/vercel/sandbox-sdk/pull/95))
165
-
166
- ## 0.0.15
167
-
168
- ### Patch Changes
169
-
170
- - Remove warning when consuming logs more than once ([#91](https://github.com/vercel/sandbox-sdk/pull/91))
171
-
172
- - Improve future compatibility of runtime parameter ([#88](https://github.com/vercel/sandbox-sdk/pull/88))
173
-
174
- ## 0.0.14
175
-
176
- ### Patch Changes
177
-
178
- - Use `@vercel/oidc` for authentication ([#87](https://github.com/vercel/sandbox-sdk/pull/87))
179
-
180
- - Expose more data in `Command` ([#85](https://github.com/vercel/sandbox-sdk/pull/85))
181
-
182
- ## 0.0.13
183
-
184
- ### Patch Changes
185
-
186
- - Add sudo support to running commands ([#72](https://github.com/vercel/sandbox-sdk/pull/72))
187
-
188
- ## 0.0.12
189
-
190
- ### Patch Changes
191
-
192
- - Fix installation with `npm` on Node 22
193
-
194
- ## 0.0.11
195
-
196
- ### Patch Changes
197
-
198
- - Rename `stream` to `content` when writing files ([#60](https://github.com/vercel/sandbox-sdk/pull/60))
199
-
200
- ## 0.0.10
201
-
202
- ### Patch Changes
203
-
204
- - Add `readFile` and fix a bug writing files to a Sandbox ([#54](https://github.com/vercel/sandbox-sdk/pull/54))
205
-
206
- - Remove unused `routes` parameter from getSandbox ([#59](https://github.com/vercel/sandbox-sdk/pull/59))
207
-
208
- ## 0.0.9
209
-
210
- ### Patch Changes
211
-
212
- - Add `cmd.kill()` to stop/signal commands ([#48](https://github.com/vercel/sandbox-sdk/pull/48))
213
- - Update SDK to use the new API ([#51](https://github.com/vercel/sandbox-sdk/pull/51))
214
-
215
- ## 0.0.8
216
-
217
- ### Patch Changes
218
-
219
- - Write files using a single compressed stream ([#44](https://github.com/vercel/sandbox-sdk/pull/44))
220
- - Expose `runtime` parameter ([#46](https://github.com/vercel/sandbox-sdk/pull/46))
221
- - Add git depth and revision options to sandbox source ([#47](https://github.com/vercel/sandbox-sdk/pull/47))
222
-
223
- ## 0.0.7
224
-
225
- ### Patch Changes
226
-
227
- - Rename `cores` to `vcpus` ([#41](https://github.com/vercel/sandbox-sdk/pull/41))
228
-
229
- ## 0.0.6
230
-
231
- ### Patch Changes
232
-
233
- - Better types for `Command` allowing a shorcut for waiting ([#29](https://github.com/vercel/sandbox-sdk/pull/29))
234
-
235
- - Remove `SDK` and simplify API surface ([#38](https://github.com/vercel/sandbox-sdk/pull/38))
236
-
237
- ## 0.0.5
238
-
239
- ### Patch Changes
240
-
241
- - Allow specifying env vars and cwd when running commands ([#25](https://github.com/vercel/sandbox-sdk/pull/25))
242
-
243
- - createSandbox: do not require ports to be specified ([#27](https://github.com/vercel/sandbox-sdk/pull/27))
244
-
245
- ## 0.0.4
246
-
247
- ### Patch Changes
248
-
249
- - Rename `SandboxSDK` to `SDK` and incorporate `projectId` as a required parameter ([#21](https://github.com/vercel/sandbox-sdk/pull/21))
250
-
251
- ## 0.0.3
252
-
253
- ### Patch Changes
254
-
255
- - Do not include dev scripts in package output ([#16](https://github.com/vercel/sandbox-sdk/pull/16))
256
-
257
- ## 0.0.2
258
-
259
- ### Patch Changes
260
-
261
- - Include user-agent HTTP header ([#13](https://github.com/vercel/sandbox-sdk/pull/13))
262
-
263
- ## 0.0.1
264
-
265
- ### Patch Changes
266
-
267
- - Initial release ([#11](https://github.com/vercel/sandbox-sdk/pull/11))
@@ -1,13 +0,0 @@
1
- /**
2
- * Mock implementation of picocolors for testing purposes
3
- * Each color function wraps the input string with HTML-like tags
4
- * e.g., red('text') => '<red>text</red>'
5
- */
6
- export default new Proxy(
7
- {},
8
- {
9
- get(_, prop: string) {
10
- return (str: string) => `<${prop}>${str}</${prop}>`;
11
- },
12
- },
13
- );
@@ -1,11 +0,0 @@
1
- import { version } from "../package.json";
2
- import { writeFile } from "fs/promises";
3
- import path from "path";
4
-
5
- async function main() {
6
- const outPath = path.resolve(__dirname, "../src/version.ts");
7
- const content = `// Autogenerated by inject-version.ts\nexport const VERSION = "${version}";\n`;
8
- await writeFile(outPath, content);
9
- }
10
-
11
- main().catch(console.error);
@@ -1,176 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
2
- import { APIClient } from "./api-client";
3
- import { APIError, StreamError } from "./api-error";
4
- import { createNdjsonStream } from "../../test-utils/mock-response";
5
-
6
- describe("APIClient", () => {
7
- describe("getLogs", () => {
8
- let client: APIClient;
9
- let mockFetch: ReturnType<typeof vi.fn>;
10
-
11
- beforeEach(() => {
12
- mockFetch = vi.fn();
13
- client = new APIClient({
14
- teamId: "team_123",
15
- token: "1234",
16
- fetch: mockFetch,
17
- });
18
- });
19
-
20
- it("yields stdout log lines", async () => {
21
- const logLines = [
22
- { stream: "stdout", data: "hello" },
23
- { stream: "stdout", data: "world" },
24
- ];
25
-
26
- mockFetch.mockResolvedValue(
27
- new Response(createNdjsonStream(logLines), {
28
- headers: { "content-type": "application/x-ndjson" },
29
- }),
30
- );
31
-
32
- const logs = client.getLogs({ sandboxId: "sbx_123", cmdId: "cmd_456" });
33
- const results: Array<{ stream: string; data: string }> = [];
34
-
35
- for await (const log of logs) {
36
- results.push(log);
37
- }
38
-
39
- expect(results).toHaveLength(2);
40
- expect(results[0]).toEqual({ stream: "stdout", data: "hello" });
41
- expect(results[1]).toEqual({ stream: "stdout", data: "world" });
42
- });
43
-
44
- it("yields stderr log lines", async () => {
45
- const logLines = [{ stream: "stderr", data: "Error" }];
46
-
47
- mockFetch.mockResolvedValue(
48
- new Response(createNdjsonStream(logLines), {
49
- headers: { "content-type": "application/x-ndjson" },
50
- }),
51
- );
52
-
53
- const logs = client.getLogs({ sandboxId: "sbx_123", cmdId: "cmd_456" });
54
- const results: Array<{ stream: string; data: string }> = [];
55
-
56
- for await (const log of logs) {
57
- results.push(log);
58
- }
59
-
60
- expect(results).toHaveLength(1);
61
- expect(results[0]).toEqual({
62
- stream: "stderr",
63
- data: "Error",
64
- });
65
- });
66
-
67
- it("throws APIError when content-type is not application/x-ndjson", async () => {
68
- mockFetch.mockResolvedValue(
69
- new Response(null, {
70
- headers: { "content-type": "application/json" },
71
- }),
72
- );
73
-
74
- const logs = client.getLogs({ sandboxId: "sbx_123", cmdId: "cmd_456" });
75
-
76
- await expect(async () => {
77
- for await (const _ of logs) {
78
- }
79
- }).rejects.toThrow(APIError);
80
- });
81
-
82
- it("throws APIError when response body is null", async () => {
83
- mockFetch.mockResolvedValue(
84
- new Response(null, {
85
- headers: { "content-type": "application/x-ndjson" },
86
- }),
87
- );
88
-
89
- const logs = client.getLogs({ sandboxId: "sbx_123", cmdId: "cmd_456" });
90
-
91
- await expect(async () => {
92
- for await (const _ of logs) {
93
- }
94
- }).rejects.toThrow(APIError);
95
- });
96
-
97
- it("throws StreamError when error log line is received", async () => {
98
- const logLines = [
99
- { stream: "stdout", data: "some logs" },
100
- {
101
- stream: "error",
102
- data: {
103
- code: "sandbox_stream_closed",
104
- message: "Sandbox stream was closed and is not accepting commands.",
105
- },
106
- },
107
- ];
108
-
109
- mockFetch.mockResolvedValue(
110
- new Response(createNdjsonStream(logLines), {
111
- headers: { "content-type": "application/x-ndjson" },
112
- }),
113
- );
114
-
115
- const logs = client.getLogs({ sandboxId: "sbx_123", cmdId: "cmd_456" });
116
- const results: Array<{ stream: string; data: string }> = [];
117
-
118
- await expect(async () => {
119
- for await (const log of logs) {
120
- results.push(log);
121
- }
122
- }).rejects.toThrow(StreamError);
123
-
124
- expect(results).toHaveLength(1);
125
- expect(results[0]).toEqual({ stream: "stdout", data: "some logs" });
126
- });
127
-
128
- it("includes sandboxId in APIError", async () => {
129
- mockFetch.mockResolvedValue(
130
- new Response(null, {
131
- headers: { "content-type": "application/json" },
132
- }),
133
- );
134
-
135
- const logs = client.getLogs({ sandboxId: "sbx_123", cmdId: "cmd_456" });
136
-
137
- try {
138
- for await (const _ of logs) {
139
- }
140
- expect.fail("Expected APIError to be thrown");
141
- } catch (err) {
142
- expect(err).toBeInstanceOf(APIError);
143
- expect((err as APIError<unknown>).sandboxId).toBe("sbx_123");
144
- }
145
- });
146
-
147
- it("includes sandboxId in StreamError", async () => {
148
- const logLines = [
149
- {
150
- stream: "error",
151
- data: {
152
- code: "sandbox_stopped",
153
- message: "Sandbox has stopped",
154
- },
155
- },
156
- ];
157
-
158
- mockFetch.mockResolvedValue(
159
- new Response(createNdjsonStream(logLines), {
160
- headers: { "content-type": "application/x-ndjson" },
161
- }),
162
- );
163
-
164
- const logs = client.getLogs({ sandboxId: "sbx_123", cmdId: "cmd_456" });
165
-
166
- try {
167
- for await (const _ of logs) {
168
- }
169
- expect.fail("Expected StreamError to be thrown");
170
- } catch (err) {
171
- expect(err).toBeInstanceOf(StreamError);
172
- expect((err as StreamError).sandboxId).toBe("sbx_123");
173
- }
174
- });
175
- });
176
- });