import type { IntegrationType } from "../db/schema.js"; import type { IntegrationField } from "./types.js"; /** * Field schema per integration type. Only types with a working adapter appear * here — the "Add integration" form only offers what's actually implemented. */ export const INTEGRATION_FIELDS: Partial> = { tailscale: [ { key: "tailnet", label: "Tailnet", secret: false, placeholder: "yourorg.github — or - for your default tailnet", }, { key: "apiKey", label: "API key", secret: true, type: "password" }, ], }; /** Fixed base URL per integration type, stored on the row for display/reference. */ export const INTEGRATION_BASE_URLS: Partial> = { tailscale: "https://api.tailscale.com", }; export function splitIntegrationConfig( type: IntegrationType, input: Record, ): { secretFields: Record; nonSecretFields: Record } { const fields = INTEGRATION_FIELDS[type] ?? []; const secretFields: Record = {}; const nonSecretFields: Record = {}; for (const field of fields) { if (input[field.key] === undefined) continue; if (field.secret) secretFields[field.key] = input[field.key]; else nonSecretFields[field.key] = input[field.key]; } return { secretFields, nonSecretFields }; } export function validateIntegrationConfig( type: IntegrationType, merged: Record, ): string[] { const fields = INTEGRATION_FIELDS[type] ?? []; return fields .filter((f) => f.type !== "checkbox") .filter((f) => merged[f.key] === undefined || merged[f.key] === "") .map((f) => f.key); }