tractatus/scripts/compare-glossaries.js
TheFlow be53ab36f8 fix(security): secure archived documents endpoint and reorganize docs UI
Security:
- Add authentication to /api/documents/archived endpoint (admin-only)
- Prevent public exposure of 108 archived/internal documents

Documentation UI:
- Remove duplicate hardcoded Resources section from docs.html
- Add Resources category to docs-app.js for implementation guides
- Move 3 implementation guides from Getting Started to Resources
- Move Glossary from Technical Reference to Getting Started
- Set Research & Theory section to collapsed by default
- Update service worker cache version to 0.1.4

Migration Scripts:
- Add scripts for document category reorganization
- Add scripts for research document migration to production
- Add scripts for glossary verification and comparison

Files changed:
- public/docs.html: Remove duplicate Resources section
- public/js/docs-app.js: Add Resources category, collapse Research
- public/service-worker.js: Bump cache to v0.1.4
- src/routes/documents.routes.js: Secure /archived endpoint
- scripts/*: Add 10 migration/diagnostic scripts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 00:03:13 +13:00

97 lines
3.5 KiB
JavaScript

/**
* Compare Glossary documents in dev and production
*/
const { MongoClient } = require('mongodb');
require('dotenv').config({ path: '/var/www/tractatus/.env' });
async function run() {
console.log('═══════════════════════════════════════════════════════════');
console.log(' COMPARING GLOSSARY DOCUMENTS');
console.log('═══════════════════════════════════════════════════════════\n');
// Check dev
const devClient = new MongoClient('mongodb://localhost:27017');
await devClient.connect();
const devDocs = await devClient.db('tractatus_dev').collection('documents').find({
slug: { $regex: 'glossary', $options: 'i' }
}).project({
slug: 1,
title: 1,
visibility: 1,
category: 1,
sections: 1
}).toArray();
await devClient.close();
console.log(`📚 DEV Database: ${devDocs.length} glossary document(s)\n`);
devDocs.forEach((doc, idx) => {
console.log(`${idx + 1}. ${doc.title}`);
console.log(` Slug: ${doc.slug}`);
console.log(` Visibility: ${doc.visibility}`);
console.log(` Category: ${doc.category || 'none'}`);
console.log(` Sections: ${doc.sections?.length || 0}`);
console.log('');
});
// Check production
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017';
const DB_NAME = process.env.MONGODB_DB || 'tractatus_prod';
const prodClient = new MongoClient(MONGODB_URI);
await prodClient.connect();
const prodDocs = await prodClient.db(DB_NAME).collection('documents').find({
slug: { $regex: 'glossary', $options: 'i' }
}).project({
slug: 1,
title: 1,
visibility: 1,
category: 1,
sections: 1
}).toArray();
await prodClient.close();
console.log(`📦 PRODUCTION Database: ${prodDocs.length} glossary document(s)\n`);
prodDocs.forEach((doc, idx) => {
console.log(`${idx + 1}. ${doc.title}`);
console.log(` Slug: ${doc.slug}`);
console.log(` Visibility: ${doc.visibility}`);
console.log(` Category: ${doc.category || 'none'}`);
console.log(` Sections: ${doc.sections?.length || 0}`);
console.log('');
});
console.log('═══════════════════════════════════════════════════════════');
console.log(' RECOMMENDATION');
console.log('═══════════════════════════════════════════════════════════\n');
// Find the best one
const allDocs = [...devDocs.map(d => ({...d, source: 'dev'})), ...prodDocs.map(d => ({...d, source: 'prod'}))];
const best = allDocs.reduce((best, doc) => {
const sectionsCount = doc.sections?.length || 0;
const bestSections = best.sections?.length || 0;
return sectionsCount > bestSections ? doc : best;
}, allDocs[0]);
if (best) {
console.log(`Best version: ${best.slug} (${best.source})`);
console.log(` ${best.sections?.length || 0} sections`);
console.log(` Currently: ${best.visibility}`);
console.log('');
if (best.visibility !== 'public') {
console.log('✅ Action: Unarchive this document and set visibility=public');
} else {
console.log('✅ Already public - no action needed');
}
}
console.log('');
}
run().catch(console.error);