@vigilon/browser 0.2.16-beta.pr-8.10 → 0.2.17-beta.pr-9.11
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 +1 -1
- package/dist/index.mjs +1 -1
- package/dist/vigilon.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -557,7 +557,7 @@ function sessionId() {
|
|
|
557
557
|
|
|
558
558
|
// src/browser/client.ts
|
|
559
559
|
var SDK_NAME = "@vigilon/browser";
|
|
560
|
-
var SDK_VERSION = "0.2.
|
|
560
|
+
var SDK_VERSION = "0.2.17-beta.pr-9.11";
|
|
561
561
|
var DEFAULT_ENDPOINT = "https://ingest.vigilon.io";
|
|
562
562
|
var EVENTS_PATH = "/v1/browser/events";
|
|
563
563
|
var DUPLICATE_WINDOW_MS = 6e4;
|
package/dist/index.mjs
CHANGED
|
@@ -524,7 +524,7 @@ function sessionId() {
|
|
|
524
524
|
|
|
525
525
|
// src/browser/client.ts
|
|
526
526
|
var SDK_NAME = "@vigilon/browser";
|
|
527
|
-
var SDK_VERSION = "0.2.
|
|
527
|
+
var SDK_VERSION = "0.2.17-beta.pr-9.11";
|
|
528
528
|
var DEFAULT_ENDPOINT = "https://ingest.vigilon.io";
|
|
529
529
|
var EVENTS_PATH = "/v1/browser/events";
|
|
530
530
|
var DUPLICATE_WINDOW_MS = 6e4;
|
package/dist/vigilon.min.js
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
${i}
|
|
7
7
|
${(s!=null?s:"").split(`
|
|
8
8
|
`,3).join(`
|
|
9
|
-
`)}`,c=this.lastSeen.get(a);return c!==void 0&&n-c<this.duplicateWindowMs?!1:(this.lastSeen.set(a,n),this.accepted+=1,!0)}};var he=["password","passwd","secret","token","authorization","cookie","apikey","api_key","api-key","credential","private_key"],fe=/[^\s@]+@[^\s@]+\.[^\s@]+/;function z(t){let e={},n=0;for(let r of Object.keys(t)){if(n===o.tagEntries)break;let i=r.toLowerCase();r.length===0||r.length>o.tagKeyLength||he.some(s=>i.includes(s))||(e[r]=p(String(t[r]),o.tagValueLength),n+=1)}return e}function y(t){return typeof t=="string"&&t.length>0&&t.length<=o.identifierLength?t:null}function T(t){let e=y(t);return e!==null&&fe.test(e)?null:e}var me=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function j(t){let e={},n=0;for(let[r,i]of Object.entries(t)){let s=g(r);if(n===o.debugIdEntries)break;s.length>0&&s.length<=o.debugIdKeyLength&&me.test(String(i))&&(e[s]=String(i),n+=1)}return e}var Ee=1e3,G=240*1024,ve=60*1024,X=512,Y=100,ye=5,be=1800*1e3,we={429:6e4,503:1e4},xe=6e4,b=class{constructor(e){this.options=e;this.queue=[];this.pausedUntil=0;this.timer=null;this.loop=null;this.inFlight=new Set}enqueue(e){if(this.queue.length>=Y){this.options.debug("queue full; event dropped");return}this.queue.push({event:e,bytes:Ie(JSON.stringify(e)),attempts:0,firstAttemptAt:null}),this.schedule(Ee)}async flush(e=2e3){this.cancelTimer();let n;return await Promise.race([this.drain().then(()=>Promise.all(this.inFlight)),new Promise(r=>{n=setTimeout(r,e)})]),clearTimeout(n),this.queue.length===0&&this.inFlight.size===0}flushOnUnload(){if(this.cancelTimer(),this.options.now()<this.pausedUntil)return;let e=ve;for(;this.queue.length>0;){let n=this.takeBatch(e);if(n.length===0)break;e-=ke(n),this.track(this.post(n,!0))}}close(){this.cancelTimer(),this.queue=[]}schedule(e){if(this.timer!==null||this.queue.length===0)return;let n=Math.max(e,this.pausedUntil-this.options.now());this.timer=setTimeout(()=>{this.timer=null,this.drain()},n)}cancelTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}drain(){return this.loop===null&&(this.loop=this.run().finally(()=>{this.loop=null})),this.loop}async run(){for(;this.queue.length>0&&this.options.now()>=this.pausedUntil;){let e=this.takeBatch(G);if(e.length===0)break;await this.track(this.post(e,!1))}this.schedule(0)}track(e){return this.inFlight.add(e),e.finally(()=>this.inFlight.delete(e))}takeBatch(e){let n=this.options.now();this.queue=this.queue.filter(s=>{let a=s.attempts>=ye||s.firstAttemptAt!==null&&n-s.firstAttemptAt>be;return a&&this.options.debug(`event ${s.event.eventId} dropped after retries`),!a});let r=[],i=X;for(;this.queue.length>0&&r.length<o.eventsPerRequest&&i+this.queue[0].bytes<=e;){let s=this.queue.shift();i+=s.bytes,r.push(s)}return r.length===0&&this.queue.length>0&&e===G&&r.push(this.queue.shift()),r}async post(e,n){var c,d;let r=this.options.now();for(let l of e)l.attempts+=1,(c=l.firstAttemptAt)!=null||(l.firstAttemptAt=r);let i={...this.options.envelope,sentAt:new Date(r).toISOString(),events:e.map(l=>l.event)},s,a=null;try{let l=await this.options.fetch(this.options.url,{method:"POST",headers:{Authorization:`Bearer ${this.options.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i),keepalive:n});s=l.status,a=l.headers.get("Retry-After")}catch{this.requeue(e);let l=Math.max(...e.map(h=>h.attempts));this.pause(Math.min(1e3*2**l,xe));return}if(s===429||s===503){this.requeue(e),this.pause((d=Se(a,this.options.now()))!=null?d:we[s]);return}(s<200||s>=300)&&this.options.debug(`request rejected with ${s}; ${e.length} events dropped`)}requeue(e){this.queue.unshift(...e),this.queue.length=Math.min(this.queue.length,Y)}pause(e){this.pausedUntil=Math.max(this.pausedUntil,this.options.now()+e),this.cancelTimer(),this.schedule(0)}};function Se(t,e){if(t===null||t.trim()==="")return null;let n=Number(t);if(Number.isFinite(n))return Math.max(0,n*1e3);let r=Date.parse(t);return Number.isNaN(r)?null:Math.max(0,r-e)}function ke(t){return t.reduce((e,n)=>e+n.bytes,X)}function Ie(t){return typeof TextEncoder=="undefined"?t.length*3:new TextEncoder().encode(t).length}function w(){let t=new Uint8Array(16),e=globalThis.crypto;if(e!=null&&e.getRandomValues)e.getRandomValues(t);else for(let r=0;r<16;r+=1)t[r]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=Array.from(t,r=>r.toString(16).padStart(2,"0"));return`${n.slice(0,4).join("")}-${n.slice(4,6).join("")}-${n.slice(6,8).join("")}-${n.slice(8,10).join("")}-${n.slice(10).join("")}`}var H="vigilon.session";function W(){try{let t=window.sessionStorage.getItem(H);if(t)return t;let e=w();return window.sessionStorage.setItem(H,e),e}catch{return null}}var Te="@vigilon/browser",R="0.2.
|
|
9
|
+
`)}`,c=this.lastSeen.get(a);return c!==void 0&&n-c<this.duplicateWindowMs?!1:(this.lastSeen.set(a,n),this.accepted+=1,!0)}};var he=["password","passwd","secret","token","authorization","cookie","apikey","api_key","api-key","credential","private_key"],fe=/[^\s@]+@[^\s@]+\.[^\s@]+/;function z(t){let e={},n=0;for(let r of Object.keys(t)){if(n===o.tagEntries)break;let i=r.toLowerCase();r.length===0||r.length>o.tagKeyLength||he.some(s=>i.includes(s))||(e[r]=p(String(t[r]),o.tagValueLength),n+=1)}return e}function y(t){return typeof t=="string"&&t.length>0&&t.length<=o.identifierLength?t:null}function T(t){let e=y(t);return e!==null&&fe.test(e)?null:e}var me=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function j(t){let e={},n=0;for(let[r,i]of Object.entries(t)){let s=g(r);if(n===o.debugIdEntries)break;s.length>0&&s.length<=o.debugIdKeyLength&&me.test(String(i))&&(e[s]=String(i),n+=1)}return e}var Ee=1e3,G=240*1024,ve=60*1024,X=512,Y=100,ye=5,be=1800*1e3,we={429:6e4,503:1e4},xe=6e4,b=class{constructor(e){this.options=e;this.queue=[];this.pausedUntil=0;this.timer=null;this.loop=null;this.inFlight=new Set}enqueue(e){if(this.queue.length>=Y){this.options.debug("queue full; event dropped");return}this.queue.push({event:e,bytes:Ie(JSON.stringify(e)),attempts:0,firstAttemptAt:null}),this.schedule(Ee)}async flush(e=2e3){this.cancelTimer();let n;return await Promise.race([this.drain().then(()=>Promise.all(this.inFlight)),new Promise(r=>{n=setTimeout(r,e)})]),clearTimeout(n),this.queue.length===0&&this.inFlight.size===0}flushOnUnload(){if(this.cancelTimer(),this.options.now()<this.pausedUntil)return;let e=ve;for(;this.queue.length>0;){let n=this.takeBatch(e);if(n.length===0)break;e-=ke(n),this.track(this.post(n,!0))}}close(){this.cancelTimer(),this.queue=[]}schedule(e){if(this.timer!==null||this.queue.length===0)return;let n=Math.max(e,this.pausedUntil-this.options.now());this.timer=setTimeout(()=>{this.timer=null,this.drain()},n)}cancelTimer(){this.timer!==null&&(clearTimeout(this.timer),this.timer=null)}drain(){return this.loop===null&&(this.loop=this.run().finally(()=>{this.loop=null})),this.loop}async run(){for(;this.queue.length>0&&this.options.now()>=this.pausedUntil;){let e=this.takeBatch(G);if(e.length===0)break;await this.track(this.post(e,!1))}this.schedule(0)}track(e){return this.inFlight.add(e),e.finally(()=>this.inFlight.delete(e))}takeBatch(e){let n=this.options.now();this.queue=this.queue.filter(s=>{let a=s.attempts>=ye||s.firstAttemptAt!==null&&n-s.firstAttemptAt>be;return a&&this.options.debug(`event ${s.event.eventId} dropped after retries`),!a});let r=[],i=X;for(;this.queue.length>0&&r.length<o.eventsPerRequest&&i+this.queue[0].bytes<=e;){let s=this.queue.shift();i+=s.bytes,r.push(s)}return r.length===0&&this.queue.length>0&&e===G&&r.push(this.queue.shift()),r}async post(e,n){var c,d;let r=this.options.now();for(let l of e)l.attempts+=1,(c=l.firstAttemptAt)!=null||(l.firstAttemptAt=r);let i={...this.options.envelope,sentAt:new Date(r).toISOString(),events:e.map(l=>l.event)},s,a=null;try{let l=await this.options.fetch(this.options.url,{method:"POST",headers:{Authorization:`Bearer ${this.options.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(i),keepalive:n});s=l.status,a=l.headers.get("Retry-After")}catch{this.requeue(e);let l=Math.max(...e.map(h=>h.attempts));this.pause(Math.min(1e3*2**l,xe));return}if(s===429||s===503){this.requeue(e),this.pause((d=Se(a,this.options.now()))!=null?d:we[s]);return}(s<200||s>=300)&&this.options.debug(`request rejected with ${s}; ${e.length} events dropped`)}requeue(e){this.queue.unshift(...e),this.queue.length=Math.min(this.queue.length,Y)}pause(e){this.pausedUntil=Math.max(this.pausedUntil,this.options.now()+e),this.cancelTimer(),this.schedule(0)}};function Se(t,e){if(t===null||t.trim()==="")return null;let n=Number(t);if(Number.isFinite(n))return Math.max(0,n*1e3);let r=Date.parse(t);return Number.isNaN(r)?null:Math.max(0,r-e)}function ke(t){return t.reduce((e,n)=>e+n.bytes,X)}function Ie(t){return typeof TextEncoder=="undefined"?t.length*3:new TextEncoder().encode(t).length}function w(){let t=new Uint8Array(16),e=globalThis.crypto;if(e!=null&&e.getRandomValues)e.getRandomValues(t);else for(let r=0;r<16;r+=1)t[r]=Math.floor(Math.random()*256);t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=Array.from(t,r=>r.toString(16).padStart(2,"0"));return`${n.slice(0,4).join("")}-${n.slice(4,6).join("")}-${n.slice(6,8).join("")}-${n.slice(8,10).join("")}-${n.slice(10).join("")}`}var H="vigilon.session";function W(){try{let t=window.sessionStorage.getItem(H);if(t)return t;let e=w();return window.sessionStorage.setItem(H,e),e}catch{return null}}var Te="@vigilon/browser",R="0.2.17-beta.pr-9.11",Re="https://ingest.vigilon.io",_e="/v1/browser/events",Le=6e4,x=class{constructor(e){this.options=e;this.tags={};this.debugIds=new m(globalThis);this.userId=null;this.route=null;this.removeListeners=[];var r,i,s,a;let n=((r=e.endpoint)!=null?r:Re).replace(/\/+$/,"");this.transport=new b({url:`${n}${_e}`,apiKey:e.apiKey,envelope:{schema:B,sdk:{name:Te,version:R},service:{name:e.serviceName,environment:e.environment,...e.serviceVersion?{version:p(e.serviceVersion,o.serviceVersionLength)}:{}}},fetch:(c,d)=>window.fetch(c,d),now:()=>Date.now(),debug:c=>this.debug(c)}),this.floodGuard=new v((i=e.maxEventsPerPage)!=null?i:100,Le),this.ignoreErrors=[...$,...(s=e.ignoreErrors)!=null?s:[]],this.denyUrls=[...q,...(a=e.denyUrls)!=null?a:[]]}install(){this.listen(window,"error",e=>{let{error:n,message:r,filename:i}=e;this.capture(n!=null?n:r,{mechanism:"onerror",handled:!1},i)}),this.listen(window,"unhandledrejection",e=>{this.capture(e.reason,{mechanism:"unhandledrejection",handled:!1})}),this.listen(document,"visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flushOnUnload()}),this.listen(window,"pagehide",()=>this.transport.flushOnUnload())}capture(e,n={},r){try{return this.captureUnsafe(e,n,r)}catch(i){return this.debug(`capture failed: ${String(i)}`),null}}setUser(e){this.userId=e===null?null:T(e.id),e!==null&&this.userId===null&&this.debug("user.id dropped: it must be an opaque ID of at most 128 characters, not an email address")}setTag(e,n){this.tags[e]=String(n)}setRoute(e){this.route=e===null||e===""?null:String(e)}flush(e){return this.transport.flush(e)}async close(e){for(let r of this.removeListeners.splice(0))r();let n=await this.transport.flush(e);return this.transport.close(),n}captureUnsafe(e,n,r){var _,L,P,A,U;let i=(_=this.options.sampleRate)!=null?_:1;if(i<1&&Math.random()>=i)return null;let s=N(e,(L=n.mechanism)!=null?L:"manual",(P=n.handled)!=null?P:!0);n.componentStack&&(s.componentStack=n.componentStack);let a=this.debugIds.forStacks([s.stack,...((A=s.cause)!=null?A:[]).map(S=>S.stack)]),c=W(),d=(U=n.route)!=null?U:this.route,l={type:"exception",eventId:w(),timestamp:new Date().toISOString(),exception:s,...a?{debugIds:a}:{},page:{url:window.location.href,...d?{route:d}:{}},session:c===null?null:{id:c},user:this.userId===null?null:{id:this.userId},traceId:null,tags:{...this.tags}};if(K(l,this.ignoreErrors)||F(l,r,this.denyUrls))return null;if(this.options.beforeSend){try{l=this.options.beforeSend(l)}catch(S){return this.debug(`beforeSend threw; event dropped: ${String(S)}`),null}if(l===null)return null}let h=Pe(l);return this.floodGuard.admit(h,Date.now())?(this.transport.enqueue(h),h.eventId):null}listen(e,n,r){e.addEventListener(n,r),this.removeListeners.push(()=>e.removeEventListener(n,r))}debug(e){this.options.debug&&console.warn(`[Vigilon] ${e}`)}};function Pe(t){var i,s,a;let e={type:"exception",eventId:t.eventId,timestamp:t.timestamp,exception:V(t.exception),page:{url:p(g(String(t.page.url)),o.pageUrlLength)}};t.exception.componentStack&&(e.exception.componentStack=p(t.exception.componentStack,o.componentStackLength)),t.page.route&&(e.page.route=p(t.page.route,o.pageRouteLength));let n=y((i=t.session)==null?void 0:i.id);e.session=n===null?null:{id:n};let r=T((s=t.user)==null?void 0:s.id);return e.user=r===null?null:{id:r},e.traceId=y(t.traceId),e.tags=z((a=t.tags)!=null?a:{}),t.debugIds&&(e.debugIds=j(t.debugIds)),e}function J(t){if(!t||typeof t.apiKey!="string"||t.apiKey.length===0)return"apiKey is required";for(let[e,n]of[["serviceName",t.serviceName],["environment",t.environment]])if(typeof n!="string"||n.length===0||n.length>o.serviceNameLength||!O.test(n))return`${e} must be 1 to 100 characters of letters, digits, and . _ : / -`;return null}var u=null;function Ae(t){if(typeof window=="undefined"||typeof document=="undefined")return!1;let e=J(t);return e!==null?(console.error(`[Vigilon] not started: ${e}`),!1):(t.serviceVersion||console.warn("[Vigilon] serviceVersion is not set; errors will not be linked to a release"),u!==null&&u.close(0),u=new x(t),u.install(),!0)}function Ue(t,e){return u===null?null:u.capture(t,e)}function Oe(t){u==null||u.setUser(t)}function Be(t){u==null||u.setRoute(t)}function Me(t,e){u==null||u.setTag(t,e)}function De(t){return u===null?Promise.resolve(!0):u.flush(t)}async function Ne(t){if(u===null)return!0;let e=u;return u=null,e.close(t)}return re(Ve);})();
|
|
10
10
|
//# sourceMappingURL=vigilon.min.js.map
|