@12-apps/marketplace 1.18.1 → 1.19.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.
@@ -17,6 +17,32 @@ type MarketplaceLifecycleAnswer = "moved" | "unchanged" | {
17
17
  reason: string;
18
18
  };
19
19
 
20
+ /**
21
+ * Where a menu link really points (FUT-6258). A host whose catalog lets one
22
+ * item be a variation of another can be handed an id that is the variation
23
+ * itself, with no variation named: a link stored that way names neither the
24
+ * item nor the variation the SKU means. The host answers where such an id
25
+ * points, and the engine stores that pair.
26
+ */
27
+ /** A link's stored target: the catalog item, and the variation of it the SKU names. */
28
+ interface MarketplaceLinkTarget {
29
+ menuItemId: string;
30
+ variationId: string;
31
+ }
32
+ /** The order port's optional half for link targets. */
33
+ interface LinkTargetOrderPort {
34
+ /**
35
+ * OPTIONAL. Where a link naming these catalog ids with no variation really
36
+ * points: for each id that is a variation of another item, that item and the
37
+ * variation; an id left out is stored as named. Asked ONCE per write, in
38
+ * bulk, before every menu-link write the engine makes (`upsertMenuLinks`,
39
+ * `setMenuLink`, the publish auto-link); the answer is then checked as any
40
+ * named pair is (`catalogHas`, `catalogHasVariation`). Absent: every link is
41
+ * stored exactly as named.
42
+ */
43
+ resolveLinkTarget?(clientId: string, subjectRefs: readonly string[]): Promise<ReadonlyMap<string, MarketplaceLinkTarget>>;
44
+ }
45
+
20
46
  /**
21
47
  * The order-side vocabulary the host's order port speaks: what a resolved line
22
48
  * is, what the queue shows, what a person stated, and why an order or a
@@ -227,7 +253,7 @@ interface MarketplaceAdmissionRequest {
227
253
  * transition has already been claimed and committed when they are called, and
228
254
  * a host that fails its half must not un-decide the acceptance.
229
255
  */
