UNPKG

ccusage-on-cloud-client

Version:

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

62 lines (51 loc) 1.81 kB
const validateConfig = (config) => { const errors = []; const warnings = []; // APIURLの形式チェック(任意項目だがあれば検証) if (config.apiUrl && !config.apiUrl.startsWith('http://') && !config.apiUrl.startsWith('https://')) { errors.push('❌ CCUSAGE_ON_CLOUD_API_URL must start with http:// or https://'); } if (!config.username) { errors.push('❌ CCUSAGE_ON_CLOUD_USERNAME is required'); } if (!config.password) { errors.push('❌ CCUSAGE_ON_CLOUD_PASSWORD is required'); } // サーバーIDの検証 if (!config.serverId) { errors.push('❌ CCUSAGE_ON_CLOUD_SERVER_ID is required'); } else if (config.serverId.length > 255) { errors.push('❌ Server ID must be 255 characters or less'); } // インターバルの検証 if (config.interval) { try { // cron形式の簡易チェック const parts = config.interval.split(' '); if (parts.length < 5) { warnings.push('⚠️ Invalid cron format for CCUSAGE_ON_CLOUD_INTERVAL'); } } catch (e) { warnings.push('⚠️ Invalid cron format for CCUSAGE_ON_CLOUD_INTERVAL'); } } return { errors, warnings }; }; const printConfigHelp = () => { console.log(` 📚 Configuration Help ==================== Required environment variables: CCUSAGE_ON_CLOUD_API_URL - API server URL CCUSAGE_ON_CLOUD_USERNAME - Authentication username CCUSAGE_ON_CLOUD_PASSWORD - Authentication password CCUSAGE_ON_CLOUD_SERVER_ID - Unique identifier for this server Optional environment variables: CCUSAGE_ON_CLOUD_INTERVAL - Cron expression for data collection (default: */1 * * * *) Or create a .env file in the current directory with these values. `); }; module.exports = { validateConfig, printConfigHelp };