@vigilon/browser 0.2.12 → 0.2.13
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
|
@@ -556,7 +556,7 @@ function sessionId() {
|
|
|
556
556
|
|
|
557
557
|
// src/browser/client.ts
|
|
558
558
|
var SDK_NAME = "@vigilon/browser";
|
|
559
|
-
var SDK_VERSION = "0.2.
|
|
559
|
+
var SDK_VERSION = "0.2.13";
|
|
560
560
|
var DEFAULT_ENDPOINT = "https://ingest.vigilon.io";
|
|
561
561
|
var EVENTS_PATH = "/v1/browser/events";
|
|
562
562
|
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.13";
|
|
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
|
-
`)}`,l=this.lastSeen.get(a);return l!==void 0&&n-l<this.duplicateWindowMs?!1:(this.lastSeen.set(a,n),this.accepted+=1,!0)}};var de=["password","passwd","secret","token","authorization","cookie","apikey","api_key","api-key","credential","private_key"],ge=/[^\s@]+@[^\s@]+\.[^\s@]+/;function K(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||de.some(s=>i.includes(s))||(e[r]=d(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&&ge.test(e)?null:e}var he=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function F(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&&he.test(String(i))&&(e[s]=String(i),n+=1)}return e}var fe=1e3,z=240*1024,me=60*1024,G=512,j=100,Ee=5,ve=1800*1e3,ye={429:6e4,503:1e4},be=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>=j){this.options.debug("queue full; event dropped");return}this.queue.push({event:e,bytes:Se(JSON.stringify(e)),attempts:0,firstAttemptAt:null}),this.schedule(fe)}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=me;for(;this.queue.length>0;){let n=this.takeBatch(e);if(n.length===0)break;e-=xe(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(z);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>=Ee||s.firstAttemptAt!==null&&n-s.firstAttemptAt>ve;return a&&this.options.debug(`event ${s.event.eventId} dropped after retries`),!a});let r=[],i=G;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===z&&r.push(this.queue.shift()),r}async post(e,n){var l,p;let r=this.options.now();for(let c of e)c.attempts+=1,(l=c.firstAttemptAt)!=null||(c.firstAttemptAt=r);let i={...this.options.envelope,sentAt:new Date(r).toISOString(),events:e.map(c=>c.event)},s,a=null;try{let c=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=c.status,a=c.headers.get("Retry-After")}catch{this.requeue(e);let c=Math.max(...e.map(h=>h.attempts));this.pause(Math.min(1e3*2**c,be));return}if(s===429||s===503){this.requeue(e),this.pause((p=we(a,this.options.now()))!=null?p:ye[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,j)}pause(e){this.pausedUntil=Math.max(this.pausedUntil,this.options.now()+e),this.cancelTimer(),this.schedule(0)}};function we(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 xe(t){return t.reduce((e,n)=>e+n.bytes,G)}function Se(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 Y="vigilon.session";function X(){try{let t=window.sessionStorage.getItem(Y);if(t)return t;let e=w();return window.sessionStorage.setItem(Y,e),e}catch{return null}}var ke="@vigilon/browser",_="0.2.
|
|
9
|
+
`)}`,l=this.lastSeen.get(a);return l!==void 0&&n-l<this.duplicateWindowMs?!1:(this.lastSeen.set(a,n),this.accepted+=1,!0)}};var de=["password","passwd","secret","token","authorization","cookie","apikey","api_key","api-key","credential","private_key"],ge=/[^\s@]+@[^\s@]+\.[^\s@]+/;function K(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||de.some(s=>i.includes(s))||(e[r]=d(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&&ge.test(e)?null:e}var he=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function F(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&&he.test(String(i))&&(e[s]=String(i),n+=1)}return e}var fe=1e3,z=240*1024,me=60*1024,G=512,j=100,Ee=5,ve=1800*1e3,ye={429:6e4,503:1e4},be=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>=j){this.options.debug("queue full; event dropped");return}this.queue.push({event:e,bytes:Se(JSON.stringify(e)),attempts:0,firstAttemptAt:null}),this.schedule(fe)}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=me;for(;this.queue.length>0;){let n=this.takeBatch(e);if(n.length===0)break;e-=xe(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(z);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>=Ee||s.firstAttemptAt!==null&&n-s.firstAttemptAt>ve;return a&&this.options.debug(`event ${s.event.eventId} dropped after retries`),!a});let r=[],i=G;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===z&&r.push(this.queue.shift()),r}async post(e,n){var l,p;let r=this.options.now();for(let c of e)c.attempts+=1,(l=c.firstAttemptAt)!=null||(c.firstAttemptAt=r);let i={...this.options.envelope,sentAt:new Date(r).toISOString(),events:e.map(c=>c.event)},s,a=null;try{let c=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=c.status,a=c.headers.get("Retry-After")}catch{this.requeue(e);let c=Math.max(...e.map(h=>h.attempts));this.pause(Math.min(1e3*2**c,be));return}if(s===429||s===503){this.requeue(e),this.pause((p=we(a,this.options.now()))!=null?p:ye[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,j)}pause(e){this.pausedUntil=Math.max(this.pausedUntil,this.options.now()+e),this.cancelTimer(),this.schedule(0)}};function we(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 xe(t){return t.reduce((e,n)=>e+n.bytes,G)}function Se(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 Y="vigilon.session";function X(){try{let t=window.sessionStorage.getItem(Y);if(t)return t;let e=w();return window.sessionStorage.setItem(Y,e),e}catch{return null}}var ke="@vigilon/browser",_="0.2.13",Ie="https://ingest.vigilon.io",Te="/v1/browser/events",_e=6e4,x=class{constructor(e){this.options=e;this.tags={};this.debugIds=new m(globalThis);this.userId=null;this.removeListeners=[];var r,i,s,a;let n=((r=e.endpoint)!=null?r:Ie).replace(/\/+$/,"");this.transport=new b({url:`${n}${Te}`,apiKey:e.apiKey,envelope:{schema:U,sdk:{name:ke,version:_},service:{name:e.serviceName,environment:e.environment,...e.serviceVersion?{version:d(e.serviceVersion,o.serviceVersionLength)}:{}}},fetch:(l,p)=>window.fetch(l,p),now:()=>Date.now(),debug:l=>this.debug(l)}),this.floodGuard=new v((i=e.maxEventsPerPage)!=null?i:100,_e),this.ignoreErrors=[...V,...(s=e.ignoreErrors)!=null?s:[]],this.denyUrls=[...C,...(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)}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 h,R,L,P;let i=(h=this.options.sampleRate)!=null?h:1;if(i<1&&Math.random()>=i)return null;let s=M(e,(R=n.mechanism)!=null?R:"manual",(L=n.handled)!=null?L:!0);n.componentStack&&(s.componentStack=n.componentStack);let a=this.debugIds.forStacks([s.stack,...((P=s.cause)!=null?P:[]).map(S=>S.stack)]),l=X(),p={type:"exception",eventId:w(),timestamp:new Date().toISOString(),exception:s,...a?{debugIds:a}:{},page:{url:window.location.href,...n.route?{route:n.route}:{}},session:l===null?null:{id:l},user:this.userId===null?null:{id:this.userId},traceId:null,tags:{...this.tags}};if($(p,this.ignoreErrors)||q(p,r,this.denyUrls))return null;if(this.options.beforeSend){try{p=this.options.beforeSend(p)}catch(S){return this.debug(`beforeSend threw; event dropped: ${String(S)}`),null}if(p===null)return null}let c=Re(p);return this.floodGuard.admit(c,Date.now())?(this.transport.enqueue(c),c.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 Re(t){var i,s,a;let e={type:"exception",eventId:t.eventId,timestamp:t.timestamp,exception:D(t.exception),page:{url:d(g(String(t.page.url)),o.pageUrlLength)}};t.exception.componentStack&&(e.exception.componentStack=d(t.exception.componentStack,o.componentStackLength)),t.page.route&&(e.page.route=d(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=K((a=t.tags)!=null?a:{}),t.debugIds&&(e.debugIds=F(t.debugIds)),e}function H(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||!A.test(n))return`${e} must be 1 to 100 characters of letters, digits, and . _ : / -`;return null}var u=null;function Le(t){if(typeof window=="undefined"||typeof document=="undefined")return!1;let e=H(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 Pe(t,e){return u===null?null:u.capture(t,e)}function Ae(t){u==null||u.setUser(t)}function Ue(t,e){u==null||u.setTag(t,e)}function Oe(t){return u===null?Promise.resolve(!0):u.flush(t)}async function Be(t){if(u===null)return!0;let e=u;return u=null,e.close(t)}return te(Me);})();
|
|
10
10
|
//# sourceMappingURL=vigilon.min.js.map
|