disk 1.2.0 → 1.4.0

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/README.md CHANGED
@@ -105,6 +105,38 @@ await d.removeUser("token", user.identifier!);
105
105
  await d.delete();
106
106
  ```
107
107
 
108
+ ### Private certificate authorities (Node.js)
109
+
110
+ For BYOC endpoints signed by a private CA, configure trust on the client:
111
+
112
+ ```ts
113
+ import { readFileSync } from "node:fs";
114
+ import { getCACertificates } from "node:tls";
115
+ import { Archil } from "disk";
116
+
117
+ const client = new Archil({
118
+ apiKey: process.env.ARCHIL_API_KEY,
119
+ region: "aws-us-east-2",
120
+ baseUrl: "https://control.archil.example.internal",
121
+ s3BaseUrl: "https://s3.archil.example.internal",
122
+ tls: {
123
+ ca: [...getCACertificates(), readFileSync("archil-ca.pem")],
124
+ },
125
+ });
126
+ ```
127
+
128
+ `tls.ca` accepts a PEM string, a `Buffer`, or an array of either. As with Node's
129
+ TLS `ca` option, it **replaces** the default trust list. The example includes Node's
130
+ defaults as well as the private CA; `getCACertificates()` requires Node 22.15+.
131
+ Omitting `tls.ca` preserves Node's default trust behavior.
132
+
133
+ The configuration applies to this client's control-plane and S3-compatible requests,
134
+ with certificate and hostname verification enabled. It does not change Node's global
135
+ dispatcher or default trust. HTTP/2 pooling is preserved, and clients only share pools
136
+ when their endpoint, API key, and CA configuration match. CA arrays and buffers are
137
+ copied at construction; create a new client to change trust settings. Custom CAs are
138
+ not supported in browsers.
139
+
108
140
  ### Sandboxes
109
141
 
110
142
  Use `Archil.sandboxes` to manage persistent VMs:
@@ -172,6 +204,37 @@ service-published ports. Deleting explicit exposure leaves a service publishing
172
204
  the same port reachable and does not stop the listening process. Routing changes
173
205
  may take a few seconds to propagate, and existing connections remain open.
174
206
 
207
+ `fork` pauses a running sandbox while the snapshot is taken and resumes it once the
208
+ fork is accepted. A paused or stopped sandbox is forked in place and left as it is.
209
+
210
+ For private HTTP access, create a port token without exposing the port publicly:
211
+
212
+ ```ts
213
+ const privateWeb = await client.sandboxes.create({ baseImage: "python:3.12-slim" });
214
+ const server = await privateWeb.processes.start("python -m http.server 8080 --bind 0.0.0.0");
215
+ await server.disconnect();
216
+
217
+ const access = await privateWeb.createPortToken(8080, { ttl: "1h" });
218
+ // Once the server is listening:
219
+ const response = await fetch(`https://${access.hostname}/`, {
220
+ headers: { "X-Archil-Token": access.token },
221
+ });
222
+ console.log(await response.text());
223
+
224
+ const metadata = await privateWeb.getPortToken(access.id);
225
+ const tokens = await privateWeb.listPortTokens();
226
+ const page = await privateWeb.listPortTokensPage({ limit: 10 });
227
+ await privateWeb.deletePortToken(access);
228
+ await privateWeb.delete();
229
+ ```
230
+
231
+ The secret and hostname are returned only by `createPortToken`; get/list return
232
+ metadata. Save the secret when creating it. Omit `ttl` for no expiration, or use
233
+ a duration up to `"8760h"` (365 days). `listPortTokens` follows all pages (its
234
+ `limit` caps the total); `listPortTokensPage` returns `nextCursor` for pagination.
235
+ Public ports bypass token authentication. Revocation and expiry deny new
236
+ connections with HTTP 401; existing connections remain open.
237
+
175
238
  Network egress can optionally be restricted when creating a sandbox:
176
239
 
177
240
  ```ts
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { O as ArchilApiError, a as deleteApiKey, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-Crk5lxKW.mjs";
3
- import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-DQS29KQU.mjs";
2
+ import { O as ArchilApiError, a as deleteApiKey, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-BaAv98od.mjs";
3
+ import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-D2ic5Rit.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { Command } from "commander";
6
6
  //#region bin/cli.ts
@@ -1,4 +1,4 @@
1
- import { D as REGION_URLS, p as Archil } from "./src-Crk5lxKW.mjs";
1
+ import { D as REGION_URLS, p as Archil } from "./src-BaAv98od.mjs";
2
2
  import { Option } from "commander";
3
3
  import { isCancel, password, spinner } from "@clack/prompts";
4
4
  import { chmod, mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
@@ -1,7 +1,17 @@
1
1
  import { Client } from "openapi-fetch";
2
2
  import { components, paths } from "@archildata/api-types";
3
+ import { ConnectionOptions } from "node:tls";
4
+
3
5
  //#region src/client.d.ts
4
6
  type ApiClient = Client<paths>;
7
+ interface ArchilTlsOptions {
8
+ /**
9
+ * Trusted PEM CA certificates for this client's control-plane and S3 requests
10
+ * (Node.js only). Replaces Node's default CA list; include those certificates
11
+ * explicitly to retain them. Certificate and hostname verification stay enabled.
12
+ */
13
+ ca?: ConnectionOptions["ca"];
14
+ }
5
15
  //#endregion
6
16
  //#region src/filesystem.d.ts
7
17
  /**
@@ -708,4 +718,4 @@ declare class DiskMultipart {
708
718
  */
709
719
  declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
710
720
  //#endregion
711
- export { S3Mount as $, ApiTokenResponse as A, DiskStatus as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepMatch as G, ExecDiskResult as H, CreateDiskRequest as I, MountConfigResponse as J, GrepStoppedReason as K, Delegation as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, S3CompatibleMount as Q, DiskMetrics as R, PosixCreateAttrs as S, S3Object as T, ExecRequest as U, DiskUser as V, GCSMount as W, R2Mount as X, MountResponse as Y, RootAttrs as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, TokenUser as et, ListObjectsOptions as f, MultipartUpload as g, MountOptions as h, DeleteObjectsOptions as i, AuthorizedUser as j, effectiveUploadPartSize as k, GrepOptions as l, ListPartsOptions as m, CompletedMultipartUpload as n, ApiClient as nt, Disk as o, ListObjectsResult as p, MountConfig as q, DeleteObjectsError as r, DiskMultipart as s, AppendObjectOptions as t, FileSystem as tt, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskResponse as z };
721
+ export { S3Mount as $, ApiTokenResponse as A, DiskStatus as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepMatch as G, ExecDiskResult as H, CreateDiskRequest as I, MountConfigResponse as J, GrepStoppedReason as K, Delegation as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, S3CompatibleMount as Q, DiskMetrics as R, PosixCreateAttrs as S, S3Object as T, ExecRequest as U, DiskUser as V, GCSMount as W, R2Mount as X, MountResponse as Y, RootAttrs as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, TokenUser as et, ListObjectsOptions as f, MultipartUpload as g, MountOptions as h, DeleteObjectsOptions as i, AuthorizedUser as j, effectiveUploadPartSize as k, GrepOptions as l, ListPartsOptions as m, CompletedMultipartUpload as n, ApiClient as nt, Disk as o, ListObjectsResult as p, MountConfig as q, DeleteObjectsError as r, ArchilTlsOptions as rt, DiskMultipart as s, AppendObjectOptions as t, FileSystem as tt, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskResponse as z };
@@ -1,7 +1,17 @@
1
1
  import { Client } from "openapi-fetch";
2
2
  import { components, paths } from "@archildata/api-types";
3
+ import { ConnectionOptions } from "node:tls";
4
+
3
5
  //#region src/client.d.ts
4
6
  type ApiClient = Client<paths>;
7
+ interface ArchilTlsOptions {
8
+ /**
9
+ * Trusted PEM CA certificates for this client's control-plane and S3 requests
10
+ * (Node.js only). Replaces Node's default CA list; include those certificates
11
+ * explicitly to retain them. Certificate and hostname verification stay enabled.
12
+ */
13
+ ca?: ConnectionOptions["ca"];
14
+ }
5
15
  //#endregion
6
16
  //#region src/filesystem.d.ts
7
17
  /**
@@ -708,4 +718,4 @@ declare class DiskMultipart {
708
718
  */
709
719
  declare function effectiveUploadPartSize(totalBytes: number, requestedPartSize: number): number;
710
720
  //#endregion
711
- export { S3Mount as $, ApiTokenResponse as A, DiskStatus as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepMatch as G, ExecDiskResult as H, CreateDiskRequest as I, MountConfigResponse as J, GrepStoppedReason as K, Delegation as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, S3CompatibleMount as Q, DiskMetrics as R, PosixCreateAttrs as S, S3Object as T, ExecRequest as U, DiskUser as V, GCSMount as W, R2Mount as X, MountResponse as Y, RootAttrs as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, TokenUser as et, ListObjectsOptions as f, MultipartUpload as g, MountOptions as h, DeleteObjectsOptions as i, AuthorizedUser as j, effectiveUploadPartSize as k, GrepOptions as l, ListPartsOptions as m, CompletedMultipartUpload as n, ApiClient as nt, Disk as o, ListObjectsResult as p, MountConfig as q, DeleteObjectsError as r, DiskMultipart as s, AppendObjectOptions as t, FileSystem as tt, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskResponse as z };
721
+ export { S3Mount as $, ApiTokenResponse as A, DiskStatus as B, PutObjectOptions as C, ShareUrlResult as D, ShareUrlOptions as E, CreateApiTokenRequest as F, GrepMatch as G, ExecDiskResult as H, CreateDiskRequest as I, MountConfigResponse as J, GrepStoppedReason as K, Delegation as L, AwsStsUser as M, AzureBlobMount as N, UploadPart as O, ConnectedClient as P, S3CompatibleMount as Q, DiskMetrics as R, PosixCreateAttrs as S, S3Object as T, ExecRequest as U, DiskUser as V, GCSMount as W, R2Mount as X, MountResponse as Y, RootAttrs as Z, MultipartUploadListing as _, DeleteObjectsResult as a, PartInfo as b, ExecResult as c, ListMultipartUploadsOptions as d, TokenUser as et, ListObjectsOptions as f, MultipartUpload as g, MountOptions as h, DeleteObjectsOptions as i, AuthorizedUser as j, effectiveUploadPartSize as k, GrepOptions as l, ListPartsOptions as m, CompletedMultipartUpload as n, ApiClient as nt, Disk as o, ListObjectsResult as p, MountConfig as q, DeleteObjectsError as r, ArchilTlsOptions as rt, DiskMultipart as s, AppendObjectOptions as t, FileSystem as tt, GrepResult as u, MultipartUploadSummary as v, PutObjectResult as w, PartListing as x, ObjectMetadata as y, DiskResponse as z };
package/dist/index.cjs CHANGED
@@ -145,7 +145,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
145
145
  }
146
146
  //#endregion
147
147
  //#region src/version.ts
148
- const VERSION = "1.2.0";
148
+ const VERSION = "1.4.0";
149
149
  const USER_AGENT = `archil-js/${VERSION}`;
150
150
  //#endregion
151
151
  //#region src/client.ts
@@ -198,11 +198,14 @@ const multiplexHttp2Requests = (dispatch) => (options, handler) => {
198
198
  return true;
199
199
  };
200
200
  const sharedDispatchers = /* @__PURE__ */ new Map();
201
- function dispatcherKey(baseUrl, apiKey) {
202
- return `${new URL(baseUrl).origin}\0${apiKey}`;
203
- }
204
- function getSharedDispatcher(baseUrl, apiKey) {
205
- const key = dispatcherKey(baseUrl, apiKey);
201
+ function dispatcherKey(baseUrl, apiKey, ca) {
202
+ return JSON.stringify([
203
+ new URL(baseUrl).origin,
204
+ apiKey,
205
+ ca?.map((cert) => cert.toString("base64"))
206
+ ]);
207
+ }
208
+ function getSharedDispatcher(key, ca) {
206
209
  const existing = sharedDispatchers.get(key);
207
210
  if (existing) return existing;
208
211
  const dispatcher = (async () => {
@@ -213,7 +216,8 @@ function getSharedDispatcher(baseUrl, apiKey) {
213
216
  connections: CONTROL_PLANE_CONNECTIONS,
214
217
  pipelining: CONTROL_PLANE_CONCURRENT_STREAMS,
215
218
  keepAliveTimeout: 6e4,
216
- keepAliveMaxTimeout: 6e5
219
+ keepAliveMaxTimeout: 6e5,
220
+ ...ca === void 0 ? {} : { connect: { ca } }
217
221
  }).compose(multiplexHttp2Requests);
218
222
  })();
219
223
  sharedDispatchers.set(key, dispatcher);
@@ -222,10 +226,15 @@ function getSharedDispatcher(baseUrl, apiKey) {
222
226
  });
223
227
  return dispatcher;
224
228
  }
225
- function createPooledFetch(baseUrl, apiKey) {
226
- if (!isNodeRuntime()) return void 0;
229
+ function createPooledFetch(baseUrl, apiKey, tls) {
230
+ if (!isNodeRuntime()) {
231
+ if (tls?.ca !== void 0) throw new Error("Custom TLS CAs require Node.js");
232
+ return;
233
+ }
234
+ const ca = tls?.ca === void 0 ? void 0 : (Array.isArray(tls.ca) ? tls.ca : [tls.ca]).map((cert) => Buffer.from(cert));
235
+ const key = dispatcherKey(baseUrl, apiKey, ca);
227
236
  return async (request) => {
228
- const dispatcher = await getSharedDispatcher(baseUrl, apiKey);
237
+ const dispatcher = await getSharedDispatcher(key, ca);
229
238
  return globalThis.fetch(request, { dispatcher });
230
239
  };
231
240
  }
@@ -234,7 +243,7 @@ function createApiClient(opts) {
234
243
  const apiKey = `key-${opts.apiKey.replace(/^key-/, "")}`;
235
244
  return createClient({
236
245
  baseUrl,
237
- fetch: createPooledFetch(baseUrl, apiKey),
246
+ fetch: createPooledFetch(baseUrl, apiKey, opts.tls),
238
247
  headers: {
239
248
  Authorization: apiKey,
240
249
  "User-Agent": USER_AGENT
@@ -1853,6 +1862,14 @@ function toError(error) {
1853
1862
  }
1854
1863
  //#endregion
1855
1864
  //#region src/sandbox.ts
1865
+ function portTokenFromWire(data) {
1866
+ return {
1867
+ id: data.id,
1868
+ port: data.port,
1869
+ createdAt: new Date(data.created_at),
1870
+ expiresAt: data.expires_at ? new Date(data.expires_at) : void 0
1871
+ };
1872
+ }
1856
1873
  const POLL_INTERVAL_MS = 500;
1857
1874
  function sleep() {
1858
1875
  return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
@@ -1874,6 +1891,7 @@ var Sandbox = class Sandbox {
1874
1891
  finishedAt;
1875
1892
  lastActiveAt;
1876
1893
  exitReason;
1894
+ checkpoint;
1877
1895
  processes;
1878
1896
  files;
1879
1897
  /** @internal */
@@ -1903,6 +1921,7 @@ var Sandbox = class Sandbox {
1903
1921
  this.finishedAt = data.finished_at ? new Date(data.finished_at) : void 0;
1904
1922
  this.lastActiveAt = new Date(data.last_active_at);
1905
1923
  this.exitReason = data.exit_reason;
1924
+ this.checkpoint = data.checkpoint;
1906
1925
  return this;
1907
1926
  }
1908
1927
  toJSON() {
@@ -1922,7 +1941,8 @@ var Sandbox = class Sandbox {
1922
1941
  runningAt: this.runningAt,
1923
1942
  finishedAt: this.finishedAt,
1924
1943
  lastActiveAt: this.lastActiveAt,
1925
- exitReason: this.exitReason
1944
+ exitReason: this.exitReason,
1945
+ checkpoint: this.checkpoint
1926
1946
  };
1927
1947
  }
1928
1948
  /** Run a process and wait for it to exit. */
@@ -1964,17 +1984,36 @@ var Sandbox = class Sandbox {
1964
1984
  this._apply(data);
1965
1985
  return options.wait === false ? this : waitForSandboxStart(this);
1966
1986
  }
1967
- /** Create an isolated writable branch from this sandbox's current state. */
1987
+ /**
1988
+ * Create an isolated writable branch from this sandbox's current state.
1989
+ * A running sandbox is paused for the snapshot and resumed once the fork is
1990
+ * accepted; a paused or stopped sandbox is left as it is. The fork names the
1991
+ * checkpoint the pause returned, so it does not depend on the source still
1992
+ * being paused when the request lands. Resuming the source is best effort:
1993
+ * the child is returned even if the source could not be resumed, so check
1994
+ * the source's status afterwards if that matters.
1995
+ */
1968
1996
  async fork(options = {}) {
1969
- const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/fork", {
1997
+ const paused = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }), "transient"));
1998
+ this._apply(paused);
1999
+ const resumeAfterFork = this.status === "pausing";
2000
+ const checkpoint = this.checkpoint;
2001
+ const wait = resumeAfterFork ? false : options.wait ?? true;
2002
+ const body = {
2003
+ name: options.name,
2004
+ checkpoint
2005
+ };
2006
+ const fork = await waitWhileSandboxStatus(this, "pausing").then(() => unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/fork", {
1970
2007
  params: {
1971
2008
  path: { sid: this.id },
1972
- query: { wait: options.wait ?? true }
2009
+ query: { wait }
1973
2010
  },
1974
- body: options.name === void 0 ? void 0 : { name: options.name }
1975
- }), "connect"));
1976
- const fork = new Sandbox(data, this._client);
1977
- return options.wait === false ? fork : waitForSandboxStart(fork);
2011
+ body
2012
+ }), "connect"))).then((data) => new Sandbox(data, this._client)).finally(() => resumeAfterFork ? this.resume({ wait: false }).catch(() => void 0) : void 0);
2013
+ if (options.wait === false) return fork;
2014
+ await waitForSandboxStart(fork);
2015
+ if (resumeAfterFork) await waitForSandboxStart(this).catch(() => void 0);
2016
+ return fork;
1978
2017
  }
