@12-apps/marketplace 1.20.0 → 1.20.1

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.
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createApiMarketplace
3
- } from "../chunk-RS2QKQ6S.js";
3
+ } from "../chunk-C2MFGZ3H.js";
4
4
  import "../chunk-LO7OKO6V.js";
5
- import "../chunk-S2ISELNJ.js";
5
+ import "../chunk-T6A46MH3.js";
6
6
  import "../chunk-Q5RMVNU5.js";
7
7
  import {
8
8
  __name
package/dist/index.js CHANGED
@@ -105,7 +105,7 @@ import {
105
105
  upsertLink,
106
106
  validatePickupCode,
107
107
  viewOf
108
- } from "./chunk-S2ISELNJ.js";
108
+ } from "./chunk-T6A46MH3.js";
109
109
  import {
110
110
  centsFromMajor
111
111
  } from "./chunk-WN2EK4KX.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  MARKETPLACE_JOBS,
3
3
  createApiMarketplace
4
- } from "../chunk-RS2QKQ6S.js";
4
+ } from "../chunk-C2MFGZ3H.js";
5
5
  import "../chunk-LO7OKO6V.js";
6
- import "../chunk-S2ISELNJ.js";
6
+ import "../chunk-T6A46MH3.js";
7
7
  import "../chunk-Q5RMVNU5.js";
8
8
  import "../chunk-7QVYU63E.js";
9
9
 
@@ -6,7 +6,7 @@ import {
6
6
  MARKETPLACE_SWEEP_QUEUE,
7
7
  ORDER_NOT_PENDING_CODE,
8
8
  createApiMarketplace
9
- } from "../chunk-RS2QKQ6S.js";
9
+ } from "../chunk-C2MFGZ3H.js";
10
10
  import {
11
11
  MARKETPLACE_DECIDE,
12
12
  MARKETPLACE_MANAGE,
@@ -20,7 +20,7 @@ import {
20
20
  upsertMarketplaceIntegrationsBody,
21
21
  upsertMarketplaceMenuLinksBody
22
22
  } from "../chunk-LO7OKO6V.js";
23
- import "../chunk-S2ISELNJ.js";
23
+ import "../chunk-T6A46MH3.js";
24
24
  import "../chunk-Q5RMVNU5.js";
25
25
  import "../chunk-7QVYU63E.js";
26
26
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@12-apps/marketplace",
3
- "version": "1.20.0",
3
+ "version": "1.20.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "One marketplace integration engine for every marketplace: the durable inbox, the ingest pipeline, the acceptance clock and its sweep, the SKU map, the integration settings with sealed credentials, and the outbound engine (confirm, cancellation request, retries), behind an adapter port. Each marketplace is an adapter at its own subpath (./ifood, ./99food and ./keeta on Open Delivery, ./rappi). Framework-neutral wiring route descriptors (./server) with a Hono adapter (./hono), dep-free job blueprints, MCP tools and the package-owned Prisma partial + migrations.",
@@ -1,5 +1,6 @@
1
1
  import type { MarketplaceAdapter, OutboundResult } from "./adapter";
2
2
  import { readOutboundConnection } from "./integration";
3
+ import { CANCELLED_BEFORE_INGEST_EVENT_TYPE } from "./order-fetch-marks";
3
4
  import type { EngineContext } from "./ports";
4
5
  import type { MarketplaceProvider } from "./types";
5
6
 
@@ -45,6 +46,13 @@ function acknowledgementOf(ctx: EngineContext, provider: string): NonNullable<Ma
45
46
  return ctx.registry.get(provider)?.acknowledgement ?? null;
46
47
  }
47
48
 
49
+ /**
50
+ * Only rows the marketplace sent are owed: the engine's own marker
51
+ * (`engine:cancelled:<id>`) is never sent, even one an older release left
52
+ * unstamped, or the marketplace refuses the whole batch (FUT-6315).
53
+ */
54
+ const SENT_BY_THE_MARKETPLACE = { eventType: { not: CANCELLED_BEFORE_INGEST_EVENT_TYPE } } as const;
55
+
48
56
  /** How many stores one pass re-queues, per marketplace. */
49
57
  const SWEEP_STORES = 500;
50
58
 
@@ -94,6 +102,7 @@ export async function runAcknowledge(
94
102
  provider: payload.provider,
95
103
  acknowledgedAt: null,
96
104
  receivedAt: { gte: windowStart(ctx, acknowledgement.retentionMs) },
105
+ ...SENT_BY_THE_MARKETPLACE,
97
106
  },
98
107
  orderBy: { receivedAt: "asc" },
99
108
  take: acknowledgement.batchSize,
@@ -164,7 +173,13 @@ export async function sweepAcknowledgements(ctx: EngineContext): Promise<{ reque
164
173
  const acknowledgement = acknowledgementOf(ctx, provider);
165
174
  if (!acknowledgement) continue;
166
175
  const rows = (await db.marketplaceInboxEvent.findMany({
167
- where: { provider, acknowledgedAt: null, clientId: { not: null }, receivedAt: { gte: windowStart(ctx, acknowledgement.retentionMs) } },
176
+ where: {
177
+ provider,
178
+ acknowledgedAt: null,
179
+ clientId: { not: null },
180
+ receivedAt: { gte: windowStart(ctx, acknowledgement.retentionMs) },
181
+ ...SENT_BY_THE_MARKETPLACE,
182
+ },
168
183
  // One row per store, bounded: the next pass takes the rest.
169
184
  distinct: ["clientId"],
170
185
  take: SWEEP_STORES,
@@ -22,7 +22,13 @@ import type { MarketplaceProvider } from "./types";
22
22
  /** The settled reason of a row that was not ingested because its order was cancelled first. */
23
23
  export const CANCELLED_BEFORE_INGEST_REASON = "cancelled before its order body arrived";
24
24
 
25
- const MARKER_TYPE = "ENGINE_CANCELLED_BEFORE_INGEST";
25
+ /**
26
+ * The marker row's `eventType`. The row is the engine's own, not an event the
27
+ * marketplace sent, so nothing is owed for it: it is written acknowledged, and
28
+ * the acknowledgment job never reads one (FUT-6315: iFood refused a whole batch
29
+ * that carried `engine:cancelled:<id>` as "an invalid event id").
30
+ */
31
+ export const CANCELLED_BEFORE_INGEST_EVENT_TYPE = "ENGINE_CANCELLED_BEFORE_INGEST";
26
32
 
27
33
  const markerId = (externalOrderId: string): string => `engine:cancelled:${externalOrderId}`;
28
34
 
@@ -38,13 +44,14 @@ export async function markCancelledBeforeIngest(
38
44
  clientId: input.clientId,
39
45
  provider: input.provider,
40
46
  eventId: markerId(input.externalOrderId),
41
- eventType: MARKER_TYPE,
47
+ eventType: CANCELLED_BEFORE_INGEST_EVENT_TYPE,
42
48
  externalOrderId: input.externalOrderId,
43
49
  payload: {},
44
50
  status: "IGNORED",
45
51
  error: "cancelled before the order was ingested",
46
52
  receivedAt: ctx.ports.clock.now(),
47
53
  processedAt: ctx.ports.clock.now(),
54
+ acknowledgedAt: ctx.ports.clock.now(),
48
55
  },
49
56
  select: { id: true },
50
57
  });