@12-apps/marketplace 1.16.0 → 1.17.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 +115 -0
- package/dist/99food/index.d.ts +2 -2
- package/dist/99food/index.js +2 -2
- package/dist/{adapter-CjVdMhZ2.d.ts → adapter-CxzF-qGx.d.ts} +185 -2
- package/dist/{chunk-TRUK5ZBE.js → chunk-7IYUO2KC.js} +2 -2
- package/dist/{chunk-BTKVZAJI.js → chunk-CF5BSXE5.js} +1 -1
- package/dist/chunk-CF5BSXE5.js.map +1 -0
- package/dist/{chunk-DJIMUEHT.js → chunk-EABVLQKK.js} +79 -7
- package/dist/chunk-EABVLQKK.js.map +1 -0
- package/dist/{chunk-H2VQRD3B.js → chunk-KKFMDV5K.js} +1 -1
- package/dist/chunk-KKFMDV5K.js.map +1 -0
- package/dist/{chunk-SGOTN5PX.js → chunk-LO7OKO6V.js} +45 -4
- package/dist/chunk-LO7OKO6V.js.map +1 -0
- package/dist/{chunk-TICWLBSA.js → chunk-UZO2NILN.js} +365 -6
- package/dist/chunk-UZO2NILN.js.map +1 -0
- package/dist/{client-DgzCkl8u.d.ts → client-C-4QvVq3.d.ts} +1 -1
- package/dist/{engine-DSRj7qnC.d.ts → engine-Y6Rpf5p7.d.ts} +430 -185
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +4 -4
- package/dist/ifood/index.d.ts +9 -2
- package/dist/ifood/index.js +271 -23
- package/dist/ifood/index.js.map +1 -1
- package/dist/index.d.ts +21 -4
- package/dist/index.js +381 -42
- package/dist/index.js.map +1 -1
- package/dist/keeta/index.d.ts +2 -2
- package/dist/keeta/index.js +2 -2
- package/dist/manifest/index.d.ts +78 -0
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/server.d.ts +6 -2
- package/dist/manifest/server.js +4 -4
- package/dist/rappi/index.d.ts +1 -1
- package/dist/rappi/index.js +1 -1
- package/dist/server/index.d.ts +93 -7
- package/dist/server/index.js +4 -4
- package/package.json +1 -1
- package/prisma/marketplace.prisma +69 -1
- package/prisma/migrations/20261203180000_marketplace_app_link_check/migration.sql +14 -0
- package/prisma/migrations/20261203190000_marketplace_disputes/migration.sql +96 -0
- package/src/core/adapter.ts +12 -1
- package/src/core/app-linking.ts +396 -0
- package/src/core/dispute-engine.ts +32 -0
- package/src/core/dispute-job.ts +142 -0
- package/src/core/dispute-port.ts +133 -0
- package/src/core/dispute-store.ts +203 -0
- package/src/core/disputes.ts +263 -0
- package/src/core/engine.ts +4 -55
- package/src/core/integration.ts +3 -1
- package/src/core/link-engine.ts +176 -0
- package/src/core/link-store.ts +15 -0
- package/src/core/linking-port.ts +35 -1
- package/src/core/linking.ts +8 -0
- package/src/core/outbound-sweep.ts +9 -1
- package/src/core/pipeline.ts +8 -3
- package/src/core/ports.ts +15 -0
- package/src/core/types.ts +8 -0
- package/src/ifood/app-linking.ts +119 -0
- package/src/ifood/disputes.ts +209 -0
- package/src/ifood/index.ts +12 -1
- package/src/ifood/normalize.ts +3 -0
- package/src/index.ts +34 -0
- package/src/server/jobs.ts +51 -3
- package/src/server/link-routes.ts +56 -4
- package/src/server/mcp-link.ts +44 -2
- package/src/server/mcp.ts +2 -1
- package/dist/chunk-BTKVZAJI.js.map +0 -1
- package/dist/chunk-DJIMUEHT.js.map +0 -1
- package/dist/chunk-H2VQRD3B.js.map +0 -1
- package/dist/chunk-SGOTN5PX.js.map +0 -1
- package/dist/chunk-TICWLBSA.js.map +0 -1
- /package/dist/{chunk-TRUK5ZBE.js.map → chunk-7IYUO2KC.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -9,11 +9,13 @@ import {
|
|
|
9
9
|
CONFIRMED_BEFORE_ORDER,
|
|
10
10
|
CancellationReasonsRetryError,
|
|
11
11
|
CatalogueRetryError,
|
|
12
|
+
DisputeAnswerRetryError,
|
|
12
13
|
FetchOrderRetryError,
|
|
13
14
|
MARKETPLACE_ACKNOWLEDGE_JOB,
|
|
14
15
|
MARKETPLACE_AVAILABILITY_JOB,
|
|
15
16
|
MARKETPLACE_CANCELLATION_REASONS_JOB,
|
|
16
17
|
MARKETPLACE_CATALOGUE_JOB,
|
|
18
|
+
MARKETPLACE_DISPUTE_ANSWER_JOB,
|
|
17
19
|
MARKETPLACE_FETCH_ORDER_JOB,
|
|
18
20
|
MARKETPLACE_OUTBOUND_JOB,
|
|
19
21
|
MarketplaceAdapterRegistrationError,
|
|
@@ -24,7 +26,9 @@ import {
|
|
|
24
26
|
OUTBOUND_STALE_MS,
|
|
25
27
|
OutboundRetryError,
|
|
26
28
|
STORE_PAUSE_LEASE_MS,
|
|
29
|
+
answerDispute,
|
|
27
30
|
appCredentialsOf,
|
|
31
|
+
applyDisputeEvent,
|
|
28
32
|
applyMarketplaceConfirmation,
|
|
29
33
|
availabilityDedupeKey,
|
|
30
34
|
awaitOrderBody,
|
|
@@ -37,6 +41,7 @@ import {
|
|
|
37
41
|
connectionMerchantId,
|
|
38
42
|
createAdapterRegistry,
|
|
39
43
|
deferInboxEvent,
|
|
44
|
+
disputeView,
|
|
40
45
|
enqueueAcknowledge,
|
|
41
46
|
enqueueAvailability,
|
|
42
47
|
enqueueCatalogue,
|
|
@@ -61,6 +66,7 @@ import {
|
|
|
61
66
|
outboundDedupeKey,
|
|
62
67
|
pauseTable,
|
|
63
68
|
planCancellation,
|
|
69
|
+
readDisputes,
|
|
64
70
|
readOrderReasons,
|
|
65
71
|
readOutboundConnection,
|
|
66
72
|
readPause,
|
|
@@ -78,9 +84,11 @@ import {
|
|
|
78
84
|
runAvailability,
|
|
79
85
|
runCancellationReasons,
|
|
80
86
|
runCatalogue,
|
|
87
|
+
runDisputeAnswer,
|
|
81
88
|
runFetchOrder,
|
|
82
89
|
runOutbound,
|
|
83
90
|
saveMarketplaceIntegration,
|
|
91
|
+
sealAppLink,
|
|
84
92
|
sealLink,
|
|
85
93
|
settleInboxEvent,
|
|
86
94
|
statusDedupeKey,
|
|
@@ -93,14 +101,14 @@ import {
|
|
|
93
101
|
upsertLink,
|
|
94
102
|
validatePickupCode,
|
|
95
103
|
viewOf
|
|
96
|
-
} from "./chunk-
|
|
104
|
+
} from "./chunk-UZO2NILN.js";
|
|
97
105
|
import {
|
|
98
106
|
centsFromMajor
|
|
99
107
|
} from "./chunk-WN2EK4KX.js";
|
|
100
108
|
import {
|
|
101
109
|
PROVIDER_ID_PATTERN,
|
|
102
110
|
normalizedLineTotalCents
|
|
103
|
-
} from "./chunk-
|
|
111
|
+
} from "./chunk-KKFMDV5K.js";
|
|
104
112
|
import {
|
|
105
113
|
stableUuid
|
|
106
114
|
} from "./chunk-M2V4RFMA.js";
|
|
@@ -108,16 +116,16 @@ import {
|
|
|
108
116
|
answered,
|
|
109
117
|
outboundResultOf,
|
|
110
118
|
tokenGrantResultOf
|
|
111
|
-
} from "./chunk-
|
|
119
|
+
} from "./chunk-CF5BSXE5.js";
|
|
112
120
|
import {
|
|
113
121
|
__name
|
|
114
122
|
} from "./chunk-7QVYU63E.js";
|
|
115
123
|
|
|
116
124
|
// src/core/bulk.ts
|
|
117
|
-
function duplicates(rows,
|
|
125
|
+
function duplicates(rows, keyOf3, list, field) {
|
|
118
126
|
const seen = /* @__PURE__ */ new Set();
|
|
119
127
|
return rows.flatMap((row, index) => {
|
|
120
|
-
const key =
|
|
128
|
+
const key = keyOf3(row);
|
|
121
129
|
if (!seen.has(key)) {
|
|
122
130
|
seen.add(key);
|
|
123
131
|
return [];
|
|
@@ -331,7 +339,7 @@ function requestOnly(ctx, plan) {
|
|
|
331
339
|
__name(requestOnly, "requestOnly");
|
|
332
340
|
async function admitAndClaim(ctx, clientId, planned, validateOnly) {
|
|
333
341
|
await ctx.ports.transaction(async (tx) => {
|
|
334
|
-
const
|
|
342
|
+
const refused4 = [];
|
|
335
343
|
for (const one of planned) {
|
|
336
344
|
const admission = one.input.decision === "ACCEPT" ? one.input.admission ?? {} : {};
|
|
337
345
|
const answer = await ctx.ports.order.admit({
|
|
@@ -343,18 +351,18 @@ async function admitAndClaim(ctx, clientId, planned, validateOnly) {
|
|
|
343
351
|
});
|
|
344
352
|
if (!answer.admitted) {
|
|
345
353
|
const host = { code: answer.code, message: answer.message, details: answer.details };
|
|
346
|
-
|
|
354
|
+
refused4.push({ path: ["decisions", one.index], code: "HOST_REFUSED", host });
|
|
347
355
|
}
|
|
348
356
|
}
|
|
349
|
-
if (
|
|
357
|
+
if (refused4.length > 0) throw new Rollback(refused4);
|
|
350
358
|
for (const one of planned) {
|
|
351
359
|
const claimed = await tx.marketplaceAcceptance.updateMany({
|
|
352
360
|
where: { orderId: one.input.orderId, clientId, status: "AWAITING", ...NO_STANDING_REQUEST },
|
|
353
361
|
data: one.data
|
|
354
362
|
});
|
|
355
|
-
if (claimed.count === 0)
|
|
363
|
+
if (claimed.count === 0) refused4.push({ path: ["decisions", one.index, "orderId"], code: "CONFLICT" });
|
|
356
364
|
}
|
|
357
|
-
if (
|
|
365
|
+
if (refused4.length > 0) throw new Rollback(refused4);
|
|
358
366
|
if (validateOnly) throw new Rollback(null);
|
|
359
367
|
});
|
|
360
368
|
}
|
|
@@ -791,14 +799,273 @@ function conformityEngine(ctx) {
|
|
|
791
799
|
}
|
|
792
800
|
__name(conformityEngine, "conformityEngine");
|
|
793
801
|
|
|
794
|
-
// src/core/linking.ts
|
|
802
|
+
// src/core/app-linking.ts
|
|
803
|
+
var ATTEMPT_MINUTES = 30;
|
|
804
|
+
var CHECK_EVERY_SECONDS = 30;
|
|
795
805
|
var refused2 = /* @__PURE__ */ __name((code, status = null, message = null) => ({
|
|
796
806
|
kind: "refused",
|
|
797
807
|
code,
|
|
798
808
|
status,
|
|
799
809
|
message
|
|
800
810
|
}), "refused");
|
|
801
|
-
var
|
|
811
|
+
var keyOf = /* @__PURE__ */ __name((clientId, provider) => ({ clientId_provider: { clientId, provider } }), "keyOf");
|
|
812
|
+
var environmentOf = /* @__PURE__ */ __name((value) => value === "SANDBOX" ? "SANDBOX" : "PRODUCTION", "environmentOf");
|
|
813
|
+
function hasAppLinking(ctx, provider) {
|
|
814
|
+
return ctx.registry.get(provider)?.appLinking !== void 0;
|
|
815
|
+
}
|
|
816
|
+
__name(hasAppLinking, "hasAppLinking");
|
|
817
|
+
async function readyOf(ctx, provider, environment) {
|
|
818
|
+
const linking = ctx.registry.get(provider)?.appLinking;
|
|
819
|
+
if (!linking) return null;
|
|
820
|
+
const attempts = (await ctx.ports.db()).marketplaceLinkAttempt;
|
|
821
|
+
if (!attempts) return null;
|
|
822
|
+
const app = await appCredentialsOf(ctx, provider, environment);
|
|
823
|
+
if (!app) return null;
|
|
824
|
+
const call = { http: ctx.ports.http, credentials: app, environment, now: ctx.ports.clock.now(), tokens: ctx.tokens };
|
|
825
|
+
return { linking, attempts, call, environment };
|
|
826
|
+
}
|
|
827
|
+
__name(readyOf, "readyOf");
|
|
828
|
+
var pendingOf = /* @__PURE__ */ __name((linking, row) => ({
|
|
829
|
+
portalUrl: linking.portalUrl,
|
|
830
|
+
expiresAt: row.expiresAt,
|
|
831
|
+
seenAt: row.seenAt ?? null,
|
|
832
|
+
checkedAt: row.checkedAt ?? null
|
|
833
|
+
}), "pendingOf");
|
|
834
|
+
var isLive = /* @__PURE__ */ __name((row, now) => row !== null && row.expiresAt.getTime() > now.getTime(), "isLive");
|
|
835
|
+
var renewed = /* @__PURE__ */ __name((now) => new Date(now.getTime() + ATTEMPT_MINUTES * 6e4), "renewed");
|
|
836
|
+
async function liveAttempt(ready, clientId, provider) {
|
|
837
|
+
const row = await ready.attempts.findUnique({ where: keyOf(clientId, provider) });
|
|
838
|
+
return isLive(row, ready.call.now) ? row : null;
|
|
839
|
+
}
|
|
840
|
+
__name(liveAttempt, "liveAttempt");
|
|
841
|
+
async function takenAmong(db, clientId, provider, ids) {
|
|
842
|
+
const held = await heldBy(db, provider, ids);
|
|
843
|
+
return new Set([...held].flatMap(([merchantId, holder]) => holder === clientId ? [] : [merchantId]));
|
|
844
|
+
}
|
|
845
|
+
__name(takenAmong, "takenAmong");
|
|
846
|
+
async function listFor(ctx, ready, input) {
|
|
847
|
+
const listed = await ready.linking.merchants(ready.call);
|
|
848
|
+
if (listed.kind === "retry") return listed;
|
|
849
|
+
if (listed.kind === "refused") return refused2("MARKETPLACE_REFUSED", listed.status, listed.message);
|
|
850
|
+
const taken = await takenAmong(await ctx.ports.db(), input.clientId, input.provider, listed.value.map((merchant) => merchant.id));
|
|
851
|
+
const judged = listed.value.map((merchant) => ({ ...merchant, taken: taken.has(merchant.id) }));
|
|
852
|
+
if (!input.addresses) return judged;
|
|
853
|
+
return withAddresses(ready, judged);
|
|
854
|
+
}
|
|
855
|
+
__name(listFor, "listFor");
|
|
856
|
+
var ADDRESS_CONCURRENCY = 4;
|
|
857
|
+
async function withAddresses(ready, judged) {
|
|
858
|
+
const out = judged.map((merchant) => ({ ...merchant, address: null }));
|
|
859
|
+
const queue2 = out.filter((merchant) => merchant.taken !== true);
|
|
860
|
+
const worker = /* @__PURE__ */ __name(async () => {
|
|
861
|
+
for (let next = queue2.shift(); next; next = queue2.shift()) {
|
|
862
|
+
const answer = await ready.linking.address(ready.call, next.id).catch(() => null);
|
|
863
|
+
next.address = answer?.kind === "ok" ? answer.value : null;
|
|
864
|
+
}
|
|
865
|
+
}, "worker");
|
|
866
|
+
await Promise.all(Array.from({ length: ADDRESS_CONCURRENCY }, worker));
|
|
867
|
+
return out;
|
|
868
|
+
}
|
|
869
|
+
__name(withAddresses, "withAddresses");
|
|
870
|
+
var pickable = /* @__PURE__ */ __name((merchants) => merchants.some((merchant) => merchant.taken !== true), "pickable");
|
|
871
|
+
async function stamp(ready, row, canPick, renew2) {
|
|
872
|
+
const now = ready.call.now;
|
|
873
|
+
const seen = row.seenAt ?? (canPick ? now : null);
|
|
874
|
+
const data = { checkedAt: now, seenAt: seen, ...renew2 ? { expiresAt: renewed(now) } : {} };
|
|
875
|
+
await ready.attempts.updateMany?.({ where: { clientId: row.clientId, provider: row.provider, verifier: row.verifier }, data });
|
|
876
|
+
return { ...row, ...data };
|
|
877
|
+
}
|
|
878
|
+
__name(stamp, "stamp");
|
|
879
|
+
async function appLinkState(ctx, input) {
|
|
880
|
+
const ready = await readyOf(ctx, input.provider, input.environment ?? "PRODUCTION");
|
|
881
|
+
if (!ready) return { available: false, pending: null };
|
|
882
|
+
const row = await liveAttempt(ready, input.clientId, input.provider);
|
|
883
|
+
if (!row) return { available: true, pending: null };
|
|
884
|
+
const stale = row.seenAt == null && (row.checkedAt == null || ready.call.now.getTime() - row.checkedAt.getTime() >= CHECK_EVERY_SECONDS * 1e3);
|
|
885
|
+
const listed = stale ? await listFor(ctx, ready, { ...input, addresses: false }) : null;
|
|
886
|
+
const checked = Array.isArray(listed) ? await stamp(ready, row, pickable(listed), true) : await renew(ready, row);
|
|
887
|
+
return { available: true, pending: pendingOf(ready.linking, checked) };
|
|
888
|
+
}
|
|
889
|
+
__name(appLinkState, "appLinkState");
|
|
890
|
+
async function renew(ready, row) {
|
|
891
|
+
const data = { expiresAt: renewed(ready.call.now) };
|
|
892
|
+
await ready.attempts.updateMany?.({ where: { clientId: row.clientId, provider: row.provider, verifier: row.verifier }, data });
|
|
893
|
+
return { ...row, ...data };
|
|
894
|
+
}
|
|
895
|
+
__name(renew, "renew");
|
|
896
|
+
async function startAppLink(ctx, input) {
|
|
897
|
+
const environment = input.environment ?? "PRODUCTION";
|
|
898
|
+
const ready = await readyOf(ctx, input.provider, environment);
|
|
899
|
+
if (!ready) return refused2("UNAVAILABLE");
|
|
900
|
+
const portal = ready.linking.portalUrl;
|
|
901
|
+
const row = {
|
|
902
|
+
environment,
|
|
903
|
+
// No secret travels in a centralized link: the column keeps a fresh nonce, so each attempt tells itself from a later one.
|
|
904
|
+
verifier: ctx.ports.secrets.seal(`app-link:${globalThis.crypto.randomUUID()}`),
|
|
905
|
+
userCode: "",
|
|
906
|
+
verificationUrl: portal,
|
|
907
|
+
verificationUrlComplete: portal,
|
|
908
|
+
expiresAt: renewed(ready.call.now),
|
|
909
|
+
seenAt: null,
|
|
910
|
+
checkedAt: null
|
|
911
|
+
};
|
|
912
|
+
await ready.attempts.upsert({
|
|
913
|
+
where: keyOf(input.clientId, input.provider),
|
|
914
|
+
create: { clientId: input.clientId, provider: input.provider, ...row },
|
|
915
|
+
update: row
|
|
916
|
+
});
|
|
917
|
+
return { kind: "started", pending: pendingOf(ready.linking, { clientId: input.clientId, provider: input.provider, ...row }) };
|
|
918
|
+
}
|
|
919
|
+
__name(startAppLink, "startAppLink");
|
|
920
|
+
async function checkAppLink(ctx, input) {
|
|
921
|
+
const attempts = (await ctx.ports.db()).marketplaceLinkAttempt;
|
|
922
|
+
const stored = attempts ? await attempts.findUnique({ where: keyOf(input.clientId, input.provider) }) : null;
|
|
923
|
+
const environment = input.environment ?? environmentOf(stored?.environment);
|
|
924
|
+
const ready = await readyOf(ctx, input.provider, environment);
|
|
925
|
+
if (!ready) return refused2("UNAVAILABLE");
|
|
926
|
+
const merchants = await listFor(ctx, ready, { ...input, addresses: true });
|
|
927
|
+
if (!Array.isArray(merchants)) return merchants;
|
|
928
|
+
const row = isLive(stored, ready.call.now) ? await stamp(ready, stored, pickable(merchants), true) : null;
|
|
929
|
+
return { kind: "checked", pending: row ? pendingOf(ready.linking, row) : null, merchants };
|
|
930
|
+
}
|
|
931
|
+
__name(checkAppLink, "checkAppLink");
|
|
932
|
+
async function cancelAppLink(ctx, input) {
|
|
933
|
+
const attempts = (await ctx.ports.db()).marketplaceLinkAttempt;
|
|
934
|
+
await attempts?.deleteMany({ where: { clientId: input.clientId, provider: input.provider } });
|
|
935
|
+
}
|
|
936
|
+
__name(cancelAppLink, "cancelAppLink");
|
|
937
|
+
async function sweepAppLinks(ctx, input = {}) {
|
|
938
|
+
const attempts = (await ctx.ports.db()).marketplaceLinkAttempt;
|
|
939
|
+
if (!attempts?.findMany) return { seen: [], waiting: 0 };
|
|
940
|
+
const now = ctx.ports.clock.now();
|
|
941
|
+
const rows = await dueAttempts(attempts, now);
|
|
942
|
+
const seen = [];
|
|
943
|
+
for (const group of groupByApp(rows).values()) seen.push(...await sweepGroup(ctx, group));
|
|
944
|
+
for (const store of seen) ctx.ports.publishLinkSeen?.(store.clientId, store.provider);
|
|
945
|
+
if (!input.half && rows.length > seen.length) await queueHalfPass(ctx, now);
|
|
946
|
+
return { seen, waiting: rows.length - seen.length };
|
|
947
|
+
}
|
|
948
|
+
__name(sweepAppLinks, "sweepAppLinks");
|
|
949
|
+
async function dueAttempts(attempts, now) {
|
|
950
|
+
const due = new Date(now.getTime() - CHECK_EVERY_SECONDS * 1e3);
|
|
951
|
+
return await attempts.findMany({
|
|
952
|
+
where: { expiresAt: { gte: now }, seenAt: null, OR: [{ checkedAt: null }, { checkedAt: { lt: due } }] },
|
|
953
|
+
orderBy: { expiresAt: "asc" },
|
|
954
|
+
take: SWEEP_BATCH
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
__name(dueAttempts, "dueAttempts");
|
|
958
|
+
function groupByApp(rows) {
|
|
959
|
+
const groups = /* @__PURE__ */ new Map();
|
|
960
|
+
for (const row of rows) {
|
|
961
|
+
const key = `${row.provider}:${environmentOf(row.environment)}`;
|
|
962
|
+
groups.set(key, [...groups.get(key) ?? [], row]);
|
|
963
|
+
}
|
|
964
|
+
return groups;
|
|
965
|
+
}
|
|
966
|
+
__name(groupByApp, "groupByApp");
|
|
967
|
+
async function sweepGroup(ctx, group) {
|
|
968
|
+
const first = group[0];
|
|
969
|
+
const ready = await readyOf(ctx, first.provider, environmentOf(first.environment));
|
|
970
|
+
const listed = ready ? await ready.linking.merchants(ready.call) : null;
|
|
971
|
+
if (!ready || listed?.kind !== "ok") return [];
|
|
972
|
+
const held = await heldBy(await ctx.ports.db(), first.provider, listed.value.map((merchant) => merchant.id));
|
|
973
|
+
const anyFree = listed.value.some((merchant) => !held.has(merchant.id));
|
|
974
|
+
const holders = new Set(held.values());
|
|
975
|
+
const seen = [];
|
|
976
|
+
for (const row of group) {
|
|
977
|
+
const checked = await stamp(ready, row, anyFree || holders.has(row.clientId), false);
|
|
978
|
+
if (checked.seenAt) seen.push({ clientId: row.clientId, provider: row.provider });
|
|
979
|
+
}
|
|
980
|
+
return seen;
|
|
981
|
+
}
|
|
982
|
+
__name(sweepGroup, "sweepGroup");
|
|
983
|
+
var MARKETPLACE_LINK_CHECK_JOB = "marketplace.link-check";
|
|
984
|
+
async function queueHalfPass(ctx, now) {
|
|
985
|
+
const minute = Math.floor(now.getTime() / 6e4);
|
|
986
|
+
const outcome = await ctx.ports.enqueue.enqueue(MARKETPLACE_LINK_CHECK_JOB, { half: true }, {
|
|
987
|
+
dedupeKey: `${MARKETPLACE_LINK_CHECK_JOB}:${minute}`,
|
|
988
|
+
delayMs: CHECK_EVERY_SECONDS * 1e3
|
|
989
|
+
});
|
|
990
|
+
if (!outcome.enqueued) ctx.ports.logger.warn(`${MARKETPLACE_LINK_CHECK_JOB}: the half-minute pass was not queued (${outcome.reason ?? "no reason"})`);
|
|
991
|
+
}
|
|
992
|
+
__name(queueHalfPass, "queueHalfPass");
|
|
993
|
+
var SWEEP_BATCH = 200;
|
|
994
|
+
async function heldBy(db, provider, ids) {
|
|
995
|
+
if (ids.length === 0) return /* @__PURE__ */ new Map();
|
|
996
|
+
const rows = await db.marketplaceIntegration.findMany({
|
|
997
|
+
where: { provider, externalMerchantId: { in: [...ids] }, archivedAt: null },
|
|
998
|
+
select: { clientId: true, externalMerchantId: true }
|
|
999
|
+
});
|
|
1000
|
+
return new Map(rows.flatMap((row) => row.externalMerchantId ? [[row.externalMerchantId, row.clientId]] : []));
|
|
1001
|
+
}
|
|
1002
|
+
__name(heldBy, "heldBy");
|
|
1003
|
+
async function savePick(ctx, input, environment) {
|
|
1004
|
+
const now = ctx.ports.clock.now();
|
|
1005
|
+
await ctx.ports.transaction(async (db) => {
|
|
1006
|
+
const existing = await db.marketplaceIntegration.findUnique({
|
|
1007
|
+
where: keyOf(input.clientId, input.provider),
|
|
1008
|
+
select: { archivedAt: true }
|
|
1009
|
+
});
|
|
1010
|
+
const data = {
|
|
1011
|
+
credentials: sealAppLink(ctx),
|
|
1012
|
+
authMode: "LINKED",
|
|
1013
|
+
environment,
|
|
1014
|
+
status: "VERIFIED",
|
|
1015
|
+
lastVerifiedAt: now,
|
|
1016
|
+
archivedAt: null,
|
|
1017
|
+
externalMerchantId: input.merchantId
|
|
1018
|
+
};
|
|
1019
|
+
await db.marketplaceIntegration.upsert({
|
|
1020
|
+
where: keyOf(input.clientId, input.provider),
|
|
1021
|
+
create: { clientId: input.clientId, provider: input.provider, ackSlaSeconds: ctx.ports.defaultAckSlaSeconds, enabled: true, ...data },
|
|
1022
|
+
update: data
|
|
1023
|
+
});
|
|
1024
|
+
if (existing?.archivedAt) {
|
|
1025
|
+
await ctx.ports.audit.record(
|
|
1026
|
+
{ clientId: input.clientId, actorId: input.actorId, action: "marketplace.integration.unarchive", provider: input.provider, reason: "linked again", at: now },
|
|
1027
|
+
db
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
await db.marketplaceLinkAttempt?.deleteMany({ where: { clientId: input.clientId, provider: input.provider } });
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
__name(savePick, "savePick");
|
|
1034
|
+
async function selectAppMerchant(ctx, input) {
|
|
1035
|
+
const attempts = (await ctx.ports.db()).marketplaceLinkAttempt;
|
|
1036
|
+
const stored = attempts ? await attempts.findUnique({ where: keyOf(input.clientId, input.provider) }) : null;
|
|
1037
|
+
const environment = environmentOf(stored?.environment);
|
|
1038
|
+
const ready = await readyOf(ctx, input.provider, environment);
|
|
1039
|
+
if (!ready) return refused2("UNAVAILABLE");
|
|
1040
|
+
const merchants = await listFor(ctx, ready, { ...input, addresses: false });
|
|
1041
|
+
if (!Array.isArray(merchants)) return merchants;
|
|
1042
|
+
const merchant = merchants.find((candidate) => candidate.id === input.merchantId);
|
|
1043
|
+
if (!merchant) return refused2("UNKNOWN_MERCHANT");
|
|
1044
|
+
if (merchant.taken) return refused2("MERCHANT_TAKEN");
|
|
1045
|
+
const pick = { clientId: input.clientId, provider: input.provider, merchantId: input.merchantId, actorId: input.actorId ?? null };
|
|
1046
|
+
const taken = await guardMerchantClaim(ctx, pick, () => savePick(ctx, pick, environment)).then(
|
|
1047
|
+
() => false,
|
|
1048
|
+
(error) => {
|
|
1049
|
+
if (error instanceof MarketplaceMerchantTakenError || isUniqueViolation(error)) return true;
|
|
1050
|
+
throw error;
|
|
1051
|
+
}
|
|
1052
|
+
);
|
|
1053
|
+
if (taken) return refused2("MERCHANT_TAKEN");
|
|
1054
|
+
ctx.ports.publishChanged(input.clientId);
|
|
1055
|
+
const [view] = await listMarketplaceIntegrations(ctx, input.clientId, { providers: [input.provider] });
|
|
1056
|
+
if (!view) throw new Error(`The ${input.provider} connection of ${input.clientId} was not saved.`);
|
|
1057
|
+
return { kind: "selected", integration: view };
|
|
1058
|
+
}
|
|
1059
|
+
__name(selectAppMerchant, "selectAppMerchant");
|
|
1060
|
+
|
|
1061
|
+
// src/core/linking.ts
|
|
1062
|
+
var refused3 = /* @__PURE__ */ __name((code, status = null, message = null) => ({
|
|
1063
|
+
kind: "refused",
|
|
1064
|
+
code,
|
|
1065
|
+
status,
|
|
1066
|
+
message
|
|
1067
|
+
}), "refused");
|
|
1068
|
+
var pendingOf2 = /* @__PURE__ */ __name((row) => ({
|
|
802
1069
|
userCode: row.userCode,
|
|
803
1070
|
verificationUrl: row.verificationUrl,
|
|
804
1071
|
verificationUrlComplete: row.verificationUrlComplete,
|
|
@@ -814,22 +1081,22 @@ async function linkingOf(ctx, provider, environment) {
|
|
|
814
1081
|
return { linking, attempts, call: { http: ctx.ports.http, credentials: app, environment, now: ctx.ports.clock.now() } };
|
|
815
1082
|
}
|
|
816
1083
|
__name(linkingOf, "linkingOf");
|
|
817
|
-
var
|
|
1084
|
+
var keyOf2 = /* @__PURE__ */ __name((clientId, provider) => ({ clientId_provider: { clientId, provider } }), "keyOf");
|
|
818
1085
|
async function linkState(ctx, input) {
|
|
819
1086
|
const ready = await linkingOf(ctx, input.provider, input.environment ?? "PRODUCTION");
|
|
820
1087
|
if (!ready) return { available: false, pending: null };
|
|
821
|
-
const row = await ready.attempts.findUnique({ where:
|
|
1088
|
+
const row = await ready.attempts.findUnique({ where: keyOf2(input.clientId, input.provider) });
|
|
822
1089
|
const live = row && row.expiresAt.getTime() > ctx.ports.clock.now().getTime();
|
|
823
|
-
return { available: true, pending: live ?
|
|
1090
|
+
return { available: true, pending: live ? pendingOf2(row) : null };
|
|
824
1091
|
}
|
|
825
1092
|
__name(linkState, "linkState");
|
|
826
1093
|
async function startLink(ctx, input) {
|
|
827
1094
|
const environment = input.environment ?? "PRODUCTION";
|
|
828
1095
|
const ready = await linkingOf(ctx, input.provider, environment);
|
|
829
|
-
if (!ready) return
|
|
1096
|
+
if (!ready) return refused3("UNAVAILABLE");
|
|
830
1097
|
const answer = await ready.linking.requestCode(ready.call);
|
|
831
1098
|
if (answer.kind === "retry") return answer;
|
|
832
|
-
if (answer.kind === "refused") return
|
|
1099
|
+
if (answer.kind === "refused") return refused3("MARKETPLACE_REFUSED", answer.status, answer.message);
|
|
833
1100
|
const code = answer.value;
|
|
834
1101
|
const row = {
|
|
835
1102
|
environment,
|
|
@@ -840,11 +1107,11 @@ async function startLink(ctx, input) {
|
|
|
840
1107
|
expiresAt: new Date(ready.call.now.getTime() + code.expiresInSeconds * 1e3)
|
|
841
1108
|
};
|
|
842
1109
|
await ready.attempts.upsert({
|
|
843
|
-
where:
|
|
1110
|
+
where: keyOf2(input.clientId, input.provider),
|
|
844
1111
|
create: { clientId: input.clientId, provider: input.provider, ...row },
|
|
845
1112
|
update: row
|
|
846
1113
|
});
|
|
847
|
-
return { kind: "started", pending:
|
|
1114
|
+
return { kind: "started", pending: pendingOf2(row) };
|
|
848
1115
|
}
|
|
849
1116
|
__name(startLink, "startLink");
|
|
850
1117
|
async function chooseMerchant(db, input, merchants, current) {
|
|
@@ -859,7 +1126,7 @@ async function saveLink(ctx, input, link) {
|
|
|
859
1126
|
const credentials = sealLink(ctx, link.refreshToken);
|
|
860
1127
|
await ctx.ports.transaction(async (db) => {
|
|
861
1128
|
const existing = await db.marketplaceIntegration.findUnique({
|
|
862
|
-
where:
|
|
1129
|
+
where: keyOf2(input.clientId, input.provider),
|
|
863
1130
|
select: { archivedAt: true, externalMerchantId: true }
|
|
864
1131
|
});
|
|
865
1132
|
const data = {
|
|
@@ -873,7 +1140,7 @@ async function saveLink(ctx, input, link) {
|
|
|
873
1140
|
...input.enabled === void 0 ? {} : { enabled: input.enabled }
|
|
874
1141
|
};
|
|
875
1142
|
await db.marketplaceIntegration.upsert({
|
|
876
|
-
where:
|
|
1143
|
+
where: keyOf2(input.clientId, input.provider),
|
|
877
1144
|
create: { clientId: input.clientId, provider: input.provider, ackSlaSeconds: ctx.ports.defaultAckSlaSeconds, ...data },
|
|
878
1145
|
update: data
|
|
879
1146
|
});
|
|
@@ -917,9 +1184,9 @@ async function finishLink(ctx, input) {
|
|
|
917
1184
|
const { ready, environment, verifier, sealedVerifier } = opened;
|
|
918
1185
|
const exchanged = await ready.linking.exchange(ready.call, { authorizationCode: input.authorizationCode.trim(), verifier });
|
|
919
1186
|
if (exchanged.kind === "retry") return exchanged;
|
|
920
|
-
if (exchanged.kind === "refused") return
|
|
1187
|
+
if (exchanged.kind === "refused") return refused3("CODE_REFUSED", exchanged.status, exchanged.message);
|
|
921
1188
|
const grant = exchanged.value;
|
|
922
|
-
if (grant.refreshToken === null) return
|
|
1189
|
+
if (grant.refreshToken === null) return refused3("CODE_REFUSED", null, "the marketplace answered no refresh token");
|
|
923
1190
|
const listed = await ready.linking.merchants(ready.call, { accessToken: grant.accessToken });
|
|
924
1191
|
const merchants = listed.kind === "ok" ? listed.value : null;
|
|
925
1192
|
if (listed.kind !== "ok") {
|
|
@@ -933,38 +1200,38 @@ async function finishLink(ctx, input) {
|
|
|
933
1200
|
__name(finishLink, "finishLink");
|
|
934
1201
|
async function openAttempt(ctx, input) {
|
|
935
1202
|
const attempts = (await ctx.ports.db()).marketplaceLinkAttempt;
|
|
936
|
-
if (!attempts) return
|
|
937
|
-
const attempt = await attempts.findUnique({ where:
|
|
938
|
-
if (!attempt) return
|
|
1203
|
+
if (!attempts) return refused3("UNAVAILABLE");
|
|
1204
|
+
const attempt = await attempts.findUnique({ where: keyOf2(input.clientId, input.provider) });
|
|
1205
|
+
if (!attempt) return refused3("NO_LINK_IN_PROGRESS");
|
|
939
1206
|
const environment = attempt.environment === "SANDBOX" ? "SANDBOX" : "PRODUCTION";
|
|
940
1207
|
const ready = await linkingOf(ctx, input.provider, environment);
|
|
941
|
-
if (!ready) return
|
|
942
|
-
if (attempt.expiresAt.getTime() <= ready.call.now.getTime()) return
|
|
1208
|
+
if (!ready) return refused3("UNAVAILABLE");
|
|
1209
|
+
if (attempt.expiresAt.getTime() <= ready.call.now.getTime()) return refused3("LINK_EXPIRED");
|
|
943
1210
|
return { ready, environment, verifier: ctx.ports.secrets.open(attempt.verifier), sealedVerifier: attempt.verifier };
|
|
944
1211
|
}
|
|
945
1212
|
__name(openAttempt, "openAttempt");
|
|
946
1213
|
async function grantCall(ctx, clientId, provider) {
|
|
947
1214
|
const views = await listMarketplaceIntegrations(ctx, clientId, { providers: [provider] });
|
|
948
|
-
if (views[0]?.authMode !== "LINKED") return
|
|
1215
|
+
if (views[0]?.authMode !== "LINKED") return refused3("NOT_LINKED");
|
|
949
1216
|
const connection = await readOutboundConnection(ctx, clientId, provider).catch(() => null);
|
|
950
|
-
if (!connection?.grant) return
|
|
1217
|
+
if (!connection?.grant) return refused3("UNAVAILABLE");
|
|
951
1218
|
const token = await connection.grant.accessToken();
|
|
952
1219
|
if ("token" in token) {
|
|
953
1220
|
const call = { http: ctx.ports.http, credentials: connection.credentials, environment: connection.environment, now: ctx.ports.clock.now() };
|
|
954
1221
|
return { call, accessToken: token.token };
|
|
955
1222
|
}
|
|
956
1223
|
if (token.kind === "retry") return token;
|
|
957
|
-
return token.kind === "refused" ?
|
|
1224
|
+
return token.kind === "refused" ? refused3("NOT_LINKED", token.status, token.message) : refused3("NOT_LINKED");
|
|
958
1225
|
}
|
|
959
1226
|
__name(grantCall, "grantCall");
|
|
960
1227
|
async function grantMerchants(ctx, clientId, provider) {
|
|
961
1228
|
const linking = ctx.registry.get(provider)?.linking;
|
|
962
|
-
if (!linking) return
|
|
1229
|
+
if (!linking) return refused3("UNAVAILABLE");
|
|
963
1230
|
const granted = await grantCall(ctx, clientId, provider);
|
|
964
1231
|
if ("kind" in granted) return granted;
|
|
965
1232
|
const listed = await linking.merchants(granted.call, { accessToken: granted.accessToken });
|
|
966
1233
|
if (listed.kind === "ok") return listed.value;
|
|
967
|
-
return listed.kind === "retry" ? listed :
|
|
1234
|
+
return listed.kind === "retry" ? listed : refused3("MARKETPLACE_REFUSED", listed.status, listed.message);
|
|
968
1235
|
}
|
|
969
1236
|
__name(grantMerchants, "grantMerchants");
|
|
970
1237
|
async function linkedMerchants(ctx, input) {
|
|
@@ -975,9 +1242,9 @@ __name(linkedMerchants, "linkedMerchants");
|
|
|
975
1242
|
async function selectLinkedMerchant(ctx, input) {
|
|
976
1243
|
const merchants = await grantMerchants(ctx, input.clientId, input.provider);
|
|
977
1244
|
if (!Array.isArray(merchants)) return merchants;
|
|
978
|
-
if (!merchants.some((merchant) => merchant.id === input.merchantId)) return
|
|
1245
|
+
if (!merchants.some((merchant) => merchant.id === input.merchantId)) return refused3("UNKNOWN_MERCHANT");
|
|
979
1246
|
const db = await ctx.ports.db();
|
|
980
|
-
if (await merchantHeldElsewhere(db, input.clientId, input.provider, input.merchantId)) return
|
|
1247
|
+
if (await merchantHeldElsewhere(db, input.clientId, input.provider, input.merchantId)) return refused3("MERCHANT_TAKEN");
|
|
981
1248
|
const write = /* @__PURE__ */ __name(() => db.marketplaceIntegration.updateMany({
|
|
982
1249
|
where: { clientId: input.clientId, provider: input.provider, authMode: "LINKED", archivedAt: null },
|
|
983
1250
|
data: { externalMerchantId: input.merchantId }
|
|
@@ -989,12 +1256,81 @@ async function selectLinkedMerchant(ctx, input) {
|
|
|
989
1256
|
throw error;
|
|
990
1257
|
}
|
|
991
1258
|
);
|
|
992
|
-
if (taken) return
|
|
1259
|
+
if (taken) return refused3("MERCHANT_TAKEN");
|
|
993
1260
|
ctx.ports.publishChanged(input.clientId);
|
|
994
1261
|
return { kind: "selected", integration: await viewOf2(ctx, input.clientId, input.provider) };
|
|
995
1262
|
}
|
|
996
1263
|
__name(selectLinkedMerchant, "selectLinkedMerchant");
|
|
997
1264
|
|
|
1265
|
+
// src/core/link-engine.ts
|
|
1266
|
+
var appPendingView = /* @__PURE__ */ __name((pending) => ({
|
|
1267
|
+
userCode: "",
|
|
1268
|
+
verificationUrl: pending.portalUrl,
|
|
1269
|
+
verificationUrlComplete: pending.portalUrl,
|
|
1270
|
+
expiresAt: pending.expiresAt,
|
|
1271
|
+
mode: "app",
|
|
1272
|
+
seenAt: pending.seenAt,
|
|
1273
|
+
checkedAt: pending.checkedAt
|
|
1274
|
+
}), "appPendingView");
|
|
1275
|
+
var NO_CODE = {
|
|
1276
|
+
kind: "refused",
|
|
1277
|
+
code: "UNAVAILABLE",
|
|
1278
|
+
status: null,
|
|
1279
|
+
message: "this marketplace links without a code"
|
|
1280
|
+
};
|
|
1281
|
+
function linkEngine(ctx) {
|
|
1282
|
+
const app = /* @__PURE__ */ __name((provider) => hasAppLinking(ctx, provider), "app");
|
|
1283
|
+
return {
|
|
1284
|
+
linkState: /* @__PURE__ */ __name(async (input) => {
|
|
1285
|
+
if (!app(input.provider)) return linkState(ctx, input);
|
|
1286
|
+
const state = await appLinkState(ctx, input);
|
|
1287
|
+
return {
|
|
1288
|
+
available: state.available,
|
|
1289
|
+
pending: state.pending ? appPendingView(state.pending) : null
|
|
1290
|
+
};
|
|
1291
|
+
}, "linkState"),
|
|
1292
|
+
startLink: /* @__PURE__ */ __name(async (input) => {
|
|
1293
|
+
if (!app(input.provider)) return startLink(ctx, input);
|
|
1294
|
+
const started = await startAppLink(ctx, input);
|
|
1295
|
+
return started.kind === "started" ? { kind: "started", pending: appPendingView(started.pending) } : started;
|
|
1296
|
+
}, "startLink"),
|
|
1297
|
+
finishLink: /* @__PURE__ */ __name((input) => app(input.provider) ? Promise.resolve(NO_CODE) : finishLink(ctx, input), "finishLink"),
|
|
1298
|
+
linkedMerchants: /* @__PURE__ */ __name(async (input) => {
|
|
1299
|
+
if (!app(input.provider)) return linkedMerchants(ctx, input);
|
|
1300
|
+
const checked = await checkAppLink(ctx, input);
|
|
1301
|
+
return checked.kind === "checked" ? { kind: "listed", merchants: checked.merchants } : checked;
|
|
1302
|
+
}, "linkedMerchants"),
|
|
1303
|
+
selectLinkedMerchant: /* @__PURE__ */ __name((input) => app(input.provider) ? selectAppMerchant(ctx, input) : selectLinkedMerchant(ctx, input), "selectLinkedMerchant"),
|
|
1304
|
+
checkLink: /* @__PURE__ */ __name(async (input) => {
|
|
1305
|
+
if (!app(input.provider))
|
|
1306
|
+
return {
|
|
1307
|
+
kind: "refused",
|
|
1308
|
+
code: "UNAVAILABLE",
|
|
1309
|
+
status: null,
|
|
1310
|
+
message: null
|
|
1311
|
+
};
|
|
1312
|
+
const checked = await checkAppLink(ctx, input);
|
|
1313
|
+
return checked.kind === "checked" ? {
|
|
1314
|
+
...checked,
|
|
1315
|
+
pending: checked.pending ? appPendingView(checked.pending) : null
|
|
1316
|
+
} : checked;
|
|
1317
|
+
}, "checkLink"),
|
|
1318
|
+
cancelLink: /* @__PURE__ */ __name((input) => cancelAppLink(ctx, input), "cancelLink"),
|
|
1319
|
+
sweepLinks: /* @__PURE__ */ __name((input) => sweepAppLinks(ctx, input), "sweepLinks")
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
__name(linkEngine, "linkEngine");
|
|
1323
|
+
|
|
1324
|
+
// src/core/dispute-engine.ts
|
|
1325
|
+
function disputeEngine(ctx) {
|
|
1326
|
+
return {
|
|
1327
|
+
disputes: /* @__PURE__ */ __name((input) => readDisputes(ctx, input), "disputes"),
|
|
1328
|
+
answerDispute: /* @__PURE__ */ __name((input) => answerDispute(ctx, input), "answerDispute"),
|
|
1329
|
+
runDisputeAnswer: /* @__PURE__ */ __name((payload, attempt) => runDisputeAnswer(ctx, payload, attempt), "runDisputeAnswer")
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
__name(disputeEngine, "disputeEngine");
|
|
1333
|
+
|
|
998
1334
|
// src/core/status-inform.ts
|
|
999
1335
|
async function informStatus(ctx, input) {
|
|
1000
1336
|
const payload = { clientId: input.clientId, orderId: input.orderId, action: "status", step: input.step, claimKey: String(input.at.getTime()) };
|
|
@@ -1358,6 +1694,8 @@ async function applyEvent(ctx, inboxId, clientId, event, settings, now) {
|
|
|
1358
1694
|
}
|
|
1359
1695
|
__name(applyEvent, "applyEvent");
|
|
1360
1696
|
async function followMarketplace(ctx, inboxId, clientId, event, settings) {
|
|
1697
|
+
const disputed = await applyDisputeEvent(ctx, inboxId, clientId, event);
|
|
1698
|
+
if (disputed) return disputed;
|
|
1361
1699
|
const confirmed = await applyMarketplaceConfirmation(ctx, inboxId, clientId, event);
|
|
1362
1700
|
return confirmed ?? followCourierAndLifecycle(ctx, inboxId, clientId, event, settings);
|
|
1363
1701
|
}
|
|
@@ -1495,11 +1833,6 @@ function createMarketplaceEngine(config) {
|
|
|
1495
1833
|
async () => saveMarketplaceIntegration(ctx, input, await ports.db())
|
|
1496
1834
|
), "saveIntegration"),
|
|
1497
1835
|
upsertIntegrations: /* @__PURE__ */ __name((input) => upsertIntegrations(ctx, input), "upsertIntegrations"),
|
|
1498
|
-
linkState: /* @__PURE__ */ __name((input) => linkState(ctx, input), "linkState"),
|
|
1499
|
-
startLink: /* @__PURE__ */ __name((input) => startLink(ctx, input), "startLink"),
|
|
1500
|
-
finishLink: /* @__PURE__ */ __name((input) => finishLink(ctx, input), "finishLink"),
|
|
1501
|
-
linkedMerchants: /* @__PURE__ */ __name((input) => linkedMerchants(ctx, input), "linkedMerchants"),
|
|
1502
|
-
selectLinkedMerchant: /* @__PURE__ */ __name((input) => selectLinkedMerchant(ctx, input), "selectLinkedMerchant"),
|
|
1503
1836
|
menuLinks: /* @__PURE__ */ __name((input) => listMarketplaceMenuLinks(ctx, input), "menuLinks"),
|
|
1504
1837
|
upsertMenuLinks: /* @__PURE__ */ __name((input) => upsertMenuLinks(ctx, input), "upsertMenuLinks"),
|
|
1505
1838
|
setMenuLink: /* @__PURE__ */ __name(async ({ clientId, ...row }) => {
|
|
@@ -1519,7 +1852,7 @@ function createMarketplaceEngine(config) {
|
|
|
1519
1852
|
runOutbound: /* @__PURE__ */ __name((payload, attempt) => runOutbound(ctx, payload, attempt), "runOutbound"),
|
|
1520
1853
|
runFetchOrder: /* @__PURE__ */ __name((payload, attempt) => runFetchOrder(ctx, payload, attempt), "runFetchOrder"),
|
|
1521
1854
|
informStatus: /* @__PURE__ */ __name((input) => informStatus(ctx, input), "informStatus"),
|
|
1522
|
-
...{ ...courierEngine(ctx), ...conformityEngine(ctx) },
|
|
1855
|
+
...{ ...courierEngine(ctx), ...conformityEngine(ctx), ...linkEngine(ctx), ...disputeEngine(ctx) },
|
|
1523
1856
|
// Null too when the host bound no catalogue port: nothing could be published.
|
|
1524
1857
|
catalogueMode: /* @__PURE__ */ __name((provider) => ports.catalogue ? registry.get(provider)?.catalogue?.mode ?? null : null, "catalogueMode"),
|
|
1525
1858
|
publish: /* @__PURE__ */ __name((input) => publishToCatalogue(ctx, input), "publish"),
|
|
@@ -1544,12 +1877,17 @@ export {
|
|
|
1544
1877
|
CONFIRMED_BEFORE_ORDER,
|
|
1545
1878
|
CancellationReasonsRetryError,
|
|
1546
1879
|
CatalogueRetryError,
|
|
1880
|
+
DisputeAnswerRetryError,
|
|
1547
1881
|
FetchOrderRetryError,
|
|
1882
|
+
ATTEMPT_MINUTES as LINK_ATTEMPT_MINUTES,
|
|
1883
|
+
CHECK_EVERY_SECONDS as LINK_CHECK_EVERY_SECONDS,
|
|
1548
1884
|
MARKETPLACE_ACKNOWLEDGE_JOB,
|
|
1549
1885
|
MARKETPLACE_AVAILABILITY_JOB,
|
|
1550
1886
|
MARKETPLACE_CANCELLATION_REASONS_JOB,
|
|
1551
1887
|
MARKETPLACE_CATALOGUE_JOB,
|
|
1888
|
+
MARKETPLACE_DISPUTE_ANSWER_JOB,
|
|
1552
1889
|
MARKETPLACE_FETCH_ORDER_JOB,
|
|
1890
|
+
MARKETPLACE_LINK_CHECK_JOB,
|
|
1553
1891
|
MARKETPLACE_OUTBOUND_JOB,
|
|
1554
1892
|
MarketplaceAdapterRegistrationError,
|
|
1555
1893
|
MarketplaceMerchantTakenError,
|
|
@@ -1564,6 +1902,7 @@ export {
|
|
|
1564
1902
|
centsFromMajor,
|
|
1565
1903
|
createAdapterRegistry,
|
|
1566
1904
|
createMarketplaceEngine,
|
|
1905
|
+
disputeView,
|
|
1567
1906
|
normalizedLineTotalCents,
|
|
1568
1907
|
outboundDedupeKey,
|
|
1569
1908
|
outboundResultOf,
|