@declaw/sdk 1.1.0 → 1.1.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.
- package/CHANGELOG.md +34 -0
- package/dist/index.cjs +215 -218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -5
- package/dist/index.d.ts +30 -5
- package/dist/index.js +213 -218
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,40 @@ All notable changes to the Declaw TypeScript / JavaScript SDK are documented in
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.1.2]
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **Binary-safe `files.read`.** `sandbox.files.read(path, { format: "bytes" })`
|
|
13
|
+
now returns a `Uint8Array` with the raw bytes. Previously the
|
|
14
|
+
`format` option was silently ignored: every read went through the
|
|
15
|
+
`text/plain` accept path and was UTF-8 decoded, so any byte with the
|
|
16
|
+
high bit set collapsed to the replacement character `U+FFFD` and the
|
|
17
|
+
buffer came back short of the real file length. Binary writes were
|
|
18
|
+
already routed through `PUT /files/raw` (1.0.1); this patch closes
|
|
19
|
+
the read side so PNGs, compressed archives, and other non-text blobs
|
|
20
|
+
round-trip unmodified.
|
|
21
|
+
|
|
22
|
+
## [1.1.1]
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- **Process-wide HTTP client cache.** `Sandbox.create` / `.connect` /
|
|
27
|
+
`.list`, `Volumes.*`, and `Template.*` now share a single `ApiClient`
|
|
28
|
+
per `(apiKey, apiUrl, requestTimeout)` via the new `getSharedClient`
|
|
29
|
+
helper instead of constructing a fresh instance per call. Matches the
|
|
30
|
+
symmetry added on the Python side and removes unnecessary
|
|
31
|
+
`AbortController` churn. Node's global fetch / undici dispatcher was
|
|
32
|
+
already pooling TCP + TLS under the hood, so end-to-end latency is
|
|
33
|
+
unchanged for most callers — the user-visible win is that
|
|
34
|
+
`close()` on a returned `Sandbox` is now a no-op rather than
|
|
35
|
+
aborting an in-flight request on the shared client.
|
|
36
|
+
- New exports from the package root: `getSharedClient`,
|
|
37
|
+
`resetSharedClients`. Use `resetSharedClients()` from tests or
|
|
38
|
+
long-running services that want to force a full teardown.
|
|
39
|
+
- `Sandbox.close()` is now a no-op. `Sandbox.kill()` still kills the
|
|
40
|
+
VM and is unchanged.
|
|
41
|
+
|
|
8
42
|
## [1.1.0]
|
|
9
43
|
|
|
10
44
|
### Added
|
package/dist/index.cjs
CHANGED
|
@@ -69,6 +69,7 @@ __export(index_exports, {
|
|
|
69
69
|
createToxicityConfig: () => createToxicityConfig,
|
|
70
70
|
createTransformationRule: () => createTransformationRule,
|
|
71
71
|
domainMatches: () => domainMatches,
|
|
72
|
+
getSharedClient: () => getSharedClient,
|
|
72
73
|
invisibleTextConfigToJSON: () => invisibleTextConfigToJSON,
|
|
73
74
|
isSensitive: () => isSensitive,
|
|
74
75
|
networkPolicyToOpts: () => networkPolicyToOpts,
|
|
@@ -96,6 +97,7 @@ __export(index_exports, {
|
|
|
96
97
|
parseVolumeInfo: () => parseVolumeInfo,
|
|
97
98
|
parseWriteInfo: () => parseWriteInfo,
|
|
98
99
|
requiresTlsInterception: () => requiresTlsInterception,
|
|
100
|
+
resetSharedClients: () => resetSharedClients,
|
|
99
101
|
securityPolicyToJSON: () => securityPolicyToJSON,
|
|
100
102
|
toxicityConfigToJSON: () => toxicityConfigToJSON,
|
|
101
103
|
validateNetworkEntry: () => validateNetworkEntry,
|
|
@@ -244,6 +246,12 @@ var ApiClient = class {
|
|
|
244
246
|
async get(path, opts) {
|
|
245
247
|
return this.requestWithRetry("GET", path, opts);
|
|
246
248
|
}
|
|
249
|
+
/** Send a GET request and return the response body as raw bytes. */
|
|
250
|
+
async getBytes(path, opts) {
|
|
251
|
+
const response = await this.requestWithRetry("GET", path, opts, true);
|
|
252
|
+
const buf = await response.arrayBuffer();
|
|
253
|
+
return new Uint8Array(buf);
|
|
254
|
+
}
|
|
247
255
|
/** Send a POST request and return parsed JSON. */
|
|
248
256
|
async post(path, opts) {
|
|
249
257
|
return this.requestWithRetry("POST", path, opts);
|
|
@@ -276,6 +284,12 @@ var ApiClient = class {
|
|
|
276
284
|
}
|
|
277
285
|
/**
|
|
278
286
|
* Abort all in-flight requests and release resources.
|
|
287
|
+
*
|
|
288
|
+
* Since 1.1.1 the SDK maintains a process-wide shared ApiClient cache
|
|
289
|
+
* for hot class-method paths (Sandbox.create, Volumes.*, Template.*).
|
|
290
|
+
* Calling `close()` on a shared instance aborts its AbortController,
|
|
291
|
+
* which would cancel any concurrent in-flight call. Prefer
|
|
292
|
+
* `resetSharedClients()` if you want to tear down every cached client.
|
|
279
293
|
*/
|
|
280
294
|
close() {
|
|
281
295
|
this.abortController.abort();
|
|
@@ -395,6 +409,28 @@ var ApiClient = class {
|
|
|
395
409
|
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
396
410
|
}
|
|
397
411
|
};
|
|
412
|
+
var _sharedClients = /* @__PURE__ */ new Map();
|
|
413
|
+
function sharedKey(config) {
|
|
414
|
+
return [config.apiKey ?? "", config.apiUrl, config.requestTimeout ?? ""].join("|");
|
|
415
|
+
}
|
|
416
|
+
function getSharedClient(config) {
|
|
417
|
+
const key = sharedKey(config);
|
|
418
|
+
let client = _sharedClients.get(key);
|
|
419
|
+
if (!client) {
|
|
420
|
+
client = new ApiClient(config);
|
|
421
|
+
_sharedClients.set(key, client);
|
|
422
|
+
}
|
|
423
|
+
return client;
|
|
424
|
+
}
|
|
425
|
+
function resetSharedClients() {
|
|
426
|
+
for (const client of _sharedClients.values()) {
|
|
427
|
+
try {
|
|
428
|
+
client.close();
|
|
429
|
+
} catch {
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
_sharedClients.clear();
|
|
433
|
+
}
|
|
398
434
|
|
|
399
435
|
// src/sandbox/network.ts
|
|
400
436
|
var ALL_TRAFFIC = "0.0.0.0/0";
|
|
@@ -1340,15 +1376,18 @@ var Filesystem = class {
|
|
|
1340
1376
|
this.sandboxId = sandboxId;
|
|
1341
1377
|
this.client = client;
|
|
1342
1378
|
}
|
|
1343
|
-
/**
|
|
1344
|
-
* Read a file's contents as a string.
|
|
1345
|
-
*
|
|
1346
|
-
* @param path - Absolute path to the file.
|
|
1347
|
-
* @param opts - Optional user and request timeout.
|
|
1348
|
-
* @returns The file contents as a string.
|
|
1349
|
-
*/
|
|
1350
1379
|
async read(path, opts) {
|
|
1351
1380
|
const user = opts?.user ?? DEFAULT_USER;
|
|
1381
|
+
if (opts?.format === "bytes") {
|
|
1382
|
+
return this.client.getBytes(
|
|
1383
|
+
`/sandboxes/${this.sandboxId}/files`,
|
|
1384
|
+
{
|
|
1385
|
+
params: { path, username: user },
|
|
1386
|
+
headers: { "Accept": "application/octet-stream" },
|
|
1387
|
+
timeout: opts?.requestTimeout
|
|
1388
|
+
}
|
|
1389
|
+
);
|
|
1390
|
+
}
|
|
1352
1391
|
const result = await this.client.get(
|
|
1353
1392
|
`/sandboxes/${this.sandboxId}/files`,
|
|
1354
1393
|
{
|
|
@@ -1944,54 +1983,49 @@ var Sandbox = class _Sandbox {
|
|
|
1944
1983
|
apiUrl: opts?.apiUrl,
|
|
1945
1984
|
requestTimeout: opts?.requestTimeout
|
|
1946
1985
|
});
|
|
1947
|
-
const client =
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
body.network = typeof opts.security.network === "object" && "allowOut" in opts.security.network ? networkOptsToJSON(opts.security.network) : opts.security.network;
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
if (opts?.lifecycle) {
|
|
1972
|
-
body.lifecycle = lifecycleToJSON(opts.lifecycle);
|
|
1973
|
-
}
|
|
1974
|
-
if (opts?.volumes && opts.volumes.length > 0) {
|
|
1975
|
-
body.volumes = opts.volumes.map(volumeAttachmentToJSON);
|
|
1986
|
+
const client = getSharedClient(config);
|
|
1987
|
+
const body = {
|
|
1988
|
+
template: opts?.template ?? DEFAULT_TEMPLATE,
|
|
1989
|
+
timeout: opts?.timeout ?? DEFAULT_TIMEOUT,
|
|
1990
|
+
secure: opts?.secure ?? true
|
|
1991
|
+
};
|
|
1992
|
+
if (opts?.metadata) {
|
|
1993
|
+
body.metadata = opts.metadata;
|
|
1994
|
+
}
|
|
1995
|
+
if (opts?.envs) {
|
|
1996
|
+
body.envs = opts.envs;
|
|
1997
|
+
}
|
|
1998
|
+
if (opts?.network) {
|
|
1999
|
+
body.network = networkOptsToJSON(opts.network);
|
|
2000
|
+
} else if (opts?.allowInternetAccess === false) {
|
|
2001
|
+
body.network = { deny_out: [ALL_TRAFFIC] };
|
|
2002
|
+
}
|
|
2003
|
+
if (opts?.security) {
|
|
2004
|
+
body.security = { policy_json: JSON.stringify(securityPolicyToJSON(opts.security)) };
|
|
2005
|
+
if (opts.security.network && !body.network) {
|
|
2006
|
+
body.network = typeof opts.security.network === "object" && "allowOut" in opts.security.network ? networkOptsToJSON(opts.security.network) : opts.security.network;
|
|
1976
2007
|
}
|
|
1977
|
-
const data = await client.post("/sandboxes", {
|
|
1978
|
-
json: body,
|
|
1979
|
-
timeout: opts?.requestTimeout
|
|
1980
|
-
});
|
|
1981
|
-
const sandboxId = data.sandbox_id;
|
|
1982
|
-
assertValidId(sandboxId, "sandbox ID (from server)");
|
|
1983
|
-
return new _Sandbox(
|
|
1984
|
-
sandboxId,
|
|
1985
|
-
config,
|
|
1986
|
-
client,
|
|
1987
|
-
data.envd_access_token,
|
|
1988
|
-
data.sandbox_domain,
|
|
1989
|
-
data.traffic_access_token
|
|
1990
|
-
);
|
|
1991
|
-
} catch (error) {
|
|
1992
|
-
client.close();
|
|
1993
|
-
throw error;
|
|
1994
2008
|
}
|
|
2009
|
+
if (opts?.lifecycle) {
|
|
2010
|
+
body.lifecycle = lifecycleToJSON(opts.lifecycle);
|
|
2011
|
+
}
|
|
2012
|
+
if (opts?.volumes && opts.volumes.length > 0) {
|
|
2013
|
+
body.volumes = opts.volumes.map(volumeAttachmentToJSON);
|
|
2014
|
+
}
|
|
2015
|
+
const data = await client.post("/sandboxes", {
|
|
2016
|
+
json: body,
|
|
2017
|
+
timeout: opts?.requestTimeout
|
|
2018
|
+
});
|
|
2019
|
+
const sandboxId = data.sandbox_id;
|
|
2020
|
+
assertValidId(sandboxId, "sandbox ID (from server)");
|
|
2021
|
+
return new _Sandbox(
|
|
2022
|
+
sandboxId,
|
|
2023
|
+
config,
|
|
2024
|
+
client,
|
|
2025
|
+
data.envd_access_token,
|
|
2026
|
+
data.sandbox_domain,
|
|
2027
|
+
data.traffic_access_token
|
|
2028
|
+
);
|
|
1995
2029
|
}
|
|
1996
2030
|
/**
|
|
1997
2031
|
* Connect to an existing sandbox.
|
|
@@ -2008,23 +2042,18 @@ var Sandbox = class _Sandbox {
|
|
|
2008
2042
|
apiUrl: opts?.apiUrl,
|
|
2009
2043
|
requestTimeout: opts?.requestTimeout
|
|
2010
2044
|
});
|
|
2011
|
-
const client =
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
);
|
|
2024
|
-
} catch (error) {
|
|
2025
|
-
client.close();
|
|
2026
|
-
throw error;
|
|
2027
|
-
}
|
|
2045
|
+
const client = getSharedClient(config);
|
|
2046
|
+
const data = await client.get(`/sandboxes/${sandboxId}`, {
|
|
2047
|
+
timeout: opts?.requestTimeout
|
|
2048
|
+
});
|
|
2049
|
+
return new _Sandbox(
|
|
2050
|
+
data.sandbox_id,
|
|
2051
|
+
config,
|
|
2052
|
+
client,
|
|
2053
|
+
data.envd_access_token,
|
|
2054
|
+
data.sandbox_domain,
|
|
2055
|
+
data.traffic_access_token
|
|
2056
|
+
);
|
|
2028
2057
|
}
|
|
2029
2058
|
/**
|
|
2030
2059
|
* List sandboxes.
|
|
@@ -2041,35 +2070,31 @@ var Sandbox = class _Sandbox {
|
|
|
2041
2070
|
apiUrl: opts?.apiUrl,
|
|
2042
2071
|
requestTimeout: opts?.requestTimeout
|
|
2043
2072
|
});
|
|
2044
|
-
const client =
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
params[key] = value;
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
if (opts?.limit !== void 0) {
|
|
2053
|
-
params.limit = String(opts.limit);
|
|
2054
|
-
}
|
|
2055
|
-
if (opts?.nextToken) {
|
|
2056
|
-
params.next_token = opts.nextToken;
|
|
2073
|
+
const client = getSharedClient(config);
|
|
2074
|
+
const params = {};
|
|
2075
|
+
if (opts?.query) {
|
|
2076
|
+
for (const [key, value] of Object.entries(opts.query)) {
|
|
2077
|
+
params[key] = value;
|
|
2057
2078
|
}
|
|
2058
|
-
const data = await client.get("/sandboxes", {
|
|
2059
|
-
params,
|
|
2060
|
-
timeout: opts?.requestTimeout
|
|
2061
|
-
});
|
|
2062
|
-
const rawSandboxes = data.sandboxes ?? [];
|
|
2063
|
-
const sandboxes = rawSandboxes.map(
|
|
2064
|
-
(s) => parseSandboxInfo(s)
|
|
2065
|
-
);
|
|
2066
|
-
return {
|
|
2067
|
-
sandboxes,
|
|
2068
|
-
nextToken: data.next_token ?? void 0
|
|
2069
|
-
};
|
|
2070
|
-
} finally {
|
|
2071
|
-
client.close();
|
|
2072
2079
|
}
|
|
2080
|
+
if (opts?.limit !== void 0) {
|
|
2081
|
+
params.limit = String(opts.limit);
|
|
2082
|
+
}
|
|
2083
|
+
if (opts?.nextToken) {
|
|
2084
|
+
params.next_token = opts.nextToken;
|
|
2085
|
+
}
|
|
2086
|
+
const data = await client.get("/sandboxes", {
|
|
2087
|
+
params,
|
|
2088
|
+
timeout: opts?.requestTimeout
|
|
2089
|
+
});
|
|
2090
|
+
const rawSandboxes = data.sandboxes ?? [];
|
|
2091
|
+
const sandboxes = rawSandboxes.map(
|
|
2092
|
+
(s) => parseSandboxInfo(s)
|
|
2093
|
+
);
|
|
2094
|
+
return {
|
|
2095
|
+
sandboxes,
|
|
2096
|
+
nextToken: data.next_token ?? void 0
|
|
2097
|
+
};
|
|
2073
2098
|
}
|
|
2074
2099
|
/**
|
|
2075
2100
|
* Kill this sandbox.
|
|
@@ -2221,33 +2246,31 @@ var Sandbox = class _Sandbox {
|
|
|
2221
2246
|
apiUrl: options.apiUrl,
|
|
2222
2247
|
requestTimeout: options.requestTimeout
|
|
2223
2248
|
});
|
|
2224
|
-
const client =
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
);
|
|
2241
|
-
} catch (error) {
|
|
2242
|
-
client.close();
|
|
2243
|
-
throw error;
|
|
2244
|
-
}
|
|
2249
|
+
const client = getSharedClient(config);
|
|
2250
|
+
const query = options.snapshotId ? `?snapshot_id=${encodeURIComponent(options.snapshotId)}` : "";
|
|
2251
|
+
await client.post(`/sandboxes/${sandboxId}/restore${query}`, {
|
|
2252
|
+
timeout: options.requestTimeout
|
|
2253
|
+
});
|
|
2254
|
+
const data = await client.get(`/sandboxes/${sandboxId}`, {
|
|
2255
|
+
timeout: options.requestTimeout
|
|
2256
|
+
});
|
|
2257
|
+
return new _Sandbox(
|
|
2258
|
+
data.sandbox_id,
|
|
2259
|
+
config,
|
|
2260
|
+
client,
|
|
2261
|
+
data.envd_access_token,
|
|
2262
|
+
data.sandbox_domain,
|
|
2263
|
+
data.traffic_access_token
|
|
2264
|
+
);
|
|
2245
2265
|
}
|
|
2246
2266
|
/**
|
|
2247
|
-
*
|
|
2267
|
+
* Historically closed the sandbox's HTTP client; since 1.1.1 the SDK
|
|
2268
|
+
* maintains a process-wide shared ApiClient (see `getSharedClient` in
|
|
2269
|
+
* api/client.ts) so per-sandbox close no longer tears the connection
|
|
2270
|
+
* pool down. Kept as a no-op for backwards compatibility — call
|
|
2271
|
+
* `resetSharedClients()` if you want to force a full teardown.
|
|
2248
2272
|
*/
|
|
2249
2273
|
close() {
|
|
2250
|
-
this._client.close();
|
|
2251
2274
|
}
|
|
2252
2275
|
/**
|
|
2253
2276
|
* Support `await using sandbox = await Sandbox.create(...)` for automatic cleanup.
|
|
@@ -2477,36 +2500,32 @@ var Template = class {
|
|
|
2477
2500
|
domain: opts?.domain,
|
|
2478
2501
|
requestTimeout: opts?.requestTimeout
|
|
2479
2502
|
});
|
|
2480
|
-
const client =
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
opts.onBuildLogs(log);
|
|
2504
|
-
}
|
|
2503
|
+
const client = getSharedClient(config);
|
|
2504
|
+
const body = {
|
|
2505
|
+
template: template.toJSON(),
|
|
2506
|
+
alias
|
|
2507
|
+
};
|
|
2508
|
+
if (opts?.cpuCount !== void 0) {
|
|
2509
|
+
body.cpu_count = opts.cpuCount;
|
|
2510
|
+
}
|
|
2511
|
+
if (opts?.memoryMb !== void 0) {
|
|
2512
|
+
body.memory_mb = opts.memoryMb;
|
|
2513
|
+
}
|
|
2514
|
+
if (opts?.diskMb !== void 0) {
|
|
2515
|
+
body.disk_mb = opts.diskMb;
|
|
2516
|
+
}
|
|
2517
|
+
const data = await client.post("/templates/build", {
|
|
2518
|
+
json: body,
|
|
2519
|
+
timeout: opts?.requestTimeout
|
|
2520
|
+
});
|
|
2521
|
+
const response = data;
|
|
2522
|
+
const result = parseBuildInfo(response);
|
|
2523
|
+
if (opts?.onBuildLogs && Array.isArray(response.logs)) {
|
|
2524
|
+
for (const log of response.logs) {
|
|
2525
|
+
opts.onBuildLogs(log);
|
|
2505
2526
|
}
|
|
2506
|
-
return result;
|
|
2507
|
-
} finally {
|
|
2508
|
-
client.close();
|
|
2509
2527
|
}
|
|
2528
|
+
return result;
|
|
2510
2529
|
}
|
|
2511
2530
|
/**
|
|
2512
2531
|
* Start a template build in the background.
|
|
@@ -2519,30 +2538,26 @@ var Template = class {
|
|
|
2519
2538
|
domain: opts?.domain,
|
|
2520
2539
|
requestTimeout: opts?.requestTimeout
|
|
2521
2540
|
});
|
|
2522
|
-
const client =
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
body.memory_mb = opts.memoryMb;
|
|
2534
|
-
}
|
|
2535
|
-
if (opts?.diskMb !== void 0) {
|
|
2536
|
-
body.disk_mb = opts.diskMb;
|
|
2537
|
-
}
|
|
2538
|
-
const data = await client.post("/templates/build", {
|
|
2539
|
-
json: body,
|
|
2540
|
-
timeout: opts?.requestTimeout
|
|
2541
|
-
});
|
|
2542
|
-
return parseBuildInfo(data);
|
|
2543
|
-
} finally {
|
|
2544
|
-
client.close();
|
|
2541
|
+
const client = getSharedClient(config);
|
|
2542
|
+
const body = {
|
|
2543
|
+
template: template.toJSON(),
|
|
2544
|
+
alias,
|
|
2545
|
+
background: true
|
|
2546
|
+
};
|
|
2547
|
+
if (opts?.cpuCount !== void 0) {
|
|
2548
|
+
body.cpu_count = opts.cpuCount;
|
|
2549
|
+
}
|
|
2550
|
+
if (opts?.memoryMb !== void 0) {
|
|
2551
|
+
body.memory_mb = opts.memoryMb;
|
|
2545
2552
|
}
|
|
2553
|
+
if (opts?.diskMb !== void 0) {
|
|
2554
|
+
body.disk_mb = opts.diskMb;
|
|
2555
|
+
}
|
|
2556
|
+
const data = await client.post("/templates/build", {
|
|
2557
|
+
json: body,
|
|
2558
|
+
timeout: opts?.requestTimeout
|
|
2559
|
+
});
|
|
2560
|
+
return parseBuildInfo(data);
|
|
2546
2561
|
}
|
|
2547
2562
|
/**
|
|
2548
2563
|
* Get the status of a template build.
|
|
@@ -2556,15 +2571,11 @@ var Template = class {
|
|
|
2556
2571
|
domain: opts?.domain,
|
|
2557
2572
|
requestTimeout: opts?.requestTimeout
|
|
2558
2573
|
});
|
|
2559
|
-
const client =
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
return parseTemplateBuildStatus(data);
|
|
2565
|
-
} finally {
|
|
2566
|
-
client.close();
|
|
2567
|
-
}
|
|
2574
|
+
const client = getSharedClient(config);
|
|
2575
|
+
const data = await client.get(`/templates/builds/${buildId}`, {
|
|
2576
|
+
timeout: opts?.requestTimeout
|
|
2577
|
+
});
|
|
2578
|
+
return parseTemplateBuildStatus(data);
|
|
2568
2579
|
}
|
|
2569
2580
|
};
|
|
2570
2581
|
|
|
@@ -2589,19 +2600,15 @@ var Volumes = class {
|
|
|
2589
2600
|
apiUrl: opts?.apiUrl,
|
|
2590
2601
|
requestTimeout: opts?.requestTimeout
|
|
2591
2602
|
});
|
|
2592
|
-
const client =
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
return parseVolumeInfo(resp);
|
|
2602
|
-
} finally {
|
|
2603
|
-
client.close();
|
|
2604
|
-
}
|
|
2603
|
+
const client = getSharedClient(config);
|
|
2604
|
+
const body = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
2605
|
+
const resp = await client.post("/volumes", {
|
|
2606
|
+
params: { name },
|
|
2607
|
+
body,
|
|
2608
|
+
headers: { "Content-Type": opts?.contentType ?? "application/gzip" },
|
|
2609
|
+
timeout: opts?.requestTimeout
|
|
2610
|
+
});
|
|
2611
|
+
return parseVolumeInfo(resp);
|
|
2605
2612
|
}
|
|
2606
2613
|
/** Fetch metadata for a single volume. */
|
|
2607
2614
|
static async get(volumeId, opts) {
|
|
@@ -2612,15 +2619,11 @@ var Volumes = class {
|
|
|
2612
2619
|
apiUrl: opts?.apiUrl,
|
|
2613
2620
|
requestTimeout: opts?.requestTimeout
|
|
2614
2621
|
});
|
|
2615
|
-
const client =
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
return parseVolumeInfo(resp);
|
|
2621
|
-
} finally {
|
|
2622
|
-
client.close();
|
|
2623
|
-
}
|
|
2622
|
+
const client = getSharedClient(config);
|
|
2623
|
+
const resp = await client.get(`/volumes/${volumeId}`, {
|
|
2624
|
+
timeout: opts?.requestTimeout
|
|
2625
|
+
});
|
|
2626
|
+
return parseVolumeInfo(resp);
|
|
2624
2627
|
}
|
|
2625
2628
|
/** List all volumes owned by the caller, newest first. */
|
|
2626
2629
|
static async list(opts) {
|
|
@@ -2630,16 +2633,12 @@ var Volumes = class {
|
|
|
2630
2633
|
apiUrl: opts?.apiUrl,
|
|
2631
2634
|
requestTimeout: opts?.requestTimeout
|
|
2632
2635
|
});
|
|
2633
|
-
const client =
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
return rows.map(parseVolumeInfo);
|
|
2640
|
-
} finally {
|
|
2641
|
-
client.close();
|
|
2642
|
-
}
|
|
2636
|
+
const client = getSharedClient(config);
|
|
2637
|
+
const resp = await client.get("/volumes", {
|
|
2638
|
+
timeout: opts?.requestTimeout
|
|
2639
|
+
});
|
|
2640
|
+
const rows = resp.volumes ?? [];
|
|
2641
|
+
return rows.map(parseVolumeInfo);
|
|
2643
2642
|
}
|
|
2644
2643
|
/** Delete a volume and its blob. Idempotent on the wire. */
|
|
2645
2644
|
static async delete(volumeId, opts) {
|
|
@@ -2650,12 +2649,8 @@ var Volumes = class {
|
|
|
2650
2649
|
apiUrl: opts?.apiUrl,
|
|
2651
2650
|
requestTimeout: opts?.requestTimeout
|
|
2652
2651
|
});
|
|
2653
|
-
const client =
|
|
2654
|
-
|
|
2655
|
-
await client.delete(`/volumes/${volumeId}`, { timeout: opts?.requestTimeout });
|
|
2656
|
-
} finally {
|
|
2657
|
-
client.close();
|
|
2658
|
-
}
|
|
2652
|
+
const client = getSharedClient(config);
|
|
2653
|
+
await client.delete(`/volumes/${volumeId}`, { timeout: opts?.requestTimeout });
|
|
2659
2654
|
}
|
|
2660
2655
|
};
|
|
2661
2656
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -2709,6 +2704,7 @@ var Volumes = class {
|
|
|
2709
2704
|
createToxicityConfig,
|
|
2710
2705
|
createTransformationRule,
|
|
2711
2706
|
domainMatches,
|
|
2707
|
+
getSharedClient,
|
|
2712
2708
|
invisibleTextConfigToJSON,
|
|
2713
2709
|
isSensitive,
|
|
2714
2710
|
networkPolicyToOpts,
|
|
@@ -2736,6 +2732,7 @@ var Volumes = class {
|
|
|
2736
2732
|
parseVolumeInfo,
|
|
2737
2733
|
parseWriteInfo,
|
|
2738
2734
|
requiresTlsInterception,
|
|
2735
|
+
resetSharedClients,
|
|
2739
2736
|
securityPolicyToJSON,
|
|
2740
2737
|
toxicityConfigToJSON,
|
|
2741
2738
|
validateNetworkEntry,
|