@useinsider/guido 3.20.1 → 3.20.2-beta.87fb8ae

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,31 +1,33 @@
1
- import { useToaster as U } from "../../../../composables/useToaster.js";
2
- import { useTranslations as M } from "../../../../composables/useTranslations.js";
3
- import { getRecommendationFeedSourceMaps as w, strategyEditPath as N, strategyCreatePath as B, getOperatorOptions as z, PriceAttributes as E } from "../../../../enums/extensions/recommendationBlock.js";
4
- import { ToasterTypeOptions as O } from "../../../../enums/toaster.js";
5
- import { useRecommendationApi as A } from "../../../../services/recommendationApi.js";
1
+ import { useToaster as L } from "../../../../composables/useToaster.js";
2
+ import { useTranslations as U } from "../../../../composables/useTranslations.js";
3
+ import { getRecommendationFeedSourceMaps as F, strategyEditPath as z, strategyCreatePath as B, getOperatorOptions as M, PriceAttributes as N } from "../../../../enums/extensions/recommendationBlock.js";
4
+ import { ToasterTypeOptions as E } from "../../../../enums/toaster.js";
5
+ import { useRecommendationApi as O } from "../../../../services/recommendationApi.js";
6
6
  import { useConfigStore as R } from "../../../../stores/config.js";
7
- import { defineStore as x } from "pinia";
7
+ import { defineStore as V } from "pinia";
8
8
  import "../constants/selectors.js";
9
- import { DEFAULT_MOBILE_CARDS_IN_ROW as T, DEFAULT_CARDS_IN_ROW as V } from "../constants/layout.js";
10
- import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as j, EXCLUDED_ALGORITHM_IDS as $ } 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 q } from "../utils/legacyStrategyMigration.js";
14
- import { getPartnerRecommendationParams as K } from "../utils/partnerCustomizations.js";
15
- import { sanitizeProductIds as H } from "../utils/productIds.js";
16
- import { isFilterValid as J } from "../validation/filterSchema.js";
17
- import { getInvalidFields as Q, isConfigValid as W } from "../validation/requiredFields.js";
18
- const u = A();
19
- let S = null, y = null, p = null, I = "", k = null, b = 0;
20
- const m = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map();
21
- function X(t) {
22
- const e = D.get(t);
23
- return e && e.token === m.get(t) ? e.outcome : !1;
9
+ import { DEFAULT_MOBILE_CARDS_IN_ROW as A, DEFAULT_CARDS_IN_ROW as x } from "../constants/layout.js";
10
+ import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as T, EXCLUDED_ALGORITHM_IDS as j } 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 $ } 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 m = O();
19
+ let p = null, y = null;
20
+ const I = /* @__PURE__ */ new Map();
21
+ let k = null, b = 0;
22
+ const u = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map();
23
+ function W(t) {
24
+ const e = _.get(t);
25
+ return e && e.token === u.get(t) ? e.outcome : !1;
24
26
  }
25
27
  let l = null;
