/** * Codex connect and disconnect on the shared subscription core (M3 PR 3b), * under the names and shapes M3 shipped. The writers themselves are * provider-neutral (`subscription-core/connections`); this module supplies * Codex as data and maps Codex's sign-in facts (the FedRAMP routing flag) * into the connection's provider state. * * API handlers reach this module only for the `core` cutover disposition, and * every write also rechecks the enabled cutover in the database. Nothing here * reads or writes a legacy Codex table. */ import type { Database } from "./database.js"; import { type SubscriptionCoreConnectRefusal, type SubscriptionCoreConnectScope, type SubscriptionCoreDisconnectAudit, type SubscriptionCoreDisconnectOutcome } from "./subscription-core/connections.js"; import type { SubscriptionCoreCodexWake } from "./subscription-core-codex-compat.js"; export { SubscriptionCoreCodexOrganizationManagedError } from "./subscription-core-codex-errors.js"; export type SubscriptionCoreCodexCredentialInput = { /** v1 envelope of JSON {access_token, refresh_token, id_token}. */ credentialEncrypted: string; providerAccountId: string | null; /** * The signed-in person within the upstream account (the id_token's ChatGPT * user). Two people's logins of one ChatGPT workspace are distinct shared * connections; only the same person's login reconnects in place. */ providerSubjectId: string | null; planType: string | null; isFedramp: boolean; 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 SubscriptionCoreCodexConnectRefusal = SubscriptionCoreConnectRefusal; export type SubscriptionCoreCodexConnectResult = { kind: "connected"; id: string; isNew: boolean; ownership: "shared" | "personal"; wake: SubscriptionCoreCodexWake; } | { kind: "refused"; reason: SubscriptionCoreCodexConnectRefusal; }; /** * Connect (or reconnect) one Codex account from a device-code sign-in. The * caller delivers `wake` after commit. */ export declare function connectSubscriptionCoreCodexConnection(db: Database, input: SubscriptionCoreConnectScope & SubscriptionCoreCodexCredentialInput): Promise; export type SubscriptionCoreCodexDisconnectOutcome = SubscriptionCoreDisconnectOutcome; export type SubscriptionCoreCodexDisconnectResult = { outcome: SubscriptionCoreCodexDisconnectOutcome; /** The canonical connection, when the route id resolved. */ connectionId: string | null; /** Workspaces whose Apps designation the removal cleared (for audit). */ clearedAppsWorkspaceIds: string[]; wake: SubscriptionCoreCodexWake | null; }; /** * Disconnect one Codex account. Throws `SubscriptionCoreCodexOrganizationManagedError` * for an organization account named from a workspace route. The caller * delivers `wake` after commit. */ export declare function disconnectSubscriptionCoreCodexConnection(db: Database, input: SubscriptionCoreConnectScope & SubscriptionCoreDisconnectAudit & { connectionId: string; }): Promise; /** * The legacy workspace "disconnect all": every account this workspace manages * (or, in a person's own Personal workspace, their personal connections), * atomically. Any refusal leaves everything connected. */ export declare function disconnectAllSubscriptionCoreCodexConnections(db: Database, input: SubscriptionCoreConnectScope & SubscriptionCoreDisconnectAudit & { workspaceId: string; }): Promise<{ removed: number; refused: { outcome: Exclude; connectionIds: string[]; } | null; clearedAppsWorkspaceIds: string[]; wake: SubscriptionCoreCodexWake | null; }>;