@useinsider/guido 3.19.0-beta.2854f4f → 3.19.0-beta.3906ea8

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 (40) hide show
  1. package/README.md +21 -3
  2. package/dist/@types/config/schemas.js +59 -51
  3. package/dist/components/Guido.vue.js +4 -4
  4. package/dist/components/Guido.vue2.js +57 -55
  5. package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue.js +3 -3
  6. package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue2.js +56 -52
  7. package/dist/components/organisms/extensions/recommendation/LegacyStrategyUpdatedModal.vue.js +18 -0
  8. package/dist/components/organisms/extensions/recommendation/LegacyStrategyUpdatedModal.vue2.js +25 -0
  9. package/dist/components/organisms/extensions/recommendation/RemoveStrategyModal.vue2.js +18 -18
  10. package/dist/components/organisms/onboarding/OnboardingWrapper.vue2.js +28 -26
  11. package/dist/components/organisms/onboarding/RecommendationLegacyStrategyOnboarding.vue.js +21 -0
  12. package/dist/components/organisms/onboarding/RecommendationLegacyStrategyOnboarding.vue2.js +46 -0
  13. package/dist/composables/useCustomInterfaceAppearance.js +54 -50
  14. package/dist/composables/useLegacyStrategyConversion.js +61 -0
  15. package/dist/enums/extensions/recommendationBlock.js +34 -25
  16. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +73 -72
  17. package/dist/extensions/Blocks/Recommendation/controls/main/strategy.js +81 -38
  18. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +169 -108
  19. package/dist/extensions/Blocks/Recommendation/utils/legacyStrategyMigration.js +42 -0
  20. package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +10 -10
  21. package/dist/guido.css +1 -1
  22. package/dist/services/recommendationApi.js +46 -37
  23. package/dist/src/@types/config/schemas.d.ts +16 -0
  24. package/dist/src/components/organisms/extensions/recommendation/LegacyStrategyUpdatedModal.vue.d.ts +2 -0
  25. package/dist/src/components/organisms/onboarding/RecommendationLegacyStrategyOnboarding.vue.d.ts +2 -0
  26. package/dist/src/composables/useConfig.d.ts +4 -0
  27. package/dist/src/composables/useLegacyStrategyConversion.d.ts +3 -0
  28. package/dist/src/enums/extensions/recommendationBlock.d.ts +5 -1
  29. package/dist/src/extensions/Blocks/Recommendation/controls/main/strategy.d.ts +1 -0
  30. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +76 -1
  31. package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMigration.d.ts +32 -0
  32. package/dist/src/services/recommendationApi.d.ts +2 -1
  33. package/dist/src/stores/config.d.ts +322 -0
  34. package/dist/src/stores/onboarding.d.ts +421 -0
  35. package/dist/static/assets/icons/filled-arrow-rising.svg.js +5 -0
  36. package/dist/static/assets/icons/line-info.svg.js +5 -0
  37. package/dist/static/styles/components/recommendation-strategy.css.js +70 -5
  38. package/dist/stores/config.js +74 -60
  39. package/dist/stores/onboarding.js +6 -1
  40. package/package.json +2 -2
@@ -1,26 +1,27 @@
1
1
  import { useToaster as D } from "../../../../composables/useToaster.js";
2
- import { useTranslations as _ } from "../../../../composables/useTranslations.js";
3
- import { getRecommendationFeedSourceMaps as v, strategyEditPath as A, URLS as E, getOperatorOptions as N, PriceAttributes as U } from "../../../../enums/extensions/recommendationBlock.js";
4
- import { ToasterTypeOptions as L } from "../../../../enums/toaster.js";
2
+ import { useTranslations as L } from "../../../../composables/useTranslations.js";
3
+ import { getRecommendationFeedSourceMaps as F, strategyEditPath as U, URLS as E, getOperatorOptions as N, PriceAttributes as M } from "../../../../enums/extensions/recommendationBlock.js";
4
+ import { ToasterTypeOptions as A } from "../../../../enums/toaster.js";
5
5
  import { useRecommendationApi as T } from "../../../../services/recommendationApi.js";
6
6
  import { useConfigStore as k } from "../../../../stores/config.js";
7
7
  import { defineStore as B } 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 { DEFAULT_NODE_CONFIG as M, EXCLUDED_ALGORITHM_IDS as z } from "../constants/defaultConfig.js";
