@useinsider/guido 3.19.0-beta.6f88fb4 → 3.19.0-beta.80b64cf

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 (80) hide show
  1. package/README.md +21 -3
  2. package/dist/@types/config/schemas.js +78 -57
  3. package/dist/components/Guido.vue.js +4 -4
  4. package/dist/components/Guido.vue2.js +81 -85
  5. package/dist/components/organisms/base/Toaster.vue2.js +13 -12
  6. package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue.js +13 -11
  7. package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue2.js +78 -57
  8. package/dist/components/organisms/extensions/recommendation/LegacyStrategyUpdatedModal.vue.js +18 -0
  9. package/dist/components/organisms/extensions/recommendation/LegacyStrategyUpdatedModal.vue2.js +25 -0
  10. package/dist/components/organisms/extensions/recommendation/RemoveStrategyModal.vue2.js +28 -42
  11. package/dist/components/organisms/header/EditorActions.vue.js +4 -4
  12. package/dist/components/organisms/header/EditorActions.vue2.js +23 -25
  13. package/dist/components/organisms/onboarding/OnboardingWrapper.vue2.js +28 -24
  14. package/dist/components/organisms/onboarding/RecommendationLegacyStrategyOnboarding.vue.js +21 -0
  15. package/dist/components/organisms/onboarding/RecommendationLegacyStrategyOnboarding.vue2.js +46 -0
  16. package/dist/components/organisms/onboarding/RecommendationStrategyOnboarding.vue.js +21 -0
  17. package/dist/components/organisms/onboarding/RecommendationStrategyOnboarding.vue2.js +47 -0
  18. package/dist/composables/useActionsApi.js +44 -43
  19. package/dist/composables/useCodeEditorApi.js +23 -9
  20. package/dist/composables/useCortexBlueprintBridge.js +54 -122
  21. package/dist/composables/useCustomInterfaceAppearance.js +65 -51
  22. package/dist/composables/useEmailTemplateApplier.js +52 -108
  23. package/dist/composables/useHtmlValidator.js +87 -82
  24. package/dist/composables/useLegacyStrategyConversion.js +61 -0
  25. package/dist/composables/useRecommendation.js +40 -35
  26. package/dist/composables/useStripo.js +30 -30
  27. package/dist/composables/useToaster.js +14 -20
  28. package/dist/composables/useTranslations.js +3 -2
  29. package/dist/composables/useVersionHistoryApi.js +33 -24
  30. package/dist/enums/extensions/recommendationBlock.js +49 -33
  31. package/dist/extensions/Blocks/Recommendation/block.js +109 -55
  32. package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +21 -20
  33. package/dist/extensions/Blocks/Recommendation/controls/main/index.js +103 -90
  34. package/dist/extensions/Blocks/Recommendation/controls/main/strategy.js +150 -52
  35. package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +74 -74
  36. package/dist/extensions/Blocks/Recommendation/store/recommendation.js +293 -92
  37. package/dist/extensions/Blocks/Recommendation/utils/legacyStrategyMigration.js +42 -0
  38. package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +26 -16
  39. package/dist/extensions/Blocks/Recommendation/utils/partnerScope.js +26 -0
  40. package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +24 -0
  41. package/dist/extensions/Blocks/Recommendation/validation/requiredFields.js +21 -12
  42. package/dist/guido.css +1 -1
  43. package/dist/services/recommendationApi.js +46 -37
  44. package/dist/src/@types/config/schemas.d.ts +32 -0
  45. package/dist/src/components/organisms/extensions/recommendation/LegacyStrategyUpdatedModal.vue.d.ts +2 -0
  46. package/dist/src/components/organisms/onboarding/RecommendationLegacyStrategyOnboarding.vue.d.ts +2 -0
  47. package/dist/src/components/organisms/onboarding/RecommendationStrategyOnboarding.vue.d.ts +2 -0
  48. package/dist/src/composables/useConfig.d.ts +6 -0
  49. package/dist/src/composables/useCortexBlueprintBridge.d.ts +3 -2
  50. package/dist/src/composables/useEmailTemplateApplier.d.ts +5 -18
  51. package/dist/src/composables/useLegacyStrategyConversion.d.ts +3 -0
  52. package/dist/src/enums/extensions/recommendationBlock.d.ts +7 -1
  53. package/dist/src/extensions/Blocks/Recommendation/block.d.ts +16 -0
  54. package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +1 -0
  55. package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +1 -1
  56. package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +2 -0
  57. package/dist/src/extensions/Blocks/Recommendation/controls/main/strategy.d.ts +10 -0
  58. package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.d.ts +7 -2
  59. package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +167 -1
  60. package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +6 -0
  61. package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMigration.d.ts +32 -0
  62. package/dist/src/extensions/Blocks/Recommendation/utils/partnerScope.d.ts +27 -0
  63. package/dist/src/extensions/Blocks/Recommendation/utils/strategyCommit.d.ts +14 -0
  64. package/dist/src/extensions/Blocks/Recommendation/validation/requiredFields.d.ts +4 -0
  65. package/dist/src/services/recommendationApi.d.ts +2 -1
  66. package/dist/src/stores/config.d.ts +342 -0
  67. package/dist/src/stores/guido-email-editor.d.ts +10 -20
  68. package/dist/src/stores/onboarding.d.ts +808 -10
  69. package/dist/src/utils/stripoEditorApi.d.ts +4 -0
  70. package/dist/static/assets/icons/filled-arrow-rising.svg.js +5 -0
  71. package/dist/static/assets/icons/line-info.svg.js +5 -0
  72. package/dist/static/styles/components/recommendation-strategy.css.js +113 -9
  73. package/dist/static/styles/components/skeleton.css.js +23 -0
  74. package/dist/stores/config.js +74 -60
  75. package/dist/stores/guido-email-editor.js +1 -3
  76. package/dist/stores/onboarding.js +46 -36
  77. package/dist/stores/unsubscribe.js +3 -3
  78. package/dist/utils/stripoEditorApi.js +11 -0
  79. package/dist/utils/templatePreparation.js +55 -55
  80. package/package.json +1 -1
