import type { Database } from "../database.js"; import type { SubscriptionCoreProvider } from "./provider.js"; /** * The writes of one credential refresh, under the caller's authority (each * runs in the caller's transaction): `begin` takes the per-connection * refresh lock, rechecks the caller's access and returns the stored * credential to rotate (null: refused); `persist` stores the rotated * credential and the plan it reports, and `fail` marks the connection * needs-relogin, each fenced on the refresh generation `begin` returned. */ export type SubscriptionCoreCredentialRefreshWriter = { begin(tx: Database): Promise<{ refreshGeneration: number; credentialEncrypted: string; } | null>; persist(tx: Database, input: { refreshGeneration: number; credentialEncrypted: string; expiresAt: Date | null; refreshedAt: Date; /** The plan the rotated credential reports; null keeps the recorded plan. */ planType: string | null; }): Promise; fail(tx: Database, input: { refreshGeneration: number; message: string; }): Promise; }; export type SubscriptionCoreCredentialRotationOutcome = { kind: "refreshed"; /** The rotated credential, already persisted. */ credential: unknown; refreshGeneration: number; /** The plan the rotated credential reported (persisted with it). */ planType: string | null; } /** Another refresh or credential writer already advanced the generation. */ | { kind: "superseded"; } | { kind: "relogin"; message: string; marked: boolean; } | { kind: "refused"; } | { kind: "error"; error: unknown; }; /** Decrypt and decode a stored credential with the provider's codec. */ export declare function decodeSubscriptionCoreCredential(provider: SubscriptionCoreProvider, key: Uint8Array, encrypted: string): unknown; /** * One credential refresh in the caller's transaction, through the caller's * writer: `begin` (lock and recheck), the adapter's rotation, then * `persist` before any other fallible work (a rolled-back transaction * would discard the only valid refresh token), or `fail` when only a new * sign-in recovers. Failures are returned, never thrown, so a status write * commits. */ export declare function rotateSubscriptionCoreCredential(tx: Database, provider: SubscriptionCoreProvider, key: Uint8Array, writer: SubscriptionCoreCredentialRefreshWriter, observedRefreshGeneration: number, now: () => Date): Promise;