@nosto/search-js 2.2.0 → 2.4.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.
Files changed (45) hide show
  1. package/dist/{InfiniteScrollWithObserver-BOtsS3zB.cjs → InfiniteScrollWithObserver-C3ILy8X_.cjs} +1 -1
  2. package/dist/{InfiniteScrollWithObserver-D47sKLiT.js → InfiniteScrollWithObserver-DGZxUITY.js} +1 -1
  3. package/dist/baseConfig-BlLNh6Jn.cjs +1 -0
  4. package/dist/{baseConfig-C_tlTx1w.js → baseConfig-XyA_9NDR.js} +8 -7
  5. package/dist/{storeContext-jWZFJ8Kf.js → configContext-CDTtcin_.js} +19 -20
  6. package/dist/configContext-CGXeJcqj.cjs +1 -0
  7. package/dist/core/core.cjs.js +1 -1
  8. package/dist/core/core.es.js +1 -1
  9. package/dist/logger-DW5RVLX8.js +17 -0
  10. package/dist/logger-DbHGgDgO.cjs +1 -0
  11. package/dist/preact/autocomplete.cjs.js +1 -1
  12. package/dist/preact/autocomplete.es.js +2 -2
  13. package/dist/preact/category.cjs.js +1 -1
  14. package/dist/preact/category.es.js +2 -2
  15. package/dist/preact/common.cjs.js +1 -1
  16. package/dist/preact/common.es.js +4 -4
  17. package/dist/preact/hooks.cjs.js +1 -1
  18. package/dist/preact/hooks.es.js +3 -3
  19. package/dist/preact/legacy.cjs.js +1 -1
  20. package/dist/preact/legacy.es.js +2 -2
  21. package/dist/preact/serp.cjs.js +1 -1
  22. package/dist/preact/serp.es.js +2 -2
  23. package/dist/preact/src/hooks/useLoadMore/getNextPageQuery.d.ts +7 -5
  24. package/dist/preact/src/search/resultCaching.d.ts +8 -1
  25. package/dist/preact/src/search/searchWithCache.d.ts +4 -0
  26. package/dist/search-DJ_ktWg-.cjs +1 -0
  27. package/dist/search-DaZVHDP9.js +44 -0
  28. package/dist/unique-BCAEb4ek.cjs +1 -0
  29. package/dist/unique-CyAMhegX.js +44 -0
  30. package/dist/useLoadMore-CHLvVMm8.js +293 -0
  31. package/dist/useLoadMore-Co6PDmam.cjs +1 -0
  32. package/dist/utils/src/bindInput.d.ts +14 -0
  33. package/dist/utils/src/logger.d.ts +6 -0
  34. package/dist/utils/utils.cjs.js +1 -1
  35. package/dist/utils/utils.d.ts +1 -0
  36. package/dist/utils/utils.es.js +9 -7
  37. package/package.json +6 -6
  38. package/dist/baseConfig-DEAGSRSp.cjs +0 -1
  39. package/dist/search-B0-bVNMy.js +0 -43
  40. package/dist/search-BVJZK90N.cjs +0 -1
  41. package/dist/storeContext-DVs7r6Qm.cjs +0 -1
  42. package/dist/unique-CGVAnKZy.cjs +0 -1
  43. package/dist/unique-Dwtu7vXB.js +0 -44
  44. package/dist/useLoadMore-BbcvS5k5.js +0 -261
  45. package/dist/useLoadMore-VMNS8y7r.cjs +0 -1
