@12-apps/marketplace 1.5.0 → 1.6.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.
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createApiMarketplace
3
- } from "../chunk-UONWZIBO.js";
3
+ } from "../chunk-4CJ7B5OR.js";
4
4
  import "../chunk-UYFYGGCS.js";
5
- import "../chunk-FKUEFVVA.js";
5
+ import "../chunk-NFZT5TWR.js";
6
6
  import {
7
7
  __name
8
8
  } from "../chunk-7QVYU63E.js";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AcceptanceDecision, a as AcceptanceStatus, b as AvailabilityJobPayload, c as AvailabilityOutcome, d as AvailabilityRetryError, e as AvailabilitySweepResult, B as BulkProblem, f as BulkProblemCode, g as BulkResult, C as CancellationFailureReason, h as CancellationStatus, i as CatalogueAction, j as CatalogueActionResult, k as CatalogueDocumentResult, l as CatalogueFailedAction, m as CatalogueFailureCode, n as CatalogueJobPayload, o as CatalogueOutcome, p as CataloguePublicationView, q as CataloguePublishInput, r as CatalogueRefusalCode, s as CatalogueRetryError, t as CatalogueStatus, u as CatalogueTarget, D as DecideManyResult, v as DecidedRow, w as DecisionInput, x as DecisionProblem, y as DecisionProblemCode, z as DecisionResult, E as DeliveryOutcome, F as ExpirySweepResult, G as FetchOrderJobPayload, H as FetchOrderOutcome, I as FetchOrderRetryError, J as IngestResult, K as IngestSettings, L as IngestionTarget, M as IntegrationRowInput, N as MARKETPLACE_AVAILABILITY_JOB, O as MARKETPLACE_CATALOGUE_JOB, P as MARKETPLACE_FETCH_ORDER_JOB, Q as MARKETPLACE_OUTBOUND_JOB, R as MarketplaceAdmission, S as MarketplaceAdmissionRequest, T as MarketplaceAdmissionResult, U as MarketplaceAuditEntry, V as MarketplaceAuditPort, W as MarketplaceCataloguePort, X as MarketplaceClockPort, Y as MarketplaceDb, Z as MarketplaceEngine, _ as MarketplaceEngineConfig, $ as MarketplaceEnqueuePort, a0 as MarketplaceIntegrationView, a1 as MarketplaceLogger, a2 as MarketplaceMenuLinkView, a3 as MarketplaceOrderPort, a4 as MarketplaceOrderState, a5 as MarketplaceOrderSummary, a6 as MarketplacePorts, a7 as MarketplaceRefusal, a8 as MarketplaceSecretsPort, a9 as MenuLinkRowInput, aa as OUTBOUND_GIVE_UP_MS, ab as OUTBOUND_STALE_MS, ac as OutboundAction, ad as OutboundAttempt, ae as OutboundJobPayload, af as OutboundOutcome, ag as OutboundRetryError, ah as OutboundSweepResult, ai as PauseOutcome, aj as PauseStoreInput, ak as PauseStoreResult, al as PendingAcceptance, am as PendingInboxEvent, an as ResolvedOrderLine, ao as ResumeOutcome, ap as STORE_PAUSE_LEASE_MS, aq as SaveMarketplaceIntegrationInput, ar as StoreAvailabilityView, as as StorePauseFailureCode, at as StorePauseState, au as StorePauseWanted, av as availabilityDedupeKey, aw as catalogueDedupeKey, ax as createMarketplaceEngine, ay as outboundDedupeKey } from './engine-C3uq_BJd.js';
