/** * Records the OAuth proxy keeps in storage. Every value is encrypted by * `SecureStore`; token-bearing keys hold SHA-256 hashes, never tokens. * * @internal */ import type { UpstreamTokenSet, UpstreamUser } from "./upstream.js"; /** @internal A client known to the proxy: registered, CIMD, or configured. */ export interface ClientRecord { clientId: string; redirectUris: string[]; clientName?: string; /** Where the record came from. */ source: "dcr" | "cimd" | "pre-registered"; } /** @internal `txn:` — one sign-in in progress (10 minutes). */ export interface TransactionRecord { clientId: string; redirectUri: string; clientState?: string; codeChallenge: string; resource: string; scopes: string[]; /** PKCE verifier of the proxy's own upstream request. */ upstreamVerifier: string; /** Whether the upstream round was repeated to get a refresh token. */ retried?: boolean; } /** @internal `code:` — one-time authorization code (60 seconds). */ export interface CodeRecord { clientId: string; redirectUri: string; codeChallenge: string; resource: string; scopes: string[]; userKey: string; generation: string; } /** @internal `grant:` — one signed-in client of one user. */ export interface GrantRecord { id: string; clientId: string; userKey: string; /** Must equal the upstream record's generation, or the grant is dead. */ generation: string; scopes: string[]; resource: string; } /** @internal `at:` — one proxy access token. */ export interface AccessRecord { grantId: string; expiresAt: number; /** * Scopes of this token, narrower than the grant's after a refresh that * asked for less. Records written before this field read as the grant's. */ scopes?: string[]; } /** @internal `rt:` — one proxy refresh token. */ export interface RefreshRecord { grantId: string; clientId: string; state: "active" | "rotated"; /** Unix seconds when the token was rotated. */ rotatedAt?: number; /** Whether the one grace use after rotation was spent. */ graceUsed?: boolean; } /** @internal `up::` — upstream tokens of one user. */ export interface UpstreamRecord { userKey: string; /** Random id of this sign-in lineage; revoking the user replaces it. */ generation: string; /** Incremented on every write, for compare-and-set on refresh. */ version: number; tokens: UpstreamTokenSet; user: UpstreamUser; } /** @internal Storage key builders. */ export declare const keys: { client: (id: string) => string; transaction: (id: string) => string; upstreamState: (hash: string) => string; code: (hash: string) => string; codeUsed: (hash: string) => string; grant: (id: string) => string; /** Marks a grant as ended, so a refresh in progress cannot restore it. */ revokedGrant: (id: string) => string; access: (hash: string) => string; refresh: (hash: string) => string; refreshLock: (hash: string) => string; upstream: (userKey: string) => string; upstreamLock: (userKey: string) => string; };