Jadlog orders are invoiced by the MULTI EMPRESAS Olist account, so our
order reaches "Enviado" with forma_envio J and an empty tracking code.
When TINY_API_TOKEN_MULTI is set, shipped Jadlog orders without tracking
are matched in that account (search by customer CPF/name from the order
date, confirmed by numero_ordem_compra) and the code is forwarded in
codigo_rastreamento. Calls are serialized and cached; any failure keeps
today's payload.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tiny fires an order webhook on every edit, not only on status changes,
and the middleware forwarded all of them, so n8n could send the customer
the same WhatsApp again (seen: order 986470642 got "enviado" twice
within 2 minutes).
Remember the last status forwarded per order and skip repeats:
- recorded only after n8n accepted it and only for orders with Tiny
data, so failed or incomplete sends can still go through;
- claimed before sending, so simultaneous duplicates send once;
- saved to data-runtime/status_notifications_sent.json (30-day TTL) so
redeploys don't resend; re-read when another container updates it;
- a real change back to an earlier status is still sent;
- the Graphs workflow still receives every update.
STATUS_DEDUPE_ENABLED=false turns it off.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Olist lookups: 20s timeout so one hung request can't stall the serial
queue; retry temporary failures (codigo_erro 6/11/35/99, timeouts,
5xx) with backoff instead of forwarding orders without phone or
forma_envio. Log "[Notification at risk]" when that still happens.
- n8n forwarding: timeout plus retries, only when n8n certainly didn't
run the workflow (connection refused, 502/503, 404 while restarting),
so retries can't send a customer the same WhatsApp twice. Stop logging
the start of N8N_AUTH_TOKEN.
- On SIGTERM, stop accepting requests and finish webhooks already acked
to Tiny (up to SHUTDOWN_GRACE_MS, default 50s).
- Keep stock_memory.json and stock_log.csv on the data-runtime volume so
stock stats survive redeploys.
- Add a node:test suite (npm test) covering the payload n8n reads, the
status cache, burst queueing, retries, stock files and shutdown drain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>