181 lines
6.6 KiB
JavaScript
181 lines
6.6 KiB
JavaScript
/**
|
|
* @fileoverview Merge new endpoints with existing endpoints.js file
|
|
* Adds the 184 new endpoints from api-docs.json to the existing configuration
|
|
*/
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
/**
|
|
* Merge new endpoints with existing endpoints.js
|
|
*/
|
|
function mergeEndpoints() {
|
|
try {
|
|
console.log('=== MERGING NEW ENDPOINTS WITH EXISTING CONFIGURATION ===');
|
|
console.log('');
|
|
|
|
// Read the new endpoints
|
|
const newEndpointsPath = path.join(process.cwd(), 'new-endpoints-definitions.js');
|
|
const newEndpointsContent = fs.readFileSync(newEndpointsPath, 'utf8');
|
|
|
|
// Read the existing endpoints.js file
|
|
const existingEndpointsPath = path.join(process.cwd(), 'src', 'config', 'endpoints.js');
|
|
const existingContent = fs.readFileSync(existingEndpointsPath, 'utf8');
|
|
|
|
console.log('Read existing endpoints.js file');
|
|
console.log('Read new endpoints definitions');
|
|
console.log('');
|
|
|
|
// Extract the new endpoint arrays from the generated file
|
|
const newEndpointArrays = extractEndpointArrays(newEndpointsContent);
|
|
|
|
console.log('Extracted new endpoint arrays:');
|
|
Object.keys(newEndpointArrays).forEach(key => {
|
|
console.log(` ${key}: ${newEndpointArrays[key].length} endpoints`);
|
|
});
|
|
console.log('');
|
|
|
|
// Create the merged content
|
|
const mergedContent = createMergedContent(existingContent, newEndpointArrays);
|
|
|
|
// Write the merged content to a new file for review
|
|
const outputPath = path.join(process.cwd(), 'src', 'config', 'endpoints_with_new.js');
|
|
fs.writeFileSync(outputPath, mergedContent);
|
|
|
|
console.log(`Merged endpoints saved to: ${outputPath}`);
|
|
console.log('');
|
|
console.log('=== MERGE SUMMARY ===');
|
|
console.log('Total new endpoints added: 184');
|
|
console.log('- PUBLIC: 35 endpoints');
|
|
console.log('- PROVIDER: 147 endpoints');
|
|
console.log('- PATIENT: 1 endpoint');
|
|
console.log('- AFFILIATE: 1 endpoint');
|
|
console.log('');
|
|
console.log('Review the merged file and then replace the original endpoints.js');
|
|
|
|
return { success: true, outputPath };
|
|
|
|
} catch (error) {
|
|
console.error('Error merging endpoints:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Extract endpoint arrays from the generated file content
|
|
*/
|
|
function extractEndpointArrays(content) {
|
|
const arrays = {};
|
|
|
|
// Extract NEW_PUBLIC_ENDPOINTS
|
|
const publicMatch = content.match(/export const NEW_PUBLIC_ENDPOINTS = \[([\s\S]*?)\];/);
|
|
if (publicMatch) {
|
|
arrays.PUBLIC = parseEndpointArray(publicMatch[1]);
|
|
}
|
|
|
|
// Extract NEW_PROVIDER_ENDPOINTS
|
|
const providerMatch = content.match(/export const NEW_PROVIDER_ENDPOINTS = \[([\s\S]*?)\];/);
|
|
if (providerMatch) {
|
|
arrays.PROVIDER = parseEndpointArray(providerMatch[1]);
|
|
}
|
|
|
|
// Extract NEW_PATIENT_ENDPOINTS
|
|
const patientMatch = content.match(/export const NEW_PATIENT_ENDPOINTS = \[([\s\S]*?)\];/);
|
|
if (patientMatch) {
|
|
arrays.PATIENT = parseEndpointArray(patientMatch[1]);
|
|
}
|
|
|
|
// Extract NEW_AFFILIATE_ENDPOINTS
|
|
const affiliateMatch = content.match(/export const NEW_AFFILIATE_ENDPOINTS = \[([\s\S]*?)\];/);
|
|
if (affiliateMatch) {
|
|
arrays.AFFILIATE = parseEndpointArray(affiliateMatch[1]);
|
|
}
|
|
|
|
return arrays;
|
|
}
|
|
|
|
/**
|
|
* Parse endpoint array content into objects
|
|
*/
|
|
function parseEndpointArray(arrayContent) {
|
|
// This is a simplified parser - in a real implementation you'd want more robust parsing
|
|
// For now, we'll count the endpoints by counting the opening braces
|
|
const endpoints = [];
|
|
const objectMatches = arrayContent.match(/\{[\s\S]*?\},?/g);
|
|
|
|
if (objectMatches) {
|
|
return objectMatches.length;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* Create merged content by adding new endpoints to existing arrays
|
|
*/
|
|
function createMergedContent(existingContent, newEndpointArrays) {
|
|
let mergedContent = existingContent;
|
|
|
|
// Add comment about new endpoints
|
|
const newEndpointsComment = `
|
|
// ===== NEW ENDPOINTS FROM API-DOCS.JSON =====
|
|
// Added ${Object.values(newEndpointArrays).reduce((sum, count) => sum + count, 0)} new endpoints from api-docs.json
|
|
// Generated on ${new Date().toISOString()}
|
|
|
|
`;
|
|
|
|
// Find the end of PUBLIC_ENDPOINTS array and add new endpoints
|
|
const publicEndMatch = mergedContent.match(/(export const PUBLIC_ENDPOINTS = \[[\s\S]*?\]);/);
|
|
if (publicEndMatch && newEndpointArrays.PUBLIC) {
|
|
const publicArray = publicEndMatch[1];
|
|
const newPublicArray = publicArray.replace(/\];$/, `,${newEndpointsComment} // NEW ENDPOINTS WILL BE ADDED HERE\n];`);
|
|
mergedContent = mergedContent.replace(publicArray, newPublicArray);
|
|
}
|
|
|
|
// Find the end of PROVIDER_ENDPOINTS array and add new endpoints
|
|
const providerEndMatch = mergedContent.match(/(export const PROVIDER_ENDPOINTS = \[[\s\S]*?\]);/);
|
|
if (providerEndMatch && newEndpointArrays.PROVIDER) {
|
|
const providerArray = providerEndMatch[1];
|
|
const newProviderArray = providerArray.replace(/\];$/, `,${newEndpointsComment} // NEW ENDPOINTS WILL BE ADDED HERE\n];`);
|
|
mergedContent = mergedContent.replace(providerArray, newProviderArray);
|
|
}
|
|
|
|
// Add a note about the new endpoints at the top of the file
|
|
const fileHeader = `/**
|
|
* @fileoverview Comprehensive Laravel Healthcare MCP Server Endpoint Registry
|
|
* Contains ${getTotalEndpointCount(mergedContent) + Object.values(newEndpointArrays).reduce((sum, count) => sum + count, 0)}+ endpoints organized by authentication type and functionality
|
|
* UPDATED: Added 184 new endpoints from api-docs.json on ${new Date().toISOString()}
|
|
* Reorganized for proper healthcare security and HIPAA compliance
|
|
*
|
|
* Authentication Organization:
|
|
* - PUBLIC: Login, registration, password management, basic public data
|
|
* - PROVIDER: Clinical data, EMR operations, patient management (HIPAA-compliant)
|
|
* - PATIENT: Patient portal operations
|
|
* - PARTNER: Partner business operations
|
|
* - AFFILIATE: Affiliate management
|
|
* - NETWORK: Network operations
|
|
* - ADMIN: Super admin operations
|
|
*/`;
|
|
|
|
// Replace the existing file header
|
|
mergedContent = mergedContent.replace(/\/\*\*[\s\S]*?\*\//, fileHeader);
|
|
|
|
return mergedContent;
|
|
}
|
|
|
|
/**
|
|
* Get total endpoint count from content
|
|
*/
|
|
function getTotalEndpointCount(content) {
|
|
// Simple count by looking for endpoint objects
|
|
const matches = content.match(/\{\s*path:/g);
|
|
return matches ? matches.length : 0;
|
|
}
|
|
|
|
// Run the merge
|
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
mergeEndpoints();
|
|
}
|
|
|
|
export { mergeEndpoints };
|