{
  "name": "Apex Card Factory Queue Monitor",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "content": "Apex Card Factory Queue Monitor\n\nPurpose: poll the public Apex automation queue, summarize pending intake/review/reverification work, and notify an operator.\n\nSafety: this workflow does not publish cards, does not fetch raw source, does not process admin writes, and does not contain secret values. Keep admin detail nodes disabled until credentials are configured inside n8n.",
        "height": 300,
        "width": 440,
        "color": 4
      },
      "id": "apex-note-policy",
      "name": "Policy Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1220,
        -260
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "id": "apex-schedule",
      "name": "Every 15 minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -1040,
        100
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.smartapex.uk/v1/automation/queue",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "Apex-n8n-Queue-Monitor/1.0"
            }
          ]
        },
        "options": {}
      },
      "id": "apex-public-queue",
      "name": "Read Public Queue",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -780,
        100
      ]
    },
    {
      "parameters": {
        "jsCode": "const queue = $json;\nconst counts = queue.counts ?? {};\nconst actions = Array.isArray(queue.actions) ? queue.actions : [];\nconst pendingTotal = Number(counts.intakeQueued ?? 0) + Number(counts.intakeReview ?? 0) + Number(counts.reviewCards ?? 0) + Number(counts.dueCards ?? 0);\nconst highPriority = actions.filter((action) => action.priority === 'high' && Number(action.count ?? 0) > 0);\nconst summaryLines = [\n  `Apex queue pending: ${pendingTotal}`,\n  `Intake: ${Number(counts.intakeQueued ?? 0) + Number(counts.intakeReview ?? 0)}`,\n  `Review cards: ${Number(counts.reviewCards ?? 0)}`,\n  `Due reverify: ${Number(counts.dueCards ?? 0)}`,\n  `LLM wiki: ${queue.llm_wiki?.version ?? 'unknown'} ${queue.llm_wiki?.digest ?? ''}`,\n  `Operator approval required: ${queue.gates?.operator_activation_required === true}`,\n  `Raw source release: ${queue.gates?.raw_source_release === true ? 'ON' : 'OFF'}`\n];\nreturn [{\n  json: {\n    schema: 'apex-n8n-queue-summary/1',\n    generatedAt: new Date().toISOString(),\n    pending_total: pendingTotal,\n    high_priority_count: highPriority.length,\n    queue_counts: counts,\n    public_queue_scope: queue.scope,\n    llm_wiki: queue.llm_wiki,\n    workflow_policy: {\n      publish_cards: false,\n      raw_source_access: false,\n      admin_writes_enabled: false,\n      operator_approval_required: true\n    },\n    message: summaryLines.join('\\n'),\n    notification_payload: {\n      text: summaryLines.join('\\n'),\n      source: 'apex-card-factory-queue',\n      public_queue: 'https://api.smartapex.uk/v1/automation/queue',\n      map_route: 'https://api.smartapex.uk/v1/map/routes/operate-card-factory-with-n8n',\n      admin_dashboard: 'https://smartapex.uk/admin'\n    }\n  }\n}];"
      },
      "id": "apex-build-summary",
      "name": "Build Queue Summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -520,
        100
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "pending-work-condition",
              "leftValue": "={{ $json.pending_total }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "apex-has-pending",
      "name": "Has Pending Work?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -260,
        100
      ]
    },
    {
      "parameters": {},
      "id": "apex-no-work",
      "name": "No Work",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        20,
        260
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.APEX_N8N_NOTIFY_WEBHOOK_URL }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.notification_payload }}",
        "options": {}
      },
      "id": "apex-notify-operator",
      "name": "Notify Operator Webhook",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        20,
        20
      ],
      "disabled": true,
      "notes": "Enable only after setting APEX_N8N_NOTIFY_WEBHOOK_URL in n8n. Do not put webhook secrets in this JSON export."
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.smartapex.uk/v1/admin/automation/queue",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-admin-key",
              "value": "={{ $env.APEX_ADMIN_API_KEY }}"
            },
            {
              "name": "User-Agent",
              "value": "Apex-n8n-Queue-Monitor/1.0"
            }
          ]
        },
        "options": {}
      },
      "id": "apex-private-queue",
      "name": "Read Private Queue Detail",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        280,
        20
      ],
      "disabled": true,
      "notes": "Optional read-only admin detail. Keep disabled unless this n8n instance is private and APEX_ADMIN_API_KEY is configured in the n8n environment or credential store."
    },
    {
      "parameters": {
        "content": "Manual operator step\n\nOpen https://smartapex.uk/admin and approve cards only after the complete checklist is true:\n- public source\n- no secrets\n- no raw source release\n- AI reviewed\n- operator reviewed\n- wrapper boundary\n- LLM wiki aligned\n\nThis workflow intentionally has no auto-approval node.",
        "height": 300,
        "width": 420,
        "color": 5
      },
      "id": "apex-note-approval",
      "name": "Operator Approval Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        240,
        -280
      ]
    }
  ],
  "connections": {
    "Every 15 minutes": {
      "main": [
        [
          {
            "node": "Read Public Queue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Public Queue": {
      "main": [
        [
          {
            "node": "Build Queue Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Queue Summary": {
      "main": [
        [
          {
            "node": "Has Pending Work?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Pending Work?": {
      "main": [
        [
          {
            "node": "Notify Operator Webhook",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Work",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Operator Webhook": {
      "main": [
        [
          {
            "node": "Read Private Queue Detail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1",
    "saveDataSuccessExecution": "none",
    "saveDataErrorExecution": "all",
    "saveManualExecutions": false
  },
  "staticData": {
    "apex": {
      "schema": "apex-n8n-workflow-export/1",
      "llm_wiki_version": "apex-llm-wiki/7",
      "public_queue": "https://api.smartapex.uk/v1/automation/queue",
      "map_route": "https://api.smartapex.uk/v1/map/routes/operate-card-factory-with-n8n",
      "source_code_release": false,
      "admin_writes_enabled": false,
      "operator_approval_required": true
    }
  },
  "tags": [
    {
      "name": "Apex"
    },
    {
      "name": "Card Factory"
    },
    {
      "name": "Operator Review"
    }
  ],
  "versionId": "apex-card-factory-queue-v1",
  "meta": {
    "templateCredsSetupCompleted": false,
    "source": "Apex public n8n workflow export",
    "notes": "No secrets. No raw source. No auto approval."
  }
}
