addsearch-js-client
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -8,2 +8,2 @@ 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){ | ||
* @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)},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||{},h=c.MutationObserver||c.WebKitMutationObserver,l="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,v,b,w=void 0;function F(t,e){var n=this,i=new this.constructor(S);void 0===i[T]&&B(i);var s=n._state;if(s){var r=arguments[s-1];a((function(){return z(s,i,r,n._result)}))}else k(n,i,t,e);return i}function _(t){if(t&&"object"==typeof t&&t.constructor===this)return t;var e=new this(S);return x(e,t),e}l?w=function(){return e.nextTick(g)}:h?(m=0,v=new h(g),b=document.createTextNode(""),v.observe(b,{characterData:!0}),w=function(){b.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 S(){}function A(e,n,i){n.constructor===e.constructor&&i===F&&n.constructor.resolve===_?function(t,e){1===e._state?O(t,e._result):2===e._state?P(t,e._result):k(e,void 0,(function(e){return x(t,e)}),(function(e){return P(t,e)}))}(e,n):void 0===i?O(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?x(t,n):O(t,n))}),(function(e){i||(i=!0,P(t,e))}),t._label);!i&&s&&(i=!0,P(t,s))}),t)}(e,n,i):O(e,n)}function x(t,e){if(t===e)P(t,new TypeError("You cannot resolve a promise with itself"));else if(s=typeof(i=e),null===i||"object"!==s&&"function"!==s)O(t,e);else{var n=void 0;try{n=e.then}catch(e){return void P(t,e)}A(t,e,n)}var i,s}function E(t){t._onerror&&t._onerror(t._result),j(t)}function O(t,e){void 0===t._state&&(t._result=e,t._state=1,0!==t._subscribers.length&&a(j,t))}function P(t,e){void 0===t._state&&(t._state=2,t._result=e,a(E,t))}function k(t,e,n,i){var s=t._subscribers,r=s.length;t._onerror=null,s[r]=e,s[r+1]=n,s[r+2]=i,0===r&&t._state&&a(j,t)}function j(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?z(n,i,s,r):s(r);t._subscribers.length=0}}function z(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 P(n,new TypeError("A promises callback cannot return that same promise."))}else o=s;void 0!==n._state||(r&&u?x(n,o):!1===u?P(n,a):1===e?O(n,o):2===e&&P(n,o))}var C=0;function B(t){t[T]=C++,t._state=void 0,t._result=void 0,t._subscribers=[]}var R=function(){function t(t,e){this._instanceConstructor=t,this.promise=new t(S),this.promise[T]||B(this.promise),i(e)?(this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?O(this.promise,this._result):(this.length=this.length||0,this._enumerate(e),0===this._remaining&&O(this.promise,this._result))):P(this.promise,new Error("Array Methods must be provided an Array"))}return t.prototype._enumerate=function(t){for(var e=0;void 0===this._state&&e<t.length;e++)this._eachEntry(t[e],e)},t.prototype._eachEntry=function(t,e){var n=this._instanceConstructor,i=n.resolve;if(i===_){var s=void 0,r=void 0,o=!1;try{s=t.then}catch(t){o=!0,r=t}if(s===F&&void 0!==t._state)this._settledAt(t._state,e,t._result);else if("function"!=typeof s)this._remaining--,this._result[e]=t;else if(n===I){var a=new n(S);o?P(a,r):A(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;void 0===i._state&&(this._remaining--,2===t?P(i,n):this._result[e]=n),0===this._remaining&&O(i,this._result)},t.prototype._willSettleAt=function(t,e){var n=this;k(t,void 0,(function(t){return n._settledAt(1,e,t)}),(function(t){return n._settledAt(2,e,t)}))},t}(),I=function(){function e(t){this[T]=C++,this._result=this._state=void 0,this._subscribers=[],S!==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){x(t,e)}),(function(e){P(t,e)}))}catch(e){P(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 I.prototype.then=F,I.all=function(t){return new R(this,t).promise},I.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."))}))},I.resolve=_,I.reject=function(t){var e=new this(S);return P(e,t),e},I._setScheduler=function(t){o=t},I._setAsap=function(t){a=t},I._asap=a,I.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=I},I.Promise=I,I},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),a=n(10),u=200;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),this.throttledSearchFetch||(this.throttledSearchFetch=a(u,i)),this.throttledSearchFetch(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),this.throttledSuggestionsFetch||(this.throttledSuggestionsFetch=a(u,i)),this.throttledSuggestionsFetch(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),this.throttledAutocompleteFetch||(this.throttledAutocompleteFetch=a(u,i)),this.throttledAutocompleteFetch(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.setThrottleTime=function(t){u=t},this.setStatsSessionId=function(t){this.sessionId=t},this.getStatsSessionId=function(){return this.sessionId},this.sendStatsEvent=function(t,e,n){if("search"===t){n={action:"search",session:this.sessionId,keyword:e,numberOfResults:n.numberOfResults};s(this.sitekey,n)}else{if("click"!==t)throw"Illegal sendStatsEvent type parameters. Should be search or click)";n={action:"click",session:this.sessionId,keyword:e,docid:n.documentId,position:n.position};s(this.sitekey,n)}},this.searchResultClicked=function(t,e){this.sendStatsEvent("click",this.settings.getSettings().keyword,{documentId:t,position:e})}}},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],h=Object.keys(c);o=o+"&personalizationEvent="+encodeURIComponent(h+"="+c[h])}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=[],h=!1,l=-1;function f(){h&&u&&(h=!1,u.length?c=u.concat(c):l=-1,c.length&&d())}function d(){if(!h){var t=a(f);h=!0;for(var e=c.length;e;){for(u=c,c=[];++l<e;)u&&u[l].run();l=-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(){}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||h||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 d})),n.d(e,"Request",(function(){return w})),n.d(e,"Response",(function(){return _})),n.d(e,"DOMException",(function(){return S})),n.d(e,"fetch",(function(){return A}));var i="URLSearchParams"in self,s="Symbol"in self&&"iterator"in Symbol,r="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),o="FormData"in self,a="ArrayBuffer"in self;if(a)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function h(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 l(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return s&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?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 p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function g(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function y(t){var e=new FileReader,n=g(e);return e.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:r&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:o&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:i&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a&&r&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=m(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=m(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&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r&&(this.blob=function(){var t=p(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?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,n,i=p(this);if(i)return i;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=g(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)},o&&(this.formData=function(){return this.text().then(F)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=h(t),e=l(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},d.prototype.delete=function(t){delete this.map[h(t)]},d.prototype.get=function(t){return t=h(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(h(t))},d.prototype.set=function(t,e){this.map[h(t)]=l(e)},d.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),f(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),f(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),f(t)},s&&(d.prototype[Symbol.iterator]=d.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var n,i,s=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(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 d(e.headers)),this.method=(n=e.method||this.method||"GET",i=n.toUpperCase(),b.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 F(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 _(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 d(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},v.call(w.prototype),v.call(_.prototype),_.prototype.clone=function(){return new _(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},_.error=function(){var t=new _(null,{status:0,statusText:""});return t.type="error",t};var T=[301,302,303,307,308];_.redirect=function(t,e){if(-1===T.indexOf(e))throw new RangeError("Invalid status code");return new _(null,{status:e,headers:{location:t}})};var S=self.DOMException;try{new S}catch(t){(S=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),S.prototype.constructor=S}function A(t,e){return new Promise((function(n,i){var s=new w(t,e);if(s.signal&&s.signal.aborted)return i(new S("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 d,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 _(s,i))},o.onerror=function(){i(new TypeError("Network request failed"))},o.ontimeout=function(){i(new TypeError("Network request failed"))},o.onabort=function(){i(new S("Aborted","AbortError"))},o.open(s.method,s.url,!0),"include"===s.credentials?o.withCredentials=!0:"omit"===s.credentials&&(o.withCredentials=!1),"responseType"in o&&r&&(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)}))}A.polyfill=!0,self.fetch||(self.fetch=A,self.Headers=d,self.Request=w,self.Response=_)},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)||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)}}},function(t,e){t.exports=function(t,e){var n,i=0;function s(){n&&clearTimeout(n)}return function(){var r=this,o=Date.now()-i,a=arguments;function u(){i=Date.now(),e.apply(r,a)}s(),o>t?u():n=setTimeout(u,t-o)}}}]); | ||
*/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||{},h=c.MutationObserver||c.WebKitMutationObserver,l="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,v,b,w=void 0;function _(t,e){var n=this,i=new this.constructor(S);void 0===i[T]&&B(i);var s=n._state;if(s){var r=arguments[s-1];a((function(){return z(s,i,r,n._result)}))}else k(n,i,t,e);return i}function F(t){if(t&&"object"==typeof t&&t.constructor===this)return t;var e=new this(S);return x(e,t),e}l?w=function(){return e.nextTick(g)}:h?(m=0,v=new h(g),b=document.createTextNode(""),v.observe(b,{characterData:!0}),w=function(){b.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 S(){}function A(e,n,i){n.constructor===e.constructor&&i===_&&n.constructor.resolve===F?function(t,e){1===e._state?O(t,e._result):2===e._state?P(t,e._result):k(e,void 0,(function(e){return x(t,e)}),(function(e){return P(t,e)}))}(e,n):void 0===i?O(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?x(t,n):O(t,n))}),(function(e){i||(i=!0,P(t,e))}),t._label);!i&&s&&(i=!0,P(t,s))}),t)}(e,n,i):O(e,n)}function x(t,e){if(t===e)P(t,new TypeError("You cannot resolve a promise with itself"));else if(s=typeof(i=e),null===i||"object"!==s&&"function"!==s)O(t,e);else{var n=void 0;try{n=e.then}catch(e){return void P(t,e)}A(t,e,n)}var i,s}function E(t){t._onerror&&t._onerror(t._result),j(t)}function O(t,e){void 0===t._state&&(t._result=e,t._state=1,0!==t._subscribers.length&&a(j,t))}function P(t,e){void 0===t._state&&(t._state=2,t._result=e,a(E,t))}function k(t,e,n,i){var s=t._subscribers,r=s.length;t._onerror=null,s[r]=e,s[r+1]=n,s[r+2]=i,0===r&&t._state&&a(j,t)}function j(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?z(n,i,s,r):s(r);t._subscribers.length=0}}function z(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 P(n,new TypeError("A promises callback cannot return that same promise."))}else o=s;void 0!==n._state||(r&&u?x(n,o):!1===u?P(n,a):1===e?O(n,o):2===e&&P(n,o))}var C=0;function B(t){t[T]=C++,t._state=void 0,t._result=void 0,t._subscribers=[]}var R=function(){function t(t,e){this._instanceConstructor=t,this.promise=new t(S),this.promise[T]||B(this.promise),i(e)?(this.length=e.length,this._remaining=e.length,this._result=new Array(this.length),0===this.length?O(this.promise,this._result):(this.length=this.length||0,this._enumerate(e),0===this._remaining&&O(this.promise,this._result))):P(this.promise,new Error("Array Methods must be provided an Array"))}return t.prototype._enumerate=function(t){for(var e=0;void 0===this._state&&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===_&&void 0!==t._state)this._settledAt(t._state,e,t._result);else if("function"!=typeof s)this._remaining--,this._result[e]=t;else if(n===I){var a=new n(S);o?P(a,r):A(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;void 0===i._state&&(this._remaining--,2===t?P(i,n):this._result[e]=n),0===this._remaining&&O(i,this._result)},t.prototype._willSettleAt=function(t,e){var n=this;k(t,void 0,(function(t){return n._settledAt(1,e,t)}),(function(t){return n._settledAt(2,e,t)}))},t}(),I=function(){function e(t){this[T]=C++,this._result=this._state=void 0,this._subscribers=[],S!==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){x(t,e)}),(function(e){P(t,e)}))}catch(e){P(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 I.prototype.then=_,I.all=function(t){return new R(this,t).promise},I.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."))}))},I.resolve=F,I.reject=function(t){var e=new this(S);return P(e,t),e},I._setScheduler=function(t){o=t},I._setAsap=function(t){a=t},I._asap=a,I.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=I},I.Promise=I,I},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),a=n(10),u=200;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),this.throttledSearchFetch||(this.throttledSearchFetch=a(u,i)),this.throttledSearchFetch(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),this.throttledSuggestionsFetch||(this.throttledSuggestionsFetch=a(u,i)),this.throttledSuggestionsFetch(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),this.throttledAutocompleteFetch||(this.throttledAutocompleteFetch=a(u,i)),this.throttledAutocompleteFetch(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.setThrottleTime=function(t){u=t},this.setStatsSessionId=function(t){this.sessionId=t},this.getStatsSessionId=function(){return this.sessionId},this.sendStatsEvent=function(t,e,n){if("search"===t){n={action:"search",session:this.sessionId,keyword:e,numberOfResults:n.numberOfResults};s(this.sitekey,n)}else{if("click"!==t)throw"Illegal sendStatsEvent type parameters. Should be search or click)";n={action:"click",session:this.sessionId,keyword:e,docid:n.documentId,position:n.position};s(this.sitekey,n)}},this.searchResultClicked=function(t,e){this.sendStatsEvent("click",this.settings.getSettings().keyword,{documentId:t,position:e})}}},function(t,e,n){"use strict";n(0).polyfill(),n(1);t.exports=function t(e,n,i,s,r){var o=function(t,e){return t||!1===t?"&"+e+"="+t:""};if("search"===n||"suggest"===n||"autocomplete"===n){var a="",u="",c=null;if("search"===n){c=n,a=(a=i.keyword).replace(/ and /g," AND ").replace(/ or /g," OR ").replace(/ not /g," NOT "),a=encodeURIComponent(a);var h=i.fuzzy;if("retry"===h&&(h=!0===r),"search"===n){if(u=o(i.lang,"lang")+o(h,"fuzzy")+o(i.collectAnalytics,"collectAnalytics")+o(i.categories,"categories")+o(i.priceFromCents,"priceFromCents")+o(i.priceToCents,"priceToCents")+o(i.dateFrom,"dateFrom")+o(i.dateTo,"dateTo")+o(i.paging.page,"page")+o(i.paging.pageSize,"limit")+o(i.paging.sortBy,"sort")+o(i.paging.sortOrder,"order")+o(i.shuffleAndLimitTo,"shuffleAndLimitTo")+o(i.jwt,"jwt")+o(i.resultType,"resultType")+o(i.userToken,"userToken")+o(i.numFacets,"numFacets"),i.customFieldFilters)for(var l=0;l<i.customFieldFilters.length;l++)u=u+"&customField="+i.customFieldFilters[l];if(i.facetFields)for(l=0;l<i.facetFields.length;l++)u=u+"&facet="+i.facetFields[l];if(i.personalizationEvents&&Array.isArray(i.personalizationEvents))for(l=0;l<i.personalizationEvents.length;l++){var f=i.personalizationEvents[l],d=Object.keys(f);u=u+"&personalizationEvent="+encodeURIComponent(d+"="+f[d])}i.filterObject&&(u=u+"&filter="+JSON.stringify(i.filterObject))}}else"suggest"===n?(c=n,u=o(i.suggestionsSize,"size"),a=i.suggestionsPrefix):"autocomplete"===n&&(c="autocomplete/document-field",u=o(i.autocomplete.field,"source")+o(i.autocomplete.size,"size"),a=i.autocomplete.prefix);fetch("https://api.addsearch.com/v1/"+c+"/"+e+"?term="+a+u).then((function(t){return t.json()})).then((function(o){if("search"===n&&"retry"===i.fuzzy&&0===o.total_hits&&!0!==r)t(e,n,i,s,!0);else{if(!0===r){var a=i.paging.pageSize;o.total_hits>=a&&(o.total_hits=a)}s(o)}})).catch((function(t){console.log(t),s({error:{response:500,message:"invalid server response"}})}))}else s({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=[],h=!1,l=-1;function f(){h&&u&&(h=!1,u.length?c=u.concat(c):l=-1,c.length&&d())}function d(){if(!h){var t=a(f);h=!0;for(var e=c.length;e;){for(u=c,c=[];++l<e;)u&&u[l].run();l=-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(){}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||h||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 d})),n.d(e,"Request",(function(){return w})),n.d(e,"Response",(function(){return F})),n.d(e,"DOMException",(function(){return S})),n.d(e,"fetch",(function(){return A}));var i="URLSearchParams"in self,s="Symbol"in self&&"iterator"in Symbol,r="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),o="FormData"in self,a="ArrayBuffer"in self;if(a)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function h(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 l(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return s&&(e[Symbol.iterator]=function(){return e}),e}function d(t){this.map={},t instanceof d?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 p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function g(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function y(t){var e=new FileReader,n=g(e);return e.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:r&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:o&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:i&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a&&r&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=m(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=m(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&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r&&(this.blob=function(){var t=p(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?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,n,i=p(this);if(i)return i;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=g(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)},o&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}d.prototype.append=function(t,e){t=h(t),e=l(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},d.prototype.delete=function(t){delete this.map[h(t)]},d.prototype.get=function(t){return t=h(t),this.has(t)?this.map[t]:null},d.prototype.has=function(t){return this.map.hasOwnProperty(h(t))},d.prototype.set=function(t,e){this.map[h(t)]=l(e)},d.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},d.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),f(t)},d.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),f(t)},d.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),f(t)},s&&(d.prototype[Symbol.iterator]=d.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var n,i,s=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new d(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 d(e.headers)),this.method=(n=e.method||this.method||"GET",i=n.toUpperCase(),b.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 _(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 F(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 d(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},v.call(w.prototype),v.call(F.prototype),F.prototype.clone=function(){return new F(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},F.error=function(){var t=new F(null,{status:0,statusText:""});return t.type="error",t};var T=[301,302,303,307,308];F.redirect=function(t,e){if(-1===T.indexOf(e))throw new RangeError("Invalid status code");return new F(null,{status:e,headers:{location:t}})};var S=self.DOMException;try{new S}catch(t){(S=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),S.prototype.constructor=S}function A(t,e){return new Promise((function(n,i){var s=new w(t,e);if(s.signal&&s.signal.aborted)return i(new S("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 d,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 F(s,i))},o.onerror=function(){i(new TypeError("Network request failed"))},o.ontimeout=function(){i(new TypeError("Network request failed"))},o.onabort=function(){i(new S("Aborted","AbortError"))},o.open(s.method,s.url,!0),"include"===s.credentials?o.withCredentials=!0:"omit"===s.credentials&&(o.withCredentials=!1),"responseType"in o&&r&&(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)}))}A.polyfill=!0,self.fetch||(self.fetch=A,self.Headers=d,self.Request=w,self.Response=F)},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&&"retry"!==t)throw"fuzzy matching can be true, false, 'auto', or 'retry'";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)||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)}}},function(t,e){t.exports=function(t,e){var n,i=0;function s(){n&&clearTimeout(n)}return function(){var r=this,o=Date.now()-i,a=arguments;function u(){i=Date.now(),e.apply(r,a)}s(),o>t?u():n=setTimeout(u,t-o)}}}]); |
{ | ||
"name": "addsearch-js-client", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "AddSearch API JavaScript client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ # AddSearch Search API Client for JavaScript | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/addsearch-js-client@0.2/dist/addsearch-js-client.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/addsearch-js-client@0.3/dist/addsearch-js-client.min.js"></script> | ||
``` | ||
@@ -13,0 +13,0 @@ To install the library locally or to use it with Node.js: |
@@ -9,3 +9,3 @@ 'use strict'; | ||
*/ | ||
var executeApiFetch = function(sitekey, type, settings, cb) { | ||
var executeApiFetch = function(sitekey, type, settings, cb, fuzzyRetry) { | ||
@@ -50,6 +50,19 @@ const RESPONSE_BAD_REQUEST = 400; | ||
// Fuzzy | ||
var fuzzy = settings.fuzzy; | ||
if (fuzzy === 'retry') { | ||
// First call, non fuzzy | ||
if (fuzzyRetry !== true) { | ||
fuzzy = false; | ||
} | ||
// Second call, fuzzy | ||
else { | ||
fuzzy = true; | ||
} | ||
} | ||
// Construct query string from settings | ||
if (type === 'search') { | ||
qs = settingToQueryParam(settings.lang, 'lang') + | ||
settingToQueryParam(settings.fuzzy, 'fuzzy') + | ||
settingToQueryParam(fuzzy, 'fuzzy') + | ||
settingToQueryParam(settings.collectAnalytics, 'collectAnalytics') + | ||
@@ -123,3 +136,23 @@ settingToQueryParam(settings.categories, 'categories') + | ||
}).then(function(json) { | ||
cb(json); | ||
// Search again with fuzzy=true if no hits | ||
if (type === 'search' && settings.fuzzy === 'retry' && json.total_hits === 0 && fuzzyRetry !== true) { | ||
executeApiFetch(sitekey, type, settings, cb, true); | ||
} | ||
// Fuzzy not "retry" OR fuzzyRetry already returning | ||
else { | ||
// Cap fuzzy results to one page as quality decreases quickly | ||
if (fuzzyRetry === true) { | ||
var pageSize = settings.paging.pageSize; | ||
if (json.total_hits >= pageSize) { | ||
json.total_hits = pageSize; | ||
} | ||
} | ||
// Callback | ||
cb(json); | ||
} | ||
}).catch(function(ex) { | ||
@@ -126,0 +159,0 @@ console.log(ex); |
@@ -60,4 +60,4 @@ 'use strict'; | ||
this.setFuzzyMatch = function(fuzzy) { | ||
if (fuzzy !== true && fuzzy !== false && fuzzy !== 'auto') { | ||
throw "fuzzy matching can be true, false, or 'auto'"; | ||
if (fuzzy !== true && fuzzy !== false && fuzzy !== 'auto' && fuzzy !== 'retry') { | ||
throw "fuzzy matching can be true, false, 'auto', or 'retry'"; | ||
} | ||
@@ -64,0 +64,0 @@ this.settings.fuzzy = fuzzy; |
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
60709
636