import { type Database } from "../database.js"; import { type DisconnectAuditActor } from "../disconnect-audit.js"; import { type SubscriptionCoreWake } from "./administration.js"; import { type SubscriptionCoreProvider } from "./provider.js"; export type SubscriptionCoreCredentialInput = { /** v1 envelope of the adapter's encoded credential. */ credentialEncrypted: string; /** * The stored format of that credential (`adapter.credential.format`); * `v1`, the 0707 writers' format, when omitted. */ credentialFormat?: string; providerAccountId: string | null; /** * The signed-in person within the upstream account. Two people's logins of * one upstream account are distinct shared connections; only the same * person's login reconnects in place. */ providerSubjectId: string | null; planType: string | null; /** Adapter-owned provider state merged into the connection's. */ providerState: Record; expiresAt: Date | null; lastRefreshAt: Date | null; accountEmail: string | null; label: string | null; /** Verified managed-browser human, never inferred from a grant's spelling. */ connectedBySubjectId?: string | null; }; export type SubscriptionCoreConnectRefusal = /** Not an organization administrator, or not allowed to manage it here. */ "forbidden" /** The upstream account is already connected and managed elsewhere. */ | "managed_elsewhere" /** A migrated login has no proven upstream person; never guess or merge it. */ | "identity_unverified" /** Personal connections are turned off for this person here. */ | "personal_connections_disabled" /** The caller is not exact. */ | "unavailable" /** A fenced reconnect's connection is gone, changed, or not the one this sign-in reaches. */ | "changed"; export type SubscriptionCoreConnectResult = { kind: "connected"; id: string; isNew: boolean; ownership: "shared" | "personal"; wake: SubscriptionCoreWake; /** * The connection's row version after the write: always for a shared * connection; for a personal one only when asked (`returnVersion` or * `reconnect`), which costs one owner read. */ version?: number; } | { kind: "refused"; reason: SubscriptionCoreConnectRefusal; }; /** * A reconnect of one exact connection (a route that names the account it * replaces): the sign-in must land on that connection at that version, or * nothing is written (`changed`). Never creates a connection. */ export type SubscriptionCoreReconnectTarget = { connectionId: string; /** The connection's row version the caller read (`SubscriptionCoreConnectionRow.version`). */ expectedVersion: number; }; export type SubscriptionCoreConnectScope = { accountId: string; /** null: the organization route. */ workspaceId: string | null; subjectId: string; /** * The caller asked for the person's own connection (a legacy `user` * scope): only a personal connection in their Personal workspace, else * refused (`forbidden`), never a shared one. */ personal?: boolean; /** Replace exactly this connection at this version (see the type). */ reconnect?: SubscriptionCoreReconnectTarget; /** Report a personal connection's row version too (one owner read). */ returnVersion?: boolean; }; /** * Connect (or reconnect) one account of this provider from a completed * sign-in. The caller delivers `wake` after commit. */ export declare function connectSubscriptionCoreConnection(db: Database, provider: SubscriptionCoreProvider, input: SubscriptionCoreConnectScope & SubscriptionCoreCredentialInput): Promise; export type SubscriptionCoreDisconnectOutcome = "removed" | "not_found" | "forbidden" | "unresolved_redemption" | "in_use"; export type SubscriptionCoreDisconnectResult = { outcome: SubscriptionCoreDisconnectOutcome; /** The canonical connection, when the route id resolved. */ connectionId: string | null; /** Workspaces whose Apps designation the removal cleared (for audit). */ clearedAppsWorkspaceIds: string[]; wake: SubscriptionCoreWake | null; }; /** * Who asked for a disconnect: each removed connection is audited * (`subscription_connection.disconnected`) in the transaction that removes it. */ export type SubscriptionCoreDisconnectAudit = { audit?: DisconnectAuditActor | null; }; /** * A route's account id (canonical, or a legacy id the drained cutover kept * as an alias) as the canonical connection id, resolved as the caller: an * organization administrator sees every alias of the organization (the * organization route, `workspaceId: null`, or any workspace route); anyone * else the aliases of connections the workspace reaches; a personal * connection's only its owner, in their own Personal workspace. Null when * nothing resolves; the caller's projection still decides whether the * connection is theirs to name. */ export declare function resolveSubscriptionCoreRouteConnectionId(db: Database, provider: SubscriptionCoreProvider, input: SubscriptionCoreConnectScope & { connectionId: string; }): Promise; /** * Disconnect one account of this provider. Throws the provider's * organization-managed error for an organization account named from a * workspace route. The caller delivers `wake` after commit. */ export declare function disconnectSubscriptionCoreConnection(db: Database, provider: SubscriptionCoreProvider, input: SubscriptionCoreConnectScope & SubscriptionCoreDisconnectAudit & { connectionId: string; }): Promise; export type SubscriptionCoreDisconnectAllResult = { removed: number; refused: { outcome: Exclude; connectionIds: string[]; } | null; clearedAppsWorkspaceIds: string[]; wake: SubscriptionCoreWake | null; }; /** * The workspace "disconnect all": every account of this provider the * workspace manages (or, in a person's own Personal workspace, their * personal connections), atomically. Any refusal leaves everything * connected. */ export declare function disconnectAllSubscriptionCoreConnections(db: Database, provider: SubscriptionCoreProvider, input: SubscriptionCoreConnectScope & SubscriptionCoreDisconnectAudit & { workspaceId: string; }): Promise;