@molecule/api-code-sandbox-flyio 1.0.2 → 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.
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +21 -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;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';
|
|
@@ -370,12 +371,17 @@ class FlyioSandboxProvider {
|
|
|
370
371
|
async allocatePrivateAddress(service, network) {
|
|
371
372
|
let assignment;
|
|
372
373
|
try {
|
|
374
|
+
// NO org_slug here. The ip_assignments endpoint derives the org from the
|
|
375
|
+
// target app and REJECTS an explicit org_slug with 400 "organization not
|
|
376
|
+
// found" (verified against api.machines.dev for a personal org: the same
|
|
377
|
+
// slug that app creation REQUIRES is refused here; omitting it returns 200
|
|
378
|
+
// and allocates the address). app creation still sends org_slug — the two
|
|
379
|
+
// endpoints genuinely differ.
|
|
373
380
|
assignment = await this.client.request(`/apps/${service.app}/ip_assignments`, {
|
|
374
381
|
method: 'POST',
|
|
375
382
|
body: {
|
|
376
383
|
type: this.config.privateIpAssignmentType ?? DEFAULT_PRIVATE_IP_TYPE,
|
|
377
384
|
network,
|
|
378
|
-
org_slug: this.orgSlug(),
|
|
379
385
|
},
|
|
380
386
|
});
|
|
381
387
|
}
|
|
@@ -550,16 +556,24 @@ class FlyioSandboxProvider {
|
|
|
550
556
|
}
|
|
551
557
|
}
|
|
552
558
|
/**
|
|
553
|
-
* Sanitizes a caller-supplied volume name into a
|
|
559
|
+
* Sanitizes a caller-supplied volume name into a valid Fly volume name.
|
|
554
560
|
*
|
|
555
|
-
* Fly
|
|
556
|
-
*
|
|
557
|
-
*
|
|
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.
|
|
558
568
|
* @param name - The caller's volume name.
|
|
559
|
-
* @returns A sanitized Fly volume name.
|
|
569
|
+
* @returns A sanitized Fly volume name, `[a-z0-9_]` and <= 30 chars.
|
|
560
570
|
*/
|
|
561
571
|
volumeName(name) {
|
|
562
|
-
|
|
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}`;
|
|
563
577
|
}
|
|
564
578
|
/**
|
|
565
579
|
* Idempotently ensures a volume exists in the app and returns its id.
|