@keska/sandbox 0.50.0 → 0.50.1

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/dist/index.d.ts CHANGED
@@ -6076,12 +6076,12 @@ declare class Sandbox$1 {
6076
6076
  missingOk?: boolean;
6077
6077
  signal?: AbortSignal;
6078
6078
  }): Promise<void>;
6079
- /** Named pin of the writable layer. Sleeps if Ready/Finished, pins, then wakes. */
6079
+ /** Named pin of the writable layer. The sandbox must already be sleeping. Call `sleep()` first. */
6080
6080
  snapshot(opts?: {
6081
6081
  name?: string;
6082
6082
  labels?: Record<string, string>;
6083
6083
  }): Promise<Snapshot>;
6084
- /** SDK glue: guest snap + N Create({ fromSnapshotId }). Not CreateMany. */
6084
+ /** SDK glue: guest snap + N Create({ fromSnapshotId }). Not CreateMany. The sandbox must already be sleeping. Call `sleep()` first. */
6085
6085
  clone(n?: number, opts?: {
6086
6086
  concurrency?: number;
6087
6087
  }): Promise<Sandbox$1[]>;
package/dist/index.js CHANGED
@@ -1343,15 +1343,46 @@ function resolveBaseUrl(explicit, credentialApiUrl = "") {
1343
1343
  }
1344
1344
  return DEFAULT_BASE_URL;
1345
1345
  }
1346
+ function labForwardBase(cpUrl) {
1347
+ let parsed;
1348
+ try {
1349
+ parsed = new URL(cpUrl);
1350
+ } catch {
1351
+ return "";
1352
+ }
1353
+ const host = parsed.hostname.toLowerCase();
1354
+ const scheme = parsed.protocol.replace(/:$/u, "") || "http";
1355
+ if ((host === "127.0.0.1" || host === "localhost") && parsed.port === "18080") {
1356
+ return `${scheme}://${host}:18082`;
1357
+ }
1358
+ return "";
1359
+ }
1346
1360
  function resolveForwardBaseUrl(cpUrl = "") {
1347
1361
  const explicit = (process.env.NUMEN_FORWARD_BASE_URL ?? "").trim();
1348
1362
  if (explicit) {
1349
1363
  return explicit.replace(/\/$/u, "");
1350
1364
  }
1351
- if (cpUrl.includes("keska.dev")) {
1365
+ const cp = cpUrl.trim();
1366
+ if (!cp) {
1367
+ return DEFAULT_FORWARD_BASE_URL;
1368
+ }
1369
+ const lab = labForwardBase(cp);
1370
+ if (lab) {
1371
+ return lab;
1372
+ }
1373
+ let host = "";
1374
+ try {
1375
+ host = new URL(cp).hostname.toLowerCase();
1376
+ } catch {
1377
+ host = "";
1378
+ }
1379
+ if (host === "keska.io" || host.endsWith(".keska.io")) {
1380
+ return DEFAULT_FORWARD_BASE_URL;
1381
+ }
1382
+ if (host === "keska.dev" || host.endsWith(".keska.dev")) {
1352
1383
  return "https://sbx.keska.dev";
1353
1384
  }
1354
- return DEFAULT_FORWARD_BASE_URL;
1385
+ throw new Error(`no guest URL for ${cp}. Set NUMEN_FORWARD_BASE_URL.`);
1355
1386
  }
1356
1387
  function guestOrigin(base, sandboxId, port, scheme) {
1357
1388
  const parsed = new URL(base);
@@ -5234,31 +5265,12 @@ var Sandbox = class _Sandbox {
5234
5265
  throw error;
5235
5266
  }
5236
5267
  }
5237
- /** Named pin of the writable layer. Sleeps if Ready/Finished, pins, then wakes. */
5268
+ /** Named pin of the writable layer. The sandbox must already be sleeping. Call `sleep()` first. */
5238
5269
  async snapshot(opts) {
5239
5270
  await this.get();
5240
- let sleeping = false;
5241
- if (this.status === "Ready" || this.status === "Finished") {
5242
- await this.sleep();
5243
- sleeping = true;
5244
- }
5245
- let snap;
5246
- try {
5247
- snap = await waitOverlayPublished(
5248
- () => this.wire.createSnapshot(this.id, { name: opts?.name, labels: opts?.labels })
5249
- );
5250
- } catch (error) {
5251
- if (sleeping) {
5252
- await this.wake().catch(() => void 0);
5253
- }
5254
- throw error;
5255
- }
5256
- if (sleeping) {
5257
- await this.wake();
5258
- }
5259
- return snap;
5271
+ return waitOverlayPublished(() => this.wire.createSnapshot(this.id, { name: opts?.name, labels: opts?.labels }));
5260
5272
  }
5261
- /** SDK glue: guest snap + N Create({ fromSnapshotId }). Not CreateMany. */
5273
+ /** SDK glue: guest snap + N Create({ fromSnapshotId }). Not CreateMany. The sandbox must already be sleeping. Call `sleep()` first. */
5262
5274
  async clone(n = 1, opts) {
5263
5275
  if (n < 1) {
5264
5276
  throw new InvalidArgumentError("clone: n must be >= 1", { code: "invalid_argument", reason: "CLONE" });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keska/sandbox",
3
- "version": "0.50.0",
3
+ "version": "0.50.1",
4
4
  "description": "TypeScript client for the Numen sandbox API",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",