addsearch-js-client
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -1,2 +0,2 @@ | ||
window.AddSearchClient=function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){(function(e,n){ | ||
window.AddSearchClient=function(t){var e={};function n(i){if(e[i])return e[i].exports;var s=e[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)n.d(i,s,function(e){return t[e]}.bind(null,s));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e,n){(function(e,n){ | ||
/*! | ||
@@ -8,2 +8,2 @@ * @overview es6-promise - a tiny implementation of Promises/A+. | ||
* @version v4.2.8+1e68dce6 | ||
*/var i;i=function(){"use strict";function t(t){return"function"==typeof t}var i=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},r=0,s=void 0,o=void 0,a=function(t,e){p[r]=t,p[r+1]=e,2===(r+=2)&&(o?o(g):w())},u="undefined"!=typeof window?window:void 0,c=u||{},h=c.MutationObserver||c.WebKitMutationObserver,f="undefined"==typeof self&&void 0!==e&&"[object process]"==={}.toString.call(e),l="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function d(){var t=setTimeout;return function(){return t(g,1)}}var p=new Array(1e3);function g(){for(var t=0;t<r;t+=2)(0,p[t])(p[t+1]),p[t]=void 0,p[t+1]=void 0;r=0}var y,b,m,v,w=void 0;function _(t,e){var n=this,i=new this.constructor(A);void 0===i[T]&&L(i);var r=n._state;if(r){var s=arguments[r-1];a((function(){return R(r,i,s,n._result)}))}else z(n,i,t,e);return i}function F(t){if(t&&"object"==typeof t&&t.constructor===this)return t;var e=new this(A);return P(e,t),e}f?w=function(){return e.nextTick(g)}:h?(b=0,m=new h(g),v=document.createTextNode(""),m.observe(v,{characterData:!0}),w=function(){v.data=b=++b%2}):l?((y=new MessageChannel).port1.onmessage=g,w=function(){return y.port2.postMessage(0)}):w=void 0===u?function(){try{var t=Function("return this")().require("vertx");return void 0!==(s=t.runOnLoop||t.runOnContext)?function(){s(g)}:d()}catch(t){return d()}}():d();var T=Math.random().toString(36).substring(2);function A(){}var S=void 0,O=1,x=2;function E(e,n,i){n.constructor===e.constructor&&i===_&&n.constructor.resolve===F?function(t,e){e._state===O?C(t,e._result):e._state===x?k(t,e._result):z(e,void 0,(function(e){return P(t,e)}),(function(e){return k(t,e)}))}(e,n):void 0===i?C(e,n):t(i)?function(t,e,n){a((function(t){var i=!1,r=function(t,e,n,i){try{t.call(e,n,i)}catch(t){return t}}(n,e,(function(n){i||(i=!0,e!==n?P(t,n):C(t,n))}),(function(e){i||(i=!0,k(t,e))}),t._label);!i&&r&&(i=!0,k(t,r))}),t)}(e,n,i):C(e,n)}function P(t,e){if(t===e)k(t,new TypeError("You cannot resolve a promise with itself"));else if(r=typeof(i=e),null===i||"object"!==r&&"function"!==r)C(t,e);else{var n=void 0;try{n=e.then}catch(e){return void k(t,e)}E(t,e,n)}var i,r}function j(t){t._onerror&&t._onerror(t._result),B(t)}function C(t,e){t._state===S&&(t._result=e,t._state=O,0!==t._subscribers.length&&a(B,t))}function k(t,e){t._state===S&&(t._state=x,t._result=e,a(j,t))}function z(t,e,n,i){var r=t._subscribers,s=r.length;t._onerror=null,r[s]=e,r[s+O]=n,r[s+x]=i,0===s&&t._state&&a(B,t)}function B(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var i=void 0,r=void 0,s=t._result,o=0;o<e.length;o+=3)i=e[o],r=e[o+n],i?R(n,i,r,s):r(s);t._subscribers.length=0}}function R(e,n,i,r){var s=t(i),o=void 0,a=void 0,u=!0;if(s){try{o=i(r)}catch(t){u=!1,a=t}if(n===o)return void k(n,new TypeError("A promises callback cannot return that same promise."))}else o=r;n._state!==S||(s&&u?P(n,o):!1===u?k(n,a):e===O?C(n,o):e===x&&k(n,o))}var U=0;function L(t){t[T]=U++,t._state=void 0,t._result=void 0,t._subscribers=[]}var I=function(){function t(t,e){this._instanceConstructor=t,this.promise=new t(A),this.promise[T]||L(this.promise),i(e)?(this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?C(this.promise,this._result):(this.length=this.length||0,this._enumerate(e),0===this._remaining&&C(this.promise,this._result))):k(this.promise,new Error("Array Methods must be provided an Array"))}return t.prototype._enumerate=function(t){for(var e=0;this._state===S&&e<t.length;e++)this._eachEntry(t[e],e)},t.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,i=n.resolve;if(i===F){var r=void 0,s=void 0,o=!1;try{r=t.then}catch(t){o=!0,s=t}if(r===_&&t._state!==S)this._settledAt(t._state,e,t._result);else if("function"!=typeof r)this._remaining--,this._result[e]=t;else if(n===D){var a=new n(A);o?k(a,s):E(a,t,r),this._willSettleAt(a,e)}else this._willSettleAt(new n((function(e){return e(t)})),e)}else this._willSettleAt(i(t),e)},t.prototype._settledAt=function(t,e,n){var i=this.promise;i._state===S&&(this._remaining--,t===x?k(i,n):this._result[e]=n),0===this._remaining&&C(i,this._result)},t.prototype._willSettleAt=function(t,e){var n=this;z(t,void 0,(function(t){return n._settledAt(O,e,t)}),(function(t){return n._settledAt(x,e,t)}))},t}(),D=function(){function e(t){this[T]=U++,this._result=this._state=void 0,this._subscribers=[],A!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof e?function(t,e){try{e((function(e){P(t,e)}),(function(e){k(t,e)}))}catch(e){k(t,e)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return e.prototype.catch=function(t){return this.then(null,t)},e.prototype.finally=function(e){var n=this.constructor;return t(e)?this.then((function(t){return n.resolve(e()).then((function(){return t}))}),(function(t){return n.resolve(e()).then((function(){throw t}))})):this.then(e,e)},e}();return D.prototype.then=_,D.all=function(t){return new I(this,t).promise},D.race=function(t){var e=this;return i(t)?new e((function(n,i){for(var r=t.length,s=0;s<r;s++)e.resolve(t[s]).then(n,i)})):new e((function(t,e){return e(new TypeError("You must pass an array to race."))}))},D.resolve=F,D.reject=function(t){var e=new this(A);return k(e,t),e},D._setScheduler=function(t){o=t},D._setAsap=function(t){a=t},D._asap=a,D.polyfill=function(){var t=void 0;if(void 0!==n)t=n;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var i=null;try{i=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===i&&!e.cast)return}t.Promise=D},D.Promise=D,D},t.exports=i()}).call(this,n(4),n(5))},function(t,e,n){n(6),t.exports=self.fetch.bind(self)},function(t,e,n){"use strict";var i=n(3),r=n(7),s=n(8),o=n(9);t.exports=function(t){this.sitekey=t,this.settings=new s,this.sessionId=("a-"+1e8*Math.random()).substring(0,10),this.search=function(t,e){var n=null,r=null;if(t&&o.isFunction(e))n=t,r=e;else if(!e&&o.isFunction(t))n=this.settings.getSettings().keyword,r=t;else{if(!this.settings.getSettings().callback)throw"Illegal search parameters. Should be (keyword, callbackFunction) or (callbackFunction)";n=this.settings.getSettings().keyword,r=this.settings.getSettings().callback}this.settings.setCallback(r),this.settings.setKeyword(n),i(this.sitekey,"search",this.settings.getSettings(),r)},this.suggestions=function(t,e){if(!t||!e||!o.isFunction(e))throw"Illegal suggestions parameters. Should be (prefix, callbackFunction)";this.settings.setSuggestionsPrefix(t),i(this.sitekey,"suggest",this.settings.getSettings(),e)},this.getSettings=function(){return this.settings.getSettings()},this.setLanguage=function(t){this.settings.setLanguage(t)},this.setCategoryFilters=function(t){this.settings.setCategoryFilters(t)},this.addCustomFieldFilter=function(t,e){this.settings.addCustomFieldFilter(t,e)},this.removeCustomFieldFilter=function(t,e){this.settings.removeCustomFieldFilter(t,e)},this.setPriceRangeFilter=function(t,e){this.settings.setPriceRangeFilter(t,e)},this.setDateFilter=function(t,e){this.settings.setDateFilter(t,e)},this.setJWT=function(t){this.settings.setJWT(t)},this.setUserToken=function(t){this.settings.setUserToken(t)},this.setPaging=function(t,e,n,i){this.settings.setPaging(t,e,n,i)},this.nextPage=function(){this.settings.nextPage()},this.previousPage=function(){this.settings.previousPage()},this.setSuggestionsSize=function(t){this.settings.setSuggestionsSize(t)},this.addFacetField=function(t){this.settings.addFacetField(t)},this.setNumberOfFacets=function(t){this.settings.setNumberOfFacets(t)},this.setResultType=function(t){this.settings.setResultType(t)},this.setPersonalizationEvents=function(t){this.settings.setPersonalizationEvents(t)},this.setFilterObject=function(t){this.settings.setFilterObject(t)},this.setShuffleAndLimitTo=function(t){this.settings.setShuffleAndLimitTo(t)},this.setFuzzyMatch=function(t){this.settings.setFuzzyMatch(t)},this.setCollectAnalytics=function(t){this.settings.setCollectAnalytics(t)},this.searchResultClicked=function(t,e){var n={action:"click",session:this.sessionId,keyword:this.settings.getSettings().keyword,docid:t,position:e};r(this.sitekey,n)},this.useFuzzyMatch=function(t){this.settings.setFuzzyMatch(t)}}},function(t,e,n){"use strict";n(0).polyfill(),n(1);t.exports=function(t,e,n,i){var r=function(t,e){return t||!1===t?"&"+e+"="+t:""};if("search"===e||"suggest"===e){var s="",o="";if("search"===e){if(s=(s=n.keyword).replace(/ and /g," AND ").replace(/ or /g," OR ").replace(/ not /g," NOT "),s=encodeURIComponent(s),"search"===e){if(o=r(n.lang,"lang")+r(n.fuzzy,"fuzzy")+r(n.collectAnalytics,"collectAnalytics")+r(n.categories,"categories")+r(n.priceFromCents,"priceFromCents")+r(n.priceToCents,"priceToCents")+r(n.dateFrom,"dateFrom")+r(n.dateTo,"dateTo")+r(n.paging.page,"page")+r(n.paging.pageSize,"limit")+r(n.paging.sortBy,"sort")+r(n.paging.sortOrder,"order")+r(n.shuffleAndLimitTo,"shuffleAndLimitTo")+r(n.jwt,"jwt")+r(n.resultType,"resultType")+r(n.userToken,"userToken")+r(n.numFacets,"numFacets"),n.customFieldFilters)for(var a=0;a<n.customFieldFilters.length;a++)o=o+"&customField="+n.customFieldFilters[a];if(n.facetFields)for(a=0;a<n.facetFields.length;a++)o=o+"&facet="+n.facetFields[a];if(n.personalizationEvents&&Array.isArray(n.personalizationEvents))for(a=0;a<n.personalizationEvents.length;a++){var u=n.personalizationEvents[a],c=Object.keys(u);o=o+"&personalizationEvent="+encodeURIComponent(c+"="+u[c])}n.filterObject&&(o=o+"&filter="+JSON.stringify(n.filterObject))}}else"suggest"===e&&(o=r(n.suggestionsSize,"size"),s=n.suggestionsPrefix);fetch("https://api.addsearch.com/v1/"+e+"/"+t+"?term="+s+o).then((function(t){return t.json()})).then((function(t){i(t)})).catch((function(t){console.log(t),i({error:{response:500,message:"invalid server response"}})}))}else i({error:{response:400,message:"invalid query type"}})}},function(t,e){var n,i,r=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(t){if(n===setTimeout)return setTimeout(t,0);if((n===s||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:s}catch(t){n=s}try{i="function"==typeof clearTimeout?clearTimeout:o}catch(t){i=o}}();var u,c=[],h=!1,f=-1;function l(){h&&u&&(h=!1,u.length?c=u.concat(c):f=-1,c.length&&d())}function d(){if(!h){var t=a(l);h=!0;for(var e=c.length;e;){for(u=c,c=[];++f<e;)u&&u[f].run();f=-1,e=c.length}u=null,h=!1,function(t){if(i===clearTimeout)return clearTimeout(t);if((i===o||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(t);try{i(t)}catch(e){try{return i.call(null,t)}catch(e){return i.call(this,t)}}}(t)}}function p(t,e){this.fun=t,this.array=e}function g(){}r.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];c.push(new p(t,e)),1!==c.length||h||a(d)},p.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=g,r.addListener=g,r.once=g,r.off=g,r.removeListener=g,r.removeAllListeners=g,r.emit=g,r.prependListener=g,r.prependOnceListener=g,r.listeners=function(t){return[]},r.binding=function(t){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(t){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";n.r(e),n.d(e,"Headers",(function(){return c})),n.d(e,"Request",(function(){return y})),n.d(e,"Response",(function(){return m})),n.d(e,"DOMException",(function(){return w})),n.d(e,"fetch",(function(){return _}));var i={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(i.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],s=ArrayBuffer.isView||function(t){return t&&r.indexOf(Object.prototype.toString.call(t))>-1};function o(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function a(t){return"string"!=typeof t&&(t=String(t)),t}function u(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return i.iterable&&(e[Symbol.iterator]=function(){return e}),e}function c(t){this.map={},t instanceof c?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function h(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function f(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function l(t){var e=new FileReader,n=f(e);return e.readAsArrayBuffer(t),n}function d(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():i.arrayBuffer&&i.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=d(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||s(t))?this._bodyArrayBuffer=d(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i.blob&&(this.blob=function(){var t=h(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?h(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(l)}),this.text=function(){var t,e,n,i=h(this);if(i)return i;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=f(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),i=0;i<e.length;i++)n[i]=String.fromCharCode(e[i]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i.formData&&(this.formData=function(){return this.text().then(b)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(t,e){t=o(t),e=a(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},c.prototype.delete=function(t){delete this.map[o(t)]},c.prototype.get=function(t){return t=o(t),this.has(t)?this.map[t]:null},c.prototype.has=function(t){return this.map.hasOwnProperty(o(t))},c.prototype.set=function(t,e){this.map[o(t)]=a(e)},c.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},c.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),u(t)},c.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),u(t)},c.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),u(t)},i.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,e){var n,i,r=(e=e||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new c(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new c(e.headers)),this.method=(n=e.method||this.method||"GET",i=n.toUpperCase(),g.indexOf(i)>-1?i:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function b(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var n=t.split("="),i=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(i),decodeURIComponent(r))}})),e}function m(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new c(e.headers),this.url=e.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},p.call(y.prototype),p.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},m.error=function(){var t=new m(null,{status:0,statusText:""});return t.type="error",t};var v=[301,302,303,307,308];m.redirect=function(t,e){if(-1===v.indexOf(e))throw new RangeError("Invalid status code");return new m(null,{status:e,headers:{location:t}})};var w=self.DOMException;try{new w}catch(t){(w=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),w.prototype.constructor=w}function _(t,e){return new Promise((function(n,r){var s=new y(t,e);if(s.signal&&s.signal.aborted)return r(new w("Aborted","AbortError"));var o=new XMLHttpRequest;function a(){o.abort()}o.onload=function(){var t,e,i={status:o.status,statusText:o.statusText,headers:(t=o.getAllResponseHeaders()||"",e=new c,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),i=n.shift().trim();if(i){var r=n.join(":").trim();e.append(i,r)}})),e)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var r="response"in o?o.response:o.responseText;n(new m(r,i))},o.onerror=function(){r(new TypeError("Network request failed"))},o.ontimeout=function(){r(new TypeError("Network request failed"))},o.onabort=function(){r(new w("Aborted","AbortError"))},o.open(s.method,s.url,!0),"include"===s.credentials?o.withCredentials=!0:"omit"===s.credentials&&(o.withCredentials=!1),"responseType"in o&&i.blob&&(o.responseType="blob"),s.headers.forEach((function(t,e){o.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",a),o.onreadystatechange=function(){4===o.readyState&&s.signal.removeEventListener("abort",a)}),o.send(void 0===s._bodyInit?null:s._bodyInit)}))}_.polyfill=!0,self.fetch||(self.fetch=_,self.Headers=c,self.Request=y,self.Response=m)},function(t,e,n){"use strict";n(0).polyfill(),n(1);t.exports=function(t,e){"undefined"!=typeof window&&window.navigator&&window.navigator.sendBeacon?navigator.sendBeacon("https://api.addsearch.com/v1/stats/"+t+"/",JSON.stringify(e)):fetch("https://api.addsearch.com/v1/stats/"+t+"/",{method:"POST",headers:{"Content-Type":"text/plain"},body:JSON.stringify(e)})}},function(t,e,n){"use strict";t.exports=function(){this.settings={keyword:"*",callback:null,fuzzy:"auto",paging:{page:1,pageSize:10,sortBy:"relevance",sortOrder:"desc"},customFieldFilters:[],userToken:null,suggestionsSize:10,facetFields:[]},this.getSettings=function(){return this.settings},this.setKeyword=function(t){this.settings.keyword=t||"*"},this.setCallback=function(t){this.settings.callback=t},this.setSuggestionsPrefix=function(t){this.settings.suggestionsPrefix=t},this.setSuggestionsSize=function(t){this.settings.suggestionsSize=t},this.setLanguage=function(t){if(t&&2!==t.length)throw'use 2-char language code (e.g. "en")';this.settings.lang=t},this.setFuzzyMatch=function(t){if(!0!==t&&!1!==t&&"auto"!==t)throw"fuzzy matching can be true, false, or 'auto'";this.settings.fuzzy=t},this.setCollectAnalytics=function(t){this.settings.collectAnalytics=t},this.setCategoryFilters=function(t){this.settings.categories=t},this.setFilterObject=function(t){this.settings.filterObject=t},this.setPriceRangeFilter=function(t,e){this.settings.priceFromCents=t,this.settings.priceToCents=e},this.addCustomFieldFilter=function(t,e){var n=encodeURIComponent(t+"="+e);-1===this.settings.customFieldFilters.indexOf(n)&&this.settings.customFieldFilters.push(n)},this.removeCustomFieldFilter=function(t,e){var n=!1,i=encodeURIComponent(t+"="+e);e||(n=!0,i=encodeURIComponent(t+"="));for(var r=this.settings.customFieldFilters.length;r>0;r--){var s=this.settings.customFieldFilters[r-1];n&&0===s.indexOf(i)?this.settings.customFieldFilters.splice(r-1,1):s===i&&this.settings.customFieldFilters.splice(r-1,1)}},this.setDateFilter=function(t,e){this.settings.dateFrom=t,this.settings.dateTo=e},this.setKeyword=function(t){this.settings.keyword=t||"*"},this.setJWT=function(t){this.settings.jwt=t},this.setUserToken=function(t){this.settings.userToken=t},this.setPersonalizationEvents=function(t){this.settings.personalizationEvents=t},this.setResultType=function(t){this.settings.resultType=t},this.addFacetField=function(t){-1===this.settings.facetFields.indexOf(t)&&this.settings.facetFields.push(t)},this.setNumberOfFacets=function(t){this.settings.numFacets=t},this.setPaging=function(t,e,n,i){if(t<1)throw"page must be 1 or bigger";if(e<1||e>300)throw"pageSize must be 1-300";if("asc"!==i&&"desc"!==i)throw"sortOrder must be asc or desc";this.settings.paging.page=t,this.settings.paging.pageSize=e,this.settings.paging.sortBy=n,this.settings.paging.sortOrder=i},this.setShuffleAndLimitTo=function(t){this.settings.shuffleAndLimitTo=t},this.nextPage=function(){this.settings.paging.page=this.settings.paging.page+1},this.previousPage=function(){this.settings.paging.page>0&&(this.settings.paging.page=this.settings.paging.page-1)}}},function(t,e){t.exports={isFunction:function(t){return t&&"[object Function]"==={}.toString.call(t)}}}]); | ||
*/var i;i=function(){"use strict";function t(t){return"function"==typeof t}var i=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)},s=0,r=void 0,o=void 0,a=function(t,e){p[s]=t,p[s+1]=e,2===(s+=2)&&(o?o(g):w())},u="undefined"!=typeof window?window:void 0,c=u||{},l=c.MutationObserver||c.WebKitMutationObserver,h="undefined"==typeof self&&void 0!==e&&"[object process]"==={}.toString.call(e),f="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function d(){var t=setTimeout;return function(){return t(g,1)}}var p=new Array(1e3);function g(){for(var t=0;t<s;t+=2)(0,p[t])(p[t+1]),p[t]=void 0,p[t+1]=void 0;s=0}var y,m,b,v,w=void 0;function _(t,e){var n=this,i=new this.constructor(A);void 0===i[T]&&L(i);var s=n._state;if(s){var r=arguments[s-1];a((function(){return R(s,i,r,n._result)}))}else C(n,i,t,e);return i}function F(t){if(t&&"object"==typeof t&&t.constructor===this)return t;var e=new this(A);return E(e,t),e}h?w=function(){return e.nextTick(g)}:l?(m=0,b=new l(g),v=document.createTextNode(""),b.observe(v,{characterData:!0}),w=function(){v.data=m=++m%2}):f?((y=new MessageChannel).port1.onmessage=g,w=function(){return y.port2.postMessage(0)}):w=void 0===u?function(){try{var t=Function("return this")().require("vertx");return void 0!==(r=t.runOnLoop||t.runOnContext)?function(){r(g)}:d()}catch(t){return d()}}():d();var T=Math.random().toString(36).substring(2);function A(){}var S=void 0,x=1,O=2;function P(e,n,i){n.constructor===e.constructor&&i===_&&n.constructor.resolve===F?function(t,e){e._state===x?z(t,e._result):e._state===O?k(t,e._result):C(e,void 0,(function(e){return E(t,e)}),(function(e){return k(t,e)}))}(e,n):void 0===i?z(e,n):t(i)?function(t,e,n){a((function(t){var i=!1,s=function(t,e,n,i){try{t.call(e,n,i)}catch(t){return t}}(n,e,(function(n){i||(i=!0,e!==n?E(t,n):z(t,n))}),(function(e){i||(i=!0,k(t,e))}),t._label);!i&&s&&(i=!0,k(t,s))}),t)}(e,n,i):z(e,n)}function E(t,e){if(t===e)k(t,new TypeError("You cannot resolve a promise with itself"));else if(s=typeof(i=e),null===i||"object"!==s&&"function"!==s)z(t,e);else{var n=void 0;try{n=e.then}catch(e){return void k(t,e)}P(t,e,n)}var i,s}function j(t){t._onerror&&t._onerror(t._result),B(t)}function z(t,e){t._state===S&&(t._result=e,t._state=x,0!==t._subscribers.length&&a(B,t))}function k(t,e){t._state===S&&(t._state=O,t._result=e,a(j,t))}function C(t,e,n,i){var s=t._subscribers,r=s.length;t._onerror=null,s[r]=e,s[r+x]=n,s[r+O]=i,0===r&&t._state&&a(B,t)}function B(t){var e=t._subscribers,n=t._state;if(0!==e.length){for(var i=void 0,s=void 0,r=t._result,o=0;o<e.length;o+=3)i=e[o],s=e[o+n],i?R(n,i,s,r):s(r);t._subscribers.length=0}}function R(e,n,i,s){var r=t(i),o=void 0,a=void 0,u=!0;if(r){try{o=i(s)}catch(t){u=!1,a=t}if(n===o)return void k(n,new TypeError("A promises callback cannot return that same promise."))}else o=s;n._state!==S||(r&&u?E(n,o):!1===u?k(n,a):e===x?z(n,o):e===O&&k(n,o))}var U=0;function L(t){t[T]=U++,t._state=void 0,t._result=void 0,t._subscribers=[]}var I=function(){function t(t,e){this._instanceConstructor=t,this.promise=new t(A),this.promise[T]||L(this.promise),i(e)?(this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?z(this.promise,this._result):(this.length=this.length||0,this._enumerate(e),0===this._remaining&&z(this.promise,this._result))):k(this.promise,new Error("Array Methods must be provided an Array"))}return t.prototype._enumerate=function(t){for(var e=0;this._state===S&&e<t.length;e++)this._eachEntry(t[e],e)},t.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,i=n.resolve;if(i===F){var s=void 0,r=void 0,o=!1;try{s=t.then}catch(t){o=!0,r=t}if(s===_&&t._state!==S)this._settledAt(t._state,e,t._result);else if("function"!=typeof s)this._remaining--,this._result[e]=t;else if(n===D){var a=new n(A);o?k(a,r):P(a,t,s),this._willSettleAt(a,e)}else this._willSettleAt(new n((function(e){return e(t)})),e)}else this._willSettleAt(i(t),e)},t.prototype._settledAt=function(t,e,n){var i=this.promise;i._state===S&&(this._remaining--,t===O?k(i,n):this._result[e]=n),0===this._remaining&&z(i,this._result)},t.prototype._willSettleAt=function(t,e){var n=this;C(t,void 0,(function(t){return n._settledAt(x,e,t)}),(function(t){return n._settledAt(O,e,t)}))},t}(),D=function(){function e(t){this[T]=U++,this._result=this._state=void 0,this._subscribers=[],A!==t&&("function"!=typeof t&&function(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}(),this instanceof e?function(t,e){try{e((function(e){E(t,e)}),(function(e){k(t,e)}))}catch(e){k(t,e)}}(this,t):function(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}())}return e.prototype.catch=function(t){return this.then(null,t)},e.prototype.finally=function(e){var n=this.constructor;return t(e)?this.then((function(t){return n.resolve(e()).then((function(){return t}))}),(function(t){return n.resolve(e()).then((function(){throw t}))})):this.then(e,e)},e}();return D.prototype.then=_,D.all=function(t){return new I(this,t).promise},D.race=function(t){var e=this;return i(t)?new e((function(n,i){for(var s=t.length,r=0;r<s;r++)e.resolve(t[r]).then(n,i)})):new e((function(t,e){return e(new TypeError("You must pass an array to race."))}))},D.resolve=F,D.reject=function(t){var e=new this(A);return k(e,t),e},D._setScheduler=function(t){o=t},D._setAsap=function(t){a=t},D._asap=a,D.polyfill=function(){var t=void 0;if(void 0!==n)t=n;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var i=null;try{i=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===i&&!e.cast)return}t.Promise=D},D.Promise=D,D},t.exports=i()}).call(this,n(4),n(5))},function(t,e,n){n(6),t.exports=self.fetch.bind(self)},function(t,e,n){"use strict";var i=n(3),s=n(7),r=n(8),o=n(9);t.exports=function(t){this.sitekey=t,this.settings=new r,this.sessionId=("a-"+1e8*Math.random()).substring(0,10),this.search=function(t,e){var n=null,s=null;if(t&&o.isFunction(e))n=t,s=e;else if(!e&&o.isFunction(t))n=this.settings.getSettings().keyword,s=t;else{if(!this.settings.getSettings().callback)throw"Illegal search parameters. Should be (keyword, callbackFunction) or (callbackFunction)";n=this.settings.getSettings().keyword,s=this.settings.getSettings().callback}this.settings.setCallback(s),this.settings.setKeyword(n),i(this.sitekey,"search",this.settings.getSettings(),s)},this.suggestions=function(t,e){if(!t||!e||!o.isFunction(e))throw"Illegal suggestions parameters. Should be (prefix, callbackFunction)";this.settings.setSuggestionsPrefix(t),i(this.sitekey,"suggest",this.settings.getSettings(),e)},this.autocomplete=function(t,e,n){if(!(t&&e&&n&&o.isFunction(n)))throw"Illegal autocomplete parameters. Should be (field, prefix, callbackFunction)";this.settings.setAutocompleteParams(t,e),i(this.sitekey,"autocomplete",this.settings.getSettings(),n)},this.getSettings=function(){return this.settings.getSettings()},this.setLanguage=function(t){this.settings.setLanguage(t)},this.setCategoryFilters=function(t){this.settings.setCategoryFilters(t)},this.addCustomFieldFilter=function(t,e){this.settings.addCustomFieldFilter(t,e)},this.removeCustomFieldFilter=function(t,e){this.settings.removeCustomFieldFilter(t,e)},this.setPriceRangeFilter=function(t,e){this.settings.setPriceRangeFilter(t,e)},this.setDateFilter=function(t,e){this.settings.setDateFilter(t,e)},this.setJWT=function(t){this.settings.setJWT(t)},this.setUserToken=function(t){this.settings.setUserToken(t)},this.setPaging=function(t,e,n,i){this.settings.setPaging(t,e,n,i)},this.nextPage=function(){this.settings.nextPage()},this.previousPage=function(){this.settings.previousPage()},this.setSuggestionsSize=function(t){this.settings.setSuggestionsSize(t)},this.setAutocompleteSize=function(t){this.settings.setAutocompleteSize(t)},this.addFacetField=function(t){this.settings.addFacetField(t)},this.setNumberOfFacets=function(t){this.settings.setNumberOfFacets(t)},this.setResultType=function(t){this.settings.setResultType(t)},this.setPersonalizationEvents=function(t){this.settings.setPersonalizationEvents(t)},this.setFilterObject=function(t){this.settings.setFilterObject(t)},this.setShuffleAndLimitTo=function(t){this.settings.setShuffleAndLimitTo(t)},this.setFuzzyMatch=function(t){this.settings.setFuzzyMatch(t)},this.setCollectAnalytics=function(t){this.settings.setCollectAnalytics(t)},this.searchResultClicked=function(t,e){var n={action:"click",session:this.sessionId,keyword:this.settings.getSettings().keyword,docid:t,position:e};s(this.sitekey,n)},this.useFuzzyMatch=function(t){this.settings.setFuzzyMatch(t)}}},function(t,e,n){"use strict";n(0).polyfill(),n(1);t.exports=function(t,e,n,i){var s=function(t,e){return t||!1===t?"&"+e+"="+t:""};if("search"===e||"suggest"===e||"autocomplete"===e){var r="",o="",a=null;if("search"===e){if(a=e,r=(r=n.keyword).replace(/ and /g," AND ").replace(/ or /g," OR ").replace(/ not /g," NOT "),r=encodeURIComponent(r),"search"===e){if(o=s(n.lang,"lang")+s(n.fuzzy,"fuzzy")+s(n.collectAnalytics,"collectAnalytics")+s(n.categories,"categories")+s(n.priceFromCents,"priceFromCents")+s(n.priceToCents,"priceToCents")+s(n.dateFrom,"dateFrom")+s(n.dateTo,"dateTo")+s(n.paging.page,"page")+s(n.paging.pageSize,"limit")+s(n.paging.sortBy,"sort")+s(n.paging.sortOrder,"order")+s(n.shuffleAndLimitTo,"shuffleAndLimitTo")+s(n.jwt,"jwt")+s(n.resultType,"resultType")+s(n.userToken,"userToken")+s(n.numFacets,"numFacets"),n.customFieldFilters)for(var u=0;u<n.customFieldFilters.length;u++)o=o+"&customField="+n.customFieldFilters[u];if(n.facetFields)for(u=0;u<n.facetFields.length;u++)o=o+"&facet="+n.facetFields[u];if(n.personalizationEvents&&Array.isArray(n.personalizationEvents))for(u=0;u<n.personalizationEvents.length;u++){var c=n.personalizationEvents[u],l=Object.keys(c);o=o+"&personalizationEvent="+encodeURIComponent(l+"="+c[l])}n.filterObject&&(o=o+"&filter="+JSON.stringify(n.filterObject))}}else"suggest"===e?(a=e,o=s(n.suggestionsSize,"size"),r=n.suggestionsPrefix):"autocomplete"===e&&(a="autocomplete/document-field",o=s(n.autocomplete.field,"source")+s(n.autocomplete.size,"size"),r=n.autocomplete.prefix);fetch("https://api.addsearch.com/v1/"+a+"/"+t+"?term="+r+o).then((function(t){return t.json()})).then((function(t){i(t)})).catch((function(t){console.log(t),i({error:{response:500,message:"invalid server response"}})}))}else i({error:{response:400,message:"invalid query type"}})}},function(t,e){var n,i,s=t.exports={};function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(t){if(n===setTimeout)return setTimeout(t,0);if((n===r||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:r}catch(t){n=r}try{i="function"==typeof clearTimeout?clearTimeout:o}catch(t){i=o}}();var u,c=[],l=!1,h=-1;function f(){l&&u&&(l=!1,u.length?c=u.concat(c):h=-1,c.length&&d())}function d(){if(!l){var t=a(f);l=!0;for(var e=c.length;e;){for(u=c,c=[];++h<e;)u&&u[h].run();h=-1,e=c.length}u=null,l=!1,function(t){if(i===clearTimeout)return clearTimeout(t);if((i===o||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(t);try{i(t)}catch(e){try{return i.call(null,t)}catch(e){return i.call(this,t)}}}(t)}}function p(t,e){this.fun=t,this.array=e}function g(){}s.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];c.push(new p(t,e)),1!==c.length||l||a(d)},p.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=g,s.addListener=g,s.once=g,s.off=g,s.removeListener=g,s.removeAllListeners=g,s.emit=g,s.prependListener=g,s.prependOnceListener=g,s.listeners=function(t){return[]},s.binding=function(t){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(t){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";n.r(e),n.d(e,"Headers",(function(){return c})),n.d(e,"Request",(function(){return y})),n.d(e,"Response",(function(){return b})),n.d(e,"DOMException",(function(){return w})),n.d(e,"fetch",(function(){return _}));var i={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(i.arrayBuffer)var s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],r=ArrayBuffer.isView||function(t){return t&&s.indexOf(Object.prototype.toString.call(t))>-1};function o(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function a(t){return"string"!=typeof t&&(t=String(t)),t}function u(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return i.iterable&&(e[Symbol.iterator]=function(){return e}),e}function c(t){this.map={},t instanceof c?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function l(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function h(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function f(t){var e=new FileReader,n=h(e);return e.readAsArrayBuffer(t),n}function d(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():i.arrayBuffer&&i.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=d(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||r(t))?this._bodyArrayBuffer=d(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i.blob&&(this.blob=function(){var t=l(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?l(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var t,e,n,i=l(this);if(i)return i;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=h(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),i=0;i<e.length;i++)n[i]=String.fromCharCode(e[i]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i.formData&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(t,e){t=o(t),e=a(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},c.prototype.delete=function(t){delete this.map[o(t)]},c.prototype.get=function(t){return t=o(t),this.has(t)?this.map[t]:null},c.prototype.has=function(t){return this.map.hasOwnProperty(o(t))},c.prototype.set=function(t,e){this.map[o(t)]=a(e)},c.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},c.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),u(t)},c.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),u(t)},c.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),u(t)},i.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var g=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,e){var n,i,s=(e=e||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new c(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,s||null==t._bodyInit||(s=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new c(e.headers)),this.method=(n=e.method||this.method||"GET",i=n.toUpperCase(),g.indexOf(i)>-1?i:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&s)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(s)}function m(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var n=t.split("="),i=n.shift().replace(/\+/g," "),s=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(i),decodeURIComponent(s))}})),e}function b(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new c(e.headers),this.url=e.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},p.call(y.prototype),p.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},b.error=function(){var t=new b(null,{status:0,statusText:""});return t.type="error",t};var v=[301,302,303,307,308];b.redirect=function(t,e){if(-1===v.indexOf(e))throw new RangeError("Invalid status code");return new b(null,{status:e,headers:{location:t}})};var w=self.DOMException;try{new w}catch(t){(w=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),w.prototype.constructor=w}function _(t,e){return new Promise((function(n,s){var r=new y(t,e);if(r.signal&&r.signal.aborted)return s(new w("Aborted","AbortError"));var o=new XMLHttpRequest;function a(){o.abort()}o.onload=function(){var t,e,i={status:o.status,statusText:o.statusText,headers:(t=o.getAllResponseHeaders()||"",e=new c,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),i=n.shift().trim();if(i){var s=n.join(":").trim();e.append(i,s)}})),e)};i.url="responseURL"in o?o.responseURL:i.headers.get("X-Request-URL");var s="response"in o?o.response:o.responseText;n(new b(s,i))},o.onerror=function(){s(new TypeError("Network request failed"))},o.ontimeout=function(){s(new TypeError("Network request failed"))},o.onabort=function(){s(new w("Aborted","AbortError"))},o.open(r.method,r.url,!0),"include"===r.credentials?o.withCredentials=!0:"omit"===r.credentials&&(o.withCredentials=!1),"responseType"in o&&i.blob&&(o.responseType="blob"),r.headers.forEach((function(t,e){o.setRequestHeader(e,t)})),r.signal&&(r.signal.addEventListener("abort",a),o.onreadystatechange=function(){4===o.readyState&&r.signal.removeEventListener("abort",a)}),o.send(void 0===r._bodyInit?null:r._bodyInit)}))}_.polyfill=!0,self.fetch||(self.fetch=_,self.Headers=c,self.Request=y,self.Response=b)},function(t,e,n){"use strict";n(0).polyfill(),n(1);t.exports=function(t,e){"undefined"!=typeof window&&window.navigator&&window.navigator.sendBeacon?navigator.sendBeacon("https://api.addsearch.com/v1/stats/"+t+"/",JSON.stringify(e)):fetch("https://api.addsearch.com/v1/stats/"+t+"/",{method:"POST",headers:{"Content-Type":"text/plain"},body:JSON.stringify(e)})}},function(t,e,n){"use strict";t.exports=function(){this.settings={keyword:"*",callback:null,fuzzy:"auto",paging:{page:1,pageSize:10,sortBy:"relevance",sortOrder:"desc"},customFieldFilters:[],userToken:null,suggestionsSize:10,facetFields:[],autocomplete:{size:10}},this.getSettings=function(){return this.settings},this.setKeyword=function(t){this.settings.keyword=t||"*"},this.setCallback=function(t){this.settings.callback=t},this.setSuggestionsPrefix=function(t){this.settings.suggestionsPrefix=t},this.setSuggestionsSize=function(t){this.settings.suggestionsSize=t},this.setAutocompleteSize=function(t){this.settings.autocomplete.size=t},this.setAutocompleteParams=function(t,e){this.settings.autocomplete.field=t,this.settings.autocomplete.prefix=e},this.setLanguage=function(t){if(t&&2!==t.length)throw'use 2-char language code (e.g. "en")';this.settings.lang=t},this.setFuzzyMatch=function(t){if(!0!==t&&!1!==t&&"auto"!==t)throw"fuzzy matching can be true, false, or 'auto'";this.settings.fuzzy=t},this.setCollectAnalytics=function(t){this.settings.collectAnalytics=t},this.setCategoryFilters=function(t){this.settings.categories=t},this.setFilterObject=function(t){this.settings.filterObject=t},this.setPriceRangeFilter=function(t,e){this.settings.priceFromCents=t,this.settings.priceToCents=e},this.addCustomFieldFilter=function(t,e){var n=encodeURIComponent(t+"="+e);-1===this.settings.customFieldFilters.indexOf(n)&&this.settings.customFieldFilters.push(n)},this.removeCustomFieldFilter=function(t,e){var n=!1,i=encodeURIComponent(t+"="+e);e||(n=!0,i=encodeURIComponent(t+"="));for(var s=this.settings.customFieldFilters.length;s>0;s--){var r=this.settings.customFieldFilters[s-1];n&&0===r.indexOf(i)?this.settings.customFieldFilters.splice(s-1,1):r===i&&this.settings.customFieldFilters.splice(s-1,1)}},this.setDateFilter=function(t,e){this.settings.dateFrom=t,this.settings.dateTo=e},this.setKeyword=function(t){this.settings.keyword=t||"*"},this.setJWT=function(t){this.settings.jwt=t},this.setUserToken=function(t){this.settings.userToken=t},this.setPersonalizationEvents=function(t){this.settings.personalizationEvents=t},this.setResultType=function(t){this.settings.resultType=t},this.addFacetField=function(t){-1===this.settings.facetFields.indexOf(t)&&this.settings.facetFields.push(t)},this.setNumberOfFacets=function(t){this.settings.numFacets=t},this.setPaging=function(t,e,n,i){if(t<1)throw"page must be 1 or bigger";if(e<1||e>300)throw"pageSize must be 1-300";if("asc"!==i&&"desc"!==i)throw"sortOrder must be asc or desc";this.settings.paging.page=t,this.settings.paging.pageSize=e,this.settings.paging.sortBy=n,this.settings.paging.sortOrder=i},this.setShuffleAndLimitTo=function(t){this.settings.shuffleAndLimitTo=t},this.nextPage=function(){this.settings.paging.page=this.settings.paging.page+1},this.previousPage=function(){this.settings.paging.page>0&&(this.settings.paging.page=this.settings.paging.page-1)}}},function(t,e){t.exports={isFunction:function(t){return t&&"[object Function]"==={}.toString.call(t)}}}]); |
{ | ||
"name": "addsearch-js-client", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "AddSearch API JavaScript client", | ||
@@ -43,12 +43,12 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@babel/cli": "^7.8.3", | ||
"@babel/core": "^7.8.3", | ||
"@babel/preset-env": "^7.8.3", | ||
"@babel/register": "^7.8.3", | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.8.4", | ||
"@babel/preset-env": "^7.8.4", | ||
"@babel/register": "^7.7.7", | ||
"babel-loader": "^8.0.6", | ||
"esm": "^3.2.25", | ||
"fetch-mock": "^8.3.1", | ||
"mocha": "^7.0.0", | ||
"fetch-mock": "^8.3.2", | ||
"mocha": "^6.2.2", | ||
"node-fetch": "^2.6.0", | ||
"uglify-js": "^3.7.6", | ||
"uglify-js": "^3.7.7", | ||
"webpack": "^4.41.5", | ||
@@ -55,0 +55,0 @@ "webpack-cli": "^3.3.10" |
@@ -60,4 +60,5 @@ # AddSearch Search API Client for JavaScript | ||
#### Fetch search suggestions | ||
Search suggestions are keywords and search phrases that real users have used in your search. Configure Search | ||
suggestions on AddSearch Dashboard before using this function. | ||
```js | ||
// Configure Search suggestions on AddSearch Dashboard first | ||
// Get suggestions starting with a specific prefix | ||
@@ -67,3 +68,3 @@ client.suggestions('a', callback); | ||
#### Number of search suggestions | ||
#### Set the number of search suggestions to fetch | ||
```js | ||
@@ -74,2 +75,16 @@ // Number of search suggestions to fetch (default 10) | ||
#### Fetch custom field autocompletion | ||
Custom fields autocomplete can be used for predictive search. For example, product names or categories can be | ||
suggested as the keyword is being typed in. | ||
```js | ||
// Fetch custom field values starting with a specific prefix. In this example, results could be "adidas, apple, azure" | ||
client.autocomplete('custom_fields.brand', 'a', callback); | ||
``` | ||
#### Set the number of custom field autocompletion results to fetch | ||
```js | ||
// Number of autocompletion results to fetch (default 10) | ||
client.setAutocompleteSize(20); | ||
``` | ||
#### Search with fuzzy matching | ||
@@ -169,2 +184,18 @@ ```js | ||
#### Set filtering object | ||
Set complex filtering object that can contain nested *and*, *or*, *not*, and *range* filters. | ||
```js | ||
// Find results where brand is apple, color is not white, and price is between 200 and 500 | ||
var filter = { | ||
'and':[ | ||
{'custom_fields.brand': 'apple'}, | ||
{'not': {'custom_fields.color': 'white'}}, | ||
{'range': {'custom_fields.price': {'gt': 200, 'lt':500}}} | ||
] | ||
}; | ||
client.setFilterObject(filter); | ||
``` | ||
#### Manage paging | ||
@@ -171,0 +202,0 @@ Set page number, page size and sorting parameters. It's possible to order results by: |
@@ -23,3 +23,3 @@ 'use strict'; | ||
// Validate query type | ||
if (type !== 'search' && type !== 'suggest') { | ||
if (type !== 'search' && type !== 'suggest' && type !== 'autocomplete') { | ||
cb({error: {response: RESPONSE_BAD_REQUEST, message: 'invalid query type'}}); | ||
@@ -33,4 +33,10 @@ return; | ||
// API Path (eq. /search, /suggest, /autocomplete/document-field) | ||
var apiPath = null; | ||
// Search | ||
if (type === 'search') { | ||
// Path | ||
apiPath = type; | ||
// Keyword | ||
@@ -98,2 +104,3 @@ kw = settings.keyword; | ||
else if (type === 'suggest') { | ||
apiPath = type; | ||
qs = settingToQueryParam(settings.suggestionsSize, 'size'); | ||
@@ -103,5 +110,13 @@ kw = settings.suggestionsPrefix; | ||
// Autocomplete | ||
else if (type === 'autocomplete') { | ||
apiPath = 'autocomplete/document-field'; | ||
qs = settingToQueryParam(settings.autocomplete.field, 'source') + | ||
settingToQueryParam(settings.autocomplete.size, 'size'); | ||
kw = settings.autocomplete.prefix; | ||
} | ||
// Execute API call | ||
fetch('https://api.addsearch.com/v1/' + type + '/' + sitekey + '?term=' + kw + qs) | ||
fetch('https://api.addsearch.com/v1/' + apiPath + '/' + sitekey + '?term=' + kw + qs) | ||
.then(function(response) { | ||
@@ -108,0 +123,0 @@ return response.json(); |
@@ -66,2 +66,16 @@ 'use strict'; | ||
/** | ||
* Fetch field autocompletes | ||
* | ||
* @param keyword | ||
*/ | ||
this.autocomplete = function(field, prefix, callback) { | ||
if (!field || !prefix || !callback || !util.isFunction(callback)) { | ||
throw "Illegal autocomplete parameters. Should be (field, prefix, callbackFunction)"; | ||
} | ||
this.settings.setAutocompleteParams(field, prefix); | ||
executeApiFetch(this.sitekey, 'autocomplete', this.settings.getSettings(), callback); | ||
} | ||
/** | ||
* Public functions | ||
@@ -82,2 +96,3 @@ */ | ||
this.setSuggestionsSize = function(size) { this.settings.setSuggestionsSize(size); } | ||
this.setAutocompleteSize = function(size) { this.settings.setAutocompleteSize(size); } | ||
this.addFacetField = function(fieldName) { this.settings.addFacetField(fieldName); } | ||
@@ -84,0 +99,0 @@ this.setNumberOfFacets = function(numFacets) { this.settings.setNumberOfFacets(numFacets); } |
@@ -17,3 +17,6 @@ 'use strict'; | ||
suggestionsSize: 10, | ||
facetFields: [] | ||
facetFields: [], | ||
autocomplete: { | ||
size: 10 | ||
} | ||
}; | ||
@@ -41,2 +44,11 @@ | ||
this.setAutocompleteSize = function(size) { | ||
this.settings.autocomplete.size = size; | ||
} | ||
this.setAutocompleteParams = function(field, prefix) { | ||
this.settings.autocomplete.field = field; | ||
this.settings.autocomplete.prefix = prefix; | ||
} | ||
this.setLanguage = function(language) { | ||
@@ -43,0 +55,0 @@ if (language && language.length !== 2) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54430
505
268