@vercel/sandbox 1.9.0 → 1.9.2

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 +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/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
package/dist/snapshot.js CHANGED
@@ -1,116 +1,116 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Snapshot = void 0;
4
- const api_client_1 = require("./api-client");
5
- const get_credentials_1 = require("./utils/get-credentials");
1
+ import { APIClient } from "./api-client/api-client.js";
2
+ import "./api-client/index.js";
3
+ import { getCredentials } from "./utils/get-credentials.js";
4
+
5
+ //#region src/snapshot.ts
6
6
  /**
7
- * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
8
- *
9
- * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
10
- * @hideconstructor
11
- */
12
- class Snapshot {
13
- /**
14
- * Unique ID of this snapshot.
15
- */
16
- get snapshotId() {
17
- return this.snapshot.id;
18
- }
19
- /**
20
- * The ID the sandbox from which this snapshot was created.
21
- */
22
- get sourceSandboxId() {
23
- return this.snapshot.sourceSandboxId;
24
- }
25
- /**
26
- * The status of the snapshot.
27
- */
28
- get status() {
29
- return this.snapshot.status;
30
- }
31
- /**
32
- * The size of the snapshot in bytes, or null if not available.
33
- */
34
- get sizeBytes() {
35
- return this.snapshot.sizeBytes;
36
- }
37
- /**
38
- * The creation date of this snapshot.
39
- */
40
- get createdAt() {
41
- return new Date(this.snapshot.createdAt);
42
- }
43
- /**
44
- * The expiration date of this snapshot, or undefined if it does not expire.
45
- */
46
- get expiresAt() {
47
- if (this.snapshot.expiresAt === undefined) {
48
- return undefined;
49
- }
50
- return new Date(this.snapshot.expiresAt);
51
- }
52
- /**
53
- * Create a new Snapshot instance.
54
- *
55
- * @param client - API client used to communicate with the backend
56
- * @param snapshot - Snapshot metadata
57
- */
58
- constructor({ client, snapshot, }) {
59
- this.client = client;
60
- this.snapshot = snapshot;
61
- }
62
- /**
63
- * Allow to get a list of snapshots for a team narrowed to the given params.
64
- * It returns both the snapshots and the pagination metadata to allow getting
65
- * the next page of results.
66
- */
67
- static async list(params) {
68
- const credentials = await (0, get_credentials_1.getCredentials)(params);
69
- const client = new api_client_1.APIClient({
70
- teamId: credentials.teamId,
71
- token: credentials.token,
72
- fetch: params?.fetch,
73
- });
74
- return client.listSnapshots({
75
- ...credentials,
76
- ...params,
77
- });
78
- }
79
- /**
80
- * Retrieve an existing snapshot.
81
- *
82
- * @param params - Get parameters and optional credentials.
83
- * @returns A promise resolving to the {@link Sandbox}.
84
- */
85
- static async get(params) {
86
- const credentials = await (0, get_credentials_1.getCredentials)(params);
87
- const client = new api_client_1.APIClient({
88
- teamId: credentials.teamId,
89
- token: credentials.token,
90
- });
91
- const sandbox = await client.getSnapshot({
92
- snapshotId: params.snapshotId,
93
- signal: params.signal,
94
- });
95
- return new Snapshot({
96
- client,
97
- snapshot: sandbox.json.snapshot,
98
- });
99
- }
100
- /**
101
- * Delete this snapshot.
102
- *
103
- * @param opts - Optional parameters.
104
- * @param opts.signal - An AbortSignal to cancel the operation.
105
- * @returns A promise that resolves once the snapshot has been deleted.
106
- */
107
- async delete(opts) {
108
- const response = await this.client.deleteSnapshot({
109
- snapshotId: this.snapshot.id,
110
- signal: opts?.signal,
111
- });
112
- this.snapshot = response.json.snapshot;
113
- }
114
- }
115
- exports.Snapshot = Snapshot;
7
+ * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes
8
+ *
9
+ * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.
10
+ * @hideconstructor
11
+ */
12
+ var Snapshot = class Snapshot {
13
+ /**
14
+ * Unique ID of this snapshot.
15
+ */
16
+ get snapshotId() {
17
+ return this.snapshot.id;
18
+ }
19
+ /**
20
+ * The ID the sandbox from which this snapshot was created.
21
+ */
22
+ get sourceSandboxId() {
23
+ return this.snapshot.sourceSandboxId;
24
+ }
25
+ /**
26
+ * The status of the snapshot.
27
+ */
28
+ get status() {
29
+ return this.snapshot.status;
30
+ }
31
+ /**
32
+ * The size of the snapshot in bytes, or null if not available.
33
+ */
34
+ get sizeBytes() {
35
+ return this.snapshot.sizeBytes;
36
+ }
37
+ /**
38
+ * The creation date of this snapshot.
39
+ */
40
+ get createdAt() {
41
+ return new Date(this.snapshot.createdAt);
42
+ }
43
+ /**
44
+ * The expiration date of this snapshot, or undefined if it does not expire.
45
+ */
46
+ get expiresAt() {
47
+ if (this.snapshot.expiresAt === void 0) return;
48
+ return new Date(this.snapshot.expiresAt);
49
+ }
50
+ /**
51
+ * Create a new Snapshot instance.
52
+ *
53
+ * @param client - API client used to communicate with the backend
54
+ * @param snapshot - Snapshot metadata
55
+ */
56
+ constructor({ client, snapshot }) {
57
+ this.client = client;
58
+ this.snapshot = snapshot;
59
+ }
60
+ /**
61
+ * Allow to get a list of snapshots for a team narrowed to the given params.
62
+ * It returns both the snapshots and the pagination metadata to allow getting
63
+ * the next page of results.
64
+ */
65
+ static async list(params) {
66
+ "use step";
67
+ const credentials = await getCredentials(params);
68
+ return new APIClient({
69
+ teamId: credentials.teamId,
70
+ token: credentials.token,
71
+ fetch: params?.fetch
72
+ }).listSnapshots({
73
+ ...credentials,
74
+ ...params
75
+ });
76
+ }
77
+ /**
78
+ * Retrieve an existing snapshot.
79
+ *
80
+ * @param params - Get parameters and optional credentials.
81
+ * @returns A promise resolving to the {@link Sandbox}.
82
+ */
83
+ static async get(params) {
84
+ "use step";
85
+ const credentials = await getCredentials(params);
86
+ const client = new APIClient({
87
+ teamId: credentials.teamId,
88
+ token: credentials.token
89
+ });
90
+ return new Snapshot({
91
+ client,
92
+ snapshot: (await client.getSnapshot({
93
+ snapshotId: params.snapshotId,
94
+ signal: params.signal
95
+ })).json.snapshot
96
+ });
97
+ }
98
+ /**
99
+ * Delete this snapshot.
100
+ *
101
+ * @param opts - Optional parameters.
102
+ * @param opts.signal - An AbortSignal to cancel the operation.
103
+ * @returns A promise that resolves once the snapshot has been deleted.
104
+ */
105
+ async delete(opts) {
106
+ "use step";
107
+ this.snapshot = (await this.client.deleteSnapshot({
108
+ snapshotId: this.snapshot.id,
109
+ signal: opts?.signal
110
+ })).json.snapshot;
111
+ }
112
+ };
113
+
114
+ //#endregion
115
+ export { Snapshot };
116
116
  //# sourceMappingURL=snapshot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAEzC,6DAAsE;AActE;;;;;GAKG;AACH,MAAa,QAAQ;IAGnB;;OAEG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,eAAe;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,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C,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC,CAAC;QAEH,OAAO,IAAI,QAAQ,CAAC;YAClB,MAAM;YACN,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ;SAChC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,IAA+B;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;YAChD,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC5B,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;IACzC,CAAC;CACF;AAtID,4BAsIC"}
