@12-apps/marketplace 1.7.0 → 1.9.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 (96) hide show
  1. package/ADOPTING.md +17 -0
  2. package/README.md +153 -3
  3. package/dist/99food/index.d.ts +30 -52
  4. package/dist/99food/index.js +62 -391
  5. package/dist/99food/index.js.map +1 -1
  6. package/dist/{adapter-DOjTak1H.d.ts → adapter-CYJzu1c9.d.ts} +45 -1
  7. package/dist/{chunk-YVUZHXUF.js → chunk-6N2HEV3U.js} +4 -4
  8. package/dist/chunk-6N2HEV3U.js.map +1 -0
  9. package/dist/{chunk-SJUKBCVO.js → chunk-BMCERPQX.js} +198 -12
  10. package/dist/chunk-BMCERPQX.js.map +1 -0
  11. package/dist/{chunk-L3DCOZUU.js → chunk-HEXLCTOG.js} +1 -1
  12. package/dist/chunk-HEXLCTOG.js.map +1 -0
  13. package/dist/{chunk-UYFYGGCS.js → chunk-NP4EYKPO.js} +3 -1
  14. package/dist/chunk-NP4EYKPO.js.map +1 -0
  15. package/dist/chunk-PYHNM47K.js +478 -0
  16. package/dist/chunk-PYHNM47K.js.map +1 -0
  17. package/dist/client-B4EQCRD_.d.ts +20 -0
  18. package/dist/{engine-DG1fg43Y.d.ts → engine-wmW-VuBL.d.ts} +107 -4
  19. package/dist/hono/index.d.ts +2 -2
  20. package/dist/hono/index.js +3 -3
  21. package/dist/ifood/index.d.ts +1 -1
  22. package/dist/ifood/index.js +29 -3
  23. package/dist/ifood/index.js.map +1 -1
  24. package/dist/index.d.ts +3 -3
  25. package/dist/index.js +104 -7
  26. package/dist/index.js.map +1 -1
  27. package/dist/keeta/en-US.d.ts +19 -0
  28. package/dist/keeta/en-US.js +23 -0
  29. package/dist/keeta/en-US.js.map +1 -0
  30. package/dist/keeta/index.d.ts +253 -0
  31. package/dist/keeta/index.js +388 -0
  32. package/dist/keeta/index.js.map +1 -0
  33. package/dist/keeta/pt-BR.d.ts +23 -0
  34. package/dist/keeta/pt-BR.js +23 -0
  35. package/dist/keeta/pt-BR.js.map +1 -0
  36. package/dist/manifest/index.d.ts +3 -0
  37. package/dist/manifest/index.js +1 -1
  38. package/dist/manifest/server.d.ts +2 -2
  39. package/dist/manifest/server.js +3 -3
  40. package/dist/rappi/index.d.ts +7 -1
  41. package/dist/rappi/index.js +20 -3
  42. package/dist/rappi/index.js.map +1 -1
  43. package/dist/server/index.d.ts +6 -2
  44. package/dist/server/index.js +3 -3
  45. package/package.json +14 -2
  46. package/prisma/marketplace.prisma +45 -1
  47. package/prisma/migrations/20261126120000_marketplace_status_updates/migration.sql +60 -0
  48. package/src/99food/catalogue.ts +19 -89
  49. package/src/99food/copy.ts +4 -19
  50. package/src/99food/index.ts +29 -28
  51. package/src/99food/normalize.ts +11 -247
  52. package/src/99food/outbound.ts +29 -215
  53. package/src/99food/pause.ts +7 -22
  54. package/src/core/adapter.ts +41 -1
  55. package/src/core/bulk.ts +1 -1
  56. package/src/core/engine.ts +9 -0
  57. package/src/core/ingest.ts +6 -0
  58. package/src/core/integration.ts +17 -0
  59. package/src/core/lifecycle-port.ts +16 -0
  60. package/src/core/lifecycle.ts +133 -0
  61. package/src/core/outbound-queue.ts +24 -4
  62. package/src/core/outbound-sweep.ts +49 -5
  63. package/src/core/outbound.ts +11 -0
  64. package/src/core/pipeline.ts +22 -2
  65. package/src/core/ports.ts +39 -3
  66. package/src/core/status-inform.ts +51 -0
  67. package/src/core/status-job.ts +207 -0
  68. package/src/core/status-store.ts +85 -0
  69. package/src/core/types.ts +14 -0
  70. package/src/ifood/index.ts +7 -1
  71. package/src/ifood/normalize.ts +17 -0
  72. package/src/ifood/outbound.ts +35 -0
  73. package/src/index.ts +8 -1
  74. package/src/keeta/authorization.ts +226 -0
  75. package/src/keeta/copy.ts +27 -0
  76. package/src/keeta/en-US.ts +19 -0
  77. package/src/keeta/index.ts +162 -0
  78. package/src/keeta/merchant.ts +70 -0
  79. package/src/keeta/normalize.ts +131 -0
  80. package/src/keeta/outbound.ts +55 -0
  81. package/src/keeta/pt-BR.ts +23 -0
  82. package/src/keeta/signature.ts +85 -0
  83. package/src/open-delivery/client.ts +185 -0
  84. package/src/open-delivery/merchant.ts +126 -0
  85. package/src/open-delivery/normalize.ts +269 -0
  86. package/src/open-delivery/orders.ts +241 -0
  87. package/src/open-delivery/reasons.ts +26 -0
  88. package/src/rappi/index.ts +6 -1
  89. package/src/rappi/normalize.ts +6 -0
  90. package/src/rappi/outbound.ts +31 -2
  91. package/src/server/mcp.ts +2 -0
  92. package/src/server/webhook.ts +3 -1
  93. package/dist/chunk-L3DCOZUU.js.map +0 -1
  94. package/dist/chunk-SJUKBCVO.js.map +0 -1
  95. package/dist/chunk-UYFYGGCS.js.map +0 -1
  96. package/dist/chunk-YVUZHXUF.js.map +0 -1
