Socket
Socket
Sign inDemoInstall

@sajari/sdk-js

Package Overview
Dependencies
0
Maintainers
8
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.10.3 to 2.10.4

dist/util.d.ts

41

dist/index.d.ts
import EventEmitter from "./events";
export { EventEmitter };
import { RequestError, setItem, getItem } from "./util";
export { EventEmitter, RequestError, setItem, getItem };
export { SearchIOAnalytics } from "./tracking";

@@ -11,10 +12,2 @@ /**

}
/**
* RequestError defines an error occuring from a request.
*/
export declare class RequestError extends Error {
readonly statusCode: number;
readonly error?: Error | undefined;
constructor(statusCode: number, message: string, error?: Error | undefined);
}
declare type ConfigObj = {

@@ -24,3 +17,3 @@ /**

* returned by the engine.
* @deprecated
* @deprecated See [[SearchIOAnalytics]] for new tracking APIs.
*/

@@ -82,3 +75,3 @@ clickTokenURL: string;

* ```
* @deprecated
* @deprecated in favor of [[SearchIOAnalytics]] tracking APIs.
*/

@@ -320,3 +313,3 @@ interactionConsume(token: string, identifier: string, weight: number, data?: Record<string, string>): Promise<void>;

* token is the [[Token]] associated with this [[Result]] (if any).
* @deprecated
* @deprecated the modern tracking API, [[SearchIOAnalytics]], does not require tracking tokens
*/

@@ -330,3 +323,3 @@ token?: Token;

/**
* @deprecated
* @deprecated the modern tracking API, [[SearchIOAnalytics]], does not require tracking tokens
*/

@@ -336,3 +329,3 @@ export declare type Token = ClickToken | PosNegToken;

* ClickToken defines a click token. See [[TrackingType.Click]] for more details.
* @deprecated
* @deprecated the modern tracking API, [[SearchIOAnalytics]], does not require tracking tokens
*/

@@ -344,3 +337,3 @@ export declare type ClickToken = {

* PosNegToken defines a pos/neg token pair. See [[TrackingType.PosNeg]] for more details.
* @deprecated
* @deprecated the modern tracking API, [[SearchIOAnalytics]], does not require tracking tokens
*/

@@ -496,3 +489,3 @@ export declare type PosNegToken = {

* Tracking defines behaviour for handling search sessions and result interactions.
* @deprecated
* @deprecated See [[SearchIOAnalytics]] for new tracking APIs.
*/

@@ -516,3 +509,3 @@ export declare type Tracking = {

* Click generates click tracking tokens.
* @deprecated
* @deprecated Use EVENT for new tracking APIs
*/

@@ -522,3 +515,3 @@ Click = "CLICK",

* PosNeg creates pos/neg tracking tokens.
* @deprecated
* @deprecated Use EVENT for new tracking APIs
*/

@@ -534,3 +527,3 @@ PosNeg = "POS_NEG",

* to be sent with search requests.
* @deprecated
* @deprecated The modern tracking API ,[[SearchIOAnalytics]], does not tracking search 'sessions'
*/

@@ -551,3 +544,3 @@ export interface Session {

* DefaultSession holds state of a sequence of searches.
* @deprecated
* @deprecated Use [[SearchIOAnalytics]] which does not attempt to track search sequences in the client.
*/

@@ -573,3 +566,3 @@ export declare class DefaultSession extends EventEmitter implements Session {

* - Cleared after being non-empty (i.e. from a delete)
* @deprecated
* @deprecated The new API, [[SearchIOAnalytics]], does not track search 'sessions' in the client.
*/

@@ -611,3 +604,3 @@ export declare class InteractiveSession implements Session {

/**
* @deprecated
* @deprecated See [[SearchIOAnalytics]] for new tracking identifier information
*/

@@ -619,4 +612,2 @@ export declare type TokenState = {

export declare const POS_NEG_STORAGE_KEY = "sajari_tokens";
export declare const setItem: (key: string, value: string) => void;
export declare const getItem: (key: string) => string | null;
/**

@@ -626,3 +617,3 @@ * PosNegLocalStorageManager is a utility class for manipulating Sajari's localstorage based

* as users move through an ecommerce purchase funnel.
* @deprecated
* @deprecated See [[SearchIOAnalytics]] for new tracking APIs.
*/

@@ -629,0 +620,0 @@ export declare class PosNegLocalStorageManager {

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

"use strict";function t(t,e,r,n,o,i,s){try{var a=t[i](s),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function e(e){return function(){var r=this,n=arguments;return new Promise((function(o,i){var s=e.apply(r,n);function a(e){t(s,o,i,a,c,"next",e)}function c(e){t(s,o,i,a,c,"throw",e)}a(void 0)}))}}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,i(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function a(t,e,r){return(a=s()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&i(o,r.prototype),o}).apply(null,arguments)}function c(t){var e="function"==typeof Map?new Map:void 0;return(c=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return a(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,t)})(t)}function u(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}Object.defineProperty(exports,"__esModule",{value:!0});var h,f,l=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",s=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new b(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var s=r.delegate;if(s){var a=E(s,r);if(a){if(a===h)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=u(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,i),o}function u(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var h={};function f(){}function l(){}function p(){}var v={};a(v,o,(function(){return this}));var d=Object.getPrototypeOf,y=d&&d(d(O([])));y&&y!==e&&r.call(y,o)&&(v=y);var g=p.prototype=f.prototype=Object.create(v);function m(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){var n;this._invoke=function(o,i){function s(){return new e((function(n,s){!function n(o,i,s,a){var c=u(t[o],t,i);if("throw"!==c.type){var h=c.arg,f=h.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,s,a)}),(function(t){n("throw",t,s,a)})):e.resolve(f).then((function(t){h.value=t,s(h)}),(function(t){return n("throw",t,s,a)}))}a(c.arg)}(o,i,n,s)}))}return n=n?n.then(s,s):s()}}function E(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=u(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function w(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function b(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function O(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:T}}function T(){return{value:void 0,done:!0}}return l.prototype=p,a(g,"constructor",p),a(p,"constructor",l),l.displayName=a(p,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,s,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(k.prototype),a(k.prototype,i,(function(){return this})),t.AsyncIterator=k,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var s=new k(c(e,r,n,o),i);return t.isGeneratorFunction(r)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},m(g),a(g,s,"Generator"),a(g,o,(function(){return this})),a(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=O,b.prototype={constructor:b,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return s.type="throw",s.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=t,s.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(f={exports:{}}),f.exports),p=function(){return"undefined"==typeof window},v=p()?null:null==(h=document.currentScript)?void 0:h.src,d="";v?d="(via "+new URL(v).host+")":p()&&(d="(SSR)");var y,g=["sajari-sdk-js/2.10.3",d].filter(Boolean).join(" "),m=function(){function t(){this.events={}}var e=t.prototype;return e.emit=function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this.events["*"]&&this.events["*"].forEach((function(e){return e.apply(void 0,[t].concat(r))})),this.events[t]&&this.events[t].forEach((function(t){return t.apply(void 0,r)}))},e.on=function(t,e){var r=this;return this.events[t]||(this.events[t]=[]),this.events[t].push(e),function(){r.events[t]=r.events[t].filter((function(t){return t!==e}))}},t}(),k=["click","redirect","promotion_click"],E=function(){function t(t,e,r){var n=this;void 0===r&&(r="https://api.search.io"),this.account=t,this.collection=e,this.endpoint=r;var o=G("searchio_events");try{this.events=o?JSON.parse(o):{}}catch(t){this.events={},console.error("Search.io event local storage key contains corrupt data.",o)}this.flush().then((function(){return n.purge()}))}var n=t.prototype;return n.add=function(t,e,r,n){var o=this.getEvents(r);o.push({queryId:t,type:e,metadata:n,timestamp:Date.now(),submitted:!1}),this.setEvents(r,o),this.save(),this.flush()},n.save=function(){D("searchio_events",JSON.stringify(this.events))},n.getIdentifierForType=function(t){switch(t){case"redirect":return"redirect_id";case"promotion_click":return"banner_id";default:return"result_id"}},n.flush=function(){var t=this,e=[];return Object.keys(this.events).forEach((function(n){t.events[n].forEach((function(o,i){var s,a=o.type,c=o.metadata;o.submitted||e.push(t.sendEvent(o.queryId,a,r((s={},s[t.getIdentifierForType(a)]=n,s),c&&{metadata:c})).then((function(){t.events[n][i].submitted=!0,t.save()})).catch((function(){console.error("Search.io event failed to send.",t.events[n][i])})))}))})),Promise.all(e).catch((function(){}))},n.sendEvent=function(){var t=e(l.mark((function t(e,n,o){var i,s,a;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(this.endpoint+"/v4/collections/"+this.collection+":trackEvent",{method:"POST",headers:{Accept:"application/json","Content-Type":"text/plain","Account-Id":this.account},body:JSON.stringify(r({query_id:e,type:n},o))});case 2:if((i=t.sent).ok){t.next=17;break}return s=i.statusText,t.prev=5,t.next=8,i.json();case 8:(a=t.sent).message&&(s=a.message),t.next=14;break;case 12:t.prev=12,t.t0=t.catch(5);case 14:if(403!==i.status){t.next=16;break}throw new b(i.status,"This domain is not authorized to make this request.",new Error(s));case 16:throw new b(i.status,"Request failed due to a configuration error.",new Error(s));case 17:return t.abrupt("return",i.json());case 18:case"end":return t.stop()}}),t,this,[[5,12]])})));return function(e,r,n){return t.apply(this,arguments)}}(),n.getExpiry=function(){return Date.now()-2592e6},n.purge=function(){var t=this,e=this.getExpiry(),r=!1;Object.keys(this.events).forEach((function(n){var o=t.events[n].filter((function(t){return!t.submitted||t.timestamp>e}));o.length<t.events[n].length&&(t.setEvents(n,o),r=!0)})),r&&this.save()},n.getEvents=function(t){return(this.events[t]||[]).slice()},n.setEvents=function(t,e){e.length?this.events[t]=e:delete this.events[t]},n.updateQueryId=function(t){this.queryId=t},n.track=function(t,e,r){var n=this.queryId;if(!k.includes(t)){var o=this.getEvents(e).pop();o&&(n=o.queryId)}n?this.trackForQuery(n,t,e,r):console.error("No queryId found. Use updateQueryId to set the current queryId or call trackForQuery with a specific queryId.")},n.trackForQuery=function(t,e,r,n){this.add(t,e,r,n)},t}(),w=["queryID"],x=function(t){function e(e){var r;return(r=t.call(this,e)||this).type="CONNECTION",r}return n(e,t),e}(c(Error)),b=function(t){function e(r,n,o){var i;return(i=t.call(this,n)||this).statusCode=r,i.error=o,Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(i),e.prototype),i}return n(e,t),e}(c(Error)),O={clickTokenURL:"https://re.sajari.com/token/",userAgent:""},T=function(){function t(t,e,r,n,o,i){if(void 0===r&&(r=(p()?"https:":"")+"//jsonapi.sajari.net"),this.userAgent="",!p()&&[n,o].some(Boolean))throw new Error("key/secret authorization is only supported for server-side rendering.");this.project=t,this.collection=e,this.endpoint=r,this.key=n,this.secret=o,this.config=Object.assign(O,i),this.interactionConsume=this.interactionConsume.bind(this)}var r=t.prototype;return r.call=function(){var t=e(l.mark((function t(e,r,n){var o,i,s,a,c;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p()||navigator.onLine){t.next=2;break}throw new x("Search request failed due to a network error. Please check your network connection.");case 2:return o={project:[this.project],collection:[this.collection],"user-agent":[[g,this.userAgent,this.config.userAgent].filter(Boolean).join(" ")]},p()&&[this.key,this.secret].every(Boolean)&&Object.assign(o,{authorization:["keysecret "+this.key+" "+this.secret]}),t.next=6,fetch(""+this.endpoint+e,{signal:n,method:"POST",headers:{Accept:"application/json","Content-Type":"text/plain"},body:JSON.stringify({metadata:o,request:r})});case 6:if(200===(i=t.sent).status){t.next=24;break}return a=i.statusText,t.prev=9,t.next=12,i.json();case 12:s=(c=t.sent).code,a=c.message,t.next=19;break;case 17:t.prev=17,t.t0=t.catch(9);case 19:if(403!==i.status){t.next=22;break}throw console.error("Check the domain "+window.location.hostname+" is an authorized query domain. See https://app.search.io/collection/domains"),new b(i.status,"Search request failed due to a permission denied error.",new Error(a));case 22:throw console.error("Search request failed due to an error. HTTP code: "+i.status+", Code: "+s+", Message: "+a),new b(i.status,"Search request failed due to an error.",new Error(a));case 24:return t.next=26,i.json();case 26:return t.abrupt("return",t.sent);case 27:case"end":return t.stop()}}),t,this,[[9,17]])})));return function(e,r,n){return t.apply(this,arguments)}}(),r.pipeline=function(t,e){return new S(this,t,e)},r.interactionConsume=function(){var t=e(l.mark((function t(e,r,n,o){return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===o&&(o={}),t.abrupt("return",this.call("/sajari.interaction.v2.Interaction/ConsumeToken",{token:e,identifier:r,weight:n,data:o}));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n,o){return t.apply(this,arguments)}}(),t}();(y=exports.PipelineType||(exports.PipelineType={}))[y.Query=1]="Query",y[y.Record=2]="Record";var _,j,S=function(t){function o(e,r,n){var o;return(o=t.call(this)||this).client=e,o.identifier={name:r,version:n},o}return n(o,t),o.prototype.search=function(){var t=e(l.mark((function t(e,n){var o,i,s,a,c,h,f,p,v,d,y,g,m=this;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o={type:exports.TrackingType.None},void 0!==n&&(i=n.queryID,s=u(n,w),o=r({query_id:i},s)),this.emit("search-sent",e),t.next=5,this.client.call("/sajari.api.pipeline.v1.Query/Search",{pipeline:this.identifier,tracking:o,values:e});case 5:return c=(a=t.sent).searchResponse,h=a.redirects,f=a.tokens,v=a.banners,d=a.queryId,y=I(p=a.activePromotions),g=((null==c?void 0:c.results)||[]).map((function(t,e){var n=t.indexScore,o=t.score,i=t.values,s=t.neuralScore,a=t.featureScore,c=void 0,u=(f||[])[e];void 0!==u&&("click"in u?c={click:m.client.config.clickTokenURL+u.click.token}:"pos"in u?c=r({},u):"posNeg"in u&&(c={pos:u.posNeg.pos,neg:u.posNeg.neg}));var h=!1;return Object.keys(y).length>0&&Object.entries(y).forEach((function(t){var e=t[1],r=q(i[t[0]]);e.has(r)&&(h=!0)})),r({indexScore:n},s&&{neuralScore:s},a&&{featureScore:a},{score:o,values:L(i),token:c,promotionPinned:h})})),t.abrupt("return",[r({time:parseFloat((null==c?void 0:c.time)||"0.0"),totalResults:parseInt((null==c?void 0:c.totalResults)||"0",10),banners:v,featureScoreWeight:(null==c?void 0:c.featureScoreWeight)||0,results:g,aggregates:N(null==c?void 0:c.aggregates),aggregateFilters:N(null==c?void 0:c.aggregateFilters),redirects:P(this.client.config.clickTokenURL,h),activePromotions:null!=p?p:[]},d&&{queryId:d}),a.values||{}]);case 10:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),o}(m);function I(t){void 0===t&&(t=[]);var e={};return t.forEach((function(t){t.activePins.forEach((function(t){var r=t.key;e[r.field]||(e[r.field]=new Set),e[r.field].add(r.value)}))})),e}function P(t,e){return void 0===e&&(e={}),Object.entries(e).reduce((function(e,r){var n=r[0];return e[n]=r[1],e[n].token=t+e[n].token,e}),{})}function N(t){return void 0===t&&(t={}),Object.entries(t).map((function(t){var e,r,n=t[0],o=t[1];if("metric"in o){var i=n.split(".");return{type:i[0],key:i[1],value:o.metric.value}}return"count"in o?{type:"count",key:n.replace(/^count./,""),value:o.count.counts}:"buckets"in o?{type:"count",key:"buckets",value:Object.values(null!=(e=null==(r=o.buckets)?void 0:r.buckets)?e:{}).reduce((function(t,e){var r;return Object.assign(t,((r={})[e.name]=e.count,r))}),{})}:{key:n,value:o}})).reduce((function(t,e){if(void 0===e.type)return console.debug(e),t;void 0===t[e.key]&&(t[e.key]={});var n=t[e.key][e.type];return"count"===e.type&&"buckets"===e.key&&"object"==typeof n&&"object"==typeof e.value?(n=r({},n,e.value),t[e.key][e.type]=n):t[e.key][e.type]=e.value,t}),{})}function L(t){var e={};return Object.keys(t).forEach((function(r){var n=q(t[r]);null!==n&&(e[r]=n)})),e}function q(t){return"single"in t?t.single:"repeated"in t?t.repeated.values:"singleBytes"in t?t.singleBytes:null}(_=exports.TextPosition||(exports.TextPosition={})).Unspecified="TEXT_POSITION_UNSPECIFIED",_.Center="TEXT_POSITION_CENTER",_.TopLeft="TEXT_POSITION_TOP_LEFT",_.TopRight="TEXT_POSITION_TOP_RIGHT",_.BottomLeft="TEXT_POSITION_BOTTOM_LEFT",_.BottomRight="TEXT_POSITION_BOTTOM_RIGHT",(j=exports.TrackingType||(exports.TrackingType={})).None="NONE",j.Click="CLICK",j.PosNeg="POS_NEG",j.Event="EVENT";var R=function(t){function e(e,r,n){var o;return(o=t.call(this)||this).queryID="",o.sequence=0,o.type=e,o.field=r,o.data=function(t){if("undefined"==typeof window)return{};var e=document.cookie.split(";").filter((function(t){return t.includes("_ga")||t.includes("sjID")})).map((function(t){return t.split("=")})).reduce((function(t,e){var r=e[0],n=e[1];return"_ga"===r?(t.ga=n,t):(t[r]=n,t)}),{});return void 0===t?e:(Object.entries(e).forEach((function(e){t[e[0]]=e[1]})),t)}(n),o}n(e,t);var r=e.prototype;return r.next=function(t){return""===this.queryID?(this.queryID=function(t){void 0===t&&(t=16);for(var e="",r=0;r<t;r++)e+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()));return e}(),this.sequence=0):this.sequence++,{type:this.type,queryID:this.queryID,sequence:this.sequence,field:this.field,data:this.data}},r.reset=function(){this.emit("tracking-reset"),this.queryID="",this.sequence=0},e}(m),C=function(){function t(t,e){this.textParam=t,this.session=e,this.lastQuery=""}var e=t.prototype;return e.next=function(t){var e=t[this.textParam];if(void 0===e)return this.reset(),this.session.next(t);var r=this.lastQuery.substr(0,Math.min(e.length,3));return(e.substr(0,r.length)!==r||this.lastQuery.length>0&&0===e.length)&&this.reset(),this.lastQuery=e,this.session.next(t)},e.reset=function(){this.session.reset()},t}(),A=function(t){function e(e,r,n,o){var i;return void 0===r&&(r=[]),void 0===n&&(n=!1),void 0===o&&(o="OR"),(i=t.call(this)||this).options=e,i.active=r,i.multi=n,i.joinOp=o,i}n(e,t);var o=e.prototype;return o.set=function(t,e){if(void 0===e&&(e=!0),this.multi)return this.active=e&&-1===this.active.indexOf(t)?this.active.concat(t):this.active.filter((function(e){return e!==t})),void this.emit("selection-updated",[].concat(this.active));this.active=e?[t]:[],this.emit("selection-updated",[].concat(this.active))},o.isActive=function(t){return-1!==this.active.indexOf(t)},o.get=function(){return[].concat(this.active)},o.updateOptions=function(t){var e=this;Object.keys(t).forEach((function(r){var n=t[r];if(void 0===n)return delete e.options[r],void(e.active=e.active.filter((function(t){return t!==r})));e.options[r]=n})),this.emit("options-updated",r({},this.options))},o.getOptions=function(){return r({},this.options)},o.filter=function(){var t=this,e=this.active.map((function(e){var r=t.options[e];return"function"==typeof r&&(r=r()),""!==r&&(r="("+r+")"),r})).filter(Boolean);switch(e.length){case 0:return"";case 1:return e[0];default:return e.join(" "+this.joinOp+" ")}},e}(m),F=function(t){function e(e){var r;return void 0===e&&(e={}),(r=t.call(this)||this).internal=e,r}n(e,t);var r=e.prototype;return r._internalUpdate=function(t){var e=this;Object.keys(t).forEach((function(r){var n=t[r];void 0===n?delete e.internal[r]:e.internal[r]=n}))},r.update=function(t){var e=this;this._internalUpdate(t),this.emit("values-changed",t,(function(t){return e._internalUpdate(t)}))},r.get=function(){var t={};return Object.entries(this.internal).forEach((function(e){var r=e[1];t[e[0]]="function"==typeof r?r():Array.isArray(r)?r.join(","):""+r})),t},e}(m),D=function(t,e){if(!p())try{localStorage.setItem(t,e)}catch(r){console.error('Search.io local storage "'+t+'" cannot be saved.',e)}},G=function(t){return p()?"":localStorage.getItem(t)},U=function(){function t(t){var e=G("sajari_tokens");try{this.currentTokens=e?JSON.parse(e):{}}catch(t){this.currentTokens={},console.error("Sajari PosNeg local storage key contains corrupt data.",e)}this.client=t}var e=t.prototype;return e.add=function(t,e){this.currentTokens[t]={token:e,clickSubmitted:!1},D("sajari_tokens",JSON.stringify(this.currentTokens))},e.get=function(t){return this.currentTokens[t]},e.sendPosEvent=function(t,e,r){var n=this.get(t);void 0!==n&&this.client.interactionConsume(n.token.pos,e,r)},e.sendClickEvent=function(t){var e=this.get(t);void 0!==e&&!1===e.clickSubmitted&&(this.sendPosEvent(t,"click",1),this.currentTokens[t].clickSubmitted=!0,D("sajari_tokens",JSON.stringify(this.currentTokens)))},e.sendPendingClicks=function(){var t=this;Object.keys(this.currentTokens).forEach((function(e){!1===t.currentTokens[e].clickSubmitted&&(t.sendClickEvent(e),t.currentTokens[e].clickSubmitted=!0)}))},t}();exports.Client=T,exports.DefaultSession=R,exports.EVENT_OPTIONS_UPDATED="options-updated",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.EventEmitter=m,exports.Filter=A,exports.InteractiveSession=C,exports.NetworkError=x,exports.POS_NEG_STORAGE_KEY="sajari_tokens",exports.PosNegLocalStorageManager=U,exports.RequestError=b,exports.SearchIOAnalytics=E,exports.Values=F,exports.formatAggregates=N,exports.getItem=G,exports.setItem=D;
"use strict";function t(t,e,r,n,o,i,s){try{var a=t[i](s),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function e(e){return function(){var r=this,n=arguments;return new Promise((function(o,i){var s=e.apply(r,n);function a(e){t(s,o,i,a,c,"next",e)}function c(e){t(s,o,i,a,c,"throw",e)}a(void 0)}))}}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function n(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,i(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function a(t,e,r){return(a=s()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&i(o,r.prototype),o}).apply(null,arguments)}function c(t){var e="function"==typeof Map?new Map:void 0;return(c=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return a(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,t)})(t)}function u(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}Object.defineProperty(exports,"__esModule",{value:!0});var h,f,l=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",s=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=Object.create((e&&e.prototype instanceof f?e:f).prototype),i=new b(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var s=r.delegate;if(s){var a=E(s,r);if(a){if(a===h)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=u(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,i),o}function u(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var h={};function f(){}function l(){}function p(){}var v={};a(v,o,(function(){return this}));var d=Object.getPrototypeOf,y=d&&d(d(O([])));y&&y!==e&&r.call(y,o)&&(v=y);var g=p.prototype=f.prototype=Object.create(v);function m(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){var n;this._invoke=function(o,i){function s(){return new e((function(n,s){!function n(o,i,s,a){var c=u(t[o],t,i);if("throw"!==c.type){var h=c.arg,f=h.value;return f&&"object"==typeof f&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,s,a)}),(function(t){n("throw",t,s,a)})):e.resolve(f).then((function(t){h.value=t,s(h)}),(function(t){return n("throw",t,s,a)}))}a(c.arg)}(o,i,n,s)}))}return n=n?n.then(s,s):s()}}function E(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return h;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=u(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,h;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function w(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function b(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function O(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:T}}function T(){return{value:void 0,done:!0}}return l.prototype=p,a(g,"constructor",p),a(p,"constructor",l),l.displayName=a(p,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,s,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(k.prototype),a(k.prototype,i,(function(){return this})),t.AsyncIterator=k,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var s=new k(c(e,r,n,o),i);return t.isGeneratorFunction(r)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},m(g),a(g,s,"Generator"),a(g,o,(function(){return this})),a(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=O,b.prototype={constructor:b,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return s.type="throw",s.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=t,s.arg=e,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(f={exports:{}}),f.exports),p=function(){return"undefined"==typeof window},v=p()?null:null==(h=document.currentScript)?void 0:h.src,d="";v?d="(via "+new URL(v).host+")":p()&&(d="(SSR)");var y,g=["sajari-sdk-js/2.10.4",d].filter(Boolean).join(" "),m=function(){function t(){this.events={}}var e=t.prototype;return e.emit=function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this.events["*"]&&this.events["*"].forEach((function(e){return e.apply(void 0,[t].concat(r))})),this.events[t]&&this.events[t].forEach((function(t){return t.apply(void 0,r)}))},e.on=function(t,e){var r=this;return this.events[t]||(this.events[t]=[]),this.events[t].push(e),function(){r.events[t]=r.events[t].filter((function(t){return t!==e}))}},t}(),k=function(t){function e(r,n,o){var i;return(i=t.call(this,n)||this).statusCode=r,i.error=o,Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(i),e.prototype),i}return n(e,t),e}(c(Error)),E=function(t,e){if(!p())try{localStorage.setItem(t,e)}catch(r){console.error('Search.io local storage "'+t+'" cannot be saved.',e)}},w=function(t){return p()?"":localStorage.getItem(t)},x=["click","redirect","promotion_click"],b=function(){function t(t,e,r){var n=this;void 0===r&&(r="https://api.search.io"),this.account=t,this.collection=e,this.endpoint=r;var o=w("searchio_events");try{this.events=o?JSON.parse(o):{}}catch(t){this.events={},console.error("Search.io event local storage key contains corrupt data.",o)}this.flush().then((function(){return n.purge()}))}var n=t.prototype;return n.add=function(t,e,r,n){var o=this.getEvents(r);o.push({queryId:t,type:e,metadata:n,timestamp:Date.now(),submitted:!1}),this.setEvents(r,o),this.save(),this.flush()},n.save=function(){E("searchio_events",JSON.stringify(this.events))},n.getIdentifierForType=function(t){switch(t){case"redirect":return"redirect_id";case"promotion_click":return"banner_id";default:return"result_id"}},n.flush=function(){var t=this,e=[];return Object.keys(this.events).forEach((function(n){t.events[n].forEach((function(o,i){var s,a=o.type,c=o.metadata;o.submitted||e.push(t.sendEvent(o.queryId,a,r((s={},s[t.getIdentifierForType(a)]=n,s),c&&{metadata:c})).then((function(){t.events[n][i].submitted=!0,t.save()})).catch((function(){console.error("Search.io event failed to send.",t.events[n][i])})))}))})),Promise.all(e).catch((function(){}))},n.sendEvent=function(){var t=e(l.mark((function t(e,n,o){var i,s,a;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(this.endpoint+"/v4/collections/"+this.collection+":trackEvent",{method:"POST",headers:{Accept:"application/json","Content-Type":"text/plain","Account-Id":this.account},body:JSON.stringify(r({query_id:e,type:n},o))});case 2:if((i=t.sent).ok){t.next=17;break}return s=i.statusText,t.prev=5,t.next=8,i.json();case 8:(a=t.sent).message&&(s=a.message),t.next=14;break;case 12:t.prev=12,t.t0=t.catch(5);case 14:if(403!==i.status){t.next=16;break}throw new k(i.status,"This domain is not authorized to make this request.",new Error(s));case 16:throw new k(i.status,"Request failed due to a configuration error.",new Error(s));case 17:return t.abrupt("return",i.json());case 18:case"end":return t.stop()}}),t,this,[[5,12]])})));return function(e,r,n){return t.apply(this,arguments)}}(),n.getExpiry=function(){return Date.now()-2592e6},n.purge=function(){var t=this,e=this.getExpiry(),r=!1;Object.keys(this.events).forEach((function(n){var o=t.events[n].filter((function(t){return!t.submitted||t.timestamp>e}));o.length<t.events[n].length&&(t.setEvents(n,o),r=!0)})),r&&this.save()},n.getEvents=function(t){return(this.events[t]||[]).slice()},n.setEvents=function(t,e){e.length?this.events[t]=e:delete this.events[t]},n.updateQueryId=function(t){this.queryId=t},n.track=function(t,e,r){var n=this.queryId;if(x.includes(t)){if(!n)return void console.error("No queryId found. Use updateQueryId to set the current queryId or call trackForQuery with a specific queryId.")}else{var o=this.getEvents(e).pop();o&&(n=o.queryId)}n&&this.trackForQuery(n,t,e,r)},n.trackForQuery=function(t,e,r,n){this.add(t,e,r,n)},t}(),O=["queryID"],T=function(t){function e(e){var r;return(r=t.call(this,e)||this).type="CONNECTION",r}return n(e,t),e}(c(Error)),_={clickTokenURL:"https://re.sajari.com/token/",userAgent:""},j=function(){function t(t,e,r,n,o,i){if(void 0===r&&(r=(p()?"https:":"")+"//jsonapi.sajari.net"),this.userAgent="",!p()&&[n,o].some(Boolean))throw new Error("key/secret authorization is only supported for server-side rendering.");this.project=t,this.collection=e,this.endpoint=r,this.key=n,this.secret=o,this.config=Object.assign(_,i),this.interactionConsume=this.interactionConsume.bind(this)}var r=t.prototype;return r.call=function(){var t=e(l.mark((function t(e,r,n){var o,i,s,a,c;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p()||navigator.onLine){t.next=2;break}throw new T("Search request failed due to a network error. Please check your network connection.");case 2:return o={project:[this.project],collection:[this.collection],"user-agent":[[g,this.userAgent,this.config.userAgent].filter(Boolean).join(" ")]},p()&&[this.key,this.secret].every(Boolean)&&Object.assign(o,{authorization:["keysecret "+this.key+" "+this.secret]}),t.next=6,fetch(""+this.endpoint+e,{signal:n,method:"POST",headers:{Accept:"application/json","Content-Type":"text/plain"},body:JSON.stringify({metadata:o,request:r})});case 6:if(200===(i=t.sent).status){t.next=24;break}return a=i.statusText,t.prev=9,t.next=12,i.json();case 12:s=(c=t.sent).code,a=c.message,t.next=19;break;case 17:t.prev=17,t.t0=t.catch(9);case 19:if(403!==i.status){t.next=22;break}throw console.error("Check the domain "+window.location.hostname+" is an authorized query domain. See https://app.search.io/collection/domains"),new k(i.status,"Search request failed due to a permission denied error.",new Error(a));case 22:throw console.error("Search request failed due to an error. HTTP code: "+i.status+", Code: "+s+", Message: "+a),new k(i.status,"Search request failed due to an error.",new Error(a));case 24:return t.next=26,i.json();case 26:return t.abrupt("return",t.sent);case 27:case"end":return t.stop()}}),t,this,[[9,17]])})));return function(e,r,n){return t.apply(this,arguments)}}(),r.pipeline=function(t,e){return new P(this,t,e)},r.interactionConsume=function(){var t=e(l.mark((function t(e,r,n,o){return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===o&&(o={}),t.abrupt("return",this.call("/sajari.interaction.v2.Interaction/ConsumeToken",{token:e,identifier:r,weight:n,data:o}));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r,n,o){return t.apply(this,arguments)}}(),t}();(y=exports.PipelineType||(exports.PipelineType={}))[y.Query=1]="Query",y[y.Record=2]="Record";var S,I,P=function(t){function o(e,r,n){var o;return(o=t.call(this)||this).client=e,o.identifier={name:r,version:n},o}return n(o,t),o.prototype.search=function(){var t=e(l.mark((function t(e,n){var o,i,s,a,c,h,f,p,v,d,y,g,m=this;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o={type:exports.TrackingType.None},void 0!==n&&(i=n.queryID,s=u(n,O),o=r({query_id:i},s)),this.emit("search-sent",e),t.next=5,this.client.call("/sajari.api.pipeline.v1.Query/Search",{pipeline:this.identifier,tracking:o,values:e});case 5:return c=(a=t.sent).searchResponse,h=a.redirects,f=a.tokens,v=a.banners,d=a.queryId,y=N(p=a.activePromotions),g=((null==c?void 0:c.results)||[]).map((function(t,e){var n=t.indexScore,o=t.score,i=t.values,s=t.neuralScore,a=t.featureScore,c=void 0,u=(f||[])[e];void 0!==u&&("click"in u?c={click:m.client.config.clickTokenURL+u.click.token}:"pos"in u?c=r({},u):"posNeg"in u&&(c={pos:u.posNeg.pos,neg:u.posNeg.neg}));var h=!1;return Object.keys(y).length>0&&Object.entries(y).forEach((function(t){var e=t[1],r=C(i[t[0]]);e.has(r)&&(h=!0)})),r({indexScore:n},s&&{neuralScore:s},a&&{featureScore:a},{score:o,values:R(i),token:c,promotionPinned:h})})),t.abrupt("return",[r({time:parseFloat((null==c?void 0:c.time)||"0.0"),totalResults:parseInt((null==c?void 0:c.totalResults)||"0",10),banners:v,featureScoreWeight:(null==c?void 0:c.featureScoreWeight)||0,results:g,aggregates:q(null==c?void 0:c.aggregates),aggregateFilters:q(null==c?void 0:c.aggregateFilters),redirects:L(this.client.config.clickTokenURL,h),activePromotions:null!=p?p:[]},d&&{queryId:d}),a.values||{}]);case 10:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),o}(m);function N(t){void 0===t&&(t=[]);var e={};return t.forEach((function(t){t.activePins.forEach((function(t){var r=t.key;e[r.field]||(e[r.field]=new Set),e[r.field].add(r.value)}))})),e}function L(t,e){return void 0===e&&(e={}),Object.entries(e).reduce((function(e,r){var n=r[0];return e[n]=r[1],e[n].token=t+e[n].token,e}),{})}function q(t){return void 0===t&&(t={}),Object.entries(t).map((function(t){var e,r,n=t[0],o=t[1];if("metric"in o){var i=n.split(".");return{type:i[0],key:i[1],value:o.metric.value}}return"count"in o?{type:"count",key:n.replace(/^count./,""),value:o.count.counts}:"buckets"in o?{type:"count",key:"buckets",value:Object.values(null!=(e=null==(r=o.buckets)?void 0:r.buckets)?e:{}).reduce((function(t,e){var r;return Object.assign(t,((r={})[e.name]=e.count,r))}),{})}:{key:n,value:o}})).reduce((function(t,e){if(void 0===e.type)return console.debug(e),t;void 0===t[e.key]&&(t[e.key]={});var n=t[e.key][e.type];return"count"===e.type&&"buckets"===e.key&&"object"==typeof n&&"object"==typeof e.value?(n=r({},n,e.value),t[e.key][e.type]=n):t[e.key][e.type]=e.value,t}),{})}function R(t){var e={};return Object.keys(t).forEach((function(r){var n=C(t[r]);null!==n&&(e[r]=n)})),e}function C(t){return"single"in t?t.single:"repeated"in t?t.repeated.values:"singleBytes"in t?t.singleBytes:null}(S=exports.TextPosition||(exports.TextPosition={})).Unspecified="TEXT_POSITION_UNSPECIFIED",S.Center="TEXT_POSITION_CENTER",S.TopLeft="TEXT_POSITION_TOP_LEFT",S.TopRight="TEXT_POSITION_TOP_RIGHT",S.BottomLeft="TEXT_POSITION_BOTTOM_LEFT",S.BottomRight="TEXT_POSITION_BOTTOM_RIGHT",(I=exports.TrackingType||(exports.TrackingType={})).None="NONE",I.Click="CLICK",I.PosNeg="POS_NEG",I.Event="EVENT";var A=function(t){function e(e,r,n){var o;return(o=t.call(this)||this).queryID="",o.sequence=0,o.type=e,o.field=r,o.data=function(t){if("undefined"==typeof window)return{};var e=document.cookie.split(";").filter((function(t){return t.includes("_ga")||t.includes("sjID")})).map((function(t){return t.split("=")})).reduce((function(t,e){var r=e[0],n=e[1];return"_ga"===r?(t.ga=n,t):(t[r]=n,t)}),{});return void 0===t?e:(Object.entries(e).forEach((function(e){t[e[0]]=e[1]})),t)}(n),o}n(e,t);var r=e.prototype;return r.next=function(t){return""===this.queryID?(this.queryID=function(t){void 0===t&&(t=16);for(var e="",r=0;r<t;r++)e+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()));return e}(),this.sequence=0):this.sequence++,{type:this.type,queryID:this.queryID,sequence:this.sequence,field:this.field,data:this.data}},r.reset=function(){this.emit("tracking-reset"),this.queryID="",this.sequence=0},e}(m),F=function(){function t(t,e){this.textParam=t,this.session=e,this.lastQuery=""}var e=t.prototype;return e.next=function(t){var e=t[this.textParam];if(void 0===e)return this.reset(),this.session.next(t);var r=this.lastQuery.substr(0,Math.min(e.length,3));return(e.substr(0,r.length)!==r||this.lastQuery.length>0&&0===e.length)&&this.reset(),this.lastQuery=e,this.session.next(t)},e.reset=function(){this.session.reset()},t}(),D=function(t){function e(e,r,n,o){var i;return void 0===r&&(r=[]),void 0===n&&(n=!1),void 0===o&&(o="OR"),(i=t.call(this)||this).options=e,i.active=r,i.multi=n,i.joinOp=o,i}n(e,t);var o=e.prototype;return o.set=function(t,e){if(void 0===e&&(e=!0),this.multi)return this.active=e&&-1===this.active.indexOf(t)?this.active.concat(t):this.active.filter((function(e){return e!==t})),void this.emit("selection-updated",[].concat(this.active));this.active=e?[t]:[],this.emit("selection-updated",[].concat(this.active))},o.isActive=function(t){return-1!==this.active.indexOf(t)},o.get=function(){return[].concat(this.active)},o.updateOptions=function(t){var e=this;Object.keys(t).forEach((function(r){var n=t[r];if(void 0===n)return delete e.options[r],void(e.active=e.active.filter((function(t){return t!==r})));e.options[r]=n})),this.emit("options-updated",r({},this.options))},o.getOptions=function(){return r({},this.options)},o.filter=function(){var t=this,e=this.active.map((function(e){var r=t.options[e];return"function"==typeof r&&(r=r()),""!==r&&(r="("+r+")"),r})).filter(Boolean);switch(e.length){case 0:return"";case 1:return e[0];default:return e.join(" "+this.joinOp+" ")}},e}(m),G=function(t){function e(e){var r;return void 0===e&&(e={}),(r=t.call(this)||this).internal=e,r}n(e,t);var r=e.prototype;return r._internalUpdate=function(t){var e=this;Object.keys(t).forEach((function(r){var n=t[r];void 0===n?delete e.internal[r]:e.internal[r]=n}))},r.update=function(t){var e=this;this._internalUpdate(t),this.emit("values-changed",t,(function(t){return e._internalUpdate(t)}))},r.get=function(){var t={};return Object.entries(this.internal).forEach((function(e){var r=e[1];t[e[0]]="function"==typeof r?r():Array.isArray(r)?r.join(","):""+r})),t},e}(m),U=function(){function t(t){var e=w("sajari_tokens");try{this.currentTokens=e?JSON.parse(e):{}}catch(t){this.currentTokens={},console.error("Sajari PosNeg local storage key contains corrupt data.",e)}this.client=t}var e=t.prototype;return e.add=function(t,e){this.currentTokens[t]={token:e,clickSubmitted:!1},E("sajari_tokens",JSON.stringify(this.currentTokens))},e.get=function(t){return this.currentTokens[t]},e.sendPosEvent=function(t,e,r){var n=this.get(t);void 0!==n&&this.client.interactionConsume(n.token.pos,e,r)},e.sendClickEvent=function(t){var e=this.get(t);void 0!==e&&!1===e.clickSubmitted&&(this.sendPosEvent(t,"click",1),this.currentTokens[t].clickSubmitted=!0,E("sajari_tokens",JSON.stringify(this.currentTokens)))},e.sendPendingClicks=function(){var t=this;Object.keys(this.currentTokens).forEach((function(e){!1===t.currentTokens[e].clickSubmitted&&(t.sendClickEvent(e),t.currentTokens[e].clickSubmitted=!0)}))},t}();exports.Client=j,exports.DefaultSession=A,exports.EVENT_OPTIONS_UPDATED="options-updated",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.EventEmitter=m,exports.Filter=D,exports.InteractiveSession=F,exports.NetworkError=T,exports.POS_NEG_STORAGE_KEY="sajari_tokens",exports.PosNegLocalStorageManager=U,exports.RequestError=k,exports.SearchIOAnalytics=b,exports.Values=G,exports.formatAggregates=q,exports.getItem=w,exports.setItem=E;
//# sourceMappingURL=sajarisdk.cjs.production.min.js.map

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).SajariSDK={})}(this,(function(t){"use strict";function e(t,e,n,r,i,o,a){try{var s=t[o](a),c=s.value}catch(t){return void n(t)}s.done?e(c):Promise.resolve(c).then(r,i)}function n(t){return function(){var n=this,r=arguments;return new Promise((function(i,o){var a=t.apply(n,r);function s(t){e(a,i,o,s,c,"next",t)}function c(t){e(a,i,o,s,c,"throw",t)}s(void 0)}))}}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,a(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function c(t,e,n){return(c=s()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var i=new(Function.bind.apply(t,r));return n&&a(i,n.prototype),i}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return c(t,arguments,o(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,t)})(t)}function f(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)e.indexOf(n=o[r])>=0||(i[n]=t[n]);return i}var h,l=function(t,e){return function(t){var e=function(t){var e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),o=new O(r||[]);return i._invoke=function(t,e,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return{value:void 0,done:!0}}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=E(a,n);if(s){if(s===f)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=u(t,e,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(t,n,o),i}function u(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f={};function h(){}function l(){}function p(){}var v={};s(v,i,(function(){return this}));var d=Object.getPrototypeOf,y=d&&d(d(T([])));y&&y!==e&&n.call(y,i)&&(v=y);var g=p.prototype=h.prototype=Object.create(v);function m(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){var r;this._invoke=function(i,o){function a(){return new e((function(r,a){!function r(i,o,a,s){var c=u(t[i],t,o);if("throw"!==c.type){var f=c.arg,h=f.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,a,s)}),(function(t){r("throw",t,a,s)})):e.resolve(h).then((function(t){f.value=t,a(f)}),(function(t){return r("throw",t,a,s)}))}s(c.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}}function E(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var r=u(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,f;var i=r.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function w(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function T(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:x}}function x(){return{value:void 0,done:!0}}return l.prototype=p,s(g,"constructor",p),s(p,"constructor",l),l.displayName=s(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,s(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(k.prototype),s(k.prototype,o,(function(){return this})),t.AsyncIterator=k,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var a=new k(c(e,n,r,i),o);return t.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),s(g,a,"Generator"),s(g,i,(function(){return this})),s(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=T,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(n,r){return a.type="throw",a.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var s=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(s&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),b(n),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:T(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(e={exports:{}}),e.exports}(),p=function(){return"undefined"==typeof window},v=p()?null:null==(h=document.currentScript)?void 0:h.src,d="";v?d="(via "+new URL(v).host+")":p()&&(d="(SSR)");var y,g=["sajari-sdk-js/2.10.3",d].filter(Boolean).join(" "),m=function(){function t(){this.events={}}var e=t.prototype;return e.emit=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];this.events["*"]&&this.events["*"].forEach((function(e){return e.apply(void 0,[t].concat(n))})),this.events[t]&&this.events[t].forEach((function(t){return t.apply(void 0,n)}))},e.on=function(t,e){var n=this;return this.events[t]||(this.events[t]=[]),this.events[t].push(e),function(){n.events[t]=n.events[t].filter((function(t){return t!==e}))}},t}(),k=["click","redirect","promotion_click"],E=function(){function t(t,e,n){var r=this;void 0===n&&(n="https://api.search.io"),this.account=t,this.collection=e,this.endpoint=n;var i=G("searchio_events");try{this.events=i?JSON.parse(i):{}}catch(t){this.events={},console.error("Search.io event local storage key contains corrupt data.",i)}this.flush().then((function(){return r.purge()}))}var e=t.prototype;return e.add=function(t,e,n,r){var i=this.getEvents(n);i.push({queryId:t,type:e,metadata:r,timestamp:Date.now(),submitted:!1}),this.setEvents(n,i),this.save(),this.flush()},e.save=function(){F("searchio_events",JSON.stringify(this.events))},e.getIdentifierForType=function(t){switch(t){case"redirect":return"redirect_id";case"promotion_click":return"banner_id";default:return"result_id"}},e.flush=function(){var t=this,e=[];return Object.keys(this.events).forEach((function(n){t.events[n].forEach((function(i,o){var a,s=i.type,c=i.metadata;i.submitted||e.push(t.sendEvent(i.queryId,s,r((a={},a[t.getIdentifierForType(s)]=n,a),c&&{metadata:c})).then((function(){t.events[n][o].submitted=!0,t.save()})).catch((function(){console.error("Search.io event failed to send.",t.events[n][o])})))}))})),Promise.all(e).catch((function(){}))},e.sendEvent=function(){var t=n(l.mark((function t(e,n,i){var o,a,s;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(this.endpoint+"/v4/collections/"+this.collection+":trackEvent",{method:"POST",headers:{Accept:"application/json","Content-Type":"text/plain","Account-Id":this.account},body:JSON.stringify(r({query_id:e,type:n},i))});case 2:if((o=t.sent).ok){t.next=17;break}return a=o.statusText,t.prev=5,t.next=8,o.json();case 8:(s=t.sent).message&&(a=s.message),t.next=14;break;case 12:t.prev=12,t.t0=t.catch(5);case 14:if(403!==o.status){t.next=16;break}throw new O(o.status,"This domain is not authorized to make this request.",new Error(a));case 16:throw new O(o.status,"Request failed due to a configuration error.",new Error(a));case 17:return t.abrupt("return",o.json());case 18:case"end":return t.stop()}}),t,this,[[5,12]])})));return function(e,n,r){return t.apply(this,arguments)}}(),e.getExpiry=function(){return Date.now()-2592e6},e.purge=function(){var t=this,e=this.getExpiry(),n=!1;Object.keys(this.events).forEach((function(r){var i=t.events[r].filter((function(t){return!t.submitted||t.timestamp>e}));i.length<t.events[r].length&&(t.setEvents(r,i),n=!0)})),n&&this.save()},e.getEvents=function(t){return(this.events[t]||[]).slice()},e.setEvents=function(t,e){e.length?this.events[t]=e:delete this.events[t]},e.updateQueryId=function(t){this.queryId=t},e.track=function(t,e,n){var r=this.queryId;if(!k.includes(t)){var i=this.getEvents(e).pop();i&&(r=i.queryId)}r?this.trackForQuery(r,t,e,n):console.error("No queryId found. Use updateQueryId to set the current queryId or call trackForQuery with a specific queryId.")},e.trackForQuery=function(t,e,n,r){this.add(t,e,n,r)},t}(),w=["queryID"],b=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="CONNECTION",n}return i(e,t),e}(u(Error)),O=function(t){function e(n,r,i){var o;return(o=t.call(this,r)||this).statusCode=n,o.error=i,Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o),e.prototype),o}return i(e,t),e}(u(Error)),T={clickTokenURL:"https://re.sajari.com/token/",userAgent:""},x=function(){function t(t,e,n,r,i,o){if(void 0===n&&(n=(p()?"https:":"")+"//jsonapi.sajari.net"),this.userAgent="",!p()&&[r,i].some(Boolean))throw new Error("key/secret authorization is only supported for server-side rendering.");this.project=t,this.collection=e,this.endpoint=n,this.key=r,this.secret=i,this.config=Object.assign(T,o),this.interactionConsume=this.interactionConsume.bind(this)}var e=t.prototype;return e.call=function(){var t=n(l.mark((function t(e,n,r){var i,o,a,s,c;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p()||navigator.onLine){t.next=2;break}throw new b("Search request failed due to a network error. Please check your network connection.");case 2:return i={project:[this.project],collection:[this.collection],"user-agent":[[g,this.userAgent,this.config.userAgent].filter(Boolean).join(" ")]},p()&&[this.key,this.secret].every(Boolean)&&Object.assign(i,{authorization:["keysecret "+this.key+" "+this.secret]}),t.next=6,fetch(""+this.endpoint+e,{signal:r,method:"POST",headers:{Accept:"application/json","Content-Type":"text/plain"},body:JSON.stringify({metadata:i,request:n})});case 6:if(200===(o=t.sent).status){t.next=24;break}return s=o.statusText,t.prev=9,t.next=12,o.json();case 12:a=(c=t.sent).code,s=c.message,t.next=19;break;case 17:t.prev=17,t.t0=t.catch(9);case 19:if(403!==o.status){t.next=22;break}throw console.error("Check the domain "+window.location.hostname+" is an authorized query domain. See https://app.search.io/collection/domains"),new O(o.status,"Search request failed due to a permission denied error.",new Error(s));case 22:throw console.error("Search request failed due to an error. HTTP code: "+o.status+", Code: "+a+", Message: "+s),new O(o.status,"Search request failed due to an error.",new Error(s));case 24:return t.next=26,o.json();case 26:return t.abrupt("return",t.sent);case 27:case"end":return t.stop()}}),t,this,[[9,17]])})));return function(e,n,r){return t.apply(this,arguments)}}(),e.pipeline=function(t,e){return new S(this,t,e)},e.interactionConsume=function(){var t=n(l.mark((function t(e,n,r,i){return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===i&&(i={}),t.abrupt("return",this.call("/sajari.interaction.v2.Interaction/ConsumeToken",{token:e,identifier:n,weight:r,data:i}));case 2:case"end":return t.stop()}}),t,this)})));return function(e,n,r,i){return t.apply(this,arguments)}}(),t}();(y=t.PipelineType||(t.PipelineType={}))[y.Query=1]="Query",y[y.Record=2]="Record";var _,j,S=function(e){function o(t,n,r){var i;return(i=e.call(this)||this).client=t,i.identifier={name:n,version:r},i}return i(o,e),o.prototype.search=function(){var e=n(l.mark((function e(n,i){var o,a,s,c,u,h,p,v,d,y,g,m,k=this;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o={type:t.TrackingType.None},void 0!==i&&(a=i.queryID,s=f(i,w),o=r({query_id:a},s)),this.emit("search-sent",n),e.next=5,this.client.call("/sajari.api.pipeline.v1.Query/Search",{pipeline:this.identifier,tracking:o,values:n});case 5:return u=(c=e.sent).searchResponse,h=c.redirects,p=c.tokens,d=c.banners,y=c.queryId,g=I(v=c.activePromotions),m=((null==u?void 0:u.results)||[]).map((function(t,e){var n=t.indexScore,i=t.score,o=t.values,a=t.neuralScore,s=t.featureScore,c=void 0,u=(p||[])[e];void 0!==u&&("click"in u?c={click:k.client.config.clickTokenURL+u.click.token}:"pos"in u?c=r({},u):"posNeg"in u&&(c={pos:u.posNeg.pos,neg:u.posNeg.neg}));var f=!1;return Object.keys(g).length>0&&Object.entries(g).forEach((function(t){var e=t[1],n=q(o[t[0]]);e.has(n)&&(f=!0)})),r({indexScore:n},a&&{neuralScore:a},s&&{featureScore:s},{score:i,values:L(o),token:c,promotionPinned:f})})),e.abrupt("return",[r({time:parseFloat((null==u?void 0:u.time)||"0.0"),totalResults:parseInt((null==u?void 0:u.totalResults)||"0",10),banners:d,featureScoreWeight:(null==u?void 0:u.featureScoreWeight)||0,results:m,aggregates:N(null==u?void 0:u.aggregates),aggregateFilters:N(null==u?void 0:u.aggregateFilters),redirects:P(this.client.config.clickTokenURL,h),activePromotions:null!=v?v:[]},y&&{queryId:y}),c.values||{}]);case 10:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),o}(m);function I(t){void 0===t&&(t=[]);var e={};return t.forEach((function(t){t.activePins.forEach((function(t){var n=t.key;e[n.field]||(e[n.field]=new Set),e[n.field].add(n.value)}))})),e}function P(t,e){return void 0===e&&(e={}),Object.entries(e).reduce((function(e,n){var r=n[0];return e[r]=n[1],e[r].token=t+e[r].token,e}),{})}function N(t){return void 0===t&&(t={}),Object.entries(t).map((function(t){var e,n,r=t[0],i=t[1];if("metric"in i){var o=r.split(".");return{type:o[0],key:o[1],value:i.metric.value}}return"count"in i?{type:"count",key:r.replace(/^count./,""),value:i.count.counts}:"buckets"in i?{type:"count",key:"buckets",value:Object.values(null!=(e=null==(n=i.buckets)?void 0:n.buckets)?e:{}).reduce((function(t,e){var n;return Object.assign(t,((n={})[e.name]=e.count,n))}),{})}:{key:r,value:i}})).reduce((function(t,e){if(void 0===e.type)return console.debug(e),t;void 0===t[e.key]&&(t[e.key]={});var n=t[e.key][e.type];return"count"===e.type&&"buckets"===e.key&&"object"==typeof n&&"object"==typeof e.value?(n=r({},n,e.value),t[e.key][e.type]=n):t[e.key][e.type]=e.value,t}),{})}function L(t){var e={};return Object.keys(t).forEach((function(n){var r=q(t[n]);null!==r&&(e[n]=r)})),e}function q(t){return"single"in t?t.single:"repeated"in t?t.repeated.values:"singleBytes"in t?t.singleBytes:null}(_=t.TextPosition||(t.TextPosition={})).Unspecified="TEXT_POSITION_UNSPECIFIED",_.Center="TEXT_POSITION_CENTER",_.TopLeft="TEXT_POSITION_TOP_LEFT",_.TopRight="TEXT_POSITION_TOP_RIGHT",_.BottomLeft="TEXT_POSITION_BOTTOM_LEFT",_.BottomRight="TEXT_POSITION_BOTTOM_RIGHT",(j=t.TrackingType||(t.TrackingType={})).None="NONE",j.Click="CLICK",j.PosNeg="POS_NEG",j.Event="EVENT";var R=function(t){function e(e,n,r){var i;return(i=t.call(this)||this).queryID="",i.sequence=0,i.type=e,i.field=n,i.data=function(t){if("undefined"==typeof window)return{};var e=document.cookie.split(";").filter((function(t){return t.includes("_ga")||t.includes("sjID")})).map((function(t){return t.split("=")})).reduce((function(t,e){var n=e[0],r=e[1];return"_ga"===n?(t.ga=r,t):(t[n]=r,t)}),{});return void 0===t?e:(Object.entries(e).forEach((function(e){t[e[0]]=e[1]})),t)}(r),i}i(e,t);var n=e.prototype;return n.next=function(t){return""===this.queryID?(this.queryID=function(t){void 0===t&&(t=16);for(var e="",n=0;n<t;n++)e+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()));return e}(),this.sequence=0):this.sequence++,{type:this.type,queryID:this.queryID,sequence:this.sequence,field:this.field,data:this.data}},n.reset=function(){this.emit("tracking-reset"),this.queryID="",this.sequence=0},e}(m),C=function(){function t(t,e){this.textParam=t,this.session=e,this.lastQuery=""}var e=t.prototype;return e.next=function(t){var e=t[this.textParam];if(void 0===e)return this.reset(),this.session.next(t);var n=this.lastQuery.substr(0,Math.min(e.length,3));return(e.substr(0,n.length)!==n||this.lastQuery.length>0&&0===e.length)&&this.reset(),this.lastQuery=e,this.session.next(t)},e.reset=function(){this.session.reset()},t}(),A=function(t){function e(e,n,r,i){var o;return void 0===n&&(n=[]),void 0===r&&(r=!1),void 0===i&&(i="OR"),(o=t.call(this)||this).options=e,o.active=n,o.multi=r,o.joinOp=i,o}i(e,t);var n=e.prototype;return n.set=function(t,e){if(void 0===e&&(e=!0),this.multi)return this.active=e&&-1===this.active.indexOf(t)?this.active.concat(t):this.active.filter((function(e){return e!==t})),void this.emit("selection-updated",[].concat(this.active));this.active=e?[t]:[],this.emit("selection-updated",[].concat(this.active))},n.isActive=function(t){return-1!==this.active.indexOf(t)},n.get=function(){return[].concat(this.active)},n.updateOptions=function(t){var e=this;Object.keys(t).forEach((function(n){var r=t[n];if(void 0===r)return delete e.options[n],void(e.active=e.active.filter((function(t){return t!==n})));e.options[n]=r})),this.emit("options-updated",r({},this.options))},n.getOptions=function(){return r({},this.options)},n.filter=function(){var t=this,e=this.active.map((function(e){var n=t.options[e];return"function"==typeof n&&(n=n()),""!==n&&(n="("+n+")"),n})).filter(Boolean);switch(e.length){case 0:return"";case 1:return e[0];default:return e.join(" "+this.joinOp+" ")}},e}(m),D=function(t){function e(e){var n;return void 0===e&&(e={}),(n=t.call(this)||this).internal=e,n}i(e,t);var n=e.prototype;return n._internalUpdate=function(t){var e=this;Object.keys(t).forEach((function(n){var r=t[n];void 0===r?delete e.internal[n]:e.internal[n]=r}))},n.update=function(t){var e=this;this._internalUpdate(t),this.emit("values-changed",t,(function(t){return e._internalUpdate(t)}))},n.get=function(){var t={};return Object.entries(this.internal).forEach((function(e){var n=e[1];t[e[0]]="function"==typeof n?n():Array.isArray(n)?n.join(","):""+n})),t},e}(m),F=function(t,e){if(!p())try{localStorage.setItem(t,e)}catch(n){console.error('Search.io local storage "'+t+'" cannot be saved.',e)}},G=function(t){return p()?"":localStorage.getItem(t)},U=function(){function t(t){var e=G("sajari_tokens");try{this.currentTokens=e?JSON.parse(e):{}}catch(t){this.currentTokens={},console.error("Sajari PosNeg local storage key contains corrupt data.",e)}this.client=t}var e=t.prototype;return e.add=function(t,e){this.currentTokens[t]={token:e,clickSubmitted:!1},F("sajari_tokens",JSON.stringify(this.currentTokens))},e.get=function(t){return this.currentTokens[t]},e.sendPosEvent=function(t,e,n){var r=this.get(t);void 0!==r&&this.client.interactionConsume(r.token.pos,e,n)},e.sendClickEvent=function(t){var e=this.get(t);void 0!==e&&!1===e.clickSubmitted&&(this.sendPosEvent(t,"click",1),this.currentTokens[t].clickSubmitted=!0,F("sajari_tokens",JSON.stringify(this.currentTokens)))},e.sendPendingClicks=function(){var t=this;Object.keys(this.currentTokens).forEach((function(e){!1===t.currentTokens[e].clickSubmitted&&(t.sendClickEvent(e),t.currentTokens[e].clickSubmitted=!0)}))},t}();t.Client=x,t.DefaultSession=R,t.EVENT_OPTIONS_UPDATED="options-updated",t.EVENT_SEARCH_SENT="search-sent",t.EVENT_SELECTION_UPDATED="selection-updated",t.EVENT_TRACKING_RESET="tracking-reset",t.EVENT_VALUES_UPDATED="values-changed",t.EventEmitter=m,t.Filter=A,t.InteractiveSession=C,t.NetworkError=b,t.POS_NEG_STORAGE_KEY="sajari_tokens",t.PosNegLocalStorageManager=U,t.RequestError=O,t.SearchIOAnalytics=E,t.Values=D,t.formatAggregates=N,t.getItem=G,t.setItem=F,Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).SajariSDK={})}(this,(function(t){"use strict";function e(t,e,n,r,i,o,a){try{var s=t[o](a),c=s.value}catch(t){return void n(t)}s.done?e(c):Promise.resolve(c).then(r,i)}function n(t){return function(){var n=this,r=arguments;return new Promise((function(i,o){var a=t.apply(n,r);function s(t){e(a,i,o,s,c,"next",t)}function c(t){e(a,i,o,s,c,"throw",t)}s(void 0)}))}}function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,a(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(t,e){return(a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function c(t,e,n){return(c=s()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var i=new(Function.bind.apply(t,r));return n&&a(i,n.prototype),i}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return c(t,arguments,o(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,t)})(t)}function f(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)e.indexOf(n=o[r])>=0||(i[n]=t[n]);return i}var h,l=function(t,e){return function(t){var e=function(t){var e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),o=new O(r||[]);return i._invoke=function(t,e,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return{value:void 0,done:!0}}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var s=E(a,n);if(s){if(s===f)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=u(t,e,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(t,n,o),i}function u(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f={};function h(){}function l(){}function p(){}var v={};s(v,i,(function(){return this}));var d=Object.getPrototypeOf,y=d&&d(d(T([])));y&&y!==e&&n.call(y,i)&&(v=y);var g=p.prototype=h.prototype=Object.create(v);function m(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){var r;this._invoke=function(i,o){function a(){return new e((function(r,a){!function r(i,o,a,s){var c=u(t[i],t,o);if("throw"!==c.type){var f=c.arg,h=f.value;return h&&"object"==typeof h&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,a,s)}),(function(t){r("throw",t,a,s)})):e.resolve(h).then((function(t){f.value=t,a(f)}),(function(t){return r("throw",t,a,s)}))}s(c.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}}function E(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var r=u(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,f;var i=r.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function w(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function T(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:x}}function x(){return{value:void 0,done:!0}}return l.prototype=p,s(g,"constructor",p),s(p,"constructor",l),l.displayName=s(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,s(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(k.prototype),s(k.prototype,o,(function(){return this})),t.AsyncIterator=k,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var a=new k(c(e,n,r,i),o);return t.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),s(g,a,"Generator"),s(g,i,(function(){return this})),s(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=T,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(n,r){return a.type="throw",a.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var s=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(s&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),b(n),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:T(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(e={exports:{}}),e.exports}(),p=function(){return"undefined"==typeof window},v=p()?null:null==(h=document.currentScript)?void 0:h.src,d="";v?d="(via "+new URL(v).host+")":p()&&(d="(SSR)");var y,g=["sajari-sdk-js/2.10.4",d].filter(Boolean).join(" "),m=function(){function t(){this.events={}}var e=t.prototype;return e.emit=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];this.events["*"]&&this.events["*"].forEach((function(e){return e.apply(void 0,[t].concat(n))})),this.events[t]&&this.events[t].forEach((function(t){return t.apply(void 0,n)}))},e.on=function(t,e){var n=this;return this.events[t]||(this.events[t]=[]),this.events[t].push(e),function(){n.events[t]=n.events[t].filter((function(t){return t!==e}))}},t}(),k=function(t){function e(n,r,i){var o;return(o=t.call(this,r)||this).statusCode=n,o.error=i,Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(o),e.prototype),o}return i(e,t),e}(u(Error)),E=function(t,e){if(!p())try{localStorage.setItem(t,e)}catch(n){console.error('Search.io local storage "'+t+'" cannot be saved.',e)}},w=function(t){return p()?"":localStorage.getItem(t)},b=["click","redirect","promotion_click"],O=function(){function t(t,e,n){var r=this;void 0===n&&(n="https://api.search.io"),this.account=t,this.collection=e,this.endpoint=n;var i=w("searchio_events");try{this.events=i?JSON.parse(i):{}}catch(t){this.events={},console.error("Search.io event local storage key contains corrupt data.",i)}this.flush().then((function(){return r.purge()}))}var e=t.prototype;return e.add=function(t,e,n,r){var i=this.getEvents(n);i.push({queryId:t,type:e,metadata:r,timestamp:Date.now(),submitted:!1}),this.setEvents(n,i),this.save(),this.flush()},e.save=function(){E("searchio_events",JSON.stringify(this.events))},e.getIdentifierForType=function(t){switch(t){case"redirect":return"redirect_id";case"promotion_click":return"banner_id";default:return"result_id"}},e.flush=function(){var t=this,e=[];return Object.keys(this.events).forEach((function(n){t.events[n].forEach((function(i,o){var a,s=i.type,c=i.metadata;i.submitted||e.push(t.sendEvent(i.queryId,s,r((a={},a[t.getIdentifierForType(s)]=n,a),c&&{metadata:c})).then((function(){t.events[n][o].submitted=!0,t.save()})).catch((function(){console.error("Search.io event failed to send.",t.events[n][o])})))}))})),Promise.all(e).catch((function(){}))},e.sendEvent=function(){var t=n(l.mark((function t(e,n,i){var o,a,s;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(this.endpoint+"/v4/collections/"+this.collection+":trackEvent",{method:"POST",headers:{Accept:"application/json","Content-Type":"text/plain","Account-Id":this.account},body:JSON.stringify(r({query_id:e,type:n},i))});case 2:if((o=t.sent).ok){t.next=17;break}return a=o.statusText,t.prev=5,t.next=8,o.json();case 8:(s=t.sent).message&&(a=s.message),t.next=14;break;case 12:t.prev=12,t.t0=t.catch(5);case 14:if(403!==o.status){t.next=16;break}throw new k(o.status,"This domain is not authorized to make this request.",new Error(a));case 16:throw new k(o.status,"Request failed due to a configuration error.",new Error(a));case 17:return t.abrupt("return",o.json());case 18:case"end":return t.stop()}}),t,this,[[5,12]])})));return function(e,n,r){return t.apply(this,arguments)}}(),e.getExpiry=function(){return Date.now()-2592e6},e.purge=function(){var t=this,e=this.getExpiry(),n=!1;Object.keys(this.events).forEach((function(r){var i=t.events[r].filter((function(t){return!t.submitted||t.timestamp>e}));i.length<t.events[r].length&&(t.setEvents(r,i),n=!0)})),n&&this.save()},e.getEvents=function(t){return(this.events[t]||[]).slice()},e.setEvents=function(t,e){e.length?this.events[t]=e:delete this.events[t]},e.updateQueryId=function(t){this.queryId=t},e.track=function(t,e,n){var r=this.queryId;if(b.includes(t)){if(!r)return void console.error("No queryId found. Use updateQueryId to set the current queryId or call trackForQuery with a specific queryId.")}else{var i=this.getEvents(e).pop();i&&(r=i.queryId)}r&&this.trackForQuery(r,t,e,n)},e.trackForQuery=function(t,e,n,r){this.add(t,e,n,r)},t}(),T=["queryID"],x=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="CONNECTION",n}return i(e,t),e}(u(Error)),_={clickTokenURL:"https://re.sajari.com/token/",userAgent:""},j=function(){function t(t,e,n,r,i,o){if(void 0===n&&(n=(p()?"https:":"")+"//jsonapi.sajari.net"),this.userAgent="",!p()&&[r,i].some(Boolean))throw new Error("key/secret authorization is only supported for server-side rendering.");this.project=t,this.collection=e,this.endpoint=n,this.key=r,this.secret=i,this.config=Object.assign(_,o),this.interactionConsume=this.interactionConsume.bind(this)}var e=t.prototype;return e.call=function(){var t=n(l.mark((function t(e,n,r){var i,o,a,s,c;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p()||navigator.onLine){t.next=2;break}throw new x("Search request failed due to a network error. Please check your network connection.");case 2:return i={project:[this.project],collection:[this.collection],"user-agent":[[g,this.userAgent,this.config.userAgent].filter(Boolean).join(" ")]},p()&&[this.key,this.secret].every(Boolean)&&Object.assign(i,{authorization:["keysecret "+this.key+" "+this.secret]}),t.next=6,fetch(""+this.endpoint+e,{signal:r,method:"POST",headers:{Accept:"application/json","Content-Type":"text/plain"},body:JSON.stringify({metadata:i,request:n})});case 6:if(200===(o=t.sent).status){t.next=24;break}return s=o.statusText,t.prev=9,t.next=12,o.json();case 12:a=(c=t.sent).code,s=c.message,t.next=19;break;case 17:t.prev=17,t.t0=t.catch(9);case 19:if(403!==o.status){t.next=22;break}throw console.error("Check the domain "+window.location.hostname+" is an authorized query domain. See https://app.search.io/collection/domains"),new k(o.status,"Search request failed due to a permission denied error.",new Error(s));case 22:throw console.error("Search request failed due to an error. HTTP code: "+o.status+", Code: "+a+", Message: "+s),new k(o.status,"Search request failed due to an error.",new Error(s));case 24:return t.next=26,o.json();case 26:return t.abrupt("return",t.sent);case 27:case"end":return t.stop()}}),t,this,[[9,17]])})));return function(e,n,r){return t.apply(this,arguments)}}(),e.pipeline=function(t,e){return new P(this,t,e)},e.interactionConsume=function(){var t=n(l.mark((function t(e,n,r,i){return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===i&&(i={}),t.abrupt("return",this.call("/sajari.interaction.v2.Interaction/ConsumeToken",{token:e,identifier:n,weight:r,data:i}));case 2:case"end":return t.stop()}}),t,this)})));return function(e,n,r,i){return t.apply(this,arguments)}}(),t}();(y=t.PipelineType||(t.PipelineType={}))[y.Query=1]="Query",y[y.Record=2]="Record";var S,I,P=function(e){function o(t,n,r){var i;return(i=e.call(this)||this).client=t,i.identifier={name:n,version:r},i}return i(o,e),o.prototype.search=function(){var e=n(l.mark((function e(n,i){var o,a,s,c,u,h,p,v,d,y,g,m,k=this;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o={type:t.TrackingType.None},void 0!==i&&(a=i.queryID,s=f(i,T),o=r({query_id:a},s)),this.emit("search-sent",n),e.next=5,this.client.call("/sajari.api.pipeline.v1.Query/Search",{pipeline:this.identifier,tracking:o,values:n});case 5:return u=(c=e.sent).searchResponse,h=c.redirects,p=c.tokens,d=c.banners,y=c.queryId,g=N(v=c.activePromotions),m=((null==u?void 0:u.results)||[]).map((function(t,e){var n=t.indexScore,i=t.score,o=t.values,a=t.neuralScore,s=t.featureScore,c=void 0,u=(p||[])[e];void 0!==u&&("click"in u?c={click:k.client.config.clickTokenURL+u.click.token}:"pos"in u?c=r({},u):"posNeg"in u&&(c={pos:u.posNeg.pos,neg:u.posNeg.neg}));var f=!1;return Object.keys(g).length>0&&Object.entries(g).forEach((function(t){var e=t[1],n=C(o[t[0]]);e.has(n)&&(f=!0)})),r({indexScore:n},a&&{neuralScore:a},s&&{featureScore:s},{score:i,values:R(o),token:c,promotionPinned:f})})),e.abrupt("return",[r({time:parseFloat((null==u?void 0:u.time)||"0.0"),totalResults:parseInt((null==u?void 0:u.totalResults)||"0",10),banners:d,featureScoreWeight:(null==u?void 0:u.featureScoreWeight)||0,results:m,aggregates:q(null==u?void 0:u.aggregates),aggregateFilters:q(null==u?void 0:u.aggregateFilters),redirects:L(this.client.config.clickTokenURL,h),activePromotions:null!=v?v:[]},y&&{queryId:y}),c.values||{}]);case 10:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),o}(m);function N(t){void 0===t&&(t=[]);var e={};return t.forEach((function(t){t.activePins.forEach((function(t){var n=t.key;e[n.field]||(e[n.field]=new Set),e[n.field].add(n.value)}))})),e}function L(t,e){return void 0===e&&(e={}),Object.entries(e).reduce((function(e,n){var r=n[0];return e[r]=n[1],e[r].token=t+e[r].token,e}),{})}function q(t){return void 0===t&&(t={}),Object.entries(t).map((function(t){var e,n,r=t[0],i=t[1];if("metric"in i){var o=r.split(".");return{type:o[0],key:o[1],value:i.metric.value}}return"count"in i?{type:"count",key:r.replace(/^count./,""),value:i.count.counts}:"buckets"in i?{type:"count",key:"buckets",value:Object.values(null!=(e=null==(n=i.buckets)?void 0:n.buckets)?e:{}).reduce((function(t,e){var n;return Object.assign(t,((n={})[e.name]=e.count,n))}),{})}:{key:r,value:i}})).reduce((function(t,e){if(void 0===e.type)return console.debug(e),t;void 0===t[e.key]&&(t[e.key]={});var n=t[e.key][e.type];return"count"===e.type&&"buckets"===e.key&&"object"==typeof n&&"object"==typeof e.value?(n=r({},n,e.value),t[e.key][e.type]=n):t[e.key][e.type]=e.value,t}),{})}function R(t){var e={};return Object.keys(t).forEach((function(n){var r=C(t[n]);null!==r&&(e[n]=r)})),e}function C(t){return"single"in t?t.single:"repeated"in t?t.repeated.values:"singleBytes"in t?t.singleBytes:null}(S=t.TextPosition||(t.TextPosition={})).Unspecified="TEXT_POSITION_UNSPECIFIED",S.Center="TEXT_POSITION_CENTER",S.TopLeft="TEXT_POSITION_TOP_LEFT",S.TopRight="TEXT_POSITION_TOP_RIGHT",S.BottomLeft="TEXT_POSITION_BOTTOM_LEFT",S.BottomRight="TEXT_POSITION_BOTTOM_RIGHT",(I=t.TrackingType||(t.TrackingType={})).None="NONE",I.Click="CLICK",I.PosNeg="POS_NEG",I.Event="EVENT";var A=function(t){function e(e,n,r){var i;return(i=t.call(this)||this).queryID="",i.sequence=0,i.type=e,i.field=n,i.data=function(t){if("undefined"==typeof window)return{};var e=document.cookie.split(";").filter((function(t){return t.includes("_ga")||t.includes("sjID")})).map((function(t){return t.split("=")})).reduce((function(t,e){var n=e[0],r=e[1];return"_ga"===n?(t.ga=r,t):(t[n]=r,t)}),{});return void 0===t?e:(Object.entries(e).forEach((function(e){t[e[0]]=e[1]})),t)}(r),i}i(e,t);var n=e.prototype;return n.next=function(t){return""===this.queryID?(this.queryID=function(t){void 0===t&&(t=16);for(var e="",n=0;n<t;n++)e+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()));return e}(),this.sequence=0):this.sequence++,{type:this.type,queryID:this.queryID,sequence:this.sequence,field:this.field,data:this.data}},n.reset=function(){this.emit("tracking-reset"),this.queryID="",this.sequence=0},e}(m),D=function(){function t(t,e){this.textParam=t,this.session=e,this.lastQuery=""}var e=t.prototype;return e.next=function(t){var e=t[this.textParam];if(void 0===e)return this.reset(),this.session.next(t);var n=this.lastQuery.substr(0,Math.min(e.length,3));return(e.substr(0,n.length)!==n||this.lastQuery.length>0&&0===e.length)&&this.reset(),this.lastQuery=e,this.session.next(t)},e.reset=function(){this.session.reset()},t}(),F=function(t){function e(e,n,r,i){var o;return void 0===n&&(n=[]),void 0===r&&(r=!1),void 0===i&&(i="OR"),(o=t.call(this)||this).options=e,o.active=n,o.multi=r,o.joinOp=i,o}i(e,t);var n=e.prototype;return n.set=function(t,e){if(void 0===e&&(e=!0),this.multi)return this.active=e&&-1===this.active.indexOf(t)?this.active.concat(t):this.active.filter((function(e){return e!==t})),void this.emit("selection-updated",[].concat(this.active));this.active=e?[t]:[],this.emit("selection-updated",[].concat(this.active))},n.isActive=function(t){return-1!==this.active.indexOf(t)},n.get=function(){return[].concat(this.active)},n.updateOptions=function(t){var e=this;Object.keys(t).forEach((function(n){var r=t[n];if(void 0===r)return delete e.options[n],void(e.active=e.active.filter((function(t){return t!==n})));e.options[n]=r})),this.emit("options-updated",r({},this.options))},n.getOptions=function(){return r({},this.options)},n.filter=function(){var t=this,e=this.active.map((function(e){var n=t.options[e];return"function"==typeof n&&(n=n()),""!==n&&(n="("+n+")"),n})).filter(Boolean);switch(e.length){case 0:return"";case 1:return e[0];default:return e.join(" "+this.joinOp+" ")}},e}(m),G=function(t){function e(e){var n;return void 0===e&&(e={}),(n=t.call(this)||this).internal=e,n}i(e,t);var n=e.prototype;return n._internalUpdate=function(t){var e=this;Object.keys(t).forEach((function(n){var r=t[n];void 0===r?delete e.internal[n]:e.internal[n]=r}))},n.update=function(t){var e=this;this._internalUpdate(t),this.emit("values-changed",t,(function(t){return e._internalUpdate(t)}))},n.get=function(){var t={};return Object.entries(this.internal).forEach((function(e){var n=e[1];t[e[0]]="function"==typeof n?n():Array.isArray(n)?n.join(","):""+n})),t},e}(m),U=function(){function t(t){var e=w("sajari_tokens");try{this.currentTokens=e?JSON.parse(e):{}}catch(t){this.currentTokens={},console.error("Sajari PosNeg local storage key contains corrupt data.",e)}this.client=t}var e=t.prototype;return e.add=function(t,e){this.currentTokens[t]={token:e,clickSubmitted:!1},E("sajari_tokens",JSON.stringify(this.currentTokens))},e.get=function(t){return this.currentTokens[t]},e.sendPosEvent=function(t,e,n){var r=this.get(t);void 0!==r&&this.client.interactionConsume(r.token.pos,e,n)},e.sendClickEvent=function(t){var e=this.get(t);void 0!==e&&!1===e.clickSubmitted&&(this.sendPosEvent(t,"click",1),this.currentTokens[t].clickSubmitted=!0,E("sajari_tokens",JSON.stringify(this.currentTokens)))},e.sendPendingClicks=function(){var t=this;Object.keys(this.currentTokens).forEach((function(e){!1===t.currentTokens[e].clickSubmitted&&(t.sendClickEvent(e),t.currentTokens[e].clickSubmitted=!0)}))},t}();t.Client=j,t.DefaultSession=A,t.EVENT_OPTIONS_UPDATED="options-updated",t.EVENT_SEARCH_SENT="search-sent",t.EVENT_SELECTION_UPDATED="selection-updated",t.EVENT_TRACKING_RESET="tracking-reset",t.EVENT_VALUES_UPDATED="values-changed",t.EventEmitter=m,t.Filter=F,t.InteractiveSession=D,t.NetworkError=x,t.POS_NEG_STORAGE_KEY="sajari_tokens",t.PosNegLocalStorageManager=U,t.RequestError=k,t.SearchIOAnalytics=O,t.Values=G,t.formatAggregates=q,t.getItem=w,t.setItem=E,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=sajarisdk.umd.production.min.js.map
{
"name": "@sajari/sdk-js",
"description": "Search.io JavaScript SDK",
"version": "2.10.3",
"version": "2.10.4",
"main": "dist/index.js",

@@ -46,3 +46,4 @@ "umd:main": "dist/sajarisdk.umd.production.js",

"docs": "typedoc src/index.ts --out docs",
"generate:user-agent": "node scripts/gen-useragent"
"generate:user-agent": "node scripts/gen-useragent",
"release": "yarn build && yarn changeset publish"
},

@@ -64,2 +65,3 @@ "husky": {

"devDependencies": {
"@changesets/cli": "^2.21.1",
"@types/jest": "^27.4.0",

@@ -66,0 +68,0 @@ "fetch-ponyfill": "^7.1.0",

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 too big to display

Sorry, the diff of this file is not supported yet

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc