@vercel/sandbox 1.8.1 → 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 -391
- package/dist/api-client/api-client.js +365 -404
- 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 -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 +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 -472
- package/dist/sandbox.js +539 -506
- 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,20 +1,28 @@
|
|
|
1
|
-
import { DeviceAuthorizationRequest, OAuth } from "./oauth";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { DeviceAuthorizationRequest, OAuth } from "./oauth.js";
|
|
2
|
+
|
|
3
|
+
//#region src/auth/poll-for-token.d.ts
|
|
4
|
+
type PollTokenItem = {
|
|
5
|
+
_tag: "Timeout";
|
|
6
|
+
newInterval: number;
|
|
5
7
|
} | {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
_tag: "SlowDown";
|
|
9
|
+
newInterval: number;
|
|
8
10
|
} | {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
_tag: "Error";
|
|
12
|
+
error: Error;
|
|
11
13
|
} | {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
_tag: "Response";
|
|
15
|
+
response: {
|
|
16
|
+
text(): Promise<string>;
|
|
17
|
+
};
|
|
16
18
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
declare function pollForToken({
|
|
20
|
+
request,
|
|
21
|
+
oauth
|
|
22
|
+
}: {
|
|
23
|
+
request: DeviceAuthorizationRequest;
|
|
24
|
+
oauth: OAuth;
|
|
20
25
|
}): AsyncGenerator<PollTokenItem, void, void>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { pollForToken };
|
|
28
|
+
//# sourceMappingURL=poll-for-token.d.ts.map
|
|
@@ -1,66 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
1
|
+
import { updateAuthConfig } from "./file.js";
|
|
2
|
+
import { isOAuthError } from "./oauth.js";
|
|
3
|
+
import { setTimeout } from "node:timers/promises";
|
|
4
|
+
|
|
5
|
+
//#region src/auth/poll-for-token.ts
|
|
6
|
+
async function* pollForToken({ request, oauth }) {
|
|
7
|
+
const controller = new AbortController();
|
|
8
|
+
try {
|
|
9
|
+
let intervalMs = request.interval * 1e3;
|
|
10
|
+
while (Date.now() < request.expiresAt) {
|
|
11
|
+
const [tokenResponseError, tokenResponse] = await oauth.deviceAccessTokenRequest(request.device_code);
|
|
12
|
+
if (tokenResponseError) {
|
|
13
|
+
if (tokenResponseError.message.includes("timeout")) {
|
|
14
|
+
intervalMs *= 2;
|
|
15
|
+
yield {
|
|
16
|
+
_tag: "Timeout",
|
|
17
|
+
newInterval: intervalMs
|
|
18
|
+
};
|
|
19
|
+
await setTimeout(intervalMs, { signal: controller.signal });
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
yield {
|
|
23
|
+
_tag: "Error",
|
|
24
|
+
error: tokenResponseError
|
|
25
|
+
};
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
yield {
|
|
29
|
+
_tag: "Response",
|
|
30
|
+
response: tokenResponse.clone()
|
|
31
|
+
};
|
|
32
|
+
const [tokensError, tokens] = await oauth.processTokenResponse(tokenResponse);
|
|
33
|
+
if (isOAuthError(tokensError)) {
|
|
34
|
+
const { code } = tokensError;
|
|
35
|
+
switch (code) {
|
|
36
|
+
case "authorization_pending":
|
|
37
|
+
await setTimeout(intervalMs, { signal: controller.signal });
|
|
38
|
+
continue;
|
|
39
|
+
case "slow_down":
|
|
40
|
+
intervalMs += 5 * 1e3;
|
|
41
|
+
yield {
|
|
42
|
+
_tag: "SlowDown",
|
|
43
|
+
newInterval: intervalMs
|
|
44
|
+
};
|
|
45
|
+
await setTimeout(intervalMs, { signal: controller.signal });
|
|
46
|
+
continue;
|
|
47
|
+
default:
|
|
48
|
+
yield {
|
|
49
|
+
_tag: "Error",
|
|
50
|
+
error: tokensError.cause
|
|
51
|
+
};
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (tokensError) {
|
|
56
|
+
yield {
|
|
57
|
+
_tag: "Error",
|
|
58
|
+
error: tokensError
|
|
59
|
+
};
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
updateAuthConfig({
|
|
63
|
+
token: tokens.access_token,
|
|
64
|
+
expiresAt: new Date(Date.now() + tokens.expires_in * 1e3),
|
|
65
|
+
refreshToken: tokens.refresh_token
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
yield {
|
|
70
|
+
_tag: "Error",
|
|
71
|
+
error: /* @__PURE__ */ new Error("Timed out waiting for authentication. Please try again.")
|
|
72
|
+
};
|
|
73
|
+
return;
|
|
74
|
+
} finally {
|
|
75
|
+
controller.abort();
|
|
76
|
+
}
|
|
65
77
|
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { pollForToken };
|
|
66
81
|
//# sourceMappingURL=poll-for-token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll-for-token.js","
|
|
1
|
+
{"version":3,"file":"poll-for-token.js","names":[],"sources":["../../src/auth/poll-for-token.ts"],"sourcesContent":["import { setTimeout } from \"node:timers/promises\";\nimport { updateAuthConfig } from \"./file.js\";\nimport { DeviceAuthorizationRequest, isOAuthError, OAuth } from \"./oauth.js\";\n\nexport type PollTokenItem =\n | { _tag: \"Timeout\"; newInterval: number }\n | { _tag: \"SlowDown\"; newInterval: number }\n | { _tag: \"Error\"; error: Error }\n | {\n _tag: \"Response\";\n response: { text(): Promise<string> };\n };\n\nexport async function* pollForToken({\n request,\n oauth,\n}: {\n request: DeviceAuthorizationRequest;\n oauth: OAuth;\n}): AsyncGenerator<PollTokenItem, void, void> {\n const controller = new AbortController();\n try {\n let intervalMs = request.interval * 1000;\n while (Date.now() < request.expiresAt) {\n const [tokenResponseError, tokenResponse] =\n await oauth.deviceAccessTokenRequest(request.device_code);\n\n if (tokenResponseError) {\n // 2x backoff on connection timeouts per spec https://datatracker.ietf.org/doc/html/rfc8628#section-3.5\n if (tokenResponseError.message.includes(\"timeout\")) {\n intervalMs *= 2;\n yield { _tag: \"Timeout\" as const, newInterval: intervalMs };\n await setTimeout(intervalMs, { signal: controller.signal });\n continue;\n }\n yield { _tag: \"Error\" as const, error: tokenResponseError };\n return;\n }\n\n yield {\n _tag: \"Response\" as const,\n response: tokenResponse.clone() as { text(): Promise<string> },\n };\n\n const [tokensError, tokens] =\n await oauth.processTokenResponse(tokenResponse);\n\n if (isOAuthError(tokensError)) {\n const { code } = tokensError;\n switch (code) {\n case \"authorization_pending\":\n await setTimeout(intervalMs, { signal: controller.signal });\n continue;\n case \"slow_down\":\n intervalMs += 5 * 1000;\n yield { _tag: \"SlowDown\" as const, newInterval: intervalMs };\n await setTimeout(intervalMs, { signal: controller.signal });\n continue;\n default:\n yield { _tag: \"Error\", error: tokensError.cause };\n return;\n }\n }\n\n if (tokensError) {\n yield { _tag: \"Error\", error: tokensError };\n return;\n }\n\n updateAuthConfig({\n token: tokens.access_token,\n expiresAt: new Date(Date.now() + tokens.expires_in * 1000),\n refreshToken: tokens.refresh_token,\n });\n\n return;\n }\n\n yield {\n _tag: \"Error\" as const,\n error: new Error(\n \"Timed out waiting for authentication. Please try again.\",\n ),\n };\n return;\n } finally {\n controller.abort();\n }\n}\n"],"mappings":";;;;;AAaA,gBAAuB,aAAa,EAClC,SACA,SAI4C;CAC5C,MAAM,aAAa,IAAI,iBAAiB;AACxC,KAAI;EACF,IAAI,aAAa,QAAQ,WAAW;AACpC,SAAO,KAAK,KAAK,GAAG,QAAQ,WAAW;GACrC,MAAM,CAAC,oBAAoB,iBACzB,MAAM,MAAM,yBAAyB,QAAQ,YAAY;AAE3D,OAAI,oBAAoB;AAEtB,QAAI,mBAAmB,QAAQ,SAAS,UAAU,EAAE;AAClD,mBAAc;AACd,WAAM;MAAE,MAAM;MAAoB,aAAa;MAAY;AAC3D,WAAM,WAAW,YAAY,EAAE,QAAQ,WAAW,QAAQ,CAAC;AAC3D;;AAEF,UAAM;KAAE,MAAM;KAAkB,OAAO;KAAoB;AAC3D;;AAGF,SAAM;IACJ,MAAM;IACN,UAAU,cAAc,OAAO;IAChC;GAED,MAAM,CAAC,aAAa,UAClB,MAAM,MAAM,qBAAqB,cAAc;AAEjD,OAAI,aAAa,YAAY,EAAE;IAC7B,MAAM,EAAE,SAAS;AACjB,YAAQ,MAAR;KACE,KAAK;AACH,YAAM,WAAW,YAAY,EAAE,QAAQ,WAAW,QAAQ,CAAC;AAC3D;KACF,KAAK;AACH,oBAAc,IAAI;AAClB,YAAM;OAAE,MAAM;OAAqB,aAAa;OAAY;AAC5D,YAAM,WAAW,YAAY,EAAE,QAAQ,WAAW,QAAQ,CAAC;AAC3D;KACF;AACE,YAAM;OAAE,MAAM;OAAS,OAAO,YAAY;OAAO;AACjD;;;AAIN,OAAI,aAAa;AACf,UAAM;KAAE,MAAM;KAAS,OAAO;KAAa;AAC3C;;AAGF,oBAAiB;IACf,OAAO,OAAO;IACd,WAAW,IAAI,KAAK,KAAK,KAAK,GAAG,OAAO,aAAa,IAAK;IAC1D,cAAc,OAAO;IACtB,CAAC;AAEF;;AAGF,QAAM;GACJ,MAAM;GACN,uBAAO,IAAI,MACT,0DACD;GACF;AACD;WACQ;AACR,aAAW,OAAO"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_error = require('./error.cjs');
|
|
3
|
+
const require_api = require('./api.cjs');
|
|
4
|
+
const require_linked_project = require('./linked-project.cjs');
|
|
5
|
+
let zod = require("zod");
|
|
6
|
+
|
|
7
|
+
//#region src/auth/project.ts
|
|
8
|
+
const TeamsSchema = zod.z.object({ teams: zod.z.array(zod.z.object({ slug: zod.z.string() })).min(1, `No teams found. Please create a team first.`) });
|
|
9
|
+
const DEFAULT_PROJECT_NAME = "vercel-sandbox-default-project";
|
|
10
|
+
/**
|
|
11
|
+
* Resolves the team and project scope for sandbox operations.
|
|
12
|
+
*
|
|
13
|
+
* First checks for a locally linked project in `.vercel/project.json`.
|
|
14
|
+
* If found, uses the `projectId` and `orgId` from there.
|
|
15
|
+
*
|
|
16
|
+
* Otherwise, if `teamId` is not provided, selects the first available team for the account.
|
|
17
|
+
* Ensures a default project exists within the team, creating it if necessary.
|
|
18
|
+
*
|
|
19
|
+
* @param opts.token - Vercel API authentication token.
|
|
20
|
+
* @param opts.teamId - Optional team slug. If omitted, the first team is selected.
|
|
21
|
+
* @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.
|
|
22
|
+
* @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.
|
|
23
|
+
*
|
|
24
|
+
* @throws {NotOk} If the API returns an error other than 404 when checking the project.
|
|
25
|
+
* @throws {ZodError} If no teams exist for the account.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const scope = await inferScope({ token: "vercel_..." });
|
|
30
|
+
* // => { projectId: "vercel-sandbox-default-project", teamId: "my-team", created: false }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
async function inferScope(opts) {
|
|
34
|
+
const linkedProject = await require_linked_project.readLinkedProject(opts.cwd ?? process.cwd());
|
|
35
|
+
if (linkedProject) return {
|
|
36
|
+
...linkedProject,
|
|
37
|
+
created: false
|
|
38
|
+
};
|
|
39
|
+
const teamId = opts.teamId ?? await selectTeam(opts.token);
|
|
40
|
+
let created = false;
|
|
41
|
+
try {
|
|
42
|
+
await require_api.fetchApi({
|
|
43
|
+
token: opts.token,
|
|
44
|
+
endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?slug=${encodeURIComponent(teamId)}`
|
|
45
|
+
});
|
|
46
|
+
} catch (e) {
|
|
47
|
+
if (!(e instanceof require_error.NotOk) || e.response.statusCode !== 404) throw e;
|
|
48
|
+
await require_api.fetchApi({
|
|
49
|
+
token: opts.token,
|
|
50
|
+
endpoint: `/v11/projects?slug=${encodeURIComponent(teamId)}`,
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: JSON.stringify({ name: DEFAULT_PROJECT_NAME })
|
|
53
|
+
});
|
|
54
|
+
created = true;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
projectId: DEFAULT_PROJECT_NAME,
|
|
58
|
+
teamId,
|
|
59
|
+
created
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Selects a team for the current token by querying the Teams API and
|
|
64
|
+
* returning the slug of the first team in the result set.
|
|
65
|
+
*
|
|
66
|
+
* @param token - Authentication token used to call the Vercel API.
|
|
67
|
+
* @returns A promise that resolves to the first team's slug.
|
|
68
|
+
*/
|
|
69
|
+
async function selectTeam(token) {
|
|
70
|
+
const { teams: [team] } = await require_api.fetchApi({
|
|
71
|
+
token,
|
|
72
|
+
endpoint: "/v2/teams?limit=1"
|
|
73
|
+
}).then(TeamsSchema.parse);
|
|
74
|
+
return team.slug;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.inferScope = inferScope;
|
|
79
|
+
exports.selectTeam = selectTeam;
|
|
80
|
+
//# sourceMappingURL=project.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.cjs","names":["z","readLinkedProject","fetchApi","NotOk"],"sources":["../../src/auth/project.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { fetchApi } from \"./api.js\";\nimport { NotOk } from \"./error.js\";\nimport { readLinkedProject } from \"./linked-project.js\";\n\nconst TeamsSchema = z.object({\n teams: z\n .array(\n z.object({\n slug: z.string(),\n }),\n )\n .min(1, `No teams found. Please create a team first.`),\n});\n\nconst DEFAULT_PROJECT_NAME = \"vercel-sandbox-default-project\";\n\n/**\n * Resolves the team and project scope for sandbox operations.\n *\n * First checks for a locally linked project in `.vercel/project.json`.\n * If found, uses the `projectId` and `orgId` from there.\n *\n * Otherwise, if `teamId` is not provided, selects the first available team for the account.\n * Ensures a default project exists within the team, creating it if necessary.\n *\n * @param opts.token - Vercel API authentication token.\n * @param opts.teamId - Optional team slug. If omitted, the first team is selected.\n * @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.\n * @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.\n *\n * @throws {NotOk} If the API returns an error other than 404 when checking the project.\n * @throws {ZodError} If no teams exist for the account.\n *\n * @example\n * ```ts\n * const scope = await inferScope({ token: \"vercel_...\" });\n * // => { projectId: \"vercel-sandbox-default-project\", teamId: \"my-team\", created: false }\n * ```\n */\nexport async function inferScope(opts: {\n token: string;\n teamId?: string;\n cwd?: string;\n}): Promise<{ projectId: string; teamId: string; created: boolean }> {\n const linkedProject = await readLinkedProject(opts.cwd ?? process.cwd());\n if (linkedProject) {\n return { ...linkedProject, created: false };\n }\n\n const teamId = opts.teamId ?? (await selectTeam(opts.token));\n\n let created = false;\n try {\n await fetchApi({\n token: opts.token,\n endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?slug=${encodeURIComponent(teamId)}`,\n });\n } catch (e) {\n if (!(e instanceof NotOk) || e.response.statusCode !== 404) {\n throw e;\n }\n\n await fetchApi({\n token: opts.token,\n endpoint: `/v11/projects?slug=${encodeURIComponent(teamId)}`,\n method: \"POST\",\n body: JSON.stringify({\n name: DEFAULT_PROJECT_NAME,\n }),\n });\n created = true;\n }\n\n return { projectId: DEFAULT_PROJECT_NAME, teamId, created };\n}\n\n/**\n * Selects a team for the current token by querying the Teams API and\n * returning the slug of the first team in the result set.\n *\n * @param token - Authentication token used to call the Vercel API.\n * @returns A promise that resolves to the first team's slug.\n */\nexport async function selectTeam(token: string) {\n const {\n teams: [team],\n } = await fetchApi({ token, endpoint: \"/v2/teams?limit=1\" }).then(\n TeamsSchema.parse,\n );\n return team.slug;\n}\n"],"mappings":";;;;;;;AAKA,MAAM,cAAcA,MAAE,OAAO,EAC3B,OAAOA,MACJ,MACCA,MAAE,OAAO,EACP,MAAMA,MAAE,QAAQ,EACjB,CAAC,CACH,CACA,IAAI,GAAG,8CAA8C,EACzD,CAAC;AAEF,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;AAyB7B,eAAsB,WAAW,MAIoC;CACnE,MAAM,gBAAgB,MAAMC,yCAAkB,KAAK,OAAO,QAAQ,KAAK,CAAC;AACxE,KAAI,cACF,QAAO;EAAE,GAAG;EAAe,SAAS;EAAO;CAG7C,MAAM,SAAS,KAAK,UAAW,MAAM,WAAW,KAAK,MAAM;CAE3D,IAAI,UAAU;AACd,KAAI;AACF,QAAMC,qBAAS;GACb,OAAO,KAAK;GACZ,UAAU,gBAAgB,mBAAmB,qBAAqB,CAAC,QAAQ,mBAAmB,OAAO;GACtG,CAAC;UACK,GAAG;AACV,MAAI,EAAE,aAAaC,wBAAU,EAAE,SAAS,eAAe,IACrD,OAAM;AAGR,QAAMD,qBAAS;GACb,OAAO,KAAK;GACZ,UAAU,sBAAsB,mBAAmB,OAAO;GAC1D,QAAQ;GACR,MAAM,KAAK,UAAU,EACnB,MAAM,sBACP,CAAC;GACH,CAAC;AACF,YAAU;;AAGZ,QAAO;EAAE,WAAW;EAAsB;EAAQ;EAAS;;;;;;;;;AAU7D,eAAsB,WAAW,OAAe;CAC9C,MAAM,EACJ,OAAO,CAAC,UACN,MAAMA,qBAAS;EAAE;EAAO,UAAU;EAAqB,CAAC,CAAC,KAC3D,YAAY,MACb;AACD,QAAO,KAAK"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/auth/project.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the team and project scope for sandbox operations.
|
|
4
|
+
*
|
|
5
|
+
* First checks for a locally linked project in `.vercel/project.json`.
|
|
6
|
+
* If found, uses the `projectId` and `orgId` from there.
|
|
7
|
+
*
|
|
8
|
+
* Otherwise, if `teamId` is not provided, selects the first available team for the account.
|
|
9
|
+
* Ensures a default project exists within the team, creating it if necessary.
|
|
10
|
+
*
|
|
11
|
+
* @param opts.token - Vercel API authentication token.
|
|
12
|
+
* @param opts.teamId - Optional team slug. If omitted, the first team is selected.
|
|
13
|
+
* @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.
|
|
14
|
+
* @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.
|
|
15
|
+
*
|
|
16
|
+
* @throws {NotOk} If the API returns an error other than 404 when checking the project.
|
|
17
|
+
* @throws {ZodError} If no teams exist for the account.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const scope = await inferScope({ token: "vercel_..." });
|
|
22
|
+
* // => { projectId: "vercel-sandbox-default-project", teamId: "my-team", created: false }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function inferScope(opts: {
|
|
26
|
+
token: string;
|
|
27
|
+
teamId?: string;
|
|
28
|
+
cwd?: string;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
projectId: string;
|
|
31
|
+
teamId: string;
|
|
32
|
+
created: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Selects a team for the current token by querying the Teams API and
|
|
36
|
+
* returning the slug of the first team in the result set.
|
|
37
|
+
*
|
|
38
|
+
* @param token - Authentication token used to call the Vercel API.
|
|
39
|
+
* @returns A promise that resolves to the first team's slug.
|
|
40
|
+
*/
|
|
41
|
+
declare function selectTeam(token: string): Promise<string>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { inferScope, selectTeam };
|
|
44
|
+
//# sourceMappingURL=project.d.cts.map
|
package/dist/auth/project.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/auth/project.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Resolves the team and project scope for sandbox operations.
|
|
3
4
|
*
|
|
@@ -21,14 +22,14 @@
|
|
|
21
22
|
* // => { projectId: "vercel-sandbox-default-project", teamId: "my-team", created: false }
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
declare function inferScope(opts: {
|
|
26
|
+
token: string;
|
|
27
|
+
teamId?: string;
|
|
28
|
+
cwd?: string;
|
|
28
29
|
}): Promise<{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
projectId: string;
|
|
31
|
+
teamId: string;
|
|
32
|
+
created: boolean;
|
|
32
33
|
}>;
|
|
33
34
|
/**
|
|
34
35
|
* Selects a team for the current token by querying the Teams API and
|
|
@@ -37,4 +38,7 @@ export declare function inferScope(opts: {
|
|
|
37
38
|
* @param token - Authentication token used to call the Vercel API.
|
|
38
39
|
* @returns A promise that resolves to the first team's slug.
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
|
+
declare function selectTeam(token: string): Promise<string>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { inferScope, selectTeam };
|
|
44
|
+
//# sourceMappingURL=project.d.ts.map
|
package/dist/auth/project.js
CHANGED
|
@@ -1,80 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const linked_project_1 = require("./linked-project");
|
|
9
|
-
const TeamsSchema = zod_1.z.object({
|
|
10
|
-
teams: zod_1.z
|
|
11
|
-
.array(zod_1.z.object({
|
|
12
|
-
slug: zod_1.z.string(),
|
|
13
|
-
}))
|
|
14
|
-
.min(1, `No teams found. Please create a team first.`),
|
|
15
|
-
});
|
|
1
|
+
import { NotOk } from "./error.js";
|
|
2
|
+
import { fetchApi } from "./api.js";
|
|
3
|
+
import { readLinkedProject } from "./linked-project.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/auth/project.ts
|
|
7
|
+
const TeamsSchema = z.object({ teams: z.array(z.object({ slug: z.string() })).min(1, `No teams found. Please create a team first.`) });
|
|
16
8
|
const DEFAULT_PROJECT_NAME = "vercel-sandbox-default-project";
|
|
17
9
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
10
|
+
* Resolves the team and project scope for sandbox operations.
|
|
11
|
+
*
|
|
12
|
+
* First checks for a locally linked project in `.vercel/project.json`.
|
|
13
|
+
* If found, uses the `projectId` and `orgId` from there.
|
|
14
|
+
*
|
|
15
|
+
* Otherwise, if `teamId` is not provided, selects the first available team for the account.
|
|
16
|
+
* Ensures a default project exists within the team, creating it if necessary.
|
|
17
|
+
*
|
|
18
|
+
* @param opts.token - Vercel API authentication token.
|
|
19
|
+
* @param opts.teamId - Optional team slug. If omitted, the first team is selected.
|
|
20
|
+
* @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.
|
|
21
|
+
* @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.
|
|
22
|
+
*
|
|
23
|
+
* @throws {NotOk} If the API returns an error other than 404 when checking the project.
|
|
24
|
+
* @throws {ZodError} If no teams exist for the account.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const scope = await inferScope({ token: "vercel_..." });
|
|
29
|
+
* // => { projectId: "vercel-sandbox-default-project", teamId: "my-team", created: false }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
40
32
|
async function inferScope(opts) {
|
|
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
|
-
|
|
33
|
+
const linkedProject = await readLinkedProject(opts.cwd ?? process.cwd());
|
|
34
|
+
if (linkedProject) return {
|
|
35
|
+
...linkedProject,
|
|
36
|
+
created: false
|
|
37
|
+
};
|
|
38
|
+
const teamId = opts.teamId ?? await selectTeam(opts.token);
|
|
39
|
+
let created = false;
|
|
40
|
+
try {
|
|
41
|
+
await fetchApi({
|
|
42
|
+
token: opts.token,
|
|
43
|
+
endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?slug=${encodeURIComponent(teamId)}`
|
|
44
|
+
});
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (!(e instanceof NotOk) || e.response.statusCode !== 404) throw e;
|
|
47
|
+
await fetchApi({
|
|
48
|
+
token: opts.token,
|
|
49
|
+
endpoint: `/v11/projects?slug=${encodeURIComponent(teamId)}`,
|
|
50
|
+
method: "POST",
|
|
51
|
+
body: JSON.stringify({ name: DEFAULT_PROJECT_NAME })
|
|
52
|
+
});
|
|
53
|
+
created = true;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
projectId: DEFAULT_PROJECT_NAME,
|
|
57
|
+
teamId,
|
|
58
|
+
created
|
|
59
|
+
};
|
|
68
60
|
}
|
|
69
61
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
* Selects a team for the current token by querying the Teams API and
|
|
63
|
+
* returning the slug of the first team in the result set.
|
|
64
|
+
*
|
|
65
|
+
* @param token - Authentication token used to call the Vercel API.
|
|
66
|
+
* @returns A promise that resolves to the first team's slug.
|
|
67
|
+
*/
|
|
76
68
|
async function selectTeam(token) {
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
const { teams: [team] } = await fetchApi({
|
|
70
|
+
token,
|
|
71
|
+
endpoint: "/v2/teams?limit=1"
|
|
72
|
+
}).then(TeamsSchema.parse);
|
|
73
|
+
return team.slug;
|
|
79
74
|
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { inferScope, selectTeam };
|
|
80
78
|
//# sourceMappingURL=project.js.map
|
package/dist/auth/project.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","
|
|
1
|
+
{"version":3,"file":"project.js","names":[],"sources":["../../src/auth/project.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { fetchApi } from \"./api.js\";\nimport { NotOk } from \"./error.js\";\nimport { readLinkedProject } from \"./linked-project.js\";\n\nconst TeamsSchema = z.object({\n teams: z\n .array(\n z.object({\n slug: z.string(),\n }),\n )\n .min(1, `No teams found. Please create a team first.`),\n});\n\nconst DEFAULT_PROJECT_NAME = \"vercel-sandbox-default-project\";\n\n/**\n * Resolves the team and project scope for sandbox operations.\n *\n * First checks for a locally linked project in `.vercel/project.json`.\n * If found, uses the `projectId` and `orgId` from there.\n *\n * Otherwise, if `teamId` is not provided, selects the first available team for the account.\n * Ensures a default project exists within the team, creating it if necessary.\n *\n * @param opts.token - Vercel API authentication token.\n * @param opts.teamId - Optional team slug. If omitted, the first team is selected.\n * @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.\n * @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.\n *\n * @throws {NotOk} If the API returns an error other than 404 when checking the project.\n * @throws {ZodError} If no teams exist for the account.\n *\n * @example\n * ```ts\n * const scope = await inferScope({ token: \"vercel_...\" });\n * // => { projectId: \"vercel-sandbox-default-project\", teamId: \"my-team\", created: false }\n * ```\n */\nexport async function inferScope(opts: {\n token: string;\n teamId?: string;\n cwd?: string;\n}): Promise<{ projectId: string; teamId: string; created: boolean }> {\n const linkedProject = await readLinkedProject(opts.cwd ?? process.cwd());\n if (linkedProject) {\n return { ...linkedProject, created: false };\n }\n\n const teamId = opts.teamId ?? (await selectTeam(opts.token));\n\n let created = false;\n try {\n await fetchApi({\n token: opts.token,\n endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?slug=${encodeURIComponent(teamId)}`,\n });\n } catch (e) {\n if (!(e instanceof NotOk) || e.response.statusCode !== 404) {\n throw e;\n }\n\n await fetchApi({\n token: opts.token,\n endpoint: `/v11/projects?slug=${encodeURIComponent(teamId)}`,\n method: \"POST\",\n body: JSON.stringify({\n name: DEFAULT_PROJECT_NAME,\n }),\n });\n created = true;\n }\n\n return { projectId: DEFAULT_PROJECT_NAME, teamId, created };\n}\n\n/**\n * Selects a team for the current token by querying the Teams API and\n * returning the slug of the first team in the result set.\n *\n * @param token - Authentication token used to call the Vercel API.\n * @returns A promise that resolves to the first team's slug.\n */\nexport async function selectTeam(token: string) {\n const {\n teams: [team],\n } = await fetchApi({ token, endpoint: \"/v2/teams?limit=1\" }).then(\n TeamsSchema.parse,\n );\n return team.slug;\n}\n"],"mappings":";;;;;;AAKA,MAAM,cAAc,EAAE,OAAO,EAC3B,OAAO,EACJ,MACC,EAAE,OAAO,EACP,MAAM,EAAE,QAAQ,EACjB,CAAC,CACH,CACA,IAAI,GAAG,8CAA8C,EACzD,CAAC;AAEF,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;AAyB7B,eAAsB,WAAW,MAIoC;CACnE,MAAM,gBAAgB,MAAM,kBAAkB,KAAK,OAAO,QAAQ,KAAK,CAAC;AACxE,KAAI,cACF,QAAO;EAAE,GAAG;EAAe,SAAS;EAAO;CAG7C,MAAM,SAAS,KAAK,UAAW,MAAM,WAAW,KAAK,MAAM;CAE3D,IAAI,UAAU;AACd,KAAI;AACF,QAAM,SAAS;GACb,OAAO,KAAK;GACZ,UAAU,gBAAgB,mBAAmB,qBAAqB,CAAC,QAAQ,mBAAmB,OAAO;GACtG,CAAC;UACK,GAAG;AACV,MAAI,EAAE,aAAa,UAAU,EAAE,SAAS,eAAe,IACrD,OAAM;AAGR,QAAM,SAAS;GACb,OAAO,KAAK;GACZ,UAAU,sBAAsB,mBAAmB,OAAO;GAC1D,QAAQ;GACR,MAAM,KAAK,UAAU,EACnB,MAAM,sBACP,CAAC;GACH,CAAC;AACF,YAAU;;AAGZ,QAAO;EAAE,WAAW;EAAsB;EAAQ;EAAS;;;;;;;;;AAU7D,eAAsB,WAAW,OAAe;CAC9C,MAAM,EACJ,OAAO,CAAC,UACN,MAAM,SAAS;EAAE;EAAO,UAAU;EAAqB,CAAC,CAAC,KAC3D,YAAY,MACb;AACD,QAAO,KAAK"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
|
|
4
|
+
//#region src/auth/zod.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Zod codec that serializes and deserializes JSON strings.
|
|
7
|
+
*/
|
|
8
|
+
const json = zod.z.string().transform((jsonString, ctx) => {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(jsonString);
|
|
11
|
+
} catch (err) {
|
|
12
|
+
ctx.addIssue({
|
|
13
|
+
code: zod.z.ZodIssueCode.custom,
|
|
14
|
+
message: `Invalid JSON: ${err.message}`
|
|
15
|
+
});
|
|
16
|
+
return zod.z.NEVER;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.json = json;
|
|
22
|
+
//# sourceMappingURL=zod.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.cjs","names":["z","err: any"],"sources":["../../src/auth/zod.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * A Zod codec that serializes and deserializes JSON strings.\n */\nexport const json = z.string().transform((jsonString: string, ctx): unknown => {\n try {\n return JSON.parse(jsonString);\n } catch (err: any) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Invalid JSON: ${err.message}`,\n });\n return z.NEVER;\n }\n});\n"],"mappings":";;;;;;;AAKA,MAAa,OAAOA,MAAE,QAAQ,CAAC,WAAW,YAAoB,QAAiB;AAC7E,KAAI;AACF,SAAO,KAAK,MAAM,WAAW;UACtBC,KAAU;AACjB,MAAI,SAAS;GACX,MAAMD,MAAE,aAAa;GACrB,SAAS,iBAAiB,IAAI;GAC/B,CAAC;AACF,SAAOA,MAAE;;EAEX"}
|
package/dist/auth/zod.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const zod_1 = require("zod");
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/auth/zod.ts
|
|
5
4
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
5
|
+
* A Zod codec that serializes and deserializes JSON strings.
|
|
6
|
+
*/
|
|
7
|
+
const json = z.string().transform((jsonString, ctx) => {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(jsonString);
|
|
10
|
+
} catch (err) {
|
|
11
|
+
ctx.addIssue({
|
|
12
|
+
code: z.ZodIssueCode.custom,
|
|
13
|
+
message: `Invalid JSON: ${err.message}`
|
|
14
|
+
});
|
|
15
|
+
return z.NEVER;
|
|
16
|
+
}
|
|
19
17
|
});
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { json };
|
|
20
21
|
//# sourceMappingURL=zod.js.map
|
package/dist/auth/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","
|
|
1
|
+
{"version":3,"file":"zod.js","names":["err: any"],"sources":["../../src/auth/zod.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * A Zod codec that serializes and deserializes JSON strings.\n */\nexport const json = z.string().transform((jsonString: string, ctx): unknown => {\n try {\n return JSON.parse(jsonString);\n } catch (err: any) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Invalid JSON: ${err.message}`,\n });\n return z.NEVER;\n }\n});\n"],"mappings":";;;;;;AAKA,MAAa,OAAO,EAAE,QAAQ,CAAC,WAAW,YAAoB,QAAiB;AAC7E,KAAI;AACF,SAAO,KAAK,MAAM,WAAW;UACtBA,KAAU;AACjB,MAAI,SAAS;GACX,MAAM,EAAE,aAAa;GACrB,SAAS,iBAAiB,IAAI;GAC/B,CAAC;AACF,SAAO,EAAE;;EAEX"}
|