@useinsider/guido 3.20.0-beta.af394f2 → 3.20.0-beta.d753259

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