@depict-ai/ui 4.10.31 → 4.10.33
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/ES10/index.cjs +1213 -20
- package/ES10/index.d.ts +102 -3
- package/ES10/index.js +1213 -22
- package/latest/index.cjs +1102 -18
- package/latest/index.d.ts +102 -3
- package/latest/index.js +1102 -20
- package/package.json +4 -4
- package/server/ES10/index.cjs +1213 -20
- package/server/ES10/index.d.ts +102 -3
- package/server/ES10/index.js +1213 -22
- package/server/latest/index.cjs +1102 -18
- package/server/latest/index.d.ts +102 -3
- package/server/latest/index.js +1102 -20
package/latest/index.cjs
CHANGED
|
@@ -91,6 +91,8 @@ $parcel$export(module.exports, "styles_to_valid_css_string", () => $2be658935c40
|
|
|
91
91
|
$parcel$export(module.exports, "disable_scrolling", () => $ca1176b694a6ee2e$export$fe334901e8bebd57);
|
|
92
92
|
$parcel$export(module.exports, "open_search_with_shift_slash", () => $5ab706c0a6d61264$export$d0596b5cae35ad4);
|
|
93
93
|
$parcel$export(module.exports, "DepictAPI", () => $e1d6c0f3d89d531c$export$e015ed2f2950f2e3);
|
|
94
|
+
$parcel$export(module.exports, "NativeDepictAPI", () => $100bd8804fbc65ac$export$721afe49a594bed);
|
|
95
|
+
$parcel$export(module.exports, "create_depict_api", () => $100bd8804fbc65ac$export$6d972e6af9de09f0);
|
|
94
96
|
$parcel$export(module.exports, "media_query_to_accessor", () => $b54e6192d0caa293$export$d9f36cf74e24d595);
|
|
95
97
|
$parcel$export(module.exports, "setup_fast_leave", () => $08e7f10b1831645f$export$689e204eadb33baf);
|
|
96
98
|
$parcel$export(module.exports, "show_toast", () => $ee498ec5e7dc2bba$export$5196e4c01fa56fcb);
|
|
@@ -109,7 +111,7 @@ $parcel$export(module.exports, "BreadCrumbs", () => $1f4925833f07df29$export$5b7
|
|
|
109
111
|
$parcel$export(module.exports, "QuickLinks", () => $1f4925833f07df29$export$de035477d6fef996);
|
|
110
112
|
$parcel$export(module.exports, "CategoryPage", () => $14f289047713d67a$export$e2bf8ce7779e827e);
|
|
111
113
|
/*! Depict.ai search and product listing SDK */
|
|
112
|
-
const $b757f75811f3261f$export$83d89fbfd8236492 = "4.10.
|
|
114
|
+
const $b757f75811f3261f$export$83d89fbfd8236492 = "4.10.33";
|
|
113
115
|
function $b54e6192d0caa293$export$d9f36cf74e24d595(media_query) {
|
|
114
116
|
const signal = $gVhhF$solidjs.createSignal(false);
|
|
115
117
|
$gVhhF$solidjs.onCleanup($gVhhF$depictaiutilishared.javascript_media_query(media_query, ({
|
|
@@ -8139,6 +8141,14 @@ function $32c662f618f5d80d$export$780a853d15174484({
|
|
|
8139
8141
|
}
|
|
8140
8142
|
}));
|
|
8141
8143
|
}
|
|
8144
|
+
|
|
8145
|
+
/** Shopify Lite's storefront (theme-static depict-content-blocks.js) treats screens up to 990px wide as phones. */
|
|
8146
|
+
const $05b9da7b91793a99$export$1e15d45642067bf0 = "(max-width: 990px)";
|
|
8147
|
+
function $05b9da7b91793a99$export$894065271726d798(visibility, isPhone) {
|
|
8148
|
+
if (visibility === "desktop") return !isPhone;
|
|
8149
|
+
if (visibility === "mobile") return isPhone;
|
|
8150
|
+
return true;
|
|
8151
|
+
}
|
|
8142
8152
|
const $0a80939bf0a1e9cc$export$af2c67164f68e9e9 = (content, aspectRatio) => {
|
|
8143
8153
|
const {
|
|
8144
8154
|
link: link,
|
|
@@ -8154,6 +8164,7 @@ function $0a80939bf0a1e9cc$export$7a92d995f1bf3592(history_content_blocks_, plp_
|
|
|
8154
8164
|
let hasSeenContentBlock = false;
|
|
8155
8165
|
const [historyContentBlocks, setHistoryContentBlocks] = history_content_blocks_;
|
|
8156
8166
|
const contentComponents = new Map();
|
|
8167
|
+
const isPhone = $b54e6192d0caa293$export$d9f36cf74e24d595((0, $05b9da7b91793a99$export$1e15d45642067bf0));
|
|
8157
8168
|
const delayedServerBlocks = $gVhhF$solidjs.createMemo(prev => {
|
|
8158
8169
|
// Do not update the server blocks while the products request is loading, to avoid this: https://depictaiworkspace.slack.com/archives/C01JB6E7K7G/p1750861454651319
|
|
8159
8170
|
if (products_request_loading_()) return prev;
|
|
@@ -8179,7 +8190,10 @@ function $0a80939bf0a1e9cc$export$7a92d995f1bf3592(history_content_blocks_, plp_
|
|
|
8179
8190
|
if (!blocksFromHistory?.length && !hasSeenContentBlock) return developerProvided;
|
|
8180
8191
|
const content = [...(developerProvided || [])];
|
|
8181
8192
|
hasSeenContentBlock = true;
|
|
8193
|
+
const phone = isPhone();
|
|
8182
8194
|
blocksFromHistory.forEach(row => {
|
|
8195
|
+
// Leave a block hidden on this device out before placement, so products fill its cells instead of a gap.
|
|
8196
|
+
if (!$05b9da7b91793a99$export$894065271726d798(row.visibility, phone)) return;
|
|
8183
8197
|
const {
|
|
8184
8198
|
content: {
|
|
8185
8199
|
link: link,
|
|
@@ -13332,12 +13346,795 @@ function $0785f4c9947d9b5f$export$f091cbac892643a4(obj) {
|
|
|
13332
13346
|
return Object.fromEntries(mapped_stuff); // FUCK TYPESCRIPT, WHY CAN'T YOU DO THIS CORRECTLY???
|
|
13333
13347
|
}
|
|
13334
13348
|
|
|
13349
|
+
/** One try and at most two retries: a 503 burst from V4 shouldn't be multiplied by fetch_retry's default of 10. */
|
|
13350
|
+
const $c25fb5290ccf7b3e$var$NATIVE_MAX_TRIES = 3;
|
|
13351
|
+
function $c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, path) {
|
|
13352
|
+
return `${(0, $gVhhF$depictaiutilishared.base_url)}/v4/${encodeURIComponent(merchant)}${path}`;
|
|
13353
|
+
}
|
|
13354
|
+
async function $c25fb5290ccf7b3e$export$88d793e3827f3436(url) {
|
|
13355
|
+
return (await $c25fb5290ccf7b3e$export$f035610fd74c541a(url)).body_;
|
|
13356
|
+
}
|
|
13357
|
+
async function $c25fb5290ccf7b3e$export$f035610fd74c541a(url) {
|
|
13358
|
+
const response = await $gVhhF$depictaiutilishared.fetch_retry(url, {
|
|
13359
|
+
method: "GET"
|
|
13360
|
+
}, $c25fb5290ccf7b3e$var$NATIVE_MAX_TRIES);
|
|
13361
|
+
if (!response) {
|
|
13362
|
+
$gVhhF$depictaiutilishared.dwarn("[NativeDepictAPI] no response from", url);
|
|
13363
|
+
return {};
|
|
13364
|
+
}
|
|
13365
|
+
if (response.status === 200)
|
|
13366
|
+
// A 200 that isn't JSON (a proxy's HTML page, a cut-off body) is a failed read like any other, so callers fall
|
|
13367
|
+
// back instead of rejecting: get_recommendation_types then forgets the read rather than keeping it in flight.
|
|
13368
|
+
try {
|
|
13369
|
+
return {
|
|
13370
|
+
body_: await response.json()
|
|
13371
|
+
};
|
|
13372
|
+
} catch (e) {
|
|
13373
|
+
$gVhhF$depictaiutilishared.dwarn("[NativeDepictAPI] 200 without a JSON body from", url, e);
|
|
13374
|
+
return {};
|
|
13375
|
+
}
|
|
13376
|
+
let error;
|
|
13377
|
+
try {
|
|
13378
|
+
error = (await response.json()).error;
|
|
13379
|
+
} catch {
|
|
13380
|
+
// not V4's error body
|
|
13381
|
+
}
|
|
13382
|
+
$gVhhF$depictaiutilishared.dwarn("[NativeDepictAPI]", response.status, error?.code, error?.message, error?.request_id, url);
|
|
13383
|
+
if (response.status >= 500) $gVhhF$depictaiutilishared.report([new Error(`V4 ${response.status} ${error?.code ?? ""}`), "Native V4 request failed"], "warning", {
|
|
13384
|
+
url: url,
|
|
13385
|
+
status: response.status,
|
|
13386
|
+
code: error?.code,
|
|
13387
|
+
request_id: error?.request_id ?? response.headers.get("x-depict-request-id")
|
|
13388
|
+
});
|
|
13389
|
+
return {
|
|
13390
|
+
error_: error
|
|
13391
|
+
};
|
|
13392
|
+
}
|
|
13393
|
+
const $48a2cfb8445bcd57$export$8e79752841e7cdb4 = 900000;
|
|
13394
|
+
const $48a2cfb8445bcd57$var$storage_key = merchant => `depict_v4_recommendation_types_${merchant}`;
|
|
13395
|
+
/** One read per merchant and CONTEXT_TTL_MS in this page; a failed read is forgotten so the next caller tries again. */
|
|
13396
|
+
const $48a2cfb8445bcd57$var$in_flight = new Map();
|
|
13397
|
+
function $48a2cfb8445bcd57$var$from_storage(merchant, now) {
|
|
13398
|
+
try {
|
|
13399
|
+
const stored = JSON.parse(localStorage.getItem($48a2cfb8445bcd57$var$storage_key(merchant)) ?? "null");
|
|
13400
|
+
if (!stored || !Array.isArray(stored.types) || !(now - stored.fetched_at < $48a2cfb8445bcd57$export$8e79752841e7cdb4)) return undefined;
|
|
13401
|
+
return $48a2cfb8445bcd57$var$to_map(stored.types);
|
|
13402
|
+
} catch {
|
|
13403
|
+
return undefined;
|
|
13404
|
+
}
|
|
13405
|
+
}
|
|
13406
|
+
function $48a2cfb8445bcd57$var$to_storage(merchant, types, now) {
|
|
13407
|
+
try {
|
|
13408
|
+
localStorage.setItem($48a2cfb8445bcd57$var$storage_key(merchant), JSON.stringify({
|
|
13409
|
+
fetched_at: now,
|
|
13410
|
+
types: types
|
|
13411
|
+
}));
|
|
13412
|
+
} catch {
|
|
13413
|
+
// localStorage unavailable or full: read /context again on the next page.
|
|
13414
|
+
}
|
|
13415
|
+
}
|
|
13416
|
+
const $48a2cfb8445bcd57$var$to_map = types => new Map(types.map(({
|
|
13417
|
+
type: type,
|
|
13418
|
+
inputs: inputs
|
|
13419
|
+
}) => [type, inputs]));
|
|
13420
|
+
function $48a2cfb8445bcd57$export$869eb14d6f85ac51(merchant, now = Date.now()) {
|
|
13421
|
+
const pending = $48a2cfb8445bcd57$var$in_flight.get(merchant);
|
|
13422
|
+
if (pending && now - pending.started_at < $48a2cfb8445bcd57$export$8e79752841e7cdb4) return pending.read;
|
|
13423
|
+
const stored = $48a2cfb8445bcd57$var$from_storage(merchant, now);
|
|
13424
|
+
if (stored) return Promise.resolve(stored);
|
|
13425
|
+
const read = $c25fb5290ccf7b3e$export$88d793e3827f3436($c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, "/context")).then(context => {
|
|
13426
|
+
if (!context) {
|
|
13427
|
+
if ($48a2cfb8445bcd57$var$in_flight.get(merchant)?.read === read) $48a2cfb8445bcd57$var$in_flight.delete(merchant);
|
|
13428
|
+
return undefined;
|
|
13429
|
+
}
|
|
13430
|
+
const types = context.recommendation_types ?? [];
|
|
13431
|
+
$48a2cfb8445bcd57$var$to_storage(merchant, types, now);
|
|
13432
|
+
return $48a2cfb8445bcd57$var$to_map(types);
|
|
13433
|
+
});
|
|
13434
|
+
$48a2cfb8445bcd57$var$in_flight.set(merchant, {
|
|
13435
|
+
started_at: now,
|
|
13436
|
+
read: read
|
|
13437
|
+
});
|
|
13438
|
+
return read;
|
|
13439
|
+
}
|
|
13440
|
+
function $48a2cfb8445bcd57$export$6cde5c31239dec47() {
|
|
13441
|
+
$48a2cfb8445bcd57$var$in_flight.clear();
|
|
13442
|
+
}
|
|
13443
|
+
|
|
13444
|
+
/**
|
|
13445
|
+
* The shopper's recently viewed products, kept in the browser for the native V4 API's history-based recommendations.
|
|
13446
|
+
*
|
|
13447
|
+
* v3 kept this history on the server, per session. V4 content requests carry no session, so a surface that reads
|
|
13448
|
+
* history gets it in the request (`recent_views`), and the SDK keeps the list. It holds product ids and view times
|
|
13449
|
+
* only (no session, user or page data), bounded in size and age, in localStorage per merchant; when localStorage
|
|
13450
|
+
* can't be used (private mode, blocked, full) it lives in memory for the page load.
|
|
13451
|
+
*
|
|
13452
|
+
* A view is recorded when a native product-anchored recommendation request resolves its anchor, as v3's facade records
|
|
13453
|
+
* a resolved anchor as a view; the product being viewed is in the list from the next request on.
|
|
13454
|
+
*/ /** recs-wasm reads the newest 20 views (V4 `recent_views` docs), so more would never be read. */
|
|
13455
|
+
const $b6d3e4dd179febae$export$3d684435158adda6 = 20;
|
|
13456
|
+
const $b6d3e4dd179febae$export$5eb0a366a50fa99e = 2592000000;
|
|
13457
|
+
/** V4's longest product id (`ProductRef`); a longer one is never a product it knows. */
|
|
13458
|
+
const $b6d3e4dd179febae$var$MAX_ID_LENGTH = 500;
|
|
13459
|
+
const $b6d3e4dd179febae$var$storage_key = merchant => `depict_v4_recent_views_${merchant}`;
|
|
13460
|
+
/** The list per merchant as last written, which reads use when localStorage can't hold it. */
|
|
13461
|
+
const $b6d3e4dd179febae$var$in_memory = new Map();
|
|
13462
|
+
/** Merchants whose last write to localStorage failed, so localStorage holds an older list than memory. */
|
|
13463
|
+
const $b6d3e4dd179febae$var$unstored = new Set();
|
|
13464
|
+
/** `views` as a valid list: well-formed entries, newest first, one per id, not older than the age bound or too many. */
|
|
13465
|
+
function $b6d3e4dd179febae$var$bounded(views, now) {
|
|
13466
|
+
if (!Array.isArray(views)) return [];
|
|
13467
|
+
const seen = new Set();
|
|
13468
|
+
const kept = [];
|
|
13469
|
+
for (const item of views) {
|
|
13470
|
+
if (!item || typeof item !== "object") continue;
|
|
13471
|
+
const {
|
|
13472
|
+
id: id,
|
|
13473
|
+
at: at
|
|
13474
|
+
} = item;
|
|
13475
|
+
if (typeof id !== "string" || !id || id.length > $b6d3e4dd179febae$var$MAX_ID_LENGTH || typeof at !== "string") continue;
|
|
13476
|
+
const time = Date.parse(at);
|
|
13477
|
+
if (Number.isNaN(time) || now - time > $b6d3e4dd179febae$export$5eb0a366a50fa99e) continue;
|
|
13478
|
+
kept.push({
|
|
13479
|
+
view: {
|
|
13480
|
+
id: id,
|
|
13481
|
+
at: new Date(time).toISOString()
|
|
13482
|
+
},
|
|
13483
|
+
time: time
|
|
13484
|
+
});
|
|
13485
|
+
}
|
|
13486
|
+
kept.sort((a, b) => b.time - a.time);
|
|
13487
|
+
const newest = [];
|
|
13488
|
+
for (const {
|
|
13489
|
+
view: view
|
|
13490
|
+
} of kept) {
|
|
13491
|
+
if (seen.has(view.id)) continue;
|
|
13492
|
+
seen.add(view.id);
|
|
13493
|
+
newest.push(view);
|
|
13494
|
+
if (newest.length === $b6d3e4dd179febae$export$3d684435158adda6) break;
|
|
13495
|
+
}
|
|
13496
|
+
return newest;
|
|
13497
|
+
}
|
|
13498
|
+
function $b6d3e4dd179febae$var$read_stored(merchant) {
|
|
13499
|
+
if ($b6d3e4dd179febae$var$unstored.has(merchant)) return $b6d3e4dd179febae$var$in_memory.get(merchant);
|
|
13500
|
+
try {
|
|
13501
|
+
const stored = localStorage.getItem($b6d3e4dd179febae$var$storage_key(merchant));
|
|
13502
|
+
return stored === null ? [] : JSON.parse(stored);
|
|
13503
|
+
} catch {
|
|
13504
|
+
return $b6d3e4dd179febae$var$in_memory.get(merchant) ?? [];
|
|
13505
|
+
}
|
|
13506
|
+
}
|
|
13507
|
+
function $b6d3e4dd179febae$export$2d7138f47b625a04(merchant, now = Date.now()) {
|
|
13508
|
+
return $b6d3e4dd179febae$var$bounded($b6d3e4dd179febae$var$read_stored(merchant), now);
|
|
13509
|
+
}
|
|
13510
|
+
function $b6d3e4dd179febae$export$6379943de8f8af08(merchant, product_id, now = Date.now()) {
|
|
13511
|
+
const views = $b6d3e4dd179febae$var$bounded([{
|
|
13512
|
+
id: product_id,
|
|
13513
|
+
at: new Date(now).toISOString()
|
|
13514
|
+
}, ...$b6d3e4dd179febae$export$2d7138f47b625a04(merchant, now)], now);
|
|
13515
|
+
$b6d3e4dd179febae$var$in_memory.set(merchant, views);
|
|
13516
|
+
try {
|
|
13517
|
+
localStorage.setItem($b6d3e4dd179febae$var$storage_key(merchant), JSON.stringify(views));
|
|
13518
|
+
$b6d3e4dd179febae$var$unstored.delete(merchant);
|
|
13519
|
+
} catch {
|
|
13520
|
+
// localStorage unavailable or full: the in-memory list serves this page load.
|
|
13521
|
+
$b6d3e4dd179febae$var$unstored.add(merchant);
|
|
13522
|
+
}
|
|
13523
|
+
}
|
|
13524
|
+
|
|
13525
|
+
/** V4's largest `limit`, and the most ids `cart` and `exclude` take. */
|
|
13526
|
+
const $c82154cf2888f2b2$export$f112abad09998fa8 = 100;
|
|
13527
|
+
const $c82154cf2888f2b2$var$MAX_IDS = 100;
|
|
13528
|
+
/** The most products V4's `recent_views` takes. */
|
|
13529
|
+
const $c82154cf2888f2b2$var$MAX_VIEWS = 50;
|
|
13530
|
+
/** What a v3 recommendations call names, as fetchDepictRecommendations takes it. */
|
|
13531
|
+
const $c82154cf2888f2b2$var$distinct = ids => [...new Set(ids.filter(id => typeof id === "string" && id.length > 0))];
|
|
13532
|
+
function $c82154cf2888f2b2$export$17493dc1a89b34e6(call, inputs, recent_views) {
|
|
13533
|
+
const reads = input => inputs ? inputs.includes(input) : input === "anchor";
|
|
13534
|
+
const product_ids = $c82154cf2888f2b2$var$distinct(call.productIds ?? []);
|
|
13535
|
+
const request = {
|
|
13536
|
+
market: call.market,
|
|
13537
|
+
...(call.locale ? {
|
|
13538
|
+
locale: call.locale
|
|
13539
|
+
} : {}),
|
|
13540
|
+
type: call.type
|
|
13541
|
+
};
|
|
13542
|
+
if (reads("anchor")) {
|
|
13543
|
+
if (call.categoryId) request.anchor = {
|
|
13544
|
+
type: "category",
|
|
13545
|
+
id: call.categoryId
|
|
13546
|
+
};else if (call.productId) request.anchor = {
|
|
13547
|
+
type: "product",
|
|
13548
|
+
id: call.productId
|
|
13549
|
+
};else if (product_ids.length) {
|
|
13550
|
+
const [first, ...rest] = product_ids;
|
|
13551
|
+
request.anchor = {
|
|
13552
|
+
type: "product",
|
|
13553
|
+
id: first
|
|
13554
|
+
};
|
|
13555
|
+
if (rest.length) request.exclude = rest.slice(0, $c82154cf2888f2b2$var$MAX_IDS);
|
|
13556
|
+
}
|
|
13557
|
+
}
|
|
13558
|
+
if (reads("cart") && product_ids.length) request.cart = product_ids.slice(0, $c82154cf2888f2b2$var$MAX_IDS);
|
|
13559
|
+
if (reads("recent_views") && recent_views.length) request.recent_views = recent_views.slice(0, $c82154cf2888f2b2$var$MAX_VIEWS);
|
|
13560
|
+
if (call.limit) request.limit = Math.min(Math.max(1, Math.floor(call.limit)), $c82154cf2888f2b2$export$f112abad09998fa8);
|
|
13561
|
+
request.include = ["attributes"];
|
|
13562
|
+
const anchor_only = inputs?.length === 1 && inputs[0] === "anchor";
|
|
13563
|
+
if (anchor_only && !request.anchor) return undefined;
|
|
13564
|
+
return request;
|
|
13565
|
+
}
|
|
13566
|
+
/** `encodeURIComponent`, as V4's own encoder writes a value (`+` would mean a space). */
|
|
13567
|
+
const $c82154cf2888f2b2$var$encode = value => encodeURIComponent(value);
|
|
13568
|
+
function $c82154cf2888f2b2$export$fc756666ac777d0(request) {
|
|
13569
|
+
const pairs = [];
|
|
13570
|
+
const add = (key, value) => value !== undefined && pairs.push(`${key}=${value}`);
|
|
13571
|
+
const list = values => values?.map($c82154cf2888f2b2$var$encode).join(",");
|
|
13572
|
+
add("market", $c82154cf2888f2b2$var$encode(request.market));
|
|
13573
|
+
add("locale", request.locale === undefined ? undefined : $c82154cf2888f2b2$var$encode(request.locale));
|
|
13574
|
+
add("type", $c82154cf2888f2b2$var$encode(request.type));
|
|
13575
|
+
add("anchor", request.anchor && `${$c82154cf2888f2b2$var$encode(request.anchor.type)}:${$c82154cf2888f2b2$var$encode(request.anchor.id)}`);
|
|
13576
|
+
add("cart", list(request.cart));
|
|
13577
|
+
add("recent_views", request.recent_views?.map(view => `${$c82154cf2888f2b2$var$encode(view.id)}@${$c82154cf2888f2b2$var$encode(view.at)}`).join(","));
|
|
13578
|
+
add("query", request.query === undefined ? undefined : $c82154cf2888f2b2$var$encode(request.query));
|
|
13579
|
+
add("exclude", list(request.exclude));
|
|
13580
|
+
add("limit", request.limit === undefined ? undefined : String(request.limit));
|
|
13581
|
+
add("include", list(request.include));
|
|
13582
|
+
return pairs.join("&");
|
|
13583
|
+
}
|
|
13584
|
+
const $c82154cf2888f2b2$export$89962366050887f7 = product => product.variants[product.selected]?.product_id ?? product.group_id;
|
|
13585
|
+
function $c82154cf2888f2b2$export$afe6aeae61a7aa58(hits, scope, type) {
|
|
13586
|
+
const anchors = hits.slice(0, type === "search" ? 10 : 1);
|
|
13587
|
+
return anchors.map((anchor, at) => {
|
|
13588
|
+
const exclude = hits.filter((_, index) => index !== at).map($c82154cf2888f2b2$export$89962366050887f7);
|
|
13589
|
+
return {
|
|
13590
|
+
market: scope.market,
|
|
13591
|
+
...(scope.locale ? {
|
|
13592
|
+
locale: scope.locale
|
|
13593
|
+
} : {}),
|
|
13594
|
+
type: type,
|
|
13595
|
+
anchor: {
|
|
13596
|
+
type: "product",
|
|
13597
|
+
id: $c82154cf2888f2b2$export$89962366050887f7(anchor)
|
|
13598
|
+
},
|
|
13599
|
+
...(exclude.length ? {
|
|
13600
|
+
exclude: exclude.slice(0, $c82154cf2888f2b2$var$MAX_IDS)
|
|
13601
|
+
} : {}),
|
|
13602
|
+
include: ["attributes"]
|
|
13603
|
+
};
|
|
13604
|
+
});
|
|
13605
|
+
}
|
|
13606
|
+
function $c82154cf2888f2b2$export$9af50be6508dcd00(lists, limit) {
|
|
13607
|
+
const merged = [];
|
|
13608
|
+
const taken = new Set();
|
|
13609
|
+
const depth = Math.max(0, ...lists.map(list => list.length));
|
|
13610
|
+
for (let index = 0; index < depth; index++) for (const list of lists) {
|
|
13611
|
+
const product = list[index];
|
|
13612
|
+
if (product === undefined || taken.has(product.group_id)) continue;
|
|
13613
|
+
taken.add(product.group_id);
|
|
13614
|
+
merged.push(product);
|
|
13615
|
+
if (merged.length >= limit) return merged;
|
|
13616
|
+
}
|
|
13617
|
+
return merged;
|
|
13618
|
+
}
|
|
13619
|
+
|
|
13620
|
+
/** Which v3 result id a card's `tracking_id` goes in; the d1 id it carries says the same (`d1.s.…`, `d1.l.…`). */ /** A bare 3/4/6/8-digit hex, as fi stores a computed `color_hex`; v3 serves it with its `#`. */
|
|
13621
|
+
const $6b1ba052a9f2341e$var$BARE_HEX = /^(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
13622
|
+
function $6b1ba052a9f2341e$export$7abfb7bc025aaea8(product, tracking_key) {
|
|
13623
|
+
const product_attributes = product.attributes ?? {};
|
|
13624
|
+
return {
|
|
13625
|
+
variant_index: product.selected,
|
|
13626
|
+
variant_displays: product.variants.map(variant => {
|
|
13627
|
+
// A variant carries its own main image only when it differs from the card's; it has no gallery of its own.
|
|
13628
|
+
const image_urls = variant.image ? [variant.image] : [...product.images];
|
|
13629
|
+
const price = variant.price ?? product.price;
|
|
13630
|
+
const color = variant.color ?? product.color;
|
|
13631
|
+
const display = {
|
|
13632
|
+
...product_attributes,
|
|
13633
|
+
// The merchant's variant attributes under their own keys (`add_to_cart_id`, `item_group_id`, …); the card
|
|
13634
|
+
// fields below win over a same-named attribute, as on v3.
|
|
13635
|
+
...variant.attributes,
|
|
13636
|
+
product_id: variant.product_id,
|
|
13637
|
+
main_product_id: variant.attributes?.main_product_id ?? variant.group_id ?? product.group_id,
|
|
13638
|
+
title: variant.title ?? product.title,
|
|
13639
|
+
image_urls: image_urls,
|
|
13640
|
+
sale_price: price.amount,
|
|
13641
|
+
original_price: price.compare_at ?? price.amount,
|
|
13642
|
+
...(price.lowest !== undefined ? {
|
|
13643
|
+
lowest_price: price.lowest
|
|
13644
|
+
} : {}),
|
|
13645
|
+
in_stock: variant.in_stock,
|
|
13646
|
+
...(color ? {
|
|
13647
|
+
color_name: color.name
|
|
13648
|
+
} : {}),
|
|
13649
|
+
uri: variant.slug ?? product.slug
|
|
13650
|
+
};
|
|
13651
|
+
const hex = display.color_hex;
|
|
13652
|
+
if (typeof hex === "string" && $6b1ba052a9f2341e$var$BARE_HEX.test(hex)) display.color_hex = `#${hex}`;
|
|
13653
|
+
return display;
|
|
13654
|
+
}),
|
|
13655
|
+
[tracking_key]: product.tracking_id
|
|
13656
|
+
};
|
|
13657
|
+
}
|
|
13658
|
+
|
|
13659
|
+
/**
|
|
13660
|
+
* Filters, facets and sorts between depict-ui's v3 shapes and the native V4 API.
|
|
13661
|
+
*
|
|
13662
|
+
* This is a client-side port of realtime's v3 facade (`v4/worker/src/facade/v3Browse.ts`: `v3FilterBy`, `toV3Filters`,
|
|
13663
|
+
* `toV3Sorts`, `toV3ContentLinks`), which owns the same translation on the server for v3 requests. Keep the two in
|
|
13664
|
+
* step: a difference shows up as a filter that works on v3 and not on native, or the other way round.
|
|
13665
|
+
*
|
|
13666
|
+
* The facade resolves a v3 filter field against the merchant's search config (titles, localized titles). The browser
|
|
13667
|
+
* has no config, so it resolves against the facets V4 served instead (see {@link FacetIndex}).
|
|
13668
|
+
*/ /** A v3 filter as depict-ui sends it: `field` is often the lowercased group title (modify_fiters_to_group_title_as_field). */ /** Thrown for a filter V4 can't express; the caller answers with the fallback response, as a v3 400 would. */
|
|
13669
|
+
class $debf9654214236f5$export$f5ea4d073ddb4bdb extends Error {}
|
|
13670
|
+
/** v3's names for V4's built-in fields, both ways. */
|
|
13671
|
+
const $debf9654214236f5$var$V3_FIELD = {
|
|
13672
|
+
price: "sale_price"
|
|
13673
|
+
};
|
|
13674
|
+
const $debf9654214236f5$var$V4_FIELD = {
|
|
13675
|
+
sale_price: "price"
|
|
13676
|
+
};
|
|
13677
|
+
const $debf9654214236f5$var$V3_SORT = {
|
|
13678
|
+
relevance: "_relevance",
|
|
13679
|
+
price: "sale_price",
|
|
13680
|
+
newest: "product_timestamp"
|
|
13681
|
+
};
|
|
13682
|
+
const $debf9654214236f5$var$V4_SORT = Object.fromEntries(Object.entries($debf9654214236f5$var$V3_SORT).map(([v4, v3]) => [v3, v4]));
|
|
13683
|
+
/** V4's public filter field syntax (`FilterField` in the contract). */
|
|
13684
|
+
const $debf9654214236f5$var$PUBLIC_FIELD = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
|
|
13685
|
+
/**
|
|
13686
|
+
* Fields that are never a lowercased group title: v3's toggles carry no group title, and `sale_price` is v3's own
|
|
13687
|
+
* name for V4's price. A reserved V4 field (`price`, `brand`, `category`) is not among them: iciw's category tree is
|
|
13688
|
+
* titled "Category", so `category` from a link may name `product_scollection_category_hierarchy`.
|
|
13689
|
+
*/
|
|
13690
|
+
const $debf9654214236f5$var$NEVER_A_TITLE = new Set(["in_stock", "on_sale", "sale_price"]);
|
|
13691
|
+
/** fi's enriched colour fields: their values are names, never a `<name>;#<hex>` composite. */
|
|
13692
|
+
const $debf9654214236f5$var$FI_COLOUR_FIELDS = new Set(["colors", "color_details"]);
|
|
13693
|
+
/** The colour template's field, which indexes the composite itself. */
|
|
13694
|
+
const $debf9654214236f5$var$V3_TEMPLATE_COLOUR = "color_with_hex_list";
|
|
13695
|
+
/** Legacy's colour pill composite suffix (`Green;#9ea386`). */
|
|
13696
|
+
const $debf9654214236f5$var$HEX_SUFFIX = /;#[0-9a-fA-F]{3,8}\s*$/;
|
|
13697
|
+
const $debf9654214236f5$var$NUMERIC = /^-?\d+(\.\d+)?$/;
|
|
13698
|
+
/** realtime's separator between the levels of a hierarchical facet value (`Shop # Woman`). */
|
|
13699
|
+
const $debf9654214236f5$var$HIERARCHY_SEPARATOR = " # ";
|
|
13700
|
+
/** The features realtime's category tree is built on. */
|
|
13701
|
+
const $debf9654214236f5$var$CATEGORY_TREE_FIELDS = new Set(["product_category_hierarchy", "product_scollection_category_hierarchy"]);
|
|
13702
|
+
/** V4's public name for the discount template's field (realtime `v4/worker/src/search/fields.ts`). */
|
|
13703
|
+
const $debf9654214236f5$var$DISCOUNT_FIELD = "discount";
|
|
13704
|
+
/** The fields of V4's toggle facets (the `on_sale` and `in_stock` templates). */
|
|
13705
|
+
const $debf9654214236f5$var$V3_TOGGLES = new Set(["on_sale", "in_stock"]);
|
|
13706
|
+
class $debf9654214236f5$export$8d488bcc71d07ffb {
|
|
13707
|
+
#by_key = new Map();
|
|
13708
|
+
/** Adds the facets of one browse response. */
|
|
13709
|
+
learn_(facets) {
|
|
13710
|
+
for (const facet of facets ?? []) {
|
|
13711
|
+
const info = {
|
|
13712
|
+
field_: facet.field,
|
|
13713
|
+
checkbox_: facet.type === "checkbox" && !$debf9654214236f5$var$is_toggle(facet),
|
|
13714
|
+
colour_: $debf9654214236f5$var$FI_COLOUR_FIELDS.has(facet.field) || facet.type === "swatch" && facet.field !== $debf9654214236f5$var$V3_TEMPLATE_COLOUR
|
|
13715
|
+
};
|
|
13716
|
+
this.#by_key.set(facet.field, info);
|
|
13717
|
+
const v3_field = $debf9654214236f5$var$V3_FIELD[facet.field];
|
|
13718
|
+
if (v3_field) this.#by_key.set(v3_field, info);
|
|
13719
|
+
if (facet.title) this.#by_key.set(facet.title.toLowerCase(), info);
|
|
13720
|
+
}
|
|
13721
|
+
}
|
|
13722
|
+
/** The field a v3 filter field names, when a served facet has it as its field or its title. */
|
|
13723
|
+
get_(field) {
|
|
13724
|
+
const bare = field.replace(/#$/, "");
|
|
13725
|
+
const direct = this.#by_key.get(bare);
|
|
13726
|
+
if (direct) return direct;
|
|
13727
|
+
let wanted;
|
|
13728
|
+
try {
|
|
13729
|
+
wanted = decodeURIComponent(bare).toLowerCase();
|
|
13730
|
+
} catch {
|
|
13731
|
+
wanted = bare.toLowerCase();
|
|
13732
|
+
}
|
|
13733
|
+
return this.#by_key.get(wanted);
|
|
13734
|
+
}
|
|
13735
|
+
}
|
|
13736
|
+
function $debf9654214236f5$export$3b6ba2422a5e0aa0(field, index) {
|
|
13737
|
+
return !!index.get_(field) || $debf9654214236f5$var$NEVER_A_TITLE.has(field.replace(/#$/, ""));
|
|
13738
|
+
}
|
|
13739
|
+
function $debf9654214236f5$var$is_empty(data) {
|
|
13740
|
+
return data === undefined || data === null || data === "" || Array.isArray(data) && !data.length;
|
|
13741
|
+
}
|
|
13742
|
+
function $debf9654214236f5$var$literal(value, field) {
|
|
13743
|
+
const text = String(value);
|
|
13744
|
+
if (text.includes("`")) throw new $debf9654214236f5$export$f5ea4d073ddb4bdb(`filters: a value of ${field} contains a backtick`);
|
|
13745
|
+
// A boolean-looking string is written bare, as realtime's filter writer does for every field.
|
|
13746
|
+
if (/^(true|True|false|False)$/.test(text)) return text.toLowerCase();
|
|
13747
|
+
if (field === "price" && $debf9654214236f5$var$NUMERIC.test(text)) return text;
|
|
13748
|
+
return typeof value === "string" ? `\`${text}\`` : text;
|
|
13749
|
+
}
|
|
13750
|
+
function $debf9654214236f5$var$lax_number(value) {
|
|
13751
|
+
if (typeof value === "number") return value;
|
|
13752
|
+
if (typeof value !== "string" || value.trim() === "") return undefined;
|
|
13753
|
+
const number = Number(value);
|
|
13754
|
+
return Number.isFinite(number) ? number : undefined;
|
|
13755
|
+
}
|
|
13756
|
+
function $debf9654214236f5$export$c17bb5d2ead3e8f3(filter, index) {
|
|
13757
|
+
if ($debf9654214236f5$var$is_empty(filter.data)) return undefined;
|
|
13758
|
+
const info = index.get_(filter.field);
|
|
13759
|
+
const bare = filter.field.replace(/#$/, "");
|
|
13760
|
+
const field = info?.field_ ?? $debf9654214236f5$var$V4_FIELD[bare] ?? bare;
|
|
13761
|
+
if (!$debf9654214236f5$var$PUBLIC_FIELD.test(field)) throw new $debf9654214236f5$export$f5ea4d073ddb4bdb(`Invalid filter field \`${filter.field}\``);
|
|
13762
|
+
const clause = text => ({
|
|
13763
|
+
field_: field,
|
|
13764
|
+
clause_: text
|
|
13765
|
+
});
|
|
13766
|
+
const colour = $debf9654214236f5$var$FI_COLOUR_FIELDS.has(field) || !!info?.colour_;
|
|
13767
|
+
const data = filter.data;
|
|
13768
|
+
const values = (Array.isArray(data) ? data : [data]).map(value => !Array.isArray(value) ? colour && typeof value === "string" ? value.replace($debf9654214236f5$var$HEX_SUFFIX, "").trim() || value : value : field === "category" ? value[value.length - 1] : value.map(String).join($debf9654214236f5$var$HIERARCHY_SEPARATOR));
|
|
13769
|
+
const list = () => `[${values.map(value => $debf9654214236f5$var$literal(value, field)).join(",")}]`;
|
|
13770
|
+
// V4's discount filter (the discount template's "X% or more" radio) is a threshold, so `in` or `eq` on it means
|
|
13771
|
+
// "this discount or more", as on the facade since realtime#2181: a link with no operator decodes as `in`, and a
|
|
13772
|
+
// shop may send `in ["0.2"]` itself. Several values take the largest, as `geq` does.
|
|
13773
|
+
const op = (filter.op === "in" || filter.op === "eq") && field === $debf9654214236f5$var$DISCOUNT_FIELD ? "geq" : filter.op;
|
|
13774
|
+
// A configured checkbox keeps in/nin; every other op on it becomes in.
|
|
13775
|
+
if (op !== "in" && op !== "nin" && info?.checkbox_) return clause(`${field}:=${list()}`);
|
|
13776
|
+
const one = () => {
|
|
13777
|
+
if (values.length !== 1) throw new $debf9654214236f5$export$f5ea4d073ddb4bdb(`filters: ${op} takes one value`);
|
|
13778
|
+
return $debf9654214236f5$var$literal(values[0], field);
|
|
13779
|
+
};
|
|
13780
|
+
// A comparison takes a number, also one sent as a string; of several numbers `geq` takes the largest.
|
|
13781
|
+
const bound = () => {
|
|
13782
|
+
const numbers = values.map(value => typeof value === "number" || typeof value === "string" && $debf9654214236f5$var$NUMERIC.test(value) ? Number(value) : undefined);
|
|
13783
|
+
if (numbers.length === 0 || numbers.some(number => number === undefined)) return one();
|
|
13784
|
+
if (numbers.length > 1 && op !== "geq") return one();
|
|
13785
|
+
return String(Math.max(...numbers));
|
|
13786
|
+
};
|
|
13787
|
+
switch (op) {
|
|
13788
|
+
case "eq":
|
|
13789
|
+
return clause(`${field}:=${one()}`);
|
|
13790
|
+
case "neq":
|
|
13791
|
+
return clause(`${field}:!=${one()}`);
|
|
13792
|
+
case "in":
|
|
13793
|
+
return clause(`${field}:=${list()}`);
|
|
13794
|
+
case "nin":
|
|
13795
|
+
return clause(`${field}:!=${list()}`);
|
|
13796
|
+
case "leq":
|
|
13797
|
+
return clause(`${field}:<=${bound()}`);
|
|
13798
|
+
case "geq":
|
|
13799
|
+
return clause(`${field}:>=${bound()}`);
|
|
13800
|
+
case "inrange":
|
|
13801
|
+
{
|
|
13802
|
+
const [min, max] = values.map($debf9654214236f5$var$lax_number);
|
|
13803
|
+
if (min === undefined || max === undefined || values.length !== 2) throw new $debf9654214236f5$export$f5ea4d073ddb4bdb("filters: inrange takes [min, max]");
|
|
13804
|
+
return clause(`${field}:[${min}..${max}]`);
|
|
13805
|
+
}
|
|
13806
|
+
default:
|
|
13807
|
+
throw new $debf9654214236f5$export$f5ea4d073ddb4bdb(`filters: unknown op ${op}`);
|
|
13808
|
+
}
|
|
13809
|
+
}
|
|
13810
|
+
function $debf9654214236f5$export$407f30f25da13cc7(filters, index) {
|
|
13811
|
+
const clauses = filters.flatMap(filter => $debf9654214236f5$export$c17bb5d2ead3e8f3(filter, index)?.clause_ ?? []);
|
|
13812
|
+
return clauses.length ? clauses.join(" && ") : undefined;
|
|
13813
|
+
}
|
|
13814
|
+
function $debf9654214236f5$export$c38de645260a41ed(error, clauses) {
|
|
13815
|
+
if (!error || !clauses.length) return [];
|
|
13816
|
+
const named = (error.message ?? "").match(/"([A-Za-z0-9_.-]+)/)?.[1];
|
|
13817
|
+
if (error.code === "unknown_filter_field") {
|
|
13818
|
+
if (error.allowed) {
|
|
13819
|
+
const allowed = new Set(error.allowed);
|
|
13820
|
+
return clauses.filter(clause => !allowed.has(clause.field_));
|
|
13821
|
+
}
|
|
13822
|
+
return clauses.filter(clause => clause.field_ === named);
|
|
13823
|
+
}
|
|
13824
|
+
if (error.code === "invalid_filter") {
|
|
13825
|
+
const on_field = clauses.filter(clause => clause.field_ === named);
|
|
13826
|
+
return on_field.length ? on_field : [...clauses];
|
|
13827
|
+
}
|
|
13828
|
+
return [];
|
|
13829
|
+
}
|
|
13830
|
+
function $debf9654214236f5$export$78eb8e636d89ff30(sort) {
|
|
13831
|
+
if (!sort || sort.field === "_relevance") return undefined;
|
|
13832
|
+
return {
|
|
13833
|
+
field: $debf9654214236f5$var$V4_SORT[sort.field] ?? sort.field,
|
|
13834
|
+
order: sort.order
|
|
13835
|
+
};
|
|
13836
|
+
}
|
|
13837
|
+
function $debf9654214236f5$export$cd08b64be5110ce2(sorts) {
|
|
13838
|
+
return sorts.map(sort => ({
|
|
13839
|
+
field: $debf9654214236f5$var$V3_SORT[sort.field] ?? sort.field,
|
|
13840
|
+
order: sort.order,
|
|
13841
|
+
meta: {
|
|
13842
|
+
title: sort.title,
|
|
13843
|
+
values: [sort.order],
|
|
13844
|
+
names: [sort.title]
|
|
13845
|
+
}
|
|
13846
|
+
}));
|
|
13847
|
+
}
|
|
13848
|
+
const $debf9654214236f5$var$V3_VALUES_TYPE = {
|
|
13849
|
+
checkbox: "checkbox",
|
|
13850
|
+
radio: "radio",
|
|
13851
|
+
swatch: "checkbox-color",
|
|
13852
|
+
hierarchy: "checkbox-hierarchical",
|
|
13853
|
+
grid: "checkbox-grid"
|
|
13854
|
+
};
|
|
13855
|
+
/** A toggle is a template facet's one `true` value. */
|
|
13856
|
+
function $debf9654214236f5$var$is_toggle(facet) {
|
|
13857
|
+
return $debf9654214236f5$var$V3_TOGGLES.has(facet.field) && facet.type === "checkbox" && facet.values.length === 1 && facet.values[0].value === "true";
|
|
13858
|
+
}
|
|
13859
|
+
function $debf9654214236f5$var$category_path(value) {
|
|
13860
|
+
return value.split("#").map(level => level.trim()).filter(Boolean);
|
|
13861
|
+
}
|
|
13862
|
+
function $debf9654214236f5$export$da9af372695714ef(facets, currency) {
|
|
13863
|
+
return facets.filter(facet => facet.type === "range" || facet.values.length > 0).map(facet => {
|
|
13864
|
+
const field = $debf9654214236f5$var$V3_FIELD[facet.field] ?? facet.field;
|
|
13865
|
+
if (facet.type === "range") return {
|
|
13866
|
+
field: field,
|
|
13867
|
+
op: "inrange",
|
|
13868
|
+
data: [facet.min, facet.max],
|
|
13869
|
+
meta: {
|
|
13870
|
+
group_title: facet.title,
|
|
13871
|
+
type: "range",
|
|
13872
|
+
min: facet.min,
|
|
13873
|
+
max: facet.max,
|
|
13874
|
+
...(facet.field === "price" && currency ? {
|
|
13875
|
+
currency: currency
|
|
13876
|
+
} : {})
|
|
13877
|
+
},
|
|
13878
|
+
id: `${field}1`
|
|
13879
|
+
};
|
|
13880
|
+
const hierarchy = facet.type === "hierarchy";
|
|
13881
|
+
const path = value => $debf9654214236f5$var$CATEGORY_TREE_FIELDS.has(facet.field) ? $debf9654214236f5$var$category_path(value) : value.split($debf9654214236f5$var$HIERARCHY_SEPARATOR);
|
|
13882
|
+
if ($debf9654214236f5$var$is_toggle(facet)) return {
|
|
13883
|
+
field: field,
|
|
13884
|
+
op: "eq",
|
|
13885
|
+
meta: {
|
|
13886
|
+
type: "checkbox",
|
|
13887
|
+
values: facet.values.map(value => value.value),
|
|
13888
|
+
counts: facet.values.map(value => value.count),
|
|
13889
|
+
names: facet.values.map(value => value.label)
|
|
13890
|
+
},
|
|
13891
|
+
id: `${field}1`
|
|
13892
|
+
};
|
|
13893
|
+
// Two spellings of one category path are one row in the tree.
|
|
13894
|
+
const seen = new Set();
|
|
13895
|
+
const values = $debf9654214236f5$var$CATEGORY_TREE_FIELDS.has(facet.field) ? facet.values.filter(({
|
|
13896
|
+
value: value
|
|
13897
|
+
}) => {
|
|
13898
|
+
const levels = path(value);
|
|
13899
|
+
const key = JSON.stringify(levels);
|
|
13900
|
+
if (levels.length === 0 || seen.has(key)) return false;
|
|
13901
|
+
seen.add(key);
|
|
13902
|
+
return true;
|
|
13903
|
+
}) : facet.values;
|
|
13904
|
+
return {
|
|
13905
|
+
field: field,
|
|
13906
|
+
op: facet.field === "discount" ? "geq" : "in",
|
|
13907
|
+
meta: {
|
|
13908
|
+
group_title: facet.title,
|
|
13909
|
+
type: $debf9654214236f5$var$V3_VALUES_TYPE[facet.type] ?? "checkbox",
|
|
13910
|
+
values: values.map(value => hierarchy ? path(value.value) : value.value),
|
|
13911
|
+
counts: values.map(value => value.count),
|
|
13912
|
+
names: values.map(value => hierarchy ? path(value.value).slice(-1)[0] : value.label),
|
|
13913
|
+
// The colour template sends swatches only with one to paint; a colour filter always sends them.
|
|
13914
|
+
...(facet.type === "swatch" && (facet.field !== $debf9654214236f5$var$V3_TEMPLATE_COLOUR || facet.values.some(value => value.swatch)) ? {
|
|
13915
|
+
swatches: facet.values.map(value => value.swatch ?? null)
|
|
13916
|
+
} : {})
|
|
13917
|
+
},
|
|
13918
|
+
id: `${field}1`
|
|
13919
|
+
};
|
|
13920
|
+
});
|
|
13921
|
+
}
|
|
13922
|
+
function $debf9654214236f5$export$b84a41a5163c4fce(content) {
|
|
13923
|
+
return content.map(hit => ({
|
|
13924
|
+
type: "content_link",
|
|
13925
|
+
title: hit.title,
|
|
13926
|
+
...(hit.description !== undefined ? {
|
|
13927
|
+
description: hit.description
|
|
13928
|
+
} : {}),
|
|
13929
|
+
...(hit.image_url !== undefined ? {
|
|
13930
|
+
image_url: hit.image_url
|
|
13931
|
+
} : {}),
|
|
13932
|
+
page_url: hit.url,
|
|
13933
|
+
highlights: hit.highlights ?? []
|
|
13934
|
+
}));
|
|
13935
|
+
}
|
|
13936
|
+
function $4261fabd2fa94c86$export$efb7dd882d411dd4(response, door, offset) {
|
|
13937
|
+
const tracking_key = door === "search" ? "search_result_id" : "product_listing_result_id";
|
|
13938
|
+
return {
|
|
13939
|
+
n_hits: response.total ?? offset + response.products.length,
|
|
13940
|
+
sorts: $debf9654214236f5$export$cd08b64be5110ce2(response.sorts ?? []),
|
|
13941
|
+
filters: $debf9654214236f5$export$da9af372695714ef(response.facets ?? [], response.currency),
|
|
13942
|
+
...(door === "search" ? {
|
|
13943
|
+
search_request_id: response.request_id,
|
|
13944
|
+
content_search_links: $debf9654214236f5$export$b84a41a5163c4fce(response.content ?? []),
|
|
13945
|
+
is_fallback: null
|
|
13946
|
+
} : {
|
|
13947
|
+
product_listing_request_id: response.request_id
|
|
13948
|
+
}),
|
|
13949
|
+
...(response.cursor !== undefined ? {
|
|
13950
|
+
cursor: response.cursor
|
|
13951
|
+
} : {}),
|
|
13952
|
+
displays: response.products.map(product => $6b1ba052a9f2341e$export$7abfb7bc025aaea8(product, tracking_key))
|
|
13953
|
+
};
|
|
13954
|
+
}
|
|
13955
|
+
function $4261fabd2fa94c86$var$listing_ref_to_v3(ref, listing_type, show) {
|
|
13956
|
+
return {
|
|
13957
|
+
listing_id: ref.id,
|
|
13958
|
+
...(ref.external_id !== undefined ? {
|
|
13959
|
+
external_id: ref.external_id
|
|
13960
|
+
} : {}),
|
|
13961
|
+
listing_type: listing_type,
|
|
13962
|
+
...show,
|
|
13963
|
+
image_urls: [],
|
|
13964
|
+
title: ref.title,
|
|
13965
|
+
...(ref.slug !== undefined ? {
|
|
13966
|
+
slug: ref.slug
|
|
13967
|
+
} : {})
|
|
13968
|
+
};
|
|
13969
|
+
}
|
|
13970
|
+
function $4261fabd2fa94c86$export$996f2b1e66d9b5af(listing) {
|
|
13971
|
+
const listing_type = listing.type;
|
|
13972
|
+
const quick_links_are_siblings = listing.quick_links.some(link => link.id === listing.id);
|
|
13973
|
+
const quick_links = listing.quick_links.map(link => $4261fabd2fa94c86$var$listing_ref_to_v3(link, listing_type, {
|
|
13974
|
+
show_in_breadcrumbs: true,
|
|
13975
|
+
show_in_quicklinks: true
|
|
13976
|
+
}));
|
|
13977
|
+
return {
|
|
13978
|
+
listing_id: listing.id,
|
|
13979
|
+
...(listing.external_id !== undefined ? {
|
|
13980
|
+
external_id: listing.external_id
|
|
13981
|
+
} : {}),
|
|
13982
|
+
listing_type: listing_type,
|
|
13983
|
+
show_in_breadcrumbs: listing.show_in_breadcrumbs,
|
|
13984
|
+
show_in_quicklinks: true,
|
|
13985
|
+
image_urls: listing.images,
|
|
13986
|
+
title: listing.title,
|
|
13987
|
+
...(listing.slug !== undefined ? {
|
|
13988
|
+
slug: listing.slug
|
|
13989
|
+
} : {}),
|
|
13990
|
+
ancestors: listing.breadcrumbs.map(ref => $4261fabd2fa94c86$var$listing_ref_to_v3(ref, "category", {
|
|
13991
|
+
show_in_breadcrumbs: true,
|
|
13992
|
+
show_in_quicklinks: true
|
|
13993
|
+
})),
|
|
13994
|
+
siblings: quick_links_are_siblings ? quick_links : [],
|
|
13995
|
+
children: quick_links_are_siblings ? [] : quick_links,
|
|
13996
|
+
content_blocks: listing.content_blocks
|
|
13997
|
+
};
|
|
13998
|
+
}
|
|
13999
|
+
function $4261fabd2fa94c86$export$76d96892da63b395(tree) {
|
|
14000
|
+
const by_id = new Map();
|
|
14001
|
+
const walk = (nodes, chain) => {
|
|
14002
|
+
for (const node of nodes) {
|
|
14003
|
+
if (!by_id.has(node.id)) by_id.set(node.id, chain);
|
|
14004
|
+
walk(node.children, [...chain, $4261fabd2fa94c86$var$listing_ref_to_v3(node, node.type, {
|
|
14005
|
+
show_in_breadcrumbs: true,
|
|
14006
|
+
show_in_quicklinks: true
|
|
14007
|
+
})]);
|
|
14008
|
+
}
|
|
14009
|
+
};
|
|
14010
|
+
walk(tree, []);
|
|
14011
|
+
return listing_id => by_id.get(listing_id);
|
|
14012
|
+
}
|
|
14013
|
+
function $4261fabd2fa94c86$export$2860125b419015f8(response, ancestors_of) {
|
|
14014
|
+
return {
|
|
14015
|
+
suggestions_request_id: response.request_id,
|
|
14016
|
+
suggestions: response.suggestions.map(suggestion => {
|
|
14017
|
+
if (suggestion.type === "query") return {
|
|
14018
|
+
type: "query",
|
|
14019
|
+
query: suggestion.query,
|
|
14020
|
+
suggestions_result_id: ""
|
|
14021
|
+
};
|
|
14022
|
+
const from_tree = ancestors_of?.(suggestion.listing.id);
|
|
14023
|
+
const ancestors = from_tree && $4261fabd2fa94c86$var$same_titles(from_tree, suggestion.path) ? from_tree : [];
|
|
14024
|
+
return {
|
|
14025
|
+
type: "listing",
|
|
14026
|
+
listing_id: suggestion.listing.id,
|
|
14027
|
+
...(suggestion.listing.external_id !== undefined ? {
|
|
14028
|
+
external_id: suggestion.listing.external_id
|
|
14029
|
+
} : {}),
|
|
14030
|
+
listing_type: suggestion.listing.type,
|
|
14031
|
+
show_in_breadcrumbs: true,
|
|
14032
|
+
show_in_quicklinks: true,
|
|
14033
|
+
image_urls: suggestion.listing.images,
|
|
14034
|
+
title: suggestion.listing.title,
|
|
14035
|
+
...(suggestion.listing.slug !== undefined ? {
|
|
14036
|
+
slug: suggestion.listing.slug
|
|
14037
|
+
} : {}),
|
|
14038
|
+
suggestions_result_id: "",
|
|
14039
|
+
ancestors: ancestors
|
|
14040
|
+
};
|
|
14041
|
+
})
|
|
14042
|
+
};
|
|
14043
|
+
}
|
|
14044
|
+
const $4261fabd2fa94c86$var$same_titles = (ancestors, path) => ancestors.length === path.length && ancestors.every((ancestor, index) => ancestor.title === path[index]);
|
|
14045
|
+
/** `encodeURIComponent`, as V4's own encoder writes a value (`+` would mean a space). */
|
|
14046
|
+
const $4261fabd2fa94c86$var$encode = value => encodeURIComponent(value);
|
|
14047
|
+
function $4261fabd2fa94c86$export$7659319cdb555579(request) {
|
|
14048
|
+
const pairs = [`market=${$4261fabd2fa94c86$var$encode(request.market)}`];
|
|
14049
|
+
const add = (key, value) => value !== undefined && pairs.push(`${key}=${value}`);
|
|
14050
|
+
add("locale", request.locale === undefined ? undefined : $4261fabd2fa94c86$var$encode(request.locale));
|
|
14051
|
+
add("query", request.query === undefined ? undefined : $4261fabd2fa94c86$var$encode(request.query));
|
|
14052
|
+
if (request.listing && "id" in request.listing) add("listing", $4261fabd2fa94c86$var$encode(request.listing.id));else if (request.listing) add("listing_external_id", $4261fabd2fa94c86$var$encode(request.listing.external_id));
|
|
14053
|
+
add("filter_by", request.filter_by === undefined ? undefined : $4261fabd2fa94c86$var$encode(request.filter_by));
|
|
14054
|
+
if (request.sort) add("sort", `${$4261fabd2fa94c86$var$encode(request.sort.field)}.${request.sort.order}`);
|
|
14055
|
+
add("include", request.include?.join(","));
|
|
14056
|
+
add("cursor", request.cursor);
|
|
14057
|
+
add("limit", request.limit === undefined ? undefined : String(request.limit));
|
|
14058
|
+
return pairs.join("&");
|
|
14059
|
+
}
|
|
14060
|
+
function $4261fabd2fa94c86$export$fec3e4b5adfcea2c(params) {
|
|
14061
|
+
return params.filter(pair => pair[1] !== undefined).map(([key, value]) => `${key}=${$4261fabd2fa94c86$var$encode(value)}`).join("&");
|
|
14062
|
+
}
|
|
14063
|
+
function $4261fabd2fa94c86$export$eb90c08da400512d(locale) {
|
|
14064
|
+
return locale ? locale.replace(/_/g, "-") : undefined;
|
|
14065
|
+
}
|
|
14066
|
+
|
|
14067
|
+
/** realtime's related search page: the hits related recommendations anchor on and never repeat. */
|
|
14068
|
+
const $ce8babba0db8995c$var$RELATED_SEARCH_PAGE = 100;
|
|
14069
|
+
const $ce8babba0db8995c$var$get_recommendations = (merchant, request) => $c25fb5290ccf7b3e$export$88d793e3827f3436($c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, "/recommendations") + "?" + $c82154cf2888f2b2$export$fc756666ac777d0(request));
|
|
14070
|
+
const $ce8babba0db8995c$var$to_displays = products => products.map(product => $6b1ba052a9f2341e$export$7abfb7bc025aaea8(product, "recommendation_id"));
|
|
14071
|
+
async function $ce8babba0db8995c$export$656ee5c46d5d1eda(call) {
|
|
14072
|
+
const {
|
|
14073
|
+
merchant: merchant
|
|
14074
|
+
} = call;
|
|
14075
|
+
const types = await $48a2cfb8445bcd57$export$869eb14d6f85ac51(merchant);
|
|
14076
|
+
const inputs = types?.get(call.type);
|
|
14077
|
+
if (types && !inputs) {
|
|
14078
|
+
$gVhhF$depictaiutilishared.dwarn(`[NativeDepictAPI] V4 serves ${merchant} no recommendation type "${call.type}"; known:`, [...types.keys()]);
|
|
14079
|
+
return [];
|
|
14080
|
+
}
|
|
14081
|
+
const request = $c82154cf2888f2b2$export$17493dc1a89b34e6({
|
|
14082
|
+
...call,
|
|
14083
|
+
locale: $4261fabd2fa94c86$export$eb90c08da400512d(call.locale)
|
|
14084
|
+
}, inputs, inputs?.includes("recent_views") ? $b6d3e4dd179febae$export$2d7138f47b625a04(merchant) : []);
|
|
14085
|
+
if (!request) return [];
|
|
14086
|
+
const response = await $ce8babba0db8995c$var$get_recommendations(merchant, request);
|
|
14087
|
+
if (!response) return [];
|
|
14088
|
+
const anchor = response.used_inputs?.anchor;
|
|
14089
|
+
if (call.productId && anchor?.type === "product") $b6d3e4dd179febae$export$6379943de8f8af08(merchant, anchor.id);
|
|
14090
|
+
return $ce8babba0db8995c$var$to_displays(response.products);
|
|
14091
|
+
}
|
|
14092
|
+
async function $ce8babba0db8995c$export$bd5f8a7d3e47a43d(call) {
|
|
14093
|
+
const {
|
|
14094
|
+
merchant: merchant,
|
|
14095
|
+
market: market
|
|
14096
|
+
} = call;
|
|
14097
|
+
const types = await $48a2cfb8445bcd57$export$869eb14d6f85ac51(merchant);
|
|
14098
|
+
if (!types) return undefined;
|
|
14099
|
+
const type = types.get("search")?.includes("anchor") ? "search" : types.get("similar")?.includes("anchor") ? "similar" : undefined;
|
|
14100
|
+
if (!type) {
|
|
14101
|
+
$gVhhF$depictaiutilishared.dwarn(`[NativeDepictAPI] V4 serves ${merchant} no search or similar recommendations for related products`);
|
|
14102
|
+
return [];
|
|
14103
|
+
}
|
|
14104
|
+
const locale = $4261fabd2fa94c86$export$eb90c08da400512d(call.locale);
|
|
14105
|
+
const query = call.query?.trim() || undefined;
|
|
14106
|
+
const searched = await $c25fb5290ccf7b3e$export$88d793e3827f3436($c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, "/browse") + "?" + $4261fabd2fa94c86$export$7659319cdb555579({
|
|
14107
|
+
market: market,
|
|
14108
|
+
...(locale ? {
|
|
14109
|
+
locale: locale
|
|
14110
|
+
} : {}),
|
|
14111
|
+
...(query ? {
|
|
14112
|
+
query: query
|
|
14113
|
+
} : {}),
|
|
14114
|
+
limit: $ce8babba0db8995c$var$RELATED_SEARCH_PAGE
|
|
14115
|
+
}));
|
|
14116
|
+
if (!searched) return undefined;
|
|
14117
|
+
const asked = $c82154cf2888f2b2$export$afe6aeae61a7aa58(searched.products, {
|
|
14118
|
+
market: market,
|
|
14119
|
+
...(locale ? {
|
|
14120
|
+
locale: locale
|
|
14121
|
+
} : {})
|
|
14122
|
+
}, type);
|
|
14123
|
+
if (!asked.length) return [];
|
|
14124
|
+
const answers = await Promise.all(asked.map(request => $ce8babba0db8995c$var$get_recommendations(merchant, request)));
|
|
14125
|
+
const lists = answers.filter(answer => !!answer).map(answer => answer.products);
|
|
14126
|
+
if (!lists.length) return undefined;
|
|
14127
|
+
const products = lists.length > 1 ? $c82154cf2888f2b2$export$9af50be6508dcd00(lists, Math.max(...lists.map(list => list.length))) : lists[0];
|
|
14128
|
+
return $ce8babba0db8995c$var$to_displays(products);
|
|
14129
|
+
}
|
|
13335
14130
|
async function $bd429c994399dd82$export$58e808b1db15d3bc(options) {
|
|
14131
|
+
if (options.api === "v4") return await $bd429c994399dd82$var$fetch_native(options);
|
|
13336
14132
|
const headers = options.headers;
|
|
13337
14133
|
const product_id = options.productId || options.product_id; // Second fallback here is just because there was very little missing to make this work with snake_case input and in case someone puts in snake case'd stuff already (preview browser did) we can easily not break it
|
|
13338
14134
|
const cleaned_up_options = $gVhhF$depictaiutilishared.snakeCasifyObject(options);
|
|
13339
14135
|
delete cleaned_up_options.headers;
|
|
13340
14136
|
delete cleaned_up_options.product_id;
|
|
14137
|
+
delete cleaned_up_options.api;
|
|
13341
14138
|
cleaned_up_options.session_id ||= $gVhhF$depictaiutilishared.get_session_id();
|
|
13342
14139
|
if (product_id && !cleaned_up_options.product_ids) cleaned_up_options.product_ids = [product_id];
|
|
13343
14140
|
const options_to_send = cleaned_up_options;
|
|
@@ -13359,6 +14156,33 @@ async function $bd429c994399dd82$export$58e808b1db15d3bc(options) {
|
|
|
13359
14156
|
return decoded?.displays || [];
|
|
13360
14157
|
});
|
|
13361
14158
|
}
|
|
14159
|
+
async function $bd429c994399dd82$var$fetch_native(options) {
|
|
14160
|
+
const {
|
|
14161
|
+
merchant: merchant,
|
|
14162
|
+
market: market,
|
|
14163
|
+
locale: locale,
|
|
14164
|
+
type: type,
|
|
14165
|
+
headers: headers,
|
|
14166
|
+
categoryId: categoryId,
|
|
14167
|
+
productIds: productIds
|
|
14168
|
+
} = options;
|
|
14169
|
+
if (headers) $gVhhF$depictaiutilishared.dwarn("fetchDepictRecommendations: headers aren't sent to the native V4 API", headers);
|
|
14170
|
+
try {
|
|
14171
|
+
return await $ce8babba0db8995c$export$656ee5c46d5d1eda({
|
|
14172
|
+
merchant: merchant,
|
|
14173
|
+
market: market,
|
|
14174
|
+
locale: locale,
|
|
14175
|
+
type: type,
|
|
14176
|
+
categoryId: categoryId,
|
|
14177
|
+
productId: options.productId || options.product_id,
|
|
14178
|
+
productIds: productIds,
|
|
14179
|
+
limit: options.limit
|
|
14180
|
+
});
|
|
14181
|
+
} catch (e) {
|
|
14182
|
+
$gVhhF$depictaiutilishared.dlog("fetch_native_recommendations threw", e);
|
|
14183
|
+
return [];
|
|
14184
|
+
}
|
|
14185
|
+
}
|
|
13362
14186
|
var $85b747260aa175c9$var$_tmpl$ = /*#__PURE__*/$gVhhF$solidjsweb.template(`<div class="sort-and-filter-buttons fake"aria-hidden=true style=position:absolute;z-index:-1;pointer-events:none;opacity:0><div class=outer><div class=inner><!$><!/><!$><!/><!$><!/>`);
|
|
13363
14187
|
const $85b747260aa175c9$export$824dde41348efed1 = /*@__PURE__*/(() => {
|
|
13364
14188
|
const actual_function = ({
|
|
@@ -13759,7 +14583,10 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13759
14583
|
input_req_: input_req_,
|
|
13760
14584
|
fallback_response_: fallback_response_,
|
|
13761
14585
|
method_ = "POST",
|
|
13762
|
-
currentListingForTransformer_: currentListingForTransformer_
|
|
14586
|
+
currentListingForTransformer_: currentListingForTransformer_,
|
|
14587
|
+
kind_: kind_,
|
|
14588
|
+
id_to_query_for_: id_to_query_for_,
|
|
14589
|
+
id_type_: id_type_
|
|
13763
14590
|
}) {
|
|
13764
14591
|
const cache_obj = this.#get_cache_obj_for_endpoint(endpoint_);
|
|
13765
14592
|
const with_ids = this.#add_ids_to_request(input_req_);
|
|
@@ -13776,19 +14603,19 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13776
14603
|
let resolve_in_progress;
|
|
13777
14604
|
cache_obj.in_progress_[body] = new Promise(r => resolve_in_progress = r);
|
|
13778
14605
|
try {
|
|
13779
|
-
const is_post = method_ === "POST";
|
|
13780
|
-
const url_to_request = is_post ? endpoint_ : $gVhhF$depictaiutilishared.make_url_with_query_params(endpoint_, sorted_request);
|
|
13781
|
-
const api_response = await $gVhhF$depictaiutilishared.fetch_retry($gVhhF$depictaiutilishared.add_version_query_params(url_to_request), {
|
|
13782
|
-
method: method_,
|
|
13783
|
-
...(is_post ? {
|
|
13784
|
-
body: body
|
|
13785
|
-
} : {})
|
|
13786
|
-
});
|
|
13787
14606
|
return_successfully: {
|
|
13788
|
-
if (!api_response || api_response.status !== 200) break return_successfully;
|
|
13789
14607
|
let result;
|
|
13790
14608
|
try {
|
|
13791
|
-
const unmodified_result = await
|
|
14609
|
+
const unmodified_result = await this.request_raw_({
|
|
14610
|
+
kind_: kind_,
|
|
14611
|
+
endpoint_: endpoint_,
|
|
14612
|
+
method_: method_,
|
|
14613
|
+
request_: sorted_request,
|
|
14614
|
+
body_: body,
|
|
14615
|
+
id_to_query_for_: id_to_query_for_,
|
|
14616
|
+
id_type_: id_type_
|
|
14617
|
+
});
|
|
14618
|
+
if (unmodified_result === undefined) break return_successfully;
|
|
13792
14619
|
result = await this.#run_display_transformers_for_rest(input_req_.merchant, input_req_.market, input_req_.locale, unmodified_result, currentListingForTransformer_);
|
|
13793
14620
|
} catch (e) {
|
|
13794
14621
|
$gVhhF$depictaiutilishared.dwarn("displayTransformer or json decoding failed", e);
|
|
@@ -13816,6 +14643,29 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13816
14643
|
delete cache_obj.in_progress_[body];
|
|
13817
14644
|
}
|
|
13818
14645
|
}
|
|
14646
|
+
/**
|
|
14647
|
+
* The network step of every read: sends `call` to the v3 API and returns the decoded JSON, or undefined when the
|
|
14648
|
+
* request failed. NativeDepictAPI overrides this to read the native V4 API instead and map its answers to v3 shapes,
|
|
14649
|
+
* so caching, display transformers and fallbacks stay the same for both.
|
|
14650
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14651
|
+
async request_raw_(call) {
|
|
14652
|
+
const {
|
|
14653
|
+
endpoint_: endpoint_,
|
|
14654
|
+
method_: method_,
|
|
14655
|
+
request_: request_,
|
|
14656
|
+
body_: body_
|
|
14657
|
+
} = call;
|
|
14658
|
+
const is_post = method_ === "POST";
|
|
14659
|
+
const url_to_request = is_post ? endpoint_ : $gVhhF$depictaiutilishared.make_url_with_query_params(endpoint_, request_);
|
|
14660
|
+
const api_response = await $gVhhF$depictaiutilishared.fetch_retry($gVhhF$depictaiutilishared.add_version_query_params(url_to_request), {
|
|
14661
|
+
method: method_,
|
|
14662
|
+
...(is_post ? {
|
|
14663
|
+
body: body_
|
|
14664
|
+
} : {})
|
|
14665
|
+
});
|
|
14666
|
+
if (!api_response || call.kind_ !== "suggest" && api_response.status !== 200) return undefined;
|
|
14667
|
+
return await api_response.json();
|
|
14668
|
+
}
|
|
13819
14669
|
constructor(options) {
|
|
13820
14670
|
const {
|
|
13821
14671
|
get_metadata: get_metadata,
|
|
@@ -13832,11 +14682,13 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13832
14682
|
const request = metaData ? Object.assign(with_ids, {
|
|
13833
14683
|
metadata: JSON.stringify(metaData)
|
|
13834
14684
|
}) : with_ids;
|
|
13835
|
-
const url = $gVhhF$depictaiutilishared.make_url_with_query_params($e1d6c0f3d89d531c$var$search_base_url + "suggestions", request);
|
|
13836
|
-
const results = await $gVhhF$depictaiutilishared.fetch_retry($gVhhF$depictaiutilishared.add_version_query_params(url));
|
|
13837
14685
|
attempt_to_return_api_response: {
|
|
13838
|
-
|
|
13839
|
-
|
|
14686
|
+
const decoded_json = await this.request_raw_({
|
|
14687
|
+
kind_: "suggest",
|
|
14688
|
+
endpoint_: $e1d6c0f3d89d531c$var$search_base_url + "suggestions",
|
|
14689
|
+
method_: "GET",
|
|
14690
|
+
request_: request
|
|
14691
|
+
});
|
|
13840
14692
|
if (!Array.isArray(decoded_json?.suggestions)) break attempt_to_return_api_response;
|
|
13841
14693
|
try {
|
|
13842
14694
|
return await this.#run_url_creator_for_suggest(input_req.merchant, input_req.market, input_req.locale, decoded_json);
|
|
@@ -13853,6 +14705,7 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13853
14705
|
async query(input_req) {
|
|
13854
14706
|
return await this.#cached_request({
|
|
13855
14707
|
endpoint_: $e1d6c0f3d89d531c$var$search_base_url + "results",
|
|
14708
|
+
kind_: "search",
|
|
13856
14709
|
input_req_: input_req,
|
|
13857
14710
|
fallback_response_: () => ({
|
|
13858
14711
|
"n_hits": 0,
|
|
@@ -13872,6 +14725,9 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13872
14725
|
return await this.#cached_request({
|
|
13873
14726
|
endpoint_: $e1d6c0f3d89d531c$var$v3_base_url + "listings/" + (id_type_ === $779741d0f266ea8c$export$5aae649db1b959fc ? "external_id/" : "") + encodeURIComponent(id_to_query_for_),
|
|
13874
14727
|
input_req_: input_req,
|
|
14728
|
+
kind_: "listing",
|
|
14729
|
+
id_to_query_for_: id_to_query_for_,
|
|
14730
|
+
id_type_: id_type_,
|
|
13875
14731
|
fallback_response_: () => ({
|
|
13876
14732
|
listing_id: "",
|
|
13877
14733
|
listing_type: "category",
|
|
@@ -13898,6 +14754,9 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13898
14754
|
endpoint_: $e1d6c0f3d89d531c$var$v3_base_url + "listings/" + (id_type_ === $779741d0f266ea8c$export$5aae649db1b959fc ? "external_id/" : "") + encodeURIComponent(id_to_query_for_) + "/products",
|
|
13899
14755
|
input_req_: input_req_,
|
|
13900
14756
|
currentListingForTransformer_: currentListingForTransformer_,
|
|
14757
|
+
kind_: "listing_products",
|
|
14758
|
+
id_to_query_for_: id_to_query_for_,
|
|
14759
|
+
id_type_: id_type_,
|
|
13901
14760
|
fallback_response_: () => ({
|
|
13902
14761
|
"n_hits": 0,
|
|
13903
14762
|
"displays": [],
|
|
@@ -13911,6 +14770,7 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13911
14770
|
async get_recommended(input_req) {
|
|
13912
14771
|
return await this.#cached_request({
|
|
13913
14772
|
endpoint_: $e1d6c0f3d89d531c$var$search_base_url + "related",
|
|
14773
|
+
kind_: "related",
|
|
13914
14774
|
input_req_: input_req,
|
|
13915
14775
|
fallback_response_: () => ({
|
|
13916
14776
|
displays: []
|
|
@@ -13918,6 +14778,228 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
13918
14778
|
});
|
|
13919
14779
|
}
|
|
13920
14780
|
}
|
|
14781
|
+
|
|
14782
|
+
/** V4 browse's largest page; a bigger v3 page is V4's pages chained by their cursors, as the facade does. */
|
|
14783
|
+
const $100bd8804fbc65ac$var$BROWSE_MAX_LIMIT = 100;
|
|
14784
|
+
/** V4 browse's page size without a limit, and v3's. */
|
|
14785
|
+
const $100bd8804fbc65ac$var$DEFAULT_LIMIT = 24;
|
|
14786
|
+
/** A query with no letter or digit browses the catalogue instead of returning an empty grid, as on v3. */
|
|
14787
|
+
const $100bd8804fbc65ac$var$HAS_LETTER_OR_DIGIT = /[\p{L}\p{N}]/u;
|
|
14788
|
+
class $100bd8804fbc65ac$export$721afe49a594bed extends (0, $e1d6c0f3d89d531c$export$e015ed2f2950f2e3) {
|
|
14789
|
+
/** Facets served so far, per merchant, market and locale, to resolve v3 filter fields (group titles) to V4 fields. */#facet_indices = new Map();
|
|
14790
|
+
/** Browses whose facets were read only to resolve filter fields, so each is read at most once. */
|
|
14791
|
+
#learned = new Set();
|
|
14792
|
+
/** How many products came before each cursor V4 handed out, for the lower-bound count when `total` is absent. */
|
|
14793
|
+
#cursor_offsets = new Map();
|
|
14794
|
+
/** Each listing's ancestors from the listing tree, per merchant, market and locale, read once a page load. */
|
|
14795
|
+
#ancestor_lookups = new Map();
|
|
14796
|
+
/** Filter clauses V4 refused (`unknown_filter_field`, `invalid_filter`), per merchant, market and locale. */
|
|
14797
|
+
#rejected = new Map();
|
|
14798
|
+
constructor(options) {
|
|
14799
|
+
super(options);
|
|
14800
|
+
$gVhhF$depictaiutilishared.set_event_api("v4");
|
|
14801
|
+
}
|
|
14802
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14803
|
+
async request_raw_(call) {
|
|
14804
|
+
switch (call.kind_) {
|
|
14805
|
+
case "search":
|
|
14806
|
+
return await this.#browse("search", call.request_);
|
|
14807
|
+
case "listing_products":
|
|
14808
|
+
return await this.#browse("listing", call.request_, {
|
|
14809
|
+
[call.id_type_ === $779741d0f266ea8c$export$5aae649db1b959fc ? "external_id" : "id"]: call.id_to_query_for_
|
|
14810
|
+
});
|
|
14811
|
+
case "listing":
|
|
14812
|
+
return await this.#listing(call);
|
|
14813
|
+
case "suggest":
|
|
14814
|
+
return await this.#suggest(call.request_);
|
|
14815
|
+
case "related":
|
|
14816
|
+
{
|
|
14817
|
+
const {
|
|
14818
|
+
merchant: merchant,
|
|
14819
|
+
market: market,
|
|
14820
|
+
locale: locale,
|
|
14821
|
+
query: query
|
|
14822
|
+
} = call.request_;
|
|
14823
|
+
const displays = await $ce8babba0db8995c$export$bd5f8a7d3e47a43d({
|
|
14824
|
+
merchant: merchant,
|
|
14825
|
+
market: market,
|
|
14826
|
+
locale: locale,
|
|
14827
|
+
query: query
|
|
14828
|
+
});
|
|
14829
|
+
return displays && {
|
|
14830
|
+
displays: displays
|
|
14831
|
+
};
|
|
14832
|
+
}
|
|
14833
|
+
}
|
|
14834
|
+
}
|
|
14835
|
+
#merchant_url(merchant, path) {
|
|
14836
|
+
return $c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, path);
|
|
14837
|
+
}
|
|
14838
|
+
async #get_json(url) {
|
|
14839
|
+
return (await this.#get_answer(url)).body_;
|
|
14840
|
+
}
|
|
14841
|
+
/** A GET's body on a 200, else V4's error (when it sent one). */
|
|
14842
|
+
async #get_answer(url) {
|
|
14843
|
+
return await $c25fb5290ccf7b3e$export$f035610fd74c541a(url);
|
|
14844
|
+
}
|
|
14845
|
+
#facet_index(merchant, market, locale) {
|
|
14846
|
+
const key = JSON.stringify([merchant, market, locale]);
|
|
14847
|
+
let index = this.#facet_indices.get(key);
|
|
14848
|
+
if (!index) this.#facet_indices.set(key, index = new (0, $debf9654214236f5$export$8d488bcc71d07ffb)());
|
|
14849
|
+
return index;
|
|
14850
|
+
}
|
|
14851
|
+
async #browse_page(merchant, request) {
|
|
14852
|
+
return (await this.#browse_answer(merchant, request)).body_;
|
|
14853
|
+
}
|
|
14854
|
+
async #browse_answer(merchant, request) {
|
|
14855
|
+
return await this.#get_answer(this.#merchant_url(merchant, "/browse") + "?" + $4261fabd2fa94c86$export$7659319cdb555579(request));
|
|
14856
|
+
}
|
|
14857
|
+
/** The filter clauses V4 refused, per merchant, market and locale, for this page load. */
|
|
14858
|
+
#rejected_clauses(merchant, market, locale) {
|
|
14859
|
+
const key = JSON.stringify([merchant, market, locale]);
|
|
14860
|
+
let rejected = this.#rejected.get(key);
|
|
14861
|
+
if (!rejected) this.#rejected.set(key, rejected = new Set());
|
|
14862
|
+
return rejected;
|
|
14863
|
+
}
|
|
14864
|
+
async #browse(door, v3_request, listing) {
|
|
14865
|
+
const {
|
|
14866
|
+
merchant: merchant,
|
|
14867
|
+
market: market
|
|
14868
|
+
} = v3_request;
|
|
14869
|
+
const locale = $4261fabd2fa94c86$export$eb90c08da400512d(v3_request.locale);
|
|
14870
|
+
const query = door === "search" && v3_request.query && $100bd8804fbc65ac$var$HAS_LETTER_OR_DIGIT.test(v3_request.query) ? v3_request.query : undefined;
|
|
14871
|
+
const base = {
|
|
14872
|
+
market: market,
|
|
14873
|
+
...(locale ? {
|
|
14874
|
+
locale: locale
|
|
14875
|
+
} : {}),
|
|
14876
|
+
...(query ? {
|
|
14877
|
+
query: query
|
|
14878
|
+
} : {}),
|
|
14879
|
+
...(listing ? {
|
|
14880
|
+
listing: listing
|
|
14881
|
+
} : {})
|
|
14882
|
+
};
|
|
14883
|
+
const index = this.#facet_index(merchant, market, locale);
|
|
14884
|
+
const filters = v3_request.filters ?? [];
|
|
14885
|
+
// depict-ui sends a filter's lowercased group title as its field. A page opened from a link with filters in it
|
|
14886
|
+
// comes before any facets, so read this browse's facets once to learn which field each title names.
|
|
14887
|
+
const learn_key = JSON.stringify([merchant, base]);
|
|
14888
|
+
if (filters.some(filter => filter.data != null && !$debf9654214236f5$export$3b6ba2422a5e0aa0(filter.field, index)) && !this.#learned.has(learn_key)) {
|
|
14889
|
+
this.#learned.add(learn_key);
|
|
14890
|
+
index.learn_((await this.#browse_page(merchant, {
|
|
14891
|
+
...base,
|
|
14892
|
+
include: ["facets"],
|
|
14893
|
+
limit: 1
|
|
14894
|
+
}))?.facets);
|
|
14895
|
+
}
|
|
14896
|
+
// A filter V4 can't take must not cost the shopper the page: a link can outlive its filter (one removed from the
|
|
14897
|
+
// store, a hand-written value). One the adapter can't write is left out here; one V4 rejects is left out and the
|
|
14898
|
+
// page asked again, and remembered for this page load so later pages don't ask with it.
|
|
14899
|
+
const rejected = this.#rejected_clauses(merchant, market, locale);
|
|
14900
|
+
let clauses = [];
|
|
14901
|
+
for (const filter of filters) try {
|
|
14902
|
+
const clause = $debf9654214236f5$export$c17bb5d2ead3e8f3(filter, index);
|
|
14903
|
+
if (clause) clauses.push(clause);
|
|
14904
|
+
} catch (e) {
|
|
14905
|
+
if (!(e instanceof (0, $debf9654214236f5$export$f5ea4d073ddb4bdb))) throw e;
|
|
14906
|
+
$gVhhF$depictaiutilishared.dwarn("[NativeDepictAPI] leaving out a filter V4 can't take:", e.message, filter);
|
|
14907
|
+
}
|
|
14908
|
+
clauses = clauses.filter(clause => !rejected.has(clause.clause_));
|
|
14909
|
+
const sort = $debf9654214236f5$export$78eb8e636d89ff30(v3_request.sort);
|
|
14910
|
+
const include = door === "search" ? ["facets", "sorts", "content", "attributes"] : ["facets", "sorts", "attributes"];
|
|
14911
|
+
const want = v3_request.limit ?? $100bd8804fbc65ac$var$DEFAULT_LIMIT;
|
|
14912
|
+
const offset = v3_request.cursor && this.#cursor_offsets.get(v3_request.cursor) || 0;
|
|
14913
|
+
const request_with = sent => ({
|
|
14914
|
+
...base,
|
|
14915
|
+
...(sent.length ? {
|
|
14916
|
+
filter_by: sent.map(clause => clause.clause_).join(" && ")
|
|
14917
|
+
} : {}),
|
|
14918
|
+
...(sort ? {
|
|
14919
|
+
sort: sort
|
|
14920
|
+
} : {}),
|
|
14921
|
+
...(v3_request.cursor ? {
|
|
14922
|
+
cursor: v3_request.cursor
|
|
14923
|
+
} : {}),
|
|
14924
|
+
include: include,
|
|
14925
|
+
...(want !== $100bd8804fbc65ac$var$DEFAULT_LIMIT ? {
|
|
14926
|
+
limit: Math.min(want, $100bd8804fbc65ac$var$BROWSE_MAX_LIMIT)
|
|
14927
|
+
} : {})
|
|
14928
|
+
});
|
|
14929
|
+
let request = request_with(clauses);
|
|
14930
|
+
let answer = await this.#browse_answer(merchant, request);
|
|
14931
|
+
// Each retry leaves out at least one more clause, so this ends.
|
|
14932
|
+
while (!answer.body_) {
|
|
14933
|
+
const refused = $debf9654214236f5$export$c38de645260a41ed(answer.error_, clauses);
|
|
14934
|
+
if (!refused.length) return undefined;
|
|
14935
|
+
$gVhhF$depictaiutilishared.dwarn("[NativeDepictAPI] leaving out filters V4 refused:", refused.map(clause => clause.clause_), answer.error_?.message);
|
|
14936
|
+
for (const clause of refused) rejected.add(clause.clause_);
|
|
14937
|
+
clauses = clauses.filter(clause => !refused.includes(clause));
|
|
14938
|
+
request = request_with(clauses);
|
|
14939
|
+
answer = await this.#browse_answer(merchant, request);
|
|
14940
|
+
}
|
|
14941
|
+
let response = answer.body_;
|
|
14942
|
+
// A page over V4's largest is its pages chained by their cursors; later pages ask for products alone.
|
|
14943
|
+
while (want > $100bd8804fbc65ac$var$BROWSE_MAX_LIMIT && response.products.length < want && response.cursor !== undefined) {
|
|
14944
|
+
const page = await this.#browse_page(merchant, {
|
|
14945
|
+
...request,
|
|
14946
|
+
cursor: response.cursor,
|
|
14947
|
+
limit: Math.min(want - response.products.length, $100bd8804fbc65ac$var$BROWSE_MAX_LIMIT),
|
|
14948
|
+
include: ["attributes"]
|
|
14949
|
+
});
|
|
14950
|
+
if (!page) return undefined;
|
|
14951
|
+
if (!page.products.length) break;
|
|
14952
|
+
response = {
|
|
14953
|
+
...response,
|
|
14954
|
+
products: [...response.products, ...page.products],
|
|
14955
|
+
...(page.cursor !== undefined ? {
|
|
14956
|
+
cursor: page.cursor
|
|
14957
|
+
} : {
|
|
14958
|
+
cursor: undefined
|
|
14959
|
+
})
|
|
14960
|
+
};
|
|
14961
|
+
}
|
|
14962
|
+
if (response.cursor === undefined) delete response.cursor;
|
|
14963
|
+
index.learn_(response.facets);
|
|
14964
|
+
if (response.cursor !== undefined) this.#cursor_offsets.set(response.cursor, offset + response.products.length);
|
|
14965
|
+
return $4261fabd2fa94c86$export$efb7dd882d411dd4(response, door, offset);
|
|
14966
|
+
}
|
|
14967
|
+
async #listing(call) {
|
|
14968
|
+
const {
|
|
14969
|
+
merchant: merchant,
|
|
14970
|
+
market: market
|
|
14971
|
+
} = call.request_;
|
|
14972
|
+
const locale = $4261fabd2fa94c86$export$eb90c08da400512d(call.request_.locale);
|
|
14973
|
+
const by_external_id = call.id_type_ === $779741d0f266ea8c$export$5aae649db1b959fc;
|
|
14974
|
+
const path = by_external_id ? "/listings" : "/listings/" + encodeURIComponent(call.id_to_query_for_);
|
|
14975
|
+
const response = await this.#get_json(this.#merchant_url(merchant, path) + "?" + $4261fabd2fa94c86$export$fec3e4b5adfcea2c([["market", market], ["locale", locale], ["external_id", by_external_id ? call.id_to_query_for_ : undefined]]));
|
|
14976
|
+
return response && $4261fabd2fa94c86$export$996f2b1e66d9b5af(response.listing);
|
|
14977
|
+
}
|
|
14978
|
+
async #suggest(v3_request) {
|
|
14979
|
+
const {
|
|
14980
|
+
merchant: merchant,
|
|
14981
|
+
market: market
|
|
14982
|
+
} = v3_request;
|
|
14983
|
+
const locale = $4261fabd2fa94c86$export$eb90c08da400512d(v3_request.locale);
|
|
14984
|
+
const response = await this.#get_json(this.#merchant_url(merchant, "/suggest") + "?" + $4261fabd2fa94c86$export$fec3e4b5adfcea2c([["market", market], ["locale", locale], ["query", v3_request.query ?? ""]]));
|
|
14985
|
+
if (!response) return undefined;
|
|
14986
|
+
const needs_ancestors = response.suggestions.some(suggestion => suggestion.type === "listing" && suggestion.path.length > 0);
|
|
14987
|
+
return $4261fabd2fa94c86$export$2860125b419015f8(response, needs_ancestors ? await this.#ancestors(merchant, market, locale) : undefined);
|
|
14988
|
+
}
|
|
14989
|
+
/** V4 suggestions name ancestors by title only; the listing tree names them by id. A failed read isn't retried. */
|
|
14990
|
+
#ancestors(merchant, market, locale) {
|
|
14991
|
+
const key = JSON.stringify([merchant, market, locale]);
|
|
14992
|
+
let lookup = this.#ancestor_lookups.get(key);
|
|
14993
|
+
if (!lookup) {
|
|
14994
|
+
lookup = this.#get_json(this.#merchant_url(merchant, "/listings") + "?" + $4261fabd2fa94c86$export$fec3e4b5adfcea2c([["market", market], ["locale", locale]])).then(tree => tree && $4261fabd2fa94c86$export$76d96892da63b395(tree.listings));
|
|
14995
|
+
this.#ancestor_lookups.set(key, lookup);
|
|
14996
|
+
}
|
|
14997
|
+
return lookup;
|
|
14998
|
+
}
|
|
14999
|
+
}
|
|
15000
|
+
function $100bd8804fbc65ac$export$6d972e6af9de09f0(version, options) {
|
|
15001
|
+
return version === "v4" ? new $100bd8804fbc65ac$export$721afe49a594bed(options) : new (0, $e1d6c0f3d89d531c$export$e015ed2f2950f2e3)(options);
|
|
15002
|
+
}
|
|
13921
15003
|
function $c79fd10a3ab7d6e0$export$477caf01aecaeb2a(options) {
|
|
13922
15004
|
const router_ = options.router_;
|
|
13923
15005
|
const search_query_url_param_name_ = "search_query_url_param_name_" in options ? options.search_query_url_param_name_ : undefined;
|
|
@@ -14168,8 +15250,9 @@ class $48567ac5b39bac56$export$f34314aa9505732e {
|
|
|
14168
15250
|
quicklinks_signal_: $gVhhF$solidjs.createSignal(),
|
|
14169
15251
|
i18n_: i18n_,
|
|
14170
15252
|
reset_history_state_: reset_history_state_,
|
|
15253
|
+
depict_api_: typeof api === "object" && api ? api :
|
|
14171
15254
|
// @ts-ignore
|
|
14172
|
-
|
|
15255
|
+
$100bd8804fbc65ac$export$6d972e6af9de09f0(api, {
|
|
14173
15256
|
display_transformers: display_transformers
|
|
14174
15257
|
}),
|
|
14175
15258
|
router_: this.#router,
|
|
@@ -15725,8 +16808,9 @@ class $2c61e4cd8229c49a$export$ac6237957a15b3f0 {
|
|
|
15725
16808
|
const get_search_query_ = $gVhhF$solidjs.createMemo(previous_value => {
|
|
15726
16809
|
if (get_search_query_updating_blocked()) return previous_value;else return raw_search_query_accessor();
|
|
15727
16810
|
});
|
|
16811
|
+
const depict_api_ = typeof api === "object" && api ? api :
|
|
15728
16812
|
// @ts-ignore
|
|
15729
|
-
|
|
16813
|
+
$100bd8804fbc65ac$export$6d972e6af9de09f0(api, {
|
|
15730
16814
|
display_transformers: display_transformers
|
|
15731
16815
|
});
|
|
15732
16816
|
const previous_searches = $2b7a005a65221045$export$84bba84a7b837187(get_search_query_);
|