1979
2018
  /** Expose a TCP port publicly (1–65535), returning its hostname. */
1980
2019
  async exposePort(port) {
@@ -1997,6 +2036,66 @@ var Sandbox = class Sandbox {
1997
2036
  port
1998
2037
  } } }), "transient"));
1999
2038
  }
2039
+ /** Authorize HTTP access to one port without making it public. */
2040
+ async createPortToken(port, options = {}) {
2041
+ const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/port-tokens", {
2042
+ params: { path: { sid: this.id } },
2043
+ body: {
2044
+ port,
2045
+ ttl: options.ttl
2046
+ }
2047
+ }), "connect"));
2048
+ return {
2049
+ ...portTokenFromWire(data),
2050
+ hostname: data.hostname,
2051
+ token: data.token
2052
+ };
2053
+ }
2054
+ /** Get token metadata. Expired and revoked tokens return not found. */
2055
+ async getPortToken(tokenId) {
2056
+ return portTokenFromWire(await unwrap(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}/port-tokens/{token_id}", { params: { path: {
2057
+ sid: this.id,
2058
+ token_id: tokenId
2059
+ } } }), "transient")));
2060
+ }
2061
+ /** List token metadata across pages. `limit` caps the total number returned. */
2062
+ async listPortTokens(options = {}) {
2063
+ const tokens = [];
2064
+ let cursor = options.cursor;
2065
+ for (;;) {
2066
+ const remaining = options.limit === void 0 ? void 0 : options.limit - tokens.length;
2067
+ if (remaining !== void 0 && remaining <= 0) return tokens;
2068
+ const page = await this.listPortTokensPage({
2069
+ limit: remaining === void 0 ? 100 : Math.min(remaining, 100),
2070
+ cursor
2071
+ });
2072
+ tokens.push(...page.tokens);
2073
+ if (!page.nextCursor) return tokens;
2074
+ cursor = page.nextCursor;
2075
+ }
2076
+ }
2077
+ /** Fetch one page of token metadata; pass `nextCursor` back as `cursor`. */
2078
+ async listPortTokensPage(options = {}) {
2079
+ const { data, nextCursor } = await unwrapPage(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}/port-tokens", { params: {
2080
+ path: { sid: this.id },
2081
+ query: {
2082
+ limit: options.limit ?? 100,
2083
+ cursor: options.cursor
2084
+ }
2085
+ } }), "transient"));
2086
+ return {
2087
+ tokens: data.tokens.map(portTokenFromWire),
2088
+ nextCursor
2089
+ };
2090
+ }
2091
+ /** Revoke a token for new connections. Existing connections remain open. */
2092
+ async deletePortToken(token) {
2093
+ const tokenId = typeof token === "string" ? token : token.id;
2094
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/sandboxes/{sid}/port-tokens/{token_id}", { params: { path: {
2095
+ sid: this.id,
2096
+ token_id: tokenId
2097
+ } } }), "transient"));
2098
+ }
2000
2099
  /** Get this running sandbox's effective network policy. */
