@useinsider/guido 3.20.0-beta.6e5144c → 3.20.0-beta.af394f2
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/extensions/Blocks/Recommendation/controls/main/index.js +188 -229
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +155 -170
- package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +6 -6
- package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +6 -19
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +1 -7
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useToaster as
|
|
1
|
+
import { useToaster as _ } from "../../../../composables/useToaster.js";
|
|
2
2
|
import { useTranslations as L } from "../../../../composables/useTranslations.js";
|
|
3
|
-
import { getRecommendationFeedSourceMaps as F, strategyEditPath as U, strategyCreatePath as N, getOperatorOptions as M, PriceAttributes as
|
|
4
|
-
import { ToasterTypeOptions as
|
|
3
|
+
import { getRecommendationFeedSourceMaps as F, strategyEditPath as U, strategyCreatePath as N, getOperatorOptions as M, PriceAttributes as E } from "../../../../enums/extensions/recommendationBlock.js";
|
|
4
|
+
import { ToasterTypeOptions as B } from "../../../../enums/toaster.js";
|
|
5
5
|
import { useRecommendationApi as z } from "../../../../services/recommendationApi.js";
|
|
6
|
-
import { useConfigStore as
|
|
6
|
+
import { useConfigStore as R } from "../../../../stores/config.js";
|
|
7
7
|
import { defineStore as A } from "pinia";
|
|
8
8
|
import "../constants/selectors.js";
|
|
9
9
|
import { DEFAULT_MOBILE_CARDS_IN_ROW as O, DEFAULT_CARDS_IN_ROW as x } from "../constants/layout.js";
|
|
10
|
-
import { CURRENT_CONFIG_VERSION as
|
|
10
|
+
import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as T, EXCLUDED_ALGORITHM_IDS as V } from "../constants/defaultConfig.js";
|
|
11
11
|
import { getDefaultProducts as w } from "../templates/utils.js";
|
|
12
12
|
import { generateCompleteFilterQuery as P } from "../utils/filterUtil.js";
|
|
13
13
|
import { isLegacyStrategyConfig as j } from "../utils/legacyStrategyMigration.js";
|
|
@@ -16,10 +16,10 @@ import { sanitizeProductIds as q } from "../utils/productIds.js";
|
|
|
16
16
|
import { isFilterValid as K } from "../validation/filterSchema.js";
|
|
17
17
|
import { getInvalidFields as H, isConfigValid as J } from "../validation/requiredFields.js";
|
|
18
18
|
const m = z();
|
|
19
|
-
let
|
|
20
|
-
const
|
|
19
|
+
let S = null, p = null, y = null, I = "", k = null, b = 0;
|
|
20
|
+
const g = /* @__PURE__ */ new Map();
|
|
21
21
|
let l = null;
|
|
22
|
-
function
|
|
22
|
+
function D() {
|
|
23
23
|
return {
|
|
24
24
|
cardsInRow: x,
|
|
25
25
|
currencySettings: {
|
|
@@ -45,9 +45,9 @@ function _() {
|
|
|
45
45
|
// that default is what reached buildCampaignUrl and baked a most-popular feed URL
|
|
46
46
|
// for a block the user never configured (SD-149916). Legacy blocks still get their real
|
|
47
47
|
// algorithm from the node-config sync or the save-time seed.
|
|
48
|
-
strategy:
|
|
48
|
+
strategy: R().isFeatureEnabled("reusableRecommendationStrategy") ? "" : "mostPopular",
|
|
49
49
|
strategyId: "",
|
|
50
|
-
nodeConfigVersion:
|
|
50
|
+
nodeConfigVersion: C,
|
|
51
51
|
textTrimming: !0,
|
|
52
52
|
unresponsive: !1,
|
|
53
53
|
size: "6",
|
|
@@ -58,7 +58,7 @@ function _() {
|
|
|
58
58
|
}
|
|
59
59
|
function G() {
|
|
60
60
|
return {
|
|
61
|
-
recommendationConfigs:
|
|
61
|
+
recommendationConfigs: D(),
|
|
62
62
|
recommendationProducts: [],
|
|
63
63
|
filterStatus: !1,
|
|
64
64
|
filterSelectionDrawerStatus: !1,
|
|
@@ -69,8 +69,7 @@ function G() {
|
|
|
69
69
|
isInitialized: !1,
|
|
70
70
|
filterSnapshot: null,
|
|
71
71
|
syncedConfigFingerprint: null,
|
|
72
|
-
legacyConversionLoading: !1
|
|
73
|
-
configVersion: 0
|
|
72
|
+
legacyConversionLoading: !1
|
|
74
73
|
};
|
|
75
74
|
}
|
|
76
75
|
const Q = () => ({
|
|
@@ -99,7 +98,7 @@ const Q = () => ({
|
|
|
99
98
|
* This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
|
|
100
99
|
*/
|
|
101
100
|
recommendationConfigs(t) {
|
|
102
|
-
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs :
|
|
101
|
+
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : D();
|
|
103
102
|
},
|
|
104
103
|
/**
|
|
105
104
|
* Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
|
|
@@ -120,7 +119,7 @@ const Q = () => ({
|
|
|
120
119
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
|
|
121
120
|
},
|
|
122
121
|
isLegacyStrategyBlock() {
|
|
123
|
-
return
|
|
122
|
+
return R().isFeatureEnabled("reusableRecommendationStrategy") && j(this.recommendationConfigs);
|
|
124
123
|
},
|
|
125
124
|
legacyConversionLoading(t) {
|
|
126
125
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
|
|
@@ -130,7 +129,7 @@ const Q = () => ({
|
|
|
130
129
|
},
|
|
131
130
|
assignedStrategy(t) {
|
|
132
131
|
const { strategyId: e } = this.recommendationConfigs;
|
|
133
|
-
return e ? t.strategies.find((
|
|
132
|
+
return e ? t.strategies.find((r) => String(r.strategy_id) === e) ?? null : null;
|
|
134
133
|
},
|
|
135
134
|
/**
|
|
136
135
|
* Proxy getter: delegates to blockStates[currentRecommendationId].filterStatus
|
|
@@ -160,19 +159,19 @@ const Q = () => ({
|
|
|
160
159
|
},
|
|
161
160
|
getUniqueFilterGroups() {
|
|
162
161
|
const { filters: t } = this.recommendationConfigs;
|
|
163
|
-
return [...new Set(t.map((e) => e.filterGroup))].sort((e,
|
|
162
|
+
return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
|
|
164
163
|
},
|
|
165
164
|
getActivePredictiveAlgorithms: (t) => {
|
|
166
|
-
const e = F(),
|
|
167
|
-
return t.activePredictiveAlgorithms.filter((
|
|
168
|
-
|
|
169
|
-
}),
|
|
170
|
-
text:
|
|
171
|
-
value:
|
|
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
|
|
172
171
|
}));
|
|
173
172
|
},
|
|
174
|
-
getLanguages: (t) => Object.entries(t.languages).map(([e,
|
|
175
|
-
text:
|
|
173
|
+
getLanguages: (t) => Object.entries(t.languages).map(([e, r]) => ({
|
|
174
|
+
text: r,
|
|
176
175
|
value: e
|
|
177
176
|
})),
|
|
178
177
|
getCurrencySymbolList: (t) => t.currencyList.map((e) => ({
|
|
@@ -182,7 +181,7 @@ const Q = () => ({
|
|
|
182
181
|
getFilterList() {
|
|
183
182
|
return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
|
|
184
183
|
let e;
|
|
185
|
-
return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` :
|
|
184
|
+
return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : E.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
|
|
186
185
|
text: t.displayName,
|
|
187
186
|
value: e,
|
|
188
187
|
type: t.attributeType
|
|
@@ -214,13 +213,13 @@ const Q = () => ({
|
|
|
214
213
|
removeBlockState(t) {
|
|
215
214
|
const e = t.toString();
|
|
216
215
|
if (this.recommendationCampaignUrls[e]) {
|
|
217
|
-
const
|
|
218
|
-
delete
|
|
216
|
+
const n = { ...this.recommendationCampaignUrls };
|
|
217
|
+
delete n[e], this.recommendationCampaignUrls = n;
|
|
219
218
|
}
|
|
220
|
-
const
|
|
221
|
-
if (delete
|
|
222
|
-
const
|
|
223
|
-
this.currentRecommendationId =
|
|
219
|
+
const r = { ...this.blockStates };
|
|
220
|
+
if (delete r[t], this.blockStates = r, this.currentRecommendationId === t) {
|
|
221
|
+
const n = Object.keys(this.blockStates).map(Number);
|
|
222
|
+
this.currentRecommendationId = n.length > 0 ? n[0] : null;
|
|
224
223
|
}
|
|
225
224
|
},
|
|
226
225
|
/**
|
|
@@ -232,15 +231,15 @@ const Q = () => ({
|
|
|
232
231
|
* (SD-149916).
|
|
233
232
|
*/
|
|
234
233
|
cloneBlockState(t, e) {
|
|
235
|
-
const
|
|
236
|
-
if (
|
|
237
|
-
const o = structuredClone(
|
|
238
|
-
o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId &&
|
|
234
|
+
const r = this.blockStates[t];
|
|
235
|
+
if (r) {
|
|
236
|
+
const o = structuredClone(r);
|
|
237
|
+
o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (o.isInitialized = !1, o.syncedConfigFingerprint = null), this.blockStates = {
|
|
239
238
|
...this.blockStates,
|
|
240
239
|
[e]: o
|
|
241
240
|
};
|
|
242
241
|
}
|
|
243
|
-
const
|
|
242
|
+
const n = t.toString(), s = e.toString(), i = this.recommendationCampaignUrls[n];
|
|
244
243
|
i && (this.recommendationCampaignUrls = {
|
|
245
244
|
...this.recommendationCampaignUrls,
|
|
246
245
|
[s]: i
|
|
@@ -268,14 +267,14 @@ const Q = () => ({
|
|
|
268
267
|
* `isInitialized`) alone.
|
|
269
268
|
*/
|
|
270
269
|
seedBlockUrlConfig(t, e) {
|
|
271
|
-
const
|
|
270
|
+
const r = (o, a) => o === "." || o === "," || o === " " ? o : a, n = {
|
|
272
271
|
name: e.currencyCode,
|
|
273
272
|
value: e.currencyCode,
|
|
274
273
|
symbol: e.currencySymbol,
|
|
275
274
|
alignment: e.currencyAlignment === "before" ? "0" : "1",
|
|
276
275
|
decimalCount: String(e.currencyDecimalCount),
|
|
277
|
-
decimalSeparator:
|
|
278
|
-
thousandSeparator:
|
|
276
|
+
decimalSeparator: r(e.currencyDecimalSeparator, ","),
|
|
277
|
+
thousandSeparator: r(e.currencyThousandSeparator, ".")
|
|
279
278
|
}, s = !this.blockStates[t], i = s ? G() : this.blockStates[t];
|
|
280
279
|
i.recommendationConfigs = {
|
|
281
280
|
...i.recommendationConfigs,
|
|
@@ -286,7 +285,7 @@ const Q = () => ({
|
|
|
286
285
|
productIds: e.productIds,
|
|
287
286
|
filters: e.filters,
|
|
288
287
|
shuffleProducts: e.shuffleProducts,
|
|
289
|
-
currencySettings:
|
|
288
|
+
currencySettings: n
|
|
290
289
|
}, s && (this.blockStates = {
|
|
291
290
|
...this.blockStates,
|
|
292
291
|
[t]: i
|
|
@@ -299,27 +298,27 @@ const Q = () => ({
|
|
|
299
298
|
patchCurrentBlockConfig(t, e = {}) {
|
|
300
299
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
301
300
|
return;
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
...
|
|
301
|
+
const r = this.blockStates[this.currentRecommendationId];
|
|
302
|
+
r.recommendationConfigs = {
|
|
303
|
+
...r.recommendationConfigs,
|
|
305
304
|
...t,
|
|
306
305
|
currencySettings: {
|
|
307
|
-
...
|
|
306
|
+
...r.recommendationConfigs.currencySettings,
|
|
308
307
|
...t.currencySettings || {}
|
|
309
308
|
}
|
|
310
309
|
};
|
|
311
|
-
const { triggerRefetch:
|
|
312
|
-
|
|
310
|
+
const { triggerRefetch: n = !0 } = e;
|
|
311
|
+
n && this.configVersion++;
|
|
313
312
|
},
|
|
314
313
|
/**
|
|
315
314
|
* Creates a filter with the first available attribute and operator pre-selected.
|
|
316
315
|
*/
|
|
317
316
|
createDefaultFilter(t, e) {
|
|
318
|
-
const [
|
|
317
|
+
const [r] = this.getFilterList, [n] = M(r == null ? void 0 : r.type);
|
|
319
318
|
return {
|
|
320
319
|
type: "standardFilter",
|
|
321
|
-
attribute: (
|
|
322
|
-
operator: (
|
|
320
|
+
attribute: (r == null ? void 0 : r.value) ?? "",
|
|
321
|
+
operator: (n == null ? void 0 : n.value) ?? "",
|
|
323
322
|
innerGroupOperator: "*",
|
|
324
323
|
outerGroupOperator: "*",
|
|
325
324
|
filterNumber: e,
|
|
@@ -381,29 +380,29 @@ const Q = () => ({
|
|
|
381
380
|
this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].removeStrategyModalStatus = !1);
|
|
382
381
|
},
|
|
383
382
|
async fetchStrategies() {
|
|
384
|
-
for (;
|
|
383
|
+
for (; k; )
|
|
385
384
|
try {
|
|
386
|
-
await
|
|
385
|
+
await k;
|
|
387
386
|
} catch {
|
|
388
387
|
}
|
|
389
388
|
if (this.strategiesFetched)
|
|
390
389
|
return;
|
|
391
|
-
const t =
|
|
390
|
+
const t = b, e = (async () => {
|
|
392
391
|
this.strategiesLoading = !0;
|
|
393
392
|
try {
|
|
394
|
-
const
|
|
395
|
-
if (t !==
|
|
393
|
+
const r = await m.fetchRecommendationStrategies();
|
|
394
|
+
if (t !== b)
|
|
396
395
|
return;
|
|
397
|
-
this.strategies =
|
|
396
|
+
this.strategies = r, this.strategiesFetched = !0;
|
|
398
397
|
} finally {
|
|
399
|
-
this.strategiesLoading = !1, t ===
|
|
398
|
+
this.strategiesLoading = !1, t === b && (this.strategiesSettled = !0);
|
|
400
399
|
}
|
|
401
400
|
})();
|
|
402
|
-
|
|
401
|
+
k = e;
|
|
403
402
|
try {
|
|
404
403
|
await e;
|
|
405
404
|
} finally {
|
|
406
|
-
|
|
405
|
+
k = null;
|
|
407
406
|
}
|
|
408
407
|
},
|
|
409
408
|
/**
|
|
@@ -417,7 +416,7 @@ const Q = () => ({
|
|
|
417
416
|
}));
|
|
418
417
|
},
|
|
419
418
|
invalidateStrategies() {
|
|
420
|
-
this.strategiesFetched = !1, this.strategiesSettled = !1,
|
|
419
|
+
this.strategiesFetched = !1, this.strategiesSettled = !1, b += 1;
|
|
421
420
|
},
|
|
422
421
|
/**
|
|
423
422
|
* Opens a Smart Recommender strategy page in a new tab and refreshes the list every time
|
|
@@ -435,20 +434,20 @@ const Q = () => ({
|
|
|
435
434
|
_armStrategyPageReturn(t) {
|
|
436
435
|
const e = window.open(t, "_blank");
|
|
437
436
|
if (!e)
|
|
438
|
-
return
|
|
439
|
-
type:
|
|
437
|
+
return _().showToaster({
|
|
438
|
+
type: B.Error,
|
|
440
439
|
message: L()("discovery-strategy.error-description")
|
|
441
440
|
}), !1;
|
|
442
441
|
e.opener = null, l == null || l();
|
|
443
|
-
let
|
|
444
|
-
const
|
|
445
|
-
document.hidden ||
|
|
442
|
+
let r = !1;
|
|
443
|
+
const n = () => {
|
|
444
|
+
document.hidden || r || (e != null && e.closed && (l == null || l()), r = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
|
|
446
445
|
}).finally(() => {
|
|
447
|
-
|
|
446
|
+
r = !1;
|
|
448
447
|
}));
|
|
449
448
|
};
|
|
450
|
-
return document.addEventListener("visibilitychange",
|
|
451
|
-
document.removeEventListener("visibilitychange",
|
|
449
|
+
return document.addEventListener("visibilitychange", n), l = () => {
|
|
450
|
+
document.removeEventListener("visibilitychange", n), l = null;
|
|
452
451
|
}, !0;
|
|
453
452
|
},
|
|
454
453
|
/**
|
|
@@ -482,13 +481,13 @@ const Q = () => ({
|
|
|
482
481
|
return this._armStrategyPageReturn(U(t));
|
|
483
482
|
},
|
|
484
483
|
async resolveStrategyUrlTemplate(t, e) {
|
|
485
|
-
const
|
|
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;
|
|
486
485
|
if (s)
|
|
487
486
|
return s;
|
|
488
487
|
const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
|
|
489
|
-
return
|
|
488
|
+
return n && i && (this.strategyUrlTemplates = {
|
|
490
489
|
...this.strategyUrlTemplates,
|
|
491
|
-
[
|
|
490
|
+
[n]: i
|
|
492
491
|
}), i;
|
|
493
492
|
},
|
|
494
493
|
assignStrategy(t) {
|
|
@@ -498,27 +497,27 @@ const Q = () => ({
|
|
|
498
497
|
});
|
|
499
498
|
},
|
|
500
499
|
async convertLegacyStrategy(t, e = { scope: "campaign" }) {
|
|
501
|
-
const
|
|
502
|
-
if (
|
|
500
|
+
const r = this.currentRecommendationId;
|
|
501
|
+
if (r === null || !this.blockStates[r])
|
|
503
502
|
throw new Error("[Guido] convertLegacyStrategy called without an active block");
|
|
504
|
-
this.blockStates[
|
|
503
|
+
this.blockStates[r].legacyConversionLoading = !0;
|
|
505
504
|
try {
|
|
506
|
-
const
|
|
505
|
+
const n = await m.migrateLegacyStrategy(t, e);
|
|
507
506
|
this.invalidateStrategies();
|
|
508
507
|
try {
|
|
509
508
|
await this.fetchStrategies();
|
|
510
509
|
} catch (o) {
|
|
511
510
|
console.error("[Guido] strategy listing refresh after conversion failed", o);
|
|
512
511
|
}
|
|
513
|
-
const s = this.strategies.find((o) => String(o.strategy_id) ===
|
|
512
|
+
const s = this.strategies.find((o) => String(o.strategy_id) === n), i = this.blockStates[r];
|
|
514
513
|
return i && (i.recommendationConfigs = {
|
|
515
514
|
...i.recommendationConfigs,
|
|
516
|
-
strategyId:
|
|
517
|
-
nodeConfigVersion:
|
|
515
|
+
strategyId: n,
|
|
516
|
+
nodeConfigVersion: C,
|
|
518
517
|
...(s == null ? void 0 : s.size) !== void 0 ? { size: String(s.size) } : {}
|
|
519
|
-
}
|
|
518
|
+
}), this.currentRecommendationId === r && this.configVersion++, n;
|
|
520
519
|
} finally {
|
|
521
|
-
this.blockStates[
|
|
520
|
+
this.blockStates[r] && (this.blockStates[r].legacyConversionLoading = !1);
|
|
522
521
|
}
|
|
523
522
|
},
|
|
524
523
|
/**
|
|
@@ -527,15 +526,15 @@ const Q = () => ({
|
|
|
527
526
|
* the document never received.
|
|
528
527
|
*/
|
|
529
528
|
revertLegacyConversion(t, e) {
|
|
530
|
-
const
|
|
531
|
-
|
|
529
|
+
const r = this.blockStates[t];
|
|
530
|
+
r && (r.recommendationConfigs = { ...r.recommendationConfigs, ...e }, this.currentRecommendationId === t && this.configVersion++);
|
|
532
531
|
},
|
|
533
532
|
removeStrategy() {
|
|
534
533
|
this.patchCurrentBlockConfig({
|
|
535
534
|
strategyId: "",
|
|
536
535
|
strategy: "",
|
|
537
|
-
size:
|
|
538
|
-
nodeConfigVersion:
|
|
536
|
+
size: T.size,
|
|
537
|
+
nodeConfigVersion: C
|
|
539
538
|
});
|
|
540
539
|
},
|
|
541
540
|
// ====================================================================
|
|
@@ -543,43 +542,43 @@ const Q = () => ({
|
|
|
543
542
|
// ====================================================================
|
|
544
543
|
async fetchRecommendationCreateData() {
|
|
545
544
|
if (!this.activePredictiveAlgorithms.length) {
|
|
546
|
-
if (
|
|
547
|
-
await
|
|
545
|
+
if (S) {
|
|
546
|
+
await S;
|
|
548
547
|
return;
|
|
549
548
|
}
|
|
550
|
-
|
|
549
|
+
S = (async () => {
|
|
551
550
|
const {
|
|
552
551
|
activePredictiveAlgorithms: t,
|
|
553
552
|
languages: e,
|
|
554
|
-
currencies:
|
|
553
|
+
currencies: r
|
|
555
554
|
} = await m.fetchRecommendationCreateData();
|
|
556
555
|
if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
|
|
557
|
-
const
|
|
558
|
-
|
|
556
|
+
const n = this.blockStates[this.currentRecommendationId];
|
|
557
|
+
n.filterStatus = !!n.recommendationConfigs.filters.length;
|
|
559
558
|
}
|
|
560
|
-
this.currencyList =
|
|
559
|
+
this.currencyList = r;
|
|
561
560
|
})();
|
|
562
561
|
try {
|
|
563
|
-
await
|
|
562
|
+
await S;
|
|
564
563
|
} finally {
|
|
565
|
-
|
|
564
|
+
S = null;
|
|
566
565
|
}
|
|
567
566
|
}
|
|
568
567
|
},
|
|
569
568
|
async fetchRecommendationFilters() {
|
|
570
569
|
if (!Object.keys(this.filterList).length) {
|
|
571
|
-
if (
|
|
572
|
-
await
|
|
570
|
+
if (p) {
|
|
571
|
+
await p;
|
|
573
572
|
return;
|
|
574
573
|
}
|
|
575
|
-
|
|
574
|
+
p = (async () => {
|
|
576
575
|
const t = await m.fetchRecommendationFilters();
|
|
577
576
|
this.filterList = t;
|
|
578
577
|
})();
|
|
579
578
|
try {
|
|
580
|
-
await
|
|
579
|
+
await p;
|
|
581
580
|
} finally {
|
|
582
|
-
|
|
581
|
+
p = null;
|
|
583
582
|
}
|
|
584
583
|
}
|
|
585
584
|
},
|
|
@@ -594,8 +593,8 @@ const Q = () => ({
|
|
|
594
593
|
deleteFilterGroup(t) {
|
|
595
594
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
596
595
|
return;
|
|
597
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
598
|
-
e.recommendationConfigs.filters =
|
|
596
|
+
const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.filter((i) => i.filterGroup !== t), n = [...new Set(r.map((i) => i.filterGroup))].sort((i, o) => i - o), s = new Map(n.map((i, o) => [i, o + 1]));
|
|
597
|
+
e.recommendationConfigs.filters = r.map((i) => ({
|
|
599
598
|
...i,
|
|
600
599
|
filterGroup: s.get(i.filterGroup) ?? i.filterGroup
|
|
601
600
|
}));
|
|
@@ -603,47 +602,47 @@ const Q = () => ({
|
|
|
603
602
|
updateFilter(t) {
|
|
604
603
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
605
604
|
return;
|
|
606
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
607
|
-
if (
|
|
608
|
-
const
|
|
609
|
-
r
|
|
605
|
+
const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
|
|
606
|
+
if (r !== -1) {
|
|
607
|
+
const n = [...e.recommendationConfigs.filters];
|
|
608
|
+
n[r] = {
|
|
610
609
|
...t,
|
|
611
610
|
isValid: K(t)
|
|
612
|
-
}, e.recommendationConfigs.filters =
|
|
611
|
+
}, e.recommendationConfigs.filters = n;
|
|
613
612
|
}
|
|
614
613
|
},
|
|
615
614
|
deleteFilter(t) {
|
|
616
615
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
617
616
|
return;
|
|
618
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
619
|
-
if (
|
|
620
|
-
let
|
|
621
|
-
if (
|
|
617
|
+
const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters].findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
|
|
618
|
+
if (r !== -1) {
|
|
619
|
+
let n = [...e.recommendationConfigs.filters];
|
|
620
|
+
if (n.splice(r, 1), n.some((i) => i.filterGroup === t.filterGroup)) {
|
|
622
621
|
let i = 1;
|
|
623
|
-
|
|
622
|
+
n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
|
|
624
623
|
} else {
|
|
625
|
-
const i = [...new Set(
|
|
626
|
-
|
|
624
|
+
const i = [...new Set(n.map((a) => a.filterGroup))].sort((a, d) => a - d), o = new Map(i.map((a, d) => [a, d + 1]));
|
|
625
|
+
n = n.map((a) => ({
|
|
627
626
|
...a,
|
|
628
627
|
filterGroup: o.get(a.filterGroup) ?? a.filterGroup
|
|
629
628
|
}));
|
|
630
629
|
}
|
|
631
|
-
e.recommendationConfigs.filters =
|
|
630
|
+
e.recommendationConfigs.filters = n;
|
|
632
631
|
}
|
|
633
632
|
},
|
|
634
633
|
addFilter(t) {
|
|
635
634
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
636
635
|
return;
|
|
637
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
636
|
+
const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters], s = r.filter(
|
|
638
637
|
(o) => o.filterGroup === t.filterGroup
|
|
639
|
-
).length + 1, i =
|
|
640
|
-
i !== -1 ?
|
|
638
|
+
).length + 1, i = r.findLastIndex((o) => o.filterGroup === t.filterGroup);
|
|
639
|
+
i !== -1 ? r.splice(i + 1, 0, {
|
|
641
640
|
...t,
|
|
642
641
|
filterNumber: s
|
|
643
|
-
}) :
|
|
642
|
+
}) : r.push({
|
|
644
643
|
...t,
|
|
645
644
|
filterNumber: s
|
|
646
|
-
}), e.recommendationConfigs.filters =
|
|
645
|
+
}), e.recommendationConfigs.filters = r;
|
|
647
646
|
},
|
|
648
647
|
generateFilterQuery() {
|
|
649
648
|
return P(this.recommendationConfigs.filters);
|
|
@@ -672,66 +671,52 @@ const Q = () => ({
|
|
|
672
671
|
const t = [
|
|
673
672
|
this.currentRecommendationId,
|
|
674
673
|
this.configVersion,
|
|
675
|
-
|
|
674
|
+
b
|
|
676
675
|
].join(":");
|
|
677
|
-
if (
|
|
678
|
-
await
|
|
676
|
+
if (y && I === t) {
|
|
677
|
+
await y;
|
|
679
678
|
return;
|
|
680
679
|
}
|
|
681
|
-
|
|
680
|
+
I = t, y = this._doFetchProducts();
|
|
682
681
|
try {
|
|
683
|
-
await
|
|
682
|
+
await y;
|
|
684
683
|
} finally {
|
|
685
|
-
|
|
686
|
-
}
|
|
687
|
-
},
|
|
688
|
-
/**
|
|
689
|
-
* Block-scoped counterpart of `fetchRecommendationProducts`: the panel teardown has to
|
|
690
|
-
* refresh the block that was edited even after the store selected another one.
|
|
691
|
-
*/
|
|
692
|
-
async fetchRecommendationProductsForBlock(t) {
|
|
693
|
-
if (this.blockStates[t]) {
|
|
694
|
-
if (t === this.currentRecommendationId) {
|
|
695
|
-
await this.fetchRecommendationProducts();
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
await this._doFetchProducts(t);
|
|
684
|
+
I === t && (y = null, I = "");
|
|
699
685
|
}
|
|
700
686
|
},
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
await this._doFetchStrategyProducts(e);
|
|
687
|
+
async _doFetchProducts() {
|
|
688
|
+
var h;
|
|
689
|
+
const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = R();
|
|
690
|
+
if (r.strategyId && n.isFeatureEnabled("reusableRecommendationStrategy")) {
|
|
691
|
+
await this._doFetchStrategyProducts(t);
|
|
707
692
|
return;
|
|
708
693
|
}
|
|
709
|
-
const
|
|
710
|
-
|
|
711
|
-
const
|
|
694
|
+
const s = (g.get(t) ?? 0) + 1;
|
|
695
|
+
g.set(t, s);
|
|
696
|
+
const i = parseInt(r.size) || 6;
|
|
712
697
|
if (!r.strategy) {
|
|
713
|
-
this._setBlockProducts(
|
|
698
|
+
this._setBlockProducts(t, [], i);
|
|
714
699
|
return;
|
|
715
700
|
}
|
|
716
|
-
const
|
|
701
|
+
const o = r.filters.filter((f) => f.isValid), a = P(o), d = ((h = F().find((f) => f.key === r.strategy)) == null ? void 0 : h.path) || "", c = {
|
|
717
702
|
locale: r.language,
|
|
718
703
|
currency: r.currencySettings.value,
|
|
719
|
-
partnerName:
|
|
704
|
+
partnerName: n.partnerName,
|
|
720
705
|
size: r.size,
|
|
721
706
|
details: !0,
|
|
722
|
-
campaignId:
|
|
707
|
+
campaignId: n.variationId
|
|
723
708
|
};
|
|
724
|
-
r.strategy === "manualMerchandising" ?
|
|
725
|
-
|
|
726
|
-
$(
|
|
709
|
+
r.strategy === "manualMerchandising" ? c.productId = q(r.productIds) : r.strategy === "similarViewed" && (c.productId = "{itemId}"), r.strategy === "userBased" && (c.userId = "{user_id}"), a && (c.filter = a), r.shuffleProducts && (c.shuffle = !0), Object.assign(
|
|
710
|
+
c,
|
|
711
|
+
$(n.partnerName, r.strategy)
|
|
727
712
|
);
|
|
728
|
-
let
|
|
713
|
+
let u;
|
|
729
714
|
try {
|
|
730
|
-
|
|
715
|
+
u = await m.fetchRecommendationProducts(d, c);
|
|
731
716
|
} catch {
|
|
732
|
-
|
|
717
|
+
u = [];
|
|
733
718
|
}
|
|
734
|
-
|
|
719
|
+
g.get(t) === s && this._setBlockProducts(t, u, i);
|
|
735
720
|
},
|
|
736
721
|
/**
|
|
737
722
|
* Block-scoped counterpart of `fetchRecommendationProducts`, which only ever serves the
|
|
@@ -743,32 +728,32 @@ const Q = () => ({
|
|
|
743
728
|
(e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId && await this._doFetchStrategyProducts(t);
|
|
744
729
|
},
|
|
745
730
|
async _doFetchStrategyProducts(t) {
|
|
746
|
-
const e = (
|
|
747
|
-
|
|
748
|
-
const { recommendationConfigs:
|
|
749
|
-
let
|
|
731
|
+
const e = (g.get(t) ?? 0) + 1;
|
|
732
|
+
g.set(t, e);
|
|
733
|
+
const { recommendationConfigs: r } = this.blockStates[t];
|
|
734
|
+
let n = [], s = parseInt(r.size) || 6;
|
|
750
735
|
try {
|
|
751
736
|
await this.fetchStrategies();
|
|
752
737
|
const i = this.strategies.find(
|
|
753
|
-
(o) => String(o.strategy_id) ===
|
|
738
|
+
(o) => String(o.strategy_id) === r.strategyId
|
|
754
739
|
);
|
|
755
740
|
if (i) {
|
|
756
741
|
s = parseInt(String(i.size ?? "")) || s;
|
|
757
|
-
const o =
|
|
758
|
-
|
|
742
|
+
const o = r.currencySettings.value, d = (await this.resolveStrategyUrlTemplate(i, o)).replaceAll("{locale}", r.language).replaceAll("{currency}", o), c = d.indexOf("?"), u = c === -1 ? d : d.slice(0, c), h = (c === -1 ? "" : d.slice(c + 1)).split("&").filter((v) => v && !v.startsWith("user_id=")), f = h.length ? `${u}?${h.join("&")}` : u;
|
|
743
|
+
f && (n = await m.fetchRecommendationProductsByUrl(f));
|
|
759
744
|
}
|
|
760
745
|
} catch {
|
|
761
|
-
|
|
746
|
+
n = [];
|
|
762
747
|
}
|
|
763
|
-
|
|
748
|
+
g.get(t) === e && this._setBlockProducts(t, n, s);
|
|
764
749
|
},
|
|
765
|
-
_setBlockProducts(t, e,
|
|
750
|
+
_setBlockProducts(t, e, r) {
|
|
766
751
|
if (!this.blockStates[t])
|
|
767
752
|
return;
|
|
768
|
-
const
|
|
753
|
+
const n = e.length > 0 ? e : w(r);
|
|
769
754
|
this.blockStates[t].recommendationProducts = [
|
|
770
|
-
...
|
|
771
|
-
...w(Math.max(0,
|
|
755
|
+
...n.slice(0, r),
|
|
756
|
+
...w(Math.max(0, r - n.length))
|
|
772
757
|
];
|
|
773
758
|
}
|
|
774
759
|
}
|