1
+ {"version":3,"file":"snapshot.js","names":[],"sources":["../src/snapshot.ts"],"sourcesContent":["import type { WithFetchOptions } from \"./api-client/api-client.js\";\nimport type { SnapshotMetadata } from \"./api-client/index.js\";\nimport { APIClient } from \"./api-client/index.js\";\nimport { type Credentials, getCredentials } from \"./utils/get-credentials.js\";\n\n/** @inline */\ninterface GetSnapshotParams {\n /**\n * Unique identifier of the snapshot.\n */\n snapshotId: string;\n /**\n * An AbortSignal to cancel the operation.\n */\n signal?: AbortSignal;\n}\n\n/**\n * A Snapshot is a saved state of a Sandbox that can be used to create new Sandboxes\n *\n * Use {@link Sandbox.snapshot} or {@link Snapshot.get} to construct.\n * @hideconstructor\n */\nexport class Snapshot {\n private readonly client: APIClient;\n\n /**\n * Unique ID of this snapshot.\n */\n public get snapshotId(): string {\n return this.snapshot.id;\n }\n\n /**\n * The ID the sandbox from which this snapshot was created.\n */\n public get sourceSandboxId(): string {\n return this.snapshot.sourceSandboxId;\n }\n\n /**\n * The status of the snapshot.\n */\n public get status(): SnapshotMetadata[\"status\"] {\n return this.snapshot.status;\n }\n\n /**\n * The size of the snapshot in bytes, or null if not available.\n */\n public get sizeBytes(): number {\n return this.snapshot.sizeBytes;\n }\n\n /**\n * The creation date of this snapshot.\n */\n public get createdAt(): Date {\n return new Date(this.snapshot.createdAt);\n }\n\n /**\n * The expiration date of this snapshot, or undefined if it does not expire.\n */\n public get expiresAt(): Date | undefined {\n if (this.snapshot.expiresAt === undefined) {\n return undefined;\n }\n\n return new Date(this.snapshot.expiresAt);\n }\n\n /**\n * Internal metadata about this snapshot.\n */\n private snapshot: SnapshotMetadata;\n\n /**\n * Create a new Snapshot instance.\n *\n * @param client - API client used to communicate with the backend\n * @param snapshot - Snapshot metadata\n */\n constructor({\n client,\n snapshot,\n }: {\n client: APIClient;\n snapshot: SnapshotMetadata;\n }) {\n this.client = client;\n this.snapshot = snapshot;\n }\n\n /**\n * Allow to get a list of snapshots for a team narrowed to the given params.\n * It returns both the snapshots and the pagination metadata to allow getting\n * the next page of results.\n */\n static async list(\n params?: Partial<Parameters<APIClient[\"listSnapshots\"]>[0]> &\n Partial<Credentials> &\n WithFetchOptions,\n ) {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n return client.listSnapshots({\n ...credentials,\n ...params,\n });\n }\n\n /**\n * Retrieve an existing snapshot.\n *\n * @param params - Get parameters and optional credentials.\n * @returns A promise resolving to the {@link Sandbox}.\n */\n static async get(\n params: GetSnapshotParams | (GetSnapshotParams & Credentials),\n ): Promise<Snapshot> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n\n const sandbox = await client.getSnapshot({\n snapshotId: params.snapshotId,\n signal: params.signal,\n });\n\n return new Snapshot({\n client,\n snapshot: sandbox.json.snapshot,\n });\n }\n\n /**\n * Delete this snapshot.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves once the snapshot has been deleted.\n */\n async delete(opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const response = await this.client!.deleteSnapshot({\n snapshotId: this.snapshot.id,\n signal: opts?.signal,\n });\n\n this.snapshot = response.json.snapshot;\n }\n}\n"],"mappings":";;;;;;;;;;;AAuBA,IAAa,WAAb,MAAa,SAAS;;;;CAMpB,IAAW,aAAqB;AAC9B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,kBAA0B;AACnC,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,SAAqC;AAC9C,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,YAAoB;AAC7B,SAAO,KAAK,SAAS;;;;;CAMvB,IAAW,YAAkB;AAC3B,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;;;;CAM1C,IAAW,YAA8B;AACvC,MAAI,KAAK,SAAS,cAAc,OAC9B;AAGF,SAAO,IAAI,KAAK,KAAK,SAAS,UAAU;;;;;;;;CAc1C,YAAY,EACV,QACA,YAIC;AACD,OAAK,SAAS;AACd,OAAK,WAAW;;;;;;;CAQlB,aAAa,KACX,QAGA;AACA;EACA,MAAM,cAAc,MAAM,eAAe,OAAO;AAMhD,SALe,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACnB,OAAO,QAAQ;GAChB,CAAC,CACY,cAAc;GAC1B,GAAG;GACH,GAAG;GACJ,CAAC;;;;;;;;CASJ,aAAa,IACX,QACmB;AACnB;EACA,MAAM,cAAc,MAAM,eAAe,OAAO;EAChD,MAAM,SAAS,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AAOF,SAAO,IAAI,SAAS;GAClB;GACA,WAPc,MAAM,OAAO,YAAY;IACvC,YAAY,OAAO;IACnB,QAAQ,OAAO;IAChB,CAAC,EAIkB,KAAK;GACxB,CAAC;;;;;;;;;CAUJ,MAAM,OAAO,MAAgD;AAC3D;AAMA,OAAK,YALY,MAAM,KAAK,OAAQ,eAAe;GACjD,YAAY,KAAK,SAAS;GAC1B,QAAQ,MAAM;GACf,CAAC,EAEuB,KAAK"}
@@ -0,0 +1,17 @@
1
+
2
+ //#region src/utils/array.ts
3
+ /**
4
+ * Returns an array from the given item. If the item is an array it will be
5
+ * returned as a it is, otherwise it will be returned as a single item array.
6
+ * If the item is undefined or null an empty array will be returned.
7
+ *
8
+ * @param item The item to convert to an array.
9
+ * @returns An array.
10
+ */
11
+ function array(item) {
12
+ return item !== void 0 && item !== null ? Array.isArray(item) ? item : [item] : [];
13
+ }
14
+
15
+ //#endregion
16
+ exports.array = array;
17
+ //# sourceMappingURL=array.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.cjs","names":[],"sources":["../../src/utils/array.ts"],"sourcesContent":["/**\n * Returns an array from the given item. If the item is an array it will be\n * returned as a it is, otherwise it will be returned as a single item array.\n * If the item is undefined or null an empty array will be returned.\n *\n * @param item The item to convert to an array.\n * @returns An array.\n */\nexport function array<T>(item?: null | T | T[]): T[] {\n return item !== undefined && item !== null\n ? Array.isArray(item)\n ? item\n : [item]\n : [];\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,MAAS,MAA4B;AACnD,QAAO,SAAS,UAAa,SAAS,OAClC,MAAM,QAAQ,KAAK,GACjB,OACA,CAAC,KAAK,GACR,EAAE"}
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.array = array;
1
+ //#region src/utils/array.ts
4
2
  /**
5
- * Returns an array from the given item. If the item is an array it will be
6
- * returned as a it is, otherwise it will be returned as a single item array.
7
- * If the item is undefined or null an empty array will be returned.
8
- *
9
- * @param item The item to convert to an array.
10
- * @returns An array.
11
- */
3
+ * Returns an array from the given item. If the item is an array it will be
4
+ * returned as a it is, otherwise it will be returned as a single item array.
5
+ * If the item is undefined or null an empty array will be returned.
6
+ *
7
+ * @param item The item to convert to an array.
8
+ * @returns An array.
9
+ */
12
10
  function array(item) {
13
- return item !== undefined && item !== null
14
- ? Array.isArray(item)
15
- ? item
16
- : [item]
17
- : [];
11
+ return item !== void 0 && item !== null ? Array.isArray(item) ? item : [item] : [];
18
12
  }
