algoliasearch
Version:
A fully-featured and blazing-fast JavaScript API client to interact with Algolia API.
11 lines (10 loc) • 95.7 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.algoliasearch = {}));
})(this, (function (exports) { 'use strict';
function A(c){let d,m=`algolia-client-js-${c.key}`;function p(){return d===void 0&&(d=c.localStorage||window.localStorage),d}function P(){return JSON.parse(p().getItem(m)||"{}")}function y(e){p().setItem(m,JSON.stringify(e));}function h(){return new Promise(e=>setTimeout(e,0))}function r(){let e=c.timeToLive?c.timeToLive*1e3:null,t=P(),s=new Date().getTime(),a=false;return {namespace:Object.fromEntries(Object.entries(t).filter(([,o])=>!o||o.timestamp===void 0||e&&o.timestamp+e<s?(a=true,false):true)),changed:a}}return {get(e,t,s={miss:()=>Promise.resolve()}){return h().then(()=>{let{namespace:a,changed:n}=r(),o=a[JSON.stringify(e)];return n&&y(a),o?o.value:t().then(u=>s.miss(u).then(()=>u))})},set(e,t){return h().then(()=>{let s=P();return s[JSON.stringify(e)]={timestamp:new Date().getTime(),value:t},p().setItem(m,JSON.stringify(s)),t})},delete(e){return h().then(()=>{let t=P();delete t[JSON.stringify(e)],p().setItem(m,JSON.stringify(t));})},clear(){return Promise.resolve().then(()=>{p().removeItem(m);})}}}function Ne(){return {get(c,d,m={miss:()=>Promise.resolve()}){return d().then(P=>Promise.all([P,m.miss(P)])).then(([P])=>P)},set(c,d){return Promise.resolve(d)},delete(c){return Promise.resolve()},clear(){return Promise.resolve()}}}function C(c){let d=[...c.caches],m=d.shift();return m===void 0?Ne():{get(p,P,y={miss:()=>Promise.resolve()}){return m.get(p,P,y).catch(()=>C({caches:d}).get(p,P,y))},set(p,P){return m.set(p,P).catch(()=>C({caches:d}).set(p,P))},delete(p){return m.delete(p).catch(()=>C({caches:d}).delete(p))},clear(){return m.clear().catch(()=>C({caches:d}).clear())}}}function R(c={serializable:true}){let d={};return {get(m,p,P={miss:()=>Promise.resolve()}){let y=JSON.stringify(m);if(y in d)return Promise.resolve(c.serializable?JSON.parse(d[y]):d[y]);let h=p();return h.then(r=>P.miss(r)).then(()=>h)},set(m,p){return d[JSON.stringify(m)]=c.serializable?JSON.stringify(p):p,Promise.resolve(p)},delete(m){return delete d[JSON.stringify(m)],Promise.resolve()},clear(){return d={},Promise.resolve()}}}var Q=800;function Be(c){let d={value:`Algolia for JavaScript (${c})`,add(m){let p=`; ${m.segment}${m.version!==void 0?` (${m.version})`:""}`;return d.value.indexOf(p)===-1&&(d.value=`${d.value}${p}`),d}};return d}function b(c,d,m="WithinHeaders"){let p={"x-algolia-api-key":d,"x-algolia-application-id":c};return {headers(){return m==="WithinHeaders"?p:{}},queryParameters(){return m==="WithinQueryParameters"?p:{}}}}function B({func:c,validate:d,aggregator:m,error:p,timeout:P=()=>0}){let y=h=>new Promise((r,e)=>{c(h).then(async t=>(m&&await m(t),await d(t)?r(t):p&&await p.validate(t)?e(new Error(await p.message(t))):setTimeout(()=>{y(t).then(r).catch(e);},await P()))).catch(t=>{e(t);});});return y()}function E({algoliaAgents:c,client:d,version:m}){let p=Be(m).add({segment:d,version:m});return c.forEach(P=>p.add(P)),p}function D(){return {debug(c,d){return Promise.resolve()},info(c,d){return Promise.resolve()},error(c,d){return Promise.resolve()}}}var Ge=10*1024*1024;async function*je(c){let d=c.getReader();try{for(;;){let{done:m,value:p}=await d.read();if(m)return;yield p;}}finally{d.releaseLock();}}function Fe(c){return Symbol.asyncIterator in c?c:je(c)}async function*Le(c){let d=new TextDecoder("utf-8"),m=[],p=0,P=false,y=true;for await(let r of Fe(c)){let e=d.decode(r,{stream:true}),t=0;for(P&&(P=false,e.length>0&&e[0]===`
`&&(t=1));t<e.length;){let s=e.indexOf("\r",t),a=e.indexOf(`
`,t);if(s===-1&&a===-1){let q=e.slice(t);if(m.push(q),p+=q.length,p>Ge)throw new Error("SSE line buffer exceeded 10MB");break}let n,o;s!==-1&&(a===-1||s<a)?(n=s,s+1<e.length?o=e[s+1]===`
`?2:1:(P=true,o=1)):(n=a,o=1);let u=e.slice(t,n);m.push(u);let l=m.length===1?m[0]:m.join("");m.length=0,p=0,y&&(l.startsWith("\uFEFF")&&(l=l.slice(1)),y=false),yield l,t=n+o;}}let h=d.decode();if(h&&m.push(h),m.length>0){let r=m.join("");y&&r.startsWith("\uFEFF")&&(r=r.slice(1)),yield r;}}var He=class{data=[];eventType="";lastEventId=null;retry=null;decode(c){if(c==="")return this.dispatch();if(c[0]===":")return null;let d=c.indexOf(":"),m,p;switch(d===-1?(m=c,p=""):(m=c.slice(0,d),p=c.slice(d+1),p[0]===" "&&(p=p.slice(1))),m){case "data":this.data.push(p);break;case "event":this.eventType=p;break;case "id":p.includes("\0")||(this.lastEventId=p);break;case "retry":/^[0-9]+$/.test(p)&&(this.retry=parseInt(p,10));break}return null}dispatch(){let c=this.eventType;if(this.eventType="",this.data.length===0)return null;let d={data:this.data.join(`
`),event:c,id:this.lastEventId,retry:this.retry};return this.data=[],d}};async function*We(c){let d=new He;for await(let m of Le(c)){let p=d.decode(m);p!==null&&(yield p);}}var _e=750,te=120*1e3;function re(c,d="up"){let m=Date.now();function p(){return d==="up"||Date.now()-m>te}function P(){return d==="timed out"&&Date.now()-m<=te}return {...c,status:d,lastUpdate:m,isUp:p,isTimedOut:P}}var ie=class extends Error{name="AlgoliaError";constructor(c,d){super(c),d&&(this.name=d);}};var ce=class extends ie{stackTrace;constructor(c,d,m){super(c,m),this.stackTrace=d;}},se=class extends ce{constructor(c){super("Unreachable hosts - your application id may be incorrect. If the error persists, please visit our help center https://alg.li/support-unreachable-hosts or reach out to the Algolia Support team: https://alg.li/support",c,"RetryError");}},W=class extends ce{status;constructor(c,d,m,p="ApiError"){super(c,m,p),this.status=d;}},Qe=class extends ie{response;constructor(c,d){super(c,"DeserializationError"),this.response=d;}},Ve=class extends W{error;constructor(c,d,m,p){super(c,d,p,"DetailedApiError"),this.error=m;}};function V(c){let d=c;for(let m=c.length-1;m>0;m--){let p=Math.floor(Math.random()*(m+1)),P=c[m];d[m]=c[p],d[p]=P;}return d}function ae(c,d,m){let p=$e(m),P=`${c.protocol}://${c.url}${c.port?`:${c.port}`:""}/${d.charAt(0)==="/"?d.substring(1):d}`;return p.length&&(P+=`?${p}`),P}function $e(c){return Object.keys(c).filter(d=>c[d]!==void 0).sort().map(d=>`${d}=${encodeURIComponent(Object.prototype.toString.call(c[d])==="[object Array]"?c[d].join(","):c[d]).replace(/\+/g,"%20")}`).join("&")}function oe(c,d){if(c.method==="GET"||c.data===void 0&&d.data===void 0)return;let m=Array.isArray(c.data)?c.data:{...c.data,...d.data};return JSON.stringify(m)}function ne(c,d,m){let p={Accept:"application/json",...c,...d,...m},P={};return Object.keys(p).forEach(y=>{let h=p[y];P[y.toLowerCase()]=h;}),P}function ze(c){if(!(c.status===204||c.content.length===0))try{return JSON.parse(c.content)}catch(d){throw new Qe(d.message,c)}}function Me({content:c,status:d},m){try{let p=JSON.parse(c);return "error"in p?new Ve(p.message,d,p.error,m):new W(p.message,d,m)}catch{}return new W(c,d,m)}function Je({isTimedOut:c,status:d}){return !c&&~~d===0}function Xe({isTimedOut:c,status:d}){return c||Je({isTimedOut:c,status:d})||~~(d/100)!==2&&~~(d/100)!==4}function Ke({status:c}){return ~~(c/100)===2}function Ye(c){return c.map(d=>ue(d))}function ue(c){let d=c.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...c,request:{...c.request,headers:{...c.request.headers,...d}}}}function k({hosts:c,hostsCache:d,baseHeaders:m,logger:p,baseQueryParameters:P,algoliaAgent:y,timeouts:h,requester:r,requestsCache:e,responsesCache:t,compress:s,compression:a}){async function n(q){let g=await Promise.all(q.map(v=>d.get(v,()=>Promise.resolve(re(v))))),f=g.filter(v=>v.isUp()),T=g.filter(v=>v.isTimedOut()),S=[...f,...T];return {hosts:S.length>0?S:q,getTimeout(v,w){return (T.length===0&&v===0?1:T.length+3+v)*w}}}async function o(q,g,f){let T=[],S=oe(q,g),I=ne(m,q.headers,g.headers),v=a==="gzip"&&S!==void 0&&S.length>_e&&(q.method==="POST"||q.method==="PUT");v&&s===void 0&&p.info("Compression is disabled because no compress method is available.");let w=v&&s!==void 0,G=w?await s(S):S;w&&(I["content-encoding"]="gzip");let j=q.method==="GET"?{...q.data,...g.data}:{},U={...P,...q.queryParameters,...j};if(y.value&&(U["x-algolia-agent"]=y.value),g&&g.queryParameters)for(let O of Object.keys(g.queryParameters))!g.queryParameters[O]||Object.prototype.toString.call(g.queryParameters[O])==="[object Object]"?U[O]=g.queryParameters[O]:U[O]=g.queryParameters[O].toString();let L=0,_=async(O,$)=>{let H=O.pop();if(H===void 0)throw new se(Ye(T));let z={...h,...g.timeouts},Y={data:G,headers:I,method:q.method,url:ae(H,q.path,U),connectTimeout:$(L,z.connect),responseTimeout:$(L,f?z.read:z.write)},Z=M=>{let ee={request:Y,response:M,host:H,triesLeft:O.length};return T.push(ee),ee},F=await r.send(Y);if(Xe(F)){let M=Z(F);return F.isTimedOut&&L++,p.info("Retryable failure",ue(M)),await d.set(H,re(H,F.isTimedOut?"timed out":"down")),_(O,$)}if(Ke(F))return ze(F);throw Z(F),Me(F,T)},N=c.filter(O=>O.accept==="readWrite"||(f?O.accept==="read":O.accept==="write")),K=await n(N);return _([...K.hosts].reverse(),K.getTimeout)}function u(q,g={}){let f=()=>o(q,g,T),T=q.useReadTransporter||q.method==="GET";if((g.cacheable||q.cacheable)!==true)return f();let I={request:q,requestOptions:g,transporter:{queryParameters:P,headers:m}};return t.get(I,()=>e.get(I,()=>e.set(I,f()).then(v=>Promise.all([e.delete(I),v]),v=>Promise.all([e.delete(I),Promise.reject(v)])).then(([v,w])=>w)),{miss:v=>t.set(I,v)})}async function*l(q,g={}){if(!r.sendStream)throw new Error("This requester does not support streaming");let f=oe(q,g),T=ne(m,q.headers,g.headers);T.accept="text/event-stream";let S=q.method==="GET"?{...q.data,...g.data}:{},I={...P,...q.queryParameters,...S};if(y.value&&(I["x-algolia-agent"]=y.value),g&&g.queryParameters)for(let N of Object.keys(g.queryParameters))!g.queryParameters[N]||Object.prototype.toString.call(g.queryParameters[N])==="[object Object]"?I[N]=g.queryParameters[N]:I[N]=g.queryParameters[N].toString();let v=q.useReadTransporter||q.method==="GET",w=c.filter(N=>N.accept==="readWrite"||(v?N.accept==="read":N.accept==="write")),j=(await n(w)).hosts[0];if(!j)throw new se([]);let U={...h,...g.timeouts},L={data:f,headers:T,method:q.method,url:ae(j,q.path,I),connectTimeout:U.connect,responseTimeout:v?U.read:U.write},_=await r.sendStream(L);yield*We(_);}return {hostsCache:d,requester:r,timeouts:h,logger:p,algoliaAgent:y,baseHeaders:m,baseQueryParameters:P,hosts:c,request:u,requestStream:l,requestsCache:e,responsesCache:t}}function i(c,d,m){if(m==null||typeof m=="string"&&m.length===0)throw new Error(`Parameter \`${c}\` is required when calling \`${d}\`.`)}function x(){function c(d){return new Promise(m=>{let p=new XMLHttpRequest;p.open(d.method,d.url,true),Object.keys(d.headers).forEach(r=>p.setRequestHeader(r,d.headers[r]));let P=(r,e)=>setTimeout(()=>{p.abort(),m({status:0,content:e,isTimedOut:true});},r),y=P(d.connectTimeout,"Connection timeout"),h;p.onreadystatechange=()=>{p.readyState>p.OPENED&&h===void 0&&(clearTimeout(y),h=P(d.responseTimeout,"Socket timeout"));},p.onerror=()=>{p.status===0&&(clearTimeout(y),clearTimeout(h),m({content:p.responseText||"Network request failed",status:p.status,isTimedOut:false}));},p.onload=()=>{clearTimeout(y),clearTimeout(h),m({content:p.responseText,status:p.status,isTimedOut:false});},p.send(d.data);})}return {send:c}}var de="1.21.2",he=["de","us"];function Ze(c){return [{url:c?"analytics.{region}.algolia.com".replace("{region}",c):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function et({appId:c,apiKey:d,authMode:m,algoliaAgents:p,region:P,...y}){let h=b(c,d,m),r=k({hosts:Ze(P),...y,algoliaAgent:E({algoliaAgents:p,client:"AbtestingV3",version:de}),baseHeaders:{"content-type":"text/plain",...h.headers(),...y.baseHeaders},baseQueryParameters:{...h.queryParameters(),...y.baseQueryParameters}});return {transporter:r,appId:c,apiKey:d,clearCache(){return Promise.all([r.requestsCache.clear(),r.responsesCache.clear()]).then(()=>{})},get _ua(){return r.algoliaAgent.value},addAlgoliaAgent(e,t){r.algoliaAgent.add({segment:e,version:t});},setClientApiKey({apiKey:e}){!m||m==="WithinHeaders"?r.baseHeaders["x-algolia-api-key"]=e:r.baseQueryParameters["x-algolia-api-key"]=e;},addABTests(e,t){i("addABTestsRequest","addABTests",e),i("addABTestsRequest.name","addABTests",e.name),i("addABTestsRequest.variants","addABTests",e.variants),i("addABTestsRequest.metrics","addABTests",e.metrics),i("addABTestsRequest.endAt","addABTests",e.endAt);let o={method:"POST",path:"/3/abtests",queryParameters:{},headers:{},data:e};return r.request(o,t)},customDelete({path:e,parameters:t},s){i("path","customDelete",e);let u={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customGet({path:e,parameters:t},s){i("path","customGet",e);let u={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customPost({path:e,parameters:t,body:s},a){i("path","customPost",e);let l={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},customPut({path:e,parameters:t,body:s},a){i("path","customPut",e);let l={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},deleteABTest({id:e},t){i("id","deleteABTest",e);let o={method:"DELETE",path:"/3/abtests/{id}".replace("{id}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},estimateABTest(e,t){i("estimateABTestRequest","estimateABTest",e),i("estimateABTestRequest.configuration","estimateABTest",e.configuration),i("estimateABTestRequest.variants","estimateABTest",e.variants);let o={method:"POST",path:"/3/abtests/estimate",queryParameters:{},headers:{},data:e};return r.request(o,t)},getABTest({id:e},t){i("id","getABTest",e);let o={method:"GET",path:"/3/abtests/{id}".replace("{id}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},getTimeseries({id:e,startDate:t,endDate:s,metric:a},n){i("id","getTimeseries",e);let o="/3/abtests/{id}/timeseries".replace("{id}",encodeURIComponent(e)),u={},l={};t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.metric=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},listABTests({offset:e,limit:t,indexPrefix:s,indexSuffix:a,direction:n}={},o=void 0){let u="/3/abtests",l={},q={};e!==void 0&&(q.offset=e.toString()),t!==void 0&&(q.limit=t.toString()),s!==void 0&&(q.indexPrefix=s.toString()),a!==void 0&&(q.indexSuffix=a.toString()),n!==void 0&&(q.direction=n.toString());let g={method:"GET",path:u,queryParameters:q,headers:l};return r.request(g,o)},stopABTest({id:e},t){i("id","stopABTest",e);let o={method:"POST",path:"/3/abtests/{id}/stop".replace("{id}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)}}}function le(c,d,m,p){if(!c||typeof c!="string")throw new Error("`appId` is missing.");if(!d||typeof d!="string")throw new Error("`apiKey` is missing.");if(m&&(typeof m!="string"||!he.includes(m)))throw new Error(`\`region\` must be one of the following: ${he.join(", ")}`);let{compression:P,...y}=p||{};return et({appId:c,apiKey:d,region:m,timeouts:{connect:1e3,read:2e3,write:3e4},logger:D(),requester:x(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:R(),requestsCache:R({serializable:false}),hostsCache:C({caches:[A({key:`${de}-${c}`}),R()]}),...y})}var pe="5.55.2",me=["de","us"];function tt(c){return [{url:c?"analytics.{region}.algolia.com".replace("{region}",c):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function rt({appId:c,apiKey:d,authMode:m,algoliaAgents:p,region:P,...y}){let h=b(c,d,m),r=k({hosts:tt(P),...y,algoliaAgent:E({algoliaAgents:p,client:"Abtesting",version:pe}),baseHeaders:{"content-type":"text/plain",...h.headers(),...y.baseHeaders},baseQueryParameters:{...h.queryParameters(),...y.baseQueryParameters}});return {transporter:r,appId:c,apiKey:d,clearCache(){return Promise.all([r.requestsCache.clear(),r.responsesCache.clear()]).then(()=>{})},get _ua(){return r.algoliaAgent.value},addAlgoliaAgent(e,t){r.algoliaAgent.add({segment:e,version:t});},setClientApiKey({apiKey:e}){!m||m==="WithinHeaders"?r.baseHeaders["x-algolia-api-key"]=e:r.baseQueryParameters["x-algolia-api-key"]=e;},addABTests(e,t){i("addABTestsRequest","addABTests",e),i("addABTestsRequest.name","addABTests",e.name),i("addABTestsRequest.variants","addABTests",e.variants),i("addABTestsRequest.endAt","addABTests",e.endAt);let o={method:"POST",path:"/2/abtests",queryParameters:{},headers:{},data:e};return r.request(o,t)},customDelete({path:e,parameters:t},s){i("path","customDelete",e);let u={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customGet({path:e,parameters:t},s){i("path","customGet",e);let u={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customPost({path:e,parameters:t,body:s},a){i("path","customPost",e);let l={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},customPut({path:e,parameters:t,body:s},a){i("path","customPut",e);let l={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},deleteABTest({id:e},t){i("id","deleteABTest",e);let o={method:"DELETE",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},estimateABTest(e,t){i("estimateABTestRequest","estimateABTest",e),i("estimateABTestRequest.configuration","estimateABTest",e.configuration),i("estimateABTestRequest.variants","estimateABTest",e.variants);let o={method:"POST",path:"/2/abtests/estimate",queryParameters:{},headers:{},data:e};return r.request(o,t)},getABTest({id:e},t){i("id","getABTest",e);let o={method:"GET",path:"/2/abtests/{id}".replace("{id}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},listABTests({offset:e,limit:t,indexPrefix:s,indexSuffix:a}={},n=void 0){let o="/2/abtests",u={},l={};e!==void 0&&(l.offset=e.toString()),t!==void 0&&(l.limit=t.toString()),s!==void 0&&(l.indexPrefix=s.toString()),a!==void 0&&(l.indexSuffix=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},stopABTest({id:e},t){i("id","stopABTest",e);let o={method:"POST",path:"/2/abtests/{id}/stop".replace("{id}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)}}}function qe(c,d,m,p){if(!c||typeof c!="string")throw new Error("`appId` is missing.");if(!d||typeof d!="string")throw new Error("`apiKey` is missing.");if(m&&(typeof m!="string"||!me.includes(m)))throw new Error(`\`region\` must be one of the following: ${me.join(", ")}`);let{compression:P,...y}=p||{};return rt({appId:c,apiKey:d,region:m,timeouts:{connect:1e3,read:2e3,write:3e4},logger:D(),requester:x(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:R(),requestsCache:R({serializable:false}),hostsCache:C({caches:[A({key:`${pe}-${c}`}),R()]}),...y})}var Pe="5.55.2",ge=["de","us"];function st(c){return [{url:c?"analytics.{region}.algolia.com".replace("{region}",c):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function at({appId:c,apiKey:d,authMode:m,algoliaAgents:p,region:P,...y}){let h=b(c,d,m),r=k({hosts:st(P),...y,algoliaAgent:E({algoliaAgents:p,client:"Analytics",version:Pe}),baseHeaders:{"content-type":"text/plain",...h.headers(),...y.baseHeaders},baseQueryParameters:{...h.queryParameters(),...y.baseQueryParameters}});return {transporter:r,appId:c,apiKey:d,clearCache(){return Promise.all([r.requestsCache.clear(),r.responsesCache.clear()]).then(()=>{})},get _ua(){return r.algoliaAgent.value},addAlgoliaAgent(e,t){r.algoliaAgent.add({segment:e,version:t});},setClientApiKey({apiKey:e}){!m||m==="WithinHeaders"?r.baseHeaders["x-algolia-api-key"]=e:r.baseQueryParameters["x-algolia-api-key"]=e;},customDelete({path:e,parameters:t},s){i("path","customDelete",e);let u={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customGet({path:e,parameters:t},s){i("path","customGet",e);let u={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customPost({path:e,parameters:t,body:s},a){i("path","customPost",e);let l={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},customPut({path:e,parameters:t,body:s},a){i("path","customPut",e);let l={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},getAddToCartRate({index:e,startDate:t,endDate:s,tags:a},n){i("index","getAddToCartRate",e);let o="/2/conversions/addToCartRate",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getAverageClickPosition({index:e,startDate:t,endDate:s,tags:a},n){i("index","getAverageClickPosition",e);let o="/2/clicks/averageClickPosition",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getClickPositions({index:e,startDate:t,endDate:s,tags:a},n){i("index","getClickPositions",e);let o="/2/clicks/positions",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getClickThroughRate({index:e,startDate:t,endDate:s,tags:a},n){i("index","getClickThroughRate",e);let o="/2/clicks/clickThroughRate",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getConversionRate({index:e,startDate:t,endDate:s,tags:a},n){i("index","getConversionRate",e);let o="/2/conversions/conversionRate",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getNoClickRate({index:e,startDate:t,endDate:s,tags:a},n){i("index","getNoClickRate",e);let o="/2/searches/noClickRate",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getNoResultsRate({index:e,startDate:t,endDate:s,tags:a},n){i("index","getNoResultsRate",e);let o="/2/searches/noResultRate",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getPurchaseRate({index:e,startDate:t,endDate:s,tags:a},n){i("index","getPurchaseRate",e);let o="/2/conversions/purchaseRate",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getRevenue({index:e,startDate:t,endDate:s,tags:a},n){i("index","getRevenue",e);let o="/2/conversions/revenue",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getSearchesCount({index:e,startDate:t,endDate:s,tags:a},n){i("index","getSearchesCount",e);let o="/2/searches/count",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)},getSearchesNoClicks({index:e,startDate:t,endDate:s,limit:a,offset:n,tags:o},u){i("index","getSearchesNoClicks",e);let l="/2/searches/noClicks",q={},g={};e!==void 0&&(g.index=e.toString()),t!==void 0&&(g.startDate=t.toString()),s!==void 0&&(g.endDate=s.toString()),a!==void 0&&(g.limit=a.toString()),n!==void 0&&(g.offset=n.toString()),o!==void 0&&(g.tags=o.toString());let f={method:"GET",path:l,queryParameters:g,headers:q};return r.request(f,u)},getSearchesNoResults({index:e,startDate:t,endDate:s,limit:a,offset:n,tags:o},u){i("index","getSearchesNoResults",e);let l="/2/searches/noResults",q={},g={};e!==void 0&&(g.index=e.toString()),t!==void 0&&(g.startDate=t.toString()),s!==void 0&&(g.endDate=s.toString()),a!==void 0&&(g.limit=a.toString()),n!==void 0&&(g.offset=n.toString()),o!==void 0&&(g.tags=o.toString());let f={method:"GET",path:l,queryParameters:g,headers:q};return r.request(f,u)},getStatus({index:e},t){i("index","getStatus",e);let s="/2/status",a={},n={};e!==void 0&&(n.index=e.toString());let o={method:"GET",path:s,queryParameters:n,headers:a};return r.request(o,t)},getTopCountries({index:e,startDate:t,endDate:s,limit:a,offset:n,tags:o},u){i("index","getTopCountries",e);let l="/2/countries",q={},g={};e!==void 0&&(g.index=e.toString()),t!==void 0&&(g.startDate=t.toString()),s!==void 0&&(g.endDate=s.toString()),a!==void 0&&(g.limit=a.toString()),n!==void 0&&(g.offset=n.toString()),o!==void 0&&(g.tags=o.toString());let f={method:"GET",path:l,queryParameters:g,headers:q};return r.request(f,u)},getTopFilterAttributes({index:e,search:t,startDate:s,endDate:a,limit:n,offset:o,tags:u},l){i("index","getTopFilterAttributes",e);let q="/2/filters",g={},f={};e!==void 0&&(f.index=e.toString()),t!==void 0&&(f.search=t.toString()),s!==void 0&&(f.startDate=s.toString()),a!==void 0&&(f.endDate=a.toString()),n!==void 0&&(f.limit=n.toString()),o!==void 0&&(f.offset=o.toString()),u!==void 0&&(f.tags=u.toString());let T={method:"GET",path:q,queryParameters:f,headers:g};return r.request(T,l)},getTopFilterForAttribute({attribute:e,index:t,search:s,startDate:a,endDate:n,limit:o,offset:u,tags:l},q){i("attribute","getTopFilterForAttribute",e),i("index","getTopFilterForAttribute",t);let g="/2/filters/{attribute}".replace("{attribute}",encodeURIComponent(e)),f={},T={};t!==void 0&&(T.index=t.toString()),s!==void 0&&(T.search=s.toString()),a!==void 0&&(T.startDate=a.toString()),n!==void 0&&(T.endDate=n.toString()),o!==void 0&&(T.limit=o.toString()),u!==void 0&&(T.offset=u.toString()),l!==void 0&&(T.tags=l.toString());let S={method:"GET",path:g,queryParameters:T,headers:f};return r.request(S,q)},getTopFiltersNoResults({index:e,search:t,startDate:s,endDate:a,limit:n,offset:o,tags:u},l){i("index","getTopFiltersNoResults",e);let q="/2/filters/noResults",g={},f={};e!==void 0&&(f.index=e.toString()),t!==void 0&&(f.search=t.toString()),s!==void 0&&(f.startDate=s.toString()),a!==void 0&&(f.endDate=a.toString()),n!==void 0&&(f.limit=n.toString()),o!==void 0&&(f.offset=o.toString()),u!==void 0&&(f.tags=u.toString());let T={method:"GET",path:q,queryParameters:f,headers:g};return r.request(T,l)},getTopHits({index:e,search:t,clickAnalytics:s,revenueAnalytics:a,startDate:n,endDate:o,limit:u,offset:l,tags:q},g){i("index","getTopHits",e);let f="/2/hits",T={},S={};e!==void 0&&(S.index=e.toString()),t!==void 0&&(S.search=t.toString()),s!==void 0&&(S.clickAnalytics=s.toString()),a!==void 0&&(S.revenueAnalytics=a.toString()),n!==void 0&&(S.startDate=n.toString()),o!==void 0&&(S.endDate=o.toString()),u!==void 0&&(S.limit=u.toString()),l!==void 0&&(S.offset=l.toString()),q!==void 0&&(S.tags=q.toString());let I={method:"GET",path:f,queryParameters:S,headers:T};return r.request(I,g)},getTopSearches({index:e,clickAnalytics:t,revenueAnalytics:s,startDate:a,endDate:n,orderBy:o,direction:u,limit:l,offset:q,tags:g},f){i("index","getTopSearches",e);let T="/2/searches",S={},I={};e!==void 0&&(I.index=e.toString()),t!==void 0&&(I.clickAnalytics=t.toString()),s!==void 0&&(I.revenueAnalytics=s.toString()),a!==void 0&&(I.startDate=a.toString()),n!==void 0&&(I.endDate=n.toString()),o!==void 0&&(I.orderBy=o.toString()),u!==void 0&&(I.direction=u.toString()),l!==void 0&&(I.limit=l.toString()),q!==void 0&&(I.offset=q.toString()),g!==void 0&&(I.tags=g.toString());let v={method:"GET",path:T,queryParameters:I,headers:S};return r.request(v,f)},getUsersCount({index:e,startDate:t,endDate:s,tags:a},n){i("index","getUsersCount",e);let o="/2/users/count",u={},l={};e!==void 0&&(l.index=e.toString()),t!==void 0&&(l.startDate=t.toString()),s!==void 0&&(l.endDate=s.toString()),a!==void 0&&(l.tags=a.toString());let q={method:"GET",path:o,queryParameters:l,headers:u};return r.request(q,n)}}}function ye(c,d,m,p){if(!c||typeof c!="string")throw new Error("`appId` is missing.");if(!d||typeof d!="string")throw new Error("`apiKey` is missing.");if(m&&(typeof m!="string"||!ge.includes(m)))throw new Error(`\`region\` must be one of the following: ${ge.join(", ")}`);let{compression:P,...y}=p||{};return at({appId:c,apiKey:d,region:m,timeouts:{connect:1e3,read:2e3,write:3e4},logger:D(),requester:x(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:R(),requestsCache:R({serializable:false}),hostsCache:C({caches:[A({key:`${Pe}-${c}`}),R()]}),...y})}var Se="5.55.2",fe=["de","us"];function ot(c){return [{url:c?"insights.{region}.algolia.io".replace("{region}",c):"insights.algolia.io",accept:"readWrite",protocol:"https"}]}function nt({appId:c,apiKey:d,authMode:m,algoliaAgents:p,region:P,...y}){let h=b(c,d,m),r=k({hosts:ot(P),...y,algoliaAgent:E({algoliaAgents:p,client:"Insights",version:Se}),baseHeaders:{"content-type":"text/plain",...h.headers(),...y.baseHeaders},baseQueryParameters:{...h.queryParameters(),...y.baseQueryParameters}});return {transporter:r,appId:c,apiKey:d,clearCache(){return Promise.all([r.requestsCache.clear(),r.responsesCache.clear()]).then(()=>{})},get _ua(){return r.algoliaAgent.value},addAlgoliaAgent(e,t){r.algoliaAgent.add({segment:e,version:t});},setClientApiKey({apiKey:e}){!m||m==="WithinHeaders"?r.baseHeaders["x-algolia-api-key"]=e:r.baseQueryParameters["x-algolia-api-key"]=e;},customDelete({path:e,parameters:t},s){i("path","customDelete",e);let u={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customGet({path:e,parameters:t},s){i("path","customGet",e);let u={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customPost({path:e,parameters:t,body:s},a){i("path","customPost",e);let l={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},customPut({path:e,parameters:t,body:s},a){i("path","customPut",e);let l={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},deleteUserToken({userToken:e},t){i("userToken","deleteUserToken",e);let o={method:"DELETE",path:"/1/usertokens/{userToken}".replace("{userToken}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},pushEvents(e,t){i("insightsEvents","pushEvents",e),i("insightsEvents.events","pushEvents",e.events);let o={method:"POST",path:"/1/events",queryParameters:{},headers:{},data:e};return r.request(o,t)}}}function Te(c,d,m,p){if(!c||typeof c!="string")throw new Error("`appId` is missing.");if(!d||typeof d!="string")throw new Error("`apiKey` is missing.");if(m&&(typeof m!="string"||!fe.includes(m)))throw new Error(`\`region\` must be one of the following: ${fe.join(", ")}`);let{compression:P,...y}=p||{};return nt({appId:c,apiKey:d,region:m,timeouts:{connect:1e3,read:2e3,write:3e4},logger:D(),requester:x(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:R(),requestsCache:R({serializable:false}),hostsCache:C({caches:[A({key:`${Se}-${c}`}),R()]}),...y})}var Re="5.55.2",ve=["eu","us"];function it(c){return [{url:"personalization.{region}.algolia.com".replace("{region}",c),accept:"readWrite",protocol:"https"}]}function ct({appId:c,apiKey:d,authMode:m,algoliaAgents:p,region:P,...y}){let h=b(c,d,m),r=k({hosts:it(P),...y,algoliaAgent:E({algoliaAgents:p,client:"Personalization",version:Re}),baseHeaders:{"content-type":"text/plain",...h.headers(),...y.baseHeaders},baseQueryParameters:{...h.queryParameters(),...y.baseQueryParameters}});return {transporter:r,appId:c,apiKey:d,clearCache(){return Promise.all([r.requestsCache.clear(),r.responsesCache.clear()]).then(()=>{})},get _ua(){return r.algoliaAgent.value},addAlgoliaAgent(e,t){r.algoliaAgent.add({segment:e,version:t});},setClientApiKey({apiKey:e}){!m||m==="WithinHeaders"?r.baseHeaders["x-algolia-api-key"]=e:r.baseQueryParameters["x-algolia-api-key"]=e;},customDelete({path:e,parameters:t},s){i("path","customDelete",e);let u={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customGet({path:e,parameters:t},s){i("path","customGet",e);let u={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customPost({path:e,parameters:t,body:s},a){i("path","customPost",e);let l={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},customPut({path:e,parameters:t,body:s},a){i("path","customPut",e);let l={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},deleteUserProfile({userToken:e},t){i("userToken","deleteUserProfile",e);let o={method:"DELETE",path:"/1/profiles/{userToken}".replace("{userToken}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},getPersonalizationStrategy(e){let n={method:"GET",path:"/1/strategies/personalization",queryParameters:{},headers:{}};return r.request(n,e)},getUserTokenProfile({userToken:e},t){i("userToken","getUserTokenProfile",e);let o={method:"GET",path:"/1/profiles/personalization/{userToken}".replace("{userToken}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},setPersonalizationStrategy(e,t){i("personalizationStrategyParams","setPersonalizationStrategy",e),i("personalizationStrategyParams.eventsScoring","setPersonalizationStrategy",e.eventsScoring),i("personalizationStrategyParams.facetsScoring","setPersonalizationStrategy",e.facetsScoring),i("personalizationStrategyParams.personalizationImpact","setPersonalizationStrategy",e.personalizationImpact);let o={method:"POST",path:"/1/strategies/personalization",queryParameters:{},headers:{},data:e};return r.request(o,t)}}}function Ie(c,d,m,p){if(!c||typeof c!="string")throw new Error("`appId` is missing.");if(!d||typeof d!="string")throw new Error("`apiKey` is missing.");if(!m||m&&(typeof m!="string"||!ve.includes(m)))throw new Error(`\`region\` is required and must be one of the following: ${ve.join(", ")}`);let{compression:P,...y}=p||{};return ct({appId:c,apiKey:d,region:m,timeouts:{connect:1e3,read:2e3,write:3e4},logger:D(),requester:x(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:R(),requestsCache:R({serializable:false}),hostsCache:C({caches:[A({key:`${Re}-${c}`}),R()]}),...y})}var Ae="5.55.2",Ce=["eu","us"];function ut(c){return [{url:"query-suggestions.{region}.algolia.com".replace("{region}",c),accept:"readWrite",protocol:"https"}]}function ht({appId:c,apiKey:d,authMode:m,algoliaAgents:p,region:P,...y}){let h=b(c,d,m),r=k({hosts:ut(P),...y,algoliaAgent:E({algoliaAgents:p,client:"QuerySuggestions",version:Ae}),baseHeaders:{"content-type":"text/plain",...h.headers(),...y.baseHeaders},baseQueryParameters:{...h.queryParameters(),...y.baseQueryParameters}});return {transporter:r,appId:c,apiKey:d,clearCache(){return Promise.all([r.requestsCache.clear(),r.responsesCache.clear()]).then(()=>{})},get _ua(){return r.algoliaAgent.value},addAlgoliaAgent(e,t){r.algoliaAgent.add({segment:e,version:t});},setClientApiKey({apiKey:e}){!m||m==="WithinHeaders"?r.baseHeaders["x-algolia-api-key"]=e:r.baseQueryParameters["x-algolia-api-key"]=e;},createConfig(e,t){i("configurationWithIndex","createConfig",e);let o={method:"POST",path:"/1/configs",queryParameters:{},headers:{},data:e};return r.request(o,t)},customDelete({path:e,parameters:t},s){i("path","customDelete",e);let u={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customGet({path:e,parameters:t},s){i("path","customGet",e);let u={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return r.request(u,s)},customPost({path:e,parameters:t,body:s},a){i("path","customPost",e);let l={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},customPut({path:e,parameters:t,body:s},a){i("path","customPut",e);let l={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:s||{}};return r.request(l,a)},deleteConfig({indexName:e},t){i("indexName","deleteConfig",e);let o={method:"DELETE",path:"/1/configs/{indexName}".replace("{indexName}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},getAllConfigs(e){let n={method:"GET",path:"/1/configs",queryParameters:{},headers:{}};return r.request(n,e)},getConfig({indexName:e},t){i("indexName","getConfig",e);let o={method:"GET",path:"/1/configs/{indexName}".replace("{indexName}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},getConfigStatus({indexName:e},t){i("indexName","getConfigStatus",e);let o={method:"GET",path:"/1/configs/{indexName}/status".replace("{indexName}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},getLogFile({indexName:e},t){i("indexName","getLogFile",e);let o={method:"GET",path:"/1/logs/{indexName}".replace("{indexName}",encodeURIComponent(e)),queryParameters:{},headers:{}};return r.request(o,t)},updateConfig({indexName:e,configuration:t},s){i("indexName","updateConfig",e),i("configuration","updateConfig",t),i("configuration.sourceIndices","updateConfig",t.sourceIndices);let u={method:"PUT",path:"/1/configs/{indexName}".replace("{indexName}",encodeURIComponent(e)),queryParameters:{},headers:{},data:t};return r.request(u,s)}}}function be(c,d,m,p){if(!c||typeof c!="string")throw new Error("`appId` is missing.");if(!d||typeof d!="string")throw new Error("`apiKey` is missing.");if(!m||m&&(typeof m!="string"||!Ce.includes(m)))throw new Error(`\`region\` is required and must be one of the following: ${Ce.join(", ")}`);let{compression:P,...y}=p||{};return ht({appId:c,apiKey:d,region:m,timeouts:{connect:1e3,read:2e3,write:3e4},logger:D(),requester:x(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:R(),requestsCache:R({serializable:false}),hostsCache:C({caches:[A({key:`${Ae}-${c}`}),R()]}),...y})}var J="5.55.2";function dt(c){return [{url:`${c}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${c}.algolia.net`,accept:"write",protocol:"https"}].concat(V([{url:`${c}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${c}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${c}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}function lt({appId:c,apiKey:d,authMode:m,algoliaAgents:p,...P}){let y=b(c,d,m),h=k({hosts:dt(c),...P,algoliaAgent:E({algoliaAgents:p,client:"Search",version:J}),baseHeaders:{"content-type":"text/plain",...y.headers(),...P.baseHeaders},baseQueryParameters:{...y.queryParameters(),...P.baseQueryParameters}});return {transporter:h,appId:c,apiKey:d,clearCache(){return Promise.all([h.requestsCache.clear(),h.responsesCache.clear()]).then(()=>{})},get _ua(){return h.algoliaAgent.value},addAlgoliaAgent(r,e){h.algoliaAgent.add({segment:r,version:e});},setClientApiKey({apiKey:r}){!m||m==="WithinHeaders"?h.baseHeaders["x-algolia-api-key"]=r:h.baseQueryParameters["x-algolia-api-key"]=r;},waitForTask({indexName:r,taskID:e,maxRetries:t=100,timeout:s=n=>Math.min(n*200,5e3)},a){let n=0;return B({func:()=>this.getTask({indexName:r,taskID:e},a),validate:o=>o.status==="published",aggregator:()=>n+=1,error:{validate:()=>n>=t,message:()=>`Stopped waiting for the task after ${t} retries. This does not mean the operation failed; it may still complete. If you need to keep polling, retry with a higher maxRetries.`},timeout:()=>s(n)})},waitForAppTask({taskID:r,maxRetries:e=100,timeout:t=a=>Math.min(a*200,5e3)},s){let a=0;return B({func:()=>this.getAppTask({taskID:r},s),validate:n=>n.status==="published",aggregator:()=>a+=1,error:{validate:()=>a>=e,message:()=>`Stopped waiting for the task after ${e} retries. This does not mean the operation failed; it may still complete. If you need to keep polling, retry with a higher maxRetries.`},timeout:()=>t(a)})},waitForApiKey({operation:r,key:e,apiKey:t,maxRetries:s=100,timeout:a=o=>Math.min(o*200,5e3)},n){let o=0,u={aggregator:()=>o+=1,error:{validate:()=>o>=s,message:()=>`Stopped waiting for the API key operation after ${s} retries. This does not mean the operation failed; it may still complete. If you need to keep polling, retry with a higher maxRetries.`},timeout:()=>a(o)};if(r==="update"){if(!t)throw new Error("`apiKey` is required when waiting for an `update` operation.");return B({...u,func:()=>this.getApiKey({key:e},n),validate:l=>{for(let q of Object.keys(t)){let g=t[q],f=l[q];if(Array.isArray(g)&&Array.isArray(f)){if(g.length!==f.length||g.some((T,S)=>T!==f[S]))return false}else if(g!==f)return false}return true}})}return B({...u,func:()=>this.getApiKey({key:e},n).catch(l=>{if(l.status!==404)throw l}),validate:l=>r==="add"?l!==void 0:l===void 0})},browseObjects({indexName:r,browseParams:e,...t},s){return B({func:a=>this.browse({indexName:r,browseParams:{cursor:a?a.cursor:void 0,hitsPerPage:1e3,...e}},s),validate:a=>a.cursor===void 0,...t})},browseRules({indexName:r,searchRulesParams:e,...t},s){let a={...e,hitsPerPage:e?.hitsPerPage||1e3};return B({func:n=>this.searchRules({indexName:r,searchRulesParams:{...a,page:n?n.page+1:a.page||0}},s),validate:n=>n.hits.length<a.hitsPerPage,...t})},browseSynonyms({indexName:r,searchSynonymsParams:e,...t},s){let a={...e,page:e?.page||0,hitsPerPage:1e3};return B({func:n=>{let o=this.searchSynonyms({indexName:r,searchSynonymsParams:{...a,page:a.page}},s);return a.page+=1,o},validate:n=>n.hits.length<a.hitsPerPage,...t})},async chunkedBatch({indexName:r,objects:e,action:t="addObject",waitForTasks:s,batchSize:a=1e3,maxRetries:n=100},o){let u=[],l=[],q=e.entries();for(let[g,f]of q)u.push({action:t,body:f}),(u.length===a||g===e.length-1)&&(l.push(await this.batch({indexName:r,batchWriteParams:{requests:u}},o)),u=[]);if(s)for(let g of l)await this.waitForTask({indexName:r,taskID:g.taskID,maxRetries:n});return l},async saveObjects({indexName:r,objects:e,waitForTasks:t,batchSize:s,maxRetries:a},n){return await this.chunkedBatch({indexName:r,objects:e,action:"addObject",waitForTasks:t,batchSize:s,maxRetries:a},n)},async deleteObjects({indexName:r,objectIDs:e,waitForTasks:t,batchSize:s,maxRetries:a},n){return await this.chunkedBatch({indexName:r,objects:e.map(o=>({objectID:o})),action:"deleteObject",waitForTasks:t,batchSize:s,maxRetries:a},n)},async partialUpdateObjects({indexName:r,objects:e,createIfNotExists:t,waitForTasks:s,batchSize:a,maxRetries:n},o){return await this.chunkedBatch({indexName:r,objects:e,action:t?"partialUpdateObject":"partialUpdateObjectNoCreate",batchSize:a,waitForTasks:s,maxRetries:n},o)},async replaceAllObjects({indexName:r,objects:e,batchSize:t,scopes:s,maxRetries:a=Q},n){let o=Math.floor(Math.random()*1e6)+1e5,u=`${r}_tmp_${o}`;s===void 0&&(s=["settings","rules","synonyms"]);try{let l=await this.operationIndex({indexName:r,operationIndexParams:{operation:"copy",destination:u,scope:s}},n),q=await this.chunkedBatch({indexName:u,objects:e,waitForTasks:!0,batchSize:t,maxRetries:a},n);await this.waitForTask({indexName:u,taskID:l.taskID,maxRetries:a}),l=await this.operationIndex({indexName:r,operationIndexParams:{operation:"copy",destination:u,scope:s}},n),await this.waitForTask({indexName:u,taskID:l.taskID,maxRetries:a});let g=await this.operationIndex({indexName:u,operationIndexParams:{operation:"move",destination:r}},n);return await this.waitForTask({indexName:u,taskID:g.taskID,maxRetries:a}),{copyOperationResponse:l,batchResponses:q,moveOperationResponse:g}}catch(l){throw await this.deleteIndex({indexName:u}),l}},async indexExists({indexName:r}){try{await this.getSettings({indexName:r});}catch(e){if(e instanceof W&&e.status===404)return false;throw e}return true},searchForHits(r,e){return this.search(r,e)},searchForFacets(r,e){return this.search(r,e)},addApiKey(r,e){i("apiKey","addApiKey",r),i("apiKey.acl","addApiKey",r.acl);let n={method:"POST",path:"/1/keys",queryParameters:{},headers:{},data:r};return h.request(n,e)},addOrUpdateObject({indexName:r,objectID:e,body:t},s){i("indexName","addOrUpdateObject",r),i("objectID","addOrUpdateObject",e),i("body","addOrUpdateObject",t);let u={method:"PUT",path:"/1/indexes/{indexName}/{objectID}".replace("{indexName}",encodeURIComponent(r)).replace("{objectID}",encodeURIComponent(e)),queryParameters:{},headers:{},data:t};return h.request(u,s)},appendSource(r,e){i("source","appendSource",r),i("source.source","appendSource",r.source);let n={method:"POST",path:"/1/security/sources/append",queryParameters:{},headers:{},data:r};return h.request(n,e)},assignUserId({xAlgoliaUserID:r,assignUserIdParams:e},t){i("xAlgoliaUserID","assignUserId",r),i("assignUserIdParams","assignUserId",e),i("assignUserIdParams.cluster","assignUserId",e.cluster);let s="/1/clusters/mapping",a={},n={};r!==void 0&&(a["X-Algolia-User-ID"]=r.toString());let o={method:"POST",path:s,queryParameters:n,headers:a,data:e};return h.request(o,t)},batch({indexName:r,batchWriteParams:e},t){i("indexName","batch",r),i("batchWriteParams","batch",e),i("batchWriteParams.requests","batch",e.requests);let o={method:"POST",path:"/1/indexes/{indexName}/batch".replace("{indexName}",encodeURIComponent(r)),queryParameters:{},headers:{},data:e};return h.request(o,t)},batchAssignUserIds({xAlgoliaUserID:r,batchAssignUserIdsParams:e},t){i("xAlgoliaUserID","batchAssignUserIds",r),i("batchAssignUserIdsParams","batchAssignUserIds",e),i("batchAssignUserIdsParams.cluster","batchAssignUserIds",e.cluster),i("batchAssignUserIdsParams.users","batchAssignUserIds",e.users);let s="/1/clusters/mapping/batch",a={},n={};r!==void 0&&(a["X-Algolia-User-ID"]=r.toString());let o={method:"POST",path:s,queryParameters:n,headers:a,data:e};return h.request(o,t)},batchDictionaryEntries({dictionaryName:r,batchDictionaryEntriesParams:e},t){i("dictionaryName","batchDictionaryEntries",r),i("batchDictionaryEntriesParams","batchDictionaryEntries",e),i("batchDictionaryEntriesParams.requests","batchDictionaryEntries",e.requests);let o={method:"POST",path:"/1/dictionaries/{dictionaryName}/batch".replace("{dictionaryName}",encodeURIComponent(r)),queryParameters:{},headers:{},data:e};return h.request(o,t)},browse({indexName:r,browseParams:e},t){i("indexName","browse",r);let o={method:"POST",path:"/1/indexes/{indexName}/browse".replace("{indexName}",encodeURIComponent(r)),queryParameters:{},headers:{},data:e||{},useReadTransporter:true};return h.request(o,t)},clearObjects({indexName:r},e){i("indexName","clearObjects",r);let n={method:"POST",path:"/1/indexes/{indexName}/clear".replace("{indexName}",encodeURIComponent(r)),queryParameters:{},headers:{}};return h.request(n,e)},clearRules({indexName:r,forwardToReplicas:e},t){i("indexName","clearRules",r);let s="/1/indexes/{indexName}/rules/clear".replace("{indexName}",encodeURIComponent(r)),a={},n={};e!==void 0&&(n.forwardToReplicas=e.toString());let o={method:"POST",path:s,queryParameters:n,headers:a};return h.request(o,t)},clearSynonyms({indexName:r,forwardToReplicas:e},t){i("indexName","clearSynonyms",r);let s="/1/indexes/{indexName}/synonyms/clear".replace("{indexName}",encodeURIComponent(r)),a={},n={};e!==void 0&&(n.forwardToReplicas=e.toString());let o={method:"POST",path:s,queryParameters:n,headers:a};return h.request(o,t)},customDelete({path:r,parameters:e},t){i("path","customDelete",r);let o={method:"DELETE",path:"/{path}".replace("{path}",r),queryParameters:e||{},headers:{}};return h.request(o,t)},customGet({path:r,parameters:e},t){i("path","customGet",r);let o={method:"GET",path:"/{path}".replace("{path}",r),queryParameters:e||{},headers:{}};return h.request(o,t)},customPost({path:r,parameters:e,body:t},s){i("path","customPost",r);let u={method:"POST",path:"/{path}".replace("{path}",r),queryParameters:e||{},headers:{},data:t||{}};return h.request(u,s)},customPut({path:r,parameters:e,body:t},s){i("path","customPut",r);let u={method:"PUT",path:"/{path}".replace("{path}",r),queryParameters:e||{},headers:{},data:t||{}};return h.request(u,s)},deleteApiKey({key:r},e){i("key","deleteApiKey",r);let n={method:"DELETE",path:"/1/keys/{key}".replace("{key}",encodeURIComponent(r)),queryParameters:{},headers:{}};return h.request(n,e)},deleteBy({indexName:r,deleteByParams:e},t){i("indexName","deleteBy",r),i("deleteByParams","deleteBy",e);let o={method:"POST",path:"/1/indexes/{indexName}/deleteByQuery".replace("{indexName}",encodeURIComponent(r)),queryParameters:{},headers:{},data:e};return h.request(o,t)},deleteIndex({indexName:r},e){i("indexName","deleteIndex",r);let n={method:"DELETE",path:"/1/indexes/{indexName}".replace("{indexName}",encodeURIComponen