{
  "name": "AHF 01 - Data Intake and Validation",
  "nodes": [
    {
      "parameters": {"httpMethod":"POST","path":"ahf-intake","responseMode":"responseNode","options":{}},
      "id": "56d8de28-1f5d-43aa-8c54-948d5ca56d93",
      "name": "Webhook Intake",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [-520, 0],
      "webhookId": "ahf-intake-validation"
    },
    {
      "parameters": {
        "jsCode": "const body = $json.body ?? $json;\nconst rows = Array.isArray(body.exceptions) ? body.exceptions : [];\nif (!rows.length) throw new Error('exceptions[] is required');\nif (rows.length > 30) throw new Error('Maximum 30 exceptions per request');\nconst clean = (value, max = 180) => String(value ?? '').replace(/[\\u0000-\\u001f]/g, ' ').trim().slice(0, max);\nconst exceptions = rows.map((row, index) => ({\n  id: clean(row.id || `EX-${index + 1}`, 40),\n  type: clean(row.type || 'Unclassified exception', 80),\n  source: clean(row.source || 'Unknown source', 80),\n  sku: clean(row.sku || 'N/A', 40),\n  customer: clean(row.customer || 'ANON', 40),\n  variance: Number.isFinite(Number(row.variance)) ? Number(row.variance) : 0,\n  severity: ['high','medium','low'].includes(row.severity) ? row.severity : 'medium',\n  note: clean(row.note, 180)\n}));\nreturn [{ json: { valid: true, sanitized: true, record_count: exceptions.length, exceptions } }];"
      },
      "id": "4fa9aab5-6a6f-4b3f-ad99-f318590cae17",
      "name": "Validate and Sanitize",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-260, 0]
    },
    {
      "parameters": {"respondWith":"json","responseBody":"={{ $json }}","options":{}},
      "id": "5fd3cc1e-8fa4-42f8-8d0e-a695285d0391",
      "name": "Return Validated Payload",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [20, 0]
    }
  ],
  "pinData": {},
  "connections": {
    "Webhook Intake": {"main":[[{"node":"Validate and Sanitize","type":"main","index":0}]]},
    "Validate and Sanitize": {"main":[[{"node":"Return Validated Payload","type":"main","index":0}]]}
  },
  "active": false,
  "settings": {"executionOrder":"v1"},
  "versionId": "052eef6d-5df1-4adb-b74d-d7ddff1cb2ea",
  "meta": {"templateCredsSetupCompleted": true},
  "tags": []
}
