@vercel/sandbox 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/README.md +8 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/api-client/api-client.cjs +375 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +403 -0
  6. package/dist/api-client/api-client.d.ts +397 -392
  7. package/dist/api-client/api-client.js +365 -405
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +31 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +27 -0
  12. package/dist/api-client/api-error.d.ts +19 -16
  13. package/dist/api-client/api-error.js +27 -32
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +113 -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 +101 -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 -52
  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 +149 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +1677 -0
  33. package/dist/api-client/validators.d.ts +1501 -2412
  34. package/dist/api-client/validators.js +124 -154
  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 +12 -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 +80 -0
  77. package/dist/auth/project.cjs.map +1 -0
  78. package/dist/auth/project.d.cts +44 -0
  79. package/dist/auth/project.d.ts +12 -8
  80. package/dist/auth/project.js +70 -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 +326 -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 +321 -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/index.cjs +11 -0
  95. package/dist/index.d.cts +6 -0
  96. package/dist/index.d.ts +6 -5
  97. package/dist/index.js +6 -15
  98. package/dist/network-policy.d.cts +100 -0
  99. package/dist/network-policy.d.ts +32 -28
  100. package/dist/sandbox.cjs +543 -0
  101. package/dist/sandbox.cjs.map +1 -0
  102. package/dist/sandbox.d.cts +538 -0
  103. package/dist/sandbox.d.ts +521 -479
  104. package/dist/sandbox.js +539 -512
  105. package/dist/sandbox.js.map +1 -1
  106. package/dist/snapshot.cjs +116 -0
  107. package/dist/snapshot.cjs.map +1 -0
  108. package/dist/snapshot.d.cts +109 -0
  109. package/dist/snapshot.d.ts +100 -92
  110. package/dist/snapshot.js +114 -114
  111. package/dist/snapshot.js.map +1 -1
  112. package/dist/utils/array.cjs +17 -0
  113. package/dist/utils/array.cjs.map +1 -0
  114. package/dist/utils/array.js +12 -15
  115. package/dist/utils/array.js.map +1 -1
  116. package/dist/utils/consume-readable.cjs +18 -0
  117. package/dist/utils/consume-readable.cjs.map +1 -0
  118. package/dist/utils/consume-readable.js +13 -12
  119. package/dist/utils/consume-readable.js.map +1 -1
  120. package/dist/utils/decode-base64-url.cjs +15 -0
  121. package/dist/utils/decode-base64-url.cjs.map +1 -0
  122. package/dist/utils/decode-base64-url.js +10 -9
  123. package/dist/utils/decode-base64-url.js.map +1 -1
  124. package/dist/utils/dev-credentials.cjs +142 -0
  125. package/dist/utils/dev-credentials.cjs.map +1 -0
  126. package/dist/utils/dev-credentials.js +126 -184
  127. package/dist/utils/dev-credentials.js.map +1 -1
  128. package/dist/utils/get-credentials.cjs +123 -0
  129. package/dist/utils/get-credentials.cjs.map +1 -0
  130. package/dist/utils/get-credentials.d.cts +21 -0
  131. package/dist/utils/get-credentials.d.ts +19 -61
  132. package/dist/utils/get-credentials.js +106 -140
  133. package/dist/utils/get-credentials.js.map +1 -1
  134. package/dist/utils/log.cjs +25 -0
  135. package/dist/utils/log.cjs.map +1 -0
  136. package/dist/utils/log.js +15 -17
  137. package/dist/utils/log.js.map +1 -1
  138. package/dist/utils/network-policy.cjs +65 -0
  139. package/dist/utils/network-policy.cjs.map +1 -0
  140. package/dist/utils/network-policy.js +58 -77
  141. package/dist/utils/network-policy.js.map +1 -1
  142. package/dist/utils/normalizePath.cjs +27 -0
  143. package/dist/utils/normalizePath.cjs.map +1 -0
  144. package/dist/utils/normalizePath.js +21 -28
  145. package/dist/utils/normalizePath.js.map +1 -1
  146. package/dist/utils/resolveSignal.cjs +20 -0
  147. package/dist/utils/resolveSignal.cjs.map +1 -0
  148. package/dist/utils/resolveSignal.d.cts +15 -0
  149. package/dist/utils/resolveSignal.d.ts +12 -10
  150. package/dist/utils/resolveSignal.js +14 -17
  151. package/dist/utils/resolveSignal.js.map +1 -1
  152. package/dist/utils/sandbox-snapshot.cjs +14 -0
  153. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  154. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  155. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  156. package/dist/utils/sandbox-snapshot.js +14 -0
  157. package/dist/utils/sandbox-snapshot.js.map +1 -0
  158. package/dist/utils/types.cjs +13 -0
  159. package/dist/utils/types.cjs.map +1 -0
  160. package/dist/utils/types.d.cts +11 -0
  161. package/dist/utils/types.d.ts +5 -7
  162. package/dist/utils/types.js +8 -8
  163. package/dist/utils/types.js.map +1 -1
  164. package/dist/version.cjs +7 -0
  165. package/dist/version.cjs.map +1 -0
  166. package/dist/version.js +5 -5
  167. package/dist/version.js.map +1 -1
  168. package/package.json +23 -3
  169. package/dist/api-client/index.js.map +0 -1
  170. package/dist/auth/api.d.ts +0 -6
  171. package/dist/auth/error.d.ts +0 -11
  172. package/dist/auth/index.js.map +0 -1
  173. package/dist/auth/linked-project.d.ts +0 -10
  174. package/dist/auth/zod.d.ts +0 -5
  175. package/dist/constants.js +0 -3
  176. package/dist/constants.js.map +0 -1
  177. package/dist/index.js.map +0 -1
  178. package/dist/network-policy.js +0 -3
  179. package/dist/network-policy.js.map +0 -1
  180. package/dist/utils/array.d.ts +0 -9
  181. package/dist/utils/consume-readable.d.ts +0 -5
  182. package/dist/utils/convert-sandbox.d.ts +0 -6
  183. package/dist/utils/convert-sandbox.js +0 -14
  184. package/dist/utils/convert-sandbox.js.map +0 -1
  185. package/dist/utils/decode-base64-url.d.ts +0 -7
  186. package/dist/utils/dev-credentials.d.ts +0 -37
  187. package/dist/utils/log.d.ts +0 -2
  188. package/dist/utils/network-policy.d.ts +0 -7
  189. package/dist/utils/normalizePath.d.ts +0 -17
  190. 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,CAAC,SAAS,EAAE,CAAC;YACtC,MAAM,CAAC,kBAAkB,EAAE,aAAa,CAAC,GACvC,MAAM,KAAK,CAAC,wBAAwB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAE5D,IAAI,kBAAkB,EAAE,CAAC;gBACvB,uGAAuG;gBACvG,IAAI,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;oBACnD,UAAU,IAAI,CAAC,CAAC;oBAChB,MAAM,EAAE,IAAI,EAAE,SAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;oBAC5D,MAAM,IAAA,qBAAU,EAAC,UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;oBAC5D,SAAS;gBACX,CAAC;gBACD,MAAM,EAAE,IAAI,EAAE,OAAgB,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC;gBAC5D,OAAO;YACT,CAAC;YAED,MAAM;gBACJ,IAAI,EAAE,UAAmB;gBACzB,QAAQ,EAAE,aAAa,CAAC,KAAK,EAAiC;aAC/D,CAAC;YAEF,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,GACzB,MAAM,KAAK,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC;YAElD,IAAI,IAAA,oBAAY,EAAC,WAAW,CAAC,EAAE,CAAC;gBAC9B,MAAM,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;gBAC7B,QAAQ,IAAI,EAAE,CAAC;oBACb,KAAK,uBAAuB;wBAC1B,MAAM,IAAA,qBAAU,EAAC,UAAU,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;wBAC5D,SAAS;oBACX,KAAK,WAAW;wBACd,UAAU,IAAI,CAAC,GAAG,IAAI,CAAC;wBACvB,MAAM,EAAE,IAAI,EAAE,UAAmB,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;wBAC7D,MAAM,IAAA,qBAAU,EAAC,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,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
