Commit Graph

49 Commits

Author SHA1 Message Date
Cauê Faleiros
64aa0a6338 Fill Jadlog tracking codes from the MULTI EMPRESAS account
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m53s
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>
2026-11-19 13:24:01 -03:00
Cauê Faleiros
e204135eb6 Send each order status to the status workflow only once
All checks were successful
Build and Deploy / build-and-push (push) Successful in 38s
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>
2026-10-08 15:30:38 -03:00
Cauê Faleiros
c5e168429d Make builds reproducible and redeploys graceful
All checks were successful
Build and Deploy / build-and-push (push) Successful in 43s
- Install with npm ci from package-lock.json so a rebuild can't pull
  different dependency versions than were tested.
- Run node directly (not via npm) so it receives SIGTERM and can drain
  queued webhooks; give the stack a 60s stop_grace_period and start the
  new task before stopping the old one.
- Add .dockerignore and stop tracking dist/ (already gitignored and
  rebuilt by the Dockerfile).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 15:12:09 -03:00
Cauê Faleiros
4fe5830f8f Stop losing notifications on Olist/n8n hiccups and redeploys
- 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>
2026-10-08 15:12:09 -03:00
Cauê Faleiros
54ffbe1b04 Stop dropping Tiny lookups during webhook bursts
All checks were successful
Build and Deploy / build-and-push (push) Successful in 49s
When more than ~5 webhooks arrived together, the 6s-spaced live Tiny
queue exceeded the 30s max wait and forwarded the order without Tiny
data: empty fone and forma_envio, so n8n silently sent no WhatsApp
message (19 such drops on 2026-10-08 alone).

Tiny is acked before the lookup, so waiting only adds latency. Raise the
default max queue wait to 15 minutes so it stays a last-resort valve
instead of something an ordinary burst can hit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 14:57:53 -03:00
Cauê Faleiros
39f0de34f2 Key Tiny order cache by status to stop forwarding stale situacao
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m23s
Tiny fires one webhook per status change, often under a minute apart
(e.g. "Preparando envio" -> "Pronto para envio"). The 120s order details
cache was keyed only by order ID, so the second webhook reused the first
fetch and forwarded the previous situacao to n8n, which then skipped the
message (notably the pickup "Pronto para envio" notification).

