@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.
@@ -1,4 +1,4 @@
1
- import { add_to_version_info as $i7OB2$add_to_version_info, javascript_media_query as $i7OB2$javascript_media_query, standard_price_format as $i7OB2$standard_price_format, catchify as $i7OB2$catchify1, observer as $i7OB2$observer, slider_fractional_factory as $i7OB2$slider_fractional_factory, report as $i7OB2$report1, dlog as $i7OB2$dlog, camelCasifyObject as $i7OB2$camelCasifyObject, make_random_classname as $i7OB2$make_random_classname, n_col_styling_with_dist as $i7OB2$n_col_styling_with_dist, layout_get_visible_recs_without_partial_rows as $i7OB2$layout_get_visible_recs_without_partial_rows, layout_get_total_rec_amount_for_row as $i7OB2$layout_get_total_rec_amount_for_row, layout_media_query_header as $i7OB2$layout_media_query_header, dwarn as $i7OB2$dwarn, slider_fading_factory as $i7OB2$slider_fading_factory, Amazing_Slider as $i7OB2$Amazing_Slider, slider_snap_css as $i7OB2$slider_snap_css, useExpandingContainer as $i7OB2$useExpandingContainer, hex_to_rgb as $i7OB2$hex_to_rgb, relative_luminance_from_rgb as $i7OB2$relative_luminance_from_rgb, instant_exec_on_suspect_history_change as $i7OB2$instant_exec_on_suspect_history_change, base64_encode_unicode as $i7OB2$base64_encode_unicode, base64_decode_unicode as $i7OB2$base64_decode_unicode, queueMacroTask as $i7OB2$queueMacroTask, findMostFrequentItem as $i7OB2$findMostFrequentItem, fetch_retry as $i7OB2$fetch_retry, base_url as $i7OB2$base_url, deparallelize_no_drop as $i7OB2$deparallelize_no_drop, ContainedImage as $i7OB2$ContainedImage, make_asyncIterable_exiter as $i7OB2$make_asyncIterable_exiter, href_change_ipns as $i7OB2$href_change_ipns, use_href_accessor as $i7OB2$use_href_accessor1, get_session_id as $i7OB2$get_session_id, add_version_query_params as $i7OB2$add_version_query_params, snakeCasifyObject as $i7OB2$snakeCasifyObject, sort_obj as $i7OB2$sort_obj, make_url_with_query_params as $i7OB2$make_url_with_query_params, insert_surfaces as $i7OB2$insert_surfaces } from "@depict-ai/utilishared/latest";
1
+ import { add_to_version_info as $i7OB2$add_to_version_info, javascript_media_query as $i7OB2$javascript_media_query, standard_price_format as $i7OB2$standard_price_format, catchify as $i7OB2$catchify1, observer as $i7OB2$observer, slider_fractional_factory as $i7OB2$slider_fractional_factory, report as $i7OB2$report1, dlog as $i7OB2$dlog, camelCasifyObject as $i7OB2$camelCasifyObject, make_random_classname as $i7OB2$make_random_classname, n_col_styling_with_dist as $i7OB2$n_col_styling_with_dist, layout_get_visible_recs_without_partial_rows as $i7OB2$layout_get_visible_recs_without_partial_rows, layout_get_total_rec_amount_for_row as $i7OB2$layout_get_total_rec_amount_for_row, layout_media_query_header as $i7OB2$layout_media_query_header, dwarn as $i7OB2$dwarn, slider_fading_factory as $i7OB2$slider_fading_factory, Amazing_Slider as $i7OB2$Amazing_Slider, slider_snap_css as $i7OB2$slider_snap_css, useExpandingContainer as $i7OB2$useExpandingContainer, hex_to_rgb as $i7OB2$hex_to_rgb, relative_luminance_from_rgb as $i7OB2$relative_luminance_from_rgb, instant_exec_on_suspect_history_change as $i7OB2$instant_exec_on_suspect_history_change, base64_encode_unicode as $i7OB2$base64_encode_unicode, base64_decode_unicode as $i7OB2$base64_decode_unicode, queueMacroTask as $i7OB2$queueMacroTask, findMostFrequentItem as $i7OB2$findMostFrequentItem, fetch_retry as $i7OB2$fetch_retry, base_url as $i7OB2$base_url, deparallelize_no_drop as $i7OB2$deparallelize_no_drop, ContainedImage as $i7OB2$ContainedImage, make_asyncIterable_exiter as $i7OB2$make_asyncIterable_exiter, href_change_ipns as $i7OB2$href_change_ipns, use_href_accessor as $i7OB2$use_href_accessor1, get_session_id as $i7OB2$get_session_id, add_version_query_params as $i7OB2$add_version_query_params, snakeCasifyObject as $i7OB2$snakeCasifyObject, set_event_api as $i7OB2$set_event_api, sort_obj as $i7OB2$sort_obj, make_url_with_query_params as $i7OB2$make_url_with_query_params, insert_surfaces as $i7OB2$insert_surfaces } from "@depict-ai/utilishared/latest";
2
2
  import { createComponent as $i7OB2$createComponent, ssr as $i7OB2$ssr, ssrHydrationKey as $i7OB2$ssrHydrationKey, escape as $i7OB2$escape, isServer as $i7OB2$isServer, ssrAttribute as $i7OB2$ssrAttribute, mergeProps as $i7OB2$mergeProps1, insert as $i7OB2$insert, ssrClassList as $i7OB2$ssrClassList, ssrElement as $i7OB2$ssrElement, ssrStyle as $i7OB2$ssrStyle, Dynamic as $i7OB2$Dynamic, spread as $i7OB2$spread } from "solid-js/web";
3
3
  import { createContext as $i7OB2$createContext, createSignal as $i7OB2$createSignal, getOwner as $i7OB2$getOwner, createResource as $i7OB2$createResource, untrack as $i7OB2$untrack, createRoot as $i7OB2$createRoot, createEffect as $i7OB2$createEffect, runWithOwner as $i7OB2$runWithOwner, onCleanup as $i7OB2$onCleanup, createMemo as $i7OB2$createMemo, Show as $i7OB2$Show, createComputed as $i7OB2$createComputed, createRenderEffect as $i7OB2$createRenderEffect, mergeProps as $i7OB2$mergeProps, useContext as $i7OB2$useContext, createReaction as $i7OB2$createReaction, on as $i7OB2$on, Suspense as $i7OB2$Suspense, ErrorBoundary as $i7OB2$ErrorBoundary, Index as $i7OB2$Index, For as $i7OB2$For, createUniqueId as $i7OB2$createUniqueId, mapArray as $i7OB2$mapArray, batch as $i7OB2$batch, Switch as $i7OB2$Switch, Match as $i7OB2$Match, splitProps as $i7OB2$splitProps, createComponent as $i7OB2$createComponent1, createSelector as $i7OB2$createSelector, children as $i7OB2$children } from "solid-js";
4
4
  import { catchify as $i7OB2$catchify, report as $i7OB2$report, use_href_accessor as $i7OB2$use_href_accessor, dlog as $i7OB2$dlog1, ListenableSet as $i7OB2$ListenableSet, queueMacroTask as $i7OB2$queueMacroTask1 } from "@depict-ai/utilishared/latest";
@@ -7,7 +7,7 @@ import { createStore as $i7OB2$createStore, reconcile as $i7OB2$reconcile } from
7
7
  /*! Depict.ai search and product listing SDK */
8
8
  import { register_es_version } from "../../multi_import_deduplicator.mjs";
9
9
  register_es_version("ui", "latest");