11
- import { getDefaultProducts as F } from "../templates/utils.js";
12
- import { generateCompleteFilterQuery as w } from "../utils/filterUtil.js";
13
- import { getPartnerRecommendationParams as V } from "../utils/partnerCustomizations.js";
14
- import { sanitizeProductIds as j } from "../utils/productIds.js";
15
- import { isFilterValid as $ } from "../validation/filterSchema.js";
16
- import { getInvalidFields as q, isConfigValid as K } from "../validation/requiredFields.js";
17
- const f = T();
9
+ import { DEFAULT_MOBILE_CARDS_IN_ROW as O, DEFAULT_CARDS_IN_ROW as z } from "../constants/layout.js";
10
+ import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as x, EXCLUDED_ALGORITHM_IDS as V } from "../constants/defaultConfig.js";
11
+ import { getDefaultProducts as w } from "../templates/utils.js";
12
+ import { generateCompleteFilterQuery as P } from "../utils/filterUtil.js";
13
+ import { isLegacyStrategyConfig as j } from "../utils/legacyStrategyMigration.js";
14
+ import { getPartnerRecommendationParams as $ } from "../utils/partnerCustomizations.js";
15
+ import { sanitizeProductIds as q } from "../utils/productIds.js";
16
+ import { isFilterValid as K } from "../validation/filterSchema.js";
17
+ import { getInvalidFields as H, isConfigValid as J } from "../validation/requiredFields.js";
18
+ const m = T();
18
19
  let S = null, p = null, y = null, I = "", R = null, b = 0;
19
20
  const g = /* @__PURE__ */ new Map();
20
21
  let l = null;
