{
  "id": "demof779c61f6116",
  "name": "Lead Qualification and CRM Routing \u2014 Local Demo",
  "active": false,
  "nodes": [
    {
      "id": "start",
      "name": "Run local demo",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        50,
        220
      ],
      "parameters": {}
    },
    {
      "id": "fixtures",
      "name": "Load fictional scenarios",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        220
      ],
      "parameters": {
        "jsCode": "return [{\"json\": {\"name\": \"Qualified lead routes to sales\", \"input\": {\"lead\": {\"email\": \"CLIENT@EXAMPLE.COM \", \"budget\": 7000, \"companySize\": 30, \"timelineDays\": 14, \"consent\": true}}, \"expected\": {\"route\": \"sales\", \"score\": 100, \"email\": \"client@example.com\", \"crmAction\": \"preview-upsert\"}}}, {\"json\": {\"name\": \"Lower score goes to nurture\", \"input\": {\"lead\": {\"email\": \"lead@example.org\", \"budget\": 1000, \"companySize\": 5, \"timelineDays\": 90, \"consent\": true}}, \"expected\": {\"route\": \"nurture\", \"score\": 0}}}, {\"json\": {\"name\": \"Opt-out suppresses CRM preview\", \"input\": {\"lead\": {\"email\": \"lead@example.org\", \"budget\": 7000, \"companySize\": 30, \"timelineDays\": 14, \"consent\": false}}, \"expected\": {\"route\": \"suppressed\", \"crmAction\": \"none\"}}}, {\"json\": {\"name\": \"Existing contact is not recreated\", \"input\": {\"lead\": {\"email\": \"LEAD@example.org\", \"budget\": 7000, \"companySize\": 30, \"timelineDays\": 14, \"consent\": true}, \"existingEmails\": [\"lead@example.org\"]}, \"expected\": {\"route\": \"duplicate\", \"crmAction\": \"none\"}}}, {\"json\": {\"name\": \"Malformed email needs review\", \"input\": {\"lead\": {\"email\": \"invalid\", \"budget\": 7000, \"companySize\": 30, \"timelineDays\": 14, \"consent\": true}}, \"expected\": {\"route\": \"review\"}}}, {\"json\": {\"name\": \"Exact qualification boundary\", \"input\": {\"lead\": {\"email\": \"lead@example.net\", \"budget\": 5000, \"companySize\": 20, \"timelineDays\": 90, \"consent\": true}}, \"expected\": {\"route\": \"sales\", \"score\": 70}}}, {\"json\": {\"name\": \"Negative budget rejected\", \"input\": {\"lead\": {\"email\": \"lead@example.net\", \"budget\": -1, \"companySize\": 20, \"timelineDays\": 30, \"consent\": true}}, \"expected\": {\"route\": \"review\"}}}];"
      }
    },
    {
      "id": "stage0",
      "name": "Normalize lead intake",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        570,
        220
      ],
      "parameters": {
        "jsCode": "function step({input}) {\n const lead={...input.lead,email:String(input.lead.email??'').trim().toLowerCase()};\n const invalid=!/^[^@\\s]+@example\\.(com|org|net)$/.test(lead.email) || !Number.isFinite(lead.budget) || lead.budget<0 || !Number.isInteger(lead.companySize) || lead.companySize<1;\n return {lead,invalid};\n}\nreturn $input.all().map(({json},index)=>({json:{...json,...step(json)},pairedItem:{item:index}}));"
      }
    },
    {
      "id": "stage1",
      "name": "Score and route with consent",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        820,
        340
      ],
      "parameters": {
        "jsCode": "function step({input,lead,invalid}) {\n if(invalid)return {decision:{route:'review',score:0,reason:'invalid-input'}};\n if(!lead.consent)return {decision:{route:'suppressed',score:0,reason:'no-consent'}};\n if((input.existingEmails??[]).map(e=>e.toLowerCase()).includes(lead.email))return {decision:{route:'duplicate',score:0,reason:'existing-contact'}};\n const score=(lead.budget>=5000?40:0)+(lead.companySize>=20?30:0)+(lead.timelineDays<=30 && lead.timelineDays>=0?30:0);\n return {decision:{route:score>=70?'sales':'nurture',score,reason:'scored'}};\n}\nreturn $input.all().map(({json},index)=>({json:{...json,...step(json)},pairedItem:{item:index}}));"
      }
    },
    {
      "id": "stage2",
      "name": "Prepare CRM change preview",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1110,
        220
      ],
      "parameters": {
        "jsCode": "function step({lead,decision}) {\n return {result:{...decision,email:lead.email,crmAction:['sales','nurture'].includes(decision.route)?'preview-upsert':'none',owner:decision.route==='sales'?'demo-sales-team':null}};\n}\nreturn $input.all().map(({json},index)=>({json:{...json,...step(json)},pairedItem:{item:index}}));"
      }
    },
    {
      "id": "assert",
      "name": "Verify expected outcomes",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1370,
        220
      ],
      "parameters": {
        "jsCode": "const checks=$input.all().map(({json})=>{const failed=Object.entries(json.expected).filter(([k,v])=>JSON.stringify(json.result[k])!==JSON.stringify(v));return {scenario:json.name,passed:failed.length===0,expected:json.expected,output:json.result,failures:failed.map(([k])=>k)};});\nconst failures=checks.filter(c=>!c.passed);if(failures.length)throw new Error(JSON.stringify(failures));\nreturn [{json:{demo:\"lead-qualification\",mode:'local-simulation',checkedAt:new Date().toISOString(),passed:checks.length,failed:0,externalActionsPerformed:0,checks}}];"
      }
    },
    {
      "id": "section-1",
      "name": "Section 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 480,
        "height": 420,
        "color": 7,
        "content": "### 1. Load lead submissions\n\nUse fictional contact, consent, budget, and company data alongside existing-contact fixtures."
      }
    },
    {
      "id": "section-2",
      "name": "Section 2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        520,
        0
      ],
      "parameters": {
        "width": 520,
        "height": 550,
        "color": 7,
        "content": "### 2. Normalize and qualify\n\nNormalize email addresses, detect duplicates, require consent, and apply a transparent qualification score."
      }
    },
    {
      "id": "section-3",
      "name": "Section 3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1080,
        0
      ],
      "parameters": {
        "width": 510,
        "height": 420,
        "color": 7,
        "content": "### 3. Preview CRM changes\n\nPrepare a simulated CRM record or review outcome and verify the routing scenarios. No enrichment provider or CRM is connected."
      }
    }
  ],
  "connections": {
    "Run local demo": {
      "main": [
        [
          {
            "node": "Load fictional scenarios",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load fictional scenarios": {
      "main": [
        [
          {
            "node": "Normalize lead intake",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize lead intake": {
      "main": [
        [
          {
            "node": "Score and route with consent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score and route with consent": {
      "main": [
        [
          {
            "node": "Prepare CRM change preview",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare CRM change preview": {
      "main": [
        [
          {
            "node": "Verify expected outcomes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
