/** * Sanitizes a Redis key component to ensure it's valid and safe * * Redis keys can contain any binary sequence, but for best practices and compatibility: * - Avoid whitespace (spaces, tabs, newlines) - replace with underscores * - Avoid pipes (|) which are used in Auth0 userIds - replace with hyphens * - Avoid quotes and backslashes that could cause escaping issues - remove them * - Avoid control characters - remove them * * @param str - The string component to sanitize * @returns Sanitized string safe for use in Redis keys * * @example * ```typescript * sanitizeRedisKeyComponent('auth0|6120ecbb1e5c68006aabe17a') * // Returns: 'auth0-6120ecbb1e5c68006aabe17a' * * sanitizeRedisKeyComponent('user name with spaces') * // Returns: 'user_name_with_spaces' * ``` */ export declare const sanitizeRedisKeyComponent: (str: string) => string; /** * Validates if a tenantId looks like a MongoDB ObjectId hash * MongoDB ObjectIds are 24 character hexadecimal strings * * @param tenantId - The tenant ID to validate * @returns true if the tenantId appears to be a hash, false otherwise */ export declare const isHashLikeTenantId: (tenantId: string) => boolean; /** * Builds a standardized Redis key with proper tenant isolation and sanitization * * Key format: `{appName}:{tenantId}:{userId}:{...segments}` * - All components are sanitized to remove invalid characters * - TenantId is validated and replaced with 'default' if it appears to be a hash * - Components can be skipped by passing null/undefined * * @param options - Key building options * @param options.appName - Application name (e.g., 'CDMBASE_TEST') * @param options.tenantId - Tenant identifier (validated against hash pattern) * @param options.userId - User identifier (sanitized for Auth0 format) * @param options.segments - Additional key segments (array of strings) * @param options.logger - Optional logger for warnings * @returns Constructed Redis key * * @example * ```typescript * buildRedisKey({ * appName: 'CDMBASE_TEST', * tenantId: 'default', * userId: 'auth0|6120ecbb', * segments: ['currentPagePermissions', 'hash123'] * }) * // Returns: 'CDMBASE_TEST:default:auth0-6120ecbb:currentPagePermissions:hash123' * ``` */ export interface BuildRedisKeyOptions { appName: string; tenantId?: string; userId?: string; segments?: string[]; logger?: { warn: (message: string, ...args: unknown[]) => void; }; } export declare const buildRedisKey: ({ appName, tenantId, userId, segments, logger }: BuildRedisKeyOptions) => string; /** * Builds a wildcard pattern for Redis key matching * Useful for bulk operations like deleting all keys matching a pattern * * @param options - Pattern building options (same as buildRedisKey) * @returns Redis key pattern with wildcards * * @example * ```typescript * buildRedisKeyPattern({ * appName: 'CDMBASE_TEST', * tenantId: 'default', * segments: ['currentPagePermissions'] * }) * // Returns: 'CDMBASE_TEST:default:*:currentPagePermissions:*' * ``` */ export declare const buildRedisKeyPattern: ({ appName, tenantId, userId, segments, }: Omit) => string;