@vercel/sandbox 2.0.0-beta.2 → 2.0.0-beta.20
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/README.md +48 -1
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/api-client/api-client.cjs +445 -0
- package/dist/api-client/api-client.cjs.map +1 -0
- package/dist/api-client/api-client.d.cts +6235 -0
- package/dist/api-client/api-client.d.ts +6229 -706
- package/dist/api-client/api-client.js +436 -472
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/api-error.cjs +32 -0
- package/dist/api-client/api-error.cjs.map +1 -0
- package/dist/api-client/api-error.d.cts +29 -0
- package/dist/api-client/api-error.d.ts +21 -16
- package/dist/api-client/api-error.js +28 -32
- package/dist/api-client/api-error.js.map +1 -1
- package/dist/api-client/base-client.cjs +126 -0
- package/dist/api-client/base-client.cjs.map +1 -0
- package/dist/api-client/base-client.d.cts +38 -0
- package/dist/api-client/base-client.d.ts +31 -36
- package/dist/api-client/base-client.js +114 -118
- package/dist/api-client/base-client.js.map +1 -1
- package/dist/api-client/file-writer.cjs +62 -0
- package/dist/api-client/file-writer.cjs.map +1 -0
- package/dist/api-client/file-writer.d.cts +66 -0
- package/dist/api-client/file-writer.d.ts +56 -42
- package/dist/api-client/file-writer.js +57 -61
- package/dist/api-client/file-writer.js.map +1 -1
- package/dist/api-client/index.cjs +2 -0
- package/dist/api-client/index.d.ts +2 -2
- package/dist/api-client/index.js +4 -21
- package/dist/api-client/validators.cjs +229 -0
- package/dist/api-client/validators.cjs.map +1 -0
- package/dist/api-client/validators.d.cts +26885 -0
- package/dist/api-client/validators.d.ts +26732 -3706
- package/dist/api-client/validators.js +198 -191
- package/dist/api-client/validators.js.map +1 -1
- package/dist/api-client/with-retry.cjs +89 -0
- package/dist/api-client/with-retry.cjs.map +1 -0
- package/dist/api-client/with-retry.d.cts +10 -0
- package/dist/api-client/with-retry.d.ts +9 -13
- package/dist/api-client/with-retry.js +81 -102
- package/dist/api-client/with-retry.js.map +1 -1
- package/dist/auth/api.cjs +29 -0
- package/dist/auth/api.cjs.map +1 -0
- package/dist/auth/api.js +26 -25
- package/dist/auth/api.js.map +1 -1
- package/dist/auth/error.cjs +13 -0
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.js +11 -11
- package/dist/auth/error.js.map +1 -1
- package/dist/auth/file.cjs +64 -0
- package/dist/auth/file.cjs.map +1 -0
- package/dist/auth/file.d.cts +26 -0
- package/dist/auth/file.d.ts +19 -15
- package/dist/auth/file.js +49 -64
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/index.cjs +11 -0
- package/dist/auth/index.d.cts +5 -0
- package/dist/auth/index.d.ts +5 -6
- package/dist/auth/index.js +6 -27
- package/dist/auth/linked-project.cjs +38 -0
- package/dist/auth/linked-project.cjs.map +1 -0
- package/dist/auth/linked-project.js +30 -64
- package/dist/auth/linked-project.js.map +1 -1
- package/dist/auth/oauth.cjs +205 -0
- package/dist/auth/oauth.cjs.map +1 -0
- package/dist/auth/oauth.d.cts +135 -0
- package/dist/auth/oauth.d.ts +113 -109
- package/dist/auth/oauth.js +185 -252
- package/dist/auth/oauth.js.map +1 -1
- package/dist/auth/poll-for-token.cjs +82 -0
- package/dist/auth/poll-for-token.cjs.map +1 -0
- package/dist/auth/poll-for-token.d.cts +28 -0
- package/dist/auth/poll-for-token.d.ts +23 -15
- package/dist/auth/poll-for-token.js +79 -64
- package/dist/auth/poll-for-token.js.map +1 -1
- package/dist/auth/project.cjs +178 -0
- package/dist/auth/project.cjs.map +1 -0
- package/dist/auth/project.d.cts +40 -0
- package/dist/auth/project.d.ts +19 -19
- package/dist/auth/project.js +169 -72
- package/dist/auth/project.js.map +1 -1
- package/dist/auth/zod.cjs +22 -0
- package/dist/auth/zod.cjs.map +1 -0
- package/dist/auth/zod.js +18 -17
- package/dist/auth/zod.js.map +1 -1
- package/dist/command.cjs +328 -0
- package/dist/command.cjs.map +1 -0
- package/dist/command.d.cts +289 -0
- package/dist/command.d.ts +265 -171
- package/dist/command.js +323 -226
- package/dist/command.js.map +1 -1
- package/dist/constants.d.cts +5 -0
- package/dist/constants.d.ts +5 -1
- package/dist/filesystem.cjs +499 -0
- package/dist/filesystem.cjs.map +1 -0
- package/dist/filesystem.d.cts +258 -0
- package/dist/filesystem.d.ts +258 -0
- package/dist/filesystem.js +497 -0
- package/dist/filesystem.js.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.js +8 -17
- package/dist/network-policy.d.cts +156 -0
- package/dist/network-policy.d.ts +88 -28
- package/dist/sandbox.cjs +816 -0
- package/dist/sandbox.cjs.map +1 -0
- package/dist/sandbox.d.cts +2847 -0
- package/dist/sandbox.d.ts +2834 -628
- package/dist/sandbox.js +808 -557
- package/dist/sandbox.js.map +1 -1
- package/dist/session.cjs +527 -0
- package/dist/session.cjs.map +1 -0
- package/dist/session.d.cts +410 -0
- package/dist/session.d.ts +403 -368
- package/dist/session.js +524 -489
- package/dist/session.js.map +1 -1
- package/dist/snapshot.cjs +204 -0
- package/dist/snapshot.cjs.map +1 -0
- package/dist/snapshot.d.cts +161 -0
- package/dist/snapshot.d.ts +152 -92
- package/dist/snapshot.js +201 -114
- package/dist/snapshot.js.map +1 -1
- package/dist/utils/array.cjs +17 -0
- package/dist/utils/array.cjs.map +1 -0
- package/dist/utils/array.js +12 -15
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/consume-readable.cjs +18 -0
- package/dist/utils/consume-readable.cjs.map +1 -0
- package/dist/utils/consume-readable.js +13 -12
- package/dist/utils/consume-readable.js.map +1 -1
- package/dist/utils/decode-base64-url.cjs +15 -0
- package/dist/utils/decode-base64-url.cjs.map +1 -0
- package/dist/utils/decode-base64-url.js +10 -9
- package/dist/utils/decode-base64-url.js.map +1 -1
- package/dist/utils/dev-credentials.cjs +142 -0
- package/dist/utils/dev-credentials.cjs.map +1 -0
- package/dist/utils/dev-credentials.js +126 -184
- package/dist/utils/dev-credentials.js.map +1 -1
- package/dist/utils/get-credentials.cjs +123 -0
- package/dist/utils/get-credentials.cjs.map +1 -0
- package/dist/utils/get-credentials.d.cts +21 -0
- package/dist/utils/get-credentials.d.ts +19 -61
- package/dist/utils/get-credentials.js +106 -140
- package/dist/utils/get-credentials.js.map +1 -1
- package/dist/utils/log.cjs +25 -0
- package/dist/utils/log.cjs.map +1 -0
- package/dist/utils/log.js +15 -17
- package/dist/utils/log.js.map +1 -1
- package/dist/utils/network-policy.cjs +49 -0
- package/dist/utils/network-policy.cjs.map +1 -0
- package/dist/utils/network-policy.js +42 -77
- package/dist/utils/network-policy.js.map +1 -1
- package/dist/utils/normalizePath.cjs +27 -0
- package/dist/utils/normalizePath.cjs.map +1 -0
- package/dist/utils/normalizePath.js +21 -28
- package/dist/utils/normalizePath.js.map +1 -1
- package/dist/utils/paginator.cjs +41 -0
- package/dist/utils/paginator.cjs.map +1 -0
- package/dist/utils/paginator.d.cts +16 -0
- package/dist/utils/paginator.d.ts +16 -0
- package/dist/utils/paginator.js +40 -0
- package/dist/utils/paginator.js.map +1 -0
- package/dist/utils/resolveSignal.cjs +20 -0
- package/dist/utils/resolveSignal.cjs.map +1 -0
- package/dist/utils/resolveSignal.d.cts +15 -0
- package/dist/utils/resolveSignal.d.ts +12 -10
- package/dist/utils/resolveSignal.js +14 -17
- package/dist/utils/resolveSignal.js.map +1 -1
- package/dist/utils/sandbox-snapshot.cjs +14 -0
- package/dist/utils/sandbox-snapshot.cjs.map +1 -0
- package/dist/utils/sandbox-snapshot.d.cts +10 -0
- package/dist/utils/sandbox-snapshot.d.ts +11 -0
- package/dist/utils/sandbox-snapshot.js +14 -0
- package/dist/utils/sandbox-snapshot.js.map +1 -0
- package/dist/utils/types.cjs +13 -0
- package/dist/utils/types.cjs.map +1 -0
- package/dist/utils/types.d.cts +11 -0
- package/dist/utils/types.d.ts +5 -7
- package/dist/utils/types.js +8 -8
- package/dist/utils/types.js.map +1 -1
- package/dist/version.cjs +7 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +5 -5
- package/dist/version.js.map +1 -1
- package/package.json +23 -3
- package/dist/api-client/index.js.map +0 -1
- package/dist/auth/api.d.ts +0 -6
- package/dist/auth/error.d.ts +0 -11
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/linked-project.d.ts +0 -10
- package/dist/auth/zod.d.ts +0 -5
- package/dist/constants.js +0 -3
- package/dist/constants.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/network-policy.js +0 -3
- package/dist/network-policy.js.map +0 -1
- package/dist/utils/array.d.ts +0 -9
- package/dist/utils/consume-readable.d.ts +0 -5
- package/dist/utils/convert-sandbox.d.ts +0 -6
- package/dist/utils/convert-sandbox.js +0 -14
- package/dist/utils/convert-sandbox.js.map +0 -1
- package/dist/utils/decode-base64-url.d.ts +0 -7
- package/dist/utils/dev-credentials.d.ts +0 -37
- package/dist/utils/log.d.ts +0 -2
- package/dist/utils/network-policy.d.ts +0 -7
- package/dist/utils/normalizePath.d.ts +0 -17
- package/dist/version.d.ts +0 -1
package/dist/utils/array.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.array = array;
|
|
1
|
+
//#region src/utils/array.ts
|
|
4
2
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
* Returns an array from the given item. If the item is an array it will be
|
|
4
|
+
* returned as a it is, otherwise it will be returned as a single item array.
|
|
5
|
+
* If the item is undefined or null an empty array will be returned.
|
|
6
|
+
*
|
|
7
|
+
* @param item The item to convert to an array.
|
|
8
|
+
* @returns An array.
|
|
9
|
+
*/
|
|
12
10
|
function array(item) {
|
|
13
|
-
|
|
14
|
-
? Array.isArray(item)
|
|
15
|
-
? item
|
|
16
|
-
: [item]
|
|
17
|
-
: [];
|
|
11
|
+
return item !== void 0 && item !== null ? Array.isArray(item) ? item : [item] : [];
|
|
18
12
|
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { array };
|
|
19
16
|
//# sourceMappingURL=array.js.map
|
package/dist/utils/array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","
|
|
1
|
+
{"version":3,"file":"array.js","names":[],"sources":["../../src/utils/array.ts"],"sourcesContent":["/**\n * Returns an array from the given item. If the item is an array it will be\n * returned as a it is, otherwise it will be returned as a single item array.\n * If the item is undefined or null an empty array will be returned.\n *\n * @param item The item to convert to an array.\n * @returns An array.\n */\nexport function array<T>(item?: null | T | T[]): T[] {\n return item !== undefined && item !== null\n ? Array.isArray(item)\n ? item\n : [item]\n : [];\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,MAAS,MAA4B;AACnD,QAAO,SAAS,UAAa,SAAS,OAClC,MAAM,QAAQ,KAAK,GACjB,OACA,CAAC,KAAK,GACR,EAAE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/consume-readable.ts
|
|
3
|
+
/**
|
|
4
|
+
* Consumes a readable entirely concatenating all content in a single Buffer
|
|
5
|
+
* @param readable A Readable stream
|
|
6
|
+
*/
|
|
7
|
+
function consumeReadable(readable) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const chunks = [];
|
|
10
|
+
readable.on("error", (err) => reject(err));
|
|
11
|
+
readable.on("data", (chunk) => chunks.push(chunk));
|
|
12
|
+
readable.on("end", () => resolve(Buffer.concat(chunks)));
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.consumeReadable = consumeReadable;
|
|
18
|
+
//# sourceMappingURL=consume-readable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consume-readable.cjs","names":["chunks: Buffer[]"],"sources":["../../src/utils/consume-readable.ts"],"sourcesContent":["/**\n * Consumes a readable entirely concatenating all content in a single Buffer\n * @param readable A Readable stream\n */\nexport function consumeReadable(readable: NodeJS.ReadableStream) {\n return new Promise<Buffer>((resolve, reject) => {\n const chunks: Buffer[] = [];\n readable.on(\"error\", (err) => reject(err));\n readable.on(\"data\", (chunk) => chunks.push(chunk));\n readable.on(\"end\", () => resolve(Buffer.concat(chunks)));\n });\n}\n"],"mappings":";;;;;;AAIA,SAAgB,gBAAgB,UAAiC;AAC/D,QAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAMA,SAAmB,EAAE;AAC3B,WAAS,GAAG,UAAU,QAAQ,OAAO,IAAI,CAAC;AAC1C,WAAS,GAAG,SAAS,UAAU,OAAO,KAAK,MAAM,CAAC;AAClD,WAAS,GAAG,aAAa,QAAQ,OAAO,OAAO,OAAO,CAAC,CAAC;GACxD"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.consumeReadable = consumeReadable;
|
|
1
|
+
//#region src/utils/consume-readable.ts
|
|
4
2
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
* Consumes a readable entirely concatenating all content in a single Buffer
|
|
4
|
+
* @param readable A Readable stream
|
|
5
|
+
*/
|
|
8
6
|
function consumeReadable(readable) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const chunks = [];
|
|
9
|
+
readable.on("error", (err) => reject(err));
|
|
10
|
+
readable.on("data", (chunk) => chunks.push(chunk));
|
|
11
|
+
readable.on("end", () => resolve(Buffer.concat(chunks)));
|
|
12
|
+
});
|
|
15
13
|
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { consumeReadable };
|
|
16
17
|
//# sourceMappingURL=consume-readable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consume-readable.js","
|
|
1
|
+
{"version":3,"file":"consume-readable.js","names":["chunks: Buffer[]"],"sources":["../../src/utils/consume-readable.ts"],"sourcesContent":["/**\n * Consumes a readable entirely concatenating all content in a single Buffer\n * @param readable A Readable stream\n */\nexport function consumeReadable(readable: NodeJS.ReadableStream) {\n return new Promise<Buffer>((resolve, reject) => {\n const chunks: Buffer[] = [];\n readable.on(\"error\", (err) => reject(err));\n readable.on(\"data\", (chunk) => chunks.push(chunk));\n readable.on(\"end\", () => resolve(Buffer.concat(chunks)));\n });\n}\n"],"mappings":";;;;;AAIA,SAAgB,gBAAgB,UAAiC;AAC/D,QAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAMA,SAAmB,EAAE;AAC3B,WAAS,GAAG,UAAU,QAAQ,OAAO,IAAI,CAAC;AAC1C,WAAS,GAAG,SAAS,UAAU,OAAO,KAAK,MAAM,CAAC;AAClD,WAAS,GAAG,aAAa,QAAQ,OAAO,OAAO,OAAO,CAAC,CAAC;GACxD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/decode-base64-url.ts
|
|
3
|
+
/**
|
|
4
|
+
* Decode a Base64 URL-encoded string into a JSON object.
|
|
5
|
+
*
|
|
6
|
+
* @param base64Url - The Base64 URL-encoded string to decode.
|
|
7
|
+
* @returns The decoded JSON object or null if decoding fails.
|
|
8
|
+
*/
|
|
9
|
+
function decodeBase64Url(base64Url) {
|
|
10
|
+
return JSON.parse(Buffer.from(base64Url.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.decodeBase64Url = decodeBase64Url;
|
|
15
|
+
//# sourceMappingURL=decode-base64-url.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-base64-url.cjs","names":[],"sources":["../../src/utils/decode-base64-url.ts"],"sourcesContent":["/**\n * Decode a Base64 URL-encoded string into a JSON object.\n *\n * @param base64Url - The Base64 URL-encoded string to decode.\n * @returns The decoded JSON object or null if decoding fails.\n */\nexport function decodeBase64Url(base64Url: string) {\n return JSON.parse(\n Buffer.from(\n base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\"),\n \"base64\",\n ).toString(\"utf8\"),\n );\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,gBAAgB,WAAmB;AACjD,QAAO,KAAK,MACV,OAAO,KACL,UAAU,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,IAAI,EAC/C,SACD,CAAC,SAAS,OAAO,CACnB"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decodeBase64Url = decodeBase64Url;
|
|
1
|
+
//#region src/utils/decode-base64-url.ts
|
|
4
2
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
* Decode a Base64 URL-encoded string into a JSON object.
|
|
4
|
+
*
|
|
5
|
+
* @param base64Url - The Base64 URL-encoded string to decode.
|
|
6
|
+
* @returns The decoded JSON object or null if decoding fails.
|
|
7
|
+
*/
|
|
10
8
|
function decodeBase64Url(base64Url) {
|
|
11
|
-
|
|
9
|
+
return JSON.parse(Buffer.from(base64Url.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
|
|
12
10
|
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { decodeBase64Url };
|
|
13
14
|
//# sourceMappingURL=decode-base64-url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode-base64-url.js","
|
|
1
|
+
{"version":3,"file":"decode-base64-url.js","names":[],"sources":["../../src/utils/decode-base64-url.ts"],"sourcesContent":["/**\n * Decode a Base64 URL-encoded string into a JSON object.\n *\n * @param base64Url - The Base64 URL-encoded string to decode.\n * @returns The decoded JSON object or null if decoding fails.\n */\nexport function decodeBase64Url(base64Url: string) {\n return JSON.parse(\n Buffer.from(\n base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\"),\n \"base64\",\n ).toString(\"utf8\"),\n );\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,gBAAgB,WAAmB;AACjD,QAAO,KAAK,MACV,OAAO,KACL,UAAU,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,IAAI,EAC/C,SACD,CAAC,SAAS,OAAO,CACnB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_log = require('./log.cjs');
|
|
3
|
+
let picocolors = require("picocolors");
|
|
4
|
+
picocolors = require_rolldown_runtime.__toESM(picocolors);
|
|
5
|
+
let ms = require("ms");
|
|
6
|
+
ms = require_rolldown_runtime.__toESM(ms);
|
|
7
|
+
|
|
8
|
+
//#region src/utils/dev-credentials.ts
|
|
9
|
+
async function importAuth() {
|
|
10
|
+
return await Promise.resolve().then(() => require("../auth/index.cjs"));
|
|
11
|
+
}
|
|
12
|
+
function shouldPromptForCredentials() {
|
|
13
|
+
return process.env.NODE_ENV !== "production" && !["1", "true"].includes(process.env.CI || "") && process.stdout.isTTY && process.stdin.isTTY;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns cached credentials for the given team/project combination.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* The cache is keyed by `teamId` and `projectId`. A new credential generation
|
|
20
|
+
* is triggered only when these values change or when a previous attempt failed.
|
|
21
|
+
*
|
|
22
|
+
* **Important:** Successfully resolved credentials are cached indefinitely and
|
|
23
|
+
* will not be refreshed even if the token expires. Cache invalidation only occurs
|
|
24
|
+
* on rejection (error). This is intentional for development use cases where
|
|
25
|
+
* short-lived sessions don't require proactive token refresh.
|
|
26
|
+
*/
|
|
27
|
+
const cachedGenerateCredentials = (() => {
|
|
28
|
+
let cache = null;
|
|
29
|
+
return async (opts) => {
|
|
30
|
+
if (!cache || cache[0].teamId !== opts.teamId || cache[0].projectId !== opts.projectId) cache = [opts, generateCredentials(opts).catch((err) => {
|
|
31
|
+
cache = null;
|
|
32
|
+
throw err;
|
|
33
|
+
})];
|
|
34
|
+
const v = await cache[1];
|
|
35
|
+
require_log.write("warn", `using inferred credentials team=${v.teamId} project=${v.projectId}`);
|
|
36
|
+
return v;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
/**
|
|
40
|
+
* Generates credentials by authenticating and inferring scope.
|
|
41
|
+
*
|
|
42
|
+
* @internal This is exported for testing purposes. Consider using
|
|
43
|
+
* {@link cachedGenerateCredentials} instead, which caches the result
|
|
44
|
+
* to avoid redundant authentication flows.
|
|
45
|
+
*/
|
|
46
|
+
async function generateCredentials(opts) {
|
|
47
|
+
const { OAuth, pollForToken, getAuth, updateAuthConfig, inferScope } = await importAuth();
|
|
48
|
+
let auth = getAuth();
|
|
49
|
+
if (!auth?.token) {
|
|
50
|
+
const timeout = process.env.VERCEL_URL ? "1 minute" : "5 minutes";
|
|
51
|
+
auth = await signInAndGetToken({
|
|
52
|
+
OAuth,
|
|
53
|
+
pollForToken,
|
|
54
|
+
getAuth
|
|
55
|
+
}, timeout);
|
|
56
|
+
}
|
|
57
|
+
if (auth?.refreshToken && auth.expiresAt && auth.expiresAt.getTime() <= Date.now()) {
|
|
58
|
+
const newToken = await (await OAuth()).refreshToken(auth.refreshToken);
|
|
59
|
+
auth = {
|
|
60
|
+
expiresAt: new Date(Date.now() + newToken.expires_in * 1e3),
|
|
61
|
+
token: newToken.access_token,
|
|
62
|
+
refreshToken: newToken.refresh_token || auth.refreshToken
|
|
63
|
+
};
|
|
64
|
+
updateAuthConfig(auth);
|
|
65
|
+
}
|
|
66
|
+
if (!auth?.token) throw new Error([
|
|
67
|
+
`Failed to retrieve authentication token.`,
|
|
68
|
+
`${picocolors.default.bold("hint:")} Set VERCEL_OIDC_TOKEN or provide a Vercel API token.`,
|
|
69
|
+
"├▶ Sandbox docs: https://vercel.com/docs/vercel-sandbox",
|
|
70
|
+
"╰▶ Access tokens: https://vercel.com/kb/guide/how-do-i-use-a-vercel-api-access-token"
|
|
71
|
+
].join("\n"));
|
|
72
|
+
if (opts.teamId && opts.projectId) return {
|
|
73
|
+
token: auth.token,
|
|
74
|
+
teamId: opts.teamId,
|
|
75
|
+
projectId: opts.projectId
|
|
76
|
+
};
|
|
77
|
+
const scope = await inferScope({
|
|
78
|
+
teamId: opts.teamId,
|
|
79
|
+
token: auth.token
|
|
80
|
+
});
|
|
81
|
+
if (scope.created) require_log.write("info", `Created default project "${scope.projectId}" in team "${scope.teamId}".`);
|
|
82
|
+
return {
|
|
83
|
+
token: auth.token,
|
|
84
|
+
teamId: opts.teamId || scope.teamId,
|
|
85
|
+
projectId: opts.projectId || scope.projectId
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function signInAndGetToken(auth, timeout) {
|
|
89
|
+
require_log.write("warn", [
|
|
90
|
+
`No VERCEL_OIDC_TOKEN environment variable found, initiating device authorization flow...`,
|
|
91
|
+
`│ ${picocolors.default.bold("help:")} this flow only happens on development environment.`,
|
|
92
|
+
`│ In production, make sure to set up a proper token, or set up Vercel OIDC [https://vercel.com/docs/oidc].`
|
|
93
|
+
]);
|
|
94
|
+
const oauth = await auth.OAuth();
|
|
95
|
+
const request = await oauth.deviceAuthorizationRequest();
|
|
96
|
+
require_log.write("info", [
|
|
97
|
+
`╰▶ To authenticate, visit: ${request.verification_uri_complete}`,
|
|
98
|
+
` or visit ${picocolors.default.italic(request.verification_uri)} and type ${picocolors.default.bold(request.user_code)}`,
|
|
99
|
+
` Press ${picocolors.default.bold("<return>")} to open in your browser`
|
|
100
|
+
]);
|
|
101
|
+
let error;
|
|
102
|
+
const generator = auth.pollForToken({
|
|
103
|
+
request,
|
|
104
|
+
oauth
|
|
105
|
+
});
|
|
106
|
+
let done = false;
|
|
107
|
+
let spawnedTimeout = setTimeout(() => {
|
|
108
|
+
if (done) return;
|
|
109
|
+
const message = [
|
|
110
|
+
`Authentication flow timed out after ${timeout}.`,
|
|
111
|
+
`│ Make sure to provide a token to avoid prompting an interactive flow.`,
|
|
112
|
+
`╰▶ ${picocolors.default.bold("help:")} Link your project with ${require_log.code("npx vercel link")} to refresh OIDC token automatically.`
|
|
113
|
+
].join("\n");
|
|
114
|
+
error = new Error(message);
|
|
115
|
+
generator.return();
|
|
116
|
+
}, (0, ms.default)(timeout));
|
|
117
|
+
try {
|
|
118
|
+
for await (const event of generator) switch (event._tag) {
|
|
119
|
+
case "SlowDown":
|
|
120
|
+
case "Timeout":
|
|
121
|
+
case "Response": break;
|
|
122
|
+
case "Error":
|
|
123
|
+
error = event.error;
|
|
124
|
+
break;
|
|
125
|
+
default: throw new Error(`Unknown event type: ${JSON.stringify(event)}`);
|
|
126
|
+
}
|
|
127
|
+
} finally {
|
|
128
|
+
done = true;
|
|
129
|
+
clearTimeout(spawnedTimeout);
|
|
130
|
+
}
|
|
131
|
+
if (error) {
|
|
132
|
+
require_log.write("error", `${picocolors.default.bold("error:")} Authentication failed: ${error.message}`);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
require_log.write("success", `${picocolors.default.bold("done!")} Authenticated successfully!`);
|
|
136
|
+
return auth.getAuth();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
exports.cachedGenerateCredentials = cachedGenerateCredentials;
|
|
141
|
+
exports.shouldPromptForCredentials = shouldPromptForCredentials;
|
|
142
|
+
//# sourceMappingURL=dev-credentials.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-credentials.cjs","names":["cache:\n | [{ teamId?: string; projectId?: string }, Promise<Credentials>]\n | null","timeout: ms.StringValue","pico","error: Error | undefined"],"sources":["../../src/utils/dev-credentials.ts"],"sourcesContent":["import pico from \"picocolors\";\nimport type { Credentials } from \"./get-credentials.js\";\nimport ms from \"ms\";\nimport * as Log from \"./log.js\";\n\nasync function importAuth() {\n const auth = await import(\"../auth/index.js\");\n return auth;\n}\n\nexport function shouldPromptForCredentials(): boolean {\n return (\n process.env.NODE_ENV !== \"production\" &&\n ![\"1\", \"true\"].includes(process.env.CI || \"\") &&\n process.stdout.isTTY &&\n process.stdin.isTTY\n );\n}\n\n/**\n * Returns cached credentials for the given team/project combination.\n *\n * @remarks\n * The cache is keyed by `teamId` and `projectId`. A new credential generation\n * is triggered only when these values change or when a previous attempt failed.\n *\n * **Important:** Successfully resolved credentials are cached indefinitely and\n * will not be refreshed even if the token expires. Cache invalidation only occurs\n * on rejection (error). This is intentional for development use cases where\n * short-lived sessions don't require proactive token refresh.\n */\nexport const cachedGenerateCredentials = (() => {\n let cache:\n | [{ teamId?: string; projectId?: string }, Promise<Credentials>]\n | null = null;\n return async (opts: { projectId?: string; teamId?: string }) => {\n if (\n !cache ||\n cache[0].teamId !== opts.teamId ||\n cache[0].projectId !== opts.projectId\n ) {\n const promise = generateCredentials(opts).catch((err) => {\n cache = null;\n throw err;\n });\n cache = [opts, promise];\n }\n const v = await cache[1];\n Log.write(\n \"warn\",\n `using inferred credentials team=${v.teamId} project=${v.projectId}`,\n );\n return v;\n };\n})();\n\n/**\n * Generates credentials by authenticating and inferring scope.\n *\n * @internal This is exported for testing purposes. Consider using\n * {@link cachedGenerateCredentials} instead, which caches the result\n * to avoid redundant authentication flows.\n */\nexport async function generateCredentials(opts: {\n teamId?: string;\n projectId?: string;\n}): Promise<Credentials> {\n const { OAuth, pollForToken, getAuth, updateAuthConfig, inferScope } =\n await importAuth();\n let auth = getAuth();\n if (!auth?.token) {\n const timeout: ms.StringValue = process.env.VERCEL_URL\n ? /* when deployed to vercel we don't want to have a long timeout */ \"1 minute\"\n : \"5 minutes\";\n auth = await signInAndGetToken({ OAuth, pollForToken, getAuth }, timeout);\n }\n if (\n auth?.refreshToken &&\n auth.expiresAt &&\n auth.expiresAt.getTime() <= Date.now()\n ) {\n const oauth = await OAuth();\n const newToken = await oauth.refreshToken(auth.refreshToken);\n auth = {\n expiresAt: new Date(Date.now() + newToken.expires_in * 1000),\n token: newToken.access_token,\n refreshToken: newToken.refresh_token || auth.refreshToken,\n };\n updateAuthConfig(auth);\n }\n\n if (!auth?.token) {\n throw new Error(\n [\n `Failed to retrieve authentication token.`,\n `${pico.bold(\"hint:\")} Set VERCEL_OIDC_TOKEN or provide a Vercel API token.`,\n \"├▶ Sandbox docs: https://vercel.com/docs/vercel-sandbox\",\n \"╰▶ Access tokens: https://vercel.com/kb/guide/how-do-i-use-a-vercel-api-access-token\",\n ].join(\"\\n\"),\n );\n }\n\n if (opts.teamId && opts.projectId) {\n return {\n token: auth.token,\n teamId: opts.teamId,\n projectId: opts.projectId,\n };\n }\n\n const scope = await inferScope({ teamId: opts.teamId, token: auth.token });\n\n if (scope.created) {\n Log.write(\n \"info\",\n `Created default project \"${scope.projectId}\" in team \"${scope.teamId}\".`,\n );\n }\n\n return {\n token: auth.token,\n teamId: opts.teamId || scope.teamId,\n projectId: opts.projectId || scope.projectId,\n };\n}\n\nexport async function signInAndGetToken(\n auth: Pick<\n Awaited<ReturnType<typeof importAuth>>,\n \"OAuth\" | \"getAuth\" | \"pollForToken\"\n >,\n timeout: ms.StringValue,\n) {\n Log.write(\"warn\", [\n `No VERCEL_OIDC_TOKEN environment variable found, initiating device authorization flow...`,\n `│ ${pico.bold(\"help:\")} this flow only happens on development environment.`,\n `│ In production, make sure to set up a proper token, or set up Vercel OIDC [https://vercel.com/docs/oidc].`,\n ]);\n const oauth = await auth.OAuth();\n const request = await oauth.deviceAuthorizationRequest();\n Log.write(\"info\", [\n `╰▶ To authenticate, visit: ${request.verification_uri_complete}`,\n ` or visit ${pico.italic(request.verification_uri)} and type ${pico.bold(request.user_code)}`,\n ` Press ${pico.bold(\"<return>\")} to open in your browser`,\n ]);\n\n let error: Error | undefined;\n const generator = auth.pollForToken({ request, oauth });\n let done = false;\n let spawnedTimeout = setTimeout(() => {\n if (done) return;\n const message = [\n `Authentication flow timed out after ${timeout}.`,\n `│ Make sure to provide a token to avoid prompting an interactive flow.`,\n `╰▶ ${pico.bold(\"help:\")} Link your project with ${Log.code(\"npx vercel link\")} to refresh OIDC token automatically.`,\n ].join(\"\\n\");\n error = new Error(message);\n // Note: generator.return() initiates cooperative cancellation. The generator's\n // finally block will abort pending setTimeout calls, but any in-flight HTTP\n // request will complete before the generator terminates. This is acceptable\n // for this dev-only timeout scenario.\n generator.return();\n }, ms(timeout));\n try {\n for await (const event of generator) {\n switch (event._tag) {\n case \"SlowDown\":\n case \"Timeout\":\n case \"Response\":\n break;\n case \"Error\":\n error = event.error;\n break;\n default:\n throw new Error(\n `Unknown event type: ${JSON.stringify(event satisfies never)}`,\n );\n }\n }\n } finally {\n done = true;\n clearTimeout(spawnedTimeout);\n }\n\n if (error) {\n Log.write(\n \"error\",\n `${pico.bold(\"error:\")} Authentication failed: ${error.message}`,\n );\n throw error;\n }\n\n Log.write(\"success\", `${pico.bold(\"done!\")} Authenticated successfully!`);\n const stored = auth.getAuth();\n return stored;\n}\n"],"mappings":"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"}
|