{
  "name": "Grownob \u00b7 CRM Sync Agent",
  "nodes": [
    {
      "parameters": {},
      "id": "sync-node-1",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "function exampleBatch(key){\n const n=8649,list=Array.from({length:n},(_,i)=>i),d=i=>`account${i+1}.example`,url=i=>`https://${d(i)}/news`,e=i=>`buyer${i+1}@${d(i)}`;\n // Deterministic synthetic inputs: varied, reproducible distributions, not customer records.\n let seed=271828+Array.from(key).reduce((a,c)=>a*31+c.charCodeAt(0),0);\n const rand=()=>{seed=(Math.imul(seed,1664525)+1013904223)>>>0;return seed/4294967296};\n const pick=a=>a[Math.floor(rand()*a.length)];\n if(key==='signal')return {max_age_days:30,min_fit:75,events:list.map(i=>({domain:d(i),type:pick(['sales hiring','new location','funding','job change','service launch']),age_days:rand()<.15?45+Math.floor(rand()*75):1+Math.floor(rand()*28),fit:rand()<.035?55:76+Math.floor(rand()*25),source:rand()<.19?'':url(i)}))};\n if(key==='repair'){\n  const records=[];while(records.length<n){const i=records.length,p=rand(),base={id:'C-'+(i+1),domain:' HTTPS://'+d(i).toUpperCase()+'/ ',email:' '+e(i).toUpperCase()+' ',title:'VP Sales'};\n   if(p<.13){records.push({...base,domain:'invalid',email:'unknown',title:''});continue;}\n   records.push(base);if(records.length<n&&p>=.13&&p<.58){records.push({...base,id:'C-'+(i+2),domain:d(i),email:e(i),title:p<.26?'Director':'VP Sales'});}\n  }return {records};\n }\n if(key==='sequence')return {accounts:list.map(i=>({domain:d(i),first_name:pick(['Jordan','Casey','Taylor','Alex','Morgan']),role:pick(['VP Sales','Head of Growth','Operations Director']),event:pick(['Hiring sales roles','Opened a new location','Launched a new service']),source:rand()<.207?'':url(i),challenge:pick(['Research workload during expansion','Keeping CRM records aligned','Prioritizing new accounts'])}))};\n if(key==='sync'){const ids=[];return {processed_ids:[],events:list.map(i=>{const p=rand(),status=pick(['interested','not_now','opt_out']);if(p<.103)return {id:'',domain:d(i),status};if(p<.257&&ids.length){const j=pick(ids);return {id:`evt-${j}`,domain:d(j),status};}ids.push(i);return {id:`evt-${i}`,domain:d(i),status};})};}\n if(key==='route')return {min_fit:75,replies:list.map(i=>{const p=rand();return {id:'R-'+i,fit:p>.755?55:85,reply:p<.36?'Interested in learning more':p<.458?'Please unsubscribe':p<.755?'Not interested':'Can you send details?',opt_out:false};})};\n if(key==='enrich')return {contacts:list.map(i=>({domain:d(i),email:rand()<.028?'invalid':e(i),role:'Operations Director',verification:rand()<.778?'valid':'unknown',source:'provider record'}))};\n throw Error('Unknown workflow');\n}\n\nreturn [{json:exampleBatch(\"sync\")}];"
      },
      "id": "sync-node-2",
      "name": "Generate example batch",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        260,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const clean=x=>typeof x==='string'?x.trim():'';\nconst domain=x=>{const d=clean(x).toLowerCase().replace(/^https?:\\/\\//,'').replace(/^www\\./,'').replace(/\\/$/,'');return /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z]{2,63}$/.test(d)?d:null};\nconst email=x=>clean(x).toLowerCase(), validEmail=x=>/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(x), count=x=>Number.isSafeInteger(x)&&x>=0;\nfunction exampleBatch(key){\n const n=8649,list=Array.from({length:n},(_,i)=>i),d=i=>`account${i+1}.example`,url=i=>`https://${d(i)}/news`,e=i=>`buyer${i+1}@${d(i)}`;\n // Deterministic synthetic inputs: varied, reproducible distributions, not customer records.\n let seed=271828+Array.from(key).reduce((a,c)=>a*31+c.charCodeAt(0),0);\n const rand=()=>{seed=(Math.imul(seed,1664525)+1013904223)>>>0;return seed/4294967296};\n const pick=a=>a[Math.floor(rand()*a.length)];\n if(key==='signal')return {max_age_days:30,min_fit:75,events:list.map(i=>({domain:d(i),type:pick(['sales hiring','new location','funding','job change','service launch']),age_days:rand()<.15?45+Math.floor(rand()*75):1+Math.floor(rand()*28),fit:rand()<.035?55:76+Math.floor(rand()*25),source:rand()<.19?'':url(i)}))};\n if(key==='repair'){\n  const records=[];while(records.length<n){const i=records.length,p=rand(),base={id:'C-'+(i+1),domain:' HTTPS://'+d(i).toUpperCase()+'/ ',email:' '+e(i).toUpperCase()+' ',title:'VP Sales'};\n   if(p<.13){records.push({...base,domain:'invalid',email:'unknown',title:''});continue;}\n   records.push(base);if(records.length<n&&p>=.13&&p<.58){records.push({...base,id:'C-'+(i+2),domain:d(i),email:e(i),title:p<.26?'Director':'VP Sales'});}\n  }return {records};\n }\n if(key==='sequence')return {accounts:list.map(i=>({domain:d(i),first_name:pick(['Jordan','Casey','Taylor','Alex','Morgan']),role:pick(['VP Sales','Head of Growth','Operations Director']),event:pick(['Hiring sales roles','Opened a new location','Launched a new service']),source:rand()<.207?'':url(i),challenge:pick(['Research workload during expansion','Keeping CRM records aligned','Prioritizing new accounts'])}))};\n if(key==='sync'){const ids=[];return {processed_ids:[],events:list.map(i=>{const p=rand(),status=pick(['interested','not_now','opt_out']);if(p<.103)return {id:'',domain:d(i),status};if(p<.257&&ids.length){const j=pick(ids);return {id:`evt-${j}`,domain:d(j),status};}ids.push(i);return {id:`evt-${i}`,domain:d(i),status};})};}\n if(key==='route')return {min_fit:75,replies:list.map(i=>{const p=rand();return {id:'R-'+i,fit:p>.755?55:85,reply:p<.36?'Interested in learning more':p<.458?'Please unsubscribe':p<.755?'Not interested':'Can you send details?',opt_out:false};})};\n if(key==='enrich')return {contacts:list.map(i=>({domain:d(i),email:rand()<.028?'invalid':e(i),role:'Operations Director',verification:rand()<.778?'valid':'unknown',source:'provider record'}))};\n throw Error('Unknown workflow');\n}\n\n\nfunction rows(x,key){if(!x||!Array.isArray(x[key])||x[key].length<1||x[key].length>10000||x[key].some(r=>!r||typeof r!=='object'||Array.isArray(r)))throw Error('Provide 1\u201310,000 objects in '+key+'.');return x[key]}\n\nfunction process(x){if(!Array.isArray(x.processed_ids))throw Error('Provide processed_ids array.');const seen=new Set(x.processed_ids.map(clean)),handoff=[],duplicates=[],review=[];for(const [i,r] of rows(x,'events').entries()){const id=clean(r.id),d=domain(r.domain),status=clean(r.status);if(!id||!d||!['interested','opt_out','not_now'].includes(status)){review.push({row:i+1,id,reason:'Invalid event'});continue}if(seen.has(id)){duplicates.push({id,domain:d});continue}seen.add(id);handoff.push({id,domain:d,action:status==='opt_out'?'Suppress contact':status==='interested'?'Sales review':'Defer review',status:'Proposed CRM update'});}return {handoff,duplicates,review,summary:{handoff:handoff.length,duplicates:duplicates.length,review:review.length}}}\nreturn [{json:process($input.first().json)}];"
      },
      "id": "sync-node-3",
      "name": "Validate & deduplicate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return $input.all().map(item => ({json:{workflow:\"CRM Sync Agent\",dataset:\"Generated example batch\",input_records:8649,...item.json,review_required:true}}));"
      },
      "id": "sync-node-4",
      "name": "Review output",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        780,
        0
      ]
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Generate example batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate example batch": {
      "main": [
        [
          {
            "node": "Validate & deduplicate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate & deduplicate": {
      "main": [
        [
          {
            "node": "Review output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}