{
  "name": "Row & Rule · Lead Intake, SLA & Safe Retry Proof",
  "nodes": [
    {
      "parameters": {
        "width": 980,
        "height": 420,
        "content": "## 01 · Controlled intake\nSynthetic leads enter through one boundary. The workflow normalises fields, creates a stable identity key and validates required data before anything reaches a destination.",
        "color": 5
      },
      "id": "row-rule-1",
      "name": "01 · Controlled intake",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1500,
        -520
      ]
    },
    {
      "parameters": {
        "width": 650,
        "height": 420,
        "content": "## 02 · Duplicate protection\nA replay is recognised before CRM, sheet or project-board writes. The duplicate is logged instead of silently creating another record.",
        "color": 3
      },
      "id": "row-rule-2",
      "name": "02 · Duplicate protection",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -410,
        -520
      ]
    },
    {
      "parameters": {
        "width": 1120,
        "height": 700,
        "content": "## 03 · Explicit routing\nClear leads follow deterministic business rules. Ambiguous regions enter a human-review queue; the demonstration records an explicit reviewer decision.",
        "color": 4
      },
      "id": "row-rule-3",
      "name": "03 · Rules + human review",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        360,
        -520
      ]
    },
    {
      "parameters": {
        "width": 1120,
        "height": 700,
        "content": "## 04 · Failure handling\nA synthetic CRM 503 is made visible. The retry reuses the same identity and idempotency key, so recovery updates one controlled record instead of creating a duplicate.",
        "color": 2
      },
      "id": "row-rule-4",
      "name": "04 · Failure + safe retry",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1590,
        -520
      ]
    },
    {
      "parameters": {
        "width": 900,
        "height": 700,
        "content": "## 05 · Traceable delivery\nThe owner, SLA deadline, destination status and audit event travel together. Every outcome can be traced back to the original synthetic event.",
        "color": 6
      },
      "id": "row-rule-5",
      "name": "05 · SLA + audit trail",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2830,
        -520
      ]
    },
    {
      "parameters": {},
      "id": "row-rule-6",
      "name": "Start · Synthetic proof run",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1400,
        -180
      ]
    },
    {
      "parameters": {
        "jsCode": "return [\n  { json: { eventId: 'EVT-9001', source: 'website', email: 'alex.morgan@example.test', company: 'Northstar Field Services', country: 'Germany', service: 'Workflow automation', urgency: 'high', value: 18000, receivedAt: '2026-11-03T12:00:00Z' } },\n  { json: { eventId: 'EVT-9002', source: 'partner-api', email: 'mira.chen@example.test', company: 'Cedar & Finch', country: 'Canada', service: 'Financial reporting', urgency: 'normal', value: 9500, receivedAt: '2026-11-03T12:02:00Z' } },\n  { json: { eventId: 'EVT-9003', source: 'shared-inbox', email: 'ewa.nowak@example.test', company: 'Baltic Operations', country: 'Germany / Poland', service: 'CRM integration', urgency: 'high', value: 24000, receivedAt: '2026-11-03T12:03:00Z' } },\n  { json: { eventId: 'EVT-9004', source: 'csv-import', email: 'alex.morgan@example.test', company: 'Northstar Field Services', country: 'Germany', service: 'Workflow automation', urgency: 'high', value: 18000, receivedAt: '2026-11-03T12:04:00Z', replayOf: 'EVT-9001' } }\n];"
      },
      "id": "row-rule-7",
      "name": "Create 4 synthetic lead events",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1180,
        -180
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => {\n  const lead = item.json;\n  const email = String(lead.email || '').trim().toLowerCase();\n  const company = String(lead.company || '').trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '');\n  return { json: { ...lead, email, identityKey: email + '::' + company, idempotencyKey: 'lead::' + email + '::' + company, requiredFieldsPresent: Boolean(email && company && lead.service), normalizedAt: '2026-11-03T12:05:00Z' } };\n});"
      },
      "id": "row-rule-8",
      "name": "Normalise + stable identity",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -940,
        -180
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, validationStatus: item.json.requiredFieldsPresent ? 'PASS' : 'MANUAL_REVIEW', validationIssues: item.json.requiredFieldsPresent ? [] : ['Missing required identity or service field'] } }));"
      },
      "id": "row-rule-9",
      "name": "Validate required fields",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -700,
        -180
      ]
    },
    {
      "parameters": {
        "jsCode": "const seen = new Set();\nreturn items.map((item) => {\n  const duplicate = seen.has(item.json.identityKey) || Boolean(item.json.replayOf);\n  seen.add(item.json.identityKey);\n  return { json: { ...item.json, isDuplicate: duplicate, duplicateDecision: duplicate ? 'SUPPRESS' : 'CONTINUE' } };\n});"
      },
      "id": "row-rule-10",
      "name": "Check replay / duplicate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -460,
        -180
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "duplicate-condition",
              "leftValue": "={{ $json.isDuplicate }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "row-rule-11",
      "name": "Duplicate?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -220,
        -180
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, finalStatus: 'DUPLICATE_SUPPRESSED', destinationsCreated: 0, auditEvent: 'Replay blocked before downstream writes' } }));"
      },
      "id": "row-rule-12",
      "name": "Audit · duplicate suppressed",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        20,
        -40
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => {\n  const highValue = Number(item.json.value || 0) >= 15000;\n  const priority = item.json.urgency === 'high' || highValue ? 'P1' : 'P2';\n  const ambiguousRegion = String(item.json.country).includes('/');\n  return { json: { ...item.json, priority, intent: item.json.service, ambiguousRegion, classificationSource: 'deterministic-demo-rules' } };\n});"
      },
      "id": "row-rule-13",
      "name": "Classify intent + priority",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        300,
        -260
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "review-condition",
              "leftValue": "={{ $json.ambiguousRegion }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "row-rule-14",
      "name": "Human review required?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        540,
        -260
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, reviewStatus: 'PENDING', reviewReason: 'Two operating regions detected', recommendedRegion: 'EMEA Central' } }));"
      },
      "id": "row-rule-15",
      "name": "Queue · regional ambiguity",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        780,
        -100
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, reviewStatus: 'APPROVED', reviewer: 'Demo Operations Reviewer', region: 'EMEA Central', owner: 'Elena Park', reviewedAt: '2026-11-03T12:06:00Z' } }));"
      },
      "id": "row-rule-16",
      "name": "Human decision · EMEA Central",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1020,
        -100
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => {\n  const country = String(item.json.country);\n  const region = country === 'Canada' ? 'North America' : 'EMEA Central';\n  const owner = region === 'North America' ? 'Marcus Lee' : 'Elena Park';\n  return { json: { ...item.json, reviewStatus: 'NOT_REQUIRED', region, owner } };\n});"
      },
      "id": "row-rule-17",
      "name": "Automatic route",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        780,
        -360
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => {\n  const minutes = item.json.priority === 'P1' ? 30 : 120;\n  return { json: { ...item.json, slaMinutes: minutes, slaDeadline: item.json.priority === 'P1' ? '2026-11-03T12:35:00Z' : '2026-11-03T14:05:00Z', crmAttempt: 1, simulateCrm503: item.json.eventId === 'EVT-9003', deliveryRecordId: 'DLV-' + item.json.eventId.slice(-4) } };\n});"
      },
      "id": "row-rule-18",
      "name": "Set SLA + delivery record",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1300,
        -260
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "crm-condition",
              "leftValue": "={{ $json.simulateCrm503 }}",
              "rightValue": false,
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "row-rule-19",
      "name": "CRM connector healthy?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1580,
        -260
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, crmStatus: 'UPSERTED', crmRecordId: 'CRM-' + item.json.eventId.slice(-4), crmAttempts: 1 } }));"
      },
      "id": "row-rule-20",
      "name": "CRM upsert · success",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1840,
        -380
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, crmStatus: 'FAILED_RETRYABLE', crmError: 'HTTP 503 — synthetic connector outage', crmAttempts: 1, retryPolicy: 'exponential-backoff-max-3' } }));"
      },
      "id": "row-rule-21",
      "name": "Capture synthetic CRM 503",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1840,
        -120
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, crmAttempt: 2, retryUsedSameKey: true, retryAt: '2026-11-03T12:07:00Z' } }));"
      },
      "id": "row-rule-22",
      "name": "Retry · same idempotency key",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2100,
        -120
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, crmStatus: 'RECOVERED', crmRecordId: 'CRM-' + item.json.eventId.slice(-4), crmAttempts: 2, duplicateCrmRecords: 0 } }));"
      },
      "id": "row-rule-23",
      "name": "CRM upsert · recovered",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2360,
        -120
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, sheetStatus: 'UPSERTED', sheetRowKey: item.json.identityKey } }));"
      },
      "id": "row-rule-24",
      "name": "Upsert master sheet",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2640,
        -260
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, boardStatus: 'UPSERTED', taskId: 'TASK-' + item.json.eventId.slice(-4), duplicateTasks: 0 } }));"
      },
      "id": "row-rule-25",
      "name": "Upsert project board",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2890,
        -260
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { ...item.json, notificationStatus: 'QUEUED', notificationTarget: item.json.owner, notificationChannel: 'synthetic-team-channel' } }));"
      },
      "id": "row-rule-26",
      "name": "Notify accountable owner",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3140,
        -260
      ]
    },
    {
      "parameters": {
        "jsCode": "return items.map((item) => ({ json: { eventId: item.json.eventId, identityKey: item.json.identityKey, finalStatus: item.json.finalStatus || 'DELIVERED', owner: item.json.owner || null, region: item.json.region || null, priority: item.json.priority || null, slaDeadline: item.json.slaDeadline || null, reviewStatus: item.json.reviewStatus || null, crmStatus: item.json.crmStatus || null, crmAttempts: item.json.crmAttempts || 0, duplicateCrmRecords: item.json.duplicateCrmRecords || 0, duplicateTasks: item.json.duplicateTasks || 0, destinationsCreated: item.json.destinationsCreated ?? 3, auditEvent: item.json.auditEvent || 'Controlled delivery completed', traceableToSource: true } }));"
      },
      "id": "row-rule-27",
      "name": "Audit log + final outcome",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3390,
        -180
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Start · Synthetic proof run": {
      "main": [
        [
          {
            "node": "Create 4 synthetic lead events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create 4 synthetic lead events": {
      "main": [
        [
          {
            "node": "Normalise + stable identity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalise + stable identity": {
      "main": [
        [
          {
            "node": "Validate required fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate required fields": {
      "main": [
        [
          {
            "node": "Check replay / duplicate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check replay / duplicate": {
      "main": [
        [
          {
            "node": "Duplicate?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Duplicate?": {
      "main": [
        [
          {
            "node": "Audit · duplicate suppressed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Classify intent + priority",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Audit · duplicate suppressed": {
      "main": [
        [
          {
            "node": "Audit log + final outcome",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify intent + priority": {
      "main": [
        [
          {
            "node": "Human review required?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Human review required?": {
      "main": [
        [
          {
            "node": "Queue · regional ambiguity",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Automatic route",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Queue · regional ambiguity": {
      "main": [
        [
          {
            "node": "Human decision · EMEA Central",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Human decision · EMEA Central": {
      "main": [
        [
          {
            "node": "Set SLA + delivery record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Automatic route": {
      "main": [
        [
          {
            "node": "Set SLA + delivery record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set SLA + delivery record": {
      "main": [
        [
          {
            "node": "CRM connector healthy?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM connector healthy?": {
      "main": [
        [
          {
            "node": "CRM upsert · success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Capture synthetic CRM 503",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Capture synthetic CRM 503": {
      "main": [
        [
          {
            "node": "Retry · same idempotency key",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retry · same idempotency key": {
      "main": [
        [
          {
            "node": "CRM upsert · recovered",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM upsert · success": {
      "main": [
        [
          {
            "node": "Upsert master sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CRM upsert · recovered": {
      "main": [
        [
          {
            "node": "Upsert master sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert master sheet": {
      "main": [
        [
          {
            "node": "Upsert project board",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert project board": {
      "main": [
        [
          {
            "node": "Notify accountable owner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify accountable owner": {
      "main": [
        [
          {
            "node": "Audit log + final outcome",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "versionId": "d0cc4814-7434-4b2f-b3d2-00a1ef6c1055",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": []
}
