@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 43 lines 1.26 KB
Raw
1 import type { MainRegionRow } from "@distilled.cloud/fly-io/machines";
2 import * as machines from "@distilled.cloud/fly-io/machines";
3 import * as Data from "effect/Data";
4 import * as Effect from "effect/Effect";
5 import { resolveOrgSlug } from "./Environment.ts";
6
7 export type CatalogKind = "region" | "org";
8
9 export class CatalogNotFound extends Data.TaggedError("Fly.CatalogNotFound")<{
10 kind: CatalogKind;
11 ref: string;
12 }> {}
13
14 const notFound = (kind: CatalogKind, ref: string) => new CatalogNotFound({ kind, ref });
15
16 /**
17 * Current token organization slug (`getCurrentToken` → `tokens[0].org_slug`).
18 * Feeds `listApps({ org_slug })`. Not a resource.
19 */
20 export const currentOrgSlug = resolveOrgSlug;
21
22 /**
23 * List Fly platform regions via `getRegions`.
24 */
25 export const listRegions = Effect.fn(function* () {
26 const { regions } = yield* machines.getRegions({});
27 return regions ?? [];
28 });
29
30 /**
31 * Resolve a Fly region by code (`iad`, `ord`, `sjc`, …).
32 */
33 export const findRegion = (code: string) =>
34 Effect.gen(function* () {
35 const regions = yield* listRegions();
36 const found = regions.find((item) => item.code === code);
37 if (found === undefined) {
38 return yield* notFound("region", code);
39 }
40 return found;
41 });
42
43 export type FlyRegion = MainRegionRow;