@12-apps/marketplace 1.11.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.
Files changed (51) hide show
  1. package/ADOPTING.md +90 -1
  2. package/README.md +37 -1
  3. package/dist/99food/index.d.ts +2 -2
  4. package/dist/99food/index.js +2 -2
  5. package/dist/{adapter-CD0SfdVS.d.ts → adapter-nUyZpLzz.d.ts} +325 -173
  6. package/dist/{chunk-YWMEIMO3.js → chunk-45ZVN5XI.js} +114 -24
  7. package/dist/chunk-45ZVN5XI.js.map +1 -0
  8. package/dist/{chunk-DCWOQ5PN.js → chunk-L6FG6T4S.js} +2 -2
  9. package/dist/{chunk-TVZU4HNT.js → chunk-LACBT6NC.js} +1 -1
  10. package/dist/{chunk-TVZU4HNT.js.map → chunk-LACBT6NC.js.map} +1 -1
  11. package/dist/{chunk-OS4TSIFU.js → chunk-MIPNQ7X5.js} +2 -2
  12. package/dist/{client-11sncog4.d.ts → client-Ctas7WCS.d.ts} +1 -1
  13. package/dist/{engine-C_3RK8wC.d.ts → engine-CIy9P7Cq.d.ts} +34 -5
  14. package/dist/hono/index.d.ts +2 -2
  15. package/dist/hono/index.js +2 -2
  16. package/dist/ifood/index.d.ts +7 -2
  17. package/dist/ifood/index.js +184 -30
  18. package/dist/ifood/index.js.map +1 -1
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +162 -65
  21. package/dist/index.js.map +1 -1
  22. package/dist/keeta/index.d.ts +2 -18
  23. package/dist/keeta/index.js +12 -3
  24. package/dist/keeta/index.js.map +1 -1
  25. package/dist/manifest/server.d.ts +2 -2
  26. package/dist/manifest/server.js +2 -2
  27. package/dist/rappi/index.d.ts +1 -1
  28. package/dist/rappi/index.js +1 -1
  29. package/dist/server/index.d.ts +2 -2
  30. package/dist/server/index.js +2 -2
  31. package/package.json +1 -1
  32. package/src/core/adapter.ts +6 -0
  33. package/src/core/courier-port.ts +100 -0
  34. package/src/core/courier.ts +153 -0
  35. package/src/core/engine.ts +4 -1
  36. package/src/core/lifecycle.ts +27 -4
  37. package/src/core/outbound-queue.ts +24 -11
  38. package/src/core/outbound.ts +8 -6
  39. package/src/core/pickup-code.ts +136 -0
  40. package/src/core/pipeline.ts +15 -6
  41. package/src/core/ports.ts +23 -1
  42. package/src/core/status-store.ts +2 -3
  43. package/src/core/types.ts +56 -4
  44. package/src/ifood/courier.ts +210 -0
  45. package/src/ifood/index.ts +4 -0
  46. package/src/ifood/normalize.ts +7 -0
  47. package/src/index.ts +16 -0
  48. package/src/keeta/normalize.ts +21 -6
  49. package/dist/chunk-YWMEIMO3.js.map +0 -1
  50. /package/dist/{chunk-DCWOQ5PN.js.map → chunk-L6FG6T4S.js.map} +0 -0
  51. /package/dist/{chunk-OS4TSIFU.js.map → chunk-MIPNQ7X5.js.map} +0 -0
