// The app registry (`apps/registry.json`) and the kits, read the way a test needs // them, so no test restates the list of apps: adding an app changes no test. import { readFileSync } from "node:fs"; import { join } from "node:path"; const ROOT = join(__dirname, "..", "..", ".."); export interface RegistryApp { slug: string; name: string; kit: string | null; phase: string; active: boolean; ios: null | { share?: boolean; provider?: boolean; live: { flavour: string; bundleId: string; ascAppId: string | null }; dev?: { flavour: string; bundleId: string; ascAppId: string | null } | null; }; } /** Every row of the registry, in its order. */ export function registryApps(root = ROOT): RegistryApp[] { return (JSON.parse(readFileSync(join(root, "apps/registry.json"), "utf8")) as { apps: RegistryApp[] }).apps; } /** The registry row whose slug is `slug`. */ export function registryApp(slug: string, root = ROOT): RegistryApp { const app = registryApps(root).find((a) => a.slug === slug); if (!app) throw new Error(`no app ${slug} in apps/registry.json`); return app; } /** * Whether an app founds the owner's Personal object: its kit is Cotton's own * (`personal`), or every table its kit names is a personal one (`personal/`, * an app over the one object). A business kit (yoga, kitchen) names its own. */ export function foundsPersonal(app: RegistryApp, root = ROOT): boolean { if (!app.kit) return false; if (app.kit === "personal") return true; const kit = JSON.parse(readFileSync(join(root, "crates/cotton-core/kits", app.kit, "kit.json"), "utf8")) as { tables?: string[] }; const tables = (kit.tables ?? []).filter((t) => !PRODUCT_TABLES.includes(t)); return tables.length > 0 && tables.every((t) => t.startsWith("personal/")); } /** * Tables that live in Cotton's own product object (`cotton-product`, where every * app's shake report lands: owner, 13 Nov 2026), not in a person's. The developer * kit names them beside its personal tables so that object can be laid from it; * naming one does not make the kit a business's. */ const PRODUCT_TABLES = ["app_report"]; /** Every App Store Connect app id the registry writes, live and dev. */ export function ascAppIds(root = ROOT): string[] { return registryApps(root).flatMap((a) => [a.ios?.live?.ascAppId, a.ios?.dev?.ascAppId].filter((id): id is string => !!id)); }