Socket
Socket
Sign inDemoInstall

@sajari/react-hooks

Package Overview
Dependencies
Maintainers
8
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sajari/react-hooks - npm Package Compare versions

Comparing version 3.10.1 to 3.11.0

6

CHANGELOG.md
# Change Log
## 3.11.0
### Minor Changes
- [`b16ac53c`](https://github.com/sajari/sdk-react/commit/b16ac53c14f36d11e88164cd11beeaafec086c64) [#772](https://github.com/sajari/sdk-react/pull/772) Thanks [@JasonBerry](https://github.com/JasonBerry)! - Add tracking field to useTracking hook
## 3.10.1

@@ -4,0 +10,0 @@

2

dist/react-hooks.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@sajari/react-sdk-utils"),n=require("react"),i=e(n),r=require("@sajari/sdk-js"),s=e(require("js-cookie"));function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var a,c={qParam:"q",qOverrideParam:"q.override",qSuggestionsParam:"q.suggestions",resultsPerPageParam:"resultsPerPage",pageParam:"page",maxSuggestions:10,fieldsParam:"fields"},l=function(){function e(){this.listeners=void 0,this.listeners=[]}var t=e.prototype;return t.listen=function(e){var t=this;return this.listeners.push(e),function(){return t.unlisten(e)}},t.unlisten=function(e){var t=this.listeners.indexOf(e);t>=0&&this.listeners.splice(t,1)},t.notify=function(e){this.listeners.forEach((function(t){try{e(t)}catch(e){console&&console.error&&console.error(e)}}))},e}(),d=["page-close-analytics","body-reset-analytics","result-clicked-analytics"],f=function(){function e(e,n){var i,r=this;this.enabled=void 0,this.body=void 0,this.pipeline=void 0,this.tracking=void 0,this.listeners=void 0,this.longestNonAutocompletedBody=void 0,this.longestAutocompletedBody=void 0,this.bodyLabel=void 0,this.bodyAutocompletedLabel=void 0,this.beforeunload=function(){r.enabled&&r.body&&(r.listeners.get("page-close-analytics").notify((function(e){e(r.body)})),r.enabled=!1)},this.resetBody=function(){r.enabled&&(r.listeners.get("body-reset-analytics").notify((function(e){e(r.body)})),r.longestNonAutocompletedBody="",r.longestAutocompletedBody="",r.enabled=!1)},this.responseUpdated=function(e){if(!e.isEmpty()&&!e.isError()){r.enabled=!0;var t=e.getQueryValues().get(r.bodyLabel)||"",n=e.getValues().get(r.bodyAutocompletedLabel)||t;r.body=n,t.length>=r.longestNonAutocompletedBody.length&&(r.longestNonAutocompletedBody=t,r.longestAutocompletedBody=n)}},this.resultClicked=function(){r.enabled&&r.body&&(r.listeners.get("result-clicked-analytics").notify((function(e){e(r.body)})),r.longestNonAutocompletedBody="",r.longestAutocompletedBody="",r.enabled=!1)},this.enabled=!1,this.body="",this.pipeline=e,this.tracking=n,this.listeners=new Map(Object.entries(((i={})["page-close-analytics"]=new l,i["body-reset-analytics"]=new l,i["result-clicked-analytics"]=new l,i))),this.longestNonAutocompletedBody="",this.longestAutocompletedBody="",this.bodyLabel="q",this.bodyAutocompletedLabel="q",t.isSSR()||window.addEventListener("beforeunload",this.beforeunload),this.pipeline.listen("response-updated",this.responseUpdated),this.pipeline.listen("result-clicked",this.resultClicked),this.tracking.listen("tracking-reset",this.resetBody)}return e.prototype.listen=function(e,t){if(-1===d.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},e}();!function(e){e.UniversalAnalytics="_ua",e.AnalyticsJS="ga",e.GTag="gtag"}(a||(a={}));var g={decodeUriArgs:function(e){var t={},n=e.split("&");for(var i in n)if(n.hasOwnProperty(i)){var r=n[i].split("=");t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t},encodeUriArgs:function(e){var t=[];return Object.keys(e).forEach((function(n){return t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]))})),t.join("&")},mergeQueryStr:function(e){for(var t=this,n="string"==typeof e?this.decodeUriArgs(e):e,i=arguments.length,r=new Array(i>1?i-1:0),s=1;s<i;s++)r[s-1]=arguments[s];return r.forEach((function(e){var i="string"==typeof e?t.decodeUriArgs(e):e;Object.keys(i).forEach((function(e){n[e]=i[e]}))})),this.encodeUriArgs(n)},augmentUri:function(e,t){var n=/^([^?]+)\?(.+)+$/.exec(e);return n?n[1]+"?"+this.mergeQueryStr(n[2],t):e+"?"+this.encodeUriArgs(t)},getURLParameter:function(e){var t=new RegExp("[?|&]"+e+"=([^&;]+?)(&|#|;|$)").exec(window.location.search)||[void 0,""];return decodeURIComponent(t[1].replace(/\+/g,"%20"))||null}},h=function(){function e(e,n,i){var r=this;void 0===i&&(i="q"),this.id=void 0,this.param=void 0,this.unregisterFunctions=[],this.detatch=function(){return r.unregisterFunctions.forEach((function(e){return e()}))},this.onBodyReset=function(e){return r.sendGAPageView(e)},this.onResultClicked=function(e){return r.sendGAPageView(e)},this.onPageClose=function(e){return r.sendGAPageView(e)},this.unregisterFunctions.push(e.listen("page-close-analytics",this.onPageClose)),this.unregisterFunctions.push(e.listen("body-reset-analytics",this.onBodyReset)),this.unregisterFunctions.push(e.listen("result-clicked-analytics",this.onResultClicked)),this.id=t.isSSR()?null:void 0!==n?n:t.isFunction(window[a.AnalyticsJS])?a.AnalyticsJS:t.isFunction(window[a.UniversalAnalytics])?a.UniversalAnalytics:t.isFunction(window[a.GTag])?a.GTag:null,this.param=i}return e.prototype.sendGAPageView=function(e){if(this.id&&!t.isSSR()&&t.isFunction(window[this.id])){var n,i=g.augmentUri(window.location.href.substring(window.location.origin.length),((n={})[this.param]=e,n));this.id===a.GTag?window[this.id]("event","page_view",{page_location:i}):window[this.id]("send","pageview",i)}},e}(),p=["selection-updated","options-updated"],v=function(){function e(e){var n,i=e.initial,r=void 0===i?[]:i,s=e.joinOperator,o=void 0===s?"OR":s,u=e.multi,a=void 0===u||u,c=e.options,d=void 0===c?{}:c,f=e.array,g=void 0!==f&&f,h=e.name,p=e.field,v=e.group,m=e.count,y=void 0===m?t.isEmpty(d):m;this.current=void 0,this.initial=void 0,this.name=void 0,this.group=void 0,this.field=void 0,this.options=void 0,this.multi=void 0,this.count=void 0,this.array=void 0,this.joinOperator=void 0,this.listeners=void 0,t.isString(r)&&(r=[r]),this.current=r,this.initial=r,this.name=h,this.group=v,this.field=p,this.count=y,this.options=d,this.multi=a,this.array=g,this.joinOperator=o,this.listeners=((n={})["selection-updated"]=new l,n["options-updated"]=new l,n)}var n=e.prototype;return n.listen=function(e,t){if(!p.includes(e))throw new Error('Unknown event type "'+e+'"');return this.listeners[e].listen(t)},n.set=function(e,t){var n=this;if(void 0===t&&(t=!1),t){var i=e.filter((function(e){return!n.current.includes(e)}));this.current=[].concat(this.current,i)}else this.current=e;this.emitSelectionUpdated()},n.remove=function(e){this.current=this.current.filter((function(t){return!e.includes(t)})),this.emitSelectionUpdated()},n.isSet=function(e){return this.current.includes(e)},n.setOptions=function(e,t){void 0===t&&(t=!1),this.options=t?o({},this.options,e):e,this.emitOptionsUpdated()},n.getName=function(){return this.name},n.getGroup=function(){return this.group},n.getField=function(){return this.field},n.getCount=function(){return this.count},n.getOptions=function(){return this.options},n.get=function(){return this.current},n.isArray=function(){return this.array},n.isMulti=function(){return this.multi},n.hasChanged=function(){return!t.arraysEqual(this.current,this.initial,!1)},n.filter=function(){var e=this,n=this.current.map((function(n){var i=e.options[n];return t.isFunction(i)&&(i=i()),t.isEmpty(i)||(i=function(e){void 0===e&&(e="");var n=e;return[","].forEach((function(i){n=t.replaceAll(e,i,"\\"+i)})),n}(i)),e.count&&void 0===i&&n&&(i=e.array?e.field+' ~ ["'+n+'"]':e.field+' = "'+n+'"'),i})).filter(Boolean);return n.length<2?n.join(""):n.map((function(e){return"("+e+")"})).join(" "+this.joinOperator+" ")},n.getBuckets=function(){var e=this;return Object.entries(this.options).map((function(t){return e.name+"_"+t[0]+":"+t[1]})).join(",")},n.reset=function(e){void 0===e&&(e=!0),t.arraysEqual(this.current,this.initial)||(this.current=[].concat(this.initial),e&&this.emitSelectionUpdated())},n.emitSelectionUpdated=function(){this.listeners["selection-updated"].notify((function(e){e()}))},n.emitOptionsUpdated=function(){this.listeners["options-updated"].notify((function(e){e()}))},e}(),m=["range-updated"],y=function(){function e(e){var n,i=e.field,r=e.name,s=e.group,o=e.aggregate,u=void 0===o||o,a=e.initial,c=e.min,d=void 0===c?0:c,f=e.max,g=void 0===f?u?0:100:f,h=e.step,p=void 0===h?1:h,v=e.formatter,m=void 0===v?function(e){return e.map((function(e){return t.roundToStep(e,p)}))}:v;this.initial=void 0,this.range=void 0,this.name=void 0,this.group=void 0,this.field=void 0,this.min=void 0,this.max=void 0,this.step=void 0,this.frozen=void 0,this.aggregate=void 0,this.listeners=void 0,this.formatter=void 0,this.initial=void 0===a?u?null:[d,g]:a,this.range=this.initial,this.name=r,this.group=s,this.field=i,this.formatter=m,this.min=d,this.max=g,this.step=p,this.frozen=!1,this.aggregate=u,this.listeners=((n={})["range-updated"]=new l,n)}var n=e.prototype;return n.listen=function(e,t){if(!m.includes(e))throw new Error('Unknown event type "'+e+'"');return this.listeners[e].listen(t)},n.get=function(){return this.range},n.set=function(e,t){void 0===t&&(t=!0),this.frozen||(this.range=e?this.formatter(e):e,t&&this.emitRangeUpdated())},n.getName=function(){return this.name},n.getGroup=function(){return this.group},n.getField=function(){return this.field},n.getFrozen=function(){return this.frozen},n.setMin=function(e){this.frozen||(this.min=e)},n.setMax=function(e){this.frozen||(this.max=e)},n.getMinMax=function(){return[this.min,this.max]},n.getStep=function(){return this.step},n.filter=function(){var e=this.getMinMax();return!this.range||this.range[0]===e[0]&&this.range[1]===e[1]?"":this.field+" >= "+this.range[0]+" AND "+this.field+" <= "+this.range[1]},n.isAggregate=function(){return this.aggregate},n.setFrozen=function(e){this.frozen=e},n.hasChanged=function(){return this.range&&this.initial?this.range[0]!==this.initial[0]||this.range[1]!==this.initial[1]:this.range===this.initial},n.reset=function(e){void 0===e&&(e=!0),this.frozen||this.initial===this.range||t.arraysEqual(this.initial||[],this.range||[])||(this.range=t.isArray(this.initial)?[].concat(this.initial):this.initial,e&&this.emitRangeUpdated())},n.format=function(e){return this.formatter(e)},n.emitRangeUpdated=function(){var e=this;this.listeners["range-updated"].notify((function(t){t(e)}))},e}(),b=function(e){var n=e.filter(Boolean);return n.length>1&&(n=n.map((function(e){return"("+e+")"}))),t.isEmptyArray(n)?"":"ARRAY_MATCH("+n.join(" AND ")+")"};function k(e,n,i){var r=e.map((function(e){return{group:e.getGroup(),field:e.getField(),expression:e.filter(),count:e instanceof v&&e.getCount()}}));"filter"===n&&(r=r.filter((function(e){return Boolean(e.expression)})));var s=Object.entries(t.groupBy(r,"group")).filter((function(e){return Boolean(e[0])})).reduce((function(e,t){var n;return o({},e,((n={})[t[0]]=t[1].map((function(e){return e.expression})),n))}),{});if("filter"===n){var u,a=r.filter((function(e){return!e.group&&!e.count})).map((function(e){return"("+e.expression+")"}));return(u=Object.entries(s).reduce((function(e,n){var i=n[1];return"undefined"===n[0]||t.isEmpty(i)?e:[].concat(e,[b(i)])}),[])).concat.apply(u,a).join(i)}return r.filter((function(e){var n=e.count;return!t.isEmpty(e.field)&&n})).map((function(e){var n=e.group,i=e.expression,r=e.count;return n&&!t.isEmpty(s[n])?b(s[n]):r?i:null})).filter((function(e){return null!==e})).join(i)}var E=["selection-updated","options-updated","range-updated"];function w(e,t){var n;void 0===t&&(t="AND");var i=((n={})["selection-updated"]=new l,n["options-updated"]=new l,n["range-updated"]=new l,n),r=[];return e.forEach((function(e){e instanceof v&&r.push(e.listen("selection-updated",(function(){i["selection-updated"].notify((function(t){t(e)}))})),e.listen("options-updated",(function(){i["options-updated"].notify((function(t){t(e)}))}))),e instanceof y&&r.push(e.listen("range-updated",(function(){i["range-updated"].notify((function(t){t(e)}))})))})),{filter:function(){return k(e,"filter"," "+t+" ")},listen:function(e,t){if(-1===E.indexOf(e))throw new Error('Unknown event type "'+e+'"');return i[e].listen(t)},buckets:function(){return e.filter((function(e){return e instanceof v&&!e.getCount()})).map((function(e){return e instanceof v&&e.getBuckets()})).filter(Boolean).join(",")},countFilters:function(){return k(e,"countFilters",",")},count:function(){return e.filter((function(e){return e instanceof v&&e.getCount()})).map((function(e){return e instanceof v&&e.getField()})).filter(Boolean).join(",")},removeChildFilterListeners:function(){r.forEach((function(e){return e()}))},max:function(){return e.filter((function(e){return e instanceof y&&e.isAggregate()})).map((function(e){return e.getField()})).join(",")},min:function(){return e.filter((function(e){return e instanceof y&&e.isAggregate()})).map((function(e){return e.getField()})).join(",")}}}var S=function(){function e(e,t,n,i){this.error=void 0,this.queryValues=void 0,this.response=void 0,this.values=void 0,this.error=e,this.queryValues=t,this.response=n,this.values=i}var t=e.prototype;return t.isEmpty=function(){return null===this.error&&void 0===this.response&&void 0===this.values&&void 0===this.queryValues},t.isError=function(){return null!==this.error},t.getError=function(){return this.error},t.getQueryValues=function(){return this.queryValues},t.getResponse=function(){return this.response},t.getValues=function(){return this.values},t.getResults=function(){var e;return null==(e=this.response)?void 0:e.get("results")},t.getRedirects=function(){var e;return null==(e=this.response)?void 0:e.get("redirects")},t.getActivePromotions=function(){var e;return null==(e=this.response)?void 0:e.get("activePromotions")},t.getTotalResults=function(){var e;return null==(e=this.response)?void 0:e.get("totalResults")},t.getTime=function(){var e;return null==(e=this.response)?void 0:e.get("time")},t.getQueryId=function(){var e;return null==(e=this.response)?void 0:e.get("queryId")},t.getAggregates=function(){var e;return null==(e=this.response)?void 0:e.get("aggregates")},t.getAggregateFilters=function(){var e;return null==(e=this.response)?void 0:e.get("aggregateFilters")},t.getFeatureScoreWeight=function(){var e;return null==(e=this.response)?void 0:e.get("featureScoreWeight")},t.getBanners=function(){var e;return null==(e=this.response)?void 0:e.get("banners")},e}(),P=["tracking-reset"],R=function(){function e(e){var t;this.field=void 0,this.clientTracking=null,this.posNegLocalStorageManager=void 0,this.listeners=void 0,this.client=void 0,this.handleResultClicked=void 0,this.field=e,this.listeners=new Map(Object.entries(((t={})["tracking-reset"]=new l,t)))}var n=e.prototype;return n.bootstrap=function(e,t){var n,i;this.client=null!=(n=this.client)?n:e,this.handleResultClicked=t,this.posNegLocalStorageManager=null!=(i=this.posNegLocalStorageManager)?i:new r.PosNegLocalStorageManager(this.client)},n.listen=function(e,t){if(-1===P.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},n.emitTrackingReset=function(e){this.listeners.get("tracking-reset").notify((function(t){t(e)}))},n.reset=function(e){this.clientTracking.reset(),void 0!==e&&this.emitTrackingReset(e)},n.next=function(e){if(null===this.clientTracking)throw new Error("clientTracking is null");return this.clientTracking.next(e)},n.getMetadata=function(){var e=this.next({}).data;return t.isEmptyObject(e)?void 0:e},n.onQueryResponse=function(e){},n.onResultClick=function(e,t){},n.onPromotionClick=function(e){},n.onRedirect=function(e){},n.getResultHref=function(e,t){return e.url},e}(),A=function(){var e={},t=s.get("_ga");t&&(e.ga=t);var n=s.get("sjID");return n&&(e.sjID=n),e},x=function(e){function n(t,n,i){var s;return void 0===t&&(t="url"),void 0===n&&(n="q"),void 0===i&&(i={}),(s=e.call(this,t)||this).clientTracking=new r.InteractiveSession(n,new r.DefaultSession(r.TrackingType.Click,s.field,o({},A(),i))),s}u(n,e);var i=n.prototype;return i.extractValues=function(e,n){var i=n&&"click"in n?n.click:void 0,r=!t.isEmpty(i)&&Object.keys(e).includes(this.field)&&t.isValidURL(e[this.field]);return{useToken:r,clickToken:i,href:r?i:e.url}},i.onResultClick=function(e,n){var i,r=this.extractValues(e,n),s=r.useToken,o=r.clickToken;o&&this.handleResultClicked({token:o,values:e}),!s&&t.isString(o)&&t.isFunction(null==(i=navigator)?void 0:i.sendBeacon)&&navigator.sendBeacon(o)},i.getResultHref=function(e,t){return this.extractValues(e,t).href},n}(R),O=function(e){function t(t,n,i){var s;return void 0===t&&(t="_id"),void 0===n&&(n={}),(s=e.call(this,t)||this).searchIOAnalyticsEndpoint=void 0,s.searchIOAnalytics=void 0,s.searchIOAnalyticsEndpoint=i,s.clientTracking=new r.DefaultSession(r.TrackingType.Event,s.field,o({},A(),n)),s}u(t,e);var n=t.prototype;return n.bootstrap=function(t,n){var i;e.prototype.bootstrap.call(this,t,n),this.searchIOAnalytics=null!=(i=this.searchIOAnalytics)?i:new r.SearchIOAnalytics(t.project,t.collection,this.searchIOAnalyticsEndpoint)},n.onQueryResponse=function(e){var t=e.getQueryId();t&&this.searchIOAnalytics.updateQueryId(t)},n.onResultClick=function(e){Object.keys(e).includes(this.field)&&this.searchIOAnalytics.track("click",e[this.field],this.getMetadata()),this.handleResultClicked({values:e})},n.onPromotionClick=function(e){var t=e.id;t&&this.searchIOAnalytics.track("promotion_click",t,this.getMetadata())},n.onRedirect=function(e){this.searchIOAnalytics.track("redirect",e.id,this.getMetadata())},t}(R),C=function(e){function t(){var t;return(t=e.call(this,"_id")||this).clientTracking=new r.DefaultSession(r.TrackingType.None,t.field,A()),t}return u(t,e),t}(R),T=function(e){function t(t,n){var i;return void 0===t&&(t="url"),void 0===n&&(n={}),(i=e.call(this,t)||this).clientTracking=new r.DefaultSession(r.TrackingType.PosNeg,i.field,o({},A(),n)),i}u(t,e);var n=t.prototype;return n.bootstrap=function(t,n){e.prototype.bootstrap.call(this,t,n)},n.onResultClick=function(e,t){t&&"pos"in t&&(this.handleResultClicked({token:t.pos,values:e}),Object.keys(e).includes(this.field)&&this.posNegLocalStorageManager.add(e[this.field],t))},t}(R),N=["search-sent","response-updated","result-clicked"],U=function(){function e(e,n,i,s){var o=this;void 0===i&&(i=new C),void 0===s&&(s=[h]),this.config=void 0,this.pipeline=void 0,this.client=void 0,this.tracking=void 0,this.listeners=void 0,this.searchCount=void 0,this.response=new S(null),this.analytics=void 0,this.emitResultClicked=function(e){o.listeners.get("result-clicked").notify((function(t){t(e)}))};var u=e.account,a=e.collection,c=e.endpoint,d=e.key,g=e.secret;this.config=e;var p={name:void 0,version:void 0};t.isString(n)?p.name=n:"name"in n&&(p.name=n.name,p.version=n.version);var v={};t.isNullOrUndefined(e.userAgent)||(v.userAgent=e.userAgent),t.isNullOrUndefined(e.clickTokenURL)||(v.clickTokenURL=e.clickTokenURL),this.client=t.isSSR()?new r.Client(u,a,c,d,g,v):new r.Client(u,a,c,void 0,void 0,v),this.pipeline=this.client.pipeline(p.name,p.version),this.tracking=i,this.listeners=new Map([["search-sent",new l],["response-updated",new l],["result-clicked",new l]]),this.searchCount=0,this.response=new S(null),this.analytics=new f(this,this.tracking),s.forEach((function(e){new e(o.analytics)})),this.tracking.bootstrap(this.client,this.emitResultClicked)}var n=e.prototype;return n.listen=function(e,t){if(-1===N.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},n._emitSearchSent=function(e){this.listeners.get("search-sent").notify((function(t){t(e)}))},n._emitResponseUpdated=function(e){this.listeners.get("response-updated").notify((function(t){t(e)}))},n.search=function(e){var t=this;this.searchCount+=1;var n=this.searchCount;this.pipeline.search(e,this.tracking.next(e)).then((function(i){var r=i[0],s=i[1];n<t.searchCount||(t.response=new S(null,new Map(Object.entries(e)),new Map(Object.entries(r)),new Map(Object.entries(s))),t.tracking.onQueryResponse(t.response))})).catch((function(i){console.error(i),n<t.searchCount||(t.response=new S(i,new Map(Object.entries(e)),void 0,void 0))})).finally((function(){t._emitResponseUpdated(t.response)})),this._emitSearchSent(e)},n.clearResponse=function(e){this.tracking.next(e),this.searchCount+=1,this.response=new S(null),this._emitResponseUpdated(this.response)},n.getResponse=function(){return this.response},n.getAnalytics=function(){return this.analytics},n.getClient=function(){return this.client},n.getTracking=function(){return this.tracking},e}(),j=function(){function e(e){var t;void 0===e&&(e={}),this.variables=void 0,this.listeners=void 0,this.listeners=new Map([["values-changed",new l]]),this.variables=new Map(Object.entries(o(((t={})[c.qParam]="",t[c.resultsPerPageParam]=15,t[c.fieldsParam]="",t),e)))}var t=e.prototype;return t.listen=function(e,t){if("values-changed"!==e)throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},t.set=function(e){this._set(e),this._emitUpdated(e)},t.get=function(){var e={};return this.variables.forEach((function(t,n){e[n]="function"==typeof t?t():Array.isArray(t)?t.join(","):String(t)})),e},t._emitUpdated=function(e){var t=this;this.listeners.get("values-changed").notify((function(n){return n(e,(function(e){return t._set(e)}))}))},t._set=function(e){var t=this;Object.keys(e).forEach((function(n){void 0===e[n]?t.variables.delete(n):t.variables.set(n,e[n])}))},e}(),_=function(e,t,n){var i=t.getValues(),r=e&&i&&i.get(n.qParam)||"",s=[];return i&&(s=(i.get(n.qSuggestionsParam)||"").split(",").filter((function(e){return e.length>0})).slice(0,n.maxSuggestions)),{completion:r,query:e,suggestions:s}},F=function(e,t,n){var i=t.config,r=t.config.qParam,s=t.redirects,u=e.get()[r]||"",a=_(u,n,i);return a.redirects=o({},s,n.getRedirects()),a},q=function(e,t,n){var i=e.get()[n.config.qParam]||"";return _(i,t.getResponse(),n.config)},M=t.createContext({strict:!0,name:"PipelineContext"}),I=M[0],V=M[1],B={response:null,query:"",completion:"",suggestions:[],config:c,redirects:{}},L=/\d+\s-\s\d+/gm,D=L.test.bind(L),Q=new Intl.Collator(t.isSSR()?"en-US":window.navigator.language,{numeric:!0}),G=function(e,t){return function(n,i){var r=i[0],s=i[1],o=String(e?n[0]:n[1]),u=String(e?r:s);switch(!0){case[o,u].every(D):var a=o.split(" - ").map(Number)[0],c=u.split(" - ").map(Number)[0];return t?Q.compare(String(a),String(c)):Q.compare(String(c),String(a));case o.startsWith(">"):case u.startsWith("<"):return t?1:-1;case o.startsWith("<"):case u.startsWith(">"):return t?-1:1}return t?Q.compare(String(o),String(u)):Q.compare(String(u),String(o))}};function W(e){void 0===e&&(e="search");var t=V(),i=t.paginate,r=t[e],s=r.response,o=r.config,u=null==s?void 0:s.getQueryValues(),a=(null==u?void 0:u.get(o.pageParam))?parseInt(u.get(o.pageParam),10):1,c=(null==u?void 0:u.get(o.resultsPerPageParam))?parseInt(null==u?void 0:u.get(o.resultsPerPageParam),10):15,l=(null==s?void 0:s.getTotalResults())||0,d=Math.ceil(l/c),f=n.useMemo((function(){return a<d}),[a,d]),g=n.useMemo((function(){return a>1}),[a]),h=n.useCallback((function(){return f&&i(a+1)}),[i,f]),p=n.useCallback((function(){return g&&i(a-1)}),[i,g]);return{page:a,pageCount:d,totalResults:l,setPage:i,resultsPerPage:c,hasNext:f,hasPrevious:g,nextPage:h,previousPage:p}}Object.defineProperty(exports,"PosNegLocalStorageManager",{enumerable:!0,get:function(){return r.PosNegLocalStorageManager}}),Object.defineProperty(exports,"SearchIOAnalytics",{enumerable:!0,get:function(){return r.SearchIOAnalytics}}),exports.ClickTracking=x,exports.EVENT_ANALYTICS_BODY_RESET="body-reset-analytics",exports.EVENT_ANALYTICS_PAGE_CLOSED="page-close-analytics",exports.EVENT_ANALYTICS_RESULT_CLICKED="result-clicked-analytics",exports.EVENT_OPTIONS_UPDATED="options-updated",exports.EVENT_RANGE_UPDATED="range-updated",exports.EVENT_RESPONSE_UPDATED="response-updated",exports.EVENT_RESULT_CLICKED="result-clicked",exports.EVENT_SEARCH_SENT="search-sent",exports.EVENT_SELECTION_UPDATED="selection-updated",exports.EVENT_TRACKING_RESET="tracking-reset",exports.EVENT_VALUES_UPDATED="values-changed",exports.EventTracking=O,exports.FieldDictionary=function(e){this.id=void 0,this.url=void 0,this.title=void 0,this.subtitle=void 0,this.description=void 0,this.image=void 0,this.createdAt=void 0,this.price=void 0,this.originalPrice=void 0,this.salePrice=void 0,this.rating=void 0,this.quantity=void 0;var t=null!=e?e:{},n=t.id,i=t.url,r=void 0===i?"url":i,s=t.title,o=void 0===s?"title":s,u=t.subtitle,a=void 0===u?"url":u,c=t.description,l=void 0===c?"description":c,d=t.image,f=void 0===d?"image":d,g=t.price,h=void 0===g?"price":g,p=t.originalPrice,v=void 0===p?"originalPrice":p,m=t.salePrice,y=void 0===m?"salePrice":m,b=t.rating,k=void 0===b?"rating":b,E=t.quantity,w=void 0===E?"quantity":E,S=t.createdAt,P=void 0===S?"created_at":S;this.id=void 0===n?"_id":n,this.url=r,this.title=o,this.subtitle=a,this.description=l,this.image=f,this.price=h,this.originalPrice=v,this.salePrice=y,this.rating=k,this.quantity=w,this.createdAt=P},exports.FilterBuilder=v,exports.NoTracking=C,exports.Pipeline=U,exports.PosNegTracking=T,exports.RangeFilterBuilder=y,exports.Response=S,exports.SearchProvider=function(e){var r,s,u=e.children,a=e.search,l=e.autocomplete,d=e.defaultFilter,f=e.searchOnLoad,g=function(e){if(!t.isString(e)||t.isEmpty(e))return null;var n=JSON.parse(e),i=n.queryValues,r=n.response,s=void 0===r?{}:r,o=n.values,u=void 0===o?{}:o;return new S(null,new Map(Object.entries(void 0===i?{}:i)),new Map(Object.entries(s)),new Map(Object.entries(u)))}(e.initialResponse),h=n.useState(!1),p=h[0],v=h[1],m=n.useState(!1),y=m[0],b=m[1],k=n.useState(o({},B,{response:g})),E=k[0],P=k[1],R=n.useState(B),A=R[0],x=R[1],O=n.useState(!1),C=O[0],T=O[1],N=n.useRef(),_=n.useRef(),M=n.useRef(l),V=n.useRef(null!=(r=a.variables)?r:new j),L=n.useRef(null!=(s=null==l?void 0:l.variables)?s:new j),D=a.pipeline.getResponse();if(D.isEmpty()&&null!==g&&(D=g),a.variables||C||Object.assign(a,{variables:V.current}),!l||l.variables||C||Object.assign(l,{variables:L.current}),!C){var Q,G,W,z=w(null!=(Q=a.filters)?Q:[]),J=null!=(G=V.current.get().filter)?G:"",Y=null!=(W=null==d?void 0:d.toString())?W:"";V.current.set({filter:function(){var e=z.filter();return[Y,J,t.isEmpty(e)?'_id != ""':e].filter(Boolean).join(" AND ")},countFilters:function(){return z.countFilters()},buckets:function(){return z.buckets()},count:function(){return z.count()},min:function(){return z.min()},max:function(){return z.max()}})}var H=n.useCallback((function(e){return function(t,n){var i;void 0===n&&(n=!1);var r="autocomplete"===e?M.current:a,s="autocomplete"===e?A:E,u="autocomplete"===e?_:N;("autocomplete"===e?b:v)(!0),P((function(e){return o({},e,{query:null!=t?t:e.query})}));var c=r.pipeline,l=r.variables,d=s.config,f=((i={})[d.qParam]=null!=t?t:l.get()[d.qParam],i[d.qOverrideParam]=void 0,i[d.pageParam]=void 0,i);n&&(f[d.qOverrideParam]="true"),l.set(f),u.current&&clearTimeout(u.current),u.current=setTimeout((function(){c.search(l.get())}),50)}}),[A.config,E.config]);n.useEffect((function(){var e=o({},c,a.config);P((function(t){return o({},t,{response:D,query:V.current.get()[e.qParam]||"",config:e})})),x((function(e){return o({},e,{config:o({},c,a.config)})}));var t,n=[];if(a.filters){var i=w(a.filters);n.push(i.listen("selection-updated",(function(){return H("search")()})),i.listen("range-updated",(function(){return H("search")()})),i.removeChildFilterListeners)}if(n.push(a.pipeline.listen("response-updated",(function(e){var n;clearTimeout(t),t=setTimeout((function(){v(!1),P((function(t){return o({},t,{response:e},F(V.current,t,e))}))}),0===(null==(n=e.getResults())?void 0:n.length)?500:20)}))),n.push(V.current.listen("values-changed",(function(){return P((function(e){return o({},e,q(V.current,a.pipeline,e))}))}))),!M.current){var r=a.pipeline.config;M.current={pipeline:new U({account:r.account,collection:r.collection,endpoint:r.endpoint},"autocomplete",a.pipeline.getTracking()),variables:L.current}}return n.push(M.current.pipeline.listen("response-updated",(function(e){b(!1),x((function(t){return o({},t,{response:e},F(L.current,t,e))}))}))),n.push(L.current.listen("values-changed",(function(){return x((function(e){return o({},e,q(L.current,M.current.pipeline,e))}))}))),f&&a.pipeline.search(V.current.get()),T(!0),function(){n.forEach((function(e){return e()}))}}),[]);var K,$,X,Z=n.useCallback((function(e){return function(t){var n="autocomplete"===e?M.current:a,i=n.pipeline,r=n.variables;void 0!==t&&r.set(t),i.clearResponse(r.get())}}),[]),ee=n.useCallback((function(e){var t,n=a.pipeline,i=a.variables;i.set(((t={})[E.config.pageParam]=String(e),t)),v(!0),n.search(i.get())}),[a.pipeline,a.variables,E.config]),te=function(e){var t;void 0===e&&(e=!0),null==(t=a.filters)||t.forEach((function(t){return null==t?void 0:t.reset(e)}))};return i.createElement(I,{value:(K={autocomplete:A,search:E},o({},K,{search:o({},K.search,{variables:V.current,filters:a.filters,pipeline:a.pipeline,search:H("search"),clear:Z("search"),resetFilters:te,fields:a.fields,searching:p}),autocomplete:o({},K.autocomplete,{variables:L.current,filters:a.filters,pipeline:null==($=M.current)?void 0:$.pipeline,search:H("autocomplete"),clear:Z("autocomplete"),resetFilters:te,fields:null==(X=M.current)?void 0:X.fields,searching:y}),resultClicked:a.pipeline.emitResultClicked,paginate:ee}))},u)},exports.Tracking=R,exports.Variables=j,exports.combineFilters=w,exports.useAutocomplete=function(){var e=V().autocomplete;return{suggestions:e.suggestions,search:e.search,completion:e.completion,searching:e.searching,redirects:e.redirects}},exports.useFilter=function(e,i){void 0===i&&(i={});var r=V().search,s=r.filters,o=void 0===s?[]:s,u=r.response,a=n.useMemo((function(){return o.filter((function(t){return t instanceof v&&t.getName()===e}))[0]}),[]);if(!a)throw new Error('Filter "'+e+"\" doesn't exist.");var c=n.useState(a.get()),l=c[0],d=c[1];n.useEffect((function(){var e=a.listen("selection-updated",(function(){d(a.get())}));return function(){e()}}),[]);var f=i.sort,g=void 0===f?"alpha":f,h=i.sortAscending,p=void 0===h?"count"!==g:h,m=i.includes,y=i.excludes,b=i.prefixFilter,k=n.useMemo((function(){return a.hasChanged()}),[l]);return{options:n.useMemo((function(){if(!u||(null==u?void 0:u.isEmpty()))return[];var n=u.getAggregates(),i=u.getAggregateFilters(),r=a.getCount(),s=a.getField();if(r&&s){var o=a.isArray(),c={};if(!(c=((i||{})[s]||{}).count)){var l=((n||{})[s]||{}).count;c=void 0===l?{}:l}var d=function(e,t,n){if(void 0===t&&(t="alpha"),void 0===n&&(n=!0),"none"===t)return e;var i="count"!==t;return e.sort((function(e,t){var r=e.label,s=e.count,o=t.label,u=t.count;return G(i,n)([r,s],[o,u])}))}(function(e,t){var n=t.excludes,i=t.includes,r=t.prefixFilter;if(!i&&!n&&!r)return e.map((function(e){var t=e[0];return{value:t,count:Number(e[1]),label:t}}));for(var s=[],o=0;o<e.length;o++){var u=e[o],a=u[0],c=u[1];(!n||!n.includes(a))&&(!i||i.includes(a))&&s.push({value:a,count:Number(c),label:a})}return r&&(s=s.filter((function(e){return e.value.startsWith(r)})).map((function(e){var t=e.value,n=e.count;return{label:t.replace(r,""),count:n,value:t}}))),s}(Object.entries(c),{includes:m,excludes:y,prefixFilter:b}),g,p).map((function(e){var t=e.value;return{label:e.label,count:e.count,value:o?s+' ~ ["'+t+'"]':s+' = "'+t+'"'}})),f={};return d.forEach((function(e){f[e.label]=e.value})),a.setOptions(f),d}return function(e,t,n){return void 0===t&&(t="alpha"),void 0===n&&(n=!0),"none"===t?e:e.sort(G("count"!==t,n))}(Object.entries(a.getOptions()),g,p).map((function(n){var i=n[0];return{label:i,value:n[1],count:function(e,n){var i,r,s,o,u;if(!e||(null==e?void 0:e.isEmpty()))return null;var a=0,c=e.getAggregates(),l=e.getAggregateFilters();return l&&Object.keys(null!=(i=null==(r=l.buckets)?void 0:r.count)?i:{}).includes(n)?a=l.buckets.count:c&&Object.keys(null!=(s=null==(o=c.buckets)?void 0:o.count)?s:{}).includes(n)&&(a=c.buckets.count),t.isNumber(a)?0:null!=(u=a[n])?u:0}(u,e+"_"+i)}}))}),[JSON.stringify(null==u?void 0:u.getResults())]),setSelected:function(e,t){void 0===t&&(t=!1),a.set(e,t)},selected:l,reset:function(){a.reset()},showReset:k,multi:a.isMulti()}},exports.usePagination=W,exports.useQuery=function(){var e=V().search,t=e.search,i=e.variables,r=e.config;return{query:e.query,setQuery:n.useCallback((function(e){var n;i.set(((n={})[r.qParam]=e,n)),t(e)}),[t,i])}},exports.useRangeFilter=function(e){var i=V().search,r=i.filters,s=void 0===r?[]:r,o=i.response,u=i.query,a=n.useRef(null),c=n.useRef(!1),l=n.useMemo((function(){return s.filter((function(t){return t instanceof y&&t.getName()===e}))[0]}),[]),d=l.isAggregate(),f=l.getMinMax();if(!l)throw new Error('Filter "'+e+"\" doesn't exist.");var g=n.useState(l.get()),h=g[0],p=g[1],v=n.useState(f[0]),m=v[0],b=v[1],k=n.useState(f[1]),E=k[0],w=k[1];n.useEffect((function(){d&&null!==a.current&&l.reset(!1)}),[u]),n.useEffect((function(){var e=l.listen("range-updated",(function(){p(l.get())}));return function(){e()}}),[]);var S=n.useCallback((function(e){l.set(e)}),[]),P=n.useMemo((function(){return!!h&&(d?h[0]!==m||h[1]!==E:l.hasChanged())}),[h,m,E]);return n.useEffect((function(){if(d&&a.current!==u&&!l.getFrozen()){if(!o||(null==o?void 0:o.isEmpty()))return b(h?h[0]:f[0]),w(h?h[1]:f[1]),void(c.current=!1);var e=l.getField(),n=o.getAggregates(),i=o.getAggregateFilters(),r=0,s=0,g=(n||{})[e]||{},v=(i||{})[e]||{};t.isNullOrUndefined(v.min)?t.isNullOrUndefined(g.min)||(r=g.min):r=v.min,t.isNullOrUndefined(v.max)?t.isNullOrUndefined(g.max)||(s=g.max):s=v.max;var m=l.format([r,s]);s=m[1],b(r=m[0]),w(s),l.setMin(r),l.setMax(s),l.set([r,s],!1),p([r,s]),a.current=u}else a.current=u}),[JSON.stringify(null==o?void 0:o.getResults())]),{min:m,max:E,step:l.getStep(),setRange:S,range:h,reset:function(){l.reset()},showReset:P}},exports.useResultsPerPage=function(){var e=V().search,i=e.search,r=e.config.resultsPerPageParam,s=e.variables,o=n.useCallback((function(e){var t;s.set(((t={})[r]=e,t)),i()}),[s,i]),u=parseInt(s.get()[r],10);return{resultsPerPage:t.isNumber(u)?u:15,setResultsPerPage:o}},exports.useSearch=function(e){return"object"==typeof e&&"pipeline"in e&&"variables"in e?(i=(t=e).pipeline,r=t.variables,u=(s=n.useState(!1))[0],a=s[1],l=n.useCallback((function(e){var t;a(!0),""===e?i.clearResponse(r.get()):(e&&r.set(((t={})[c.qParam]=e,t)),i.search(r.get()))}),[i,r]),f=(d=n.useState({search:l,error:null,redirects:{},activePromotions:[],featureScoreWeight:0,banners:[]}))[0],g=d[1],n.useEffect((function(){return l(),i.listen("response-updated",(function(e){a(!1),g((function(t){var n,i,r,s;return o({},t,{results:null==e?void 0:e.getResults(),latency:null==e?void 0:e.getTime(),totalResults:null==e?void 0:e.getTotalResults(),error:null==e?void 0:e.getError(),redirects:null!=(n=e.getRedirects())?n:{},activePromotions:null!=(i=e.getActivePromotions())?i:[],featureScoreWeight:null!=(r=e.getFeatureScoreWeight())?r:0,banners:null!=(s=e.getBanners())?s:[],queryId:e.getQueryId()})}))}))}),[]),n.useEffect((function(){return r.listen("values-changed",(function(){l()}))}),[]),o({},f,{searching:u})):function(e){var t,i,r,s=e.queryOverride,o=e.allowEmptySearch,u=void 0===o||o,a=n.useState(null),c=a[0],l=a[1],d=V(),f=d.search,g=f.searching,h=f.response,p=f.search,v=d.autocomplete,m=v.search,y=v.suggestions,b=v.redirects,k=null==h?void 0:h.getResults(),E=n.useCallback((function(e){return m(e)}),[]);return n.useEffect((function(){void 0!==s?(u||""!==s)&&p(s):p()}),[s]),n.useEffect((function(){var e,t;if(h)switch(!0){case h.isError():l(null!=(e=null==(t=h.getError())?void 0:t.error)?e:new Error("Something went wrong. Please try again."));break;case!h.isError():l(null)}}),[h]),{latency:null==h?void 0:h.getTime(),totalResults:null==h?void 0:h.getTotalResults(),suggestions:null!=y?y:[],redirects:b,activePromotions:null!=(t=null==h?void 0:h.getActivePromotions())?t:[],featureScoreWeight:null!=(i=null==h?void 0:h.getFeatureScoreWeight())?i:0,results:k,search:p,searchInstant:E,searching:g,error:c,banners:null!=(r=null==h?void 0:h.getBanners())?r:[],queryId:null==h?void 0:h.getQueryId()}}(null!=e?e:{});var t,i,r,s,u,a,l,d,f,g},exports.useSearchContext=function(){var e,n,i,r,s,o=V().search,u=o.config,a=o.response,c=o.search,l=o.searching,d=o.fields,f=void 0===d?{}:d,g=o.clear,h=o.resetFilters,p=W("search"),v=p.page,m=p.resultsPerPage,y=p.totalResults,b=p.pageCount,k=p.setPage,E=(r=null==a?void 0:a.getResponse(),s={},r&&r.forEach((function(e,t){"string"!=typeof e&&"number"!=typeof e||(s[t]=e)})),s),w=null==a?void 0:a.getResults();return{empty:null!=(e=null==a?void 0:a.isEmpty())&&e,error:null==a?void 0:a.getError(),queryValues:null==a?void 0:a.getQueryValues(),latency:null==a?void 0:a.getTime(),page:v,resultsPerPage:m,totalResults:y,pageCount:b,setPage:k,search:c,results:w,response:E,searching:l,searched:!t.isNullOrUndefined(w),fields:f,config:u,clear:g,resetFilters:h,activePromotions:null!=(n=null==a?void 0:a.getActivePromotions())?n:[],banners:null!=(i=null==a?void 0:a.getBanners())?i:[]}},exports.useSorting=function(){var e,t=V().search,i=t.search,r=t.variables,s=n.useCallback((function(e,t){void 0===t&&(t=!0),r.set({sort:e}),t&&i()}),[r,i]);return{sorting:null!=(e=r.get().sort)?e:"",setSorting:s}},exports.useTracking=function(){var e=V(),t=e.resultClicked,n=e.search.pipeline;return{consumeInteractionToken:n.getClient().interactionConsume,handleResultClicked:t,posNegLocalStorageManager:n.getTracking().posNegLocalStorageManager}},exports.useVariables=function(){return{variables:V().search.variables}};
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@sajari/react-sdk-utils"),n=require("react"),i=e(n),r=require("@sajari/sdk-js"),s=e(require("js-cookie"));function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var a,c={qParam:"q",qOverrideParam:"q.override",qSuggestionsParam:"q.suggestions",resultsPerPageParam:"resultsPerPage",pageParam:"page",maxSuggestions:10,fieldsParam:"fields"},l=function(){function e(){this.listeners=void 0,this.listeners=[]}var t=e.prototype;return t.listen=function(e){var t=this;return this.listeners.push(e),function(){return t.unlisten(e)}},t.unlisten=function(e){var t=this.listeners.indexOf(e);t>=0&&this.listeners.splice(t,1)},t.notify=function(e){this.listeners.forEach((function(t){try{e(t)}catch(e){console&&console.error&&console.error(e)}}))},e}(),d=["page-close-analytics","body-reset-analytics","result-clicked-analytics"],f=function(){function e(e,n){var i,r=this;this.enabled=void 0,this.body=void 0,this.pipeline=void 0,this.tracking=void 0,this.listeners=void 0,this.longestNonAutocompletedBody=void 0,this.longestAutocompletedBody=void 0,this.bodyLabel=void 0,this.bodyAutocompletedLabel=void 0,this.beforeunload=function(){r.enabled&&r.body&&(r.listeners.get("page-close-analytics").notify((function(e){e(r.body)})),r.enabled=!1)},this.resetBody=function(){r.enabled&&(r.listeners.get("body-reset-analytics").notify((function(e){e(r.body)})),r.longestNonAutocompletedBody="",r.longestAutocompletedBody="",r.enabled=!1)},this.responseUpdated=function(e){if(!e.isEmpty()&&!e.isError()){r.enabled=!0;var t=e.getQueryValues().get(r.bodyLabel)||"",n=e.getValues().get(r.bodyAutocompletedLabel)||t;r.body=n,t.length>=r.longestNonAutocompletedBody.length&&(r.longestNonAutocompletedBody=t,r.longestAutocompletedBody=n)}},this.resultClicked=function(){r.enabled&&r.body&&(r.listeners.get("result-clicked-analytics").notify((function(e){e(r.body)})),r.longestNonAutocompletedBody="",r.longestAutocompletedBody="",r.enabled=!1)},this.enabled=!1,this.body="",this.pipeline=e,this.tracking=n,this.listeners=new Map(Object.entries(((i={})["page-close-analytics"]=new l,i["body-reset-analytics"]=new l,i["result-clicked-analytics"]=new l,i))),this.longestNonAutocompletedBody="",this.longestAutocompletedBody="",this.bodyLabel="q",this.bodyAutocompletedLabel="q",t.isSSR()||window.addEventListener("beforeunload",this.beforeunload),this.pipeline.listen("response-updated",this.responseUpdated),this.pipeline.listen("result-clicked",this.resultClicked),this.tracking.listen("tracking-reset",this.resetBody)}return e.prototype.listen=function(e,t){if(-1===d.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},e}();!function(e){e.UniversalAnalytics="_ua",e.AnalyticsJS="ga",e.GTag="gtag"}(a||(a={}));var g={decodeUriArgs:function(e){var t={},n=e.split("&");for(var i in n)if(n.hasOwnProperty(i)){var r=n[i].split("=");t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t},encodeUriArgs:function(e){var t=[];return Object.keys(e).forEach((function(n){return t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]))})),t.join("&")},mergeQueryStr:function(e){for(var t=this,n="string"==typeof e?this.decodeUriArgs(e):e,i=arguments.length,r=new Array(i>1?i-1:0),s=1;s<i;s++)r[s-1]=arguments[s];return r.forEach((function(e){var i="string"==typeof e?t.decodeUriArgs(e):e;Object.keys(i).forEach((function(e){n[e]=i[e]}))})),this.encodeUriArgs(n)},augmentUri:function(e,t){var n=/^([^?]+)\?(.+)+$/.exec(e);return n?n[1]+"?"+this.mergeQueryStr(n[2],t):e+"?"+this.encodeUriArgs(t)},getURLParameter:function(e){var t=new RegExp("[?|&]"+e+"=([^&;]+?)(&|#|;|$)").exec(window.location.search)||[void 0,""];return decodeURIComponent(t[1].replace(/\+/g,"%20"))||null}},h=function(){function e(e,n,i){var r=this;void 0===i&&(i="q"),this.id=void 0,this.param=void 0,this.unregisterFunctions=[],this.detatch=function(){return r.unregisterFunctions.forEach((function(e){return e()}))},this.onBodyReset=function(e){return r.sendGAPageView(e)},this.onResultClicked=function(e){return r.sendGAPageView(e)},this.onPageClose=function(e){return r.sendGAPageView(e)},this.unregisterFunctions.push(e.listen("page-close-analytics",this.onPageClose)),this.unregisterFunctions.push(e.listen("body-reset-analytics",this.onBodyReset)),this.unregisterFunctions.push(e.listen("result-clicked-analytics",this.onResultClicked)),this.id=t.isSSR()?null:void 0!==n?n:t.isFunction(window[a.AnalyticsJS])?a.AnalyticsJS:t.isFunction(window[a.UniversalAnalytics])?a.UniversalAnalytics:t.isFunction(window[a.GTag])?a.GTag:null,this.param=i}return e.prototype.sendGAPageView=function(e){if(this.id&&!t.isSSR()&&t.isFunction(window[this.id])){var n,i=g.augmentUri(window.location.href.substring(window.location.origin.length),((n={})[this.param]=e,n));this.id===a.GTag?window[this.id]("event","page_view",{page_location:i}):window[this.id]("send","pageview",i)}},e}(),p=["selection-updated","options-updated"],v=function(){function e(e){var n,i=e.initial,r=void 0===i?[]:i,s=e.joinOperator,o=void 0===s?"OR":s,u=e.multi,a=void 0===u||u,c=e.options,d=void 0===c?{}:c,f=e.array,g=void 0!==f&&f,h=e.name,p=e.field,v=e.group,m=e.count,y=void 0===m?t.isEmpty(d):m;this.current=void 0,this.initial=void 0,this.name=void 0,this.group=void 0,this.field=void 0,this.options=void 0,this.multi=void 0,this.count=void 0,this.array=void 0,this.joinOperator=void 0,this.listeners=void 0,t.isString(r)&&(r=[r]),this.current=r,this.initial=r,this.name=h,this.group=v,this.field=p,this.count=y,this.options=d,this.multi=a,this.array=g,this.joinOperator=o,this.listeners=((n={})["selection-updated"]=new l,n["options-updated"]=new l,n)}var n=e.prototype;return n.listen=function(e,t){if(!p.includes(e))throw new Error('Unknown event type "'+e+'"');return this.listeners[e].listen(t)},n.set=function(e,t){var n=this;if(void 0===t&&(t=!1),t){var i=e.filter((function(e){return!n.current.includes(e)}));this.current=[].concat(this.current,i)}else this.current=e;this.emitSelectionUpdated()},n.remove=function(e){this.current=this.current.filter((function(t){return!e.includes(t)})),this.emitSelectionUpdated()},n.isSet=function(e){return this.current.includes(e)},n.setOptions=function(e,t){void 0===t&&(t=!1),this.options=t?o({},this.options,e):e,this.emitOptionsUpdated()},n.getName=function(){return this.name},n.getGroup=function(){return this.group},n.getField=function(){return this.field},n.getCount=function(){return this.count},n.getOptions=function(){return this.options},n.get=function(){return this.current},n.isArray=function(){return this.array},n.isMulti=function(){return this.multi},n.hasChanged=function(){return!t.arraysEqual(this.current,this.initial,!1)},n.filter=function(){var e=this,n=this.current.map((function(n){var i=e.options[n];return t.isFunction(i)&&(i=i()),t.isEmpty(i)||(i=function(e){void 0===e&&(e="");var n=e;return[","].forEach((function(i){n=t.replaceAll(e,i,"\\"+i)})),n}(i)),e.count&&void 0===i&&n&&(i=e.array?e.field+' ~ ["'+n+'"]':e.field+' = "'+n+'"'),i})).filter(Boolean);return n.length<2?n.join(""):n.map((function(e){return"("+e+")"})).join(" "+this.joinOperator+" ")},n.getBuckets=function(){var e=this;return Object.entries(this.options).map((function(t){return e.name+"_"+t[0]+":"+t[1]})).join(",")},n.reset=function(e){void 0===e&&(e=!0),t.arraysEqual(this.current,this.initial)||(this.current=[].concat(this.initial),e&&this.emitSelectionUpdated())},n.emitSelectionUpdated=function(){this.listeners["selection-updated"].notify((function(e){e()}))},n.emitOptionsUpdated=function(){this.listeners["options-updated"].notify((function(e){e()}))},e}(),m=["range-updated"],y=function(){function e(e){var n,i=e.field,r=e.name,s=e.group,o=e.aggregate,u=void 0===o||o,a=e.initial,c=e.min,d=void 0===c?0:c,f=e.max,g=void 0===f?u?0:100:f,h=e.step,p=void 0===h?1:h,v=e.formatter,m=void 0===v?function(e){return e.map((function(e){return t.roundToStep(e,p)}))}:v;this.initial=void 0,this.range=void 0,this.name=void 0,this.group=void 0,this.field=void 0,this.min=void 0,this.max=void 0,this.step=void 0,this.frozen=void 0,this.aggregate=void 0,this.listeners=void 0,this.formatter=void 0,this.initial=void 0===a?u?null:[d,g]:a,this.range=this.initial,this.name=r,this.group=s,this.field=i,this.formatter=m,this.min=d,this.max=g,this.step=p,this.frozen=!1,this.aggregate=u,this.listeners=((n={})["range-updated"]=new l,n)}var n=e.prototype;return n.listen=function(e,t){if(!m.includes(e))throw new Error('Unknown event type "'+e+'"');return this.listeners[e].listen(t)},n.get=function(){return this.range},n.set=function(e,t){void 0===t&&(t=!0),this.frozen||(this.range=e?this.formatter(e):e,t&&this.emitRangeUpdated())},n.getName=function(){return this.name},n.getGroup=function(){return this.group},n.getField=function(){return this.field},n.getFrozen=function(){return this.frozen},n.setMin=function(e){this.frozen||(this.min=e)},n.setMax=function(e){this.frozen||(this.max=e)},n.getMinMax=function(){return[this.min,this.max]},n.getStep=function(){return this.step},n.filter=function(){var e=this.getMinMax();return!this.range||this.range[0]===e[0]&&this.range[1]===e[1]?"":this.field+" >= "+this.range[0]+" AND "+this.field+" <= "+this.range[1]},n.isAggregate=function(){return this.aggregate},n.setFrozen=function(e){this.frozen=e},n.hasChanged=function(){return this.range&&this.initial?this.range[0]!==this.initial[0]||this.range[1]!==this.initial[1]:this.range===this.initial},n.reset=function(e){void 0===e&&(e=!0),this.frozen||this.initial===this.range||t.arraysEqual(this.initial||[],this.range||[])||(this.range=t.isArray(this.initial)?[].concat(this.initial):this.initial,e&&this.emitRangeUpdated())},n.format=function(e){return this.formatter(e)},n.emitRangeUpdated=function(){var e=this;this.listeners["range-updated"].notify((function(t){t(e)}))},e}(),b=function(e){var n=e.filter(Boolean);return n.length>1&&(n=n.map((function(e){return"("+e+")"}))),t.isEmptyArray(n)?"":"ARRAY_MATCH("+n.join(" AND ")+")"};function k(e,n,i){var r=e.map((function(e){return{group:e.getGroup(),field:e.getField(),expression:e.filter(),count:e instanceof v&&e.getCount()}}));"filter"===n&&(r=r.filter((function(e){return Boolean(e.expression)})));var s=Object.entries(t.groupBy(r,"group")).filter((function(e){return Boolean(e[0])})).reduce((function(e,t){var n;return o({},e,((n={})[t[0]]=t[1].map((function(e){return e.expression})),n))}),{});if("filter"===n){var u,a=r.filter((function(e){return!e.group&&!e.count})).map((function(e){return"("+e.expression+")"}));return(u=Object.entries(s).reduce((function(e,n){var i=n[1];return"undefined"===n[0]||t.isEmpty(i)?e:[].concat(e,[b(i)])}),[])).concat.apply(u,a).join(i)}return r.filter((function(e){var n=e.count;return!t.isEmpty(e.field)&&n})).map((function(e){var n=e.group,i=e.expression,r=e.count;return n&&!t.isEmpty(s[n])?b(s[n]):r?i:null})).filter((function(e){return null!==e})).join(i)}var E=["selection-updated","options-updated","range-updated"];function w(e,t){var n;void 0===t&&(t="AND");var i=((n={})["selection-updated"]=new l,n["options-updated"]=new l,n["range-updated"]=new l,n),r=[];return e.forEach((function(e){e instanceof v&&r.push(e.listen("selection-updated",(function(){i["selection-updated"].notify((function(t){t(e)}))})),e.listen("options-updated",(function(){i["options-updated"].notify((function(t){t(e)}))}))),e instanceof y&&r.push(e.listen("range-updated",(function(){i["range-updated"].notify((function(t){t(e)}))})))})),{filter:function(){return k(e,"filter"," "+t+" ")},listen:function(e,t){if(-1===E.indexOf(e))throw new Error('Unknown event type "'+e+'"');return i[e].listen(t)},buckets:function(){return e.filter((function(e){return e instanceof v&&!e.getCount()})).map((function(e){return e instanceof v&&e.getBuckets()})).filter(Boolean).join(",")},countFilters:function(){return k(e,"countFilters",",")},count:function(){return e.filter((function(e){return e instanceof v&&e.getCount()})).map((function(e){return e instanceof v&&e.getField()})).filter(Boolean).join(",")},removeChildFilterListeners:function(){r.forEach((function(e){return e()}))},max:function(){return e.filter((function(e){return e instanceof y&&e.isAggregate()})).map((function(e){return e.getField()})).join(",")},min:function(){return e.filter((function(e){return e instanceof y&&e.isAggregate()})).map((function(e){return e.getField()})).join(",")}}}var S=function(){function e(e,t,n,i){this.error=void 0,this.queryValues=void 0,this.response=void 0,this.values=void 0,this.error=e,this.queryValues=t,this.response=n,this.values=i}var t=e.prototype;return t.isEmpty=function(){return null===this.error&&void 0===this.response&&void 0===this.values&&void 0===this.queryValues},t.isError=function(){return null!==this.error},t.getError=function(){return this.error},t.getQueryValues=function(){return this.queryValues},t.getResponse=function(){return this.response},t.getValues=function(){return this.values},t.getResults=function(){var e;return null==(e=this.response)?void 0:e.get("results")},t.getRedirects=function(){var e;return null==(e=this.response)?void 0:e.get("redirects")},t.getActivePromotions=function(){var e;return null==(e=this.response)?void 0:e.get("activePromotions")},t.getTotalResults=function(){var e;return null==(e=this.response)?void 0:e.get("totalResults")},t.getTime=function(){var e;return null==(e=this.response)?void 0:e.get("time")},t.getQueryId=function(){var e;return null==(e=this.response)?void 0:e.get("queryId")},t.getAggregates=function(){var e;return null==(e=this.response)?void 0:e.get("aggregates")},t.getAggregateFilters=function(){var e;return null==(e=this.response)?void 0:e.get("aggregateFilters")},t.getFeatureScoreWeight=function(){var e;return null==(e=this.response)?void 0:e.get("featureScoreWeight")},t.getBanners=function(){var e;return null==(e=this.response)?void 0:e.get("banners")},e}(),P=["tracking-reset"],R=function(){function e(e){var t;this.field=void 0,this.clientTracking=null,this.posNegLocalStorageManager=void 0,this.listeners=void 0,this.client=void 0,this.handleResultClicked=void 0,this.field=e,this.listeners=new Map(Object.entries(((t={})["tracking-reset"]=new l,t)))}var n=e.prototype;return n.bootstrap=function(e,t){var n,i;this.client=null!=(n=this.client)?n:e,this.handleResultClicked=t,this.posNegLocalStorageManager=null!=(i=this.posNegLocalStorageManager)?i:new r.PosNegLocalStorageManager(this.client)},n.listen=function(e,t){if(-1===P.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},n.emitTrackingReset=function(e){this.listeners.get("tracking-reset").notify((function(t){t(e)}))},n.reset=function(e){this.clientTracking.reset(),void 0!==e&&this.emitTrackingReset(e)},n.next=function(e){if(null===this.clientTracking)throw new Error("clientTracking is null");return this.clientTracking.next(e)},n.getMetadata=function(){var e=this.next({}).data;return t.isEmptyObject(e)?void 0:e},n.onQueryResponse=function(e){},n.onResultClick=function(e,t){},n.onPromotionClick=function(e){},n.onRedirect=function(e){},n.getResultHref=function(e,t){return e.url},e}(),A=function(){var e={},t=s.get("_ga");t&&(e.ga=t);var n=s.get("sjID");return n&&(e.sjID=n),e},x=function(e){function n(t,n,i){var s;return void 0===t&&(t="url"),void 0===n&&(n="q"),void 0===i&&(i={}),(s=e.call(this,t)||this).clientTracking=new r.InteractiveSession(n,new r.DefaultSession(r.TrackingType.Click,s.field,o({},A(),i))),s}u(n,e);var i=n.prototype;return i.extractValues=function(e,n){var i=n&&"click"in n?n.click:void 0,r=!t.isEmpty(i)&&Object.keys(e).includes(this.field)&&t.isValidURL(e[this.field]);return{useToken:r,clickToken:i,href:r?i:e.url}},i.onResultClick=function(e,n){var i,r=this.extractValues(e,n),s=r.useToken,o=r.clickToken;o&&this.handleResultClicked({token:o,values:e}),!s&&t.isString(o)&&t.isFunction(null==(i=navigator)?void 0:i.sendBeacon)&&navigator.sendBeacon(o)},i.getResultHref=function(e,t){return this.extractValues(e,t).href},n}(R),O=function(e){function t(t,n,i){var s;return void 0===t&&(t="_id"),void 0===n&&(n={}),(s=e.call(this,t)||this).searchIOAnalyticsEndpoint=void 0,s.searchIOAnalytics=void 0,s.searchIOAnalyticsEndpoint=i,s.clientTracking=new r.DefaultSession(r.TrackingType.Event,s.field,o({},A(),n)),s}u(t,e);var n=t.prototype;return n.bootstrap=function(t,n){var i;e.prototype.bootstrap.call(this,t,n),this.searchIOAnalytics=null!=(i=this.searchIOAnalytics)?i:new r.SearchIOAnalytics(t.project,t.collection,this.searchIOAnalyticsEndpoint)},n.onQueryResponse=function(e){var t=e.getQueryId();t&&this.searchIOAnalytics.updateQueryId(t)},n.onResultClick=function(e){Object.keys(e).includes(this.field)&&this.searchIOAnalytics.track("click",e[this.field],this.getMetadata()),this.handleResultClicked({values:e})},n.onPromotionClick=function(e){var t=e.id;t&&this.searchIOAnalytics.track("promotion_click",t,this.getMetadata())},n.onRedirect=function(e){this.searchIOAnalytics.track("redirect",e.id,this.getMetadata())},t}(R),C=function(e){function t(){var t;return(t=e.call(this,"_id")||this).clientTracking=new r.DefaultSession(r.TrackingType.None,t.field,A()),t}return u(t,e),t}(R),T=function(e){function t(t,n){var i;return void 0===t&&(t="url"),void 0===n&&(n={}),(i=e.call(this,t)||this).clientTracking=new r.DefaultSession(r.TrackingType.PosNeg,i.field,o({},A(),n)),i}u(t,e);var n=t.prototype;return n.bootstrap=function(t,n){e.prototype.bootstrap.call(this,t,n)},n.onResultClick=function(e,t){t&&"pos"in t&&(this.handleResultClicked({token:t.pos,values:e}),Object.keys(e).includes(this.field)&&this.posNegLocalStorageManager.add(e[this.field],t))},t}(R),N=["search-sent","response-updated","result-clicked"],U=function(){function e(e,n,i,s){var o=this;void 0===i&&(i=new C),void 0===s&&(s=[h]),this.config=void 0,this.pipeline=void 0,this.client=void 0,this.tracking=void 0,this.listeners=void 0,this.searchCount=void 0,this.response=new S(null),this.analytics=void 0,this.emitResultClicked=function(e){o.listeners.get("result-clicked").notify((function(t){t(e)}))};var u=e.account,a=e.collection,c=e.endpoint,d=e.key,g=e.secret;this.config=e;var p={name:void 0,version:void 0};t.isString(n)?p.name=n:"name"in n&&(p.name=n.name,p.version=n.version);var v={};t.isNullOrUndefined(e.userAgent)||(v.userAgent=e.userAgent),t.isNullOrUndefined(e.clickTokenURL)||(v.clickTokenURL=e.clickTokenURL),this.client=t.isSSR()?new r.Client(u,a,c,d,g,v):new r.Client(u,a,c,void 0,void 0,v),this.pipeline=this.client.pipeline(p.name,p.version),this.tracking=i,this.listeners=new Map([["search-sent",new l],["response-updated",new l],["result-clicked",new l]]),this.searchCount=0,this.response=new S(null),this.analytics=new f(this,this.tracking),s.forEach((function(e){new e(o.analytics)})),this.tracking.bootstrap(this.client,this.emitResultClicked)}var n=e.prototype;return n.listen=function(e,t){if(-1===N.indexOf(e))throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},n._emitSearchSent=function(e){this.listeners.get("search-sent").notify((function(t){t(e)}))},n._emitResponseUpdated=function(e){this.listeners.get("response-updated").notify((function(t){t(e)}))},n.search=function(e){var t=this;this.searchCount+=1;var n=this.searchCount;this.pipeline.search(e,this.tracking.next(e)).then((function(i){var r=i[0],s=i[1];n<t.searchCount||(t.response=new S(null,new Map(Object.entries(e)),new Map(Object.entries(r)),new Map(Object.entries(s))),t.tracking.onQueryResponse(t.response))})).catch((function(i){console.error(i),n<t.searchCount||(t.response=new S(i,new Map(Object.entries(e)),void 0,void 0))})).finally((function(){t._emitResponseUpdated(t.response)})),this._emitSearchSent(e)},n.clearResponse=function(e){this.tracking.next(e),this.searchCount+=1,this.response=new S(null),this._emitResponseUpdated(this.response)},n.getResponse=function(){return this.response},n.getAnalytics=function(){return this.analytics},n.getClient=function(){return this.client},n.getTracking=function(){return this.tracking},e}(),j=function(){function e(e){var t;void 0===e&&(e={}),this.variables=void 0,this.listeners=void 0,this.listeners=new Map([["values-changed",new l]]),this.variables=new Map(Object.entries(o(((t={})[c.qParam]="",t[c.resultsPerPageParam]=15,t[c.fieldsParam]="",t),e)))}var t=e.prototype;return t.listen=function(e,t){if("values-changed"!==e)throw new Error('Unknown event type "'+e+'"');return this.listeners.get(e).listen(t)},t.set=function(e){this._set(e),this._emitUpdated(e)},t.get=function(){var e={};return this.variables.forEach((function(t,n){e[n]="function"==typeof t?t():Array.isArray(t)?t.join(","):String(t)})),e},t._emitUpdated=function(e){var t=this;this.listeners.get("values-changed").notify((function(n){return n(e,(function(e){return t._set(e)}))}))},t._set=function(e){var t=this;Object.keys(e).forEach((function(n){void 0===e[n]?t.variables.delete(n):t.variables.set(n,e[n])}))},e}(),_=function(e,t,n){var i=t.getValues(),r=e&&i&&i.get(n.qParam)||"",s=[];return i&&(s=(i.get(n.qSuggestionsParam)||"").split(",").filter((function(e){return e.length>0})).slice(0,n.maxSuggestions)),{completion:r,query:e,suggestions:s}},F=function(e,t,n){var i=t.config,r=t.config.qParam,s=t.redirects,u=e.get()[r]||"",a=_(u,n,i);return a.redirects=o({},s,n.getRedirects()),a},q=function(e,t,n){var i=e.get()[n.config.qParam]||"";return _(i,t.getResponse(),n.config)},M=t.createContext({strict:!0,name:"PipelineContext"}),I=M[0],V=M[1],B={response:null,query:"",completion:"",suggestions:[],config:c,redirects:{}},L=/\d+\s-\s\d+/gm,D=L.test.bind(L),Q=new Intl.Collator(t.isSSR()?"en-US":window.navigator.language,{numeric:!0}),G=function(e,t){return function(n,i){var r=i[0],s=i[1],o=String(e?n[0]:n[1]),u=String(e?r:s);switch(!0){case[o,u].every(D):var a=o.split(" - ").map(Number)[0],c=u.split(" - ").map(Number)[0];return t?Q.compare(String(a),String(c)):Q.compare(String(c),String(a));case o.startsWith(">"):case u.startsWith("<"):return t?1:-1;case o.startsWith("<"):case u.startsWith(">"):return t?-1:1}return t?Q.compare(String(o),String(u)):Q.compare(String(u),String(o))}};function W(e){void 0===e&&(e="search");var t=V(),i=t.paginate,r=t[e],s=r.response,o=r.config,u=null==s?void 0:s.getQueryValues(),a=(null==u?void 0:u.get(o.pageParam))?parseInt(u.get(o.pageParam),10):1,c=(null==u?void 0:u.get(o.resultsPerPageParam))?parseInt(null==u?void 0:u.get(o.resultsPerPageParam),10):15,l=(null==s?void 0:s.getTotalResults())||0,d=Math.ceil(l/c),f=n.useMemo((function(){return a<d}),[a,d]),g=n.useMemo((function(){return a>1}),[a]),h=n.useCallback((function(){return f&&i(a+1)}),[i,f]),p=n.useCallback((function(){return g&&i(a-1)}),[i,g]);return{page:a,pageCount:d,totalResults:l,setPage:i,resultsPerPage:c,hasNext:f,hasPrevious:g,nextPage:h,previousPage:p}}Object.defineProperty(exports,"PosNegLocalStorageManager",{enumerable:!0,get:function(){return r.PosNegLocalStorageManager}}),Object.defineProperty(exports,"SearchIOAnalytics",{enumerable:!0,get:function(){return r.SearchIOAnalytics}}),exports.ClickTracking=x,exports.EVENT_ANALYTICS_BODY_RESET="body-reset-analytics",exports.EVENT_ANALYTICS_PAGE_CLOSED="page-close-analytics",exports.EVENT_ANALYTICS_RESULT_CLICKED="result-clicked-analytics",exports.EVENT_OPTIONS_UPDATED="options-updated",exports.EVENT_RANGE_UPDATED="range-updated",exports.EVENT_RESPONSE_UPDATED="response-updated",exports.EVENT_RESULT_CLICKED="result-clicked",exports.EVENT_SEARCH_SENT="search-sent",exports.EVENT_SELECTION_UPDATED="selection-updated",exports.EVENT_TRACKING_RESET="tracking-reset",exports.EVENT_VALUES_UPDATED="values-changed",exports.EventTracking=O,exports.FieldDictionary=function(e){this.id=void 0,this.url=void 0,this.title=void 0,this.subtitle=void 0,this.description=void 0,this.image=void 0,this.createdAt=void 0,this.price=void 0,this.originalPrice=void 0,this.salePrice=void 0,this.rating=void 0,this.quantity=void 0;var t=null!=e?e:{},n=t.id,i=t.url,r=void 0===i?"url":i,s=t.title,o=void 0===s?"title":s,u=t.subtitle,a=void 0===u?"url":u,c=t.description,l=void 0===c?"description":c,d=t.image,f=void 0===d?"image":d,g=t.price,h=void 0===g?"price":g,p=t.originalPrice,v=void 0===p?"originalPrice":p,m=t.salePrice,y=void 0===m?"salePrice":m,b=t.rating,k=void 0===b?"rating":b,E=t.quantity,w=void 0===E?"quantity":E,S=t.createdAt,P=void 0===S?"created_at":S;this.id=void 0===n?"_id":n,this.url=r,this.title=o,this.subtitle=a,this.description=l,this.image=f,this.price=h,this.originalPrice=v,this.salePrice=y,this.rating=k,this.quantity=w,this.createdAt=P},exports.FilterBuilder=v,exports.NoTracking=C,exports.Pipeline=U,exports.PosNegTracking=T,exports.RangeFilterBuilder=y,exports.Response=S,exports.SearchProvider=function(e){var r,s,u=e.children,a=e.search,l=e.autocomplete,d=e.defaultFilter,f=e.searchOnLoad,g=function(e){if(!t.isString(e)||t.isEmpty(e))return null;var n=JSON.parse(e),i=n.queryValues,r=n.response,s=void 0===r?{}:r,o=n.values,u=void 0===o?{}:o;return new S(null,new Map(Object.entries(void 0===i?{}:i)),new Map(Object.entries(s)),new Map(Object.entries(u)))}(e.initialResponse),h=n.useState(!1),p=h[0],v=h[1],m=n.useState(!1),y=m[0],b=m[1],k=n.useState(o({},B,{response:g})),E=k[0],P=k[1],R=n.useState(B),A=R[0],x=R[1],O=n.useState(!1),C=O[0],T=O[1],N=n.useRef(),_=n.useRef(),M=n.useRef(l),V=n.useRef(null!=(r=a.variables)?r:new j),L=n.useRef(null!=(s=null==l?void 0:l.variables)?s:new j),D=a.pipeline.getResponse();if(D.isEmpty()&&null!==g&&(D=g),a.variables||C||Object.assign(a,{variables:V.current}),!l||l.variables||C||Object.assign(l,{variables:L.current}),!C){var Q,G,W,z=w(null!=(Q=a.filters)?Q:[]),J=null!=(G=V.current.get().filter)?G:"",Y=null!=(W=null==d?void 0:d.toString())?W:"";V.current.set({filter:function(){var e=z.filter();return[Y,J,t.isEmpty(e)?'_id != ""':e].filter(Boolean).join(" AND ")},countFilters:function(){return z.countFilters()},buckets:function(){return z.buckets()},count:function(){return z.count()},min:function(){return z.min()},max:function(){return z.max()}})}var H=n.useCallback((function(e){return function(t,n){var i;void 0===n&&(n=!1);var r="autocomplete"===e?M.current:a,s="autocomplete"===e?A:E,u="autocomplete"===e?_:N;("autocomplete"===e?b:v)(!0),P((function(e){return o({},e,{query:null!=t?t:e.query})}));var c=r.pipeline,l=r.variables,d=s.config,f=((i={})[d.qParam]=null!=t?t:l.get()[d.qParam],i[d.qOverrideParam]=void 0,i[d.pageParam]=void 0,i);n&&(f[d.qOverrideParam]="true"),l.set(f),u.current&&clearTimeout(u.current),u.current=setTimeout((function(){c.search(l.get())}),50)}}),[A.config,E.config]);n.useEffect((function(){var e=o({},c,a.config);P((function(t){return o({},t,{response:D,query:V.current.get()[e.qParam]||"",config:e})})),x((function(e){return o({},e,{config:o({},c,a.config)})}));var t,n=[];if(a.filters){var i=w(a.filters);n.push(i.listen("selection-updated",(function(){return H("search")()})),i.listen("range-updated",(function(){return H("search")()})),i.removeChildFilterListeners)}if(n.push(a.pipeline.listen("response-updated",(function(e){var n;clearTimeout(t),t=setTimeout((function(){v(!1),P((function(t){return o({},t,{response:e},F(V.current,t,e))}))}),0===(null==(n=e.getResults())?void 0:n.length)?500:20)}))),n.push(V.current.listen("values-changed",(function(){return P((function(e){return o({},e,q(V.current,a.pipeline,e))}))}))),!M.current){var r=a.pipeline.config;M.current={pipeline:new U({account:r.account,collection:r.collection,endpoint:r.endpoint},"autocomplete",a.pipeline.getTracking()),variables:L.current}}return n.push(M.current.pipeline.listen("response-updated",(function(e){b(!1),x((function(t){return o({},t,{response:e},F(L.current,t,e))}))}))),n.push(L.current.listen("values-changed",(function(){return x((function(e){return o({},e,q(L.current,M.current.pipeline,e))}))}))),f&&a.pipeline.search(V.current.get()),T(!0),function(){n.forEach((function(e){return e()}))}}),[]);var K,$,X,Z=n.useCallback((function(e){return function(t){var n="autocomplete"===e?M.current:a,i=n.pipeline,r=n.variables;void 0!==t&&r.set(t),i.clearResponse(r.get())}}),[]),ee=n.useCallback((function(e){var t,n=a.pipeline,i=a.variables;i.set(((t={})[E.config.pageParam]=String(e),t)),v(!0),n.search(i.get())}),[a.pipeline,a.variables,E.config]),te=function(e){var t;void 0===e&&(e=!0),null==(t=a.filters)||t.forEach((function(t){return null==t?void 0:t.reset(e)}))};return i.createElement(I,{value:(K={autocomplete:A,search:E},o({},K,{search:o({},K.search,{variables:V.current,filters:a.filters,pipeline:a.pipeline,search:H("search"),clear:Z("search"),resetFilters:te,fields:a.fields,searching:p}),autocomplete:o({},K.autocomplete,{variables:L.current,filters:a.filters,pipeline:null==($=M.current)?void 0:$.pipeline,search:H("autocomplete"),clear:Z("autocomplete"),resetFilters:te,fields:null==(X=M.current)?void 0:X.fields,searching:y}),resultClicked:a.pipeline.emitResultClicked,paginate:ee}))},u)},exports.Tracking=R,exports.Variables=j,exports.combineFilters=w,exports.useAutocomplete=function(){var e=V().autocomplete;return{suggestions:e.suggestions,search:e.search,completion:e.completion,searching:e.searching,redirects:e.redirects}},exports.useFilter=function(e,i){void 0===i&&(i={});var r=V().search,s=r.filters,o=void 0===s?[]:s,u=r.response,a=n.useMemo((function(){return o.filter((function(t){return t instanceof v&&t.getName()===e}))[0]}),[]);if(!a)throw new Error('Filter "'+e+"\" doesn't exist.");var c=n.useState(a.get()),l=c[0],d=c[1];n.useEffect((function(){var e=a.listen("selection-updated",(function(){d(a.get())}));return function(){e()}}),[]);var f=i.sort,g=void 0===f?"alpha":f,h=i.sortAscending,p=void 0===h?"count"!==g:h,m=i.includes,y=i.excludes,b=i.prefixFilter,k=n.useMemo((function(){return a.hasChanged()}),[l]);return{options:n.useMemo((function(){if(!u||(null==u?void 0:u.isEmpty()))return[];var n=u.getAggregates(),i=u.getAggregateFilters(),r=a.getCount(),s=a.getField();if(r&&s){var o=a.isArray(),c={};if(!(c=((i||{})[s]||{}).count)){var l=((n||{})[s]||{}).count;c=void 0===l?{}:l}var d=function(e,t,n){if(void 0===t&&(t="alpha"),void 0===n&&(n=!0),"none"===t)return e;var i="count"!==t;return e.sort((function(e,t){var r=e.label,s=e.count,o=t.label,u=t.count;return G(i,n)([r,s],[o,u])}))}(function(e,t){var n=t.excludes,i=t.includes,r=t.prefixFilter;if(!i&&!n&&!r)return e.map((function(e){var t=e[0];return{value:t,count:Number(e[1]),label:t}}));for(var s=[],o=0;o<e.length;o++){var u=e[o],a=u[0],c=u[1];(!n||!n.includes(a))&&(!i||i.includes(a))&&s.push({value:a,count:Number(c),label:a})}return r&&(s=s.filter((function(e){return e.value.startsWith(r)})).map((function(e){var t=e.value,n=e.count;return{label:t.replace(r,""),count:n,value:t}}))),s}(Object.entries(c),{includes:m,excludes:y,prefixFilter:b}),g,p).map((function(e){var t=e.value;return{label:e.label,count:e.count,value:o?s+' ~ ["'+t+'"]':s+' = "'+t+'"'}})),f={};return d.forEach((function(e){f[e.label]=e.value})),a.setOptions(f),d}return function(e,t,n){return void 0===t&&(t="alpha"),void 0===n&&(n=!0),"none"===t?e:e.sort(G("count"!==t,n))}(Object.entries(a.getOptions()),g,p).map((function(n){var i=n[0];return{label:i,value:n[1],count:function(e,n){var i,r,s,o,u;if(!e||(null==e?void 0:e.isEmpty()))return null;var a=0,c=e.getAggregates(),l=e.getAggregateFilters();return l&&Object.keys(null!=(i=null==(r=l.buckets)?void 0:r.count)?i:{}).includes(n)?a=l.buckets.count:c&&Object.keys(null!=(s=null==(o=c.buckets)?void 0:o.count)?s:{}).includes(n)&&(a=c.buckets.count),t.isNumber(a)?0:null!=(u=a[n])?u:0}(u,e+"_"+i)}}))}),[JSON.stringify(null==u?void 0:u.getResults())]),setSelected:function(e,t){void 0===t&&(t=!1),a.set(e,t)},selected:l,reset:function(){a.reset()},showReset:k,multi:a.isMulti()}},exports.usePagination=W,exports.useQuery=function(){var e=V().search,t=e.search,i=e.variables,r=e.config;return{query:e.query,setQuery:n.useCallback((function(e){var n;i.set(((n={})[r.qParam]=e,n)),t(e)}),[t,i])}},exports.useRangeFilter=function(e){var i=V().search,r=i.filters,s=void 0===r?[]:r,o=i.response,u=i.query,a=n.useRef(null),c=n.useRef(!1),l=n.useMemo((function(){return s.filter((function(t){return t instanceof y&&t.getName()===e}))[0]}),[]),d=l.isAggregate(),f=l.getMinMax();if(!l)throw new Error('Filter "'+e+"\" doesn't exist.");var g=n.useState(l.get()),h=g[0],p=g[1],v=n.useState(f[0]),m=v[0],b=v[1],k=n.useState(f[1]),E=k[0],w=k[1];n.useEffect((function(){d&&null!==a.current&&l.reset(!1)}),[u]),n.useEffect((function(){var e=l.listen("range-updated",(function(){p(l.get())}));return function(){e()}}),[]);var S=n.useCallback((function(e){l.set(e)}),[]),P=n.useMemo((function(){return!!h&&(d?h[0]!==m||h[1]!==E:l.hasChanged())}),[h,m,E]);return n.useEffect((function(){if(d&&a.current!==u&&!l.getFrozen()){if(!o||(null==o?void 0:o.isEmpty()))return b(h?h[0]:f[0]),w(h?h[1]:f[1]),void(c.current=!1);var e=l.getField(),n=o.getAggregates(),i=o.getAggregateFilters(),r=0,s=0,g=(n||{})[e]||{},v=(i||{})[e]||{};t.isNullOrUndefined(v.min)?t.isNullOrUndefined(g.min)||(r=g.min):r=v.min,t.isNullOrUndefined(v.max)?t.isNullOrUndefined(g.max)||(s=g.max):s=v.max;var m=l.format([r,s]);s=m[1],b(r=m[0]),w(s),l.setMin(r),l.setMax(s),l.set([r,s],!1),p([r,s]),a.current=u}else a.current=u}),[JSON.stringify(null==o?void 0:o.getResults())]),{min:m,max:E,step:l.getStep(),setRange:S,range:h,reset:function(){l.reset()},showReset:P}},exports.useResultsPerPage=function(){var e=V().search,i=e.search,r=e.config.resultsPerPageParam,s=e.variables,o=n.useCallback((function(e){var t;s.set(((t={})[r]=e,t)),i()}),[s,i]),u=parseInt(s.get()[r],10);return{resultsPerPage:t.isNumber(u)?u:15,setResultsPerPage:o}},exports.useSearch=function(e){return"object"==typeof e&&"pipeline"in e&&"variables"in e?(i=(t=e).pipeline,r=t.variables,u=(s=n.useState(!1))[0],a=s[1],l=n.useCallback((function(e){var t;a(!0),""===e?i.clearResponse(r.get()):(e&&r.set(((t={})[c.qParam]=e,t)),i.search(r.get()))}),[i,r]),f=(d=n.useState({search:l,error:null,redirects:{},activePromotions:[],featureScoreWeight:0,banners:[]}))[0],g=d[1],n.useEffect((function(){return l(),i.listen("response-updated",(function(e){a(!1),g((function(t){var n,i,r,s;return o({},t,{results:null==e?void 0:e.getResults(),latency:null==e?void 0:e.getTime(),totalResults:null==e?void 0:e.getTotalResults(),error:null==e?void 0:e.getError(),redirects:null!=(n=e.getRedirects())?n:{},activePromotions:null!=(i=e.getActivePromotions())?i:[],featureScoreWeight:null!=(r=e.getFeatureScoreWeight())?r:0,banners:null!=(s=e.getBanners())?s:[],queryId:e.getQueryId()})}))}))}),[]),n.useEffect((function(){return r.listen("values-changed",(function(){l()}))}),[]),o({},f,{searching:u})):function(e){var t,i,r,s=e.queryOverride,o=e.allowEmptySearch,u=void 0===o||o,a=n.useState(null),c=a[0],l=a[1],d=V(),f=d.search,g=f.searching,h=f.response,p=f.search,v=d.autocomplete,m=v.search,y=v.suggestions,b=v.redirects,k=null==h?void 0:h.getResults(),E=n.useCallback((function(e){return m(e)}),[]);return n.useEffect((function(){void 0!==s?(u||""!==s)&&p(s):p()}),[s]),n.useEffect((function(){var e,t;if(h)switch(!0){case h.isError():l(null!=(e=null==(t=h.getError())?void 0:t.error)?e:new Error("Something went wrong. Please try again."));break;case!h.isError():l(null)}}),[h]),{latency:null==h?void 0:h.getTime(),totalResults:null==h?void 0:h.getTotalResults(),suggestions:null!=y?y:[],redirects:b,activePromotions:null!=(t=null==h?void 0:h.getActivePromotions())?t:[],featureScoreWeight:null!=(i=null==h?void 0:h.getFeatureScoreWeight())?i:0,results:k,search:p,searchInstant:E,searching:g,error:c,banners:null!=(r=null==h?void 0:h.getBanners())?r:[],queryId:null==h?void 0:h.getQueryId()}}(null!=e?e:{});var t,i,r,s,u,a,l,d,f,g},exports.useSearchContext=function(){var e,n,i,r,s,o=V().search,u=o.config,a=o.response,c=o.search,l=o.searching,d=o.fields,f=void 0===d?{}:d,g=o.clear,h=o.resetFilters,p=W("search"),v=p.page,m=p.resultsPerPage,y=p.totalResults,b=p.pageCount,k=p.setPage,E=(r=null==a?void 0:a.getResponse(),s={},r&&r.forEach((function(e,t){"string"!=typeof e&&"number"!=typeof e||(s[t]=e)})),s),w=null==a?void 0:a.getResults();return{empty:null!=(e=null==a?void 0:a.isEmpty())&&e,error:null==a?void 0:a.getError(),queryValues:null==a?void 0:a.getQueryValues(),latency:null==a?void 0:a.getTime(),page:v,resultsPerPage:m,totalResults:y,pageCount:b,setPage:k,search:c,results:w,response:E,searching:l,searched:!t.isNullOrUndefined(w),fields:f,config:u,clear:g,resetFilters:h,activePromotions:null!=(n=null==a?void 0:a.getActivePromotions())?n:[],banners:null!=(i=null==a?void 0:a.getBanners())?i:[]}},exports.useSorting=function(){var e,t=V().search,i=t.search,r=t.variables,s=n.useCallback((function(e,t){void 0===t&&(t=!0),r.set({sort:e}),t&&i()}),[r,i]);return{sorting:null!=(e=r.get().sort)?e:"",setSorting:s}},exports.useTracking=function(){var e=V(),t=e.resultClicked,n=e.search.pipeline;return{consumeInteractionToken:n.getClient().interactionConsume,handleResultClicked:t,tracking:n.getTracking(),posNegLocalStorageManager:n.getTracking().posNegLocalStorageManager}},exports.useVariables=function(){return{variables:V().search.variables}};
//# sourceMappingURL=react-hooks.cjs.production.min.js.map

@@ -11,2 +11,3 @@ import { useContext } from '../ContextProvider/index.esm.js';

handleResultClicked: resultClicked,
tracking: pipeline.getTracking(),
posNegLocalStorageManager: pipeline.getTracking().posNegLocalStorageManager

@@ -13,0 +14,0 @@ };

import { PosNegLocalStorageManager } from '@sajari/sdk-js';
import { Tracking } from '../ContextProvider';
import { ResultClickedFn } from '../ContextProvider/types';

@@ -6,3 +7,4 @@ export interface UseTrackingResult {

consumeInteractionToken: (token: string, identifier: string, weight: number, data?: Record<string, string>) => Promise<void>;
tracking: Tracking;
posNegLocalStorageManager: PosNegLocalStorageManager;
}
{
"name": "@sajari/react-hooks",
"version": "3.10.1",
"version": "3.11.0",
"description": "Easy to use hooks that allow you to build a powerful search interface powered by Sajari using any component library.",

@@ -5,0 +5,0 @@ "sideEffects": false,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc