Skip to content

feat(wake): order analytics — totals, PII-free projection, dashboard, rate gate - #600

Merged
thalesvf merged 1 commit into
mainfrom
feat/wake-orders-analytics
Nov 26, 2026
Merged

thalesvf merged 1 commit into
mainfrom
feat/wake-orders-analytics

Conversation

@thalesvf

@thalesvf thalesvf commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Why

Analytics apps reading a Wake store's orders through this MCP (first one: insights-mcp's sales radar) hit four problems:

  1. No total. WAKE_LIST_ORDERS dropped Wake's x-total-count header. A caller couldn't size its paging or tell how many orders a day had.
  2. A bare day returned an empty list. Wake reads 2026-11-25 as midnight. A date-only dataFinal ended the range where it started, with no error.
  3. Every order carried personal data. Buyer name, CPF, e-mail, phones, street address, card holder and masked number, Pix QR code and free-text notes all went through the gateway, even when the caller only needed totals.
  4. No protection of the token. Wake allows 120 req/min per Admin token. A token that keeps calling after a 429 is blocked for an hour, and that block hits every integration sharing it.

What

WAKE_LIST_ORDERS (backwards compatible: items and count are unchanged, fields defaults to full)

  • Returns total (from x-total-count), page, pageSize and hasMore.
  • A bare day means the whole day: 00:00:00 to 23:59:59. T is accepted as the separator.
  • New params: direcaoOrdenacao, listaPedidosIds (up to 50 ids in one call, instead of WAKE_GET_ORDER in a loop), DataStatus in enumTipoFiltroData, and camposAdicionais. Array params are sent as repeated keys.
  • fields: "analytics" is a whitelist projection (lib/order-analytics.ts).
    • Keeps: status, dates, totals, coupon, channel, split siblings, fulfilling distribution centers, pickup store, city/state, items with their promotion id and coupon, payment group/brand/acquirer, and UTMs and other non-personal metadata.
    • Drops everything that identifies a person. A field Wake adds later stays out until someone adds it to the projection.

New read tools

Tool Endpoint
WAKE_DASHBOARD /dashboard/{receita,transacoes,ticketMedio,faturamento,graficofaturamento,graficoformapagamento,produtos,novoscompradores,carrinhoabandonado,produtoestoque}
WAKE_LIST_PAYMENT_METHODS /formasPagamento
WAKE_LIST_ORDER_ORIGINS /origensPedido
WAKE_LIST_DISTRIBUTION_CENTERS /centrosdistribuicao
WAKE_LIST_PHYSICAL_STORES /lojasFisicas (paged, with total)

Rate gate (lib/rate-gate.ts, applied to every Admin call)

  • Paces each token to WAKE_ADMIN_MAX_PER_MINUTE calls per minute (default 100) per process. A call waits up to 15 s for a free slot.
  • After a 429, refuses that token locally until Retry-After has passed, without reaching Wake.
  • Never retries. A refusal fails with [wake-rate-limited] … retry-after=<s>, so callers can back off.
  • State is keyed by a SHA-256 of the token.

Also: the README documents dates (store local time, no offset), the page-199 ceiling and the rate limit. app.json, registry.json and the version (1.1.0) are updated.

Verified

  • bun test (wake): 22 pass. They cover the gate (pacing, refusal, 429 block, Retry-After parsing), the client (x-total-count, the 429 stop, array query strings), the date range and hasMore, and the analytics projection. The projection tests use a synthetic order that carries every personal field, and assert that none of them survive.
  • scripts/check.ts wake, oxfmt --check, oxlint and check:registry are clean. The one wake lint warning (body on GET in fetch) predates this change.
  • Against a live store's Admin API before this PR, through the current tools:
    • order dates match GA4's purchase timestamps to the minute, which confirms they are local time with no offset;
    • a date-only range returns [];
    • the list carries complete orders, with UTMs in metadados and promotions with coupon in itens[].ajustes.
  • Not yet run live: the new endpoints (/dashboard/*, /formasPagamento, /origensPedido, /centrosdistribuicao, /lojasFisicas) and the x-total-count header. Their paths and params follow Wake's API reference. A wrong path would surface as a clear HTTP 404 from the tool. I'll call each one on a real connection right after deploy.

🤖 Generated with Claude Code


Summary by cubic

Adds order analytics to the Wake MCP: WAKE_LIST_ORDERS now reports totals, handles date-only ranges, and can project orders without personal data, plus new dashboard and reference tools and a per-token rate gate.

Order listing improvements

  • Returns total, page, pageSize, and hasMore from Wake's x-total-count header.
  • A bare day (2026-11-25) now means the whole day; previously a date-only dataFinal ended at midnight and returned nothing.
  • New params: direcaoOrdenacao, listaPedidosIds (up to 50 ids in one call), DataStatus filter, and camposAdicionais.
  • fields: "analytics" returns a whitelist projection that drops buyer name, CPF, e-mail, phones, street address, card data, Pix QR code, and free-text notes; a field Wake adds later stays out until added to the projection.
  • items and count are unchanged; fields defaults to full.

New tools and rate gate

  • Adds WAKE_DASHBOARD (revenue, transactions, average ticket, payment methods, best sellers, abandoned carts), WAKE_LIST_PAYMENT_METHODS, WAKE_LIST_ORDER_ORIGINS, WAKE_LIST_DISTRIBUTION_CENTERS, and WAKE_LIST_PHYSICAL_STORES.
  • Every Admin call now goes through a per-token gate: paced to 100 calls/minute (configurable) with a 15 s wait, and after a 429 the token is refused locally until Retry-After passes, without reaching Wake. The refusal carries a [wake-rate-limited] error so callers can back off.
  • Wake blocks a token for an hour when calls keep coming after a 429, and that block hits every integration sharing the token.
  • Bumps version to 1.1.0 and documents dates, paging limits, and the rate limit in the README.

Written for commit c4e6c74. Summary will update on new commits.

View guided diff Turn on auto-fix

… rate gate

WAKE_LIST_ORDERS now returns Wake's x-total-count (total, hasMore), reads a
bare day as the whole day (a date-only dataFinal used to end the range at
midnight and return nothing), and takes direcaoOrdenacao, listaPedidosIds,
DataStatus and camposAdicionais. fields: "analytics" returns each order
without the buyer, documents, street address, card, Pix QR or free-text
notes.

New read tools: WAKE_DASHBOARD (/dashboard/* aggregates),
WAKE_LIST_PAYMENT_METHODS, WAKE_LIST_ORDER_ORIGINS,
WAKE_LIST_DISTRIBUTION_CENTERS and WAKE_LIST_PHYSICAL_STORES.

Every Admin call goes through a per-token gate: at most
WAKE_ADMIN_MAX_PER_MINUTE (default 100) per minute, and after a 429 the
token is refused locally until Retry-After, with a [wake-rate-limited]
error and no retry. Wake blocks a token for an hour when it keeps calling
past its limit.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@deco-hosting
deco-hosting Bot temporarily deployed to preview/pr-600/wake November 26, 2026 21:05 Destroyed
@thalesvf
thalesvf merged commit 2c36c40 into main Nov 26, 2026
2 of 3 checks passed

This branch was successfully deployed

No deployments
preview/pr-600/wake — c4e6c743 Deployed Nov 26, 2026 by deco-hosting[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants