@12-apps/marketplace 1.11.0 → 1.13.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 +134 -1
- package/README.md +49 -3
- package/dist/99food/index.d.ts +2 -2
- package/dist/99food/index.js +2 -2
- package/dist/{adapter-CD0SfdVS.d.ts → adapter-CQ4QiZPi.d.ts} +327 -174
- package/dist/{chunk-TVZU4HNT.js → chunk-4J2KJ3ZW.js} +1 -1
- package/dist/{chunk-TVZU4HNT.js.map → chunk-4J2KJ3ZW.js.map} +1 -1
- package/dist/{chunk-YWMEIMO3.js → chunk-CEWTV2TC.js} +176 -40
- package/dist/chunk-CEWTV2TC.js.map +1 -0
- package/dist/{chunk-DCWOQ5PN.js → chunk-NFJQQWG4.js} +2 -2
- package/dist/{chunk-OS4TSIFU.js → chunk-W57TITU4.js} +2 -2
- package/dist/{client-11sncog4.d.ts → client-CCSnylou.d.ts} +1 -1
- package/dist/{engine-C_3RK8wC.d.ts → engine-1KlJ_8jK.d.ts} +34 -5
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +2 -2
- package/dist/ifood/index.d.ts +20 -2
- package/dist/ifood/index.js +349 -125
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +162 -65
- package/dist/index.js.map +1 -1
- package/dist/keeta/index.d.ts +2 -18
- package/dist/keeta/index.js +12 -3
- package/dist/keeta/index.js.map +1 -1
- package/dist/manifest/server.d.ts +2 -2
- package/dist/manifest/server.js +2 -2
- package/dist/rappi/index.d.ts +1 -1
- package/dist/rappi/index.js +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -2
- package/package.json +1 -1
- package/src/core/adapter.ts +8 -1
- package/src/core/connection-stamp.ts +61 -0
- package/src/core/courier-port.ts +100 -0
- package/src/core/courier.ts +153 -0
- package/src/core/engine.ts +4 -1
- package/src/core/fetch-order.ts +54 -12
- package/src/core/integration.ts +19 -4
- package/src/core/lifecycle.ts +27 -4
- package/src/core/outbound-queue.ts +24 -11
- package/src/core/outbound.ts +8 -6
- package/src/core/pickup-code.ts +136 -0
- package/src/core/pipeline.ts +15 -6
- package/src/core/ports.ts +23 -1
- package/src/core/status-store.ts +2 -3
- package/src/core/types.ts +56 -4
- package/src/ifood/courier.ts +210 -0
- package/src/ifood/fetch-order.ts +103 -0
- package/src/ifood/index.ts +9 -1
- package/src/ifood/normalize.ts +30 -3
- package/src/index.ts +16 -0
- package/src/keeta/normalize.ts +21 -6
- package/dist/chunk-YWMEIMO3.js.map +0 -1
- /package/dist/{chunk-DCWOQ5PN.js.map → chunk-NFJQQWG4.js.map} +0 -0
- /package/dist/{chunk-OS4TSIFU.js.map → chunk-W57TITU4.js.map} +0 -0
package/ADOPTING.md
CHANGED
|
@@ -22,11 +22,13 @@ error at mount, never a default that quietly adopts another host's policy.
|
|
|
22
22
|
| `order.onRefused` | `(clientId, orderId, reason: "REJECTED" \| "EXPIRED" \| "CANCELLED") => Promise<void>` | Refuse/cancel the host order: the store refused on the clock, the clock lapsed, or the marketplace cancelled. After the commit and after the cancellation request is queued; a throw on a decision is logged. NOT called for `recordStoreCancellation`. A host that binds `onCancellationConfirmed` (request first) does not get `"REJECTED"` from `decide` either, nor `"CANCELLED"` for a cancellation the store asked for: `onCancellationConfirmed` replaces both. |
|
|
23
23
|
| `order.onCancellationConfirmed` | OPTIONAL — binding it OPTS IN to request first. `(clientId, orderId) => Promise<void>` | The marketplace CONFIRMED the store's own cancellation request (its event, or the job's answer for a marketplace that answers in the response); the row is REJECTED/CONFIRMED by then. Run the host's cancel here. Bound: the store's refusals and cancels (`decide` REJECT, `recordStoreCancellation`) only REQUEST the cancellation and keep the order as it was until this is called, once (a redelivered confirmation calls nothing), INSTEAD of `onRefused`. Not bound (a 1.0.0 host): everything as 1.0.0 — REJECTED at request time, `onRefused(…, "REJECTED")` from `decide`, and `onRefused(…, "CANCELLED")` on the confirmation. A throw is logged. |
|
|
24
24
|
| `order.onCancellationFailed` | OPTIONAL. `(clientId, orderId, reason: "REFUSED" \| "TIMEOUT") => Promise<void>` | The store's request FAILED: REFUSED (the marketplace's refusal event, the job's 4xx, its last attempt dying, or — request first — a marketplace whose API cannot take it, at once) or TIMEOUT (the outbound sweep, past the marketplace's answer window, or the 24-hour give-up). Called once, by the path that moved the row. Request first: the order stays as it was (AWAITING or ACCEPTED) and may be accepted again; show the adapter's app link and tell the person. A throw is logged. |
|
|
25
|
+
| `order.onCourier` | OPTIONAL (FUT-5665). `(clientId, orderId, event: NormalizedCourierEvent, facts: { deliveredBy; at }) => Promise<"recorded" \| "unchanged" \| { kind: "unchanged"; reason }>` | The marketplace's courier moved (assigned, on the way, at the counter, collected, returning, returned): store the facts on the order, never move it. Asked for an ACCEPTED order only; idempotent (the reconcile pass may re-run a row). Section 10. |
|
|
26
|
+
| `order.onPickupCodeValidated` | OPTIONAL (FUT-5665). `(clientId, orderId, validation: "VALID" \| "INVALID" \| "UNVERIFIED") => Promise<void>` | The marketplace's verdict on the code sent with `validatePickupCode`, after the hand-over committed. `INVALID` warns, moves nothing. A throw is logged. Section 10. |
|
|
25
27
|
| `order.summarize` | `(clientId, orderIds: readonly string[]) => Promise<Map<string, MarketplaceOrderSummary>>` | The queue's host facts in one read: `{ buyerName, totalCents, unmappedLines, createdAt }`. |
|
|
26
28
|
| `secrets` | `{ seal(plaintext): string; open(sealed): string }` | Seal and open the credential blob with the host's key. `open` THROWS on a blob that will not open. |
|
|
27
29
|
| `http` | `(req: MarketplaceHttpRequest) => Promise<MarketplaceHttpResponse>` | The only way the engine reaches a marketplace. Answer any status; throw only when no answer arrived (timeout, network). The host owns the timeout, proxy and CA. `method` is `GET`, `POST`, `PUT` or, since the catalogue (1.2), `PATCH`. |
|
|
28
30
|
| `audit` | `{ record(entry: { clientId; actorId: string \| null; action: "marketplace.integration.archive" \| "marketplace.integration.unarchive"; provider; reason: string \| null; at: Date }, db: MarketplaceDb): Promise<void> }` | Every archive and unarchive of a connection, INSIDE the same transaction: write the line through `db`, so an archive never lands without its line and a failing audit rolls the archive back. `actorId` is `MarketplaceActor.userId`. |
|
|
29
|
-
| `enqueue` | `{ enqueue(name, payload, { dedupeKey? }) => Promise<{ enqueued: boolean; reason?: string }> }` | The wiring `JobsEnqueuePort`. Never throws. The engine queues only its own three on-demand jobs: `marketplace.outbound` (`{ clientId, orderId, action }`, dedupe key `marketplace.outbound:<action>:<orderId
|
|
31
|
+
| `enqueue` | `{ enqueue(name, payload, { dedupeKey? }) => Promise<{ enqueued: boolean; reason?: string }> }` | The wiring `JobsEnqueuePort`. Never throws. The engine queues only its own three on-demand jobs: `marketplace.outbound` (`{ clientId, orderId, action }`, dedupe key `marketplace.outbound:<action>:<orderId>`; `validatePickupCode` adds `code`, the one non-identifier a payload carries, a short-lived code no log line prints, and keys on the hand-over's instant), `marketplace.fetch-order` (`{ clientId, inboxId }`, dedupe key `marketplace.fetch-order:<inboxId>`) and `marketplace.catalogue` (`{ clientId, publicationId, action }`, dedupe key `marketplace.catalogue:<action>:<publicationId>:<asked at, ms>`); the sweeps re-queue each under a key of their own. |
|
|
30
32
|
| `clock` | `{ now(): Date }` | What time it is. |
|
|
31
33
|
| `logger` | `{ info, warn, error }` | The wiring `LoggerPort`; bind `assembled.loggers["@12-apps/marketplace"]`. |
|
|
32
34
|
| `publishChanged` | `(clientId) => void` | Tell the staff surfaces something moved. Fire-and-forget. |
|
|
@@ -78,6 +80,8 @@ export const engine = createMarketplaceEngine({
|
|
|
78
80
|
| `catalogueState({ clientId, productIds, providers? })` | The product page's read: one row per marketplace the product was ever switched on for, in one query. Draw PUBLISHED as "in the catalogue" (with your sentence for a `warningCode`, IMAGE_TOO_LARGE or IMAGE_REFUSED: it went out without its photo), PUBLISHING / WITHDRAWING as "sending…" (switch disabled), FAILED with your own sentence for its `failureCode` (REFUSED, UNAVAILABLE, TIMEOUT, NOT_CONNECTED, CREDENTIALS, PRODUCT_GONE, UNSUPPORTED, INTERNAL), the marketplace's own words from `failureReason` beside a REFUSED, and a retry (`publish` or `withdraw` again, per `failedAction`). The engine writes no sentence a person reads. No row is OFF. |
|
|
79
81
|
| `catalogueDocument({ clientId, provider, options: { menuName, currency } })` | PULL marketplaces only (99Food): the menu part of the document the marketplace reads. Serve it from the route the marketplace pulls (Open Delivery's `GET /v1/merchant`), merged into the rest of that document, which is the host's (`id`, `status`, `lastUpdate`, `TTL`, `basicInfo`, `services`). The menu's name and the currency are the host's words. |
|
|
80
82
|
| `informStatus({ clientId, orderId, step, at, delayMs? })` | An order reached `READY`, `DISPATCHED` or `HANDED_OVER` (FUT-4653). One enqueue, no statement, never throws: call it after the move's commit, from the one place every writer of that step passes, gated on the order being a marketplace's. `at` is the move's own timestamp (it makes the job's dedupe key, so a re-dispatch after an undo is a new job); `delayMs` is the board's undo window for a dispatch. Your `enqueue` port must pass `options.delayMs` on. The job decides everything else (see the README). |
|
|
83
|
+
| `validatePickupCode({ clientId, orderId, code, at })` | After the host's own hand-over of a marketplace-courier bag committed, with the code the store checked locally (FUT-5665). One enqueue, never throws. Section 10. |
|
|
84
|
+
| `courierTracking({ clientId, orderId })` | From a job, at most once per 30 s per order (iFood's rate): where the marketplace's courier is (`pickupEtaAt`, the "arrives at" time). Calls the marketplace at once; never on a tap or a screen load. Section 10. |
|
|
81
85
|
| `ingest(...)`, `deliver(...)` | A producer that hands over an order directly; the webhook does `deliver` for you. |
|
|
82
86
|
|
|
83
87
|
A host never writes `provider === "IFOOD"`. A capability is asked of
|
|
@@ -354,3 +358,132 @@ software's own app"). What the host binds and decides:
|
|
|
354
358
|
`archive`): the row is kept; linking again unarchives it with its audit line.
|
|
355
359
|
- **A view** gains `authMode`; a host that switches on it treats an absent
|
|
356
360
|
value as `CREDENTIALS`.
|
|
361
|
+
|
|
362
|
+
## 10. The marketplace's own courier and the pickup code (FUT-5665)
|
|
363
|
+
|
|
364
|
+
When the marketplace's fleet carries a bag (`deliveredBy: "MARKETPLACE"`;
|
|
365
|
+
iFood's `delivery.deliveredBy = IFOOD`), the engine reports where its courier
|
|
366
|
+
is, carries the code the courier states at the counter, checks that code with
|
|
367
|
+
the marketplace after the hand-over, and reads the courier's tracking. All of
|
|
368
|
+
it is additive: every new port and field is optional, nothing below needs an
|
|
369
|
+
engine migration, and a host that binds none of the new hooks keeps its 1.x
|
|
370
|
+
behaviour, with one exception: a host that binds `onLifecycle` now receives
|
|
371
|
+
`lifecycle: "COLLECTED"` (iFood `CLT`, Keeta `ORDER_COLLECTED`, for a bag the
|
|
372
|
+
marketplace carries; before, IGNORED as `no order body`). A switch with a
|
|
373
|
+
default answers `unchanged`; an exhaustive switch must add the case, as for
|
|
374
|
+
`status` in FUT-4653.
|
|
375
|
+
|
|
376
|
+
**What the host binds.**
|
|
377
|
+
|
|
378
|
+
- `order.onCourier(clientId, orderId, event, facts)`: a courier event of an
|
|
379
|
+
ACCEPTED order (an event before its order is deferred and re-run by the
|
|
380
|
+
reconcile pass; another status is IGNORED). `event` is
|
|
381
|
+
`NormalizedCourierEvent`: `step` (`ASSIGNED`, `GOING_TO_ORIGIN`,
|
|
382
|
+
`ARRIVED_AT_ORIGIN`, `COLLECTED`, `RETURNING_TO_ORIGIN`,
|
|
383
|
+
`RETURNED_TO_ORIGIN`), `at` (the event's instant or null), `courier` (on
|
|
384
|
+
`ASSIGNED`: `{ name, photoUrl, vehicle }`, the photo an https URL or null,
|
|
385
|
+
the vehicle `MOTORCYCLE` / `BICYCLE` / `CAR` / `OTHER` or null) and
|
|
386
|
+
`returning` (`RETURNING`, `RETURNED` or null). `facts` is
|
|
387
|
+
`{ deliveredBy, at }`, `at` falling back to the engine's clock. Store what
|
|
388
|
+
the card shows (name, photo, vehicle, arrived at, collected at, returning)
|
|
389
|
+
on your own order and answer `"recorded"`; the engine settles the inbox row
|
|
390
|
+
PROCESSED and calls `publishChanged`. It is NOT gated on `followStatus`: a
|
|
391
|
+
fact moves nothing. Unbound: courier events stay IGNORED (`no order body on
|
|
392
|
+
ADR`).
|
|
393
|
+
- `order.onLifecycle` now also gets `lifecycle: "COLLECTED"` (iFood `CLT`,
|
|
394
|
+
Keeta `ORDER_COLLECTED`). For a fleet bag treat it as `DISPATCHED`: the
|
|
395
|
+
courier has the bag, so move it to handed over, forward only, with no code
|
|
396
|
+
asked. A `COLLECTED` of a bag the marketplace does not carry is IGNORED by
|
|
397
|
+
the engine, never noted and never sent to the host. The engine notes it as
|
|
398
|
+
the marketplace's HANDED_OVER, and treats a `COLLECTED` after your own informed HANDED_OVER as an echo. The courier's
|
|
399
|
+
facts reach `onCourier` first; when the lifecycle moves nothing the row is
|
|
400
|
+
settled by the courier's answer.
|
|
401
|
+
- `order.onPickupCodeValidated(clientId, orderId, validation)`: `VALID`,
|
|
402
|
+
`INVALID` (warn on the order; the hand-over stands) or `UNVERIFIED` (a final
|
|
403
|
+
4xx, retries that ran out, no connection: no verdict). Unbound: the verdict
|
|
404
|
+
is logged only.
|
|
405
|
+
|
|
406
|
+
**What the host stores from the order.** `NormalizedMarketplaceOrder.pickupCode`
|
|
407
|
+
(iFood `delivery.pickupCode`, null when the marketplace asks none) arrives in
|
|
408
|
+
`order.create`. Keep it on your order; the hand-over compares the typed code
|
|
409
|
+
with it LOCALLY, with no call to the marketplace. No code on the order: hand
|
|
410
|
+
over as before.
|
|
411
|
+
|
|
412
|
+
**What the host calls.**
|
|
413
|
+
|
|
414
|
+
- `engine.validatePickupCode({ clientId, orderId, code, at })` AFTER the
|
|
415
|
+
hand-over's commit, with the code the store checked; `at` is the
|
|
416
|
+
hand-over's instant (the job's key). One enqueue of `marketplace.outbound`,
|
|
417
|
+
action `validatePickupCode`; never throws, false when the queue refused
|
|
418
|
+
(nothing re-queues it: the marketplace's check is its half, never a gate on
|
|
419
|
+
yours). The job skips, with no call, a marketplace with no `courier` API, an
|
|
420
|
+
order no longer ACCEPTED, a bag not carried by the marketplace's courier and
|
|
421
|
+
an empty code; a 5xx or timeout is retried (3 attempts from 30 s) and the
|
|
422
|
+
last answers `UNVERIFIED`.
|
|
423
|
+
- `engine.courierTracking({ clientId, orderId })` from a job of yours while
|
|
424
|
+
the courier comes to the store, at most once per 30 s per order. Answers
|
|
425
|
+
`{ kind: "tracking", tracking: { pickupEtaAt, deliveryEtaAt, latitude,
|
|
426
|
+
longitude, trackedAt } }`, `{ kind: "notYet" }` (iFood's 404 before
|
|
427
|
+
`ASSIGN_DRIVER`), `{ kind: "unsupported", reason }` with no call (unknown
|
|
428
|
+
order, no `courier` API, a bag the store carries), or the `refused` /
|
|
429
|
+
`retry` shapes of an outbound call. Store `pickupEtaAt` as "chega em"; the
|
|
430
|
+
engine stores nothing.
|
|
431
|
+
|
|
432
|
+
**What a marketplace offers.** `engine.adapter(provider).courier` is present
|
|
433
|
+
when it has the two calls (iFood only). Courier events: iFood (all six;
|
|
434
|
+
the two return events by long name only); Keeta `RIDER_ARRIVED_AT_STORE` and
|
|
435
|
+
`ORDER_COLLECTED`, ESTIMATED, with no rider identity; 99Food and Rappi none
|
|
436
|
+
(Open Delivery's standard events and Rappi's documented ones name no courier
|
|
437
|
+
step).
|
|
438
|
+
|
|
439
|
+
**Migration-free on the engine's side.** No engine table changes:
|
|
440
|
+
`COLLECTED` is noted under the existing `HANDED_OVER` step of
|
|
441
|
+
`marketplace_status_updates`. The courier facts, the pickup code and the last
|
|
442
|
+
ETA are the host's own columns.
|
|
443
|
+
|
|
444
|
+
**Copy.** The engine adds no copy key; every sentence ("Código não confere",
|
|
445
|
+
"Voltando para a loja") is the host's.
|
|
446
|
+
|
|
447
|
+
## 11. iFood: the order fetched after PLACED (FUT-5800)
|
|
448
|
+
|
|
449
|
+
iFood's events name an order without carrying it: a PLACED is
|
|
450
|
+
`{ id, code: "PLC", fullCode: "PLACED", orderId, merchantId, createdAt }`, and
|
|
451
|
+
the order itself is `GET /order/v1.0/orders/{orderId}`. The iFood adapter now
|
|
452
|
+
marks a PLACED that carries no items `orderToFetch` and implements
|
|
453
|
+
`fetchOrder`, so a PLACED by id goes through the engine's existing order-fetch
|
|
454
|
+
path, the one 99Food and Keeta already use. A PLACED that does carry the order
|
|
455
|
+
(a replay, an older payload) is ingested from its body as before.
|
|
456
|
+
|
|
457
|
+
**The path is the webhook only.** The software connects to iFood as one
|
|
458
|
+
centralized app that iFood calls back (owner, FUT-5798: "no 30-second
|
|
459
|
+
polling"), so the engine has no events poller, calls neither
|
|
460
|
+
`events:polling` nor `events/acknowledgment`, and asks the host to schedule
|
|
461
|
+
nothing new.
|
|
462
|
+
|
|
463
|
+
**The contract.**
|
|
464
|
+
|
|
465
|
+
| | |
|
|
466
|
+
|---|---|
|
|
467
|
+
| **What the host binds** | Nothing new. The `marketplace.fetch-order` job already arrives with `MARKETPLACE_JOBS` (bind `{ engine }`); the `enqueue` port carries it and the `http` port makes its `GET`. A host that holds the job (its `enqueue` answers "not enqueued") holds every iFood order: each waits PENDING and the reconciliation sweep re-queues it. |
|
|
468
|
+
| **Delivery** | At least once. iFood redelivers a webhook it got no 2xx for; a second copy of an event is expected, never an error. |
|
|
469
|
+
| **Recorded before answered** | The webhook answers 2xx only after the delivery's inbox row is written (PENDING, "order details to fetch"). That 2xx is the acknowledgement: a delivery whose row could not be written answers no 2xx (the write's throw reaches the host's error handler), and iFood delivers it again. |
|
|
470
|
+
| **Dedupe** | By event id, at the inbox's unique `(provider, eventId)`: a redelivered PLACED is `duplicate`, queues nothing and calls nobody. By order id, at ingest's `(provider, externalOrderId)`: a second PLACED for the same order under another event id, or the same order also delivered with its body, fetches at most again and still lands ONE order. |
|
|
471
|
+
| **When iFood is called** | Never in the webhook request. The request queues `marketplace.fetch-order` (`{ clientId, inboxId }`, dedupe key `marketplace.fetch-order:<inboxId>`) after the row is written; the job reads the row, calls `GET /order/v1.0/orders/{id}` with the connection's bearer token (the adapter's token cache, the linked grant for a linked store) and ingests the answer through the one ingest path. The acceptance window counts from when the event arrived, not from when the fetch returned. |
|
|
472
|
+
| **Retry and backoff** | 3 attempts, exponential from 5 s. Retried: 404 (an order iFood has not replicated yet, ESTIMATED), 408, 425, 429, 5xx, a timeout or a network error, and a 2xx whose body is not JSON. Refused at once (row FAILED, no retry): a 2xx naming another order or carrying no items, and any other final 4xx. The last attempt settles the row FAILED (`order fetch failed: …`). The `marketplace.reconcile-inbox` sweep (every 5 min) re-queues a FAILED or still-PENDING row older than 2 minutes, until the row has been tried `maxInboxAttempts` times. |
|
|
473
|
+
| **Terminal state** | The inbox row: PROCESSED (ingested), IGNORED (cancelled before its body arrived), or FAILED with its reason once its attempts are spent. A FAILED row is never re-run past `maxInboxAttempts`; it stays as the evidence. |
|
|
474
|
+
| **401: credentials refused** | A 401 on the order read forgets the cached token and asks for a new one, once, inside the same attempt. A second 401, a 403 (the merchant has not authorized the app), or a token grant iFood refuses with a final 4xx, is our credentials refused, not the order's fault: the job does not retry it, settles the row FAILED (`order fetch failed: refused 401: …`), stamps the connection `status: "FAILED"` (what the connections screen shows) and calls `publishChanged`. The stamp is the engine's, for every adapter whose `fetchOrder` answers an `own` 4xx refusal (99Food and Keeta on a refused token grant too). No tight loop: the next try is the sweep's, at its 5-minute cadence and within the row's attempt bound. Only the credentials the call was made with are judged: a store that entered new ones meanwhile is not stamped. Re-entering the credentials resets the status to UNVERIFIED, and the next fetch that succeeds on credentials stamped FAILED sets them VERIFIED again (`lastVerifiedAt` too); the sweep then ingests what is still within its bound. |
|
|
475
|
+
|
|
476
|
+
**What the host does on the bump.** Nothing to code: confirm the
|
|
477
|
+
`marketplace.fetch-order` job runs on the worker (it was registered with the
|
|
478
|
+
other jobs since 1.x), and that the iFood webhook is registered. An iFood
|
|
479
|
+
order then reaches `order.create` as it did with a body. The outcome the
|
|
480
|
+
webhook answers for a PLACED by id is `{ received: true, outcome: "awaitingOrder" }`.
|
|
481
|
+
|
|
482
|
+
**What the fetched order carries.** The same `NormalizedMarketplaceOrder` a
|
|
483
|
+
PLACED with its body produces (lines with their SKU, name, quantity, unit price
|
|
484
|
+
and note; the buyer; the total, delivery fee, subtotal and discounts; the
|
|
485
|
+
order type, who delivers, the address and the pickup code), plus
|
|
486
|
+
`externalMerchantId` from the order's `merchant.id`: an order naming another
|
|
487
|
+
merchant than the connection's is refused FAILED, as for 99Food. The canonical
|
|
488
|
+
shape has no field for an item's options or for the payment methods; the raw
|
|
489
|
+
order is not stored by the engine.
|
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ engine code (`src/__tests__/second-adapter.test.ts`).
|
|
|
45
45
|
| **SKU map** | External SKU → host catalog id, every SKU ever seen a row; mapping checks the id is the tenant's. A link may name ONE variation of that id (`variationId`): the host's optional `order.catalogHasVariation` checks it belongs, and ingest hands it on the line as `variationRef` beside `subjectRef`. Without a variation the SKU maps to the item alone, as before. |
|
|
46
46
|
| **Integration settings** | Enabled, environment, merchant id, auto-accept, acknowledgement window; credentials sealed as one blob by the host's secrets port, never returned. A connection is archived (reversible, audited), never deleted. |
|
|
47
47
|
| **Outbound engine** | The `marketplace.outbound` job: confirm after accept (with the preparation time where the marketplace takes one), cancellation request with the stored reason code and SKUs. 2xx done; a 4xx other than 408/425/429 refused and final; anything else retried until the last attempt, which ends FAILED whatever went wrong. Stamps `confirmed_at`, `confirm_failed_at`, `cancellation_status` (PENDING, REQUESTED, CONFIRMED, FAILED). Idempotent by the row. Queued BEFORE the host's half runs, and the `marketplace.outbound-sweep` job re-queues every call still owed, so nothing is lost. The same sweep fails a request still waiting (never delivered, or delivered and unanswered) as TIMEOUT once past its answer window, and its retries stop (the adapter's `cancellationAnswerWindowMs`, or the engine's `cancellationWindowMs`), so no request waits forever. |
|
|
48
|
-
| **Order fetch** | For a marketplace whose events name an order without carrying it (Open Delivery's `CREATED`), the adapter marks the event `orderToFetch`: the webhook records it PENDING and queues `marketplace.fetch-order`, which calls the adapter's `fetchOrder` and ingests through the same ingest path. No request calls out; the reconciliation sweep re-queues a row still owed, and a host that holds the job holds every fetch. |
|
|
48
|
+
| **Order fetch** | For a marketplace whose events name an order without carrying it (Open Delivery's `CREATED`, iFood's `PLACED`, FUT-5800), the adapter marks the event `orderToFetch`: the webhook records it PENDING and queues `marketplace.fetch-order`, which calls the adapter's `fetchOrder` and ingests through the same ingest path. No request calls out; the reconciliation sweep re-queues a row still owed, and a host that holds the job holds every fetch. A fetch our credentials are refused on (an `own` 4xx) is not retried by the queue and stamps the connection FAILED. Contract: [ADOPTING.md §11](./ADOPTING.md#11-ifood-the-order-fetched-after-placed-fut-5800). |
|
|
49
49
|
| **Inbound outcomes** | A marketplace CANCELLED confirms a pending request; CANCELLATION_REQUEST_FAILED marks it FAILED; CONFIRMED is terminal. |
|
|
50
50
|
| **Catalogue publishing** | A store turns a product ON or OFF per connected marketplace, with an optional price for that marketplace. One row per (store, marketplace, product): PUBLISHING → PUBLISHED, WITHDRAWING → WITHDRAWN, FAILED with a failure code (and the marketplace's own words for a refusal). The `marketplace.catalogue` job makes the call; the sweep re-queues what is owed. Push or pull is the adapter's. See [Catalogue publishing](#catalogue-publishing). |
|
|
51
51
|
| **Adapter port** | `MarketplaceAdapter`: `normalize`, `readSignature`, `verifySignature`, `cancellationReasons`, `confirm`, `requestCancellation`, `appLink`, `capabilities`, and the optional `fetchOrder`, `catalogue` and `catalogueReader`. |
|
|
@@ -223,7 +223,17 @@ body fields and reason codes come from the portal's search snippets
|
|
|
223
223
|
(2026-11-11). (Its Catalog module's pages were read whole on 2026-11-13: see
|
|
224
224
|
[Catalogue publishing](#catalogue-publishing).)
|
|
225
225
|
They live only in `src/ifood/outbound.ts` and `src/ifood/copy.ts`, whose
|
|
226
|
-
headers say so, so the homologation run corrects two files.
|
|
226
|
+
headers say so, so the homologation run corrects two files.
|
|
227
|
+
|
|
228
|
+
The order read (FUT-5800) is partly verified. Only the EVENT shape was seen in
|
|
229
|
+
the sandbox (2026-11-27): iFood's events carry only the order id (`{ id, code,
|
|
230
|
+
fullCode, orderId, merchantId, createdAt }`), so a PLACED with no items is
|
|
231
|
+
fetched with `GET /order/v1.0/orders/{id}` by the `marketplace.fetch-order` job
|
|
232
|
+
and ingested like a PLACED carrying its body (`src/ifood/fetch-order.ts`). The
|
|
233
|
+
order body's field names are still the documented ones, not yet checked against
|
|
234
|
+
a real sandbox order. A 404 right after the PLACED is retried (ESTIMATED: not
|
|
235
|
+
yet served). Webhook only: the software is one centralized iFood app, so the
|
|
236
|
+
adapter does not poll iFood's events (FUT-5798). Tests never reach
|
|
227
237
|
iFood: the HTTP client is the host's port.
|
|
228
238
|
|
|
229
239
|
## Linking a store through the software's own app (FUT-5613)
|
|
@@ -375,7 +385,7 @@ What differs from 99Food's v1.7.1, and where the adapter handles it:
|
|
|
375
385
|
| part | from Keeta's documentation |
|
|
376
386
|
|---|---|
|
|
377
387
|
| Merchant id | A connection's `externalMerchantId` for Keeta is the SOFTWARE's merchant id: the `merchantId` the onboarding binds to `keetaMerchantId`, echoed as `X-App-MerchantId` and `Order.merchant.id`, and the `{merchantId}` of `merchantUpdate`. Keeta's own store id (`keetaMerchantId`, `authorizedShops[].id`) is the onboarding's. "Without onboarding there are no order events"; onboarding the same id again replaces the mapping. |
|
|
378
|
-
| Events | `CREATED` → fetch; `CANCELLED` (its `metadata` a JSON string with `reason`, `code`) → cancelled; `DISPATCHED`, `CONCLUDED` → lifecycle; the rest (`CONFIRMED`, `READY_FOR_PICKUP`, `PICKUP_ONGOING`, `
|
|
388
|
+
| Events | `CREATED` → fetch; `CANCELLED` (its `metadata` a JSON string with `reason`, `code`) → cancelled; `DISPATCHED`, `CONCLUDED` → lifecycle; `RIDER_ARRIVED_AT_STORE`, `ORDER_COLLECTED` → courier steps, the second a `COLLECTED` lifecycle too (FUT-5665, ESTIMATED); the rest (`CONFIRMED`, `READY_FOR_PICKUP`, `PICKUP_ONGOING`, `DELIVERED`, `CANCELLATION_REQUESTED`, the refund events, `RECOMMENDED_PREPARATION_START`) recorded and IGNORED. Keeta retries an unanswered webhook 3 times (1, 2 and 3 minutes later). |
|
|
379
389
|
| Confirm | `POST /v1/orders/{id}/confirm` `{ createdAt, orderExternalCode, preparationTime? }`; 202, then `CONFIRMED`; 422 "invalid or repeated state". Keeta cancels an order not accepted within 5 minutes and may close the store for it: a connection's acknowledgement window should be at most 300 s. |
|
|
380
390
|
| Cancel | `POST /v1/orders/{id}/requestCancellation` `{ reason, code, mode, outOfStockItems? }` with Keeta's eleven v1.0.7+ codes (the standard's); 202 "received for analysis", then `CANCELLED` or nothing. |
|
|
381
391
|
| Order | The standard's `Order`; `total.orderAmount` = items + fees − discounts is the total, no commission (`commissionCents` null). An encrypted value Keeta would not reveal (its own fleet, a refused or failed decrypt) is dropped, never shown: the number reads the copy's missing-number text, the phone is null. A failed decrypt never keeps the order out of the queue. |
|
|
@@ -563,6 +573,42 @@ Sources: Open Delivery `openapi.yaml` (read 2026-11-25), Rappi's portal
|
|
|
563
573
|
so every iFood row but confirm and requestCancellation is ESTIMATED, in
|
|
564
574
|
`src/ifood/outbound.ts` and `src/ifood/normalize.ts` only.
|
|
565
575
|
|
|
576
|
+
## The marketplace's own courier and the pickup code (FUT-5665)
|
|
577
|
+
|
|
578
|
+
For a bag the marketplace's fleet carries, four additive pieces, each optional
|
|
579
|
+
for the host (ADOPTING.md section 10):
|
|
580
|
+
|
|
581
|
+
- **Courier events.** `NormalizedEvent.courier` (`NormalizedCourierEvent`:
|
|
582
|
+
`step`, `at`, `courier { name, photoUrl, vehicle }` on `ASSIGNED`,
|
|
583
|
+
`returning`) reaches `order.onCourier` for an ACCEPTED order; it moves
|
|
584
|
+
nothing. iFood: `ADR`/`ASSIGN_DRIVER` (metadata `workerName`,
|
|
585
|
+
`workerPhotoUrl`, `workerVehicleType`), `GTO`, `AAO`, `CLT`,
|
|
586
|
+
`DELIVERY_RETURNING_TO_ORIGIN`, `DELIVERY_RETURNED_TO_ORIGIN`. Keeta:
|
|
587
|
+
`RIDER_ARRIVED_AT_STORE`, `ORDER_COLLECTED` (ESTIMATED). 99Food, Rappi:
|
|
588
|
+
unsupported.
|
|
589
|
+
- **COLLECTED is a lifecycle step.** `CLT` / `ORDER_COLLECTED` also names
|
|
590
|
+
`lifecycle: "COLLECTED"`, which follows the FUT-4653 rules like a
|
|
591
|
+
`DISPATCHED` and is noted as the marketplace's `HANDED_OVER`, for a bag the
|
|
592
|
+
marketplace carries only (a store-carried bag's COLLECTED is IGNORED, never
|
|
593
|
+
noted, so the store's own "delivered" is still sent).
|
|
594
|
+
- **The pickup code.** `NormalizedMarketplaceOrder.pickupCode` (iFood
|
|
595
|
+
`delivery.pickupCode`). After its local check and hand-over, the host calls
|
|
596
|
+
`engine.validatePickupCode`, and the `marketplace.outbound` job (action
|
|
597
|
+
`validatePickupCode`) posts `POST /order/v1.0/orders/{id}/validatePickupCode
|
|
598
|
+
{"code"}` and hands `{"valid"}` to `order.onPickupCodeValidated` as `VALID`,
|
|
599
|
+
`INVALID` or `UNVERIFIED`.
|
|
600
|
+
- **Tracking.** `engine.courierTracking` reads `GET
|
|
601
|
+
/order/v1.0/orders/{id}/tracking` at once (404 is `notYet`); the host runs
|
|
602
|
+
it from a job, at most once per 30 s.
|
|
603
|
+
|
|
604
|
+
Source: the iFood research of 2026-11-26 (Order module, marked confirmed
|
|
605
|
+
there). ESTIMATED, in `src/ifood/courier.ts` only: the values of
|
|
606
|
+
`workerVehicleType`, the names of the tracking body's second counts
|
|
607
|
+
(`pickupEtaStart` / `deliveryEtaEnd`, else `pickupEta` / `deliveryEta`), the
|
|
608
|
+
absence of short codes for the two return events, and whether a wrong code
|
|
609
|
+
answers `{"valid": false}` rather than a 4xx (a 4xx is `UNVERIFIED`, never
|
|
610
|
+
`INVALID`).
|
|
611
|
+
|
|
566
612
|
## Pausing a store (FUT-4851)
|
|
567
613
|
|
|
568
614
|
When the store's kitchen passes its cap, the host closes the store on every
|
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-CQ4QiZPi.js';
|
|
2
|
+
import { O as OpenDeliveryApiBaseUrls } from '../client-CCSnylou.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-NFJQQWG4.js";
|
|
16
16
|
import "../chunk-M2V4RFMA.js";
|
|
17
17
|
import "../chunk-BD7DS3XM.js";
|
|
18
|
-
import "../chunk-
|
|
18
|
+
import "../chunk-4J2KJ3ZW.js";
|
|
19
19
|
import {
|
|
20
20
|
__name
|
|
21
21
|
} from "../chunk-7QVYU63E.js";
|