230
- interface MarketplaceOrderPort extends LogisticsOrderPort {
256
+ interface MarketplaceOrderPort extends LogisticsOrderPort, LinkTargetOrderPort {
231
257
  /**
232
258
  * Judge a decision BEFORE its claim commits, inside the claim's
233
259
  * transaction: the stock check (and the draw) of an accept, anything the
@@ -240,8 +266,7 @@ interface MarketplaceOrderPort extends LogisticsOrderPort {
240
266
  /**
241
267
  * Turn a normalized order into whatever this host sells; hand back its id.
242
268
  * `db` is the ingest's transaction client (the host's `transaction` port):
243
- * write the order through it, so the order and the engine's acceptance row
244
- * commit together or not at all.
269
+ * write the order through it: the order and the engine's acceptance row commit together or not at all.
245
270
  */
246
271
  create(clientId: string, order: NormalizedMarketplaceOrder, lines: readonly ResolvedOrderLine[], db: MarketplaceDb): Promise<string>;
247
272
  /** Does this catalog id exist and belong to this tenant? */
@@ -2086,4 +2111,4 @@ interface MarketplaceEngine extends MarketplaceCourierEngine, MarketplaceConform
2086
2111
  */
2087
2112
  declare function createMarketplaceEngine(config: MarketplaceEngineConfig): MarketplaceEngine;
2088
2113
 
2089
- export { type IngestionTarget as $, type AcceptanceDecision as A, type BulkProblem as B, type CancellationFailureReason as C, type CatalogueStatus as D, type CatalogueTarget as E, type DecideManyResult as F, type DecidedRow as G, type DecisionInput as H, type DecisionProblem as I, type DecisionProblemCode as J, type DecisionResult as K, type DeliveryOutcome as L, type DisputeAnswerInput as M, type DisputeAnswerJobPayload as N, type DisputeAnswerOutcome as O, DisputeAnswerRetryError as P, type DisputeAnswerView as Q, type DisputeRefusalCode as R, type DisputeRow as S, type DisputeStatus as T, type ExpirySweepResult as U, type FetchOrderJobPayload as V, type FetchOrderOutcome as W, FetchOrderRetryError as X, type InformStatusInput as Y, type IngestResult as Z, type IngestSettings as _, type AcceptanceStatus as a, catalogueDedupeKey as a$, type IntegrationRowInput as a0, type LinkFailure as a1, type LinkFinished as a2, type LinkPendingView as a3, type LinkRefusalCode as a4, MARKETPLACE_ACKNOWLEDGE_JOB as a5, MARKETPLACE_AVAILABILITY_JOB as a6, MARKETPLACE_CANCELLATION_REASONS_JOB as a7, MARKETPLACE_CATALOGUE_JOB as a8, MARKETPLACE_DISPUTE_ANSWER_JOB as a9, type MarketplacePorts as aA, type MarketplaceRefusal as aB, type MarketplaceSecretsPort as aC, type MenuLinkRowInput as aD, OUTBOUND_GIVE_UP_MS as aE, OUTBOUND_STALE_MS as aF, type OutboundAction as aG, type OutboundAttempt as aH, type OutboundJobPayload as aI, type OutboundOutcome as aJ, OutboundRetryError as aK, type OutboundSweepResult as aL, type PauseOutcome as aM, type PauseStoreInput as aN, type PauseStoreResult as aO, type PendingAcceptance as aP, type PendingInboxEvent as aQ, type ResolvedOrderLine as aR, type ResumeOutcome as aS, STORE_PAUSE_LEASE_MS as aT, type SaveMarketplaceIntegrationInput as aU, type StoreAvailabilityView as aV, type StorePauseFailureCode as aW, type StorePauseState as aX, type StorePauseWanted as aY, type VerifyDeliveryCodeInput as aZ, availabilityDedupeKey as a_, MARKETPLACE_FETCH_ORDER_JOB as aa, MARKETPLACE_OUTBOUND_JOB as ab, type MarketplaceAdmission as ac, type MarketplaceAdmissionRequest as ad, type MarketplaceAdmissionResult as ae, type MarketplaceAuditEntry as af, type MarketplaceAuditPort as ag, type MarketplaceAuthMode as ah, type MarketplaceCataloguePort as ai, type MarketplaceClockPort as aj, type MarketplaceConformityEngine as ak, type MarketplaceDb as al, type MarketplaceDeliveryCodeEngine as am, type MarketplaceDisputeEngine as an, type MarketplaceDisputeView as ao, type MarketplaceEngine as ap, type MarketplaceEngineConfig as aq, type MarketplaceEnqueuePort as ar, type MarketplaceIntegrationView as as, type MarketplaceLifecycleAnswer as at, type MarketplaceLifecycleFacts as au, type MarketplaceLogger as av, type MarketplaceMenuLinkView as aw, type MarketplaceOrderPort as ax, type MarketplaceOrderState as ay, type MarketplaceOrderSummary as az, type AcknowledgeJobPayload as b, createMarketplaceEngine as b0, disputeView as b1, outboundDedupeKey as b2, type AcknowledgeOutcome as c, AcknowledgeRetryError as d, type AnswerDisputeResult as e, type AvailabilityJobPayload as f, type AvailabilityOutcome as g, AvailabilityRetryError as h, type AvailabilitySweepResult as i, type BulkProblemCode as j, type BulkResult as k, type CancellationReasonsJobPayload as l, type CancellationReasonsOutcome as m, CancellationReasonsRetryError as n, type CancellationStatus as o, type CatalogueAction as p, type CatalogueActionResult as q, type CatalogueDocumentResult as r, type CatalogueFailedAction as s, type CatalogueFailureCode as t, type CatalogueJobPayload as u, type CatalogueOutcome as v, type CataloguePublicationView as w, type CataloguePublishInput as x, type CatalogueRefusalCode as y, CatalogueRetryError as z };
2114
+ export { type IngestionTarget as $, type AcceptanceDecision as A, type BulkProblem as B, type CancellationFailureReason as C, type CatalogueStatus as D, type CatalogueTarget as E, type DecideManyResult as F, type DecidedRow as G, type DecisionInput as H, type DecisionProblem as I, type DecisionProblemCode as J, type DecisionResult as K, type DeliveryOutcome as L, type DisputeAnswerInput as M, type DisputeAnswerJobPayload as N, type DisputeAnswerOutcome as O, DisputeAnswerRetryError as P, type DisputeAnswerView as Q, type DisputeRefusalCode as R, type DisputeRow as S, type DisputeStatus as T, type ExpirySweepResult as U, type FetchOrderJobPayload as V, type FetchOrderOutcome as W, FetchOrderRetryError as X, type InformStatusInput as Y, type IngestResult as Z, type IngestSettings as _, type AcceptanceStatus as a, type VerifyDeliveryCodeInput as a$, type IntegrationRowInput as a0, type LinkFailure as a1, type LinkFinished as a2, type LinkPendingView as a3, type LinkRefusalCode as a4, type LinkTargetOrderPort as a5, MARKETPLACE_ACKNOWLEDGE_JOB as a6, MARKETPLACE_AVAILABILITY_JOB as a7, MARKETPLACE_CANCELLATION_REASONS_JOB as a8, MARKETPLACE_CATALOGUE_JOB as a9, type MarketplaceOrderState as aA, type MarketplaceOrderSummary as aB, type MarketplacePorts as aC, type MarketplaceRefusal as aD, type MarketplaceSecretsPort as aE, type MenuLinkRowInput as aF, OUTBOUND_GIVE_UP_MS as aG, OUTBOUND_STALE_MS as aH, type OutboundAction as aI, type OutboundAttempt as aJ, type OutboundJobPayload as aK, type OutboundOutcome as aL, OutboundRetryError as aM, type OutboundSweepResult as aN, type PauseOutcome as aO, type PauseStoreInput as aP, type PauseStoreResult as aQ, type PendingAcceptance as aR, type PendingInboxEvent as aS, type ResolvedOrderLine as aT, type ResumeOutcome as aU, STORE_PAUSE_LEASE_MS as aV, type SaveMarketplaceIntegrationInput as aW, type StoreAvailabilityView as aX, type StorePauseFailureCode as aY, type StorePauseState as aZ, type StorePauseWanted as a_, MARKETPLACE_DISPUTE_ANSWER_JOB as aa, MARKETPLACE_FETCH_ORDER_JOB as ab, MARKETPLACE_OUTBOUND_JOB as ac, type MarketplaceAdmission as ad, type MarketplaceAdmissionRequest as ae, type MarketplaceAdmissionResult as af, type MarketplaceAuditEntry as ag, type MarketplaceAuditPort as ah, type MarketplaceAuthMode as ai, type MarketplaceCataloguePort as aj, type MarketplaceClockPort as ak, type MarketplaceConformityEngine as al, type MarketplaceDb as am, type MarketplaceDeliveryCodeEngine as an, type MarketplaceDisputeEngine as ao, type MarketplaceDisputeView as ap, type MarketplaceEngine as aq, type MarketplaceEngineConfig as ar, type MarketplaceEnqueuePort as as, type MarketplaceIntegrationView as at, type MarketplaceLifecycleAnswer as au, type MarketplaceLifecycleFacts as av, type MarketplaceLinkTarget as aw, type MarketplaceLogger as ax, type MarketplaceMenuLinkView as ay, type MarketplaceOrderPort as az, type AcknowledgeJobPayload as b, availabilityDedupeKey as b0, catalogueDedupeKey as b1, createMarketplaceEngine as b2, disputeView as b3, outboundDedupeKey as b4, type AcknowledgeOutcome as c, AcknowledgeRetryError as d, type AnswerDisputeResult as e, type AvailabilityJobPayload as f, type AvailabilityOutcome as g, AvailabilityRetryError as h, type AvailabilitySweepResult as i, type BulkProblemCode as j, type BulkResult as k, type CancellationReasonsJobPayload as l, type CancellationReasonsOutcome as m, CancellationReasonsRetryError as n, type CancellationStatus as o, type CatalogueAction as p, type CatalogueActionResult as q, type CatalogueDocumentResult as r, type CatalogueFailedAction as s, type CatalogueFailureCode as t, type CatalogueJobPayload as u, type CatalogueOutcome as v, type CataloguePublicationView as w, type CataloguePublishInput as x, type CatalogueRefusalCode as y, CatalogueRetryError as z };
@@ -1,6 +1,6 @@
1
1
  import { Hono, Context } from 'hono';
2
2
  import { ApiMarketplace, MarketplaceApiConfig, MarketplaceActor } from '../server/index.js';
3
- import '../engine-DRRhAjZK.js';
3
+ import '../engine-CaiVufoP.js';
4
4
  import '../adapter-ZpAWKoCk.js';
5
5
  import '@12-apps/wiring';
6
6
  import 'zod';
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createApiMarketplace
3
- } from "../chunk-BLHZ3MRB.js";
3
+ } from "../chunk-RS2QKQ6S.js";
4
4
  import "../chunk-LO7OKO6V.js";
