import { createDirectus, rest, staticToken, createCollection, readCollections, createDashboard, createPanel, createItems, readDashboards, readPanels, createPermission, readPolicies } from '@directus/sdk'; import { config } from '../lib/config'; async function setupInfraFeedback() { console.log('🚀 Setting up INFRA_FEEDBACK (Renamed for v11 Visibility)...'); const url = 'http://localhost:8059'; const token = '59fb8f4c1a51b18fe28ad947f713914e'; const client = createDirectus(url).with(staticToken(token)).with(rest()); try { const collections = await client.request(readCollections()); const existing = collections.map(c => c.collection); const COLL = 'infra_feedback'; if (!existing.includes(COLL)) { console.log(`🏗️ Creating "${COLL}"...`); await client.request(createCollection({ collection: COLL, meta: { icon: 'feedback', display_template: '{{user_name}}: {{text}}' }, fields: [ { field: 'id', type: 'integer', schema: { is_primary_key: true, has_auto_increment: true } }, { field: 'status', type: 'string', schema: { default_value: 'open' }, meta: { interface: 'select-dropdown' } }, { field: 'url', type: 'string' }, { field: 'text', type: 'text' }, { field: 'user_name', type: 'string' }, { field: 'date_created', type: 'timestamp', schema: { default_value: 'NOW()' } } ] } as any)); } const policies = await client.request(readPolicies()); const adminPolicy = policies.find(p => p.name === 'Administrator')?.id; const publicPolicy = policies.find(p => p.name === '$t:public_label' || p.name === 'Public')?.id; for (const policy of [adminPolicy, publicPolicy]) { if (!policy) continue; console.log(`🔐 Granting permissions to ${policy}...`); for (const action of ['create', 'read', 'update', 'delete']) { try { await client.request(createPermission({ policy, collection: COLL, action, fields: ['*'] } as any)); } catch (e) { } } } console.log('💉 Injecting test data...'); await client.request(createItems(COLL, [ { user_name: 'Antigravity', text: 'Rename Test Success', status: 'open' } ])); console.log('📊 Configuring Dashboard "Feedback OVERVIEW"...'); const dashboards = await client.request(readDashboards()); let dash = dashboards.find(d => d.name === 'Feedback OVERVIEW'); if (dash) await client.request(() => ({ path: `/dashboards/${dash.id}`, method: 'DELETE' })); dash = await client.request(createDashboard({ name: 'Feedback OVERVIEW', icon: 'visibility', color: '#FFCC00' })); await client.request(createPanel({ dashboard: dash.id, name: 'Table View', type: 'list', width: 24, height: 12, position_x: 1, position_y: 1, options: { collection: COLL, display_template: '{{user_name}}: {{text}}' } } as any)); console.log('✅ Renamed Setup Complete! Dash: "Feedback OVERVIEW"'); } catch (error: any) { console.error('❌ Rename setup failed:', error); } } setupInfraFeedback();