/** * The credential part of a unified cache key ('unified::'). The gateway's * UnifiedValidationCache keys its entries with this, and buildSpecificCacheKey below addresses them * with it, so an invalidation event - which carries the raw credential - hits exactly the key that * was written. Full SHA-256: two credentials share a key only through a SHA-256 collision, so a * cache hit can never be served to a different credential. */ export declare function hashUnifiedCacheCredential(credential: string): string; export interface CacheInvalidationEvent { type: 'api_key_disabled' | 'api_key_deleted' | 'aws_credential_disabled' | 'aws_credential_deleted' | 'manual_invalidation' | 'pattern_invalidation'; /** Credential events only. A 'pattern_invalidation' carries `pattern` instead. */ credentialId?: string; authType?: 'api_key' | 'aws_credential'; /** 'pattern_invalidation' only: the key pattern every subscriber must clear, e.g. 'unified-cache:*'. */ pattern?: string; reason?: string; timestamp: number; requestId?: string; } export interface CacheInvalidationConfig { valkeyUrl?: string; channelName: string; enableLogging: boolean; serviceName: string; } export interface CacheService { name: string; clearByCredentialId: (credentialId: string, authType: 'api_key' | 'aws_credential') => Promise; clearByPattern?: (pattern: string) => Promise; } /** * Shared cache invalidation service for both admin and gateway services * Handles publishing and subscribing to cache invalidation events via ValKey pub/sub */ export declare class CacheInvalidationService { private config; private subscriberClient?; private commandClient?; private isSubscriberConnected; private isCommandConnected; private registeredCacheServices; private logger; constructor(config: CacheInvalidationConfig, logger: any); /** * Initialize the cache invalidation service */ initialize(): Promise; /** * Register a cache service for invalidation (gateway only) */ registerCacheService(service: CacheService): void; /** * Invalidate cache for an API key (admin service publishes, gateway receives) */ invalidateApiKey(keyId: string, reason?: 'disabled' | 'deleted' | 'manual', requestId?: string): Promise; /** * Invalidate cache for AWS credentials */ invalidateAwsCredential(credentialId: string, reason?: 'disabled' | 'deleted' | 'manual', requestId?: string): Promise; /** * Bulk invalidate multiple cache entries */ bulkInvalidate(invalidations: Array<{ credentialId: string; authType: 'api_key' | 'aws_credential'; reason?: string; }>): Promise; /** * Invalidate every cache entry matching a key pattern, everywhere. * * Deleting the Valkey keys is only half the job: each gateway process also holds the same * validations in memory, and nothing in a KEYS+DEL reaches those. So this clears the * distributed keys AND publishes a 'pattern_invalidation' that every subscriber dispatches to * its registered caches' clearByPattern. Used when a change affects everyone at once - a * default entitlement catalog change, for instance - where per-credential invalidation would * mean enumerating every credential in the system. * * Distributed keys go first: a subscriber that cleared its memory before the Valkey keys were * gone would just repopulate from them. */ invalidatePattern(pattern: string, reason?: string, requestId?: string): Promise; /** * Clear specific cache keys directly */ clearCacheKey(cacheKey: string): Promise; /** * Clear all cache keys matching a pattern */ clearCachePattern(pattern: string): Promise; /** * Handle incoming cache invalidation events (gateway only) */ private handleInvalidationEvent; /** * Process a cache invalidation event (gateway only). * * Public so the dispatch can be driven directly by a test: everything above it is ValKey * plumbing, and a wiring bug here (an event type nobody dispatches) is invisible from outside. */ processInvalidationEvent(event: CacheInvalidationEvent): Promise; /** * A pattern event reaches the in-process caches, which a KEYS+DEL on ValKey never touches. * A registered cache without clearByPattern is skipped rather than treated as an error - the * capability is optional on the CacheService contract. */ private processPatternInvalidation; /** * Build specific cache key for a credential (replaces wildcard pattern approach) */ private buildSpecificCacheKey; /** * Publish cache invalidation event to ValKey pub/sub */ private publishInvalidationEvent; /** * Get service status */ getStatus(): { commandConnected: boolean; subscriberConnected: boolean; valkeyAvailable: boolean; channelName: string; serviceName: string; registeredServices: string[]; }; /** * Shutdown the service */ shutdown(): Promise; }