@useinsider/guido 3.20.0 → 3.20.1-beta.04cd240

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.
Files changed (78) hide show
  1. package/dist/composables/useLegacyStrategyConversion.js +16 -16
  2. package/dist/composables/useStripo.js +11 -10
  3. package/dist/composables/useVersionHistoryApi.js +42 -37
  4. package/dist/config/compiler/itemsCompilerRules.js +21 -5
  5. package/dist/config/compiler/utils/itemsCompilerUtils.js +64 -17
  6. package/dist/config/migrator/itemsBlockMigrator.js +112 -108
  7. package/dist/extensions/Blocks/Items/block.js +76 -64
  8. package/dist/extensions/Blocks/Items/constants/cardWidth.js +20 -0
  9. package/dist/extensions/Blocks/Items/layouts/vertical.html.js +1 -1
  10. package/dist/extensions/Blocks/Recommendation/block.js +60 -49
  11. package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +163 -149
  12. package/dist/extensions/Blocks/Recommendation/controls/customAttribute/textTrim.js +1 -2
  13. package/dist/extensions/Blocks/Recommendation/controls/main/currency.js +102 -78
  14. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +313 -210
  15. package/dist/extensions/Blocks/Recommendation/controls/main/layoutOrientation.js +15 -13
  16. package/dist/extensions/Blocks/Recommendation/controls/main/pricePlacement.js +17 -12
  17. package/dist/extensions/Blocks/Recommendation/controls/main/productLayout.js +92 -84
  18. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +219 -193
  19. package/dist/extensions/Blocks/Recommendation/controls/mobileLayout/cssRules.js +23 -18
  20. package/dist/extensions/Blocks/Recommendation/controls/name/textTrim.js +1 -2
  21. package/dist/extensions/Blocks/Recommendation/controls/shared/textTrimCssRules.js +6 -6
  22. package/dist/extensions/Blocks/Recommendation/controls/spacing/index.js +12 -9
  23. package/dist/extensions/Blocks/Recommendation/extension.js +4 -2
  24. package/dist/extensions/Blocks/Recommendation/settingsPanel.js +4 -2
  25. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +240 -190
  26. package/dist/extensions/Blocks/Recommendation/utils/blockRefresh.js +19 -0
  27. package/dist/extensions/Blocks/Recommendation/utils/blockUrlConfig.js +25 -0
  28. package/dist/extensions/Blocks/Recommendation/utils/captureStyleTemplates.js +72 -70
  29. package/dist/extensions/Blocks/Recommendation/utils/compositionKeys.js +69 -60
  30. package/dist/extensions/Blocks/Recommendation/utils/followUpApply.js +34 -0
  31. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +73 -28
  32. package/dist/extensions/Blocks/Recommendation/utils/restoreRefresh.js +36 -0
  33. package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +39 -20
  34. package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +271 -192
  35. package/dist/package.json.js +1 -1
  36. package/dist/src/config/compiler/utils/itemsCompilerUtils.d.ts +10 -0
  37. package/dist/src/extensions/Blocks/Checkbox/controls/blockBackground/index.d.ts +1 -0
  38. package/dist/src/extensions/Blocks/CouponBlock/controls/index.d.ts +8 -0
  39. package/dist/src/extensions/Blocks/Items/block.d.ts +5 -0
  40. package/dist/src/extensions/Blocks/Items/constants/cardWidth.d.ts +12 -0
  41. package/dist/src/extensions/Blocks/Items/controls/index.d.ts +40 -0
  42. package/dist/src/extensions/Blocks/RadioButton/controls/blockBackground/index.d.ts +1 -0
  43. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +3 -0
  44. package/dist/src/extensions/Blocks/Recommendation/controls/blockBackground/index.d.ts +1 -0
  45. package/dist/src/extensions/Blocks/Recommendation/controls/button/index.d.ts +11 -0
  46. package/dist/src/extensions/Blocks/Recommendation/controls/cardComposition/index.d.ts +3 -0
  47. package/dist/src/extensions/Blocks/Recommendation/controls/customAttribute/index.d.ts +7 -0
  48. package/dist/src/extensions/Blocks/Recommendation/controls/image/index.d.ts +2 -0
  49. package/dist/src/extensions/Blocks/Recommendation/controls/main/currency.d.ts +3 -0
  50. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +22 -3
  51. package/dist/src/extensions/Blocks/Recommendation/controls/main/productLayout.d.ts +1 -18
  52. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +8 -0
  53. package/dist/src/extensions/Blocks/Recommendation/controls/mobileLayout/cssRules.d.ts +10 -6
  54. package/dist/src/extensions/Blocks/Recommendation/controls/name/index.d.ts +7 -0
  55. package/dist/src/extensions/Blocks/Recommendation/controls/oldPrice/index.d.ts +7 -0
  56. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusDiscount/index.d.ts +7 -0
  57. package/dist/src/extensions/Blocks/Recommendation/controls/omnibusPrice/index.d.ts +7 -0
  58. package/dist/src/extensions/Blocks/Recommendation/controls/price/index.d.ts +7 -0
  59. package/dist/src/extensions/Blocks/Recommendation/controls/shared/textTrimCssRules.d.ts +2 -3
  60. package/dist/src/extensions/Blocks/Recommendation/controls/spacing/index.d.ts +1 -1
  61. package/dist/src/extensions/Blocks/Recommendation/controls/title/index.d.ts +7 -0
  62. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +28 -6
  63. package/dist/src/extensions/Blocks/Recommendation/utils/blockRefresh.d.ts +19 -0
  64. package/dist/src/extensions/Blocks/Recommendation/utils/blockUrlConfig.d.ts +4 -0
  65. package/dist/src/extensions/Blocks/Recommendation/utils/compositionKeys.d.ts +4 -0
  66. package/dist/src/extensions/Blocks/Recommendation/utils/followUpApply.d.ts +20 -0
  67. package/dist/src/extensions/Blocks/Recommendation/utils/nodeConfigWriter.d.ts +15 -2
  68. package/dist/src/extensions/Blocks/Recommendation/utils/restoreRefresh.d.ts +2 -0
  69. package/dist/src/extensions/Blocks/Recommendation/utils/strategyCommit.d.ts +7 -0
  70. package/dist/src/extensions/Blocks/_Boilerplate/controls/blockBackground/index.d.ts +1 -0
  71. package/dist/src/extensions/Blocks/controlFactories.d.ts +22 -0
  72. package/dist/src/stores/editor.d.ts +3 -1
  73. package/dist/src/utils/liquidProtection.d.ts +3 -0
  74. package/dist/static/styles/components/button.css.js +5 -0
  75. package/dist/stores/editor.js +5 -0
  76. package/dist/utils/liquidProtection.js +5 -0
  77. package/dist/utils/templatePreparation.js +61 -85
  78. package/package.json +3 -3
