@useinsider/guido 3.19.0-beta.dcea8c0 → 3.19.0-beta.e110e88

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,27 +1,27 @@
1
- import { useToaster as D } from "../../../../composables/useToaster.js";
2
- import { useTranslations as L } from "../../../../composables/useTranslations.js";
3
- import { getRecommendationFeedSourceMaps as F, strategyEditPath as U, URLS as E, getOperatorOptions as N, PriceAttributes as M } from "../../../../enums/extensions/recommendationBlock.js";
4
- import { ToasterTypeOptions as A } from "../../../../enums/toaster.js";
5
- import { useRecommendationApi as T } from "../../../../services/recommendationApi.js";
6
- import { useConfigStore as k } from "../../../../stores/config.js";
7
- import { defineStore as B } from "pinia";
1
+ import { useToaster as L } from "../../../../composables/useToaster.js";
2
+ import { useTranslations as U } from "../../../../composables/useTranslations.js";
3
+ import { getRecommendationFeedSourceMaps as w, strategyEditPath as E, URLS as N, getOperatorOptions as M, PriceAttributes as A } from "../../../../enums/extensions/recommendationBlock.js";
4
+ import { ToasterTypeOptions as B } from "../../../../enums/toaster.js";
5
+ import { useRecommendationApi as z } from "../../../../services/recommendationApi.js";
6
+ import { useConfigStore as R } from "../../../../stores/config.js";
7
+ import { defineStore as O } from "pinia";
8
8
  import "../constants/selectors.js";
9
- import { DEFAULT_MOBILE_CARDS_IN_ROW as O, DEFAULT_CARDS_IN_ROW as z } from "../constants/layout.js";
10
- import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as x, EXCLUDED_ALGORITHM_IDS as V } from "../constants/defaultConfig.js";
11
- import { getDefaultProducts as w } from "../templates/utils.js";
12
- import { generateCompleteFilterQuery as P } from "../utils/filterUtil.js";
13
- import { isLegacyStrategyConfig as j } from "../utils/legacyStrategyMigration.js";
14
- import { getPartnerRecommendationParams as $ } from "../utils/partnerCustomizations.js";
15
- import { sanitizeProductIds as q } from "../utils/productIds.js";
16
- import { isFilterValid as K } from "../validation/filterSchema.js";
17
- import { getInvalidFields as H, isConfigValid as J } from "../validation/requiredFields.js";
18
- const m = T();
19
- let S = null, p = null, y = null, I = "", R = null, b = 0;
9
+ import { DEFAULT_MOBILE_CARDS_IN_ROW as T, DEFAULT_CARDS_IN_ROW as x } from "../constants/layout.js";
10
+ import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as V, EXCLUDED_ALGORITHM_IDS as j } from "../constants/defaultConfig.js";
11
+ import { getDefaultProducts as P } from "../templates/utils.js";
12
+ import { generateCompleteFilterQuery as G } from "../utils/filterUtil.js";
13
+ import { isLegacyStrategyConfig as $ } from "../utils/legacyStrategyMigration.js";
14
+ import { getPartnerRecommendationParams as q } from "../utils/partnerCustomizations.js";
15
+ import { sanitizeProductIds as K } from "../utils/productIds.js";
16
+ import { isFilterValid as H } from "../validation/filterSchema.js";
17
+ import { getInvalidFields as J, isConfigValid as Q } from "../validation/requiredFields.js";
18
+ const u = z();
19
+ let S = null, p = null, y = null, I = "", k = null, b = 0;
20
20
  const g = /* @__PURE__ */ new Map();
21
21
  let l = null;