26
- function L() {
28
+ function D() {
27
29
  return {
28
- cardsInRow: V,
30
+ cardsInRow: x,
29
31
  currencySettings: {
30
32
  name: "USD",
31
33
  value: "USD",
@@ -39,7 +41,7 @@ function L() {
39
41
  productIds: [],
40
42
  id: 1,
41
43
  language: "en_US",
42
- mobileCardsInRow: T,
44
+ mobileCardsInRow: A,
43
45
  mobileLayoutEnabled: !1,
44
46
  orientation: "grid",
45
47
  recommendedProducts: [],
@@ -60,9 +62,9 @@ function L() {
60
62
  priceHideIfSameAsDiscounted: !1
61
63
  };
62
64
  }
63
- function _() {
65
+ function G() {
64
66
  return {
65
- recommendationConfigs: L(),
67
+ recommendationConfigs: D(),
66
68
  recommendationProducts: [],
67
69
  filterStatus: !1,
68
70
  filterSelectionDrawerStatus: !1,
@@ -73,10 +75,12 @@ function _() {
73
75
  isInitialized: !1,
74
76
  filterSnapshot: null,
75
77
  syncedConfigFingerprint: null,
76
- legacyConversionLoading: !1
78
+ legacyConversionLoading: !1,
79
+ configVersion: 0,
80
+ adoptedSizeVersion: 0
77
81
  };
78
82
  }
79
- const Y = () => ({
83
+ const X = () => ({
80
84
  recommendationCampaignUrls: {},
81
85
  activePredictiveAlgorithms: [],
82
86
  languages: {},
@@ -91,8 +95,8 @@ const Y = () => ({
91
95
  currentRecommendationId: null,
92
96
  strategyPanelOpen: !1,
93
97
  configVersion: 0
94
- }), St = x("guidoRecommendationExtension", {
95
- state: () => Y(),
98
+ }), ht = V("guidoRecommendationExtension", {
99
+ state: () => X(),
96
100
  getters: {
97
101
  // ====================================================================
98
102
  // Proxy Getters — Backward Compatible Access to Current Block State
@@ -102,7 +106,7 @@ const Y = () => ({
102
106
  * This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
103
107
  */
104
108
  recommendationConfigs(t) {
105
- return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : L();
109
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : D();
106
110
  },
107
111
  /**
108
112
  * Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
@@ -123,7 +127,7 @@ const Y = () => ({
123
127
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
124
128
  },
125
129
  isLegacyStrategyBlock() {
126
- return R().isFeatureEnabled("reusableRecommendationStrategy") && q(this.recommendationConfigs);
130
+ return R().isFeatureEnabled("reusableRecommendationStrategy") && $(this.recommendationConfigs);
127
131
  },
128
132
  legacyConversionLoading(t) {
129
133
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
@@ -133,7 +137,7 @@ const Y = () => ({
133
137
  },
134
138
  assignedStrategy(t) {
135
139
  const { strategyId: e } = this.recommendationConfigs;
136
- return e ? t.strategies.find((r) => String(r.strategy_id) === e) ?? null : null;
140
+ return e ? t.strategies.find((n) => String(n.strategy_id) === e) ?? null : null;
137
141
  },
138
142
  /**
139
143
  * Proxy getter: delegates to blockStates[currentRecommendationId].filterStatus
@@ -163,19 +167,19 @@ const Y = () => ({
163
167
  },
164
168
  getUniqueFilterGroups() {
165
169
  const { filters: t } = this.recommendationConfigs;
166
- return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
170
+ return [...new Set(t.map((e) => e.filterGroup))].sort((e, n) => e - n);
167
171
  },
168
172
  getActivePredictiveAlgorithms: (t) => {
169
- const e = w(), r = [];
170
- return t.activePredictiveAlgorithms.filter((n) => !$.includes(n)).forEach((n) => {
171
- r.push(...e.filter((s) => s.id === n));
172
- }), r.map((n) => ({
173
- text: n.name,
174
- value: n.key
173
+ const e = F(), n = [];
174
+ return t.activePredictiveAlgorithms.filter((r) => !j.includes(r)).forEach((r) => {
175
+ n.push(...e.filter((o) => o.id === r));
176
+ }), n.map((r) => ({
177
+ text: r.name,
178
+ value: r.key
175
179
  }));
176
180
  },
177
- getLanguages: (t) => Object.entries(t.languages).map(([e, r]) => ({
178
- text: r,
181
+ getLanguages: (t) => Object.entries(t.languages).map(([e, n]) => ({
182
+ text: n,
179
183
  value: e
180
184
  })),
181
185
  getCurrencySymbolList: (t) => t.currencyList.map((e) => ({
@@ -185,7 +189,7 @@ const Y = () => ({
185
189
  getFilterList() {
186
190
  return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
187
191
  let e;
188
- return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : E.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
192
+ return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : N.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
189
193
  text: t.displayName,
190
194
  value: e,
191
195
  type: t.attributeType
@@ -207,7 +211,7 @@ const Y = () => ({
207
211
  setCurrentBlock(t) {
208
212
  this.blockStates[t] || (this.blockStates = {
209
213
  ...this.blockStates,
210
- [t]: _()
214
+ [t]: G()
211
215
  }), this.currentRecommendationId = t;
212
216
  },
213
217
  /**
@@ -217,13 +221,13 @@ const Y = () => ({
217
221
  removeBlockState(t) {
218
222
  const e = t.toString();
219
223
  if (this.recommendationCampaignUrls[e]) {
220
- const n = { ...this.recommendationCampaignUrls };
221
- delete n[e], this.recommendationCampaignUrls = n;
224
+ const r = { ...this.recommendationCampaignUrls };
225
+ delete r[e], this.recommendationCampaignUrls = r;
222
226
  }
223
- const r = { ...this.blockStates };
224
- if (delete r[t], this.blockStates = r, this.currentRecommendationId === t) {
225
- const n = Object.keys(this.blockStates).map(Number);
226
- this.currentRecommendationId = n.length > 0 ? n[0] : null;
227
+ const n = { ...this.blockStates };
228
+ if (delete n[t], this.blockStates = n, this.currentRecommendationId === t) {
229
+ const r = Object.keys(this.blockStates).map(Number);
230
+ this.currentRecommendationId = r.length > 0 ? r[0] : null;
227
231
  }
228
232
  },
229
233
  /**
@@ -235,18 +239,18 @@ const Y = () => ({
235
239
  * (SD-149916).
236
240
  */
237
241
  cloneBlockState(t, e) {
238
- const r = this.blockStates[t];
239
- if (r) {
240
- const o = structuredClone(r);
241
- o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (o.isInitialized = !1, o.syncedConfigFingerprint = null), this.blockStates = {
242
+ const n = this.blockStates[t];
243
+ if (n) {
244
+ const s = structuredClone(n);
245
+ s.recommendationConfigs.id = e, s.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (s.isInitialized = !1, s.syncedConfigFingerprint = null), this.blockStates = {
242
246
  ...this.blockStates,
243
- [e]: o
247
+ [e]: s
244
248
  };
245
249
  }
246
- const n = t.toString(), s = e.toString(), i = this.recommendationCampaignUrls[n];
250
+ const r = t.toString(), o = e.toString(), i = this.recommendationCampaignUrls[r];
247
251
  i && (this.recommendationCampaignUrls = {
248
252
  ...this.recommendationCampaignUrls,
249
- [s]: i
253
+ [o]: i
250
254
  });
251
255
  },
252
256
  /**
@@ -271,15 +275,15 @@ const Y = () => ({
271
275
  * `isInitialized`) alone.
272
276
  */
273
277
  seedBlockUrlConfig(t, e) {
274
- const r = (o, a) => o === "." || o === "," || o === " " ? o : a, n = {
278
+ const n = (s, a) => s === "." || s === "," || s === " " ? s : a, r = {
275
279
  name: e.currencyCode,
276
280
  value: e.currencyCode,
277
281
  symbol: e.currencySymbol,
278
282
  alignment: e.currencyAlignment === "before" ? "0" : "1",
279
283
  decimalCount: String(e.currencyDecimalCount),
280
- decimalSeparator: r(e.currencyDecimalSeparator, ","),
281
- thousandSeparator: r(e.currencyThousandSeparator, ".")
282
- }, s = !this.blockStates[t], i = s ? _() : this.blockStates[t];
284
+ decimalSeparator: n(e.currencyDecimalSeparator, ","),
285
+ thousandSeparator: n(e.currencyThousandSeparator, ".")
286
+ }, o = !this.blockStates[t], i = o ? G() : this.blockStates[t];
283
287
  i.recommendationConfigs = {
284
288
  ...i.recommendationConfigs,
285
289
  strategy: e.strategy,
@@ -289,8 +293,8 @@ const Y = () => ({
289
293
  productIds: e.productIds,
290
294
  filters: e.filters,
291
295
  shuffleProducts: e.shuffleProducts,
292
- currencySettings: n
293
- }, s && (this.blockStates = {
296
+ currencySettings: r
297
+ }, o && (this.blockStates = {
294
298
  ...this.blockStates,
295
299
  [t]: i
296
300
  });
@@ -302,27 +306,27 @@ const Y = () => ({
302
306
  patchCurrentBlockConfig(t, e = {}) {
303
307
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
304
308
  return;
305
- const r = this.blockStates[this.currentRecommendationId];
306
- r.recommendationConfigs = {
307
- ...r.recommendationConfigs,
309
+ const n = this.blockStates[this.currentRecommendationId];
310
+ n.recommendationConfigs = {
311
+ ...n.recommendationConfigs,
308
312
  ...t,
309
313
  currencySettings: {
310
- ...r.recommendationConfigs.currencySettings,
314
+ ...n.recommendationConfigs.currencySettings,
311
315
  ...t.currencySettings || {}
312
316
  }
313
317
  };
314
- const { triggerRefetch: n = !0 } = e;
315
- n && this.configVersion++;
318
+ const { triggerRefetch: r = !0 } = e;
319
+ r && (n.configVersion++, this.configVersion++);
316
320
  },
317
321
  /**
318
322
  * Creates a filter with the first available attribute and operator pre-selected.
319
323
  */
320
324
  createDefaultFilter(t, e) {
321
- const [r] = this.getFilterList, [n] = z(r == null ? void 0 : r.type);
325
+ const [n] = this.getFilterList, [r] = M(n == null ? void 0 : n.type);
322
326
  return {
323
327
  type: "standardFilter",
324
- attribute: (r == null ? void 0 : r.value) ?? "",
325
- operator: (n == null ? void 0 : n.value) ?? "",
328
+ attribute: (n == null ? void 0 : n.value) ?? "",
329
+ operator: (r == null ? void 0 : r.value) ?? "",
326
330
  innerGroupOperator: "*",
327
331
  outerGroupOperator: "*",
328
332
  filterNumber: e,
@@ -394,10 +398,10 @@ const Y = () => ({
394
398
  const t = b, e = (async () => {
395
399
  this.strategiesLoading = !0;
396
400
  try {
397
- const r = await u.fetchRecommendationStrategies();
401
+ const n = await m.fetchRecommendationStrategies();
398
402
  if (t !== b)
399
403
  return;
400
- this.strategies = r, this.strategiesFetched = !0;
404
+ this.strategies = n, this.strategiesFetched = !0;
401
405
  } finally {
402
406
  this.strategiesLoading = !1, t === b && (this.strategiesSettled = !0);
403
407
  }
@@ -438,20 +442,20 @@ const Y = () => ({
438
442
  _armStrategyPageReturn(t) {
439
443
  const e = window.open(t, "_blank");
440
444
  if (!e)
441
- return U().showToaster({
442
- type: O.Error,
443
- message: M()("discovery-strategy.error-description")
445
+ return L().showToaster({
446
+ type: E.Error,
447
+ message: U()("discovery-strategy.error-description")
444
448
  }), !1;
445
449
  e.opener = null, l == null || l();
446
- let r = !1;
447
- const n = () => {
448
- document.hidden || r || (e != null && e.closed && (l == null || l()), r = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
450
+ let n = !1;
451
+ const r = () => {
452
+ document.hidden || n || (e != null && e.closed && (l == null || l()), n = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
449
453
  }).finally(() => {
450
- r = !1;
454
+ n = !1;
451
455
  }));
452
456
  };
453
- return document.addEventListener("visibilitychange", n), l = () => {
454
- document.removeEventListener("visibilitychange", n), l = null;
457
+ return document.addEventListener("visibilitychange", r), l = () => {
458
+ document.removeEventListener("visibilitychange", r), l = null;
455
459
  }, !0;
456
460
  },
457
461
  /**
@@ -482,16 +486,16 @@ const Y = () => ({
482
486
  * edited configuration.
483
487
  */
484
488
  openStrategyEdit(t) {
485
- return this._armStrategyPageReturn(N(t));
489
+ return this._armStrategyPageReturn(z(t));
486
490
  },
487
491
  async resolveStrategyUrlTemplate(t, e) {
488
- const r = typeof t.updated_at == "string" ? t.updated_at : "", n = r ? `${t.strategy_id}:${r}:${e}` : "", s = n ? this.strategyUrlTemplates[n] : void 0;
489
- if (s)
490
- return s;
491
- const { full_path: i = "" } = await u.generateStrategyEndpoint(t, e) ?? {};
492
- return n && i && (this.strategyUrlTemplates = {
492
+ const n = typeof t.updated_at == "string" ? t.updated_at : "", r = n ? `${t.strategy_id}:${n}:${e}` : "", o = r ? this.strategyUrlTemplates[r] : void 0;
493
+ if (o)
494
+ return o;
495
+ const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
496
+ return r && i && (this.strategyUrlTemplates = {
493
497
  ...this.strategyUrlTemplates,
494
- [n]: i
498
+ [r]: i
495
499
  }), i;
496
500
  },
497
501
  assignStrategy(t) {
@@ -501,27 +505,27 @@ const Y = () => ({
501
505
  });
502
506
  },
503
507
  async convertLegacyStrategy(t, e = { scope: "campaign" }) {
504
- const r = this.currentRecommendationId;
505
- if (r === null || !this.blockStates[r])
508
+ const n = this.currentRecommendationId;
509
+ if (n === null || !this.blockStates[n])
506
510
  throw new Error("[Guido] convertLegacyStrategy called without an active block");
507
- this.blockStates[r].legacyConversionLoading = !0;
511
+ this.blockStates[n].legacyConversionLoading = !0;
508
512
  try {
509
- const n = await u.migrateLegacyStrategy(t, e);
513
+ const r = await m.migrateLegacyStrategy(t, e);
510
514
  this.invalidateStrategies();
511
515
  try {
512
516
  await this.fetchStrategies();
513
- } catch (o) {
514
- console.error("[Guido] strategy listing refresh after conversion failed", o);
517
+ } catch (s) {
518
+ console.error("[Guido] strategy listing refresh after conversion failed", s);
515
519
  }
516
- const s = this.strategies.find((o) => String(o.strategy_id) === n), i = this.blockStates[r];
520
+ const o = this.strategies.find((s) => String(s.strategy_id) === r), i = this.blockStates[n];
517
521
  return i && (i.recommendationConfigs = {
518
522
  ...i.recommendationConfigs,
519
- strategyId: n,
523
+ strategyId: r,
520
524
  nodeConfigVersion: C,
521
- ...(s == null ? void 0 : s.size) !== void 0 ? { size: String(s.size) } : {}
522
- }), this.currentRecommendationId === r && this.configVersion++, n;
525
+ ...(o == null ? void 0 : o.size) !== void 0 ? { size: String(o.size) } : {}
526
+ }, i.configVersion++), this.currentRecommendationId === n && this.configVersion++, r;
523
527
  } finally {
524
- this.blockStates[r] && (this.blockStates[r].legacyConversionLoading = !1);
528
+ this.blockStates[n] && (this.blockStates[n].legacyConversionLoading = !1);
525
529
  }
526
530
  },
527
531
  /**
@@ -530,14 +534,14 @@ const Y = () => ({
530
534
  * the document never received.
531
535
  */
532
536
  revertLegacyConversion(t, e) {
533
- const r = this.blockStates[t];
534
- r && (r.recommendationConfigs = { ...r.recommendationConfigs, ...e }, this.currentRecommendationId === t && this.configVersion++);
537
+ const n = this.blockStates[t];
538
+ n && (n.recommendationConfigs = { ...n.recommendationConfigs, ...e }, n.configVersion++, this.currentRecommendationId === t && this.configVersion++);
535
539
  },
536
540
  removeStrategy() {
537
541
  this.patchCurrentBlockConfig({
538
542
  strategyId: "",
539
543
  strategy: "",
540
- size: j.size,
544
+ size: T.size,
541
545
  nodeConfigVersion: C
542
546
  });
543
547
  },
@@ -546,26 +550,26 @@ const Y = () => ({
546
550
  // ====================================================================
547
551
  async fetchRecommendationCreateData() {
548
552
  if (!this.activePredictiveAlgorithms.length) {
549
- if (S) {
550
- await S;
553
+ if (p) {
554
+ await p;
551
555
  return;
552
556
  }
553
- S = (async () => {
557
+ p = (async () => {
554
558
  const {
555
559
  activePredictiveAlgorithms: t,
556
560
  languages: e,
557
- currencies: r
558
- } = await u.fetchRecommendationCreateData();
561
+ currencies: n
562
+ } = await m.fetchRecommendationCreateData();
559
563
  if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
560
- const n = this.blockStates[this.currentRecommendationId];
561
- n.filterStatus = !!n.recommendationConfigs.filters.length;
564
+ const r = this.blockStates[this.currentRecommendationId];
565
+ r.filterStatus = !!r.recommendationConfigs.filters.length;
562
566
  }
563
- this.currencyList = r;
567
+ this.currencyList = n;
564
568
  })();
565
569
  try {
566
- await S;
570
+ await p;
567
571
  } finally {
568
- S = null;
572
+ p = null;
569
573
  }
570
574
  }
571
575
  },
@@ -576,7 +580,7 @@ const Y = () => ({
576
580
  return;
577
581
  }
578
582
  y = (async () => {
579
- const t = await u.fetchRecommendationFilters();
583
+ const t = await m.fetchRecommendationFilters();
580
584
  this.filterList = t;
581
585
  })();
582
586
  try {
@@ -597,59 +601,59 @@ const Y = () => ({
597
601
  deleteFilterGroup(t) {
598
602
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
599
603
  return;
600
- const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.filter((i) => i.filterGroup !== t), n = [...new Set(r.map((i) => i.filterGroup))].sort((i, o) => i - o), s = new Map(n.map((i, o) => [i, o + 1]));
601
- e.recommendationConfigs.filters = r.map((i) => ({
604
+ const e = this.blockStates[this.currentRecommendationId], n = e.recommendationConfigs.filters.filter((i) => i.filterGroup !== t), r = [...new Set(n.map((i) => i.filterGroup))].sort((i, s) => i - s), o = new Map(r.map((i, s) => [i, s + 1]));
605
+ e.recommendationConfigs.filters = n.map((i) => ({
602
606
  ...i,
603
- filterGroup: s.get(i.filterGroup) ?? i.filterGroup
607
+ filterGroup: o.get(i.filterGroup) ?? i.filterGroup
604
608
  }));
605
609
  },
606
610
  updateFilter(t) {
607
611
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
608
612
  return;
609
- const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
610
- if (r !== -1) {
611
- const n = [...e.recommendationConfigs.filters];
612
- n[r] = {
613
+ const e = this.blockStates[this.currentRecommendationId], n = e.recommendationConfigs.filters.findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
614
+ if (n !== -1) {
615
+ const r = [...e.recommendationConfigs.filters];
616
+ r[n] = {
613
617
  ...t,
614
- isValid: J(t)
615
- }, e.recommendationConfigs.filters = n;
618
+ isValid: H(t)
619
+ }, e.recommendationConfigs.filters = r;
616
620
  }
617
621
  },
618
622
  deleteFilter(t) {
619
623
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
620
624
  return;
621
- const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters].findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
622
- if (r !== -1) {
623
- let n = [...e.recommendationConfigs.filters];
624
- if (n.splice(r, 1), n.some((i) => i.filterGroup === t.filterGroup)) {
625
+ const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters].findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
626
+ if (n !== -1) {
627
+ let r = [...e.recommendationConfigs.filters];
628
+ if (r.splice(n, 1), r.some((i) => i.filterGroup === t.filterGroup)) {
625
629
  let i = 1;
626
- n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
630
+ r = r.map((s) => s.filterGroup === t.filterGroup ? { ...s, filterNumber: i++ } : s);
627
631
  } else {
628
- const i = [...new Set(n.map((a) => a.filterGroup))].sort((a, f) => a - f), o = new Map(i.map((a, f) => [a, f + 1]));
629
- n = n.map((a) => ({
632
+ const i = [...new Set(r.map((a) => a.filterGroup))].sort((a, d) => a - d), s = new Map(i.map((a, d) => [a, d + 1]));
633
+ r = r.map((a) => ({
630
634
  ...a,
631
- filterGroup: o.get(a.filterGroup) ?? a.filterGroup
635
+ filterGroup: s.get(a.filterGroup) ?? a.filterGroup
632
636
  }));
633
637
  }
634
- e.recommendationConfigs.filters = n;
638
+ e.recommendationConfigs.filters = r;
635
639
  }
636
640
  },
637
641
  addFilter(t) {
638
642
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
639
643
  return;
640
- const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters], s = r.filter(
641
- (o) => o.filterGroup === t.filterGroup
642
- ).length + 1, i = r.findLastIndex((o) => o.filterGroup === t.filterGroup);
643
- i !== -1 ? r.splice(i + 1, 0, {
644
+ const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters], o = n.filter(
645
+ (s) => s.filterGroup === t.filterGroup
646
+ ).length + 1, i = n.findLastIndex((s) => s.filterGroup === t.filterGroup);
647
+ i !== -1 ? n.splice(i + 1, 0, {
644
648
  ...t,
645
- filterNumber: s
646
- }) : r.push({
649
+ filterNumber: o
650
+ }) : n.push({
647
651
  ...t,
648
- filterNumber: s
649
- }), e.recommendationConfigs.filters = r;
652
+ filterNumber: o
653
+ }), e.recommendationConfigs.filters = n;
650
654
  },
651
655
  generateFilterQuery() {
652
- return G(this.recommendationConfigs.filters);
656
+ return P(this.recommendationConfigs.filters);
653
657
  },
654
658
  /**
655
659
  * Validation-only check invoked at save-CTA time. Defined as an action
@@ -657,70 +661,77 @@ const Y = () => ({
657
661
  * every block's recommendationConfigs across user edits.
658
662
  */
659
663
  hasInvalidBlock() {
660
- return Object.values(this.blockStates).some((t) => !W(t.recommendationConfigs, this));
664
+ return Object.values(this.blockStates).some((t) => !Q(t.recommendationConfigs, this));
661
665
  },
662
666
  /**
663
667
  * Which required fields are missing across the design's blocks, so the save
664
668
  * toaster can name the cause instead of always showing the generic message.
665
669
  */
666
670
  invalidBlockFields() {
667
- return Object.values(this.blockStates).flatMap((t) => Q(t.recommendationConfigs, this));
671
+ return Object.values(this.blockStates).flatMap((t) => J(t.recommendationConfigs, this));
668
672
  },
669
673
  // ====================================================================
670
674
  // Per-Block Product Fetching
671
675
  // ====================================================================
672
676
  async fetchRecommendationProducts() {
673
- if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
677
+ this.currentRecommendationId !== null && await this.fetchRecommendationProductsForBlock(this.currentRecommendationId);
678
+ },
679
+ /**
680
+ * Fetches one block's products whether or not it is selected: the panel teardown and the
681
+ * strategy drawer refresh the block they were handed after the user may have moved on.
682
+ */
683
+ async fetchRecommendationProductsForBlock(t) {
684
+ var i;
685
+ const e = this.blockStates[t];
686
+ if (!e)
674
687
  return;
675
- const t = [
676
- this.currentRecommendationId,
677
- this.configVersion,
678
- b
679
- ].join(":");
680
- if (p && I === t) {
681
- await p;
688
+ const n = [e.configVersion, e.adoptedSizeVersion, b].join(":"), r = I.get(t);
689
+ if ((r == null ? void 0 : r.key) === n) {
690
+ await r.promise;
682
691
  return;
683
692
  }
684
- I = t, p = this._doFetchProducts();
693
+ const o = this._doFetchProducts(t);
694
+ I.set(t, { key: n, promise: o });
685
695
  try {
686
- await p;
696
+ await o;
687
697
  } finally {
688
- I === t && (p = null, I = "");
698
+ ((i = I.get(t)) == null ? void 0 : i.promise) === o && I.delete(t);
689
699
  }
690
700
  },
691
- async _doFetchProducts() {
692
- var h;
693
- const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = R();
694
- if (r.strategyId && n.isFeatureEnabled("reusableRecommendationStrategy")) {
695
- await this._doFetchStrategyProducts(t);
701
+ // Captures the block ID up front so the write lands on it even if the user switches.
702
+ async _doFetchProducts(t) {
703
+ var S;
704
+ const e = t ?? this.currentRecommendationId, n = this.blockStates[e], { recommendationConfigs: r } = n, o = R();
705
+ if (r.strategyId && o.isFeatureEnabled("reusableRecommendationStrategy")) {
706
+ await this._doFetchStrategyProducts(e);
696
707
  return;
697
708
  }
698
- const s = (m.get(t) ?? 0) + 1;
699
- m.set(t, s);
700
- const i = parseInt(r.size) || 6;
709
+ const i = (u.get(e) ?? 0) + 1;
710
+ u.set(e, i);
711
+ const s = parseInt(r.size) || 6;
701
712
  if (!r.strategy) {
702
- this._setBlockProducts(t, [], i);
713
+ this._setBlockProducts(e, [], s);
703
714
  return;
704
715
  }
705
- const o = r.filters.filter((g) => g.isValid), a = G(o), f = ((h = w().find((g) => g.key === r.strategy)) == null ? void 0 : h.path) || "", c = {
716
+ const a = r.filters.filter((h) => h.isValid), d = P(a), f = ((S = F().find((h) => h.key === r.strategy)) == null ? void 0 : S.path) || "", c = {
706
717
  locale: r.language,
707
718
  currency: r.currencySettings.value,
708
- partnerName: n.partnerName,
719
+ partnerName: o.partnerName,
709
720
  size: r.size,
710
721
  details: !0,
711
- campaignId: n.variationId
722
+ campaignId: o.variationId
712
723
  };
713
- r.strategy === "manualMerchandising" ? c.productId = H(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(
724
+ r.strategy === "manualMerchandising" ? c.productId = K(r.productIds) : r.strategy === "similarViewed" && (c.productId = "{itemId}"), r.strategy === "userBased" && (c.userId = "{user_id}"), d && (c.filter = d), r.shuffleProducts && (c.shuffle = !0), Object.assign(
714
725
  c,
715
- K(n.partnerName, r.strategy)
726
+ q(o.partnerName, r.strategy)
716
727
  );
717
- let d;
728
+ let g;
718
729
  try {
719
- d = await u.fetchRecommendationProducts(f, c);
730
+ g = await m.fetchRecommendationProducts(f, c);
720
731
  } catch {
721
- d = [];
732
+ g = [];
722
733
  }
723
- m.get(t) === s && this._setBlockProducts(t, d, i);
734
+ u.get(e) === i && this._setBlockProducts(e, g, s);
724
735
  },
725
736
  /**
726
737
  * Block-scoped counterpart of `fetchRecommendationProducts`, which only serves the selected block:
@@ -728,8 +739,8 @@ const Y = () => ({
728
739
  * @returns whether real products arrived
729
740
  */
730
741
  async fetchStrategyProductsForBlock(t, e = {}) {
731
- var r;
732
- return (r = this.blockStates[t]) != null && r.recommendationConfigs.strategyId ? this._doFetchStrategyProducts(t, e) : !1;
742
+ var n;
743
+ return (n = this.blockStates[t]) != null && n.recommendationConfigs.strategyId ? this._doFetchStrategyProducts(t, e) : !1;
733
744
  },
734
745
  /**
735
746
  * Reloads a block's products and adopts its strategy's current size, which may have
@@ -737,8 +748,8 @@ const Y = () => ({
737
748
  * @returns whether a fresh listing holds the strategy and its products arrived
738
749
  */
739
750
  async refreshStrategyBlock(t) {
740
- var s;
741
- const e = (s = this.blockStates[t]) == null ? void 0 : s.recommendationConfigs.strategyId;
751
+ var o;
752
+ const e = (o = this.blockStates[t]) == null ? void 0 : o.recommendationConfigs.strategyId;
742
753
  if (!e)
743
754
  return !1;
744
755
  try {
@@ -746,50 +757,53 @@ const Y = () => ({
746
757
  } catch {
747
758
  return !1;
748
759
  }
749
- const r = this.strategiesFetched ? this.strategies.find((i) => String(i.strategy_id) === e) : void 0;
750
- if (!r || !await this.fetchStrategyProductsForBlock(t, { keepOnFailure: !0 }))
760
+ const n = this.strategiesFetched ? this.strategies.find((i) => String(i.strategy_id) === e) : void 0;
761
+ if (!n || !await this.fetchStrategyProductsForBlock(t, { keepOnFailure: !0 }))
751
762
  return !1;
752
- const n = this.blockStates[t];
753
- return (n == null ? void 0 : n.recommendationConfigs.strategyId) !== e ? !1 : (r.size !== void 0 && (n.recommendationConfigs = {
754
- ...n.recommendationConfigs,
755
- size: String(r.size)
756
- }), !0);
763
+ const r = this.blockStates[t];
764
+ if ((r == null ? void 0 : r.recommendationConfigs.strategyId) !== e)
765
+ return !1;
766
+ if (n.size !== void 0) {
767
+ const i = String(n.size);
768
+ r.recommendationConfigs.size !== i && r.adoptedSizeVersion++, r.recommendationConfigs = { ...r.recommendationConfigs, size: i };
769
+ }
770
+ return !0;
757
771
  },
758
772
  _doFetchStrategyProducts(t, e = {}) {
759
- const r = (m.get(t) ?? 0) + 1;
760
- m.set(t, r);
761
- const n = this._loadStrategyProducts(t, r, e);
762
- return D.set(t, { token: r, outcome: n }), n;
763
- },
764
- async _loadStrategyProducts(t, e, { keepOnFailure: r = !1 }) {
765
- const { recommendationConfigs: n } = this.blockStates[t];
766
- let s = [], i = parseInt(n.size) || 6;
773
+ const n = (u.get(t) ?? 0) + 1;
774
+ u.set(t, n);
775
+ const r = this._loadStrategyProducts(t, n, e);
776
+ return _.set(t, { token: n, outcome: r }), r;
777
+ },
778
+ async _loadStrategyProducts(t, e, { keepOnFailure: n = !1 }) {
779
+ const { recommendationConfigs: r } = this.blockStates[t];
780
+ let o = [], i = parseInt(r.size) || 6;
767
781
  try {
768
782
  await this.fetchStrategies();
769
- const o = this.strategies.find(
770
- (a) => String(a.strategy_id) === n.strategyId
783
+ const s = this.strategies.find(
784
+ (a) => String(a.strategy_id) === r.strategyId
771
785
  );
772
- if (o) {
773
- i = parseInt(String(o.size ?? "")) || i;
774
- 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), g = (d === -1 ? "" : c.slice(d + 1)).split("&").filter((F) => F && !F.startsWith("user_id=")), v = g.length ? `${h}?${g.join("&")}` : h;
775
- v && (s = await u.fetchRecommendationProductsByUrl(v));
786
+ if (s) {
787
+ i = parseInt(String(s.size ?? "")) || i;
788
+ const a = r.currencySettings.value, f = (await this.resolveStrategyUrlTemplate(s, a)).replaceAll("{locale}", r.language).replaceAll("{currency}", a), c = f.indexOf("?"), g = c === -1 ? f : f.slice(0, c), S = (c === -1 ? "" : f.slice(c + 1)).split("&").filter((v) => v && !v.startsWith("user_id=")), h = S.length ? `${g}?${S.join("&")}` : g;
789
+ h && (o = await m.fetchRecommendationProductsByUrl(h));
776
790
  }
777
791
  } catch {
778
- s = [];
792
+ o = [];
779
793
  }
780
- return m.get(t) !== e ? X(t) : !s.length && r ? !1 : (this._setBlockProducts(t, s, i), s.length > 0);
794
+ return u.get(t) !== e ? W(t) : !o.length && n ? !1 : (this._setBlockProducts(t, o, i), o.length > 0);
781
795
  },
782
- _setBlockProducts(t, e, r) {
796
+ _setBlockProducts(t, e, n) {
783
797
  if (!this.blockStates[t])
784
798
  return;
785
- const n = e.length > 0 ? e : P(r);
799
+ const r = e.length > 0 ? e : w(n);
786
800
  this.blockStates[t].recommendationProducts = [
787
- ...n.slice(0, r),
788
- ...P(Math.max(0, r - n.length))
801
+ ...r.slice(0, n),
802
+ ...w(Math.max(0, n - r.length))
789
803
  ];
790
804
  }
791
805
  }
792
806
  });
793
807
  export {
794
- St as useRecommendationExtensionStore
808
+ ht as useRecommendationExtensionStore
795
809
  };