@@ -1,23 +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";
4
- import { ToasterTypeOptions as B } from "../../../../enums/toaster.js";
5
- import { useRecommendationApi as z } 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 B, strategyCreatePath as z, 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 A } from "pinia";
7
+ import { defineStore as V } 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 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
11
  import { getDefaultProducts as w } from "../templates/utils.js";
12
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();
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 b = /* @__PURE__ */ new Map();
21
+ let k = null, I = 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;
26
+ }
21
27
  let l = null;
22
28
  function D() {
23
29
  return {
@@ -35,7 +41,7 @@ function D() {
35
41
  productIds: [],
36
42
  id: 1,
37
43
  language: "en_US",
38
- mobileCardsInRow: O,
44
+ mobileCardsInRow: A,
39
45
  mobileLayoutEnabled: !1,
40
46
  orientation: "grid",
41
47
  recommendedProducts: [],
@@ -69,10 +75,12 @@ function G() {
69
75
  isInitialized: !1,
70
76
  filterSnapshot: null,
71
77
  syncedConfigFingerprint: null,
72
- legacyConversionLoading: !1
78
+ legacyConversionLoading: !1,
79
+ configVersion: 0,
80
+ adoptedSizeVersion: 0
73
81
  };
74
82
  }
75
- const Q = () => ({
83
+ const X = () => ({
76
84
  recommendationCampaignUrls: {},
77
85
  activePredictiveAlgorithms: [],
78
86
  languages: {},
@@ -87,8 +95,8 @@ const Q = () => ({
87
95
  currentRecommendationId: null,
88
96
  strategyPanelOpen: !1,
89
97
  configVersion: 0
90
- }), ft = A("guidoRecommendationExtension", {
91
- state: () => Q(),
98
+ }), ht = V("guidoRecommendationExtension", {
99
+ state: () => X(),
92
100
  getters: {
93
101
  // ====================================================================
94
102
  // Proxy Getters — Backward Compatible Access to Current Block State
@@ -119,7 +127,7 @@ const Q = () => ({
119
127
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
120
128
  },
121
129
  isLegacyStrategyBlock() {
122
- return R().isFeatureEnabled("reusableRecommendationStrategy") && j(this.recommendationConfigs);
130
+ return R().isFeatureEnabled("reusableRecommendationStrategy") && $(this.recommendationConfigs);
123
131
  },
124
132
  legacyConversionLoading(t) {
125
133
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
@@ -129,7 +137,7 @@ const Q = () => ({
129
137
  },
130
138
  assignedStrategy(t) {
131
139
  const { strategyId: e } = this.recommendationConfigs;
132
- 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;
133
141
  },
134
142
  /**
135
143
  * Proxy getter: delegates to blockStates[currentRecommendationId].filterStatus
@@ -159,19 +167,19 @@ const Q = () => ({
159
167
  },
160
168
  getUniqueFilterGroups() {
161
169
  const { filters: t } = this.recommendationConfigs;
162
- 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);
163
171
  },
164
172
  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
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
171
179
  }));
172
180
  },
173
- getLanguages: (t) => Object.entries(t.languages).map(([e, r]) => ({
174
- text: r,
181
+ getLanguages: (t) => Object.entries(t.languages).map(([e, n]) => ({
182
+ text: n,
175
183
  value: e
176
184
  })),
177
185
  getCurrencySymbolList: (t) => t.currencyList.map((e) => ({
@@ -181,7 +189,7 @@ const Q = () => ({
181
189
  getFilterList() {
182
190
  return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
183
191
  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, {
192
+ return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : N.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
185
193
  text: t.displayName,
186
194
  value: e,
187
195
  type: t.attributeType
@@ -213,13 +221,13 @@ const Q = () => ({
213
221
  removeBlockState(t) {
214
222
  const e = t.toString();
215
223
  if (this.recommendationCampaignUrls[e]) {
216
- const n = { ...this.recommendationCampaignUrls };
217
- delete n[e], this.recommendationCampaignUrls = n;
224
+ const r = { ...this.recommendationCampaignUrls };
225
+ delete r[e], this.recommendationCampaignUrls = r;
218
226
  }
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;
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;
223
231
  }
224
232
  },
225
233
  /**
@@ -231,18 +239,18 @@ const Q = () => ({
231
239
  * (SD-149916).
232
240
  */
233
241
  cloneBlockState(t, e) {
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 = {
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 = {
238
246
  ...this.blockStates,
239
- [e]: o
247
+ [e]: s
240
248
  };
241
249
  }
242
- const n = t.toString(), s = e.toString(), i = this.recommendationCampaignUrls[n];
250
+ const r = t.toString(), o = e.toString(), i = this.recommendationCampaignUrls[r];
243
251
  i && (this.recommendationCampaignUrls = {
244
252
  ...this.recommendationCampaignUrls,
245
- [s]: i
253
+ [o]: i
246
254
  });
247
255
  },
248
256
  /**
@@ -267,15 +275,15 @@ const Q = () => ({
267
275
  * `isInitialized`) alone.
268
276
  */
269
277
  seedBlockUrlConfig(t, e) {
270
- const r = (o, a) => o === "." || o === "," || o === " " ? o : a, n = {
278
+ const n = (s, a) => s === "." || s === "," || s === " " ? s : a, r = {
271
279
  name: e.currencyCode,
272
280
  value: e.currencyCode,
273
281
  symbol: e.currencySymbol,
274
282
  alignment: e.currencyAlignment === "before" ? "0" : "1",
275
283
  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];
284
+ decimalSeparator: n(e.currencyDecimalSeparator, ","),
285
+ thousandSeparator: n(e.currencyThousandSeparator, ".")
286
+ }, o = !this.blockStates[t], i = o ? G() : this.blockStates[t];
279
287
  i.recommendationConfigs = {
280
288
  ...i.recommendationConfigs,
281
289
  strategy: e.strategy,
@@ -285,12 +293,16 @@ const Q = () => ({
285
293
  productIds: e.productIds,
286
294
  filters: e.filters,
287
295
  shuffleProducts: e.shuffleProducts,
288
- currencySettings: n
289
- }, s && (this.blockStates = {
296
+ currencySettings: r
297
+ }, o && (this.blockStates = {
290
298
  ...this.blockStates,
291
299
  [t]: i
292
300
  });
293
301
  },
302
+ /** Re-seeds a block whose node a restore rewrote; a pending fetch for the old config must not be joined. */
303
+ reseedBlockFromNode(t, e) {
304
+ this.seedBlockUrlConfig(t, e), b.delete(t);
305
+ },
294
306
  /**
295
307
  * Patches the current block's recommendationConfigs.
296
308
  * Replaces `store.$patch({ recommendationConfigs: { ... } })` pattern.
@@ -298,27 +310,27 @@ const Q = () => ({
298
310
  patchCurrentBlockConfig(t, e = {}) {
299
311
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
300
312
  return;
301
- const r = this.blockStates[this.currentRecommendationId];
302
- r.recommendationConfigs = {
303
- ...r.recommendationConfigs,
313
+ const n = this.blockStates[this.currentRecommendationId];
314
+ n.recommendationConfigs = {
315
+ ...n.recommendationConfigs,
304
316
  ...t,
305
317
  currencySettings: {
306
- ...r.recommendationConfigs.currencySettings,
318
+ ...n.recommendationConfigs.currencySettings,
307
319
  ...t.currencySettings || {}
308
320
  }
309
321
  };
310
- const { triggerRefetch: n = !0 } = e;
311
- n && this.configVersion++;
322
+ const { triggerRefetch: r = !0 } = e;
323
+ r && (n.configVersion++, this.configVersion++);
312
324
  },
313
325
  /**
314
326
  * Creates a filter with the first available attribute and operator pre-selected.
315
327
  */
316
328
  createDefaultFilter(t, e) {
317
- const [r] = this.getFilterList, [n] = M(r == null ? void 0 : r.type);
329
+ const [n] = this.getFilterList, [r] = M(n == null ? void 0 : n.type);
318
330
  return {
319
331
  type: "standardFilter",
320
- attribute: (r == null ? void 0 : r.value) ?? "",
321
- operator: (n == null ? void 0 : n.value) ?? "",
332
+ attribute: (n == null ? void 0 : n.value) ?? "",
333
+ operator: (r == null ? void 0 : r.value) ?? "",
322
334
  innerGroupOperator: "*",
323
335
  outerGroupOperator: "*",
324
336
  filterNumber: e,
@@ -387,15 +399,15 @@ const Q = () => ({
387
399
  }
388
400
  if (this.strategiesFetched)
389
401
  return;
390
- const t = b, e = (async () => {
402
+ const t = I, e = (async () => {
391
403
  this.strategiesLoading = !0;
392
404
  try {
393
- const r = await m.fetchRecommendationStrategies();
394
- if (t !== b)
405
+ const n = await m.fetchRecommendationStrategies();
406
+ if (t !== I)
395
407
  return;
396
- this.strategies = r, this.strategiesFetched = !0;
408
+ this.strategies = n, this.strategiesFetched = !0;
397
409
  } finally {
398
- this.strategiesLoading = !1, t === b && (this.strategiesSettled = !0);
410
+ this.strategiesLoading = !1, t === I && (this.strategiesSettled = !0);
399
411
  }
400
412
  })();
401
413
  k = e;
@@ -416,7 +428,7 @@ const Q = () => ({
416
428
  }));
417
429
  },
418
430
  invalidateStrategies() {
419
- this.strategiesFetched = !1, this.strategiesSettled = !1, b += 1;
431
+ this.strategiesFetched = !1, this.strategiesSettled = !1, I += 1;
420
432
  },
421
433
  /**
422
434
  * Opens a Smart Recommender strategy page in a new tab and refreshes the list every time
@@ -434,20 +446,20 @@ const Q = () => ({
434
446
  _armStrategyPageReturn(t) {
435
447
  const e = window.open(t, "_blank");
436
448
  if (!e)
437
- return _().showToaster({
438
- type: B.Error,
439
- message: L()("discovery-strategy.error-description")
449
+ return L().showToaster({
450
+ type: E.Error,
451
+ message: U()("discovery-strategy.error-description")
440
452
  }), !1;
441
453
  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(() => {
454
+ let n = !1;
455
+ const r = () => {
456
+ document.hidden || n || (e != null && e.closed && (l == null || l()), n = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
445
457
  }).finally(() => {
446
- r = !1;
458
+ n = !1;
447
459
  }));
448
460
  };
449
- return document.addEventListener("visibilitychange", n), l = () => {
450
- document.removeEventListener("visibilitychange", n), l = null;
461
+ return document.addEventListener("visibilitychange", r), l = () => {
462
+ document.removeEventListener("visibilitychange", r), l = null;
451
463
  }, !0;
452
464
  },
453
465
  /**
@@ -471,23 +483,23 @@ const Q = () => ({
471
483
  * new strategy is offered; the user picks it themselves.
472
484
  */
473
485
  openStrategyCreation() {
474
- return this._armStrategyPageReturn(N());
486
+ return this._armStrategyPageReturn(z());
475
487
  },
476
488
  /**
477
489
  * Opens the strategy's edit page. Every return refreshes the list so the block reflects the
478
490
  * edited configuration.
479
491
  */
480
492
  openStrategyEdit(t) {
481
- return this._armStrategyPageReturn(U(t));
493
+ return this._armStrategyPageReturn(B(t));
482
494
  },
483
495
  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;
485
- if (s)
486
- return s;
496
+ const n = typeof t.updated_at == "string" ? t.updated_at : "", r = n ? `${t.strategy_id}:${n}:${e}` : "", o = r ? this.strategyUrlTemplates[r] : void 0;
497
+ if (o)
498
+ return o;
487
499
  const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
488
- return n && i && (this.strategyUrlTemplates = {
500
+ return r && i && (this.strategyUrlTemplates = {
489
501
  ...this.strategyUrlTemplates,
490
- [n]: i
502
+ [r]: i
491
503
  }), i;
492
504
  },
493
505
  assignStrategy(t) {
@@ -497,27 +509,27 @@ const Q = () => ({
497
509
  });
498
510
  },
499
511
  async convertLegacyStrategy(t, e = { scope: "campaign" }) {
500
- const r = this.currentRecommendationId;
501
- if (r === null || !this.blockStates[r])
512
+ const n = this.currentRecommendationId;
513
+ if (n === null || !this.blockStates[n])
502
514
  throw new Error("[Guido] convertLegacyStrategy called without an active block");
503
- this.blockStates[r].legacyConversionLoading = !0;
515
+ this.blockStates[n].legacyConversionLoading = !0;
504
516
  try {
505
- const n = await m.migrateLegacyStrategy(t, e);
517
+ const r = await m.migrateLegacyStrategy(t, e);
506
518
  this.invalidateStrategies();
507
519
  try {
508
520
  await this.fetchStrategies();
509
- } catch (o) {
510
- console.error("[Guido] strategy listing refresh after conversion failed", o);
521
+ } catch (s) {
522
+ console.error("[Guido] strategy listing refresh after conversion failed", s);
511
523
  }
512
- const s = this.strategies.find((o) => String(o.strategy_id) === n), i = this.blockStates[r];
524
+ const o = this.strategies.find((s) => String(s.strategy_id) === r), i = this.blockStates[n];
513
525
  return i && (i.recommendationConfigs = {
514
526
  ...i.recommendationConfigs,
515
- strategyId: n,
527
+ strategyId: r,
516
528
  nodeConfigVersion: C,
517
- ...(s == null ? void 0 : s.size) !== void 0 ? { size: String(s.size) } : {}
518
- }), this.currentRecommendationId === r && this.configVersion++, n;
529
+ ...(o == null ? void 0 : o.size) !== void 0 ? { size: String(o.size) } : {}
530
+ }, i.configVersion++), this.currentRecommendationId === n && this.configVersion++, r;
519
531
  } finally {
520
- this.blockStates[r] && (this.blockStates[r].legacyConversionLoading = !1);
532
+ this.blockStates[n] && (this.blockStates[n].legacyConversionLoading = !1);
521
533
  }
522
534
  },
523
535
  /**
@@ -526,8 +538,8 @@ const Q = () => ({
526
538
  * the document never received.
527
539
  */
528
540
  revertLegacyConversion(t, e) {
529
- const r = this.blockStates[t];
530
- r && (r.recommendationConfigs = { ...r.recommendationConfigs, ...e }, this.currentRecommendationId === t && this.configVersion++);
541
+ const n = this.blockStates[t];
542
+ n && (n.recommendationConfigs = { ...n.recommendationConfigs, ...e }, n.configVersion++, this.currentRecommendationId === t && this.configVersion++);
531
543
  },
532
544
  removeStrategy() {
533
545
  this.patchCurrentBlockConfig({
@@ -542,43 +554,43 @@ const Q = () => ({
542
554
  // ====================================================================
543
555
  async fetchRecommendationCreateData() {
544
556
  if (!this.activePredictiveAlgorithms.length) {
545
- if (S) {
546
- await S;
557
+ if (p) {
558
+ await p;
547
559
  return;
548
560
  }
549
- S = (async () => {
561
+ p = (async () => {
550
562
  const {
551
563
  activePredictiveAlgorithms: t,
552
564
  languages: e,
553
- currencies: r
565
+ currencies: n
554
566
  } = await m.fetchRecommendationCreateData();
555
567
  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;
568
+ const r = this.blockStates[this.currentRecommendationId];
569
+ r.filterStatus = !!r.recommendationConfigs.filters.length;
558
570
  }
559
- this.currencyList = r;
571
+ this.currencyList = n;
560
572
  })();
561
573
  try {
562
- await S;
574
+ await p;
563
575
  } finally {
564
- S = null;
576
+ p = null;
565
577
  }
566
578
  }
567
579
  },
568
580
  async fetchRecommendationFilters() {
569
581
  if (!Object.keys(this.filterList).length) {
570
- if (p) {
571
- await p;
582
+ if (y) {
583
+ await y;
572
584
  return;
573
585
  }
574
- p = (async () => {
586
+ y = (async () => {
575
587
  const t = await m.fetchRecommendationFilters();
576
588
  this.filterList = t;
577
589
  })();
578
590
  try {
579
- await p;
591
+ await y;
580
592
  } finally {
581
- p = null;
593
+ y = null;
582
594
  }
583
595
  }
584
596
  },
@@ -593,56 +605,56 @@ const Q = () => ({
593
605
  deleteFilterGroup(t) {
594
606
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
595
607
  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) => ({
608
+ 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]));
609
+ e.recommendationConfigs.filters = n.map((i) => ({
598
610
  ...i,
599
- filterGroup: s.get(i.filterGroup) ?? i.filterGroup
611
+ filterGroup: o.get(i.filterGroup) ?? i.filterGroup
600
612
  }));
601
613
  },
602
614
  updateFilter(t) {
603
615
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
604
616
  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] = {
617
+ const e = this.blockStates[this.currentRecommendationId], n = e.recommendationConfigs.filters.findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
618
+ if (n !== -1) {
619
+ const r = [...e.recommendationConfigs.filters];
620
+ r[n] = {
609
621
  ...t,
610
- isValid: K(t)
611
- }, e.recommendationConfigs.filters = n;
622
+ isValid: H(t)
623
+ }, e.recommendationConfigs.filters = r;
612
624
  }
613
625
  },
614
626
  deleteFilter(t) {
615
627
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
616
628
  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)) {
629
+ const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters].findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
630
+ if (n !== -1) {
631
+ let r = [...e.recommendationConfigs.filters];
632
+ if (r.splice(n, 1), r.some((i) => i.filterGroup === t.filterGroup)) {
621
633
  let i = 1;
622
- n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
634
+ r = r.map((s) => s.filterGroup === t.filterGroup ? { ...s, filterNumber: i++ } : s);
623
635
  } 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) => ({
636
+ const i = [...new Set(r.map((a) => a.filterGroup))].sort((a, d) => a - d), s = new Map(i.map((a, d) => [a, d + 1]));
637
+ r = r.map((a) => ({
626
638
  ...a,
627
- filterGroup: o.get(a.filterGroup) ?? a.filterGroup
639
+ filterGroup: s.get(a.filterGroup) ?? a.filterGroup
628
640
  }));
629
641
  }
630
- e.recommendationConfigs.filters = n;
642
+ e.recommendationConfigs.filters = r;
631
643
  }
632
644
  },
633
645
  addFilter(t) {
634
646
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
635
647
  return;
636
- const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters], s = r.filter(
637
- (o) => o.filterGroup === t.filterGroup
638
- ).length + 1, i = r.findLastIndex((o) => o.filterGroup === t.filterGroup);
639
- i !== -1 ? r.splice(i + 1, 0, {
648
+ const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters], o = n.filter(
649
+ (s) => s.filterGroup === t.filterGroup
650
+ ).length + 1, i = n.findLastIndex((s) => s.filterGroup === t.filterGroup);
651
+ i !== -1 ? n.splice(i + 1, 0, {
640
652
  ...t,
641
- filterNumber: s
642
- }) : r.push({
653
+ filterNumber: o
654
+ }) : n.push({
643
655
  ...t,
644
- filterNumber: s
645
- }), e.recommendationConfigs.filters = r;
656
+ filterNumber: o
657
+ }), e.recommendationConfigs.filters = n;
646
658
  },
647
659
  generateFilterQuery() {
648
660
  return P(this.recommendationConfigs.filters);
@@ -653,111 +665,149 @@ const Q = () => ({
653
665
  * every block's recommendationConfigs across user edits.
654
666
  */
655
667
  hasInvalidBlock() {
656
- return Object.values(this.blockStates).some((t) => !J(t.recommendationConfigs, this));
668
+ return Object.values(this.blockStates).some((t) => !Q(t.recommendationConfigs, this));
657
669
  },
658
670
  /**
659
671
  * Which required fields are missing across the design's blocks, so the save
660
672
  * toaster can name the cause instead of always showing the generic message.
661
673
  */
662
674
  invalidBlockFields() {
663
- return Object.values(this.blockStates).flatMap((t) => H(t.recommendationConfigs, this));
675
+ return Object.values(this.blockStates).flatMap((t) => J(t.recommendationConfigs, this));
664
676
  },
665
677
  // ====================================================================
666
678
  // Per-Block Product Fetching
667
679
  // ====================================================================
668
680
  async fetchRecommendationProducts() {
669
- if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
681
+ this.currentRecommendationId !== null && await this.fetchRecommendationProductsForBlock(this.currentRecommendationId);
682
+ },
683
+ /**
684
+ * Fetches one block's products whether or not it is selected: the panel teardown and the
685
+ * strategy drawer refresh the block they were handed after the user may have moved on.
686
+ */
687
+ async fetchRecommendationProductsForBlock(t) {
688
+ var i;
689
+ const e = this.blockStates[t];
690
+ if (!e)
670
691
  return;
671
- const t = [
672
- this.currentRecommendationId,
673
- this.configVersion,
674
- b
675
- ].join(":");
676
- if (y && I === t) {
677
- await y;
692
+ const n = [e.configVersion, e.adoptedSizeVersion, I].join(":"), r = b.get(t);
693
+ if ((r == null ? void 0 : r.key) === n) {
694
+ await r.promise;
678
695
  return;
679
696
  }
680
- I = t, y = this._doFetchProducts();
697
+ const o = this._doFetchProducts(t);
698
+ b.set(t, { key: n, promise: o });
681
699
  try {
682
- await y;
700
+ await o;
683
701
  } finally {
684
- I === t && (y = null, I = "");
702
+ ((i = b.get(t)) == null ? void 0 : i.promise) === o && b.delete(t);
685
703
  }
686
704
  },
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);
705
+ // Captures the block ID up front so the write lands on it even if the user switches.
706
+ async _doFetchProducts(t) {
707
+ var S;
708
+ const e = t ?? this.currentRecommendationId, n = this.blockStates[e], { recommendationConfigs: r } = n, o = R();
709
+ if (r.strategyId && o.isFeatureEnabled("reusableRecommendationStrategy")) {
710
+ await this._doFetchStrategyProducts(e);
692
711
  return;
693
712
  }
694
- const s = (g.get(t) ?? 0) + 1;
695
- g.set(t, s);
696
- const i = parseInt(r.size) || 6;
713
+ const i = (u.get(e) ?? 0) + 1;
714
+ u.set(e, i);
715
+ const s = parseInt(r.size) || 6;
697
716
  if (!r.strategy) {
698
- this._setBlockProducts(t, [], i);
717
+ this._setBlockProducts(e, [], s);
699
718
  return;
700
719
  }
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 = {
720
+ 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 = {
702
721
  locale: r.language,
703
722
  currency: r.currencySettings.value,
704
- partnerName: n.partnerName,
723
+ partnerName: o.partnerName,
705
724
  size: r.size,
706
725
  details: !0,
707
- campaignId: n.variationId
726
+ campaignId: o.variationId
708
727
  };
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(
728
+ 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(
710
729
  c,
711
- $(n.partnerName, r.strategy)
730
+ q(o.partnerName, r.strategy)
712
731
  );
713
- let u;
732
+ let g;
714
733
  try {
715
- u = await m.fetchRecommendationProducts(d, c);
734
+ g = await m.fetchRecommendationProducts(f, c);
716
735
  } catch {
717
- u = [];
736
+ g = [];
718
737
  }
719
- g.get(t) === s && this._setBlockProducts(t, u, i);
738
+ u.get(e) === i && this._setBlockProducts(e, g, s);
720
739
  },
721
740
  /**
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.
741
+ * Block-scoped counterpart of `fetchRecommendationProducts`, which only serves the selected block:
742
+ * the legacy conversion and the duplicate refresh must reach a block that may no longer be selected.
743
+ * @returns whether real products arrived
725
744
  */
726
- async fetchStrategyProductsForBlock(t) {
727
- var e;
728
- (e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId && await this._doFetchStrategyProducts(t);
745
+ async fetchStrategyProductsForBlock(t, e = {}) {
746
+ var n;
747
+ return (n = this.blockStates[t]) != null && n.recommendationConfigs.strategyId ? this._doFetchStrategyProducts(t, e) : !1;
748
+ },
749
+ /**
750
+ * Reloads a block's products and adopts its strategy's current size, which may have
751
+ * moved since the block was assigned.
752
+ * @returns whether a fresh listing holds the strategy and its products arrived
753
+ */
754
+ async refreshStrategyBlock(t) {
755
+ var o;
756
+ const e = (o = this.blockStates[t]) == null ? void 0 : o.recommendationConfigs.strategyId;
757
+ if (!e)
758
+ return !1;
759
+ try {
760
+ await this.fetchStrategies();
761
+ } catch {
762
+ return !1;
763
+ }
764
+ const n = this.strategiesFetched ? this.strategies.find((i) => String(i.strategy_id) === e) : void 0;
765
+ if (!n || !await this.fetchStrategyProductsForBlock(t, { keepOnFailure: !0 }))
766
+ return !1;
767
+ const r = this.blockStates[t];
768
+ if ((r == null ? void 0 : r.recommendationConfigs.strategyId) !== e)
769
+ return !1;
770
+ if (n.size !== void 0) {
771
+ const i = String(n.size);
772
+ r.recommendationConfigs.size !== i && r.adoptedSizeVersion++, r.recommendationConfigs = { ...r.recommendationConfigs, size: i };
773
+ }
774
+ return !0;
775
+ },
776
+ _doFetchStrategyProducts(t, e = {}) {
777
+ const n = (u.get(t) ?? 0) + 1;
778
+ u.set(t, n);
779
+ const r = this._loadStrategyProducts(t, n, e);
780
+ return _.set(t, { token: n, outcome: r }), r;
729
781
  },
730
- async _doFetchStrategyProducts(t) {
731
- const e = (g.get(t) ?? 0) + 1;
732
- g.set(t, e);
782
+ async _loadStrategyProducts(t, e, { keepOnFailure: n = !1 }) {
733
783
  const { recommendationConfigs: r } = this.blockStates[t];
734
- let n = [], s = parseInt(r.size) || 6;
784
+ let o = [], i = parseInt(r.size) || 6;
735
785
  try {
736
786
  await this.fetchStrategies();
737
- const i = this.strategies.find(
738
- (o) => String(o.strategy_id) === r.strategyId
787
+ const s = this.strategies.find(
788
+ (a) => String(a.strategy_id) === r.strategyId
739
789
  );
740
- if (i) {
741
- s = parseInt(String(i.size ?? "")) || s;
742
- const o = r.currencySettings.value, d = (await this.resolveStrategyUrlTemplate(i, o)).replaceAll("{locale}", r.language).replaceAll("{currency}", o), c = d.indexOf("?"), u = c === -1 ? d : d.slice(0, c), h = (c === -1 ? "" : d.slice(c + 1)).split("&").filter((v) => v && !v.startsWith("user_id=")), f = h.length ? `${u}?${h.join("&")}` : u;
743
- f && (n = await m.fetchRecommendationProductsByUrl(f));
790
+ if (s) {
791
+ i = parseInt(String(s.size ?? "")) || i;
792
+ 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;
793
+ h && (o = await m.fetchRecommendationProductsByUrl(h));
744
794
  }
745
795
  } catch {
746
- n = [];
796
+ o = [];
747
797
  }
748
- g.get(t) === e && this._setBlockProducts(t, n, s);
798
+ return u.get(t) !== e ? W(t) : !o.length && n ? !1 : (this._setBlockProducts(t, o, i), o.length > 0);
749
799
  },
750
- _setBlockProducts(t, e, r) {
800
+ _setBlockProducts(t, e, n) {
751
801
  if (!this.blockStates[t])
752
802
  return;
753
- const n = e.length > 0 ? e : w(r);
803
+ const r = e.length > 0 ? e : w(n);
754
804
  this.blockStates[t].recommendationProducts = [
755
- ...n.slice(0, r),
756
- ...w(Math.max(0, r - n.length))
805
+ ...r.slice(0, n),
806
+ ...w(Math.max(0, n - r.length))
757
807
  ];
758
808
  }
759
809
  }
760
810
  });
761
811
  export {
762
- ft as useRecommendationExtensionStore
812
+ ht as useRecommendationExtensionStore
763
813
  };