@@ -1,261 +0,0 @@
1
- import { u as v, S as w } from "./storeContext-jWZFJ8Kf.js";
2
- import { useContext as C, useMemo as M, useCallback as g, useState as T, useEffect as A } from "preact/hooks";
3
- import { s as R } from "./search-B0-bVNMy.js";
4
- import { u as N, a as f, m as Q, i as E } from "./unique-Dwtu7vXB.js";
5
- import { i as b, d as p } from "./isEqual-BzZ3d1JM.js";
6
- function U(e, r) {
7
- return {
8
- ...r,
9
- products: {
10
- facets: e === "autocomplete" ? void 0 : ["*"],
11
- fields: V,
12
- ...r.products
13
- },
14
- ...r.keywords ? {
15
- keywords: {
16
- ...r.keywords,
17
- fields: N([...K, ...r.keywords.fields ?? []]),
18
- highlight: r.keywords.highlight ?? {
19
- preTag: "<strong>",
20
- postTag: "</strong>"
21
- }
22
- }
23
- } : {}
24
- };
25
- }
26
- const V = [
27
- "productId",
28
- "url",
29
- "name",
30
- "imageUrl",
31
- "imageHash",
32
- "thumbUrl",
33
- "description",
34
- "brand",
35
- "variantId",
36
- "availability",
37
- "price",
38
- "priceText",
39
- "categoryIds",
40
- "categories",
41
- "customFields.key",
42
- "customFields.value",
43
- "priceCurrencyCode",
44
- "datePublished",
45
- "listPrice",
46
- "unitPricingBaseMeasure",
47
- "unitPricingUnit",
48
- "unitPricingMeasure",
49
- "googleCategory",
50
- "gtin",
51
- "ageGroup",
52
- "gender",
53
- "condition",
54
- "alternateImageUrls",
55
- "ratingValue",
56
- "reviewCount",
57
- "inventoryLevel",
58
- "skus.id",
59
- "skus.name",
60
- "skus.price",
61
- "skus.listPrice",
62
- "skus.priceText",
63
- "skus.url",
64
- "skus.imageUrl",
65
- "skus.inventoryLevel",
66
- "skus.customFields.key",
67
- "skus.customFields.value",
68
- "skus.availability",
69
- "pid",
70
- "onDiscount",
71
- "extra.key",
72
- "extra.value",
73
- "saleable",
74
- "available",
75
- "tags1",
76
- "tags2",
77
- "tags3"
78
- ], K = ["keyword", "_redirect"];
79
- function O(e, r, t) {
80
- const s = JSON.stringify(r);
81
- try {
82
- console.info("Setting storage", e, s), t.setItem(e, s);
83
- } catch (o) {
84
- console.warn(o);
85
- }
86
- }
87
- function z(e, r) {
88
- try {
89
- const t = r.getItem(e);
90
- if (t)
91
- return JSON.parse(t);
92
- } catch (t) {
93
- console.warn(t);
94
- }
95
- }
96
- function D(e, r) {
97
- O(e, r, sessionStorage);
98
- }
99
- function L(e) {
100
- return z(e, sessionStorage);
101
- }
102
- const P = "nosto:search:searchResult";
103
- function _(e, r, t) {
104
- if (!e)
105
- return;
106
- D(P, { query: r, result: t });
107
- }
108
- function j(e, r) {
109
- if (!e)
110
- return null;
111
- const t = L(P);
112
- if (!t || !B(t))
113
- return null;
114
- const s = k(t.query);
115
- return b(k(r), s) ? t.result : null;
116
- }
117
- function k(e) {
118
- return {
119
- accountId: e.accountId,
120
- customRules: e.customRules,
121
- explain: e.explain,
122
- keywords: e.keywords,
123
- products: e.products,
124
- query: e.query,
125
- redirect: e.redirect,
126
- rules: e.rules,
127
- segments: e.segments,
128
- sessionParams: e.sessionParams
129
- };
130
- }
131
- function B(e) {
132
- return typeof e == "object" && e !== null && "query" in e && "result" in e;
133
- }
134
- async function F(e, r, t) {
135
- var u, y, h;
136
- const s = f("newSearch"), o = e.config.pageType, c = o === "search" ? "serp" : o, n = p(e.store.getInitialState().query, r), a = p(e.config.search, t, {
137
- track: c,
138
- redirect: o !== "autocomplete",
139
- isKeyword: !!(t != null && t.isKeyword)
140
- });
141
- e.store.updateState({
142
- query: n,
143
- loading: !0,
144
- initialized: !0
145
- });
146
- const i = o !== "autocomplete" && e.config.persistentSearchCache, l = e.config.queryModifications(
147
- {
148
- ...n,
149
- products: {
150
- ...n.products,
151
- // Apply filter merging to avoid overwriting base filters
152
- filter: Q((y = (u = e.store.getInitialState().query) == null ? void 0 : u.products) == null ? void 0 : y.filter, (h = r.products) == null ? void 0 : h.filter)
153
- }
154
- },
155
- o
156
- );
157
- try {
158
- let d;
159
- const S = j(i, l);
160
- if (S)
161
- d = S;
162
- else {
163
- const I = U(o, l);
164
- d = await R(I, a), _(i, l, d);
165
- }
166
- e.store.updateState({
167
- response: d,
168
- loading: !1
169
- });
170
- } catch (d) {
171
- console.error("Search action failed", d);
172
- }
173
- s();
174
- }
175
- async function m(e, r, t) {
176
- const s = f("updateSearch"), o = p(e.store.getState().query, { products: { from: 0 } }, r);
177
- await F(e, o, t), s();
178
- }
179
- async function G(e, r, t) {
180
- var n;
181
- const s = f("replaceFilter"), o = (n = e.store.getState().query.products) == null ? void 0 : n.filter, c = t !== void 0 ? [{ field: r, [typeof t == "object" ? "range" : "value"]: [t] }] : [];
182
- await m(e, {
183
- products: {
184
- filter: [...(o == null ? void 0 : o.filter((a) => a.field !== r)) ?? [], ...c]
185
- }
186
- }), s();
187
- }
188
- async function J(e, r, t, s) {
189
- var i, l;
190
- const o = f("toggleProductFilter"), c = (i = e.store.getState().query.products) == null ? void 0 : i.filter, n = c == null ? void 0 : c.find((u) => u.value instanceof Array && u.field === r), a = n != null && n.value ? {
191
- ...n,
192
- value: [...n.value.filter((u) => !b(u, t)), ...s ? [t] : []]
193
- } : s ? {
194
- field: r,
195
- value: [t]
196
- } : void 0;
197
- await m(e, {
198
- products: {
199
- filter: [...(c == null ? void 0 : c.filter((u) => u !== n)) ?? [], ...(l = a == null ? void 0 : a.value) != null && l.length ? [a] : []]
200
- }
201
- }), o();
202
- }
203
- function q() {
204
- const e = v(), r = C(w), t = M(
205
- () => ({
206
- config: e,
207
- store: r
208
- }),
209
- [e, r]
210
- ), s = g(
211
- (a, i) => F(t, a, i),
212
- [t]
213
- ), o = g(
214
- (a, i) => m(t, a, i),
215
- [t]
216
- ), c = g(
217
- (a, i, l) => J(t, a, i, l),
218
- [t]
219
- ), n = g(
220
- (a, i) => G(t, a, i),
221
- [t]
222
- );
223
- return {
224
- newSearch: s,
225
- updateSearch: o,
226
- toggleProductFilter: c,
227
- replaceFilter: n
228
- };
229
- }
230
- function x(e = H) {
231
- const r = C(w), [t, s] = T(e(r.getState()));
232
- return r.onChange(e, s), A(() => () => r.clearOnChange(s), [r]), t;
233
- }
234
- const H = (e) => e;
235
- function W({ from: e, size: r, pageSize: t }) {
236
- return E() ? {
237
- products: { from: e + t }
238
- } : {
239
- products: { size: r + t }
240
- };
241
- }
242
- function te(e = 24) {
243
- const { from: r, size: t } = x((c) => {
244
- var n, a;
245
- return {
246
- from: ((n = c.query.products) == null ? void 0 : n.from) ?? 0,
247
- size: ((a = c.query.products) == null ? void 0 : a.size) ?? 0
248
- };
249
- }), { updateSearch: s } = q();
250
- return {
251
- loadMore: g(async () => {
252
- await s(W({ from: r, size: t, pageSize: e }));
253
- }, [r, t, e, s])
254
- };
255
- }
256
- export {
257
- te as a,
258
- q as b,
259
- W as g,
260
- x as u
261
- };
@@ -1 +0,0 @@
1
- "use strict";const y=require("./storeContext-DVs7r6Qm.cjs"),i=require("preact/hooks"),M=require("./search-BVJZK90N.cjs"),g=require("./unique-CGVAnKZy.cjs"),p=require("./isEqual-DQXR__da.cjs");function q(e,r){return{...r,products:{facets:e==="autocomplete"?void 0:["*"],fields:A,...r.products},...r.keywords?{keywords:{...r.keywords,fields:g.unique([...N,...r.keywords.fields??[]]),highlight:r.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"],N=["keyword","_redirect"];function T(e,r,t){const s=JSON.stringify(r);try{console.info("Setting storage",e,s),t.setItem(e,s)}catch(o){console.warn(o)}}function E(e,r){try{const t=r.getItem(e);if(t)return JSON.parse(t)}catch(t){console.warn(t)}}function Q(e,r){T(e,r,sessionStorage)}function R(e){return E(e,sessionStorage)}const w="nosto:search:searchResult";function U(e,r,t){if(!e)return;Q(w,{query:r,result:t})}function V(e,r){if(!e)return null;const t=R(w);if(!t||!x(t))return null;const s=C(t.query);return p.isEqual(C(r),s)?t.result:null}function C(e){return{accountId:e.accountId,customRules:e.customRules,explain:e.explain,keywords:e.keywords,products:e.products,query:e.query,redirect:e.redirect,rules:e.rules,segments:e.segments,sessionParams:e.sessionParams}}function x(e){return typeof e=="object"&&e!==null&&"query"in e&&"result"in e}async function b(e,r,t){var l,S,m;const s=g.measure("newSearch"),o=e.config.pageType,c=o==="search"?"serp":o,n=p.deepMerge(e.store.getInitialState().query,r),a=p.deepMerge(e.config.search,t,{track:c,redirect:o!=="autocomplete",isKeyword:!!(t!=null&&t.isKeyword)});e.store.updateState({query:n,loading:!0,initialized:!0});const u=o!=="autocomplete"&&e.config.persistentSearchCache,d=e.config.queryModifications({...n,products:{...n.products,filter:g.mergeArrays((S=(l=e.store.getInitialState().query)==null?void 0:l.products)==null?void 0:S.filter,(m=r.products)==null?void 0:m.filter)}},o);try{let f;const k=V(u,d);if(k)f=k;else{const v=q(o,d);f=await M.search(v,a),U(u,d,f)}e.store.updateState({response:f,loading:!1})}catch(f){console.error("Search action failed",f)}s()}async function h(e,r,t){const s=g.measure("updateSearch"),o=p.deepMerge(e.store.getState().query,{products:{from:0}},r);await b(e,o,t),s()}async function K(e,r,t){var n;const s=g.measure("replaceFilter"),o=(n=e.store.getState().query.products)==null?void 0:n.filter,c=t!==void 0?[{field:r,[typeof t=="object"?"range":"value"]:[t]}]:[];await h(e,{products:{filter:[...(o==null?void 0:o.filter(a=>a.field!==r))??[],...c]}}),s()}async function L(e,r,t,s){var u,d;const o=g.measure("toggleProductFilter"),c=(u=e.store.getState().query.products)==null?void 0:u.filter,n=c==null?void 0:c.find(l=>l.value instanceof Array&&l.field===r),a=n!=null&&n.value?{...n,value:[...n.value.filter(l=>!p.isEqual(l,t)),...s?[t]:[]]}:s?{field:r,value:[t]}:void 0;await h(e,{products:{filter:[...(c==null?void 0:c.filter(l=>l!==n))??[],...(d=a==null?void 0:a.value)!=null&&d.length?[a]:[]]}}),o()}function P(){const e=y.useConfig(),r=i.useContext(y.StoreContext),t=i.useMemo(()=>({config:e,store:r}),[e,r]),s=i.useCallback((a,u)=>b(t,a,u),[t]),o=i.useCallback((a,u)=>h(t,a,u),[t]),c=i.useCallback((a,u,d)=>L(t,a,u,d),[t]),n=i.useCallback((a,u)=>K(t,a,u),[t]);return{newSearch:s,updateSearch:o,toggleProductFilter:c,replaceFilter:n}}function F(e=O){const r=i.useContext(y.StoreContext),[t,s]=i.useState(e(r.getState()));return r.onChange(e,s),i.useEffect(()=>()=>r.clearOnChange(s),[r]),t}const O=e=>e;function I({from:e,size:r,pageSize:t}){return g.isBot()?{products:{from:e+t}}:{products:{size:r+t}}}function z(e=24){const{from:r,size:t}=F(c=>{var n,a;return{from:((n=c.query.products)==null?void 0:n.from)??0,size:((a=c.query.products)==null?void 0:a.size)??0}}),{updateSearch:s}=P();return{loadMore:i.useCallback(async()=>{await s(I({from:r,size:t,pageSize:e}))},[r,t,e,s])}}exports.getNextPageQuery=I;exports.useActions=P;exports.useLoadMore=z;exports.useNostoAppState=F;