22
- function _() {
22
+ function D() {
23
23
  return {
24
- cardsInRow: z,
24
+ cardsInRow: x,
25
25
  currencySettings: {
26
26
  name: "USD",
27
27
  value: "USD",
@@ -35,7 +35,7 @@ function _() {
35
35
  productIds: [],
36
36
  id: 1,
37
37
  language: "en_US",
38
- mobileCardsInRow: O,
38
+ mobileCardsInRow: T,
39
39
  mobileLayoutEnabled: !1,
40
40
  orientation: "grid",
41
41
  recommendedProducts: [],
@@ -45,7 +45,7 @@ function _() {
45
45
  // that default is what reached buildCampaignUrl and baked a most-popular feed URL
46
46
  // for a block the user never configured (SD-149916). Legacy blocks still get their real
47
47
  // algorithm from the node-config sync or the save-time seed.
48
- strategy: k().isFeatureEnabled("reusableRecommendationStrategy") ? "" : "mostPopular",
48
+ strategy: R().isFeatureEnabled("reusableRecommendationStrategy") ? "" : "mostPopular",
49
49
  strategyId: "",
50
50
  nodeConfigVersion: C,
51
51
  textTrimming: !0,
@@ -56,9 +56,9 @@ function _() {
56
56
  priceHideIfSameAsDiscounted: !1
57
57
  };
58
58
  }
59
- function G() {
59
+ function _() {
60
60
  return {
61
- recommendationConfigs: _(),
61
+ recommendationConfigs: D(),
62
62
  recommendationProducts: [],
63
63
  filterStatus: !1,
64
64
  filterSelectionDrawerStatus: !1,
@@ -72,7 +72,7 @@ function G() {
72
72
  legacyConversionLoading: !1
73
73
  };
74
74
  }
75
- const Q = () => ({
75
+ const W = () => ({
76
76
  recommendationCampaignUrls: {},
77
77
  activePredictiveAlgorithms: [],
78
78
  languages: {},
@@ -87,8 +87,8 @@ const Q = () => ({
87
87
  currentRecommendationId: null,
88
88
  strategyPanelOpen: !1,
89
89
  configVersion: 0
90
- }), ft = B("guidoRecommendationExtension", {
91
- state: () => Q(),
90
+ }), gt = O("guidoRecommendationExtension", {
91
+ state: () => W(),
92
92
  getters: {
93
93
  // ====================================================================
94
94
  // Proxy Getters — Backward Compatible Access to Current Block State
@@ -98,7 +98,7 @@ const Q = () => ({
98
98
  * This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
99
99
  */
100
100
  recommendationConfigs(t) {
101
- return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : _();
101
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : D();
102
102
  },
103
103
  /**
104
104
  * Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
@@ -119,7 +119,7 @@ const Q = () => ({
119
119
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
120
120
  },
121
121
  isLegacyStrategyBlock() {
122
- return k().isFeatureEnabled("reusableRecommendationStrategy") && j(this.recommendationConfigs);
122
+ return R().isFeatureEnabled("reusableRecommendationStrategy") && $(this.recommendationConfigs);
123
123
  },
124
124
  legacyConversionLoading(t) {
125
125
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
@@ -162,8 +162,8 @@ const Q = () => ({
162
162
  return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
163
163
  },
164
164
  getActivePredictiveAlgorithms: (t) => {
165
- const e = F(), r = [];
166
- return t.activePredictiveAlgorithms.filter((n) => !V.includes(n)).forEach((n) => {
165
+ const e = w(), r = [];
166
+ return t.activePredictiveAlgorithms.filter((n) => !j.includes(n)).forEach((n) => {
167
167
  r.push(...e.filter((s) => s.id === n));
168
168
  }), r.map((n) => ({
169
169
  text: n.name,
@@ -181,7 +181,7 @@ const Q = () => ({
181
181
  getFilterList() {
182
182
  return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
183
183
  let e;
184
- return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : M.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
184
+ return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : A.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
185
185
  text: t.displayName,
186
186
  value: e,
187
187
  type: t.attributeType
@@ -203,7 +203,7 @@ const Q = () => ({
203
203
  setCurrentBlock(t) {
204
204
  this.blockStates[t] || (this.blockStates = {
205
205
  ...this.blockStates,
206
- [t]: G()
206
+ [t]: _()
207
207
  }), this.currentRecommendationId = t;
208
208
  },
209
209
  /**
@@ -234,7 +234,7 @@ const Q = () => ({
234
234
  const r = this.blockStates[t];
235
235
  if (r) {
236
236
  const o = structuredClone(r);
237
- o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId && k().isFeatureEnabled("reusableRecommendationStrategy") && (o.isInitialized = !1, o.syncedConfigFingerprint = null), this.blockStates = {
237
+ o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (o.isInitialized = !1, o.syncedConfigFingerprint = null), this.blockStates = {
238
238
  ...this.blockStates,
239
239
  [e]: o
240
240
  };
@@ -275,7 +275,7 @@ const Q = () => ({
275
275
  decimalCount: String(e.currencyDecimalCount),
276
276
  decimalSeparator: r(e.currencyDecimalSeparator, ","),
277
277
  thousandSeparator: r(e.currencyThousandSeparator, ".")
278
- }, s = !this.blockStates[t], i = s ? G() : this.blockStates[t];
278
+ }, s = !this.blockStates[t], i = s ? _() : this.blockStates[t];
279
279
  i.recommendationConfigs = {
280
280
  ...i.recommendationConfigs,
281
281
  strategy: e.strategy,
@@ -314,7 +314,7 @@ const Q = () => ({
314
314
  * Creates a filter with the first available attribute and operator pre-selected.
315
315
  */
316
316
  createDefaultFilter(t, e) {
317
- const [r] = this.getFilterList, [n] = N(r == null ? void 0 : r.type);
317
+ const [r] = this.getFilterList, [n] = M(r == null ? void 0 : r.type);
318
318
  return {
319
319
  type: "standardFilter",
320
320
  attribute: (r == null ? void 0 : r.value) ?? "",
@@ -380,9 +380,9 @@ const Q = () => ({
380
380
  this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].removeStrategyModalStatus = !1);
381
381
  },
382
382
  async fetchStrategies() {
383
- for (; R; )
383
+ for (; k; )
384
384
  try {
385
- await R;
385
+ await k;
386
386
  } catch {
387
387
  }
388
388
  if (this.strategiesFetched)
@@ -390,7 +390,7 @@ const Q = () => ({
390
390
  const t = b, e = (async () => {
391
391
  this.strategiesLoading = !0;
392
392
  try {
393
- const r = await m.fetchRecommendationStrategies();
393
+ const r = await u.fetchRecommendationStrategies();
394
394
  if (t !== b)
395
395
  return;
396
396
  this.strategies = r, this.strategiesFetched = !0;
@@ -398,11 +398,11 @@ const Q = () => ({
398
398
  this.strategiesLoading = !1, t === b && (this.strategiesSettled = !0);
399
399
  }
400
400
  })();
401
- R = e;
401
+ k = e;
402
402
  try {
403
403
  await e;
404
404
  } finally {
405
- R = null;
405
+ k = null;
406
406
  }
407
407
  },
408
408
  /**
@@ -434,9 +434,9 @@ const Q = () => ({
434
434
  _armStrategyPageReturn(t) {
435
435
  const e = window.open(t, "_blank");
436
436
  if (!e)
437
- return D().showToaster({
438
- type: A.Error,
439
- message: L()("discovery-strategy.error-description")
437
+ return L().showToaster({
438
+ type: B.Error,
439
+ message: U()("discovery-strategy.error-description")
440
440
  }), !1;
441
441
  e.opener = null, l == null || l();
442
442
  let r = !1;
@@ -471,20 +471,20 @@ const Q = () => ({
471
471
  * new strategy is offered; the user picks it themselves.
472
472
  */
473
473
  openStrategyCreation() {
474
- return this._armStrategyPageReturn(E.RECOMMENDATION_STRATEGY_CREATE_PATH);
474
+ return this._armStrategyPageReturn(N.RECOMMENDATION_STRATEGY_CREATE_PATH);
475
475
  },
476
476
  /**
477
477
  * Opens the strategy's edit page. Every return refreshes the list so the block reflects the
478
478
  * edited configuration.
479
479
  */
480
480
  openStrategyEdit(t) {
481
- return this._armStrategyPageReturn(U(t));
481
+ return this._armStrategyPageReturn(E(t));
482
482
  },
483
483
  async resolveStrategyUrlTemplate(t, e) {
484
484
  const r = typeof t.updated_at == "string" ? t.updated_at : "", n = r ? `${t.strategy_id}:${r}:${e}` : "", s = n ? this.strategyUrlTemplates[n] : void 0;
485
485
  if (s)
486
486
  return s;
487
- const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
487
+ const { full_path: i = "" } = await u.generateStrategyEndpoint(t, e) ?? {};
488
488
  return n && i && (this.strategyUrlTemplates = {
489
489
  ...this.strategyUrlTemplates,
490
490
  [n]: i
@@ -502,8 +502,7 @@ const Q = () => ({
502
502
  throw new Error("[Guido] convertLegacyStrategy called without an active block");
503
503
  this.blockStates[r].legacyConversionLoading = !0;
504
504
  try {
505
- const n = await m.migrateLegacyStrategy(t, e);
506
- this.invalidateStrategies();
505
+ const n = await u.migrateLegacyStrategy(t, e);
507
506
  try {
508
507
  await this.fetchStrategies();
509
508
  } catch (o) {
@@ -533,7 +532,7 @@ const Q = () => ({
533
532
  this.patchCurrentBlockConfig({
534
533
  strategyId: "",
535
534
  strategy: "",
536
- size: x.size,
535
+ size: V.size,
537
536
  nodeConfigVersion: C
538
537
  });
539
538
  },
@@ -551,7 +550,7 @@ const Q = () => ({
551
550
  activePredictiveAlgorithms: t,
552
551
  languages: e,
553
552
  currencies: r
554
- } = await m.fetchRecommendationCreateData();
553
+ } = await u.fetchRecommendationCreateData();
555
554
  if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
556
555
  const n = this.blockStates[this.currentRecommendationId];
557
556
  n.filterStatus = !!n.recommendationConfigs.filters.length;
@@ -572,7 +571,7 @@ const Q = () => ({
572
571
  return;
573
572
  }
574
573
  p = (async () => {
575
- const t = await m.fetchRecommendationFilters();
574
+ const t = await u.fetchRecommendationFilters();
576
575
  this.filterList = t;
577
576
  })();
578
577
  try {
@@ -607,7 +606,7 @@ const Q = () => ({
607
606
  const n = [...e.recommendationConfigs.filters];
608
607
  n[r] = {
609
608
  ...t,
610
- isValid: K(t)
609
+ isValid: H(t)
611
610
  }, e.recommendationConfigs.filters = n;
612
611
  }
613
612
  },
@@ -621,7 +620,7 @@ const Q = () => ({
621
620
  let i = 1;
622
621
  n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
623
622
  } else {
624
- const i = [...new Set(n.map((a) => a.filterGroup))].sort((a, d) => a - d), o = new Map(i.map((a, d) => [a, d + 1]));
623
+ const i = [...new Set(n.map((a) => a.filterGroup))].sort((a, m) => a - m), o = new Map(i.map((a, m) => [a, m + 1]));
625
624
  n = n.map((a) => ({
626
625
  ...a,
627
626
  filterGroup: o.get(a.filterGroup) ?? a.filterGroup
@@ -645,7 +644,7 @@ const Q = () => ({
645
644
  }), e.recommendationConfigs.filters = r;
646
645
  },
647
646
  generateFilterQuery() {
648
- return P(this.recommendationConfigs.filters);
647
+ return G(this.recommendationConfigs.filters);
649
648
  },
650
649
  /**
651
650
  * Validation-only check invoked at save-CTA time. Defined as an action
@@ -653,14 +652,14 @@ const Q = () => ({
653
652
  * every block's recommendationConfigs across user edits.
654
653
  */
655
654
  hasInvalidBlock() {
656
- return Object.values(this.blockStates).some((t) => !J(t.recommendationConfigs, this));
655
+ return Object.values(this.blockStates).some((t) => !Q(t.recommendationConfigs, this));
657
656
  },
658
657
  /**
659
658
  * Which required fields are missing across the design's blocks, so the save
660
659
  * toaster can name the cause instead of always showing the generic message.
661
660
  */
662
661
  invalidBlockFields() {
663
- return Object.values(this.blockStates).flatMap((t) => H(t.recommendationConfigs, this));
662
+ return Object.values(this.blockStates).flatMap((t) => J(t.recommendationConfigs, this));
664
663
  },
665
664
  // ====================================================================
666
665
  // Per-Block Product Fetching
@@ -686,7 +685,7 @@ const Q = () => ({
686
685
  },
687
686
  async _doFetchProducts() {
688
687
  var h;
689
- const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = k();
688
+ const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = R();
690
689
  if (r.strategyId && n.isFeatureEnabled("reusableRecommendationStrategy")) {
691
690
  await this._doFetchStrategyProducts(t);
692
691
  return;
@@ -698,7 +697,7 @@ const Q = () => ({
698
697
  this._setBlockProducts(t, [], i);
699
698
  return;
700
699
  }
701
- const o = r.filters.filter((f) => f.isValid), a = P(o), d = ((h = F().find((f) => f.key === r.strategy)) == null ? void 0 : h.path) || "", c = {
700
+ const o = r.filters.filter((f) => f.isValid), a = G(o), m = ((h = w().find((f) => f.key === r.strategy)) == null ? void 0 : h.path) || "", c = {
702
701
  locale: r.language,
703
702
  currency: r.currencySettings.value,
704
703
  partnerName: n.partnerName,
@@ -706,58 +705,83 @@ const Q = () => ({
706
705
  details: !0,
707
706
  campaignId: n.variationId
708
707
  };
709
- r.strategy === "manualMerchandising" ? c.productId = q(r.productIds) : r.strategy === "similarViewed" && (c.productId = "{itemId}"), r.strategy === "userBased" && (c.userId = "{user_id}"), a && (c.filter = a), r.shuffleProducts && (c.shuffle = !0), Object.assign(
708
+ r.strategy === "manualMerchandising" ? c.productId = K(r.productIds) : r.strategy === "similarViewed" && (c.productId = "{itemId}"), r.strategy === "userBased" && (c.userId = "{user_id}"), a && (c.filter = a), r.shuffleProducts && (c.shuffle = !0), Object.assign(
710
709
  c,
711
- $(n.partnerName, r.strategy)
710
+ q(n.partnerName, r.strategy)
712
711
  );
713
- let u;
712
+ let d;
714
713
  try {
715
- u = await m.fetchRecommendationProducts(d, c);
714
+ d = await u.fetchRecommendationProducts(m, c);
716
715
  } catch {
717
- u = [];
716
+ d = [];
718
717
  }
719
- g.get(t) === s && this._setBlockProducts(t, u, i);
718
+ g.get(t) === s && this._setBlockProducts(t, d, i);
720
719
  },
721
720
  /**
722
721
  * Block-scoped counterpart of `fetchRecommendationProducts`, which only ever serves the
723
722
  * selected block. The legacy conversion must refresh the products of the block that
724
723
  * started it even after the user selected another one.
724
+ * @returns whether real products arrived
725
725
  */
726
- async fetchStrategyProductsForBlock(t) {
727
- var e;
728
- (e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId && await this._doFetchStrategyProducts(t);
726
+ async fetchStrategyProductsForBlock(t, e = {}) {
727
+ var r;
728
+ return (r = this.blockStates[t]) != null && r.recommendationConfigs.strategyId ? this._doFetchStrategyProducts(t, e) : !1;
729
729
  },
730
- async _doFetchStrategyProducts(t) {
731
- const e = (g.get(t) ?? 0) + 1;
732
- g.set(t, e);
733
- const { recommendationConfigs: r } = this.blockStates[t];
734
- let n = [], s = parseInt(r.size) || 6;
730
+ /**
731
+ * Reloads a block's products and adopts its strategy's current size, which may have
732
+ * moved since the block was assigned.
733
+ * @returns whether a fresh listing holds the strategy and its products arrived
734
+ */
735
+ async refreshStrategyBlock(t) {
736
+ var s;
737
+ const e = (s = this.blockStates[t]) == null ? void 0 : s.recommendationConfigs.strategyId;
738
+ if (!e)
739
+ return !1;
740
+ try {
741
+ await this.fetchStrategies();
742
+ } catch {
743
+ return !1;
744
+ }
745
+ const r = this.strategiesFetched ? this.strategies.find((i) => String(i.strategy_id) === e) : void 0;
746
+ if (!r || !await this.fetchStrategyProductsForBlock(t, { keepOnFailure: !0 }))
747
+ return !1;
748
+ const n = this.blockStates[t];
749
+ return n ? (r.size !== void 0 && (n.recommendationConfigs = {
750
+ ...n.recommendationConfigs,
751
+ size: String(r.size)
752
+ }), !0) : !1;
753
+ },
754
+ async _doFetchStrategyProducts(t, { keepOnFailure: e = !1 } = {}) {
755
+ const r = (g.get(t) ?? 0) + 1;
756
+ g.set(t, r);
757
+ const { recommendationConfigs: n } = this.blockStates[t];
758
+ let s = [], i = parseInt(n.size) || 6;
735
759
  try {
736
760
  await this.fetchStrategies();
737
- const i = this.strategies.find(
738
- (o) => String(o.strategy_id) === r.strategyId
761
+ const o = this.strategies.find(
762
+ (a) => String(a.strategy_id) === n.strategyId
739
763
  );
740
- if (i) {
741
- s = parseInt(String(i.size ?? "")) || s;
742
- const o = r.currencySettings.value, d = (await this.resolveStrategyUrlTemplate(i, o)).replaceAll("{locale}", r.language).replaceAll("{currency}", o), c = d.indexOf("?"), u = c === -1 ? d : d.slice(0, c), h = (c === -1 ? "" : d.slice(c + 1)).split("&").filter((v) => v && !v.startsWith("user_id=")), f = h.length ? `${u}?${h.join("&")}` : u;
743
- f && (n = await m.fetchRecommendationProductsByUrl(f));
764
+ if (o) {
765
+ i = parseInt(String(o.size ?? "")) || i;
766
+ const a = n.currencySettings.value, c = (await this.resolveStrategyUrlTemplate(o, a)).replaceAll("{locale}", n.language).replaceAll("{currency}", a), d = c.indexOf("?"), h = d === -1 ? c : c.slice(0, d), f = (d === -1 ? "" : c.slice(d + 1)).split("&").filter((F) => F && !F.startsWith("user_id=")), v = f.length ? `${h}?${f.join("&")}` : h;
767
+ v && (s = await u.fetchRecommendationProductsByUrl(v));
744
768
  }
745
769
  } catch {
746
- n = [];
770
+ s = [];
747
771
  }
748
- g.get(t) === e && this._setBlockProducts(t, n, s);
772
+ return g.get(t) !== r || !s.length && e ? !1 : (this._setBlockProducts(t, s, i), s.length > 0);
749
773
  },
750
774
  _setBlockProducts(t, e, r) {
751
775
  if (!this.blockStates[t])
752
776
  return;
753
- const n = e.length > 0 ? e : w(r);
777
+ const n = e.length > 0 ? e : P(r);
754
778
  this.blockStates[t].recommendationProducts = [
755
779
  ...n.slice(0, r),
756
- ...w(Math.max(0, r - n.length))
780
+ ...P(Math.max(0, r - n.length))
757
781
  ];
758
782
  }
759
783
  }
760
784
  });
761
785
  export {
762
- ft as useRecommendationExtensionStore
786
+ gt as useRecommendationExtensionStore
763
787
  };
@@ -1,32 +1,37 @@
1
- import { ModificationDescription as g } from "../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
- import { RECOMMENDATION_ID_ATTR as s } from "../constants/selectors.js";
3
- import { isPartnerManagedBlock as p, updateProductContentInPlace as C, regenerateProductRowsWithStyles as N } from "../controls/main/utils.js";
4
- import { RecommendationConfigService as m } from "../services/configService.js";
5
- let o = null;
6
- function D(n) {
7
- o = n;
1
+ import { ModificationDescription as m } from "../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
2
+ import { RECOMMENDATION_ID_ATTR as a } from "../constants/selectors.js";
3
+ import { isPartnerManagedBlock as C, updateProductContentInPlace as N, regenerateProductRowsWithStyles as p } from "../controls/main/utils.js";
4
+ import { RecommendationConfigService as l } from "../services/configService.js";
5
+ let e = null;
6
+ function O(n) {
7
+ e = n;
8
8
  }
9
- function P(n, r, c, l) {
10
- const i = o == null ? void 0 : o.getDocumentRootHtmlNode();
11
- if (!o || !i || !("querySelector" in i))
9
+ function R(n) {
10
+ const o = e == null ? void 0 : e.getDocumentRootHtmlNode();
11
+ return !o || !("querySelectorAll" in o) ? [] : o.querySelectorAll(`[${a}="${n}"]`).map((i) => l.getConfig(i));
12
+ }
13
+ function P(n, o, i, u) {
14
+ const c = e == null ? void 0 : e.getDocumentRootHtmlNode();
15
+ if (!e || !c || !("querySelector" in c))
12
16
  return !1;
13
- const e = i.querySelector(`[${s}="${n}"]`);
14
- if (!e)
17
+ const t = c.querySelector(`[${a}="${n}"]`);
18
+ if (!t)
15
19
  return !1;
16
- const t = o.getDocumentModifier(), a = m.getConfig(e), d = Object.keys(r).some((u) => JSON.stringify(a[u]) !== JSON.stringify(r[u]));
17
- if (m.stageConfig(t, e, r), p(e))
18
- return t.apply(new g(l)), !0;
20
+ const r = e.getDocumentModifier(), d = l.getConfig(t), s = Object.keys(o).some((g) => JSON.stringify(d[g]) !== JSON.stringify(o[g]));
21
+ if (l.stageConfig(r, t, o), C(t))
22
+ return r.apply(new m(u)), !0;
19
23
  let f = !1;
20
- return C({
21
- currentNode: e,
22
- documentModifier: t,
23
- products: c,
24
+ return N({
25
+ currentNode: t,
26
+ documentModifier: r,
27
+ products: i,
24
28
  onApplied: () => {
25
29
  f = !0;
26
30
  }
27
- }) || (f = N({ currentNode: e, documentModifier: t, products: c })), !f && d && t.apply(new g(l)), !0;
31
+ }) || (f = p({ currentNode: t, documentModifier: r, products: i })), !f && s && r.apply(new m(u)), !0;
28
32
  }
29
33
  export {
30
34
  P as commitBlockChangeOutsidePanel,
31
- D as registerNodeConfigWriter
35
+ R as readBlockNodeConfigs,
36
+ O as registerNodeConfigWriter
32
37
  };
@@ -1,24 +1,63 @@
1
- import { useRecommendationExtensionStore as d } from "../store/recommendation.js";
2
- import { commitBlockChangeOutsidePanel as f } from "./nodeConfigWriter.js";
3
- async function h(e, r) {
4
- const t = d(), o = t.blockStates[e];
5
- if (!o)
1
+ import { useRecommendationExtensionStore as m } from "../store/recommendation.js";
2
+ import { commitBlockChangeOutsidePanel as d, readBlockNodeConfigs as l } from "./nodeConfigWriter.js";
3
+ function i(e) {
4
+ return {
5
+ strategy: e.strategy,
6
+ strategyId: e.strategyId,
7
+ language: e.language,
8
+ size: e.size,
9
+ productIds: [...e.productIds],
10
+ filters: structuredClone(e.filters),
11
+ shuffleProducts: e.shuffleProducts,
12
+ currencyCode: e.currency.code,
13
+ currencySymbol: e.currency.symbol,
14
+ currencyAlignment: e.currency.alignment,
15
+ currencyDecimalCount: e.currency.decimalCount,
16
+ currencyDecimalSeparator: e.currency.decimalSeparator,
17
+ currencyThousandSeparator: e.currency.thousandSeparator
18
+ };
19
+ }
20
+ function f(e, n) {
21
+ const o = JSON.stringify(i(n));
22
+ return l(e).find((r) => JSON.stringify(i(r)) !== o) ?? n;
23
+ }
24
+ async function C(e, n, o) {
25
+ const r = m(), c = [e, n];
26
+ (/* @__PURE__ */ new Map([[e, f(e, o)], [n, o]])).forEach((t, s) => {
27
+ var a;
28
+ t.strategyId && ((a = r.blockStates[s]) == null ? void 0 : a.recommendationConfigs.strategyId) !== t.strategyId && r.seedBlockUrlConfig(s, i(t));
29
+ }), r.resetArrivedBlock(n), await Promise.all(c.map(async (t) => {
30
+ if (!await r.refreshStrategyBlock(t))
31
+ return;
32
+ const { recommendationConfigs: s, recommendationProducts: a } = r.blockStates[t];
33
+ d(
34
+ t,
35
+ { size: s.size },
36
+ a,
37
+ "Refresh duplicated recommendation strategy"
38
+ );
39
+ }));
40
+ }
41
+ async function S(e, n) {
42
+ const o = m(), r = o.blockStates[e];
43
+ if (!r)
6
44
  return !1;
7
- const { strategyId: a, strategy: c, size: i, nodeConfigVersion: s } = o.recommendationConfigs;
8
- if (t.currentRecommendationId === e)
45
+ const { strategyId: c, strategy: u, size: t, nodeConfigVersion: s } = r.recommendationConfigs;
46
+ if (o.currentRecommendationId === e)
9
47
  try {
10
- await t.fetchRecommendationProducts();
11
- } catch (m) {
12
- console.error("[recommendation] product refetch after a strategy change failed", m);
48
+ await o.fetchRecommendationProducts();
49
+ } catch (y) {
50
+ console.error("[recommendation] product refetch after a strategy change failed", y);
13
51
  }
14
- const n = f(
52
+ const a = d(
15
53
  e,
16
- { strategyId: a, strategy: c, size: i, configVersion: s },
17
- o.recommendationProducts,
18
- r
54
+ { strategyId: c, strategy: u, size: t, configVersion: s },
55
+ r.recommendationProducts,
56
+ n
19
57
  );
20
- return n || console.error("[recommendation] strategy change did not reach a node", { blockId: e }), n;
58
+ return a || console.error("[recommendation] strategy change did not reach a node", { blockId: e }), a;
21
59
  }
22
60
  export {
23
- h as commitStrategyChange
61
+ S as commitStrategyChange,
62
+ C as refreshDuplicatedStrategyBlocks
24
63
  };
@@ -139,6 +139,8 @@ export declare class RecommendationBlockControl extends CommonControl {
139
139
  * fails when the size actually changed.
140
140
  */
141
141
  private _debouncedRegenerateWithProducts;
142
+ /** Draws the current block's products into this panel's node. */
143
+ private _regenerateWithProducts;
142
144
  /**
143
145
  * Listen to store changes that require product refresh or regeneration.
144
146
  *
@@ -623,9 +623,20 @@ export declare const useRecommendationExtensionStore: import("pinia").StoreDefin
623
623
  * Block-scoped counterpart of `fetchRecommendationProducts`, which only ever serves the
624
624
  * selected block. The legacy conversion must refresh the products of the block that
625
625
  * started it even after the user selected another one.
626
+ * @returns whether real products arrived
626
627
  */
627
- fetchStrategyProductsForBlock(blockId: number): Promise<void>;
628
- _doFetchStrategyProducts(blockId: number): Promise<void>;
628
+ fetchStrategyProductsForBlock(blockId: number, options?: {
629
+ keepOnFailure?: boolean;
630
+ }): Promise<boolean>;
631
+ /**
632
+ * Reloads a block's products and adopts its strategy's current size, which may have
633
+ * moved since the block was assigned.
634
+ * @returns whether a fresh listing holds the strategy and its products arrived
635
+ */
636
+ refreshStrategyBlock(blockId: number): Promise<boolean>;
637
+ _doFetchStrategyProducts(blockId: number, { keepOnFailure }?: {
638
+ keepOnFailure?: boolean;
639
+ }): Promise<boolean>;
629
640
  _setBlockProducts(blockId: number, products: RecommendationProduct[], size: number): void;
630
641
  }>;
631
642
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { DocumentModifier } from '../services/configService';
2
- import type { PartialNodeConfig } from '../types/nodeConfig';
2
+ import type { PartialNodeConfig, RecommendationNodeConfig } from '../types/nodeConfig';
3
3
  import type { RecommendationProduct } from '@@/Types/recommendation';
4
4
  import { ImmutableHtmlNode } from '@stripoinc/ui-editor-extensions';
5
5
  interface ConfigWriterApi {
@@ -13,6 +13,8 @@ interface ConfigWriterApi {
13
13
  * itself is torn down.
14
14
  */
15
15
  export declare function registerNodeConfigWriter(api: ConfigWriterApi): void;
16
+ /** Reads the persisted config of every node carrying a block id (two while a duplicate still shares it). */
17
+ export declare function readBlockNodeConfigs(blockId: number): RecommendationNodeConfig[];
16
18
  /**
17
19
  * Commits a config change and its product re-render straight to the document,
18
20
  * bypassing the settings panel.
@@ -1,3 +1,10 @@
1
+ import type { RecommendationNodeConfig } from '../types/nodeConfig';
2
+ /**
3
+ * Re-reads the strategy of a duplicated block and its source and redraws both: the clone copies the
4
+ * cards the source last drew, so a strategy edited since then only reached a block once selected (SD-153266).
5
+ * @param config - the arriving block's persisted config; seeds either block its store entry does not match
6
+ */
7
+ export declare function refreshDuplicatedStrategyBlocks(sourceId: number, duplicateId: number, config: RecommendationNodeConfig): Promise<void>;
1
8
  /**
2
9
  * Writes a strategy change and its products straight to the document, without the settings panel.
3
10
  *