@useinsider/guido 3.20.1 → 3.20.2-beta.87fb8ae
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.
- package/dist/composables/useLegacyStrategyConversion.js +16 -16
- package/dist/extensions/Blocks/Recommendation/controls/main/index.js +296 -223
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +219 -205
- package/dist/extensions/Blocks/Recommendation/utils/blockRefresh.js +19 -0
- package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +51 -36
- package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +31 -35
- package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +18 -3
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +8 -1
- package/dist/src/extensions/Blocks/Recommendation/utils/blockRefresh.d.ts +17 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/nodeConfigWriter.d.ts +7 -0
- package/package.json +1 -1
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import { useToaster as
|
|
2
|
-
import { useTranslations as
|
|
3
|
-
import { getRecommendationFeedSourceMaps as
|
|
4
|
-
import { ToasterTypeOptions as
|
|
5
|
-
import { useRecommendationApi as
|
|
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 z, strategyCreatePath as B, 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
|
|
7
|
+
import { defineStore as V } from "pinia";
|
|
8
8
|
import "../constants/selectors.js";
|
|
9
|
-
import { DEFAULT_MOBILE_CARDS_IN_ROW as
|
|
10
|
-
import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as
|
|
11
|
-
import { getDefaultProducts as
|
|
12
|
-
import { generateCompleteFilterQuery as
|
|
13
|
-
import { isLegacyStrategyConfig as
|
|
14
|
-
import { getPartnerRecommendationParams as
|
|
15
|
-
import { sanitizeProductIds as
|
|
16
|
-
import { isFilterValid as
|
|
17
|
-
import { getInvalidFields as
|
|
18
|
-
const
|
|
19
|
-
let
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
import { getDefaultProducts as w } from "../templates/utils.js";
|
|
12
|
+
import { generateCompleteFilterQuery as P } from "../utils/filterUtil.js";
|
|
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 I = /* @__PURE__ */ new Map();
|
|
21
|
+
let k = null, b = 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;
|
|
24
26
|
}
|
|
25
27
|
let l = null;
|
|
26
|
-
function
|
|
28
|
+
function D() {
|
|
27
29
|
return {
|
|
28
|
-
cardsInRow:
|
|
30
|
+
cardsInRow: x,
|
|
29
31
|
currencySettings: {
|
|
30
32
|
name: "USD",
|
|
31
33
|
value: "USD",
|
|
@@ -39,7 +41,7 @@ function L() {
|
|
|
39
41
|
productIds: [],
|
|
40
42
|
id: 1,
|
|
41
43
|
language: "en_US",
|
|
42
|
-
mobileCardsInRow:
|
|
44
|
+
mobileCardsInRow: A,
|
|
43
45
|
mobileLayoutEnabled: !1,
|
|
44
46
|
orientation: "grid",
|
|
45
47
|
recommendedProducts: [],
|
|
@@ -60,9 +62,9 @@ function L() {
|
|
|
60
62
|
priceHideIfSameAsDiscounted: !1
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
|
-
function
|
|
65
|
+
function G() {
|
|
64
66
|
return {
|
|
65
|
-
recommendationConfigs:
|
|
67
|
+
recommendationConfigs: D(),
|
|
66
68
|
recommendationProducts: [],
|
|
67
69
|
filterStatus: !1,
|
|
68
70
|
filterSelectionDrawerStatus: !1,
|
|
@@ -73,10 +75,12 @@ function _() {
|
|
|
73
75
|
isInitialized: !1,
|
|
74
76
|
filterSnapshot: null,
|
|
75
77
|
syncedConfigFingerprint: null,
|
|
76
|
-
legacyConversionLoading: !1
|
|
78
|
+
legacyConversionLoading: !1,
|
|
79
|
+
configVersion: 0,
|
|
80
|
+
adoptedSizeVersion: 0
|
|
77
81
|
};
|
|
78
82
|
}
|
|
79
|
-
const
|
|
83
|
+
const X = () => ({
|
|
80
84
|
recommendationCampaignUrls: {},
|
|
81
85
|
activePredictiveAlgorithms: [],
|
|
82
86
|
languages: {},
|
|
@@ -91,8 +95,8 @@ const Y = () => ({
|
|
|
91
95
|
currentRecommendationId: null,
|
|
92
96
|
strategyPanelOpen: !1,
|
|
93
97
|
configVersion: 0
|
|
94
|
-
}),
|
|
95
|
-
state: () =>
|
|
98
|
+
}), ht = V("guidoRecommendationExtension", {
|
|
99
|
+
state: () => X(),
|
|
96
100
|
getters: {
|
|
97
101
|
// ====================================================================
|
|
98
102
|
// Proxy Getters — Backward Compatible Access to Current Block State
|
|
@@ -102,7 +106,7 @@ const Y = () => ({
|
|
|
102
106
|
* This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
|
|
103
107
|
*/
|
|
104
108
|
recommendationConfigs(t) {
|
|
105
|
-
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs :
|
|
109
|
+
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : D();
|
|
106
110
|
},
|
|
107
111
|
/**
|
|
108
112
|
* Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
|
|
@@ -123,7 +127,7 @@ const Y = () => ({
|
|
|
123
127
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
|
|
124
128
|
},
|
|
125
129
|
isLegacyStrategyBlock() {
|
|
126
|
-
return R().isFeatureEnabled("reusableRecommendationStrategy") &&
|
|
130
|
+
return R().isFeatureEnabled("reusableRecommendationStrategy") && $(this.recommendationConfigs);
|
|
127
131
|
},
|
|
128
132
|
legacyConversionLoading(t) {
|
|
129
133
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
|
|
@@ -133,7 +137,7 @@ const Y = () => ({
|
|
|
133
137
|
},
|
|
134
138
|
assignedStrategy(t) {
|
|
135
139
|
const { strategyId: e } = this.recommendationConfigs;
|
|
136
|
-
return e ? t.strategies.find((
|
|
140
|
+
return e ? t.strategies.find((n) => String(n.strategy_id) === e) ?? null : null;
|
|
137
141
|
},
|
|
138
142
|
/**
|
|
139
143
|
* Proxy getter: delegates to blockStates[currentRecommendationId].filterStatus
|
|
@@ -163,19 +167,19 @@ const Y = () => ({
|
|
|
163
167
|
},
|
|
164
168
|
getUniqueFilterGroups() {
|
|
165
169
|
const { filters: t } = this.recommendationConfigs;
|
|
166
|
-
return [...new Set(t.map((e) => e.filterGroup))].sort((e,
|
|
170
|
+
return [...new Set(t.map((e) => e.filterGroup))].sort((e, n) => e - n);
|
|
167
171
|
},
|
|
168
172
|
getActivePredictiveAlgorithms: (t) => {
|
|
169
|
-
const e =
|
|
170
|
-
return t.activePredictiveAlgorithms.filter((
|
|
171
|
-
|
|
172
|
-
}),
|
|
173
|
-
text:
|
|
174
|
-
value:
|
|
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
|
|
175
179
|
}));
|
|
176
180
|
},
|
|
177
|
-
getLanguages: (t) => Object.entries(t.languages).map(([e,
|
|
178
|
-
text:
|
|
181
|
+
getLanguages: (t) => Object.entries(t.languages).map(([e, n]) => ({
|
|
182
|
+
text: n,
|
|
179
183
|
value: e
|
|
180
184
|
})),
|
|
181
185
|
getCurrencySymbolList: (t) => t.currencyList.map((e) => ({
|
|
@@ -185,7 +189,7 @@ const Y = () => ({
|
|
|
185
189
|
getFilterList() {
|
|
186
190
|
return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
|
|
187
191
|
let e;
|
|
188
|
-
return t.type === "productAttribute" ? e = `product_attributes.${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, {
|
|
189
193
|
text: t.displayName,
|
|
190
194
|
value: e,
|
|
191
195
|
type: t.attributeType
|
|
@@ -207,7 +211,7 @@ const Y = () => ({
|
|
|
207
211
|
setCurrentBlock(t) {
|
|
208
212
|
this.blockStates[t] || (this.blockStates = {
|
|
209
213
|
...this.blockStates,
|
|
210
|
-
[t]:
|
|
214
|
+
[t]: G()
|
|
211
215
|
}), this.currentRecommendationId = t;
|
|
212
216
|
},
|
|
213
217
|
/**
|
|
@@ -217,13 +221,13 @@ const Y = () => ({
|
|
|
217
221
|
removeBlockState(t) {
|
|
218
222
|
const e = t.toString();
|
|
219
223
|
if (this.recommendationCampaignUrls[e]) {
|
|
220
|
-
const
|
|
221
|
-
delete
|
|
224
|
+
const r = { ...this.recommendationCampaignUrls };
|
|
225
|
+
delete r[e], this.recommendationCampaignUrls = r;
|
|
222
226
|
}
|
|
223
|
-
const
|
|
224
|
-
if (delete
|
|
225
|
-
const
|
|
226
|
-
this.currentRecommendationId =
|
|
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;
|
|
227
231
|
}
|
|
228
232
|
},
|
|
229
233
|
/**
|
|
@@ -235,18 +239,18 @@ const Y = () => ({
|
|
|
235
239
|
* (SD-149916).
|
|
236
240
|
*/
|
|
237
241
|
cloneBlockState(t, e) {
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
240
|
-
const
|
|
241
|
-
|
|
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 = {
|
|
242
246
|
...this.blockStates,
|
|
243
|
-
[e]:
|
|
247
|
+
[e]: s
|
|
244
248
|
};
|
|
245
249
|
}
|
|
246
|
-
const
|
|
250
|
+
const r = t.toString(), o = e.toString(), i = this.recommendationCampaignUrls[r];
|
|
247
251
|
i && (this.recommendationCampaignUrls = {
|
|
248
252
|
...this.recommendationCampaignUrls,
|
|
249
|
-
[
|
|
253
|
+
[o]: i
|
|
250
254
|
});
|
|
251
255
|
},
|
|
252
256
|
/**
|
|
@@ -271,15 +275,15 @@ const Y = () => ({
|
|
|
271
275
|
* `isInitialized`) alone.
|
|
272
276
|
*/
|
|
273
277
|
seedBlockUrlConfig(t, e) {
|
|
274
|
-
const
|
|
278
|
+
const n = (s, a) => s === "." || s === "," || s === " " ? s : a, r = {
|
|
275
279
|
name: e.currencyCode,
|
|
276
280
|
value: e.currencyCode,
|
|
277
281
|
symbol: e.currencySymbol,
|
|
278
282
|
alignment: e.currencyAlignment === "before" ? "0" : "1",
|
|
279
283
|
decimalCount: String(e.currencyDecimalCount),
|
|
280
|
-
decimalSeparator:
|
|
281
|
-
thousandSeparator:
|
|
282
|
-
},
|
|
284
|
+
decimalSeparator: n(e.currencyDecimalSeparator, ","),
|
|
285
|
+
thousandSeparator: n(e.currencyThousandSeparator, ".")
|
|
286
|
+
}, o = !this.blockStates[t], i = o ? G() : this.blockStates[t];
|
|
283
287
|
i.recommendationConfigs = {
|
|
284
288
|
...i.recommendationConfigs,
|
|
285
289
|
strategy: e.strategy,
|
|
@@ -289,8 +293,8 @@ const Y = () => ({
|
|
|
289
293
|
productIds: e.productIds,
|
|
290
294
|
filters: e.filters,
|
|
291
295
|
shuffleProducts: e.shuffleProducts,
|
|
292
|
-
currencySettings:
|
|
293
|
-
},
|
|
296
|
+
currencySettings: r
|
|
297
|
+
}, o && (this.blockStates = {
|
|
294
298
|
...this.blockStates,
|
|
295
299
|
[t]: i
|
|
296
300
|
});
|
|
@@ -302,27 +306,27 @@ const Y = () => ({
|
|
|
302
306
|
patchCurrentBlockConfig(t, e = {}) {
|
|
303
307
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
304
308
|
return;
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
...
|
|
309
|
+
const n = this.blockStates[this.currentRecommendationId];
|
|
310
|
+
n.recommendationConfigs = {
|
|
311
|
+
...n.recommendationConfigs,
|
|
308
312
|
...t,
|
|
309
313
|
currencySettings: {
|
|
310
|
-
...
|
|
314
|
+
...n.recommendationConfigs.currencySettings,
|
|
311
315
|
...t.currencySettings || {}
|
|
312
316
|
}
|
|
313
317
|
};
|
|
314
|
-
const { triggerRefetch:
|
|
315
|
-
|
|
318
|
+
const { triggerRefetch: r = !0 } = e;
|
|
319
|
+
r && (n.configVersion++, this.configVersion++);
|
|
316
320
|
},
|
|
317
321
|
/**
|
|
318
322
|
* Creates a filter with the first available attribute and operator pre-selected.
|
|
319
323
|
*/
|
|
320
324
|
createDefaultFilter(t, e) {
|
|
321
|
-
const [
|
|
325
|
+
const [n] = this.getFilterList, [r] = M(n == null ? void 0 : n.type);
|
|
322
326
|
return {
|
|
323
327
|
type: "standardFilter",
|
|
324
|
-
attribute: (
|
|
325
|
-
operator: (
|
|
328
|
+
attribute: (n == null ? void 0 : n.value) ?? "",
|
|
329
|
+
operator: (r == null ? void 0 : r.value) ?? "",
|
|
326
330
|
innerGroupOperator: "*",
|
|
327
331
|
outerGroupOperator: "*",
|
|
328
332
|
filterNumber: e,
|
|
@@ -394,10 +398,10 @@ const Y = () => ({
|
|
|
394
398
|
const t = b, e = (async () => {
|
|
395
399
|
this.strategiesLoading = !0;
|
|
396
400
|
try {
|
|
397
|
-
const
|
|
401
|
+
const n = await m.fetchRecommendationStrategies();
|
|
398
402
|
if (t !== b)
|
|
399
403
|
return;
|
|
400
|
-
this.strategies =
|
|
404
|
+
this.strategies = n, this.strategiesFetched = !0;
|
|
401
405
|
} finally {
|
|
402
406
|
this.strategiesLoading = !1, t === b && (this.strategiesSettled = !0);
|
|
403
407
|
}
|
|
@@ -438,20 +442,20 @@ const Y = () => ({
|
|
|
438
442
|
_armStrategyPageReturn(t) {
|
|
439
443
|
const e = window.open(t, "_blank");
|
|
440
444
|
if (!e)
|
|
441
|
-
return
|
|
442
|
-
type:
|
|
443
|
-
message:
|
|
445
|
+
return L().showToaster({
|
|
446
|
+
type: E.Error,
|
|
447
|
+
message: U()("discovery-strategy.error-description")
|
|
444
448
|
}), !1;
|
|
445
449
|
e.opener = null, l == null || l();
|
|
446
|
-
let
|
|
447
|
-
const
|
|
448
|
-
document.hidden ||
|
|
450
|
+
let n = !1;
|
|
451
|
+
const r = () => {
|
|
452
|
+
document.hidden || n || (e != null && e.closed && (l == null || l()), n = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
|
|
449
453
|
}).finally(() => {
|
|
450
|
-
|
|
454
|
+
n = !1;
|
|
451
455
|
}));
|
|
452
456
|
};
|
|
453
|
-
return document.addEventListener("visibilitychange",
|
|
454
|
-
document.removeEventListener("visibilitychange",
|
|
457
|
+
return document.addEventListener("visibilitychange", r), l = () => {
|
|
458
|
+
document.removeEventListener("visibilitychange", r), l = null;
|
|
455
459
|
}, !0;
|
|
456
460
|
},
|
|
457
461
|
/**
|
|
@@ -482,16 +486,16 @@ const Y = () => ({
|
|
|
482
486
|
* edited configuration.
|
|
483
487
|
*/
|
|
484
488
|
openStrategyEdit(t) {
|
|
485
|
-
return this._armStrategyPageReturn(
|
|
489
|
+
return this._armStrategyPageReturn(z(t));
|
|
486
490
|
},
|
|
487
491
|
async resolveStrategyUrlTemplate(t, e) {
|
|
488
|
-
const
|
|
489
|
-
if (
|
|
490
|
-
return
|
|
491
|
-
const { full_path: i = "" } = await
|
|
492
|
-
return
|
|
492
|
+
const n = typeof t.updated_at == "string" ? t.updated_at : "", r = n ? `${t.strategy_id}:${n}:${e}` : "", o = r ? this.strategyUrlTemplates[r] : void 0;
|
|
493
|
+
if (o)
|
|
494
|
+
return o;
|
|
495
|
+
const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
|
|
496
|
+
return r && i && (this.strategyUrlTemplates = {
|
|
493
497
|
...this.strategyUrlTemplates,
|
|
494
|
-
[
|
|
498
|
+
[r]: i
|
|
495
499
|
}), i;
|
|
496
500
|
},
|
|
497
501
|
assignStrategy(t) {
|
|
@@ -501,27 +505,27 @@ const Y = () => ({
|
|
|
501
505
|
});
|
|
502
506
|
},
|
|
503
507
|
async convertLegacyStrategy(t, e = { scope: "campaign" }) {
|
|
504
|
-
const
|
|
505
|
-
if (
|
|
508
|
+
const n = this.currentRecommendationId;
|
|
509
|
+
if (n === null || !this.blockStates[n])
|
|
506
510
|
throw new Error("[Guido] convertLegacyStrategy called without an active block");
|
|
507
|
-
this.blockStates[
|
|
511
|
+
this.blockStates[n].legacyConversionLoading = !0;
|
|
508
512
|
try {
|
|
509
|
-
const
|
|
513
|
+
const r = await m.migrateLegacyStrategy(t, e);
|
|
510
514
|
this.invalidateStrategies();
|
|
511
515
|
try {
|
|
512
516
|
await this.fetchStrategies();
|
|
513
|
-
} catch (
|
|
514
|
-
console.error("[Guido] strategy listing refresh after conversion failed",
|
|
517
|
+
} catch (s) {
|
|
518
|
+
console.error("[Guido] strategy listing refresh after conversion failed", s);
|
|
515
519
|
}
|
|
516
|
-
const
|
|
520
|
+
const o = this.strategies.find((s) => String(s.strategy_id) === r), i = this.blockStates[n];
|
|
517
521
|
return i && (i.recommendationConfigs = {
|
|
518
522
|
...i.recommendationConfigs,
|
|
519
|
-
strategyId:
|
|
523
|
+
strategyId: r,
|
|
520
524
|
nodeConfigVersion: C,
|
|
521
|
-
...(
|
|
522
|
-
}), this.currentRecommendationId ===
|
|
525
|
+
...(o == null ? void 0 : o.size) !== void 0 ? { size: String(o.size) } : {}
|
|
526
|
+
}, i.configVersion++), this.currentRecommendationId === n && this.configVersion++, r;
|
|
523
527
|
} finally {
|
|
524
|
-
this.blockStates[
|
|
528
|
+
this.blockStates[n] && (this.blockStates[n].legacyConversionLoading = !1);
|
|
525
529
|
}
|
|
526
530
|
},
|
|
527
531
|
/**
|
|
@@ -530,14 +534,14 @@ const Y = () => ({
|
|
|
530
534
|
* the document never received.
|
|
531
535
|
*/
|
|
532
536
|
revertLegacyConversion(t, e) {
|
|
533
|
-
const
|
|
534
|
-
|
|
537
|
+
const n = this.blockStates[t];
|
|
538
|
+
n && (n.recommendationConfigs = { ...n.recommendationConfigs, ...e }, n.configVersion++, this.currentRecommendationId === t && this.configVersion++);
|
|
535
539
|
},
|
|
536
540
|
removeStrategy() {
|
|
537
541
|
this.patchCurrentBlockConfig({
|
|
538
542
|
strategyId: "",
|
|
539
543
|
strategy: "",
|
|
540
|
-
size:
|
|
544
|
+
size: T.size,
|
|
541
545
|
nodeConfigVersion: C
|
|
542
546
|
});
|
|
543
547
|
},
|
|
@@ -546,26 +550,26 @@ const Y = () => ({
|
|
|
546
550
|
// ====================================================================
|
|
547
551
|
async fetchRecommendationCreateData() {
|
|
548
552
|
if (!this.activePredictiveAlgorithms.length) {
|
|
549
|
-
if (
|
|
550
|
-
await
|
|
553
|
+
if (p) {
|
|
554
|
+
await p;
|
|
551
555
|
return;
|
|
552
556
|
}
|
|
553
|
-
|
|
557
|
+
p = (async () => {
|
|
554
558
|
const {
|
|
555
559
|
activePredictiveAlgorithms: t,
|
|
556
560
|
languages: e,
|
|
557
|
-
currencies:
|
|
558
|
-
} = await
|
|
561
|
+
currencies: n
|
|
562
|
+
} = await m.fetchRecommendationCreateData();
|
|
559
563
|
if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
|
|
560
|
-
const
|
|
561
|
-
|
|
564
|
+
const r = this.blockStates[this.currentRecommendationId];
|
|
565
|
+
r.filterStatus = !!r.recommendationConfigs.filters.length;
|
|
562
566
|
}
|
|
563
|
-
this.currencyList =
|
|
567
|
+
this.currencyList = n;
|
|
564
568
|
})();
|
|
565
569
|
try {
|
|
566
|
-
await
|
|
570
|
+
await p;
|
|
567
571
|
} finally {
|
|
568
|
-
|
|
572
|
+
p = null;
|
|
569
573
|
}
|
|
570
574
|
}
|
|
571
575
|
},
|
|
@@ -576,7 +580,7 @@ const Y = () => ({
|
|
|
576
580
|
return;
|
|
577
581
|
}
|
|
578
582
|
y = (async () => {
|
|
579
|
-
const t = await
|
|
583
|
+
const t = await m.fetchRecommendationFilters();
|
|
580
584
|
this.filterList = t;
|
|
581
585
|
})();
|
|
582
586
|
try {
|
|
@@ -597,59 +601,59 @@ const Y = () => ({
|
|
|
597
601
|
deleteFilterGroup(t) {
|
|
598
602
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
599
603
|
return;
|
|
600
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
601
|
-
e.recommendationConfigs.filters =
|
|
604
|
+
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]));
|
|
605
|
+
e.recommendationConfigs.filters = n.map((i) => ({
|
|
602
606
|
...i,
|
|
603
|
-
filterGroup:
|
|
607
|
+
filterGroup: o.get(i.filterGroup) ?? i.filterGroup
|
|
604
608
|
}));
|
|
605
609
|
},
|
|
606
610
|
updateFilter(t) {
|
|
607
611
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
608
612
|
return;
|
|
609
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
610
|
-
if (
|
|
611
|
-
const
|
|
612
|
-
n
|
|
613
|
+
const e = this.blockStates[this.currentRecommendationId], n = e.recommendationConfigs.filters.findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
|
|
614
|
+
if (n !== -1) {
|
|
615
|
+
const r = [...e.recommendationConfigs.filters];
|
|
616
|
+
r[n] = {
|
|
613
617
|
...t,
|
|
614
|
-
isValid:
|
|
615
|
-
}, e.recommendationConfigs.filters =
|
|
618
|
+
isValid: H(t)
|
|
619
|
+
}, e.recommendationConfigs.filters = r;
|
|
616
620
|
}
|
|
617
621
|
},
|
|
618
622
|
deleteFilter(t) {
|
|
619
623
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
620
624
|
return;
|
|
621
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
622
|
-
if (
|
|
623
|
-
let
|
|
624
|
-
if (
|
|
625
|
+
const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters].findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
|
|
626
|
+
if (n !== -1) {
|
|
627
|
+
let r = [...e.recommendationConfigs.filters];
|
|
628
|
+
if (r.splice(n, 1), r.some((i) => i.filterGroup === t.filterGroup)) {
|
|
625
629
|
let i = 1;
|
|
626
|
-
|
|
630
|
+
r = r.map((s) => s.filterGroup === t.filterGroup ? { ...s, filterNumber: i++ } : s);
|
|
627
631
|
} else {
|
|
628
|
-
const i = [...new Set(
|
|
629
|
-
|
|
632
|
+
const i = [...new Set(r.map((a) => a.filterGroup))].sort((a, d) => a - d), s = new Map(i.map((a, d) => [a, d + 1]));
|
|
633
|
+
r = r.map((a) => ({
|
|
630
634
|
...a,
|
|
631
|
-
filterGroup:
|
|
635
|
+
filterGroup: s.get(a.filterGroup) ?? a.filterGroup
|
|
632
636
|
}));
|
|
633
637
|
}
|
|
634
|
-
e.recommendationConfigs.filters =
|
|
638
|
+
e.recommendationConfigs.filters = r;
|
|
635
639
|
}
|
|
636
640
|
},
|
|
637
641
|
addFilter(t) {
|
|
638
642
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
639
643
|
return;
|
|
640
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
641
|
-
(
|
|
642
|
-
).length + 1, i =
|
|
643
|
-
i !== -1 ?
|
|
644
|
+
const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters], o = n.filter(
|
|
645
|
+
(s) => s.filterGroup === t.filterGroup
|
|
646
|
+
).length + 1, i = n.findLastIndex((s) => s.filterGroup === t.filterGroup);
|
|
647
|
+
i !== -1 ? n.splice(i + 1, 0, {
|
|
644
648
|
...t,
|
|
645
|
-
filterNumber:
|
|
646
|
-
}) :
|
|
649
|
+
filterNumber: o
|
|
650
|
+
}) : n.push({
|
|
647
651
|
...t,
|
|
648
|
-
filterNumber:
|
|
649
|
-
}), e.recommendationConfigs.filters =
|
|
652
|
+
filterNumber: o
|
|
653
|
+
}), e.recommendationConfigs.filters = n;
|
|
650
654
|
},
|
|
651
655
|
generateFilterQuery() {
|
|
652
|
-
return
|
|
656
|
+
return P(this.recommendationConfigs.filters);
|
|
653
657
|
},
|
|
654
658
|
/**
|
|
655
659
|
* Validation-only check invoked at save-CTA time. Defined as an action
|
|
@@ -657,70 +661,77 @@ const Y = () => ({
|
|
|
657
661
|
* every block's recommendationConfigs across user edits.
|
|
658
662
|
*/
|
|
659
663
|
hasInvalidBlock() {
|
|
660
|
-
return Object.values(this.blockStates).some((t) => !
|
|
664
|
+
return Object.values(this.blockStates).some((t) => !Q(t.recommendationConfigs, this));
|
|
661
665
|
},
|
|
662
666
|
/**
|
|
663
667
|
* Which required fields are missing across the design's blocks, so the save
|
|
664
668
|
* toaster can name the cause instead of always showing the generic message.
|
|
665
669
|
*/
|
|
666
670
|
invalidBlockFields() {
|
|
667
|
-
return Object.values(this.blockStates).flatMap((t) =>
|
|
671
|
+
return Object.values(this.blockStates).flatMap((t) => J(t.recommendationConfigs, this));
|
|
668
672
|
},
|
|
669
673
|
// ====================================================================
|
|
670
674
|
// Per-Block Product Fetching
|
|
671
675
|
// ====================================================================
|
|
672
676
|
async fetchRecommendationProducts() {
|
|
673
|
-
|
|
677
|
+
this.currentRecommendationId !== null && await this.fetchRecommendationProductsForBlock(this.currentRecommendationId);
|
|
678
|
+
},
|
|
679
|
+
/**
|
|
680
|
+
* Fetches one block's products whether or not it is selected: the panel teardown and the
|
|
681
|
+
* strategy drawer refresh the block they were handed after the user may have moved on.
|
|
682
|
+
*/
|
|
683
|
+
async fetchRecommendationProductsForBlock(t) {
|
|
684
|
+
var i;
|
|
685
|
+
const e = this.blockStates[t];
|
|
686
|
+
if (!e)
|
|
674
687
|
return;
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
b
|
|
679
|
-
].join(":");
|
|
680
|
-
if (p && I === t) {
|
|
681
|
-
await p;
|
|
688
|
+
const n = [e.configVersion, e.adoptedSizeVersion, b].join(":"), r = I.get(t);
|
|
689
|
+
if ((r == null ? void 0 : r.key) === n) {
|
|
690
|
+
await r.promise;
|
|
682
691
|
return;
|
|
683
692
|
}
|
|
684
|
-
|
|
693
|
+
const o = this._doFetchProducts(t);
|
|
694
|
+
I.set(t, { key: n, promise: o });
|
|
685
695
|
try {
|
|
686
|
-
await
|
|
696
|
+
await o;
|
|
687
697
|
} finally {
|
|
688
|
-
|
|
698
|
+
((i = I.get(t)) == null ? void 0 : i.promise) === o && I.delete(t);
|
|
689
699
|
}
|
|
690
700
|
},
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
701
|
+
// Captures the block ID up front so the write lands on it even if the user switches.
|
|
702
|
+
async _doFetchProducts(t) {
|
|
703
|
+
var S;
|
|
704
|
+
const e = t ?? this.currentRecommendationId, n = this.blockStates[e], { recommendationConfigs: r } = n, o = R();
|
|
705
|
+
if (r.strategyId && o.isFeatureEnabled("reusableRecommendationStrategy")) {
|
|
706
|
+
await this._doFetchStrategyProducts(e);
|
|
696
707
|
return;
|
|
697
708
|
}
|
|
698
|
-
const
|
|
699
|
-
|
|
700
|
-
const
|
|
709
|
+
const i = (u.get(e) ?? 0) + 1;
|
|
710
|
+
u.set(e, i);
|
|
711
|
+
const s = parseInt(r.size) || 6;
|
|
701
712
|
if (!r.strategy) {
|
|
702
|
-
this._setBlockProducts(
|
|
713
|
+
this._setBlockProducts(e, [], s);
|
|
703
714
|
return;
|
|
704
715
|
}
|
|
705
|
-
const
|
|
716
|
+
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 = {
|
|
706
717
|
locale: r.language,
|
|
707
718
|
currency: r.currencySettings.value,
|
|
708
|
-
partnerName:
|
|
719
|
+
partnerName: o.partnerName,
|
|
709
720
|
size: r.size,
|
|
710
721
|
details: !0,
|
|
711
|
-
campaignId:
|
|
722
|
+
campaignId: o.variationId
|
|
712
723
|
};
|
|
713
|
-
r.strategy === "manualMerchandising" ? c.productId =
|
|
724
|
+
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(
|
|
714
725
|
c,
|
|
715
|
-
|
|
726
|
+
q(o.partnerName, r.strategy)
|
|
716
727
|
);
|
|
717
|
-
let
|
|
728
|
+
let g;
|
|
718
729
|
try {
|
|
719
|
-
|
|
730
|
+
g = await m.fetchRecommendationProducts(f, c);
|
|
720
731
|
} catch {
|
|
721
|
-
|
|
732
|
+
g = [];
|
|
722
733
|
}
|
|
723
|
-
|
|
734
|
+
u.get(e) === i && this._setBlockProducts(e, g, s);
|
|
724
735
|
},
|
|
725
736
|
/**
|
|
726
737
|
* Block-scoped counterpart of `fetchRecommendationProducts`, which only serves the selected block:
|
|
@@ -728,8 +739,8 @@ const Y = () => ({
|
|
|
728
739
|
* @returns whether real products arrived
|
|
729
740
|
*/
|
|
730
741
|
async fetchStrategyProductsForBlock(t, e = {}) {
|
|
731
|
-
var
|
|
732
|
-
return (
|
|
742
|
+
var n;
|
|
743
|
+
return (n = this.blockStates[t]) != null && n.recommendationConfigs.strategyId ? this._doFetchStrategyProducts(t, e) : !1;
|
|
733
744
|
},
|
|
734
745
|
/**
|
|
735
746
|
* Reloads a block's products and adopts its strategy's current size, which may have
|
|
@@ -737,8 +748,8 @@ const Y = () => ({
|
|
|
737
748
|
* @returns whether a fresh listing holds the strategy and its products arrived
|
|
738
749
|
*/
|
|
739
750
|
async refreshStrategyBlock(t) {
|
|
740
|
-
var
|
|
741
|
-
const e = (
|
|
751
|
+
var o;
|
|
752
|
+
const e = (o = this.blockStates[t]) == null ? void 0 : o.recommendationConfigs.strategyId;
|
|
742
753
|
if (!e)
|
|
743
754
|
return !1;
|
|
744
755
|
try {
|
|
@@ -746,50 +757,53 @@ const Y = () => ({
|
|
|
746
757
|
} catch {
|
|
747
758
|
return !1;
|
|
748
759
|
}
|
|
749
|
-
const
|
|
750
|
-
if (!
|
|
760
|
+
const n = this.strategiesFetched ? this.strategies.find((i) => String(i.strategy_id) === e) : void 0;
|
|
761
|
+
if (!n || !await this.fetchStrategyProductsForBlock(t, { keepOnFailure: !0 }))
|
|
751
762
|
return !1;
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
763
|
+
const r = this.blockStates[t];
|
|
764
|
+
if ((r == null ? void 0 : r.recommendationConfigs.strategyId) !== e)
|
|
765
|
+
return !1;
|
|
766
|
+
if (n.size !== void 0) {
|
|
767
|
+
const i = String(n.size);
|
|
768
|
+
r.recommendationConfigs.size !== i && r.adoptedSizeVersion++, r.recommendationConfigs = { ...r.recommendationConfigs, size: i };
|
|
769
|
+
}
|
|
770
|
+
return !0;
|
|
757
771
|
},
|
|
758
772
|
_doFetchStrategyProducts(t, e = {}) {
|
|
759
|
-
const
|
|
760
|
-
|
|
761
|
-
const
|
|
762
|
-
return
|
|
763
|
-
},
|
|
764
|
-
async _loadStrategyProducts(t, e, { keepOnFailure:
|
|
765
|
-
const { recommendationConfigs:
|
|
766
|
-
let
|
|
773
|
+
const n = (u.get(t) ?? 0) + 1;
|
|
774
|
+
u.set(t, n);
|
|
775
|
+
const r = this._loadStrategyProducts(t, n, e);
|
|
776
|
+
return _.set(t, { token: n, outcome: r }), r;
|
|
777
|
+
},
|
|
778
|
+
async _loadStrategyProducts(t, e, { keepOnFailure: n = !1 }) {
|
|
779
|
+
const { recommendationConfigs: r } = this.blockStates[t];
|
|
780
|
+
let o = [], i = parseInt(r.size) || 6;
|
|
767
781
|
try {
|
|
768
782
|
await this.fetchStrategies();
|
|
769
|
-
const
|
|
770
|
-
(a) => String(a.strategy_id) ===
|
|
783
|
+
const s = this.strategies.find(
|
|
784
|
+
(a) => String(a.strategy_id) === r.strategyId
|
|
771
785
|
);
|
|
772
|
-
if (
|
|
773
|
-
i = parseInt(String(
|
|
774
|
-
const a =
|
|
775
|
-
|
|
786
|
+
if (s) {
|
|
787
|
+
i = parseInt(String(s.size ?? "")) || i;
|
|
788
|
+
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;
|
|
789
|
+
h && (o = await m.fetchRecommendationProductsByUrl(h));
|
|
776
790
|
}
|
|
777
791
|
} catch {
|
|
778
|
-
|
|
792
|
+
o = [];
|
|
779
793
|
}
|
|
780
|
-
return
|
|
794
|
+
return u.get(t) !== e ? W(t) : !o.length && n ? !1 : (this._setBlockProducts(t, o, i), o.length > 0);
|
|
781
795
|
},
|
|
782
|
-
_setBlockProducts(t, e,
|
|
796
|
+
_setBlockProducts(t, e, n) {
|
|
783
797
|
if (!this.blockStates[t])
|
|
784
798
|
return;
|
|
785
|
-
const
|
|
799
|
+
const r = e.length > 0 ? e : w(n);
|
|
786
800
|
this.blockStates[t].recommendationProducts = [
|
|
787
|
-
...
|
|
788
|
-
...
|
|
801
|
+
...r.slice(0, n),
|
|
802
|
+
...w(Math.max(0, n - r.length))
|
|
789
803
|
];
|
|
790
804
|
}
|
|
791
805
|
}
|
|
792
806
|
});
|
|
793
807
|
export {
|
|
794
|
-
|
|
808
|
+
ht as useRecommendationExtensionStore
|
|
795
809
|
};
|