migrate-jwt-references.jsā¢3.3 kB
#!/usr/bin/env node
/**
* JWT Reference Migration Tool
* @version 1.0.0
* @description Updates critical files to use centralized JWT configuration
*/
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
const PROJECT_ROOT = '/Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc';
const CRITICAL_FILES = [
'dist/browser-automation-api-jit-v5.1.0.js',
'tools/servers/jwt-redirect-server-v1.0.2.js'
];
const MIGRATION_PATTERNS = [
{
description: 'Replace hardcoded archive/authentication path',
pattern: /const tokenPath = join\(PROJECT_ROOT, 'archive\/authentication\/correct-jwt-new\.txt'\);/g,
replacement: `import { getJWTToken } from '../src/config/jwt-config.js';\n // JWT token loaded via centralized config`
},
{
description: 'Replace readFileSync with centralized loader',
pattern: /this\.jwtToken = readFileSync\(tokenPath, 'utf-8'\)\.trim\(\);/g,
replacement: 'this.jwtToken = getJWTToken();'
},
{
description: 'Replace fallback path loading',
pattern: /const fallbackPath = join\(PROJECT_ROOT, 'correct-jwt-new\.txt'\);[\s\S]*?readFileSync\(fallbackPath, 'utf-8'\)\.trim\(\);/g,
replacement: 'this.jwtToken = getJWTToken(); // Centralized loading with built-in fallbacks'
},
{
description: 'Replace JWT redirect server path',
pattern: /this\.jwtFilePath = path\.join\(__dirname, 'correct-jwt-new\.txt'\);/g,
replacement: `import { getJWTPrimaryPath } from '../../src/config/jwt-config.js';\n this.jwtFilePath = getJWTPrimaryPath();`
}
];
function migrateFile(filePath) {
console.log(`\nš§ Migrating: ${filePath}`);
try {
let content = readFileSync(join(PROJECT_ROOT, filePath), 'utf-8');
let modified = false;
for (const pattern of MIGRATION_PATTERNS) {
if (pattern.pattern.test(content)) {
content = content.replace(pattern.pattern, pattern.replacement);
modified = true;
console.log(` ā
Applied: ${pattern.description}`);
}
}
if (modified) {
// Create backup
const backupPath = join(PROJECT_ROOT, filePath + '.backup-pre-jwt-migration');
writeFileSync(backupPath, readFileSync(join(PROJECT_ROOT, filePath)));
console.log(` š¦ Backup created: ${backupPath}`);
// Write updated file
writeFileSync(join(PROJECT_ROOT, filePath), content);
console.log(` ā
File updated: ${filePath}`);
} else {
console.log(` ā¹ļø No changes needed`);
}
} catch (error) {
console.error(` ā Error migrating ${filePath}:`, error.message);
}
}
function main() {
console.log('š JWT Reference Migration Tool v1.0.0');
console.log('š Migrating critical files to use centralized JWT configuration...\n');
for (const file of CRITICAL_FILES) {
migrateFile(file);
}
console.log(`
ā
Migration complete!
š Next Steps:
1. Test the migrated files to ensure they work correctly
2. Gradually migrate other files using the centralized JWT config
3. Remove duplicate JWT token files once migration is complete
š Centralized JWT Location: /config/jwt-token.txt
š Configuration Module: /src/config/jwt-config.js
ā ļø Note: Backups were created for all modified files with .backup-pre-jwt-migration extension
`);
}
main();