import type { SqlClient } from "@decionis/agent-safe-pipeline"; import type { CardHoldSeal } from "./CardHoldSeal.js"; import { type CardClaimInput, type CardHoldAdoption, type CardHoldKey, type CardHoldStore, type CardVelocity, type ClaimedCardAuthorization, type HeldCardGrant, type HeldCardGrantRecord } from "./CardHoldStore.js"; import type { CardAuthorizationRequest } from "./CardPurchase.js"; export declare const DEFAULT_CARD_HOLDS_TABLE = "agentsafe_card"; declare const CLAIM_NOT_ADOPTED = "CLAIM_NOT_ADOPTED"; export declare class CardHoldStoreError extends Error { readonly code: typeof CLAIM_NOT_ADOPTED | "CARD_HOLDS_UNAVAILABLE"; constructor(code: typeof CLAIM_NOT_ADOPTED | "CARD_HOLDS_UNAVAILABLE"); } export interface PostgresCardHoldsOptions { readonly client: SqlClient; /** Whose holds these are: one deployment. Two deployments on one database never see each other's. */ readonly namespace: string; /** The tables' prefix, optionally schema-qualified; `agentsafe_card` by default. */ readonly table?: string; /** Seals what the rows keep of a grant and a claim; the key stays in the process. */ readonly seal: CardHoldSeal; /** How this process admits a hold or a claim another replica made. */ readonly adopt: CardHoldAdoption; /** This replica's name in a row, for an operator reading the table; random when absent. */ readonly replica?: string; /** How long a claimed authorization waits for its result before it is forgotten. */ readonly claimRetentionMs?: number; readonly clock?: () => number; } /** * Holds and claims shared by every replica, and kept across a restart. A * hold is one row, unique on the card and the merchant; `hold` takes the * key when its row is absent, spent or expired, in one statement, so of two * purchases racing for the same card at the same merchant the database lets * one hold. `spend` sets `used` on the row that is still unspent and * unexpired, in one statement, so of two authorizations racing for the * same hold the database lets one claim: the same race rule as in memory, * decided by the database instead of by one process's memory. * * What a row keeps of the grant, and later of the claim, is sealed under * the deployment's hold key, so the database holds no bearer credential in * clear; the columns outside the seal are references, times and flags. A * hold another replica made is admitted here on first use, through the * executor's own checks, and a claim another replica made is finalized here * with the material that replica sealed. The operator creates the tables * (`PostgresCardHolds.schema()`); the executor's role needs SELECT, INSERT, * UPDATE and DELETE on them and nothing else. */ export declare class PostgresCardHolds implements CardHoldStore { readonly kind: "postgres"; private readonly client; private readonly namespace; private readonly holds; private readonly claims; private readonly activity; private readonly seal; private readonly adopt; private readonly replica; private readonly claimRetentionMs; private readonly clock; /** The handles this process holds, by key, each valid for the intent it was made for. */ private readonly localHolds; private readonly localClaims; /** The claim material each claim was recorded with here, for re-sealing an amendment. */ private readonly materials; constructor(options: PostgresCardHoldsOptions); /** The DDL an operator runs once, before the first replica starts. */ static schema(table?: string): string; spendable(key: CardHoldKey): Promise; hold(grant: HeldCardGrant): Promise; grant(key: CardHoldKey): Promise; spend(grant: HeldCardGrant): Promise; claimed(authorizationId: string): Promise; recordClaim(authorizationId: string, claim: CardClaimInput): Promise; amend(authorizationId: string, request: CardAuthorizationRequest): Promise; settle(authorizationId: string): Promise; velocity(cardTokenRef: string, windowMs?: number): Promise; /** Throws unless every table exists with the columns this store uses. */ ready(): Promise; /** * Forgets what lapsed: a hold a claim's retention after its expiry (so a * late authorization is still told its grant expired), a claim after its * retention, and activity older than the velocity window plus a day. */ cleanup(): Promise; close(): Promise; private note; private sealClaim; /** The material a claim was recorded with here, kept only in the row; re-read for an amendment. */ private materialOf; private holdIdentity; private claimIdentity; private iso; private static holdRow; private static claimRow; } export {}; //# sourceMappingURL=PostgresCardHolds.d.ts.map