1
+ export { A as AcceptanceDecision, a as AcceptanceStatus, b as AvailabilityJobPayload, c as AvailabilityOutcome, d as AvailabilityRetryError, e as AvailabilitySweepResult, B as BulkProblem, f as BulkProblemCode, g as BulkResult, C as CancellationFailureReason, h as CancellationStatus, i as CatalogueAction, j as CatalogueActionResult, k as CatalogueDocumentResult, l as CatalogueFailedAction, m as CatalogueFailureCode, n as CatalogueJobPayload, o as CatalogueOutcome, p as CataloguePublicationView, q as CataloguePublishInput, r as CatalogueRefusalCode, s as CatalogueRetryError, t as CatalogueStatus, u as CatalogueTarget, D as DecideManyResult, v as DecidedRow, w as DecisionInput, x as DecisionProblem, y as DecisionProblemCode, z as DecisionResult, E as DeliveryOutcome, F as ExpirySweepResult, G as FetchOrderJobPayload, H as FetchOrderOutcome, I as FetchOrderRetryError, J as IngestResult, K as IngestSettings, L as IngestionTarget, M as IntegrationRowInput, N as MARKETPLACE_AVAILABILITY_JOB, O as MARKETPLACE_CATALOGUE_JOB, P as MARKETPLACE_FETCH_ORDER_JOB, Q as MARKETPLACE_OUTBOUND_JOB, R as MarketplaceAdmission, S as MarketplaceAdmissionRequest, T as MarketplaceAdmissionResult, U as MarketplaceAuditEntry, V as MarketplaceAuditPort, W as MarketplaceCataloguePort, X as MarketplaceClockPort, Y as MarketplaceDb, Z as MarketplaceEngine, _ as MarketplaceEngineConfig, $ as MarketplaceEnqueuePort, a0 as MarketplaceIntegrationView, a1 as MarketplaceLogger, a2 as MarketplaceMenuLinkView, a3 as MarketplaceOrderPort, a4 as MarketplaceOrderState, a5 as MarketplaceOrderSummary, a6 as MarketplacePorts, a7 as MarketplaceRefusal, a8 as MarketplaceSecretsPort, a9 as MenuLinkRowInput, aa as OUTBOUND_GIVE_UP_MS, ab as OUTBOUND_STALE_MS, ac as OutboundAction, ad as OutboundAttempt, ae as OutboundJobPayload, af as OutboundOutcome, ag as OutboundRetryError, ah as OutboundSweepResult, ai as PauseOutcome, aj as PauseStoreInput, ak as PauseStoreResult, al as PendingAcceptance, am as PendingInboxEvent, an as ResolvedOrderLine, ao as ResumeOutcome, ap as STORE_PAUSE_LEASE_MS, aq as SaveMarketplaceIntegrationInput, ar as StoreAvailabilityView, as as StorePauseFailureCode, at as StorePauseState, au as StorePauseWanted, av as availabilityDedupeKey, aw as catalogueDedupeKey, ax as createMarketplaceEngine, ay as outboundDedupeKey } from './engine-w2TgRrlc.js';
2
2
  import { c as MarketplaceAdapter, i as MarketplaceProvider, j as CancellationReason } from './adapter-CCWMqt2g.js';
3
3
  export { A as AdapterCallContext, k as AdapterTokenCache, l as CancellationOutcome, m as CancellationRequestInput, n as CatalogueCallContext, o as CatalogueFailure, p as CatalogueImage, q as CatalogueItem, e as CatalogueItemOut, r as CatalogueItemRef, C as CatalogueMenuEntry, b as CatalogueMenuOptions, s as CataloguePublishResult, t as CatalogueReadContext, u as CatalogueReadNotice, v as CatalogueReadRefusalCode, w as CatalogueReadResult, x as CatalogueReadWarning, y as CatalogueReadWarningCode, f as CatalogueReader, z as CatalogueSnapshot, B as CatalogueSnapshotCategory, D as CatalogueSnapshotItem, E as CatalogueSnapshotOption, F as CatalogueSnapshotOptionGroup, G as CatalogueStoredImage, H as CatalogueWarningCode, I as FetchOrderResult, M as MarketplaceAvailability, J as MarketplaceCapabilities, K as MarketplaceCatalogue, L as MarketplaceCredentials, Q as MarketplaceDeliveredBy, R as MarketplaceHttp, T as MarketplaceHttpRequest, U as MarketplaceHttpResponse, V as MarketplaceOrderType, W as NormalizedAddress, X as NormalizedBuyer, N as NormalizedEvent, a as NormalizedMarketplaceOrder, Y as NormalizedOrderLine, Z as OutboundOrderRef, O as OutboundResult, _ as PROVIDER_ID_PATTERN, P as PullCatalogue, d as PushCatalogue, h as StorePauseRef, S as StorePauseRequest, g as StorePauseResult, $ as answered, a0 as centsFromMajor, a1 as outboundResultOf } from './adapter-CCWMqt2g.js';
