@molecule/api-code-sandbox-flyio 1.0.3 → 1.0.5
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/provider.d.ts.map +1 -1
- package/dist/provider.js +23 -7
- package/package.json +1 -1
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAUV,eAAe,EAEhB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAE,YAAY,EAAgC,MAAM,UAAU,CAAA;AAsBrE,OAAO,EAAmD,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAEhG,OAAO,KAAK,EAEV,WAAW,EAUZ,MAAM,YAAY,CAAA;AAwpDnB;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,GACzB,eAAe,CAEjB"}
|
package/dist/provider.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
9
10
|
import { getLogger } from '@molecule/api-bond';
|
|
10
11
|
import { t } from '@molecule/api-i18n';
|
|
11
12
|
import { FlyApiClient, FlyApiError, normalizeApiUrl } from './api.js';
|
|
@@ -555,16 +556,24 @@ class FlyioSandboxProvider {
|
|
|
555
556
|
}
|
|
556
557
|
}
|
|
557
558
|
/**
|
|
558
|
-
* Sanitizes a caller-supplied volume name into a
|
|
559
|
+
* Sanitizes a caller-supplied volume name into a valid Fly volume name.
|
|
559
560
|
*
|
|
560
|
-
* Fly
|
|
561
|
-
*
|
|
562
|
-
*
|
|
561
|
+
* Fly requires `[a-z0-9_]` (lowercase only) and at most 30 characters — it
|
|
562
|
+
* rejects anything else with `400 "name only allows lowercase alphanumeric
|
|
563
|
+
* characters and underscores with at most 30 characters"`. Callers pass names
|
|
564
|
+
* like `mol-<uuid>` (40 chars, hyphens): lowercase, map every other character
|
|
565
|
+
* to `_`, and when the result is too long, keep a readable prefix plus a
|
|
566
|
+
* deterministic hash suffix so the name stays stable (`findVolume` re-derives
|
|
567
|
+
* the same name on the idempotent path) and unique.
|
|
563
568
|
* @param name - The caller's volume name.
|
|
564
|
-
* @returns A sanitized Fly volume name.
|
|
569
|
+
* @returns A sanitized Fly volume name, `[a-z0-9_]` and <= 30 chars.
|
|
565
570
|
*/
|
|
566
571
|
volumeName(name) {
|
|
567
|
-
|
|
572
|
+
const sanitized = name.toLowerCase().replace(/[^a-z0-9_]/g, '_');
|
|
573
|
+
if (sanitized.length <= 30)
|
|
574
|
+
return sanitized;
|
|
575
|
+
const hash = createHash('sha256').update(name).digest('hex').slice(0, 12);
|
|
576
|
+
return `${sanitized.slice(0, 17)}_${hash}`;
|
|
568
577
|
}
|
|
569
578
|
/**
|
|
570
579
|
* Idempotently ensures a volume exists in the app and returns its id.
|
|
@@ -716,7 +725,14 @@ class FlyioSandboxProvider {
|
|
|
716
725
|
// read back from the creation response is stale by definition.
|
|
717
726
|
return this.buildSandbox(app, machine.id, 'running');
|
|
718
727
|
}
|
|
719
|
-
|
|
728
|
+
// `POST .../machines` launches the Machine but returns as soon as it is
|
|
729
|
+
// scheduled — often still `created`/`starting`. The caller's very first
|
|
730
|
+
// action is an `exec` (to scaffold the workspace), which Fly rejects with
|
|
731
|
+
// `412 failed_precondition: machine not running` until the Machine is up.
|
|
732
|
+
// Wait for `started` here so `create` always hands back a live sandbox, as
|
|
733
|
+
// the JSDoc promises — the template path already does this via restore.
|
|
734
|
+
await this.waitForStarted(app, machine.id);
|
|
735
|
+
return this.buildSandbox(app, machine.id, 'running');
|
|
720
736
|
}
|
|
721
737
|
/**
|
|
722
738
|
* Retrieves an existing sandbox by its composite `<app>:<machineId>` id.
|