@vercel/sandbox 1.9.0 → 1.9.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.
- package/README.md +8 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/api-client/api-client.cjs +375 -0
- package/dist/api-client/api-client.cjs.map +1 -0
- package/dist/api-client/api-client.d.cts +403 -0
- package/dist/api-client/api-client.d.ts +397 -392
- package/dist/api-client/api-client.js +365 -405
- package/dist/api-client/api-client.js.map +1 -1
- package/dist/api-client/api-error.cjs +31 -0
- package/dist/api-client/api-error.cjs.map +1 -0
- package/dist/api-client/api-error.d.cts +27 -0
- package/dist/api-client/api-error.d.ts +19 -16
- package/dist/api-client/api-error.js +27 -32
- package/dist/api-client/api-error.js.map +1 -1
- package/dist/api-client/base-client.cjs +113 -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 +101 -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 -52
- 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 +149 -0
- package/dist/api-client/validators.cjs.map +1 -0
- package/dist/api-client/validators.d.cts +1677 -0
- package/dist/api-client/validators.d.ts +1501 -2412
- package/dist/api-client/validators.js +124 -154
- 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 +12 -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 +80 -0
- package/dist/auth/project.cjs.map +1 -0
- package/dist/auth/project.d.cts +44 -0
- package/dist/auth/project.d.ts +12 -8
- package/dist/auth/project.js +70 -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 +326 -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 +321 -226
- package/dist/command.js.map +1 -1
- package/dist/constants.d.cts +5 -0
- package/dist/constants.d.ts +5 -1
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -15
- package/dist/network-policy.d.cts +100 -0
- package/dist/network-policy.d.ts +32 -28
- package/dist/sandbox.cjs +543 -0
- package/dist/sandbox.cjs.map +1 -0
- package/dist/sandbox.d.cts +538 -0
- package/dist/sandbox.d.ts +521 -479
- package/dist/sandbox.js +539 -512
- package/dist/sandbox.js.map +1 -1
- package/dist/snapshot.cjs +116 -0
- package/dist/snapshot.cjs.map +1 -0
- package/dist/snapshot.d.cts +109 -0
- package/dist/snapshot.d.ts +100 -92
- package/dist/snapshot.js +114 -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 +65 -0
- package/dist/utils/network-policy.cjs.map +1 -0
- package/dist/utils/network-policy.js +58 -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/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
|
@@ -1,108 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.withRetry = withRetry;
|
|
7
|
-
const api_error_1 = require("./api-error");
|
|
8
|
-
const promises_1 = require("node:timers/promises");
|
|
9
|
-
const async_retry_1 = __importDefault(require("async-retry"));
|
|
1
|
+
import { APIError } from "./api-error.js";
|
|
2
|
+
import { setTimeout } from "node:timers/promises";
|
|
3
|
+
import retry from "async-retry";
|
|
4
|
+
|
|
5
|
+
//#region src/api-client/with-retry.ts
|
|
10
6
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
* Wraps a fetch function with retry logic. The retry logic will retry
|
|
8
|
+
* on network errors, 429 responses and 5xx responses. The retry logic
|
|
9
|
+
* will not retry on 4xx responses.
|
|
10
|
+
*
|
|
11
|
+
* @param rawFetch The fetch function to wrap.
|
|
12
|
+
* @returns The wrapped fetch function.
|
|
13
|
+
*/
|
|
18
14
|
function withRetry(rawFetch) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return bail(opts.signal.reason || new Error("Request aborted"));
|
|
85
|
-
}
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
}, retryOpts));
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
/**
|
|
92
|
-
* The ResponseError is only intended for retries so in case we
|
|
93
|
-
* ran out of attempts we will respond with the last response
|
|
94
|
-
* we obtained.
|
|
95
|
-
*/
|
|
96
|
-
if (error instanceof api_error_1.APIError) {
|
|
97
|
-
return error.response;
|
|
98
|
-
}
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
15
|
+
return async (url, opts = {}) => {
|
|
16
|
+
/**
|
|
17
|
+
* Timeouts by default will be [10, 60, 360, 2160, 12960]
|
|
18
|
+
* before randomization is added.
|
|
19
|
+
*/
|
|
20
|
+
const retryOpts = Object.assign({
|
|
21
|
+
minTimeout: 10,
|
|
22
|
+
retries: 5,
|
|
23
|
+
factor: 6,
|
|
24
|
+
maxRetryAfter: 20
|
|
25
|
+
}, opts.retry);
|
|
26
|
+
if (opts.onRetry) retryOpts.onRetry = (error, attempts) => {
|
|
27
|
+
opts.onRetry(error, opts);
|
|
28
|
+
if (opts.retry && opts.retry.onRetry) opts.retry.onRetry(error, attempts);
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
return await retry(async (bail) => {
|
|
32
|
+
try {
|
|
33
|
+
if (opts.signal?.aborted) return bail(opts.signal.reason || /* @__PURE__ */ new Error("Request aborted"));
|
|
34
|
+
const response = await rawFetch(url, opts);
|
|
35
|
+
/**
|
|
36
|
+
* When the response is 429 we will try to parse the Retry-After
|
|
37
|
+
* header. If the header exists we will try to parse it and, if
|
|
38
|
+
* the wait time is higher than the maximum defined, we respond.
|
|
39
|
+
* Otherwise we wait for the time given in the header and throw
|
|
40
|
+
* to retry.
|
|
41
|
+
*/
|
|
42
|
+
if (response.status === 429) {
|
|
43
|
+
const retryAfter = parseInt(response.headers.get("retry-after") || "", 10);
|
|
44
|
+
if (retryAfter && !isNaN(retryAfter)) {
|
|
45
|
+
if (retryAfter > retryOpts.maxRetryAfter) return response;
|
|
46
|
+
await setTimeout(retryAfter * 1e3);
|
|
47
|
+
}
|
|
48
|
+
throw new APIError(response);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* If the response is a a retryable error, we throw in
|
|
52
|
+
* order to retry.
|
|
53
|
+
*/
|
|
54
|
+
if (response.status >= 500 && response.status < 600) throw new APIError(response);
|
|
55
|
+
return response;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
/**
|
|
58
|
+
* If the request was aborted using the AbortController
|
|
59
|
+
* we bail from retrying throwing the original error.
|
|
60
|
+
*/
|
|
61
|
+
if (isAbortError(error)) return bail(error);
|
|
62
|
+
/**
|
|
63
|
+
* If the signal was aborted meanwhile we were
|
|
64
|
+
* waiting, we bail from retrying.
|
|
65
|
+
*/
|
|
66
|
+
if (opts.signal?.aborted) return bail(opts.signal.reason || /* @__PURE__ */ new Error("Request aborted"));
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}, retryOpts);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
/**
|
|
72
|
+
* The ResponseError is only intended for retries so in case we
|
|
73
|
+
* ran out of attempts we will respond with the last response
|
|
74
|
+
* we obtained.
|
|
75
|
+
*/
|
|
76
|
+
if (error instanceof APIError) return error.response;
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
102
80
|
}
|
|
103
81
|
function isAbortError(error) {
|
|
104
|
-
|
|
105
|
-
error !== null &&
|
|
106
|
-
error.name === "AbortError");
|
|
82
|
+
return error !== void 0 && error !== null && error.name === "AbortError";
|
|
107
83
|
}
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
export { withRetry };
|
|
108
87
|
//# sourceMappingURL=with-retry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-retry.js","
|
|
1
|
+
{"version":3,"file":"with-retry.js","names":[],"sources":["../../src/api-client/with-retry.ts"],"sourcesContent":["import type { Options as RetryOptions } from \"async-retry\";\nimport { APIError } from \"./api-error.js\";\nimport { setTimeout } from \"node:timers/promises\";\nimport retry from \"async-retry\";\n\nexport interface RequestOptions {\n onRetry?(error: any, options: RequestOptions): void;\n retry?: Partial<RetryOptions>;\n}\n\n/**\n * Wraps a fetch function with retry logic. The retry logic will retry\n * on network errors, 429 responses and 5xx responses. The retry logic\n * will not retry on 4xx responses.\n *\n * @param rawFetch The fetch function to wrap.\n * @returns The wrapped fetch function.\n */\nexport function withRetry<T extends RequestInit>(\n rawFetch: (url: URL | string, init?: T) => Promise<Response>,\n) {\n return async (\n url: URL | string,\n opts: T & RequestOptions = <T & RequestOptions>{},\n ) => {\n /**\n * Timeouts by default will be [10, 60, 360, 2160, 12960]\n * before randomization is added.\n */\n const retryOpts = Object.assign(\n {\n minTimeout: 10,\n retries: 5,\n factor: 6,\n maxRetryAfter: 20,\n },\n opts.retry,\n );\n\n if (opts.onRetry) {\n retryOpts.onRetry = (error, attempts) => {\n opts.onRetry!(error, opts);\n if (opts.retry && opts.retry.onRetry) {\n opts.retry.onRetry(error, attempts);\n }\n };\n }\n\n try {\n return (await retry(async (bail) => {\n try {\n if (opts.signal?.aborted) {\n return bail(opts.signal.reason || new Error(\"Request aborted\"));\n }\n const response = await rawFetch(url, opts);\n\n /**\n * When the response is 429 we will try to parse the Retry-After\n * header. If the header exists we will try to parse it and, if\n * the wait time is higher than the maximum defined, we respond.\n * Otherwise we wait for the time given in the header and throw\n * to retry.\n */\n if (response.status === 429) {\n const retryAfter = parseInt(\n response.headers.get(\"retry-after\") || \"\",\n 10,\n );\n\n if (retryAfter && !isNaN(retryAfter)) {\n if (retryAfter > retryOpts.maxRetryAfter) {\n return response;\n }\n\n await setTimeout(retryAfter * 1e3);\n }\n\n throw new APIError(response);\n }\n\n /**\n * If the response is a a retryable error, we throw in\n * order to retry.\n */\n if (response.status >= 500 && response.status < 600) {\n throw new APIError(response);\n }\n\n return response;\n } catch (error) {\n /**\n * If the request was aborted using the AbortController\n * we bail from retrying throwing the original error.\n */\n if (isAbortError(error)) {\n return bail(error);\n }\n\n /**\n * If the signal was aborted meanwhile we were\n * waiting, we bail from retrying.\n */\n if (opts.signal?.aborted) {\n return bail(opts.signal.reason || new Error(\"Request aborted\"));\n }\n\n throw error;\n }\n }, retryOpts)) as Response;\n } catch (error) {\n /**\n * The ResponseError is only intended for retries so in case we\n * ran out of attempts we will respond with the last response\n * we obtained.\n */\n if (error instanceof APIError) {\n return error.response;\n }\n\n throw error;\n }\n };\n}\n\nfunction isAbortError(error: unknown): error is Error {\n return (\n error !== undefined &&\n error !== null &&\n (error as Error).name === \"AbortError\"\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAgB,UACd,UACA;AACA,QAAO,OACL,KACA,OAA+C,EAAE,KAC9C;;;;;EAKH,MAAM,YAAY,OAAO,OACvB;GACE,YAAY;GACZ,SAAS;GACT,QAAQ;GACR,eAAe;GAChB,EACD,KAAK,MACN;AAED,MAAI,KAAK,QACP,WAAU,WAAW,OAAO,aAAa;AACvC,QAAK,QAAS,OAAO,KAAK;AAC1B,OAAI,KAAK,SAAS,KAAK,MAAM,QAC3B,MAAK,MAAM,QAAQ,OAAO,SAAS;;AAKzC,MAAI;AACF,UAAQ,MAAM,MAAM,OAAO,SAAS;AAClC,QAAI;AACF,SAAI,KAAK,QAAQ,QACf,QAAO,KAAK,KAAK,OAAO,0BAAU,IAAI,MAAM,kBAAkB,CAAC;KAEjE,MAAM,WAAW,MAAM,SAAS,KAAK,KAAK;;;;;;;;AAS1C,SAAI,SAAS,WAAW,KAAK;MAC3B,MAAM,aAAa,SACjB,SAAS,QAAQ,IAAI,cAAc,IAAI,IACvC,GACD;AAED,UAAI,cAAc,CAAC,MAAM,WAAW,EAAE;AACpC,WAAI,aAAa,UAAU,cACzB,QAAO;AAGT,aAAM,WAAW,aAAa,IAAI;;AAGpC,YAAM,IAAI,SAAS,SAAS;;;;;;AAO9B,SAAI,SAAS,UAAU,OAAO,SAAS,SAAS,IAC9C,OAAM,IAAI,SAAS,SAAS;AAG9B,YAAO;aACA,OAAO;;;;;AAKd,SAAI,aAAa,MAAM,CACrB,QAAO,KAAK,MAAM;;;;;AAOpB,SAAI,KAAK,QAAQ,QACf,QAAO,KAAK,KAAK,OAAO,0BAAU,IAAI,MAAM,kBAAkB,CAAC;AAGjE,WAAM;;MAEP,UAAU;WACN,OAAO;;;;;;AAMd,OAAI,iBAAiB,SACnB,QAAO,MAAM;AAGf,SAAM;;;;AAKZ,SAAS,aAAa,OAAgC;AACpD,QACE,UAAU,UACV,UAAU,QACT,MAAgB,SAAS"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_error = require('./error.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/auth/api.ts
|
|
4
|
+
async function fetchApi(opts) {
|
|
5
|
+
const x = await fetch(`https://api.vercel.com${opts.endpoint}`, {
|
|
6
|
+
method: opts.method,
|
|
7
|
+
body: opts.body,
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: `Bearer ${opts.token}`,
|
|
10
|
+
"Content-Type": "application/json"
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
if (!x.ok) {
|
|
14
|
+
let message = await x.text();
|
|
15
|
+
try {
|
|
16
|
+
const { error } = JSON.parse(message);
|
|
17
|
+
message = `${error.code.toUpperCase()}: ${error.message}`;
|
|
18
|
+
} catch {}
|
|
19
|
+
throw new require_error.NotOk({
|
|
20
|
+
responseText: message,
|
|
21
|
+
statusCode: x.status
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return await x.json();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.fetchApi = fetchApi;
|
|
29
|
+
//# sourceMappingURL=api.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.cjs","names":["NotOk"],"sources":["../../src/auth/api.ts"],"sourcesContent":["import { NotOk } from \"./error.js\";\n\nexport async function fetchApi(opts: {\n token: string;\n endpoint: string;\n method?: string;\n body?: string;\n}): Promise<unknown> {\n const x = await fetch(`https://api.vercel.com${opts.endpoint}`, {\n method: opts.method,\n body: opts.body,\n headers: {\n Authorization: `Bearer ${opts.token}`,\n \"Content-Type\": \"application/json\",\n },\n });\n if (!x.ok) {\n let message = await x.text();\n\n try {\n const { error } = JSON.parse(message);\n message = `${error.code.toUpperCase()}: ${error.message}`;\n } catch {}\n\n throw new NotOk({\n responseText: message,\n statusCode: x.status,\n });\n }\n return (await x.json()) as unknown;\n}\n"],"mappings":";;;AAEA,eAAsB,SAAS,MAKV;CACnB,MAAM,IAAI,MAAM,MAAM,yBAAyB,KAAK,YAAY;EAC9D,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,SAAS;GACP,eAAe,UAAU,KAAK;GAC9B,gBAAgB;GACjB;EACF,CAAC;AACF,KAAI,CAAC,EAAE,IAAI;EACT,IAAI,UAAU,MAAM,EAAE,MAAM;AAE5B,MAAI;GACF,MAAM,EAAE,UAAU,KAAK,MAAM,QAAQ;AACrC,aAAU,GAAG,MAAM,KAAK,aAAa,CAAC,IAAI,MAAM;UAC1C;AAER,QAAM,IAAIA,oBAAM;GACd,cAAc;GACd,YAAY,EAAE;GACf,CAAC;;AAEJ,QAAQ,MAAM,EAAE,MAAM"}
|
package/dist/auth/api.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const error_1 = require("./error");
|
|
1
|
+
import { NotOk } from "./error.js";
|
|
2
|
+
|
|
3
|
+
//#region src/auth/api.ts
|
|
5
4
|
async function fetchApi(opts) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return (await x.json());
|
|
5
|
+
const x = await fetch(`https://api.vercel.com${opts.endpoint}`, {
|
|
6
|
+
method: opts.method,
|
|
7
|
+
body: opts.body,
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: `Bearer ${opts.token}`,
|
|
10
|
+
"Content-Type": "application/json"
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
if (!x.ok) {
|
|
14
|
+
let message = await x.text();
|
|
15
|
+
try {
|
|
16
|
+
const { error } = JSON.parse(message);
|
|
17
|
+
message = `${error.code.toUpperCase()}: ${error.message}`;
|
|
18
|
+
} catch {}
|
|
19
|
+
throw new NotOk({
|
|
20
|
+
responseText: message,
|
|
21
|
+
statusCode: x.status
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return await x.json();
|
|
27
25
|
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { fetchApi };
|
|
28
29
|
//# sourceMappingURL=api.js.map
|
package/dist/auth/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","
|
|
1
|
+
{"version":3,"file":"api.js","names":[],"sources":["../../src/auth/api.ts"],"sourcesContent":["import { NotOk } from \"./error.js\";\n\nexport async function fetchApi(opts: {\n token: string;\n endpoint: string;\n method?: string;\n body?: string;\n}): Promise<unknown> {\n const x = await fetch(`https://api.vercel.com${opts.endpoint}`, {\n method: opts.method,\n body: opts.body,\n headers: {\n Authorization: `Bearer ${opts.token}`,\n \"Content-Type\": \"application/json\",\n },\n });\n if (!x.ok) {\n let message = await x.text();\n\n try {\n const { error } = JSON.parse(message);\n message = `${error.code.toUpperCase()}: ${error.message}`;\n } catch {}\n\n throw new NotOk({\n responseText: message,\n statusCode: x.status,\n });\n }\n return (await x.json()) as unknown;\n}\n"],"mappings":";;;AAEA,eAAsB,SAAS,MAKV;CACnB,MAAM,IAAI,MAAM,MAAM,yBAAyB,KAAK,YAAY;EAC9D,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,SAAS;GACP,eAAe,UAAU,KAAK;GAC9B,gBAAgB;GACjB;EACF,CAAC;AACF,KAAI,CAAC,EAAE,IAAI;EACT,IAAI,UAAU,MAAM,EAAE,MAAM;AAE5B,MAAI;GACF,MAAM,EAAE,UAAU,KAAK,MAAM,QAAQ;AACrC,aAAU,GAAG,MAAM,KAAK,aAAa,CAAC,IAAI,MAAM;UAC1C;AAER,QAAM,IAAI,MAAM;GACd,cAAc;GACd,YAAY,EAAE;GACf,CAAC;;AAEJ,QAAQ,MAAM,EAAE,MAAM"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/auth/error.ts
|
|
3
|
+
var NotOk = class extends Error {
|
|
4
|
+
constructor(response) {
|
|
5
|
+
super(`HTTP ${response.statusCode}: ${response.responseText}`);
|
|
6
|
+
this.name = "NotOk";
|
|
7
|
+
this.response = response;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.NotOk = NotOk;
|
|
13
|
+
//# sourceMappingURL=error.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.cjs","names":[],"sources":["../../src/auth/error.ts"],"sourcesContent":["export class NotOk extends Error {\n name = \"NotOk\";\n response: { statusCode: number; responseText: string };\n constructor(response: { statusCode: number; responseText: string }) {\n super(`HTTP ${response.statusCode}: ${response.responseText}`);\n this.response = response;\n }\n}\n"],"mappings":";;AAAA,IAAa,QAAb,cAA2B,MAAM;CAG/B,YAAY,UAAwD;AAClE,QAAM,QAAQ,SAAS,WAAW,IAAI,SAAS,eAAe;OAHhE,OAAO;AAIL,OAAK,WAAW"}
|
package/dist/auth/error.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
//#region src/auth/error.ts
|
|
2
|
+
var NotOk = class extends Error {
|
|
3
|
+
constructor(response) {
|
|
4
|
+
super(`HTTP ${response.statusCode}: ${response.responseText}`);
|
|
5
|
+
this.name = "NotOk";
|
|
6
|
+
this.response = response;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { NotOk };
|
|
12
12
|
//# sourceMappingURL=error.js.map
|
package/dist/auth/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","
|
|
1
|
+
{"version":3,"file":"error.js","names":[],"sources":["../../src/auth/error.ts"],"sourcesContent":["export class NotOk extends Error {\n name = \"NotOk\";\n response: { statusCode: number; responseText: string };\n constructor(response: { statusCode: number; responseText: string }) {\n super(`HTTP ${response.statusCode}: ${response.responseText}`);\n this.response = response;\n }\n}\n"],"mappings":";AAAA,IAAa,QAAb,cAA2B,MAAM;CAG/B,YAAY,UAAwD;AAClE,QAAM,QAAQ,SAAS,WAAW,IAAI,SAAS,eAAe;OAHhE,OAAO;AAIL,OAAK,WAAW"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_zod = require('./zod.cjs');
|
|
3
|
+
let zod = require("zod");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
6
|
+
let node_fs = require("node:fs");
|
|
7
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
8
|
+
let node_os = require("node:os");
|
|
9
|
+
let xdg_app_paths = require("xdg-app-paths");
|
|
10
|
+
xdg_app_paths = require_rolldown_runtime.__toESM(xdg_app_paths);
|
|
11
|
+
|
|
12
|
+
//#region src/auth/file.ts
|
|
13
|
+
const ZodDate = zod.z.number().transform((seconds) => /* @__PURE__ */ new Date(seconds * 1e3));
|
|
14
|
+
const AuthFile = zod.z.object({
|
|
15
|
+
token: zod.z.string().min(1).optional(),
|
|
16
|
+
refreshToken: zod.z.string().min(1).optional(),
|
|
17
|
+
expiresAt: ZodDate.optional()
|
|
18
|
+
});
|
|
19
|
+
const StoredAuthFile = require_zod.json.pipe(AuthFile);
|
|
20
|
+
const isDirectory = (path$1) => {
|
|
21
|
+
try {
|
|
22
|
+
return node_fs.default.lstatSync(path$1).isDirectory();
|
|
23
|
+
} catch (_) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Returns in which directory the config should be present.
|
|
29
|
+
*
|
|
30
|
+
* @internal The `VERCEL_AUTH_CONFIG_DIR` env var is for testing purposes only
|
|
31
|
+
* and is not part of the public API.
|
|
32
|
+
*/
|
|
33
|
+
const getGlobalPathConfig = () => {
|
|
34
|
+
if (process.env.VERCEL_AUTH_CONFIG_DIR) return process.env.VERCEL_AUTH_CONFIG_DIR;
|
|
35
|
+
const vercelDirectories = (0, xdg_app_paths.default)("com.vercel.cli").dataDirs();
|
|
36
|
+
return [
|
|
37
|
+
...vercelDirectories,
|
|
38
|
+
node_path.default.join((0, node_os.homedir)(), ".now"),
|
|
39
|
+
...(0, xdg_app_paths.default)("now").dataDirs()
|
|
40
|
+
].find((configPath) => isDirectory(configPath)) || vercelDirectories[0];
|
|
41
|
+
};
|
|
42
|
+
const getAuth = () => {
|
|
43
|
+
try {
|
|
44
|
+
const pathname = node_path.default.join(getGlobalPathConfig(), "auth.json");
|
|
45
|
+
return StoredAuthFile.parse(node_fs.default.readFileSync(pathname, "utf8"));
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function updateAuthConfig(config) {
|
|
51
|
+
const pathname = node_path.default.join(getGlobalPathConfig(), "auth.json");
|
|
52
|
+
node_fs.default.mkdirSync(node_path.default.dirname(pathname), { recursive: true });
|
|
53
|
+
const content = {
|
|
54
|
+
token: config.token,
|
|
55
|
+
expiresAt: config.expiresAt && Math.round(config.expiresAt.getTime() / 1e3),
|
|
56
|
+
refreshToken: config.refreshToken
|
|
57
|
+
};
|
|
58
|
+
node_fs.default.writeFileSync(pathname, JSON.stringify(content) + "\n");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.getAuth = getAuth;
|
|
63
|
+
exports.updateAuthConfig = updateAuthConfig;
|
|
64
|
+
//# sourceMappingURL=file.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.cjs","names":["z","json","fs","path"],"sources":["../../src/auth/file.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport XDGAppPaths from \"xdg-app-paths\";\nimport { z } from \"zod\";\nimport { json } from \"./zod.js\";\n\nconst ZodDate = z.number().transform((seconds) => new Date(seconds * 1000));\n\nconst AuthFile = z.object({\n token: z.string().min(1).optional(),\n refreshToken: z.string().min(1).optional(),\n expiresAt: ZodDate.optional(),\n});\n\nconst StoredAuthFile = json.pipe(AuthFile);\n\ntype AuthFile = z.infer<typeof AuthFile>;\n\n// Returns whether a directory exists\nconst isDirectory = (path: string): boolean => {\n try {\n return fs.lstatSync(path).isDirectory();\n } catch (_) {\n // We don't care which kind of error occured, it isn't a directory anyway.\n return false;\n }\n};\n\n/**\n * Returns in which directory the config should be present.\n *\n * @internal The `VERCEL_AUTH_CONFIG_DIR` env var is for testing purposes only\n * and is not part of the public API.\n */\nconst getGlobalPathConfig = (): string => {\n if (process.env.VERCEL_AUTH_CONFIG_DIR) {\n return process.env.VERCEL_AUTH_CONFIG_DIR;\n }\n\n const vercelDirectories = XDGAppPaths(\"com.vercel.cli\").dataDirs();\n\n const possibleConfigPaths = [\n ...vercelDirectories, // latest vercel directory\n path.join(homedir(), \".now\"), // legacy config in user's home directory\n ...XDGAppPaths(\"now\").dataDirs(), // legacy XDG directory\n ];\n\n // The customPath flag is the preferred location,\n // followed by the vercel directory,\n // followed by the now directory.\n // If none of those exist, use the vercel directory.\n return (\n possibleConfigPaths.find((configPath) => isDirectory(configPath)) ||\n vercelDirectories[0]\n );\n};\n\nexport const getAuth = () => {\n try {\n const pathname = path.join(getGlobalPathConfig(), \"auth.json\");\n return StoredAuthFile.parse(fs.readFileSync(pathname, \"utf8\"));\n } catch {\n return null;\n }\n};\n\nexport function updateAuthConfig(config: AuthFile): void {\n const pathname = path.join(getGlobalPathConfig(), \"auth.json\");\n fs.mkdirSync(path.dirname(pathname), { recursive: true });\n const content = {\n token: config.token,\n expiresAt:\n config.expiresAt && Math.round(config.expiresAt.getTime() / 1000),\n refreshToken: config.refreshToken,\n } satisfies z.input<typeof AuthFile>;\n fs.writeFileSync(pathname, JSON.stringify(content) + \"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;AAOA,MAAM,UAAUA,MAAE,QAAQ,CAAC,WAAW,4BAAY,IAAI,KAAK,UAAU,IAAK,CAAC;AAE3E,MAAM,WAAWA,MAAE,OAAO;CACxB,OAAOA,MAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,UAAU;CACnC,cAAcA,MAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,UAAU;CAC1C,WAAW,QAAQ,UAAU;CAC9B,CAAC;AAEF,MAAM,iBAAiBC,iBAAK,KAAK,SAAS;AAK1C,MAAM,eAAe,WAA0B;AAC7C,KAAI;AACF,SAAOC,gBAAG,UAAUC,OAAK,CAAC,aAAa;UAChC,GAAG;AAEV,SAAO;;;;;;;;;AAUX,MAAM,4BAAoC;AACxC,KAAI,QAAQ,IAAI,uBACd,QAAO,QAAQ,IAAI;CAGrB,MAAM,+CAAgC,iBAAiB,CAAC,UAAU;AAYlE,QAV4B;EAC1B,GAAG;EACHA,kBAAK,2BAAc,EAAE,OAAO;EAC5B,8BAAe,MAAM,CAAC,UAAU;EACjC,CAOqB,MAAM,eAAe,YAAY,WAAW,CAAC,IACjE,kBAAkB;;AAItB,MAAa,gBAAgB;AAC3B,KAAI;EACF,MAAM,WAAWA,kBAAK,KAAK,qBAAqB,EAAE,YAAY;AAC9D,SAAO,eAAe,MAAMD,gBAAG,aAAa,UAAU,OAAO,CAAC;SACxD;AACN,SAAO;;;AAIX,SAAgB,iBAAiB,QAAwB;CACvD,MAAM,WAAWC,kBAAK,KAAK,qBAAqB,EAAE,YAAY;AAC9D,iBAAG,UAAUA,kBAAK,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;CACzD,MAAM,UAAU;EACd,OAAO,OAAO;EACd,WACE,OAAO,aAAa,KAAK,MAAM,OAAO,UAAU,SAAS,GAAG,IAAK;EACnE,cAAc,OAAO;EACtB;AACD,iBAAG,cAAc,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAK"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/auth/file.d.ts
|
|
4
|
+
declare const AuthFile: z.ZodObject<{
|
|
5
|
+
token: z.ZodOptional<z.ZodString>;
|
|
6
|
+
refreshToken: z.ZodOptional<z.ZodString>;
|
|
7
|
+
expiresAt: z.ZodOptional<z.ZodEffects<z.ZodNumber, Date, number>>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
token?: string | undefined;
|
|
10
|
+
refreshToken?: string | undefined;
|
|
11
|
+
expiresAt?: Date | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
token?: string | undefined;
|
|
14
|
+
refreshToken?: string | undefined;
|
|
15
|
+
expiresAt?: number | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
type AuthFile = z.infer<typeof AuthFile>;
|
|
18
|
+
declare const getAuth: () => {
|
|
19
|
+
token?: string | undefined;
|
|
20
|
+
refreshToken?: string | undefined;
|
|
21
|
+
expiresAt?: Date | undefined;
|
|
22
|
+
} | null;
|
|
23
|
+
declare function updateAuthConfig(config: AuthFile): void;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { getAuth, updateAuthConfig };
|
|
26
|
+
//# sourceMappingURL=file.d.cts.map
|
package/dist/auth/file.d.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/auth/file.d.ts
|
|
2
4
|
declare const AuthFile: z.ZodObject<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
token: z.ZodOptional<z.ZodString>;
|
|
6
|
+
refreshToken: z.ZodOptional<z.ZodString>;
|
|
7
|
+
expiresAt: z.ZodOptional<z.ZodEffects<z.ZodNumber, Date, number>>;
|
|
6
8
|
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
token?: string | undefined;
|
|
10
|
+
refreshToken?: string | undefined;
|
|
11
|
+
expiresAt?: Date | undefined;
|
|
10
12
|
}, {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
token?: string | undefined;
|
|
14
|
+
refreshToken?: string | undefined;
|
|
15
|
+
expiresAt?: number | undefined;
|
|
14
16
|
}>;
|
|
15
17
|
type AuthFile = z.infer<typeof AuthFile>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
declare const getAuth: () => {
|
|
19
|
+
token?: string | undefined;
|
|
20
|
+
refreshToken?: string | undefined;
|
|
21
|
+
expiresAt?: Date | undefined;
|
|
20
22
|
} | null;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
declare function updateAuthConfig(config: AuthFile): void;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { getAuth, updateAuthConfig };
|
|
26
|
+
//# sourceMappingURL=file.d.ts.map
|