13 lines
20 KiB
JavaScript
13 lines
20 KiB
JavaScript
|
(function (global, factory) {
|
||
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@algolia/client-analytics"] = {}));
|
||
|
})(this, (function (exports) { 'use strict';
|
||
|
|
||
|
function Q(){function o(t){return new Promise(d=>{let u=new XMLHttpRequest;u.open(t.method,t.url,true),Object.keys(t.headers).forEach(f=>u.setRequestHeader(f,t.headers[f]));let h=(f,e)=>setTimeout(()=>{u.abort(),d({status:0,content:e,isTimedOut:true});},f),R=h(t.connectTimeout,"Connection timeout"),y;u.onreadystatechange=()=>{u.readyState>u.OPENED&&y===void 0&&(clearTimeout(R),y=h(t.responseTimeout,"Socket timeout"));},u.onerror=()=>{u.status===0&&(clearTimeout(R),clearTimeout(y),d({content:u.responseText||"Network request failed",status:u.status,isTimedOut:false}));},u.onload=()=>{clearTimeout(R),clearTimeout(y),d({content:u.responseText,status:u.status,isTimedOut:false});},u.send(t.data);})}return {send:o}}function L(o){let t,d=`algolia-client-js-${o.key}`;function u(){return t===void 0&&(t=o.localStorage||window.localStorage),t}function h(){return JSON.parse(u().getItem(d)||"{}")}function R(f){u().setItem(d,JSON.stringify(f));}function y(){let f=o.timeToLive?o.timeToLive*1e3:null,e=h(),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 l=new Date().getTime();return !(i.timestamp+f<l)}));R(n);}return {get(f,e,s={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(y(),h()[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=h();return s[JSON.stringify(f)]={timestamp:new Date().getTime(),value:e},u().setItem(d,JSON.stringify(s)),e})},delete(f){return Promise.resolve().then(()=>{let e=h();delete e[JSON.stringify(f)],u().setItem(d,JSON.stringify(e));})},clear(){return Promise.resolve().then(()=>{u().removeItem(d);})}}}function V(){return {get(o,t,d={miss:()=>Promise.resolve()}){return t().then(h=>Promise.all([h,d.miss(h)])).then(([h])=>h)},set(o,t){return Promise.resolve(t)},delete(o){return Promise.resolve()},clear(){return Promise.resolve()}}}function E(o){let t=[...o.caches],d=t.shift();return d===void 0?V():{get(u,h,R={miss:()=>Promise.resolve()}){return d.get(u,h,R).catch(()=>E({caches:t}).get(u,h,R))},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 x(o={serializable:true}){let t={};return {get(d,u,h={miss:()=>Promise.resolve()}){let R=JSON.stringify(d);if(R in t)return Promise.resolve(o.serializable?JSON.parse(t[R]):t[R]);let y=u();return y.then(f=>h.miss(f)).then(()=>y)},set(d,u){return t[JSON.stringify(d)]=o.serializable?JSON.stringify(u):u,Promise.resolve(u)},delete(d){return delete t[JSON.stringify(d)],Promise.resolve()},clear(){return t={},Promise.resolve()}}}function Y(o){let t={value:`Algolia for JavaScript (${o})`,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 $(o,t,d="WithinHeaders"){let u={"x-algolia-api-key":t,"x-algolia-application-id":o};return {headers(){return d==="WithinHeaders"?u:{}},queryParameters(){return d==="WithinQueryParameters"?u:{}}}}function j({algoliaAgents:o,client:t,version:d}){let u=Y(d).add({segment:t,version:d});return o.forEach(h=>u.add(h)),u}function W(){return {debug(o,t){return Promise.resolve()},info(o,t){return Promise.resolve()},error(o,t){return Promise.resolve()}}}var _=2*60*1e3;function U(o,t="up"){let d=Date.now();function u(){return t==="up"||Date.now()-d>_}function h(){return t==="timed out"&&Date.now()-d<=_}return {...o,status:t,lastUpdate:d,isUp:u,isTimedOut:h}}var J=class extends Error{name="AlgoliaError";constructor(o,t){super(o),t&&(this.name=t);}};var z=class extends J{stackTrace;constructor(o,t,d){super(o,d),this.stackTrace=t;}},Z=class extends z{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 z{status;constructor
|
||
|
|
||
|
exports.analyticsClient = At;
|
||
|
exports.apiClientVersion = v;
|
||
|
|
||
|
}));
|