Monorepo for Aesthetic.Computer aesthetic.computer
at main 77 lines 2.3 kB view raw
1#!/usr/bin/env node 2 3// Add PayPal credentials to MongoDB secrets collection 4// Run: node scripts/add-paypal-secret.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// PayPal credentials from vault 18const PAYPAL_CLIENT_ID = process.env.PAYPAL_CLIENT_ID; 19const PAYPAL_CLIENT_SECRET = process.env.PAYPAL_CLIENT_SECRET; 20 21if (!PAYPAL_CLIENT_ID || !PAYPAL_CLIENT_SECRET) { 22 console.error("❌ PAYPAL_CLIENT_ID and PAYPAL_CLIENT_SECRET required"); 23 console.error(" Load from vault first: source ../aesthetic-computer-vault/.env"); 24 process.exit(1); 25} 26 27async function main() { 28 const client = new MongoClient(MONGODB_CONNECTION_STRING); 29 30 try { 31 await client.connect(); 32 console.log("✅ Connected to MongoDB"); 33 34 const db = client.db(MONGODB_NAME); 35 const secrets = db.collection("secrets"); 36 37 // Upsert PayPal credentials 38 const result = await secrets.updateOne( 39 { _id: "paypal" }, 40 { 41 $set: { 42 _id: "paypal", 43 clientId: PAYPAL_CLIENT_ID, 44 clientSecret: PAYPAL_CLIENT_SECRET, 45 account: "mail@aesthetic.computer", 46 apiUrl: "https://api-m.paypal.com", 47 updatedAt: new Date(), 48 }, 49 }, 50 { upsert: true } 51 ); 52 53 if (result.upsertedCount > 0) { 54 console.log("✅ PayPal secret created"); 55 } else if (result.modifiedCount > 0) { 56 console.log("✅ PayPal secret updated"); 57 } else { 58 console.log("ℹ️ PayPal secret unchanged"); 59 } 60 61 // Verify 62 const doc = await secrets.findOne({ _id: "paypal" }); 63 console.log("📋 Stored document:"); 64 console.log(` _id: ${doc._id}`); 65 console.log(` clientId: ${doc.clientId.slice(0, 10)}...`); 66 console.log(` account: ${doc.account}`); 67 console.log(` updatedAt: ${doc.updatedAt}`); 68 69 } catch (error) { 70 console.error("❌ Error:", error.message); 71 process.exit(1); 72 } finally { 73 await client.close(); 74 } 75} 76 77main();