@useinsider/guido 3.20.0-beta.af394f2 → 3.20.0-beta.d753259
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 +238 -212
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +181 -180
- package/dist/extensions/Blocks/Recommendation/utils/blockRefresh.js +19 -0
- package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +40 -25
- package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +15 -20
- package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +14 -8
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +5 -5
- 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,27 +1,29 @@
|
|
|
1
|
-
import { useToaster as
|
|
2
|
-
import { useTranslations as
|
|
3
|
-
import { getRecommendationFeedSourceMaps as
|
|
1
|
+
import { useToaster as D } from "../../../../composables/useToaster.js";
|
|
2
|
+
import { useTranslations as _ } from "../../../../composables/useTranslations.js";
|
|
3
|
+
import { getRecommendationFeedSourceMaps as v, strategyEditPath as L, strategyCreatePath as U, getOperatorOptions as M, PriceAttributes as N } from "../../../../enums/extensions/recommendationBlock.js";
|
|
4
4
|
import { ToasterTypeOptions as B } from "../../../../enums/toaster.js";
|
|
5
|
-
import { useRecommendationApi as
|
|
5
|
+
import { useRecommendationApi as E } from "../../../../services/recommendationApi.js";
|
|
6
6
|
import { useConfigStore as R } from "../../../../stores/config.js";
|
|
7
|
-
import { defineStore as
|
|
7
|
+
import { defineStore as z } 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
|
|
9
|
+
import { DEFAULT_MOBILE_CARDS_IN_ROW as A, DEFAULT_CARDS_IN_ROW as O } 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
11
|
import { getDefaultProducts as w } from "../templates/utils.js";
|
|
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 m =
|
|
19
|
-
let
|
|
20
|
-
const
|
|
12
|
+
import { generateCompleteFilterQuery as F } from "../utils/filterUtil.js";
|
|
13
|
+
import { isLegacyStrategyConfig as T } from "../utils/legacyStrategyMigration.js";
|
|
14
|
+
import { getPartnerRecommendationParams as j } from "../utils/partnerCustomizations.js";
|
|
15
|
+
import { sanitizeProductIds as $ } from "../utils/productIds.js";
|
|
16
|
+
import { isFilterValid as q } from "../validation/filterSchema.js";
|
|
17
|
+
import { getInvalidFields as K, isConfigValid as H } from "../validation/requiredFields.js";
|
|
18
|
+
const m = E();
|
|
19
|
+
let p = null, y = null;
|
|
20
|
+
const I = /* @__PURE__ */ new Map();
|
|
21
|
+
let k = null, b = 0;
|
|
22
|
+
const h = /* @__PURE__ */ new Map();
|
|
21
23
|
let l = null;
|
|
22
|
-
function
|
|
24
|
+
function G() {
|
|
23
25
|
return {
|
|
24
|
-
cardsInRow:
|
|
26
|
+
cardsInRow: O,
|
|
25
27
|
currencySettings: {
|
|
26
28
|
name: "USD",
|
|
27
29
|
value: "USD",
|
|
@@ -35,7 +37,7 @@ function D() {
|
|
|
35
37
|
productIds: [],
|
|
36
38
|
id: 1,
|
|
37
39
|
language: "en_US",
|
|
38
|
-
mobileCardsInRow:
|
|
40
|
+
mobileCardsInRow: A,
|
|
39
41
|
mobileLayoutEnabled: !1,
|
|
40
42
|
orientation: "grid",
|
|
41
43
|
recommendedProducts: [],
|
|
@@ -56,9 +58,9 @@ function D() {
|
|
|
56
58
|
priceHideIfSameAsDiscounted: !1
|
|
57
59
|
};
|
|
58
60
|
}
|
|
59
|
-
function
|
|
61
|
+
function P() {
|
|
60
62
|
return {
|
|
61
|
-
recommendationConfigs:
|
|
63
|
+
recommendationConfigs: G(),
|
|
62
64
|
recommendationProducts: [],
|
|
63
65
|
filterStatus: !1,
|
|
64
66
|
filterSelectionDrawerStatus: !1,
|
|
@@ -69,10 +71,11 @@ function G() {
|
|
|
69
71
|
isInitialized: !1,
|
|
70
72
|
filterSnapshot: null,
|
|
71
73
|
syncedConfigFingerprint: null,
|
|
72
|
-
legacyConversionLoading: !1
|
|
74
|
+
legacyConversionLoading: !1,
|
|
75
|
+
configVersion: 0
|
|
73
76
|
};
|
|
74
77
|
}
|
|
75
|
-
const
|
|
78
|
+
const J = () => ({
|
|
76
79
|
recommendationCampaignUrls: {},
|
|
77
80
|
activePredictiveAlgorithms: [],
|
|
78
81
|
languages: {},
|
|
@@ -87,8 +90,8 @@ const Q = () => ({
|
|
|
87
90
|
currentRecommendationId: null,
|
|
88
91
|
strategyPanelOpen: !1,
|
|
89
92
|
configVersion: 0
|
|
90
|
-
}),
|
|
91
|
-
state: () =>
|
|
93
|
+
}), ut = z("guidoRecommendationExtension", {
|
|
94
|
+
state: () => J(),
|
|
92
95
|
getters: {
|
|
93
96
|
// ====================================================================
|
|
94
97
|
// Proxy Getters — Backward Compatible Access to Current Block State
|
|
@@ -98,7 +101,7 @@ const Q = () => ({
|
|
|
98
101
|
* This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
|
|
99
102
|
*/
|
|
100
103
|
recommendationConfigs(t) {
|
|
101
|
-
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs :
|
|
104
|
+
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : G();
|
|
102
105
|
},
|
|
103
106
|
/**
|
|
104
107
|
* Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
|
|
@@ -119,7 +122,7 @@ const Q = () => ({
|
|
|
119
122
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
|
|
120
123
|
},
|
|
121
124
|
isLegacyStrategyBlock() {
|
|
122
|
-
return R().isFeatureEnabled("reusableRecommendationStrategy") &&
|
|
125
|
+
return R().isFeatureEnabled("reusableRecommendationStrategy") && T(this.recommendationConfigs);
|
|
123
126
|
},
|
|
124
127
|
legacyConversionLoading(t) {
|
|
125
128
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
|
|
@@ -129,7 +132,7 @@ const Q = () => ({
|
|
|
129
132
|
},
|
|
130
133
|
assignedStrategy(t) {
|
|
131
134
|
const { strategyId: e } = this.recommendationConfigs;
|
|
132
|
-
return e ? t.strategies.find((
|
|
135
|
+
return e ? t.strategies.find((n) => String(n.strategy_id) === e) ?? null : null;
|
|
133
136
|
},
|
|
134
137
|
/**
|
|
135
138
|
* Proxy getter: delegates to blockStates[currentRecommendationId].filterStatus
|
|
@@ -159,19 +162,19 @@ const Q = () => ({
|
|
|
159
162
|
},
|
|
160
163
|
getUniqueFilterGroups() {
|
|
161
164
|
const { filters: t } = this.recommendationConfigs;
|
|
162
|
-
return [...new Set(t.map((e) => e.filterGroup))].sort((e,
|
|
165
|
+
return [...new Set(t.map((e) => e.filterGroup))].sort((e, n) => e - n);
|
|
163
166
|
},
|
|
164
167
|
getActivePredictiveAlgorithms: (t) => {
|
|
165
|
-
const e =
|
|
166
|
-
return t.activePredictiveAlgorithms.filter((
|
|
167
|
-
|
|
168
|
-
}),
|
|
169
|
-
text:
|
|
170
|
-
value:
|
|
168
|
+
const e = v(), n = [];
|
|
169
|
+
return t.activePredictiveAlgorithms.filter((r) => !V.includes(r)).forEach((r) => {
|
|
170
|
+
n.push(...e.filter((s) => s.id === r));
|
|
171
|
+
}), n.map((r) => ({
|
|
172
|
+
text: r.name,
|
|
173
|
+
value: r.key
|
|
171
174
|
}));
|
|
172
175
|
},
|
|
173
|
-
getLanguages: (t) => Object.entries(t.languages).map(([e,
|
|
174
|
-
text:
|
|
176
|
+
getLanguages: (t) => Object.entries(t.languages).map(([e, n]) => ({
|
|
177
|
+
text: n,
|
|
175
178
|
value: e
|
|
176
179
|
})),
|
|
177
180
|
getCurrencySymbolList: (t) => t.currencyList.map((e) => ({
|
|
@@ -181,7 +184,7 @@ const Q = () => ({
|
|
|
181
184
|
getFilterList() {
|
|
182
185
|
return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
|
|
183
186
|
let e;
|
|
184
|
-
return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` :
|
|
187
|
+
return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : N.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
|
|
185
188
|
text: t.displayName,
|
|
186
189
|
value: e,
|
|
187
190
|
type: t.attributeType
|
|
@@ -203,7 +206,7 @@ const Q = () => ({
|
|
|
203
206
|
setCurrentBlock(t) {
|
|
204
207
|
this.blockStates[t] || (this.blockStates = {
|
|
205
208
|
...this.blockStates,
|
|
206
|
-
[t]:
|
|
209
|
+
[t]: P()
|
|
207
210
|
}), this.currentRecommendationId = t;
|
|
208
211
|
},
|
|
209
212
|
/**
|
|
@@ -213,13 +216,13 @@ const Q = () => ({
|
|
|
213
216
|
removeBlockState(t) {
|
|
214
217
|
const e = t.toString();
|
|
215
218
|
if (this.recommendationCampaignUrls[e]) {
|
|
216
|
-
const
|
|
217
|
-
delete
|
|
219
|
+
const r = { ...this.recommendationCampaignUrls };
|
|
220
|
+
delete r[e], this.recommendationCampaignUrls = r;
|
|
218
221
|
}
|
|
219
|
-
const
|
|
220
|
-
if (delete
|
|
221
|
-
const
|
|
222
|
-
this.currentRecommendationId =
|
|
222
|
+
const n = { ...this.blockStates };
|
|
223
|
+
if (delete n[t], this.blockStates = n, this.currentRecommendationId === t) {
|
|
224
|
+
const r = Object.keys(this.blockStates).map(Number);
|
|
225
|
+
this.currentRecommendationId = r.length > 0 ? r[0] : null;
|
|
223
226
|
}
|
|
224
227
|
},
|
|
225
228
|
/**
|
|
@@ -231,15 +234,15 @@ const Q = () => ({
|
|
|
231
234
|
* (SD-149916).
|
|
232
235
|
*/
|
|
233
236
|
cloneBlockState(t, e) {
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
const o = structuredClone(
|
|
237
|
+
const n = this.blockStates[t];
|
|
238
|
+
if (n) {
|
|
239
|
+
const o = structuredClone(n);
|
|
237
240
|
o.recommendationConfigs.id = e, o.recommendationConfigs.strategyId && R().isFeatureEnabled("reusableRecommendationStrategy") && (o.isInitialized = !1, o.syncedConfigFingerprint = null), this.blockStates = {
|
|
238
241
|
...this.blockStates,
|
|
239
242
|
[e]: o
|
|
240
243
|
};
|
|
241
244
|
}
|
|
242
|
-
const
|
|
245
|
+
const r = t.toString(), s = e.toString(), i = this.recommendationCampaignUrls[r];
|
|
243
246
|
i && (this.recommendationCampaignUrls = {
|
|
244
247
|
...this.recommendationCampaignUrls,
|
|
245
248
|
[s]: i
|
|
@@ -267,15 +270,15 @@ const Q = () => ({
|
|
|
267
270
|
* `isInitialized`) alone.
|
|
268
271
|
*/
|
|
269
272
|
seedBlockUrlConfig(t, e) {
|
|
270
|
-
const
|
|
273
|
+
const n = (o, a) => o === "." || o === "," || o === " " ? o : a, r = {
|
|
271
274
|
name: e.currencyCode,
|
|
272
275
|
value: e.currencyCode,
|
|
273
276
|
symbol: e.currencySymbol,
|
|
274
277
|
alignment: e.currencyAlignment === "before" ? "0" : "1",
|
|
275
278
|
decimalCount: String(e.currencyDecimalCount),
|
|
276
|
-
decimalSeparator:
|
|
277
|
-
thousandSeparator:
|
|
278
|
-
}, s = !this.blockStates[t], i = s ?
|
|
279
|
+
decimalSeparator: n(e.currencyDecimalSeparator, ","),
|
|
280
|
+
thousandSeparator: n(e.currencyThousandSeparator, ".")
|
|
281
|
+
}, s = !this.blockStates[t], i = s ? P() : this.blockStates[t];
|
|
279
282
|
i.recommendationConfigs = {
|
|
280
283
|
...i.recommendationConfigs,
|
|
281
284
|
strategy: e.strategy,
|
|
@@ -285,7 +288,7 @@ const Q = () => ({
|
|
|
285
288
|
productIds: e.productIds,
|
|
286
289
|
filters: e.filters,
|
|
287
290
|
shuffleProducts: e.shuffleProducts,
|
|
288
|
-
currencySettings:
|
|
291
|
+
currencySettings: r
|
|
289
292
|
}, s && (this.blockStates = {
|
|
290
293
|
...this.blockStates,
|
|
291
294
|
[t]: i
|
|
@@ -298,27 +301,27 @@ const Q = () => ({
|
|
|
298
301
|
patchCurrentBlockConfig(t, e = {}) {
|
|
299
302
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
300
303
|
return;
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
...
|
|
304
|
+
const n = this.blockStates[this.currentRecommendationId];
|
|
305
|
+
n.recommendationConfigs = {
|
|
306
|
+
...n.recommendationConfigs,
|
|
304
307
|
...t,
|
|
305
308
|
currencySettings: {
|
|
306
|
-
...
|
|
309
|
+
...n.recommendationConfigs.currencySettings,
|
|
307
310
|
...t.currencySettings || {}
|
|
308
311
|
}
|
|
309
312
|
};
|
|
310
|
-
const { triggerRefetch:
|
|
311
|
-
|
|
313
|
+
const { triggerRefetch: r = !0 } = e;
|
|
314
|
+
r && (n.configVersion++, this.configVersion++);
|
|
312
315
|
},
|
|
313
316
|
/**
|
|
314
317
|
* Creates a filter with the first available attribute and operator pre-selected.
|
|
315
318
|
*/
|
|
316
319
|
createDefaultFilter(t, e) {
|
|
317
|
-
const [
|
|
320
|
+
const [n] = this.getFilterList, [r] = M(n == null ? void 0 : n.type);
|
|
318
321
|
return {
|
|
319
322
|
type: "standardFilter",
|
|
320
|
-
attribute: (
|
|
321
|
-
operator: (
|
|
323
|
+
attribute: (n == null ? void 0 : n.value) ?? "",
|
|
324
|
+
operator: (r == null ? void 0 : r.value) ?? "",
|
|
322
325
|
innerGroupOperator: "*",
|
|
323
326
|
outerGroupOperator: "*",
|
|
324
327
|
filterNumber: e,
|
|
@@ -390,10 +393,10 @@ const Q = () => ({
|
|
|
390
393
|
const t = b, e = (async () => {
|
|
391
394
|
this.strategiesLoading = !0;
|
|
392
395
|
try {
|
|
393
|
-
const
|
|
396
|
+
const n = await m.fetchRecommendationStrategies();
|
|
394
397
|
if (t !== b)
|
|
395
398
|
return;
|
|
396
|
-
this.strategies =
|
|
399
|
+
this.strategies = n, this.strategiesFetched = !0;
|
|
397
400
|
} finally {
|
|
398
401
|
this.strategiesLoading = !1, t === b && (this.strategiesSettled = !0);
|
|
399
402
|
}
|
|
@@ -434,20 +437,20 @@ const Q = () => ({
|
|
|
434
437
|
_armStrategyPageReturn(t) {
|
|
435
438
|
const e = window.open(t, "_blank");
|
|
436
439
|
if (!e)
|
|
437
|
-
return
|
|
440
|
+
return D().showToaster({
|
|
438
441
|
type: B.Error,
|
|
439
|
-
message:
|
|
442
|
+
message: _()("discovery-strategy.error-description")
|
|
440
443
|
}), !1;
|
|
441
444
|
e.opener = null, l == null || l();
|
|
442
|
-
let
|
|
443
|
-
const
|
|
444
|
-
document.hidden ||
|
|
445
|
+
let n = !1;
|
|
446
|
+
const r = () => {
|
|
447
|
+
document.hidden || n || (e != null && e.closed && (l == null || l()), n = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
|
|
445
448
|
}).finally(() => {
|
|
446
|
-
|
|
449
|
+
n = !1;
|
|
447
450
|
}));
|
|
448
451
|
};
|
|
449
|
-
return document.addEventListener("visibilitychange",
|
|
450
|
-
document.removeEventListener("visibilitychange",
|
|
452
|
+
return document.addEventListener("visibilitychange", r), l = () => {
|
|
453
|
+
document.removeEventListener("visibilitychange", r), l = null;
|
|
451
454
|
}, !0;
|
|
452
455
|
},
|
|
453
456
|
/**
|
|
@@ -471,23 +474,23 @@ const Q = () => ({
|
|
|
471
474
|
* new strategy is offered; the user picks it themselves.
|
|
472
475
|
*/
|
|
473
476
|
openStrategyCreation() {
|
|
474
|
-
return this._armStrategyPageReturn(
|
|
477
|
+
return this._armStrategyPageReturn(U());
|
|
475
478
|
},
|
|
476
479
|
/**
|
|
477
480
|
* Opens the strategy's edit page. Every return refreshes the list so the block reflects the
|
|
478
481
|
* edited configuration.
|
|
479
482
|
*/
|
|
480
483
|
openStrategyEdit(t) {
|
|
481
|
-
return this._armStrategyPageReturn(
|
|
484
|
+
return this._armStrategyPageReturn(L(t));
|
|
482
485
|
},
|
|
483
486
|
async resolveStrategyUrlTemplate(t, e) {
|
|
484
|
-
const
|
|
487
|
+
const n = typeof t.updated_at == "string" ? t.updated_at : "", r = n ? `${t.strategy_id}:${n}:${e}` : "", s = r ? this.strategyUrlTemplates[r] : void 0;
|
|
485
488
|
if (s)
|
|
486
489
|
return s;
|
|
487
490
|
const { full_path: i = "" } = await m.generateStrategyEndpoint(t, e) ?? {};
|
|
488
|
-
return
|
|
491
|
+
return r && i && (this.strategyUrlTemplates = {
|
|
489
492
|
...this.strategyUrlTemplates,
|
|
490
|
-
[
|
|
493
|
+
[r]: i
|
|
491
494
|
}), i;
|
|
492
495
|
},
|
|
493
496
|
assignStrategy(t) {
|
|
@@ -497,27 +500,27 @@ const Q = () => ({
|
|
|
497
500
|
});
|
|
498
501
|
},
|
|
499
502
|
async convertLegacyStrategy(t, e = { scope: "campaign" }) {
|
|
500
|
-
const
|
|
501
|
-
if (
|
|
503
|
+
const n = this.currentRecommendationId;
|
|
504
|
+
if (n === null || !this.blockStates[n])
|
|
502
505
|
throw new Error("[Guido] convertLegacyStrategy called without an active block");
|
|
503
|
-
this.blockStates[
|
|
506
|
+
this.blockStates[n].legacyConversionLoading = !0;
|
|
504
507
|
try {
|
|
505
|
-
const
|
|
508
|
+
const r = await m.migrateLegacyStrategy(t, e);
|
|
506
509
|
this.invalidateStrategies();
|
|
507
510
|
try {
|
|
508
511
|
await this.fetchStrategies();
|
|
509
512
|
} catch (o) {
|
|
510
513
|
console.error("[Guido] strategy listing refresh after conversion failed", o);
|
|
511
514
|
}
|
|
512
|
-
const s = this.strategies.find((o) => String(o.strategy_id) ===
|
|
515
|
+
const s = this.strategies.find((o) => String(o.strategy_id) === r), i = this.blockStates[n];
|
|
513
516
|
return i && (i.recommendationConfigs = {
|
|
514
517
|
...i.recommendationConfigs,
|
|
515
|
-
strategyId:
|
|
518
|
+
strategyId: r,
|
|
516
519
|
nodeConfigVersion: C,
|
|
517
520
|
...(s == null ? void 0 : s.size) !== void 0 ? { size: String(s.size) } : {}
|
|
518
|
-
}), this.currentRecommendationId ===
|
|
521
|
+
}, i.configVersion++), this.currentRecommendationId === n && this.configVersion++, r;
|
|
519
522
|
} finally {
|
|
520
|
-
this.blockStates[
|
|
523
|
+
this.blockStates[n] && (this.blockStates[n].legacyConversionLoading = !1);
|
|
521
524
|
}
|
|
522
525
|
},
|
|
523
526
|
/**
|
|
@@ -526,14 +529,14 @@ const Q = () => ({
|
|
|
526
529
|
* the document never received.
|
|
527
530
|
*/
|
|
528
531
|
revertLegacyConversion(t, e) {
|
|
529
|
-
const
|
|
530
|
-
|
|
532
|
+
const n = this.blockStates[t];
|
|
533
|
+
n && (n.recommendationConfigs = { ...n.recommendationConfigs, ...e }, n.configVersion++, this.currentRecommendationId === t && this.configVersion++);
|
|
531
534
|
},
|
|
532
535
|
removeStrategy() {
|
|
533
536
|
this.patchCurrentBlockConfig({
|
|
534
537
|
strategyId: "",
|
|
535
538
|
strategy: "",
|
|
536
|
-
size:
|
|
539
|
+
size: x.size,
|
|
537
540
|
nodeConfigVersion: C
|
|
538
541
|
});
|
|
539
542
|
},
|
|
@@ -542,43 +545,43 @@ const Q = () => ({
|
|
|
542
545
|
// ====================================================================
|
|
543
546
|
async fetchRecommendationCreateData() {
|
|
544
547
|
if (!this.activePredictiveAlgorithms.length) {
|
|
545
|
-
if (
|
|
546
|
-
await
|
|
548
|
+
if (p) {
|
|
549
|
+
await p;
|
|
547
550
|
return;
|
|
548
551
|
}
|
|
549
|
-
|
|
552
|
+
p = (async () => {
|
|
550
553
|
const {
|
|
551
554
|
activePredictiveAlgorithms: t,
|
|
552
555
|
languages: e,
|
|
553
|
-
currencies:
|
|
556
|
+
currencies: n
|
|
554
557
|
} = await m.fetchRecommendationCreateData();
|
|
555
558
|
if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
|
|
556
|
-
const
|
|
557
|
-
|
|
559
|
+
const r = this.blockStates[this.currentRecommendationId];
|
|
560
|
+
r.filterStatus = !!r.recommendationConfigs.filters.length;
|
|
558
561
|
}
|
|
559
|
-
this.currencyList =
|
|
562
|
+
this.currencyList = n;
|
|
560
563
|
})();
|
|
561
564
|
try {
|
|
562
|
-
await
|
|
565
|
+
await p;
|
|
563
566
|
} finally {
|
|
564
|
-
|
|
567
|
+
p = null;
|
|
565
568
|
}
|
|
566
569
|
}
|
|
567
570
|
},
|
|
568
571
|
async fetchRecommendationFilters() {
|
|
569
572
|
if (!Object.keys(this.filterList).length) {
|
|
570
|
-
if (
|
|
571
|
-
await
|
|
573
|
+
if (y) {
|
|
574
|
+
await y;
|
|
572
575
|
return;
|
|
573
576
|
}
|
|
574
|
-
|
|
577
|
+
y = (async () => {
|
|
575
578
|
const t = await m.fetchRecommendationFilters();
|
|
576
579
|
this.filterList = t;
|
|
577
580
|
})();
|
|
578
581
|
try {
|
|
579
|
-
await
|
|
582
|
+
await y;
|
|
580
583
|
} finally {
|
|
581
|
-
|
|
584
|
+
y = null;
|
|
582
585
|
}
|
|
583
586
|
}
|
|
584
587
|
},
|
|
@@ -593,8 +596,8 @@ const Q = () => ({
|
|
|
593
596
|
deleteFilterGroup(t) {
|
|
594
597
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
595
598
|
return;
|
|
596
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
597
|
-
e.recommendationConfigs.filters =
|
|
599
|
+
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, o) => i - o), s = new Map(r.map((i, o) => [i, o + 1]));
|
|
600
|
+
e.recommendationConfigs.filters = n.map((i) => ({
|
|
598
601
|
...i,
|
|
599
602
|
filterGroup: s.get(i.filterGroup) ?? i.filterGroup
|
|
600
603
|
}));
|
|
@@ -602,50 +605,50 @@ const Q = () => ({
|
|
|
602
605
|
updateFilter(t) {
|
|
603
606
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
604
607
|
return;
|
|
605
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
606
|
-
if (
|
|
607
|
-
const
|
|
608
|
-
n
|
|
608
|
+
const e = this.blockStates[this.currentRecommendationId], n = e.recommendationConfigs.filters.findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
|
|
609
|
+
if (n !== -1) {
|
|
610
|
+
const r = [...e.recommendationConfigs.filters];
|
|
611
|
+
r[n] = {
|
|
609
612
|
...t,
|
|
610
|
-
isValid:
|
|
611
|
-
}, e.recommendationConfigs.filters =
|
|
613
|
+
isValid: q(t)
|
|
614
|
+
}, e.recommendationConfigs.filters = r;
|
|
612
615
|
}
|
|
613
616
|
},
|
|
614
617
|
deleteFilter(t) {
|
|
615
618
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
616
619
|
return;
|
|
617
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
618
|
-
if (
|
|
619
|
-
let
|
|
620
|
-
if (
|
|
620
|
+
const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters].findIndex((r) => r.filterNumber === t.filterNumber && r.filterGroup === t.filterGroup);
|
|
621
|
+
if (n !== -1) {
|
|
622
|
+
let r = [...e.recommendationConfigs.filters];
|
|
623
|
+
if (r.splice(n, 1), r.some((i) => i.filterGroup === t.filterGroup)) {
|
|
621
624
|
let i = 1;
|
|
622
|
-
|
|
625
|
+
r = r.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
|
|
623
626
|
} else {
|
|
624
|
-
const i = [...new Set(
|
|
625
|
-
|
|
627
|
+
const i = [...new Set(r.map((a) => a.filterGroup))].sort((a, c) => a - c), o = new Map(i.map((a, c) => [a, c + 1]));
|
|
628
|
+
r = r.map((a) => ({
|
|
626
629
|
...a,
|
|
627
630
|
filterGroup: o.get(a.filterGroup) ?? a.filterGroup
|
|
628
631
|
}));
|
|
629
632
|
}
|
|
630
|
-
e.recommendationConfigs.filters =
|
|
633
|
+
e.recommendationConfigs.filters = r;
|
|
631
634
|
}
|
|
632
635
|
},
|
|
633
636
|
addFilter(t) {
|
|
634
637
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
635
638
|
return;
|
|
636
|
-
const e = this.blockStates[this.currentRecommendationId],
|
|
639
|
+
const e = this.blockStates[this.currentRecommendationId], n = [...e.recommendationConfigs.filters], s = n.filter(
|
|
637
640
|
(o) => o.filterGroup === t.filterGroup
|
|
638
|
-
).length + 1, i =
|
|
639
|
-
i !== -1 ?
|
|
641
|
+
).length + 1, i = n.findLastIndex((o) => o.filterGroup === t.filterGroup);
|
|
642
|
+
i !== -1 ? n.splice(i + 1, 0, {
|
|
640
643
|
...t,
|
|
641
644
|
filterNumber: s
|
|
642
|
-
}) :
|
|
645
|
+
}) : n.push({
|
|
643
646
|
...t,
|
|
644
647
|
filterNumber: s
|
|
645
|
-
}), e.recommendationConfigs.filters =
|
|
648
|
+
}), e.recommendationConfigs.filters = n;
|
|
646
649
|
},
|
|
647
650
|
generateFilterQuery() {
|
|
648
|
-
return
|
|
651
|
+
return F(this.recommendationConfigs.filters);
|
|
649
652
|
},
|
|
650
653
|
/**
|
|
651
654
|
* Validation-only check invoked at save-CTA time. Defined as an action
|
|
@@ -653,111 +656,109 @@ const Q = () => ({
|
|
|
653
656
|
* every block's recommendationConfigs across user edits.
|
|
654
657
|
*/
|
|
655
658
|
hasInvalidBlock() {
|
|
656
|
-
return Object.values(this.blockStates).some((t) => !
|
|
659
|
+
return Object.values(this.blockStates).some((t) => !H(t.recommendationConfigs, this));
|
|
657
660
|
},
|
|
658
661
|
/**
|
|
659
662
|
* Which required fields are missing across the design's blocks, so the save
|
|
660
663
|
* toaster can name the cause instead of always showing the generic message.
|
|
661
664
|
*/
|
|
662
665
|
invalidBlockFields() {
|
|
663
|
-
return Object.values(this.blockStates).flatMap((t) =>
|
|
666
|
+
return Object.values(this.blockStates).flatMap((t) => K(t.recommendationConfigs, this));
|
|
664
667
|
},
|
|
665
668
|
// ====================================================================
|
|
666
669
|
// Per-Block Product Fetching
|
|
667
670
|
// ====================================================================
|
|
668
671
|
async fetchRecommendationProducts() {
|
|
669
|
-
|
|
672
|
+
this.currentRecommendationId !== null && await this.fetchRecommendationProductsForBlock(this.currentRecommendationId);
|
|
673
|
+
},
|
|
674
|
+
/**
|
|
675
|
+
* Fetches one block's products whether or not it is selected: the panel teardown and the
|
|
676
|
+
* strategy drawer refresh the block they were handed after the user may have moved on.
|
|
677
|
+
*/
|
|
678
|
+
async fetchRecommendationProductsForBlock(t) {
|
|
679
|
+
var i;
|
|
680
|
+
const e = this.blockStates[t];
|
|
681
|
+
if (!e)
|
|
670
682
|
return;
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
b
|
|
675
|
-
].join(":");
|
|
676
|
-
if (y && I === t) {
|
|
677
|
-
await y;
|
|
683
|
+
const n = [e.configVersion, b].join(":"), r = I.get(t);
|
|
684
|
+
if ((r == null ? void 0 : r.key) === n) {
|
|
685
|
+
await r.promise;
|
|
678
686
|
return;
|
|
679
687
|
}
|
|
680
|
-
|
|
688
|
+
const s = this._doFetchProducts(t);
|
|
689
|
+
I.set(t, { key: n, promise: s });
|
|
681
690
|
try {
|
|
682
|
-
await
|
|
691
|
+
await s;
|
|
683
692
|
} finally {
|
|
684
|
-
|
|
693
|
+
((i = I.get(t)) == null ? void 0 : i.promise) === s && I.delete(t);
|
|
685
694
|
}
|
|
686
695
|
},
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
696
|
+
// Captures the block ID up front so the write lands on it even if the user switches.
|
|
697
|
+
async _doFetchProducts(t) {
|
|
698
|
+
var S;
|
|
699
|
+
const e = t ?? this.currentRecommendationId, n = this.blockStates[e], { recommendationConfigs: r } = n, s = R();
|
|
700
|
+
if (r.strategyId && s.isFeatureEnabled("reusableRecommendationStrategy")) {
|
|
701
|
+
await this._doFetchStrategyProducts(e);
|
|
692
702
|
return;
|
|
693
703
|
}
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
const
|
|
704
|
+
const i = (h.get(e) ?? 0) + 1;
|
|
705
|
+
h.set(e, i);
|
|
706
|
+
const o = parseInt(r.size) || 6;
|
|
697
707
|
if (!r.strategy) {
|
|
698
|
-
this._setBlockProducts(
|
|
708
|
+
this._setBlockProducts(e, [], o);
|
|
699
709
|
return;
|
|
700
710
|
}
|
|
701
|
-
const
|
|
711
|
+
const a = r.filters.filter((g) => g.isValid), c = F(a), u = ((S = v().find((g) => g.key === r.strategy)) == null ? void 0 : S.path) || "", d = {
|
|
702
712
|
locale: r.language,
|
|
703
713
|
currency: r.currencySettings.value,
|
|
704
|
-
partnerName:
|
|
714
|
+
partnerName: s.partnerName,
|
|
705
715
|
size: r.size,
|
|
706
716
|
details: !0,
|
|
707
|
-
campaignId:
|
|
717
|
+
campaignId: s.variationId
|
|
708
718
|
};
|
|
709
|
-
r.strategy === "manualMerchandising" ?
|
|
710
|
-
|
|
711
|
-
|
|
719
|
+
r.strategy === "manualMerchandising" ? d.productId = $(r.productIds) : r.strategy === "similarViewed" && (d.productId = "{itemId}"), r.strategy === "userBased" && (d.userId = "{user_id}"), c && (d.filter = c), r.shuffleProducts && (d.shuffle = !0), Object.assign(
|
|
720
|
+
d,
|
|
721
|
+
j(s.partnerName, r.strategy)
|
|
712
722
|
);
|
|
713
|
-
let
|
|
723
|
+
let f;
|
|
714
724
|
try {
|
|
715
|
-
|
|
725
|
+
f = await m.fetchRecommendationProducts(u, d);
|
|
716
726
|
} catch {
|
|
717
|
-
|
|
727
|
+
f = [];
|
|
718
728
|
}
|
|
719
|
-
|
|
720
|
-
},
|
|
721
|
-
/**
|
|
722
|
-
* Block-scoped counterpart of `fetchRecommendationProducts`, which only ever serves the
|
|
723
|
-
* selected block. The legacy conversion must refresh the products of the block that
|
|
724
|
-
* started it even after the user selected another one.
|
|
725
|
-
*/
|
|
726
|
-
async fetchStrategyProductsForBlock(t) {
|
|
727
|
-
var e;
|
|
728
|
-
(e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId && await this._doFetchStrategyProducts(t);
|
|
729
|
+
h.get(e) === i && this._setBlockProducts(e, f, o);
|
|
729
730
|
},
|
|
730
731
|
async _doFetchStrategyProducts(t) {
|
|
731
|
-
const e = (
|
|
732
|
-
|
|
733
|
-
const { recommendationConfigs:
|
|
734
|
-
let
|
|
732
|
+
const e = (h.get(t) ?? 0) + 1;
|
|
733
|
+
h.set(t, e);
|
|
734
|
+
const { recommendationConfigs: n } = this.blockStates[t];
|
|
735
|
+
let r = [], s = parseInt(n.size) || 6;
|
|
735
736
|
try {
|
|
736
737
|
await this.fetchStrategies();
|
|
737
738
|
const i = this.strategies.find(
|
|
738
|
-
(o) => String(o.strategy_id) ===
|
|
739
|
+
(o) => String(o.strategy_id) === n.strategyId
|
|
739
740
|
);
|
|
740
741
|
if (i) {
|
|
741
742
|
s = parseInt(String(i.size ?? "")) || s;
|
|
742
|
-
const o =
|
|
743
|
-
|
|
743
|
+
const o = n.currencySettings.value, c = (await this.resolveStrategyUrlTemplate(i, o)).replaceAll("{locale}", n.language).replaceAll("{currency}", o), u = c.indexOf("?"), d = u === -1 ? c : c.slice(0, u), f = (u === -1 ? "" : c.slice(u + 1)).split("&").filter((g) => g && !g.startsWith("user_id=")), S = f.length ? `${d}?${f.join("&")}` : d;
|
|
744
|
+
S && (r = await m.fetchRecommendationProductsByUrl(S));
|
|
744
745
|
}
|
|
745
746
|
} catch {
|
|
746
|
-
|
|
747
|
+
r = [];
|
|
747
748
|
}
|
|
748
|
-
|
|
749
|
+
h.get(t) === e && this._setBlockProducts(t, r, s);
|
|
749
750
|
},
|
|
750
|
-
_setBlockProducts(t, e,
|
|
751
|
+
_setBlockProducts(t, e, n) {
|
|
751
752
|
if (!this.blockStates[t])
|
|
752
753
|
return;
|
|
753
|
-
const
|
|
754
|
+
const r = e.length > 0 ? e : w(n);
|
|
754
755
|
this.blockStates[t].recommendationProducts = [
|
|
755
|
-
...
|
|
756
|
-
...w(Math.max(0,
|
|
756
|
+
...r.slice(0, n),
|
|
757
|
+
...w(Math.max(0, n - r.length))
|
|
757
758
|
];
|
|
758
759
|
}
|
|
759
760
|
}
|
|
760
761
|
});
|
|
761
762
|
export {
|
|
762
|
-
|
|
763
|
+
ut as useRecommendationExtensionStore
|
|
763
764
|
};
|