@@ -79,13 +79,17 @@ __name(suggestReason, "suggestReason");
79
79
  // src/core/outbound-queue.ts
80
80
  var MARKETPLACE_OUTBOUND_JOB = "marketplace.outbound";
81
81
  function outboundDedupeKey(payload) {
82
- return `${MARKETPLACE_OUTBOUND_JOB}:${payload.action}:${payload.orderId}`;
82
+ return `${MARKETPLACE_OUTBOUND_JOB}:${payload.action}:${payload.step ? `${payload.step}:` : ""}${payload.orderId}`;
83
83
  }
84
84
  __name(outboundDedupeKey, "outboundDedupeKey");
85
+ function statusDedupeKey(step, orderId, at) {
86
+ return `${MARKETPLACE_OUTBOUND_JOB}:status:${step}:${orderId}:${at.getTime()}`;
87
+ }
88
+ __name(statusDedupeKey, "statusDedupeKey");
85
89
  async function enqueueOutbound(ctx, payload, provider, dedupeKey = outboundDedupeKey(payload)) {
86
90
  const adapter = ctx.registry.get(provider);
87
91
  if (!adapter) return false;
88
- const able = payload.action === "confirm" ? adapter.capabilities.apiConfirm : adapter.capabilities.apiCancel;
92
+ const able = payload.action === "status" ? Boolean(payload.step && adapter.capabilities.statusSteps?.includes(payload.step)) : payload.action === "confirm" ? adapter.capabilities.apiConfirm : adapter.capabilities.apiCancel;
89
93
  if (!able) return false;
90
94
  const outcome = await ctx.ports.enqueue.enqueue(MARKETPLACE_OUTBOUND_JOB, payload, { dedupeKey });
91
95
  if (!outcome.enqueued) {
@@ -165,6 +169,7 @@ var VIEW_SELECT = {
165
169
  status: true,
166
170
  externalMerchantId: true,
167
171
  autoAccept: true,
172
+ followStatus: true,
168
173
  ackSlaSeconds: true,
169
174
  credentials: true,
170
175
  lastEventAt: true,
@@ -179,6 +184,7 @@ function toView(row) {
179
184
  status: row.status,
180
185
  externalMerchantId: row.externalMerchantId,
181
186
  autoAccept: row.autoAccept,
187
+ followStatus: row.followStatus ?? true,
182
188
  ackSlaSeconds: row.ackSlaSeconds,
183
189
  connected: row.credentials !== "",
184
190
  lastEventAt: row.lastEventAt,
@@ -208,6 +214,7 @@ async function saveMarketplaceIntegration(ctx, input, db) {
208
214
  ...input.environment === void 0 ? {} : { environment: input.environment },
209
215
  ...input.externalMerchantId === void 0 ? {} : { externalMerchantId: input.externalMerchantId },
210
216
  ...input.autoAccept === void 0 ? {} : { autoAccept: input.autoAccept },
217
+ ...input.followStatus === void 0 ? {} : { followStatus: input.followStatus },
211
218
  ...input.ackSlaSeconds === void 0 ? {} : { ackSlaSeconds: input.ackSlaSeconds },
212
219
  ...sealed === void 0 ? {} : { credentials: sealed, status: "UNVERIFIED" }
213
220
  };
@@ -242,6 +249,7 @@ async function resolveIngestionTarget(ctx, clientId, provider) {
242
249
  select: {
243
250
  enabled: true,
244
251
  autoAccept: true,
252
+ followStatus: true,
245
253
  ackSlaSeconds: true,
246
254
  credentials: true,
247
255
  archivedAt: true,
@@ -252,6 +260,7 @@ async function resolveIngestionTarget(ctx, clientId, provider) {
252
260
  return {
253
261
  enabled: row.enabled,
254
262
  autoAccept: row.autoAccept,
263
+ followStatus: row.followStatus ?? true,
255
264
  ackSlaSeconds: row.ackSlaSeconds,
256
265
  externalMerchantId: row.externalMerchantId ?? null,
257
266
  // An unopenable blob must not read as "no secret configured" — that would
@@ -1255,20 +1264,58 @@ async function sweepCatalogue(ctx, now) {
1255
1264
  }
1256
1265
  __name(sweepCatalogue, "sweepCatalogue");
1257
1266
 
1267
+ // src/core/status-store.ts
1268
+ function statusTable(db) {
1269
+ return db.marketplaceStatusUpdate ?? null;
1270
+ }
1271
+ __name(statusTable, "statusTable");
1272
+ async function readStatusRows(table, orderId, steps2) {
1273
+ return await table.findMany({
1274
+ where: { orderId, step: { in: [...steps2] } },
1275
+ select: { orderId: true, step: true, source: true, state: true, claimKey: true }
1276
+ });
1277
+ }
1278
+ __name(readStatusRows, "readStatusRows");
1279
+ async function insertStatusRow(table, row) {
1280
+ try {
1281
+ await table.create({ data: row });
1282
+ return true;
1283
+ } catch (error) {
1284
+ if (error.code === "P2002") return false;
1285
+ throw error;
1286
+ }
1287
+ }
1288
+ __name(insertStatusRow, "insertStatusRow");
1289
+ async function noteMarketplaceStep(ctx, row) {
1290
+ const table = statusTable(await ctx.ports.db());
1291
+ if (table) await insertStatusRow(table, { ...row, source: "MARKETPLACE", state: "NOTED", claimKey: "" });
1292
+ }
1293
+ __name(noteMarketplaceStep, "noteMarketplaceStep");
1294
+ async function settleStatusRow(table, where, state) {
1295
+ return (await table.updateMany({ where: { ...where, state: "SENDING" }, data: { state } })).count;
1296
+ }
1297
+ __name(settleStatusRow, "settleStatusRow");
1298
+
1258
1299
  // src/core/outbound-sweep.ts
1259
1300
  var OUTBOUND_STALE_MS = 10 * 6e4;
1260
1301
  var OUTBOUND_GIVE_UP_MS = 24 * 60 * 6e4;
1261
1302
  var WAITING = ["PENDING", "REQUESTED"];
1262
1303
  var OWED_SELECT = { clientId: true, orderId: true, provider: true };
1263
- function sweepDedupeKey(action, orderId, now) {
1264
- return `${MARKETPLACE_OUTBOUND_JOB}:${action}:${orderId}:sweep:${now.getTime()}`;
1304
+ function sweepDedupeKey(action, orderId, now, step) {
1305
+ return `${MARKETPLACE_OUTBOUND_JOB}:${action}:${step ? `${step}:` : ""}${orderId}:sweep:${now.getTime()}`;
1265
1306
  }
1266
1307
  __name(sweepDedupeKey, "sweepDedupeKey");
1267
1308
  async function requeue(ctx, rows, action, now) {
1268
1309
  let queued = 0;
1269
1310
  for (const row of rows) {
1270
- const payload = { clientId: row.clientId, orderId: row.orderId, action };
1271
- if (await enqueueOutbound(ctx, payload, row.provider, sweepDedupeKey(action, row.orderId, now))) queued += 1;
1311
+ const payload = {
1312
+ clientId: row.clientId,
1313
+ orderId: row.orderId,
1314
+ action,
1315
+ ...row.step ? { step: row.step } : {},
1316
+ ...row.claimKey === void 0 ? {} : { claimKey: row.claimKey }
1317
+ };
1318
+ if (await enqueueOutbound(ctx, payload, row.provider, sweepDedupeKey(action, row.orderId, now, row.step))) queued += 1;
1272
1319
  }
1273
1320
  return queued;
1274
1321
  }
@@ -1310,6 +1357,29 @@ async function expireUnanswered(ctx, now) {
1310
1357
  return expired;
1311
1358
  }
1312
1359
  __name(expireUnanswered, "expireUnanswered");
1360
+ async function sweepStatus(ctx, now) {
1361
+ const table = statusTable(await ctx.ports.db());
1362
+ if (!table) return { requeued: 0, givenUp: 0 };
1363
+ const stale = new Date(now.getTime() - OUTBOUND_STALE_MS);
1364
+ const giveUp = new Date(now.getTime() - OUTBOUND_GIVE_UP_MS);
1365
+ const givenUp = (await table.updateMany({ where: { state: "SENDING", updatedAt: { lt: giveUp } }, data: { state: "FAILED" } })).count;
1366
+ if (givenUp > 0) ctx.ports.logger.error(`marketplace.outbound-sweep: gave up on ${givenUp} status call(s).`);
1367
+ const owed = await table.findMany({
1368
+ where: { state: "SENDING", source: "STORE", updatedAt: { lt: stale, gte: giveUp } },
1369
+ select: { clientId: true, orderId: true, provider: true, step: true, claimKey: true }
1370
+ });
1371
+ const claimed = [];
1372
+ for (const row of owed) {
1373
+ const fresh = `sweep:${now.getTime()}`;
1374
+ const taken = await table.updateMany({
1375
+ where: { orderId: row.orderId, step: row.step, state: "SENDING", claimKey: row.claimKey, updatedAt: { lt: stale } },
1376
+ data: { claimKey: fresh }
1377
+ });
1378
+ if (taken.count > 0) claimed.push({ ...row, claimKey: fresh });
1379
+ }
1380
+ return { requeued: await requeue(ctx, claimed, "status", now), givenUp };
1381
+ }
1382
+ __name(sweepStatus, "sweepStatus");
1313
1383
  async function sweepOutbound(ctx, now) {
1314
1384
  const db = await ctx.ports.db();
1315
1385
  const stale = new Date(now.getTime() - OUTBOUND_STALE_MS);
@@ -1334,10 +1404,113 @@ async function sweepOutbound(ctx, now) {
1334
1404
  const requeued = await requeue(ctx, cancellations, "requestCancellation", now) + await requeue(ctx, confirms, "confirm", now);
1335
1405
  if (givenUp > 0) ctx.ports.logger.error(`marketplace.outbound-sweep: gave up on ${givenUp} cancellation request(s).`);
1336
1406
  const catalogueRequeued = await sweepCatalogue(ctx, now);
1337
- return { requeued, givenUp, timedOut, catalogueRequeued };
1407
+ const status = await sweepStatus(ctx, now);
1408
+ return { requeued: requeued + status.requeued, givenUp: givenUp + status.givenUp, timedOut, catalogueRequeued };
1338
1409
  }
1339
1410
  __name(sweepOutbound, "sweepOutbound");
1340
1411
 
1412
+ // src/core/status-job.ts
1413
+ function deliveredByOf(row) {
1414
+ return row.deliveredBy === "MERCHANT" || row.deliveredBy === "MARKETPLACE" ? row.deliveredBy : null;
1415
+ }
1416
+ __name(deliveredByOf, "deliveredByOf");
1417
+ var skipped = /* @__PURE__ */ __name((reason) => ({ kind: "skipped", reason }), "skipped");
1418
+ function acceptanceSkip(row) {
1419
+ if (row.status !== "ACCEPTED") return `the order is ${row.status}, not ACCEPTED`;
1420
+ const standing = row.cancellationStatus !== null && row.cancellationStatus !== "FAILED";
1421
+ return standing ? `a cancellation request is ${row.cancellationStatus}` : null;
1422
+ }
1423
+ __name(acceptanceSkip, "acceptanceSkip");
1424
+ async function adapterAndHostSkip(ctx, payload, step, row, adapter) {
1425
+ const takes = adapter.informStatus !== void 0 && adapter.capabilities.statusSteps?.includes(step) === true && adapter.statusSupported?.({ step, deliveredBy: deliveredByOf(row) }) !== false;
1426
+ if (!takes) return `the marketplace does not take ${step} for this order`;
1427
+ const holds2 = ctx.ports.order.statusHolds;
1428
+ if (!holds2) return "the host binds no statusHolds, so it cannot say the order still holds the step";
1429
+ return await holds2.call(ctx.ports.order, payload.clientId, row.orderId, step) ? null : `the order no longer holds ${step}`;
1430
+ }
1431
+ __name(adapterAndHostSkip, "adapterAndHostSkip");
1432
+ async function connectionOf(ctx, clientId, provider) {
1433
+ try {
1434
+ return await readOutboundConnection(ctx, clientId, provider) ?? "no credentials on file";
1435
+ } catch (error) {
1436
+ return `credentials do not open: ${error instanceof Error ? error.message : String(error)}`;
1437
+ }
1438
+ }
1439
+ __name(connectionOf, "connectionOf");
1440
+ function callAdapter(ctx, connection, adapter, row, step, ref) {
1441
+ const now = ctx.ports.clock.now();
1442
+ return adapter.informStatus({ http: ctx.ports.http, tokens: ctx.tokens, now, ...connection }, ref, {
1443
+ step,
1444
+ deliveredBy: deliveredByOf(row)
1445
+ });
1446
+ }
1447
+ __name(callAdapter, "callAdapter");
1448
+ async function settle2(ctx, db, where, result, deps) {
1449
+ const table = statusTable(db);
1450
+ if (result.kind === "accepted") {
1451
+ await settleStatusRow(table, where, "SENT");
1452
+ return { kind: "done", action: "status" };
1453
+ }
1454
+ const reason = result.kind === "refused" ? `refused ${result.status}: ${result.message}` : result.kind === "retry" ? result.reason : "the adapter answered unsupported after the claim";
1455
+ if (result.kind === "retry" && deps.attempt.attempt < deps.attempt.maxAttempts) {
1456
+ throw deps.retryError(`status ${where.step} for order ${where.orderId}: ${reason}`);
1457
+ }
1458
+ await settleStatusRow(table, where, "FAILED");
1459
+ ctx.ports.logger.error(`${MARKETPLACE_OUTBOUND_JOB}: status ${where.step} for order ${where.orderId} failed: ${reason}`);
1460
+ return { kind: "failed", action: "status", reason };
1461
+ }
1462
+ __name(settle2, "settle");
1463
+ function ownsClaim(found, key) {
1464
+ return found.source === "STORE" && found.state === "SENDING" && found.claimKey === key;
1465
+ }
1466
+ __name(ownsClaim, "ownsClaim");
1467
+ async function claim2(table, payload, row, step, key) {
1468
+ const rows = await readStatusRows(table, row.orderId, [step, "CONCLUDED"]);
1469
+ if (rows.some((found) => found.step === "CONCLUDED" && found.source === "MARKETPLACE")) {
1470
+ return "the marketplace concluded this order";
1471
+ }
1472
+ const own = rows.find((found) => found.step === step);
1473
+ if (own) return ownsClaim(own, key) ? null : `${step} is already ${own.state}${own.state === "SENDING" ? ", held by another run" : ""}`;
1474
+ const claimed = await insertStatusRow(table, {
1475
+ clientId: payload.clientId,
1476
+ orderId: row.orderId,
1477
+ provider: row.provider,
1478
+ step,
1479
+ source: "STORE",
1480
+ state: "SENDING",
1481
+ claimKey: key
1482
+ });
1483
+ return claimed ? null : `another run holds the claim on ${step}`;
1484
+ }
1485
+ __name(claim2, "claim");
1486
+ async function runStatus(ctx, payload, row, adapter, deps) {
1487
+ const step = payload.step;
1488
+ if (!step) return skipped("a status call names no step");
1489
+ const stopped = acceptanceSkip(row) ?? await adapterAndHostSkip(ctx, payload, step, row, adapter);
1490
+ if (stopped) return skipped(stopped);
1491
+ const db = await ctx.ports.db();
1492
+ const table = statusTable(db);
1493
+ if (!table) return skipped("the host has not composed the status model");
1494
+ const connection = await connectionOf(ctx, payload.clientId, row.provider);
1495
+ if (typeof connection === "string") {
1496
+ ctx.ports.logger.info(`${MARKETPLACE_OUTBOUND_JOB}: status ${step} for order ${row.orderId} not sent: ${connection}`);
1497
+ return skipped(connection);
1498
+ }
1499
+ const key = payload.claimKey ?? "";
1500
+ const unclaimed = await claim2(table, payload, row, step, key);
1501
+ if (unclaimed) return skipped(unclaimed);
1502
+ const result = await callAdapter(ctx, connection, adapter, row, step, deps.ref);
1503
+ return settle2(ctx, db, { orderId: row.orderId, step, claimKey: key }, result, deps);
1504
+ }
1505
+ __name(runStatus, "runStatus");
1506
+ async function failStatusRow(ctx, payload) {
1507
+ const table = statusTable(await ctx.ports.db());
1508
+ if (table && payload.step) {
1509
+ await settleStatusRow(table, { orderId: payload.orderId, step: payload.step, claimKey: payload.claimKey ?? "" }, "FAILED");
1510
+ }
1511
+ }
1512
+ __name(failStatusRow, "failStatusRow");
1513
+
1341
1514
  // src/core/outbound.ts
1342
1515
  var OutboundRetryError = class extends Error {
1343
1516
  static {
@@ -1356,6 +1529,7 @@ var ROW_SELECT = {
1356
1529
  status: true,
1357
1530
  confirmedAt: true,
1358
1531
  confirmFailedAt: true,
1532
+ deliveredBy: true,
1359
1533
  cancellationStatus: true,
1360
1534
  cancellationReasonCode: true,
1361
1535
  cancellationOffendingSkus: true,
@@ -1437,7 +1611,7 @@ async function connectionFor(ctx, clientId, provider) {
1437
1611
  }
1438
1612
  }
1439
1613
  __name(connectionFor, "connectionFor");
1440
- async function settle2(ctx, payload, row, result, attempt, succeed, fail3) {
1614
+ async function settle3(ctx, payload, row, result, attempt, succeed, fail3) {
1441
1615
  if (result.kind === "accepted") {
1442
1616
  await succeed();
1443
1617
  ctx.ports.publishChanged(payload.clientId);
@@ -1452,7 +1626,7 @@ async function settle2(ctx, payload, row, result, attempt, succeed, fail3) {
1452
1626
  ctx.ports.publishChanged(payload.clientId);
1453
1627
  return { kind: "failed", action: payload.action, reason };
1454
1628
  }
1455
- __name(settle2, "settle");
1629
+ __name(settle3, "settle");
1456
1630
  async function runConfirm(ctx, payload, row, adapter, attempt) {
1457
1631
  const skip = confirmSkip(row, adapter);
1458
1632
  if (skip) return { kind: "skipped", reason: skip };
@@ -1464,7 +1638,7 @@ async function runConfirm(ctx, payload, row, adapter, attempt) {
1464
1638
  // The stated preparation time, for a marketplace whose confirm takes one.
1465
1639
  { preparationMinutes: adapter.capabilities.confirmTakesPreparationTime ? row.preparationMinutes : null }
1466
1640
  );
1467
- return settle2(
1641
+ return settle3(
1468
1642
  ctx,
1469
1643
  payload,
1470
1644
  row,
@@ -1507,7 +1681,7 @@ async function runCancellation(ctx, payload, row, adapter, attempt) {
1507
1681
  );
1508
1682
  }
1509
1683
  const taken = adapter.capabilities.asyncCancellationOutcome ? "REQUESTED" : "CONFIRMED";
1510
- return settle2(
1684
+ return settle3(
1511
1685
  ctx,
1512
1686
  payload,
1513
1687
  row,
@@ -1520,6 +1694,11 @@ async function runCancellation(ctx, payload, row, adapter, attempt) {
1520
1694
  __name(runCancellation, "runCancellation");
1521
1695
  async function stampLastAttemptFailure(ctx, payload, error) {
1522
1696
  const reason = error instanceof Error ? error.message : String(error);
1697
+ if (payload.action === "status") {
1698
+ await failStatusRow(ctx, payload);
1699
+ ctx.ports.logger.error(`marketplace.outbound: status ${payload.step ?? ""} for order ${payload.orderId} failed: ${reason}`);
1700
+ return { kind: "failed", action: payload.action, reason };
1701
+ }
1523
1702
  const db = await ctx.ports.db();
1524
1703
  const moved = await (payload.action === "confirm" ? db.marketplaceAcceptance.updateMany({
1525
1704
  where: { orderId: payload.orderId, clientId: payload.clientId, confirmedAt: null, confirmFailedAt: null },
@@ -1545,6 +1724,9 @@ async function runOnce2(ctx, payload, attempt) {
1545
1724
  if (!row) return { kind: "skipped", reason: "no acceptance for this order" };
1546
1725
  const adapter = ctx.registry.get(row.provider);
1547
1726
  if (!adapter) return { kind: "skipped", reason: `no adapter for ${row.provider}` };
1727
+ if (payload.action === "status") {
1728
+ return runStatus(ctx, payload, row, adapter, { attempt, ref: refOf(row), retryError: /* @__PURE__ */ __name((m) => new OutboundRetryError(m), "retryError") });
1729
+ }
1548
1730
  return payload.action === "confirm" ? runConfirm(ctx, payload, row, adapter, attempt) : runCancellation(ctx, payload, row, adapter, attempt);
1549
1731
  }
1550
1732
  __name(runOnce2, "runOnce");
@@ -1967,6 +2149,7 @@ export {
1967
2149
  upsertLink,
1968
2150
  MARKETPLACE_OUTBOUND_JOB,
1969
2151
  outboundDedupeKey,
2152
+ statusDedupeKey,
1970
2153
  enqueueOutbound,
1971
2154
  CATALOGUE_ROW_SELECT,
1972
2155
  catalogueTable,
@@ -1994,6 +2177,9 @@ export {
1994
2177
  runFetchOrder,
1995
2178
  CATALOGUE_STALE_MS,
1996
2179
  CATALOGUE_GIVE_UP_MS,
2180
+ statusTable,
2181
+ readStatusRows,
2182
+ noteMarketplaceStep,
1997
2183
  OUTBOUND_STALE_MS,
1998
2184
  OUTBOUND_GIVE_UP_MS,
1999
2185
  sweepOutbound,
@@ -2010,4 +2196,4 @@ export {
2010
2196
  AvailabilityRetryError,
2011
2197
  runAvailability
2012
2198
  };
2013
- //# sourceMappingURL=chunk-SJUKBCVO.js.map
2199
+ //# sourceMappingURL=chunk-BMCERPQX.js.map