@12-apps/marketplace 1.7.0 → 1.8.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 +17 -0
- package/README.md +56 -0
- package/dist/99food/index.d.ts +4 -2
- package/dist/99food/index.js +32 -3
- package/dist/99food/index.js.map +1 -1
- package/dist/{adapter-DOjTak1H.d.ts → adapter-CYJzu1c9.d.ts} +45 -1
- package/dist/{chunk-YVUZHXUF.js → chunk-6N2HEV3U.js} +4 -4
- package/dist/chunk-6N2HEV3U.js.map +1 -0
- package/dist/{chunk-SJUKBCVO.js → chunk-BMCERPQX.js} +198 -12
- package/dist/chunk-BMCERPQX.js.map +1 -0
- package/dist/{chunk-L3DCOZUU.js → chunk-HEXLCTOG.js} +1 -1
- package/dist/chunk-HEXLCTOG.js.map +1 -0
- package/dist/{chunk-UYFYGGCS.js → chunk-NP4EYKPO.js} +3 -1
- package/dist/chunk-NP4EYKPO.js.map +1 -0
- package/dist/{engine-DG1fg43Y.d.ts → engine-wmW-VuBL.d.ts} +107 -4
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +3 -3
- package/dist/ifood/index.d.ts +1 -1
- package/dist/ifood/index.js +29 -3
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +104 -7
- package/dist/index.js.map +1 -1
- package/dist/manifest/index.d.ts +3 -0
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/server.d.ts +2 -2
- package/dist/manifest/server.js +3 -3
- package/dist/rappi/index.d.ts +7 -1
- package/dist/rappi/index.js +20 -3
- package/dist/rappi/index.js.map +1 -1
- package/dist/server/index.d.ts +6 -2
- package/dist/server/index.js +3 -3
- package/package.json +1 -1
- package/prisma/marketplace.prisma +45 -1
- package/prisma/migrations/20261126120000_marketplace_status_updates/migration.sql +60 -0
- package/src/99food/index.ts +6 -0
- package/src/99food/normalize.ts +7 -1
- package/src/99food/outbound.ts +55 -0
- package/src/core/adapter.ts +41 -1
- package/src/core/bulk.ts +1 -1
- package/src/core/engine.ts +9 -0
- package/src/core/ingest.ts +6 -0
- package/src/core/integration.ts +17 -0
- package/src/core/lifecycle-port.ts +16 -0
- package/src/core/lifecycle.ts +133 -0
- package/src/core/outbound-queue.ts +24 -4
- package/src/core/outbound-sweep.ts +49 -5
- package/src/core/outbound.ts +11 -0
- package/src/core/pipeline.ts +22 -2
- package/src/core/ports.ts +39 -3
- package/src/core/status-inform.ts +51 -0
- package/src/core/status-job.ts +207 -0
- package/src/core/status-store.ts +85 -0
- package/src/core/types.ts +14 -0
- package/src/ifood/index.ts +7 -1
- package/src/ifood/normalize.ts +17 -0
- package/src/ifood/outbound.ts +35 -0
- package/src/index.ts +6 -0
- package/src/rappi/index.ts +6 -1
- package/src/rappi/normalize.ts +6 -0
- package/src/rappi/outbound.ts +31 -2
- package/src/server/mcp.ts +2 -0
- package/src/server/webhook.ts +3 -1
- package/dist/chunk-L3DCOZUU.js.map +0 -1
- package/dist/chunk-SJUKBCVO.js.map +0 -1
- package/dist/chunk-UYFYGGCS.js.map +0 -1
- package/dist/chunk-YVUZHXUF.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -44,11 +44,13 @@ import {
|
|
|
44
44
|
markCancelledBeforeIngest,
|
|
45
45
|
merchantMismatch,
|
|
46
46
|
notPendingProblem,
|
|
47
|
+
noteMarketplaceStep,
|
|
47
48
|
outboundDedupeKey,
|
|
48
49
|
pauseTable,
|
|
49
50
|
planCancellation,
|
|
50
51
|
readOutboundConnection,
|
|
51
52
|
readPause,
|
|
53
|
+
readStatusRows,
|
|
52
54
|
recordInboxEvent,
|
|
53
55
|
refusalData,
|
|
54
56
|
requestData,
|
|
@@ -63,12 +65,14 @@ import {
|
|
|
63
65
|
runOutbound,
|
|
64
66
|
saveMarketplaceIntegration,
|
|
65
67
|
settleInboxEvent,
|
|
68
|
+
statusDedupeKey,
|
|
69
|
+
statusTable,
|
|
66
70
|
suggestReason,
|
|
67
71
|
sweepOutbound,
|
|
68
72
|
tellCancellationFailed,
|
|
69
73
|
upsertLink,
|
|
70
74
|
viewOf
|
|
71
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-BMCERPQX.js";
|
|
72
76
|
import {
|
|
73
77
|
centsFromMajor
|
|
74
78
|
} from "./chunk-WN2EK4KX.js";
|
|
@@ -79,7 +83,7 @@ import {
|
|
|
79
83
|
answered,
|
|
80
84
|
outboundResultOf,
|
|
81
85
|
tokenGrantResultOf
|
|
82
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-HEXLCTOG.js";
|
|
83
87
|
import {
|
|
84
88
|
__name
|
|
85
89
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -103,7 +107,7 @@ function unknownProviders(ctx, rows, list) {
|
|
|
103
107
|
);
|
|
104
108
|
}
|
|
105
109
|
__name(unknownProviders, "unknownProviders");
|
|
106
|
-
var SETTING_KEYS = ["enabled", "environment", "externalMerchantId", "autoAccept", "ackSlaSeconds", "credentials"];
|
|
110
|
+
var SETTING_KEYS = ["enabled", "environment", "externalMerchantId", "autoAccept", "followStatus", "ackSlaSeconds", "credentials"];
|
|
107
111
|
function integrationRowProblems(row, index, existing) {
|
|
108
112
|
if (row.operation === "archive" || row.operation === "unarchive") {
|
|
109
113
|
return existing.has(row.provider) ? [] : [{ path: ["integrations", index, "provider"], code: "NOT_FOUND" }];
|
|
@@ -436,8 +440,8 @@ __name(publishRefusal, "publishRefusal");
|
|
|
436
440
|
async function publishToCatalogue(ctx, input) {
|
|
437
441
|
const table = await usableTable(ctx, input.provider);
|
|
438
442
|
if (!table) return refused("UNSUPPORTED");
|
|
439
|
-
const
|
|
440
|
-
if (
|
|
443
|
+
const refusal2 = await publishRefusal(ctx, input);
|
|
444
|
+
if (refusal2) return refused(refusal2);
|
|
441
445
|
const existing = await findRow(table, input);
|
|
442
446
|
const now = ctx.ports.clock.now();
|
|
443
447
|
const price = input.priceCents === void 0 ? {} : { priceCents: input.priceCents };
|
|
@@ -551,6 +555,30 @@ var engineRefusal = /* @__PURE__ */ __name((code) => ({
|
|
|
551
555
|
message: null
|
|
552
556
|
}), "engineRefusal");
|
|
553
557
|
|
|
558
|
+
// src/core/status-inform.ts
|
|
559
|
+
async function informStatus(ctx, input) {
|
|
560
|
+
const payload = { clientId: input.clientId, orderId: input.orderId, action: "status", step: input.step, claimKey: String(input.at.getTime()) };
|
|
561
|
+
const options = {
|
|
562
|
+
dedupeKey: statusDedupeKey(input.step, input.orderId, input.at),
|
|
563
|
+
...input.delayMs === void 0 ? {} : { delayMs: input.delayMs }
|
|
564
|
+
};
|
|
565
|
+
try {
|
|
566
|
+
const outcome = await ctx.ports.enqueue.enqueue(MARKETPLACE_OUTBOUND_JOB, payload, options);
|
|
567
|
+
if (!outcome.enqueued) {
|
|
568
|
+
ctx.ports.logger.warn(
|
|
569
|
+
`${MARKETPLACE_OUTBOUND_JOB}: status ${input.step} for order ${input.orderId} was not queued` + (outcome.reason ? ` (${outcome.reason})` : "")
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
return outcome.enqueued;
|
|
573
|
+
} catch (error) {
|
|
574
|
+
ctx.ports.logger.warn(
|
|
575
|
+
`${MARKETPLACE_OUTBOUND_JOB}: status ${input.step} for order ${input.orderId} was not queued: ` + (error instanceof Error ? error.message : String(error))
|
|
576
|
+
);
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
__name(informStatus, "informStatus");
|
|
581
|
+
|
|
554
582
|
// src/core/pause.ts
|
|
555
583
|
async function liveConnections(ctx, clientId) {
|
|
556
584
|
const db = await ctx.ports.db();
|
|
@@ -829,6 +857,68 @@ async function sweepAvailability(ctx, now) {
|
|
|
829
857
|
}
|
|
830
858
|
__name(sweepAvailability, "sweepAvailability");
|
|
831
859
|
|
|
860
|
+
// src/core/lifecycle.ts
|
|
861
|
+
var ECHO_OF = {
|
|
862
|
+
DISPATCHED: "DISPATCHED",
|
|
863
|
+
CONCLUDED: "HANDED_OVER"
|
|
864
|
+
};
|
|
865
|
+
async function ignored(ctx, inboxId, reason) {
|
|
866
|
+
await settleInboxEvent(ctx, inboxId, "IGNORED", reason);
|
|
867
|
+
return { kind: "ignored", reason };
|
|
868
|
+
}
|
|
869
|
+
__name(ignored, "ignored");
|
|
870
|
+
function refusal(held) {
|
|
871
|
+
if (held.status !== "ACCEPTED") return `the order is ${held.status}, not ACCEPTED`;
|
|
872
|
+
if (held.cancellationStatus === "PENDING" || held.cancellationStatus === "REQUESTED") {
|
|
873
|
+
return `a cancellation request is ${held.cancellationStatus}`;
|
|
874
|
+
}
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
__name(refusal, "refusal");
|
|
878
|
+
function deliveredByOf(held) {
|
|
879
|
+
return held.deliveredBy === "MERCHANT" || held.deliveredBy === "MARKETPLACE" ? held.deliveredBy : null;
|
|
880
|
+
}
|
|
881
|
+
__name(deliveredByOf, "deliveredByOf");
|
|
882
|
+
function following(ctx, event, settings) {
|
|
883
|
+
const hook = ctx.ports.order.onLifecycle;
|
|
884
|
+
if (!event.lifecycle || !event.externalOrderId || !settings.followStatus || !hook) return null;
|
|
885
|
+
return { lifecycle: event.lifecycle, externalOrderId: event.externalOrderId, hook };
|
|
886
|
+
}
|
|
887
|
+
__name(following, "following");
|
|
888
|
+
async function followLifecycle(ctx, inboxId, clientId, event, settings) {
|
|
889
|
+
const follow = following(ctx, event, settings);
|
|
890
|
+
if (!follow) return null;
|
|
891
|
+
const { lifecycle, hook } = follow;
|
|
892
|
+
const db = await ctx.ports.db();
|
|
893
|
+
const table = statusTable(db);
|
|
894
|
+
if (!table) return null;
|
|
895
|
+
const held = await db.marketplaceAcceptance.findFirst({
|
|
896
|
+
where: { clientId, provider: event.provider, externalOrderId: follow.externalOrderId },
|
|
897
|
+
select: { orderId: true, status: true, deliveredBy: true, cancellationStatus: true }
|
|
898
|
+
});
|
|
899
|
+
if (!held) {
|
|
900
|
+
const reason2 = "lifecycle before its order";
|
|
901
|
+
await deferInboxEvent(ctx, inboxId, reason2);
|
|
902
|
+
return { kind: "ignored", reason: reason2 };
|
|
903
|
+
}
|
|
904
|
+
const stopped = refusal(held);
|
|
905
|
+
if (stopped) return ignored(ctx, inboxId, stopped);
|
|
906
|
+
const echo = ECHO_OF[lifecycle];
|
|
907
|
+
const ours = (await readStatusRows(table, held.orderId, [echo])).some((row) => row.source === "STORE");
|
|
908
|
+
if (ours) return ignored(ctx, inboxId, `echo of our ${echo}`);
|
|
909
|
+
const answer = await hook.call(ctx.ports.order, clientId, held.orderId, event, { deliveredBy: deliveredByOf(held) });
|
|
910
|
+
await noteMarketplaceStep(ctx, { clientId, orderId: held.orderId, provider: event.provider, step: lifecycle });
|
|
911
|
+
if (answer === "moved") {
|
|
912
|
+
await settleInboxEvent(ctx, inboxId, "PROCESSED");
|
|
913
|
+
ctx.ports.publishChanged(clientId);
|
|
914
|
+
return { kind: "moved", orderId: held.orderId, lifecycle };
|
|
915
|
+
}
|
|
916
|
+
const reason = answer === "unchanged" ? `already at or past ${lifecycle}` : answer.reason;
|
|
917
|
+
if (answer !== "unchanged") ctx.ports.logger.warn(`marketplace.lifecycle: ${event.provider} order ${held.orderId}: ${reason}`);
|
|
918
|
+
return ignored(ctx, inboxId, reason);
|
|
919
|
+
}
|
|
920
|
+
__name(followLifecycle, "followLifecycle");
|
|
921
|
+
|
|
832
922
|
// src/core/pipeline.ts
|
|
833
923
|
function normalizeEvent(ctx, provider, payload) {
|
|
834
924
|
return ctx.registry.get(provider)?.normalize(payload) ?? null;
|
|
@@ -883,6 +973,12 @@ async function applyEvent(ctx, inboxId, clientId, event, settings, now) {
|
|
|
883
973
|
await awaitOrderBody(ctx, clientId, inboxId);
|
|
884
974
|
return { kind: "awaitingOrder" };
|
|
885
975
|
}
|
|
976
|
+
const followed = await followLifecycle(ctx, inboxId, clientId, event, settings);
|
|
977
|
+
if (followed) return followed;
|
|
978
|
+
return ingestOrIgnore(ctx, inboxId, clientId, event, settings, now);
|
|
979
|
+
}
|
|
980
|
+
__name(applyEvent, "applyEvent");
|
|
981
|
+
async function ingestOrIgnore(ctx, inboxId, clientId, event, settings, now) {
|
|
886
982
|
if (!event.order) {
|
|
887
983
|
const reason = `no order body on ${event.eventType}`;
|
|
888
984
|
await settleInboxEvent(ctx, inboxId, "IGNORED", reason);
|
|
@@ -890,7 +986,7 @@ async function applyEvent(ctx, inboxId, clientId, event, settings, now) {
|
|
|
890
986
|
}
|
|
891
987
|
return ingestCarried(ctx, inboxId, clientId, event.order, settings, now);
|
|
892
988
|
}
|
|
893
|
-
__name(
|
|
989
|
+
__name(ingestOrIgnore, "ingestOrIgnore");
|
|
894
990
|
async function ingestCarried(ctx, inboxId, clientId, order, settings, now) {
|
|
895
991
|
const mismatch = await carriedOrderMismatch(ctx, clientId, order);
|
|
896
992
|
if (mismatch) {
|
|
@@ -929,7 +1025,7 @@ async function reprocessStoredDelivery(ctx, input) {
|
|
|
929
1025
|
input.id,
|
|
930
1026
|
input.clientId,
|
|
931
1027
|
event,
|
|
932
|
-
{ autoAccept: target.autoAccept, ackSlaSeconds: target.ackSlaSeconds },
|
|
1028
|
+
{ autoAccept: target.autoAccept, ackSlaSeconds: target.ackSlaSeconds, followStatus: target.followStatus },
|
|
933
1029
|
void 0
|
|
934
1030
|
);
|
|
935
1031
|
} catch (error) {
|
|
@@ -1027,6 +1123,7 @@ function createMarketplaceEngine(config) {
|
|
|
1027
1123
|
sweepOutbound: /* @__PURE__ */ __name((now) => sweepOutbound(ctx, now ?? ports.clock.now()), "sweepOutbound"),
|
|
1028
1124
|
runOutbound: /* @__PURE__ */ __name((payload, attempt) => runOutbound(ctx, payload, attempt), "runOutbound"),
|
|
1029
1125
|
runFetchOrder: /* @__PURE__ */ __name((payload, attempt) => runFetchOrder(ctx, payload, attempt), "runFetchOrder"),
|
|
1126
|
+
informStatus: /* @__PURE__ */ __name((input) => informStatus(ctx, input), "informStatus"),
|
|
1030
1127
|
// Null too when the host bound no catalogue port: nothing could be published.
|
|
1031
1128
|
catalogueMode: /* @__PURE__ */ __name((provider) => ports.catalogue ? registry.get(provider)?.catalogue?.mode ?? null : null, "catalogueMode"),
|
|
1032
1129
|
publish: /* @__PURE__ */ __name((input) => publishToCatalogue(ctx, input), "publish"),
|