@algolia/client-analytics 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.analyticsClient = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- function Q(s,t,d="WithinHeaders"){let u={"x-algolia-api-key":t,"x-algolia-application-id":s};return {headers(){return d==="WithinHeaders"?u:{}},queryParameters(){return d==="WithinQueryParameters"?u:{}}}}function I(s){let t,d=`algolia-client-js-${s.key}`;function u(){return t===void 0&&(t=s.localStorage||window.localStorage),t}function h(){return JSON.parse(u().getItem(d)||"{}")}function P(e){u().setItem(d,JSON.stringify(e));}function q(){let e=s.timeToLive?s.timeToLive*1e3:null,o=h(),n=Object.fromEntries(Object.entries(o).filter(([,l])=>l.timestamp!==void 0));if(P(n),!e)return;let i=Object.fromEntries(Object.entries(n).filter(([,l])=>{let a=new Date().getTime();return !(l.timestamp+e<a)}));P(i);}return {get(e,o,n={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(q(),h()[JSON.stringify(e)])).then(i=>Promise.all([i?i.value:o(),i!==void 0])).then(([i,l])=>Promise.all([i,l||n.miss(i)])).then(([i])=>i)},set(e,o){return Promise.resolve().then(()=>{let n=h();return n[JSON.stringify(e)]={timestamp:new Date().getTime(),value:o},u().setItem(d,JSON.stringify(n)),o})},delete(e){return Promise.resolve().then(()=>{let o=h();delete o[JSON.stringify(e)],u().setItem(d,JSON.stringify(o));})},clear(){return Promise.resolve().then(()=>{u().removeItem(d);})}}}function Y(){return {get(s,t,d={miss:()=>Promise.resolve()}){return t().then(h=>Promise.all([h,d.miss(h)])).then(([h])=>h)},set(s,t){return Promise.resolve(t)},delete(s){return Promise.resolve()},clear(){return Promise.resolve()}}}function E(s){let t=[...s.caches],d=t.shift();return d===void 0?Y():{get(u,h,P={miss:()=>Promise.resolve()}){return d.get(u,h,P).catch(()=>E({caches:t}).get(u,h,P))},set(u,h){return d.set(u,h).catch(()=>E({caches:t}).set(u,h))},delete(u){return d.delete(u).catch(()=>E({caches:t}).delete(u))},clear(){return d.clear().catch(()=>E({caches:t}).clear())}}}function G(s={serializable:!0}){let t={};return {get(d,u,h={miss:()=>Promise.resolve()}){let P=JSON.stringify(d);if(P in t)return Promise.resolve(s.serializable?JSON.parse(t[P]):t[P]);let q=u();return q.then(e=>h.miss(e)).then(()=>q)},set(d,u){return t[JSON.stringify(d)]=s.serializable?JSON.stringify(u):u,Promise.resolve(u)},delete(d){return delete t[JSON.stringify(d)],Promise.resolve()},clear(){return t={},Promise.resolve()}}}var D=2*60*1e3;function _(s,t="up"){let d=Date.now();function u(){return t==="up"||Date.now()-d>D}function h(){return t==="timed out"&&Date.now()-d<=D}return {...s,status:t,lastUpdate:d,isUp:u,isTimedOut:h}}var L=class extends Error{name="AlgoliaError";constructor(s,t){super(s),t&&(this.name=t);}},W=class extends L{stackTrace;constructor(s,t,d){super(s,d),this.stackTrace=t;}},Z=class extends W{constructor(s){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",s,"RetryError");}},N=class extends W{status;constructor(s,t,d,u="ApiError"){super(s,d,u),this.status=t;}},ee=class extends L{response;constructor(s,t){super(s,"DeserializationError"),this.response=t;}},te=class extends N{error;constructor(s,t,d,u){super(s,t,u,"DetailedApiError"),this.error=d;}};function re(s,t,d){let u=oe(d),h=`${s.protocol}://${s.url}${s.port?`:${s.port}`:""}/${t.charAt(0)==="/"?t.substring(1):t}`;return u.length&&(h+=`?${u}`),h}function oe(s){return Object.keys(s).filter(t=>s[t]!==void 0).sort().map(t=>`${t}=${encodeURIComponent(Object.prototype.toString.call(s[t])==="[object Array]"?s[t].join(","):s[t]).replaceAll("+","%20")}`).join("&")}function se(s,t){if(s.method==="GET"||s.data===void 0&&t.data===void 0)return;let d=Array.isArray(s.data)?s.data:{...s.data,...t.data};return JSON.stringify(d)}function ne(s,t,d){let u={Accept:"application/json",...s,...t,...d},h={};return Object.keys(u).forEach(P=>{let q=u[P];h[P.toLowerCase()]=q;}),h}function ie(s){try{return JSON.parse(s.content)}catch(t){throw new ee(t.message,s)}}function ae({content:s,status:t},d){try{let u=JSON.parse(s);return "error"in u?new te(u.message,t,u.error,d):new N(u.message,t,d)}catch{}return new N(s,t,d)}function ue({isTimedOut:s,status:t}){return !s&&~~t===0}function ce({isTimedOut:s,status:t}){return s||ue({isTimedOut:s,status:t})||~~(t/100)!==2&&~~(t/100)!==4}function de({status:s}){return ~~(s/100)===2}function le(s){return s.map(t=>j(t))}function j(s){let t=s.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...s,request:{...s.request,headers:{...s.request.headers,...t}}}}function J({hosts:s,hostsCache:t,baseHeaders:d,baseQueryParameters:u,algoliaAgent:h,timeouts:P,requester:q,requestsCache:e,responsesCache:o}){async function n(a){let c=await Promise.all(a.map(g=>t.get(g,()=>Promise.resolve(_(g))))),r=c.filter(g=>g.isUp()),p=c.filter(g=>g.isTimedOut()),f=[...r,...p];return {hosts:f.length>0?f:a,getTimeout(g,R){return (p.length===0&&g===0?1:p.length+3+g)*R}}}async function i(a,c,r=!0){let p=[],f=se(a,c),m=ne(d,a.headers,c.headers),g=a.method==="GET"?{...a.data,...c.data}:{},R={...u,...a.queryParameters,...g};if(h.value&&(R["x-algolia-agent"]=h.value),c&&c.queryParameters)for(let y of Object.keys(c.queryParameters))!c.queryParameters[y]||Object.prototype.toString.call(c.queryParameters[y])==="[object Object]"?R[y]=c.queryParameters[y]:R[y]=c.queryParameters[y].toString();let S=0,C=async(y,A)=>{let w=y.pop();if(w===void 0)throw new Z(le(p));let x={...P,...c.timeouts},H={data:f,headers:m,method:a.method,url:re(w,a.path,R),connectTimeout:A(S,x.connect),responseTimeout:A(S,r?x.read:x.write)},F=O=>{let U={request:H,response:O,host:w,triesLeft:y.length};return p.push(U),U},T=await q.send(H);if(ce(T)){let O=F(T);return T.isTimedOut&&S++,console.log("Retryable failure",j(O)),await t.set(w,_(w,T.isTimedOut?"timed out":"down")),C(y,A)}if(de(T))return ie(T);throw F(T),ae(T,p)},V=s.filter(y=>y.accept==="readWrite"||(r?y.accept==="read":y.accept==="write")),b=await n(V);return C([...b.hosts].reverse(),b.getTimeout)}function l(a,c={}){let r=a.useReadTransporter||a.method==="GET";if(!r)return i(a,c,r);let p=()=>i(a,c);if((c.cacheable||a.cacheable)!==!0)return p();let m={request:a,requestOptions:c,transporter:{queryParameters:u,headers:d}};return o.get(m,()=>e.get(m,()=>e.set(m,p()).then(g=>Promise.all([e.delete(m),g]),g=>Promise.all([e.delete(m),Promise.reject(g)])).then(([g,R])=>R)),{miss:g=>o.set(m,g)})}return {hostsCache:t,requester:q,timeouts:P,algoliaAgent:h,baseHeaders:d,baseQueryParameters:u,hosts:s,request:l,requestsCache:e,responsesCache:o}}function pe(s){let t={value:`Algolia for JavaScript (${s})`,add(d){let u=`; ${d.segment}${d.version!==void 0?` (${d.version})`:""}`;return t.value.indexOf(u)===-1&&(t.value=`${t.value}${u}`),t}};return t}function $({algoliaAgents:s,client:t,version:d}){let u=pe(d).add({segment:t,version:d});return s.forEach(h=>u.add(h)),u}var M=1e3,z=2e3,B=3e4;function X(){function s(t){return new Promise(d=>{let u=new XMLHttpRequest;u.open(t.method,t.url,!0),Object.keys(t.headers).forEach(e=>u.setRequestHeader(e,t.headers[e]));let h=(e,o)=>setTimeout(()=>{u.abort(),d({status:0,content:o,isTimedOut:!0});},e),P=h(t.connectTimeout,"Connection timeout"),q;u.onreadystatechange=()=>{u.readyState>u.OPENED&&q===void 0&&(clearTimeout(P),q=h(t.responseTimeout,"Socket timeout"));},u.onerror=()=>{u.status===0&&(clearTimeout(P),clearTimeout(q),d({content:u.responseText||"Network request failed",status:u.status,isTimedOut:!1}));},u.onload=()=>{clearTimeout(P),clearTimeout(q),d({content:u.responseText,status:u.status,isTimedOut:!1});},u.send(t.data);})}return {send:s}}var v="5.3.0",k=["de","us"];function fe(s){return [{url:s?"analytics.{region}.algolia.com".replace("{region}",s):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function K({appId:s,apiKey:t,authMode:d,algoliaAgents:u,region:h,...P}){let q=Q(s,t,d);return {transporter:J({hosts:fe(h),...P,algoliaAgent:$({algoliaAgents:u,client:"Analytics",version:v}),baseHeaders:{"content-type":"text/plain",...q.headers(),...P.baseHeaders},baseQueryParameters:{...q.queryParameters(),...P.baseQueryParameters}}),appId:s,clearCache(){return Promise.all([this.transporter.requestsCache.clear(),this.transporter.responsesCache.clear()]).then(()=>{})},get _ua(){return this.transporter.algoliaAgent.value},addAlgoliaAgent(e,o){this.transporter.algoliaAgent.add({segment:e,version:o});},setClientApiKey({apiKey:e}){this.transporter.baseHeaders["x-algolia-api-key"]=e;},customDelete({path:e,parameters:o},n){if(!e)throw new Error("Parameter `path` is required when calling `customDelete`.");let c={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:o||{},headers:{}};return this.transporter.request(c,n)},customGet({path:e,parameters:o},n){if(!e)throw new Error("Parameter `path` is required when calling `customGet`.");let c={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:o||{},headers:{}};return this.transporter.request(c,n)},customPost({path:e,parameters:o,body:n},i){if(!e)throw new Error("Parameter `path` is required when calling `customPost`.");let r={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:o||{},headers:{},data:n||{}};return this.transporter.request(r,i)},customPut({path:e,parameters:o,body:n},i){if(!e)throw new Error("Parameter `path` is required when calling `customPut`.");let r={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:o||{},headers:{},data:n||{}};return this.transporter.request(r,i)},getAddToCartRate({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getAddToCartRate`.");let a="/2/conversions/addToCartRate",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getAverageClickPosition({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getAverageClickPosition`.");let a="/2/clicks/averageClickPosition",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getClickPositions({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getClickPositions`.");let a="/2/clicks/positions",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getClickThroughRate({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getClickThroughRate`.");let a="/2/clicks/clickThroughRate",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getConversionRate({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getConversionRate`.");let a="/2/conversions/conversionRate",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getNoClickRate({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getNoClickRate`.");let a="/2/searches/noClickRate",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getNoResultsRate({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getNoResultsRate`.");let a="/2/searches/noResultRate",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getPurchaseRate({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getPurchaseRate`.");let a="/2/conversions/purchaseRate",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getRevenue({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getRevenue`.");let a="/2/conversions/revenue",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getSearchesCount({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesCount`.");let a="/2/searches/count",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)},getSearchesNoClicks({index:e,startDate:o,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesNoClicks`.");let r="/2/searches/noClicks",p={},f={};e!==void 0&&(f.index=e.toString()),o!==void 0&&(f.startDate=o.toString()),n!==void 0&&(f.endDate=n.toString()),i!==void 0&&(f.limit=i.toString()),l!==void 0&&(f.offset=l.toString()),a!==void 0&&(f.tags=a.toString());let m={method:"GET",path:r,queryParameters:f,headers:p};return this.transporter.request(m,c)},getSearchesNoResults({index:e,startDate:o,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesNoResults`.");let r="/2/searches/noResults",p={},f={};e!==void 0&&(f.index=e.toString()),o!==void 0&&(f.startDate=o.toString()),n!==void 0&&(f.endDate=n.toString()),i!==void 0&&(f.limit=i.toString()),l!==void 0&&(f.offset=l.toString()),a!==void 0&&(f.tags=a.toString());let m={method:"GET",path:r,queryParameters:f,headers:p};return this.transporter.request(m,c)},getStatus({index:e},o){if(!e)throw new Error("Parameter `index` is required when calling `getStatus`.");let n="/2/status",i={},l={};e!==void 0&&(l.index=e.toString());let a={method:"GET",path:n,queryParameters:l,headers:i};return this.transporter.request(a,o)},getTopCountries({index:e,startDate:o,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getTopCountries`.");let r="/2/countries",p={},f={};e!==void 0&&(f.index=e.toString()),o!==void 0&&(f.startDate=o.toString()),n!==void 0&&(f.endDate=n.toString()),i!==void 0&&(f.limit=i.toString()),l!==void 0&&(f.offset=l.toString()),a!==void 0&&(f.tags=a.toString());let m={method:"GET",path:r,queryParameters:f,headers:p};return this.transporter.request(m,c)},getTopFilterAttributes({index:e,search:o,startDate:n,endDate:i,limit:l,offset:a,tags:c},r){if(!e)throw new Error("Parameter `index` is required when calling `getTopFilterAttributes`.");let p="/2/filters",f={},m={};e!==void 0&&(m.index=e.toString()),o!==void 0&&(m.search=o.toString()),n!==void 0&&(m.startDate=n.toString()),i!==void 0&&(m.endDate=i.toString()),l!==void 0&&(m.limit=l.toString()),a!==void 0&&(m.offset=a.toString()),c!==void 0&&(m.tags=c.toString());let g={method:"GET",path:p,queryParameters:m,headers:f};return this.transporter.request(g,r)},getTopFilterForAttribute({attribute:e,index:o,search:n,startDate:i,endDate:l,limit:a,offset:c,tags:r},p){if(!e)throw new Error("Parameter `attribute` is required when calling `getTopFilterForAttribute`.");if(!o)throw new Error("Parameter `index` is required when calling `getTopFilterForAttribute`.");let f="/2/filters/{attribute}".replace("{attribute}",encodeURIComponent(e)),m={},g={};o!==void 0&&(g.index=o.toString()),n!==void 0&&(g.search=n.toString()),i!==void 0&&(g.startDate=i.toString()),l!==void 0&&(g.endDate=l.toString()),a!==void 0&&(g.limit=a.toString()),c!==void 0&&(g.offset=c.toString()),r!==void 0&&(g.tags=r.toString());let R={method:"GET",path:f,queryParameters:g,headers:m};return this.transporter.request(R,p)},getTopFiltersNoResults({index:e,search:o,startDate:n,endDate:i,limit:l,offset:a,tags:c},r){if(!e)throw new Error("Parameter `index` is required when calling `getTopFiltersNoResults`.");let p="/2/filters/noResults",f={},m={};e!==void 0&&(m.index=e.toString()),o!==void 0&&(m.search=o.toString()),n!==void 0&&(m.startDate=n.toString()),i!==void 0&&(m.endDate=i.toString()),l!==void 0&&(m.limit=l.toString()),a!==void 0&&(m.offset=a.toString()),c!==void 0&&(m.tags=c.toString());let g={method:"GET",path:p,queryParameters:m,headers:f};return this.transporter.request(g,r)},getTopHits({index:e,search:o,clickAnalytics:n,revenueAnalytics:i,startDate:l,endDate:a,limit:c,offset:r,tags:p},f){if(!e)throw new Error("Parameter `index` is required when calling `getTopHits`.");let m="/2/hits",g={},R={};e!==void 0&&(R.index=e.toString()),o!==void 0&&(R.search=o.toString()),n!==void 0&&(R.clickAnalytics=n.toString()),i!==void 0&&(R.revenueAnalytics=i.toString()),l!==void 0&&(R.startDate=l.toString()),a!==void 0&&(R.endDate=a.toString()),c!==void 0&&(R.limit=c.toString()),r!==void 0&&(R.offset=r.toString()),p!==void 0&&(R.tags=p.toString());let S={method:"GET",path:m,queryParameters:R,headers:g};return this.transporter.request(S,f)},getTopSearches({index:e,clickAnalytics:o,revenueAnalytics:n,startDate:i,endDate:l,orderBy:a,direction:c,limit:r,offset:p,tags:f},m){if(!e)throw new Error("Parameter `index` is required when calling `getTopSearches`.");let g="/2/searches",R={},S={};e!==void 0&&(S.index=e.toString()),o!==void 0&&(S.clickAnalytics=o.toString()),n!==void 0&&(S.revenueAnalytics=n.toString()),i!==void 0&&(S.startDate=i.toString()),l!==void 0&&(S.endDate=l.toString()),a!==void 0&&(S.orderBy=a.toString()),c!==void 0&&(S.direction=c.toString()),r!==void 0&&(S.limit=r.toString()),p!==void 0&&(S.offset=p.toString()),f!==void 0&&(S.tags=f.toString());let C={method:"GET",path:g,queryParameters:S,headers:R};return this.transporter.request(C,m)},getUsersCount({index:e,startDate:o,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getUsersCount`.");let a="/2/users/count",c={},r={};e!==void 0&&(r.index=e.toString()),o!==void 0&&(r.startDate=o.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let p={method:"GET",path:a,queryParameters:r,headers:c};return this.transporter.request(p,l)}}}function Nt(s,t,d,u){if(!s||typeof s!="string")throw new Error("`appId` is missing.");if(!t||typeof t!="string")throw new Error("`apiKey` is missing.");if(d&&(typeof d!="string"||!k.includes(d)))throw new Error(`\`region\` must be one of the following: ${k.join(", ")}`);return K({appId:s,apiKey:t,region:d,timeouts:{connect:M,read:z,write:B},requester:X(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:G(),requestsCache:G({serializable:!1}),hostsCache:E({caches:[I({key:`${v}-${s}`}),G()]}),...u})}
7
+ function I(o,r,d="WithinHeaders"){let c={"x-algolia-api-key":r,"x-algolia-application-id":o};return {headers(){return d==="WithinHeaders"?c:{}},queryParameters(){return d==="WithinQueryParameters"?c:{}}}}function L(o){let r,d=`algolia-client-js-${o.key}`;function c(){return r===void 0&&(r=o.localStorage||window.localStorage),r}function g(){return JSON.parse(c().getItem(d)||"{}")}function R(f){c().setItem(d,JSON.stringify(f));}function q(){let f=o.timeToLive?o.timeToLive*1e3:null,e=g(),s=Object.fromEntries(Object.entries(e).filter(([,i])=>i.timestamp!==void 0));if(R(s),!f)return;let n=Object.fromEntries(Object.entries(s).filter(([,i])=>{let a=new Date().getTime();return !(i.timestamp+f<a)}));R(n);}return {get(f,e,s={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(q(),g()[JSON.stringify(f)])).then(n=>Promise.all([n?n.value:e(),n!==void 0])).then(([n,i])=>Promise.all([n,i||s.miss(n)])).then(([n])=>n)},set(f,e){return Promise.resolve().then(()=>{let s=g();return s[JSON.stringify(f)]={timestamp:new Date().getTime(),value:e},c().setItem(d,JSON.stringify(s)),e})},delete(f){return Promise.resolve().then(()=>{let e=g();delete e[JSON.stringify(f)],c().setItem(d,JSON.stringify(e));})},clear(){return Promise.resolve().then(()=>{c().removeItem(d);})}}}function Y(){return {get(o,r,d={miss:()=>Promise.resolve()}){return r().then(g=>Promise.all([g,d.miss(g)])).then(([g])=>g)},set(o,r){return Promise.resolve(r)},delete(o){return Promise.resolve()},clear(){return Promise.resolve()}}}function w(o){let r=[...o.caches],d=r.shift();return d===void 0?Y():{get(c,g,R={miss:()=>Promise.resolve()}){return d.get(c,g,R).catch(()=>w({caches:r}).get(c,g,R))},set(c,g){return d.set(c,g).catch(()=>w({caches:r}).set(c,g))},delete(c){return d.delete(c).catch(()=>w({caches:r}).delete(c))},clear(){return d.clear().catch(()=>w({caches:r}).clear())}}}function G(o={serializable:!0}){let r={};return {get(d,c,g={miss:()=>Promise.resolve()}){let R=JSON.stringify(d);if(R in r)return Promise.resolve(o.serializable?JSON.parse(r[R]):r[R]);let q=c();return q.then(f=>g.miss(f)).then(()=>q)},set(d,c){return r[JSON.stringify(d)]=o.serializable?JSON.stringify(c):c,Promise.resolve(c)},delete(d){return delete r[JSON.stringify(d)],Promise.resolve()},clear(){return r={},Promise.resolve()}}}var _=2*60*1e3;function Q(o,r="up"){let d=Date.now();function c(){return r==="up"||Date.now()-d>_}function g(){return r==="timed out"&&Date.now()-d<=_}return {...o,status:r,lastUpdate:d,isUp:c,isTimedOut:g}}var W=class extends Error{name="AlgoliaError";constructor(o,r){super(o),r&&(this.name=r);}},j=class extends W{stackTrace;constructor(o,r,d){super(o,d),this.stackTrace=r;}},Z=class extends j{constructor(o){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",o,"RetryError");}},k=class extends j{status;constructor(o,r,d,c="ApiError"){super(o,d,c),this.status=r;}},ee=class extends W{response;constructor(o,r){super(o,"DeserializationError"),this.response=r;}},te=class extends k{error;constructor(o,r,d,c){super(o,r,c,"DetailedApiError"),this.error=d;}};function re(o,r,d){let c=oe(d),g=`${o.protocol}://${o.url}${o.port?`:${o.port}`:""}/${r.charAt(0)==="/"?r.substring(1):r}`;return c.length&&(g+=`?${c}`),g}function oe(o){return Object.keys(o).filter(r=>o[r]!==void 0).sort().map(r=>`${r}=${encodeURIComponent(Object.prototype.toString.call(o[r])==="[object Array]"?o[r].join(","):o[r]).replaceAll("+","%20")}`).join("&")}function se(o,r){if(o.method==="GET"||o.data===void 0&&r.data===void 0)return;let d=Array.isArray(o.data)?o.data:{...o.data,...r.data};return JSON.stringify(d)}function ne(o,r,d){let c={Accept:"application/json",...o,...r,...d},g={};return Object.keys(c).forEach(R=>{let q=c[R];g[R.toLowerCase()]=q;}),g}function ie(o){try{return JSON.parse(o.content)}catch(r){throw new ee(r.message,o)}}function ae({content:o,status:r},d){try{let c=JSON.parse(o);return "error"in c?new te(c.message,r,c.error,d):new k(c.message,r,d)}catch{}return new k(o,r,d)}function ue({isTimedOut:o,status:r}){return !o&&~~r===0}function ce({isTimedOut:o,status:r}){return o||ue({isTimedOut:o,status:r})||~~(r/100)!==2&&~~(r/100)!==4}function de({status:o}){return ~~(o/100)===2}function le(o){return o.map(r=>J(r))}function J(o){let r=o.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...o,request:{...o.request,headers:{...o.request.headers,...r}}}}function $({hosts:o,hostsCache:r,baseHeaders:d,baseQueryParameters:c,algoliaAgent:g,timeouts:R,requester:q,requestsCache:f,responsesCache:e}){async function s(a){let u=await Promise.all(a.map(m=>r.get(m,()=>Promise.resolve(Q(m))))),l=u.filter(m=>m.isUp()),t=u.filter(m=>m.isTimedOut()),p=[...l,...t];return {hosts:p.length>0?p:a,getTimeout(m,P){return (t.length===0&&m===0?1:t.length+3+m)*P}}}async function n(a,u,l=!0){let t=[],p=se(a,u),h=ne(d,a.headers,u.headers),m=a.method==="GET"?{...a.data,...u.data}:{},P={...c,...a.queryParameters,...m};if(g.value&&(P["x-algolia-agent"]=g.value),u&&u.queryParameters)for(let T of Object.keys(u.queryParameters))!u.queryParameters[T]||Object.prototype.toString.call(u.queryParameters[T])==="[object Object]"?P[T]=u.queryParameters[T]:P[T]=u.queryParameters[T].toString();let S=0,y=async(T,x)=>{let C=T.pop();if(C===void 0)throw new Z(le(t));let O={...R,...u.timeouts},F={data:p,headers:h,method:a.method,url:re(C,a.path,P),connectTimeout:x(S,O.connect),responseTimeout:x(S,l?O.read:O.write)},U=N=>{let D={request:F,response:N,host:C,triesLeft:T.length};return t.push(D),D},E=await q.send(F);if(ce(E)){let N=U(E);return E.isTimedOut&&S++,console.log("Retryable failure",J(N)),await r.set(C,Q(C,E.isTimedOut?"timed out":"down")),y(T,x)}if(de(E))return ie(E);throw U(E),ae(E,t)},A=o.filter(T=>T.accept==="readWrite"||(l?T.accept==="read":T.accept==="write")),H=await s(A);return y([...H.hosts].reverse(),H.getTimeout)}function i(a,u={}){let l=a.useReadTransporter||a.method==="GET";if(!l)return n(a,u,l);let t=()=>n(a,u);if((u.cacheable||a.cacheable)!==!0)return t();let h={request:a,requestOptions:u,transporter:{queryParameters:c,headers:d}};return e.get(h,()=>f.get(h,()=>f.set(h,t()).then(m=>Promise.all([f.delete(h),m]),m=>Promise.all([f.delete(h),Promise.reject(m)])).then(([m,P])=>P)),{miss:m=>e.set(h,m)})}return {hostsCache:r,requester:q,timeouts:R,algoliaAgent:g,baseHeaders:d,baseQueryParameters:c,hosts:o,request:i,requestsCache:f,responsesCache:e}}function fe(o){let r={value:`Algolia for JavaScript (${o})`,add(d){let c=`; ${d.segment}${d.version!==void 0?` (${d.version})`:""}`;return r.value.indexOf(c)===-1&&(r.value=`${r.value}${c}`),r}};return r}function M({algoliaAgents:o,client:r,version:d}){let c=fe(d).add({segment:r,version:d});return o.forEach(g=>c.add(g)),c}var z=1e3,B=2e3,X=3e4;function K(){function o(r){return new Promise(d=>{let c=new XMLHttpRequest;c.open(r.method,r.url,!0),Object.keys(r.headers).forEach(f=>c.setRequestHeader(f,r.headers[f]));let g=(f,e)=>setTimeout(()=>{c.abort(),d({status:0,content:e,isTimedOut:!0});},f),R=g(r.connectTimeout,"Connection timeout"),q;c.onreadystatechange=()=>{c.readyState>c.OPENED&&q===void 0&&(clearTimeout(R),q=g(r.responseTimeout,"Socket timeout"));},c.onerror=()=>{c.status===0&&(clearTimeout(R),clearTimeout(q),d({content:c.responseText||"Network request failed",status:c.status,isTimedOut:!1}));},c.onload=()=>{clearTimeout(R),clearTimeout(q),d({content:c.responseText,status:c.status,isTimedOut:!1});},c.send(r.data);})}return {send:o}}var v="5.3.2",b=["de","us"];function me(o){return [{url:o?"analytics.{region}.algolia.com".replace("{region}",o):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function V({appId:o,apiKey:r,authMode:d,algoliaAgents:c,region:g,...R}){let q=I(o,r,d),f=$({hosts:me(g),...R,algoliaAgent:M({algoliaAgents:c,client:"Analytics",version:v}),baseHeaders:{"content-type":"text/plain",...q.headers(),...R.baseHeaders},baseQueryParameters:{...q.queryParameters(),...R.baseQueryParameters}});return {transporter:f,appId:o,clearCache(){return Promise.all([f.requestsCache.clear(),f.responsesCache.clear()]).then(()=>{})},get _ua(){return f.algoliaAgent.value},addAlgoliaAgent(e,s){f.algoliaAgent.add({segment:e,version:s});},setClientApiKey({apiKey:e}){!d||d==="WithinHeaders"?f.baseHeaders["x-algolia-api-key"]=e:f.baseQueryParameters["x-algolia-api-key"]=e;},customDelete({path:e,parameters:s},n){if(!e)throw new Error("Parameter `path` is required when calling `customDelete`.");let l={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{}};return f.request(l,n)},customGet({path:e,parameters:s},n){if(!e)throw new Error("Parameter `path` is required when calling `customGet`.");let l={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{}};return f.request(l,n)},customPost({path:e,parameters:s,body:n},i){if(!e)throw new Error("Parameter `path` is required when calling `customPost`.");let t={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{},data:n||{}};return f.request(t,i)},customPut({path:e,parameters:s,body:n},i){if(!e)throw new Error("Parameter `path` is required when calling `customPut`.");let t={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{},data:n||{}};return f.request(t,i)},getAddToCartRate({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getAddToCartRate`.");let u="/2/conversions/addToCartRate",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getAverageClickPosition({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getAverageClickPosition`.");let u="/2/clicks/averageClickPosition",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getClickPositions({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getClickPositions`.");let u="/2/clicks/positions",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getClickThroughRate({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getClickThroughRate`.");let u="/2/clicks/clickThroughRate",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getConversionRate({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getConversionRate`.");let u="/2/conversions/conversionRate",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getNoClickRate({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getNoClickRate`.");let u="/2/searches/noClickRate",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getNoResultsRate({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getNoResultsRate`.");let u="/2/searches/noResultRate",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getPurchaseRate({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getPurchaseRate`.");let u="/2/conversions/purchaseRate",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getRevenue({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getRevenue`.");let u="/2/conversions/revenue",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getSearchesCount({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesCount`.");let u="/2/searches/count",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)},getSearchesNoClicks({index:e,startDate:s,endDate:n,limit:i,offset:a,tags:u},l){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesNoClicks`.");let t="/2/searches/noClicks",p={},h={};e!==void 0&&(h.index=e.toString()),s!==void 0&&(h.startDate=s.toString()),n!==void 0&&(h.endDate=n.toString()),i!==void 0&&(h.limit=i.toString()),a!==void 0&&(h.offset=a.toString()),u!==void 0&&(h.tags=u.toString());let m={method:"GET",path:t,queryParameters:h,headers:p};return f.request(m,l)},getSearchesNoResults({index:e,startDate:s,endDate:n,limit:i,offset:a,tags:u},l){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesNoResults`.");let t="/2/searches/noResults",p={},h={};e!==void 0&&(h.index=e.toString()),s!==void 0&&(h.startDate=s.toString()),n!==void 0&&(h.endDate=n.toString()),i!==void 0&&(h.limit=i.toString()),a!==void 0&&(h.offset=a.toString()),u!==void 0&&(h.tags=u.toString());let m={method:"GET",path:t,queryParameters:h,headers:p};return f.request(m,l)},getStatus({index:e},s){if(!e)throw new Error("Parameter `index` is required when calling `getStatus`.");let n="/2/status",i={},a={};e!==void 0&&(a.index=e.toString());let u={method:"GET",path:n,queryParameters:a,headers:i};return f.request(u,s)},getTopCountries({index:e,startDate:s,endDate:n,limit:i,offset:a,tags:u},l){if(!e)throw new Error("Parameter `index` is required when calling `getTopCountries`.");let t="/2/countries",p={},h={};e!==void 0&&(h.index=e.toString()),s!==void 0&&(h.startDate=s.toString()),n!==void 0&&(h.endDate=n.toString()),i!==void 0&&(h.limit=i.toString()),a!==void 0&&(h.offset=a.toString()),u!==void 0&&(h.tags=u.toString());let m={method:"GET",path:t,queryParameters:h,headers:p};return f.request(m,l)},getTopFilterAttributes({index:e,search:s,startDate:n,endDate:i,limit:a,offset:u,tags:l},t){if(!e)throw new Error("Parameter `index` is required when calling `getTopFilterAttributes`.");let p="/2/filters",h={},m={};e!==void 0&&(m.index=e.toString()),s!==void 0&&(m.search=s.toString()),n!==void 0&&(m.startDate=n.toString()),i!==void 0&&(m.endDate=i.toString()),a!==void 0&&(m.limit=a.toString()),u!==void 0&&(m.offset=u.toString()),l!==void 0&&(m.tags=l.toString());let P={method:"GET",path:p,queryParameters:m,headers:h};return f.request(P,t)},getTopFilterForAttribute({attribute:e,index:s,search:n,startDate:i,endDate:a,limit:u,offset:l,tags:t},p){if(!e)throw new Error("Parameter `attribute` is required when calling `getTopFilterForAttribute`.");if(!s)throw new Error("Parameter `index` is required when calling `getTopFilterForAttribute`.");let h="/2/filters/{attribute}".replace("{attribute}",encodeURIComponent(e)),m={},P={};s!==void 0&&(P.index=s.toString()),n!==void 0&&(P.search=n.toString()),i!==void 0&&(P.startDate=i.toString()),a!==void 0&&(P.endDate=a.toString()),u!==void 0&&(P.limit=u.toString()),l!==void 0&&(P.offset=l.toString()),t!==void 0&&(P.tags=t.toString());let S={method:"GET",path:h,queryParameters:P,headers:m};return f.request(S,p)},getTopFiltersNoResults({index:e,search:s,startDate:n,endDate:i,limit:a,offset:u,tags:l},t){if(!e)throw new Error("Parameter `index` is required when calling `getTopFiltersNoResults`.");let p="/2/filters/noResults",h={},m={};e!==void 0&&(m.index=e.toString()),s!==void 0&&(m.search=s.toString()),n!==void 0&&(m.startDate=n.toString()),i!==void 0&&(m.endDate=i.toString()),a!==void 0&&(m.limit=a.toString()),u!==void 0&&(m.offset=u.toString()),l!==void 0&&(m.tags=l.toString());let P={method:"GET",path:p,queryParameters:m,headers:h};return f.request(P,t)},getTopHits({index:e,search:s,clickAnalytics:n,revenueAnalytics:i,startDate:a,endDate:u,limit:l,offset:t,tags:p},h){if(!e)throw new Error("Parameter `index` is required when calling `getTopHits`.");let m="/2/hits",P={},S={};e!==void 0&&(S.index=e.toString()),s!==void 0&&(S.search=s.toString()),n!==void 0&&(S.clickAnalytics=n.toString()),i!==void 0&&(S.revenueAnalytics=i.toString()),a!==void 0&&(S.startDate=a.toString()),u!==void 0&&(S.endDate=u.toString()),l!==void 0&&(S.limit=l.toString()),t!==void 0&&(S.offset=t.toString()),p!==void 0&&(S.tags=p.toString());let y={method:"GET",path:m,queryParameters:S,headers:P};return f.request(y,h)},getTopSearches({index:e,clickAnalytics:s,revenueAnalytics:n,startDate:i,endDate:a,orderBy:u,direction:l,limit:t,offset:p,tags:h},m){if(!e)throw new Error("Parameter `index` is required when calling `getTopSearches`.");let P="/2/searches",S={},y={};e!==void 0&&(y.index=e.toString()),s!==void 0&&(y.clickAnalytics=s.toString()),n!==void 0&&(y.revenueAnalytics=n.toString()),i!==void 0&&(y.startDate=i.toString()),a!==void 0&&(y.endDate=a.toString()),u!==void 0&&(y.orderBy=u.toString()),l!==void 0&&(y.direction=l.toString()),t!==void 0&&(y.limit=t.toString()),p!==void 0&&(y.offset=p.toString()),h!==void 0&&(y.tags=h.toString());let A={method:"GET",path:P,queryParameters:y,headers:S};return f.request(A,m)},getUsersCount({index:e,startDate:s,endDate:n,tags:i},a){if(!e)throw new Error("Parameter `index` is required when calling `getUsersCount`.");let u="/2/users/count",l={},t={};e!==void 0&&(t.index=e.toString()),s!==void 0&&(t.startDate=s.toString()),n!==void 0&&(t.endDate=n.toString()),i!==void 0&&(t.tags=i.toString());let p={method:"GET",path:u,queryParameters:t,headers:l};return f.request(p,a)}}}function Nt(o,r,d,c){if(!o||typeof o!="string")throw new Error("`appId` is missing.");if(!r||typeof r!="string")throw new Error("`apiKey` is missing.");if(d&&(typeof d!="string"||!b.includes(d)))throw new Error(`\`region\` must be one of the following: ${b.join(", ")}`);return V({appId:o,apiKey:r,region:d,timeouts:{connect:z,read:B,write:X},requester:K(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:G(),requestsCache:G({serializable:!1}),hostsCache:w({caches:[L({key:`${v}-${o}`}),G()]}),...c})}
8
8
 
9
9
  exports.analyticsClient = Nt;
10
10
  exports.apiClientVersion = v;
@@ -29,7 +29,7 @@ var import_requester_node_http = require("@algolia/requester-node-http");
29
29
 
30
30
  // src/analyticsClient.ts
31
31
  var import_client_common = require("@algolia/client-common");
32
- var apiClientVersion = "5.3.0";
32
+ var apiClientVersion = "5.3.2";
33
33
  var REGIONS = ["de", "us"];
34
34
  function getDefaultHosts(region) {
35
35
  const url = !region ? "analytics.algolia.com" : "analytics.{region}.algolia.com".replace("{region}", region);
@@ -44,25 +44,26 @@ function createAnalyticsClient({
44
44
  ...options
45
45
  }) {
46
46
  const auth = (0, import_client_common.createAuth)(appIdOption, apiKeyOption, authMode);
47
- return {
48
- transporter: (0, import_client_common.createTransporter)({
49
- hosts: getDefaultHosts(regionOption),
50
- ...options,
51
- algoliaAgent: (0, import_client_common.getAlgoliaAgent)({
52
- algoliaAgents,
53
- client: "Analytics",
54
- version: apiClientVersion
55
- }),
56
- baseHeaders: {
57
- "content-type": "text/plain",
58
- ...auth.headers(),
59
- ...options.baseHeaders
60
- },
61
- baseQueryParameters: {
62
- ...auth.queryParameters(),
63
- ...options.baseQueryParameters
64
- }
47
+ const transporter = (0, import_client_common.createTransporter)({
48
+ hosts: getDefaultHosts(regionOption),
49
+ ...options,
50
+ algoliaAgent: (0, import_client_common.getAlgoliaAgent)({
51
+ algoliaAgents,
52
+ client: "Analytics",
53
+ version: apiClientVersion
65
54
  }),
55
+ baseHeaders: {
56
+ "content-type": "text/plain",
57
+ ...auth.headers(),
58
+ ...options.baseHeaders
59
+ },
60
+ baseQueryParameters: {
61
+ ...auth.queryParameters(),
62
+ ...options.baseQueryParameters
63
+ }
64
+ });
65
+ return {
66
+ transporter,
66
67
  /**
67
68
  * The `appId` currently in use.
68
69
  */
@@ -71,15 +72,13 @@ function createAnalyticsClient({
71
72
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
72
73
  */
73
74
  clearCache() {
74
- return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
75
- () => void 0
76
- );
75
+ return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
77
76
  },
78
77
  /**
79
78
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
80
79
  */
81
80
  get _ua() {
82
- return this.transporter.algoliaAgent.value;
81
+ return transporter.algoliaAgent.value;
83
82
  },
84
83
  /**
85
84
  * Adds a `segment` to the `x-algolia-agent` sent with every requests.
@@ -88,7 +87,7 @@ function createAnalyticsClient({
88
87
  * @param version - The version of the agent.
89
88
  */
90
89
  addAlgoliaAgent(segment, version) {
91
- this.transporter.algoliaAgent.add({ segment, version });
90
+ transporter.algoliaAgent.add({ segment, version });
92
91
  },
93
92
  /**
94
93
  * Helper method to switch the API key used to authenticate the requests.
@@ -97,7 +96,11 @@ function createAnalyticsClient({
97
96
  * @param params.apiKey - The new API Key to use.
98
97
  */
99
98
  setClientApiKey({ apiKey }) {
100
- this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
99
+ if (!authMode || authMode === "WithinHeaders") {
100
+ transporter.baseHeaders["x-algolia-api-key"] = apiKey;
101
+ } else {
102
+ transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
103
+ }
101
104
  },
102
105
  /**
103
106
  * This method allow you to send requests to the Algolia REST API.
@@ -120,7 +123,7 @@ function createAnalyticsClient({
120
123
  queryParameters,
121
124
  headers
122
125
  };
123
- return this.transporter.request(request, requestOptions);
126
+ return transporter.request(request, requestOptions);
124
127
  },
125
128
  /**
126
129
  * This method allow you to send requests to the Algolia REST API.
@@ -143,7 +146,7 @@ function createAnalyticsClient({
143
146
  queryParameters,
144
147
  headers
145
148
  };
146
- return this.transporter.request(request, requestOptions);
149
+ return transporter.request(request, requestOptions);
147
150
  },
148
151
  /**
149
152
  * This method allow you to send requests to the Algolia REST API.
@@ -168,7 +171,7 @@ function createAnalyticsClient({
168
171
  headers,
169
172
  data: body ? body : {}
170
173
  };
171
- return this.transporter.request(request, requestOptions);
174
+ return transporter.request(request, requestOptions);
172
175
  },
173
176
  /**
174
177
  * This method allow you to send requests to the Algolia REST API.
@@ -193,7 +196,7 @@ function createAnalyticsClient({
193
196
  headers,
194
197
  data: body ? body : {}
195
198
  };
196
- return this.transporter.request(request, requestOptions);
199
+ return transporter.request(request, requestOptions);
197
200
  },
198
201
  /**
199
202
  * Retrieves the add-to-cart rate for all of your searches with at least one add-to-cart event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -233,7 +236,7 @@ function createAnalyticsClient({
233
236
  queryParameters,
234
237
  headers
235
238
  };
236
- return this.transporter.request(request, requestOptions);
239
+ return transporter.request(request, requestOptions);
237
240
  },
238
241
  /**
239
242
  * Retrieves the average click position of your search results, including a daily breakdown. The average click position is the average of all clicked search results\' positions. For example, if users only ever click on the first result for any search, the average click position is 1. By default, the analyzed period includes the last eight days including the current day.
@@ -273,7 +276,7 @@ function createAnalyticsClient({
273
276
  queryParameters,
274
277
  headers
275
278
  };
276
- return this.transporter.request(request, requestOptions);
279
+ return transporter.request(request, requestOptions);
277
280
  },
278
281
  /**
279
282
  * Retrieves the positions in the search results and their associated number of clicks. This lets you check how many clicks the first, second, or tenth search results receive.
@@ -313,7 +316,7 @@ function createAnalyticsClient({
313
316
  queryParameters,
314
317
  headers
315
318
  };
316
- return this.transporter.request(request, requestOptions);
319
+ return transporter.request(request, requestOptions);
317
320
  },
318
321
  /**
319
322
  * Retrieves the click-through rate for all of your searches with at least one click event, including a daily breakdown By default, the analyzed period includes the last eight days including the current day.
@@ -353,7 +356,7 @@ function createAnalyticsClient({
353
356
  queryParameters,
354
357
  headers
355
358
  };
356
- return this.transporter.request(request, requestOptions);
359
+ return transporter.request(request, requestOptions);
357
360
  },
358
361
  /**
359
362
  * Retrieves the conversion rate for all of your searches with at least one conversion event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -393,7 +396,7 @@ function createAnalyticsClient({
393
396
  queryParameters,
394
397
  headers
395
398
  };
396
- return this.transporter.request(request, requestOptions);
399
+ return transporter.request(request, requestOptions);
397
400
  },
398
401
  /**
399
402
  * Retrieves the fraction of searches that didn\'t lead to any click within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -433,7 +436,7 @@ function createAnalyticsClient({
433
436
  queryParameters,
434
437
  headers
435
438
  };
436
- return this.transporter.request(request, requestOptions);
439
+ return transporter.request(request, requestOptions);
437
440
  },
438
441
  /**
439
442
  * Retrieves the fraction of searches that didn\'t return any results within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -473,7 +476,7 @@ function createAnalyticsClient({
473
476
  queryParameters,
474
477
  headers
475
478
  };
476
- return this.transporter.request(request, requestOptions);
479
+ return transporter.request(request, requestOptions);
477
480
  },
478
481
  /**
479
482
  * Retrieves the purchase rate for all of your searches with at least one purchase event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -513,7 +516,7 @@ function createAnalyticsClient({
513
516
  queryParameters,
514
517
  headers
515
518
  };
516
- return this.transporter.request(request, requestOptions);
519
+ return transporter.request(request, requestOptions);
517
520
  },
518
521
  /**
519
522
  * Retrieves revenue-related metrics, such as the total revenue or the average order value. To retrieve revenue-related metrics, sent purchase events. By default, the analyzed period includes the last eight days including the current day.
@@ -553,7 +556,7 @@ function createAnalyticsClient({
553
556
  queryParameters,
554
557
  headers
555
558
  };
556
- return this.transporter.request(request, requestOptions);
559
+ return transporter.request(request, requestOptions);
557
560
  },
558
561
  /**
559
562
  * Retrieves the number of searches within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
@@ -593,7 +596,7 @@ function createAnalyticsClient({
593
596
  queryParameters,
594
597
  headers
595
598
  };
596
- return this.transporter.request(request, requestOptions);
599
+ return transporter.request(request, requestOptions);
597
600
  },
598
601
  /**
599
602
  * Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
@@ -641,7 +644,7 @@ function createAnalyticsClient({
641
644
  queryParameters,
642
645
  headers
643
646
  };
644
- return this.transporter.request(request, requestOptions);
647
+ return transporter.request(request, requestOptions);
645
648
  },
646
649
  /**
647
650
  * Retrieves the most popular searches that didn\'t return any results.
@@ -689,7 +692,7 @@ function createAnalyticsClient({
689
692
  queryParameters,
690
693
  headers
691
694
  };
692
- return this.transporter.request(request, requestOptions);
695
+ return transporter.request(request, requestOptions);
693
696
  },
694
697
  /**
695
698
  * Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
@@ -717,7 +720,7 @@ function createAnalyticsClient({
717
720
  queryParameters,
718
721
  headers
719
722
  };
720
- return this.transporter.request(request, requestOptions);
723
+ return transporter.request(request, requestOptions);
721
724
  },
722
725
  /**
723
726
  * Retrieves the countries with the most searches to your index.
@@ -765,7 +768,7 @@ function createAnalyticsClient({
765
768
  queryParameters,
766
769
  headers
767
770
  };
768
- return this.transporter.request(request, requestOptions);
771
+ return transporter.request(request, requestOptions);
769
772
  },
770
773
  /**
771
774
  * Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -817,7 +820,7 @@ function createAnalyticsClient({
817
820
  queryParameters,
818
821
  headers
819
822
  };
820
- return this.transporter.request(request, requestOptions);
823
+ return transporter.request(request, requestOptions);
821
824
  },
822
825
  /**
823
826
  * Retrieves the most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -873,7 +876,7 @@ function createAnalyticsClient({
873
876
  queryParameters,
874
877
  headers
875
878
  };
876
- return this.transporter.request(request, requestOptions);
879
+ return transporter.request(request, requestOptions);
877
880
  },
878
881
  /**
879
882
  * Retrieves the most frequently used filters for a search that didn\'t return any results. To get the most frequent searches without results, use the [Retrieve searches without results](#tag/search/operation/getSearchesNoResults) operation.
@@ -925,7 +928,7 @@ function createAnalyticsClient({
925
928
  queryParameters,
926
929
  headers
927
930
  };
928
- return this.transporter.request(request, requestOptions);
931
+ return transporter.request(request, requestOptions);
929
932
  },
930
933
  /**
931
934
  * Retrieves the object IDs of the most frequent search results.
@@ -985,7 +988,7 @@ function createAnalyticsClient({
985
988
  queryParameters,
986
989
  headers
987
990
  };
988
- return this.transporter.request(request, requestOptions);
991
+ return transporter.request(request, requestOptions);
989
992
  },
990
993
  /**
991
994
  * Returns the most popular search terms.
@@ -1060,7 +1063,7 @@ function createAnalyticsClient({
1060
1063
  queryParameters,
1061
1064
  headers
1062
1065
  };
1063
- return this.transporter.request(request, requestOptions);
1066
+ return transporter.request(request, requestOptions);
1064
1067
  },
1065
1068
  /**
1066
1069
  * Retrieves the number of unique users within a time range, including a daily breakdown. Since this endpoint returns the number of unique users, the sum of the daily values might be different from the total number. By default, Algolia distinguishes search users by their IP address, _unless_ you include a pseudonymous user identifier in your search requests with the `userToken` API parameter or `x-algolia-usertoken` request header. By default, the analyzed period includes the last eight days including the current day.
@@ -1100,7 +1103,7 @@ function createAnalyticsClient({
1100
1103
  queryParameters,
1101
1104
  headers
1102
1105
  };
1103
- return this.transporter.request(request, requestOptions);
1106
+ return transporter.request(request, requestOptions);
1104
1107
  }
1105
1108
  };
1106
1109
  }