@12-apps/marketplace 1.15.0 → 1.16.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 CHANGED
@@ -517,7 +517,7 @@ Events `webhook-overview`, `webhook-best-practices`, `presence`,
517
517
  | A4 | an enqueue lost, or a job that gave up | — | the `marketplace.reconcile-inbox` pass also re-queues one job per (store, marketplace) with events still owed inside the window | same |
518
518
  | A5 | an event older than 8 h | — | never acknowledged (iFood keeps events 8 h) | same |
519
519
  | A6 | a marketplace whose adapter states no `acknowledgement` (99Food, Keeta, Rappi) | nothing | nothing | same |
520
- | R1 | an iFood order ingested | static reasons only, no call | `marketplace.cancellation-reasons` `{ clientId, orderId }` queued after the ingest's commit, key `…:<orderId>` | `__tests__/cancellation-reasons.test.ts` |
520
+ | R1 | an iFood order ingested | static reasons only, no call | `marketplace.cancellation-reasons` `{ clientId, orderId }` queued after the ingest's commit, key `…:<orderId>`; an order not auto-accepted adds `deferredConfirmations: true` (C5) | `__tests__/cancellation-reasons.test.ts` |
521
521
  | R2 | the job | none exists | `GET /order/v1.0/orders/{id}/cancellationReasons` with the connection's bearer; `{ reasons: [{ code, description }] }` (or a bare array) is kept on the order (`marketplace_acceptances.cancellation_reasons`) for its life; a second run calls nobody. `engine.orderReasons(clientId, orderId)` and `orderStates(…).cancellationReasons` answer it, each code labelled by the pack when the pack names it, else by iFood's own `description` | same |
522
522
  | R3 | the read fails | — | retried (3 attempts); the last leaves the column null and the order's reasons are the adapter's static list (the fallback) | same |
523
523
  | R4 | the store refuses with a code of the order's list | the code must be in the static list; the body was `{ reason: <label>, cancellationCode: <code> }` | accepted; the body is exactly `{ "reason": "<code>" }` (`cancellation`: `-d '{"reason": "503"}'`) | same |
@@ -546,7 +546,7 @@ Events `webhook-overview`, `webhook-best-practices`, `presence`,
546
546
  | C3 | an order accepted or stamped by CFM, past its deadline | expired | never expired: the expiry predicate adds `confirmed_at IS NULL` | same |
