mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2024-12-11 10:45:37 +01:00
1 line
31 KiB
JavaScript
1 line
31 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,t=a[r=t],r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t}):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 p(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 h(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 m(t,e,r){var n={"x-algolia-api-key":r,"x-algolia-application-id":e};return{headers:function(){return t===P.WithinHeaders?n:{}},queryParameters:function(){return t===P.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 l(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 l(t.then(function(t){return Promise.all([r(t,e),t])}).then(function(t){return t[1]}))}})}function y(e,r){return r&&Object.keys(r).forEach(function(t){e[t]=r[t](e)}),e}function v(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 P={WithinQueryParameters:0,WithinHeaders:1};function w(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 O={Read:1,Write:2,Any:3},I=2,x=3;function j(t,e){e=1<arguments.length&&void 0!==e?e:1;return g(g({},t),{},{status:e,lastUpdate:Date.now()})}function D(t){return"string"==typeof t?{protocol:"https",url:t,accept:O.Any}:{protocol:t.protocol||"https",url:t.url,accept:t.accept||O.Any}}var a="DELETE",o="GET",q="POST",s="PUT";function i(e,n){return Promise.all(n.map(function(t){return e.get(t,function(){return Promise.resolve(j(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===x&&Date.now()-t.lastUpdate<=12e4}),e=[].concat(b(e),b(r));return{getTimeout:function(t,e){return(0===r.length&&0===t?1:r.length+3+t)*e},statelessHosts:0<e.length?e.map(D):n}})}function S(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:N(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=T(r),e="".concat(t.protocol,"://").concat(t.url,"/").concat("/"===e.charAt(0)?e.substr(1):e);return r.length&&(e+="?".concat(r)),e}(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",E(e)),u.hostsCache.set(a,j(a,t.isTimedOut?x:I))]).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,N(d))}};return u.requester.send(e).then(function(t){return r=i,a=(n=e=t).status,n.isTimedOut||(t=n.isTimedOut,n=n.status,!t&&0==~~n)||2!=~~(a/100)&&4!=~~(a/100)?r.onRetry(e):2==~~(e.status/100)?r.onSuccess(e):r.onFail(e);var e,r,n,a})}var e,r,n,d=[],l=function(t,e){if(t.method!==o&&(void 0!==t.data||void 0!==e.data)){e=Array.isArray(t.data)?t.data:g(g({},t.data),e.data);return JSON.stringify(e)}}(s,c),p=(e=c,r=g(g({},u.headers),e.headers),n={},Object.keys(r).forEach(function(t){var e=r[t];n[t.toLowerCase()]=e}),n),h=s.method,e=s.method!==o?{}:g(g({},s.data),c.data),m=g(g(g({"x-algolia-agent":u.userAgent.value},u.queryParameters),e),c.queryParameters),y=0;return i(u.hostsCache,t).then(function(t){return f(b(t.statelessHosts).reverse(),t.getTimeout)})}function k(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(D),read:function(t,e){function r(){return S(f,f.hosts.filter(function(t){return 0!=(t.accept&O.Read)}),t,n)}var n=w(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=p(t,2);return t[0],t[1]})})},{miss:function(t){return f.responsesCache.set(a,t)}})},write:function(t,e){return S(f,f.hosts.filter(function(t){return 0!=(t.accept&O.Write)}),t,w(e,f.timeouts.write))}};return f}function T(r){return Object.keys(r).map(function(t){return v("%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 N(t){return t.map(E)}function E(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 R(r){return function(t,e){return r.transporter.write({method:q,path:"2/abtests",data:t},e)}}function A(r){return function(t,e){return r.transporter.write({method:a,path:v("2/abtests/%s",t)},e)}}function C(r){return function(t,e){return r.transporter.read({method:o,path:v("2/abtests/%s",t)},e)}}function U(e){return function(t){return e.transporter.read({method:o,path:"2/abtests"},t)}}function z(r){return function(t,e){return r.transporter.write({method:q,path:v("2/abtests/%s/stop",t)},e)}}function J(e){return function(t){return e.transporter.read({method:o,path:"1/strategies/personalization"},t)}}function F(r){return function(t,e){return r.transporter.write({method:q,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 H(n){return function(t,e){var r=e||{},e=r.queryParameters,r=d(r,["queryParameters"]),e=g({acl:t},void 0!==e?{queryParameters:e}:{});return l(n.transporter.write({method:q,path:"1/keys",data:e},r),function(t,r){return u(function(e){return Lt(n)(t.key,r).catch(function(t){if(404!==t.status)throw t;return e()})})})}}function M(n){return function(t,e,r){r=w(r);return r.queryParameters["X-Algolia-User-ID"]=t,n.transporter.write({method:q,path:"1/clusters/mapping",data:{cluster:e}},r)}}function K(n){return function(t,e,r){return n.transporter.write({method:q,path:"1/clusters/mapping/batch",data:{users:t,cluster:e}},r)}}function W(r){return function(t,e){return l(r.transporter.write({method:q,path:v("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:!0,requests:{action:"addEntry",body:[]}}},e),function(t,e){return Xt(r)(t.taskID,e)})}}function B(n){return function(t,e,r){return Gt(n)(t,e,g(g({},r),{},{scope:[se.Rules]}))}}function Q(n){return function(t,e,r){return Gt(n)(t,e,g(g({},r),{},{scope:[se.Settings]}))}}function G(n){return function(t,e,r){return Gt(n)(t,e,g(g({},r),{},{scope:[se.Synonyms]}))}}function L(r){return function(t,e){return t.method===o?r.transporter.read(t,e):r.transporter.write(t,e)}}function V(n){return function(r,t){return l(n.transporter.write({method:a,path:v("1/keys/%s",r)},t),function(t,e){return u(function(t){return Lt(n)(r,e).then(t).catch(function(t){if(404!==t.status)throw t})})})}}function _(n){return function(t,e,r){e=e.map(function(t){return{action:"deleteEntry",body:{objectID:t}}});return l(n.transporter.write({method:q,path:v("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:!1,requests:e}},r),function(t,e){return Xt(n)(t.taskID,e)})}}function X(e){return function(t){return e.transporter.read({method:o,path:"/1/dictionaries/*/settings"},t)}}function Y(e){return function(t){return e.transporter.read({method:o,path:"1/logs"},t)}}function Z(e){return function(t){return e.transporter.read({method:o,path:"1/clusters/mapping/top"},t)}}function $(r){return function(t,e){return r.transporter.read({method:o,path:v("1/clusters/mapping/%s",t)},e)}}function tt(r){return function(t){var e=t||{},t=e.retrieveMappings,e=d(e,["retrieveMappings"]);return!0===t&&(e.getClusters=!0),r.transporter.read({method:o,path:"1/clusters/mapping/pending"},e)}}function et(e){return function(t){return e.transporter.read({method:o,path:"1/keys"},t)}}function rt(e){return function(t){return e.transporter.read({method:o,path:"1/clusters"},t)}}function nt(e){return function(t){return e.transporter.read({method:o,path:"1/indexes"},t)}}function at(e){return function(t){return e.transporter.read({method:o,path:"1/clusters/mapping"},t)}}function ot(n){return function(r,t,e){return l(n.transporter.write({method:q,path:v("1/indexes/%s/operation",r),data:{operation:"move",destination:t}},e),function(t,e){return _t(n)(r,{methods:{waitTask:ue}}).waitTask(t.taskID,e)})}}function it(n){return function(t,e){return l(n.transporter.write({method:q,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:ue}}).waitTask(e.taskID[t],r)}))})}}function ut(r){return function(t,e){return r.transporter.read({method:q,path:"1/indexes/*/objects",data:{requests:t}},e)}}function st(r){return function(t,e){t=t.map(function(t){return g(g({},t),{},{params:T(t.params||{})})});return r.transporter.read({method:q,path:"1/indexes/*/queries",data:{requests:t},cacheable:!0},e)}}function ct(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:ae}}).searchForFacetValues(r,n,g(g({},a),e))}))}}function ft(r){return function(t,e){e=w(e);return e.queryParameters["X-Algolia-User-ID"]=t,r.transporter.write({method:a,path:"1/clusters/mapping"},e)}}function dt(n){return function(t,e,r){e=e.map(function(t){return{action:"addEntry",body:t}});return l(n.transporter.write({method:q,path:v("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:!0,requests:e}},r),function(t,e){return Xt(n)(t.taskID,e)})}}function lt(a){return function(n,t){return l(a.transporter.write({method:q,path:v("1/keys/%s/restore",n)},t),function(t,r){return u(function(e){return Lt(a)(n,r).catch(function(t){if(404!==t.status)throw t;return e()})})})}}function pt(n){return function(t,e,r){e=e.map(function(t){return{action:"addEntry",body:t}});return l(n.transporter.write({method:q,path:v("/1/dictionaries/%s/batch",t),data:{clearExistingDictionaryEntries:!1,requests:e}},r),function(t,e){return Xt(n)(t.taskID,e)})}}function ht(n){return function(t,e,r){return n.transporter.read({method:q,path:v("/1/dictionaries/%s/search",t),data:{query:e},cacheable:!0},r)}}function mt(r){return function(t,e){return r.transporter.read({method:q,path:"1/clusters/mapping/search",data:{query:t}},e)}}function yt(r){return function(t,e){return l(r.transporter.write({method:s,path:"/1/dictionaries/*/settings",data:t},e),function(t,e){return Xt(r)(t.taskID,e)})}}function gt(i){return function(n,t){var a=Object.assign({},t),e=t||{},t=e.queryParameters,e=d(e,["queryParameters"]),t=t?{queryParameters:t}:{},o=["acl","indexes","referers","restrictSources","queryParameters","description","maxQueriesPerIPPerHour","maxHitsPerQuery"];return l(i.transporter.write({method:s,path:v("1/keys/%s",n),data:t},e),function(t,e){return u(function(r){return Lt(i)(n,e).then(function(t){return e=t,Object.keys(a).filter(function(t){return-1!==o.indexOf(t)}).every(function(t){return e[t]===a[t]})?Promise.resolve():r();var e})})})}}function bt(r){return function(t,e){return l(r.transporter.write({method:q,path:v("1/indexes/%s/batch",r.indexName),data:{requests:t}},e),function(t,e){return ue(r)(t.taskID,e)})}}function vt(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:q,path:v("1/indexes/%s/browse",r.indexName),data:t},e)}}))}}function Pt(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 oe(r)("",g(g({},e),t)).then(function(t){return g(g({},t),{},{hits:t.hits.map(function(t){return delete t._highlightResult,t})})})}}))}}function wt(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 ie(r)("",g(g({},e),t)).then(function(t){return g(g({},t),{},{hits:t.hits.map(function(t){return delete t._highlightResult,t})})})}}))}}function Ot(r){return function(t){return l(r.transporter.write({method:q,path:v("1/indexes/%s/clear",r.indexName)},t),function(t,e){return ue(r)(t.taskID,e)})}}function It(r){return function(t){var e=t||{},t=e.forwardToReplicas,e=w(d(e,["forwardToReplicas"]));return t&&(e.queryParameters.forwardToReplicas=1),l(r.transporter.write({method:q,path:v("1/indexes/%s/rules/clear",r.indexName)},e),function(t,e){return ue(r)(t.taskID,e)})}}function xt(r){return function(t){var e=t||{},t=e.forwardToReplicas,e=w(d(e,["forwardToReplicas"]));return t&&(e.queryParameters.forwardToReplicas=1),l(r.transporter.write({method:q,path:v("1/indexes/%s/synonyms/clear",r.indexName)},e),function(t,e){return ue(r)(t.taskID,e)})}}function jt(r){return function(t,e){return l(r.transporter.write({method:q,path:v("1/indexes/%s/deleteByQuery",r.indexName),data:t},e),function(t,e){return ue(r)(t.taskID,e)})}}function Dt(r){return function(t){return l(r.transporter.write({method:a,path:v("1/indexes/%s",r.indexName)},t),function(t,e){return ue(r)(t.taskID,e)})}}function qt(r){return function(t,e){return l(Yt(r)([t],e).then(function(t){return{taskID:t.taskIDs[0]}}),function(t,e){return ue(r)(t.taskID,e)})}}function St(n){return function(t,e){var r=e||{},e=r.forwardToReplicas,r=w(d(r,["forwardToReplicas"]));return e&&(r.queryParameters.forwardToReplicas=1),l(n.transporter.write({method:a,path:v("1/indexes/%s/rules/%s",n.indexName,t)},r),function(t,e){return ue(n)(t.taskID,e)})}}function kt(n){return function(t,e){var r=e||{},e=r.forwardToReplicas,r=w(d(r,["forwardToReplicas"]));return e&&(r.queryParameters.forwardToReplicas=1),l(n.transporter.write({method:a,path:v("1/indexes/%s/synonyms/%s",n.indexName,t)},r),function(t,e){return ue(n)(t.taskID,e)})}}function Tt(e){return function(t){return Zt(e)(t).then(function(){return!0}).catch(function(t){if(404!==t.status)throw t;return!1})}}function Nt(n){return function(t,e,r){return n.transporter.read({method:q,path:v("1/answers/%s/prediction",n.indexName),data:{query:t,queryLanguages:e},cacheable:!0},r)}}function Et(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 ne(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=p(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 Rt(r){return function(t,e){return r.transporter.read({method:o,path:v("1/indexes/%s/%s",r.indexName,t)},e)}}function At(){return function(t,e){for(var r=0,n=Object.entries(t.hits);r<n.length;r++){var a=p(n[r],2),o=a[0];if(a[1].objectID===e)return parseInt(o,10)}return-1}}function Ct(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:q,path:"1/indexes/*/objects",data:{requests:t}},e)}}function Ut(r){return function(t,e){return r.transporter.read({method:o,path:v("1/indexes/%s/rules/%s",r.indexName,t)},e)}}function zt(r){return function(t,e){return r.transporter.read({method:o,path:v("1/indexes/%s/synonyms/%s",r.indexName,t)},e)}}function Jt(r){return function(t,e){return l($t(r)([t],e).then(function(t){return{objectID:t.objectIDs[0],taskID:t.taskIDs[0]}}),function(t,e){return ue(r)(t.taskID,e)})}}function Ft(f){return function(e,t){function r(t,e,r,n){return l(f.transporter.write({method:q,path:v("1/indexes/%s/operation",t),data:{operation:r,destination:e}},n),function(t,e){return ue(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=te({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),l((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 e=p(t,3),r=e[0],t=e[1],e=e[2];return{objectIDs:t.objectIDs,taskIDs:[r.taskID].concat(b(t.taskIDs),[e.taskID])}}),function(t,e){return Promise.all(c.map(function(t){return t.wait(e)}))})}}function Ht(r){return function(t,e){return ee(r)(t,g(g({},e),{},{clearExistingRules:!0}))}}function Mt(r){return function(t,e){return re(r)(t,g(g({},e),{},{clearExistingSynonyms:!0}))}}function Kt(r){return function(t,e){return l(te(r)([t],e).then(function(t){return{objectID:t.objectIDs[0],taskID:t.taskIDs[0]}}),function(t,e){return ue(r)(t.taskID,e)})}}function Wt(r){return function(t,e){return ee(r)([t],e)}}function Bt(r){return function(t,e){return re(r)([t],e)}}function Qt(n){return function(t,e){var r=e||{},e=r.forwardToReplicas,r=w(d(r,["forwardToReplicas"]));return e&&(r.queryParameters.forwardToReplicas=1),l(n.transporter.write({method:s,path:v("1/indexes/%s/settings",n.indexName),data:t},r),function(t,e){return ue(n)(t.taskID,e)})}}var Gt=function(n){return function(r,t,e){return l(n.transporter.write({method:q,path:v("1/indexes/%s/operation",r),data:{operation:"copy",destination:t}},e),function(t,e){return _t(n)(r,{methods:{waitTask:ue}}).waitTask(t.taskID,e)})}},Lt=function(r){return function(t,e){return r.transporter.read({method:o,path:v("1/keys/%s",t)},e)}},Vt=function(r){return function(t,e){return r.transporter.read({method:o,path:v("1/task/%s",t.toString())},e)}},_t=function(e){return function(t){return y({transporter:e.transporter,appId:e.appId,indexName:t},(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).methods)}},Xt=function(n){return function(t,r){return u(function(e){return Vt(n)(t,r).then(function(t){return"published"!==t.status?e():void 0})})}},c=function(s){return function(n,a,t){var t=t||{},o=t.batchSize,i=d(t,["batchSize"]),u={taskIDs:[],objectIDs:[]};return l(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):bt(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 ue(s)(t,e)}))})}},Yt=function(r){return function(t,e){t=t.map(function(t){return{objectID:t}});return c(r)(t,f.DeleteObject,e)}},Zt=function(e){return function(t){return e.transporter.read({method:o,path:v("1/indexes/%s/settings",e.indexName),data:{getVersion:2}},t)}},$t=function(n){return function(t,e){var r=e||{},e=r.createIfNotExists,r=d(r,["createIfNotExists"]),e=e?f.PartialUpdateObject:f.PartialUpdateObjectNoCreate;return c(n)(t,e,r)}},te=function(s){return function(t,e){var r=e||{},n=r.autoGenerateObjectIDIfNotExist,a=d(r,["autoGenerateObjectIDIfNotExist"]),e=n?f.AddObject:f.UpdateObject;if(e===f.UpdateObject){var o=!0,r=!1,n=void 0;try{for(var i,u=t[Symbol.iterator]();!(o=(i=u.next()).done);o=!0)if(void 0===i.value.objectID)return l(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){r=!0,n=t}finally{try{o||null==u.return||u.return()}finally{if(r)throw n}}}return c(s)(t,e,a)}},ee=function(a){return function(t,e){var r=e||{},n=r.forwardToReplicas,e=r.clearExistingRules,r=w(d(r,["forwardToReplicas","clearExistingRules"]));return n&&(r.queryParameters.forwardToReplicas=1),e&&(r.queryParameters.clearExistingRules=1),l(a.transporter.write({method:q,path:v("1/indexes/%s/rules/batch",a.indexName),data:t},r),function(t,e){return ue(a)(t.taskID,e)})}},re=function(o){return function(t,e){var r=e||{},n=r.forwardToReplicas,a=r.clearExistingSynonyms,e=r.replaceExistingSynonyms,r=w(d(r,["forwardToReplicas","clearExistingSynonyms","replaceExistingSynonyms"]));return n&&(r.queryParameters.forwardToReplicas=1),(e||a)&&(r.queryParameters.replaceExistingSynonyms=1),l(o.transporter.write({method:q,path:v("1/indexes/%s/synonyms/batch",o.indexName),data:t},r),function(t,e){return ue(o)(t.taskID,e)})}},ne=function(r){return function(t,e){return r.transporter.read({method:q,path:v("1/indexes/%s/query",r.indexName),data:{query:t},cacheable:!0},e)}},ae=function(n){return function(t,e,r){return n.transporter.read({method:q,path:v("1/indexes/%s/facets/%s/query",n.indexName,t),data:{facetQuery:e},cacheable:!0},r)}},oe=function(r){return function(t,e){return r.transporter.read({method:q,path:v("1/indexes/%s/rules/search",r.indexName),data:{query:t}},e)}},ie=function(r){return function(t,e){return r.transporter.read({method:q,path:v("1/indexes/%s/synonyms/search",r.indexName),data:{query:t}},e)}},ue=function(a){return function(t,n){return u(function(e){return r=a,function(t,e){return r.transporter.read({method:o,path:v("1/indexes/%s/task/%s",r.indexName,t.toString())},e)}(t,n).then(function(t){return"published"!==t.status?e():void 0});var r})}},f={AddObject:"addObject",UpdateObject:"updateObject",PartialUpdateObject:"partialUpdateObject",PartialUpdateObjectNoCreate:"partialUpdateObjectNoCreate",DeleteObject:"deleteObject",DeleteIndex:"delete",ClearIndex:"clear"},se={Settings:"settings",Synonyms:"synonyms",Rules:"rules"};function t(t,e,r){function n(){return function(t){return e=g(g(g({},c),t),{},{methods:{getPersonalizationStrategy:J,setPersonalizationStrategy:F}}),r=e.region||"us",t=m(P.WithinHeaders,e.appId,e.apiKey),t=k(g(g({hosts:[{url:"personalization.".concat(r,".algolia.com")}]},e),{},{headers:g(g(g({},t.headers()),{"content-type":"application/json"}),e.headers),queryParameters:g(g({},t.queryParameters()),e.queryParameters)})),y({appId:e.appId,transporter:t},e.methods);var e,r}}var a,o,i,u,s,c={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:h(),requestsCache:h({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 p(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:[(o={key:"".concat("4.11.0","-").concat(t)},u="algoliasearch-client-js-".concat(o.key),{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(){var t=JSON.stringify(e),t=l()[t];return Promise.all([t||r(),void 0!==t])}).then(function(t){var e=p(t,2),t=e[0],e=e[1];return Promise.all([t,e||n.miss(t)])}).then(function(t){return p(t,1)[0]})},set:function(e,r){return Promise.resolve().then(function(){var t=l();return t[JSON.stringify(e)]=r,d().setItem(u,JSON.stringify(t)),r})},delete:function(e){return Promise.resolve().then(function(){var t=l();delete t[JSON.stringify(e)],d().setItem(u,JSON.stringify(t))})},clear:function(){return Promise.resolve().then(function(){d().removeItem(u)})}}),h()]}),userAgent:(a={value:"Algolia for JavaScript (".concat("4.11.0",")"),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"})},f=g(g({},c),r);function d(){return i=void 0===i?o.localStorage||window.localStorage:i}function l(){return JSON.parse(d().getItem(u)||"{}")}return e=g(g({},f),{},{methods:{search:st,searchForFacetValues:ct,multipleBatch:it,multipleGetObjects:ut,multipleQueries:st,copyIndex:Gt,copySettings:Q,copySynonyms:G,copyRules:B,moveIndex:ot,listIndices:nt,getLogs:Y,listClusters:rt,multipleSearchForFacetValues:ct,getApiKey:Lt,addApiKey:H,listApiKeys:et,updateApiKey:gt,deleteApiKey:V,restoreApiKey:lt,assignUserID:M,assignUserIDs:K,getUserID:$,searchUserIDs:mt,listUserIDs:at,getTopUserIDs:Z,removeUserID:ft,hasPendingMappings:tt,clearDictionaryEntries:W,deleteDictionaryEntries:_,getDictionarySettings:X,getAppTask:Vt,replaceDictionaryEntries:dt,saveDictionaryEntries:pt,searchDictionaryEntries:ht,setDictionarySettings:yt,waitAppTask:Xt,customRequest:L,initIndex:function(e){return function(t){return _t(e)(t,{methods:{batch:bt,delete:Dt,findAnswers:Nt,getObject:Rt,getObjects:Ct,saveObject:Kt,saveObjects:te,search:ne,searchForFacetValues:ae,waitTask:ue,setSettings:Qt,getSettings:Zt,partialUpdateObject:Jt,partialUpdateObjects:$t,deleteObject:qt,deleteObjects:Yt,deleteBy:jt,clearObjects:Ot,browseObjects:vt,getObjectPosition:At,findObject:Et,exists:Tt,saveSynonym:Bt,saveSynonyms:re,getSynonym:zt,searchSynonyms:ie,browseSynonyms:wt,deleteSynonym:kt,clearSynonyms:xt,replaceAllObjects:Ft,replaceAllSynonyms:Mt,searchRules:oe,getRule:Ut,deleteRule:St,saveRule:Wt,saveRules:ee,replaceAllRules:Ht,browseRules:Pt,clearRules:It}})}},initAnalytics:function(){return function(t){return e=g(g(g({},c),t),{},{methods:{addABTest:R,getABTest:C,getABTests:U,stopABTest:z,deleteABTest:A}}),r=e.region||"us",t=m(P.WithinHeaders,e.appId,e.apiKey),t=k(g(g({hosts:[{url:"analytics.".concat(r,".algolia.com")}]},e),{},{headers:g(g(g({},t.headers()),{"content-type":"application/json"}),e.headers),queryParameters:g(g({},t.queryParameters()),e.queryParameters)})),y({appId:e.appId,transporter:t},e.methods);var e,r}},initPersonalization:n,initRecommendation:function(){return function(t){return f.logger.info("The `initRecommendation` method is deprecated. Use `initPersonalization` instead."),n()(t)}}}}),t=e.appId,r=m(void 0!==e.authMode?e.authMode:P.WithinHeaders,t,e.apiKey),y({transporter:s=k(g(g({hosts:[{url:"".concat(t,"-dsn.algolia.net"),accept:O.Read},{url:"".concat(t,".algolia.net"),accept:O.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){s.userAgent.add({segment:t,version:e})},clearCache:function(){return Promise.all([s.requestsCache.clear(),s.responsesCache.clear()]).then(function(){})}},e.methods)}return t.version="4.11.0",t}); |