@gengage/assistant-fe 0.6.50 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat/api.d.ts +1 -1
- package/dist/chat/components/ChatDrawer.d.ts +4 -1
- package/dist/chat/features/beauty-consulting/mode-controller.d.ts +1 -1
- package/dist/chat/features/beauty-consulting/stream-handler.d.ts +7 -1
- package/dist/chat/history-storage.d.ts +36 -4
- package/dist/chat/runtime.d.ts +2 -2
- package/dist/chat/utils/chat-presentation-debug.d.ts +0 -14
- package/dist/chat-runtime.js +1 -1
- package/dist/chat.iife.js +56 -56
- package/dist/chat.js +1 -1
- package/dist/common/connection-warning.d.ts +10 -0
- package/dist/common/indexed-db.d.ts +35 -2
- package/dist/common/native-webview.d.ts +1 -1
- package/dist/common/streaming.d.ts +6 -1
- package/dist/common/transport.d.ts +2 -1
- package/dist/common/types.d.ts +16 -0
- package/dist/{common-DJFI5t11.js → common-CW6814pZ.js} +61 -65
- package/dist/common.js +30 -30
- package/dist/{connection-warning-TXqyeFaf.js → connection-warning-C0e2byq5.js} +31 -25
- package/dist/{fastIntent-539wPavr.js → fastIntent-CJGhUTpS.js} +2 -2
- package/dist/global-error-toast-DvaKvPNA.js +798 -0
- package/dist/index.js +29 -29
- package/dist/native-webview-CHKpwixw.js +303 -0
- package/dist/native.iife.js +27 -27
- package/dist/native.js +1 -1
- package/dist/{overlay-BPZEIyo_.js → overlay-C3XzoSKd.js} +51 -32
- package/dist/overlay.js +6 -6
- package/dist/{price-formatter-CHUmYq8I.js → price-formatter-Q3wUKrl1.js} +2 -1
- package/dist/qna/runtime.d.ts +1 -0
- package/dist/qna-runtime.js +1 -1
- package/dist/qna.iife.js +32 -32
- package/dist/qna.js +1 -1
- package/dist/{request-response-cache-DwADBDeB.js → request-response-cache-DItrp4fO.js} +478 -454
- package/dist/{runtime-9f9SB4WE.js → runtime-B9m0kyTB.js} +2796 -2697
- package/dist/{runtime-Do3qShrH.js → runtime-CZ363BP8.js} +231 -219
- package/dist/{runtime-rTw1jMhB.js → runtime-DKkw_dca.js} +230 -212
- package/dist/{simbut-DlWvDoPI.js → simbut-D_j8YgHS.js} +5 -5
- package/dist/simbut.iife.js +2 -2
- package/dist/simbut.js +1 -1
- package/dist/simrel/components/GroupTabs.d.ts +6 -0
- package/dist/simrel/runtime.d.ts +8 -0
- package/dist/{simrel-BFPU2n5p.js → simrel-BkAtQjNa.js} +15 -15
- package/dist/simrel-runtime.js +1 -1
- package/dist/simrel.iife.js +22 -22
- package/dist/simrel.js +2 -2
- package/dist/widget-base-BnUjuCt7.js +141 -0
- package/package.json +1 -1
- package/dist/context-UTzCGyR9.js +0 -543
- package/dist/native-webview-CYX30O3Q.js +0 -273
- package/dist/widget-base-BwU6SI2o.js +0 -365
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
var
|
|
1
|
+
import { i as ee } from "./widget-base-BnUjuCt7.js";
|
|
2
|
+
var te = ({ element: e, renderElement: t }) => {
|
|
3
3
|
if (!e.children || e.children.length === 0) return null;
|
|
4
4
|
const r = document.createElement("div");
|
|
5
5
|
for (const n of e.children) {
|
|
@@ -8,14 +8,14 @@ var Z = ({ element: e, renderElement: t }) => {
|
|
|
8
8
|
}
|
|
9
9
|
return r;
|
|
10
10
|
};
|
|
11
|
-
function
|
|
11
|
+
function pt(e) {
|
|
12
12
|
const t = document.createElement("div");
|
|
13
13
|
if (t.className = e.containerClassName, !e.spec.elements[e.spec.root]) return t;
|
|
14
|
-
const r = e.unknownRenderer ??
|
|
14
|
+
const r = e.unknownRenderer ?? te, n = (i) => {
|
|
15
15
|
const s = e.spec.elements[i];
|
|
16
16
|
if (!s) return null;
|
|
17
|
-
const
|
|
18
|
-
return
|
|
17
|
+
const a = e.registry[s.type];
|
|
18
|
+
return a ? a({
|
|
19
19
|
elementId: i,
|
|
20
20
|
element: s,
|
|
21
21
|
spec: e.spec,
|
|
@@ -31,38 +31,38 @@ function dt(e) {
|
|
|
31
31
|
}, o = n(e.spec.root);
|
|
32
32
|
return o && t.appendChild(o), t;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function ft(e, t) {
|
|
35
35
|
if (!t) return e;
|
|
36
36
|
const r = { ...e };
|
|
37
37
|
for (const [n, o] of Object.entries(t))
|
|
38
38
|
o && (r[n] = o);
|
|
39
39
|
return r;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function z(e) {
|
|
42
42
|
return typeof e == "object" && e !== null && typeof e.type == "string";
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function re(e) {
|
|
45
45
|
const t = [];
|
|
46
46
|
let r = 0, n = !1, o = !1, i = 0;
|
|
47
47
|
for (let s = 0; s < e.length; s++) {
|
|
48
|
-
const
|
|
48
|
+
const a = e[s];
|
|
49
49
|
if (o) {
|
|
50
50
|
o = !1;
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
53
|
-
if (
|
|
53
|
+
if (a === "\\" && n) {
|
|
54
54
|
o = !0;
|
|
55
55
|
continue;
|
|
56
56
|
}
|
|
57
|
-
if (
|
|
57
|
+
if (a === '"') {
|
|
58
58
|
n = !n;
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
61
|
-
n || (
|
|
61
|
+
n || (a === "{" && r++, a === "}" && (r--, r === 0 && (t.push(e.slice(i, s + 1)), i = s + 1)));
|
|
62
62
|
}
|
|
63
63
|
return t.length > 0 ? t : [e];
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function H(e, t) {
|
|
66
66
|
const r = e.trim();
|
|
67
67
|
if (!r || r.startsWith(":")) return !1;
|
|
68
68
|
const n = r.startsWith("data: ") ? r.slice(6) : r;
|
|
@@ -70,23 +70,25 @@ function M(e, t) {
|
|
|
70
70
|
return t.onDone?.(), !0;
|
|
71
71
|
try {
|
|
72
72
|
const o = JSON.parse(n);
|
|
73
|
-
return
|
|
73
|
+
return z(o) ? (ee("stream", `event: ${o.type}`, o), t.onEvent(o), o.type === "done" ? (t.onDone?.(), !0) : !1) : !1;
|
|
74
74
|
} catch {
|
|
75
|
-
const o =
|
|
76
|
-
if (o.length
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
75
|
+
const o = re(n);
|
|
76
|
+
if (o.length >= 1) {
|
|
77
|
+
let i = !1;
|
|
78
|
+
for (const s of o) try {
|
|
79
|
+
const a = JSON.parse(s);
|
|
80
|
+
if (!z(a)) continue;
|
|
81
|
+
if (i = !0, t.onEvent(a), a.type === "done")
|
|
81
82
|
return t.onDone?.(), !0;
|
|
82
83
|
} catch {
|
|
84
|
+
o.length > 1;
|
|
83
85
|
}
|
|
84
|
-
return !1;
|
|
86
|
+
if (i) return !1;
|
|
85
87
|
}
|
|
86
88
|
return !1;
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
|
-
async function
|
|
91
|
+
async function ne(e, t) {
|
|
90
92
|
if (!e.ok) {
|
|
91
93
|
t.onError?.(/* @__PURE__ */ new Error(`HTTP ${e.status}: ${e.statusText}`));
|
|
92
94
|
return;
|
|
@@ -97,39 +99,43 @@ async function te(e, t) {
|
|
|
97
99
|
}
|
|
98
100
|
const r = e.body.getReader(), n = new TextDecoder("utf-8");
|
|
99
101
|
let o = "";
|
|
100
|
-
const i = t.idleTimeoutMs ??
|
|
101
|
-
let
|
|
102
|
+
const i = t.idleTimeoutMs ?? 12e4, s = /* @__PURE__ */ Symbol("idle-timeout");
|
|
103
|
+
let a = !1;
|
|
102
104
|
try {
|
|
103
105
|
for (; ; ) {
|
|
104
|
-
const
|
|
105
|
-
let
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
})]) :
|
|
109
|
-
if (
|
|
110
|
-
|
|
106
|
+
const c = r.read();
|
|
107
|
+
let u;
|
|
108
|
+
const _ = await (i > 0 ? Promise.race([c.finally(() => clearTimeout(u)), new Promise((y) => {
|
|
109
|
+
u = setTimeout(() => y(s), i);
|
|
110
|
+
})]) : c);
|
|
111
|
+
if (_ === s) {
|
|
112
|
+
a = !0, await r.cancel();
|
|
111
113
|
break;
|
|
112
114
|
}
|
|
113
|
-
const { done:
|
|
114
|
-
if (
|
|
115
|
-
o += n.decode(
|
|
116
|
-
const
|
|
115
|
+
const { done: f, value: d } = _;
|
|
116
|
+
if (f) break;
|
|
117
|
+
o += n.decode(d, { stream: !0 });
|
|
118
|
+
const p = o.split(`
|
|
117
119
|
`);
|
|
118
|
-
o =
|
|
119
|
-
for (const
|
|
120
|
+
o = p.pop() ?? "";
|
|
121
|
+
for (const y of p) if (H(y, t)) return;
|
|
120
122
|
}
|
|
121
|
-
if (o.trim() &&
|
|
123
|
+
if (o += n.decode(), o.trim() && H(o, t))
|
|
122
124
|
return;
|
|
123
|
-
} catch (
|
|
124
|
-
if (
|
|
125
|
-
t.onError?.(
|
|
125
|
+
} catch (c) {
|
|
126
|
+
if (c instanceof DOMException && c.name === "AbortError") return;
|
|
127
|
+
t.onError?.(c instanceof Error ? c : new Error(String(c)));
|
|
126
128
|
} finally {
|
|
127
|
-
|
|
129
|
+
a || r.releaseLock();
|
|
128
130
|
}
|
|
129
131
|
t.onDone?.();
|
|
130
132
|
}
|
|
131
|
-
function
|
|
132
|
-
const n = new AbortController(), o = r.signal ?
|
|
133
|
+
function yt(e, t, r) {
|
|
134
|
+
const n = new AbortController(), o = r.signal ? oe([r.signal, n.signal]) : {
|
|
135
|
+
signal: n.signal,
|
|
136
|
+
cleanup: () => {
|
|
137
|
+
}
|
|
138
|
+
}, i = o.signal;
|
|
133
139
|
return fetch(e, {
|
|
134
140
|
method: "POST",
|
|
135
141
|
headers: {
|
|
@@ -137,125 +143,138 @@ function pt(e, t, r) {
|
|
|
137
143
|
...r.headers
|
|
138
144
|
},
|
|
139
145
|
body: JSON.stringify(t),
|
|
140
|
-
signal:
|
|
141
|
-
}).then((
|
|
146
|
+
signal: i
|
|
147
|
+
}).then((s) => ne(s, {
|
|
142
148
|
...r,
|
|
143
|
-
signal:
|
|
144
|
-
})).catch((
|
|
145
|
-
|
|
146
|
-
}), n;
|
|
149
|
+
signal: i
|
|
150
|
+
})).catch((s) => {
|
|
151
|
+
s instanceof DOMException && s.name === "AbortError" || r.onError?.(s instanceof Error ? s : new Error(String(s)));
|
|
152
|
+
}).finally(() => o.cleanup()), n;
|
|
147
153
|
}
|
|
148
|
-
function
|
|
149
|
-
const t =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
154
|
+
function oe(e) {
|
|
155
|
+
const t = AbortSignal.any;
|
|
156
|
+
if (typeof t == "function") return {
|
|
157
|
+
signal: t(e),
|
|
158
|
+
cleanup: () => {
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const r = new AbortController(), n = [], o = () => {
|
|
162
|
+
for (; n.length > 0; ) n.pop()();
|
|
163
|
+
};
|
|
164
|
+
for (const i of e) {
|
|
165
|
+
if (i.aborted)
|
|
166
|
+
return o(), r.abort(i.reason), {
|
|
167
|
+
signal: r.signal,
|
|
168
|
+
cleanup: () => {
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const s = () => r.abort(i.reason);
|
|
172
|
+
i.addEventListener("abort", s, { once: !0 }), n.push(() => i.removeEventListener("abort", s));
|
|
155
173
|
}
|
|
156
|
-
return
|
|
157
|
-
|
|
158
|
-
|
|
174
|
+
return r.signal.addEventListener("abort", o, { once: !0 }), {
|
|
175
|
+
signal: r.signal,
|
|
176
|
+
cleanup: o
|
|
177
|
+
};
|
|
159
178
|
}
|
|
160
|
-
var
|
|
179
|
+
var G = 3, ie = (e, t) => {
|
|
161
180
|
const r = e.replace(/\s+/g, " ").trim().replace(/^[,.;:!?•-]+|[,.;:!?•-]+$/g, "");
|
|
162
181
|
if (!r) return "";
|
|
163
182
|
const n = t?.stripLeadingStopWords ? r.replace(/^(?:daha|için)\s+/i, "").trim() : r;
|
|
164
183
|
return n ? n.split(/\s+/).slice(0, 3).join(" ").trim() : "";
|
|
165
|
-
},
|
|
166
|
-
function
|
|
167
|
-
const t = (e.display_keywords ?? []).flatMap((o) =>
|
|
168
|
-
if (r.length > 0) return r.slice(0,
|
|
169
|
-
const n = [...
|
|
170
|
-
return n.filter((o, i) => n.indexOf(o) === i).slice(0,
|
|
184
|
+
}, L = (e, t) => e ? e.split(/[•,;:/()]|(?:\sve\s)|(?:\sand\s)|(?:\sile\s)|(?:\sfor\s)|(?:\swith\s)/i).map((r) => ie(r, t)).filter(Boolean) : [];
|
|
185
|
+
function se(e) {
|
|
186
|
+
const t = (e.display_keywords ?? []).flatMap((o) => L(o, { stripLeadingStopWords: !0 })), r = t.filter((o, i) => t.indexOf(o) === i);
|
|
187
|
+
if (r.length > 0) return r.slice(0, G);
|
|
188
|
+
const n = [...L(e.chosen_attribute, { stripLeadingStopWords: !0 }), ...L(e.short_name)];
|
|
189
|
+
return n.filter((o, i) => n.indexOf(o) === i).slice(0, G);
|
|
171
190
|
}
|
|
172
|
-
function
|
|
173
|
-
return
|
|
191
|
+
function ae(e) {
|
|
192
|
+
return se(e).join(" • ");
|
|
174
193
|
}
|
|
175
|
-
function
|
|
194
|
+
function ce(e) {
|
|
176
195
|
return e === "beauty_consulting" || e === "account_expert";
|
|
177
196
|
}
|
|
178
|
-
function
|
|
197
|
+
function C(...e) {
|
|
179
198
|
for (const t of e) {
|
|
180
199
|
if (typeof t != "string") continue;
|
|
181
200
|
const r = t.trim();
|
|
182
201
|
if (r.length > 0) return r;
|
|
183
202
|
}
|
|
184
203
|
}
|
|
185
|
-
function
|
|
204
|
+
function I(e) {
|
|
186
205
|
return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.trim().length > 0).map((t) => t.trim()) : [];
|
|
187
206
|
}
|
|
188
|
-
function
|
|
189
|
-
const t = { ...e }, r =
|
|
207
|
+
function N(e) {
|
|
208
|
+
const t = { ...e }, r = C(t.sku), n = I(t.group_skus);
|
|
190
209
|
if (r ? t.sku = r : delete t.sku, n.length > 0 ? t.group_skus = n : delete t.group_skus, r || n.length > 0) delete t.image_url;
|
|
191
210
|
else {
|
|
192
|
-
const o =
|
|
211
|
+
const o = C(t.image_url);
|
|
193
212
|
o ? t.image_url = o : delete t.image_url;
|
|
194
213
|
}
|
|
195
214
|
return t;
|
|
196
215
|
}
|
|
197
|
-
function
|
|
216
|
+
function gt(e) {
|
|
198
217
|
if (typeof e.type != "string") return null;
|
|
199
|
-
if (
|
|
218
|
+
if (e.payload == null && (e.payload = {}), ue(e)) return e;
|
|
200
219
|
const t = e;
|
|
201
220
|
switch (t.type) {
|
|
202
221
|
case "outputText":
|
|
203
|
-
return
|
|
222
|
+
return le(t);
|
|
204
223
|
case "suggestedActions":
|
|
205
|
-
return ue(t);
|
|
206
|
-
case "productList":
|
|
207
224
|
return de(t);
|
|
225
|
+
case "productList":
|
|
226
|
+
return pe(t);
|
|
208
227
|
case "productDetails":
|
|
209
|
-
return
|
|
228
|
+
return fe(t);
|
|
210
229
|
case "productDetailsSimilars":
|
|
211
|
-
return
|
|
230
|
+
return ye(t);
|
|
212
231
|
case "comparisonTable":
|
|
213
|
-
return
|
|
232
|
+
return ge(t);
|
|
214
233
|
case "context":
|
|
215
|
-
return
|
|
234
|
+
return be(t);
|
|
216
235
|
case "chatStreamEnd":
|
|
217
|
-
return
|
|
236
|
+
return ke();
|
|
218
237
|
case "loading":
|
|
219
|
-
return
|
|
238
|
+
return Ae(t);
|
|
220
239
|
case "panelLoading":
|
|
221
|
-
return ke(t);
|
|
222
|
-
case "similarLoading":
|
|
223
240
|
return Se(t);
|
|
224
|
-
case "
|
|
241
|
+
case "similarLoading":
|
|
225
242
|
return we(t);
|
|
226
|
-
case "
|
|
243
|
+
case "redirect":
|
|
227
244
|
return xe(t);
|
|
245
|
+
case "error":
|
|
246
|
+
return Pe(t);
|
|
228
247
|
case "dummy":
|
|
229
|
-
return
|
|
248
|
+
return Ee(t);
|
|
230
249
|
case "launcherAction":
|
|
231
|
-
return
|
|
250
|
+
return Te(t);
|
|
232
251
|
case "text":
|
|
233
|
-
return
|
|
252
|
+
return B(t);
|
|
234
253
|
case "productItem":
|
|
235
|
-
return
|
|
254
|
+
return Ce(t);
|
|
236
255
|
case "text_image":
|
|
237
|
-
return
|
|
256
|
+
return W(t);
|
|
238
257
|
case "quick_qna":
|
|
239
|
-
return
|
|
258
|
+
return J(t);
|
|
240
259
|
case "reviewHighlights":
|
|
241
|
-
return
|
|
260
|
+
return Ie(t);
|
|
242
261
|
case "aiProductSuggestions":
|
|
243
|
-
return
|
|
262
|
+
return Ne(t);
|
|
244
263
|
case "aiProductGroupings":
|
|
245
|
-
return
|
|
264
|
+
return De(t);
|
|
246
265
|
case "aiSuggestedSearches":
|
|
247
|
-
return
|
|
266
|
+
return Le(t);
|
|
248
267
|
case "getGroundingReview":
|
|
249
|
-
return
|
|
268
|
+
return Oe(t);
|
|
250
269
|
case "voice":
|
|
251
|
-
return
|
|
270
|
+
return qe(t);
|
|
252
271
|
case "uiSpec":
|
|
253
|
-
return
|
|
272
|
+
return $e(t);
|
|
254
273
|
default:
|
|
255
274
|
return null;
|
|
256
275
|
}
|
|
257
276
|
}
|
|
258
|
-
function
|
|
277
|
+
function ue(e) {
|
|
259
278
|
const t = e.type;
|
|
260
279
|
if (typeof t != "string") return !1;
|
|
261
280
|
switch (t) {
|
|
@@ -266,11 +285,11 @@ function ae(e) {
|
|
|
266
285
|
case "ui_spec": {
|
|
267
286
|
const r = e.widget;
|
|
268
287
|
if (r !== "chat" && r !== "qna" && r !== "simrel") return !1;
|
|
269
|
-
const n =
|
|
270
|
-
return n ? typeof n.root == "string" &&
|
|
288
|
+
const n = m(e.spec);
|
|
289
|
+
return n ? typeof n.root == "string" && m(n.elements) !== null : !1;
|
|
271
290
|
}
|
|
272
291
|
case "action": {
|
|
273
|
-
const r =
|
|
292
|
+
const r = m(e.action);
|
|
274
293
|
return r !== null && typeof r.kind == "string";
|
|
275
294
|
}
|
|
276
295
|
case "error":
|
|
@@ -281,7 +300,7 @@ function ae(e) {
|
|
|
281
300
|
return !1;
|
|
282
301
|
}
|
|
283
302
|
}
|
|
284
|
-
function
|
|
303
|
+
function le(e) {
|
|
285
304
|
const t = l(e.payload.text, e.payload.plain_text) ?? "", r = l(e.payload.plain_text, e.payload.text) ?? t;
|
|
286
305
|
if (e.payload.is_error) return {
|
|
287
306
|
type: "error",
|
|
@@ -295,75 +314,77 @@ function ce(e) {
|
|
|
295
314
|
}, o = e.payload.sku_to_product_item;
|
|
296
315
|
o && typeof o == "object" && !Array.isArray(o) && (n.skuToProductItem = o);
|
|
297
316
|
const i = e.payload.product_mentions;
|
|
298
|
-
Array.isArray(i) && i.length > 0 && (n.productMentions = i.map((
|
|
299
|
-
if (typeof
|
|
300
|
-
const
|
|
301
|
-
if (!
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
return typeof
|
|
317
|
+
Array.isArray(i) && i.length > 0 && (n.productMentions = i.map((c) => {
|
|
318
|
+
if (typeof c != "object" || c === null || typeof c.sku != "string") return null;
|
|
319
|
+
const u = typeof c.short_name == "string" ? c.short_name : "";
|
|
320
|
+
if (!u) return null;
|
|
321
|
+
const _ = (typeof c.url == "string" && c.url.trim() ? c.url.trim() : void 0) ?? (() => {
|
|
322
|
+
const f = n.skuToProductItem?.[c.sku];
|
|
323
|
+
return typeof f?.url == "string" && f.url.trim() ? f.url.trim() : void 0;
|
|
305
324
|
})();
|
|
306
|
-
return
|
|
307
|
-
sku:
|
|
308
|
-
short_name:
|
|
309
|
-
url:
|
|
325
|
+
return _ ? {
|
|
326
|
+
sku: c.sku,
|
|
327
|
+
short_name: u,
|
|
328
|
+
url: _
|
|
310
329
|
} : {
|
|
311
|
-
sku:
|
|
312
|
-
short_name:
|
|
330
|
+
sku: c.sku,
|
|
331
|
+
short_name: u
|
|
313
332
|
};
|
|
314
|
-
}).filter((
|
|
333
|
+
}).filter((c) => c !== null));
|
|
315
334
|
const s = e.payload.conversation_mode;
|
|
316
335
|
typeof s == "string" && s && (n.conversationMode = s);
|
|
317
|
-
const
|
|
318
|
-
return typeof
|
|
336
|
+
const a = e.payload.render_hint;
|
|
337
|
+
return typeof a == "string" && a && (n.renderHint = a), e.payload.kvkk === !0 && (n.kvkk = !0), n;
|
|
319
338
|
}
|
|
320
|
-
function
|
|
321
|
-
return
|
|
339
|
+
function de(e) {
|
|
340
|
+
return Q((e.payload.actions ?? []).map((t) => {
|
|
341
|
+
if (!m(t)) return null;
|
|
322
342
|
const r = l(t.title) ?? "", n = k(t.requestDetails, r), o = n ? {
|
|
323
343
|
label: r,
|
|
324
344
|
action: n
|
|
325
345
|
} : null;
|
|
326
346
|
return o ? (typeof t.icon == "string" && (o.icon = t.icon), typeof t.image == "string" && (o.image = t.image), o) : null;
|
|
327
|
-
}).filter(
|
|
347
|
+
}).filter(P), "chat");
|
|
328
348
|
}
|
|
329
|
-
function
|
|
330
|
-
const t = Array.isArray(e.payload.grouped_assignment) ? e.payload.grouped_assignment : [], r = (Array.isArray(e.payload.style_variations) ? e.payload.style_variations : []).map((
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
349
|
+
function pe(e) {
|
|
350
|
+
const t = Array.isArray(e.payload.grouped_assignment) ? e.payload.grouped_assignment : [], r = (Array.isArray(e.payload.style_variations) ? e.payload.style_variations : []).map((a) => {
|
|
351
|
+
if (!m(a)) return null;
|
|
352
|
+
const c = l(a.style_label);
|
|
353
|
+
if (!c) return null;
|
|
354
|
+
const u = l(a.style_mood), _ = l(a.image_url ?? void 0), f = (Array.isArray(a.product_list) ? a.product_list : []).map((p) => {
|
|
355
|
+
const y = m(p);
|
|
356
|
+
return y ? U(m(y.product_detail) ?? m(y.product) ?? y) : null;
|
|
357
|
+
}).filter(P), d = Array.isArray(a.recommendation_groups) ? a.recommendation_groups.map((p) => m(p) ? {
|
|
358
|
+
label: l(p.label) ?? "",
|
|
359
|
+
reason: l(p.reason) ?? "",
|
|
360
|
+
skus: Array.isArray(p.skus) ? p.skus.filter((y) => typeof y == "string" && y.trim().length > 0) : []
|
|
361
|
+
} : null).filter(P) : [];
|
|
341
362
|
return {
|
|
342
|
-
style_label:
|
|
343
|
-
style_mood:
|
|
344
|
-
...
|
|
345
|
-
...typeof
|
|
346
|
-
product_list:
|
|
347
|
-
recommendation_groups:
|
|
363
|
+
style_label: c,
|
|
364
|
+
style_mood: u ?? "",
|
|
365
|
+
..._ ? { image_url: _ } : {},
|
|
366
|
+
...typeof a.status == "string" ? { status: a.status } : {},
|
|
367
|
+
product_list: f,
|
|
368
|
+
recommendation_groups: d
|
|
348
369
|
};
|
|
349
|
-
}).filter(
|
|
370
|
+
}).filter(P), n = e.payload.product_list ?? [], o = ce(e.payload.source) && r.length > 0 ? r[0].product_list : null, i = o ? Be(o, "chat") : t.length > 0 ? je(t, n, "chat") ?? O(n, "chat") : O(n, "chat");
|
|
350
371
|
i.panelHint = "panel";
|
|
351
372
|
const s = i.spec.elements[i.spec.root];
|
|
352
373
|
if (s) {
|
|
353
|
-
const
|
|
354
|
-
typeof e.payload.offset == "number" && (
|
|
355
|
-
const
|
|
356
|
-
typeof
|
|
374
|
+
const a = {};
|
|
375
|
+
typeof e.payload.offset == "number" && (a.offset = e.payload.offset), typeof e.payload.end_of_list == "boolean" && (a.endOfList = e.payload.end_of_list), typeof e.payload.title == "string" && (a.panelTitle = e.payload.title), typeof e.payload.source == "string" && (a.source = e.payload.source), r.length > 0 && (a.styleVariations = r), e.payload.replace_panel === !0 && (a.replacePanel = !0), (e.payload.ranking_state === "pending" || e.payload.ranking_state === "final") && (a.rankingState = e.payload.ranking_state);
|
|
376
|
+
const c = e.payload.sequence_id ?? e.payload.search_id;
|
|
377
|
+
typeof c == "string" && c.length > 0 && (a.sequenceId = c), Object.keys(a).length > 0 && (s.props = {
|
|
357
378
|
...s.props,
|
|
358
|
-
...
|
|
379
|
+
...a
|
|
359
380
|
});
|
|
360
381
|
}
|
|
361
382
|
return i;
|
|
362
383
|
}
|
|
363
|
-
function
|
|
384
|
+
function fe(e) {
|
|
364
385
|
const t = e.payload.productDetails;
|
|
365
|
-
if (!t) return
|
|
366
|
-
const r =
|
|
386
|
+
if (!t) return Ue("chat");
|
|
387
|
+
const r = w(t);
|
|
367
388
|
return {
|
|
368
389
|
type: "ui_spec",
|
|
369
390
|
widget: "chat",
|
|
@@ -380,8 +401,8 @@ function le(e) {
|
|
|
380
401
|
panelHint: "panel"
|
|
381
402
|
};
|
|
382
403
|
}
|
|
383
|
-
function
|
|
384
|
-
const t =
|
|
404
|
+
function ye(e) {
|
|
405
|
+
const t = O(e.payload.similarProducts ?? [], "chat"), r = t.spec.elements[t.spec.root];
|
|
385
406
|
return r && (r.props = {
|
|
386
407
|
...r.props,
|
|
387
408
|
similarsAppend: !0
|
|
@@ -390,7 +411,7 @@ function pe(e) {
|
|
|
390
411
|
panelHint: "panel"
|
|
391
412
|
};
|
|
392
413
|
}
|
|
393
|
-
function
|
|
414
|
+
function ge(e) {
|
|
394
415
|
const t = e.payload.multiple_product_details ?? [], r = e.payload, n = {
|
|
395
416
|
key_differences: r.key_differences,
|
|
396
417
|
recommended_choice: r.recommended_choice,
|
|
@@ -403,80 +424,80 @@ function fe(e) {
|
|
|
403
424
|
winner_hits: r.winner_hits,
|
|
404
425
|
...e.payload.product_comparison_framework ?? {}
|
|
405
426
|
}, o = e.payload.table, i = e.payload.features_list, s = [];
|
|
406
|
-
for (const
|
|
407
|
-
const
|
|
408
|
-
s.push(
|
|
427
|
+
for (const g of t) {
|
|
428
|
+
const b = w(g);
|
|
429
|
+
s.push(b);
|
|
409
430
|
}
|
|
410
|
-
const
|
|
411
|
-
let
|
|
412
|
-
n?.recommended_choice_sku ?
|
|
413
|
-
const
|
|
431
|
+
const a = me(o, s, n, i);
|
|
432
|
+
let c;
|
|
433
|
+
n?.recommended_choice_sku ? c = n.recommended_choice_sku : n?.winner_product && n.winner_product.length > 0 && (c = n.winner_product[0]?.product_detail?.sku ?? n.winner_product[0]?.sku);
|
|
434
|
+
const u = c ? s.find((g) => g.sku === c) ?? s[0] : s[0], _ = [];
|
|
414
435
|
if (Array.isArray(n?.key_differences))
|
|
415
|
-
for (const
|
|
416
|
-
const
|
|
417
|
-
for (const
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
title:
|
|
436
|
+
for (const g of n.key_differences) typeof g == "string" && _.push(g);
|
|
437
|
+
const f = Y(n?.special_considerations), d = n?.recommended_choice, p = n?.winner_hits, y = {};
|
|
438
|
+
for (const g of s) {
|
|
439
|
+
const b = g.sku;
|
|
440
|
+
b && (y[b] = {
|
|
441
|
+
title: g.name ?? b,
|
|
421
442
|
type: "launchSingleProduct",
|
|
422
|
-
payload: { sku:
|
|
443
|
+
payload: { sku: b }
|
|
423
444
|
});
|
|
424
445
|
}
|
|
425
|
-
const
|
|
446
|
+
const h = {
|
|
426
447
|
products: s,
|
|
427
|
-
attributes:
|
|
428
|
-
highlights:
|
|
429
|
-
productActions:
|
|
448
|
+
attributes: a,
|
|
449
|
+
highlights: _,
|
|
450
|
+
productActions: y
|
|
430
451
|
};
|
|
431
|
-
return
|
|
452
|
+
return u && (h.recommended = u), f.length > 0 && (h.specialCases = f), d && (h.recommendedText = d), p && (h.winnerHits = p), typeof n?.key_differences == "string" && (h.keyDifferencesHtml = n.key_differences), n?.special_considerations && (h.specialConsiderations = n.special_considerations), {
|
|
432
453
|
type: "ui_spec",
|
|
433
454
|
widget: "chat",
|
|
434
455
|
spec: {
|
|
435
456
|
root: "root",
|
|
436
457
|
elements: { root: {
|
|
437
458
|
type: "ComparisonTable",
|
|
438
|
-
props:
|
|
459
|
+
props: h
|
|
439
460
|
} }
|
|
440
461
|
},
|
|
441
462
|
panelHint: "panel"
|
|
442
463
|
};
|
|
443
464
|
}
|
|
444
|
-
function
|
|
465
|
+
function me(e, t, r, n) {
|
|
445
466
|
if (!e) return [];
|
|
446
467
|
const o = Object.entries(e);
|
|
447
468
|
if (o.length === 0) return [];
|
|
448
469
|
const i = o[0]?.[1];
|
|
449
470
|
if (Array.isArray(i)) {
|
|
450
|
-
const
|
|
451
|
-
for (const
|
|
452
|
-
const
|
|
453
|
-
if (!
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
label:
|
|
457
|
-
values:
|
|
471
|
+
const d = m(r.criteria_view) ?? m(r.criteria_view_short) ?? {}, p = (Array.isArray(r.compared_field_names) ? r.compared_field_names : []).filter((g) => typeof g == "string"), y = p.length > 0 ? p : Object.keys(e), h = [];
|
|
472
|
+
for (const g of y) {
|
|
473
|
+
const b = e[g];
|
|
474
|
+
if (!b || !Array.isArray(b)) continue;
|
|
475
|
+
const x = d[g], R = typeof x == "string" && x ? x : g;
|
|
476
|
+
h.push({
|
|
477
|
+
label: R,
|
|
478
|
+
values: b.map((v) => typeof v == "string" ? v : String(v ?? ""))
|
|
458
479
|
});
|
|
459
480
|
}
|
|
460
|
-
return
|
|
481
|
+
return h;
|
|
461
482
|
}
|
|
462
|
-
const s = e,
|
|
463
|
-
for (const
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
if (!
|
|
467
|
-
const
|
|
468
|
-
return
|
|
483
|
+
const s = e, a = t.map((d) => String(d.sku ?? "")).filter((d) => d.length > 0), c = m(r.criteria_view) ?? m(r.criteria_view_short) ?? {}, u = (Array.isArray(r.compared_field_names) ? r.compared_field_names : []).filter((d) => typeof d == "string"), _ = (n && n.length > 0 ? n : u.length > 0 ? u : _e(s)).filter((d) => d !== "name" && d !== "name_short" && !d.endsWith("_short")), f = [];
|
|
484
|
+
for (const d of _) {
|
|
485
|
+
const p = a.map((g) => {
|
|
486
|
+
const b = s[g];
|
|
487
|
+
if (!b || typeof b != "object") return "";
|
|
488
|
+
const x = b[`${d}_short`], R = b[d];
|
|
489
|
+
return he(x ?? R);
|
|
469
490
|
});
|
|
470
|
-
if (
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
label:
|
|
474
|
-
values:
|
|
491
|
+
if (p.every((g) => g.length === 0)) continue;
|
|
492
|
+
const y = c[d], h = typeof y == "string" && y ? y : d;
|
|
493
|
+
f.push({
|
|
494
|
+
label: h,
|
|
495
|
+
values: p
|
|
475
496
|
});
|
|
476
497
|
}
|
|
477
|
-
return
|
|
498
|
+
return f;
|
|
478
499
|
}
|
|
479
|
-
function
|
|
500
|
+
function _e(e) {
|
|
480
501
|
const t = [], r = /* @__PURE__ */ new Set();
|
|
481
502
|
for (const n of Object.values(e))
|
|
482
503
|
if (!(!n || typeof n != "object"))
|
|
@@ -484,10 +505,10 @@ function ye(e) {
|
|
|
484
505
|
r.has(o) || (r.add(o), t.push(o));
|
|
485
506
|
return t;
|
|
486
507
|
}
|
|
487
|
-
function
|
|
508
|
+
function he(e) {
|
|
488
509
|
return typeof e == "string" ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : "";
|
|
489
510
|
}
|
|
490
|
-
function
|
|
511
|
+
function be(e) {
|
|
491
512
|
return {
|
|
492
513
|
type: "metadata",
|
|
493
514
|
sessionId: "",
|
|
@@ -499,10 +520,10 @@ function _e(e) {
|
|
|
499
520
|
}
|
|
500
521
|
};
|
|
501
522
|
}
|
|
502
|
-
function
|
|
523
|
+
function ke() {
|
|
503
524
|
return { type: "done" };
|
|
504
525
|
}
|
|
505
|
-
function
|
|
526
|
+
function Ae(e) {
|
|
506
527
|
return {
|
|
507
528
|
type: "metadata",
|
|
508
529
|
sessionId: "",
|
|
@@ -515,7 +536,7 @@ function be(e) {
|
|
|
515
536
|
}
|
|
516
537
|
};
|
|
517
538
|
}
|
|
518
|
-
function
|
|
539
|
+
function Se(e) {
|
|
519
540
|
return {
|
|
520
541
|
type: "metadata",
|
|
521
542
|
sessionId: "",
|
|
@@ -528,7 +549,7 @@ function ke(e) {
|
|
|
528
549
|
}
|
|
529
550
|
};
|
|
530
551
|
}
|
|
531
|
-
function
|
|
552
|
+
function we(e) {
|
|
532
553
|
return {
|
|
533
554
|
type: "metadata",
|
|
534
555
|
sessionId: "",
|
|
@@ -541,7 +562,7 @@ function Se(e) {
|
|
|
541
562
|
}
|
|
542
563
|
};
|
|
543
564
|
}
|
|
544
|
-
function
|
|
565
|
+
function xe(e) {
|
|
545
566
|
const t = l(e.payload.url);
|
|
546
567
|
return t ? {
|
|
547
568
|
type: "action",
|
|
@@ -560,14 +581,14 @@ function we(e) {
|
|
|
560
581
|
}
|
|
561
582
|
};
|
|
562
583
|
}
|
|
563
|
-
function
|
|
584
|
+
function Pe(e) {
|
|
564
585
|
return {
|
|
565
586
|
type: "error",
|
|
566
587
|
code: "BACKEND_ERROR",
|
|
567
588
|
message: l(e.payload?.text, e.payload?.message, e.payload?.error) ?? "Backend returned an error"
|
|
568
589
|
};
|
|
569
590
|
}
|
|
570
|
-
function
|
|
591
|
+
function Ee(e) {
|
|
571
592
|
return {
|
|
572
593
|
type: "metadata",
|
|
573
594
|
sessionId: "",
|
|
@@ -575,27 +596,27 @@ function Ae(e) {
|
|
|
575
596
|
meta: { noop: !0 }
|
|
576
597
|
};
|
|
577
598
|
}
|
|
578
|
-
function
|
|
599
|
+
function Te(e) {
|
|
579
600
|
const t = e.payload ?? {};
|
|
580
601
|
if (Array.isArray(t.action_list)) {
|
|
581
602
|
const o = { action_list: t.action_list }, i = typeof t.type == "string" ? t.type : void 0, s = typeof t.theme == "string" ? t.theme : void 0;
|
|
582
|
-
return i !== void 0 && (o.type = i), s !== void 0 && (o.theme = s),
|
|
603
|
+
return i !== void 0 && (o.type = i), s !== void 0 && (o.theme = s), J({
|
|
583
604
|
type: "quick_qna",
|
|
584
605
|
payload: o
|
|
585
606
|
});
|
|
586
607
|
}
|
|
587
|
-
const r =
|
|
608
|
+
const r = m(t.action);
|
|
588
609
|
if (r) {
|
|
589
|
-
const o = { action: r }, i = typeof t.text == "string" ? t.text : void 0, s = typeof t.image_url == "string" ? t.image_url : void 0,
|
|
590
|
-
return i !== void 0 && (o.text = i), s !== void 0 && (o.image_url = s),
|
|
610
|
+
const o = { action: r }, i = typeof t.text == "string" ? t.text : void 0, s = typeof t.image_url == "string" ? t.image_url : void 0, a = typeof t.theme == "string" ? t.theme : void 0;
|
|
611
|
+
return i !== void 0 && (o.text = i), s !== void 0 && (o.image_url = s), a !== void 0 && (o.theme = a), W({
|
|
591
612
|
type: "text_image",
|
|
592
613
|
payload: o
|
|
593
614
|
});
|
|
594
615
|
}
|
|
595
616
|
const n = typeof t.text == "string" ? t.text : "";
|
|
596
617
|
if (n) {
|
|
597
|
-
const o = { text: n }, i = typeof t.type == "string" ? t.type : void 0, s = typeof t.theme == "string" ? t.theme : void 0,
|
|
598
|
-
return i !== void 0 && (o.type = i),
|
|
618
|
+
const o = { text: n }, i = typeof t.type == "string" ? t.type : void 0, s = typeof t.theme == "string" ? t.theme : void 0, a = m(t.payload) ?? void 0;
|
|
619
|
+
return i !== void 0 && (o.type = i), a !== void 0 && (o.payload = a), s !== void 0 && (o.theme = s), B({
|
|
599
620
|
type: "text",
|
|
600
621
|
payload: o
|
|
601
622
|
});
|
|
@@ -607,7 +628,7 @@ function Pe(e) {
|
|
|
607
628
|
meta: { launcherAction: t }
|
|
608
629
|
};
|
|
609
630
|
}
|
|
610
|
-
function
|
|
631
|
+
function B(e) {
|
|
611
632
|
const t = { text: l(e.payload.text) ?? "" };
|
|
612
633
|
return typeof e.payload.theme == "string" && (t.theme = e.payload.theme), e.payload.payload !== void 0 && (t.payload = e.payload.payload), {
|
|
613
634
|
type: "ui_spec",
|
|
@@ -621,10 +642,10 @@ function O(e) {
|
|
|
621
642
|
}
|
|
622
643
|
};
|
|
623
644
|
}
|
|
624
|
-
function
|
|
625
|
-
return
|
|
645
|
+
function Ce(e) {
|
|
646
|
+
return Me(e.payload, "qna");
|
|
626
647
|
}
|
|
627
|
-
function
|
|
648
|
+
function W(e) {
|
|
628
649
|
const t = l(e.payload.text) ?? "", r = k(e.payload.action, t);
|
|
629
650
|
if (r) {
|
|
630
651
|
const o = {
|
|
@@ -644,25 +665,27 @@ function K(e) {
|
|
|
644
665
|
};
|
|
645
666
|
}
|
|
646
667
|
const n = { text: t };
|
|
647
|
-
return typeof e.payload.theme == "string" && (n.theme = e.payload.theme),
|
|
668
|
+
return typeof e.payload.theme == "string" && (n.theme = e.payload.theme), B({
|
|
648
669
|
type: "text",
|
|
649
670
|
payload: n
|
|
650
671
|
});
|
|
651
672
|
}
|
|
652
|
-
function
|
|
653
|
-
return
|
|
673
|
+
function J(e) {
|
|
674
|
+
return Q((e.payload.action_list ?? []).map((t) => {
|
|
675
|
+
if (!m(t)) return null;
|
|
654
676
|
const r = l(t.title) ?? "", n = k(t.requestDetails, r), o = n ? {
|
|
655
677
|
label: r,
|
|
656
678
|
action: n
|
|
657
679
|
} : null;
|
|
658
680
|
return o ? (typeof t.icon == "string" && (o.icon = t.icon), typeof t.image == "string" && (o.image = t.image), o) : null;
|
|
659
|
-
}).filter(
|
|
681
|
+
}).filter(P), "qna");
|
|
660
682
|
}
|
|
661
|
-
function
|
|
683
|
+
function Ie(e) {
|
|
662
684
|
const t = { reviews: (e.payload.reviews ?? []).map((r) => {
|
|
685
|
+
if (!m(r)) return null;
|
|
663
686
|
const n = {};
|
|
664
687
|
return typeof r.review_class == "string" && (n.review_class = r.review_class), typeof r.review_text == "string" && (n.review_text = r.review_text), (typeof r.review_rating == "string" || typeof r.review_rating == "number") && (n.review_rating = r.review_rating), typeof r.review_tag == "string" && (n.review_tag = r.review_tag), n;
|
|
665
|
-
}) };
|
|
688
|
+
}).filter(P) };
|
|
666
689
|
return typeof e.payload.sku == "string" && (t.sku = e.payload.sku), {
|
|
667
690
|
type: "ui_spec",
|
|
668
691
|
widget: "chat",
|
|
@@ -675,15 +698,15 @@ function Te(e) {
|
|
|
675
698
|
}
|
|
676
699
|
};
|
|
677
700
|
}
|
|
678
|
-
function
|
|
701
|
+
function Ne(e) {
|
|
679
702
|
const t = e.payload.product_suggestions ?? [], r = [];
|
|
680
703
|
for (let n = 0; n < t.length; n++) {
|
|
681
704
|
const o = t[n];
|
|
682
705
|
if (!o) continue;
|
|
683
|
-
const i =
|
|
706
|
+
const i = ze(o);
|
|
684
707
|
if (!i) continue;
|
|
685
|
-
const s = { product: i },
|
|
686
|
-
|
|
708
|
+
const s = { product: i }, a = k(o.requestDetails, i.name);
|
|
709
|
+
a && (s.action = a), typeof o.role == "string" && (s.role = o.role), typeof o.reason == "string" && (s.reason = o.reason), typeof o.review_highlight == "string" && (s.reviewHighlight = o.review_highlight), Array.isArray(o.labels) && (s.labels = o.labels), typeof o.expert_quality_score == "number" && (s.expertQualityScore = o.expert_quality_score), r.push(s);
|
|
687
710
|
}
|
|
688
711
|
return r.length === 0 ? {
|
|
689
712
|
type: "metadata",
|
|
@@ -702,28 +725,28 @@ function Ce(e) {
|
|
|
702
725
|
}
|
|
703
726
|
};
|
|
704
727
|
}
|
|
705
|
-
function
|
|
728
|
+
function De(e) {
|
|
706
729
|
const t = e.payload.product_groupings ?? [], r = [], n = [];
|
|
707
730
|
for (let o = 0; o < t.length; o++) {
|
|
708
731
|
const i = t[o];
|
|
709
732
|
if (!i) continue;
|
|
710
|
-
const s = l(i.name) ?? "",
|
|
711
|
-
const
|
|
712
|
-
return
|
|
713
|
-
}).filter(
|
|
714
|
-
if (s &&
|
|
715
|
-
const
|
|
733
|
+
const s = l(i.name) ?? "", a = l(i.description), c = l(i.highlight), u = Array.isArray(i.labels) ? Y(i.labels) : [], _ = l(i.sku, i.repr_sku), f = l(i.image, i.repr_image), d = Re(i, s, _), p = (Array.isArray(i.group_products) ? i.group_products : []).map((g) => {
|
|
734
|
+
const b = m(g);
|
|
735
|
+
return b ? U(b) : null;
|
|
736
|
+
}).filter(P), y = f ?? l(...p.map((g) => g.imageUrl));
|
|
737
|
+
if (s && p.length > 0) {
|
|
738
|
+
const g = {
|
|
716
739
|
groupName: s,
|
|
717
|
-
products:
|
|
740
|
+
products: p
|
|
718
741
|
};
|
|
719
|
-
|
|
742
|
+
y && (g.image = y), a && (g.description = a), c && (g.highlight = c), u.length > 0 && (g.labels = u), r.push(g);
|
|
720
743
|
}
|
|
721
|
-
if (!
|
|
722
|
-
const
|
|
744
|
+
if (!d) continue;
|
|
745
|
+
const h = {
|
|
723
746
|
name: s,
|
|
724
|
-
action:
|
|
747
|
+
action: d
|
|
725
748
|
};
|
|
726
|
-
|
|
749
|
+
u.length > 0 && (h.labels = u), f !== void 0 && (h.image = f), n.push(h);
|
|
727
750
|
}
|
|
728
751
|
return r.length > 0 ? {
|
|
729
752
|
type: "ui_spec",
|
|
@@ -753,72 +776,72 @@ function Ie(e) {
|
|
|
753
776
|
}
|
|
754
777
|
};
|
|
755
778
|
}
|
|
756
|
-
function
|
|
757
|
-
const n =
|
|
779
|
+
function Re(e, t, r) {
|
|
780
|
+
const n = m(e.requestDetails);
|
|
758
781
|
if (n) {
|
|
759
782
|
if (n.type !== "findSimilar") return k(n, t);
|
|
760
|
-
const s = { ...
|
|
761
|
-
r && !
|
|
762
|
-
const
|
|
763
|
-
return
|
|
783
|
+
const s = { ...m(n.payload) ?? {} };
|
|
784
|
+
r && !C(s.sku) && (s.sku = r);
|
|
785
|
+
const a = I(e.group_skus);
|
|
786
|
+
return a.length > 0 && (s.group_skus = a), k({
|
|
764
787
|
...n,
|
|
765
|
-
payload:
|
|
788
|
+
payload: N(s)
|
|
766
789
|
}, t);
|
|
767
790
|
}
|
|
768
791
|
const o = {};
|
|
769
792
|
r && (o.sku = r);
|
|
770
|
-
const i =
|
|
793
|
+
const i = I(e.group_skus);
|
|
771
794
|
return i.length > 0 && (o.group_skus = i), Object.keys(o).length === 0 ? null : k({
|
|
772
795
|
type: "findSimilar",
|
|
773
|
-
payload:
|
|
796
|
+
payload: N(o)
|
|
774
797
|
}, t);
|
|
775
798
|
}
|
|
776
|
-
function
|
|
777
|
-
const r =
|
|
799
|
+
function ve(e, t) {
|
|
800
|
+
const r = m(e.requestDetails), n = m(r?.payload), o = l(e.detailed_user_message), i = e.group_skus && Array.isArray(e.group_skus) ? I(e.group_skus) : I(n?.group_skus), s = l(e.sku, e.representative_product_sku, n?.sku);
|
|
778
801
|
if (r?.type === "findSimilar") {
|
|
779
|
-
const
|
|
780
|
-
return s && (
|
|
802
|
+
const c = { ...n ?? {} };
|
|
803
|
+
return s && (c.sku = s), i.length > 0 && (c.group_skus = i), o && (c.input = o, C(c.text) || (c.text = o)), c.is_search_suggestion = 1, k({
|
|
781
804
|
...r,
|
|
782
|
-
payload:
|
|
805
|
+
payload: N(c)
|
|
783
806
|
}, t);
|
|
784
807
|
}
|
|
785
808
|
if (s) {
|
|
786
|
-
const
|
|
809
|
+
const c = {
|
|
787
810
|
sku: s,
|
|
788
811
|
is_search_suggestion: 1
|
|
789
812
|
};
|
|
790
|
-
return i.length > 0 && (
|
|
813
|
+
return i.length > 0 && (c.group_skus = i), o && (c.input = o, c.text = o), k({
|
|
791
814
|
type: "findSimilar",
|
|
792
|
-
payload:
|
|
815
|
+
payload: N(c)
|
|
793
816
|
}, t);
|
|
794
817
|
}
|
|
795
|
-
const
|
|
818
|
+
const a = {
|
|
796
819
|
...n ?? {},
|
|
797
820
|
is_suggested_text: 1,
|
|
798
821
|
is_search_suggestion: 1
|
|
799
822
|
};
|
|
800
|
-
return o && !
|
|
823
|
+
return o && !C(a.text) && (a.text = o), i.length > 0 && (a.group_skus = i), k(r?.type === "inputText" ? {
|
|
801
824
|
...r,
|
|
802
|
-
payload:
|
|
825
|
+
payload: a
|
|
803
826
|
} : {
|
|
804
827
|
type: "inputText",
|
|
805
|
-
payload:
|
|
828
|
+
payload: a
|
|
806
829
|
}, t);
|
|
807
830
|
}
|
|
808
|
-
function
|
|
831
|
+
function Le(e) {
|
|
809
832
|
const t = e.payload.suggested_searches ?? [], r = [];
|
|
810
833
|
for (let n = 0; n < t.length; n++) {
|
|
811
834
|
const o = t[n];
|
|
812
835
|
if (!o) continue;
|
|
813
|
-
const i = l(o.short_name, o.chosen_attribute, o.detailed_user_message) ?? `Search ${n + 1}`, s =
|
|
836
|
+
const i = l(o.short_name, o.chosen_attribute, o.detailed_user_message) ?? `Search ${n + 1}`, s = ve(o, i);
|
|
814
837
|
if (!s) continue;
|
|
815
|
-
const
|
|
838
|
+
const a = {
|
|
816
839
|
shortName: i,
|
|
817
840
|
action: s
|
|
818
|
-
},
|
|
819
|
-
|
|
820
|
-
const
|
|
821
|
-
|
|
841
|
+
}, c = l(o.detailed_user_message);
|
|
842
|
+
c && c !== i && (a.detailedMessage = c);
|
|
843
|
+
const u = ae(o);
|
|
844
|
+
u && u !== i && u !== (c ?? "") && (a.whyDifferent = u), typeof o.image == "string" && (a.image = o.image), r.push(a);
|
|
822
845
|
}
|
|
823
846
|
return r.length === 0 ? {
|
|
824
847
|
type: "metadata",
|
|
@@ -837,7 +860,7 @@ function Re(e) {
|
|
|
837
860
|
}
|
|
838
861
|
};
|
|
839
862
|
}
|
|
840
|
-
function
|
|
863
|
+
function Oe(e) {
|
|
841
864
|
const t = e.payload, r = k(t.requestDetails ?? t.request_details, l(t.review_count, t.reviewCount, t.text, t.title) ?? "Show product reviews");
|
|
842
865
|
if (!r) return {
|
|
843
866
|
type: "metadata",
|
|
@@ -858,7 +881,7 @@ function ve(e) {
|
|
|
858
881
|
}
|
|
859
882
|
};
|
|
860
883
|
}
|
|
861
|
-
function
|
|
884
|
+
function qe(e) {
|
|
862
885
|
return {
|
|
863
886
|
type: "metadata",
|
|
864
887
|
sessionId: "",
|
|
@@ -866,7 +889,7 @@ function Le(e) {
|
|
|
866
889
|
meta: { voice: e.payload }
|
|
867
890
|
};
|
|
868
891
|
}
|
|
869
|
-
function
|
|
892
|
+
function M(e, t) {
|
|
870
893
|
const r = {
|
|
871
894
|
product: e,
|
|
872
895
|
index: t
|
|
@@ -880,20 +903,20 @@ function q(e, t) {
|
|
|
880
903
|
props: r
|
|
881
904
|
};
|
|
882
905
|
}
|
|
883
|
-
function
|
|
906
|
+
function Q(e, t) {
|
|
884
907
|
const r = {}, n = [];
|
|
885
908
|
for (let o = 0; o < e.length; o++) {
|
|
886
909
|
const i = e[o];
|
|
887
910
|
if (!i) continue;
|
|
888
911
|
const s = `action-${o}`;
|
|
889
912
|
n.push(s);
|
|
890
|
-
const
|
|
913
|
+
const a = {
|
|
891
914
|
label: i.label,
|
|
892
915
|
action: i.action
|
|
893
916
|
};
|
|
894
|
-
i.icon !== void 0 && (
|
|
917
|
+
i.icon !== void 0 && (a.icon = i.icon), i.image !== void 0 && (a.image = i.image), i.description !== void 0 && (a.description = i.description), r[s] = {
|
|
895
918
|
type: "ActionButton",
|
|
896
|
-
props:
|
|
919
|
+
props: a
|
|
897
920
|
};
|
|
898
921
|
}
|
|
899
922
|
return r.root = {
|
|
@@ -915,13 +938,13 @@ function V(e, t) {
|
|
|
915
938
|
}
|
|
916
939
|
};
|
|
917
940
|
}
|
|
918
|
-
function
|
|
941
|
+
function O(e, t) {
|
|
919
942
|
const r = {}, n = [];
|
|
920
943
|
for (let o = 0; o < e.length; o++) {
|
|
921
944
|
const i = e[o];
|
|
922
945
|
if (!i) continue;
|
|
923
|
-
const s =
|
|
924
|
-
n.push(
|
|
946
|
+
const s = w(i), a = `product-${o}`;
|
|
947
|
+
n.push(a), r[a] = M(s, o);
|
|
925
948
|
}
|
|
926
949
|
return r.root = {
|
|
927
950
|
type: "ProductGrid",
|
|
@@ -936,34 +959,34 @@ function R(e, t) {
|
|
|
936
959
|
}
|
|
937
960
|
};
|
|
938
961
|
}
|
|
939
|
-
function
|
|
962
|
+
function je(e, t, r) {
|
|
940
963
|
const n = /* @__PURE__ */ new Map();
|
|
941
|
-
for (const
|
|
942
|
-
|
|
964
|
+
for (const u of t)
|
|
965
|
+
u?.sku && n.set(u.sku, u);
|
|
943
966
|
if (n.size === 0) return null;
|
|
944
|
-
const o = /* @__PURE__ */ new Set(), i = {}, s = [],
|
|
945
|
-
let
|
|
946
|
-
for (let
|
|
947
|
-
const
|
|
948
|
-
for (let
|
|
949
|
-
const
|
|
950
|
-
if (!
|
|
951
|
-
const
|
|
952
|
-
if (!
|
|
953
|
-
o.add(
|
|
954
|
-
const
|
|
955
|
-
s.push(
|
|
967
|
+
const o = /* @__PURE__ */ new Set(), i = {}, s = [], a = [];
|
|
968
|
+
let c = 0;
|
|
969
|
+
for (let u = 0; u < e.length; u++) {
|
|
970
|
+
const _ = e[u], f = l(_?.title) ?? "", d = Array.isArray(_?.skus) ? _.skus : [], p = [];
|
|
971
|
+
for (let y = 0; y < d.length; y++) {
|
|
972
|
+
const h = typeof d[y] == "string" ? d[y].trim() : "";
|
|
973
|
+
if (!h || o.has(h)) continue;
|
|
974
|
+
const g = n.get(h);
|
|
975
|
+
if (!g) continue;
|
|
976
|
+
o.add(h);
|
|
977
|
+
const b = `product-${u}-${y}`, x = w(g);
|
|
978
|
+
s.push(b), p.push(b), i[b] = M(x, c), c += 1;
|
|
956
979
|
}
|
|
957
|
-
|
|
958
|
-
title:
|
|
959
|
-
children:
|
|
980
|
+
p.length > 0 && a.push({
|
|
981
|
+
title: f,
|
|
982
|
+
children: p
|
|
960
983
|
});
|
|
961
984
|
}
|
|
962
|
-
return
|
|
985
|
+
return a.length === 0 || o.size < n.size ? null : (i.root = {
|
|
963
986
|
type: "ProductGrid",
|
|
964
987
|
props: {
|
|
965
988
|
layout: "grouped",
|
|
966
|
-
productSections:
|
|
989
|
+
productSections: a
|
|
967
990
|
},
|
|
968
991
|
children: s
|
|
969
992
|
}, {
|
|
@@ -975,13 +998,13 @@ function Oe(e, t, r) {
|
|
|
975
998
|
}
|
|
976
999
|
});
|
|
977
1000
|
}
|
|
978
|
-
function
|
|
1001
|
+
function Be(e, t) {
|
|
979
1002
|
const r = {}, n = [];
|
|
980
1003
|
for (let o = 0; o < e.length; o++) {
|
|
981
1004
|
const i = e[o];
|
|
982
1005
|
if (!i) continue;
|
|
983
1006
|
const s = `product-${o}`;
|
|
984
|
-
n.push(s), r[s] =
|
|
1007
|
+
n.push(s), r[s] = M(i, o);
|
|
985
1008
|
}
|
|
986
1009
|
return r.root = {
|
|
987
1010
|
type: "ProductGrid",
|
|
@@ -996,7 +1019,7 @@ function qe(e, t) {
|
|
|
996
1019
|
}
|
|
997
1020
|
};
|
|
998
1021
|
}
|
|
999
|
-
function
|
|
1022
|
+
function Me(e, t) {
|
|
1000
1023
|
return {
|
|
1001
1024
|
type: "ui_spec",
|
|
1002
1025
|
widget: t,
|
|
@@ -1005,14 +1028,14 @@ function je(e, t) {
|
|
|
1005
1028
|
elements: { root: {
|
|
1006
1029
|
type: "ProductCard",
|
|
1007
1030
|
props: {
|
|
1008
|
-
product:
|
|
1031
|
+
product: w(e),
|
|
1009
1032
|
index: 0
|
|
1010
1033
|
}
|
|
1011
1034
|
} }
|
|
1012
1035
|
}
|
|
1013
1036
|
};
|
|
1014
1037
|
}
|
|
1015
|
-
function
|
|
1038
|
+
function Ue(e) {
|
|
1016
1039
|
return {
|
|
1017
1040
|
type: "ui_spec",
|
|
1018
1041
|
widget: e,
|
|
@@ -1026,11 +1049,11 @@ function Be(e) {
|
|
|
1026
1049
|
}
|
|
1027
1050
|
};
|
|
1028
1051
|
}
|
|
1029
|
-
function
|
|
1030
|
-
const t = l(e.sku), r = l(e.short_name), n = { ...
|
|
1031
|
-
return o && !l(n.discount_reason, n.discountReason) && (n.discount_reason = o),
|
|
1052
|
+
function ze(e) {
|
|
1053
|
+
const t = l(e.sku), r = l(e.short_name), n = { ...m(e.product_item) ?? e }, o = l(e.discount_reason, e.discountReason);
|
|
1054
|
+
return o && !l(n.discount_reason, n.discountReason) && (n.discount_reason = o), U(n, t, r);
|
|
1032
1055
|
}
|
|
1033
|
-
function
|
|
1056
|
+
function U(e, t, r) {
|
|
1034
1057
|
const n = l(e.sku, t), o = l(e.name, r);
|
|
1035
1058
|
if (!n || !o) return null;
|
|
1036
1059
|
const i = {
|
|
@@ -1038,29 +1061,29 @@ function j(e, t, r) {
|
|
|
1038
1061
|
name: o
|
|
1039
1062
|
}, s = l(e.brand);
|
|
1040
1063
|
s && (i.brand = s);
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1043
|
-
const
|
|
1044
|
-
if (
|
|
1064
|
+
const a = l(e.url);
|
|
1065
|
+
a && (i.url = a);
|
|
1066
|
+
const c = He(e.images);
|
|
1067
|
+
if (c.length > 0) i.images = c;
|
|
1045
1068
|
else {
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1069
|
+
const h = l(e.image, e.image_url, e.imageUrl);
|
|
1070
|
+
h && (i.images = [h]);
|
|
1048
1071
|
}
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1051
|
-
const
|
|
1052
|
-
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1055
|
-
const
|
|
1056
|
-
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
const
|
|
1060
|
-
return
|
|
1072
|
+
const u = E(e.price_discounted);
|
|
1073
|
+
u !== void 0 && (i.price_discounted = u);
|
|
1074
|
+
const _ = E(e.price);
|
|
1075
|
+
_ !== void 0 && (i.price = _);
|
|
1076
|
+
const f = E(e.rating);
|
|
1077
|
+
f !== void 0 && (i.rating = f);
|
|
1078
|
+
const d = E(e.review_count) ?? E(e.reviewCount);
|
|
1079
|
+
d !== void 0 && (i.review_count = d);
|
|
1080
|
+
const p = l(e.cart_code, e.cartCode);
|
|
1081
|
+
p && (i.cart_code = p), typeof e.in_stock == "boolean" && (i.in_stock = e.in_stock), typeof e.inStock == "boolean" && (i.in_stock = e.inStock);
|
|
1082
|
+
const y = l(e.discount_reason, e.discountReason);
|
|
1083
|
+
return y && (i.discount_reason = y), w(i);
|
|
1061
1084
|
}
|
|
1062
1085
|
function k(e, t) {
|
|
1063
|
-
const r =
|
|
1086
|
+
const r = m(e);
|
|
1064
1087
|
if (!r) return null;
|
|
1065
1088
|
const n = r.type;
|
|
1066
1089
|
if (typeof n != "string" || n.length === 0) return null;
|
|
@@ -1070,7 +1093,7 @@ function k(e, t) {
|
|
|
1070
1093
|
};
|
|
1071
1094
|
return r.payload !== void 0 && (o.payload = r.payload), o;
|
|
1072
1095
|
}
|
|
1073
|
-
function
|
|
1096
|
+
function m(e) {
|
|
1074
1097
|
return !e || typeof e != "object" || Array.isArray(e) ? null : e;
|
|
1075
1098
|
}
|
|
1076
1099
|
function l(...e) {
|
|
@@ -1079,29 +1102,30 @@ function l(...e) {
|
|
|
1079
1102
|
if (r.length > 0) return r;
|
|
1080
1103
|
}
|
|
1081
1104
|
}
|
|
1082
|
-
function
|
|
1105
|
+
function He(e) {
|
|
1083
1106
|
return Array.isArray(e) ? e.filter((t) => typeof t == "string" && t.length > 0) : [];
|
|
1084
1107
|
}
|
|
1085
|
-
function
|
|
1108
|
+
function Y(e) {
|
|
1086
1109
|
if (typeof e == "string") {
|
|
1087
1110
|
const t = e.trim();
|
|
1088
1111
|
return t ? [t] : [];
|
|
1089
1112
|
}
|
|
1090
1113
|
return Array.isArray(e) ? e.filter((t) => typeof t == "string").map((t) => t.trim()).filter((t) => t.length > 0) : [];
|
|
1091
1114
|
}
|
|
1092
|
-
function
|
|
1115
|
+
function E(e) {
|
|
1093
1116
|
if (typeof e == "number" && Number.isFinite(e)) return e;
|
|
1094
1117
|
if (typeof e == "string") {
|
|
1118
|
+
if (!e.trim()) return;
|
|
1095
1119
|
let t;
|
|
1096
1120
|
e.includes(".") && e.includes(",") ? t = e.replace(/\./g, "").replace(",", ".") : t = e.replace(",", ".");
|
|
1097
1121
|
const r = Number(t);
|
|
1098
1122
|
if (Number.isFinite(r)) return r;
|
|
1099
1123
|
}
|
|
1100
1124
|
}
|
|
1101
|
-
function
|
|
1125
|
+
function P(e) {
|
|
1102
1126
|
return e != null;
|
|
1103
1127
|
}
|
|
1104
|
-
var
|
|
1128
|
+
var Ge = /* @__PURE__ */ new Set([
|
|
1105
1129
|
"sku",
|
|
1106
1130
|
"name",
|
|
1107
1131
|
"brand",
|
|
@@ -1127,102 +1151,102 @@ var ze = /* @__PURE__ */ new Set([
|
|
|
1127
1151
|
"facet_hits",
|
|
1128
1152
|
"promotions"
|
|
1129
1153
|
]);
|
|
1130
|
-
function
|
|
1154
|
+
function w(e) {
|
|
1131
1155
|
const t = e.price_discounted != null && e.price_discounted > 0, r = t ? e.price_discounted : e.price, n = t && e.price != null ? e.price : void 0;
|
|
1132
1156
|
let o;
|
|
1133
1157
|
n != null && r != null && n > 0 ? o = Math.round((n - r) / n * 100) : e.price_discount_rate != null && e.price_discount_rate > 0 && (o = e.price_discount_rate);
|
|
1134
|
-
const i = l(e.brand), s = l(e.name) ?? e.sku,
|
|
1158
|
+
const i = l(e.brand), s = l(e.name) ?? e.sku, a = i && !s.toLowerCase().startsWith(i.toLowerCase()) ? `${i} ${s}` : s, c = {
|
|
1135
1159
|
sku: e.sku,
|
|
1136
|
-
name:
|
|
1160
|
+
name: a,
|
|
1137
1161
|
url: l(e.url) ?? ""
|
|
1138
|
-
},
|
|
1139
|
-
|
|
1140
|
-
const
|
|
1141
|
-
let
|
|
1142
|
-
for (const
|
|
1143
|
-
return
|
|
1144
|
-
}
|
|
1145
|
-
function
|
|
1146
|
-
return e.results.map(
|
|
1147
|
-
}
|
|
1148
|
-
function
|
|
1149
|
-
return e.product_groupings.map((t) => {
|
|
1150
|
-
const r = {
|
|
1162
|
+
}, u = e.images?.[0];
|
|
1163
|
+
u && (c.imageUrl = u), e.images && e.images.length > 1 && (c.images = e.images), r != null && r > 0 && (c.price = String(r)), o !== void 0 && o > 0 && (c.discountPercent = o, n != null && n > 0 && (c.originalPrice = String(n))), i !== void 0 && (c.brand = i), e.rating !== void 0 && (c.rating = e.rating), e.review_count !== void 0 && (c.reviewCount = e.review_count), e.cart_code !== void 0 && (c.cartCode = e.cart_code), e.in_stock !== void 0 && (c.inStock = e.in_stock), e.variants && e.variants.length > 0 && (c.variants = e.variants), e.discount_reason !== void 0 && (c.discountReason = e.discount_reason), e.promotions && e.promotions.length > 0 && (c.promotions = e.promotions), e.description !== void 0 && (c.description = e.description), e.description_html !== void 0 && (c.descriptionHtml = e.description_html), e.features && e.features.length > 0 && (c.features = e.features), e.specifications !== void 0 && (c.specifications = e.specifications), e.facet_hits && (c.facetHits = e.facet_hits), e.category_names && e.category_names.length > 0 && (c.categoryNames = e.category_names), e.short_name !== void 0 && (c.shortName = e.short_name);
|
|
1164
|
+
const _ = e, f = {};
|
|
1165
|
+
let d = !1;
|
|
1166
|
+
for (const p of Object.keys(_)) Ge.has(p) || (f[p] = _[p], d = !0);
|
|
1167
|
+
return d && (c.extras = f), c;
|
|
1168
|
+
}
|
|
1169
|
+
function mt(e) {
|
|
1170
|
+
return (Array.isArray(e?.results) ? e.results : []).filter((t) => m(t) !== null).map(w);
|
|
1171
|
+
}
|
|
1172
|
+
function _t(e) {
|
|
1173
|
+
return (Array.isArray(e?.product_groupings) ? e.product_groupings : []).filter((t) => m(t) !== null).map((t) => {
|
|
1174
|
+
const r = Array.isArray(t.group_products) ? t.group_products : [], n = {
|
|
1151
1175
|
name: t.name,
|
|
1152
|
-
products: (
|
|
1176
|
+
products: r.filter((o) => m(o) !== null).map(w)
|
|
1153
1177
|
};
|
|
1154
|
-
return t.highlight !== void 0 && (
|
|
1178
|
+
return t.highlight !== void 0 && (n.highlight = t.highlight), n;
|
|
1155
1179
|
});
|
|
1156
1180
|
}
|
|
1157
|
-
function
|
|
1158
|
-
const t = e.payload.type, { type:
|
|
1181
|
+
function $e(e) {
|
|
1182
|
+
const t = m(e.payload) ?? {}, r = typeof t.type == "string" ? t.type : "", { type: n, ...o } = t;
|
|
1159
1183
|
return {
|
|
1160
1184
|
type: "ui_spec",
|
|
1161
1185
|
widget: "chat",
|
|
1162
1186
|
spec: {
|
|
1163
1187
|
root: "root",
|
|
1164
1188
|
elements: { root: {
|
|
1165
|
-
type:
|
|
1166
|
-
props:
|
|
1189
|
+
type: r,
|
|
1190
|
+
props: o
|
|
1167
1191
|
} }
|
|
1168
1192
|
}
|
|
1169
1193
|
};
|
|
1170
1194
|
}
|
|
1171
|
-
var
|
|
1195
|
+
var Ke = {
|
|
1172
1196
|
process_action: "/process_action",
|
|
1173
1197
|
launcher_action: "/launcher_action",
|
|
1174
1198
|
similar_products: "/similar_products",
|
|
1175
1199
|
product_groupings: "/product_groupings"
|
|
1176
1200
|
};
|
|
1177
|
-
function
|
|
1201
|
+
function Fe(e) {
|
|
1178
1202
|
if (e === void 0) throw new Error("[gengage] middlewareUrl is required. Pass your Gengage backend URL in widget config.");
|
|
1179
1203
|
const t = e.trim();
|
|
1180
1204
|
return t === "" ? "" : t.replace(/\/+$/, "");
|
|
1181
1205
|
}
|
|
1182
|
-
function
|
|
1183
|
-
return `${
|
|
1206
|
+
function ht(e, t) {
|
|
1207
|
+
return `${Fe(t?.middlewareUrl)}/chat${Ke[e]}`;
|
|
1184
1208
|
}
|
|
1185
|
-
var
|
|
1186
|
-
async function
|
|
1187
|
-
const n =
|
|
1209
|
+
var Ve = 7200 * 1e3, X = 200, We = 5 * 1024 * 1024, Je = "gengage_request_response_cache", Qe = 1, S = "responses", Ye = /* @__PURE__ */ new Set(["addToCart", "like"]), A = /* @__PURE__ */ new Map(), $ = null;
|
|
1210
|
+
async function bt(e, t = {}, r = {}) {
|
|
1211
|
+
const n = Xe(e, t);
|
|
1188
1212
|
if (!n) return fetch(e, t);
|
|
1189
|
-
const o = Date.now(), i = await
|
|
1190
|
-
if (i) return
|
|
1213
|
+
const o = Date.now(), i = await rt(n, o);
|
|
1214
|
+
if (i) return it(i);
|
|
1191
1215
|
const s = await fetch(e, t);
|
|
1192
|
-
return s.ok &&
|
|
1193
|
-
ttlMs: r.ttlMs ??
|
|
1194
|
-
maxEntries: r.maxEntries ??
|
|
1195
|
-
maxBodyBytes: r.maxBodyBytes ??
|
|
1216
|
+
return s.ok && nt(n, s.clone(), o, {
|
|
1217
|
+
ttlMs: r.ttlMs ?? Ve,
|
|
1218
|
+
maxEntries: r.maxEntries ?? X,
|
|
1219
|
+
maxBodyBytes: r.maxBodyBytes ?? We
|
|
1196
1220
|
}), s;
|
|
1197
1221
|
}
|
|
1198
|
-
function
|
|
1222
|
+
function Xe(e, t = {}) {
|
|
1199
1223
|
if (typeof Request < "u" && e instanceof Request) return null;
|
|
1200
1224
|
const r = String(t.method || "GET").toUpperCase();
|
|
1201
1225
|
if (r !== "POST" || typeof t.body != "string") return null;
|
|
1202
|
-
const n =
|
|
1203
|
-
if (
|
|
1204
|
-
const o =
|
|
1226
|
+
const n = Ze(t.body);
|
|
1227
|
+
if (et(n)) return null;
|
|
1228
|
+
const o = tt(n);
|
|
1205
1229
|
if (o) {
|
|
1206
|
-
const i =
|
|
1207
|
-
return `rr:${
|
|
1230
|
+
const i = T(n?.action);
|
|
1231
|
+
return `rr:${V(F({
|
|
1208
1232
|
url: String(e),
|
|
1209
1233
|
method: r,
|
|
1210
|
-
headers:
|
|
1234
|
+
headers: K(t.headers),
|
|
1211
1235
|
type: n?.type ?? i?.type ?? "",
|
|
1212
1236
|
account_id: n?.account_id ?? n?.accountId ?? "",
|
|
1213
1237
|
locale: n?.locale ?? "",
|
|
1214
|
-
outputLanguage:
|
|
1238
|
+
outputLanguage: T(n?.meta)?.outputLanguage ?? "",
|
|
1215
1239
|
cache_key: o
|
|
1216
1240
|
}))}`;
|
|
1217
1241
|
}
|
|
1218
|
-
return `rr:${
|
|
1242
|
+
return `rr:${V(F({
|
|
1219
1243
|
url: String(e),
|
|
1220
1244
|
method: r,
|
|
1221
|
-
headers:
|
|
1245
|
+
headers: K(t.headers),
|
|
1222
1246
|
body: t.body
|
|
1223
1247
|
}))}`;
|
|
1224
1248
|
}
|
|
1225
|
-
function
|
|
1249
|
+
function Ze(e) {
|
|
1226
1250
|
try {
|
|
1227
1251
|
const t = JSON.parse(e);
|
|
1228
1252
|
return !t || typeof t != "object" || Array.isArray(t) ? null : t;
|
|
@@ -1230,150 +1254,150 @@ function Ye(e) {
|
|
|
1230
1254
|
return null;
|
|
1231
1255
|
}
|
|
1232
1256
|
}
|
|
1233
|
-
function
|
|
1257
|
+
function et(e) {
|
|
1234
1258
|
const t = e?.type;
|
|
1235
|
-
return typeof t == "string" &&
|
|
1259
|
+
return typeof t == "string" && Ye.has(t);
|
|
1236
1260
|
}
|
|
1237
|
-
function
|
|
1238
|
-
const t = (
|
|
1261
|
+
function tt(e) {
|
|
1262
|
+
const t = (T(e?.payload) ?? T(T(e?.action)?.payload))?.cache_key;
|
|
1239
1263
|
return typeof t == "string" && t.trim().length > 0 ? t.trim() : null;
|
|
1240
1264
|
}
|
|
1241
|
-
async function
|
|
1242
|
-
const r =
|
|
1243
|
-
if (r) if (r.expiresAt <= t)
|
|
1265
|
+
async function rt(e, t) {
|
|
1266
|
+
const r = A.get(e);
|
|
1267
|
+
if (r) if (r.expiresAt <= t) A.delete(e);
|
|
1244
1268
|
else
|
|
1245
|
-
return r.lastAccessedAt = t,
|
|
1246
|
-
const n = await
|
|
1247
|
-
return n ? n.expiresAt <= t ? (
|
|
1269
|
+
return r.lastAccessedAt = t, A.delete(e), A.set(e, r), q(r), r;
|
|
1270
|
+
const n = await at(e);
|
|
1271
|
+
return n ? n.expiresAt <= t ? (A.delete(e), ct(e), null) : (n.lastAccessedAt = t, A.set(e, n), q(n), Z(X), n) : null;
|
|
1248
1272
|
}
|
|
1249
|
-
async function
|
|
1273
|
+
async function nt(e, t, r, n) {
|
|
1250
1274
|
try {
|
|
1251
1275
|
const o = await t.text();
|
|
1252
|
-
if (
|
|
1276
|
+
if (lt(o) > n.maxBodyBytes || ot(o)) return;
|
|
1253
1277
|
const i = {
|
|
1254
1278
|
key: e,
|
|
1255
1279
|
status: t.status,
|
|
1256
1280
|
statusText: t.statusText,
|
|
1257
|
-
headers:
|
|
1281
|
+
headers: st(t.headers),
|
|
1258
1282
|
body: o,
|
|
1259
1283
|
createdAt: r,
|
|
1260
1284
|
expiresAt: r + n.ttlMs,
|
|
1261
1285
|
lastAccessedAt: r
|
|
1262
1286
|
};
|
|
1263
|
-
|
|
1287
|
+
A.set(e, i), Z(n.maxEntries), await q(i), await ut(n.maxEntries, r);
|
|
1264
1288
|
} catch {
|
|
1265
1289
|
}
|
|
1266
1290
|
}
|
|
1267
|
-
function
|
|
1291
|
+
function ot(e) {
|
|
1268
1292
|
return /"_error"\s*:/u.test(e) || /"type"\s*:\s*"error"/u.test(e);
|
|
1269
1293
|
}
|
|
1270
|
-
function
|
|
1294
|
+
function it(e) {
|
|
1271
1295
|
return new Response(e.body, {
|
|
1272
1296
|
status: e.status,
|
|
1273
1297
|
statusText: e.statusText,
|
|
1274
1298
|
headers: new Headers(e.headers)
|
|
1275
1299
|
});
|
|
1276
1300
|
}
|
|
1277
|
-
function
|
|
1301
|
+
function K(e) {
|
|
1278
1302
|
const t = new Headers(e), r = [];
|
|
1279
1303
|
return t.forEach((n, o) => {
|
|
1280
1304
|
const i = o.toLowerCase();
|
|
1281
1305
|
i !== "authorization" && i !== "cookie" && r.push([i, n]);
|
|
1282
1306
|
}), r.sort(([n], [o]) => n.localeCompare(o));
|
|
1283
1307
|
}
|
|
1284
|
-
function
|
|
1308
|
+
function st(e) {
|
|
1285
1309
|
const t = [];
|
|
1286
1310
|
return e.forEach((r, n) => {
|
|
1287
1311
|
const o = n.toLowerCase();
|
|
1288
1312
|
o !== "set-cookie" && t.push([o, r]);
|
|
1289
1313
|
}), t.sort(([r], [n]) => r.localeCompare(n));
|
|
1290
1314
|
}
|
|
1291
|
-
function
|
|
1292
|
-
for (;
|
|
1293
|
-
const t = [...
|
|
1315
|
+
function Z(e) {
|
|
1316
|
+
for (; A.size > e; ) {
|
|
1317
|
+
const t = [...A.values()].sort((r, n) => r.lastAccessedAt - n.lastAccessedAt)[0];
|
|
1294
1318
|
if (!t) break;
|
|
1295
|
-
|
|
1319
|
+
A.delete(t.key);
|
|
1296
1320
|
}
|
|
1297
1321
|
}
|
|
1298
|
-
async function
|
|
1299
|
-
return typeof indexedDB > "u" ? null : (
|
|
1300
|
-
const t = indexedDB.open(
|
|
1322
|
+
async function D() {
|
|
1323
|
+
return typeof indexedDB > "u" ? null : ($ ??= new Promise((e) => {
|
|
1324
|
+
const t = indexedDB.open(Je, Qe);
|
|
1301
1325
|
t.onupgradeneeded = () => {
|
|
1302
1326
|
const r = t.result;
|
|
1303
|
-
r.objectStoreNames.contains(
|
|
1327
|
+
r.objectStoreNames.contains(S) || r.createObjectStore(S, { keyPath: "key" }).createIndex("lastAccessedAt", "lastAccessedAt", { unique: !1 });
|
|
1304
1328
|
}, t.onsuccess = () => e(t.result), t.onerror = () => e(null), t.onblocked = () => e(null);
|
|
1305
|
-
}),
|
|
1329
|
+
}), $);
|
|
1306
1330
|
}
|
|
1307
|
-
async function
|
|
1308
|
-
const t = await
|
|
1331
|
+
async function at(e) {
|
|
1332
|
+
const t = await D();
|
|
1309
1333
|
return t ? new Promise((r) => {
|
|
1310
|
-
const n = t.transaction(
|
|
1334
|
+
const n = t.transaction(S, "readonly"), o = n.objectStore(S).get(e);
|
|
1311
1335
|
o.onsuccess = () => r(o.result ?? null), o.onerror = () => r(null), n.onerror = () => r(null);
|
|
1312
1336
|
}) : null;
|
|
1313
1337
|
}
|
|
1314
|
-
async function
|
|
1315
|
-
const t = await
|
|
1338
|
+
async function q(e) {
|
|
1339
|
+
const t = await D();
|
|
1316
1340
|
t && await new Promise((r) => {
|
|
1317
|
-
const n = t.transaction(
|
|
1318
|
-
n.objectStore(
|
|
1341
|
+
const n = t.transaction(S, "readwrite");
|
|
1342
|
+
n.objectStore(S).put(e), n.oncomplete = () => r(), n.onerror = () => r(), n.onabort = () => r();
|
|
1319
1343
|
});
|
|
1320
1344
|
}
|
|
1321
|
-
async function
|
|
1322
|
-
const t = await
|
|
1345
|
+
async function ct(e) {
|
|
1346
|
+
const t = await D();
|
|
1323
1347
|
t && await new Promise((r) => {
|
|
1324
|
-
const n = t.transaction(
|
|
1325
|
-
n.objectStore(
|
|
1348
|
+
const n = t.transaction(S, "readwrite");
|
|
1349
|
+
n.objectStore(S).delete(e), n.oncomplete = () => r(), n.onerror = () => r(), n.onabort = () => r();
|
|
1326
1350
|
});
|
|
1327
1351
|
}
|
|
1328
|
-
async function
|
|
1329
|
-
const r = await
|
|
1352
|
+
async function ut(e, t) {
|
|
1353
|
+
const r = await D();
|
|
1330
1354
|
r && await new Promise((n) => {
|
|
1331
|
-
const o = r.transaction(
|
|
1332
|
-
|
|
1333
|
-
const
|
|
1334
|
-
if (!
|
|
1335
|
-
const
|
|
1336
|
-
for (const
|
|
1355
|
+
const o = r.transaction(S, "readwrite"), i = o.objectStore(S), s = [], a = i.openCursor();
|
|
1356
|
+
a.onsuccess = () => {
|
|
1357
|
+
const c = a.result;
|
|
1358
|
+
if (!c) {
|
|
1359
|
+
const u = s.filter((f) => f.expiresAt <= t), _ = s.filter((f) => f.expiresAt > t).sort((f, d) => f.lastAccessedAt - d.lastAccessedAt).slice(0, Math.max(0, s.length - u.length - e));
|
|
1360
|
+
for (const f of [...u, ..._]) i.delete(f.key);
|
|
1337
1361
|
return;
|
|
1338
1362
|
}
|
|
1339
|
-
s.push(
|
|
1340
|
-
},
|
|
1363
|
+
s.push(c.value), c.continue();
|
|
1364
|
+
}, a.onerror = () => n(), o.oncomplete = () => n(), o.onerror = () => n(), o.onabort = () => n();
|
|
1341
1365
|
});
|
|
1342
1366
|
}
|
|
1343
|
-
function
|
|
1344
|
-
return JSON.stringify(
|
|
1367
|
+
function F(e) {
|
|
1368
|
+
return JSON.stringify(j(e));
|
|
1345
1369
|
}
|
|
1346
|
-
function
|
|
1370
|
+
function T(e) {
|
|
1347
1371
|
return e && typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
1348
1372
|
}
|
|
1349
|
-
function
|
|
1350
|
-
return Array.isArray(e) ? e.map(
|
|
1373
|
+
function j(e) {
|
|
1374
|
+
return Array.isArray(e) ? e.map(j) : !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).sort(([t], [r]) => t.localeCompare(r)).map(([t, r]) => [t, j(r)]));
|
|
1351
1375
|
}
|
|
1352
|
-
function
|
|
1376
|
+
function V(e) {
|
|
1353
1377
|
let t = 14695981039346656037n;
|
|
1354
1378
|
const r = 1099511628211n;
|
|
1355
1379
|
for (let n = 0; n < e.length; n += 1)
|
|
1356
1380
|
t ^= BigInt(e.charCodeAt(n)), t = BigInt.asUintN(64, t * r);
|
|
1357
1381
|
return t.toString(16).padStart(16, "0");
|
|
1358
1382
|
}
|
|
1359
|
-
function
|
|
1383
|
+
function lt(e) {
|
|
1360
1384
|
return typeof TextEncoder < "u" ? new TextEncoder().encode(e).byteLength : e.length;
|
|
1361
1385
|
}
|
|
1362
1386
|
export {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1387
|
+
_t as a,
|
|
1388
|
+
N as c,
|
|
1389
|
+
ae as d,
|
|
1390
|
+
ne as f,
|
|
1391
|
+
pt as g,
|
|
1392
|
+
te as h,
|
|
1393
|
+
gt as i,
|
|
1394
|
+
ce as l,
|
|
1395
|
+
ft as m,
|
|
1396
|
+
ht as n,
|
|
1397
|
+
mt as o,
|
|
1398
|
+
yt as p,
|
|
1399
|
+
Fe as r,
|
|
1400
|
+
w as s,
|
|
1401
|
+
bt as t,
|
|
1402
|
+
se as u
|
|
1379
1403
|
};
|