@depict-ai/ui 1.1.5 → 1.2.1
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/dist/client/main.cjs +139 -49
- package/dist/client/module.js +140 -50
- package/dist/index.d.ts +220 -121
- package/dist/server/main.cjs +139 -49
- package/dist/server/module.js +140 -50
- package/dist/tsconfig2.tsbuildinfo +1 -0
- package/package.json +4 -4
- package/dist/client/main.js +0 -9068
- package/dist/server/main.js +0 -8063
- package/locales/require.js +0 -1154
package/dist/client/main.cjs
CHANGED
|
@@ -43,7 +43,7 @@ $parcel$export(module.exports, "defaultGridSpacing", () => $a3280f0aad997933$exp
|
|
|
43
43
|
$parcel$export(module.exports, "defaultColsAtSize", () => $a3280f0aad997933$export$c3834fa86c616831);
|
|
44
44
|
$parcel$export(module.exports, "defaultCategoryTitlePlugin", () => $a3280f0aad997933$export$7bf543b9d9be2c22);
|
|
45
45
|
$parcel$export(module.exports, "version", () => $b757f75811f3261f$export$83d89fbfd8236492);
|
|
46
|
-
/*! Depict.ai search and product listing SDK */ const $b757f75811f3261f$export$83d89fbfd8236492 = "1.1
|
|
46
|
+
/*! Depict.ai search and product listing SDK */ const $b757f75811f3261f$export$83d89fbfd8236492 = "1.2.1";
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
|
@@ -244,26 +244,77 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
244
244
|
#get_metadata;
|
|
245
245
|
#get_user_id;
|
|
246
246
|
#get_session_id;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
247
|
+
#guard_url_creator_length(expected, received) {
|
|
248
|
+
if (expected.length !== received.length) {
|
|
249
|
+
const e = new Error("Page URL creator returned wrong number of page URLs, got " + received.length + ", expected " + expected.length);
|
|
250
|
+
queueMicrotask(()=>{
|
|
251
|
+
throw e;
|
|
252
|
+
});
|
|
253
|
+
throw e;
|
|
254
|
+
}
|
|
251
255
|
}
|
|
252
|
-
async
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
async #run_url_creator_for_suggest(merchant, market, response) {
|
|
257
|
+
if (!this.page_url_creator) return response;
|
|
258
|
+
// find category suggestions, run thing with them, and then replace them
|
|
259
|
+
const category_suggestions = response.suggestions.filter((suggestion)=>suggestion.type === "category");
|
|
260
|
+
const page_urls = await this.page_url_creator({
|
|
261
|
+
type: "categories",
|
|
262
|
+
market: market,
|
|
263
|
+
merchant: merchant,
|
|
264
|
+
data: [
|
|
265
|
+
...category_suggestions
|
|
266
|
+
]
|
|
267
|
+
});
|
|
268
|
+
this.#guard_url_creator_length(category_suggestions, page_urls);
|
|
269
|
+
while(page_urls.length)Object.assign(category_suggestions.pop(), page_urls.pop());
|
|
270
|
+
return response;
|
|
271
|
+
}
|
|
272
|
+
async #run_url_creator_for_rest(merchant1, market1, input_data) {
|
|
273
|
+
if (!this.page_url_creator) return input_data;
|
|
274
|
+
const displays = input_data.displays;
|
|
275
|
+
const breadcrumb = input_data.breadcrumb;
|
|
276
|
+
const quick_links = input_data.quick_links;
|
|
277
|
+
if (displays) {
|
|
278
|
+
const page_urls = await this.page_url_creator({
|
|
279
|
+
type: "products",
|
|
280
|
+
merchant: merchant1,
|
|
281
|
+
market: market1,
|
|
282
|
+
displays: [
|
|
283
|
+
...input_data.displays
|
|
284
|
+
]
|
|
285
|
+
});
|
|
286
|
+
this.#guard_url_creator_length(displays, page_urls);
|
|
287
|
+
for(let i = 0; i < displays.length; i++){
|
|
288
|
+
const new_display_or_page_url = page_urls[i];
|
|
289
|
+
const old_display = displays[i];
|
|
290
|
+
if ("page_url" in new_display_or_page_url && Object.keys(new_display_or_page_url).length === 1) {
|
|
291
|
+
// they only returned page_url, let's put it into the display
|
|
292
|
+
const old_display_was_modern = "variant_index" in old_display;
|
|
293
|
+
if (old_display_was_modern) {
|
|
294
|
+
const variant_displays = old_display.variant_displays;
|
|
295
|
+
for(let i = 0; i < variant_displays.length; i++)variant_displays[i].page_url = new_display_or_page_url.page_url;
|
|
296
|
+
} else old_display.page_url = new_display_or_page_url.page_url;
|
|
297
|
+
} else // We got a whole new display, let's replace it
|
|
298
|
+
displays[i] = new_display_or_page_url;
|
|
299
|
+
}
|
|
261
300
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
301
|
+
for (const category_display_array of [
|
|
302
|
+
breadcrumb,
|
|
303
|
+
quick_links
|
|
304
|
+
]){
|
|
305
|
+
if (!category_display_array) continue;
|
|
306
|
+
const page_urls = await this.page_url_creator({
|
|
307
|
+
type: "categories",
|
|
308
|
+
merchant: merchant1,
|
|
309
|
+
market: market1,
|
|
310
|
+
data: [
|
|
311
|
+
...category_display_array
|
|
312
|
+
]
|
|
313
|
+
});
|
|
314
|
+
this.#guard_url_creator_length(category_display_array, page_urls);
|
|
315
|
+
for(let i = 0; i < category_display_array.length; i++)Object.assign(category_display_array[i], page_urls[i]);
|
|
316
|
+
}
|
|
317
|
+
return input_data;
|
|
267
318
|
}
|
|
268
319
|
async #cached_post_request(endpoint1, input_req, fallback_response) {
|
|
269
320
|
const cache_obj = this.#get_cache_obj_for_endpoint(endpoint1);
|
|
@@ -280,66 +331,101 @@ class $e1d6c0f3d89d531c$export$e015ed2f2950f2e3 {
|
|
|
280
331
|
let resolve_in_progress;
|
|
281
332
|
cache_obj.in_progress_[body] = new Promise((r)=>resolve_in_progress = r);
|
|
282
333
|
try {
|
|
283
|
-
let
|
|
334
|
+
let api_response = await (0, $57o7A$depictaiutilishared.fetch_retry)((0, $57o7A$depictaiutilishared.add_version_query_params)(endpoint1), {
|
|
284
335
|
method: "POST",
|
|
285
336
|
body: body
|
|
286
337
|
});
|
|
287
338
|
if ("query_id" in request && request.type === "collection") // FIXME: Remove. Backwards compatibility layer
|
|
288
339
|
// This will retry the request without the collection type if the first request fails
|
|
289
340
|
{
|
|
290
|
-
if (!
|
|
341
|
+
if (!api_response || api_response?.status === 404) {
|
|
291
342
|
(0, $57o7A$depictaiutilishared.dlog)("Fallback request for collections due to failure");
|
|
292
343
|
const fallback_body = JSON.parse(body);
|
|
293
344
|
delete fallback_body.type;
|
|
294
|
-
|
|
345
|
+
api_response = await (0, $57o7A$depictaiutilishared.fetch_retry)((0, $57o7A$depictaiutilishared.add_version_query_params)(endpoint1), {
|
|
295
346
|
method: "POST",
|
|
296
347
|
body: JSON.stringify(fallback_body)
|
|
297
348
|
});
|
|
298
349
|
}
|
|
299
350
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
351
|
+
return_successfully: {
|
|
352
|
+
if (!api_response || api_response.status !== 200) break return_successfully;
|
|
353
|
+
let result;
|
|
354
|
+
try {
|
|
355
|
+
const unmodified_result = await api_response.json();
|
|
356
|
+
result = await this.#run_url_creator_for_rest(input_req.tenant, input_req.market, unmodified_result);
|
|
357
|
+
} catch (e) {
|
|
358
|
+
(0, $57o7A$depictaiutilishared.dwarn)("URL creator or json decoding failed", e);
|
|
359
|
+
break return_successfully;
|
|
360
|
+
}
|
|
361
|
+
cache_obj.cache_[body] = new WeakRef(result);
|
|
362
|
+
resolve_in_progress(result);
|
|
363
|
+
setTimeout((0, $57o7A$depictaiutilishared.catchify)(()=>{
|
|
364
|
+
if (this.#supports_finalization_registry) cache_obj.finalization_registry_.register(result, body); // delete key from cache when value (WeakRefs) are collected
|
|
365
|
+
else // delete things from cache after 5 minutes, so it doesn't get too heavy
|
|
366
|
+
setTimeout((0, $57o7A$depictaiutilishared.catchify)(()=>delete cache_obj.cache_[body]), 300000);
|
|
367
|
+
}), 60000 // cache values for at least 60 seconds
|
|
368
|
+
);
|
|
369
|
+
return result;
|
|
304
370
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
resolve_in_progress(
|
|
308
|
-
|
|
309
|
-
if (this.#supports_finalization_registry) cache_obj.finalization_registry_.register(result, body); // delete key from cache when value (WeakRefs) are collected
|
|
310
|
-
else // delete things from cache after 5 minutes, so it doesn't get too heavy
|
|
311
|
-
setTimeout((0, $57o7A$depictaiutilishared.catchify)(()=>delete cache_obj.cache_[body]), 300000);
|
|
312
|
-
}), 60000 // cache values for at least 60 seconds
|
|
313
|
-
);
|
|
314
|
-
return result;
|
|
371
|
+
// If we get here, the request failed
|
|
372
|
+
const retval = fallback_response(input_req);
|
|
373
|
+
resolve_in_progress(retval);
|
|
374
|
+
return retval;
|
|
315
375
|
} finally{
|
|
316
376
|
delete cache_obj.in_progress_[body];
|
|
317
377
|
}
|
|
318
378
|
}
|
|
379
|
+
constructor(options){
|
|
380
|
+
const { get_metadata: get_metadata , get_user_id: get_user_id , get_session_id: get_session_id , page_url_creator: page_url_creator } = options ?? {};
|
|
381
|
+
this.#get_metadata = get_metadata;
|
|
382
|
+
this.#get_user_id = get_user_id;
|
|
383
|
+
this.#get_session_id = get_session_id;
|
|
384
|
+
this.page_url_creator = page_url_creator;
|
|
385
|
+
}
|
|
386
|
+
async suggest(input_req) {
|
|
387
|
+
const request = this.#add_ids_to_request(input_req);
|
|
388
|
+
const url = (0, $57o7A$depictaiutilishared.make_url_with_query_params)($e1d6c0f3d89d531c$var$search_base_url + "suggestions", request);
|
|
389
|
+
const results = await (0, $57o7A$depictaiutilishared.fetch_retry)((0, $57o7A$depictaiutilishared.add_version_query_params)(url));
|
|
390
|
+
attempt_to_return_api_response: {
|
|
391
|
+
if (!results) break attempt_to_return_api_response;
|
|
392
|
+
const decoded_json = await results.json();
|
|
393
|
+
if (!Array.isArray(decoded_json?.suggestions)) break attempt_to_return_api_response;
|
|
394
|
+
try {
|
|
395
|
+
return await this.#run_url_creator_for_suggest(input_req.tenant, input_req.market, decoded_json);
|
|
396
|
+
} catch (e) {
|
|
397
|
+
(0, $57o7A$depictaiutilishared.dwarn)("URL creator failed", e);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
"suggestions_request_id": "error",
|
|
402
|
+
"suggestions": [],
|
|
403
|
+
failed: true
|
|
404
|
+
};
|
|
405
|
+
}
|
|
319
406
|
async query(input_req) {
|
|
320
|
-
return await this.#cached_post_request($e1d6c0f3d89d531c$var$search_base_url + "results", input_req, (
|
|
407
|
+
return await this.#cached_post_request($e1d6c0f3d89d531c$var$search_base_url + "results", input_req, ()=>({
|
|
321
408
|
"n_hits": 0,
|
|
322
|
-
"page": request.page ?? 1,
|
|
323
409
|
"displays": [],
|
|
324
|
-
"
|
|
325
|
-
"
|
|
410
|
+
"sorts": [],
|
|
411
|
+
"filters": [],
|
|
326
412
|
"search_request_id": "error",
|
|
327
413
|
failed: true
|
|
328
414
|
}));
|
|
329
415
|
}
|
|
330
416
|
async list(input_req) {
|
|
331
|
-
return await this.#cached_post_request($e1d6c0f3d89d531c$var$v2_base_url + "product-listing", input_req, (
|
|
417
|
+
return await this.#cached_post_request($e1d6c0f3d89d531c$var$v2_base_url + "product-listing", input_req, ()=>({
|
|
332
418
|
"n_hits": 0,
|
|
333
|
-
"page": request.page ?? 1,
|
|
334
419
|
"displays": [],
|
|
335
|
-
"
|
|
336
|
-
"
|
|
420
|
+
"sorts": [],
|
|
421
|
+
"filters": [],
|
|
422
|
+
"breadcrumb": [],
|
|
423
|
+
"quick_links": [],
|
|
337
424
|
"product_listing_request_id": "error",
|
|
338
425
|
failed: true
|
|
339
426
|
}));
|
|
340
427
|
}
|
|
341
428
|
async get_recommended(input_req) {
|
|
342
|
-
// @ts-ignore ModernDisplay doesn't have arbitrary string access, and we'd like it to stay that way
|
|
343
429
|
return await this.#cached_post_request($e1d6c0f3d89d531c$var$search_base_url + "related", input_req, ()=>({
|
|
344
430
|
displays: []
|
|
345
431
|
}));
|
|
@@ -6009,7 +6095,7 @@ class $48567ac5b39bac56$export$f34314aa9505732e {
|
|
|
6009
6095
|
set on_navigation(new_function) {
|
|
6010
6096
|
this.#router.on_navigation_ = new_function;
|
|
6011
6097
|
}
|
|
6012
|
-
constructor({ api: api , on_navigation: on_navigation , ...props_on_class }){
|
|
6098
|
+
constructor({ api: api , on_navigation: on_navigation , page_url_creator: page_url_creator , ...props_on_class }){
|
|
6013
6099
|
const owner = (0, $57o7A$solidjs.getOwner)() || (0, $57o7A$solidjs.createRoot)(()=>(0, $57o7A$solidjs.getOwner)()); // we might have an owner, if so, pass it on. Otherwise, create one so solid doesn't print warnings to the console
|
|
6014
6100
|
(0, $57o7A$solidjs.runWithOwner)(owner, ()=>{
|
|
6015
6101
|
if ($48567ac5b39bac56$export$f34314aa9505732e.#has_been_constructed && !(0, $57o7A$solidjsweb.isServer)) // on the server we can't write stuff to history.state anyway so can have multiple
|
|
@@ -6037,7 +6123,9 @@ class $48567ac5b39bac56$export$f34314aa9505732e {
|
|
|
6037
6123
|
quicklinks_signal_: (0, $57o7A$solidjs.createSignal)(),
|
|
6038
6124
|
i18n_: i18n_,
|
|
6039
6125
|
reset_history_state_: reset_history_state_,
|
|
6040
|
-
depict_api_: api ?? new (0, $e1d6c0f3d89d531c$export$e015ed2f2950f2e3)(
|
|
6126
|
+
depict_api_: api ?? new (0, $e1d6c0f3d89d531c$export$e015ed2f2950f2e3)({
|
|
6127
|
+
page_url_creator: page_url_creator
|
|
6128
|
+
}),
|
|
6041
6129
|
router_: this.#router,
|
|
6042
6130
|
selected_filters_: selected_filters_,
|
|
6043
6131
|
current_sorting_: current_sorting_,
|
|
@@ -8438,7 +8526,7 @@ class $2c61e4cd8229c49a$export$ac6237957a15b3f0 {
|
|
|
8438
8526
|
#modal_open_signal = (0, $57o7A$solidjs.createSignal)(false);
|
|
8439
8527
|
static #has_been_constructed = false;
|
|
8440
8528
|
#router = new (0, $e96dd13889871fc0$export$7e1297a3a19f10d8)("hard_navigation");
|
|
8441
|
-
constructor({ search_query_url_param_name: search_query_url_param_name_ = "query" , url_transformer: url_transformer , on_navigation: on_navigation , enable_category_suggestions: enable_category_suggestions = true , disable_scrolling_during_modal: // Stuff needed for non-standard customer deployments that we shouldn't actually expose
|
|
8529
|
+
constructor({ search_query_url_param_name: search_query_url_param_name_ = "query" , url_transformer: url_transformer , on_navigation: on_navigation , enable_category_suggestions: enable_category_suggestions = true , page_url_creator: page_url_creator , disable_scrolling_during_modal: // Stuff needed for non-standard customer deployments that we shouldn't actually expose
|
|
8442
8530
|
disable_scrolling_during_modal = true , api: api , bottom_distance_under_modal: bottom_distance_under_modal , render_instant_card: render_instant_card , ...props_on_class }){
|
|
8443
8531
|
const owner = (0, $57o7A$solidjs.getOwner)() || (0, $57o7A$solidjs.createRoot)(()=>(0, $57o7A$solidjs.getOwner)()); // we might have an owner, if so, pass it on. Otherwise, create one so solid doesn't print warnings to the console
|
|
8444
8532
|
(0, $57o7A$solidjs.runWithOwner)(owner, ()=>{
|
|
@@ -8467,7 +8555,9 @@ class $2c61e4cd8229c49a$export$ac6237957a15b3f0 {
|
|
|
8467
8555
|
if (get_search_query_updating_blocked()) return previous_value;
|
|
8468
8556
|
else return raw_search_query_accessor();
|
|
8469
8557
|
});
|
|
8470
|
-
const depict_api_ = api ?? new (0, $e1d6c0f3d89d531c$export$e015ed2f2950f2e3)(
|
|
8558
|
+
const depict_api_ = api ?? new (0, $e1d6c0f3d89d531c$export$e015ed2f2950f2e3)({
|
|
8559
|
+
page_url_creator: page_url_creator
|
|
8560
|
+
});
|
|
8471
8561
|
const previous_searches = (0, $2b7a005a65221045$export$84bba84a7b837187)(get_search_query_);
|
|
8472
8562
|
const [, set_search_showing_recommendation_rows] = state_.search_showing_recommendation_rows;
|
|
8473
8563
|
const after_submit_ = ()=>set_search_showing_recommendation_rows((0, $fb29c6201c369e39$export$1c8c715550dc689d)); // do this every time after we have submitted a new query - otherwise there might already be a saved number of rows in the state
|
package/dist/client/module.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {add_to_version_info as $gco9i$add_to_version_info, observer as $gco9i$observer, catchify as $gco9i$catchify, fetch_recs as $gco9i$fetch_recs, snakeCasifyObject as $gco9i$snakeCasifyObject, instant_exec_on_suspect_history_change as $gco9i$instant_exec_on_suspect_history_change, base_url as $gco9i$base_url, dlog as $gco9i$dlog, get_depict_id as $gco9i$get_depict_id, get_user_id as $gco9i$get_user_id, get_session_id as $gco9i$get_session_id,
|
|
1
|
+
import {add_to_version_info as $gco9i$add_to_version_info, observer as $gco9i$observer, catchify as $gco9i$catchify, fetch_recs as $gco9i$fetch_recs, snakeCasifyObject as $gco9i$snakeCasifyObject, instant_exec_on_suspect_history_change as $gco9i$instant_exec_on_suspect_history_change, base_url as $gco9i$base_url, dlog as $gco9i$dlog, get_depict_id as $gco9i$get_depict_id, get_user_id as $gco9i$get_user_id, get_session_id as $gco9i$get_session_id, sort_obj as $gco9i$sort_obj, fetch_retry as $gco9i$fetch_retry, add_version_query_params as $gco9i$add_version_query_params, dwarn as $gco9i$dwarn, make_url_with_query_params as $gco9i$make_url_with_query_params, report as $gco9i$report, javascript_media_query as $gco9i$javascript_media_query, standard_price_format as $gco9i$standard_price_format, make_random_classname as $gco9i$make_random_classname, n_col_styling_with_dist as $gco9i$n_col_styling_with_dist, useExpandingContainer as $gco9i$useExpandingContainer, Amazing_Slider as $gco9i$Amazing_Slider, slider_snap_css as $gco9i$slider_snap_css, slider_fading_factory as $gco9i$slider_fading_factory, hsl_to_rgb as $gco9i$hsl_to_rgb, relative_luminance_from_rgb as $gco9i$relative_luminance_from_rgb, base64_encode_unicode as $gco9i$base64_encode_unicode, base64_decode_unicode as $gco9i$base64_decode_unicode, queueMacroTask as $gco9i$queueMacroTask, is_debug as $gco9i$is_debug, Layout as $gco9i$Layout, async_iterable_ipns as $gco9i$async_iterable_ipns, make_asyncIterable_exiter as $gco9i$make_asyncIterable_exiter, href_change_ipns as $gco9i$href_change_ipns, ContainedImage as $gco9i$ContainedImage, buildThresholdList as $gco9i$buildThresholdList, deparallelize_no_drop as $gco9i$deparallelize_no_drop, insert_surfaces as $gco9i$insert_surfaces} from "@depict-ai/utilishared";
|
|
2
2
|
import {createRoot as $gco9i$createRoot, createSignal as $gco9i$createSignal, getOwner as $gco9i$getOwner, runWithOwner as $gco9i$runWithOwner, onCleanup as $gco9i$onCleanup, createComputed as $gco9i$createComputed, createRenderEffect as $gco9i$createRenderEffect, createEffect as $gco9i$createEffect, untrack as $gco9i$untrack, batch as $gco9i$batch, createResource as $gco9i$createResource, createMemo as $gco9i$createMemo, Show as $gco9i$Show, createReaction as $gco9i$createReaction, Suspense as $gco9i$Suspense, on as $gco9i$on, ErrorBoundary as $gco9i$ErrorBoundary, For as $gco9i$For, Index as $gco9i$Index} from "solid-js";
|
|
3
3
|
import {template as $gco9i$template, getNextElement as $gco9i$getNextElement, spread as $gco9i$spread, mergeProps as $gco9i$mergeProps, runHydrationEvents as $gco9i$runHydrationEvents, effect as $gco9i$effect, setAttribute as $gco9i$setAttribute, insert as $gco9i$insert, isServer as $gco9i$isServer, createComponent as $gco9i$createComponent, getNextMarker as $gco9i$getNextMarker, use as $gco9i$use, memo as $gco9i$memo, addEventListener as $gco9i$addEventListener, delegateEvents as $gco9i$delegateEvents, classList as $gco9i$classList, style as $gco9i$style, className as $gco9i$className, Dynamic as $gco9i$Dynamic} from "solid-js/web";
|
|
4
4
|
|
|
5
|
-
/*! Depict.ai search and product listing SDK */ const $ec291e0010116877$export$83d89fbfd8236492 = "1.1
|
|
5
|
+
/*! Depict.ai search and product listing SDK */ const $ec291e0010116877$export$83d89fbfd8236492 = "1.2.1";
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -203,26 +203,77 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
|
|
|
203
203
|
#get_metadata;
|
|
204
204
|
#get_user_id;
|
|
205
205
|
#get_session_id;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
#guard_url_creator_length(expected, received) {
|
|
207
|
+
if (expected.length !== received.length) {
|
|
208
|
+
const e = new Error("Page URL creator returned wrong number of page URLs, got " + received.length + ", expected " + expected.length);
|
|
209
|
+
queueMicrotask(()=>{
|
|
210
|
+
throw e;
|
|
211
|
+
});
|
|
212
|
+
throw e;
|
|
213
|
+
}
|
|
210
214
|
}
|
|
211
|
-
async
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
async #run_url_creator_for_suggest(merchant, market, response) {
|
|
216
|
+
if (!this.page_url_creator) return response;
|
|
217
|
+
// find category suggestions, run thing with them, and then replace them
|
|
218
|
+
const category_suggestions = response.suggestions.filter((suggestion)=>suggestion.type === "category");
|
|
219
|
+
const page_urls = await this.page_url_creator({
|
|
220
|
+
type: "categories",
|
|
221
|
+
market: market,
|
|
222
|
+
merchant: merchant,
|
|
223
|
+
data: [
|
|
224
|
+
...category_suggestions
|
|
225
|
+
]
|
|
226
|
+
});
|
|
227
|
+
this.#guard_url_creator_length(category_suggestions, page_urls);
|
|
228
|
+
while(page_urls.length)Object.assign(category_suggestions.pop(), page_urls.pop());
|
|
229
|
+
return response;
|
|
230
|
+
}
|
|
231
|
+
async #run_url_creator_for_rest(merchant1, market1, input_data) {
|
|
232
|
+
if (!this.page_url_creator) return input_data;
|
|
233
|
+
const displays = input_data.displays;
|
|
234
|
+
const breadcrumb = input_data.breadcrumb;
|
|
235
|
+
const quick_links = input_data.quick_links;
|
|
236
|
+
if (displays) {
|
|
237
|
+
const page_urls = await this.page_url_creator({
|
|
238
|
+
type: "products",
|
|
239
|
+
merchant: merchant1,
|
|
240
|
+
market: market1,
|
|
241
|
+
displays: [
|
|
242
|
+
...input_data.displays
|
|
243
|
+
]
|
|
244
|
+
});
|
|
245
|
+
this.#guard_url_creator_length(displays, page_urls);
|
|
246
|
+
for(let i = 0; i < displays.length; i++){
|
|
247
|
+
const new_display_or_page_url = page_urls[i];
|
|
248
|
+
const old_display = displays[i];
|
|
249
|
+
if ("page_url" in new_display_or_page_url && Object.keys(new_display_or_page_url).length === 1) {
|
|
250
|
+
// they only returned page_url, let's put it into the display
|
|
251
|
+
const old_display_was_modern = "variant_index" in old_display;
|
|
252
|
+
if (old_display_was_modern) {
|
|
253
|
+
const variant_displays = old_display.variant_displays;
|
|
254
|
+
for(let i = 0; i < variant_displays.length; i++)variant_displays[i].page_url = new_display_or_page_url.page_url;
|
|
255
|
+
} else old_display.page_url = new_display_or_page_url.page_url;
|
|
256
|
+
} else // We got a whole new display, let's replace it
|
|
257
|
+
displays[i] = new_display_or_page_url;
|
|
258
|
+
}
|
|
220
259
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
260
|
+
for (const category_display_array of [
|
|
261
|
+
breadcrumb,
|
|
262
|
+
quick_links
|
|
263
|
+
]){
|
|
264
|
+
if (!category_display_array) continue;
|
|
265
|
+
const page_urls = await this.page_url_creator({
|
|
266
|
+
type: "categories",
|
|
267
|
+
merchant: merchant1,
|
|
268
|
+
market: market1,
|
|
269
|
+
data: [
|
|
270
|
+
...category_display_array
|
|
271
|
+
]
|
|
272
|
+
});
|
|
273
|
+
this.#guard_url_creator_length(category_display_array, page_urls);
|
|
274
|
+
for(let i = 0; i < category_display_array.length; i++)Object.assign(category_display_array[i], page_urls[i]);
|
|
275
|
+
}
|
|
276
|
+
return input_data;
|
|
226
277
|
}
|
|
227
278
|
async #cached_post_request(endpoint1, input_req, fallback_response) {
|
|
228
279
|
const cache_obj = this.#get_cache_obj_for_endpoint(endpoint1);
|
|
@@ -239,66 +290,101 @@ class $7fa23e2a0079eca4$export$e015ed2f2950f2e3 {
|
|
|
239
290
|
let resolve_in_progress;
|
|
240
291
|
cache_obj.in_progress_[body] = new Promise((r)=>resolve_in_progress = r);
|
|
241
292
|
try {
|
|
242
|
-
let
|
|
293
|
+
let api_response = await (0, $gco9i$fetch_retry)((0, $gco9i$add_version_query_params)(endpoint1), {
|
|
243
294
|
method: "POST",
|
|
244
295
|
body: body
|
|
245
296
|
});
|
|
246
297
|
if ("query_id" in request && request.type === "collection") // FIXME: Remove. Backwards compatibility layer
|
|
247
298
|
// This will retry the request without the collection type if the first request fails
|
|
248
299
|
{
|
|
249
|
-
if (!
|
|
300
|
+
if (!api_response || api_response?.status === 404) {
|
|
250
301
|
(0, $gco9i$dlog)("Fallback request for collections due to failure");
|
|
251
302
|
const fallback_body = JSON.parse(body);
|
|
252
303
|
delete fallback_body.type;
|
|
253
|
-
|
|
304
|
+
api_response = await (0, $gco9i$fetch_retry)((0, $gco9i$add_version_query_params)(endpoint1), {
|
|
254
305
|
method: "POST",
|
|
255
306
|
body: JSON.stringify(fallback_body)
|
|
256
307
|
});
|
|
257
308
|
}
|
|
258
309
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
310
|
+
return_successfully: {
|
|
311
|
+
if (!api_response || api_response.status !== 200) break return_successfully;
|
|
312
|
+
let result;
|
|
313
|
+
try {
|
|
314
|
+
const unmodified_result = await api_response.json();
|
|
315
|
+
result = await this.#run_url_creator_for_rest(input_req.tenant, input_req.market, unmodified_result);
|
|
316
|
+
} catch (e) {
|
|
317
|
+
(0, $gco9i$dwarn)("URL creator or json decoding failed", e);
|
|
318
|
+
break return_successfully;
|
|
319
|
+
}
|
|
320
|
+
cache_obj.cache_[body] = new WeakRef(result);
|
|
321
|
+
resolve_in_progress(result);
|
|
322
|
+
setTimeout((0, $gco9i$catchify)(()=>{
|
|
323
|
+
if (this.#supports_finalization_registry) cache_obj.finalization_registry_.register(result, body); // delete key from cache when value (WeakRefs) are collected
|
|
324
|
+
else // delete things from cache after 5 minutes, so it doesn't get too heavy
|
|
325
|
+
setTimeout((0, $gco9i$catchify)(()=>delete cache_obj.cache_[body]), 300000);
|
|
326
|
+
}), 60000 // cache values for at least 60 seconds
|
|
327
|
+
);
|
|
328
|
+
return result;
|
|
263
329
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
resolve_in_progress(
|
|
267
|
-
|
|
268
|
-
if (this.#supports_finalization_registry) cache_obj.finalization_registry_.register(result, body); // delete key from cache when value (WeakRefs) are collected
|
|
269
|
-
else // delete things from cache after 5 minutes, so it doesn't get too heavy
|
|
270
|
-
setTimeout((0, $gco9i$catchify)(()=>delete cache_obj.cache_[body]), 300000);
|
|
271
|
-
}), 60000 // cache values for at least 60 seconds
|
|
272
|
-
);
|
|
273
|
-
return result;
|
|
330
|
+
// If we get here, the request failed
|
|
331
|
+
const retval = fallback_response(input_req);
|
|
332
|
+
resolve_in_progress(retval);
|
|
333
|
+
return retval;
|
|
274
334
|
} finally{
|
|
275
335
|
delete cache_obj.in_progress_[body];
|
|
276
336
|
}
|
|
277
337
|
}
|
|
338
|
+
constructor(options){
|
|
339
|
+
const { get_metadata: get_metadata , get_user_id: get_user_id , get_session_id: get_session_id , page_url_creator: page_url_creator } = options ?? {};
|
|
340
|
+
this.#get_metadata = get_metadata;
|
|
341
|
+
this.#get_user_id = get_user_id;
|
|
342
|
+
this.#get_session_id = get_session_id;
|
|
343
|
+
this.page_url_creator = page_url_creator;
|
|
344
|
+
}
|
|
345
|
+
async suggest(input_req) {
|
|
346
|
+
const request = this.#add_ids_to_request(input_req);
|
|
347
|
+
const url = (0, $gco9i$make_url_with_query_params)($7fa23e2a0079eca4$var$search_base_url + "suggestions", request);
|
|
348
|
+
const results = await (0, $gco9i$fetch_retry)((0, $gco9i$add_version_query_params)(url));
|
|
349
|
+
attempt_to_return_api_response: {
|
|
350
|
+
if (!results) break attempt_to_return_api_response;
|
|
351
|
+
const decoded_json = await results.json();
|
|
352
|
+
if (!Array.isArray(decoded_json?.suggestions)) break attempt_to_return_api_response;
|
|
353
|
+
try {
|
|
354
|
+
return await this.#run_url_creator_for_suggest(input_req.tenant, input_req.market, decoded_json);
|
|
355
|
+
} catch (e) {
|
|
356
|
+
(0, $gco9i$dwarn)("URL creator failed", e);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
"suggestions_request_id": "error",
|
|
361
|
+
"suggestions": [],
|
|
362
|
+
failed: true
|
|
363
|
+
};
|
|
364
|
+
}
|
|
278
365
|
async query(input_req) {
|
|
279
|
-
return await this.#cached_post_request($7fa23e2a0079eca4$var$search_base_url + "results", input_req, (
|
|
366
|
+
return await this.#cached_post_request($7fa23e2a0079eca4$var$search_base_url + "results", input_req, ()=>({
|
|
280
367
|
"n_hits": 0,
|
|
281
|
-
"page": request.page ?? 1,
|
|
282
368
|
"displays": [],
|
|
283
|
-
"
|
|
284
|
-
"
|
|
369
|
+
"sorts": [],
|
|
370
|
+
"filters": [],
|
|
285
371
|
"search_request_id": "error",
|
|
286
372
|
failed: true
|
|
287
373
|
}));
|
|
288
374
|
}
|
|
289
375
|
async list(input_req) {
|
|
290
|
-
return await this.#cached_post_request($7fa23e2a0079eca4$var$v2_base_url + "product-listing", input_req, (
|
|
376
|
+
return await this.#cached_post_request($7fa23e2a0079eca4$var$v2_base_url + "product-listing", input_req, ()=>({
|
|
291
377
|
"n_hits": 0,
|
|
292
|
-
"page": request.page ?? 1,
|
|
293
378
|
"displays": [],
|
|
294
|
-
"
|
|
295
|
-
"
|
|
379
|
+
"sorts": [],
|
|
380
|
+
"filters": [],
|
|
381
|
+
"breadcrumb": [],
|
|
382
|
+
"quick_links": [],
|
|
296
383
|
"product_listing_request_id": "error",
|
|
297
384
|
failed: true
|
|
298
385
|
}));
|
|
299
386
|
}
|
|
300
387
|
async get_recommended(input_req) {
|
|
301
|
-
// @ts-ignore ModernDisplay doesn't have arbitrary string access, and we'd like it to stay that way
|
|
302
388
|
return await this.#cached_post_request($7fa23e2a0079eca4$var$search_base_url + "related", input_req, ()=>({
|
|
303
389
|
displays: []
|
|
304
390
|
}));
|
|
@@ -5968,7 +6054,7 @@ class $961b5c64bef4662f$export$f34314aa9505732e {
|
|
|
5968
6054
|
set on_navigation(new_function) {
|
|
5969
6055
|
this.#router.on_navigation_ = new_function;
|
|
5970
6056
|
}
|
|
5971
|
-
constructor({ api: api , on_navigation: on_navigation , ...props_on_class }){
|
|
6057
|
+
constructor({ api: api , on_navigation: on_navigation , page_url_creator: page_url_creator , ...props_on_class }){
|
|
5972
6058
|
const owner = (0, $gco9i$getOwner)() || (0, $gco9i$createRoot)(()=>(0, $gco9i$getOwner)()); // we might have an owner, if so, pass it on. Otherwise, create one so solid doesn't print warnings to the console
|
|
5973
6059
|
(0, $gco9i$runWithOwner)(owner, ()=>{
|
|
5974
6060
|
if ($961b5c64bef4662f$export$f34314aa9505732e.#has_been_constructed && !(0, $gco9i$isServer)) // on the server we can't write stuff to history.state anyway so can have multiple
|
|
@@ -5996,7 +6082,9 @@ class $961b5c64bef4662f$export$f34314aa9505732e {
|
|
|
5996
6082
|
quicklinks_signal_: (0, $gco9i$createSignal)(),
|
|
5997
6083
|
i18n_: i18n_,
|
|
5998
6084
|
reset_history_state_: reset_history_state_,
|
|
5999
|
-
depict_api_: api ?? new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)(
|
|
6085
|
+
depict_api_: api ?? new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)({
|
|
6086
|
+
page_url_creator: page_url_creator
|
|
6087
|
+
}),
|
|
6000
6088
|
router_: this.#router,
|
|
6001
6089
|
selected_filters_: selected_filters_,
|
|
6002
6090
|
current_sorting_: current_sorting_,
|
|
@@ -8397,7 +8485,7 @@ class $806c97b931758897$export$ac6237957a15b3f0 {
|
|
|
8397
8485
|
#modal_open_signal = (0, $gco9i$createSignal)(false);
|
|
8398
8486
|
static #has_been_constructed = false;
|
|
8399
8487
|
#router = new (0, $4fd2ba03703a7d92$export$7e1297a3a19f10d8)("hard_navigation");
|
|
8400
|
-
constructor({ search_query_url_param_name: search_query_url_param_name_ = "query" , url_transformer: url_transformer , on_navigation: on_navigation , enable_category_suggestions: enable_category_suggestions = true , disable_scrolling_during_modal: // Stuff needed for non-standard customer deployments that we shouldn't actually expose
|
|
8488
|
+
constructor({ search_query_url_param_name: search_query_url_param_name_ = "query" , url_transformer: url_transformer , on_navigation: on_navigation , enable_category_suggestions: enable_category_suggestions = true , page_url_creator: page_url_creator , disable_scrolling_during_modal: // Stuff needed for non-standard customer deployments that we shouldn't actually expose
|
|
8401
8489
|
disable_scrolling_during_modal = true , api: api , bottom_distance_under_modal: bottom_distance_under_modal , render_instant_card: render_instant_card , ...props_on_class }){
|
|
8402
8490
|
const owner = (0, $gco9i$getOwner)() || (0, $gco9i$createRoot)(()=>(0, $gco9i$getOwner)()); // we might have an owner, if so, pass it on. Otherwise, create one so solid doesn't print warnings to the console
|
|
8403
8491
|
(0, $gco9i$runWithOwner)(owner, ()=>{
|
|
@@ -8426,7 +8514,9 @@ class $806c97b931758897$export$ac6237957a15b3f0 {
|
|
|
8426
8514
|
if (get_search_query_updating_blocked()) return previous_value;
|
|
8427
8515
|
else return raw_search_query_accessor();
|
|
8428
8516
|
});
|
|
8429
|
-
const depict_api_ = api ?? new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)(
|
|
8517
|
+
const depict_api_ = api ?? new (0, $7fa23e2a0079eca4$export$e015ed2f2950f2e3)({
|
|
8518
|
+
page_url_creator: page_url_creator
|
|
8519
|
+
});
|
|
8430
8520
|
const previous_searches = (0, $21f51c14cb3f586f$export$84bba84a7b837187)(get_search_query_);
|
|
8431
8521
|
const [, set_search_showing_recommendation_rows] = state_.search_showing_recommendation_rows;
|
|
8432
8522
|
const after_submit_ = ()=>set_search_showing_recommendation_rows((0, $172e1b898d457050$export$1c8c715550dc689d)); // do this every time after we have submitted a new query - otherwise there might already be a saved number of rows in the state
|