import type { Pool, PoolClient } from '@evershop/postgres-query-builder'; import type { ClaimedDelivery, WebhookDeliveryRow, WebhookEnvelope } from '../types/index.js'; type Queryable = Pool | PoolClient; export type NewDelivery = { uuid: string; webhookId: number; topic: string; eventUuid: string | null; payload: WebhookEnvelope; /** `sending` is used by the test event, which is sent at once. */ status?: 'pending' | 'sending'; attempts?: number; }; /** Insert deliveries in one statement. Returns the inserted rows. */ export declare function insertDeliveries(rows: NewDelivery[], db?: Queryable): Promise; /** * Claim these deliveries for sending: `pending` -> `sending`, attempts + 1. * Same primitive as `EventStorage.claimBatch` (`FOR UPDATE SKIP LOCKED`), so a * row is never sent by two workers. Rows of a disabled webhook are not claimed. */ export declare function claimByIds(ids: number[], db?: Queryable): Promise; /** Claim up to `limit` pending deliveries whose retry time has come. */ export declare function claimDue(limit: number, db?: Queryable): Promise; /** * The `status = 'sending'` guard on the two writes below means a late result * can never overwrite a row that was reclaimed and re-sent in the meantime. */ export declare function markDelivered(id: number, statusCode: number, db?: Queryable): Promise; export declare function markAttemptFailed(id: number, result: { status: 'pending' | 'failed'; nextAttemptAt: Date | null; statusCode: number | null; error: string | null; }, db?: Queryable): Promise; /** * Crash recovery: a `sending` row older than `STUCK_SENDING_MINUTES` lost its * worker. Unlike the event system (which marks stuck events failed), a webhook * is sent again, so delivery is at-least-once and the receiver dedupes on the * delivery id. A row already at the attempt limit is failed instead. */ export declare function reclaimStuck(db?: Queryable): Promise; /** Cancel the pending deliveries of one webhook (it was just disabled). */ export declare function cancelPendingForWebhook(webhookId: number, db?: Queryable): Promise; /** * Self-healing: the subscriber's cache can be up to a few seconds stale, so a * delivery can be created for a webhook that was disabled a moment ago. */ export declare function cancelPendingForDisabled(db?: Queryable): Promise; /** * Keep the newest `limit` finished rows (`delivered` / `canceled`) per webhook. * `pending` and `sending` rows are the retry queue and are never touched. */ export declare function trimFinished(limit: number, db?: Queryable): Promise; /** Delete final `failed` rows older than the retention period. */ export declare function trimFailed(db?: Queryable): Promise; export {};