@nosto/search-js 3.22.0 → 3.23.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/{AutocompletePageProvider-Xg9H1y3f.cjs → AutocompletePageProvider-CFcim_G9.cjs} +1 -1
- package/dist/{AutocompletePageProvider-DsUoIbbx.js → AutocompletePageProvider-CJb7OEAr.js} +3 -3
- package/dist/{CategoryPageProvider-DU3DjmnJ.js → CategoryPageProvider-BGqhQtdT.js} +2 -2
- package/dist/{CategoryPageProvider-2ZmajAxh.cjs → CategoryPageProvider-C2nqTdZ8.cjs} +1 -1
- package/dist/{InfiniteScrollWithObserver-B0iiezKy.js → InfiniteScrollWithObserver-CtEBs3Ts.js} +1 -1
- package/dist/{InfiniteScrollWithObserver-LxLj-_bT.cjs → InfiniteScrollWithObserver-DAtCSz5E.cjs} +1 -1
- package/dist/{SerpPageProvider-Dn6PSZoF.cjs → SerpPageProvider-D5cD0ttm.cjs} +1 -1
- package/dist/{SerpPageProvider-DshgTNpM.js → SerpPageProvider-wkZs_QWn.js} +2 -2
- package/dist/{baseConfig-DeHr2N1l.js → baseConfig-BU6c9mCI.js} +1 -1
- package/dist/{baseConfig-CaRa_-zN.cjs → baseConfig-DDoRk8Lk.cjs} +1 -1
- package/dist/core/core.cjs.js +1 -1
- package/dist/core/core.es.js +1 -1
- package/dist/core/src/withRedirects.d.ts +3 -0
- package/dist/preact/autocomplete/autocomplete.cjs.js +1 -1
- package/dist/preact/autocomplete/autocomplete.es.js +1 -1
- package/dist/preact/autocomplete/src/components/AutocompleteElement.d.ts +2 -2
- package/dist/preact/autocomplete/src/types.d.ts +5 -7
- package/dist/preact/category/category.cjs.js +1 -1
- package/dist/preact/category/category.es.js +1 -1
- package/dist/preact/common/common.cjs.js +1 -1
- package/dist/preact/common/common.es.js +3 -3
- package/dist/preact/hooks/hooks.cjs.js +1 -1
- package/dist/preact/hooks/hooks.es.js +101 -100
- package/dist/preact/inject/inject.cjs.js +1 -1
- package/dist/preact/inject/inject.es.js +5 -5
- package/dist/preact/legacy/legacy.cjs.js +1 -1
- package/dist/preact/legacy/legacy.es.js +3 -3
- package/dist/preact/serp/serp.cjs.js +1 -1
- package/dist/preact/serp/serp.es.js +2 -2
- package/dist/search-DItu5YCc.cjs +1 -0
- package/dist/search-xLgL6P5R.js +187 -0
- package/dist/{useActions-CY9uts_o.cjs → useActions-B6FFW8xI.cjs} +1 -1
- package/dist/{useActions-CSNwQtT1.js → useActions-DoZCMPfW.js} +1 -1
- package/dist/{useHistory-joVBx1r2.js → useHistory-BJo9WE5S.js} +2 -2
- package/dist/{useHistory-rc2PvSkv.cjs → useHistory-D_TgfzXK.cjs} +1 -1
- package/dist/{useLoadMore-2OmOqicJ.js → useLoadMore-CdqyUIQQ.js} +1 -1
- package/dist/{useLoadMore-CBshMpps.cjs → useLoadMore-DYxXgyV2.cjs} +1 -1
- package/package.json +6 -6
- package/dist/search-RNs4Cunh.cjs +0 -1
- package/dist/search-mArZ2PXy.js +0 -170
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { s as y } from "./index.es-XNBESE3P.js";
|
|
2
|
+
import { l as f, i as h } from "./logger-_fg_Za9y.js";
|
|
3
|
+
async function C(t, { hitDecorators: e, ...r }, c) {
|
|
4
|
+
const n = await c(t, r);
|
|
5
|
+
if (!n.products?.hits?.length || !e?.length)
|
|
6
|
+
return n;
|
|
7
|
+
const s = (o) => e.reduce((i, a) => a(i), o);
|
|
8
|
+
return {
|
|
9
|
+
...n,
|
|
10
|
+
products: {
|
|
11
|
+
...n.products,
|
|
12
|
+
hits: n.products.hits.map(s)
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function p(t, e, r) {
|
|
17
|
+
const c = JSON.stringify(e);
|
|
18
|
+
try {
|
|
19
|
+
r.setItem(t, c);
|
|
20
|
+
} catch (n) {
|
|
21
|
+
f.warn(n);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function g(t, e) {
|
|
25
|
+
try {
|
|
26
|
+
const r = e.getItem(t);
|
|
27
|
+
if (r)
|
|
28
|
+
return JSON.parse(r);
|
|
29
|
+
} catch (r) {
|
|
30
|
+
f.warn(r);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function P(t, e) {
|
|
34
|
+
p(t, e, localStorage);
|
|
35
|
+
}
|
|
36
|
+
function R(t, e) {
|
|
37
|
+
p(t, e, sessionStorage);
|
|
38
|
+
}
|
|
39
|
+
function G(t) {
|
|
40
|
+
return g(t, localStorage);
|
|
41
|
+
}
|
|
42
|
+
function I(t) {
|
|
43
|
+
return g(t, sessionStorage);
|
|
44
|
+
}
|
|
45
|
+
const m = "nosto:search-js:cache", b = 60 * 1e3;
|
|
46
|
+
function k(t, e) {
|
|
47
|
+
R(m, { query: t, result: e, created: Date.now() });
|
|
48
|
+
}
|
|
49
|
+
function N(t) {
|
|
50
|
+
const e = I(m);
|
|
51
|
+
if (!e || !T(e))
|
|
52
|
+
return null;
|
|
53
|
+
const r = d(e.query);
|
|
54
|
+
return !h(d(t), r) || Date.now() - e.created > b ? null : e.result;
|
|
55
|
+
}
|
|
56
|
+
function d(t) {
|
|
57
|
+
const e = {
|
|
58
|
+
...t,
|
|
59
|
+
time: void 0,
|
|
60
|
+
products: {
|
|
61
|
+
...t.products,
|
|
62
|
+
size: void 0
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return JSON.parse(JSON.stringify(e));
|
|
66
|
+
}
|
|
67
|
+
function T(t) {
|
|
68
|
+
return typeof t == "object" && t !== null && "query" in t && "result" in t && "created" in t;
|
|
69
|
+
}
|
|
70
|
+
async function z(t, { usePersistentCache: e, ...r }, c) {
|
|
71
|
+
if (!e)
|
|
72
|
+
return c(t, r);
|
|
73
|
+
const n = await O(t, r, c);
|
|
74
|
+
return k(t, n), n;
|
|
75
|
+
}
|
|
76
|
+
async function O(t, e, r) {
|
|
77
|
+
const { from: c = 0, size: n = 0 } = t.products || {}, s = N(t);
|
|
78
|
+
if (!s)
|
|
79
|
+
return await r(t, e);
|
|
80
|
+
const o = s?.products?.size ?? 0, i = s?.products?.hits ?? [];
|
|
81
|
+
if (n === o)
|
|
82
|
+
return s;
|
|
83
|
+
if (n < o)
|
|
84
|
+
return {
|
|
85
|
+
...s,
|
|
86
|
+
products: {
|
|
87
|
+
...s.products,
|
|
88
|
+
size: n,
|
|
89
|
+
hits: i.slice(0, n),
|
|
90
|
+
total: s.products?.total || 0
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const a = n - i.length, w = c > 0 ? c + 1 : n - a, S = {
|
|
94
|
+
...t,
|
|
95
|
+
products: {
|
|
96
|
+
...t.products,
|
|
97
|
+
from: w,
|
|
98
|
+
size: a
|
|
99
|
+
}
|
|
100
|
+
}, l = await r(S, e);
|
|
101
|
+
return {
|
|
102
|
+
...s,
|
|
103
|
+
products: {
|
|
104
|
+
...s.products,
|
|
105
|
+
size: n,
|
|
106
|
+
hits: [...s.products?.hits || [], ...l.products?.hits || []],
|
|
107
|
+
total: l.products?.total || 0
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const E = 3e4, u = /* @__PURE__ */ new Map();
|
|
112
|
+
function J(t, e) {
|
|
113
|
+
const r = u.get(t);
|
|
114
|
+
if (!r) return;
|
|
115
|
+
const c = Date.now() - r.created > E, n = h(e, r.query);
|
|
116
|
+
if (c || !n) {
|
|
117
|
+
u.delete(t);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
return r.result;
|
|
121
|
+
}
|
|
122
|
+
function W(t, e, r) {
|
|
123
|
+
u.set(t, {
|
|
124
|
+
query: e,
|
|
125
|
+
result: r,
|
|
126
|
+
created: Date.now()
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async function _(t, e, r) {
|
|
130
|
+
if (!e.useMemoryCache)
|
|
131
|
+
return r(t, e);
|
|
132
|
+
const c = JSON.stringify(t), n = J(c, t);
|
|
133
|
+
if (n) return n;
|
|
134
|
+
const s = await r(t, e);
|
|
135
|
+
return W(c, t, s), s;
|
|
136
|
+
}
|
|
137
|
+
async function D(t, e, r) {
|
|
138
|
+
if (!e.redirect)
|
|
139
|
+
return r(t, e);
|
|
140
|
+
const c = await r(t, e);
|
|
141
|
+
if (c.keywords?.hits?.length) {
|
|
142
|
+
const n = c.keywords.hits.find((s) => s.keyword === t.query && s._redirect);
|
|
143
|
+
n && n._redirect && (window.location.href = n._redirect);
|
|
144
|
+
}
|
|
145
|
+
return c;
|
|
146
|
+
}
|
|
147
|
+
function L(t) {
|
|
148
|
+
return new Promise((e) => setTimeout(e, t));
|
|
149
|
+
}
|
|
150
|
+
async function M(t, { maxRetries: e = 0, retryInterval: r = 0, ...c }, n) {
|
|
151
|
+
let s = 0;
|
|
152
|
+
for (; ; )
|
|
153
|
+
try {
|
|
154
|
+
return await n(t, c);
|
|
155
|
+
} catch (o) {
|
|
156
|
+
if (s >= e)
|
|
157
|
+
throw o;
|
|
158
|
+
if (!V(o))
|
|
159
|
+
throw f.info("Skipping retry logic for", o), o;
|
|
160
|
+
s++, await L(r);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function V(t) {
|
|
164
|
+
return !t || typeof t != "object" ? !1 : !("status" in t) || j(t.status);
|
|
165
|
+
}
|
|
166
|
+
function j(t) {
|
|
167
|
+
return typeof t == "number" && (t < 400 || t >= 500);
|
|
168
|
+
}
|
|
169
|
+
async function H(t, e = {}) {
|
|
170
|
+
const r = await new Promise(y);
|
|
171
|
+
return x(
|
|
172
|
+
r.search,
|
|
173
|
+
M,
|
|
174
|
+
D,
|
|
175
|
+
_,
|
|
176
|
+
z,
|
|
177
|
+
C
|
|
178
|
+
)(t, e);
|
|
179
|
+
}
|
|
180
|
+
function x(t, ...e) {
|
|
181
|
+
return e.reduce((r, c) => (n, s) => c(n, s, r), t);
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
P as a,
|
|
185
|
+
G as g,
|
|
186
|
+
H as s
|
|
187
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const w=require("preact"),f=require("preact/hooks"),u=require("./unique-BXXNictB.cjs"),C=require("./logger-Boh_C6Bz.cjs"),E=require("./search-
|
|
1
|
+
"use strict";const w=require("preact"),f=require("preact/hooks"),u=require("./unique-BXXNictB.cjs"),C=require("./logger-Boh_C6Bz.cjs"),E=require("./search-DItu5YCc.cjs"),k=w.createContext(null);function p(){const e=f.useContext(k);if(!e)throw new Error("useConfig must be used within a ConfigProvider");return e}function A(){const e=p();if(e.pageType!=="search")throw new Error("useSerpConfig must be used within a NostoSearchPageProvider");return e}function I(){const e=p();if(e.pageType!=="category")throw new Error("useCategoryConfig must be used within a NostoCategoryPageProvider");return e}function U(){const e=p();if(e.pageType!=="autocomplete")throw new Error("useAutocompleteConfig must be used within a NostoAutocompletePageProvider");return e}function b(e,r={}){const t=new Map;let n=u.deepMergePlain(e,r??{});const a=u.deepMergePlain(e,r);function c(l){n=l(n);for(const g of t.values())g(n)}function s(l){c(g=>({...g,...l}))}function i(){return n}function o(){return structuredClone(a)}function d(l,g){let m=l(n);t.set(g,M=>{const y=l(M);C.isEqual(y,m)||(m=y,g(y))})}function T(l){d(g=>g.initialized,g=>{g&&l()})}function q(l){t.delete(l)}return{updateState:s,getState:i,getInitialState:o,onChange:d,onInit:T,clearOnChange:q}}const v={loading:!0,query:{},response:{},initialized:!1};function P(e={}){return b(v,e)}const F=w.createContext(P());function Q(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:z,...r.products},...r.keywords?{keywords:{...r.keywords,fields:u.unique([...K,...r.keywords.fields??[]]),highlight:r.keywords.highlight??{preTag:"<strong>",postTag:"</strong>"}}}:{}}}const z=["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"],K=["keyword","_redirect"];async function S(e,r,t){const n=u.measure("newSearch"),a=e.config.pageType,c=a==="search"?"serp":a,s=u.deepMerge(e.store.getInitialState().query,r),i=u.deepMerge(e.config.search,t,{track:c,redirect:a!=="autocomplete",isKeyword:!!t?.isKeyword,usePersistentCache:e.config.pageType!=="autocomplete"&&e.config.persistentSearchCache,useMemoryCache:e.config.pageType==="autocomplete"&&e.config.memoryCache});e.config.onBeforeSearch?.(e,i),e.store.updateState({query:s,loading:!0,initialized:!0});const o=e.config.queryModifications({...s,products:{...s.products,filter:u.mergeArrays(e.store.getInitialState().query?.products?.filter,r.products?.filter)}},a);try{const d=await E.search(Q(e.config.pageType,o),i);e.store.updateState({response:d,loading:!1})}catch(d){C.logger.error("Search action failed",d),e.config.onSearchError?.(d,o,i,a)}n()}async function h(e,r,t){const n=u.measure("updateSearch"),a=u.deepMerge(e.store.getState().query,{products:{from:0}},r);await S(e,a,t),n()}async function N(e,r,t){const n=u.measure("replaceFilter"),a=e.store.getState().query.products?.filter,c=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await h(e,{products:{filter:[...a?.filter(s=>s.field!==r)??[],...c]}}),n()}async function x(e,r,t,n){const a=u.measure("toggleProductFilter"),c=e.store.getState().query.products?.filter,s=c?.find(o=>o.value instanceof Array&&o.field===r),i=s?.value?{...s,value:[...s.value.filter(o=>!C.isEqual(o,t)),...n?[t]:[]]}:n?{field:r,value:[t]}:void 0;await h(e,{products:{filter:[...c?.filter(o=>o!==s)??[],...i?.value?.length?[i]:[]]}}),a()}function B(){const e=p(),r=f.useContext(F),t=f.useMemo(()=>({config:e,store:r}),[e,r]),n=f.useCallback((i,o)=>S(t,i,o),[t]),a=f.useCallback((i,o)=>h(t,i,o),[t]),c=f.useCallback((i,o,d)=>x(t,i,o,d),[t]),s=f.useCallback((i,o)=>N(t,i,o),[t]);return{newSearch:n,updateSearch:a,toggleProductFilter:c,replaceFilter:s}}exports.ConfigContext=k;exports.StoreContext=F;exports.createExtendableStore=b;exports.createStore=P;exports.defaultState=v;exports.newSearch=S;exports.updateSearch=h;exports.useActions=B;exports.useAutocompleteConfig=U;exports.useCategoryConfig=I;exports.useConfig=p;exports.useSerpConfig=A;
|
|
@@ -2,7 +2,7 @@ import { createContext as S } from "preact";
|
|
|
2
2
|
import { useContext as k, useMemo as I, useCallback as d } from "preact/hooks";
|
|
3
3
|
import { b as w, u as M, a as f, d as h, m as E } from "./unique-Cv2g464w.js";
|
|
4
4
|
import { i as b, l as A } from "./logger-_fg_Za9y.js";
|
|
5
|
-
import { s as U } from "./search-
|
|
5
|
+
import { s as U } from "./search-xLgL6P5R.js";
|
|
6
6
|
const q = S(null);
|
|
7
7
|
function p() {
|
|
8
8
|
const e = k(q);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as l, a as m } from "./useActions-
|
|
2
|
-
import { g as c, a as u } from "./search-
|
|
1
|
+
import { S as l, a as m } from "./useActions-DoZCMPfW.js";
|
|
2
|
+
import { g as c, a as u } from "./search-xLgL6P5R.js";
|
|
3
3
|
import { useContext as y, useCallback as f } from "preact/hooks";
|
|
4
4
|
const e = "nosto:search-js:history";
|
|
5
5
|
function g({ value: o, historySize: t, store: s }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const a=require("./useActions-
|
|
1
|
+
"use strict";const a=require("./useActions-B6FFW8xI.cjs"),o=require("./search-DItu5YCc.cjs"),i=require("preact/hooks"),s="nosto:search-js:history";function u({value:e,historySize:t,store:r}){const l=(o.getLocalStorageItem(s)??[]).filter(y=>y!==e).concat(e),n=t?l.slice(-t):[];o.setLocalStorageItem(s,n),r.updateState({historyItems:n.reverse()})}function d(){return(o.getLocalStorageItem(s)??[]).slice().reverse().filter(t=>!!t)}function g(){const e=i.useContext(a.StoreContext),{historySize:t}=a.useAutocompleteConfig();return{addQuery:i.useCallback(c=>{u({value:c,historySize:t,store:e})},[t,e])}}exports.addToHistory=u;exports.getSavedHistory=d;exports.useHistory=g;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as n, h as u } from "./useActions-
|
|
1
|
+
import { S as n, h as u } from "./useActions-DoZCMPfW.js";
|
|
2
2
|
import { useContext as a, useState as c, useEffect as i, useCallback as f } from "preact/hooks";
|
|
3
3
|
import { i as m } from "./isBot-Dt3hQTa6.js";
|
|
4
4
|
function l(t = p) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const n=require("./useActions-
|
|
1
|
+
"use strict";const n=require("./useActions-B6FFW8xI.cjs"),r=require("preact/hooks"),i=require("./isBot-Bs99-Wlv.cjs");function c(e=f){const t=r.useContext(n.StoreContext),[o,s]=r.useState(e(t.getState()));return t.onChange(e,s),r.useEffect(()=>()=>t.clearOnChange(s),[t]),o}const f=e=>e;function a({from:e,size:t,pageSize:o}){return i.isBot()?{products:{from:e+o}}:{products:{size:t+o}}}function d(e=24){const{from:t,size:o}=c(u=>({from:u.query.products?.from??0,size:u.query.products?.size??0})),{updateSearch:s}=n.useActions();return{loadMore:r.useCallback(async()=>{await s(a({from:t,size:o,pageSize:e}))},[t,o,e,s])}}exports.getNextPageQuery=a;exports.useLoadMore=d;exports.useNostoAppState=c;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nosto/search-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.23.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -99,15 +99,15 @@
|
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@commitlint/cli": "^20.1.0",
|
|
101
101
|
"@commitlint/config-conventional": "^20.0.0",
|
|
102
|
-
"@nosto/nosto-js": "^2.9.
|
|
102
|
+
"@nosto/nosto-js": "^2.9.3",
|
|
103
103
|
"@testing-library/dom": "^10.4.1",
|
|
104
104
|
"@types/dom-speech-recognition": "^0.0.7",
|
|
105
105
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
106
|
-
"@types/node": "^24.
|
|
106
|
+
"@types/node": "^24.10.0",
|
|
107
107
|
"@vitest/coverage-v8": "^3.2.4",
|
|
108
108
|
"concurrently": "^9.2.1",
|
|
109
109
|
"copyfiles": "^2.4.1",
|
|
110
|
-
"eslint": "^9.
|
|
110
|
+
"eslint": "^9.39.0",
|
|
111
111
|
"eslint-config-prettier": "^10.1.8",
|
|
112
112
|
"eslint-plugin-barrel-files": "^3.0.1",
|
|
113
113
|
"eslint-plugin-prettier": "^5.5.4",
|
|
@@ -117,11 +117,11 @@
|
|
|
117
117
|
"eslint-plugin-unused-imports": "^4.3.0",
|
|
118
118
|
"husky": "^9.1.7",
|
|
119
119
|
"isbot": "^5.1.31",
|
|
120
|
-
"jsdom": "^27.0
|
|
120
|
+
"jsdom": "^27.1.0",
|
|
121
121
|
"prettier": "^3.6.2",
|
|
122
122
|
"typedoc": "^0.28.14",
|
|
123
123
|
"typescript": "^5.9.3",
|
|
124
|
-
"typescript-eslint": "^8.46.
|
|
124
|
+
"typescript-eslint": "^8.46.3",
|
|
125
125
|
"vite": "^7.1.12",
|
|
126
126
|
"vite-plugin-dts": "^4.5.4",
|
|
127
127
|
"vitest": "^3.1.3"
|
package/dist/search-RNs4Cunh.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const w=require("./index.es-Dp6Iaxz3.cjs"),i=require("./logger-Boh_C6Bz.cjs");async function y(t,{hitDecorators:e,...r},o){const n=await o(t,r);if(!n.products?.hits?.length||!e?.length)return n;const c=s=>e.reduce((a,u)=>u(a),s);return{...n,products:{...n.products,hits:n.products.hits.map(c)}}}function h(t,e,r){const o=JSON.stringify(e);try{r.setItem(t,o)}catch(n){i.logger.warn(n)}}function g(t,e){try{const r=e.getItem(t);if(r)return JSON.parse(r)}catch(r){i.logger.warn(r)}}function I(t,e){h(t,e,localStorage)}function C(t,e){h(t,e,sessionStorage)}function R(t){return g(t,localStorage)}function b(t){return g(t,sessionStorage)}const p="nosto:search-js:cache",N=60*1e3;function T(t,e){C(p,{query:t,result:e,created:Date.now()})}function z(t){const e=b(p);if(!e||!E(e))return null;const r=d(e.query);return!i.isEqual(d(t),r)||Date.now()-e.created>N?null:e.result}function d(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&&"created"in t}async function L(t,{usePersistentCache:e,...r},o){if(!e)return o(t,r);const n=await O(t,r,o);return T(t,n),n}async function O(t,e,r){const{from:o=0,size:n=0}=t.products||{},c=z(t);if(!c)return await r(t,e);const s=c?.products?.size??0,a=c?.products?.hits??[];if(n===s)return c;if(n<s)return{...c,products:{...c.products,size:n,hits:a.slice(0,n),total:c.products?.total||0}};const u=n-a.length,S=o>0?o+1:n-u,m={...t,products:{...t.products,from:S,size:u}},f=await r(m,e);return{...c,products:{...c.products,size:n,hits:[...c.products?.hits||[],...f.products?.hits||[]],total:f.products?.total||0}}}const J=3e4,l=new Map;function k(t,e){const r=l.get(t);if(!r)return;const o=Date.now()-r.created>J,n=i.isEqual(e,r.query);if(o||!n){l.delete(t);return}return r.result}function D(t,e,r){l.set(t,{query:e,result:r,created:Date.now()})}async function M(t,e,r){if(!e.useMemoryCache)return r(t,e);const o=JSON.stringify(t),n=k(o,t);if(n)return n;const c=await r(t,e);return D(o,t,c),c}function V(t){return new Promise(e=>setTimeout(e,t))}async function W(t,{maxRetries:e=0,retryInterval:r=0,...o},n){let c=0;for(;;)try{return await n(t,o)}catch(s){if(c>=e)throw s;if(!j(s))throw i.logger.info("Skipping retry logic for",s),s;c++,await V(r)}}function j(t){return!t||typeof t!="object"?!1:!("status"in t)||_(t.status)}function _(t){return typeof t=="number"&&(t<400||t>=500)}async function x(t,e={}){const r=await new Promise(w.s);return A(r.search,W,M,L,y)(t,e)}function A(t,...e){return e.reduce((r,o)=>(n,c)=>o(n,c,r),t)}exports.getLocalStorageItem=R;exports.search=x;exports.setLocalStorageItem=I;
|
package/dist/search-mArZ2PXy.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { s as y } from "./index.es-XNBESE3P.js";
|
|
2
|
-
import { l as f, i as h } from "./logger-_fg_Za9y.js";
|
|
3
|
-
async function C(t, { hitDecorators: e, ...r }, o) {
|
|
4
|
-
const n = await o(t, r);
|
|
5
|
-
if (!n.products?.hits?.length || !e?.length)
|
|
6
|
-
return n;
|
|
7
|
-
const c = (s) => e.reduce((i, a) => a(i), s);
|
|
8
|
-
return {
|
|
9
|
-
...n,
|
|
10
|
-
products: {
|
|
11
|
-
...n.products,
|
|
12
|
-
hits: n.products.hits.map(c)
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function p(t, e, r) {
|
|
17
|
-
const o = JSON.stringify(e);
|
|
18
|
-
try {
|
|
19
|
-
r.setItem(t, o);
|
|
20
|
-
} catch (n) {
|
|
21
|
-
f.warn(n);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function g(t, e) {
|
|
25
|
-
try {
|
|
26
|
-
const r = e.getItem(t);
|
|
27
|
-
if (r)
|
|
28
|
-
return JSON.parse(r);
|
|
29
|
-
} catch (r) {
|
|
30
|
-
f.warn(r);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function P(t, e) {
|
|
34
|
-
p(t, e, localStorage);
|
|
35
|
-
}
|
|
36
|
-
function I(t, e) {
|
|
37
|
-
p(t, e, sessionStorage);
|
|
38
|
-
}
|
|
39
|
-
function _(t) {
|
|
40
|
-
return g(t, localStorage);
|
|
41
|
-
}
|
|
42
|
-
function R(t) {
|
|
43
|
-
return g(t, sessionStorage);
|
|
44
|
-
}
|
|
45
|
-
const m = "nosto:search-js:cache", b = 60 * 1e3;
|
|
46
|
-
function N(t, e) {
|
|
47
|
-
I(m, { query: t, result: e, created: Date.now() });
|
|
48
|
-
}
|
|
49
|
-
function T(t) {
|
|
50
|
-
const e = R(m);
|
|
51
|
-
if (!e || !z(e))
|
|
52
|
-
return null;
|
|
53
|
-
const r = d(e.query);
|
|
54
|
-
return !h(d(t), r) || Date.now() - e.created > b ? null : e.result;
|
|
55
|
-
}
|
|
56
|
-
function d(t) {
|
|
57
|
-
const e = {
|
|
58
|
-
...t,
|
|
59
|
-
time: void 0,
|
|
60
|
-
products: {
|
|
61
|
-
...t.products,
|
|
62
|
-
size: void 0
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
return JSON.parse(JSON.stringify(e));
|
|
66
|
-
}
|
|
67
|
-
function z(t) {
|
|
68
|
-
return typeof t == "object" && t !== null && "query" in t && "result" in t && "created" in t;
|
|
69
|
-
}
|
|
70
|
-
async function O(t, { usePersistentCache: e, ...r }, o) {
|
|
71
|
-
if (!e)
|
|
72
|
-
return o(t, r);
|
|
73
|
-
const n = await E(t, r, o);
|
|
74
|
-
return N(t, n), n;
|
|
75
|
-
}
|
|
76
|
-
async function E(t, e, r) {
|
|
77
|
-
const { from: o = 0, size: n = 0 } = t.products || {}, c = T(t);
|
|
78
|
-
if (!c)
|
|
79
|
-
return await r(t, e);
|
|
80
|
-
const s = c?.products?.size ?? 0, i = c?.products?.hits ?? [];
|
|
81
|
-
if (n === s)
|
|
82
|
-
return c;
|
|
83
|
-
if (n < s)
|
|
84
|
-
return {
|
|
85
|
-
...c,
|
|
86
|
-
products: {
|
|
87
|
-
...c.products,
|
|
88
|
-
size: n,
|
|
89
|
-
hits: i.slice(0, n),
|
|
90
|
-
total: c.products?.total || 0
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const a = n - i.length, S = o > 0 ? o + 1 : n - a, w = {
|
|
94
|
-
...t,
|
|
95
|
-
products: {
|
|
96
|
-
...t.products,
|
|
97
|
-
from: S,
|
|
98
|
-
size: a
|
|
99
|
-
}
|
|
100
|
-
}, l = await r(w, e);
|
|
101
|
-
return {
|
|
102
|
-
...c,
|
|
103
|
-
products: {
|
|
104
|
-
...c.products,
|
|
105
|
-
size: n,
|
|
106
|
-
hits: [...c.products?.hits || [], ...l.products?.hits || []],
|
|
107
|
-
total: l.products?.total || 0
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
const J = 3e4, u = /* @__PURE__ */ new Map();
|
|
112
|
-
function k(t, e) {
|
|
113
|
-
const r = u.get(t);
|
|
114
|
-
if (!r) return;
|
|
115
|
-
const o = Date.now() - r.created > J, n = h(e, r.query);
|
|
116
|
-
if (o || !n) {
|
|
117
|
-
u.delete(t);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
return r.result;
|
|
121
|
-
}
|
|
122
|
-
function D(t, e, r) {
|
|
123
|
-
u.set(t, {
|
|
124
|
-
query: e,
|
|
125
|
-
result: r,
|
|
126
|
-
created: Date.now()
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
async function L(t, e, r) {
|
|
130
|
-
if (!e.useMemoryCache)
|
|
131
|
-
return r(t, e);
|
|
132
|
-
const o = JSON.stringify(t), n = k(o, t);
|
|
133
|
-
if (n) return n;
|
|
134
|
-
const c = await r(t, e);
|
|
135
|
-
return D(o, t, c), c;
|
|
136
|
-
}
|
|
137
|
-
function M(t) {
|
|
138
|
-
return new Promise((e) => setTimeout(e, t));
|
|
139
|
-
}
|
|
140
|
-
async function V(t, { maxRetries: e = 0, retryInterval: r = 0, ...o }, n) {
|
|
141
|
-
let c = 0;
|
|
142
|
-
for (; ; )
|
|
143
|
-
try {
|
|
144
|
-
return await n(t, o);
|
|
145
|
-
} catch (s) {
|
|
146
|
-
if (c >= e)
|
|
147
|
-
throw s;
|
|
148
|
-
if (!W(s))
|
|
149
|
-
throw f.info("Skipping retry logic for", s), s;
|
|
150
|
-
c++, await M(r);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function W(t) {
|
|
154
|
-
return !t || typeof t != "object" ? !1 : !("status" in t) || j(t.status);
|
|
155
|
-
}
|
|
156
|
-
function j(t) {
|
|
157
|
-
return typeof t == "number" && (t < 400 || t >= 500);
|
|
158
|
-
}
|
|
159
|
-
async function F(t, e = {}) {
|
|
160
|
-
const r = await new Promise(y);
|
|
161
|
-
return x(r.search, V, L, O, C)(t, e);
|
|
162
|
-
}
|
|
163
|
-
function x(t, ...e) {
|
|
164
|
-
return e.reduce((r, o) => (n, c) => o(n, c, r), t);
|
|
165
|
-
}
|
|
166
|
-
export {
|
|
167
|
-
P as a,
|
|
168
|
-
_ as g,
|
|
169
|
-
F as s
|
|
170
|
-
};
|