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 collectionsToMakePublic = [ 'settings', 'posts', 'contracts', 'publication_types', 'media', 'programming_matrices' ]; async function fixPermissions() { try { console.log('Fijando Permisos Públicos de Lectura (Read Any)...'); for (const col of collectionsToMakePublic) { try { // Obtenemos la colección actual para preservar su nombre y otros ajustes const current = await databases.getCollection(dbId, col); // Agregamos Permiso universal de Lectura let existingPerms = current.$permissions || []; // Remover cualquier read existente para evitar conflictos y poner el nuestro existingPerms = existingPerms.filter(p => !p.startsWith('read(')); existingPerms.push(sdk.Permission.read(sdk.Role.any())); await databases.updateCollection( dbId, col, current.name, existingPerms ); console.log(` ✓ Permisos arreglados para: ${col}`); } catch (err) { console.log(` x Error en ${col}: ${err.message}`); } } console.log('Listo.'); } catch(e) { console.error(e); } } fixPermissions();