@12-apps/marketplace 1.8.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/README.md +102 -8
- 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-PYHNM47K.js +478 -0
- package/dist/chunk-PYHNM47K.js.map +1 -0
- package/dist/client-B4EQCRD_.d.ts +20 -0
- 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/package.json +14 -2
- 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/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/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)
|
|
@@ -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
|
|