{
  "name": "NovaSync Ops \u2014 Flujo Conector v3",
  "nodes": [
    {
      "parameters": {
        "content": "## \ud83d\udd17 NovaSync Ops \u2014 Flujo Conector v3\n\n**\u00bfQu\u00e9 hace este flujo?**\nRecibe compras del simulador (Vercel) v\u00eda webhook.\nNormaliza los datos del payload (Stock_Actual ya viene de Supabase)\ny decide si generar orden de recompra o solo notificar.\n\n**Fixes aplicados v3:**\n- Eliminado Google Sheets Inventario READ (innecesario)\n- Cruzar Lee stock directamente del payload (Supabase es maestro)\n- IF Score conecta directo a Cruzar (sin detour por Sheets)\n- Fan-out de Cruzar: IF Orden + Actualizar Sheets (espejo)\n\n**Credenciales a configurar:**\n- Google Sheets (OAuth2)\n- Slack (OAuth2)\n- Google Gemini API Key",
        "height": 360,
        "width": 320,
        "color": 4
      },
      "id": "e889c2f1-8064-462c-bd0e-5a62b4f41032",
      "name": "\ud83d\udcdd Instrucciones",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1080,
        500
      ]
    },
    {
      "parameters": {
        "content": "### \ud83d\udccb Estructura Google Sheets\n\n**Hoja: Inventario**\nColumnas: C\u00f3digo, Producto, Categor\u00eda,\nStock Actual, Stock M\u00ednimo, Precio Unitario,\nProveedor, Estado\n\n**Hoja: Ops_Alertas**\nColumnas: Fecha, Hora, Lead, Empresa,\nEmail, Score_IA, Producto, C\u00f3digo,\nCantidad, Total_Venta, Stock_Post_Venta,\nStock_M\u00ednimo, Estado_Stock,\nOrden_Generada, Proveedor, Mensaje_Slack",
        "height": 320,
        "width": 300,
        "color": 5
      },
      "id": "21f2d395-b0f7-4cac-9f1f-3914ed020d55",
      "name": "\ud83d\udcca Estructura Sheets",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1080,
        880
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "e263a234-ab7d-4dec-a196-544edb38b3cc",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "cbb47ff1-38ab-4bff-b930-1c1bb71124d0",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -760,
        700
      ]
    },
    {
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "nombre",
              "value": "={{ $json.body.nombre || '' }}",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "empresa",
              "value": "={{ $json.body.empresa || '' }}",
              "type": "string"
            },
            {
              "id": "a3",
              "name": "email",
              "value": "={{ $json.body.email || '' }}",
              "type": "string"
            },
            {
              "id": "a4",
              "name": "cargo",
              "value": "={{ $json.body.cargo || '' }}",
              "type": "string"
            },
            {
              "id": "a5",
              "name": "Score_IA",
              "value": "={{ $json.body.Score_IA || 0 }}",
              "type": "number"
            },
            {
              "id": "a6",
              "name": "Estado_Venta",
              "value": "={{ $json.body.Estado_Venta || '' }}",
              "type": "string"
            },
            {
              "id": "a7",
              "name": "Producto_Comprado",
              "value": "={{ $json.body.Producto_Comprado || '' }}",
              "type": "string"
            },
            {
              "id": "a8",
              "name": "Codigo",
              "value": "={{ $json.body.Codigo || '' }}",
              "type": "string"
            },
            {
              "id": "a9",
              "name": "Cantidad",
              "value": "={{ $json.body.Cantidad || 1 }}",
              "type": "number"
            },
            {
              "id": "a10",
              "name": "Total",
              "value": "={{ $json.body.Total || 0 }}",
              "type": "number"
            },
            {
              "id": "a11",
              "name": "Stock_Actual",
              "value": "={{ $json.body.Stock_Actual || 0 }}",
              "type": "number"
            },
            {
              "id": "a12",
              "name": "Stock_Minimo",
              "value": "={{ $json.body.Stock_Minimo || 0 }}",
              "type": "number"
            },
            {
              "id": "a13",
              "name": "Proveedor",
              "value": "={{ $json.body.Proveedor || '' }}",
              "type": "string"
            },
            {
              "id": "a14",
              "name": "fecha",
              "value": "={{ $json.body.fecha || '' }}",
              "type": "string"
            },
            {
              "id": "a15",
              "name": "hora",
              "value": "={{ $json.body.hora || '' }}",
              "type": "string"
            },
            {
              "id": "a16",
              "name": "fuente",
              "value": "={{ $json.body.fuente || 'Simulador NovaSync' }}",
              "type": "string"
            },
            {
              "id": "a17",
              "name": "mensaje",
              "value": "={{ $json.body.mensaje || '' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "set-norm-2024-001",
      "name": "\ud83d\udd27 Normalizar Datos Webhook",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -560,
        700
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "cond-stock-critico",
              "leftValue": "={{ $json.Stock_Actual }}",
              "rightValue": 4,
              "operator": {
                "type": "number",
                "operation": "lte"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "b4d30b85-d6a6-4b88-ac70-e22a8c008dc0",
      "name": "\ud83c\udfaf \u00bfStock Cr\u00edtico?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        -340,
        700
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { status: 'ok', mensaje: 'Venta registrada \u2014 stock normal sin alerta critica', stock_post_venta: $json.Stock_Actual } }}",
        "options": {}
      },
      "id": "respond-ignored-001",
      "name": "\ud83d\udd01 Respond: Venta Normal",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -340,
        880
      ]
    },
    {
      "parameters": {
        "jsCode": "const lead = $input.first().json;\n\nconst stockActual = lead.Stock_Actual || 0;\nconst stockMinimo = lead.Stock_Minimo || 0;\nconst proveedor = lead.Proveedor || 'Sin proveedor';\nconst producto = lead.Producto_Comprado || 'Sin producto';\nconst codigo = lead.Codigo || 'N/A';\nconst cantidad = lead.Cantidad || 1;\nconst total = lead.Total || 0;\n\nconst stockBajo = stockActual < stockMinimo;\nconst stockUrgente = stockActual < 5;\nconst estadoStock = stockUrgente ? '\ud83d\udd34 CR\u00cdTICO' : (stockBajo ? '\ud83d\udfe1 BAJO' : '\ud83d\udfe2 OK');\n\nconst fechaHora = new Date().toLocaleString('es-CO', { timeZone: 'America/Bogota' });\nconst fecha = new Date().toLocaleDateString('es-CO');\nconst hora = new Date().toLocaleTimeString('es-CO');\n\nconst sep = '\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500';\n\nconst msgCritico = [\n  '\ud83d\udea8 *ALERTA \u2014 Stock Cr\u00edtico + Venta Premium*',\n  sep,\n  `\ud83d\udc64 *Cliente:* ${lead.nombre || 'Sin nombre'}`,\n  `\ud83c\udfe2 *Empresa:* ${lead.empresa || 'Sin empresa'}`,\n  `\ud83d\udcbc *Cargo:* ${lead.cargo || 'Sin cargo'}`,\n  `\ud83d\udce7 *Email:* ${lead.email || 'Sin email'}`,\n  `\u2b50 *Score IA:* ${lead.Score_IA || 0}/10`,\n  '',\n  `\ud83d\udce6 *Producto:* ${producto}`,\n  `\ud83d\udd22 *Cantidad vendida:* ${cantidad} unidad(es)`,\n  `\ud83d\udcb0 *Total venta:* $${Math.round(total).toLocaleString('es-CO')}`,\n  `\ud83d\udccd *C\u00f3digo:* ${codigo}`,\n  '',\n  '\ud83d\udcca *Estado del inventario:*',\n  `\u2022 Stock tras venta: ${stockActual} uds`,\n  `\u2022 Stock m\u00ednimo: ${stockMinimo} uds`,\n  `\u2022 Estado: ${estadoStock}`,\n  '',\n  `\ud83c\udfed *Proveedor:* ${proveedor}`,\n  `\ud83d\udd50 *Fecha:* ${fecha} \u2014 ${hora}`,\n  sep,\n  '\u26a0\ufe0f _Se generar\u00e1 orden de recompra autom\u00e1ticamente_'\n].join('\\n');\n\nconst msgOk = [\n  '\u2705 *Venta Premium Convertida*',\n  sep,\n  `\ud83d\udc64 *Cliente:* ${lead.nombre || 'Sin nombre'}`,\n  `\ud83c\udfe2 *Empresa:* ${lead.empresa || 'Sin empresa'}`,\n  `\ud83d\udcbc *Cargo:* ${lead.cargo || 'Sin cargo'}`,\n  `\ud83d\udce7 *Email:* ${lead.email || 'Sin email'}`,\n  `\u2b50 *Score IA:* ${lead.Score_IA || 0}/10`,\n  '',\n  `\ud83d\udce6 *Producto:* ${producto}`,\n  `\ud83d\udd22 *Cantidad vendida:* ${cantidad} unidad(es)`,\n  `\ud83d\udcb0 *Total venta:* $${Math.round(total).toLocaleString('es-CO')}`,\n  `\ud83d\udccd *C\u00f3digo:* ${codigo}`,\n  '',\n  '\ud83d\udcca *Estado del inventario:*',\n  `\u2022 Stock tras venta: ${stockActual} uds`,\n  `\u2022 Stock m\u00ednimo: ${stockMinimo} uds`,\n  `\u2022 Estado: ${estadoStock}`,\n  '',\n  `\ud83c\udfed *Proveedor:* ${proveedor}`,\n  `\ud83d\udd50 *Fecha:* ${fecha} \u2014 ${hora}`,\n  sep,\n  '\u2705 _Stock en rango normal. No se requiere reabastecimiento._'\n].join('\\n');\n\nreturn [{\n  json: {\n    leadNombre: lead.nombre || 'Sin nombre',\n    leadEmpresa: lead.empresa || 'Sin empresa',\n    leadEmail: lead.email || '',\n    leadCargo: lead.cargo || '',\n    leadScore: lead.Score_IA || 0,\n    producto,\n    codigo,\n    proveedor,\n    stockActual,\n    stockMinimo,\n    cantidad,\n    total,\n    stockBajo,\n    stockUrgente,\n    estadoStock,\n    generarOrden: stockUrgente || stockBajo,\n    mensajeSlack: (stockUrgente || stockBajo) ? msgCritico : msgOk,\n    mensajeFinal: (stockUrgente || stockBajo) ? msgCritico : msgOk,\n    fechaHora,\n    fecha,\n    hora\n  }\n}];"
      },
      "id": "626fbaca-6127-41f0-9023-06b1d33e7310",
      "name": "\u2699\ufe0f Cruzar Lead + Inventario",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        340,
        580
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "cond-generar-orden",
              "leftValue": "={{ $json.generarOrden }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "ca1df44a-4c02-4c60-98e7-24c125561e19",
      "name": "\u26a0\ufe0f \u00bfGenerar Orden?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        560,
        580
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { status: 'alerta', alerta: $json.estadoStock, orden_generada: $json.generarOrden, producto: $json.producto, stock_post_venta: $json.stockActual, mensaje: 'Alerta critica \u2014 Slack + Gemini enviado' } }}",
        "options": {}
      },
      "id": "respond-critico-001",
      "name": "\ud83d\udd01 Respond: Alerta Cr\u00edtica",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        780,
        400
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { status: 'ok', orden_generada: false, producto: $json.producto, stock_post_venta: $json.stockActual, alerta: $json.estadoStock, mensaje: 'Venta procesada \u2014 stock en rango normal' } }}",
        "options": {}
      },
      "id": "respond-ok-001",
      "name": "\ud83d\udd01 Respond: Venta Procesada",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        780,
        780
      ]
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first().json;\n\nconst prompt = `Eres un asistente experto en gesti\u00f3n de inventario y ventas B2B en Colombia.\\n\\nAcabas de procesar una venta a un cliente premium. El stock del producto vendido baj\u00f3 del m\u00ednimo requerido. Genera un mensaje ejecutivo de Slack (m\u00e1ximo 5 l\u00edneas, formato bullet points con emojis) que resuma:\\n1. La oportunidad de negocio (cliente + empresa)\\n2. El estado cr\u00edtico del inventario\\n3. La acci\u00f3n inmediata recomendada al equipo\\n\\nUsa un tono profesional pero urgente. El mensaje debe motivar al equipo a actuar r\u00e1pido.\\n\\nDATOS:\\n- Cliente: ${item.leadNombre} \u2014 ${item.leadEmpresa}\\n- Score Lead: ${item.leadScore}/10\\n- Producto: ${item.producto} (${item.codigo})\\n- Stock actual: ${item.stockActual} unidades\\n- Stock m\u00ednimo: ${item.stockMinimo} unidades\\n- Proveedor: ${item.proveedor}\\n- Estado: ${item.estadoStock}\\n\\nResponde SOLO con el mensaje de Slack, sin comillas ni texto adicional.`;\n\nconst geminiBody = JSON.stringify({\n  contents: [{ parts: [{ text: prompt }] }],\n  generationConfig: { temperature: 0.4, maxOutputTokens: 400 }\n});\n\nreturn [{ json: { ...item, prompt, geminiBody } }];"
      },
      "id": "500410b2-dbd6-4f7c-9881-46be608eb404",
      "name": "\u2699\ufe0f Preparar Prompt Alerta",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1000,
        480
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "x-goog-api-key",
              "value": "<redacted-credential>"
            }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={{ $json.geminiBody }}",
        "options": {}
      },
      "id": "cc7f40a8-b063-4154-8b96-07c6afba77ce",
      "name": "\ud83e\udd16 Gemini - Generar Orden",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1220,
        480
      ]
    },
    {
      "parameters": {
        "jsCode": "const geminiResponse = $input.first().json;\nconst prevData = $('\u2699\ufe0f Preparar Prompt Alerta').first().json;\n\nconst mensajeIA = (geminiResponse.text || geminiResponse.candidates?.[0]?.content?.parts?.[0]?.text || '').trim();\nconst mensajeFinal = prevData.mensajeSlack + (mensajeIA ? '\\n\\n\ud83d\udca1 *An\u00e1lisis IA:*\\n' + mensajeIA : '');\n\nreturn [{ json: { ...prevData, mensajeFinal } }];"
      },
      "id": "4976debf-6403-4fd1-be6a-5749e77b289d",
      "name": "\ud83d\udcdd Parsear Alerta IA",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1440,
        480
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "ventas-alertas",
          "mode": "name"
        },
        "text": "={{ $json.mensajeFinal }}",
        "otherOptions": {
          "mrkdwn": true
        },
        "authentication": "oAuth2"
      },
      "id": "7a8db477-c3be-4537-a9c0-676750dec23b",
      "name": "\ud83d\udce3 Slack \u2014 Alerta Stock Cr\u00edtico",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [
        1660,
        480
      ],
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "ventas-alertas",
          "mode": "name"
        },
        "text": "={{ $json.mensajeSlack }}",
        "otherOptions": {
          "mrkdwn": true
        },
        "authentication": "oAuth2"
      },
      "id": "e03d92e6-fd01-4af6-8d50-9106aa2d1a98",
      "name": "\ud83d\udce3 Slack \u2014 Notificaci\u00f3n Venta",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [
        1000,
        700
      ],
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1mqKIJnD6fNjPokLzC-82BG4ufo0zgMpxEvsowmOWq9M",
          "mode": "list",
          "cachedResultName": "NovaSync",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1mqKIJnD6fNjPokLzC-82BG4ufo0zgMpxEvsowmOWq9M/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 544319994,
          "mode": "list",
          "cachedResultName": "Inventario",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1mqKIJnD6fNjPokLzC-82BG4ufo0zgMpxEvsowmOWq9M/edit#gid=544319994"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "C\u00f3digo": "={{ $json.codigo }}",
            "Stock Actual": "={{ $json.stockActual }}"
          },
          "matchingColumns": [
            "C\u00f3digo"
          ],
          "schema": [
            {
              "id": "C\u00f3digo",
              "displayName": "C\u00f3digo",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Stock Actual",
              "displayName": "Stock Actual",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      },
      "id": "sheets-update-001",
      "name": "\ud83d\udd04 Actualizar Stock en Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        340,
        760
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1mqKIJnD6fNjPokLzC-82BG4ufo0zgMpxEvsowmOWq9M",
          "mode": "list",
          "cachedResultName": "NovaSync",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1mqKIJnD6fNjPokLzC-82BG4ufo0zgMpxEvsowmOWq9M/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 906478809,
          "mode": "list",
          "cachedResultName": "Ops_Alertas",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1mqKIJnD6fNjPokLzC-82BG4ufo0zgMpxEvsowmOWq9M/edit#gid=906478809"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Fecha": "={{ $json.fecha }}",
            "Hora": "={{ $json.hora }}",
            "Lead": "={{ $json.leadNombre }}",
            "Email": "={{ $json.leadEmail }}",
            "Empresa": "={{ $json.leadEmpresa }}",
            "Total_Venta": "={{ $json.total }}",
            "Cantidad": "={{ $json.cantidad }}",
            "C\u00f3digo": "={{ $json.codigo }}",
            "Producto": "={{ $json.producto }}",
            "Score_IA": "={{ $json.leadScore }}",
            "Stock_Post_Venta": "={{ $json.stockActual }}",
            "Stock_M\u00ednimo": "={{ $json.stockMinimo }}",
            "Estado_Stock": "={{ $json.stockUrgente ? 'CRITICO' : $json.stockBajo ? 'BAJO' : 'OK' }}",
            "Orden_Generada": "={{ $json.generarOrden ? 'Si' : 'No' }}",
            "Proveedor": "={{ $json.proveedor }}",
            "Mensaje_Slack": "={{ $json.mensajeFinal }}"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": [
            {
              "id": "Fecha",
              "displayName": "Fecha",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Hora",
              "displayName": "Hora",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Lead",
              "displayName": "Lead",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Empresa",
              "displayName": "Empresa",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Score_IA",
              "displayName": "Score_IA",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Producto",
              "displayName": "Producto",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "C\u00f3digo",
              "displayName": "C\u00f3digo",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Cantidad",
              "displayName": "Cantidad",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Total_Venta",
              "displayName": "Total_Venta",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Stock_Post_Venta",
              "displayName": "Stock_Post_Venta",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Stock_M\u00ednimo",
              "displayName": "Stock_M\u00ednimo",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Estado_Stock",
              "displayName": "Estado_Stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Orden_Generada",
              "displayName": "Orden_Generada",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Proveedor",
              "displayName": "Proveedor",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Mensaje_Slack",
              "displayName": "Mensaje_Slack",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      },
      "id": "5232ca41-ec64-473d-862c-001f8c3e3acf",
      "name": "\ud83d\udcca Registrar en Ops_Alertas",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1220,
        700
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1mqKIJnD6fNjPokLzC-82BG4ufo0zgMpxEvsowmOWq9M",
          "mode": "list",
          "cachedResultName": "NovaSync"
        },
        "sheetName": {
          "__rl": true,
          "value": 544319994,
          "mode": "list",
          "cachedResultName": "Inventario",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1mqKIJnD6fNjPokLzC-82BG4ufo0zgMpxEvsowmOWq9M/edit#gid=544319994"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "C\u00f3digo": "={{ $json.Codigo }}",
            "Stock Actual": "={{ $json.Stock_Actual }}"
          },
          "matchingColumns": [
            "C\u00f3digo"
          ],
          "schema": [
            {
              "id": "C\u00f3digo",
              "displayName": "C\u00f3digo",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Stock Actual",
              "displayName": "Stock Actual",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      },
      "id": "sheets-normal-001",
      "name": "\ud83d\udd04 Sheets \u2014 Venta Normal",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        -100,
        900
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "=https://lpvqyjelnzwaesohiwwk.supabase.co/rest/v1/products?codigo=eq.{{ $json.Codigo }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "<redacted-credential>"
            },
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Prefer",
              "value": "return=minimal"
            }
          ]
        },
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ stock_actual: $json.Stock_Actual }) }}",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "supabase-update-001",
      "name": "\ud83c\udf10 Actualizar Supabase",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -100,
        1040
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "\ud83d\udd27 Normalizar Datos Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd27 Normalizar Datos Webhook": {
      "main": [
        [
          {
            "node": "\ud83c\udfaf \u00bfStock Cr\u00edtico?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u2699\ufe0f Cruzar Lead + Inventario": {
      "main": [
        [
          {
            "node": "\u2699\ufe0f Preparar Prompt Alerta",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udd04 Actualizar Stock en Sheets",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udcca Registrar en Ops_Alertas",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udd01 Respond: Alerta Cr\u00edtica",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u26a0\ufe0f \u00bfGenerar Orden?": {
      "main": [
        [
          {
            "node": "\u2699\ufe0f Preparar Prompt Alerta",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udd01 Respond: Orden Generada",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\ud83d\udce3 Slack \u2014 Notificaci\u00f3n Venta",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udd01 Respond: Venta Procesada",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u2699\ufe0f Preparar Prompt Alerta": {
      "main": [
        [
          {
            "node": "\ud83e\udd16 Gemini - Generar Orden",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83e\udd16 Gemini - Generar Orden": {
      "main": [
        [
          {
            "node": "\ud83d\udcdd Parsear Alerta IA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udcdd Parsear Alerta IA": {
      "main": [
        [
          {
            "node": "\ud83d\udce3 Slack \u2014 Alerta Stock Cr\u00edtico",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udce3 Slack \u2014 Alerta Stock Cr\u00edtico": {
      "main": [
        []
      ]
    },
    "\ud83d\udce3 Slack \u2014 Notificaci\u00f3n Venta": {
      "main": [
        []
      ]
    },
    "\ud83c\udfaf \u00bfStock Cr\u00edtico?": {
      "main": [
        [
          {
            "node": "\u2699\ufe0f Cruzar Lead + Inventario",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\ud83d\udd04 Sheets \u2014 Venta Normal",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83c\udf10 Actualizar Supabase",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\udd01 Respond: Venta Normal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "163496ca-8eff-4b02-8ed2-cbb2e2fc3748",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "dVqEwHttRRBG1WIm",
  "tags": [
    {
      "name": "NovaSync",
      "id": "LTa3nmujgTAjxXNv",
      "createdAt": "2026-05-16T14:24:23.421Z",
      "updatedAt": "2026-05-16T14:24:23.421Z"
    },
    {
      "name": "Gemini Free",
      "id": "MpWueOLFF0dmoQzJ",
      "createdAt": "2026-05-16T14:24:23.479Z",
      "updatedAt": "2026-05-16T14:24:23.479Z"
    },
    {
      "name": "Ops",
      "id": "dTXSmvoQeNM5fQo9",
      "createdAt": "2026-05-16T14:24:23.454Z",
      "updatedAt": "2026-05-16T14:24:23.454Z"
    }
  ]
}