@useinsider/guido 3.18.1-beta.2b89365 → 3.18.1-beta.2e195ed
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/components/Guido.vue.js +3 -3
- package/dist/components/Guido.vue2.js +30 -30
- package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue.js +13 -11
- package/dist/components/organisms/extensions/recommendation/AssignStrategyDrawer.vue2.js +65 -53
- package/dist/components/organisms/onboarding/OnboardingWrapper.vue2.js +20 -18
- package/dist/components/organisms/onboarding/RecommendationStrategyOnboarding.vue.js +21 -0
- package/dist/components/organisms/onboarding/RecommendationStrategyOnboarding.vue2.js +47 -0
- package/dist/composables/useCustomInterfaceAppearance.js +56 -48
- package/dist/composables/useGuidoStateBridge.js +24 -29
- package/dist/composables/useHtmlValidator.js +84 -79
- package/dist/composables/useRecommendation.js +21 -18
- package/dist/composables/useStripo.js +31 -31
- package/dist/enums/extensions/recommendationBlock.js +38 -31
- package/dist/extensions/Blocks/Recommendation/block.js +43 -39
- package/dist/extensions/Blocks/Recommendation/controls/main/index.js +62 -57
- package/dist/extensions/Blocks/Recommendation/controls/main/strategy.js +84 -52
- package/dist/extensions/Blocks/Recommendation/store/recommendation.js +165 -78
- package/dist/extensions/Blocks/Recommendation/validation/requiredFields.js +21 -12
- package/dist/guido.css +1 -1
- package/dist/library.js +13 -15
- package/dist/src/components/organisms/onboarding/RecommendationStrategyOnboarding.vue.d.ts +2 -0
- package/dist/src/composables/useGuidoStateBridge.d.ts +7 -11
- package/dist/src/enums/extensions/recommendationBlock.d.ts +2 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/index.d.ts +2 -0
- package/dist/src/extensions/Blocks/Recommendation/controls/main/strategy.d.ts +9 -0
- package/dist/src/extensions/Blocks/Recommendation/store/recommendation.d.ts +74 -0
- package/dist/src/extensions/Blocks/Recommendation/validation/requiredFields.d.ts +4 -0
- package/dist/src/library.d.ts +0 -2
- package/dist/src/public/trackingIds.d.ts +2 -6
- package/dist/src/stores/editor.d.ts +0 -25
- package/dist/src/stores/guido-email-editor.d.ts +27 -27
- package/dist/src/stores/onboarding.d.ts +377 -0
- package/dist/static/styles/components/recommendation-strategy.css.js +51 -4
- package/dist/stores/editor.js +0 -4
- package/dist/stores/guido-email-editor.js +4 -0
- package/dist/stores/onboarding.js +41 -36
- package/dist/utils/templatePreparation.js +50 -50
- package/package.json +1 -5
- package/dist/public/editorState.js +0 -4
- package/dist/src/public/editorState.d.ts +0 -14
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { ACADEMY_LINKS as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var S = (o, n, t) => n in o ? u(o, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[n] = t;
|
|
3
|
+
var r = (o, n, t) => S(o, typeof n != "symbol" ? n + "" : n, t);
|
|
4
|
+
import { ACADEMY_LINKS as _ } from "../../../../../enums/academy.js";
|
|
5
|
+
import { useOnboardingStore as f } from "../../../../../stores/onboarding.js";
|
|
6
|
+
import { CommonControl as v } from "../../../common-control.js";
|
|
7
|
+
import { CURRENT_CONFIG_VERSION as b } from "../../constants/defaultConfig.js";
|
|
8
|
+
import { RecommendationConfigService as h } from "../../services/configService.js";
|
|
9
|
+
import { useRecommendationExtensionStore as C } from "../../store/recommendation.js";
|
|
10
|
+
const k = "recommendation-strategy-control";
|
|
11
|
+
class I extends v {
|
|
9
12
|
constructor() {
|
|
10
13
|
super(...arguments);
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
r(this, "store", C());
|
|
15
|
+
r(this, "onboardingStore", f());
|
|
16
|
+
r(this, "storeUnsubscription", () => {
|
|
13
17
|
});
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
r(this, "listeners", []);
|
|
19
|
+
r(this, "lastPaintedState", null);
|
|
16
20
|
}
|
|
17
21
|
getId() {
|
|
18
|
-
return
|
|
22
|
+
return k;
|
|
19
23
|
}
|
|
20
24
|
getTemplate() {
|
|
21
25
|
const t = this.api.translate(
|
|
@@ -23,21 +27,34 @@ class f extends h {
|
|
|
23
27
|
), e = this.api.translate("For more information, you can"), a = this.api.translate("visit Academy");
|
|
24
28
|
return `
|
|
25
29
|
<div class="strategy-control-container">
|
|
26
|
-
<div
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
</p>
|
|
30
|
+
<div data-strategy-loading-state>
|
|
31
|
+
<div class="strategy-control-header">
|
|
32
|
+
<span class="guido-skeleton guido-skeleton--strategy-title"></span>
|
|
33
|
+
</div>
|
|
34
|
+
<div class="strategy-control-description-row">
|
|
35
|
+
<span class="guido-skeleton guido-skeleton--strategy-description"></span>
|
|
36
|
+
</div>
|
|
37
|
+
<div class="strategy-control-skeleton-row">
|
|
38
|
+
<span class="guido-skeleton guido-skeleton--strategy-cta"></span>
|
|
39
|
+
<span class="guido-skeleton guido-skeleton--strategy-cta"></span>
|
|
40
|
+
</div>
|
|
38
41
|
</div>
|
|
39
|
-
<div data-strategy-
|
|
40
|
-
|
|
42
|
+
<div data-strategy-content style="display: none;">
|
|
43
|
+
<div class="strategy-control-header">
|
|
44
|
+
<h3 class="strategy-control-title">${this.api.translate("Recommendation Strategy")}</h3>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="strategy-control-description-row">
|
|
47
|
+
<p class="strategy-control-description">
|
|
48
|
+
${t}
|
|
49
|
+
${e}
|
|
50
|
+
<a
|
|
51
|
+
href="${_.EMAIL_RECOMMENDATION_BLOCK}"
|
|
52
|
+
target="_blank"
|
|
53
|
+
rel="noopener noreferrer">${a}</a>.
|
|
54
|
+
</p>
|
|
55
|
+
</div>
|
|
56
|
+
<div data-strategy-empty-state style="display: none;">
|
|
57
|
+
${this._GuTwoColumns([
|
|
41
58
|
this._GuButton({
|
|
42
59
|
name: "assignStrategy",
|
|
43
60
|
label: this.api.translate("Assign Strategy"),
|
|
@@ -48,26 +65,28 @@ class f extends h {
|
|
|
48
65
|
name: "createStrategy",
|
|
49
66
|
label: this.api.translate("Create New Strategy"),
|
|
50
67
|
id: "guido__btn-create-strategy",
|
|
51
|
-
className: "strategy-control-cta primary"
|
|
52
|
-
disabled: !0
|
|
68
|
+
className: "strategy-control-cta primary"
|
|
53
69
|
})
|
|
54
70
|
], "strategy-control-cta-row")}
|
|
55
|
-
</div>
|
|
56
|
-
<div data-strategy-assigned-state style="display: none;">
|
|
57
|
-
<div class="strategy-control-name-band">
|
|
58
|
-
<span class="strategy-control-name" data-strategy-name></span>
|
|
59
71
|
</div>
|
|
60
|
-
<div
|
|
61
|
-
|
|
72
|
+
<div data-strategy-assigned-state style="display: none;">
|
|
73
|
+
<div class="strategy-control-name-band">
|
|
74
|
+
<span class="strategy-control-name" data-strategy-name></span>
|
|
75
|
+
<span
|
|
76
|
+
class="guido-skeleton guido-skeleton--strategy-name" data-strategy-name-skeleton></span>
|
|
77
|
+
</div>
|
|
78
|
+
<div class="strategy-control-actions">
|
|
79
|
+
${this._strategyAction({
|
|
62
80
|
id: "guido__btn-change-strategy",
|
|
63
81
|
label: this.api.translate("Change"),
|
|
64
82
|
modifier: "change"
|
|
65
83
|
})}
|
|
66
|
-
|
|
84
|
+
${this._strategyAction({
|
|
67
85
|
id: "guido__btn-remove-strategy",
|
|
68
86
|
label: this.api.translate("Remove"),
|
|
69
87
|
modifier: "remove"
|
|
70
88
|
})}
|
|
89
|
+
</div>
|
|
71
90
|
</div>
|
|
72
91
|
</div>
|
|
73
92
|
</div>
|
|
@@ -84,41 +103,54 @@ class f extends h {
|
|
|
84
103
|
`;
|
|
85
104
|
}
|
|
86
105
|
onRender() {
|
|
87
|
-
this._teardown(), this._setupButtonListeners(), this._renderState(), this.storeUnsubscription = this.store.$subscribe(() => {
|
|
106
|
+
this._teardown(), this.store.strategyPanelOpen = !0, this._setupButtonListeners(), this._renderState(), this.storeUnsubscription = this.store.$subscribe(() => {
|
|
88
107
|
this._renderState();
|
|
89
|
-
}), this.store.recommendationConfigs.strategyId && !this.store.
|
|
108
|
+
}), this.store.recommendationConfigs.strategyId && !this.store.strategiesFetched && this.store.fetchStrategies().catch(() => {
|
|
90
109
|
});
|
|
91
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Whether the document itself says this block has no strategy.
|
|
113
|
+
*
|
|
114
|
+
* Read the node, not the store: when the main control cannot resolve the block id off the
|
|
115
|
+
* node it never syncs the persisted config, so the store still holds defaults (empty
|
|
116
|
+
* strategyId) for an assigned block.
|
|
117
|
+
*/
|
|
118
|
+
_isNodeUnassigned() {
|
|
119
|
+
if (!h.hasConfig(this.currentNode))
|
|
120
|
+
return !1;
|
|
121
|
+
const t = h.getConfig(this.currentNode);
|
|
122
|
+
return !t.strategyId && (t.configVersion ?? 0) >= b;
|
|
123
|
+
}
|
|
92
124
|
onDestroy() {
|
|
93
125
|
this._teardown();
|
|
94
126
|
}
|
|
95
127
|
_teardown() {
|
|
96
|
-
this.storeUnsubscription(), this.storeUnsubscription = () => {
|
|
128
|
+
this.store.strategyPanelOpen = !1, this.storeUnsubscription(), this.storeUnsubscription = () => {
|
|
97
129
|
}, this.lastPaintedState = null, this.listeners.forEach(({ element: t, handler: e }) => t.removeEventListener("click", e)), this.listeners = [];
|
|
98
130
|
}
|
|
99
131
|
_setupButtonListeners() {
|
|
100
132
|
const t = this.getContainer();
|
|
101
133
|
if (!t)
|
|
102
134
|
return;
|
|
103
|
-
const e = (a,
|
|
104
|
-
const
|
|
105
|
-
|
|
135
|
+
const e = (a, i) => {
|
|
136
|
+
const s = t.querySelector(a);
|
|
137
|
+
s && (s.addEventListener("click", i), this.listeners.push({ element: s, handler: i }));
|
|
106
138
|
};
|
|
107
|
-
e("#guido__btn-assign-strategy", () => this.store.openAssignStrategyDrawer()), e("#guido__btn-change-strategy", () => this.store.openAssignStrategyDrawer()), e("#guido__btn-remove-strategy", () => this.store.openRemoveStrategyModal());
|
|
139
|
+
e("#guido__btn-assign-strategy", () => this.store.openAssignStrategyDrawer()), e("#guido__btn-create-strategy", () => this.store.openStrategyCreation()), e("#guido__btn-change-strategy", () => this.store.openAssignStrategyDrawer()), e("#guido__btn-remove-strategy", () => this.store.openRemoveStrategyModal());
|
|
108
140
|
}
|
|
109
141
|
_renderState() {
|
|
110
|
-
var
|
|
111
|
-
const { strategyId: t } = this.store.recommendationConfigs, e = t ? ((
|
|
112
|
-
if (
|
|
142
|
+
var p;
|
|
143
|
+
const { strategyId: t } = this.store.recommendationConfigs, e = t ? ((p = this.store.assignedStrategy) == null ? void 0 : p.name) ?? "" : "", a = !!t && !e && (this.store.strategiesLoading || !this.store.strategiesSettled), i = `${t}\0${e}\0${a}`;
|
|
144
|
+
if (i === this.lastPaintedState)
|
|
113
145
|
return;
|
|
114
|
-
const
|
|
115
|
-
if (!
|
|
146
|
+
const s = this.getContainer();
|
|
147
|
+
if (!s)
|
|
116
148
|
return;
|
|
117
|
-
const
|
|
118
|
-
!
|
|
149
|
+
const c = s.querySelector("[data-strategy-empty-state]"), g = s.querySelector("[data-strategy-assigned-state]"), l = s.querySelector("[data-strategy-loading-state]"), y = s.querySelector("[data-strategy-content]"), d = s.querySelector("[data-strategy-name]"), m = s.querySelector("[data-strategy-name-skeleton]");
|
|
150
|
+
!c || !g || (l && (l.style.display = "none"), y && (y.style.display = ""), c.style.display = t ? "none" : "", g.style.display = t ? "" : "none", !t && this._isNodeUnassigned() && this.onboardingStore.startOnboarding("recommendationStrategyOnboarding"), d && (d.style.display = a ? "none" : "", t && !a && (d.textContent = e || `#${t}`)), m && (m.style.display = a ? "block" : "none"), this.lastPaintedState = i);
|
|
119
151
|
}
|
|
120
152
|
}
|
|
121
153
|
export {
|
|
122
|
-
|
|
123
|
-
|
|
154
|
+
k as STRATEGY_CONTROL_ID,
|
|
155
|
+
I as StrategyControl
|
|
124
156
|
};
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import { getRecommendationFeedSourceMaps as
|
|
2
|
-
import { useRecommendationApi as
|
|
3
|
-
import { useConfigStore as
|
|
4
|
-
import { defineStore as
|
|
1
|
+
import { getRecommendationFeedSourceMaps as k, strategyEditPath as G, URLS as D, getOperatorOptions as _, PriceAttributes as L } from "../../../../enums/extensions/recommendationBlock.js";
|
|
2
|
+
import { useRecommendationApi as E } from "../../../../services/recommendationApi.js";
|
|
3
|
+
import { useConfigStore as F } from "../../../../stores/config.js";
|
|
4
|
+
import { defineStore as N } from "pinia";
|
|
5
5
|
import "../constants/selectors.js";
|
|
6
|
-
import { DEFAULT_MOBILE_CARDS_IN_ROW as
|
|
7
|
-
import { DEFAULT_NODE_CONFIG as
|
|
8
|
-
import { getDefaultProducts as
|
|
9
|
-
import { generateCompleteFilterQuery as
|
|
10
|
-
import { getPartnerRecommendationParams as
|
|
11
|
-
import { sanitizeProductIds as
|
|
12
|
-
import { isFilterValid as
|
|
13
|
-
import { isConfigValid as
|
|
14
|
-
const
|
|
15
|
-
let
|
|
16
|
-
const
|
|
17
|
-
|
|
6
|
+
import { DEFAULT_MOBILE_CARDS_IN_ROW as U, DEFAULT_CARDS_IN_ROW as A } from "../constants/layout.js";
|
|
7
|
+
import { DEFAULT_NODE_CONFIG as x, EXCLUDED_ALGORITHM_IDS as B } from "../constants/defaultConfig.js";
|
|
8
|
+
import { getDefaultProducts as C } from "../templates/utils.js";
|
|
9
|
+
import { generateCompleteFilterQuery as v } from "../utils/filterUtil.js";
|
|
10
|
+
import { getPartnerRecommendationParams as M } from "../utils/partnerCustomizations.js";
|
|
11
|
+
import { sanitizeProductIds as O } from "../utils/productIds.js";
|
|
12
|
+
import { isFilterValid as T } from "../validation/filterSchema.js";
|
|
13
|
+
import { getInvalidFields as z, isConfigValid as V } from "../validation/requiredFields.js";
|
|
14
|
+
const d = E();
|
|
15
|
+
let h = null, g = null, S = null, p = null, y = 0;
|
|
16
|
+
const b = /* @__PURE__ */ new Map();
|
|
17
|
+
let l = null;
|
|
18
|
+
function P() {
|
|
18
19
|
return {
|
|
19
|
-
cardsInRow:
|
|
20
|
+
cardsInRow: A,
|
|
20
21
|
currencySettings: {
|
|
21
22
|
name: "USD",
|
|
22
23
|
value: "USD",
|
|
@@ -30,13 +31,17 @@ function w() {
|
|
|
30
31
|
productIds: [],
|
|
31
32
|
id: 1,
|
|
32
33
|
language: "en_US",
|
|
33
|
-
mobileCardsInRow:
|
|
34
|
+
mobileCardsInRow: U,
|
|
34
35
|
mobileLayoutEnabled: !1,
|
|
35
36
|
orientation: "grid",
|
|
36
37
|
recommendedProducts: [],
|
|
37
38
|
sendProductRequestFlag: !1,
|
|
38
39
|
shuffleProducts: !1,
|
|
39
|
-
|
|
40
|
+
// With RRS on, a block that has not been synced yet must not claim an algorithm:
|
|
41
|
+
// that default is what reached buildCampaignUrl and baked a most-popular feed URL
|
|
42
|
+
// for a block the user never configured (SD-149916). Legacy blocks still get their real
|
|
43
|
+
// algorithm from the node-config sync or the save-time seed.
|
|
44
|
+
strategy: F().isFeatureEnabled("reusableRecommendationStrategy") ? "" : "mostPopular",
|
|
40
45
|
strategyId: "",
|
|
41
46
|
textTrimming: !0,
|
|
42
47
|
unresponsive: !1,
|
|
@@ -46,9 +51,9 @@ function w() {
|
|
|
46
51
|
priceHideIfSameAsDiscounted: !1
|
|
47
52
|
};
|
|
48
53
|
}
|
|
49
|
-
function
|
|
54
|
+
function w() {
|
|
50
55
|
return {
|
|
51
|
-
recommendationConfigs:
|
|
56
|
+
recommendationConfigs: P(),
|
|
52
57
|
recommendationProducts: [],
|
|
53
58
|
filterStatus: !1,
|
|
54
59
|
filterSelectionDrawerStatus: !1,
|
|
@@ -59,7 +64,7 @@ function C() {
|
|
|
59
64
|
filterSnapshot: null
|
|
60
65
|
};
|
|
61
66
|
}
|
|
62
|
-
const
|
|
67
|
+
const j = () => ({
|
|
63
68
|
recommendationCampaignUrls: {},
|
|
64
69
|
activePredictiveAlgorithms: [],
|
|
65
70
|
languages: {},
|
|
@@ -68,11 +73,14 @@ const z = () => ({
|
|
|
68
73
|
strategies: [],
|
|
69
74
|
strategiesLoading: !1,
|
|
70
75
|
strategyUrlTemplates: {},
|
|
76
|
+
strategiesFetched: !1,
|
|
77
|
+
strategiesSettled: !1,
|
|
71
78
|
blockStates: {},
|
|
72
79
|
currentRecommendationId: null,
|
|
80
|
+
strategyPanelOpen: !1,
|
|
73
81
|
configVersion: 0
|
|
74
|
-
}),
|
|
75
|
-
state: () =>
|
|
82
|
+
}), nt = N("guidoRecommendationExtension", {
|
|
83
|
+
state: () => j(),
|
|
76
84
|
getters: {
|
|
77
85
|
// ====================================================================
|
|
78
86
|
// Proxy Getters — Backward Compatible Access to Current Block State
|
|
@@ -82,7 +90,7 @@ const z = () => ({
|
|
|
82
90
|
* This allows all existing code that reads `store.recommendationConfigs` to work unchanged.
|
|
83
91
|
*/
|
|
84
92
|
recommendationConfigs(t) {
|
|
85
|
-
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs :
|
|
93
|
+
return t.currentRecommendationId !== null && t.blockStates[t.currentRecommendationId] ? t.blockStates[t.currentRecommendationId].recommendationConfigs : P();
|
|
86
94
|
},
|
|
87
95
|
/**
|
|
88
96
|
* Proxy getter: delegates to blockStates[currentRecommendationId].recommendationProducts
|
|
@@ -137,8 +145,8 @@ const z = () => ({
|
|
|
137
145
|
return [...new Set(t.map((e) => e.filterGroup))].sort((e, r) => e - r);
|
|
138
146
|
},
|
|
139
147
|
getActivePredictiveAlgorithms: (t) => {
|
|
140
|
-
const e =
|
|
141
|
-
return t.activePredictiveAlgorithms.filter((n) => !
|
|
148
|
+
const e = k(), r = [];
|
|
149
|
+
return t.activePredictiveAlgorithms.filter((n) => !B.includes(n)).forEach((n) => {
|
|
142
150
|
r.push(...e.filter((s) => s.id === n));
|
|
143
151
|
}), r.map((n) => ({
|
|
144
152
|
text: n.name,
|
|
@@ -156,7 +164,7 @@ const z = () => ({
|
|
|
156
164
|
getFilterList() {
|
|
157
165
|
return Object.values(this.filterList).filter((t) => t.isFilterable !== 0 && t.isFilterable !== !1).map((t) => {
|
|
158
166
|
let e;
|
|
159
|
-
return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` :
|
|
167
|
+
return t.type === "productAttribute" ? e = `product_attributes.${t.attributeName}` : L.includes(t.attributeName) ? e = `${t.attributeName}.${this.recommendationConfigs.currencySettings.value}` : e = t.attributeName, {
|
|
160
168
|
text: t.displayName,
|
|
161
169
|
value: e,
|
|
162
170
|
type: t.attributeType
|
|
@@ -178,7 +186,7 @@ const z = () => ({
|
|
|
178
186
|
setCurrentBlock(t) {
|
|
179
187
|
this.blockStates[t] || (this.blockStates = {
|
|
180
188
|
...this.blockStates,
|
|
181
|
-
[t]:
|
|
189
|
+
[t]: w()
|
|
182
190
|
}), this.currentRecommendationId = t;
|
|
183
191
|
},
|
|
184
192
|
/**
|
|
@@ -246,7 +254,7 @@ const z = () => ({
|
|
|
246
254
|
decimalCount: String(e.currencyDecimalCount),
|
|
247
255
|
decimalSeparator: r(e.currencyDecimalSeparator, ","),
|
|
248
256
|
thousandSeparator: r(e.currencyThousandSeparator, ".")
|
|
249
|
-
}, s = !this.blockStates[t], i = s ?
|
|
257
|
+
}, s = !this.blockStates[t], i = s ? w() : this.blockStates[t];
|
|
250
258
|
i.recommendationConfigs = {
|
|
251
259
|
...i.recommendationConfigs,
|
|
252
260
|
strategy: e.strategy,
|
|
@@ -285,7 +293,7 @@ const z = () => ({
|
|
|
285
293
|
* Creates a filter with the first available attribute and operator pre-selected.
|
|
286
294
|
*/
|
|
287
295
|
createDefaultFilter(t, e) {
|
|
288
|
-
const [r] = this.getFilterList, [n] =
|
|
296
|
+
const [r] = this.getFilterList, [n] = _(r == null ? void 0 : r.type);
|
|
289
297
|
return {
|
|
290
298
|
type: "standardFilter",
|
|
291
299
|
attribute: (r == null ? void 0 : r.value) ?? "",
|
|
@@ -345,29 +353,96 @@ const z = () => ({
|
|
|
345
353
|
this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId] || (this.blockStates[this.currentRecommendationId].removeStrategyModalStatus = !1);
|
|
346
354
|
},
|
|
347
355
|
async fetchStrategies() {
|
|
348
|
-
|
|
349
|
-
|
|
356
|
+
for (; p; )
|
|
357
|
+
try {
|
|
358
|
+
await p;
|
|
359
|
+
} catch {
|
|
360
|
+
}
|
|
361
|
+
if (this.strategiesFetched)
|
|
350
362
|
return;
|
|
351
|
-
|
|
352
|
-
S = (async () => {
|
|
363
|
+
const t = y, e = (async () => {
|
|
353
364
|
this.strategiesLoading = !0;
|
|
354
365
|
try {
|
|
355
|
-
|
|
366
|
+
const r = await d.fetchRecommendationStrategies();
|
|
367
|
+
if (t !== y)
|
|
368
|
+
return;
|
|
369
|
+
this.strategies = r, this.strategiesFetched = !0;
|
|
356
370
|
} finally {
|
|
357
|
-
this.strategiesLoading = !1;
|
|
371
|
+
this.strategiesLoading = !1, t === y && (this.strategiesSettled = !0);
|
|
358
372
|
}
|
|
359
373
|
})();
|
|
374
|
+
p = e;
|
|
360
375
|
try {
|
|
361
|
-
await
|
|
376
|
+
await e;
|
|
362
377
|
} finally {
|
|
363
|
-
|
|
378
|
+
p = null;
|
|
364
379
|
}
|
|
365
380
|
},
|
|
381
|
+
invalidateStrategies() {
|
|
382
|
+
this.strategiesFetched = !1, this.strategiesSettled = !1, y += 1;
|
|
383
|
+
},
|
|
384
|
+
/**
|
|
385
|
+
* Opens a Smart Recommender strategy page in a new tab and refreshes the list every time
|
|
386
|
+
* the user comes back. `visibilitychange` covers the tab case; `focus` covers the page
|
|
387
|
+
* landing in a separate window, where this document never goes hidden.
|
|
388
|
+
*
|
|
389
|
+
* Deliberately NOT one-shot: the strategy tab stays open, so a user can create a second
|
|
390
|
+
* strategy in it and come back again — a listener that disarmed on the first return would
|
|
391
|
+
* leave that one missing from the list. It disarms on the first return AFTER that tab is
|
|
392
|
+
* closed instead, so an ordinary alt-tab later in the session costs nothing. Armed only
|
|
393
|
+
* once the user actually opens a strategy page, so anyone who never does pays nothing.
|
|
394
|
+
*/
|
|
395
|
+
_armStrategyPageReturn(t) {
|
|
396
|
+
const e = window.open(t, "_blank");
|
|
397
|
+
if (!e)
|
|
398
|
+
return;
|
|
399
|
+
e.opener = null, l == null || l();
|
|
400
|
+
let r = !1;
|
|
401
|
+
const n = () => {
|
|
402
|
+
document.hidden || r || (e != null && e.closed && (l == null || l()), r = !0, this.invalidateStrategies(), this.fetchStrategies().then(() => this._refreshAssignedStrategyProducts()).catch(() => {
|
|
403
|
+
}).finally(() => {
|
|
404
|
+
r = !1;
|
|
405
|
+
}));
|
|
406
|
+
};
|
|
407
|
+
document.addEventListener("visibilitychange", n), window.addEventListener("focus", n), l = () => {
|
|
408
|
+
document.removeEventListener("visibilitychange", n), window.removeEventListener("focus", n), l = null;
|
|
409
|
+
};
|
|
410
|
+
},
|
|
411
|
+
/**
|
|
412
|
+
* Reloads the products of the block the user is on, so an edit made in the strategy tab
|
|
413
|
+
* lands on the canvas instead of waiting for the assign drawer to be reopened.
|
|
414
|
+
*
|
|
415
|
+
* Only the selected block: the canvas regeneration is driven off the active block's
|
|
416
|
+
* product array, so refreshing an unselected block would fetch without redrawing it.
|
|
417
|
+
*/
|
|
418
|
+
async _refreshAssignedStrategyProducts() {
|
|
419
|
+
var e;
|
|
420
|
+
const t = this.currentRecommendationId;
|
|
421
|
+
t === null || !((e = this.blockStates[t]) != null && e.recommendationConfigs.strategyId) || await this.fetchRecommendationProducts();
|
|
422
|
+
},
|
|
423
|
+
/** Lets the editor tear the return listeners down when it unmounts. */
|
|
424
|
+
disposeStrategyPageReturn() {
|
|
425
|
+
l == null || l();
|
|
426
|
+
},
|
|
427
|
+
/**
|
|
428
|
+
* Opens Smart Recommender's strategy creation page. Every return refreshes the list so the
|
|
429
|
+
* new strategy is offered; the user picks it themselves.
|
|
430
|
+
*/
|
|
431
|
+
openStrategyCreation() {
|
|
432
|
+
this._armStrategyPageReturn(D.RECOMMENDATION_STRATEGY_CREATE_PATH);
|
|
433
|
+
},
|
|
434
|
+
/**
|
|
435
|
+
* Opens the strategy's edit page. Every return refreshes the list so the block reflects the
|
|
436
|
+
* edited configuration.
|
|
437
|
+
*/
|
|
438
|
+
openStrategyEdit(t) {
|
|
439
|
+
this._armStrategyPageReturn(G(t));
|
|
440
|
+
},
|
|
366
441
|
async resolveStrategyUrlTemplate(t, e) {
|
|
367
442
|
const r = typeof t.updated_at == "string" ? t.updated_at : "", n = r ? `${t.strategy_id}:${r}:${e}` : "", s = n ? this.strategyUrlTemplates[n] : void 0;
|
|
368
443
|
if (s)
|
|
369
444
|
return s;
|
|
370
|
-
const { full_path: i = "" } = await
|
|
445
|
+
const { full_path: i = "" } = await d.generateStrategyEndpoint(t, e) ?? {};
|
|
371
446
|
return n && i && (this.strategyUrlTemplates = {
|
|
372
447
|
...this.strategyUrlTemplates,
|
|
373
448
|
[n]: i
|
|
@@ -380,23 +455,23 @@ const z = () => ({
|
|
|
380
455
|
});
|
|
381
456
|
},
|
|
382
457
|
removeStrategy() {
|
|
383
|
-
this.patchCurrentBlockConfig({ strategyId: "", size:
|
|
458
|
+
this.patchCurrentBlockConfig({ strategyId: "", size: x.size });
|
|
384
459
|
},
|
|
385
460
|
// ====================================================================
|
|
386
461
|
// Shared Data Fetching (fetched once, used by all blocks)
|
|
387
462
|
// ====================================================================
|
|
388
463
|
async fetchRecommendationCreateData() {
|
|
389
464
|
if (!this.activePredictiveAlgorithms.length) {
|
|
390
|
-
if (
|
|
391
|
-
await
|
|
465
|
+
if (h) {
|
|
466
|
+
await h;
|
|
392
467
|
return;
|
|
393
468
|
}
|
|
394
|
-
|
|
469
|
+
h = (async () => {
|
|
395
470
|
const {
|
|
396
471
|
activePredictiveAlgorithms: t,
|
|
397
472
|
languages: e,
|
|
398
473
|
currencies: r
|
|
399
|
-
} = await
|
|
474
|
+
} = await d.fetchRecommendationCreateData();
|
|
400
475
|
if (this.activePredictiveAlgorithms = t, this.languages = e, this.currentRecommendationId !== null && this.blockStates[this.currentRecommendationId]) {
|
|
401
476
|
const n = this.blockStates[this.currentRecommendationId];
|
|
402
477
|
n.filterStatus = !!n.recommendationConfigs.filters.length;
|
|
@@ -404,26 +479,26 @@ const z = () => ({
|
|
|
404
479
|
this.currencyList = r;
|
|
405
480
|
})();
|
|
406
481
|
try {
|
|
407
|
-
await
|
|
482
|
+
await h;
|
|
408
483
|
} finally {
|
|
409
|
-
|
|
484
|
+
h = null;
|
|
410
485
|
}
|
|
411
486
|
}
|
|
412
487
|
},
|
|
413
488
|
async fetchRecommendationFilters() {
|
|
414
489
|
if (!Object.keys(this.filterList).length) {
|
|
415
|
-
if (
|
|
416
|
-
await
|
|
490
|
+
if (g) {
|
|
491
|
+
await g;
|
|
417
492
|
return;
|
|
418
493
|
}
|
|
419
|
-
|
|
420
|
-
const t = await
|
|
494
|
+
g = (async () => {
|
|
495
|
+
const t = await d.fetchRecommendationFilters();
|
|
421
496
|
this.filterList = t;
|
|
422
497
|
})();
|
|
423
498
|
try {
|
|
424
|
-
await
|
|
499
|
+
await g;
|
|
425
500
|
} finally {
|
|
426
|
-
|
|
501
|
+
g = null;
|
|
427
502
|
}
|
|
428
503
|
}
|
|
429
504
|
},
|
|
@@ -452,7 +527,7 @@ const z = () => ({
|
|
|
452
527
|
const n = [...e.recommendationConfigs.filters];
|
|
453
528
|
n[r] = {
|
|
454
529
|
...t,
|
|
455
|
-
isValid:
|
|
530
|
+
isValid: T(t)
|
|
456
531
|
}, e.recommendationConfigs.filters = n;
|
|
457
532
|
}
|
|
458
533
|
},
|
|
@@ -490,7 +565,7 @@ const z = () => ({
|
|
|
490
565
|
}), e.recommendationConfigs.filters = r;
|
|
491
566
|
},
|
|
492
567
|
generateFilterQuery() {
|
|
493
|
-
return
|
|
568
|
+
return v(this.recommendationConfigs.filters);
|
|
494
569
|
},
|
|
495
570
|
/**
|
|
496
571
|
* Validation-only check invoked at save-CTA time. Defined as an action
|
|
@@ -498,33 +573,45 @@ const z = () => ({
|
|
|
498
573
|
* every block's recommendationConfigs across user edits.
|
|
499
574
|
*/
|
|
500
575
|
hasInvalidBlock() {
|
|
501
|
-
return Object.values(this.blockStates).some((t) => !
|
|
576
|
+
return Object.values(this.blockStates).some((t) => !V(t.recommendationConfigs, this));
|
|
577
|
+
},
|
|
578
|
+
/**
|
|
579
|
+
* Which required fields are missing across the design's blocks, so the save
|
|
580
|
+
* toaster can name the cause instead of always showing the generic message.
|
|
581
|
+
*/
|
|
582
|
+
invalidBlockFields() {
|
|
583
|
+
return Object.values(this.blockStates).flatMap((t) => z(t.recommendationConfigs, this));
|
|
502
584
|
},
|
|
503
585
|
// ====================================================================
|
|
504
586
|
// Per-Block Product Fetching
|
|
505
587
|
// ====================================================================
|
|
506
588
|
async fetchRecommendationProducts() {
|
|
507
589
|
if (!(this.currentRecommendationId === null || !this.blockStates[this.currentRecommendationId])) {
|
|
508
|
-
if (
|
|
509
|
-
await
|
|
590
|
+
if (S) {
|
|
591
|
+
await S;
|
|
510
592
|
return;
|
|
511
593
|
}
|
|
512
|
-
|
|
594
|
+
S = this._doFetchProducts();
|
|
513
595
|
try {
|
|
514
|
-
await
|
|
596
|
+
await S;
|
|
515
597
|
} finally {
|
|
516
|
-
|
|
598
|
+
S = null;
|
|
517
599
|
}
|
|
518
600
|
}
|
|
519
601
|
},
|
|
520
602
|
async _doFetchProducts() {
|
|
521
|
-
var
|
|
522
|
-
const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n =
|
|
603
|
+
var f;
|
|
604
|
+
const t = this.currentRecommendationId, e = this.blockStates[t], { recommendationConfigs: r } = e, n = F();
|
|
523
605
|
if (r.strategyId && n.isFeatureEnabled("reusableRecommendationStrategy")) {
|
|
524
606
|
await this._doFetchStrategyProducts(t);
|
|
525
607
|
return;
|
|
526
608
|
}
|
|
527
|
-
const s =
|
|
609
|
+
const s = parseInt(r.size) || 6;
|
|
610
|
+
if (!r.strategy) {
|
|
611
|
+
this._setBlockProducts(t, [], s);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const i = r.filters.filter((m) => m.isValid), o = v(i), c = ((f = k().find((m) => m.key === r.strategy)) == null ? void 0 : f.path) || "", a = {
|
|
528
615
|
locale: r.language,
|
|
529
616
|
currency: r.currencySettings.value,
|
|
530
617
|
partnerName: n.partnerName,
|
|
@@ -532,21 +619,21 @@ const z = () => ({
|
|
|
532
619
|
details: !0,
|
|
533
620
|
campaignId: n.variationId
|
|
534
621
|
};
|
|
535
|
-
r.strategy === "manualMerchandising" ? a.productId =
|
|
622
|
+
r.strategy === "manualMerchandising" ? a.productId = O(r.productIds) : r.strategy === "similarViewed" && (a.productId = "{itemId}"), r.strategy === "userBased" && (a.userId = "{user_id}"), o && (a.filter = o), r.shuffleProducts && (a.shuffle = !0), Object.assign(
|
|
536
623
|
a,
|
|
537
|
-
|
|
624
|
+
M(n.partnerName, r.strategy)
|
|
538
625
|
);
|
|
539
|
-
let
|
|
626
|
+
let u;
|
|
540
627
|
try {
|
|
541
|
-
|
|
628
|
+
u = await d.fetchRecommendationProducts(c, a);
|
|
542
629
|
} catch {
|
|
543
|
-
|
|
630
|
+
u = [];
|
|
544
631
|
}
|
|
545
|
-
this._setBlockProducts(t,
|
|
632
|
+
this._setBlockProducts(t, u, s);
|
|
546
633
|
},
|
|
547
634
|
async _doFetchStrategyProducts(t) {
|
|
548
|
-
const e = (
|
|
549
|
-
|
|
635
|
+
const e = (b.get(t) ?? 0) + 1;
|
|
636
|
+
b.set(t, e);
|
|
550
637
|
const { recommendationConfigs: r } = this.blockStates[t];
|
|
551
638
|
let n = [], s = parseInt(r.size) || 6;
|
|
552
639
|
try {
|
|
@@ -556,25 +643,25 @@ const z = () => ({
|
|
|
556
643
|
);
|
|
557
644
|
if (i) {
|
|
558
645
|
s = parseInt(String(i.size ?? "")) || s;
|
|
559
|
-
const o = r.currencySettings.value, a = (await this.resolveStrategyUrlTemplate(i, o)).replaceAll("{locale}", r.language).replaceAll("{currency}", o),
|
|
560
|
-
|
|
646
|
+
const o = r.currencySettings.value, a = (await this.resolveStrategyUrlTemplate(i, o)).replaceAll("{locale}", r.language).replaceAll("{currency}", o), u = a.indexOf("?"), f = u === -1 ? a : a.slice(0, u), m = (u === -1 ? "" : a.slice(u + 1)).split("&").filter((R) => R && !R.startsWith("user_id=")), I = m.length ? `${f}?${m.join("&")}` : f;
|
|
647
|
+
I && (n = await d.fetchRecommendationProductsByUrl(I));
|
|
561
648
|
}
|
|
562
649
|
} catch {
|
|
563
650
|
n = [];
|
|
564
651
|
}
|
|
565
|
-
|
|
652
|
+
b.get(t) === e && this._setBlockProducts(t, n, s);
|
|
566
653
|
},
|
|
567
654
|
_setBlockProducts(t, e, r) {
|
|
568
655
|
if (!this.blockStates[t])
|
|
569
656
|
return;
|
|
570
|
-
const n = e.length > 0 ? e :
|
|
657
|
+
const n = e.length > 0 ? e : C(r);
|
|
571
658
|
this.blockStates[t].recommendationProducts = [
|
|
572
659
|
...n.slice(0, r),
|
|
573
|
-
...
|
|
660
|
+
...C(Math.max(0, r - n.length))
|
|
574
661
|
];
|
|
575
662
|
}
|
|
576
663
|
}
|
|
577
664
|
});
|
|
578
665
|
export {
|
|
579
|
-
|
|
666
|
+
nt as useRecommendationExtensionStore
|
|
580
667
|
};
|