@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
|
@@ -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,178 @@
|
|
|
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 UserSchema = zod.z.object({ user: zod.z.object({
|
|
9
|
+
defaultTeamId: zod.z.string().nullable(),
|
|
10
|
+
username: zod.z.string()
|
|
11
|
+
}) });
|
|
12
|
+
const TeamSchema = zod.z.object({
|
|
13
|
+
id: zod.z.string(),
|
|
14
|
+
slug: zod.z.string(),
|
|
15
|
+
updatedAt: zod.z.number(),
|
|
16
|
+
membership: zod.z.object({ role: zod.z.string() }),
|
|
17
|
+
billing: zod.z.object({ plan: zod.z.string() })
|
|
18
|
+
});
|
|
19
|
+
const TeamsSchema = zod.z.object({
|
|
20
|
+
teams: zod.z.array(TeamSchema),
|
|
21
|
+
pagination: zod.z.object({
|
|
22
|
+
count: zod.z.number(),
|
|
23
|
+
next: zod.z.number().nullable()
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
const DEFAULT_PROJECT_NAME = "vercel-sandbox-default-project";
|
|
27
|
+
/** Status codes that mean "this team can't be used, try the next one". */
|
|
28
|
+
function isSkippableTeamError(e) {
|
|
29
|
+
return e instanceof require_error.NotOk && (e.response.statusCode === 402 || e.response.statusCode === 403);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolves the team and project scope for sandbox operations.
|
|
33
|
+
*
|
|
34
|
+
* First checks for a locally linked project in `.vercel/project.json`.
|
|
35
|
+
* If found, uses the `projectId` and `orgId` from there.
|
|
36
|
+
*
|
|
37
|
+
* Otherwise, if `teamId` is not provided, builds an ordered list of candidate
|
|
38
|
+
* teams to try: the user's `defaultTeamId` first (if set), then hobby-plan
|
|
39
|
+
* teams where the user has an OWNER role (preferring the personal team matching
|
|
40
|
+
* the username, then the most recently updated). Tries each candidate until one
|
|
41
|
+
* succeeds.
|
|
42
|
+
*
|
|
43
|
+
* @param opts.token - Vercel API authentication token.
|
|
44
|
+
* @param opts.teamId - Optional team slug. If omitted, candidate teams are resolved automatically.
|
|
45
|
+
* @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.
|
|
46
|
+
* @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.
|
|
47
|
+
*
|
|
48
|
+
* @throws {NotOk} If the API returns an error other than 404 when checking the project.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const scope = await inferScope({ token: "vercel_..." });
|
|
53
|
+
* // => { projectId: "vercel-sandbox-default-project", teamId: "my-team", created: false }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async function inferScope(opts) {
|
|
57
|
+
const linkedProject = await require_linked_project.readLinkedProject(opts.cwd ?? process.cwd());
|
|
58
|
+
if (linkedProject) {
|
|
59
|
+
const slugs = await resolveLinkedProjectSlugs(opts.token, linkedProject.teamId, linkedProject.projectId);
|
|
60
|
+
return {
|
|
61
|
+
...linkedProject,
|
|
62
|
+
created: false,
|
|
63
|
+
...slugs
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (opts.teamId) return tryTeam(opts.token, opts.teamId);
|
|
67
|
+
const { defaultTeamId, username } = (await require_api.fetchApi({
|
|
68
|
+
token: opts.token,
|
|
69
|
+
endpoint: "/v2/user"
|
|
70
|
+
}).then(UserSchema.parse)).user;
|
|
71
|
+
if (defaultTeamId) try {
|
|
72
|
+
const result = await tryTeam(opts.token, defaultTeamId);
|
|
73
|
+
try {
|
|
74
|
+
const team = await require_api.fetchApi({
|
|
75
|
+
token: opts.token,
|
|
76
|
+
endpoint: `/v2/teams/${encodeURIComponent(defaultTeamId)}`
|
|
77
|
+
}).then(zod.z.object({ slug: zod.z.string() }).parse);
|
|
78
|
+
return {
|
|
79
|
+
...result,
|
|
80
|
+
teamSlug: team.slug
|
|
81
|
+
};
|
|
82
|
+
} catch {
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if (!isSkippableTeamError(e)) throw e;
|
|
87
|
+
}
|
|
88
|
+
let next = null;
|
|
89
|
+
do {
|
|
90
|
+
const endpoint = next === null ? "/v2/teams?limit=20" : `/v2/teams?limit=20&until=${next}`;
|
|
91
|
+
const page = await require_api.fetchApi({
|
|
92
|
+
token: opts.token,
|
|
93
|
+
endpoint
|
|
94
|
+
}).then(TeamsSchema.parse);
|
|
95
|
+
next = page.pagination.next;
|
|
96
|
+
const hobbyOwnerTeams = page.teams.filter((t) => t.membership.role === "OWNER" && t.billing.plan === "hobby");
|
|
97
|
+
if (hobbyOwnerTeams.length === 0) continue;
|
|
98
|
+
const bestHobbyTeam = hobbyOwnerTeams.find((t) => t.slug === username) ?? hobbyOwnerTeams.sort((a, b) => b.updatedAt - a.updatedAt)[0];
|
|
99
|
+
if (bestHobbyTeam && bestHobbyTeam.id !== defaultTeamId) try {
|
|
100
|
+
return {
|
|
101
|
+
...await tryTeam(opts.token, bestHobbyTeam.id),
|
|
102
|
+
teamSlug: bestHobbyTeam.slug
|
|
103
|
+
};
|
|
104
|
+
} catch (e) {
|
|
105
|
+
if (!isSkippableTeamError(e)) throw e;
|
|
106
|
+
}
|
|
107
|
+
} while (next !== null);
|
|
108
|
+
try {
|
|
109
|
+
return {
|
|
110
|
+
...await tryTeam(opts.token, username),
|
|
111
|
+
teamSlug: username
|
|
112
|
+
};
|
|
113
|
+
} catch (e) {
|
|
114
|
+
if (!isSkippableTeamError(e)) throw e;
|
|
115
|
+
}
|
|
116
|
+
throw new require_error.NotOk({
|
|
117
|
+
statusCode: 403,
|
|
118
|
+
responseText: `Authenticated as "${username}" but none of the available teams allow sandbox creation. Specify a team explicitly with --scope <team-id-or-slug>.`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Attempts to use a specific team for sandbox operations by checking for
|
|
123
|
+
* (or creating) the default project within that team.
|
|
124
|
+
*
|
|
125
|
+
* @returns The resolved scope if the team is usable.
|
|
126
|
+
* @throws {NotOk} On authorization or other API errors.
|
|
127
|
+
*/
|
|
128
|
+
async function tryTeam(token, teamId) {
|
|
129
|
+
const teamParam = teamId.startsWith("team_") ? `teamId=${encodeURIComponent(teamId)}` : `slug=${encodeURIComponent(teamId)}`;
|
|
130
|
+
let created = false;
|
|
131
|
+
try {
|
|
132
|
+
await require_api.fetchApi({
|
|
133
|
+
token,
|
|
134
|
+
endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?${teamParam}`
|
|
135
|
+
});
|
|
136
|
+
} catch (e) {
|
|
137
|
+
if (!(e instanceof require_error.NotOk) || e.response.statusCode !== 404) throw e;
|
|
138
|
+
await require_api.fetchApi({
|
|
139
|
+
token,
|
|
140
|
+
endpoint: `/v11/projects?${teamParam}`,
|
|
141
|
+
method: "POST",
|
|
142
|
+
body: JSON.stringify({ name: DEFAULT_PROJECT_NAME })
|
|
143
|
+
});
|
|
144
|
+
created = true;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
projectId: DEFAULT_PROJECT_NAME,
|
|
148
|
+
teamId,
|
|
149
|
+
created
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Best-effort resolution of team slug and project name for a linked project.
|
|
154
|
+
* Both IDs may be opaque (e.g. `team_xxx`, `prj_xxx`), so we fetch the
|
|
155
|
+
* human-readable names from the API in parallel.
|
|
156
|
+
*/
|
|
157
|
+
async function resolveLinkedProjectSlugs(token, teamId, projectId) {
|
|
158
|
+
try {
|
|
159
|
+
const teamParam = teamId.startsWith("team_") ? `teamId=${encodeURIComponent(teamId)}` : `slug=${encodeURIComponent(teamId)}`;
|
|
160
|
+
const [teamData, projectData] = await Promise.all([require_api.fetchApi({
|
|
161
|
+
token,
|
|
162
|
+
endpoint: `/v2/teams/${encodeURIComponent(teamId)}`
|
|
163
|
+
}).then(zod.z.object({ slug: zod.z.string() }).parse), require_api.fetchApi({
|
|
164
|
+
token,
|
|
165
|
+
endpoint: `/v2/projects/${encodeURIComponent(projectId)}?${teamParam}`
|
|
166
|
+
}).then(zod.z.object({ name: zod.z.string() }).parse)]);
|
|
167
|
+
return {
|
|
168
|
+
teamSlug: teamData.slug,
|
|
169
|
+
projectSlug: projectData.name
|
|
170
|
+
};
|
|
171
|
+
} catch {
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
//#endregion
|
|
177
|
+
exports.inferScope = inferScope;
|
|
178
|
+
//# sourceMappingURL=project.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.cjs","names":["z","NotOk","readLinkedProject","fetchApi","next: number | null","endpoint: string"],"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 UserSchema = z.object({\n user: z.object({\n defaultTeamId: z.string().nullable(),\n username: z.string(),\n }),\n});\n\nconst TeamSchema = z.object({\n id: z.string(),\n slug: z.string(),\n updatedAt: z.number(),\n membership: z.object({\n role: z.string(),\n }),\n billing: z.object({\n plan: z.string(),\n }),\n});\n\nconst TeamsSchema = z.object({\n teams: z.array(TeamSchema),\n pagination: z.object({\n count: z.number(),\n next: z.number().nullable(),\n }),\n});\n\nconst DEFAULT_PROJECT_NAME = \"vercel-sandbox-default-project\";\n\n/** Status codes that mean \"this team can't be used, try the next one\". */\nfunction isSkippableTeamError(e: unknown): boolean {\n return e instanceof NotOk && (e.response.statusCode === 402 || e.response.statusCode === 403);\n}\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, builds an ordered list of candidate\n * teams to try: the user's `defaultTeamId` first (if set), then hobby-plan\n * teams where the user has an OWNER role (preferring the personal team matching\n * the username, then the most recently updated). Tries each candidate until one\n * succeeds.\n *\n * @param opts.token - Vercel API authentication token.\n * @param opts.teamId - Optional team slug. If omitted, candidate teams are resolved automatically.\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 *\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<{\n projectId: string;\n teamId: string;\n created: boolean;\n teamSlug?: string;\n projectSlug?: string;\n}> {\n const linkedProject = await readLinkedProject(opts.cwd ?? process.cwd());\n if (linkedProject) {\n const slugs = await resolveLinkedProjectSlugs(\n opts.token,\n linkedProject.teamId,\n linkedProject.projectId,\n );\n return { ...linkedProject, created: false, ...slugs };\n }\n\n if (opts.teamId) {\n return tryTeam(opts.token, opts.teamId);\n }\n\n const userData = await fetchApi({\n token: opts.token,\n endpoint: \"/v2/user\",\n }).then(UserSchema.parse);\n const { defaultTeamId, username } = userData.user;\n\n // 1. Try defaultTeamId first\n if (defaultTeamId) {\n try {\n const result = await tryTeam(opts.token, defaultTeamId);\n // Resolve team slug (best-effort)\n try {\n const team = await fetchApi({\n token: opts.token,\n endpoint: `/v2/teams/${encodeURIComponent(defaultTeamId)}`,\n }).then(z.object({ slug: z.string() }).parse);\n return { ...result, teamSlug: team.slug };\n } catch {\n return result;\n }\n } catch (e) {\n if (!isSkippableTeamError(e)) throw e;\n }\n }\n\n // 2. Paginate teams in pages of 20, try best hobby team per page\n let next: number | null = null;\n do {\n const endpoint: string =\n next === null\n ? \"/v2/teams?limit=20\"\n : `/v2/teams?limit=20&until=${next}`;\n const page = await fetchApi({ token: opts.token, endpoint }).then(\n TeamsSchema.parse,\n );\n\n next = page.pagination.next;\n\n const hobbyOwnerTeams = page.teams.filter(\n (t) => t.membership.role === \"OWNER\" && t.billing.plan === \"hobby\",\n );\n if (hobbyOwnerTeams.length === 0) {\n continue;\n }\n\n const bestHobbyTeam =\n hobbyOwnerTeams.find((t) => t.slug === username) ??\n hobbyOwnerTeams.sort((a, b) => b.updatedAt - a.updatedAt)[0];\n\n if (bestHobbyTeam && bestHobbyTeam.id !== defaultTeamId) {\n try {\n const result = await tryTeam(opts.token, bestHobbyTeam.id);\n return { ...result, teamSlug: bestHobbyTeam.slug };\n } catch (e) {\n if (!isSkippableTeamError(e)) throw e;\n }\n }\n } while (next !== null);\n\n // 3. Fall back to username as personal team\n try {\n const result = await tryTeam(opts.token, username);\n return { ...result, teamSlug: username };\n } catch (e) {\n if (!isSkippableTeamError(e)) throw e;\n }\n\n throw new NotOk({\n statusCode: 403,\n responseText: `Authenticated as \"${username}\" but none of the available teams allow sandbox creation. Specify a team explicitly with --scope <team-id-or-slug>.`,\n });\n}\n\n/**\n * Attempts to use a specific team for sandbox operations by checking for\n * (or creating) the default project within that team.\n *\n * @returns The resolved scope if the team is usable.\n * @throws {NotOk} On authorization or other API errors.\n */\nasync function tryTeam(\n token: string,\n teamId: string,\n): Promise<{ projectId: string; teamId: string; created: boolean }> {\n const teamParam = teamId.startsWith(\"team_\")\n ? `teamId=${encodeURIComponent(teamId)}`\n : `slug=${encodeURIComponent(teamId)}`;\n\n let created = false;\n try {\n await fetchApi({\n token,\n endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?${teamParam}`,\n });\n } catch (e) {\n if (!(e instanceof NotOk) || e.response.statusCode !== 404) {\n throw e;\n }\n\n await fetchApi({\n token,\n endpoint: `/v11/projects?${teamParam}`,\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 * Best-effort resolution of team slug and project name for a linked project.\n * Both IDs may be opaque (e.g. `team_xxx`, `prj_xxx`), so we fetch the\n * human-readable names from the API in parallel.\n */\nasync function resolveLinkedProjectSlugs(\n token: string,\n teamId: string,\n projectId: string,\n): Promise<{ teamSlug?: string; projectSlug?: string }> {\n try {\n const teamParam = teamId.startsWith(\"team_\")\n ? `teamId=${encodeURIComponent(teamId)}`\n : `slug=${encodeURIComponent(teamId)}`;\n const [teamData, projectData] = await Promise.all([\n fetchApi({\n token,\n endpoint: `/v2/teams/${encodeURIComponent(teamId)}`,\n }).then(z.object({ slug: z.string() }).parse),\n fetchApi({\n token,\n endpoint: `/v2/projects/${encodeURIComponent(projectId)}?${teamParam}`,\n }).then(z.object({ name: z.string() }).parse),\n ]);\n return { teamSlug: teamData.slug, projectSlug: projectData.name };\n } catch {\n return {};\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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, builds an ordered list of candidate
|
|
9
|
+
* teams to try: the user's `defaultTeamId` first (if set), then hobby-plan
|
|
10
|
+
* teams where the user has an OWNER role (preferring the personal team matching
|
|
11
|
+
* the username, then the most recently updated). Tries each candidate until one
|
|
12
|
+
* succeeds.
|
|
13
|
+
*
|
|
14
|
+
* @param opts.token - Vercel API authentication token.
|
|
15
|
+
* @param opts.teamId - Optional team slug. If omitted, candidate teams are resolved automatically.
|
|
16
|
+
* @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.
|
|
17
|
+
* @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.
|
|
18
|
+
*
|
|
19
|
+
* @throws {NotOk} If the API returns an error other than 404 when checking the project.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const scope = await inferScope({ token: "vercel_..." });
|
|
24
|
+
* // => { projectId: "vercel-sandbox-default-project", teamId: "my-team", created: false }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function inferScope(opts: {
|
|
28
|
+
token: string;
|
|
29
|
+
teamId?: string;
|
|
30
|
+
cwd?: string;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
projectId: string;
|
|
33
|
+
teamId: string;
|
|
34
|
+
created: boolean;
|
|
35
|
+
teamSlug?: string;
|
|
36
|
+
projectSlug?: string;
|
|
37
|
+
}>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { inferScope };
|
|
40
|
+
//# sourceMappingURL=project.d.cts.map
|
package/dist/auth/project.d.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
+
//#region src/auth/project.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Resolves the team and project scope for sandbox operations.
|
|
3
4
|
*
|
|
4
5
|
* First checks for a locally linked project in `.vercel/project.json`.
|
|
5
6
|
* If found, uses the `projectId` and `orgId` from there.
|
|
6
7
|
*
|
|
7
|
-
* Otherwise, if `teamId` is not provided,
|
|
8
|
-
*
|
|
8
|
+
* Otherwise, if `teamId` is not provided, builds an ordered list of candidate
|
|
9
|
+
* teams to try: the user's `defaultTeamId` first (if set), then hobby-plan
|
|
10
|
+
* teams where the user has an OWNER role (preferring the personal team matching
|
|
11
|
+
* the username, then the most recently updated). Tries each candidate until one
|
|
12
|
+
* succeeds.
|
|
9
13
|
*
|
|
10
14
|
* @param opts.token - Vercel API authentication token.
|
|
11
|
-
* @param opts.teamId - Optional team slug. If omitted,
|
|
15
|
+
* @param opts.teamId - Optional team slug. If omitted, candidate teams are resolved automatically.
|
|
12
16
|
* @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.
|
|
13
17
|
* @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.
|
|
14
18
|
*
|
|
15
19
|
* @throws {NotOk} If the API returns an error other than 404 when checking the project.
|
|
16
|
-
* @throws {ZodError} If no teams exist for the account.
|
|
17
20
|
*
|
|
18
21
|
* @example
|
|
19
22
|
* ```ts
|
|
@@ -21,20 +24,17 @@
|
|
|
21
24
|
* // => { projectId: "vercel-sandbox-default-project", teamId: "my-team", created: false }
|
|
22
25
|
* ```
|
|
23
26
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
declare function inferScope(opts: {
|
|
28
|
+
token: string;
|
|
29
|
+
teamId?: string;
|
|
30
|
+
cwd?: string;
|
|
28
31
|
}): Promise<{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
projectId: string;
|
|
33
|
+
teamId: string;
|
|
34
|
+
created: boolean;
|
|
35
|
+
teamSlug?: string;
|
|
36
|
+
projectSlug?: string;
|
|
32
37
|
}>;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
* @param token - Authentication token used to call the Vercel API.
|
|
38
|
-
* @returns A promise that resolves to the first team's slug.
|
|
39
|
-
*/
|
|
40
|
-
export declare function selectTeam(token: string): Promise<string>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { inferScope };
|
|
40
|
+
//# sourceMappingURL=project.d.ts.map
|