@vercel/sandbox 0.0.14 → 0.0.15
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.
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +8 -0
- package/dist/api-client/api-client.d.ts +1 -1
- package/dist/api-client/api-client.js +0 -22
- package/dist/sandbox.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -2
- package/src/api-client/api-client.ts +1 -27
- package/src/command.test.ts +9 -12
- package/src/sandbox.ts +1 -1
- package/src/version.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @vercel/sandbox
|
|
2
2
|
|
|
3
|
+
## 0.0.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Remove warning when consuming logs more than once ([#91](https://github.com/vercel/sandbox-sdk/pull/91))
|
|
8
|
+
|
|
9
|
+
- Improve future compatibility of runtime parameter ([#88](https://github.com/vercel/sandbox-sdk/pull/88))
|
|
10
|
+
|
|
3
11
|
## 0.0.14
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -8,20 +8,10 @@ const base_client_1 = require("./base-client");
|
|
|
8
8
|
const validators_1 = require("./validators");
|
|
9
9
|
const api_error_1 = require("./api-error");
|
|
10
10
|
const file_writer_1 = require("./file-writer");
|
|
11
|
-
const lru_cache_1 = require("lru-cache");
|
|
12
11
|
const version_1 = require("../version");
|
|
13
12
|
const consume_readable_1 = require("../utils/consume-readable");
|
|
14
13
|
const jsonlines_1 = __importDefault(require("jsonlines"));
|
|
15
14
|
const os_1 = __importDefault(require("os"));
|
|
16
|
-
const ms_1 = __importDefault(require("ms"));
|
|
17
|
-
/**
|
|
18
|
-
* Allows to track the logs hits for a command un a to maximum of items and
|
|
19
|
-
* TTL so that we don't incur in memory leaks in a log running process.
|
|
20
|
-
*/
|
|
21
|
-
const logHits = new lru_cache_1.LRUCache({
|
|
22
|
-
ttl: (0, ms_1.default)("45m"),
|
|
23
|
-
max: 1000,
|
|
24
|
-
});
|
|
25
15
|
class APIClient extends base_client_1.BaseClient {
|
|
26
16
|
constructor(params) {
|
|
27
17
|
super({
|
|
@@ -128,18 +118,6 @@ class APIClient extends base_client_1.BaseClient {
|
|
|
128
118
|
message: "Expected a stream of logs",
|
|
129
119
|
});
|
|
130
120
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Currently, once we consume logs in the backend we cannot read them
|
|
133
|
-
* again. This logic writes a warning when the endpoint for a command
|
|
134
|
-
* logs is consumed more than once to alert the user about this.
|
|
135
|
-
*
|
|
136
|
-
* This is a temporary solution, we should be able to handle this in
|
|
137
|
-
* the backend in the future.
|
|
138
|
-
*/
|
|
139
|
-
if (logHits.get(url)) {
|
|
140
|
-
console.warn(`Multiple consumers for logs of command \`${params.cmdId}\`. This may lead to unexpected behavior.`);
|
|
141
|
-
}
|
|
142
|
-
logHits.set(url, true);
|
|
143
121
|
for await (const chunk of response.body.pipe(jsonlines_1.default.parse())) {
|
|
144
122
|
yield validators_1.LogLine.parse(chunk);
|
|
145
123
|
}
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface CreateSandboxParams {
|
|
|
51
51
|
* The runtime of the sandbox, currently only `node22` and `python3.13` are supported.
|
|
52
52
|
* If not specified, the default runtime `node22` will be used.
|
|
53
53
|
*/
|
|
54
|
-
runtime?: "node22" | "python3.13";
|
|
54
|
+
runtime?: "node22" | "python3.13" | (string & {});
|
|
55
55
|
}
|
|
56
56
|
/** @inline */
|
|
57
57
|
interface GetSandboxParams {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.
|
|
1
|
+
export declare const VERSION = "0.0.15";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/sandbox",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"async-retry": "1.3.3",
|
|
14
14
|
"form-data": "3.0.0",
|
|
15
15
|
"jsonlines": "0.1.1",
|
|
16
|
-
"lru-cache": "11.1.0",
|
|
17
16
|
"ms": "2.1.3",
|
|
18
17
|
"node-fetch": "2.6.11",
|
|
19
18
|
"tar-stream": "3.1.7",
|
|
@@ -14,22 +14,11 @@ import {
|
|
|
14
14
|
} from "./validators";
|
|
15
15
|
import { APIError } from "./api-error";
|
|
16
16
|
import { FileWriter } from "./file-writer";
|
|
17
|
-
import { LRUCache } from "lru-cache";
|
|
18
17
|
import { VERSION } from "../version";
|
|
19
18
|
import { consumeReadable } from "../utils/consume-readable";
|
|
20
19
|
import { z } from "zod";
|
|
21
20
|
import jsonlines from "jsonlines";
|
|
22
21
|
import os from "os";
|
|
23
|
-
import ms from "ms";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Allows to track the logs hits for a command un a to maximum of items and
|
|
27
|
-
* TTL so that we don't incur in memory leaks in a log running process.
|
|
28
|
-
*/
|
|
29
|
-
const logHits = new LRUCache<string, boolean>({
|
|
30
|
-
ttl: ms("45m"),
|
|
31
|
-
max: 1000,
|
|
32
|
-
});
|
|
33
22
|
|
|
34
23
|
export class APIClient extends BaseClient {
|
|
35
24
|
private teamId: string;
|
|
@@ -78,7 +67,7 @@ export class APIClient extends BaseClient {
|
|
|
78
67
|
| { type: "tarball"; url: string };
|
|
79
68
|
timeout?: number;
|
|
80
69
|
resources?: { vcpus: number };
|
|
81
|
-
runtime?: "node22" | "python3.13";
|
|
70
|
+
runtime?: "node22" | "python3.13" | (string & {});
|
|
82
71
|
}) {
|
|
83
72
|
return parseOrThrow(
|
|
84
73
|
SandboxAndRoutesResponse,
|
|
@@ -239,21 +228,6 @@ export class APIClient extends BaseClient {
|
|
|
239
228
|
});
|
|
240
229
|
}
|
|
241
230
|
|
|
242
|
-
/**
|
|
243
|
-
* Currently, once we consume logs in the backend we cannot read them
|
|
244
|
-
* again. This logic writes a warning when the endpoint for a command
|
|
245
|
-
* logs is consumed more than once to alert the user about this.
|
|
246
|
-
*
|
|
247
|
-
* This is a temporary solution, we should be able to handle this in
|
|
248
|
-
* the backend in the future.
|
|
249
|
-
*/
|
|
250
|
-
if (logHits.get(url)) {
|
|
251
|
-
console.warn(
|
|
252
|
-
`Multiple consumers for logs of command \`${params.cmdId}\`. This may lead to unexpected behavior.`,
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
logHits.set(url, true);
|
|
257
231
|
for await (const chunk of response.body.pipe(jsonlines.parse())) {
|
|
258
232
|
yield LogLine.parse(chunk);
|
|
259
233
|
}
|
package/src/command.test.ts
CHANGED
|
@@ -11,8 +11,7 @@ afterEach(async () => {
|
|
|
11
11
|
await sandbox.stop();
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
it("
|
|
15
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
14
|
+
it("supports more than one logs consumer", async () => {
|
|
16
15
|
const stdoutSpy = vi
|
|
17
16
|
.spyOn(process.stdout, "write")
|
|
18
17
|
.mockImplementation(() => true);
|
|
@@ -23,13 +22,8 @@ it("warns when there is more than one logs consumer", async () => {
|
|
|
23
22
|
stdout: process.stdout,
|
|
24
23
|
});
|
|
25
24
|
|
|
26
|
-
expect(await cmd.stdout()).toEqual("");
|
|
25
|
+
expect(await cmd.stdout()).toEqual("Hello World!\n");
|
|
27
26
|
expect(stdoutSpy).toHaveBeenCalledWith("Hello World!\n");
|
|
28
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
29
|
-
expect.stringMatching(
|
|
30
|
-
/Multiple consumers for logs of command `[^`]+`\.\sThis may lead to unexpected behavior\./,
|
|
31
|
-
),
|
|
32
|
-
);
|
|
33
27
|
});
|
|
34
28
|
|
|
35
29
|
it("does not warn when there is only one logs consumer", async () => {
|
|
@@ -85,9 +79,12 @@ it("can execute commands with sudo", async () => {
|
|
|
85
79
|
expect(output).toContain("USER=root\n");
|
|
86
80
|
expect(output).toContain("SUDO_USER=vercel-sandbox\n");
|
|
87
81
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
const pathLine = output.split("\n").find((line) => line.startsWith("PATH="));
|
|
83
|
+
expect(pathLine).toBeDefined();
|
|
84
|
+
|
|
85
|
+
const pathSegments = pathLine!.slice(5).split(":");
|
|
86
|
+
expect(pathSegments).toContain("/vercel/bin");
|
|
87
|
+
expect(pathSegments).toContain("/vercel/runtimes/node22/bin");
|
|
91
88
|
|
|
92
89
|
const dnf = await sandbox.runCommand({
|
|
93
90
|
cmd: "dnf",
|
|
@@ -98,5 +95,5 @@ it("can execute commands with sudo", async () => {
|
|
|
98
95
|
expect(dnf.exitCode).toBe(0);
|
|
99
96
|
|
|
100
97
|
const which = await sandbox.runCommand("which", ["go"]);
|
|
101
|
-
expect(which.output()).
|
|
98
|
+
expect(await which.output()).toContain("/usr/bin/go");
|
|
102
99
|
});
|
package/src/sandbox.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface CreateSandboxParams {
|
|
|
51
51
|
* The runtime of the sandbox, currently only `node22` and `python3.13` are supported.
|
|
52
52
|
* If not specified, the default runtime `node22` will be used.
|
|
53
53
|
*/
|
|
54
|
-
runtime?: "node22" | "python3.13";
|
|
54
|
+
runtime?: "node22" | "python3.13" | (string & {});
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/** @inline */
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Autogenerated by inject-version.ts
|
|
2
|
-
export const VERSION = "0.0.
|
|
2
|
+
export const VERSION = "0.0.15";
|