/** * Utilitário de debug para requisições HTTP (apenas em desenvolvimento) */ export function debugRequest( method: string, url: string, headers: Record, body?: any, ) { if (process.env.NODE_ENV !== "development") return; const headersWithoutSensitive = Object.keys(headers).reduce( (accumulator, key) => { // Não logar valores sensíveis, apenas nomes if ( key.toLowerCase().includes("apikey") || key.toLowerCase().includes("authorization") ) { accumulator[key] = "[REDACTED]"; } else { accumulator[key] = headers[key]; } return accumulator; }, {} as Record, ); const bodyShape = body ? Object.keys(typeof body === "string" ? JSON.parse(body) : body) : []; console.log("[DEBUG] Request Preview:", { method, path: new URL(url).pathname, query: new URL(url).search, headerNames: Object.keys(headers), headers: headersWithoutSensitive, bodyShape, timestamp: new Date().toISOString(), }); }