createApprovalGate
function createApprovalGate(options: CreateApprovalGateOptions): ScheduleRouteRunner;Defined in: src/mft/approvals.ts:283
Wraps a route runner with an approval gate.
The returned runner creates an approval request, waits for resolution, and
dispatches the underlying runner only when the request is approved. Rejection
surfaces an ApprovalRejectedError; an unresolved request that exceeds
timeoutMs surfaces an ApprovalTimeoutError. Pair with
MftScheduler to implement two-person rules and human-in-the-loop
release flows.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options | CreateApprovalGateOptions | Registry, downstream runner, approval-id derivation, hooks. |
Returns
Section titled “Returns”A ScheduleRouteRunner that gates execution behind approval.
Throws
Section titled “Throws”ApprovalTimeoutError From the returned runner when the
request stays pending longer than timeoutMs.
Example
Section titled “Example”import { ApprovalRegistry, createApprovalGate, runRoute,} from "@zero-transfer/sdk";
const approvals = new ApprovalRegistry();
const gatedRunner = createApprovalGate({ registry: approvals, approvalId: ({ route }) => `release:${route.id}:${Date.now()}`, onRequested: (req) => notifyOnCallChannel(req), runner: ({ client, route, signal }) => runRoute({ client, route, signal }),});
// Elsewhere, an authorized operator approves or rejects:approvals.approve(approvalId, { actor: "alice@example.com" });// approvals.reject(approvalId, { actor: "bob@example.com", reason: "hold release" });