text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.SwiftypeAppSearch={})}(this,function(e){"use strict";var h=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}(),f=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s=function(e,t){var n={};for(var r in e)0<=t.indexOf(r)||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},d=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,i=!1,a=void 0;try{for(var s,o=e[Symbol.iterator]();!(r=(s=o.next()).done)&&(n.push(s.value),!t||n.length!==t);r=!0);}catch(e){i=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(i)throw a}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},p=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},i=function(){function t(e){h(this,t),e._group&&0<e._group.length&&(e=l({},e,{_group:e._group.map(function(e){return new t(e)})})),this.data=e}return n(t,[{key:"getRaw",value:function(e){return(this.data[e]||{}).raw}},{key:"getSnippet",value:function(e){return(this.data[e]||{}).snippet}}]),t}(),t=function e(t,n){h(this,e),this.rawResults=t,this.rawInfo=n;var r=new Array;t.forEach(function(e){r.push(new i(e))}),this.results=r,this.info=n},v=function(){function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};h(this,t),this.filtersJSON=e}return n(t,[{key:"removeFilter",value:function(e){return new t(function a(s,e){var t=Object.entries(e).reduce(function(e,t){var n=d(t,2),r=n[0],i=n[1];return r===s?e:(["all","any","none"].includes(r)&&(i=i.reduce(function(e,t){var n=a(s,t);return n?e.concat(n):e},[])),l({},e,f({},r,i)))},{});if(0!==Object.keys(t).length)return t}(e,1<arguments.length&&void 0!==arguments[1]?arguments[1]:this.filtersJSON))}},{key:"getListOfAppliedFilters",value:function(){var a=this,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.filtersJSON,t=Object.entries(e).reduce(function(n,e){var t=d(e,2),r=t[0],i=t[1];return["all","any","none"].includes(r)?i.forEach(function(t){Object.keys(t).forEach(function(e){["all","any","none"].includes(e)?n=new Set([].concat(p(n),p(a.getListOfAppliedFilters(t)))):n.add(e)})}):n.add(r),n},new Set);return Array.from(t.values())}}]),t}(),c="swiftype-app-search-javascript",u="2.4.0",y=new(function(){function e(){h(this,e),this.cache={}}return n(e,[{key:"getKey",value:function(e,t,n){return e+t+JSON.stringify(n)}},{key:"store",value:function(e,t){this.cache[e]=t}},{key:"retrieve",value:function(e){return this.cache[e]}}]),e}());function o(e,t,n,r,i){var a=(5<arguments.length&&void 0!==arguments[5]?arguments[5]:{}).additionalHeaders,s=y.getKey("POST",t+n,r);if(i){var o=y.retrieve(s);if(o)return Promise.resolve(o)}return function(e,t,n,r,i){var a=(5<arguments.length&&void 0!==arguments[5]?arguments[5]:{}).additionalHeaders,s=new Headers(l({Authorization:"Bearer "+t,"Content-Type":"application/json","X-Swiftype-Client":c,"X-Swiftype-Client-Version":u},a));return fetch(""+n+r,{method:e,headers:s,body:JSON.stringify(i),credentials:"include"})}("POST",e,t,n,r,{additionalHeaders:a}).then(function(n){return n.json().then(function(e){var t={response:n,json:e};return i&&y.store(s,t),t}).catch(function(){return{response:n,json:{}}})})}var r="SEARCH",a="MULTI_SEARCH";function g(e){return new t(e.results,function(e,t){if(e)return e[t],s(e,[t])}(e,"results"))}function m(e){var t,n=e.response,r=e.json;if(!n.ok){var i=Array.isArray(r)?" "+(t=r.map(function(e){return e.errors}),[].concat.apply([],t)).join(", "):r.errors?" "+r.errors:"";throw new Error("["+n.status+"]"+i)}return r}var S=function(){function u(e,t,n){var r=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},i=r.endpointBase,a=void 0===i?"":i,s=r.cacheResponses,o=void 0===s||s,c=r.additionalHeaders;h(this,u),this.additionalHeaders=c,this.searchKey=t,this.cacheResponses=o,this.engineName=n,this.apiEndpoint=a?a+"/api/as/v1/":"https://"+e+".api.swiftype.com/api/as/v1/",this.searchPath="engines/"+this.engineName+"/search",this.multiSearchPath="engines/"+this.engineName+"/multi_search",this.querySuggestionPath="engines/"+this.engineName+"/query_suggestion",this.clickPath="engines/"+this.engineName+"/click"}return n(u,[{key:"querySuggestion",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=Object.assign({query:e},t);return o(this.searchKey,this.apiEndpoint,this.querySuggestionPath,n,this.cacheResponses,{additionalHeaders:this.additionalHeaders}).then(m)}},{key:"search",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=t.disjunctiveFacets,r=t.disjunctiveFacetsAnalyticsTags,i=s(t,["disjunctiveFacets","disjunctiveFacetsAnalyticsTags"]),a=Object.assign({query:e},i);return n&&0<n.length?this._performDisjunctiveSearch(a,n,r).then(g):this._performSearch(a).then(g)}},{key:"multiSearch",value:function(e){var t=e.map(function(e){return l({query:e.query},e.options||{})});return this._performSearch({queries:t},a).then(function(e){return e.map(g)})}},{key:"_performDisjunctiveSearch",value:function(t,n){var r=this,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["Facet-Only"],i=this._performSearch(t),a=new v(t.filters),s=a.getListOfAppliedFilters().filter(function(e){return n.includes(e)});if(!s.length)return i;var o=t.page||{},c=t.analytics||{};c.tags=e;var u=s.map(function(e){return r._performSearch(l({},t,{filters:a.removeFilter(e).filtersJSON,page:l({},o,{size:0}),analytics:c,facets:f({},e,t.facets[e])}))});return Promise.all([i].concat(p(u))).then(function(e){var t,n=(t=e,Array.isArray(t)?t:Array.from(t)),i=n[0];return n.slice(1).forEach(function(e){var t=d(Object.entries(e.facets)[0],2),n=t[0],r=t[1];i.facets[n]=r}),i})}},{key:"_performSearch",value:function(e){var t=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:r)===a?this.multiSearchPath:this.searchPath;return o(this.searchKey,this.apiEndpoint,t+".json",e,this.cacheResponses,{additionalHeaders:this.additionalHeaders}).then(m)}},{key:"click",value:function(e){var t=e.query,n=e.documentId,r=e.requestId,i=e.tags,a={query:t,document_id:n,request_id:r,tags:void 0===i?[]:i};return o(this.searchKey,this.apiEndpoint,this.clickPath+".json",a,this.cacheResponses,{additionalHeaders:this.additionalHeaders}).then(m)}}]),u}();e.createClient=function(e){var t=e.hostIdentifier,n=e.accountHostKey,r=e.apiKey,i=e.searchKey,a=e.engineName,s=e.endpointBase,o=e.cacheResponses,c=e.additionalHeaders;return new S(t=t||n,i=i||r,a,{endpointBase:s,cacheResponses:o,additionalHeaders:c})},Object.defineProperty(e,"__esModule",{value:!0})});
  