| | |
| | |
| | |
| | |
| | |
| | |
| | export function safeStringify(obj: unknown, maxLength = 1000): string { |
| | try { |
| | const str = JSON.stringify(obj, (key, value) => { |
| | |
| | if ( |
| | key === 'client_secret' || |
| | key === 'Authorization' || |
| | key.toLowerCase().includes('token') || |
| | key.toLowerCase().includes('password') |
| | ) { |
| | return typeof value === 'string' && value.length > 6 |
| | ? `${value.substring(0, 3)}...${value.substring(value.length - 3)}` |
| | : '***MASKED***'; |
| | } |
| | return value; |
| | }); |
| |
|
| | if (str && str.length > maxLength) { |
| | return `${str.substring(0, maxLength)}... (truncated)`; |
| | } |
| | return str; |
| | } catch (error) { |
| | return `[Error stringifying object: ${(error as Error).message}]`; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export function logHeaders(headers: Headers | undefined | null): string { |
| | const headerObj: Record<string, string> = {}; |
| | if (!headers || typeof headers.entries !== 'function') { |
| | return 'No headers available'; |
| | } |
| | for (const [key, value] of headers.entries()) { |
| | if (key.toLowerCase() === 'authorization' || key.toLowerCase().includes('secret')) { |
| | headerObj[key] = '***MASKED***'; |
| | } else { |
| | headerObj[key] = value; |
| | } |
| | } |
| | return safeStringify(headerObj); |
| | } |
| |
|