import type { StorageAdapter } from "../interfaces.js"; import type { ID } from "../types.js"; import type { OperationsDomain } from "./operations.js"; /** * Default per-payment checkout TTL in milliseconds (24 hours). * If a payment's Op A is still pending after this window, the sweep auto-fails it. */ export declare const DEFAULT_PAYMENT_TTL_MS: number; /** * SweepJob — background task interface for TTL-driven session and payment lifecycle management. * * Production callers MUST wire the three sweep methods to a scheduler * (e.g. cron, queue worker). The frequency should be: * - `sweepExpiredPayments`: every 5–15 minutes * - `sweepExpiredSessions`: every 5–15 minutes * - `sweepClosingSessions`: every 1–5 minutes (monitors short-lived closing windows) * * @example * ```ts * const sweep = createSweepJob({ storage, operations: pay.operations }); * // Wire to a cron scheduler * cron.schedule("* /5 * * * *", () => { * sweep.sweepExpiredPayments(tenantId); * sweep.sweepExpiredSessions(tenantId); * sweep.sweepClosingSessions(tenantId); * }); * ``` */ export interface SweepJob { /** * Auto-fail payments whose Op A is still pending after `paymentTtlMs`. * * For each timed-out payment: * 1. Fail Op A via `operations.fail(opA.id)`. * 2. Void the associated `CheckoutQuote` (status → `'expired'`). * 3. Set `CheckoutPayment.status = 'failed'`. * * The session remains `active` after this sweep — the payer may retry with a new quote. * * @param tenantId - Tenant scope for the sweep. * @param paymentTtlMs - Maximum age of a pending payment before auto-failing. Defaults to 24h. */ sweepExpiredPayments(tenantId: ID, paymentTtlMs?: number): Promise; /** * Transition sessions that have passed their `expiresAt`. * * For each past-TTL session: * - If in-flight pending payments or an `activeQuoteId` exists → transition to `'closing'`. * - Otherwise → transition directly to `'expired'`. * * Both paths converge at `'closed'` (via `sweepClosingSessions` or direct transition). * * @param tenantId - Tenant scope for the sweep. */ sweepExpiredSessions(tenantId: ID): Promise; /** * Transition `'closing'` sessions to `'closed'` when all in-flight payments * have reached a terminal status and no active quotes remain. * * Computes `fulfillmentStatus` and writes it to the session record. * * @param tenantId - Tenant scope for the sweep. */ sweepClosingSessions(tenantId: ID): Promise; } export interface SweepJobConfig { storage: StorageAdapter; operations: Pick; /** Default per-payment TTL in ms. Defaults to 24h. */ paymentTtlMs?: number; } export declare function createSweepJob(config: SweepJobConfig): SweepJob; //# sourceMappingURL=sweep.d.ts.map