@algolia/client-analytics 5.2.5 → 5.3.0
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.
- package/dist/browser.d.ts +1152 -809
- package/dist/builds/browser.js +57 -47
- package/dist/builds/browser.js.map +1 -1
- package/dist/builds/browser.min.js +1 -1
- package/dist/builds/browser.min.js.map +1 -1
- package/dist/builds/browser.umd.js +1 -1
- package/dist/builds/node.cjs +57 -47
- package/dist/builds/node.cjs.map +1 -1
- package/dist/builds/node.js +57 -47
- package/dist/builds/node.js.map +1 -1
- package/dist/node.d.cts +1153 -810
- package/dist/node.d.ts +1153 -810
- package/dist/src/analyticsClient.cjs +57 -47
- package/dist/src/analyticsClient.cjs.map +1 -1
- package/dist/src/analyticsClient.js +57 -47
- package/dist/src/analyticsClient.js.map +1 -1
- package/package.json +4 -4
|
@@ -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.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})}
|
|
8
8
|
|
|
9
9
|
exports.analyticsClient = Nt;
|
|
10
10
|
exports.apiClientVersion = v;
|
package/dist/builds/node.cjs
CHANGED
|
@@ -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.
|
|
32
|
+
var apiClientVersion = "5.3.0";
|
|
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(
|
|
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,16 @@ 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
|
+
this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
|
|
91
101
|
},
|
|
92
102
|
/**
|
|
93
103
|
* This method allow you to send requests to the Algolia REST API.
|
|
@@ -110,7 +120,7 @@ function createAnalyticsClient({
|
|
|
110
120
|
queryParameters,
|
|
111
121
|
headers
|
|
112
122
|
};
|
|
113
|
-
return transporter.request(request, requestOptions);
|
|
123
|
+
return this.transporter.request(request, requestOptions);
|
|
114
124
|
},
|
|
115
125
|
/**
|
|
116
126
|
* This method allow you to send requests to the Algolia REST API.
|
|
@@ -133,7 +143,7 @@ function createAnalyticsClient({
|
|
|
133
143
|
queryParameters,
|
|
134
144
|
headers
|
|
135
145
|
};
|
|
136
|
-
return transporter.request(request, requestOptions);
|
|
146
|
+
return this.transporter.request(request, requestOptions);
|
|
137
147
|
},
|
|
138
148
|
/**
|
|
139
149
|
* This method allow you to send requests to the Algolia REST API.
|
|
@@ -158,7 +168,7 @@ function createAnalyticsClient({
|
|
|
158
168
|
headers,
|
|
159
169
|
data: body ? body : {}
|
|
160
170
|
};
|
|
161
|
-
return transporter.request(request, requestOptions);
|
|
171
|
+
return this.transporter.request(request, requestOptions);
|
|
162
172
|
},
|
|
163
173
|
/**
|
|
164
174
|
* This method allow you to send requests to the Algolia REST API.
|
|
@@ -183,7 +193,7 @@ function createAnalyticsClient({
|
|
|
183
193
|
headers,
|
|
184
194
|
data: body ? body : {}
|
|
185
195
|
};
|
|
186
|
-
return transporter.request(request, requestOptions);
|
|
196
|
+
return this.transporter.request(request, requestOptions);
|
|
187
197
|
},
|
|
188
198
|
/**
|
|
189
199
|
* 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 +233,7 @@ function createAnalyticsClient({
|
|
|
223
233
|
queryParameters,
|
|
224
234
|
headers
|
|
225
235
|
};
|
|
226
|
-
return transporter.request(request, requestOptions);
|
|
236
|
+
return this.transporter.request(request, requestOptions);
|
|
227
237
|
},
|
|
228
238
|
/**
|
|
229
239
|
* 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 +273,7 @@ function createAnalyticsClient({
|
|
|
263
273
|
queryParameters,
|
|
264
274
|
headers
|
|
265
275
|
};
|
|
266
|
-
return transporter.request(request, requestOptions);
|
|
276
|
+
return this.transporter.request(request, requestOptions);
|
|
267
277
|
},
|
|
268
278
|
/**
|
|
269
279
|
* 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 +313,7 @@ function createAnalyticsClient({
|
|
|
303
313
|
queryParameters,
|
|
304
314
|
headers
|
|
305
315
|
};
|
|
306
|
-
return transporter.request(request, requestOptions);
|
|
316
|
+
return this.transporter.request(request, requestOptions);
|
|
307
317
|
},
|
|
308
318
|
/**
|
|
309
319
|
* 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 +353,7 @@ function createAnalyticsClient({
|
|
|
343
353
|
queryParameters,
|
|
344
354
|
headers
|
|
345
355
|
};
|
|
346
|
-
return transporter.request(request, requestOptions);
|
|
356
|
+
return this.transporter.request(request, requestOptions);
|
|
347
357
|
},
|
|
348
358
|
/**
|
|
349
359
|
* 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 +393,7 @@ function createAnalyticsClient({
|
|
|
383
393
|
queryParameters,
|
|
384
394
|
headers
|
|
385
395
|
};
|
|
386
|
-
return transporter.request(request, requestOptions);
|
|
396
|
+
return this.transporter.request(request, requestOptions);
|
|
387
397
|
},
|
|
388
398
|
/**
|
|
389
399
|
* 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 +433,7 @@ function createAnalyticsClient({
|
|
|
423
433
|
queryParameters,
|
|
424
434
|
headers
|
|
425
435
|
};
|
|
426
|
-
return transporter.request(request, requestOptions);
|
|
436
|
+
return this.transporter.request(request, requestOptions);
|
|
427
437
|
},
|
|
428
438
|
/**
|
|
429
439
|
* 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 +473,7 @@ function createAnalyticsClient({
|
|
|
463
473
|
queryParameters,
|
|
464
474
|
headers
|
|
465
475
|
};
|
|
466
|
-
return transporter.request(request, requestOptions);
|
|
476
|
+
return this.transporter.request(request, requestOptions);
|
|
467
477
|
},
|
|
468
478
|
/**
|
|
469
479
|
* 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 +513,7 @@ function createAnalyticsClient({
|
|
|
503
513
|
queryParameters,
|
|
504
514
|
headers
|
|
505
515
|
};
|
|
506
|
-
return transporter.request(request, requestOptions);
|
|
516
|
+
return this.transporter.request(request, requestOptions);
|
|
507
517
|
},
|
|
508
518
|
/**
|
|
509
519
|
* 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 +553,7 @@ function createAnalyticsClient({
|
|
|
543
553
|
queryParameters,
|
|
544
554
|
headers
|
|
545
555
|
};
|
|
546
|
-
return transporter.request(request, requestOptions);
|
|
556
|
+
return this.transporter.request(request, requestOptions);
|
|
547
557
|
},
|
|
548
558
|
/**
|
|
549
559
|
* 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 +593,7 @@ function createAnalyticsClient({
|
|
|
583
593
|
queryParameters,
|
|
584
594
|
headers
|
|
585
595
|
};
|
|
586
|
-
return transporter.request(request, requestOptions);
|
|
596
|
+
return this.transporter.request(request, requestOptions);
|
|
587
597
|
},
|
|
588
598
|
/**
|
|
589
599
|
* Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
|
|
@@ -631,7 +641,7 @@ function createAnalyticsClient({
|
|
|
631
641
|
queryParameters,
|
|
632
642
|
headers
|
|
633
643
|
};
|
|
634
|
-
return transporter.request(request, requestOptions);
|
|
644
|
+
return this.transporter.request(request, requestOptions);
|
|
635
645
|
},
|
|
636
646
|
/**
|
|
637
647
|
* Retrieves the most popular searches that didn\'t return any results.
|
|
@@ -679,7 +689,7 @@ function createAnalyticsClient({
|
|
|
679
689
|
queryParameters,
|
|
680
690
|
headers
|
|
681
691
|
};
|
|
682
|
-
return transporter.request(request, requestOptions);
|
|
692
|
+
return this.transporter.request(request, requestOptions);
|
|
683
693
|
},
|
|
684
694
|
/**
|
|
685
695
|
* Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
|
|
@@ -707,7 +717,7 @@ function createAnalyticsClient({
|
|
|
707
717
|
queryParameters,
|
|
708
718
|
headers
|
|
709
719
|
};
|
|
710
|
-
return transporter.request(request, requestOptions);
|
|
720
|
+
return this.transporter.request(request, requestOptions);
|
|
711
721
|
},
|
|
712
722
|
/**
|
|
713
723
|
* Retrieves the countries with the most searches to your index.
|
|
@@ -755,7 +765,7 @@ function createAnalyticsClient({
|
|
|
755
765
|
queryParameters,
|
|
756
766
|
headers
|
|
757
767
|
};
|
|
758
|
-
return transporter.request(request, requestOptions);
|
|
768
|
+
return this.transporter.request(request, requestOptions);
|
|
759
769
|
},
|
|
760
770
|
/**
|
|
761
771
|
* Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
|
|
@@ -807,7 +817,7 @@ function createAnalyticsClient({
|
|
|
807
817
|
queryParameters,
|
|
808
818
|
headers
|
|
809
819
|
};
|
|
810
|
-
return transporter.request(request, requestOptions);
|
|
820
|
+
return this.transporter.request(request, requestOptions);
|
|
811
821
|
},
|
|
812
822
|
/**
|
|
813
823
|
* 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 +873,7 @@ function createAnalyticsClient({
|
|
|
863
873
|
queryParameters,
|
|
864
874
|
headers
|
|
865
875
|
};
|
|
866
|
-
return transporter.request(request, requestOptions);
|
|
876
|
+
return this.transporter.request(request, requestOptions);
|
|
867
877
|
},
|
|
868
878
|
/**
|
|
869
879
|
* 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 +925,7 @@ function createAnalyticsClient({
|
|
|
915
925
|
queryParameters,
|
|
916
926
|
headers
|
|
917
927
|
};
|
|
918
|
-
return transporter.request(request, requestOptions);
|
|
928
|
+
return this.transporter.request(request, requestOptions);
|
|
919
929
|
},
|
|
920
930
|
/**
|
|
921
931
|
* Retrieves the object IDs of the most frequent search results.
|
|
@@ -975,7 +985,7 @@ function createAnalyticsClient({
|
|
|
975
985
|
queryParameters,
|
|
976
986
|
headers
|
|
977
987
|
};
|
|
978
|
-
return transporter.request(request, requestOptions);
|
|
988
|
+
return this.transporter.request(request, requestOptions);
|
|
979
989
|
},
|
|
980
990
|
/**
|
|
981
991
|
* Returns the most popular search terms.
|
|
@@ -1050,7 +1060,7 @@ function createAnalyticsClient({
|
|
|
1050
1060
|
queryParameters,
|
|
1051
1061
|
headers
|
|
1052
1062
|
};
|
|
1053
|
-
return transporter.request(request, requestOptions);
|
|
1063
|
+
return this.transporter.request(request, requestOptions);
|
|
1054
1064
|
},
|
|
1055
1065
|
/**
|
|
1056
1066
|
* 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 +1100,7 @@ function createAnalyticsClient({
|
|
|
1090
1100
|
queryParameters,
|
|
1091
1101
|
headers
|
|
1092
1102
|
};
|
|
1093
|
-
return transporter.request(request, requestOptions);
|
|
1103
|
+
return this.transporter.request(request, requestOptions);
|
|
1094
1104
|
}
|
|
1095
1105
|
};
|
|
1096
1106
|
}
|