547
547
  | C4 | CFM of an ACCEPTED order whose confirm is stamped (our confirm's echo), or of a REJECTED or EXPIRED one | IGNORED | IGNORED, unchanged | same |
548
548
  | C9 | CFM of an ACCEPTED order whose confirm is not stamped (`confirmed_at` null, `confirm_failed_at` either way): a person's aceite raced the tablet's, or our confirm timed out but landed | IGNORED; the queued confirm is sent again (and a 4xx stamps `confirm_failed_at`, which S2 would then make stop every step) | `confirmed_at` stamped, no host call: the queued confirm skips ("already stamped"). With `confirm_failed_at` already set (the tablet confirmed, a person's aceite claimed it here, our duplicate confirm got a 4xx before the CFM landed) it is cleared too: iFood says the order IS confirmed, and leaving the failure would make S2 skip every later step of a confirmed order and the host show "não confirmou" (worse than `main`, where steps ignored the confirm) | same |
549
- | C5 | CFM before its order (the PLACED's fetch still running) | IGNORED, lost | DEFERRED (PENDING, `confirmed before its order`); when an adapter that `marketplaceConfirms` ingests that order, the deferred confirmation is applied right after the ingest's commit | same |
549
+ | C5 | CFM before its order (the PLACED's fetch still running) | IGNORED, lost | DEFERRED (PENDING, `confirmed before its order`); when an adapter that `marketplaceConfirms` ingests that order and does not auto-accept it, the deferred confirmation is applied by the `marketplace.cancellation-reasons` job, a few seconds after the ingest's commit (FUT-5984: the ingest itself reads no inbox row; C7 covers a late job) | same, `__tests__/deferred-confirmation-job.test.ts` |
550
550
  | C6 | CFM while the store's cancellation request stands | IGNORED | `confirmed_at` stamped (the request's answer or window ends the order, not the clock); no admit, no claim | same |
551
551
  | C7 | a deferred CFM still PENDING when the clock runs out | expired | the expiry sweep applies it first (one inbox read, only when rows lapsed), so the order is accepted, not expired | same |
552
552
  | C8 | an AWAITING order with no CFM past its deadline | expired | expired, unchanged | same |
@@ -571,6 +571,9 @@ Events `webhook-overview`, `webhook-best-practices`, `presence`,
571
571
  draw), never a bypass; a refused admit leaves the order for a person.
572
572
  - **The normal webhook path costs no new statement.** The answer status is an
573
573
  adapter constant; the acknowledge enqueue is a queue call.
574
+ - **A deferred confirmation now applies in the `marketplace.cancellation-reasons`
575
+ job, a few seconds after ingest**, never inside the ingest (FUT-5984: 1.14.0's
576
+ inline read added one statement to every iFood ingest not auto-accepted).
574
577
 
575
578
  ### 12.3 What is still ESTIMATED
576
579
 
@@ -742,3 +745,34 @@ host), the mapping is:
742
745
  exports `normalizedLineTotalCents`, `NormalizedLineOption`,
743
746
  `NormalizedPayments`, `NormalizedPaymentMethod`, `MarketplacePaymentMethod`,
744
747
  `NormalizedOrderFee`.
748
+
749
+ ## 14. iFood Logistics: the store's own motoboy reported to iFood (FUT-5988)
750
+
751
+ When the store's own motoboy carries an iFood order (`deliveredBy: MERCHANT`),
752
+ iFood's **Logistics** module lets the software report the delivery, so the
753
+ customer follows it in the iFood app. `@12-apps/marketplace/ifood` exports the
754
+ wire client (`src/ifood/logistics.ts`); which step is sent when, and the job
755
+ that sends it, are the host's.
756
+
757
+ - **A second app.** Logistics is its own iFood app (category Logística,
758
+ centralized), so the call context carries THAT app's client id and secret,
759
+ never the store's PDV credentials and never a linked store's grant. Its token
760
+ is cached under its own client id, apart from the PDV app's.
761
+ - **`ifoodLogisticsAssignDriver(ctx, orderId, driver)`**: name, phone (sent as
762
+ digits, 10 to 13 of them) and one of `IFOOD_LOGISTICS_VEHICLES`. An invalid
763
+ driver answers `{ kind: "invalid" }` and nothing is sent. A second
764
+ assignment is iFood's 409, a `refused`.
765
+ - **`ifoodLogisticsStep(ctx, orderId, step)`**: `GOING_TO_ORIGIN`,
766
+ `ARRIVED_AT_ORIGIN`, `DISPATCHED`, `ARRIVED_AT_DESTINATION`. iFood takes them
767
+ asynchronously (202) and only in that order: out of order is 409.
768
+ `ifoodLogisticsStepsTo(lastSent, target)` names the steps still owed, in
769
+ order, so a host that reaches `DISPATCHED` straight from the assignment sends
770
+ the two origin steps first.
771
+ - **`ifoodLogisticsVerifyDeliveryCode(ctx, orderId, code)`**: `verified`,
772
+ `wrong-code` (iFood's `success: false` or 422: the motoboy may type it
773
+ again), `not-requested` (412: the order never asked for a code), or the
774
+ usual `refused` / `retry`. The code is never logged.
775
+ - **No live location.** iFood's guides have no endpoint for the motoboy's
776
+ position or route (read 2026-12-01).
777
+ - Every result is an `OutboundResult` shape: 429, 408 and 5xx are retries, a
778
+ 401 renews the token once inside the call.
@@ -20,7 +20,7 @@ import {
20
20
  CatalogueRetryError,
21
21
  FetchOrderRetryError,
22
22
  OutboundRetryError
23
- } from "./chunk-B4DYPQFE.js";
23
+ } from "./chunk-TICWLBSA.js";
24
24
  import {
25
25
  __name
26
26
  } from "./chunk-7QVYU63E.js";
@@ -698,4 +698,4 @@ export {
698
698
  MARKETPLACE_JOBS,
699
699
  createApiMarketplace
700
700
  };
701
- //# sourceMappingURL=chunk-FQI56NGC.js.map
701
+ //# sourceMappingURL=chunk-DJIMUEHT.js.map
@@ -1296,8 +1296,14 @@ var CancellationReasonsRetryError = class extends Error {
1296
1296
  }
