import { z } from "zod"; import { getApplicationDomain } from "../env"; import type { OrganizationId } from "../organizations"; import type { RemoteModule } from "../remote-module"; /** * An installation's config snapshot, embedded with `include=activeConfig`. The * `version` is caller-supplied at deploy and mirrors interface versioning. * @public */ export const ActiveConfig = z.object({ id: z.string(), version: z.string(), }); /** * @public */ export type ActiveConfig = z.output; /** * A config a local dev server forwards. * @public */ export interface LocalAppConfig { appType: "media-library"; version: string; remoteURL: string; } /** * The stable `name` each local config's `appType` binds to — the workbench's own * mapping, since a local config carries no application identity of its own. This * is the key config↔app pairing matches on (identity, not the mutable slug). * @public */ export const APP_TYPE_NAME = { "media-library": "media-library", } as const satisfies Record; /** * The exposed module's manifest name the CLI emits every installation config * under — a config ref's `moduleId`. * @public */ export const CONFIG_MODULE_EXPOSE = "configs/installation_config"; /** * The module ref for a deployed installation's active config, served at the * stable `-configs-` host. * @public */ export function getDeployedConfigModuleRef( slug: string, config: ActiveConfig, organizationId: OrganizationId, ): RemoteModule { return { entry: `https://${slug}-configs-${organizationId}.${getApplicationDomain()}`, moduleId: CONFIG_MODULE_EXPOSE, version: config.version, }; }