2001
2100
  async getNetwork() {
2002
2101
  const client = this._client;
@@ -2095,7 +2194,7 @@ var Tokens = class {
2095
2194
  return await unwrap(this._client.POST("/api/tokens", { body: req }));
2096
2195
  }
2097
2196
  async delete(id) {
2098
- await unwrapEmpty(this._client.DELETE("/api/tokens/{id}", { params: { path: { id } } }));
2197
+ await unwrapEmpty(this._client.DELETE("/api/tokens/{tokenId}", { params: { path: { tokenId: id } } }));
2099
2198
  }
2100
2199
  };
2101
2200
  //#endregion
@@ -2371,7 +2470,8 @@ var Archil = class {
2371
2470
  const client = createApiClient({
2372
2471
  apiKey,
2373
2472
  region,
2374
- baseUrl: controlBaseUrl
2473
+ baseUrl: controlBaseUrl,
2474
+ tls: opts.tls
2375
2475
  });
2376
2476
  const s3BaseUrl = opts.s3BaseUrl ?? envVar("ARCHIL_S3_BASE_URL") ?? deriveS3BaseUrl(controlBaseUrl);
2377
2477
  this._client = client;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as S3Mount, A as ApiTokenResponse, B as DiskStatus, C as PutObjectOptions, D as ShareUrlResult, E as ShareUrlOptions, F as CreateApiTokenRequest, G as GrepMatch, H as ExecDiskResult, I as CreateDiskRequest, J as MountConfigResponse, K as GrepStoppedReason, L as Delegation, M as AwsStsUser, N as AzureBlobMount, O as UploadPart, P as ConnectedClient, Q as S3CompatibleMount, R as DiskMetrics, S as PosixCreateAttrs, T as S3Object, U as ExecRequest, V as DiskUser, W as GCSMount, X as R2Mount, Y as MountResponse, Z as RootAttrs, _ as MultipartUploadListing, a as DeleteObjectsResult, b as PartInfo, c as ExecResult, d as ListMultipartUploadsOptions, et as TokenUser, f as ListObjectsOptions, g as MultipartUpload, h as MountOptions, i as DeleteObjectsOptions, j as AuthorizedUser, k as effectiveUploadPartSize, l as GrepOptions, m as ListPartsOptions, n as CompletedMultipartUpload, nt as ApiClient, o as Disk, p as ListObjectsResult, q as MountConfig, r as DeleteObjectsError, s as DiskMultipart, t as AppendObjectOptions, tt as FileSystem, u as GrepResult, v as MultipartUploadSummary, w as PutObjectResult, x as PartListing, y as ObjectMetadata, z as DiskResponse } from "./disk-CiLNoFCd.cjs";