5
- import "../chunk-MDEIRGNL.js";
5
+ import "../chunk-S2ISELNJ.js";
6
6
  import "../chunk-Q5RMVNU5.js";
7
7
  import {
8
8
  __name
@@ -51,14 +51,17 @@ function defaultCatalogIdIn(body) {
51
51
  return null;
52
52
  }
53
53
  if (!Array.isArray(parsed2)) return null;
54
- for (const entry of parsed2) {
55
- if (typeof entry !== "object" || entry === null) continue;
56
- const { catalogId, context } = entry;
57
- if (typeof catalogId === "string" && catalogId !== "" && Array.isArray(context) && context.includes("DEFAULT")) return catalogId;
58
- }
59
- return null;
54
+ const defaults = parsed2.map(defaultEntryOf).filter((entry) => entry !== null);
55
+ return (defaults.find((entry) => entry.available) ?? defaults[0])?.catalogId ?? null;
60
56
  }
61
57
  __name(defaultCatalogIdIn, "defaultCatalogIdIn");
58
+ function defaultEntryOf(entry) {
59
+ if (typeof entry !== "object" || entry === null) return null;
60
+ const { catalogId, context, status } = entry;
61
+ if (typeof catalogId !== "string" || catalogId === "" || !Array.isArray(context) || !context.includes("DEFAULT")) return null;
62
+ return { catalogId, available: status === "AVAILABLE" };
63
+ }
64
+ __name(defaultEntryOf, "defaultEntryOf");
62
65
  var categoriesPath = /* @__PURE__ */ __name((catalogId) => `catalogs/${encodeURIComponent(catalogId)}/categories`, "categoriesPath");