Key the cache and in-flight dedupe by order ID + webhook codigoSituacao,
so a status change always refetches while same-status duplicates still
share one Tiny call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 14:47:50 -03:00
Cauê Faleiros
4659222a41 Fix Swarm deployment template defaults
All checks were successful
Build and Deploy / build-and-push (push) Successful in 52s
2026-07-29 14:58:02 -03:00
Cauê Faleiros
06b59d8d37 Sync only V3 product compositions
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m46s
2026-07-29 14:46:25 -03:00
Cauê Faleiros
b1067325b9 Add Olist V3 product structure sync 2026-07-28 14:09:48 -03:00
Cauê Faleiros
4547642411 Add Tiny Olist production order sync
All checks were successful
Build and Deploy / build-and-push (push) Successful in 49s
2026-07-23 14:36:45 -03:00
Cauê Faleiros
e7ea6b4276 Let product structure tests override default CSV
All checks were successful
Build and Deploy / build-and-push (push) Successful in 53s
2026-07-23 14:15:05 -03:00
Cauê Faleiros
12aa5c7f83 Make product structure sync use product export
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m23s
2026-07-23 14:03:43 -03:00
Cauê Faleiros
bda1e22be3 Add Tiny product structure sync 2026-07-23 13:57:47 -03:00
Cauê Faleiros
831f82ee57 Improve graphs backfill resilience
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m56s
2026-07-03 12:19:43 -03:00
Cauê Faleiros
83f165381d fix: hardcode safe Tiny throttle defaults
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m9s
2026-06-23 10:34:12 -03:00
Cauê Faleiros
aa581a4d14 fix: queue live Tiny order lookups 2026-06-23 10:28:58 -03:00
Cauê Faleiros
4d7daff496 fix: throttle Graphs backfill by Tiny request
All checks were successful
Build and Deploy / build-and-push (push) Successful in 45s
2026-06-23 10:03:22 -03:00
Cauê Faleiros
44cfdbb4c9 fix: slow and control Graphs backfill
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m18s
2026-06-23 09:32:08 -03:00
Cauê Faleiros
1d24831aa7 Revert "fix: throttle Tiny API usage across backfills"
This reverts commit 10d7048497.
2026-06-22 16:31:36 -03:00
Cauê Faleiros
ae41ae4a55 Revert "fix: pause Tiny calls globally after rate blocks"
This reverts commit c315265d16.
2026-06-22 16:31:36 -03:00
Cauê Faleiros
c315265d16 fix: pause Tiny calls globally after rate blocks 2026-06-22 16:27:23 -03:00
Cauê Faleiros
10d7048497 fix: throttle Tiny API usage across backfills
All checks were successful
Build and Deploy / build-and-push (push) Successful in 59s
2026-06-22 16:17:40 -03:00
Cauê Faleiros
3234ab6160 feat: sync Tiny orders directly to Graphs
All checks were successful
Build and Deploy / build-and-push (push) Successful in 59s
2026-06-22 15:49:22 -03:00
Cauê Faleiros
9a9e9bedf2 feat: track average, max, and min stock additions per product in csv and n8n payload
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m4s
2026-05-11 12:48:30 -03:00
Cauê Faleiros
d89e2c11b1 feat: add endpoint to download stock logs csv directly from browser
All checks were successful
Build and Deploy / build-and-push (push) Successful in 42s
2026-05-11 11:56:10 -03:00
Cauê Faleiros
65fcf3f0fc feat: log stock changes to local csv file for analysis
All checks were successful
Build and Deploy / build-and-push (push) Successful in 47s
2026-05-11 11:50:34 -03:00
Cauê Faleiros
774fd4cf69 feat: add local memory tracker to calculate stock deltas
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m41s
2026-05-11 11:36:35 -03:00
Cauê Faleiros
d317a5041c feat: add http endpoint to trigger backfill script remotely
All checks were successful
Build and Deploy / build-and-push (push) Successful in 59s
2026-05-07 17:17:51 -03:00
Cauê Faleiros
7dfb3d4a03 feat: add backfill script to push historical tiny orders to n8n
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m38s
2026-05-07 17:09:54 -03:00
Cauê Faleiros
8af4bc9885 fix: map new n8n webhook environment variables in docker-compose
All checks were successful
Build and Deploy / build-and-push (push) Successful in 53s
2026-05-05 14:03:15 -03:00
Cauê Faleiros
7b74140136 fix: dispatch webhooks in parallel to prevent blocking and add config logs
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m24s
2026-05-05 13:33:01 -03:00
Cauê Faleiros
ff2f5aca29 feat: add multi-dashboard routing support for n8n
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m36s
- Refactor `sendToN8n` service to accept dynamic webhook URLs.
- Update `order-status` controller to fan-out payload to both STATUS and GRAPHS webhooks.
- Add new endpoints and controllers for stock and graphs updates (`/stock-update`, `/graphs-update`).
- Maintain backward compatibility with existing `N8N_WEBHOOK_URL` environment variable.
2026-05-05 11:26:56 -03:00
Cauê Faleiros
325099ec94 feat: include items array in payload for n8n filtering
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m14s
2026-04-10 16:25:01 -03:00
Cauê Faleiros
52646e82de fix: revert to contato.obter.php to fetch seller phone
All checks were successful
Build and Deploy / build-and-push (push) Successful in 46s
2026-04-09 19:02:10 -03:00
Cauê Faleiros
26be7effa4 fix: use correct vendedor.obter.php API endpoint
All checks were successful
Build and Deploy / build-and-push (push) Successful in 43s
2026-04-09 18:44:31 -03:00
Cauê Faleiros
ccdf6b4136 feat: add secondary fetch for seller whatsapp
All checks were successful
Build and Deploy / build-and-push (push) Successful in 39s
2026-04-09 18:21:14 -03:00
Cauê Faleiros
9011d200d7 fix: resolve typescript scoping error for api response
All checks were successful
Build and Deploy / build-and-push (push) Successful in 35s
2026-04-09 18:03:59 -03:00
Cauê Faleiros
4b68d0b359 fix: correct JSON paths for Tiny API V2
Some checks failed
Build and Deploy / build-and-push (push) Failing after 34s
2026-04-09 18:01:47 -03:00
Cauê Faleiros
2f4f7ca91a fix: prevent server crash on empty payloads
All checks were successful
Build and Deploy / build-and-push (push) Successful in 39s
2026-04-09 17:32:47 -03:00
Cauê Faleiros
246bc03124 feat: fetch full order details and format payload
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m19s
2026-04-09 17:27:42 -03:00
Cauê Faleiros
bb072af130 chore: add debug logging for auth token
All checks were successful
Build and Deploy / build-and-push (push) Successful in 41s
2026-04-09 11:37:52 -03:00
Cauê Faleiros
9fdd15e292 fix: actually send the N8N_AUTH_TOKEN header to n8n
All checks were successful
Build and Deploy / build-and-push (push) Successful in 53s
2026-04-09 11:33:25 -03:00
Cauê Faleiros
a6ba7559d1 fix: map environment variables for Docker Swarm
All checks were successful
Build and Deploy / build-and-push (push) Successful in 41s
2026-04-09 11:06:19 -03:00
Cauê Faleiros
3875cb4153 fix: updated compose for docker swarm compatibility
All checks were successful
Build and Deploy / build-and-push (push) Successful in 43s
2026-04-09 10:52:46 -03:00
Cauê Faleiros
bb136c3816 fix: removed env_file from compose so portainer UI variables work
All checks were successful
Build and Deploy / build-and-push (push) Successful in 41s
2026-04-09 10:45:24 -03:00
Cauê Faleiros
c8b24eeaea fix: actually upload package.json
All checks were successful
Build and Deploy / build-and-push (push) Successful in 41s
2026-04-09 10:36:37 -03:00
Cauê Faleiros
6e7d266a72 fix: explicit package.json copy in Dockerfile
Some checks failed
Build and Deploy / build-and-push (push) Failing after 27s
2026-04-09 10:30:20 -03:00
Cauê Faleiros
923705c83b feat: initial commit of tiny-n8n middleware with CI/CD
Some checks failed
Build and Deploy / build-and-push (push) Failing after 27s
2026-04-09 10:28:23 -03:00
Cauê Faleiros
c687fd2bd1 first commit
Some checks failed
Build and Deploy / build-and-push (push) Failing after 4m14s
2026-04-09 09:45:02 -03:00