import { type ConnectAttempt as Attempt } from "@opengeni/contracts/connect"; import { ExternalActorContinuation } from "@opengeni/contracts/external-identities"; import { type Database } from "./database.js"; export type ConnectActorScope = { accountId: string; workspaceId: string; subjectId: string; }; /** Live admission under the attempt transaction. Implementations must acquire * their key/membership/link fences in a consistent order and hold them through * commit. No network I/O. The attempt argument is an isolated copy. */ export type ConnectOperationAuthorization = (tx: Database, attempt: Attempt, origin: ExternalActorContinuation | null) => Promise; /** * Content-free state transition of one Connect attempt, reported only after * its transaction committed. `providerId` is caller-chosen; observers must * bound it against a reviewed catalog before using it as a label. */ export type ConnectAttemptTransition = { providerId: string; previousState: Attempt["state"] | null; state: Attempt["state"]; errorCode: string | null; }; type ConnectAttemptTransitionObserver = (transition: ConnectAttemptTransition) => void; /** Install the process-wide observer (the API sets one at startup). */ export declare function setConnectAttemptTransitionObserver(observer: ConnectAttemptTransitionObserver | null): void; export declare class ConnectAttemptConflictError extends Error { readonly code = "CONNECT_ATTEMPT_CONFLICT"; constructor(message?: string); } export declare class ConnectAttemptNotFoundError extends Error { readonly code = "CONNECT_ATTEMPT_NOT_FOUND"; constructor(); } /** Caller must establish live workspace/actor authority before this storage * seam. RLS scope is a consistency boundary, not proof of authentication. */ type ConnectBeginIdentity = { idempotencyKey: string; requestDigest: string; returnUrl: string; externalContinuation?: ExternalActorContinuation; }; /** Recover only an exact saved begin request, under the caller's live actor * admission. This performs no provider work or acquisition. */ export declare function getConnectBeginReplay(db: Database, scope: ConnectActorScope, input: ConnectBeginIdentity): Promise; export declare function beginConnectAttempt(db: Database, scope: ConnectActorScope, input: { idempotencyKey: string; requestDigest: string; returnUrl: string; attempt: Attempt; externalContinuation?: ExternalActorContinuation; authorizeAcquisition?: (tx: Database) => Promise; }): Promise; export declare function getConnectAttempt(db: Database, scope: ConnectActorScope, id: string): Promise<{ attempt: Attempt; returnUrl: string; operationInFlight: boolean; }>; export declare function listPendingConnectAttempts(db: Database, scope: ConnectActorScope): Promise; /** How long a saved account whose setup did not finish stays eligible to finish. */ export declare const UNFINISHED_CONNECT_SETUP_WINDOW_MS: number; export declare function listUnfinishedConnectSetups(db: Database, scope: ConnectActorScope, limit?: number): Promise; /** * Finish one unfinished setup (see listUnfinishedConnectSetups) in a single * transaction: `commit` installs under the attempt's row lock and returns the * completed attempt, or null to leave it as it is. Nothing happens when the * attempt moved on since `expectedRevision` or an operation is in flight * (the app is advancing it itself). Pass the same transaction to * installation persistence; do not perform network effects inside commit. */ export declare function completeUnfinishedConnectSetup(db: Database, scope: ConnectActorScope, input: { attemptId: string; expectedRevision: number; commit: (tx: Database, current: Attempt, origin: ExternalActorContinuation | null) => Promise; }): Promise; /** A claim is committed before remote effects. Never expire/reclaim it merely * because the caller timed out: the provider may have accepted the operation. */ export declare function claimConnectOperation(db: Database, scope: ConnectActorScope, input: { attemptId: string; expectedRevision: number; operationId: string; inputDigest: string; authorize?: ConnectOperationAuthorization; /** Additional acquisition admission, only after exact no-effect receipt replay. */ authorizeAcquisition?: (tx: Database, attempt: Attempt) => Promise; }): Promise<{ status: "claimed"; attempt: Attempt; } | { status: "replayed"; attempt: Attempt; }>; /** * Free this operation's claim after it failed, so the attempt can be advanced * again. Only for an operation whose work has no remote effects (it reads and * then writes in finishConnectOperation's one transaction): when that fails, * nothing is uncertain. Changes nothing when the claim is no longer this * operation's, including when the operation did finish. */ export declare function releaseConnectOperation(db: Database, scope: ConnectActorScope, input: { attemptId: string; operationId: string; inputDigest: string; }): Promise; /** Pass the same transaction to credential/installation persistence through * commit so its receipt and the public setup result become visible atomically. * Do not perform network effects inside commit. */ export declare function finishConnectOperation(db: Database, scope: ConnectActorScope, input: { attemptId: string; operationId: string; inputDigest: string; commit: (tx: Database, current: Attempt) => Promise; authorize?: ConnectOperationAuthorization; /** Additional acquisition admission, only after exact no-effect receipt replay. */ authorizeAcquisition?: (tx: Database, attempt: Attempt) => Promise; }): Promise; export {};