@useinsider/guido 3.20.0-beta.6e5144c → 3.20.0-beta.af394f2

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,13 +1,13 @@
1
- import { useToaster as D } from "../../../../composables/useToaster.js";
1
+ import { useToaster as _ } from "../../../../composables/useToaster.js";
2
2
  import { useTranslations as L } from "../../../../composables/useTranslations.js";
3
- import { getRecommendationFeedSourceMaps as F, strategyEditPath as U, strategyCreatePath as N, getOperatorOptions as M, PriceAttributes as B } from "../../../../enums/extensions/recommendationBlock.js";
4
- import { ToasterTypeOptions as E } from "../../../../enums/toaster.js";
3
+ import { getRecommendationFeedSourceMaps as F, strategyEditPath as U, strategyCreatePath as N, getOperatorOptions as M, PriceAttributes as E } from "../../../../enums/extensions/recommendationBlock.js";
4
+ import { ToasterTypeOptions as B } from "../../../../enums/toaster.js";
5
5
  import { useRecommendationApi as z } from "../../../../services/recommendationApi.js";
6
- import { useConfigStore as C } from "../../../../stores/config.js";
6
+ import { useConfigStore as R } from "../../../../stores/config.js";
7
7
  import { defineStore as A } from "pinia";
8
8
  import "../constants/selectors.js";
9
9
  import { DEFAULT_MOBILE_CARDS_IN_ROW as O, DEFAULT_CARDS_IN_ROW as x } from "../constants/layout.js";
10
- import { CURRENT_CONFIG_VERSION as v, DEFAULT_NODE_CONFIG as V, EXCLUDED_ALGORITHM_IDS as T } from "../constants/defaultConfig.js";
10
+ import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as T, EXCLUDED_ALGORITHM_IDS as V } from "../constants/defaultConfig.js";
11
11
  import { getDefaultProducts as w } from "../templates/utils.js";
12
12
  import { generateCompleteFilterQuery as P } from "../utils/filterUtil.js";
13
13
  import { isLegacyStrategyConfig as j } from "../utils/legacyStrategyMigration.js";
@@ -16,10 +16,10 @@ import { sanitizeProductIds as q } from "../utils/productIds.js";
16
16
  import { isFilterValid as K } from "../validation/filterSchema.js";
17
17
  import { getInvalidFields as H, isConfigValid as J } from "../validation/requiredFields.js";
18
18
  const m = z();
19
- let p = null, y = null, b = null, k = "", R = null, I = 0;
20
- const h = /* @__PURE__ */ new Map();
19
+ let S = null, p = null, y = null, I = "", k = null, b = 0;
20
+ const g = /* @__PURE__ */ new Map();
21
21
  let l = null;
