@12-apps/marketplace 1.7.0 → 1.9.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 +17 -0
- package/README.md +153 -3
- package/dist/99food/index.d.ts +30 -52
- package/dist/99food/index.js +62 -391
- package/dist/99food/index.js.map +1 -1
- package/dist/{adapter-DOjTak1H.d.ts → adapter-CYJzu1c9.d.ts} +45 -1
- package/dist/{chunk-YVUZHXUF.js → chunk-6N2HEV3U.js} +4 -4
- package/dist/chunk-6N2HEV3U.js.map +1 -0
- package/dist/{chunk-SJUKBCVO.js → chunk-BMCERPQX.js} +198 -12
- package/dist/chunk-BMCERPQX.js.map +1 -0
- package/dist/{chunk-L3DCOZUU.js → chunk-HEXLCTOG.js} +1 -1
- package/dist/chunk-HEXLCTOG.js.map +1 -0
- package/dist/{chunk-UYFYGGCS.js → chunk-NP4EYKPO.js} +3 -1
- package/dist/chunk-NP4EYKPO.js.map +1 -0
- package/dist/chunk-PYHNM47K.js +478 -0
- package/dist/chunk-PYHNM47K.js.map +1 -0
- package/dist/client-B4EQCRD_.d.ts +20 -0
- package/dist/{engine-DG1fg43Y.d.ts → engine-wmW-VuBL.d.ts} +107 -4
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +3 -3
- package/dist/ifood/index.d.ts +1 -1
- package/dist/ifood/index.js +29 -3
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +104 -7
- package/dist/index.js.map +1 -1
- package/dist/keeta/en-US.d.ts +19 -0
- package/dist/keeta/en-US.js +23 -0
- package/dist/keeta/en-US.js.map +1 -0
- package/dist/keeta/index.d.ts +253 -0
- package/dist/keeta/index.js +388 -0
- package/dist/keeta/index.js.map +1 -0
- package/dist/keeta/pt-BR.d.ts +23 -0
- package/dist/keeta/pt-BR.js +23 -0
- package/dist/keeta/pt-BR.js.map +1 -0
- package/dist/manifest/index.d.ts +3 -0
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/server.d.ts +2 -2
- package/dist/manifest/server.js +3 -3
- package/dist/rappi/index.d.ts +7 -1
- package/dist/rappi/index.js +20 -3
- package/dist/rappi/index.js.map +1 -1
- package/dist/server/index.d.ts +6 -2
- package/dist/server/index.js +3 -3
- package/package.json +14 -2
- package/prisma/marketplace.prisma +45 -1
- package/prisma/migrations/20261126120000_marketplace_status_updates/migration.sql +60 -0
- package/src/99food/catalogue.ts +19 -89
- package/src/99food/copy.ts +4 -19
- package/src/99food/index.ts +29 -28
- package/src/99food/normalize.ts +11 -247
- package/src/99food/outbound.ts +29 -215
- package/src/99food/pause.ts +7 -22
- package/src/core/adapter.ts +41 -1
- package/src/core/bulk.ts +1 -1
- package/src/core/engine.ts +9 -0
- package/src/core/ingest.ts +6 -0
- package/src/core/integration.ts +17 -0
- package/src/core/lifecycle-port.ts +16 -0
- package/src/core/lifecycle.ts +133 -0
- package/src/core/outbound-queue.ts +24 -4
- package/src/core/outbound-sweep.ts +49 -5
- package/src/core/outbound.ts +11 -0
- package/src/core/pipeline.ts +22 -2
- package/src/core/ports.ts +39 -3
- package/src/core/status-inform.ts +51 -0
- package/src/core/status-job.ts +207 -0
- package/src/core/status-store.ts +85 -0
- package/src/core/types.ts +14 -0
- package/src/ifood/index.ts +7 -1
- package/src/ifood/normalize.ts +17 -0
- package/src/ifood/outbound.ts +35 -0
- package/src/index.ts +8 -1
- package/src/keeta/authorization.ts +226 -0
- package/src/keeta/copy.ts +27 -0
- package/src/keeta/en-US.ts +19 -0
- package/src/keeta/index.ts +162 -0
- package/src/keeta/merchant.ts +70 -0
- package/src/keeta/normalize.ts +131 -0
- package/src/keeta/outbound.ts +55 -0
- package/src/keeta/pt-BR.ts +23 -0
- package/src/keeta/signature.ts +85 -0
- package/src/open-delivery/client.ts +185 -0
- package/src/open-delivery/merchant.ts +126 -0
- package/src/open-delivery/normalize.ts +269 -0
- package/src/open-delivery/orders.ts +241 -0
- package/src/open-delivery/reasons.ts +26 -0
- package/src/rappi/index.ts +6 -1
- package/src/rappi/normalize.ts +6 -0
- package/src/rappi/outbound.ts +31 -2
- package/src/server/mcp.ts +2 -0
- package/src/server/webhook.ts +3 -1
- package/dist/chunk-L3DCOZUU.js.map +0 -1
- package/dist/chunk-SJUKBCVO.js.map +0 -1
- package/dist/chunk-UYFYGGCS.js.map +0 -1
- package/dist/chunk-YVUZHXUF.js.map +0 -1
package/ADOPTING.md
CHANGED
|
@@ -75,6 +75,7 @@ export const engine = createMarketplaceEngine({
|
|
|
75
75
|
| `withdraw({ clientId, provider, productId })` | The switch turned OFF (and the undo of an ON). `queued` (WITHDRAWING), or `unchanged` when the product was never switched on, or is WITHDRAWN at once because its connection was archived or removed since. |
|
|
76
76
|
| `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. |
|
|
77
77
|
| `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. |
|
|
78
|
+
| `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). |
|
|
78
79
|
| `ingest(...)`, `deliver(...)` | A producer that hands over an order directly; the webhook does `deliver` for you. |
|
|
79
80
|
|
|
80
81
|
A host never writes `provider === "IFOOD"`. A capability is asked of
|
|
@@ -222,6 +223,22 @@ connection's `archived_at`, keeps the host's foreign keys, and replaces the
|
|
|
222
223
|
closed provider lists (`*_provider_valid`) with a shape check, so a new
|
|
223
224
|
adapter is never a migration.
|
|
224
225
|
|
|
226
|
+
`20261126120000_marketplace_status_updates` (1.8, FUT-4653) adds
|
|
227
|
+
`marketplace_integrations.follow_status` (NOT NULL DEFAULT true: every existing
|
|
228
|
+
connection follows the marketplace's status once the hook is bound) and
|
|
229
|
+
`marketplace_status_updates`, one row per (order, step) with its step, source and
|
|
230
|
+
state CHECKed and a partial index the outbound sweep reads. Additive; `order_id`
|
|
231
|
+
is by value. Compose it with the schema in the same change as the engine bump: the
|
|
232
|
+
engine selects `follow_status`. To follow the marketplace's status a host binds
|
|
233
|
+
`order.onLifecycle`; to tell it, `order.statusHolds` and calls `informStatus`.
|
|
234
|
+
Both are optional: a host that binds neither behaves as before.
|
|
235
|
+
`MarketplaceDb.marketplaceStatusUpdate` is optional in the type, so a host that has
|
|
236
|
+
not composed the model still compiles, and the two paths then do nothing.
|
|
237
|
+
`DeliveryOutcome` gains `{ kind: "moved", orderId, lifecycle }`, and
|
|
238
|
+
`OutboundAction` gains `"status"` (the payload an optional `step`): a host that
|
|
239
|
+
switches over either exhaustively adds the case; allow `"status"` in any
|
|
240
|
+
action allow-list in front of the outbound job.
|
|
241
|
+
|
|
225
242
|
## 6. What stays the host's
|
|
226
243
|
|
|
227
244
|
The stock draw at the acceptance, the settlement effects, the board's and the
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
One integration engine for every marketplace a store sells through. Each
|
|
4
4
|
marketplace is an **adapter** on that engine, shipped inside this package at
|
|
5
5
|
its own subpath (`@12-apps/marketplace/ifood`, `@12-apps/marketplace/99food`,
|
|
6
|
-
`@12-apps/marketplace/rappi`).
|
|
6
|
+
`@12-apps/marketplace/keeta`, `@12-apps/marketplace/rappi`).
|
|
7
7
|
|
|
8
8
|
```ts
|
|
9
9
|
import { createMarketplaceEngine } from "@12-apps/marketplace";
|
|
@@ -59,6 +59,8 @@ engine code (`src/__tests__/second-adapter.test.ts`).
|
|
|
59
59
|
| `@12-apps/marketplace/ifood/pt-BR`, `/en-US` | the iFood adapter's copy packs (reason labels, "no street number") |
|
|
60
60
|
| `@12-apps/marketplace/99food` | `createNinetyNineFoodAdapter({ copy, apiBaseUrl, portalUrl })`, provider `NINETY_NINE_FOOD`, on Open Delivery |
|
|
61
61
|
| `@12-apps/marketplace/99food/pt-BR`, `/en-US` | the 99Food adapter's copy packs |
|
|
62
|
+
| `@12-apps/marketplace/keeta` | `createKeetaAdapter({ copy, apiBaseUrl?, portalUrl?, pauseByStoreSwitch? })`, provider `KEETA`, on Open Delivery; `createKeetaAuthorization()` for the self-serve merchant authorization |
|
|
63
|
+
| `@12-apps/marketplace/keeta/pt-BR`, `/en-US` | the Keeta adapter's copy packs |
|
|
62
64
|
| `@12-apps/marketplace/rappi` | `createRappiAdapter({ copy, apiBaseUrl, tokenUrl, portalUrl, amountUnit })`, provider `RAPPI` |
|
|
63
65
|
| `@12-apps/marketplace/rappi/pt-BR`, `/en-US` | the Rappi adapter's copy packs |
|
|
64
66
|
| `@12-apps/marketplace/server` | `createApiMarketplace` (route descriptors), `MARKETPLACE_JOBS`, `MARKETPLACE_MCP_TOOLS` (six: a read and a bulk write per entity), `MARKETPLACE_PERMISSIONS`, the strict Zod inputs |
|
|
@@ -136,6 +138,17 @@ there, chosen in the adapter's code and marked so beside it.
|
|
|
136
138
|
| `X-App-MerchantId` on the notification (the operation lists no header) | ESTIMATED |
|
|
137
139
|
| A product in the document is PUBLISHED once 99Food took the notification, not once it read the menu | choice |
|
|
138
140
|
|
|
141
|
+
**Keeta — pull, Open Delivery v1.5.0 + Keeta's changes** (`src/keeta/merchant.ts`)
|
|
142
|
+
|
|
143
|
+
| fact | status |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `POST /v1/merchantUpdate/{merchantId}` (the SOFTWARE's merchant id in the path): an empty body makes Keeta call the host's `GET /v1/merchant` and reload everything; 204 | CONFIRMED — [merchantUpdate](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/merchantupdate) |
|
|
146
|
+
| `entityType` + `updatedObjects` applies only `ITEM_OFFER` / `OPTION` **status** as sent (since v1.0.8); `MENU`, `CATEGORY`, `ITEM`… still reload the whole menu: a product's name, photo and price reach Keeta only through the document, so the adapter is pull, not push | CONFIRMED — same; [general-info](https://api-docs.mykeeta.com/apis/opendelivery/general-info) ("only full-menu update") |
|
|
147
|
+
| The document's `items[].unit` must be `UN`, every item needs a status and a delivery price, `itemOffers[].price.originalValue` is required, `currency`, `lastUpdate` and `TTL` are ignored; `basicInfo.contactEmails` and `contactPhones.commercialNumber` are required (the host's part) | CONFIRMED — [getMerchant](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/getmerchant) |
|
|
148
|
+
| The document's URL is per merchant, registered at onboarding (`getMerchantURL.baseURL`, optional `apiKey`) | CONFIRMED — [putMerchantOnboarding](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/putmerchantonboarding) |
|
|
149
|
+
| An update with no body and no `Content-Type` is read as the documented "empty body" | ESTIMATED |
|
|
150
|
+
| `POST /v1/merchant/image/upload` (an image URL for the menu) | not used: the document carries the host's own `imageUrl` |
|
|
151
|
+
|
|
139
152
|
**Rappi — not supported** (no `catalogue` on the adapter)
|
|
140
153
|
|
|
141
154
|
| fact | status |
|
|
@@ -200,7 +213,7 @@ reader that day, so what they would settle is ESTIMATED below (the push's
|
|
|
200
213
|
| An item `type` other than `DEFAULT` (a pizza, a combo) is read as a plain item with `ITEM_TYPE_UNSUPPORTED` | choice |
|
|
201
214
|
| The read covers the merchant-level categories (the DEFAULT, delivery, context); other catalogs and `contextModifiers` prices are not read | ESTIMATED |
|
|
202
215
|
|
|
203
|
-
99Food and Rappi state no `catalogueReader`: `engine.readCatalogue` answers
|
|
216
|
+
99Food, Keeta and Rappi state no `catalogueReader`: `engine.readCatalogue` answers
|
|
204
217
|
`UNSUPPORTED` for them.
|
|
205
218
|
|
|
206
219
|
## iFood is unverified
|
|
@@ -218,7 +231,9 @@ iFood: the HTTP client is the host's port.
|
|
|
218
231
|
99Food completed Open Delivery (Abrasel) adherence, so its adapter speaks
|
|
219
232
|
[Open Delivery v1.7.1](https://abrasel-nacional.github.io/opendelivery/openapi.yaml)
|
|
220
233
|
and is registered as `NINETY_NINE_FOOD`. Its webhook is the engine's one
|
|
221
|
-
route, `POST /webhooks/marketplace/:tenantSlug/NINETY_NINE_FOOD`.
|
|
234
|
+
route, `POST /webhooks/marketplace/:tenantSlug/NINETY_NINE_FOOD`. The standard's
|
|
235
|
+
readers and calls live in `src/open-delivery/`, shared with Keeta; what is
|
|
236
|
+
99Food's (its dialect, copy and ESTIMATED choices) is in `src/99food/`.
|
|
222
237
|
|
|
223
238
|
```ts
|
|
224
239
|
import { createNinetyNineFoodAdapter } from "@12-apps/marketplace/99food";
|
|
@@ -259,6 +274,83 @@ end to end: event, fetch, ingest, aceite, confirm, cancel, the answer.
|
|
|
259
274
|
- that 99Food sends every event by webhook (Open Delivery also allows
|
|
260
275
|
polling, which this adapter does not do).
|
|
261
276
|
|
|
277
|
+
## Keeta, on Open Delivery
|
|
278
|
+
|
|
279
|
+
Keeta's API is [Open Delivery v1.5.0 with Keeta's own changes](https://api-docs.mykeeta.com/apis/opendelivery/general-info)
|
|
280
|
+
("the definitions of this document prevail"; `openapi.json` and its
|
|
281
|
+
changelog to v1.0.9, read 2026-11-26). The adapter is built on the same Open
|
|
282
|
+
Delivery module as 99Food's (`src/open-delivery/`: the readers, the token
|
|
283
|
+
grant, the order calls, the menu document, `merchantUpdate`), and is
|
|
284
|
+
registered as `KEETA`. Its webhook is the engine's one route, `POST
|
|
285
|
+
/webhooks/marketplace/:tenantSlug/KEETA`, registered per store as
|
|
286
|
+
`ordersWebhookURL` at onboarding.
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
import { createKeetaAdapter, createKeetaAuthorization } from "@12-apps/marketplace/keeta";
|
|
290
|
+
import { KEETA_ADAPTER_COPY_PT_BR } from "@12-apps/marketplace/keeta/pt-BR";
|
|
291
|
+
|
|
292
|
+
createKeetaAdapter({ copy: KEETA_ADAPTER_COPY_PT_BR }); // apiBaseUrl and portalUrl default to Keeta's documented ones
|
|
293
|
+
const authorization = createKeetaAuthorization(); // the self-serve merchant authorization calls
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
What differs from 99Food's v1.7.1, and where the adapter handles it:
|
|
297
|
+
|
|
298
|
+
| Keeta | 99Food (v1.7.1) | in |
|
|
299
|
+
|---|---|---|
|
|
300
|
+
| **Every request** (the token grant included) carries `X-App-Signature`: Base64 HMAC-SHA256, keyed by the client secret, of the URL without its query + `&k=v` per query parameter sorted by key + `&` + the body, the body compact RFC 8785 JSON (an empty body or `{}` is left out with its `&`) | no request signature | `src/keeta/signature.ts`, `src/keeta/outbound.ts` |
|
|
301
|
+
| The webhook's `X-App-Signature` is Base64 HMAC-SHA256 of the body | lowercase hex | `src/keeta/signature.ts` |
|
|
302
|
+
| Token: JSON `{ client_id, client_secret, grant_type: "app_level_token" }` (v1.0.9; `client_credentials` stays accepted for certified integrations); ONE token per application, for every store that authorized it | form-encoded `client_credentials` | `src/keeta/outbound.ts` |
|
|
303
|
+
| Merchant authorization the software can automate: `GET /oauth/authorization/url`, the redirect's `authId`, `GET /oauth/authorized/{authId}/merchantInfo`, `PUT /v1/merchantOnboarding?merchantId=`, and the authorization webhook (`opType` 1 added, 2 revoked) | none | `src/keeta/authorization.ts` |
|
|
304
|
+
| `merchantUpdate/{merchantId}`: the path names the merchant | `merchantUpdate`, merchant in a header | `src/keeta/merchant.ts` |
|
|
305
|
+
| Menu: full reload only (`ITEM_OFFER` / `OPTION` status excepted) | full reload | `src/keeta/merchant.ts` |
|
|
306
|
+
| Personal data encrypted (`ENC_…`: the phone, the address's district, number, complement, formatted address); `POST /v1/batchDecrypt` (≤ 50 a call) only for the merchant's own delivery | plain | `src/keeta/normalize.ts` |
|
|
307
|
+
| No `CANCELLATION_REQUEST_DENIED`: a request Keeta does not grant is silent, so it ends TIMEOUT at the answer window | the denial event | the adapter's `cancellationAnswerWindowMs` |
|
|
308
|
+
| `outOfStockItems` carries the PDV codes (`externalCode`, Keeta's example `"PDV-1002"`): sent with an item-unavailable reason when the store named the SKUs | item uuids: not sent | `openDeliveryRequestCancellation`'s option |
|
|
309
|
+
| No take-out (`PICKED_UP` "is not sent"), so no `pickedUp`; `delivered` only for the merchant's bag | `pickedUp` for a take-out | `openDeliveryStatus`'s option |
|
|
310
|
+
| One public base URL (`https://open.mykeeta.com/api/open/opendelivery`) and Merchant Portal (`https://merchant.mykeeta.com/`) | given at onboarding: required config | defaults, overridable |
|
|
311
|
+
|
|
312
|
+
| part | from Keeta's documentation |
|
|
313
|
+
|---|---|
|
|
314
|
+
| 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. |
|
|
315
|
+
| Events | `CREATED` → fetch; `CANCELLED` (its `metadata` a JSON string with `reason`, `code`) → cancelled; `DISPATCHED`, `CONCLUDED` → lifecycle; the rest (`CONFIRMED`, `READY_FOR_PICKUP`, `PICKUP_ONGOING`, `RIDER_ARRIVED_AT_STORE`, `ORDER_COLLECTED`, `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). |
|
|
316
|
+
| 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. |
|
|
317
|
+
| 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. |
|
|
318
|
+
| 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. |
|
|
319
|
+
|
|
320
|
+
The fixtures are Keeta's own examples (`src/keeta/__tests__/fixtures.ts`: the
|
|
321
|
+
Brazilian order of `orderDetails`' appendix, `newEvent`, `merchantInfo`, the
|
|
322
|
+
authorization webhook, the signature-string examples).
|
|
323
|
+
`src/keeta/__tests__/engine.test.ts` drives the engine through the adapter end
|
|
324
|
+
to end; `src/keeta/__tests__/keeta.test.ts` pins every request's shape and
|
|
325
|
+
signature.
|
|
326
|
+
|
|
327
|
+
**ESTIMATED, to be checked in Keeta's SIT:**
|
|
328
|
+
|
|
329
|
+
- the SANDBOX base URL: Keeta documents one host, and a test application (its
|
|
330
|
+
own client id and secret, its test stores) is what makes a session a test
|
|
331
|
+
one, so both environments default to it;
|
|
332
|
+
- query values are signed DECODED (only the authorization calls send one, and
|
|
333
|
+
only `redirectUri` changes under encoding);
|
|
334
|
+
- the webhook signature covers the raw body as received; the authorization
|
|
335
|
+
webhook uses the same Base64 HMAC (its schema says only "SHA256 hash of the
|
|
336
|
+
body"); the answer it wants is `{ code: 0, message: "success" }`
|
|
337
|
+
(`KEETA_AUTHORIZATION_WEBHOOK_ANSWER`: "JSON with `code` and `message`");
|
|
338
|
+
- the cancellation answer window, 5 minutes (Keeta names none, and sends no
|
|
339
|
+
denial);
|
|
340
|
+
- `outOfStockItems` reads PDV codes (the example's), not Keeta's item ids;
|
|
341
|
+
- `OrderConfirmed.createdAt` is sent as the moment of the confirmation (as
|
|
342
|
+
for 99Food; Keeta's example shows a minute after the order);
|
|
343
|
+
- a `batchDecrypt` entry with no `errorCode` is a success; decrypt runs only
|
|
344
|
+
when `delivery.deliveredBy` is `MERCHANT`;
|
|
345
|
+
- an empty-body `merchantUpdate` is sent with no `Content-Type`;
|
|
346
|
+
- that Keeta sends every event by webhook: polling (`GET /v1/events:polling`,
|
|
347
|
+
2 a minute, with acknowledgement) is not done by this adapter, though Keeta
|
|
348
|
+
recommends it as a fallback.
|
|
349
|
+
|
|
350
|
+
Out of scope: refunds (`USER_REFUND_REQUEST`, `acceptRefund`, `rejectRefund`),
|
|
351
|
+
tracking (`POST /v1/orders/{id}/tracking`), the image upload, and serving
|
|
352
|
+
`GET /v1/merchant` and the authorization webhook, which are host routes.
|
|
353
|
+
|
|
262
354
|
## Rappi, from its public developer portal
|
|
263
355
|
|
|
264
356
|
Built now (owner, 2026-11-11) from what [dev-portal.rappi.com](https://dev-portal.rappi.com)
|
|
@@ -352,6 +444,62 @@ nothing, so the order stays ACCEPTED here while cancelled on Rappi. The take
|
|
|
352
444
|
the accept queued is then answered 400, so the order shows "não confirmou"
|
|
353
445
|
with the portal link and a person settles it there.
|
|
354
446
|
|
|
447
|
+
## Following and informing an order's status (FUT-4653)
|
|
448
|
+
|
|
449
|
+
Two directions, both forward-only and neither ever refused, reverted or waited on.
|
|
450
|
+
|
|
451
|
+
**Inbound.** An iFood `DSP`/`CON` and an Open Delivery `DISPATCHED`/`CONCLUDED`
|
|
452
|
+
normalize to `NormalizedEvent.lifecycle` (`"DISPATCHED"` or `"CONCLUDED"`).
|
|
453
|
+
iFood's codes are ESTIMATED (its portal refused our reader, 2026-11-25); Rappi
|
|
454
|
+
maps none (its `event` values are undocumented). With the connection's
|
|
455
|
+
`followStatus` ON (default; `marketplace_integrations.follow_status`) and a host
|
|
456
|
+
that binds `order.onLifecycle`, the engine asks the host to move the order
|
|
457
|
+
forward, after four rules of its own, each ending the delivery IGNORED with a
|
|
458
|
+
reason:
|
|
459
|
+
|
|
460
|
+
1. no acceptance yet: DEFERRED (PENDING, one attempt counted,
|
|
461
|
+
`lifecycle before its order`), so the reconcile pass applies it after the
|
|
462
|
+
order's own event ingests; retired after `maxInboxAttempts`;
|
|
463
|
+
2. the acceptance is not ACCEPTED (`the order is AWAITING, not ACCEPTED`);
|
|
464
|
+
3. a cancellation request is PENDING or REQUESTED;
|
|
465
|
+
4. the event echoes a step we informed (`echo of our DISPATCHED`; a CONCLUDED
|
|
466
|
+
after our HANDED_OVER): without this, a store that dispatched, told iFood and
|
|
467
|
+
dragged the bag back would have it dispatched again by iFood's own echo.
|
|
468
|
+
|
|
469
|
+
Whatever the host answers, the marketplace's word is NOTED (a
|
|
470
|
+
`marketplace_status_updates` row) so our own job never informs it back. The
|
|
471
|
+
host answers `"moved"`, `"unchanged"` or `{ kind: "unchanged", reason }` (its
|
|
472
|
+
reason becomes the inbox's; a bag whose store never named a courier is the
|
|
473
|
+
host's rule, not the engine's). The facts it gets are `{ deliveredBy }`
|
|
474
|
+
(`MERCHANT`, `MARKETPLACE`, null for a take-out). Switch OFF, no hook, or
|
|
475
|
+
settings built by hand without `followStatus`: byte-for-byte the old answer
|
|
476
|
+
(`no order body on <type>`).
|
|
477
|
+
|
|
478
|
+
**Outbound.** The host calls `engine.informStatus({ clientId, orderId, step,
|
|
479
|
+
at, delayMs? })` when an order reaches `READY`, `DISPATCHED` or `HANDED_OVER`:
|
|
480
|
+
one enqueue of `marketplace.outbound` (action `status`), no statement, never
|
|
481
|
+
throws. The job asks, in order, stopping at the first no, with no row and no
|
|
482
|
+
call: acceptance ACCEPTED and no cancellation request standing; the adapter
|
|
483
|
+
states the step (`capabilities.statusSteps`) and takes it for this order
|
|
484
|
+
(`statusSupported`); `order.statusHolds` says the order still holds it; no
|
|
485
|
+
status row exists for (order, step) and the marketplace has not CONCLUDED;
|
|
486
|
+
then it claims the row (STORE, SENDING, unique per (order, step)) and calls
|
|
487
|
+
`informStatus`. 2xx is SENT; a final 4xx FAILED (error log, never retried); a
|
|
488
|
+
5xx or timeout is retried (3 attempts, exponential from 30 s) and the last is
|
|
489
|
+
FAILED. A SENDING row left by a dead job is re-queued by the outbound sweep
|
|
490
|
+
after 10 minutes and failed after 24 hours.
|
|
491
|
+
|
|
492
|
+
| step | iFood (ESTIMATED) | 99Food (Open Delivery v1.7.1) | Keeta | Rappi |
|
|
493
|
+
|---|---|---|---|---|
|
|
494
|
+
| READY | `POST /orders/{id}/readyToPickup`, not for a merchant bag | `POST /v1/orders/{id}/readyForPickup` | `POST /v1/orders/{id}/readyForPickup` | `POST /orders/{id}/ready-for-pickup` (ESTIMATED verb; MANUAL-notification stores only) |
|
|
495
|
+
| 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 |
|
|
496
|
+
| 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 |
|
|
497
|
+
|
|
498
|
+
Sources: Open Delivery `openapi.yaml` (read 2026-11-25), Rappi's portal
|
|
499
|
+
"Managing User Orders" (read 2026-11-25); iFood's developer portal answered 403,
|
|
500
|
+
so every iFood row but confirm and requestCancellation is ESTIMATED, in
|
|
501
|
+
`src/ifood/outbound.ts` and `src/ifood/normalize.ts` only.
|
|
502
|
+
|
|
355
503
|
## Pausing a store (FUT-4851)
|
|
356
504
|
|
|
357
505
|
When the store's kitchen passes its cap, the host closes the store on every
|
|
@@ -402,6 +550,8 @@ marketplace's sandbox.
|
|
|
402
550
|
| 99Food | `merchantStatus` has no end ("you don't know when the service will be re-established"): a switch | CONFIRMED for the standard | same |
|
|
403
551
|
| 99Food | The path is `/v1/merchantUpdate` (the spec files the webhook under the key `/v1/menuUpdated`, while its description and route table say `POST /v1/merchantUpdate`) | ESTIMATED | same |
|
|
404
552
|
| 99Food | 99Food implements `merchantUpdate`, and the token names the merchant (the body names none) | ESTIMATED | none public for 99Food |
|
|
553
|
+
| Keeta | `POST /v1/merchantUpdate/{merchantId}` with only `merchantStatus` (`AVAILABLE`/`UNAVAILABLE`) opens or closes the store "without reloading the menu"; 204, 400, 401, 503; `merchantStatus` beside `entityType` makes Keeta ignore the rest | CONFIRMED | [merchantUpdate](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/merchantupdate) |
|
|
554
|
+
| Keeta | No end, no id: a switch, offered only with `pauseByStoreSwitch: true`; the store's open state also depends on its hours and items | CONFIRMED | same |
|
|
405
555
|
| 99Food | The marketplace PULLING the status (`GET /v1/merchant/{id}/status`, host: the software) | Not used: the engine pushes, and serving the status is a host route this package does not ship | same spec |
|
|
406
556
|
|
|
407
557
|
### Failure codes
|
package/dist/99food/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder,
|
|
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-CYJzu1c9.js';
|
|
2
|
+
import { O as OpenDeliveryApiBaseUrls } from '../client-B4EQCRD_.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The words the 99Food adapter needs from its host, and nothing else.
|
|
@@ -7,12 +8,7 @@ import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, P as PullCatalog
|
|
|
7
8
|
* ships no language of its own. Two packs sit beside it (`./pt-BR`,
|
|
8
9
|
* `./en-US`); a host passes one by hand, or its own.
|
|
9
10
|
*/
|
|
10
|
-
/**
|
|
11
|
-
* The cancellation codes a merchant may send, verbatim from Open Delivery
|
|
12
|
-
* v1.7.1 (`RequestCancelled.code`). Pinned by the spec, not estimated. The two
|
|
13
|
-
* codes only the marketplace sends (`CONSUMER_CANCELLATION_REQUESTED`,
|
|
14
|
-
* `OTHER_CANCELLATION_REASON`) are not a store's to choose and are left out.
|
|
15
|
-
*/
|
|
11
|
+
/** The cancellation codes a merchant may send: Open Delivery v1.7.1's (`../open-delivery/reasons.ts`). */
|
|
16
12
|
declare const NINETY_NINE_FOOD_REASON_CODES: readonly ["SYSTEMIC_ISSUES", "DUPLICATE_APPLICATION", "UNAVAILABLE_ITEM", "RESTAURANT_WITHOUT_DELIVERY_PERSON", "OUTDATED_MENU", "ORDER_OUTSIDE_THE_DELIVERY_AREA", "BLOCKED_CUSTOMER", "OUTSIDE_DELIVERY_HOURS", "INTERNAL_DIFFICULTIES_OF_THE_RESTAURANT", "RISK_AREA", "DELIVERY_PROBLEM"];
|
|
17
13
|
type NinetyNineFoodReasonCode = (typeof NINETY_NINE_FOOD_REASON_CODES)[number];
|
|
18
14
|
interface NinetyNineFoodAdapterCopy {
|
|
@@ -23,37 +19,23 @@ interface NinetyNineFoodAdapterCopy {
|
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
/**
|
|
26
|
-
*
|
|
27
|
-
* grant, the order fetch, confirm
|
|
28
|
-
*
|
|
29
|
-
*
|
|
22
|
+
* 99Food's Open Delivery DIALECT: v1.7.1 as the standard writes it. The calls
|
|
23
|
+
* themselves (the grant, the order fetch, confirm, requestCancellation, the
|
|
24
|
+
* status steps) are `../open-delivery/`'s; this file only says where and how
|
|
25
|
+
* 99Food takes them.
|
|
26
|
+
*
|
|
27
|
+
* - Token: `POST /oauth/token`, form-encoded `client_id`, `client_secret`,
|
|
28
|
+
* `grant_type=client_credentials`.
|
|
29
|
+
* - Bodies: plain JSON; no request signature.
|
|
30
30
|
*
|
|
31
31
|
* The one thing the spec cannot pin is WHERE: Open Delivery standardizes the
|
|
32
32
|
* paths under each Ordering Application's own base URL, and 99Food gives its
|
|
33
33
|
* base URLs to a partner at onboarding. So the base URL per environment is
|
|
34
|
-
* the adapter's REQUIRED config, never a guessed default.
|
|
35
|
-
* 99Food: the HTTP client is the host's port, answered by a fake.
|
|
34
|
+
* the adapter's REQUIRED config, never a guessed default.
|
|
36
35
|
*/
|
|
37
36
|
/** Where 99Food serves Open Delivery, per environment (given at partner onboarding). */
|
|
38
|
-
type NinetyNineFoodApiBaseUrls =
|
|
37
|
+
type NinetyNineFoodApiBaseUrls = OpenDeliveryApiBaseUrls;
|
|
39
38
|
|
|
40
|
-
/**
|
|
41
|
-
* The 99Food adapter's INBOUND half, on Open Delivery v1.7.1 (Abrasel).
|
|
42
|
-
*
|
|
43
|
-
* Open Delivery splits what iFood sends at once: the webhook's `Event` names
|
|
44
|
-
* an order (`eventId`, `eventType`, `orderId`, `orderURL`, `createdAt`) and
|
|
45
|
-
* carries no body, and `GET /v1/orders/{orderId}` answers the `Order`. So
|
|
46
|
-
* there are two readers here: {@link normalizeOpenDeliveryEvent} for the
|
|
47
|
-
* webhook (a `CREATED` becomes `orderToFetch`), and
|
|
48
|
-
* {@link normalizeOpenDeliveryOrder} for what the engine's fetch job reads.
|
|
49
|
-
*
|
|
50
|
-
* Every shape below is the spec's (`components/schemas/Event`, `Order`,
|
|
51
|
-
* `Price`, `Address`), and every fixture in the tests is the spec's own
|
|
52
|
-
* example. Read defensively all the same: a missing field produces null, and
|
|
53
|
-
* only a missing order id refuses an event (it is the idempotency key).
|
|
54
|
-
*/
|
|
55
|
-
/** The provider id 99Food is registered under. Uppercase: the column's CHECK holds that shape. */
|
|
56
|
-
declare const NINETY_NINE_FOOD_PROVIDER = "NINETY_NINE_FOOD";
|
|
57
39
|
/**
|
|
58
40
|
* Verify a delivery: Open Delivery's `X-App-Signature` is "a lowercased
|
|
59
41
|
* hexadecimal HMAC signature of the webhook HTTP request body, using the
|
|
@@ -66,34 +48,29 @@ declare const NINETY_NINE_FOOD_PROVIDER = "NINETY_NINE_FOOD";
|
|
|
66
48
|
* CANCELLED for a known order id would otherwise cancel it.
|
|
67
49
|
*/
|
|
68
50
|
declare function verifyOpenDeliverySignature(rawBody: string, signature: string | null, webhookSecret: string | null): boolean;
|
|
51
|
+
|
|
69
52
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* -
|
|
74
|
-
* - `CANCELLATION_REQUEST_DENIED` refuses the store's request.
|
|
75
|
-
* - Everything else (`CONFIRMED`, `CANCELLATION_REQUESTED`, `DISPATCHED`, the
|
|
76
|
-
* consumer's `ORDER_CANCELLATION_REQUEST` handshake…) is understood and
|
|
77
|
-
* recorded, and acts on nothing: an IGNORED inbox row.
|
|
78
|
-
*
|
|
79
|
-
* The merchant is named by the `X-App-MerchantId` HEADER, not the body; the
|
|
80
|
-
* engine attributes a delivery by its URL's store slug, so it reads none.
|
|
53
|
+
* The 99Food adapter's INBOUND half: Open Delivery v1.7.1's readers
|
|
54
|
+
* (`../open-delivery/normalize.ts`), stamped with 99Food's provider id. 99Food
|
|
55
|
+
* departs from the standard in nothing inbound: the `X-App-Signature` is the
|
|
56
|
+
* standard's lowercase-hex HMAC-SHA256 of the body.
|
|
81
57
|
*/
|
|
58
|
+
/** The provider id 99Food is registered under. Uppercase: the column's CHECK holds that shape. */
|
|
59
|
+
declare const NINETY_NINE_FOOD_PROVIDER = "NINETY_NINE_FOOD";
|
|
60
|
+
|
|
61
|
+
/** Normalize one webhook `Event` (see `normalizeOpenDeliveryEventAs`). Null only when it names no order. */
|
|
82
62
|
declare function normalizeOpenDeliveryEvent(payload: unknown): NormalizedEvent | null;
|
|
83
|
-
/**
|
|
84
|
-
* Normalize one `Order` (the answer of `GET /v1/orders/{orderId}`). Null when
|
|
85
|
-
* it carries no id or no line.
|
|
86
|
-
*
|
|
87
|
-
* The total is `total.orderAmount`, "the final value of the order (itemsPrice
|
|
88
|
-
* + otherFees - discounts)": the buyer's receipt, gross. Open Delivery's
|
|
89
|
-
* `Order` states NO commission field, so `commissionCents` is null ("did not
|
|
90
|
-
* say"), never 0; the marketplace's cut arrives with its statement.
|
|
91
|
-
*/
|
|
63
|
+
/** Normalize one `Order` (see `normalizeOpenDeliveryOrderAs`). Null when it carries no id or no line. */
|
|
92
64
|
declare function normalizeOpenDeliveryOrder(order: unknown, options: {
|
|
93
65
|
missingStreetNumber: string;
|
|
94
66
|
}): NormalizedMarketplaceOrder | null;
|
|
95
67
|
|
|
96
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* The menu part of Open Delivery's `Merchant`: `menus`, `categories`,
|
|
70
|
+
* `items`, `itemOffers` (the price lives on the offer). Every item is a unit
|
|
71
|
+
* (`UN`) with a status, and every offer states `originalValue`: what both
|
|
72
|
+
* v1.7.1 and Keeta's v1.5.0 require.
|
|
73
|
+
*/
|
|
97
74
|
declare function openDeliveryMenuDocument(input: {
|
|
98
75
|
externalMerchantId: string;
|
|
99
76
|
entries: readonly CatalogueMenuEntry[];
|
|
@@ -136,6 +113,7 @@ declare function openDeliveryMenuDocument(input: {
|
|
|
136
113
|
};
|
|
137
114
|
}[];
|
|
138
115
|
};
|
|
116
|
+
|
|
139
117
|
/** 99Food's catalogue capability, for the base URLs it was given. */
|
|
140
118
|
declare function openDeliveryCatalogue(bases: NinetyNineFoodApiBaseUrls): PullCatalogue;
|
|
141
119
|
|