import type { Selectable } from 'kysely'; import type * as Webhooks from '../../internal/Webhooks.js'; import type * as Db from '../Db.js'; import type * as db_Schema from '../Schema.js'; /** Columns of the `webhook_subscriptions` table, derived from `Schema.WebhookSubscription`. */ export type Table = db_Schema.WebhookSubscription; /** A stored webhook-subscription row. */ export type Record = Selectable; /** Reads one live subscription by id for an internal Queue delivery. */ export declare function getById(db: Db.Db, id: string, now: string): Promise; /** Maps an owner union to its stored `ownerId` column value. */ export declare function ownerId(owner: Webhooks.Owner): string; /** Maps a stored row to the domain subscription (null columns → absent fields). */ export declare function toSubscription(row: Record): Webhooks.Subscription; /** * Inserts a subscription row from its domain value. * * @param db - The database. * @param subscription - The subscription to insert. * @param options - Initial cursor options. */ export declare function insert(db: Db.Db, subscription: Webhooks.Subscription, options?: insert.Options): Promise; export declare namespace insert { /** Options for {@link insert}. */ type Options = { /** Initial cursor committed with the subscription. */ pollerCursor?: string | undefined; }; } /** * Inserts a subscription when its owner remains below the configured cap. * An owner-scoped transaction lock serializes the count and insert. */ export declare function insertWithinLimit(db: Db.Db, subscription: Webhooks.Subscription, options: insertWithinLimit.Options): Promise; export declare namespace insertWithinLimit { /** Options for an atomic capped insert. */ type Options = { /** Maximum live subscriptions the owner may hold. */ maxPerOwner: number; /** ISO timestamp used to exclude expired rows from the count. */ now: string; /** Initial cursor committed with the subscription. */ pollerCursor?: string | undefined; }; } /** * Reads an owner's subscription by id; expired rows never match (query-time * expiry, same read semantics as the old store TTL). * * @param db - The database. * @param owner - The authenticated owner. * @param id - The subscription id (`wh_…`). * @param now - ISO timestamp expiry is evaluated against. * @returns The subscription, or `null` when absent (or not the owner's). */ export declare function get(db: Db.Db, owner: Webhooks.Owner, id: string, now: string, access?: Webhooks.Access): Promise; /** * Lists an owner's live subscriptions, newest first, with keyset paging * (`id < cursor` — ids embed a zero-padded timestamp, so lexical order is * chronological). * * @param db - The database. * @param owner - The authenticated owner. * @param options - Paging options plus the expiry timestamp. * @returns The subscriptions. */ export declare function list(db: Db.Db, owner: Webhooks.Owner, options: list.Options): Promise; export declare namespace list { /** Options for {@link list}. */ type Options = { /** Private-resource visibility scope. */ access?: Webhooks.Access | undefined; /** Return subscriptions older than this id (keyset paging, newest first). */ cursor?: string | undefined; /** Maximum subscriptions to return. */ limit?: number | undefined; /** ISO timestamp expiry is evaluated against. */ now: string; /** Rows to skip from the head (positional pagination; exclusive with `cursor`). */ offset?: number | undefined; }; } /** * Counts an owner's live subscriptions. * * @param db - The database. * @param owner - The authenticated owner. * @param now - ISO timestamp expiry is evaluated against. * @returns The count. */ export declare function count(db: Db.Db, owner: Webhooks.Owner, now: string, access?: Webhooks.Access): Promise; /** * Applies a column patch to a subscription. Only the provided columns are * written; `context: null` clears the stored context. * * @param db - The database. * @param id - The subscription id (`wh_…`). * @param set - The columns to write. * @returns The updated row's subscription, or `undefined` when absent. */ export declare function update(db: Db.Db, id: string, set: update.Set): Promise; export declare namespace update { /** Columns writable by a subscription patch. */ type Set = { /** New human context; null clears it. */ context?: Webhooks.Context | null | undefined; /** New delivery destination. */ destination?: Webhooks.Destination | undefined; /** New filter predicates. */ filters?: Webhooks.Subscription['filters'] | undefined; /** New lifecycle status. */ status?: Webhooks.Status | undefined; /** Mutation timestamp (ISO). */ updatedAt: string; }; } /** * Deletes an owner's live subscription; delivery rows cascade via the FK. * * @param db - The database. * @param owner - The authenticated owner. * @param id - The subscription id (`wh_…`). * @param now - ISO timestamp expiry is evaluated against. * @returns Whether a row was deleted. */ export declare function remove(db: Db.Db, owner: Webhooks.Owner, id: string, now: string, access?: Webhooks.Access): Promise; /** * Lists live `active` subscriptions for a `(chainId, eventType)` stream, * served by the partial status index. Each row carries its cursor so callers * avoid a per-subscription read. * * @param db - The database. * @param chainId - Chain the stream belongs to. * @param eventType - Event type of the stream. * @param now - ISO timestamp expiry is evaluated against. * @returns Cursor-and-subscription pairs, in id (chronological) order. */ export declare function listActive(db: Db.Db, chainId: number, eventType: Webhooks.EventType, now: string): Promise<{ cursor: string | null; subscription: Webhooks.Subscription; }[]>; /** * Lists every live `active` subscription on a chain in one read. Callers * group the rows by event type so empty streams cost no extra database reads. * * @param db - The database. * @param options - Chain, configured event types, and expiry time. * @returns Cursor-and-subscription pairs ordered by event type, then id. */ export declare function listActiveForChain(db: Db.Db, options: listActiveForChain.Options): Promise<{ cursor: string | null; subscription: Webhooks.Subscription; }[]>; export declare namespace listActiveForChain { /** Filters for the chain-level subscription read. */ type Options = { /** Chain whose subscriptions to read. */ chainId: number; /** Event types eligible for the read. */ eventTypes: readonly Webhooks.EventType[]; /** ISO timestamp expiry is evaluated against. */ now: string; }; } /** Lists live funding subscriptions visible to one resource owner. */ export declare function listActiveForFundingEvent(db: Db.Db, options: listActiveForFundingEvent.Options): Promise; export declare namespace listActiveForFundingEvent { /** Ownership scope and chain for a funding resource event. */ type Options = { /** Destination Tempo chain id. */ chainId: number; /** Resource API-key environment. */ environment: 'production' | 'sandbox'; /** Event timestamp used to keep subscriptions future-only, when supplied. */ eventCreatedAt?: string | undefined; /** Funding event type to match. */ eventType: Extract; /** ISO timestamp used to exclude expired subscriptions. */ now: string; /** Owning organization id. */ orgId: string; /** Attributed funding resource project, when present. */ projectId?: string | undefined; }; } /** * Reads a subscription's keyset cursor. * * @param db - The database. * @param id - The subscription id (`wh_…`). * @returns The cursor, or `null` when unset (or the row is absent). */ export declare function getCursor(db: Db.Db, id: string): Promise; /** * Records a successful delivery: resets the consecutive-failure counter and * stamps `lastDeliveryAt`. Skipped when neither field would move, so * deliveries stop contending on the row's lock. * * @param db - The database. * @param id - The subscription id (`wh_…`). * @param options - Delivery timestamp and stamp-staleness bound. * @returns The updated subscription, or `undefined` when nothing was written. */ export declare function recordSuccess(db: Db.Db, id: string, options: recordSuccess.Options): Promise; export declare namespace recordSuccess { /** Clock bounds for one success record. */ type Options = { /** Delivery timestamp (ISO). */ now: string; /** Rewrite the stamp only when it predates this (ISO). */ staleBefore: string; }; } /** * Records a failed delivery: atomically increments the consecutive-failure * counter and disables the subscription once it reaches `maxFailures` (raw * fragments use storage column names — they bypass the camelCase mapping). * Skipped once disabled at the cap, when nothing would move. * * @param db - The database. * @param id - The subscription id (`wh_…`). * @param maxFailures - Consecutive failures before auto-disabling. * @param now - Failure timestamp (ISO). * @returns The updated subscription, or `undefined` when nothing was written. */ export declare function recordFailure(db: Db.Db, id: string, maxFailures: number, now: string): Promise; /** * Deletes expired subscriptions (their delivery rows cascade). Called * best-effort on a schedule. * * @param db - The database. * @param now - ISO timestamp expiry is evaluated against. * @returns The number of rows deleted. */ export declare function pruneExpired(db: Db.Db, now: string): Promise; //# sourceMappingURL=webhookSubscriptions.d.ts.map