21
- function G() {
22
+ function _() {
22
23
  return {
23
- cardsInRow: x,
24
+ cardsInRow: z,
24
25
  currencySettings: {
25
26
  name: "USD",
26
27
  value: "USD",
@@ -46,6 +47,7 @@ function G() {
46
47
  // algorithm from the node-config sync or the save-time seed.
47
48
  strategy: k().isFeatureEnabled("reusableRecommendationStrategy") ? "" : "mostPopular",
48
49
  strategyId: "",
50
+ nodeConfigVersion: C,
49
51
  textTrimming: !0,
50
52
  unresponsive: !1,
51
53
  size: "6",
@@ -54,21 +56,23 @@ function G() {
54
56
  priceHideIfSameAsDiscounted: !1
55
57
  };
56
58
  }
57
- function P() {
59
+ function G() {
58
60
  return {
59
- recommendationConfigs: G(),
61
+ recommendationConfigs: _(),
60
62
  recommendationProducts: [],
61
63
  filterStatus: !1,
62
64
  filterSelectionDrawerStatus: !1,
63
65
  assignStrategyDrawerStatus: !1,
64
66
  removeStrategyModalStatus: !1,
67
+ legacyStrategyUpdatedModalStatus: !1,
65
68
  filterGroup: 1,
66
69
  isInitialized: !1,
67
70
  filterSnapshot: null,
68
- syncedConfigFingerprint: null
71
+ syncedConfigFingerprint: null,
72
+ legacyConversionLoading: !1
69
73
  };
70
74
  }
71
- const H = () => ({
75
+ const Q = () => ({
72
76
  recommendationCampaignUrls: {},
73
77
  activePredictiveAlgorithms: [],
74
78
  languages: {},
@@ -83,8 +87,8 @@ const H = () => ({
83
87
  currentRecommendationId: null,
84
88
  strategyPanelOpen: !1,
85
89
  configVersion: 0
86
- }), mt = B("guidoRecommendationExtension", {
87
- state: () => H(),
90
+ }), ft = B("guidoRecommendationExtension", {
91
+ state: () => Q(),
88
92
  getters: {
89
93
  // ====================================================================
90
94
  // Proxy Getters — Backward Compatible Access to Current Block State
@@ -94,7 +98,7 @@ const H = () => ({
94
98
  * This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
95
99
  */
96
100
  recommendationConfigs(t) {
97
- return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : G();
101
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : _();
98
102
  },
99
103
  /**
100
104
  * Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
@@ -114,6 +118,15 @@ const H = () => ({
114
118
  removeStrategyModalStatus(t) {
115
119
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
116
120
  },
121
+ isLegacyStrategyBlock() {
122
+ return k().isFeatureEnabled("reusableRecommendationStrategy") && j(this.recommendationConfigs);
123
+ },
124
+ legacyConversionLoading(t) {
125
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
126
+ },
127
+ legacyStrategyUpdatedModalStatus(t) {
128
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyStrategyUpdatedModalStatus : !1;
129
+ },
117
130
  assignedStrategy(t) {
118
131
  const { strategyId: e } = this.recommendationConfigs;
119
132
  return e ? t.strategies.find((r) => String(r.strategy_id) === e) ?? null : null;
@@ -149,12 +162,12 @@ const H = () => ({
149
162
  return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
150
163
  },
151
164
  getActivePredictiveAlgorithms: (t) => {
152
- const e = v(), r = [];
153
- return t.activePredictiveAlgorithms.filter((i) => !z.includes(i)).forEach((i) => {
154
- r.push(...e.filter((s) => s.id === i));
155
- }), r.map((i) => ({
156
- text: i.name,
157
- value: i.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
158
171
  }));
159
172
  },
160
173
  getLanguages: (t) => Object.entries(t.languages).map(([e, r]) => ({
@@ -168,7 +181,7 @@ const H = () => ({
168
181
  getFilterList() {
169
182
  return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
170
183
  let e;
171
- return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : U.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
184
+ return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : M.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
172
185
  text: t.displayName,
173
186
  value: e,
174
187
  type: t.attributeType
@@ -190,7 +203,7 @@ const H = () => ({
190
203
  setCurrentBlock(t) {
191
204
  this.blockStates[t] || (this.blockStates = {
192
205
  ...this.blockStates,
193
- [t]: P()
206
+ [t]: G()
194
207
  }), this.currentRecommendationId = t;
195
208
  },
196
209
  /**
@@ -200,13 +213,13 @@ const H = () => ({
200
213
  removeBlockState(t) {
201
214
  const e = t.toString();
202
215
  if (this.recommendationCampaignUrls[e]) {
203
- const i = { ...this.recommendationCampaignUrls };
204
- delete i[e], this.recommendationCampaignUrls = i;
216
+ const n = { ...this.recommendationCampaignUrls };
217
+ delete n[e], this.recommendationCampaignUrls = n;
205
218
  }
206
219
  const r = { ...this.blockStates };
207
220
  if (delete r[t], this.blockStates = r, this.currentRecommendationId === t) {
208
- const i = Object.keys(this.blockStates).map(Number);
209
- this.currentRecommendationId = i.length > 0 ? i[0] : null;
221
+ const n = Object.keys(this.blockStates).map(Number);
222
+ this.currentRecommendationId = n.length > 0 ? n[0] : null;
210
223
  }
211
224
  },
212
225
  /**
@@ -226,10 +239,10 @@ const H = () => ({
226
239
  [e]: o
227
240
  };
228
241
  }
229
- const i = t.toString(), s = e.toString(), n = this.recommendationCampaignUrls[i];
230
- n && (this.recommendationCampaignUrls = {
242
+ const n = t.toString(), s = e.toString(), i = this.recommendationCampaignUrls[n];
243
+ i && (this.recommendationCampaignUrls = {
231
244
  ...this.recommendationCampaignUrls,
232
- [s]: n
245
+ [s]: i
233
246
  });
234
247
  },
235
248
  /**
@@ -254,7 +267,7 @@ const H = () => ({
254
267
  * `isInitialized`) alone.
255
268
  */
256
269
  seedBlockUrlConfig(t, e) {
257
- const r = (o, a) => o === "." || o === "," || o === " " ? o : a, i = {
270
+ const r = (o, a) => o === "." || o === "," || o === " " ? o : a, n = {
258
271
  name: e.currencyCode,
259
272
  value: e.currencyCode,
260
273
  symbol: e.currencySymbol,
@@ -262,9 +275,9 @@ const H = () => ({
262
275
  decimalCount: String(e.currencyDecimalCount),
263
276
  decimalSeparator: r(e.currencyDecimalSeparator, ","),
264
277
  thousandSeparator: r(e.currencyThousandSeparator, ".")
265
- }, s = !this.blockStates[t], n = s ? P() : this.blockStates[t];
266
- n.recommendationConfigs = {
267
- ...n.recommendationConfigs,
278
+ }, s = !this.blockStates[t], i = s ? G() : this.blockStates[t];
279
+ i.recommendationConfigs = {
280
+ ...i.recommendationConfigs,
268
281
  strategy: e.strategy,
269
282
  strategyId: e.strategyId,
270
283
  language: e.language,
@@ -272,10 +285,10 @@ const H = () => ({
272
285
  productIds: e.productIds,
273
286
  filters: e.filters,
274
287
  shuffleProducts: e.shuffleProducts,
275
- currencySettings: i
288
+ currencySettings: n
276
289
  }, s && (this.blockStates = {
277
290
  ...this.blockStates,
278
- [t]: n
291
+ [t]: i
279
292
  });
280
293
  },
281
294
  /**
@@ -294,18 +307,18 @@ const H = () => ({
294
307
  ...t.currencySettings || {}
295
308
  }
296
309
  };
297
- const { triggerRefetch: i = !0 } = e;
298
- i && this.configVersion++;
310
+ const { triggerRefetch: n = !0 } = e;
311
+ n && this.configVersion++;
299
312
  },
300
313
  /**
301
314
  * Creates a filter with the first available attribute and operator pre-selected.
302
315
  */
303
316
  createDefaultFilter(t, e) {
304
- const [r] = this.getFilterList, [i] = N(r == null ? void 0 : r.type);
317
+ const [r] = this.getFilterList, [n] = N(r == null ? void 0 : r.type);
305
318
  return {
306
319
  type: "standardFilter",
307
320
  attribute: (r == null ? void 0 : r.value) ?? "",
308
- operator: (i == null ? void 0 : i.value) ?? "",
321
+ operator: (n == null ? void 0 : n.value) ?? "",
309
322
  innerGroupOperator: "*",
310
323
  outerGroupOperator: "*",
311
324
  filterNumber: e,
@@ -354,6 +367,12 @@ const H = () => ({
354
367
  closeAssignStrategyDrawer() {
355
368
  this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].assignStrategyDrawerStatus = !1);
356
369
  },
370
+ openLegacyStrategyUpdatedModal() {
371
+ this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].legacyStrategyUpdatedModalStatus = !0);
372
+ },
373
+ closeLegacyStrategyUpdatedModal() {
374
+ this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].legacyStrategyUpdatedModalStatus = !1);
375
+ },
357
376
  openRemoveStrategyModal() {
358
377
  this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].removeStrategyModalStatus = !0);
359
378
  },
@@ -371,7 +390,7 @@ const H = () => ({
371
390
  const t = b, e = (async () => {
372
391
  this.strategiesLoading = !0;
373
392
  try {
374
- const r = await f.fetchRecommendationStrategies();
393
+ const r = await m.fetchRecommendationStrategies();
375
394
  if (t !== b)
376
395
  return;
377
396
  this.strategies = r, this.strategiesFetched = !0;
@@ -416,19 +435,19 @@ const H = () => ({
416
435
  const e = window.open(t, "_blank");
417
436
  if (!e)
418
437
  return D().showToaster({
419
- type: L.Error,
420
- message: _()("discovery-strategy.error-description")
438
+ type: A.Error,
439
+ message: L()("discovery-strategy.error-description")
421
440
  }), !1;
422
441
  e.opener = null, l == null || l();
423
442
  let r = !1;
424
- const i = () => {
443
+ const n = () => {
425
444
  document.hidden || r || (e != null && e.closed && (l == null || l()), r = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
426
445
  }).finally(() => {
427
446
  r = !1;
428
447
  }));
429
448
  };
430
- return document.addEventListener("visibilitychange", i), l = () => {
431
- document.removeEventListener("visibilitychange", i), l = null;
449
+ return document.addEventListener("visibilitychange", n), l = () => {
450
+ document.removeEventListener("visibilitychange", n), l = null;
432
451
  }, !0;
433
452
  },
434
453
  /**
@@ -459,17 +478,17 @@ const H = () => ({
459
478
  * edited configuration.
460
479
  */
461
480
  openStrategyEdit(t) {
462
- return this._armStrategyPageReturn(A(t));
481
+ return this._armStrategyPageReturn(U(t));
463
482
  },
464
483
  async resolveStrategyUrlTemplate(t, e) {
465
- const r = typeof t.updated_at == "string" ? t.updated_at : "", i = r ? `${t.strategy_id}:${r}:${e}` : "", s = i ? this.strategyUrlTemplates[i] : 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;
466
485
  if (s)
467
486
  return s;
468
- const { full_path: n = "" } = await f.generateStrategyEndpoint(t, e) ?? {};
469
- return i && n && (this.strategyUrlTemplates = {
487
+ const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
488
+ return n && i && (this.strategyUrlTemplates = {
470
489
  ...this.strategyUrlTemplates,
471
- [i]: n
472
- }), n;
490
+ [n]: i
491
+ }), i;
473
492
  },
474
493
  assignStrategy(t) {
475
494
  this.patchCurrentBlockConfig({
@@ -477,11 +496,44 @@ const H = () => ({
477
496
  ...t.size !== void 0 ? { size: String(t.size) } : {}
478
497
  });
479
498
  },
499
+ async convertLegacyStrategy(t, e = { scope: "campaign" }) {
500
+ const r = this.currentRecommendationId;
501
+ if (r === null || !this.blockStates[r])
502
+ throw new Error("[Guido] convertLegacyStrategy called without an active block");
503
+ this.blockStates[r].legacyConversionLoading = !0;
504
+ try {
505
+ const n = await m.migrateLegacyStrategy(t, e);
506
+ try {
507
+ await this.fetchStrategies();
508
+ } catch (o) {
509
+ console.error("[Guido] strategy listing refresh after conversion failed", o);
510
+ }
511
+ const s = this.strategies.find((o) => String(o.strategy_id) === n), i = this.blockStates[r];
512
+ return i && (i.recommendationConfigs = {
513
+ ...i.recommendationConfigs,
514
+ strategyId: n,
515
+ nodeConfigVersion: C,
516
+ ...(s == null ? void 0 : s.size) !== void 0 ? { size: String(s.size) } : {}
517
+ }), this.currentRecommendationId === r && this.configVersion++, n;
518
+ } finally {
519
+ this.blockStates[r] && (this.blockStates[r].legacyConversionLoading = !1);
520
+ }
521
+ },
522
+ /**
523
+ * Undoes the config half of a conversion whose document write never landed, so the
524
+ * panel and the drawer fall back to "Legacy Strategy" instead of showing an assignment
525
+ * the document never received.
526
+ */
527
+ revertLegacyConversion(t, e) {
528
+ const r = this.blockStates[t];
529
+ r && (r.recommendationConfigs = { ...r.recommendationConfigs, ...e }, this.currentRecommendationId === t && this.configVersion++);
530
+ },
480
531
  removeStrategy() {
481
532
  this.patchCurrentBlockConfig({
482
533
  strategyId: "",
483
534
  strategy: "",
484
- size: M.size
535
+ size: x.size,
536
+ nodeConfigVersion: C
485
537
  });
486
538
  },
487
539
  // ====================================================================
@@ -498,10 +550,10 @@ const H = () => ({
498
550
  activePredictiveAlgorithms: t,
499
551
  languages: e,
500
552
  currencies: r
501
- } = await f.fetchRecommendationCreateData();
553
+ } = await m.fetchRecommendationCreateData();
502
554
  if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
503
- const i = this.blockStates[this.currentRecommendationId];
504
- i.filterStatus = !!i.recommendationConfigs.filters.length;
555
+ const n = this.blockStates[this.currentRecommendationId];
556
+ n.filterStatus = !!n.recommendationConfigs.filters.length;
505
557
  }
506
558
  this.currencyList = r;
507
559
  })();
@@ -519,7 +571,7 @@ const H = () => ({
519
571
  return;
520
572
  }
521
573
  p = (async () => {
522
- const t = await f.fetchRecommendationFilters();
574
+ const t = await m.fetchRecommendationFilters();
523
575
  this.filterList = t;
524
576
  })();
525
577
  try {
@@ -540,41 +592,41 @@ const H = () => ({
540
592
  deleteFilterGroup(t) {
541
593
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
542
594
  return;
543
- const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.filter((n) => n.filterGroup !== t), i = [...new Set(r.map((n) => n.filterGroup))].sort((n, o) => n - o), s = new Map(i.map((n, o) => [n, o + 1]));
544
- e.recommendationConfigs.filters = r.map((n) => ({
545
- ...n,
546
- filterGroup: s.get(n.filterGroup) ?? n.filterGroup
595
+ 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]));
596
+ e.recommendationConfigs.filters = r.map((i) => ({
597
+ ...i,
598
+ filterGroup: s.get(i.filterGroup) ?? i.filterGroup
547
599
  }));
548
600
  },
549
601
  updateFilter(t) {
550
602
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
551
603
  return;
552
- const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.findIndex((i) => i.filterNumber === t.filterNumber && i.filterGroup === t.filterGroup);
604
+ const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
553
605
  if (r !== -1) {
554
- const i = [...e.recommendationConfigs.filters];
555
- i[r] = {
606
+ const n = [...e.recommendationConfigs.filters];
607
+ n[r] = {
556
608
  ...t,
557
- isValid: $(t)
558
- }, e.recommendationConfigs.filters = i;
609
+ isValid: K(t)
610
+ }, e.recommendationConfigs.filters = n;
559
611
  }
560
612
  },
561
613
  deleteFilter(t) {
562
614
  if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
563
615
  return;
564
- const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters].findIndex((i) => i.filterNumber === t.filterNumber && i.filterGroup === t.filterGroup);
616
+ const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters].findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
565
617
  if (r !== -1) {
566
- let i = [...e.recommendationConfigs.filters];
567
- if (i.splice(r, 1), i.some((n) => n.filterGroup === t.filterGroup)) {
568
- let n = 1;
569
- i = i.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: n++ } : o);
618
+ let n = [...e.recommendationConfigs.filters];
619
+ if (n.splice(r, 1), n.some((i) => i.filterGroup === t.filterGroup)) {
620
+ let i = 1;
621
+ n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
570
622
  } else {
571
- const n = [...new Set(i.map((a) => a.filterGroup))].sort((a, m) => a - m), o = new Map(n.map((a, m) => [a, m + 1]));
572
- i = i.map((a) => ({
623
+ const i = [...new Set(n.map((a) => a.filterGroup))].sort((a, d) => a - d), o = new Map(i.map((a, d) => [a, d + 1]));
624
+ n = n.map((a) => ({
573
625
  ...a,
574
626
  filterGroup: o.get(a.filterGroup) ?? a.filterGroup
575
627
  }));
576
628
  }
577
- e.recommendationConfigs.filters = i;
629
+ e.recommendationConfigs.filters = n;
578
630
  }
579
631
  },
580
632
  addFilter(t) {
@@ -582,8 +634,8 @@ const H = () => ({
582
634
  return;
583
635
  const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters], s = r.filter(
584
636
  (o) => o.filterGroup === t.filterGroup
585
- ).length + 1, n = r.findLastIndex((o) => o.filterGroup === t.filterGroup);
586
- n !== -1 ? r.splice(n + 1, 0, {
637
+ ).length + 1, i = r.findLastIndex((o) => o.filterGroup === t.filterGroup);
638
+ i !== -1 ? r.splice(i + 1, 0, {
587
639
  ...t,
588
640
  filterNumber: s
589
641
  }) : r.push({
@@ -592,7 +644,7 @@ const H = () => ({
592
644
  }), e.recommendationConfigs.filters = r;
593
645
  },
594
646
  generateFilterQuery() {
595
- return w(this.recommendationConfigs.filters);
647
+ return P(this.recommendationConfigs.filters);
596
648
  },
597
649
  /**
598
650
  * Validation-only check invoked at save-CTA time. Defined as an action
@@ -600,14 +652,14 @@ const H = () => ({
600
652
  * every block's recommendationConfigs across user edits.
601
653
  */
602
654
  hasInvalidBlock() {
603
- return Object.values(this.blockStates).some((t) => !K(t.recommendationConfigs, this));
655
+ return Object.values(this.blockStates).some((t) => !J(t.recommendationConfigs, this));
604
656
  },
605
657
  /**
606
658
  * Which required fields are missing across the design's blocks, so the save
607
659
  * toaster can name the cause instead of always showing the generic message.
608
660
  */
609
661
  invalidBlockFields() {
610
- return Object.values(this.blockStates).flatMap((t) => q(t.recommendationConfigs, this));
662
+ return Object.values(this.blockStates).flatMap((t) => H(t.recommendationConfigs, this));
611
663
  },
612
664
  // ====================================================================
613
665
  // Per-Block Product Fetching
@@ -633,69 +685,78 @@ const H = () => ({
633
685
  },
634
686
  async _doFetchProducts() {
635
687
  var h;
636
- const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, i = k();
637
- if (r.strategyId && i.isFeatureEnabled("reusableRecommendationStrategy")) {
688
+ const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = k();
689
+ if (r.strategyId && n.isFeatureEnabled("reusableRecommendationStrategy")) {
638
690
  await this._doFetchStrategyProducts(t);
639
691
  return;
640
692
  }
641
693
  const s = (g.get(t) ?? 0) + 1;
642
694
  g.set(t, s);
643
- const n = parseInt(r.size) || 6;
695
+ const i = parseInt(r.size) || 6;
644
696
  if (!r.strategy) {
645
- this._setBlockProducts(t, [], n);
697
+ this._setBlockProducts(t, [], i);
646
698
  return;
647
699
  }
648
- const o = r.filters.filter((d) => d.isValid), a = w(o), m = ((h = v().find((d) => d.key === r.strategy)) == null ? void 0 : h.path) || "", c = {
700
+ 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 = {
649
701
  locale: r.language,
650
702
  currency: r.currencySettings.value,
651
- partnerName: i.partnerName,
703
+ partnerName: n.partnerName,
652
704
  size: r.size,
653
705
  details: !0,
654
- campaignId: i.variationId
706
+ campaignId: n.variationId
655
707
  };
656
- r.strategy === "manualMerchandising" ? c.productId = j(r.productIds) : r.strategy === "similarViewed" && (c.productId = "{itemId}"), r.strategy === "userBased" && (c.userId = "{user_id}"), a && (c.filter = a), r.shuffleProducts && (c.shuffle = !0), Object.assign(
708
+ r.strategy === "manualMerchandising" ? c.productId = 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(
657
709
  c,
658
- V(i.partnerName, r.strategy)
710
+ $(n.partnerName, r.strategy)
659
711
  );
660
712
  let u;
661
713
  try {
662
- u = await f.fetchRecommendationProducts(m, c);
714
+ u = await m.fetchRecommendationProducts(d, c);
663
715
  } catch {
664
716
  u = [];
665
717
  }
666
- g.get(t) === s && this._setBlockProducts(t, u, n);
718
+ g.get(t) === s && this._setBlockProducts(t, u, i);
719
+ },
720
+ /**
721
+ * Block-scoped counterpart of `fetchRecommendationProducts`, which only ever serves the
722
+ * selected block. The legacy conversion must refresh the products of the block that
723
+ * started it even after the user selected another one.
724
+ */
725
+ async fetchStrategyProductsForBlock(t) {
726
+ var e;
727
+ (e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId && await this._doFetchStrategyProducts(t);
667
728
  },
668
729
  async _doFetchStrategyProducts(t) {
669
730
  const e = (g.get(t) ?? 0) + 1;
670
731
  g.set(t, e);
671
732
  const { recommendationConfigs: r } = this.blockStates[t];
672
- let i = [], s = parseInt(r.size) || 6;
733
+ let n = [], s = parseInt(r.size) || 6;
673
734
  try {
674
735
  await this.fetchStrategies();
675
- const n = this.strategies.find(
736
+ const i = this.strategies.find(
676
737
  (o) => String(o.strategy_id) === r.strategyId
677
738
  );
678
- if (n) {
679
- s = parseInt(String(n.size ?? "")) || s;
680
- const o = r.currencySettings.value, m = (await this.resolveStrategyUrlTemplate(n, o)).replaceAll("{locale}", r.language).replaceAll("{currency}", o), c = m.indexOf("?"), u = c === -1 ? m : m.slice(0, c), h = (c === -1 ? "" : m.slice(c + 1)).split("&").filter((C) => C && !C.startsWith("user_id=")), d = h.length ? `${u}?${h.join("&")}` : u;
681
- d && (i = await f.fetchRecommendationProductsByUrl(d));
739
+ if (i) {
740
+ s = parseInt(String(i.size ?? "")) || s;
741
+ 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;
742
+ f && (n = await m.fetchRecommendationProductsByUrl(f));
682
743
  }
683
744
  } catch {
684
- i = [];
745
+ n = [];
685
746
  }
686
- g.get(t) === e && this._setBlockProducts(t, i, s);
747
+ g.get(t) === e && this._setBlockProducts(t, n, s);
687
748
  },
688
749
  _setBlockProducts(t, e, r) {
689
750
  if (!this.blockStates[t])
690
751
  return;
691
- const i = e.length > 0 ? e : F(r);
752
+ const n = e.length > 0 ? e : w(r);
692
753
  this.blockStates[t].recommendationProducts = [
693
- ...i.slice(0, r),
694
- ...F(Math.max(0, r - i.length))
754
+ ...n.slice(0, r),
755
+ ...w(Math.max(0, r - n.length))
695
756
  ];
696
757
  }
697
758
  }
698
759
  });
699
760
  export {
700
- mt as useRecommendationExtensionStore
761
+ ft as useRecommendationExtensionStore
701
762
  };
@@ -0,0 +1,42 @@
1
+ import "../constants/selectors.js";
2
+ import { RRS_CONFIG_VERSION as m } from "../constants/defaultConfig.js";
3
+ import { sanitizeProductIds as p } from "./productIds.js";
4
+ const d = "manualMerchandising";
5
+ function N({ strategyId: e, nodeConfigVersion: t }) {
6
+ return !e && t < m;
7
+ }
8
+ const o = (e) => {
9
+ const t = String(e ?? "").trim();
10
+ return /^[1-9]\d*$/.test(t) ? t : null;
11
+ };
12
+ function f({ campaignId: e, templateLibraryId: t }) {
13
+ if (o(e))
14
+ return { scope: "campaign" };
15
+ const n = o(t);
16
+ return n ? { scope: "template", templateId: n } : { scope: "campaign" };
17
+ }
18
+ function y({
19
+ blockId: e,
20
+ url: t,
21
+ campaignId: n,
22
+ variationId: a,
23
+ strategy: c,
24
+ productIds: s,
25
+ target: r
26
+ }) {
27
+ const i = c === d ? p(s).split(",").filter(Boolean) : [];
28
+ return {
29
+ ...r.scope === "template" ? { templateId: Number.parseInt(r.templateId) } : {
30
+ campaignId: Number.parseInt(n) || 0,
31
+ variationId: Number.parseInt(a) || 0
32
+ },
33
+ blockId: String(e),
34
+ url: t,
35
+ ...i.length ? { productIds: i } : {}
36
+ };
37
+ }
38
+ export {
39
+ y as buildLegacyMigrationPayload,
40
+ N as isLegacyStrategyConfig,
41
+ f as resolveMigrationTarget
42
+ };
@@ -1,24 +1,24 @@
1
- import { useRecommendationExtensionStore as s } from "../store/recommendation.js";
2
- import { commitBlockChangeOutsidePanel as d } from "./nodeConfigWriter.js";
3
- async function u(e, n) {
4
- const t = s(), o = t.blockStates[e];
1
+ import { useRecommendationExtensionStore as d } from "../store/recommendation.js";
2
+ import { commitBlockChangeOutsidePanel as f } from "./nodeConfigWriter.js";
3
+ async function h(e, r) {
4
+ const t = d(), o = t.blockStates[e];
5
5
  if (!o)
6
6
  return !1;
7
- const { strategyId: a, strategy: c, size: i } = o.recommendationConfigs;
7
+ const { strategyId: a, strategy: c, size: i, nodeConfigVersion: s } = o.recommendationConfigs;
8
8
  if (t.currentRecommendationId === e)
9
9
  try {
10
10
  await t.fetchRecommendationProducts();
11
11
  } catch (m) {
12
12
  console.error("[recommendation] product refetch after a strategy change failed", m);
13
13
  }
14
- const r = d(
14
+ const n = f(
15
15
  e,
16
- { strategyId: a, strategy: c, size: i },
16
+ { strategyId: a, strategy: c, size: i, configVersion: s },
17
17
  o.recommendationProducts,
18
- n
18
+ r
19
19
  );
20
- return r || console.error("[recommendation] strategy change did not reach a node", { blockId: e }), r;
20
+ return n || console.error("[recommendation] strategy change did not reach a node", { blockId: e }), n;
21
21
  }
22
22
  export {
23
- u as commitStrategyChange
23
+ h as commitStrategyChange
24
24
  };