1
+ import { $ as S3Mount, A as ApiTokenResponse, B as DiskStatus, C as PutObjectOptions, D as ShareUrlResult, E as ShareUrlOptions, F as CreateApiTokenRequest, G as GrepMatch, H as ExecDiskResult, I as CreateDiskRequest, J as MountConfigResponse, K as GrepStoppedReason, L as Delegation, M as AwsStsUser, N as AzureBlobMount, O as UploadPart, P as ConnectedClient, Q as S3CompatibleMount, R as DiskMetrics, S as PosixCreateAttrs, T as S3Object, U as ExecRequest, V as DiskUser, W as GCSMount, X as R2Mount, Y as MountResponse, Z as RootAttrs, _ as MultipartUploadListing, a as DeleteObjectsResult, b as PartInfo, c as ExecResult, d as ListMultipartUploadsOptions, et as TokenUser, f as ListObjectsOptions, g as MultipartUpload, h as MountOptions, i as DeleteObjectsOptions, j as AuthorizedUser, k as effectiveUploadPartSize, l as GrepOptions, m as ListPartsOptions, n as CompletedMultipartUpload, nt as ApiClient, o as Disk, p as ListObjectsResult, q as MountConfig, r as DeleteObjectsError, rt as ArchilTlsOptions, s as DiskMultipart, t as AppendObjectOptions, tt as FileSystem, u as GrepResult, v as MultipartUploadSummary, w as PutObjectResult, x as PartListing, y as ObjectMetadata, z as DiskResponse } from "./disk-iq-QAbnz.cjs";
2
2
  import { components } from "@archildata/api-types";
3
3
 
4
4
  //#region src/disks.d.ts
@@ -209,6 +209,30 @@ interface SandboxEndpoint {
209
209
  port: number;
210
210
  hostname: string;
211
211
  }
