@nosto/search-js 1.3.0 → 1.4.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(){window.nostojs=window.nostojs??function(t){(window.nostojs.q=window.nostojs.q??[]).push(t)}}async function c(t){return window.nostojs(t)}typeof window<"u"&&(s(),c(t=>{t.internal.getSettings()}));typeof window<"u"&&s();function a(t,n){if(!t.products||!(n!=null&&n.length))return t;const e=o=>n.reduce((r,i)=>i(r),o);return{...t,products:{...t.products,hits:t.products.hits.map(e)}}}function w(t){return new Promise(n=>setTimeout(n,t))}async function f(t,n,e){const{maxRetries:o=0,retryInterval:r=1e3}=e;let i=0;for(;;)try{return await t.search(n,e)}catch(u){if(!l(u))throw console.info("Skipping retry logic for",u),u;if(i>=o)throw u;i++,await w(r)}}function l(t){return!t||typeof t!="object"?!1:!("status"in t)||h(t.status)}function h(t){return typeof t=="number"&&(t<400||t>=500)}async function y(t,n={}){const{hitDecorators:e,...o}=n,r=await new Promise(c),i=await f(r,t,o);return a(i,e)}exports.search=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../index.es-D_7T9vdv.cjs");function a(t,e){if(!t.products||!(e!=null&&e.length))return t;const r=i=>e.reduce((u,n)=>n(u),i);return{...t,products:{...t.products,hits:t.products.hits.map(r)}}}function o(t){return new Promise(e=>setTimeout(e,t))}async function l(t,e,r){const{maxRetries:i=0,retryInterval:u=1e3}=r;let n=0;for(;;)try{return await t.search(e,r)}catch(c){if(!f(c))throw console.info("Skipping retry logic for",c),c;if(n>=i)throw c;n++,await o(u)}}function f(t){return!t||typeof t!="object"?!1:!("status"in t)||h(t.status)}function h(t){return typeof t=="number"&&(t<400||t>=500)}async function y(t,e={}){const{hitDecorators:r,...i}=e,u=await new Promise(s.s),n=await l(u,t,i);return a(n,r)}exports.search=y;
@@ -0,0 +1,3 @@
1
+ /** @module ./ */
2
+ export { search } from "./src/search";
3
+ export type { HitDecorator, Options } from "./src/types";
@@ -1,42 +1,31 @@
1
- function s() {
2
- window.nostojs = window.nostojs ?? function(t) {
3
- (window.nostojs.q = window.nostojs.q ?? []).push(t);
4
- };
5
- }
6
- async function c(t) {
7
- return window.nostojs(t);
8
- }
9
- typeof window < "u" && (s(), c((t) => {
10
- t.internal.getSettings();
11
- }));
12
- typeof window < "u" && s();
13
- function a(t, n) {
14
- if (!t.products || !(n != null && n.length))
1
+ import { s as a } from "../index.es-Bcd5IQh9.js";
2
+ function s(t, r) {
3
+ if (!t.products || !(r != null && r.length))
15
4
  return t;
16
- const i = (o) => n.reduce((r, e) => e(r), o);
5
+ const e = (i) => r.reduce((u, n) => n(u), i);
17
6
  return {
18
7
  ...t,
19
8
  products: {
20
9
  ...t.products,
21
- hits: t.products.hits.map(i)
10
+ hits: t.products.hits.map(e)
22
11
  }
23
12
  };
24
13
  }
25
- function w(t) {
26
- return new Promise((n) => setTimeout(n, t));
14
+ function o(t) {
15
+ return new Promise((r) => setTimeout(r, t));
27
16
  }
28
- async function f(t, n, i) {
29
- const { maxRetries: o = 0, retryInterval: r = 1e3 } = i;
30
- let e = 0;
17
+ async function f(t, r, e) {
18
+ const { maxRetries: i = 0, retryInterval: u = 1e3 } = e;
19
+ let n = 0;
31
20
  for (; ; )
32
21
  try {
33
- return await t.search(n, i);
34
- } catch (u) {
35
- if (!h(u))
36
- throw console.info("Skipping retry logic for", u), u;
37
- if (e >= o)
38
- throw u;
39
- e++, await w(r);
22
+ return await t.search(r, e);
23
+ } catch (c) {
24
+ if (!h(c))
25
+ throw console.info("Skipping retry logic for", c), c;
26
+ if (n >= i)
27
+ throw c;
28
+ n++, await o(u);
40
29
  }
41
30
  }
42
31
  function h(t) {
@@ -45,10 +34,10 @@ function h(t) {
45
34
  function l(t) {
46
35
  return typeof t == "number" && (t < 400 || t >= 500);
47
36
  }
48
- async function y(t, n = {}) {
49
- const { hitDecorators: i, ...o } = n, r = await new Promise(c), e = await f(r, t, o);
50
- return a(e, i);
37
+ async function p(t, r = {}) {
38
+ const { hitDecorators: e, ...i } = r, u = await new Promise(a), n = await f(u, t, i);
39
+ return s(n, e);
51
40
  }
52
41
  export {
53
- y as search
42
+ p as search
54
43
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(){window.nostojs=window.nostojs??function(t){(window.nostojs.q=window.nostojs.q??[]).push(t)}}async function y(t){return window.nostojs(t)}typeof window<"u"&&(d(),y(t=>{t.internal.getSettings()}));typeof window<"u"&&d();const p={defaultCurrency:"EUR",defaultLocale:"en-US",currencySettings:{}},w={EUR:"de-DE",GBP:"en-GB",USD:"en-US",AUD:"en-AU",CAD:"en-CA",INR:"en-IN",AFN:"en-IN",BDT:"en-IN",BTN:"en-IN",MMK:"en-IN",NPR:"en-IN",PKR:"en-IN"};function g(t={}){const i={...p,...t};t.currencySettings||y(o=>{i.currencySettings=o.internal.getSettings().currencySettings??{}});function s(o,n){const{defaultCurrency:c,currencySettings:e,defaultLocale:u}=i,a=n??c,m=w[a]??u;if(a in e){const r=e[a],l=new Intl.NumberFormat(m,{useGrouping:!!r.groupingSeparator,minimumFractionDigits:r.decimalPlaces,maximumFractionDigits:r.decimalPlaces}).formatToParts(o).map(f=>f.type==="group"?r.groupingSeparator:f.type==="decimal"?r.decimalCharacter:f.value).join("");return r!=null&&r.currencyBeforeAmount?`${r.currencyToken}${l}`:`${l}${r==null?void 0:r.currencyToken}`}return new Intl.NumberFormat(m,{style:"currency",currency:a}).format(o)}return{formatCurrency:s}}function C(t){const{formatCurrency:i}=g(t);function s(n,c){const e={};return n.price!==void 0&&(e.priceText=i(n.price,c)),n.listPrice!==void 0&&(e.listPriceText=i(n.listPrice,c)),Object.assign({},n,e)}function o(n){return n.price!==void 0||n.listPrice!==void 0}return function(c){if(!o(c))return c;const e=s(c,c.priceCurrencyCode);return e.skus&&e.skus.some(o)&&(e.skus=e.skus.map(u=>o(u)?s(u,c.priceCurrencyCode):u)),e}}exports.getCurrencyFormatting=g;exports.priceDecorator=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../index.es-D_7T9vdv.cjs"),g={defaultCurrency:"EUR",defaultLocale:"en-US",currencySettings:{}},p={EUR:"de-DE",GBP:"en-GB",USD:"en-US",AUD:"en-AU",CAD:"en-CA",INR:"en-IN",AFN:"en-IN",BDT:"en-IN",BTN:"en-IN",MMK:"en-IN",NPR:"en-IN",PKR:"en-IN"};function y(u={}){const o={...g,...u};u.currencySettings||d.s(c=>{o.currencySettings=c.internal.getSettings().currencySettings??{}});function a(c,n){const{defaultCurrency:t,currencySettings:r,defaultLocale:i}=o,s=n??t,f=p[s]??i;if(s in r){const e=r[s],l=new Intl.NumberFormat(f,{useGrouping:!!e.groupingSeparator,minimumFractionDigits:e.decimalPlaces,maximumFractionDigits:e.decimalPlaces}).formatToParts(c).map(m=>m.type==="group"?e.groupingSeparator:m.type==="decimal"?e.decimalCharacter:m.value).join("");return e!=null&&e.currencyBeforeAmount?`${e.currencyToken}${l}`:`${l}${e==null?void 0:e.currencyToken}`}return new Intl.NumberFormat(f,{style:"currency",currency:s}).format(c)}return{formatCurrency:a}}function C(u){const{formatCurrency:o}=y(u);function a(n,t){const r={};return n.price!==void 0&&(r.priceText=o(n.price,t)),n.listPrice!==void 0&&(r.listPriceText=o(n.listPrice,t)),Object.assign({},n,r)}function c(n){return n.price!==void 0||n.listPrice!==void 0}return function(t){if(!c(t))return t;const r=a(t,t.priceCurrencyCode);return r.skus&&r.skus.some(c)&&(r.skus=r.skus.map(i=>c(i)?a(i,t.priceCurrencyCode):i)),r}}exports.getCurrencyFormatting=y;exports.priceDecorator=C;
@@ -0,0 +1,3 @@
1
+ /** @module currencies */
2
+ export { type CurrencyConfig, getCurrencyFormatting } from "./src/getCurrencyFormatting";
3
+ export { type FormattedPrices, priceDecorator, type Result } from "./src/priceDecorator";
@@ -1,21 +1,10 @@
1
- function d() {
2
- window.nostojs = window.nostojs ?? function(t) {
3
- (window.nostojs.q = window.nostojs.q ?? []).push(t);
4
- };
5
- }
6
- async function y(t) {
7
- return window.nostojs(t);
8
- }
9
- typeof window < "u" && (d(), y((t) => {
10
- t.internal.getSettings();
11
- }));
12
- typeof window < "u" && d();
1
+ import { s as y } from "../index.es-Bcd5IQh9.js";
13
2
  const p = {
14
3
  defaultCurrency: "EUR",
15
4
  defaultLocale: "en-US",
16
5
  /** @hidden */
17
6
  currencySettings: {}
18
- }, g = {
7
+ }, d = {
19
8
  EUR: "de-DE",
20
9
  GBP: "en-GB",
21
10
  USD: "en-US",
@@ -30,50 +19,50 @@ const p = {
30
19
  NPR: "en-IN",
31
20
  PKR: "en-IN"
32
21
  };
33
- function w(t = {}) {
34
- const i = {
22
+ function g(i = {}) {
23
+ const o = {
35
24
  ...p,
36
- ...t
25
+ ...i
37
26
  };
38
- t.currencySettings || y((o) => {
39
- i.currencySettings = o.internal.getSettings().currencySettings ?? {};
27
+ i.currencySettings || y((c) => {
28
+ o.currencySettings = c.internal.getSettings().currencySettings ?? {};
40
29
  });
41
- function s(o, e) {
42
- const { defaultCurrency: c, currencySettings: n, defaultLocale: u } = i, a = e ?? c, m = g[a] ?? u;
43
- if (a in n) {
44
- const r = n[a], l = new Intl.NumberFormat(m, {
45
- useGrouping: !!r.groupingSeparator,
46
- minimumFractionDigits: r.decimalPlaces,
47
- maximumFractionDigits: r.decimalPlaces
48
- }).formatToParts(o).map((f) => f.type === "group" ? r.groupingSeparator : f.type === "decimal" ? r.decimalCharacter : f.value).join("");
49
- return r != null && r.currencyBeforeAmount ? `${r.currencyToken}${l}` : `${l}${r == null ? void 0 : r.currencyToken}`;
30
+ function a(c, n) {
31
+ const { defaultCurrency: t, currencySettings: r, defaultLocale: u } = o, s = n ?? t, f = d[s] ?? u;
32
+ if (s in r) {
33
+ const e = r[s], l = new Intl.NumberFormat(f, {
34
+ useGrouping: !!e.groupingSeparator,
35
+ minimumFractionDigits: e.decimalPlaces,
36
+ maximumFractionDigits: e.decimalPlaces
37
+ }).formatToParts(c).map((m) => m.type === "group" ? e.groupingSeparator : m.type === "decimal" ? e.decimalCharacter : m.value).join("");
38
+ return e != null && e.currencyBeforeAmount ? `${e.currencyToken}${l}` : `${l}${e == null ? void 0 : e.currencyToken}`;
50
39
  }
51
- return new Intl.NumberFormat(m, {
40
+ return new Intl.NumberFormat(f, {
52
41
  style: "currency",
53
- currency: a
54
- }).format(o);
42
+ currency: s
43
+ }).format(c);
55
44
  }
56
45
  return {
57
- formatCurrency: s
46
+ formatCurrency: a
58
47
  };
59
48
  }
60
- function P(t) {
61
- const { formatCurrency: i } = w(t);
62
- function s(e, c) {
63
- const n = {};
64
- return e.price !== void 0 && (n.priceText = i(e.price, c)), e.listPrice !== void 0 && (n.listPriceText = i(e.listPrice, c)), Object.assign({}, e, n);
49
+ function S(i) {
50
+ const { formatCurrency: o } = g(i);
51
+ function a(n, t) {
52
+ const r = {};
53
+ return n.price !== void 0 && (r.priceText = o(n.price, t)), n.listPrice !== void 0 && (r.listPriceText = o(n.listPrice, t)), Object.assign({}, n, r);
65
54
  }
66
- function o(e) {
67
- return e.price !== void 0 || e.listPrice !== void 0;
55
+ function c(n) {
56
+ return n.price !== void 0 || n.listPrice !== void 0;
68
57
  }
69
- return function(c) {
70
- if (!o(c))
71
- return c;
72
- const n = s(c, c.priceCurrencyCode);
73
- return n.skus && n.skus.some(o) && (n.skus = n.skus.map((u) => o(u) ? s(u, c.priceCurrencyCode) : u)), n;
58
+ return function(t) {
59
+ if (!c(t))
60
+ return t;
61
+ const r = a(t, t.priceCurrencyCode);
62
+ return r.skus && r.skus.some(c) && (r.skus = r.skus.map((u) => c(u) ? a(u, t.priceCurrencyCode) : u)), r;
74
63
  };
75
64
  }
76
65
  export {
77
- w as getCurrencyFormatting,
78
- P as priceDecorator
66
+ g as getCurrencyFormatting,
67
+ S as priceDecorator
79
68
  };
@@ -0,0 +1,20 @@
1
+ function o() {
2
+ window.nostojs = window.nostojs ?? function(n) {
3
+ (window.nostojs.q = window.nostojs.q ?? []).push(n);
4
+ };
5
+ }
6
+ async function i(n) {
7
+ return window.nostojs(n);
8
+ }
9
+ let t = null;
10
+ typeof window < "u" && (o(), i((n) => {
11
+ t = n.internal.getSettings();
12
+ }));
13
+ function s() {
14
+ return t;
15
+ }
16
+ typeof window < "u" && o();
17
+ export {
18
+ s as i,
19
+ i as s
20
+ };
@@ -0,0 +1 @@
1
+ "use strict";function o(){window.nostojs=window.nostojs??function(n){(window.nostojs.q=window.nostojs.q??[]).push(n)}}async function t(n){return window.nostojs(n)}let s=null;typeof window<"u"&&(o(),t(n=>{s=n.internal.getSettings()}));function i(){return s}typeof window<"u"&&o();exports.i=i;exports.s=t;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("preact/hooks");function s(){window.nostojs=window.nostojs??function(o){(window.nostojs.q=window.nostojs.q??[]).push(o)}}async function e(o){return window.nostojs(o)}typeof window<"u"&&(s(),e(o=>{o.internal.getSettings()}));typeof window<"u"&&s();function c(){const[o,i]=n.useState([]),[a,u]=n.useState([]);return n.useEffect(()=>{e(async r=>{const{products:t,segments:w}=await r.getSearchSessionParams();i(w??[]),u((t==null?void 0:t.personalizationBoost)??[])})},[]),{segments:o,boost:a}}exports.usePersonalization=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("preact"),l=require("preact/hooks"),C=require("../index.es-D_7T9vdv.cjs");var b=0;function q(t,e,n,r,o,u){e||(e={});var i,s,c=e;if("ref"in c)for(s in c={},e)s=="ref"?i=e[s]:c[s]=e[s];var p={type:t,props:c,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--b,__i:-1,__u:0,__source:o,__self:u};if(typeof t=="function"&&(i=t.defaultProps))for(s in i)c[s]===void 0&&(c[s]=i[s]);return _.options.vnode&&_.options.vnode(p),p}const m=t=>String(t)==="[object Object]";function S(t){if(!m(t))return!1;const e=t.constructor;if(e===void 0)return!0;const n=e.prototype;return!(!m(n)||!n.hasOwnProperty("isPrototypeOf"))}const j=t=>{const e=Object.entries(t).reduce((n,[r,o])=>{const u=S(o)?j(o):Object.freeze(o);return{...n,[r]:u}},{});return Object.freeze(e)};function A(...t){return t.reduce((e,n)=>P(e,n))}function P(t,e){return S(t)&&S(e)?Object.entries(e).reduce((n,[r,o])=>(n[r]=P(n[r],o),n),{...t}):e}function y(t,e){if(t===e)return!0;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)&&Array.isArray(e))return t.length!==e.length?!1:t.every((n,r)=>y(n,e[r]));if(S(t)&&S(e)){const n=Object.entries(t);return n.length!==Object.keys(e).length?!1:n.every(([r,o])=>y(o,e[r]))}return!1}const h={loading:!0,pageType:void 0,query:{query:""},response:{query:""},initialized:!1,customParams:{}};function v(t){const e=new Map;let n=t?A(h,t):h;const r=j(n);function o(a){n=a(n);for(const f of e.values())f(n)}function u(a){o(f=>({...f,...a}))}function i(){return n}function s(){return r}function c(a,f){let O;e.set(f,z=>{const g=a(z);y(g,O)||(O=g,f(g))})}function p(a){e.delete(a)}return{updateState:u,getState:i,getInitialState:s,onChange:c,clearOnChange:p}}const d=_.createContext(v({}));function k({store:t,children:e}){return q(d,{value:t,children:e})}function x(t=T){const e=l.useContext(d),[n,r]=l.useState(t(e.getState()));return e.onChange(t,r),l.useEffect(()=>()=>e.clearOnChange(r),[e]),n}const T=t=>t;function w(){const[t,e]=l.useState([]),[n,r]=l.useState([]);return l.useEffect(()=>{C.s(async o=>{const{products:u,segments:i}=await o.getSearchSessionParams();e(i??[]),r((u==null?void 0:u.personalizationBoost)??[])})},[]),{segments:t,boost:n}}function E(t){return v(t)}exports.StoreContext=d;exports.StoreProvider=k;exports.mockStore=E;exports.useNostoAppState=x;exports.usePersonalization=w;
@@ -0,0 +1,6 @@
1
+ /** @module preact */
2
+ export { useNostoAppState } from "./src/hooks/useNostoAppState";
3
+ export { usePersonalization } from "./src/hooks/usePersonalization";
4
+ export { type State, type Store } from "./src/store";
5
+ export { StoreContext, StoreProvider } from "./src/storeContext";
6
+ export { mockStore } from "./test/mocks/mocks";
@@ -1,28 +1,133 @@
1
- import { useState as s, useEffect as c } from "preact/hooks";
2
- function t() {
3
- window.nostojs = window.nostojs ?? function(o) {
4
- (window.nostojs.q = window.nostojs.q ?? []).push(o);
1
+ import { options as m, createContext as b } from "preact";
2
+ import { useContext as A, useState as S, useEffect as h } from "preact/hooks";
3
+ import { s as k } from "../index.es-Bcd5IQh9.js";
4
+ var q = 0;
5
+ function x(t, e, n, r, o, i) {
6
+ e || (e = {});
7
+ var u, s, c = e;
8
+ if ("ref" in c) for (s in c = {}, e) s == "ref" ? u = e[s] : c[s] = e[s];
9
+ var p = { type: t, props: c, key: n, ref: u, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --q, __i: -1, __u: 0, __source: o, __self: i };
10
+ if (typeof t == "function" && (u = t.defaultProps)) for (s in u) c[s] === void 0 && (c[s] = u[s]);
11
+ return m.vnode && m.vnode(p), p;
12
+ }
13
+ const d = (t) => String(t) === "[object Object]";
14
+ function l(t) {
15
+ if (!d(t))
16
+ return !1;
17
+ const e = t.constructor;
18
+ if (e === void 0)
19
+ return !0;
20
+ const n = e.prototype;
21
+ return !(!d(n) || !n.hasOwnProperty("isPrototypeOf"));
22
+ }
23
+ const j = (t) => {
24
+ const e = Object.entries(t).reduce((n, [r, o]) => {
25
+ const i = l(o) ? j(o) : Object.freeze(o);
26
+ return {
27
+ ...n,
28
+ [r]: i
29
+ };
30
+ }, {});
31
+ return Object.freeze(e);
32
+ };
33
+ function w(...t) {
34
+ return t.reduce((e, n) => v(e, n));
35
+ }
36
+ function v(t, e) {
37
+ return l(t) && l(e) ? Object.entries(e).reduce(
38
+ (n, [r, o]) => (n[r] = v(n[r], o), n),
39
+ { ...t }
40
+ ) : e;
41
+ }
42
+ function _(t, e) {
43
+ if (t === e)
44
+ return !0;
45
+ if (t instanceof Date && e instanceof Date)
46
+ return t.getTime() === e.getTime();
47
+ if (Array.isArray(t) && Array.isArray(e))
48
+ return t.length !== e.length ? !1 : t.every((n, r) => _(n, e[r]));
49
+ if (l(t) && l(e)) {
50
+ const n = Object.entries(t);
51
+ return n.length !== Object.keys(e).length ? !1 : n.every(([r, o]) => _(o, e[r]));
52
+ }
53
+ return !1;
54
+ }
55
+ const O = {
56
+ loading: !0,
57
+ pageType: void 0,
58
+ query: {
59
+ query: ""
60
+ },
61
+ response: {
62
+ query: ""
63
+ },
64
+ initialized: !1,
65
+ customParams: {}
66
+ };
67
+ function z(t) {
68
+ const e = /* @__PURE__ */ new Map();
69
+ let n = t ? w(O, t) : O;
70
+ const r = j(n);
71
+ function o(f) {
72
+ n = f(n);
73
+ for (const a of e.values())
74
+ a(n);
75
+ }
76
+ function i(f) {
77
+ o((a) => ({ ...a, ...f }));
78
+ }
79
+ function u() {
80
+ return n;
81
+ }
82
+ function s() {
83
+ return r;
84
+ }
85
+ function c(f, a) {
86
+ let y;
87
+ e.set(a, (P) => {
88
+ const g = f(P);
89
+ _(g, y) || (y = g, a(g));
90
+ });
91
+ }
92
+ function p(f) {
93
+ e.delete(f);
94
+ }
95
+ return {
96
+ updateState: i,
97
+ getState: u,
98
+ getInitialState: s,
99
+ onChange: c,
100
+ clearOnChange: p
5
101
  };
6
102
  }
7
- async function e(o) {
8
- return window.nostojs(o);
9
- }
10
- typeof window < "u" && (t(), e((o) => {
11
- o.internal.getSettings();
12
- }));
13
- typeof window < "u" && t();
14
- function g() {
15
- const [o, i] = s([]), [w, a] = s([]);
16
- return c(() => {
17
- e(async (r) => {
18
- const { products: n, segments: u } = await r.getSearchSessionParams();
19
- i(u ?? []), a((n == null ? void 0 : n.personalizationBoost) ?? []);
103
+ const C = b(z({}));
104
+ function M({ store: t, children: e }) {
105
+ return /* @__PURE__ */ x(C, { value: t, children: e });
106
+ }
107
+ function V(t = T) {
108
+ const e = A(C), [n, r] = S(t(e.getState()));
109
+ return e.onChange(t, r), h(() => () => e.clearOnChange(r), [e]), n;
110
+ }
111
+ const T = (t) => t;
112
+ function F() {
113
+ const [t, e] = S([]), [n, r] = S([]);
114
+ return h(() => {
115
+ k(async (o) => {
116
+ const { products: i, segments: u } = await o.getSearchSessionParams();
117
+ e(u ?? []), r((i == null ? void 0 : i.personalizationBoost) ?? []);
20
118
  });
21
119
  }, []), {
22
- segments: o,
23
- boost: w
120
+ segments: t,
121
+ boost: n
24
122
  };
25
123
  }
124
+ function I(t) {
125
+ return z(t);
126
+ }
26
127
  export {
27
- g as usePersonalization
128
+ C as StoreContext,
129
+ M as StoreProvider,
130
+ I as mockStore,
131
+ V as useNostoAppState,
132
+ F as usePersonalization
28
133
  };
@@ -0,0 +1,41 @@
1
+ import { State } from "@preact/store";
2
+ /**
3
+ * Imports a part of the Nosto state to the component.
4
+ *
5
+ * @example
6
+ * ```jsx
7
+ * import { useNostoAppState } from '@nosto/search-js/preact'
8
+ *
9
+ * export default () => {
10
+ * const pageType = useNostoAppState(state => state.pageType)
11
+ *
12
+ * return (
13
+ * <div>
14
+ * Page type is {pageType}
15
+ * </div>
16
+ * )
17
+ * }
18
+ * ```
19
+ *
20
+ * If the selector parameter is not provided, the full state is returned.
21
+ * Be mindful of the unnecessary rerenders it may cause.
22
+ *
23
+ * @example
24
+ * ```jsx
25
+ * import { useNostoAppState } from '@nosto/search-js/preact'
26
+ *
27
+ * export default () => {
28
+ * const state = useNostoAppState()
29
+ *
30
+ * return (
31
+ * <div>
32
+ * Page type is {state.pageType}
33
+ * </div>
34
+ * )
35
+ * }
36
+ * ```
37
+ *
38
+ * @group Hooks
39
+ */
40
+ export declare function useNostoAppState(): State;
41
+ export declare function useNostoAppState<Selected>(selector: (state: State) => Selected): Selected;