/** * API key resolution and storage through the harness credential store. * * The plugin config carries a credential REFERENCE (an env-var-style name), * never the secret. Per operation the value is resolved from dsh's optional * `credentials` service (which layers the launch environment, the user's * credential file and .env files) or, when the service is absent, from the * launch environment. Nothing is resolved at boot and the value is never * stored on any object beyond the request closure. * * @module dsh-realtimeavatar/credentials */ /** The subset of dsh's credential service this plugin uses (all optional at runtime). */ export interface CredentialService { resolve(ref: string): Promise<{ value: string; source?: string; } | undefined>; describe(ref: string): Promise<{ configured: boolean; source?: string; writable?: boolean; }>; set(ref: string, value: string): Promise; unset(ref: string): Promise; } /** Where the key came from, for status output (never the value). */ export interface KeyPosture { ref: string; configured: boolean; source: string; environment: 'live' | 'test' | 'unknown' | 'none'; } export type KeyErrorCode = 'RTA_KEY_MISSING' | 'RTA_KEY_INVALID' | 'RTA_KEY_SHADOWED' | 'RTA_KEY_STORE_UNAVAILABLE'; /** A coded, actionable key error. Messages never contain the key. */ export declare class KeyError extends Error { readonly code: KeyErrorCode; constructor(code: KeyErrorCode, message: string); } /** Validate a key's shape without ever echoing it. Returns the trimmed key. */ export declare function validateKeyFormat(value: string, ref: string): string; /** Environment tag from the key prefix. */ export declare function keyEnvironment(value: string): 'live' | 'test' | 'unknown'; /** Access to the optional credential service plus the launch environment. */ export interface KeySource { credentials?: CredentialService; env: NodeJS.ProcessEnv; } /** Resolve and validate the key for one operation. Throws a coded {@link KeyError}. */ export declare function resolveKey(source: KeySource, ref: string): Promise; /** Key posture for status output: configured?, source, environment tag. Never the value. */ export declare function describeKey(source: KeySource, ref: string): Promise; /** Store a key through the credential service. Throws a coded error when that is impossible. */ export declare function storeKey(source: KeySource, ref: string, value: string): Promise<{ environment: 'live' | 'test' | 'unknown'; length: number; }>; /** * Remove the stored key. Only the credential file is writable: a value from the * launching environment or a .env file cannot be edited from here, so the * result reports what still resolves afterwards. */ export declare function clearKey(source: KeySource, ref: string): Promise<{ removed: boolean; residual: KeyPosture; }>;