tractatus/scripts/import-research-doc.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

71 lines
2.7 KiB
JavaScript

/**
* Import tractatus-framework-research document from JSON file
*/
const { MongoClient } = require('mongodb');
const fs = require('fs');
require('dotenv').config({ path: '/var/www/tractatus/.env' });
async function run() {
console.log('═══════════════════════════════════════════════════════════');
console.log(' IMPORTING RESEARCH DOCUMENT TO PRODUCTION');
console.log('═══════════════════════════════════════════════════════════\n');
// Read JSON file
const doc = JSON.parse(fs.readFileSync('/tmp/tractatus-framework-research.json', 'utf8'));
console.log(`📄 Loaded: ${doc.title}`);
console.log(` Slug: ${doc.slug}`);
console.log(` Category: ${doc.category}`);
console.log(` Order: ${doc.order}`);
console.log(` Sections: ${doc.sections?.length || 0}\n`);
// Connect to production
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017';
const DB_NAME = process.env.MONGODB_DB || 'tractatus_prod';
console.log(`Database: ${DB_NAME}`);
console.log(`URI: ${MONGODB_URI.replace(/:[^:]*@/, ':***@')}\n`);
const client = new MongoClient(MONGODB_URI);
await client.connect();
const db = client.db(DB_NAME);
const collection = db.collection('documents');
// Check if exists
const existing = await collection.findOne({ slug: doc.slug });
if (existing) {
console.log('⚠️ Document already exists - replacing...\n');
const result = await collection.replaceOne(
{ slug: doc.slug },
doc
);
console.log(`✅ Replaced: ${result.modifiedCount} document(s)`);
} else {
console.log('📝 Inserting new document...\n');
const result = await collection.insertOne(doc);
console.log(`✅ Inserted with ID: ${result.insertedId}`);
}
// Verify
const verification = await collection.findOne(
{ slug: doc.slug },
{ projection: { title: 1, category: 1, order: 1, visibility: 1 } }
);
console.log('\n🔍 Verification:');
console.log(JSON.stringify(verification, null, 2));
await client.close();
console.log('\n═══════════════════════════════════════════════════════════');
console.log(' IMPORT COMPLETE');
console.log('═══════════════════════════════════════════════════════════\n');
}
run().catch(console.error);