4
4
 
package/dist/index.js CHANGED
@@ -66,7 +66,7 @@ import {
66
66
  tellCancellationFailed,
67
67
  upsertLink,
68
68
  viewOf
69
- } from "./chunk-FKUEFVVA.js";
69
+ } from "./chunk-NFZT5TWR.js";
70
70
  import {
71
71
  centsFromMajor
72
72
  } from "./chunk-WN2EK4KX.js";
@@ -1,4 +1,4 @@
1
- import { ae as OutboundJobPayload, G as FetchOrderJobPayload, n as CatalogueJobPayload, b as AvailabilityJobPayload } from '../engine-C3uq_BJd.js';
1
+ import { ae as OutboundJobPayload, G as FetchOrderJobPayload, n as CatalogueJobPayload, b as AvailabilityJobPayload } from '../engine-w2TgRrlc.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-CCWMqt2g.js';
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  MARKETPLACE_JOBS,
3
3
  createApiMarketplace
4
- } from "../chunk-UONWZIBO.js";
4
+ } from "../chunk-4CJ7B5OR.js";
5
5
  import "../chunk-UYFYGGCS.js";
6
- import "../chunk-FKUEFVVA.js";
6
+ import "../chunk-NFZT5TWR.js";
7
7
  import "../chunk-7QVYU63E.js";
8
8
 
9
9
  // src/manifest/server.ts
@@ -1,4 +1,4 @@
1
- import { y as DecisionProblemCode, f as BulkProblemCode, Z as MarketplaceEngine, a1 as MarketplaceLogger, ae as OutboundJobPayload, G as FetchOrderJobPayload, n as CatalogueJobPayload, b as AvailabilityJobPayload } from '../engine-C3uq_BJd.js';
1
+ import { y as DecisionProblemCode, f as BulkProblemCode, Z as MarketplaceEngine, a1 as MarketplaceLogger, ae as OutboundJobPayload, G as FetchOrderJobPayload, n as CatalogueJobPayload, b as AvailabilityJobPayload } from '../engine-w2TgRrlc.js';
2
2
  import { WireRoute, WireJobBlueprint } from '@12-apps/wiring';
3
3
  import { z } from 'zod';
4
4
  import '../adapter-CCWMqt2g.js';
@@ -6,7 +6,7 @@ import {
6
6
  MARKETPLACE_SWEEP_QUEUE,
7
7
  ORDER_NOT_PENDING_CODE,
8
8
  createApiMarketplace
9
- } from "../chunk-UONWZIBO.js";
9
+ } from "../chunk-4CJ7B5OR.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-UYFYGGCS.js";
23
- import "../chunk-FKUEFVVA.js";
23
+ import "../chunk-NFZT5TWR.js";
24
24
  import "../chunk-7QVYU63E.js";
