@12-apps/marketplace 1.10.0 → 1.12.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 +126 -1
- package/README.md +100 -1
- package/dist/99food/index.d.ts +2 -2
- package/dist/99food/index.js +2 -2
- package/dist/{adapter-CYJzu1c9.d.ts → adapter-nUyZpLzz.d.ts} +448 -173
- package/dist/{chunk-2BA2EHNF.js → chunk-45ZVN5XI.js} +316 -42
- package/dist/chunk-45ZVN5XI.js.map +1 -0
- package/dist/{chunk-PYHNM47K.js → chunk-L6FG6T4S.js} +2 -2
- package/dist/{chunk-HEXLCTOG.js → chunk-LACBT6NC.js} +1 -1
- package/dist/chunk-LACBT6NC.js.map +1 -0
- package/dist/{chunk-WVZ2IXFH.js → chunk-MIPNQ7X5.js} +190 -12
- package/dist/chunk-MIPNQ7X5.js.map +1 -0
- package/dist/chunk-SGOTN5PX.js +345 -0
- package/dist/chunk-SGOTN5PX.js.map +1 -0
- package/dist/{client-B4EQCRD_.d.ts → client-Ctas7WCS.d.ts} +1 -1
- package/dist/{engine-DK3iV_Kk.d.ts → engine-CIy9P7Cq.d.ts} +149 -8
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +3 -3
- package/dist/ifood/index.d.ts +10 -2
- package/dist/ifood/index.js +297 -25
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +23 -4
- package/dist/index.js +424 -84
- package/dist/index.js.map +1 -1
- package/dist/keeta/index.d.ts +2 -18
- package/dist/keeta/index.js +12 -3
- package/dist/keeta/index.js.map +1 -1
- package/dist/manifest/index.d.ts +219 -1
- 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 +1 -1
- package/dist/rappi/index.js +1 -1
- package/dist/server/en-US.d.ts +13 -0
- package/dist/server/en-US.js +13 -0
- package/dist/server/en-US.js.map +1 -1
- package/dist/server/index.d.ts +241 -7
- package/dist/server/index.js +3 -3
- package/dist/server/pt-BR.d.ts +13 -0
- package/dist/server/pt-BR.js +13 -0
- package/dist/server/pt-BR.js.map +1 -1
- package/package.json +1 -1
- package/prisma/marketplace.prisma +41 -0
- package/prisma/migrations/20261127090000_marketplace_app_link/migration.sql +81 -0
- package/src/core/adapter.ts +27 -0
- package/src/core/bulk.ts +43 -8
- package/src/core/courier-port.ts +100 -0
- package/src/core/courier.ts +153 -0
- package/src/core/engine.ts +63 -4
- package/src/core/integration.ts +60 -32
- package/src/core/lifecycle.ts +27 -4
- package/src/core/link-store.ts +170 -0
- package/src/core/linking-port.ts +100 -0
- package/src/core/linking.ts +363 -0
- package/src/core/merchant-claim.ts +106 -0
- package/src/core/outbound-queue.ts +24 -11
- package/src/core/outbound.ts +8 -6
- package/src/core/pickup-code.ts +136 -0
- package/src/core/pipeline.ts +15 -6
- package/src/core/ports.ts +26 -1
- package/src/core/status-store.ts +2 -3
- package/src/core/types.ts +56 -4
- package/src/ifood/courier.ts +210 -0
- package/src/ifood/index.ts +8 -0
- package/src/ifood/linking.ts +170 -0
- package/src/ifood/normalize.ts +7 -0
- package/src/ifood/outbound.ts +10 -3
- package/src/index.ts +30 -0
- package/src/keeta/normalize.ts +21 -6
- package/src/server/copy.ts +20 -2
- package/src/server/en-US.ts +13 -0
- package/src/server/index.ts +1 -1
- package/src/server/link-routes.ts +140 -0
- package/src/server/mcp-link.ts +103 -0
- package/src/server/mcp.ts +6 -2
- package/src/server/pt-BR.ts +13 -0
- package/src/server/routes.ts +5 -2
- package/src/server/webhook.ts +86 -0
- package/dist/chunk-2BA2EHNF.js.map +0 -1
- package/dist/chunk-HEXLCTOG.js.map +0 -1
- package/dist/chunk-WVZ2IXFH.js.map +0 -1
- package/dist/chunk-ZO4S3LF4.js +0 -254
- package/dist/chunk-ZO4S3LF4.js.map +0 -1
- /package/dist/{chunk-PYHNM47K.js.map → chunk-L6FG6T4S.js.map} +0 -0
package/ADOPTING.md
CHANGED
|
@@ -22,11 +22,13 @@ error at mount, never a default that quietly adopts another host's policy.
|
|
|
22
22
|
| `order.onRefused` | `(clientId, orderId, reason: "REJECTED" \| "EXPIRED" \| "CANCELLED") => Promise<void>` | Refuse/cancel the host order: the store refused on the clock, the clock lapsed, or the marketplace cancelled. After the commit and after the cancellation request is queued; a throw on a decision is logged. NOT called for `recordStoreCancellation`. A host that binds `onCancellationConfirmed` (request first) does not get `"REJECTED"` from `decide` either, nor `"CANCELLED"` for a cancellation the store asked for: `onCancellationConfirmed` replaces both. |
|
|
23
23
|
| `order.onCancellationConfirmed` | OPTIONAL — binding it OPTS IN to request first. `(clientId, orderId) => Promise<void>` | The marketplace CONFIRMED the store's own cancellation request (its event, or the job's answer for a marketplace that answers in the response); the row is REJECTED/CONFIRMED by then. Run the host's cancel here. Bound: the store's refusals and cancels (`decide` REJECT, `recordStoreCancellation`) only REQUEST the cancellation and keep the order as it was until this is called, once (a redelivered confirmation calls nothing), INSTEAD of `onRefused`. Not bound (a 1.0.0 host): everything as 1.0.0 — REJECTED at request time, `onRefused(…, "REJECTED")` from `decide`, and `onRefused(…, "CANCELLED")` on the confirmation. A throw is logged. |
|
|
24
24
|
| `order.onCancellationFailed` | OPTIONAL. `(clientId, orderId, reason: "REFUSED" \| "TIMEOUT") => Promise<void>` | The store's request FAILED: REFUSED (the marketplace's refusal event, the job's 4xx, its last attempt dying, or — request first — a marketplace whose API cannot take it, at once) or TIMEOUT (the outbound sweep, past the marketplace's answer window, or the 24-hour give-up). Called once, by the path that moved the row. Request first: the order stays as it was (AWAITING or ACCEPTED) and may be accepted again; show the adapter's app link and tell the person. A throw is logged. |
|
|
25
|
+
| `order.onCourier` | OPTIONAL (FUT-5665). `(clientId, orderId, event: NormalizedCourierEvent, facts: { deliveredBy; at }) => Promise<"recorded" \| "unchanged" \| { kind: "unchanged"; reason }>` | The marketplace's courier moved (assigned, on the way, at the counter, collected, returning, returned): store the facts on the order, never move it. Asked for an ACCEPTED order only; idempotent (the reconcile pass may re-run a row). Section 10. |
|
|
26
|
+
| `order.onPickupCodeValidated` | OPTIONAL (FUT-5665). `(clientId, orderId, validation: "VALID" \| "INVALID" \| "UNVERIFIED") => Promise<void>` | The marketplace's verdict on the code sent with `validatePickupCode`, after the hand-over committed. `INVALID` warns, moves nothing. A throw is logged. Section 10. |
|
|
25
27
|
| `order.summarize` | `(clientId, orderIds: readonly string[]) => Promise<Map<string, MarketplaceOrderSummary>>` | The queue's host facts in one read: `{ buyerName, totalCents, unmappedLines, createdAt }`. |
|
|
26
28
|
| `secrets` | `{ seal(plaintext): string; open(sealed): string }` | Seal and open the credential blob with the host's key. `open` THROWS on a blob that will not open. |
|
|
27
29
|
| `http` | `(req: MarketplaceHttpRequest) => Promise<MarketplaceHttpResponse>` | The only way the engine reaches a marketplace. Answer any status; throw only when no answer arrived (timeout, network). The host owns the timeout, proxy and CA. `method` is `GET`, `POST`, `PUT` or, since the catalogue (1.2), `PATCH`. |
|
|
28
30
|
| `audit` | `{ record(entry: { clientId; actorId: string \| null; action: "marketplace.integration.archive" \| "marketplace.integration.unarchive"; provider; reason: string \| null; at: Date }, db: MarketplaceDb): Promise<void> }` | Every archive and unarchive of a connection, INSIDE the same transaction: write the line through `db`, so an archive never lands without its line and a failing audit rolls the archive back. `actorId` is `MarketplaceActor.userId`. |
|
|
29
|
-
| `enqueue` | `{ enqueue(name, payload, { dedupeKey? }) => Promise<{ enqueued: boolean; reason?: string }> }` | The wiring `JobsEnqueuePort`. Never throws. The engine queues only its own three on-demand jobs: `marketplace.outbound` (`{ clientId, orderId, action }`, dedupe key `marketplace.outbound:<action>:<orderId
|
|
31
|
+
| `enqueue` | `{ enqueue(name, payload, { dedupeKey? }) => Promise<{ enqueued: boolean; reason?: string }> }` | The wiring `JobsEnqueuePort`. Never throws. The engine queues only its own three on-demand jobs: `marketplace.outbound` (`{ clientId, orderId, action }`, dedupe key `marketplace.outbound:<action>:<orderId>`; `validatePickupCode` adds `code`, the one non-identifier a payload carries, a short-lived code no log line prints, and keys on the hand-over's instant), `marketplace.fetch-order` (`{ clientId, inboxId }`, dedupe key `marketplace.fetch-order:<inboxId>`) and `marketplace.catalogue` (`{ clientId, publicationId, action }`, dedupe key `marketplace.catalogue:<action>:<publicationId>:<asked at, ms>`); the sweeps re-queue each under a key of their own. |
|
|
30
32
|
| `clock` | `{ now(): Date }` | What time it is. |
|
|
31
33
|
| `logger` | `{ info, warn, error }` | The wiring `LoggerPort`; bind `assembled.loggers["@12-apps/marketplace"]`. |
|
|
32
34
|
| `publishChanged` | `(clientId) => void` | Tell the staff surfaces something moved. Fire-and-forget. |
|
|
@@ -34,6 +36,7 @@ error at mount, never a default that quietly adopts another host's policy.
|
|
|
34
36
|
| `reconcileBatchSize` | `number` | Stored deliveries one reconciliation pass re-runs (origin: 50). |
|
|
35
37
|
| `maxInboxAttempts` | `number` | Re-runs before a stored delivery is retired (origin: 5). |
|
|
36
38
|
| `catalogue` | OPTIONAL. `{ items(clientId, productIds) => Promise<Map<string, CatalogueItem>>; image(url) => Promise<{ contentType; base64 } \| null> }` | Catalogue publishing (1.2, FUT-4768). `items` maps the host's products into `{ name, description, imageUrl, categoryName, priceCents }` (the store's price, smallest unit; the photo an absolute https URL that CHANGES when the photo changes, such as a content hash or upload id in it: a marketplace's uploaded copy is reused while the URL is the same), keyed by product id; a missing id is a product that no longer exists. Called at publish (to check it exists) and by the job when it sends, so what goes out is the product as it is then. `image` reads a photo's bytes for a marketplace that takes an upload (iFood); null publishes without a photo. Absent: every catalogue call answers `UNSUPPORTED`. |
|
|
39
|
+
| `appCredentials` | OPTIONAL. `(provider, environment) => { clientId; clientSecret; webhookSecret } \| null` (sync or async) | The software's OWN app on each marketplace, for linking a store without its own credentials (FUT-5613, section 9). Absent or null: linking is unavailable there and the per-store credentials work as before. |
|
|
37
40
|
| `cancellationWindowMs` | OPTIONAL. `number` | For a host that requests first (binds `onCancellationConfirmed`): how long a store's cancellation request may wait (PENDING: not yet delivered, or REQUESTED: delivered and unanswered) before the outbound sweep fails it as TIMEOUT, for every adapter; a PENDING request's retries stop with it. A 1.0.0 host has no window: its requests are re-queued and given up after 24 hours, as before. Absent: each adapter's `capabilities.cancellationAnswerWindowMs` (iFood: 5 minutes, estimated); an adapter with none is given up on only after 24 hours. |
|
|
38
41
|
|
|
39
42
|
Plus `adapters: readonly MarketplaceAdapter[]` — one per marketplace the host
|
|
@@ -77,6 +80,8 @@ export const engine = createMarketplaceEngine({
|
|
|
77
80
|
| `catalogueState({ clientId, productIds, providers? })` | The product page's read: one row per marketplace the product was ever switched on for, in one query. Draw PUBLISHED as "in the catalogue" (with your sentence for a `warningCode`, IMAGE_TOO_LARGE or IMAGE_REFUSED: it went out without its photo), PUBLISHING / WITHDRAWING as "sending…" (switch disabled), FAILED with your own sentence for its `failureCode` (REFUSED, UNAVAILABLE, TIMEOUT, NOT_CONNECTED, CREDENTIALS, PRODUCT_GONE, UNSUPPORTED, INTERNAL), the marketplace's own words from `failureReason` beside a REFUSED, and a retry (`publish` or `withdraw` again, per `failedAction`). The engine writes no sentence a person reads. No row is OFF. |
|
|
78
81
|
| `catalogueDocument({ clientId, provider, options: { menuName, currency } })` | PULL marketplaces only (99Food): the menu part of the document the marketplace reads. Serve it from the route the marketplace pulls (Open Delivery's `GET /v1/merchant`), merged into the rest of that document, which is the host's (`id`, `status`, `lastUpdate`, `TTL`, `basicInfo`, `services`). The menu's name and the currency are the host's words. |
|
|
79
82
|
| `informStatus({ clientId, orderId, step, at, delayMs? })` | An order reached `READY`, `DISPATCHED` or `HANDED_OVER` (FUT-4653). One enqueue, no statement, never throws: call it after the move's commit, from the one place every writer of that step passes, gated on the order being a marketplace's. `at` is the move's own timestamp (it makes the job's dedupe key, so a re-dispatch after an undo is a new job); `delayMs` is the board's undo window for a dispatch. Your `enqueue` port must pass `options.delayMs` on. The job decides everything else (see the README). |
|
|
83
|
+
| `validatePickupCode({ clientId, orderId, code, at })` | After the host's own hand-over of a marketplace-courier bag committed, with the code the store checked locally (FUT-5665). One enqueue, never throws. Section 10. |
|
|
84
|
+
| `courierTracking({ clientId, orderId })` | From a job, at most once per 30 s per order (iFood's rate): where the marketplace's courier is (`pickupEtaAt`, the "arrives at" time). Calls the marketplace at once; never on a tap or a screen load. Section 10. |
|
|
80
85
|
| `ingest(...)`, `deliver(...)` | A producer that hands over an order directly; the webhook does `deliver` for you. |
|
|
81
86
|
|
|
82
87
|
A host never writes `provider === "IFOOD"`. A capability is asked of
|
|
@@ -240,6 +245,15 @@ not composed the model still compiles, and the two paths then do nothing.
|
|
|
240
245
|
switches over either exhaustively adds the case; allow `"status"` in any
|
|
241
246
|
action allow-list in front of the outbound job.
|
|
242
247
|
|
|
248
|
+
`20261127090000_marketplace_app_link` (FUT-5613) adds
|
|
249
|
+
`marketplace_integrations.auth_mode` (NOT NULL DEFAULT 'CREDENTIALS', CHECKed
|
|
250
|
+
CREDENTIALS | LINKED: every existing connection stays the store's own app) and
|
|
251
|
+
`marketplace_link_attempts`, one linking in progress per (store, marketplace)
|
|
252
|
+
with its sealed verifier, environment CHECKed and provider shape-checked.
|
|
253
|
+
Additive. Compose it with the schema in the same change as the engine bump:
|
|
254
|
+
the engine selects `auth_mode`. `MarketplaceDb.marketplaceLinkAttempt` is
|
|
255
|
+
optional in the type; without it linking reports itself unavailable.
|
|
256
|
+
|
|
243
257
|
## 6. What stays the host's
|
|
244
258
|
|
|
245
259
|
The stock draw at the acceptance, the settlement effects, the board's and the
|
|
@@ -318,3 +332,114 @@ key, every existing link stays the item alone. The engine selects the column,
|
|
|
318
332
|
so a Prisma client generated before the migration throws on the unknown
|
|
319
333
|
`variationId`: on the bump, sync the partial, run `prisma generate` and apply
|
|
320
334
|
the migration together.
|
|
335
|
+
|
|
336
|
+
## 9. Linking a store through the software's own app
|
|
337
|
+
|
|
338
|
+
The flow and its routes are in the README ("Linking a store through the
|
|
339
|
+
software's own app"). What the host binds and decides:
|
|
340
|
+
|
|
341
|
+
- **`appCredentials`** (OPTIONAL port): `(provider, environment) =>
|
|
342
|
+
{ clientId, clientSecret, webhookSecret } | null`, sync or async, read at
|
|
343
|
+
each use (a rotation reaches every linked store at once). Answer it from the
|
|
344
|
+
host's secret store; never from a store's row. Null or unbound: the screen
|
|
345
|
+
shows the per-store form, as before.
|
|
346
|
+
- **The app's webhook**: register `…/webhooks/marketplace/IFOOD` (under the
|
|
347
|
+
host's mount) as the app's one webhook address on iFood's developer portal,
|
|
348
|
+
iFood signs it with the app's client secret, so `webhookSecret` may be left
|
|
349
|
+
null; pass it only to verify with another key.
|
|
350
|
+
- **The screen** is the host's: `GET …/link` says whether to offer it and
|
|
351
|
+
restores a code in progress after a reload; `start`, `finish` and, when the
|
|
352
|
+
grant covers several iFood stores, `merchants` and `merchant`. Each refusal
|
|
353
|
+
answers a `code` (`UNAVAILABLE`, `NO_LINK_IN_PROGRESS`, `LINK_EXPIRED`,
|
|
354
|
+
`CODE_REFUSED`, `MARKETPLACE_REFUSED`, `NOT_LINKED`, `UNKNOWN_MERCHANT`,
|
|
355
|
+
`MERCHANT_TAKEN`; 503 `MARKETPLACE_UNREACHABLE`) and the pack's sentence
|
|
356
|
+
(`copy.link`, optional in the type, carried by both shipped packs).
|
|
357
|
+
- **Disconnect** is the existing archive (`PUT …/marketplace`, operation
|
|
358
|
+
`archive`): the row is kept; linking again unarchives it with its audit line.
|
|
359
|
+
- **A view** gains `authMode`; a host that switches on it treats an absent
|
|
360
|
+
value as `CREDENTIALS`.
|
|
361
|
+
|
|
362
|
+
## 10. The marketplace's own courier and the pickup code (FUT-5665)
|
|
363
|
+
|
|
364
|
+
When the marketplace's fleet carries a bag (`deliveredBy: "MARKETPLACE"`;
|
|
365
|
+
iFood's `delivery.deliveredBy = IFOOD`), the engine reports where its courier
|
|
366
|
+
is, carries the code the courier states at the counter, checks that code with
|
|
367
|
+
the marketplace after the hand-over, and reads the courier's tracking. All of
|
|
368
|
+
it is additive: every new port and field is optional, nothing below needs an
|
|
369
|
+
engine migration, and a host that binds none of the new hooks keeps its 1.x
|
|
370
|
+
behaviour, with one exception: a host that binds `onLifecycle` now receives
|
|
371
|
+
`lifecycle: "COLLECTED"` (iFood `CLT`, Keeta `ORDER_COLLECTED`, for a bag the
|
|
372
|
+
marketplace carries; before, IGNORED as `no order body`). A switch with a
|
|
373
|
+
default answers `unchanged`; an exhaustive switch must add the case, as for
|
|
374
|
+
`status` in FUT-4653.
|
|
375
|
+
|
|
376
|
+
**What the host binds.**
|
|
377
|
+
|
|
378
|
+
- `order.onCourier(clientId, orderId, event, facts)`: a courier event of an
|
|
379
|
+
ACCEPTED order (an event before its order is deferred and re-run by the
|
|
380
|
+
reconcile pass; another status is IGNORED). `event` is
|
|
381
|
+
`NormalizedCourierEvent`: `step` (`ASSIGNED`, `GOING_TO_ORIGIN`,
|
|
382
|
+
`ARRIVED_AT_ORIGIN`, `COLLECTED`, `RETURNING_TO_ORIGIN`,
|
|
383
|
+
`RETURNED_TO_ORIGIN`), `at` (the event's instant or null), `courier` (on
|
|
384
|
+
`ASSIGNED`: `{ name, photoUrl, vehicle }`, the photo an https URL or null,
|
|
385
|
+
the vehicle `MOTORCYCLE` / `BICYCLE` / `CAR` / `OTHER` or null) and
|
|
386
|
+
`returning` (`RETURNING`, `RETURNED` or null). `facts` is
|
|
387
|
+
`{ deliveredBy, at }`, `at` falling back to the engine's clock. Store what
|
|
388
|
+
the card shows (name, photo, vehicle, arrived at, collected at, returning)
|
|
389
|
+
on your own order and answer `"recorded"`; the engine settles the inbox row
|
|
390
|
+
PROCESSED and calls `publishChanged`. It is NOT gated on `followStatus`: a
|
|
391
|
+
fact moves nothing. Unbound: courier events stay IGNORED (`no order body on
|
|
392
|
+
ADR`).
|
|
393
|
+
- `order.onLifecycle` now also gets `lifecycle: "COLLECTED"` (iFood `CLT`,
|
|
394
|
+
Keeta `ORDER_COLLECTED`). For a fleet bag treat it as `DISPATCHED`: the
|
|
395
|
+
courier has the bag, so move it to handed over, forward only, with no code
|
|
396
|
+
asked. A `COLLECTED` of a bag the marketplace does not carry is IGNORED by
|
|
397
|
+
the engine, never noted and never sent to the host. The engine notes it as
|
|
398
|
+
the marketplace's HANDED_OVER, and treats a `COLLECTED` after your own informed HANDED_OVER as an echo. The courier's
|
|
399
|
+
facts reach `onCourier` first; when the lifecycle moves nothing the row is
|
|
400
|
+
settled by the courier's answer.
|
|
401
|
+
- `order.onPickupCodeValidated(clientId, orderId, validation)`: `VALID`,
|
|
402
|
+
`INVALID` (warn on the order; the hand-over stands) or `UNVERIFIED` (a final
|
|
403
|
+
4xx, retries that ran out, no connection: no verdict). Unbound: the verdict
|
|
404
|
+
is logged only.
|
|
405
|
+
|
|
406
|
+
**What the host stores from the order.** `NormalizedMarketplaceOrder.pickupCode`
|
|
407
|
+
(iFood `delivery.pickupCode`, null when the marketplace asks none) arrives in
|
|
408
|
+
`order.create`. Keep it on your order; the hand-over compares the typed code
|
|
409
|
+
with it LOCALLY, with no call to the marketplace. No code on the order: hand
|
|
410
|
+
over as before.
|
|
411
|
+
|
|
412
|
+
**What the host calls.**
|
|
413
|
+
|
|
414
|
+
- `engine.validatePickupCode({ clientId, orderId, code, at })` AFTER the
|
|
415
|
+
hand-over's commit, with the code the store checked; `at` is the
|
|
416
|
+
hand-over's instant (the job's key). One enqueue of `marketplace.outbound`,
|
|
417
|
+
action `validatePickupCode`; never throws, false when the queue refused
|
|
418
|
+
(nothing re-queues it: the marketplace's check is its half, never a gate on
|
|
419
|
+
yours). The job skips, with no call, a marketplace with no `courier` API, an
|
|
420
|
+
order no longer ACCEPTED, a bag not carried by the marketplace's courier and
|
|
421
|
+
an empty code; a 5xx or timeout is retried (3 attempts from 30 s) and the
|
|
422
|
+
last answers `UNVERIFIED`.
|
|
423
|
+
- `engine.courierTracking({ clientId, orderId })` from a job of yours while
|
|
424
|
+
the courier comes to the store, at most once per 30 s per order. Answers
|
|
425
|
+
`{ kind: "tracking", tracking: { pickupEtaAt, deliveryEtaAt, latitude,
|
|
426
|
+
longitude, trackedAt } }`, `{ kind: "notYet" }` (iFood's 404 before
|
|
427
|
+
`ASSIGN_DRIVER`), `{ kind: "unsupported", reason }` with no call (unknown
|
|
428
|
+
order, no `courier` API, a bag the store carries), or the `refused` /
|
|
429
|
+
`retry` shapes of an outbound call. Store `pickupEtaAt` as "chega em"; the
|
|
430
|
+
engine stores nothing.
|
|
431
|
+
|
|
432
|
+
**What a marketplace offers.** `engine.adapter(provider).courier` is present
|
|
433
|
+
when it has the two calls (iFood only). Courier events: iFood (all six;
|
|
434
|
+
the two return events by long name only); Keeta `RIDER_ARRIVED_AT_STORE` and
|
|
435
|
+
`ORDER_COLLECTED`, ESTIMATED, with no rider identity; 99Food and Rappi none
|
|
436
|
+
(Open Delivery's standard events and Rappi's documented ones name no courier
|
|
437
|
+
step).
|
|
438
|
+
|
|
439
|
+
**Migration-free on the engine's side.** No engine table changes:
|
|
440
|
+
`COLLECTED` is noted under the existing `HANDED_OVER` step of
|
|
441
|
+
`marketplace_status_updates`. The courier facts, the pickup code and the last
|
|
442
|
+
ETA are the host's own columns.
|
|
443
|
+
|
|
444
|
+
**Copy.** The engine adds no copy key; every sentence ("Código não confere",
|
|
445
|
+
"Voltando para a loja") is the host's.
|
package/README.md
CHANGED
|
@@ -226,6 +226,69 @@ They live only in `src/ifood/outbound.ts` and `src/ifood/copy.ts`, whose
|
|
|
226
226
|
headers say so, so the homologation run corrects two files. Tests never reach
|
|
227
227
|
iFood: the HTTP client is the host's port.
|
|
228
228
|
|
|
229
|
+
## Linking a store through the software's own app (FUT-5613)
|
|
230
|
+
|
|
231
|
+
A store connects iFood WITHOUT typing a client id, a secret, a webhook key or a
|
|
232
|
+
webhook address: it authorizes the software's own iFood app (iFood's
|
|
233
|
+
"distributed app") on iFood's portal. The host's screen is three steps; the
|
|
234
|
+
engine supplies each one:
|
|
235
|
+
|
|
236
|
+
| step | engine | route (`marketplace:manage`) |
|
|
237
|
+
|---|---|---|
|
|
238
|
+
| the code to copy, and the portal link that already carries it | `startLink({ clientId, provider, environment? })` → `{ userCode, verificationUrl, verificationUrlComplete, expiresAt }` | `POST …/marketplace/link/start` |
|
|
239
|
+
| the screen after a reload | `linkState(...)` → `{ available, pending }` | `GET …/marketplace/link?provider=` |
|
|
240
|
+
| the authorization code pasted back | `finishLink({ clientId, provider, authorizationCode, actorId, enabled? })` → `{ integration, merchants }` | `POST …/marketplace/link/finish` |
|
|
241
|
+
| a grant covering several iFood stores | `linkedMerchants(...)`, `selectLinkedMerchant({ …, merchantId })` | `GET …/link/merchants`, `PUT …/link/merchant` |
|
|
242
|
+
|
|
243
|
+
- **The verifier never leaves the server.** `startLink` seals iFood's
|
|
244
|
+
`authorizationCodeVerifier` with the host's secrets port into
|
|
245
|
+
`marketplace_link_attempts` (one per store and marketplace; starting again
|
|
246
|
+
replaces it; the exchange removes it). No answer carries a token, the
|
|
247
|
+
verifier or the app's credentials.
|
|
248
|
+
- **The tokens.** `finishLink` stores the refresh token sealed in the
|
|
249
|
+
connection's `credentials` and marks it `authMode: "LINKED"`, `VERIFIED`,
|
|
250
|
+
unarchived (a disconnected store reconnecting gets its `unarchive` audit
|
|
251
|
+
line). The merchant is selected when the grant covers exactly one, and
|
|
252
|
+
never when another store's live connection holds it. The access token lives
|
|
253
|
+
in the per-process cache, per STORE (never per app); a missing or expiring
|
|
254
|
+
one is refreshed once however many calls ask at once, and a rotated refresh
|
|
255
|
+
token is stored back. A refused refresh marks the connection `FAILED`: the
|
|
256
|
+
store links again.
|
|
257
|
+
- **The app's credentials** are the host's, through the optional
|
|
258
|
+
`appCredentials(provider, environment)` port (client id, secret, and
|
|
259
|
+
optionally a separate key the app's deliveries are signed with; absent or
|
|
260
|
+
empty, the client secret, which is what iFood signs with). Unbound, or null for a marketplace:
|
|
261
|
+
`available: false`, and a store's own credentials keep working exactly as
|
|
262
|
+
before. Typing credentials into a linked connection makes it `CREDENTIALS`
|
|
263
|
+
again.
|
|
264
|
+
- **One webhook address for every linked store:** `POST
|
|
265
|
+
/webhooks/marketplace/:provider`. The store is found by the merchant the
|
|
266
|
+
delivery names, and the delivery must carry a valid signature by the app's
|
|
267
|
+
key (unsigned is refused here, whatever the store's own setting). The
|
|
268
|
+
per-store address keeps working, and a linked store's never accepts an
|
|
269
|
+
unsigned delivery either. A merchant is held by one live connection of a
|
|
270
|
+
marketplace at a time: every write refuses `MERCHANT_TAKEN` at
|
|
271
|
+
`externalMerchantId`, and a partial unique index backs it. A linked
|
|
272
|
+
connection with no merchant chosen yet (the list failed, or the grant covers
|
|
273
|
+
several) has every delivery to this address refused, and iFood redelivers,
|
|
274
|
+
until the store chooses one.
|
|
275
|
+
|
|
276
|
+
What iFood's pages settle, read 2026-11-26 as Markdown
|
|
277
|
+
(`developer.ifood.com.br/pt-BR/docs/guides/modules/authentication/distributed.md`,
|
|
278
|
+
`…/merchant/endpoints.md`), and what they do not:
|
|
279
|
+
|
|
280
|
+
| fact | status |
|
|
281
|
+
|---|---|
|
|
282
|
+
| `POST /authentication/v1.0/oauth/userCode`, form `clientId` → `userCode`, `authorizationCodeVerifier`, `verificationUrl`, `verificationUrlComplete`, `expiresIn` (600: ten minutes) | CONFIRMED |
|
|
283
|
+
| `POST /authentication/v1.0/oauth/token`, form `grantType=authorization_code`, `clientId`, `clientSecret`, `authorizationCode`, `authorizationCodeVerifier`; and `grantType=refresh_token` with `refreshToken` | CONFIRMED |
|
|
284
|
+
| The token answer: `accessToken`, `type`, `expiresIn` (21600: six hours) | CONFIRMED |
|
|
285
|
+
| The refresh token's FIELD in that answer (`refreshToken`, `refresh_token` as a fallback) | ESTIMATED: the page says one is returned, its table lists none |
|
|
286
|
+
| Whether a refresh rotates the refresh token | ESTIMATED: stored when answered, kept when not |
|
|
287
|
+
| The refresh token's lifetime | ESTIMATED: unstated; a refused refresh marks the connection FAILED |
|
|
288
|
+
| `GET /merchant/v1.0/merchants?page=&size=` (size 100) → `[{ id, name, corporateName }]` | CONFIRMED |
|
|
289
|
+
| The status of a wrong or used authorization code | ESTIMATED: any final 4xx is `CODE_REFUSED` |
|
|
290
|
+
| The key iFood signs an app's webhook deliveries with | CONFIRMED (`webhook-signature.md`): the app's `client_secret`, the default when `webhookSecret` is absent |
|
|
291
|
+
|
|
229
292
|
## 99Food, on Open Delivery
|
|
230
293
|
|
|
231
294
|
99Food completed Open Delivery (Abrasel) adherence, so its adapter speaks
|
|
@@ -312,7 +375,7 @@ What differs from 99Food's v1.7.1, and where the adapter handles it:
|
|
|
312
375
|
| part | from Keeta's documentation |
|
|
313
376
|
|---|---|
|
|
314
377
|
| 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`, `
|
|
378
|
+
| Events | `CREATED` → fetch; `CANCELLED` (its `metadata` a JSON string with `reason`, `code`) → cancelled; `DISPATCHED`, `CONCLUDED` → lifecycle; `RIDER_ARRIVED_AT_STORE`, `ORDER_COLLECTED` → courier steps, the second a `COLLECTED` lifecycle too (FUT-5665, ESTIMATED); the rest (`CONFIRMED`, `READY_FOR_PICKUP`, `PICKUP_ONGOING`, `DELIVERED`, `CANCELLATION_REQUESTED`, the refund events, `RECOMMENDED_PREPARATION_START`) recorded and IGNORED. Keeta retries an unanswered webhook 3 times (1, 2 and 3 minutes later). |
|
|
316
379
|
| 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
380
|
| 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
381
|
| 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. |
|
|
@@ -500,6 +563,42 @@ Sources: Open Delivery `openapi.yaml` (read 2026-11-25), Rappi's portal
|
|
|
500
563
|
so every iFood row but confirm and requestCancellation is ESTIMATED, in
|
|
501
564
|
`src/ifood/outbound.ts` and `src/ifood/normalize.ts` only.
|
|
502
565
|
|
|
566
|
+
## The marketplace's own courier and the pickup code (FUT-5665)
|
|
567
|
+
|
|
568
|
+
For a bag the marketplace's fleet carries, four additive pieces, each optional
|
|
569
|
+
for the host (ADOPTING.md section 10):
|
|
570
|
+
|
|
571
|
+
- **Courier events.** `NormalizedEvent.courier` (`NormalizedCourierEvent`:
|
|
572
|
+
`step`, `at`, `courier { name, photoUrl, vehicle }` on `ASSIGNED`,
|
|
573
|
+
`returning`) reaches `order.onCourier` for an ACCEPTED order; it moves
|
|
574
|
+
nothing. iFood: `ADR`/`ASSIGN_DRIVER` (metadata `workerName`,
|
|
575
|
+
`workerPhotoUrl`, `workerVehicleType`), `GTO`, `AAO`, `CLT`,
|
|
576
|
+
`DELIVERY_RETURNING_TO_ORIGIN`, `DELIVERY_RETURNED_TO_ORIGIN`. Keeta:
|
|
577
|
+
`RIDER_ARRIVED_AT_STORE`, `ORDER_COLLECTED` (ESTIMATED). 99Food, Rappi:
|
|
578
|
+
unsupported.
|
|
579
|
+
- **COLLECTED is a lifecycle step.** `CLT` / `ORDER_COLLECTED` also names
|
|
580
|
+
`lifecycle: "COLLECTED"`, which follows the FUT-4653 rules like a
|
|
581
|
+
`DISPATCHED` and is noted as the marketplace's `HANDED_OVER`, for a bag the
|
|
582
|
+
marketplace carries only (a store-carried bag's COLLECTED is IGNORED, never
|
|
583
|
+
noted, so the store's own "delivered" is still sent).
|
|
584
|
+
- **The pickup code.** `NormalizedMarketplaceOrder.pickupCode` (iFood
|
|
585
|
+
`delivery.pickupCode`). After its local check and hand-over, the host calls
|
|
586
|
+
`engine.validatePickupCode`, and the `marketplace.outbound` job (action
|
|
587
|
+
`validatePickupCode`) posts `POST /order/v1.0/orders/{id}/validatePickupCode
|
|
588
|
+
{"code"}` and hands `{"valid"}` to `order.onPickupCodeValidated` as `VALID`,
|
|
589
|
+
`INVALID` or `UNVERIFIED`.
|
|
590
|
+
- **Tracking.** `engine.courierTracking` reads `GET
|
|
591
|
+
/order/v1.0/orders/{id}/tracking` at once (404 is `notYet`); the host runs
|
|
592
|
+
it from a job, at most once per 30 s.
|
|
593
|
+
|
|
594
|
+
Source: the iFood research of 2026-11-26 (Order module, marked confirmed
|
|
595
|
+
there). ESTIMATED, in `src/ifood/courier.ts` only: the values of
|
|
596
|
+
`workerVehicleType`, the names of the tracking body's second counts
|
|
597
|
+
(`pickupEtaStart` / `deliveryEtaEnd`, else `pickupEta` / `deliveryEta`), the
|
|
598
|
+
absence of short codes for the two return events, and whether a wrong code
|
|
599
|
+
answers `{"valid": false}` rather than a 4xx (a 4xx is `UNVERIFIED`, never
|
|
600
|
+
`INVALID`).
|
|
601
|
+
|
|
503
602
|
## Pausing a store (FUT-4851)
|
|
504
603
|
|
|
505
604
|
When the store's kitchen passes its cap, the host closes the store on every
|
package/dist/99food/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, C as CatalogueMenuEntry, b as CatalogueMenuOptions, P as PullCatalogue, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-
|
|
2
|
-
import { O as OpenDeliveryApiBaseUrls } from '../client-
|
|
1
|
+
import { N as NormalizedEvent, a as NormalizedMarketplaceOrder, C as CatalogueMenuEntry, b as CatalogueMenuOptions, P as PullCatalogue, M as MarketplaceAvailability, A as AdapterCallContext, O as OutboundResult, c as MarketplaceAdapter } from '../adapter-nUyZpLzz.js';
|
|
2
|
+
import { O as OpenDeliveryApiBaseUrls } from '../client-Ctas7WCS.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The words the 99Food adapter needs from its host, and nothing else.
|
package/dist/99food/index.js
CHANGED
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
openDeliveryStatus,
|
|
13
13
|
openDeliverySwitchAvailability,
|
|
14
14
|
verifyOpenDeliverySignature
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-L6FG6T4S.js";
|
|
16
16
|
import "../chunk-M2V4RFMA.js";
|
|
17
17
|
import "../chunk-BD7DS3XM.js";
|
|
18
|
-
import "../chunk-
|
|
18
|
+
import "../chunk-LACBT6NC.js";
|
|
19
19
|
import {
|
|
20
20
|
__name
|
|
21
21
|
} from "../chunk-7QVYU63E.js";
|