import { createMintelDirectusClient, ensureDirectusAuthenticated, } from "@mintel/next-utils"; import { createCollection, createField, updateSettings } from "@directus/sdk"; const client = createMintelDirectusClient(); async function setupBranding() { const prjName = process.env.PROJECT_NAME || "Mintel Project"; const prjColor = process.env.PROJECT_COLOR || "#82ed20"; console.log(`🎨 Setup Directus Branding for ${prjName}...`); await ensureDirectusAuthenticated(client); const cssInjection = `

MINTEL INFRASTRUCTURE ENGINE

${prjName.toUpperCase()} RELIABILITY.

`; try { await client.request( updateSettings({ project_name: prjName, project_color: prjColor, public_note: cssInjection, theme_light_overrides: { primary: prjColor, borderRadius: "16px", navigationBackground: "#000c24", navigationForeground: "#ffffff", }, // eslint-disable-next-line @typescript-eslint/no-explicit-any } as any), ); console.log("✨ Branding applied!"); try { await createCollectionAndFields(); console.log("đŸ—ī¸ Schema alignment complete!"); } catch (error) { console.error("❌ Error aligning schema:", error); } } catch (error) { console.error("❌ Error setting up branding:", error); } } async function createCollectionAndFields() { const collectionName = "contact_submissions"; try { await client.request( createCollection({ collection: collectionName, schema: {}, meta: { icon: "contact_mail", display_template: "{{name}} <{{email}}>", }, }), ); // Add ID field await client.request( createField(collectionName, { field: "id", type: "integer", meta: { hidden: true }, schema: { is_primary_key: true, has_auto_increment: true }, }), ); console.log(`✅ Collection ${collectionName} created.`); } catch { console.log( `â„šī¸ Collection ${collectionName} already exists or error occured.`, ); } const safeAddField = async ( field: string, type: string, meta: Record = {}, ) => { try { await client.request(createField(collectionName, { field, type, meta })); console.log(`✅ Field ${field} added.`); } catch { // Ignore if exists } }; await safeAddField("name", "string", { interface: "input" }); await safeAddField("email", "string", { interface: "input" }); await safeAddField("company", "string", { interface: "input" }); await safeAddField("message", "text", { interface: "textarea" }); await safeAddField("date_created", "timestamp", { interface: "datetime", special: ["date-created"], }); } setupBranding();