@algolia/client-analytics 5.2.5 → 5.3.1

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 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 y of Object.keys(u.queryParameters))!u.queryParameters[y]||Object.prototype.toString.call(u.queryParameters[y])==="[object Object]"?P[y]=u.queryParameters[y]:P[y]=u.queryParameters[y].toString();let S=0,T=async(y,x)=>{let C=y.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:y.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")),T(y,x)}if(de(E))return ie(E);throw U(E),ae(E,t)},A=o.filter(y=>y.accept==="readWrite"||(l?y.accept==="read":y.accept==="write")),H=await s(A);return T([...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 V(){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.2.5",b=["de","us"];function me(o){return [{url:o?"analytics.{region}.algolia.com".replace("{region}",o):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function K({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});},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 T={method:"GET",path:m,queryParameters:S,headers:P};return f.request(T,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={},T={};e!==void 0&&(T.index=e.toString()),s!==void 0&&(T.clickAnalytics=s.toString()),n!==void 0&&(T.revenueAnalytics=n.toString()),i!==void 0&&(T.startDate=i.toString()),a!==void 0&&(T.endDate=a.toString()),u!==void 0&&(T.orderBy=u.toString()),l!==void 0&&(T.direction=l.toString()),t!==void 0&&(T.limit=t.toString()),p!==void 0&&(T.offset=p.toString()),h!==void 0&&(T.tags=h.toString());let A={method:"GET",path:P,queryParameters:T,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 K({appId:o,apiKey:r,region:d,timeouts:{connect:z,read:B,write:X},requester:V(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:G(),requestsCache:G({serializable:!1}),hostsCache:w({caches:[L({key:`${v}-${o}`}),G()]}),...c})}
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.1",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}){!d||d==="WithinHeaders"?this.transporter.baseHeaders["x-algolia-api-key"]=e:this.transporter.baseQueryParameters["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})}
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.2.5";
32
+ var apiClientVersion = "5.3.1";
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,26 +44,25 @@ function createAnalyticsClient({
44
44
  ...options
45
45
  }) {
46
46
  const auth = (0, import_client_common.createAuth)(appIdOption, apiKeyOption, authMode);
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
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
47
  return {
66
- transporter,
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
+ }
65
+ }),
67
66
  /**
68
67
  * The `appId` currently in use.
69
68
  */
@@ -72,13 +71,15 @@ function createAnalyticsClient({
72
71
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
73
72
  */
74
73
  clearCache() {
75
- return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
74
+ return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
75
+ () => void 0
76
+ );
76
77
  },
77
78
  /**
78
79
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
79
80
  */
80
81
  get _ua() {
81
- return transporter.algoliaAgent.value;
82
+ return this.transporter.algoliaAgent.value;
82
83
  },
83
84
  /**
84
85
  * Adds a `segment` to the `x-algolia-agent` sent with every requests.
@@ -87,7 +88,20 @@ function createAnalyticsClient({
87
88
  * @param version - The version of the agent.
88
89
  */
89
90
  addAlgoliaAgent(segment, version) {
90
- transporter.algoliaAgent.add({ segment, version });
91
+ this.transporter.algoliaAgent.add({ segment, version });
92
+ },
93
+ /**
94
+ * Helper method to switch the API key used to authenticate the requests.
95
+ *
96
+ * @param params - Method params.
97
+ * @param params.apiKey - The new API Key to use.
98
+ */
99
+ setClientApiKey({ apiKey }) {
100
+ if (!authMode || authMode === "WithinHeaders") {
101
+ this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
102
+ } else {
103
+ this.transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
104
+ }
91
105
  },
92
106
  /**
93
107
  * This method allow you to send requests to the Algolia REST API.
@@ -110,7 +124,7 @@ function createAnalyticsClient({
110
124
  queryParameters,
111
125
  headers
112
126
  };
113
- return transporter.request(request, requestOptions);
127
+ return this.transporter.request(request, requestOptions);
114
128
  },
115
129
  /**
116
130
  * This method allow you to send requests to the Algolia REST API.
@@ -133,7 +147,7 @@ function createAnalyticsClient({
133
147
  queryParameters,
134
148
  headers
135
149
  };
136
- return transporter.request(request, requestOptions);
150
+ return this.transporter.request(request, requestOptions);
137
151
  },
138
152
  /**
139
153
  * This method allow you to send requests to the Algolia REST API.
@@ -158,7 +172,7 @@ function createAnalyticsClient({
158
172
  headers,
159
173
  data: body ? body : {}
160
174
  };
161
- return transporter.request(request, requestOptions);
175
+ return this.transporter.request(request, requestOptions);
162
176
  },
163
177
  /**
164
178
  * This method allow you to send requests to the Algolia REST API.
@@ -183,7 +197,7 @@ function createAnalyticsClient({
183
197
  headers,
184
198
  data: body ? body : {}
185
199
  };
186
- return transporter.request(request, requestOptions);
200
+ return this.transporter.request(request, requestOptions);
187
201
  },
188
202
  /**
189
203
  * 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.
@@ -223,7 +237,7 @@ function createAnalyticsClient({
223
237
  queryParameters,
224
238
  headers
225
239
  };
226
- return transporter.request(request, requestOptions);
240
+ return this.transporter.request(request, requestOptions);
227
241
  },
228
242
  /**
229
243
  * 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.
@@ -263,7 +277,7 @@ function createAnalyticsClient({
263
277
  queryParameters,
264
278
  headers
265
279
  };
266
- return transporter.request(request, requestOptions);
280
+ return this.transporter.request(request, requestOptions);
267
281
  },
268
282
  /**
269
283
  * 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.
@@ -303,7 +317,7 @@ function createAnalyticsClient({
303
317
  queryParameters,
304
318
  headers
305
319
  };
306
- return transporter.request(request, requestOptions);
320
+ return this.transporter.request(request, requestOptions);
307
321
  },
308
322
  /**
309
323
  * 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.
@@ -343,7 +357,7 @@ function createAnalyticsClient({
343
357
  queryParameters,
344
358
  headers
345
359
  };
346
- return transporter.request(request, requestOptions);
360
+ return this.transporter.request(request, requestOptions);
347
361
  },
348
362
  /**
349
363
  * 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.
@@ -383,7 +397,7 @@ function createAnalyticsClient({
383
397
  queryParameters,
384
398
  headers
385
399
  };
386
- return transporter.request(request, requestOptions);
400
+ return this.transporter.request(request, requestOptions);
387
401
  },
388
402
  /**
389
403
  * 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.
@@ -423,7 +437,7 @@ function createAnalyticsClient({
423
437
  queryParameters,
424
438
  headers
425
439
  };
426
- return transporter.request(request, requestOptions);
440
+ return this.transporter.request(request, requestOptions);
427
441
  },
428
442
  /**
429
443
  * 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.
@@ -463,7 +477,7 @@ function createAnalyticsClient({
463
477
  queryParameters,
464
478
  headers
465
479
  };
466
- return transporter.request(request, requestOptions);
480
+ return this.transporter.request(request, requestOptions);
467
481
  },
468
482
  /**
469
483
  * 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.
@@ -503,7 +517,7 @@ function createAnalyticsClient({
503
517
  queryParameters,
504
518
  headers
505
519
  };
506
- return transporter.request(request, requestOptions);
520
+ return this.transporter.request(request, requestOptions);
507
521
  },
508
522
  /**
509
523
  * 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.
@@ -543,7 +557,7 @@ function createAnalyticsClient({
543
557
  queryParameters,
544
558
  headers
545
559
  };
546
- return transporter.request(request, requestOptions);
560
+ return this.transporter.request(request, requestOptions);
547
561
  },
548
562
  /**
549
563
  * 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.
@@ -583,7 +597,7 @@ function createAnalyticsClient({
583
597
  queryParameters,
584
598
  headers
585
599
  };
586
- return transporter.request(request, requestOptions);
600
+ return this.transporter.request(request, requestOptions);
587
601
  },
588
602
  /**
589
603
  * Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
@@ -631,7 +645,7 @@ function createAnalyticsClient({
631
645
  queryParameters,
632
646
  headers
633
647
  };
634
- return transporter.request(request, requestOptions);
648
+ return this.transporter.request(request, requestOptions);
635
649
  },
636
650
  /**
637
651
  * Retrieves the most popular searches that didn\'t return any results.
@@ -679,7 +693,7 @@ function createAnalyticsClient({
679
693
  queryParameters,
680
694
  headers
681
695
  };
682
- return transporter.request(request, requestOptions);
696
+ return this.transporter.request(request, requestOptions);
683
697
  },
684
698
  /**
685
699
  * Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
@@ -707,7 +721,7 @@ function createAnalyticsClient({
707
721
  queryParameters,
708
722
  headers
709
723
  };
710
- return transporter.request(request, requestOptions);
724
+ return this.transporter.request(request, requestOptions);
711
725
  },
712
726
  /**
713
727
  * Retrieves the countries with the most searches to your index.
@@ -755,7 +769,7 @@ function createAnalyticsClient({
755
769
  queryParameters,
756
770
  headers
757
771
  };
758
- return transporter.request(request, requestOptions);
772
+ return this.transporter.request(request, requestOptions);
759
773
  },
760
774
  /**
761
775
  * Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -807,7 +821,7 @@ function createAnalyticsClient({
807
821
  queryParameters,
808
822
  headers
809
823
  };
810
- return transporter.request(request, requestOptions);
824
+ return this.transporter.request(request, requestOptions);
811
825
  },
812
826
  /**
813
827
  * Retrieves the most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -863,7 +877,7 @@ function createAnalyticsClient({
863
877
  queryParameters,
864
878
  headers
865
879
  };
866
- return transporter.request(request, requestOptions);
880
+ return this.transporter.request(request, requestOptions);
867
881
  },
868
882
  /**
869
883
  * 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.
@@ -915,7 +929,7 @@ function createAnalyticsClient({
915
929
  queryParameters,
916
930
  headers
917
931
  };
918
- return transporter.request(request, requestOptions);
932
+ return this.transporter.request(request, requestOptions);
919
933
  },
920
934
  /**
921
935
  * Retrieves the object IDs of the most frequent search results.
@@ -975,7 +989,7 @@ function createAnalyticsClient({
975
989
  queryParameters,
976
990
  headers
977
991
  };
978
- return transporter.request(request, requestOptions);
992
+ return this.transporter.request(request, requestOptions);
979
993
  },
980
994
  /**
981
995
  * Returns the most popular search terms.
@@ -1050,7 +1064,7 @@ function createAnalyticsClient({
1050
1064
  queryParameters,
1051
1065
  headers
1052
1066
  };
1053
- return transporter.request(request, requestOptions);
1067
+ return this.transporter.request(request, requestOptions);
1054
1068
  },
1055
1069
  /**
1056
1070
  * 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.
@@ -1090,7 +1104,7 @@ function createAnalyticsClient({
1090
1104
  queryParameters,
1091
1105
  headers
1092
1106
  };
1093
- return transporter.request(request, requestOptions);
1107
+ return this.transporter.request(request, requestOptions);
1094
1108
  }
1095
1109
  };
1096
1110
  }