@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,128 +1,124 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseClient = void 0;
4
- exports.parse = parse;
5
- exports.parseOrThrow = parseOrThrow;
6
- const api_error_1 = require("./api-error");
7
- const array_1 = require("../utils/array");
8
- const with_retry_1 = require("./with-retry");
9
- const undici_1 = require("undici");
1
+ import { APIError } from "./api-error.js";
2
+ import { array } from "../utils/array.js";
3
+ import { withRetry } from "./with-retry.js";
4
+ import { Agent } from "undici";
5
+
6
+ //#region src/api-client/base-client.ts
7
+ const DEFAULT_AGENT = new Agent({ bodyTimeout: 0 });
10
8
  /**
11
- * A base API client that provides a convenience wrapper for fetching where
12
- * we can pass query parameters as an object, support retries, debugging
13
- * and automatic authorization.
14
- */
15
- class BaseClient {
16
- constructor(params) {
17
- this.fetch = (0, with_retry_1.withRetry)(params.fetch ?? globalThis.fetch);
18
- this.baseUrl = params.baseUrl;
19
- this.debug = params.debug ?? process.env.DEBUG_FETCH === "true";
20
- this.token = params.token;
21
- this.agent = new undici_1.Agent({
22
- bodyTimeout: 0, // disable body timeout to allow long logs streaming
23
- });
24
- }
25
- async request(path, opts) {
26
- const url = new URL(`${this.baseUrl}${path}`);
27
- if (opts?.query) {
28
- for (const [key, value] of Object.entries(opts.query)) {
29
- (0, array_1.array)(value).forEach((value) => {
30
- url.searchParams.append(key, value.toString());
31
- });
32
- }
33
- }
34
- const start = Date.now();
35
- const response = await this.fetch(url.toString(), {
36
- ...opts,
37
- body: opts?.body,
38
- method: opts?.method || "GET",
39
- headers: this.token
40
- ? { Authorization: `Bearer ${this.token}`, ...opts?.headers }
41
- : opts?.headers,
42
- // @ts-expect-error Node.js' and undici's Agent have different types
43
- dispatcher: this.agent,
44
- signal: opts?.signal,
45
- });
46
- if (this.debug) {
47
- const duration = Date.now() - start;
48
- console.log(`[API] ${url} (${response.status}) ${duration}ms`);
49
- if (response.status === 429) {
50
- const retry = parseInt(response.headers.get("Retry-After") ?? "", 10);
51
- const hours = Math.floor(retry / 60 / 60);
52
- const minutes = Math.floor(retry / 60) % 60;
53
- const seconds = retry % 60;
54
- console.warn(`[API] ${url} Rate Limited, Retry After ${hours}h ${minutes}m ${seconds}s`);
55
- }
56
- }
57
- return response;
58
- }
9
+ * A base API client that provides a convenience wrapper for fetching where
10
+ * we can pass query parameters as an object, support retries, debugging
11
+ * and automatic authorization.
12
+ */
13
+ var BaseClient = class {
14
+ constructor(params) {
15
+ this.fetch = withRetry(params.fetch ?? globalThis.fetch);
16
+ this.baseUrl = params.baseUrl;
17
+ this.debug = params.debug ?? process.env.DEBUG_FETCH === "true";
18
+ this.token = params.token;
19
+ this.agent = DEFAULT_AGENT;
20
+ }
21
+ async request(path, opts) {
22
+ const url = new URL(`${this.baseUrl}${path}`);
23
+ if (opts?.query) for (const [key, value] of Object.entries(opts.query)) array(value).forEach((value$1) => {
24
+ url.searchParams.append(key, value$1.toString());
25
+ });
26
+ const start = Date.now();
27
+ const response = await this.fetch(url.toString(), {
28
+ ...opts,
29
+ body: opts?.body,
30
+ method: opts?.method || "GET",
31
+ headers: this.token ? {
32
+ Authorization: `Bearer ${this.token}`,
33
+ ...opts?.headers
34
+ } : opts?.headers,
35
+ dispatcher: this.agent,
36
+ signal: opts?.signal
37
+ });
38
+ if (this.debug) {
39
+ const duration = Date.now() - start;
40
+ console.log(`[API] ${url} (${response.status}) ${duration}ms`);
41
+ if (response.status === 429) {
42
+ const retry = parseInt(response.headers.get("Retry-After") ?? "", 10);
43
+ const hours = Math.floor(retry / 60 / 60);
44
+ const minutes = Math.floor(retry / 60) % 60;
45
+ const seconds = retry % 60;
46
+ console.warn(`[API] ${url} Rate Limited, Retry After ${hours}h ${minutes}m ${seconds}s`);
47
+ }
48
+ }
49
+ return response;
50
+ }
51
+ };
52
+ /**
53
+ * Extract sessionId from a sandbox API URL.
54
+ */
55
+ function extractSessionId(url) {
56
+ return url.match(/\/v2\/sandboxes\/sessions\/([^/?]+)/)?.[1];
59
57
  }
60
- exports.BaseClient = BaseClient;
61
58
  /**
62
- * Extract sandboxId from a sandbox API URL.
63
- * URLs follow the pattern: /v1/sandboxes/{sandboxId}/...
64
- */
65
- function extractSandboxId(url) {
66
- const match = url.match(/\/v1\/sandboxes\/([^/?]+)/);
67
- return match?.[1];
59
+ * Extract sandbox name from a sandbox API url.
60
+ * Excludes known sub-paths like /sessions/ and /snapshots/.
61
+ */
62
+ function extractSandboxName(url) {
63
+ return url.match(/\/v2\/sandboxes\/(?!sessions(?:\/|$|\?))(?!snapshots(?:\/|$|\?))([^/?]+)/)?.[1];
68
64
  }
69
65
  /**
70
- * Allows to read the response text and parse it as JSON casting to the given
71
- * type. If the response is not ok or cannot be parsed it will return error.
72
- *
73
- * @param response Response to parse.
74
- * @returns Parsed response or error.
75
- */
66
+ * Allows to read the response text and parse it as JSON casting to the given
67
+ * type. If the response is not ok or cannot be parsed it will return error.
68
+ *
69
+ * @param response Response to parse.
70
+ * @returns Parsed response or error.
71
+ */
76
72
  async function parse(validator, response) {
77
- const sandboxId = extractSandboxId(response.url);
78
- const text = await response.text().catch((err) => {
79
- return new api_error_1.APIError(response, {
80
- message: `Can't read response text: ${String(err)}`,
81
- sandboxId,
82
- });
83
- });
84
- if (typeof text !== "string") {
85
- return text;
86
- }
87
- let json;
88
- try {
89
- json = JSON.parse(text || "{}");
90
- }
91
- catch (error) {
92
- return new api_error_1.APIError(response, {
93
- message: `Can't parse JSON: ${String(error)}`,
94
- text,
95
- sandboxId,
96
- });
97
- }
98
- if (!response.ok) {
99
- return new api_error_1.APIError(response, {
100
- message: `Status code ${response.status} is not ok`,
101
- json: json,
102
- text,
103
- sandboxId,
104
- });
105
- }
106
- const validated = validator.safeParse(json);
107
- if (!validated.success) {
108
- return new api_error_1.APIError(response, {
109
- message: `Response JSON is not valid: ${validated.error}`,
110
- json: json,
111
- text,
112
- sandboxId,
113
- });
114
- }
115
- return {
116
- json: validated.data,
117
- response,
118
- text,
119
- };
73
+ const sessionId = extractSessionId(response.url);
74
+ let sandboxName;
75
+ if (!sessionId) sandboxName = extractSandboxName(response.url);
76
+ const text = await response.text().catch((err) => {
77
+ return new APIError(response, {
78
+ message: `Can't read response text: ${String(err)}`,
79
+ sessionId,
80
+ sandboxName
81
+ });
82
+ });
83
+ if (typeof text !== "string") return text;
84
+ let json;
85
+ try {
86
+ json = JSON.parse(text || "{}");
87
+ } catch (error) {
88
+ return new APIError(response, {
89
+ message: `Can't parse JSON: ${String(error)}`,
90
+ text,
91
+ sessionId,
92
+ sandboxName
93
+ });
94
+ }
95
+ if (!response.ok) return new APIError(response, {
96
+ message: `Status code ${response.status} is not ok`,
97
+ json,
98
+ text,
99
+ sessionId,
100
+ sandboxName
101
+ });
102
+ const validated = validator.safeParse(json);
103
+ if (!validated.success) return new APIError(response, {
104
+ message: `Response JSON is not valid: ${validated.error}`,
105
+ json,
106
+ text,
107
+ sessionId,
108
+ sandboxName
109
+ });
110
+ return {
111
+ json: validated.data,
112
+ response,
113
+ text
114
+ };
120
115
  }
121
116
  async function parseOrThrow(validator, response) {
122
- const result = await parse(validator, response);
123
- if (result instanceof api_error_1.APIError) {
124
- throw result;
125
- }
126
- return result;
117
+ const result = await parse(validator, response);
118
+ if (result instanceof APIError) throw result;
119
+ return result;
127
120
  }
121
+
122
+ //#endregion
123
+ export { BaseClient, parseOrThrow };
128
124
  //# sourceMappingURL=base-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-client.js","sourceRoot":"","sources":["../../src/api-client/base-client.ts"],"names":[],"mappings":";;;AAyGA,sBAqDC;AAED,oCAUC;AAzKD,2CAAuC;AAEvC,0CAAuC;AACvC,6CAA8D;AAC9D,mCAA+B;AAU/B;;;;GAIG;AACH,MAAa,UAAU;IAOrB,YAAY,MAKX;QACC,IAAI,CAAC,KAAK,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,K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,MAAM,MAAM,GAAG,MAAM,KAAK,CAAkB,SAAS,EAAE,QAAQ,CAAC,CAAC;IACjE,IAAI,MAAM,YAAY,oBAAQ,EAAE,CAAC;QAC/B,MAAM,MAAM,CAAC;IACf,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"base-client.js","names":["value","sandboxName: string | undefined","json: Data | ErrorData"],"sources":["../../src/api-client/base-client.ts"],"sourcesContent":["import type { Options as RetryOptions } from \"async-retry\";\nimport { APIError } from \"./api-error.js\";\nimport { ZodType } from \"zod\";\nimport { array } from \"../utils/array.js\";\nimport { withRetry, type RequestOptions } from \"./with-retry.js\";\nimport { Agent } from \"undici\";\n\nexport interface RequestParams extends RequestInit {\n headers?: Record<string, string>;\n method?: string;\n onRetry?(error: any, options: RequestOptions): void;\n query?: Record<string, number | string | null | undefined | string[]>;\n retry?: Partial<RetryOptions>;\n}\n\nconst DEFAULT_AGENT = new Agent({\n bodyTimeout: 0, // disable body timeout to allow long logs streaming\n});\n\n/**\n * A base API client that provides a convenience wrapper for fetching where\n * we can pass query parameters as an object, support retries, debugging\n * and automatic authorization.\n */\nexport class BaseClient {\n protected token?: string;\n private fetch: ReturnType<typeof withRetry<RequestInit>>;\n private debug: boolean;\n private baseUrl: string;\n private agent: Agent;\n\n constructor(params: {\n debug?: boolean;\n baseUrl: string;\n token?: string;\n fetch?: typeof globalThis.fetch;\n }) {\n this.fetch = withRetry(params.fetch ?? globalThis.fetch);\n this.baseUrl = params.baseUrl;\n this.debug = params.debug ?? process.env.DEBUG_FETCH === \"true\";\n this.token = params.token;\n this.agent = DEFAULT_AGENT;\n }\n\n protected async request(path: string, opts?: RequestParams) {\n const url = new URL(`${this.baseUrl}${path}`);\n if (opts?.query) {\n for (const [key, value] of Object.entries(opts.query)) {\n array(value).forEach((value) => {\n url.searchParams.append(key, value.toString());\n });\n }\n }\n\n const start = Date.now();\n const response = await this.fetch(url.toString(), {\n ...opts,\n body: opts?.body,\n method: opts?.method || \"GET\",\n headers: this.token\n ? { Authorization: `Bearer ${this.token}`, ...opts?.headers }\n : opts?.headers,\n // @ts-expect-error Node.js' and undici's Agent have different types\n dispatcher: this.agent,\n signal: opts?.signal,\n });\n\n if (this.debug) {\n const duration = Date.now() - start;\n console.log(`[API] ${url} (${response.status}) ${duration}ms`);\n if (response.status === 429) {\n const retry = parseInt(response.headers.get(\"Retry-After\") ?? \"\", 10);\n const hours = Math.floor(retry / 60 / 60);\n const minutes = Math.floor(retry / 60) % 60;\n const seconds = retry % 60;\n console.warn(\n `[API] ${url} Rate Limited, Retry After ${hours}h ${minutes}m ${seconds}s`,\n );\n }\n }\n\n return response;\n }\n}\n\nexport interface Parsed<Data> {\n response: Response;\n text: string;\n json: Data;\n}\n\n/**\n * Extract sessionId from a sandbox API URL.\n */\nfunction extractSessionId(url: string): string | undefined {\n const match = url.match(/\\/v2\\/sandboxes\\/sessions\\/([^/?]+)/);\n return match?.[1];\n}\n\n/**\n * Extract sandbox name from a sandbox API url.\n * Excludes known sub-paths like /sessions/ and /snapshots/.\n */\nfunction extractSandboxName(url: string): string | undefined {\n const match = url.match(/\\/v2\\/sandboxes\\/(?!sessions(?:\\/|$|\\?))(?!snapshots(?:\\/|$|\\?))([^/?]+)/);\n return match?.[1];\n}\n\n/**\n * Allows to read the response text and parse it as JSON casting to the given\n * type. If the response is not ok or cannot be parsed it will return error.\n *\n * @param response Response to parse.\n * @returns Parsed response or error.\n */\nexport async function parse<Data, ErrorData>(\n validator: ZodType<Data>,\n response: Response,\n): Promise<Parsed<Data> | APIError<ErrorData>> {\n const sessionId = extractSessionId(response.url);\n let sandboxName: string | undefined;\n if (!sessionId) {\n sandboxName = extractSandboxName(response.url);\n }\n\n const text = await response.text().catch((err) => {\n return new APIError<ErrorData>(response, {\n message: `Can't read response text: ${String(err)}`,\n sessionId,\n sandboxName\n });\n });\n\n if (typeof text !== \"string\") {\n return text;\n }\n\n let json: Data | ErrorData;\n\n try {\n json = JSON.parse(text || \"{}\");\n } catch (error) {\n return new APIError<ErrorData>(response, {\n message: `Can't parse JSON: ${String(error)}`,\n text,\n sessionId,\n sandboxName\n });\n }\n\n if (!response.ok) {\n return new APIError<ErrorData>(response, {\n message: `Status code ${response.status} is not ok`,\n json: json as ErrorData,\n text,\n sessionId,\n sandboxName\n });\n }\n\n const validated = validator.safeParse(json);\n if (!validated.success) {\n return new APIError<ErrorData>(response, {\n message: `Response JSON is not valid: ${validated.error}`,\n json: json as ErrorData,\n text,\n sessionId,\n sandboxName\n });\n }\n\n return {\n json: validated.data,\n response,\n text,\n };\n}\n\nexport async function parseOrThrow<Data, ErrorData>(\n validator: ZodType<Data>,\n response: Response,\n): Promise<Parsed<Data>> {\n const result = await parse<Data, ErrorData>(validator, response);\n if (result instanceof APIError) {\n throw result;\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAeA,MAAM,gBAAgB,IAAI,MAAM,EAC9B,aAAa,GACd,CAAC;;;;;;AAOF,IAAa,aAAb,MAAwB;CAOtB,YAAY,QAKT;AACD,OAAK,QAAQ,UAAU,OAAO,SAAS,WAAW,MAAM;AACxD,OAAK,UAAU,OAAO;AACtB,OAAK,QAAQ,OAAO,SAAS,QAAQ,IAAI,gBAAgB;AACzD,OAAK,QAAQ,OAAO;AACpB,OAAK,QAAQ;;CAGf,MAAgB,QAAQ,MAAc,MAAsB;EAC1D,MAAM,MAAM,IAAI,IAAI,GAAG,KAAK,UAAU,OAAO;AAC7C,MAAI,MAAM,MACR,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,MAAM,CACnD,OAAM,MAAM,CAAC,SAAS,YAAU;AAC9B,OAAI,aAAa,OAAO,KAAKA,QAAM,UAAU,CAAC;IAC9C;EAIN,MAAM,QAAQ,KAAK,KAAK;EACxB,MAAM,WAAW,MAAM,KAAK,MAAM,IAAI,UAAU,EAAE;GAChD,GAAG;GACH,MAAM,MAAM;GACZ,QAAQ,MAAM,UAAU;GACxB,SAAS,KAAK,QACV;IAAE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,SAAoB,UAAU;EACvC,SAAS,eAAe,SAAS,OAAO;EAClC;EACN;EACA;EACA;EACD,CAAC;CAGJ,MAAM,YAAY,UAAU,UAAU,KAAK;AAC3C,KAAI,CAAC,UAAU,QACb,QAAO,IAAI,SAAoB,UAAU;EACvC,SAAS,+BAA+B,UAAU;EAC5C;EACN;EACA;EACA;EACD,CAAC;AAGJ,QAAO;EACL,MAAM,UAAU;EAChB;EACA;EACD;;AAGH,eAAsB,aACpB,WACA,UACuB;CACvB,MAAM,SAAS,MAAM,MAAuB,WAAW,SAAS;AAChE,KAAI,kBAAkB,SACpB,OAAM;AAGR,QAAO"}
@@ -0,0 +1,62 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let zlib = require("zlib");
3
+ zlib = require_rolldown_runtime.__toESM(zlib);
4
+ let tar_stream = require("tar-stream");
5
+ tar_stream = require_rolldown_runtime.__toESM(tar_stream);
6
+ let stream = require("stream");
7
+
8
+ //#region src/api-client/file-writer.ts
9
+ /**
10
+ * Allows to create a Readable stream with methods to write files
11
+ * to it and to finish it. Files written are compressed together
12
+ * and gzipped in the stream.
13
+ */
14
+ var FileWriter = class {
15
+ constructor() {
16
+ const gzip = zlib.default.createGzip();
17
+ this.pack = tar_stream.default.pack();
18
+ this.readable = this.pack.pipe(gzip);
19
+ }
20
+ /**
21
+ * Allows to add a file to the stream. Size is required to write
22
+ * the tarball header so when content is a stream it must be
23
+ * provided.
24
+ *
25
+ * Returns a Promise resolved once the file is written in the
26
+ * stream.
27
+ */
28
+ async addFile(file) {
29
+ return new Promise((resolve, reject) => {
30
+ const entry = this.pack.entry("size" in file ? {
31
+ name: file.name,
32
+ size: file.size,
33
+ mode: file.mode
34
+ } : {
35
+ name: file.name,
36
+ size: Buffer.byteLength(file.content),
37
+ mode: file.mode
38
+ }, (error) => {
39
+ if (error) return reject(error);
40
+ else resolve();
41
+ });
42
+ if (file.content instanceof stream.Readable) file.content.pipe(entry);
43
+ else entry.end(file.content);
44
+ });
45
+ }
46
+ /**
47
+ * Allows to finish the stream returning a Promise that will
48
+ * resolve once the readable is effectively closed or
49
+ * errored.
50
+ */
51
+ async end() {
52
+ return new Promise((resolve, reject) => {
53
+ this.readable.on("error", reject);
54
+ this.readable.on("end", resolve);
55
+ this.pack.finalize();
56
+ });
57
+ }
58
+ };
59
+
60
+ //#endregion
61
+ exports.FileWriter = FileWriter;
62
+ //# sourceMappingURL=file-writer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-writer.cjs","names":["tar","Readable"],"sources":["../../src/api-client/file-writer.ts"],"sourcesContent":["import zlib from \"zlib\";\nimport tar, { type Pack } from \"tar-stream\";\nimport { Readable } from \"stream\";\n\ninterface FileData {\n /**\n * The name (path) of the file to write.\n */\n name: string;\n /**\n * The content of the file.\n */\n content: string | Uint8Array;\n /**\n * The file mode (permissions) to set on the file.\n * For example, 0o755 for executable files.\n */\n mode?: number;\n}\n\ninterface FileStream {\n /**\n * The name (path) of the file to write.\n */\n name: string;\n /**\n * A Readable stream to consume the content of the file.\n */\n content: Readable;\n /**\n * The expected size of the file. This is required to write\n * the header of the compressed file.\n */\n size: number;\n /**\n * The file mode (permissions) to set on the file.\n * For example, 0o755 for executable files.\n */\n mode?: number;\n}\n\n/**\n * Allows to create a Readable stream with methods to write files\n * to it and to finish it. Files written are compressed together\n * and gzipped in the stream.\n */\nexport class FileWriter {\n public readable: Readable;\n private pack: Pack;\n\n constructor() {\n const gzip = zlib.createGzip();\n this.pack = tar.pack();\n this.readable = this.pack.pipe(gzip);\n }\n\n /**\n * Allows to add a file to the stream. Size is required to write\n * the tarball header so when content is a stream it must be\n * provided.\n *\n * Returns a Promise resolved once the file is written in the\n * stream.\n */\n async addFile(file: FileData | FileStream) {\n return new Promise<void>((resolve, reject) => {\n const entry = this.pack.entry(\n \"size\" in file\n ? { name: file.name, size: file.size, mode: file.mode }\n : {\n name: file.name,\n size: Buffer.byteLength(file.content),\n mode: file.mode,\n },\n (error) => {\n if (error) {\n return reject(error);\n } else {\n resolve();\n }\n },\n );\n\n if (file.content instanceof Readable) {\n file.content.pipe(entry);\n } else {\n entry.end(file.content);\n }\n });\n }\n\n /**\n * Allows to finish the stream returning a Promise that will\n * resolve once the readable is effectively closed or\n * errored.\n */\n async end() {\n return new Promise<void>((resolve, reject) => {\n this.readable.on(\"error\", reject);\n this.readable.on(\"end\", resolve);\n this.pack.finalize();\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA8CA,IAAa,aAAb,MAAwB;CAItB,cAAc;EACZ,MAAM,OAAO,aAAK,YAAY;AAC9B,OAAK,OAAOA,mBAAI,MAAM;AACtB,OAAK,WAAW,KAAK,KAAK,KAAK,KAAK;;;;;;;;;;CAWtC,MAAM,QAAQ,MAA6B;AACzC,SAAO,IAAI,SAAe,SAAS,WAAW;GAC5C,MAAM,QAAQ,KAAK,KAAK,MACtB,UAAU,OACN;IAAE,MAAM,KAAK;IAAM,MAAM,KAAK;IAAM,MAAM,KAAK;IAAM,GACrD;IACE,MAAM,KAAK;IACX,MAAM,OAAO,WAAW,KAAK,QAAQ;IACrC,MAAM,KAAK;IACZ,GACJ,UAAU;AACT,QAAI,MACF,QAAO,OAAO,MAAM;QAEpB,UAAS;KAGd;AAED,OAAI,KAAK,mBAAmBC,gBAC1B,MAAK,QAAQ,KAAK,MAAM;OAExB,OAAM,IAAI,KAAK,QAAQ;IAEzB;;;;;;;CAQJ,MAAM,MAAM;AACV,SAAO,IAAI,SAAe,SAAS,WAAW;AAC5C,QAAK,SAAS,GAAG,SAAS,OAAO;AACjC,QAAK,SAAS,GAAG,OAAO,QAAQ;AAChC,QAAK,KAAK,UAAU;IACpB"}
@@ -0,0 +1,66 @@
1
+ import { Readable } from "stream";
2
+
3
+ //#region src/api-client/file-writer.d.ts
4
+ interface FileData {
5
+ /**
6
+ * The name (path) of the file to write.
7
+ */
8
+ name: string;
9
+ /**
10
+ * The content of the file.
11
+ */
12
+ content: string | Uint8Array;
13
+ /**
14
+ * The file mode (permissions) to set on the file.
15
+ * For example, 0o755 for executable files.
16
+ */
17
+ mode?: number;
18
+ }
19
+ interface FileStream {
20
+ /**
21
+ * The name (path) of the file to write.
22
+ */
23
+ name: string;
24
+ /**
25
+ * A Readable stream to consume the content of the file.
26
+ */
27
+ content: Readable;
28
+ /**
29
+ * The expected size of the file. This is required to write
30
+ * the header of the compressed file.
31
+ */
32
+ size: number;
33
+ /**
34
+ * The file mode (permissions) to set on the file.
35
+ * For example, 0o755 for executable files.
36
+ */
37
+ mode?: number;
38
+ }
39
+ /**
40
+ * Allows to create a Readable stream with methods to write files
41
+ * to it and to finish it. Files written are compressed together
42
+ * and gzipped in the stream.
43
+ */
44
+ declare class FileWriter {
45
+ readable: Readable;
46
+ private pack;
47
+ constructor();
48
+ /**
49
+ * Allows to add a file to the stream. Size is required to write
50
+ * the tarball header so when content is a stream it must be
51
+ * provided.
52
+ *
53
+ * Returns a Promise resolved once the file is written in the
54
+ * stream.
55
+ */
56
+ addFile(file: FileData | FileStream): Promise<void>;
57
+ /**
58
+ * Allows to finish the stream returning a Promise that will
59
+ * resolve once the readable is effectively closed or
60
+ * errored.
61
+ */
62
+ end(): Promise<void>;
63
+ }
64
+ //#endregion
65
+ export { FileWriter };
66
+ //# sourceMappingURL=file-writer.d.cts.map
@@ -1,52 +1,66 @@
1
1
  import { Readable } from "stream";
2
- interface FileBuffer {
3
- /**
4
- * The name (path) of the file to write.
5
- */
6
- name: string;
7
- /**
8
- * The content of the file as a Buffer.
9
- */
10
- content: Buffer;
2
+
3
+ //#region src/api-client/file-writer.d.ts
4
+ interface FileData {
5
+ /**
6
+ * The name (path) of the file to write.
7
+ */
8
+ name: string;
9
+ /**
10
+ * The content of the file.
11
+ */
12
+ content: string | Uint8Array;
13
+ /**
14
+ * The file mode (permissions) to set on the file.
15
+ * For example, 0o755 for executable files.
16
+ */
17
+ mode?: number;
11
18
  }
12
19
  interface FileStream {
13
- /**
14
- * The name (path) of the file to write.
15
- */
16
- name: string;
17
- /**
18
- * A Readable stream to consume the content of the file.
19
- */
20
- content: Readable;
21
- /**
22
- * The expected size of the file. This is required to write
23
- * the header of the compressed file.
24
- */
25
- size: number;
20
+ /**
21
+ * The name (path) of the file to write.
22
+ */
23
+ name: string;
24
+ /**
25
+ * A Readable stream to consume the content of the file.
26
+ */
27
+ content: Readable;
28
+ /**
29
+ * The expected size of the file. This is required to write
30
+ * the header of the compressed file.
31
+ */
32
+ size: number;
33
+ /**
34
+ * The file mode (permissions) to set on the file.
35
+ * For example, 0o755 for executable files.
36
+ */
37
+ mode?: number;
26
38
  }
27
39
  /**
28
40
  * Allows to create a Readable stream with methods to write files
29
41
  * to it and to finish it. Files written are compressed together
30
42
  * and gzipped in the stream.
31
43
  */
32
- export declare class FileWriter {
33
- readable: Readable;
34
- private pack;
35
- constructor();
36
- /**
37
- * Allows to add a file to the stream. Size is required to write
38
- * the tarball header so when content is a stream it must be
39
- * provided.
40
- *
41
- * Returns a Promise resolved once the file is written in the
42
- * stream.
43
- */
44
- addFile(file: FileBuffer | FileStream): Promise<void>;
45
- /**
46
- * Allows to finish the stream returning a Promise that will
47
- * resolve once the readable is effectively closed or
48
- * errored.
49
- */
50
- end(): Promise<void>;
44
+ declare class FileWriter {
45
+ readable: Readable;
46
+ private pack;
47
+ constructor();
48
+ /**
49
+ * Allows to add a file to the stream. Size is required to write
50
+ * the tarball header so when content is a stream it must be
51
+ * provided.
52
+ *
53
+ * Returns a Promise resolved once the file is written in the
54
+ * stream.
55
+ */
56
+ addFile(file: FileData | FileStream): Promise<void>;
57
+ /**
58
+ * Allows to finish the stream returning a Promise that will
59
+ * resolve once the readable is effectively closed or
60
+ * errored.
61
+ */
62
+ end(): Promise<void>;
51
63
  }
52
- export {};
64
+ //#endregion
65
+ export { FileWriter };
66
+ //# sourceMappingURL=file-writer.d.ts.map