81 lines
3.4 KiB
TypeScript
81 lines
3.4 KiB
TypeScript
import { createDirectus, rest, staticToken, deleteCollection, createCollection, createDashboard, createPanel, createItems, createPermission, readPolicies } from '@directus/sdk';
|
|
import { config } from '../lib/config';
|
|
|
|
async function nukeAndPaveV11() {
|
|
console.log('🚀 NUKE & PAVE: Feedback System v11...');
|
|
|
|
const url = 'http://localhost:8059';
|
|
const token = '59fb8f4c1a51b18fe28ad947f713914e';
|
|
const client = createDirectus(url).with(staticToken(token)).with(rest());
|
|
|
|
try {
|
|
console.log('🗑️ Deleting collections...');
|
|
try { await client.request(deleteCollection('visual_feedback_comments')); } catch (e) { }
|
|
try { await client.request(deleteCollection('visual_feedback')); } catch (e) { }
|
|
|
|
console.log('🏗️ Creating "visual_feedback" fresh...');
|
|
await client.request(createCollection({
|
|
collection: 'visual_feedback',
|
|
meta: { icon: 'feedback', display_template: '{{user_name}}: {{text}}' },
|
|
fields: [
|
|
{ field: 'id', type: 'uuid', schema: { is_primary_key: true } },
|
|
{ field: 'status', type: 'string', schema: { default_value: 'open' }, meta: { interface: 'select-dropdown' } },
|
|
{ field: 'url', type: 'string', meta: { interface: 'input' } },
|
|
{ field: 'selector', type: 'string', meta: { interface: 'input' } },
|
|
{ field: 'text', type: 'text', meta: { interface: 'input-multiline' } },
|
|
{ field: 'user_name', type: 'string', meta: { interface: 'input' } },
|
|
{ field: 'date_created', type: 'timestamp', schema: { default_value: 'NOW()' }, meta: { interface: 'datetime' } }
|
|
]
|
|
} as any));
|
|
|
|
console.log('🔐 Granting Permissions...');
|
|
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 to Policy: ${policy}...`);
|
|
await client.request(createPermission({
|
|
policy,
|
|
collection: 'visual_feedback',
|
|
action: 'read',
|
|
fields: ['*'],
|
|
permissions: {},
|
|
validation: {}
|
|
} as any));
|
|
}
|
|
|
|
console.log('💉 Injecting items...');
|
|
await client.request(createItems('visual_feedback', [
|
|
{ user_name: 'Antigravity', text: 'Nuke & Pave Success', status: 'open' }
|
|
]));
|
|
|
|
console.log('📊 Recreating Dashboard...');
|
|
const dash = await client.request(createDashboard({
|
|
name: 'Feedback Insights',
|
|
icon: 'analytics',
|
|
color: '#6644FF'
|
|
}));
|
|
|
|
await client.request(createPanel({
|
|
dashboard: dash.id,
|
|
name: 'Status',
|
|
type: 'metric',
|
|
width: 12,
|
|
height: 6,
|
|
position_x: 1,
|
|
position_y: 1,
|
|
options: { collection: 'visual_feedback', function: 'count', field: 'id' }
|
|
} as any));
|
|
|
|
console.log('✅ Nuke & Pave Complete!');
|
|
|
|
} catch (e: any) {
|
|
console.error('❌ Nuke failed:', e);
|
|
if (e.errors) console.error(JSON.stringify(e.errors, null, 2));
|
|
}
|
|
}
|
|
|
|
nukeAndPaveV11();
|