10
- const $ec291e0010116877$export$83d89fbfd8236492 = "4.10.32";
10
+ const $ec291e0010116877$export$83d89fbfd8236492 = "4.10.33";
11
11
  function $dc9262ef6f786812$export$d9f36cf74e24d595(media_query) {
12
12
  const signal = $i7OB2$createSignal(false);
13
13
  $i7OB2$onCleanup($i7OB2$javascript_media_query(media_query, ({
@@ -10674,12 +10674,795 @@ function $c16e74cfe125bb05$export$f091cbac892643a4(obj) {
10674
10674
  return Object.fromEntries(mapped_stuff); // FUCK TYPESCRIPT, WHY CAN'T YOU DO THIS CORRECTLY???
10675
10675
  }
10676
10676
 
10677
+ /** One try and at most two retries: a 503 burst from V4 shouldn't be multiplied by fetch_retry's default of 10. */
10678
+ const $c6c537571dbf3c03$var$NATIVE_MAX_TRIES = 3;
10679
+ function $c6c537571dbf3c03$export$b6dad15503f66988(merchant, path) {
10680
+ return `${(0, $i7OB2$base_url)}/v4/${encodeURIComponent(merchant)}${path}`;
10681
+ }
10682
+ async function $c6c537571dbf3c03$export$88d793e3827f3436(url) {
10683
+ return (await $c6c537571dbf3c03$export$f035610fd74c541a(url)).body_;
10684
+ }
10685
+ async function $c6c537571dbf3c03$export$f035610fd74c541a(url) {
10686
+ const response = await $i7OB2$fetch_retry(url, {
10687
+ method: "GET"
10688
+ }, $c6c537571dbf3c03$var$NATIVE_MAX_TRIES);
10689
+ if (!response) {
10690
+ $i7OB2$dwarn("[NativeDepictAPI] no response from", url);
10691
+ return {};
10692
+ }
10693
+ if (response.status === 200)
10694
+ // 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
10695
+ // back instead of rejecting: get_recommendation_types then forgets the read rather than keeping it in flight.
10696
+ try {
10697
+ return {
10698
+ body_: await response.json()
10699
+ };
10700
+ } catch (e) {
10701
+ $i7OB2$dwarn("[NativeDepictAPI] 200 without a JSON body from", url, e);
10702
+ return {};
10703
+ }
10704
+ let error;
10705
+ try {
10706
+ error = (await response.json()).error;
10707
+ } catch {
10708
+ // not V4's error body
10709
+ }
10710
+ $i7OB2$dwarn("[NativeDepictAPI]", response.status, error?.code, error?.message, error?.request_id, url);
10711
+ if (response.status >= 500) $i7OB2$report1([new Error(`V4 ${response.status} ${error?.code ?? ""}`), "Native V4 request failed"], "warning", {
10712
+ url: url,
10713
+ status: response.status,
10714
+ code: error?.code,
10715
+ request_id: error?.request_id ?? response.headers.get("x-depict-request-id")
10716
+ });
10717
+ return {
10718
+ error_: error
10719
+ };
10720
+ }
10721
+ const $5e86c304f21e41a8$export$8e79752841e7cdb4 = 900000;
10722
+ const $5e86c304f21e41a8$var$storage_key = merchant => `depict_v4_recommendation_types_${merchant}`;
10723
+ /** One read per merchant and CONTEXT_TTL_MS in this page; a failed read is forgotten so the next caller tries again. */
10724
+ const $5e86c304f21e41a8$var$in_flight = new Map();
10725
+ function $5e86c304f21e41a8$var$from_storage(merchant, now) {
10726
+ try {
10727
+ const stored = JSON.parse(localStorage.getItem($5e86c304f21e41a8$var$storage_key(merchant)) ?? "null");
10728
+ if (!stored || !Array.isArray(stored.types) || !(now - stored.fetched_at < $5e86c304f21e41a8$export$8e79752841e7cdb4)) return undefined;
10729
+ return $5e86c304f21e41a8$var$to_map(stored.types);
10730
+ } catch {
10731
+ return undefined;
10732
+ }
10733
+ }
10734
+ function $5e86c304f21e41a8$var$to_storage(merchant, types, now) {
10735
+ try {
10736
+ localStorage.setItem($5e86c304f21e41a8$var$storage_key(merchant), JSON.stringify({
10737
+ fetched_at: now,
10738
+ types: types
10739
+ }));
10740
+ } catch {
10741
+ // localStorage unavailable or full: read /context again on the next page.
10742
+ }
10743
+ }
10744
+ const $5e86c304f21e41a8$var$to_map = types => new Map(types.map(({
10745
+ type: type,
10746
+ inputs: inputs
10747
+ }) => [type, inputs]));
10748
+ function $5e86c304f21e41a8$export$869eb14d6f85ac51(merchant, now = Date.now()) {
10749
+ const pending = $5e86c304f21e41a8$var$in_flight.get(merchant);
10750
+ if (pending && now - pending.started_at < $5e86c304f21e41a8$export$8e79752841e7cdb4) return pending.read;
10751
+ const stored = $5e86c304f21e41a8$var$from_storage(merchant, now);
10752
+ if (stored) return Promise.resolve(stored);
10753
+ const read = $c6c537571dbf3c03$export$88d793e3827f3436($c6c537571dbf3c03$export$b6dad15503f66988(merchant, "/context")).then(context => {
10754
+ if (!context) {
10755
+ if ($5e86c304f21e41a8$var$in_flight.get(merchant)?.read === read) $5e86c304f21e41a8$var$in_flight.delete(merchant);
10756
+ return undefined;
10757
+ }
10758
+ const types = context.recommendation_types ?? [];
10759
+ $5e86c304f21e41a8$var$to_storage(merchant, types, now);
10760
+ return $5e86c304f21e41a8$var$to_map(types);
10761
+ });
10762
+ $5e86c304f21e41a8$var$in_flight.set(merchant, {
10763
+ started_at: now,
10764
+ read: read
10765
+ });
10766
+ return read;
10767
+ }
10768
+ function $5e86c304f21e41a8$export$6cde5c31239dec47() {
10769
+ $5e86c304f21e41a8$var$in_flight.clear();
10770
+ }
10771
+
10772
+ /**
10773
+ * The shopper's recently viewed products, kept in the browser for the native V4 API's history-based recommendations.
10774
+ *
10775
+ * v3 kept this history on the server, per session. V4 content requests carry no session, so a surface that reads
10776
+ * history gets it in the request (`recent_views`), and the SDK keeps the list. It holds product ids and view times
10777
+ * only (no session, user or page data), bounded in size and age, in localStorage per merchant; when localStorage
10778
+ * can't be used (private mode, blocked, full) it lives in memory for the page load.
10779
+ *
10780
+ * A view is recorded when a native product-anchored recommendation request resolves its anchor, as v3's facade records
10781
+ * a resolved anchor as a view; the product being viewed is in the list from the next request on.
10782
+ */ /** recs-wasm reads the newest 20 views (V4 `recent_views` docs), so more would never be read. */
10783
+ const $6db5e630baf4072a$export$3d684435158adda6 = 20;
10784
+ const $6db5e630baf4072a$export$5eb0a366a50fa99e = 2592000000;
10785
+ /** V4's longest product id (`ProductRef`); a longer one is never a product it knows. */
10786
+ const $6db5e630baf4072a$var$MAX_ID_LENGTH = 500;
10787
+ const $6db5e630baf4072a$var$storage_key = merchant => `depict_v4_recent_views_${merchant}`;
10788
+ /** The list per merchant as last written, which reads use when localStorage can't hold it. */
10789
+ const $6db5e630baf4072a$var$in_memory = new Map();
10790
+ /** Merchants whose last write to localStorage failed, so localStorage holds an older list than memory. */
10791
+ const $6db5e630baf4072a$var$unstored = new Set();
10792
+ /** `views` as a valid list: well-formed entries, newest first, one per id, not older than the age bound or too many. */
10793
+ function $6db5e630baf4072a$var$bounded(views, now) {
10794
+ if (!Array.isArray(views)) return [];
10795
+ const seen = new Set();
10796
+ const kept = [];
10797
+ for (const item of views) {
10798
+ if (!item || typeof item !== "object") continue;
10799
+ const {
10800
+ id: id,
10801
+ at: at
10802
+ } = item;
10803
+ if (typeof id !== "string" || !id || id.length > $6db5e630baf4072a$var$MAX_ID_LENGTH || typeof at !== "string") continue;
10804
+ const time = Date.parse(at);
10805
+ if (Number.isNaN(time) || now - time > $6db5e630baf4072a$export$5eb0a366a50fa99e) continue;
10806
+ kept.push({
10807
+ view: {
10808
+ id: id,
10809
+ at: new Date(time).toISOString()
10810
+ },
10811
+ time: time
10812
+ });
10813
+ }
10814
+ kept.sort((a, b) => b.time - a.time);
10815
+ const newest = [];
10816
+ for (const {
10817
+ view: view
10818
+ } of kept) {
10819
+ if (seen.has(view.id)) continue;
10820
+ seen.add(view.id);
10821
+ newest.push(view);
10822
+ if (newest.length === $6db5e630baf4072a$export$3d684435158adda6) break;
10823
+ }
10824
+ return newest;
10825
+ }
10826
+ function $6db5e630baf4072a$var$read_stored(merchant) {
10827
+ if ($6db5e630baf4072a$var$unstored.has(merchant)) return $6db5e630baf4072a$var$in_memory.get(merchant);
10828
+ try {
10829
+ const stored = localStorage.getItem($6db5e630baf4072a$var$storage_key(merchant));
10830
+ return stored === null ? [] : JSON.parse(stored);
10831
+ } catch {
10832
+ return $6db5e630baf4072a$var$in_memory.get(merchant) ?? [];
10833
+ }
10834
+ }
10835
+ function $6db5e630baf4072a$export$2d7138f47b625a04(merchant, now = Date.now()) {
10836
+ return $6db5e630baf4072a$var$bounded($6db5e630baf4072a$var$read_stored(merchant), now);
10837
+ }
10838
+ function $6db5e630baf4072a$export$6379943de8f8af08(merchant, product_id, now = Date.now()) {
10839
+ const views = $6db5e630baf4072a$var$bounded([{
10840
+ id: product_id,
10841
+ at: new Date(now).toISOString()
10842
+ }, ...$6db5e630baf4072a$export$2d7138f47b625a04(merchant, now)], now);
10843
+ $6db5e630baf4072a$var$in_memory.set(merchant, views);
10844
+ try {
10845
+ localStorage.setItem($6db5e630baf4072a$var$storage_key(merchant), JSON.stringify(views));
10846
+ $6db5e630baf4072a$var$unstored.delete(merchant);
10847
+ } catch {
10848
+ // localStorage unavailable or full: the in-memory list serves this page load.
10849
+ $6db5e630baf4072a$var$unstored.add(merchant);
10850
+ }
10851
+ }
10852
+
10853
+ /** V4's largest `limit`, and the most ids `cart` and `exclude` take. */
10854
+ const $6387a5d45d50694e$export$f112abad09998fa8 = 100;
10855
+ const $6387a5d45d50694e$var$MAX_IDS = 100;
10856
+ /** The most products V4's `recent_views` takes. */
10857
+ const $6387a5d45d50694e$var$MAX_VIEWS = 50;
10858
+ /** What a v3 recommendations call names, as fetchDepictRecommendations takes it. */
10859
+ const $6387a5d45d50694e$var$distinct = ids => [...new Set(ids.filter(id => typeof id === "string" && id.length > 0))];
10860
+ function $6387a5d45d50694e$export$17493dc1a89b34e6(call, inputs, recent_views) {
10861
+ const reads = input => inputs ? inputs.includes(input) : input === "anchor";
10862
+ const product_ids = $6387a5d45d50694e$var$distinct(call.productIds ?? []);
10863
+ const request = {
10864
+ market: call.market,
10865
+ ...(call.locale ? {
10866
+ locale: call.locale
10867
+ } : {}),
10868
+ type: call.type
10869
+ };
10870
+ if (reads("anchor")) {
10871
+ if (call.categoryId) request.anchor = {
10872
+ type: "category",
10873
+ id: call.categoryId
10874
+ };else if (call.productId) request.anchor = {
10875
+ type: "product",
10876
+ id: call.productId
10877
+ };else if (product_ids.length) {
10878
+ const [first, ...rest] = product_ids;
10879
+ request.anchor = {
10880
+ type: "product",
10881
+ id: first
10882
+ };
10883
+ if (rest.length) request.exclude = rest.slice(0, $6387a5d45d50694e$var$MAX_IDS);
10884
+ }
10885
+ }
10886
+ if (reads("cart") && product_ids.length) request.cart = product_ids.slice(0, $6387a5d45d50694e$var$MAX_IDS);
10887
+ if (reads("recent_views") && recent_views.length) request.recent_views = recent_views.slice(0, $6387a5d45d50694e$var$MAX_VIEWS);
10888
+ if (call.limit) request.limit = Math.min(Math.max(1, Math.floor(call.limit)), $6387a5d45d50694e$export$f112abad09998fa8);
10889
+ request.include = ["attributes"];
10890
+ const anchor_only = inputs?.length === 1 && inputs[0] === "anchor";
10891
+ if (anchor_only && !request.anchor) return undefined;
10892
+ return request;
10893
+ }
10894
+ /** `encodeURIComponent`, as V4's own encoder writes a value (`+` would mean a space). */
10895
+ const $6387a5d45d50694e$var$encode = value => encodeURIComponent(value);
10896
+ function $6387a5d45d50694e$export$fc756666ac777d0(request) {
10897
+ const pairs = [];
10898
+ const add = (key, value) => value !== undefined && pairs.push(`${key}=${value}`);
10899
+ const list = values => values?.map($6387a5d45d50694e$var$encode).join(",");
10900
+ add("market", $6387a5d45d50694e$var$encode(request.market));
10901
+ add("locale", request.locale === undefined ? undefined : $6387a5d45d50694e$var$encode(request.locale));
10902
+ add("type", $6387a5d45d50694e$var$encode(request.type));
10903
+ add("anchor", request.anchor && `${$6387a5d45d50694e$var$encode(request.anchor.type)}:${$6387a5d45d50694e$var$encode(request.anchor.id)}`);
10904
+ add("cart", list(request.cart));
10905
+ add("recent_views", request.recent_views?.map(view => `${$6387a5d45d50694e$var$encode(view.id)}@${$6387a5d45d50694e$var$encode(view.at)}`).join(","));
10906
+ add("query", request.query === undefined ? undefined : $6387a5d45d50694e$var$encode(request.query));
10907
+ add("exclude", list(request.exclude));
10908
+ add("limit", request.limit === undefined ? undefined : String(request.limit));
10909
+ add("include", list(request.include));
10910
+ return pairs.join("&");
10911
+ }
10912
+ const $6387a5d45d50694e$export$89962366050887f7 = product => product.variants[product.selected]?.product_id ?? product.group_id;
10913
+ function $6387a5d45d50694e$export$afe6aeae61a7aa58(hits, scope, type) {
10914
+ const anchors = hits.slice(0, type === "search" ? 10 : 1);
10915
+ return anchors.map((anchor, at) => {
10916
+ const exclude = hits.filter((_, index) => index !== at).map($6387a5d45d50694e$export$89962366050887f7);
10917
+ return {
10918
+ market: scope.market,
10919
+ ...(scope.locale ? {
10920
+ locale: scope.locale
10921
+ } : {}),
10922
+ type: type,
10923
+ anchor: {
10924
+ type: "product",
10925
+ id: $6387a5d45d50694e$export$89962366050887f7(anchor)
10926
+ },
10927
+ ...(exclude.length ? {
10928
+ exclude: exclude.slice(0, $6387a5d45d50694e$var$MAX_IDS)
10929
+ } : {}),
10930
+ include: ["attributes"]
10931
+ };
10932
+ });
10933
+ }
10934
+ function $6387a5d45d50694e$export$9af50be6508dcd00(lists, limit) {
10935
+ const merged = [];
10936
+ const taken = new Set();
10937
+ const depth = Math.max(0, ...lists.map(list => list.length));
10938
+ for (let index = 0; index < depth; index++) for (const list of lists) {
10939
+ const product = list[index];
10940
+ if (product === undefined || taken.has(product.group_id)) continue;
10941
+ taken.add(product.group_id);
10942
+ merged.push(product);
10943
+ if (merged.length >= limit) return merged;
10944
+ }
10945
+ return merged;
10946
+ }
10947
+
10948
+ /** 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 `#`. */
10949
+ const $bb0caa66ae094e38$var$BARE_HEX = /^(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
10950
+ function $bb0caa66ae094e38$export$7abfb7bc025aaea8(product, tracking_key) {
10951
+ const product_attributes = product.attributes ?? {};
10952
+ return {
10953
+ variant_index: product.selected,
10954
+ variant_displays: product.variants.map(variant => {
10955
+ // A variant carries its own main image only when it differs from the card's; it has no gallery of its own.
10956
+ const image_urls = variant.image ? [variant.image] : [...product.images];
10957
+ const price = variant.price ?? product.price;
10958
+ const color = variant.color ?? product.color;
10959
+ const display = {
10960
+ ...product_attributes,
10961
+ // The merchant's variant attributes under their own keys (`add_to_cart_id`, `item_group_id`, …); the card
10962
+ // fields below win over a same-named attribute, as on v3.
10963
+ ...variant.attributes,
10964
+ product_id: variant.product_id,
10965
+ main_product_id: variant.attributes?.main_product_id ?? variant.group_id ?? product.group_id,
10966
+ title: variant.title ?? product.title,
10967
+ image_urls: image_urls,
10968
+ sale_price: price.amount,
10969
+ original_price: price.compare_at ?? price.amount,
10970
+ ...(price.lowest !== undefined ? {
10971
+ lowest_price: price.lowest
10972
+ } : {}),
10973
+ in_stock: variant.in_stock,
10974
+ ...(color ? {
10975
+ color_name: color.name
10976
+ } : {}),
10977
+ uri: variant.slug ?? product.slug
10978
+ };
10979
+ const hex = display.color_hex;
10980
+ if (typeof hex === "string" && $bb0caa66ae094e38$var$BARE_HEX.test(hex)) display.color_hex = `#${hex}`;
10981
+ return display;
10982
+ }),
10983
+ [tracking_key]: product.tracking_id
10984
+ };
10985
+ }
10986
+
10987
+ /**
10988
+ * Filters, facets and sorts between depict-ui's v3 shapes and the native V4 API.
10989
+ *
10990
+ * This is a client-side port of realtime's v3 facade (`v4/worker/src/facade/v3Browse.ts`: `v3FilterBy`, `toV3Filters`,
10991
+ * `toV3Sorts`, `toV3ContentLinks`), which owns the same translation on the server for v3 requests. Keep the two in
10992
+ * step: a difference shows up as a filter that works on v3 and not on native, or the other way round.
10993
+ *
10994
+ * The facade resolves a v3 filter field against the merchant's search config (titles, localized titles). The browser
10995
+ * has no config, so it resolves against the facets V4 served instead (see {@link FacetIndex}).
10996
+ */ /** 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. */
10997
+ class $929d1037ed236371$export$f5ea4d073ddb4bdb extends Error {}
10998
+ /** v3's names for V4's built-in fields, both ways. */
10999
+ const $929d1037ed236371$var$V3_FIELD = {
11000
+ price: "sale_price"
11001
+ };
11002
+ const $929d1037ed236371$var$V4_FIELD = {
11003
+ sale_price: "price"
11004
+ };
11005
+ const $929d1037ed236371$var$V3_SORT = {
11006
+ relevance: "_relevance",
11007
+ price: "sale_price",
11008
+ newest: "product_timestamp"
11009
+ };
11010
+ const $929d1037ed236371$var$V4_SORT = Object.fromEntries(Object.entries($929d1037ed236371$var$V3_SORT).map(([v4, v3]) => [v3, v4]));
11011
+ /** V4's public filter field syntax (`FilterField` in the contract). */
11012
+ const $929d1037ed236371$var$PUBLIC_FIELD = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
11013
+ /**
11014
+ * Fields that are never a lowercased group title: v3's toggles carry no group title, and `sale_price` is v3's own
11015
+ * name for V4's price. A reserved V4 field (`price`, `brand`, `category`) is not among them: iciw's category tree is
11016
+ * titled "Category", so `category` from a link may name `product_scollection_category_hierarchy`.
11017
+ */
11018
+ const $929d1037ed236371$var$NEVER_A_TITLE = new Set(["in_stock", "on_sale", "sale_price"]);
11019
+ /** fi's enriched colour fields: their values are names, never a `<name>;#<hex>` composite. */
11020
+ const $929d1037ed236371$var$FI_COLOUR_FIELDS = new Set(["colors", "color_details"]);
11021
+ /** The colour template's field, which indexes the composite itself. */
11022
+ const $929d1037ed236371$var$V3_TEMPLATE_COLOUR = "color_with_hex_list";
11023
+ /** Legacy's colour pill composite suffix (`Green;#9ea386`). */
11024
+ const $929d1037ed236371$var$HEX_SUFFIX = /;#[0-9a-fA-F]{3,8}\s*$/;
11025
+ const $929d1037ed236371$var$NUMERIC = /^-?\d+(\.\d+)?$/;
11026
+ /** realtime's separator between the levels of a hierarchical facet value (`Shop # Woman`). */
11027
+ const $929d1037ed236371$var$HIERARCHY_SEPARATOR = " # ";
11028
+ /** The features realtime's category tree is built on. */
11029
+ const $929d1037ed236371$var$CATEGORY_TREE_FIELDS = new Set(["product_category_hierarchy", "product_scollection_category_hierarchy"]);
11030
+ /** V4's public name for the discount template's field (realtime `v4/worker/src/search/fields.ts`). */
11031
+ const $929d1037ed236371$var$DISCOUNT_FIELD = "discount";
11032
+ /** The fields of V4's toggle facets (the `on_sale` and `in_stock` templates). */
11033
+ const $929d1037ed236371$var$V3_TOGGLES = new Set(["on_sale", "in_stock"]);
11034
+ class $929d1037ed236371$export$8d488bcc71d07ffb {
11035
+ #by_key = new Map();
11036
+ /** Adds the facets of one browse response. */
11037
+ learn_(facets) {
11038
+ for (const facet of facets ?? []) {
11039
+ const info = {
11040
+ field_: facet.field,
11041
+ checkbox_: facet.type === "checkbox" && !$929d1037ed236371$var$is_toggle(facet),
11042
+ colour_: $929d1037ed236371$var$FI_COLOUR_FIELDS.has(facet.field) || facet.type === "swatch" && facet.field !== $929d1037ed236371$var$V3_TEMPLATE_COLOUR
11043
+ };
11044
+ this.#by_key.set(facet.field, info);
11045
+ const v3_field = $929d1037ed236371$var$V3_FIELD[facet.field];
11046
+ if (v3_field) this.#by_key.set(v3_field, info);
11047
+ if (facet.title) this.#by_key.set(facet.title.toLowerCase(), info);
11048
+ }
11049
+ }
11050
+ /** The field a v3 filter field names, when a served facet has it as its field or its title. */
11051
+ get_(field) {
11052
+ const bare = field.replace(/#$/, "");
11053
+ const direct = this.#by_key.get(bare);
11054
+ if (direct) return direct;
11055
+ let wanted;
11056
+ try {
11057
+ wanted = decodeURIComponent(bare).toLowerCase();
11058
+ } catch {
11059
+ wanted = bare.toLowerCase();
11060
+ }
11061
+ return this.#by_key.get(wanted);
11062
+ }
11063
+ }
11064
+ function $929d1037ed236371$export$3b6ba2422a5e0aa0(field, index) {
11065
+ return !!index.get_(field) || $929d1037ed236371$var$NEVER_A_TITLE.has(field.replace(/#$/, ""));
11066
+ }
11067
+ function $929d1037ed236371$var$is_empty(data) {
11068
+ return data === undefined || data === null || data === "" || Array.isArray(data) && !data.length;
11069
+ }
11070
+ function $929d1037ed236371$var$literal(value, field) {
11071
+ const text = String(value);
11072
+ if (text.includes("`")) throw new $929d1037ed236371$export$f5ea4d073ddb4bdb(`filters: a value of ${field} contains a backtick`);
11073
+ // A boolean-looking string is written bare, as realtime's filter writer does for every field.
11074
+ if (/^(true|True|false|False)$/.test(text)) return text.toLowerCase();
11075
+ if (field === "price" && $929d1037ed236371$var$NUMERIC.test(text)) return text;
11076
+ return typeof value === "string" ? `\`${text}\`` : text;
11077
+ }
11078
+ function $929d1037ed236371$var$lax_number(value) {
11079
+ if (typeof value === "number") return value;
11080
+ if (typeof value !== "string" || value.trim() === "") return undefined;
11081
+ const number = Number(value);
11082
+ return Number.isFinite(number) ? number : undefined;
11083
+ }
11084
+ function $929d1037ed236371$export$c17bb5d2ead3e8f3(filter, index) {
11085
+ if ($929d1037ed236371$var$is_empty(filter.data)) return undefined;
11086
+ const info = index.get_(filter.field);
11087
+ const bare = filter.field.replace(/#$/, "");
11088
+ const field = info?.field_ ?? $929d1037ed236371$var$V4_FIELD[bare] ?? bare;
11089
+ if (!$929d1037ed236371$var$PUBLIC_FIELD.test(field)) throw new $929d1037ed236371$export$f5ea4d073ddb4bdb(`Invalid filter field \`${filter.field}\``);
11090
+ const clause = text => ({
11091
+ field_: field,
11092
+ clause_: text
11093
+ });
11094
+ const colour = $929d1037ed236371$var$FI_COLOUR_FIELDS.has(field) || !!info?.colour_;
11095
+ const data = filter.data;
11096
+ const values = (Array.isArray(data) ? data : [data]).map(value => !Array.isArray(value) ? colour && typeof value === "string" ? value.replace($929d1037ed236371$var$HEX_SUFFIX, "").trim() || value : value : field === "category" ? value[value.length - 1] : value.map(String).join($929d1037ed236371$var$HIERARCHY_SEPARATOR));
11097
+ const list = () => `[${values.map(value => $929d1037ed236371$var$literal(value, field)).join(",")}]`;
11098
+ // V4's discount filter (the discount template's "X% or more" radio) is a threshold, so `in` or `eq` on it means
11099
+ // "this discount or more", as on the facade since realtime#2181: a link with no operator decodes as `in`, and a
11100
+ // shop may send `in ["0.2"]` itself. Several values take the largest, as `geq` does.
11101
+ const op = (filter.op === "in" || filter.op === "eq") && field === $929d1037ed236371$var$DISCOUNT_FIELD ? "geq" : filter.op;
11102
+ // A configured checkbox keeps in/nin; every other op on it becomes in.
11103
+ if (op !== "in" && op !== "nin" && info?.checkbox_) return clause(`${field}:=${list()}`);
11104
+ const one = () => {
11105
+ if (values.length !== 1) throw new $929d1037ed236371$export$f5ea4d073ddb4bdb(`filters: ${op} takes one value`);
11106
+ return $929d1037ed236371$var$literal(values[0], field);
11107
+ };
11108
+ // A comparison takes a number, also one sent as a string; of several numbers `geq` takes the largest.
11109
+ const bound = () => {
11110
+ const numbers = values.map(value => typeof value === "number" || typeof value === "string" && $929d1037ed236371$var$NUMERIC.test(value) ? Number(value) : undefined);
11111
+ if (numbers.length === 0 || numbers.some(number => number === undefined)) return one();
11112
+ if (numbers.length > 1 && op !== "geq") return one();
11113
+ return String(Math.max(...numbers));
11114
+ };
11115
+ switch (op) {
11116
+ case "eq":
11117
+ return clause(`${field}:=${one()}`);
11118
+ case "neq":
11119
+ return clause(`${field}:!=${one()}`);
11120
+ case "in":
11121
+ return clause(`${field}:=${list()}`);
11122
+ case "nin":
11123
+ return clause(`${field}:!=${list()}`);
11124
+ case "leq":
11125
+ return clause(`${field}:<=${bound()}`);
11126
+ case "geq":
11127
+ return clause(`${field}:>=${bound()}`);
11128
+ case "inrange":
11129
+ {
11130
+ const [min, max] = values.map($929d1037ed236371$var$lax_number);
11131
+ if (min === undefined || max === undefined || values.length !== 2) throw new $929d1037ed236371$export$f5ea4d073ddb4bdb("filters: inrange takes [min, max]");
11132
+ return clause(`${field}:[${min}..${max}]`);
11133
+ }
11134
+ default:
11135
+ throw new $929d1037ed236371$export$f5ea4d073ddb4bdb(`filters: unknown op ${op}`);
11136
+ }
11137
+ }
11138
+ function $929d1037ed236371$export$407f30f25da13cc7(filters, index) {
11139
+ const clauses = filters.flatMap(filter => $929d1037ed236371$export$c17bb5d2ead3e8f3(filter, index)?.clause_ ?? []);
11140
+ return clauses.length ? clauses.join(" && ") : undefined;
11141
+ }
11142
+ function $929d1037ed236371$export$c38de645260a41ed(error, clauses) {
11143
+ if (!error || !clauses.length) return [];
11144
+ const named = (error.message ?? "").match(/"([A-Za-z0-9_.-]+)/)?.[1];
11145
+ if (error.code === "unknown_filter_field") {
11146
+ if (error.allowed) {
11147
+ const allowed = new Set(error.allowed);
11148
+ return clauses.filter(clause => !allowed.has(clause.field_));
11149
+ }
11150
+ return clauses.filter(clause => clause.field_ === named);
11151
+ }
11152
+ if (error.code === "invalid_filter") {
11153
+ const on_field = clauses.filter(clause => clause.field_ === named);
11154
+ return on_field.length ? on_field : [...clauses];
11155
+ }
11156
+ return [];
11157
+ }
11158
+ function $929d1037ed236371$export$78eb8e636d89ff30(sort) {
11159
+ if (!sort || sort.field === "_relevance") return undefined;
11160
+ return {
11161
+ field: $929d1037ed236371$var$V4_SORT[sort.field] ?? sort.field,
11162
+ order: sort.order
11163
+ };
11164
+ }
11165
+ function $929d1037ed236371$export$cd08b64be5110ce2(sorts) {
11166
+ return sorts.map(sort => ({
11167
+ field: $929d1037ed236371$var$V3_SORT[sort.field] ?? sort.field,
11168
+ order: sort.order,
11169
+ meta: {
11170
+ title: sort.title,
11171
+ values: [sort.order],
11172
+ names: [sort.title]
11173
+ }
11174
+ }));
11175
+ }
11176
+ const $929d1037ed236371$var$V3_VALUES_TYPE = {
11177
+ checkbox: "checkbox",
11178
+ radio: "radio",
11179
+ swatch: "checkbox-color",
11180
+ hierarchy: "checkbox-hierarchical",
11181
+ grid: "checkbox-grid"
11182
+ };
11183
+ /** A toggle is a template facet's one `true` value. */
11184
+ function $929d1037ed236371$var$is_toggle(facet) {
11185
+ return $929d1037ed236371$var$V3_TOGGLES.has(facet.field) && facet.type === "checkbox" && facet.values.length === 1 && facet.values[0].value === "true";
11186
+ }
11187
+ function $929d1037ed236371$var$category_path(value) {
11188
+ return value.split("#").map(level => level.trim()).filter(Boolean);
11189
+ }
11190
+ function $929d1037ed236371$export$da9af372695714ef(facets, currency) {
11191
+ return facets.filter(facet => facet.type === "range" || facet.values.length > 0).map(facet => {
11192
+ const field = $929d1037ed236371$var$V3_FIELD[facet.field] ?? facet.field;
11193
+ if (facet.type === "range") return {
11194
+ field: field,
11195
+ op: "inrange",
11196
+ data: [facet.min, facet.max],
11197
+ meta: {
11198
+ group_title: facet.title,
11199
+ type: "range",
11200
+ min: facet.min,
11201
+ max: facet.max,
11202
+ ...(facet.field === "price" && currency ? {
11203
+ currency: currency
11204
+ } : {})
11205
+ },
11206
+ id: `${field}1`
11207
+ };
11208
+ const hierarchy = facet.type === "hierarchy";
11209
+ const path = value => $929d1037ed236371$var$CATEGORY_TREE_FIELDS.has(facet.field) ? $929d1037ed236371$var$category_path(value) : value.split($929d1037ed236371$var$HIERARCHY_SEPARATOR);
11210
+ if ($929d1037ed236371$var$is_toggle(facet)) return {
11211
+ field: field,
11212
+ op: "eq",
11213
+ meta: {
11214
+ type: "checkbox",
11215
+ values: facet.values.map(value => value.value),
11216
+ counts: facet.values.map(value => value.count),
11217
+ names: facet.values.map(value => value.label)
11218
+ },
11219
+ id: `${field}1`
11220
+ };
11221
+ // Two spellings of one category path are one row in the tree.
11222
+ const seen = new Set();
11223
+ const values = $929d1037ed236371$var$CATEGORY_TREE_FIELDS.has(facet.field) ? facet.values.filter(({
11224
+ value: value
11225
+ }) => {
11226
+ const levels = path(value);
11227
+ const key = JSON.stringify(levels);
11228
+ if (levels.length === 0 || seen.has(key)) return false;
11229
+ seen.add(key);
11230
+ return true;
11231
+ }) : facet.values;
11232
+ return {
11233
+ field: field,
11234
+ op: facet.field === "discount" ? "geq" : "in",
11235
+ meta: {
11236
+ group_title: facet.title,
11237
+ type: $929d1037ed236371$var$V3_VALUES_TYPE[facet.type] ?? "checkbox",
11238
+ values: values.map(value => hierarchy ? path(value.value) : value.value),
11239
+ counts: values.map(value => value.count),
11240
+ names: values.map(value => hierarchy ? path(value.value).slice(-1)[0] : value.label),
11241
+ // The colour template sends swatches only with one to paint; a colour filter always sends them.
11242
+ ...(facet.type === "swatch" && (facet.field !== $929d1037ed236371$var$V3_TEMPLATE_COLOUR || facet.values.some(value => value.swatch)) ? {
11243
+ swatches: facet.values.map(value => value.swatch ?? null)
11244
+ } : {})
11245
+ },
11246
+ id: `${field}1`
11247
+ };
11248
+ });
11249
+ }
11250
+ function $929d1037ed236371$export$b84a41a5163c4fce(content) {
11251
+ return content.map(hit => ({
11252
+ type: "content_link",
11253
+ title: hit.title,
11254
+ ...(hit.description !== undefined ? {
11255
+ description: hit.description
11256
+ } : {}),
11257
+ ...(hit.image_url !== undefined ? {
11258
+ image_url: hit.image_url
11259
+ } : {}),
11260
+ page_url: hit.url,
11261
+ highlights: hit.highlights ?? []
11262
+ }));
11263
+ }
11264
+ function $a85aaf1b38f3c6f0$export$efb7dd882d411dd4(response, door, offset) {
11265
+ const tracking_key = door === "search" ? "search_result_id" : "product_listing_result_id";
11266
+ return {
11267
+ n_hits: response.total ?? offset + response.products.length,
11268
+ sorts: $929d1037ed236371$export$cd08b64be5110ce2(response.sorts ?? []),
11269
+ filters: $929d1037ed236371$export$da9af372695714ef(response.facets ?? [], response.currency),
11270
+ ...(door === "search" ? {
11271
+ search_request_id: response.request_id,
11272
+ content_search_links: $929d1037ed236371$export$b84a41a5163c4fce(response.content ?? []),
11273
+ is_fallback: null
11274
+ } : {
11275
+ product_listing_request_id: response.request_id
11276
+ }),
11277
+ ...(response.cursor !== undefined ? {
11278
+ cursor: response.cursor
11279
+ } : {}),
11280
+ displays: response.products.map(product => $bb0caa66ae094e38$export$7abfb7bc025aaea8(product, tracking_key))
11281
+ };
11282
+ }
11283
+ function $a85aaf1b38f3c6f0$var$listing_ref_to_v3(ref, listing_type, show) {
11284
+ return {
11285
+ listing_id: ref.id,
11286
+ ...(ref.external_id !== undefined ? {
11287
+ external_id: ref.external_id
11288
+ } : {}),
11289
+ listing_type: listing_type,
11290
+ ...show,
11291
+ image_urls: [],
11292
+ title: ref.title,
11293
+ ...(ref.slug !== undefined ? {
11294
+ slug: ref.slug
11295
+ } : {})
11296
+ };
11297
+ }
11298
+ function $a85aaf1b38f3c6f0$export$996f2b1e66d9b5af(listing) {
11299
+ const listing_type = listing.type;
11300
+ const quick_links_are_siblings = listing.quick_links.some(link => link.id === listing.id);
11301
+ const quick_links = listing.quick_links.map(link => $a85aaf1b38f3c6f0$var$listing_ref_to_v3(link, listing_type, {
11302
+ show_in_breadcrumbs: true,
11303
+ show_in_quicklinks: true
11304
+ }));
11305
+ return {
11306
+ listing_id: listing.id,
11307
+ ...(listing.external_id !== undefined ? {
11308
+ external_id: listing.external_id
11309
+ } : {}),
11310
+ listing_type: listing_type,
11311
+ show_in_breadcrumbs: listing.show_in_breadcrumbs,
11312
+ show_in_quicklinks: true,
11313
+ image_urls: listing.images,
11314
+ title: listing.title,
11315
+ ...(listing.slug !== undefined ? {
11316
+ slug: listing.slug
11317
+ } : {}),
11318
+ ancestors: listing.breadcrumbs.map(ref => $a85aaf1b38f3c6f0$var$listing_ref_to_v3(ref, "category", {
11319
+ show_in_breadcrumbs: true,
11320
+ show_in_quicklinks: true
11321
+ })),
11322
+ siblings: quick_links_are_siblings ? quick_links : [],
11323
+ children: quick_links_are_siblings ? [] : quick_links,
11324
+ content_blocks: listing.content_blocks
11325
+ };
11326
+ }
11327
+ function $a85aaf1b38f3c6f0$export$76d96892da63b395(tree) {
11328
+ const by_id = new Map();
11329
+ const walk = (nodes, chain) => {
11330
+ for (const node of nodes) {
11331
+ if (!by_id.has(node.id)) by_id.set(node.id, chain);
11332
+ walk(node.children, [...chain, $a85aaf1b38f3c6f0$var$listing_ref_to_v3(node, node.type, {
11333
+ show_in_breadcrumbs: true,
11334
+ show_in_quicklinks: true
11335
+ })]);
11336
+ }
11337
+ };
11338
+ walk(tree, []);
11339
+ return listing_id => by_id.get(listing_id);
11340
+ }
11341
+ function $a85aaf1b38f3c6f0$export$2860125b419015f8(response, ancestors_of) {
11342
+ return {
11343
+ suggestions_request_id: response.request_id,
11344
+ suggestions: response.suggestions.map(suggestion => {
11345
+ if (suggestion.type === "query") return {
11346
+ type: "query",
11347
+ query: suggestion.query,
11348
+ suggestions_result_id: ""
11349
+ };
11350
+ const from_tree = ancestors_of?.(suggestion.listing.id);
11351
+ const ancestors = from_tree && $a85aaf1b38f3c6f0$var$same_titles(from_tree, suggestion.path) ? from_tree : [];
11352
+ return {
11353
+ type: "listing",
11354
+ listing_id: suggestion.listing.id,
11355
+ ...(suggestion.listing.external_id !== undefined ? {
11356
+ external_id: suggestion.listing.external_id
11357
+ } : {}),
11358
+ listing_type: suggestion.listing.type,
11359
+ show_in_breadcrumbs: true,
11360
+ show_in_quicklinks: true,
11361
+ image_urls: suggestion.listing.images,
11362
+ title: suggestion.listing.title,
11363
+ ...(suggestion.listing.slug !== undefined ? {
11364
+ slug: suggestion.listing.slug
11365
+ } : {}),
11366
+ suggestions_result_id: "",
11367
+ ancestors: ancestors
11368
+ };
11369
+ })
11370
+ };
11371
+ }
11372
+ const $a85aaf1b38f3c6f0$var$same_titles = (ancestors, path) => ancestors.length === path.length && ancestors.every((ancestor, index) => ancestor.title === path[index]);
11373
+ /** `encodeURIComponent`, as V4's own encoder writes a value (`+` would mean a space). */
11374
+ const $a85aaf1b38f3c6f0$var$encode = value => encodeURIComponent(value);
11375
+ function $a85aaf1b38f3c6f0$export$7659319cdb555579(request) {
11376
+ const pairs = [`market=${$a85aaf1b38f3c6f0$var$encode(request.market)}`];
11377
+ const add = (key, value) => value !== undefined && pairs.push(`${key}=${value}`);
11378
+ add("locale", request.locale === undefined ? undefined : $a85aaf1b38f3c6f0$var$encode(request.locale));
11379
+ add("query", request.query === undefined ? undefined : $a85aaf1b38f3c6f0$var$encode(request.query));
11380
+ if (request.listing && "id" in request.listing) add("listing", $a85aaf1b38f3c6f0$var$encode(request.listing.id));else if (request.listing) add("listing_external_id", $a85aaf1b38f3c6f0$var$encode(request.listing.external_id));
11381
+ add("filter_by", request.filter_by === undefined ? undefined : $a85aaf1b38f3c6f0$var$encode(request.filter_by));
11382
+ if (request.sort) add("sort", `${$a85aaf1b38f3c6f0$var$encode(request.sort.field)}.${request.sort.order}`);
11383
+ add("include", request.include?.join(","));
11384
+ add("cursor", request.cursor);
11385
+ add("limit", request.limit === undefined ? undefined : String(request.limit));
11386
+ return pairs.join("&");
11387
+ }
11388
+ function $a85aaf1b38f3c6f0$export$fec3e4b5adfcea2c(params) {
11389
+ return params.filter(pair => pair[1] !== undefined).map(([key, value]) => `${key}=${$a85aaf1b38f3c6f0$var$encode(value)}`).join("&");
11390
+ }
11391
+ function $a85aaf1b38f3c6f0$export$eb90c08da400512d(locale) {
11392
+ return locale ? locale.replace(/_/g, "-") : undefined;
11393
+ }
11394
+
11395
+ /** realtime's related search page: the hits related recommendations anchor on and never repeat. */
11396
+ const $8e175fb7c533c600$var$RELATED_SEARCH_PAGE = 100;
11397
+ const $8e175fb7c533c600$var$get_recommendations = (merchant, request) => $c6c537571dbf3c03$export$88d793e3827f3436($c6c537571dbf3c03$export$b6dad15503f66988(merchant, "/recommendations") + "?" + $6387a5d45d50694e$export$fc756666ac777d0(request));
11398
+ const $8e175fb7c533c600$var$to_displays = products => products.map(product => $bb0caa66ae094e38$export$7abfb7bc025aaea8(product, "recommendation_id"));
11399
+ async function $8e175fb7c533c600$export$656ee5c46d5d1eda(call) {
11400
+ const {
11401
+ merchant: merchant
11402
+ } = call;
11403
+ const types = await $5e86c304f21e41a8$export$869eb14d6f85ac51(merchant);
11404
+ const inputs = types?.get(call.type);
11405
+ if (types && !inputs) {
11406
+ $i7OB2$dwarn(`[NativeDepictAPI] V4 serves ${merchant} no recommendation type "${call.type}"; known:`, [...types.keys()]);
11407
+ return [];
11408
+ }
11409
+ const request = $6387a5d45d50694e$export$17493dc1a89b34e6({
11410
+ ...call,
11411
+ locale: $a85aaf1b38f3c6f0$export$eb90c08da400512d(call.locale)
11412
+ }, inputs, inputs?.includes("recent_views") ? $6db5e630baf4072a$export$2d7138f47b625a04(merchant) : []);
11413
+ if (!request) return [];
11414
+ const response = await $8e175fb7c533c600$var$get_recommendations(merchant, request);
11415
+ if (!response) return [];
11416
+ const anchor = response.used_inputs?.anchor;
11417
+ if (call.productId && anchor?.type === "product") $6db5e630baf4072a$export$6379943de8f8af08(merchant, anchor.id);
11418
+ return $8e175fb7c533c600$var$to_displays(response.products);
11419
+ }
11420
+ async function $8e175fb7c533c600$export$bd5f8a7d3e47a43d(call) {
11421
+ const {
11422
+ merchant: merchant,
11423
+ market: market
11424
+ } = call;
11425
+ const types = await $5e86c304f21e41a8$export$869eb14d6f85ac51(merchant);
11426
+ if (!types) return undefined;
11427
+ const type = types.get("search")?.includes("anchor") ? "search" : types.get("similar")?.includes("anchor") ? "similar" : undefined;
11428
+ if (!type) {
11429
+ $i7OB2$dwarn(`[NativeDepictAPI] V4 serves ${merchant} no search or similar recommendations for related products`);
11430
+ return [];
11431
+ }
11432
+ const locale = $a85aaf1b38f3c6f0$export$eb90c08da400512d(call.locale);
11433
+ const query = call.query?.trim() || undefined;
11434
+ const searched = await $c6c537571dbf3c03$export$88d793e3827f3436($c6c537571dbf3c03$export$b6dad15503f66988(merchant, "/browse") + "?" + $a85aaf1b38f3c6f0$export$7659319cdb555579({
11435
+ market: market,
11436
+ ...(locale ? {
11437
+ locale: locale
11438
+ } : {}),
11439
+ ...(query ? {
11440
+ query: query
11441
+ } : {}),
11442
+ limit: $8e175fb7c533c600$var$RELATED_SEARCH_PAGE
11443
+ }));
11444
+ if (!searched) return undefined;
11445
+ const asked = $6387a5d45d50694e$export$afe6aeae61a7aa58(searched.products, {
11446
+ market: market,
11447
+ ...(locale ? {
11448
+ locale: locale
11449
+ } : {})
11450
+ }, type);
11451
+ if (!asked.length) return [];
11452
+ const answers = await Promise.all(asked.map(request => $8e175fb7c533c600$var$get_recommendations(merchant, request)));
11453
+ const lists = answers.filter(answer => !!answer).map(answer => answer.products);
11454
+ if (!lists.length) return undefined;
11455
+ const products = lists.length > 1 ? $6387a5d45d50694e$export$9af50be6508dcd00(lists, Math.max(...lists.map(list => list.length))) : lists[0];
11456
+ return $8e175fb7c533c600$var$to_displays(products);
11457
+ }
10677
11458
  async function $a0f0e923bad68a9b$export$58e808b1db15d3bc(options) {
11459
+ if (options.api === "v4") return await $a0f0e923bad68a9b$var$fetch_native(options);
10678
11460
  const headers = options.headers;
10679
11461
  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
10680
11462
  const cleaned_up_options = $i7OB2$snakeCasifyObject(options);
10681
11463
  delete cleaned_up_options.headers;
10682
11464
  delete cleaned_up_options.product_id;
11465
+ delete cleaned_up_options.api;
10683
11466
  cleaned_up_options.session_id ||= $i7OB2$get_session_id();
10684
11467
  if (product_id && !cleaned_up_options.product_ids) cleaned_up_options.product_ids = [product_id];
10685
11468
  const options_to_send = cleaned_up_options;
@@ -10701,6 +11484,33 @@ async function $a0f0e923bad68a9b$export$58e808b1db15d3bc(options) {
10701
11484
  return decoded?.displays || [];
10702
11485
  });
10703
11486
  }
11487
+ async function $a0f0e923bad68a9b$var$fetch_native(options) {
11488
+ const {
11489
+ merchant: merchant,
11490
+ market: market,
11491
+ locale: locale,
11492
+ type: type,
11493
+ headers: headers,
11494
+ categoryId: categoryId,
11495
+ productIds: productIds
11496
+ } = options;
11497
+ if (headers) $i7OB2$dwarn("fetchDepictRecommendations: headers aren't sent to the native V4 API", headers);
11498
+ try {
11499
+ return await $8e175fb7c533c600$export$656ee5c46d5d1eda({
11500
+ merchant: merchant,
11501
+ market: market,
11502
+ locale: locale,
11503
+ type: type,
11504
+ categoryId: categoryId,
11505
+ productId: options.productId || options.product_id,
11506
+ productIds: productIds,
11507
+ limit: options.limit
11508
+ });
11509
+ } catch (e) {
11510
+ $i7OB2$dlog("fetch_native_recommendations threw", e);
11511
+ return [];
11512
+ }
11513
+ }
10704
11514
  var $a6e23a834336fc19$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>"];
10705
11515
  const $a6e23a834336fc19$export$824dde41348efed1 = /*@__PURE__*/(() => {
10706
11516
  const actual_function = ({
@@ -11087,7 +11897,10 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11087
11897
  input_req_: input_req_,
11088
11898
  fallback_response_: fallback_response_,
11089
11899
  method_ = "POST",
11090
- currentListingForTransformer_: currentListingForTransformer_
11900
+ currentListingForTransformer_: currentListingForTransformer_,
11901
+ kind_: kind_,
11902
+ id_to_query_for_: id_to_query_for_,
11903
+ id_type_: id_type_
11091
11904
  }) {
11092
11905
  const cache_obj = this.#get_cache_obj_for_endpoint(endpoint_);
11093
11906
  const with_ids = this.#add_ids_to_request(input_req_);
@@ -11104,19 +11917,19 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11104
11917
  let resolve_in_progress;
11105
11918
  cache_obj.in_progress_[body] = new Promise(r => resolve_in_progress = r);
11106
11919
  try {
11107
- const is_post = method_ === "POST";
11108
- const url_to_request = is_post ? endpoint_ : $i7OB2$make_url_with_query_params(endpoint_, sorted_request);
11109
- const api_response = await $i7OB2$fetch_retry($i7OB2$add_version_query_params(url_to_request), {
11110
- method: method_,
11111
- ...(is_post ? {
11112
- body: body
11113
- } : {})
11114
- });
11115
11920
  return_successfully: {
11116
- if (!api_response || api_response.status !== 200) break return_successfully;
11117
11921
  let result;
11118
11922
  try {
11119
- const unmodified_result = await api_response.json();
11923
+ const unmodified_result = await this.request_raw_({
11924
+ kind_: kind_,
11925
+ endpoint_: endpoint_,
11926
+ method_: method_,
11927
+ request_: sorted_request,
11928
+ body_: body,
11929
+ id_to_query_for_: id_to_query_for_,
11930
+ id_type_: id_type_
11931
+ });
11932
+ if (unmodified_result === undefined) break return_successfully;
11120
11933
  result = await this.#run_display_transformers_for_rest(input_req_.merchant, input_req_.market, input_req_.locale, unmodified_result, currentListingForTransformer_);
11121
11934
  } catch (e) {
11122
11935
  $i7OB2$dwarn("displayTransformer or json decoding failed", e);
@@ -11144,6 +11957,29 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11144
11957
  delete cache_obj.in_progress_[body];
11145
11958
  }
11146
11959
  }
11960
+ /**
11961
+ * The network step of every read: sends `call` to the v3 API and returns the decoded JSON, or undefined when the
11962
+ * request failed. NativeDepictAPI overrides this to read the native V4 API instead and map its answers to v3 shapes,
11963
+ * so caching, display transformers and fallbacks stay the same for both.
11964
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11965
+ async request_raw_(call) {
11966
+ const {
11967
+ endpoint_: endpoint_,
11968
+ method_: method_,
11969
+ request_: request_,
11970
+ body_: body_
11971
+ } = call;
11972
+ const is_post = method_ === "POST";
11973
+ const url_to_request = is_post ? endpoint_ : $i7OB2$make_url_with_query_params(endpoint_, request_);
11974
+ const api_response = await $i7OB2$fetch_retry($i7OB2$add_version_query_params(url_to_request), {
11975
+ method: method_,
11976
+ ...(is_post ? {
11977
+ body: body_
11978
+ } : {})
11979
+ });
11980
+ if (!api_response || call.kind_ !== "suggest" && api_response.status !== 200) return undefined;
11981
+ return await api_response.json();
11982
+ }
11147
11983
  constructor(options) {
11148
11984
  const {
11149
11985
  get_metadata: get_metadata,
@@ -11160,11 +11996,13 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11160
11996
  const request = metaData ? Object.assign(with_ids, {
11161
11997
  metadata: JSON.stringify(metaData)
11162
11998
  }) : with_ids;
11163
- const url = $i7OB2$make_url_with_query_params($7fa23e2a0079eca4$var$search_base_url + "suggestions", request);
11164
- const results = await $i7OB2$fetch_retry($i7OB2$add_version_query_params(url));
11165
11999
  attempt_to_return_api_response: {
11166
- if (!results) break attempt_to_return_api_response;
11167
- const decoded_json = await results.json();
12000
+ const decoded_json = await this.request_raw_({
12001
+ kind_: "suggest",
12002
+ endpoint_: $7fa23e2a0079eca4$var$search_base_url + "suggestions",
12003
+ method_: "GET",
12004
+ request_: request
12005
+ });
11168
12006
  if (!Array.isArray(decoded_json?.suggestions)) break attempt_to_return_api_response;
11169
12007
  try {
11170
12008
  return await this.#run_url_creator_for_suggest(input_req.merchant, input_req.market, input_req.locale, decoded_json);
@@ -11181,6 +12019,7 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11181
12019
  async query(input_req) {
11182
12020
  return await this.#cached_request({
11183
12021
  endpoint_: $7fa23e2a0079eca4$var$search_base_url + "results",
12022
+ kind_: "search",
11184
12023
  input_req_: input_req,
11185
12024
  fallback_response_: () => ({
11186
12025
  "n_hits": 0,
@@ -11200,6 +12039,9 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11200
12039
  return await this.#cached_request({
11201
12040
  endpoint_: $7fa23e2a0079eca4$var$v3_base_url + "listings/" + (id_type_ === $c20599a0d81d953a$export$5aae649db1b959fc ? "external_id/" : "") + encodeURIComponent(id_to_query_for_),
11202
12041
  input_req_: input_req,
12042
+ kind_: "listing",
12043
+ id_to_query_for_: id_to_query_for_,
12044
+ id_type_: id_type_,
11203
12045
  fallback_response_: () => ({
11204
12046
  listing_id: "",
11205
12047
  listing_type: "category",
@@ -11226,6 +12068,9 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11226
12068
  endpoint_: $7fa23e2a0079eca4$var$v3_base_url + "listings/" + (id_type_ === $c20599a0d81d953a$export$5aae649db1b959fc ? "external_id/" : "") + encodeURIComponent(id_to_query_for_) + "/products",
11227
12069
  input_req_: input_req_,
11228
12070
  currentListingForTransformer_: currentListingForTransformer_,
12071
+ kind_: "listing_products",
12072
+ id_to_query_for_: id_to_query_for_,
12073
+ id_type_: id_type_,
11229
12074
  fallback_response_: () => ({
11230
12075
  "n_hits": 0,
11231
12076
  "displays": [],
@@ -11239,6 +12084,7 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11239
12084
  async get_recommended(input_req) {
11240
12085
  return await this.#cached_request({
11241
12086
  endpoint_: $7fa23e2a0079eca4$var$search_base_url + "related",
12087
+ kind_: "related",
11242
12088
  input_req_: input_req,
11243
12089
  fallback_response_: () => ({
11244
12090
  displays: []
@@ -11246,6 +12092,228 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
11246
12092
  });
11247
12093
  }
11248
12094
  }
12095
+
12096
+ /** V4 browse's largest page; a bigger v3 page is V4's pages chained by their cursors, as the facade does. */
12097
+ const $890cbbfc01f1e100$var$BROWSE_MAX_LIMIT = 100;
12098
+ /** V4 browse's page size without a limit, and v3's. */
12099
+ const $890cbbfc01f1e100$var$DEFAULT_LIMIT = 24;
12100
+ /** A query with no letter or digit browses the catalogue instead of returning an empty grid, as on v3. */
12101
+ const $890cbbfc01f1e100$var$HAS_LETTER_OR_DIGIT = /[\p{L}\p{N}]/u;
12102
+ class $890cbbfc01f1e100$export$721afe49a594bed extends (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3) {
12103
+ /** Facets served so far, per merchant, market and locale, to resolve v3 filter fields (group titles) to V4 fields. */#facet_indices = new Map();
12104
+ /** Browses whose facets were read only to resolve filter fields, so each is read at most once. */
12105
+ #learned = new Set();
12106
+ /** How many products came before each cursor V4 handed out, for the lower-bound count when `total` is absent. */
12107
+ #cursor_offsets = new Map();
12108
+ /** Each listing's ancestors from the listing tree, per merchant, market and locale, read once a page load. */
12109
+ #ancestor_lookups = new Map();
12110
+ /** Filter clauses V4 refused (`unknown_filter_field`, `invalid_filter`), per merchant, market and locale. */
12111
+ #rejected = new Map();
12112
+ constructor(options) {
12113
+ super(options);
12114
+ $i7OB2$set_event_api("v4");
12115
+ }
12116
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12117
+ async request_raw_(call) {
12118
+ switch (call.kind_) {
12119
+ case "search":
12120
+ return await this.#browse("search", call.request_);
12121
+ case "listing_products":
12122
+ return await this.#browse("listing", call.request_, {
12123
+ [call.id_type_ === $c20599a0d81d953a$export$5aae649db1b959fc ? "external_id" : "id"]: call.id_to_query_for_
12124
+ });
12125
+ case "listing":
12126
+ return await this.#listing(call);
12127
+ case "suggest":
12128
+ return await this.#suggest(call.request_);
12129
+ case "related":
12130
+ {
12131
+ const {
12132
+ merchant: merchant,
12133
+ market: market,
12134
+ locale: locale,
12135
+ query: query
12136
+ } = call.request_;
12137
+ const displays = await $8e175fb7c533c600$export$bd5f8a7d3e47a43d({
12138
+ merchant: merchant,
12139
+ market: market,
12140
+ locale: locale,
12141
+ query: query
12142
+ });
12143
+ return displays && {
12144
+ displays: displays
12145
+ };
12146
+ }
12147
+ }
12148
+ }
12149
+ #merchant_url(merchant, path) {
12150
+ return $c6c537571dbf3c03$export$b6dad15503f66988(merchant, path);
12151
+ }
12152
+ async #get_json(url) {
12153
+ return (await this.#get_answer(url)).body_;
12154
+ }
12155
+ /** A GET's body on a 200, else V4's error (when it sent one). */
12156
+ async #get_answer(url) {
12157
+ return await $c6c537571dbf3c03$export$f035610fd74c541a(url);
12158
+ }
12159
+ #facet_index(merchant, market, locale) {
12160
+ const key = JSON.stringify([merchant, market, locale]);
12161
+ let index = this.#facet_indices.get(key);
12162
+ if (!index) this.#facet_indices.set(key, index = new (0, $929d1037ed236371$export$8d488bcc71d07ffb)());
12163
+ return index;
12164
+ }
12165
+ async #browse_page(merchant, request) {
12166
+ return (await this.#browse_answer(merchant, request)).body_;
12167
+ }
12168
+ async #browse_answer(merchant, request) {
12169
+ return await this.#get_answer(this.#merchant_url(merchant, "/browse") + "?" + $a85aaf1b38f3c6f0$export$7659319cdb555579(request));
12170
+ }
12171
+ /** The filter clauses V4 refused, per merchant, market and locale, for this page load. */
12172
+ #rejected_clauses(merchant, market, locale) {
12173
+ const key = JSON.stringify([merchant, market, locale]);
12174
+ let rejected = this.#rejected.get(key);
12175
+ if (!rejected) this.#rejected.set(key, rejected = new Set());
12176
+ return rejected;
12177
+ }
12178
+ async #browse(door, v3_request, listing) {
12179
+ const {
12180
+ merchant: merchant,
12181
+ market: market
12182
+ } = v3_request;
12183
+ const locale = $a85aaf1b38f3c6f0$export$eb90c08da400512d(v3_request.locale);
12184
+ const query = door === "search" && v3_request.query && $890cbbfc01f1e100$var$HAS_LETTER_OR_DIGIT.test(v3_request.query) ? v3_request.query : undefined;
12185
+ const base = {
12186
+ market: market,
12187
+ ...(locale ? {
12188
+ locale: locale
12189
+ } : {}),
12190
+ ...(query ? {
12191
+ query: query
12192
+ } : {}),
12193
+ ...(listing ? {
12194
+ listing: listing
12195
+ } : {})
12196
+ };
12197
+ const index = this.#facet_index(merchant, market, locale);
12198
+ const filters = v3_request.filters ?? [];
12199
+ // depict-ui sends a filter's lowercased group title as its field. A page opened from a link with filters in it
12200
+ // comes before any facets, so read this browse's facets once to learn which field each title names.
12201
+ const learn_key = JSON.stringify([merchant, base]);
12202
+ if (filters.some(filter => filter.data != null && !$929d1037ed236371$export$3b6ba2422a5e0aa0(filter.field, index)) && !this.#learned.has(learn_key)) {
12203
+ this.#learned.add(learn_key);
12204
+ index.learn_((await this.#browse_page(merchant, {
12205
+ ...base,
12206
+ include: ["facets"],
12207
+ limit: 1
12208
+ }))?.facets);
12209
+ }
12210
+ // A filter V4 can't take must not cost the shopper the page: a link can outlive its filter (one removed from the
12211
+ // store, a hand-written value). One the adapter can't write is left out here; one V4 rejects is left out and the
12212
+ // page asked again, and remembered for this page load so later pages don't ask with it.
12213
+ const rejected = this.#rejected_clauses(merchant, market, locale);
12214
+ let clauses = [];
12215
+ for (const filter of filters) try {
12216
+ const clause = $929d1037ed236371$export$c17bb5d2ead3e8f3(filter, index);
12217
+ if (clause) clauses.push(clause);
12218
+ } catch (e) {
12219
+ if (!(e instanceof (0, $929d1037ed236371$export$f5ea4d073ddb4bdb))) throw e;
12220
+ $i7OB2$dwarn("[NativeDepictAPI] leaving out a filter V4 can't take:", e.message, filter);
12221
+ }
12222
+ clauses = clauses.filter(clause => !rejected.has(clause.clause_));
12223
+ const sort = $929d1037ed236371$export$78eb8e636d89ff30(v3_request.sort);
12224
+ const include = door === "search" ? ["facets", "sorts", "content", "attributes"] : ["facets", "sorts", "attributes"];
12225
+ const want = v3_request.limit ?? $890cbbfc01f1e100$var$DEFAULT_LIMIT;
12226
+ const offset = v3_request.cursor && this.#cursor_offsets.get(v3_request.cursor) || 0;
12227
+ const request_with = sent => ({
12228
+ ...base,
12229
+ ...(sent.length ? {
12230
+ filter_by: sent.map(clause => clause.clause_).join(" && ")
12231
+ } : {}),
12232
+ ...(sort ? {
12233
+ sort: sort
12234
+ } : {}),
12235
+ ...(v3_request.cursor ? {
12236
+ cursor: v3_request.cursor
12237
+ } : {}),
12238
+ include: include,
12239
+ ...(want !== $890cbbfc01f1e100$var$DEFAULT_LIMIT ? {
12240
+ limit: Math.min(want, $890cbbfc01f1e100$var$BROWSE_MAX_LIMIT)
12241
+ } : {})
12242
+ });
12243
+ let request = request_with(clauses);
12244
+ let answer = await this.#browse_answer(merchant, request);
12245
+ // Each retry leaves out at least one more clause, so this ends.
12246
+ while (!answer.body_) {
12247
+ const refused = $929d1037ed236371$export$c38de645260a41ed(answer.error_, clauses);
12248
+ if (!refused.length) return undefined;
12249
+ $i7OB2$dwarn("[NativeDepictAPI] leaving out filters V4 refused:", refused.map(clause => clause.clause_), answer.error_?.message);
12250
+ for (const clause of refused) rejected.add(clause.clause_);
12251
+ clauses = clauses.filter(clause => !refused.includes(clause));
12252
+ request = request_with(clauses);
12253
+ answer = await this.#browse_answer(merchant, request);
12254
+ }
12255
+ let response = answer.body_;
12256
+ // A page over V4's largest is its pages chained by their cursors; later pages ask for products alone.
12257
+ while (want > $890cbbfc01f1e100$var$BROWSE_MAX_LIMIT && response.products.length < want && response.cursor !== undefined) {
12258
+ const page = await this.#browse_page(merchant, {
12259
+ ...request,
12260
+ cursor: response.cursor,
12261
+ limit: Math.min(want - response.products.length, $890cbbfc01f1e100$var$BROWSE_MAX_LIMIT),
12262
+ include: ["attributes"]
12263
+ });
12264
+ if (!page) return undefined;
12265
+ if (!page.products.length) break;
12266
+ response = {
12267
+ ...response,
12268
+ products: [...response.products, ...page.products],
12269
+ ...(page.cursor !== undefined ? {
12270
+ cursor: page.cursor
12271
+ } : {
12272
+ cursor: undefined
12273
+ })
12274
+ };
12275
+ }
12276
+ if (response.cursor === undefined) delete response.cursor;
12277
+ index.learn_(response.facets);
12278
+ if (response.cursor !== undefined) this.#cursor_offsets.set(response.cursor, offset + response.products.length);
12279
+ return $a85aaf1b38f3c6f0$export$efb7dd882d411dd4(response, door, offset);
12280
+ }
12281
+ async #listing(call) {
12282
+ const {
12283
+ merchant: merchant,
12284
+ market: market
12285
+ } = call.request_;
12286
+ const locale = $a85aaf1b38f3c6f0$export$eb90c08da400512d(call.request_.locale);
12287
+ const by_external_id = call.id_type_ === $c20599a0d81d953a$export$5aae649db1b959fc;
12288
+ const path = by_external_id ? "/listings" : "/listings/" + encodeURIComponent(call.id_to_query_for_);
12289
+ const response = await this.#get_json(this.#merchant_url(merchant, path) + "?" + $a85aaf1b38f3c6f0$export$fec3e4b5adfcea2c([["market", market], ["locale", locale], ["external_id", by_external_id ? call.id_to_query_for_ : undefined]]));
12290
+ return response && $a85aaf1b38f3c6f0$export$996f2b1e66d9b5af(response.listing);
12291
+ }
12292
+ async #suggest(v3_request) {
12293
+ const {
12294
+ merchant: merchant,
12295
+ market: market
12296
+ } = v3_request;
12297
+ const locale = $a85aaf1b38f3c6f0$export$eb90c08da400512d(v3_request.locale);
12298
+ const response = await this.#get_json(this.#merchant_url(merchant, "/suggest") + "?" + $a85aaf1b38f3c6f0$export$fec3e4b5adfcea2c([["market", market], ["locale", locale], ["query", v3_request.query ?? ""]]));
12299
+ if (!response) return undefined;
12300
+ const needs_ancestors = response.suggestions.some(suggestion => suggestion.type === "listing" && suggestion.path.length > 0);
12301
+ return $a85aaf1b38f3c6f0$export$2860125b419015f8(response, needs_ancestors ? await this.#ancestors(merchant, market, locale) : undefined);
12302
+ }
12303
+ /** V4 suggestions name ancestors by title only; the listing tree names them by id. A failed read isn't retried. */
12304
+ #ancestors(merchant, market, locale) {
12305
+ const key = JSON.stringify([merchant, market, locale]);
12306
+ let lookup = this.#ancestor_lookups.get(key);
12307
+ if (!lookup) {
12308
+ lookup = this.#get_json(this.#merchant_url(merchant, "/listings") + "?" + $a85aaf1b38f3c6f0$export$fec3e4b5adfcea2c([["market", market], ["locale", locale]])).then(tree => tree && $a85aaf1b38f3c6f0$export$76d96892da63b395(tree.listings));
12309
+ this.#ancestor_lookups.set(key, lookup);
12310
+ }
12311
+ return lookup;
12312
+ }
12313
+ }
12314
+ function $890cbbfc01f1e100$export$6d972e6af9de09f0(version, options) {
12315
+ return version === "v4" ? new $890cbbfc01f1e100$export$721afe49a594bed(options) : new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)(options);
12316
+ }
11249
12317
  function $ccd5db07a3a069c5$export$477caf01aecaeb2a(options) {
11250
12318
  const router_ = options.router_;
11251
12319
  const search_query_url_param_name_ = "search_query_url_param_name_" in options ? options.search_query_url_param_name_ : undefined;
@@ -11496,8 +12564,9 @@ class $961b5c64bef4662f$export$f34314aa9505732e {
11496
12564
  quicklinks_signal_: $i7OB2$createSignal(),
11497
12565
  i18n_: i18n_,
11498
12566
  reset_history_state_: reset_history_state_,
12567
+ depict_api_: typeof api === "object" && api ? api :
11499
12568
  // @ts-ignore
11500
- depict_api_: api ?? new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)({
12569
+ $890cbbfc01f1e100$export$6d972e6af9de09f0(api, {
11501
12570
  display_transformers: display_transformers
11502
12571
  }),
11503
12572
  router_: this.#router,
@@ -12897,8 +13966,9 @@ class $806c97b931758897$export$ac6237957a15b3f0 {
12897
13966
  const get_search_query_ = $i7OB2$createMemo(previous_value => {
12898
13967
  if (get_search_query_updating_blocked()) return previous_value;else return raw_search_query_accessor();
12899
13968
  });
13969
+ const depict_api_ = typeof api === "object" && api ? api :
12900
13970
  // @ts-ignore
12901
- const depict_api_ = api ?? new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)({
13971
+ $890cbbfc01f1e100$export$6d972e6af9de09f0(api, {
12902
13972
  display_transformers: display_transformers
12903
13973
  });
12904
13974
  const previous_searches = $21f51c14cb3f586f$export$84bba84a7b837187(get_search_query_);
@@ -13774,4 +14844,4 @@ function $442f32a4d80abbde$export$e2bf8ce7779e827e(props) {
13774
14844
  }, "Entire CategoryPage failed");
13775
14845
  }
13776
14846
  $i7OB2$add_to_version_info("ui", (0, $ec291e0010116877$export$83d89fbfd8236492));
13777
- export { $df5d81d0fe61ff21$export$1d575f423147a8c as usePLPLayout, $a444a52bafa0dacc$export$54c6d6ff54e72743 as makeSizeAccessors, $a63fa9cb46ed211b$export$f98b8d5ea7207a1 as setExtraDisplayTransformers, $a63fa9cb46ed211b$export$b2d94be4f02525b2 as getExtraDisplayTransformers, $70bb27cc6be01fc7$export$140423fa4bfb6d63 as ModernResponsiveImage, $e7a7eb102ddc0c79$export$92aa5d691d588f3f as remap_blocks_to_index, $4eb0a704f8f30273$export$d4d96868197be50e as useMobileHover, $5e3d278ef4c80cd7$export$54299a3c81f5425 as useVisibilityState, $f32e14878e75af51$export$eaa625fb39439e37 as useSlidableInformation, $f091294da861020c$export$80bb7300ce6a8be3 as useProductCardIsVisible, $f091294da861020c$export$f223d69ed12f5fb7 as CurrentlyIntersectingContext, $24e27fab9c821b86$export$5bad61ecde080b1f as useExpandingContainerReactive, $07ef910e8ef6b783$export$2c9f9bf2092486aa as LooksSliderOrGrid, $e9d1d09be9e6471e$export$44809a8a3e867e30 as LookCard, $4fd2ba03703a7d92$export$7e1297a3a19f10d8 as PseudoRouter, $de6ccd37192b5fc2$export$83bb9af5671e1dbe as promiseSafeStructuredClone, $90980bd87c9960f9$export$5162a71f252e6122 as preserve_items_in_history_dot_state, $90980bd87c9960f9$export$3064e1e8c6513da3 as prefixes_to_preserve_in_history_dot_state, $a281666e5c15c2ec$export$29d28dadc2d6b631 as allowNativeNavigation, $66db7a014e20802e$export$1ea76ea778b880dd as modalVersionSymbol, $136f1d4d6c7ba6ac$export$e417c49320921907 as createDeparallelizedNoDropResource, $d8dbf52fea1773e2$export$f50b88e2a00918b5 as throw_globally, $42912431795f188e$export$9265e66f26f8e383 as ClassicSearchModal, $500a16dd18ee5a71$export$b0c55aa2e87c4be7 as SearchModalV2, $70bb27cc6be01fc7$export$9d4a4b669b1929ab as ModernResponsiveContainedImage, $024fbc0a2d796fad$export$3e41faf802a29e71 as Tab, $024fbc0a2d796fad$export$b2539bed5023c21c as Tabs, $8560c919ff763930$export$d4973c31938cbfd1 as ShopTheLookButton, $ca6f574bd8772184$export$e183a13865960371 as history_dot_state_to_state, $4147651646da990a$export$916e6850778505f6 as strip_encoded_filter_and_sort, $4147651646da990a$export$58aa3f171519b6d7 as encode_filters, $4147651646da990a$export$f934fa24c3a86811 as decode_filters, $4147651646da990a$export$62acb285a7579555 as encode_sorting, $4147651646da990a$export$766e9676e74997d3 as decode_sorting, $660070e2a394b3c3$export$d7b7ab832c20e2f4 as shopifyContainedImageContextSymbol, $011607bdf658f807$export$e68cff63f76bd15b as ListingProvider, $011607bdf658f807$export$8d0c4fdbb05a2f2e as useListing, $b6440e72ed83671a$export$11354f017ddc9790 as ProductCardIndexProvider, $b6440e72ed83671a$export$e3faf4d95300054f as useProductCardIndex, $660070e2a394b3c3$export$e4b984597b71e989 as ShopifyContainedImage, $f32e14878e75af51$export$6649caad96ef8870 as SlidableItems, $2449872a62a75a20$export$ebdc3711f7e02ccd as make_accurate_width_accessor, $ee116da074deb002$export$9574e176201e5e8d as RecommendationSlider, $9ea5383493360761$export$9756467d34d91cdb as RecommendationGrid, $e8ffe11ed01df0fe$export$6e5611bc7e57e477 as ShopifyResponsiveImg, $f18d425032111270$export$94026ee33dbabc26 as ImageContainer, $b7436a6d1fd64e3b$export$b69d0d92862de18b as SentryErrorBoundary, $b7436a6d1fd64e3b$export$240ecf5363d76c0f as ExtraSentryContextProvider, $6bb0a0c563dff4bb$export$6c6d7a51fa9aa15d as ExpandingDetails, $c16e74cfe125bb05$export$f091cbac892643a4 as accessor_of_object_to_object_with_accessor_values, $1adfe60f3a14a1d7$export$fecbb157621501bd as SelectedFilters, $fab07f52c9861732$export$3f1a388cc0d8fed7 as FilterBody, $5efb5894079b220e$export$b288c38ae3fddb56 as create_modified_filters, $c8d5ff4524619fcd$export$d21e32dfedac04be as SolidLayout, $c8d5ff4524619fcd$export$445d8d3f5f706a40 as SolidLayoutWithProvidedElement, $194bd6b8e4c59830$export$79b1565500412d9b as general_modal_abstraction, $19976a74d273070d$export$3b621d86b1566b2 as CrossIcon, $fbbadcb080ad1d4a$export$8be2714ec7f169ee as GenericSliderArrowButton, $a0f0e923bad68a9b$export$58e808b1db15d3bc as fetchDepictRecommendations, $e4615ecd1849548f$export$b91cec6bdc6b32a1 as CategoryTitle, $a6e23a834336fc19$export$824dde41348efed1 as embedded_num_products, $4b2134398dfa83fa$export$c1a6b039e689a58e as get_listings, $961b5c64bef4662f$export$f34314aa9505732e as DepictCategory, $806c97b931758897$export$ac6237957a15b3f0 as DepictSearch, $806c97b931758897$export$bde3eb976dfded9 as get_search_query_updating_blocked_signal, $806c97b931758897$export$f2dc7e4e4aa11abb as SearchPage, $4fd48cb976bf1789$export$aa14a9f43128f61f as ProductCardError, $6891c018a834cfdd$export$d86a33413558014e as open_modal_with_alignment, $bb15dfb548a7666e$export$ee1733d9a8495996 as DefaultInstantCardPlaceholder, $b6d5529b253681aa$export$b3ad617e9036868 as align_field, $b6d5529b253681aa$export$3f238c96c45e6cc6 as ALIGN_TOP, $b6d5529b253681aa$export$902f8b4a7dae5d78 as ALIGN_WIDTH_ON_MODAL, $b6d5529b253681aa$export$7895aadd1956b1c7 as ALIGN_LEFT, $b6d5529b253681aa$export$6060bc6bee850eb6 as SET_CENTERED_LEFT, $b5cccc8ee7d24677$export$6daf8749b65a1b77 as convert_sdk_cols_at_size_to_layout, $926b1b5ba2239356$export$1233ca167bf71f9a as styles_to_valid_css_string, $aea1edf92433e81e$export$fe334901e8bebd57 as disable_scrolling, $6e8944558258054f$export$d0596b5cae35ad4 as open_search_with_shift_slash, $7fa23e2a0079eca4$export$e015ed2f2950f2e3 as DepictAPI, $dc9262ef6f786812$export$d9f36cf74e24d595 as media_query_to_accessor, $6936724b9e0b98d5$export$689e204eadb33baf as setup_fast_leave, $bf52d9f9eebd1938$export$5196e4c01fa56fcb as show_toast, $8c0f86cb3e266eeb$export$a71e92cfbb498adc as SolidFormatPrice, $4ca91518c9a35379$export$828dcdd425fd3231 as connect_search_field_height_to_aligner_height, $d20eff0aadc28983$export$acb3eaade4b23afd as BasePlaceholder, $d134eae24341b4a1$export$89c6019e4baa40b1 as TextPlaceholder, $7f60f09116a3fe61$export$3f37af283f8fb843 as ImagePlaceholder, $753e9b2889a47c89$export$3ccaa27d81dd8556 as PageReplacer, $4690a06c8489dcd0$export$864d304a0bc46829 as defaultGridSpacing, $4690a06c8489dcd0$export$c3834fa86c616831 as defaultColsAtSize, $4690a06c8489dcd0$export$7bf543b9d9be2c22 as defaultCategoryTitlePlugin, $ec291e0010116877$export$83d89fbfd8236492 as version, $58b3487626e85ece$export$316f6f283ae64765 as SearchField, $feffae76d8dc0135$export$5b7c3ce0ebe51f86 as BreadCrumbs, $feffae76d8dc0135$export$de035477d6fef996 as QuickLinks, $442f32a4d80abbde$export$e2bf8ce7779e827e as CategoryPage };
14847
+ export { $df5d81d0fe61ff21$export$1d575f423147a8c as usePLPLayout, $a444a52bafa0dacc$export$54c6d6ff54e72743 as makeSizeAccessors, $a63fa9cb46ed211b$export$f98b8d5ea7207a1 as setExtraDisplayTransformers, $a63fa9cb46ed211b$export$b2d94be4f02525b2 as getExtraDisplayTransformers, $70bb27cc6be01fc7$export$140423fa4bfb6d63 as ModernResponsiveImage, $e7a7eb102ddc0c79$export$92aa5d691d588f3f as remap_blocks_to_index, $4eb0a704f8f30273$export$d4d96868197be50e as useMobileHover, $5e3d278ef4c80cd7$export$54299a3c81f5425 as useVisibilityState, $f32e14878e75af51$export$eaa625fb39439e37 as useSlidableInformation, $f091294da861020c$export$80bb7300ce6a8be3 as useProductCardIsVisible, $f091294da861020c$export$f223d69ed12f5fb7 as CurrentlyIntersectingContext, $24e27fab9c821b86$export$5bad61ecde080b1f as useExpandingContainerReactive, $07ef910e8ef6b783$export$2c9f9bf2092486aa as LooksSliderOrGrid, $e9d1d09be9e6471e$export$44809a8a3e867e30 as LookCard, $4fd2ba03703a7d92$export$7e1297a3a19f10d8 as PseudoRouter, $de6ccd37192b5fc2$export$83bb9af5671e1dbe as promiseSafeStructuredClone, $90980bd87c9960f9$export$5162a71f252e6122 as preserve_items_in_history_dot_state, $90980bd87c9960f9$export$3064e1e8c6513da3 as prefixes_to_preserve_in_history_dot_state, $a281666e5c15c2ec$export$29d28dadc2d6b631 as allowNativeNavigation, $66db7a014e20802e$export$1ea76ea778b880dd as modalVersionSymbol, $136f1d4d6c7ba6ac$export$e417c49320921907 as createDeparallelizedNoDropResource, $d8dbf52fea1773e2$export$f50b88e2a00918b5 as throw_globally, $42912431795f188e$export$9265e66f26f8e383 as ClassicSearchModal, $500a16dd18ee5a71$export$b0c55aa2e87c4be7 as SearchModalV2, $70bb27cc6be01fc7$export$9d4a4b669b1929ab as ModernResponsiveContainedImage, $024fbc0a2d796fad$export$3e41faf802a29e71 as Tab, $024fbc0a2d796fad$export$b2539bed5023c21c as Tabs, $8560c919ff763930$export$d4973c31938cbfd1 as ShopTheLookButton, $ca6f574bd8772184$export$e183a13865960371 as history_dot_state_to_state, $4147651646da990a$export$916e6850778505f6 as strip_encoded_filter_and_sort, $4147651646da990a$export$58aa3f171519b6d7 as encode_filters, $4147651646da990a$export$f934fa24c3a86811 as decode_filters, $4147651646da990a$export$62acb285a7579555 as encode_sorting, $4147651646da990a$export$766e9676e74997d3 as decode_sorting, $660070e2a394b3c3$export$d7b7ab832c20e2f4 as shopifyContainedImageContextSymbol, $011607bdf658f807$export$e68cff63f76bd15b as ListingProvider, $011607bdf658f807$export$8d0c4fdbb05a2f2e as useListing, $b6440e72ed83671a$export$11354f017ddc9790 as ProductCardIndexProvider, $b6440e72ed83671a$export$e3faf4d95300054f as useProductCardIndex, $660070e2a394b3c3$export$e4b984597b71e989 as ShopifyContainedImage, $f32e14878e75af51$export$6649caad96ef8870 as SlidableItems, $2449872a62a75a20$export$ebdc3711f7e02ccd as make_accurate_width_accessor, $ee116da074deb002$export$9574e176201e5e8d as RecommendationSlider, $9ea5383493360761$export$9756467d34d91cdb as RecommendationGrid, $e8ffe11ed01df0fe$export$6e5611bc7e57e477 as ShopifyResponsiveImg, $f18d425032111270$export$94026ee33dbabc26 as ImageContainer, $b7436a6d1fd64e3b$export$b69d0d92862de18b as SentryErrorBoundary, $b7436a6d1fd64e3b$export$240ecf5363d76c0f as ExtraSentryContextProvider, $6bb0a0c563dff4bb$export$6c6d7a51fa9aa15d as ExpandingDetails, $c16e74cfe125bb05$export$f091cbac892643a4 as accessor_of_object_to_object_with_accessor_values, $1adfe60f3a14a1d7$export$fecbb157621501bd as SelectedFilters, $fab07f52c9861732$export$3f1a388cc0d8fed7 as FilterBody, $5efb5894079b220e$export$b288c38ae3fddb56 as create_modified_filters, $c8d5ff4524619fcd$export$d21e32dfedac04be as SolidLayout, $c8d5ff4524619fcd$export$445d8d3f5f706a40 as SolidLayoutWithProvidedElement, $194bd6b8e4c59830$export$79b1565500412d9b as general_modal_abstraction, $19976a74d273070d$export$3b621d86b1566b2 as CrossIcon, $fbbadcb080ad1d4a$export$8be2714ec7f169ee as GenericSliderArrowButton, $a0f0e923bad68a9b$export$58e808b1db15d3bc as fetchDepictRecommendations, $e4615ecd1849548f$export$b91cec6bdc6b32a1 as CategoryTitle, $a6e23a834336fc19$export$824dde41348efed1 as embedded_num_products, $4b2134398dfa83fa$export$c1a6b039e689a58e as get_listings, $961b5c64bef4662f$export$f34314aa9505732e as DepictCategory, $806c97b931758897$export$ac6237957a15b3f0 as DepictSearch, $806c97b931758897$export$bde3eb976dfded9 as get_search_query_updating_blocked_signal, $806c97b931758897$export$f2dc7e4e4aa11abb as SearchPage, $4fd48cb976bf1789$export$aa14a9f43128f61f as ProductCardError, $6891c018a834cfdd$export$d86a33413558014e as open_modal_with_alignment, $bb15dfb548a7666e$export$ee1733d9a8495996 as DefaultInstantCardPlaceholder, $b6d5529b253681aa$export$b3ad617e9036868 as align_field, $b6d5529b253681aa$export$3f238c96c45e6cc6 as ALIGN_TOP, $b6d5529b253681aa$export$902f8b4a7dae5d78 as ALIGN_WIDTH_ON_MODAL, $b6d5529b253681aa$export$7895aadd1956b1c7 as ALIGN_LEFT, $b6d5529b253681aa$export$6060bc6bee850eb6 as SET_CENTERED_LEFT, $b5cccc8ee7d24677$export$6daf8749b65a1b77 as convert_sdk_cols_at_size_to_layout, $926b1b5ba2239356$export$1233ca167bf71f9a as styles_to_valid_css_string, $aea1edf92433e81e$export$fe334901e8bebd57 as disable_scrolling, $6e8944558258054f$export$d0596b5cae35ad4 as open_search_with_shift_slash, $7fa23e2a0079eca4$export$e015ed2f2950f2e3 as DepictAPI, $890cbbfc01f1e100$export$721afe49a594bed as NativeDepictAPI, $890cbbfc01f1e100$export$6d972e6af9de09f0 as create_depict_api, $dc9262ef6f786812$export$d9f36cf74e24d595 as media_query_to_accessor, $6936724b9e0b98d5$export$689e204eadb33baf as setup_fast_leave, $bf52d9f9eebd1938$export$5196e4c01fa56fcb as show_toast, $8c0f86cb3e266eeb$export$a71e92cfbb498adc as SolidFormatPrice, $4ca91518c9a35379$export$828dcdd425fd3231 as connect_search_field_height_to_aligner_height, $d20eff0aadc28983$export$acb3eaade4b23afd as BasePlaceholder, $d134eae24341b4a1$export$89c6019e4baa40b1 as TextPlaceholder, $7f60f09116a3fe61$export$3f37af283f8fb843 as ImagePlaceholder, $753e9b2889a47c89$export$3ccaa27d81dd8556 as PageReplacer, $4690a06c8489dcd0$export$864d304a0bc46829 as defaultGridSpacing, $4690a06c8489dcd0$export$c3834fa86c616831 as defaultColsAtSize, $4690a06c8489dcd0$export$7bf543b9d9be2c22 as defaultCategoryTitlePlugin, $ec291e0010116877$export$83d89fbfd8236492 as version, $58b3487626e85ece$export$316f6f283ae64765 as SearchField, $feffae76d8dc0135$export$5b7c3ce0ebe51f86 as BreadCrumbs, $feffae76d8dc0135$export$de035477d6fef996 as QuickLinks, $442f32a4d80abbde$export$e2bf8ce7779e827e as CategoryPage };