63
66
 
64
67
  // src/ifood/outbound.ts
@@ -274,27 +277,25 @@ async function findCategoryIn(ctx, catalogId, name) {
274
277
  return { id: categoryIdIn(listed.body, name) };
275
278
  }
276
279
  __name(findCategoryIn, "findCategoryIn");
277
- async function findCategory(ctx, name) {
278
- const catalog = await catalogOf(ctx);
279
- return "kind" in catalog ? catalog : findCategoryIn(ctx, catalog.catalogId, name);
280
- }
281
- __name(findCategory, "findCategory");
282
- async function findOrCreateCategory(ctx, name) {
283
- const catalog = await catalogOf(ctx);
280
+ async function findOrCreateCategory(ctx, name, catalogId) {
281
+ const catalog = catalogId === void 0 ? await catalogOf(ctx) : { catalogId };
284
282
  if ("kind" in catalog) return catalog;
285
283
  const found = await findCategoryIn(ctx, catalog.catalogId, name);
286
284
  if ("kind" in found) return found;
287
- if (found.id) return { id: found.id };
288
- const created = await call(ctx, "POST", categoriesPath(catalog.catalogId), { name, status: "AVAILABLE", template: "DEFAULT" });
285
+ return found.id ? { id: found.id } : createCategoryIn(ctx, catalog.catalogId, name);
286
+ }
287
+ __name(findOrCreateCategory, "findOrCreateCategory");
288
+ async function createCategoryIn(ctx, catalogId, name) {
289
+ const created = await call(ctx, "POST", categoriesPath(catalogId), { name, status: "AVAILABLE", template: "DEFAULT" });
289
290
  if ("kind" in created) return created;
290
291
  if (!ok(created)) return failureOf(created);
291
292
  const id = parse(created.body)?.id;
292
293
  if (typeof id !== "string") return { kind: "retry", reason: "iFood created the category without an id" };
293
- const again = await findCategoryIn(ctx, catalog.catalogId, name);
294
+ const again = await findCategoryIn(ctx, catalogId, name);
294
295
  return "id" in again && again.id ? { id: again.id } : { id };
295
296
  }
296
- __name(findOrCreateCategory, "findOrCreateCategory");
297
- var categoryId = /* @__PURE__ */ __name((ctx, name) => ctx.category(name, () => findOrCreateCategory(ctx, name)), "categoryId");
297
+ __name(createCategoryIn, "createCategoryIn");
298
+ var categoryId = /* @__PURE__ */ __name((ctx, name, catalogId) => ctx.category(name, () => findOrCreateCategory(ctx, name, catalogId)), "categoryId");
298
299
  async function photoFor(ctx, item) {
299
300
  const stored = item.storedImage;
300
301
  if (item.imageUrl === null) return { image: null };
@@ -347,18 +348,22 @@ function ifoodItemBody(item, category, image) {
347
348
  }
348
349
  __name(ifoodItemBody, "ifoodItemBody");
349
350
  async function categoryWentStale(ctx, put, name, used) {
350
- if (put.status !== 400 && put.status !== 404) return false;
351
- const found = await findCategory(ctx, name);
352
- return !("kind" in found) && found.id !== used;
351
+ if (put.status !== 400 && put.status !== 404) return null;
352
+ const catalog = await catalogOf(ctx);
353
+ if ("kind" in catalog) return null;
354
+ const found = await findCategoryIn(ctx, catalog.catalogId, name);
355
+ return !("kind" in found) && found.id !== used ? catalog : null;
353
356
  }
354
357
  __name(categoryWentStale, "categoryWentStale");
355
358
  async function putItem(ctx, item, image) {
356
359
  const category = await categoryId(ctx, item.categoryName);
357
360
  if ("kind" in category) return category;
358
361
  const put = await call(ctx, "PUT", "items", ifoodItemBody(item, category.id, image));
359
- if ("kind" in put || ok(put) || !await categoryWentStale(ctx, put, item.categoryName, category.id)) return put;
362
+ if ("kind" in put || ok(put)) return put;
363
+ const stale = await categoryWentStale(ctx, put, item.categoryName, category.id);
364
+ if (stale === null) return put;
360
365
  await ctx.forgetCategory(item.categoryName);
361
- const again = await categoryId(ctx, item.categoryName);
366
+ const again = await categoryId(ctx, item.categoryName, stale.catalogId);
362
367
  if ("kind" in again) return again;
363
368
  return call(ctx, "PUT", "items", ifoodItemBody(item, again.id, image));
364
369
  }