import type { Selectable } from 'kysely';
import type * as Db from '../Db.js';
import type * as db_Schema from '../Schema.js';
/** Columns of the `routes_idempotency_requests` table. */
export type Table = db_Schema.RoutesIdempotencyRequest;
/** A stored idempotency claim. */
export type Record = Selectable
;
/** Route creation operations sharing the idempotency table. */
export declare const operations: {
readonly depositAddress: 'deposit_address';
readonly transfer: 'transfer';
};
/** Route creation operation owning an idempotency claim. */
export type Operation = (typeof operations)[keyof typeof operations];
/**
* Claims `(apiKeyId, keyHash)` for one creation attempt. A live claim rejects
* mismatches, blocks pending work, resumes checkpoints, or replays completion.
* Deposit checkpoints are shared across rotated keys for the same scoped request.
*/
export declare function claim(db: Db.Db, input: claim.Input): Promise;
export declare namespace claim {
/** Claim identity and retention. */
type Input = {
/** API key id (`key_…`) the claim is scoped to. */
apiKeyId: string;
/** Older fingerprints accepted only when reading an existing claim. */
compatibleRequestHashes?: readonly string[] | undefined;
/** Whether provider success creates liability that must not expire. */
irrevocable: boolean;
/** SHA-256 of the caller Idempotency-Key. */
keyHash: string;
/** Route creation operation owning the claim. */
operation: Operation;
/** Organization owning the route creation. */
orgId: string;
/** Whether an adopted provider checkpoint carries irrevocable liability. */
recoveredIrrevocable?: boolean | undefined;
/** SHA-256 fingerprint of the canonical validated request. */
requestHash: string;
/** Lease duration for the pending execution, in milliseconds. */
ttlMs: number;
};
/** Outcome of a claim attempt. */
type Result = {
createdAt: string;
type: 'claimed';
} | {
type: 'mismatch';
} | {
type: 'pending';
} | {
response: string;
type: 'replay';
} | {
/** Whether the checkpoint still carries current quote terms. */
checkpointFresh: boolean;
createdAt: string;
recoveredClaim?: release.Input | undefined;
response: string;
type: 'resume';
};
}
/** Returns whether the database rejected a claim for a deleted owner. */
export declare function isOwnerFenceError(cause: unknown): boolean;
/** Marks an owned live claim as potentially creating irrevocable provider liability. */
export declare function markProviderAttempt(db: Db.Db, input: markProviderAttempt.Input): Promise;
export declare namespace markProviderAttempt {
/** Owned pending claim and renewed liability lease. */
type Input = release.Input & {
/** Renewed pending lease duration, in milliseconds. */
ttlMs: number;
};
}
/** Counts pending or provisioned deposit-address claims for an organization creator. */
export declare function countInFlightDepositAddresses(db: Db.Db, owner: countInFlightDepositAddresses.Owner): Promise;
export declare namespace countInFlightDepositAddresses {
/** Canonical creator scope, with organization fallback for unowned rows. */
type Owner = {
/** Organization id (`org_…`). */
orgId: string;
/** Canonical creator id (`usr_…`). */
userId: string | null;
};
}
/** Reserves one canonical reusable match across idempotency keys. */
export declare function reserveDepositAddressMatch(db: Db.Db, input: reserveDepositAddressMatch.Input): Promise;
export declare namespace reserveDepositAddressMatch {
/** Claim and canonical match identity. */
type Input = release.Input & {
/** SHA-256 fingerprint of the canonical reusable match. */
matchHash: string;
/** Organization owning the reusable match. */
orgId: string;
/** Renewed pending lease duration, in milliseconds. */
ttlMs: number;
};
/** Match reservation, recovery, or ownership outcome. */
type Result = {
type: 'lost';
} | {
type: 'pending';
} | {
type: 'provisioned';
} | {
type: 'reserved';
} | {
checkpointFresh: boolean;
claim: release.Input;
response: string;
type: 'resume';
};
}
/** Returns whether provider provisioning may still create an address for an organization. */
export declare function hasInFlightDepositAddress(db: Db.Db, orgId: string): Promise;
/** Returns whether a rolling deployment left route work without attributable ownership. */
export declare function hasUnattributedInFlightClaim(db: Db.Db): Promise;
/** Stores a provider result before committing its API resource and replay response. */
export declare function checkpoint(db: Db.Db, input: checkpoint.Input): Promise;
export declare namespace checkpoint {
/** Provider result and owned claim required for durable recovery. */
type Input = {
/** API key id (`key_…`) the claim is scoped to. */
apiKeyId: string;
/** Creation time returned by the successful claim. */
createdAt: string;
/** SHA-256 of the caller Idempotency-Key. */
keyHash: string;
/** Recovery checkpoint retention in milliseconds. */
replayTtlMs: number;
/** Serialized provider result required to resume resource creation. */
response: string;
};
}
/** Completes an owned pending or provisioned claim with its replay response. */
export declare function complete(db: Db.Db, input: complete.Input): Promise;
export declare namespace complete {
/** Completion fields. */
type Input = {
/** API key id (`key_…`) the claim is scoped to. */
apiKeyId: string;
/** Creation time returned by the successful claim. */
createdAt: string;
/** SHA-256 of the caller Idempotency-Key. */
keyHash: string;
/** Successful-response replay retention from completion, in milliseconds. */
replayTtlMs: number;
/** Serialized success response replayed for the retention window. */
response: string;
/** Transfer id (`rtr_…`) when the request created a route transfer. */
transferId?: string | undefined;
};
}
/** Releases a pending claim after a retryable failure. */
export declare function release(db: Db.Db, input: release.Input): Promise;
export declare namespace release {
/** Pending claim identity. */
type Input = {
/** API key id (`key_…`) the claim is scoped to. */
apiKeyId: string;
/** Creation time returned by the successful claim. */
createdAt: string;
/** SHA-256 of the caller Idempotency-Key. */
keyHash: string;
};
}
//# sourceMappingURL=routesIdempotency.d.ts.map