{
  "name": "ezGPT - RSS Digest Preview",
  "active": false,
  "nodes": [
    {
      "id": "trigger",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ],
      "parameters": {}
    },
    {
      "id": "rss",
      "name": "Read Demo Feed",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1.2,
      "position": [
        460,
        300
      ],
      "alwaysOutputData": true,
      "parameters": {
        "url": "https://ezgpt.ru/storage/article-files/ezgpt-rss-demo.xml",
        "options": {
          "ignoreSSL": false
        }
      }
    },
    {
      "id": "check",
      "name": "Check Feed",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const items = $input.all();\nif (!items.length || (items.length === 1 && !Object.keys(items[0].json).length)) {\n  throw new Error('feed_empty');\n}\nif (items.length > 20) throw new Error('feed_too_many_items');\nconst ids = new Set();\nconst links = new Set();\nreturn items.map(({ json: row }) => {\n  const text = key => {\n    const value = row[key];\n    if (typeof value !== 'string' || !value.trim()) throw new Error(key + '_required');\n    return value.trim();\n  };\n  const id = text('guid');\n  const title = text('title');\n  const link = text('link');\n  const date = text('isoDate');\n  const excerpt = text('contentSnippet');\n  if (title.length > 200 || excerpt.length > 1000) throw new Error('feed_text_too_long');\n  if (!link.startsWith('https://example.invalid/') || !/^rss-demo-\\d{3}$/.test(link.slice('https://example.invalid/'.length))) {\n    throw new Error('feed_link_not_allowed');\n  }\n  if (!/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/.test(date) || !Number.isFinite(Date.parse(date))) {\n    throw new Error('feed_date_invalid');\n  }\n  if (ids.has(id) || links.has(link)) throw new Error('feed_duplicate');\n  ids.add(id);\n  links.add(link);\n  return { json: { id, title, link, published_at: date, excerpt } };\n});"
      }
    },
    {
      "id": "sort",
      "name": "Sort News",
      "type": "n8n-nodes-base.sort",
      "typeVersion": 1,
      "position": [
        900,
        300
      ],
      "parameters": {
        "type": "simple",
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "published_at",
              "order": "descending"
            },
            {
              "fieldName": "id",
              "order": "ascending"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "preview",
      "name": "Digest Preview",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1120,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const source = $('Check Feed').all().map(item => item.json);\nconst entries = $input.all().map(item => item.json);\nconst expected = [...source].sort((a, b) => b.published_at.localeCompare(a.published_at) || a.id.localeCompare(b.id));\nif (JSON.stringify(entries) !== JSON.stringify(expected)) throw new Error('feed_order_mismatch');\nreturn [{ json: {\n  status: 'needs_review',\n  count: entries.length,\n  entries,\n  approved: false,\n  action_performed: false,\n} }];"
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Read Demo Feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Demo Feed": {
      "main": [
        [
          {
            "node": "Check Feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Feed": {
      "main": [
        [
          {
            "node": "Sort News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort News": {
      "main": [
        [
          {
            "node": "Digest Preview",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveDataSuccessExecution": "all",
    "saveDataErrorExecution": "all"
  },
  "pinData": {}
}
