UNPKG

ccusage-on-cloud-client

Version:

Claude Code usage reporter client for ccusage-on-cloud-server

91 lines (76 loc) 3.05 kB
require('dotenv').config(); const axios = require('axios'); const fs = require('fs'); async function debugFetch() { const config = { apiUrl: process.env.CCUSAGE_ON_CLOUD_API_URL || 'https://ccusage-on-cloud-server.onrender.com/usage', username: process.env.CCUSAGE_ON_CLOUD_USERNAME || 'default-user', password: process.env.CCUSAGE_ON_CLOUD_PASSWORD || 'default-pass', }; console.log('Config:', config); try { const auth = Buffer.from(`${config.username}:${config.password}`).toString('base64'); const response = await axios.get(config.apiUrl, { headers: { 'Authorization': `Basic ${auth}` }, timeout: 10000 }); console.log('\n=== Server Response ==='); console.log('Server Version:', response.data.serverVersion); console.log('Total Reports:', response.data.rawReports?.length); if (response.data.rawReports?.[0]) { const firstReport = response.data.rawReports[0]; console.log('\nFirst Report:'); console.log('- Server ID:', firstReport.serverID); console.log('- Raw JSONL entries:', firstReport.rawJsonl?.length); if (firstReport.rawJsonl?.[0]) { console.log('\nFirst JSONL entry (raw):', typeof firstReport.rawJsonl[0]); // Try to parse it let parsed; if (typeof firstReport.rawJsonl[0] === 'string') { try { parsed = JSON.parse(firstReport.rawJsonl[0]); } catch (e) { // Double-encoded string parsed = JSON.parse(JSON.parse(firstReport.rawJsonl[0])); } } else { parsed = firstReport.rawJsonl[0]; } console.log('\nParsed data:'); console.log('- ID:', parsed.id); console.log('- totalTokens:', parsed.totalTokens); console.log('- tokenCounts:', parsed.tokenCounts); } } // Now convert and check the output const jsonlLines = []; response.data.rawReports.forEach((report) => { if (report.rawJsonl && report.rawJsonl.length > 0) { report.rawJsonl.forEach((rawData) => { try { const data = typeof rawData === 'string' ? rawData : JSON.stringify(rawData); jsonlLines.push(data); } catch (e) { console.error('Failed to process:', e); } }); } }); console.log('\n=== Generated JSONL ==='); console.log('Total lines:', jsonlLines.length); if (jsonlLines[0]) { console.log('\nFirst line (raw):', jsonlLines[0].substring(0, 200) + '...'); // Parse and check const firstParsed = JSON.parse(jsonlLines[0]); console.log('\nFirst line parsed:'); console.log('- totalTokens:', firstParsed.totalTokens); console.log('- tokenCounts:', firstParsed.tokenCounts); } // Write to file and check fs.writeFileSync('/tmp/debug-output.jsonl', jsonlLines.join('\n')); console.log('\nWrote to /tmp/debug-output.jsonl'); } catch (error) { console.error('Error:', error.message); } } debugFetch();