@nosto/search-js 2.7.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{InfiniteScrollWithObserver-DHIVa8bY.js → InfiniteScrollWithObserver-Cs-9_P6c.js} +5 -5
- package/dist/{InfiniteScrollWithObserver-D906VaKk.cjs → InfiniteScrollWithObserver-PqDE6YMh.cjs} +1 -1
- package/dist/core/core.cjs.js +1 -1
- package/dist/core/core.es.js +1 -1
- package/dist/core/src/resultCaching.d.ts +1 -3
- 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.d.ts +2 -0
- package/dist/preact/legacy.es.js +7 -5
- package/dist/preact/src/config/base/baseConfig.d.ts +18 -0
- package/dist/preact/src/config/pages/autocomplete/config.d.ts +2 -0
- package/dist/preact/src/config/pages/category/config.d.ts +2 -0
- package/dist/preact/src/config/pages/serp/config.d.ts +2 -0
- package/dist/search-BUagWuec.cjs +1 -0
- package/dist/search-t_zFNrtP.js +136 -0
- package/dist/useLoadMore-B2HNnDWw.js +203 -0
- package/dist/useLoadMore-BqRzn6Z9.cjs +1 -0
- package/package.json +6 -5
- package/dist/search-BgrZ1cY8.js +0 -136
- package/dist/search-Di9DRn5H.cjs +0 -1
- package/dist/useLoadMore-3isftdTM.cjs +0 -1
- package/dist/useLoadMore-4uB1MmI6.js +0 -201
package/dist/{InfiniteScrollWithObserver-DHIVa8bY.js → InfiniteScrollWithObserver-Cs-9_P6c.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { u as f } from "./jsxRuntime.module-Bzuv3cXw.js";
|
|
2
|
-
import {
|
|
2
|
+
import { a, b as l } from "./useLoadMore-B2HNnDWw.js";
|
|
3
3
|
import { p as d } from "./pick-DReBictn.js";
|
|
4
|
-
import { useRef as m, useEffect as
|
|
5
|
-
import { Fragment as
|
|
4
|
+
import { useRef as m, useEffect as b } from "preact/hooks";
|
|
5
|
+
import { Fragment as v } from "preact";
|
|
6
6
|
function w(o, i) {
|
|
7
7
|
var n, e, r;
|
|
8
8
|
const t = ((n = i.products) == null ? void 0 : n.total) ?? 0, c = ((e = o.products) == null ? void 0 : e.from) ?? 0, s = ((r = o.products) == null ? void 0 : r.size) ?? 0;
|
|
@@ -13,7 +13,7 @@ function E() {
|
|
|
13
13
|
}
|
|
14
14
|
function M({ children: o, pageSize: i }) {
|
|
15
15
|
const t = m(null), { query: c, response: s } = a((e) => d(e, "query", "response")), { loadMore: n } = l(i);
|
|
16
|
-
return
|
|
16
|
+
return b(() => {
|
|
17
17
|
let e, r;
|
|
18
18
|
return w(c, s) && (e = t.current, r = new IntersectionObserver((p) => {
|
|
19
19
|
const u = p[0];
|
|
@@ -21,7 +21,7 @@ function M({ children: o, pageSize: i }) {
|
|
|
21
21
|
}), e && r.observe(e)), () => {
|
|
22
22
|
e && r.unobserve(e);
|
|
23
23
|
};
|
|
24
|
-
}, [s]), /* @__PURE__ */ f(
|
|
24
|
+
}, [s]), /* @__PURE__ */ f(v, { children: [
|
|
25
25
|
o,
|
|
26
26
|
/* @__PURE__ */ f("div", { ref: t, style: { height: "1px" } })
|
|
27
27
|
] });
|
package/dist/{InfiniteScrollWithObserver-D906VaKk.cjs → InfiniteScrollWithObserver-PqDE6YMh.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-BqRzn6Z9.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/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-BUagWuec.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-t_zFNrtP.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,11 +1,9 @@
|
|
|
1
1
|
import { SearchQuery, SearchResult } from '@nosto/nosto-js/client';
|
|
2
2
|
export declare const STORAGE_ENTRY_NAME = "nosto:search:searchResult";
|
|
3
3
|
export type SearchResultDto = {
|
|
4
|
-
query:
|
|
4
|
+
query: SearchQuery;
|
|
5
5
|
result: SearchResult;
|
|
6
6
|
};
|
|
7
7
|
export declare function cacheSearchResult(query: SearchQuery, result: SearchResult): void;
|
|
8
8
|
export declare function loadCachedResult(query: SearchQuery): SearchResult | null;
|
|
9
|
-
declare function getCacheKey(query: SearchQuery): SearchQuery;
|
|
10
9
|
export declare function isValueShapeCorrect(value: unknown): value is SearchResultDto;
|
|
11
|
-
export {};
|
|
@@ -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-BqRzn6Z9.cjs"),p=require("../pick-rYi1lc2m.cjs"),n=require("../InfiniteScrollWithObserver-PqDE6YMh.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-CyAMhegX.js";
|
|
2
2
|
import { u as r } from "../jsxRuntime.module-Bzuv3cXw.js";
|
|
3
|
-
import {
|
|
3
|
+
import { b as p, a as m } from "../useLoadMore-B2HNnDWw.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-Cs-9_P6c.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 m=require("../useLoadMore-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../useLoadMore-BqRzn6Z9.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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as F, c as R } from "../useLoadMore-B2HNnDWw.js";
|
|
2
|
+
import { b as Y } from "../useLoadMore-B2HNnDWw.js";
|
|
3
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";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../useLoadMore-BqRzn6Z9.cjs"),r=require("../InfiniteScrollWithObserver-PqDE6YMh.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.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** @module preact/legacy */
|
|
2
|
+
export { newSearch } from './src/actions/newSearch';
|
|
3
|
+
export { updateSearch } from './src/actions/updateSearch';
|
|
2
4
|
export { InfiniteScrollWithObserver } from './src/components/InfiniteScroll/InfiniteScrollWithObserver';
|
|
3
5
|
export { intersectionObserverSupported } from './src/components/InfiniteScroll/utils';
|
|
4
6
|
export { getNextPageQuery } from './src/hooks/useLoadMore/getNextPageQuery';
|
package/dist/preact/legacy.es.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { g as t, n as a, u as s } from "../useLoadMore-B2HNnDWw.js";
|
|
2
|
+
import { I as i, i as n } from "../InfiniteScrollWithObserver-Cs-9_P6c.js";
|
|
3
3
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
i as InfiniteScrollWithObserver,
|
|
5
|
+
t as getNextPageQuery,
|
|
6
|
+
n as intersectionObserverSupported,
|
|
7
|
+
a as newSearch,
|
|
8
|
+
s as updateSearch
|
|
7
9
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SearchOptions } from '../../../../core/src/types';
|
|
2
2
|
import { SearchQuery } from '@nosto/nosto-js/client';
|
|
3
|
+
import { ActionContext } from '../../actions/types';
|
|
3
4
|
import { PageType } from '../../api/types';
|
|
4
5
|
export declare const defaultBaseConfig: {
|
|
5
6
|
defaultCurrency: string;
|
|
@@ -38,4 +39,21 @@ export interface BaseConfig {
|
|
|
38
39
|
* ```
|
|
39
40
|
*/
|
|
40
41
|
queryModifications: (query: SearchQuery, pageType: PageType | undefined) => SearchQuery;
|
|
42
|
+
/**
|
|
43
|
+
* Custom callback invoked before the search query is executed.
|
|
44
|
+
*
|
|
45
|
+
* To cancel the search action, throw an error in this callback.
|
|
46
|
+
*
|
|
47
|
+
* @param context The action context containing the store and config.
|
|
48
|
+
* @param options The search options that would be used for the query.
|
|
49
|
+
*/
|
|
50
|
+
onBeforeSearch?: (context: ActionContext, options: SearchOptions) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Custom error handler for search errors.
|
|
53
|
+
*
|
|
54
|
+
* @param error The error object that occurred during the search operation. This can be of any type.
|
|
55
|
+
* @param query The search query that was being executed when the error occurred.
|
|
56
|
+
* @param options The search options that were used for the query.
|
|
57
|
+
*/
|
|
58
|
+
onSearchError?: (error: unknown, query: SearchQuery, options: SearchOptions, pageType: PageType) => void;
|
|
41
59
|
}
|
|
@@ -9,6 +9,8 @@ export interface AutocompleteConfig extends BaseConfig {
|
|
|
9
9
|
export type PublicAutocompleteConfig = Omit<AutocompleteConfig, keyof typeof defaultAutocompleteConfig | "pageType"> & Partial<Pick<AutocompleteConfig, keyof typeof defaultAutocompleteConfig>>;
|
|
10
10
|
export declare function makeAutocompleteConfig(config: PublicAutocompleteConfig): {
|
|
11
11
|
search?: import('../../../../../core/src/types').SearchOptions | undefined;
|
|
12
|
+
onBeforeSearch?: ((context: import('../../../actions/types').ActionContext, options: import('../../../../../core/src/types').SearchOptions) => void) | undefined;
|
|
13
|
+
onSearchError?: ((error: unknown, query: import('@nosto/nosto-js/client').SearchQuery, options: import('../../../../../core/src/types').SearchOptions, pageType: import('../../../api/types').PageType) => void) | undefined;
|
|
12
14
|
defaultCurrency: string;
|
|
13
15
|
queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
|
|
14
16
|
pageType: "autocomplete";
|
|
@@ -26,6 +26,8 @@ export interface CategoryConfig extends BaseConfig {
|
|
|
26
26
|
export type PublicCategoryConfig = Omit<CategoryConfig, keyof typeof defaultCategoryConfig | "pageType"> & Partial<Pick<CategoryConfig, keyof typeof defaultCategoryConfig>>;
|
|
27
27
|
export declare function makeCategoryConfig(config: PublicCategoryConfig): {
|
|
28
28
|
search?: import('../../../../../core/src/types').SearchOptions | undefined;
|
|
29
|
+
onBeforeSearch?: ((context: import('../../../actions/types').ActionContext, options: import('../../../../../core/src/types').SearchOptions) => void) | undefined;
|
|
30
|
+
onSearchError?: ((error: unknown, query: import('@nosto/nosto-js/client').SearchQuery, options: import('../../../../../core/src/types').SearchOptions, pageType: import('../../../api/types').PageType) => void) | undefined;
|
|
29
31
|
defaultCurrency: string;
|
|
30
32
|
queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
|
|
31
33
|
persistentSearchCache: boolean;
|
|
@@ -26,6 +26,8 @@ export interface SerpConfig extends BaseConfig {
|
|
|
26
26
|
export type PublicSerpConfig = Omit<SerpConfig, keyof typeof defaultSerpConfig | "pageType"> & Partial<Pick<SerpConfig, keyof typeof defaultSerpConfig>>;
|
|
27
27
|
export declare function makeSerpConfig(config?: PublicSerpConfig): {
|
|
28
28
|
search?: import('../../../../../core/src/types').SearchOptions | undefined;
|
|
29
|
+
onBeforeSearch?: ((context: import('../../../actions/types').ActionContext, options: import('../../../../../core/src/types').SearchOptions) => void) | undefined;
|
|
30
|
+
onSearchError?: ((error: unknown, query: import('@nosto/nosto-js/client').SearchQuery, options: import('../../../../../core/src/types').SearchOptions, pageType: import('../../../api/types').PageType) => void) | undefined;
|
|
29
31
|
defaultCurrency: string;
|
|
30
32
|
queryModifications: (query: import('@nosto/nosto-js/client').SearchQuery, pageType: import('../../../api/types').PageType | undefined) => import('@nosto/nosto-js/client').SearchQuery;
|
|
31
33
|
persistentSearchCache: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const m=require("./index.es-DlUp67LT.cjs"),a=require("./logger-BcHMZObS.cjs");async function R(t,{hitDecorators:e,...r},o){var c,i;const n=await o(t,r);if(!((i=(c=n.products)==null?void 0:c.hits)!=null&&i.length)||!(e!=null&&e.length))return n;const s=l=>e.reduce((f,u)=>u(f),l);return{...n,products:{...n.products,hits:n.products.hits.map(s)}}}function b(t,e,r){const o=JSON.stringify(e);try{r.setItem(t,o)}catch(n){a.logger.warn(n)}}function N(t,e){try{const r=e.getItem(t);if(r)return JSON.parse(r)}catch(r){a.logger.warn(r)}}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 r=w(e.query);return a.isEqual(w(t),r)?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,...r},o){if(!e)return o(t,r);const n=await J(t,r,o);return O(t,n),n}async function J(t,e,r){var d,p,g,h,S;const{from:o=0,size:n=0}=t.products||{},s=z(t);if(!s)return await r(t,e);const c=((d=s==null?void 0:s.products)==null?void 0:d.hits)||[];if(n===c.length)return s;if(n<c.length)return{...s,products:{...s.products,hits:c.slice(0,n),total:((p=s.products)==null?void 0:p.total)||0}};const i=n-c.length,l=o>0?o+1:n-i,f={...t,products:{...t.products,from:l,size:i}},u=await r(f,e);return{...s,products:{...s.products,hits:[...((g=s.products)==null?void 0:g.hits)||[],...((h=u.products)==null?void 0:h.hits)||[]],total:((S=u.products)==null?void 0:S.total)||0}}}function V(t){return new Promise(e=>setTimeout(e,t))}async function T(t,{maxRetries:e=0,retryInterval:r=0,...o},n){let s=0;for(;;)try{return await n(t,o)}catch(c){if(s>=e)throw c;if(!W(c))throw a.logger.info("Skipping retry logic for",c),c;s++,await V(r)}}function W(t){return!t||typeof t!="object"?!1:!("status"in t)||_(t.status)}function _(t){return typeof t=="number"&&(t<400||t>=500)}async function j(t,e={}){const r=await new Promise(m.s);return q(r.search,T,I,R)(t,e)}function q(t,...e){return e.reduce((r,o)=>(n,s)=>o(n,s,r),t)}exports.search=j;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { s as y } from "./index.es-B8mbAxS4.js";
|
|
2
|
+
import { l, i as R } from "./logger-DVwg4Wor.js";
|
|
3
|
+
async function b(t, { hitDecorators: r, ...n }, o) {
|
|
4
|
+
var c, i;
|
|
5
|
+
const e = await o(t, n);
|
|
6
|
+
if (!((i = (c = e.products) == null ? void 0 : c.hits) != null && i.length) || !(r != null && r.length))
|
|
7
|
+
return e;
|
|
8
|
+
const s = (a) => r.reduce((f, u) => u(f), a);
|
|
9
|
+
return {
|
|
10
|
+
...e,
|
|
11
|
+
products: {
|
|
12
|
+
...e.products,
|
|
13
|
+
hits: e.products.hits.map(s)
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function N(t, r, n) {
|
|
18
|
+
const o = JSON.stringify(r);
|
|
19
|
+
try {
|
|
20
|
+
n.setItem(t, o);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
l.warn(e);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function k(t, r) {
|
|
26
|
+
try {
|
|
27
|
+
const n = r.getItem(t);
|
|
28
|
+
if (n)
|
|
29
|
+
return JSON.parse(n);
|
|
30
|
+
} catch (n) {
|
|
31
|
+
l.warn(n);
|
|
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 n = m(r.query);
|
|
49
|
+
return R(m(t), n) ? r.result : null;
|
|
50
|
+
}
|
|
51
|
+
function m(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, ...n }, o) {
|
|
66
|
+
if (!r)
|
|
67
|
+
return o(t, n);
|
|
68
|
+
const e = await V(t, n, o);
|
|
69
|
+
return z(t, e), e;
|
|
70
|
+
}
|
|
71
|
+
async function V(t, r, n) {
|
|
72
|
+
var p, d, h, g, S;
|
|
73
|
+
const { from: o = 0, size: e = 0 } = t.products || {}, s = E(t);
|
|
74
|
+
if (!s)
|
|
75
|
+
return await n(t, r);
|
|
76
|
+
const c = ((p = s == null ? void 0 : s.products) == null ? void 0 : p.hits) || [];
|
|
77
|
+
if (e === c.length)
|
|
78
|
+
return s;
|
|
79
|
+
if (e < c.length)
|
|
80
|
+
return {
|
|
81
|
+
...s,
|
|
82
|
+
products: {
|
|
83
|
+
...s.products,
|
|
84
|
+
hits: c.slice(0, e),
|
|
85
|
+
total: ((d = s.products) == null ? void 0 : d.total) || 0
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const i = e - c.length, a = o > 0 ? o + 1 : e - i, f = {
|
|
89
|
+
...t,
|
|
90
|
+
products: {
|
|
91
|
+
...t.products,
|
|
92
|
+
from: a,
|
|
93
|
+
size: i
|
|
94
|
+
}
|
|
95
|
+
}, u = await n(f, r);
|
|
96
|
+
return {
|
|
97
|
+
...s,
|
|
98
|
+
products: {
|
|
99
|
+
...s.products,
|
|
100
|
+
hits: [...((h = s.products) == null ? void 0 : h.hits) || [], ...((g = u.products) == null ? void 0 : g.hits) || []],
|
|
101
|
+
total: ((S = u.products) == null ? void 0 : S.total) || 0
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function T(t) {
|
|
106
|
+
return new Promise((r) => setTimeout(r, t));
|
|
107
|
+
}
|
|
108
|
+
async function W(t, { maxRetries: r = 0, retryInterval: n = 0, ...o }, e) {
|
|
109
|
+
let s = 0;
|
|
110
|
+
for (; ; )
|
|
111
|
+
try {
|
|
112
|
+
return await e(t, o);
|
|
113
|
+
} catch (c) {
|
|
114
|
+
if (s >= r)
|
|
115
|
+
throw c;
|
|
116
|
+
if (!j(c))
|
|
117
|
+
throw l.info("Skipping retry logic for", c), c;
|
|
118
|
+
s++, await T(n);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function j(t) {
|
|
122
|
+
return !t || typeof t != "object" ? !1 : !("status" in t) || A(t.status);
|
|
123
|
+
}
|
|
124
|
+
function A(t) {
|
|
125
|
+
return typeof t == "number" && (t < 400 || t >= 500);
|
|
126
|
+
}
|
|
127
|
+
async function F(t, r = {}) {
|
|
128
|
+
const n = await new Promise(y);
|
|
129
|
+
return P(n.search, W, J, b)(t, r);
|
|
130
|
+
}
|
|
131
|
+
function P(t, ...r) {
|
|
132
|
+
return r.reduce((n, o) => (e, s) => o(e, s, n), t);
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
F as s
|
|
136
|
+
};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { S as C, u as F } from "./configContext-GuZOIX3o.js";
|
|
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-t_zFNrtP.js";
|
|
4
|
+
import { u as q, a as p, m as Q, i as U } from "./unique-CyAMhegX.js";
|
|
5
|
+
import { d as f } from "./deepMerge-CZwCJzEe.js";
|
|
6
|
+
import { l as A, i as z } from "./logger-DVwg4Wor.js";
|
|
7
|
+
function B(e, t) {
|
|
8
|
+
return {
|
|
9
|
+
...t,
|
|
10
|
+
products: {
|
|
11
|
+
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
12
|
+
fields: E,
|
|
13
|
+
...t.products
|
|
14
|
+
},
|
|
15
|
+
...t.keywords ? {
|
|
16
|
+
keywords: {
|
|
17
|
+
...t.keywords,
|
|
18
|
+
fields: q([...K, ...t.keywords.fields ?? []]),
|
|
19
|
+
highlight: t.keywords.highlight ?? {
|
|
20
|
+
preTag: "<strong>",
|
|
21
|
+
postTag: "</strong>"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} : {}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const E = [
|
|
28
|
+
"productId",
|
|
29
|
+
"url",
|
|
30
|
+
"name",
|
|
31
|
+
"imageUrl",
|
|
32
|
+
"imageHash",
|
|
33
|
+
"thumbUrl",
|
|
34
|
+
"description",
|
|
35
|
+
"brand",
|
|
36
|
+
"variantId",
|
|
37
|
+
"availability",
|
|
38
|
+
"price",
|
|
39
|
+
"priceText",
|
|
40
|
+
"categoryIds",
|
|
41
|
+
"categories",
|
|
42
|
+
"customFields.key",
|
|
43
|
+
"customFields.value",
|
|
44
|
+
"priceCurrencyCode",
|
|
45
|
+
"datePublished",
|
|
46
|
+
"listPrice",
|
|
47
|
+
"unitPricingBaseMeasure",
|
|
48
|
+
"unitPricingUnit",
|
|
49
|
+
"unitPricingMeasure",
|
|
50
|
+
"googleCategory",
|
|
51
|
+
"gtin",
|
|
52
|
+
"ageGroup",
|
|
53
|
+
"gender",
|
|
54
|
+
"condition",
|
|
55
|
+
"alternateImageUrls",
|
|
56
|
+
"ratingValue",
|
|
57
|
+
"reviewCount",
|
|
58
|
+
"inventoryLevel",
|
|
59
|
+
"skus.id",
|
|
60
|
+
"skus.name",
|
|
61
|
+
"skus.price",
|
|
62
|
+
"skus.listPrice",
|
|
63
|
+
"skus.priceText",
|
|
64
|
+
"skus.url",
|
|
65
|
+
"skus.imageUrl",
|
|
66
|
+
"skus.inventoryLevel",
|
|
67
|
+
"skus.customFields.key",
|
|
68
|
+
"skus.customFields.value",
|
|
69
|
+
"skus.availability",
|
|
70
|
+
"pid",
|
|
71
|
+
"onDiscount",
|
|
72
|
+
"extra.key",
|
|
73
|
+
"extra.value",
|
|
74
|
+
"saleable",
|
|
75
|
+
"available",
|
|
76
|
+
"tags1",
|
|
77
|
+
"tags2",
|
|
78
|
+
"tags3"
|
|
79
|
+
], K = ["keyword", "_redirect"];
|
|
80
|
+
async function b(e, t, r) {
|
|
81
|
+
var l, u, m, h, k, S, w;
|
|
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
|
+
track: c,
|
|
84
|
+
redirect: i !== "autocomplete",
|
|
85
|
+
isKeyword: !!(r != null && r.isKeyword),
|
|
86
|
+
usePersistentCache: e.config.pageType !== "autocomplete" && e.config.persistentSearchCache
|
|
87
|
+
});
|
|
88
|
+
(u = (l = e.config).onBeforeSearch) == null || u.call(l, e, s), e.store.updateState({
|
|
89
|
+
query: a,
|
|
90
|
+
loading: !0,
|
|
91
|
+
initialized: !0
|
|
92
|
+
});
|
|
93
|
+
const n = e.config.queryModifications(
|
|
94
|
+
{
|
|
95
|
+
...a,
|
|
96
|
+
products: {
|
|
97
|
+
...a.products,
|
|
98
|
+
// Apply filter merging to avoid overwriting base filters
|
|
99
|
+
filter: Q((h = (m = e.store.getInitialState().query) == null ? void 0 : m.products) == null ? void 0 : h.filter, (k = t.products) == null ? void 0 : k.filter)
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
i
|
|
103
|
+
);
|
|
104
|
+
try {
|
|
105
|
+
const g = await I(B(e.config.pageType, n), s);
|
|
106
|
+
e.store.updateState({
|
|
107
|
+
response: g,
|
|
108
|
+
loading: !1
|
|
109
|
+
});
|
|
110
|
+
} catch (g) {
|
|
111
|
+
A.error("Search action failed", g), (w = (S = e.config).onSearchError) == null || w.call(S, g, n, s, i);
|
|
112
|
+
}
|
|
113
|
+
o();
|
|
114
|
+
}
|
|
115
|
+
async function y(e, t, r) {
|
|
116
|
+
const o = p("updateSearch"), i = f(e.store.getState().query, { products: { from: 0 } }, t);
|
|
117
|
+
await b(e, i, r), o();
|
|
118
|
+
}
|
|
119
|
+
function L(e = D) {
|
|
120
|
+
const t = v(C), [r, o] = P(e(t.getState()));
|
|
121
|
+
return t.onChange(e, o), M(() => () => t.clearOnChange(o), [t]), r;
|
|
122
|
+
}
|
|
123
|
+
const D = (e) => e;
|
|
124
|
+
async function N(e, t, r) {
|
|
125
|
+
var a;
|
|
126
|
+
const o = p("replaceFilter"), i = (a = e.store.getState().query.products) == null ? void 0 : a.filter, c = r !== void 0 ? [{ field: t, [typeof r == "object" ? "range" : "value"]: [r] }] : [];
|
|
127
|
+
await y(e, {
|
|
128
|
+
products: {
|
|
129
|
+
filter: [...(i == null ? void 0 : i.filter((s) => s.field !== t)) ?? [], ...c]
|
|
130
|
+
}
|
|
131
|
+
}), o();
|
|
132
|
+
}
|
|
133
|
+
async function O(e, t, r, o) {
|
|
134
|
+
var n, l;
|
|
135
|
+
const i = p("toggleProductFilter"), c = (n = e.store.getState().query.products) == null ? void 0 : n.filter, a = c == null ? void 0 : c.find((u) => u.value instanceof Array && u.field === t), s = a != null && a.value ? {
|
|
136
|
+
...a,
|
|
137
|
+
value: [...a.value.filter((u) => !z(u, r)), ...o ? [r] : []]
|
|
138
|
+
} : o ? {
|
|
139
|
+
field: t,
|
|
140
|
+
value: [r]
|
|
141
|
+
} : void 0;
|
|
142
|
+
await y(e, {
|
|
143
|
+
products: {
|
|
144
|
+
filter: [...(c == null ? void 0 : c.filter((u) => u !== a)) ?? [], ...(l = s == null ? void 0 : s.value) != null && l.length ? [s] : []]
|
|
145
|
+
}
|
|
146
|
+
}), i();
|
|
147
|
+
}
|
|
148
|
+
function j() {
|
|
149
|
+
const e = F(), t = v(C), r = T(
|
|
150
|
+
() => ({
|
|
151
|
+
config: e,
|
|
152
|
+
store: t
|
|
153
|
+
}),
|
|
154
|
+
[e, t]
|
|
155
|
+
), o = d(
|
|
156
|
+
(s, n) => b(r, s, n),
|
|
157
|
+
[r]
|
|
158
|
+
), i = d(
|
|
159
|
+
(s, n) => y(r, s, n),
|
|
160
|
+
[r]
|
|
161
|
+
), c = d(
|
|
162
|
+
(s, n, l) => O(r, s, n, l),
|
|
163
|
+
[r]
|
|
164
|
+
), a = d(
|
|
165
|
+
(s, n) => N(r, s, n),
|
|
166
|
+
[r]
|
|
167
|
+
);
|
|
168
|
+
return {
|
|
169
|
+
newSearch: o,
|
|
170
|
+
updateSearch: i,
|
|
171
|
+
toggleProductFilter: c,
|
|
172
|
+
replaceFilter: a
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function G({ from: e, size: t, pageSize: r }) {
|
|
176
|
+
return U() ? {
|
|
177
|
+
products: { from: e + r }
|
|
178
|
+
} : {
|
|
179
|
+
products: { size: t + r }
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function X(e = 24) {
|
|
183
|
+
const { from: t, size: r } = L((c) => {
|
|
184
|
+
var a, s;
|
|
185
|
+
return {
|
|
186
|
+
from: ((a = c.query.products) == null ? void 0 : a.from) ?? 0,
|
|
187
|
+
size: ((s = c.query.products) == null ? void 0 : s.size) ?? 0
|
|
188
|
+
};
|
|
189
|
+
}), { updateSearch: o } = j();
|
|
190
|
+
return {
|
|
191
|
+
loadMore: d(async () => {
|
|
192
|
+
await o(G({ from: t, size: r, pageSize: e }));
|
|
193
|
+
}, [t, r, e, o])
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export {
|
|
197
|
+
L as a,
|
|
198
|
+
X as b,
|
|
199
|
+
j as c,
|
|
200
|
+
G as g,
|
|
201
|
+
b as n,
|
|
202
|
+
y as u
|
|
203
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const y=require("./configContext-BR7w4VlU.cjs"),n=require("preact/hooks"),M=require("./search-BUagWuec.cjs"),g=require("./unique-BCAEb4ek.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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"dev:library": "vite build --watch",
|
|
77
77
|
"dev:preact": "cd dev/preact && npm run dev",
|
|
78
78
|
"typedoc": "typedoc --treatWarningsAsErrors",
|
|
79
|
-
"test": "vitest --run && (cd dev/preact && npm run test)",
|
|
79
|
+
"test": "vitest --run --coverage && (cd dev/preact && npm run test)",
|
|
80
80
|
"test:watch": "vitest",
|
|
81
81
|
"lint": "eslint",
|
|
82
82
|
"lint-fix": "eslint --fix",
|
|
@@ -84,10 +84,13 @@
|
|
|
84
84
|
"prepare": "husky"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
+
"@commitlint/cli": "^19.8.0",
|
|
88
|
+
"@commitlint/config-conventional": "^19.8.0",
|
|
87
89
|
"@nosto/nosto-js": "^2.0.0",
|
|
88
90
|
"@testing-library/dom": "^10.4.0",
|
|
89
91
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
90
92
|
"@types/node": "^22.15.3",
|
|
93
|
+
"@vitest/coverage-v8": "^3.1.3",
|
|
91
94
|
"concurrently": "^9.1.2",
|
|
92
95
|
"copyfiles": "^2.4.1",
|
|
93
96
|
"eslint": "^9.26.0",
|
|
@@ -107,9 +110,7 @@
|
|
|
107
110
|
"typescript-eslint": "^8.31.1",
|
|
108
111
|
"vite": "^6.3.5",
|
|
109
112
|
"vite-plugin-dts": "^4.5.3",
|
|
110
|
-
"vitest": "^3.1.3"
|
|
111
|
-
"@commitlint/cli": "^19.8.0",
|
|
112
|
-
"@commitlint/config-conventional": "^19.8.0"
|
|
113
|
+
"vitest": "^3.1.3"
|
|
113
114
|
},
|
|
114
115
|
"publishConfig": {
|
|
115
116
|
"access": "public"
|
package/dist/search-BgrZ1cY8.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/search-Di9DRn5H.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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;
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { S as h, u as w } from "./configContext-GuZOIX3o.js";
|
|
2
|
-
import { useContext as k, useState as C, useEffect as v, useMemo as b, useCallback as d } from "preact/hooks";
|
|
3
|
-
import { s as F } from "./search-BgrZ1cY8.js";
|
|
4
|
-
import { u as P, a as g, m as M, i as T } from "./unique-CyAMhegX.js";
|
|
5
|
-
import { d as f } from "./deepMerge-CZwCJzEe.js";
|
|
6
|
-
import { l as I, i as q } from "./logger-DVwg4Wor.js";
|
|
7
|
-
function Q(e = U) {
|
|
8
|
-
const r = k(h), [t, o] = C(e(r.getState()));
|
|
9
|
-
return r.onChange(e, o), v(() => () => r.clearOnChange(o), [r]), t;
|
|
10
|
-
}
|
|
11
|
-
const U = (e) => e;
|
|
12
|
-
function A(e, r) {
|
|
13
|
-
return {
|
|
14
|
-
...r,
|
|
15
|
-
products: {
|
|
16
|
-
facets: e === "autocomplete" ? void 0 : ["*"],
|
|
17
|
-
fields: z,
|
|
18
|
-
...r.products
|
|
19
|
-
},
|
|
20
|
-
...r.keywords ? {
|
|
21
|
-
keywords: {
|
|
22
|
-
...r.keywords,
|
|
23
|
-
fields: P([...K, ...r.keywords.fields ?? []]),
|
|
24
|
-
highlight: r.keywords.highlight ?? {
|
|
25
|
-
preTag: "<strong>",
|
|
26
|
-
postTag: "</strong>"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
} : {}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const z = [
|
|
33
|
-
"productId",
|
|
34
|
-
"url",
|
|
35
|
-
"name",
|
|
36
|
-
"imageUrl",
|
|
37
|
-
"imageHash",
|
|
38
|
-
"thumbUrl",
|
|
39
|
-
"description",
|
|
40
|
-
"brand",
|
|
41
|
-
"variantId",
|
|
42
|
-
"availability",
|
|
43
|
-
"price",
|
|
44
|
-
"priceText",
|
|
45
|
-
"categoryIds",
|
|
46
|
-
"categories",
|
|
47
|
-
"customFields.key",
|
|
48
|
-
"customFields.value",
|
|
49
|
-
"priceCurrencyCode",
|
|
50
|
-
"datePublished",
|
|
51
|
-
"listPrice",
|
|
52
|
-
"unitPricingBaseMeasure",
|
|
53
|
-
"unitPricingUnit",
|
|
54
|
-
"unitPricingMeasure",
|
|
55
|
-
"googleCategory",
|
|
56
|
-
"gtin",
|
|
57
|
-
"ageGroup",
|
|
58
|
-
"gender",
|
|
59
|
-
"condition",
|
|
60
|
-
"alternateImageUrls",
|
|
61
|
-
"ratingValue",
|
|
62
|
-
"reviewCount",
|
|
63
|
-
"inventoryLevel",
|
|
64
|
-
"skus.id",
|
|
65
|
-
"skus.name",
|
|
66
|
-
"skus.price",
|
|
67
|
-
"skus.listPrice",
|
|
68
|
-
"skus.priceText",
|
|
69
|
-
"skus.url",
|
|
70
|
-
"skus.imageUrl",
|
|
71
|
-
"skus.inventoryLevel",
|
|
72
|
-
"skus.customFields.key",
|
|
73
|
-
"skus.customFields.value",
|
|
74
|
-
"skus.availability",
|
|
75
|
-
"pid",
|
|
76
|
-
"onDiscount",
|
|
77
|
-
"extra.key",
|
|
78
|
-
"extra.value",
|
|
79
|
-
"saleable",
|
|
80
|
-
"available",
|
|
81
|
-
"tags1",
|
|
82
|
-
"tags2",
|
|
83
|
-
"tags3"
|
|
84
|
-
], K = ["keyword", "_redirect"];
|
|
85
|
-
async function S(e, r, t) {
|
|
86
|
-
var l, n, m;
|
|
87
|
-
const o = g("newSearch"), i = e.config.pageType, c = i === "search" ? "serp" : i, a = f(e.store.getInitialState().query, r), s = f(e.config.search, t, {
|
|
88
|
-
track: c,
|
|
89
|
-
redirect: i !== "autocomplete",
|
|
90
|
-
isKeyword: !!(t != null && t.isKeyword),
|
|
91
|
-
usePersistentCache: e.config.pageType !== "autocomplete" && e.config.persistentSearchCache
|
|
92
|
-
});
|
|
93
|
-
e.store.updateState({
|
|
94
|
-
query: a,
|
|
95
|
-
loading: !0,
|
|
96
|
-
initialized: !0
|
|
97
|
-
});
|
|
98
|
-
const u = e.config.queryModifications(
|
|
99
|
-
{
|
|
100
|
-
...a,
|
|
101
|
-
products: {
|
|
102
|
-
...a.products,
|
|
103
|
-
// Apply filter merging to avoid overwriting base filters
|
|
104
|
-
filter: M((n = (l = e.store.getInitialState().query) == null ? void 0 : l.products) == null ? void 0 : n.filter, (m = r.products) == null ? void 0 : m.filter)
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
i
|
|
108
|
-
);
|
|
109
|
-
try {
|
|
110
|
-
const p = await F(A(e.config.pageType, u), s);
|
|
111
|
-
e.store.updateState({
|
|
112
|
-
response: p,
|
|
113
|
-
loading: !1
|
|
114
|
-
});
|
|
115
|
-
} catch (p) {
|
|
116
|
-
I.error("Search action failed", p);
|
|
117
|
-
}
|
|
118
|
-
o();
|
|
119
|
-
}
|
|
120
|
-
async function y(e, r, t) {
|
|
121
|
-
const o = g("updateSearch"), i = f(e.store.getState().query, { products: { from: 0 } }, r);
|
|
122
|
-
await S(e, i, t), o();
|
|
123
|
-
}
|
|
124
|
-
async function L(e, r, t) {
|
|
125
|
-
var a;
|
|
126
|
-
const o = g("replaceFilter"), i = (a = e.store.getState().query.products) == null ? void 0 : a.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
|
|
127
|
-
await y(e, {
|
|
128
|
-
products: {
|
|
129
|
-
filter: [...(i == null ? void 0 : i.filter((s) => s.field !== r)) ?? [], ...c]
|
|
130
|
-
}
|
|
131
|
-
}), o();
|
|
132
|
-
}
|
|
133
|
-
async function B(e, r, t, o) {
|
|
134
|
-
var u, l;
|
|
135
|
-
const i = g("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 === r), s = a != null && a.value ? {
|
|
136
|
-
...a,
|
|
137
|
-
value: [...a.value.filter((n) => !q(n, t)), ...o ? [t] : []]
|
|
138
|
-
} : o ? {
|
|
139
|
-
field: r,
|
|
140
|
-
value: [t]
|
|
141
|
-
} : void 0;
|
|
142
|
-
await y(e, {
|
|
143
|
-
products: {
|
|
144
|
-
filter: [...(c == null ? void 0 : c.filter((n) => n !== a)) ?? [], ...(l = s == null ? void 0 : s.value) != null && l.length ? [s] : []]
|
|
145
|
-
}
|
|
146
|
-
}), i();
|
|
147
|
-
}
|
|
148
|
-
function D() {
|
|
149
|
-
const e = w(), r = k(h), t = b(
|
|
150
|
-
() => ({
|
|
151
|
-
config: e,
|
|
152
|
-
store: r
|
|
153
|
-
}),
|
|
154
|
-
[e, r]
|
|
155
|
-
), o = d(
|
|
156
|
-
(s, u) => S(t, s, u),
|
|
157
|
-
[t]
|
|
158
|
-
), i = d(
|
|
159
|
-
(s, u) => y(t, s, u),
|
|
160
|
-
[t]
|
|
161
|
-
), c = d(
|
|
162
|
-
(s, u, l) => B(t, s, u, l),
|
|
163
|
-
[t]
|
|
164
|
-
), a = d(
|
|
165
|
-
(s, u) => L(t, s, u),
|
|
166
|
-
[t]
|
|
167
|
-
);
|
|
168
|
-
return {
|
|
169
|
-
newSearch: o,
|
|
170
|
-
updateSearch: i,
|
|
171
|
-
toggleProductFilter: c,
|
|
172
|
-
replaceFilter: a
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function E({ from: e, size: r, pageSize: t }) {
|
|
176
|
-
return T() ? {
|
|
177
|
-
products: { from: e + t }
|
|
178
|
-
} : {
|
|
179
|
-
products: { size: r + t }
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function _(e = 24) {
|
|
183
|
-
const { from: r, size: t } = Q((c) => {
|
|
184
|
-
var a, s;
|
|
185
|
-
return {
|
|
186
|
-
from: ((a = c.query.products) == null ? void 0 : a.from) ?? 0,
|
|
187
|
-
size: ((s = c.query.products) == null ? void 0 : s.size) ?? 0
|
|
188
|
-
};
|
|
189
|
-
}), { updateSearch: o } = D();
|
|
190
|
-
return {
|
|
191
|
-
loadMore: d(async () => {
|
|
192
|
-
await o(E({ from: r, size: t, pageSize: e }));
|
|
193
|
-
}, [r, t, e, o])
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
export {
|
|
197
|
-
_ as a,
|
|
198
|
-
D as b,
|
|
199
|
-
E as g,
|
|
200
|
-
Q as u
|
|
201
|
-
};
|