A Deno-compatible AT Protocol OAuth client that serves as a drop-in replacement for @atproto/oauth-client-node
at main 124 lines 3.1 kB view raw
1/** 2 * @fileoverview Logging abstraction for OAuth client operations 3 * @module 4 */ 5 6/** 7 * Logger interface for OAuth client operations. 8 * 9 * Implement this interface to provide custom logging for the OAuth client. 10 * By default, the client uses a no-op logger that produces no output. 11 * 12 * @example Custom logger implementation 13 * ```ts 14 * class ConsoleLogger implements Logger { 15 * debug(message: string, ...args: unknown[]): void { 16 * console.debug(`[DEBUG] ${message}`, ...args); 17 * } 18 * 19 * info(message: string, ...args: unknown[]): void { 20 * console.info(`[INFO] ${message}`, ...args); 21 * } 22 * 23 * warn(message: string, ...args: unknown[]): void { 24 * console.warn(`[WARN] ${message}`, ...args); 25 * } 26 * 27 * error(message: string, ...args: unknown[]): void { 28 * console.error(`[ERROR] ${message}`, ...args); 29 * } 30 * } 31 * 32 * const client = new OAuthClient({ 33 * // ... other config 34 * logger: new ConsoleLogger(), 35 * }); 36 * ``` 37 */ 38export interface Logger { 39 /** 40 * Log debug-level message (lowest priority). 41 * Use for detailed diagnostic information. 42 */ 43 debug(message: string, ...args: unknown[]): void; 44 45 /** 46 * Log info-level message. 47 * Use for general informational messages. 48 */ 49 info(message: string, ...args: unknown[]): void; 50 51 /** 52 * Log warning-level message. 53 * Use for potentially harmful situations. 54 */ 55 warn(message: string, ...args: unknown[]): void; 56 57 /** 58 * Log error-level message (highest priority). 59 * Use for error events that might still allow the application to continue. 60 */ 61 error(message: string, ...args: unknown[]): void; 62} 63 64/** 65 * No-op logger implementation that produces no output. 66 * 67 * This is the default logger used by the OAuth client when no custom 68 * logger is provided. All log methods are no-ops. 69 * 70 * @example 71 * ```ts 72 * const logger = new NoOpLogger(); 73 * logger.info("This will not be logged anywhere"); 74 * ``` 75 */ 76export class NoOpLogger implements Logger { 77 debug(_message: string, ..._args: unknown[]): void { 78 // No-op 79 } 80 81 info(_message: string, ..._args: unknown[]): void { 82 // No-op 83 } 84 85 warn(_message: string, ..._args: unknown[]): void { 86 // No-op 87 } 88 89 error(_message: string, ..._args: unknown[]): void { 90 // No-op 91 } 92} 93 94/** 95 * Console logger implementation for development and debugging. 96 * 97 * Logs all messages to the console with appropriate log levels. 98 * Useful for development but not recommended for production. 99 * 100 * @example 101 * ```ts 102 * const client = new OAuthClient({ 103 * // ... other config 104 * logger: new ConsoleLogger(), 105 * }); 106 * ``` 107 */ 108export class ConsoleLogger implements Logger { 109 debug(message: string, ...args: unknown[]): void { 110 console.debug(`[DEBUG] ${message}`, ...args); 111 } 112 113 info(message: string, ...args: unknown[]): void { 114 console.info(`[INFO] ${message}`, ...args); 115 } 116 117 warn(message: string, ...args: unknown[]): void { 118 console.warn(`[WARN] ${message}`, ...args); 119 } 120 121 error(message: string, ...args: unknown[]): void { 122 console.error(`[ERROR] ${message}`, ...args); 123 } 124}