@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.
- package/ADOPTING.md +90 -1
- package/README.md +37 -1
- package/dist/99food/index.d.ts +2 -2
- package/dist/99food/index.js +2 -2
- package/dist/{adapter-CD0SfdVS.d.ts → adapter-nUyZpLzz.d.ts} +325 -173
- package/dist/{chunk-YWMEIMO3.js → chunk-45ZVN5XI.js} +114 -24
- package/dist/chunk-45ZVN5XI.js.map +1 -0
- package/dist/{chunk-DCWOQ5PN.js → chunk-L6FG6T4S.js} +2 -2
- package/dist/{chunk-TVZU4HNT.js → chunk-LACBT6NC.js} +1 -1
- package/dist/{chunk-TVZU4HNT.js.map → chunk-LACBT6NC.js.map} +1 -1
- package/dist/{chunk-OS4TSIFU.js → chunk-MIPNQ7X5.js} +2 -2
- package/dist/{client-11sncog4.d.ts → client-Ctas7WCS.d.ts} +1 -1
- package/dist/{engine-C_3RK8wC.d.ts → engine-CIy9P7Cq.d.ts} +34 -5
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +2 -2
- package/dist/ifood/index.d.ts +7 -2
- package/dist/ifood/index.js +184 -30
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +162 -65
- package/dist/index.js.map +1 -1
- package/dist/keeta/index.d.ts +2 -18
- package/dist/keeta/index.js +12 -3
- package/dist/keeta/index.js.map +1 -1
- package/dist/manifest/server.d.ts +2 -2
- package/dist/manifest/server.js +2 -2
- package/dist/rappi/index.d.ts +1 -1
- package/dist/rappi/index.js +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +2 -2
- package/package.json +1 -1
- package/src/core/adapter.ts +6 -0
- package/src/core/courier-port.ts +100 -0
- package/src/core/courier.ts +153 -0
- package/src/core/engine.ts +4 -1
- package/src/core/lifecycle.ts +27 -4
- package/src/core/outbound-queue.ts +24 -11
- package/src/core/outbound.ts +8 -6
- package/src/core/pickup-code.ts +136 -0
- package/src/core/pipeline.ts +15 -6
- package/src/core/ports.ts +23 -1
- package/src/core/status-store.ts +2 -3
- package/src/core/types.ts +56 -4
- package/src/ifood/courier.ts +210 -0
- package/src/ifood/index.ts +4 -0
- package/src/ifood/normalize.ts +7 -0
- package/src/index.ts +16 -0
- package/src/keeta/normalize.ts +21 -6
- package/dist/chunk-YWMEIMO3.js.map +0 -1
- /package/dist/{chunk-DCWOQ5PN.js.map → chunk-L6FG6T4S.js.map} +0 -0
- /package/dist/{chunk-OS4TSIFU.js.map → chunk-MIPNQ7X5.js.map} +0 -0
|
@@ -144,11 +144,21 @@ function statusDedupeKey(step, orderId, at) {
|
|
|
144
144
|
return `${MARKETPLACE_OUTBOUND_JOB}:status:${step}:${orderId}:${at.getTime()}`;
|
|
145
145
|
}
|
|
146
146
|
__name(statusDedupeKey, "statusDedupeKey");
|
|
147
|
+
function ableTo(adapter, payload) {
|
|
148
|
+
switch (payload.action) {
|
|
149
|
+
case "status":
|
|
150
|
+
return Boolean(payload.step && adapter.capabilities.statusSteps?.includes(payload.step));
|
|
151
|
+
case "confirm":
|
|
152
|
+
return adapter.capabilities.apiConfirm;
|
|
153
|
+
default:
|
|
154
|
+
return adapter.capabilities.apiCancel;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
__name(ableTo, "ableTo");
|
|
147
158
|
async function enqueueOutbound(ctx, payload, provider, dedupeKey = outboundDedupeKey(payload)) {
|
|
148
159
|
const adapter = ctx.registry.get(provider);
|
|
149
160
|
if (!adapter) return false;
|
|
150
|
-
|
|
151
|
-
if (!able) return false;
|
|
161
|
+
if (!ableTo(adapter, payload)) return false;
|
|
152
162
|
const outcome = await ctx.ports.enqueue.enqueue(MARKETPLACE_OUTBOUND_JOB, payload, { dedupeKey });
|
|
153
163
|
if (!outcome.enqueued) {
|
|
154
164
|
ctx.ports.logger.warn(
|
|
@@ -315,12 +325,12 @@ function linkGrant(ctx, link) {
|
|
|
315
325
|
}
|
|
316
326
|
const pending = running.get(key);
|
|
317
327
|
if (pending) return pending;
|
|
318
|
-
const
|
|
328
|
+
const call2 = refreshOnce(ctx, link, key).catch((error) => ({
|
|
319
329
|
kind: "retry",
|
|
320
330
|
reason: error instanceof Error ? error.message : String(error)
|
|
321
331
|
})).finally(() => running.delete(key));
|
|
322
|
-
running.set(key,
|
|
323
|
-
return
|
|
332
|
+
running.set(key, call2);
|
|
333
|
+
return call2;
|
|
324
334
|
}, "accessToken")
|
|
325
335
|
};
|
|
326
336
|
}
|
|
@@ -589,21 +599,21 @@ async function enqueueCatalogue(ctx, payload, dedupeKey) {
|
|
|
589
599
|
);
|
|
590
600
|
}
|
|
591
601
|
__name(enqueueCatalogue, "enqueueCatalogue");
|
|
592
|
-
async function callFor(ctx, row, action, catalogue,
|
|
602
|
+
async function callFor(ctx, row, action, catalogue, call2) {
|
|
593
603
|
if (action === "withdraw") {
|
|
594
|
-
if (catalogue.mode === "pull") return { result: await catalogue.notifyMenuChanged(
|
|
604
|
+
if (catalogue.mode === "pull") return { result: await catalogue.notifyMenuChanged(call2), sentPriceCents: null };
|
|
595
605
|
const ref = { ref: row.id, productId: row.productId, externalId: row.externalId };
|
|
596
|
-
return { result: await catalogue.withdrawItem(
|
|
606
|
+
return { result: await catalogue.withdrawItem(call2, ref), sentPriceCents: null };
|
|
597
607
|
}
|
|
598
608
|
const item = (await ctx.ports.catalogue?.items(row.clientId, [row.productId]))?.get(row.productId);
|
|
599
609
|
if (!item) return { code: "PRODUCT_GONE" };
|
|
600
610
|
const priceCents = row.priceCents ?? item.priceCents;
|
|
601
611
|
if (catalogue.mode === "pull") {
|
|
602
|
-
return { result: await catalogue.notifyMenuChanged(
|
|
612
|
+
return { result: await catalogue.notifyMenuChanged(call2), sentPriceCents: priceCents, name: item.name };
|
|
603
613
|
}
|
|
604
614
|
const storedImage = row.imageRef && row.imageSourceUrl ? { ref: row.imageRef, sourceUrl: row.imageSourceUrl } : null;
|
|
605
615
|
const out = { ...item, priceCents, ref: row.id, productId: row.productId, externalId: row.externalId, storedImage };
|
|
606
|
-
return { result: await catalogue.publishItem(
|
|
616
|
+
return { result: await catalogue.publishItem(call2, out), sentPriceCents: priceCents, name: item.name };
|
|
607
617
|
}
|
|
608
618
|
__name(callFor, "callFor");
|
|
609
619
|
var stillAsked = /* @__PURE__ */ __name((row, action) => ({
|
|
@@ -1018,9 +1028,9 @@ async function ingestMarketplaceOrder(ctx, input) {
|
|
|
1018
1028
|
__name(ingestMarketplaceOrder, "ingestMarketplaceOrder");
|
|
1019
1029
|
|
|
1020
1030
|
// src/core/cancellation-outcome.ts
|
|
1021
|
-
async function tell(ctx, what, orderId,
|
|
1031
|
+
async function tell(ctx, what, orderId, call2) {
|
|
1022
1032
|
try {
|
|
1023
|
-
await
|
|
1033
|
+
await call2();
|
|
1024
1034
|
} catch (error) {
|
|
1025
1035
|
ctx.ports.logger.error(
|
|
1026
1036
|
`marketplace.cancellation: order ${orderId} ${what} but the host's half failed: ` + (error instanceof Error ? error.message : String(error))
|
|
@@ -1595,6 +1605,84 @@ async function sweepOutbound(ctx, now) {
|
|
|
1595
1605
|
}
|
|
1596
1606
|
__name(sweepOutbound, "sweepOutbound");
|
|
1597
1607
|
|
|
1608
|
+
// src/core/pickup-code.ts
|
|
1609
|
+
async function validatePickupCode(ctx, input) {
|
|
1610
|
+
const payload = {
|
|
1611
|
+
clientId: input.clientId,
|
|
1612
|
+
orderId: input.orderId,
|
|
1613
|
+
action: "validatePickupCode",
|
|
1614
|
+
code: input.code
|
|
1615
|
+
};
|
|
1616
|
+
const dedupeKey = `${MARKETPLACE_OUTBOUND_JOB}:validatePickupCode:${input.orderId}:${input.at.getTime()}`;
|
|
1617
|
+
const notQueued = /* @__PURE__ */ __name((why) => {
|
|
1618
|
+
ctx.ports.logger.warn(`${MARKETPLACE_OUTBOUND_JOB}: validatePickupCode for order ${input.orderId} was not queued${why}`);
|
|
1619
|
+
return false;
|
|
1620
|
+
}, "notQueued");
|
|
1621
|
+
try {
|
|
1622
|
+
const outcome = await ctx.ports.enqueue.enqueue(MARKETPLACE_OUTBOUND_JOB, payload, { dedupeKey });
|
|
1623
|
+
return outcome.enqueued || notQueued(outcome.reason ? ` (${outcome.reason})` : "");
|
|
1624
|
+
} catch (error) {
|
|
1625
|
+
return notQueued(`: ${error instanceof Error ? error.message : String(error)}`);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
__name(validatePickupCode, "validatePickupCode");
|
|
1629
|
+
async function tellPickupCode(ctx, payload, validation) {
|
|
1630
|
+
const hook = ctx.ports.order.onPickupCodeValidated;
|
|
1631
|
+
const log = validation === "VALID" ? ctx.ports.logger.info : ctx.ports.logger.warn;
|
|
1632
|
+
log.call(ctx.ports.logger, `marketplace.outbound: pickup code of order ${payload.orderId}: ${validation}`);
|
|
1633
|
+
if (!hook) return;
|
|
1634
|
+
try {
|
|
1635
|
+
await hook.call(ctx.ports.order, payload.clientId, payload.orderId, validation);
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
ctx.ports.logger.error(
|
|
1638
|
+
`marketplace.outbound: the host's half of the pickup-code verdict for order ${payload.orderId} failed: ` + (error instanceof Error ? error.message : String(error))
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
__name(tellPickupCode, "tellPickupCode");
|
|
1643
|
+
function skipOf(payload, row, adapter) {
|
|
1644
|
+
if (!adapter.courier) return "the marketplace has no pickup-code check";
|
|
1645
|
+
if (row.status !== "ACCEPTED") return `the order is ${row.status}, not ACCEPTED`;
|
|
1646
|
+
if (row.deliveredBy !== "MARKETPLACE") return "the order is not carried by the marketplace's courier";
|
|
1647
|
+
return payload.code ? null : "no pickup code to send";
|
|
1648
|
+
}
|
|
1649
|
+
__name(skipOf, "skipOf");
|
|
1650
|
+
async function call(ctx, payload, row, adapter, ref) {
|
|
1651
|
+
let connection;
|
|
1652
|
+
try {
|
|
1653
|
+
connection = await readOutboundConnection(ctx, payload.clientId, row.provider);
|
|
1654
|
+
} catch (error) {
|
|
1655
|
+
const message = `credentials do not open: ${error instanceof Error ? error.message : String(error)}`;
|
|
1656
|
+
return { kind: "refused", status: 0, message, own: true };
|
|
1657
|
+
}
|
|
1658
|
+
if (!connection) return { kind: "refused", status: 0, message: "no credentials on file", own: true };
|
|
1659
|
+
return adapter.courier.validatePickupCode(
|
|
1660
|
+
{ http: ctx.ports.http, tokens: ctx.tokens, now: ctx.ports.clock.now(), ...connection },
|
|
1661
|
+
ref,
|
|
1662
|
+
{ code: payload.code }
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
__name(call, "call");
|
|
1666
|
+
async function runPickupCode(ctx, payload, row, adapter, deps) {
|
|
1667
|
+
const skip = skipOf(payload, row, adapter);
|
|
1668
|
+
if (skip) return { kind: "skipped", reason: skip };
|
|
1669
|
+
const result = await call(ctx, payload, row, adapter, deps.ref);
|
|
1670
|
+
if (result.kind === "answered") {
|
|
1671
|
+
await tellPickupCode(ctx, payload, result.valid ? "VALID" : "INVALID");
|
|
1672
|
+
ctx.ports.publishChanged(payload.clientId);
|
|
1673
|
+
return { kind: "done", action: "validatePickupCode" };
|
|
1674
|
+
}
|
|
1675
|
+
const reason = result.kind === "refused" ? `refused ${result.status}: ${result.message}` : result.reason;
|
|
1676
|
+
if (result.kind === "retry" && deps.attempt.attempt < deps.attempt.maxAttempts) {
|
|
1677
|
+
throw deps.retryError(`validatePickupCode for order ${row.orderId}: ${reason}`);
|
|
1678
|
+
}
|
|
1679
|
+
ctx.ports.logger.error(`marketplace.outbound: validatePickupCode for order ${row.orderId} failed: ${reason}`);
|
|
1680
|
+
await tellPickupCode(ctx, payload, "UNVERIFIED");
|
|
1681
|
+
ctx.ports.publishChanged(payload.clientId);
|
|
1682
|
+
return { kind: "failed", action: "validatePickupCode", reason };
|
|
1683
|
+
}
|
|
1684
|
+
__name(runPickupCode, "runPickupCode");
|
|
1685
|
+
|
|
1598
1686
|
// src/core/status-job.ts
|
|
1599
1687
|
function deliveredByOf(row) {
|
|
1600
1688
|
return row.deliveredBy === "MERCHANT" || row.deliveredBy === "MARKETPLACE" ? row.deliveredBy : null;
|
|
@@ -1880,9 +1968,10 @@ async function runCancellation(ctx, payload, row, adapter, attempt) {
|
|
|
1880
1968
|
__name(runCancellation, "runCancellation");
|
|
1881
1969
|
async function stampLastAttemptFailure(ctx, payload, error) {
|
|
1882
1970
|
const reason = error instanceof Error ? error.message : String(error);
|
|
1883
|
-
if (payload.action === "status") {
|
|
1884
|
-
await failStatusRow(ctx, payload);
|
|
1885
|
-
ctx
|
|
1971
|
+
if (payload.action === "status" || payload.action === "validatePickupCode") {
|
|
1972
|
+
if (payload.action === "status") await failStatusRow(ctx, payload);
|
|
1973
|
+
else await tellPickupCode(ctx, payload, "UNVERIFIED");
|
|
1974
|
+
ctx.ports.logger.error(`marketplace.outbound: ${payload.action}${payload.step ? ` ${payload.step}` : ""} for order ${payload.orderId} failed: ${reason}`);
|
|
1886
1975
|
return { kind: "failed", action: payload.action, reason };
|
|
1887
1976
|
}
|
|
1888
1977
|
const db = await ctx.ports.db();
|
|
@@ -1910,9 +1999,9 @@ async function runOnce2(ctx, payload, attempt) {
|
|
|
1910
1999
|
if (!row) return { kind: "skipped", reason: "no acceptance for this order" };
|
|
1911
2000
|
const adapter = ctx.registry.get(row.provider);
|
|
1912
2001
|
if (!adapter) return { kind: "skipped", reason: `no adapter for ${row.provider}` };
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
2002
|
+
const deps = { attempt, ref: refOf(row), retryError: /* @__PURE__ */ __name((m) => new OutboundRetryError(m), "retryError") };
|
|
2003
|
+
if (payload.action === "status") return runStatus(ctx, payload, row, adapter, deps);
|
|
2004
|
+
if (payload.action === "validatePickupCode") return runPickupCode(ctx, payload, row, adapter, deps);
|
|
1916
2005
|
return payload.action === "confirm" ? runConfirm(ctx, payload, row, adapter, attempt) : runCancellation(ctx, payload, row, adapter, attempt);
|
|
1917
2006
|
}
|
|
1918
2007
|
__name(runOnce2, "runOnce");
|
|
@@ -2102,9 +2191,9 @@ var PAUSE_CODES = { refused: "PAUSE_REFUSED", unanswered: "PAUSE_UNANSWERED" };
|
|
|
2102
2191
|
var RESUME_CODES = { refused: "RESUME_REFUSED", unanswered: "RESUME_UNANSWERED" };
|
|
2103
2192
|
var upToDate = /* @__PURE__ */ __name((row) => row.sentUntil !== null && row.until !== null && row.sentUntil.getTime() === row.until.getTime(), "upToDate");
|
|
2104
2193
|
var holds = /* @__PURE__ */ __name((row) => row.externalId !== null || row.sentUntil !== null, "holds");
|
|
2105
|
-
async function calledSafely(
|
|
2194
|
+
async function calledSafely(call2) {
|
|
2106
2195
|
try {
|
|
2107
|
-
return await
|
|
2196
|
+
return await call2();
|
|
2108
2197
|
} catch (error) {
|
|
2109
2198
|
return { kind: "retry", reason: error instanceof Error ? error.message : String(error) };
|
|
2110
2199
|
}
|
|
@@ -2359,6 +2448,10 @@ export {
|
|
|
2359
2448
|
settleInboxEvent,
|
|
2360
2449
|
deferInboxEvent,
|
|
2361
2450
|
listRetryableInboxEvents,
|
|
2451
|
+
statusTable,
|
|
2452
|
+
readStatusRows,
|
|
2453
|
+
noteMarketplaceStep,
|
|
2454
|
+
validatePickupCode,
|
|
2362
2455
|
ingestMarketplaceOrder,
|
|
2363
2456
|
CANCELLED_BEFORE_INGEST_REASON,
|
|
2364
2457
|
markCancelledBeforeIngest,
|
|
@@ -2371,9 +2464,6 @@ export {
|
|
|
2371
2464
|
runFetchOrder,
|
|
2372
2465
|
CATALOGUE_STALE_MS,
|
|
2373
2466
|
CATALOGUE_GIVE_UP_MS,
|
|
2374
|
-
statusTable,
|
|
2375
|
-
readStatusRows,
|
|
2376
|
-
noteMarketplaceStep,
|
|
2377
2467
|
OUTBOUND_STALE_MS,
|
|
2378
2468
|
OUTBOUND_GIVE_UP_MS,
|
|
2379
2469
|
sweepOutbound,
|
|
@@ -2390,4 +2480,4 @@ export {
|
|
|
2390
2480
|
AvailabilityRetryError,
|
|
2391
2481
|
runAvailability
|
|
2392
2482
|
};
|
|
2393
|
-
//# sourceMappingURL=chunk-
|
|
2483
|
+
//# sourceMappingURL=chunk-45ZVN5XI.js.map
|