Skip to content

createApprovalGate

function createApprovalGate(options: CreateApprovalGateOptions): ScheduleRouteRunner;

Defined in: src/mft/approvals.ts:250

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. Pair with MftScheduler to implement two-person rules and human-in-the-loop release flows.

ParameterTypeDescription
optionsCreateApprovalGateOptionsRegistry, downstream runner, approval-id derivation, hooks.

ScheduleRouteRunner

A ScheduleRouteRunner that gates execution behind approval.

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" });