@@ -160,6 +160,325 @@ interface PullCatalogue {
160
160
  /** The catalogue capability an adapter states, or leaves out. */
161
161
  type MarketplaceCatalogue = PushCatalogue | PullCatalogue;
162
162
 
163
+ /**
164
+ * The canonical shape every marketplace adapter normalizes INTO.
165
+ *
166
+ * This type is the seam. The engine below it knows no marketplace by name: a
167
+ * marketplace is an adapter registered with the engine (`./adapter`), and the
168
+ * provider id is whatever that adapter says it is. A second marketplace is a
169
+ * second adapter, never a second pipeline, a second acceptance clock or a
170
+ * second idea of what an order is.
171
+ *
172
+ * Deliberately POORER than any marketplace's own payload. Everything a store
173
+ * operates on is here; everything else stays in the inbox row's raw `payload`,
174
+ * which is where a normalization bug is reconstructed from.
175
+ */
176
+ /**
177
+ * A marketplace's id, as its adapter declares it (`"IFOOD"`). Uppercase
178
+ * letters, digits and underscores; the migration's CHECK holds the same shape.
179
+ * A string rather than a closed union, because the set of marketplaces is the
180
+ * set of registered adapters, and a union would make a new one a code change
181
+ * in the engine.
182
+ */
183
+ type MarketplaceProvider = string;
184
+ /** The shape a provider id must have. Shared by the registry and the CHECK. */
185
+ declare const PROVIDER_ID_PATTERN: RegExp;
186
+ /** One line of an incoming order, before it is resolved against the catalog. */
187
+ interface NormalizedOrderLine {
188
+ /** The marketplace's own SKU — the key the SKU map is matched on. */
189
+ externalSku: string;
190
+ /** What the marketplace called it. Snapshotted, and the fallback line text. */
191
+ name: string;
192
+ quantity: number;
193
+ /**
194
+ * Unit price in the smallest currency unit AS THE MARKETPLACE STATES IT. A
195
+ * marketplace's menu carries its own prices, and the buyer's receipt is the
196
+ * marketplace's one: re-pricing from the host's catalog would produce a
197
+ * total nobody was charged.
198
+ */
199
+ unitPriceCents: number;
200
+ /** The buyer's note on this line, when they left one. */
201
+ note: string | null;
202
+ }
203
+ /** The buyer, as much of them as the marketplace discloses. */
204
+ interface NormalizedBuyer {
205
+ /** The marketplace's own stable id for this customer, when it gives one. */
206
+ externalId: string | null;
207
+ name: string | null;
208
+ phone: string | null;
209
+ }
210
+ /** Where a delivery goes, as much of it as the marketplace states. */
211
+ interface NormalizedAddress {
212
+ street: string;
213
+ number: string;
214
+ neighborhood: string;
215
+ complement: string | null;
216
+ /** The sentence that finds the door. */
217
+ reference: string | null;
218
+ postalCode: string | null;
219
+ city: string | null;
220
+ state: string | null;
221
+ }
222
+ /** How the order reaches the buyer: brought to the door, or collected. */
223
+ type MarketplaceOrderType = "DELIVERY" | "TAKEOUT";
224
+ /** WHO carries a delivery: the merchant's own courier, or the marketplace's fleet. */
225
+ type MarketplaceDeliveredBy = "MERCHANT" | "MARKETPLACE";
226
+ /** WHO pays for a discount: the store, the marketplace's own campaign, or someone else (a card issuer, a voucher). */
227
+ type MarketplaceDiscountSponsor = "MERCHANT" | "MARKETPLACE" | "OTHER";
228
+ /** One discount on an order, as the part one sponsor pays. */
229
+ interface NormalizedOrderDiscount {
230
+ /** The discount's value in the smallest currency unit. */
231
+ cents: number;
232
+ sponsor: MarketplaceDiscountSponsor;
233
+ /** What the marketplace called the campaign, when it says. */
234
+ name?: string;
235
+ }
236
+ /** An incoming marketplace order, normalized. */
237
+ interface NormalizedMarketplaceOrder {
238
+ provider: MarketplaceProvider;
239
+ /** The marketplace's order id — THE idempotency key for the whole pipeline. */
240
+ externalOrderId: string;
241
+ /** The short code the courier and the buyer say out loud. */
242
+ externalDisplayId: string | null;
243
+ buyer: NormalizedBuyer;
244
+ lines: NormalizedOrderLine[];
245
+ /**
246
+ * What the buyer paid, gross. NOT derived from the lines when the
247
+ * marketplace states it: its total carries fees, promotions and rounding the
248
+ * line sum does not, and the number that must match the receipt is this one.
249
+ */
250
+ totalCents: number;
251
+ /** The marketplace's cut, when it states one. NULL is "did not say", not 0. */
252
+ commissionCents: number | null;
253
+ /** The marketplace's own promise to the buyer. */
254
+ deliveryDueAt: Date | null;
255
+ /** When the marketplace says the order was placed. */
256
+ placedAt: Date;
257
+ /** Null when the payload does not say. */
258
+ orderType?: MarketplaceOrderType | null;
259
+ /** Null on a take-out and when unstated. */
260
+ deliveredBy?: MarketplaceDeliveredBy | null;
261
+ /** Null on a take-out and when unstated. */
262
+ deliveryAddress?: NormalizedAddress | null;
263
+ /**
264
+ * OPTIONAL. The delivery fee the buyer was charged, in the smallest currency
265
+ * unit. 0 is a free delivery; null or absent is "did not say".
266
+ */
267
+ deliveryFeeCents?: number | null;
268
+ /** OPTIONAL. The items' sum as the marketplace states it, before fees and discounts. Null or absent is "did not say". */
269
+ subtotalCents?: number | null;
270
+ /**
271
+ * OPTIONAL. The discounts on the order, one entry per sponsor's share, so a
272
+ * host can tell what the store gave from what the marketplace paid for.
273
+ * Absent is "did not say"; an empty array is "no discount".
274
+ */
275
+ discounts?: NormalizedOrderDiscount[];
276
+ /**
277
+ * OPTIONAL. The merchant the order names, when its body says (Open
278
+ * Delivery's `merchant.id`). A fetched order naming another merchant than
279
+ * the connection's is refused.
280
+ */
281
+ externalMerchantId?: string | null;
282
+ /**
283
+ * OPTIONAL (FUT-5665). The code the marketplace's courier states at the
284
+ * counter to collect the bag (iFood's `delivery.pickupCode`), for the host
285
+ * to check locally at the hand-over. Null or absent: the marketplace asks
286
+ * none for this order (the check is off for the store, or the store carries
287
+ * the bag itself).
288
+ */
289
+ pickupCode?: string | null;
290
+ }
291
+ /**
292
+ * What an event says about the STORE's own cancellation request: `CONFIRMED`
293
+ * when the marketplace cancelled the order (a pending request is answered),
294
+ * `FAILED` when it refused the request.
295
+ */
296
+ type CancellationOutcome = "CONFIRMED" | "FAILED";
297
+ /**
298
+ * A step of the order's life a marketplace announces about an order it
299
+ * already has (FUT-4653): the courier left (`DISPATCHED`), the marketplace's
300
+ * courier has the bag (`COLLECTED`, FUT-5665: for a fleet bag it is the same
301
+ * hand-over as `DISPATCHED`) or the order is finished (`CONCLUDED`). An event
302
+ * that names one moves nothing by itself; the engine asks the host to move the
303
+ * order forward (`onLifecycle`).
304
+ */
305
+ type MarketplaceLifecycle = "DISPATCHED" | "COLLECTED" | "CONCLUDED";
306
+ /**
307
+ * Where the marketplace's own courier is with a bag (FUT-5665), provider-
308
+ * neutral: named (`ASSIGNED`), on the way to the store (`GOING_TO_ORIGIN`),
309
+ * at the counter (`ARRIVED_AT_ORIGIN`), holding the bag (`COLLECTED`), or
310
+ * bringing it back (`RETURNING_TO_ORIGIN`, then `RETURNED_TO_ORIGIN`).
311
+ */
312
+ type MarketplaceCourierStep = "ASSIGNED" | "GOING_TO_ORIGIN" | "ARRIVED_AT_ORIGIN" | "COLLECTED" | "RETURNING_TO_ORIGIN" | "RETURNED_TO_ORIGIN";
313
+ /** What the courier rides, as a closed set the host has words for. `OTHER`: stated, and none of these. */
314
+ type MarketplaceCourierVehicle = "MOTORCYCLE" | "BICYCLE" | "CAR" | "OTHER";
315
+ /** Who the marketplace sent, as much as it says. */
316
+ interface MarketplaceCourier {
317
+ name: string | null;
318
+ /** An https URL of the courier's photo, or null (any other scheme is dropped). */
319
+ photoUrl: string | null;
320
+ vehicle: MarketplaceCourierVehicle | null;
321
+ }
322
+ /** One courier event, normalized (FUT-5665). */
323
+ interface NormalizedCourierEvent {
324
+ step: MarketplaceCourierStep;
325
+ /** When the marketplace says it happened; null when it does not (the engine then hands the host its clock). */
326
+ at: Date | null;
327
+ /** Who is coming: on `ASSIGNED`, when the marketplace names them; null otherwise. */
328
+ courier: MarketplaceCourier | null;
329
+ /** The bag is coming back (`RETURNING`) or is back (`RETURNED`); null on every other step. */
330
+ returning: "RETURNING" | "RETURNED" | null;
331
+ }
332
+ /** What an adapter makes of one inbound delivery. */
333
+ interface NormalizedEvent {
334
+ provider: MarketplaceProvider;
335
+ /** The delivery's own id — the inbox dedup key, paired with the provider. */
336
+ eventId: string;
337
+ /** The provider's event type verbatim, kept for the inbox row and the log. */
338
+ eventType: string;
339
+ /** The merchant this event names, used to attribute it to a tenant. */
340
+ externalMerchantId: string | null;
341
+ externalOrderId: string | null;
342
+ /**
343
+ * The order this event carries, or null when the event is one the engine
344
+ * understands and does not ingest. A null here is an IGNORED inbox row (or a
345
+ * cancellation, below), never a failure.
346
+ */
347
+ order: NormalizedMarketplaceOrder | null;
348
+ /** The marketplace has CANCELLED the order. */
349
+ cancelled: boolean;
350
+ /**
351
+ * The answer to the store's own cancellation request, when this event is
352
+ * one. A `cancelled: true` event reads as `CONFIRMED` when this is absent.
353
+ */
354
+ cancellationOutcome?: CancellationOutcome | null;
355
+ /**
356
+ * OPTIONAL. This event announces an order whose body the marketplace serves
357
+ * separately (Open Delivery's `CREATED` carries only the order's id): the
358
+ * engine fetches it through the adapter's `fetchOrder`, in the
359
+ * `marketplace.fetch-order` job, never inside the request that delivered
360
+ * the event. Ignored when `order` is present.
361
+ */
362
+ orderToFetch?: boolean;
363
+ /**
364
+ * OPTIONAL. The lifecycle step this event announces about an order the
365
+ * engine already has. Absent or null: the event names none. An event that
366
+ * names one carries no order body.
367
+ */
368
+ lifecycle?: MarketplaceLifecycle | null;
369
+ /**
370
+ * OPTIONAL (FUT-5665). Where the marketplace's courier is, when this event
371
+ * says. A `COLLECTED` names the lifecycle too. Absent or null: the event
372
+ * names no courier step.
373
+ */
374
+ courier?: NormalizedCourierEvent | null;
375
+ }
376
+
377
+ /**
378
+ * The marketplace's own courier (FUT-5665): what an adapter can do about the
379
+ * courier its marketplace sends, and what the host is told. Optional in every
380
+ * type, so a host or an adapter that knows nothing of it compiles unchanged.
381
+ */
382
+ /** Where the marketplace's courier is, as its tracking read says. Every field null when unstated. */
383
+ interface MarketplaceCourierTracking {
384
+ /** When the courier reaches the store: the "chega em" time. */
385
+ pickupEtaAt: Date | null;
386
+ /** When the marketplace expects the bag at the buyer's door. */
387
+ deliveryEtaAt: Date | null;
388
+ latitude: number | null;
389
+ longitude: number | null;
390
+ /** When the marketplace took this reading. */
391
+ trackedAt: Date | null;
392
+ }
393
+ /** What an adapter's pickup-code check answers: the marketplace's verdict, or why there is none. */
394
+ type PickupCodeCallResult = {
395
+ kind: "answered";
396
+ valid: boolean;
397
+ } | Exclude<OutboundResult, {
398
+ kind: "accepted";
399
+ }>;
400
+ /**
401
+ * What an adapter's tracking read answers: the reading; `notYet` (no courier
402
+ * is assigned, so there is nothing to track); or the refusal and retry shapes
403
+ * of an outbound call.
404
+ */
405
+ type CourierTrackingCallResult = {
406
+ kind: "tracking";
407
+ tracking: MarketplaceCourierTracking;
408
+ } | {
409
+ kind: "notYet";
410
+ } | Exclude<OutboundResult, {
411
+ kind: "accepted";
412
+ }>;
413
+ /** The courier calls one marketplace takes. Present on an adapter whose marketplace has them (iFood). */
414
+ interface MarketplaceCourierApi {
415
+ /**
416
+ * Tell the marketplace the code the store checked at the hand-over, and
417
+ * read its verdict. Called only from the `marketplace.outbound` job, action
418
+ * `validatePickupCode`, after the host's own hand-over committed.
419
+ */
420
+ validatePickupCode(ctx: AdapterCallContext, order: OutboundOrderRef, input: {
421
+ code: string;
422
+ }): Promise<PickupCodeCallResult>;
423
+ /** Read where the courier is. Called only by `engine.courierTracking`, which the host runs in a job. */
424
+ tracking(ctx: AdapterCallContext, order: OutboundOrderRef): Promise<CourierTrackingCallResult>;
425
+ }
426
+ /**
427
+ * The marketplace's verdict on a pickup code, as the host is told it:
428
+ * `VALID`, `INVALID` (the hand-over has committed: warn, move nothing) or
429
+ * `UNVERIFIED` (no verdict came: a final refusal, retries that ran out, no
430
+ * connection).
431
+ */
432
+ type PickupCodeValidation = "VALID" | "INVALID" | "UNVERIFIED";
433
+ /** What the engine tells the host with a courier event. */
434
+ interface MarketplaceCourierFacts {
435
+ /** Who carries the delivery, as the acceptance row holds it. */
436
+ deliveredBy: MarketplaceDeliveredBy | null;
437
+ /** When it happened: the event's own instant, or the engine's clock when the event states none. */
438
+ at: Date;
439
+ }
440
+ /**
441
+ * The host's answer to a courier event: `recorded` (it stored the facts),
442
+ * `unchanged` (nothing to store, with the engine's reason), or `unchanged`
443
+ * with the host's own reason, which becomes the inbox row's.
444
+ */
445
+ type MarketplaceCourierAnswer = "recorded" | "unchanged" | {
446
+ kind: "unchanged";
447
+ reason: string;
448
+ };
449
+ /** What `engine.courierTracking` answers. */
450
+ type CourierTrackingResult = CourierTrackingCallResult
451
+ /** Nothing to call: no such marketplace order, a marketplace with no tracking, or a bag the store carries itself. */
452
+ | {
453
+ kind: "unsupported";
454
+ reason: string;
455
+ };
456
+ /** What the host says after its hand-over committed. */
457
+ interface ValidatePickupCodeInput {
458
+ clientId: string;
459
+ /** The host's order id. */
460
+ orderId: string;
461
+ /** The code the store checked (the one the courier stated). */
462
+ code: string;
463
+ /** The hand-over's own instant: it makes the job's key, so a hand-over after an undo is a new job. */
464
+ at: Date;
465
+ }
466
+ /** The engine's courier calls (FUT-5665), part of `MarketplaceEngine`. */
467
+ interface MarketplaceCourierEngine {
468
+ /**
469
+ * The store handed a marketplace courier's bag over after checking the
470
+ * pickup code locally: ONE enqueue of `marketplace.outbound`, action
471
+ * `validatePickupCode`, after the hand-over's commit. Never throws, runs no
472
+ * statement and calls nobody. True when the queue took it.
473
+ */
474
+ validatePickupCode(input: ValidatePickupCodeInput): Promise<boolean>;
475
+ /** Read where the marketplace's courier is: one call to the marketplace, at once. Run it from a job. */
476
+ courierTracking(input: {
477
+ clientId: string;
478
+ orderId: string;
479
+ }): Promise<CourierTrackingResult>;
480
+ }
481
+
163
482
  /**
164
483
  * The catalogue READ half of the adapter port (FUT-951): the menu a store
165
484
  * already keeps on a marketplace, read through the store's own connection, so
@@ -519,178 +838,6 @@ interface MarketplaceAvailability {
519
838
  resume(ctx: AdapterCallContext, ref: StorePauseRef): Promise<OutboundResult>;
520
839
  }
521
840
 
522
- /**
523
- * The canonical shape every marketplace adapter normalizes INTO.
524
- *
525
- * This type is the seam. The engine below it knows no marketplace by name: a
526
- * marketplace is an adapter registered with the engine (`./adapter`), and the
527
- * provider id is whatever that adapter says it is. A second marketplace is a
528
- * second adapter, never a second pipeline, a second acceptance clock or a
529
- * second idea of what an order is.
530
- *
531
- * Deliberately POORER than any marketplace's own payload. Everything a store
532
- * operates on is here; everything else stays in the inbox row's raw `payload`,
533
- * which is where a normalization bug is reconstructed from.
534
- */
535
- /**
536
- * A marketplace's id, as its adapter declares it (`"IFOOD"`). Uppercase
537
- * letters, digits and underscores; the migration's CHECK holds the same shape.
538
- * A string rather than a closed union, because the set of marketplaces is the
539
- * set of registered adapters, and a union would make a new one a code change
540
- * in the engine.
541
- */
542
- type MarketplaceProvider = string;
543
- /** The shape a provider id must have. Shared by the registry and the CHECK. */
544
- declare const PROVIDER_ID_PATTERN: RegExp;
545
- /** One line of an incoming order, before it is resolved against the catalog. */
546
- interface NormalizedOrderLine {
547
- /** The marketplace's own SKU — the key the SKU map is matched on. */
548
- externalSku: string;
549
- /** What the marketplace called it. Snapshotted, and the fallback line text. */
550
- name: string;
551
- quantity: number;
552
- /**
553
- * Unit price in the smallest currency unit AS THE MARKETPLACE STATES IT. A
554
- * marketplace's menu carries its own prices, and the buyer's receipt is the
555
- * marketplace's one: re-pricing from the host's catalog would produce a
556
- * total nobody was charged.
557
- */
558
- unitPriceCents: number;
559
- /** The buyer's note on this line, when they left one. */
560
- note: string | null;
561
- }
562
- /** The buyer, as much of them as the marketplace discloses. */
563
- interface NormalizedBuyer {
564
- /** The marketplace's own stable id for this customer, when it gives one. */
565
- externalId: string | null;
566
- name: string | null;
567
- phone: string | null;
568
- }
569
- /** Where a delivery goes, as much of it as the marketplace states. */
570
- interface NormalizedAddress {
571
- street: string;
572
- number: string;
573
- neighborhood: string;
574
- complement: string | null;
575
- /** The sentence that finds the door. */
576
- reference: string | null;
577
- postalCode: string | null;
578
- city: string | null;
579
- state: string | null;
580
- }
581
- /** How the order reaches the buyer: brought to the door, or collected. */
582
- type MarketplaceOrderType = "DELIVERY" | "TAKEOUT";
583
- /** WHO carries a delivery: the merchant's own courier, or the marketplace's fleet. */
584
- type MarketplaceDeliveredBy = "MERCHANT" | "MARKETPLACE";
585
- /** WHO pays for a discount: the store, the marketplace's own campaign, or someone else (a card issuer, a voucher). */
586
- type MarketplaceDiscountSponsor = "MERCHANT" | "MARKETPLACE" | "OTHER";
587
- /** One discount on an order, as the part one sponsor pays. */
588
- interface NormalizedOrderDiscount {
589
- /** The discount's value in the smallest currency unit. */
590
- cents: number;
591
- sponsor: MarketplaceDiscountSponsor;
592
- /** What the marketplace called the campaign, when it says. */
593
- name?: string;
594
- }
595
- /** An incoming marketplace order, normalized. */
596
- interface NormalizedMarketplaceOrder {
597
- provider: MarketplaceProvider;
598
- /** The marketplace's order id — THE idempotency key for the whole pipeline. */
599
- externalOrderId: string;
600
- /** The short code the courier and the buyer say out loud. */
601
- externalDisplayId: string | null;
602
- buyer: NormalizedBuyer;
603
- lines: NormalizedOrderLine[];
604
- /**
605
- * What the buyer paid, gross. NOT derived from the lines when the
606
- * marketplace states it: its total carries fees, promotions and rounding the
607
- * line sum does not, and the number that must match the receipt is this one.
608
- */
609
- totalCents: number;
610
- /** The marketplace's cut, when it states one. NULL is "did not say", not 0. */
611
- commissionCents: number | null;
612
- /** The marketplace's own promise to the buyer. */
613
- deliveryDueAt: Date | null;
614
- /** When the marketplace says the order was placed. */
615
- placedAt: Date;
616
- /** Null when the payload does not say. */
617
- orderType?: MarketplaceOrderType | null;
618
- /** Null on a take-out and when unstated. */
619
- deliveredBy?: MarketplaceDeliveredBy | null;
620
- /** Null on a take-out and when unstated. */
621
- deliveryAddress?: NormalizedAddress | null;
622
- /**
623
- * OPTIONAL. The delivery fee the buyer was charged, in the smallest currency
624
- * unit. 0 is a free delivery; null or absent is "did not say".
625
- */
626
- deliveryFeeCents?: number | null;
627
- /** OPTIONAL. The items' sum as the marketplace states it, before fees and discounts. Null or absent is "did not say". */
628
- subtotalCents?: number | null;
629
- /**
630
- * OPTIONAL. The discounts on the order, one entry per sponsor's share, so a
631
- * host can tell what the store gave from what the marketplace paid for.
632
- * Absent is "did not say"; an empty array is "no discount".
633
- */
634
- discounts?: NormalizedOrderDiscount[];
635
- /**
636
- * OPTIONAL. The merchant the order names, when its body says (Open
637
- * Delivery's `merchant.id`). A fetched order naming another merchant than
638
- * the connection's is refused.
639
- */
640
- externalMerchantId?: string | null;
641
- }
642
- /**
643
- * What an event says about the STORE's own cancellation request: `CONFIRMED`
644
- * when the marketplace cancelled the order (a pending request is answered),
645
- * `FAILED` when it refused the request.
646
- */
647
- type CancellationOutcome = "CONFIRMED" | "FAILED";
648
- /**
649
- * A step of the order's life a marketplace announces about an order it
650
- * already has (FUT-4653): the courier left (`DISPATCHED`) or the order is
651
- * finished (`CONCLUDED`). An event that names one moves nothing by itself; the
652
- * engine asks the host to move the order forward (`onLifecycle`).
653
- */
654
- type MarketplaceLifecycle = "DISPATCHED" | "CONCLUDED";
655
- /** What an adapter makes of one inbound delivery. */
656
- interface NormalizedEvent {
657
- provider: MarketplaceProvider;
658
- /** The delivery's own id — the inbox dedup key, paired with the provider. */
659
- eventId: string;
660
- /** The provider's event type verbatim, kept for the inbox row and the log. */
661
- eventType: string;
662
- /** The merchant this event names, used to attribute it to a tenant. */
663
- externalMerchantId: string | null;
664
- externalOrderId: string | null;
665
- /**
666
- * The order this event carries, or null when the event is one the engine
667
- * understands and does not ingest. A null here is an IGNORED inbox row (or a
668
- * cancellation, below), never a failure.
669
- */
670
- order: NormalizedMarketplaceOrder | null;
671
- /** The marketplace has CANCELLED the order. */
672
- cancelled: boolean;
673
- /**
674
- * The answer to the store's own cancellation request, when this event is
675
- * one. A `cancelled: true` event reads as `CONFIRMED` when this is absent.
676
- */
677
- cancellationOutcome?: CancellationOutcome | null;
678
- /**
679
- * OPTIONAL. This event announces an order whose body the marketplace serves
680
- * separately (Open Delivery's `CREATED` carries only the order's id): the
681
- * engine fetches it through the adapter's `fetchOrder`, in the
682
- * `marketplace.fetch-order` job, never inside the request that delivered
683
- * the event. Ignored when `order` is present.
684
- */
685
- orderToFetch?: boolean;
686
- /**
687
- * OPTIONAL. The lifecycle step this event announces about an order the
688
- * engine already has. Absent or null: the event names none. An event that
689
- * names one carries no order body.
690
- */
691
- lifecycle?: MarketplaceLifecycle | null;
692
- }
693
-
694
841
  /**
695
842
  * The adapter port: everything one marketplace is, behind one shape.
696
843
  *
@@ -941,6 +1088,11 @@ interface MarketplaceAdapter {
941
1088
  * marketplace (FUT-5613). Absent: a store connects with its own credentials only.
942
1089
  */
943
1090
  readonly linking?: MarketplaceLinking;
1091
+ /**
1092
+ * OPTIONAL. The marketplace's own courier (FUT-5665): the pickup-code check
1093
+ * and the tracking read. Absent: neither is offered, and the host says so.
1094
+ */
1095
+ readonly courier?: MarketplaceCourierApi;
944
1096
  /** Where "open it on the marketplace" goes: the order when `perOrderAppLink`, else the portal. Always https. */
945
1097
  appLink(order: Pick<OutboundOrderRef, "externalOrderId" | "externalDisplayId">): string;
946
1098
  }
