@vigilon/browser 0.2.8 → 0.2.9
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
|
@@ -495,7 +495,7 @@ function sessionId() {
|
|
|
495
495
|
|
|
496
496
|
// src/browser/client.ts
|
|
497
497
|
var SDK_NAME = "@vigilon/browser";
|
|
498
|
-
var SDK_VERSION = "0.2.
|
|
498
|
+
var SDK_VERSION = "0.2.9";
|
|
499
499
|
var DEFAULT_ENDPOINT = "https://ingest.vigilon.io";
|
|
500
500
|
var EVENTS_PATH = "/v1/browser/events";
|
|
501
501
|
var DUPLICATE_WINDOW_MS = 6e4;
|
package/dist/index.mjs
CHANGED
|
@@ -463,7 +463,7 @@ function sessionId() {
|
|
|
463
463
|
|
|
464
464
|
// src/browser/client.ts
|
|
465
465
|
var SDK_NAME = "@vigilon/browser";
|
|
466
|
-
var SDK_VERSION = "0.2.
|
|
466
|
+
var SDK_VERSION = "0.2.9";
|
|
467
467
|
var DEFAULT_ENDPOINT = "https://ingest.vigilon.io";
|
|
468
468
|
var EVENTS_PATH = "/v1/browser/events";
|
|
469
469
|
var DUPLICATE_WINDOW_MS = 6e4;
|
package/dist/vigilon.min.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
${i}
|
|
5
5
|
${(s!=null?s:"").split(`
|
|
6
6
|
`,3).join(`
|
|
7
|
-
`)}`,l=this.lastSeen.get(a);return l!==void 0&&n-l<this.duplicateWindowMs?!1:(this.lastSeen.set(a,n),this.accepted+=1,!0)}};var se=["password","passwd","secret","token","authorization","cookie","apikey","api_key","api-key","credential","private_key"],oe=/[^\s@]+@[^\s@]+\.[^\s@]+/;function V(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||se.some(s=>i.includes(s))||(e[r]=p(String(t[r]),o.tagValueLength),n+=1)}return e}function E(t){return typeof t=="string"&&t.length>0&&t.length<=o.identifierLength?t:null}function S(t){let e=E(t);return e!==null&&oe.test(e)?null:e}var ae=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function C(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&&ae.test(String(i))&&(e[s]=String(i),n+=1)}return e}var ue=1e3,$=240*1024,le=60*1024,K=512,q=100,ce=5,pe=1800*1e3,de={429:6e4,503:1e4},ge=6e4,v=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>=q){this.options.debug("queue full; event dropped");return}this.queue.push({event:e,bytes:fe(JSON.stringify(e)),attempts:0,firstAttemptAt:null}),this.schedule(ue)}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=le;for(;this.queue.length>0;){let n=this.takeBatch(e);if(n.length===0)break;e-=me(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($);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>=ce||s.firstAttemptAt!==null&&n-s.firstAttemptAt>pe;return a&&this.options.debug(`event ${s.event.eventId} dropped after retries`),!a});let r=[],i=K;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===$&&r.push(this.queue.shift()),r}async post(e,n){var l,d;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,ge));return}if(s===429||s===503){this.requeue(e),this.pause((d=he(a,this.options.now()))!=null?d:de[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,q)}pause(e){this.pausedUntil=Math.max(this.pausedUntil,this.options.now()+e),this.cancelTimer(),this.schedule(0)}};function he(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 me(t){return t.reduce((e,n)=>e+n.bytes,K)}function fe(t){return typeof TextEncoder=="undefined"?t.length*3:new TextEncoder().encode(t).length}function y(){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 F="vigilon.session";function z(){try{let t=window.sessionStorage.getItem(F);if(t)return t;let e=y();return window.sessionStorage.setItem(F,e),e}catch{return null}}var Ee="@vigilon/browser",k="0.2.
|
|
7
|
+
`)}`,l=this.lastSeen.get(a);return l!==void 0&&n-l<this.duplicateWindowMs?!1:(this.lastSeen.set(a,n),this.accepted+=1,!0)}};var se=["password","passwd","secret","token","authorization","cookie","apikey","api_key","api-key","credential","private_key"],oe=/[^\s@]+@[^\s@]+\.[^\s@]+/;function V(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||se.some(s=>i.includes(s))||(e[r]=p(String(t[r]),o.tagValueLength),n+=1)}return e}function E(t){return typeof t=="string"&&t.length>0&&t.length<=o.identifierLength?t:null}function S(t){let e=E(t);return e!==null&&oe.test(e)?null:e}var ae=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function C(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&&ae.test(String(i))&&(e[s]=String(i),n+=1)}return e}var ue=1e3,$=240*1024,le=60*1024,K=512,q=100,ce=5,pe=1800*1e3,de={429:6e4,503:1e4},ge=6e4,v=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>=q){this.options.debug("queue full; event dropped");return}this.queue.push({event:e,bytes:fe(JSON.stringify(e)),attempts:0,firstAttemptAt:null}),this.schedule(ue)}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=le;for(;this.queue.length>0;){let n=this.takeBatch(e);if(n.length===0)break;e-=me(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($);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>=ce||s.firstAttemptAt!==null&&n-s.firstAttemptAt>pe;return a&&this.options.debug(`event ${s.event.eventId} dropped after retries`),!a});let r=[],i=K;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===$&&r.push(this.queue.shift()),r}async post(e,n){var l,d;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,ge));return}if(s===429||s===503){this.requeue(e),this.pause((d=he(a,this.options.now()))!=null?d:de[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,q)}pause(e){this.pausedUntil=Math.max(this.pausedUntil,this.options.now()+e),this.cancelTimer(),this.schedule(0)}};function he(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 me(t){return t.reduce((e,n)=>e+n.bytes,K)}function fe(t){return typeof TextEncoder=="undefined"?t.length*3:new TextEncoder().encode(t).length}function y(){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 F="vigilon.session";function z(){try{let t=window.sessionStorage.getItem(F);if(t)return t;let e=y();return window.sessionStorage.setItem(F,e),e}catch{return null}}var Ee="@vigilon/browser",k="0.2.9",ve="https://ingest.vigilon.io",ye="/v1/browser/events",we=6e4,w=class{constructor(e){this.options=e;this.tags={};this.userId=null;this.removeListeners=[];var r,i,s,a;let n=((r=e.endpoint)!=null?r:ve).replace(/\/+$/,"");this.transport=new v({url:`${n}${ye}`,apiKey:e.apiKey,envelope:{schema:_,sdk:{name:Ee,version:k},service:{name:e.serviceName,environment:e.environment,...e.serviceVersion?{version:p(e.serviceVersion,o.serviceVersionLength)}:{}}},fetch:(l,d)=>window.fetch(l,d),now:()=>Date.now(),debug:l=>this.debug(l)}),this.floodGuard=new f((i=e.maxEventsPerPage)!=null?i:100,we),this.ignoreErrors=[...O,...(s=e.ignoreErrors)!=null?s:[]],this.denyUrls=[...M,...(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:S(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 c,h,I;let i=(c=this.options.sampleRate)!=null?c:1;if(i<1&&Math.random()>=i)return null;let s=A(e,(h=n.mechanism)!=null?h:"manual",(I=n.handled)!=null?I:!0);n.componentStack&&(s.componentStack=n.componentStack);let a=z(),l={type:"exception",eventId:y(),timestamp:new Date().toISOString(),exception:s,page:{url:window.location.href,...n.route?{route:n.route}:{}},session:a===null?null:{id:a},user:this.userId===null?null:{id:this.userId},traceId:null,tags:{...this.tags}};if(N(l,this.ignoreErrors)||D(l,r,this.denyUrls))return null;if(this.options.beforeSend){try{l=this.options.beforeSend(l)}catch(G){return this.debug(`beforeSend threw; event dropped: ${String(G)}`),null}if(l===null)return null}let d=be(l);return this.floodGuard.admit(d,Date.now())?(this.transport.enqueue(d),d.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 be(t){var i,s,a;let e={type:"exception",eventId:t.eventId,timestamp:t.timestamp,exception:U(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=E((i=t.session)==null?void 0:i.id);e.session=n===null?null:{id:n};let r=S((s=t.user)==null?void 0:s.id);return e.user=r===null?null:{id:r},e.traceId=E(t.traceId),e.tags=V((a=t.tags)!=null?a:{}),t.debugIds&&(e.debugIds=C(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||!T.test(n))return`${e} must be 1 to 100 characters of letters, digits, and . _ : / -`;return null}var u=null;function xe(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 w(t),u.install(),!0)}function Se(t,e){return u===null?null:u.capture(t,e)}function ke(t){u==null||u.setUser(t)}function Ie(t,e){u==null||u.setTag(t,e)}function Te(t){return u===null?Promise.resolve(!0):u.flush(t)}async function _e(t){if(u===null)return!0;let e=u;return u=null,e.close(t)}return Q(Le);})();
|
|
8
8
|
//# sourceMappingURL=vigilon.min.js.map
|