feat(wake): order analytics ā totals, PII-free projection, dashboard, rate gate
Merged
TH
4d ago+1094+1094+0123456789012345678901234567890123456789-46-46-01234567890123456789
Why
Analytics apps reading a Wake store's orders through this MCP (first one: insights-mcp's sales radar) hit four problems:
- No total.
WAKE_LIST_ORDERSdropped Wake'sx-total-countheader. A caller couldn't size its paging or tell how many orders a day had. - A bare day returned an empty list. Wake reads
2026-11-25as midnight. A date-onlydataFinalended the range where it started, with no error. - 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.
- 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(fromx-total-count),page,pageSizeandhasMore. - A bare day means the whole day:
00:00:00to23:59:59.Tis accepted as the separator. - New params:
direcaoOrdenacao,listaPedidosIds(up to 50 ids in one call, instead ofWAKE_GET_ORDERin a loop),DataStatusinenumTipoFiltroData, andcamposAdicionais. 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_MINUTEcalls 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-Afterhas 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-Afterparsing), the client (x-total-count, the 429 stop, array query strings), the date range andhasMore, 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,oxlintandcheck:registryare clean. The one wake lint warning (bodyon GET infetch) 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
metadadosand promotions with coupon initens[].ajustes.
- Not yet run live: the new endpoints (
/dashboard/*,/formasPagamento,/origensPedido,/centrosdistribuicao,/lojasFisicas) and thex-total-countheader. Their paths and params follow Wake's API reference. A wrong path would surface as a clearHTTP 404from 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, andhasMorefrom Wake'sx-total-countheader. - A bare day (
2026-11-25) now means the whole day; previously a date-onlydataFinalended at midnight and returned nothing. - New params:
direcaoOrdenacao,listaPedidosIds(up to 50 ids in one call),DataStatusfilter, andcamposAdicionais. 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.itemsandcountare unchanged;fieldsdefaults tofull.
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, andWAKE_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-Afterpasses, 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.