@vercel/sandbox 2.0.0-beta.11 → 2.0.0-beta.13

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 (196) 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 +456 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +790 -0
  6. package/dist/api-client/api-client.d.ts +784 -777
  7. package/dist/api-client/api-client.js +445 -471
  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 -18
  13. package/dist/api-client/api-error.js +28 -33
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +125 -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 +110 -130
  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 +182 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +1469 -0
  33. package/dist/api-client/validators.d.ts +1282 -3699
  34. package/dist/api-client/validators.js +155 -170
  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 +13 -0
  95. package/dist/index.d.cts +7 -0
  96. package/dist/index.d.ts +7 -6
  97. package/dist/index.js +7 -17
  98. package/dist/network-policy.d.cts +100 -0
  99. package/dist/network-policy.d.ts +32 -28
  100. package/dist/sandbox.cjs +694 -0
  101. package/dist/sandbox.cjs.map +1 -0
  102. package/dist/sandbox.d.cts +796 -0
  103. package/dist/sandbox.d.ts +783 -711
  104. package/dist/sandbox.js +684 -615
  105. package/dist/sandbox.js.map +1 -1
  106. package/dist/session.cjs +520 -0
  107. package/dist/session.cjs.map +1 -0
  108. package/dist/session.d.cts +406 -0
  109. package/dist/session.d.ts +398 -367
  110. package/dist/session.js +517 -505
  111. package/dist/session.js.map +1 -1
  112. package/dist/snapshot.cjs +116 -0
  113. package/dist/snapshot.cjs.map +1 -0
  114. package/dist/snapshot.d.cts +107 -0
  115. package/dist/snapshot.d.ts +98 -91
  116. package/dist/snapshot.js +114 -115
  117. package/dist/snapshot.js.map +1 -1
  118. package/dist/utils/array.cjs +17 -0
  119. package/dist/utils/array.cjs.map +1 -0
  120. package/dist/utils/array.js +12 -15
  121. package/dist/utils/array.js.map +1 -1
  122. package/dist/utils/consume-readable.cjs +18 -0
  123. package/dist/utils/consume-readable.cjs.map +1 -0
  124. package/dist/utils/consume-readable.js +13 -12
  125. package/dist/utils/consume-readable.js.map +1 -1
  126. package/dist/utils/decode-base64-url.cjs +15 -0
  127. package/dist/utils/decode-base64-url.cjs.map +1 -0
  128. package/dist/utils/decode-base64-url.js +10 -9
  129. package/dist/utils/decode-base64-url.js.map +1 -1
  130. package/dist/utils/dev-credentials.cjs +142 -0
  131. package/dist/utils/dev-credentials.cjs.map +1 -0
  132. package/dist/utils/dev-credentials.js +126 -184
  133. package/dist/utils/dev-credentials.js.map +1 -1
  134. package/dist/utils/get-credentials.cjs +123 -0
  135. package/dist/utils/get-credentials.cjs.map +1 -0
  136. package/dist/utils/get-credentials.d.cts +21 -0
  137. package/dist/utils/get-credentials.d.ts +19 -61
  138. package/dist/utils/get-credentials.js +106 -140
  139. package/dist/utils/get-credentials.js.map +1 -1
  140. package/dist/utils/log.cjs +25 -0
  141. package/dist/utils/log.cjs.map +1 -0
  142. package/dist/utils/log.js +15 -17
  143. package/dist/utils/log.js.map +1 -1
  144. package/dist/utils/network-policy.cjs +65 -0
  145. package/dist/utils/network-policy.cjs.map +1 -0
  146. package/dist/utils/network-policy.js +58 -77
  147. package/dist/utils/network-policy.js.map +1 -1
  148. package/dist/utils/normalizePath.cjs +27 -0
  149. package/dist/utils/normalizePath.cjs.map +1 -0
  150. package/dist/utils/normalizePath.js +21 -28
  151. package/dist/utils/normalizePath.js.map +1 -1
  152. package/dist/utils/resolveSignal.cjs +20 -0
  153. package/dist/utils/resolveSignal.cjs.map +1 -0
  154. package/dist/utils/resolveSignal.d.cts +15 -0
  155. package/dist/utils/resolveSignal.d.ts +12 -10
  156. package/dist/utils/resolveSignal.js +14 -17
  157. package/dist/utils/resolveSignal.js.map +1 -1
  158. package/dist/utils/sandbox-snapshot.cjs +14 -0
  159. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  160. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  161. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  162. package/dist/utils/sandbox-snapshot.js +14 -0
  163. package/dist/utils/sandbox-snapshot.js.map +1 -0
  164. package/dist/utils/types.cjs +13 -0
  165. package/dist/utils/types.cjs.map +1 -0
  166. package/dist/utils/types.d.cts +11 -0
  167. package/dist/utils/types.d.ts +5 -7
  168. package/dist/utils/types.js +8 -8
  169. package/dist/utils/types.js.map +1 -1
  170. package/dist/version.cjs +7 -0
  171. package/dist/version.cjs.map +1 -0
  172. package/dist/version.js +5 -5
  173. package/dist/version.js.map +1 -1
  174. package/package.json +23 -3
  175. package/dist/api-client/index.js.map +0 -1
  176. package/dist/auth/api.d.ts +0 -6
  177. package/dist/auth/error.d.ts +0 -11
  178. package/dist/auth/index.js.map +0 -1
  179. package/dist/auth/linked-project.d.ts +0 -10
  180. package/dist/auth/zod.d.ts +0 -5
  181. package/dist/constants.js +0 -3
  182. package/dist/constants.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/network-policy.js +0 -3
  185. package/dist/network-policy.js.map +0 -1
  186. package/dist/utils/array.d.ts +0 -9
  187. package/dist/utils/consume-readable.d.ts +0 -5
  188. package/dist/utils/convert-sandbox.d.ts +0 -6
  189. package/dist/utils/convert-sandbox.js +0 -14
  190. package/dist/utils/convert-sandbox.js.map +0 -1
  191. package/dist/utils/decode-base64-url.d.ts +0 -7
  192. package/dist/utils/dev-credentials.d.ts +0 -37
  193. package/dist/utils/log.d.ts +0 -2
  194. package/dist/utils/network-policy.d.ts +0 -7
  195. package/dist/utils/normalizePath.d.ts +0 -17
  196. package/dist/version.d.ts +0 -1
@@ -1,143 +1,123 @@
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
10
7
  /**
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
- }
59
- }
60
- exports.BaseClient = BaseClient;
8
+ * A base API client that provides a convenience wrapper for fetching where
9
+ * we can pass query parameters as an object, support retries, debugging
10
+ * and automatic authorization.
11
+ */
12
+ var BaseClient = class {
13
+ constructor(params) {
14
+ this.fetch = withRetry(params.fetch ?? globalThis.fetch);
15
+ this.baseUrl = params.baseUrl;
16
+ this.debug = params.debug ?? process.env.DEBUG_FETCH === "true";
17
+ this.token = params.token;
18
+ this.agent = new Agent({ bodyTimeout: 0 });
19
+ }
20
+ async request(path, opts) {
21
+ const url = new URL(`${this.baseUrl}${path}`);
22
+ if (opts?.query) for (const [key, value] of Object.entries(opts.query)) array(value).forEach((value$1) => {
23
+ url.searchParams.append(key, value$1.toString());
24
+ });
25
+ const start = Date.now();
26
+ const response = await this.fetch(url.toString(), {
27
+ ...opts,
28
+ body: opts?.body,
29
+ method: opts?.method || "GET",
30
+ headers: this.token ? {
31
+ Authorization: `Bearer ${this.token}`,
32
+ ...opts?.headers
33
+ } : opts?.headers,
34
+ dispatcher: this.agent,
35
+ signal: opts?.signal
36
+ });
37
+ if (this.debug) {
38
+ const duration = Date.now() - start;
39
+ console.log(`[API] ${url} (${response.status}) ${duration}ms`);
40
+ if (response.status === 429) {
41
+ const retry = parseInt(response.headers.get("Retry-After") ?? "", 10);
42
+ const hours = Math.floor(retry / 60 / 60);
43
+ const minutes = Math.floor(retry / 60) % 60;
44
+ const seconds = retry % 60;
45
+ console.warn(`[API] ${url} Rate Limited, Retry After ${hours}h ${minutes}m ${seconds}s`);
46
+ }
47
+ }
48
+ return response;
49
+ }
50
+ };
61
51
  /**
62
- * Extract sessionId from a sandbox API URL.
63
- */
52
+ * Extract sessionId from a sandbox API URL.
53
+ */
64
54
  function extractSessionId(url) {
65
- const match = url.match(/\/v2\/sandboxes\/sessions\/([^/?]+)/);
66
- return match?.[1];
55
+ return url.match(/\/v2\/sandboxes\/sessions\/([^/?]+)/)?.[1];
67
56
  }
