189 lines
6.0 KiB
JavaScript
189 lines
6.0 KiB
JavaScript
/**
|
|
* Comprehensive fix for all brace and structure issues
|
|
*/
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
function comprehensiveBraceFix() {
|
|
console.log('=== COMPREHENSIVE BRACE AND STRUCTURE FIX ===');
|
|
|
|
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_comprehensive_fix_backup_${Date.now()}.js`);
|
|
fs.writeFileSync(backupPath, content);
|
|
console.log(`💾 Backup created: ${backupPath}`);
|
|
|
|
// Step 1: Fix all parameter blocks that are missing closing braces
|
|
console.log('🔧 Step 1: Fix parameter block closures...');
|
|
|
|
// Pattern 1: parameters: { ... } followed directly by {
|
|
content = content.replace(
|
|
/(parameters:\s*\{[^}]*\})\s*\n(\s*\{)/g,
|
|
'$1\n },\n$2'
|
|
);
|
|
|
|
// Pattern 2: parameter definition followed directly by {
|
|
content = content.replace(
|
|
/(description:\s*"[^"]*"\s*\})\s*\n(\s*\{)/g,
|
|
'$1\n }\n },\n$2'
|
|
);
|
|
|
|
// Pattern 3: parameter without closing brace followed by {
|
|
content = content.replace(
|
|
/(description:\s*"[^"]*"\s*\}),?\s*\n(\s*\{)/g,
|
|
'$1\n }\n },\n$2'
|
|
);
|
|
|
|
// Step 2: Fix missing closing braces for endpoints
|
|
console.log('🔧 Step 2: Fix endpoint closures...');
|
|
|
|
// Pattern: description followed by comment and {
|
|
content = content.replace(
|
|
/(description:\s*"[^"]*"),?\s*\n\s*(\/\/[^\n]*)\n(\s*\{)/g,
|
|
'$1\n },\n\n$2\n$3'
|
|
);
|
|
|
|
// Pattern: last parameter followed by comment and {
|
|
content = content.replace(
|
|
/(dummy:\s*\{\s*type:\s*"string",\s*required:\s*false,\s*description:\s*"Dummy field"\s*\}),?\s*\n\s*(\/\/[^\n]*)\n(\s*\{)/g,
|
|
'$1\n }\n },\n\n$2\n$3'
|
|
);
|
|
|
|
// Step 3: Fix specific patterns
|
|
console.log('🔧 Step 3: Fix specific patterns...');
|
|
|
|
// Fix partner_email pattern
|
|
content = content.replace(
|
|
/(partner_email:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"Partner email"\s*\}),?\s*\n(\s*\{)/g,
|
|
'$1\n }\n },\n$2'
|
|
);
|
|
|
|
// Fix partner_id pattern
|
|
content = content.replace(
|
|
/(partner_id:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"Partner ID"\s*\}),?\s*\n(\s*\{)/g,
|
|
'$1\n }\n },\n$2'
|
|
);
|
|
|
|
// Fix token pattern
|
|
content = content.replace(
|
|
/(token:\s*\{\s*type:\s*"string",\s*required:\s*true,\s*description:\s*"Password reset token"\s*\}),?\s*\n(\s*\{)/g,
|
|
'$1\n }\n },\n$2'
|
|
);
|
|
|
|
// Step 4: Remove duplicate parameters
|
|
console.log('🔧 Step 4: Remove duplicate parameters...');
|
|
|
|
// Remove duplicate username 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'
|
|
);
|
|
|
|
// Remove duplicate email parameters
|
|
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'
|
|
);
|
|
|
|
// Remove duplicate password parameters
|
|
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'
|
|
);
|
|
|
|
// Step 5: Fix trailing commas
|
|
console.log('🔧 Step 5: Fix trailing commas...');
|
|
content = content.replace(/,(\s*\})/g, '$1');
|
|
content = content.replace(/,(\s*\])/g, '$1');
|
|
|
|
// Step 6: Add helper functions if missing
|
|
console.log('🔧 Step 6: Add 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('✅ Comprehensive fix completed!');
|
|
|
|
return {
|
|
backupPath: backupPath,
|
|
success: true
|
|
};
|
|
}
|
|
|
|
// Run the comprehensive fix
|
|
try {
|
|
const result = comprehensiveBraceFix();
|
|
console.log(`💾 Backup saved: ${result.backupPath}`);
|
|
|
|
// Test syntax
|
|
console.log('🔍 Testing syntax...');
|
|
const { spawn } = require('child_process');
|
|
const child = spawn('node', ['-c', 'src/config/endpoints.js'], {
|
|
stdio: ['pipe', 'pipe', 'pipe']
|
|
});
|
|
|
|
let stderr = '';
|
|
child.stderr.on('data', (data) => {
|
|
stderr += data.toString();
|
|
});
|
|
|
|
child.on('close', (code) => {
|
|
if (code === 0) {
|
|
console.log('✅ Syntax validation passed!');
|
|
} else {
|
|
console.error('❌ Syntax errors found:');
|
|
console.error(stderr);
|
|
}
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error during comprehensive fix:', error);
|
|
}
|