@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.
Files changed (208) hide show
  1. package/README.md +48 -1
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/api-client/api-client.cjs +445 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +6235 -0
  6. package/dist/api-client/api-client.d.ts +6229 -706
  7. package/dist/api-client/api-client.js +436 -472
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +32 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +29 -0
  12. package/dist/api-client/api-error.d.ts +21 -16
  13. package/dist/api-client/api-error.js +28 -32
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +126 -0
  16. package/dist/api-client/base-client.cjs.map +1 -0
  17. package/dist/api-client/base-client.d.cts +38 -0
  18. package/dist/api-client/base-client.d.ts +31 -36
  19. package/dist/api-client/base-client.js +114 -118
  20. package/dist/api-client/base-client.js.map +1 -1
  21. package/dist/api-client/file-writer.cjs +62 -0
  22. package/dist/api-client/file-writer.cjs.map +1 -0
  23. package/dist/api-client/file-writer.d.cts +66 -0
  24. package/dist/api-client/file-writer.d.ts +56 -42
  25. package/dist/api-client/file-writer.js +57 -61
  26. package/dist/api-client/file-writer.js.map +1 -1
  27. package/dist/api-client/index.cjs +2 -0
  28. package/dist/api-client/index.d.ts +2 -2
  29. package/dist/api-client/index.js +4 -21
  30. package/dist/api-client/validators.cjs +229 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +26885 -0
  33. package/dist/api-client/validators.d.ts +26732 -3706
  34. package/dist/api-client/validators.js +198 -191
  35. package/dist/api-client/validators.js.map +1 -1
  36. package/dist/api-client/with-retry.cjs +89 -0
  37. package/dist/api-client/with-retry.cjs.map +1 -0
  38. package/dist/api-client/with-retry.d.cts +10 -0
  39. package/dist/api-client/with-retry.d.ts +9 -13
  40. package/dist/api-client/with-retry.js +81 -102
  41. package/dist/api-client/with-retry.js.map +1 -1
  42. package/dist/auth/api.cjs +29 -0
  43. package/dist/auth/api.cjs.map +1 -0
  44. package/dist/auth/api.js +26 -25
  45. package/dist/auth/api.js.map +1 -1
  46. package/dist/auth/error.cjs +13 -0
  47. package/dist/auth/error.cjs.map +1 -0
  48. package/dist/auth/error.js +11 -11
  49. package/dist/auth/error.js.map +1 -1
  50. package/dist/auth/file.cjs +64 -0
  51. package/dist/auth/file.cjs.map +1 -0
  52. package/dist/auth/file.d.cts +26 -0
  53. package/dist/auth/file.d.ts +19 -15
  54. package/dist/auth/file.js +49 -64
  55. package/dist/auth/file.js.map +1 -1
  56. package/dist/auth/index.cjs +11 -0
  57. package/dist/auth/index.d.cts +5 -0
  58. package/dist/auth/index.d.ts +5 -6
  59. package/dist/auth/index.js +6 -27
  60. package/dist/auth/linked-project.cjs +38 -0
  61. package/dist/auth/linked-project.cjs.map +1 -0
  62. package/dist/auth/linked-project.js +30 -64
  63. package/dist/auth/linked-project.js.map +1 -1
  64. package/dist/auth/oauth.cjs +205 -0
  65. package/dist/auth/oauth.cjs.map +1 -0
  66. package/dist/auth/oauth.d.cts +135 -0
  67. package/dist/auth/oauth.d.ts +113 -109
  68. package/dist/auth/oauth.js +185 -252
  69. package/dist/auth/oauth.js.map +1 -1
  70. package/dist/auth/poll-for-token.cjs +82 -0
  71. package/dist/auth/poll-for-token.cjs.map +1 -0
  72. package/dist/auth/poll-for-token.d.cts +28 -0
  73. package/dist/auth/poll-for-token.d.ts +23 -15
  74. package/dist/auth/poll-for-token.js +79 -64
  75. package/dist/auth/poll-for-token.js.map +1 -1
  76. package/dist/auth/project.cjs +178 -0
  77. package/dist/auth/project.cjs.map +1 -0
  78. package/dist/auth/project.d.cts +40 -0
  79. package/dist/auth/project.d.ts +19 -19
  80. package/dist/auth/project.js +169 -72
  81. package/dist/auth/project.js.map +1 -1
  82. package/dist/auth/zod.cjs +22 -0
  83. package/dist/auth/zod.cjs.map +1 -0
  84. package/dist/auth/zod.js +18 -17
  85. package/dist/auth/zod.js.map +1 -1
  86. package/dist/command.cjs +328 -0
  87. package/dist/command.cjs.map +1 -0
  88. package/dist/command.d.cts +289 -0
  89. package/dist/command.d.ts +265 -171
  90. package/dist/command.js +323 -226
  91. package/dist/command.js.map +1 -1
  92. package/dist/constants.d.cts +5 -0
  93. package/dist/constants.d.ts +5 -1
  94. package/dist/filesystem.cjs +499 -0
  95. package/dist/filesystem.cjs.map +1 -0
  96. package/dist/filesystem.d.cts +258 -0
  97. package/dist/filesystem.d.ts +258 -0
  98. package/dist/filesystem.js +497 -0
  99. package/dist/filesystem.js.map +1 -0
  100. package/dist/index.cjs +15 -0
  101. package/dist/index.d.cts +8 -0
  102. package/dist/index.d.ts +8 -6
  103. package/dist/index.js +8 -17
  104. package/dist/network-policy.d.cts +156 -0
  105. package/dist/network-policy.d.ts +88 -28
  106. package/dist/sandbox.cjs +816 -0
  107. package/dist/sandbox.cjs.map +1 -0
  108. package/dist/sandbox.d.cts +2847 -0
  109. package/dist/sandbox.d.ts +2834 -628
  110. package/dist/sandbox.js +808 -557
  111. package/dist/sandbox.js.map +1 -1
  112. package/dist/session.cjs +527 -0
  113. package/dist/session.cjs.map +1 -0
  114. package/dist/session.d.cts +410 -0
  115. package/dist/session.d.ts +403 -368
  116. package/dist/session.js +524 -489
  117. package/dist/session.js.map +1 -1
  118. package/dist/snapshot.cjs +204 -0
  119. package/dist/snapshot.cjs.map +1 -0
  120. package/dist/snapshot.d.cts +161 -0
  121. package/dist/snapshot.d.ts +152 -92
  122. package/dist/snapshot.js +201 -114
  123. package/dist/snapshot.js.map +1 -1
  124. package/dist/utils/array.cjs +17 -0
  125. package/dist/utils/array.cjs.map +1 -0
  126. package/dist/utils/array.js +12 -15
  127. package/dist/utils/array.js.map +1 -1
  128. package/dist/utils/consume-readable.cjs +18 -0
  129. package/dist/utils/consume-readable.cjs.map +1 -0
  130. package/dist/utils/consume-readable.js +13 -12
  131. package/dist/utils/consume-readable.js.map +1 -1
  132. package/dist/utils/decode-base64-url.cjs +15 -0
  133. package/dist/utils/decode-base64-url.cjs.map +1 -0
  134. package/dist/utils/decode-base64-url.js +10 -9
  135. package/dist/utils/decode-base64-url.js.map +1 -1
  136. package/dist/utils/dev-credentials.cjs +142 -0
  137. package/dist/utils/dev-credentials.cjs.map +1 -0
  138. package/dist/utils/dev-credentials.js +126 -184
  139. package/dist/utils/dev-credentials.js.map +1 -1
  140. package/dist/utils/get-credentials.cjs +123 -0
  141. package/dist/utils/get-credentials.cjs.map +1 -0
  142. package/dist/utils/get-credentials.d.cts +21 -0
  143. package/dist/utils/get-credentials.d.ts +19 -61
  144. package/dist/utils/get-credentials.js +106 -140
  145. package/dist/utils/get-credentials.js.map +1 -1
  146. package/dist/utils/log.cjs +25 -0
  147. package/dist/utils/log.cjs.map +1 -0
  148. package/dist/utils/log.js +15 -17
  149. package/dist/utils/log.js.map +1 -1
  150. package/dist/utils/network-policy.cjs +49 -0
  151. package/dist/utils/network-policy.cjs.map +1 -0
  152. package/dist/utils/network-policy.js +42 -77
  153. package/dist/utils/network-policy.js.map +1 -1
  154. package/dist/utils/normalizePath.cjs +27 -0
  155. package/dist/utils/normalizePath.cjs.map +1 -0
  156. package/dist/utils/normalizePath.js +21 -28
  157. package/dist/utils/normalizePath.js.map +1 -1
  158. package/dist/utils/paginator.cjs +41 -0
  159. package/dist/utils/paginator.cjs.map +1 -0
  160. package/dist/utils/paginator.d.cts +16 -0
  161. package/dist/utils/paginator.d.ts +16 -0
  162. package/dist/utils/paginator.js +40 -0
  163. package/dist/utils/paginator.js.map +1 -0
  164. package/dist/utils/resolveSignal.cjs +20 -0
  165. package/dist/utils/resolveSignal.cjs.map +1 -0
  166. package/dist/utils/resolveSignal.d.cts +15 -0
  167. package/dist/utils/resolveSignal.d.ts +12 -10
  168. package/dist/utils/resolveSignal.js +14 -17
  169. package/dist/utils/resolveSignal.js.map +1 -1
  170. package/dist/utils/sandbox-snapshot.cjs +14 -0
  171. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  172. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  173. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  174. package/dist/utils/sandbox-snapshot.js +14 -0
  175. package/dist/utils/sandbox-snapshot.js.map +1 -0
  176. package/dist/utils/types.cjs +13 -0
  177. package/dist/utils/types.cjs.map +1 -0
  178. package/dist/utils/types.d.cts +11 -0
  179. package/dist/utils/types.d.ts +5 -7
  180. package/dist/utils/types.js +8 -8
  181. package/dist/utils/types.js.map +1 -1
  182. package/dist/version.cjs +7 -0
  183. package/dist/version.cjs.map +1 -0
  184. package/dist/version.js +5 -5
  185. package/dist/version.js.map +1 -1
  186. package/package.json +23 -3
  187. package/dist/api-client/index.js.map +0 -1
  188. package/dist/auth/api.d.ts +0 -6
  189. package/dist/auth/error.d.ts +0 -11
  190. package/dist/auth/index.js.map +0 -1
  191. package/dist/auth/linked-project.d.ts +0 -10
  192. package/dist/auth/zod.d.ts +0 -5
  193. package/dist/constants.js +0 -3
  194. package/dist/constants.js.map +0 -1
  195. package/dist/index.js.map +0 -1
  196. package/dist/network-policy.js +0 -3
  197. package/dist/network-policy.js.map +0 -1
  198. package/dist/utils/array.d.ts +0 -9
  199. package/dist/utils/consume-readable.d.ts +0 -5
  200. package/dist/utils/convert-sandbox.d.ts +0 -6
  201. package/dist/utils/convert-sandbox.js +0 -14
  202. package/dist/utils/convert-sandbox.js.map +0 -1
  203. package/dist/utils/decode-base64-url.d.ts +0 -7
  204. package/dist/utils/dev-credentials.d.ts +0 -37
  205. package/dist/utils/log.d.ts +0 -2
  206. package/dist/utils/network-policy.d.ts +0 -7
  207. package/dist/utils/normalizePath.d.ts +0 -17
  208. package/dist/version.d.ts +0 -1
