/** * Fix all parameter block issues in endpoints.js */ import fs from 'fs'; import path from 'path'; function fixParameterBlocks() { console.log('=== FIXING ALL PARAMETER BLOCK ISSUES ==='); const endpointsPath = path.join(process.cwd(), 'src/config/endpoints.js'); let content = fs.readFileSync(endpointsPath, 'utf8'); console.log('📁 Reading endpoints.js...'); console.log(`📊 Original file size: ${content.length} characters`); // Create backup const backupPath = path.join(process.cwd(), `endpoints_param_fix_backup_${Date.now()}.js`); fs.writeFileSync(backupPath, content); console.log(`💾 Backup created: ${backupPath}`); // Fix all parameter blocks that are missing closing braces console.log('🔧 Fixing parameter blocks...'); // Pattern: parameters: { ... } followed by { (next endpoint) // This indicates missing closing brace and comma content = content.replace( /(parameters:\s*\{[^}]*\})\s*\n(\s*\{)/g, '$1\n },\n$2' ); // Pattern: parameters: { ... last_param } followed by { (next endpoint) // This indicates missing closing brace for parameters and endpoint content = content.replace( /(parameters:\s*\{[^}]*[^,]\s*\})\s*\n(\s*\{)/g, '$1\n },\n$2' ); // Fix missing closing braces after parameter definitions content = content.replace( /(password:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\}),?\s*\n(\s*\{)/g, '$1\n }\n },\n$2' ); // Fix specific pattern where parameters block is not closed content = content.replace( /(email:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\},?\s*\n\s*password:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\}),?\s*\n(\s*\{)/g, '$1\n }\n },\n$2' ); // Remove duplicate parameters (keep first occurrence) console.log('🔧 Removing duplicate parameters...'); content = content.replace( /(username:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\}),\s*\n\s*username:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\},?/g, '$1' ); content = content.replace( /(email:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\}),\s*\n\s*email:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\},?/g, '$1' ); content = content.replace( /(password:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\}),\s*\n\s*password:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"[^"]*"\s*\},?/g, '$1' ); // Add helper functions if missing console.log('🔧 Adding helper functions...'); if (!content.includes('export function getEndpointsByAuthType')) { const helperFunctions = ` /** * Helper function to get endpoints by authentication type */ export function getEndpointsByAuthType(authType) { switch (authType) { case AUTH_TYPES.PUBLIC: return PUBLIC_ENDPOINTS; case AUTH_TYPES.PROVIDER: return PROVIDER_ENDPOINTS; case AUTH_TYPES.PATIENT: return PATIENT_ENDPOINTS; case AUTH_TYPES.PARTNER: return PARTNER_ENDPOINTS; case AUTH_TYPES.AFFILIATE: return AFFILIATE_ENDPOINTS; case AUTH_TYPES.NETWORK: return NETWORK_ENDPOINTS; default: return []; } } /** * Get all endpoints */ export function getAllEndpoints() { return [ ...PUBLIC_ENDPOINTS, ...PROVIDER_ENDPOINTS, ...PATIENT_ENDPOINTS, ...PARTNER_ENDPOINTS, ...AFFILIATE_ENDPOINTS, ...NETWORK_ENDPOINTS ]; }`; content += helperFunctions; } // Write the fixed content fs.writeFileSync(endpointsPath, content); console.log(`📊 Fixed file size: ${content.length} characters`); console.log('✅ All parameter block issues fixed!'); return { backupPath: backupPath, success: true }; } // Run the fix try { const result = fixParameterBlocks(); console.log(`💾 Backup saved: ${result.backupPath}`); } catch (error) { console.error('❌ Error fixing parameter blocks:', error); }