tractatus/scripts/fix-document-organization.js
TheFlow b199a3e265 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

108 lines
4.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Fix document organization issues:
* 1. Move Executive Brief to research-theory
* 2. Migrate tractatus-framework-research to production
* 3. Ensure both are viewable as card documents
*/
const { MongoClient } = require('mongodb');
require('dotenv').config({ path: '/var/www/tractatus/.env' });
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017';
const DB_NAME = process.env.MONGODB_DB || 'tractatus_prod';
async function run() {
const client = new MongoClient(MONGODB_URI);
await client.connect();
const db = client.db(DB_NAME);
const collection = db.collection('documents');
console.log('═══════════════════════════════════════════════════════════');
console.log(' FIXING DOCUMENT ORGANIZATION');
console.log('═══════════════════════════════════════════════════════════\n');
// 1. Move Executive Brief from getting-started to research-theory
console.log('1⃣ Moving Executive Brief to Research & Theory...');
const execBriefResult = await collection.updateOne(
{ slug: 'executive-summary-tractatus-inflection-point' },
{
$set: {
category: 'research-theory',
order: 1, // First in research section
updated_at: new Date()
}
}
);
if (execBriefResult.modifiedCount > 0) {
console.log(' ✅ Executive Brief moved to research-theory (order: 1)');
} else {
console.log(' ⚠️ Executive Brief not found or already correct');
}
// 2. Check if tractatus-framework-research exists in production
console.log('\n2⃣ Checking for tractatus-framework-research...');
const researchDoc = await collection.findOne({ slug: 'tractatus-framework-research' });
if (!researchDoc) {
console.log(' ❌ Document missing from production - needs migration from dev');
console.log(' 📝 Run migration script to copy from dev to prod');
} else {
console.log(' ✅ Document exists in production');
console.log(` Category: ${researchDoc.category}`);
console.log(` Order: ${researchDoc.order}`);
console.log(` Sections: ${researchDoc.sections?.length || 0}`);
// Ensure it's in research-theory with correct order
await collection.updateOne(
{ slug: 'tractatus-framework-research' },
{
$set: {
category: 'research-theory',
order: 2, // Second in research section (after Executive Brief)
updated_at: new Date()
}
}
);
console.log(' ✅ Updated category and order');
}
// 3. Renumber other research-theory documents
console.log('\n3⃣ Renumbering research-theory documents...');
const researchDocs = await collection.find({ category: 'research-theory' }).toArray();
console.log(` Found ${researchDocs.length} research documents`);
const orderedSlugs = [
'executive-summary-tractatus-inflection-point', // 1
'tractatus-framework-research', // 2
'pluralistic-values-research-foundations', // 3
'the-27027-incident-a-case-study-in-pattern-recognition-bias', // 4
'real-world-ai-governance-a-case-study-in-framework-failure-and-recovery', // 5
'llm-integration-feasibility-research-scope', // 6
'research-topic-concurrent-session-architecture', // 7
'research-topic-rule-proliferation-transactional-overhead' // 8
];
for (let i = 0; i < orderedSlugs.length; i++) {
await collection.updateOne(
{ slug: orderedSlugs[i] },
{ $set: { order: i + 1, updated_at: new Date() } }
);
}
console.log(` ✅ Updated order for ${orderedSlugs.length} documents`);
console.log('\n═══════════════════════════════════════════════════════════');
console.log(' SUMMARY');
console.log('═══════════════════════════════════════════════════════════\n');
console.log('✅ Executive Brief moved to research-theory');
console.log('✅ Document ordering updated');
console.log('');
await client.close();
}
run().catch(console.error);