(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/lite"] = {}));
})(this, (function (exports) { 'use strict';

	function K(e){let r,o=`algolia-client-js-${e.key}`;function t(){return r===void 0&&(r=e.localStorage||window.localStorage),r}function s(){return JSON.parse(t().getItem(o)||"{}")}function l(n){t().setItem(o,JSON.stringify(n));}function i(){return new Promise(n=>setTimeout(n,0))}function a(){let n=e.timeToLive?e.timeToLive*1e3:null,u=s(),p=new Date().getTime(),d=false;return {namespace:Object.fromEntries(Object.entries(u).filter(([,h])=>!h||h.timestamp===void 0||n&&h.timestamp+n<p?(d=true,false):true)),changed:d}}return {get(n,u,p={miss:()=>Promise.resolve()}){return i().then(()=>{let{namespace:d,changed:x}=a(),h=d[JSON.stringify(n)];return x&&l(d),h?h.value:u().then(v=>p.miss(v).then(()=>v))})},set(n,u){return i().then(()=>{let p=s();return p[JSON.stringify(n)]={timestamp:new Date().getTime(),value:u},t().setItem(o,JSON.stringify(p)),u})},delete(n){return i().then(()=>{let u=s();delete u[JSON.stringify(n)],t().setItem(o,JSON.stringify(u));})},clear(){return Promise.resolve().then(()=>{t().removeItem(o);})}}}function ce(){return {get(e,r,o={miss:()=>Promise.resolve()}){return r().then(s=>Promise.all([s,o.miss(s)])).then(([s])=>s)},set(e,r){return Promise.resolve(r)},delete(e){return Promise.resolve()},clear(){return Promise.resolve()}}}function O(e){let r=[...e.caches],o=r.shift();return o===void 0?ce():{get(t,s,l={miss:()=>Promise.resolve()}){return o.get(t,s,l).catch(()=>O({caches:r}).get(t,s,l))},set(t,s){return o.set(t,s).catch(()=>O({caches:r}).set(t,s))},delete(t){return o.delete(t).catch(()=>O({caches:r}).delete(t))},clear(){return o.clear().catch(()=>O({caches:r}).clear())}}}function F(e={serializable:true}){let r={};return {get(o,t,s={miss:()=>Promise.resolve()}){let l=JSON.stringify(o);if(l in r)return Promise.resolve(e.serializable?JSON.parse(r[l]):r[l]);let i=t();return i.then(a=>s.miss(a)).then(()=>i)},set(o,t){return r[JSON.stringify(o)]=e.serializable?JSON.stringify(t):t,Promise.resolve(t)},delete(o){return delete r[JSON.stringify(o)],Promise.resolve()},clear(){return r={},Promise.resolve()}}}function me(e){let r={value:`Algolia for JavaScript (${e})`,add(o){let t=`; ${o.segment}${o.version!==void 0?` (${o.version})`:""}`;return r.value.indexOf(t)===-1&&(r.value=`${r.value}${t}`),r}};return r}function Y(e,r,o="WithinHeaders"){let t={"x-algolia-api-key":r,"x-algolia-application-id":e};return {headers(){return o==="WithinHeaders"?t:{}},queryParameters(){return o==="WithinQueryParameters"?t:{}}}}function Z({algoliaAgents:e,client:r,version:o}){let t=me(o).add({segment:r,version:o});return e.forEach(s=>t.add(s)),t}function ee(){return {debug(e,r){return Promise.resolve()},info(e,r){return Promise.resolve()},error(e,r){return Promise.resolve()}}}var le=10*1024*1024;async function*ue(e){let r=e.getReader();try{for(;;){let{done:o,value:t}=await r.read();if(o)return;yield t;}}finally{r.releaseLock();}}function fe(e){return Symbol.asyncIterator in e?e:ue(e)}async function*pe(e){let r=new TextDecoder("utf-8"),o=[],t=0,s=false,l=true;for await(let a of fe(e)){let n=r.decode(a,{stream:true}),u=0;for(s&&(s=false,n.length>0&&n[0]===`
`&&(u=1));u<n.length;){let p=n.indexOf("\r",u),d=n.indexOf(`
`,u);if(p===-1&&d===-1){let c=n.slice(u);if(o.push(c),t+=c.length,t>le)throw new Error("SSE line buffer exceeded 10MB");break}let x,h;p!==-1&&(d===-1||p<d)?(x=p,p+1<n.length?h=n[p+1]===`
`?2:1:(s=true,h=1)):(x=d,h=1);let v=n.slice(u,x);o.push(v);let E=o.length===1?o[0]:o.join("");o.length=0,t=0,l&&(E.startsWith("\uFEFF")&&(E=E.slice(1)),l=false),yield E,u=x+h;}}let i=r.decode();if(i&&o.push(i),o.length>0){let a=o.join("");l&&a.startsWith("\uFEFF")&&(a=a.slice(1)),yield a;}}var de=class{data=[];eventType="";lastEventId=null;retry=null;decode(e){if(e==="")return this.dispatch();if(e[0]===":")return null;let r=e.indexOf(":"),o,t;switch(r===-1?(o=e,t=""):(o=e.slice(0,r),t=e.slice(r+1),t[0]===" "&&(t=t.slice(1))),o){case "data":this.data.push(t);break;case "event":this.eventType=t;break;case "id":t.includes("\0")||(this.lastEventId=t);break;case "retry":/^[0-9]+$/.test(t)&&(this.retry=parseInt(t,10));break}return null}dispatch(){let e=this.eventType;if(this.eventType="",this.data.length===0)return null;let r={data:this.data.join(`
`),event:e,id:this.lastEventId,retry:this.retry};return this.data=[],r}};async function*he(e){let r=new de;for await(let o of pe(e)){let t=r.decode(o);t!==null&&(yield t);}}var xe=750,J=120*1e3;function G(e,r="up"){let o=Date.now();function t(){return r==="up"||Date.now()-o>J}function s(){return r==="timed out"&&Date.now()-o<=J}return {...e,status:r,lastUpdate:o,isUp:t,isTimedOut:s}}var re=class extends Error{name="AlgoliaError";constructor(e,r){super(e),r&&(this.name=r);}};var te=class extends re{stackTrace;constructor(e,r,o){super(e,o),this.stackTrace=r;}},Q=class extends te{constructor(e){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",e,"RetryError");}},U=class extends te{status;constructor(e,r,o,t="ApiError"){super(e,o,t),this.status=r;}},ge=class extends re{response;constructor(e,r){super(e,"DeserializationError"),this.response=r;}},ye=class extends U{error;constructor(e,r,o,t){super(e,r,t,"DetailedApiError"),this.error=o;}};function oe(e){let r=e;for(let o=e.length-1;o>0;o--){let t=Math.floor(Math.random()*(o+1)),s=e[o];r[o]=e[t],r[t]=s;}return r}function B(e,r,o){let t=Pe(o),s=`${e.protocol}://${e.url}${e.port?`:${e.port}`:""}/${r.charAt(0)==="/"?r.substring(1):r}`;return t.length&&(s+=`?${t}`),s}function Pe(e){return Object.keys(e).filter(r=>e[r]!==void 0).sort().map(r=>`${r}=${encodeURIComponent(Object.prototype.toString.call(e[r])==="[object Array]"?e[r].join(","):e[r]).replace(/\+/g,"%20")}`).join("&")}function V(e,r){if(e.method==="GET"||e.data===void 0&&r.data===void 0)return;let o=Array.isArray(e.data)?e.data:{...e.data,...r.data};return JSON.stringify(o)}function X(e,r,o){let t={Accept:"application/json",...e,...r,...o},s={};return Object.keys(t).forEach(l=>{let i=t[l];s[l.toLowerCase()]=i;}),s}function Te(e){if(!(e.status===204||e.content.length===0))try{return JSON.parse(e.content)}catch(r){throw new ge(r.message,e)}}function ve({content:e,status:r},o){try{let t=JSON.parse(e);return "error"in t?new ye(t.message,r,t.error,o):new U(t.message,r,o)}catch{}return new U(e,r,o)}function Ee({isTimedOut:e,status:r}){return !e&&~~r===0}function Se({isTimedOut:e,status:r}){return e||Ee({isTimedOut:e,status:r})||~~(r/100)!==2&&~~(r/100)!==4}function Re({status:e}){return ~~(e/100)===2}function we(e){return e.map(r=>ae(r))}function ae(e){let r=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...e,request:{...e.request,headers:{...e.request.headers,...r}}}}function se({hosts:e,hostsCache:r,baseHeaders:o,logger:t,baseQueryParameters:s,algoliaAgent:l,timeouts:i,requester:a,requestsCache:n,responsesCache:u,compress:p,compression:d}){async function x(c){let m=await Promise.all(c.map(f=>r.get(f,()=>Promise.resolve(G(f))))),R=m.filter(f=>f.isUp()),P=m.filter(f=>f.isTimedOut()),S=[...R,...P];return {hosts:S.length>0?S:c,getTimeout(f,w){return (P.length===0&&f===0?1:P.length+3+f)*w}}}async function h(c,m,R){let P=[],S=V(c,m),g=X(o,c.headers,m.headers),f=d==="gzip"&&S!==void 0&&S.length>xe&&(c.method==="POST"||c.method==="PUT");f&&p===void 0&&t.info("Compression is disabled because no compress method is available.");let w=f&&p!==void 0,D=w?await p(S):S;w&&(g["content-encoding"]="gzip");let I=c.method==="GET"?{...c.data,...m.data}:{},A={...s,...c.queryParameters,...I};if(l.value&&(A["x-algolia-agent"]=l.value),m&&m.queryParameters)for(let y of Object.keys(m.queryParameters))!m.queryParameters[y]||Object.prototype.toString.call(m.queryParameters[y])==="[object Object]"?A[y]=m.queryParameters[y]:A[y]=m.queryParameters[y].toString();let _=0,N=async(y,$)=>{let C=y.pop();if(C===void 0)throw new Q(we(P));let q={...i,...m.timeouts},j={data:D,headers:g,method:c.method,url:B(C,c.path,A),connectTimeout:$(_,q.connect),responseTimeout:$(_,R?q.read:q.write)},W=M=>{let z={request:j,response:M,host:C,triesLeft:y.length};return P.push(z),z},b=await a.send(j);if(Se(b)){let M=W(b);return b.isTimedOut&&_++,t.info("Retryable failure",ae(M)),await r.set(C,G(C,b.isTimedOut?"timed out":"down")),N(y,$)}if(Re(b))return Te(b);throw W(b),ve(b,P)},T=e.filter(y=>y.accept==="readWrite"||(R?y.accept==="read":y.accept==="write")),H=await x(T);return N([...H.hosts].reverse(),H.getTimeout)}function v(c,m={}){let R=()=>h(c,m,P),P=c.useReadTransporter||c.method==="GET";if((m.cacheable||c.cacheable)!==true)return R();let g={request:c,requestOptions:m,transporter:{queryParameters:s,headers:o}};return u.get(g,()=>n.get(g,()=>n.set(g,R()).then(f=>Promise.all([n.delete(g),f]),f=>Promise.all([n.delete(g),Promise.reject(f)])).then(([f,w])=>w)),{miss:f=>u.set(g,f)})}async function*E(c,m={}){if(!a.sendStream)throw new Error("This requester does not support streaming");let R=V(c,m),P=X(o,c.headers,m.headers);P.accept="text/event-stream";let S=c.method==="GET"?{...c.data,...m.data}:{},g={...s,...c.queryParameters,...S};if(l.value&&(g["x-algolia-agent"]=l.value),m&&m.queryParameters)for(let T of Object.keys(m.queryParameters))!m.queryParameters[T]||Object.prototype.toString.call(m.queryParameters[T])==="[object Object]"?g[T]=m.queryParameters[T]:g[T]=m.queryParameters[T].toString();let f=c.useReadTransporter||c.method==="GET",w=e.filter(T=>T.accept==="readWrite"||(f?T.accept==="read":T.accept==="write")),I=(await x(w)).hosts[0];if(!I)throw new Q([]);let A={...i,...m.timeouts},_={data:R,headers:P,method:c.method,url:B(I,c.path,g),connectTimeout:A.connect,responseTimeout:f?A.read:A.write},N=await a.sendStream(_);yield*he(N);}return {hostsCache:r,requester:a,timeouts:i,logger:t,algoliaAgent:l,baseHeaders:o,baseQueryParameters:s,hosts:e,request:v,requestStream:E,requestsCache:n,responsesCache:u}}function L(e,r,o){if(o==null||typeof o=="string"&&o.length===0)throw new Error(`Parameter \`${e}\` is required when calling \`${r}\`.`)}function ne(){function e(r){return new Promise(o=>{let t=new XMLHttpRequest;t.open(r.method,r.url,true),Object.keys(r.headers).forEach(a=>t.setRequestHeader(a,r.headers[a]));let s=(a,n)=>setTimeout(()=>{t.abort(),o({status:0,content:n,isTimedOut:true});},a),l=s(r.connectTimeout,"Connection timeout"),i;t.onreadystatechange=()=>{t.readyState>t.OPENED&&i===void 0&&(clearTimeout(l),i=s(r.responseTimeout,"Socket timeout"));},t.onerror=()=>{t.status===0&&(clearTimeout(l),clearTimeout(i),o({content:t.responseText||"Network request failed",status:t.status,isTimedOut:false}));},t.onload=()=>{clearTimeout(l),clearTimeout(i),o({content:t.responseText,status:t.status,isTimedOut:false});},t.send(r.data);})}return {send:e}}var k="5.55.1";function Ae(e){return [{url:`${e}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${e}.algolia.net`,accept:"write",protocol:"https"}].concat(oe([{url:`${e}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}function ie({appId:e,apiKey:r,authMode:o,algoliaAgents:t,...s}){let l=Y(e,r,o),i=se({hosts:Ae(e),...s,algoliaAgent:Z({algoliaAgents:t,client:"Lite",version:k}),baseHeaders:{"content-type":"text/plain",...l.headers(),...s.baseHeaders},baseQueryParameters:{...l.queryParameters(),...s.baseQueryParameters}});return {transporter:i,appId:e,apiKey:r,clearCache(){return Promise.all([i.requestsCache.clear(),i.responsesCache.clear()]).then(()=>{})},get _ua(){return i.algoliaAgent.value},addAlgoliaAgent(a,n){i.algoliaAgent.add({segment:a,version:n});},setClientApiKey({apiKey:a}){!o||o==="WithinHeaders"?i.baseHeaders["x-algolia-api-key"]=a:i.baseQueryParameters["x-algolia-api-key"]=a;},searchForHits(a,n){return this.search(a,n)},searchForFacets(a,n){return this.search(a,n)},customPost({path:a,parameters:n,body:u},p){L("path","customPost",a);let v={method:"POST",path:"/{path}".replace("{path}",a),queryParameters:n||{},headers:{},data:u||{}};return i.request(v,p)},getRecommendations(a,n){a&&Array.isArray(a)&&(a={requests:a}),L("getRecommendationsParams","getRecommendations",a),L("getRecommendationsParams.requests","getRecommendations",a.requests);let x={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:a,useReadTransporter:true,cacheable:true};return i.request(x,n)},search(a,n){a&&Array.isArray(a)&&(a={requests:a.map(({params:v,...E})=>E.type==="facet"?{...E,...v,type:"facet"}:{...E,...v,facet:void 0,maxFacetHits:void 0,facetQuery:void 0})}),L("searchMethodParams","search",a),L("searchMethodParams.requests","search",a.requests);let x={method:"POST",path:"/1/indexes/*/queries",queryParameters:{},headers:{},data:a,useReadTransporter:true,cacheable:true};return i.request(x,n)}}}function xo(e,r,o){if(!e||typeof e!="string")throw new Error("`appId` is missing.");if(!r||typeof r!="string")throw new Error("`apiKey` is missing.");let{compression:t,...s}=o||{};return ie({appId:e,apiKey:r,timeouts:{connect:1e3,read:2e3,write:3e4},logger:ee(),requester:ne(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:F(),requestsCache:F({serializable:false}),hostsCache:O({caches:[K({key:`${k}-${e}`}),F()]}),...s})}

	exports.apiClientVersion = k;
	exports.liteClient = xo;

}));
