@depict-ai/ui 4.10.32 → 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 +1201 -20
- package/ES10/index.d.ts +102 -3
- package/ES10/index.js +1201 -22
- package/latest/index.cjs +1090 -18
- package/latest/index.d.ts +102 -3
- package/latest/index.js +1090 -20
- package/package.json +4 -4
- package/server/ES10/index.cjs +1201 -20
- package/server/ES10/index.d.ts +102 -3
- package/server/ES10/index.js +1201 -22
- package/server/latest/index.cjs +1090 -18
- package/server/latest/index.d.ts +102 -3
- package/server/latest/index.js +1090 -20
package/server/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 = $5vyXB$solidjs.createSignal(false);
|
|
115
117
|
$5vyXB$solidjs.onCleanup($5vyXB$depictaiutilishared.javascript_media_query(media_query, ({
|
|
@@ -10776,12 +10778,795 @@ function $0785f4c9947d9b5f$export$f091cbac892643a4(obj) {
|
|
|
10776
10778
|
return Object.fromEntries(mapped_stuff); // FUCK TYPESCRIPT, WHY CAN'T YOU DO THIS CORRECTLY???
|
|
10777
10779
|
}
|
|
10778
10780
|
|
|
10781
|
+
/** One try and at most two retries: a 503 burst from V4 shouldn't be multiplied by fetch_retry's default of 10. */
|
|
10782
|
+
const $c25fb5290ccf7b3e$var$NATIVE_MAX_TRIES = 3;
|
|
10783
|
+
function $c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, path) {
|
|
10784
|
+
return `${(0, $5vyXB$depictaiutilishared.base_url)}/v4/${encodeURIComponent(merchant)}${path}`;
|
|
10785
|
+
}
|
|
10786
|
+
async function $c25fb5290ccf7b3e$export$88d793e3827f3436(url) {
|
|
10787
|
+
return (await $c25fb5290ccf7b3e$export$f035610fd74c541a(url)).body_;
|
|
10788
|
+
}
|
|
10789
|
+
async function $c25fb5290ccf7b3e$export$f035610fd74c541a(url) {
|
|
10790
|
+
const response = await $5vyXB$depictaiutilishared.fetch_retry(url, {
|
|
10791
|
+
method: "GET"
|
|
10792
|
+
}, $c25fb5290ccf7b3e$var$NATIVE_MAX_TRIES);
|
|
10793
|
+
if (!response) {
|
|
10794
|
+
$5vyXB$depictaiutilishared.dwarn("[NativeDepictAPI] no response from", url);
|
|
10795
|
+
return {};
|
|
10796
|
+
}
|
|
10797
|
+
if (response.status === 200)
|
|
10798
|
+
// 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
|
|
10799
|
+
// back instead of rejecting: get_recommendation_types then forgets the read rather than keeping it in flight.
|
|
10800
|
+
try {
|
|
10801
|
+
return {
|
|
10802
|
+
body_: await response.json()
|
|
10803
|
+
};
|
|
10804
|
+
} catch (e) {
|
|
10805
|
+
$5vyXB$depictaiutilishared.dwarn("[NativeDepictAPI] 200 without a JSON body from", url, e);
|
|
10806
|
+
return {};
|
|
10807
|
+
}
|
|
10808
|
+
let error;
|
|
10809
|
+
try {
|
|
10810
|
+
error = (await response.json()).error;
|
|
10811
|
+
} catch {
|
|
10812
|
+
// not V4's error body
|
|
10813
|
+
}
|
|
10814
|
+
$5vyXB$depictaiutilishared.dwarn("[NativeDepictAPI]", response.status, error?.code, error?.message, error?.request_id, url);
|
|
10815
|
+
if (response.status >= 500) $5vyXB$depictaiutilishared.report([new Error(`V4 ${response.status} ${error?.code ?? ""}`), "Native V4 request failed"], "warning", {
|
|
10816
|
+
url: url,
|
|
10817
|
+
status: response.status,
|
|
10818
|
+
code: error?.code,
|
|
10819
|
+
request_id: error?.request_id ?? response.headers.get("x-depict-request-id")
|
|
10820
|
+
});
|
|
10821
|
+
return {
|
|
10822
|
+
error_: error
|
|
10823
|
+
};
|
|
10824
|
+
}
|
|
10825
|
+
const $48a2cfb8445bcd57$export$8e79752841e7cdb4 = 900000;
|
|
10826
|
+
const $48a2cfb8445bcd57$var$storage_key = merchant => `depict_v4_recommendation_types_${merchant}`;
|
|
10827
|
+
/** One read per merchant and CONTEXT_TTL_MS in this page; a failed read is forgotten so the next caller tries again. */
|
|
10828
|
+
const $48a2cfb8445bcd57$var$in_flight = new Map();
|
|
10829
|
+
function $48a2cfb8445bcd57$var$from_storage(merchant, now) {
|
|
10830
|
+
try {
|
|
10831
|
+
const stored = JSON.parse(localStorage.getItem($48a2cfb8445bcd57$var$storage_key(merchant)) ?? "null");
|
|
10832
|
+
if (!stored || !Array.isArray(stored.types) || !(now - stored.fetched_at < $48a2cfb8445bcd57$export$8e79752841e7cdb4)) return undefined;
|
|
10833
|
+
return $48a2cfb8445bcd57$var$to_map(stored.types);
|
|
10834
|
+
} catch {
|
|
10835
|
+
return undefined;
|
|
10836
|
+
}
|
|
10837
|
+
}
|
|
10838
|
+
function $48a2cfb8445bcd57$var$to_storage(merchant, types, now) {
|
|
10839
|
+
try {
|
|
10840
|
+
localStorage.setItem($48a2cfb8445bcd57$var$storage_key(merchant), JSON.stringify({
|
|
10841
|
+
fetched_at: now,
|
|
10842
|
+
types: types
|
|
10843
|
+
}));
|
|
10844
|
+
} catch {
|
|
10845
|
+
// localStorage unavailable or full: read /context again on the next page.
|
|
10846
|
+
}
|
|
10847
|
+
}
|
|
10848
|
+
const $48a2cfb8445bcd57$var$to_map = types => new Map(types.map(({
|
|
10849
|
+
type: type,
|
|
10850
|
+
inputs: inputs
|
|
10851
|
+
}) => [type, inputs]));
|
|
10852
|
+
function $48a2cfb8445bcd57$export$869eb14d6f85ac51(merchant, now = Date.now()) {
|
|
10853
|
+
const pending = $48a2cfb8445bcd57$var$in_flight.get(merchant);
|
|
10854
|
+
if (pending && now - pending.started_at < $48a2cfb8445bcd57$export$8e79752841e7cdb4) return pending.read;
|
|
10855
|
+
const stored = $48a2cfb8445bcd57$var$from_storage(merchant, now);
|
|
10856
|
+
if (stored) return Promise.resolve(stored);
|
|
10857
|
+
const read = $c25fb5290ccf7b3e$export$88d793e3827f3436($c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, "/context")).then(context => {
|
|
10858
|
+
if (!context) {
|
|
10859
|
+
if ($48a2cfb8445bcd57$var$in_flight.get(merchant)?.read === read) $48a2cfb8445bcd57$var$in_flight.delete(merchant);
|
|
10860
|
+
return undefined;
|
|
10861
|
+
}
|
|
10862
|
+
const types = context.recommendation_types ?? [];
|
|
10863
|
+
$48a2cfb8445bcd57$var$to_storage(merchant, types, now);
|
|
10864
|
+
return $48a2cfb8445bcd57$var$to_map(types);
|
|
10865
|
+
});
|
|
10866
|
+
$48a2cfb8445bcd57$var$in_flight.set(merchant, {
|
|
10867
|
+
started_at: now,
|
|
10868
|
+
read: read
|
|
10869
|
+
});
|
|
10870
|
+
return read;
|
|
10871
|
+
}
|
|
10872
|
+
function $48a2cfb8445bcd57$export$6cde5c31239dec47() {
|
|
10873
|
+
$48a2cfb8445bcd57$var$in_flight.clear();
|
|
10874
|
+
}
|
|
10875
|
+
|
|
10876
|
+
/**
|
|
10877
|
+
* The shopper's recently viewed products, kept in the browser for the native V4 API's history-based recommendations.
|
|
10878
|
+
*
|
|
10879
|
+
* v3 kept this history on the server, per session. V4 content requests carry no session, so a surface that reads
|
|
10880
|
+
* history gets it in the request (`recent_views`), and the SDK keeps the list. It holds product ids and view times
|
|
10881
|
+
* only (no session, user or page data), bounded in size and age, in localStorage per merchant; when localStorage
|
|
10882
|
+
* can't be used (private mode, blocked, full) it lives in memory for the page load.
|
|
10883
|
+
*
|
|
10884
|
+
* A view is recorded when a native product-anchored recommendation request resolves its anchor, as v3's facade records
|
|
10885
|
+
* a resolved anchor as a view; the product being viewed is in the list from the next request on.
|
|
10886
|
+
*/ /** recs-wasm reads the newest 20 views (V4 `recent_views` docs), so more would never be read. */
|
|
10887
|
+
const $b6d3e4dd179febae$export$3d684435158adda6 = 20;
|
|
10888
|
+
const $b6d3e4dd179febae$export$5eb0a366a50fa99e = 2592000000;
|
|
10889
|
+
/** V4's longest product id (`ProductRef`); a longer one is never a product it knows. */
|
|
10890
|
+
const $b6d3e4dd179febae$var$MAX_ID_LENGTH = 500;
|
|
10891
|
+
const $b6d3e4dd179febae$var$storage_key = merchant => `depict_v4_recent_views_${merchant}`;
|
|
10892
|
+
/** The list per merchant as last written, which reads use when localStorage can't hold it. */
|
|
10893
|
+
const $b6d3e4dd179febae$var$in_memory = new Map();
|
|
10894
|
+
/** Merchants whose last write to localStorage failed, so localStorage holds an older list than memory. */
|
|
10895
|
+
const $b6d3e4dd179febae$var$unstored = new Set();
|
|
10896
|
+
/** `views` as a valid list: well-formed entries, newest first, one per id, not older than the age bound or too many. */
|
|
10897
|
+
function $b6d3e4dd179febae$var$bounded(views, now) {
|
|
10898
|
+
if (!Array.isArray(views)) return [];
|
|
10899
|
+
const seen = new Set();
|
|
10900
|
+
const kept = [];
|
|
10901
|
+
for (const item of views) {
|
|
10902
|
+
if (!item || typeof item !== "object") continue;
|
|
10903
|
+
const {
|
|
10904
|
+
id: id,
|
|
10905
|
+
at: at
|
|
10906
|
+
} = item;
|
|
10907
|
+
if (typeof id !== "string" || !id || id.length > $b6d3e4dd179febae$var$MAX_ID_LENGTH || typeof at !== "string") continue;
|
|
10908
|
+
const time = Date.parse(at);
|
|
10909
|
+
if (Number.isNaN(time) || now - time > $b6d3e4dd179febae$export$5eb0a366a50fa99e) continue;
|
|
10910
|
+
kept.push({
|
|
10911
|
+
view: {
|
|
10912
|
+
id: id,
|
|
10913
|
+
at: new Date(time).toISOString()
|
|
10914
|
+
},
|
|
10915
|
+
time: time
|
|
10916
|
+
});
|
|
10917
|
+
}
|
|
10918
|
+
kept.sort((a, b) => b.time - a.time);
|
|
10919
|
+
const newest = [];
|
|
10920
|
+
for (const {
|
|
10921
|
+
view: view
|
|
10922
|
+
} of kept) {
|
|
10923
|
+
if (seen.has(view.id)) continue;
|
|
10924
|
+
seen.add(view.id);
|
|
10925
|
+
newest.push(view);
|
|
10926
|
+
if (newest.length === $b6d3e4dd179febae$export$3d684435158adda6) break;
|
|
10927
|
+
}
|
|
10928
|
+
return newest;
|
|
10929
|
+
}
|
|
10930
|
+
function $b6d3e4dd179febae$var$read_stored(merchant) {
|
|
10931
|
+
if ($b6d3e4dd179febae$var$unstored.has(merchant)) return $b6d3e4dd179febae$var$in_memory.get(merchant);
|
|
10932
|
+
try {
|
|
10933
|
+
const stored = localStorage.getItem($b6d3e4dd179febae$var$storage_key(merchant));
|
|
10934
|
+
return stored === null ? [] : JSON.parse(stored);
|
|
10935
|
+
} catch {
|
|
10936
|
+
return $b6d3e4dd179febae$var$in_memory.get(merchant) ?? [];
|
|
10937
|
+
}
|
|
10938
|
+
}
|
|
10939
|
+
function $b6d3e4dd179febae$export$2d7138f47b625a04(merchant, now = Date.now()) {
|
|
10940
|
+
return $b6d3e4dd179febae$var$bounded($b6d3e4dd179febae$var$read_stored(merchant), now);
|
|
10941
|
+
}
|
|
10942
|
+
function $b6d3e4dd179febae$export$6379943de8f8af08(merchant, product_id, now = Date.now()) {
|
|
10943
|
+
const views = $b6d3e4dd179febae$var$bounded([{
|
|
10944
|
+
id: product_id,
|
|
10945
|
+
at: new Date(now).toISOString()
|
|
10946
|
+
}, ...$b6d3e4dd179febae$export$2d7138f47b625a04(merchant, now)], now);
|
|
10947
|
+
$b6d3e4dd179febae$var$in_memory.set(merchant, views);
|
|
10948
|
+
try {
|
|
10949
|
+
localStorage.setItem($b6d3e4dd179febae$var$storage_key(merchant), JSON.stringify(views));
|
|
10950
|
+
$b6d3e4dd179febae$var$unstored.delete(merchant);
|
|
10951
|
+
} catch {
|
|
10952
|
+
// localStorage unavailable or full: the in-memory list serves this page load.
|
|
10953
|
+
$b6d3e4dd179febae$var$unstored.add(merchant);
|
|
10954
|
+
}
|
|
10955
|
+
}
|
|
10956
|
+
|
|
10957
|
+
/** V4's largest `limit`, and the most ids `cart` and `exclude` take. */
|
|
10958
|
+
const $c82154cf2888f2b2$export$f112abad09998fa8 = 100;
|
|
10959
|
+
const $c82154cf2888f2b2$var$MAX_IDS = 100;
|
|
10960
|
+
/** The most products V4's `recent_views` takes. */
|
|
10961
|
+
const $c82154cf2888f2b2$var$MAX_VIEWS = 50;
|
|
10962
|
+
/** What a v3 recommendations call names, as fetchDepictRecommendations takes it. */
|
|
10963
|
+
const $c82154cf2888f2b2$var$distinct = ids => [...new Set(ids.filter(id => typeof id === "string" && id.length > 0))];
|
|
10964
|
+
function $c82154cf2888f2b2$export$17493dc1a89b34e6(call, inputs, recent_views) {
|
|
10965
|
+
const reads = input => inputs ? inputs.includes(input) : input === "anchor";
|
|
10966
|
+
const product_ids = $c82154cf2888f2b2$var$distinct(call.productIds ?? []);
|
|
10967
|
+
const request = {
|
|
10968
|
+
market: call.market,
|
|
10969
|
+
...(call.locale ? {
|
|
10970
|
+
locale: call.locale
|
|
10971
|
+
} : {}),
|
|
10972
|
+
type: call.type
|
|
10973
|
+
};
|
|
10974
|
+
if (reads("anchor")) {
|
|
10975
|
+
if (call.categoryId) request.anchor = {
|
|
10976
|
+
type: "category",
|
|
10977
|
+
id: call.categoryId
|
|
10978
|
+
};else if (call.productId) request.anchor = {
|
|
10979
|
+
type: "product",
|
|
10980
|
+
id: call.productId
|
|
10981
|
+
};else if (product_ids.length) {
|
|
10982
|
+
const [first, ...rest] = product_ids;
|
|
10983
|
+
request.anchor = {
|
|
10984
|
+
type: "product",
|
|
10985
|
+
id: first
|
|
10986
|
+
};
|
|
10987
|
+
if (rest.length) request.exclude = rest.slice(0, $c82154cf2888f2b2$var$MAX_IDS);
|
|
10988
|
+
}
|
|
10989
|
+
}
|
|
10990
|
+
if (reads("cart") && product_ids.length) request.cart = product_ids.slice(0, $c82154cf2888f2b2$var$MAX_IDS);
|
|
10991
|
+
if (reads("recent_views") && recent_views.length) request.recent_views = recent_views.slice(0, $c82154cf2888f2b2$var$MAX_VIEWS);
|
|
10992
|
+
if (call.limit) request.limit = Math.min(Math.max(1, Math.floor(call.limit)), $c82154cf2888f2b2$export$f112abad09998fa8);
|
|
10993
|
+
request.include = ["attributes"];
|
|
10994
|
+
const anchor_only = inputs?.length === 1 && inputs[0] === "anchor";
|
|
10995
|
+
if (anchor_only && !request.anchor) return undefined;
|
|
10996
|
+
return request;
|
|
10997
|
+
}
|
|
10998
|
+
/** `encodeURIComponent`, as V4's own encoder writes a value (`+` would mean a space). */
|
|
10999
|
+
const $c82154cf2888f2b2$var$encode = value => encodeURIComponent(value);
|
|
11000
|
+
function $c82154cf2888f2b2$export$fc756666ac777d0(request) {
|
|
11001
|
+
const pairs = [];
|
|
11002
|
+
const add = (key, value) => value !== undefined && pairs.push(`${key}=${value}`);
|
|
11003
|
+
const list = values => values?.map($c82154cf2888f2b2$var$encode).join(",");
|
|
11004
|
+
add("market", $c82154cf2888f2b2$var$encode(request.market));
|
|
11005
|
+
add("locale", request.locale === undefined ? undefined : $c82154cf2888f2b2$var$encode(request.locale));
|
|
11006
|
+
add("type", $c82154cf2888f2b2$var$encode(request.type));
|
|
11007
|
+
add("anchor", request.anchor && `${$c82154cf2888f2b2$var$encode(request.anchor.type)}:${$c82154cf2888f2b2$var$encode(request.anchor.id)}`);
|
|
11008
|
+
add("cart", list(request.cart));
|
|
11009
|
+
add("recent_views", request.recent_views?.map(view => `${$c82154cf2888f2b2$var$encode(view.id)}@${$c82154cf2888f2b2$var$encode(view.at)}`).join(","));
|
|
11010
|
+
add("query", request.query === undefined ? undefined : $c82154cf2888f2b2$var$encode(request.query));
|
|
11011
|
+
add("exclude", list(request.exclude));
|
|
11012
|
+
add("limit", request.limit === undefined ? undefined : String(request.limit));
|
|
11013
|
+
add("include", list(request.include));
|
|
11014
|
+
return pairs.join("&");
|
|
11015
|
+
}
|
|
11016
|
+
const $c82154cf2888f2b2$export$89962366050887f7 = product => product.variants[product.selected]?.product_id ?? product.group_id;
|
|
11017
|
+
function $c82154cf2888f2b2$export$afe6aeae61a7aa58(hits, scope, type) {
|
|
11018
|
+
const anchors = hits.slice(0, type === "search" ? 10 : 1);
|
|
11019
|
+
return anchors.map((anchor, at) => {
|
|
11020
|
+
const exclude = hits.filter((_, index) => index !== at).map($c82154cf2888f2b2$export$89962366050887f7);
|
|
11021
|
+
return {
|
|
11022
|
+
market: scope.market,
|
|
11023
|
+
...(scope.locale ? {
|
|
11024
|
+
locale: scope.locale
|
|
11025
|
+
} : {}),
|
|
11026
|
+
type: type,
|
|
11027
|
+
anchor: {
|
|
11028
|
+
type: "product",
|
|
11029
|
+
id: $c82154cf2888f2b2$export$89962366050887f7(anchor)
|
|
11030
|
+
},
|
|
11031
|
+
...(exclude.length ? {
|
|
11032
|
+
exclude: exclude.slice(0, $c82154cf2888f2b2$var$MAX_IDS)
|
|
11033
|
+
} : {}),
|
|
11034
|
+
include: ["attributes"]
|
|
11035
|
+
};
|
|
11036
|
+
});
|
|
11037
|
+
}
|
|
11038
|
+
function $c82154cf2888f2b2$export$9af50be6508dcd00(lists, limit) {
|
|
11039
|
+
const merged = [];
|
|
11040
|
+
const taken = new Set();
|
|
11041
|
+
const depth = Math.max(0, ...lists.map(list => list.length));
|
|
11042
|
+
for (let index = 0; index < depth; index++) for (const list of lists) {
|
|
11043
|
+
const product = list[index];
|
|
11044
|
+
if (product === undefined || taken.has(product.group_id)) continue;
|
|
11045
|
+
taken.add(product.group_id);
|
|
11046
|
+
merged.push(product);
|
|
11047
|
+
if (merged.length >= limit) return merged;
|
|
11048
|
+
}
|
|
11049
|
+
return merged;
|
|
11050
|
+
}
|
|
11051
|
+
|
|
11052
|
+
/** 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 `#`. */
|
|
11053
|
+
const $6b1ba052a9f2341e$var$BARE_HEX = /^(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
11054
|
+
function $6b1ba052a9f2341e$export$7abfb7bc025aaea8(product, tracking_key) {
|
|
11055
|
+
const product_attributes = product.attributes ?? {};
|
|
11056
|
+
return {
|
|
11057
|
+
variant_index: product.selected,
|
|
11058
|
+
variant_displays: product.variants.map(variant => {
|
|
11059
|
+
// A variant carries its own main image only when it differs from the card's; it has no gallery of its own.
|
|
11060
|
+
const image_urls = variant.image ? [variant.image] : [...product.images];
|
|
11061
|
+
const price = variant.price ?? product.price;
|
|
11062
|
+
const color = variant.color ?? product.color;
|
|
11063
|
+
const display = {
|
|
11064
|
+
...product_attributes,
|
|
11065
|
+
// The merchant's variant attributes under their own keys (`add_to_cart_id`, `item_group_id`, …); the card
|
|
11066
|
+
// fields below win over a same-named attribute, as on v3.
|
|
11067
|
+
...variant.attributes,
|
|
11068
|
+
product_id: variant.product_id,
|
|
11069
|
+
main_product_id: variant.attributes?.main_product_id ?? variant.group_id ?? product.group_id,
|
|
11070
|
+
title: variant.title ?? product.title,
|
|
11071
|
+
image_urls: image_urls,
|
|
11072
|
+
sale_price: price.amount,
|
|
11073
|
+
original_price: price.compare_at ?? price.amount,
|
|
11074
|
+
...(price.lowest !== undefined ? {
|
|
11075
|
+
lowest_price: price.lowest
|
|
11076
|
+
} : {}),
|
|
11077
|
+
in_stock: variant.in_stock,
|
|
11078
|
+
...(color ? {
|
|
11079
|
+
color_name: color.name
|
|
11080
|
+
} : {}),
|
|
11081
|
+
uri: variant.slug ?? product.slug
|
|
11082
|
+
};
|
|
11083
|
+
const hex = display.color_hex;
|
|
11084
|
+
if (typeof hex === "string" && $6b1ba052a9f2341e$var$BARE_HEX.test(hex)) display.color_hex = `#${hex}`;
|
|
11085
|
+
return display;
|
|
11086
|
+
}),
|
|
11087
|
+
[tracking_key]: product.tracking_id
|
|
11088
|
+
};
|
|
11089
|
+
}
|
|
11090
|
+
|
|
11091
|
+
/**
|
|
11092
|
+
* Filters, facets and sorts between depict-ui's v3 shapes and the native V4 API.
|
|
11093
|
+
*
|
|
11094
|
+
* This is a client-side port of realtime's v3 facade (`v4/worker/src/facade/v3Browse.ts`: `v3FilterBy`, `toV3Filters`,
|
|
11095
|
+
* `toV3Sorts`, `toV3ContentLinks`), which owns the same translation on the server for v3 requests. Keep the two in
|
|
11096
|
+
* step: a difference shows up as a filter that works on v3 and not on native, or the other way round.
|
|
11097
|
+
*
|
|
11098
|
+
* The facade resolves a v3 filter field against the merchant's search config (titles, localized titles). The browser
|
|
11099
|
+
* has no config, so it resolves against the facets V4 served instead (see {@link FacetIndex}).
|
|
11100
|
+
*/ /** 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. */
|
|
11101
|
+
class $debf9654214236f5$export$f5ea4d073ddb4bdb extends Error {}
|
|
11102
|
+
/** v3's names for V4's built-in fields, both ways. */
|
|
11103
|
+
const $debf9654214236f5$var$V3_FIELD = {
|
|
11104
|
+
price: "sale_price"
|
|
11105
|
+
};
|
|
11106
|
+
const $debf9654214236f5$var$V4_FIELD = {
|
|
11107
|
+
sale_price: "price"
|
|
11108
|
+
};
|
|
11109
|
+
const $debf9654214236f5$var$V3_SORT = {
|
|
11110
|
+
relevance: "_relevance",
|
|
11111
|
+
price: "sale_price",
|
|
11112
|
+
newest: "product_timestamp"
|
|
11113
|
+
};
|
|
11114
|
+
const $debf9654214236f5$var$V4_SORT = Object.fromEntries(Object.entries($debf9654214236f5$var$V3_SORT).map(([v4, v3]) => [v3, v4]));
|
|
11115
|
+
/** V4's public filter field syntax (`FilterField` in the contract). */
|
|
11116
|
+
const $debf9654214236f5$var$PUBLIC_FIELD = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
|
|
11117
|
+
/**
|
|
11118
|
+
* Fields that are never a lowercased group title: v3's toggles carry no group title, and `sale_price` is v3's own
|
|
11119
|
+
* name for V4's price. A reserved V4 field (`price`, `brand`, `category`) is not among them: iciw's category tree is
|
|
11120
|
+
* titled "Category", so `category` from a link may name `product_scollection_category_hierarchy`.
|
|
11121
|
+
*/
|
|
11122
|
+
const $debf9654214236f5$var$NEVER_A_TITLE = new Set(["in_stock", "on_sale", "sale_price"]);
|
|
11123
|
+
/** fi's enriched colour fields: their values are names, never a `<name>;#<hex>` composite. */
|
|
11124
|
+
const $debf9654214236f5$var$FI_COLOUR_FIELDS = new Set(["colors", "color_details"]);
|
|
11125
|
+
/** The colour template's field, which indexes the composite itself. */
|
|
11126
|
+
const $debf9654214236f5$var$V3_TEMPLATE_COLOUR = "color_with_hex_list";
|
|
11127
|
+
/** Legacy's colour pill composite suffix (`Green;#9ea386`). */
|
|
11128
|
+
const $debf9654214236f5$var$HEX_SUFFIX = /;#[0-9a-fA-F]{3,8}\s*$/;
|
|
11129
|
+
const $debf9654214236f5$var$NUMERIC = /^-?\d+(\.\d+)?$/;
|
|
11130
|
+
/** realtime's separator between the levels of a hierarchical facet value (`Shop # Woman`). */
|
|
11131
|
+
const $debf9654214236f5$var$HIERARCHY_SEPARATOR = " # ";
|
|
11132
|
+
/** The features realtime's category tree is built on. */
|
|
11133
|
+
const $debf9654214236f5$var$CATEGORY_TREE_FIELDS = new Set(["product_category_hierarchy", "product_scollection_category_hierarchy"]);
|
|
11134
|
+
/** V4's public name for the discount template's field (realtime `v4/worker/src/search/fields.ts`). */
|
|
11135
|
+
const $debf9654214236f5$var$DISCOUNT_FIELD = "discount";
|
|
11136
|
+
/** The fields of V4's toggle facets (the `on_sale` and `in_stock` templates). */
|
|
11137
|
+
const $debf9654214236f5$var$V3_TOGGLES = new Set(["on_sale", "in_stock"]);
|
|
11138
|
+
class $debf9654214236f5$export$8d488bcc71d07ffb {
|
|
11139
|
+
#by_key = new Map();
|
|
11140
|
+
/** Adds the facets of one browse response. */
|
|
11141
|
+
learn_(facets) {
|
|
11142
|
+
for (const facet of facets ?? []) {
|
|
11143
|
+
const info = {
|
|
11144
|
+
field_: facet.field,
|
|
11145
|
+
checkbox_: facet.type === "checkbox" && !$debf9654214236f5$var$is_toggle(facet),
|
|
11146
|
+
colour_: $debf9654214236f5$var$FI_COLOUR_FIELDS.has(facet.field) || facet.type === "swatch" && facet.field !== $debf9654214236f5$var$V3_TEMPLATE_COLOUR
|
|
11147
|
+
};
|
|
11148
|
+
this.#by_key.set(facet.field, info);
|
|
11149
|
+
const v3_field = $debf9654214236f5$var$V3_FIELD[facet.field];
|
|
11150
|
+
if (v3_field) this.#by_key.set(v3_field, info);
|
|
11151
|
+
if (facet.title) this.#by_key.set(facet.title.toLowerCase(), info);
|
|
11152
|
+
}
|
|
11153
|
+
}
|
|
11154
|
+
/** The field a v3 filter field names, when a served facet has it as its field or its title. */
|
|
11155
|
+
get_(field) {
|
|
11156
|
+
const bare = field.replace(/#$/, "");
|
|
11157
|
+
const direct = this.#by_key.get(bare);
|
|
11158
|
+
if (direct) return direct;
|
|
11159
|
+
let wanted;
|
|
11160
|
+
try {
|
|
11161
|
+
wanted = decodeURIComponent(bare).toLowerCase();
|
|
11162
|
+
} catch {
|
|
11163
|
+
wanted = bare.toLowerCase();
|
|
11164
|
+
}
|
|
11165
|
+
return this.#by_key.get(wanted);
|
|
11166
|
+
}
|
|
11167
|
+
}
|
|
11168
|
+
function $debf9654214236f5$export$3b6ba2422a5e0aa0(field, index) {
|
|
11169
|
+
return !!index.get_(field) || $debf9654214236f5$var$NEVER_A_TITLE.has(field.replace(/#$/, ""));
|
|
11170
|
+
}
|
|
11171
|
+
function $debf9654214236f5$var$is_empty(data) {
|
|
11172
|
+
return data === undefined || data === null || data === "" || Array.isArray(data) && !data.length;
|
|
11173
|
+
}
|
|
11174
|
+
function $debf9654214236f5$var$literal(value, field) {
|
|
11175
|
+
const text = String(value);
|
|
11176
|
+
if (text.includes("`")) throw new $debf9654214236f5$export$f5ea4d073ddb4bdb(`filters: a value of ${field} contains a backtick`);
|
|
11177
|
+
// A boolean-looking string is written bare, as realtime's filter writer does for every field.
|
|
11178
|
+
if (/^(true|True|false|False)$/.test(text)) return text.toLowerCase();
|
|
11179
|
+
if (field === "price" && $debf9654214236f5$var$NUMERIC.test(text)) return text;
|
|
11180
|
+
return typeof value === "string" ? `\`${text}\`` : text;
|
|
11181
|
+
}
|
|
11182
|
+
function $debf9654214236f5$var$lax_number(value) {
|
|
11183
|
+
if (typeof value === "number") return value;
|
|
11184
|
+
if (typeof value !== "string" || value.trim() === "") return undefined;
|
|
11185
|
+
const number = Number(value);
|
|
11186
|
+
return Number.isFinite(number) ? number : undefined;
|
|
11187
|
+
}
|
|
11188
|
+
function $debf9654214236f5$export$c17bb5d2ead3e8f3(filter, index) {
|
|
11189
|
+
if ($debf9654214236f5$var$is_empty(filter.data)) return undefined;
|
|
11190
|
+
const info = index.get_(filter.field);
|
|
11191
|
+
const bare = filter.field.replace(/#$/, "");
|
|
11192
|
+
const field = info?.field_ ?? $debf9654214236f5$var$V4_FIELD[bare] ?? bare;
|
|
11193
|
+
if (!$debf9654214236f5$var$PUBLIC_FIELD.test(field)) throw new $debf9654214236f5$export$f5ea4d073ddb4bdb(`Invalid filter field \`${filter.field}\``);
|
|
11194
|
+
const clause = text => ({
|
|
11195
|
+
field_: field,
|
|
11196
|
+
clause_: text
|
|
11197
|
+
});
|
|
11198
|
+
const colour = $debf9654214236f5$var$FI_COLOUR_FIELDS.has(field) || !!info?.colour_;
|
|
11199
|
+
const data = filter.data;
|
|
11200
|
+
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));
|
|
11201
|
+
const list = () => `[${values.map(value => $debf9654214236f5$var$literal(value, field)).join(",")}]`;
|
|
11202
|
+
// V4's discount filter (the discount template's "X% or more" radio) is a threshold, so `in` or `eq` on it means
|
|
11203
|
+
// "this discount or more", as on the facade since realtime#2181: a link with no operator decodes as `in`, and a
|
|
11204
|
+
// shop may send `in ["0.2"]` itself. Several values take the largest, as `geq` does.
|
|
11205
|
+
const op = (filter.op === "in" || filter.op === "eq") && field === $debf9654214236f5$var$DISCOUNT_FIELD ? "geq" : filter.op;
|
|
11206
|
+
// A configured checkbox keeps in/nin; every other op on it becomes in.
|
|
11207
|
+
if (op !== "in" && op !== "nin" && info?.checkbox_) return clause(`${field}:=${list()}`);
|
|
11208
|
+
const one = () => {
|
|
11209
|
+
if (values.length !== 1) throw new $debf9654214236f5$export$f5ea4d073ddb4bdb(`filters: ${op} takes one value`);
|
|
11210
|
+
return $debf9654214236f5$var$literal(values[0], field);
|
|
11211
|
+
};
|
|
11212
|
+
// A comparison takes a number, also one sent as a string; of several numbers `geq` takes the largest.
|
|
11213
|
+
const bound = () => {
|
|
11214
|
+
const numbers = values.map(value => typeof value === "number" || typeof value === "string" && $debf9654214236f5$var$NUMERIC.test(value) ? Number(value) : undefined);
|
|
11215
|
+
if (numbers.length === 0 || numbers.some(number => number === undefined)) return one();
|
|
11216
|
+
if (numbers.length > 1 && op !== "geq") return one();
|
|
11217
|
+
return String(Math.max(...numbers));
|
|
11218
|
+
};
|
|
11219
|
+
switch (op) {
|
|
11220
|
+
case "eq":
|
|
11221
|
+
return clause(`${field}:=${one()}`);
|
|
11222
|
+
case "neq":
|
|
11223
|
+
return clause(`${field}:!=${one()}`);
|
|
11224
|
+
case "in":
|
|
11225
|
+
return clause(`${field}:=${list()}`);
|
|
11226
|
+
case "nin":
|
|
11227
|
+
return clause(`${field}:!=${list()}`);
|
|
11228
|
+
case "leq":
|
|
11229
|
+
return clause(`${field}:<=${bound()}`);
|
|
11230
|
+
case "geq":
|
|
11231
|
+
return clause(`${field}:>=${bound()}`);
|
|
11232
|
+
case "inrange":
|
|
11233
|
+
{
|
|
11234
|
+
const [min, max] = values.map($debf9654214236f5$var$lax_number);
|
|
11235
|
+
if (min === undefined || max === undefined || values.length !== 2) throw new $debf9654214236f5$export$f5ea4d073ddb4bdb("filters: inrange takes [min, max]");
|
|
11236
|
+
return clause(`${field}:[${min}..${max}]`);
|
|
11237
|
+
}
|
|
11238
|
+
default:
|
|
11239
|
+
throw new $debf9654214236f5$export$f5ea4d073ddb4bdb(`filters: unknown op ${op}`);
|
|
11240
|
+
}
|
|
11241
|
+
}
|
|
11242
|
+
function $debf9654214236f5$export$407f30f25da13cc7(filters, index) {
|
|
11243
|
+
const clauses = filters.flatMap(filter => $debf9654214236f5$export$c17bb5d2ead3e8f3(filter, index)?.clause_ ?? []);
|
|
11244
|
+
return clauses.length ? clauses.join(" && ") : undefined;
|
|
11245
|
+
}
|
|
11246
|
+
function $debf9654214236f5$export$c38de645260a41ed(error, clauses) {
|
|
11247
|
+
if (!error || !clauses.length) return [];
|
|
11248
|
+
const named = (error.message ?? "").match(/"([A-Za-z0-9_.-]+)/)?.[1];
|
|
11249
|
+
if (error.code === "unknown_filter_field") {
|
|
11250
|
+
if (error.allowed) {
|
|
11251
|
+
const allowed = new Set(error.allowed);
|
|
11252
|
+
return clauses.filter(clause => !allowed.has(clause.field_));
|
|
11253
|
+
}
|
|
11254
|
+
return clauses.filter(clause => clause.field_ === named);
|
|
11255
|
+
}
|
|
11256
|
+
if (error.code === "invalid_filter") {
|
|
11257
|
+
const on_field = clauses.filter(clause => clause.field_ === named);
|
|
11258
|
+
return on_field.length ? on_field : [...clauses];
|
|
11259
|
+
}
|
|
11260
|
+
return [];
|
|
11261
|
+
}
|
|
11262
|
+
function $debf9654214236f5$export$78eb8e636d89ff30(sort) {
|
|
11263
|
+
if (!sort || sort.field === "_relevance") return undefined;
|
|
11264
|
+
return {
|
|
11265
|
+
field: $debf9654214236f5$var$V4_SORT[sort.field] ?? sort.field,
|
|
11266
|
+
order: sort.order
|
|
11267
|
+
};
|
|
11268
|
+
}
|
|
11269
|
+
function $debf9654214236f5$export$cd08b64be5110ce2(sorts) {
|
|
11270
|
+
return sorts.map(sort => ({
|
|
11271
|
+
field: $debf9654214236f5$var$V3_SORT[sort.field] ?? sort.field,
|
|
11272
|
+
order: sort.order,
|
|
11273
|
+
meta: {
|
|
11274
|
+
title: sort.title,
|
|
11275
|
+
values: [sort.order],
|
|
11276
|
+
names: [sort.title]
|
|
11277
|
+
}
|
|
11278
|
+
}));
|
|
11279
|
+
}
|
|
11280
|
+
const $debf9654214236f5$var$V3_VALUES_TYPE = {
|
|
11281
|
+
checkbox: "checkbox",
|
|
11282
|
+
radio: "radio",
|
|
11283
|
+
swatch: "checkbox-color",
|
|
11284
|
+
hierarchy: "checkbox-hierarchical",
|
|
11285
|
+
grid: "checkbox-grid"
|
|
11286
|
+
};
|
|
11287
|
+
/** A toggle is a template facet's one `true` value. */
|
|
11288
|
+
function $debf9654214236f5$var$is_toggle(facet) {
|
|
11289
|
+
return $debf9654214236f5$var$V3_TOGGLES.has(facet.field) && facet.type === "checkbox" && facet.values.length === 1 && facet.values[0].value === "true";
|
|
11290
|
+
}
|
|
11291
|
+
function $debf9654214236f5$var$category_path(value) {
|
|
11292
|
+
return value.split("#").map(level => level.trim()).filter(Boolean);
|
|
11293
|
+
}
|
|
11294
|
+
function $debf9654214236f5$export$da9af372695714ef(facets, currency) {
|
|
11295
|
+
return facets.filter(facet => facet.type === "range" || facet.values.length > 0).map(facet => {
|
|
11296
|
+
const field = $debf9654214236f5$var$V3_FIELD[facet.field] ?? facet.field;
|
|
11297
|
+
if (facet.type === "range") return {
|
|
11298
|
+
field: field,
|
|
11299
|
+
op: "inrange",
|
|
11300
|
+
data: [facet.min, facet.max],
|
|
11301
|
+
meta: {
|
|
11302
|
+
group_title: facet.title,
|
|
11303
|
+
type: "range",
|
|
11304
|
+
min: facet.min,
|
|
11305
|
+
max: facet.max,
|
|
11306
|
+
...(facet.field === "price" && currency ? {
|
|
11307
|
+
currency: currency
|
|
11308
|
+
} : {})
|
|
11309
|
+
},
|
|
11310
|
+
id: `${field}1`
|
|
11311
|
+
};
|
|
11312
|
+
const hierarchy = facet.type === "hierarchy";
|
|
11313
|
+
const path = value => $debf9654214236f5$var$CATEGORY_TREE_FIELDS.has(facet.field) ? $debf9654214236f5$var$category_path(value) : value.split($debf9654214236f5$var$HIERARCHY_SEPARATOR);
|
|
11314
|
+
if ($debf9654214236f5$var$is_toggle(facet)) return {
|
|
11315
|
+
field: field,
|
|
11316
|
+
op: "eq",
|
|
11317
|
+
meta: {
|
|
11318
|
+
type: "checkbox",
|
|
11319
|
+
values: facet.values.map(value => value.value),
|
|
11320
|
+
counts: facet.values.map(value => value.count),
|
|
11321
|
+
names: facet.values.map(value => value.label)
|
|
11322
|
+
},
|
|
11323
|
+
id: `${field}1`
|
|
11324
|
+
};
|
|
11325
|
+
// Two spellings of one category path are one row in the tree.
|
|
11326
|
+
const seen = new Set();
|
|
11327
|
+
const values = $debf9654214236f5$var$CATEGORY_TREE_FIELDS.has(facet.field) ? facet.values.filter(({
|
|
11328
|
+
value: value
|
|
11329
|
+
}) => {
|
|
11330
|
+
const levels = path(value);
|
|
11331
|
+
const key = JSON.stringify(levels);
|
|
11332
|
+
if (levels.length === 0 || seen.has(key)) return false;
|
|
11333
|
+
seen.add(key);
|
|
11334
|
+
return true;
|
|
11335
|
+
}) : facet.values;
|
|
11336
|
+
return {
|
|
11337
|
+
field: field,
|
|
11338
|
+
op: facet.field === "discount" ? "geq" : "in",
|
|
11339
|
+
meta: {
|
|
11340
|
+
group_title: facet.title,
|
|
11341
|
+
type: $debf9654214236f5$var$V3_VALUES_TYPE[facet.type] ?? "checkbox",
|
|
11342
|
+
values: values.map(value => hierarchy ? path(value.value) : value.value),
|
|
11343
|
+
counts: values.map(value => value.count),
|
|
11344
|
+
names: values.map(value => hierarchy ? path(value.value).slice(-1)[0] : value.label),
|
|
11345
|
+
// The colour template sends swatches only with one to paint; a colour filter always sends them.
|
|
11346
|
+
...(facet.type === "swatch" && (facet.field !== $debf9654214236f5$var$V3_TEMPLATE_COLOUR || facet.values.some(value => value.swatch)) ? {
|
|
11347
|
+
swatches: facet.values.map(value => value.swatch ?? null)
|
|
11348
|
+
} : {})
|
|
11349
|
+
},
|
|
11350
|
+
id: `${field}1`
|
|
11351
|
+
};
|
|
11352
|
+
});
|
|
11353
|
+
}
|
|
11354
|
+
function $debf9654214236f5$export$b84a41a5163c4fce(content) {
|
|
11355
|
+
return content.map(hit => ({
|
|
11356
|
+
type: "content_link",
|
|
11357
|
+
title: hit.title,
|
|
11358
|
+
...(hit.description !== undefined ? {
|
|
11359
|
+
description: hit.description
|
|
11360
|
+
} : {}),
|
|
11361
|
+
...(hit.image_url !== undefined ? {
|
|
11362
|
+
image_url: hit.image_url
|
|
11363
|
+
} : {}),
|
|
11364
|
+
page_url: hit.url,
|
|
11365
|
+
highlights: hit.highlights ?? []
|
|
11366
|
+
}));
|
|
11367
|
+
}
|
|
11368
|
+
function $4261fabd2fa94c86$export$efb7dd882d411dd4(response, door, offset) {
|
|
11369
|
+
const tracking_key = door === "search" ? "search_result_id" : "product_listing_result_id";
|
|
11370
|
+
return {
|
|
11371
|
+
n_hits: response.total ?? offset + response.products.length,
|
|
11372
|
+
sorts: $debf9654214236f5$export$cd08b64be5110ce2(response.sorts ?? []),
|
|
11373
|
+
filters: $debf9654214236f5$export$da9af372695714ef(response.facets ?? [], response.currency),
|
|
11374
|
+
...(door === "search" ? {
|
|
11375
|
+
search_request_id: response.request_id,
|
|
11376
|
+
content_search_links: $debf9654214236f5$export$b84a41a5163c4fce(response.content ?? []),
|
|
11377
|
+
is_fallback: null
|
|
11378
|
+
} : {
|
|
11379
|
+
product_listing_request_id: response.request_id
|
|
11380
|
+
}),
|
|
11381
|
+
...(response.cursor !== undefined ? {
|
|
11382
|
+
cursor: response.cursor
|
|
11383
|
+
} : {}),
|
|
11384
|
+
displays: response.products.map(product => $6b1ba052a9f2341e$export$7abfb7bc025aaea8(product, tracking_key))
|
|
11385
|
+
};
|
|
11386
|
+
}
|
|
11387
|
+
function $4261fabd2fa94c86$var$listing_ref_to_v3(ref, listing_type, show) {
|
|
11388
|
+
return {
|
|
11389
|
+
listing_id: ref.id,
|
|
11390
|
+
...(ref.external_id !== undefined ? {
|
|
11391
|
+
external_id: ref.external_id
|
|
11392
|
+
} : {}),
|
|
11393
|
+
listing_type: listing_type,
|
|
11394
|
+
...show,
|
|
11395
|
+
image_urls: [],
|
|
11396
|
+
title: ref.title,
|
|
11397
|
+
...(ref.slug !== undefined ? {
|
|
11398
|
+
slug: ref.slug
|
|
11399
|
+
} : {})
|
|
11400
|
+
};
|
|
11401
|
+
}
|
|
11402
|
+
function $4261fabd2fa94c86$export$996f2b1e66d9b5af(listing) {
|
|
11403
|
+
const listing_type = listing.type;
|
|
11404
|
+
const quick_links_are_siblings = listing.quick_links.some(link => link.id === listing.id);
|
|
11405
|
+
const quick_links = listing.quick_links.map(link => $4261fabd2fa94c86$var$listing_ref_to_v3(link, listing_type, {
|
|
11406
|
+
show_in_breadcrumbs: true,
|
|
11407
|
+
show_in_quicklinks: true
|
|
11408
|
+
}));
|
|
11409
|
+
return {
|
|
11410
|
+
listing_id: listing.id,
|
|
11411
|
+
...(listing.external_id !== undefined ? {
|
|
11412
|
+
external_id: listing.external_id
|
|
11413
|
+
} : {}),
|
|
11414
|
+
listing_type: listing_type,
|
|
11415
|
+
show_in_breadcrumbs: listing.show_in_breadcrumbs,
|
|
11416
|
+
show_in_quicklinks: true,
|
|
11417
|
+
image_urls: listing.images,
|
|
11418
|
+
title: listing.title,
|
|
11419
|
+
...(listing.slug !== undefined ? {
|
|
11420
|
+
slug: listing.slug
|
|
11421
|
+
} : {}),
|
|
11422
|
+
ancestors: listing.breadcrumbs.map(ref => $4261fabd2fa94c86$var$listing_ref_to_v3(ref, "category", {
|
|
11423
|
+
show_in_breadcrumbs: true,
|
|
11424
|
+
show_in_quicklinks: true
|
|
11425
|
+
})),
|
|
11426
|
+
siblings: quick_links_are_siblings ? quick_links : [],
|
|
11427
|
+
children: quick_links_are_siblings ? [] : quick_links,
|
|
11428
|
+
content_blocks: listing.content_blocks
|
|
11429
|
+
};
|
|
11430
|
+
}
|
|
11431
|
+
function $4261fabd2fa94c86$export$76d96892da63b395(tree) {
|
|
11432
|
+
const by_id = new Map();
|
|
11433
|
+
const walk = (nodes, chain) => {
|
|
11434
|
+
for (const node of nodes) {
|
|
11435
|
+
if (!by_id.has(node.id)) by_id.set(node.id, chain);
|
|
11436
|
+
walk(node.children, [...chain, $4261fabd2fa94c86$var$listing_ref_to_v3(node, node.type, {
|
|
11437
|
+
show_in_breadcrumbs: true,
|
|
11438
|
+
show_in_quicklinks: true
|
|
11439
|
+
})]);
|
|
11440
|
+
}
|
|
11441
|
+
};
|
|
11442
|
+
walk(tree, []);
|
|
11443
|
+
return listing_id => by_id.get(listing_id);
|
|
11444
|
+
}
|
|
11445
|
+
function $4261fabd2fa94c86$export$2860125b419015f8(response, ancestors_of) {
|
|
11446
|
+
return {
|
|
11447
|
+
suggestions_request_id: response.request_id,
|
|
11448
|
+
suggestions: response.suggestions.map(suggestion => {
|
|
11449
|
+
if (suggestion.type === "query") return {
|
|
11450
|
+
type: "query",
|
|
11451
|
+
query: suggestion.query,
|
|
11452
|
+
suggestions_result_id: ""
|
|
11453
|
+
};
|
|
11454
|
+
const from_tree = ancestors_of?.(suggestion.listing.id);
|
|
11455
|
+
const ancestors = from_tree && $4261fabd2fa94c86$var$same_titles(from_tree, suggestion.path) ? from_tree : [];
|
|
11456
|
+
return {
|
|
11457
|
+
type: "listing",
|
|
11458
|
+
listing_id: suggestion.listing.id,
|
|
11459
|
+
...(suggestion.listing.external_id !== undefined ? {
|
|
11460
|
+
external_id: suggestion.listing.external_id
|
|
11461
|
+
} : {}),
|
|
11462
|
+
listing_type: suggestion.listing.type,
|
|
11463
|
+
show_in_breadcrumbs: true,
|
|
11464
|
+
show_in_quicklinks: true,
|
|
11465
|
+
image_urls: suggestion.listing.images,
|
|
11466
|
+
title: suggestion.listing.title,
|
|
11467
|
+
...(suggestion.listing.slug !== undefined ? {
|
|
11468
|
+
slug: suggestion.listing.slug
|
|
11469
|
+
} : {}),
|
|
11470
|
+
suggestions_result_id: "",
|
|
11471
|
+
ancestors: ancestors
|
|
11472
|
+
};
|
|
11473
|
+
})
|
|
11474
|
+
};
|
|
11475
|
+
}
|
|
11476
|
+
const $4261fabd2fa94c86$var$same_titles = (ancestors, path) => ancestors.length === path.length && ancestors.every((ancestor, index) => ancestor.title === path[index]);
|
|
11477
|
+
/** `encodeURIComponent`, as V4's own encoder writes a value (`+` would mean a space). */
|
|
11478
|
+
const $4261fabd2fa94c86$var$encode = value => encodeURIComponent(value);
|
|
11479
|
+
function $4261fabd2fa94c86$export$7659319cdb555579(request) {
|
|
11480
|
+
const pairs = [`market=${$4261fabd2fa94c86$var$encode(request.market)}`];
|
|
11481
|
+
const add = (key, value) => value !== undefined && pairs.push(`${key}=${value}`);
|
|
11482
|
+
add("locale", request.locale === undefined ? undefined : $4261fabd2fa94c86$var$encode(request.locale));
|
|
11483
|
+
add("query", request.query === undefined ? undefined : $4261fabd2fa94c86$var$encode(request.query));
|
|
11484
|
+
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));
|
|
11485
|
+
add("filter_by", request.filter_by === undefined ? undefined : $4261fabd2fa94c86$var$encode(request.filter_by));
|
|
11486
|
+
if (request.sort) add("sort", `${$4261fabd2fa94c86$var$encode(request.sort.field)}.${request.sort.order}`);
|
|
11487
|
+
add("include", request.include?.join(","));
|
|
11488
|
+
add("cursor", request.cursor);
|
|
11489
|
+
add("limit", request.limit === undefined ? undefined : String(request.limit));
|
|
11490
|
+
return pairs.join("&");
|
|
11491
|
+
}
|
|
11492
|
+
function $4261fabd2fa94c86$export$fec3e4b5adfcea2c(params) {
|
|
11493
|
+
return params.filter(pair => pair[1] !== undefined).map(([key, value]) => `${key}=${$4261fabd2fa94c86$var$encode(value)}`).join("&");
|
|
11494
|
+
}
|
|
11495
|
+
function $4261fabd2fa94c86$export$eb90c08da400512d(locale) {
|
|
11496
|
+
return locale ? locale.replace(/_/g, "-") : undefined;
|
|
11497
|
+
}
|
|
11498
|
+
|
|
11499
|
+
/** realtime's related search page: the hits related recommendations anchor on and never repeat. */
|
|
11500
|
+
const $ce8babba0db8995c$var$RELATED_SEARCH_PAGE = 100;
|
|
11501
|
+
const $ce8babba0db8995c$var$get_recommendations = (merchant, request) => $c25fb5290ccf7b3e$export$88d793e3827f3436($c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, "/recommendations") + "?" + $c82154cf2888f2b2$export$fc756666ac777d0(request));
|
|
11502
|
+
const $ce8babba0db8995c$var$to_displays = products => products.map(product => $6b1ba052a9f2341e$export$7abfb7bc025aaea8(product, "recommendation_id"));
|
|
11503
|
+
async function $ce8babba0db8995c$export$656ee5c46d5d1eda(call) {
|
|
11504
|
+
const {
|
|
11505
|
+
merchant: merchant
|
|
11506
|
+
} = call;
|
|
11507
|
+
const types = await $48a2cfb8445bcd57$export$869eb14d6f85ac51(merchant);
|
|
11508
|
+
const inputs = types?.get(call.type);
|
|
11509
|
+
if (types && !inputs) {
|
|
11510
|
+
$5vyXB$depictaiutilishared.dwarn(`[NativeDepictAPI] V4 serves ${merchant} no recommendation type "${call.type}"; known:`, [...types.keys()]);
|
|
11511
|
+
return [];
|
|
11512
|
+
}
|
|
11513
|
+
const request = $c82154cf2888f2b2$export$17493dc1a89b34e6({
|
|
11514
|
+
...call,
|
|
11515
|
+
locale: $4261fabd2fa94c86$export$eb90c08da400512d(call.locale)
|
|
11516
|
+
}, inputs, inputs?.includes("recent_views") ? $b6d3e4dd179febae$export$2d7138f47b625a04(merchant) : []);
|
|
11517
|
+
if (!request) return [];
|
|
11518
|
+
const response = await $ce8babba0db8995c$var$get_recommendations(merchant, request);
|
|
11519
|
+
if (!response) return [];
|
|
11520
|
+
const anchor = response.used_inputs?.anchor;
|
|
11521
|
+
if (call.productId && anchor?.type === "product") $b6d3e4dd179febae$export$6379943de8f8af08(merchant, anchor.id);
|
|
11522
|
+
return $ce8babba0db8995c$var$to_displays(response.products);
|
|
11523
|
+
}
|
|
11524
|
+
async function $ce8babba0db8995c$export$bd5f8a7d3e47a43d(call) {
|
|
11525
|
+
const {
|
|
11526
|
+
merchant: merchant,
|
|
11527
|
+
market: market
|
|
11528
|
+
} = call;
|
|
11529
|
+
const types = await $48a2cfb8445bcd57$export$869eb14d6f85ac51(merchant);
|
|
11530
|
+
if (!types) return undefined;
|
|
11531
|
+
const type = types.get("search")?.includes("anchor") ? "search" : types.get("similar")?.includes("anchor") ? "similar" : undefined;
|
|
11532
|
+
if (!type) {
|
|
11533
|
+
$5vyXB$depictaiutilishared.dwarn(`[NativeDepictAPI] V4 serves ${merchant} no search or similar recommendations for related products`);
|
|
11534
|
+
return [];
|
|
11535
|
+
}
|
|
11536
|
+
const locale = $4261fabd2fa94c86$export$eb90c08da400512d(call.locale);
|
|
11537
|
+
const query = call.query?.trim() || undefined;
|
|
11538
|
+
const searched = await $c25fb5290ccf7b3e$export$88d793e3827f3436($c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, "/browse") + "?" + $4261fabd2fa94c86$export$7659319cdb555579({
|
|
11539
|
+
market: market,
|
|
11540
|
+
...(locale ? {
|
|
11541
|
+
locale: locale
|
|
11542
|
+
} : {}),
|
|
11543
|
+
...(query ? {
|
|
11544
|
+
query: query
|
|
11545
|
+
} : {}),
|
|
11546
|
+
limit: $ce8babba0db8995c$var$RELATED_SEARCH_PAGE
|
|
11547
|
+
}));
|
|
11548
|
+
if (!searched) return undefined;
|
|
11549
|
+
const asked = $c82154cf2888f2b2$export$afe6aeae61a7aa58(searched.products, {
|
|
11550
|
+
market: market,
|
|
11551
|
+
...(locale ? {
|
|
11552
|
+
locale: locale
|
|
11553
|
+
} : {})
|
|
11554
|
+
}, type);
|
|
11555
|
+
if (!asked.length) return [];
|
|
11556
|
+
const answers = await Promise.all(asked.map(request => $ce8babba0db8995c$var$get_recommendations(merchant, request)));
|
|
11557
|
+
const lists = answers.filter(answer => !!answer).map(answer => answer.products);
|
|
11558
|
+
if (!lists.length) return undefined;
|
|
11559
|
+
const products = lists.length > 1 ? $c82154cf2888f2b2$export$9af50be6508dcd00(lists, Math.max(...lists.map(list => list.length))) : lists[0];
|
|
11560
|
+
return $ce8babba0db8995c$var$to_displays(products);
|
|
11561
|
+
}
|
|
10779
11562
|
async function $bd429c994399dd82$export$58e808b1db15d3bc(options) {
|
|
11563
|
+
if (options.api === "v4") return await $bd429c994399dd82$var$fetch_native(options);
|
|
10780
11564
|
const headers = options.headers;
|
|
10781
11565
|
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
|
|
10782
11566
|
const cleaned_up_options = $5vyXB$depictaiutilishared.snakeCasifyObject(options);
|
|
10783
11567
|
delete cleaned_up_options.headers;
|
|
10784
11568
|
delete cleaned_up_options.product_id;
|
|
11569
|
+
delete cleaned_up_options.api;
|
|
10785
11570
|
cleaned_up_options.session_id ||= $5vyXB$depictaiutilishared.get_session_id();
|
|
10786
11571
|
if (product_id && !cleaned_up_options.product_ids) cleaned_up_options.product_ids = [product_id];
|
|
10787
11572
|
const options_to_send = cleaned_up_options;
|
|
@@ -10803,6 +11588,33 @@ async function $bd429c994399dd82$export$58e808b1db15d3bc(options) {
|
|
|
10803
11588
|
return decoded?.displays || [];
|
|
10804
11589
|
});
|
|
10805
11590
|
}
|
|
11591
|
+
async function $bd429c994399dd82$var$fetch_native(options) {
|
|
11592
|
+
const {
|
|
11593
|
+
merchant: merchant,
|
|
11594
|
+
market: market,
|
|
11595
|
+
locale: locale,
|
|
11596
|
+
type: type,
|
|
11597
|
+
headers: headers,
|
|
11598
|
+
categoryId: categoryId,
|
|
11599
|
+
productIds: productIds
|
|
11600
|
+
} = options;
|
|
11601
|
+
if (headers) $5vyXB$depictaiutilishared.dwarn("fetchDepictRecommendations: headers aren't sent to the native V4 API", headers);
|
|
11602
|
+
try {
|
|
11603
|
+
return await $ce8babba0db8995c$export$656ee5c46d5d1eda({
|
|
11604
|
+
merchant: merchant,
|
|
11605
|
+
market: market,
|
|
11606
|
+
locale: locale,
|
|
11607
|
+
type: type,
|
|
11608
|
+
categoryId: categoryId,
|
|
11609
|
+
productId: options.productId || options.product_id,
|
|
11610
|
+
productIds: productIds,
|
|
11611
|
+
limit: options.limit
|
|
11612
|
+
});
|
|
11613
|
+
} catch (e) {
|
|
11614
|
+
$5vyXB$depictaiutilishared.dlog("fetch_native_recommendations threw", e);
|
|
11615
|
+
return [];
|
|
11616
|
+
}
|
|
11617
|
+
}
|
|
10806
11618
|
var $85b747260aa175c9$var$_tmpl$ = ["<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"><!--$-->', "<!--/--><!--$-->", "<!--/--><!--$-->", "<!--/--></div></div></div>"];
|
|
10807
11619
|
const $85b747260aa175c9$export$824dde41348efed1 = /*@__PURE__*/(() => {
|
|
10808
11620
|
const actual_function = ({
|
|
@@ -11189,7 +12001,10 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11189
12001
|
input_req_: input_req_,
|
|
11190
12002
|
fallback_response_: fallback_response_,
|
|
11191
12003
|
method_ = "POST",
|
|
11192
|
-
currentListingForTransformer_: currentListingForTransformer_
|
|
12004
|
+
currentListingForTransformer_: currentListingForTransformer_,
|
|
12005
|
+
kind_: kind_,
|
|
12006
|
+
id_to_query_for_: id_to_query_for_,
|
|
12007
|
+
id_type_: id_type_
|
|
11193
12008
|
}) {
|
|
11194
12009
|
const cache_obj = this.#get_cache_obj_for_endpoint(endpoint_);
|
|
11195
12010
|
const with_ids = this.#add_ids_to_request(input_req_);
|
|
@@ -11206,19 +12021,19 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11206
12021
|
let resolve_in_progress;
|
|
11207
12022
|
cache_obj.in_progress_[body] = new Promise(r => resolve_in_progress = r);
|
|
11208
12023
|
try {
|
|
11209
|
-
const is_post = method_ === "POST";
|
|
11210
|
-
const url_to_request = is_post ? endpoint_ : $5vyXB$depictaiutilishared.make_url_with_query_params(endpoint_, sorted_request);
|
|
11211
|
-
const api_response = await $5vyXB$depictaiutilishared.fetch_retry($5vyXB$depictaiutilishared.add_version_query_params(url_to_request), {
|
|
11212
|
-
method: method_,
|
|
11213
|
-
...(is_post ? {
|
|
11214
|
-
body: body
|
|
11215
|
-
} : {})
|
|
11216
|
-
});
|
|
11217
12024
|
return_successfully: {
|
|
11218
|
-
if (!api_response || api_response.status !== 200) break return_successfully;
|
|
11219
12025
|
let result;
|
|
11220
12026
|
try {
|
|
11221
|
-
const unmodified_result = await
|
|
12027
|
+
const unmodified_result = await this.request_raw_({
|
|
12028
|
+
kind_: kind_,
|
|
12029
|
+
endpoint_: endpoint_,
|
|
12030
|
+
method_: method_,
|
|
12031
|
+
request_: sorted_request,
|
|
12032
|
+
body_: body,
|
|
12033
|
+
id_to_query_for_: id_to_query_for_,
|
|
12034
|
+
id_type_: id_type_
|
|
12035
|
+
});
|
|
12036
|
+
if (unmodified_result === undefined) break return_successfully;
|
|
11222
12037
|
result = await this.#run_display_transformers_for_rest(input_req_.merchant, input_req_.market, input_req_.locale, unmodified_result, currentListingForTransformer_);
|
|
11223
12038
|
} catch (e) {
|
|
11224
12039
|
$5vyXB$depictaiutilishared.dwarn("displayTransformer or json decoding failed", e);
|
|
@@ -11246,6 +12061,29 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11246
12061
|
delete cache_obj.in_progress_[body];
|
|
11247
12062
|
}
|
|
11248
12063
|
}
|
|
12064
|
+
/**
|
|
12065
|
+
* The network step of every read: sends `call` to the v3 API and returns the decoded JSON, or undefined when the
|
|
12066
|
+
* request failed. NativeDepictAPI overrides this to read the native V4 API instead and map its answers to v3 shapes,
|
|
12067
|
+
* so caching, display transformers and fallbacks stay the same for both.
|
|
12068
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12069
|
+
async request_raw_(call) {
|
|
12070
|
+
const {
|
|
12071
|
+
endpoint_: endpoint_,
|
|
12072
|
+
method_: method_,
|
|
12073
|
+
request_: request_,
|
|
12074
|
+
body_: body_
|
|
12075
|
+
} = call;
|
|
12076
|
+
const is_post = method_ === "POST";
|
|
12077
|
+
const url_to_request = is_post ? endpoint_ : $5vyXB$depictaiutilishared.make_url_with_query_params(endpoint_, request_);
|
|
12078
|
+
const api_response = await $5vyXB$depictaiutilishared.fetch_retry($5vyXB$depictaiutilishared.add_version_query_params(url_to_request), {
|
|
12079
|
+
method: method_,
|
|
12080
|
+
...(is_post ? {
|
|
12081
|
+
body: body_
|
|
12082
|
+
} : {})
|
|
12083
|
+
});
|
|
12084
|
+
if (!api_response || call.kind_ !== "suggest" && api_response.status !== 200) return undefined;
|
|
12085
|
+
return await api_response.json();
|
|
12086
|
+
}
|
|
11249
12087
|
constructor(options) {
|
|
11250
12088
|
const {
|
|
11251
12089
|
get_metadata: get_metadata,
|
|
@@ -11262,11 +12100,13 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11262
12100
|
const request = metaData ? Object.assign(with_ids, {
|
|
11263
12101
|
metadata: JSON.stringify(metaData)
|
|
11264
12102
|
}) : with_ids;
|
|
11265
|
-
const url = $5vyXB$depictaiutilishared.make_url_with_query_params($e1d6c0f3d89d531c$var$search_base_url + "suggestions", request);
|
|
11266
|
-
const results = await $5vyXB$depictaiutilishared.fetch_retry($5vyXB$depictaiutilishared.add_version_query_params(url));
|
|
11267
12103
|
attempt_to_return_api_response: {
|
|
11268
|
-
|
|
11269
|
-
|
|
12104
|
+
const decoded_json = await this.request_raw_({
|
|
12105
|
+
kind_: "suggest",
|
|
12106
|
+
endpoint_: $e1d6c0f3d89d531c$var$search_base_url + "suggestions",
|
|
12107
|
+
method_: "GET",
|
|
12108
|
+
request_: request
|
|
12109
|
+
});
|
|
11270
12110
|
if (!Array.isArray(decoded_json?.suggestions)) break attempt_to_return_api_response;
|
|
11271
12111
|
try {
|
|
11272
12112
|
return await this.#run_url_creator_for_suggest(input_req.merchant, input_req.market, input_req.locale, decoded_json);
|
|
@@ -11283,6 +12123,7 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11283
12123
|
async query(input_req) {
|
|
11284
12124
|
return await this.#cached_request({
|
|
11285
12125
|
endpoint_: $e1d6c0f3d89d531c$var$search_base_url + "results",
|
|
12126
|
+
kind_: "search",
|
|
11286
12127
|
input_req_: input_req,
|
|
11287
12128
|
fallback_response_: () => ({
|
|
11288
12129
|
"n_hits": 0,
|
|
@@ -11302,6 +12143,9 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11302
12143
|
return await this.#cached_request({
|
|
11303
12144
|
endpoint_: $e1d6c0f3d89d531c$var$v3_base_url + "listings/" + (id_type_ === $779741d0f266ea8c$export$5aae649db1b959fc ? "external_id/" : "") + encodeURIComponent(id_to_query_for_),
|
|
11304
12145
|
input_req_: input_req,
|
|
12146
|
+
kind_: "listing",
|
|
12147
|
+
id_to_query_for_: id_to_query_for_,
|
|
12148
|
+
id_type_: id_type_,
|
|
11305
12149
|
fallback_response_: () => ({
|
|
11306
12150
|
listing_id: "",
|
|
11307
12151
|
listing_type: "category",
|
|
@@ -11328,6 +12172,9 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11328
12172
|
endpoint_: $e1d6c0f3d89d531c$var$v3_base_url + "listings/" + (id_type_ === $779741d0f266ea8c$export$5aae649db1b959fc ? "external_id/" : "") + encodeURIComponent(id_to_query_for_) + "/products",
|
|
11329
12173
|
input_req_: input_req_,
|
|
11330
12174
|
currentListingForTransformer_: currentListingForTransformer_,
|
|
12175
|
+
kind_: "listing_products",
|
|
12176
|
+
id_to_query_for_: id_to_query_for_,
|
|
12177
|
+
id_type_: id_type_,
|
|
11331
12178
|
fallback_response_: () => ({
|
|
11332
12179
|
"n_hits": 0,
|
|
11333
12180
|
"displays": [],
|
|
@@ -11341,6 +12188,7 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11341
12188
|
async get_recommended(input_req) {
|
|
11342
12189
|
return await this.#cached_request({
|
|
11343
12190
|
endpoint_: $e1d6c0f3d89d531c$var$search_base_url + "related",
|
|
12191
|
+
kind_: "related",
|
|
11344
12192
|
input_req_: input_req,
|
|
11345
12193
|
fallback_response_: () => ({
|
|
11346
12194
|
displays: []
|
|
@@ -11348,6 +12196,228 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
11348
12196
|
});
|
|
11349
12197
|
}
|
|
11350
12198
|
}
|
|
12199
|
+
|
|
12200
|
+
/** V4 browse's largest page; a bigger v3 page is V4's pages chained by their cursors, as the facade does. */
|
|
12201
|
+
const $100bd8804fbc65ac$var$BROWSE_MAX_LIMIT = 100;
|
|
12202
|
+
/** V4 browse's page size without a limit, and v3's. */
|
|
12203
|
+
const $100bd8804fbc65ac$var$DEFAULT_LIMIT = 24;
|
|
12204
|
+
/** A query with no letter or digit browses the catalogue instead of returning an empty grid, as on v3. */
|
|
12205
|
+
const $100bd8804fbc65ac$var$HAS_LETTER_OR_DIGIT = /[\p{L}\p{N}]/u;
|
|
12206
|
+
class $100bd8804fbc65ac$export$721afe49a594bed extends (0, $e1d6c0f3d89d531c$export$e015ed2f2950f2e3) {
|
|
12207
|
+
/** Facets served so far, per merchant, market and locale, to resolve v3 filter fields (group titles) to V4 fields. */#facet_indices = new Map();
|
|
12208
|
+
/** Browses whose facets were read only to resolve filter fields, so each is read at most once. */
|
|
12209
|
+
#learned = new Set();
|
|
12210
|
+
/** How many products came before each cursor V4 handed out, for the lower-bound count when `total` is absent. */
|
|
12211
|
+
#cursor_offsets = new Map();
|
|
12212
|
+
/** Each listing's ancestors from the listing tree, per merchant, market and locale, read once a page load. */
|
|
12213
|
+
#ancestor_lookups = new Map();
|
|
12214
|
+
/** Filter clauses V4 refused (`unknown_filter_field`, `invalid_filter`), per merchant, market and locale. */
|
|
12215
|
+
#rejected = new Map();
|
|
12216
|
+
constructor(options) {
|
|
12217
|
+
super(options);
|
|
12218
|
+
$5vyXB$depictaiutilishared.set_event_api("v4");
|
|
12219
|
+
}
|
|
12220
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12221
|
+
async request_raw_(call) {
|
|
12222
|
+
switch (call.kind_) {
|
|
12223
|
+
case "search":
|
|
12224
|
+
return await this.#browse("search", call.request_);
|
|
12225
|
+
case "listing_products":
|
|
12226
|
+
return await this.#browse("listing", call.request_, {
|
|
12227
|
+
[call.id_type_ === $779741d0f266ea8c$export$5aae649db1b959fc ? "external_id" : "id"]: call.id_to_query_for_
|
|
12228
|
+
});
|
|
12229
|
+
case "listing":
|
|
12230
|
+
return await this.#listing(call);
|
|
12231
|
+
case "suggest":
|
|
12232
|
+
return await this.#suggest(call.request_);
|
|
12233
|
+
case "related":
|
|
12234
|
+
{
|
|
12235
|
+
const {
|
|
12236
|
+
merchant: merchant,
|
|
12237
|
+
market: market,
|
|
12238
|
+
locale: locale,
|
|
12239
|
+
query: query
|
|
12240
|
+
} = call.request_;
|
|
12241
|
+
const displays = await $ce8babba0db8995c$export$bd5f8a7d3e47a43d({
|
|
12242
|
+
merchant: merchant,
|
|
12243
|
+
market: market,
|
|
12244
|
+
locale: locale,
|
|
12245
|
+
query: query
|
|
12246
|
+
});
|
|
12247
|
+
return displays && {
|
|
12248
|
+
displays: displays
|
|
12249
|
+
};
|
|
12250
|
+
}
|
|
12251
|
+
}
|
|
12252
|
+
}
|
|
12253
|
+
#merchant_url(merchant, path) {
|
|
12254
|
+
return $c25fb5290ccf7b3e$export$b6dad15503f66988(merchant, path);
|
|
12255
|
+
}
|
|
12256
|
+
async #get_json(url) {
|
|
12257
|
+
return (await this.#get_answer(url)).body_;
|
|
12258
|
+
}
|
|
12259
|
+
/** A GET's body on a 200, else V4's error (when it sent one). */
|
|
12260
|
+
async #get_answer(url) {
|
|
12261
|
+
return await $c25fb5290ccf7b3e$export$f035610fd74c541a(url);
|
|
12262
|
+
}
|
|
12263
|
+
#facet_index(merchant, market, locale) {
|
|
12264
|
+
const key = JSON.stringify([merchant, market, locale]);
|
|
12265
|
+
let index = this.#facet_indices.get(key);
|
|
12266
|
+
if (!index) this.#facet_indices.set(key, index = new (0, $debf9654214236f5$export$8d488bcc71d07ffb)());
|
|
12267
|
+
return index;
|
|
12268
|
+
}
|
|
12269
|
+
async #browse_page(merchant, request) {
|
|
12270
|
+
return (await this.#browse_answer(merchant, request)).body_;
|
|
12271
|
+
}
|
|
12272
|
+
async #browse_answer(merchant, request) {
|
|
12273
|
+
return await this.#get_answer(this.#merchant_url(merchant, "/browse") + "?" + $4261fabd2fa94c86$export$7659319cdb555579(request));
|
|
12274
|
+
}
|
|
12275
|
+
/** The filter clauses V4 refused, per merchant, market and locale, for this page load. */
|
|
12276
|
+
#rejected_clauses(merchant, market, locale) {
|
|
12277
|
+
const key = JSON.stringify([merchant, market, locale]);
|
|
12278
|
+
let rejected = this.#rejected.get(key);
|
|
12279
|
+
if (!rejected) this.#rejected.set(key, rejected = new Set());
|
|
12280
|
+
return rejected;
|
|
12281
|
+
}
|
|
12282
|
+
async #browse(door, v3_request, listing) {
|
|
12283
|
+
const {
|
|
12284
|
+
merchant: merchant,
|
|
12285
|
+
market: market
|
|
12286
|
+
} = v3_request;
|
|
12287
|
+
const locale = $4261fabd2fa94c86$export$eb90c08da400512d(v3_request.locale);
|
|
12288
|
+
const query = door === "search" && v3_request.query && $100bd8804fbc65ac$var$HAS_LETTER_OR_DIGIT.test(v3_request.query) ? v3_request.query : undefined;
|
|
12289
|
+
const base = {
|
|
12290
|
+
market: market,
|
|
12291
|
+
...(locale ? {
|
|
12292
|
+
locale: locale
|
|
12293
|
+
} : {}),
|
|
12294
|
+
...(query ? {
|
|
12295
|
+
query: query
|
|
12296
|
+
} : {}),
|
|
12297
|
+
...(listing ? {
|
|
12298
|
+
listing: listing
|
|
12299
|
+
} : {})
|
|
12300
|
+
};
|
|
12301
|
+
const index = this.#facet_index(merchant, market, locale);
|
|
12302
|
+
const filters = v3_request.filters ?? [];
|
|
12303
|
+
// depict-ui sends a filter's lowercased group title as its field. A page opened from a link with filters in it
|
|
12304
|
+
// comes before any facets, so read this browse's facets once to learn which field each title names.
|
|
12305
|
+
const learn_key = JSON.stringify([merchant, base]);
|
|
12306
|
+
if (filters.some(filter => filter.data != null && !$debf9654214236f5$export$3b6ba2422a5e0aa0(filter.field, index)) && !this.#learned.has(learn_key)) {
|
|
12307
|
+
this.#learned.add(learn_key);
|
|
12308
|
+
index.learn_((await this.#browse_page(merchant, {
|
|
12309
|
+
...base,
|
|
12310
|
+
include: ["facets"],
|
|
12311
|
+
limit: 1
|
|
12312
|
+
}))?.facets);
|
|
12313
|
+
}
|
|
12314
|
+
// A filter V4 can't take must not cost the shopper the page: a link can outlive its filter (one removed from the
|
|
12315
|
+
// store, a hand-written value). One the adapter can't write is left out here; one V4 rejects is left out and the
|
|
12316
|
+
// page asked again, and remembered for this page load so later pages don't ask with it.
|
|
12317
|
+
const rejected = this.#rejected_clauses(merchant, market, locale);
|
|
12318
|
+
let clauses = [];
|
|
12319
|
+
for (const filter of filters) try {
|
|
12320
|
+
const clause = $debf9654214236f5$export$c17bb5d2ead3e8f3(filter, index);
|
|
12321
|
+
if (clause) clauses.push(clause);
|
|
12322
|
+
} catch (e) {
|
|
12323
|
+
if (!(e instanceof (0, $debf9654214236f5$export$f5ea4d073ddb4bdb))) throw e;
|
|
12324
|
+
$5vyXB$depictaiutilishared.dwarn("[NativeDepictAPI] leaving out a filter V4 can't take:", e.message, filter);
|
|
12325
|
+
}
|
|
12326
|
+
clauses = clauses.filter(clause => !rejected.has(clause.clause_));
|
|
12327
|
+
const sort = $debf9654214236f5$export$78eb8e636d89ff30(v3_request.sort);
|
|
12328
|
+
const include = door === "search" ? ["facets", "sorts", "content", "attributes"] : ["facets", "sorts", "attributes"];
|
|
12329
|
+
const want = v3_request.limit ?? $100bd8804fbc65ac$var$DEFAULT_LIMIT;
|
|
12330
|
+
const offset = v3_request.cursor && this.#cursor_offsets.get(v3_request.cursor) || 0;
|
|
12331
|
+
const request_with = sent => ({
|
|
12332
|
+
...base,
|
|
12333
|
+
...(sent.length ? {
|
|
12334
|
+
filter_by: sent.map(clause => clause.clause_).join(" && ")
|
|
12335
|
+
} : {}),
|
|
12336
|
+
...(sort ? {
|
|
12337
|
+
sort: sort
|
|
12338
|
+
} : {}),
|
|
12339
|
+
...(v3_request.cursor ? {
|
|
12340
|
+
cursor: v3_request.cursor
|
|
12341
|
+
} : {}),
|
|
12342
|
+
include: include,
|
|
12343
|
+
...(want !== $100bd8804fbc65ac$var$DEFAULT_LIMIT ? {
|
|
12344
|
+
limit: Math.min(want, $100bd8804fbc65ac$var$BROWSE_MAX_LIMIT)
|
|
12345
|
+
} : {})
|
|
12346
|
+
});
|
|
12347
|
+
let request = request_with(clauses);
|
|
12348
|
+
let answer = await this.#browse_answer(merchant, request);
|
|
12349
|
+
// Each retry leaves out at least one more clause, so this ends.
|
|
12350
|
+
while (!answer.body_) {
|
|
12351
|
+
const refused = $debf9654214236f5$export$c38de645260a41ed(answer.error_, clauses);
|
|
12352
|
+
if (!refused.length) return undefined;
|
|
12353
|
+
$5vyXB$depictaiutilishared.dwarn("[NativeDepictAPI] leaving out filters V4 refused:", refused.map(clause => clause.clause_), answer.error_?.message);
|
|
12354
|
+
for (const clause of refused) rejected.add(clause.clause_);
|
|
12355
|
+
clauses = clauses.filter(clause => !refused.includes(clause));
|
|
12356
|
+
request = request_with(clauses);
|
|
12357
|
+
answer = await this.#browse_answer(merchant, request);
|
|
12358
|
+
}
|
|
12359
|
+
let response = answer.body_;
|
|
12360
|
+
// A page over V4's largest is its pages chained by their cursors; later pages ask for products alone.
|
|
12361
|
+
while (want > $100bd8804fbc65ac$var$BROWSE_MAX_LIMIT && response.products.length < want && response.cursor !== undefined) {
|
|
12362
|
+
const page = await this.#browse_page(merchant, {
|
|
12363
|
+
...request,
|
|
12364
|
+
cursor: response.cursor,
|
|
12365
|
+
limit: Math.min(want - response.products.length, $100bd8804fbc65ac$var$BROWSE_MAX_LIMIT),
|
|
12366
|
+
include: ["attributes"]
|
|
12367
|
+
});
|
|
12368
|
+
if (!page) return undefined;
|
|
12369
|
+
if (!page.products.length) break;
|
|
12370
|
+
response = {
|
|
12371
|
+
...response,
|
|
12372
|
+
products: [...response.products, ...page.products],
|
|
12373
|
+
...(page.cursor !== undefined ? {
|
|
12374
|
+
cursor: page.cursor
|
|
12375
|
+
} : {
|
|
12376
|
+
cursor: undefined
|
|
12377
|
+
})
|
|
12378
|
+
};
|
|
12379
|
+
}
|
|
12380
|
+
if (response.cursor === undefined) delete response.cursor;
|
|
12381
|
+
index.learn_(response.facets);
|
|
12382
|
+
if (response.cursor !== undefined) this.#cursor_offsets.set(response.cursor, offset + response.products.length);
|
|
12383
|
+
return $4261fabd2fa94c86$export$efb7dd882d411dd4(response, door, offset);
|
|
12384
|
+
}
|
|
12385
|
+
async #listing(call) {
|
|
12386
|
+
const {
|
|
12387
|
+
merchant: merchant,
|
|
12388
|
+
market: market
|
|
12389
|
+
} = call.request_;
|
|
12390
|
+
const locale = $4261fabd2fa94c86$export$eb90c08da400512d(call.request_.locale);
|
|
12391
|
+
const by_external_id = call.id_type_ === $779741d0f266ea8c$export$5aae649db1b959fc;
|
|
12392
|
+
const path = by_external_id ? "/listings" : "/listings/" + encodeURIComponent(call.id_to_query_for_);
|
|
12393
|
+
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]]));
|
|
12394
|
+
return response && $4261fabd2fa94c86$export$996f2b1e66d9b5af(response.listing);
|
|
12395
|
+
}
|
|
12396
|
+
async #suggest(v3_request) {
|
|
12397
|
+
const {
|
|
12398
|
+
merchant: merchant,
|
|
12399
|
+
market: market
|
|
12400
|
+
} = v3_request;
|
|
12401
|
+
const locale = $4261fabd2fa94c86$export$eb90c08da400512d(v3_request.locale);
|
|
12402
|
+
const response = await this.#get_json(this.#merchant_url(merchant, "/suggest") + "?" + $4261fabd2fa94c86$export$fec3e4b5adfcea2c([["market", market], ["locale", locale], ["query", v3_request.query ?? ""]]));
|
|
12403
|
+
if (!response) return undefined;
|
|
12404
|
+
const needs_ancestors = response.suggestions.some(suggestion => suggestion.type === "listing" && suggestion.path.length > 0);
|
|
12405
|
+
return $4261fabd2fa94c86$export$2860125b419015f8(response, needs_ancestors ? await this.#ancestors(merchant, market, locale) : undefined);
|
|
12406
|
+
}
|
|
12407
|
+
/** V4 suggestions name ancestors by title only; the listing tree names them by id. A failed read isn't retried. */
|
|
12408
|
+
#ancestors(merchant, market, locale) {
|
|
12409
|
+
const key = JSON.stringify([merchant, market, locale]);
|
|
12410
|
+
let lookup = this.#ancestor_lookups.get(key);
|
|
12411
|
+
if (!lookup) {
|
|
12412
|
+
lookup = this.#get_json(this.#merchant_url(merchant, "/listings") + "?" + $4261fabd2fa94c86$export$fec3e4b5adfcea2c([["market", market], ["locale", locale]])).then(tree => tree && $4261fabd2fa94c86$export$76d96892da63b395(tree.listings));
|
|
12413
|
+
this.#ancestor_lookups.set(key, lookup);
|
|
12414
|
+
}
|
|
12415
|
+
return lookup;
|
|
12416
|
+
}
|
|
12417
|
+
}
|
|
12418
|
+
function $100bd8804fbc65ac$export$6d972e6af9de09f0(version, options) {
|
|
12419
|
+
return version === "v4" ? new $100bd8804fbc65ac$export$721afe49a594bed(options) : new (0, $e1d6c0f3d89d531c$export$e015ed2f2950f2e3)(options);
|
|
12420
|
+
}
|
|
11351
12421
|
function $c79fd10a3ab7d6e0$export$477caf01aecaeb2a(options) {
|
|
11352
12422
|
const router_ = options.router_;
|
|
11353
12423
|
const search_query_url_param_name_ = "search_query_url_param_name_" in options ? options.search_query_url_param_name_ : undefined;
|
|
@@ -11598,8 +12668,9 @@ class $48567ac5b39bac56$export$f34314aa9505732e {
|
|
|
11598
12668
|
quicklinks_signal_: $5vyXB$solidjs.createSignal(),
|
|
11599
12669
|
i18n_: i18n_,
|
|
11600
12670
|
reset_history_state_: reset_history_state_,
|
|
12671
|
+
depict_api_: typeof api === "object" && api ? api :
|
|
11601
12672
|
// @ts-ignore
|
|
11602
|
-
|
|
12673
|
+
$100bd8804fbc65ac$export$6d972e6af9de09f0(api, {
|
|
11603
12674
|
display_transformers: display_transformers
|
|
11604
12675
|
}),
|
|
11605
12676
|
router_: this.#router,
|
|
@@ -12999,8 +14070,9 @@ class $2c61e4cd8229c49a$export$ac6237957a15b3f0 {
|
|
|
12999
14070
|
const get_search_query_ = $5vyXB$solidjs.createMemo(previous_value => {
|
|
13000
14071
|
if (get_search_query_updating_blocked()) return previous_value;else return raw_search_query_accessor();
|
|
13001
14072
|
});
|
|
14073
|
+
const depict_api_ = typeof api === "object" && api ? api :
|
|
13002
14074
|
// @ts-ignore
|
|
13003
|
-
|
|
14075
|
+
$100bd8804fbc65ac$export$6d972e6af9de09f0(api, {
|
|
13004
14076
|
display_transformers: display_transformers
|
|
13005
14077
|
});
|
|
13006
14078
|
const previous_searches = $2b7a005a65221045$export$84bba84a7b837187(get_search_query_);
|