import { oc } from "@orpc/contract"; import { BAD_REQUEST, CONNECTION_ERROR, UNAUTHORIZED } from "every-plugin/errors"; import { z } from "zod"; const DeployInputSchema = z.object({ stage: z.string().min(1).describe("Stage name (the alchemy stage / fly app base)"), image: z.string().min(1).describe("OCI image ref, digest-pinned in production"), identityEnv: z .record(z.string(), z.string()) .describe( "The stage's full identity env (BOS_ACCOUNT/BOS_GATEWAY/BETTER_AUTH_SECRET/BASE_URL + provisioned bindings)", ), region: z.string().optional().describe("Substrate region"), }); export const deploymentsContract = oc.router({ deploy: oc .route({ method: "POST", path: "/deploy", summary: "Deploy a runtime stage on the substrate", description: "Converge a named stage to an image: the universal image boots env-only on the hosting substrate — docker (dev/CI) or fly machines (blue/green). Pure substrate orchestration: the caller owns the guard, the ledger, and the identity env composition.", tags: ["Stages"], }) .input(DeployInputSchema) .output( z.object({ status: z.enum(["deployed", "error"]), stage: z.string(), url: z.string().optional(), error: z.string().optional(), }), ) .errors({ UNAUTHORIZED, BAD_REQUEST, CONNECTION_ERROR }), status: oc .route({ method: "POST", path: "/status", summary: "Observe a stage", tags: ["Stages"], }) .input(z.object({ stage: z.string().min(1) })) .output( z.object({ status: z.enum(["running", "stopped", "error"]), stage: z.string(), url: z.string().optional(), image: z.string().optional(), error: z.string().optional(), }), ) .errors({ UNAUTHORIZED }), destroy: oc .route({ method: "POST", path: "/destroy", summary: "Destroy a stage", tags: ["Stages"], }) .input(z.object({ stage: z.string().min(1) })) .output( z.object({ status: z.enum(["destroyed", "not-found", "error"]), stage: z.string(), error: z.string().optional(), }), ) .errors({ UNAUTHORIZED }), }); export type ContractType = typeof deploymentsContract;