/** * Claude's legacy route shapes on the shared subscription core (design * docs/design/subscription-core-2026-10-07.md, 5.3 "Claude track", C2b). * * Pools, settings and writers are the * provider-neutral ones; this module projects neutral rows into the legacy * Claude account shape and encodes an OAuth sign-in or a pasted setup token * as the adapter's stored credential. Nothing here reads or writes a legacy * Claude table or returns credential material. */ import type { ClaudeSubscriptionUsage } from "@opengeni/contracts"; import type { SubscriptionCorePoolAccount } from "./subscription-core/account-projection.js"; import { type Database } from "./database.js"; import { type SubscriptionCoreConnectionRow } from "./subscription-core/administration.js"; import { type SubscriptionCoreConnectResult, type SubscriptionCoreConnectScope } from "./subscription-core/connections.js"; import { type SubscriptionCoreClaudeCredential } from "./subscription-core-claude-adapter.js"; export type SubscriptionCoreClaudeScope = "workspace" | "user" | "organization"; /** A core Claude connection in the legacy account shape, with its usage reading. */ export type ClaudeSubscriptionAccountMetadata = SubscriptionCorePoolAccount; export type SubscriptionCoreClaudeAccount = SubscriptionCorePoolAccount & { usage: ClaudeSubscriptionUsage; }; /** * One core connection in the legacy Claude account shape. `version` is the * connection's row version, the one legacy credential version on the core: * the listing's `version` and `usage.credentialVersion` alike (the web * client treats a difference as a credential change). It moves on connect, * reconnect, rename and every status transition (needs_relogin, quarantine, * recovery), never on a successful refresh (that moves * `refresh_generation` only), and fences a reconnect. The legacy quota * columns and selection counters have no core counterpart and no Claude * route projects them. */ export declare function projectSubscriptionCoreClaudeAccount(row: SubscriptionCoreConnectionRow, scope: SubscriptionCoreClaudeScope, allocatorEnabled?: boolean): SubscriptionCoreClaudeAccount; export type SubscriptionCoreClaudePoolProjection = { /** As for SuperGrok: `user` in the viewer's Personal workspace with personal rows, else the shared source. */ source: SubscriptionCoreClaudeScope; accounts: SubscriptionCoreClaudeAccount[]; activeCredentialId: string | null; rotationEnabled: boolean; }; /** * A workspace's Claude pool for one viewer in the legacy shapes. Shared * connections carry the pool they serve this workspace from; personal ones * (listed only to their owner, only in the owner's Personal workspace) are * `user`, with their version read through the owner reader. Both reads share * one snapshot (repeatable read), so a concurrent disconnect cannot leave a * listed personal row without its version; a mismatch is a defect and fails. */ export declare function getSubscriptionCoreClaudeWorkspaceProjection(db: Database, input: { accountId: string; workspaceId: string; viewerSubjectId: string; }): Promise; /** The organization's own Claude accounts and rotation; empty for a non-administrator. */ export declare function getSubscriptionCoreClaudeOrganizationProjection(db: Database, input: { organizationId: string; subjectId: string; }): Promise; /** An HMAC provider account id: a credential proves no Claude account (`setup:`/`oauth:`). */ export declare function isSubscriptionCoreClaudeUnverifiedAccountId(id: string | null): boolean; /** * The identity a Claude reconnect writes, or null when the sign-in may not * replace the target (design 5.3, C2b, "Reconnect"). A core connection's * upstream identity never changes: * - a credential that proves an account (an OAuth account uuid) reconnects * only that account; * - one that proves none (a setup token, or an OAuth sign-in without an * account uuid) keeps the target's `setup:`/`oauth:` id, and only for such * a target, never one whose account was proven. */ export declare function subscriptionCoreClaudeReconnectIdentity(targetProviderAccountId: string | null, signedIn: { providerAccountId: string; verified: boolean; }): string | null; export type SubscriptionCoreClaudeConnectResult = SubscriptionCoreConnectResult /** * A reconnect whose credential may not replace the target: * `setup_token_over_sign_in` (a setup token for an account a sign-in * proved), `sign_in_over_unverified` (a proven sign-in for an account * whose id is unverified: a setup token's, or an earlier sign-in's without * an account uuid), else `different_account`. */ | { kind: "refused"; reason: "different_account" | "setup_token_over_sign_in" | "sign_in_over_unverified"; }; /** * Connect (or reconnect) one Claude account from an OAuth sign-in or a * pasted setup token through the neutral connect writer. The stored * credential is the legacy secret object (the adapter's codec), its format * the adapter's (`claude_oauth_v1` with OAuth, else * `claude_setup_token_v1`), and the adapter-owned provider state records * the granted OAuth scopes (`[]` for a setup token). The provider account * id is the legacy one (the account uuid, else the `oauth:`/`setup:` HMAC * id); the Claude account is the person's own, so it is also the provider * subject. A `reconnect` replaces exactly that connection at that version * and keeps its identity. The caller delivers `wake` after commit. */ export declare function connectSubscriptionCoreClaudeConnection(db: Database, input: SubscriptionCoreConnectScope & { encryptionKey: Uint8Array; credential: SubscriptionCoreClaudeCredential; /** The legacy provider account id this sign-in computes. */ providerAccountId: string; accountEmail: string | null; planType: string | null; label: string | null; connectedBySubjectId: string | null; /** The target of a reconnect and its listed provider account id. */ reconnectTarget?: { connectionId: string; expectedVersion: number; providerAccountId: string | null; }; }): Promise;