@@ -960,4 +1112,4 @@ declare function tokenGrantResultOf(response: MarketplaceHttpResponse): Outbound
960
1112
  /** A call that never got an answer is a retry, with the reason a log can read. */
961
1113
  declare function answered(call: () => Promise<OutboundResult>): Promise<OutboundResult>;
962
1114
 
963
- export { type MarketplaceHttp as $, type AdapterCallContext as A, type CatalogueReadWarningCode as B, type CatalogueMenuEntry as C, type CatalogueSnapshot as D, type CatalogueSnapshotCategory as E, type CatalogueSnapshotItem as F, type CatalogueSnapshotOption as G, type CatalogueSnapshotOptionGroup as H, type CatalogueStoredImage as I, type CatalogueWarningCode as J, type FetchOrderResult as K, type LinkCallContext as L, type MarketplaceAvailability as M, type NormalizedEvent as N, type OutboundResult as O, type PullCatalogue as P, type LinkCode as Q, type LinkGrant as R, type StorePauseRequest as S, type LinkResult as T, type LinkedMerchant as U, type MarketplaceAppCredentialsPort as V, type MarketplaceCapabilities as W, type MarketplaceCatalogue as X, type MarketplaceCredentials as Y, type MarketplaceDeliveredBy as Z, type MarketplaceDiscountSponsor as _, type NormalizedMarketplaceOrder as a, type MarketplaceHttpRequest as a0, type MarketplaceHttpResponse as a1, type MarketplaceLifecycle as a2, type MarketplaceLinkAttemptDelegate as a3, type MarketplaceOrderType as a4, type NormalizedAddress as a5, type NormalizedBuyer as a6, type NormalizedOrderDiscount as a7, type NormalizedOrderLine as a8, type OutboundOrderRef as a9, PROVIDER_ID_PATTERN as aa, type StatusFacts as ab, type StatusStep as ac, answered as ad, centsFromMajor as ae, outboundResultOf as af, tokenGrantResultOf as ag, type CatalogueMenuOptions as b, type MarketplaceAdapter as c, type PushCatalogue as d, type CatalogueItemOut as e, type CatalogueReader as f, type MarketplaceLinking as g, type StorePauseResult as h, type StorePauseRef as i, type MarketplaceProvider as j, type CancellationReason as k, type AdapterGrant as l, type AdapterTokenCache as m, type CancellationOutcome as n, type CancellationRequestInput as o, type CatalogueCallContext as p, type CatalogueFailure as q, type CatalogueImage as r, type CatalogueItem as s, type CatalogueItemRef as t, type CataloguePublishResult as u, type CatalogueReadContext as v, type CatalogueReadNotice as w, type CatalogueReadRefusalCode as x, type CatalogueReadResult as y, type CatalogueReadWarning as z };
1115
+ export { type MarketplaceCatalogue as $, type AdapterCallContext as A, type CatalogueReadResult as B, type CatalogueMenuEntry as C, type CatalogueReadWarning as D, type CatalogueReadWarningCode as E, type CatalogueSnapshot as F, type CatalogueSnapshotCategory as G, type CatalogueSnapshotItem as H, type CatalogueSnapshotOption as I, type CatalogueSnapshotOptionGroup as J, type CatalogueStoredImage as K, type CatalogueWarningCode as L, type MarketplaceAvailability as M, type NormalizedEvent as N, type OutboundResult as O, type PullCatalogue as P, type CourierTrackingCallResult as Q, type CourierTrackingResult as R, type StorePauseRequest as S, type FetchOrderResult as T, type LinkCallContext as U, type LinkCode as V, type LinkGrant as W, type LinkResult as X, type LinkedMerchant as Y, type MarketplaceAppCredentialsPort as Z, type MarketplaceCapabilities as _, type NormalizedMarketplaceOrder as a, type MarketplaceCourier as a0, type MarketplaceCourierAnswer as a1, type MarketplaceCourierEngine as a2, type MarketplaceCourierFacts as a3, type MarketplaceCourierStep as a4, type MarketplaceCourierTracking as a5, type MarketplaceCourierVehicle as a6, type MarketplaceCredentials as a7, type MarketplaceDeliveredBy as a8, type MarketplaceDiscountSponsor as a9, type MarketplaceHttp as aa, type MarketplaceHttpRequest as ab, type MarketplaceHttpResponse as ac, type MarketplaceLifecycle as ad, type MarketplaceLinkAttemptDelegate as ae, type MarketplaceOrderType as af, type NormalizedAddress as ag, type NormalizedBuyer as ah, type NormalizedOrderDiscount as ai, type NormalizedOrderLine as aj, type OutboundOrderRef as ak, PROVIDER_ID_PATTERN as al, type PickupCodeCallResult as am, type PickupCodeValidation as an, type StatusFacts as ao, type StatusStep as ap, type ValidatePickupCodeInput as aq, answered as ar, centsFromMajor as as, outboundResultOf as at, tokenGrantResultOf as au, type CatalogueMenuOptions as b, type MarketplaceAdapter as c, type PushCatalogue as d, type CatalogueItemOut as e, type CatalogueReader as f, type MarketplaceLinking as g, type MarketplaceCourierApi as h, type NormalizedCourierEvent as i, type StorePauseResult as j, type StorePauseRef as k, type MarketplaceProvider as l, type CancellationReason as m, type AdapterGrant as n, type AdapterTokenCache as o, type CancellationOutcome as p, type CancellationRequestInput as q, type CatalogueCallContext as r, type CatalogueFailure as s, type CatalogueImage as t, type CatalogueItem as u, type CatalogueItemRef as v, type CataloguePublishResult as w, type CatalogueReadContext as x, type CatalogueReadNotice as y, type CatalogueReadRefusalCode as z };