@nosto/search-js 2.5.0 → 2.7.0
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/{InfiniteScrollWithObserver-C3ILy8X_.cjs → InfiniteScrollWithObserver-D906VaKk.cjs} +1 -1
- package/dist/{InfiniteScrollWithObserver-DGZxUITY.js → InfiniteScrollWithObserver-DHIVa8bY.js} +1 -1
- package/dist/{baseConfig-BlLNh6Jn.cjs → baseConfig-BFFqFSg5.cjs} +1 -1
- package/dist/{baseConfig-XyA_9NDR.js → baseConfig-Bafl02NY.js} +1 -1
- package/dist/configContext-BR7w4VlU.cjs +1 -0
- package/dist/{configContext-CDTtcin_.js → configContext-GuZOIX3o.js} +18 -17
- package/dist/core/core.cjs.js +1 -1
- package/dist/core/core.es.js +1 -1
- package/dist/core/src/applyDecorators.d.ts +3 -21
- package/dist/{preact/src/search → core/src}/resultCaching.d.ts +2 -2
- package/dist/core/src/search.d.ts +2 -20
- package/dist/core/src/types.d.ts +7 -1
- package/dist/core/src/withCache.d.ts +3 -0
- package/dist/core/src/withRetries.d.ts +7 -0
- package/dist/deepMerge-CZwCJzEe.js +17 -0
- package/dist/deepMerge-lDscDfII.cjs +1 -0
- package/dist/logger-BcHMZObS.cjs +1 -0
- package/dist/logger-DVwg4Wor.js +42 -0
- package/dist/preact/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete.es.js +2 -2
- package/dist/preact/category.cjs.js +1 -1
- package/dist/preact/category.es.js +2 -2
- package/dist/preact/common.cjs.js +1 -1
- package/dist/preact/common.es.js +3 -3
- package/dist/preact/hooks.cjs.js +1 -1
- package/dist/preact/hooks.es.js +3 -3
- package/dist/preact/legacy.cjs.js +1 -1
- package/dist/preact/legacy.es.js +2 -2
- package/dist/preact/serp.cjs.js +1 -1
- package/dist/preact/serp.es.js +2 -2
- package/dist/preact/src/search/defaults.d.ts +3 -3
- package/dist/search-BgrZ1cY8.js +136 -0
- package/dist/search-Di9DRn5H.cjs +1 -0
- package/dist/useLoadMore-3isftdTM.cjs +1 -0
- package/dist/useLoadMore-4uB1MmI6.js +201 -0
- package/dist/utils/utils.cjs.js +1 -1
- package/dist/utils/utils.es.js +9 -9
- package/package.json +1 -1
- package/dist/configContext-CGXeJcqj.cjs +0 -1
- package/dist/core/src/searchWithRetries.d.ts +0 -7
- package/dist/isEqual-BzZ3d1JM.js +0 -41
- package/dist/isEqual-DQXR__da.cjs +0 -1
- package/dist/logger-DW5RVLX8.js +0 -17
- package/dist/logger-DbHGgDgO.cjs +0 -1
- package/dist/preact/src/search/searchWithCache.d.ts +0 -4
- package/dist/search-DJ_ktWg-.cjs +0 -1
- package/dist/search-DaZVHDP9.js +0 -44
- package/dist/useLoadMore-CHLvVMm8.js +0 -293
- package/dist/useLoadMore-Co6PDmam.cjs +0 -1
package/dist/{InfiniteScrollWithObserver-C3ILy8X_.cjs → InfiniteScrollWithObserver-D906VaKk.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const l=require("./jsxRuntime.module-B3sGoTIU.cjs"),p=require("./useLoadMore-
|
|
1
|
+
"use strict";const l=require("./jsxRuntime.module-B3sGoTIU.cjs"),p=require("./useLoadMore-3isftdTM.cjs"),a=require("./pick-rYi1lc2m.cjs"),d=require("preact/hooks"),b=require("preact");function f(s,i){var o,e,r;const t=((o=i.products)==null?void 0:o.total)??0,c=((e=s.products)==null?void 0:e.from)??0,n=((r=s.products)==null?void 0:r.size)??0;return t>0&&t>c+n}function h(){return!!(window.IntersectionObserver&&window.IntersectionObserverEntry&&"intersectionRatio"in window.IntersectionObserverEntry.prototype)}function O({children:s,pageSize:i}){const t=d.useRef(null),{query:c,response:n}=p.useNostoAppState(e=>a.pick(e,"query","response")),{loadMore:o}=p.useLoadMore(i);return d.useEffect(()=>{let e,r;return f(c,n)&&(e=t.current,r=new IntersectionObserver(v=>{const u=v[0];u!=null&&u.isIntersecting&&o()}),e&&r.observe(e)),()=>{e&&r.unobserve(e)}},[n]),l.u(b.Fragment,{children:[s,l.u("div",{ref:t,style:{height:"1px"}})]})}exports.InfiniteScrollWithObserver=O;exports.hasMoreResults=f;exports.intersectionObserverSupported=h;
|
package/dist/{InfiniteScrollWithObserver-DGZxUITY.js → InfiniteScrollWithObserver-DHIVa8bY.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as f } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { u as a, a as l } from "./useLoadMore-
|
|
2
|
+
import { u as a, a as l } from "./useLoadMore-4uB1MmI6.js";
|
|
3
3
|
import { p as d } from "./pick-DReBictn.js";
|
|
4
4
|
import { useRef as m, useEffect as v } from "preact/hooks";
|
|
5
5
|
import { Fragment as b } from "preact";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=require("./index.es-DlUp67LT.cjs"),o=require("./logger-
|
|
1
|
+
"use strict";const t=require("./index.es-DlUp67LT.cjs"),o=require("./logger-BcHMZObS.cjs"),i=require("preact/hooks");function s(){i.useEffect(()=>{const e=window.setTimeout(()=>{o.logger.error("Nosto client script has not loaded after 3 seconds.")},3e3);t.s(()=>{window.clearTimeout(e)})},[])}const r={defaultCurrency:"EUR",queryModifications:e=>e};exports.defaultBaseConfig=r;exports.useCheckClientScript=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=require("preact"),u=require("./deepMerge-lDscDfII.cjs"),E=require("./logger-BcHMZObS.cjs"),M=require("preact/hooks");function l(e,i={}){const r=new Map;let o=u.deepMergePlain(e,i??{});const d=u.deepMergePlain(e,i);function S(t){o=t(o);for(const n of r.values())n(o)}function x(t){S(n=>({...n,...t}))}function p(){return o}function h(){return structuredClone(d)}function q(t,n){let c;r.set(n,w=>{const a=t(w);E.isEqual(a,c)||(c=a,n(a))})}function b(t){r.delete(t)}return{updateState:x,getState:p,getInitialState:h,onChange:q,clearOnChange:b}}const f={loading:!0,query:{},response:{},initialized:!1};function g(e={}){return l(f,e)}const P=s.createContext(g()),C=s.createContext(null),k=()=>{const e=M.useContext(C);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e};exports.ConfigContext=C;exports.StoreContext=P;exports.createExtendableStore=l;exports.createStore=g;exports.defaultState=f;exports.useConfig=k;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createContext as c } from "preact";
|
|
2
|
-
import {
|
|
2
|
+
import { a as u } from "./deepMerge-CZwCJzEe.js";
|
|
3
|
+
import { i as x } from "./logger-DVwg4Wor.js";
|
|
3
4
|
import { useContext as h } from "preact/hooks";
|
|
4
|
-
function
|
|
5
|
+
function w(t, i = {}) {
|
|
5
6
|
const a = /* @__PURE__ */ new Map();
|
|
6
7
|
let o = u(t, i ?? {});
|
|
7
8
|
const f = u(t, i);
|
|
@@ -16,37 +17,37 @@ function b(t, i = {}) {
|
|
|
16
17
|
function g() {
|
|
17
18
|
return o;
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
+
function p() {
|
|
20
21
|
return structuredClone(f);
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
+
function d(e, n) {
|
|
23
24
|
let s;
|
|
24
|
-
a.set(n, (
|
|
25
|
-
const r = e(
|
|
25
|
+
a.set(n, (S) => {
|
|
26
|
+
const r = e(S);
|
|
26
27
|
x(r, s) || (s = r, n(r));
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
+
function m(e) {
|
|
30
31
|
a.delete(e);
|
|
31
32
|
}
|
|
32
33
|
return {
|
|
33
34
|
updateState: C,
|
|
34
35
|
getState: g,
|
|
35
|
-
getInitialState:
|
|
36
|
-
onChange:
|
|
37
|
-
clearOnChange:
|
|
36
|
+
getInitialState: p,
|
|
37
|
+
onChange: d,
|
|
38
|
+
clearOnChange: m
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
|
-
const
|
|
41
|
+
const b = {
|
|
41
42
|
loading: !0,
|
|
42
43
|
query: {},
|
|
43
44
|
response: {},
|
|
44
45
|
initialized: !1
|
|
45
46
|
};
|
|
46
47
|
function E(t = {}) {
|
|
47
|
-
return b
|
|
48
|
+
return w(b, t);
|
|
48
49
|
}
|
|
49
|
-
const
|
|
50
|
+
const y = c(E()), q = c(null), z = () => {
|
|
50
51
|
const t = h(q);
|
|
51
52
|
if (!t)
|
|
52
53
|
throw new Error("useConfig must be used within a ConfigProvider");
|
|
@@ -54,9 +55,9 @@ const v = c(E()), q = c(null), y = () => {
|
|
|
54
55
|
};
|
|
55
56
|
export {
|
|
56
57
|
q as C,
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
y as S,
|
|
59
|
+
w as a,
|
|
59
60
|
E as c,
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
b as d,
|
|
62
|
+
z as u
|
|
62
63
|
};
|
package/dist/core/core.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.es-DlUp67LT.cjs"),o=require("../search-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../index.es-DlUp67LT.cjs"),o=require("../search-Di9DRn5H.cjs");async function d(r,a,t=1){await e.L(a,void 0,t),await e.s(async c=>await c.recordSearchAddToCart(r,a))}exports.search=o.search;exports.addToCart=d;
|
package/dist/core/core.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { L as c, s as d } from "../index.es-B8mbAxS4.js";
|
|
2
|
-
import { s as f } from "../search-
|
|
2
|
+
import { s as f } from "../search-BgrZ1cY8.js";
|
|
3
3
|
async function e(r, a, o = 1) {
|
|
4
4
|
await c(a, void 0, o), await d(async (t) => await t.recordSearchAddToCart(r, a));
|
|
5
5
|
}
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HitDecorator } from './types';
|
|
3
|
-
export declare function applyDecorators<HD extends readonly HitDecorator[]>(
|
|
4
|
-
products: {
|
|
5
|
-
hits: import('./types').ToIntersection<ReturnType<HD[number]>>[];
|
|
6
|
-
categoryId?: string;
|
|
7
|
-
categoryPath?: string;
|
|
8
|
-
collapse?: string;
|
|
9
|
-
facets?: import('@nosto/nosto-js/client').SearchFacet[];
|
|
10
|
-
from?: number;
|
|
11
|
-
fuzzy?: boolean;
|
|
12
|
-
size?: number;
|
|
13
|
-
total: number;
|
|
14
|
-
};
|
|
15
|
-
autocorrect?: import('@nosto/nosto-js/client').SearchAutocorrect;
|
|
16
|
-
explain?: import('@nosto/nosto-js/client').SearchExplain;
|
|
17
|
-
keywords?: import('@nosto/nosto-js/client').SearchKeywords;
|
|
18
|
-
query?: string;
|
|
19
|
-
redirect?: string;
|
|
20
|
-
abTests?: import('@nosto/nosto-js/client').ABTest[];
|
|
21
|
-
};
|
|
1
|
+
import { SearchQuery } from '@nosto/nosto-js/client';
|
|
2
|
+
import { DecoratedResult, HitDecorator, SearchFn, SearchOptions } from './types';
|
|
3
|
+
export declare function applyDecorators<HD extends readonly HitDecorator[]>(query: SearchQuery, { hitDecorators, ...options }: SearchOptions<HD>, searchFn: SearchFn<HD>): Promise<DecoratedResult<HD>>;
|
|
@@ -4,8 +4,8 @@ export type SearchResultDto = {
|
|
|
4
4
|
query: ReturnType<typeof getCacheKey>;
|
|
5
5
|
result: SearchResult;
|
|
6
6
|
};
|
|
7
|
-
export declare function cacheSearchResult(
|
|
8
|
-
export declare function
|
|
7
|
+
export declare function cacheSearchResult(query: SearchQuery, result: SearchResult): void;
|
|
8
|
+
export declare function loadCachedResult(query: SearchQuery): SearchResult | null;
|
|
9
9
|
declare function getCacheKey(query: SearchQuery): SearchQuery;
|
|
10
10
|
export declare function isValueShapeCorrect(value: unknown): value is SearchResultDto;
|
|
11
11
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SearchQuery } from '@nosto/nosto-js/client';
|
|
2
|
-
import { HitDecorator, SearchOptions } from './types';
|
|
2
|
+
import { DecoratedResult, HitDecorator, SearchOptions } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Performs a search operation using the provided query and options.
|
|
5
5
|
*
|
|
@@ -7,22 +7,4 @@ import { HitDecorator, SearchOptions } from './types';
|
|
|
7
7
|
* @param options - An object containing optional parameters for the search.
|
|
8
8
|
* @returns A promise that resolves to the search result.
|
|
9
9
|
*/
|
|
10
|
-
export declare function search<HD extends readonly HitDecorator[]>(query: SearchQuery, options?: SearchOptions<HD>): Promise<
|
|
11
|
-
products: {
|
|
12
|
-
hits: import('./types').ToIntersection<ReturnType<HD[number]>>[];
|
|
13
|
-
categoryId?: string;
|
|
14
|
-
categoryPath?: string;
|
|
15
|
-
collapse?: string;
|
|
16
|
-
facets?: import('@nosto/nosto-js/client').SearchFacet[];
|
|
17
|
-
from?: number;
|
|
18
|
-
fuzzy?: boolean;
|
|
19
|
-
size?: number;
|
|
20
|
-
total: number;
|
|
21
|
-
};
|
|
22
|
-
autocorrect?: import('@nosto/nosto-js/client').SearchAutocorrect;
|
|
23
|
-
explain?: import('@nosto/nosto-js/client').SearchExplain;
|
|
24
|
-
keywords?: import('@nosto/nosto-js/client').SearchKeywords;
|
|
25
|
-
query?: string;
|
|
26
|
-
redirect?: string;
|
|
27
|
-
abTests?: import('@nosto/nosto-js/client').ABTest[];
|
|
28
|
-
}>;
|
|
10
|
+
export declare function search<HD extends readonly HitDecorator[]>(query: SearchQuery, options?: SearchOptions<HD>): Promise<DecoratedResult<HD>>;
|
package/dist/core/src/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SearchOptions as BaseOptions, SearchProduct, SearchResult } from '@nosto/nosto-js/client';
|
|
1
|
+
import { SearchOptions as BaseOptions, SearchProduct, SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
2
|
export type SearchOptions<HD extends readonly HitDecorator[] = readonly HitDecorator[]> = BaseOptions & {
|
|
3
3
|
/**
|
|
4
4
|
* Hit decorators to apply to the search results.
|
|
@@ -12,7 +12,13 @@ export type SearchOptions<HD extends readonly HitDecorator[] = readonly HitDecor
|
|
|
12
12
|
* Interval (in ms) between retry attempts. Default: 1000 ms.
|
|
13
13
|
*/
|
|
14
14
|
retryInterval?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to use a persistent cache for the search results. Default: false.
|
|
17
|
+
*/
|
|
18
|
+
usePersistentCache?: boolean;
|
|
15
19
|
};
|
|
20
|
+
export type SearchFn<HD extends readonly HitDecorator[]> = (query: SearchQuery, options: SearchOptions<HD>) => Promise<SearchResult>;
|
|
21
|
+
export type SearchWithNext<HD extends readonly HitDecorator[]> = (query: SearchQuery, options: SearchOptions<HD>, searchFn: SearchFn<HD>) => Promise<SearchResult>;
|
|
16
22
|
export type HitDecorator = (hit: SearchProduct) => SearchProduct;
|
|
17
23
|
export type ToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
18
24
|
export type DecoratedProduct<HD extends readonly HitDecorator[]> = ToIntersection<ReturnType<HD[number]>>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { HitDecorator, SearchFn, SearchOptions } from './types';
|
|
2
|
+
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
3
|
+
export declare function searchWithCache<HD extends readonly HitDecorator[]>(query: SearchQuery, { usePersistentCache, ...options }: SearchOptions<HD>, searchFn: SearchFn<HD>): Promise<SearchResult>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
|
+
import { HitDecorator, SearchFn, SearchOptions } from './types';
|
|
3
|
+
export declare function searchWithRetries<HD extends readonly HitDecorator[]>(query: SearchQuery, { maxRetries, retryInterval, ...options }: SearchOptions<HD>, searchFn: SearchFn<HD>): Promise<SearchResult>;
|
|
4
|
+
/**
|
|
5
|
+
* Should the error trigger a search retry
|
|
6
|
+
*/
|
|
7
|
+
export declare function shouldRetry(error: unknown): error is object;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { a as u } from "./logger-DVwg4Wor.js";
|
|
2
|
+
function o(...e) {
|
|
3
|
+
return f(...e);
|
|
4
|
+
}
|
|
5
|
+
function f(...e) {
|
|
6
|
+
return e.reduce((n, r) => c(n, r));
|
|
7
|
+
}
|
|
8
|
+
function c(e, n) {
|
|
9
|
+
return u(e) && u(n) ? Object.entries(n).reduce(
|
|
10
|
+
(r, [i, t]) => (r[i] = c(r[i], t), r),
|
|
11
|
+
{ ...e }
|
|
12
|
+
) : u(e) ? e : n;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
f as a,
|
|
16
|
+
o as d
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("./logger-BcHMZObS.cjs");function s(...e){return c(...e)}function c(...e){return e.reduce((n,r)=>t(n,r))}function t(e,n){return i.isPlainObject(e)&&i.isPlainObject(n)?Object.entries(n).reduce((r,[u,l])=>(r[u]=t(r[u],l),r),{...e}):i.isPlainObject(e)?e:n}exports.deepMerge=s;exports.deepMergePlain=c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const f=require("./index.es-DlUp67LT.cjs"),c=e=>String(e)==="[object Object]";function o(e){if(!c(e))return!1;const r=e.constructor;if(r===void 0)return!0;const t=r.prototype;return!(!c(t)||!t.hasOwnProperty("isPrototypeOf"))}function s(e,r){if(e===r)return!0;if(e instanceof Date&&r instanceof Date)return e.getTime()===r.getTime();if(Array.isArray(e)&&Array.isArray(r))return e.length!==r.length?!1:e.every((t,n)=>s(t,r[n]));if(o(e)&&o(r)){const t=Object.entries(e);return t.length!==Object.keys(r).length?!1:t.every(([n,u])=>s(u,r[n]))}return!1}function i(e){return(...r)=>{f.s(t=>{(t.internal.context.mode.isPreview()?console[e]:t.internal.logger[e])(...r)})}}const g={debug:i("debug"),info:i("info"),warn:i("warn"),error:i("error")};exports.isEqual=s;exports.isPlainObject=o;exports.logger=g;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { s as u } from "./index.es-B8mbAxS4.js";
|
|
2
|
+
const i = (r) => String(r) === "[object Object]";
|
|
3
|
+
function s(r) {
|
|
4
|
+
if (!i(r))
|
|
5
|
+
return !1;
|
|
6
|
+
const e = r.constructor;
|
|
7
|
+
if (e === void 0)
|
|
8
|
+
return !0;
|
|
9
|
+
const t = e.prototype;
|
|
10
|
+
return !(!i(t) || !t.hasOwnProperty("isPrototypeOf"));
|
|
11
|
+
}
|
|
12
|
+
function f(r, e) {
|
|
13
|
+
if (r === e)
|
|
14
|
+
return !0;
|
|
15
|
+
if (r instanceof Date && e instanceof Date)
|
|
16
|
+
return r.getTime() === e.getTime();
|
|
17
|
+
if (Array.isArray(r) && Array.isArray(e))
|
|
18
|
+
return r.length !== e.length ? !1 : r.every((t, n) => f(t, e[n]));
|
|
19
|
+
if (s(r) && s(e)) {
|
|
20
|
+
const t = Object.entries(r);
|
|
21
|
+
return t.length !== Object.keys(e).length ? !1 : t.every(([n, c]) => f(c, e[n]));
|
|
22
|
+
}
|
|
23
|
+
return !1;
|
|
24
|
+
}
|
|
25
|
+
function o(r) {
|
|
26
|
+
return (...e) => {
|
|
27
|
+
u((t) => {
|
|
28
|
+
(t.internal.context.mode.isPreview() ? console[r] : t.internal.logger[r])(...e);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const a = {
|
|
33
|
+
debug: o("debug"),
|
|
34
|
+
info: o("info"),
|
|
35
|
+
warn: o("warn"),
|
|
36
|
+
error: o("error")
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
s as a,
|
|
40
|
+
f as i,
|
|
41
|
+
a as l
|
|
42
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../index.es-DlUp67LT.cjs"),a=require("preact"),u=require("../renderHeadless-xhkLegO4.cjs"),i=require("../jsxRuntime.module-B3sGoTIU.cjs"),r=require("../configContext-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../index.es-DlUp67LT.cjs"),a=require("preact"),u=require("../renderHeadless-xhkLegO4.cjs"),i=require("../jsxRuntime.module-B3sGoTIU.cjs"),r=require("../configContext-BR7w4VlU.cjs"),c=require("../baseConfig-BFFqFSg5.cjs");function f(e){return e!==null&&typeof e=="object"&&"props"in e&&typeof e.type=="string"}function m({children:e,hit:n}){var o;if(!f(e))throw new Error("AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported.");const t=(o=e.props)==null?void 0:o.onClick;return a.cloneElement(e,{onClick:p=>{n&&l.s(s=>s.recordSearchClick("autocomplete",n)),typeof t=="function"&&t(p)}})}function g({children:e,onSearchInput:n}){return u.renderHeadless({children:e,updateElement:t=>(!u.isHTMLInput(t)||t.props.type!=="search"||(t.props={...t.props,onInput:o=>{o.target instanceof HTMLInputElement&&n(o.target)}}),t)})}const C={...c.defaultBaseConfig};function d(e){return{pageType:"autocomplete",...C,...e}}function S({config:e,store:n,children:t}){const o=n??r.createStore();return c.useCheckClientScript(),i.u(r.ConfigContext,{value:d(e),children:i.u(r.StoreContext,{value:o,children:t})})}exports.AutocompleteElement=m;exports.AutocompletePageProvider=S;exports.SearchInput=g;
|
|
@@ -2,8 +2,8 @@ import { s as u } from "../index.es-B8mbAxS4.js";
|
|
|
2
2
|
import { cloneElement as a } from "preact";
|
|
3
3
|
import { r as s, i as c } from "../renderHeadless-BteGML1G.js";
|
|
4
4
|
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
5
|
-
import { c as l, S as m, C as f } from "../configContext-
|
|
6
|
-
import { d as C, u as g } from "../baseConfig-
|
|
5
|
+
import { c as l, S as m, C as f } from "../configContext-GuZOIX3o.js";
|
|
6
|
+
import { d as C, u as g } from "../baseConfig-Bafl02NY.js";
|
|
7
7
|
function E(t) {
|
|
8
8
|
return t !== null && typeof t == "object" && "props" in t && typeof t.type == "string";
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),t=require("../configContext-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../jsxRuntime.module-B3sGoTIU.cjs"),t=require("../configContext-BR7w4VlU.cjs"),o=require("../baseConfig-BFFqFSg5.cjs"),u={...o.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function c(e){return{pageType:"category",...u,...e}}function g({config:e,store:n,children:a}){const i=n??t.createStore();return o.useCheckClientScript(),r.u(t.ConfigContext,{value:c(e),children:r.u(t.StoreContext,{value:i,children:a})})}exports.CategoryPageProvider=g;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { u as t } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { c as n, S as c, C as i } from "../configContext-
|
|
3
|
-
import { d as s, u as f } from "../baseConfig-
|
|
2
|
+
import { c as n, S as c, C as i } from "../configContext-GuZOIX3o.js";
|
|
3
|
+
import { d as s, u as f } from "../baseConfig-Bafl02NY.js";
|
|
4
4
|
const C = {
|
|
5
5
|
...s,
|
|
6
6
|
persistentSearchCache: !1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-BCAEb4ek.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-BCAEb4ek.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-3isftdTM.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-D906VaKk.cjs"),q=require("preact"),r=require("../configContext-BR7w4VlU.cjs");function b({pageSize:o}){const{loadMore:e}=c.useLoadMore(o);return t.u("button",{onClick:e,children:"More results"})}function u({children:o,loadMoreComponent:e,pageSize:i}){const{loading:s,query:l,response:a}=c.useNostoAppState(S=>p.pick(S,"loading","query","response")),d=!s&&n.hasMoreResults(l,a);return t.u(q.Fragment,{children:[o,d&&(e?t.u(e,{pageSize:i}):t.u(b,{pageSize:i}))]})}const M=!f.isBot()&&n.intersectionObserverSupported()?n.InfiniteScrollWithObserver:u;exports.StoreContext=r.StoreContext;exports.createExtendableStore=r.createExtendableStore;exports.createStore=r.createStore;exports.defaultState=r.defaultState;exports.InfiniteScroll=M;exports.InfiniteScrollWithLink=u;
|
package/dist/preact/common.es.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { i as l } from "../unique-CyAMhegX.js";
|
|
2
2
|
import { u as r } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
|
-
import { a as p, u as m } from "../useLoadMore-
|
|
3
|
+
import { a as p, u as m } from "../useLoadMore-4uB1MmI6.js";
|
|
4
4
|
import { p as u } from "../pick-DReBictn.js";
|
|
5
|
-
import { h as d, i as f, I as S } from "../InfiniteScrollWithObserver-
|
|
5
|
+
import { h as d, i as f, I as S } from "../InfiniteScrollWithObserver-DHIVa8bY.js";
|
|
6
6
|
import { Fragment as h } from "preact";
|
|
7
|
-
import { S as O, a as W, c as A, d as B } from "../configContext-
|
|
7
|
+
import { S as O, a as W, c as A, d as B } from "../configContext-GuZOIX3o.js";
|
|
8
8
|
function M({ pageSize: e }) {
|
|
9
9
|
const { loadMore: o } = p(e);
|
|
10
10
|
return /* @__PURE__ */ r("button", { onClick: o, children: "More results" });
|
package/dist/preact/hooks.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../useLoadMore-3isftdTM.cjs"),P=require("../logger-BcHMZObS.cjs"),v=require("preact/hooks"),C=require("../index.es-DlUp67LT.cjs"),N=require("../parseNumber-FsZ8w61u.cjs");function q(e){const o=m.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&P.isPlainObject(e)?e:o}function z(e){var a;const o=((a=e.data)==null?void 0:a.filter(c=>c.selected).length)??0,[t,n]=v.useState(o>0),{toggleProductFilter:u}=m.useActions();return{active:t,selectedFiltersCount:o,toggleActive:()=>{n(!t)},toggleProductFilter:u}}function x(){const{loading:e,facets:o}=m.useNostoAppState(t=>{var n,u;return{loading:t.loading,facets:((u=(n=t.response)==null?void 0:n.products)==null?void 0:u.facets)??[]}});return{loading:e,facets:o}}function k(e,o){const t=o-e;return!isNaN(t)&&t>0?new Array(o-e).fill(void 0).map((n,u)=>u+e):[]}function w(e){const{query:o,products:t}=m.useNostoAppState(n=>({query:n.query,products:n.response.products}));return v.useMemo(()=>{var F;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const n=((F=o.products)==null?void 0:F.from)??0,u=(e==null?void 0:e.width)??1/0,i=Math.max(Math.floor(u-1)/2,1),a=t.size>0?Math.floor(n/t.size)+1:1,c=t.size>0?Math.ceil(t.total/t.size):0,g=A=>A>=a-i&&A<=a+i,s=n+1,l=Math.min(n+t.total,t.total),r={from:n,page:a,current:!0},p=A=>({from:(A-1)*t.size,page:A,current:A===a}),S=a>1?p(a-1):void 0,d=a<c?p(a+1):void 0,y=i===1/0||a-i-1>1?p(1):void 0,f=i===1/0||a+i+1<c?p(c):void 0,h=k(1,c+1).filter(g).map(p);return{totalPages:c,resultsFrom:s,resultsTo:l,current:r,prev:S,next:d,first:y,last:f,pages:h}},[o,t,e==null?void 0:e.width])}function T(){const[e,o]=v.useState([]),[t,n]=v.useState([]);return v.useEffect(()=>{C.s(async u=>{const{products:i,segments:a}=await u.getSearchSessionParams();o(a??[]),n((i==null?void 0:i.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function B(){const{facets:e}=m.useNostoAppState(s=>{var l;return{facets:((l=s.response.products)==null?void 0:l.facets)??[]}}),{replaceFilter:o,toggleProductFilter:t}=m.useActions(),n=v.useCallback(s=>{const l=e==null?void 0:e.find(r=>r.type==="stats"&&r.field===s);if(l&&"min"in l&&"max"in l)return l},[e]),u=v.useCallback(s=>{var l;return((l=e==null?void 0:e.find(r=>r.field===s))==null?void 0:l.name)??s},[e]),i=v.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),a=v.useCallback(s=>{var l;return{...s,range:(l=s.range)==null?void 0:l.map(r=>({gt:r.gt?Number(r.gt):r.gt,gte:r.gte?Number(r.gte):r.gte,lt:r.lt?Number(r.lt):r.lt,lte:r.lte?Number(r.lte):r.lte}))}},[]),c=v.useCallback(s=>(s.value??[]).map(r=>({value:r,field:s.field,name:u(s.field),filter:a(s),remove:()=>{t(s.field,r,!1)}})),[a,u,t]),g=v.useCallback(s=>(s.range??[]).map(r=>{var d,y;const p=r.gte??r.gt??((d=n(s.field))==null?void 0:d.min),S=r.lte??r.lt??((y=n(s.field))==null?void 0:y.max);if(p!==void 0&&S!==void 0)return{value:`${p} - ${S}`,field:s.field,name:u(s.field),filter:a(s),remove:()=>{o(s.field,void 0)}}}).filter(Boolean),[a,n,u,o]);return{selectFilters:i,toValueFilter:c,toRangeFilter:g}}function M(){const{filter:e}=m.useNostoAppState(c=>{var g;return{filter:((g=c.query.products)==null?void 0:g.filter)??[]}}),{updateSearch:o}=m.useActions(),{selectFilters:t,toValueFilter:n,toRangeFilter:u}=B(),i=v.useMemo(()=>e?e.filter(t).flatMap(c=>"value"in c?n(c):"range"in c?u(c):[]).filter(Boolean):[],[e,t,u,n]),a=v.useCallback(()=>{o({products:{filter:[]}})},[o]);return{filters:i,removeAll:a}}function R(e){var r,p,S;const{replaceFilter:o}=m.useActions(),{query:t,products:n}=m.useNostoAppState(d=>({query:d.query,products:d.response.products})),u=(r=n==null?void 0:n.facets)==null?void 0:r.find(d=>d.id===e);if(!u)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const i=(S=(p=t.products)==null?void 0:p.filter)==null?void 0:S.find(d=>d.field===u.field),a=i!=null&&i.range?i.range[0]:void 0,c=typeof a=="object"&&("gte"in a||"lte"in a)?[N.parseNumber(a.gte),N.parseNumber(a.lte)]:[void 0,void 0],g="min"in u?Math.floor(u.min):0,s="max"in u?Math.ceil(u.max):0,l=([d,y])=>{const f=d!==void 0?Math.floor(d):void 0,h=y!==void 0?Math.ceil(y):void 0,F=f!==void 0,A=h!==void 0;(g===f||!F)&&(s===h||!A)?o(u.field,void 0):(g===f||!F)&&A?o(u.field,{lte:h.toString()}):(s===h||!A)&&F?o(u.field,{gte:f.toString()}):F&&A&&o(u.field,{gte:f.toString(),lte:h.toString()})};return{min:g,max:s,range:[c[0]??g,c[1]??s],updateRange:l}}function D(e,o){const{min:t,max:n,range:u,updateRange:i}=R(e),{filters:a}=M(),c=v.useMemo(()=>{var y;const r=a.find(f=>{var h;return(h=f==null?void 0:f.filter)==null?void 0:h.range});let p=null;if(r){const f=(y=r.filter.range)==null?void 0:y[0];p=[N.parseNumber(f==null?void 0:f.gte),N.parseNumber(f==null?void 0:f.lte)]}const S=[];let d=Math.floor(t/o)*o;for(;d<n;){const f=d+o,h=p&&p[0]===d&&p[1]===f;S.push({min:d,max:f,selected:h}),d=f}return S},[a,t,n,o]),g=r=>{i([r,u[1]])},s=r=>{i([u[0],r])},l=t!==u[0]||n!==u[1];return{min:t,max:n,range:u,updateRange:i,ranges:c,handleMinChange:g,handleMaxChange:s,isSelected:l}}function j(){const{products:e,keywords:o}=m.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:o??{hits:[],total:0}}}function I(){const e=m.useNostoAppState(t=>{var n;return(n=t.query.products)==null?void 0:n.filter});return v.useMemo(()=>e?e.reduce((t,n)=>t+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function b(e){return e&&!Number.isNaN(e)?e:0}function L(e,o){const{from:t,size:n,total:u}=m.useNostoAppState(s=>{var l,r,p,S,d;return{from:b(((l=s.query.products)==null?void 0:l.from)??0),size:b(((p=(r=s.response)==null?void 0:r.products)==null?void 0:p.size)??0),total:b(((d=(S=s.response)==null?void 0:S.products)==null?void 0:d.total)??0)}}),{updateSearch:i}=m.useActions(),a=t+n,c=[...e].reverse().filter(s=>s+o<u);return{from:t,to:a,total:u,size:n,sizeOptions:c,handleSizeChange:s=>{i({products:{size:N.parseNumber(s)}})}}}function O(e,o){return e.length!==o.length?!1:e.every(t=>o.find(n=>t.field===n.field&&t.order===n.order))}function V(e){var i,a;const o=m.useNostoAppState(c=>c.query),{updateSearch:t}=m.useActions();return{activeSort:((i=e.find(c=>{var g;return O(c.value.sort,((g=o.products)==null?void 0:g.sort)||[])}))==null?void 0:i.id)??((a=e[0])==null?void 0:a.id),setSort:c=>{const g=e.find(s=>s.id===c);g&&t({products:{sort:g.value.sort}})}}}exports.useActions=m.useActions;exports.useLoadMore=m.useLoadMore;exports.useNostoAppState=m.useNostoAppState;exports.useDecoratedSearchResults=q;exports.useFacet=z;exports.useFacets=x;exports.usePagination=w;exports.usePersonalization=T;exports.useProductFilters=M;exports.useRange=R;exports.useRangeSelector=D;exports.useResponse=j;exports.useSelectedFiltersCount=I;exports.useSizeOptions=L;exports.useSort=V;
|
package/dist/preact/hooks.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { u as F, b as R } from "../useLoadMore-
|
|
2
|
-
import { a as Y } from "../useLoadMore-
|
|
3
|
-
import { a as N } from "../
|
|
1
|
+
import { u as F, b as R } from "../useLoadMore-4uB1MmI6.js";
|
|
2
|
+
import { a as Y } from "../useLoadMore-4uB1MmI6.js";
|
|
3
|
+
import { a as N } from "../logger-DVwg4Wor.js";
|
|
4
4
|
import { useState as P, useMemo as z, useEffect as b, useCallback as M } from "preact/hooks";
|
|
5
5
|
import { s as q } from "../index.es-B8mbAxS4.js";
|
|
6
6
|
import { p as x } from "../parseNumber-QA48nJLp.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../InfiniteScrollWithObserver-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../InfiniteScrollWithObserver-D906VaKk.cjs"),r=require("../useLoadMore-3isftdTM.cjs");exports.InfiniteScrollWithObserver=e.InfiniteScrollWithObserver;exports.intersectionObserverSupported=e.intersectionObserverSupported;exports.getNextPageQuery=r.getNextPageQuery;
|
package/dist/preact/legacy.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as t, i as o } from "../InfiniteScrollWithObserver-
|
|
2
|
-
import { g as s } from "../useLoadMore-
|
|
1
|
+
import { I as t, i as o } from "../InfiniteScrollWithObserver-DHIVa8bY.js";
|
|
2
|
+
import { g as s } from "../useLoadMore-4uB1MmI6.js";
|
|
3
3
|
export {
|
|
4
4
|
t as InfiniteScrollWithObserver,
|
|
5
5
|
s as getNextPageQuery,
|
package/dist/preact/serp.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../index.es-DlUp67LT.cjs"),s=require("../configContext-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../index.es-DlUp67LT.cjs"),s=require("../configContext-BR7w4VlU.cjs"),S=require("../renderHeadless-xhkLegO4.cjs"),a=require("../jsxRuntime.module-B3sGoTIU.cjs"),i=require("../baseConfig-BFFqFSg5.cjs"),g="nosto:search:scrollPos";function d(){window.sessionStorage.setItem(g,window.scrollY.toString())}function C({children:e,hit:t,onClick:o}){const{pageType:r}=s.useConfig(),c=r==="autocomplete"?void 0:r==="search"?"serp":r;return S.renderHeadless({children:e,updateElement:(n,u)=>(u.depth>0||(n.props={...n.props,onClick:l=>{t&&c&&p.s(f=>f.recordSearchClick(c,t)),d(),typeof o=="function"&&o(l)}}),n)})}const h={...i.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function m(e={}){return{pageType:"search",...h,...e}}function P({config:e,store:t,children:o}){const r=t??s.createStore();return i.useCheckClientScript(),a.u(s.ConfigContext,{value:m(e),children:a.u(s.StoreContext,{value:r,children:o})})}exports.SearchPageProvider=P;exports.SerpElement=C;
|
package/dist/preact/serp.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { s as l } from "../index.es-B8mbAxS4.js";
|
|
2
|
-
import { u as f, c as u, S, C as m } from "../configContext-
|
|
2
|
+
import { u as f, c as u, S, C as m } from "../configContext-GuZOIX3o.js";
|
|
3
3
|
import { r as g } from "../renderHeadless-BteGML1G.js";
|
|
4
4
|
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
5
|
-
import { d as C, u as d } from "../baseConfig-
|
|
5
|
+
import { d as C, u as d } from "../baseConfig-Bafl02NY.js";
|
|
6
6
|
const h = "nosto:search:scrollPos";
|
|
7
7
|
function P() {
|
|
8
8
|
window.sessionStorage.setItem(h, window.scrollY.toString());
|
|
@@ -29,15 +29,15 @@ export declare function applyQueryDefaults(pageType: PageType, query: SearchQuer
|
|
|
29
29
|
variationId?: string;
|
|
30
30
|
fields: string[];
|
|
31
31
|
};
|
|
32
|
+
accountId?: string | undefined;
|
|
33
|
+
customRules?: import('@nosto/nosto-js/client').InputSearchRule[] | undefined;
|
|
32
34
|
explain?: boolean | undefined;
|
|
33
35
|
query?: string | undefined;
|
|
34
36
|
redirect?: string | undefined;
|
|
35
|
-
abTests?: import('@nosto/nosto-js/client').InputSearchABTest[] | undefined;
|
|
36
|
-
accountId?: string | undefined;
|
|
37
|
-
customRules?: import('@nosto/nosto-js/client').InputSearchRule[] | undefined;
|
|
38
37
|
rules?: string[] | undefined;
|
|
39
38
|
segments?: string[] | undefined;
|
|
40
39
|
sessionParams?: import('@nosto/nosto-js/client').InputSearchQuery | undefined;
|
|
40
|
+
abTests?: import('@nosto/nosto-js/client').InputSearchABTest[] | undefined;
|
|
41
41
|
time?: number | undefined;
|
|
42
42
|
name?: string;
|
|
43
43
|
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { s as y } from "./index.es-B8mbAxS4.js";
|
|
2
|
+
import { l as f, i as R } from "./logger-DVwg4Wor.js";
|
|
3
|
+
async function b(t, { hitDecorators: r, ...e }, s) {
|
|
4
|
+
var c, i;
|
|
5
|
+
const n = await s(t, e);
|
|
6
|
+
if (!((i = (c = n.products) == null ? void 0 : c.hits) != null && i.length) || !(r != null && r.length))
|
|
7
|
+
return n;
|
|
8
|
+
const o = (l) => r.reduce((u, a) => a(u), l);
|
|
9
|
+
return {
|
|
10
|
+
...n,
|
|
11
|
+
products: {
|
|
12
|
+
...n.products,
|
|
13
|
+
hits: n.products.hits.map(o)
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function N(t, r, e) {
|
|
18
|
+
const s = JSON.stringify(r);
|
|
19
|
+
try {
|
|
20
|
+
f.info("Setting storage", t, s), e.setItem(t, s);
|
|
21
|
+
} catch (n) {
|
|
22
|
+
f.warn(n);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function k(t, r) {
|
|
26
|
+
try {
|
|
27
|
+
const e = r.getItem(t);
|
|
28
|
+
if (e)
|
|
29
|
+
return JSON.parse(e);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
f.warn(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function C(t, r) {
|
|
35
|
+
N(t, r, sessionStorage);
|
|
36
|
+
}
|
|
37
|
+
function O(t) {
|
|
38
|
+
return k(t, sessionStorage);
|
|
39
|
+
}
|
|
40
|
+
const w = "nosto:search:searchResult";
|
|
41
|
+
function z(t, r) {
|
|
42
|
+
C(w, { query: t, result: r });
|
|
43
|
+
}
|
|
44
|
+
function E(t) {
|
|
45
|
+
const r = O(w);
|
|
46
|
+
if (!r || !I(r))
|
|
47
|
+
return null;
|
|
48
|
+
const e = S(r.query);
|
|
49
|
+
return R(S(t), e) ? r.result : null;
|
|
50
|
+
}
|
|
51
|
+
function S(t) {
|
|
52
|
+
const r = {
|
|
53
|
+
...t,
|
|
54
|
+
time: void 0,
|
|
55
|
+
products: {
|
|
56
|
+
...t.products,
|
|
57
|
+
size: void 0
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return JSON.parse(JSON.stringify(r));
|
|
61
|
+
}
|
|
62
|
+
function I(t) {
|
|
63
|
+
return typeof t == "object" && t !== null && "query" in t && "result" in t;
|
|
64
|
+
}
|
|
65
|
+
async function J(t, { usePersistentCache: r, ...e }, s) {
|
|
66
|
+
if (!r)
|
|
67
|
+
return s(t, e);
|
|
68
|
+
const n = await V(t, e);
|
|
69
|
+
return z(t, n), n;
|
|
70
|
+
}
|
|
71
|
+
async function V(t, r) {
|
|
72
|
+
var a, p, d, h, g;
|
|
73
|
+
const { from: e = 0, size: s = 0 } = t.products || {}, n = E(t);
|
|
74
|
+
if (!n)
|
|
75
|
+
return await m(t, r);
|
|
76
|
+
const o = ((a = n == null ? void 0 : n.products) == null ? void 0 : a.hits) || [];
|
|
77
|
+
if (s === o.length)
|
|
78
|
+
return n;
|
|
79
|
+
if (s < o.length)
|
|
80
|
+
return {
|
|
81
|
+
...n,
|
|
82
|
+
products: {
|
|
83
|
+
...n.products,
|
|
84
|
+
hits: o.slice(0, s),
|
|
85
|
+
total: ((p = n.products) == null ? void 0 : p.total) || 0
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const c = s - o.length, i = e > 0 ? e + 1 : s - c, l = {
|
|
89
|
+
...t,
|
|
90
|
+
products: {
|
|
91
|
+
...t.products,
|
|
92
|
+
from: i,
|
|
93
|
+
size: c
|
|
94
|
+
}
|
|
95
|
+
}, u = await m(l, r);
|
|
96
|
+
return {
|
|
97
|
+
...n,
|
|
98
|
+
products: {
|
|
99
|
+
...n.products,
|
|
100
|
+
hits: [...((d = n.products) == null ? void 0 : d.hits) || [], ...((h = u.products) == null ? void 0 : h.hits) || []],
|
|
101
|
+
total: (g = u.products) == null ? void 0 : g.total
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function F(t) {
|
|
106
|
+
return new Promise((r) => setTimeout(r, t));
|
|
107
|
+
}
|
|
108
|
+
async function T(t, { maxRetries: r = 0, retryInterval: e = 0, ...s }, n) {
|
|
109
|
+
let o = 0;
|
|
110
|
+
for (; ; )
|
|
111
|
+
try {
|
|
112
|
+
return await n(t, s);
|
|
113
|
+
} catch (c) {
|
|
114
|
+
if (o >= r)
|
|
115
|
+
throw c;
|
|
116
|
+
if (!W(c))
|
|
117
|
+
throw f.info("Skipping retry logic for", c), c;
|
|
118
|
+
o++, await F(e);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function W(t) {
|
|
122
|
+
return !t || typeof t != "object" ? !1 : !("status" in t) || j(t.status);
|
|
123
|
+
}
|
|
124
|
+
function j(t) {
|
|
125
|
+
return typeof t == "number" && (t < 400 || t >= 500);
|
|
126
|
+
}
|
|
127
|
+
async function m(t, r = {}) {
|
|
128
|
+
const e = await new Promise(y);
|
|
129
|
+
return A(e.search, T, J, b)(t, r);
|
|
130
|
+
}
|
|
131
|
+
function A(t, ...r) {
|
|
132
|
+
return r.reduce((e, s) => (n, o) => s(n, o, e), t);
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
m as s
|
|
136
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const m=require("./index.es-DlUp67LT.cjs"),i=require("./logger-BcHMZObS.cjs");async function R(t,{hitDecorators:e,...n},s){var c,u;const r=await s(t,n);if(!((u=(c=r.products)==null?void 0:c.hits)!=null&&u.length)||!(e!=null&&e.length))return r;const o=f=>e.reduce((a,l)=>l(a),f);return{...r,products:{...r.products,hits:r.products.hits.map(o)}}}function b(t,e,n){const s=JSON.stringify(e);try{i.logger.info("Setting storage",t,s),n.setItem(t,s)}catch(r){i.logger.warn(r)}}function N(t,e){try{const n=e.getItem(t);if(n)return JSON.parse(n)}catch(n){i.logger.warn(n)}}function k(t,e){b(t,e,sessionStorage)}function C(t){return N(t,sessionStorage)}const y="nosto:search:searchResult";function O(t,e){k(y,{query:t,result:e})}function z(t){const e=C(y);if(!e||!E(e))return null;const n=w(e.query);return i.isEqual(w(t),n)?e.result:null}function w(t){const e={...t,time:void 0,products:{...t.products,size:void 0}};return JSON.parse(JSON.stringify(e))}function E(t){return typeof t=="object"&&t!==null&&"query"in t&&"result"in t}async function I(t,{usePersistentCache:e,...n},s){if(!e)return s(t,n);const r=await J(t,n);return O(t,r),r}async function J(t,e){var l,d,h,p,S;const{from:n=0,size:s=0}=t.products||{},r=z(t);if(!r)return await g(t,e);const o=((l=r==null?void 0:r.products)==null?void 0:l.hits)||[];if(s===o.length)return r;if(s<o.length)return{...r,products:{...r.products,hits:o.slice(0,s),total:((d=r.products)==null?void 0:d.total)||0}};const c=s-o.length,u=n>0?n+1:s-c,f={...t,products:{...t.products,from:u,size:c}},a=await g(f,e);return{...r,products:{...r.products,hits:[...((h=r.products)==null?void 0:h.hits)||[],...((p=a.products)==null?void 0:p.hits)||[]],total:(S=a.products)==null?void 0:S.total}}}function V(t){return new Promise(e=>setTimeout(e,t))}async function F(t,{maxRetries:e=0,retryInterval:n=0,...s},r){let o=0;for(;;)try{return await r(t,s)}catch(c){if(o>=e)throw c;if(!T(c))throw i.logger.info("Skipping retry logic for",c),c;o++,await V(n)}}function T(t){return!t||typeof t!="object"?!1:!("status"in t)||W(t.status)}function W(t){return typeof t=="number"&&(t<400||t>=500)}async function g(t,e={}){const n=await new Promise(m.s);return _(n.search,F,I,R)(t,e)}function _(t,...e){return e.reduce((n,s)=>(r,o)=>s(r,o,n),t)}exports.search=g;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const f=require("./configContext-BR7w4VlU.cjs"),n=require("preact/hooks"),v=require("./search-Di9DRn5H.cjs"),g=require("./unique-BCAEb4ek.cjs"),y=require("./deepMerge-lDscDfII.cjs"),m=require("./logger-BcHMZObS.cjs");function S(e=P){const r=n.useContext(f.StoreContext),[t,o]=n.useState(e(r.getState()));return r.onChange(e,o),n.useEffect(()=>()=>r.clearOnChange(o),[r]),t}const P=e=>e;function F(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:q,...r.products},...r.keywords?{keywords:{...r.keywords,fields:g.unique([...M,...r.keywords.fields??[]]),highlight:r.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const q=["productId","url","name","imageUrl","imageHash","thumbUrl","description","brand","variantId","availability","price","priceText","categoryIds","categories","customFields.key","customFields.value","priceCurrencyCode","datePublished","listPrice","unitPricingBaseMeasure","unitPricingUnit","unitPricingMeasure","googleCategory","gtin","ageGroup","gender","condition","alternateImageUrls","ratingValue","reviewCount","inventoryLevel","skus.id","skus.name","skus.price","skus.listPrice","skus.priceText","skus.url","skus.imageUrl","skus.inventoryLevel","skus.customFields.key","skus.customFields.value","skus.availability","pid","onDiscount","extra.key","extra.value","saleable","available","tags1","tags2","tags3"],M=["keyword","_redirect"];async function C(e,r,t){var d,l,k;const o=g.measure("newSearch"),u=e.config.pageType,c=u==="search"?"serp":u,a=y.deepMerge(e.store.getInitialState().query,r),s=y.deepMerge(e.config.search,t,{track:c,redirect:u!=="autocomplete",isKeyword:!!(t!=null&&t.isKeyword),usePersistentCache:e.config.pageType!=="autocomplete"&&e.config.persistentSearchCache});e.store.updateState({query:a,loading:!0,initialized:!0});const i=e.config.queryModifications({...a,products:{...a.products,filter:g.mergeArrays((l=(d=e.store.getInitialState().query)==null?void 0:d.products)==null?void 0:l.filter,(k=r.products)==null?void 0:k.filter)}},u);try{const p=await v.search(F(e.config.pageType,i),s);e.store.updateState({response:p,loading:!1})}catch(p){m.logger.error("Search action failed",p)}o()}async function h(e,r,t){const o=g.measure("updateSearch"),u=y.deepMerge(e.store.getState().query,{products:{from:0}},r);await C(e,u,t),o()}async function T(e,r,t){var a;const o=g.measure("replaceFilter"),u=(a=e.store.getState().query.products)==null?void 0:a.filter,c=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await h(e,{products:{filter:[...(u==null?void 0:u.filter(s=>s.field!==r))??[],...c]}}),o()}async function A(e,r,t,o){var i,d;const u=g.measure("toggleProductFilter"),c=(i=e.store.getState().query.products)==null?void 0:i.filter,a=c==null?void 0:c.find(l=>l.value instanceof Array&&l.field===r),s=a!=null&&a.value?{...a,value:[...a.value.filter(l=>!m.isEqual(l,t)),...o?[t]:[]]}:o?{field:r,value:[t]}:void 0;await h(e,{products:{filter:[...(c==null?void 0:c.filter(l=>l!==a))??[],...(d=s==null?void 0:s.value)!=null&&d.length?[s]:[]]}}),u()}function w(){const e=f.useConfig(),r=n.useContext(f.StoreContext),t=n.useMemo(()=>({config:e,store:r}),[e,r]),o=n.useCallback((s,i)=>C(t,s,i),[t]),u=n.useCallback((s,i)=>h(t,s,i),[t]),c=n.useCallback((s,i,d)=>A(t,s,i,d),[t]),a=n.useCallback((s,i)=>T(t,s,i),[t]);return{newSearch:o,updateSearch:u,toggleProductFilter:c,replaceFilter:a}}function b({from:e,size:r,pageSize:t}){return g.isBot()?{products:{from:e+t}}:{products:{size:r+t}}}function I(e=24){const{from:r,size:t}=S(c=>{var a,s;return{from:((a=c.query.products)==null?void 0:a.from)??0,size:((s=c.query.products)==null?void 0:s.size)??0}}),{updateSearch:o}=w();return{loadMore:n.useCallback(async()=>{await o(b({from:r,size:t,pageSize:e}))},[r,t,e,o])}}exports.getNextPageQuery=b;exports.useActions=w;exports.useLoadMore=I;exports.useNostoAppState=S;
|