const sdk = require('node-appwrite'); const client = new sdk.Client(); const databases = new sdk.Databases(client); const ENDPOINT = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1'; const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c'; const API_KEY = process.env.APPWRITE_API_KEY || 'standard_ee81a4ca6784c0fa6a23abab0a983dbba9cd0c2d8e211a00c759d9801f5d8e27b43a605bfa373e13106da87acfc7673608f0ffb0eb04e10cae3dae93d2404bfda8676f96e3fcfd6bd642f6e12d69367916b796c54e98e2e4c4bc0b7a27aa42ba5048582fcbd45b1365b51c5014cb939c1853923c418048ff0e39c2237065da3c'; client.setEndpoint(ENDPOINT).setProject(PROJECT_ID).setKey(API_KEY); const dbId = 'almeira'; const delay = ms => new Promise(res => setTimeout(res, ms)); async function setupPhase5() { try { console.log('========================================'); console.log('Almeira Web — Appwrite Phase 5 (2FA & Profile)'); console.log('========================================\n'); console.log('[1/1] Creando colección segura: verification_tokens...'); try { // Creado SIN permisos públicos intencionalmente (Solo el Server Node via API_KEY podrá leer/escribir estos tokens) await databases.createCollection(dbId, 'verification_tokens', 'Bóveda Criptográfica OTP', [], false); console.log(' ✓ Colección creada.'); } catch(e){ console.log(' > Colección ya existe.'); } await delay(500); try { await databases.createStringAttribute(dbId, 'verification_tokens', 'user_id', 255, true); console.log(' ✓ Atributo user_id'); } catch(e){} await delay(300); try { await databases.createStringAttribute(dbId, 'verification_tokens', 'otp_code', 10, true); console.log(' ✓ Atributo otp_code'); } catch(e){} await delay(300); try { await databases.createDatetimeAttribute(dbId, 'verification_tokens', 'expires_at', true); console.log(' ✓ Atributo expires_at'); } catch(e){} await delay(300); try { await databases.createStringAttribute(dbId, 'verification_tokens', 'pending_data', 1000000, true); console.log(' ✓ Atributo pending_data (JSON Payload)'); } catch(e){} await delay(500); console.log('\n========================================'); console.log('✅ Base de Datos Phase 5 (OTP Wallet) Lista!'); console.log('========================================'); } catch(e) { console.error('\n❌ Error DB:', e.message); } } setupPhase5();