@molecule/api-code-sandbox-flyio 1.0.3 → 1.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,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;AA0oDnB;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,GACzB,eAAe,CAEjB"}
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;AAipDnB;;;;;;;;;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 conservative form.
559
+ * Sanitizes a caller-supplied volume name into a valid Fly volume name.
559
560
  *
560
- * Fly does NOT document the character rules for volume names, so this reduces
561
- * to `[A-Za-z0-9_]`, which is the form every Fly example uses. Callers pass
562
- * names like `mol-<uuid>`; the hyphens become underscores.
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
- return name.replace(/[^A-Za-z0-9_]/g, '_');
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-code-sandbox-flyio",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Fly.io Machines (Firecracker microVM) code sandbox provider",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",