@@ -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
- export declare function inferScope(opts: {
25
- token: string;
26
- teamId?: string;
27
- cwd?: string;
25
+ declare function inferScope(opts: {
26
+ token: string;
27
+ teamId?: string;
28
+ cwd?: string;
28
29
  }): Promise<{
29
- projectId: string;
30
- teamId: string;
31
- created: boolean;
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
- export declare function selectTeam(token: string): Promise<string>;
41
+ declare function selectTeam(token: string): Promise<string>;
42
+ //#endregion
43
+ export { inferScope, selectTeam };
44
+ //# sourceMappingURL=project.d.ts.map
@@ -1,80 +1,78 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.inferScope = inferScope;
4
- exports.selectTeam = selectTeam;
5
- const zod_1 = require("zod");
6
- const api_1 = require("./api");
7
- const error_1 = require("./error");
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
- * Resolves the team and project scope for sandbox operations.
19
- *
20
- * First checks for a locally linked project in `.vercel/project.json`.
21
- * If found, uses the `projectId` and `orgId` from there.
22
- *
23
- * Otherwise, if `teamId` is not provided, selects the first available team for the account.
24
- * Ensures a default project exists within the team, creating it if necessary.
25
- *
26
- * @param opts.token - Vercel API authentication token.
27
- * @param opts.teamId - Optional team slug. If omitted, the first team is selected.
28
- * @param opts.cwd - Optional directory to search for `.vercel/project.json`. Defaults to `process.cwd()`.
29
- * @returns The resolved scope with `projectId`, `teamId`, and whether the project was `created`.
30
- *
31
- * @throws {NotOk} If the API returns an error other than 404 when checking the project.
32
- * @throws {ZodError} If no teams exist for the account.
33
- *
34
- * @example
35
- * ```ts
36
- * const scope = await inferScope({ token: "vercel_..." });
37
- * // => { projectId: "vercel-sandbox-default-project", teamId: "my-team", created: false }
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
- const linkedProject = await (0, linked_project_1.readLinkedProject)(opts.cwd ?? process.cwd());
42
- if (linkedProject) {
43
- return { ...linkedProject, created: false };
44
- }
45
- const teamId = opts.teamId ?? (await selectTeam(opts.token));
46
- let created = false;
47
- try {
48
- await (0, api_1.fetchApi)({
49
- token: opts.token,
50
- endpoint: `/v2/projects/${encodeURIComponent(DEFAULT_PROJECT_NAME)}?slug=${encodeURIComponent(teamId)}`,
51
- });
52
- }
53
- catch (e) {
54
- if (!(e instanceof error_1.NotOk) || e.response.statusCode !== 404) {
55
- throw e;
56
- }
57
- await (0, api_1.fetchApi)({
58
- token: opts.token,
59
- endpoint: `/v11/projects?slug=${encodeURIComponent(teamId)}`,
60
- method: "POST",
61
- body: JSON.stringify({
62
- name: DEFAULT_PROJECT_NAME,
63
- }),
64
- });
65
- created = true;
66
- }
67
- return { projectId: DEFAULT_PROJECT_NAME, teamId, created };
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
- * Selects a team for the current token by querying the Teams API and
71
- * returning the slug of the first team in the result set.
72
- *
73
- * @param token - Authentication token used to call the Vercel API.
74
- * @returns A promise that resolves to the first team's slug.
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
- const { teams: [team], } = await (0, api_1.fetchApi)({ token, endpoint: "/v2/teams?limit=1" }).then(TeamsSchema.parse);
78
- return team.slug;
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
@@ -1 +1 @@
1
- {"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/auth/project.ts"],"names":[],"mappings":";;AAwCA,gCAmCC;AASD,gCAOC;AA3FD,6BAAwB;AACxB,+BAAiC;AACjC,mCAAgC;AAChC,qDAAqD;AAErD,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3B,KAAK,EAAE,OAAC;SACL,KAAK,CACJ,OAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;KACjB,CAAC,CACH;SACA,GAAG,CAAC,CAAC,EAAE,6CAA6C,CAAC;CACzD,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,gCAAgC,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACI,KAAK,UAAU,UAAU,CAAC,IAIhC;IACC,MAAM,aAAa,GAAG,MAAM,IAAA,kCAAiB,EAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACzE,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,EAAE,GAAG,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9C,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAE7D,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,IAAA,cAAQ,EAAC;YACb,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,gBAAgB,kBAAkB,CAAC,oBAAoB,CAAC,SAAS,kBAAkB,CAAC,MAAM,CAAC,EAAE;SACxG,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,CAAC,CAAC,YAAY,aAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YAC3D,MAAM,CAAC,CAAC;QACV,CAAC;QAED,MAAM,IAAA,cAAQ,EAAC;YACb,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,sBAAsB,kBAAkB,CAAC,MAAM,CAAC,EAAE;YAC5D,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,IAAI,EAAE,oBAAoB;aAC3B,CAAC;SACH,CAAC,CAAC;QACH,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC9D,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,UAAU,CAAC,KAAa;IAC5C,MAAM,EACJ,KAAK,EAAE,CAAC,IAAI,CAAC,GACd,GAAG,MAAM,IAAA,cAAQ,EAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,CAAC,CAAC,IAAI,CAC/D,WAAW,CAAC,KAAK,CAClB,CAAC;IACF,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC"}
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.json = void 0;
4
- const zod_1 = require("zod");
1
+ import { z } from "zod";
2
+
3
+ //#region src/auth/zod.ts
5
4
  /**
6
- * A Zod codec that serializes and deserializes JSON strings.
7
- */
8
- exports.json = zod_1.z.string().transform((jsonString, ctx) => {
9
- try {
10
- return JSON.parse(jsonString);
11
- }
12
- catch (err) {
13
- ctx.addIssue({
14
- code: zod_1.z.ZodIssueCode.custom,
15
- message: `Invalid JSON: ${err.message}`,
16
- });
17
- return zod_1.z.NEVER;
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
@@ -1 +1 @@
1
- {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/auth/zod.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAExB;;GAEG;AACU,QAAA,IAAI,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,UAAkB,EAAE,GAAG,EAAW,EAAE;IAC5E,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,GAAG,CAAC,QAAQ,CAAC;YACX,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,iBAAiB,GAAG,CAAC,OAAO,EAAE;SACxC,CAAC,CAAC;QACH,OAAO,OAAC,CAAC,KAAK,CAAC;IACjB,CAAC;AACH,CAAC,CAAC,CAAC"}
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"}