212
+ /** Port-token metadata. The secret and hostname are returned only on creation. */
213
+ interface SandboxPortToken {
214
+ id: string;
215
+ port: number;
216
+ createdAt: Date;
217
+ expiresAt?: Date;
218
+ }
219
+ interface CreatedSandboxPortToken extends SandboxPortToken {
220
+ hostname: string;
221
+ /** Send in X-Archil-Token. Save it now; it cannot be retrieved again. */
222
+ token: string;
223
+ }
224
+ interface CreateSandboxPortTokenOptions {
225
+ /** Duration such as "1h" or "30m", up to "8760h" (365 days). Omit for no expiration. */
226
+ ttl?: string;
227
+ }
228
+ interface ListSandboxPortTokensOptions {
229
+ limit?: number;
230
+ cursor?: string;
231
+ }
232
+ interface SandboxPortTokenPage {
233
+ tokens: SandboxPortToken[];
234
+ nextCursor?: string;
235
+ }
212
236
  interface SandboxResponse {
213
237
  id: string;
214
238
  name: string;
@@ -227,6 +251,8 @@ interface SandboxResponse {
227
251
  finishedAt?: Date;
228
252
  lastActiveAt: Date;
229
253
  exitReason?: string;
254
+ /** Disk checkpoint the current session leaves behind; present while pausing, paused, stopping, or stopped. */
255
+ checkpoint?: string;
230
256
  }
231
257
  interface SandboxWaitOptions {
232
258
  /**
@@ -262,6 +288,7 @@ declare class Sandbox {
262
288
  finishedAt?: Date;
263
289
  lastActiveAt: Date;
264
290
  exitReason?: string;
291
+ checkpoint?: string;
265
292
  readonly processes: SandboxProcesses;
266
293
  readonly files: SandboxFiles;
267
294
  /** @internal */
@@ -283,7 +310,15 @@ declare class Sandbox {
283
310
  pause(options?: SandboxWaitOptions): Promise<Sandbox | this>;
284
311
  /** Resume this sandbox from its preserved CPU and memory state. */
285
312
  resume(options?: SandboxWaitOptions): Promise<Sandbox | this>;
286
- /** Create an isolated writable branch from this sandbox's current state. */
313
+ /**
314
+ * Create an isolated writable branch from this sandbox's current state.
315
+ * A running sandbox is paused for the snapshot and resumed once the fork is
316
+ * accepted; a paused or stopped sandbox is left as it is. The fork names the
317
+ * checkpoint the pause returned, so it does not depend on the source still
318
+ * being paused when the request lands. Resuming the source is best effort:
319
+ * the child is returned even if the source could not be resumed, so check
320
+ * the source's status afterwards if that matters.
321
+ */
287
322
  fork(options?: SandboxForkOptions): Promise<Sandbox>;
288
323
  /** Expose a TCP port publicly (1–65535), returning its hostname. */
289
324
  exposePort(port: number): Promise<string>;
@@ -291,6 +326,16 @@ declare class Sandbox {
291
326
  listPorts(): Promise<SandboxEndpoint[]>;
292
327
  /** Remove explicit public exposure. A service publishing the same port remains reachable. */
293
328
  unexposePort(port: number): Promise<void>;
329
+ /** Authorize HTTP access to one port without making it public. */
330
+ createPortToken(port: number, options?: CreateSandboxPortTokenOptions): Promise<CreatedSandboxPortToken>;
331
+ /** Get token metadata. Expired and revoked tokens return not found. */
332
+ getPortToken(tokenId: string): Promise<SandboxPortToken>;
333
+ /** List token metadata across pages. `limit` caps the total number returned. */
334
+ listPortTokens(options?: ListSandboxPortTokensOptions): Promise<SandboxPortToken[]>;
335
+ /** Fetch one page of token metadata; pass `nextCursor` back as `cursor`. */
336
+ listPortTokensPage(options?: ListSandboxPortTokensOptions): Promise<SandboxPortTokenPage>;
337
+ /** Revoke a token for new connections. Existing connections remain open. */
338
+ deletePortToken(token: SandboxPortToken | string): Promise<void>;
294
339
  /** Get this running sandbox's effective network policy. */
295
340
  getNetwork(): Promise<SandboxNetwork>;
296
341
  /** Replace this running sandbox's complete network policy and return the effective policy. */
@@ -427,6 +472,8 @@ interface ArchilOptions {
427
472
  * control plane URL with its `control.` hostname prefix swapped for `s3.`.
428
473
  */
429
474
  s3BaseUrl?: string;
475
+ /** Per-client TLS trust for control-plane and S3 requests (Node.js only). */
476
+ tls?: ArchilTlsOptions;
430
477
  }
431
478
  /**
432
479
  * Options that apply to a single mounted disk in an exec request.
@@ -585,4 +632,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
585
632
  */
586
633
  declare function workspace(mounts: Record<string, ExecMount>): Workspace;
587
634
  //#endregion
588
- export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxRequest, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
635
+ export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as S3Mount, A as ApiTokenResponse, B as DiskStatus, C as PutObjectOptions, D as ShareUrlResult, E as ShareUrlOptions, F as CreateApiTokenRequest, G as GrepMatch, H as ExecDiskResult, I as CreateDiskRequest, J as MountConfigResponse, K as GrepStoppedReason, L as Delegation, M as AwsStsUser, N as AzureBlobMount, O as UploadPart, P as ConnectedClient, Q as S3CompatibleMount, R as DiskMetrics, S as PosixCreateAttrs, T as S3Object, U as ExecRequest, V as DiskUser, W as GCSMount, X as R2Mount, Y as MountResponse, Z as RootAttrs, _ as MultipartUploadListing, a as DeleteObjectsResult, b as PartInfo, c as ExecResult, d as ListMultipartUploadsOptions, et as TokenUser, f as ListObjectsOptions, g as MultipartUpload, h as MountOptions, i as DeleteObjectsOptions, j as AuthorizedUser, k as effectiveUploadPartSize, l as GrepOptions, m as ListPartsOptions, n as CompletedMultipartUpload, nt as ApiClient, o as Disk, p as ListObjectsResult, q as MountConfig, r as DeleteObjectsError, s as DiskMultipart, t as AppendObjectOptions, tt as FileSystem, u as GrepResult, v as MultipartUploadSummary, w as PutObjectResult, x as PartListing, y as ObjectMetadata, z as DiskResponse } from "./disk-CiLNoFCd.mjs";
1
+ import { $ as S3Mount, A as ApiTokenResponse, B as DiskStatus, C as PutObjectOptions, D as ShareUrlResult, E as ShareUrlOptions, F as CreateApiTokenRequest, G as GrepMatch, H as ExecDiskResult, I as CreateDiskRequest, J as MountConfigResponse, K as GrepStoppedReason, L as Delegation, M as AwsStsUser, N as AzureBlobMount, O as UploadPart, P as ConnectedClient, Q as S3CompatibleMount, R as DiskMetrics, S as PosixCreateAttrs, T as S3Object, U as ExecRequest, V as DiskUser, W as GCSMount, X as R2Mount, Y as MountResponse, Z as RootAttrs, _ as MultipartUploadListing, a as DeleteObjectsResult, b as PartInfo, c as ExecResult, d as ListMultipartUploadsOptions, et as TokenUser, f as ListObjectsOptions, g as MultipartUpload, h as MountOptions, i as DeleteObjectsOptions, j as AuthorizedUser, k as effectiveUploadPartSize, l as GrepOptions, m as ListPartsOptions, n as CompletedMultipartUpload, nt as ApiClient, o as Disk, p as ListObjectsResult, q as MountConfig, r as DeleteObjectsError, rt as ArchilTlsOptions, s as DiskMultipart, t as AppendObjectOptions, tt as FileSystem, u as GrepResult, v as MultipartUploadSummary, w as PutObjectResult, x as PartListing, y as ObjectMetadata, z as DiskResponse } from "./disk-iq-QAbnz.mjs";
2
2
  import { components } from "@archildata/api-types";
3
3
 
4
4
  //#region src/disks.d.ts
@@ -209,6 +209,30 @@ interface SandboxEndpoint {
209
209
  port: number;
210
210
  hostname: string;
211
211
  }
212
+ /** Port-token metadata. The secret and hostname are returned only on creation. */
213
+ interface SandboxPortToken {
214
+ id: string;
215
+ port: number;
216
+ createdAt: Date;
217
+ expiresAt?: Date;
218
+ }
219
+ interface CreatedSandboxPortToken extends SandboxPortToken {
220
+ hostname: string;
221
+ /** Send in X-Archil-Token. Save it now; it cannot be retrieved again. */
222
+ token: string;
223
+ }
224
+ interface CreateSandboxPortTokenOptions {
225
+ /** Duration such as "1h" or "30m", up to "8760h" (365 days). Omit for no expiration. */
226
+ ttl?: string;
227
+ }
228
+ interface ListSandboxPortTokensOptions {
229
+ limit?: number;
230
+ cursor?: string;
231
+ }
232
+ interface SandboxPortTokenPage {
233
+ tokens: SandboxPortToken[];
234
+ nextCursor?: string;
235
+ }
212
236
  interface SandboxResponse {
213
237
  id: string;
214
238
  name: string;
@@ -227,6 +251,8 @@ interface SandboxResponse {
227
251
  finishedAt?: Date;
228
252
  lastActiveAt: Date;
229
253
  exitReason?: string;
254
+ /** Disk checkpoint the current session leaves behind; present while pausing, paused, stopping, or stopped. */
255
+ checkpoint?: string;
230
256
  }
231
257
  interface SandboxWaitOptions {
232
258
  /**
@@ -262,6 +288,7 @@ declare class Sandbox {
262
288
  finishedAt?: Date;
263
289
  lastActiveAt: Date;
264
290
  exitReason?: string;
291
+ checkpoint?: string;
265
292
  readonly processes: SandboxProcesses;
266
293
  readonly files: SandboxFiles;
267
294
  /** @internal */
@@ -283,7 +310,15 @@ declare class Sandbox {
283
310
  pause(options?: SandboxWaitOptions): Promise<Sandbox | this>;
284
311
  /** Resume this sandbox from its preserved CPU and memory state. */
285
312
  resume(options?: SandboxWaitOptions): Promise<Sandbox | this>;
286
- /** Create an isolated writable branch from this sandbox's current state. */
313
+ /**
314
+ * Create an isolated writable branch from this sandbox's current state.
315
+ * A running sandbox is paused for the snapshot and resumed once the fork is
316
+ * accepted; a paused or stopped sandbox is left as it is. The fork names the
317
+ * checkpoint the pause returned, so it does not depend on the source still
318
+ * being paused when the request lands. Resuming the source is best effort:
319
+ * the child is returned even if the source could not be resumed, so check
320
+ * the source's status afterwards if that matters.
321
+ */
287
322
  fork(options?: SandboxForkOptions): Promise<Sandbox>;
288
323
  /** Expose a TCP port publicly (1–65535), returning its hostname. */
289
324
  exposePort(port: number): Promise<string>;
@@ -291,6 +326,16 @@ declare class Sandbox {
291
326
  listPorts(): Promise<SandboxEndpoint[]>;
292
327
  /** Remove explicit public exposure. A service publishing the same port remains reachable. */
293
328
  unexposePort(port: number): Promise<void>;
329
+ /** Authorize HTTP access to one port without making it public. */
330
+ createPortToken(port: number, options?: CreateSandboxPortTokenOptions): Promise<CreatedSandboxPortToken>;
331
+ /** Get token metadata. Expired and revoked tokens return not found. */
332
+ getPortToken(tokenId: string): Promise<SandboxPortToken>;
333
+ /** List token metadata across pages. `limit` caps the total number returned. */
334
+ listPortTokens(options?: ListSandboxPortTokensOptions): Promise<SandboxPortToken[]>;
335
+ /** Fetch one page of token metadata; pass `nextCursor` back as `cursor`. */
336
+ listPortTokensPage(options?: ListSandboxPortTokensOptions): Promise<SandboxPortTokenPage>;
337
+ /** Revoke a token for new connections. Existing connections remain open. */
338
+ deletePortToken(token: SandboxPortToken | string): Promise<void>;
294
339
  /** Get this running sandbox's effective network policy. */
295
340
  getNetwork(): Promise<SandboxNetwork>;
296
341
  /** Replace this running sandbox's complete network policy and return the effective policy. */
@@ -427,6 +472,8 @@ interface ArchilOptions {
427
472
  * control plane URL with its `control.` hostname prefix swapped for `s3.`.
428
473
  */
429
474
  s3BaseUrl?: string;
475
+ /** Per-client TLS trust for control-plane and S3 requests (Node.js only). */
476
+ tls?: ArchilTlsOptions;
430
477
  }
431
478
  /**
432
479
  * Options that apply to a single mounted disk in an exec request.
@@ -585,4 +632,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
585
632
  */
586
633
  declare function workspace(mounts: Record<string, ExecMount>): Workspace;
587
634
  //#endregion
588
- export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxRequest, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
635
+ export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type ArchilTlsOptions, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as ArchilS3Error, C as DiskMultipart, E as VERSION, O as ArchilApiError, S as Disk, T as USER_AGENT, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as SandboxFileTransferError, k as ArchilError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as effectiveUploadPartSize, x as Disks, y as SandboxProcess } from "./src-Crk5lxKW.mjs";
1
+ import { A as ArchilS3Error, C as DiskMultipart, E as VERSION, O as ArchilApiError, S as Disk, T as USER_AGENT, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as SandboxFileTransferError, k as ArchilError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as effectiveUploadPartSize, x as Disks, y as SandboxProcess } from "./src-BaAv98od.mjs";
2
2
  export { Archil, ArchilApiError, ArchilError, ArchilS3Error, Disk, DiskMultipart, Disks, Sandbox, SandboxFileTransferError, SandboxFiles, SandboxProcess, SandboxProcesses, Sandboxes, Tokens, USER_AGENT, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
@@ -1,4 +1,4 @@
1
- import { tt as FileSystem } from "../disk-CiLNoFCd.cjs";
1
+ import { tt as FileSystem } from "../disk-iq-QAbnz.cjs";
2
2
  import { ZodType, z } from "zod";
3
3
 
4
4
  //#region src/internal/tools.d.ts
@@ -1,4 +1,4 @@
1
- import { tt as FileSystem } from "../disk-CiLNoFCd.mjs";
1
+ import { tt as FileSystem } from "../disk-iq-QAbnz.mjs";
2
2
  import { ZodType, z } from "zod";
3
3
 
4
4
  //#region src/internal/tools.d.ts
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { O as ArchilApiError, p as Archil } from "./src-Crk5lxKW.mjs";
3
- import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-DQS29KQU.mjs";
2
+ import { O as ArchilApiError, p as Archil } from "./src-BaAv98od.mjs";
3
+ import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-D2ic5Rit.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { Command } from "commander";
6
6
  import { spinner } from "@clack/prompts";
@@ -122,7 +122,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
122
122
  }
123
123
  //#endregion
124
124
  //#region src/version.ts
125
- const VERSION = "1.2.0";
125
+ const VERSION = "1.4.0";
126
126
  const USER_AGENT = `archil-js/${VERSION}`;
127
127
  //#endregion
128
128
  //#region src/client.ts
@@ -175,11 +175,14 @@ const multiplexHttp2Requests = (dispatch) => (options, handler) => {
175
175
  return true;
176
176
  };
177
177
  const sharedDispatchers = /* @__PURE__ */ new Map();
178
- function dispatcherKey(baseUrl, apiKey) {
179
- return `${new URL(baseUrl).origin}\0${apiKey}`;
180
- }
181
- function getSharedDispatcher(baseUrl, apiKey) {
182
- const key = dispatcherKey(baseUrl, apiKey);
178
+ function dispatcherKey(baseUrl, apiKey, ca) {
179
+ return JSON.stringify([
180
+ new URL(baseUrl).origin,
181
+ apiKey,
182
+ ca?.map((cert) => cert.toString("base64"))
183
+ ]);
184
+ }
185
+ function getSharedDispatcher(key, ca) {
183
186
  const existing = sharedDispatchers.get(key);
184
187
  if (existing) return existing;
185
188
  const dispatcher = (async () => {
@@ -190,7 +193,8 @@ function getSharedDispatcher(baseUrl, apiKey) {
190
193
  connections: CONTROL_PLANE_CONNECTIONS,
191
194
  pipelining: CONTROL_PLANE_CONCURRENT_STREAMS,
192
195
  keepAliveTimeout: 6e4,
193
- keepAliveMaxTimeout: 6e5
196
+ keepAliveMaxTimeout: 6e5,
197
+ ...ca === void 0 ? {} : { connect: { ca } }
194
198
  }).compose(multiplexHttp2Requests);
195
199
  })();
196
200
  sharedDispatchers.set(key, dispatcher);
@@ -199,10 +203,15 @@ function getSharedDispatcher(baseUrl, apiKey) {
199
203
  });
200
204
  return dispatcher;
201
205
  }
202
- function createPooledFetch(baseUrl, apiKey) {
203
- if (!isNodeRuntime()) return void 0;
206
+ function createPooledFetch(baseUrl, apiKey, tls) {
207
+ if (!isNodeRuntime()) {
208
+ if (tls?.ca !== void 0) throw new Error("Custom TLS CAs require Node.js");
209
+ return;
210
+ }
211
+ const ca = tls?.ca === void 0 ? void 0 : (Array.isArray(tls.ca) ? tls.ca : [tls.ca]).map((cert) => Buffer.from(cert));
212
+ const key = dispatcherKey(baseUrl, apiKey, ca);
204
213
  return async (request) => {
205
- const dispatcher = await getSharedDispatcher(baseUrl, apiKey);
214
+ const dispatcher = await getSharedDispatcher(key, ca);
206
215
  return globalThis.fetch(request, { dispatcher });
207
216
  };
208
217
  }
@@ -211,7 +220,7 @@ function createApiClient(opts) {
211
220
  const apiKey = `key-${opts.apiKey.replace(/^key-/, "")}`;
212
221
  return createClient({
213
222
  baseUrl,
214
- fetch: createPooledFetch(baseUrl, apiKey),
223
+ fetch: createPooledFetch(baseUrl, apiKey, opts.tls),
215
224
  headers: {
216
225
  Authorization: apiKey,
217
226
  "User-Agent": USER_AGENT
@@ -1830,6 +1839,14 @@ function toError(error) {
1830
1839
  }
1831
1840
  //#endregion
1832
1841
  //#region src/sandbox.ts
1842
+ function portTokenFromWire(data) {
1843
+ return {
1844
+ id: data.id,
1845
+ port: data.port,
1846
+ createdAt: new Date(data.created_at),
1847
+ expiresAt: data.expires_at ? new Date(data.expires_at) : void 0
1848
+ };
1849
+ }
1833
1850
  const POLL_INTERVAL_MS = 500;
1834
1851
  function sleep() {
1835
1852
  return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
@@ -1851,6 +1868,7 @@ var Sandbox = class Sandbox {
1851
1868
  finishedAt;
1852
1869
  lastActiveAt;
1853
1870
  exitReason;
1871
+ checkpoint;
1854
1872
  processes;
1855
1873
  files;
1856
1874
  /** @internal */
@@ -1880,6 +1898,7 @@ var Sandbox = class Sandbox {
1880
1898
  this.finishedAt = data.finished_at ? new Date(data.finished_at) : void 0;
1881
1899
  this.lastActiveAt = new Date(data.last_active_at);
1882
1900
  this.exitReason = data.exit_reason;
1901
+ this.checkpoint = data.checkpoint;
1883
1902
  return this;
1884
1903
  }
1885
1904
  toJSON() {
@@ -1899,7 +1918,8 @@ var Sandbox = class Sandbox {
1899
1918
  runningAt: this.runningAt,
1900
1919
  finishedAt: this.finishedAt,
1901
1920
  lastActiveAt: this.lastActiveAt,
1902
- exitReason: this.exitReason
1921
+ exitReason: this.exitReason,
1922
+ checkpoint: this.checkpoint
1903
1923
  };
1904
1924
  }
1905
1925
  /** Run a process and wait for it to exit. */
@@ -1941,17 +1961,36 @@ var Sandbox = class Sandbox {
1941
1961
  this._apply(data);
1942
1962
  return options.wait === false ? this : waitForSandboxStart(this);
1943
1963
  }
1944
- /** Create an isolated writable branch from this sandbox's current state. */
1964
+ /**
1965
+ * Create an isolated writable branch from this sandbox's current state.
1966
+ * A running sandbox is paused for the snapshot and resumed once the fork is
1967
+ * accepted; a paused or stopped sandbox is left as it is. The fork names the
1968
+ * checkpoint the pause returned, so it does not depend on the source still
1969
+ * being paused when the request lands. Resuming the source is best effort:
1970
+ * the child is returned even if the source could not be resumed, so check
1971
+ * the source's status afterwards if that matters.
1972
+ */
1945
1973
  async fork(options = {}) {
1946
- const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/fork", {
1974
+ const paused = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }), "transient"));
1975
+ this._apply(paused);
1976
+ const resumeAfterFork = this.status === "pausing";
1977
+ const checkpoint = this.checkpoint;
1978
+ const wait = resumeAfterFork ? false : options.wait ?? true;
1979
+ const body = {
1980
+ name: options.name,
1981
+ checkpoint
1982
+ };
1983
+ const fork = await waitWhileSandboxStatus(this, "pausing").then(() => unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/fork", {
1947
1984
  params: {
1948
1985
  path: { sid: this.id },
1949
- query: { wait: options.wait ?? true }
1986
+ query: { wait }
1950
1987
  },
1951
- body: options.name === void 0 ? void 0 : { name: options.name }
1952
- }), "connect"));
1953
- const fork = new Sandbox(data, this._client);
1954
- return options.wait === false ? fork : waitForSandboxStart(fork);
1988
+ body
1989
+ }), "connect"))).then((data) => new Sandbox(data, this._client)).finally(() => resumeAfterFork ? this.resume({ wait: false }).catch(() => void 0) : void 0);
1990
+ if (options.wait === false) return fork;
1991
+ await waitForSandboxStart(fork);
1992
+ if (resumeAfterFork) await waitForSandboxStart(this).catch(() => void 0);
1993
+ return fork;
1955
1994
  }
