@ecomid/modules 0.0.0-stage → 0.1.0
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 +332 -2
- package/dist/chunks/cs-Dqb_rREp.js +97 -0
- package/dist/chunks/da-WYTDtjgg.js +97 -0
- package/dist/chunks/de-D6tbcZ82.js +97 -0
- package/dist/chunks/en-BJsf6vvY.js +97 -0
- package/dist/chunks/es-UCU6bjwJ.js +97 -0
- package/dist/chunks/fi-BZ1TBPKK.js +97 -0
- package/dist/chunks/fr-Bh4svI2n.js +97 -0
- package/dist/chunks/it-S3zZ2XyN.js +97 -0
- package/dist/chunks/nl-BskWxJtL.js +97 -0
- package/dist/chunks/no-fPEJ7LXi.js +97 -0
- package/dist/chunks/pl-DgFibWpI.js +97 -0
- package/dist/chunks/pt-CZ1aBAcy.js +97 -0
- package/dist/chunks/resultsStore-3P0rGTOF.js +1714 -0
- package/dist/chunks/searchPage-BDL83WXl.d.ts +113 -0
- package/dist/chunks/sk-BVkd-dpe.js +97 -0
- package/dist/chunks/sv-CoiCABF8.js +97 -0
- package/dist/react.d.ts +51 -0
- package/dist/react.js +4497 -0
- package/dist/search/styles.css +2 -0
- package/dist/search.d.ts +227 -0
- package/dist/search.js +39 -0
- package/package.json +42 -4
|
@@ -0,0 +1,1714 @@
|
|
|
1
|
+
// src/helpers/ecomidWindow.ts
|
|
2
|
+
var e = () => window, t = {
|
|
3
|
+
production: {
|
|
4
|
+
cgw: "https://cgw.ecomid.com",
|
|
5
|
+
events: "https://events.ecomid.com"
|
|
6
|
+
},
|
|
7
|
+
staging: {
|
|
8
|
+
cgw: "https://cgw.staging.ecomid.com",
|
|
9
|
+
events: "https://events.staging.ecomid.com"
|
|
10
|
+
},
|
|
11
|
+
sandbox: {
|
|
12
|
+
cgw: "https://cgw.sandbox.ecomid.com",
|
|
13
|
+
events: "https://events.sandbox.ecomid.com"
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function n(e = "production") {
|
|
17
|
+
return t[e];
|
|
18
|
+
}
|
|
19
|
+
// src/cookies/cookies.ts
|
|
20
|
+
var r = (e) => {
|
|
21
|
+
try {
|
|
22
|
+
return decodeURIComponent(e);
|
|
23
|
+
} catch {
|
|
24
|
+
return e;
|
|
25
|
+
}
|
|
26
|
+
}, i = (e) => {
|
|
27
|
+
let t = document.cookie.split("; ").map((e) => e.split(/=(.+)/)).find(([t]) => r(t) === e)?.[1];
|
|
28
|
+
return t ? r(t) : void 0;
|
|
29
|
+
}, a = (e) => /^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(e.hostname) || e.protocol === "file:", o = () => {
|
|
30
|
+
if (m()) {
|
|
31
|
+
let e = new URLSearchParams(window.location.search);
|
|
32
|
+
return {
|
|
33
|
+
origin: e.get("origin") || "",
|
|
34
|
+
path: e.get("path") || ""
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
origin: window.location.origin,
|
|
39
|
+
path: window.location.pathname
|
|
40
|
+
};
|
|
41
|
+
}, s = (e) => e === e.parent ? e : s(e.parent), c = class extends Error {
|
|
42
|
+
status;
|
|
43
|
+
constructor(e, t) {
|
|
44
|
+
super(e), this.status = t;
|
|
45
|
+
}
|
|
46
|
+
}, l = (t, n = {}, r = {}) => {
|
|
47
|
+
if (typeof window > "u") return t;
|
|
48
|
+
let i = {
|
|
49
|
+
...n,
|
|
50
|
+
...o()
|
|
51
|
+
}, s = e().ecomid?.version;
|
|
52
|
+
if (s && (i = {
|
|
53
|
+
...i,
|
|
54
|
+
version: s
|
|
55
|
+
}), a(window.location)) return console.warn("Ignoring error event", "localhost", {
|
|
56
|
+
error: t,
|
|
57
|
+
meta: i
|
|
58
|
+
}), t;
|
|
59
|
+
fetch(`${r.eventsBaseUrl ?? "https://events.ecomid.com"}/v0/errors`, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: { "Content-Type": "application/json" },
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
error: t.toString(),
|
|
64
|
+
stack: t.stack,
|
|
65
|
+
cause: t.cause?.toString(),
|
|
66
|
+
meta: i
|
|
67
|
+
})
|
|
68
|
+
}).catch(() => {});
|
|
69
|
+
}, u = () => {
|
|
70
|
+
if (m()) {
|
|
71
|
+
let e = new URLSearchParams(window.location.search).get("consent");
|
|
72
|
+
if (e) try {
|
|
73
|
+
return {
|
|
74
|
+
consent: JSON.parse(e),
|
|
75
|
+
source: "iframe_param",
|
|
76
|
+
detail: e
|
|
77
|
+
};
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return l(Error("Failed to parse iframe consent param", { cause: e })), {
|
|
80
|
+
consent: {
|
|
81
|
+
preferences: !1,
|
|
82
|
+
statistics: !1,
|
|
83
|
+
marketing: !1
|
|
84
|
+
},
|
|
85
|
+
source: "default"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
let t = e().ecomid;
|
|
90
|
+
if (t?.getConsent) {
|
|
91
|
+
let e = t.getConsent();
|
|
92
|
+
if (e && typeof e == "object") return {
|
|
93
|
+
consent: e,
|
|
94
|
+
source: "merchant_override"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
let n = i("CookieConsent");
|
|
98
|
+
if (n) return {
|
|
99
|
+
consent: {
|
|
100
|
+
preferences: n.includes("preferences:true"),
|
|
101
|
+
statistics: n.includes("statistics:true"),
|
|
102
|
+
marketing: n.includes("marketing:true")
|
|
103
|
+
},
|
|
104
|
+
source: "cookiebot",
|
|
105
|
+
detail: n
|
|
106
|
+
};
|
|
107
|
+
let r = i("OptanonConsent");
|
|
108
|
+
if (r) return {
|
|
109
|
+
consent: {
|
|
110
|
+
preferences: r.includes("C0003:1"),
|
|
111
|
+
statistics: r.includes("C0002:1"),
|
|
112
|
+
marketing: r.includes("C0004:1")
|
|
113
|
+
},
|
|
114
|
+
source: "onetrust",
|
|
115
|
+
detail: r
|
|
116
|
+
};
|
|
117
|
+
try {
|
|
118
|
+
let t = e().Shopify;
|
|
119
|
+
if (t?.customerPrivacy?.currentVisitorConsent) {
|
|
120
|
+
let { customerPrivacy: e } = t;
|
|
121
|
+
return {
|
|
122
|
+
consent: {
|
|
123
|
+
preferences: e.preferencesProcessingAllowed?.() ?? !1,
|
|
124
|
+
statistics: e.analyticsProcessingAllowed?.() ?? !1,
|
|
125
|
+
marketing: e.thirdPartyMarketingAllowed?.() ?? !1
|
|
126
|
+
},
|
|
127
|
+
source: "shopify"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
} catch (e) {
|
|
131
|
+
l(Error("Failed to get Shopify consent", { cause: e }));
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
consent: {
|
|
135
|
+
preferences: !1,
|
|
136
|
+
statistics: !1,
|
|
137
|
+
marketing: !1
|
|
138
|
+
},
|
|
139
|
+
source: "default"
|
|
140
|
+
};
|
|
141
|
+
}, d = () => u().consent;
|
|
142
|
+
// src/helpers/isE2ETest.ts
|
|
143
|
+
function f() {
|
|
144
|
+
return !1;
|
|
145
|
+
}
|
|
146
|
+
var p = () => document.getElementById("ecomid-pixel")?.contentWindow ?? null, m = () => window !== window.parent, h = (e) => f() ? !0 : e.origin === "/";
|
|
147
|
+
// src/helpers/retry.ts
|
|
148
|
+
async function g(e, t = {}) {
|
|
149
|
+
let { retries: n = 2, shouldRetry: r = () => !0, delayMs: i = (e) => 200 * (e + 1) } = t, a;
|
|
150
|
+
for (let t = 0; t <= n; t++) try {
|
|
151
|
+
return await e();
|
|
152
|
+
} catch (e) {
|
|
153
|
+
if (a = e, t === n || !r(e)) throw e;
|
|
154
|
+
await new Promise((e) => setTimeout(e, i(t)));
|
|
155
|
+
}
|
|
156
|
+
throw a;
|
|
157
|
+
}
|
|
158
|
+
// src/helpers/request/fetchWithRetry.ts
|
|
159
|
+
var _ = (e, t) => g(() => fetch(e, t), { shouldRetry: (e) => e instanceof TypeError }), v = null;
|
|
160
|
+
function y(e) {
|
|
161
|
+
v = e;
|
|
162
|
+
}
|
|
163
|
+
function b(e) {
|
|
164
|
+
return e instanceof Error && e.name === "AbortError";
|
|
165
|
+
}
|
|
166
|
+
function x() {
|
|
167
|
+
return v?.isSignedIn() ? "user" : "guest";
|
|
168
|
+
}
|
|
169
|
+
async function S(e, t) {
|
|
170
|
+
if (v?.isSignedIn() && v.canRelay(e)) try {
|
|
171
|
+
return await v.fetch(e, t ?? {});
|
|
172
|
+
} catch (e) {
|
|
173
|
+
if (b(e) || t?.signal?.aborted) throw e;
|
|
174
|
+
}
|
|
175
|
+
return t?.method === "POST" ? fetch(e, t) : _(e, t);
|
|
176
|
+
}
|
|
177
|
+
// src/translations/translations.ts
|
|
178
|
+
var C = "en", w = {
|
|
179
|
+
nb: "no",
|
|
180
|
+
nn: "no"
|
|
181
|
+
}, T = (e) => {
|
|
182
|
+
let t = (e || C).toLowerCase().trim();
|
|
183
|
+
if (!t.match(/^[a-z]{2}([-_][a-z0-9_-]+)?$/)) return {
|
|
184
|
+
lang: C,
|
|
185
|
+
market: void 0
|
|
186
|
+
};
|
|
187
|
+
let [n, ...r] = t.split(/[-_]/), i = r.length > 0 ? r.join("-") : void 0;
|
|
188
|
+
return {
|
|
189
|
+
lang: w[n] || n,
|
|
190
|
+
market: i || void 0
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
// src/search/core/validate.ts
|
|
194
|
+
function E(e) {
|
|
195
|
+
if (!e) throw Error("Locale is required");
|
|
196
|
+
let { lang: t, market: n } = T(e);
|
|
197
|
+
if (!n) throw Error("Market is required");
|
|
198
|
+
return {
|
|
199
|
+
lang: t,
|
|
200
|
+
market: n
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function D(e) {
|
|
204
|
+
if (!e.clientId) throw Error("Client ID is required");
|
|
205
|
+
return {
|
|
206
|
+
clientId: e.clientId,
|
|
207
|
+
...E(e.locale)
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
// src/search/core/searchPage.ts
|
|
211
|
+
var O = [
|
|
212
|
+
"relevance",
|
|
213
|
+
"best_selling",
|
|
214
|
+
"newest",
|
|
215
|
+
"cheapest",
|
|
216
|
+
"most_expensive",
|
|
217
|
+
"biggest_discount"
|
|
218
|
+
], k = [
|
|
219
|
+
"color",
|
|
220
|
+
"material",
|
|
221
|
+
"category",
|
|
222
|
+
"gender",
|
|
223
|
+
"size",
|
|
224
|
+
"price_min",
|
|
225
|
+
"price_max",
|
|
226
|
+
"on_sale"
|
|
227
|
+
], A = [
|
|
228
|
+
"term",
|
|
229
|
+
"exclude_term",
|
|
230
|
+
"filter",
|
|
231
|
+
"exclude"
|
|
232
|
+
], j = [
|
|
233
|
+
...A,
|
|
234
|
+
"sort",
|
|
235
|
+
"request"
|
|
236
|
+
];
|
|
237
|
+
function M(e) {
|
|
238
|
+
let t = new URLSearchParams();
|
|
239
|
+
if (e.kind === "compose") return t.set("request", e.text), t;
|
|
240
|
+
let { terms: n, excludedTerms: r, filters: i, sort: a } = e.state;
|
|
241
|
+
for (let e of n) t.append("term", e);
|
|
242
|
+
for (let e of r) t.append("exclude_term", e);
|
|
243
|
+
for (let e of i) for (let n of e.values) t.append(e.exclude ? "exclude" : "filter", `${e.key}:${n}`);
|
|
244
|
+
return a !== "relevance" && t.set("sort", a), t;
|
|
245
|
+
}
|
|
246
|
+
function N(e) {
|
|
247
|
+
let t = typeof e == "string" ? new URLSearchParams(e) : e, n = t.get("request");
|
|
248
|
+
if (n) return {
|
|
249
|
+
kind: "compose",
|
|
250
|
+
text: n
|
|
251
|
+
};
|
|
252
|
+
if (!A.some((e) => t.has(e))) return null;
|
|
253
|
+
let r = [];
|
|
254
|
+
for (let e of [!1, !0]) for (let n of t.getAll(e ? "exclude" : "filter")) {
|
|
255
|
+
let t = n.indexOf(":"), i = n.slice(0, t);
|
|
256
|
+
if (t < 0 || !k.includes(i)) continue;
|
|
257
|
+
let a = n.slice(t + 1), o = r.find((t) => t.key === i && !!t.exclude === e);
|
|
258
|
+
o ? o.values.push(a) : r.push({
|
|
259
|
+
key: i,
|
|
260
|
+
values: [a],
|
|
261
|
+
...e && { exclude: e }
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
let i = O.find((e) => e === t.get("sort"));
|
|
265
|
+
return {
|
|
266
|
+
kind: "search",
|
|
267
|
+
state: {
|
|
268
|
+
terms: t.getAll("term"),
|
|
269
|
+
excludedTerms: t.getAll("exclude_term"),
|
|
270
|
+
filters: r,
|
|
271
|
+
sort: i ?? "relevance"
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function P(e) {
|
|
276
|
+
return M(e).toString();
|
|
277
|
+
}
|
|
278
|
+
function F(e) {
|
|
279
|
+
return e.kind === "compose" ? e.text.trim() : e.state.terms.join(" ").trim();
|
|
280
|
+
}
|
|
281
|
+
function ee(e, t) {
|
|
282
|
+
let n = new URLSearchParams(e);
|
|
283
|
+
for (let e of j) n.delete(e);
|
|
284
|
+
if (t) for (let [e, r] of M(t)) n.append(e, r);
|
|
285
|
+
let r = n.toString();
|
|
286
|
+
return r ? `?${r}` : "";
|
|
287
|
+
}
|
|
288
|
+
// src/contexts/Locale/langs.ts
|
|
289
|
+
var I = [
|
|
290
|
+
"en",
|
|
291
|
+
"da",
|
|
292
|
+
"de",
|
|
293
|
+
"es",
|
|
294
|
+
"fi",
|
|
295
|
+
"fr",
|
|
296
|
+
"it",
|
|
297
|
+
"nl",
|
|
298
|
+
"no",
|
|
299
|
+
"pl",
|
|
300
|
+
"sv",
|
|
301
|
+
"cs",
|
|
302
|
+
"sk",
|
|
303
|
+
"pt"
|
|
304
|
+
], L = (e) => I.find((t) => t === e) ?? "en";
|
|
305
|
+
// src/helpers/preview.ts
|
|
306
|
+
function R() {
|
|
307
|
+
return typeof window > "u" ? !1 : new URLSearchParams(window.location.search).get("preview") === "true";
|
|
308
|
+
}
|
|
309
|
+
// src/helpers/random.ts
|
|
310
|
+
var te = (e) => {
|
|
311
|
+
let t = [...e];
|
|
312
|
+
for (let e = t.length - 1; e > 0; e--) {
|
|
313
|
+
let n = Math.floor(Math.random() * (e + 1));
|
|
314
|
+
[t[e], t[n]] = [t[n], t[e]];
|
|
315
|
+
}
|
|
316
|
+
return t;
|
|
317
|
+
};
|
|
318
|
+
// src/helpers/request/cgw/searchStartQuery.ts
|
|
319
|
+
function ne(e) {
|
|
320
|
+
let t = new URLSearchParams();
|
|
321
|
+
t.set("location", e.location), e.surface && t.set("surface", e.surface), e.market && t.set("market", e.market), t.set("locale", e.locale), e.category && t.set("category", e.category);
|
|
322
|
+
for (let n of e.variantIds ?? []) t.append("variant_ids", n);
|
|
323
|
+
for (let n of e.skus ?? []) t.append("skus", n);
|
|
324
|
+
return R() && t.append("preview", "true"), t.toString();
|
|
325
|
+
}
|
|
326
|
+
// src/search/core/api.ts
|
|
327
|
+
function z(e) {
|
|
328
|
+
let t = {
|
|
329
|
+
id: e.variant_id,
|
|
330
|
+
name: e.name
|
|
331
|
+
};
|
|
332
|
+
e.url !== void 0 && (t.url = e.url);
|
|
333
|
+
let n = e.images?.[0];
|
|
334
|
+
n?.url !== void 0 && (t.imageUrl = n.url), n?.tags !== void 0 && (t.imageTags = n.tags);
|
|
335
|
+
let r = e.images?.[1];
|
|
336
|
+
return r?.url !== void 0 && (t.hoverImageUrl = r.url), r?.tags !== void 0 && (t.hoverImageTags = r.tags), e.current_price_in_cents !== void 0 && (t.price = e.current_price_in_cents / 100), e.baseline_price_in_cents !== void 0 && (t.baselinePrice = e.baseline_price_in_cents / 100), e.currency_code !== void 0 && (t.currency = e.currency_code), e.variant_count !== void 0 && (t.variantCount = e.variant_count), e.reason && (t.reason = e.reason), t;
|
|
337
|
+
}
|
|
338
|
+
function re(e) {
|
|
339
|
+
return {
|
|
340
|
+
suggestions: (e.suggestions ?? []).map((e) => ({ text: e.text ?? "" })).filter((e) => e.text.length > 0),
|
|
341
|
+
products: (e.products ?? []).map(z)
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function B(e) {
|
|
345
|
+
return e ?? "https://cgw.ecomid.com";
|
|
346
|
+
}
|
|
347
|
+
function ie(e) {
|
|
348
|
+
let t = new URLSearchParams();
|
|
349
|
+
return t.set("q", e.query), t.set("market", e.market), t.set("locale", L(e.lang)), e.limit !== void 0 && t.set("limit", String(e.limit)), R() && t.set("preview", "true"), t.toString();
|
|
350
|
+
}
|
|
351
|
+
async function ae(e, t, n) {
|
|
352
|
+
let r = await S(`${B(t.baseUrl)}/v0/search/${e}/suggestions?${ie(t)}`, { signal: n });
|
|
353
|
+
if (!r.ok) throw new c(`search suggestions request failed with status ${r.status}`, r.status);
|
|
354
|
+
return re(await r.json());
|
|
355
|
+
}
|
|
356
|
+
function oe(e) {
|
|
357
|
+
return {
|
|
358
|
+
starters: (e.search_starters ?? []).map((e) => ({ text: e.text })),
|
|
359
|
+
recommendedProducts: (e.recommended_products ?? []).map(z)
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
var se = 10;
|
|
363
|
+
function ce(e) {
|
|
364
|
+
return te(e).slice(0, se);
|
|
365
|
+
}
|
|
366
|
+
async function V(e, t) {
|
|
367
|
+
let n = ne({
|
|
368
|
+
location: t.location ?? "landing",
|
|
369
|
+
surface: "search",
|
|
370
|
+
market: t.market,
|
|
371
|
+
locale: L(t.lang),
|
|
372
|
+
category: t.category,
|
|
373
|
+
variantIds: t.variantIds,
|
|
374
|
+
skus: t.skus
|
|
375
|
+
}), r = await S(`${B(t.baseUrl)}/v0/search/${e}/start?${n}`);
|
|
376
|
+
if (!r.ok) throw new c(`search start request failed with status ${r.status}`, r.status);
|
|
377
|
+
let i = oe(await r.json());
|
|
378
|
+
return {
|
|
379
|
+
...i,
|
|
380
|
+
starters: ce(i.starters)
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
// src/helpers/storage.ts
|
|
384
|
+
var H = () => {
|
|
385
|
+
try {
|
|
386
|
+
return window.localStorage ?? null;
|
|
387
|
+
} catch {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
function U(e) {
|
|
392
|
+
if (e instanceof Error) {
|
|
393
|
+
if (e.message.includes("The operation is insecure") || e.message.includes("Access is denied for this document")) return;
|
|
394
|
+
l(e);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
var le = (e, t) => {
|
|
398
|
+
let n = H();
|
|
399
|
+
if (n) try {
|
|
400
|
+
let r = n.getItem(e);
|
|
401
|
+
if (r) return t ? JSON.parse(r)[t] : JSON.parse(r);
|
|
402
|
+
} catch (e) {
|
|
403
|
+
U(e);
|
|
404
|
+
}
|
|
405
|
+
}, ue = (e, t, n, r = !1) => {
|
|
406
|
+
let i = H();
|
|
407
|
+
if (i) try {
|
|
408
|
+
if (!r && !d().preferences) return;
|
|
409
|
+
let a = JSON.parse(i.getItem(e) || "{}"), o = a[t] || {}, s = n;
|
|
410
|
+
typeof n == "object" && !Array.isArray(n) && (s = {
|
|
411
|
+
...o,
|
|
412
|
+
...n
|
|
413
|
+
}), i.setItem(e, JSON.stringify({
|
|
414
|
+
...a,
|
|
415
|
+
[t]: s
|
|
416
|
+
}));
|
|
417
|
+
} catch (e) {
|
|
418
|
+
U(e);
|
|
419
|
+
}
|
|
420
|
+
}, de = "ec_search", fe = "recent", pe = 5;
|
|
421
|
+
function me(e) {
|
|
422
|
+
return e.trim().toLowerCase();
|
|
423
|
+
}
|
|
424
|
+
function he() {
|
|
425
|
+
let e = le(de, fe);
|
|
426
|
+
return Array.isArray(e) ? e.filter((e) => typeof e == "string") : [];
|
|
427
|
+
}
|
|
428
|
+
function ge(e) {
|
|
429
|
+
let t = e.trim(), n = he();
|
|
430
|
+
if (t.length === 0) return n;
|
|
431
|
+
let r = [t, ...n.filter((e) => me(e) !== me(t))].slice(0, pe);
|
|
432
|
+
return ue(de, fe, r), r;
|
|
433
|
+
}
|
|
434
|
+
// src/search/core/store.ts
|
|
435
|
+
function W(e) {
|
|
436
|
+
return e.trim();
|
|
437
|
+
}
|
|
438
|
+
function _e(e) {
|
|
439
|
+
return e instanceof Error && e.name === "AbortError";
|
|
440
|
+
}
|
|
441
|
+
function ve(e) {
|
|
442
|
+
let { clientId: t, market: n, lang: r, location: i, baseUrl: a, debounceMs: o = 150, minQueryLength: s = 2, suggestLimit: c = 12, cacheLimit: l = 20 } = e, u = e.fetchers?.fetchSuggestions ?? ae, d = e.fetchers?.fetchEmptyState ?? V, f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map(), m = {
|
|
443
|
+
query: "",
|
|
444
|
+
status: "idle",
|
|
445
|
+
instant: null,
|
|
446
|
+
emptyState: null,
|
|
447
|
+
emptyStateStatus: "idle"
|
|
448
|
+
}, h, g, _ = 0, v = 0;
|
|
449
|
+
function y(e) {
|
|
450
|
+
m = e;
|
|
451
|
+
for (let e of f) e();
|
|
452
|
+
}
|
|
453
|
+
function b(e, t) {
|
|
454
|
+
if (p.size >= l && !p.has(e)) {
|
|
455
|
+
let e = p.keys().next().value;
|
|
456
|
+
e !== void 0 && p.delete(e);
|
|
457
|
+
}
|
|
458
|
+
p.set(e, t);
|
|
459
|
+
}
|
|
460
|
+
function S() {
|
|
461
|
+
h !== void 0 && (clearTimeout(h), h = void 0);
|
|
462
|
+
}
|
|
463
|
+
function C() {
|
|
464
|
+
g?.abort(), g = void 0;
|
|
465
|
+
}
|
|
466
|
+
async function w(e) {
|
|
467
|
+
C();
|
|
468
|
+
let i = ++_, o = `${x()}:${e.toLowerCase()}`, s = p.get(o);
|
|
469
|
+
if (s) {
|
|
470
|
+
y({
|
|
471
|
+
...m,
|
|
472
|
+
status: "success",
|
|
473
|
+
instant: s
|
|
474
|
+
});
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
let l = new AbortController();
|
|
478
|
+
g = l, y({
|
|
479
|
+
...m,
|
|
480
|
+
status: "loading"
|
|
481
|
+
});
|
|
482
|
+
try {
|
|
483
|
+
let s = await u(t, {
|
|
484
|
+
query: e,
|
|
485
|
+
market: n,
|
|
486
|
+
lang: r,
|
|
487
|
+
limit: c,
|
|
488
|
+
baseUrl: a
|
|
489
|
+
}, l.signal);
|
|
490
|
+
if (i !== _) return;
|
|
491
|
+
b(o, s), y({
|
|
492
|
+
...m,
|
|
493
|
+
status: "success",
|
|
494
|
+
instant: s
|
|
495
|
+
});
|
|
496
|
+
} catch (e) {
|
|
497
|
+
if (i !== _ || _e(e)) return;
|
|
498
|
+
y({
|
|
499
|
+
...m,
|
|
500
|
+
status: "error"
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function T(e) {
|
|
505
|
+
S();
|
|
506
|
+
let t = W(e);
|
|
507
|
+
t.length < s ? (C(), _ += 1, y({
|
|
508
|
+
...m,
|
|
509
|
+
query: e,
|
|
510
|
+
status: "idle",
|
|
511
|
+
instant: null
|
|
512
|
+
})) : (y({
|
|
513
|
+
...m,
|
|
514
|
+
query: e,
|
|
515
|
+
status: "loading"
|
|
516
|
+
}), h = setTimeout(() => {
|
|
517
|
+
h = void 0, w(t);
|
|
518
|
+
}, o));
|
|
519
|
+
}
|
|
520
|
+
function E() {
|
|
521
|
+
S(), C(), _ += 1;
|
|
522
|
+
let e = W(m.query);
|
|
523
|
+
return ge(e), y({
|
|
524
|
+
...m,
|
|
525
|
+
status: "idle"
|
|
526
|
+
}), e.length > 0 ? e : null;
|
|
527
|
+
}
|
|
528
|
+
async function D() {
|
|
529
|
+
if (m.emptyStateStatus === "loading" || m.emptyStateStatus === "success") return;
|
|
530
|
+
let e = ++v;
|
|
531
|
+
y({
|
|
532
|
+
...m,
|
|
533
|
+
emptyStateStatus: "loading"
|
|
534
|
+
});
|
|
535
|
+
try {
|
|
536
|
+
let o = await d(t, {
|
|
537
|
+
location: i,
|
|
538
|
+
market: n,
|
|
539
|
+
lang: r,
|
|
540
|
+
baseUrl: a
|
|
541
|
+
});
|
|
542
|
+
if (e !== v) return;
|
|
543
|
+
y({
|
|
544
|
+
...m,
|
|
545
|
+
emptyState: o,
|
|
546
|
+
emptyStateStatus: "success"
|
|
547
|
+
});
|
|
548
|
+
} catch {
|
|
549
|
+
if (e !== v) return;
|
|
550
|
+
y({
|
|
551
|
+
...m,
|
|
552
|
+
emptyStateStatus: "error"
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
function O() {
|
|
557
|
+
let e = W(m.query);
|
|
558
|
+
e.length < s || (S(), w(e));
|
|
559
|
+
}
|
|
560
|
+
function k() {
|
|
561
|
+
S(), C(), _ += 1, v += 1, m = {
|
|
562
|
+
...m,
|
|
563
|
+
status: m.status === "loading" ? "idle" : m.status,
|
|
564
|
+
emptyStateStatus: m.emptyStateStatus === "loading" ? "idle" : m.emptyStateStatus
|
|
565
|
+
}, f.clear();
|
|
566
|
+
}
|
|
567
|
+
function A() {
|
|
568
|
+
return m;
|
|
569
|
+
}
|
|
570
|
+
function j(e) {
|
|
571
|
+
return f.add(e), () => {
|
|
572
|
+
f.delete(e);
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
minQueryLength: s,
|
|
577
|
+
getState: A,
|
|
578
|
+
subscribe: j,
|
|
579
|
+
setQuery: T,
|
|
580
|
+
submit: E,
|
|
581
|
+
loadEmptyState: D,
|
|
582
|
+
resumeSearch: O,
|
|
583
|
+
destroy: k
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
// src/search/core/text.ts
|
|
587
|
+
var ye = (e) => e.charAt(0).toUpperCase() + e.slice(1), be = /* @__PURE__ */ new Set([
|
|
588
|
+
"how",
|
|
589
|
+
"what",
|
|
590
|
+
"which",
|
|
591
|
+
"why",
|
|
592
|
+
"who",
|
|
593
|
+
"where",
|
|
594
|
+
"when",
|
|
595
|
+
"vad",
|
|
596
|
+
"hur",
|
|
597
|
+
"vilken",
|
|
598
|
+
"vilket",
|
|
599
|
+
"vilka",
|
|
600
|
+
"varfor",
|
|
601
|
+
"vem",
|
|
602
|
+
"vart"
|
|
603
|
+
]), xe = /* @__PURE__ */ new Set([
|
|
604
|
+
"need",
|
|
605
|
+
"needs",
|
|
606
|
+
"want",
|
|
607
|
+
"wondering",
|
|
608
|
+
"something",
|
|
609
|
+
"anything",
|
|
610
|
+
"behover",
|
|
611
|
+
"vill",
|
|
612
|
+
"soker",
|
|
613
|
+
"letar",
|
|
614
|
+
"undrar",
|
|
615
|
+
"nagot",
|
|
616
|
+
"nat",
|
|
617
|
+
"nagon",
|
|
618
|
+
"nagra",
|
|
619
|
+
"tips"
|
|
620
|
+
]), Se = [
|
|
621
|
+
"recommend",
|
|
622
|
+
"suggest",
|
|
623
|
+
"rekommend",
|
|
624
|
+
"foresl"
|
|
625
|
+
], Ce = [
|
|
626
|
+
"looking for",
|
|
627
|
+
"show me",
|
|
628
|
+
"give me",
|
|
629
|
+
"find me",
|
|
630
|
+
"help me",
|
|
631
|
+
"visa mig",
|
|
632
|
+
"ge mig",
|
|
633
|
+
"hjalp mig"
|
|
634
|
+
], we = [
|
|
635
|
+
"jag",
|
|
636
|
+
"vi",
|
|
637
|
+
"we",
|
|
638
|
+
"im",
|
|
639
|
+
"i m",
|
|
640
|
+
"i am",
|
|
641
|
+
"i ve"
|
|
642
|
+
], Te = [
|
|
643
|
+
"can",
|
|
644
|
+
"could",
|
|
645
|
+
"do",
|
|
646
|
+
"does",
|
|
647
|
+
"is",
|
|
648
|
+
"are",
|
|
649
|
+
"will",
|
|
650
|
+
"should",
|
|
651
|
+
"would",
|
|
652
|
+
"help",
|
|
653
|
+
"kan",
|
|
654
|
+
"finns",
|
|
655
|
+
"nar",
|
|
656
|
+
"var",
|
|
657
|
+
"ska",
|
|
658
|
+
"borde",
|
|
659
|
+
"bor",
|
|
660
|
+
"maste",
|
|
661
|
+
"hjalp",
|
|
662
|
+
"gar det"
|
|
663
|
+
], Ee = (e, t) => t.some((t) => e.startsWith(` ${t} `));
|
|
664
|
+
function De(e) {
|
|
665
|
+
if (e.includes("?")) return !0;
|
|
666
|
+
let t = e.toLowerCase().normalize("NFD").replace(/\p{M}/gu, "").split(/[^\p{L}\p{N}]+/u).filter(Boolean);
|
|
667
|
+
if (t.length < 2) return !1;
|
|
668
|
+
let n = ` ${t.join(" ")} `;
|
|
669
|
+
return t.slice(0, -1).some((e) => be.has(e)) || t.some((e) => xe.has(e) || Se.some((t) => e.startsWith(t))) || Ce.some((e) => n.includes(` ${e} `)) || Ee(n, we) || t.length >= 3 && Ee(n, Te);
|
|
670
|
+
}
|
|
671
|
+
function Oe(e) {
|
|
672
|
+
let t = e.trim();
|
|
673
|
+
return t && De(t) ? [{
|
|
674
|
+
text: t,
|
|
675
|
+
ask: !0
|
|
676
|
+
}] : [];
|
|
677
|
+
}
|
|
678
|
+
// src/search/core/filters.ts
|
|
679
|
+
var G = [
|
|
680
|
+
"category",
|
|
681
|
+
"gender",
|
|
682
|
+
"size",
|
|
683
|
+
"color",
|
|
684
|
+
"material"
|
|
685
|
+
], ke = [
|
|
686
|
+
"category",
|
|
687
|
+
"gender",
|
|
688
|
+
"size",
|
|
689
|
+
"color",
|
|
690
|
+
"price",
|
|
691
|
+
"material"
|
|
692
|
+
], Ae = [
|
|
693
|
+
"relevance",
|
|
694
|
+
"newest",
|
|
695
|
+
"cheapest",
|
|
696
|
+
"most_expensive"
|
|
697
|
+
], je = "relevance";
|
|
698
|
+
function Me(e) {
|
|
699
|
+
return e === void 0 || e === "relevance";
|
|
700
|
+
}
|
|
701
|
+
function Ne(e) {
|
|
702
|
+
return e ?? "relevance";
|
|
703
|
+
}
|
|
704
|
+
function K(e) {
|
|
705
|
+
let t = {};
|
|
706
|
+
if (!e) return t;
|
|
707
|
+
for (let n of G) {
|
|
708
|
+
let r = e[n]?.filter((e) => e !== "");
|
|
709
|
+
r?.length && (t[n] = [...new Set(r)]);
|
|
710
|
+
}
|
|
711
|
+
return e.priceMin !== void 0 && Number.isFinite(e.priceMin) && (t.priceMin = e.priceMin), e.priceMax !== void 0 && Number.isFinite(e.priceMax) && (t.priceMax = e.priceMax), e.onSale && (t.onSale = !0), t;
|
|
712
|
+
}
|
|
713
|
+
function Pe(e) {
|
|
714
|
+
let t = K(e);
|
|
715
|
+
return JSON.stringify([
|
|
716
|
+
...G.map((e) => [...t[e] ?? []].sort()),
|
|
717
|
+
t.priceMin ?? null,
|
|
718
|
+
t.priceMax ?? null,
|
|
719
|
+
t.onSale ?? !1
|
|
720
|
+
]);
|
|
721
|
+
}
|
|
722
|
+
function Fe(e, t) {
|
|
723
|
+
return Pe(e) === Pe(t);
|
|
724
|
+
}
|
|
725
|
+
function Ie(e) {
|
|
726
|
+
return e.priceMin !== void 0 || e.priceMax !== void 0;
|
|
727
|
+
}
|
|
728
|
+
function Le(e, t, n) {
|
|
729
|
+
let r = e[t] ?? [], i = r.includes(n) ? r.filter((e) => e !== n) : [...r, n];
|
|
730
|
+
return K({
|
|
731
|
+
...e,
|
|
732
|
+
[t]: i
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
function Re(e, t) {
|
|
736
|
+
if (t === "price") {
|
|
737
|
+
let { priceMin: t, priceMax: n, ...r } = e;
|
|
738
|
+
return K(r);
|
|
739
|
+
}
|
|
740
|
+
return K({
|
|
741
|
+
...e,
|
|
742
|
+
[t]: []
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
function ze(e) {
|
|
746
|
+
let t = K(e);
|
|
747
|
+
return G.reduce((e, n) => e + (t[n]?.length ?? 0), 0) + +!!Ie(t) + +!!t.onSale;
|
|
748
|
+
}
|
|
749
|
+
var q = "price_min", Be = "price_max", Ve = "on_sale";
|
|
750
|
+
function He(e) {
|
|
751
|
+
let t = K(e), n = [];
|
|
752
|
+
for (let e of G) {
|
|
753
|
+
let r = t[e];
|
|
754
|
+
r?.length && n.push({
|
|
755
|
+
key: e,
|
|
756
|
+
values: r
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
return t.priceMin !== void 0 && n.push({
|
|
760
|
+
key: q,
|
|
761
|
+
values: [String(t.priceMin)]
|
|
762
|
+
}), t.priceMax !== void 0 && n.push({
|
|
763
|
+
key: Be,
|
|
764
|
+
values: [String(t.priceMax)]
|
|
765
|
+
}), t.onSale && n.push({
|
|
766
|
+
key: Ve,
|
|
767
|
+
values: ["true"]
|
|
768
|
+
}), n;
|
|
769
|
+
}
|
|
770
|
+
function Ue(e, t) {
|
|
771
|
+
return {
|
|
772
|
+
...e,
|
|
773
|
+
filters: [...e.filters.filter((e) => e.exclude), ...He(t)]
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
function J(e) {
|
|
777
|
+
let t = {};
|
|
778
|
+
for (let n of e) {
|
|
779
|
+
if (n.exclude) continue;
|
|
780
|
+
let e = G.find((e) => e === n.key);
|
|
781
|
+
if (e) t[e] = [...t[e] ?? [], ...n.values];
|
|
782
|
+
else if (n.key === q || n.key === Be) {
|
|
783
|
+
let e = Number(n.values[0]);
|
|
784
|
+
Number.isFinite(e) && (t[n.key === q ? "priceMin" : "priceMax"] = e);
|
|
785
|
+
} else n.key === Ve && n.values[0] === "true" && (t.onSale = !0);
|
|
786
|
+
}
|
|
787
|
+
return K(t);
|
|
788
|
+
}
|
|
789
|
+
// src/search/core/composePage.ts
|
|
790
|
+
function Y(e = null) {
|
|
791
|
+
return {
|
|
792
|
+
order: [],
|
|
793
|
+
sections: {},
|
|
794
|
+
layoutReceived: !1,
|
|
795
|
+
followUps: [],
|
|
796
|
+
replied: !1,
|
|
797
|
+
mode: e,
|
|
798
|
+
failed: !1,
|
|
799
|
+
completed: !1
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
function We(e) {
|
|
803
|
+
return e.order.length > 0 || e.followUps.length > 0;
|
|
804
|
+
}
|
|
805
|
+
function Ge(e) {
|
|
806
|
+
return e.replied || e.completed;
|
|
807
|
+
}
|
|
808
|
+
function X(e, t) {
|
|
809
|
+
switch (t.type) {
|
|
810
|
+
case "layout": {
|
|
811
|
+
let n = {};
|
|
812
|
+
for (let r of t.sectionIds) {
|
|
813
|
+
let t = e.sections[r];
|
|
814
|
+
t && (n[r] = t);
|
|
815
|
+
}
|
|
816
|
+
return {
|
|
817
|
+
...e,
|
|
818
|
+
order: t.sectionIds,
|
|
819
|
+
sections: n,
|
|
820
|
+
layoutReceived: !0
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
case "section": {
|
|
824
|
+
let { section: n } = t;
|
|
825
|
+
return e.layoutReceived && !e.order.includes(n.id) ? e : {
|
|
826
|
+
...e,
|
|
827
|
+
order: e.order.includes(n.id) ? e.order : [...e.order, n.id],
|
|
828
|
+
sections: {
|
|
829
|
+
...e.sections,
|
|
830
|
+
[n.id]: n
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
case "text_delta": {
|
|
835
|
+
let n = e.sections[t.sectionId];
|
|
836
|
+
if (!n && e.layoutReceived && !e.order.includes(t.sectionId)) return e;
|
|
837
|
+
let r = n ? {
|
|
838
|
+
...n,
|
|
839
|
+
text: n.text + t.text
|
|
840
|
+
} : {
|
|
841
|
+
id: t.sectionId,
|
|
842
|
+
kind: "intro",
|
|
843
|
+
title: "",
|
|
844
|
+
pending: !1,
|
|
845
|
+
text: t.text,
|
|
846
|
+
products: []
|
|
847
|
+
};
|
|
848
|
+
return {
|
|
849
|
+
...e,
|
|
850
|
+
order: e.order.includes(r.id) ? e.order : [...e.order, r.id],
|
|
851
|
+
sections: {
|
|
852
|
+
...e.sections,
|
|
853
|
+
[r.id]: r
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
case "follow_ups": return {
|
|
858
|
+
...e,
|
|
859
|
+
followUps: t.followUps,
|
|
860
|
+
replied: !0
|
|
861
|
+
};
|
|
862
|
+
case "error": return {
|
|
863
|
+
...e,
|
|
864
|
+
error: t.message || void 0,
|
|
865
|
+
failed: !0
|
|
866
|
+
};
|
|
867
|
+
case "completed": return {
|
|
868
|
+
...e,
|
|
869
|
+
completed: !0,
|
|
870
|
+
mode: e.mode ?? "discovery",
|
|
871
|
+
failed: e.failed || t.failed
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
// src/helpers/request/sse.ts
|
|
876
|
+
var Ke = class extends Error {
|
|
877
|
+
constructor() {
|
|
878
|
+
super("[stream] idle timeout"), this.name = "StreamIdleError";
|
|
879
|
+
}
|
|
880
|
+
}, qe = 3e4;
|
|
881
|
+
function Je(e) {
|
|
882
|
+
let t = [], n = e.endsWith("\r"), r = (n ? e.slice(0, -1) : e).replace(/\r\n?/g, "\n") + (n ? "\r" : ""), i = r.indexOf("\n\n");
|
|
883
|
+
for (; i !== -1;) {
|
|
884
|
+
let e = r.slice(0, i);
|
|
885
|
+
r = r.slice(i + 2);
|
|
886
|
+
let n = "message", a = [];
|
|
887
|
+
for (let t of e.split("\n")) t.startsWith(":") || (t.startsWith("event:") ? n = t.slice(6).trim() : t.startsWith("data:") && a.push(t.slice(5).replace(/^ /, "")));
|
|
888
|
+
a.length > 0 && t.push({
|
|
889
|
+
event: n,
|
|
890
|
+
data: a.join("\n")
|
|
891
|
+
}), i = r.indexOf("\n\n");
|
|
892
|
+
}
|
|
893
|
+
return {
|
|
894
|
+
frames: t,
|
|
895
|
+
rest: r
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
async function Ye(e, t, n = qe) {
|
|
899
|
+
let r = e.getReader(), i = new TextDecoder(), a = "", o = !1, s, c = () => {
|
|
900
|
+
s && clearTimeout(s), s = setTimeout(() => {
|
|
901
|
+
o = !0, r.cancel().catch(() => {});
|
|
902
|
+
}, n);
|
|
903
|
+
}, l = !1;
|
|
904
|
+
try {
|
|
905
|
+
for (c(); !l;) {
|
|
906
|
+
let { value: e, done: n } = await r.read();
|
|
907
|
+
if (n) break;
|
|
908
|
+
c(), a += i.decode(e, { stream: !0 });
|
|
909
|
+
let o = Je(a);
|
|
910
|
+
a = o.rest;
|
|
911
|
+
for (let e of o.frames) if (t(e)) {
|
|
912
|
+
l = !0;
|
|
913
|
+
break;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
} finally {
|
|
917
|
+
s && clearTimeout(s), r.cancel().catch(() => {});
|
|
918
|
+
}
|
|
919
|
+
if (o && !l) throw new Ke();
|
|
920
|
+
}
|
|
921
|
+
// src/search/core/stream.ts
|
|
922
|
+
var Xe = [
|
|
923
|
+
"intro",
|
|
924
|
+
"picks",
|
|
925
|
+
"carousel",
|
|
926
|
+
"grid"
|
|
927
|
+
], Ze = [
|
|
928
|
+
"search",
|
|
929
|
+
"discovery",
|
|
930
|
+
"conversational"
|
|
931
|
+
], Qe = [
|
|
932
|
+
"relevance",
|
|
933
|
+
"best_selling",
|
|
934
|
+
"newest",
|
|
935
|
+
"cheapest",
|
|
936
|
+
"most_expensive",
|
|
937
|
+
"biggest_discount"
|
|
938
|
+
], $e = (e) => Qe.find((t) => t === e) ?? "relevance";
|
|
939
|
+
function Z(e) {
|
|
940
|
+
return {
|
|
941
|
+
terms: e?.terms ?? [],
|
|
942
|
+
excludedTerms: e?.excluded_terms ?? [],
|
|
943
|
+
filters: (e?.filters ?? []).map((e) => {
|
|
944
|
+
let t = {
|
|
945
|
+
key: e.key ?? "",
|
|
946
|
+
values: e.values ?? []
|
|
947
|
+
};
|
|
948
|
+
return Array.isArray(e.labels) && e.labels.length === t.values.length && (t.labels = e.labels), e.exclude && (t.exclude = !0), t;
|
|
949
|
+
}),
|
|
950
|
+
sort: $e(e?.sort)
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
function et(e) {
|
|
954
|
+
return {
|
|
955
|
+
terms: e.terms,
|
|
956
|
+
excluded_terms: e.excludedTerms,
|
|
957
|
+
filters: e.filters.map((e) => ({
|
|
958
|
+
key: e.key,
|
|
959
|
+
values: e.values,
|
|
960
|
+
exclude: e.exclude === !0
|
|
961
|
+
})),
|
|
962
|
+
sort: e.sort
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
function tt(e) {
|
|
966
|
+
let t = {
|
|
967
|
+
id: e.id ?? "",
|
|
968
|
+
kind: Xe.find((t) => t === e.kind) ?? "grid",
|
|
969
|
+
title: e.title ?? "",
|
|
970
|
+
pending: e.pending === !0,
|
|
971
|
+
text: e.text ?? "",
|
|
972
|
+
products: (e.products ?? []).map(z)
|
|
973
|
+
};
|
|
974
|
+
return e.see_all && (t.seeAll = Z(e.see_all)), t;
|
|
975
|
+
}
|
|
976
|
+
function nt(e) {
|
|
977
|
+
return (e ?? []).map((e) => ({
|
|
978
|
+
key: e.key ?? "",
|
|
979
|
+
values: (e.values ?? []).map((e) => ({
|
|
980
|
+
value: e.value ?? "",
|
|
981
|
+
label: e.label ?? e.value ?? "",
|
|
982
|
+
available: e.available !== !1
|
|
983
|
+
}))
|
|
984
|
+
}));
|
|
985
|
+
}
|
|
986
|
+
function rt(e) {
|
|
987
|
+
let t;
|
|
988
|
+
try {
|
|
989
|
+
let n = JSON.parse(e.data);
|
|
990
|
+
if (typeof n != "object" || !n) return null;
|
|
991
|
+
t = n;
|
|
992
|
+
} catch {
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
switch (e.event) {
|
|
996
|
+
case "started": return {
|
|
997
|
+
type: "started",
|
|
998
|
+
contextId: typeof t.context_id == "string" ? t.context_id : "",
|
|
999
|
+
turn: typeof t.turn == "number" ? t.turn : 0
|
|
1000
|
+
};
|
|
1001
|
+
case "mode": {
|
|
1002
|
+
let e = Ze.find((e) => e === t.mode);
|
|
1003
|
+
return e ? {
|
|
1004
|
+
type: "mode",
|
|
1005
|
+
mode: e
|
|
1006
|
+
} : null;
|
|
1007
|
+
}
|
|
1008
|
+
case "state": return {
|
|
1009
|
+
type: "state",
|
|
1010
|
+
state: Z(t.state)
|
|
1011
|
+
};
|
|
1012
|
+
case "facets": return {
|
|
1013
|
+
type: "facets",
|
|
1014
|
+
facets: nt(Array.isArray(t.facets) ? t.facets : void 0)
|
|
1015
|
+
};
|
|
1016
|
+
case "question": return typeof t.text != "string" || !t.text ? null : {
|
|
1017
|
+
type: "question",
|
|
1018
|
+
text: t.text,
|
|
1019
|
+
answers: Array.isArray(t.answers) ? t.answers.filter((e) => typeof e == "string") : []
|
|
1020
|
+
};
|
|
1021
|
+
case "grid": {
|
|
1022
|
+
let e = {
|
|
1023
|
+
products: (t.products ?? []).map(z),
|
|
1024
|
+
total: typeof t.total == "number" ? t.total : 0
|
|
1025
|
+
};
|
|
1026
|
+
return typeof t.next_page_token == "string" && t.next_page_token && (e.nextPageToken = t.next_page_token), e.total < e.products.length && (e.total = e.products.length), {
|
|
1027
|
+
type: "grid",
|
|
1028
|
+
grid: e
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
case "layout": {
|
|
1032
|
+
let e = t.section_ids;
|
|
1033
|
+
return {
|
|
1034
|
+
type: "layout",
|
|
1035
|
+
sectionIds: Array.isArray(e) ? e.filter((e) => typeof e == "string") : []
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
case "section": return {
|
|
1039
|
+
type: "section",
|
|
1040
|
+
section: tt(t)
|
|
1041
|
+
};
|
|
1042
|
+
case "text_delta": return {
|
|
1043
|
+
type: "text_delta",
|
|
1044
|
+
sectionId: typeof t.section_id == "string" ? t.section_id : "",
|
|
1045
|
+
text: typeof t.text == "string" ? t.text : ""
|
|
1046
|
+
};
|
|
1047
|
+
case "follow_ups": {
|
|
1048
|
+
let e = t.follow_ups;
|
|
1049
|
+
return {
|
|
1050
|
+
type: "follow_ups",
|
|
1051
|
+
followUps: Array.isArray(e) ? e.filter((e) => typeof e == "string") : []
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
case "error": return {
|
|
1055
|
+
type: "error",
|
|
1056
|
+
errorType: typeof t.type == "string" ? t.type : "",
|
|
1057
|
+
message: typeof t.message == "string" ? t.message : ""
|
|
1058
|
+
};
|
|
1059
|
+
case "completed": return {
|
|
1060
|
+
type: "completed",
|
|
1061
|
+
failed: t.failed === !0
|
|
1062
|
+
};
|
|
1063
|
+
default: return null;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
function it(e) {
|
|
1067
|
+
return e.type === "layout" || e.type === "section" || e.type === "text_delta" || e.type === "follow_ups";
|
|
1068
|
+
}
|
|
1069
|
+
async function at(e, t, { signal: n, onEvent: r, idleMs: i }) {
|
|
1070
|
+
let a = t.baseUrl ?? "https://cgw.ecomid.com", o = {
|
|
1071
|
+
market: t.market,
|
|
1072
|
+
locale: L(t.lang)
|
|
1073
|
+
};
|
|
1074
|
+
t.contextId && (o.context_id = t.contextId), t.limit !== void 0 && (o.limit = t.limit), t.pageToken ? o.page_token = t.pageToken : t.state ? o.state = et(t.state) : t.text && (o.text = t.text);
|
|
1075
|
+
let s = await S(`${a}/v0/search/${e}/results${R() ? "?preview=true" : ""}`, {
|
|
1076
|
+
method: "POST",
|
|
1077
|
+
headers: {
|
|
1078
|
+
"Content-Type": "application/json",
|
|
1079
|
+
Accept: "text/event-stream"
|
|
1080
|
+
},
|
|
1081
|
+
body: JSON.stringify(o),
|
|
1082
|
+
signal: n
|
|
1083
|
+
});
|
|
1084
|
+
if (!s.ok) throw await s.body?.cancel().catch(() => {}), new c(`search results request failed with status ${s.status}`, s.status);
|
|
1085
|
+
if (!s.body) throw new c("search results response has no body", s.status);
|
|
1086
|
+
let l = !1;
|
|
1087
|
+
return await Ye(s.body, (e) => {
|
|
1088
|
+
let t = rt(e);
|
|
1089
|
+
return t ? (r(t), t.type === "completed" && (l = !0, !0)) : !1;
|
|
1090
|
+
}, i), l;
|
|
1091
|
+
}
|
|
1092
|
+
function Q(e, t, n = {}) {
|
|
1093
|
+
let r = n.state ?? Z(void 0), i = {
|
|
1094
|
+
query: t.query,
|
|
1095
|
+
lang: t.lang,
|
|
1096
|
+
market: t.market,
|
|
1097
|
+
products: e.products,
|
|
1098
|
+
total: e.total,
|
|
1099
|
+
appliedFilters: r.filters.map((e) => {
|
|
1100
|
+
let t = {
|
|
1101
|
+
key: e.key,
|
|
1102
|
+
values: e.values,
|
|
1103
|
+
labels: e.labels ?? e.values.map(ye)
|
|
1104
|
+
};
|
|
1105
|
+
return e.exclude && (t.exclude = !0), t;
|
|
1106
|
+
}),
|
|
1107
|
+
facets: n.facets ?? [],
|
|
1108
|
+
state: r
|
|
1109
|
+
};
|
|
1110
|
+
return t.limit !== void 0 && (i.limit = t.limit), t.page && (i.page = t.page), e.nextPageToken && (i.nextPageToken = e.nextPageToken), i;
|
|
1111
|
+
}
|
|
1112
|
+
async function ot(e, t, n) {
|
|
1113
|
+
let r = t.page === void 0 ? null : N(t.page), i = r ? F(r) : (t.query ?? "").trim(), a = {
|
|
1114
|
+
market: t.market,
|
|
1115
|
+
lang: t.lang,
|
|
1116
|
+
limit: t.limit,
|
|
1117
|
+
baseUrl: t.baseUrl
|
|
1118
|
+
};
|
|
1119
|
+
r?.kind === "search" ? a.state = r.state : r ? a.text = r.text : i && (a.text = i);
|
|
1120
|
+
let o = new AbortController(), s = () => o.abort();
|
|
1121
|
+
n?.addEventListener("abort", s, { once: !0 });
|
|
1122
|
+
let c, l, u = !1, d = {};
|
|
1123
|
+
try {
|
|
1124
|
+
await at(e, a, {
|
|
1125
|
+
signal: o.signal,
|
|
1126
|
+
onEvent: (e) => {
|
|
1127
|
+
e.type === "mode" && e.mode !== "search" && (u = !0, o.abort()), e.type === "grid" && (c = e.grid), e.type === "state" && (d.state = e.state), e.type === "facets" && (d.facets = e.facets), e.type === "error" && (l = e.message), e.type === "completed" && e.failed && (l ??= "search failed"), c && d.facets && o.abort();
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
} catch (e) {
|
|
1131
|
+
if (!(e instanceof Error && e.name === "AbortError") || n?.aborted || !c && !u) throw e;
|
|
1132
|
+
} finally {
|
|
1133
|
+
n?.removeEventListener("abort", s);
|
|
1134
|
+
}
|
|
1135
|
+
if (u) throw Error("search did not return a results grid");
|
|
1136
|
+
if (!c) throw Error(l ?? "search returned no results");
|
|
1137
|
+
return Q(c, {
|
|
1138
|
+
query: i,
|
|
1139
|
+
lang: t.lang,
|
|
1140
|
+
market: t.market,
|
|
1141
|
+
limit: t.limit,
|
|
1142
|
+
page: r ? P(r) : void 0
|
|
1143
|
+
}, d);
|
|
1144
|
+
}
|
|
1145
|
+
function st(e) {
|
|
1146
|
+
if (e == null) return null;
|
|
1147
|
+
let t = N(e);
|
|
1148
|
+
return t && F(t) ? t : null;
|
|
1149
|
+
}
|
|
1150
|
+
function ct(e) {
|
|
1151
|
+
let t = F(e), n = P(e);
|
|
1152
|
+
return e.kind === "compose" ? {
|
|
1153
|
+
text: t,
|
|
1154
|
+
fresh: !0,
|
|
1155
|
+
pageKey: n
|
|
1156
|
+
} : {
|
|
1157
|
+
text: t,
|
|
1158
|
+
state: e.state,
|
|
1159
|
+
fresh: !0,
|
|
1160
|
+
pageKey: n
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
function lt(e) {
|
|
1164
|
+
return e === "discovery" ? "discovery" : e === "conversational" ? "conversation" : null;
|
|
1165
|
+
}
|
|
1166
|
+
function ut(e) {
|
|
1167
|
+
return e instanceof Error && e.name === "AbortError";
|
|
1168
|
+
}
|
|
1169
|
+
function dt(e) {
|
|
1170
|
+
return e instanceof Error ? e : Error(String(e));
|
|
1171
|
+
}
|
|
1172
|
+
function $(e, { query: t, lang: n, market: r, limit: i, page: a }) {
|
|
1173
|
+
return !!t && !!e && typeof e.query == "string" && e.query.trim() === t && e.lang === n && e.market === r && e.limit === i && (e.page ?? "") === (a ?? "");
|
|
1174
|
+
}
|
|
1175
|
+
function ft(e) {
|
|
1176
|
+
let { clientId: t, market: n, lang: r, baseUrl: i, limit: a, initialResults: o } = e, s = e.fetchers?.streamSearch ?? at, c = a ?? 24, l = /* @__PURE__ */ new Set(), u = st(e.page), d = u ? F(u) : e.query.trim(), f = "relevance", p = {}, m = u, h = u ? P(u) : null, g = (e, t, i) => $(e, {
|
|
1177
|
+
query: t,
|
|
1178
|
+
lang: r,
|
|
1179
|
+
market: n,
|
|
1180
|
+
limit: a,
|
|
1181
|
+
page: i ? P(i) : void 0
|
|
1182
|
+
}), _ = g(o, d, u) ? o : null, v = {
|
|
1183
|
+
query: d,
|
|
1184
|
+
title: d,
|
|
1185
|
+
status: d ? _ ? "success" : "loading" : "idle",
|
|
1186
|
+
results: _,
|
|
1187
|
+
error: null,
|
|
1188
|
+
sort: _?.state?.sort ?? f,
|
|
1189
|
+
filters: J(_?.state?.filters ?? []),
|
|
1190
|
+
loadingMore: !1,
|
|
1191
|
+
moreError: null,
|
|
1192
|
+
surface: "grid",
|
|
1193
|
+
pending: !d || _ ? null : "results",
|
|
1194
|
+
turns: [],
|
|
1195
|
+
page: Y(),
|
|
1196
|
+
archive: {},
|
|
1197
|
+
gridArchive: {},
|
|
1198
|
+
activeTurn: 0,
|
|
1199
|
+
followUps: []
|
|
1200
|
+
}, y, b = 0, x = null;
|
|
1201
|
+
function S(e) {
|
|
1202
|
+
v = {
|
|
1203
|
+
...v,
|
|
1204
|
+
...e,
|
|
1205
|
+
...e.page && { archive: {
|
|
1206
|
+
...e.archive ?? v.archive,
|
|
1207
|
+
[b]: e.page
|
|
1208
|
+
} }
|
|
1209
|
+
}, e.results && v.surface === "grid" && v.activeTurn > 0 && (v.gridArchive = {
|
|
1210
|
+
...v.gridArchive,
|
|
1211
|
+
[v.activeTurn]: {
|
|
1212
|
+
query: v.query,
|
|
1213
|
+
title: v.title,
|
|
1214
|
+
results: e.results,
|
|
1215
|
+
sort: v.sort,
|
|
1216
|
+
filters: v.filters
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
for (let e of l) e();
|
|
1220
|
+
}
|
|
1221
|
+
function C() {
|
|
1222
|
+
y?.abort(), y = void 0;
|
|
1223
|
+
}
|
|
1224
|
+
function w() {
|
|
1225
|
+
return v.surface === "compose" && v.page.state ? v.page.state : v.results?.state ?? {
|
|
1226
|
+
terms: v.query ? [v.query] : [],
|
|
1227
|
+
excludedTerms: [],
|
|
1228
|
+
filters: He(v.filters),
|
|
1229
|
+
sort: v.sort
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
function T(e, t = w()) {
|
|
1233
|
+
return Ue(t, e);
|
|
1234
|
+
}
|
|
1235
|
+
function E(e, t) {
|
|
1236
|
+
let n = new Set(e.products.map((e) => e.id)), r = t.products.filter((e) => !n.has(e.id)), i = {
|
|
1237
|
+
...e,
|
|
1238
|
+
products: [...e.products, ...r],
|
|
1239
|
+
total: t.total
|
|
1240
|
+
};
|
|
1241
|
+
return e.sections && r.length > 0 && (i.sections = [...e.sections, { products: r }]), t.nextPageToken && r.length > 0 ? i.nextPageToken = t.nextPageToken : delete i.nextPageToken, i;
|
|
1242
|
+
}
|
|
1243
|
+
async function D(e) {
|
|
1244
|
+
C(), m = null, h = e.pageKey ?? null;
|
|
1245
|
+
let a = ++b, o = new AbortController();
|
|
1246
|
+
y = o;
|
|
1247
|
+
let l = e.pageToken !== void 0, u = e.fresh ? void 0 : v.contextId, d = !1, g, _ = !1, w = () => a === b, T = e.text !== void 0, D = T && e.text !== void 0 ? {
|
|
1248
|
+
text: e.text,
|
|
1249
|
+
fresh: e.fresh === !0
|
|
1250
|
+
} : null, O = !1;
|
|
1251
|
+
x = D ? D.text : null;
|
|
1252
|
+
let k = () => {
|
|
1253
|
+
if (!D) return;
|
|
1254
|
+
let { text: e, fresh: t } = D;
|
|
1255
|
+
D = null, x = null;
|
|
1256
|
+
let n = t || O;
|
|
1257
|
+
S({
|
|
1258
|
+
query: e,
|
|
1259
|
+
title: !n && v.surface === "grid" && v.title ? v.title : e,
|
|
1260
|
+
turns: [...n ? [] : v.turns, {
|
|
1261
|
+
id: a,
|
|
1262
|
+
text: e
|
|
1263
|
+
}],
|
|
1264
|
+
activeTurn: a,
|
|
1265
|
+
page: Y(!n && v.surface === "compose" ? v.page.mode : null),
|
|
1266
|
+
...n && {
|
|
1267
|
+
archive: {},
|
|
1268
|
+
gridArchive: {}
|
|
1269
|
+
},
|
|
1270
|
+
...t && {
|
|
1271
|
+
sort: f,
|
|
1272
|
+
filters: p
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
};
|
|
1276
|
+
S(l ? {
|
|
1277
|
+
loadingMore: !0,
|
|
1278
|
+
moreError: null
|
|
1279
|
+
} : {
|
|
1280
|
+
pending: T ? "results" : null,
|
|
1281
|
+
status: "loading",
|
|
1282
|
+
error: null,
|
|
1283
|
+
loadingMore: !1,
|
|
1284
|
+
moreError: null,
|
|
1285
|
+
followUps: [],
|
|
1286
|
+
question: void 0,
|
|
1287
|
+
mode: void 0
|
|
1288
|
+
});
|
|
1289
|
+
let A = {
|
|
1290
|
+
market: n,
|
|
1291
|
+
lang: r,
|
|
1292
|
+
baseUrl: i,
|
|
1293
|
+
limit: c,
|
|
1294
|
+
contextId: u
|
|
1295
|
+
};
|
|
1296
|
+
l ? A.pageToken = e.pageToken : e.state ? A.state = e.state : e.text !== void 0 && (A.text = e.text);
|
|
1297
|
+
let j = !1, M = !1, N = {}, P = (e) => ({
|
|
1298
|
+
...e,
|
|
1299
|
+
...N.state && { state: N.state },
|
|
1300
|
+
...N.facets && { facets: N.facets }
|
|
1301
|
+
});
|
|
1302
|
+
function F(e) {
|
|
1303
|
+
if (w()) {
|
|
1304
|
+
if (e.type === "started") {
|
|
1305
|
+
d = !0;
|
|
1306
|
+
let t = !!u && !!e.contextId && e.contextId !== u;
|
|
1307
|
+
t && (O = !0), S({
|
|
1308
|
+
contextId: e.contextId || void 0,
|
|
1309
|
+
turnNumber: e.turn,
|
|
1310
|
+
...t && !D && {
|
|
1311
|
+
turns: v.turns.filter((e) => e.id === a),
|
|
1312
|
+
archive: v.archive[a] ? { [a]: v.archive[a] } : {},
|
|
1313
|
+
gridArchive: v.gridArchive[a] ? { [a]: v.gridArchive[a] } : {}
|
|
1314
|
+
}
|
|
1315
|
+
});
|
|
1316
|
+
} else if (e.type === "mode") {
|
|
1317
|
+
if (l) return;
|
|
1318
|
+
S({ mode: e.mode });
|
|
1319
|
+
let t = lt(e.mode);
|
|
1320
|
+
if (M && t && v.surface === "compose") {
|
|
1321
|
+
S({ page: {
|
|
1322
|
+
...v.page,
|
|
1323
|
+
mode: t
|
|
1324
|
+
} });
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
if (!D || j || M) return;
|
|
1328
|
+
let n = !D.fresh && !O && v.surface === "grid" && !!v.results;
|
|
1329
|
+
if (!t && n) return;
|
|
1330
|
+
k(), t ? (M = !0, S({
|
|
1331
|
+
surface: "compose",
|
|
1332
|
+
pending: null,
|
|
1333
|
+
page: P({
|
|
1334
|
+
...v.page,
|
|
1335
|
+
mode: t
|
|
1336
|
+
})
|
|
1337
|
+
})) : S({
|
|
1338
|
+
surface: "grid",
|
|
1339
|
+
results: null,
|
|
1340
|
+
pending: "grid"
|
|
1341
|
+
});
|
|
1342
|
+
} else if (e.type === "question") {
|
|
1343
|
+
let t = {
|
|
1344
|
+
text: e.text,
|
|
1345
|
+
answers: e.answers
|
|
1346
|
+
};
|
|
1347
|
+
if (v.surface === "compose" || !j) {
|
|
1348
|
+
k();
|
|
1349
|
+
let n = v.surface === "compose" ? v.page : Y(), r = !M;
|
|
1350
|
+
M = !0, S({
|
|
1351
|
+
question: t,
|
|
1352
|
+
surface: "compose",
|
|
1353
|
+
pending: null,
|
|
1354
|
+
status: "success",
|
|
1355
|
+
page: {
|
|
1356
|
+
...r ? P(n) : n,
|
|
1357
|
+
question: e.text,
|
|
1358
|
+
followUps: e.answers,
|
|
1359
|
+
replied: !0,
|
|
1360
|
+
mode: "conversation"
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
S({ question: t });
|
|
1366
|
+
} else if (e.type === "state") {
|
|
1367
|
+
if (N.state = e.state, M && v.surface === "compose") {
|
|
1368
|
+
S({ page: {
|
|
1369
|
+
...v.page,
|
|
1370
|
+
state: e.state
|
|
1371
|
+
} });
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
if (j && !l && v.results) {
|
|
1375
|
+
let t = v.results;
|
|
1376
|
+
S({
|
|
1377
|
+
results: Q({
|
|
1378
|
+
products: t.products,
|
|
1379
|
+
total: t.total ?? t.products.length,
|
|
1380
|
+
nextPageToken: t.nextPageToken
|
|
1381
|
+
}, {
|
|
1382
|
+
query: v.query,
|
|
1383
|
+
lang: r,
|
|
1384
|
+
market: n,
|
|
1385
|
+
limit: c
|
|
1386
|
+
}, {
|
|
1387
|
+
state: e.state,
|
|
1388
|
+
facets: t.facets
|
|
1389
|
+
}),
|
|
1390
|
+
sort: e.state.sort,
|
|
1391
|
+
filters: J(e.state.filters)
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
} else if (e.type === "facets") {
|
|
1395
|
+
if (N.facets = e.facets, M && v.surface === "compose") {
|
|
1396
|
+
S({ page: {
|
|
1397
|
+
...v.page,
|
|
1398
|
+
facets: e.facets
|
|
1399
|
+
} });
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
j && v.results && S({ results: {
|
|
1403
|
+
...v.results,
|
|
1404
|
+
facets: e.facets
|
|
1405
|
+
} });
|
|
1406
|
+
} else if (e.type === "grid") {
|
|
1407
|
+
j = !0;
|
|
1408
|
+
let { grid: t } = e;
|
|
1409
|
+
if (l && v.results) {
|
|
1410
|
+
S({
|
|
1411
|
+
results: E(v.results, t),
|
|
1412
|
+
loadingMore: !1
|
|
1413
|
+
});
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
k();
|
|
1417
|
+
let i = Q(t, {
|
|
1418
|
+
query: v.query,
|
|
1419
|
+
lang: r,
|
|
1420
|
+
market: n,
|
|
1421
|
+
limit: c
|
|
1422
|
+
}, N);
|
|
1423
|
+
S({
|
|
1424
|
+
surface: "grid",
|
|
1425
|
+
pending: null,
|
|
1426
|
+
status: "success",
|
|
1427
|
+
results: i,
|
|
1428
|
+
sort: i.state?.sort ?? v.sort,
|
|
1429
|
+
filters: J(i.state?.filters ?? [])
|
|
1430
|
+
});
|
|
1431
|
+
} else if (e.type === "error") g = e.message || e.errorType || "search failed", (v.surface === "compose" || We(v.page)) && S({ page: X(v.page, e) });
|
|
1432
|
+
else if (e.type === "completed") {
|
|
1433
|
+
if (_ = !0, k(), v.pending && S({ pending: null }), v.surface === "compose" && !l) {
|
|
1434
|
+
S({
|
|
1435
|
+
page: X(v.page, e),
|
|
1436
|
+
status: "success"
|
|
1437
|
+
});
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
if (e.failed) {
|
|
1441
|
+
let e = Error(g ?? "search failed");
|
|
1442
|
+
l ? S({
|
|
1443
|
+
loadingMore: !1,
|
|
1444
|
+
moreError: e
|
|
1445
|
+
}) : (k(), S({
|
|
1446
|
+
status: "error",
|
|
1447
|
+
error: e,
|
|
1448
|
+
pending: null
|
|
1449
|
+
}));
|
|
1450
|
+
} else l && S({ loadingMore: !1 });
|
|
1451
|
+
} else if (it(e)) {
|
|
1452
|
+
if (e.type === "follow_ups" && j) {
|
|
1453
|
+
S({ followUps: e.followUps });
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
k();
|
|
1457
|
+
let t = X(v.surface === "compose" ? v.page : Y(), e), n = lt(v.mode), r = n ? {
|
|
1458
|
+
...t,
|
|
1459
|
+
mode: n
|
|
1460
|
+
} : t, i = !M;
|
|
1461
|
+
M = !0, S({
|
|
1462
|
+
surface: "compose",
|
|
1463
|
+
pending: null,
|
|
1464
|
+
status: "success",
|
|
1465
|
+
page: i ? P(r) : r
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
try {
|
|
1471
|
+
let e = await s(t, A, {
|
|
1472
|
+
signal: o.signal,
|
|
1473
|
+
onEvent: F
|
|
1474
|
+
});
|
|
1475
|
+
if (!w()) return;
|
|
1476
|
+
if (y = void 0, !e && !_) {
|
|
1477
|
+
let e = /* @__PURE__ */ Error("search stream ended early");
|
|
1478
|
+
l ? S({
|
|
1479
|
+
loadingMore: !1,
|
|
1480
|
+
moreError: e
|
|
1481
|
+
}) : v.surface === "compose" ? S({
|
|
1482
|
+
page: X(v.page, {
|
|
1483
|
+
type: "completed",
|
|
1484
|
+
failed: !0
|
|
1485
|
+
}),
|
|
1486
|
+
status: "success"
|
|
1487
|
+
}) : (k(), S({
|
|
1488
|
+
status: "error",
|
|
1489
|
+
error: e,
|
|
1490
|
+
pending: null
|
|
1491
|
+
}));
|
|
1492
|
+
}
|
|
1493
|
+
} catch (e) {
|
|
1494
|
+
if (!w() || ut(e) || (y = void 0, _)) return;
|
|
1495
|
+
let t = dt(e);
|
|
1496
|
+
l ? S({
|
|
1497
|
+
loadingMore: !1,
|
|
1498
|
+
moreError: t
|
|
1499
|
+
}) : d && v.surface === "compose" ? S({
|
|
1500
|
+
page: X(v.page, {
|
|
1501
|
+
type: "completed",
|
|
1502
|
+
failed: !0
|
|
1503
|
+
}),
|
|
1504
|
+
status: "success"
|
|
1505
|
+
}) : (k(), S({
|
|
1506
|
+
status: "error",
|
|
1507
|
+
error: t,
|
|
1508
|
+
pending: null
|
|
1509
|
+
}));
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
function O(e, t, n) {
|
|
1513
|
+
C(), b += 1, m = null, h = n, S({
|
|
1514
|
+
query: e,
|
|
1515
|
+
title: e,
|
|
1516
|
+
status: "success",
|
|
1517
|
+
results: t,
|
|
1518
|
+
error: null,
|
|
1519
|
+
sort: t.state?.sort ?? f,
|
|
1520
|
+
filters: J(t.state?.filters ?? []),
|
|
1521
|
+
loadingMore: !1,
|
|
1522
|
+
moreError: null,
|
|
1523
|
+
surface: "grid",
|
|
1524
|
+
pending: null,
|
|
1525
|
+
contextId: void 0,
|
|
1526
|
+
turns: [],
|
|
1527
|
+
archive: {},
|
|
1528
|
+
gridArchive: {},
|
|
1529
|
+
activeTurn: 0,
|
|
1530
|
+
followUps: [],
|
|
1531
|
+
mode: void 0,
|
|
1532
|
+
question: void 0
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
function k() {
|
|
1536
|
+
C(), b += 1, m = null, h = null, S({
|
|
1537
|
+
query: "",
|
|
1538
|
+
title: "",
|
|
1539
|
+
status: "idle",
|
|
1540
|
+
results: null,
|
|
1541
|
+
error: null,
|
|
1542
|
+
sort: f,
|
|
1543
|
+
filters: p,
|
|
1544
|
+
loadingMore: !1,
|
|
1545
|
+
moreError: null,
|
|
1546
|
+
surface: "grid",
|
|
1547
|
+
pending: null,
|
|
1548
|
+
contextId: void 0,
|
|
1549
|
+
turns: [],
|
|
1550
|
+
archive: {},
|
|
1551
|
+
gridArchive: {},
|
|
1552
|
+
activeTurn: 0,
|
|
1553
|
+
followUps: [],
|
|
1554
|
+
mode: void 0,
|
|
1555
|
+
question: void 0
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
function A(e, t) {
|
|
1559
|
+
let n = e.trim();
|
|
1560
|
+
if (g(t, n)) {
|
|
1561
|
+
if (v.status === "success" && v.query === n && v.results === t) return;
|
|
1562
|
+
O(n, t, null);
|
|
1563
|
+
} else n !== v.query && n !== x && (n ? D({
|
|
1564
|
+
text: n,
|
|
1565
|
+
fresh: !0
|
|
1566
|
+
}) : k());
|
|
1567
|
+
}
|
|
1568
|
+
function j() {
|
|
1569
|
+
return !v.query || v.status !== "success" ? null : v.surface === "compose" ? {
|
|
1570
|
+
kind: "compose",
|
|
1571
|
+
text: v.title
|
|
1572
|
+
} : v.results ? {
|
|
1573
|
+
kind: "search",
|
|
1574
|
+
state: v.results.state ?? w()
|
|
1575
|
+
} : null;
|
|
1576
|
+
}
|
|
1577
|
+
function M(e, t) {
|
|
1578
|
+
let n = st(e);
|
|
1579
|
+
if (!n) {
|
|
1580
|
+
v.query && k();
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
let r = P(n);
|
|
1584
|
+
if (r === h) return;
|
|
1585
|
+
let i = j();
|
|
1586
|
+
if (i && P(i) === r) {
|
|
1587
|
+
h = r;
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
let a = F(n);
|
|
1591
|
+
g(t, a, n) ? O(a, t, r) : D(ct(n));
|
|
1592
|
+
}
|
|
1593
|
+
function N(e) {
|
|
1594
|
+
let a = v.gridArchive[e];
|
|
1595
|
+
a && v.activeTurn !== e && (C(), b += 1, S({
|
|
1596
|
+
...a,
|
|
1597
|
+
status: "success",
|
|
1598
|
+
error: null,
|
|
1599
|
+
surface: "grid",
|
|
1600
|
+
pending: null,
|
|
1601
|
+
loadingMore: !1,
|
|
1602
|
+
moreError: null,
|
|
1603
|
+
followUps: [],
|
|
1604
|
+
activeTurn: e
|
|
1605
|
+
}), a.results.state && s(t, {
|
|
1606
|
+
market: n,
|
|
1607
|
+
lang: r,
|
|
1608
|
+
baseUrl: i,
|
|
1609
|
+
limit: 1,
|
|
1610
|
+
contextId: v.contextId,
|
|
1611
|
+
state: a.results.state
|
|
1612
|
+
}, {
|
|
1613
|
+
signal: new AbortController().signal,
|
|
1614
|
+
onEvent: () => {}
|
|
1615
|
+
}).catch(() => {}));
|
|
1616
|
+
}
|
|
1617
|
+
function ee(e) {
|
|
1618
|
+
let t = e.trim();
|
|
1619
|
+
t && D({ text: t });
|
|
1620
|
+
}
|
|
1621
|
+
function I(e) {
|
|
1622
|
+
(v.query || v.results) && D({ state: e });
|
|
1623
|
+
}
|
|
1624
|
+
function L(e) {
|
|
1625
|
+
let t = w();
|
|
1626
|
+
t.terms.includes(e) && I({
|
|
1627
|
+
...t,
|
|
1628
|
+
terms: t.terms.filter((t) => t !== e)
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
function R(e) {
|
|
1632
|
+
let t = w();
|
|
1633
|
+
t.excludedTerms.includes(e) && I({
|
|
1634
|
+
...t,
|
|
1635
|
+
excludedTerms: t.excludedTerms.filter((t) => t !== e)
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
function te(e) {
|
|
1639
|
+
let t = Ne(e);
|
|
1640
|
+
v.query && t !== v.sort && I({
|
|
1641
|
+
...w(),
|
|
1642
|
+
sort: t
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
function ne(e) {
|
|
1646
|
+
let t = K(e);
|
|
1647
|
+
v.query && !Fe(t, v.filters) && I(T(t));
|
|
1648
|
+
}
|
|
1649
|
+
function z() {
|
|
1650
|
+
let e = v.results?.nextPageToken;
|
|
1651
|
+
!v.query || !e || v.status !== "success" || v.loadingMore || v.moreError || y || D({ pageToken: e });
|
|
1652
|
+
}
|
|
1653
|
+
async function re(e, a, o) {
|
|
1654
|
+
let c = new AbortController(), l = () => c.abort();
|
|
1655
|
+
a?.addEventListener("abort", l, { once: !0 });
|
|
1656
|
+
let u;
|
|
1657
|
+
try {
|
|
1658
|
+
await s(t, {
|
|
1659
|
+
market: n,
|
|
1660
|
+
lang: r,
|
|
1661
|
+
baseUrl: i,
|
|
1662
|
+
limit: 1,
|
|
1663
|
+
state: T(K(e), o)
|
|
1664
|
+
}, {
|
|
1665
|
+
signal: c.signal,
|
|
1666
|
+
onEvent: (e) => {
|
|
1667
|
+
e.type === "grid" && (u = e.grid.total, c.abort());
|
|
1668
|
+
}
|
|
1669
|
+
});
|
|
1670
|
+
} catch (e) {
|
|
1671
|
+
if (u === void 0) throw e;
|
|
1672
|
+
} finally {
|
|
1673
|
+
a?.removeEventListener("abort", l);
|
|
1674
|
+
}
|
|
1675
|
+
if (u === void 0) throw Error("count returned no grid");
|
|
1676
|
+
return u;
|
|
1677
|
+
}
|
|
1678
|
+
function B() {
|
|
1679
|
+
v.query && v.status !== "success" && v.status !== "error" && !y && D(m ? ct(m) : {
|
|
1680
|
+
text: v.query,
|
|
1681
|
+
fresh: !0
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
function ie() {
|
|
1685
|
+
C(), b += 1, v = {
|
|
1686
|
+
...v,
|
|
1687
|
+
status: v.status === "loading" ? "idle" : v.status,
|
|
1688
|
+
loadingMore: !1
|
|
1689
|
+
}, l.clear();
|
|
1690
|
+
}
|
|
1691
|
+
return {
|
|
1692
|
+
getState: () => v,
|
|
1693
|
+
subscribe(e) {
|
|
1694
|
+
return l.add(e), () => {
|
|
1695
|
+
l.delete(e);
|
|
1696
|
+
};
|
|
1697
|
+
},
|
|
1698
|
+
setQuery: A,
|
|
1699
|
+
setPage: M,
|
|
1700
|
+
getPage: j,
|
|
1701
|
+
send: ee,
|
|
1702
|
+
jumpTo: N,
|
|
1703
|
+
setSort: te,
|
|
1704
|
+
setFilters: ne,
|
|
1705
|
+
applyState: I,
|
|
1706
|
+
removeTerm: L,
|
|
1707
|
+
removeExcludedTerm: R,
|
|
1708
|
+
loadMore: z,
|
|
1709
|
+
count: re,
|
|
1710
|
+
load: B,
|
|
1711
|
+
destroy: ie
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
export { ee as A, n as B, V as C, P as D, N as E, h as F, l as I, o as L, D as M, y as N, M as O, p as P, s as R, ve as S, j as T, e as V, J as _, We as a, Oe as b, ke as c, Re as d, Ie as f, Fe as g, Ne as h, Q as i, E as j, F as k, Ae as l, K as m, $ as n, Ge as o, Me as p, ot as r, je as s, ft as t, ze as u, Le as v, ae as w, ye as x, Ue as y, t as z };
|