@12-apps/marketplace 1.15.0 → 1.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADOPTING.md +5 -2
- package/dist/{chunk-FQI56NGC.js → chunk-DJIMUEHT.js} +2 -2
- package/dist/{chunk-B4DYPQFE.js → chunk-TICWLBSA.js} +26 -7
- package/dist/chunk-TICWLBSA.js.map +1 -0
- package/dist/{engine-BSLdhAGC.d.ts → engine-DSRj7qnC.d.ts} +9 -0
- package/dist/hono/index.d.ts +1 -1
- package/dist/hono/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/manifest/server.d.ts +1 -1
- package/dist/manifest/server.js +2 -2
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +2 -2
- package/package.json +1 -1
- package/src/core/ingest.ts +5 -5
- package/src/core/order-reasons.ts +46 -8
- package/dist/chunk-B4DYPQFE.js.map +0 -1
- /package/dist/{chunk-FQI56NGC.js.map → chunk-DJIMUEHT.js.map} +0 -0
|
@@ -938,6 +938,13 @@ declare class AcknowledgeRetryError extends Error {
|
|
|
938
938
|
* kept on the acceptance row (`cancellation_reasons`) for the order's life.
|
|
939
939
|
* The adapter's static list is the fallback while, or when, that read did not
|
|
940
940
|
* land: a refusal is never held on the marketplace.
|
|
941
|
+
*
|
|
942
|
+
* The same job, for an order the store did not auto-accept, first applies a
|
|
943
|
+
* confirmation on the marketplace that arrived before the order (FUT-5653's
|
|
944
|
+
* C5). It runs here, a few seconds after the ingest, rather than inside it, so
|
|
945
|
+
* the ingest pays no inbox read that almost always finds nothing (FUT-5984).
|
|
946
|
+
* A job that is late or lost loses nothing: the expiry sweep applies a deferred
|
|
947
|
+
* confirmation before it expires the order (`applyOwedConfirmations`).
|
|
941
948
|
*/
|
|
942
949
|
/** The wire name, `<namespace>.<blueprint>`. */
|
|
943
950
|
declare const MARKETPLACE_CANCELLATION_REASONS_JOB = "marketplace.cancellation-reasons";
|
|
@@ -945,6 +952,8 @@ declare const MARKETPLACE_CANCELLATION_REASONS_JOB = "marketplace.cancellation-r
|
|
|
945
952
|
interface CancellationReasonsJobPayload {
|
|
946
953
|
clientId: string;
|
|
947
954
|
orderId: string;
|
|
955
|
+
/** Set for an order not auto-accepted: apply a confirmation that outran it first. */
|
|
956
|
+
deferredConfirmations?: true;
|
|
948
957
|
}
|
|
949
958
|
/** What one run did. */
|
|
950
959
|
type CancellationReasonsOutcome = {
|
package/dist/hono/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Hono, Context } from 'hono';
|
|
2
2
|
import { ApiMarketplace, MarketplaceApiConfig, MarketplaceActor } from '../server/index.js';
|
|
3
|
-
import '../engine-
|
|
3
|
+
import '../engine-DSRj7qnC.js';
|
|
4
4
|
import '../adapter-CjVdMhZ2.js';
|
|
5
5
|
import '@12-apps/wiring';
|
|
6
6
|
import 'zod';
|
package/dist/hono/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AcceptanceDecision, a as AcceptanceStatus, b as AcknowledgeJobPayload, c as AcknowledgeOutcome, d as AcknowledgeRetryError, e as AvailabilityJobPayload, f as AvailabilityOutcome, g as AvailabilityRetryError, h as AvailabilitySweepResult, B as BulkProblem, i as BulkProblemCode, j as BulkResult, C as CancellationFailureReason, k as CancellationReasonsJobPayload, l as CancellationReasonsOutcome, m as CancellationReasonsRetryError, n as CancellationStatus, o as CatalogueAction, p as CatalogueActionResult, q as CatalogueDocumentResult, r as CatalogueFailedAction, s as CatalogueFailureCode, t as CatalogueJobPayload, u as CatalogueOutcome, v as CataloguePublicationView, w as CataloguePublishInput, x as CatalogueRefusalCode, y as CatalogueRetryError, z as CatalogueStatus, D as CatalogueTarget, E as DecideManyResult, F as DecidedRow, G as DecisionInput, H as DecisionProblem, I as DecisionProblemCode, J as DecisionResult, K as DeliveryOutcome, L as ExpirySweepResult, M as FetchOrderJobPayload, N as FetchOrderOutcome, O as FetchOrderRetryError, P as InformStatusInput, Q as IngestResult, R as IngestSettings, S as IngestionTarget, T as IntegrationRowInput, U as LinkFailure, V as LinkFinished, W as LinkPendingView, X as LinkRefusalCode, Y as MARKETPLACE_ACKNOWLEDGE_JOB, Z as MARKETPLACE_AVAILABILITY_JOB, _ as MARKETPLACE_CANCELLATION_REASONS_JOB, $ as MARKETPLACE_CATALOGUE_JOB, a0 as MARKETPLACE_FETCH_ORDER_JOB, a1 as MARKETPLACE_OUTBOUND_JOB, a2 as MarketplaceAdmission, a3 as MarketplaceAdmissionRequest, a4 as MarketplaceAdmissionResult, a5 as MarketplaceAuditEntry, a6 as MarketplaceAuditPort, a7 as MarketplaceAuthMode, a8 as MarketplaceCataloguePort, a9 as MarketplaceClockPort, aa as MarketplaceConformityEngine, ab as MarketplaceDb, ac as MarketplaceEngine, ad as MarketplaceEngineConfig, ae as MarketplaceEnqueuePort, af as MarketplaceIntegrationView, ag as MarketplaceLifecycleAnswer, ah as MarketplaceLifecycleFacts, ai as MarketplaceLogger, aj as MarketplaceMenuLinkView, ak as MarketplaceOrderPort, al as MarketplaceOrderState, am as MarketplaceOrderSummary, an as MarketplacePorts, ao as MarketplaceRefusal, ap as MarketplaceSecretsPort, aq as MenuLinkRowInput, ar as OUTBOUND_GIVE_UP_MS, as as OUTBOUND_STALE_MS, at as OutboundAction, au as OutboundAttempt, av as OutboundJobPayload, aw as OutboundOutcome, ax as OutboundRetryError, ay as OutboundSweepResult, az as PauseOutcome, aA as PauseStoreInput, aB as PauseStoreResult, aC as PendingAcceptance, aD as PendingInboxEvent, aE as ResolvedOrderLine, aF as ResumeOutcome, aG as STORE_PAUSE_LEASE_MS, aH as SaveMarketplaceIntegrationInput, aI as StoreAvailabilityView, aJ as StorePauseFailureCode, aK as StorePauseState, aL as StorePauseWanted, aM as availabilityDedupeKey, aN as catalogueDedupeKey, aO as createMarketplaceEngine, aP as outboundDedupeKey } from './engine-
|
|
1
|
+
export { A as AcceptanceDecision, a as AcceptanceStatus, b as AcknowledgeJobPayload, c as AcknowledgeOutcome, d as AcknowledgeRetryError, e as AvailabilityJobPayload, f as AvailabilityOutcome, g as AvailabilityRetryError, h as AvailabilitySweepResult, B as BulkProblem, i as BulkProblemCode, j as BulkResult, C as CancellationFailureReason, k as CancellationReasonsJobPayload, l as CancellationReasonsOutcome, m as CancellationReasonsRetryError, n as CancellationStatus, o as CatalogueAction, p as CatalogueActionResult, q as CatalogueDocumentResult, r as CatalogueFailedAction, s as CatalogueFailureCode, t as CatalogueJobPayload, u as CatalogueOutcome, v as CataloguePublicationView, w as CataloguePublishInput, x as CatalogueRefusalCode, y as CatalogueRetryError, z as CatalogueStatus, D as CatalogueTarget, E as DecideManyResult, F as DecidedRow, G as DecisionInput, H as DecisionProblem, I as DecisionProblemCode, J as DecisionResult, K as DeliveryOutcome, L as ExpirySweepResult, M as FetchOrderJobPayload, N as FetchOrderOutcome, O as FetchOrderRetryError, P as InformStatusInput, Q as IngestResult, R as IngestSettings, S as IngestionTarget, T as IntegrationRowInput, U as LinkFailure, V as LinkFinished, W as LinkPendingView, X as LinkRefusalCode, Y as MARKETPLACE_ACKNOWLEDGE_JOB, Z as MARKETPLACE_AVAILABILITY_JOB, _ as MARKETPLACE_CANCELLATION_REASONS_JOB, $ as MARKETPLACE_CATALOGUE_JOB, a0 as MARKETPLACE_FETCH_ORDER_JOB, a1 as MARKETPLACE_OUTBOUND_JOB, a2 as MarketplaceAdmission, a3 as MarketplaceAdmissionRequest, a4 as MarketplaceAdmissionResult, a5 as MarketplaceAuditEntry, a6 as MarketplaceAuditPort, a7 as MarketplaceAuthMode, a8 as MarketplaceCataloguePort, a9 as MarketplaceClockPort, aa as MarketplaceConformityEngine, ab as MarketplaceDb, ac as MarketplaceEngine, ad as MarketplaceEngineConfig, ae as MarketplaceEnqueuePort, af as MarketplaceIntegrationView, ag as MarketplaceLifecycleAnswer, ah as MarketplaceLifecycleFacts, ai as MarketplaceLogger, aj as MarketplaceMenuLinkView, ak as MarketplaceOrderPort, al as MarketplaceOrderState, am as MarketplaceOrderSummary, an as MarketplacePorts, ao as MarketplaceRefusal, ap as MarketplaceSecretsPort, aq as MenuLinkRowInput, ar as OUTBOUND_GIVE_UP_MS, as as OUTBOUND_STALE_MS, at as OutboundAction, au as OutboundAttempt, av as OutboundJobPayload, aw as OutboundOutcome, ax as OutboundRetryError, ay as OutboundSweepResult, az as PauseOutcome, aA as PauseStoreInput, aB as PauseStoreResult, aC as PendingAcceptance, aD as PendingInboxEvent, aE as ResolvedOrderLine, aF as ResumeOutcome, aG as STORE_PAUSE_LEASE_MS, aH as SaveMarketplaceIntegrationInput, aI as StoreAvailabilityView, aJ as StorePauseFailureCode, aK as StorePauseState, aL as StorePauseWanted, aM as availabilityDedupeKey, aN as catalogueDedupeKey, aO as createMarketplaceEngine, aP as outboundDedupeKey } from './engine-DSRj7qnC.js';
|
|
2
2
|
import { c as MarketplaceAdapter, l as MarketplaceProvider, m as CancellationReason } from './adapter-CjVdMhZ2.js';
|
|
3
3
|
export { A as AdapterCallContext, n as AdapterGrant, o as AdapterTokenCache, p as CancellationOutcome, q as CancellationRequestInput, r as CatalogueCallContext, s as CatalogueFailure, t as CatalogueImage, u as CatalogueItem, e as CatalogueItemOut, v as CatalogueItemRef, C as CatalogueMenuEntry, b as CatalogueMenuOptions, w as CataloguePublishResult, x as CatalogueReadContext, y as CatalogueReadNotice, z as CatalogueReadRefusalCode, B as CatalogueReadResult, D as CatalogueReadWarning, E as CatalogueReadWarningCode, f as CatalogueReader, G as CatalogueSnapshot, H as CatalogueSnapshotCategory, I as CatalogueSnapshotItem, J as CatalogueSnapshotOption, K as CatalogueSnapshotOptionGroup, L as CatalogueStoredImage, Q as CatalogueWarningCode, R as CourierTrackingCallResult, T as CourierTrackingResult, F as FetchOrderResult, U as LinkCallContext, V as LinkCode, W as LinkGrant, X as LinkResult, Y as LinkedMerchant, Z as MarketplaceAcknowledgement, _ as MarketplaceAppCredentialsPort, M as MarketplaceAvailability, $ as MarketplaceCapabilities, a0 as MarketplaceCatalogue, a1 as MarketplaceCourier, a2 as MarketplaceCourierAnswer, h as MarketplaceCourierApi, a3 as MarketplaceCourierEngine, a4 as MarketplaceCourierFacts, a5 as MarketplaceCourierStep, a6 as MarketplaceCourierTracking, a7 as MarketplaceCourierVehicle, a8 as MarketplaceCredentials, a9 as MarketplaceDeliveredBy, aa as MarketplaceDiscountSponsor, ab as MarketplaceHttp, ac as MarketplaceHttpRequest, ad as MarketplaceHttpResponse, ae as MarketplaceLifecycle, af as MarketplaceLinkAttemptDelegate, g as MarketplaceLinking, ag as MarketplaceOrderType, ah as MarketplacePaymentMethod, ai as NormalizedAddress, aj as NormalizedBuyer, i as NormalizedCourierEvent, N as NormalizedEvent, ak as NormalizedLineOption, a as NormalizedMarketplaceOrder, al as NormalizedOrderDiscount, am as NormalizedOrderFee, an as NormalizedOrderLine, ao as NormalizedPaymentMethod, ap as NormalizedPayments, aq as OrderCancellationReason, ar as OrderCancellationReasonsResult, as as OutboundOrderRef, O as OutboundResult, at as PROVIDER_ID_PATTERN, au as PickupCodeCallResult, av as PickupCodeValidation, aw as PresenceProbe, P as PullCatalogue, d as PushCatalogue, ax as StatusFacts, ay as StatusStep, k as StorePauseRef, S as StorePauseRequest, j as StorePauseResult, az as ValidatePickupCodeInput, aA as answered, aB as centsFromMajor, aC as normalizedLineTotalCents, aD as outboundResultOf, aE as tokenGrantResultOf } from './adapter-CjVdMhZ2.js';
|
|
4
4
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { av as OutboundJobPayload, M as FetchOrderJobPayload, b as AcknowledgeJobPayload, k as CancellationReasonsJobPayload, t as CatalogueJobPayload, e as AvailabilityJobPayload } from '../engine-
|
|
1
|
+
import { av as OutboundJobPayload, M as FetchOrderJobPayload, b as AcknowledgeJobPayload, k as CancellationReasonsJobPayload, t as CatalogueJobPayload, e as AvailabilityJobPayload } from '../engine-DSRj7qnC.js';
|
|
2
2
|
import * as _12_apps_wiring from '@12-apps/wiring';
|
|
3
3
|
import { createApiMarketplace, MarketplaceJobDeps } from '../server/index.js';
|
|
4
4
|
import '../adapter-CjVdMhZ2.js';
|
package/dist/manifest/server.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MARKETPLACE_JOBS,
|
|
3
3
|
createApiMarketplace
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-DJIMUEHT.js";
|
|
5
5
|
import "../chunk-SGOTN5PX.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-TICWLBSA.js";
|
|
7
7
|
import "../chunk-H2VQRD3B.js";
|
|
8
8
|
import "../chunk-7QVYU63E.js";
|
|
9
9
|
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as DecisionProblemCode, i as BulkProblemCode, X as LinkRefusalCode, ac as MarketplaceEngine, ai as MarketplaceLogger, av as OutboundJobPayload, M as FetchOrderJobPayload, b as AcknowledgeJobPayload, k as CancellationReasonsJobPayload, t as CatalogueJobPayload, e as AvailabilityJobPayload } from '../engine-
|
|
1
|
+
import { I as DecisionProblemCode, i as BulkProblemCode, X as LinkRefusalCode, ac as MarketplaceEngine, ai as MarketplaceLogger, av as OutboundJobPayload, M as FetchOrderJobPayload, b as AcknowledgeJobPayload, k as CancellationReasonsJobPayload, t as CatalogueJobPayload, e as AvailabilityJobPayload } from '../engine-DSRj7qnC.js';
|
|
2
2
|
import { WireRoute, WireJobBlueprint } from '@12-apps/wiring';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import '../adapter-CjVdMhZ2.js';
|
package/dist/server/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
MARKETPLACE_SWEEP_QUEUE,
|
|
7
7
|
ORDER_NOT_PENDING_CODE,
|
|
8
8
|
createApiMarketplace
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-DJIMUEHT.js";
|
|
10
10
|
import {
|
|
11
11
|
MARKETPLACE_DECIDE,
|
|
12
12
|
MARKETPLACE_MANAGE,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
upsertMarketplaceIntegrationsBody,
|
|
21
21
|
upsertMarketplaceMenuLinksBody
|
|
22
22
|
} from "../chunk-SGOTN5PX.js";
|
|
23
|
-
import "../chunk-
|
|
23
|
+
import "../chunk-TICWLBSA.js";
|
|
24
24
|
import "../chunk-H2VQRD3B.js";
|
|
25
25
|
import "../chunk-7QVYU63E.js";
|
|
26
26
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@12-apps/marketplace",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "One marketplace integration engine for every marketplace: the durable inbox, the ingest pipeline, the acceptance clock and its sweep, the SKU map, the integration settings with sealed credentials, and the outbound engine (confirm, cancellation request, retries), behind an adapter port. Each marketplace is an adapter at its own subpath (./ifood, ./99food and ./keeta on Open Delivery, ./rappi). Framework-neutral wiring route descriptors (./server) with a Hono adapter (./hono), dep-free job blueprints, MCP tools and the package-owned Prisma partial + migrations.",
|
package/src/core/ingest.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { applyDeferredConfirmations } from "./marketplace-confirmed";
|
|
2
1
|
import { enqueueOrderReasons } from "./order-reasons";
|
|
3
2
|
import { markMarketplaceEventSeen } from "./integration";
|
|
4
3
|
import { resolveSkus } from "./menu-links";
|
|
@@ -209,10 +208,11 @@ export async function ingestMarketplaceOrder(
|
|
|
209
208
|
}
|
|
210
209
|
|
|
211
210
|
ctx.ports.publishChanged(clientId);
|
|
212
|
-
// After the commit: the order's own cancellation reasons are read
|
|
213
|
-
// confirmation on the marketplace that outran
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
// After the commit, in one job: the order's own cancellation reasons are read and,
|
|
212
|
+
// for an order nobody accepted yet, a confirmation on the marketplace that outran it
|
|
213
|
+
// is applied (FUT-5984, FUT-5653). Never inline: that read almost always finds
|
|
214
|
+
// nothing, and the expiry sweep applies what a late job has not yet.
|
|
215
|
+
await enqueueOrderReasons(ctx, { clientId, orderId, provider: order.provider, deferredConfirmations: !accepted });
|
|
216
216
|
|
|
217
217
|
return { orderId, created: true, unmappedSkus, autoAccepted: accepted };
|
|
218
218
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CancellationReason, OrderCancellationReason } from "./adapter";
|
|
2
2
|
import { readOutboundConnection } from "./integration";
|
|
3
|
+
import { applyDeferredConfirmations } from "./marketplace-confirmed";
|
|
3
4
|
import type { EngineContext, MarketplaceDb } from "./ports";
|
|
4
5
|
import { reasonsForOrder, storedReasons } from "./registry";
|
|
5
6
|
import type { MarketplaceProvider } from "./types";
|
|
@@ -11,6 +12,13 @@ import type { MarketplaceProvider } from "./types";
|
|
|
11
12
|
* kept on the acceptance row (`cancellation_reasons`) for the order's life.
|
|
12
13
|
* The adapter's static list is the fallback while, or when, that read did not
|
|
13
14
|
* land: a refusal is never held on the marketplace.
|
|
15
|
+
*
|
|
16
|
+
* The same job, for an order the store did not auto-accept, first applies a
|
|
17
|
+
* confirmation on the marketplace that arrived before the order (FUT-5653's
|
|
18
|
+
* C5). It runs here, a few seconds after the ingest, rather than inside it, so
|
|
19
|
+
* the ingest pays no inbox read that almost always finds nothing (FUT-5984).
|
|
20
|
+
* A job that is late or lost loses nothing: the expiry sweep applies a deferred
|
|
21
|
+
* confirmation before it expires the order (`applyOwedConfirmations`).
|
|
14
22
|
*/
|
|
15
23
|
|
|
16
24
|
/** The wire name, `<namespace>.<blueprint>`. */
|
|
@@ -20,6 +28,8 @@ export const MARKETPLACE_CANCELLATION_REASONS_JOB = "marketplace.cancellation-re
|
|
|
20
28
|
export interface CancellationReasonsJobPayload {
|
|
21
29
|
clientId: string;
|
|
22
30
|
orderId: string;
|
|
31
|
+
/** Set for an order not auto-accepted: apply a confirmation that outran it first. */
|
|
32
|
+
deferredConfirmations?: true;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
/** What one run did. */
|
|
@@ -36,13 +46,22 @@ export class CancellationReasonsRetryError extends Error {
|
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Queue the job after a new order's commit, when its marketplace lists reasons per
|
|
51
|
+
* order or (for an order not auto-accepted) confirms on its own side. Never throws.
|
|
52
|
+
*/
|
|
40
53
|
export async function enqueueOrderReasons(
|
|
41
54
|
ctx: EngineContext,
|
|
42
|
-
input: { clientId: string; orderId: string; provider: MarketplaceProvider },
|
|
55
|
+
input: { clientId: string; orderId: string; provider: MarketplaceProvider; deferredConfirmations?: boolean },
|
|
43
56
|
): Promise<void> {
|
|
44
|
-
|
|
45
|
-
const
|
|
57
|
+
const adapter = ctx.registry.get(input.provider);
|
|
58
|
+
const deferred = input.deferredConfirmations === true && adapter?.capabilities.marketplaceConfirms === true;
|
|
59
|
+
if (!adapter?.orderCancellationReasons && !deferred) return;
|
|
60
|
+
const payload: CancellationReasonsJobPayload = {
|
|
61
|
+
clientId: input.clientId,
|
|
62
|
+
orderId: input.orderId,
|
|
63
|
+
...(deferred ? { deferredConfirmations: true as const } : {}),
|
|
64
|
+
};
|
|
46
65
|
const outcome = await ctx.ports.enqueue.enqueue(MARKETPLACE_CANCELLATION_REASONS_JOB, payload, {
|
|
47
66
|
dedupeKey: `${MARKETPLACE_CANCELLATION_REASONS_JOB}:${input.orderId}`,
|
|
48
67
|
});
|
|
@@ -78,6 +97,28 @@ async function keep(
|
|
|
78
97
|
return { kind: "done", count: reasons.length };
|
|
79
98
|
}
|
|
80
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Apply a confirmation deferred before this order. A failure is logged, never
|
|
102
|
+
* thrown: the reasons read still runs, and the expiry sweep applies it later.
|
|
103
|
+
*/
|
|
104
|
+
async function applyEarlyConfirmations(ctx: EngineContext, clientId: string, row: ReasonsRow): Promise<void> {
|
|
105
|
+
try {
|
|
106
|
+
await applyDeferredConfirmations(ctx, { clientId, provider: row.provider, externalOrderId: row.externalOrderId });
|
|
107
|
+
} catch (error) {
|
|
108
|
+
ctx.ports.logger.warn(`${MARKETPLACE_CANCELLATION_REASONS_JOB}: order ${row.orderId}: a deferred confirmation was not applied; the expiry sweep applies it`, error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The order's acceptance row; for an order not auto-accepted, its early confirmations applied first. */
|
|
113
|
+
async function loadOrder(ctx: EngineContext, db: MarketplaceDb, payload: CancellationReasonsJobPayload): Promise<ReasonsRow | null> {
|
|
114
|
+
const row = (await db.marketplaceAcceptance.findFirst({
|
|
115
|
+
where: { orderId: payload.orderId, clientId: payload.clientId },
|
|
116
|
+
select: { orderId: true, provider: true, externalOrderId: true, cancellationReasons: true },
|
|
117
|
+
})) as ReasonsRow | null;
|
|
118
|
+
if (row && payload.deferredConfirmations) await applyEarlyConfirmations(ctx, payload.clientId, row);
|
|
119
|
+
return row;
|
|
120
|
+
}
|
|
121
|
+
|
|
81
122
|
/** Run one read. Throws {@link CancellationReasonsRetryError} for a retryable answer before the last attempt. */
|
|
82
123
|
export async function runCancellationReasons(
|
|
83
124
|
ctx: EngineContext,
|
|
@@ -85,10 +126,7 @@ export async function runCancellationReasons(
|
|
|
85
126
|
attempt: { attempt: number; maxAttempts: number },
|
|
86
127
|
): Promise<CancellationReasonsOutcome> {
|
|
87
128
|
const db = await ctx.ports.db();
|
|
88
|
-
const row =
|
|
89
|
-
where: { orderId: payload.orderId, clientId: payload.clientId },
|
|
90
|
-
select: { orderId: true, provider: true, externalOrderId: true, cancellationReasons: true },
|
|
91
|
-
})) as ReasonsRow | null;
|
|
129
|
+
const row = await loadOrder(ctx, db, payload);
|
|
92
130
|
if (!row) return { kind: "skipped", reason: "no acceptance for this order" };
|
|
93
131
|
if (storedReasons(row.cancellationReasons) !== null) return { kind: "skipped", reason: "the order's reasons are already kept" };
|
|
94
132
|
const read = ctx.registry.get(row.provider)?.orderCancellationReasons;
|