1956
1995
  /** Expose a TCP port publicly (1–65535), returning its hostname. */
1957
1996
  async exposePort(port) {
@@ -1974,6 +2013,66 @@ var Sandbox = class Sandbox {
1974
2013
  port
1975
2014
  } } }), "transient"));
1976
2015
  }
2016
+ /** Authorize HTTP access to one port without making it public. */
2017
+ async createPortToken(port, options = {}) {
2018
+ const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/port-tokens", {
2019
+ params: { path: { sid: this.id } },
2020
+ body: {
2021
+ port,
2022
+ ttl: options.ttl
2023
+ }
2024
+ }), "connect"));
2025
+ return {
2026
+ ...portTokenFromWire(data),
2027
+ hostname: data.hostname,
2028
+ token: data.token
2029
+ };
2030
+ }
2031
+ /** Get token metadata. Expired and revoked tokens return not found. */
2032
+ async getPortToken(tokenId) {
2033
+ return portTokenFromWire(await unwrap(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}/port-tokens/{token_id}", { params: { path: {
2034
+ sid: this.id,
2035
+ token_id: tokenId
2036
+ } } }), "transient")));
2037
+ }
2038
+ /** List token metadata across pages. `limit` caps the total number returned. */
2039
+ async listPortTokens(options = {}) {
2040
+ const tokens = [];
2041
+ let cursor = options.cursor;
2042
+ for (;;) {
2043
+ const remaining = options.limit === void 0 ? void 0 : options.limit - tokens.length;
2044
+ if (remaining !== void 0 && remaining <= 0) return tokens;
2045
+ const page = await this.listPortTokensPage({
2046
+ limit: remaining === void 0 ? 100 : Math.min(remaining, 100),
2047
+ cursor
2048
+ });
2049
+ tokens.push(...page.tokens);
2050
+ if (!page.nextCursor) return tokens;
2051
+ cursor = page.nextCursor;
2052
+ }
2053
+ }
2054
+ /** Fetch one page of token metadata; pass `nextCursor` back as `cursor`. */
2055
+ async listPortTokensPage(options = {}) {
2056
+ const { data, nextCursor } = await unwrapPage(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}/port-tokens", { params: {
2057
+ path: { sid: this.id },
2058
+ query: {
2059
+ limit: options.limit ?? 100,
2060
+ cursor: options.cursor
2061
+ }
2062
+ } }), "transient"));
2063
+ return {
2064
+ tokens: data.tokens.map(portTokenFromWire),
2065
+ nextCursor
2066
+ };
2067
+ }
2068
+ /** Revoke a token for new connections. Existing connections remain open. */
2069
+ async deletePortToken(token) {
2070
+ const tokenId = typeof token === "string" ? token : token.id;
2071
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/sandboxes/{sid}/port-tokens/{token_id}", { params: { path: {
2072
+ sid: this.id,
2073
+ token_id: tokenId
2074
+ } } }), "transient"));
2075
+ }
1977
2076
  /** Get this running sandbox's effective network policy. */
