UNPKG

@settlemint/sdk-utils

Version:

Shared utilities and helper functions for SettleMint SDK modules

78 lines 2.78 kB
//#region src/logging/logger.d.ts /** * Log levels supported by the logger */ type LogLevel = "debug" | "info" | "warn" | "error" | "none"; /** * Configuration options for the logger * @interface LoggerOptions */ interface LoggerOptions { /** The minimum log level to output */ level?: LogLevel; /** The prefix to add to the log message */ prefix?: string; } /** * Simple logger interface with basic logging methods * @interface Logger */ interface Logger { /** Log debug information */ debug: (message: string, ...args: unknown[]) => void; /** Log general information */ info: (message: string, ...args: unknown[]) => void; /** Log warnings */ warn: (message: string, ...args: unknown[]) => void; /** Log errors */ error: (message: string, ...args: unknown[]) => void; } /** * Creates a simple logger with configurable log level * * @param options - Configuration options for the logger * @param options.level - The minimum log level to output (default: warn) * @param options.prefix - The prefix to add to the log message (default: "") * @returns A logger instance with debug, info, warn, and error methods * * @example * import { createLogger } from "@/utils/logging/logger"; * * const logger = createLogger({ level: 'info' }); * * logger.info('User logged in', { userId: '123' }); * logger.error('Operation failed', new Error('Connection timeout')); */ declare function createLogger(options?: LoggerOptions): Logger; /** * Default logger instance with standard configuration */ declare const logger: Logger; //#endregion //#region src/logging/request-logger.d.ts /** * Logs the request and duration of a fetch call (> 500ms is logged as warn, otherwise info) * @param logger - The logger to use * @param name - The name of the request * @param fn - The fetch function to use * @returns The fetch function */ declare function requestLogger(logger: Logger, name: string, fn: typeof fetch): (...args: Parameters<typeof fetch>) => Promise<Response>; //#endregion //#region src/logging/mask-tokens.d.ts /** * Masks sensitive SettleMint tokens in output text by replacing them with asterisks. * Handles personal access tokens (PAT), application access tokens (AAT), and service account tokens (SAT). * * @param output - The text string that may contain sensitive tokens * @returns The text with any sensitive tokens masked with asterisks * @example * import { maskTokens } from "@settlemint/sdk-utils/terminal"; * * // Masks a token in text * const masked = maskTokens("Token: sm_pat_****"); // "Token: ***" */ declare const maskTokens: (output: string) => string; //#endregion export { type LogLevel, type Logger, type LoggerOptions, createLogger, maskTokens, requestLogger }; //# sourceMappingURL=logging.d.ts.map