@12-apps/marketplace 1.13.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADOPTING.md +258 -3
- package/README.md +27 -2
- package/dist/99food/index.d.ts +2 -2
- package/dist/99food/index.js +3 -3
- package/dist/{adapter-CQ4QiZPi.d.ts → adapter-CjVdMhZ2.d.ts} +177 -4
- package/dist/{chunk-CEWTV2TC.js → chunk-B4DYPQFE.js} +657 -251
- package/dist/chunk-B4DYPQFE.js.map +1 -0
- package/dist/{chunk-4J2KJ3ZW.js → chunk-BTKVZAJI.js} +1 -1
- package/dist/chunk-BTKVZAJI.js.map +1 -0
- package/dist/{chunk-BD7DS3XM.js → chunk-E4XJXHUK.js} +20 -1
- package/dist/chunk-E4XJXHUK.js.map +1 -0
- package/dist/{chunk-W57TITU4.js → chunk-FQI56NGC.js} +53 -6
- package/dist/chunk-FQI56NGC.js.map +1 -0
- package/dist/chunk-H2VQRD3B.js +16 -0
- package/dist/chunk-H2VQRD3B.js.map +1 -0
- package/dist/{chunk-NFJQQWG4.js → chunk-TRUK5ZBE.js} +12 -4
- package/dist/chunk-TRUK5ZBE.js.map +1 -0
- package/dist/{client-CCSnylou.d.ts → client-DgzCkl8u.d.ts} +1 -1
- package/dist/{engine-1KlJ_8jK.d.ts → engine-BSLdhAGC.d.ts} +134 -3
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +3 -2
- package/dist/hono/index.js.map +1 -1
- package/dist/ifood/index.d.ts +13 -3
- package/dist/ifood/index.js +219 -29
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +29 -5
- package/dist/index.js +59 -7
- package/dist/index.js.map +1 -1
- package/dist/keeta/index.d.ts +2 -2
- package/dist/keeta/index.js +3 -3
- package/dist/manifest/server.d.ts +4 -2
- package/dist/manifest/server.js +3 -2
- package/dist/manifest/server.js.map +1 -1
- package/dist/rappi/index.d.ts +1 -1
- package/dist/rappi/index.js +2 -2
- package/dist/server/index.d.ts +14 -5
- package/dist/server/index.js +3 -2
- package/package.json +1 -1
- package/prisma/marketplace.prisma +17 -3
- package/prisma/migrations/20261202120000_marketplace_ifood_conformity/migration.sql +25 -0
- package/src/core/acceptance.ts +12 -6
- package/src/core/acknowledge.ts +189 -0
- package/src/core/adapter.ts +74 -1
- package/src/core/cancellation.ts +10 -6
- package/src/core/conformity.ts +63 -0
- package/src/core/engine.ts +3 -2
- package/src/core/ingest.ts +7 -0
- package/src/core/link-store.ts +2 -4
- package/src/core/marketplace-confirmed.ts +229 -0
- package/src/core/order-reasons.ts +119 -0
- package/src/core/order-types.ts +8 -0
- package/src/core/outbound.ts +5 -1
- package/src/core/payload-read.ts +24 -0
- package/src/core/pipeline.ts +27 -1
- package/src/core/ports.ts +2 -0
- package/src/core/registry.ts +28 -2
- package/src/core/state.ts +10 -0
- package/src/core/status-job.ts +86 -3
- package/src/core/types.ts +117 -2
- package/src/ifood/index.ts +27 -4
- package/src/ifood/normalize.ts +38 -5
- package/src/ifood/order-details.ts +120 -0
- package/src/ifood/outbound.ts +131 -27
- package/src/index.ts +24 -0
- package/src/open-delivery/normalize.ts +9 -0
- package/src/server/jobs.ts +57 -4
- package/src/server/webhook.ts +27 -4
- package/dist/chunk-4J2KJ3ZW.js.map +0 -1
- package/dist/chunk-BD7DS3XM.js.map +0 -1
- package/dist/chunk-CEWTV2TC.js.map +0 -1
- package/dist/chunk-NFJQQWG4.js.map +0 -1
- package/dist/chunk-W57TITU4.js.map +0 -1
package/ADOPTING.md
CHANGED
|
@@ -456,9 +456,9 @@ path, the one 99Food and Keeta already use. A PLACED that does carry the order
|
|
|
456
456
|
|
|
457
457
|
**The path is the webhook only.** The software connects to iFood as one
|
|
458
458
|
centralized app that iFood calls back (owner, FUT-5798: "no 30-second
|
|
459
|
-
polling"), so the engine has no events poller
|
|
460
|
-
`events:polling
|
|
461
|
-
|
|
459
|
+
polling"), so the engine has no events poller and never calls
|
|
460
|
+
`events:polling`. Since section 12, each recorded event is acknowledged
|
|
461
|
+
(`events/acknowledgment`, from a job), which iFood's Order homologation asks.
|
|
462
462
|
|
|
463
463
|
**The contract.**
|
|
464
464
|
|
|
@@ -487,3 +487,258 @@ order type, who delivers, the address and the pickup code), plus
|
|
|
487
487
|
merchant than the connection's is refused FAILED, as for 99Food. The canonical
|
|
488
488
|
shape has no field for an item's options or for the payment methods; the raw
|
|
489
489
|
order is not stored by the engine.
|
|
490
|
+
|
|
491
|
+
## 12. iFood homologation conformity (FUT-5984, FUT-5653, FUT-5673)
|
|
492
|
+
|
|
493
|
+
The contract of this release, written before its code: every case below is a
|
|
494
|
+
test that failed on `main` (`be17871d`, 2026-12-02: `npx vitest run` of the six
|
|
495
|
+
files named in the table, 22 failed and 12 passed; the passing 12 are the
|
|
496
|
+
"unchanged" rows, pinned so they stay unchanged). The iFood pages it follows
|
|
497
|
+
were read on 2026-12-02 as Markdown (`developer.ifood.com.br/pt-BR/docs/…/<page>.md`):
|
|
498
|
+
Events `webhook-overview`, `webhook-best-practices`, `presence`,
|
|
499
|
+
`polling-overview` (its API reference), `homologation`; Order `endpoints`,
|
|
500
|
+
`cancellation`, `homologation`; Authentication `intro`.
|
|
501
|
+
|
|
502
|
+
### 12.1 The cases
|
|
503
|
+
|
|
504
|
+
| id | event / state / provider | `main` today (measured) | this release | test |
|
|
505
|
+
|---|---|---|---|---|
|
|
506
|
+
| W1 | an iFood delivery, per-store or app address, recorded | `200` | `202 Accepted`, after the inbox row is written ("Retorne `202 Accepted` em até 5 segundos", `webhook-overview`); a redelivery too | `server/__tests__/ifood-webhook-answer.test.ts` |
|
|
507
|
+
| W2 | any other marketplace | `200` | `200`, unchanged: the answer status is the adapter's `capabilities.webhookAnswerStatus`, absent = 200 | same |
|
|
508
|
+
| W3 | a refusal (bad signature, no store) or a processing failure | `401` / `500` | unchanged | same |
|
|
509
|
+
| K1 | iFood `KEEPALIVE` (`{code, fullCode, id}`, every 30 s, no merchant) on the app's address, signed by the app's key | `401` (no merchant → no store) | `202`, no statement (no merchant lookup, no connection read), no inbox row: the signature is checked against the app's own key, `appCredentials` for both environments (`presence`: "KEEPALIVE … `X-IFood-Signature`"; "`202 Accepted` → merchant(s) ficam online") | same |
|
|
510
|
+
| K2 | `KEEPALIVE` unsigned, signed by another key, or no app configured | `401` | `401`, unchanged | same |
|
|
511
|
+
| K3 | `KEEPALIVE` in iFood's per-merchant mode (`merchantIds` in the body) | `401` | `202` `{ merchantIds }` naming every merchant it asked about: while the software answers, every store it serves is online, the per-app mode's meaning. The per-app mode is iFood's default ("Por aplicativo (padrão)", configured on the Developer Portal) and is the one to register; the per-merchant answer only keeps a portal switched to it from taking every store offline | same |
|
|
512
|
+
| K4 | `KEEPALIVE` on a store's own address, signed by its key | `200 {ignored: "unrecognized_payload"}` | `202`, no inbox row; a bad signature stays `401` | same |
|
|
513
|
+
| A1 | an iFood event recorded in the inbox (fresh) | nothing | `marketplace.acknowledge` `{ clientId, provider }` queued after the row is written, key `marketplace.acknowledge:<inboxId>`; a redelivery queues nothing; the request calls nobody | `__tests__/acknowledgment.test.ts` |
|
|
514
|
+
| A2 | the job | none exists | `POST /events/v1.0/events/acknowledgment` with `[{ id }]` of every event of that store recorded in the last 8 h and not yet acknowledged, up to 2000 a call (`polling-overview`: "Limite: até 2000 IDs por requisição"); 2xx stamps `acknowledged_at` on exactly those rows; a second run sends nothing ("apenas uma vez por evento") | same |
|
|
515
|
+
| A7 | the marketplace refuses the batch for good (a final 4xx, not our credentials) | — | given up on: stamped and logged at error, never resent (one bad id cannot make every reconcile pass resend the store's events for 8 h); our own credentials refused leave them owed | same |
|
|
516
|
+
| A3 | the call fails (5xx, 429, timeout) | — | retried (3 attempts, exponential from 10 s); the rows stay owed; the last attempt leaves them for the sweep. A final 4xx is logged and leaves them owed until the 8 h window closes. Never blocks or fails the ingest | same |
|
|
517
|
+
| A4 | an enqueue lost, or a job that gave up | — | the `marketplace.reconcile-inbox` pass also re-queues one job per (store, marketplace) with events still owed inside the window | same |
|
|
518
|
+
| A5 | an event older than 8 h | — | never acknowledged (iFood keeps events 8 h) | same |
|
|
519
|
+
| A6 | a marketplace whose adapter states no `acknowledgement` (99Food, Keeta, Rappi) | nothing | nothing | same |
|
|
520
|
+
| R1 | an iFood order ingested | static reasons only, no call | `marketplace.cancellation-reasons` `{ clientId, orderId }` queued after the ingest's commit, key `…:<orderId>` | `__tests__/cancellation-reasons.test.ts` |
|
|
521
|
+
| R2 | the job | none exists | `GET /order/v1.0/orders/{id}/cancellationReasons` with the connection's bearer; `{ reasons: [{ code, description }] }` (or a bare array) is kept on the order (`marketplace_acceptances.cancellation_reasons`) for its life; a second run calls nobody. `engine.orderReasons(clientId, orderId)` and `orderStates(…).cancellationReasons` answer it, each code labelled by the pack when the pack names it, else by iFood's own `description` | same |
|
|
522
|
+
| R3 | the read fails | — | retried (3 attempts); the last leaves the column null and the order's reasons are the adapter's static list (the fallback) | same |
|
|
523
|
+
| R4 | the store refuses with a code of the order's list | the code must be in the static list; the body was `{ reason: <label>, cancellationCode: <code> }` | accepted; the body is exactly `{ "reason": "<code>" }` (`cancellation`: `-d '{"reason": "503"}'`) | same |
|
|
524
|
+
| R5 | a code not in the order's list | judged against the static list | `INVALID_REASON` naming the order's codes | same |
|
|
525
|
+
| R6 | the static fallback | body as R4 on `main` | `{ "reason": "<code>" }` | same |
|
|
526
|
+
| R7 | a refusal validated against the static list, the order's list stored before the send | — | the validated code is sent (resolved against the order's list, else the static one it was validated against); iFood's answer decides, never a FAILED of ours with no call | same |
|
|
527
|
+
| R8 | iFood answers `{ reasons: [] }` | — | not kept: the static list stays the order's (an empty list would refuse every refusal) | same |
|
|
528
|
+
| D1 | READY of an iFood order `deliveredBy: MERCHANT` | skipped ("does not take READY") | `POST /orders/{id}/readyToPickup`, SENT (`endpoints`: "Para entrega própria, notifique o pedido pronto via `POST /orders/{id}/readyToPickup` antes de despachar via `/dispatch`"; the verb is the Endpoints page's POST; the homologation page's PUT is the doc conflict, see 12.3) | `__tests__/status-conformity.test.ts` |
|
|
529
|
+
| D2 | DISPATCHED of a merchant bag with no READY told | `dispatch` alone | `readyToPickup` first (its own READY row), then `dispatch`, in that order, in the same run | same |
|
|
530
|
+
| D3 | DISPATCHED while READY is SENDING under another run | `dispatch` sent | retried (the dispatch waits); nothing sent | same |
|
|
531
|
+
| D4 | DISPATCHED with READY SENT (or FAILED) | `dispatch` | `dispatch`, unchanged | same |
|
|
532
|
+
| D5 | a fleet bag's DISPATCHED | skipped | skipped, unchanged | same |
|
|
533
|
+
| S1 | any status step of an ACCEPTED order whose confirm is still owed (`confirmed_at` and `confirm_failed_at` null), on a marketplace that states `statusAfterConfirm` (iFood only) | sent | retried, no row, no call (FUT-5673 item 1) | same |
|
|
534
|
+
| S2 | the confirm failed (`confirm_failed_at`) | sent | skipped ("the marketplace never took the store's confirm"), no row | same |
|
|
535
|
+
| S3 | still owed on the last attempt | sent | skipped, never sent before the confirm | same |
|
|
536
|
+
| S4 | the confirm taken | sent | sent, unchanged | same |
|
|
537
|
+
| S5 | 99Food, Keeta, Rappi (no `statusAfterConfirm`), confirm owed or failed | sent | sent, unchanged: FUT-5673 is iFood's | `__tests__/status-adapters.test.ts` |
|
|
538
|
+
| T1 | the store's iFood token 30 s from its `expiresIn` | renewed (60 s margin) | used: "Renove tokens … apenas quando expirados, não antecipadamente" (Order `homologation`) | `ifood/__tests__/token.test.ts` |
|
|
539
|
+
| T2 | the token expired | renewed | renewed, unchanged | same |
|
|
540
|
+
| T3 | a 401 on an order call | token forgotten, the attempt answers `retry` (the queue retries 30 s later) | token forgotten, a new one bought and the call made again, once, inside the same call ("Prepare seu aplicativo para solicitar um novo token quando receber status 401", Authentication `intro`) | same |
|
|
541
|
+
| T4 | a second 401 | — | `retry`, no third grant | same |
|
|
542
|
+
| T5 | a linked store's access token 30 s from expiry | refreshed (60 s margin) | used | same |
|
|
543
|
+
| C0 | iFood `CFM` / `CONFIRMED` | normalizes with no meaning (IGNORED, "no order body") | `NormalizedEvent.marketplaceConfirmed: true` | `__tests__/marketplace-confirmed.test.ts` |
|
|
544
|
+
| C1 | CFM of an order AWAITING here | IGNORED; the clock expires it later and the host cancels it | stamped `confirmed_at`, then the SAME admit + claim as a decision (`order.admit` with `decision: "ACCEPT"`, `admission: {}`: the stock ask), AWAITING → ACCEPTED, NO confirm queued (iFood has it), `onAccepted` after the commit; outcome `confirmedByMarketplace`, `accepted: true` (owner's decision on FUT-5653, 2026-12-02) | same |
|
|
545
|
+
| C2 | CFM whose admit the host refuses (stock ask, unmapped line, plan paused) | as C1 | stays AWAITING for a person, `confirmed_at` stamped: the clock never expires it; the person's aceite (Sim on the stock ask) goes through `decide` as ever, and its queued confirm is skipped ("already stamped"); outcome `accepted: false` with the host's `refusal` | same |
|
|
546
|
+
| C3 | an order accepted or stamped by CFM, past its deadline | expired | never expired: the expiry predicate adds `confirmed_at IS NULL` | same |
|
|
547
|
+
| C4 | CFM of an ACCEPTED order whose confirm is stamped (our confirm's echo), or of a REJECTED or EXPIRED one | IGNORED | IGNORED, unchanged | same |
|
|
548
|
+
| C9 | CFM of an ACCEPTED order whose confirm is not stamped (`confirmed_at` null, `confirm_failed_at` either way): a person's aceite raced the tablet's, or our confirm timed out but landed | IGNORED; the queued confirm is sent again (and a 4xx stamps `confirm_failed_at`, which S2 would then make stop every step) | `confirmed_at` stamped, no host call: the queued confirm skips ("already stamped"). With `confirm_failed_at` already set (the tablet confirmed, a person's aceite claimed it here, our duplicate confirm got a 4xx before the CFM landed) it is cleared too: iFood says the order IS confirmed, and leaving the failure would make S2 skip every later step of a confirmed order and the host show "não confirmou" (worse than `main`, where steps ignored the confirm) | same |
|
|
549
|
+
| C5 | CFM before its order (the PLACED's fetch still running) | IGNORED, lost | DEFERRED (PENDING, `confirmed before its order`); when an adapter that `marketplaceConfirms` ingests that order, the deferred confirmation is applied right after the ingest's commit | same |
|
|
550
|
+
| C6 | CFM while the store's cancellation request stands | IGNORED | `confirmed_at` stamped (the request's answer or window ends the order, not the clock); no admit, no claim | same |
|
|
551
|
+
| C7 | a deferred CFM still PENDING when the clock runs out | expired | the expiry sweep applies it first (one inbox read, only when rows lapsed), so the order is accepted, not expired | same |
|
|
552
|
+
| C8 | an AWAITING order with no CFM past its deadline | expired | expired, unchanged | same |
|
|
553
|
+
| N1 | `marketplace.prisma` comment on `follow_status` | "Governs the INBOUND move only: telling the marketplace … is always on" | "Off: neither side moves the other" (FUT-5673 item 2, the owner's decision); comment only, the applied migration's SQL comment is left as it is | — |
|
|
554
|
+
|
|
555
|
+
### 12.2 Invariants
|
|
556
|
+
|
|
557
|
+
- **No order is created or cancelled differently than on `main`** except where
|
|
558
|
+
the table says: C1/C2/C5/C7 accept (never cancel) an AWAITING order iFood
|
|
559
|
+
confirmed, through the host's own admit; nothing else moves an acceptance.
|
|
560
|
+
- **No iFood call inside a webhook request.** The request writes the inbox row,
|
|
561
|
+
queues (fetch, acknowledge) and answers; KEEPALIVE reads nothing. Every iFood
|
|
562
|
+
call is a job's: `marketplace.fetch-order`, `marketplace.acknowledge`,
|
|
563
|
+
`marketplace.cancellation-reasons`, `marketplace.outbound`.
|
|
564
|
+
- **Every new job is durable and idempotent.** `acknowledge`: the stamp
|
|
565
|
+
`acknowledged_at` is the marker, the reconcile pass re-queues what is owed;
|
|
566
|
+
two runs racing may send an id twice (harmless: iFood answers 202 and keys on
|
|
567
|
+
the id). `cancellation-reasons`: the column is the marker; a lost job leaves
|
|
568
|
+
the static fallback. The admit + claim of a CFM is the decision path's own
|
|
569
|
+
transaction (all or nothing), predicated on AWAITING with no request standing.
|
|
570
|
+
- **Money:** a CFM goes through the host's `order.admit` (the stock ask and its
|
|
571
|
+
draw), never a bypass; a refused admit leaves the order for a person.
|
|
572
|
+
- **The normal webhook path costs no new statement.** The answer status is an
|
|
573
|
+
adapter constant; the acknowledge enqueue is a queue call.
|
|
574
|
+
|
|
575
|
+
### 12.3 What is still ESTIMATED
|
|
576
|
+
|
|
577
|
+
- `readyToPickup` / `dispatch` verb: the Endpoints page says POST, the Order
|
|
578
|
+
homologation page says PUT. POST is kept (the more detailed page).
|
|
579
|
+
- Acknowledgment for a WEBHOOK app: the Events concepts page says a webhook
|
|
580
|
+
delivery has none; the Order homologation page asks `POST /acknowledgment`
|
|
581
|
+
for every event. Both are honoured (202 fast AND acknowledge).
|
|
582
|
+
- `cancellationReasons` answering a bare array instead of `{ reasons }`: read
|
|
583
|
+
either way.
|
|
584
|
+
- The order's list is read once, after ingest, and kept: iFood's page says it
|
|
585
|
+
lists the codes accepted "now", so a list can be stale by a later cancel.
|
|
586
|
+
iFood's own refusal of the request (CANCELLATION_REQUEST_FAILED) is then
|
|
587
|
+
what tells the store; re-reading before each refusal would put a call in
|
|
588
|
+
the dialog's path.
|
|
589
|
+
- In the sandbox (2026-12-02), `cancellationReasons` of an unknown order
|
|
590
|
+
answered 403, not 404: read as a final refusal, the static list applies.
|
|
591
|
+
|
|
592
|
+
### 12.4 What the host binds
|
|
593
|
+
|
|
594
|
+
1. **Migration `20261202120000_marketplace_ifood_conformity`** (additive):
|
|
595
|
+
`marketplace_inbox_events.acknowledged_at` and two partial indexes of the
|
|
596
|
+
rows still owed (per store for the job, per marketplace for the sweep), `marketplace_acceptances.cancellation_reasons` (JSONB). Sync the
|
|
597
|
+
partial, `prisma generate`, apply it with the bump: the engine selects both.
|
|
598
|
+
2. **The two new jobs** arrive with `MARKETPLACE_JOBS`
|
|
599
|
+
(`marketplace.acknowledge`, `marketplace.cancellation-reasons`); let the
|
|
600
|
+
`enqueue` port take both names (a host that holds jobs by name must not hold
|
|
601
|
+
these: holding the acknowledgment makes iFood redeliver).
|
|
602
|
+
3. **The app's webhook** stays one address; nothing changes for KEEPALIVE but
|
|
603
|
+
`appCredentials` must be bound (it already is for linking). Register the
|
|
604
|
+
per-app presence mode on iFood's portal.
|
|
605
|
+
4. **The CFM admit** is the host's existing `order.admit`: it is called with
|
|
606
|
+
`decision: "ACCEPT"` and `admission: {}` outside any surface's context, like
|
|
607
|
+
the admin route's aceite. `onAccepted` follows. An AWAITING row whose
|
|
608
|
+
`orderStates(…).confirmedAt` is set is "accepted on the marketplace, waiting
|
|
609
|
+
for your answer" (C2): draw it so, never with a countdown.
|
|
610
|
+
5. **The refusal dialog** reads the order's own reasons
|
|
611
|
+
(`orderStates(…).cancellationReasons`, null = `reasons(provider)`), never
|
|
612
|
+
the static list alone.
|
|
613
|
+
6. **TypeScript-visible additions** (the release is a minor; a host with
|
|
614
|
+
exhaustive switches or hand-built fakes adapts):
|
|
615
|
+
- `DeliveryOutcome` gains `confirmedByMarketplace` (an exhaustive switch
|
|
616
|
+
adds the case);
|
|
617
|
+
- `MarketplaceOrderState.cancellationReasons` is a new required field (a
|
|
618
|
+
hand-built fake adds it, `null` keeps the static list);
|
|
619
|
+
- `MarketplaceDb.marketplaceInboxEvent.updateMany` is a new required member
|
|
620
|
+
(Prisma's delegate has it; a hand-built fake adds it);
|
|
621
|
+
- `MarketplaceCapabilities` gains the optional `webhookAnswerStatus`,
|
|
622
|
+
`marketplaceConfirms` and `statusAfterConfirm`, and the adapter the
|
|
623
|
+
optional `statusPrerequisite`, `presence`, `acknowledgement`,
|
|
624
|
+
`orderCancellationReasons`.
|
|
625
|
+
7. **Ship the bump as one unit**: the engine selects `cancellation_reasons`
|
|
626
|
+
on every decision, so the partial sync, `prisma generate` and the migration
|
|
627
|
+
go with it; and until the refusal dialog reads the order's own reasons
|
|
628
|
+
(step 5), a static code iFood did not list for that order is refused
|
|
629
|
+
`INVALID_REASON` instead of being sent.
|
|
630
|
+
|
|
631
|
+
## 13. Options, payment, fees and the buyer's document (FUT-5803)
|
|
632
|
+
|
|
633
|
+
An iFood order used to land without its complementos, its payment, its fees
|
|
634
|
+
besides delivery, the buyer's CPF/CNPJ and its eat-in types, and its lines
|
|
635
|
+
could sum to less than the receipt (a line was priced `unitPrice` only). Every
|
|
636
|
+
case below is a test in `src/ifood/__tests__/order-details.test.ts`, replayed
|
|
637
|
+
with the order shape of iFood's order-details guide
|
|
638
|
+
("Detalhes do pedido" on iFood's developer portal; the page answered 404 and 403
|
|
639
|
+
from this environment on 2026-12-02, so the shape was not checked against it), that failed
|
|
640
|
+
on `main` (`3e8ce550`: 14 failed; the 3 "absent when unstated" cases passed and
|
|
641
|
+
stay pinned).
|
|
642
|
+
|
|
643
|
+
### 13.1 The shape (additive, provider-neutral)
|
|
644
|
+
|
|
645
|
+
| field | meaning | iFood source | other adapters |
|
|
646
|
+
|---|---|---|---|
|
|
647
|
+
| `NormalizedOrderLine.options?: NormalizedLineOption[]` | each option the buyer chose: `externalCode`, `name`, `groupName`, `quantity` (for the WHOLE line), `unitPriceCents`, `totalCents` (always `unitPriceCents × quantity`). An option whose stated price does not divide by its count arrives as two rows of the same name (the floor, then one unit carrying the remainder), so the counts still sum to the stated count. Present only when there is at least one; then `unitPriceCents` is the item ALONE | `items[].options[]` (`name`, `externalCode`, `groupName`, `quantity`, `unitPrice`, `price`) | absent: Open Delivery (99Food, Keeta) and Rappi keep folding option prices into `unitPriceCents` and option names into `note`, as on `main` |
|
|
648
|
+
| `normalizedLineTotalCents(line)` | what a line costs: `unitPriceCents × quantity + Σ options[].totalCents`. Σ over the lines is the items' subtotal | iFood's `totalPrice` (`price + optionsPrice`) | equals `unitPriceCents × quantity` (no options) |
|
|
649
|
+
| `ResolvedOrderLine.options?` | the same options, handed to `order.create` with the resolved lines | — | absent |
|
|
650
|
+
| `NormalizedBuyer.document?` | the CPF or CNPJ for the invoice, digits only | `customer.documentNumber`, else `customer.document` | Open Delivery's `customer.documentNumber` |
|
|
651
|
+
| `NormalizedBuyer.phoneLocalizer?` | the extension that reaches the buyer through the marketplace's masked number | `customer.phone.localizer` | absent |
|
|
652
|
+
| `MarketplaceOrderType` gains `DINE_IN` and `INDOOR` | eaten at the store; ordered from inside it (a table) | `orderType` | unchanged (Open Delivery's `INDOOR` still reads null) |
|
|
653
|
+
| `NormalizedMarketplaceOrder.payments?: NormalizedPayments` | `prepaidCents`, `pendingCents`, `methods[]`: `method` (`CREDIT`, `DEBIT`, `MEAL_VOUCHER`, `FOOD_VOUCHER`, `PIX`, `CASH`, `DIGITAL_WALLET`, else `OTHER`), `statedMethod` (verbatim), `prepaid` (true online, false at the door, null unstated), `valueCents`, `cardBrand`, `changeForCents` (cash: the note the buyer pays with) | `payments.prepaid`, `payments.pending`, `payments.methods[]` (`method`, `type` ONLINE/OFFLINE, else `prepaid`, `value`, `card.brand`, `cash.changeFor`) | absent |
|
|
654
|
+
| `NormalizedMarketplaceOrder.additionalFees?: NormalizedOrderFee[]` | fees besides delivery, inside `totalCents`: `kind` (verbatim), `cents`, `name?` | top-level `additionalFees[]` (`type`, `value`, `description`) | absent |
|
|
655
|
+
|
|
656
|
+
Every new field is optional, and an unstated one is ABSENT (not null): a
|
|
657
|
+
payload that states none of these parts normalizes deep-equal to what `main`
|
|
658
|
+
produced. A payload that states them does not, and a host that deep-compares
|
|
659
|
+
normalized orders sees each of these:
|
|
660
|
+
|
|
661
|
+
- an iFood line with `options[]` gains `options`;
|
|
662
|
+
- an iFood order gains `payments` when it states `payments` (every real order
|
|
663
|
+
does), and `additionalFees` when it states `additionalFees[]`;
|
|
664
|
+
- an iFood buyer gains `document` (`customer.documentNumber` or `document`)
|
|
665
|
+
and `phoneLocalizer` (`customer.phone.localizer`);
|
|
666
|
+
- an iFood `orderType` of `DINE_IN` or `INDOOR` reads as that value, where
|
|
667
|
+
`main` read null;
|
|
668
|
+
- an Open Delivery buyer (99Food, Keeta) gains `document` when the order
|
|
669
|
+
states `customer.documentNumber`.
|
|
670
|
+
|
|
671
|
+
### 13.2 The cases
|
|
672
|
+
|
|
673
|
+
| id | order | `main` | this release |
|
|
674
|
+
|---|---|---|---|
|
|
675
|
+
| O1 | a pizza with "Borda recheada" R$ 8, "Bacon extra" 2 × R$ 2, "Sem cebola" R$ 0 | options dropped | each option on the line, a free one included (the kitchen reads it) |
|
|
676
|
+
| O2 | the same order | lines sum R$ 57 against a subtotal of R$ 69 | Σ `normalizedLineTotalCents` = `subtotalCents`, and subtotal + delivery fee = total |
|
|
677
|
+
| O3 | no `total` stated | total = Σ unit × quantity, options lost | total = Σ line totals, options included |
|
|
678
|
+
| O4 | an option whose `price` is not `unitPrice × quantity` (3 × Borda at R$ 10.00) | — | the stated `price` is the total, split over the stated count: 2 × 3.33 + 1 × 3.34, still 3 × Borda; one row at `price / quantity` when it divides (O4b) |
|
|
679
|
+
| O6 | 2 × Pizza, each with a Borda (option `quantity: 2`, `price: 16`) | options dropped, line R$ 90 against a `totalPrice` of R$ 106 | line R$ 90 + 2 × Borda R$ 16 = R$ 106; the lines add up to the subtotal |
|
|
680
|
+
| O5 | the order ingested | — | `order.create` receives the options on the resolved lines; a line with none carries no key |
|
|
681
|
+
| P1 | online credit card | dropped | `CREDIT`, prepaid, brand, value |
|
|
682
|
+
| P2 | cash at the door with change for R$ 100 | dropped | `CASH`, not prepaid, `changeForCents: 10000`, `pendingCents` the whole total |
|
|
683
|
+
| P3 | debit at the door, a gift card online | dropped | `DEBIT` not prepaid with its brand; `OTHER` with `statedMethod: "GIFT_CARD"` |
|
|
684
|
+
| P4 | any stated payment | — | Σ `methods[].valueCents` = `totalCents` = prepaid + pending, as iFood states them |
|
|
685
|
+
| F1 | a small-order fee R$ 2.99 | dropped (inside the total, nowhere else) | `additionalFees: [{ kind: "SMALL_ORDER_FEE", cents: 299, name }]`; lines + delivery fee + fees = total |
|
|
686
|
+
| B1/B2 | a CPF as `documentNumber`, a CNPJ as `document` | dropped | `buyer.document`, digits only; the phone's localizer in `buyer.phoneLocalizer` |
|
|
687
|
+
| T1/T2 | `INDOOR`, `DINE_IN` | `orderType: null` | `orderType: "INDOOR"` / `"DINE_IN"`, no deliverer, no address |
|
|
688
|
+
|
|
689
|
+
### 13.3 What is still ESTIMATED
|
|
690
|
+
|
|
691
|
+
- iFood's option `quantity`: read as the count for the whole line. The money
|
|
692
|
+
is right either way (the option's stated `price` is used), but if iFood's
|
|
693
|
+
count is per unit of the item, a line of 2 shows "1 × Borda" where the
|
|
694
|
+
kitchen makes two. Test O6 pins the whole-line reading. Confirming it on a
|
|
695
|
+
real order with an item quantity above 1 is a gate of the HOST bump (its
|
|
696
|
+
step 1 puts the count on the kitchen ticket), not of this release.
|
|
697
|
+
- An option's nested `customizations[]` (a sub-choice inside an option) are
|
|
698
|
+
not read: their price is assumed inside the option's `price`.
|
|
699
|
+
- An item stating `optionsPrice` with no `options[]` listed keeps only its
|
|
700
|
+
`unitPrice × quantity`; the stated order total is unaffected.
|
|
701
|
+
- `additionalFees[].liabilities` (who keeps the fee) is not read.
|
|
702
|
+
- A tax id stated as a NUMBER lost its leading zeros on the wire; it is padded
|
|
703
|
+
back to 11 digits (CPF), or 14 (CNPJ) when longer (test B4). A CNPJ sent as
|
|
704
|
+
a number with three or more leading zeros has 11 digits or fewer and reads
|
|
705
|
+
as a CPF; a bare number cannot tell the two apart. Both providers document
|
|
706
|
+
the field as a string.
|
|
707
|
+
|
|
708
|
+
### 13.4 What the host binds on the bump
|
|
709
|
+
|
|
710
|
+
The engine adds no table and no migration: everything travels on the order and
|
|
711
|
+
lines `order.create` already receives. Where a host keeps it is the host's
|
|
712
|
+
call; for a host with a line-extras model and a door-payment model (the origin
|
|
713
|
+
host), the mapping is:
|
|
714
|
+
|
|
715
|
+
1. **Options → the line's extras.** For each `options[]` entry write one extra
|
|
716
|
+
row (an option split in two rows, O4, is two extras of the same name) (name snapshot = `name`, unit price = `unitPriceCents`,
|
|
717
|
+
quantity = `quantity`, no catalogue id): every reader that already shows a
|
|
718
|
+
storefront line's extras (the order board card, the kitchen ticket, the
|
|
719
|
+
fiscal and till sums: `unit × quantity + Σ extra unit × extra quantity`)
|
|
720
|
+
then shows and sums them unchanged. Keep the line's own unit price as
|
|
721
|
+
`unitPriceCents` (the item alone). A host that ignores `options` keeps
|
|
722
|
+
`main`'s behaviour, lines short by the options' price.
|
|
723
|
+
2. **The buyer's document** goes where the host keeps a buyer tax id for the
|
|
724
|
+
invoice (encrypted at rest like any CPF), never in a log.
|
|
725
|
+
3. **Payment.** `payments.pendingCents > 0` is money the store's courier or
|
|
726
|
+
counter still collects: draw the pedido's payment line from the pending
|
|
727
|
+
method (`CASH` with `changeForCents` reads as cash with change for that
|
|
728
|
+
amount, the vocabulary a door payment already has; `CREDIT`, `DEBIT`,
|
|
729
|
+
`PIX`, `MEAL_VOUCHER`, `FOOD_VOUCHER` map one to one; `DIGITAL_WALLET` and
|
|
730
|
+
`OTHER` read as the marketplace's own word). Whether such a pedido is
|
|
731
|
+
still born PAID is the host's decision; a prepaid order (`pendingCents`
|
|
732
|
+
0) reads "Pago no <marketplace>" with the method and brand.
|
|
733
|
+
4. **Additional fees** are inside `totalCents` already. A host whose order-fee
|
|
734
|
+
table has a closed kind list widens it (an additive CHECK change, a host
|
|
735
|
+
migration) or shows them from the order's own record; summing them again
|
|
736
|
+
would charge them twice.
|
|
737
|
+
5. **Order type.** `DINE_IN` / `INDOOR` are not deliveries: route them like a
|
|
738
|
+
counter or table order (no delivery run, no address), never by the
|
|
739
|
+
`deliveredBy` fallback that treats an unknown type as a delivery.
|
|
740
|
+
6. **TypeScript-visible additions** (a minor): the optional fields above;
|
|
741
|
+
`MarketplaceOrderType` widens (an exhaustive switch adds two cases); new
|
|
742
|
+
exports `normalizedLineTotalCents`, `NormalizedLineOption`,
|
|
743
|
+
`NormalizedPayments`, `NormalizedPaymentMethod`, `MarketplacePaymentMethod`,
|
|
744
|
+
`NormalizedOrderFee`.
|
package/README.md
CHANGED
|
@@ -236,6 +236,31 @@ yet served). Webhook only: the software is one centralized iFood app, so the
|
|
|
236
236
|
adapter does not poll iFood's events (FUT-5798). Tests never reach
|
|
237
237
|
iFood: the HTTP client is the host's port.
|
|
238
238
|
|
|
239
|
+
## iFood homologation conformity (FUT-5984, FUT-5653, FUT-5673)
|
|
240
|
+
|
|
241
|
+
What iFood's Order and Events homologation checks, and what the engine does
|
|
242
|
+
for it (contract, cases and host steps: [ADOPTING.md §12](./ADOPTING.md#12-ifood-homologation-conformity-fut-5984-fut-5653-fut-5673)):
|
|
243
|
+
|
|
244
|
+
- a recorded delivery is answered `202 Accepted`; the presence heartbeat
|
|
245
|
+
(`KEEPALIVE`) is answered 202 with no statement, proved by the app's key;
|
|
246
|
+
- every recorded event is acknowledged (`events/acknowledgment`) by the
|
|
247
|
+
`marketplace.acknowledge` job, batched per store;
|
|
248
|
+
- each order's own cancellation reasons are read once
|
|
249
|
+
(`GET /orders/{id}/cancellationReasons`) by the
|
|
250
|
+
`marketplace.cancellation-reasons` job; the static list is the fallback; a
|
|
251
|
+
request sends `{ "reason": "<code>" }`;
|
|
252
|
+
- a merchant bag is made ready (`readyToPickup`) before it is dispatched, and
|
|
253
|
+
no step is told before the marketplace took the store's confirm;
|
|
254
|
+
- a token is renewed only once expired (or on a 401, once, in the same call);
|
|
255
|
+
- an order accepted on iFood's own app (CFM) is accepted here through the
|
|
256
|
+
host's admit, with no confirm sent back, and is never expired.
|
|
257
|
+
|
|
258
|
+
Type-level additions a TypeScript host meets on this bump (a minor):
|
|
259
|
+
`DeliveryOutcome` gains `confirmedByMarketplace`;
|
|
260
|
+
`MarketplaceOrderState.cancellationReasons` is a new required field;
|
|
261
|
+
`MarketplaceDb.marketplaceInboxEvent.updateMany` is a new required member.
|
|
262
|
+
Ship the migration `20261202120000_marketplace_ifood_conformity` with it.
|
|
263
|
+
|
|
239
264
|
## Linking a store through the software's own app (FUT-5613)
|
|
240
265
|
|
|
241
266
|
A store connects iFood WITHOUT typing a client id, a secret, a webhook key or a
|
|
@@ -564,8 +589,8 @@ after 10 minutes and failed after 24 hours.
|
|
|
564
589
|
|
|
565
590
|
| step | iFood (ESTIMATED) | 99Food (Open Delivery v1.7.1) | Keeta | Rappi |
|
|
566
591
|
|---|---|---|---|---|
|
|
567
|
-
| READY | `POST /orders/{id}/readyToPickup`,
|
|
568
|
-
| DISPATCHED | `POST /orders/{id}/dispatch`, merchant bag only | `POST /v1/orders/{id}/dispatch`, merchant bag only | `POST /v1/orders/{id}/dispatch`, merchant bag only | none |
|
|
592
|
+
| READY | `POST /orders/{id}/readyToPickup`, every bag (CONFIRMED, FUT-5984) | `POST /v1/orders/{id}/readyForPickup` | `POST /v1/orders/{id}/readyForPickup` | `POST /orders/{id}/ready-for-pickup` (ESTIMATED verb; MANUAL-notification stores only) |
|
|
593
|
+
| DISPATCHED | `POST /orders/{id}/dispatch`, merchant bag only, strictly after its READY | `POST /v1/orders/{id}/dispatch`, merchant bag only | `POST /v1/orders/{id}/dispatch`, merchant bag only | none |
|
|
569
594
|
| HANDED_OVER | none | merchant bag `delivered`, take-out `pickedUp`, fleet none | merchant bag `delivered`; no take-out (`PICKED_UP` is never sent), fleet none | none |
|
|
570
595
|
|
|
571
596
|
Sources: Open Delivery `openapi.yaml` (read 2026-11-25), Rappi's portal
|
package/dist/99food/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, C as CatalogueMenuEntry, b as CatalogueMenuOptions, P as PullCatalogue, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-
|
|
2
|
-
import { O as OpenDeliveryApiBaseUrls } from '../client-
|
|
1
|
+
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, C as CatalogueMenuEntry, b as CatalogueMenuOptions, P as PullCatalogue, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-CjVdMhZ2.js';
|
|
2
|
+
import { O as OpenDeliveryApiBaseUrls } from '../client-DgzCkl8u.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The words the 99Food adapter needs from its host, and nothing else.
|
package/dist/99food/index.js
CHANGED
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
openDeliveryStatus,
|
|
13
13
|
openDeliverySwitchAvailability,
|
|
14
14
|
verifyOpenDeliverySignature
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-TRUK5ZBE.js";
|
|
16
16
|
import "../chunk-M2V4RFMA.js";
|
|
17
|
-
import "../chunk-
|
|
18
|
-
import "../chunk-
|
|
17
|
+
import "../chunk-E4XJXHUK.js";
|
|
18
|
+
import "../chunk-BTKVZAJI.js";
|
|
19
19
|
import {
|
|
20
20
|
__name
|
|
21
21
|
} from "../chunk-7QVYU63E.js";
|
|
@@ -199,13 +199,53 @@ interface NormalizedOrderLine {
|
|
|
199
199
|
unitPriceCents: number;
|
|
200
200
|
/** The buyer's note on this line, when they left one. */
|
|
201
201
|
note: string | null;
|
|
202
|
+
/**
|
|
203
|
+
* OPTIONAL (FUT-5803). The options the buyer chose on this line (a
|
|
204
|
+
* complemento: "borda recheada", "sem cebola"), each priced on its own. When
|
|
205
|
+
* present, `unitPriceCents` is the item ALONE and the line costs
|
|
206
|
+
* `unitPriceCents × quantity + Σ options[].totalCents`
|
|
207
|
+
* ({@link normalizedLineTotalCents}). Absent: none is itemized. Open
|
|
208
|
+
* Delivery and Rappi then fold the options' price into `unitPriceCents`;
|
|
209
|
+
* iFood does not, so an iFood item that states `optionsPrice` but lists no
|
|
210
|
+
* `options[]` is priced as the item alone. Never an empty array.
|
|
211
|
+
*/
|
|
212
|
+
options?: NormalizedLineOption[];
|
|
213
|
+
}
|
|
214
|
+
/** One option on an order line, as the marketplace priced it (FUT-5803). */
|
|
215
|
+
interface NormalizedLineOption {
|
|
216
|
+
/** The marketplace's own code for the option, when it gives one. */
|
|
217
|
+
externalCode: string | null;
|
|
218
|
+
name: string;
|
|
219
|
+
/** The group the marketplace shows it under ("Borda", "Adicionais"), when it says. */
|
|
220
|
+
groupName: string | null;
|
|
221
|
+
/** How many, for the WHOLE line (never per unit of it). */
|
|
222
|
+
quantity: number;
|
|
223
|
+
unitPriceCents: number;
|
|
224
|
+
/**
|
|
225
|
+
* Always exactly `unitPriceCents × quantity`. A stated price that does not
|
|
226
|
+
* divide by its count arrives as two rows of the same option (the floor,
|
|
227
|
+
* then one unit carrying the remainder), whose counts sum to the stated one.
|
|
228
|
+
*/
|
|
229
|
+
totalCents: number;
|
|
202
230
|
}
|
|
231
|
+
/** What a line costs: the item times its quantity, plus each of its options. */
|
|
232
|
+
declare function normalizedLineTotalCents(line: Pick<NormalizedOrderLine, "unitPriceCents" | "quantity" | "options">): number;
|
|
203
233
|
/** The buyer, as much of them as the marketplace discloses. */
|
|
204
234
|
interface NormalizedBuyer {
|
|
205
235
|
/** The marketplace's own stable id for this customer, when it gives one. */
|
|
206
236
|
externalId: string | null;
|
|
207
237
|
name: string | null;
|
|
208
238
|
phone: string | null;
|
|
239
|
+
/**
|
|
240
|
+
* OPTIONAL (FUT-5803). The buyer's tax id for the invoice (a CPF or a CNPJ),
|
|
241
|
+
* digits only. Absent: the marketplace states none.
|
|
242
|
+
*/
|
|
243
|
+
document?: string | null;
|
|
244
|
+
/**
|
|
245
|
+
* OPTIONAL (FUT-5803). The extension that reaches the buyer through the
|
|
246
|
+
* marketplace's masked number in `phone` (iFood's `phone.localizer`). Absent: none.
|
|
247
|
+
*/
|
|
248
|
+
phoneLocalizer?: string | null;
|
|
209
249
|
}
|
|
210
250
|
/** Where a delivery goes, as much of it as the marketplace states. */
|
|
211
251
|
interface NormalizedAddress {
|
|
@@ -219,8 +259,12 @@ interface NormalizedAddress {
|
|
|
219
259
|
city: string | null;
|
|
220
260
|
state: string | null;
|
|
221
261
|
}
|
|
222
|
-
/**
|
|
223
|
-
|
|
262
|
+
/**
|
|
263
|
+
* How the order reaches the buyer: brought to the door (`DELIVERY`), collected
|
|
264
|
+
* (`TAKEOUT`), eaten at the store (`DINE_IN`), or ordered from inside it, at a
|
|
265
|
+
* table or a spot the buyer names (`INDOOR`, FUT-5803).
|
|
266
|
+
*/
|
|
267
|
+
type MarketplaceOrderType = "DELIVERY" | "TAKEOUT" | "DINE_IN" | "INDOOR";
|
|
224
268
|
/** WHO carries a delivery: the merchant's own courier, or the marketplace's fleet. */
|
|
225
269
|
type MarketplaceDeliveredBy = "MERCHANT" | "MARKETPLACE";
|
|
226
270
|
/** WHO pays for a discount: the store, the marketplace's own campaign, or someone else (a card issuer, a voucher). */
|
|
@@ -233,6 +277,44 @@ interface NormalizedOrderDiscount {
|
|
|
233
277
|
/** What the marketplace called the campaign, when it says. */
|
|
234
278
|
name?: string;
|
|
235
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* How a buyer paid, as a closed set a host has words for. `OTHER`: stated,
|
|
282
|
+
* and none of these (the marketplace's own word is in `statedMethod`).
|
|
283
|
+
*/
|
|
284
|
+
type MarketplacePaymentMethod = "CREDIT" | "DEBIT" | "MEAL_VOUCHER" | "FOOD_VOUCHER" | "PIX" | "CASH" | "DIGITAL_WALLET" | "OTHER";
|
|
285
|
+
/** One way the buyer pays an order (FUT-5803). */
|
|
286
|
+
interface NormalizedPaymentMethod {
|
|
287
|
+
method: MarketplacePaymentMethod;
|
|
288
|
+
/** The marketplace's own word for the method, verbatim; null when it states none. */
|
|
289
|
+
statedMethod: string | null;
|
|
290
|
+
/**
|
|
291
|
+
* True: already paid on the marketplace. False: to collect from the buyer at
|
|
292
|
+
* the door or the counter. Null: unstated.
|
|
293
|
+
*/
|
|
294
|
+
prepaid: boolean | null;
|
|
295
|
+
/** What this method pays, in the smallest currency unit. */
|
|
296
|
+
valueCents: number;
|
|
297
|
+
/** The card's brand as the marketplace names it ("VISA"), when it does. */
|
|
298
|
+
cardBrand: string | null;
|
|
299
|
+
/** On cash: the note the buyer pays with, so the courier brings the change. Null: no change asked, or unstated. */
|
|
300
|
+
changeForCents: number | null;
|
|
301
|
+
}
|
|
302
|
+
/** The order's payment, as the marketplace states it (FUT-5803). */
|
|
303
|
+
interface NormalizedPayments {
|
|
304
|
+
/** What the marketplace already collected. Null: unstated. */
|
|
305
|
+
prepaidCents: number | null;
|
|
306
|
+
/** What is still to collect from the buyer. Null: unstated. */
|
|
307
|
+
pendingCents: number | null;
|
|
308
|
+
methods: NormalizedPaymentMethod[];
|
|
309
|
+
}
|
|
310
|
+
/** A fee the marketplace charged the buyer besides delivery (FUT-5803), such as a small-order fee. */
|
|
311
|
+
interface NormalizedOrderFee {
|
|
312
|
+
/** The marketplace's own kind, verbatim (`SMALL_ORDER_FEE`). */
|
|
313
|
+
kind: string;
|
|
314
|
+
cents: number;
|
|
315
|
+
/** What the marketplace called it, when it says. */
|
|
316
|
+
name?: string;
|
|
317
|
+
}
|
|
236
318
|
/** An incoming marketplace order, normalized. */
|
|
237
319
|
interface NormalizedMarketplaceOrder {
|
|
238
320
|
provider: MarketplaceProvider;
|
|
@@ -287,6 +369,17 @@ interface NormalizedMarketplaceOrder {
|
|
|
287
369
|
* the bag itself).
|
|
288
370
|
*/
|
|
289
371
|
pickupCode?: string | null;
|
|
372
|
+
/**
|
|
373
|
+
* OPTIONAL (FUT-5803). How the buyer pays: each method, what is prepaid and
|
|
374
|
+
* what is still to collect, and the change a cash buyer asks for. Absent:
|
|
375
|
+
* the marketplace states none.
|
|
376
|
+
*/
|
|
377
|
+
payments?: NormalizedPayments;
|
|
378
|
+
/**
|
|
379
|
+
* OPTIONAL (FUT-5803). The fees besides delivery, inside `totalCents`.
|
|
380
|
+
* Absent is "did not say"; an empty array is "none".
|
|
381
|
+
*/
|
|
382
|
+
additionalFees?: NormalizedOrderFee[];
|
|
290
383
|
}
|
|
291
384
|
/**
|
|
292
385
|
* What an event says about the STORE's own cancellation request: `CONFIRMED`
|
|
@@ -372,6 +465,12 @@ interface NormalizedEvent {
|
|
|
372
465
|
* names no courier step.
|
|
373
466
|
*/
|
|
374
467
|
courier?: NormalizedCourierEvent | null;
|
|
468
|
+
/**
|
|
469
|
+
* OPTIONAL (FUT-5653). The store accepted the order in the marketplace's own
|
|
470
|
+
* app (iFood's `CFM`): an order still AWAITING here is accepted through the
|
|
471
|
+
* host's admit, with no confirm sent back. Carries no order body.
|
|
472
|
+
*/
|
|
473
|
+
marketplaceConfirmed?: boolean;
|
|
375
474
|
}
|
|
376
475
|
|
|
377
476
|
/**
|
|
@@ -918,7 +1017,53 @@ interface MarketplaceCapabilities {
|
|
|
918
1017
|
* Absent or empty: the engine tells it nothing.
|
|
919
1018
|
*/
|
|
920
1019
|
statusSteps?: readonly StatusStep[];
|
|
1020
|
+
/**
|
|
1021
|
+
* OPTIONAL. The HTTP status a recorded delivery is answered with (FUT-5984:
|
|
1022
|
+
* iFood wants `202 Accepted`). Absent: 200. Refusals and failures keep theirs.
|
|
1023
|
+
*/
|
|
1024
|
+
webhookAnswerStatus?: 200 | 202;
|
|
1025
|
+
/**
|
|
1026
|
+
* OPTIONAL. The marketplace announces that the store accepted an order in the
|
|
1027
|
+
* marketplace's own app (`NormalizedEvent.marketplaceConfirmed`, FUT-5653).
|
|
1028
|
+
* Its ingest then applies a confirmation that arrived before the order.
|
|
1029
|
+
*/
|
|
1030
|
+
marketplaceConfirms?: boolean;
|
|
1031
|
+
/**
|
|
1032
|
+
* OPTIONAL. A status step is told only after the marketplace took the
|
|
1033
|
+
* store's confirm (`confirmedAt`, FUT-5673: iFood refuses a step of an order
|
|
1034
|
+
* it has not confirmed). Absent: steps never wait on the confirm.
|
|
1035
|
+
*/
|
|
1036
|
+
statusAfterConfirm?: boolean;
|
|
921
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* A marketplace's presence heartbeat (FUT-5984: iFood's `KEEPALIVE`), read off
|
|
1040
|
+
* a delivery: `merchantIds` when it asks about named merchants (its
|
|
1041
|
+
* per-merchant mode), null when it asks about the whole app.
|
|
1042
|
+
*/
|
|
1043
|
+
interface PresenceProbe {
|
|
1044
|
+
merchantIds: readonly string[] | null;
|
|
1045
|
+
}
|
|
1046
|
+
/** Acknowledging recorded events to the marketplace (FUT-5984: iFood's `events/acknowledgment`). */
|
|
1047
|
+
interface MarketplaceAcknowledgement {
|
|
1048
|
+
/** At most this many event ids per call. */
|
|
1049
|
+
batchSize: number;
|
|
1050
|
+
/** How long the marketplace keeps an event: an older one is never acknowledged. */
|
|
1051
|
+
retentionMs: number;
|
|
1052
|
+
/** Acknowledge these event ids, in one call. */
|
|
1053
|
+
send(ctx: AdapterCallContext, eventIds: readonly string[]): Promise<OutboundResult>;
|
|
1054
|
+
}
|
|
1055
|
+
/** One cancellation reason the marketplace lists for one order: its code and its own words. */
|
|
1056
|
+
interface OrderCancellationReason {
|
|
1057
|
+
code: string;
|
|
1058
|
+
description: string;
|
|
1059
|
+
}
|
|
1060
|
+
/** One order's reasons read from the marketplace, or the refusal / retry of the read. */
|
|
1061
|
+
type OrderCancellationReasonsResult = {
|
|
1062
|
+
kind: "reasons";
|
|
1063
|
+
reasons: OrderCancellationReason[];
|
|
1064
|
+
} | Exclude<OutboundResult, {
|
|
1065
|
+
kind: "accepted";
|
|
1066
|
+
}>;
|
|
922
1067
|
/**
|
|
923
1068
|
* A step of the order the store tells the marketplace about (FUT-4653): the
|
|
924
1069
|
* order is ready for pickup, the courier left, the order was handed over.
|
|
@@ -1031,7 +1176,11 @@ interface MarketplaceAdapter {
|
|
|
1031
1176
|
readSignature(header: (name: string) => string | null): string | null;
|
|
1032
1177
|
/** Is this delivery's signature the one this store's secret would produce? */
|
|
1033
1178
|
verifySignature(rawBody: string, signature: string | null, secret: string | null): boolean;
|
|
1034
|
-
/**
|
|
1179
|
+
/**
|
|
1180
|
+
* The marketplace's documented reasons, static and offline: a dialog never
|
|
1181
|
+
* waits on the network. With `orderCancellationReasons`, the fallback of an
|
|
1182
|
+
* order whose own list could not be read.
|
|
1183
|
+
*/
|
|
1035
1184
|
cancellationReasons(): readonly CancellationReason[];
|
|
1036
1185
|
/** Tell the marketplace the store accepted the order. */
|
|
1037
1186
|
confirm(ctx: AdapterCallContext, order: OutboundOrderRef, input: {
|
|
@@ -1055,6 +1204,30 @@ interface MarketplaceAdapter {
|
|
|
1055
1204
|
informStatus?(ctx: AdapterCallContext, order: OutboundOrderRef, facts: StatusFacts): Promise<OutboundResult | {
|
|
1056
1205
|
kind: "unsupported";
|
|
1057
1206
|
}>;
|
|
1207
|
+
/**
|
|
1208
|
+
* OPTIONAL. The step that must be told before this one for this kind of
|
|
1209
|
+
* order (FUT-5984: iFood's dispatch of a merchant bag follows its
|
|
1210
|
+
* `readyToPickup`), or null. The status job sends it first when it is not
|
|
1211
|
+
* told yet.
|
|
1212
|
+
*/
|
|
1213
|
+
statusPrerequisite?(facts: StatusFacts): StatusStep | null;
|
|
1214
|
+
/**
|
|
1215
|
+
* OPTIONAL. A delivery that is the marketplace's presence heartbeat, not an
|
|
1216
|
+
* event (FUT-5984: iFood's `KEEPALIVE`), or null. Answered 202 once its
|
|
1217
|
+
* signature is proved, with nothing recorded.
|
|
1218
|
+
*/
|
|
1219
|
+
presence?(payload: unknown): PresenceProbe | null;
|
|
1220
|
+
/** OPTIONAL. Acknowledging recorded events (FUT-5984). Absent: nothing is acknowledged. */
|
|
1221
|
+
readonly acknowledgement?: MarketplaceAcknowledgement;
|
|
1222
|
+
/**
|
|
1223
|
+
* OPTIONAL. Read the reasons the marketplace accepts for cancelling THIS
|
|
1224
|
+
* order (FUT-5984: iFood's `GET /orders/{id}/cancellationReasons`). Called
|
|
1225
|
+
* only from the `marketplace.cancellation-reasons` job. Absent: the static
|
|
1226
|
+
* `cancellationReasons()` are every order's.
|
|
1227
|
+
*/
|
|
1228
|
+
orderCancellationReasons?(ctx: AdapterCallContext, order: {
|
|
1229
|
+
externalOrderId: string;
|
|
1230
|
+
}): Promise<OrderCancellationReasonsResult>;
|
|
1058
1231
|
/**
|
|
1059
1232
|
* OPTIONAL. Fetch the order an event announced with `orderToFetch` (a
|
|
1060
1233
|
* marketplace whose events carry no order body). Called only from the
|
|
@@ -1113,4 +1286,4 @@ declare function tokenGrantResultOf(response: MarketplaceHttpResponse): Outbound
|
|
|
1113
1286
|
/** A call that never got an answer is a retry, with the reason a log can read. */
|
|
1114
1287
|
declare function answered(call: () => Promise<OutboundResult>): Promise<OutboundResult>;
|
|
1115
1288
|
|
|
1116
|
-
export { type
|
|
1289
|
+
export { type MarketplaceCapabilities as $, type AdapterCallContext as A, type CatalogueReadResult as B, type CatalogueMenuEntry as C, type CatalogueReadWarning as D, type CatalogueReadWarningCode as E, type FetchOrderResult as F, type CatalogueSnapshot as G, type CatalogueSnapshotCategory as H, type CatalogueSnapshotItem as I, type CatalogueSnapshotOption as J, type CatalogueSnapshotOptionGroup as K, type CatalogueStoredImage as L, type MarketplaceAvailability as M, type NormalizedEvent as N, type OutboundResult as O, type PullCatalogue as P, type CatalogueWarningCode as Q, type CourierTrackingCallResult as R, type StorePauseRequest as S, type CourierTrackingResult as T, type LinkCallContext as U, type LinkCode as V, type LinkGrant as W, type LinkResult as X, type LinkedMerchant as Y, type MarketplaceAcknowledgement as Z, type MarketplaceAppCredentialsPort as _, type NormalizedMarketplaceOrder as a, type MarketplaceCatalogue as a0, type MarketplaceCourier as a1, type MarketplaceCourierAnswer as a2, type MarketplaceCourierEngine as a3, type MarketplaceCourierFacts as a4, type MarketplaceCourierStep as a5, type MarketplaceCourierTracking as a6, type MarketplaceCourierVehicle as a7, type MarketplaceCredentials as a8, type MarketplaceDeliveredBy as a9, answered as aA, centsFromMajor as aB, normalizedLineTotalCents as aC, outboundResultOf as aD, tokenGrantResultOf as aE, type MarketplaceDiscountSponsor as aa, type MarketplaceHttp as ab, type MarketplaceHttpRequest as ac, type MarketplaceHttpResponse as ad, type MarketplaceLifecycle as ae, type MarketplaceLinkAttemptDelegate as af, type MarketplaceOrderType as ag, type MarketplacePaymentMethod as ah, type NormalizedAddress as ai, type NormalizedBuyer as aj, type NormalizedLineOption as ak, type NormalizedOrderDiscount as al, type NormalizedOrderFee as am, type NormalizedOrderLine as an, type NormalizedPaymentMethod as ao, type NormalizedPayments as ap, type OrderCancellationReason as aq, type OrderCancellationReasonsResult as ar, type OutboundOrderRef as as, PROVIDER_ID_PATTERN as at, type PickupCodeCallResult as au, type PickupCodeValidation as av, type PresenceProbe as aw, type StatusFacts as ax, type StatusStep as ay, type ValidatePickupCodeInput as az, type CatalogueMenuOptions as b, type MarketplaceAdapter as c, type PushCatalogue as d, type CatalogueItemOut as e, type CatalogueReader as f, type MarketplaceLinking as g, type MarketplaceCourierApi as h, type NormalizedCourierEvent as i, type StorePauseResult as j, type StorePauseRef as k, type MarketplaceProvider as l, type CancellationReason as m, type AdapterGrant as n, type AdapterTokenCache as o, type CancellationOutcome as p, type CancellationRequestInput as q, type CatalogueCallContext as r, type CatalogueFailure as s, type CatalogueImage as t, type CatalogueItem as u, type CatalogueItemRef as v, type CataloguePublishResult as w, type CatalogueReadContext as x, type CatalogueReadNotice as y, type CatalogueReadRefusalCode as z };
|