68
57
  /**
69
- * Extract sandbox name from a sandbox API url.
70
- * Excludes known sub-paths like /sessions/ and /snapshots/.
71
- */
58
+ * Extract sandbox name from a sandbox API url.
59
+ * Excludes known sub-paths like /sessions/ and /snapshots/.
60
+ */
72
61
  function extractSandboxName(url) {
73
- const match = url.match(/\/v2\/sandboxes\/(?!sessions(?:\/|$|\?))(?!snapshots(?:\/|$|\?))([^/?]+)/);
74
- return match?.[1];
62
+ return url.match(/\/v2\/sandboxes\/(?!sessions(?:\/|$|\?))(?!snapshots(?:\/|$|\?))([^/?]+)/)?.[1];
75
63
  }
76
64
  /**
77
- * Allows to read the response text and parse it as JSON casting to the given
78
- * type. If the response is not ok or cannot be parsed it will return error.
79
- *
80
- * @param response Response to parse.
81
- * @returns Parsed response or error.
82
- */
65
+ * Allows to read the response text and parse it as JSON casting to the given
66
+ * type. If the response is not ok or cannot be parsed it will return error.
67
+ *
68
+ * @param response Response to parse.
69
+ * @returns Parsed response or error.
70
+ */
83
71
  async function parse(validator, response) {
84
- const sessionId = extractSessionId(response.url);
85
- let sandboxName;
86
- if (!sessionId) {
87
- sandboxName = extractSandboxName(response.url);
88
- }
89
- const text = await response.text().catch((err) => {
90
- return new api_error_1.APIError(response, {
91
- message: `Can't read response text: ${String(err)}`,
92
- sessionId,
93
- sandboxName
94
- });
95
- });
96
- if (typeof text !== "string") {
97
- return text;
98
- }
99
- let json;
100
- try {
101
- json = JSON.parse(text || "{}");
102
- }
103
- catch (error) {
104
- return new api_error_1.APIError(response, {
105
- message: `Can't parse JSON: ${String(error)}`,
106
- text,
107
- sessionId,
108
- sandboxName
109
- });
110
- }
111
- if (!response.ok) {
112
- return new api_error_1.APIError(response, {
113
- message: `Status code ${response.status} is not ok`,
114
- json: json,
115
- text,
116
- sessionId,
117
- sandboxName
118
- });
119
- }
120
- const validated = validator.safeParse(json);
121
- if (!validated.success) {
122
- return new api_error_1.APIError(response, {
123
- message: `Response JSON is not valid: ${validated.error}`,
124
- json: json,
125
- text,
126
- sessionId,
127
- sandboxName
128
- });
129
- }
130
- return {
131
- json: validated.data,
132
- response,
133
- text,
134
- };
72
+ const sessionId = extractSessionId(response.url);
73
+ let sandboxName;
74
+ if (!sessionId) sandboxName = extractSandboxName(response.url);
75
+ const text = await response.text().catch((err) => {
76
+ return new APIError(response, {
77
+ message: `Can't read response text: ${String(err)}`,
78
+ sessionId,
79
+ sandboxName
80
+ });
81
+ });
82
+ if (typeof text !== "string") return text;
83
+ let json;
84
+ try {
85
+ json = JSON.parse(text || "{}");
86
+ } catch (error) {
87
+ return new APIError(response, {
88
+ message: `Can't parse JSON: ${String(error)}`,
89
+ text,
90
+ sessionId,
91
+ sandboxName
92
+ });
93
+ }
94
+ if (!response.ok) return new APIError(response, {
95
+ message: `Status code ${response.status} is not ok`,
96
+ json,
97
+ text,
98
+ sessionId,
99
+ sandboxName
100
+ });
101
+ const validated = validator.safeParse(json);
102
+ if (!validated.success) return new APIError(response, {
103
+ message: `Response JSON is not valid: ${validated.error}`,
104
+ json,
105
+ text,
106
+ sessionId,
107
+ sandboxName
108
+ });
109
+ return {
110
+ json: validated.data,
111
+ response,
112
+ text
113
+ };
135
114
  }
