@useinsider/guido 3.20.0 → 3.20.1
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/config/compiler/itemsCompilerRules.js +21 -5
- package/dist/config/compiler/utils/itemsCompilerUtils.js +64 -17
- package/dist/config/migrator/itemsBlockMigrator.js +112 -108
- package/dist/extensions/Blocks/Items/block.js +78 -67
- package/dist/extensions/Blocks/Items/constants/cardWidth.js +20 -0
- package/dist/extensions/Blocks/Items/layouts/vertical.html.js +1 -1
- package/dist/extensions/Blocks/Recommendation/block.js +51 -44
- package/dist/extensions/Blocks/Recommendation/controls/cardComposition/index.js +103 -91
- package/dist/extensions/Blocks/Recommendation/controls/main/index.js +90 -73
- package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +209 -203
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +122 -90
- package/dist/extensions/Blocks/Recommendation/utils/blockUrlConfig.js +25 -0
- package/dist/extensions/Blocks/Recommendation/utils/captureStyleTemplates.js +72 -70
- package/dist/extensions/Blocks/Recommendation/utils/compositionKeys.js +69 -60
- package/dist/extensions/Blocks/Recommendation/utils/nodeConfigWriter.js +46 -25
- package/dist/extensions/Blocks/Recommendation/utils/strategyCommit.js +40 -17
- package/dist/src/config/compiler/utils/itemsCompilerUtils.d.ts +10 -0
- package/dist/src/extensions/Blocks/Items/block.d.ts +5 -0
- package/dist/src/extensions/Blocks/Items/constants/cardWidth.d.ts +12 -0
- package/dist/src/extensions/Blocks/Recommendation/block.d.ts +2 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/cardComposition/index.d.ts +3 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +2 -0
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +18 -5
- package/dist/src/extensions/Blocks/Recommendation/utils/blockUrlConfig.d.ts +4 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/compositionKeys.d.ts +4 -0
- package/dist/src/extensions/Blocks/Recommendation/utils/nodeConfigWriter.d.ts +3 -1
- package/dist/src/extensions/Blocks/Recommendation/utils/strategyCommit.d.ts +7 -0
- package/dist/src/utils/liquidProtection.d.ts +3 -0
- package/dist/utils/liquidProtection.js +5 -0
- package/dist/utils/templatePreparation.js +61 -85
- package/package.json +1 -1
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import { useToaster as
|
|
2
|
-
import { useTranslations as
|
|
3
|
-
import { getRecommendationFeedSourceMaps as
|
|
4
|
-
import { ToasterTypeOptions as
|
|
5
|
-
import { useRecommendationApi as
|
|
1
|
+
import { useToaster as U } from "../../../../composables/useToaster.js";
|
|
2
|
+
import { useTranslations as M } from "../../../../composables/useTranslations.js";
|
|
3
|
+
import { getRecommendationFeedSourceMaps as w, strategyEditPath as N, strategyCreatePath as B, getOperatorOptions as z, PriceAttributes as E } from "../../../../enums/extensions/recommendationBlock.js";
|
|
4
|
+
import { ToasterTypeOptions as O } from "../../../../enums/toaster.js";
|
|
5
|
+
import { useRecommendationApi as A } from "../../../../services/recommendationApi.js";
|
|
6
6
|
import { useConfigStore as R } from "../../../../stores/config.js";
|
|
7
|
-
import { defineStore as
|
|
7
|
+
import { defineStore as x } 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 S = null,
|
|
20
|
-
const
|
|
9
|
+
import { DEFAULT_MOBILE_CARDS_IN_ROW as T, DEFAULT_CARDS_IN_ROW as V } from "../constants/layout.js";
|
|
10
|
+
import { CURRENT_CONFIG_VERSION as C, DEFAULT_NODE_CONFIG as j, EXCLUDED_ALGORITHM_IDS as $ } from "../constants/defaultConfig.js";
|
|
11
|
+
import { getDefaultProducts as P } from "../templates/utils.js";
|
|
12
|
+
import { generateCompleteFilterQuery as G } from "../utils/filterUtil.js";
|
|
13
|
+
import { isLegacyStrategyConfig as q } from "../utils/legacyStrategyMigration.js";
|
|
14
|
+
import { getPartnerRecommendationParams as K } from "../utils/partnerCustomizations.js";
|
|
15
|
+
import { sanitizeProductIds as H } from "../utils/productIds.js";
|
|
16
|
+
import { isFilterValid as J } from "../validation/filterSchema.js";
|
|
17
|
+
import { getInvalidFields as Q, isConfigValid as W } from "../validation/requiredFields.js";
|
|
18
|
+
const u = A();
|
|
19
|
+
let S = null, y = null, p = null, I = "", k = null, b = 0;
|
|
20
|
+
const m = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map();
|
|
21
|
+
function X(t) {
|
|
22
|
+
const e = D.get(t);
|
|
23
|
+
return e && e.token === m.get(t) ? e.outcome : !1;
|
|
24
|
+
}
|
|
21
25
|
let l = null;
|
|
22
|
-
function
|
|
26
|
+
function L() {
|
|
23
27
|
return {
|
|
24
|
-
cardsInRow:
|
|
28
|
+
cardsInRow: V,
|
|
25
29
|
currencySettings: {
|
|
26
30
|
name: "USD",
|
|
27
31
|
value: "USD",
|
|
@@ -35,7 +39,7 @@ function D() {
|
|
|
35
39
|
productIds: [],
|
|
36
40
|
id: 1,
|
|
37
41
|
language: "en_US",
|
|
38
|
-
mobileCardsInRow:
|
|
42
|
+
mobileCardsInRow: T,
|
|
39
43
|
mobileLayoutEnabled: !1,
|
|
40
44
|
orientation: "grid",
|
|
41
45
|
recommendedProducts: [],
|
|
@@ -56,9 +60,9 @@ function D() {
|
|
|
56
60
|
priceHideIfSameAsDiscounted: !1
|
|
57
61
|
};
|
|
58
62
|
}
|
|
59
|
-
function
|
|
63
|
+
function _() {
|
|
60
64
|
return {
|
|
61
|
-
recommendationConfigs:
|
|
65
|
+
recommendationConfigs: L(),
|
|
62
66
|
recommendationProducts: [],
|
|
63
67
|
filterStatus: !1,
|
|
64
68
|
filterSelectionDrawerStatus: !1,
|
|
@@ -72,7 +76,7 @@ function G() {
|
|
|
72
76
|
legacyConversionLoading: !1
|
|
73
77
|
};
|
|
74
78
|
}
|
|
75
|
-
const
|
|
79
|
+
const Y = () => ({
|
|
76
80
|
recommendationCampaignUrls: {},
|
|
77
81
|
activePredictiveAlgorithms: [],
|
|
78
82
|
languages: {},
|
|
@@ -87,8 +91,8 @@ const Q = () => ({
|
|
|
87
91
|
currentRecommendationId: null,
|
|
88
92
|
strategyPanelOpen: !1,
|
|
89
93
|
configVersion: 0
|
|
90
|
-
}),
|
|
91
|
-
state: () =>
|
|
94
|
+
}), St = x("guidoRecommendationExtension", {
|
|
95
|
+
state: () => Y(),
|
|
92
96
|
getters: {
|
|
93
97
|
// ====================================================================
|
|
94
98
|
// Proxy Getters — Backward Compatible Access to Current Block State
|
|
@@ -98,7 +102,7 @@ const Q = () => ({
|
|
|
98
102
|
* This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
|
|
99
103
|
*/
|
|
100
104
|
recommendationConfigs(t) {
|
|
101
|
-
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs :
|
|
105
|
+
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : L();
|
|
102
106
|
},
|
|
103
107
|
/**
|
|
104
108
|
* Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
|
|
@@ -119,7 +123,7 @@ const Q = () => ({
|
|
|
119
123
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].removeStrategyModalStatus : !1;
|
|
120
124
|
},
|
|
121
125
|
isLegacyStrategyBlock() {
|
|
122
|
-
return R().isFeatureEnabled("reusableRecommendationStrategy") &&
|
|
126
|
+
return R().isFeatureEnabled("reusableRecommendationStrategy") && q(this.recommendationConfigs);
|
|
123
127
|
},
|
|
124
128
|
legacyConversionLoading(t) {
|
|
125
129
|
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].legacyConversionLoading ?? !1 : !1;
|
|
@@ -162,8 +166,8 @@ const Q = () => ({
|
|
|
162
166
|
return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
|
|
163
167
|
},
|
|
164
168
|
getActivePredictiveAlgorithms: (t) => {
|
|
165
|
-
const e =
|
|
166
|
-
return t.activePredictiveAlgorithms.filter((n) =>
|
|
169
|
+
const e = w(), r = [];
|
|
170
|
+
return t.activePredictiveAlgorithms.filter((n) => !$.includes(n)).forEach((n) => {
|
|
167
171
|
r.push(...e.filter((s) => s.id === n));
|
|
168
172
|
}), r.map((n) => ({
|
|
169
173
|
text: n.name,
|
|
@@ -203,7 +207,7 @@ const Q = () => ({
|
|
|
203
207
|
setCurrentBlock(t) {
|
|
204
208
|
this.blockStates[t] || (this.blockStates = {
|
|
205
209
|
...this.blockStates,
|
|
206
|
-
[t]:
|
|
210
|
+
[t]: _()
|
|
207
211
|
}), this.currentRecommendationId = t;
|
|
208
212
|
},
|
|
209
213
|
/**
|
|
@@ -275,7 +279,7 @@ const Q = () => ({
|
|
|
275
279
|
decimalCount: String(e.currencyDecimalCount),
|
|
276
280
|
decimalSeparator: r(e.currencyDecimalSeparator, ","),
|
|
277
281
|
thousandSeparator: r(e.currencyThousandSeparator, ".")
|
|
278
|
-
}, s = !this.blockStates[t], i = s ?
|
|
282
|
+
}, s = !this.blockStates[t], i = s ? _() : this.blockStates[t];
|
|
279
283
|
i.recommendationConfigs = {
|
|
280
284
|
...i.recommendationConfigs,
|
|
281
285
|
strategy: e.strategy,
|
|
@@ -314,7 +318,7 @@ const Q = () => ({
|
|
|
314
318
|
* Creates a filter with the first available attribute and operator pre-selected.
|
|
315
319
|
*/
|
|
316
320
|
createDefaultFilter(t, e) {
|
|
317
|
-
const [r] = this.getFilterList, [n] =
|
|
321
|
+
const [r] = this.getFilterList, [n] = z(r == null ? void 0 : r.type);
|
|
318
322
|
return {
|
|
319
323
|
type: "standardFilter",
|
|
320
324
|
attribute: (r == null ? void 0 : r.value) ?? "",
|
|
@@ -390,7 +394,7 @@ const Q = () => ({
|
|
|
390
394
|
const t = b, e = (async () => {
|
|
391
395
|
this.strategiesLoading = !0;
|
|
392
396
|
try {
|
|
393
|
-
const r = await
|
|
397
|
+
const r = await u.fetchRecommendationStrategies();
|
|
394
398
|
if (t !== b)
|
|
395
399
|
return;
|
|
396
400
|
this.strategies = r, this.strategiesFetched = !0;
|
|
@@ -434,9 +438,9 @@ const Q = () => ({
|
|
|
434
438
|
_armStrategyPageReturn(t) {
|
|
435
439
|
const e = window.open(t, "_blank");
|
|
436
440
|
if (!e)
|
|
437
|
-
return
|
|
438
|
-
type:
|
|
439
|
-
message:
|
|
441
|
+
return U().showToaster({
|
|
442
|
+
type: O.Error,
|
|
443
|
+
message: M()("discovery-strategy.error-description")
|
|
440
444
|
}), !1;
|
|
441
445
|
e.opener = null, l == null || l();
|
|
442
446
|
let r = !1;
|
|
@@ -471,20 +475,20 @@ const Q = () => ({
|
|
|
471
475
|
* new strategy is offered; the user picks it themselves.
|
|
472
476
|
*/
|
|
473
477
|
openStrategyCreation() {
|
|
474
|
-
return this._armStrategyPageReturn(
|
|
478
|
+
return this._armStrategyPageReturn(B());
|
|
475
479
|
},
|
|
476
480
|
/**
|
|
477
481
|
* Opens the strategy's edit page. Every return refreshes the list so the block reflects the
|
|
478
482
|
* edited configuration.
|
|
479
483
|
*/
|
|
480
484
|
openStrategyEdit(t) {
|
|
481
|
-
return this._armStrategyPageReturn(
|
|
485
|
+
return this._armStrategyPageReturn(N(t));
|
|
482
486
|
},
|
|
483
487
|
async resolveStrategyUrlTemplate(t, e) {
|
|
484
488
|
const r = typeof t.updated_at == "string" ? t.updated_at : "", n = r ? `${t.strategy_id}:${r}:${e}` : "", s = n ? this.strategyUrlTemplates[n] : void 0;
|
|
485
489
|
if (s)
|
|
486
490
|
return s;
|
|
487
|
-
const { full_path: i = "" } = await
|
|
491
|
+
const { full_path: i = "" } = await u.generateStrategyEndpoint(t, e) ?? {};
|
|
488
492
|
return n && i && (this.strategyUrlTemplates = {
|
|
489
493
|
...this.strategyUrlTemplates,
|
|
490
494
|
[n]: i
|
|
@@ -502,7 +506,7 @@ const Q = () => ({
|
|
|
502
506
|
throw new Error("[Guido] convertLegacyStrategy called without an active block");
|
|
503
507
|
this.blockStates[r].legacyConversionLoading = !0;
|
|
504
508
|
try {
|
|
505
|
-
const n = await
|
|
509
|
+
const n = await u.migrateLegacyStrategy(t, e);
|
|
506
510
|
this.invalidateStrategies();
|
|
507
511
|
try {
|
|
508
512
|
await this.fetchStrategies();
|
|
@@ -533,7 +537,7 @@ const Q = () => ({
|
|
|
533
537
|
this.patchCurrentBlockConfig({
|
|
534
538
|
strategyId: "",
|
|
535
539
|
strategy: "",
|
|
536
|
-
size:
|
|
540
|
+
size: j.size,
|
|
537
541
|
nodeConfigVersion: C
|
|
538
542
|
});
|
|
539
543
|
},
|
|
@@ -551,7 +555,7 @@ const Q = () => ({
|
|
|
551
555
|
activePredictiveAlgorithms: t,
|
|
552
556
|
languages: e,
|
|
553
557
|
currencies: r
|
|
554
|
-
} = await
|
|
558
|
+
} = await u.fetchRecommendationCreateData();
|
|
555
559
|
if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
|
|
556
560
|
const n = this.blockStates[this.currentRecommendationId];
|
|
557
561
|
n.filterStatus = !!n.recommendationConfigs.filters.length;
|
|
@@ -567,18 +571,18 @@ const Q = () => ({
|
|
|
567
571
|
},
|
|
568
572
|
async fetchRecommendationFilters() {
|
|
569
573
|
if (!Object.keys(this.filterList).length) {
|
|
570
|
-
if (
|
|
571
|
-
await
|
|
574
|
+
if (y) {
|
|
575
|
+
await y;
|
|
572
576
|
return;
|
|
573
577
|
}
|
|
574
|
-
|
|
575
|
-
const t = await
|
|
578
|
+
y = (async () => {
|
|
579
|
+
const t = await u.fetchRecommendationFilters();
|
|
576
580
|
this.filterList = t;
|
|
577
581
|
})();
|
|
578
582
|
try {
|
|
579
|
-
await
|
|
583
|
+
await y;
|
|
580
584
|
} finally {
|
|
581
|
-
|
|
585
|
+
y = null;
|
|
582
586
|
}
|
|
583
587
|
}
|
|
584
588
|
},
|
|
@@ -607,7 +611,7 @@ const Q = () => ({
|
|
|
607
611
|
const n = [...e.recommendationConfigs.filters];
|
|
608
612
|
n[r] = {
|
|
609
613
|
...t,
|
|
610
|
-
isValid:
|
|
614
|
+
isValid: J(t)
|
|
611
615
|
}, e.recommendationConfigs.filters = n;
|
|
612
616
|
}
|
|
613
617
|
},
|
|
@@ -621,7 +625,7 @@ const Q = () => ({
|
|
|
621
625
|
let i = 1;
|
|
622
626
|
n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
|
|
623
627
|
} else {
|
|
624
|
-
const i = [...new Set(n.map((a) => a.filterGroup))].sort((a,
|
|
628
|
+
const i = [...new Set(n.map((a) => a.filterGroup))].sort((a, f) => a - f), o = new Map(i.map((a, f) => [a, f + 1]));
|
|
625
629
|
n = n.map((a) => ({
|
|
626
630
|
...a,
|
|
627
631
|
filterGroup: o.get(a.filterGroup) ?? a.filterGroup
|
|
@@ -645,7 +649,7 @@ const Q = () => ({
|
|
|
645
649
|
}), e.recommendationConfigs.filters = r;
|
|
646
650
|
},
|
|
647
651
|
generateFilterQuery() {
|
|
648
|
-
return
|
|
652
|
+
return G(this.recommendationConfigs.filters);
|
|
649
653
|
},
|
|
650
654
|
/**
|
|
651
655
|
* Validation-only check invoked at save-CTA time. Defined as an action
|
|
@@ -653,14 +657,14 @@ const Q = () => ({
|
|
|
653
657
|
* every block's recommendationConfigs across user edits.
|
|
654
658
|
*/
|
|
655
659
|
hasInvalidBlock() {
|
|
656
|
-
return Object.values(this.blockStates).some((t) => !
|
|
660
|
+
return Object.values(this.blockStates).some((t) => !W(t.recommendationConfigs, this));
|
|
657
661
|
},
|
|
658
662
|
/**
|
|
659
663
|
* Which required fields are missing across the design's blocks, so the save
|
|
660
664
|
* toaster can name the cause instead of always showing the generic message.
|
|
661
665
|
*/
|
|
662
666
|
invalidBlockFields() {
|
|
663
|
-
return Object.values(this.blockStates).flatMap((t) =>
|
|
667
|
+
return Object.values(this.blockStates).flatMap((t) => Q(t.recommendationConfigs, this));
|
|
664
668
|
},
|
|
665
669
|
// ====================================================================
|
|
666
670
|
// Per-Block Product Fetching
|
|
@@ -673,15 +677,15 @@ const Q = () => ({
|
|
|
673
677
|
this.configVersion,
|
|
674
678
|
b
|
|
675
679
|
].join(":");
|
|
676
|
-
if (
|
|
677
|
-
await
|
|
680
|
+
if (p && I === t) {
|
|
681
|
+
await p;
|
|
678
682
|
return;
|
|
679
683
|
}
|
|
680
|
-
I = t,
|
|
684
|
+
I = t, p = this._doFetchProducts();
|
|
681
685
|
try {
|
|
682
|
-
await
|
|
686
|
+
await p;
|
|
683
687
|
} finally {
|
|
684
|
-
I === t && (
|
|
688
|
+
I === t && (p = null, I = "");
|
|
685
689
|
}
|
|
686
690
|
},
|
|
687
691
|
async _doFetchProducts() {
|
|
@@ -691,14 +695,14 @@ const Q = () => ({
|
|
|
691
695
|
await this._doFetchStrategyProducts(t);
|
|
692
696
|
return;
|
|
693
697
|
}
|
|
694
|
-
const s = (
|
|
695
|
-
|
|
698
|
+
const s = (m.get(t) ?? 0) + 1;
|
|
699
|
+
m.set(t, s);
|
|
696
700
|
const i = parseInt(r.size) || 6;
|
|
697
701
|
if (!r.strategy) {
|
|
698
702
|
this._setBlockProducts(t, [], i);
|
|
699
703
|
return;
|
|
700
704
|
}
|
|
701
|
-
const o = r.filters.filter((
|
|
705
|
+
const o = r.filters.filter((g) => g.isValid), a = G(o), f = ((h = w().find((g) => g.key === r.strategy)) == null ? void 0 : h.path) || "", c = {
|
|
702
706
|
locale: r.language,
|
|
703
707
|
currency: r.currencySettings.value,
|
|
704
708
|
partnerName: n.partnerName,
|
|
@@ -706,58 +710,86 @@ const Q = () => ({
|
|
|
706
710
|
details: !0,
|
|
707
711
|
campaignId: n.variationId
|
|
708
712
|
};
|
|
709
|
-
r.strategy === "manualMerchandising" ? c.productId =
|
|
713
|
+
r.strategy === "manualMerchandising" ? c.productId = H(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
714
|
c,
|
|
711
|
-
|
|
715
|
+
K(n.partnerName, r.strategy)
|
|
712
716
|
);
|
|
713
|
-
let
|
|
717
|
+
let d;
|
|
714
718
|
try {
|
|
715
|
-
|
|
719
|
+
d = await u.fetchRecommendationProducts(f, c);
|
|
716
720
|
} catch {
|
|
717
|
-
|
|
721
|
+
d = [];
|
|
718
722
|
}
|
|
719
|
-
|
|
723
|
+
m.get(t) === s && this._setBlockProducts(t, d, i);
|
|
720
724
|
},
|
|
721
725
|
/**
|
|
722
|
-
* Block-scoped counterpart of `fetchRecommendationProducts`, which only
|
|
723
|
-
*
|
|
724
|
-
*
|
|
726
|
+
* Block-scoped counterpart of `fetchRecommendationProducts`, which only serves the selected block:
|
|
727
|
+
* the legacy conversion and the duplicate refresh must reach a block that may no longer be selected.
|
|
728
|
+
* @returns whether real products arrived
|
|
725
729
|
*/
|
|
726
|
-
async fetchStrategyProductsForBlock(t) {
|
|
727
|
-
var
|
|
728
|
-
(
|
|
730
|
+
async fetchStrategyProductsForBlock(t, e = {}) {
|
|
731
|
+
var r;
|
|
732
|
+
return (r = this.blockStates[t]) != null && r.recommendationConfigs.strategyId ? this._doFetchStrategyProducts(t, e) : !1;
|
|
729
733
|
},
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
734
|
+
/**
|
|
735
|
+
* Reloads a block's products and adopts its strategy's current size, which may have
|
|
736
|
+
* moved since the block was assigned.
|
|
737
|
+
* @returns whether a fresh listing holds the strategy and its products arrived
|
|
738
|
+
*/
|
|
739
|
+
async refreshStrategyBlock(t) {
|
|
740
|
+
var s;
|
|
741
|
+
const e = (s = this.blockStates[t]) == null ? void 0 : s.recommendationConfigs.strategyId;
|
|
742
|
+
if (!e)
|
|
743
|
+
return !1;
|
|
744
|
+
try {
|
|
745
|
+
await this.fetchStrategies();
|
|
746
|
+
} catch {
|
|
747
|
+
return !1;
|
|
748
|
+
}
|
|
749
|
+
const r = this.strategiesFetched ? this.strategies.find((i) => String(i.strategy_id) === e) : void 0;
|
|
750
|
+
if (!r || !await this.fetchStrategyProductsForBlock(t, { keepOnFailure: !0 }))
|
|
751
|
+
return !1;
|
|
752
|
+
const n = this.blockStates[t];
|
|
753
|
+
return (n == null ? void 0 : n.recommendationConfigs.strategyId) !== e ? !1 : (r.size !== void 0 && (n.recommendationConfigs = {
|
|
754
|
+
...n.recommendationConfigs,
|
|
755
|
+
size: String(r.size)
|
|
756
|
+
}), !0);
|
|
757
|
+
},
|
|
758
|
+
_doFetchStrategyProducts(t, e = {}) {
|
|
759
|
+
const r = (m.get(t) ?? 0) + 1;
|
|
760
|
+
m.set(t, r);
|
|
761
|
+
const n = this._loadStrategyProducts(t, r, e);
|
|
762
|
+
return D.set(t, { token: r, outcome: n }), n;
|
|
763
|
+
},
|
|
764
|
+
async _loadStrategyProducts(t, e, { keepOnFailure: r = !1 }) {
|
|
765
|
+
const { recommendationConfigs: n } = this.blockStates[t];
|
|
766
|
+
let s = [], i = parseInt(n.size) || 6;
|
|
735
767
|
try {
|
|
736
768
|
await this.fetchStrategies();
|
|
737
|
-
const
|
|
738
|
-
(
|
|
769
|
+
const o = this.strategies.find(
|
|
770
|
+
(a) => String(a.strategy_id) === n.strategyId
|
|
739
771
|
);
|
|
740
|
-
if (
|
|
741
|
-
|
|
742
|
-
const
|
|
743
|
-
|
|
772
|
+
if (o) {
|
|
773
|
+
i = parseInt(String(o.size ?? "")) || i;
|
|
774
|
+
const a = n.currencySettings.value, c = (await this.resolveStrategyUrlTemplate(o, a)).replaceAll("{locale}", n.language).replaceAll("{currency}", a), d = c.indexOf("?"), h = d === -1 ? c : c.slice(0, d), g = (d === -1 ? "" : c.slice(d + 1)).split("&").filter((F) => F && !F.startsWith("user_id=")), v = g.length ? `${h}?${g.join("&")}` : h;
|
|
775
|
+
v && (s = await u.fetchRecommendationProductsByUrl(v));
|
|
744
776
|
}
|
|
745
777
|
} catch {
|
|
746
|
-
|
|
778
|
+
s = [];
|
|
747
779
|
}
|
|
748
|
-
|
|
780
|
+
return m.get(t) !== e ? X(t) : !s.length && r ? !1 : (this._setBlockProducts(t, s, i), s.length > 0);
|
|
749
781
|
},
|
|
750
782
|
_setBlockProducts(t, e, r) {
|
|
751
783
|
if (!this.blockStates[t])
|
|
752
784
|
return;
|
|
753
|
-
const n = e.length > 0 ? e :
|
|
785
|
+
const n = e.length > 0 ? e : P(r);
|
|
754
786
|
this.blockStates[t].recommendationProducts = [
|
|
755
787
|
...n.slice(0, r),
|
|
756
|
-
...
|
|
788
|
+
...P(Math.max(0, r - n.length))
|
|
757
789
|
];
|
|
758
790
|
}
|
|
759
791
|
}
|
|
760
792
|
});
|
|
761
793
|
export {
|
|
762
|
-
|
|
794
|
+
St as useRecommendationExtensionStore
|
|
763
795
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RRS_CONFIG_VERSION as d, DEFAULT_CURRENCY as t, DEFAULT_NODE_CONFIG as e } from "../constants/defaultConfig.js";
|
|
2
|
+
import { mapLegacyStrategy as n } from "./legacyStrategyMap.js";
|
|
3
|
+
function S(r) {
|
|
4
|
+
var a, u, c, s, l, o;
|
|
5
|
+
const y = !!r.strategyId || (r.configVersion ?? 0) >= d;
|
|
6
|
+
return {
|
|
7
|
+
strategy: n(r.strategy) || (y ? "" : e.strategy),
|
|
8
|
+
strategyId: r.strategyId ?? e.strategyId,
|
|
9
|
+
language: r.language ?? e.language,
|
|
10
|
+
size: r.size ?? e.size,
|
|
11
|
+
// Copied: the source can be a live node config or the shared defaults.
|
|
12
|
+
productIds: [...r.productIds ?? e.productIds],
|
|
13
|
+
filters: structuredClone(r.filters ?? e.filters),
|
|
14
|
+
shuffleProducts: r.shuffleProducts ?? e.shuffleProducts,
|
|
15
|
+
currencyCode: ((a = r.currency) == null ? void 0 : a.code) ?? t.code,
|
|
16
|
+
currencySymbol: ((u = r.currency) == null ? void 0 : u.symbol) ?? t.symbol,
|
|
17
|
+
currencyAlignment: ((c = r.currency) == null ? void 0 : c.alignment) ?? t.alignment,
|
|
18
|
+
currencyDecimalCount: ((s = r.currency) == null ? void 0 : s.decimalCount) ?? t.decimalCount,
|
|
19
|
+
currencyDecimalSeparator: ((l = r.currency) == null ? void 0 : l.decimalSeparator) ?? t.decimalSeparator,
|
|
20
|
+
currencyThousandSeparator: ((o = r.currency) == null ? void 0 : o.thousandSeparator) ?? t.thousandSeparator
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
S as toBlockUrlConfig
|
|
25
|
+
};
|