import { type ClearableCart, type CompletedOrderStore, type CompletionContext } from "./ceremony/completion.js"; import type { CeremonyCatalog, CeremonyOrderStore, CompletionInput, CompletionResult, CompletionSeam } from "./ceremony/types.js"; import type { VerificationStore } from "./types.js"; /** The minimal Express-app shape `publish()` needs — just `app.locals` (no `express` dep). */ export interface HostApp { locals: Record; } export interface DefineHostSpec { /** Server-side re-pricing — the amount source of truth (Security invariant 2). Required. */ catalog: CeremonyCatalog; /** Resolve a created order by id (line items only; the catalog re-prices). Required. */ orderStore: CeremonyOrderStore; /** * The completed-order store (idempotent, keyed by order id) `defineHost` uses to BUILD the * shared completion for you — so you never call `completeOrder` by hand. Provide this OR a * ready-made `completion` seam, not both. */ records?: CompletedOrderStore; /** * A ready-made completion seam, if you'd rather bind `completeOrder` yourself (advanced / * an unusual store shape). Mutually exclusive with `records`. */ completion?: CompletionSeam; /** * Stable HMAC key for the ceremony challenge (e.g. `process.env.GATE_SECRET`) so an * options→verify hop survives a serverless instance split. Pass this OR `allowEphemeralKey`. */ signingKey?: string; /** Allow a per-process ephemeral key for a single-process dev server. Pass this OR `signingKey`. */ allowEphemeralKey?: boolean; /** * The per-order verification store the rails write and completion reads (Security invariant * 4). Default: a fresh in-memory store (inject a shared one — e.g. Redis — for multi-instance). */ verificationStore?: VerificationStore; /** A cart to empty on completion (optional). */ cart?: ClearableCart; /** Optional demo-mode settlement; throwing GATES completion (records nothing). */ settle?: CompletionContext["settle"]; /** * Where a rail returns the buyer after they prove — YOUR checkout route, e.g. * `(id) => \`/checkout/${id}\``. Absent ⇒ each rail's default `/checkout?order=`, which a * non-storefront host usually does not serve (the buyer would be bounced to a dead link). */ returnUrl?: (orderId: string) => string; /** Opt-in: treat a verified Cart Mandate as the created-order transport (FR-007). Default off. */ statelessOrders?: boolean; } /** * A host bound to its stores: the per-order verification store, `publish(app)` to wire the * seams onto your app, and `complete(input)` — the shared completion your OWN action calls so * the gates run server-side (never only in a rendered page). */ export interface Host { /** The per-order verification store the rails write and completion reads (invariant 4). */ readonly verificationStore: VerificationStore; /** * Publish the ceremony seams onto `app.locals.credentagent` so `credentagent.mount(app)` * wires the `/credentagent/*` rails over them with zero explicit args. Call this BEFORE * `mount(app)`. Idempotent-friendly (merges onto any existing `app.locals.credentagent`). */ publish(app: HostApp): void; /** * The shared completion seam — re-price, reconcile, run the age + custom gates, settle, * idempotent record. Call it from your own place-order / MCP tool so a gate is enforced on * YOUR completion path (invariant 1). Returns typed plain data: `{ completed, reason? }`. */ complete(input: CompletionInput): Promise; } /** * Turn a host's domain pieces (catalog, order store, completed-order store) into the ceremony * seams the gate consumes, with the shared `completeOrder` built for you. Fails fast, at * construction, on an incomplete or contradictory seam set — one clear error door. */ export declare function defineHost(spec: DefineHostSpec): Host;