136
115
  async function parseOrThrow(validator, response) {
137
- const result = await parse(validator, response);
138
- if (result instanceof api_error_1.APIError) {
139
- throw result;
140
- }
141
- return result;
116
+ const result = await parse(validator, response);
117
+ if (result instanceof APIError) throw result;
118
+ return result;
142
119
  }
120
+
121
+ //#endregion
122
+ export { BaseClient, parseOrThrow };
143
123
  //# sourceMappingURL=base-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-client.js","sourceRoot":"","sources":["../../src/api-client/base-client.ts"],"names":[],"mappings":";;;AAiHA,sBA6DC;AAED,oCAUC;AAzLD,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,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM,CAAC;QAChE,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,cAAK,CAAC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SAAS;YACT,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,QAAQ;QACR,IAAI;KACL,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,YAAY,CAChC,SAAwB,EACxB,QAAkB;IAElB,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\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 = new Agent({\n bodyTimeout: 0, // disable body timeout to allow long logs streaming\n });\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":";;;;;;;;;;;AAoBA,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,IAAI,MAAM,EACrB,aAAa,GACd,CAAC;;CAGJ,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,KAA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AAO;AACd,SAAO,IAAI,SAAoB,UAAU;GACvC,SAAS,qBAAqB,OAAO,MAAM;GAC3C;GACA;GACA;GACD,CAAC;;AAGJ,KAAI,CAAC,SAAS,GACZ,QAAO,IAAI,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,62 +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;
11
- /**
12
- * The file mode (permissions) to set on the file.
13
- * For example, 0o755 for executable files.
14
- */
15
- mode?: number;
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;
16
18
  }
17
19
  interface FileStream {
18
- /**
19
- * The name (path) of the file to write.
20
- */
21
- name: string;
22
- /**
23
- * A Readable stream to consume the content of the file.
24
- */
25
- content: Readable;
26
- /**
27
- * The expected size of the file. This is required to write
28
- * the header of the compressed file.
29
- */
30
- size: number;
31
- /**
32
- * The file mode (permissions) to set on the file.
33
- * For example, 0o755 for executable files.
34
- */
35
- mode?: 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;
36
38
  }
37
39
  /**
38
40
  * Allows to create a Readable stream with methods to write files
39
41
  * to it and to finish it. Files written are compressed together
40
42
  * and gzipped in the stream.
41
43
  */
42
- export declare class FileWriter {
43
- readable: Readable;
44
- private pack;
45
- constructor();
46
- /**
47
- * Allows to add a file to the stream. Size is required to write
48
- * the tarball header so when content is a stream it must be
49
- * provided.
50
- *
51
- * Returns a Promise resolved once the file is written in the
52
- * stream.
53
- */
54
- addFile(file: FileBuffer | FileStream): Promise<void>;
55
- /**
56
- * Allows to finish the stream returning a Promise that will
57
- * resolve once the readable is effectively closed or
58
- * errored.
59
- */
60
- 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>;
61
63
  }
62
- export {};
64
+ //#endregion
65
+ export { FileWriter };
66
+ //# sourceMappingURL=file-writer.d.ts.map