/** * HTTP surface for workflow React hooks and run-event clients. * * `useWorkflow`, `useWorkflowStart`, `useWorkflowList` and `useApproval` all * call a fixed set of paths under their `apiBase` (default `/api/workflows`). * Those clients are the specification for this module. Every response shape * below is the one its caller parses. * * @module workflow/http * * @example Mount every workflow route at once * ```typescript * // app/api/workflows/[...path]/route.ts * import { createWorkflowHandler } from "veryfront/workflow"; * import { getSession } from "../../../../lib/auth.ts"; * import { workflows } from "../../../../lib/workflows.ts"; * * export const { GET, POST } = createWorkflowHandler(workflows, { * authorize: async (request) => (await getSession(request))?.user.id ?? null, * }); * ``` */ import type { WorkflowClient } from "../api/index.js"; /** Options for {@linkcode createWorkflowHandler}. */ export interface WorkflowHandlerOptions { /** * Authorize a request and return the authenticated approver identity. * Return null to deny access. The handler uses this server-derived identity * for approval decisions instead of trusting the request body. */ authorize: (request: Request) => string | null | Promise; /** * Path this handler is mounted at. It has to match the `apiBase` the hooks * use, because the handler resolves a route by what follows it. */ basePath?: string; } /** Route handlers to re-export from a catch-all route module. */ export interface WorkflowHandlers { GET: (request: Request) => Promise; POST: (request: Request) => Promise; } /** * Build the HTTP routes the workflow hooks call. * * Pass the same client the rest of the app starts workflows with. A client * created here instead would carry its own in-memory backend and would not see * those runs. * * `GET {basePath}/runs/{runId}/events` returns a Server-Sent Events stream. It * sends the current public run as `snapshot`, followed by persisted step and * run-status events, and closes on a terminal run. Missing runs return 404. * Custom backends without atomic run observation return 501. Observation * failures send one sanitized `error` event with `retryable: true`, then close. * A snapshot that cannot be serialized fails the same way on every reconnect, * so that error event carries `retryable: false` instead. */ export declare function createWorkflowHandler(client: WorkflowClient, options: WorkflowHandlerOptions): WorkflowHandlers; //# sourceMappingURL=handler.d.ts.map