@nosto/search-js 2.14.0 → 2.16.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/BaseElement-B0hSjDTT.cjs +1 -0
- package/dist/BaseElement-IyqEeIiJ.js +18 -0
- package/dist/{InfiniteScrollWithObserver-Do05gtr2.cjs → InfiniteScrollWithObserver-BZeSt2TI.cjs} +1 -1
- package/dist/{InfiniteScrollWithObserver-CvnCyquA.js → InfiniteScrollWithObserver-DYKAh87P.js} +1 -1
- package/dist/core/core.cjs.js +1 -1
- package/dist/core/core.es.js +1 -1
- package/dist/core/src/types.d.ts +4 -0
- package/dist/core/src/withMemoryCache.d.ts +4 -0
- package/dist/preact/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete.d.ts +1 -1
- package/dist/preact/autocomplete.es.js +34 -37
- package/dist/preact/common.cjs.js +1 -1
- package/dist/preact/common.es.js +2 -2
- package/dist/preact/hooks.cjs.js +1 -1
- package/dist/preact/hooks.es.js +2 -2
- package/dist/preact/legacy.cjs.js +1 -1
- package/dist/preact/legacy.es.js +2 -2
- package/dist/preact/preact.d.ts +1 -1
- package/dist/preact/serp.cjs.js +1 -1
- package/dist/preact/serp.es.js +21 -26
- package/dist/preact/src/components/AutocompleteElement.d.ts +6 -0
- package/dist/preact/src/components/BaseElement.d.ts +17 -0
- package/dist/preact/src/components/SerpElement.d.ts +5 -12
- package/dist/preact/src/components/types.d.ts +7 -0
- package/dist/preact/src/config/pages/autocomplete/config.d.ts +6 -0
- package/dist/search-Bhebxu8K.cjs +1 -0
- package/dist/search-BrR80UbS.js +164 -0
- package/dist/useLoadMore-CeqFdxt1.cjs +1 -0
- package/dist/{useLoadMore-CzqfcD1v.js → useLoadMore-Der8Cglb.js} +16 -15
- package/package.json +4 -4
- package/dist/preact/src/components/Autocomplete/AutocompleteElement.d.ts +0 -36
- package/dist/preact/src/components/Autocomplete/utils.d.ts +0 -5
- package/dist/search-DapMuqyR.cjs +0 -1
- package/dist/search-PYPD19kM.js +0 -138
- package/dist/useLoadMore-BJWBvbZ1.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const h=require("./jsxRuntime.module-B3sGoTIU.cjs"),q=require("preact/hooks");function B({onClick:i,as:l,children:e,componentProps:u}){const k={...u,onClick:q.useCallback(f=>{var a;i(),(a=u==null?void 0:u.onClick)==null||a.call(u,f)},[i,u])},C=l??(u&&"href"in u?"a":"span");return h.u(C,{...k,children:e})}exports.BaseElement=B;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { u as b } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
+
import { useCallback as h } from "preact/hooks";
|
|
3
|
+
function d({ onClick: i, as: l, children: u, componentProps: a }) {
|
|
4
|
+
const C = {
|
|
5
|
+
...a,
|
|
6
|
+
onClick: h(
|
|
7
|
+
(B) => {
|
|
8
|
+
var f;
|
|
9
|
+
i(), (f = a == null ? void 0 : a.onClick) == null || f.call(a, B);
|
|
10
|
+
},
|
|
11
|
+
[i, a]
|
|
12
|
+
)
|
|
13
|
+
}, k = l ?? (a && "href" in a ? "a" : "span");
|
|
14
|
+
return /* @__PURE__ */ b(k, { ...C, children: u });
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
d as B
|
|
18
|
+
};
|
package/dist/{InfiniteScrollWithObserver-Do05gtr2.cjs → InfiniteScrollWithObserver-BZeSt2TI.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-CeqFdxt1.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-CvnCyquA.js → InfiniteScrollWithObserver-DYKAh87P.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as f } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { a, b as l } from "./useLoadMore-
|
|
2
|
+
import { a, b as l } from "./useLoadMore-Der8Cglb.js";
|
|
3
3
|
import { p as d } from "./pick-DReBictn.js";
|
|
4
4
|
import { useRef as m, useEffect as b } from "preact/hooks";
|
|
5
5
|
import { Fragment as v } from "preact";
|
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-Bhebxu8K.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-BrR80UbS.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
|
}
|
package/dist/core/src/types.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ export type SearchOptions<HD extends readonly HitDecorator[] = readonly HitDecor
|
|
|
16
16
|
* Whether to use a persistent cache for the search results. Default: false.
|
|
17
17
|
*/
|
|
18
18
|
usePersistentCache?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to use a in-memory cache
|
|
21
|
+
*/
|
|
22
|
+
useMemoryCache?: boolean;
|
|
19
23
|
};
|
|
20
24
|
export type SearchFn = (query: SearchQuery, options: SearchOptions) => Promise<SearchResult>;
|
|
21
25
|
export type SearchWithNext = (query: SearchQuery, options: SearchOptions, searchFn: SearchFn) => Promise<SearchResult>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SearchFn, SearchOptions } from './types';
|
|
2
|
+
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
3
|
+
export declare function clearMemoryCache(): void;
|
|
4
|
+
export declare function searchWithMemoryCache(query: SearchQuery, options: SearchOptions, searchFn: SearchFn): Promise<SearchResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../index.es-DlUp67LT.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../jsxRuntime.module-B3sGoTIU.cjs"),s=require("../index.es-DlUp67LT.cjs"),p=require("preact/hooks"),m=require("../BaseElement-B0hSjDTT.cjs"),i=require("../configContext-BR7w4VlU.cjs"),a=require("../baseConfig-BFFqFSg5.cjs");function f({children:e,hit:t,as:o,componentProps:n}){const r=p.useCallback(()=>{t&&"productId"in t&&s.s(c=>c.recordSearchClick("autocomplete",t))},[t]);return u.u(m.BaseElement,{onClick:r,as:o,componentProps:n,children:e})}function C({as:e,componentProps:t,onSearchInput:o,children:n}){const r={...t,onInput:l=>{o(l.target)}},c=e??"input";return e||(r.type="search"),u.u(c,{...r,children:n})}const d={...a.defaultBaseConfig,memoryCache:!1};function g(e){return{pageType:"autocomplete",...d,...e}}function S({config:e,store:t,children:o}){const n=t??i.createStore();return a.useCheckClientScript(),u.u(i.ConfigContext,{value:g(e),children:u.u(i.StoreContext,{value:n,children:o})})}exports.AutocompleteElement=f;exports.AutocompletePageProvider=S;exports.SearchInput=C;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @module preact/autocomplete */
|
|
2
|
-
export { AutocompleteElement } from './src/components/
|
|
2
|
+
export { AutocompleteElement, type AutocompleteElementProps } from './src/components/AutocompleteElement';
|
|
3
3
|
export { SearchInput } from './src/components/SearchInput';
|
|
4
4
|
export type { PublicAutocompleteConfig as AutocompleteConfig } from './src/config/pages/autocomplete/config';
|
|
5
5
|
export { AutocompletePageProvider } from './src/config/pages/autocomplete/provider';
|
|
@@ -1,49 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { u as c } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
+
import { s as m } from "../index.es-B8mbAxS4.js";
|
|
3
|
+
import { useCallback as p } from "preact/hooks";
|
|
4
|
+
import { B as i } from "../BaseElement-IyqEeIiJ.js";
|
|
5
|
+
import { c as l, S as f, C as s } from "../configContext-GuZOIX3o.js";
|
|
6
|
+
import { d as C, u as d } from "../baseConfig-Bafl02NY.js";
|
|
7
|
+
function B({
|
|
8
|
+
children: e,
|
|
9
|
+
hit: o,
|
|
10
|
+
as: t,
|
|
11
|
+
componentProps: r
|
|
12
|
+
}) {
|
|
13
|
+
const n = p(() => {
|
|
14
|
+
o && "productId" in o && m((a) => a.recordSearchClick("autocomplete", o));
|
|
15
|
+
}, [o]);
|
|
16
|
+
return /* @__PURE__ */ c(i, { onClick: n, as: t, componentProps: r, children: e });
|
|
8
17
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
throw new Error(
|
|
13
|
-
"AutocompleteElement expects a single valid HTML element as its child (e.g., <div>, <a>). Custom components are not supported."
|
|
14
|
-
);
|
|
15
|
-
const o = (n = t.props) == null ? void 0 : n.onClick;
|
|
16
|
-
return a(t, {
|
|
17
|
-
onClick: (r) => {
|
|
18
|
-
e && c((p) => p.recordSearchClick("autocomplete", e)), typeof o == "function" && o(r);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function P({ as: t, componentProps: e, onSearchInput: o, children: n }) {
|
|
23
|
-
const r = {
|
|
24
|
-
...e,
|
|
18
|
+
function I({ as: e, componentProps: o, onSearchInput: t, children: r }) {
|
|
19
|
+
const n = {
|
|
20
|
+
...o,
|
|
25
21
|
onInput: (u) => {
|
|
26
|
-
|
|
22
|
+
t(u.target);
|
|
27
23
|
}
|
|
28
|
-
},
|
|
29
|
-
return
|
|
24
|
+
}, a = e ?? "input";
|
|
25
|
+
return e || (n.type = "search"), /* @__PURE__ */ c(a, { ...n, children: r });
|
|
30
26
|
}
|
|
31
|
-
const
|
|
32
|
-
...
|
|
27
|
+
const g = {
|
|
28
|
+
...C,
|
|
29
|
+
memoryCache: !1
|
|
33
30
|
};
|
|
34
|
-
function S(
|
|
31
|
+
function S(e) {
|
|
35
32
|
return {
|
|
36
33
|
pageType: "autocomplete",
|
|
37
|
-
...
|
|
38
|
-
...
|
|
34
|
+
...g,
|
|
35
|
+
...e
|
|
39
36
|
};
|
|
40
37
|
}
|
|
41
|
-
function
|
|
42
|
-
const
|
|
43
|
-
return
|
|
38
|
+
function P({ config: e, store: o, children: t }) {
|
|
39
|
+
const r = o ?? l();
|
|
40
|
+
return d(), /* @__PURE__ */ c(s, { value: S(e), children: /* @__PURE__ */ c(f, { value: r, children: t }) });
|
|
44
41
|
}
|
|
45
42
|
export {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
B as AutocompleteElement,
|
|
44
|
+
P as AutocompletePageProvider,
|
|
45
|
+
I as SearchInput
|
|
49
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-Blp-K9zG.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../unique-Blp-K9zG.cjs"),t=require("../jsxRuntime.module-B3sGoTIU.cjs"),c=require("../useLoadMore-CeqFdxt1.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-BZeSt2TI.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,8 +1,8 @@
|
|
|
1
1
|
import { i as l } from "../unique-m1TIDWdl.js";
|
|
2
2
|
import { u as r } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
|
-
import { b as p, a as m } from "../useLoadMore-
|
|
3
|
+
import { b as p, a as m } from "../useLoadMore-Der8Cglb.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-DYKAh87P.js";
|
|
6
6
|
import { Fragment as h } from "preact";
|
|
7
7
|
import { S as O, a as W, c as A, d as B } from "../configContext-GuZOIX3o.js";
|
|
8
8
|
function M({ pageSize: e }) {
|
package/dist/preact/hooks.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../useLoadMore-CeqFdxt1.cjs"),z=require("../logger-BcHMZObS.cjs"),p=require("preact/hooks"),P=require("../index.es-DlUp67LT.cjs"),N=require("../parseNumber-FsZ8w61u.cjs");function T(e){const r=h.useNostoAppState(t=>t.response);return e&&Array.isArray(e)||e&&z.isPlainObject(e)?e:r}function q(e,r){var d;const t=((d=e.data)==null?void 0:d.filter(s=>s.selected).length)??0,{active:n}={active:t>0,...r},[o,a]=p.useState(n),{toggleProductFilter:c}=h.useActions(),i=p.useCallback(()=>{a(!o)},[o]);return{active:o,selectedFiltersCount:t,toggleActive:i,toggleProductFilter:c}}function X(){const{loading:e,facets:r}=h.useNostoAppState(t=>{var n,o;return{loading:t.loading,facets:((o=(n=t.response)==null?void 0:n.products)==null?void 0:o.facets)??[]}});return{loading:e,facets:r}}function O(e,r){const t=r-e;return!isNaN(t)&&t>0?new Array(r-e).fill(void 0).map((n,o)=>o+e):[]}function j(e){const{query:r,products:t}=h.useNostoAppState(n=>({query:n.query,products:n.response.products}));return p.useMemo(()=>{var F,y,w;if(!t)return{totalPages:0,resultsFrom:0,resultsTo:0,pages:[]};const n=((F=r.products)==null?void 0:F.from)??0,o=(e==null?void 0:e.width)??1/0,a=Math.max(Math.floor(o-1)/2,1),c=t.size>0?Math.floor(n/t.size)+1:1,i=t.size>0?Math.ceil(t.total/t.size):0,d=A=>A>=c-a&&A<=c+a,s=n+1,l=Math.min(n+t.total,t.total),u={from:n,page:c,current:!0},f=A=>({from:(A-1)*t.size,page:A,current:A===c}),m=c>1?f(c-1):void 0,g=c<i?f(c+1):void 0,b=c-a-1>1?f(1):void 0,S=c+a+1<i?f(i):void 0,v=O(1,i+1).filter(d).map(f);return!b&&((y=v[0])==null?void 0:y.page)===2&&v.unshift(f(1)),!S&&((w=v[v.length-1])==null?void 0:w.page)===i-1&&v.push(f(i)),{totalPages:i,resultsFrom:s,resultsTo:l,current:u,prev:m,next:g,first:b,last:S,pages:v}},[r,t,e==null?void 0:e.width])}function V(){const[e,r]=p.useState([]),[t,n]=p.useState([]);return p.useEffect(()=>{P.s(async o=>{const{products:a,segments:c}=await o.getSearchSessionParams();r(c??[]),n((a==null?void 0:a.personalizationBoost)??[])})},[]),{segments:e,boost:t}}function D(){const{facets:e}=h.useNostoAppState(s=>{var l;return{facets:((l=s.response.products)==null?void 0:l.facets)??[]}}),{replaceFilter:r,toggleProductFilter:t}=h.useActions(),n=p.useCallback(s=>{const l=e==null?void 0:e.find(u=>u.type==="stats"&&u.field===s);if(l&&"min"in l&&"max"in l)return l},[e]),o=p.useCallback(s=>{var l;return((l=e==null?void 0:e.find(u=>u.field===s))==null?void 0:l.name)??s},[e]),a=p.useCallback(s=>"field"in s&&(s.value instanceof Array||s.range instanceof Array),[]),c=p.useCallback(s=>{var l;return{...s,range:(l=s.range)==null?void 0:l.map(u=>({gt:u.gt?Number(u.gt):u.gt,gte:u.gte?Number(u.gte):u.gte,lt:u.lt?Number(u.lt):u.lt,lte:u.lte?Number(u.lte):u.lte}))}},[]),i=p.useCallback(s=>(s.value??[]).map(u=>({value:u,field:s.field,name:o(s.field),filter:c(s),remove:()=>{t(s.field,u,!1)}})),[c,o,t]),d=p.useCallback(s=>(s.range??[]).map(u=>{var g,b;const f=u.gte??u.gt??((g=n(s.field))==null?void 0:g.min),m=u.lte??u.lt??((b=n(s.field))==null?void 0:b.max);if(f!==void 0&&m!==void 0)return{value:`${f} - ${m}`,field:s.field,name:o(s.field),filter:c(s),remove:()=>{r(s.field,void 0)}}}).filter(Boolean),[c,n,o,r]);return{selectFilters:a,toValueFilter:i,toRangeFilter:d}}function k(){const{filter:e}=h.useNostoAppState(i=>{var d;return{filter:((d=i.query.products)==null?void 0:d.filter)??[]}}),{updateSearch:r}=h.useActions(),{selectFilters:t,toValueFilter:n,toRangeFilter:o}=D(),a=p.useMemo(()=>e?e.filter(t).flatMap(i=>"value"in i?n(i):"range"in i?o(i):[]).filter(Boolean):[],[e,t,o,n]),c=p.useCallback(()=>{r({products:{filter:[]}})},[r]);return{filters:a,removeAll:c}}function x(e){var u,f,m;const{replaceFilter:r}=h.useActions(),{query:t,products:n}=h.useNostoAppState(g=>({query:g.query,products:g.response.products})),o=(u=n==null?void 0:n.facets)==null?void 0:u.find(g=>g.id===e);if(!o)return{min:0,max:0,range:[0,0],updateRange:()=>{}};const a=(m=(f=t.products)==null?void 0:f.filter)==null?void 0:m.find(g=>g.field===o.field),c=a!=null&&a.range?a.range[0]:void 0,i=typeof c=="object"&&("gte"in c||"lte"in c)?[N.parseNumber(c.gte),N.parseNumber(c.lte)]:[void 0,void 0],d="min"in o?Math.floor(o.min):0,s="max"in o?Math.ceil(o.max):0,l=([g,b])=>{const S=g!==void 0?Math.floor(g):void 0,v=b!==void 0?Math.ceil(b):void 0,F=S!==void 0,y=v!==void 0;(d===S||!F)&&(s===v||!y)?r(o.field,void 0):(d===S||!F)&&y?r(o.field,{lte:v.toString()}):(s===v||!y)&&F?r(o.field,{gte:S.toString()}):F&&y&&r(o.field,{gte:S.toString(),lte:v.toString()})};return{min:d,max:s,range:[i[0]??d,i[1]??s],updateRange:l}}function B(e,r){const{min:t,max:n,range:o,updateRange:a}=x(e),{filters:c}=k(),i=p.useMemo(()=>{var b;const u=c.find(S=>{var v;return(v=S==null?void 0:S.filter)==null?void 0:v.range});let f=null;if(u){const S=(b=u.filter.range)==null?void 0:b[0];f=[N.parseNumber(S==null?void 0:S.gte),N.parseNumber(S==null?void 0:S.lte)]}const m=[];let g=Math.floor(t/r)*r;for(;g<n;){const S=g+r,v=f&&f[0]===g&&f[1]===S;m.push({min:g,max:S,selected:v}),g=S}return m},[c,t,n,r]),d=u=>{a([u,o[1]])},s=u=>{a([o[0],u])},l=t!==o[0]||n!==o[1];return{min:t,max:n,range:o,updateRange:a,ranges:i,handleMinChange:d,handleMaxChange:s,isSelected:l}}function E(){const{products:e,keywords:r}=h.useNostoAppState(t=>t.response);return{products:e??{hits:[],total:0},keywords:r??{hits:[],total:0}}}function _(){const e=h.useNostoAppState(t=>{var n;return(n=t.query.products)==null?void 0:n.filter});return p.useMemo(()=>e?e.reduce((t,n)=>t+(Array.isArray(n.value)?n.value.length:1),0):0,[e])}function M(e){return e&&!Number.isNaN(e)?e:0}function U(e,r){const{from:t,size:n,total:o}=h.useNostoAppState(s=>{var l,u,f,m,g;return{from:M(((l=s.query.products)==null?void 0:l.from)??0),size:M(((f=(u=s.response)==null?void 0:u.products)==null?void 0:f.size)??0),total:M(((g=(m=s.response)==null?void 0:m.products)==null?void 0:g.total)??0)}}),{updateSearch:a}=h.useActions(),c=t+n,i=[...e].reverse().filter(s=>s+r<o);return{from:t,to:c,total:o,size:n,sizeOptions:i,handleSizeChange:s=>{a({products:{size:N.parseNumber(s)}})}}}function $(e,r){return e.length!==r.length?!1:e.every(t=>r.find(n=>t.field===n.field&&t.order===n.order))}function I(e){var a,c;const r=h.useNostoAppState(i=>i.query),{updateSearch:t}=h.useActions();return{activeSort:((a=e.find(i=>{var d;return $(i.value.sort,((d=r.products)==null?void 0:d.sort)||[])}))==null?void 0:a.id)??((c=e[0])==null?void 0:c.id),setSort:i=>{const d=e.find(s=>s.id===i);d&&t({products:{sort:d.value.sort}})}}}const R=window.SpeechRecognition||window.webkitSpeechRecognition,L=!!(R&&typeof R=="function");function Z(){return{listening:!1,startListening:()=>{},stopListening:()=>{}}}function G({language:e="en-US",interimResults:r=!1}={}){const[t,n]=p.useState(!1),o=p.useRef(null),a=p.useCallback(({onResult:i,onError:d})=>{const s=new R;s.lang=e,s.interimResults=r,s.onstart=()=>n(!0),s.onresult=l=>{var f,m;const{transcript:u}=(m=(f=l.results)==null?void 0:f[0])==null?void 0:m[0];i(u)},d&&(s.onerror=l=>d(l.error)),s.onend=()=>n(!1),o.current=s,s.start()},[e,r]),c=p.useCallback(()=>{var i;(i=o.current)==null||i.stop()},[o]);return{listening:t,startListening:a,stopListening:c}}const H=L?G:Z;function J(e,r){if(!e.length||!r.length)return[];const t=r.reduce((n,o)=>(n[o]={},n),{});return e.forEach(n=>{var o;(o=n.customFields)==null||o.forEach(({key:a,value:c})=>{const i=a.toLowerCase();r.includes(i)&&(t[i][c]=t[i][c]||[],t[i][c].push(n))})}),Object.entries(t).filter(n=>Object.keys(n[1]).length).map(([n,o])=>({field:n,options:Object.entries(o).map(([a,c])=>({value:a,skus:c,unavailable:!1,selected:!1}))}))}function K(e,r){return e.length?e.map(({field:t,options:n})=>({field:t,options:n.map(o=>{var i;const a=!((i=o.skus)!=null&&i.some(d=>Object.entries(r).every(([s,l])=>{var f,m;return s===t?!0:((m=(f=d.customFields)==null?void 0:f.find(g=>g.key.toLowerCase()===s))==null?void 0:m.value)===l}))),c=r[t]===o.value;return{...o,unavailable:a,selected:c}})})):[]}const C=["4XS","3XS","2XS","XXS","XS","S","M","L","XL","XXL","2XL","XXXL","3XL","4XL"];function Q(e){if(C.includes(e))return 1e3+C.indexOf(e);const r=parseFloat(e);return isNaN(r)?e:r}function W(e,r){return[...r].sort((t,n)=>{const[o,a]=[t.value,n.value].map(Q);return o<a?-1:1})}function Y(e=[],r=[]){const[t,n]=p.useState({}),o=p.useMemo(()=>J(e,r).map(({field:s,options:l})=>({field:s,options:W(s,l)})),[e,r]),a=p.useMemo(()=>K(o,t),[o,t]),c=p.useCallback((d,s)=>{n(l=>{const u={...l};return u[d]===s?delete u[d]:u[d]=s,u})},[]),i=p.useMemo(()=>Object.keys(t).filter(l=>t[l]).length===0?[]:a.filter(({field:l})=>t[l]).map(({field:l,options:u})=>{const f=t[l],m=u.find(g=>g.value===f);return(m==null?void 0:m.skus)??[]}).reduce((l,u)=>l.filter(f=>u.includes(f))),[a,t]);return{swatches:a,toggleOption:c,matchedSkus:i}}exports.useActions=h.useActions;exports.useLoadMore=h.useLoadMore;exports.useNostoAppState=h.useNostoAppState;exports.speechToTextSupported=L;exports.useDecoratedSearchResults=T;exports.useFacet=q;exports.useFacets=X;exports.usePagination=j;exports.usePersonalization=V;exports.useProductFilters=k;exports.useRange=x;exports.useRangeSelector=B;exports.useResponse=E;exports.useSelectedFiltersCount=_;exports.useSizeOptions=U;exports.useSort=I;exports.useSpeechToText=H;exports.useSwatches=Y;
|
package/dist/preact/hooks.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as y, c as x } from "../useLoadMore-
|
|
2
|
-
import { b as fe } from "../useLoadMore-
|
|
1
|
+
import { a as y, c as x } from "../useLoadMore-Der8Cglb.js";
|
|
2
|
+
import { b as fe } from "../useLoadMore-Der8Cglb.js";
|
|
3
3
|
import { a as P } from "../logger-DVwg4Wor.js";
|
|
4
4
|
import { useState as L, useCallback as S, useMemo as b, useEffect as O, useRef as T } from "preact/hooks";
|
|
5
5
|
import { s as C } from "../index.es-B8mbAxS4.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../useLoadMore-CeqFdxt1.cjs"),r=require("../InfiniteScrollWithObserver-BZeSt2TI.cjs");exports.getNextPageQuery=e.getNextPageQuery;exports.newSearch=e.newSearch;exports.updateSearch=e.updateSearch;exports.InfiniteScrollWithObserver=r.InfiniteScrollWithObserver;exports.intersectionObserverSupported=r.intersectionObserverSupported;
|
package/dist/preact/legacy.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as t, n as a, u as s } from "../useLoadMore-
|
|
2
|
-
import { I as i, i as n } from "../InfiniteScrollWithObserver-
|
|
1
|
+
import { g as t, n as a, u as s } from "../useLoadMore-Der8Cglb.js";
|
|
2
|
+
import { I as i, i as n } from "../InfiniteScrollWithObserver-DYKAh87P.js";
|
|
3
3
|
export {
|
|
4
4
|
i as InfiniteScrollWithObserver,
|
|
5
5
|
t as getNextPageQuery,
|
package/dist/preact/preact.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @module preact */
|
|
2
|
-
export { AutocompleteElement } from './src/components/
|
|
2
|
+
export { AutocompleteElement, type AutocompleteElementProps } from './src/components/AutocompleteElement';
|
|
3
3
|
export { InfiniteScroll, type InfiniteScrollProps } from './src/components/InfiniteScroll/InfiniteScroll';
|
|
4
4
|
export { InfiniteScrollWithLink } from './src/components/InfiniteScroll/InfiniteScrollWithLink';
|
|
5
5
|
export { SearchInput } from './src/components/SearchInput';
|
package/dist/preact/serp.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../jsxRuntime.module-B3sGoTIU.cjs"),S=require("../index.es-DlUp67LT.cjs"),r=require("../configContext-BR7w4VlU.cjs"),g=require("preact/hooks"),f=require("../BaseElement-B0hSjDTT.cjs"),i=require("../baseConfig-BFFqFSg5.cjs"),C="nosto:search:scrollPos";function p(){window.sessionStorage.setItem(C,window.scrollY.toString())}function d({children:e,hit:o,componentProps:t,as:n}){const{pageType:s}=r.useConfig(),c=s==="autocomplete"?void 0:s==="search"?"serp":s,l=g.useCallback(()=>{o&&c&&S.s(u=>u.recordSearchClick(c,o)),p()},[o,c]);return a.u(f.BaseElement,{as:n,onClick:l,componentProps:t,children:e})}const m={...i.defaultBaseConfig,persistentSearchCache:!1,preservePageScroll:!1};function h(e={}){return{pageType:"search",...m,...e}}function P({config:e,store:o,children:t}){const n=o??r.createStore();return i.useCheckClientScript(),a.u(r.ConfigContext,{value:h(e),children:a.u(r.StoreContext,{value:n,children:t})})}exports.SearchPageProvider=P;exports.SerpElement=d;
|
package/dist/preact/serp.es.js
CHANGED
|
@@ -1,41 +1,36 @@
|
|
|
1
1
|
import { u as n } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import { s as
|
|
3
|
-
import { u as
|
|
4
|
-
import { useCallback as
|
|
5
|
-
import {
|
|
2
|
+
import { s as l } from "../index.es-B8mbAxS4.js";
|
|
3
|
+
import { u as f, c as p, S as u, C as m } from "../configContext-GuZOIX3o.js";
|
|
4
|
+
import { useCallback as S } from "preact/hooks";
|
|
5
|
+
import { B as C } from "../BaseElement-IyqEeIiJ.js";
|
|
6
|
+
import { d as g, u as d } from "../baseConfig-Bafl02NY.js";
|
|
6
7
|
const h = "nosto:search:scrollPos";
|
|
7
|
-
function
|
|
8
|
+
function k() {
|
|
8
9
|
window.sessionStorage.setItem(h, window.scrollY.toString());
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
const { pageType:
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[r, e, c]
|
|
16
|
-
), i = {
|
|
17
|
-
...e,
|
|
18
|
-
onClick: s
|
|
19
|
-
};
|
|
20
|
-
return /* @__PURE__ */ n(o ?? "a", { ...i, children: t });
|
|
11
|
+
function b({ children: e, hit: o, componentProps: r, as: t }) {
|
|
12
|
+
const { pageType: s } = f(), a = s === "autocomplete" ? void 0 : s === "search" ? "serp" : s, c = S(() => {
|
|
13
|
+
o && a && l((i) => i.recordSearchClick(a, o)), k();
|
|
14
|
+
}, [o, a]);
|
|
15
|
+
return /* @__PURE__ */ n(C, { as: t, onClick: c, componentProps: r, children: e });
|
|
21
16
|
}
|
|
22
|
-
const
|
|
23
|
-
...
|
|
17
|
+
const v = {
|
|
18
|
+
...g,
|
|
24
19
|
persistentSearchCache: !1,
|
|
25
20
|
preservePageScroll: !1
|
|
26
21
|
};
|
|
27
|
-
function
|
|
22
|
+
function P(e = {}) {
|
|
28
23
|
return {
|
|
29
24
|
pageType: "search",
|
|
30
|
-
...
|
|
31
|
-
...
|
|
25
|
+
...v,
|
|
26
|
+
...e
|
|
32
27
|
};
|
|
33
28
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
return
|
|
29
|
+
function I({ config: e, store: o, children: r }) {
|
|
30
|
+
const t = o ?? p();
|
|
31
|
+
return d(), /* @__PURE__ */ n(m, { value: P(e), children: /* @__PURE__ */ n(u, { value: t, children: r }) });
|
|
37
32
|
}
|
|
38
33
|
export {
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
I as SearchPageProvider,
|
|
35
|
+
b as SerpElement
|
|
41
36
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AsComponent, BaseElementProps } from './BaseElement';
|
|
2
|
+
import { KeywordHit, ProductHit } from './types';
|
|
3
|
+
export type AutocompleteElementProps<C extends AsComponent> = Omit<BaseElementProps<C>, "onClick"> & {
|
|
4
|
+
hit: ProductHit | KeywordHit;
|
|
5
|
+
};
|
|
6
|
+
export declare function AutocompleteElement<C extends AsComponent>({ children, hit, as, componentProps }: AutocompleteElementProps<C>): import("preact").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentChildren, ComponentProps, ComponentType, JSX } from 'preact';
|
|
2
|
+
export type AsComponent = keyof JSX.IntrinsicElements | ComponentType<any>;
|
|
3
|
+
/**
|
|
4
|
+
* @group Components
|
|
5
|
+
*/
|
|
6
|
+
export type BaseElementProps<C extends AsComponent> = {
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
as?: C;
|
|
9
|
+
componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
|
|
10
|
+
children?: ComponentChildren;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Wrapper component that can be used to wrap any element in the search result list.
|
|
14
|
+
*
|
|
15
|
+
* @group Components
|
|
16
|
+
*/
|
|
17
|
+
export declare function BaseElement<C extends AsComponent>({ onClick, as, children, componentProps }: BaseElementProps<C>): JSX.Element;
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AsComponent, BaseElementProps } from './BaseElement';
|
|
2
|
+
import { ProductHit } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* @group Components
|
|
5
5
|
*/
|
|
6
|
-
export type SerpElementProps<C extends AsComponent> = {
|
|
7
|
-
hit:
|
|
8
|
-
productId: string;
|
|
9
|
-
url?: string;
|
|
10
|
-
};
|
|
11
|
-
as?: C;
|
|
12
|
-
componentProps?: JSX.LibraryManagedAttributes<C, ComponentProps<C>>;
|
|
13
|
-
children?: ComponentChildren;
|
|
6
|
+
export type SerpElementProps<C extends AsComponent> = Omit<BaseElementProps<C>, "onClick"> & {
|
|
7
|
+
hit: ProductHit;
|
|
14
8
|
};
|
|
15
9
|
/**
|
|
16
10
|
* Wrapper component that can be used to wrap any element in the search result list.
|
|
17
11
|
*
|
|
18
12
|
* @group Components
|
|
19
13
|
*/
|
|
20
|
-
export declare function SerpElement<C extends AsComponent>({
|
|
21
|
-
export {};
|
|
14
|
+
export declare function SerpElement<C extends AsComponent>({ children, hit, componentProps, as }: SerpElementProps<C>): import("preact").JSX.Element;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { BaseConfig } from '../../base/baseConfig';
|
|
2
2
|
export declare const defaultAutocompleteConfig: {
|
|
3
|
+
memoryCache: false;
|
|
3
4
|
defaultCurrency: string;
|
|
4
5
|
queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery) => import('@nosto/nosto-js/client').SearchQuery;
|
|
5
6
|
};
|
|
6
7
|
export interface AutocompleteConfig extends BaseConfig {
|
|
7
8
|
pageType: "autocomplete";
|
|
9
|
+
/**
|
|
10
|
+
* Enable in-memory caching
|
|
11
|
+
*/
|
|
12
|
+
memoryCache: boolean;
|
|
8
13
|
}
|
|
9
14
|
export type PublicAutocompleteConfig = Omit<AutocompleteConfig, keyof typeof defaultAutocompleteConfig | "pageType"> & Partial<Pick<AutocompleteConfig, keyof typeof defaultAutocompleteConfig>>;
|
|
10
15
|
export declare function makeAutocompleteConfig(config: PublicAutocompleteConfig): {
|
|
@@ -13,5 +18,6 @@ export declare function makeAutocompleteConfig(config: PublicAutocompleteConfig)
|
|
|
13
18
|
onSearchError?: ((error: unknown, query: import('@nosto/nosto-js/client').SearchQuery, options: import('../../../../../core/src/types').SearchOptions, pageType: import('../../../api/types').PageType) => void) | undefined;
|
|
14
19
|
defaultCurrency: string;
|
|
15
20
|
queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
|
|
21
|
+
memoryCache: boolean;
|
|
16
22
|
pageType: "autocomplete";
|
|
17
23
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const b=require("./index.es-DlUp67LT.cjs"),u=require("./logger-BcHMZObS.cjs");async function N(t,{hitDecorators:e,...n},s){var o,i;const r=await s(t,n);if(!((i=(o=r.products)==null?void 0:o.hits)!=null&&i.length)||!(e!=null&&e.length))return r;const c=a=>e.reduce((f,l)=>l(f),a);return{...r,products:{...r.products,hits:r.products.hits.map(c)}}}function T(t,e,n){const s=JSON.stringify(e);try{n.setItem(t,s)}catch(r){u.logger.warn(r)}}function z(t,e){try{const n=e.getItem(t);if(n)return JSON.parse(n)}catch(n){u.logger.warn(n)}}function E(t,e){T(t,e,sessionStorage)}function O(t){return z(t,sessionStorage)}const R="nosto:search-js:cache",J=60*1e3;function k(t,e){E(R,{query:t,result:e,created:Date.now()})}function I(t){const e=O(R);if(!e||!M(e))return null;const n=C(e.query);return!u.isEqual(C(t),n)||Date.now()-e.created>J?null:e.result}function C(t){const e={...t,time:void 0,products:{...t.products,size:void 0}};return JSON.parse(JSON.stringify(e))}function M(t){return typeof t=="object"&&t!==null&&"query"in t&&"result"in t&&"created"in t}async function V(t,{usePersistentCache:e,...n},s){if(!e)return s(t,n);const r=await W(t,n,s);return k(t,r),r}async function W(t,e,n){var p,g,S,w,m,y;const{from:s=0,size:r=0}=t.products||{},c=I(t);if(!c)return await n(t,e);const o=((p=c==null?void 0:c.products)==null?void 0:p.size)??0,i=((g=c==null?void 0:c.products)==null?void 0:g.hits)??[];if(r===o)return c;if(r<o)return{...c,products:{...c.products,size:r,hits:i.slice(0,r),total:((S=c.products)==null?void 0:S.total)||0}};const a=r-i.length,f=s>0?s+1:r-a,l={...t,products:{...t.products,from:f,size:a}},h=await n(l,e);return{...c,products:{...c.products,size:r,hits:[...((w=c.products)==null?void 0:w.hits)||[],...((m=h.products)==null?void 0:m.hits)||[]],total:((y=h.products)==null?void 0:y.total)||0}}}const j=3e4,d=new Map;function _(t,e){const n=d.get(t);if(!n)return;const s=Date.now()-n.created>j,r=u.isEqual(e,n.query);if(s||!r){d.delete(t);return}return n.result}function x(t,e,n){d.set(t,{query:e,result:n,created:Date.now()})}async function A(t,e,n){if(!e.useMemoryCache)return n(t,e);const s=JSON.stringify(t),r=_(s,t);if(r)return r;const c=await n(t,e);return x(s,t,c),c}function K(t){return new Promise(e=>setTimeout(e,t))}async function L(t,{maxRetries:e=0,retryInterval:n=0,...s},r){let c=0;for(;;)try{return await r(t,s)}catch(o){if(c>=e)throw o;if(!P(o))throw u.logger.info("Skipping retry logic for",o),o;c++,await K(n)}}function P(t){return!t||typeof t!="object"?!1:!("status"in t)||F(t.status)}function F(t){return typeof t=="number"&&(t<400||t>=500)}async function G(t,e={}){const n=await new Promise(b.s);return H(n.search,L,A,V,N)(t,e)}function H(t,...e){return e.reduce((n,s)=>(r,c)=>s(r,c,n),t)}exports.search=G;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { s as N } from "./index.es-B8mbAxS4.js";
|
|
2
|
+
import { l, i as R } from "./logger-DVwg4Wor.js";
|
|
3
|
+
async function T(t, { hitDecorators: e, ...n }, s) {
|
|
4
|
+
var o, i;
|
|
5
|
+
const r = await s(t, n);
|
|
6
|
+
if (!((i = (o = r.products) == null ? void 0 : o.hits) != null && i.length) || !(e != null && e.length))
|
|
7
|
+
return r;
|
|
8
|
+
const c = (a) => e.reduce((u, f) => f(u), a);
|
|
9
|
+
return {
|
|
10
|
+
...r,
|
|
11
|
+
products: {
|
|
12
|
+
...r.products,
|
|
13
|
+
hits: r.products.hits.map(c)
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function z(t, e, n) {
|
|
18
|
+
const s = JSON.stringify(e);
|
|
19
|
+
try {
|
|
20
|
+
n.setItem(t, s);
|
|
21
|
+
} catch (r) {
|
|
22
|
+
l.warn(r);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function O(t, e) {
|
|
26
|
+
try {
|
|
27
|
+
const n = e.getItem(t);
|
|
28
|
+
if (n)
|
|
29
|
+
return JSON.parse(n);
|
|
30
|
+
} catch (n) {
|
|
31
|
+
l.warn(n);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function E(t, e) {
|
|
35
|
+
z(t, e, sessionStorage);
|
|
36
|
+
}
|
|
37
|
+
function J(t) {
|
|
38
|
+
return O(t, sessionStorage);
|
|
39
|
+
}
|
|
40
|
+
const b = "nosto:search-js:cache", k = 60 * 1e3;
|
|
41
|
+
function I(t, e) {
|
|
42
|
+
E(b, { query: t, result: e, created: Date.now() });
|
|
43
|
+
}
|
|
44
|
+
function M(t) {
|
|
45
|
+
const e = J(b);
|
|
46
|
+
if (!e || !V(e))
|
|
47
|
+
return null;
|
|
48
|
+
const n = C(e.query);
|
|
49
|
+
return !R(C(t), n) || Date.now() - e.created > k ? null : e.result;
|
|
50
|
+
}
|
|
51
|
+
function C(t) {
|
|
52
|
+
const e = {
|
|
53
|
+
...t,
|
|
54
|
+
time: void 0,
|
|
55
|
+
products: {
|
|
56
|
+
...t.products,
|
|
57
|
+
size: void 0
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return JSON.parse(JSON.stringify(e));
|
|
61
|
+
}
|
|
62
|
+
function V(t) {
|
|
63
|
+
return typeof t == "object" && t !== null && "query" in t && "result" in t && "created" in t;
|
|
64
|
+
}
|
|
65
|
+
async function W(t, { usePersistentCache: e, ...n }, s) {
|
|
66
|
+
if (!e)
|
|
67
|
+
return s(t, n);
|
|
68
|
+
const r = await j(t, n, s);
|
|
69
|
+
return I(t, r), r;
|
|
70
|
+
}
|
|
71
|
+
async function j(t, e, n) {
|
|
72
|
+
var h, g, m, S, w, y;
|
|
73
|
+
const { from: s = 0, size: r = 0 } = t.products || {}, c = M(t);
|
|
74
|
+
if (!c)
|
|
75
|
+
return await n(t, e);
|
|
76
|
+
const o = ((h = c == null ? void 0 : c.products) == null ? void 0 : h.size) ?? 0, i = ((g = c == null ? void 0 : c.products) == null ? void 0 : g.hits) ?? [];
|
|
77
|
+
if (r === o)
|
|
78
|
+
return c;
|
|
79
|
+
if (r < o)
|
|
80
|
+
return {
|
|
81
|
+
...c,
|
|
82
|
+
products: {
|
|
83
|
+
...c.products,
|
|
84
|
+
size: r,
|
|
85
|
+
hits: i.slice(0, r),
|
|
86
|
+
total: ((m = c.products) == null ? void 0 : m.total) || 0
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const a = r - i.length, u = s > 0 ? s + 1 : r - a, f = {
|
|
90
|
+
...t,
|
|
91
|
+
products: {
|
|
92
|
+
...t.products,
|
|
93
|
+
from: u,
|
|
94
|
+
size: a
|
|
95
|
+
}
|
|
96
|
+
}, p = await n(f, e);
|
|
97
|
+
return {
|
|
98
|
+
...c,
|
|
99
|
+
products: {
|
|
100
|
+
...c.products,
|
|
101
|
+
size: r,
|
|
102
|
+
hits: [...((S = c.products) == null ? void 0 : S.hits) || [], ...((w = p.products) == null ? void 0 : w.hits) || []],
|
|
103
|
+
total: ((y = p.products) == null ? void 0 : y.total) || 0
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const x = 3e4, d = /* @__PURE__ */ new Map();
|
|
108
|
+
function A(t, e) {
|
|
109
|
+
const n = d.get(t);
|
|
110
|
+
if (!n) return;
|
|
111
|
+
const s = Date.now() - n.created > x, r = R(e, n.query);
|
|
112
|
+
if (s || !r) {
|
|
113
|
+
d.delete(t);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
return n.result;
|
|
117
|
+
}
|
|
118
|
+
function K(t, e, n) {
|
|
119
|
+
d.set(t, {
|
|
120
|
+
query: e,
|
|
121
|
+
result: n,
|
|
122
|
+
created: Date.now()
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async function L(t, e, n) {
|
|
126
|
+
if (!e.useMemoryCache)
|
|
127
|
+
return n(t, e);
|
|
128
|
+
const s = JSON.stringify(t), r = A(s, t);
|
|
129
|
+
if (r) return r;
|
|
130
|
+
const c = await n(t, e);
|
|
131
|
+
return K(s, t, c), c;
|
|
132
|
+
}
|
|
133
|
+
function P(t) {
|
|
134
|
+
return new Promise((e) => setTimeout(e, t));
|
|
135
|
+
}
|
|
136
|
+
async function _(t, { maxRetries: e = 0, retryInterval: n = 0, ...s }, r) {
|
|
137
|
+
let c = 0;
|
|
138
|
+
for (; ; )
|
|
139
|
+
try {
|
|
140
|
+
return await r(t, s);
|
|
141
|
+
} catch (o) {
|
|
142
|
+
if (c >= e)
|
|
143
|
+
throw o;
|
|
144
|
+
if (!F(o))
|
|
145
|
+
throw l.info("Skipping retry logic for", o), o;
|
|
146
|
+
c++, await P(n);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function F(t) {
|
|
150
|
+
return !t || typeof t != "object" ? !1 : !("status" in t) || G(t.status);
|
|
151
|
+
}
|
|
152
|
+
function G(t) {
|
|
153
|
+
return typeof t == "number" && (t < 400 || t >= 500);
|
|
154
|
+
}
|
|
155
|
+
async function v(t, e = {}) {
|
|
156
|
+
const n = await new Promise(N);
|
|
157
|
+
return H(n.search, _, L, W, T)(t, e);
|
|
158
|
+
}
|
|
159
|
+
function H(t, ...e) {
|
|
160
|
+
return e.reduce((n, s) => (r, c) => s(r, c, n), t);
|
|
161
|
+
}
|
|
162
|
+
export {
|
|
163
|
+
v as s
|
|
164
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const y=require("./configContext-BR7w4VlU.cjs"),n=require("preact/hooks"),q=require("./search-Bhebxu8K.cjs"),g=require("./unique-Blp-K9zG.cjs"),h=require("./deepMerge-lDscDfII.cjs"),v=require("./logger-BcHMZObS.cjs");function T(e,t){return{...t,products:{facets:e==="autocomplete"?void 0:["*"],fields:A,...t.products},...t.keywords?{keywords:{...t.keywords,fields:g.unique([...I,...t.keywords.fields??[]]),highlight:t.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const A=["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"],I=["keyword","_redirect"];async function k(e,t,r){var d,l,m,S,C,w,b;const o=g.measure("newSearch"),c=e.config.pageType,u=c==="search"?"serp":c,a=h.deepMerge(e.store.getInitialState().query,t),s=h.deepMerge(e.config.search,r,{track:u,redirect:c!=="autocomplete",isKeyword:!!(r!=null&&r.isKeyword),usePersistentCache:e.config.pageType!=="autocomplete"&&e.config.persistentSearchCache,useMemoryCache:e.config.pageType==="autocomplete"&&e.config.memoryCache});(l=(d=e.config).onBeforeSearch)==null||l.call(d,e,s),e.store.updateState({query:a,loading:!0,initialized:!0});const i=e.config.queryModifications({...a,products:{...a.products,filter:g.mergeArrays((S=(m=e.store.getInitialState().query)==null?void 0:m.products)==null?void 0:S.filter,(C=t.products)==null?void 0:C.filter)}},c);try{const p=await q.search(T(e.config.pageType,i),s);e.store.updateState({response:p,loading:!1})}catch(p){v.logger.error("Search action failed",p),(b=(w=e.config).onSearchError)==null||b.call(w,p,i,s,c)}o()}async function f(e,t,r){const o=g.measure("updateSearch"),c=h.deepMerge(e.store.getState().query,{products:{from:0}},t);await k(e,c,r),o()}function P(e=Q){const t=n.useContext(y.StoreContext),[r,o]=n.useState(e(t.getState()));return t.onChange(e,o),n.useEffect(()=>()=>t.clearOnChange(o),[t]),r}const Q=e=>e;async function U(e,t,r){var a;const o=g.measure("replaceFilter"),c=(a=e.store.getState().query.products)==null?void 0:a.filter,u=r!==void 0?[{field:t,[typeof r=="object"?"range":"value"]:[r]}]:[];await f(e,{products:{filter:[...(c==null?void 0:c.filter(s=>s.field!==t))??[],...u]}}),o()}async function L(e,t,r,o){var i,d;const c=g.measure("toggleProductFilter"),u=(i=e.store.getState().query.products)==null?void 0:i.filter,a=u==null?void 0:u.find(l=>l.value instanceof Array&&l.field===t),s=a!=null&&a.value?{...a,value:[...a.value.filter(l=>!v.isEqual(l,r)),...o?[r]:[]]}:o?{field:t,value:[r]}:void 0;await f(e,{products:{filter:[...(u==null?void 0:u.filter(l=>l!==a))??[],...(d=s==null?void 0:s.value)!=null&&d.length?[s]:[]]}}),c()}function F(){const e=y.useConfig(),t=n.useContext(y.StoreContext),r=n.useMemo(()=>({config:e,store:t}),[e,t]),o=n.useCallback((s,i)=>k(r,s,i),[r]),c=n.useCallback((s,i)=>f(r,s,i),[r]),u=n.useCallback((s,i,d)=>L(r,s,i,d),[r]),a=n.useCallback((s,i)=>U(r,s,i),[r]);return{newSearch:o,updateSearch:c,toggleProductFilter:u,replaceFilter:a}}function M({from:e,size:t,pageSize:r}){return g.isBot()?{products:{from:e+r}}:{products:{size:t+r}}}function N(e=24){const{from:t,size:r}=P(u=>{var a,s;return{from:((a=u.query.products)==null?void 0:a.from)??0,size:((s=u.query.products)==null?void 0:s.size)??0}}),{updateSearch:o}=F();return{loadMore:n.useCallback(async()=>{await o(M({from:t,size:r,pageSize:e}))},[t,r,e,o])}}exports.getNextPageQuery=M;exports.newSearch=k;exports.updateSearch=f;exports.useActions=F;exports.useLoadMore=N;exports.useNostoAppState=P;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { S as C, u as F } from "./configContext-GuZOIX3o.js";
|
|
2
2
|
import { useContext as v, useState as P, useEffect as M, useMemo as T, useCallback as d } from "preact/hooks";
|
|
3
|
-
import { s as I } from "./search-
|
|
3
|
+
import { s as I } from "./search-BrR80UbS.js";
|
|
4
4
|
import { u as q, a as p, m as Q, i as U } from "./unique-m1TIDWdl.js";
|
|
5
5
|
import { d as f } from "./deepMerge-CZwCJzEe.js";
|
|
6
6
|
import { l as A, i as z } from "./logger-DVwg4Wor.js";
|
|
@@ -78,19 +78,20 @@ const E = [
|
|
|
78
78
|
"tags3"
|
|
79
79
|
], K = ["keyword", "_redirect"];
|
|
80
80
|
async function b(e, t, r) {
|
|
81
|
-
var l,
|
|
81
|
+
var l, n, m, h, k, S, w;
|
|
82
82
|
const o = p("newSearch"), i = e.config.pageType, c = i === "search" ? "serp" : i, a = f(e.store.getInitialState().query, t), s = f(e.config.search, r, {
|
|
83
83
|
track: c,
|
|
84
84
|
redirect: i !== "autocomplete",
|
|
85
85
|
isKeyword: !!(r != null && r.isKeyword),
|
|
86
|
-
usePersistentCache: e.config.pageType !== "autocomplete" && e.config.persistentSearchCache
|
|
86
|
+
usePersistentCache: e.config.pageType !== "autocomplete" && e.config.persistentSearchCache,
|
|
87
|
+
useMemoryCache: e.config.pageType === "autocomplete" && e.config.memoryCache
|
|
87
88
|
});
|
|
88
|
-
(
|
|
89
|
+
(n = (l = e.config).onBeforeSearch) == null || n.call(l, e, s), e.store.updateState({
|
|
89
90
|
query: a,
|
|
90
91
|
loading: !0,
|
|
91
92
|
initialized: !0
|
|
92
93
|
});
|
|
93
|
-
const
|
|
94
|
+
const u = e.config.queryModifications(
|
|
94
95
|
{
|
|
95
96
|
...a,
|
|
96
97
|
products: {
|
|
@@ -102,13 +103,13 @@ async function b(e, t, r) {
|
|
|
102
103
|
i
|
|
103
104
|
);
|
|
104
105
|
try {
|
|
105
|
-
const g = await I(B(e.config.pageType,
|
|
106
|
+
const g = await I(B(e.config.pageType, u), s);
|
|
106
107
|
e.store.updateState({
|
|
107
108
|
response: g,
|
|
108
109
|
loading: !1
|
|
109
110
|
});
|
|
110
111
|
} catch (g) {
|
|
111
|
-
A.error("Search action failed", g), (w = (S = e.config).onSearchError) == null || w.call(S, g,
|
|
112
|
+
A.error("Search action failed", g), (w = (S = e.config).onSearchError) == null || w.call(S, g, u, s, i);
|
|
112
113
|
}
|
|
113
114
|
o();
|
|
114
115
|
}
|
|
@@ -131,17 +132,17 @@ async function N(e, t, r) {
|
|
|
131
132
|
}), o();
|
|
132
133
|
}
|
|
133
134
|
async function O(e, t, r, o) {
|
|
134
|
-
var
|
|
135
|
-
const i = p("toggleProductFilter"), c = (
|
|
135
|
+
var u, l;
|
|
136
|
+
const i = p("toggleProductFilter"), c = (u = e.store.getState().query.products) == null ? void 0 : u.filter, a = c == null ? void 0 : c.find((n) => n.value instanceof Array && n.field === t), s = a != null && a.value ? {
|
|
136
137
|
...a,
|
|
137
|
-
value: [...a.value.filter((
|
|
138
|
+
value: [...a.value.filter((n) => !z(n, r)), ...o ? [r] : []]
|
|
138
139
|
} : o ? {
|
|
139
140
|
field: t,
|
|
140
141
|
value: [r]
|
|
141
142
|
} : void 0;
|
|
142
143
|
await y(e, {
|
|
143
144
|
products: {
|
|
144
|
-
filter: [...(c == null ? void 0 : c.filter((
|
|
145
|
+
filter: [...(c == null ? void 0 : c.filter((n) => n !== a)) ?? [], ...(l = s == null ? void 0 : s.value) != null && l.length ? [s] : []]
|
|
145
146
|
}
|
|
146
147
|
}), i();
|
|
147
148
|
}
|
|
@@ -153,16 +154,16 @@ function j() {
|
|
|
153
154
|
}),
|
|
154
155
|
[e, t]
|
|
155
156
|
), o = d(
|
|
156
|
-
(s,
|
|
157
|
+
(s, u) => b(r, s, u),
|
|
157
158
|
[r]
|
|
158
159
|
), i = d(
|
|
159
|
-
(s,
|
|
160
|
+
(s, u) => y(r, s, u),
|
|
160
161
|
[r]
|
|
161
162
|
), c = d(
|
|
162
|
-
(s,
|
|
163
|
+
(s, u, l) => O(r, s, u, l),
|
|
163
164
|
[r]
|
|
164
165
|
), a = d(
|
|
165
|
-
(s,
|
|
166
|
+
(s, u) => N(r, s, u),
|
|
166
167
|
[r]
|
|
167
168
|
);
|
|
168
169
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -86,11 +86,11 @@
|
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@commitlint/cli": "^19.8.1",
|
|
88
88
|
"@commitlint/config-conventional": "^19.8.1",
|
|
89
|
-
"@nosto/nosto-js": "^2.
|
|
89
|
+
"@nosto/nosto-js": "^2.1.0",
|
|
90
90
|
"@testing-library/dom": "^10.4.0",
|
|
91
91
|
"@types/dom-speech-recognition": "^0.0.6",
|
|
92
92
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
93
|
-
"@types/node": "^22.15.
|
|
93
|
+
"@types/node": "^22.15.21",
|
|
94
94
|
"@vitest/coverage-v8": "^3.1.4",
|
|
95
95
|
"concurrently": "^9.1.2",
|
|
96
96
|
"copyfiles": "^2.4.1",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"isbot": "^5.1.28",
|
|
107
107
|
"jsdom": "^26.1.0",
|
|
108
108
|
"prettier": "^3.5.3",
|
|
109
|
-
"typedoc": "^0.28.
|
|
109
|
+
"typedoc": "^0.28.5",
|
|
110
110
|
"typescript": "^5.8.3",
|
|
111
111
|
"typescript-eslint": "^8.32.1",
|
|
112
112
|
"vite": "^6.3.5",
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ComponentChildren } from 'preact';
|
|
2
|
-
/**
|
|
3
|
-
* @group Components
|
|
4
|
-
*/
|
|
5
|
-
export type AutocompleteElementProps = {
|
|
6
|
-
/**
|
|
7
|
-
* Rendered content.
|
|
8
|
-
*/
|
|
9
|
-
children: ComponentChildren;
|
|
10
|
-
/**
|
|
11
|
-
* Get product data for analytics
|
|
12
|
-
*/
|
|
13
|
-
hit: {
|
|
14
|
-
productId: string;
|
|
15
|
-
url?: string;
|
|
16
|
-
keyword?: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Wraps elements to interactive component that handles selection based on provided configuration.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```jsx
|
|
24
|
-
* // Render product
|
|
25
|
-
* {products?.hits?.map(hit => <AutocompleteElement hit={hit}>
|
|
26
|
-
* <a href={hit.url} class="nosto-product">
|
|
27
|
-
* <img src={hit.imageUrl} alt={hit.name} />
|
|
28
|
-
* <span>{hit.name}</span>
|
|
29
|
-
* <span>{hit.price}</span>
|
|
30
|
-
* </a>
|
|
31
|
-
* </AutocompleteElement>)}
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @group Components
|
|
35
|
-
*/
|
|
36
|
-
export declare function AutocompleteElement({ children, hit }: AutocompleteElementProps): import('preact').VNode<any>;
|
package/dist/search-DapMuqyR.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const b=require("./index.es-DlUp67LT.cjs"),a=require("./logger-BcHMZObS.cjs");async function z(t,{hitDecorators:e,...r},c){var o,i;const n=await c(t,r);if(!((i=(o=n.products)==null?void 0:o.hits)!=null&&i.length)||!(e!=null&&e.length))return n;const s=u=>e.reduce((f,l)=>l(f),u);return{...n,products:{...n.products,hits:n.products.hits.map(s)}}}function N(t,e,r){const c=JSON.stringify(e);try{r.setItem(t,c)}catch(n){a.logger.warn(n)}}function k(t,e){try{const r=e.getItem(t);if(r)return JSON.parse(r)}catch(r){a.logger.warn(r)}}function C(t,e){N(t,e,sessionStorage)}function O(t){return k(t,sessionStorage)}const R="nosto:search-js:cache",T=60*1e3;function E(t,e){C(R,{query:t,result:e,created:Date.now()})}function I(t){const e=O(R);if(!e||!J(e))return null;const r=m(e.query);return!a.isEqual(m(t),r)||Date.now()-e.created>T?null:e.result}function m(t){const e={...t,time:void 0,products:{...t.products,size:void 0}};return JSON.parse(JSON.stringify(e))}function J(t){return typeof t=="object"&&t!==null&&"query"in t&&"result"in t&&"created"in t}async function V(t,{usePersistentCache:e,...r},c){if(!e)return c(t,r);const n=await j(t,r,c);return E(t,n),n}async function j(t,e,r){var p,g,h,S,w,y;const{from:c=0,size:n=0}=t.products||{},s=I(t);if(!s)return await r(t,e);const o=((p=s==null?void 0:s.products)==null?void 0:p.size)??0,i=((g=s==null?void 0:s.products)==null?void 0:g.hits)??[];if(n===o)return s;if(n<o)return{...s,products:{...s.products,size:n,hits:i.slice(0,n),total:((h=s.products)==null?void 0:h.total)||0}};const u=n-i.length,f=c>0?c+1:n-u,l={...t,products:{...t.products,from:f,size:u}},d=await r(l,e);return{...s,products:{...s.products,size:n,hits:[...((S=s.products)==null?void 0:S.hits)||[],...((w=d.products)==null?void 0:w.hits)||[]],total:((y=d.products)==null?void 0:y.total)||0}}}function W(t){return new Promise(e=>setTimeout(e,t))}async function _(t,{maxRetries:e=0,retryInterval:r=0,...c},n){let s=0;for(;;)try{return await n(t,c)}catch(o){if(s>=e)throw o;if(!q(o))throw a.logger.info("Skipping retry logic for",o),o;s++,await W(r)}}function q(t){return!t||typeof t!="object"?!1:!("status"in t)||A(t.status)}function A(t){return typeof t=="number"&&(t<400||t>=500)}async function P(t,e={}){const r=await new Promise(b.s);return x(r.search,_,V,z)(t,e)}function x(t,...e){return e.reduce((r,c)=>(n,s)=>c(n,s,r),t)}exports.search=P;
|
package/dist/search-PYPD19kM.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { s as b } from "./index.es-B8mbAxS4.js";
|
|
2
|
-
import { l, i as z } from "./logger-DVwg4Wor.js";
|
|
3
|
-
async function N(t, { hitDecorators: e, ...r }, o) {
|
|
4
|
-
var c, i;
|
|
5
|
-
const n = await o(t, r);
|
|
6
|
-
if (!((i = (c = n.products) == null ? void 0 : c.hits) != null && i.length) || !(e != null && e.length))
|
|
7
|
-
return n;
|
|
8
|
-
const s = (u) => e.reduce((a, f) => f(a), u);
|
|
9
|
-
return {
|
|
10
|
-
...n,
|
|
11
|
-
products: {
|
|
12
|
-
...n.products,
|
|
13
|
-
hits: n.products.hits.map(s)
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function k(t, e, r) {
|
|
18
|
-
const o = JSON.stringify(e);
|
|
19
|
-
try {
|
|
20
|
-
r.setItem(t, o);
|
|
21
|
-
} catch (n) {
|
|
22
|
-
l.warn(n);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function C(t, e) {
|
|
26
|
-
try {
|
|
27
|
-
const r = e.getItem(t);
|
|
28
|
-
if (r)
|
|
29
|
-
return JSON.parse(r);
|
|
30
|
-
} catch (r) {
|
|
31
|
-
l.warn(r);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function O(t, e) {
|
|
35
|
-
k(t, e, sessionStorage);
|
|
36
|
-
}
|
|
37
|
-
function T(t) {
|
|
38
|
-
return C(t, sessionStorage);
|
|
39
|
-
}
|
|
40
|
-
const R = "nosto:search-js:cache", E = 60 * 1e3;
|
|
41
|
-
function I(t, e) {
|
|
42
|
-
O(R, { query: t, result: e, created: Date.now() });
|
|
43
|
-
}
|
|
44
|
-
function J(t) {
|
|
45
|
-
const e = T(R);
|
|
46
|
-
if (!e || !V(e))
|
|
47
|
-
return null;
|
|
48
|
-
const r = y(e.query);
|
|
49
|
-
return !z(y(t), r) || Date.now() - e.created > E ? null : e.result;
|
|
50
|
-
}
|
|
51
|
-
function y(t) {
|
|
52
|
-
const e = {
|
|
53
|
-
...t,
|
|
54
|
-
time: void 0,
|
|
55
|
-
products: {
|
|
56
|
-
...t.products,
|
|
57
|
-
size: void 0
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
return JSON.parse(JSON.stringify(e));
|
|
61
|
-
}
|
|
62
|
-
function V(t) {
|
|
63
|
-
return typeof t == "object" && t !== null && "query" in t && "result" in t && "created" in t;
|
|
64
|
-
}
|
|
65
|
-
async function j(t, { usePersistentCache: e, ...r }, o) {
|
|
66
|
-
if (!e)
|
|
67
|
-
return o(t, r);
|
|
68
|
-
const n = await W(t, r, o);
|
|
69
|
-
return I(t, n), n;
|
|
70
|
-
}
|
|
71
|
-
async function W(t, e, r) {
|
|
72
|
-
var d, h, g, S, m, w;
|
|
73
|
-
const { from: o = 0, size: n = 0 } = t.products || {}, s = J(t);
|
|
74
|
-
if (!s)
|
|
75
|
-
return await r(t, e);
|
|
76
|
-
const c = ((d = s == null ? void 0 : s.products) == null ? void 0 : d.size) ?? 0, i = ((h = s == null ? void 0 : s.products) == null ? void 0 : h.hits) ?? [];
|
|
77
|
-
if (n === c)
|
|
78
|
-
return s;
|
|
79
|
-
if (n < c)
|
|
80
|
-
return {
|
|
81
|
-
...s,
|
|
82
|
-
products: {
|
|
83
|
-
...s.products,
|
|
84
|
-
size: n,
|
|
85
|
-
hits: i.slice(0, n),
|
|
86
|
-
total: ((g = s.products) == null ? void 0 : g.total) || 0
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const u = n - i.length, a = o > 0 ? o + 1 : n - u, f = {
|
|
90
|
-
...t,
|
|
91
|
-
products: {
|
|
92
|
-
...t.products,
|
|
93
|
-
from: a,
|
|
94
|
-
size: u
|
|
95
|
-
}
|
|
96
|
-
}, p = await r(f, e);
|
|
97
|
-
return {
|
|
98
|
-
...s,
|
|
99
|
-
products: {
|
|
100
|
-
...s.products,
|
|
101
|
-
size: n,
|
|
102
|
-
hits: [...((S = s.products) == null ? void 0 : S.hits) || [], ...((m = p.products) == null ? void 0 : m.hits) || []],
|
|
103
|
-
total: ((w = p.products) == null ? void 0 : w.total) || 0
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function A(t) {
|
|
108
|
-
return new Promise((e) => setTimeout(e, t));
|
|
109
|
-
}
|
|
110
|
-
async function P(t, { maxRetries: e = 0, retryInterval: r = 0, ...o }, n) {
|
|
111
|
-
let s = 0;
|
|
112
|
-
for (; ; )
|
|
113
|
-
try {
|
|
114
|
-
return await n(t, o);
|
|
115
|
-
} catch (c) {
|
|
116
|
-
if (s >= e)
|
|
117
|
-
throw c;
|
|
118
|
-
if (!_(c))
|
|
119
|
-
throw l.info("Skipping retry logic for", c), c;
|
|
120
|
-
s++, await A(r);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
function _(t) {
|
|
124
|
-
return !t || typeof t != "object" ? !1 : !("status" in t) || x(t.status);
|
|
125
|
-
}
|
|
126
|
-
function x(t) {
|
|
127
|
-
return typeof t == "number" && (t < 400 || t >= 500);
|
|
128
|
-
}
|
|
129
|
-
async function K(t, e = {}) {
|
|
130
|
-
const r = await new Promise(b);
|
|
131
|
-
return F(r.search, P, j, N)(t, e);
|
|
132
|
-
}
|
|
133
|
-
function F(t, ...e) {
|
|
134
|
-
return e.reduce((r, o) => (n, s) => o(n, s, r), t);
|
|
135
|
-
}
|
|
136
|
-
export {
|
|
137
|
-
K as s
|
|
138
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const y=require("./configContext-BR7w4VlU.cjs"),n=require("preact/hooks"),M=require("./search-DapMuqyR.cjs"),g=require("./unique-Blp-K9zG.cjs"),h=require("./deepMerge-lDscDfII.cjs"),v=require("./logger-BcHMZObS.cjs");function T(e,t){return{...t,products:{facets:e==="autocomplete"?void 0:["*"],fields:A,...t.products},...t.keywords?{keywords:{...t.keywords,fields:g.unique([...I,...t.keywords.fields??[]]),highlight:t.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const A=["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"],I=["keyword","_redirect"];async function k(e,t,r){var d,l,S,m,C,w,b;const o=g.measure("newSearch"),c=e.config.pageType,u=c==="search"?"serp":c,a=h.deepMerge(e.store.getInitialState().query,t),s=h.deepMerge(e.config.search,r,{track:u,redirect:c!=="autocomplete",isKeyword:!!(r!=null&&r.isKeyword),usePersistentCache:e.config.pageType!=="autocomplete"&&e.config.persistentSearchCache});(l=(d=e.config).onBeforeSearch)==null||l.call(d,e,s),e.store.updateState({query:a,loading:!0,initialized:!0});const i=e.config.queryModifications({...a,products:{...a.products,filter:g.mergeArrays((m=(S=e.store.getInitialState().query)==null?void 0:S.products)==null?void 0:m.filter,(C=t.products)==null?void 0:C.filter)}},c);try{const p=await M.search(T(e.config.pageType,i),s);e.store.updateState({response:p,loading:!1})}catch(p){v.logger.error("Search action failed",p),(b=(w=e.config).onSearchError)==null||b.call(w,p,i,s,c)}o()}async function f(e,t,r){const o=g.measure("updateSearch"),c=h.deepMerge(e.store.getState().query,{products:{from:0}},t);await k(e,c,r),o()}function P(e=Q){const t=n.useContext(y.StoreContext),[r,o]=n.useState(e(t.getState()));return t.onChange(e,o),n.useEffect(()=>()=>t.clearOnChange(o),[t]),r}const Q=e=>e;async function U(e,t,r){var a;const o=g.measure("replaceFilter"),c=(a=e.store.getState().query.products)==null?void 0:a.filter,u=r!==void 0?[{field:t,[typeof r=="object"?"range":"value"]:[r]}]:[];await f(e,{products:{filter:[...(c==null?void 0:c.filter(s=>s.field!==t))??[],...u]}}),o()}async function L(e,t,r,o){var i,d;const c=g.measure("toggleProductFilter"),u=(i=e.store.getState().query.products)==null?void 0:i.filter,a=u==null?void 0:u.find(l=>l.value instanceof Array&&l.field===t),s=a!=null&&a.value?{...a,value:[...a.value.filter(l=>!v.isEqual(l,r)),...o?[r]:[]]}:o?{field:t,value:[r]}:void 0;await f(e,{products:{filter:[...(u==null?void 0:u.filter(l=>l!==a))??[],...(d=s==null?void 0:s.value)!=null&&d.length?[s]:[]]}}),c()}function F(){const e=y.useConfig(),t=n.useContext(y.StoreContext),r=n.useMemo(()=>({config:e,store:t}),[e,t]),o=n.useCallback((s,i)=>k(r,s,i),[r]),c=n.useCallback((s,i)=>f(r,s,i),[r]),u=n.useCallback((s,i,d)=>L(r,s,i,d),[r]),a=n.useCallback((s,i)=>U(r,s,i),[r]);return{newSearch:o,updateSearch:c,toggleProductFilter:u,replaceFilter:a}}function q({from:e,size:t,pageSize:r}){return g.isBot()?{products:{from:e+r}}:{products:{size:t+r}}}function N(e=24){const{from:t,size:r}=P(u=>{var a,s;return{from:((a=u.query.products)==null?void 0:a.from)??0,size:((s=u.query.products)==null?void 0:s.size)??0}}),{updateSearch:o}=F();return{loadMore:n.useCallback(async()=>{await o(q({from:t,size:r,pageSize:e}))},[t,r,e,o])}}exports.getNextPageQuery=q;exports.newSearch=k;exports.updateSearch=f;exports.useActions=F;exports.useLoadMore=N;exports.useNostoAppState=P;
|