1297
1297
  };
1298
1298
  async function enqueueOrderReasons(ctx, input) {
1299
- if (!ctx.registry.get(input.provider)?.orderCancellationReasons) return;
1300
- const payload = { clientId: input.clientId, orderId: input.orderId };
1299
+ const adapter = ctx.registry.get(input.provider);
1300
+ const deferred = input.deferredConfirmations === true && adapter?.capabilities.marketplaceConfirms === true;
1301
+ if (!adapter?.orderCancellationReasons && !deferred) return;
1302
+ const payload = {
1303
+ clientId: input.clientId,
1304
+ orderId: input.orderId,
1305
+ ...deferred ? { deferredConfirmations: true } : {}
1306
+ };
1301
1307
  const outcome = await ctx.ports.enqueue.enqueue(MARKETPLACE_CANCELLATION_REASONS_JOB, payload, {
1302
1308
  dedupeKey: `${MARKETPLACE_CANCELLATION_REASONS_JOB}:${input.orderId}`
1303
1309
  });
@@ -1318,12 +1324,26 @@ async function keep(ctx, db, clientId, orderId, reasons) {
1318
1324
  return { kind: "done", count: reasons.length };
1319
1325
  }
1320
1326
  __name(keep, "keep");
1321
- async function runCancellationReasons(ctx, payload, attempt) {
1322
- const db = await ctx.ports.db();
1327
+ async function applyEarlyConfirmations(ctx, clientId, row) {
1328
+ try {
1329
+ await applyDeferredConfirmations(ctx, { clientId, provider: row.provider, externalOrderId: row.externalOrderId });
1330
+ } catch (error) {
1331
+ ctx.ports.logger.warn(`${MARKETPLACE_CANCELLATION_REASONS_JOB}: order ${row.orderId}: a deferred confirmation was not applied; the expiry sweep applies it`, error);
1332
+ }
1333
+ }
1334
+ __name(applyEarlyConfirmations, "applyEarlyConfirmations");
1335
+ async function loadOrder(ctx, db, payload) {
1323
1336
  const row = await db.marketplaceAcceptance.findFirst({
1324
1337
  where: { orderId: payload.orderId, clientId: payload.clientId },
1325
1338
  select: { orderId: true, provider: true, externalOrderId: true, cancellationReasons: true }
1326
1339
  });
1340
+ if (row && payload.deferredConfirmations) await applyEarlyConfirmations(ctx, payload.clientId, row);
1341
+ return row;
1342
+ }
1343
+ __name(loadOrder, "loadOrder");
1344
+ async function runCancellationReasons(ctx, payload, attempt) {
1345
+ const db = await ctx.ports.db();
1346
+ const row = await loadOrder(ctx, db, payload);
1327
1347
  if (!row) return { kind: "skipped", reason: "no acceptance for this order" };
1328
1348
  if (storedReasons(row.cancellationReasons) !== null) return { kind: "skipped", reason: "the order's reasons are already kept" };
1329
1349
  const read = ctx.registry.get(row.provider)?.orderCancellationReasons;
@@ -1529,8 +1549,7 @@ async function ingestMarketplaceOrder(ctx, input) {
1529
1549
  await ctx.ports.order.onAccepted(clientId, orderId);
1530
1550
  }
1531
1551
  ctx.ports.publishChanged(clientId);
1532
- await enqueueOrderReasons(ctx, { clientId, orderId, provider: order.provider });
1533
- if (!accepted) await applyDeferredConfirmations(ctx, { clientId, provider: order.provider, externalOrderId: order.externalOrderId });
1552
+ await enqueueOrderReasons(ctx, { clientId, orderId, provider: order.provider, deferredConfirmations: !accepted });
1534
1553
  return { orderId, created: true, unmappedSkus, autoAccepted: accepted };
1535
1554
  }
1536
1555
  __name(ingestMarketplaceOrder, "ingestMarketplaceOrder");
@@ -2932,4 +2951,4 @@ export {
2932
2951
  AvailabilityRetryError,
2933
2952
  runAvailability
2934
2953
  };
2935
- //# sourceMappingURL=chunk-B4DYPQFE.js.map
2954
+ //# sourceMappingURL=chunk-TICWLBSA.js.map