@modainteract/moda-interact-shared 5.9.0 → 5.11.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,7 +1,7 @@
1
1
  import * as zod from 'zod';
2
2
  import { z } from 'zod';
3
3
  import { ModaSupportedLanguageTag, IcuMessageCatalogue, InternationalizationRuntime } from '../../internationalization.js';
4
- import { Y as CommerceShippingInformation, d as CommerceFinalResponse } from '../../response-DD6HXT8s.js';
4
+ import { _ as CommerceShippingInformation, d as CommerceFinalResponse } from '../../response-gHpvLkzy.js';
5
5
  import 'intl-messageformat';
6
6
 
7
7
  declare const CommerceVerifiedPresentationSchema: z.ZodObject<{
@@ -62,6 +62,19 @@ declare const CommerceVerifiedPresentationSchema: z.ZodObject<{
62
62
  }, z.core.$strict>>>;
63
63
  }, z.core.$strict>>;
64
64
  productFacts: z.ZodDefault<z.ZodArray<z.ZodObject<{
65
+ stock: z.ZodDiscriminatedUnion<[z.ZodObject<{
66
+ status: z.ZodLiteral<"KNOWN">;
67
+ quantity: z.ZodNumber;
68
+ scope: z.ZodEnum<{
69
+ PRODUCT: "PRODUCT";
70
+ VARIANT: "VARIANT";
71
+ }>;
72
+ }, z.core.$strict>, z.ZodObject<{
73
+ status: z.ZodLiteral<"NOT_TRACKED">;
74
+ }, z.core.$strict>, z.ZodObject<{
75
+ status: z.ZodLiteral<"UNAVAILABLE">;
76
+ }, z.core.$strict>], "status">;
77
+ observedAt: z.ZodISODateTime;
65
78
  productId: z.ZodString;
66
79
  variantId: z.ZodNullable<z.ZodString>;
67
80
  title: z.ZodString;
@@ -363,6 +376,19 @@ type CommerceWhatsAppPreviewResult = {
363
376
  declare function composeCommerceWhatsAppPreview(input: CommerceWhatsAppPreviewInput): CommerceWhatsAppPreviewResult;
364
377
 
365
378
  declare const CommerceProductFactSchema: z.ZodObject<{
379
+ stock: z.ZodDiscriminatedUnion<[z.ZodObject<{
380
+ status: z.ZodLiteral<"KNOWN">;
381
+ quantity: z.ZodNumber;
382
+ scope: z.ZodEnum<{
383
+ PRODUCT: "PRODUCT";
384
+ VARIANT: "VARIANT";
385
+ }>;
386
+ }, z.core.$strict>, z.ZodObject<{
387
+ status: z.ZodLiteral<"NOT_TRACKED">;
388
+ }, z.core.$strict>, z.ZodObject<{
389
+ status: z.ZodLiteral<"UNAVAILABLE">;
390
+ }, z.core.$strict>], "status">;
391
+ observedAt: z.ZodISODateTime;
366
392
  productId: z.ZodString;
367
393
  variantId: z.ZodNullable<z.ZodString>;
368
394
  title: z.ZodString;
@@ -416,5 +442,7 @@ declare function verifyCommerceProductFacts(selection: readonly {
416
442
  declare function renderCommerceProductFacts(facts: readonly CommerceProductFact[], locale: ModaSupportedLanguageTag): string;
417
443
 
418
444
  declare const productFactMessages: Readonly<Record<"tr" | "zh-Hans" | "zh-Hant" | "cs" | "da" | "nl" | "en" | "fi" | "fr" | "de" | "it" | "ja" | "ko" | "nb" | "pl" | "pt-BR" | "pt-PT" | "es" | "sv" | "th", readonly [string, string, string]>>;
445
+ /** Aggregate sellable counts for the exact selected identity, never a fulfillment promise. */
446
+ declare const stockFactMessages: Readonly<Record<ModaSupportedLanguageTag, readonly [string, string, string, string]>>;
419
447
 
420
- export { type CommerceOptionFact, CommerceOptionFactSchema, type CommerceProductFact, CommerceProductFactSchema, type CommerceVerifiedPresentation, CommerceVerifiedPresentationSchema, type CommerceWhatsAppPreviewInput, type CommerceWhatsAppPreviewResult, MAX_WHATSAPP_TEXT_LENGTH, type PreparedToken, type PreparedWrapper, type PresentationDigest, type RenderRecommendationProduct, type ShippingPresentation, type VerifiedWrapperContext, type WrapperAudience, type WrapperDefinition, type WrapperRefusal, type WrapperSlot, type WrapperSource, type WrapperVariable, buildReplyCandidates, canonicalTag, chooseSlot, composeCommerceWhatsAppPreview, currencyExponent, decimalToMinorUnits, digest, formatObservedMoney, isValidDecimal, languageChoices, minorUnitsToDecimal, normalizeCommerceReplyText, productFactMessages, productOptionMessages, readPreparedWrapper, recommendationMessage, recommendationMessageKeys, recommendationMessages, renderCommerceProductFacts, renderPreparedWrapper, renderProductOptionFacts, renderRecommendationReply, selectShippingPresentation, stableJson, sumPurchaseSubtotal, validDefinition, verifyCommerceOptionFacts, verifyCommerceProductFacts };
448
+ export { type CommerceOptionFact, CommerceOptionFactSchema, type CommerceProductFact, CommerceProductFactSchema, type CommerceVerifiedPresentation, CommerceVerifiedPresentationSchema, type CommerceWhatsAppPreviewInput, type CommerceWhatsAppPreviewResult, MAX_WHATSAPP_TEXT_LENGTH, type PreparedToken, type PreparedWrapper, type PresentationDigest, type RenderRecommendationProduct, type ShippingPresentation, type VerifiedWrapperContext, type WrapperAudience, type WrapperDefinition, type WrapperRefusal, type WrapperSlot, type WrapperSource, type WrapperVariable, buildReplyCandidates, canonicalTag, chooseSlot, composeCommerceWhatsAppPreview, currencyExponent, decimalToMinorUnits, digest, formatObservedMoney, isValidDecimal, languageChoices, minorUnitsToDecimal, normalizeCommerceReplyText, productFactMessages, productOptionMessages, readPreparedWrapper, recommendationMessage, recommendationMessageKeys, recommendationMessages, renderCommerceProductFacts, renderPreparedWrapper, renderProductOptionFacts, renderRecommendationReply, selectShippingPresentation, stableJson, stockFactMessages, sumPurchaseSubtotal, validDefinition, verifyCommerceOptionFacts, verifyCommerceProductFacts };
@@ -4,9 +4,12 @@ import {
4
4
  CommerceProductDescriptionSchema,
5
5
  CommerceProductOptionsSchema,
6
6
  CommerceProductSchema,
7
- CommerceProductSelectedOptionsSchema
8
- } from "../../chunk-SW2AFMT7.js";
9
- import "../../chunk-GCCT2BDE.js";
7
+ CommerceProductSelectedOptionsSchema,
8
+ CommerceProductStockSchema
9
+ } from "../../chunk-GADJQUWU.js";
10
+ import {
11
+ DateSchema
12
+ } from "../../chunk-GCCT2BDE.js";
10
13
  import {
11
14
  MODA_SUPPORTED_LANGUAGE_TAGS,
12
15
  ModaSupportedLanguageTagSchema,
@@ -44,9 +47,31 @@ var labels = {
44
47
  tr: ["\xDCr\xFCn ayr\u0131nt\u0131lar\u0131 mevcut de\u011Fil.", "\xDCr\xFCn bilgileri eksik.", "Se\xE7ilen se\xE7enekler"]
45
48
  };
46
49
  var productFactMessages = Object.freeze(labels);
50
+ var stockFactMessages = Object.freeze({
51
+ en: ["Stock (product)", "Stock (selected variant)", "Stock is not tracked.", "Stock is unavailable."],
52
+ "zh-Hans": ["\u5E93\u5B58\uFF08\u5546\u54C1\uFF09", "\u5E93\u5B58\uFF08\u6240\u9009\u6B3E\u5F0F\uFF09", "\u672A\u8DDF\u8E2A\u5E93\u5B58\u3002", "\u5E93\u5B58\u4FE1\u606F\u4E0D\u53EF\u7528\u3002"],
53
+ "zh-Hant": ["\u5EAB\u5B58\uFF08\u5546\u54C1\uFF09", "\u5EAB\u5B58\uFF08\u6240\u9078\u6B3E\u5F0F\uFF09", "\u672A\u8FFD\u8E64\u5EAB\u5B58\u3002", "\u5EAB\u5B58\u8CC7\u8A0A\u7121\u6CD5\u53D6\u5F97\u3002"],
54
+ cs: ["Z\xE1soby (produkt)", "Z\xE1soby (vybran\xE1 varianta)", "Z\xE1soby nejsou sledov\xE1ny.", "Z\xE1soby nejsou dostupn\xE9."],
55
+ da: ["Lager (produkt)", "Lager (valgt variant)", "Lager spores ikke.", "Lageroplysninger er ikke tilg\xE6ngelige."],
56
+ nl: ["Voorraad (product)", "Voorraad (geselecteerde variant)", "Voorraad wordt niet bijgehouden.", "Voorraad is niet beschikbaar."],
57
+ fi: ["Varasto (tuote)", "Varasto (valittu vaihtoehto)", "Varastoa ei seurata.", "Varastotietoja ei ole saatavilla."],
58
+ fr: ["Stock (produit)", "Stock (variante s\xE9lectionn\xE9e)", "Le stock n\u2019est pas suivi.", "Le stock est indisponible."],
59
+ de: ["Bestand (Produkt)", "Bestand (ausgew\xE4hlte Variante)", "Der Bestand wird nicht verfolgt.", "Der Bestand ist nicht verf\xFCgbar."],
60
+ it: ["Scorte (prodotto)", "Scorte (variante selezionata)", "Le scorte non sono monitorate.", "Le scorte non sono disponibili."],
61
+ ja: ["\u5728\u5EAB\uFF08\u5546\u54C1\uFF09", "\u5728\u5EAB\uFF08\u9078\u629E\u3057\u305F\u30D0\u30EA\u30A8\u30FC\u30B7\u30E7\u30F3\uFF09", "\u5728\u5EAB\u306F\u8FFD\u8DE1\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002", "\u5728\u5EAB\u60C5\u5831\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3002"],
62
+ ko: ["\uC7AC\uACE0 (\uC81C\uD488)", "\uC7AC\uACE0 (\uC120\uD0DD\uD55C \uC635\uC158)", "\uC7AC\uACE0\uB97C \uCD94\uC801\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.", "\uC7AC\uACE0 \uC815\uBCF4\uB97C \uD655\uC778\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."],
63
+ nb: ["Lager (produkt)", "Lager (valgt variant)", "Lager spores ikke.", "Lagerinformasjon er ikke tilgjengelig."],
64
+ pl: ["Stan magazynowy (produkt)", "Stan magazynowy (wybrany wariant)", "Stan magazynowy nie jest \u015Bledzony.", "Stan magazynowy jest niedost\u0119pny."],
65
+ "pt-BR": ["Estoque (produto)", "Estoque (variante selecionada)", "O estoque n\xE3o \xE9 acompanhado.", "O estoque est\xE1 indispon\xEDvel."],
66
+ "pt-PT": ["Stock (produto)", "Stock (variante selecionada)", "O stock n\xE3o \xE9 acompanhado.", "O stock est\xE1 indispon\xEDvel."],
67
+ es: ["Existencias (producto)", "Existencias (variante seleccionada)", "No se realiza seguimiento de existencias.", "Las existencias no est\xE1n disponibles."],
68
+ sv: ["Lager (produkt)", "Lager (vald variant)", "Lager sp\xE5ras inte.", "Lagerinformation \xE4r inte tillg\xE4nglig."],
69
+ th: ["\u0E2A\u0E15\u0E47\u0E2D\u0E01 (\u0E2A\u0E34\u0E19\u0E04\u0E49\u0E32)", "\u0E2A\u0E15\u0E47\u0E2D\u0E01 (\u0E15\u0E31\u0E27\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E17\u0E35\u0E48\u0E40\u0E25\u0E37\u0E2D\u0E01)", "\u0E44\u0E21\u0E48\u0E21\u0E35\u0E01\u0E32\u0E23\u0E15\u0E34\u0E14\u0E15\u0E32\u0E21\u0E2A\u0E15\u0E47\u0E2D\u0E01", "\u0E44\u0E21\u0E48\u0E21\u0E35\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E2A\u0E15\u0E47\u0E2D\u0E01"],
70
+ tr: ["Stok (\xFCr\xFCn)", "Stok (se\xE7ilen varyant)", "Stok takip edilmiyor.", "Stok bilgisi mevcut de\u011Fil."]
71
+ });
47
72
 
48
73
  // src/commerce/presentation/facts.ts
49
- var CommerceProductFactSchema = z.strictObject({ productId: z.string().min(1).max(128), variantId: z.string().min(1).max(128).nullable(), title: z.string().min(1).max(512), description: CommerceProductDescriptionSchema, attributes: CommerceProductAttributesSchema, options: CommerceProductOptionsSchema, selectedOptions: CommerceProductSelectedOptionsSchema });
74
+ var CommerceProductFactSchema = z.strictObject({ stock: CommerceProductStockSchema, observedAt: DateSchema, productId: z.string().min(1).max(128), variantId: z.string().min(1).max(128).nullable(), title: z.string().min(1).max(512), description: CommerceProductDescriptionSchema, attributes: CommerceProductAttributesSchema, options: CommerceProductOptionsSchema, selectedOptions: CommerceProductSelectedOptionsSchema });
50
75
  function verifyCommerceProductFacts(selection, currentProducts) {
51
76
  const parsed = z.array(z.strictObject({ productId: z.string().min(1).max(128), variantId: z.string().min(1).max(128).nullable() })).max(3).safeParse(selection);
52
77
  if (!parsed.success || new Set(selection.map((s) => JSON.stringify([s.productId, s.variantId]))).size !== selection.length) return { kind: "limitation", reason: "INVALID_SELECTION" };
@@ -56,7 +81,7 @@ function verifyCommerceProductFacts(selection, currentProducts) {
56
81
  if (matches.length !== 1) return { kind: "limitation", reason: "PRODUCT_NOT_FOUND" };
57
82
  const product2 = CommerceProductSchema.safeParse(matches[0]);
58
83
  if (!product2.success) return { kind: "limitation", reason: "PRODUCT_INVALID" };
59
- facts.push({ productId: product2.data.productId, variantId: product2.data.variantId, title: product2.data.title, description: product2.data.description ?? { status: "PARTIAL", text: "" }, attributes: product2.data.attributes ?? { status: "PARTIAL", items: [] }, options: product2.data.options ?? { status: "PARTIAL", items: [] }, selectedOptions: product2.data.selectedOptions ?? [] });
84
+ facts.push({ stock: product2.data.stock ?? { status: "UNAVAILABLE" }, observedAt: product2.data.observedAt, productId: product2.data.productId, variantId: product2.data.variantId, title: product2.data.title, description: product2.data.description ?? { status: "PARTIAL", text: "" }, attributes: product2.data.attributes ?? { status: "PARTIAL", items: [] }, options: product2.data.options ?? { status: "PARTIAL", items: [] }, selectedOptions: product2.data.selectedOptions ?? [] });
60
85
  }
61
86
  return { kind: "verified", productFacts: facts };
62
87
  }
@@ -64,7 +89,8 @@ function renderCommerceProductFacts(facts, locale) {
64
89
  const [unavailable, incomplete, selected] = productFactMessages[locale];
65
90
  if (!facts.length) return unavailable;
66
91
  return facts.map((f) => {
67
- const lines = [];
92
+ const labels3 = stockFactMessages[locale];
93
+ const lines = [f.stock.status === "KNOWN" ? `${f.stock.scope === "VARIANT" ? labels3[1] : labels3[0]}: ${new Intl.NumberFormat(locale).format(f.stock.quantity)}` : f.stock.status === "NOT_TRACKED" ? labels3[2] : labels3[3]];
68
94
  if (f.description.text) lines.push(f.description.text);
69
95
  const selectedLines = [...new Set(f.selectedOptions.map((o) => `${o.name}: ${o.value}`))];
70
96
  const factLines = [...f.attributes.items.map((a) => `${a.name}: ${a.values.length ? a.values.join(", ") : unavailable}`), ...f.options.items.filter((o) => !f.attributes.items.some((a) => a.name === o.name && JSON.stringify(a.values) === JSON.stringify(o.values))).map((o) => `${o.name}: ${o.values.length ? o.values.join(", ") : unavailable}`)];
@@ -653,6 +679,7 @@ export {
653
679
  renderRecommendationReply,
654
680
  selectShippingPresentation,
655
681
  stableJson,
682
+ stockFactMessages,
656
683
  sumPurchaseSubtotal,
657
684
  validDefinition,
658
685
  verifyCommerceOptionFacts,