{
  "nodes": [
    {
      "id": "084f3e30-edcd-41a6-a8d4-9b5c003bec82",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        240,
        368
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0ed22ae1-9405-4006-950f-0a56c59bf7da",
      "name": "ScrapeGraphAI",
      "type": "n8n-nodes-scrapegraphai.scrapegraphAi",
      "position": [
        944,
        624
      ],
      "parameters": {
        "userPrompt": "Extract regulatory changes and new rules from this government site. Use the following schema for response: { \"title\": \"Rule Title\", \"agency\": \"SEC\", \"publication_date\": \"2025-01-15\", \"effective_date\": \"2025-03-15\", \"summary\": \"Brief description of the rule\", \"impact_level\": \"High/Medium/Low\", \"affected_sectors\": [\"Financial Services\", \"Banking\"], \"document_url\": \"https://federalregister.gov/...\", \"rule_type\": \"Final Rule/Proposed Rule/Notice\", \"comment_deadline\": \"2025-02-15\" }",
        "websiteUrl": "https://www.federalregister.gov/documents/search?conditions%5Bagencies%5D%5B%5D=securities-and-exchange-commission&conditions%5Bpublication_date%5D%5Bgte%5D={ { $now.minus({ days: 1 }).toISODate() } }"
      },
      "typeVersion": 1
    },
    {
      "id": "f82dfb15-b15a-4436-8256-082f4169de47",
      "name": "Regulation Parser",
      "type": "n8n-nodes-base.code",
      "notes": "Parse and clean regulatory data from scraping",
      "position": [
        1680,
        368
      ],
      "parameters": {
        "jsCode": "// Get the input data from ScrapeGraphAI\nconst inputData = $input.all()[0].json;\n\nconst regulations = inputData.result.regulatory_changes || inputData.result.rules || inputData.result.regulations || inputData.regulations || [];\n\nfunction parseRegulation(regulation) {\n  const {\n    title,\n    agency,\n    publication_date,\n    effective_date,\n    summary,\n    impact_level,\n    affected_sectors,\n    document_url,\n    rule_type,\n    comment_deadline\n  } = regulation;\n\n  const cleanTitle = title?.trim() || 'Title not available';\n  const cleanAgency = agency?.trim() || 'Agency not specified';\n  const cleanSummary = summary?.trim() || 'Summary not available';\n  const cleanImpactLevel = impact_level || 'Medium';\n  const cleanRuleType = rule_type || 'Unknown';\n  const cleanUrl = document_url || '#';\n  \n  const pubDate = publication_date ? new Date(publication_date).toLocaleDateString() : 'Not specified';\n  const effDate = effective_date ? new Date(effective_date).toLocaleDateString() : 'Not specified';\n  const commentDate = comment_deadline ? new Date(comment_deadline).toLocaleDateString() : 'N/A';\n  \n  const sectors = Array.isArray(affected_sectors) ? affected_sectors : (affected_sectors ? [affected_sectors] : ['General']);\n  \n  return {\n    title: cleanTitle,\n    agency: cleanAgency,\n    publication_date: pubDate,\n    effective_date: effDate,\n    summary: cleanSummary,\n    impact_level: cleanImpactLevel,\n    affected_sectors: sectors,\n    document_url: cleanUrl,\n    rule_type: cleanRuleType,\n    comment_deadline: commentDate,\n    parsed_at: new Date().toISOString()\n  };\n}\n\nreturn regulations.map(regulation => ({\n  json: parseRegulation(regulation)\n}));"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "0027ecda-5b32-4cfa-b0b4-dac6c967f548",
      "name": "Impact Assessor",
      "type": "n8n-nodes-base.code",
      "notes": "Assess business impact and risk levels",
      "position": [
        2448,
        480
      ],
      "parameters": {
        "jsCode": "// Get parsed regulation data\nconst regulation = $input.all()[0].json;\n\nfunction assessImpact(regulation) {\n  const { title, summary, affected_sectors, rule_type, agency } = regulation;\n  \n  let impactScore = 0;\n  let riskFactors = [];\n  let opportunities = [];\n  let complianceActions = [];\n  \n  switch (rule_type.toLowerCase()) {\n    case 'final rule':\n      impactScore += 3;\n      complianceActions.push('Immediate compliance review required');\n      break;\n    case 'proposed rule':\n      impactScore += 2;\n      complianceActions.push('Prepare comment response');\n      break;\n    case 'notice':\n      impactScore += 1;\n      complianceActions.push('Monitor for developments');\n      break;\n  }\n  \n  const criticalSectors = ['financial services', 'banking', 'healthcare', 'energy', 'technology'];\n  const matchedCriticalSectors = affected_sectors.filter(sector => \n    criticalSectors.some(critical => sector.toLowerCase().includes(critical.toLowerCase()))\n  );\n  \n  if (matchedCriticalSectors.length > 0) {\n    impactScore += 2;\n    riskFactors.push(`Direct impact on critical sectors: ${matchedCriticalSectors.join(', ')}`);\n  }\n  \n  const highImpactKeywords = ['compliance', 'penalty', 'fine', 'mandatory', 'prohibited', 'required'];\n  const mediumImpactKeywords = ['guidance', 'recommendation', 'best practice', 'voluntary'];\n  const opportunityKeywords = ['incentive', 'tax credit', 'grant', 'funding', 'streamlined'];\n  \n  const textToAnalyze = `${title} ${summary}`.toLowerCase();\n  \n  highImpactKeywords.forEach(keyword => {\n    if (textToAnalyze.includes(keyword)) {\n      impactScore += 1;\n      riskFactors.push(`Contains high-impact keyword: ${keyword}`);\n    }\n  });\n  \n  mediumImpactKeywords.forEach(keyword => {\n    if (textToAnalyze.includes(keyword)) {\n      impactScore += 0.5;\n    }\n  });\n  \n  opportunityKeywords.forEach(keyword => {\n    if (textToAnalyze.includes(keyword)) {\n      opportunities.push(`Potential opportunity: ${keyword}`);\n    }\n  });\n  \n  let finalImpactLevel;\n  if (impactScore >= 5) {\n    finalImpactLevel = 'Critical';\n    complianceActions.push('Executive review required within 24 hours');\n  } else if (impactScore >= 3) {\n    finalImpactLevel = 'High';\n    complianceActions.push('Legal and compliance team review required');\n  } else if (impactScore >= 1.5) {\n    finalImpactLevel = 'Medium';\n    complianceActions.push('Department head review recommended');\n  } else {\n    finalImpactLevel = 'Low';\n    complianceActions.push('Standard monitoring sufficient');\n  }\n  \n  return {\n    ...regulation,\n    impact_assessment: {\n      impact_score: impactScore,\n      final_impact_level: finalImpactLevel,\n      risk_factors: riskFactors,\n      opportunities: opportunities,\n      compliance_actions: complianceActions,\n      assessment_date: new Date().toISOString()\n    }\n  };\n}\n\nreturn [{ json: assessImpact(regulation) }];"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "72a0346a-6a67-4a07-87f7-ceeb1178e939",
      "name": "Compliance Tracker",
      "type": "n8n-nodes-base.code",
      "notes": "Create compliance tracking record and tasks",
      "position": [
        3200,
        432
      ],
      "parameters": {
        "jsCode": "// Get assessed regulation data\nconst regulation = $input.all()[0].json;\nconst { impact_assessment, title, agency, effective_date, comment_deadline } = regulation;\n\nfunction createComplianceTracker(regulation) {\n  const compliance = {\n    regulation_id: `REG_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,\n    title: regulation.title,\n    agency: regulation.agency,\n    status: 'New',\n    priority: regulation.impact_assessment.final_impact_level,\n    key_dates: {\n      publication_date: regulation.publication_date,\n      effective_date: regulation.effective_date,\n      comment_deadline: regulation.comment_deadline,\n      review_due_date: calculateReviewDate(regulation.impact_assessment.final_impact_level)\n    },\n    assigned_team: assignTeam(regulation.impact_assessment.final_impact_level),\n    compliance_tasks: generateComplianceTasks(regulation),\n    tracking_status: {\n      initial_review: 'Pending',\n      impact_analysis: 'Pending',\n      policy_update: 'Pending',\n      training_required: 'Pending',\n      implementation: 'Pending'\n    },\n    created_at: new Date().toISOString(),\n    last_updated: new Date().toISOString()\n  };\n  \n  return {\n    ...regulation,\n    compliance_tracking: compliance\n  };\n}\n\nfunction calculateReviewDate(impactLevel) {\n  const now = new Date();\n  switch (impactLevel) {\n    case 'Critical':\n      return new Date(now.getTime() + 24 * 60 * 60 * 1000).toISOString();\n    case 'High':\n      return new Date(now.getTime() + 3 * 24 * 60 * 60 * 1000).toISOString();\n    case 'Medium':\n      return new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000).toISOString();\n    default:\n      return new Date(now.getTime() + 14 * 24 * 60 * 60 * 1000).toISOString();\n  }\n}\n\nfunction assignTeam(impactLevel) {\n  switch (impactLevel) {\n    case 'Critical':\n      return ['Executive Team', 'Legal', 'Compliance', 'Operations'];\n    case 'High':\n      return ['Legal', 'Compliance', 'Department Heads'];\n    case 'Medium':\n      return ['Compliance', 'Relevant Department'];\n    default:\n      return ['Compliance'];\n  }\n}\n\nfunction generateComplianceTasks(regulation) {\n  const baseTasks = [\n    'Review regulation text',\n    'Assess current policy alignment',\n    'Identify compliance gaps'\n  ];\n  \n  const { final_impact_level, compliance_actions } = regulation.impact_assessment;\n  \n  if (final_impact_level === 'Critical' || final_impact_level === 'High') {\n    baseTasks.push(\n      'Conduct legal review',\n      'Update internal policies',\n      'Plan staff training',\n      'Create implementation timeline'\n    );\n  }\n  \n  if (regulation.comment_deadline !== 'N/A') {\n    baseTasks.push('Prepare regulatory comment response');\n  }\n  \n  return baseTasks.concat(compliance_actions);\n}\n\nreturn [{ json: createComplianceTracker(regulation) }];"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "59ac11b9-2a10-4fed-ac03-a73e5d92ec3b",
      "name": "Executive Alert",
      "type": "n8n-nodes-base.code",
      "notes": "Format executive alert message",
      "position": [
        3968,
        432
      ],
      "parameters": {
        "jsCode": "// Get regulation with compliance tracking\nconst regulation = $input.all()[0].json;\nconst { impact_assessment, compliance_tracking } = regulation;\n\nfunction formatExecutiveAlert(regulation) {\n  const { title, agency, impact_assessment, compliance_tracking } = regulation;\n  const { final_impact_level, risk_factors, opportunities } = impact_assessment;\n  \n  let alertLevel = '⚠️';\n  let urgency = 'Standard';\n  \n  switch (final_impact_level) {\n    case 'Critical':\n      alertLevel = '🚨';\n      urgency = 'URGENT';\n      break;\n    case 'High':\n      alertLevel = '⚠️';\n      urgency = 'High Priority';\n      break;\n    case 'Medium':\n      alertLevel = '📋';\n      urgency = 'Medium Priority';\n      break;\n    case 'Low':\n      alertLevel = 'ℹ️';\n      urgency = 'Low Priority';\n      break;\n  }\n  \n  let message = `${alertLevel} **REGULATORY ALERT - ${urgency}**\\n\\n`;\n  message += `**Regulation:** ${title}\\n`;\n  message += `**Agency:** ${agency}\\n`;\n  message += `**Impact Level:** ${final_impact_level}\\n`;\n  message += `**Publication Date:** ${regulation.publication_date}\\n`;\n  message += `**Effective Date:** ${regulation.effective_date}\\n\\n`;\n  \n  message += `**📊 SUMMARY**\\n${regulation.summary}\\n\\n`;\n  \n  if (risk_factors.length > 0) {\n    message += `**⚠️ RISK FACTORS**\\n`;\n    risk_factors.forEach(risk => {\n      message += `• ${risk}\\n`;\n    });\n    message += `\\n`;\n  }\n  \n  if (opportunities.length > 0) {\n    message += `**💡 OPPORTUNITIES**\\n`;\n    opportunities.forEach(opp => {\n      message += `• ${opp}\\n`;\n    });\n    message += `\\n`;\n  }\n  \n  message += `**👥 ASSIGNED TEAMS**\\n${compliance_tracking.assigned_team.join(', ')}\\n\\n`;\n  \n  message += `**📅 KEY DATES**\\n`;\n  message += `• Review Due: ${new Date(compliance_tracking.key_dates.review_due_date).toLocaleDateString()}\\n`;\n  if (regulation.comment_deadline !== 'N/A') {\n    message += `• Comment Deadline: ${regulation.comment_deadline}\\n`;\n  }\n  message += `• Effective Date: ${regulation.effective_date}\\n\\n`;\n  \n  message += `**✅ IMMEDIATE ACTIONS REQUIRED**\\n`;\n  compliance_tracking.compliance_tasks.slice(0, 5).forEach(task => {\n    message += `• ${task}\\n`;\n  });\n  \n  message += `\\n**🔗 RESOURCES**\\n`;\n  message += `• [Full Regulation Document](${regulation.document_url})\\n`;\n  message += `• Compliance ID: ${compliance_tracking.regulation_id}\\n\\n`;\n  \n  message += `**📈 TRACKING STATUS**\\nAll compliance tasks have been logged and assigned. Progress will be monitored through the compliance dashboard.\\n\\n`;\n  \n  message += `━━━━━━━━━━━━━━━━━━━━━━\\n`;\n  message += `🕐 Alert Generated: ${new Date().toLocaleString()}`;\n  \n  return message;\n}\n\nreturn [{\n  json: {\n    alert_text: formatExecutiveAlert(regulation),\n    alert_level: regulation.impact_assessment.final_impact_level,\n    regulation_id: regulation.compliance_tracking.regulation_id,\n    title: regulation.title,\n    agency: regulation.agency,\n    effective_date: regulation.effective_date,\n    assigned_teams: regulation.compliance_tracking.assigned_team,\n    review_due_date: regulation.compliance_tracking.key_dates.review_due_date,\n    document_url: regulation.document_url\n  }\n}];"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "ca7c5d3e-9fbc-4fd4-be75-a709463f989c",
      "name": "Email Alert",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        4688,
        528
      ],
      "parameters": {
        "options": {
          "ccEmail": "user@example.com"
        },
        "subject": "🚨 Regulatory Alert: { { $json.alert_level } } Impact - { { $json.title } }"
      },
      "typeVersion": 2
    }
  ],
  "connections": {
    "ScrapeGraphAI": {
      "main": [
        [
          {
            "node": "Regulation Parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Executive Alert": {
      "main": [
        [
          {
            "node": "Email Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Impact Assessor": {
      "main": [
        [
          {
            "node": "Compliance Tracker",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "ScrapeGraphAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Regulation Parser": {
      "main": [
        [
          {
            "node": "Impact Assessor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compliance Tracker": {
      "main": [
        [
          {
            "node": "Executive Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}