@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/latest/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { add_to_version_info as $9HbP8$add_to_version_info, javascript_media_query as $9HbP8$javascript_media_query, standard_price_format as $9HbP8$standard_price_format, catchify as $9HbP8$catchify1, observer as $9HbP8$observer, slider_fractional_factory as $9HbP8$slider_fractional_factory, report as $9HbP8$report1, dlog as $9HbP8$dlog, camelCasifyObject as $9HbP8$camelCasifyObject, make_random_classname as $9HbP8$make_random_classname, n_col_styling_with_dist as $9HbP8$n_col_styling_with_dist, layout_get_visible_recs_without_partial_rows as $9HbP8$layout_get_visible_recs_without_partial_rows, layout_get_total_rec_amount_for_row as $9HbP8$layout_get_total_rec_amount_for_row, layout_media_query_header as $9HbP8$layout_media_query_header, dwarn as $9HbP8$dwarn, slider_fading_factory as $9HbP8$slider_fading_factory, Amazing_Slider as $9HbP8$Amazing_Slider, slider_snap_css as $9HbP8$slider_snap_css, useExpandingContainer as $9HbP8$useExpandingContainer, hex_to_rgb as $9HbP8$hex_to_rgb, relative_luminance_from_rgb as $9HbP8$relative_luminance_from_rgb, instant_exec_on_suspect_history_change as $9HbP8$instant_exec_on_suspect_history_change, base64_encode_unicode as $9HbP8$base64_encode_unicode, base64_decode_unicode as $9HbP8$base64_decode_unicode, queueMacroTask as $9HbP8$queueMacroTask, is_debug as $9HbP8$is_debug, findMostFrequentItem as $9HbP8$findMostFrequentItem, is_available_in as $9HbP8$is_available_in, fetch_retry as $9HbP8$fetch_retry, base_url as $9HbP8$base_url, deparallelize_no_drop as $9HbP8$deparallelize_no_drop, ContainedImage as $9HbP8$ContainedImage, buildThresholdList as $9HbP8$buildThresholdList, make_asyncIterable_exiter as $9HbP8$make_asyncIterable_exiter, href_change_ipns as $9HbP8$href_change_ipns, use_href_accessor as $9HbP8$use_href_accessor1, get_session_id as $9HbP8$get_session_id, add_version_query_params as $9HbP8$add_version_query_params, snakeCasifyObject as $9HbP8$snakeCasifyObject, sort_obj as $9HbP8$sort_obj, make_url_with_query_params as $9HbP8$make_url_with_query_params, insert_surfaces as $9HbP8$insert_surfaces } from "@depict-ai/utilishared/latest";
1
+ import { add_to_version_info as $9HbP8$add_to_version_info, javascript_media_query as $9HbP8$javascript_media_query, standard_price_format as $9HbP8$standard_price_format, catchify as $9HbP8$catchify1, observer as $9HbP8$observer, slider_fractional_factory as $9HbP8$slider_fractional_factory, report as $9HbP8$report1, dlog as $9HbP8$dlog, camelCasifyObject as $9HbP8$camelCasifyObject, make_random_classname as $9HbP8$make_random_classname, n_col_styling_with_dist as $9HbP8$n_col_styling_with_dist, layout_get_visible_recs_without_partial_rows as $9HbP8$layout_get_visible_recs_without_partial_rows, layout_get_total_rec_amount_for_row as $9HbP8$layout_get_total_rec_amount_for_row, layout_media_query_header as $9HbP8$layout_media_query_header, dwarn as $9HbP8$dwarn, slider_fading_factory as $9HbP8$slider_fading_factory, Amazing_Slider as $9HbP8$Amazing_Slider, slider_snap_css as $9HbP8$slider_snap_css, useExpandingContainer as $9HbP8$useExpandingContainer, hex_to_rgb as $9HbP8$hex_to_rgb, relative_luminance_from_rgb as $9HbP8$relative_luminance_from_rgb, instant_exec_on_suspect_history_change as $9HbP8$instant_exec_on_suspect_history_change, base64_encode_unicode as $9HbP8$base64_encode_unicode, base64_decode_unicode as $9HbP8$base64_decode_unicode, queueMacroTask as $9HbP8$queueMacroTask, is_debug as $9HbP8$is_debug, findMostFrequentItem as $9HbP8$findMostFrequentItem, is_available_in as $9HbP8$is_available_in, fetch_retry as $9HbP8$fetch_retry, base_url as $9HbP8$base_url, deparallelize_no_drop as $9HbP8$deparallelize_no_drop, ContainedImage as $9HbP8$ContainedImage, buildThresholdList as $9HbP8$buildThresholdList, make_asyncIterable_exiter as $9HbP8$make_asyncIterable_exiter, href_change_ipns as $9HbP8$href_change_ipns, use_href_accessor as $9HbP8$use_href_accessor1, get_session_id as $9HbP8$get_session_id, add_version_query_params as $9HbP8$add_version_query_params, snakeCasifyObject as $9HbP8$snakeCasifyObject, set_event_api as $9HbP8$set_event_api, sort_obj as $9HbP8$sort_obj, make_url_with_query_params as $9HbP8$make_url_with_query_params, insert_surfaces as $9HbP8$insert_surfaces } from "@depict-ai/utilishared/latest";
2
2
  import { template as $9HbP8$template, createComponent as $9HbP8$createComponent, getNextElement as $9HbP8$getNextElement, getNextMarker as $9HbP8$getNextMarker, insert as $9HbP8$insert, isServer as $9HbP8$isServer, use as $9HbP8$use, effect as $9HbP8$effect, setAttribute as $9HbP8$setAttribute, memo as $9HbP8$memo, mergeProps as $9HbP8$mergeProps1, addEventListener as $9HbP8$addEventListener, runHydrationEvents as $9HbP8$runHydrationEvents, delegateEvents as $9HbP8$delegateEvents, spread as $9HbP8$spread, classList as $9HbP8$classList, className as $9HbP8$className, style as $9HbP8$style, Dynamic as $9HbP8$Dynamic, setProperty as $9HbP8$setProperty } from "solid-js/web";
3
3
  import { createContext as $9HbP8$createContext, createSignal as $9HbP8$createSignal, getOwner as $9HbP8$getOwner, createResource as $9HbP8$createResource, untrack as $9HbP8$untrack, createRoot as $9HbP8$createRoot, createEffect as $9HbP8$createEffect, runWithOwner as $9HbP8$runWithOwner, onCleanup as $9HbP8$onCleanup, createMemo as $9HbP8$createMemo, Show as $9HbP8$Show, createComputed as $9HbP8$createComputed, createRenderEffect as $9HbP8$createRenderEffect, mergeProps as $9HbP8$mergeProps, useContext as $9HbP8$useContext, createReaction as $9HbP8$createReaction, on as $9HbP8$on, Suspense as $9HbP8$Suspense, ErrorBoundary as $9HbP8$ErrorBoundary, Index as $9HbP8$Index, For as $9HbP8$For, createUniqueId as $9HbP8$createUniqueId, mapArray as $9HbP8$mapArray, batch as $9HbP8$batch, Switch as $9HbP8$Switch, Match as $9HbP8$Match, splitProps as $9HbP8$splitProps, createComponent as $9HbP8$createComponent1, createSelector as $9HbP8$createSelector, children as $9HbP8$children } from "solid-js";
4
4
  import { catchify as $9HbP8$catchify, report as $9HbP8$report, use_href_accessor as $9HbP8$use_href_accessor, observer as $9HbP8$observer1, dlog as $9HbP8$dlog1, ListenableSet as $9HbP8$ListenableSet, queueMacroTask as $9HbP8$queueMacroTask1 } from "@depict-ai/utilishared/latest";
