@useinsider/guido 3.2.0-beta.caa22bf → 3.2.0-beta.ccaf9f5
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 +0 -92
- package/dist/@types/config/schemas.js +94 -150
- package/dist/components/Guido.vue.js +1 -1
- package/dist/components/Guido.vue2.js +75 -75
- package/dist/composables/useCortexBlueprintBridge.js +38 -0
- package/dist/composables/useEmailTemplateApplier.js +41 -0
- package/dist/composables/useRecommendation.js +26 -46
- package/dist/composables/useSave.js +18 -21
- package/dist/composables/useStripo.js +16 -14
- package/dist/config/compiler/recommendationCompilerRules.js +27 -27
- package/dist/config/migrator/index.js +9 -9
- package/dist/config/migrator/radioButtonMigrator.js +44 -64
- package/dist/config/migrator/recommendationMigrator.js +290 -74
- package/dist/enums/displayConditions.js +80 -0
- package/dist/enums/extensions/recommendationBlock.js +1 -2
- package/dist/extensions/Blocks/RadioButton/template.js +1 -1
- package/dist/extensions/Blocks/Recommendation/block.js +32 -35
- package/dist/extensions/Blocks/Recommendation/constants/defaultConfig.js +5 -5
- package/dist/extensions/Blocks/Recommendation/controls/main/algorithm.js +24 -25
- package/dist/extensions/Blocks/Recommendation/controls/main/utils.js +181 -228
- package/dist/extensions/Blocks/Recommendation/services/configService.js +29 -65
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +90 -130
- package/dist/extensions/Blocks/Recommendation/templates/grid/migration.js +251 -0
- package/dist/extensions/Blocks/Recommendation/templates/grid/template.js +8 -8
- package/dist/extensions/Blocks/Recommendation/templates/utils.js +1 -1
- package/dist/extensions/Blocks/Recommendation/utils/preserveTextStyles.js +22 -13
- package/dist/guido.css +1 -1
- package/dist/node_modules/valibot/dist/index.js +235 -450
- package/dist/src/@types/config/defaults.d.ts +1 -5
- package/dist/src/@types/config/index.d.ts +3 -3
- package/dist/src/@types/config/schemas.d.ts +0 -213
- package/dist/src/@types/config/types.d.ts +1 -9
- package/dist/src/components/wrappers/WpModal.vue.d.ts +1 -1
- package/dist/src/composables/useConfig.d.ts +0 -56
- package/dist/src/composables/useCortexBlueprintBridge.d.ts +17 -0
- package/dist/src/composables/useEmailTemplateApplier.d.ts +21 -0
- package/dist/src/composables/useRecommendation.d.ts +1 -10
- package/dist/src/config/migrator/index.d.ts +1 -2
- package/dist/src/config/migrator/recommendationMigrator.d.ts +1 -13
- package/dist/src/enums/displayConditions.d.ts +2 -0
- package/dist/src/extensions/Blocks/RadioButton/template.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/services/configService.d.ts +0 -10
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +0 -34
- package/dist/src/extensions/Blocks/Recommendation/types/nodeConfig.d.ts +1 -1
- package/dist/src/extensions/Blocks/Recommendation/utils/preserveTextStyles.d.ts +3 -0
- package/dist/src/library.d.ts +1 -1
- package/dist/src/stores/config.d.ts +0 -504
- package/dist/utils/templatePreparation.js +32 -72
- package/package.json +1 -5
- package/dist/composables/validators/useCouponBlockValidator.js +0 -24
- package/dist/config/migrator/recommendation/compositionMapper.js +0 -98
- package/dist/config/migrator/recommendation/extractors.js +0 -27
- package/dist/config/migrator/recommendation/htmlBuilder.js +0 -496
- package/dist/config/migrator/recommendation/parseLegacyConfig.js +0 -33
- package/dist/config/migrator/recommendation/settingsMapper.js +0 -70
- package/dist/config/migrator/recommendation/themeMapper.js +0 -93
- package/dist/extensions/Blocks/Recommendation/utils/legacyStrategyMap.js +0 -21
- package/dist/src/composables/useRecommendation.test.d.ts +0 -1
- package/dist/src/composables/validators/useCouponBlockValidator.d.ts +0 -3
- package/dist/src/config/migrator/recommendation/compositionMapper.d.ts +0 -2
- package/dist/src/config/migrator/recommendation/compositionMapper.test.d.ts +0 -1
- package/dist/src/config/migrator/recommendation/extractors.d.ts +0 -7
- package/dist/src/config/migrator/recommendation/extractors.test.d.ts +0 -1
- package/dist/src/config/migrator/recommendation/htmlBuilder.d.ts +0 -11
- package/dist/src/config/migrator/recommendation/parseLegacyConfig.d.ts +0 -15
- package/dist/src/config/migrator/recommendation/parseLegacyConfig.test.d.ts +0 -1
- package/dist/src/config/migrator/recommendation/settingsMapper.d.ts +0 -7
- package/dist/src/config/migrator/recommendation/settingsMapper.test.d.ts +0 -1
- package/dist/src/config/migrator/recommendation/themeMapper.d.ts +0 -5
- package/dist/src/config/migrator/recommendation/themeMapper.test.d.ts +0 -1
- package/dist/src/config/migrator/recommendation/types.d.ts +0 -205
- package/dist/src/config/migrator/recommendationMigrator.test.d.ts +0 -1
- package/dist/src/extensions/Blocks/Recommendation/controls/main/utils.test.d.ts +0 -1
- package/dist/src/extensions/Blocks/Recommendation/services/configService.test.d.ts +0 -1
- package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMap.d.ts +0 -21
- package/dist/src/extensions/Blocks/Recommendation/utils/legacyStrategyMap.test.d.ts +0 -1
- package/dist/src/utils/htmlEscape.d.ts +0 -5
- package/dist/src/utils/htmlEscape.test.d.ts +0 -1
- package/dist/utils/htmlEscape.js +0 -13
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { ModificationDescription as
|
|
2
|
-
import { CURRENT_CONFIG_VERSION as
|
|
3
|
-
import { setCurrencyAttributes as
|
|
4
|
-
import { hasMinimalConfig as
|
|
5
|
-
|
|
6
|
-
return e === "." || e === "," || e === " ";
|
|
7
|
-
}
|
|
8
|
-
function N(e) {
|
|
9
|
-
return e === "." || e === "," || e === " " || e === "";
|
|
10
|
-
}
|
|
11
|
-
class V {
|
|
1
|
+
import { ModificationDescription as f } from "../../../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
2
|
+
import { CURRENT_CONFIG_VERSION as u, DEFAULT_NODE_CONFIG as e } from "../constants/defaultConfig.js";
|
|
3
|
+
import { setCurrencyAttributes as g } from "../controls/main/utils.js";
|
|
4
|
+
import { hasMinimalConfig as a } from "../types/nodeConfig.js";
|
|
5
|
+
class C {
|
|
12
6
|
// ========================================================================
|
|
13
7
|
// Read Operations
|
|
14
8
|
// ========================================================================
|
|
@@ -48,7 +42,7 @@ class V {
|
|
|
48
42
|
return !1;
|
|
49
43
|
try {
|
|
50
44
|
const t = i.getNodeConfig();
|
|
51
|
-
return
|
|
45
|
+
return a(t);
|
|
52
46
|
} catch {
|
|
53
47
|
return !1;
|
|
54
48
|
}
|
|
@@ -83,8 +77,8 @@ class V {
|
|
|
83
77
|
* @returns The new complete configuration
|
|
84
78
|
*/
|
|
85
79
|
static updateConfig(i, t, o, n) {
|
|
86
|
-
const
|
|
87
|
-
return this.saveConfig(i, t,
|
|
80
|
+
const s = this.getConfig(t), r = this.deepMerge(s, o);
|
|
81
|
+
return this.saveConfig(i, t, r, n), r;
|
|
88
82
|
}
|
|
89
83
|
/**
|
|
90
84
|
* Initialize configuration for a new block
|
|
@@ -101,7 +95,7 @@ class V {
|
|
|
101
95
|
*/
|
|
102
96
|
static initializeConfig(i, t, o) {
|
|
103
97
|
const n = o ? this.mergeWithDefaults(o) : this.cloneDefaults();
|
|
104
|
-
return this.saveConfig(i, t, n, "Initialize recommendation block"),
|
|
98
|
+
return this.saveConfig(i, t, n, "Initialize recommendation block"), g({
|
|
105
99
|
currentNode: t,
|
|
106
100
|
documentModifier: i.getDocumentModifier(),
|
|
107
101
|
currency: n.currency
|
|
@@ -118,9 +112,9 @@ class V {
|
|
|
118
112
|
*/
|
|
119
113
|
static saveConfig(i, t, o, n) {
|
|
120
114
|
try {
|
|
121
|
-
i.getDocumentModifier().modifyHtml(t).setNodeConfig(o).apply(new
|
|
122
|
-
} catch (
|
|
123
|
-
console.warn("[RecommendationConfigService] Failed to save config:",
|
|
115
|
+
i.getDocumentModifier().modifyHtml(t).setNodeConfig(o).apply(new f(n));
|
|
116
|
+
} catch (s) {
|
|
117
|
+
console.warn("[RecommendationConfigService] Failed to save config:", s);
|
|
124
118
|
}
|
|
125
119
|
}
|
|
126
120
|
// ========================================================================
|
|
@@ -131,53 +125,23 @@ class V {
|
|
|
131
125
|
*
|
|
132
126
|
* Reads existing data-attributes and creates a proper node config.
|
|
133
127
|
* Used when loading templates created before node config was implemented.
|
|
134
|
-
*
|
|
135
|
-
* Sources, in priority order (later overrides earlier):
|
|
136
|
-
* 1. `esd-ext-config` JSON blob — emitted by the recommendation migrator and
|
|
137
|
-
* by hand-authored new templates. Carries the full RecommendationNodeConfig
|
|
138
|
-
* (strategy, language, currency, filters, productIds, etc.) which the
|
|
139
|
-
* discrete data-* attrs below cannot capture.
|
|
140
|
-
* 2. Discrete `data-*` attributes — runtime source of truth for
|
|
141
|
-
* layout/composition/spacing; controls keep these in sync as the user
|
|
142
|
-
* edits, so we let them override the JSON blob if they disagree.
|
|
143
|
-
* 3. `currency-*` attributes — durable currency source on the block element.
|
|
144
128
|
* @param api - Stripo extension API with document modifier
|
|
145
129
|
* @param node - The block node to migrate
|
|
146
130
|
* @returns The migrated configuration
|
|
147
131
|
*/
|
|
148
132
|
static migrateFromDataAttributes(i, t) {
|
|
149
133
|
const o = {
|
|
150
|
-
configVersion:
|
|
134
|
+
configVersion: u
|
|
151
135
|
};
|
|
152
136
|
if ("getAttribute" in t && typeof t.getAttribute == "function") {
|
|
153
|
-
const n = t.getAttribute("
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
c === "list" || c === "horizontal" ? o.layout = "list" : (c === "grid" || c === "vertical") && (o.layout = "grid");
|
|
162
|
-
const u = t.getAttribute("data-card-composition");
|
|
163
|
-
u && (o.composition = u.split(",").filter(Boolean));
|
|
164
|
-
const p = t.getAttribute("data-column-spacing");
|
|
165
|
-
p && (o.columnSpacing = parseInt(p) || r.columnSpacing);
|
|
166
|
-
const b = t.getAttribute("data-row-spacing");
|
|
167
|
-
if (b && (o.rowSpacing = parseInt(b) || r.rowSpacing), !o.currency) {
|
|
168
|
-
const s = t.getAttribute("currency"), y = t.getAttribute("currency-symbol"), d = t.getAttribute("currency-alignment"), f = t.getAttribute("currency-thousand-separator"), g = t.getAttribute("currency-decimal-separator"), m = t.getAttribute("currency-decimal-count");
|
|
169
|
-
if (s || y || d || f || g || m) {
|
|
170
|
-
const a = r.currency, C = m ? parseInt(m) : NaN;
|
|
171
|
-
o.currency = {
|
|
172
|
-
code: s ?? a.code,
|
|
173
|
-
symbol: y ?? a.symbol,
|
|
174
|
-
alignment: d === "0" ? "before" : "after",
|
|
175
|
-
decimalCount: Number.isFinite(C) ? C : a.decimalCount,
|
|
176
|
-
decimalSeparator: S(g) ? g : a.decimalSeparator,
|
|
177
|
-
thousandSeparator: N(f) ? f : a.thousandSeparator
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
137
|
+
const n = t.getAttribute("data-layout");
|
|
138
|
+
n === "list" || n === "horizontal" ? o.layout = "list" : (n === "grid" || n === "vertical") && (o.layout = "grid");
|
|
139
|
+
const s = t.getAttribute("data-card-composition");
|
|
140
|
+
s && (o.composition = s.split(",").filter(Boolean));
|
|
141
|
+
const r = t.getAttribute("data-column-spacing");
|
|
142
|
+
r && (o.columnSpacing = parseInt(r) || e.columnSpacing);
|
|
143
|
+
const c = t.getAttribute("data-row-spacing");
|
|
144
|
+
c && (o.rowSpacing = parseInt(c) || e.rowSpacing);
|
|
181
145
|
}
|
|
182
146
|
return this.initializeConfig(i, t, o);
|
|
183
147
|
}
|
|
@@ -187,7 +151,7 @@ class V {
|
|
|
187
151
|
* @returns True if migration is needed
|
|
188
152
|
*/
|
|
189
153
|
static needsMigration(i) {
|
|
190
|
-
return i ? this.hasConfig(i) ? this.getConfigVersion(i) <
|
|
154
|
+
return i ? this.hasConfig(i) ? this.getConfigVersion(i) < u : !0 : !1;
|
|
191
155
|
}
|
|
192
156
|
// ========================================================================
|
|
193
157
|
// Internal Helpers
|
|
@@ -197,12 +161,12 @@ class V {
|
|
|
197
161
|
*/
|
|
198
162
|
static cloneDefaults() {
|
|
199
163
|
return {
|
|
200
|
-
...
|
|
201
|
-
currency: { ...
|
|
202
|
-
omnibusPrice: { ...
|
|
203
|
-
omnibusDiscount: { ...
|
|
204
|
-
composition: [...
|
|
205
|
-
visibility: { ...
|
|
164
|
+
...e,
|
|
165
|
+
currency: { ...e.currency },
|
|
166
|
+
omnibusPrice: { ...e.omnibusPrice },
|
|
167
|
+
omnibusDiscount: { ...e.omnibusDiscount },
|
|
168
|
+
composition: [...e.composition],
|
|
169
|
+
visibility: { ...e.visibility },
|
|
206
170
|
filters: [],
|
|
207
171
|
productIds: [],
|
|
208
172
|
recommendationId: 0
|
|
@@ -272,5 +236,5 @@ class V {
|
|
|
272
236
|
}
|
|
273
237
|
}
|
|
274
238
|
export {
|
|
275
|
-
|
|
239
|
+
C as RecommendationConfigService
|
|
276
240
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { RecommendationFeedSourceMaps as
|
|
1
|
+
import { RecommendationFeedSourceMaps as g, getOperatorOptions as R, PriceAttributes as k } from "../../../../enums/extensions/recommendationBlock.js";
|
|
2
2
|
import { useRecommendationApi as C } from "../../../../services/recommendationApi.js";
|
|
3
|
-
import { useConfigStore as
|
|
4
|
-
import { defineStore as
|
|
3
|
+
import { useConfigStore as y } from "../../../../stores/config.js";
|
|
4
|
+
import { defineStore as G } from "pinia";
|
|
5
5
|
import { DEFAULT_CARDS_IN_ROW as F } from "../constants/layout.js";
|
|
6
|
-
import { EXCLUDED_ALGORITHM_IDS as
|
|
7
|
-
import { getDefaultProducts as
|
|
6
|
+
import { EXCLUDED_ALGORITHM_IDS as w } from "../constants/defaultConfig.js";
|
|
7
|
+
import { getDefaultProducts as S } from "../templates/utils.js";
|
|
8
8
|
import { generateCompleteFilterQuery as b } from "../utils/filterUtil.js";
|
|
9
|
-
import { isFilterValid as
|
|
9
|
+
import { isFilterValid as D } from "../validation/filterSchema.js";
|
|
10
10
|
const h = C();
|
|
11
|
-
let
|
|
12
|
-
function
|
|
11
|
+
let m = null, u = null, d = null;
|
|
12
|
+
function I() {
|
|
13
13
|
return {
|
|
14
14
|
cardsInRow: F,
|
|
15
15
|
currencySettings: {
|
|
@@ -37,9 +37,9 @@ function k() {
|
|
|
37
37
|
customAttributes: []
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function P() {
|
|
41
41
|
return {
|
|
42
|
-
recommendationConfigs:
|
|
42
|
+
recommendationConfigs: I(),
|
|
43
43
|
recommendationProducts: [],
|
|
44
44
|
filterStatus: !1,
|
|
45
45
|
filterSelectionDrawerStatus: !1,
|
|
@@ -57,7 +57,7 @@ const v = () => ({
|
|
|
57
57
|
blockStates: {},
|
|
58
58
|
currentRecommendationId: null,
|
|
59
59
|
configVersion: 0
|
|
60
|
-
}),
|
|
60
|
+
}), z = G("guidoRecommendationExtension", {
|
|
61
61
|
state: () => v(),
|
|
62
62
|
getters: {
|
|
63
63
|
// ====================================================================
|
|
@@ -68,7 +68,7 @@ const v = () => ({
|
|
|
68
68
|
* This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
|
|
69
69
|
*/
|
|
70
70
|
recommendationConfigs(t) {
|
|
71
|
-
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs :
|
|
71
|
+
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : I();
|
|
72
72
|
},
|
|
73
73
|
/**
|
|
74
74
|
* Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
|
|
@@ -102,45 +102,45 @@ const v = () => ({
|
|
|
102
102
|
},
|
|
103
103
|
hasValidFilters() {
|
|
104
104
|
const { filters: t } = this.recommendationConfigs;
|
|
105
|
-
return t.length ? t.every((
|
|
105
|
+
return t.length ? t.every((r) => r.isValid) : !1;
|
|
106
106
|
},
|
|
107
107
|
getFilterGroupCount() {
|
|
108
108
|
const { filters: t } = this.recommendationConfigs;
|
|
109
|
-
return t.length ? new Set(t.map((
|
|
109
|
+
return t.length ? new Set(t.map((r) => r.filterGroup)).size : 0;
|
|
110
110
|
},
|
|
111
111
|
getUniqueFilterGroups() {
|
|
112
112
|
const { filters: t } = this.recommendationConfigs;
|
|
113
|
-
return [...new Set(t.map((
|
|
113
|
+
return [...new Set(t.map((r) => r.filterGroup))].sort((r, e) => r - e);
|
|
114
114
|
},
|
|
115
115
|
getActivePredictiveAlgorithms: (t) => {
|
|
116
|
-
const
|
|
117
|
-
return t.activePredictiveAlgorithms.filter((
|
|
118
|
-
|
|
119
|
-
}),
|
|
120
|
-
text:
|
|
121
|
-
value:
|
|
116
|
+
const r = [];
|
|
117
|
+
return t.activePredictiveAlgorithms.filter((e) => !w.includes(e)).forEach((e) => {
|
|
118
|
+
r.push(...g.filter((n) => n.id === e));
|
|
119
|
+
}), r.map((e) => ({
|
|
120
|
+
text: e.name,
|
|
121
|
+
value: e.key
|
|
122
122
|
}));
|
|
123
123
|
},
|
|
124
|
-
getLanguages: (t) => Object.entries(t.languages).map(([
|
|
125
|
-
text:
|
|
126
|
-
value:
|
|
124
|
+
getLanguages: (t) => Object.entries(t.languages).map(([r, e]) => ({
|
|
125
|
+
text: e,
|
|
126
|
+
value: r
|
|
127
127
|
})),
|
|
128
|
-
getCurrencySymbolList: (t) => t.currencyList.map((
|
|
129
|
-
text:
|
|
130
|
-
value:
|
|
128
|
+
getCurrencySymbolList: (t) => t.currencyList.map((r) => ({
|
|
129
|
+
text: r.text,
|
|
130
|
+
value: r.text
|
|
131
131
|
})),
|
|
132
132
|
getFilterList() {
|
|
133
133
|
return Object.values(this.filterList).map((t) => {
|
|
134
|
-
let
|
|
135
|
-
return t.type === "productAttribute" ?
|
|
134
|
+
let r;
|
|
135
|
+
return t.type === "productAttribute" ? r = `product_attributes.${t.attributeName}` : k.includes(t.attributeName) ? r = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : r = t.attributeName, {
|
|
136
136
|
text: t.displayName,
|
|
137
|
-
value:
|
|
137
|
+
value: r,
|
|
138
138
|
type: t.attributeType
|
|
139
139
|
};
|
|
140
140
|
});
|
|
141
141
|
},
|
|
142
142
|
getSelectedFilterGroup() {
|
|
143
|
-
return (t) => [...this.recommendationConfigs.filters].filter((
|
|
143
|
+
return (t) => [...this.recommendationConfigs.filters].filter((r) => r.filterGroup === t);
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
146
|
actions: {
|
|
@@ -154,7 +154,7 @@ const v = () => ({
|
|
|
154
154
|
setCurrentBlock(t) {
|
|
155
155
|
this.blockStates[t] || (this.blockStates = {
|
|
156
156
|
...this.blockStates,
|
|
157
|
-
[t]:
|
|
157
|
+
[t]: P()
|
|
158
158
|
}), this.currentRecommendationId = t;
|
|
159
159
|
},
|
|
160
160
|
/**
|
|
@@ -162,13 +162,13 @@ const v = () => ({
|
|
|
162
162
|
* Resets currentRecommendationId if it was the deleted block.
|
|
163
163
|
*/
|
|
164
164
|
removeBlockState(t) {
|
|
165
|
-
const
|
|
166
|
-
if (this.recommendationCampaignUrls[
|
|
165
|
+
const r = t.toString();
|
|
166
|
+
if (this.recommendationCampaignUrls[r]) {
|
|
167
167
|
const n = { ...this.recommendationCampaignUrls };
|
|
168
|
-
delete n[
|
|
168
|
+
delete n[r], this.recommendationCampaignUrls = n;
|
|
169
169
|
}
|
|
170
|
-
const
|
|
171
|
-
if (delete
|
|
170
|
+
const e = { ...this.blockStates };
|
|
171
|
+
if (delete e[t], this.blockStates = e, this.currentRecommendationId === t) {
|
|
172
172
|
const n = Object.keys(this.blockStates).map(Number);
|
|
173
173
|
this.currentRecommendationId = n.length > 0 ? n[0] : null;
|
|
174
174
|
}
|
|
@@ -180,75 +180,37 @@ const v = () => ({
|
|
|
180
180
|
markBlockInitialized(t) {
|
|
181
181
|
this.blockStates[t] && (this.blockStates[t].isInitialized = !0);
|
|
182
182
|
},
|
|
183
|
-
/**
|
|
184
|
-
* Seeds the URL-relevant fields of a block from a persisted node config.
|
|
185
|
-
*
|
|
186
|
-
* Used at save-time to ensure the campaign URL is built from the
|
|
187
|
-
* persisted truth (the `esd-ext-config` blob in the raw HTML) even when
|
|
188
|
-
* the user never selected the block in this editor session — without
|
|
189
|
-
* this seed, `_syncNodeConfigToStore` would never have run for that
|
|
190
|
-
* block and the store would hold default values (USD/en_US/mostPopular)
|
|
191
|
-
* instead of the real config.
|
|
192
|
-
*
|
|
193
|
-
* Creates the block entry if missing; otherwise patches only the URL-
|
|
194
|
-
* relevant subset and leaves runtime fields (e.g., `recommendedProducts`,
|
|
195
|
-
* `isInitialized`) alone.
|
|
196
|
-
*/
|
|
197
|
-
seedBlockUrlConfig(t, e) {
|
|
198
|
-
const r = (o, s) => o === "." || o === "," || o === " " ? o : s, n = {
|
|
199
|
-
name: e.currencyCode,
|
|
200
|
-
value: e.currencyCode,
|
|
201
|
-
symbol: e.currencyCode,
|
|
202
|
-
alignment: e.currencyAlignment === "before" ? "0" : "1",
|
|
203
|
-
decimalCount: String(e.currencyDecimalCount),
|
|
204
|
-
decimalSeparator: r(e.currencyDecimalSeparator, ","),
|
|
205
|
-
thousandSeparator: r(e.currencyThousandSeparator, ".")
|
|
206
|
-
}, c = !this.blockStates[t], i = c ? I() : this.blockStates[t];
|
|
207
|
-
i.recommendationConfigs = {
|
|
208
|
-
...i.recommendationConfigs,
|
|
209
|
-
strategy: e.strategy,
|
|
210
|
-
language: e.language,
|
|
211
|
-
size: e.size,
|
|
212
|
-
productIds: e.productIds,
|
|
213
|
-
filters: e.filters,
|
|
214
|
-
shuffleProducts: e.shuffleProducts,
|
|
215
|
-
currencySettings: n
|
|
216
|
-
}, c && (this.blockStates = {
|
|
217
|
-
...this.blockStates,
|
|
218
|
-
[t]: i
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
183
|
/**
|
|
222
184
|
* Patches the current block's recommendationConfigs.
|
|
223
185
|
* Replaces `store.$patch({ recommendationConfigs: { ... } })` pattern.
|
|
224
186
|
*/
|
|
225
|
-
patchCurrentBlockConfig(t,
|
|
187
|
+
patchCurrentBlockConfig(t, r = {}) {
|
|
226
188
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
227
189
|
return;
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
...
|
|
190
|
+
const e = this.blockStates[this.currentRecommendationId];
|
|
191
|
+
e.recommendationConfigs = {
|
|
192
|
+
...e.recommendationConfigs,
|
|
231
193
|
...t,
|
|
232
194
|
currencySettings: {
|
|
233
|
-
...
|
|
195
|
+
...e.recommendationConfigs.currencySettings,
|
|
234
196
|
...t.currencySettings || {}
|
|
235
197
|
}
|
|
236
198
|
};
|
|
237
|
-
const { triggerRefetch: n = !0 } =
|
|
199
|
+
const { triggerRefetch: n = !0 } = r;
|
|
238
200
|
n && this.configVersion++;
|
|
239
201
|
},
|
|
240
202
|
/**
|
|
241
203
|
* Creates a filter with the first available attribute and operator pre-selected.
|
|
242
204
|
*/
|
|
243
|
-
createDefaultFilter(t,
|
|
244
|
-
const [
|
|
205
|
+
createDefaultFilter(t, r) {
|
|
206
|
+
const [e] = this.getFilterList, [n] = R(e == null ? void 0 : e.type);
|
|
245
207
|
return {
|
|
246
208
|
type: "standardFilter",
|
|
247
|
-
attribute: (
|
|
209
|
+
attribute: (e == null ? void 0 : e.value) ?? "",
|
|
248
210
|
operator: (n == null ? void 0 : n.value) ?? "",
|
|
249
211
|
innerGroupOperator: "*",
|
|
250
212
|
outerGroupOperator: "*",
|
|
251
|
-
filterNumber:
|
|
213
|
+
filterNumber: r,
|
|
252
214
|
filterGroup: t,
|
|
253
215
|
isValid: !1,
|
|
254
216
|
value: ""
|
|
@@ -293,43 +255,43 @@ const v = () => ({
|
|
|
293
255
|
// ====================================================================
|
|
294
256
|
async fetchRecommendationCreateData() {
|
|
295
257
|
if (!this.activePredictiveAlgorithms.length) {
|
|
296
|
-
if (
|
|
297
|
-
await
|
|
258
|
+
if (m) {
|
|
259
|
+
await m;
|
|
298
260
|
return;
|
|
299
261
|
}
|
|
300
|
-
|
|
262
|
+
m = (async () => {
|
|
301
263
|
const {
|
|
302
264
|
activePredictiveAlgorithms: t,
|
|
303
|
-
languages:
|
|
304
|
-
currencies:
|
|
265
|
+
languages: r,
|
|
266
|
+
currencies: e
|
|
305
267
|
} = await h.fetchRecommendationCreateData();
|
|
306
|
-
if (this.activePredictiveAlgorithms = t, this.languages =
|
|
268
|
+
if (this.activePredictiveAlgorithms = t, this.languages = r, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
|
|
307
269
|
const n = this.blockStates[this.currentRecommendationId];
|
|
308
270
|
n.filterStatus = !!n.recommendationConfigs.filters.length;
|
|
309
271
|
}
|
|
310
|
-
this.currencyList =
|
|
272
|
+
this.currencyList = e;
|
|
311
273
|
})();
|
|
312
274
|
try {
|
|
313
|
-
await
|
|
275
|
+
await m;
|
|
314
276
|
} finally {
|
|
315
|
-
|
|
277
|
+
m = null;
|
|
316
278
|
}
|
|
317
279
|
}
|
|
318
280
|
},
|
|
319
281
|
async fetchRecommendationFilters() {
|
|
320
282
|
if (!Object.keys(this.filterList).length) {
|
|
321
|
-
if (
|
|
322
|
-
await
|
|
283
|
+
if (u) {
|
|
284
|
+
await u;
|
|
323
285
|
return;
|
|
324
286
|
}
|
|
325
|
-
|
|
287
|
+
u = (async () => {
|
|
326
288
|
const t = await h.fetchRecommendationFilters();
|
|
327
289
|
this.filterList = t;
|
|
328
290
|
})();
|
|
329
291
|
try {
|
|
330
|
-
await
|
|
292
|
+
await u;
|
|
331
293
|
} finally {
|
|
332
|
-
|
|
294
|
+
u = null;
|
|
333
295
|
}
|
|
334
296
|
}
|
|
335
297
|
},
|
|
@@ -344,8 +306,8 @@ const v = () => ({
|
|
|
344
306
|
deleteFilterGroup(t) {
|
|
345
307
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
346
308
|
return;
|
|
347
|
-
const
|
|
348
|
-
|
|
309
|
+
const r = this.blockStates[this.currentRecommendationId], e = r.recommendationConfigs.filters.filter((i) => i.filterGroup !== t), n = [...new Set(e.map((i) => i.filterGroup))].sort((i, o) => i - o), c = new Map(n.map((i, o) => [i, o + 1]));
|
|
310
|
+
r.recommendationConfigs.filters = e.map((i) => ({
|
|
349
311
|
...i,
|
|
350
312
|
filterGroup: c.get(i.filterGroup) ?? i.filterGroup
|
|
351
313
|
}));
|
|
@@ -353,47 +315,47 @@ const v = () => ({
|
|
|
353
315
|
updateFilter(t) {
|
|
354
316
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
355
317
|
return;
|
|
356
|
-
const
|
|
357
|
-
if (
|
|
358
|
-
const n = [...
|
|
359
|
-
n[
|
|
318
|
+
const r = this.blockStates[this.currentRecommendationId], e = r.recommendationConfigs.filters.findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
|
|
319
|
+
if (e !== -1) {
|
|
320
|
+
const n = [...r.recommendationConfigs.filters];
|
|
321
|
+
n[e] = {
|
|
360
322
|
...t,
|
|
361
|
-
isValid:
|
|
362
|
-
},
|
|
323
|
+
isValid: D(t)
|
|
324
|
+
}, r.recommendationConfigs.filters = n;
|
|
363
325
|
}
|
|
364
326
|
},
|
|
365
327
|
deleteFilter(t) {
|
|
366
328
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
367
329
|
return;
|
|
368
|
-
const
|
|
369
|
-
if (
|
|
370
|
-
let n = [...
|
|
371
|
-
if (n.splice(
|
|
330
|
+
const r = this.blockStates[this.currentRecommendationId], e = [...r.recommendationConfigs.filters].findIndex((n) => n.filterNumber === t.filterNumber && n.filterGroup === t.filterGroup);
|
|
331
|
+
if (e !== -1) {
|
|
332
|
+
let n = [...r.recommendationConfigs.filters];
|
|
333
|
+
if (n.splice(e, 1), n.some((i) => i.filterGroup === t.filterGroup)) {
|
|
372
334
|
let i = 1;
|
|
373
335
|
n = n.map((o) => o.filterGroup === t.filterGroup ? { ...o, filterNumber: i++ } : o);
|
|
374
336
|
} else {
|
|
375
|
-
const i = [...new Set(n.map((s) => s.filterGroup))].sort((s,
|
|
337
|
+
const i = [...new Set(n.map((s) => s.filterGroup))].sort((s, l) => s - l), o = new Map(i.map((s, l) => [s, l + 1]));
|
|
376
338
|
n = n.map((s) => ({
|
|
377
339
|
...s,
|
|
378
340
|
filterGroup: o.get(s.filterGroup) ?? s.filterGroup
|
|
379
341
|
}));
|
|
380
342
|
}
|
|
381
|
-
|
|
343
|
+
r.recommendationConfigs.filters = n;
|
|
382
344
|
}
|
|
383
345
|
},
|
|
384
346
|
addFilter(t) {
|
|
385
347
|
if (this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])
|
|
386
348
|
return;
|
|
387
|
-
const
|
|
349
|
+
const r = this.blockStates[this.currentRecommendationId], e = [...r.recommendationConfigs.filters], c = e.filter(
|
|
388
350
|
(o) => o.filterGroup === t.filterGroup
|
|
389
|
-
).length + 1, i =
|
|
390
|
-
i !== -1 ?
|
|
351
|
+
).length + 1, i = e.findLastIndex((o) => o.filterGroup === t.filterGroup);
|
|
352
|
+
i !== -1 ? e.splice(i + 1, 0, {
|
|
391
353
|
...t,
|
|
392
354
|
filterNumber: c
|
|
393
|
-
}) :
|
|
355
|
+
}) : e.push({
|
|
394
356
|
...t,
|
|
395
357
|
filterNumber: c
|
|
396
|
-
}),
|
|
358
|
+
}), r.recommendationConfigs.filters = e;
|
|
397
359
|
},
|
|
398
360
|
generateFilterQuery() {
|
|
399
361
|
return b(this.recommendationConfigs.filters);
|
|
@@ -417,31 +379,29 @@ const v = () => ({
|
|
|
417
379
|
},
|
|
418
380
|
async _doFetchProducts() {
|
|
419
381
|
var p;
|
|
420
|
-
const t = this.currentRecommendationId,
|
|
421
|
-
locale:
|
|
422
|
-
currency:
|
|
382
|
+
const t = this.currentRecommendationId, r = this.blockStates[t], { recommendationConfigs: e } = r, n = e.filters.filter((a) => a.isValid), c = b(n), i = ((p = g.find((a) => a.key === e.strategy)) == null ? void 0 : p.path) || "", o = y(), s = {
|
|
383
|
+
locale: e.language,
|
|
384
|
+
currency: e.currencySettings.value,
|
|
423
385
|
partnerName: o.partnerName,
|
|
424
|
-
size:
|
|
386
|
+
size: e.size,
|
|
425
387
|
details: !0,
|
|
426
388
|
campaignId: o.variationId
|
|
427
389
|
};
|
|
428
|
-
|
|
390
|
+
e.strategy === "manualMerchandising" ? s.productId = e.productIds.join(",") : e.strategy === "similarViewed" && (s.productId = "{itemId}"), e.strategy === "userBased" && (s.userId = "{user_id}"), c && (s.filter = c), e.shuffleProducts && (s.shuffle = !0);
|
|
391
|
+
const l = parseInt(e.size) || 6;
|
|
429
392
|
let f;
|
|
430
393
|
try {
|
|
431
|
-
f = await h.fetchRecommendationProducts(i,
|
|
394
|
+
f = await h.fetchRecommendationProducts(i, s);
|
|
432
395
|
} catch {
|
|
433
396
|
f = [];
|
|
434
397
|
}
|
|
435
398
|
if (this.blockStates[t]) {
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
...l,
|
|
439
|
-
...g(s - l.length)
|
|
440
|
-
] : l.length > s ? this.blockStates[t].recommendationProducts = l.slice(0, s) : this.blockStates[t].recommendationProducts = l;
|
|
399
|
+
const a = f.length > 0 ? f : S(l);
|
|
400
|
+
this.blockStates[t].recommendationProducts = a.length < l ? [...a, ...S(l - a.length)] : a;
|
|
441
401
|
}
|
|
442
402
|
}
|
|
443
403
|
}
|
|
444
404
|
});
|
|
445
405
|
export {
|
|
446
|
-
|
|
406
|
+
z as useRecommendationExtensionStore
|
|
447
407
|
};
|