22
- function _() {
22
+ function D() {
23
23
  return {
24
24
  cardsInRow: x,
25
25
  currencySettings: {
@@ -45,9 +45,9 @@ 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: C().isFeatureEnabled("reusableRecommendationStrategy") ? "" : "mostPopular",
48
+ strategy: R().isFeatureEnabled("reusableRecommendationStrategy") ? "" : "mostPopular",
49
49
  strategyId: "",
50
- nodeConfigVersion: v,
50
+ nodeConfigVersion: C,
51
51
  textTrimming: !0,
52
52
  unresponsive: !1,
53
53
  size: "6",
@@ -58,7 +58,7 @@ function _() {
58
58
  }
59
59
  function G() {
60
60
  return {
61
- recommendationConfigs: _(),
61
+ recommendationConfigs: D(),
62
62
  recommendationProducts: [],
63
63
  filterStatus: !1,
64
64
  filterSelectionDrawerStatus: !1,
@@ -69,8 +69,7 @@ function G() {
69
69
  isInitialized: !1,
70
70
  filterSnapshot: null,
71
71
  syncedConfigFingerprint: null,
72
- legacyConversionLoading: !1,
73
- configVersion: 0
72
+ legacyConversionLoading: !1
74
73
  };
75
74
  }
76
75
  const Q = () => ({
@@ -99,7 +98,7 @@ const Q = () => ({
99
98
  * This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
100
99
  */
101
100
  recommendationConfigs(t) {
102
- 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();
103
102
  },
104
103
  /**
105
104
  * Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
@@ -120,7 +119,7 @@ const Q = () => ({
120
119
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
121
120
  },
122
121
  isLegacyStrategyBlock() {
123
- return C().isFeatureEnabled("reusableRecommendationStrategy") && j(this.recommendationConfigs);
122
+ return R().isFeatureEnabled("reusableRecommendationStrategy") && j(this.recommendationConfigs);
124
123
  },
125
124
  legacyConversionLoading(t) {
126
125
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
@@ -130,7 +129,7 @@ const Q = () => ({
130
129
  },
131
130
  assignedStrategy(t) {
132
131
  const { strategyId: e } = this.recommendationConfigs;
133
- return e ? t.strategies.find((n) => String(n.strategy_id) === e) ?? null : null;
132
+ return e ? t.strategies.find((r) => String(r.strategy_id) === e) ?? null : null;
134
133
  },
135
134
  /**
136
135
  * Proxy getter: delegates to blockStates[currentRecommendationId].filterStatus
@@ -160,19 +159,19 @@ const Q = () => ({
160
159
  },
161
160
  getUniqueFilterGroups() {
162
161
  const { filters: t } = this.recommendationConfigs;
163
- return [...new Set(t.map((e) => e.filterGroup))].sort((e, n) => e - n);
162
+ return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
164
163
  },
165
164
  getActivePredictiveAlgorithms: (t) => {
166
- const e = F(), n = [];
167
- return t.activePredictiveAlgorithms.filter((r) => !T.includes(r)).forEach((r) => {
168
- n.push(...e.filter((s) => s.id === r));
169
- }), n.map((r) => ({
170
- text: r.name,
171
- value: r.key
165
+ const e = F(), r = [];
166
+ return t.activePredictiveAlgorithms.filter((n) => !V.includes(n)).forEach((n) => {
167
+ r.push(...e.filter((s) => s.id === n));
168
+ }), r.map((n) => ({
169
+ text: n.name,
170
+ value: n.key
172
171
  }));
173
172
  },
174
- getLanguages: (t) => Object.entries(t.languages).map(([e, n]) => ({
175
- text: n,
173
+ getLanguages: (t) => Object.entries(t.languages).map(([e, r]) => ({
174
+ text: r,
176
175
  value: e
177
176
  })),
178
177
  getCurrencySymbolList: (t) => t.currencyList.map((e) => ({
@@ -182,7 +181,7 @@ const Q = () => ({
182
181
  getFilterList() {
183
182
  return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
184
183
  let e;
185
- return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : B.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
184
+ return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : E.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
186
185
  text: t.displayName,
187
186
  value: e,
188
187
  type: t.attributeType
@@ -214,13 +213,13 @@ const Q = () => ({
214
213
  removeBlockState(t) {
215
214
  const e = t.toString();
216
215
  if (this.recommendationCampaignUrls[e]) {
217
- const r = { ...this.recommendationCampaignUrls };
218
- delete r[e], this.recommendationCampaignUrls = r;
216
+ const n = { ...this.recommendationCampaignUrls };
217
+ delete n[e], this.recommendationCampaignUrls = n;
219
218
  }
220
- const n = { ...this.blockStates };
221
- if (delete n[t], this.blockStates = n, this.currentRecommendationId === t) {
222
- const r = Object.keys(this.blockStates).map(Number);
223
- this.currentRecommendationId = r.length > 0 ? r[0] : null;
219
+ const r = { ...this.blockStates };
220
+ if (delete r[t], this.blockStates = r, this.currentRecommendationId === t) {
221
+ const n = Object.keys(this.blockStates).map(Number);
222
+ this.currentRecommendationId = n.length > 0 ? n[0] : null;
224
223
  }
225
224
  },
226
225
  /**
@@ -232,15 +231,15 @@ const Q = () => ({
232
231
  * (SD-149916).
233
232
  */
234
233
  cloneBlockState(t, e) {
235
- const n = this.blockStates[t];
236
- if (n) {
237
- const o = structuredClone(n);
238
- o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId && C().isFeatureEnabled("reusableRecommendationStrategy") && (o.isInitialized = !1, o.syncedConfigFingerprint = null), this.blockStates = {
234
+ const r = this.blockStates[t];
235
+ if (r) {
236
+ const o = structuredClone(r);
237
+ o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (o.isInitialized = !1, o.syncedConfigFingerprint = null), this.blockStates = {
239
238
  ...this.blockStates,
240
239
  [e]: o
241
240
  };
242
241
  }
243
- const r = t.toString(), s = e.toString(), i = this.recommendationCampaignUrls[r];
242
+ const n = t.toString(), s = e.toString(), i = this.recommendationCampaignUrls[n];
244
243
  i && (this.recommendationCampaignUrls = {
245
244
  ...this.recommendationCampaignUrls,
246
245
  [s]: i
@@ -268,14 +267,14 @@ const Q = () => ({
268
267
  * `isInitialized`) alone.
269
268
  */
270
269
  seedBlockUrlConfig(t, e) {
271
- const n = (o, a) => o === "." || o === "," || o === " " ? o : a, r = {
270
+ const r = (o, a) => o === "." || o === "," || o === " " ? o : a, n = {
272
271
  name: e.currencyCode,
273
272
  value: e.currencyCode,
274
273
  symbol: e.currencySymbol,
275
274
  alignment: e.currencyAlignment === "before" ? "0" : "1",
276
275
  decimalCount: String(e.currencyDecimalCount),
277
- decimalSeparator: n(e.currencyDecimalSeparator, ","),
278
- thousandSeparator: n(e.currencyThousandSeparator, ".")
276
+ decimalSeparator: r(e.currencyDecimalSeparator, ","),
277
+ thousandSeparator: r(e.currencyThousandSeparator, ".")
279
278
  }, s = !this.blockStates[t], i = s ? G() : this.blockStates[t];
280
279
  i.recommendationConfigs = {
281
280
  ...i.recommendationConfigs,
@@ -286,7 +285,7 @@ const Q = () => ({
286
285
  productIds: e.productIds,
287
286
  filters: e.filters,
288
287
  shuffleProducts: e.shuffleProducts,
289
- currencySettings: r
288
+ currencySettings: n
290
289
  }, s && (this.blockStates = {
291
290
  ...this.blockStates,
292
291
  [t]: i
@@ -299,27 +298,27 @@ const Q = () => ({
299
298
  patchCurrentBlockConfig(t, e = {}) {
300
299
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
301
300
  return;
302
- const n = this.blockStates[this.currentRecommendationId];
303
- n.recommendationConfigs = {
304
- ...n.recommendationConfigs,
301
+ const r = this.blockStates[this.currentRecommendationId];
302
+ r.recommendationConfigs = {
303
+ ...r.recommendationConfigs,
305
304
  ...t,
306
305
  currencySettings: {
307
- ...n.recommendationConfigs.currencySettings,
306
+ ...r.recommendationConfigs.currencySettings,
308
307
  ...t.currencySettings || {}
309
308
  }
310
309
  };
311
- const { triggerRefetch: r = !0 } = e;
312
- r && (n.configVersion++, this.configVersion++);
310
+ const { triggerRefetch: n = !0 } = e;
311
+ n && this.configVersion++;
313
312
  },
314
313
  /**
315
314
  * Creates a filter with the first available attribute and operator pre-selected.
316
315
  */
317
316
  createDefaultFilter(t, e) {
318
- const [n] = this.getFilterList, [r] = M(n == null ? void 0 : n.type);
317
+ const [r] = this.getFilterList, [n] = M(r == null ? void 0 : r.type);
319
318
  return {
320
319
  type: "standardFilter",
321
- attribute: (n == null ? void 0 : n.value) ?? "",
322
- operator: (r == null ? void 0 : r.value) ?? "",
320
+ attribute: (r == null ? void 0 : r.value) ?? "",
321
+ operator: (n == null ? void 0 : n.value) ?? "",
323
322
  innerGroupOperator: "*",
324
323
  outerGroupOperator: "*",
325
324
  filterNumber: e,
@@ -381,29 +380,29 @@ const Q = () => ({
381
380
  this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].removeStrategyModalStatus = !1);
382
381
  },
383
382
  async fetchStrategies() {
384
- for (; R; )
383
+ for (; k; )
385
384
  try {
386
- await R;
385
+ await k;
387
386
  } catch {
388
387
  }
389
388
  if (this.strategiesFetched)
390
389
  return;
391
- const t = I, e = (async () => {
390
+ const t = b, e = (async () => {
392
391
  this.strategiesLoading = !0;
393
392
  try {
394
- const n = await m.fetchRecommendationStrategies();
395
- if (t !== I)
393
+ const r = await m.fetchRecommendationStrategies();
394
+ if (t !== b)
396
395
  return;
397
- this.strategies = n, this.strategiesFetched = !0;
396
+ this.strategies = r, this.strategiesFetched = !0;
398
397
  } finally {
399
- this.strategiesLoading = !1, t === I && (this.strategiesSettled = !0);
398
+ this.strategiesLoading = !1, t === b && (this.strategiesSettled = !0);
400
399
  }
401
400
  })();
402
- R = e;
401
+ k = e;
403
402
  try {
404
403
  await e;
405
404
  } finally {
406
- R = null;
405
+ k = null;
407
406
  }
408
407
  },
409
408
  /**
@@ -417,7 +416,7 @@ const Q = () => ({
417
416
  }));
418
417
  },
419
418
  invalidateStrategies() {
420
- this.strategiesFetched = !1, this.strategiesSettled = !1, I += 1;
419
+ this.strategiesFetched = !1, this.strategiesSettled = !1, b += 1;
421
420
  },
422
421
  /**
423
422
  * Opens a Smart Recommender strategy page in a new tab and refreshes the list every time
@@ -435,20 +434,20 @@ const Q = () => ({
435
434
  _armStrategyPageReturn(t) {
436
435
  const e = window.open(t, "_blank");
437
436
  if (!e)
438
- return D().showToaster({
439
- type: E.Error,
437
+ return _().showToaster({
438
+ type: B.Error,
440
439
  message: L()("discovery-strategy.error-description")
441
440
  }), !1;
442
441
  e.opener = null, l == null || l();
443
- let n = !1;
444
- const r = () => {
445
- document.hidden || n || (e != null && e.closed && (l == null || l()), n = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
442
+ let r = !1;
443
+ const n = () => {
444
+ document.hidden || r || (e != null && e.closed && (l == null || l()), r = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
446
445
  }).finally(() => {
447
- n = !1;
446
+ r = !1;
448
447
  }));
449
448
  };
450
- return document.addEventListener("visibilitychange", r), l = () => {
451
- document.removeEventListener("visibilitychange", r), l = null;
449
+ return document.addEventListener("visibilitychange", n), l = () => {
450
+ document.removeEventListener("visibilitychange", n), l = null;
452
451
  }, !0;
453
452
  },
454
453
  /**
@@ -482,13 +481,13 @@ const Q = () => ({
482
481
  return this._armStrategyPageReturn(U(t));
483
482
  },
484
483
  async resolveStrategyUrlTemplate(t, e) {
485
- const n = typeof t.updated_at == "string" ? t.updated_at : "", r = n ? `${t.strategy_id}:${n}:${e}` : "", s = r ? this.strategyUrlTemplates[r] : void 0;
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;
486
485
  if (s)
487
486
  return s;
488
487
  const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
489
- return r && i && (this.strategyUrlTemplates = {
488
+ return n && i && (this.strategyUrlTemplates = {
490
489
  ...this.strategyUrlTemplates,
491
- [r]: i
490
+ [n]: i
492
491
  }), i;
493
492
  },
494
493
  assignStrategy(t) {
@@ -498,27 +497,27 @@ const Q = () => ({
498
497
  });
499
498
  },
500
499
  async convertLegacyStrategy(t, e = { scope: "campaign" }) {
501
- const n = this.currentRecommendationId;
502
- if (n === null || !this.blockStates[n])
500
+ const r = this.currentRecommendationId;
501
+ if (r === null || !this.blockStates[r])
503
502
  throw new Error("[Guido] convertLegacyStrategy called without an active block");
504
- this.blockStates[n].legacyConversionLoading = !0;
503
+ this.blockStates[r].legacyConversionLoading = !0;
505
504
  try {
506
- const r = await m.migrateLegacyStrategy(t, e);
505
+ const n = await m.migrateLegacyStrategy(t, e);
507
506
  this.invalidateStrategies();
508
507
  try {
509
508
  await this.fetchStrategies();
510
509
  } catch (o) {
511
510
  console.error("[Guido] strategy listing refresh after conversion failed", o);
512
511
  }
513
- const s = this.strategies.find((o) => String(o.strategy_id) === r), i = this.blockStates[n];
512
+ const s = this.strategies.find((o) => String(o.strategy_id) === n), i = this.blockStates[r];
514
513
  return i && (i.recommendationConfigs = {
515
514
  ...i.recommendationConfigs,
516
- strategyId: r,
517
- nodeConfigVersion: v,
515
+ strategyId: n,
516
+ nodeConfigVersion: C,
518
517
  ...(s == null ? void 0 : s.size) !== void 0 ? { size: String(s.size) } : {}
519
- }, i.configVersion++), this.currentRecommendationId === n && this.configVersion++, r;
518
+ }), this.currentRecommendationId === r && this.configVersion++, n;
520
519
  } finally {
521
- this.blockStates[n] && (this.blockStates[n].legacyConversionLoading = !1);
520
+ this.blockStates[r] && (this.blockStates[r].legacyConversionLoading = !1);
522
521
  }
523
522
  },
524
523
  /**
@@ -527,15 +526,15 @@ const Q = () => ({
527
526
  * the document never received.
528
527
  */
529
528
  revertLegacyConversion(t, e) {
530
- const n = this.blockStates[t];
531
- n && (n.recommendationConfigs = { ...n.recommendationConfigs, ...e }, n.configVersion++, this.currentRecommendationId === t && this.configVersion++);
529
+ const r = this.blockStates[t];
530
+ r && (r.recommendationConfigs = { ...r.recommendationConfigs, ...e }, this.currentRecommendationId === t && this.configVersion++);
532
531
  },
533
532
  removeStrategy() {
534
533
  this.patchCurrentBlockConfig({
535
534
  strategyId: "",
536
535
  strategy: "",
537
- size: V.size,
538
- nodeConfigVersion: v
536
+ size: T.size,
537
+ nodeConfigVersion: C
539
538
  });
540
539
  },
541
540
  // ====================================================================
@@ -543,43 +542,43 @@ const Q = () => ({
543
542
  // ====================================================================
544
543
  async fetchRecommendationCreateData() {
545
544
  if (!this.activePredictiveAlgorithms.length) {
546
- if (p) {
547
- await p;
545
+ if (S) {
546
+ await S;
548
547
  return;
549
548
  }
550
- p = (async () => {
549
+ S = (async () => {
551
550
  const {
552
551
  activePredictiveAlgorithms: t,
553
552
  languages: e,
554
- currencies: n
553
+ currencies: r
555
554
  } = await m.fetchRecommendationCreateData();
556
555
  if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
557
- const r = this.blockStates[this.currentRecommendationId];
558
- r.filterStatus = !!r.recommendationConfigs.filters.length;
556
+ const n = this.blockStates[this.currentRecommendationId];
557
+ n.filterStatus = !!n.recommendationConfigs.filters.length;
559
558
  }
560
- this.currencyList = n;
559
+ this.currencyList = r;
561
560
  })();
562
561
  try {
563
- await p;
562
+ await S;
564
563
  } finally {
565
- p = null;
564
+ S = null;
566
565
  }
567
566
  }
568
567
  },
569
568
  async fetchRecommendationFilters() {
570
569
  if (!Object.keys(this.filterList).length) {
571
- if (y) {
572
- await y;
570
+ if (p) {
571
+ await p;
573
572
  return;
574
573
  }
575
- y = (async () => {
574
+ p = (async () => {
576
575
  const t = await m.fetchRecommendationFilters();
577
576
  this.filterList = t;
578
577
  })();
579
578
  try {
580
- await y;
579
+ await p;
581
580
  } finally {
582
- y = null;
581
+ p = null;
583
582
  }
584
583
  }
585
584
  },
@@ -594,8 +593,8 @@ const Q = () => ({
594
593
  deleteFilterGroup(t) {
595
594
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
596
595
  return;
597
- 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, o) => i - o), s = new Map(r.map((i, o) => [i, o + 1]));
598
- e.recommendationConfigs.filters = n.map((i) => ({
596
+ 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]));
597
+ e.recommendationConfigs.filters = r.map((i) => ({
599
598
  ...i,
600
599
  filterGroup: s.get(i.filterGroup) ?? i.filterGroup
601
600
  }));
@@ -603,47 +602,47 @@ const Q = () => ({
603
602
  updateFilter(t) {
604
603
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
605
604
  return;
606
- const e = this.blockStates[this.currentRecommendationId], n = e.recommendationConfigs.filters.findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
607
- if (n !== -1) {
608
- const r = [...e.recommendationConfigs.filters];
609
- r[n] = {
605
+ const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
606
+ if (r !== -1) {
607
+ const n = [...e.recommendationConfigs.filters];
608
+ n[r] = {
610
609
  ...t,
611
610
  isValid: K(t)
612
- }, e.recommendationConfigs.filters = r;
611
+ }, e.recommendationConfigs.filters = n;
613
612
  }
614
613
  },
615
614
  deleteFilter(t) {
616
615
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
617
616
  return;
618
- const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters].findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
619
- if (n !== -1) {
620
- let r = [...e.recommendationConfigs.filters];
621
- if (r.splice(n, 1), r.some((i) => i.filterGroup === t.filterGroup)) {
617
+ const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters].findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
618
+ if (r !== -1) {
619
+ let n = [...e.recommendationConfigs.filters];
620
+ if (n.splice(r, 1), n.some((i) => i.filterGroup === t.filterGroup)) {
622
621
  let i = 1;
623
- r = r.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
622
+ n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
624
623
  } else {
625
- const i = [...new Set(r.map((a) => a.filterGroup))].sort((a, c) => a - c), o = new Map(i.map((a, c) => [a, c + 1]));
626
- r = r.map((a) => ({
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]));
625
+ n = n.map((a) => ({
627
626
  ...a,
628
627
  filterGroup: o.get(a.filterGroup) ?? a.filterGroup
629
628
  }));
630
629
  }
631
- e.recommendationConfigs.filters = r;
630
+ e.recommendationConfigs.filters = n;
632
631
  }
633
632
  },
634
633
  addFilter(t) {
635
634
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
636
635
  return;
637
- const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters], s = n.filter(
636
+ const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters], s = r.filter(
638
637
  (o) => o.filterGroup === t.filterGroup
639
- ).length + 1, i = n.findLastIndex((o) => o.filterGroup === t.filterGroup);
640
- i !== -1 ? n.splice(i + 1, 0, {
638
+ ).length + 1, i = r.findLastIndex((o) => o.filterGroup === t.filterGroup);
639
+ i !== -1 ? r.splice(i + 1, 0, {
641
640
  ...t,
642
641
  filterNumber: s
643
- }) : n.push({
642
+ }) : r.push({
644
643
  ...t,
645
644
  filterNumber: s
646
- }), e.recommendationConfigs.filters = n;
645
+ }), e.recommendationConfigs.filters = r;
647
646
  },
648
647
  generateFilterQuery() {
649
648
  return P(this.recommendationConfigs.filters);
@@ -672,66 +671,52 @@ const Q = () => ({
672
671
  const t = [
673
672
  this.currentRecommendationId,
674
673
  this.configVersion,
675
- I
674
+ b
676
675
  ].join(":");
677
- if (b && k === t) {
678
- await b;
676
+ if (y && I === t) {
677
+ await y;
679
678
  return;
680
679
  }
681
- k = t, b = this._doFetchProducts();
680
+ I = t, y = this._doFetchProducts();
682
681
  try {
683
- await b;
682
+ await y;
684
683
  } finally {
685
- k === t && (b = null, k = "");
686
- }
687
- },
688
- /**
689
- * Block-scoped counterpart of `fetchRecommendationProducts`: the panel teardown has to
690
- * refresh the block that was edited even after the store selected another one.
691
- */
692
- async fetchRecommendationProductsForBlock(t) {
693
- if (this.blockStates[t]) {
694
- if (t === this.currentRecommendationId) {
695
- await this.fetchRecommendationProducts();
696
- return;
697
- }
698
- await this._doFetchProducts(t);
684
+ I === t && (y = null, I = "");
699
685
  }
700
686
  },
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, s = C();
705
- if (r.strategyId && s.isFeatureEnabled("reusableRecommendationStrategy")) {
706
- await this._doFetchStrategyProducts(e);
687
+ async _doFetchProducts() {
688
+ var h;
689
+ const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = R();
690
+ if (r.strategyId && n.isFeatureEnabled("reusableRecommendationStrategy")) {
691
+ await this._doFetchStrategyProducts(t);
707
692
  return;
708
693
  }
709
- const i = (h.get(e) ?? 0) + 1;
710
- h.set(e, i);
711
- const o = parseInt(r.size) || 6;
694
+ const s = (g.get(t) ?? 0) + 1;
695
+ g.set(t, s);
696
+ const i = parseInt(r.size) || 6;
712
697
  if (!r.strategy) {
713
- this._setBlockProducts(e, [], o);
698
+ this._setBlockProducts(t, [], i);
714
699
  return;
715
700
  }
716
- const a = r.filters.filter((g) => g.isValid), c = P(a), u = ((S = F().find((g) => g.key === r.strategy)) == null ? void 0 : S.path) || "", d = {
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 = {
717
702
  locale: r.language,
718
703
  currency: r.currencySettings.value,
719
- partnerName: s.partnerName,
704
+ partnerName: n.partnerName,
720
705
  size: r.size,
721
706
  details: !0,
722
- campaignId: s.variationId
707
+ campaignId: n.variationId
723
708
  };
724
- r.strategy === "manualMerchandising" ? d.productId = q(r.productIds) : r.strategy === "similarViewed" && (d.productId = "{itemId}"), r.strategy === "userBased" && (d.userId = "{user_id}"), c && (d.filter = c), r.shuffleProducts && (d.shuffle = !0), Object.assign(
725
- d,
726
- $(s.partnerName, r.strategy)
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(
710
+ c,
711
+ $(n.partnerName, r.strategy)
727
712
  );
728
- let f;
713
+ let u;
729
714
  try {
730
- f = await m.fetchRecommendationProducts(u, d);
715
+ u = await m.fetchRecommendationProducts(d, c);
731
716
  } catch {
732
- f = [];
717
+ u = [];
733
718
  }
734
- h.get(e) === i && this._setBlockProducts(e, f, o);
719
+ g.get(t) === s && this._setBlockProducts(t, u, i);
735
720
  },
736
721
  /**
737
722
  * Block-scoped counterpart of `fetchRecommendationProducts`, which only ever serves the
@@ -743,32 +728,32 @@ const Q = () => ({
743
728
  (e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId && await this._doFetchStrategyProducts(t);
744
729
  },
745
730
  async _doFetchStrategyProducts(t) {
746
- const e = (h.get(t) ?? 0) + 1;
747
- h.set(t, e);
748
- const { recommendationConfigs: n } = this.blockStates[t];
749
- let r = [], s = parseInt(n.size) || 6;
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;
750
735
  try {
751
736
  await this.fetchStrategies();
752
737
  const i = this.strategies.find(
753
- (o) => String(o.strategy_id) === n.strategyId
738
+ (o) => String(o.strategy_id) === r.strategyId
754
739
  );
755
740
  if (i) {
756
741
  s = parseInt(String(i.size ?? "")) || s;
757
- const o = n.currencySettings.value, c = (await this.resolveStrategyUrlTemplate(i, o)).replaceAll("{locale}", n.language).replaceAll("{currency}", o), u = c.indexOf("?"), d = u === -1 ? c : c.slice(0, u), f = (u === -1 ? "" : c.slice(u + 1)).split("&").filter((g) => g && !g.startsWith("user_id=")), S = f.length ? `${d}?${f.join("&")}` : d;
758
- S && (r = await m.fetchRecommendationProductsByUrl(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));
759
744
  }
760
745
  } catch {
761
- r = [];
746
+ n = [];
762
747
  }
763
- h.get(t) === e && this._setBlockProducts(t, r, s);
748
+ g.get(t) === e && this._setBlockProducts(t, n, s);
764
749
  },
765
- _setBlockProducts(t, e, n) {
750
+ _setBlockProducts(t, e, r) {
766
751
  if (!this.blockStates[t])
767
752
  return;
768
- const r = e.length > 0 ? e : w(n);
753
+ const n = e.length > 0 ? e : w(r);
769
754
  this.blockStates[t].recommendationProducts = [
770
- ...r.slice(0, n),
771
- ...w(Math.max(0, n - r.length))
755
+ ...n.slice(0, r),
756
+ ...w(Math.max(0, r - n.length))
772
757
  ];
773
758
  }
774
759
  }