// Deploy regenerated W1..W4 workflows to live n8n via public API. // Usage: N8N_API_KEY= N8N_BASE=http://192.168.137.2:5678 node deploy_w1_w3.mjs // Key lives in repo-root SECRETS.md (never hardcode here). import { readFile } from "node:fs/promises"; const N8N = process.env.N8N_BASE || "http://192.168.137.2:5678"; const KEY = process.env.N8N_API_KEY; if (!KEY) { console.error("N8N_API_KEY env required (see SECRETS.md)"); process.exit(1); } const H = { "X-N8N-API-KEY": KEY, "Content-Type": "application/json" }; const TARGETS = [ { file: "W1-customer-provision.json", id: "gU2ee9Eg5w1KzB5p" }, { file: "W3-expiry-sync.json", id: "zlEfjj5eK5IfILtk" }, ]; for (const t of TARGETS) { const wf = JSON.parse(await readFile(t.file, "utf-8")); delete wf.pinData; delete wf.active; delete wf.id; const r = await fetch(`${N8N}/api/v1/workflows/${t.id}`, { method: "PUT", headers: H, body: JSON.stringify(wf), }); const txt = await r.text(); console.log(t.file, "PUT", r.status, txt.slice(0, 120)); if (r.status !== 200) process.exit(1); } console.log("DEPLOY OK — remember to recheck workflow_entity.activeVersionId alignment");