@gengage/assistant-fe 0.4.4 → 0.4.6
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 -1
- package/dist/api-paths-C4GDpeTf.js +1214 -0
- package/dist/chat/index.d.ts +1 -374
- package/dist/chat/runtime.d.ts +374 -0
- package/dist/chat/types.d.ts +1 -1
- package/dist/chat-BRKK63lt.js +303 -0
- package/dist/chat-runtime.js +13 -0
- package/dist/chat.iife.js +7 -7
- package/dist/chat.js +11 -10
- package/dist/common/config-constants.d.ts +1 -0
- package/dist/common/config-schema.d.ts +0 -1
- package/dist/common/overlay.d.ts +4 -4
- package/dist/common-CEN5OW7E.js +491 -0
- package/dist/common.js +78 -76
- package/dist/{connection-warning-n88bjkqL.js → connection-warning-B6oIU-9s.js} +1 -1
- package/dist/context-VIG4SVcS.js +529 -0
- package/dist/index.js +70 -67
- package/dist/locale-CfqNifrU.js +7 -0
- package/dist/native-webview-DudQ7nHe.js +273 -0
- package/dist/native.iife.js +28 -91
- package/dist/native.js +1 -1
- package/dist/overlay-1EO41ZC7.js +212 -0
- package/dist/overlay.d.ts +4 -0
- package/dist/overlay.js +10 -0
- package/dist/pill-launcher-57nrdLRr.js +364 -0
- package/dist/qna/index.d.ts +1 -61
- package/dist/qna/runtime.d.ts +61 -0
- package/dist/qna-BNvttR6s.js +40 -0
- package/dist/qna-runtime.js +8 -0
- package/dist/qna.iife.js +4 -4
- package/dist/qna.js +6 -5
- package/dist/{simrel-K2TGFi1r.js → runtime-BdwZZIrO.js} +244 -293
- package/dist/{chat-DI7Vm0gh.js → runtime-C0qZk0y7.js} +1644 -2298
- package/dist/{qna-C5Ok3wd0.js → runtime-DDu8Wk0z.js} +87 -121
- package/dist/schemas-CLo8wCjs.js +3207 -0
- package/dist/{simbut-Cb5RfaAp.js → simbut-BMWC6x_t.js} +24 -22
- package/dist/simbut.js +1 -1
- package/dist/simrel/index.d.ts +1 -59
- package/dist/simrel/runtime.d.ts +59 -0
- package/dist/simrel-ohfkluhp.js +55 -0
- package/dist/simrel-runtime.js +8 -0
- package/dist/simrel.iife.js +4 -4
- package/dist/simrel.js +7 -6
- package/dist/widget-base-TgwiA8cD.js +578 -0
- package/package.json +17 -1
- package/dist/common-BxSi3UWt.js +0 -387
- package/dist/locale-MM0U5eeR.js +0 -1109
- package/dist/native-webview-DFqnyus6.js +0 -586
- package/dist/schemas-JpRGzRQT.js +0 -4419
- /package/dist/{price-formatter-CR6VT5z4.js → price-formatter-xI3g9Cd4.js} +0 -0
|
@@ -1,106 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { a as D, f as j, i as F, m as H, r as N, t as R, u as U } from "./api-paths-C4GDpeTf.js";
|
|
2
|
+
import { S as z, b as T, f as $, i as W, t as J, w, x as Q } from "./widget-base-TgwiA8cD.js";
|
|
3
|
+
import { A as Y, E as A, N as V, a as S, l as K, v as X } from "./context-VIG4SVcS.js";
|
|
4
|
+
import { t as Z } from "./locale-CfqNifrU.js";
|
|
5
|
+
import { a as ee, n as te, r as re, t as P } from "./price-formatter-xI3g9Cd4.js";
|
|
6
|
+
import { n as ne } from "./connection-warning-B6oIU-9s.js";
|
|
7
|
+
function M(e) {
|
|
6
8
|
const t = [];
|
|
7
|
-
for (const
|
|
8
|
-
const
|
|
9
|
-
typeof
|
|
9
|
+
for (const r of Object.values(e)) if (r.type === "ProductCard" && r.props) {
|
|
10
|
+
const n = r.props.product ?? r.props;
|
|
11
|
+
typeof n.sku == "string" && typeof n.name == "string" && t.push(n);
|
|
10
12
|
}
|
|
11
13
|
return t;
|
|
12
14
|
}
|
|
13
|
-
function
|
|
15
|
+
function G(e) {
|
|
14
16
|
const t = e.headers.get("Content-Type") ?? "";
|
|
15
17
|
return t.includes("application/x-ndjson") || t.includes("text/event-stream");
|
|
16
18
|
}
|
|
17
|
-
async function
|
|
18
|
-
const
|
|
19
|
-
const s =
|
|
20
|
-
!s || s.type !== "ui_spec" ||
|
|
19
|
+
async function ie(e, t) {
|
|
20
|
+
const r = [], n = { onEvent: (i) => {
|
|
21
|
+
const s = N(i);
|
|
22
|
+
!s || s.type !== "ui_spec" || r.push(...M(s.spec.elements));
|
|
21
23
|
} };
|
|
22
|
-
return t !== void 0 && (
|
|
24
|
+
return t !== void 0 && (n.signal = t), await U(e, n), r;
|
|
23
25
|
}
|
|
24
|
-
async function
|
|
25
|
-
const
|
|
26
|
+
async function se(e, t, r) {
|
|
27
|
+
const n = R("similar_products", t), i = {
|
|
26
28
|
method: "POST",
|
|
27
29
|
headers: { "Content-Type": "application/json" },
|
|
28
30
|
body: JSON.stringify(e)
|
|
29
31
|
};
|
|
30
|
-
|
|
31
|
-
const s = await fetch(
|
|
32
|
+
r !== void 0 && (i.signal = r);
|
|
33
|
+
const s = await fetch(n, i);
|
|
32
34
|
if (!s.ok) throw new Error(`HTTP ${s.status}: ${s.statusText}`);
|
|
33
|
-
if (
|
|
35
|
+
if (G(s)) return ie(s, r);
|
|
34
36
|
const c = await s.text();
|
|
35
37
|
if (!c) throw new Error("Empty response body from similar_products endpoint");
|
|
36
38
|
try {
|
|
37
|
-
return
|
|
39
|
+
return D(JSON.parse(c));
|
|
38
40
|
} catch {
|
|
39
41
|
throw new Error("Invalid JSON from similar_products endpoint");
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
async function
|
|
43
|
-
const
|
|
44
|
-
let
|
|
44
|
+
async function oe(e, t) {
|
|
45
|
+
const r = [];
|
|
46
|
+
let n = null;
|
|
45
47
|
const i = { onEvent: (s) => {
|
|
46
|
-
const c =
|
|
48
|
+
const c = N(s);
|
|
47
49
|
if (c) {
|
|
48
50
|
if (c.type === "metadata" && c.meta) {
|
|
49
51
|
const d = c.meta.group_name;
|
|
50
52
|
if (typeof d == "string") {
|
|
51
|
-
|
|
53
|
+
n = {
|
|
52
54
|
name: d,
|
|
53
55
|
products: []
|
|
54
56
|
};
|
|
55
|
-
const
|
|
56
|
-
typeof
|
|
57
|
+
const g = c.meta.highlight;
|
|
58
|
+
typeof g == "string" && (n.highlight = g), r.push(n);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
|
-
c.type === "ui_spec" &&
|
|
61
|
+
c.type === "ui_spec" && n && n.products.push(...M(c.spec.elements));
|
|
60
62
|
}
|
|
61
63
|
} };
|
|
62
|
-
return t !== void 0 && (i.signal = t), await
|
|
64
|
+
return t !== void 0 && (i.signal = t), await U(e, i), r;
|
|
63
65
|
}
|
|
64
|
-
async function
|
|
65
|
-
const
|
|
66
|
+
async function ae(e, t, r) {
|
|
67
|
+
const n = R("product_groupings", t), i = {
|
|
66
68
|
method: "POST",
|
|
67
69
|
headers: { "Content-Type": "application/json" },
|
|
68
70
|
body: JSON.stringify(e)
|
|
69
71
|
};
|
|
70
|
-
|
|
71
|
-
const s = await fetch(
|
|
72
|
+
r !== void 0 && (i.signal = r);
|
|
73
|
+
const s = await fetch(n, i);
|
|
72
74
|
if (!s.ok) throw new Error(`HTTP ${s.status}: ${s.statusText}`);
|
|
73
|
-
if (
|
|
75
|
+
if (G(s)) return oe(s, r);
|
|
74
76
|
const c = await s.text();
|
|
75
77
|
if (!c) return [];
|
|
76
78
|
try {
|
|
77
|
-
return
|
|
79
|
+
return F(JSON.parse(c));
|
|
78
80
|
} catch {
|
|
79
81
|
throw new Error("Invalid JSON from product_groupings endpoint");
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
|
-
function
|
|
83
|
-
const { product: t, index:
|
|
84
|
+
function x(e) {
|
|
85
|
+
const { product: t, index: r, discountType: n, onClick: i, onAddToCart: s, renderCard: c } = e, d = e.i18n, g = e.pricing;
|
|
84
86
|
if (e.renderCardElement) {
|
|
85
|
-
const o = e.renderCardElement(t,
|
|
87
|
+
const o = e.renderCardElement(t, r);
|
|
86
88
|
if (o) return o;
|
|
87
89
|
}
|
|
88
90
|
if (c) {
|
|
89
91
|
const o = document.createElement("div");
|
|
90
|
-
return o.className = "gengage-simrel-card gengage-simrel-card--custom gds-card gds-product-card gds-card-interactive", o.dataset.gengagePart = "simrel-product-card", o.innerHTML =
|
|
92
|
+
return o.className = "gengage-simrel-card gengage-simrel-card--custom gds-card gds-product-card gds-card-interactive", o.dataset.gengagePart = "simrel-product-card", o.innerHTML = V(c(t, r)), o.addEventListener("click", (a) => {
|
|
91
93
|
a.target.closest(".gengage-simrel-atc") || a.target.closest(".gengage-chat-product-card-atc") || i(t);
|
|
92
94
|
}), o;
|
|
93
95
|
}
|
|
94
96
|
const l = document.createElement("article");
|
|
95
97
|
l.className = "gengage-simrel-card gengage-chat-product-card gds-card gds-product-card gds-card-interactive", l.dataset.gengagePart = "simrel-product-card", t.inStock === !1 && l.classList.add("gengage-simrel-card--out-of-stock"), l.setAttribute("role", "listitem"), l.dataset.sku = t.sku;
|
|
96
98
|
const h = document.createElement("div");
|
|
97
|
-
if (h.className = "gengage-simrel-card-image gengage-chat-product-card-img-wrapper", h.dataset.gengagePart = "simrel-product-card-image", t.imageUrl &&
|
|
99
|
+
if (h.className = "gengage-simrel-card-image gengage-chat-product-card-img-wrapper", h.dataset.gengagePart = "simrel-product-card-image", t.imageUrl && Y(t.imageUrl)) {
|
|
98
100
|
const o = document.createElement("img");
|
|
99
|
-
o.className = "gengage-chat-product-card-img", o.src = t.imageUrl, o.alt = t.name, o.loading = "lazy",
|
|
101
|
+
o.className = "gengage-chat-product-card-img", o.src = t.imageUrl, o.alt = t.name, o.loading = "lazy", te(o), h.appendChild(o);
|
|
100
102
|
}
|
|
101
|
-
if (
|
|
103
|
+
if (n === "badge" && t.discountPercent && t.discountPercent > 0) {
|
|
102
104
|
const o = document.createElement("span");
|
|
103
|
-
o.className = "gengage-simrel-badge gengage-chat-product-card-discount-badge", o.textContent = `%${
|
|
105
|
+
o.className = "gengage-simrel-badge gengage-chat-product-card-discount-badge", o.textContent = `%${re(t.discountPercent)}`, h.appendChild(o);
|
|
104
106
|
}
|
|
105
107
|
l.appendChild(h);
|
|
106
108
|
const m = document.createElement("div");
|
|
@@ -111,20 +113,20 @@ function D(e) {
|
|
|
111
113
|
const p = document.createElement("div");
|
|
112
114
|
if (p.className = "gengage-simrel-card-name gengage-chat-product-card-name", p.textContent = t.name, p.title = t.name, m.appendChild(p), t.rating != null && t.rating > 0) {
|
|
113
115
|
const o = document.createElement("div");
|
|
114
|
-
if (o.className = "gengage-simrel-card-rating gengage-chat-product-card-rating", o.appendChild(
|
|
116
|
+
if (o.className = "gengage-simrel-card-rating gengage-chat-product-card-rating", o.appendChild(ee(t.rating)), t.reviewCount != null) {
|
|
115
117
|
const a = document.createElement("span");
|
|
116
118
|
a.className = "gengage-simrel-card-review-count gengage-chat-product-card-review-count", a.textContent = ` (${t.reviewCount})`, o.appendChild(a);
|
|
117
119
|
}
|
|
118
120
|
m.appendChild(o);
|
|
119
121
|
}
|
|
120
122
|
const y = document.createElement("div");
|
|
121
|
-
if (y.className = "gengage-simrel-card-price gengage-chat-product-card-price", t.originalPrice && t.originalPrice !== t.price && (
|
|
123
|
+
if (y.className = "gengage-simrel-card-price gengage-chat-product-card-price", t.originalPrice && t.originalPrice !== t.price && (n === "strike-through" || !n)) {
|
|
122
124
|
const o = document.createElement("span");
|
|
123
|
-
o.className = "gengage-simrel-card-price-original gengage-chat-product-card-original-price", o.textContent =
|
|
125
|
+
o.className = "gengage-simrel-card-price-original gengage-chat-product-card-original-price", o.textContent = P(t.originalPrice, g), y.appendChild(o);
|
|
124
126
|
}
|
|
125
127
|
if (t.price && parseFloat(t.price) > 0) {
|
|
126
128
|
const o = document.createElement("span");
|
|
127
|
-
o.className = "gengage-simrel-card-price-current gengage-chat-product-card-price-current", o.textContent =
|
|
129
|
+
o.className = "gengage-simrel-card-price-current gengage-chat-product-card-price-current", o.textContent = P(t.price, g), y.appendChild(o);
|
|
128
130
|
}
|
|
129
131
|
m.appendChild(y), l.appendChild(m);
|
|
130
132
|
const b = document.createElement("button");
|
|
@@ -147,40 +149,40 @@ function D(e) {
|
|
|
147
149
|
o.target.closest(".gengage-simrel-atc") || o.target.closest(".gengage-chat-product-card-atc") || o.target.closest(".gengage-chat-product-card-cta") || i(t);
|
|
148
150
|
}), l;
|
|
149
151
|
}
|
|
150
|
-
function
|
|
152
|
+
function I(e) {
|
|
151
153
|
const t = document.createElement("div");
|
|
152
154
|
t.className = "gengage-simrel-grid", t.setAttribute("role", "list"), t.setAttribute("aria-label", e.i18n?.similarProductsAriaLabel ?? "Similar products"), e.columns && t.style.setProperty("--gengage-simrel-columns", String(e.columns));
|
|
153
|
-
for (let
|
|
154
|
-
const
|
|
155
|
-
product: e.products[
|
|
156
|
-
index:
|
|
155
|
+
for (let r = 0; r < e.products.length; r++) {
|
|
156
|
+
const n = {
|
|
157
|
+
product: e.products[r],
|
|
158
|
+
index: r,
|
|
157
159
|
onClick: e.onClick,
|
|
158
160
|
onAddToCart: e.onAddToCart
|
|
159
161
|
};
|
|
160
|
-
e.i18n !== void 0 && (
|
|
161
|
-
const i =
|
|
162
|
+
e.i18n !== void 0 && (n.i18n = e.i18n), e.discountType !== void 0 && (n.discountType = e.discountType), e.renderCard !== void 0 && (n.renderCard = e.renderCard), e.renderCardElement !== void 0 && (n.renderCardElement = e.renderCardElement);
|
|
163
|
+
const i = x(n);
|
|
162
164
|
t.appendChild(i);
|
|
163
165
|
}
|
|
164
166
|
return e.products.length === 0 && (t.style.display = "none", t.dataset.empty = "true"), t;
|
|
165
167
|
}
|
|
166
|
-
var
|
|
167
|
-
function
|
|
168
|
-
const t =
|
|
169
|
-
if (
|
|
170
|
-
return
|
|
171
|
-
const
|
|
172
|
-
|
|
168
|
+
var ce = 0;
|
|
169
|
+
function de(e) {
|
|
170
|
+
const t = ce++, r = document.createElement("div");
|
|
171
|
+
if (r.className = "gengage-simrel-groups", r.dataset.gengagePart = "simrel-groups", e.groups.length === 0)
|
|
172
|
+
return r.style.display = "none", r.dataset.empty = "true", r;
|
|
173
|
+
const n = document.createElement("div");
|
|
174
|
+
n.className = "gengage-simrel-tabs gds-toolbar", n.dataset.gengagePart = "simrel-tab-bar", n.setAttribute("role", "tablist");
|
|
173
175
|
const i = [], s = [];
|
|
174
176
|
let c = 0;
|
|
175
177
|
const d = (a) => {
|
|
176
|
-
const
|
|
178
|
+
const u = {
|
|
177
179
|
products: a.products,
|
|
178
180
|
onClick: e.onClick,
|
|
179
181
|
onAddToCart: e.onAddToCart
|
|
180
182
|
};
|
|
181
|
-
return e.i18n !== void 0 && (
|
|
182
|
-
},
|
|
183
|
-
if (
|
|
183
|
+
return e.i18n !== void 0 && (u.i18n = e.i18n), e.discountType !== void 0 && (u.discountType = e.discountType), e.renderCard !== void 0 && (u.renderCard = e.renderCard), e.renderCardElement !== void 0 && (u.renderCardElement = e.renderCardElement), e.columns !== void 0 && (u.columns = e.columns), u;
|
|
184
|
+
}, g = (a, u = !1) => {
|
|
185
|
+
if (u && a !== c && e.onGroupingActivate) {
|
|
184
186
|
const f = e.groups[a];
|
|
185
187
|
e.onGroupingActivate({
|
|
186
188
|
grouping_label: f.name,
|
|
@@ -192,23 +194,23 @@ function fe(e) {
|
|
|
192
194
|
const v = f === a;
|
|
193
195
|
i[f].classList.toggle("gengage-simrel-tab--active", v), i[f].setAttribute("aria-selected", String(v)), i[f].tabIndex = v ? 0 : -1;
|
|
194
196
|
}
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
const C =
|
|
198
|
-
|
|
197
|
+
const _ = e.groups[a], E = s[a];
|
|
198
|
+
E.innerHTML = "";
|
|
199
|
+
const C = I(d(_));
|
|
200
|
+
E.appendChild(C);
|
|
199
201
|
for (let f = 0; f < s.length; f++) {
|
|
200
202
|
const v = f === a;
|
|
201
203
|
s[f].style.display = v ? "" : "none", s[f].tabIndex = v ? 0 : -1;
|
|
202
204
|
}
|
|
203
205
|
};
|
|
204
206
|
for (let a = 0; a < e.groups.length; a++) {
|
|
205
|
-
const
|
|
206
|
-
C.className = "gengage-simrel-tab gds-tab", C.type = "button", C.dataset.gengagePart = "simrel-tab", C.id =
|
|
207
|
-
let
|
|
208
|
-
v.key === "ArrowRight" || v.key === "ArrowDown" ?
|
|
209
|
-
}), i.push(C),
|
|
207
|
+
const u = e.groups[a], _ = `gengage-simrel-tab-${t}-${a}`, E = `gengage-simrel-panel-${t}-${a}`, C = document.createElement("button");
|
|
208
|
+
C.className = "gengage-simrel-tab gds-tab", C.type = "button", C.dataset.gengagePart = "simrel-tab", C.id = _, C.textContent = u.name, C.setAttribute("role", "tab"), C.setAttribute("aria-controls", E), C.setAttribute("aria-selected", String(a === 0)), C.tabIndex = a === 0 ? 0 : -1, a === 0 && C.classList.add("gengage-simrel-tab--active"), C.addEventListener("click", () => g(a, !0)), C.addEventListener("keydown", (v) => {
|
|
209
|
+
let k = -1;
|
|
210
|
+
v.key === "ArrowRight" || v.key === "ArrowDown" ? k = (a + 1) % e.groups.length : v.key === "ArrowLeft" || v.key === "ArrowUp" ? k = (a - 1 + e.groups.length) % e.groups.length : v.key === "Home" ? k = 0 : v.key === "End" && (k = e.groups.length - 1), k >= 0 && (v.preventDefault(), g(k, !0), i[k].focus());
|
|
211
|
+
}), i.push(C), n.appendChild(C);
|
|
210
212
|
const f = document.createElement("div");
|
|
211
|
-
f.className = "gengage-simrel-tab-panel", f.dataset.gengagePart = "simrel-tab-panel", f.id =
|
|
213
|
+
f.className = "gengage-simrel-tab-panel", f.dataset.gengagePart = "simrel-tab-panel", f.id = E, f.setAttribute("role", "tabpanel"), f.setAttribute("aria-labelledby", _), f.tabIndex = a === 0 ? 0 : -1, a !== 0 && (f.style.display = "none"), s.push(f);
|
|
212
214
|
}
|
|
213
215
|
const l = document.createElement("button");
|
|
214
216
|
l.type = "button", l.className = "gengage-simrel-tabs-arrow gengage-simrel-tabs-arrow--left", l.setAttribute("aria-label", e.i18n?.scrollTabsLeft ?? "Scroll tabs left"), l.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>';
|
|
@@ -216,181 +218,181 @@ function fe(e) {
|
|
|
216
218
|
h.type = "button", h.className = "gengage-simrel-tabs-arrow gengage-simrel-tabs-arrow--right", h.setAttribute("aria-label", e.i18n?.scrollTabsRight ?? "Scroll tabs right"), h.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>';
|
|
217
219
|
const m = 200;
|
|
218
220
|
l.addEventListener("click", () => {
|
|
219
|
-
|
|
221
|
+
n.scrollBy({
|
|
220
222
|
left: -m,
|
|
221
223
|
behavior: "smooth"
|
|
222
224
|
});
|
|
223
225
|
}), h.addEventListener("click", () => {
|
|
224
|
-
|
|
226
|
+
n.scrollBy({
|
|
225
227
|
left: m,
|
|
226
228
|
behavior: "smooth"
|
|
227
229
|
});
|
|
228
230
|
});
|
|
229
231
|
const p = () => {
|
|
230
|
-
const a =
|
|
231
|
-
l.style.display = a ? "none" : "", h.style.display =
|
|
232
|
+
const a = n.scrollLeft <= 4, u = n.scrollLeft + n.clientWidth >= n.scrollWidth - 4;
|
|
233
|
+
l.style.display = a ? "none" : "", h.style.display = u ? "none" : "", n.classList.toggle("gengage-simrel-tabs--peek-right", !u), n.classList.toggle("gengage-simrel-tabs--peek-left", !a);
|
|
232
234
|
};
|
|
233
|
-
|
|
235
|
+
n.addEventListener("scroll", p, { passive: !0 }), typeof ResizeObserver < "u" && new ResizeObserver(p).observe(n), l.style.display = "none", h.style.display = "none", requestAnimationFrame(p);
|
|
234
236
|
const y = document.createElement("div");
|
|
235
|
-
y.className = "gengage-simrel-tabs-wrapper", y.appendChild(l), y.appendChild(
|
|
236
|
-
const b = s[0], o =
|
|
237
|
+
y.className = "gengage-simrel-tabs-wrapper", y.appendChild(l), y.appendChild(n), y.appendChild(h), r.appendChild(y);
|
|
238
|
+
const b = s[0], o = I(d(e.groups[0]));
|
|
237
239
|
b.appendChild(o);
|
|
238
|
-
for (const a of s)
|
|
239
|
-
return
|
|
240
|
+
for (const a of s) r.appendChild(a);
|
|
241
|
+
return r;
|
|
240
242
|
}
|
|
241
|
-
function
|
|
243
|
+
function L(e) {
|
|
242
244
|
if (!e || typeof e != "object") return null;
|
|
243
245
|
const t = e;
|
|
244
246
|
if (typeof t.sku != "string" || typeof t.name != "string" || typeof t.url != "string") return null;
|
|
245
|
-
const
|
|
247
|
+
const r = {
|
|
246
248
|
sku: t.sku,
|
|
247
249
|
name: t.name,
|
|
248
250
|
url: t.url
|
|
249
|
-
},
|
|
250
|
-
typeof
|
|
251
|
+
}, n = t.imageUrl;
|
|
252
|
+
typeof n == "string" && (r.imageUrl = n);
|
|
251
253
|
const i = t.price;
|
|
252
|
-
typeof i == "string" && (
|
|
254
|
+
typeof i == "string" && (r.price = i);
|
|
253
255
|
const s = t.originalPrice;
|
|
254
|
-
typeof s == "string" && (
|
|
256
|
+
typeof s == "string" && (r.originalPrice = s);
|
|
255
257
|
const c = t.discountPercent;
|
|
256
|
-
typeof c == "number" && (
|
|
258
|
+
typeof c == "number" && (r.discountPercent = c);
|
|
257
259
|
const d = t.brand;
|
|
258
|
-
typeof d == "string" && (
|
|
259
|
-
const
|
|
260
|
-
typeof
|
|
260
|
+
typeof d == "string" && (r.brand = d);
|
|
261
|
+
const g = t.rating;
|
|
262
|
+
typeof g == "number" && (r.rating = g);
|
|
261
263
|
const l = t.reviewCount;
|
|
262
|
-
typeof l == "number" && (
|
|
264
|
+
typeof l == "number" && (r.reviewCount = l);
|
|
263
265
|
const h = t.cartCode;
|
|
264
|
-
typeof h == "string" && (
|
|
266
|
+
typeof h == "string" && (r.cartCode = h);
|
|
265
267
|
const m = t.inStock;
|
|
266
|
-
typeof m == "boolean" && (
|
|
268
|
+
typeof m == "boolean" && (r.inStock = m);
|
|
267
269
|
const p = t.extras;
|
|
268
|
-
return p != null && typeof p == "object" && (
|
|
270
|
+
return p != null && typeof p == "object" && (r.extras = p), r;
|
|
269
271
|
}
|
|
270
|
-
function
|
|
272
|
+
function le(e) {
|
|
271
273
|
if (!e || typeof e != "object") return null;
|
|
272
|
-
const t = e,
|
|
273
|
-
if (typeof
|
|
274
|
+
const t = e, r = t.title, n = t.type;
|
|
275
|
+
if (typeof r != "string" || typeof n != "string") return null;
|
|
274
276
|
const i = {
|
|
275
|
-
title:
|
|
276
|
-
type:
|
|
277
|
+
title: r,
|
|
278
|
+
type: n
|
|
277
279
|
};
|
|
278
280
|
return t.payload !== void 0 && (i.payload = t.payload), i;
|
|
279
281
|
}
|
|
280
|
-
var
|
|
281
|
-
ProductGrid: ({ element: e, renderElement: t, context:
|
|
282
|
-
const
|
|
283
|
-
|
|
282
|
+
var O = {
|
|
283
|
+
ProductGrid: ({ element: e, renderElement: t, context: r }) => {
|
|
284
|
+
const n = document.createElement("div");
|
|
285
|
+
n.className = "gengage-simrel-grid", n.setAttribute("role", "list");
|
|
284
286
|
const i = e.props?.columns;
|
|
285
287
|
let s;
|
|
286
|
-
typeof i == "number" && Number.isFinite(i) && i > 0 ? s = Math.floor(i) : typeof
|
|
288
|
+
typeof i == "number" && Number.isFinite(i) && i > 0 ? s = Math.floor(i) : typeof r.gridColumns == "number" && Number.isFinite(r.gridColumns) && r.gridColumns > 0 && (s = Math.floor(r.gridColumns)), s !== void 0 && n.style.setProperty("--gengage-simrel-columns", String(s));
|
|
287
289
|
for (const c of e.children ?? []) {
|
|
288
290
|
const d = t(c);
|
|
289
|
-
d &&
|
|
291
|
+
d && n.appendChild(d);
|
|
290
292
|
}
|
|
291
|
-
if (
|
|
293
|
+
if (n.children.length === 0) {
|
|
292
294
|
const c = document.createElement("div");
|
|
293
|
-
c.className = "gengage-simrel-empty", c.textContent =
|
|
295
|
+
c.className = "gengage-simrel-empty", c.textContent = r.i18n.emptyStateMessage, n.appendChild(c);
|
|
294
296
|
}
|
|
295
|
-
return
|
|
297
|
+
return n;
|
|
296
298
|
},
|
|
297
299
|
ProductCard: ({ element: e, context: t }) => {
|
|
298
|
-
const
|
|
299
|
-
if (!
|
|
300
|
-
const
|
|
301
|
-
product:
|
|
300
|
+
const r = L(e.props?.product ?? e.props);
|
|
301
|
+
if (!r) return null;
|
|
302
|
+
const n = e.props?.index, i = typeof n == "number" && Number.isFinite(n) ? n : 0, s = e.props?.discountType, c = s === "strike-through" || s === "badge" ? s : t.discountType, d = {
|
|
303
|
+
product: r,
|
|
302
304
|
index: i,
|
|
303
305
|
onClick: t.onClick,
|
|
304
306
|
onAddToCart: t.onAddToCart,
|
|
305
307
|
i18n: t.i18n
|
|
306
308
|
};
|
|
307
|
-
return c !== void 0 && (d.discountType = c), t.renderCard !== void 0 && (d.renderCard = t.renderCard), t.renderCardElement !== void 0 && (d.renderCardElement = t.renderCardElement), t.pricing !== void 0 && (d.pricing = t.pricing),
|
|
309
|
+
return c !== void 0 && (d.discountType = c), t.renderCard !== void 0 && (d.renderCard = t.renderCard), t.renderCardElement !== void 0 && (d.renderCardElement = t.renderCardElement), t.pricing !== void 0 && (d.pricing = t.pricing), x(d);
|
|
308
310
|
},
|
|
309
311
|
GroupTabs: ({ element: e, context: t }) => {
|
|
310
|
-
const
|
|
311
|
-
if (!Array.isArray(
|
|
312
|
-
const
|
|
313
|
-
for (const c of
|
|
312
|
+
const r = e.props?.groups;
|
|
313
|
+
if (!Array.isArray(r)) return null;
|
|
314
|
+
const n = [];
|
|
315
|
+
for (const c of r) {
|
|
314
316
|
if (!c || typeof c != "object") continue;
|
|
315
317
|
const d = c;
|
|
316
318
|
if (typeof d.name != "string") continue;
|
|
317
|
-
const
|
|
319
|
+
const g = [];
|
|
318
320
|
if (Array.isArray(d.products)) for (const h of d.products) {
|
|
319
|
-
const m =
|
|
320
|
-
m &&
|
|
321
|
+
const m = L(h);
|
|
322
|
+
m && g.push(m);
|
|
321
323
|
}
|
|
322
324
|
const l = {
|
|
323
325
|
name: d.name,
|
|
324
|
-
products:
|
|
326
|
+
products: g
|
|
325
327
|
};
|
|
326
|
-
typeof d.highlight == "string" && (l.highlight = d.highlight),
|
|
328
|
+
typeof d.highlight == "string" && (l.highlight = d.highlight), n.push(l);
|
|
327
329
|
}
|
|
328
330
|
const i = {
|
|
329
|
-
groups:
|
|
331
|
+
groups: n,
|
|
330
332
|
onClick: t.onClick,
|
|
331
333
|
onAddToCart: t.onAddToCart,
|
|
332
334
|
i18n: t.i18n
|
|
333
335
|
}, s = e.props?.columns;
|
|
334
|
-
return typeof s == "number" && Number.isFinite(s) && s > 0 ? i.columns = Math.floor(s) : typeof t.gridColumns == "number" && Number.isFinite(t.gridColumns) && t.gridColumns > 0 && (i.columns = Math.floor(t.gridColumns)), t.discountType !== void 0 && (i.discountType = t.discountType), t.renderCard !== void 0 && (i.renderCard = t.renderCard), t.renderCardElement !== void 0 && (i.renderCardElement = t.renderCardElement), t.onGroupingActivate !== void 0 && (i.onGroupingActivate = t.onGroupingActivate),
|
|
336
|
+
return typeof s == "number" && Number.isFinite(s) && s > 0 ? i.columns = Math.floor(s) : typeof t.gridColumns == "number" && Number.isFinite(t.gridColumns) && t.gridColumns > 0 && (i.columns = Math.floor(t.gridColumns)), t.discountType !== void 0 && (i.discountType = t.discountType), t.renderCard !== void 0 && (i.renderCard = t.renderCard), t.renderCardElement !== void 0 && (i.renderCardElement = t.renderCardElement), t.onGroupingActivate !== void 0 && (i.onGroupingActivate = t.onGroupingActivate), de(i);
|
|
335
337
|
},
|
|
336
338
|
EmptyState: ({ element: e, context: t }) => {
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
return
|
|
339
|
+
const r = document.createElement("div");
|
|
340
|
+
r.className = "gengage-simrel-empty";
|
|
341
|
+
const n = e.props?.message;
|
|
342
|
+
return r.textContent = typeof n == "string" ? n : t.i18n.emptyStateMessage, r;
|
|
341
343
|
},
|
|
342
344
|
AddToCartButton: ({ element: e, context: t }) => {
|
|
343
|
-
const
|
|
344
|
-
if (typeof
|
|
345
|
+
const r = e.props?.sku, n = e.props?.cartCode;
|
|
346
|
+
if (typeof r != "string" || typeof n != "string") return null;
|
|
345
347
|
const i = document.createElement("button");
|
|
346
348
|
i.className = "gengage-simrel-atc gengage-chat-product-card-cta", i.type = "button";
|
|
347
349
|
const s = e.props?.label;
|
|
348
350
|
return i.textContent = typeof s == "string" ? s : t.i18n.addToCartButton, i.addEventListener("click", (c) => {
|
|
349
351
|
c.preventDefault(), c.stopPropagation(), t.onAddToCart({
|
|
350
|
-
sku:
|
|
352
|
+
sku: r,
|
|
351
353
|
quantity: 1,
|
|
352
|
-
cartCode:
|
|
354
|
+
cartCode: n
|
|
353
355
|
});
|
|
354
356
|
}), i;
|
|
355
357
|
},
|
|
356
358
|
QuickActions: ({ element: e, context: t }) => {
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
const
|
|
360
|
-
if (!Array.isArray(
|
|
361
|
-
for (const i of
|
|
359
|
+
const r = document.createElement("div");
|
|
360
|
+
r.className = "gengage-simrel-quick-actions";
|
|
361
|
+
const n = e.props?.actions;
|
|
362
|
+
if (!Array.isArray(n) || !t.onAction) return r;
|
|
363
|
+
for (const i of n) {
|
|
362
364
|
if (!i || typeof i != "object") continue;
|
|
363
|
-
const s = i, c = s.label, d =
|
|
365
|
+
const s = i, c = s.label, d = le(s.action);
|
|
364
366
|
if (typeof c != "string" || !d) continue;
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
+
const g = document.createElement("button");
|
|
368
|
+
g.className = "gengage-simrel-quick-action", g.type = "button", g.textContent = c, g.addEventListener("click", (l) => {
|
|
367
369
|
l.preventDefault(), l.stopPropagation(), t.onAction?.(d);
|
|
368
|
-
}),
|
|
370
|
+
}), r.appendChild(g);
|
|
369
371
|
}
|
|
370
|
-
return
|
|
372
|
+
return r;
|
|
371
373
|
}
|
|
372
|
-
},
|
|
374
|
+
}, B = ({ element: e, renderElement: t }) => {
|
|
373
375
|
if (!e.children || e.children.length === 0) return null;
|
|
374
|
-
const
|
|
375
|
-
for (const
|
|
376
|
-
const i = t(
|
|
377
|
-
i &&
|
|
376
|
+
const r = document.createElement("div");
|
|
377
|
+
for (const n of e.children) {
|
|
378
|
+
const i = t(n);
|
|
379
|
+
i && r.appendChild(i);
|
|
378
380
|
}
|
|
379
|
-
return
|
|
381
|
+
return r;
|
|
380
382
|
};
|
|
381
|
-
function
|
|
382
|
-
return { ...
|
|
383
|
+
function ge() {
|
|
384
|
+
return { ...O };
|
|
383
385
|
}
|
|
384
|
-
function
|
|
385
|
-
return
|
|
386
|
+
function ue(e, t, r = O, n = B) {
|
|
387
|
+
return H({
|
|
386
388
|
spec: e,
|
|
387
389
|
context: t,
|
|
388
|
-
registry:
|
|
390
|
+
registry: r,
|
|
389
391
|
containerClassName: "gengage-simrel-uispec",
|
|
390
|
-
unknownRenderer:
|
|
392
|
+
unknownRenderer: n
|
|
391
393
|
});
|
|
392
394
|
}
|
|
393
|
-
var
|
|
395
|
+
var q = {
|
|
394
396
|
similarProductsAriaLabel: "Benzer ürünler",
|
|
395
397
|
emptyStateMessage: "Benzer ürün bulunamadı.",
|
|
396
398
|
addToCartButton: "Sepete Ekle",
|
|
@@ -403,7 +405,7 @@ var H = {
|
|
|
403
405
|
priceSuffix: " TL",
|
|
404
406
|
scrollTabsLeft: "Sola kaydır",
|
|
405
407
|
scrollTabsRight: "Sağa kaydır"
|
|
406
|
-
},
|
|
408
|
+
}, pe = {
|
|
407
409
|
similarProductsAriaLabel: "Similar products",
|
|
408
410
|
emptyStateMessage: "No similar products found.",
|
|
409
411
|
addToCartButton: "Add to cart",
|
|
@@ -417,74 +419,24 @@ var H = {
|
|
|
417
419
|
scrollTabsLeft: "Scroll tabs left",
|
|
418
420
|
scrollTabsRight: "Scroll tabs right"
|
|
419
421
|
};
|
|
420
|
-
function
|
|
422
|
+
function me(e) {
|
|
421
423
|
return e ? e.toLowerCase().split("-")[0] ?? "tr" : "tr";
|
|
422
424
|
}
|
|
423
|
-
function
|
|
424
|
-
return
|
|
425
|
+
function fe(e) {
|
|
426
|
+
return me(e) === "en" ? pe : q;
|
|
425
427
|
}
|
|
426
|
-
var
|
|
427
|
-
|
|
428
|
-
name: E(),
|
|
429
|
-
imageUrl: E().url().optional(),
|
|
430
|
-
price: E().optional(),
|
|
431
|
-
originalPrice: E().optional(),
|
|
432
|
-
discountPercent: A().optional(),
|
|
433
|
-
url: E().url(),
|
|
434
|
-
brand: E().optional(),
|
|
435
|
-
rating: A().min(0).max(5).optional(),
|
|
436
|
-
reviewCount: A().int().nonnegative().optional()
|
|
437
|
-
}), ke = S({
|
|
438
|
-
layout: O(["grid", "carousel"]).optional(),
|
|
439
|
-
columns: A().int().positive().optional()
|
|
440
|
-
}), Se = S({
|
|
441
|
-
product: _e,
|
|
442
|
-
index: A().int().nonnegative(),
|
|
443
|
-
discountType: O(["strike-through", "badge"]).optional()
|
|
444
|
-
}), Te = S({
|
|
445
|
-
sku: E(),
|
|
446
|
-
label: E().optional(),
|
|
447
|
-
cartCode: E()
|
|
448
|
-
}), we = S({ actions: J(S({
|
|
449
|
-
label: E(),
|
|
450
|
-
action: S({
|
|
451
|
-
title: E(),
|
|
452
|
-
type: E(),
|
|
453
|
-
payload: Q().optional()
|
|
454
|
-
})
|
|
455
|
-
})) }), Ae = S({ message: E().optional() }), Ge = { components: {
|
|
456
|
-
ProductGrid: {
|
|
457
|
-
schema: ke,
|
|
458
|
-
description: "Outer grid or carousel container for similar products."
|
|
459
|
-
},
|
|
460
|
-
ProductCard: {
|
|
461
|
-
schema: Se,
|
|
462
|
-
description: "A single product card with image, title, price, and actions."
|
|
463
|
-
},
|
|
464
|
-
AddToCartButton: {
|
|
465
|
-
schema: Te,
|
|
466
|
-
description: "Add-to-cart CTA rendered inside or below a product card."
|
|
467
|
-
},
|
|
468
|
-
QuickActions: {
|
|
469
|
-
schema: we,
|
|
470
|
-
description: "A row of quick-action buttons below product info."
|
|
471
|
-
},
|
|
472
|
-
EmptyState: {
|
|
473
|
-
schema: Ae,
|
|
474
|
-
description: "Empty state shown when no similar products are available."
|
|
475
|
-
}
|
|
476
|
-
} }, Pe = 12e4;
|
|
477
|
-
function Ie(e) {
|
|
428
|
+
var he = 12e4;
|
|
429
|
+
function ye(e) {
|
|
478
430
|
return e instanceof DOMException && e.name === "AbortError";
|
|
479
431
|
}
|
|
480
|
-
var
|
|
432
|
+
var Ce = class extends J {
|
|
481
433
|
constructor(...e) {
|
|
482
|
-
super(...e), this._abortController = null, this._contentEl = null, this._lastResultCount = -1, this._i18n =
|
|
434
|
+
super(...e), this._abortController = null, this._contentEl = null, this._lastResultCount = -1, this._i18n = q;
|
|
483
435
|
}
|
|
484
436
|
async onInit(e) {
|
|
485
|
-
this._i18n = this._resolveI18n(e), this._contentEl = document.createElement("div"), this._contentEl.className = "gengage-simrel-container", this._contentEl.dataset.gengagePart = "simrel-container", this._contentEl.lang =
|
|
437
|
+
this._i18n = this._resolveI18n(e), this._contentEl = document.createElement("div"), this._contentEl.className = "gengage-simrel-container", this._contentEl.dataset.gengagePart = "simrel-container", this._contentEl.lang = Z(e.locale);
|
|
486
438
|
const t = this._clampGridColumns(e.gridColumns);
|
|
487
|
-
t !== void 0 && this._contentEl.style.setProperty("--gengage-simrel-columns", String(t)), this.root.appendChild(this._contentEl), this._lastSku = e.sku, await this._fetchAndRender(e.sku),
|
|
439
|
+
t !== void 0 && this._contentEl.style.setProperty("--gengage-simrel-columns", String(t)), this.root.appendChild(this._contentEl), this._lastSku = e.sku, await this._fetchAndRender(e.sku), X("simrel");
|
|
488
440
|
}
|
|
489
441
|
onUpdate(e) {
|
|
490
442
|
const t = e.sku;
|
|
@@ -507,16 +459,16 @@ var Le = class extends te {
|
|
|
507
459
|
url: e.url
|
|
508
460
|
};
|
|
509
461
|
if (e.imageUrl !== void 0 && (t.imageUrl = e.imageUrl), e.price !== void 0 && (t.price = e.price), e.originalPrice !== void 0 && (t.originalPrice = e.originalPrice), e.discountPercent !== void 0 && (t.discountPercent = e.discountPercent), e.brand !== void 0 && (t.brand = e.brand), e.rating !== void 0 && (t.rating = e.rating), e.reviewCount !== void 0 && (t.reviewCount = e.reviewCount), e.cartCode !== void 0 && (t.cartCode = e.cartCode), e.inStock !== void 0 && (t.inStock = e.inStock), this.config.onProductClick?.(t) === !1) return;
|
|
510
|
-
const
|
|
511
|
-
|
|
462
|
+
const r = this.config.session?.sessionId ?? null;
|
|
463
|
+
S("gengage:similar:product-click", {
|
|
512
464
|
sku: e.sku,
|
|
513
465
|
url: e.url,
|
|
514
|
-
sessionId:
|
|
466
|
+
sessionId: r,
|
|
515
467
|
productName: e.name
|
|
516
|
-
}), this.config.onProductNavigate?.(e.url, e.sku,
|
|
468
|
+
}), this.config.onProductNavigate?.(e.url, e.sku, r);
|
|
517
469
|
}
|
|
518
470
|
_handleAddToCart(e) {
|
|
519
|
-
|
|
471
|
+
K(e.sku, e.quantity), this.config.onAddToCart?.(e), S("gengage:similar:add-to-cart", e), this.track($(this.analyticsContext(), {
|
|
520
472
|
attribution_source: "simrel",
|
|
521
473
|
attribution_action_id: crypto.randomUUID(),
|
|
522
474
|
cart_value: 0,
|
|
@@ -532,40 +484,40 @@ var Le = class extends te {
|
|
|
532
484
|
return this._abortController?.signal !== e;
|
|
533
485
|
}
|
|
534
486
|
_emitSimilarProductsImpression(e, t) {
|
|
535
|
-
const
|
|
536
|
-
|
|
487
|
+
const r = this.config.session?.sessionId ?? null;
|
|
488
|
+
S("gengage:similar:products-impression", {
|
|
537
489
|
source_sku: this.config.sku,
|
|
538
490
|
product_count: e,
|
|
539
491
|
grouped: t,
|
|
540
|
-
sessionId:
|
|
492
|
+
sessionId: r
|
|
541
493
|
});
|
|
542
494
|
}
|
|
543
495
|
_resolveRequestTimeoutMs() {
|
|
544
496
|
const e = this.config.requestTimeoutMs;
|
|
545
|
-
return typeof e != "number" || !Number.isFinite(e) || e <= 0 ?
|
|
497
|
+
return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? he : Math.floor(e);
|
|
546
498
|
}
|
|
547
499
|
async _fetchAndRender(e) {
|
|
548
500
|
this._abort();
|
|
549
501
|
const t = new AbortController();
|
|
550
502
|
this._abortController = t;
|
|
551
|
-
const
|
|
552
|
-
let
|
|
503
|
+
const r = t.signal;
|
|
504
|
+
let n = !1;
|
|
553
505
|
const i = setTimeout(() => {
|
|
554
|
-
|
|
506
|
+
n = !0, t.abort();
|
|
555
507
|
}, this._resolveRequestTimeoutMs());
|
|
556
|
-
if (
|
|
508
|
+
if (r.addEventListener("abort", () => clearTimeout(i), { once: !0 }), !this._contentEl) return;
|
|
557
509
|
this._contentEl.innerHTML = "", this._contentEl.style.display = "";
|
|
558
510
|
const s = document.createElement("div");
|
|
559
511
|
s.className = "gengage-simrel-loading", s.dataset.gengagePart = "simrel-loading";
|
|
560
512
|
const c = document.createElement("div");
|
|
561
513
|
c.className = "gengage-simrel-spinner", c.dataset.gengagePart = "simrel-loading-spinner", s.appendChild(c), this._contentEl.appendChild(s);
|
|
562
|
-
const d = { middlewareUrl: this.config.middlewareUrl },
|
|
514
|
+
const d = { middlewareUrl: this.config.middlewareUrl }, g = crypto.randomUUID(), l = Date.now(), h = ne({
|
|
563
515
|
source: "simrel",
|
|
564
516
|
locale: this.config.locale
|
|
565
517
|
});
|
|
566
|
-
this.track(
|
|
518
|
+
this.track(z(this.analyticsContext(), {
|
|
567
519
|
endpoint: "similar_products",
|
|
568
|
-
request_id:
|
|
520
|
+
request_id: g,
|
|
569
521
|
widget: "simrel"
|
|
570
522
|
}));
|
|
571
523
|
try {
|
|
@@ -576,64 +528,64 @@ var Le = class extends te {
|
|
|
576
528
|
sku: e
|
|
577
529
|
};
|
|
578
530
|
this.config.domain !== void 0 && (m.domain = this.config.domain);
|
|
579
|
-
const p = await
|
|
531
|
+
const p = await se(m, d, r);
|
|
580
532
|
if (this._lastResultCount = p.length, !this._contentEl) return;
|
|
581
533
|
if (this._contentEl.innerHTML = "", p.length > 0) try {
|
|
582
|
-
const y = p.map((a) => a.sku), b = new Map(p.map((a) => [a.sku, a])), o = (await
|
|
534
|
+
const y = p.map((a) => a.sku), b = new Map(p.map((a) => [a.sku, a])), o = (await ae({
|
|
583
535
|
account_id: this.config.accountId,
|
|
584
536
|
session_id: this.config.session?.sessionId ?? "",
|
|
585
537
|
correlation_id: this.config.session?.sessionId ?? "",
|
|
586
538
|
skus: y
|
|
587
|
-
}, d,
|
|
539
|
+
}, d, r)).map((a) => ({
|
|
588
540
|
...a,
|
|
589
|
-
products: a.products.map((
|
|
590
|
-
...b.get(
|
|
591
|
-
...
|
|
592
|
-
})).filter((
|
|
541
|
+
products: a.products.map((u) => ({
|
|
542
|
+
...b.get(u.sku),
|
|
543
|
+
...u
|
|
544
|
+
})).filter((u) => typeof u.sku == "string" && typeof u.name == "string" && typeof u.url == "string")
|
|
593
545
|
})).filter((a) => a.products.length > 0);
|
|
594
546
|
if (o.length > 0 && this._contentEl) {
|
|
595
|
-
const a = this._buildGroupsSpec(o),
|
|
596
|
-
this._contentEl.appendChild(
|
|
597
|
-
request_id:
|
|
547
|
+
const a = this._buildGroupsSpec(o), u = this._renderUISpec(a);
|
|
548
|
+
this._contentEl.appendChild(u), A("simrel"), this.track(T(this.analyticsContext(), {
|
|
549
|
+
request_id: g,
|
|
598
550
|
latency_ms: Date.now() - l,
|
|
599
|
-
chunk_count: o.reduce((
|
|
551
|
+
chunk_count: o.reduce((_, E) => _ + E.products.length, 0),
|
|
600
552
|
widget: "simrel"
|
|
601
|
-
})), this.track(
|
|
602
|
-
message_count: o.reduce((
|
|
603
|
-
history_ref:
|
|
553
|
+
})), this.track(w(this.analyticsContext(), {
|
|
554
|
+
message_count: o.reduce((_, E) => _ + E.products.length, 0),
|
|
555
|
+
history_ref: g,
|
|
604
556
|
redaction_level: "none",
|
|
605
557
|
widget: "simrel"
|
|
606
|
-
})), this._emitSimilarProductsImpression(o.reduce((
|
|
558
|
+
})), this._emitSimilarProductsImpression(o.reduce((_, E) => _ + E.products.length, 0), !0);
|
|
607
559
|
return;
|
|
608
560
|
}
|
|
609
561
|
} catch {
|
|
610
562
|
}
|
|
611
|
-
if (this._isSuperseded(
|
|
563
|
+
if (this._isSuperseded(r)) return;
|
|
612
564
|
if (this._contentEl) {
|
|
613
565
|
const y = this._buildProductsSpec(p), b = this._renderUISpec(y);
|
|
614
566
|
this._contentEl.appendChild(b);
|
|
615
567
|
}
|
|
616
|
-
p.length > 0 &&
|
|
617
|
-
request_id:
|
|
568
|
+
p.length > 0 && A("simrel"), this.track(T(this.analyticsContext(), {
|
|
569
|
+
request_id: g,
|
|
618
570
|
latency_ms: Date.now() - l,
|
|
619
571
|
chunk_count: p.length,
|
|
620
572
|
widget: "simrel"
|
|
621
|
-
})), this.track(
|
|
573
|
+
})), this.track(w(this.analyticsContext(), {
|
|
622
574
|
message_count: p.length,
|
|
623
|
-
history_ref:
|
|
575
|
+
history_ref: g,
|
|
624
576
|
redaction_level: "none",
|
|
625
577
|
widget: "simrel"
|
|
626
578
|
})), this._emitSimilarProductsImpression(p.length, !1);
|
|
627
579
|
} catch (m) {
|
|
628
|
-
const p =
|
|
629
|
-
if (p && this._isSuperseded(
|
|
630
|
-
const y = p &&
|
|
631
|
-
if (
|
|
580
|
+
const p = ye(m);
|
|
581
|
+
if (p && this._isSuperseded(r)) return;
|
|
582
|
+
const y = p && n ? "REQUEST_TIMEOUT" : "FETCH_ERROR", b = p && n ? "request_timeout" : m instanceof Error ? m.message : String(m);
|
|
583
|
+
if (S("gengage:global:error", {
|
|
632
584
|
source: "simrel",
|
|
633
585
|
code: y,
|
|
634
|
-
message:
|
|
635
|
-
}), this.track(
|
|
636
|
-
request_id:
|
|
586
|
+
message: W(this.config.locale, m)
|
|
587
|
+
}), this.track(Q(this.analyticsContext(), {
|
|
588
|
+
request_id: g,
|
|
637
589
|
error_code: y,
|
|
638
590
|
error_message: b,
|
|
639
591
|
widget: "simrel"
|
|
@@ -643,10 +595,10 @@ var Le = class extends te {
|
|
|
643
595
|
o.className = "gengage-simrel-error";
|
|
644
596
|
const a = document.createElement("span");
|
|
645
597
|
a.textContent = this._i18n.errorLoadingMessage, o.appendChild(a);
|
|
646
|
-
const
|
|
647
|
-
|
|
598
|
+
const u = document.createElement("button");
|
|
599
|
+
u.className = "gengage-simrel-retry", u.textContent = this._i18n.retryButtonText, u.addEventListener("click", () => {
|
|
648
600
|
this._fetchAndRender(this.config.sku);
|
|
649
|
-
}), o.appendChild(
|
|
601
|
+
}), o.appendChild(u), this._contentEl.appendChild(o);
|
|
650
602
|
}
|
|
651
603
|
} finally {
|
|
652
604
|
clearTimeout(i), h();
|
|
@@ -658,43 +610,43 @@ var Le = class extends te {
|
|
|
658
610
|
}
|
|
659
611
|
_resolveI18n(e) {
|
|
660
612
|
return {
|
|
661
|
-
...
|
|
613
|
+
...fe(e.locale),
|
|
662
614
|
...e.i18n
|
|
663
615
|
};
|
|
664
616
|
}
|
|
665
617
|
_resolveUISpecRegistry() {
|
|
666
|
-
return
|
|
618
|
+
return j(ge(), this.config.renderer?.registry);
|
|
667
619
|
}
|
|
668
620
|
_buildRenderContext() {
|
|
669
621
|
const e = this.config.renderCard, t = {
|
|
670
|
-
onClick: (
|
|
671
|
-
onAddToCart: (
|
|
672
|
-
onGroupingActivate: (
|
|
673
|
-
|
|
674
|
-
grouping_label:
|
|
675
|
-
grouping_index:
|
|
622
|
+
onClick: (n) => this._handleProductClick(n),
|
|
623
|
+
onAddToCart: (n) => this._handleAddToCart(n),
|
|
624
|
+
onGroupingActivate: (n) => {
|
|
625
|
+
S("gengage:similar:grouping-click", {
|
|
626
|
+
grouping_label: n.grouping_label,
|
|
627
|
+
grouping_index: n.grouping_index,
|
|
676
628
|
sessionId: this.config.session?.sessionId ?? null
|
|
677
629
|
});
|
|
678
630
|
},
|
|
679
631
|
i18n: this._i18n
|
|
680
632
|
};
|
|
681
633
|
this.config.discountType !== void 0 && (t.discountType = this.config.discountType), e !== void 0 && (t.renderCard = e), this.config.renderCardElement !== void 0 && (t.renderCardElement = this.config.renderCardElement), this.config.pricing !== void 0 && (t.pricing = this.config.pricing);
|
|
682
|
-
const
|
|
683
|
-
return
|
|
634
|
+
const r = this._clampGridColumns(this.config.gridColumns);
|
|
635
|
+
return r !== void 0 && (t.gridColumns = r), t;
|
|
684
636
|
}
|
|
685
637
|
_renderUISpec(e) {
|
|
686
|
-
const t = this._resolveUISpecRegistry(),
|
|
687
|
-
return s ? s(e,
|
|
638
|
+
const t = this._resolveUISpecRegistry(), r = this._buildRenderContext(), n = this.config.renderer?.unknownRenderer ?? B, i = (c, d) => ue(c, d, t, n), s = this.config.renderer?.renderUISpec;
|
|
639
|
+
return s ? s(e, r, {
|
|
688
640
|
registry: t,
|
|
689
|
-
unknownRenderer:
|
|
641
|
+
unknownRenderer: n,
|
|
690
642
|
defaultRender: i
|
|
691
|
-
}) : i(e,
|
|
643
|
+
}) : i(e, r);
|
|
692
644
|
}
|
|
693
645
|
_buildProductsSpec(e) {
|
|
694
|
-
const t = {},
|
|
646
|
+
const t = {}, r = [];
|
|
695
647
|
for (let s = 0; s < e.length; s++) {
|
|
696
648
|
const c = e[s], d = `product-${s}`;
|
|
697
|
-
|
|
649
|
+
r.push(d), t[d] = {
|
|
698
650
|
type: "ProductCard",
|
|
699
651
|
props: {
|
|
700
652
|
product: c,
|
|
@@ -703,11 +655,11 @@ var Le = class extends te {
|
|
|
703
655
|
}
|
|
704
656
|
};
|
|
705
657
|
}
|
|
706
|
-
const
|
|
707
|
-
return i !== void 0 && (
|
|
658
|
+
const n = { layout: "grid" }, i = this._clampGridColumns(this.config.gridColumns);
|
|
659
|
+
return i !== void 0 && (n.columns = i), t.root = {
|
|
708
660
|
type: "ProductGrid",
|
|
709
|
-
props:
|
|
710
|
-
children:
|
|
661
|
+
props: n,
|
|
662
|
+
children: r
|
|
711
663
|
}, {
|
|
712
664
|
root: "root",
|
|
713
665
|
elements: t
|
|
@@ -723,14 +675,13 @@ var Le = class extends te {
|
|
|
723
675
|
};
|
|
724
676
|
}
|
|
725
677
|
};
|
|
726
|
-
function
|
|
727
|
-
return new
|
|
678
|
+
function Te() {
|
|
679
|
+
return new Ce();
|
|
728
680
|
}
|
|
729
681
|
export {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
Le as t
|
|
682
|
+
ue as a,
|
|
683
|
+
B as i,
|
|
684
|
+
Te as n,
|
|
685
|
+
ge as r,
|
|
686
|
+
Ce as t
|
|
736
687
|
};
|