LocalCDN-Firefox-Chrome-Brave/resources/algoliasearch/4.22.1/algoliasearch.min.jsm

1 line
32 KiB
JavaScript

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).algoliasearch=e()}(this,function(){"use strict";function e(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function g(n){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?e(Object(a),!0).forEach(function(t){var e,r;e=n,r=a[t=t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(a)):e(Object(a)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(a,t))})}return n}function d(t,e){if(null==t)return{};var r,n=function(t,e){if(null==t)return{};for(var r,n={},a=Object.keys(t),o=0;o<a.length;o++)r=a[o],0<=e.indexOf(r)||(n[r]=t[r]);return n}(t,e);if(Object.getOwnPropertySymbols)for(var a=Object.getOwnPropertySymbols(t),o=0;o<a.length;o++)r=a[o],0<=e.indexOf(r)||Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r]);return n}function l(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var r=[],n=!0,a=!1,o=void 0;try{for(var i,u=t[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!e||r.length!==e);n=!0);}catch(t){a=!0,o=t}finally{try{n||null==u.return||u.return()}finally{if(a)throw o}}return r}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function b(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function J(a){function o(){return JSON.parse(u().getItem(n)||"{}")}function i(t){u().setItem(n,JSON.stringify(t))}var t,n="algoliasearch-client-js-".concat(a.key),u=function(){return t=void 0===t?a.localStorage||window.localStorage:t};return{get:function(e,r){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return Promise.resolve().then(function(){r=a.timeToLive?1e3*a.timeToLive:null,t=o(),t=Object.fromEntries(Object.entries(t).filter(function(t){return void 0!==l(t,2)[1].timestamp})),i(t),r&&(t=Object.fromEntries(Object.entries(t).filter(function(t){var t=l(t,2)[1],e=(new Date).getTime();return!(t.timestamp+r<e)})),i(t));var r,t=JSON.stringify(e);return o()[t]}).then(function(t){return Promise.all([t?t.value:r(),void 0!==t])}).then(function(t){var t=l(t,2),e=t[0],t=t[1];return Promise.all([e,t||n.miss(e)])}).then(function(t){return l(t,1)[0]})},set:function(e,r){return Promise.resolve().then(function(){var t=o();return t[JSON.stringify(e)]={timestamp:(new Date).getTime(),value:r},u().setItem(n,JSON.stringify(t)),r})},delete:function(e){return Promise.resolve().then(function(){var t=o();delete t[JSON.stringify(e)],u().setItem(n,JSON.stringify(t))})},clear:function(){return Promise.resolve().then(function(){u().removeItem(n)})}}}function s(t){var o=0<arguments.length&&void 0!==t?t:{serializable:!0},i={};return{get:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}},t=JSON.stringify(t);if(t in i)return Promise.resolve(o.serializable?JSON.parse(i[t]):i[t]);var n=e(),a=r&&r.miss||function(){return Promise.resolve()};return n.then(function(t){return a(t)}).then(function(){return n})},set:function(t,e){return i[JSON.stringify(t)]=o.serializable?JSON.stringify(e):e,Promise.resolve(e)},delete:function(t){return delete i[JSON.stringify(t)],Promise.resolve()},clear:function(){return i={},Promise.resolve()}}}function c(t,e,r){var n={"x-algolia-api-key":r,"x-algolia-application-id":e};return{headers:function(){return t===m.WithinHeaders?n:{}},queryParameters:function(){return t===m.WithinQueryParameters?n:{}}}}function u(r){var n=0;return r(function e(){return n++,new Promise(function(t){setTimeout(function(){t(r(e))},Math.min(100*n,1e3))})})}function p(t,e){var r=1<arguments.length&&void 0!==e?e:function(t,e){return Promise.resolve()};return Object.assign(t,{wait:function(e){return p(t.then(function(t){return Promise.all([r(t,e),t])}).then(function(t){return t[1]}))}})}function f(e,r){return r&&Object.keys(r).forEach(function(t){e[t]=r[t](e)}),e}function h(t){for(var e=arguments.length,r=new Array(1<e?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];var a=0;return t.replace(/%s/g,function(){return encodeURIComponent(r[a++])})}var m={WithinQueryParameters:0,WithinHeaders:1};function y(t,e){var r=t||{},n=r.data||{};return Object.keys(r).forEach(function(t){-1===["timeout","headers","queryParameters","data","cacheable"].indexOf(t)&&(n[t]=r[t])}),{data:0<Object.entries(n).length?n:void 0,timeout:r.timeout||e,headers:r.headers||{},queryParameters:r.queryParameters||{},cacheable:r.cacheable}}var v={Read:1,Write:2,Any:3},F=2,O=3;function P(t,e){e=1<arguments.length&&void 0!==e?e:1;return g(g({},t),{},{status:e,lastUpdate:Date.now()})}function w(t){return"string"==typeof t?{protocol:"https",url:t,accept:v.Any}:{protocol:t.protocol||"https",url:t.url,accept:t.accept||v.Any}}var a="DELETE",i="GET",I="POST",j="PUT";function x(u,t,s,c){function f(r,n){var a=r.pop();if(void 0===a)throw{name:"RetryError",message:"Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",transporterStackTrace:H(d)};function o(t){return t={request:e,response:t,host:a,triesLeft:r.length},d.push(t),t}var e={data:l,headers:p,method:h,url:function(t,e,r){r=q(r),t="".concat(t.protocol,"://").concat(t.url,"/").concat("/"===e.charAt(0)?e.substr(1):e);return r.length&&(t+="?".concat(r)),t}(a,s.path,m),connectTimeout:n(y,u.timeouts.connect),responseTimeout:n(y,c.timeout)},i={onSuccess:function(e){try{return JSON.parse(e.content)}catch(t){throw{name:"DeserializationError",message:t.message,response:e}}},onRetry:function(t){var e=o(t);return t.isTimedOut&&y++,Promise.all([u.logger.info("Retryable failure",M(e)),u.hostsCache.set(a,P(a,t.isTimedOut?O:F))]).then(function(){return f(r,n)})},onFail:function(t){throw o(t),function(t,e){var r=t.content,n=t.status,a=r;try{a=JSON.parse(r).message}catch(t){}return{name:"ApiError",message:a,status:n,transporterStackTrace:e}}(t,H(d))}};return u.requester.send(e).then(function(t){return e=i,a=(r=t=t).status,r.isTimedOut||(n=r.isTimedOut,r=r.status,!n&&0==~~r)||2!=~~(a/100)&&4!=~~(a/100)?e.onRetry(t):2==~~(t.status/100)?e.onSuccess(t):e.onFail(t);var e,r,n,a})}var r,n,e,a,d=[],l=function(t,e){if(t.method!==i&&(void 0!==t.data||void 0!==e.data))return t=Array.isArray(t.data)?t.data:g(g({},t.data),e.data),JSON.stringify(t)}(s,c),p=(o=c,r=g(g({},u.headers),o.headers),n={},Object.keys(r).forEach(function(t){var e=r[t];n[t.toLowerCase()]=e}),n),h=s.method,o=s.method!==i?{}:g(g({},s.data),c.data),m=g(g(g({"x-algolia-agent":u.userAgent.value},u.queryParameters),o),c.queryParameters),y=0;return e=u.hostsCache,a=t,Promise.all(a.map(function(t){return e.get(t,function(){return Promise.resolve(P(t))})})).then(function(t){var e=t.filter(function(t){return 1===(t=t).status||12e4<Date.now()-t.lastUpdate}),r=t.filter(function(t){return(t=t).status===O&&Date.now()-t.lastUpdate<=12e4}),t=[].concat(b(e),b(r));return{getTimeout:function(t,e){return(0===r.length&&0===t?1:r.length+3+t)*e},statelessHosts:0<t.length?t.map(w):a}}).then(function(t){return f(b(t.statelessHosts).reverse(),t.getTimeout)})}function D(t){var e=t.hostsCache,r=t.logger,n=t.requester,a=t.requestsCache,o=t.responsesCache,i=t.timeouts,u=t.userAgent,s=t.hosts,c=t.queryParameters,f={hostsCache:e,logger:r,requester:n,requestsCache:a,responsesCache:o,timeouts:i,userAgent:u,headers:t.headers,queryParameters:c,hosts:s.map(w),read:function(t,e){function r(){return x(f,f.hosts.filter(function(t){return 0!=(t.accept&v.Read)}),t,n)}var n=y(e,f.timeouts.read);if(!0!==(void 0!==n.cacheable?n:t).cacheable)return r();var a={request:t,mappedRequestOptions:n,transporter:{queryParameters:f.queryParameters,headers:f.headers}};return f.responsesCache.get(a,function(){return f.requestsCache.get(a,function(){return f.requestsCache.set(a,r()).then(function(t){return Promise.all([f.requestsCache.delete(a),t])},function(t){return Promise.all([f.requestsCache.delete(a),Promise.reject(t)])}).then(function(t){t=l(t,2);return t[0],t[1]})})},{miss:function(t){return f.responsesCache.set(a,t)}})},write:function(t,e){return x(f,f.hosts.filter(function(t){return 0!=(t.accept&v.Write)}),t,y(e,f.timeouts.write))}};return f}function q(r){return Object.keys(r).map(function(t){return h("%s=%s",t,(e=r[t],"[object Object]"===Object.prototype.toString.call(e)||"[object Array]"===Object.prototype.toString.call(e)?JSON.stringify(r[t]):r[t]));var e}).join("&")}function H(t){return t.map(M)}function M(t){var e=t.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return g(g({},t),{},{request:g(g({},t.request),{},{headers:g(g({},t.request.headers),e)})})}function K(r){return function(t,e){return r.transporter.write({method:I,path:"2/abtests",data:t},e)}}function W(r){return function(t,e){return r.transporter.write({method:a,path:h("2/abtests/%s",t)},e)}}function B(r){return function(t,e){return r.transporter.read({method:i,path:h("2/abtests/%s",t)},e)}}function Q(e){return function(t){return e.transporter.read({method:i,path:"2/abtests"},t)}}function G(r){return function(t,e){return r.transporter.write({method:I,path:h("2/abtests/%s/stop",t)},e)}}function L(e){return function(t){return e.transporter.read({method:i,path:"1/strategies/personalization"},t)}}function V(r){return function(t,e){return r.transporter.write({method:I,path:"1/strategies/personalization",data:t},e)}}function n(n){return function e(r){return n.request(r).then(function(t){if(void 0!==n.batch&&n.batch(t.hits),!n.shouldStop(t))return t.cursor?e({cursor:t.cursor}):e({page:(r.page||0)+1})})}({})}function _(n){return function(t,e){var e=e||{},r=e.queryParameters,e=d(e,["queryParameters"]),t=g({acl:t},void 0!==r?{queryParameters:r}:{});return p(n.transporter.write({method:I,path:"1/keys",data:t},e),function(t,r){return u(function(e){return k(n)(t.key,r).catch(function(t){if(404!==t.status)throw t;return e()})})})}}function X(n){return function(t,e,r){r=y(r);return r.queryParameters["X-Algolia-User-ID"]=t,n.transporter.write({method:I,path:"1/clusters/mapping",data:{cluster:e}},r)}}function Y(n){return function(t,e,r){return n.transporter.write({method:I,path:"1/clusters/mapping/batch",data:{users:t,cluster:e}},r)}}function Z(r){return function(t,e){return p(r.transporter.write({method:I,path:h("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:!0,requests:{action:"addEntry",body:[]}}},e),function(t,e){return N(r)(t.taskID,e)})}}function $(n){return function(t,e,r){return S(n)(t,e,g(g({},r),{},{scope:[o.Rules]}))}}function tt(n){return function(t,e,r){return S(n)(t,e,g(g({},r),{},{scope:[o.Settings]}))}}function et(n){return function(t,e,r){return S(n)(t,e,g(g({},r),{},{scope:[o.Synonyms]}))}}function rt(r){return function(t,e){return t.method===i?r.transporter.read(t,e):r.transporter.write(t,e)}}function nt(n){return function(r,t){return p(n.transporter.write({method:a,path:h("1/keys/%s",r)},t),function(t,e){return u(function(t){return k(n)(r,e).then(t).catch(function(t){if(404!==t.status)throw t})})})}}function at(n){return function(t,e,r){e=e.map(function(t){return{action:"deleteEntry",body:{objectID:t}}});return p(n.transporter.write({method:I,path:h("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:!1,requests:e}},r),function(t,e){return N(n)(t.taskID,e)})}}function ot(e){return function(t){return e.transporter.read({method:i,path:"/1/dictionaries/*/settings"},t)}}function it(e){return function(t){return e.transporter.read({method:i,path:"1/logs"},t)}}function ut(e){return function(t){return e.transporter.read({method:i,path:"1/clusters/mapping/top"},t)}}function st(r){return function(t,e){return r.transporter.read({method:i,path:h("1/clusters/mapping/%s",t)},e)}}function ct(r){return function(t){var t=t||{},e=t.retrieveMappings,t=d(t,["retrieveMappings"]);return!0===e&&(t.getClusters=!0),r.transporter.read({method:i,path:"1/clusters/mapping/pending"},t)}}function ft(e){return function(t){return e.transporter.read({method:i,path:"1/keys"},t)}}function dt(e){return function(t){return e.transporter.read({method:i,path:"1/clusters"},t)}}function lt(e){return function(t){return e.transporter.read({method:i,path:"1/indexes"},t)}}function pt(e){return function(t){return e.transporter.read({method:i,path:"1/clusters/mapping"},t)}}function ht(n){return function(r,t,e){return p(n.transporter.write({method:I,path:h("1/indexes/%s/operation",r),data:{operation:"move",destination:t}},e),function(t,e){return T(n)(r,{methods:{waitTask:U}}).waitTask(t.taskID,e)})}}function mt(n){return function(t,e){return p(n.transporter.write({method:I,path:"1/indexes/*/batch",data:{requests:t}},e),function(e,r){return Promise.all(Object.keys(e.taskID).map(function(t){return T(n)(t,{methods:{waitTask:U}}).waitTask(e.taskID[t],r)}))})}}function yt(r){return function(t,e){return r.transporter.read({method:I,path:"1/indexes/*/objects",data:{requests:t}},e)}}function gt(r){return function(t,e){t=t.map(function(t){return g(g({},t),{},{params:q(t.params||{})})});return r.transporter.read({method:I,path:"1/indexes/*/queries",data:{requests:t},cacheable:!0},e)}}function bt(o){return function(t,a){return Promise.all(t.map(function(t){var e=t.params,r=e.facetName,n=e.facetQuery,e=d(e,["facetName","facetQuery"]);return T(o)(t.indexName,{methods:{searchForFacetValues:ie}}).searchForFacetValues(r,n,g(g({},a),e))}))}}function vt(r){return function(t,e){e=y(e);return e.queryParameters["X-Algolia-User-ID"]=t,r.transporter.write({method:a,path:"1/clusters/mapping"},e)}}function Ot(n){return function(t,e,r){e=e.map(function(t){return{action:"addEntry",body:t}});return p(n.transporter.write({method:I,path:h("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:!0,requests:e}},r),function(t,e){return N(n)(t.taskID,e)})}}function Pt(a){return function(n,t){return p(a.transporter.write({method:I,path:h("1/keys/%s/restore",n)},t),function(t,r){return u(function(e){return k(a)(n,r).catch(function(t){if(404!==t.status)throw t;return e()})})})}}function wt(n){return function(t,e,r){e=e.map(function(t){return{action:"addEntry",body:t}});return p(n.transporter.write({method:I,path:h("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:!1,requests:e}},r),function(t,e){return N(n)(t.taskID,e)})}}function It(n){return function(t,e,r){return n.transporter.read({method:I,path:h("/1/dictionaries/%s/search",t),data:{query:e},cacheable:!0},r)}}function jt(r){return function(t,e){return r.transporter.read({method:I,path:"1/clusters/mapping/search",data:{query:t}},e)}}function xt(r){return function(t,e){return p(r.transporter.write({method:j,path:"/1/dictionaries/*/settings",data:t},e),function(t,e){return N(r)(t.taskID,e)})}}function Dt(i){return function(n,t){var a=Object.assign({},t),t=t||{},e=t.queryParameters,t=d(t,["queryParameters"]),e=e?{queryParameters:e}:{},o=["acl","indexes","referers","restrictSources","queryParameters","description","maxQueriesPerIPPerHour","maxHitsPerQuery"];return p(i.transporter.write({method:j,path:h("1/keys/%s",n),data:e},t),function(t,e){return u(function(r){return k(i)(n,e).then(function(t){return e=t,Object.keys(a).filter(function(t){return-1!==o.indexOf(t)}).every(function(r){var t;return Array.isArray(e[r])&&Array.isArray(a[r])?(t=e[r]).length===a[r].length&&t.every(function(t,e){return t===a[r][e]}):e[r]===a[r]})?Promise.resolve():r();var e})})})}}function qt(r){return function(t,e){return p(r.transporter.write({method:I,path:h("1/indexes/%s/batch",r.indexName),data:{requests:t}},e),function(t,e){return U(r)(t.taskID,e)})}}function St(r){return function(e){return n(g(g({shouldStop:function(t){return void 0===t.cursor}},e),{},{request:function(t){return r.transporter.read({method:I,path:h("1/indexes/%s/browse",r.indexName),data:t},e)}}))}}function kt(r){return function(t){var e=g({hitsPerPage:1e3},t);return n(g(g({shouldStop:function(t){return t.hits.length<e.hitsPerPage}},e),{},{request:function(t){return ue(r)("",g(g({},e),t)).then(function(t){return g(g({},t),{},{hits:t.hits.map(function(t){return delete t._highlightResult,t})})})}}))}}function Tt(r){return function(t){var e=g({hitsPerPage:1e3},t);return n(g(g({shouldStop:function(t){return t.hits.length<e.hitsPerPage}},e),{},{request:function(t){return se(r)("",g(g({},e),t)).then(function(t){return g(g({},t),{},{hits:t.hits.map(function(t){return delete t._highlightResult,t})})})}}))}}function Nt(r){return function(t){return p(r.transporter.write({method:I,path:h("1/indexes/%s/clear",r.indexName)},t),function(t,e){return U(r)(t.taskID,e)})}}function Et(r){return function(t){var t=t||{},e=t.forwardToReplicas,t=y(d(t,["forwardToReplicas"]));return e&&(t.queryParameters.forwardToReplicas=1),p(r.transporter.write({method:I,path:h("1/indexes/%s/rules/clear",r.indexName)},t),function(t,e){return U(r)(t.taskID,e)})}}function Rt(r){return function(t){var t=t||{},e=t.forwardToReplicas,t=y(d(t,["forwardToReplicas"]));return e&&(t.queryParameters.forwardToReplicas=1),p(r.transporter.write({method:I,path:h("1/indexes/%s/synonyms/clear",r.indexName)},t),function(t,e){return U(r)(t.taskID,e)})}}function At(r){return function(t,e){return p(r.transporter.write({method:I,path:h("1/indexes/%s/deleteByQuery",r.indexName),data:t},e),function(t,e){return U(r)(t.taskID,e)})}}function Ct(r){return function(t){return p(r.transporter.write({method:a,path:h("1/indexes/%s",r.indexName)},t),function(t,e){return U(r)(t.taskID,e)})}}function Ut(r){return function(t,e){return p(re(r)([t],e).then(function(t){return{taskID:t.taskIDs[0]}}),function(t,e){return U(r)(t.taskID,e)})}}function zt(n){return function(t,e){var e=e||{},r=e.forwardToReplicas,e=y(d(e,["forwardToReplicas"]));return r&&(e.queryParameters.forwardToReplicas=1),p(n.transporter.write({method:a,path:h("1/indexes/%s/rules/%s",n.indexName,t)},e),function(t,e){return U(n)(t.taskID,e)})}}function Jt(n){return function(t,e){var e=e||{},r=e.forwardToReplicas,e=y(d(e,["forwardToReplicas"]));return r&&(e.queryParameters.forwardToReplicas=1),p(n.transporter.write({method:a,path:h("1/indexes/%s/synonyms/%s",n.indexName,t)},e),function(t,e){return U(n)(t.taskID,e)})}}function Ft(e){return function(t){return ne(e)(t).then(function(){return!0}).catch(function(t){if(404!==t.status)throw t;return!1})}}function Ht(n){return function(t,e,r){return n.transporter.read({method:I,path:h("1/answers/%s/prediction",n.indexName),data:{query:t,queryLanguages:e},cacheable:!0},r)}}function Mt(n){return function(i,t){var t=t||{},e=t.query,u=t.paginate,r=d(t,["query","paginate"]),s=0;return function o(){return oe(n)(e||"",g(g({},r),{},{page:s})).then(function(t){for(var e=0,r=Object.entries(t.hits);e<r.length;e++){var n=l(r[e],2),a=n[0],n=n[1];if(i(n))return{object:n,position:parseInt(a,10),page:s}}if(s++,!1===u||s>=t.nbPages)throw{name:"ObjectNotFoundError",message:"Object not found."};return o()})}()}}function Kt(r){return function(t,e){return r.transporter.read({method:i,path:h("1/indexes/%s/%s",r.indexName,t)},e)}}function Wt(){return function(t,e){for(var r=0,n=Object.entries(t.hits);r<n.length;r++){var a=l(n[r],2),o=a[0];if(a[1].objectID===e)return parseInt(o,10)}return-1}}function Bt(n){return function(t,e){var e=e||{},r=e.attributesToRetrieve,e=d(e,["attributesToRetrieve"]),t=t.map(function(t){return g({indexName:n.indexName,objectID:t},r?{attributesToRetrieve:r}:{})});return n.transporter.read({method:I,path:"1/indexes/*/objects",data:{requests:t}},e)}}function Qt(r){return function(t,e){return r.transporter.read({method:i,path:h("1/indexes/%s/rules/%s",r.indexName,t)},e)}}function Gt(r){return function(t,e){return r.transporter.read({method:i,path:h("1/indexes/%s/synonyms/%s",r.indexName,t)},e)}}function Lt(r){return function(t,e){return p(ae(r)([t],e).then(function(t){return{objectID:t.objectIDs[0],taskID:t.taskIDs[0]}}),function(t,e){return U(r)(t.taskID,e)})}}function Vt(f){return function(e,t){function r(t,e,r,n){return p(f.transporter.write({method:I,path:h("1/indexes/%s/operation",t),data:{operation:r,destination:e}},n),function(t,e){return U(f)(t.taskID,e)})}var t=t||{},n=t.safe,a=t.autoGenerateObjectIDIfNotExist,o=t.batchSize,i=d(t,["safe","autoGenerateObjectIDIfNotExist","batchSize"]),t=Math.random().toString(36).substring(7),u="".concat(f.indexName,"_tmp_").concat(t),s=R({appId:f.appId,transporter:f.transporter,indexName:u}),c=[],t=r(f.indexName,u,"copy",g(g({},i),{},{scope:["settings","synonyms","rules"]}));return c.push(t),p((n?t.wait(i):t).then(function(){var t=s(e,g(g({},i),{},{autoGenerateObjectIDIfNotExist:a,batchSize:o}));return c.push(t),n?t.wait(i):t}).then(function(){var t=r(u,f.indexName,"move",i);return c.push(t),n?t.wait(i):t}).then(function(){return Promise.all(c)}).then(function(t){var t=l(t,3),e=t[0],r=t[1],t=t[2];return{objectIDs:r.objectIDs,taskIDs:[e.taskID].concat(b(r.taskIDs),[t.taskID])}}),function(t,e){return Promise.all(c.map(function(t){return t.wait(e)}))})}}function _t(r){return function(t,e){return A(r)(t,g(g({},e),{},{clearExistingRules:!0}))}}function Xt(r){return function(t,e){return C(r)(t,g(g({},e),{},{clearExistingSynonyms:!0}))}}function Yt(r){return function(t,e){return p(R(r)([t],e).then(function(t){return{objectID:t.objectIDs[0],taskID:t.taskIDs[0]}}),function(t,e){return U(r)(t.taskID,e)})}}function Zt(r){return function(t,e){return A(r)([t],e)}}function $t(r){return function(t,e){return C(r)([t],e)}}function te(n){return function(t,e){var e=e||{},r=e.forwardToReplicas,e=y(d(e,["forwardToReplicas"]));return r&&(e.queryParameters.forwardToReplicas=1),p(n.transporter.write({method:j,path:h("1/indexes/%s/settings",n.indexName),data:t},e),function(t,e){return U(n)(t.taskID,e)})}}var S=function(n){return function(r,t,e){return p(n.transporter.write({method:I,path:h("1/indexes/%s/operation",r),data:{operation:"copy",destination:t}},e),function(t,e){return T(n)(r,{methods:{waitTask:U}}).waitTask(t.taskID,e)})}},k=function(r){return function(t,e){return r.transporter.read({method:i,path:h("1/keys/%s",t)},e)}},ee=function(r){return function(t,e){return r.transporter.read({method:i,path:h("1/task/%s",t.toString())},e)}},T=function(e){return function(t){return f({transporter:e.transporter,appId:e.appId,indexName:t},(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).methods)}},N=function(n){return function(t,r){return u(function(e){return ee(n)(t,r).then(function(t){return"published"!==t.status?e():void 0})})}},E=function(s){return function(n,a,t){var t=t||{},o=t.batchSize,i=d(t,["batchSize"]),u={taskIDs:[],objectIDs:[]};return p(function e(){for(var t=[],r=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;r<n.length&&(t.push(n[r]),t.length!==(o||1e3));r++);return 0===t.length?Promise.resolve(u):qt(s)(t.map(function(t){return{action:a,body:t}}),i).then(function(t){return u.objectIDs=u.objectIDs.concat(t.objectIDs),u.taskIDs.push(t.taskID),e(++r)})}(),function(t,e){return Promise.all(t.taskIDs.map(function(t){return U(s)(t,e)}))})}},re=function(r){return function(t,e){t=t.map(function(t){return{objectID:t}});return E(r)(t,z.DeleteObject,e)}},ne=function(e){return function(t){return e.transporter.read({method:i,path:h("1/indexes/%s/settings",e.indexName),data:{getVersion:2}},t)}},ae=function(n){return function(t,e){var e=e||{},r=e.createIfNotExists,e=d(e,["createIfNotExists"]),r=r?z.PartialUpdateObject:z.PartialUpdateObjectNoCreate;return E(n)(t,r,e)}},R=function(s){return function(t,e){var e=e||{},r=e.autoGenerateObjectIDIfNotExist,e=d(e,["autoGenerateObjectIDIfNotExist"]),r=r?z.AddObject:z.UpdateObject;if(r===z.UpdateObject){var n=!0,a=!1,o=void 0;try{for(var i,u=t[Symbol.iterator]();!(n=(i=u.next()).done);n=!0)if(void 0===i.value.objectID)return p(Promise.reject({name:"MissingObjectIDError",message:"All objects must have an unique objectID (like a primary key) to be valid. Algolia is also able to generate objectIDs automatically but *it's not recommended*. To do it, use the `{'autoGenerateObjectIDIfNotExist': true}` option."}))}catch(t){a=!0,o=t}finally{try{n||null==u.return||u.return()}finally{if(a)throw o}}}return E(s)(t,r,e)}},A=function(a){return function(t,e){var e=e||{},r=e.forwardToReplicas,n=e.clearExistingRules,e=y(d(e,["forwardToReplicas","clearExistingRules"]));return r&&(e.queryParameters.forwardToReplicas=1),n&&(e.queryParameters.clearExistingRules=1),p(a.transporter.write({method:I,path:h("1/indexes/%s/rules/batch",a.indexName),data:t},e),function(t,e){return U(a)(t.taskID,e)})}},C=function(o){return function(t,e){var e=e||{},r=e.forwardToReplicas,n=e.clearExistingSynonyms,a=e.replaceExistingSynonyms,e=y(d(e,["forwardToReplicas","clearExistingSynonyms","replaceExistingSynonyms"]));return r&&(e.queryParameters.forwardToReplicas=1),(a||n)&&(e.queryParameters.replaceExistingSynonyms=1),p(o.transporter.write({method:I,path:h("1/indexes/%s/synonyms/batch",o.indexName),data:t},e),function(t,e){return U(o)(t.taskID,e)})}},oe=function(r){return function(t,e){return r.transporter.read({method:I,path:h("1/indexes/%s/query",r.indexName),data:{query:t},cacheable:!0},e)}},ie=function(n){return function(t,e,r){return n.transporter.read({method:I,path:h("1/indexes/%s/facets/%s/query",n.indexName,t),data:{facetQuery:e},cacheable:!0},r)}},ue=function(r){return function(t,e){return r.transporter.read({method:I,path:h("1/indexes/%s/rules/search",r.indexName),data:{query:t}},e)}},se=function(r){return function(t,e){return r.transporter.read({method:I,path:h("1/indexes/%s/synonyms/search",r.indexName),data:{query:t}},e)}},U=function(a){return function(t,n){return u(function(e){return r=a,function(t,e){return r.transporter.read({method:i,path:h("1/indexes/%s/task/%s",r.indexName,t.toString())},e)}(t,n).then(function(t){return"published"!==t.status?e():void 0});var r})}},z={AddObject:"addObject",UpdateObject:"updateObject",PartialUpdateObject:"partialUpdateObject",PartialUpdateObjectNoCreate:"partialUpdateObjectNoCreate",DeleteObject:"deleteObject",DeleteIndex:"delete",ClearIndex:"clear"},o={Settings:"settings",Synonyms:"synonyms",Rules:"rules"};function t(t,e,r){function n(){return function(t){return t=g(g(g({},i),t),{},{methods:{getPersonalizationStrategy:L,setPersonalizationStrategy:V}}),e=t.region||"us",r=c(m.WithinHeaders,t.appId,t.apiKey),e=D(g(g({hosts:[{url:"personalization.".concat(e,".algolia.com")}]},t),{},{headers:g(g(g({},r.headers()),{"content-type":"application/json"}),t.headers),queryParameters:g(g({},r.queryParameters()),t.queryParameters)})),f({appId:t.appId,transporter:e},t.methods);var e,r}}var a,o,i={appId:t,apiKey:e,timeouts:{connect:1,read:2,write:30},requester:{send:function(o){return new Promise(function(r){var n=new XMLHttpRequest;n.open(o.method,o.url,!0),Object.keys(o.headers).forEach(function(t){return n.setRequestHeader(t,o.headers[t])});function t(t,e){return setTimeout(function(){n.abort(),r({status:0,content:e,isTimedOut:!0})},1e3*t)}var e,a=t(o.connectTimeout,"Connection timeout");n.onreadystatechange=function(){n.readyState>n.OPENED&&void 0===e&&(clearTimeout(a),e=t(o.responseTimeout,"Socket timeout"))},n.onerror=function(){0===n.status&&(clearTimeout(a),clearTimeout(e),r({content:n.responseText||"Network request failed",status:n.status,isTimedOut:!1}))},n.onload=function(){clearTimeout(a),clearTimeout(e),r({content:n.responseText,status:n.status,isTimedOut:!1})},n.send(o.data)})}},logger:{debug:function(t,e){return Promise.resolve()},info:function(t,e){return Promise.resolve()},error:function(t,e){return console.error(t,e),Promise.resolve()}},responsesCache:s(),requestsCache:s({serializable:!1}),hostsCache:function n(t){var a=b(t.caches),o=a.shift();return void 0===o?{get:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return e().then(function(t){return Promise.all([t,r.miss(t)])}).then(function(t){return l(t,1)[0]})},set:function(t,e){return Promise.resolve(e)},delete:function(t){return Promise.resolve()},clear:function(){return Promise.resolve()}}:{get:function(t,e){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return o.get(t,e,r).catch(function(){return n({caches:a}).get(t,e,r)})},set:function(t,e){return o.set(t,e).catch(function(){return n({caches:a}).set(t,e)})},delete:function(t){return o.delete(t).catch(function(){return n({caches:a}).delete(t)})},clear:function(){return o.clear().catch(function(){return n({caches:a}).clear()})}}}({caches:[J({key:"".concat("4.22.1","-").concat(t)}),s()]}),userAgent:(a={value:"Algolia for JavaScript (".concat("4.22.1",")"),add:function(t){t="; ".concat(t.segment).concat(void 0!==t.version?" (".concat(t.version,")"):"");return-1===a.value.indexOf(t)&&(a.value="".concat(a.value).concat(t)),a}}).add({segment:"Browser"})},u=g(g({},i),r);return e=g(g({},u),{},{methods:{search:gt,searchForFacetValues:bt,multipleBatch:mt,multipleGetObjects:yt,multipleQueries:gt,copyIndex:S,copySettings:tt,copySynonyms:et,copyRules:$,moveIndex:ht,listIndices:lt,getLogs:it,listClusters:dt,multipleSearchForFacetValues:bt,getApiKey:k,addApiKey:_,listApiKeys:ft,updateApiKey:Dt,deleteApiKey:nt,restoreApiKey:Pt,assignUserID:X,assignUserIDs:Y,getUserID:st,searchUserIDs:jt,listUserIDs:pt,getTopUserIDs:ut,removeUserID:vt,hasPendingMappings:ct,clearDictionaryEntries:Z,deleteDictionaryEntries:at,getDictionarySettings:ot,getAppTask:ee,replaceDictionaryEntries:Ot,saveDictionaryEntries:wt,searchDictionaryEntries:It,setDictionarySettings:xt,waitAppTask:N,customRequest:rt,initIndex:function(e){return function(t){return T(e)(t,{methods:{batch:qt,delete:Ct,findAnswers:Ht,getObject:Kt,getObjects:Bt,saveObject:Yt,saveObjects:R,search:oe,searchForFacetValues:ie,waitTask:U,setSettings:te,getSettings:ne,partialUpdateObject:Lt,partialUpdateObjects:ae,deleteObject:Ut,deleteObjects:re,deleteBy:At,clearObjects:Nt,browseObjects:St,getObjectPosition:Wt,findObject:Mt,exists:Ft,saveSynonym:$t,saveSynonyms:C,getSynonym:Gt,searchSynonyms:se,browseSynonyms:Tt,deleteSynonym:Jt,clearSynonyms:Rt,replaceAllObjects:Vt,replaceAllSynonyms:Xt,searchRules:ue,getRule:Qt,deleteRule:zt,saveRule:Zt,saveRules:A,replaceAllRules:_t,browseRules:kt,clearRules:Et}})}},initAnalytics:function(){return function(t){return t=g(g(g({},i),t),{},{methods:{addABTest:K,getABTest:B,getABTests:Q,stopABTest:G,deleteABTest:W}}),e=t.region||"us",r=c(m.WithinHeaders,t.appId,t.apiKey),e=D(g(g({hosts:[{url:"analytics.".concat(e,".algolia.com")}]},t),{},{headers:g(g(g({},r.headers()),{"content-type":"application/json"}),t.headers),queryParameters:g(g({},r.queryParameters()),t.queryParameters)})),f({appId:t.appId,transporter:e},t.methods);var e,r}},initPersonalization:n,initRecommendation:function(){return function(t){return u.logger.info("The `initRecommendation` method is deprecated. Use `initPersonalization` instead."),n()(t)}}}}),t=e.appId,r=c(void 0!==e.authMode?e.authMode:m.WithinHeaders,t,e.apiKey),f({transporter:o=D(g(g({hosts:[{url:"".concat(t,"-dsn.algolia.net"),accept:v.Read},{url:"".concat(t,".algolia.net"),accept:v.Write}].concat(function(t){for(var e=t.length-1;0<e;e--){var r=Math.floor(Math.random()*(e+1)),n=t[e];t[e]=t[r],t[r]=n}return t}([{url:"".concat(t,"-1.algolianet.com")},{url:"".concat(t,"-2.algolianet.com")},{url:"".concat(t,"-3.algolianet.com")}]))},e),{},{headers:g(g(g({},r.headers()),{"content-type":"application/x-www-form-urlencoded"}),e.headers),queryParameters:g(g({},r.queryParameters()),e.queryParameters)})),appId:t,addAlgoliaAgent:function(t,e){o.userAgent.add({segment:t,version:e})},clearCache:function(){return Promise.all([o.requestsCache.clear(),o.responsesCache.clear()]).then(function(){})}},e.methods)}return t.version="4.22.1",t});