/** * @module @dotdo/postgres-shared/sanitize * * Connection string and credential sanitization utilities. * Ensures sensitive information like passwords and API keys * never appear in logs, error messages, or debug output. */ /** * The string used to replace redacted values */ export declare const REDACTED = "***"; /** * The string used to replace redacted values in URLs */ export declare const REDACTED_PASSWORD = ":***@"; /** * Sanitize a PostgreSQL connection string by removing sensitive credentials. * * Handles various connection string formats: * - Standard PostgreSQL: postgres://user:password@host:port/database * - With special characters in password: postgres://user:p%40ss@host/db * - Multiple @ symbols: postgres://user:pass@word@host/db * - Query string parameters: postgres://host/db?password=secret * - Alternative auth parameters: sslpassword, apikey, api_key, secret, token * * @param connectionString - The connection string to sanitize * @returns The sanitized connection string with credentials removed * * @example * ```typescript * sanitizeConnectionString('postgres://user:secret123@localhost/db') * // => 'postgres://user:***@localhost/db' * * sanitizeConnectionString('postgres://user:p%40ss@host/db?sslpassword=secret') * // => 'postgres://user:***@host/db?sslpassword=***' * ``` */ export declare function sanitizeConnectionString(connectionString: string | undefined | null): string; /** * Sanitize a URL by removing credentials from the authority section. * This is a more general function that works with any URL scheme. * * @param url - The URL to sanitize * @returns The sanitized URL with credentials removed * * @example * ```typescript * sanitizeUrl('https://user:secret@api.example.com/path') * // => 'https://user:***@api.example.com/path' * ``` */ export declare function sanitizeUrl(url: string | undefined | null): string; /** * Sanitize an error message by removing potential credentials. * Scans for common patterns that might contain sensitive data. * * @param message - The error message to sanitize * @returns The sanitized error message * * @example * ```typescript * sanitizeErrorMessage('Failed to connect to postgres://user:secret@host') * // => 'Failed to connect to postgres://user:***@host' * ``` */ export declare function sanitizeErrorMessage(message: string | undefined | null): string; /** * Recursively sanitize an object by redacting sensitive values. * Useful for logging configuration objects safely. * * @param obj - The object to sanitize * @param maxDepth - Maximum recursion depth (default: 10) * @returns A new object with sensitive values redacted * * @example * ```typescript * sanitizeObject({ * host: 'localhost', * user: 'admin', * password: 'secret123', * connectionString: 'postgres://user:pass@host/db' * }) * // => { host: 'localhost', user: 'admin', password: '***', connectionString: '***' } * ``` */ export declare function sanitizeObject>(obj: T | undefined | null, maxDepth?: number): T | null; /** * Create a safe debug string from a connection configuration. * Shows useful information without exposing credentials. * * @param config - The connection configuration * @returns A safe debug string * * @example * ```typescript * createSafeDebugString({ * host: 'db.example.com', * port: 5432, * database: 'mydb', * user: 'admin', * password: 'secret' * }) * // => 'host=db.example.com port=5432 database=mydb user=admin' * ``` */ export declare function createSafeDebugString(config: { host?: string; port?: number | string; database?: string; user?: string; ssl?: boolean | string | object; [key: string]: unknown; }): string; /** * Wrap a value for safe logging. * Returns a string representation that can be safely logged. * * @param value - The value to wrap * @returns A safe string representation */ export declare function safeLog(value: unknown): string; //# sourceMappingURL=sanitize.d.ts.map