@@ -7,7 +7,7 @@ import { createStore as $9HbP8$createStore, reconcile as $9HbP8$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 = $9HbP8$createSignal(false);
13
13
  $9HbP8$onCleanup($9HbP8$javascript_media_query(media_query, ({
@@ -13242,12 +13242,795 @@ function $c16e74cfe125bb05$export$f091cbac892643a4(obj) {
13242
13242
  return Object.fromEntries(mapped_stuff); // FUCK TYPESCRIPT, WHY CAN'T YOU DO THIS CORRECTLY???
13243
13243
  }
13244
13244
 
13245
+ /** One try and at most two retries: a 503 burst from V4 shouldn't be multiplied by fetch_retry's default of 10. */
13246
+ const $c6c537571dbf3c03$var$NATIVE_MAX_TRIES = 3;
13247
+ function $c6c537571dbf3c03$export$b6dad15503f66988(merchant, path) {
13248
+ return `${(0, $9HbP8$base_url)}/v4/${encodeURIComponent(merchant)}${path}`;
13249
+ }
13250
+ async function $c6c537571dbf3c03$export$88d793e3827f3436(url) {
13251
+ return (await $c6c537571dbf3c03$export$f035610fd74c541a(url)).body_;
13252
+ }
13253
+ async function $c6c537571dbf3c03$export$f035610fd74c541a(url) {
13254
+ const response = await $9HbP8$fetch_retry(url, {
13255
+ method: "GET"
13256
+ }, $c6c537571dbf3c03$var$NATIVE_MAX_TRIES);
13257
+ if (!response) {
13258
+ $9HbP8$dwarn("[NativeDepictAPI] no response from", url);
13259
+ return {};
13260
+ }
13261
+ if (response.status === 200)
13262
+ // 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
13263
+ // back instead of rejecting: get_recommendation_types then forgets the read rather than keeping it in flight.
13264
+ try {
13265
+ return {
13266
+ body_: await response.json()
13267
+ };
13268
+ } catch (e) {
13269
+ $9HbP8$dwarn("[NativeDepictAPI] 200 without a JSON body from", url, e);
13270
+ return {};
13271
+ }
13272
+ let error;
13273
+ try {
13274
+ error = (await response.json()).error;
13275
+ } catch {
13276
+ // not V4's error body
13277
+ }
13278
+ $9HbP8$dwarn("[NativeDepictAPI]", response.status, error?.code, error?.message, error?.request_id, url);
13279
+ if (response.status >= 500) $9HbP8$report1([new Error(`V4 ${response.status} ${error?.code ?? ""}`), "Native V4 request failed"], "warning", {
13280
+ url: url,
13281
+ status: response.status,
13282
+ code: error?.code,
13283
+ request_id: error?.request_id ?? response.headers.get("x-depict-request-id")
13284
+ });
13285
+ return {
13286
+ error_: error
13287
+ };
13288
+ }
13289
+ const $5e86c304f21e41a8$export$8e79752841e7cdb4 = 900000;
13290
+ const $5e86c304f21e41a8$var$storage_key = merchant => `depict_v4_recommendation_types_${merchant}`;
13291
+ /** One read per merchant and CONTEXT_TTL_MS in this page; a failed read is forgotten so the next caller tries again. */
13292
+ const $5e86c304f21e41a8$var$in_flight = new Map();
13293
+ function $5e86c304f21e41a8$var$from_storage(merchant, now) {
13294
+ try {
13295
+ const stored = JSON.parse(localStorage.getItem($5e86c304f21e41a8$var$storage_key(merchant)) ?? "null");
13296
+ if (!stored || !Array.isArray(stored.types) || !(now - stored.fetched_at < $5e86c304f21e41a8$export$8e79752841e7cdb4)) return undefined;
13297
+ return $5e86c304f21e41a8$var$to_map(stored.types);
13298
+ } catch {
13299
+ return undefined;
13300
+ }
13301
+ }
13302
+ function $5e86c304f21e41a8$var$to_storage(merchant, types, now) {
13303
+ try {
13304
+ localStorage.setItem($5e86c304f21e41a8$var$storage_key(merchant), JSON.stringify({
13305
+ fetched_at: now,
13306
+ types: types
13307
+ }));
13308
+ } catch {
13309
+ // localStorage unavailable or full: read /context again on the next page.
13310
+ }
13311
+ }
13312
+ const $5e86c304f21e41a8$var$to_map = types => new Map(types.map(({
13313
+ type: type,
13314
+ inputs: inputs
13315
+ }) => [type, inputs]));
13316
+ function $5e86c304f21e41a8$export$869eb14d6f85ac51(merchant, now = Date.now()) {
13317
+ const pending = $5e86c304f21e41a8$var$in_flight.get(merchant);
13318
+ if (pending && now - pending.started_at < $5e86c304f21e41a8$export$8e79752841e7cdb4) return pending.read;
13319
+ const stored = $5e86c304f21e41a8$var$from_storage(merchant, now);
13320
+ if (stored) return Promise.resolve(stored);
13321
+ const read = $c6c537571dbf3c03$export$88d793e3827f3436($c6c537571dbf3c03$export$b6dad15503f66988(merchant, "/context")).then(context => {
13322
+ if (!context) {
13323
+ if ($5e86c304f21e41a8$var$in_flight.get(merchant)?.read === read) $5e86c304f21e41a8$var$in_flight.delete(merchant);
13324
+ return undefined;
13325
+ }
13326
+ const types = context.recommendation_types ?? [];
13327
+ $5e86c304f21e41a8$var$to_storage(merchant, types, now);
13328
+ return $5e86c304f21e41a8$var$to_map(types);
13329
+ });
13330
+ $5e86c304f21e41a8$var$in_flight.set(merchant, {
13331
+ started_at: now,
13332
+ read: read
13333
+ });
13334
+ return read;
13335
+ }
13336
+ function $5e86c304f21e41a8$export$6cde5c31239dec47() {
13337
+ $5e86c304f21e41a8$var$in_flight.clear();
13338
+ }
13339
+
13340
+ /**
13341
+ * The shopper's recently viewed products, kept in the browser for the native V4 API's history-based recommendations.
13342
+ *
13343
+ * v3 kept this history on the server, per session. V4 content requests carry no session, so a surface that reads
13344
+ * history gets it in the request (`recent_views`), and the SDK keeps the list. It holds product ids and view times
13345
+ * only (no session, user or page data), bounded in size and age, in localStorage per merchant; when localStorage
13346
+ * can't be used (private mode, blocked, full) it lives in memory for the page load.
13347
+ *
13348
+ * A view is recorded when a native product-anchored recommendation request resolves its anchor, as v3's facade records
13349
+ * a resolved anchor as a view; the product being viewed is in the list from the next request on.
13350
+ */ /** recs-wasm reads the newest 20 views (V4 `recent_views` docs), so more would never be read. */
13351
+ const $6db5e630baf4072a$export$3d684435158adda6 = 20;
13352
+ const $6db5e630baf4072a$export$5eb0a366a50fa99e = 2592000000;
13353
+ /** V4's longest product id (`ProductRef`); a longer one is never a product it knows. */
13354
+ const $6db5e630baf4072a$var$MAX_ID_LENGTH = 500;
13355
+ const $6db5e630baf4072a$var$storage_key = merchant => `depict_v4_recent_views_${merchant}`;
13356
+ /** The list per merchant as last written, which reads use when localStorage can't hold it. */
13357
+ const $6db5e630baf4072a$var$in_memory = new Map();
13358
+ /** Merchants whose last write to localStorage failed, so localStorage holds an older list than memory. */
13359
+ const $6db5e630baf4072a$var$unstored = new Set();
13360
+ /** `views` as a valid list: well-formed entries, newest first, one per id, not older than the age bound or too many. */
13361
+ function $6db5e630baf4072a$var$bounded(views, now) {
13362
+ if (!Array.isArray(views)) return [];
13363
+ const seen = new Set();
13364
+ const kept = [];
13365
+ for (const item of views) {
13366
+ if (!item || typeof item !== "object") continue;
13367
+ const {
13368
+ id: id,
13369
+ at: at
13370
+ } = item;
13371
+ if (typeof id !== "string" || !id || id.length > $6db5e630baf4072a$var$MAX_ID_LENGTH || typeof at !== "string") continue;
13372
+ const time = Date.parse(at);
13373
+ if (Number.isNaN(time) || now - time > $6db5e630baf4072a$export$5eb0a366a50fa99e) continue;
13374
+ kept.push({
13375
+ view: {
13376
+ id: id,
13377
+ at: new Date(time).toISOString()
13378
+ },
13379
+ time: time
13380
+ });
13381
+ }
13382
+ kept.sort((a, b) => b.time - a.time);
13383
+ const newest = [];
13384
+ for (const {
13385
+ view: view
13386
+ } of kept) {
13387
+ if (seen.has(view.id)) continue;
13388
+ seen.add(view.id);
13389
+ newest.push(view);
13390
+ if (newest.length === $6db5e630baf4072a$export$3d684435158adda6) break;
13391
+ }
13392
+ return newest;
13393
+ }
13394
+ function $6db5e630baf4072a$var$read_stored(merchant) {
13395
+ if ($6db5e630baf4072a$var$unstored.has(merchant)) return $6db5e630baf4072a$var$in_memory.get(merchant);
13396
+ try {
13397
+ const stored = localStorage.getItem($6db5e630baf4072a$var$storage_key(merchant));
13398
+ return stored === null ? [] : JSON.parse(stored);
13399
+ } catch {
13400
+ return $6db5e630baf4072a$var$in_memory.get(merchant) ?? [];
13401
+ }
13402
+ }
13403
+ function $6db5e630baf4072a$export$2d7138f47b625a04(merchant, now = Date.now()) {
13404
+ return $6db5e630baf4072a$var$bounded($6db5e630baf4072a$var$read_stored(merchant), now);
13405
+ }
13406
+ function $6db5e630baf4072a$export$6379943de8f8af08(merchant, product_id, now = Date.now()) {
13407
+ const views = $6db5e630baf4072a$var$bounded([{
13408
+ id: product_id,
13409
+ at: new Date(now).toISOString()
13410
+ }, ...$6db5e630baf4072a$export$2d7138f47b625a04(merchant, now)], now);
13411
+ $6db5e630baf4072a$var$in_memory.set(merchant, views);
13412
+ try {
13413
+ localStorage.setItem($6db5e630baf4072a$var$storage_key(merchant), JSON.stringify(views));
13414
+ $6db5e630baf4072a$var$unstored.delete(merchant);
13415
+ } catch {
13416
+ // localStorage unavailable or full: the in-memory list serves this page load.
13417
+ $6db5e630baf4072a$var$unstored.add(merchant);
13418
+ }
13419
+ }
13420
+
13421
+ /** V4's largest `limit`, and the most ids `cart` and `exclude` take. */
13422
+ const $6387a5d45d50694e$export$f112abad09998fa8 = 100;
13423
+ const $6387a5d45d50694e$var$MAX_IDS = 100;
13424
+ /** The most products V4's `recent_views` takes. */
13425
+ const $6387a5d45d50694e$var$MAX_VIEWS = 50;
13426
+ /** What a v3 recommendations call names, as fetchDepictRecommendations takes it. */
13427
+ const $6387a5d45d50694e$var$distinct = ids => [...new Set(ids.filter(id => typeof id === "string" && id.length > 0))];
13428
+ function $6387a5d45d50694e$export$17493dc1a89b34e6(call, inputs, recent_views) {
13429
+ const reads = input => inputs ? inputs.includes(input) : input === "anchor";
13430
+ const product_ids = $6387a5d45d50694e$var$distinct(call.productIds ?? []);
13431
+ const request = {
13432
+ market: call.market,
13433
+ ...(call.locale ? {
13434
+ locale: call.locale
13435
+ } : {}),
13436
+ type: call.type
13437
+ };
13438
+ if (reads("anchor")) {
13439
+ if (call.categoryId) request.anchor = {
13440
+ type: "category",
13441
+ id: call.categoryId
13442
+ };else if (call.productId) request.anchor = {
13443
+ type: "product",
13444
+ id: call.productId
13445
+ };else if (product_ids.length) {
13446
+ const [first, ...rest] = product_ids;
13447
+ request.anchor = {
13448
+ type: "product",
13449
+ id: first
13450
+ };
13451
+ if (rest.length) request.exclude = rest.slice(0, $6387a5d45d50694e$var$MAX_IDS);
13452
+ }
13453
+ }
13454
+ if (reads("cart") && product_ids.length) request.cart = product_ids.slice(0, $6387a5d45d50694e$var$MAX_IDS);
13455
+ if (reads("recent_views") && recent_views.length) request.recent_views = recent_views.slice(0, $6387a5d45d50694e$var$MAX_VIEWS);
13456
+ if (call.limit) request.limit = Math.min(Math.max(1, Math.floor(call.limit)), $6387a5d45d50694e$export$f112abad09998fa8);
13457
+ request.include = ["attributes"];
13458
+ const anchor_only = inputs?.length === 1 && inputs[0] === "anchor";
13459
+ if (anchor_only && !request.anchor) return undefined;
13460
+ return request;
13461
+ }
13462
+ /** `encodeURIComponent`, as V4's own encoder writes a value (`+` would mean a space). */
13463
+ const $6387a5d45d50694e$var$encode = value => encodeURIComponent(value);
13464
+ function $6387a5d45d50694e$export$fc756666ac777d0(request) {
13465
+ const pairs = [];
13466
+ const add = (key, value) => value !== undefined && pairs.push(`${key}=${value}`);
13467
+ const list = values => values?.map($6387a5d45d50694e$var$encode).join(",");
13468
+ add("market", $6387a5d45d50694e$var$encode(request.market));
13469
+ add("locale", request.locale === undefined ? undefined : $6387a5d45d50694e$var$encode(request.locale));
13470
+ add("type", $6387a5d45d50694e$var$encode(request.type));
13471
+ add("anchor", request.anchor && `${$6387a5d45d50694e$var$encode(request.anchor.type)}:${$6387a5d45d50694e$var$encode(request.anchor.id)}`);
13472
+ add("cart", list(request.cart));
13473
+ add("recent_views", request.recent_views?.map(view => `${$6387a5d45d50694e$var$encode(view.id)}@${$6387a5d45d50694e$var$encode(view.at)}`).join(","));
13474
+ add("query", request.query === undefined ? undefined : $6387a5d45d50694e$var$encode(request.query));
13475
+ add("exclude", list(request.exclude));
13476
+ add("limit", request.limit === undefined ? undefined : String(request.limit));
13477
+ add("include", list(request.include));
13478
+ return pairs.join("&");
13479
+ }
13480
+ const $6387a5d45d50694e$export$89962366050887f7 = product => product.variants[product.selected]?.product_id ?? product.group_id;
13481
+ function $6387a5d45d50694e$export$afe6aeae61a7aa58(hits, scope, type) {
13482
+ const anchors = hits.slice(0, type === "search" ? 10 : 1);
13483
+ return anchors.map((anchor, at) => {
13484
+ const exclude = hits.filter((_, index) => index !== at).map($6387a5d45d50694e$export$89962366050887f7);
13485
+ return {
13486
+ market: scope.market,
13487
+ ...(scope.locale ? {
13488
+ locale: scope.locale
13489
+ } : {}),
13490
+ type: type,
13491
+ anchor: {
13492
+ type: "product",
13493
+ id: $6387a5d45d50694e$export$89962366050887f7(anchor)
13494
+ },
13495
+ ...(exclude.length ? {
13496
+ exclude: exclude.slice(0, $6387a5d45d50694e$var$MAX_IDS)
13497
+ } : {}),
13498
+ include: ["attributes"]
13499
+ };
13500
+ });
13501
+ }
13502
+ function $6387a5d45d50694e$export$9af50be6508dcd00(lists, limit) {
13503
+ const merged = [];
13504
+ const taken = new Set();
13505
+ const depth = Math.max(0, ...lists.map(list => list.length));
13506
+ for (let index = 0; index < depth; index++) for (const list of lists) {
13507
+ const product = list[index];
13508
+ if (product === undefined || taken.has(product.group_id)) continue;
13509
+ taken.add(product.group_id);
13510
+ merged.push(product);
13511
+ if (merged.length >= limit) return merged;
13512
+ }
13513
+ return merged;
13514
+ }
13515
+
13516
+ /** 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 `#`. */
13517
+ const $bb0caa66ae094e38$var$BARE_HEX = /^(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
13518
+ function $bb0caa66ae094e38$export$7abfb7bc025aaea8(product, tracking_key) {
13519
+ const product_attributes = product.attributes ?? {};
13520
+ return {
13521
+ variant_index: product.selected,
13522
+ variant_displays: product.variants.map(variant => {
13523
+ // A variant carries its own main image only when it differs from the card's; it has no gallery of its own.
13524
+ const image_urls = variant.image ? [variant.image] : [...product.images];
13525
+ const price = variant.price ?? product.price;
13526
+ const color = variant.color ?? product.color;
13527
+ const display = {
13528
+ ...product_attributes,
13529
+ // The merchant's variant attributes under their own keys (`add_to_cart_id`, `item_group_id`, …); the card
13530
+ // fields below win over a same-named attribute, as on v3.
13531
+ ...variant.attributes,
13532
+ product_id: variant.product_id,
13533
+ main_product_id: variant.attributes?.main_product_id ?? variant.group_id ?? product.group_id,
13534
+ title: variant.title ?? product.title,
13535
+ image_urls: image_urls,
13536
+ sale_price: price.amount,
13537
+ original_price: price.compare_at ?? price.amount,
13538
+ ...(price.lowest !== undefined ? {
13539
+ lowest_price: price.lowest
13540
+ } : {}),
13541
+ in_stock: variant.in_stock,
13542
+ ...(color ? {
13543
+ color_name: color.name
13544
+ } : {}),
13545
+ uri: variant.slug ?? product.slug
13546
+ };
13547
+ const hex = display.color_hex;
13548
+ if (typeof hex === "string" && $bb0caa66ae094e38$var$BARE_HEX.test(hex)) display.color_hex = `#${hex}`;
13549
+ return display;
13550
+ }),
13551
+ [tracking_key]: product.tracking_id
13552
+ };
13553
+ }
13554
+
13555
+ /**
13556
+ * Filters, facets and sorts between depict-ui's v3 shapes and the native V4 API.
13557
+ *
13558
+ * This is a client-side port of realtime's v3 facade (`v4/worker/src/facade/v3Browse.ts`: `v3FilterBy`, `toV3Filters`,
13559
+ * `toV3Sorts`, `toV3ContentLinks`), which owns the same translation on the server for v3 requests. Keep the two in
13560
+ * step: a difference shows up as a filter that works on v3 and not on native, or the other way round.
13561
+ *
13562
+ * The facade resolves a v3 filter field against the merchant's search config (titles, localized titles). The browser
13563
+ * has no config, so it resolves against the facets V4 served instead (see {@link FacetIndex}).
13564
+ */ /** 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. */
13565
+ class $929d1037ed236371$export$f5ea4d073ddb4bdb extends Error {}
13566
+ /** v3's names for V4's built-in fields, both ways. */
13567
+ const $929d1037ed236371$var$V3_FIELD = {
13568
+ price: "sale_price"
13569
+ };
13570
+ const $929d1037ed236371$var$V4_FIELD = {
13571
+ sale_price: "price"
13572
+ };
13573
+ const $929d1037ed236371$var$V3_SORT = {
13574
+ relevance: "_relevance",
13575
+ price: "sale_price",
13576
+ newest: "product_timestamp"
13577
+ };
13578
+ const $929d1037ed236371$var$V4_SORT = Object.fromEntries(Object.entries($929d1037ed236371$var$V3_SORT).map(([v4, v3]) => [v3, v4]));
13579
+ /** V4's public filter field syntax (`FilterField` in the contract). */
13580
+ const $929d1037ed236371$var$PUBLIC_FIELD = /^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/;
13581
+ /**
13582
+ * Fields that are never a lowercased group title: v3's toggles carry no group title, and `sale_price` is v3's own
13583
+ * name for V4's price. A reserved V4 field (`price`, `brand`, `category`) is not among them: iciw's category tree is
13584
+ * titled "Category", so `category` from a link may name `product_scollection_category_hierarchy`.
13585
+ */
13586
+ const $929d1037ed236371$var$NEVER_A_TITLE = new Set(["in_stock", "on_sale", "sale_price"]);
13587
+ /** fi's enriched colour fields: their values are names, never a `<name>;#<hex>` composite. */
13588
+ const $929d1037ed236371$var$FI_COLOUR_FIELDS = new Set(["colors", "color_details"]);
13589
+ /** The colour template's field, which indexes the composite itself. */
13590
+ const $929d1037ed236371$var$V3_TEMPLATE_COLOUR = "color_with_hex_list";
13591
+ /** Legacy's colour pill composite suffix (`Green;#9ea386`). */
13592
+ const $929d1037ed236371$var$HEX_SUFFIX = /;#[0-9a-fA-F]{3,8}\s*$/;
13593
+ const $929d1037ed236371$var$NUMERIC = /^-?\d+(\.\d+)?$/;
13594
+ /** realtime's separator between the levels of a hierarchical facet value (`Shop # Woman`). */
13595
+ const $929d1037ed236371$var$HIERARCHY_SEPARATOR = " # ";
13596
+ /** The features realtime's category tree is built on. */
13597
+ const $929d1037ed236371$var$CATEGORY_TREE_FIELDS = new Set(["product_category_hierarchy", "product_scollection_category_hierarchy"]);
13598
+ /** V4's public name for the discount template's field (realtime `v4/worker/src/search/fields.ts`). */
13599
+ const $929d1037ed236371$var$DISCOUNT_FIELD = "discount";
13600
+ /** The fields of V4's toggle facets (the `on_sale` and `in_stock` templates). */
13601
+ const $929d1037ed236371$var$V3_TOGGLES = new Set(["on_sale", "in_stock"]);
13602
+ class $929d1037ed236371$export$8d488bcc71d07ffb {
13603
+ #by_key = new Map();
13604
+ /** Adds the facets of one browse response. */
13605
+ learn_(facets) {
13606
+ for (const facet of facets ?? []) {
13607
+ const info = {
13608
+ field_: facet.field,
13609
+ checkbox_: facet.type === "checkbox" && !$929d1037ed236371$var$is_toggle(facet),
13610
+ colour_: $929d1037ed236371$var$FI_COLOUR_FIELDS.has(facet.field) || facet.type === "swatch" && facet.field !== $929d1037ed236371$var$V3_TEMPLATE_COLOUR
13611
+ };
13612
+ this.#by_key.set(facet.field, info);
13613
+ const v3_field = $929d1037ed236371$var$V3_FIELD[facet.field];
13614
+ if (v3_field) this.#by_key.set(v3_field, info);
13615
+ if (facet.title) this.#by_key.set(facet.title.toLowerCase(), info);
13616
+ }
13617
+ }
13618
+ /** The field a v3 filter field names, when a served facet has it as its field or its title. */
13619
+ get_(field) {
13620
+ const bare = field.replace(/#$/, "");
13621
+ const direct = this.#by_key.get(bare);
13622
+ if (direct) return direct;
13623
+ let wanted;
13624
+ try {
13625
+ wanted = decodeURIComponent(bare).toLowerCase();
13626
+ } catch {
13627
+ wanted = bare.toLowerCase();
13628
+ }
13629
+ return this.#by_key.get(wanted);
13630
+ }
13631
+ }
13632
+ function $929d1037ed236371$export$3b6ba2422a5e0aa0(field, index) {
13633
+ return !!index.get_(field) || $929d1037ed236371$var$NEVER_A_TITLE.has(field.replace(/#$/, ""));
13634
+ }
13635
+ function $929d1037ed236371$var$is_empty(data) {
13636
+ return data === undefined || data === null || data === "" || Array.isArray(data) && !data.length;
13637
+ }
13638
+ function $929d1037ed236371$var$literal(value, field) {
13639
+ const text = String(value);
13640
+ if (text.includes("`")) throw new $929d1037ed236371$export$f5ea4d073ddb4bdb(`filters: a value of ${field} contains a backtick`);
13641
+ // A boolean-looking string is written bare, as realtime's filter writer does for every field.
13642
+ if (/^(true|True|false|False)$/.test(text)) return text.toLowerCase();
13643
+ if (field === "price" && $929d1037ed236371$var$NUMERIC.test(text)) return text;
13644
+ return typeof value === "string" ? `\`${text}\`` : text;
13645
+ }
13646
+ function $929d1037ed236371$var$lax_number(value) {
13647
+ if (typeof value === "number") return value;
13648
+ if (typeof value !== "string" || value.trim() === "") return undefined;
13649
+ const number = Number(value);
13650
+ return Number.isFinite(number) ? number : undefined;
13651
+ }
13652
+ function $929d1037ed236371$export$c17bb5d2ead3e8f3(filter, index) {
13653
+ if ($929d1037ed236371$var$is_empty(filter.data)) return undefined;
13654
+ const info = index.get_(filter.field);
13655
+ const bare = filter.field.replace(/#$/, "");
13656
+ const field = info?.field_ ?? $929d1037ed236371$var$V4_FIELD[bare] ?? bare;
13657
+ if (!$929d1037ed236371$var$PUBLIC_FIELD.test(field)) throw new $929d1037ed236371$export$f5ea4d073ddb4bdb(`Invalid filter field \`${filter.field}\``);
13658
+ const clause = text => ({
13659
+ field_: field,
13660
+ clause_: text
13661
+ });
13662
+ const colour = $929d1037ed236371$var$FI_COLOUR_FIELDS.has(field) || !!info?.colour_;
13663
+ const data = filter.data;
13664
+ 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));
13665
+ const list = () => `[${values.map(value => $929d1037ed236371$var$literal(value, field)).join(",")}]`;
13666
+ // V4's discount filter (the discount template's "X% or more" radio) is a threshold, so `in` or `eq` on it means
13667
+ // "this discount or more", as on the facade since realtime#2181: a link with no operator decodes as `in`, and a
13668
+ // shop may send `in ["0.2"]` itself. Several values take the largest, as `geq` does.
13669
+ const op = (filter.op === "in" || filter.op === "eq") && field === $929d1037ed236371$var$DISCOUNT_FIELD ? "geq" : filter.op;
13670
+ // A configured checkbox keeps in/nin; every other op on it becomes in.
13671
+ if (op !== "in" && op !== "nin" && info?.checkbox_) return clause(`${field}:=${list()}`);
13672
+ const one = () => {
13673
+ if (values.length !== 1) throw new $929d1037ed236371$export$f5ea4d073ddb4bdb(`filters: ${op} takes one value`);
13674
+ return $929d1037ed236371$var$literal(values[0], field);
13675
+ };
13676
+ // A comparison takes a number, also one sent as a string; of several numbers `geq` takes the largest.
13677
+ const bound = () => {
13678
+ const numbers = values.map(value => typeof value === "number" || typeof value === "string" && $929d1037ed236371$var$NUMERIC.test(value) ? Number(value) : undefined);
13679
+ if (numbers.length === 0 || numbers.some(number => number === undefined)) return one();
13680
+ if (numbers.length > 1 && op !== "geq") return one();
13681
+ return String(Math.max(...numbers));
13682
+ };
13683
+ switch (op) {
13684
+ case "eq":
13685
+ return clause(`${field}:=${one()}`);
13686
+ case "neq":
13687
+ return clause(`${field}:!=${one()}`);
13688
+ case "in":
13689
+ return clause(`${field}:=${list()}`);
13690
+ case "nin":
13691
+ return clause(`${field}:!=${list()}`);
13692
+ case "leq":
13693
+ return clause(`${field}:<=${bound()}`);
13694
+ case "geq":
13695
+ return clause(`${field}:>=${bound()}`);
13696
+ case "inrange":
13697
+ {
13698
+ const [min, max] = values.map($929d1037ed236371$var$lax_number);
13699
+ if (min === undefined || max === undefined || values.length !== 2) throw new $929d1037ed236371$export$f5ea4d073ddb4bdb("filters: inrange takes [min, max]");
13700
+ return clause(`${field}:[${min}..${max}]`);
13701
+ }
13702
+ default:
13703
+ throw new $929d1037ed236371$export$f5ea4d073ddb4bdb(`filters: unknown op ${op}`);
13704
+ }
13705
+ }
13706
+ function $929d1037ed236371$export$407f30f25da13cc7(filters, index) {
13707
+ const clauses = filters.flatMap(filter => $929d1037ed236371$export$c17bb5d2ead3e8f3(filter, index)?.clause_ ?? []);
13708
+ return clauses.length ? clauses.join(" && ") : undefined;
13709
+ }
13710
+ function $929d1037ed236371$export$c38de645260a41ed(error, clauses) {
13711
+ if (!error || !clauses.length) return [];
13712
+ const named = (error.message ?? "").match(/"([A-Za-z0-9_.-]+)/)?.[1];
13713
+ if (error.code === "unknown_filter_field") {
13714
+ if (error.allowed) {
13715
+ const allowed = new Set(error.allowed);
13716
+ return clauses.filter(clause => !allowed.has(clause.field_));
13717
+ }
13718
+ return clauses.filter(clause => clause.field_ === named);
13719
+ }
13720
+ if (error.code === "invalid_filter") {
13721
+ const on_field = clauses.filter(clause => clause.field_ === named);
13722
+ return on_field.length ? on_field : [...clauses];
13723
+ }
13724
+ return [];
13725
+ }
13726
+ function $929d1037ed236371$export$78eb8e636d89ff30(sort) {
13727
+ if (!sort || sort.field === "_relevance") return undefined;
13728
+ return {
13729
+ field: $929d1037ed236371$var$V4_SORT[sort.field] ?? sort.field,
13730
+ order: sort.order
13731
+ };
13732
+ }
13733
+ function $929d1037ed236371$export$cd08b64be5110ce2(sorts) {
13734
+ return sorts.map(sort => ({
13735
+ field: $929d1037ed236371$var$V3_SORT[sort.field] ?? sort.field,
13736
+ order: sort.order,
13737
+ meta: {
13738
+ title: sort.title,
13739
+ values: [sort.order],
13740
+ names: [sort.title]
13741
+ }
13742
+ }));
13743
+ }
13744
+ const $929d1037ed236371$var$V3_VALUES_TYPE = {
13745
+ checkbox: "checkbox",
13746
+ radio: "radio",
13747
+ swatch: "checkbox-color",
13748
+ hierarchy: "checkbox-hierarchical",
13749
+ grid: "checkbox-grid"
13750
+ };
13751
+ /** A toggle is a template facet's one `true` value. */
13752
+ function $929d1037ed236371$var$is_toggle(facet) {
13753
+ return $929d1037ed236371$var$V3_TOGGLES.has(facet.field) && facet.type === "checkbox" && facet.values.length === 1 && facet.values[0].value === "true";
13754
+ }
13755
+ function $929d1037ed236371$var$category_path(value) {
13756
+ return value.split("#").map(level => level.trim()).filter(Boolean);
13757
+ }
13758
+ function $929d1037ed236371$export$da9af372695714ef(facets, currency) {
13759
+ return facets.filter(facet => facet.type === "range" || facet.values.length > 0).map(facet => {
13760
+ const field = $929d1037ed236371$var$V3_FIELD[facet.field] ?? facet.field;
13761
+ if (facet.type === "range") return {
13762
+ field: field,
13763
+ op: "inrange",
13764
+ data: [facet.min, facet.max],
13765
+ meta: {
13766
+ group_title: facet.title,
13767
+ type: "range",
13768
+ min: facet.min,
13769
+ max: facet.max,
13770
+ ...(facet.field === "price" && currency ? {
13771
+ currency: currency
13772
+ } : {})
13773
+ },
13774
+ id: `${field}1`
13775
+ };
13776
+ const hierarchy = facet.type === "hierarchy";
13777
+ const path = value => $929d1037ed236371$var$CATEGORY_TREE_FIELDS.has(facet.field) ? $929d1037ed236371$var$category_path(value) : value.split($929d1037ed236371$var$HIERARCHY_SEPARATOR);
13778
+ if ($929d1037ed236371$var$is_toggle(facet)) return {
13779
+ field: field,
13780
+ op: "eq",
13781
+ meta: {
13782
+ type: "checkbox",
13783
+ values: facet.values.map(value => value.value),
13784
+ counts: facet.values.map(value => value.count),
13785
+ names: facet.values.map(value => value.label)
13786
+ },
13787
+ id: `${field}1`
13788
+ };
13789
+ // Two spellings of one category path are one row in the tree.
13790
+ const seen = new Set();
13791
+ const values = $929d1037ed236371$var$CATEGORY_TREE_FIELDS.has(facet.field) ? facet.values.filter(({
13792
+ value: value
13793
+ }) => {
13794
+ const levels = path(value);
13795
+ const key = JSON.stringify(levels);
13796
+ if (levels.length === 0 || seen.has(key)) return false;
13797
+ seen.add(key);
13798
+ return true;
13799
+ }) : facet.values;
13800
+ return {
13801
+ field: field,
13802
+ op: facet.field === "discount" ? "geq" : "in",
13803
+ meta: {
13804
+ group_title: facet.title,
13805
+ type: $929d1037ed236371$var$V3_VALUES_TYPE[facet.type] ?? "checkbox",
13806
+ values: values.map(value => hierarchy ? path(value.value) : value.value),
13807
+ counts: values.map(value => value.count),
13808
+ names: values.map(value => hierarchy ? path(value.value).slice(-1)[0] : value.label),
13809
+ // The colour template sends swatches only with one to paint; a colour filter always sends them.
13810
+ ...(facet.type === "swatch" && (facet.field !== $929d1037ed236371$var$V3_TEMPLATE_COLOUR || facet.values.some(value => value.swatch)) ? {
13811
+ swatches: facet.values.map(value => value.swatch ?? null)
13812
+ } : {})
13813
+ },
13814
+ id: `${field}1`
13815
+ };
13816
+ });
13817
+ }
13818
+ function $929d1037ed236371$export$b84a41a5163c4fce(content) {
13819
+ return content.map(hit => ({
13820
+ type: "content_link",
13821
+ title: hit.title,
13822
+ ...(hit.description !== undefined ? {
13823
+ description: hit.description
13824
+ } : {}),
13825
+ ...(hit.image_url !== undefined ? {
13826
+ image_url: hit.image_url
13827
+ } : {}),
13828
+ page_url: hit.url,
13829
+ highlights: hit.highlights ?? []
13830
+ }));
13831
+ }
13832
+ function $a85aaf1b38f3c6f0$export$efb7dd882d411dd4(response, door, offset) {
13833
+ const tracking_key = door === "search" ? "search_result_id" : "product_listing_result_id";
13834
+ return {
13835
+ n_hits: response.total ?? offset + response.products.length,
13836
+ sorts: $929d1037ed236371$export$cd08b64be5110ce2(response.sorts ?? []),
13837
+ filters: $929d1037ed236371$export$da9af372695714ef(response.facets ?? [], response.currency),
13838
+ ...(door === "search" ? {
13839
+ search_request_id: response.request_id,
13840
+ content_search_links: $929d1037ed236371$export$b84a41a5163c4fce(response.content ?? []),
13841
+ is_fallback: null
13842
+ } : {
13843
+ product_listing_request_id: response.request_id
13844
+ }),
13845
+ ...(response.cursor !== undefined ? {
13846
+ cursor: response.cursor
13847
+ } : {}),
13848
+ displays: response.products.map(product => $bb0caa66ae094e38$export$7abfb7bc025aaea8(product, tracking_key))
13849
+ };
13850
+ }
13851
+ function $a85aaf1b38f3c6f0$var$listing_ref_to_v3(ref, listing_type, show) {
13852
+ return {
13853
+ listing_id: ref.id,
13854
+ ...(ref.external_id !== undefined ? {
13855
+ external_id: ref.external_id
13856
+ } : {}),
13857
+ listing_type: listing_type,
13858
+ ...show,
13859
+ image_urls: [],
13860
+ title: ref.title,
13861
+ ...(ref.slug !== undefined ? {
13862
+ slug: ref.slug
13863
+ } : {})
13864
+ };
13865
+ }
13866
+ function $a85aaf1b38f3c6f0$export$996f2b1e66d9b5af(listing) {
13867
+ const listing_type = listing.type;
13868
+ const quick_links_are_siblings = listing.quick_links.some(link => link.id === listing.id);
13869
+ const quick_links = listing.quick_links.map(link => $a85aaf1b38f3c6f0$var$listing_ref_to_v3(link, listing_type, {
13870
+ show_in_breadcrumbs: true,
13871
+ show_in_quicklinks: true
13872
+ }));
13873
+ return {
13874
+ listing_id: listing.id,
13875
+ ...(listing.external_id !== undefined ? {
13876
+ external_id: listing.external_id
13877
+ } : {}),
13878
+ listing_type: listing_type,
13879
+ show_in_breadcrumbs: listing.show_in_breadcrumbs,
13880
+ show_in_quicklinks: true,
13881
+ image_urls: listing.images,
13882
+ title: listing.title,
13883
+ ...(listing.slug !== undefined ? {
13884
+ slug: listing.slug
13885
+ } : {}),
13886
+ ancestors: listing.breadcrumbs.map(ref => $a85aaf1b38f3c6f0$var$listing_ref_to_v3(ref, "category", {
13887
+ show_in_breadcrumbs: true,
13888
+ show_in_quicklinks: true
13889
+ })),
13890
+ siblings: quick_links_are_siblings ? quick_links : [],
13891
+ children: quick_links_are_siblings ? [] : quick_links,
13892
+ content_blocks: listing.content_blocks
13893
+ };
13894
+ }
13895
+ function $a85aaf1b38f3c6f0$export$76d96892da63b395(tree) {
13896
+ const by_id = new Map();
13897
+ const walk = (nodes, chain) => {
13898
+ for (const node of nodes) {
13899
+ if (!by_id.has(node.id)) by_id.set(node.id, chain);
13900
+ walk(node.children, [...chain, $a85aaf1b38f3c6f0$var$listing_ref_to_v3(node, node.type, {
13901
+ show_in_breadcrumbs: true,
13902
+ show_in_quicklinks: true
13903
+ })]);
13904
+ }
13905
+ };
13906
+ walk(tree, []);
13907
+ return listing_id => by_id.get(listing_id);
13908
+ }
13909
+ function $a85aaf1b38f3c6f0$export$2860125b419015f8(response, ancestors_of) {
13910
+ return {
13911
+ suggestions_request_id: response.request_id,
13912
+ suggestions: response.suggestions.map(suggestion => {
13913
+ if (suggestion.type === "query") return {
13914
+ type: "query",
13915
+ query: suggestion.query,
13916
+ suggestions_result_id: ""
13917
+ };
13918
+ const from_tree = ancestors_of?.(suggestion.listing.id);
13919
+ const ancestors = from_tree && $a85aaf1b38f3c6f0$var$same_titles(from_tree, suggestion.path) ? from_tree : [];
13920
+ return {
13921
+ type: "listing",
13922
+ listing_id: suggestion.listing.id,
13923
+ ...(suggestion.listing.external_id !== undefined ? {
13924
+ external_id: suggestion.listing.external_id
13925
+ } : {}),
13926
+ listing_type: suggestion.listing.type,
13927
+ show_in_breadcrumbs: true,
13928
+ show_in_quicklinks: true,
13929
+ image_urls: suggestion.listing.images,
13930
+ title: suggestion.listing.title,
13931
+ ...(suggestion.listing.slug !== undefined ? {
13932
+ slug: suggestion.listing.slug
13933
+ } : {}),
13934
+ suggestions_result_id: "",
13935
+ ancestors: ancestors
13936
+ };
13937
+ })
13938
+ };
13939
+ }
13940
+ const $a85aaf1b38f3c6f0$var$same_titles = (ancestors, path) => ancestors.length === path.length && ancestors.every((ancestor, index) => ancestor.title === path[index]);
13941
+ /** `encodeURIComponent`, as V4's own encoder writes a value (`+` would mean a space). */
13942
+ const $a85aaf1b38f3c6f0$var$encode = value => encodeURIComponent(value);
13943
+ function $a85aaf1b38f3c6f0$export$7659319cdb555579(request) {
13944
+ const pairs = [`market=${$a85aaf1b38f3c6f0$var$encode(request.market)}`];
13945
+ const add = (key, value) => value !== undefined && pairs.push(`${key}=${value}`);
13946
+ add("locale", request.locale === undefined ? undefined : $a85aaf1b38f3c6f0$var$encode(request.locale));
13947
+ add("query", request.query === undefined ? undefined : $a85aaf1b38f3c6f0$var$encode(request.query));
13948
+ 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));
13949
+ add("filter_by", request.filter_by === undefined ? undefined : $a85aaf1b38f3c6f0$var$encode(request.filter_by));
13950
+ if (request.sort) add("sort", `${$a85aaf1b38f3c6f0$var$encode(request.sort.field)}.${request.sort.order}`);
13951
+ add("include", request.include?.join(","));
13952
+ add("cursor", request.cursor);
13953
+ add("limit", request.limit === undefined ? undefined : String(request.limit));
13954
+ return pairs.join("&");
13955
+ }
13956
+ function $a85aaf1b38f3c6f0$export$fec3e4b5adfcea2c(params) {
13957
+ return params.filter(pair => pair[1] !== undefined).map(([key, value]) => `${key}=${$a85aaf1b38f3c6f0$var$encode(value)}`).join("&");
13958
+ }
13959
+ function $a85aaf1b38f3c6f0$export$eb90c08da400512d(locale) {
13960
+ return locale ? locale.replace(/_/g, "-") : undefined;
13961
+ }
13962
+
13963
+ /** realtime's related search page: the hits related recommendations anchor on and never repeat. */
13964
+ const $8e175fb7c533c600$var$RELATED_SEARCH_PAGE = 100;
13965
+ const $8e175fb7c533c600$var$get_recommendations = (merchant, request) => $c6c537571dbf3c03$export$88d793e3827f3436($c6c537571dbf3c03$export$b6dad15503f66988(merchant, "/recommendations") + "?" + $6387a5d45d50694e$export$fc756666ac777d0(request));
13966
+ const $8e175fb7c533c600$var$to_displays = products => products.map(product => $bb0caa66ae094e38$export$7abfb7bc025aaea8(product, "recommendation_id"));
13967
+ async function $8e175fb7c533c600$export$656ee5c46d5d1eda(call) {
13968
+ const {
13969
+ merchant: merchant
13970
+ } = call;
13971
+ const types = await $5e86c304f21e41a8$export$869eb14d6f85ac51(merchant);
13972
+ const inputs = types?.get(call.type);
13973
+ if (types && !inputs) {
13974
+ $9HbP8$dwarn(`[NativeDepictAPI] V4 serves ${merchant} no recommendation type "${call.type}"; known:`, [...types.keys()]);
13975
+ return [];
13976
+ }
13977
+ const request = $6387a5d45d50694e$export$17493dc1a89b34e6({
13978
+ ...call,
13979
+ locale: $a85aaf1b38f3c6f0$export$eb90c08da400512d(call.locale)
13980
+ }, inputs, inputs?.includes("recent_views") ? $6db5e630baf4072a$export$2d7138f47b625a04(merchant) : []);
13981
+ if (!request) return [];
13982
+ const response = await $8e175fb7c533c600$var$get_recommendations(merchant, request);
13983
+ if (!response) return [];
13984
+ const anchor = response.used_inputs?.anchor;
13985
+ if (call.productId && anchor?.type === "product") $6db5e630baf4072a$export$6379943de8f8af08(merchant, anchor.id);
13986
+ return $8e175fb7c533c600$var$to_displays(response.products);
13987
+ }
13988
+ async function $8e175fb7c533c600$export$bd5f8a7d3e47a43d(call) {
13989
+ const {
13990
+ merchant: merchant,
13991
+ market: market
13992
+ } = call;
13993
+ const types = await $5e86c304f21e41a8$export$869eb14d6f85ac51(merchant);
13994
+ if (!types) return undefined;
13995
+ const type = types.get("search")?.includes("anchor") ? "search" : types.get("similar")?.includes("anchor") ? "similar" : undefined;
13996
+ if (!type) {
13997
+ $9HbP8$dwarn(`[NativeDepictAPI] V4 serves ${merchant} no search or similar recommendations for related products`);
13998
+ return [];
13999
+ }
14000
+ const locale = $a85aaf1b38f3c6f0$export$eb90c08da400512d(call.locale);
14001
+ const query = call.query?.trim() || undefined;
14002
+ const searched = await $c6c537571dbf3c03$export$88d793e3827f3436($c6c537571dbf3c03$export$b6dad15503f66988(merchant, "/browse") + "?" + $a85aaf1b38f3c6f0$export$7659319cdb555579({
14003
+ market: market,
14004
+ ...(locale ? {
14005
+ locale: locale
14006
+ } : {}),
14007
+ ...(query ? {
14008
+ query: query
14009
+ } : {}),
14010
+ limit: $8e175fb7c533c600$var$RELATED_SEARCH_PAGE
14011
+ }));
14012
+ if (!searched) return undefined;
14013
+ const asked = $6387a5d45d50694e$export$afe6aeae61a7aa58(searched.products, {
14014
+ market: market,
14015
+ ...(locale ? {
14016
+ locale: locale
14017
+ } : {})
14018
+ }, type);
14019
+ if (!asked.length) return [];
14020
+ const answers = await Promise.all(asked.map(request => $8e175fb7c533c600$var$get_recommendations(merchant, request)));
14021
+ const lists = answers.filter(answer => !!answer).map(answer => answer.products);
14022
+ if (!lists.length) return undefined;
14023
+ const products = lists.length > 1 ? $6387a5d45d50694e$export$9af50be6508dcd00(lists, Math.max(...lists.map(list => list.length))) : lists[0];
14024
+ return $8e175fb7c533c600$var$to_displays(products);
14025
+ }
13245
14026
  async function $a0f0e923bad68a9b$export$58e808b1db15d3bc(options) {
14027
+ if (options.api === "v4") return await $a0f0e923bad68a9b$var$fetch_native(options);
13246
14028
  const headers = options.headers;
13247
14029
  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
13248
14030
  const cleaned_up_options = $9HbP8$snakeCasifyObject(options);
13249
14031
  delete cleaned_up_options.headers;
13250
14032
  delete cleaned_up_options.product_id;
14033
+ delete cleaned_up_options.api;
13251
14034
  cleaned_up_options.session_id ||= $9HbP8$get_session_id();
13252
14035
  if (product_id && !cleaned_up_options.product_ids) cleaned_up_options.product_ids = [product_id];
13253
14036
  const options_to_send = cleaned_up_options;
@@ -13269,6 +14052,33 @@ async function $a0f0e923bad68a9b$export$58e808b1db15d3bc(options) {
13269
14052
  return decoded?.displays || [];
13270
14053
  });
13271
14054
  }
14055
+ async function $a0f0e923bad68a9b$var$fetch_native(options) {
14056
+ const {
14057
+ merchant: merchant,
14058
+ market: market,
14059
+ locale: locale,
14060
+ type: type,
14061
+ headers: headers,
14062
+ categoryId: categoryId,
14063
+ productIds: productIds
14064
+ } = options;
14065
+ if (headers) $9HbP8$dwarn("fetchDepictRecommendations: headers aren't sent to the native V4 API", headers);
14066
+ try {
14067
+ return await $8e175fb7c533c600$export$656ee5c46d5d1eda({
14068
+ merchant: merchant,
14069
+ market: market,
14070
+ locale: locale,
14071
+ type: type,
14072
+ categoryId: categoryId,
14073
+ productId: options.productId || options.product_id,
14074
+ productIds: productIds,
14075
+ limit: options.limit
14076
+ });
14077
+ } catch (e) {
14078
+ $9HbP8$dlog("fetch_native_recommendations threw", e);
14079
+ return [];
14080
+ }
14081
+ }
13272
14082
  var $a6e23a834336fc19$var$_tmpl$ = /*#__PURE__*/$9HbP8$template(`<div class="sort-and-filter-buttons fake"aria-hidden=true style=position:absolute;z-index:-1;pointer-events:none;opacity:0><div class=outer><div class=inner><!$><!/><!$><!/><!$><!/>`);
13273
14083
  const $a6e23a834336fc19$export$824dde41348efed1 = /*@__PURE__*/(() => {
13274
14084
  const actual_function = ({
@@ -13669,7 +14479,10 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13669
14479
  input_req_: input_req_,
13670
14480
  fallback_response_: fallback_response_,
13671
14481
  method_ = "POST",
13672
- currentListingForTransformer_: currentListingForTransformer_
14482
+ currentListingForTransformer_: currentListingForTransformer_,
14483
+ kind_: kind_,
14484
+ id_to_query_for_: id_to_query_for_,
14485
+ id_type_: id_type_
13673
14486
  }) {
13674
14487
  const cache_obj = this.#get_cache_obj_for_endpoint(endpoint_);
13675
14488
  const with_ids = this.#add_ids_to_request(input_req_);
@@ -13686,19 +14499,19 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13686
14499
  let resolve_in_progress;
13687
14500
  cache_obj.in_progress_[body] = new Promise(r => resolve_in_progress = r);
13688
14501
  try {
13689
- const is_post = method_ === "POST";
13690
- const url_to_request = is_post ? endpoint_ : $9HbP8$make_url_with_query_params(endpoint_, sorted_request);
13691
- const api_response = await $9HbP8$fetch_retry($9HbP8$add_version_query_params(url_to_request), {
13692
- method: method_,
13693
- ...(is_post ? {
13694
- body: body
13695
- } : {})
13696
- });
13697
14502
  return_successfully: {
13698
- if (!api_response || api_response.status !== 200) break return_successfully;
13699
14503
  let result;
13700
14504
  try {
13701
- const unmodified_result = await api_response.json();
14505
+ const unmodified_result = await this.request_raw_({
14506
+ kind_: kind_,
14507
+ endpoint_: endpoint_,
14508
+ method_: method_,
14509
+ request_: sorted_request,
14510
+ body_: body,
14511
+ id_to_query_for_: id_to_query_for_,
14512
+ id_type_: id_type_
14513
+ });
14514
+ if (unmodified_result === undefined) break return_successfully;
13702
14515
  result = await this.#run_display_transformers_for_rest(input_req_.merchant, input_req_.market, input_req_.locale, unmodified_result, currentListingForTransformer_);
13703
14516
  } catch (e) {
13704
14517
  $9HbP8$dwarn("displayTransformer or json decoding failed", e);
@@ -13726,6 +14539,29 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13726
14539
  delete cache_obj.in_progress_[body];
13727
14540
  }
13728
14541
  }
14542
+ /**
14543
+ * The network step of every read: sends `call` to the v3 API and returns the decoded JSON, or undefined when the
14544
+ * request failed. NativeDepictAPI overrides this to read the native V4 API instead and map its answers to v3 shapes,
14545
+ * so caching, display transformers and fallbacks stay the same for both.
14546
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14547
+ async request_raw_(call) {
14548
+ const {
14549
+ endpoint_: endpoint_,
14550
+ method_: method_,
14551
+ request_: request_,
14552
+ body_: body_
14553
+ } = call;
14554
+ const is_post = method_ === "POST";
14555
+ const url_to_request = is_post ? endpoint_ : $9HbP8$make_url_with_query_params(endpoint_, request_);
14556
+ const api_response = await $9HbP8$fetch_retry($9HbP8$add_version_query_params(url_to_request), {
14557
+ method: method_,
14558
+ ...(is_post ? {
14559
+ body: body_
14560
+ } : {})
14561
+ });
14562
+ if (!api_response || call.kind_ !== "suggest" && api_response.status !== 200) return undefined;
14563
+ return await api_response.json();
14564
+ }
13729
14565
  constructor(options) {
13730
14566
  const {
13731
14567
  get_metadata: get_metadata,
@@ -13742,11 +14578,13 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13742
14578
  const request = metaData ? Object.assign(with_ids, {
13743
14579
  metadata: JSON.stringify(metaData)
13744
14580
  }) : with_ids;
13745
- const url = $9HbP8$make_url_with_query_params($7fa23e2a0079eca4$var$search_base_url + "suggestions", request);
13746
- const results = await $9HbP8$fetch_retry($9HbP8$add_version_query_params(url));
13747
14581
  attempt_to_return_api_response: {
13748
- if (!results) break attempt_to_return_api_response;
13749
- const decoded_json = await results.json();
14582
+ const decoded_json = await this.request_raw_({
14583
+ kind_: "suggest",
14584
+ endpoint_: $7fa23e2a0079eca4$var$search_base_url + "suggestions",
14585
+ method_: "GET",
14586
+ request_: request
14587
+ });
13750
14588
  if (!Array.isArray(decoded_json?.suggestions)) break attempt_to_return_api_response;
13751
14589
  try {
13752
14590
  return await this.#run_url_creator_for_suggest(input_req.merchant, input_req.market, input_req.locale, decoded_json);
@@ -13763,6 +14601,7 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13763
14601
  async query(input_req) {
13764
14602
  return await this.#cached_request({
13765
14603
  endpoint_: $7fa23e2a0079eca4$var$search_base_url + "results",
14604
+ kind_: "search",
13766
14605
  input_req_: input_req,
13767
14606
  fallback_response_: () => ({
13768
14607
  "n_hits": 0,
@@ -13782,6 +14621,9 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13782
14621
  return await this.#cached_request({
13783
14622
  endpoint_: $7fa23e2a0079eca4$var$v3_base_url + "listings/" + (id_type_ === $c20599a0d81d953a$export$5aae649db1b959fc ? "external_id/" : "") + encodeURIComponent(id_to_query_for_),
13784
14623
  input_req_: input_req,
14624
+ kind_: "listing",
14625
+ id_to_query_for_: id_to_query_for_,
14626
+ id_type_: id_type_,
13785
14627
  fallback_response_: () => ({
13786
14628
  listing_id: "",
13787
14629
  listing_type: "category",
@@ -13808,6 +14650,9 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13808
14650
  endpoint_: $7fa23e2a0079eca4$var$v3_base_url + "listings/" + (id_type_ === $c20599a0d81d953a$export$5aae649db1b959fc ? "external_id/" : "") + encodeURIComponent(id_to_query_for_) + "/products",
13809
14651
  input_req_: input_req_,
13810
14652
  currentListingForTransformer_: currentListingForTransformer_,
14653
+ kind_: "listing_products",
14654
+ id_to_query_for_: id_to_query_for_,
14655
+ id_type_: id_type_,
13811
14656
  fallback_response_: () => ({
13812
14657
  "n_hits": 0,
13813
14658
  "displays": [],
@@ -13821,6 +14666,7 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13821
14666
  async get_recommended(input_req) {
13822
14667
  return await this.#cached_request({
13823
14668
  endpoint_: $7fa23e2a0079eca4$var$search_base_url + "related",
14669
+ kind_: "related",
13824
14670
  input_req_: input_req,
13825
14671
  fallback_response_: () => ({
13826
14672
  displays: []
@@ -13828,6 +14674,228 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
13828
14674
  });
13829
14675
  }
13830
14676
  }
14677
+
14678
+ /** V4 browse's largest page; a bigger v3 page is V4's pages chained by their cursors, as the facade does. */
14679
+ const $890cbbfc01f1e100$var$BROWSE_MAX_LIMIT = 100;
14680
+ /** V4 browse's page size without a limit, and v3's. */
14681
+ const $890cbbfc01f1e100$var$DEFAULT_LIMIT = 24;
14682
+ /** A query with no letter or digit browses the catalogue instead of returning an empty grid, as on v3. */
14683
+ const $890cbbfc01f1e100$var$HAS_LETTER_OR_DIGIT = /[\p{L}\p{N}]/u;
14684
+ class $890cbbfc01f1e100$export$721afe49a594bed extends (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3) {
14685
+ /** Facets served so far, per merchant, market and locale, to resolve v3 filter fields (group titles) to V4 fields. */#facet_indices = new Map();
14686
+ /** Browses whose facets were read only to resolve filter fields, so each is read at most once. */
14687
+ #learned = new Set();
14688
+ /** How many products came before each cursor V4 handed out, for the lower-bound count when `total` is absent. */
14689
+ #cursor_offsets = new Map();
14690
+ /** Each listing's ancestors from the listing tree, per merchant, market and locale, read once a page load. */
14691
+ #ancestor_lookups = new Map();
14692
+ /** Filter clauses V4 refused (`unknown_filter_field`, `invalid_filter`), per merchant, market and locale. */
14693
+ #rejected = new Map();
14694
+ constructor(options) {
14695
+ super(options);
14696
+ $9HbP8$set_event_api("v4");
14697
+ }
14698
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14699
+ async request_raw_(call) {
14700
+ switch (call.kind_) {
14701
+ case "search":
14702
+ return await this.#browse("search", call.request_);
14703
+ case "listing_products":
14704
+ return await this.#browse("listing", call.request_, {
14705
+ [call.id_type_ === $c20599a0d81d953a$export$5aae649db1b959fc ? "external_id" : "id"]: call.id_to_query_for_
14706
+ });
14707
+ case "listing":
14708
+ return await this.#listing(call);
14709
+ case "suggest":
14710
+ return await this.#suggest(call.request_);
14711
+ case "related":
14712
+ {
14713
+ const {
14714
+ merchant: merchant,
14715
+ market: market,
14716
+ locale: locale,
14717
+ query: query
14718
+ } = call.request_;
14719
+ const displays = await $8e175fb7c533c600$export$bd5f8a7d3e47a43d({
14720
+ merchant: merchant,
14721
+ market: market,
14722
+ locale: locale,
14723
+ query: query
14724
+ });
14725
+ return displays && {
14726
+ displays: displays
14727
+ };
14728
+ }
14729
+ }
14730
+ }
14731
+ #merchant_url(merchant, path) {
14732
+ return $c6c537571dbf3c03$export$b6dad15503f66988(merchant, path);
14733
+ }
14734
+ async #get_json(url) {
14735
+ return (await this.#get_answer(url)).body_;
14736
+ }
14737
+ /** A GET's body on a 200, else V4's error (when it sent one). */
14738
+ async #get_answer(url) {
14739
+ return await $c6c537571dbf3c03$export$f035610fd74c541a(url);
14740
+ }
14741
+ #facet_index(merchant, market, locale) {
14742
+ const key = JSON.stringify([merchant, market, locale]);
14743
+ let index = this.#facet_indices.get(key);
14744
+ if (!index) this.#facet_indices.set(key, index = new (0, $929d1037ed236371$export$8d488bcc71d07ffb)());
14745
+ return index;
14746
+ }
14747
+ async #browse_page(merchant, request) {
14748
+ return (await this.#browse_answer(merchant, request)).body_;
14749
+ }
14750
+ async #browse_answer(merchant, request) {
14751
+ return await this.#get_answer(this.#merchant_url(merchant, "/browse") + "?" + $a85aaf1b38f3c6f0$export$7659319cdb555579(request));
14752
+ }
14753
+ /** The filter clauses V4 refused, per merchant, market and locale, for this page load. */
14754
+ #rejected_clauses(merchant, market, locale) {
14755
+ const key = JSON.stringify([merchant, market, locale]);
14756
+ let rejected = this.#rejected.get(key);
14757
+ if (!rejected) this.#rejected.set(key, rejected = new Set());
14758
+ return rejected;
14759
+ }
14760
+ async #browse(door, v3_request, listing) {
14761
+ const {
14762
+ merchant: merchant,
14763
+ market: market
14764
+ } = v3_request;
14765
+ const locale = $a85aaf1b38f3c6f0$export$eb90c08da400512d(v3_request.locale);
14766
+ const query = door === "search" && v3_request.query && $890cbbfc01f1e100$var$HAS_LETTER_OR_DIGIT.test(v3_request.query) ? v3_request.query : undefined;
14767
+ const base = {
14768
+ market: market,
14769
+ ...(locale ? {
14770
+ locale: locale
14771
+ } : {}),
14772
+ ...(query ? {
14773
+ query: query
14774
+ } : {}),
14775
+ ...(listing ? {
14776
+ listing: listing
14777
+ } : {})
14778
+ };
14779
+ const index = this.#facet_index(merchant, market, locale);
14780
+ const filters = v3_request.filters ?? [];
14781
+ // depict-ui sends a filter's lowercased group title as its field. A page opened from a link with filters in it
14782
+ // comes before any facets, so read this browse's facets once to learn which field each title names.
14783
+ const learn_key = JSON.stringify([merchant, base]);
14784
+ if (filters.some(filter => filter.data != null && !$929d1037ed236371$export$3b6ba2422a5e0aa0(filter.field, index)) && !this.#learned.has(learn_key)) {
14785
+ this.#learned.add(learn_key);
14786
+ index.learn_((await this.#browse_page(merchant, {
14787
+ ...base,
14788
+ include: ["facets"],
14789
+ limit: 1
14790
+ }))?.facets);
14791
+ }
14792
+ // A filter V4 can't take must not cost the shopper the page: a link can outlive its filter (one removed from the
14793
+ // store, a hand-written value). One the adapter can't write is left out here; one V4 rejects is left out and the
14794
+ // page asked again, and remembered for this page load so later pages don't ask with it.
14795
+ const rejected = this.#rejected_clauses(merchant, market, locale);
14796
+ let clauses = [];
14797
+ for (const filter of filters) try {
14798
+ const clause = $929d1037ed236371$export$c17bb5d2ead3e8f3(filter, index);
14799
+ if (clause) clauses.push(clause);
14800
+ } catch (e) {
14801
+ if (!(e instanceof (0, $929d1037ed236371$export$f5ea4d073ddb4bdb))) throw e;
14802
+ $9HbP8$dwarn("[NativeDepictAPI] leaving out a filter V4 can't take:", e.message, filter);
14803
+ }
14804
+ clauses = clauses.filter(clause => !rejected.has(clause.clause_));
14805
+ const sort = $929d1037ed236371$export$78eb8e636d89ff30(v3_request.sort);
14806
+ const include = door === "search" ? ["facets", "sorts", "content", "attributes"] : ["facets", "sorts", "attributes"];
14807
+ const want = v3_request.limit ?? $890cbbfc01f1e100$var$DEFAULT_LIMIT;
14808
+ const offset = v3_request.cursor && this.#cursor_offsets.get(v3_request.cursor) || 0;
14809
+ const request_with = sent => ({
14810
+ ...base,
14811
+ ...(sent.length ? {
14812
+ filter_by: sent.map(clause => clause.clause_).join(" && ")
14813
+ } : {}),
14814
+ ...(sort ? {
14815
+ sort: sort
14816
+ } : {}),
14817
+ ...(v3_request.cursor ? {
14818
+ cursor: v3_request.cursor
14819
+ } : {}),
14820
+ include: include,
14821
+ ...(want !== $890cbbfc01f1e100$var$DEFAULT_LIMIT ? {
14822
+ limit: Math.min(want, $890cbbfc01f1e100$var$BROWSE_MAX_LIMIT)
14823
+ } : {})
14824
+ });
14825
+ let request = request_with(clauses);
14826
+ let answer = await this.#browse_answer(merchant, request);
14827
+ // Each retry leaves out at least one more clause, so this ends.
14828
+ while (!answer.body_) {
14829
+ const refused = $929d1037ed236371$export$c38de645260a41ed(answer.error_, clauses);
14830
+ if (!refused.length) return undefined;
14831
+ $9HbP8$dwarn("[NativeDepictAPI] leaving out filters V4 refused:", refused.map(clause => clause.clause_), answer.error_?.message);
14832
+ for (const clause of refused) rejected.add(clause.clause_);
14833
+ clauses = clauses.filter(clause => !refused.includes(clause));
14834
+ request = request_with(clauses);
14835
+ answer = await this.#browse_answer(merchant, request);
14836
+ }
14837
+ let response = answer.body_;
14838
+ // A page over V4's largest is its pages chained by their cursors; later pages ask for products alone.
14839
+ while (want > $890cbbfc01f1e100$var$BROWSE_MAX_LIMIT && response.products.length < want && response.cursor !== undefined) {
14840
+ const page = await this.#browse_page(merchant, {
14841
+ ...request,
14842
+ cursor: response.cursor,
14843
+ limit: Math.min(want - response.products.length, $890cbbfc01f1e100$var$BROWSE_MAX_LIMIT),
14844
+ include: ["attributes"]
14845
+ });
14846
+ if (!page) return undefined;
14847
+ if (!page.products.length) break;
14848
+ response = {
14849
+ ...response,
14850
+ products: [...response.products, ...page.products],
14851
+ ...(page.cursor !== undefined ? {
14852
+ cursor: page.cursor
14853
+ } : {
14854
+ cursor: undefined
14855
+ })
14856
+ };
14857
+ }
14858
+ if (response.cursor === undefined) delete response.cursor;
14859
+ index.learn_(response.facets);
14860
+ if (response.cursor !== undefined) this.#cursor_offsets.set(response.cursor, offset + response.products.length);
14861
+ return $a85aaf1b38f3c6f0$export$efb7dd882d411dd4(response, door, offset);
14862
+ }
14863
+ async #listing(call) {
14864
+ const {
14865
+ merchant: merchant,
14866
+ market: market
14867
+ } = call.request_;
14868
+ const locale = $a85aaf1b38f3c6f0$export$eb90c08da400512d(call.request_.locale);
14869
+ const by_external_id = call.id_type_ === $c20599a0d81d953a$export$5aae649db1b959fc;
14870
+ const path = by_external_id ? "/listings" : "/listings/" + encodeURIComponent(call.id_to_query_for_);
14871
+ 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]]));
14872
+ return response && $a85aaf1b38f3c6f0$export$996f2b1e66d9b5af(response.listing);
14873
+ }
14874
+ async #suggest(v3_request) {
14875
+ const {
14876
+ merchant: merchant,
14877
+ market: market
14878
+ } = v3_request;
14879
+ const locale = $a85aaf1b38f3c6f0$export$eb90c08da400512d(v3_request.locale);
14880
+ const response = await this.#get_json(this.#merchant_url(merchant, "/suggest") + "?" + $a85aaf1b38f3c6f0$export$fec3e4b5adfcea2c([["market", market], ["locale", locale], ["query", v3_request.query ?? ""]]));
14881
+ if (!response) return undefined;
14882
+ const needs_ancestors = response.suggestions.some(suggestion => suggestion.type === "listing" && suggestion.path.length > 0);
14883
+ return $a85aaf1b38f3c6f0$export$2860125b419015f8(response, needs_ancestors ? await this.#ancestors(merchant, market, locale) : undefined);
14884
+ }
14885
+ /** V4 suggestions name ancestors by title only; the listing tree names them by id. A failed read isn't retried. */
14886
+ #ancestors(merchant, market, locale) {
14887
+ const key = JSON.stringify([merchant, market, locale]);
14888
+ let lookup = this.#ancestor_lookups.get(key);
14889
+ if (!lookup) {
14890
+ lookup = this.#get_json(this.#merchant_url(merchant, "/listings") + "?" + $a85aaf1b38f3c6f0$export$fec3e4b5adfcea2c([["market", market], ["locale", locale]])).then(tree => tree && $a85aaf1b38f3c6f0$export$76d96892da63b395(tree.listings));
14891
+ this.#ancestor_lookups.set(key, lookup);
14892
+ }
14893
+ return lookup;
14894
+ }
14895
+ }
14896
+ function $890cbbfc01f1e100$export$6d972e6af9de09f0(version, options) {
14897
+ return version === "v4" ? new $890cbbfc01f1e100$export$721afe49a594bed(options) : new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)(options);
14898
+ }
13831
14899
  function $ccd5db07a3a069c5$export$477caf01aecaeb2a(options) {
13832
14900
  const router_ = options.router_;
13833
14901
  const search_query_url_param_name_ = "search_query_url_param_name_" in options ? options.search_query_url_param_name_ : undefined;
@@ -14078,8 +15146,9 @@ class $961b5c64bef4662f$export$f34314aa9505732e {
14078
15146
  quicklinks_signal_: $9HbP8$createSignal(),
14079
15147
  i18n_: i18n_,
14080
15148
  reset_history_state_: reset_history_state_,
15149
+ depict_api_: typeof api === "object" && api ? api :
14081
15150
  // @ts-ignore
14082
- depict_api_: api ?? new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)({
15151
+ $890cbbfc01f1e100$export$6d972e6af9de09f0(api, {
14083
15152
  display_transformers: display_transformers
14084
15153
  }),
14085
15154
  router_: this.#router,
@@ -15635,8 +16704,9 @@ class $806c97b931758897$export$ac6237957a15b3f0 {
15635
16704
  const get_search_query_ = $9HbP8$createMemo(previous_value => {
15636
16705
  if (get_search_query_updating_blocked()) return previous_value;else return raw_search_query_accessor();
15637
16706
  });
16707
+ const depict_api_ = typeof api === "object" && api ? api :
15638
16708
  // @ts-ignore
15639
- const depict_api_ = api ?? new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)({
16709
+ $890cbbfc01f1e100$export$6d972e6af9de09f0(api, {
15640
16710
  display_transformers: display_transformers
15641
16711
  });
15642
16712
  const previous_searches = $21f51c14cb3f586f$export$84bba84a7b837187(get_search_query_);
@@ -16521,4 +17591,4 @@ function $442f32a4d80abbde$export$e2bf8ce7779e827e(props) {
16521
17591
  }, "Entire CategoryPage failed");
16522
17592
  }
16523
17593
  $9HbP8$add_to_version_info("ui", (0, $ec291e0010116877$export$83d89fbfd8236492));
16524
- 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 };
17594
+ 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 };