@bugban/js 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.cjs +79 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +79 -21
- package/dist/index.js.map +1 -1
- package/dist/standalone/bugban.global.js +3 -3
- package/dist/standalone/bugban.global.js.map +1 -1
- package/package.json +21 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var BugbanSDK=(()=>{var I=Object.defineProperty,
|
|
2
|
-
`);for(let o of r){if(t.length>=e)break;let s=o.replace(/\r$/,"");if(!s.trim()||!/^\s*at\s/.test(s)&&s.indexOf("@")===-1)continue;let i=
|
|
3
|
-
`,!(e.length>n));s++);}catch(o){continue}}catch(t){}return e.length>n?e.slice(0,n):e}function ie(n){if(!f||!n.enabled)return null;try{let e=document.documentElement;if(!e)return null;let t=e.cloneNode(!0);ze(e,t),n.maskInputs&&$e(t),n.maskSelectors&&n.maskSelectors.length&&Ge(t,n.maskSelectors);for(let s of De){let i=t.getElementsByTagName(s);for(;i.length>0;){let c=i[0];if(c.parentNode)c.parentNode.removeChild(c);else break}}try{let s=t.querySelector("head");if(s&&!s.querySelector("base")){let i=document.createElement("base");i.setAttribute("href",document.baseURI||location.href),s.insertBefore(i,s.firstChild)}}catch(s){}let r=t.outerHTML||"";if(r.length>n.maxBytes)return null;let o=Xe(Math.max(0,n.maxBytes-r.length));return{kind:"dom",html:r,css:o||void 0,viewport:{width:window.innerWidth,height:window.innerHeight,scrollX:window.scrollX||0,scrollY:window.scrollY||0},url:location.href,taken_at:b()}}catch(e){return null}}var Ye={LCP:[2500,4e3],FCP:[1800,3e3],CLS:[.1,.25],INP:[200,500],TTFB:[800,1800]};function ae(n,e){let t=Ye[n];if(t)return e<=t[0]?"good":e<=t[1]?"needs-improvement":"poor"}var j=class{constructor(e,t){this.opts=e;this.flush=t;this.metrics=[];this.observers=[];this.flushed=!1;this.latest={}}start(){!f||!this.opts.enabled||typeof PerformanceObserver=="function"&&(this.observeTtfb(),this.observePaint(),this.observeLcp(),this.observeCls(),this.observeInp(),this.observeLongTasks(),this.observeResources(),this.installFlushTriggers())}stop(){for(let e of this.observers)a(()=>e.disconnect());this.observers=[]}push(e){var t,r,o;try{this.metrics.push(x(m({},e),{rating:(t=e.rating)!=null?t:ae(e.name,e.value),url:(r=e.url)!=null?r:location.href,occurred_at:(o=e.occurred_at)!=null?o:b()}))}catch(s){}}set(e,t,r={}){this.latest[e]=m({name:e,value:Math.round(t*1e3)/1e3,rating:ae(e,t),url:a(()=>location.href),occurred_at:b()},r)}observe(e,t,r=!0){a(()=>{let o=new PerformanceObserver(s=>a(()=>t(s.getEntries())));o.observe({type:e,buffered:r}),this.observers.push(o)})}observeTtfb(){a(()=>{let e=performance.getEntriesByType("navigation")[0];e&&typeof e.responseStart=="number"&&e.responseStart>0&&this.set("TTFB",e.responseStart,{navigation_type:e.type})})}observePaint(){this.observe("paint",e=>{for(let t of e)t.name==="first-contentful-paint"&&this.set("FCP",t.startTime)})}observeLcp(){this.observe("largest-contentful-paint",e=>{let t=e[e.length-1];t&&this.set("LCP",t.startTime,{target:A(t.element),data:{size:t.size,url:t.url||void 0}})})}observeCls(){let e=0,t=0,r=[];this.observe("layout-shift",o=>{var s;for(let i of o){if(i.hadRecentInput)continue;let c=r[0],l=r[r.length-1];if(t&&i.startTime-l.startTime<1e3&&i.startTime-c.startTime<5e3?(t+=i.value,r.push(i)):(t=i.value,r=[i]),t>e){e=t;let u=r.slice().sort((p,h)=>h.value-p.value)[0];this.set("CLS",e,{target:(s=u==null?void 0:u.sources)!=null&&s[0]?A(u.sources[0].node):void 0})}}})}observeInp(){let e=0;this.observe("event",t=>{for(let r of t){let o=r.duration;typeof o!="number"||o<=e||(e=o,this.set("INP",o,{target:A(r.target),data:{interaction:r.name}}))}})}observeLongTasks(){this.observe("longtask",e=>{var t,r;for(let o of e)o.duration<this.opts.longTaskMs||this.push({name:"LONG_TASK",value:Math.round(o.duration),rating:o.duration>200?"poor":"needs-improvement",target:((r=(t=o.attribution)==null?void 0:t[0])==null?void 0:r.containerName)||void 0,data:{start:Math.round(o.startTime)}})})}observeResources(){this.observe("resource",e=>{for(let t of e)t.duration<this.opts.slowResourceMs||t.name.indexOf("/api/ingest/")===-1&&this.push({name:"RESOURCE",value:Math.round(t.duration),rating:t.duration>3e3?"poor":"needs-improvement",target:t.name,data:{type:t.initiatorType,size:t.transferSize||void 0,cached:t.transferSize===0&&t.decodedBodySize>0}})})}installFlushTriggers(){let e=()=>this.flushNow();a(()=>{document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&e()},{capture:!0}),window.addEventListener("pagehide",e,{capture:!0})})}flushNow(){if(!this.flushed)try{let e=this.metrics.concat(Object.keys(this.latest).map(t=>this.latest[t]));if(e.length===0)return;this.flushed=!0,this.metrics=[],this.latest={},this.flush(e)}catch(e){}}};var Je={log:"info",info:"info",debug:"debug",warn:"warning",error:"error"};function ce(n,e){if(typeof console=="undefined")return()=>{};let t={},r=!1;for(let o of n.levels){let s=console[o];typeof s=="function"&&(t[o]=s,console[o]=function(...i){try{if(!r){r=!0;let c=Je[o]||"info",l=i.map(u=>typeof u=="string"?u:w(u,200)).join(" ");e.breadcrumb(c,w(l,500),i),(o==="error"||o==="warn")&&n.captureAsEvent.indexOf(o)!==-1&&e.capture(c,l,i),r=!1}}catch(c){r=!1}return a(()=>s.apply(console,i))})}return()=>{for(let o in t)a(()=>{console[o]=t[o]})}}var We=["password","passwd","pwd","secret","token","access_token","refresh_token","api_key","apikey","authorization","auth","cookie","set-cookie","session","csrf","xsrf","card","card_number","cardnumber","cvv","cvc","pin","ssn","iban"],ue="[redacted]";function le(n,e){let t=n.toLowerCase();for(let r of We)if(t.indexOf(r)!==-1)return!0;for(let r of e)if(r&&t.indexOf(r.toLowerCase())!==-1)return!0;return!1}function k(n,e=[],t=0){if(t>6||n==null)return n;try{if(Array.isArray(n))return n.slice(0,100).map(r=>k(r,e,t+1));if(typeof n=="object"){let r=n,o={},s=0;for(let i in r)if(Object.prototype.hasOwnProperty.call(r,i)){if(++s>100)break;o[i]=le(i,e)?ue:k(r[i],e,t+1)}return o}}catch(r){}return n}function v(n,e=[]){try{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(n),r=new URL(n,t?void 0:"http://localhost");return(r.username||r.password)&&(r.username="",r.password=""),r.searchParams.forEach((o,s)=>{le(s,e)&&r.searchParams.set(s,ue)}),t?r.toString():r.pathname+r.search+r.hash}catch(t){return n}}function de(n,e,t,r){let o=[],s=c=>c.indexOf("/api/ingest/")!==-1||r&&c.indexOf(r)===0?!0:P(c,n.ignoreUrls),i=(c,l,u,p,h)=>{try{let y=v(l,t),S=Math.round(G()-p),E=h||typeof u=="number"&&u>=400,z={method:c,url:y,status_code:u,duration_ms:S},X=`${c} ${y} \u2192 ${h?"failed":u} (${S}ms)`;e.breadcrumb(X,z,E),n.captureFailures&&(h||u!==void 0&&u>=500)&&e.capture(X,z)}catch(y){}};if(n.enabled&&typeof fetch=="function"){let c=fetch,l=function(u,p){let h="",y="GET",S=G();try{h=typeof u=="string"?u:u&&u.url?u.url:String(u),y=String(p&&p.method||u&&u.method||"GET").toUpperCase()}catch(E){}return!h||s(h)?c.apply(this,[u,p]):c.apply(this,[u,p]).then(E=>(i(y,h,E?E.status:void 0,S,!1),E),E=>{throw i(y,h,void 0,S,!0),E})};globalThis.fetch=l,o.push(()=>{globalThis.fetch=c})}if(n.enabled&&typeof XMLHttpRequest=="function"){let c=XMLHttpRequest.prototype,l=c.open,u=c.send;c.open=function(p,h,...y){return a(()=>{this.__bugban={method:String(p||"GET").toUpperCase(),url:String(h||"")}}),l.apply(this,[p,h,...y])},c.send=function(...p){let h=a(()=>this.__bugban);if(h&&h.url&&!s(h.url)){let y=G();a(()=>{this.addEventListener("loadend",()=>{let S=this.status||void 0;i(h.method,h.url,S,y,!S)})})}return u.apply(this,p)},o.push(()=>{c.open=l,c.send=u})}return()=>{for(let c of o)a(c)}}function G(){try{return typeof performance!="undefined"&&typeof performance.now=="function"?performance.now():Date.now()}catch(n){return Date.now()}}function fe(n){let e=[];if(f){let t=o=>{a(()=>{let s=o.error||{name:"Error",message:o.message,stack:void 0};n.capture(s,{handled:!1,type:"onerror"})})},r=o=>{a(()=>{let s=o.reason;n.capture(s,{handled:!1,type:"unhandledrejection"})})};a(()=>window.addEventListener("error",t,!0)),a(()=>window.addEventListener("unhandledrejection",r,!0)),e.push(()=>{a(()=>window.removeEventListener("error",t,!0)),a(()=>window.removeEventListener("unhandledrejection",r,!0))})}if(g){let t=o=>{n.capture(o,{handled:!1,type:"uncaughtException"}),a(()=>{n.flush().then(()=>{process.listenerCount("uncaughtException")<=1&&process.exit(1)})})},r=o=>{n.capture(o,{handled:!1,type:"unhandledRejection"})};a(()=>process.on("uncaughtException",t)),a(()=>process.on("unhandledRejection",r)),a(()=>process.on("beforeExit",()=>{n.flush()})),e.push(()=>{a(()=>process.off("uncaughtException",t)),a(()=>process.off("unhandledRejection",r))})}return()=>{for(let t of e)a(t)}}function Qe(n){return a(()=>{let e=n.getAttribute("aria-label");if(e)return w(e,60);let t=n.tagName.toLowerCase();if(t==="input"||t==="textarea"||t==="select"){let o=n.getAttribute("placeholder")||n.getAttribute("name")||"";return o?`${t}[${w(o,40)}]`:t}let r=(n.textContent||"").trim().replace(/\s+/g," ");return r?w(r,60):t})||"element"}function pe(n){if(!f)return()=>{};let e=[],t=s=>{a(()=>{let i=s.target;if(!i||typeof i.tagName!="string")return;let c=i;for(let u=0;u<4&&c;u++){let p=c.tagName.toLowerCase();if(p==="button"||p==="a"||c.getAttribute("role")==="button")break;c=c.parentElement}let l=c||i;n.click(Qe(l),{selector:A(l),href:a(()=>l.getAttribute("href"))||void 0})})};a(()=>document.addEventListener("click",t,{capture:!0,passive:!0})),e.push(()=>a(()=>document.removeEventListener("click",t,!0)));let r=a(()=>location.href)||"",o=()=>{a(()=>{let s=location.href;s!==r&&(n.navigate(r,s),r=s)})};return a(()=>{let s=window.history,i=s.pushState,c=s.replaceState;typeof i=="function"&&(s.pushState=function(...l){let u=i.apply(this,l);return o(),u},e.push(()=>{s.pushState=i})),typeof c=="function"&&(s.replaceState=function(...l){let u=c.apply(this,l);return o(),u},e.push(()=>{s.replaceState=c}))}),a(()=>window.addEventListener("popstate",o)),e.push(()=>a(()=>window.removeEventListener("popstate",o))),()=>{for(let s of e)a(s)}}var he="bugban.ping",L=!1;async function Ze(n,e){let t=`${n.slice(0,12)}:${e}`;if(f)return a(()=>localStorage.getItem(he))===t||(a(()=>localStorage.setItem(he,t)),L)?!0:(L=!0,!1);if(g)try{let[r,o,s]=await Promise.all([nodeModule("fs"),nodeModule("os"),nodeModule("path")]);if(!r||!o||!s||typeof r.existsSync!="function")return L?!0:(L=!0,!1);let i=et(t).slice(0,32),c=s.join(o.tmpdir(),`.bugban-ping-${i}`);return r.existsSync(c)?!0:(r.writeFileSync(c,t),!1)}catch(r){return!1}return L?!0:(L=!0,!1)}function et(n){let e="";for(let t=0;t<n.length;t++)e+=n.charCodeAt(t).toString(16);return e}async function me(n,e){if(!(!n.installPing||!n.enabled))try{if(await Ze(n.apiKey,T))return;let t=await Z(),r=await Q(),o={sdk:_,sdk_version:T,framework:n.framework||B(),framework_version:n.frameworkVersion,environment:n.environment,hostname:r,app_name:t.name||(f?a(()=>location.hostname):void 0),app_version:n.release||t.version,runtime:B(),runtime_version:C()};for(let s in o)(o[s]==null||o[s]==="")&&delete o[s];e.send("/api/ingest/ping",o)}catch(t){}}var N=class{constructor(e={}){this.teardown=[];this.user=null;this.context={};this.sessionId=re();this.startedAt=Date.now();this.queue=[];this.flushTimer=null;this.sending=!1;this.started=!1;this.opts=ne(e),this.transport=new q(this.opts.host,this.opts.apiKey,this.opts.debug),this.crumbs=new U(this.opts.maxBreadcrumbs)}get options(){return this.opts}start(){if(!this.started){if(this.started=!0,!this.opts.enabled){this.debug("disabled (no API key)");return}a(()=>this.installIntegrations()),a(()=>me(this.opts,this.transport))}}installIntegrations(){let e=this.opts;e.globalHandlers&&this.teardown.push(fe({capture:(t,r)=>this.capture(t,r),flush:()=>this.flush()})),e.console&&this.teardown.push(ce(e.console,{breadcrumb:(t,r)=>this.addBreadcrumb({type:"console",level:t,message:r}),capture:(t,r,o)=>{let s=o.find(i=>i instanceof Error);this.capture(s!=null?s:r,{handled:!0,type:"console",level:t})}})),e.network&&this.teardown.push(de(e.network,{breadcrumb:(t,r,o)=>this.addBreadcrumb({type:"http",level:o?"error":"info",message:t,data:r}),capture:(t,r)=>this.capture(new Error(t),{handled:!0,type:"http",context:r})},e.redactKeys,e.host)),e.domBreadcrumbs&&this.teardown.push(pe({click:(t,r)=>this.addBreadcrumb({type:"click",message:`Clicked ${t}`,data:r}),navigate:(t,r)=>this.addBreadcrumb({type:"navigation",message:`${v(t,e.redactKeys)} \u2192 ${v(r,e.redactKeys)}`})})),e.vitals&&f&&(H(e.vitals.sampleRate)?(this.vitals=new j(e.vitals,t=>this.sendVitals(t)),this.vitals.start(),this.teardown.push(()=>{var t;return(t=this.vitals)==null?void 0:t.stop()})):this.debug("vitals not sampled for this session")),f&&this.teardown.push(this.installUnloadFlush())}installUnloadFlush(){let e=()=>{document.visibilityState==="hidden"&&this.drain(!0)},t=()=>{this.drain(!0)};return a(()=>document.addEventListener("visibilitychange",e,!0)),a(()=>window.addEventListener("pagehide",t,!0)),()=>{a(()=>document.removeEventListener("visibilitychange",e,!0)),a(()=>window.removeEventListener("pagehide",t,!0))}}addBreadcrumb(e){this.opts.enabled&&a(()=>{let t=x(m({},e),{data:e.data?k(e.data,this.opts.redactKeys):void 0,timestamp:e.timestamp||b()});if(this.opts.beforeBreadcrumb){let r=this.opts.beforeBreadcrumb(t);if(!r)return;t=r}this.crumbs.add(t)})}setUser(e){a(()=>{this.user=e?k(e,this.opts.redactKeys):null})}setContext(e,t){a(()=>{this.context[e]=k(t,this.opts.redactKeys)})}captureMessage(e,t="info"){this.capture(new Error(e),{handled:!0,level:t,type:"message"})}capture(e,t={}){this.opts.enabled&&(this.sending||a(()=>{var c;let r=F(e);if(this.opts.ignoreErrors.length&&P(r.message,this.opts.ignoreErrors)||!H(this.opts.sampleRate))return;let o=V(r.stack),s=o.find(l=>l.in_app)||o[0],i={exception_class:r.name,message:w(r.message,2e3),level:t.level||"error",type:t.type||"error",handled:(c=t.handled)!=null?c:!0,file:s==null?void 0:s.file,line:s==null?void 0:s.line,stacktrace:o,release:this.opts.release,environment:this.opts.environment,user:this.user,breadcrumbs:this.crumbs.all(),device:K(),session:{id:this.sessionId,started_at:new Date(this.startedAt).toISOString(),duration_ms:Date.now()-this.startedAt},request:t.request||this.requestInfo(),context:m(m({},this.context),t.context?k(t.context,this.opts.redactKeys):{}),snapshot:this.opts.snapshot?ie(this.opts.snapshot):null};if(this.opts.beforeSend){let l=this.opts.beforeSend(i);if(!l)return;i=l}this.enqueue(i)}))}async flush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),await this.drain(!1),a(()=>{var e;return(e=this.vitals)==null?void 0:e.flushNow()})}close(){for(let e of this.teardown)a(e);this.teardown=[],this.started=!1}recordMetric(e){a(()=>{var t;return(t=this.vitals)==null?void 0:t.push(e)})}requestInfo(){if(f)return a(()=>({url:v(location.href,this.opts.redactKeys),referrer:document.referrer?v(document.referrer,this.opts.redactKeys):void 0,method:"GET"}))}enqueue(e){this.queue.push(e),this.queue.length>50&&this.queue.splice(0,this.queue.length-50),!this.flushTimer&&(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain(!1)},300),a(()=>{let t=this.flushTimer;t&&typeof t.unref=="function"&&t.unref()}))}async drain(e){if(this.queue.length===0)return;let t=this.queue.splice(0,this.queue.length);this.sending=!0;try{await this.transport.send("/api/ingest/events",{events:t},{beacon:e})}finally{this.sending=!1}}sendVitals(e){a(()=>{let t=[],r=[];for(let s of e)if(s.name==="SLOW_QUERY"){let i=s.data||{};t.push({sql:i.sql,duration_ms:s.value,connection:i.connection,bindings:i.bindings,url:i.url,method:i.method,occurred_at:s.occurred_at})}else r.push(s);let o=a(()=>v(location.href,this.opts.redactKeys));t.length&&this.transport.send("/api/ingest/queries",{queries:t},{beacon:!0}),r.length&&this.transport.send("/api/ingest/vitals",{vitals:r,url:o,release:this.opts.release,environment:this.opts.environment,session_id:this.sessionId,device:K()},{beacon:!0})})}debug(...e){this.opts.debug&&a(()=>console.info("[bugban]",...e))}};var d=null;function ge(n={}){return d&&a(()=>d.close()),d=new N(n),d.start(),d}function ye(){return d}function ve(n,e){d==null||d.capture(n,e)}function be(n,e="info"){d==null||d.captureMessage(n,e)}function we(n){d==null||d.setUser(n)}function ke(n,e){d==null||d.setContext(n,e)}function Se(n){d==null||d.addBreadcrumb(n)}function Ee(n){d==null||d.recordMetric(n)}async function xe(){await(d==null?void 0:d.flush())}function Te(){d==null||d.close(),d=null}var tt={VERSION:T,init:ge,getClient:ye,capture:ve,captureMessage:be,setUser:we,setContext:ke,addBreadcrumb:Se,recordMetric:Ee,flush:xe,close:Te};return Ce(nt);})();
|
|
1
|
+
"use strict";var BugbanSDK=(()=>{var I=Object.defineProperty,Be=Object.defineProperties,_e=Object.getOwnPropertyDescriptor,Ae=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var Y=(n,e,t)=>e in n?I(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,h=(n,e)=>{for(var t in e||(e={}))J.call(e,t)&&Y(n,t,e[t]);if(X)for(var t of X(e))Le.call(e,t)&&Y(n,t,e[t]);return n},x=(n,e)=>Be(n,Ae(e));var Ce=(n,e)=>{for(var t in e)I(n,t,{get:e[t],enumerable:!0})},Ie=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ne(e))!J.call(n,o)&&o!==t&&I(n,o,{get:()=>e[o],enumerable:!(r=_e(e,o))||r.enumerable});return n};var Me=n=>Ie(I({},"__esModule",{value:!0}),n);var st={};Ce(st,{Bugban:()=>ot,BugbanClient:()=>N,SDK_NAME:()=>L,SDK_VERSION:()=>T,addBreadcrumb:()=>xe,capture:()=>we,captureMessage:()=>ke,close:()=>Re,dependencyVersion:()=>ee,flush:()=>Oe,getClient:()=>ve,init:()=>be,normalizeError:()=>j,parseStack:()=>V,recordMetric:()=>Te,redact:()=>k,redactUrl:()=>y,runtimeName:()=>B,runtimeVersion:()=>C,setContext:()=>Ee,setUser:()=>Se});var L="bugban-js",T="1.0.1",f=(()=>{try{return typeof window!="undefined"&&typeof window.document!="undefined"}catch(n){return!1}})(),m=(()=>{try{return typeof process!="undefined"&&process.versions!=null&&process.versions.node!=null}catch(n){return!1}})();function B(){return f?"browser":m?"node":"unknown"}function C(){try{if(m)return process.versions.node;if(f)return navigator.userAgent}catch(n){}}async function R(n){if(!m)return;let e="node:".concat(n);for(let t of[e,String(n)])try{let r=await import(t);if(r)return r.default&&!r.hostname&&!r.existsSync?r.default:r}catch(r){}return Pe(n)}async function Q(){try{if(f)return window.location.hostname;if(m){let n=await R("os");if(n&&typeof n.hostname=="function")return String(n.hostname())}}catch(n){}}async function Z(){if(!m)return{};try{let n=await R("fs"),e=await R("path");if(!n||!e||typeof n.existsSync!="function")return{};let t=process.cwd();for(let r=0;r<6;r++){let o=e.join(t,"package.json");if(n.existsSync(o)){let i=JSON.parse(n.readFileSync(o,"utf8"));return{name:i.name,version:i.version}}let s=e.dirname(t);if(s===t)break;t=s}}catch(n){}return{}}async function ee(n){if(m)try{let e=await R("module");if(e&&typeof e.createRequire=="function"){let r=e.createRequire(process.cwd()+"/package.json")(`${n}/package.json`);return r&&r.version?String(r.version):void 0}}catch(e){}}function O(n){try{if(typeof process!="undefined"&&process.env){let e=process.env[n];return e==null||e===""?void 0:String(e)}}catch(e){}}function Pe(n){try{let e=typeof module!="undefined"&&typeof module.require=="function"?module.require:typeof globalThis.require=="function"?globalThis.require:void 0;return e?e(n):void 0}catch(e){return}}function K(){var e,t;let n={sdk:L,sdk_version:T,runtime:B(),runtime_version:C()};try{f&&(n.user_agent=navigator.userAgent,n.language=navigator.language,n.screen={width:(e=window.screen)==null?void 0:e.width,height:(t=window.screen)==null?void 0:t.height},n.viewport={width:window.innerWidth,height:window.innerHeight},n.online=navigator.onLine),m&&(n.platform=process.platform,n.arch=process.arch,n.pid=process.pid)}catch(r){}return n}function M(n,e,t){return n===!1?!1:n===!0||n===void 0?t||n===!0?e:!1:h(h({},e),n)}var qe={levels:["log","info","warn","error","debug"],captureAsEvent:f?["error"]:[]},Ue={enabled:!0,captureFailures:!0,ignoreUrls:[]},Ve={enabled:!0,maskInputs:!0,maskSelectors:[],maxBytes:5e5},je={enabled:!0,sampleRate:.2,longTaskMs:100,slowResourceMs:1e3};function ne(n={}){var r,o;let e=n.apiKey||O("BUGBAN_API_KEY")||O("NEXT_PUBLIC_BUGBAN_API_KEY")||"",t=n.host||O("BUGBAN_HOST")||O("NEXT_PUBLIC_BUGBAN_HOST")||"https://bugban.online";return x(h({},n),{apiKey:e,host:t.replace(/\/+$/,""),release:n.release||O("BUGBAN_RELEASE"),environment:n.environment||O("BUGBAN_ENV")||O("NODE_ENV")||"production",enabled:n.enabled!==!1&&e!=="",debug:n.debug===!0,maxBreadcrumbs:te((r=n.maxBreadcrumbs)!=null?r:50,1,200),sampleRate:te((o=n.sampleRate)!=null?o:1,0,1),console:M(n.console,qe,!0),network:M(n.network,Ue,!0),snapshot:M(n.snapshot,Ve,!0),vitals:M(n.vitals,je,!0),globalHandlers:n.globalHandlers!==!1,domBreadcrumbs:n.domBreadcrumbs!==!1,installPing:n.installPing!==!1,redactKeys:n.redactKeys||[],ignoreErrors:n.ignoreErrors||[]})}function te(n,e,t){return typeof n!="number"||isNaN(n)?e:Math.min(t,Math.max(e,n))}function a(n,e){try{return n()}catch(t){return e}}function v(){try{return new Date().toISOString()}catch(n){return""}}function w(n,e){let t=typeof n=="string"?n:Fe(n);return t.length>e?t.slice(0,e)+"\u2026":t}function Fe(n,e=2e3){try{let t=new WeakSet,r=JSON.stringify(n,(o,s)=>{if(typeof s=="bigint")return s.toString();if(typeof s=="function")return"[Function]";if(s instanceof Error)return{name:s.name,message:s.message};if(typeof s=="object"&&s!==null){if(t.has(s))return"[Circular]";t.add(s)}return s});return r==null?String(n):r.length>e?r.slice(0,e)+"\u2026":r}catch(t){try{return String(n)}catch(r){return"[unserializable]"}}}function P(n,e){for(let t of e)try{if(typeof t=="string"){if(n.indexOf(t)!==-1)return!0}else if(t.test(n))return!0}catch(r){}return!1}function re(){try{let n=globalThis.crypto;if(n&&typeof n.randomUUID=="function")return n.randomUUID();if(n&&typeof n.getRandomValues=="function"){let e=new Uint8Array(16);return n.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}}catch(n){}return Math.random().toString(36).slice(2)+Date.now().toString(36)}function H(n){return n>=1?!0:n<=0?!1:Math.random()<n}function _(n){try{let e=n;if(!e||typeof e.tagName!="string")return;let t=e.tagName.toLowerCase();if(e.id)return`${t}#${e.id}`;if(typeof e.className=="string"&&e.className.trim()){let r=e.className.trim().split(/\s+/).slice(0,2).join(".");r&&(t+=`.${r}`)}return t}catch(e){return}}function Ke(n){try{if(typeof TextEncoder=="function")return new TextEncoder().encode(n).length}catch(t){}try{let t=globalThis.Buffer;if(t&&typeof t.byteLength=="function")return t.byteLength(n)}catch(t){}let e=0;for(let t=0;t<n.length;t++){let r=n.charCodeAt(t);r<128?e+=1:r<2048?e+=2:r>=55296&&r<=56319?(e+=4,t++):e+=3}return e}var q=class{constructor(e,t,r=!1){this.host=e;this.apiKey=t;this.debug=r}async send(e,t,r={}){let o=this.host.replace(/\/+$/,"")+e,s;try{s=JSON.stringify(t)}catch(i){return!1}return r.beacon&&f&&a(()=>{let c=navigator;if(typeof c.sendBeacon!="function")return!1;let l=new Blob([JSON.stringify(x(h({},t),{_key:this.apiKey}))],{type:"text/plain;charset=UTF-8"});return c.sendBeacon(o,l)},!1)?!0:typeof fetch=="function"?this.viaFetch(o,s,r):m?this.viaNodeHttp(o,s,r):(this.log("no transport available"),!1)}async viaFetch(e,t,r){var o;try{let s=typeof AbortController=="function"?new AbortController:void 0,i=s?setTimeout(()=>a(()=>s.abort()),(o=r.timeoutMs)!=null?o:8e3):void 0,c=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json","X-Bugban-Key":this.apiKey},body:t,keepalive:r.beacon===!0,signal:s?s.signal:void 0,credentials:"omit",mode:"cors"});return i&&clearTimeout(i),c.ok||this.log("ingest rejected",c.status),c.ok}catch(s){return this.log("fetch failed",s),!1}}async viaNodeHttp(e,t,r){let o=e.indexOf("https://")===0,s=await R(o?"https":"http");return!s||typeof s.request!="function"?!1:new Promise(i=>{var c;try{let l=new URL(e),u=s.request({method:"POST",hostname:l.hostname,port:l.port||(o?443:80),path:l.pathname+l.search,timeout:(c=r.timeoutMs)!=null?c:8e3,headers:{"Content-Type":"application/json","Content-Length":Ke(t),"X-Bugban-Key":this.apiKey}},d=>{d.resume(),i(d.statusCode>=200&&d.statusCode<300)});u.on("error",()=>i(!1)),u.on("timeout",()=>{a(()=>u.destroy()),i(!1)}),u.write(t),u.end()}catch(l){i(!1)}})}log(...e){this.debug&&a(()=>console.warn("[bugban]",...e))}};var U=class{constructor(e){this.max=e;this.items=[]}add(e){try{let t={type:e.type,message:e.message,level:e.level,data:e.data,timestamp:e.timestamp||v()};this.items.push(t),this.items.length>this.max&&this.items.splice(0,this.items.length-this.max)}catch(t){}}all(){return this.items.slice()}clear(){this.items=[]}setMax(e){this.max=e,this.items.length>e&&this.items.splice(0,this.items.length-e)}};var He=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?\s*$/,De=/^\s*(?:(.*?)@)?(.+?):(\d+):(\d+)\s*$/,$e=["node_modules","webpack-internal","webpack://","/.next/","/.nuxt/","node:internal","internal/process"];function oe(n){if(!n)return!1;for(let e of $e)if(n.indexOf(e)!==-1)return!1;return!0}function D(n,e,t,r){let o={file:e||void 0,line:t?parseInt(t,10):void 0,column:r?parseInt(r,10):void 0,in_app:oe(e)};return n&&n!=="<anonymous>"&&(o.function=n.trim()),o}function V(n,e=50){if(typeof n!="string"||n==="")return[];let t=[],r=n.split(`
|
|
2
|
+
`);for(let o of r){if(t.length>=e)break;let s=o.replace(/\r$/,"");if(!s.trim()||!/^\s*at\s/.test(s)&&s.indexOf("@")===-1)continue;let i=He.exec(s);if(i){if(i[5]&&!i[2]){let c=/^(.*?):(\d+):(\d+)$/.exec(i[5]);t.push(c?D(i[1],c[1],c[2],c[3]):{function:i[1],file:i[5],in_app:oe(i[5])})}else t.push(D(i[1],i[2]||"",i[3]||"",i[4]||""));continue}if(i=De.exec(s),i){t.push(D(i[1],i[2]||"",i[3]||"",i[4]||""));continue}t.push({function:s.trim(),in_app:!1})}return t}function j(n){if(n instanceof Error)return{name:n.name||"Error",message:n.message||String(n),stack:n.stack};if(typeof n=="string")return{name:"Error",message:n};if(n&&typeof n=="object"){let e=n;if(typeof e.message=="string")return{name:typeof e.name=="string"?e.name:"Error",message:e.message,stack:typeof e.stack=="string"?e.stack:void 0};try{return{name:"Error",message:JSON.stringify(e)}}catch(t){return{name:"Error",message:"[object]"}}}return{name:"Error",message:String(n)}}var $="\u2022",Ge=["SCRIPT","NOSCRIPT","TEMPLATE"];function se(n){let e=Math.min(n.length,12);return e>0?$.repeat(e):""}function ze(n){let e=n.querySelectorAll("input, textarea, select");for(let t=0;t<e.length;t++){let r=e[t];try{let o=(r.getAttribute("type")||"").toLowerCase();if(o==="password"){r.setAttribute("value",$.repeat(8));continue}if(o==="checkbox"||o==="radio"||o==="submit"||o==="button")continue;let s=r.getAttribute("value")||"";s&&r.setAttribute("value",se(s)),r.tagName==="TEXTAREA"&&r.textContent&&(r.textContent=se(r.textContent))}catch(o){}}}function We(n,e){for(let t of e)try{let r=n.querySelectorAll(t);for(let o=0;o<r.length;o++){let s=r[o];s.textContent&&(s.textContent=$.repeat(6))}}catch(r){}}function Xe(n,e){try{let t=n.querySelectorAll("input, textarea, select"),r=e.querySelectorAll("input, textarea, select"),o=Math.min(t.length,r.length);for(let s=0;s<o;s++){let i=t[s],c=r[s];if(i.tagName==="SELECT"){c.setAttribute("data-bugban-selected",String(i.selectedIndex));continue}typeof i.value=="string"&&i.value!==""&&c.setAttribute("value",i.value),i.checked&&c.setAttribute("checked","checked")}}catch(t){}}function Ye(n){let e="";try{let t=document.styleSheets;for(let r=0;r<t.length&&!(e.length>n);r++)try{let o=t[r].cssRules;if(!o)continue;for(let s=0;s<o.length&&(e+=o[s].cssText+`
|
|
3
|
+
`,!(e.length>n));s++);}catch(o){continue}}catch(t){}return e.length>n?e.slice(0,n):e}function ie(n){if(!f||!n.enabled)return null;try{let e=document.documentElement;if(!e)return null;let t=e.cloneNode(!0);Xe(e,t),n.maskInputs&&ze(t),n.maskSelectors&&n.maskSelectors.length&&We(t,n.maskSelectors);for(let s of Ge){let i=t.getElementsByTagName(s);for(;i.length>0;){let c=i[0];if(c.parentNode)c.parentNode.removeChild(c);else break}}try{let s=t.querySelector("head");if(s&&!s.querySelector("base")){let i=document.createElement("base");i.setAttribute("href",document.baseURI||location.href),s.insertBefore(i,s.firstChild)}}catch(s){}let r=t.outerHTML||"";if(r.length>n.maxBytes)return null;let o=Ye(Math.max(0,n.maxBytes-r.length));return{kind:"dom",html:r,css:o||void 0,viewport:{width:window.innerWidth,height:window.innerHeight,scrollX:window.scrollX||0,scrollY:window.scrollY||0},url:location.href,taken_at:v()}}catch(e){return null}}var Je={LCP:[2500,4e3],FCP:[1800,3e3],CLS:[.1,.25],INP:[200,500],TTFB:[800,1800]};function ae(n,e){let t=Je[n];if(t)return e<=t[0]?"good":e<=t[1]?"needs-improvement":"poor"}var F=class{constructor(e,t){this.opts=e;this.flush=t;this.metrics=[];this.observers=[];this.flushed=!1;this.latest={}}start(){!f||!this.opts.enabled||typeof PerformanceObserver=="function"&&(this.observeTtfb(),this.observePaint(),this.observeLcp(),this.observeCls(),this.observeInp(),this.observeLongTasks(),this.observeResources(),this.installFlushTriggers())}stop(){for(let e of this.observers)a(()=>e.disconnect());this.observers=[]}push(e){var t,r,o;try{this.metrics.push(x(h({},e),{rating:(t=e.rating)!=null?t:ae(e.name,e.value),url:(r=e.url)!=null?r:location.href,occurred_at:(o=e.occurred_at)!=null?o:v()}))}catch(s){}}set(e,t,r={}){this.latest[e]=h({name:e,value:Math.round(t*1e3)/1e3,rating:ae(e,t),url:a(()=>location.href),occurred_at:v()},r)}observe(e,t,r=!0){a(()=>{let o=new PerformanceObserver(s=>a(()=>t(s.getEntries())));o.observe({type:e,buffered:r}),this.observers.push(o)})}observeTtfb(){a(()=>{let e=performance.getEntriesByType("navigation")[0];e&&typeof e.responseStart=="number"&&e.responseStart>0&&this.set("TTFB",e.responseStart,{navigation_type:e.type})})}observePaint(){this.observe("paint",e=>{for(let t of e)t.name==="first-contentful-paint"&&this.set("FCP",t.startTime)})}observeLcp(){this.observe("largest-contentful-paint",e=>{let t=e[e.length-1];t&&this.set("LCP",t.startTime,{target:_(t.element),data:{size:t.size,url:t.url||void 0}})})}observeCls(){let e=0,t=0,r=[];this.observe("layout-shift",o=>{var s;for(let i of o){if(i.hadRecentInput)continue;let c=r[0],l=r[r.length-1];if(t&&i.startTime-l.startTime<1e3&&i.startTime-c.startTime<5e3?(t+=i.value,r.push(i)):(t=i.value,r=[i]),t>e){e=t;let u=r.slice().sort((d,p)=>p.value-d.value)[0];this.set("CLS",e,{target:(s=u==null?void 0:u.sources)!=null&&s[0]?_(u.sources[0].node):void 0})}}})}observeInp(){let e=0;this.observe("event",t=>{for(let r of t){let o=r.duration;typeof o!="number"||o<=e||(e=o,this.set("INP",o,{target:_(r.target),data:{interaction:r.name}}))}})}observeLongTasks(){this.observe("longtask",e=>{var t,r;for(let o of e)o.duration<this.opts.longTaskMs||this.push({name:"LONG_TASK",value:Math.round(o.duration),rating:o.duration>200?"poor":"needs-improvement",target:((r=(t=o.attribution)==null?void 0:t[0])==null?void 0:r.containerName)||void 0,data:{start:Math.round(o.startTime)}})})}observeResources(){this.observe("resource",e=>{for(let t of e)t.duration<this.opts.slowResourceMs||t.name.indexOf("/api/ingest/")===-1&&this.push({name:"RESOURCE",value:Math.round(t.duration),rating:t.duration>3e3?"poor":"needs-improvement",target:t.name,data:{type:t.initiatorType,size:t.transferSize||void 0,cached:t.transferSize===0&&t.decodedBodySize>0}})})}installFlushTriggers(){let e=()=>this.flushNow();a(()=>{document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&e()},{capture:!0}),window.addEventListener("pagehide",e,{capture:!0})})}flushNow(){if(!this.flushed)try{let e=this.metrics.concat(Object.keys(this.latest).map(t=>this.latest[t]));if(e.length===0)return;this.flushed=!0,this.metrics=[],this.latest={},this.flush(e)}catch(e){}}};var Qe={log:"info",info:"info",debug:"debug",warn:"warning",error:"error"};function Ze(n){for(let e of n)if(e instanceof Error)return!0;return!1}function ce(n,e){if(typeof console=="undefined")return()=>{};let t={},r=!1;for(let o of n.levels){let s=console[o];typeof s=="function"&&(t[o]=s,console[o]=function(...i){try{if(!r){r=!0;let c=Qe[o]||"info",l=i.map(u=>typeof u=="string"?u:w(u,200)).join(" ");if(e.breadcrumb(c,w(l,500),i),(o==="error"||o==="warn")&&n.captureAsEvent.indexOf(o)!==-1)if(Ze(i)){let u=()=>a(()=>e.capture(c,l,i));a(()=>{let d=setTimeout(u,50);d&&typeof d.unref=="function"&&d.unref()})}else e.capture(c,l,i);r=!1}}catch(c){r=!1}return a(()=>s.apply(console,i))})}return()=>{for(let o in t)a(()=>{console[o]=t[o]})}}var et=["password","passwd","pwd","secret","token","access_token","refresh_token","api_key","apikey","authorization","auth","cookie","set-cookie","session","csrf","xsrf","card","card_number","cardnumber","cvv","cvc","pin","ssn","iban"],ue="[redacted]";function le(n,e){let t=n.toLowerCase();for(let r of et)if(t.indexOf(r)!==-1)return!0;for(let r of e)if(r&&t.indexOf(r.toLowerCase())!==-1)return!0;return!1}function k(n,e=[],t=0){if(t>6||n==null)return n;try{if(Array.isArray(n))return n.slice(0,100).map(r=>k(r,e,t+1));if(typeof n=="object"){let r=n,o={},s=0;for(let i in r)if(Object.prototype.hasOwnProperty.call(r,i)){if(++s>100)break;o[i]=le(i,e)?ue:k(r[i],e,t+1)}return o}}catch(r){}return n}function y(n,e=[]){try{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(n),r=new URL(n,t?void 0:"http://localhost");return(r.username||r.password)&&(r.username="",r.password=""),r.searchParams.forEach((o,s)=>{le(s,e)&&r.searchParams.set(s,ue)}),t?r.toString():r.pathname+r.search+r.hash}catch(t){return n}}function de(n,e,t,r){let o=[],s=c=>c.indexOf("/api/ingest/")!==-1||r&&c.indexOf(r)===0?!0:P(c,n.ignoreUrls),i=(c,l,u,d,p)=>{try{let g=y(l,t),S=Math.round(G()-d),E=p||typeof u=="number"&&u>=400,z={method:c,url:g,status_code:u,duration_ms:S},W=`${c} ${g} \u2192 ${p?"failed":u} (${S}ms)`;e.breadcrumb(W,z,E),n.captureFailures&&(p||u!==void 0&&u>=500)&&e.capture(W,z)}catch(g){}};if(n.enabled&&typeof fetch=="function"){let c=fetch,l=function(u,d){let p="",g="GET",S=G();try{p=typeof u=="string"?u:u&&u.url?u.url:String(u),g=String(d&&d.method||u&&u.method||"GET").toUpperCase()}catch(E){}return!p||s(p)?c.apply(this,[u,d]):c.apply(this,[u,d]).then(E=>(i(g,p,E?E.status:void 0,S,!1),E),E=>{throw i(g,p,void 0,S,!0),E})};globalThis.fetch=l,o.push(()=>{globalThis.fetch=c})}if(n.enabled&&typeof XMLHttpRequest=="function"){let c=XMLHttpRequest.prototype,l=c.open,u=c.send;c.open=function(d,p,...g){return a(()=>{this.__bugban={method:String(d||"GET").toUpperCase(),url:String(p||"")}}),l.apply(this,[d,p,...g])},c.send=function(...d){let p=a(()=>this.__bugban);if(p&&p.url&&!s(p.url)){let g=G();a(()=>{this.addEventListener("loadend",()=>{let S=this.status||void 0;i(p.method,p.url,S,g,!S)})})}return u.apply(this,d)},o.push(()=>{c.open=l,c.send=u})}return()=>{for(let c of o)a(c)}}function G(){try{return typeof performance!="undefined"&&typeof performance.now=="function"?performance.now():Date.now()}catch(n){return Date.now()}}function fe(n){let e=[];if(f){let t=o=>{a(()=>{let s=o.error||{name:"Error",message:o.message,stack:void 0};n.capture(s,{handled:!1,type:"onerror"})})},r=o=>{a(()=>{let s=o.reason;n.capture(s,{handled:!1,type:"unhandledrejection"})})};a(()=>window.addEventListener("error",t,!0)),a(()=>window.addEventListener("unhandledrejection",r,!0)),e.push(()=>{a(()=>window.removeEventListener("error",t,!0)),a(()=>window.removeEventListener("unhandledrejection",r,!0))})}if(m){let t=o=>{n.capture(o,{handled:!1,type:"uncaughtException"}),a(()=>{n.flush().then(()=>{process.listenerCount("uncaughtException")<=1&&process.exit(1)})})},r=o=>{n.capture(o,{handled:!1,type:"unhandledRejection"})};a(()=>process.on("uncaughtException",t)),a(()=>process.on("unhandledRejection",r)),a(()=>process.on("beforeExit",()=>{n.flush()})),e.push(()=>{a(()=>process.off("uncaughtException",t)),a(()=>process.off("unhandledRejection",r))})}return()=>{for(let t of e)a(t)}}function tt(n){return a(()=>{let e=n.getAttribute("aria-label");if(e)return w(e,60);let t=n.tagName.toLowerCase();if(t==="input"||t==="textarea"||t==="select"){let o=n.getAttribute("placeholder")||n.getAttribute("name")||"";return o?`${t}[${w(o,40)}]`:t}let r=(n.textContent||"").trim().replace(/\s+/g," ");return r?w(r,60):t})||"element"}function pe(n){if(!f)return()=>{};let e=[],t=s=>{a(()=>{let i=s.target;if(!i||typeof i.tagName!="string")return;let c=i;for(let u=0;u<4&&c;u++){let d=c.tagName.toLowerCase();if(d==="button"||d==="a"||c.getAttribute("role")==="button")break;c=c.parentElement}let l=c||i;n.click(tt(l),{selector:_(l),href:a(()=>l.getAttribute("href"))||void 0})})};a(()=>document.addEventListener("click",t,{capture:!0,passive:!0})),e.push(()=>a(()=>document.removeEventListener("click",t,!0)));let r=a(()=>location.href)||"",o=()=>{a(()=>{let s=location.href;s!==r&&(n.navigate(r,s),r=s)})};return a(()=>{let s=window.history,i=s.pushState,c=s.replaceState;typeof i=="function"&&(s.pushState=function(...l){let u=i.apply(this,l);return o(),u},e.push(()=>{s.pushState=i})),typeof c=="function"&&(s.replaceState=function(...l){let u=c.apply(this,l);return o(),u},e.push(()=>{s.replaceState=c}))}),a(()=>window.addEventListener("popstate",o)),e.push(()=>a(()=>window.removeEventListener("popstate",o))),()=>{for(let s of e)a(s)}}var he="bugban.ping",A=!1;async function nt(n,e){let t=`${n.slice(0,12)}:${e}`;if(f)return a(()=>localStorage.getItem(he))===t||(a(()=>localStorage.setItem(he,t)),A)?!0:(A=!0,!1);if(m)try{let[r,o,s]=await Promise.all([nodeModule("fs"),nodeModule("os"),nodeModule("path")]);if(!r||!o||!s||typeof r.existsSync!="function")return A?!0:(A=!0,!1);let i=rt(t).slice(0,32),c=s.join(o.tmpdir(),`.bugban-ping-${i}`);return r.existsSync(c)?!0:(r.writeFileSync(c,t),!1)}catch(r){return!1}return A?!0:(A=!0,!1)}function rt(n){let e="";for(let t=0;t<n.length;t++)e+=n.charCodeAt(t).toString(16);return e}async function me(n,e){if(!(!n.installPing||!n.enabled))try{if(await nt(n.apiKey,T))return;let t=await Z(),r=await Q(),o={sdk:L,sdk_version:T,framework:n.framework||B(),framework_version:n.frameworkVersion,environment:n.environment,hostname:r,app_name:t.name||(f?a(()=>location.hostname):void 0),app_version:n.release||t.version,runtime:B(),runtime_version:C()};for(let s in o)(o[s]==null||o[s]==="")&&delete o[s];e.send("/api/ingest/ping",o)}catch(t){}}var N=class{constructor(e={}){this.teardown=[];this.user=null;this.context={};this.sessionId=re();this.startedAt=Date.now();this.queue=[];this.flushTimer=null;this.sending=!1;this.seen=new WeakSet;this.started=!1;this.opts=ne(e),this.transport=new q(this.opts.host,this.opts.apiKey,this.opts.debug),this.crumbs=new U(this.opts.maxBreadcrumbs)}get options(){return this.opts}start(){if(!this.started){if(this.started=!0,!this.opts.enabled){this.debug("disabled (no API key)");return}a(()=>this.installIntegrations()),a(()=>me(this.opts,this.transport))}}installIntegrations(){let e=this.opts;e.globalHandlers&&this.teardown.push(fe({capture:(t,r)=>this.capture(t,r),flush:()=>this.flush()})),e.console&&this.teardown.push(ce(e.console,{breadcrumb:(t,r)=>this.addBreadcrumb({type:"console",level:t,message:r}),capture:(t,r,o)=>{let s=o.find(i=>i instanceof Error);this.capture(s!=null?s:r,{handled:!0,type:"console",level:t})}})),e.network&&this.teardown.push(de(e.network,{breadcrumb:(t,r,o)=>this.addBreadcrumb({type:"http",level:o?"error":"info",message:t,data:r}),capture:(t,r)=>this.capture(new Error(t),{handled:!0,type:"http",context:r})},e.redactKeys,e.host)),e.domBreadcrumbs&&this.teardown.push(pe({click:(t,r)=>this.addBreadcrumb({type:"click",message:`Clicked ${t}`,data:r}),navigate:(t,r)=>this.addBreadcrumb({type:"navigation",message:`${y(t,e.redactKeys)} \u2192 ${y(r,e.redactKeys)}`})})),e.vitals&&f&&(H(e.vitals.sampleRate)?(this.vitals=new F(e.vitals,t=>this.sendVitals(t)),this.vitals.start(),this.teardown.push(()=>{var t;return(t=this.vitals)==null?void 0:t.stop()})):this.debug("vitals not sampled for this session")),f&&this.teardown.push(this.installUnloadFlush())}installUnloadFlush(){let e=()=>{document.visibilityState==="hidden"&&this.drain(!0)},t=()=>{this.drain(!0)};return a(()=>document.addEventListener("visibilitychange",e,!0)),a(()=>window.addEventListener("pagehide",t,!0)),()=>{a(()=>document.removeEventListener("visibilitychange",e,!0)),a(()=>window.removeEventListener("pagehide",t,!0))}}addBreadcrumb(e){this.opts.enabled&&a(()=>{let t=x(h({},e),{data:e.data?k(e.data,this.opts.redactKeys):void 0,timestamp:e.timestamp||v()});if(this.opts.beforeBreadcrumb){let r=this.opts.beforeBreadcrumb(t);if(!r)return;t=r}this.crumbs.add(t)})}setUser(e){a(()=>{this.user=e?k(e,this.opts.redactKeys):null})}setContext(e,t){a(()=>{this.context[e]=k(t,this.opts.redactKeys)})}captureMessage(e,t="info"){this.capture(new Error(e),{handled:!0,level:t,type:"message"})}capture(e,t={}){if(this.opts.enabled&&!this.sending){if(typeof e=="object"&&e!==null){if(this.seen.has(e))return;a(()=>this.seen.add(e))}a(()=>{var c;let r=j(e);if(this.opts.ignoreErrors.length&&P(r.message,this.opts.ignoreErrors)||!H(this.opts.sampleRate))return;let o=V(r.stack),s=o.find(l=>l.in_app)||o[0],i={exception_class:r.name,message:w(r.message,2e3),level:t.level||"error",type:t.type||"error",handled:(c=t.handled)!=null?c:!0,file:s==null?void 0:s.file,line:s==null?void 0:s.line,stacktrace:o,release:this.opts.release,environment:this.opts.environment,user:this.user,breadcrumbs:this.crumbs.all(),device:K(),session:{id:this.sessionId,started_at:new Date(this.startedAt).toISOString(),duration_ms:Date.now()-this.startedAt},request:t.request||this.requestInfo(),context:h(h({},this.context),t.context?k(t.context,this.opts.redactKeys):{}),snapshot:this.opts.snapshot?ie(this.opts.snapshot):null};if(this.opts.beforeSend){let l=this.opts.beforeSend(i);if(!l)return;i=l}this.enqueue(i)})}}async flush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),await this.drain(!1),a(()=>{var e;return(e=this.vitals)==null?void 0:e.flushNow()})}close(){for(let e of this.teardown)a(e);this.teardown=[],this.started=!1}recordMetric(e){a(()=>{var t;return(t=this.vitals)==null?void 0:t.push(e)})}requestInfo(){if(f)return a(()=>({url:y(location.href,this.opts.redactKeys),referrer:document.referrer?y(document.referrer,this.opts.redactKeys):void 0,method:"GET"}))}enqueue(e){this.queue.push(e),this.queue.length>50&&this.queue.splice(0,this.queue.length-50),!this.flushTimer&&(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.drain(!1)},300),a(()=>{let t=this.flushTimer;t&&typeof t.unref=="function"&&t.unref()}))}async drain(e){if(this.queue.length===0)return;let t=this.queue.splice(0,this.queue.length);this.sending=!0;try{await this.transport.send("/api/ingest/events",{events:t},{beacon:e})}finally{this.sending=!1}}sendVitals(e){a(()=>{let t=[],r=[];for(let s of e)if(s.name==="SLOW_QUERY"){let i=s.data||{};t.push({sql:i.sql,duration_ms:s.value,connection:i.connection,bindings:i.bindings,url:i.url,method:i.method,occurred_at:s.occurred_at})}else r.push(s);let o=a(()=>y(location.href,this.opts.redactKeys));t.length&&this.transport.send("/api/ingest/queries",{queries:t},{beacon:!0}),r.length&&this.transport.send("/api/ingest/vitals",{vitals:r,url:o,release:this.opts.release,environment:this.opts.environment,session_id:this.sessionId,device:K()},{beacon:!0})})}debug(...e){this.opts.debug&&a(()=>console.info("[bugban]",...e))}};var ge="__bugban_client__";function b(){var n;return(n=a(()=>{var e;return(e=globalThis[ge])!=null?e:null},null))!=null?n:null}function ye(n){a(()=>{globalThis[ge]=n})}function be(n={}){let e=b();e&&a(()=>e.close());let t=new N(n);return ye(t),t.start(),t}function ve(){return b()}function we(n,e){var t;(t=b())==null||t.capture(n,e)}function ke(n,e="info"){var t;(t=b())==null||t.captureMessage(n,e)}function Se(n){var e;(e=b())==null||e.setUser(n)}function Ee(n,e){var t;(t=b())==null||t.setContext(n,e)}function xe(n){var e;(e=b())==null||e.addBreadcrumb(n)}function Te(n){var e;(e=b())==null||e.recordMetric(n)}async function Oe(){var n;await((n=b())==null?void 0:n.flush())}function Re(){var n;(n=b())==null||n.close(),ye(null)}var ot={VERSION:T,init:be,getClient:ve,capture:we,captureMessage:ke,setUser:Se,setContext:Ee,addBreadcrumb:xe,recordMetric:Te,flush:Oe,close:Re};return Me(st);})();
|
|
4
4
|
if (typeof window !== "undefined" && window.BugbanSDK) { window.Bugban = window.BugbanSDK.Bugban; }
|
|
5
5
|
//# sourceMappingURL=bugban.global.js.map
|