13
+
14
+ //#endregion
15
+ export { array };
19
16
  //# sourceMappingURL=array.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/utils/array.ts"],"names":[],"mappings":";;AAQA,sBAMC;AAdD;;;;;;;GAOG;AACH,SAAgB,KAAK,CAAI,IAAqB;IAC5C,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QACxC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YACnB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,CAAC,IAAI,CAAC;QACV,CAAC,CAAC,EAAE,CAAC;AACT,CAAC"}
1
+ {"version":3,"file":"array.js","names":[],"sources":["../../src/utils/array.ts"],"sourcesContent":["/**\n * Returns an array from the given item. If the item is an array it will be\n * returned as a it is, otherwise it will be returned as a single item array.\n * If the item is undefined or null an empty array will be returned.\n *\n * @param item The item to convert to an array.\n * @returns An array.\n */\nexport function array<T>(item?: null | T | T[]): T[] {\n return item !== undefined && item !== null\n ? Array.isArray(item)\n ? item\n : [item]\n : [];\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,MAAS,MAA4B;AACnD,QAAO,SAAS,UAAa,SAAS,OAClC,MAAM,QAAQ,KAAK,GACjB,OACA,CAAC,KAAK,GACR,EAAE"}
@@ -0,0 +1,18 @@
1
+
2
+ //#region src/utils/consume-readable.ts
3
+ /**
4
+ * Consumes a readable entirely concatenating all content in a single Buffer
5
+ * @param readable A Readable stream
6
+ */
7
+ function consumeReadable(readable) {
8
+ return new Promise((resolve, reject) => {
9
+ const chunks = [];
10
+ readable.on("error", (err) => reject(err));
11
+ readable.on("data", (chunk) => chunks.push(chunk));
12
+ readable.on("end", () => resolve(Buffer.concat(chunks)));
13
+ });
14
+ }
15
+
16
+ //#endregion
17
+ exports.consumeReadable = consumeReadable;
18
+ //# sourceMappingURL=consume-readable.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consume-readable.cjs","names":["chunks: Buffer[]"],"sources":["../../src/utils/consume-readable.ts"],"sourcesContent":["/**\n * Consumes a readable entirely concatenating all content in a single Buffer\n * @param readable A Readable stream\n */\nexport function consumeReadable(readable: NodeJS.ReadableStream) {\n return new Promise<Buffer>((resolve, reject) => {\n const chunks: Buffer[] = [];\n readable.on(\"error\", (err) => reject(err));\n readable.on(\"data\", (chunk) => chunks.push(chunk));\n readable.on(\"end\", () => resolve(Buffer.concat(chunks)));\n });\n}\n"],"mappings":";;;;;;AAIA,SAAgB,gBAAgB,UAAiC;AAC/D,QAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAMA,SAAmB,EAAE;AAC3B,WAAS,GAAG,UAAU,QAAQ,OAAO,IAAI,CAAC;AAC1C,WAAS,GAAG,SAAS,UAAU,OAAO,KAAK,MAAM,CAAC;AAClD,WAAS,GAAG,aAAa,QAAQ,OAAO,OAAO,OAAO,CAAC,CAAC;GACxD"}
@@ -1,16 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.consumeReadable = consumeReadable;
1
+ //#region src/utils/consume-readable.ts
4
2
  /**
5
- * Consumes a readable entirely concatenating all content in a single Buffer
6
- * @param readable A Readable stream
7
- */
3
+ * Consumes a readable entirely concatenating all content in a single Buffer
4
+ * @param readable A Readable stream
5
+ */
8
6
  function consumeReadable(readable) {
9
- return new Promise((resolve, reject) => {
10
- const chunks = [];
11
- readable.on("error", (err) => reject(err));
12
- readable.on("data", (chunk) => chunks.push(chunk));
13
- readable.on("end", () => resolve(Buffer.concat(chunks)));
14
- });
7
+ return new Promise((resolve, reject) => {
8
+ const chunks = [];
9
+ readable.on("error", (err) => reject(err));
10
+ readable.on("data", (chunk) => chunks.push(chunk));
11
+ readable.on("end", () => resolve(Buffer.concat(chunks)));
12
+ });
15
13
  }
14
+
15
+ //#endregion
16
+ export { consumeReadable };
16
17
  //# sourceMappingURL=consume-readable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"consume-readable.js","sourceRoot":"","sources":["../../src/utils/consume-readable.ts"],"names":[],"mappings":";;AAIA,0CAOC;AAXD;;;GAGG;AACH,SAAgB,eAAe,CAAC,QAA+B;IAC7D,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3C,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACnD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"consume-readable.js","names":["chunks: Buffer[]"],"sources":["../../src/utils/consume-readable.ts"],"sourcesContent":["/**\n * Consumes a readable entirely concatenating all content in a single Buffer\n * @param readable A Readable stream\n */\nexport function consumeReadable(readable: NodeJS.ReadableStream) {\n return new Promise<Buffer>((resolve, reject) => {\n const chunks: Buffer[] = [];\n readable.on(\"error\", (err) => reject(err));\n readable.on(\"data\", (chunk) => chunks.push(chunk));\n readable.on(\"end\", () => resolve(Buffer.concat(chunks)));\n });\n}\n"],"mappings":";;;;;AAIA,SAAgB,gBAAgB,UAAiC;AAC/D,QAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAMA,SAAmB,EAAE;AAC3B,WAAS,GAAG,UAAU,QAAQ,OAAO,IAAI,CAAC;AAC1C,WAAS,GAAG,SAAS,UAAU,OAAO,KAAK,MAAM,CAAC;AAClD,WAAS,GAAG,aAAa,QAAQ,OAAO,OAAO,OAAO,CAAC,CAAC;GACxD"}
@@ -0,0 +1,15 @@
1
+
2
+ //#region src/utils/decode-base64-url.ts
3
+ /**
4
+ * Decode a Base64 URL-encoded string into a JSON object.
5
+ *
6
+ * @param base64Url - The Base64 URL-encoded string to decode.
7
+ * @returns The decoded JSON object or null if decoding fails.
8
+ */
9
+ function decodeBase64Url(base64Url) {
10
+ return JSON.parse(Buffer.from(base64Url.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
11
+ }
12
+
13
+ //#endregion
14
+ exports.decodeBase64Url = decodeBase64Url;
15
+ //# sourceMappingURL=decode-base64-url.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-base64-url.cjs","names":[],"sources":["../../src/utils/decode-base64-url.ts"],"sourcesContent":["/**\n * Decode a Base64 URL-encoded string into a JSON object.\n *\n * @param base64Url - The Base64 URL-encoded string to decode.\n * @returns The decoded JSON object or null if decoding fails.\n */\nexport function decodeBase64Url(base64Url: string) {\n return JSON.parse(\n Buffer.from(\n base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\"),\n \"base64\",\n ).toString(\"utf8\"),\n );\n}\n"],"mappings":";;;;;;;;AAMA,SAAgB,gBAAgB,WAAmB;AACjD,QAAO,KAAK,MACV,OAAO,KACL,UAAU,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,IAAI,EAC/C,SACD,CAAC,SAAS,OAAO,CACnB"}
@@ -1,13 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decodeBase64Url = decodeBase64Url;
1
+ //#region src/utils/decode-base64-url.ts
4
2
  /**
5
- * Decode a Base64 URL-encoded string into a JSON object.
6
- *
7
- * @param base64Url - The Base64 URL-encoded string to decode.
8
- * @returns The decoded JSON object or null if decoding fails.
9
- */
3
+ * Decode a Base64 URL-encoded string into a JSON object.
4
+ *
5
+ * @param base64Url - The Base64 URL-encoded string to decode.
6
+ * @returns The decoded JSON object or null if decoding fails.
7
+ */
10
8
  function decodeBase64Url(base64Url) {
11
- return JSON.parse(Buffer.from(base64Url.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
9
+ return JSON.parse(Buffer.from(base64Url.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
12
10
  }
11
+
12
+ //#endregion
13
+ export { decodeBase64Url };
13
14
  //# sourceMappingURL=decode-base64-url.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decode-base64-url.js","sourceRoot":"","sources":["../../src/utils/decode-base64-url.ts"],"names":[],"mappings":";;AAMA,0CAOC;AAbD;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,SAAiB;IAC/C,OAAO,IAAI,CAAC,KAAK,CACf,MAAM,CAAC,IAAI,CACT,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAC/C,QAAQ,CACT,CAAC,QAAQ,CAAC,MAAM,CAAC,CACnB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"decode-base64-url.js","names":[],"sources":["../../src/utils/decode-base64-url.ts"],"sourcesContent":["/**\n * Decode a Base64 URL-encoded string into a JSON object.\n *\n * @param base64Url - The Base64 URL-encoded string to decode.\n * @returns The decoded JSON object or null if decoding fails.\n */\nexport function decodeBase64Url(base64Url: string) {\n return JSON.parse(\n Buffer.from(\n base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\"),\n \"base64\",\n ).toString(\"utf8\"),\n );\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,gBAAgB,WAAmB;AACjD,QAAO,KAAK,MACV,OAAO,KACL,UAAU,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,IAAI,EAC/C,SACD,CAAC,SAAS,OAAO,CACnB"}
@@ -0,0 +1,142 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_log = require('./log.cjs');
3
+ let picocolors = require("picocolors");
4
+ picocolors = require_rolldown_runtime.__toESM(picocolors);
5
+ let ms = require("ms");
6
+ ms = require_rolldown_runtime.__toESM(ms);
7
+
8
+ //#region src/utils/dev-credentials.ts
9
+ async function importAuth() {
10
+ return await Promise.resolve().then(() => require("../auth/index.cjs"));
11
+ }
12
+ function shouldPromptForCredentials() {
13
+ return process.env.NODE_ENV !== "production" && !["1", "true"].includes(process.env.CI || "") && process.stdout.isTTY && process.stdin.isTTY;
14
+ }
15
+ /**
16
+ * Returns cached credentials for the given team/project combination.
17
+ *
18
+ * @remarks
19
+ * The cache is keyed by `teamId` and `projectId`. A new credential generation
20
+ * is triggered only when these values change or when a previous attempt failed.
21
+ *
22
+ * **Important:** Successfully resolved credentials are cached indefinitely and
23
+ * will not be refreshed even if the token expires. Cache invalidation only occurs
24
+ * on rejection (error). This is intentional for development use cases where
25
+ * short-lived sessions don't require proactive token refresh.
26
+ */
27
+ const cachedGenerateCredentials = (() => {
28
+ let cache = null;
29
+ return async (opts) => {
30
+ if (!cache || cache[0].teamId !== opts.teamId || cache[0].projectId !== opts.projectId) cache = [opts, generateCredentials(opts).catch((err) => {
31
+ cache = null;
32
+ throw err;
33
+ })];
34
+ const v = await cache[1];
35
+ require_log.write("warn", `using inferred credentials team=${v.teamId} project=${v.projectId}`);
36
+ return v;
37
+ };
38
+ })();
39
+ /**
40
+ * Generates credentials by authenticating and inferring scope.
41
+ *
42
+ * @internal This is exported for testing purposes. Consider using
43
+ * {@link cachedGenerateCredentials} instead, which caches the result
44
+ * to avoid redundant authentication flows.
45
+ */
46
+ async function generateCredentials(opts) {
47
+ const { OAuth, pollForToken, getAuth, updateAuthConfig, inferScope } = await importAuth();
48
+ let auth = getAuth();
49
+ if (!auth?.token) {
50
+ const timeout = process.env.VERCEL_URL ? "1 minute" : "5 minutes";
51
+ auth = await signInAndGetToken({
52
+ OAuth,
53
+ pollForToken,
54
+ getAuth
55
+ }, timeout);
56
+ }
57
+ if (auth?.refreshToken && auth.expiresAt && auth.expiresAt.getTime() <= Date.now()) {
58
+ const newToken = await (await OAuth()).refreshToken(auth.refreshToken);
59
+ auth = {
60
+ expiresAt: new Date(Date.now() + newToken.expires_in * 1e3),
61
+ token: newToken.access_token,
62
+ refreshToken: newToken.refresh_token || auth.refreshToken
63
+ };
64
+ updateAuthConfig(auth);
65
+ }
66
+ if (!auth?.token) throw new Error([
67
+ `Failed to retrieve authentication token.`,
68
+ `${picocolors.default.bold("hint:")} Set VERCEL_OIDC_TOKEN or provide a Vercel API token.`,
69
+ "├▶ Sandbox docs: https://vercel.com/docs/vercel-sandbox",
70
+ "╰▶ Access tokens: https://vercel.com/kb/guide/how-do-i-use-a-vercel-api-access-token"
71
+ ].join("\n"));
72
+ if (opts.teamId && opts.projectId) return {
73
+ token: auth.token,
74
+ teamId: opts.teamId,
75
+ projectId: opts.projectId
76
+ };
77
+ const scope = await inferScope({
78
+ teamId: opts.teamId,
79
+ token: auth.token
80
+ });
81
+ if (scope.created) require_log.write("info", `Created default project "${scope.projectId}" in team "${scope.teamId}".`);
82
+ return {
83
+ token: auth.token,
84
+ teamId: opts.teamId || scope.teamId,
85
+ projectId: opts.projectId || scope.projectId
86
+ };
87
+ }
88
+ async function signInAndGetToken(auth, timeout) {
89
+ require_log.write("warn", [
90
+ `No VERCEL_OIDC_TOKEN environment variable found, initiating device authorization flow...`,
91
+ `│ ${picocolors.default.bold("help:")} this flow only happens on development environment.`,
92
+ `│ In production, make sure to set up a proper token, or set up Vercel OIDC [https://vercel.com/docs/oidc].`
93
+ ]);
94
+ const oauth = await auth.OAuth();
95
+ const request = await oauth.deviceAuthorizationRequest();
96
+ require_log.write("info", [
97
+ `╰▶ To authenticate, visit: ${request.verification_uri_complete}`,
98
+ ` or visit ${picocolors.default.italic(request.verification_uri)} and type ${picocolors.default.bold(request.user_code)}`,
99
+ ` Press ${picocolors.default.bold("<return>")} to open in your browser`
100
+ ]);
101
+ let error;
102
+ const generator = auth.pollForToken({
103
+ request,
104
+ oauth
105
+ });
106
+ let done = false;
107
+ let spawnedTimeout = setTimeout(() => {
108
+ if (done) return;
109
+ const message = [
110
+ `Authentication flow timed out after ${timeout}.`,
111
+ `│ Make sure to provide a token to avoid prompting an interactive flow.`,
112
+ `╰▶ ${picocolors.default.bold("help:")} Link your project with ${require_log.code("npx vercel link")} to refresh OIDC token automatically.`
113
+ ].join("\n");
114
+ error = new Error(message);
115
+ generator.return();
116
+ }, (0, ms.default)(timeout));
117
+ try {
118
+ for await (const event of generator) switch (event._tag) {
119
+ case "SlowDown":
120
+ case "Timeout":
121
+ case "Response": break;
122
+ case "Error":
123
+ error = event.error;
124
+ break;
125
+ default: throw new Error(`Unknown event type: ${JSON.stringify(event)}`);
126
+ }
127
+ } finally {
128
+ done = true;
129
+ clearTimeout(spawnedTimeout);
130
+ }
131
+ if (error) {
132
+ require_log.write("error", `${picocolors.default.bold("error:")} Authentication failed: ${error.message}`);
133
+ throw error;
134
+ }
135
+ require_log.write("success", `${picocolors.default.bold("done!")} Authenticated successfully!`);
136
+ return auth.getAuth();
137
+ }
138
+
139
+ //#endregion
140
+ exports.cachedGenerateCredentials = cachedGenerateCredentials;
141
+ exports.shouldPromptForCredentials = shouldPromptForCredentials;
142
+ //# sourceMappingURL=dev-credentials.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-credentials.cjs","names":["cache:\n | [{ teamId?: string; projectId?: string }, Promise<Credentials>]\n | null","timeout: ms.StringValue","pico","error: Error | undefined"],"sources":["../../src/utils/dev-credentials.ts"],"sourcesContent":["import pico from \"picocolors\";\nimport type { Credentials } from \"./get-credentials.js\";\nimport ms from \"ms\";\nimport * as Log from \"./log.js\";\n\nasync function importAuth() {\n const auth = await import(\"../auth/index.js\");\n return auth;\n}\n\nexport function shouldPromptForCredentials(): boolean {\n return (\n process.env.NODE_ENV !== \"production\" &&\n ![\"1\", \"true\"].includes(process.env.CI || \"\") &&\n process.stdout.isTTY &&\n process.stdin.isTTY\n );\n}\n\n/**\n * Returns cached credentials for the given team/project combination.\n *\n * @remarks\n * The cache is keyed by `teamId` and `projectId`. A new credential generation\n * is triggered only when these values change or when a previous attempt failed.\n *\n * **Important:** Successfully resolved credentials are cached indefinitely and\n * will not be refreshed even if the token expires. Cache invalidation only occurs\n * on rejection (error). This is intentional for development use cases where\n * short-lived sessions don't require proactive token refresh.\n */\nexport const cachedGenerateCredentials = (() => {\n let cache:\n | [{ teamId?: string; projectId?: string }, Promise<Credentials>]\n | null = null;\n return async (opts: { projectId?: string; teamId?: string }) => {\n if (\n !cache ||\n cache[0].teamId !== opts.teamId ||\n cache[0].projectId !== opts.projectId\n ) {\n const promise = generateCredentials(opts).catch((err) => {\n cache = null;\n throw err;\n });\n cache = [opts, promise];\n }\n const v = await cache[1];\n Log.write(\n \"warn\",\n `using inferred credentials team=${v.teamId} project=${v.projectId}`,\n );\n return v;\n };\n})();\n\n/**\n * Generates credentials by authenticating and inferring scope.\n *\n * @internal This is exported for testing purposes. Consider using\n * {@link cachedGenerateCredentials} instead, which caches the result\n * to avoid redundant authentication flows.\n */\nexport async function generateCredentials(opts: {\n teamId?: string;\n projectId?: string;\n}): Promise<Credentials> {\n const { OAuth, pollForToken, getAuth, updateAuthConfig, inferScope } =\n await importAuth();\n let auth = getAuth();\n if (!auth?.token) {\n const timeout: ms.StringValue = process.env.VERCEL_URL\n ? /* when deployed to vercel we don't want to have a long timeout */ \"1 minute\"\n : \"5 minutes\";\n auth = await signInAndGetToken({ OAuth, pollForToken, getAuth }, timeout);\n }\n if (\n auth?.refreshToken &&\n auth.expiresAt &&\n auth.expiresAt.getTime() <= Date.now()\n ) {\n const oauth = await OAuth();\n const newToken = await oauth.refreshToken(auth.refreshToken);\n auth = {\n expiresAt: new Date(Date.now() + newToken.expires_in * 1000),\n token: newToken.access_token,\n refreshToken: newToken.refresh_token || auth.refreshToken,\n };\n updateAuthConfig(auth);\n }\n\n if (!auth?.token) {\n throw new Error(\n [\n `Failed to retrieve authentication token.`,\n `${pico.bold(\"hint:\")} Set VERCEL_OIDC_TOKEN or provide a Vercel API token.`,\n \"├▶ Sandbox docs: https://vercel.com/docs/vercel-sandbox\",\n \"╰▶ Access tokens: https://vercel.com/kb/guide/how-do-i-use-a-vercel-api-access-token\",\n ].join(\"\\n\"),\n );\n }\n\n if (opts.teamId && opts.projectId) {\n return {\n token: auth.token,\n teamId: opts.teamId,\n projectId: opts.projectId,\n };\n }\n\n const scope = await inferScope({ teamId: opts.teamId, token: auth.token });\n\n if (scope.created) {\n Log.write(\n \"info\",\n `Created default project \"${scope.projectId}\" in team \"${scope.teamId}\".`,\n );\n }\n\n return {\n token: auth.token,\n teamId: opts.teamId || scope.teamId,\n projectId: opts.projectId || scope.projectId,\n };\n}\n\nexport async function signInAndGetToken(\n auth: Pick<\n Awaited<ReturnType<typeof importAuth>>,\n \"OAuth\" | \"getAuth\" | \"pollForToken\"\n >,\n timeout: ms.StringValue,\n) {\n Log.write(\"warn\", [\n `No VERCEL_OIDC_TOKEN environment variable found, initiating device authorization flow...`,\n `│ ${pico.bold(\"help:\")} this flow only happens on development environment.`,\n `│ In production, make sure to set up a proper token, or set up Vercel OIDC [https://vercel.com/docs/oidc].`,\n ]);\n const oauth = await auth.OAuth();\n const request = await oauth.deviceAuthorizationRequest();\n Log.write(\"info\", [\n `╰▶ To authenticate, visit: ${request.verification_uri_complete}`,\n ` or visit ${pico.italic(request.verification_uri)} and type ${pico.bold(request.user_code)}`,\n ` Press ${pico.bold(\"<return>\")} to open in your browser`,\n ]);\n\n let error: Error | undefined;\n const generator = auth.pollForToken({ request, oauth });\n let done = false;\n let spawnedTimeout = setTimeout(() => {\n if (done) return;\n const message = [\n `Authentication flow timed out after ${timeout}.`,\n `│ Make sure to provide a token to avoid prompting an interactive flow.`,\n `╰▶ ${pico.bold(\"help:\")} Link your project with ${Log.code(\"npx vercel link\")} to refresh OIDC token automatically.`,\n ].join(\"\\n\");\n error = new Error(message);\n // Note: generator.return() initiates cooperative cancellation. The generator's\n // finally block will abort pending setTimeout calls, but any in-flight HTTP\n // request will complete before the generator terminates. This is acceptable\n // for this dev-only timeout scenario.\n generator.return();\n }, ms(timeout));\n try {\n for await (const event of generator) {\n switch (event._tag) {\n case \"SlowDown\":\n case \"Timeout\":\n case \"Response\":\n break;\n case \"Error\":\n error = event.error;\n break;\n default:\n throw new Error(\n `Unknown event type: ${JSON.stringify(event satisfies never)}`,\n );\n }\n }\n } finally {\n done = true;\n clearTimeout(spawnedTimeout);\n }\n\n if (error) {\n Log.write(\n \"error\",\n `${pico.bold(\"error:\")} Authentication failed: ${error.message}`,\n );\n throw error;\n }\n\n Log.write(\"success\", `${pico.bold(\"done!\")} Authenticated successfully!`);\n const stored = auth.getAuth();\n return stored;\n}\n"],"mappings":";;;;;;;;AAKA,eAAe,aAAa;AAE1B,QADa,2CAAM;;AAIrB,SAAgB,6BAAsC;AACpD,QACE,QAAQ,IAAI,aAAa,gBACzB,CAAC,CAAC,KAAK,OAAO,CAAC,SAAS,QAAQ,IAAI,MAAM,GAAG,IAC7C,QAAQ,OAAO,SACf,QAAQ,MAAM;;;;;;;;;;;;;;AAgBlB,MAAa,mCAAmC;CAC9C,IAAIA,QAEO;AACX,QAAO,OAAO,SAAkD;AAC9D,MACE,CAAC,SACD,MAAM,GAAG,WAAW,KAAK,UACzB,MAAM,GAAG,cAAc,KAAK,UAM5B,SAAQ,CAAC,MAJO,oBAAoB,KAAK,CAAC,OAAO,QAAQ;AACvD,WAAQ;AACR,SAAM;IACN,CACqB;EAEzB,MAAM,IAAI,MAAM,MAAM;AACtB,oBACE,QACA,mCAAmC,EAAE,OAAO,WAAW,EAAE,YAC1D;AACD,SAAO;;IAEP;;;;;;;;AASJ,eAAsB,oBAAoB,MAGjB;CACvB,MAAM,EAAE,OAAO,cAAc,SAAS,kBAAkB,eACtD,MAAM,YAAY;CACpB,IAAI,OAAO,SAAS;AACpB,KAAI,CAAC,MAAM,OAAO;EAChB,MAAMC,UAA0B,QAAQ,IAAI,aAC2B,aACnE;AACJ,SAAO,MAA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