import type { GateOrder, Step, VerificationManifestEntry, TrustLevel } from "./types.js"; import { type ProofEntry } from "./ceremony/proofs.js"; /** A created-but-not-yet-completed order: the inputs the door + page re-derive from. */ export interface CreatedOrder { order: GateOrder; policy: Step[]; } /** The lean record completeOrder writes when an order finishes (mirrors the storefront shape). */ export interface CompletedOrder { orderId: string; amount?: number; currency?: string; method?: string; txId?: string; network?: string; completedAt?: string; /** The signed AP2 records, when the completion path surfaces them. */ mandateBundle?: unknown; /** What was proven for this order (the order proof receipt) — each with its own trust_level. */ proofs?: ProofEntry[]; } /** Minimal per-order KV, mirroring VerificationStore. In-memory default; inject for prod. */ export interface OrderStore { read(id: string): T | undefined | Promise; write(id: string, value: T): void | Promise; clear(id: string): void | Promise; } export declare class MemoryOrderStore implements OrderStore { private readonly m; read(id: string): T | undefined; write(id: string, value: T): void; clear(id: string): void; } /** The completed-order store as every reader gets it (the status route, the paid page, * `orders.retrieve`): proofs without the wallet's raw answer, even on an order stored before * #320 fixed the write side. Those reads need only the order id. */ export declare function receiptsOnly(store: OrderStore): OrderStore; /** * The refusal codes the door's `{ ok:false, code }` branch can carry — a TYPED union, not * `string`, so `res.code === "not-found"` autocompletes, a typo fails to compile, and a * `switch` on it is exhaustiveness-checked (#95 review — a bare string is a footgun). * * Today `orders.retrieve` reads stores and only refuses with `"not-found"`; it does not surface * policy failures — an age/payment gate refuses at the ceremony, not here. Widen this union * DELIBERATELY when a new orders refusal path lands; the compile error at each `switch` is the * reminder to handle it. (Sibling of the delegated `RefusalCode` and the webhook `WebhookRefusalCode`.) */ export type OrderDoorCode = "not-found"; /** The one result shape every consent path shares (spec 009 FR-003). */ export type OrderDoor = { ok: true; mandateBundle?: unknown; authorization: "direct"; trustLevel: TrustLevel; completion: Omit; } | { ok: false; pending: true; approveUrl: string; trustLevel: TrustLevel; } | { ok: false; code: OrderDoorCode; credential?: string; trustLevel: TrustLevel; }; export interface OrdersDeps { walletOrigin: string; /** Resolve the policy to the serializable manifest (CredentAgent.requirements). */ requirements: (order: GateOrder, policy: Step[]) => VerificationManifestEntry[]; created: OrderStore; /** The completed-order store; its write() fires "order.settled". */ completed: OrderStore; emit: (event: "order.settled", payload: { id: string; }) => void; /** Fan the settled order out to registered HTTP webhook endpoints (fire-and-forget). */ deliverWebhook?: (type: "order.settled", object: CompletedOrder) => void; /** Wire the checkout (rails + page + completion) onto an Express app — `orders.serve(app)`. */ serve: (app: unknown) => void; } export declare class Orders { private readonly deps; constructor(deps: OrdersDeps); /** Open an order that needs consent. Returns the id, the approve link, and the manifest. */ create({ order, policy }: { order: GateOrder; policy: Step[]; }): Promise<{ id: string; approveUrl: string; manifest: VerificationManifestEntry[]; }>; /** Read the current outcome — a single call (use in an order.settled handler, never a poll loop). */ retrieve(id: string): Promise; /** * Wire the checkout onto your Express app in one call: the ceremony rails, the checkout * page at each order's `approveUrl` (`/credentagent/orders/:id`), and completion — a * finished ceremony records the order and fires `order.settled`. No seams to assemble. * * ca.orders.serve(app); * ca.on("order.settled", ({ id }) => fulfill(id)); * const { approveUrl } = await ca.orders.create({ order, policy }); */ serve(app: unknown): void; /** Called by the completion path when an order finishes — records it and emits the * in-process `order.settled` event (see `CredentAgent.on` — a local listener, not a webhook). */ _complete(completion: CompletedOrder): Promise; }