25
25
  export {
26
26
  MARKETPLACE_AVAILABILITY_ATTEMPTS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@12-apps/marketplace",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
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 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.",
@@ -30,7 +30,10 @@ export interface IngestResult {
30
30
  created: boolean;
31
31
  /** SKUs that arrived with nothing behind them, in this order. */
32
32
  unmappedSkus: string[];
33
- /** Whether the connection's policy made this order born accepted. */
33
+ /**
34
+ * Whether this order was born accepted: the connection auto-accepts AND the
35
+ * host's `mayAutoAccept`, when bound, allowed it.
36
+ */
34
37
  autoAccepted: boolean;
35
38
  }
36
39
 
@@ -79,10 +82,10 @@ function acceptanceData(
79
82
  orderId: string,
80
83
  order: NormalizedMarketplaceOrder,
81
84
  settings: IngestSettings,
85
+ accepted: boolean,
82
86
  now: Date,
83
87
  clockStartsAt: Date,
84
88
  ): Record<string, unknown> {
85
- const accepted = settings.autoAccept;
86
89
  return {
87
90
  clientId,
88
91
  orderId,
@@ -101,6 +104,31 @@ function acceptanceData(
101
104
  };
102
105
  }
103
106
 
107
+ /**
108
+ * The host's say on an automatic acceptance (`order.mayAutoAccept`), asked
109
+ * only when the connection auto-accepts. Absent, it allows. A declined
110
+ * auto-accept is never a refused order: the order lands on the clock and a
111
+ * person decides it — so a host half that throws declines rather than failing
112
+ * the ingest, which would hold a paid order back until the sweep.
113
+ */
114
+ async function hostAllowsAutoAccept(
115
+ ctx: EngineContext,
116
+ clientId: string,
117
+ order: NormalizedMarketplaceOrder,
118
+ ): Promise<boolean> {
119
+ const ask = ctx.ports.order.mayAutoAccept;
120
+ if (!ask) return true;
121
+ try {
122
+ return await ask.call(ctx.ports.order, clientId);
123
+ } catch (error) {
124
+ ctx.ports.logger.warn(
125
+ `marketplace: mayAutoAccept threw for ${order.provider} order ${order.externalOrderId}; it lands awaiting a decision`,
126
+ error,
127
+ );
128
+ return false;
129
+ }
130
+ }
131
+
104
132
  /**
105
133
  * Ingest one order.
106
134
  *
@@ -147,7 +175,7 @@ export async function ingestMarketplaceOrder(
147
175
  return { orderId: existing.orderId, created: false, unmappedSkus: [], autoAccepted: false };
148
176
  }
149
177
 
150
- const accepted = settings.autoAccept;
178
+ const accepted = settings.autoAccept && (await hostAllowsAutoAccept(ctx, clientId, order));
151
179
  // ONE transaction for the host's order, the SKU rows, the acceptance row and
152
180
  // the liveness stamp: the host's `create` is handed the transaction's client,
153
181
  // so an acceptance that cannot be written (a concurrent ingest won the
@@ -156,7 +184,7 @@ export async function ingestMarketplaceOrder(
156
184
  const { orderId, unmappedSkus } = await ctx.ports.transaction(async (tx) => {
157
185
  const lines = await composeLines(tx, clientId, order, now);
158
186
  const created = await ctx.ports.order.create(clientId, order, lines, tx);
159
- await tx.marketplaceAcceptance.create({ data: acceptanceData(clientId, created, order, settings, now, clockStartsAt) });
187
+ await tx.marketplaceAcceptance.create({ data: acceptanceData(clientId, created, order, settings, accepted, now, clockStartsAt) });
160
188
  await markMarketplaceEventSeen(tx, clientId, order.provider, now);
161
189
  return { orderId: created, unmappedSkus: lines.filter((l) => l.subjectRef === null).map((l) => l.externalSku) };
162
190
  });
package/src/core/ports.ts CHANGED
@@ -185,6 +185,17 @@ export interface MarketplaceOrderPort {
185
185
  catalogHas(clientId: string, subjectRef: string): Promise<boolean>;
186
186
  /** The store said yes, or the connection auto-accepts. */
187
187
  onAccepted(clientId: string, orderId: string): Promise<void>;
188
+ /**
189
+ * OPTIONAL. May an arriving order of this tenant be accepted automatically?
190
+ * Asked once per NEW order of a connection with auto-accept on, before the
191
+ * ingest's transaction (never for a redelivery, never with auto-accept off).
192
+ * `false` declines the automatic acceptance: the order lands exactly as it
193
+ * would with auto-accept off — AWAITING on the clock, no confirm queued, no
194
+ * `onAccepted` — and a person decides it. The order itself is never refused.
195
+ * A throw is logged and declines too. Absent: every auto-accept proceeds.
196
+ * Answer it cheaply: it sits on the ingest path of every order.
197
+ */
198
+ mayAutoAccept?(clientId: string): Promise<boolean>;
188
199
  /** The store said no, the marketplace cancelled, or the clock lapsed. */
189
200
  onRefused(clientId: string, orderId: string, reason: MarketplaceRefusal): Promise<void>;
190
201
  /**