@@ -1,20 +1,28 @@
1
- import { DeviceAuthorizationRequest, OAuth } from "./oauth";
2
- export type PollTokenItem = {
3
- _tag: "Timeout";
4
- newInterval: number;
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
- _tag: "SlowDown";
7
- newInterval: number;
8
+ _tag: "SlowDown";
9
+ newInterval: number;
8
10
  } | {
9
- _tag: "Error";
10
- error: Error;
11
+ _tag: "Error";
12
+ error: Error;
11
13
  } | {
12
- _tag: "Response";
13
- response: {
14
- text(): Promise<string>;
15
- };
14
+ _tag: "Response";
15
+ response: {
16
+ text(): Promise<string>;
17
+ };
16
18
  };
17
- export declare function pollForToken({ request, oauth, }: {
18
- request: DeviceAuthorizationRequest;
19
- oauth: OAuth;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pollForToken = pollForToken;
4
- const promises_1 = require("node:timers/promises");
5
- const file_1 = require("./file");
6
- const oauth_1 = require("./oauth");
7
- async function* pollForToken({ request, oauth, }) {
8
- const controller = new AbortController();
9
- try {
10
- let intervalMs = request.interval * 1000;
11
- while (Date.now() < request.expiresAt) {
12
- const [tokenResponseError, tokenResponse] = await oauth.deviceAccessTokenRequest(request.device_code);
13
- if (tokenResponseError) {
14
- // 2x backoff on connection timeouts per spec https://datatracker.ietf.org/doc/html/rfc8628#section-3.5
15
- if (tokenResponseError.message.includes("timeout")) {
16
- intervalMs *= 2;
17
- yield { _tag: "Timeout", newInterval: intervalMs };
18
- await (0, promises_1.setTimeout)(intervalMs, { signal: controller.signal });
19
- continue;
20
- }
21
- yield { _tag: "Error", error: tokenResponseError };
22
- return;
23
- }
24
- yield {
25
- _tag: "Response",
26
- response: tokenResponse.clone(),
27
- };
28
- const [tokensError, tokens] = await oauth.processTokenResponse(tokenResponse);
29
- if ((0, oauth_1.isOAuthError)(tokensError)) {
30
- const { code } = tokensError;
31
- switch (code) {
32
- case "authorization_pending":
33
- await (0, promises_1.setTimeout)(intervalMs, { signal: controller.signal });
34
- continue;
35
- case "slow_down":
36
- intervalMs += 5 * 1000;
37
- yield { _tag: "SlowDown", newInterval: intervalMs };
38
- await (0, promises_1.setTimeout)(intervalMs, { signal: controller.signal });
39
- continue;
40
- default:
41
- yield { _tag: "Error", error: tokensError.cause };
42
- return;
43
- }
44
- }
45
- if (tokensError) {
46
- yield { _tag: "Error", error: tokensError };
47
- return;
48
- }
49
- (0, file_1.updateAuthConfig)({
50
- token: tokens.access_token,
51
- expiresAt: new Date(Date.now() + tokens.expires_in * 1000),
52
- refreshToken: tokens.refresh_token,
53
- });
54
- return;
55
- }
56
- yield {
57
- _tag: "Error",
58
- error: new Error("Timed out waiting for authentication. Please try again."),
59
- };
60
- return;
61
- }
62
- finally {
63
- controller.abort();
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","sourceRoot":"","sources":["../../src/auth/poll-for-token.ts"],"names":[],"mappings":";;AAaA,oCA2EC;AAxFD,mDAAkD;AAClD,iCAA0C;AAC1C,mCAA0E;AAWnE,KAAK,SAAS,CAAC,CAAC,YAAY,CAAC,EAClC,OAAO,EACP,KAAK,GAIN;IACC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,IAAI,CAAC;QACH,IAAI,UAAU,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;QACzC,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CA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UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;wBAC5D,SAAS;oBACX;wBACE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC;wBAClD,OAAO;gBACX,CAAC;YACH,CAAC;YAED,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;gBAC5C,OAAO;YACT,CAAC;YAED,IAAA,uBAAgB,EAAC;gBACf,KAAK,EAAE,MAAM,CAAC,YAAY;gBAC1B,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;gBAC1D,YAAY,EAAE,MAAM,CAAC,aAAa;aACnC,CAAC,CAAC;YAEH,OAAO;QACT,CAAC;QAED,MAAM;YACJ,IAAI,EAAE,OAAgB;YACtB,KAAK,EAAE,IAAI,KAAK,CACd,yDAAyD,CAC1D;SACF,CAAC;QACF,OAAO;IACT,CAAC;YAAS,CAAC;QACT,UAAU,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;AACH,CAAC"}
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":";;;;;;;AAKA,MAAM,aAAaA,MAAE,OAAO,EAC1B,MAAMA,MAAE,OAAO;CACb,eAAeA,MAAE,QAAQ,CAAC,UAAU;CACpC,UAAUA,MAAE,QAAQ;CACrB,CAAC,EACH,CAAC;AAEF,MAAM,aAAaA,MAAE,OAAO;CAC1B,IAAIA,MAAE,QAAQ;CACd,MAAMA,MAAE,QAAQ;CAChB,WAAWA,MAAE,QAAQ;CACrB,YAAYA,MAAE,OAAO,EACnB,MAAMA,MAAE,QAAQ,EACjB,CAAC;CACF,SAASA,MAAE,OAAO,EAChB,MAAMA,MAAE,QAAQ,EACjB,CAAC;CACH,CAAC;AAEF,MAAM,cAAcA,MAAE,OAAO;CAC3B,OAAOA,MAAE,MAAM,WAAW;CAC1B,YAAYA,MAAE,OAAO;EACnB,OAAOA,MAAE,QAAQ;EACjB,MAAMA,MAAE,QAAQ,CAAC,UAAU;EAC5B,CAAC;CACH,CAAC;AAEF,MAAM,uBAAuB;;AAG7B,SAAS,qBAAqB,GAAqB;AACjD,QAAO,aAAaC,wBAAU,EAAE,SAAS,eAAe,OAAO,EAAE,SAAS,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B3F,eAAsB,WAAW,MAU9B;CACD,MAAM,gBAAgB,MAAMC,yCAAkB,KAAK,OAAO,QAAQ,KAAK,CAAC;AACxE,KAAI,eAAe;EACjB,MAAM,QAAQ,MAAM,0BAClB,KAAK,OACL,cAAc,QACd,cAAc,UACf;AACD,SAAO;GAAE,GAAG;GAAe,SAAS;GAAO,GAAG;GAAO;;AAGvD,KAAI,KAAK,OACP,QAAO,QAAQ,KAAK,OAAO,KAAK,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#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
@@ -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, selects the first available team for the account.
8
- * Ensures a default project exists within the team, creating it if necessary.
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, the first team is selected.
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
- export declare function inferScope(opts: {
25
- token: string;
26
- teamId?: string;
27
- cwd?: string;
27
+ declare function inferScope(opts: {
28
+ token: string;
29
+ teamId?: string;
30
+ cwd?: string;
28
31
  }): Promise<{
29
- projectId: string;
30
- teamId: string;
31
- created: boolean;
32
+ projectId: string;
33
+ teamId: string;
34
+ created: boolean;
35
+ teamSlug?: string;
36
+ projectSlug?: string;
32
37
  }>;
33
- /**
34
- * Selects a team for the current token by querying the Teams API and
35
- * returning the slug of the first team in the result set.
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