Monorepo for Aesthetic.Computer aesthetic.computer
at main 116 lines 3.9 kB view raw
1#!/usr/bin/env node 2 3// Add Facebook/Instagram and Threads credentials to MongoDB secrets collection 4// Run: node scripts/add-facebook-secrets.mjs 5 6import { MongoClient } from "mongodb"; 7 8const MONGODB_CONNECTION_STRING = process.env.MONGODB_CONNECTION_STRING; 9const MONGODB_NAME = process.env.MONGODB_NAME || "aesthetic"; 10 11if (!MONGODB_CONNECTION_STRING) { 12 console.error("❌ MONGODB_CONNECTION_STRING environment variable is required"); 13 console.error(" Load from vault first: source ../aesthetic-computer-vault/.env"); 14 process.exit(1); 15} 16 17// Facebook/Instagram credentials from vault 18const FACEBOOK_APP_ID = process.env.FACEBOOK_APP_ID; 19const FACEBOOK_APP_SECRET = process.env.FACEBOOK_APP_SECRET; 20const THREADS_APP_ID = process.env.THREADS_APP_ID; 21const THREADS_APP_SECRET = process.env.THREADS_APP_SECRET; 22 23if (!FACEBOOK_APP_ID || !FACEBOOK_APP_SECRET) { 24 console.error("❌ FACEBOOK_APP_ID and FACEBOOK_APP_SECRET required"); 25 console.error(" Load from vault first: source ../aesthetic-computer-vault/.env"); 26 process.exit(1); 27} 28 29async function main() { 30 const client = new MongoClient(MONGODB_CONNECTION_STRING); 31 32 try { 33 await client.connect(); 34 console.log("✅ Connected to MongoDB"); 35 36 const db = client.db(MONGODB_NAME); 37 const secrets = db.collection("secrets"); 38 39 // Upsert Facebook/Instagram credentials 40 const facebookResult = await secrets.updateOne( 41 { _id: "facebook" }, 42 { 43 $set: { 44 _id: "facebook", 45 appId: FACEBOOK_APP_ID, 46 appSecret: FACEBOOK_APP_SECRET, 47 displayName: "Aesthetic.Computer", 48 purpose: "Instagram oEmbed and Graph API access", 49 updatedAt: new Date(), 50 }, 51 }, 52 { upsert: true } 53 ); 54 55 if (facebookResult.upsertedCount > 0) { 56 console.log("✅ Facebook/Instagram secret created"); 57 } else if (facebookResult.modifiedCount > 0) { 58 console.log("✅ Facebook/Instagram secret updated"); 59 } else { 60 console.log("ℹ️ Facebook/Instagram secret unchanged"); 61 } 62 63 // Upsert Threads credentials (if available) 64 if (THREADS_APP_ID && THREADS_APP_SECRET) { 65 const threadsResult = await secrets.updateOne( 66 { _id: "threads" }, 67 { 68 $set: { 69 _id: "threads", 70 appId: THREADS_APP_ID, 71 appSecret: THREADS_APP_SECRET, 72 displayName: "Aesthetic.Computer", 73 purpose: "Threads API access", 74 updatedAt: new Date(), 75 }, 76 }, 77 { upsert: true } 78 ); 79 80 if (threadsResult.upsertedCount > 0) { 81 console.log("✅ Threads secret created"); 82 } else if (threadsResult.modifiedCount > 0) { 83 console.log("✅ Threads secret updated"); 84 } else { 85 console.log("ℹ️ Threads secret unchanged"); 86 } 87 } 88 89 // Verify 90 const facebookDoc = await secrets.findOne({ _id: "facebook" }); 91 console.log("\n📋 Stored Facebook/Instagram document:"); 92 console.log(` _id: ${facebookDoc._id}`); 93 console.log(` appId: ${facebookDoc.appId.slice(0, 10)}...`); 94 console.log(` displayName: ${facebookDoc.displayName}`); 95 console.log(` purpose: ${facebookDoc.purpose}`); 96 console.log(` updatedAt: ${facebookDoc.updatedAt}`); 97 98 if (THREADS_APP_ID) { 99 const threadsDoc = await secrets.findOne({ _id: "threads" }); 100 console.log("\n📋 Stored Threads document:"); 101 console.log(` _id: ${threadsDoc._id}`); 102 console.log(` appId: ${threadsDoc.appId.slice(0, 10)}...`); 103 console.log(` displayName: ${threadsDoc.displayName}`); 104 console.log(` purpose: ${threadsDoc.purpose}`); 105 console.log(` updatedAt: ${threadsDoc.updatedAt}`); 106 } 107 108 } catch (error) { 109 console.error("❌ Error:", error.message); 110 process.exit(1); 111 } finally { 112 await client.close(); 113 } 114} 115 116main();