{"id":"ETDEnquiryDemo14","name":"ETD sample enquiry routing — validation, review and retries","active":false,"versionId":"466ea08b-c117-41ca-a3e3-308fb5a21766","settings":{"executionOrder":"v1"},"nodes":[{"id":"manual-start","name":"Manual start","type":"n8n-nodes-base.manualTrigger","typeVersion":1,"position":[0,0],"parameters":{}},{"id":"sample-enquiries","name":"Sample enquiries","type":"n8n-nodes-base.code","typeVersion":2,"position":[240,0],"parameters":{"jsCode":"const base = {email: 'ops@example.invalid', service: 'n8n', approved: true, destinationAvailable: true};\nreturn [\n  {...base, eventId: 'demo-001'},\n  {...base, eventId: 'demo-001'},\n  {...base, eventId: 'demo-002', email: 'missing-at-sign'},\n  {...base, eventId: 'demo-003', approved: false},\n  {...base, eventId: 'demo-004', destinationAvailable: false},\n  {...base, eventId: 'demo-005', approved: 'true'},\n  {...base},\n  {...base, eventId: 'demo-004'},\n].map(json => ({json}));"}},{"id":"check-and-route","name":"Check and route","type":"n8n-nodes-base.code","typeVersion":2,"position":[480,0],"parameters":{"jsCode":"// shortcut: duplicate tracking lasts for this execution; use durable IDs and atomic writes before connecting a real destination.\nconst readyIds = new Set();\nreturn $input.all().map(({json}) => {\n  const eventId = typeof json.eventId === 'string' ? json.eventId.trim() : '';\n  const email = typeof json.email === 'string' ? json.email.trim() : '';\n  let status;\n  if (!eventId || eventId.length > 64 || email.length > 254 || !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email) || !['custom_software', 'ai_automation', 'n8n'].includes(json.service)) {\n    status = 'needs_correction';\n  } else if (readyIds.has(eventId)) {\n    status = 'duplicate_suppressed';\n  } else if (json.approved !== true) {\n    status = 'awaiting_review';\n  } else if (json.destinationAvailable !== true) {\n    status = 'retry_pending';\n  } else {\n    status = 'ready_to_route';\n    readyIds.add(eventId);\n  }\n  return {json: {eventId: eventId || null, status}};\n});"}},{"id":"verify-results","name":"Verify sample results","type":"n8n-nodes-base.code","typeVersion":2,"position":[720,0],"parameters":{"jsCode":"const results = $input.all().map(item => item.json);\nconst expected = ['ready_to_route', 'duplicate_suppressed', 'needs_correction', 'awaiting_review', 'retry_pending', 'awaiting_review', 'needs_correction', 'ready_to_route'];\nif (results.length !== expected.length || results.some((row, i) => row.status !== expected[i])) {\n  throw new Error('The sample workflow failed its expected routing checks.');\n}\nreturn [{json: {example: 'Sample data only; no message or CRM write was performed.', passed: true, testedCases: results.length, results}}];"}}],"connections":{"Manual start":{"main":[[{"node":"Sample enquiries","type":"main","index":0}]]},"Sample enquiries":{"main":[[{"node":"Check and route","type":"main","index":0}]]},"Check and route":{"main":[[{"node":"Verify sample results","type":"main","index":0}]]}}}