@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.
- package/ADOPTING.md +1 -0
- package/dist/{chunk-RS2QKQ6S.js → chunk-C2MFGZ3H.js} +2 -2
- package/dist/{chunk-S2ISELNJ.js → chunk-T6A46MH3.js} +52 -43
- package/dist/chunk-T6A46MH3.js.map +1 -0
- package/dist/hono/index.js +2 -2
- package/dist/index.js +1 -1
- package/dist/manifest/server.js +2 -2
- package/dist/server/index.js +2 -2
- package/package.json +1 -1
- package/src/core/acknowledge.ts +16 -1
- package/src/core/order-fetch-marks.ts +9 -2
- package/dist/chunk-S2ISELNJ.js.map +0 -1
- /package/dist/{chunk-RS2QKQ6S.js.map → chunk-C2MFGZ3H.js.map} +0 -0
package/ADOPTING.md
CHANGED
|
@@ -565,6 +565,7 @@ Events `webhook-overview`, `webhook-best-practices`, `presence`,
|
|
|
565
565
|
| A1 | an iFood event recorded in the inbox (fresh) | nothing | `marketplace.acknowledge` `{ clientId, provider }` queued after the row is written, key `marketplace.acknowledge:<inboxId>`; a redelivery queues nothing; the request calls nobody | `__tests__/acknowledgment.test.ts` |
|
|
566
566
|
| A2 | the job | none exists | `POST /events/v1.0/events/acknowledgment` with `[{ id }]` of every event of that store recorded in the last 8 h and not yet acknowledged, up to 2000 a call (`polling-overview`: "Limite: até 2000 IDs por requisição"); 2xx stamps `acknowledged_at` on exactly those rows; a second run sends nothing ("apenas uma vez por evento") | same |
|
|
567
567
|
| A7 | the marketplace refuses the batch for good (a final 4xx, not our credentials) | — | given up on: stamped and logged at error, never resent (one bad id cannot make every reconcile pass resend the store's events for 8 h); our own credentials refused leave them owed | same |
|
|
568
|
+
| A8 | a cancellation that outran its order (the engine's marker row `engine:cancelled:<id>`) | the marker's id sent in the batch; iFood refused the whole batch (`400 "Ack with invalid event id"`) and the real events in it were stamped as refused (FUT-6315) | the marker is written acknowledged and never selected: only ids the marketplace sent are acknowledged, and a store whose only unstamped row is a marker is neither called nor re-queued | same |
|
|
568
569
|
| A3 | the call fails (5xx, 429, timeout) | — | retried (3 attempts, exponential from 10 s); the rows stay owed; the last attempt leaves them for the sweep. A final 4xx is logged and leaves them owed until the 8 h window closes. Never blocks or fails the ingest | same |
|
|
569
570
|
| 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 |
|
|
570
571
|
| A5 | an event older than 8 h | — | never acknowledged (iFood keeps events 8 h) | same |
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
DisputeAnswerRetryError,
|
|
24
24
|
FetchOrderRetryError,
|
|
25
25
|
OutboundRetryError
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-T6A46MH3.js";
|
|
27
27
|
import {
|
|
28
28
|
__name
|
|
29
29
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -770,4 +770,4 @@ export {
|
|
|
770
770
|
MARKETPLACE_JOBS,
|
|
771
771
|
createApiMarketplace
|
|
772
772
|
};
|
|
773
|
-
//# sourceMappingURL=chunk-
|
|
773
|
+
//# sourceMappingURL=chunk-C2MFGZ3H.js.map
|
|
@@ -1508,6 +1508,44 @@ async function runCatalogue(ctx, payload, attempt) {
|
|
|
1508
1508
|
}
|
|
1509
1509
|
__name(runCatalogue, "runCatalogue");
|
|
1510
1510
|
|
|
1511
|
+
// src/core/order-fetch-marks.ts
|
|
1512
|
+
var CANCELLED_BEFORE_INGEST_REASON = "cancelled before its order body arrived";
|
|
1513
|
+
var CANCELLED_BEFORE_INGEST_EVENT_TYPE = "ENGINE_CANCELLED_BEFORE_INGEST";
|
|
1514
|
+
var markerId = /* @__PURE__ */ __name((externalOrderId) => `engine:cancelled:${externalOrderId}`, "markerId");
|
|
1515
|
+
async function markCancelledBeforeIngest(ctx, input) {
|
|
1516
|
+
const db = await ctx.ports.db();
|
|
1517
|
+
try {
|
|
1518
|
+
await db.marketplaceInboxEvent.create({
|
|
1519
|
+
data: {
|
|
1520
|
+
clientId: input.clientId,
|
|
1521
|
+
provider: input.provider,
|
|
1522
|
+
eventId: markerId(input.externalOrderId),
|
|
1523
|
+
eventType: CANCELLED_BEFORE_INGEST_EVENT_TYPE,
|
|
1524
|
+
externalOrderId: input.externalOrderId,
|
|
1525
|
+
payload: {},
|
|
1526
|
+
status: "IGNORED",
|
|
1527
|
+
error: "cancelled before the order was ingested",
|
|
1528
|
+
receivedAt: ctx.ports.clock.now(),
|
|
1529
|
+
processedAt: ctx.ports.clock.now(),
|
|
1530
|
+
acknowledgedAt: ctx.ports.clock.now()
|
|
1531
|
+
},
|
|
1532
|
+
select: { id: true }
|
|
1533
|
+
});
|
|
1534
|
+
} catch (error) {
|
|
1535
|
+
if (error.code !== "P2002") throw error;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
__name(markCancelledBeforeIngest, "markCancelledBeforeIngest");
|
|
1539
|
+
async function cancelledBeforeIngest(ctx, input) {
|
|
1540
|
+
const db = await ctx.ports.db();
|
|
1541
|
+
const row = await db.marketplaceInboxEvent.findUnique({
|
|
1542
|
+
where: { provider_eventId: { provider: input.provider, eventId: markerId(input.externalOrderId) } },
|
|
1543
|
+
select: { clientId: true }
|
|
1544
|
+
});
|
|
1545
|
+
return row !== null && row.clientId === input.clientId;
|
|
1546
|
+
}
|
|
1547
|
+
__name(cancelledBeforeIngest, "cancelledBeforeIngest");
|
|
1548
|
+
|
|
1511
1549
|
// src/core/acknowledge.ts
|
|
1512
1550
|
var MARKETPLACE_ACKNOWLEDGE_JOB = "marketplace.acknowledge";
|
|
1513
1551
|
var AcknowledgeRetryError = class extends Error {
|
|
@@ -1523,6 +1561,7 @@ function acknowledgementOf(ctx, provider) {
|
|
|
1523
1561
|
return ctx.registry.get(provider)?.acknowledgement ?? null;
|
|
1524
1562
|
}
|
|
1525
1563
|
__name(acknowledgementOf, "acknowledgementOf");
|
|
1564
|
+
var SENT_BY_THE_MARKETPLACE = { eventType: { not: CANCELLED_BEFORE_INGEST_EVENT_TYPE } };
|
|
1526
1565
|
var SWEEP_STORES = 500;
|
|
1527
1566
|
function windowStart(ctx, retentionMs) {
|
|
1528
1567
|
return new Date(ctx.ports.clock.now().getTime() - retentionMs);
|
|
@@ -1550,7 +1589,8 @@ async function runAcknowledge(ctx, payload, attempt) {
|
|
|
1550
1589
|
clientId: payload.clientId,
|
|
1551
1590
|
provider: payload.provider,
|
|
1552
1591
|
acknowledgedAt: null,
|
|
1553
|
-
receivedAt: { gte: windowStart(ctx, acknowledgement.retentionMs) }
|
|
1592
|
+
receivedAt: { gte: windowStart(ctx, acknowledgement.retentionMs) },
|
|
1593
|
+
...SENT_BY_THE_MARKETPLACE
|
|
1554
1594
|
},
|
|
1555
1595
|
orderBy: { receivedAt: "asc" },
|
|
1556
1596
|
take: acknowledgement.batchSize,
|
|
@@ -1600,7 +1640,13 @@ async function sweepAcknowledgements(ctx) {
|
|
|
1600
1640
|
const acknowledgement = acknowledgementOf(ctx, provider);
|
|
1601
1641
|
if (!acknowledgement) continue;
|
|
1602
1642
|
const rows = await db.marketplaceInboxEvent.findMany({
|
|
1603
|
-
where: {
|
|
1643
|
+
where: {
|
|
1644
|
+
provider,
|
|
1645
|
+
acknowledgedAt: null,
|
|
1646
|
+
clientId: { not: null },
|
|
1647
|
+
receivedAt: { gte: windowStart(ctx, acknowledgement.retentionMs) },
|
|
1648
|
+
...SENT_BY_THE_MARKETPLACE
|
|
1649
|
+
},
|
|
1604
1650
|
// One row per store, bounded: the next pass takes the rest.
|
|
1605
1651
|
distinct: ["clientId"],
|
|
1606
1652
|
take: SWEEP_STORES,
|
|
@@ -2252,43 +2298,6 @@ async function cancelAcceptance(ctx, input) {
|
|
|
2252
2298
|
}
|
|
2253
2299
|
__name(cancelAcceptance, "cancelAcceptance");
|
|
2254
2300
|
|
|
2255
|
-
// src/core/order-fetch-marks.ts
|
|
2256
|
-
var CANCELLED_BEFORE_INGEST_REASON = "cancelled before its order body arrived";
|
|
2257
|
-
var MARKER_TYPE = "ENGINE_CANCELLED_BEFORE_INGEST";
|
|
2258
|
-
var markerId = /* @__PURE__ */ __name((externalOrderId) => `engine:cancelled:${externalOrderId}`, "markerId");
|
|
2259
|
-
async function markCancelledBeforeIngest(ctx, input) {
|
|
2260
|
-
const db = await ctx.ports.db();
|
|
2261
|
-
try {
|
|
2262
|
-
await db.marketplaceInboxEvent.create({
|
|
2263
|
-
data: {
|
|
2264
|
-
clientId: input.clientId,
|
|
2265
|
-
provider: input.provider,
|
|
2266
|
-
eventId: markerId(input.externalOrderId),
|
|
2267
|
-
eventType: MARKER_TYPE,
|
|
2268
|
-
externalOrderId: input.externalOrderId,
|
|
2269
|
-
payload: {},
|
|
2270
|
-
status: "IGNORED",
|
|
2271
|
-
error: "cancelled before the order was ingested",
|
|
2272
|
-
receivedAt: ctx.ports.clock.now(),
|
|
2273
|
-
processedAt: ctx.ports.clock.now()
|
|
2274
|
-
},
|
|
2275
|
-
select: { id: true }
|
|
2276
|
-
});
|
|
2277
|
-
} catch (error) {
|
|
2278
|
-
if (error.code !== "P2002") throw error;
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
__name(markCancelledBeforeIngest, "markCancelledBeforeIngest");
|
|
2282
|
-
async function cancelledBeforeIngest(ctx, input) {
|
|
2283
|
-
const db = await ctx.ports.db();
|
|
2284
|
-
const row = await db.marketplaceInboxEvent.findUnique({
|
|
2285
|
-
where: { provider_eventId: { provider: input.provider, eventId: markerId(input.externalOrderId) } },
|
|
2286
|
-
select: { clientId: true }
|
|
2287
|
-
});
|
|
2288
|
-
return row !== null && row.clientId === input.clientId;
|
|
2289
|
-
}
|
|
2290
|
-
__name(cancelledBeforeIngest, "cancelledBeforeIngest");
|
|
2291
|
-
|
|
2292
2301
|
// src/core/fetch-order.ts
|
|
2293
2302
|
var MARKETPLACE_FETCH_ORDER_JOB = "marketplace.fetch-order";
|
|
2294
2303
|
var FetchOrderRetryError = class extends Error {
|
|
@@ -3470,6 +3479,9 @@ export {
|
|
|
3470
3479
|
enqueueCatalogue,
|
|
3471
3480
|
runCatalogue,
|
|
3472
3481
|
validatePickupCode,
|
|
3482
|
+
CANCELLED_BEFORE_INGEST_REASON,
|
|
3483
|
+
markCancelledBeforeIngest,
|
|
3484
|
+
cancelledBeforeIngest,
|
|
3473
3485
|
MARKETPLACE_ACKNOWLEDGE_JOB,
|
|
3474
3486
|
AcknowledgeRetryError,
|
|
3475
3487
|
enqueueAcknowledge,
|
|
@@ -3487,9 +3499,6 @@ export {
|
|
|
3487
3499
|
DisputeAnswerRetryError,
|
|
3488
3500
|
runDisputeAnswer,
|
|
3489
3501
|
ingestMarketplaceOrder,
|
|
3490
|
-
CANCELLED_BEFORE_INGEST_REASON,
|
|
3491
|
-
markCancelledBeforeIngest,
|
|
3492
|
-
cancelledBeforeIngest,
|
|
3493
3502
|
MARKETPLACE_FETCH_ORDER_JOB,
|
|
3494
3503
|
FetchOrderRetryError,
|
|
3495
3504
|
awaitOrderBody,
|
|
@@ -3514,4 +3523,4 @@ export {
|
|
|
3514
3523
|
AvailabilityRetryError,
|
|
3515
3524
|
runAvailability
|
|
3516
3525
|
};
|
|
3517
|
-
//# sourceMappingURL=chunk-
|
|
3526
|
+
//# sourceMappingURL=chunk-T6A46MH3.js.map
|