mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2025-02-19 05:10:53 +01:00
1 line
33 KiB
JavaScript
1 line
33 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).algoliasearch=t()}(this,function(){"use strict";function t(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function g(n){for(var e=1;e<arguments.length;e++){var a=null!=arguments[e]?arguments[e]:{};e%2?t(Object(a),!0).forEach(function(e){var t,r;t=n,r=a[e=e],e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(a)):t(Object(a)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(a,e))})}return n}function d(e,t){if(null==e)return{};var r,n=function(e,t){if(null==e)return{};for(var r,n={},a=Object.keys(e),o=0;o<a.length;o++)r=a[o],0<=t.indexOf(r)||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols)for(var a=Object.getOwnPropertySymbols(e),o=0;o<a.length;o++)r=a[o],0<=t.indexOf(r)||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r]);return n}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var r=[],n=!0,a=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){a=!0,o=e}finally{try{n||null==u.return||u.return()}finally{if(a)throw o}}return r}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function b(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function J(a){function o(){return JSON.parse(u().getItem(n)||"{}")}function i(e){u().setItem(n,JSON.stringify(e))}var e,n="algoliasearch-client-js-".concat(a.key),u=function(){return e=void 0===e?a.localStorage||window.localStorage:e};return{get:function(t,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,e=o(),e=Object.fromEntries(Object.entries(e).filter(function(e){return void 0!==l(e,2)[1].timestamp})),i(e),r&&(e=Object.fromEntries(Object.entries(e).filter(function(e){var e=l(e,2)[1],t=(new Date).getTime();return!(e.timestamp+r<t)})),i(e));var r,e=JSON.stringify(t);return o()[e]}).then(function(e){return Promise.all([e?e.value:r(),void 0!==e])}).then(function(e){var e=l(e,2),t=e[0],e=e[1];return Promise.all([t,e||n.miss(t)])}).then(function(e){return l(e,1)[0]})},set:function(t,r){return Promise.resolve().then(function(){var e=o();return e[JSON.stringify(t)]={timestamp:(new Date).getTime(),value:r},u().setItem(n,JSON.stringify(e)),r})},delete:function(t){return Promise.resolve().then(function(){var e=o();delete e[JSON.stringify(t)],u().setItem(n,JSON.stringify(e))})},clear:function(){return Promise.resolve().then(function(){u().removeItem(n)})}}}function s(e){var o=0<arguments.length&&void 0!==e?e:{serializable:!0},i={};return{get:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}},e=JSON.stringify(e);if(e in i)return Promise.resolve(o.serializable?JSON.parse(i[e]):i[e]);var n=t(),a=r&&r.miss||function(){return Promise.resolve()};return n.then(function(e){return a(e)}).then(function(){return n})},set:function(e,t){return i[JSON.stringify(e)]=o.serializable?JSON.stringify(t):t,Promise.resolve(t)},delete:function(e){return delete i[JSON.stringify(e)],Promise.resolve()},clear:function(){return i={},Promise.resolve()}}}function c(e,t,r){var n={"x-algolia-api-key":r,"x-algolia-application-id":t};return{headers:function(){return e===m.WithinHeaders?n:{}},queryParameters:function(){return e===m.WithinQueryParameters?n:{}}}}function u(r){var n=0;return r(function t(){return n++,new Promise(function(e){setTimeout(function(){e(r(t))},Math.min(100*n,1e3))})})}function p(e,t){var r=1<arguments.length&&void 0!==t?t:function(e,t){return Promise.resolve()};return Object.assign(e,{wait:function(t){return p(e.then(function(e){return Promise.all([r(e,t),e])}).then(function(e){return e[1]}))}})}function f(t,r){return r&&Object.keys(r).forEach(function(e){t[e]=r[e](t)}),t}function h(e){for(var t=arguments.length,r=new Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var a=0;return e.replace(/%s/g,function(){return encodeURIComponent(r[a++])})}var m={WithinQueryParameters:0,WithinHeaders:1};function y(e,t){var r=e||{},n=r.data||{};return Object.keys(r).forEach(function(e){-1===["timeout","headers","queryParameters","data","cacheable"].indexOf(e)&&(n[e]=r[e])}),{data:0<Object.entries(n).length?n:void 0,timeout:r.timeout||t,headers:r.headers||{},queryParameters:r.queryParameters||{},cacheable:r.cacheable}}var v={Read:1,Write:2,Any:3},F=2,P=3;function O(e,t){t=1<arguments.length&&void 0!==t?t:1;return g(g({},e),{},{status:t,lastUpdate:Date.now()})}function w(e){return"string"==typeof e?{protocol:"https",url:e,accept:v.Any}:{protocol:e.protocol||"https",url:e.url,accept:e.accept||v.Any}}var a="DELETE",i="GET",I="POST",x="PUT";function j(u,e,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, please reach out to the Algolia Support team: https://alg.li/support .",transporterStackTrace:M(d)};function o(e){return e={request:t,response:e,host:a,triesLeft:r.length},d.push(e),e}var t={data:l,headers:p,method:h,url:function(e,t,r){r=H(r),e="".concat(e.protocol,"://").concat(e.url,"/").concat("/"===t.charAt(0)?t.substr(1):t);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(t){try{return JSON.parse(t.content)}catch(e){throw{name:"DeserializationError",message:e.message,response:t}}},onRetry:function(e){var t=o(e);return e.isTimedOut&&y++,Promise.all([u.logger.info("Retryable failure",B(t)),u.hostsCache.set(a,O(a,e.isTimedOut?P:F))]).then(function(){return f(r,n)})},onFail:function(e){throw o(e),function(e,t){var r=e.content,n=e.status,a=r;try{a=JSON.parse(r).message}catch(e){}return{name:"ApiError",message:a,status:n,transporterStackTrace:t}}(e,M(d))}};return u.requester.send(t).then(function(e){return t=i,a=(r=e=e).status,r.isTimedOut||(n=r.isTimedOut,r=r.status,!n&&0==~~r)||2!=~~(a/100)&&4!=~~(a/100)?t.onRetry(e):2==~~(e.status/100)?t.onSuccess(e):t.onFail(e);var t,r,n,a})}var r,n,t,a,d=[],l=function(e,t){if(e.method!==i&&(void 0!==e.data||void 0!==t.data))return e=Array.isArray(e.data)?e.data:g(g({},e.data),t.data),JSON.stringify(e)}(s,c),p=(o=c,r=g(g({},u.headers),o.headers),n={},Object.keys(r).forEach(function(e){var t=r[e];n[e.toLowerCase()]=t}),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 t=u.hostsCache,a=e,Promise.all(a.map(function(e){return t.get(e,function(){return Promise.resolve(O(e))})})).then(function(e){var t=e.filter(function(e){return 1===(e=e).status||12e4<Date.now()-e.lastUpdate}),r=e.filter(function(e){return(e=e).status===P&&Date.now()-e.lastUpdate<=12e4}),e=[].concat(b(t),b(r));return{getTimeout:function(e,t){return(0===r.length&&0===e?1:r.length+3+e)*t},statelessHosts:0<e.length?e.map(w):a}}).then(function(e){return f(b(e.statelessHosts).reverse(),e.getTimeout)})}function D(e){var t=e.hostsCache,r=e.logger,n=e.requester,a=e.requestsCache,o=e.responsesCache,i=e.timeouts,u=e.userAgent,s=e.hosts,c=e.queryParameters,f={hostsCache:t,logger:r,requester:n,requestsCache:a,responsesCache:o,timeouts:i,userAgent:u,headers:e.headers,queryParameters:c,hosts:s.map(w),read:function(e,t){function r(){return j(f,f.hosts.filter(function(e){return 0!=(e.accept&v.Read)}),e,n)}var n=y(t,f.timeouts.read);if(!0!==(void 0!==n.cacheable?n:e).cacheable)return r();var a={request:e,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(e){return Promise.all([f.requestsCache.delete(a),e])},function(e){return Promise.all([f.requestsCache.delete(a),Promise.reject(e)])}).then(function(e){e=l(e,2);return e[0],e[1]})})},{miss:function(e){return f.responsesCache.set(a,e)}})},write:function(e,t){return j(f,f.hosts.filter(function(e){return 0!=(e.accept&v.Write)}),e,y(t,f.timeouts.write))}};return f}function H(r){return Object.keys(r).map(function(e){return h("%s=%s",e,(t=r[e],"[object Object]"===Object.prototype.toString.call(t)||"[object Array]"===Object.prototype.toString.call(t)?JSON.stringify(r[e]):r[e]));var t}).join("&")}function M(e){return e.map(B)}function B(e){var t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return g(g({},e),{},{request:g(g({},e.request),{},{headers:g(g({},e.request.headers),t)})})}function K(r){return function(e,t){return r.transporter.write({method:I,path:"2/abtests",data:e},t)}}function W(r){return function(e,t){return r.transporter.write({method:a,path:h("2/abtests/%s",e)},t)}}function L(r){return function(e,t){return r.transporter.read({method:i,path:h("2/abtests/%s",e)},t)}}function Q(t){return function(e){return t.transporter.read({method:i,path:"2/abtests"},e)}}function G(r){return function(e,t){return r.transporter.write({method:I,path:h("2/abtests/%s/stop",e)},t)}}function V(t){return function(e){return t.transporter.read({method:i,path:"1/strategies/personalization"},e)}}function _(r){return function(e,t){return r.transporter.write({method:I,path:"1/strategies/personalization",data:e},t)}}function n(n){return function t(r){return n.request(r).then(function(e){if(void 0!==n.batch&&n.batch(e.hits),!n.shouldStop(e))return e.cursor?t({cursor:e.cursor}):t({page:(r.page||0)+1})})}({})}function X(n){return function(e,t){var t=t||{},r=t.queryParameters,t=d(t,["queryParameters"]),e=g({acl:e},void 0!==r?{queryParameters:r}:{});return p(n.transporter.write({method:I,path:"1/keys",data:e},t),function(e,r){return u(function(t){return S(n)(e.key,r).catch(function(e){if(404!==e.status)throw e;return t()})})})}}function Y(n){return function(e,t,r){r=y(r);return r.queryParameters["X-Algolia-User-ID"]=e,n.transporter.write({method:I,path:"1/clusters/mapping",data:{cluster:t}},r)}}function Z(n){return function(e,t,r){return n.transporter.write({method:I,path:"1/clusters/mapping/batch",data:{users:e,cluster:t}},r)}}function $(r){return function(e,t){return p(r.transporter.write({method:I,path:h("/1/dictionaries/%s/batch",e),data:{clearExistingDictionaryEntries:!0,requests:{action:"addEntry",body:[]}}},t),function(e,t){return T(r)(e.taskID,t)})}}function ee(n){return function(e,t,r){return q(n)(e,t,g(g({},r),{},{scope:[o.Rules]}))}}function te(n){return function(e,t,r){return q(n)(e,t,g(g({},r),{},{scope:[o.Settings]}))}}function re(n){return function(e,t,r){return q(n)(e,t,g(g({},r),{},{scope:[o.Synonyms]}))}}function ne(r){return function(e,t){return e.method===i?r.transporter.read(e,t):r.transporter.write(e,t)}}function ae(n){return function(r,e){return p(n.transporter.write({method:a,path:h("1/keys/%s",r)},e),function(e,t){return u(function(e){return S(n)(r,t).then(e).catch(function(e){if(404!==e.status)throw e})})})}}function oe(n){return function(e,t,r){t=t.map(function(e){return{action:"deleteEntry",body:{objectID:e}}});return p(n.transporter.write({method:I,path:h("/1/dictionaries/%s/batch",e),data:{clearExistingDictionaryEntries:!1,requests:t}},r),function(e,t){return T(n)(e.taskID,t)})}}function ie(t){return function(e){return t.transporter.read({method:i,path:"/1/dictionaries/*/settings"},e)}}function ue(t){return function(e){return t.transporter.read({method:i,path:"1/logs"},e)}}function se(t){return function(e){return t.transporter.read({method:i,path:"1/clusters/mapping/top"},e)}}function ce(r){return function(e,t){return r.transporter.read({method:i,path:h("1/clusters/mapping/%s",e)},t)}}function fe(r){return function(e){var e=e||{},t=e.retrieveMappings,e=d(e,["retrieveMappings"]);return!0===t&&(e.getClusters=!0),r.transporter.read({method:i,path:"1/clusters/mapping/pending"},e)}}function de(t){return function(e){return t.transporter.read({method:i,path:"1/keys"},e)}}function le(t){return function(e){return t.transporter.read({method:i,path:"1/clusters"},e)}}function pe(t){return function(e){return t.transporter.read({method:i,path:"1/indexes"},e)}}function he(t){return function(e){return t.transporter.read({method:i,path:"1/clusters/mapping"},e)}}function me(n){return function(r,e,t){return p(n.transporter.write({method:I,path:h("1/indexes/%s/operation",r),data:{operation:"move",destination:e}},t),function(e,t){return k(n)(r,{methods:{waitTask:C}}).waitTask(e.taskID,t)})}}function ye(n){return function(e,t){return p(n.transporter.write({method:I,path:"1/indexes/*/batch",data:{requests:e}},t),function(t,r){return Promise.all(Object.keys(t.taskID).map(function(e){return k(n)(e,{methods:{waitTask:C}}).waitTask(t.taskID[e],r)}))})}}function ge(r){return function(e,t){return r.transporter.read({method:I,path:"1/indexes/*/objects",data:{requests:e}},t)}}function be(r){return function(e,t){e=e.map(function(e){return g(g({},e),{},{params:H(e.params||{})})});return r.transporter.read({method:I,path:"1/indexes/*/queries",data:{requests:e},cacheable:!0},t)}}function ve(o){return function(e,a){return Promise.all(e.map(function(e){var t=e.params,r=t.facetName,n=t.facetQuery,t=d(t,["facetName","facetQuery"]);return k(o)(e.indexName,{methods:{searchForFacetValues:pt}}).searchForFacetValues(r,n,g(g({},a),t))}))}}function Pe(r){return function(e,t){t=y(t);return t.queryParameters["X-Algolia-User-ID"]=e,r.transporter.write({method:a,path:"1/clusters/mapping"},t)}}function Oe(n){return function(e,t,r){t=t.map(function(e){return{action:"addEntry",body:e}});return p(n.transporter.write({method:I,path:h("/1/dictionaries/%s/batch",e),data:{clearExistingDictionaryEntries:!0,requests:t}},r),function(e,t){return T(n)(e.taskID,t)})}}function we(a){return function(n,e){return p(a.transporter.write({method:I,path:h("1/keys/%s/restore",n)},e),function(e,r){return u(function(t){return S(a)(n,r).catch(function(e){if(404!==e.status)throw e;return t()})})})}}function Ie(n){return function(e,t,r){t=t.map(function(e){return{action:"addEntry",body:e}});return p(n.transporter.write({method:I,path:h("/1/dictionaries/%s/batch",e),data:{clearExistingDictionaryEntries:!1,requests:t}},r),function(e,t){return T(n)(e.taskID,t)})}}function xe(n){return function(e,t,r){return n.transporter.read({method:I,path:h("/1/dictionaries/%s/search",e),data:{query:t},cacheable:!0},r)}}function je(r){return function(e,t){return r.transporter.read({method:I,path:"1/clusters/mapping/search",data:{query:e}},t)}}function De(r){return function(e,t){return p(r.transporter.write({method:x,path:"/1/dictionaries/*/settings",data:e},t),function(e,t){return T(r)(e.taskID,t)})}}function qe(i){return function(n,e){var a=Object.assign({},e),e=e||{},t=e.queryParameters,e=d(e,["queryParameters"]),t=t?{queryParameters:t}:{},o=["acl","indexes","referers","restrictSources","queryParameters","description","maxQueriesPerIPPerHour","maxHitsPerQuery"];return p(i.transporter.write({method:x,path:h("1/keys/%s",n),data:t},e),function(e,t){return u(function(r){return S(i)(n,t).then(function(e){return t=e,Object.keys(a).filter(function(e){return-1!==o.indexOf(e)}).every(function(r){var e;return Array.isArray(t[r])&&Array.isArray(a[r])?(e=t[r]).length===a[r].length&&e.every(function(e,t){return e===a[r][t]}):t[r]===a[r]})?Promise.resolve():r();var t})})})}}function Se(r){return function(e,t){return p(r.transporter.write({method:I,path:h("1/indexes/%s/batch",r.indexName),data:{requests:e}},t),function(e,t){return C(r)(e.taskID,t)})}}function ke(r){return function(t){return n(g(g({shouldStop:function(e){return void 0===e.cursor}},t),{},{request:function(e){return r.transporter.read({method:I,path:h("1/indexes/%s/browse",r.indexName),data:e},t)}}))}}function Te(r){return function(e){var t=g({hitsPerPage:1e3},e);return n(g(g({shouldStop:function(e){return e.hits.length<t.hitsPerPage}},t),{},{request:function(e){return ht(r)("",g(g({},t),e)).then(function(e){return g(g({},e),{},{hits:e.hits.map(function(e){return delete e._highlightResult,e})})})}}))}}function Ne(r){return function(e){var t=g({hitsPerPage:1e3},e);return n(g(g({shouldStop:function(e){return e.hits.length<t.hitsPerPage}},t),{},{request:function(e){return mt(r)("",g(g({},t),e)).then(function(e){return g(g({},e),{},{hits:e.hits.map(function(e){return delete e._highlightResult,e})})})}}))}}function Re(r){return function(e){return p(r.transporter.write({method:I,path:h("1/indexes/%s/clear",r.indexName)},e),function(e,t){return C(r)(e.taskID,t)})}}function Ee(r){return function(e){var e=e||{},t=e.forwardToReplicas,e=y(d(e,["forwardToReplicas"]));return t&&(e.queryParameters.forwardToReplicas=1),p(r.transporter.write({method:I,path:h("1/indexes/%s/rules/clear",r.indexName)},e),function(e,t){return C(r)(e.taskID,t)})}}function Ae(r){return function(e){var e=e||{},t=e.forwardToReplicas,e=y(d(e,["forwardToReplicas"]));return t&&(e.queryParameters.forwardToReplicas=1),p(r.transporter.write({method:I,path:h("1/indexes/%s/synonyms/clear",r.indexName)},e),function(e,t){return C(r)(e.taskID,t)})}}function Ce(r){return function(e,t){return p(r.transporter.write({method:I,path:h("1/indexes/%s/deleteByQuery",r.indexName),data:e},t),function(e,t){return C(r)(e.taskID,t)})}}function Ue(r){return function(e){return p(r.transporter.write({method:a,path:h("1/indexes/%s",r.indexName)},e),function(e,t){return C(r)(e.taskID,t)})}}function ze(r){return function(e,t){return p(ct(r)([e],t).then(function(e){return{taskID:e.taskIDs[0]}}),function(e,t){return C(r)(e.taskID,t)})}}function Je(n){return function(e,t){var t=t||{},r=t.forwardToReplicas,t=y(d(t,["forwardToReplicas"]));return r&&(t.queryParameters.forwardToReplicas=1),p(n.transporter.write({method:a,path:h("1/indexes/%s/rules/%s",n.indexName,e)},t),function(e,t){return C(n)(e.taskID,t)})}}function Fe(n){return function(e,t){var t=t||{},r=t.forwardToReplicas,t=y(d(t,["forwardToReplicas"]));return r&&(t.queryParameters.forwardToReplicas=1),p(n.transporter.write({method:a,path:h("1/indexes/%s/synonyms/%s",n.indexName,e)},t),function(e,t){return C(n)(e.taskID,t)})}}function He(t){return function(e){return ft(t)(e).then(function(){return!0}).catch(function(e){if(404!==e.status)throw e;return!1})}}function Me(n){return function(e,t,r){return n.transporter.read({method:I,path:h("1/answers/%s/prediction",n.indexName),data:{query:e,queryLanguages:t},cacheable:!0},r)}}function Be(n){return function(i,e){var e=e||{},t=e.query,u=e.paginate,r=d(e,["query","paginate"]),s=0;return function o(){return lt(n)(t||"",g(g({},r),{},{page:s})).then(function(e){for(var t=0,r=Object.entries(e.hits);t<r.length;t++){var n=l(r[t],2),a=n[0],n=n[1];if(i(n))return{object:n,position:parseInt(a,10),page:s}}if(s++,!1===u||s>=e.nbPages)throw{name:"ObjectNotFoundError",message:"Object not found."};return o()})}()}}function Ke(r){return function(e,t){return r.transporter.read({method:i,path:h("1/indexes/%s/%s",r.indexName,e)},t)}}function We(){return function(e,t){for(var r=0,n=Object.entries(e.hits);r<n.length;r++){var a=l(n[r],2),o=a[0];if(a[1].objectID===t)return parseInt(o,10)}return-1}}function Le(n){return function(e,t){var t=t||{},r=t.attributesToRetrieve,t=d(t,["attributesToRetrieve"]),e=e.map(function(e){return g({indexName:n.indexName,objectID:e},r?{attributesToRetrieve:r}:{})});return n.transporter.read({method:I,path:"1/indexes/*/objects",data:{requests:e}},t)}}function Qe(r){return function(e,t){return r.transporter.read({method:i,path:h("1/indexes/%s/rules/%s",r.indexName,e)},t)}}function Ge(r){return function(e,t){return r.transporter.read({method:i,path:h("1/indexes/%s/synonyms/%s",r.indexName,e)},t)}}function Ve(r){return function(e,t){return p(dt(r)([e],t).then(function(e){return{objectID:e.objectIDs[0],taskID:e.taskIDs[0]}}),function(e,t){return C(r)(e.taskID,t)})}}function _e(f){return function(t,e){function r(e,t,r,n){return p(f.transporter.write({method:I,path:h("1/indexes/%s/operation",e),data:{operation:r,destination:t}},n),function(e,t){return C(f)(e.taskID,t)})}var e=e||{},n=e.safe,a=e.autoGenerateObjectIDIfNotExist,o=e.batchSize,i=d(e,["safe","autoGenerateObjectIDIfNotExist","batchSize"]),e=Math.random().toString(36).substring(7),u="".concat(f.indexName,"_tmp_").concat(e),s=R({appId:f.appId,transporter:f.transporter,indexName:u}),c=[],e=r(f.indexName,u,"copy",g(g({},i),{},{scope:["settings","synonyms","rules"]}));return c.push(e),p((n?e.wait(i):e).then(function(){var e=s(t,g(g({},i),{},{autoGenerateObjectIDIfNotExist:a,batchSize:o}));return c.push(e),n?e.wait(i):e}).then(function(){var e=r(u,f.indexName,"move",i);return c.push(e),n?e.wait(i):e}).then(function(){return Promise.all(c)}).then(function(e){var e=l(e,3),t=e[0],r=e[1],e=e[2];return{objectIDs:r.objectIDs,taskIDs:[t.taskID].concat(b(r.taskIDs),[e.taskID])}}),function(e,t){return Promise.all(c.map(function(e){return e.wait(t)}))})}}function Xe(r){return function(e,t){return E(r)(e,g(g({},t),{},{clearExistingRules:!0}))}}function Ye(r){return function(e,t){return A(r)(e,g(g({},t),{},{clearExistingSynonyms:!0}))}}function Ze(r){return function(e,t){return p(R(r)([e],t).then(function(e){return{objectID:e.objectIDs[0],taskID:e.taskIDs[0]}}),function(e,t){return C(r)(e.taskID,t)})}}function $e(r){return function(e,t){return E(r)([e],t)}}function et(r){return function(e,t){return A(r)([e],t)}}function tt(n){return function(e,t){var t=t||{},r=t.forwardToReplicas,t=y(d(t,["forwardToReplicas"]));return r&&(t.queryParameters.forwardToReplicas=1),p(n.transporter.write({method:x,path:h("1/indexes/%s/settings",n.indexName),data:e},t),function(e,t){return C(n)(e.taskID,t)})}}function rt(r){return function(e,t){return z(r)(e.map(function(e){return g(g({},e),{},{fallbackParameters:{},model:"bought-together"})}),t)}}function nt(r){return function(e,t){return z(r)(e.map(function(e){return g(g({},e),{},{model:"related-products"})}),t)}}function at(r){return function(e,t){e=e.map(function(e){return g(g({},e),{},{model:"trending-facets",threshold:e.threshold||0})});return r.transporter.read({method:I,path:"1/indexes/*/recommendations",data:{requests:e},cacheable:!0},t)}}function ot(r){return function(e,t){e=e.map(function(e){return g(g({},e),{},{model:"trending-items",threshold:e.threshold||0})});return r.transporter.read({method:I,path:"1/indexes/*/recommendations",data:{requests:e},cacheable:!0},t)}}function it(r){return function(e,t){return z(r)(e.map(function(e){return g(g({},e),{},{model:"looking-similar"})}),t)}}function ut(r){return function(e,t){e=e.map(function(e){return g(g({},e),{},{model:"recommended-for-you",threshold:e.threshold||0})});return r.transporter.read({method:I,path:"1/indexes/*/recommendations",data:{requests:e},cacheable:!0},t)}}var q=function(n){return function(r,e,t){return p(n.transporter.write({method:I,path:h("1/indexes/%s/operation",r),data:{operation:"copy",destination:e}},t),function(e,t){return k(n)(r,{methods:{waitTask:C}}).waitTask(e.taskID,t)})}},S=function(r){return function(e,t){return r.transporter.read({method:i,path:h("1/keys/%s",e)},t)}},st=function(r){return function(e,t){return r.transporter.read({method:i,path:h("1/task/%s",e.toString())},t)}},k=function(t){return function(e){return f({transporter:t.transporter,appId:t.appId,indexName:e},(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).methods)}},T=function(n){return function(e,r){return u(function(t){return st(n)(e,r).then(function(e){return"published"!==e.status?t():void 0})})}},N=function(s){return function(n,a,e){var e=e||{},o=e.batchSize,i=d(e,["batchSize"]),u={taskIDs:[],objectIDs:[]};return p(function t(){for(var e=[],r=0<arguments.length&&void 0!==arguments[0]?arguments[0]:0;r<n.length&&(e.push(n[r]),e.length!==(o||1e3));r++);return 0===e.length?Promise.resolve(u):Se(s)(e.map(function(e){return{action:a,body:e}}),i).then(function(e){return u.objectIDs=u.objectIDs.concat(e.objectIDs),u.taskIDs.push(e.taskID),t(++r)})}(),function(e,t){return Promise.all(e.taskIDs.map(function(e){return C(s)(e,t)}))})}},ct=function(r){return function(e,t){e=e.map(function(e){return{objectID:e}});return N(r)(e,U.DeleteObject,t)}},ft=function(t){return function(e){return t.transporter.read({method:i,path:h("1/indexes/%s/settings",t.indexName),data:{getVersion:2}},e)}},dt=function(n){return function(e,t){var t=t||{},r=t.createIfNotExists,t=d(t,["createIfNotExists"]),r=r?U.PartialUpdateObject:U.PartialUpdateObjectNoCreate;return N(n)(e,r,t)}},R=function(s){return function(e,t){var t=t||{},r=t.autoGenerateObjectIDIfNotExist,t=d(t,["autoGenerateObjectIDIfNotExist"]),r=r?U.AddObject:U.UpdateObject;if(r===U.UpdateObject){var n=!0,a=!1,o=void 0;try{for(var i,u=e[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(e){a=!0,o=e}finally{try{n||null==u.return||u.return()}finally{if(a)throw o}}}return N(s)(e,r,t)}},E=function(a){return function(e,t){var t=t||{},r=t.forwardToReplicas,n=t.clearExistingRules,t=y(d(t,["forwardToReplicas","clearExistingRules"]));return r&&(t.queryParameters.forwardToReplicas=1),n&&(t.queryParameters.clearExistingRules=1),p(a.transporter.write({method:I,path:h("1/indexes/%s/rules/batch",a.indexName),data:e},t),function(e,t){return C(a)(e.taskID,t)})}},A=function(o){return function(e,t){var t=t||{},r=t.forwardToReplicas,n=t.clearExistingSynonyms,a=t.replaceExistingSynonyms,t=y(d(t,["forwardToReplicas","clearExistingSynonyms","replaceExistingSynonyms"]));return r&&(t.queryParameters.forwardToReplicas=1),(a||n)&&(t.queryParameters.replaceExistingSynonyms=1),p(o.transporter.write({method:I,path:h("1/indexes/%s/synonyms/batch",o.indexName),data:e},t),function(e,t){return C(o)(e.taskID,t)})}},lt=function(r){return function(e,t){return r.transporter.read({method:I,path:h("1/indexes/%s/query",r.indexName),data:{query:e},cacheable:!0},t)}},pt=function(n){return function(e,t,r){return n.transporter.read({method:I,path:h("1/indexes/%s/facets/%s/query",n.indexName,e),data:{facetQuery:t},cacheable:!0},r)}},ht=function(r){return function(e,t){return r.transporter.read({method:I,path:h("1/indexes/%s/rules/search",r.indexName),data:{query:e}},t)}},mt=function(r){return function(e,t){return r.transporter.read({method:I,path:h("1/indexes/%s/synonyms/search",r.indexName),data:{query:e}},t)}},C=function(a){return function(e,n){return u(function(t){return r=a,function(e,t){return r.transporter.read({method:i,path:h("1/indexes/%s/task/%s",r.indexName,e.toString())},t)}(e,n).then(function(e){return"published"!==e.status?t():void 0});var r})}},U={AddObject:"addObject",UpdateObject:"updateObject",PartialUpdateObject:"partialUpdateObject",PartialUpdateObjectNoCreate:"partialUpdateObjectNoCreate",DeleteObject:"deleteObject",DeleteIndex:"delete",ClearIndex:"clear"},o={Settings:"settings",Synonyms:"synonyms",Rules:"rules"},z=function(r){return function(e,t){e=e.map(function(e){return g(g({},e),{},{threshold:e.threshold||0})});return r.transporter.read({method:I,path:"1/indexes/*/recommendations",data:{requests:e},cacheable:!0},t)}};function e(e,t,r){function n(){return function(e){return e=g(g(g({},i),e),{},{methods:{getPersonalizationStrategy:V,setPersonalizationStrategy:_}}),t=e.region||"us",r=c(m.WithinHeaders,e.appId,e.apiKey),t=D(g(g({hosts:[{url:"personalization.".concat(t,".algolia.com")}]},e),{},{headers:g(g(g({},r.headers()),{"content-type":"application/json"}),e.headers),queryParameters:g(g({},r.queryParameters()),e.queryParameters)})),f({appId:e.appId,transporter:t},e.methods);var t,r}}var a,o,i={appId:e,apiKey:t,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(e){return n.setRequestHeader(e,o.headers[e])});function e(e,t){return setTimeout(function(){n.abort(),r({status:0,content:t,isTimedOut:!0})},1e3*e)}var t,a=e(o.connectTimeout,"Connection timeout");n.onreadystatechange=function(){n.readyState>n.OPENED&&void 0===t&&(clearTimeout(a),t=e(o.responseTimeout,"Socket timeout"))},n.onerror=function(){0===n.status&&(clearTimeout(a),clearTimeout(t),r({content:n.responseText||"Network request failed",status:n.status,isTimedOut:!1}))},n.onload=function(){clearTimeout(a),clearTimeout(t),r({content:n.responseText,status:n.status,isTimedOut:!1})},n.send(o.data)})}},logger:{debug:function(e,t){return Promise.resolve()},info:function(e,t){return Promise.resolve()},error:function(e,t){return console.error(e,t),Promise.resolve()}},responsesCache:s(),requestsCache:s({serializable:!1}),hostsCache:function n(e){var a=b(e.caches),o=a.shift();return void 0===o?{get:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return t().then(function(e){return Promise.all([e,r.miss(e)])}).then(function(e){return l(e,1)[0]})},set:function(e,t){return Promise.resolve(t)},delete:function(e){return Promise.resolve()},clear:function(){return Promise.resolve()}}:{get:function(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{miss:function(){return Promise.resolve()}};return o.get(e,t,r).catch(function(){return n({caches:a}).get(e,t,r)})},set:function(e,t){return o.set(e,t).catch(function(){return n({caches:a}).set(e,t)})},delete:function(e){return o.delete(e).catch(function(){return n({caches:a}).delete(e)})},clear:function(){return o.clear().catch(function(){return n({caches:a}).clear()})}}}({caches:[J({key:"".concat("4.24.0","-").concat(e)}),s()]}),userAgent:(a={value:"Algolia for JavaScript (".concat("4.24.0",")"),add:function(e){e="; ".concat(e.segment).concat(void 0!==e.version?" (".concat(e.version,")"):"");return-1===a.value.indexOf(e)&&(a.value="".concat(a.value).concat(e)),a}}).add({segment:"Browser"})},u=g(g({},i),r);return t=g(g({},u),{},{methods:{search:be,searchForFacetValues:ve,multipleBatch:ye,multipleGetObjects:ge,multipleQueries:be,copyIndex:q,copySettings:te,copySynonyms:re,copyRules:ee,moveIndex:me,listIndices:pe,getLogs:ue,listClusters:le,multipleSearchForFacetValues:ve,getApiKey:S,addApiKey:X,listApiKeys:de,updateApiKey:qe,deleteApiKey:ae,restoreApiKey:we,assignUserID:Y,assignUserIDs:Z,getUserID:ce,searchUserIDs:je,listUserIDs:he,getTopUserIDs:se,removeUserID:Pe,hasPendingMappings:fe,clearDictionaryEntries:$,deleteDictionaryEntries:oe,getDictionarySettings:ie,getAppTask:st,replaceDictionaryEntries:Oe,saveDictionaryEntries:Ie,searchDictionaryEntries:xe,setDictionarySettings:De,waitAppTask:T,customRequest:ne,initIndex:function(t){return function(e){return k(t)(e,{methods:{batch:Se,delete:Ue,findAnswers:Me,getObject:Ke,getObjects:Le,saveObject:Ze,saveObjects:R,search:lt,searchForFacetValues:pt,waitTask:C,setSettings:tt,getSettings:ft,partialUpdateObject:Ve,partialUpdateObjects:dt,deleteObject:ze,deleteObjects:ct,deleteBy:Ce,clearObjects:Re,browseObjects:ke,getObjectPosition:We,findObject:Be,exists:He,saveSynonym:et,saveSynonyms:A,getSynonym:Ge,searchSynonyms:mt,browseSynonyms:Ne,deleteSynonym:Fe,clearSynonyms:Ae,replaceAllObjects:_e,replaceAllSynonyms:Ye,searchRules:ht,getRule:Qe,deleteRule:Je,saveRule:$e,saveRules:E,replaceAllRules:Xe,browseRules:Te,clearRules:Ee}})}},initAnalytics:function(){return function(e){return e=g(g(g({},i),e),{},{methods:{addABTest:K,getABTest:L,getABTests:Q,stopABTest:G,deleteABTest:W}}),t=e.region||"us",r=c(m.WithinHeaders,e.appId,e.apiKey),t=D(g(g({hosts:[{url:"analytics.".concat(t,".algolia.com")}]},e),{},{headers:g(g(g({},r.headers()),{"content-type":"application/json"}),e.headers),queryParameters:g(g({},r.queryParameters()),e.queryParameters)})),f({appId:e.appId,transporter:t},e.methods);var t,r}},initPersonalization:n,initRecommendation:function(){return function(e){return u.logger.info("The `initRecommendation` method is deprecated. Use `initPersonalization` instead."),n()(e)}},getRecommendations:z,getFrequentlyBoughtTogether:rt,getLookingSimilar:it,getRecommendedForYou:ut,getRelatedProducts:nt,getTrendingFacets:at,getTrendingItems:ot}}),e=t.appId,r=c(void 0!==t.authMode?t.authMode:m.WithinHeaders,e,t.apiKey),f({transporter:o=D(g(g({hosts:[{url:"".concat(e,"-dsn.algolia.net"),accept:v.Read},{url:"".concat(e,".algolia.net"),accept:v.Write}].concat(function(e){for(var t=e.length-1;0<t;t--){var r=Math.floor(Math.random()*(t+1)),n=e[t];e[t]=e[r],e[r]=n}return e}([{url:"".concat(e,"-1.algolianet.com")},{url:"".concat(e,"-2.algolianet.com")},{url:"".concat(e,"-3.algolianet.com")}]))},t),{},{headers:g(g(g({},r.headers()),{"content-type":"application/x-www-form-urlencoded"}),t.headers),queryParameters:g(g({},r.queryParameters()),t.queryParameters)})),appId:e,addAlgoliaAgent:function(e,t){o.userAgent.add({segment:e,version:t})},clearCache:function(){return Promise.all([o.requestsCache.clear(),o.responsesCache.clear()]).then(function(){})}},t.methods)}return e.version="4.24.0",e}); |