/** * Centralized Redis Key Builder * * Enforces consistent Redis key formatting across the entire application. * Standard format: :::<...segments> * * Key Design Principles: * 1. All keys MUST start with APP_NAME for application isolation * 2. All keys SHOULD include tenantId for multi-tenancy (use 'default' if no tenant context) * 3. Keys are sanitized to remove invalid Redis characters * 4. Use namespaces to organize keys by domain/feature */ /** * Options for building Redis keys with namespace support */ export interface RedisKeyBuilderOptions { /** Application name for key prefix (e.g., 'CDMBASE_TEST') */ appName: string; /** Tenant ID for multi-tenancy. Use 'default' for global/system keys */ tenantId?: string; /** Namespace for organizing keys (e.g., 'cache', 'session', 'tenant', 'config') */ namespace: string; /** Additional key segments (e.g., ['user', userId] or ['query', queryName]) */ segments: string[]; } /** * Builds a standardized Redis key with namespace and consistent formatting * * Format: :::::... * * @param options - Key building options * @returns Formatted and sanitized Redis key * * @example * ```typescript * // Cache key with tenant * buildRedisKeyWithNamespace({ * appName: 'CDMBASE_TEST', * tenantId: 'tenant-123', * namespace: 'cache', * segments: ['user', userId, 'profile'] * }); * // => "CDMBASE_TEST:tenant-123:cache:user:auth0-123:profile" * * // Global configuration key * buildRedisKeyWithNamespace({ * appName: 'CDMBASE_TEST', * tenantId: 'default', * namespace: 'config', * segments: ['extension', 'permissions'] * }); * // => "CDMBASE_TEST:default:config:extension:permissions" * * // Session key without tenant * buildRedisKeyWithNamespace({ * appName: 'CDMBASE_TEST', * namespace: 'session', * segments: ['abc123'] * }); * // => "CDMBASE_TEST:default:session:abc123" * ``` */ export declare function buildRedisKeyWithNamespace(options: RedisKeyBuilderOptions): string; /** * Builds a wildcard pattern for Redis KEYS command with namespace support * * @param options - Key building options (segments can include '*' wildcards) * @returns Redis key pattern for matching multiple keys * * @example * ```typescript * // Match all cache keys for a tenant * buildRedisKeyPatternWithNamespace({ * appName: 'CDMBASE_TEST', * tenantId: 'tenant-123', * namespace: 'cache', * segments: ['*'] * }); * // => "CDMBASE_TEST:tenant-123:cache:*" * * // Match all user cache keys across all tenants * buildRedisKeyPatternWithNamespace({ * appName: 'CDMBASE_TEST', * tenantId: '*', * namespace: 'cache', * segments: ['user', '*'] * }); * // => "CDMBASE_TEST:*:cache:user:*" * ``` */ export declare function buildRedisKeyPatternWithNamespace(options: RedisKeyBuilderOptions): string; /** * Common namespaces used across the application * These provide a standardized vocabulary for organizing Redis keys */ export declare const RedisNamespace: { /** GraphQL/API response caching */ readonly CACHE: "cache"; /** User session data */ readonly SESSION: "session"; /** Tenant information cache */ readonly TENANT: "tenant"; /** Configuration and settings */ readonly CONFIG: "config"; /** Extension/plugin data */ readonly EXTENSION: "extension"; /** Contribution points */ readonly CONTRIBUTION: "contribution"; /** Request-scoped storage */ readonly STORAGE: "storage"; /** Permission and access control */ readonly PERMISSION: "permission"; /** Temporary/TTL based data */ readonly TEMP: "temp"; }; export type RedisNamespaceType = (typeof RedisNamespace)[keyof typeof RedisNamespace]; /** * Extracts tenant ID from a Redis key if present * * @param key - Redis key to parse * @returns Tenant ID or null if not found/parseable */ export declare function extractTenantIdFromRedisKey(key: string): string | null; /** * Extracts namespace from a Redis key if present * * @param key - Redis key to parse * @returns Namespace or null if not found/parseable */ export declare function extractNamespaceFromRedisKey(key: string): string | null; /** * Validates if a key follows the standard format with namespace * * @param key - Redis key to validate * @returns True if key follows standard format */ export declare function isValidRedisKeyWithNamespace(key: string): boolean; /** * Parses a Redis key into its components * * @param key - Redis key to parse * @returns Parsed key components or null if invalid */ export interface ParsedRedisKey { appName: string; tenantId: string; namespace: string; segments: string[]; } export declare function parseRedisKey(key: string): ParsedRedisKey | null;