@useinsider/guido 3.16.0 → 3.17.0-beta.24a776b
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/README.md +1 -0
- package/dist/@types/config/schemas.js +12 -6
- package/dist/components/Guido.vue.js +6 -6
- package/dist/components/Guido.vue2.js +66 -63
- package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue.js +18 -0
- package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue2.js +65 -0
- package/dist/composables/useConfig.js +37 -30
- package/dist/composables/useCustomInterfaceAppearance.js +52 -38
- package/dist/composables/useRecommendation.js +51 -42
- package/dist/composables/useStripo.js +30 -29
- package/dist/config/migrator/itemsBlockMigrator.js +1 -1
- package/dist/config/migrator/recommendation/settingsMapper.js +19 -17
- package/dist/config/migrator/recommendationMigrator.js +56 -37
- package/dist/enums/academy.js +2 -1
- package/dist/enums/date.js +4 -3
- package/dist/enums/extensions/recommendationBlock.js +4 -1
- package/dist/enums/recommendation.js +17 -17
- package/dist/extensions/Blocks/Items/enums/productEnums.js +45 -45
- package/dist/extensions/Blocks/Recommendation/block.js +26 -21
- package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +36 -34
- package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +96 -95
- package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +37 -26
- package/dist/extensions/Blocks/Recommendation/controls/main/index.js +147 -150
- package/dist/extensions/Blocks/Recommendation/controls/main/strategy.js +136 -0
- package/dist/extensions/Blocks/Recommendation/services/configService.js +35 -35
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +247 -107
- package/dist/extensions/Blocks/Recommendation/utils/productIds.js +6 -0
- package/dist/extensions/Blocks/common-control.js +22 -19
- package/dist/guido.css +1 -1
- package/dist/services/recommendationApi.js +72 -30
- package/dist/src/@types/config/schemas.d.ts +12 -0
- package/dist/src/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue.d.ts +3 -0
- package/dist/src/composables/useConfig.d.ts +3 -0
- package/dist/src/composables/useRecommendation.d.ts +1 -0
- package/dist/src/enums/academy.d.ts +1 -0
- package/dist/src/enums/extensions/recommendationBlock.d.ts +2 -0
- package/dist/src/extensions/Blocks/Recommendation/constants/defaultConfig.d.ts +7 -6
- package/dist/src/extensions/Blocks/Recommendation/constants/index.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +9 -3
- package/dist/src/extensions/Blocks/Recommendation/controls/main/strategy.d.ts +29 -0
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +204 -10
- package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +6 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/productIds.d.ts +6 -0
- package/dist/src/extensions/Blocks/common-control.d.ts +4 -1
- package/dist/src/mock/api/recommendation-strategies.d.ts +63 -0
- package/dist/src/services/recommendationApi.d.ts +4 -1
- package/dist/src/stores/config.d.ts +18 -0
- package/dist/src/stores/template.d.ts +14 -0
- package/dist/src/utils/strategyInfoBox.d.ts +18 -0
- package/dist/static/assets/icons/line-change.svg.js +5 -0
- package/dist/static/assets/icons/line-delete.svg.js +5 -0
- package/dist/static/assets/icons/line-plus.svg.js +5 -0
- package/dist/static/styles/components/recommendation-strategy.css.js +172 -0
- package/dist/stores/template.js +13 -8
- package/dist/utils/dateUtil.js +23 -10
- package/dist/utils/strategyInfoBox.js +37 -0
- package/dist/utils/templatePreparation.js +37 -34
- package/package.json +2 -1
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { useConfig as C } from "../../../../composables/useConfig.js";
|
|
2
|
+
import { getRecommendationFeedSourceMaps as y, getOperatorOptions as w, PriceAttributes as G } from "../../../../enums/extensions/recommendationBlock.js";
|
|
3
|
+
import { useRecommendationApi as D } from "../../../../services/recommendationApi.js";
|
|
4
|
+
import { useConfigStore as P } from "../../../../stores/config.js";
|
|
4
5
|
import { defineStore as F } from "pinia";
|
|
5
6
|
import "../constants/selectors.js";
|
|
6
|
-
import { DEFAULT_MOBILE_CARDS_IN_ROW as
|
|
7
|
-
import { EXCLUDED_ALGORITHM_IDS as
|
|
8
|
-
import { getDefaultProducts as
|
|
7
|
+
import { DEFAULT_MOBILE_CARDS_IN_ROW as v, DEFAULT_CARDS_IN_ROW as _ } from "../constants/layout.js";
|
|
8
|
+
import { DEFAULT_NODE_CONFIG as U, EXCLUDED_ALGORITHM_IDS as N } from "../constants/defaultConfig.js";
|
|
9
|
+
import { getDefaultProducts as I } from "../templates/utils.js";
|
|
9
10
|
import { generateCompleteFilterQuery as b } from "../utils/filterUtil.js";
|
|
10
|
-
import { getPartnerRecommendationParams as
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
import { getPartnerRecommendationParams as L } from "../utils/partnerCustomizations.js";
|
|
12
|
+
import { sanitizeProductIds as x } from "../utils/productIds.js";
|
|
13
|
+
import { isFilterValid as A } from "../validation/filterSchema.js";
|
|
14
|
+
import { isConfigValid as B } from "../validation/requiredFields.js";
|
|
15
|
+
const m = D();
|
|
16
|
+
let f = null, g = null, h = null, S = null;
|
|
17
|
+
function R() {
|
|
16
18
|
return {
|
|
17
|
-
cardsInRow:
|
|
19
|
+
cardsInRow: _,
|
|
18
20
|
currencySettings: {
|
|
19
21
|
name: "USD",
|
|
20
22
|
value: "USD",
|
|
@@ -28,13 +30,14 @@ function k() {
|
|
|
28
30
|
productIds: [],
|
|
29
31
|
id: 1,
|
|
30
32
|
language: "en_US",
|
|
31
|
-
mobileCardsInRow:
|
|
33
|
+
mobileCardsInRow: v,
|
|
32
34
|
mobileLayoutEnabled: !1,
|
|
33
35
|
orientation: "grid",
|
|
34
36
|
recommendedProducts: [],
|
|
35
37
|
sendProductRequestFlag: !1,
|
|
36
38
|
shuffleProducts: !1,
|
|
37
39
|
strategy: "mostPopular",
|
|
40
|
+
strategyId: "",
|
|
38
41
|
textTrimming: !0,
|
|
39
42
|
unresponsive: !1,
|
|
40
43
|
size: "6",
|
|
@@ -43,28 +46,32 @@ function k() {
|
|
|
43
46
|
priceHideIfSameAsDiscounted: !1
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
|
-
function
|
|
49
|
+
function k() {
|
|
47
50
|
return {
|
|
48
|
-
recommendationConfigs:
|
|
51
|
+
recommendationConfigs: R(),
|
|
49
52
|
recommendationProducts: [],
|
|
50
53
|
filterStatus: !1,
|
|
51
54
|
filterSelectionDrawerStatus: !1,
|
|
55
|
+
assignStrategyDrawerStatus: !1,
|
|
52
56
|
filterGroup: 1,
|
|
53
57
|
isInitialized: !1,
|
|
54
58
|
filterSnapshot: null
|
|
55
59
|
};
|
|
56
60
|
}
|
|
57
|
-
const
|
|
61
|
+
const z = () => ({
|
|
58
62
|
recommendationCampaignUrls: {},
|
|
59
63
|
activePredictiveAlgorithms: [],
|
|
60
64
|
languages: {},
|
|
61
65
|
currencyList: [],
|
|
62
66
|
filterList: {},
|
|
67
|
+
strategies: [],
|
|
68
|
+
strategiesLoading: !1,
|
|
69
|
+
strategyUrlTemplates: {},
|
|
63
70
|
blockStates: {},
|
|
64
71
|
currentRecommendationId: null,
|
|
65
72
|
configVersion: 0
|
|
66
|
-
}),
|
|
67
|
-
state: () =>
|
|
73
|
+
}), Y = F("guidoRecommendationExtension", {
|
|
74
|
+
state: () => z(),
|
|
68
75
|
getters: {
|
|
69
76
|
// ====================================================================
|
|
70
77
|
// Proxy Getters — Backward Compatible Access to Current Block State
|
|
@@ -74,7 +81,7 @@ const L = () => ({
|
|
|
74
81
|
* This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
|
|
75
82
|
*/
|
|
76
83
|
recommendationConfigs(t) {
|
|
77
|
-
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs :
|
|
84
|
+
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : R();
|
|
78
85
|
},
|
|
79
86
|
/**
|
|
80
87
|
* Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
|
|
@@ -88,6 +95,20 @@ const L = () => ({
|
|
|
88
95
|
filterSelectionDrawerStatus(t) {
|
|
89
96
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].filterSelectionDrawerStatus : !1;
|
|
90
97
|
},
|
|
98
|
+
/**
|
|
99
|
+
* Proxy getter: delegates to blockStates[currentRecommendationId].assignStrategyDrawerStatus
|
|
100
|
+
*/
|
|
101
|
+
assignStrategyDrawerStatus(t) {
|
|
102
|
+
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].assignStrategyDrawerStatus : !1;
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* The current block's assigned strategy record from the listing,
|
|
106
|
+
* or null when nothing is assigned / the strategy is no longer listed.
|
|
107
|
+
*/
|
|
108
|
+
assignedStrategy(t) {
|
|
109
|
+
const { strategyId: e } = this.recommendationConfigs;
|
|
110
|
+
return e ? t.strategies.find((r) => String(r.strategy_id) === e) ?? null : null;
|
|
111
|
+
},
|
|
91
112
|
/**
|
|
92
113
|
* Proxy getter: delegates to blockStates[currentRecommendationId].filterStatus
|
|
93
114
|
*/
|
|
@@ -119,12 +140,12 @@ const L = () => ({
|
|
|
119
140
|
return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
|
|
120
141
|
},
|
|
121
142
|
getActivePredictiveAlgorithms: (t) => {
|
|
122
|
-
const e =
|
|
123
|
-
return t.activePredictiveAlgorithms.filter((
|
|
124
|
-
r.push(...e.filter((
|
|
125
|
-
}), r.map((
|
|
126
|
-
text:
|
|
127
|
-
value:
|
|
143
|
+
const e = y(), r = [];
|
|
144
|
+
return t.activePredictiveAlgorithms.filter((i) => !N.includes(i)).forEach((i) => {
|
|
145
|
+
r.push(...e.filter((s) => s.id === i));
|
|
146
|
+
}), r.map((i) => ({
|
|
147
|
+
text: i.name,
|
|
148
|
+
value: i.key
|
|
128
149
|
}));
|
|
129
150
|
},
|
|
130
151
|
getLanguages: (t) => Object.entries(t.languages).map(([e, r]) => ({
|
|
@@ -138,7 +159,7 @@ const L = () => ({
|
|
|
138
159
|
getFilterList() {
|
|
139
160
|
return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
|
|
140
161
|
let e;
|
|
141
|
-
return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` :
|
|
162
|
+
return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : G.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
|
|
142
163
|
text: t.displayName,
|
|
143
164
|
value: e,
|
|
144
165
|
type: t.attributeType
|
|
@@ -160,7 +181,7 @@ const L = () => ({
|
|
|
160
181
|
setCurrentBlock(t) {
|
|
161
182
|
this.blockStates[t] || (this.blockStates = {
|
|
162
183
|
...this.blockStates,
|
|
163
|
-
[t]:
|
|
184
|
+
[t]: k()
|
|
164
185
|
}), this.currentRecommendationId = t;
|
|
165
186
|
},
|
|
166
187
|
/**
|
|
@@ -170,13 +191,13 @@ const L = () => ({
|
|
|
170
191
|
removeBlockState(t) {
|
|
171
192
|
const e = t.toString();
|
|
172
193
|
if (this.recommendationCampaignUrls[e]) {
|
|
173
|
-
const
|
|
174
|
-
delete
|
|
194
|
+
const i = { ...this.recommendationCampaignUrls };
|
|
195
|
+
delete i[e], this.recommendationCampaignUrls = i;
|
|
175
196
|
}
|
|
176
197
|
const r = { ...this.blockStates };
|
|
177
198
|
if (delete r[t], this.blockStates = r, this.currentRecommendationId === t) {
|
|
178
|
-
const
|
|
179
|
-
this.currentRecommendationId =
|
|
199
|
+
const i = Object.keys(this.blockStates).map(Number);
|
|
200
|
+
this.currentRecommendationId = i.length > 0 ? i[0] : null;
|
|
180
201
|
}
|
|
181
202
|
},
|
|
182
203
|
/**
|
|
@@ -192,10 +213,10 @@ const L = () => ({
|
|
|
192
213
|
[e]: o
|
|
193
214
|
};
|
|
194
215
|
}
|
|
195
|
-
const
|
|
196
|
-
|
|
216
|
+
const i = t.toString(), s = e.toString(), n = this.recommendationCampaignUrls[i];
|
|
217
|
+
n && (this.recommendationCampaignUrls = {
|
|
197
218
|
...this.recommendationCampaignUrls,
|
|
198
|
-
[
|
|
219
|
+
[s]: n
|
|
199
220
|
});
|
|
200
221
|
},
|
|
201
222
|
/**
|
|
@@ -220,7 +241,7 @@ const L = () => ({
|
|
|
220
241
|
* `isInitialized`) alone.
|
|
221
242
|
*/
|
|
222
243
|
seedBlockUrlConfig(t, e) {
|
|
223
|
-
const r = (o,
|
|
244
|
+
const r = (o, a) => o === "." || o === "," || o === " " ? o : a, i = {
|
|
224
245
|
name: e.currencyCode,
|
|
225
246
|
value: e.currencyCode,
|
|
226
247
|
symbol: e.currencyCode,
|
|
@@ -228,19 +249,20 @@ const L = () => ({
|
|
|
228
249
|
decimalCount: String(e.currencyDecimalCount),
|
|
229
250
|
decimalSeparator: r(e.currencyDecimalSeparator, ","),
|
|
230
251
|
thousandSeparator: r(e.currencyThousandSeparator, ".")
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
...
|
|
252
|
+
}, s = !this.blockStates[t], n = s ? k() : this.blockStates[t];
|
|
253
|
+
n.recommendationConfigs = {
|
|
254
|
+
...n.recommendationConfigs,
|
|
234
255
|
strategy: e.strategy,
|
|
256
|
+
strategyId: e.strategyId,
|
|
235
257
|
language: e.language,
|
|
236
258
|
size: e.size,
|
|
237
259
|
productIds: e.productIds,
|
|
238
260
|
filters: e.filters,
|
|
239
261
|
shuffleProducts: e.shuffleProducts,
|
|
240
|
-
currencySettings:
|
|
241
|
-
},
|
|
262
|
+
currencySettings: i
|
|
263
|
+
}, s && (this.blockStates = {
|
|
242
264
|
...this.blockStates,
|
|
243
|
-
[t]:
|
|
265
|
+
[t]: n
|
|
244
266
|
});
|
|
245
267
|
},
|
|
246
268
|
/**
|
|
@@ -259,18 +281,18 @@ const L = () => ({
|
|
|
259
281
|
...t.currencySettings || {}
|
|
260
282
|
}
|
|
261
283
|
};
|
|
262
|
-
const { triggerRefetch:
|
|
263
|
-
|
|
284
|
+
const { triggerRefetch: i = !0 } = e;
|
|
285
|
+
i && this.configVersion++;
|
|
264
286
|
},
|
|
265
287
|
/**
|
|
266
288
|
* Creates a filter with the first available attribute and operator pre-selected.
|
|
267
289
|
*/
|
|
268
290
|
createDefaultFilter(t, e) {
|
|
269
|
-
const [r] = this.getFilterList, [
|
|
291
|
+
const [r] = this.getFilterList, [i] = w(r == null ? void 0 : r.type);
|
|
270
292
|
return {
|
|
271
293
|
type: "standardFilter",
|
|
272
294
|
attribute: (r == null ? void 0 : r.value) ?? "",
|
|
273
|
-
operator: (
|
|
295
|
+
operator: (i == null ? void 0 : i.value) ?? "",
|
|
274
296
|
innerGroupOperator: "*",
|
|
275
297
|
outerGroupOperator: "*",
|
|
276
298
|
filterNumber: e,
|
|
@@ -314,47 +336,127 @@ const L = () => ({
|
|
|
314
336
|
t.filterSnapshot !== null && (t.recommendationConfigs.filters = t.filterSnapshot, t.filterSnapshot = null), t.filterSelectionDrawerStatus = !1;
|
|
315
337
|
},
|
|
316
338
|
// ====================================================================
|
|
339
|
+
// Reusable Recommendation Strategy (SD-149105)
|
|
340
|
+
// ====================================================================
|
|
341
|
+
/**
|
|
342
|
+
* Opens the Assign Strategy drawer for the current block.
|
|
343
|
+
* Selection state lives in the drawer component until Assign is
|
|
344
|
+
* pressed, so closing without assigning needs no snapshot/revert.
|
|
345
|
+
*/
|
|
346
|
+
openAssignStrategyDrawer() {
|
|
347
|
+
this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].assignStrategyDrawerStatus = !0);
|
|
348
|
+
},
|
|
349
|
+
closeAssignStrategyDrawer() {
|
|
350
|
+
this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].assignStrategyDrawerStatus = !1);
|
|
351
|
+
},
|
|
352
|
+
/**
|
|
353
|
+
* Fetches the active + EMAIL strategy listing. Always fetches fresh
|
|
354
|
+
* (dead-strategy detection and post-create refresh need freshness);
|
|
355
|
+
* only concurrent in-flight calls share one request.
|
|
356
|
+
*/
|
|
357
|
+
async fetchStrategies() {
|
|
358
|
+
if (S) {
|
|
359
|
+
await S;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
S = (async () => {
|
|
363
|
+
this.strategiesLoading = !0;
|
|
364
|
+
try {
|
|
365
|
+
this.strategies = await m.fetchRecommendationStrategies();
|
|
366
|
+
} finally {
|
|
367
|
+
this.strategiesLoading = !1;
|
|
368
|
+
}
|
|
369
|
+
})();
|
|
370
|
+
try {
|
|
371
|
+
await S;
|
|
372
|
+
} finally {
|
|
373
|
+
S = null;
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
/**
|
|
377
|
+
* Resolves a strategy's recommendation endpoint template via
|
|
378
|
+
* endpoint-generate, cached per strategy id + revision. Failures throw
|
|
379
|
+
* and are NOT cached, so the next attempt retries.
|
|
380
|
+
*
|
|
381
|
+
* `full_path` bakes in the algorithm path and `size=` as they were when
|
|
382
|
+
* generated, so the revision keys the cache — and a record with no
|
|
383
|
+
* revision is not cached at all, since its key could never change.
|
|
384
|
+
*/
|
|
385
|
+
async resolveStrategyUrlTemplate(t) {
|
|
386
|
+
const e = typeof t.updated_at == "string" ? t.updated_at : "", r = e ? `${t.strategy_id}:${e}` : "", i = r ? this.strategyUrlTemplates[r] : void 0;
|
|
387
|
+
if (i)
|
|
388
|
+
return i;
|
|
389
|
+
const { full_path: s } = await m.generateStrategyEndpoint(t);
|
|
390
|
+
return r && (this.strategyUrlTemplates = {
|
|
391
|
+
...this.strategyUrlTemplates,
|
|
392
|
+
[r]: s
|
|
393
|
+
}), s;
|
|
394
|
+
},
|
|
395
|
+
/**
|
|
396
|
+
* Assigns a strategy to the current block. The config write is
|
|
397
|
+
* synchronous (before any await) so a block switch cannot misdirect
|
|
398
|
+
* it; the configVersion bump persists it to node config and triggers
|
|
399
|
+
* the product refetch via the coordinator control's subscription.
|
|
400
|
+
*/
|
|
401
|
+
assignStrategy(t) {
|
|
402
|
+
this.patchCurrentBlockConfig({
|
|
403
|
+
strategyId: String(t.strategy_id),
|
|
404
|
+
...t.size !== void 0 ? { size: String(t.size) } : {}
|
|
405
|
+
});
|
|
406
|
+
},
|
|
407
|
+
/**
|
|
408
|
+
* Clears the current block's strategy; it falls back to the per-block
|
|
409
|
+
* algorithm settings.
|
|
410
|
+
*
|
|
411
|
+
* `size` goes back to the default rather than staying on the removed
|
|
412
|
+
* strategy's count: with Number of Products hidden in RRS mode, a block
|
|
413
|
+
* left on that count would have no UI to correct it.
|
|
414
|
+
*/
|
|
415
|
+
removeStrategy() {
|
|
416
|
+
this.patchCurrentBlockConfig({ strategyId: "", size: U.size });
|
|
417
|
+
},
|
|
418
|
+
// ====================================================================
|
|
317
419
|
// Shared Data Fetching (fetched once, used by all blocks)
|
|
318
420
|
// ====================================================================
|
|
319
421
|
async fetchRecommendationCreateData() {
|
|
320
422
|
if (!this.activePredictiveAlgorithms.length) {
|
|
321
|
-
if (
|
|
322
|
-
await
|
|
423
|
+
if (f) {
|
|
424
|
+
await f;
|
|
323
425
|
return;
|
|
324
426
|
}
|
|
325
|
-
|
|
427
|
+
f = (async () => {
|
|
326
428
|
const {
|
|
327
429
|
activePredictiveAlgorithms: t,
|
|
328
430
|
languages: e,
|
|
329
431
|
currencies: r
|
|
330
|
-
} = await
|
|
432
|
+
} = await m.fetchRecommendationCreateData();
|
|
331
433
|
if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
|
|
332
|
-
const
|
|
333
|
-
|
|
434
|
+
const i = this.blockStates[this.currentRecommendationId];
|
|
435
|
+
i.filterStatus = !!i.recommendationConfigs.filters.length;
|
|
334
436
|
}
|
|
335
437
|
this.currencyList = r;
|
|
336
438
|
})();
|
|
337
439
|
try {
|
|
338
|
-
await
|
|
440
|
+
await f;
|
|
339
441
|
} finally {
|
|
340
|
-
|
|
442
|
+
f = null;
|
|
341
443
|
}
|
|
342
444
|
}
|
|
343
445
|
},
|
|
344
446
|
async fetchRecommendationFilters() {
|
|
345
447
|
if (!Object.keys(this.filterList).length) {
|
|
346
|
-
if (
|
|
347
|
-
await
|
|
448
|
+
if (g) {
|
|
449
|
+
await g;
|
|
348
450
|
return;
|
|
349
451
|
}
|
|
350
|
-
|
|
351
|
-
const t = await
|
|
452
|
+
g = (async () => {
|
|
453
|
+
const t = await m.fetchRecommendationFilters();
|
|
352
454
|
this.filterList = t;
|
|
353
455
|
})();
|
|
354
456
|
try {
|
|
355
|
-
await
|
|
457
|
+
await g;
|
|
356
458
|
} finally {
|
|
357
|
-
|
|
459
|
+
g = null;
|
|
358
460
|
}
|
|
359
461
|
}
|
|
360
462
|
},
|
|
@@ -369,55 +471,55 @@ const L = () => ({
|
|
|
369
471
|
deleteFilterGroup(t) {
|
|
370
472
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
371
473
|
return;
|
|
372
|
-
const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.filter((
|
|
373
|
-
e.recommendationConfigs.filters = r.map((
|
|
374
|
-
...
|
|
375
|
-
filterGroup:
|
|
474
|
+
const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.filter((n) => n.filterGroup !== t), i = [...new Set(r.map((n) => n.filterGroup))].sort((n, o) => n - o), s = new Map(i.map((n, o) => [n, o + 1]));
|
|
475
|
+
e.recommendationConfigs.filters = r.map((n) => ({
|
|
476
|
+
...n,
|
|
477
|
+
filterGroup: s.get(n.filterGroup) ?? n.filterGroup
|
|
376
478
|
}));
|
|
377
479
|
},
|
|
378
480
|
updateFilter(t) {
|
|
379
481
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
380
482
|
return;
|
|
381
|
-
const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.findIndex((
|
|
483
|
+
const e = this.blockStates[this.currentRecommendationId], r = e.recommendationConfigs.filters.findIndex((i) => i.filterNumber === t.filterNumber && i.filterGroup === t.filterGroup);
|
|
382
484
|
if (r !== -1) {
|
|
383
|
-
const
|
|
384
|
-
|
|
485
|
+
const i = [...e.recommendationConfigs.filters];
|
|
486
|
+
i[r] = {
|
|
385
487
|
...t,
|
|
386
|
-
isValid:
|
|
387
|
-
}, e.recommendationConfigs.filters =
|
|
488
|
+
isValid: A(t)
|
|
489
|
+
}, e.recommendationConfigs.filters = i;
|
|
388
490
|
}
|
|
389
491
|
},
|
|
390
492
|
deleteFilter(t) {
|
|
391
493
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
392
494
|
return;
|
|
393
|
-
const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters].findIndex((
|
|
495
|
+
const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters].findIndex((i) => i.filterNumber === t.filterNumber && i.filterGroup === t.filterGroup);
|
|
394
496
|
if (r !== -1) {
|
|
395
|
-
let
|
|
396
|
-
if (
|
|
397
|
-
let
|
|
398
|
-
|
|
497
|
+
let i = [...e.recommendationConfigs.filters];
|
|
498
|
+
if (i.splice(r, 1), i.some((n) => n.filterGroup === t.filterGroup)) {
|
|
499
|
+
let n = 1;
|
|
500
|
+
i = i.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: n++ } : o);
|
|
399
501
|
} else {
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
...
|
|
403
|
-
filterGroup: o.get(
|
|
502
|
+
const n = [...new Set(i.map((a) => a.filterGroup))].sort((a, l) => a - l), o = new Map(n.map((a, l) => [a, l + 1]));
|
|
503
|
+
i = i.map((a) => ({
|
|
504
|
+
...a,
|
|
505
|
+
filterGroup: o.get(a.filterGroup) ?? a.filterGroup
|
|
404
506
|
}));
|
|
405
507
|
}
|
|
406
|
-
e.recommendationConfigs.filters =
|
|
508
|
+
e.recommendationConfigs.filters = i;
|
|
407
509
|
}
|
|
408
510
|
},
|
|
409
511
|
addFilter(t) {
|
|
410
512
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
411
513
|
return;
|
|
412
|
-
const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters],
|
|
514
|
+
const e = this.blockStates[this.currentRecommendationId], r = [...e.recommendationConfigs.filters], s = r.filter(
|
|
413
515
|
(o) => o.filterGroup === t.filterGroup
|
|
414
|
-
).length + 1,
|
|
415
|
-
|
|
516
|
+
).length + 1, n = r.findLastIndex((o) => o.filterGroup === t.filterGroup);
|
|
517
|
+
n !== -1 ? r.splice(n + 1, 0, {
|
|
416
518
|
...t,
|
|
417
|
-
filterNumber:
|
|
519
|
+
filterNumber: s
|
|
418
520
|
}) : r.push({
|
|
419
521
|
...t,
|
|
420
|
-
filterNumber:
|
|
522
|
+
filterNumber: s
|
|
421
523
|
}), e.recommendationConfigs.filters = r;
|
|
422
524
|
},
|
|
423
525
|
generateFilterQuery() {
|
|
@@ -429,55 +531,93 @@ const L = () => ({
|
|
|
429
531
|
* every block's recommendationConfigs across user edits.
|
|
430
532
|
*/
|
|
431
533
|
hasInvalidBlock() {
|
|
432
|
-
return Object.values(this.blockStates).some((t) => !
|
|
534
|
+
return Object.values(this.blockStates).some((t) => !B(t.recommendationConfigs, this));
|
|
433
535
|
},
|
|
434
536
|
// ====================================================================
|
|
435
537
|
// Per-Block Product Fetching
|
|
436
538
|
// ====================================================================
|
|
437
539
|
async fetchRecommendationProducts() {
|
|
438
540
|
if (!(this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])) {
|
|
439
|
-
if (
|
|
440
|
-
await
|
|
541
|
+
if (h) {
|
|
542
|
+
await h;
|
|
441
543
|
return;
|
|
442
544
|
}
|
|
443
|
-
|
|
545
|
+
h = this._doFetchProducts();
|
|
444
546
|
try {
|
|
445
|
-
await
|
|
547
|
+
await h;
|
|
446
548
|
} finally {
|
|
447
|
-
|
|
549
|
+
h = null;
|
|
448
550
|
}
|
|
449
551
|
}
|
|
450
552
|
},
|
|
451
553
|
async _doFetchProducts() {
|
|
452
|
-
var
|
|
453
|
-
const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e,
|
|
554
|
+
var d;
|
|
555
|
+
const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, i = P(), { isRrsSessionActive: s } = C();
|
|
556
|
+
if (s() && r.strategyId) {
|
|
557
|
+
await this._doFetchStrategyProducts(t);
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const n = r.filters.filter((p) => p.isValid), o = b(n), a = ((d = y().find((p) => p.key === r.strategy)) == null ? void 0 : d.path) || "", l = parseInt(r.size) || 6, c = {
|
|
454
561
|
locale: r.language,
|
|
455
562
|
currency: r.currencySettings.value,
|
|
456
|
-
partnerName:
|
|
563
|
+
partnerName: i.partnerName,
|
|
457
564
|
size: r.size,
|
|
458
565
|
details: !0,
|
|
459
|
-
campaignId:
|
|
566
|
+
campaignId: i.variationId
|
|
460
567
|
};
|
|
461
|
-
r.strategy === "manualMerchandising" ?
|
|
462
|
-
|
|
463
|
-
|
|
568
|
+
r.strategy === "manualMerchandising" ? c.productId = x(r.productIds) : r.strategy === "similarViewed" && (c.productId = "{itemId}"), r.strategy === "userBased" && (c.userId = "{user_id}"), o && (c.filter = o), r.shuffleProducts && (c.shuffle = !0), Object.assign(
|
|
569
|
+
c,
|
|
570
|
+
L(i.partnerName, r.strategy)
|
|
464
571
|
);
|
|
465
|
-
let
|
|
572
|
+
let u;
|
|
466
573
|
try {
|
|
467
|
-
|
|
574
|
+
u = await m.fetchRecommendationProducts(a, c);
|
|
468
575
|
} catch {
|
|
469
|
-
|
|
576
|
+
u = [];
|
|
470
577
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
578
|
+
this._setBlockProducts(t, u, l);
|
|
579
|
+
},
|
|
580
|
+
/**
|
|
581
|
+
* Fetches products for a strategy-backed block: listing lookup →
|
|
582
|
+
* endpoint-generate template → fill {locale}/{currency}, drop
|
|
583
|
+
* {user_id} (resolved at send time) → fetch. Any failure (dead
|
|
584
|
+
* strategy, resolution error) falls back to placeholder products.
|
|
585
|
+
*/
|
|
586
|
+
async _doFetchStrategyProducts(t) {
|
|
587
|
+
const { recommendationConfigs: e } = this.blockStates[t];
|
|
588
|
+
let r = [], i = parseInt(e.size) || 6;
|
|
589
|
+
try {
|
|
590
|
+
this.strategies.length || await this.fetchStrategies();
|
|
591
|
+
const s = this.strategies.find(
|
|
592
|
+
(n) => String(n.strategy_id) === e.strategyId
|
|
593
|
+
);
|
|
594
|
+
if (s) {
|
|
595
|
+
i = parseInt(String(s.size ?? "")) || i;
|
|
596
|
+
const o = (await this.resolveStrategyUrlTemplate(s)).replaceAll("{locale}", e.language).replaceAll("{currency}", e.currencySettings.value), a = o.indexOf("?"), l = a === -1 ? o : o.slice(0, a), c = (a === -1 ? "" : o.slice(a + 1)).split("&").filter((d) => d && !d.startsWith("user_id=")), u = c.length ? `${l}?${c.join("&")}` : l;
|
|
597
|
+
r = await m.fetchRecommendationProductsByUrl(u);
|
|
598
|
+
}
|
|
599
|
+
} catch {
|
|
600
|
+
r = [];
|
|
477
601
|
}
|
|
602
|
+
this._setBlockProducts(t, r, i);
|
|
603
|
+
},
|
|
604
|
+
/**
|
|
605
|
+
* Writes products to a block's state, padded/clipped to exactly `size`:
|
|
606
|
+
* in-place content updates compare the DOM element count against
|
|
607
|
+
* products.length, and a longer list makes the renderer extend its slot
|
|
608
|
+
* grid, which resets migrator-applied styles.
|
|
609
|
+
*/
|
|
610
|
+
_setBlockProducts(t, e, r) {
|
|
611
|
+
if (!this.blockStates[t])
|
|
612
|
+
return;
|
|
613
|
+
const i = e.length > 0 ? e : I(r);
|
|
614
|
+
this.blockStates[t].recommendationProducts = [
|
|
615
|
+
...i.slice(0, r),
|
|
616
|
+
...I(Math.max(0, r - i.length))
|
|
617
|
+
];
|
|
478
618
|
}
|
|
479
619
|
}
|
|
480
620
|
});
|
|
481
621
|
export {
|
|
482
|
-
|
|
622
|
+
Y as useRecommendationExtensionStore
|
|
483
623
|
};
|