{
  "name": "Regulatory Doc Processor",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "sec-filing-webhook",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-001",
      "name": "SEC Filing Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "set-filing-001",
              "name": "filing_url",
              "value": "={{ $json.body.filing_url || $json.filing_url }}",
              "type": "string"
            },
            {
              "id": "set-filing-002",
              "name": "filing_type",
              "value": "={{ $json.body.filing_type || $json.filing_type || '10-K' }}",
              "type": "string"
            },
            {
              "id": "set-filing-003",
              "name": "company_name",
              "value": "={{ $json.body.company_name || $json.company_name || 'Unknown' }}",
              "type": "string"
            },
            {
              "id": "set-filing-004",
              "name": "cik",
              "value": "={{ $json.body.cik || $json.cik || '' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "extract-payload-001",
      "name": "Extract Filing Details",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        470,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ $json.filing_url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          },
          "timeout": 60000
        }
      },
      "id": "fetch-doc-001",
      "name": "Download Filing Document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        690,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const rawText = $input.item.json.data || '';\n\n// Strip HTML tags and normalize whitespace\nconst cleanText = rawText\n  .replace(/<[^>]*>/g, ' ')\n  .replace(/&nbsp;/g, ' ')\n  .replace(/&amp;/g, '&')\n  .replace(/&lt;/g, '<')\n  .replace(/&gt;/g, '>')\n  .replace(/&quot;/g, '\"')\n  .replace(/\\s+/g, ' ')\n  .trim();\n\n// Take first 15000 chars to stay within API limits\nconst truncated = cleanText.substring(0, 15000);\n\nreturn [{\n  json: {\n    ...($('Extract Filing Details').item.json),\n    cleaned_text: truncated,\n    char_count: truncated.length\n  }\n}];"
      },
      "id": "clean-doc-001",
      "name": "Clean & Truncate Document",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        910,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $vars.FASTAPI_BASE_URL || 'http://fastapi-service:8000' }}/extract",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "text": "={{ $json.cleaned_text }}",
          "document_type": "={{ $json.filing_type }}",
          "company_name": "={{ $json.company_name }}"
        },
        "options": {
          "timeout": 60000
        }
      },
      "id": "extract-info-001",
      "name": "Extract Key Information",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1130,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const extraction = $input.item.json;\nconst filing = $('Extract Filing Details').item.json;\n\nconst formatDate = (d) => d ? new Date(d).toLocaleDateString('en-US', {year:'numeric',month:'long',day:'numeric'}) : 'TBD';\n\nconst emailHtml = `\n<h2>\ud83d\udccb Regulatory Filing Alert: ${filing.filing_type} \u2014 ${filing.company_name}</h2>\n<p><strong>CIK:</strong> ${filing.cik}</p>\n<p><strong>Filing URL:</strong> <a href=\"${filing.filing_url}\">${filing.filing_url}</a></p>\n<hr/>\n<h3>\ud83d\uddd3 Effective Date</h3>\n<p>${formatDate(extraction.effective_date)}</p>\n<h3>\ud83d\udd11 Key Changes</h3>\n<ul>${(extraction.key_changes || []).map(c => `<li>${c}</li>`).join('')}</ul>\n<h3>\u26a0\ufe0f Risk Factors</h3>\n<ul>${(extraction.risk_factors || []).map(r => `<li>${r}</li>`).join('')}</ul>\n<h3>\u23f0 Compliance Deadline</h3>\n<p>${formatDate(extraction.compliance_deadline)}</p>\n<h3>\ud83c\udfe2 Affected Entities</h3>\n<ul>${(extraction.affected_entities || []).map(e => `<li>${e}</li>`).join('')}</ul>\n`;\n\nreturn [{\n  json: {\n    ...extraction,\n    email_html: emailHtml,\n    email_subject: `[Regulatory Alert] ${filing.filing_type} Filing \u2014 ${filing.company_name}`,\n    company_name: filing.company_name,\n    filing_type: filing.filing_type\n  }\n}];"
      },
      "id": "format-email-001",
      "name": "Format Email Report",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1350,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "={{ $vars.ALERT_FROM_EMAIL || 'alerts@fintech-hub.internal' }}",
        "toEmail": "={{ $vars.COMPLIANCE_TEAM_EMAIL || 'compliance@fintech-hub.internal' }}",
        "subject": "={{ $json.email_subject }}",
        "emailFormat": "html",
        "html": "={{ $json.email_html }}",
        "options": {}
      },
      "id": "send-email-001",
      "name": "Email Compliance Team",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1570,
        300
      ],
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"status\": \"processed\", \"company\": \"{{ $('Extract Filing Details').item.json.company_name }}\", \"filing_type\": \"{{ $('Extract Filing Details').item.json.filing_type }}\" }",
        "options": {}
      },
      "id": "webhook-response-001",
      "name": "Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1570,
        500
      ]
    }
  ],
  "connections": {
    "SEC Filing Webhook": {
      "main": [
        [
          {
            "node": "Extract Filing Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Filing Details": {
      "main": [
        [
          {
            "node": "Download Filing Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Filing Document": {
      "main": [
        [
          {
            "node": "Clean & Truncate Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean & Truncate Document": {
      "main": [
        [
          {
            "node": "Extract Key Information",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Key Information": {
      "main": [
        [
          {
            "node": "Format Email Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Email Report": {
      "main": [
        [
          {
            "node": "Email Compliance Team",
            "type": "main",
            "index": 0
          },
          {
            "node": "Webhook Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner",
    "errorWorkflow": ""
  },
  "staticData": null,
  "tags": [
    "fintech",
    "regulatory",
    "sec",
    "claude",
    "email"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-06-15T00:00:00.000Z",
  "versionId": "b2c3d4e5-f6a7-8901-bcde-f23456789012"
}