@launchdarkly/browser-telemetry 1.0.0 → 1.0.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.
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- function N(e){try{return e.target}catch(t){return}}var Be=">",Re=` ${Be} `;function Ce(e){let t=e;return typeof t=="object"&&t!=null&&t.parentNode}function Ie(e){if(typeof e.className!="string")return;let t=e.className;if(e.className.includes(" ")&&(t=e.className.replace(" ",".")),t!=="")return`.${t}`}function De(e){if(!e.tagName)return"";let t=[];t.push(e.tagName.toLowerCase()),e.id&&t.push(`#${e.id}`);let r=Ie(e);return r&&t.push(r),t.join("")}function U(e,t={maxDepth:10}){let r=[],n=e;for(;Ce(n)&&n.parentNode&&r.length<t.maxDepth;){let i=De(n);if(i==="html")break;r.push(i),n=n.parentNode}return r.reverse().join(Re)}var $=class{constructor(){window.addEventListener("click",t=>{var n;let r=N(t);if(r){let i={class:"ui",type:"click",level:"info",timestamp:Date.now(),message:U(r)};(n=this._destination)==null||n.addBreadcrumb(i)}},!0)}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var Me=1e3,Pe=["INPUT","TEXTAREA"],H=class{constructor(){window.addEventListener("keypress",t=>{var i;let r=N(t),n=r;if(r&&(Pe.includes(r.tagName)||n!=null&&n.isContentEditable)){let m={class:"ui",type:"input",level:"info",timestamp:Date.now(),message:U(r)};this._shouldDeduplicate(m)||((i=this._destination)==null||i.addBreadcrumb(m),this._lastEvent=m)}},!0)}register(t,r){this._destination=t}unregister(){this._destination=void 0}_shouldDeduplicate(t){return this._lastEvent?Math.abs(t.timestamp-this._lastEvent.timestamp)<=Me&&this._lastEvent.message===t.message:!1}};var A=class{constructor(){window.addEventListener("error",t=>{var r;(r=this._destination)==null||r.captureErrorEvent(t)},!0),window.addEventListener("unhandledrejection",t=>{var r;t.reason&&((r=this._destination)==null||r.captureError(t.reason))},!0)}register(t){this._destination=t}unregister(){this._destination=void 0}};function re(e,t){return t?e.reduce((r,n)=>n(r),t):""}function X(e,t){var r;(r=e.data)!=null&&r.url&&(e.data.url=re(t.urlFilters,e.data.url))}var Ne="__LaunchDarkly_original_fetch",j=window.fetch;function Ue(e,t){var i;let r="",n="GET";return typeof e=="string"&&(r=e),typeof Request!="undefined"&&e instanceof Request&&(r=e.url,n=e.method),typeof URL!="undefined"&&e instanceof URL&&(r=e.toString()),t&&(n=(i=t.method)!=null?i:n),{url:r,method:n}}function ne(e){function t(...r){let n=Date.now();return j.apply(this,r).then(i=>{let m={class:"http",timestamp:n,level:i.ok?"info":"error",type:"fetch",data:{...Ue(r[0],r[1]),statusCode:i.status,statusText:i.statusText}};return e(m),i})}t.prototype=j==null?void 0:j.prototype;try{Object.defineProperty(t,Ne,{value:j,writable:!0,configurable:!0})}catch(r){}window.fetch=t}var q=class{constructor(t){ne(r=>{var n;X(r,t),(n=this._destination)==null||n.addBreadcrumb(r)})}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var ye="__LaunchDarkly_original_xhr",$e=`${ye}_open`,He=`${ye}_send`,Q="__LaunchDarkly_data_xhr",be=window.XMLHttpRequest.prototype.open,xe=window.XMLHttpRequest.prototype.send;function ie(e){function t(...n){this.addEventListener("error",function(i){let m=this[Q];m.error=!0}),this.addEventListener("loadend",function(i){let m=this[Q];m&&m.timestamp&&e({class:"http",timestamp:m.timestamp,level:m.error?"error":"info",type:"xhr",data:{url:m.url,method:m.method,statusCode:this.status,statusText:this.statusText}})},!0),be.apply(this,n);try{let i={method:n==null?void 0:n[0],url:n==null?void 0:n[1]};Object.defineProperty(this,Q,{value:i,writable:!0,configurable:!0})}catch(i){}}function r(...n){xe.apply(this,n);let i=this[Q];i&&(i.timestamp=Date.now())}window.XMLHttpRequest.prototype.open=t,window.XMLHttpRequest.prototype.send=r;try{Object.defineProperties(window.XMLHttpRequest,{[$e]:{value:be,writable:!0,configurable:!0},[He]:{value:xe,writable:!0,configurable:!0}})}catch(n){}}var K=class{constructor(t){ie(r=>{var n;X(r,t),(n=this._destination)==null||n.addBreadcrumb(r)})}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var Ae=/sdk\/evalx\/[^/]+\/contexts\/(?<context>[^/?]*)\??.*?/,Xe=/\/eval\/[^/]+\/(?<context>[^/?]*)\??.*?/;function je(e){let t=new URL(e),r=!1;return t.username&&(t.username="redacted",r=!0),t.password&&(t.password="redacted",r=!0),r?t.toString():e}function qe(e){var t,r;if(e.includes("/sdk/evalx")){let n=e.match(Ae),i=(t=n==null?void 0:n.groups)==null?void 0:t.context;if(i)return e.replace(i,"*".repeat(i.length))}if(e.includes("/eval/")){let n=e.match(Xe),i=(r=n==null?void 0:n.groups)==null?void 0:r.context;if(i)return e.replace(i,"*".repeat(i.length))}return e}function se(e){return qe(je(e))}function ae(e,t,r){e.breadcrumbs.evaluations&&t.push({type:"flag-used",name:"launchdarkly-browser-telemetry-flag-used",synchronous:!0,method(n,i,m){r.handleFlagUsed(n,i,m)}}),e.breadcrumbs.flagChange&&t.push({type:"flag-detail-changed",name:"launchdarkly-browser-telemetry-flag-used",synchronous:!0,method(n,i){r.handleFlagDetailChanged(n,i)}})}var T={warn:console.warn},Ke="LaunchDarkly - Browser Telemetry:";function _(e){return`${Ke} ${e}`}function C(e){return{warn:(...t)=>{if(!e){T.warn(...t);return}try{e.warn(...t)}catch(r){T.warn(...t),T.warn(_("The provided logger threw an exception, using fallback logger."))}}}}var We={start:0,end:3},Ge={start:4,end:5},oe={start:6,end:7},ce={start:8,end:8},ze={start:9,end:9},Ve={start:10,end:15};function Ye(){if(crypto&&crypto.getRandomValues){let t=new Uint8Array(16);return crypto.getRandomValues(t),[...t.values()]}let e=[];for(let t=0;t<16;t+=1)e.push(Math.floor(Math.random()*256));return e}function I(e,t){let r="";for(let n=t.start;n<=t.end;n+=1)r+=e[n].toString(16).padStart(2,"0");return r}function Ze(e){return e[ce.start]=(e[ce.start]|128)&191,e[oe.start]=e[oe.start]&15|64,`${I(e,We)}-${I(e,Ge)}-${I(e,oe)}-${I(e,ce)}${I(e,ze)}-${I(e,Ve)}`}function Je(){let e=Ye();return Ze(e)}function le(){return typeof crypto!==void 0&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Je()}var y={};(function(e,t){if(!e)return;let r=[].slice,n="?",i=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function m(S,z){return Object.prototype.hasOwnProperty.call(S,z)}function L(S){return typeof S=="undefined"}y.wrap=function(z){function M(){try{return z.apply(this,arguments)}catch(V){throw y.report(V),V}}return M},y.computeStackTrace=function(){let M={};function V(a){if(!y.remoteFetching)return"";try{let u=function(){try{return new e.XMLHttpRequest}catch(d){return new e.ActiveXObject("Microsoft.XMLHTTP")}}();return u.open("GET",a,!1),u.send(""),u.responseText}catch(c){return""}}function B(a){if(typeof a!="string")return[];if(!m(M,a)){let c="",u="";try{u=e.document.domain}catch(l){}let d=/(.*)\:\/\/([^:\/]+)([:\d]*)\/{0,1}([\s\S]*)/.exec(a);d&&d[2]===u&&(c=V(a)),M[a]=c?c.split(`
2
- `):[]}return M[a]}function R(a,c){typeof c!="number"&&(c=Number(c));let u=/function ([^(]*)\(([^)]*)\)/,d=/['"]?([0-9A-Za-z$_]+)['"]?\s*[:=]\s*(function|eval|new Function)/,l="",b=10,g=B(a),f;if(!g.length)return n;for(let o=0;o<b;++o)if(l=g[c-o]+l,!L(l)&&((f=d.exec(l))||(f=u.exec(l))))return f[1];return n}function P(a,c){typeof c!="number"&&(c=Number(c));let u=B(a);if(!u.length)return null;let d=[],l=Math.floor(y.linesOfContext/2),b=l+y.linesOfContext%2,g=Math.max(0,c-l-1),f=Math.min(u.length,c+b-1);c-=1;for(let o=g;o<f;++o)L(u[o])||d.push(u[o]);return d.length>0?d:null}function Y(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#]/g,"\\$&")}function me(a){return Y(a).replace("<","(?:<|&lt;)").replace(">","(?:>|&gt;)").replace("&","(?:&|&amp;)").replace('"','(?:"|&quot;)').replace(/\s+/g,"\\s+")}function Z(a,c){let u,d;for(let l=0,b=c.length;l<b;++l)if((u=B(c[l])).length&&(u=u.join(`
1
+ function N(e){try{return e.target}catch(t){return}}var Be=">",Ie=` ${Be} `;function Ce(e){let t=e;return typeof t=="object"&&t!=null&&t.parentNode}function Re(e){if(typeof e.className!="string")return;let t=e.className;if(e.className.includes(" ")&&(t=e.className.replace(" ",".")),t!=="")return`.${t}`}function De(e){if(!e.tagName)return"";let t=[];t.push(e.tagName.toLowerCase()),e.id&&t.push(`#${e.id}`);let r=Re(e);return r&&t.push(r),t.join("")}function U(e,t={maxDepth:10}){let r=[],n=e;for(;Ce(n)&&n.parentNode&&r.length<t.maxDepth;){let i=De(n);if(i==="html")break;r.push(i),n=n.parentNode}return r.reverse().join(Ie)}var $=class{constructor(){window.addEventListener("click",t=>{var n;let r=N(t);if(r){let i={class:"ui",type:"click",level:"info",timestamp:Date.now(),message:U(r)};(n=this._destination)==null||n.addBreadcrumb(i)}},!0)}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var Me=1e3,Pe=["INPUT","TEXTAREA"],H=class{constructor(){window.addEventListener("keypress",t=>{var i;let r=N(t),n=r;if(r&&(Pe.includes(r.tagName)||n!=null&&n.isContentEditable)){let f={class:"ui",type:"input",level:"info",timestamp:Date.now(),message:U(r)};this._shouldDeduplicate(f)||((i=this._destination)==null||i.addBreadcrumb(f),this._lastEvent=f)}},!0)}register(t,r){this._destination=t}unregister(){this._destination=void 0}_shouldDeduplicate(t){return this._lastEvent?Math.abs(t.timestamp-this._lastEvent.timestamp)<=Me&&this._lastEvent.message===t.message:!1}};var A=class{constructor(){window.addEventListener("error",t=>{var r;(r=this._destination)==null||r.captureErrorEvent(t)},!0),window.addEventListener("unhandledrejection",t=>{var r;t.reason&&((r=this._destination)==null||r.captureError(t.reason))},!0)}register(t){this._destination=t}unregister(){this._destination=void 0}};function re(e,t){return t?e.reduce((r,n)=>n(r),t):""}function X(e,t){var r;(r=e.data)!=null&&r.url&&(e.data.url=re(t.urlFilters,e.data.url))}var Ne="__LaunchDarkly_original_fetch",j=window.fetch;function Ue(e,t){var i;let r="",n="GET";return typeof e=="string"&&(r=e),typeof Request!="undefined"&&e instanceof Request&&(r=e.url,n=e.method),typeof URL!="undefined"&&e instanceof URL&&(r=e.toString()),t&&(n=(i=t.method)!=null?i:n),{url:r,method:n}}function ne(e){function t(...r){let n=Date.now();return j.apply(this,r).then(i=>{let f={class:"http",timestamp:n,level:i.ok?"info":"error",type:"fetch",data:{...Ue(r[0],r[1]),statusCode:i.status,statusText:i.statusText}};return e(f),i})}t.prototype=j==null?void 0:j.prototype;try{Object.defineProperty(t,Ne,{value:j,writable:!0,configurable:!0})}catch(r){}window.fetch=t}var q=class{constructor(t){this._loggedIssue=!1;ne(r=>{var i,f,x;let n=!1;try{X(r,t),n=!0}catch(_){this._loggedIssue||((f=(i=t.getLogger)==null?void 0:i.call(t))==null||f.warn("Error filtering http breadcrumb",_),this._loggedIssue=!0)}n&&((x=this._destination)==null||x.addBreadcrumb(r))})}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var ye="__LaunchDarkly_original_xhr",$e=`${ye}_open`,He=`${ye}_send`,Q="__LaunchDarkly_data_xhr",be=window.XMLHttpRequest.prototype.open,xe=window.XMLHttpRequest.prototype.send;function ie(e){function t(...n){this.addEventListener("error",function(i){let f=this[Q];f.error=!0}),this.addEventListener("loadend",function(i){let f=this[Q];f&&f.timestamp&&e({class:"http",timestamp:f.timestamp,level:f.error?"error":"info",type:"xhr",data:{url:f.url,method:f.method,statusCode:this.status,statusText:this.statusText}})},!0),be.apply(this,n);try{let i={method:n==null?void 0:n[0],url:n==null?void 0:n[1]};Object.defineProperty(this,Q,{value:i,writable:!0,configurable:!0})}catch(i){}}function r(...n){xe.apply(this,n);let i=this[Q];i&&(i.timestamp=Date.now())}window.XMLHttpRequest.prototype.open=t,window.XMLHttpRequest.prototype.send=r;try{Object.defineProperties(window.XMLHttpRequest,{[$e]:{value:be,writable:!0,configurable:!0},[He]:{value:xe,writable:!0,configurable:!0}})}catch(n){}}var K=class{constructor(t){this._loggedIssue=!1;ie(r=>{var i,f,x;let n=!1;try{X(r,t),n=!0}catch(_){this._loggedIssue||((f=(i=t.getLogger)==null?void 0:i.call(t))==null||f.warn("Error filtering http breadcrumb",_),this._loggedIssue=!0)}n&&((x=this._destination)==null||x.addBreadcrumb(r))})}register(t,r){this._destination=t}unregister(){this._destination=void 0}};var Ae=/sdk\/evalx\/[^/]+\/contexts\/(?<context>[^/?]*)\??.*?/,Xe=/\/eval\/[^/]+\/(?<context>[^/?]*)\??.*?/;function je(e){try{if(e.includes("://")){let t=new URL(e),r=!1;if(t.username&&(t.username="redacted",r=!0),t.password&&(t.password="redacted",r=!0),r)return t.toString()}}catch(t){}return e}function qe(e){var t,r;if(e.includes("/sdk/evalx")){let n=e.match(Ae),i=(t=n==null?void 0:n.groups)==null?void 0:t.context;if(i)return e.replace(i,"*".repeat(i.length))}if(e.includes("/eval/")){let n=e.match(Xe),i=(r=n==null?void 0:n.groups)==null?void 0:r.context;if(i)return e.replace(i,"*".repeat(i.length))}return e}function se(e){return qe(je(e))}function ae(e,t,r){e.breadcrumbs.evaluations&&t.push({type:"flag-used",name:"launchdarkly-browser-telemetry-flag-used",synchronous:!0,method(n,i,f){r.handleFlagUsed(n,i,f)}}),e.breadcrumbs.flagChange&&t.push({type:"flag-detail-changed",name:"launchdarkly-browser-telemetry-flag-used",synchronous:!0,method(n,i){r.handleFlagDetailChanged(n,i)}})}var w={warn:console.warn},Ke="LaunchDarkly - Browser Telemetry:";function k(e){return`${Ke} ${e}`}function C(e){return{warn:(...t)=>{if(!e){w.warn(...t);return}try{e.warn(...t)}catch(r){w.warn(...t),w.warn(k("The provided logger threw an exception, using fallback logger."))}}}}var We={start:0,end:3},Ge={start:4,end:5},oe={start:6,end:7},ce={start:8,end:8},ze={start:9,end:9},Ve={start:10,end:15};function Ye(){if(crypto&&crypto.getRandomValues){let t=new Uint8Array(16);return crypto.getRandomValues(t),[...t.values()]}let e=[];for(let t=0;t<16;t+=1)e.push(Math.floor(Math.random()*256));return e}function R(e,t){let r="";for(let n=t.start;n<=t.end;n+=1)r+=e[n].toString(16).padStart(2,"0");return r}function Ze(e){return e[ce.start]=(e[ce.start]|128)&191,e[oe.start]=e[oe.start]&15|64,`${R(e,We)}-${R(e,Ge)}-${R(e,oe)}-${R(e,ce)}${R(e,ze)}-${R(e,Ve)}`}function Je(){let e=Ye();return Ze(e)}function le(){return typeof crypto!==void 0&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Je()}var v={};(function(e,t){if(!e)return;let r=[].slice,n="?",i=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/;function f(_,z){return Object.prototype.hasOwnProperty.call(_,z)}function x(_){return typeof _=="undefined"}v.wrap=function(z){function M(){try{return z.apply(this,arguments)}catch(V){throw v.report(V),V}}return M},v.computeStackTrace=function(){let M={};function V(a){if(!v.remoteFetching)return"";try{let u=function(){try{return new e.XMLHttpRequest}catch(d){return new e.ActiveXObject("Microsoft.XMLHTTP")}}();return u.open("GET",a,!1),u.send(""),u.responseText}catch(c){return""}}function B(a){if(typeof a!="string")return[];if(!f(M,a)){let c="",u="";try{u=e.document.domain}catch(l){}let d=/(.*)\:\/\/([^:\/]+)([:\d]*)\/{0,1}([\s\S]*)/.exec(a);d&&d[2]===u&&(c=V(a)),M[a]=c?c.split(`
2
+ `):[]}return M[a]}function I(a,c){typeof c!="number"&&(c=Number(c));let u=/function ([^(]*)\(([^)]*)\)/,d=/['"]?([0-9A-Za-z$_]+)['"]?\s*[:=]\s*(function|eval|new Function)/,l="",b=10,g=B(a),m;if(!g.length)return n;for(let o=0;o<b;++o)if(l=g[c-o]+l,!x(l)&&((m=d.exec(l))||(m=u.exec(l))))return m[1];return n}function P(a,c){typeof c!="number"&&(c=Number(c));let u=B(a);if(!u.length)return null;let d=[],l=Math.floor(v.linesOfContext/2),b=l+v.linesOfContext%2,g=Math.max(0,c-l-1),m=Math.min(u.length,c+b-1);c-=1;for(let o=g;o<m;++o)x(u[o])||d.push(u[o]);return d.length>0?d:null}function Y(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#]/g,"\\$&")}function me(a){return Y(a).replace("<","(?:<|&lt;)").replace(">","(?:>|&gt;)").replace("&","(?:&|&amp;)").replace('"','(?:"|&quot;)').replace(/\s+/g,"\\s+")}function Z(a,c){let u,d;for(let l=0,b=c.length;l<b;++l)if((u=B(c[l])).length&&(u=u.join(`
3
3
  `),d=a.exec(u)))return{url:c[l],line:u.substring(0,d.index).split(`
4
4
  `).length,column:d.index-u.lastIndexOf(`
5
- `,d.index)-1};return null}function te(a,c,u){typeof u!="number"&&(u=Number(u));let d=B(c),l=new RegExp(`\\b${Y(a)}\\b`),b;return u-=1,d&&d.length>u&&(b=l.exec(d[u]))?b.index:null}function we(a){if(L(e&&e.document))return;let c=[e.location.href],u=e.document.getElementsByTagName("script"),d,l=`${a}`,b=/^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,g=/^function on([\w$]+)\s*\(event\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,f,o,h;for(let s=0;s<u.length;++s){let p=u[s];p.src&&c.push(p.src)}if(!(o=b.exec(l)))f=new RegExp(Y(l).replace(/\s+/g,"\\s+"));else{let s=o[1]?`\\s+${o[1]}`:"",p=o[2].split(",").join("\\s*,\\s*");d=Y(o[3]).replace(/;$/,";?"),f=new RegExp(`function${s}\\s*\\(\\s*${p}\\s*\\)\\s*{\\s*${d}\\s*}`)}if(h=Z(f,c))return h;if(o=g.exec(l)){let s=o[1];if(d=me(o[2]),f=new RegExp(`on${s}=[\\'"]\\s*${d}\\s*[\\'"]`,"i"),(h=Z(f,c[0]))||(f=new RegExp(d),h=Z(f,c)))return h}return null}function de(a){if(!a.stack)return null;let c=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,u=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,d=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,l,b=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,g=/\((\S*)(?::(\d+))(?::(\d+))\)/,f=a.stack.split(`
6
- `),o=[],h,s,p,k=/^(.*) is undefined$/.exec(a.message);for(let x=0,J=f.length;x<J;++x){if(s=c.exec(f[x])){let he=s[2]&&s[2].indexOf("native")===0;l=s[2]&&s[2].indexOf("eval")===0,l&&(h=g.exec(s[2]))&&(s[2]=h[1],s[3]=h[2],s[4]=h[3]),p={url:he?null:s[2],func:s[1]||n,args:he?[s[2]]:[],line:s[3]?+s[3]:null,column:s[4]?+s[4]:null}}else if(s=d.exec(f[x]))p={url:s[2],func:s[1]||n,args:[],line:+s[3],column:s[4]?+s[4]:null};else if(s=u.exec(f[x]))l=s[3]&&s[3].indexOf(" > eval")>-1,l&&(h=b.exec(s[3]))?(s[3]=h[1],s[4]=h[2],s[5]=null):x===0&&!s[5]&&!L(a.columnNumber)&&(o[0].column=a.columnNumber+1),p={url:s[3],func:s[1]||n,args:s[2]?s[2].split(","):[],line:s[4]?+s[4]:null,column:s[5]?+s[5]:null};else continue;!p.func&&p.line&&(p.func=R(p.url,p.line)),p.context=p.line?P(p.url,p.line):null,o.push(p)}return o.length?(o[0]&&o[0].line&&!o[0].column&&k&&(o[0].column=te(k[1],o[0].url,o[0].line)),{mode:"stack",name:a.name,message:a.message,stack:o}):null}function Se(a){let{stacktrace:c}=a;if(!c)return null;let u=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,d=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,l=c.split(`
7
- `),b=[],g;for(let f=0;f<l.length;f+=2){let o=null;if((g=u.exec(l[f]))?o={url:g[2],line:+g[1],column:null,func:g[3],args:[]}:(g=d.exec(l[f]))&&(o={url:g[6],line:+g[1],column:+g[2],func:g[3]||g[4],args:g[5]?g[5].split(","):[]}),o){if(!o.func&&o.line&&(o.func=R(o.url,o.line)),o.line)try{o.context=P(o.url,o.line)}catch(h){}o.context||(o.context=[l[f+1]]),b.push(o)}}return b.length?{mode:"stacktrace",name:a.name,message:a.message,stack:b}:null}function Oe(a){let c=a.message.split(`
8
- `);if(c.length<4)return null;let u=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,d=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,l=/^\s*Line (\d+) of function script\s*$/i,b=[],g=e&&e.document&&e.document.getElementsByTagName("script"),f=[],o;for(let h in g)m(g,h)&&!g[h].src&&f.push(g[h]);for(let h=2;h<c.length;h+=2){let s=null;if(o=u.exec(c[h]))s={url:o[2],func:o[3],args:[],line:+o[1],column:null};else if(o=d.exec(c[h])){s={url:o[3],func:o[4],args:[],line:+o[1],column:null};let p=+o[1],k=f[o[2]-1];if(k){let x=B(s.url);if(x){x=x.join(`
9
- `);let J=x.indexOf(k.innerText);J>=0&&(s.line=p+x.substring(0,J).split(`
10
- `).length)}}}else if(o=l.exec(c[h])){let p=e.location.href.replace(/#.*$/,""),k=new RegExp(me(c[h+1])),x=Z(k,[p]);s={url:p,func:"",args:[],line:x?x.line:o[1],column:null}}if(s){s.func||(s.func=R(s.url,s.line));let p=P(s.url,s.line),k=p?p[Math.floor(p.length/2)]:null;p&&k&&k.replace(/^\s*/,"")===c[h+1].replace(/^\s*/,"")?s.context=p:s.context=[c[h+1]],b.push(s)}}return b.length?{mode:"multiline",name:a.name,message:c[0],stack:b}:null}function pe(a,c,u,d){let l={url:c,line:u};if(l.url&&l.line){a.incomplete=!1,l.func||(l.func=R(l.url,l.line)),l.context||(l.context=P(l.url,l.line));let b=/ '([^']+)' /.exec(d);if(b&&(l.column=te(b[1],l.url,l.line)),a.stack.length>0&&a.stack[0].url===l.url){if(a.stack[0].line===l.line)return!1;if(!a.stack[0].line&&a.stack[0].func===l.func)return a.stack[0].line=l.line,a.stack[0].context=l.context,!1}return a.stack.unshift(l),a.partial=!0,!0}return a.incomplete=!0,!1}function ge(a,c){let u=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,d=[],l={},b=!1,g,f,o;for(let s=ge.caller;s&&!b;s=s.caller)if(!(s===w||s===y.report)){if(f={url:null,func:n,args:[],line:null,column:null},s.name?f.func=s.name:(g=u.exec(s.toString()))&&(f.func=g[1]),typeof f.func=="undefined")try{f.func=g.input.substring(0,g.input.indexOf("{"))}catch(p){}if(o=we(s)){f.url=o.url,f.line=o.line,f.func===n&&(f.func=R(f.url,f.line));let p=/ '([^']+)' /.exec(a.message||a.description);p&&(f.column=te(p[1],o.url,o.line))}l[`${s}`]?b=!0:l[`${s}`]=!0,d.push(f)}c&&d.splice(0,c);let h={mode:"callers",name:a.name,message:a.message,stack:d};return pe(h,a.sourceURL||a.fileName,a.line||a.lineNumber,a.message||a.description),h}function w(a,c){let u=null;c=c==null?0:+c;try{if(u=Se(a),u)return u}catch(d){}try{if(u=de(a),u)return u}catch(d){}try{if(u=Oe(a),u)return u}catch(d){}try{if(u=ge(a,c+1),u)return u}catch(d){}return{name:a.name,message:a.message,mode:"failed",stack:[]}}function Fe(a){a=(a==null?0:+a)+1;try{throw new Error}catch(c){return w(c,a+1)}}return w.augmentStackTraceWithInitialElement=pe,w.computeStackTraceFromStackProp=de,w.guessFunctionName=R,w.gatherContext=P,w.ofCaller=Fe,w.getSource=B,w}(),y.remoteFetching||(y.remoteFetching=!0),y.collectWindowErrors||(y.collectWindowErrors=!0),(!y.linesOfContext||y.linesOfContext<1)&&(y.linesOfContext=11)})(typeof window!="undefined"?window:global);function ee(){return y}var ve="(index)";function Qe(e,t){let r=e;if(e.startsWith(t)){if(r=e.slice(t.length),r.startsWith("/")&&(r=r.slice(1)),r==="")return ve;r.endsWith("/")&&(r+=ve)}return r}function Ee(e,t,r){if(t.length<=e.maxLength)return t;let n=Math.max(0,r-e.beforeColumnCharacters),i=Math.min(t.length,n+e.maxLength);return t.slice(n,i)}function Le(e,t,r,n){let i=e<0?0:e,m=t>r.length?r.length:t;return i<m?r.slice(i,m).map(n):[]}function et(e,t){let{context:r}=e;if(!r)return{};let{maxLineLength:n}=t.source,i=Math.floor(n/2),m=S=>Ee({maxLength:t.source.maxLineLength,beforeColumnCharacters:i},S,0),L=Math.floor(r.length/2);return{srcBefore:Le(L-t.source.beforeLines,L,r,m),srcLine:Ee({maxLength:n,beforeColumnCharacters:i},r[L],e.column||0),srcAfter:Le(L+1,L+1+t.source.afterLines,r,m)}}function ue(e,t){return t.enabled?{frames:ee().computeStackTrace(e).stack.reverse().map(i=>({fileName:Qe(i.url,window.location.origin),function:i.func,line:i.line,col:i.column,...et(i,t)}))}:{frames:[]}}var Te="$ld:telemetry",tt=`${Te}:error`,rt=`${Te}:session:init`,_e="generic",nt="exception was null or undefined",it="exception had no message",st=5;function ke(e){switch(typeof e){case"string":case"boolean":case"number":return e;default:return}}function at(e,t){return e===void 0?void 0:t(e)}function ot(e){if(!e.enabled)return;let t=ee(),r=Math.max(e.source.afterLines,e.source.beforeLines),n=t;n.linesOfContext=r*2+1}function ct(e){return e.logger!==void 0}function lt(e){return e.waitForInitialization!==void 0}var O=class{constructor(t){this._options=t;this._pendingEvents=[];this._breadcrumbs=[];this._inspectorInstances=[];this._collectors=[];this._sessionId=le();this._registrationComplete=!1;this._clientRegistered=!1;this._eventsDropped=!1;this._breadcrumbFilterError=!1;this._errorFilterError=!1;var m;ot(t.stack),this._collectors.push(new A),this._collectors.push(...t.collectors),this._maxPendingEvents=t.maxPendingEvents,this._maxBreadcrumbs=t.breadcrumbs.maxBreadcrumbs;let r=[se];t.breadcrumbs.http.customUrlFilter&&r.push(t.breadcrumbs.http.customUrlFilter),t.breadcrumbs.http.instrumentFetch&&this._collectors.push(new q({urlFilters:r})),t.breadcrumbs.http.instrumentXhr&&this._collectors.push(new K({urlFilters:r})),t.breadcrumbs.click&&this._collectors.push(new $),t.breadcrumbs.keyboardInput&&this._collectors.push(new H),this._collectors.forEach(L=>L.register(this,this._sessionId));let n=this,i=[];ae(t,i,n),this._inspectorInstances.push(...i),this._logger=(m=this._options.logger)!=null?m:T}register(t){if(this._client!==void 0)return;this._client=t,this._setLogger();let r=()=>{var n;(n=this._client)==null||n.track(rt,{sessionId:this._sessionId}),this._pendingEvents.forEach(i=>{var m;(m=this._client)==null||m.track(i.type,i.data)}),this._pendingEvents=[],this._registrationComplete=!0};lt(t)?(async()=>{try{await t.waitForInitialization(st)}catch(n){}r()})():r()}_setLogger(){this._options.logger?this._logger=this._options.logger:ct(this._client)?this._logger=this._client.logger:this._logger=T}inspectors(){return this._inspectorInstances}_capture(t,r){var i;let n=this._applyFilters(r,this._options.errorFilters,m=>{this._errorFilterError||(this._errorFilterError=!0,this._logger.warn(_(`Error applying error filters: ${m}`)))});n!==void 0&&(this._registrationComplete?(i=this._client)==null||i.track(t,n):(this._pendingEvents.push({type:t,data:n}),this._pendingEvents.length>this._maxPendingEvents&&(this._eventsDropped||(this._eventsDropped=!0,this._logger.warn(_("Maximum pending events reached. Old events will be dropped until the SDK client is registered."))),this._pendingEvents.shift())))}captureError(t){var i,m;let n=t!=null?{type:t.name||((i=t.constructor)==null?void 0:i.name)||_e,message:(m=t.message)!=null?m:it,stack:ue(t,this._options.stack),breadcrumbs:[...this._breadcrumbs],sessionId:this._sessionId}:{type:_e,message:nt,stack:{frames:[]},breadcrumbs:[...this._breadcrumbs],sessionId:this._sessionId};this._capture(tt,n)}captureErrorEvent(t){this.captureError(t.error)}_applyFilters(t,r,n){try{return r.reduce((i,m)=>at(i,m),t)}catch(i){n(i);return}}addBreadcrumb(t){let r=this._applyFilters(t,this._options.breadcrumbs.filters,n=>{this._breadcrumbFilterError||(this._breadcrumbFilterError=!0,this._logger.warn(_(`Error applying breadcrumb filters: ${n}`)))});r!==void 0&&(this._breadcrumbs.push(r),this._breadcrumbs.length>this._maxBreadcrumbs&&this._breadcrumbs.shift())}close(){this._collectors.forEach(t=>t.unregister())}handleFlagUsed(t,r,n){let i={type:"flag-evaluated",data:{key:t,value:ke(r.value)},timestamp:new Date().getTime(),class:"feature-management",level:"info"};this.addBreadcrumb(i)}handleFlagDetailChanged(t,r){let n={type:"flag-detail-changed",data:{key:t,value:ke(r.value)},timestamp:new Date().getTime(),class:"feature-management",level:"info"};this.addBreadcrumb(n)}};var ut={maxBreadcrumbs:0,evaluations:!1,flagChange:!1,click:!1,keyboardInput:!1,http:{instrumentFetch:!1,instrumentXhr:!1,customUrlFilter:void 0},filters:[]},ft={enabled:!1,source:{beforeLines:0,afterLines:0,maxLineLength:0}};function mt(){return{breadcrumbs:{maxBreadcrumbs:50,evaluations:!0,flagChange:!0,click:!0,keyboardInput:!0,http:{instrumentFetch:!0,instrumentXhr:!0},filters:[]},stack:{enabled:!0,source:{beforeLines:3,afterLines:3,maxLineLength:280}},maxPendingEvents:100,collectors:[],errorFilters:[]}}function D(e,t,r){return _(`Config option "${e}" should be of type ${t}, got ${r}, using default value`)}function E(e,t,r){return n=>{let i=typeof n;return i===e?!0:(r==null||r.warn(D(t,e,i)),!1)}}function v(e,t,r){return e!=null&&(!r||r(e))?e:t}function dt(e,t,r){if(e!==void 0&&e!==!1&&typeof e!="object")return r==null||r.warn(D("breadcrumbs.http","HttpBreadCrumbOptions | false",typeof e)),t;if(e===!1)return{instrumentFetch:!1,instrumentXhr:!1};e!=null&&e.customUrlFilter&&typeof e.customUrlFilter!="function"&&(r==null||r.warn(_(`The "breadcrumbs.http.customUrlFilter" must be a function. Received ${typeof e.customUrlFilter}`)));let n=e!=null&&e.customUrlFilter&&typeof(e==null?void 0:e.customUrlFilter)=="function"?e.customUrlFilter:void 0;return{instrumentFetch:v(e==null?void 0:e.instrumentFetch,t.instrumentFetch,E("boolean","breadcrumbs.http.instrumentFetch",r)),instrumentXhr:v(e==null?void 0:e.instrumentXhr,t.instrumentXhr,E("boolean","breadcrumbs.http.instrumentXhr",r)),customUrlFilter:n}}function pt(e){if(e.logger){let{logger:t}=e;if(typeof t=="object"&&t!==null&&"warn"in t)return C(t);T.warn(D("logger","MinLogger or LDLogger",typeof t))}}function gt(e,t,r){var n,i,m;return e===!1?ft:{enabled:!0,source:{beforeLines:v((n=e==null?void 0:e.source)==null?void 0:n.beforeLines,t.source.beforeLines,E("number","stack.beforeLines",r)),afterLines:v((i=e==null?void 0:e.source)==null?void 0:i.afterLines,t.source.afterLines,E("number","stack.afterLines",r)),maxLineLength:v((m=e==null?void 0:e.source)==null?void 0:m.maxLineLength,t.source.maxLineLength,E("number","stack.maxLineLength",r))}}}function ht(e,t,r){return e===!1?ut:{maxBreadcrumbs:v(e==null?void 0:e.maxBreadcrumbs,t.maxBreadcrumbs,E("number","breadcrumbs.maxBreadcrumbs",r)),evaluations:v(e==null?void 0:e.evaluations,t.evaluations,E("boolean","breadcrumbs.evaluations",r)),flagChange:v(e==null?void 0:e.flagChange,t.flagChange,E("boolean","breadcrumbs.flagChange",r)),click:v(e==null?void 0:e.click,t.click,E("boolean","breadcrumbs.click",r)),keyboardInput:v(e==null?void 0:e.keyboardInput,t.keyboardInput,E("boolean","breadcrumbs.keyboardInput",r)),http:dt(e==null?void 0:e.http,t.http,r),filters:v(e==null?void 0:e.filters,t.filters,n=>Array.isArray(n)?!0:(r==null||r.warn(D("breadcrumbs.filters","BreadcrumbFilter[]",typeof n)),!1))}}function W(e,t){let r=mt();return e.breadcrumbs&&E("object","breadcrumbs",t)(e.breadcrumbs),e.stack&&E("object","stack",t)(e.stack),{breadcrumbs:ht(e.breadcrumbs,r.breadcrumbs,t),stack:gt(e.stack,r.stack,t),maxPendingEvents:v(e.maxPendingEvents,r.maxPendingEvents,E("number","maxPendingEvents",t)),collectors:[...v(e.collectors,r.collectors,n=>Array.isArray(n)?!0:(t==null||t.warn(D("collectors","Collector[]",typeof n)),!1))],logger:pt(e),errorFilters:v(e.errorFilters,r.errorFilters,n=>Array.isArray(n)?!0:(t==null||t.warn(D("errorFilters","ErrorDataFilter[]",typeof n)),!1))}}var G,fe=!1;function Lr(e){let t=C(e==null?void 0:e.logger);if(G){t.warn(_("Telemetry has already been initialized. Ignoring new options."));return}let r=W(e||{},t);G=new O(r)}function F(){if(!G){if(fe)return;T.warn(_("Telemetry has not been initialized")),fe=!0;return}return G}function _r(){G=void 0,fe=!1}function wr(){var e;return((e=F())==null?void 0:e.inspectors())||[]}function Sr(e){var t;(t=F())==null||t.captureError(e)}function Or(e){var t;(t=F())==null||t.captureErrorEvent(e)}function Fr(e){var t;(t=F())==null||t.addBreadcrumb(e)}function Br(e){var t;(t=F())==null||t.register(e)}function Rr(){var e;(e=F())==null||e.close()}function $r(e){let t=W(e||{},C(e==null?void 0:e.logger));return new O(t)}export{Fr as addBreadcrumb,Sr as captureError,Or as captureErrorEvent,Rr as close,F as getTelemetryInstance,Lr as initTelemetry,$r as initTelemetryInstance,wr as inspectors,Br as register,_r as resetTelemetryInstance};
5
+ `,d.index)-1};return null}function te(a,c,u){typeof u!="number"&&(u=Number(u));let d=B(c),l=new RegExp(`\\b${Y(a)}\\b`),b;return u-=1,d&&d.length>u&&(b=l.exec(d[u]))?b.index:null}function we(a){if(x(e&&e.document))return;let c=[e.location.href],u=e.document.getElementsByTagName("script"),d,l=`${a}`,b=/^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,g=/^function on([\w$]+)\s*\(event\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,m,o,h;for(let s=0;s<u.length;++s){let p=u[s];p.src&&c.push(p.src)}if(!(o=b.exec(l)))m=new RegExp(Y(l).replace(/\s+/g,"\\s+"));else{let s=o[1]?`\\s+${o[1]}`:"",p=o[2].split(",").join("\\s*,\\s*");d=Y(o[3]).replace(/;$/,";?"),m=new RegExp(`function${s}\\s*\\(\\s*${p}\\s*\\)\\s*{\\s*${d}\\s*}`)}if(h=Z(m,c))return h;if(o=g.exec(l)){let s=o[1];if(d=me(o[2]),m=new RegExp(`on${s}=[\\'"]\\s*${d}\\s*[\\'"]`,"i"),(h=Z(m,c[0]))||(m=new RegExp(d),h=Z(m,c)))return h}return null}function de(a){if(!a.stack)return null;let c=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,u=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,d=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,l,b=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,g=/\((\S*)(?::(\d+))(?::(\d+))\)/,m=a.stack.split(`
6
+ `),o=[],h,s,p,T=/^(.*) is undefined$/.exec(a.message);for(let y=0,J=m.length;y<J;++y){if(s=c.exec(m[y])){let he=s[2]&&s[2].indexOf("native")===0;l=s[2]&&s[2].indexOf("eval")===0,l&&(h=g.exec(s[2]))&&(s[2]=h[1],s[3]=h[2],s[4]=h[3]),p={url:he?null:s[2],func:s[1]||n,args:he?[s[2]]:[],line:s[3]?+s[3]:null,column:s[4]?+s[4]:null}}else if(s=d.exec(m[y]))p={url:s[2],func:s[1]||n,args:[],line:+s[3],column:s[4]?+s[4]:null};else if(s=u.exec(m[y]))l=s[3]&&s[3].indexOf(" > eval")>-1,l&&(h=b.exec(s[3]))?(s[3]=h[1],s[4]=h[2],s[5]=null):y===0&&!s[5]&&!x(a.columnNumber)&&(o[0].column=a.columnNumber+1),p={url:s[3],func:s[1]||n,args:s[2]?s[2].split(","):[],line:s[4]?+s[4]:null,column:s[5]?+s[5]:null};else continue;!p.func&&p.line&&(p.func=I(p.url,p.line)),p.context=p.line?P(p.url,p.line):null,o.push(p)}return o.length?(o[0]&&o[0].line&&!o[0].column&&T&&(o[0].column=te(T[1],o[0].url,o[0].line)),{mode:"stack",name:a.name,message:a.message,stack:o}):null}function Se(a){let{stacktrace:c}=a;if(!c)return null;let u=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,d=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,l=c.split(`
7
+ `),b=[],g;for(let m=0;m<l.length;m+=2){let o=null;if((g=u.exec(l[m]))?o={url:g[2],line:+g[1],column:null,func:g[3],args:[]}:(g=d.exec(l[m]))&&(o={url:g[6],line:+g[1],column:+g[2],func:g[3]||g[4],args:g[5]?g[5].split(","):[]}),o){if(!o.func&&o.line&&(o.func=I(o.url,o.line)),o.line)try{o.context=P(o.url,o.line)}catch(h){}o.context||(o.context=[l[m+1]]),b.push(o)}}return b.length?{mode:"stacktrace",name:a.name,message:a.message,stack:b}:null}function Oe(a){let c=a.message.split(`
8
+ `);if(c.length<4)return null;let u=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,d=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,l=/^\s*Line (\d+) of function script\s*$/i,b=[],g=e&&e.document&&e.document.getElementsByTagName("script"),m=[],o;for(let h in g)f(g,h)&&!g[h].src&&m.push(g[h]);for(let h=2;h<c.length;h+=2){let s=null;if(o=u.exec(c[h]))s={url:o[2],func:o[3],args:[],line:+o[1],column:null};else if(o=d.exec(c[h])){s={url:o[3],func:o[4],args:[],line:+o[1],column:null};let p=+o[1],T=m[o[2]-1];if(T){let y=B(s.url);if(y){y=y.join(`
9
+ `);let J=y.indexOf(T.innerText);J>=0&&(s.line=p+y.substring(0,J).split(`
10
+ `).length)}}}else if(o=l.exec(c[h])){let p=e.location.href.replace(/#.*$/,""),T=new RegExp(me(c[h+1])),y=Z(T,[p]);s={url:p,func:"",args:[],line:y?y.line:o[1],column:null}}if(s){s.func||(s.func=I(s.url,s.line));let p=P(s.url,s.line),T=p?p[Math.floor(p.length/2)]:null;p&&T&&T.replace(/^\s*/,"")===c[h+1].replace(/^\s*/,"")?s.context=p:s.context=[c[h+1]],b.push(s)}}return b.length?{mode:"multiline",name:a.name,message:c[0],stack:b}:null}function pe(a,c,u,d){let l={url:c,line:u};if(l.url&&l.line){a.incomplete=!1,l.func||(l.func=I(l.url,l.line)),l.context||(l.context=P(l.url,l.line));let b=/ '([^']+)' /.exec(d);if(b&&(l.column=te(b[1],l.url,l.line)),a.stack.length>0&&a.stack[0].url===l.url){if(a.stack[0].line===l.line)return!1;if(!a.stack[0].line&&a.stack[0].func===l.func)return a.stack[0].line=l.line,a.stack[0].context=l.context,!1}return a.stack.unshift(l),a.partial=!0,!0}return a.incomplete=!0,!1}function ge(a,c){let u=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,d=[],l={},b=!1,g,m,o;for(let s=ge.caller;s&&!b;s=s.caller)if(!(s===S||s===v.report)){if(m={url:null,func:n,args:[],line:null,column:null},s.name?m.func=s.name:(g=u.exec(s.toString()))&&(m.func=g[1]),typeof m.func=="undefined")try{m.func=g.input.substring(0,g.input.indexOf("{"))}catch(p){}if(o=we(s)){m.url=o.url,m.line=o.line,m.func===n&&(m.func=I(m.url,m.line));let p=/ '([^']+)' /.exec(a.message||a.description);p&&(m.column=te(p[1],o.url,o.line))}l[`${s}`]?b=!0:l[`${s}`]=!0,d.push(m)}c&&d.splice(0,c);let h={mode:"callers",name:a.name,message:a.message,stack:d};return pe(h,a.sourceURL||a.fileName,a.line||a.lineNumber,a.message||a.description),h}function S(a,c){let u=null;c=c==null?0:+c;try{if(u=Se(a),u)return u}catch(d){}try{if(u=de(a),u)return u}catch(d){}try{if(u=Oe(a),u)return u}catch(d){}try{if(u=ge(a,c+1),u)return u}catch(d){}return{name:a.name,message:a.message,mode:"failed",stack:[]}}function Fe(a){a=(a==null?0:+a)+1;try{throw new Error}catch(c){return S(c,a+1)}}return S.augmentStackTraceWithInitialElement=pe,S.computeStackTraceFromStackProp=de,S.guessFunctionName=I,S.gatherContext=P,S.ofCaller=Fe,S.getSource=B,S}(),v.remoteFetching||(v.remoteFetching=!0),v.collectWindowErrors||(v.collectWindowErrors=!0),(!v.linesOfContext||v.linesOfContext<1)&&(v.linesOfContext=11)})(typeof window!="undefined"?window:global);function ee(){return v}var ve="(index)";function Qe(e,t){let r=e;if(e.startsWith(t)){if(r=e.slice(t.length),r.startsWith("/")&&(r=r.slice(1)),r==="")return ve;r.endsWith("/")&&(r+=ve)}return r}function Ee(e,t,r){if(t.length<=e.maxLength)return t;let n=Math.max(0,r-e.beforeColumnCharacters),i=Math.min(t.length,n+e.maxLength);return t.slice(n,i)}function Le(e,t,r,n){let i=e<0?0:e,f=t>r.length?r.length:t;return i<f?r.slice(i,f).map(n):[]}function et(e,t){let{context:r}=e;if(!r)return{};let{maxLineLength:n}=t.source,i=Math.floor(n/2),f=_=>Ee({maxLength:t.source.maxLineLength,beforeColumnCharacters:i},_,0),x=Math.floor(r.length/2);return{srcBefore:Le(x-t.source.beforeLines,x,r,f),srcLine:Ee({maxLength:n,beforeColumnCharacters:i},r[x],e.column||0),srcAfter:Le(x+1,x+1+t.source.afterLines,r,f)}}function ue(e,t){return t.enabled?{frames:ee().computeStackTrace(e).stack.reverse().map(i=>({fileName:Qe(i.url,window.location.origin),function:i.func,line:i.line,col:i.column,...et(i,t)}))}:{frames:[]}}var Te="$ld:telemetry",tt=`${Te}:error`,rt=`${Te}:session:init`,_e="generic",nt="exception was null or undefined",it="exception had no message",st=5;function ke(e){switch(typeof e){case"string":case"boolean":case"number":return e;default:return}}function at(e,t){return e===void 0?void 0:t(e)}function ot(e){if(!e.enabled)return;let t=ee(),r=Math.max(e.source.afterLines,e.source.beforeLines),n=t;n.linesOfContext=r*2+1}function ct(e){return e.logger!==void 0}function lt(e){return e.waitForInitialization!==void 0}var O=class{constructor(t){this._options=t;this._pendingEvents=[];this._breadcrumbs=[];this._inspectorInstances=[];this._collectors=[];this._sessionId=le();this._registrationComplete=!1;this._eventsDropped=!1;this._breadcrumbFilterError=!1;this._errorFilterError=!1;var f;ot(t.stack),this._collectors.push(new A),this._collectors.push(...t.collectors),this._maxPendingEvents=t.maxPendingEvents,this._maxBreadcrumbs=t.breadcrumbs.maxBreadcrumbs,this._logger=(f=this._options.logger)!=null?f:w;let r=[se];t.breadcrumbs.http.customUrlFilter&&r.push(t.breadcrumbs.http.customUrlFilter),t.breadcrumbs.http.instrumentFetch&&this._collectors.push(new q({urlFilters:r,getLogger:()=>this._logger})),t.breadcrumbs.http.instrumentXhr&&this._collectors.push(new K({urlFilters:r,getLogger:()=>this._logger})),t.breadcrumbs.click&&this._collectors.push(new $),t.breadcrumbs.keyboardInput&&this._collectors.push(new H),this._collectors.forEach(x=>x.register(this,this._sessionId));let n=this,i=[];ae(t,i,n),this._inspectorInstances.push(...i)}register(t){if(this._client!==void 0)return;this._client=t,this._setLogger();let r=()=>{var n;(n=this._client)==null||n.track(rt,{sessionId:this._sessionId}),this._pendingEvents.forEach(i=>{var f;(f=this._client)==null||f.track(i.type,i.data)}),this._pendingEvents=[],this._registrationComplete=!0};lt(t)?(async()=>{try{await t.waitForInitialization(st)}catch(n){}r()})():r()}_setLogger(){this._options.logger?this._logger=this._options.logger:ct(this._client)?this._logger=this._client.logger:this._logger=w}inspectors(){return this._inspectorInstances}_capture(t,r){var i;let n=this._applyFilters(r,this._options.errorFilters,f=>{this._errorFilterError||(this._errorFilterError=!0,this._logger.warn(k(`Error applying error filters: ${f}`)))});n!==void 0&&(this._registrationComplete?(i=this._client)==null||i.track(t,n):(this._pendingEvents.push({type:t,data:n}),this._pendingEvents.length>this._maxPendingEvents&&(this._eventsDropped||(this._eventsDropped=!0,this._logger.warn(k("Maximum pending events reached. Old events will be dropped until the SDK client is registered."))),this._pendingEvents.shift())))}captureError(t){var i,f;let n=t!=null?{type:t.name||((i=t.constructor)==null?void 0:i.name)||_e,message:(f=t.message)!=null?f:it,stack:ue(t,this._options.stack),breadcrumbs:[...this._breadcrumbs],sessionId:this._sessionId}:{type:_e,message:nt,stack:{frames:[]},breadcrumbs:[...this._breadcrumbs],sessionId:this._sessionId};this._capture(tt,n)}captureErrorEvent(t){this.captureError(t.error)}_applyFilters(t,r,n){try{return r.reduce((i,f)=>at(i,f),t)}catch(i){n(i);return}}addBreadcrumb(t){let r=this._applyFilters(t,this._options.breadcrumbs.filters,n=>{this._breadcrumbFilterError||(this._breadcrumbFilterError=!0,this._logger.warn(k(`Error applying breadcrumb filters: ${n}`)))});r!==void 0&&(this._breadcrumbs.push(r),this._breadcrumbs.length>this._maxBreadcrumbs&&this._breadcrumbs.shift())}close(){this._collectors.forEach(t=>t.unregister())}handleFlagUsed(t,r,n){let i={type:"flag-evaluated",data:{key:t,value:ke(r.value)},timestamp:new Date().getTime(),class:"feature-management",level:"info"};this.addBreadcrumb(i)}handleFlagDetailChanged(t,r){let n={type:"flag-detail-changed",data:{key:t,value:ke(r.value)},timestamp:new Date().getTime(),class:"feature-management",level:"info"};this.addBreadcrumb(n)}};var ut={maxBreadcrumbs:0,evaluations:!1,flagChange:!1,click:!1,keyboardInput:!1,http:{instrumentFetch:!1,instrumentXhr:!1,customUrlFilter:void 0},filters:[]},ft={enabled:!1,source:{beforeLines:0,afterLines:0,maxLineLength:0}};function mt(){return{breadcrumbs:{maxBreadcrumbs:50,evaluations:!0,flagChange:!0,click:!0,keyboardInput:!0,http:{instrumentFetch:!0,instrumentXhr:!0},filters:[]},stack:{enabled:!0,source:{beforeLines:3,afterLines:3,maxLineLength:280}},maxPendingEvents:100,collectors:[],errorFilters:[]}}function D(e,t,r){return k(`Config option "${e}" should be of type ${t}, got ${r}, using default value`)}function L(e,t,r){return n=>{let i=typeof n;return i===e?!0:(r==null||r.warn(D(t,e,i)),!1)}}function E(e,t,r){return e!=null&&(!r||r(e))?e:t}function dt(e,t,r){if(e!==void 0&&e!==!1&&typeof e!="object")return r==null||r.warn(D("breadcrumbs.http","HttpBreadCrumbOptions | false",typeof e)),t;if(e===!1)return{instrumentFetch:!1,instrumentXhr:!1};e!=null&&e.customUrlFilter&&typeof e.customUrlFilter!="function"&&(r==null||r.warn(k(`The "breadcrumbs.http.customUrlFilter" must be a function. Received ${typeof e.customUrlFilter}`)));let n=e!=null&&e.customUrlFilter&&typeof(e==null?void 0:e.customUrlFilter)=="function"?e.customUrlFilter:void 0;return{instrumentFetch:E(e==null?void 0:e.instrumentFetch,t.instrumentFetch,L("boolean","breadcrumbs.http.instrumentFetch",r)),instrumentXhr:E(e==null?void 0:e.instrumentXhr,t.instrumentXhr,L("boolean","breadcrumbs.http.instrumentXhr",r)),customUrlFilter:n}}function pt(e){if(e.logger){let{logger:t}=e;if(typeof t=="object"&&t!==null&&"warn"in t)return C(t);w.warn(D("logger","MinLogger or LDLogger",typeof t))}}function gt(e,t,r){var n,i,f;return e===!1?ft:{enabled:!0,source:{beforeLines:E((n=e==null?void 0:e.source)==null?void 0:n.beforeLines,t.source.beforeLines,L("number","stack.beforeLines",r)),afterLines:E((i=e==null?void 0:e.source)==null?void 0:i.afterLines,t.source.afterLines,L("number","stack.afterLines",r)),maxLineLength:E((f=e==null?void 0:e.source)==null?void 0:f.maxLineLength,t.source.maxLineLength,L("number","stack.maxLineLength",r))}}}function ht(e,t,r){return e===!1?ut:{maxBreadcrumbs:E(e==null?void 0:e.maxBreadcrumbs,t.maxBreadcrumbs,L("number","breadcrumbs.maxBreadcrumbs",r)),evaluations:E(e==null?void 0:e.evaluations,t.evaluations,L("boolean","breadcrumbs.evaluations",r)),flagChange:E(e==null?void 0:e.flagChange,t.flagChange,L("boolean","breadcrumbs.flagChange",r)),click:E(e==null?void 0:e.click,t.click,L("boolean","breadcrumbs.click",r)),keyboardInput:E(e==null?void 0:e.keyboardInput,t.keyboardInput,L("boolean","breadcrumbs.keyboardInput",r)),http:dt(e==null?void 0:e.http,t.http,r),filters:E(e==null?void 0:e.filters,t.filters,n=>Array.isArray(n)?!0:(r==null||r.warn(D("breadcrumbs.filters","BreadcrumbFilter[]",typeof n)),!1))}}function W(e,t){let r=mt();return e.breadcrumbs&&L("object","breadcrumbs",t)(e.breadcrumbs),e.stack&&L("object","stack",t)(e.stack),{breadcrumbs:ht(e.breadcrumbs,r.breadcrumbs,t),stack:gt(e.stack,r.stack,t),maxPendingEvents:E(e.maxPendingEvents,r.maxPendingEvents,L("number","maxPendingEvents",t)),collectors:[...E(e.collectors,r.collectors,n=>Array.isArray(n)?!0:(t==null||t.warn(D("collectors","Collector[]",typeof n)),!1))],logger:pt(e),errorFilters:E(e.errorFilters,r.errorFilters,n=>Array.isArray(n)?!0:(t==null||t.warn(D("errorFilters","ErrorDataFilter[]",typeof n)),!1))}}var G,fe=!1;function Lr(e){let t=C(e==null?void 0:e.logger);if(G){t.warn(k("Telemetry has already been initialized. Ignoring new options."));return}let r=W(e||{},t);G=new O(r)}function F(){if(!G){if(fe)return;w.warn(k("Telemetry has not been initialized")),fe=!0;return}return G}function _r(){G=void 0,fe=!1}function wr(){var e;return((e=F())==null?void 0:e.inspectors())||[]}function Sr(e){var t;(t=F())==null||t.captureError(e)}function Or(e){var t;(t=F())==null||t.captureErrorEvent(e)}function Fr(e){var t;(t=F())==null||t.addBreadcrumb(e)}function Br(e){var t;(t=F())==null||t.register(e)}function Ir(){var e;(e=F())==null||e.close()}function $r(e){let t=W(e||{},C(e==null?void 0:e.logger));return new O(t)}export{Fr as addBreadcrumb,Sr as captureError,Or as captureErrorEvent,Ir as close,F as getTelemetryInstance,Lr as initTelemetry,$r as initTelemetryInstance,wr as inspectors,Br as register,_r as resetTelemetryInstance};
11
11
  /**
12
12
  * https://github.com/csnover/TraceKit
13
13
  * @license MIT