@12-apps/marketplace 1.8.0 → 1.10.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 +27 -1
- package/README.md +103 -9
- package/dist/99food/index.d.ts +30 -54
- package/dist/99food/index.js +60 -418
- package/dist/99food/index.js.map +1 -1
- package/dist/{chunk-BMCERPQX.js → chunk-2BA2EHNF.js} +16 -6
- package/dist/chunk-2BA2EHNF.js.map +1 -0
- package/dist/chunk-PYHNM47K.js +478 -0
- package/dist/chunk-PYHNM47K.js.map +1 -0
- package/dist/{chunk-6N2HEV3U.js → chunk-WVZ2IXFH.js} +3 -3
- package/dist/{chunk-NP4EYKPO.js → chunk-ZO4S3LF4.js} +5 -3
- package/dist/chunk-ZO4S3LF4.js.map +1 -0
- package/dist/client-B4EQCRD_.d.ts +20 -0
- package/dist/{engine-wmW-VuBL.d.ts → engine-DK3iV_Kk.d.ts} +91 -60
- package/dist/hono/index.d.ts +1 -1
- package/dist/hono/index.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -6
- 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 +4 -1
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/server.d.ts +1 -1
- package/dist/manifest/server.js +3 -3
- package/dist/server/index.d.ts +6 -2
- package/dist/server/index.js +3 -3
- package/package.json +14 -2
- package/prisma/marketplace.prisma +6 -0
- package/prisma/migrations/20261126230000_marketplace_menu_link_variation/migration.sql +11 -0
- package/src/99food/catalogue.ts +19 -89
- package/src/99food/copy.ts +4 -19
- package/src/99food/index.ts +28 -33
- package/src/99food/normalize.ts +11 -253
- package/src/99food/outbound.ts +29 -270
- package/src/99food/pause.ts +7 -22
- package/src/core/bulk.ts +34 -7
- package/src/core/ingest.ts +2 -1
- package/src/core/menu-links.ts +36 -6
- package/src/core/order-types.ts +74 -0
- package/src/core/ports.ts +23 -65
- package/src/index.ts +2 -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/server/mcp.ts +7 -2
- package/dist/chunk-BMCERPQX.js.map +0 -1
- package/dist/chunk-NP4EYKPO.js.map +0 -1
- /package/dist/{chunk-6N2HEV3U.js.map → chunk-WVZ2IXFH.js.map} +0 -0
package/ADOPTING.md
CHANGED
|
@@ -14,8 +14,9 @@ error at mount, never a default that quietly adopts another host's policy.
|
|
|
14
14
|
| `db` | `() => Promise<MarketplaceDb>` | The Prisma client generated from a schema that includes `prisma/marketplace.prisma`. Structural: the four delegates `marketplaceIntegration`, `marketplaceMenuLink`, `marketplaceInboxEvent`, `marketplaceAcceptance`, and the catalogue's `marketplaceCataloguePublication` (optional in the type; the catalogue calls need it). |
|
|
15
15
|
| `transaction` | `<T>(fn: (db: MarketplaceDb) => Promise<T>) => Promise<T>` | Prisma's interactive `$transaction`: run `fn` with the transaction's client; a throw rolls back. Every bulk write and every decision (admission + claim) is one transaction. |
|
|
16
16
|
| `order.admit` | `(request: { clientId; orderId; decision: "ACCEPT" \| "REJECT"; admission: MarketplaceAdmission; db: MarketplaceDb }) => Promise<{ admitted: true } \| { admitted: false; code: string; message: string; details?: unknown }>` | Judge each decision BEFORE its claim commits, inside the claim's transaction (`request.db` is the transaction's client: draw the stock there, and a refusal anywhere in the call rolls the draw back). `admission` is `{ admitStockPastZero?: boolean }` as the person stated it. Refuse with your own code: the route answers 409 with it (`MARKETPLACE_STOCK_ASK` and the short lines in `details`). Never called for an ingest or `recordStoreCancellation`. |
|
|
17
|
-
| `order.create` | `(clientId, order: NormalizedMarketplaceOrder, lines: readonly ResolvedOrderLine[], db: MarketplaceDb) => Promise<string>` | Create the host's own order from a normalized one; return its id. `lines[i].subjectRef` is the mapped catalog id or null (never refuse the order for a null). `db` is the ingest's transaction client: write the order through it, so the order and the acceptance row commit together (a lost race rolls the host's order back instead of leaving an orphan a redelivery would duplicate). |
|
|
17
|
+
| `order.create` | `(clientId, order: NormalizedMarketplaceOrder, lines: readonly ResolvedOrderLine[], db: MarketplaceDb) => Promise<string>` | Create the host's own order from a normalized one; return its id. `lines[i].subjectRef` is the mapped catalog id or null (never refuse the order for a null); `lines[i].variationRef` is the variation of it the SKU was mapped to, or null for the item alone. `db` is the ingest's transaction client: write the order through it, so the order and the acceptance row commit together (a lost race rolls the host's order back instead of leaving an orphan a redelivery would duplicate). |
|
|
18
18
|
| `order.catalogHas` | `(clientId, subjectRef) => Promise<boolean>` | Does this catalog id exist and belong to this tenant? Asked before a SKU is mapped. |
|
|
19
|
+
| `order.catalogHasVariation` (optional) | `(clientId, subjectRef, variationRef) => Promise<boolean>` | Is `variationRef` a variation of this tenant's catalog id `subjectRef`? Asked before a SKU is mapped to a variation, after `catalogHas`. Absent: a mapping that names a variation is refused (`CATALOG_ITEM_NOT_FOUND` at `variationId`). |
|
|
19
20
|
| `order.onAccepted` | `(clientId, orderId) => Promise<void>` | The store accepted, or the connection auto-accepts. Start whatever accepting means here (the ticket, the board). Runs after the commit and AFTER the confirm is queued; a throw is logged and cannot un-accept or lose the confirm. Atomic work (the stock draw) belongs in `admit`. |
|
|
20
21
|
| `order.mayAutoAccept` | OPTIONAL. `(clientId) => Promise<boolean>` | May a NEW order of this tenant be accepted automatically? Asked once per order, before the ingest's transaction, and only when the connection auto-accepts (never for a redelivery). `false` declines the automatic acceptance: the order lands exactly as with auto-accept off (AWAITING on the clock, no confirm queued, no `onAccepted`) and a person decides it; the order is never refused for it. A throw is logged and declines too. Not bound: every auto-accept proceeds, as before. It sits on every order's ingest, so answer it from something already in hand rather than a fresh query. |
|
|
21
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. |
|
|
@@ -292,3 +293,28 @@ if you want one). The `MarketplaceDb.marketplaceStorePause` delegate is
|
|
|
292
293
|
OPTIONAL in the type, so a 1.x host compiles before it migrates; `pauseStore`
|
|
293
294
|
and `resumeStore` throw naming the migration until it does, and
|
|
294
295
|
`availabilityState` reads every marketplace OPEN.
|
|
296
|
+
|
|
297
|
+
## 8. Mapping a SKU to a variation (FUT-4927)
|
|
298
|
+
|
|
299
|
+
A marketplace SKU usually names one flavour or size of an item. A link can now
|
|
300
|
+
carry that variation beside the catalog id: `variationId` on
|
|
301
|
+
`upsertMenuLinks` / `setMenuLink` rows, on `PUT …/menu-links` and its MCP
|
|
302
|
+
tool, and on every link view. Absent or null maps the item alone, exactly as
|
|
303
|
+
before; a write always sets both halves, so re-mapping to the item clears a
|
|
304
|
+
variation and an unmap clears both. A variation on an unmap is refused.
|
|
305
|
+
|
|
306
|
+
**The port.** Bind `order.catalogHasVariation(clientId, subjectRef,
|
|
307
|
+
variationRef)` to answer whether the variation is one of that item's and the
|
|
308
|
+
tenant's. Without it every mapping that names a variation is refused, and
|
|
309
|
+
mapping to the item works as it did.
|
|
310
|
+
|
|
311
|
+
**The line.** `ResolvedOrderLine.variationRef` is the mapped variation, or
|
|
312
|
+
null. Write it on the order line with `subjectRef`; a host that ignores it
|
|
313
|
+
keeps selling the item alone.
|
|
314
|
+
|
|
315
|
+
**The database.** Migration `20261126230000_marketplace_menu_link_variation`
|
|
316
|
+
adds the nullable `marketplace_menu_links.variation_id`: additive, no foreign
|
|
317
|
+
key, every existing link stays the item alone. The engine selects the column,
|
|
318
|
+
so a Prisma client generated before the migration throws on the unknown
|
|
319
|
+
`variationId`: on the bump, sync the partial, run `prisma generate` and apply
|
|
320
|
+
the migration together.
|
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";
|
|
@@ -42,7 +42,7 @@ engine code (`src/__tests__/second-adapter.test.ts`).
|
|
|
42
42
|
| **Ingest** | Idempotent on `(provider, externalOrderId)`. Unmapped SKUs are rows on the attention list, never a rejection. The deadline is stamped at ingest; auto-accept is born accepted in one write and queues the confirm, unless the host's optional `order.mayAutoAccept` declines it, and then the order lands AWAITING as if auto-accept were off. |
|
|
43
43
|
| **Acceptance clock** | `AWAITING → ACCEPTED | REJECTED | EXPIRED`, every transition predicated on the current state. The sweep never touches an accepted order. |
|
|
44
44
|
| **Decisions** | Many at once, all-or-nothing: accept (with the person's admission and a preparation time), or refuse with a reason code validated against the adapter's own list and, for a reason that needs them, the order's offending SKUs. The host admits each decision inside the claim's transaction (`order.admit`: the stock ask, the draw). For a host that binds `onCancellationConfirmed`, the store's refusal or cancel is a REQUEST: only the request moves, the order stays as it was until the marketplace answers, and the host hears the answer through the optional `onCancellationConfirmed` / `onCancellationFailed` (REFUSED or TIMEOUT). `suggestReason` preselects the item-unavailable reason when the host says stock is short. |
|
|
45
|
-
| **SKU map** | External SKU → host catalog id, every SKU ever seen a row; mapping checks the id is the tenant's. |
|
|
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
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. |
|
|
@@ -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)
|
|
@@ -397,11 +489,11 @@ then it claims the row (STORE, SENDING, unique per (order, step)) and calls
|
|
|
397
489
|
FAILED. A SENDING row left by a dead job is re-queued by the outbound sweep
|
|
398
490
|
after 10 minutes and failed after 24 hours.
|
|
399
491
|
|
|
400
|
-
| step | iFood (ESTIMATED) | 99Food (Open Delivery v1.7.1) | Rappi |
|
|
401
|
-
|
|
402
|
-
| READY | `POST /orders/{id}/readyToPickup`, not for a merchant bag | `POST /v1/orders/{id}/readyForPickup` | `POST /orders/{id}/ready-for-pickup` (ESTIMATED verb; MANUAL-notification stores only) |
|
|
403
|
-
| DISPATCHED | `POST /orders/{id}/dispatch`, merchant bag only | `POST /v1/orders/{id}/dispatch`, merchant bag only | none |
|
|
404
|
-
| HANDED_OVER | none | merchant bag `delivered`, take-out `pickedUp`, fleet none | none |
|
|
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 |
|
|
405
497
|
|
|
406
498
|
Sources: Open Delivery `openapi.yaml` (read 2026-11-25), Rappi's portal
|
|
407
499
|
"Managing User Orders" (read 2026-11-25); iFood's developer portal answered 403,
|
|
@@ -458,6 +550,8 @@ marketplace's sandbox.
|
|
|
458
550
|
| 99Food | `merchantStatus` has no end ("you don't know when the service will be re-established"): a switch | CONFIRMED for the standard | same |
|
|
459
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 |
|
|
460
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 |
|
|
461
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 |
|
|
462
556
|
|
|
463
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,36 +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
|
-
* - `DISPATCHED` and `CONCLUDED` are lifecycle events (FUT-4653): the engine
|
|
76
|
-
* asks the host to move the order forward, when the store follows them.
|
|
77
|
-
* - Everything else (`CONFIRMED`, `CANCELLATION_REQUESTED`, the
|
|
78
|
-
* consumer's `ORDER_CANCELLATION_REQUEST` handshake…) is understood and
|
|
79
|
-
* recorded, and acts on nothing: an IGNORED inbox row.
|
|
80
|
-
*
|
|
81
|
-
* The merchant is named by the `X-App-MerchantId` HEADER, not the body; the
|
|
82
|
-
* 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.
|
|
83
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. */
|
|
84
62
|
declare function normalizeOpenDeliveryEvent(payload: unknown): NormalizedEvent | null;
|
|
85
|
-
/**
|
|
86
|
-
* Normalize one `Order` (the answer of `GET /v1/orders/{orderId}`). Null when
|
|
87
|
-
* it carries no id or no line.
|
|
88
|
-
*
|
|
89
|
-
* The total is `total.orderAmount`, "the final value of the order (itemsPrice
|
|
90
|
-
* + otherFees - discounts)": the buyer's receipt, gross. Open Delivery's
|
|
91
|
-
* `Order` states NO commission field, so `commissionCents` is null ("did not
|
|
92
|
-
* say"), never 0; the marketplace's cut arrives with its statement.
|
|
93
|
-
*/
|
|
63
|
+
/** Normalize one `Order` (see `normalizeOpenDeliveryOrderAs`). Null when it carries no id or no line. */
|
|
94
64
|
declare function normalizeOpenDeliveryOrder(order: unknown, options: {
|
|
95
65
|
missingStreetNumber: string;
|
|
96
66
|
}): NormalizedMarketplaceOrder | null;
|
|
97
67
|
|
|
98
|
-
/**
|
|
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
|
+
*/
|
|
99
74
|
declare function openDeliveryMenuDocument(input: {
|
|
100
75
|
externalMerchantId: string;
|
|
101
76
|
entries: readonly CatalogueMenuEntry[];
|
|
@@ -138,6 +113,7 @@ declare function openDeliveryMenuDocument(input: {
|
|
|
138
113
|
};
|
|
139
114
|
}[];
|
|
140
115
|
};
|
|
116
|
+
|
|
141
117
|
/** 99Food's catalogue capability, for the base URLs it was given. */
|
|
142
118
|
declare function openDeliveryCatalogue(bases: NinetyNineFoodApiBaseUrls): PullCatalogue;
|
|
143
119
|
|