@@ -1,22 +1,27 @@
1
- import { getRecommendationFeedSourceMaps as b, getOperatorOptions as G, PriceAttributes as v } from "../../../../enums/extensions/recommendationBlock.js";
2
- import { useRecommendationApi as D } from "../../../../services/recommendationApi.js";
3
- import { useConfigStore as F } from "../../../../stores/config.js";
4
- import { defineStore as P } from "pinia";
1
+ import { useToaster as D } from "../../../../composables/useToaster.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
+ import { useRecommendationApi as T } from "../../../../services/recommendationApi.js";
6
+ import { useConfigStore as R } from "../../../../stores/config.js";
7
+ import { defineStore as B } from "pinia";
5
8
  import "../constants/selectors.js";
6
- import { DEFAULT_MOBILE_CARDS_IN_ROW as _, DEFAULT_CARDS_IN_ROW as U } from "../constants/layout.js";
7
- import { DEFAULT_NODE_CONFIG as N, EXCLUDED_ALGORITHM_IDS as L } from "../constants/defaultConfig.js";
8
- import { getDefaultProducts as R } from "../templates/utils.js";
9
- import { generateCompleteFilterQuery as k } from "../utils/filterUtil.js";
10
- import { getPartnerRecommendationParams as x } from "../utils/partnerCustomizations.js";
11
- import { sanitizeProductIds as A } from "../utils/productIds.js";
12
- import { isFilterValid as B } from "../validation/filterSchema.js";
13
- import { isConfigValid as M } from "../validation/requiredFields.js";
14
- const u = D();
15
- let f = null, g = null, h = null, S = null;
16
- const p = /* @__PURE__ */ new Map();
17
- function w() {
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 K } from "../utils/productIds.js";
16
+ import { isFilterValid as q } from "../validation/filterSchema.js";
17
+ import { getInvalidFields as H, isConfigValid as J } from "../validation/requiredFields.js";
18
+ const m = T();
19
+ let S = null, p = null, y = null, b = "", k = null, I = 0;
20
+ const g = /* @__PURE__ */ new Map();
21
+ let l = null;
22
+ function _() {
18
23
  return {
19
- cardsInRow: U,
24
+ cardsInRow: z,
20
25
  currencySettings: {
21
26
  name: "USD",
22
27
  value: "USD",
@@ -30,14 +35,19 @@ function w() {
30
35
  productIds: [],
31
36
  id: 1,
32
37
  language: "en_US",
33
- mobileCardsInRow: _,
38
+ mobileCardsInRow: O,
34
39
  mobileLayoutEnabled: !1,
35
40
  orientation: "grid",
36
41
  recommendedProducts: [],
37
42
  sendProductRequestFlag: !1,
38
43
  shuffleProducts: !1,
39
- strategy: "mostPopular",
44
+ // With RRS on, a block that has not been synced yet must not claim an algorithm:
45
+ // that default is what reached buildCampaignUrl and baked a most-popular feed URL
46
+ // for a block the user never configured (SD-149916). Legacy blocks still get their real
47
+ // algorithm from the node-config sync or the save-time seed.
48
+ strategy: R().isFeatureEnabled("reusableRecommendationStrategy") ? "" : "mostPopular",
40
49
  strategyId: "",
50
+ nodeConfigVersion: C,
41
51
  textTrimming: !0,
42
52
  unresponsive: !1,
43
53
  size: "6",
@@ -46,21 +56,23 @@ function w() {
46
56
  priceHideIfSameAsDiscounted: !1
47
57
  };
48
58
  }
49
- function C() {
59
+ function G() {
50
60
  return {
51
- recommendationConfigs: w(),
61
+ recommendationConfigs: _(),
52
62
  recommendationProducts: [],
53
63
  filterStatus: !1,
54
64
  filterSelectionDrawerStatus: !1,
55
65
  assignStrategyDrawerStatus: !1,
56
66
  removeStrategyModalStatus: !1,
67
+ legacyStrategyUpdatedModalStatus: !1,
57
68
  filterGroup: 1,
58
69
  isInitialized: !1,
59
70
  filterSnapshot: null,
60
- syncedConfigFingerprint: null
71
+ syncedConfigFingerprint: null,
72
+ legacyConversionLoading: !1
61
73
  };
62
74
  }
63
- const z = () => ({
75
+ const Q = () => ({
64
76
  recommendationCampaignUrls: {},
65
77
  activePredictiveAlgorithms: [],
66
78
  languages: {},
@@ -69,11 +81,14 @@ const z = () => ({
69
81
  strategies: [],
70
82
  strategiesLoading: !1,
71
83
  strategyUrlTemplates: {},
84
+ strategiesFetched: !1,
85
+ strategiesSettled: !1,
72
86
  blockStates: {},
73
87
  currentRecommendationId: null,
88
+ strategyPanelOpen: !1,
74
89
  configVersion: 0
75
- }), Y = P("guidoRecommendationExtension", {
76
- state: () => z(),
90
+ }), ft = B("guidoRecommendationExtension", {
91
+ state: () => Q(),
77
92
  getters: {
78
93
  // ====================================================================
79
94
  // Proxy Getters — Backward Compatible Access to Current Block State
@@ -83,7 +98,7 @@ const z = () => ({
83
98
  * This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
84
99
  */
85
100
  recommendationConfigs(t) {
86
- return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : w();
101
+ return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : _();
87
102
  },
88
103
  /**
89
104
  * Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
@@ -103,6 +118,15 @@ const z = () => ({
103
118
  removeStrategyModalStatus(t) {
104
119
  return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
105
120
  },
121
+ isLegacyStrategyBlock() {
122
+ return R().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
+ },
106
130
  assignedStrategy(t) {
107
131
  const { strategyId: e } = this.recommendationConfigs;
108
132
  return e ? t.strategies.find((r) => String(r.strategy_id) === e) ?? null : null;
@@ -138,8 +162,8 @@ const z = () => ({
138
162
  return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
139
163
  },
140
164
  getActivePredictiveAlgorithms: (t) => {
141
- const e = b(), r = [];
142
- return t.activePredictiveAlgorithms.filter((n) => !L.includes(n)).forEach((n) => {
165
+ const e = F(), r = [];
166
+ return t.activePredictiveAlgorithms.filter((n) => !V.includes(n)).forEach((n) => {
143
167
  r.push(...e.filter((s) => s.id === n));
144
168
  }), r.map((n) => ({
145
169
  text: n.name,
@@ -157,7 +181,7 @@ const z = () => ({
157
181
  getFilterList() {
158
182
  return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
159
183
  let e;
160
- return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : v.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, {
161
185
  text: t.displayName,
162
186
  value: e,
163
187
  type: t.attributeType
@@ -179,7 +203,7 @@ const z = () => ({
179
203
  setCurrentBlock(t) {
180
204
  this.blockStates[t] || (this.blockStates = {
181
205
  ...this.blockStates,
182
- [t]: C()
206
+ [t]: G()
183
207
  }), this.currentRecommendationId = t;
184
208
  },
185
209
  /**
@@ -201,12 +225,16 @@ const z = () => ({
201
225
  /**
202
226
  * Deep-clones a block's state and mirrors its campaign URL under a new id.
203
227
  * Invoked from `onCreated` when a duplicate is detected (SD-142352).
228
+ *
229
+ * The clone keeps the source's data but drops its "already fetched / already
230
+ * synced" claims for strategy blocks, so it fetches again like a fresh drop
231
+ * (SD-149916).
204
232
  */
205
233
  cloneBlockState(t, e) {
206
234
  const r = this.blockStates[t];
207
235
  if (r) {
208
236
  const o = structuredClone(r);
209
- o.recommendationConfigs.id = e, this.blockStates = {
237
+ o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (o.isInitialized = !1, o.syncedConfigFingerprint = null), this.blockStates = {
210
238
  ...this.blockStates,
211
239
  [e]: o
212
240
  };
@@ -239,7 +267,7 @@ const z = () => ({
239
267
  * `isInitialized`) alone.
240
268
  */
241
269
  seedBlockUrlConfig(t, e) {
242
- const r = (o, c) => o === "." || o === "," || o === " " ? o : c, n = {
270
+ const r = (o, a) => o === "." || o === "," || o === " " ? o : a, n = {
243
271
  name: e.currencyCode,
244
272
  value: e.currencyCode,
245
273
  symbol: e.currencySymbol,
@@ -247,7 +275,7 @@ const z = () => ({
247
275
  decimalCount: String(e.currencyDecimalCount),
248
276
  decimalSeparator: r(e.currencyDecimalSeparator, ","),
249
277
  thousandSeparator: r(e.currencyThousandSeparator, ".")
250
- }, s = !this.blockStates[t], i = s ? C() : this.blockStates[t];
278
+ }, s = !this.blockStates[t], i = s ? G() : this.blockStates[t];
251
279
  i.recommendationConfigs = {
252
280
  ...i.recommendationConfigs,
253
281
  strategy: e.strategy,
@@ -286,7 +314,7 @@ const z = () => ({
286
314
  * Creates a filter with the first available attribute and operator pre-selected.
287
315
  */
288
316
  createDefaultFilter(t, e) {
289
- const [r] = this.getFilterList, [n] = G(r == null ? void 0 : r.type);
317
+ const [r] = this.getFilterList, [n] = N(r == null ? void 0 : r.type);
290
318
  return {
291
319
  type: "standardFilter",
292
320
  attribute: (r == null ? void 0 : r.value) ?? "",
@@ -339,6 +367,12 @@ const z = () => ({
339
367
  closeAssignStrategyDrawer() {
340
368
  this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].assignStrategyDrawerStatus = !1);
341
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
+ },
342
376
  openRemoveStrategyModal() {
343
377
  this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].removeStrategyModalStatus = !0);
344
378
  },
@@ -346,29 +380,130 @@ const z = () => ({
346
380
  this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].removeStrategyModalStatus = !1);
347
381
  },
348
382
  async fetchStrategies() {
349
- if (S) {
350
- await S;
383
+ for (; k; )
384
+ try {
385
+ await k;
386
+ } catch {
387
+ }
388
+ if (this.strategiesFetched)
351
389
  return;
352
- }
353
- S = (async () => {
390
+ const t = I, e = (async () => {
354
391
  this.strategiesLoading = !0;
355
392
  try {
356
- this.strategies = await u.fetchRecommendationStrategies();
393
+ const r = await m.fetchRecommendationStrategies();
394
+ if (t !== I)
395
+ return;
396
+ this.strategies = r, this.strategiesFetched = !0;
357
397
  } finally {
358
- this.strategiesLoading = !1;
398
+ this.strategiesLoading = !1, t === I && (this.strategiesSettled = !0);
359
399
  }
360
400
  })();
401
+ k = e;
361
402
  try {
362
- await S;
403
+ await e;
363
404
  } finally {
364
- S = null;
405
+ k = null;
365
406
  }
366
407
  },
408
+ /**
409
+ * Drops what the store still holds for a block whose account-scoped config was just
410
+ * reset in the document (SD-151945), so the panel re-seeds from the emptied node.
411
+ */
412
+ resetPartnerScopedConfig(t) {
413
+ const e = t.toString();
414
+ if (this.recommendationCampaignUrls[e] !== void 0) {
415
+ const n = { ...this.recommendationCampaignUrls };
416
+ delete n[e], this.recommendationCampaignUrls = n;
417
+ }
418
+ const r = this.blockStates[t];
419
+ r && (r.recommendationConfigs = {
420
+ ...r.recommendationConfigs,
421
+ strategyId: "",
422
+ strategy: "",
423
+ filters: [],
424
+ productIds: []
425
+ }, r.isInitialized = !1, r.syncedConfigFingerprint = null, this.currentRecommendationId === t && this.configVersion++);
426
+ },
427
+ /**
428
+ * Clears what a block inherited from the id it arrived holding, so the panel fetches for it.
429
+ * A re-dropped saved module can keep the source's id — and its "already fetched" entry —
430
+ * while the strategy's product count has moved on (SD-149916).
431
+ */
432
+ resetArrivedBlock(t) {
433
+ const e = this.blockStates[t];
434
+ e != null && e.recommendationConfigs.strategyId && (e.isInitialized = !1, e.syncedConfigFingerprint = null, this.invalidateStrategies(), this.fetchStrategies().catch(() => {
435
+ }));
436
+ },
437
+ invalidateStrategies() {
438
+ this.strategiesFetched = !1, this.strategiesSettled = !1, I += 1;
439
+ },
440
+ /**
441
+ * Opens a Smart Recommender strategy page in a new tab and refreshes the list every time
442
+ * the user comes back. `visibilitychange` only: a `focus` listener would also fire when
443
+ * focus merely returns from the Stripo canvas iframe to the panel, refetching and
444
+ * regenerating the canvas while the user never left the editor (SD-149916).
445
+ *
446
+ * Deliberately NOT one-shot: the strategy tab stays open, so a user can create a second
447
+ * strategy in it and come back again — a listener that disarmed on the first return would
448
+ * leave that one missing from the list. It disarms on the first return AFTER that tab is
449
+ * closed instead, so an ordinary alt-tab later in the session costs nothing. Armed only
450
+ * once the user actually opens a strategy page, so anyone who never does pays nothing.
451
+ * @returns whether a tab actually opened, so callers can skip work that assumes one did
452
+ */
453
+ _armStrategyPageReturn(t) {
454
+ const e = window.open(t, "_blank");
455
+ if (!e)
456
+ return D().showToaster({
457
+ type: A.Error,
458
+ message: L()("discovery-strategy.error-description")
459
+ }), !1;
460
+ e.opener = null, l == null || l();
461
+ let r = !1;
462
+ const n = () => {
463
+ document.hidden || r || (e != null && e.closed && (l == null || l()), r = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
464
+ }).finally(() => {
465
+ r = !1;
466
+ }));
467
+ };
468
+ return document.addEventListener("visibilitychange", n), l = () => {
469
+ document.removeEventListener("visibilitychange", n), l = null;
470
+ }, !0;
471
+ },
472
+ /**
473
+ * Reloads the products of the block the user is on, so an edit made in the strategy tab
474
+ * lands on the canvas instead of waiting for the assign drawer to be reopened.
475
+ *
476
+ * Only the selected block: the canvas regeneration is driven off the active block's
477
+ * product array, so refreshing an unselected block would fetch without redrawing it.
478
+ */
479
+ async _refreshAssignedStrategyProducts() {
480
+ var e;
481
+ const t = this.currentRecommendationId;
482
+ t === null || !((e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId) || await this.fetchRecommendationProducts();
483
+ },
484
+ /** Lets the editor tear the return listeners down when it unmounts. */
485
+ disposeStrategyPageReturn() {
486
+ l == null || l();
487
+ },
488
+ /**
489
+ * Opens Smart Recommender's strategy creation page. Every return refreshes the list so the
490
+ * new strategy is offered; the user picks it themselves.
491
+ */
492
+ openStrategyCreation() {
493
+ return this._armStrategyPageReturn(E.RECOMMENDATION_STRATEGY_CREATE_PATH);
494
+ },
495
+ /**
496
+ * Opens the strategy's edit page. Every return refreshes the list so the block reflects the
497
+ * edited configuration.
498
+ */
499
+ openStrategyEdit(t) {
500
+ return this._armStrategyPageReturn(U(t));
501
+ },
367
502
  async resolveStrategyUrlTemplate(t, e) {
368
503
  const r = typeof t.updated_at == "string" ? t.updated_at : "", n = r ? `${t.strategy_id}:${r}:${e}` : "", s = n ? this.strategyUrlTemplates[n] : void 0;
369
504
  if (s)
370
505
  return s;
371
- const { full_path: i = "" } = await u.generateStrategyEndpoint(t, e) ?? {};
506
+ const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
372
507
  return n && i && (this.strategyUrlTemplates = {
373
508
  ...this.strategyUrlTemplates,
374
509
  [n]: i
@@ -380,24 +515,62 @@ const z = () => ({
380
515
  ...t.size !== void 0 ? { size: String(t.size) } : {}
381
516
  });
382
517
  },
518
+ async convertLegacyStrategy(t, e = { scope: "campaign" }) {
519
+ const r = this.currentRecommendationId;
520
+ if (r === null || !this.blockStates[r])
521
+ throw new Error("[Guido] convertLegacyStrategy called without an active block");
522
+ this.blockStates[r].legacyConversionLoading = !0;
523
+ try {
524
+ const n = await m.migrateLegacyStrategy(t, e);
525
+ this.invalidateStrategies();
526
+ try {
527
+ await this.fetchStrategies();
528
+ } catch (o) {
529
+ console.error("[Guido] strategy listing refresh after conversion failed", o);
530
+ }
531
+ const s = this.strategies.find((o) => String(o.strategy_id) === n), i = this.blockStates[r];
532
+ return i && (i.recommendationConfigs = {
533
+ ...i.recommendationConfigs,
534
+ strategyId: n,
535
+ nodeConfigVersion: C,
536
+ ...(s == null ? void 0 : s.size) !== void 0 ? { size: String(s.size) } : {}
537
+ }), this.currentRecommendationId === r && this.configVersion++, n;
538
+ } finally {
539
+ this.blockStates[r] && (this.blockStates[r].legacyConversionLoading = !1);
540
+ }
541
+ },
542
+ /**
543
+ * Undoes the config half of a conversion whose document write never landed, so the
544
+ * panel and the drawer fall back to "Legacy Strategy" instead of showing an assignment
545
+ * the document never received.
546
+ */
547
+ revertLegacyConversion(t, e) {
548
+ const r = this.blockStates[t];
549
+ r && (r.recommendationConfigs = { ...r.recommendationConfigs, ...e }, this.currentRecommendationId === t && this.configVersion++);
550
+ },
383
551
  removeStrategy() {
384
- this.patchCurrentBlockConfig({ strategyId: "", size: N.size });
552
+ this.patchCurrentBlockConfig({
553
+ strategyId: "",
554
+ strategy: "",
555
+ size: x.size,
556
+ nodeConfigVersion: C
557
+ });
385
558
  },
386
559
  // ====================================================================
387
560
  // Shared Data Fetching (fetched once, used by all blocks)
388
561
  // ====================================================================
389
562
  async fetchRecommendationCreateData() {
390
563
  if (!this.activePredictiveAlgorithms.length) {
391
- if (f) {
392
- await f;
564
+ if (S) {
565
+ await S;
393
566
  return;
394
567
  }
395
- f = (async () => {
568
+ S = (async () => {
396
569
  const {
397
570
  activePredictiveAlgorithms: t,
398
571
  languages: e,
399
572
  currencies: r
400
- } = await u.fetchRecommendationCreateData();
573
+ } = await m.fetchRecommendationCreateData();
401
574
  if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
402
575
  const n = this.blockStates[this.currentRecommendationId];
403
576
  n.filterStatus = !!n.recommendationConfigs.filters.length;
@@ -405,26 +578,26 @@ const z = () => ({
405
578
  this.currencyList = r;
406
579
  })();
407
580
  try {
408
- await f;
581
+ await S;
409
582
  } finally {
410
- f = null;
583
+ S = null;
411
584
  }
412
585
  }
413
586
  },
414
587
  async fetchRecommendationFilters() {
415
588
  if (!Object.keys(this.filterList).length) {
416
- if (g) {
417
- await g;
589
+ if (p) {
590
+ await p;
418
591
  return;
419
592
  }
420
- g = (async () => {
421
- const t = await u.fetchRecommendationFilters();
593
+ p = (async () => {
594
+ const t = await m.fetchRecommendationFilters();
422
595
  this.filterList = t;
423
596
  })();
424
597
  try {
425
- await g;
598
+ await p;
426
599
  } finally {
427
- g = null;
600
+ p = null;
428
601
  }
429
602
  }
430
603
  },
@@ -453,7 +626,7 @@ const z = () => ({
453
626
  const n = [...e.recommendationConfigs.filters];
454
627
  n[r] = {
455
628
  ...t,
456
- isValid: B(t)
629
+ isValid: q(t)
457
630
  }, e.recommendationConfigs.filters = n;
458
631
  }
459
632
  },
@@ -467,10 +640,10 @@ const z = () => ({
467
640
  let i = 1;
468
641
  n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
469
642
  } else {
470
- const i = [...new Set(n.map((c) => c.filterGroup))].sort((c, a) => c - a), o = new Map(i.map((c, a) => [c, a + 1]));
471
- n = n.map((c) => ({
472
- ...c,
473
- filterGroup: o.get(c.filterGroup) ?? c.filterGroup
643
+ const i = [...new Set(n.map((a) => a.filterGroup))].sort((a, d) => a - d), o = new Map(i.map((a, d) => [a, d + 1]));
644
+ n = n.map((a) => ({
645
+ ...a,
646
+ filterGroup: o.get(a.filterGroup) ?? a.filterGroup
474
647
  }));
475
648
  }
476
649
  e.recommendationConfigs.filters = n;
@@ -491,7 +664,7 @@ const z = () => ({
491
664
  }), e.recommendationConfigs.filters = r;
492
665
  },
493
666
  generateFilterQuery() {
494
- return k(this.recommendationConfigs.filters);
667
+ return P(this.recommendationConfigs.filters);
495
668
  },
496
669
  /**
497
670
  * Validation-only check invoked at save-CTA time. Defined as an action
@@ -499,33 +672,52 @@ const z = () => ({
499
672
  * every block's recommendationConfigs across user edits.
500
673
  */
501
674
  hasInvalidBlock() {
502
- return Object.values(this.blockStates).some((t) => !M(t.recommendationConfigs, this));
675
+ return Object.values(this.blockStates).some((t) => !J(t.recommendationConfigs, this));
676
+ },
677
+ /**
678
+ * Which required fields are missing across the design's blocks, so the save
679
+ * toaster can name the cause instead of always showing the generic message.
680
+ */
681
+ invalidBlockFields() {
682
+ return Object.values(this.blockStates).flatMap((t) => H(t.recommendationConfigs, this));
503
683
  },
504
684
  // ====================================================================
505
685
  // Per-Block Product Fetching
506
686
  // ====================================================================
507
687
  async fetchRecommendationProducts() {
508
- if (!(this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])) {
509
- if (h) {
510
- await h;
511
- return;
512
- }
513
- h = this._doFetchProducts();
514
- try {
515
- await h;
516
- } finally {
517
- h = null;
518
- }
688
+ if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
689
+ return;
690
+ const t = [
691
+ this.currentRecommendationId,
692
+ this.configVersion,
693
+ I
694
+ ].join(":");
695
+ if (y && b === t) {
696
+ await y;
697
+ return;
698
+ }
699
+ b = t, y = this._doFetchProducts();
700
+ try {
701
+ await y;
702
+ } finally {
703
+ b === t && (y = null, b = "");
519
704
  }
520
705
  },
521
706
  async _doFetchProducts() {
522
- var d;
523
- const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = F();
707
+ var h;
708
+ const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = R();
524
709
  if (r.strategyId && n.isFeatureEnabled("reusableRecommendationStrategy")) {
525
710
  await this._doFetchStrategyProducts(t);
526
711
  return;
527
712
  }
528
- const s = r.filters.filter((m) => m.isValid), i = k(s), o = ((d = b().find((m) => m.key === r.strategy)) == null ? void 0 : d.path) || "", c = parseInt(r.size) || 6, a = {
713
+ const s = (g.get(t) ?? 0) + 1;
714
+ g.set(t, s);
715
+ const i = parseInt(r.size) || 6;
716
+ if (!r.strategy) {
717
+ this._setBlockProducts(t, [], i);
718
+ return;
719
+ }
720
+ 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 = {
529
721
  locale: r.language,
530
722
  currency: r.currencySettings.value,
531
723
  partnerName: n.partnerName,
@@ -533,21 +725,30 @@ const z = () => ({
533
725
  details: !0,
534
726
  campaignId: n.variationId
535
727
  };
536
- r.strategy === "manualMerchandising" ? a.productId = A(r.productIds) : r.strategy === "similarViewed" && (a.productId = "{itemId}"), r.strategy === "userBased" && (a.userId = "{user_id}"), i && (a.filter = i), r.shuffleProducts && (a.shuffle = !0), Object.assign(
537
- a,
538
- x(n.partnerName, r.strategy)
728
+ r.strategy === "manualMerchandising" ? c.productId = K(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(
729
+ c,
730
+ $(n.partnerName, r.strategy)
539
731
  );
540
- let l;
732
+ let u;
541
733
  try {
542
- l = await u.fetchRecommendationProducts(o, a);
734
+ u = await m.fetchRecommendationProducts(d, c);
543
735
  } catch {
544
- l = [];
736
+ u = [];
545
737
  }
546
- this._setBlockProducts(t, l, c);
738
+ g.get(t) === s && this._setBlockProducts(t, u, i);
739
+ },
740
+ /**
741
+ * Block-scoped counterpart of `fetchRecommendationProducts`, which only ever serves the
742
+ * selected block. The legacy conversion must refresh the products of the block that
743
+ * started it even after the user selected another one.
744
+ */
745
+ async fetchStrategyProductsForBlock(t) {
746
+ var e;
747
+ (e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId && await this._doFetchStrategyProducts(t);
547
748
  },
548
749
  async _doFetchStrategyProducts(t) {
549
- const e = (p.get(t) ?? 0) + 1;
550
- p.set(t, e);
750
+ const e = (g.get(t) ?? 0) + 1;
751
+ g.set(t, e);
551
752
  const { recommendationConfigs: r } = this.blockStates[t];
552
753
  let n = [], s = parseInt(r.size) || 6;
553
754
  try {
@@ -557,25 +758,25 @@ const z = () => ({
557
758
  );
558
759
  if (i) {
559
760
  s = parseInt(String(i.size ?? "")) || s;
560
- const o = r.currencySettings.value, a = (await this.resolveStrategyUrlTemplate(i, o)).replaceAll("{locale}", r.language).replaceAll("{currency}", o), l = a.indexOf("?"), d = l === -1 ? a : a.slice(0, l), m = (l === -1 ? "" : a.slice(l + 1)).split("&").filter((I) => I && !I.startsWith("user_id=")), y = m.length ? `${d}?${m.join("&")}` : d;
561
- y && (n = await u.fetchRecommendationProductsByUrl(y));
761
+ 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;
762
+ f && (n = await m.fetchRecommendationProductsByUrl(f));
562
763
  }
563
764
  } catch {
564
765
  n = [];
565
766
  }
566
- p.get(t) === e && this._setBlockProducts(t, n, s);
767
+ g.get(t) === e && this._setBlockProducts(t, n, s);
567
768
  },
568
769
  _setBlockProducts(t, e, r) {
569
770
  if (!this.blockStates[t])
570
771
  return;
571
- const n = e.length > 0 ? e : R(r);
772
+ const n = e.length > 0 ? e : w(r);
572
773
  this.blockStates[t].recommendationProducts = [
573
774
  ...n.slice(0, r),
574
- ...R(Math.max(0, r - n.length))
775
+ ...w(Math.max(0, r - n.length))
575
776
  ];
576
777
  }
577
778
  }
578
779
  });
579
780
  export {
580
- Y as useRecommendationExtensionStore
781
+ ft as useRecommendationExtensionStore
581
782
  };