1978
2077
  async getNetwork() {
1979
2078
  const client = this._client;
@@ -2072,7 +2171,7 @@ var Tokens = class {
2072
2171
  return await unwrap(this._client.POST("/api/tokens", { body: req }));
2073
2172
  }
2074
2173
  async delete(id) {
2075
- await unwrapEmpty(this._client.DELETE("/api/tokens/{id}", { params: { path: { id } } }));
2174
+ await unwrapEmpty(this._client.DELETE("/api/tokens/{tokenId}", { params: { path: { tokenId: id } } }));
2076
2175
  }
2077
2176
  };
2078
2177
  //#endregion
@@ -2348,7 +2447,8 @@ var Archil = class {
2348
2447
  const client = createApiClient({
2349
2448
  apiKey,
2350
2449
  region,
2351
- baseUrl: controlBaseUrl
2450
+ baseUrl: controlBaseUrl,
2451
+ tls: opts.tls
2352
2452
  });
2353
2453
  const s3BaseUrl = opts.s3BaseUrl ?? envVar("ARCHIL_S3_BASE_URL") ?? deriveS3BaseUrl(controlBaseUrl);
2354
2454
  this._client = client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disk",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Pure-JS client and CLIs for Archil disks and sandboxes",
5
5
  "keywords": [
6
6
  "archil",
@@ -40,7 +40,7 @@
40
40
  "LICENSE"
41
41
  ],
42
42
  "dependencies": {
43
- "@archildata/api-types": "^0.0.24",
43
+ "@archildata/api-types": "^0.0.40",
44
44
  "@clack/prompts": "^1.7.0",
45
45
  "commander": "^14.0.3",
46
46
  "fast-xml-parser": "^5.7.0",