UNPKG

@safaricom-mxl/core

Version:

MXL Javascript agent core

3 lines (2 loc) 21.5 kB
"use strict";var X=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var it=Object.prototype.hasOwnProperty;var st=(e,t)=>{for(var n in t)X(e,n,{get:t[n],enumerable:!0})},at=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ot(t))!it.call(e,o)&&o!==n&&X(e,o,{get:()=>t[o],enumerable:!(r=rt(t,o))||r.enumerable});return e};var ct=e=>at(X({},"__esModule",{value:!0}),e);var wt={};st(wt,{GLOBAL_OBJ:()=>m,LRUMap:()=>K,MxlAnalytics:()=>fe,SDK_VERSION:()=>Qe,UNKNOWN_FUNCTION:()=>b,addNonEnumerableProperty:()=>D,basename:()=>Ve,callFrameToStackFrame:()=>Ye,convertToPlainObject:()=>P,createStackParser:()=>ne,dirname:()=>$e,dropUndefinedKeys:()=>$,eventFromMessage:()=>Je,eventFromUnknownInput:()=>qe,exceptionFromError:()=>le,extractExceptionKeysForMessage:()=>B,filenameIsInApp:()=>O,fill:()=>Oe,getComponentName:()=>be,getDebugImagesForResources:()=>tt,getFilenameToDebugIdMap:()=>pe,getFramesFromEvent:()=>Fe,getFunctionName:()=>z,getLocationHref:()=>he,getOriginalFunction:()=>Ie,getSDKSource:()=>_e,getSanitizedUrlString:()=>We,htmlTreeAsString:()=>L,isAbsolute:()=>ae,isBrowser:()=>xe,isBrowserBundle:()=>j,isDOMError:()=>me,isDOMException:()=>ge,isElement:()=>T,isError:()=>_,isErrorEvent:()=>R,isEvent:()=>N,isInstanceOf:()=>h,isMatchingPattern:()=>Y,isNodeEnv:()=>U,isParameterizedString:()=>E,isPlainObject:()=>y,isPrimitive:()=>A,isRegExp:()=>F,isString:()=>g,isSyntheticEvent:()=>M,isThenable:()=>ye,isVueViewModel:()=>x,join:()=>Be,loadModule:()=>ke,logger:()=>S,markFunctionWrapped:()=>ee,node:()=>ce,nodeStackLineParser:()=>He,normalize:()=>ie,normalizePath:()=>se,normalizeToSize:()=>v,normalizeUrlToBase:()=>Me,objectify:()=>Re,parseStackFrames:()=>H,parseUrl:()=>Ke,relative:()=>De,resolve:()=>C,safeJoin:()=>Ee,severityLevelFromString:()=>ze,snipLine:()=>Z,stackParserFromStackParserOptions:()=>Te,stringMatchesSomePattern:()=>Se,stripSentryFramesAndReverse:()=>re,stripUrlQueryAndFragment:()=>Ge,truncate:()=>w,watchdogTimer:()=>Ze});module.exports=ct(wt);var I=class{constructor(t){this.baseUrl=t.baseUrl,this.headers={"Content-Type":"application/json",...t.defaultHeaders},this.maxRetries=t.maxRetries??3,this.initialRetryDelay=t.initialRetryDelay??500,this.retryAttempts=0}addHeader(t,n){this.headers[t]=n}onSuccess(){}onError(){}async fetch({path:t,data:n,options:r={},useBeacon:o=!1}){let i=`${this.baseUrl}${t}`;try{if(!o){let s=await fetch(i,{method:"POST",headers:await this.resolveHeaders(),body:JSON.stringify(n??{}),keepalive:!0,...r});if(s.status===401)return null;if(s.status!==200&&s.status!==202)throw new Error(`HTTP error! status: ${s.status}`);let a=await s.text();return this.onSuccess(),a?JSON.parse(a):null}if(navigator.sendBeacon){let s={type:"application/json",headers:await this.resolveHeaders()},a=new Blob([JSON.stringify(n??{})],s);if(navigator.sendBeacon(i,a))return this.onSuccess(),null;throw new Error("Beacon request failed")}throw new Error("Beacon API not supported")}catch(s){return console.error("Error in fetch:",s),this.onError(),this.fallbackRequest(i,n)}}async resolveHeaders(){let t={};for(let[n,r]of Object.entries(this.headers))try{let o=await r;o!==null&&(t[n]=o)}catch(o){console.error(`Error resolving header ${n}:`,o)}return t}async retry(){if(this.retryAttempts<this.maxRetries){let t=this.initialRetryDelay*2**this.retryAttempts;this.retryAttempts++,await new Promise(n=>setTimeout(n,t))}else console.error("Request failed after multiple retries."),this.retryAttempts=0}async fallbackRequest(t,n){return new Promise(r=>{let o=new XMLHttpRequest;o.open("POST",t),this.resolveHeaders().then(i=>{for(let[s,a]of Object.entries(i))o.setRequestHeader(s,a);o.onload=async()=>{o.status===200?this.onSuccess():await this.retry(),r(null)},o.onerror=async()=>{this.onError(),await this.retry(),console.error("Couldn't send request to the server. See the XHR error."),r(null)},o.send(JSON.stringify(n))})})}};var de=Object.prototype.toString;function _(e){switch(de.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":case"[object WebAssembly.Exception]":return!0;default:return h(e,Error)}}function k(e,t){return de.call(e)===`[object ${t}]`}function R(e){return k(e,"ErrorEvent")}function me(e){return k(e,"DOMError")}function ge(e){return k(e,"DOMException")}function g(e){return k(e,"String")}function E(e){return typeof e=="object"&&e!==null&&"__sentry_template_string__"in e&&"__sentry_template_values__"in e}function A(e){return e===null||E(e)||typeof e!="object"&&typeof e!="function"}function y(e){return k(e,"Object")}function N(e){return typeof Event<"u"&&h(e,Event)}function T(e){return typeof Element<"u"&&h(e,Element)}function F(e){return k(e,"RegExp")}function ye(e){return!!(e?.then&&typeof e.then=="function")}function M(e){return y(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e}function h(e,t){try{return e instanceof t}catch{return!1}}function x(e){return!!(typeof e=="object"&&e!==null&&(e.__isVue||e._isVue))}var m=globalThis;var q=m,ut=80;function L(e,t={}){if(!e)return"<unknown>";try{let n=e,r=5,o=[],i=0,s=0,a=" > ",c=a.length,u,l=Array.isArray(t)?t:t.keyAttrs,f=!Array.isArray(t)&&t.maxStringLength||ut;for(;n&&i++<r&&(u=lt(n,l),!(u==="html"||i>1&&s+o.length*c+u.length>=f));)o.push(u),s+=u.length,n=n.parentNode;return o.reverse().join(a)}catch{return"<unknown>"}}function lt(e,t){let n=e,r=[];if(!n?.tagName)return"";if(q.HTMLElement&&n instanceof HTMLElement&&n.dataset){if(n.dataset.mxlComponent)return n.dataset.mxlComponent;if(n.dataset.mxlElement)return n.dataset.mxlElement}r.push(n.tagName.toLowerCase());let o=t?.length?t.filter(s=>n.getAttribute(s)).map(s=>[s,n.getAttribute(s)]):null;if(o?.length)o.forEach(s=>{r.push(`[${s[0]}="${s[1]}"]`)});else{n.id&&r.push(`#${n.id}`);let s=n.className;if(s&&g(s)){let a=s.split(/\s+/);for(let c of a)r.push(`.${c}`)}}let i=["aria-label","type","name","title","alt"];for(let s of i){let a=n.getAttribute(s);a&&r.push(`[${s}="${a}"]`)}return r.join("")}function he(){try{return q.document.location.href}catch{return""}}function be(e){if(!q.HTMLElement)return null;let t=e,n=5;for(let r=0;r<n;r++){if(!t)return null;if(t instanceof HTMLElement){if(t.dataset.mxlComponent)return t.dataset.mxlComponent;if(t.dataset.mxlElement)return t.dataset.mxlElement}t=t.parentNode}return null}function j(){return typeof __MXL_BROWSER_BUNDLE__<"u"&&!!__MXL_BROWSER_BUNDLE__}function _e(){return"npm"}function U(){return!j()&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]"}function J(e,t){return e.require(t)}function ke(e,t=module){let n;try{n=J(t,e)}catch{}if(!n)try{let{cwd:r}=J(t,"process");n=J(t,`${r()}/node_modules/${e}`)}catch{}return n}function xe(){return typeof window<"u"&&(!U()||pt())}function pt(){return m.process?.type==="renderer"}var S=console;function w(e,t=0){return typeof e!="string"||t===0||e.length<=t?e:`${e.slice(0,t)}...`}function Z(e,t){let n=e,r=n.length;if(r<=150)return n;t>r&&(t=r);let o=Math.max(t-60,0);o<5&&(o=0);let i=Math.min(o+140,r);return i>r-5&&(i=r),i===r&&(o=Math.max(i-140,0)),n=n.slice(o,i),o>0&&(n=`'{snip} ${n}`),i<r&&(n+=" {snip}"),n}function Ee(e,t){if(!Array.isArray(e))return"";let n=[];for(let r=0;r<e.length;r++){let o=e[r];try{x(o)?n.push("[VueViewModel]"):n.push(String(o))}catch{n.push("[value cannot be serialized]")}}return n.join(t)}function Y(e,t,n=!1){return g(e)?F(t)?t.test(e):g(t)?n?e===t:e.includes(t):!1:!1}function Se(e,t=[],n=!1){return t.some(r=>Y(e,r,n))}function Oe(e,t,n){if(!(t in e))return;let r=e[t],o=n(r);typeof o=="function"&&ee(o,r);try{e[t]=o}catch{!1}}function D(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch{!1}}function ee(e,t){try{let n=t.prototype||{};e.prototype=t.prototype=n,D(e,"__mxl_original__",t)}catch{}}function Ie(e){return e.__mxl_original__}function P(e){if(_(e))return{message:e.message,name:e.name,stack:e.stack,...Pe(e)};if(N(e)){let t={type:e.type,target:we(e.target),currentTarget:we(e.currentTarget),...Pe(e)};return typeof CustomEvent<"u"&&h(e,CustomEvent)&&(t.detail=e.detail),t}return e}function we(e){try{return T(e)?L(e):Object.prototype.toString.call(e)}catch{return"<unknown>"}}function Pe(e){if(typeof e=="object"&&e!==null){let t={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}return{}}function B(e,t=40){let n=Object.keys(P(e));n.sort();let r=n[0];if(!r)return"[object has no keys]";if(r.length>=t)return w(r,t);for(let o=n.length;o>0;o--){let i=n.slice(0,o).join(", ");if(!(i.length>t))return o===n.length?i:w(i,t)}return""}function $(e){return Q(e,new Map)}function Q(e,t){if(ft(e)){let n=t.get(e);if(n!==void 0)return n;let r={};t.set(e,r);for(let o of Object.getOwnPropertyNames(e))typeof e[o]<"u"&&(r[o]=Q(e[o],t));return r}if(Array.isArray(e)){let n=t.get(e);if(n!==void 0)return n;let r=[];return t.set(e,r),e.forEach(o=>{r.push(Q(o,t))}),r}return e}function ft(e){if(!y(e))return!1;try{let t=Object.getPrototypeOf(e).constructor.name;return!t||t==="Object"}catch{return!0}}function Re(e){let t;switch(!0){case e===void 0:t=String(e);break;case(typeof e=="symbol"||typeof e=="bigint"):t=Object(e);break;case A(e):t=new e.constructor(e);break;default:t=e;break}return t}var b="?",Ae=/\(error: (.*)\)/,Ne=/captureMessage|captureException/;function ne(...e){let t=e.sort((n,r)=>n[0]-r[0]).map(n=>n[1]);return(n,r=0,o=0)=>{let i=[],s=n.split(` `);for(let a=r;a<s.length;a++){let c=s[a];if(c.length>1024)continue;let u=Ae.test(c)?c.replace(Ae,"$1"):c;if(!u.match(/\S*Error: /)){for(let l of t){let f=l(u);if(f){i.push(f);break}}if(i.length>=50+o)break}}return re(i.slice(o))}}function Te(e){return Array.isArray(e)?ne(...e):e}function re(e){if(!e.length)return[];let t=Array.from(e);return/sentryWrapped/.test(V(t).function||"")&&t.pop(),t.reverse(),Ne.test(V(t).function||"")&&(t.pop(),Ne.test(V(t).function||"")&&t.pop()),t.slice(0,50).map(n=>({...n,filename:n.filename||V(t).filename,function:n.function||b}))}function V(e){return e[e.length-1]||{}}var te="<anonymous>";function z(e){try{return!e||typeof e!="function"?te:e.name||te}catch{return te}}function Fe(e){let t=e.exception;if(t){let n=[];try{return t.values.forEach(r=>{r.stacktrace.frames&&n.push(...r.stacktrace.frames)}),n}catch{return}}}function ie(e,t=100,n=Number.POSITIVE_INFINITY){try{return oe("",e,t,n)}catch(r){return{ERROR:`**non-serializable** (${r})`}}}function v(e,t=3,n=100*1024){let r=ie(e,t);return yt(r)>n?v(e,t-1,n):r}function oe(e,t,n=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,o=ht()){let[i,s]=o;if(t==null||["boolean","string"].includes(typeof t)||typeof t=="number"&&Number.isFinite(t))return t;let a=dt(e,t);if(!a.startsWith("[object "))return a;if(t.__sentry_skip_normalization__)return t;let c=typeof t.__sentry_override_normalization_depth__=="number"?t.__sentry_override_normalization_depth__:n;if(c===0)return a.replace("object ","");if(i(t))return"[Circular ~]";let u=t;if(u&&typeof u.toJSON=="function")try{let p=u.toJSON();return oe("",p,c-1,r,o)}catch{}let l=Array.isArray(t)?[]:{},f=0,d=P(t);for(let p in d){if(!Object.prototype.hasOwnProperty.call(d,p))continue;if(f>=r){l[p]="[MaxProperties ~]";break}let nt=d[p];l[p]=oe(p,nt,c-1,r,o),f++}return s(t),l}function dt(e,t){try{if(e==="domain"&&t&&typeof t=="object"&&t._events)return"[Domain]";if(e==="domainEmitter")return"[DomainEmitter]";if(typeof global<"u"&&t===global)return"[Global]";if(typeof window<"u"&&t===window)return"[Window]";if(typeof document<"u"&&t===document)return"[Document]";if(x(t))return"[VueViewModel]";if(M(t))return"[SyntheticEvent]";if(typeof t=="number"&&!Number.isFinite(t))return`[${t}]`;if(typeof t=="function")return`[Function: ${z(t)}]`;if(typeof t=="symbol")return`[${String(t)}]`;if(typeof t=="bigint")return`[BigInt: ${String(t)}]`;let n=mt(t);return/^HTML(\w*)Element$/.test(n)?`[HTMLElement: ${n}]`:`[object ${n}]`}catch(n){return`**non-serializable** (${n})`}}function mt(e){let t=Object.getPrototypeOf(e);return t?t.constructor.name:"null prototype"}function gt(e){return~-encodeURI(e).split(/%..|./).length}function yt(e){return gt(JSON.stringify(e))}function Me(e,t){let n=t.replace(/\\/g,"/").replace(/[|\\{}()[\]^$+*?.]/g,"\\$&"),r=e;try{r=decodeURI(e)}catch{}return r.replace(/\\/g,"/").replace(/webpack:\/?/g,"").replace(new RegExp(`(file://)?/*${n}/*`,"ig"),"app:///")}function ht(){let e=new WeakSet;function t(r){return e.has(r)?!0:(e.add(r),!1)}function n(r){e.delete(r)}return[t,n]}function je(e,t){let n=0;for(let r=e.length-1;r>=0;r--){let o=e[r];o==="."?e.splice(r,1):o===".."?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}var bt=/^(\S+:\\|\/?)([\s\S]*?)((?:\.{1,2}|[^/\\]+?|)(\.[^./\\]*|))(?:[/\\]*)$/;function Ue(e){let t=e.length>1024?`<truncated>${e.slice(-1024)}`:e,n=bt.exec(t);return n?n.slice(1):[]}function C(...e){let t="",n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let o=r>=0?e[r]:"/";o&&(t=`${o}/${t}`,n=o.charAt(0)==="/")}return t=je(t.split("/").filter(r=>!!r),!n).join("/"),(n?"/":"")+t||"."}function Le(e){let t=0;for(;t<e.length&&e[t]==="";t++);let n=e.length-1;for(;n>=0&&e[n]==="";n--);return t>n?[]:e.slice(t,n-t+1)}function De(e,t){e=C(e).slice(1),t=C(t).slice(1);let n=Le(e.split("/")),r=Le(t.split("/")),o=Math.min(n.length,r.length),i=o;for(let a=0;a<o;a++)if(n[a]!==r[a]){i=a;break}let s=[];for(let a=i;a<n.length;a++)s.push("..");return s=s.concat(r.slice(i)),s.join("/")}function se(e){let t=ae(e),n=e.slice(-1)==="/",r=je(e.split("/").filter(o=>!!o),!t).join("/");return!r&&!t&&(r="."),r&&n&&(r+="/"),(t?"/":"")+r}function ae(e){return e.charAt(0)==="/"}function Be(...e){return se(e.join("/"))}function $e(e){let t=Ue(e),n=t[0]||"",r=t[1];return!n&&!r?".":(r&&(r=r.slice(0,r.length-1)),n+r)}function Ve(e,t){let n=Ue(e)[2]||"";return t&&n.slice(t.length*-1)===t&&(n=n.slice(0,n.length-t.length)),n}function ze(e){return e==="warn"?"warning":["fatal","error","warning","log","info","debug"].includes(e)?e:"log"}function O(e,t=!1){return!(t||e&&!e.startsWith("/")&&!e.match(/^[A-Z]:/)&&!e.startsWith(".")&&!e.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//))&&e!==void 0&&!e.includes("node_modules/")}function ce(e){let t=/^\s*[-]{4,}$/,n=/at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;return r=>{let o=r.match(n);if(o){let i,s,a,c,u;if(o[1]){a=o[1];let d=a.lastIndexOf(".");if(a[d-1]==="."&&d--,d>0){i=a.slice(0,d),s=a.slice(d+1);let p=i.indexOf(".Module");p>0&&(a=a.slice(p+1),i=i.slice(0,p))}c=void 0}s&&(c=i,u=s),s==="<anonymous>"&&(u=void 0,a=void 0),a===void 0&&(u=u||b,a=c?`${c}.${u}`:u);let l=o[2]?.startsWith("file://")?o[2].slice(7):o[2],f=o[5]==="native";return l?.match(/\/[A-Z]:/)&&(l=l.slice(1)),!l&&o[5]&&!f&&(l=o[5]),{filename:l?decodeURI(l):void 0,module:e?e(l):void 0,function:a,lineno:Ce(o[3]),colno:Ce(o[4]),in_app:O(l||"",f)}}if(r.match(t))return{filename:r}}}function He(e){return[90,ce(e)]}function Ce(e){return Number.parseInt(e||"",10)||void 0}function Ke(e){if(!e)return{};let t=e.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)return{};let n=t[6]||"",r=t[8]||"";return{host:t[4],path:t[5],protocol:t[2],search:n,hash:r,relative:t[5]+n+r}}function Ge(e){return e.split(/[?#]/,1)[0]}function We(e){let{protocol:t,host:n,path:r}=e,o=n?.replace(/^.*@/,"[filtered]:[filtered]@").replace(/(:80)$/,"").replace(/(:443)$/,"")||"";return`${t?`${t}://`:""}${o}${r}`}function _t(e){return e.exception?.values?.[0]}function Xe(e,t,n){let r=e.exception=e.exception||{},o=r.values=r.values||[],i=o[0]=o[0]||{};i.value||(i.value=t||""),i.type||(i.type=n||"Error")}function ue(e,t){let n=_t(e);if(!n)return;let r={type:"generic",handled:!0},o=n.mechanism;if(n.mechanism={...r,...o,...t},t&&"data"in t){let i={...o?.data,...t.data};n.mechanism.data=i}}function H(e,t){return e(t.stack||"",1)}function le(e,t){let n={type:t.name||t.constructor.name,value:t.message},r=H(e,t);return r.length&&(n.stacktrace={frames:r}),n}function kt(e){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t)){let n=e[t];if(n instanceof Error)return n}}function xt(e){if("name"in e&&typeof e.name=="string"){let r=`'${e.name}' captured as exception`;return"message"in e&&typeof e.message=="string"&&(r+=` with message '${e.message}'`),r}if("message"in e&&typeof e.message=="string")return e.message;let t=B(e);if(R(e))return`Event \`ErrorEvent\` captured as exception with message \`${e.message}\``;let n=Et(e);return`${n&&n!=="Object"?`'${n}'`:"Object"} captured as exception with keys: ${t}`}function Et(e){try{let t=Object.getPrototypeOf(e);return t?t.constructor.name:void 0}catch{}}function St(e,t,n,r){if(_(n))return[n,void 0];if(t.synthetic=!0,y(n)){let i=e?.getOptions().normalizeDepth,s={__serialized__:v(n,i)},a=kt(n);if(a)return[a,s];let c=xt(n),u=r?.syntheticException||new Error(c);return u.message=c,[u,s]}let o=r?.syntheticException||new Error(n);return o.message=`${n}`,[o,void 0]}function qe(e,t,n,r){let i=r?.data&&r.data.mechanism||{handled:!0,type:"generic"},[s,a]=St(e,i,n,r),c={exception:{values:[le(t,s)]}};return a&&(c.extra=a),Xe(c,void 0,void 0),ue(c,i),{...c,event_id:r?.event_id}}function Je(e,t,n="info",r,o){let i={event_id:r?.event_id,level:n};if(o&&r?.syntheticException){let s=H(e,r.syntheticException);s.length&&(i.exception={values:[{value:t,stacktrace:{frames:s}}]},ue(i,{synthetic:!0}))}if(E(t)){let{__mxl_template_string__:s,__mxl_template_values__:a}=t;return i.logentry={message:s,params:a},i}return i.message=t,i}function Ze(e,t,n,r){let o=e(),i=!1,s=!0;return setInterval(()=>{let a=o.getTimeMs();i===!1&&a>t+n&&(i=!0,s&&r()),a<t+n&&(i=!1)},20),{poll:()=>{o.reset()},enabled:a=>{s=a}}}function Ye(e,t,n){let r=t?t.replace(/^file:\/\//,""):void 0,o=e.location.columnNumber?e.location.columnNumber+1:void 0,i=e.location.lineNumber?e.location.lineNumber+1:void 0;return $({filename:r,module:n(r),function:e.functionName||b,colno:o,lineno:i,in_app:r?O(r):void 0})}var K=class{constructor(t){this._maxSize=t;this._cache=new Map}get size(){return this._cache.size}get(t){let n=this._cache.get(t);if(n!==void 0)return this._cache.delete(t),this._cache.set(t,n),n}set(t,n){this._cache.size>=this._maxSize&&this._cache.delete(this._cache.keys().next().value),this._cache.set(t,n)}remove(t){let n=this._cache.get(t);return n&&this._cache.delete(t),n}clear(){this._cache.clear()}keys(){return Array.from(this._cache.keys())}values(){let t=[];return this._cache.forEach(n=>t.push(n)),t}};var Qe=typeof __MXL_SDK_VERSION__=="string"?__MXL_SDK_VERSION__:"0.0.0-unknown.0";var G,et,W;function pe(e){let t=m._mxlDebugIds;if(!t)return{};let n=Object.keys(t);return W&&n.length===et||(et=n.length,W=n.reduce((r,o)=>{G||(G={});let i=G[o];if(i)r[i[0]]=i[1];else{let s=e(o);for(let a=s.length-1;a>=0;a--){let u=s[a]?.filename,l=t[o];if(u&&l){r[u]=l,G[o]=[u,l];break}}}return r},{})),W}function tt(e,t){let n=pe(e);if(!n)return[];let r=[];for(let o of t)o&&n[o]&&r.push({type:"sourcemap",code_file:o,debug_id:n[o]});return r}var fe=class{constructor(t){this.options=t;this.queue=[];let n={"mxl-api-key":t.apiKey};n["mxl-sdk-name"]=t.sdk||"node",n["mxl-sdk-version"]=t.sdkVersion||"unknown",this.api=new I({baseUrl:t.apiUrl||"http://mxl-server.service-availability.apps.ocpthikadev01.safaricom.net",defaultHeaders:n})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}async send(t,n){if(!this.options.disabled&&!(this.options.filter&&!this.options.filter(t))){if(this.options.waitForProfile&&!this.profileId){this.queue.push(t);return}try{await this.api.fetch({path:"/track",data:t,useBeacon:n??this.options.useBeacon})}catch(r){console.error("Failed to send analytics data:",r)}}}setGlobalProperties(t){this.global={...this.global,...t}}async track(t,n,r){await this.send({type:"track",payload:{name:t,profileId:n?.profileId??this.profileId,properties:{...this.global??{},...n??{}}}},r)}async identify(t,n){t.profileId&&(this.profileId=t.profileId,this.flush()),Object.keys(t).length>1&&await this.send({type:"identify",payload:{...t,properties:{...this.global,...t.properties}}},n)}async alias(t,n){await this.send({type:"alias",payload:t},n)}async increment(t,n){await this.send({type:"increment",payload:t},n)}async decrement(t,n){await this.send({type:"decrement",payload:t},n)}clear(){this.profileId=void 0,this.global=void 0,this.queue=[]}async flush(){let t=this.queue.map(n=>this.send({...n,payload:{...n.payload,profileId:n.payload.profileId??this.profileId}}));await Promise.all(t),this.queue=[]}};0&&(module.exports={GLOBAL_OBJ,LRUMap,MxlAnalytics,SDK_VERSION,UNKNOWN_FUNCTION,addNonEnumerableProperty,basename,callFrameToStackFrame,convertToPlainObject,createStackParser,dirname,dropUndefinedKeys,eventFromMessage,eventFromUnknownInput,exceptionFromError,extractExceptionKeysForMessage,filenameIsInApp,fill,getComponentName,getDebugImagesForResources,getFilenameToDebugIdMap,getFramesFromEvent,getFunctionName,getLocationHref,getOriginalFunction,getSDKSource,getSanitizedUrlString,htmlTreeAsString,isAbsolute,isBrowser,isBrowserBundle,isDOMError,isDOMException,isElement,isError,isErrorEvent,isEvent,isInstanceOf,isMatchingPattern,isNodeEnv,isParameterizedString,isPlainObject,isPrimitive,isRegExp,isString,isSyntheticEvent,isThenable,isVueViewModel,join,loadModule,logger,markFunctionWrapped,node,nodeStackLineParser,normalize,normalizePath,normalizeToSize,normalizeUrlToBase,objectify,parseStackFrames,parseUrl,relative,resolve,safeJoin,severityLevelFromString,snipLine,stackParserFromStackParserOptions,stringMatchesSomePattern,stripSentryFramesAndReverse,stripUrlQueryAndFragment,truncate,watchdogTimer});