UNPKG

addsearch-js-client

Version:

AddSearch API JavaScript client

2 lines 111 kB
/*! addsearch-js-client 1.1.1 */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AddSearchClient=e():t.AddSearchClient=e()}(this,(()=>(()=>{var t={995:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.putSentimentClick=void 0,n(542);const r=n(972);e.putSentimentClick=(t,e,n,i)=>new Promise(((s,o)=>{r.aiAnswersInteractionsInstance.put("https://".concat(t,"/v2/indices/").concat(e,"/conversations/").concat(n,"/rating"),{value:"positive"===i?1:"negative"===i?-1:0}).then((t=>{200===t.status?s(!0):o(new Error(JSON.stringify({type:r.RESPONSE_SERVER_ERROR,message:"Unable to put sentiment click value."})))})).catch((t=>{console.error(t),o(new Error(JSON.stringify({type:r.RESPONSE_SERVER_ERROR,message:"Unable to put sentiment click value."})))}))}))},972:function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.RESPONSE_SERVER_ERROR=e.RESPONSE_BAD_REQUEST=e.setRequestInterceptor=e.aiAnswersInteractionsInstance=e.statsInstance=e.apiInstance=void 0;const i=r(n(425)),s=i.default.create();e.apiInstance=s;const o=i.default.create();e.statsInstance=o;const a=i.default.create();e.aiAnswersInteractionsInstance=a;e.RESPONSE_BAD_REQUEST=400;e.RESPONSE_SERVER_ERROR=500;e.setRequestInterceptor=(t,e)=>{("searchApi"===e?s:o).interceptors.request.use((e=>{const n=t({url:e.url,headers:e.headers});return e=Object.assign(Object.assign({},e),n)}),(t=>Promise.reject(new Error(JSON.stringify(t)))))}},650:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),n(542);const r=n(972),i=n(570),s=function(t,e,n,o,a,u,c,l){var f,h,d,p,g,y,m,b;const v=function(t,e){return t||!1===t?"&"+e+"="+t:""};if("search"!==n&&"ai-answers"!==n&&"suggest"!==n&&"autocomplete"!==n&&"recommend"!==n)return void a({error:{response:r.RESPONSE_BAD_REQUEST,message:"invalid query type"}});let w="",E="",O={},S=null,A=null;if("search"===n){A=n,w=null==o?void 0:o.keyword,w=(null==o?void 0:o.enableLogicalOperators)?w.replace(/ and /g," AND ").replace(/ or /g," OR ").replace(/ not /g," NOT "):w.replace(/ AND /g," and ").replace(/ OR /g," or ").replace(/ NOT /g," not "),w=encodeURIComponent(w);let r=null==o?void 0:o.fuzzy;if("retry"===r&&(r=!0===u),E=v(null==o?void 0:o.lang,"lang")+v(r,"fuzzy")+v(null==o?void 0:o.collectAnalytics,"collectAnalytics")+v(null==o?void 0:o.postfixWildcard,"postfixWildcard")+v(null==o?void 0:o.categories,"categories")+v(null==o?void 0:o.priceFromCents,"priceFromCents")+v(null==o?void 0:o.priceToCents,"priceToCents")+v(null==o?void 0:o.dateFrom,"dateFrom")+v(null==o?void 0:o.dateTo,"dateTo")+v(null==o?void 0:o.paging.page,"page")+v(null==o?void 0:o.paging.pageSize,"limit")+v(null==o?void 0:o.shuffleAndLimitTo,"shuffleAndLimitTo")+v(null==o?void 0:o.jwt,"jwt")+v(null==o?void 0:o.resultType,"resultType")+v(null==o?void 0:o.userToken,"userToken")+v(null==o?void 0:o.numFacets,"numFacets")+v(null==o?void 0:o.cacheResponseTime,"cacheResponseWithTtlSeconds")+v(null==o?void 0:o.searchOperator,"defaultOperator")+v(null==o?void 0:o.analyticsTag,"analyticsTag"),O=Object.assign(Object.assign({},O),{language:null==o?void 0:o.lang,fuzzy:!0!==r&&!1!==r?r:JSON.stringify(r),collectAnalytics:null==o?void 0:o.collectAnalytics,postfixWildcard:null==o?void 0:o.postfixWildcard,categories:(null==o?void 0:o.categories)?null==o?void 0:o.categories.split(","):void 0,priceFromCents:(null==o?void 0:o.priceFromCents)?parseInt(null==o?void 0:o.priceFromCents,10):void 0,priceToCents:(null==o?void 0:o.priceToCents)?parseInt(null==o?void 0:o.priceToCents,10):void 0,dateFrom:null==o?void 0:o.dateFrom,dateTo:null==o?void 0:o.dateTo,paging:{page:null!==(f=null==o?void 0:o.paging.page)&&void 0!==f?f:1,pageSize:null!==(h=null==o?void 0:o.paging.pageSize)&&void 0!==h?h:10,shuffleAndLimitTo:null!==(d=null==o?void 0:o.shuffleAndLimitTo)&&void 0!==d?d:void 0,sortByField:null==o?void 0:o.paging.sortBy,sortOrder:null==o?void 0:o.paging.sortOrder},jwt:null==o?void 0:o.jwt,resultType:null==o?void 0:o.resultType,userToken:null!==(p=null==o?void 0:o.userToken)&&void 0!==p?p:void 0,numFacets:null==o?void 0:o.numFacets,cacheResponseWithTtlSeconds:null!==(g=null==o?void 0:o.cacheResponseTime)&&void 0!==g?g:void 0,defaultOperator:null!==(y=null==o?void 0:o.searchOperator)&&void 0!==y?y:void 0,analyticsTag:null==o?void 0:o.analyticsTag}),Array.isArray(null==o?void 0:o.paging.sortBy)&&(null==o?void 0:o.paging.sortBy.length)>1?null==o||o.paging.sortBy.forEach((function(t,e){E=E+v(t,"sort")+v(null==o?void 0:o.paging.sortOrder[e],"order")})):E=E+v(null==o?void 0:o.paging.sortBy,"sort")+v(null==o?void 0:o.paging.sortOrder,"order"),null==o?void 0:o.customFieldFilters){const t={};for(let e=0;e<(null==o?void 0:o.customFieldFilters.length);e++){E=E+"&customField="+(null==o?void 0:o.customFieldFilters[e]);const n=decodeURIComponent(null==o?void 0:o.customFieldFilters[e]).split("="),r=n[0],i=n[1];t[r]=i}O=Object.assign(Object.assign({},O),{customField:(0,i.isEmptyObject)(t)?void 0:t})}if(null==o?void 0:o.facetFields){const t=[];for(let e=0;e<(null==o?void 0:o.facetFields.length);e++)E=E+"&facet="+(null==o?void 0:o.facetFields[e]),t.push(null==o?void 0:o.facetFields[e]);O=Object.assign(Object.assign({},O),{facet:t.length>0?t:void 0})}if((null==o?void 0:o.rangeFacets)&&(E=E+"&rangeFacets="+encodeURIComponent(JSON.stringify(null==o?void 0:o.rangeFacets)),O=Object.assign(Object.assign({},O),{rangeFacets:null==o?void 0:o.rangeFacets})),(null==o?void 0:o.hierarchicalFacetSetting)&&(E=E+"&hierarchicalFacets="+encodeURIComponent(JSON.stringify(null==o?void 0:o.hierarchicalFacetSetting)),O=Object.assign(Object.assign({},O),{hierarchicalFacets:null==o?void 0:o.hierarchicalFacetSetting})),null==o?void 0:o.statsFields){const t=[];for(let e=0;e<(null==o?void 0:o.statsFields.length);e++)E=E+"&fieldStat="+(null==o?void 0:o.statsFields[e]),t.push(null==o?void 0:o.statsFields[e]);O=Object.assign(Object.assign({},O),{statsFields:t})}if((null==o?void 0:o.personalizationEvents)&&Array.isArray(null==o?void 0:o.personalizationEvents)){const t=[];for(let e=0;e<(null==o?void 0:o.personalizationEvents.length);e++){const n=null==o?void 0:o.personalizationEvents[e],r=Object.keys(n)[0];E=E+"&personalizationEvent="+encodeURIComponent(r+"="+n[r]),t.push(n)}O=Object.assign(Object.assign({},O),{personalizationEvents:t})}c?(E=E+"&filter="+encodeURIComponent(JSON.stringify(c)),O=Object.assign(Object.assign({},O),{filter:c})):(null==o?void 0:o.filterObject)&&(E=E+"&filter="+encodeURIComponent(JSON.stringify(null==o?void 0:o.filterObject)),O=Object.assign(Object.assign({},O),{filter:(0,i.isEmptyObject)(null==o?void 0:o.filterObject)||null==o?void 0:o.filterObject})),S="https://"+t+"/v1/"+A+"/"+e+"?term="+w+E}else"ai-answers"===n?r.apiInstance.post("https://".concat(t,"/v2/indices/").concat(e,"/conversations"),{question:null==o?void 0:o.keyword}).then((function(t){t.data.response?a(t.data.response):a({error:{response:r.RESPONSE_SERVER_ERROR,message:"Could not get ai-answers response in the expected data format"}})})).catch((function(t){console.error(t),a({error:{response:r.RESPONSE_SERVER_ERROR,message:"invalid server response"}})})):"suggest"===n?(A=n,E=v(null==o?void 0:o.suggestionsSize,"size")+v(null==o?void 0:o.lang,"language"),O=Object.assign(Object.assign({},O),{size:null==o?void 0:o.suggestionsSize,language:null==o?void 0:o.lang}),w=null==o?void 0:o.suggestionsPrefix,S="https://"+t+"/v1/"+A+"/"+e+"?term="+w+E):"autocomplete"===n?(A="autocomplete/document-field",E=v(null==o?void 0:o.autocomplete.field,"source")+v(null==o?void 0:o.autocomplete.size,"size"),w=(null==o?void 0:o.autocomplete.prefix)||"",S="https://"+t+"/v1/"+A+"/"+e+"?term="+w+E,O=Object.assign(Object.assign({},O),{source:null==o?void 0:o.autocomplete.field,size:null==o?void 0:o.autocomplete.size})):"recommend"===n&&("RELATED_ITEMS"===(null==l?void 0:l.type)?(E=v(l.itemId,"itemId"),A="recommendations/index/"+e+"/block/"+l.blockId+"?"+E,O=Object.assign(Object.assign({},O),{itemId:null!==(m=l.itemId)&&void 0!==m?m:void 0,blockId:l.blockId})):"FREQUENTLY_BOUGHT_TOGETHER"===(null==l?void 0:l.type)&&(E=v(l.itemId,"itemId"),A="recommendations/"+e+"?configurationKey="+l.configurationKey+E,O=Object.assign(Object.assign({},O),{itemId:null!==(b=l.itemId)&&void 0!==b?b:void 0,configurationKey:l.configurationKey})),S="https://"+t+"/v1/"+A);if("ai-answers"!==n){const i=function(r){var i,c,l;const f=r.data;"search"===n&&"retry"===(null==o?void 0:o.fuzzy)&&0===f.total_hits&&!0!==u?s(t,e,n,o,a,!0):(!0===u&&(f.total_hits=Math.min(null!==(i=f.total_hits)&&void 0!==i?i:1/0,null!==(l=null===(c=null==o?void 0:o.paging)||void 0===c?void 0:c.pageSize)&&void 0!==l?l:1/0)),a(f))},c=function(t){console.error(t),a({error:{response:r.RESPONSE_SERVER_ERROR,message:"invalid server response"}})};if("POST"===(null==o?void 0:o.apiMethod)&&["search","suggest","autocomplete"].includes(n)){S="https://"+t+"/v1/"+A+"/"+e;const s="search"===n?decodeURIComponent(w):w;O=Object.assign({term:s},O),r.apiInstance.post(S,O).then(i).catch(c)}else r.apiInstance.get(S).then(i).catch(c)}};e.default=s},168:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.deleteCookie=e.getCookie=e.setCookie=void 0;const r=n(232);e.setCookie=(t,e,n)=>{if("undefined"==typeof document)return;const i=new Date;i.setTime(i.getTime()+24*n*60*60*1e3),document.cookie=(0,r.serialize)(t,e,{expires:i,path:"/"})};e.getCookie=t=>{if("undefined"!=typeof document)try{return(0,r.parse)(document.cookie)[t]}catch(t){return void console.debug("Error parsing cookies:",t)}};e.deleteCookie=t=>{"undefined"!=typeof document&&(document.cookie=(0,r.serialize)(t,"",{expires:new Date(0),path:"/"}))}},740:function(t,e,n){"use strict";var r,i=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),o=this&&this.__importStar||(r=function(t){return r=Object.getOwnPropertyNames||function(t){var e=[];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[e.length]=n);return e},r(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n=r(t),o=0;o<n.length;o++)"default"!==n[o]&&i(e,t,n[o]);return s(e,t),e}),a=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};const u=a(n(650)),c=n(104),l=a(n(515)),f=n(995),h=a(n(219)),d=o(n(570)),p=a(n(718)),g=o(n(168)),y=n(972),m="api.addsearch.com",b="addsearchUserToken";let v=!1,w=!1,E=180;t.exports=class{constructor(t,e){this.useStatsSessionId=!1,this.sitekey=t,this.privatekey=e||"",this.apiHostname=m,this.statsApiHostname=m,this.settings=new h.default,this.sessionId="a-".concat(1e8*Math.random()).substring(0,10),this.userTokenInPersonalization=g.getCookie(b)||d.generateUUID()}search(t,e){var n;let r=null,i=null;if("string"==typeof t&&"function"==typeof e)r=t,i=e;else if("function"!=typeof t||e){if(!this.settings.getSettings().callback)throw new Error("Illegal search parameters. Should be (keyword, callbackFunction) or (callbackFunction)");r=this.settings.getSettings().keyword||null,i=this.settings.getSettings().callback}else r=this.settings.getSettings().keyword||null,i=t;this.settings.setCallback((()=>i)),this.settings.setKeyword(r),null!==(n=this.throttledSearchFetch)&&void 0!==n||(this.throttledSearchFetch=(0,p.default)(this.settings.getSettings().throttleTimeMs,u.default)),this.throttledSearchFetch(this.apiHostname,this.sitekey,"search",this.settings.getSettings(),i)}aiAnswers(t,e){var n;this.settings.setCallback((()=>e)),this.settings.setKeyword(t),null!==(n=this.throttledAiAnswersFetch)&&void 0!==n||(this.throttledAiAnswersFetch=(0,p.default)(this.settings.getSettings().throttleTimeMs,u.default)),this.throttledAiAnswersFetch(this.apiHostname,this.sitekey,"ai-answers",this.settings.getSettings(),e)}putSentimentClick(t,e){return(0,f.putSentimentClick)(this.apiHostname,this.sitekey,t,e)}suggestions(t,e){var n;if(!t||!e||!d.isFunction(e))throw new Error("Illegal suggestions parameters. Should be (prefix, callbackFunction)");this.settings.setSuggestionsPrefix(t),null!==(n=this.throttledSuggestionsFetch)&&void 0!==n||(this.throttledSuggestionsFetch=(0,p.default)(this.settings.getSettings().throttleTimeMs,u.default)),this.throttledSuggestionsFetch(this.apiHostname,this.sitekey,"suggest",this.settings.getSettings(),e)}autocomplete(t,e,n){var r;if(!(t&&e&&n&&d.isFunction(n)))throw new Error("Illegal autocomplete parameters. Should be (field, prefix, callbackFunction)");this.settings.setAutocompleteParams(t,e),null!==(r=this.throttledAutocompleteFetch)&&void 0!==r||(this.throttledAutocompleteFetch=(0,p.default)(this.settings.getSettings().throttleTimeMs,u.default)),this.throttledAutocompleteFetch(this.apiHostname,this.sitekey,"autocomplete",this.settings.getSettings(),n)}fetchCustomApi(t,e,n){var r;const i=Object.assign({},this.settings.getSettings());i.facetFields=null===(r=i.facetFields)||void 0===r?void 0:r.filter((e=>t===e)),(0,u.default)(this.apiHostname,this.sitekey,"search",i,n,null,e)}fetchRangeFacets(t,e,n){var r;const i=Object.assign({},this.settings.getSettings());null!==(r=i.rangeFacets)&&void 0!==r||(i.rangeFacets=[]),i.rangeFacets.push({field:t.field,ranges:t.ranges}),(0,u.default)(this.apiHostname,this.sitekey,"search",i,n,null,e)}recommendations(t,e){var n;if(!t||!e||!d.isFunction(e))throw new Error("Illegal recommendations parameters. Should be (options, callbackFunction)");null!==(n=this.throttledRecommendationFetch)&&void 0!==n||(this.throttledRecommendationFetch=(0,p.default)(this.settings.getSettings().throttleTimeMs,u.default)),this.throttledRecommendationFetch(this.apiHostname,this.sitekey,"recommend",this.settings.getSettings(),e,!1,null,t)}getDocument(t){return(0,c.getDocument)(this.apiHostname,this.sitekey,this.privatekey,t)}saveDocument(t){return(0,c.saveDocument)(this.apiHostname,this.sitekey,this.privatekey,t)}saveDocumentsBatch(t){if(!t||!t.documents||!Array.isArray(t.documents))throw new Error("Please provide an array of documents: {documents: []}");return(0,c.saveDocumentsBatch)(this.apiHostname,this.sitekey,this.privatekey,t)}deleteDocument(t){return(0,c.deleteDocument)(this.apiHostname,this.sitekey,this.privatekey,t)}deleteDocumentsBatch(t){if(!t||!t.documents||!Array.isArray(t.documents))throw new Error("Please provide an array of document ids: {documents: []}");return(0,c.deleteDocumentsBatch)(this.apiHostname,this.sitekey,this.privatekey,t)}setApiHostname(t,e){e&&e.statsApiRequestOnly||(this.apiHostname=t),e&&e.searchApiRequestOnly||(this.statsApiHostname=t)}getSettings(){return this.settings.getSettings()}setLanguage(t){this.settings.setLanguage(t)}setCategoryFilters(t){this.settings.setCategoryFilters(t)}addCustomFieldFilter(t,e){this.settings.addCustomFieldFilter(t,e)}removeCustomFieldFilter(t,e){this.settings.removeCustomFieldFilter(t,e)}setPriceRangeFilter(t,e){this.settings.setPriceRangeFilter(t,e)}setDateFilter(t,e){this.settings.setDateFilter(t,e)}setJWT(t){this.settings.setJWT(t)}setUserToken(t){this.settings.setUserToken(t)}setPaging(t,e,n,r){this.settings.setPaging(t,e,n,r)}nextPage(){this.settings.nextPage()}previousPage(){this.settings.previousPage()}setSuggestionsSize(t){this.settings.setSuggestionsSize(t)}setAutocompleteSize(t){this.settings.setAutocompleteSize(t)}addFacetField(t){this.settings.addFacetField(t)}addHierarchicalFacetSetting(t){this.settings.addHierarchicalFacetSetting(t)}addRangeFacet(t,e){this.settings.addRangeFacet(t,e)}addStatsField(t){this.settings.addStatsField(t)}setNumberOfFacets(t){this.settings.setNumberOfFacets(t)}setResultType(t){this.settings.setResultType(t)}setPersonalizationEvents(t){this.settings.setPersonalizationEvents(t)}setFilterObject(t){this.settings.setFilterObject(t)}setShuffleAndLimitTo(t){this.settings.setShuffleAndLimitTo(t)}setFuzzyMatch(t){this.settings.setFuzzyMatch(t)}setPostfixWildcard(t){this.settings.setPostfixWildcard(t)}setCacheResponseTime(t){this.settings.setCacheResponseTime(t)}setCollectAnalytics(t){this.settings.setCollectAnalytics(t)}setAnalyticsTag(t){this.settings.setAnalyticsTag(t)}setThrottleTime(t){this.settings.setThrottleTime(t)}setStatsSessionId(t){this.sessionId=t,this.userTokenInPersonalization=t,this.useStatsSessionId=!0}getStatsSessionId(){return this.sessionId}enableLogicalOperators(t){this.settings.enableLogicalOperators(t)}setSearchOperator(t){this.settings.setSearchOperator(t)}setApiMethod(t){this.settings.setApiMethod(t)}sendStatsEvent(t,e,n){const r=!this.useStatsSessionId&&v&&w;if(r&&!g.getCookie(b)&&g.setCookie(b,this.userTokenInPersonalization,E),"search"===t){const t={action:"search",session:r?this.userTokenInPersonalization:this.sessionId,keyword:e,numberOfResults:n.numberOfResults,tag:this.getSettings().analyticsTag};(0,l.default)(this.statsApiHostname,this.sitekey,t,this.settings.getSettings().statsRequestIntercepted)}else{if("click"!==t)throw new Error("Illegal sendStatsEvent type parameters. Should be search or click)");{const t={action:"click",session:r?this.userTokenInPersonalization:this.sessionId,keyword:e,docid:n.documentId,position:n.position,tag:this.getSettings().analyticsTag};(0,l.default)(this.statsApiHostname,this.sitekey,t,this.settings.getSettings().statsRequestIntercepted)}}}getUserTokenInPersonalization(){return this.userTokenInPersonalization}enablePersonalizationTracking(t,e){v=t,e&&(E=e)}consentAddSearchCookie(t){w=t}setApiRequestInterceptor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("function"!=typeof t)return void console.error("API interceptor must be a function");const{searchApiRequestOnly:n=!1,statsApiRequestOnly:r=!1}=e;n||r?(n&&(0,y.setRequestInterceptor)(t,"searchApi"),r&&((0,y.setRequestInterceptor)(t,"statsApi"),this.settings.setStatsRequestIntercepted(!0))):((0,y.setRequestInterceptor)(t,"searchApi"),(0,y.setRequestInterceptor)(t,"statsApi"),this.settings.setStatsRequestIntercepted(!0))}setCookie(t,e,n){g.setCookie(t,e,n)}getCookie(t){return g.getCookie(t)}searchResultClicked(t,e){this.sendStatsEvent("click",this.settings.getSettings().keyword||"",{documentId:t,position:e})}}},104:function(t,e,n){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.deleteDocumentsBatch=e.deleteDocument=e.saveDocumentsBatch=e.saveDocument=e.getDocument=void 0;const i=r(n(425)),s=n(570),o=(t,e)=>({Authorization:"Basic "+(0,s.base64)(t+":"+e),"Content-Type":"application/json"});e.getDocument=(t,e,n,r)=>new Promise(((s,a)=>{i.default.get("https://".concat(t,"/v2/indices/").concat(e,"/documents/").concat(r),{headers:o(e,n)}).then((t=>{200===t.status?s(t.data):a(new Error(JSON.stringify({status:t.status,text:t.statusText})))})).catch((t=>{a(new Error(JSON.stringify({status:400,text:t})))}))}));e.saveDocument=(t,e,n,r)=>{const s=Boolean(r.id||r.url);return new Promise(((a,u)=>{(0,i.default)({url:"https://".concat(t,"/v2/indices/").concat(e,"/documents/"),method:s?"put":"post",headers:o(e,n),data:r}).then((t=>{202===t.status?a({status:t.status,text:t.statusText}):u(new Error(JSON.stringify({status:t.status,text:t.statusText})))})).catch((t=>{u(new Error(JSON.stringify({status:400,text:t})))}))}))};e.saveDocumentsBatch=(t,e,n,r)=>new Promise(((s,a)=>{(0,i.default)({method:"put",url:"https://".concat(t,"/v2/indices/").concat(e,"/documents:batch"),headers:o(e,n),data:r}).then((t=>{202===t.status?s({status:t.status,text:t.statusText}):a(new Error(JSON.stringify({status:t.status,text:t.statusText})))})).catch((t=>{a(new Error(JSON.stringify({status:400,text:t})))}))}));e.deleteDocument=(t,e,n,r)=>new Promise(((s,a)=>{i.default.delete("https://".concat(t,"/v2/indices/").concat(e,"/documents/").concat(r),{headers:o(e,n)}).then((t=>{202===t.status?s({status:t.status,text:t.statusText}):a(new Error(JSON.stringify({status:t.status,text:t.statusText})))})).catch((t=>{a(new Error(JSON.stringify({status:400,text:t})))}))}));e.deleteDocumentsBatch=(t,e,n,r)=>new Promise(((s,a)=>{i.default.delete("https://".concat(t,"/v2/indices/").concat(e,"/documents:batch"),{headers:o(e,n),data:r}).then((t=>{202===t.status?s({status:t.status,text:t.statusText}):a(new Error(JSON.stringify({status:t.status,text:t.statusText})))})).catch((t=>{a(new Error(JSON.stringify({status:400,text:t})))}))}))},219:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});const r=n(570);e.default=class{constructor(){this.settings={keyword:"*",callback:null,throttleTimeMs:200,fuzzy:"auto",paging:{page:1,pageSize:10,sortBy:"relevance",sortOrder:"desc"},customFieldFilters:[],userToken:null,suggestionsSize:10,facetFields:[],autocomplete:{size:10},searchOperator:null,enableLogicalOperators:!1,cacheResponseTime:null,statsRequestIntercepted:!1,apiMethod:"GET"}}getSettings(){return this.settings}setKeyword(t){this.settings.keyword=t||"*"}setCallback(t){this.settings.callback=t}setThrottleTime(t){this.settings.throttleTimeMs=t}setSuggestionsPrefix(t){this.settings.suggestionsPrefix=t}setSuggestionsSize(t){this.settings.suggestionsSize=t}setAutocompleteSize(t){this.settings.autocomplete.size=t}setAutocompleteParams(t,e){this.settings.autocomplete.field=t,this.settings.autocomplete.prefix=e}setLanguage(t){let e;if(Intl&&Intl.Locale)try{e=new Intl.Locale(t).language}catch(t){throw console.debug(t),new Error('Use an accepted language code provided by the ECMAScript Internationalization API (e.g., "en", "en-GB").')}else e=t;if(e&&2!==e.length)throw new Error('Use a 2-char/4-char language code (e.g., "en", "en-GB")');this.settings.lang=e}setFuzzyMatch(t){if(!0!==t&&!1!==t&&"auto"!==t&&"retry"!==t)throw new Error("Fuzzy matching can be true, false, 'auto', or 'retry'");this.settings.fuzzy=t}enableLogicalOperators(t){this.settings.enableLogicalOperators=t}setCacheResponseTime(t){this.settings.cacheResponseTime=t}setPostfixWildcard(t){this.settings.postfixWildcard=t}setCollectAnalytics(t){this.settings.collectAnalytics=t}setAnalyticsTag(t){this.settings.analyticsTag=t}setCategoryFilters(t){this.settings.categories=t}setFilterObject(t){this.settings.filterObject=t}setPriceRangeFilter(t,e){this.settings.priceFromCents=t,this.settings.priceToCents=e}addCustomFieldFilter(t,e){const n=encodeURIComponent("".concat(t,"=").concat(e));this.settings.customFieldFilters.includes(n)||this.settings.customFieldFilters.push(n)}removeCustomFieldFilter(t,e){const n=!e,r=encodeURIComponent("".concat(t,"=").concat(e||""));this.settings.customFieldFilters=this.settings.customFieldFilters.filter((t=>n?!t.startsWith(r):t!==r))}setDateFilter(t,e){this.settings.dateFrom=t,this.settings.dateTo=e}setJWT(t){this.settings.jwt=t}setUserToken(t){this.settings.userToken=t}setPersonalizationEvents(t){Array.isArray(t)&&(this.settings.personalizationEvents=t)}setResultType(t){this.settings.resultType=t}addFacetField(t){this.settings.facetFields.includes(t)||this.settings.facetFields.push(t)}addHierarchicalFacetSetting(t){this.settings.hierarchicalFacetSetting=t}addRangeFacet(t,e){var n,r;null!==(n=(r=this.settings).rangeFacets)&&void 0!==n||(r.rangeFacets=[]),this.settings.rangeFacets.push({field:t,ranges:e})}addStatsField(t){var e,n;null!==(e=(n=this.settings).statsFields)&&void 0!==e||(n.statsFields=[]),this.settings.statsFields.includes(t)||this.settings.statsFields.push(t)}setNumberOfFacets(t){this.settings.numFacets=t}setPaging(t,e,n,i){(0,r.validateSetPagingParams)(t,e,n,i),this.settings.paging={page:t,pageSize:e,sortBy:n,sortOrder:i}}setShuffleAndLimitTo(t){this.settings.shuffleAndLimitTo=t}nextPage(){this.settings.paging.page++}previousPage(){this.settings.paging.page>0&&this.settings.paging.page--}setSearchOperator(t){if("and"!==t&&"or"!==t)throw new Error("Operator must be 'and' or 'or'");this.settings.searchOperator=t}setStatsRequestIntercepted(t){this.settings.statsRequestIntercepted=t}setApiMethod(t){if("GET"!==t&&"POST"!==t)throw new Error("API method must be 'GET' or 'POST'");this.settings.apiMethod=t}}},515:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});const r=n(964),i=n(972);(0,r.polyfill)();e.default=(t,e,n,r)=>{"undefined"!=typeof window&&window.navigator&&window.navigator.sendBeacon&&!r?window.navigator.sendBeacon("https://".concat(t,"/v1/stats/").concat(e,"/"),JSON.stringify(n)):i.statsInstance.post("https://".concat(t,"/v1/stats/").concat(e,"/"),n,{headers:{"Content-Type":"text/plain"}}).then().catch((t=>{console.error(t)}))}},718:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.default=(t,e)=>{let n=0,r=null;return function(){for(var i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];const a=Date.now()-n,u=()=>{n=Date.now(),e(...s)};null!==r&&(clearTimeout(r),r=null),a>t?u():r=setTimeout(u,t-a)}}},570:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.isEmptyObject=e.generateUUID=e.validateSetPagingParams=e.base64=e.isFunction=void 0;const r=n(287),i=n(182);e.isFunction=t=>"function"==typeof t;e.base64=t=>"undefined"!=typeof window&&window.btoa?window.btoa(t):r.Buffer?r.Buffer.from(t).toString("base64"):void 0;e.validateSetPagingParams=(t,e,n,r)=>{if(t<1)throw new Error("Page must be 1 or bigger");if(e<1||e>300)throw new Error("PageSize must be between 1 and 300");if(!n||!r)throw new Error("Invalid values for sortBy or sortOrder:");if(!("string"==typeof n&&"string"==typeof r||Array.isArray(n)&&Array.isArray(r)))throw new Error("sortBy and sortOrder must have the same type: string or Array");if(Array.isArray(n)&&n.length!==r.length)throw new Error("sortBy and sortOrder must have the same size");if("string"==typeof r&&"asc"!==r&&"desc"!==r)throw new Error("sortOrder must be asc or desc");if(Array.isArray(r)&&r.some((t=>"desc"!==t&&"asc"!==t)))throw new Error("All values of sortOrder array must be asc or desc")};e.generateUUID=()=>(0,i.v4)().replace(/-/g,"");e.isEmptyObject=t=>null==t||(!(!Array.isArray(t)&&"[object Object]"===Object.prototype.toString.call(t))||0===Object.keys(t).length)},526:(t,e)=>{"use strict";e.byteLength=function(t){var e=a(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){var e,n,s=a(t),o=s[0],u=s[1],c=new i(function(t,e,n){return 3*(e+n)/4-n}(0,o,u)),l=0,f=u>0?o-4:o;for(n=0;n<f;n+=4)e=r[t.charCodeAt(n)]<<18|r[t.charCodeAt(n+1)]<<12|r[t.charCodeAt(n+2)]<<6|r[t.charCodeAt(n+3)],c[l++]=e>>16&255,c[l++]=e>>8&255,c[l++]=255&e;2===u&&(e=r[t.charCodeAt(n)]<<2|r[t.charCodeAt(n+1)]>>4,c[l++]=255&e);1===u&&(e=r[t.charCodeAt(n)]<<10|r[t.charCodeAt(n+1)]<<4|r[t.charCodeAt(n+2)]>>2,c[l++]=e>>8&255,c[l++]=255&e);return c},e.fromByteArray=function(t){for(var e,r=t.length,i=r%3,s=[],o=16383,a=0,c=r-i;a<c;a+=o)s.push(u(t,a,a+o>c?c:a+o));1===i?(e=t[r-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],r=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0;o<64;++o)n[o]=s[o],r[s.charCodeAt(o)]=o;function a(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function u(t,e,r){for(var i,s,o=[],a=e;a<r;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),o.push(n[(s=i)>>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return o.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},287:(t,e,n)=>{"use strict";const r=n(526),i=n(251),s="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=u,e.SlowBuffer=function(t){+t!=t&&(t=0);return u.alloc(+t)},e.INSPECT_MAX_BYTES=50;const o=2147483647;function a(t){if(t>o)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(t,e,n){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return f(t)}return c(t,e,n)}function c(t,e,n){if("string"==typeof t)return function(t,e){"string"==typeof e&&""!==e||(e="utf8");if(!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const n=0|g(t,e);let r=a(n);const i=r.write(t,e);i!==n&&(r=r.slice(0,i));return r}(t,e);if(ArrayBuffer.isView(t))return function(t){if(G(t,Uint8Array)){const e=new Uint8Array(t);return d(e.buffer,e.byteOffset,e.byteLength)}return h(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(G(t,ArrayBuffer)||t&&G(t.buffer,ArrayBuffer))return d(t,e,n);if("undefined"!=typeof SharedArrayBuffer&&(G(t,SharedArrayBuffer)||t&&G(t.buffer,SharedArrayBuffer)))return d(t,e,n);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const r=t.valueOf&&t.valueOf();if(null!=r&&r!==t)return u.from(r,e,n);const i=function(t){if(u.isBuffer(t)){const e=0|p(t.length),n=a(e);return 0===n.length||t.copy(n,0,0,e),n}if(void 0!==t.length)return"number"!=typeof t.length||X(t.length)?a(0):h(t);if("Buffer"===t.type&&Array.isArray(t.data))return h(t.data)}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u.from(t[Symbol.toPrimitive]("string"),e,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function l(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function f(t){return l(t),a(t<0?0:0|p(t))}function h(t){const e=t.length<0?0:0|p(t.length),n=a(e);for(let r=0;r<e;r+=1)n[r]=255&t[r];return n}function d(t,e,n){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(n||0))throw new RangeError('"length" is outside of buffer bounds');let r;return r=void 0===e&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,e):new Uint8Array(t,e,n),Object.setPrototypeOf(r,u.prototype),r}function p(t){if(t>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return 0|t}function g(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||G(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const n=t.length,r=arguments.length>2&&!0===arguments[2];if(!r&&0===n)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return V(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return W(t).length;default:if(i)return r?-1:V(t).length;e=(""+e).toLowerCase(),i=!0}}function y(t,e,n){let r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return j(this,e,n);case"utf8":case"utf-8":return T(this,e,n);case"ascii":return U(this,e,n);case"latin1":case"binary":return F(this,e,n);case"base64":return R(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function m(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function b(t,e,n,r,i){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),X(n=+n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=u.from(e,r)),u.isBuffer(e))return 0===e.length?-1:v(t,e,n,r,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):v(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function v(t,e,n,r,i){let s,o=1,a=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;o=2,a/=2,u/=2,n/=2}function c(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){let r=-1;for(s=n;s<a;s++)if(c(t,s)===c(e,-1===r?0:s-r)){if(-1===r&&(r=s),s-r+1===u)return r*o}else-1!==r&&(s-=s-r),r=-1}else for(n+u>a&&(n=a-u),s=n;s>=0;s--){let n=!0;for(let r=0;r<u;r++)if(c(t,s+r)!==c(e,r)){n=!1;break}if(n)return s}return-1}function w(t,e,n,r){n=Number(n)||0;const i=t.length-n;r?(r=Number(r))>i&&(r=i):r=i;const s=e.length;let o;for(r>s/2&&(r=s/2),o=0;o<r;++o){const r=parseInt(e.substr(2*o,2),16);if(X(r))return o;t[n+o]=r}return o}function E(t,e,n,r){return K(V(e,t.length-n),t,n,r)}function O(t,e,n,r){return K(function(t){const e=[];for(let n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function S(t,e,n,r){return K(W(e),t,n,r)}function A(t,e,n,r){return K(function(t,e){let n,r,i;const s=[];for(let o=0;o<t.length&&!((e-=2)<0);++o)n=t.charCodeAt(o),r=n>>8,i=n%256,s.push(i),s.push(r);return s}(e,t.length-n),t,n,r)}function R(t,e,n){return 0===e&&n===t.length?r.fromByteArray(t):r.fromByteArray(t.slice(e,n))}function T(t,e,n){n=Math.min(t.length,n);const r=[];let i=e;for(;i<n;){const e=t[i];let s=null,o=e>239?4:e>223?3:e>191?2:1;if(i+o<=n){let n,r,a,u;switch(o){case 1:e<128&&(s=e);break;case 2:n=t[i+1],128==(192&n)&&(u=(31&e)<<6|63&n,u>127&&(s=u));break;case 3:n=t[i+1],r=t[i+2],128==(192&n)&&128==(192&r)&&(u=(15&e)<<12|(63&n)<<6|63&r,u>2047&&(u<55296||u>57343)&&(s=u));break;case 4:n=t[i+1],r=t[i+2],a=t[i+3],128==(192&n)&&128==(192&r)&&128==(192&a)&&(u=(15&e)<<18|(63&n)<<12|(63&r)<<6|63&a,u>65535&&u<1114112&&(s=u))}}null===s?(s=65533,o=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),i+=o}return function(t){const e=t.length;if(e<=_)return String.fromCharCode.apply(String,t);let n="",r=0;for(;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=_));return n}(r)}e.kMaxLength=o,u.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),u.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}}),u.poolSize=8192,u.from=function(t,e,n){return c(t,e,n)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array),u.alloc=function(t,e,n){return function(t,e,n){return l(t),t<=0?a(t):void 0!==e?"string"==typeof n?a(t).fill(e,n):a(t).fill(e):a(t)}(t,e,n)},u.allocUnsafe=function(t){return f(t)},u.allocUnsafeSlow=function(t){return f(t)},u.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==u.prototype},u.compare=function(t,e){if(G(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),G(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(t)||!u.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let n=t.length,r=e.length;for(let i=0,s=Math.min(n,r);i<s;++i)if(t[i]!==e[i]){n=t[i],r=e[i];break}return n<r?-1:r<n?1:0},u.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);let n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;const r=u.allocUnsafe(e);let i=0;for(n=0;n<t.length;++n){let e=t[n];if(G(e,Uint8Array))i+e.length>r.length?(u.isBuffer(e)||(e=u.from(e)),e.copy(r,i)):Uint8Array.prototype.set.call(r,e,i);else{if(!u.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(r,i)}i+=e.length}return r},u.byteLength=g,u.prototype._isBuffer=!0,u.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)m(this,e,e+1);return this},u.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)m(this,e,e+3),m(this,e+1,e+2);return this},u.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)m(this,e,e+7),m(this,e+1,e+6),m(this,e+2,e+5),m(this,e+3,e+4);return this},u.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?T(this,0,t):y.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.prototype.inspect=function(){let t="";const n=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(t+=" ... "),"<Buffer "+t+">"},s&&(u.prototype[s]=u.prototype.inspect),u.prototype.compare=function(t,e,n,r,i){if(G(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(this===t)return 0;let s=(i>>>=0)-(r>>>=0),o=(n>>>=0)-(e>>>=0);const a=Math.min(s,o),c=this.slice(r,i),l=t.slice(e,n);for(let t=0;t<a;++t)if(c[t]!==l[t]){s=c[t],o=l[t];break}return s<o?-1:o<s?1:0},u.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},u.prototype.indexOf=function(t,e,n){return b(this,t,e,n,!0)},u.prototype.lastIndexOf=function(t,e,n){return b(this,t,e,n,!1)},u.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}const i=this.length-e;if((void 0===n||n>i)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");let s=!1;for(;;)switch(r){case"hex":return w(this,t,e,n);case"utf8":case"utf-8":return E(this,t,e,n);case"ascii":case"latin1":case"binary":return O(this,t,e,n);case"base64":return S(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const _=4096;function U(t,e,n){let r="";n=Math.min(t.length,n);for(let i=e;i<n;++i)r+=String.fromCharCode(127&t[i]);return r}function F(t,e,n){let r="";n=Math.min(t.length,n);for(let i=e;i<n;++i)r+=String.fromCharCode(t[i]);return r}function j(t,e,n){const r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);let i="";for(let r=e;r<n;++r)i+=Y[t[r]];return i}function P(t,e,n){const r=t.slice(e,n);let i="";for(let t=0;t<r.length-1;t+=2)i+=String.fromCharCode(r[t]+256*r[t+1]);return i}function B(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function I(t,e,n,r,i,s){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<s)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function C(t,e,n,r,i){q(e,r,i,t,n,7);let s=Number(e&BigInt(4294967295));t[n++]=s,s>>=8,t[n++]=s,s>>=8,t[n++]=s,s>>=8,t[n++]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[n++]=o,o>>=8,t[n++]=o,o>>=8,t[n++]=o,o>>=8,t[n++]=o,n}function x(t,e,n,r,i){q(e,r,i,t,n,7);let s=Number(e&BigInt(4294967295));t[n+7]=s,s>>=8,t[n+6]=s,s>>=8,t[n+5]=s,s>>=8,t[n+4]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[n+3]=o,o>>=8,t[n+2]=o,o>>=8,t[n+1]=o,o>>=8,t[n]=o,n+8}function k(t,e,n,r,i,s){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function N(t,e,n,r,s){return e=+e,n>>>=0,s||k(t,0,n,4),i.write(t,e,n,r,23,4),n+4}function L(t,e,n,r,s){return e=+e,n>>>=0,s||k(t,0,n,8),i.write(t,e,n,r,52,8),n+8}u.prototype.slice=function(t,e){const n=this.length;(t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t);const r=this.subarray(t,e);return Object.setPrototypeOf(r,u.prototype),r},u.prototype.readUintLE=u.prototype.readUIntLE=function(t,e,n){t>>>=0,e>>>=0,n||B(t,e,this.length);let r=this[t],i=1,s=0;for(;++s<e&&(i*=256);)r+=this[t+s]*i;return r},u.prototype.readUintBE=u.prototype.readUIntBE=function(t,e,n){t>>>=0,e>>>=0,n||B(t,e,this.length);let r=this[t+--e],i=1;for(;e>0&&(i*=256);)r+=this[t+--e]*i;return r},u.prototype.readUint8=u.prototype.readUInt8=function(t,e){return t>>>=0,e||B(t,1,this.length),this[t]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(t,e){return t>>>=0,e||B(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(t,e){return t>>>=0,e||B(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(t,e){return t>>>=0,e||B(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(t,e){return t>>>=0,e||B(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readBigUInt64LE=Q((function(t){$(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||H(t,this.length-8);const r=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+n*2**24;return BigInt(r)+(BigInt(i)<<BigInt(32))})),u.prototype.readBigUInt64BE=Q((function(t){$(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||H(t,this.length-8);const r=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+n;return(BigInt(r)<<BigInt(32))+BigInt(i)})),u.prototype.readIntLE=function(t,e,n){t>>>=0,e>>>=0,n||B(t,e,this.length);let r=this[t],i=1,s=0;for(;++s<e&&(i*=256);)r+=this[t+s]*i;return i*=128,r>=i&&(r-=Math.pow(2,8*e)),r},u.prototype.readIntBE=function(t,e,n){t>>>=0,e>>>=0,n||B(t,e,this.length);let r=e,i=1,s=this[t+--r];for(;r>0&&(i*=256);)s+=this[t+--r]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*e)),s},u.prototype.readInt8=function(t,e){return t>>>=0,e||B(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){t>>>=0,e||B(t,2,this.length);const n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt16BE=function(t,e){t>>>=0,e||B(t,2,this.length);const n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt32LE=function(t,e){return t>>>=0,e||B(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return t>>>=0,e||B(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readBigInt64LE=Q((function(t){$(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||H(t,this.length-8);const r=this[t+4]+256*this[t+5]+65536*this[t+6]+(n<<24);return(BigInt(r)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),u.prototype.readBigInt64BE=Q((function(t){$(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||H(t,this.length-8);const r=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(r)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+n)})),u.prototype.readFloatLE=function(t,e){return t>>>=0,e||B(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return t>>>=0,e||B(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return t>>>=0,e||B(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return t>>>=0,e||B(t,8,this.length),i.read(this,t,!1,52,8)},u.prototype.writeUintLE=u.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e>>>=0,n>>>=0,!r){I(this,t,e,n,Math.pow(2,8*n)-1,0)}let i=1,s=0;for(this[e]=255&t;++s<n&&(i*=256);)this[e+s]=t/i&255;return e+n},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(t,e,n,r){if(t=+t,e>>>=0,n>>>=0,!r){I(this,t,e,n,Math.pow(2,8*n)-1,0)}let i=n-1,s=1;for(this[e+i]=255&t;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+n},u.prototype.writeUint8=u.prototype.writeUInt8=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,1,255,0),this[e]=255&t,e+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},u.prototype.writeBigUInt64LE=Q((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeBigUInt64BE=Q((function(t,e=0){return x(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e>>>=0,!r){const r=Math.pow(2,8*n-1);I(this,t,e,n,r-1,-r)}let i=0,s=1,o=0;for(this[e]=255&t;++i<n&&(s*=256);)t<0&&0===o&&0!==this[e+i-1]&&(o=1),this[e+i]=(t/s|0)-o&255;return e+n},u.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e>>>=0,!r){const r=Math.pow(2,8*n-1);I(this,t,e,n,r-1,-r)}let i=n-1,s=1,o=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===o&&0!==this[e+i+1]&&(o=1),this[e+i]=(t/s|0)-o&255;return e+n},u.prototype.writeInt8=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeInt16BE=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeInt32LE=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},u.prototype.writeInt32BE=function(t,e,n){return t=+t,e>>>=0,n||I(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},u.prototype.writeBigInt64LE=Q((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeBigInt64BE=Q((function(t,e=0){return x(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeFloatLE=function(t,e,n){return N(this,t,e,!0,n)},u.prototype.writeFloatBE=function(t,e,n){return N(this,t,e,!1,n)},u.prototype.writeDoubleLE=function(t,e,n){return L(this,t,e,!0,n)},u.prototype.writeDoubleBE=function(t,e,n){return L(this,t,e,!1,n)},u.prototype.copy=function(t,e,n,r){if(!u.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);const i=r-n;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,n,r):Uint8Array.prototype.set.call(t,this.subarray(n,r),e),i},u.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(1===t.length){const e=t.charCodeAt(0);("utf8"===r&&e<128||"latin1"===r)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;let i;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(i=e;i<n;++i)this[i]=t;else{const s=u.isBuffer(t)?t:u.from(t,r),o=s.length;if(0===o)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<n-e;++i)this[i+e]=s[i%o]}return this};const D={};function M(t,e,n){D[t]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}