@abyss-project/monitor-browser 0.0.0-stage → 1.0.0

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.
@@ -0,0 +1,90 @@
1
+ import { RumDeviceType, RumAttributeValues, RumEvent } from '@abyss-project/monitor/rum';
2
+ export { RumEvent } from '@abyss-project/monitor/rum';
3
+
4
+ /** What `sampler` receives, once per session, at its creation (RUM spec §35.2). */
5
+ interface RumSamplingContext {
6
+ /** Masked route of the page where the session starts. */
7
+ route: string;
8
+ deviceType: RumDeviceType;
9
+ /** `Edge`, `Opera`, `Samsung Internet`, `Firefox`, `Chrome`, `Safari` or `Other`. */
10
+ browserFamily: string;
11
+ /** ISO 3166 alpha-2 country given by the configuration route (`CF-IPCountry`), never an IP. */
12
+ country: string | null;
13
+ /** Attributes set by `setAttributes` before the session started. */
14
+ attributes: RumAttributeValues;
15
+ /** Drawn once per session, in [0, 1): the same value drives the rate-based decision. */
16
+ random: number;
17
+ sessionSampleRate: number;
18
+ /** Share of the sampled sessions that record a replay. */
19
+ replaySampleRate: number;
20
+ }
21
+ interface RumSamplingDecision {
22
+ session: boolean;
23
+ replay: boolean;
24
+ }
25
+ /** `setAttributes` input: `null` removes the key (§35.1). */
26
+ type RumAttributeInput = Record<string, string | number | boolean | null>;
27
+ /** Options of `AbyssRum.init` (RUM spec §5.1, §35, §36). */
28
+ interface AbyssRumOptions {
29
+ /** Monitor API, e.g. `https://monitor-api.abyss-project.fr`. */
30
+ apiUrl: string;
31
+ applicationId: string;
32
+ /** `publicRumToken` of the environment; it carries the environment. */
33
+ token: string;
34
+ release?: string;
35
+ /** Origins that receive the correlation headers (and `abyss_rid`/`abyss_sid` on sockets). */
36
+ instrumentedOrigins?: string[];
37
+ /** Route template of the application; its result is masked like any URL. */
38
+ routeResolver?: (location: Location) => string;
39
+ /** Read each time replay is considered: replay requires analytics consent. */
40
+ consent?: () => {
41
+ analytics: boolean;
42
+ };
43
+ /** Replay (lot G). */
44
+ unmaskSelectors?: string[];
45
+ /** Decides the session and its replay; it overrides the rates (§35.2). */
46
+ sampler?: (ctx: RumSamplingContext) => RumSamplingDecision;
47
+ /**
48
+ * Called on each event before it is queued. `null` drops it. `id` and `type` cannot change, and
49
+ * URLs are masked after it (§36.1).
50
+ */
51
+ beforeSend?: (event: RumEvent) => RumEvent | null;
52
+ /** `console.error` and `console.warn` capture, on by default (§36.4). */
53
+ captureConsole?: boolean;
54
+ /**
55
+ * First-party relay (`MonitorCore.rumProxy()`): configuration and batches go to
56
+ * `proxyUrl` + `/rum/:applicationId/...` instead of `apiUrl` + `/api/rum/...` (§36.2).
57
+ */
58
+ proxyUrl?: string;
59
+ }
60
+
61
+ /**
62
+ * Real user monitoring for Abyss-Monitor (RUM spec §5). One instance per page:
63
+ *
64
+ * ```ts
65
+ * AbyssRum.init({ apiUrl, applicationId, token, release, instrumentedOrigins });
66
+ * AbyssRum.setActor(user.id);
67
+ * ```
68
+ */
69
+ declare const AbyssRum: {
70
+ /**
71
+ * Starts the SDK. A second call is ignored until `stop()`. Without `token`, `applicationId` or an
72
+ * API URL (`apiUrl` or `proxyUrl`), nothing is installed. Nothing is collected until the remote
73
+ * configuration enables RUM for the token's environment.
74
+ */
75
+ init(options: AbyssRumOptions): void;
76
+ /** The actor of the session; the API stores only its HMAC. `null` clears it. */
77
+ setActor(actor: string | null): void;
78
+ /**
79
+ * Merges session attributes, stored in clear and filterable (§35.1): `null` removes a key. At
80
+ * most 30 keys of 64 characters (`[a-zA-Z0-9_.-]`), values of 256 characters; beyond, the key is
81
+ * ignored and counted in `droppedEvents`.
82
+ */
83
+ setAttributes(attributes: RumAttributeInput): void;
84
+ /** Sends a JS error, always, whatever the sampling of the session. */
85
+ captureError(error: unknown, context?: Record<string, string>): void;
86
+ /** Stops everything, empties the buffers and removes the session. `init` can be called again. */
87
+ stop(): void;
88
+ };
89
+
90
+ export { AbyssRum, type AbyssRumOptions, type RumAttributeInput, type RumSamplingContext, type RumSamplingDecision };
@@ -0,0 +1,90 @@
1
+ import { RumDeviceType, RumAttributeValues, RumEvent } from '@abyss-project/monitor/rum';
2
+ export { RumEvent } from '@abyss-project/monitor/rum';
3
+
4
+ /** What `sampler` receives, once per session, at its creation (RUM spec §35.2). */
5
+ interface RumSamplingContext {
6
+ /** Masked route of the page where the session starts. */
7
+ route: string;
8
+ deviceType: RumDeviceType;
9
+ /** `Edge`, `Opera`, `Samsung Internet`, `Firefox`, `Chrome`, `Safari` or `Other`. */
10
+ browserFamily: string;
11
+ /** ISO 3166 alpha-2 country given by the configuration route (`CF-IPCountry`), never an IP. */
12
+ country: string | null;
13
+ /** Attributes set by `setAttributes` before the session started. */
14
+ attributes: RumAttributeValues;
15
+ /** Drawn once per session, in [0, 1): the same value drives the rate-based decision. */
16
+ random: number;
17
+ sessionSampleRate: number;
18
+ /** Share of the sampled sessions that record a replay. */
19
+ replaySampleRate: number;
20
+ }
21
+ interface RumSamplingDecision {
22
+ session: boolean;
23
+ replay: boolean;
24
+ }
25
+ /** `setAttributes` input: `null` removes the key (§35.1). */
26
+ type RumAttributeInput = Record<string, string | number | boolean | null>;
27
+ /** Options of `AbyssRum.init` (RUM spec §5.1, §35, §36). */
28
+ interface AbyssRumOptions {
29
+ /** Monitor API, e.g. `https://monitor-api.abyss-project.fr`. */
30
+ apiUrl: string;
31
+ applicationId: string;
32
+ /** `publicRumToken` of the environment; it carries the environment. */
33
+ token: string;
34
+ release?: string;
35
+ /** Origins that receive the correlation headers (and `abyss_rid`/`abyss_sid` on sockets). */
36
+ instrumentedOrigins?: string[];
37
+ /** Route template of the application; its result is masked like any URL. */
38
+ routeResolver?: (location: Location) => string;
39
+ /** Read each time replay is considered: replay requires analytics consent. */
40
+ consent?: () => {
41
+ analytics: boolean;
42
+ };
43
+ /** Replay (lot G). */
44
+ unmaskSelectors?: string[];
45
+ /** Decides the session and its replay; it overrides the rates (§35.2). */
46
+ sampler?: (ctx: RumSamplingContext) => RumSamplingDecision;
47
+ /**
48
+ * Called on each event before it is queued. `null` drops it. `id` and `type` cannot change, and
49
+ * URLs are masked after it (§36.1).
50
+ */
51
+ beforeSend?: (event: RumEvent) => RumEvent | null;
52
+ /** `console.error` and `console.warn` capture, on by default (§36.4). */
53
+ captureConsole?: boolean;
54
+ /**
55
+ * First-party relay (`MonitorCore.rumProxy()`): configuration and batches go to
56
+ * `proxyUrl` + `/rum/:applicationId/...` instead of `apiUrl` + `/api/rum/...` (§36.2).
57
+ */
58
+ proxyUrl?: string;
59
+ }
60
+
61
+ /**
62
+ * Real user monitoring for Abyss-Monitor (RUM spec §5). One instance per page:
63
+ *
64
+ * ```ts
65
+ * AbyssRum.init({ apiUrl, applicationId, token, release, instrumentedOrigins });
66
+ * AbyssRum.setActor(user.id);
67
+ * ```
68
+ */
69
+ declare const AbyssRum: {
70
+ /**
71
+ * Starts the SDK. A second call is ignored until `stop()`. Without `token`, `applicationId` or an
72
+ * API URL (`apiUrl` or `proxyUrl`), nothing is installed. Nothing is collected until the remote
73
+ * configuration enables RUM for the token's environment.
74
+ */
75
+ init(options: AbyssRumOptions): void;
76
+ /** The actor of the session; the API stores only its HMAC. `null` clears it. */
77
+ setActor(actor: string | null): void;
78
+ /**
79
+ * Merges session attributes, stored in clear and filterable (§35.1): `null` removes a key. At
80
+ * most 30 keys of 64 characters (`[a-zA-Z0-9_.-]`), values of 256 characters; beyond, the key is
81
+ * ignored and counted in `droppedEvents`.
82
+ */
83
+ setAttributes(attributes: RumAttributeInput): void;
84
+ /** Sends a JS error, always, whatever the sampling of the session. */
85
+ captureError(error: unknown, context?: Record<string, string>): void;
86
+ /** Stops everything, empties the buffers and removes the session. `init` can be called again. */
87
+ stop(): void;
88
+ };
89
+
90
+ export { AbyssRum, type AbyssRumOptions, type RumAttributeInput, type RumSamplingContext, type RumSamplingDecision };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var ft=Object.create;var Se=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var Et=Object.getPrototypeOf,gt=Object.prototype.hasOwnProperty;var V=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var St=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Rt(t))!gt.call(e,o)&&o!==n&&Se(e,o,{get:()=>t[o],enumerable:!(s=ht(t,o))||s.enumerable});return e};var v=(e,t,n)=>(n=e!=null?ft(Et(e)):{},St(!e||!e.__esModule?Se(n,"default",{value:e,enumerable:true}):n,e));var Pe=V(f=>{Object.defineProperty(f,"__esModule",{value:true});f.RumCspDisposition=f.RumBreadcrumbKind=f.RumConsoleLevel=f.RumTimingKind=f.RumSocketBinaryType=f.RumSocketDirection=f.RumFrustrationType=f.RumDeviceType=f.RumNavigationType=f.RumRequestKind=f.RumRequestOutcome=f.RumEventType=void 0;var Ie;(function(e){e.SESSION="session",e.PAGE_VIEW="pageView",e.VITALS="vitals",e.REQUEST="request",e.ERROR="error",e.CONSOLE="console",e.ACTION="action",e.FRUSTRATION="frustration",e.TIMING="timing",e.CSP_VIOLATION="cspViolation",e.SOCKET_MESSAGE="socketMessage",e.FEEDBACK="feedback";})(Ie||(f.RumEventType=Ie={}));var be;(function(e){e.SUCCESS="SUCCESS",e.HTTP_ERROR="HTTP_ERROR",e.NETWORK_ERROR="NETWORK_ERROR",e.OFFLINE="OFFLINE",e.ABORTED="ABORTED",e.TIMEOUT="TIMEOUT";})(be||(f.RumRequestOutcome=be={}));var Te;(function(e){e.FETCH="FETCH",e.XHR="XHR",e.RESOURCE="RESOURCE",e.WEBSOCKET="WEBSOCKET",e.SSE="SSE";})(Te||(f.RumRequestKind=Te={}));var Ae;(function(e){e.NAVIGATE="NAVIGATE",e.RELOAD="RELOAD",e.BACK_FORWARD="BACK_FORWARD",e.SPA="SPA";})(Ae||(f.RumNavigationType=Ae={}));var we;(function(e){e.DESKTOP="desktop",e.MOBILE="mobile",e.TABLET="tablet";})(we||(f.RumDeviceType=we={}));var Oe;(function(e){e.RAGE_CLICK="RAGE_CLICK",e.DEAD_CLICK="DEAD_CLICK",e.ERROR_CLICK="ERROR_CLICK";})(Oe||(f.RumFrustrationType=Oe={}));var _e;(function(e){e.IN="IN",e.OUT="OUT";})(_e||(f.RumSocketDirection=_e={}));var Ce;(function(e){e.BLOB="blob",e.ARRAYBUFFER="arraybuffer";})(Ce||(f.RumSocketBinaryType=Ce={}));var Me;(function(e){e.TIMING="TIMING",e.DURATION="DURATION";})(Me||(f.RumTimingKind=Me={}));var ke;(function(e){e.ERROR="error",e.WARN="warn";})(ke||(f.RumConsoleLevel=ke={}));var De;(function(e){e.NAVIGATION="NAVIGATION",e.REQUEST="REQUEST",e.CLICK="CLICK";})(De||(f.RumBreadcrumbKind=De={}));var Ne;(function(e){e.ENFORCE="enforce",e.REPORT="report";})(Ne||(f.RumCspDisposition=Ne={}));});var Le=V(Ue=>{Object.defineProperty(Ue,"__esModule",{value:true});});var ie=V(P=>{Object.defineProperty(P,"__esModule",{value:true});P.isUuid=P.UUID_PATTERN=void 0;P.UUID_PATTERN=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;var bt=e=>typeof e=="string"&&P.UUID_PATTERN.test(e);P.isUuid=bt;});var xe=V(O=>{Object.defineProperty(O,"__esModule",{value:true});O.maskUrl=O.MASK_URL_MAX_SEGMENT_LENGTH=O.MASKED_SEGMENT=void 0;var Tt=ie();O.MASKED_SEGMENT=":id";O.MASK_URL_MAX_SEGMENT_LENGTH=40;var At=/^\d{3,}$/,wt=/^[0-9a-f]{16,}$/i,Ot=/^[a-z][a-z0-9+.-]*:\/\//i,_t=e=>e.length>O.MASK_URL_MAX_SEGMENT_LENGTH||Tt.UUID_PATTERN.test(e)||At.test(e)||wt.test(e),Ct=e=>e===""?"/":e.split("/").map(t=>_t(t)?O.MASKED_SEGMENT:t).join("/"),Mt=e=>{try{let t=new URL(e.startsWith("//")?`https:${e}`:e);return {host:t.host===""?null:t.host.toLowerCase(),path:t.pathname}}catch{return {host:null,path:"/"}}},kt=e=>{let n=(typeof e=="string"?e.trim():"").split("#")[0].split("?")[0],{host:s,path:o}=Ot.test(n)||n.startsWith("//")?Mt(n):{host:null,path:n};return {host:s,path:Ct(o)}};O.maskUrl=kt;});var Ve=V(R=>{Object.defineProperty(R,"__esModule",{value:true});R.TIMING_ALLOW_ORIGIN_HEADER=R.SOCKET_SESSION_ID_PARAM=R.SOCKET_REQUEST_ID_PARAM=R.MONITOR_CORRELATION_HEADERS=R.SESSION_ID_HEADER=R.REQUEST_ID_HEADER=void 0;R.REQUEST_ID_HEADER="x-abyss-request-id";R.SESSION_ID_HEADER="x-abyss-session-id";R.MONITOR_CORRELATION_HEADERS=[R.REQUEST_ID_HEADER,R.SESSION_ID_HEADER];R.SOCKET_REQUEST_ID_PARAM="abyss_rid";R.SOCKET_SESSION_ID_PARAM="abyss_sid";R.TIMING_ALLOW_ORIGIN_HEADER="Timing-Allow-Origin";});var g=V(A=>{var Dt=A&&A.__createBinding||(Object.create?(function(e,t,n,s){s===void 0&&(s=n);var o=Object.getOwnPropertyDescriptor(t,n);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:true,get:function(){return t[n]}}),Object.defineProperty(e,s,o);}):(function(e,t,n,s){s===void 0&&(s=n),e[s]=t[n];})),G=A&&A.__exportStar||function(e,t){for(var n in e)n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n)&&Dt(t,e,n);};Object.defineProperty(A,"__esModule",{value:true});G(Pe(),A);G(Le(),A);G(xe(),A);G(Ve(),A);G(ie(),A);});var ye=e=>e===null?null:typeof e=="string"&&e.trim()!==""?e:void 0;var yt=/^[a-zA-Z0-9_.-]{1,64}$/,vt=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),It=e=>typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e)||typeof e=="string"&&e.length<=256,ve=(e,t,n)=>{let s={...e};if(!t||typeof t!="object"||Array.isArray(t))return n(),s;for(let[o,r]of Object.entries(t))!yt.test(o)||o==="__proto__"?n():r===null?delete s[o]:!It(r)||!vt(s,o)&&Object.keys(s).length>=30?n():s[o]=r;return s};var I=v(g());var Nt=["id","type","sessionId"],Pt=(e,t)=>e==null?t==null||["string","number","boolean"].includes(typeof t):Array.isArray(e)?Array.isArray(t):t!==null&&typeof t==typeof e,He=(e,t,n)=>{if(!t)return e;let s;try{s=t(JSON.parse(JSON.stringify(e)));}catch{return n(),e}if(s===null)return null;if(!s||typeof s!="object"||Array.isArray(s))return n(),null;let o=e,r=s,i={};for(let a of Object.keys(o))if(Nt.includes(a))i[a]=o[a];else if(Pt(o[a],r[a]))r[a]!==void 0&&(i[a]=r[a]);else return n(),null;return i};var j=v(g());var M=e=>new Date(e).toISOString(),S=(e,t)=>e>0&&t>=e?Math.round(t-e):null,$=e=>{var t;if(typeof e=="string")return e;if(e instanceof Error)return `${e.name}: ${e.message}`;try{return (t=JSON.stringify(e))!=null?t:String(e)}catch{return String(e)}},_=(e,t,n,s=false)=>{let o={capture:s,passive:true};return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)},H=e=>{let t=0;for(let n=0;n<e.length;n+=1){let s=e.charCodeAt(n);s<128?t+=1:s<2048?t+=2:s>=55296&&s<56320?(t+=4,n+=1):t+=3;}return t},Q=(e,t)=>{if(H(e)<=t)return e;let n=0;for(let s=0;s<e.length;s+=1){let o=e.charCodeAt(s)>=55296&&e.charCodeAt(s)<56320,r=H(e.slice(s,o?s+2:s+1));if(n+r>t)return e.slice(0,s);n+=r,o&&(s+=1);}return e},ae=e=>{if(typeof e=="string")return H(e);if(typeof Blob!="undefined"&&e instanceof Blob)return e.size;let t=e==null?void 0:e.byteLength;return typeof t=="number"?t:0},z=e=>{try{let t=sessionStorage.getItem(e);return t===null?null:JSON.parse(t)}catch{return null}},Y=(e,t)=>{try{sessionStorage.setItem(e,JSON.stringify(t));}catch{}},Be=e=>{try{sessionStorage.removeItem(e);}catch{}};var E=()=>{let e=globalThis.crypto;if(typeof(e==null?void 0:e.randomUUID)=="function")return e.randomUUID();let t=new Uint8Array(16);e.getRandomValues(t),t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=Array.from(t,s=>(s+256).toString(16).slice(1)).join("");return `${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`};var Ut=1024,Lt=50,qe=e=>{let t=[["error",j.RumConsoleLevel.ERROR],["warn",j.RumConsoleLevel.WARN]],n=null,s=0,o=t.map(([r,i])=>{let a=console[r],d=(...c)=>{try{let u=e.pageViewId();u!==n&&(n=u,s=0),s+=1,s>Lt?e.drop():e.record({id:E(),type:j.RumEventType.CONSOLE,pageViewId:u,occurredAt:M(Date.now()),level:i,message:Q(c.map($).join(" "),Ut)});}catch{e.drop();}a.apply(console,c);};return console[r]=d,()=>{console[r]===d&&(console[r]=a);}});return ()=>o.forEach(r=>r())};var C=v(g());var J=4096,U=e=>{try{return new URL(e,window.location.href)}catch{return null}},ue=e=>{let t=U(e);return t?`${t.protocol==="ws:"?"http:":t.protocol==="wss:"?"https:":t.protocol}//${t.host}`.toLowerCase():null},B=(e,t)=>{var n;return e.instrumentedOrigins.includes((n=ue(t.href))!=null?n:"")},k=e=>{let t=e==null?void 0:e.name;return t==="AbortError"?C.RumRequestOutcome.ABORTED:t==="TimeoutError"?C.RumRequestOutcome.TIMEOUT:navigator.onLine===false?C.RumRequestOutcome.OFFLINE:C.RumRequestOutcome.NETWORK_ERROR},Z=e=>e>=400?C.RumRequestOutcome.HTTP_ERROR:C.RumRequestOutcome.SUCCESS,q=(e,t,n,s,o,r)=>({id:E(),type:C.RumEventType.REQUEST,pageViewId:e.pageViewId(),kind:t,method:n,url:s,startedAt:M(o),status:null,outcome:C.RumRequestOutcome.SUCCESS,durationMs:null,dnsMs:null,tcpMs:null,tlsMs:null,ttfbMs:null,downloadMs:null,requestId:r,instrumented:r!==null}),Fe=(e,t)=>{let n;try{n=performance.getEntriesByName(e,"resource");}catch{return null}let s=n.filter(o=>performance.timeOrigin+o.startTime>=t-50).pop();return !s||!s.requestStart?null:{dnsMs:S(s.domainLookupStart,s.domainLookupEnd),tcpMs:S(s.connectStart,s.connectEnd),tlsMs:s.secureConnectionStart>0?S(s.secureConnectionStart,s.connectEnd):null,ttfbMs:S(s.requestStart,s.responseStart),downloadMs:S(s.responseStart,s.responseEnd)}};var L=v(g());var w=v(g());var xt=123,ce=(e,t,n)=>{let s=U(String(n));if(!s)return null;let o=s.href,r=null;B(e,s)&&(r=E(),s.searchParams.set(w.SOCKET_REQUEST_ID_PARAM,r),s.searchParams.set(w.SOCKET_SESSION_ID_PARAM,e.sessionId()));let i=Date.now(),a=q(e,t,"GET",o,i,r);Object.assign(a,{connectMs:null,messagesIn:0,messagesOut:0,bytesIn:0,bytesOut:0,droppedMessages:0});let d={event:a,startedAt:i,opened:false,dirty:true,done:false};return e.trackConnection(d),{connection:d,nativeUrl:r===null?String(n):s.href}},de=e=>{e.opened||(e.opened=true,e.event.connectMs=Date.now()-e.startedAt,e.dirty=true);},ee=(e,t,n)=>{var o,r,i,a;let{event:s}=e;t==="in"?(s.messagesIn=((o=s.messagesIn)!=null?o:0)+1,s.bytesIn=((r=s.bytesIn)!=null?r:0)+ae(n)):(s.messagesOut=((i=s.messagesOut)!=null?i:0)+1,s.bytesOut=((a=s.bytesOut)!=null?a:0)+ae(n)),e.dirty=true;},te=(e,t)=>{e.done||(e.event.durationMs=Date.now()-e.startedAt,e.event.outcome=t,e.done=true,e.dirty=true);},Vt=(e,t,n,s)=>{if(n)return w.RumRequestOutcome.ABORTED;if(e&&(t===1e3||t===1001||s&&t===1005))return w.RumRequestOutcome.SUCCESS;let o=k();return o===w.RumRequestOutcome.OFFLINE||!e?o:w.RumRequestOutcome.HTTP_ERROR},Ke=e=>{let t=window.WebSocket;if(typeof t!="function")return ()=>{};let n=t.prototype,s=n.send,o=n.close,r=new WeakMap,i=(u,l)=>{r.set(u,l),u.addEventListener("open",()=>de(l)),u.addEventListener("message",p=>ee(l,"in",p.data)),u.addEventListener("close",p=>{let h=r.get(u);l.event.closeCode=p.code,l.event.closeReason=p.reason?Q(p.reason,xt):null,te(l,Vt(l.opened,p.code,(h==null?void 0:h.abortedByApp)===true,(h==null?void 0:h.closedByApp)===true));});},a=new Proxy(t,{construct(u,l,p){let h=null;try{h=ce(e,w.RumRequestKind.WEBSOCKET,l[0]);}catch{e.drop();}let b=h?[h.nativeUrl,...l.slice(1)]:l,m=Reflect.construct(u,b,p===a?u:p);return h&&i(m,h.connection),m}}),d=function(u){s.call(this,u);let l=r.get(this);l&&ee(l,"out",u);},c=function(u,l){let p=r.get(this);return p&&(p.abortedByApp=this.readyState===t.CONNECTING,p.closedByApp=true),o.apply(this,arguments)};return window.WebSocket=a,n.send=d,n.close=c,()=>{window.WebSocket===a&&(window.WebSocket=t),n.send===d&&(n.send=s),n.close===c&&(n.close=o);}};var We=e=>{let t=window,n=t.EventSource;if(typeof n!="function")return ()=>{};let s=n.prototype,o=s.close,r=new WeakMap,i=(c,u)=>{r.set(c,u),u.event.reconnectCount=0,c.addEventListener("open",()=>de(u)),c.addEventListener("message",l=>ee(u,"in",l.data)),c.addEventListener("error",()=>{var p;if(c.readyState===n.CONNECTING){u.event.reconnectCount=((p=u.event.reconnectCount)!=null?p:0)+1,u.dirty=true;return}let l=k();te(u,u.opened&&l!==L.RumRequestOutcome.OFFLINE?L.RumRequestOutcome.HTTP_ERROR:l);});},a=new Proxy(n,{construct(c,u,l){let p=null;try{p=ce(e,L.RumRequestKind.SSE,u[0]);}catch{e.drop();}let h=p?[p.nativeUrl,...u.slice(1)]:u,b=Reflect.construct(c,h,l===a?c:l);return p&&i(b,p.connection),b}}),d=function(){o.call(this);let c=r.get(this);c&&te(c,c.opened?L.RumRequestOutcome.SUCCESS:L.RumRequestOutcome.ABORTED);};return t.EventSource=a,s.close=d,()=>{t.EventSource===a&&(t.EventSource=n),s.close===d&&(s.close=o);}};var F=v(g());var Ht=(e,t,n)=>{var u,l,p;let s=typeof Request!="undefined"&&t instanceof Request?t:null,o=U(s?s.url:String(t));if(!o)return null;let r=((l=(u=n==null?void 0:n.method)!=null?u:s==null?void 0:s.method)!=null?l:"GET").toUpperCase(),i=Date.now(),a=null,d=n;if(B(e,o)){a=E();let h=new Headers((p=n==null?void 0:n.headers)!=null?p:s==null?void 0:s.headers);h.set(F.REQUEST_ID_HEADER,a),h.set(F.SESSION_ID_HEADER,e.sessionId()),d={...n,headers:h};}let c=q(e,F.RumRequestKind.FETCH,r,o.href,i,a);return e.trackTiming(c.id,o.href,i),{event:c,init:d,startedAt:i}},Bt=(e,t,n)=>{let{event:s}=t;if(s.durationMs=Date.now()-t.startedAt,s.status=n.status,s.outcome=Z(n.status),s.instrumented||n.status<400){e.record(s);return}n.clone().text().then(o=>{s.responseBodyExcerpt=o.slice(0,J),e.record(s);},()=>e.record(s));},Ge=e=>{let t=window.fetch;if(typeof t!="function")return ()=>{};let n=(s,o)=>{let r=null;try{r=Ht(e,s,o);}catch{e.drop();}let i=t.call(window,s,r?r.init:o);if(r){let a=r;i.then(d=>{try{Bt(e,a,d);}catch{e.drop();}},d=>{a.event.durationMs=Date.now()-a.startedAt,a.event.outcome=k(d),e.record(a.event);});}return i};return window.fetch=n,()=>{window.fetch===n&&(window.fetch=t);}};var D=v(g());var je=e=>{let t=window.XMLHttpRequest;if(typeof t!="function")return ()=>{};let n=t.prototype,s=n.open,o=n.send,r=new WeakMap,i=function(c,u){try{r.set(this,{method:String(c).toUpperCase(),url:String(u)});}catch{e.drop();}return s.apply(this,arguments)},a=(c,u,l)=>{let p=U(l);if(!p)return;let h=Date.now(),b=null;B(e,p)&&(b=E(),c.setRequestHeader(D.REQUEST_ID_HEADER,b),c.setRequestHeader(D.SESSION_ID_HEADER,e.sessionId()));let m=q(e,D.RumRequestKind.XHR,u,p.href,h,b);e.trackTiming(m.id,p.href,h);let T=null;c.addEventListener("error",()=>T=k()),c.addEventListener("abort",()=>T=D.RumRequestOutcome.ABORTED),c.addEventListener("timeout",()=>T=D.RumRequestOutcome.TIMEOUT),c.addEventListener("loadend",()=>{m.durationMs=Date.now()-h,m.status=T===null&&c.status>0?c.status:null,m.outcome=m.status===null?T!=null?T:k():Z(m.status),!m.instrumented&&m.status!==null&&m.status>=400&&(c.responseType===""||c.responseType==="text")&&(m.responseBodyExcerpt=c.responseText.slice(0,J)),e.record(m);});},d=function(c){let u=r.get(this);if(u)try{a(this,u.method,u.url);}catch{e.drop();}return o.call(this,c)};return n.open=i,n.send=d,()=>{n.open===i&&(n.open=s),n.send===d&&(n.send=o);}};var le=v(g()),qt=/^([a-z][a-z0-9+.-]*:)\/\//i,Ft=["url","blockedUri","sourceFile"],Kt=["route","referrerRoute","entryPath"],Wt=e=>{let{host:t,path:n}=(0, le.maskUrl)(e);if(t===null)return n;let s=qt.exec(e.trim());return `${s?s[1].toLowerCase():"https:"}//${t}${n}`},pe=e=>(0, le.maskUrl)(e).path,Xe=e=>{let t=e;for(let n of Ft)typeof t[n]=="string"&&(t[n]=Wt(t[n]));for(let n of Kt)typeof t[n]=="string"&&(t[n]=pe(t[n]));return e};var x=v(g());var Gt={reload:x.RumNavigationType.RELOAD,back_forward:x.RumNavigationType.BACK_FORWARD},$e=()=>{try{return performance.getEntriesByType("navigation")[0]}catch{return}},Qe=e=>({dnsMs:e?S(e.domainLookupStart,e.domainLookupEnd):null,tcpMs:e?S(e.connectStart,e.connectEnd):null,tlsMs:e&&e.secureConnectionStart>0?S(e.secureConnectionStart,e.connectEnd):null,requestMs:e?S(e.requestStart,e.responseStart):null,responseMs:e?S(e.responseStart,e.responseEnd):null,domProcessingMs:e?S(e.responseEnd,e.domComplete):null,loadMs:e&&e.loadEventEnd>0?Math.round(e.loadEventEnd-e.startTime):null}),ze=e=>{var h,b;let t=null,n=null,s=(m,T=null,mt)=>{let ge=Date.now();return t={startedAt:ge,path:window.location.pathname,event:{id:E(),type:x.RumEventType.PAGE_VIEW,route:e.resolveRoute(),referrerRoute:T,startedAt:M(ge),durationMs:null,navigationType:m,lcpMs:null,inpMs:null,cls:null,fcpMs:null,ttfbMs:null,dnsMs:null,tcpMs:null,tlsMs:null,requestMs:null,responseMs:null,domProcessingMs:null,loadMs:null,longTaskCount:0,longTaskTotalMs:0,...mt}},e.record({...t.event}),t.event.id},o=()=>{t&&(t.event.durationMs=Date.now()-t.startedAt,e.record({...t.event}));},r=()=>{try{if(e.onNavigation(),t&&window.location.pathname!==t.path){let m=t.event.route;o(),s(x.RumNavigationType.SPA,m);}}catch{e.drop();}},i=()=>{t&&t.event.id===n&&(Object.assign(t.event,Qe($e())),e.record({...t.event}));},a=$e(),d=document.readyState==="complete",c=(b=Gt[(h=a==null?void 0:a.type)!=null?h:""])!=null?b:x.RumNavigationType.NAVIGATE;n=s(c,null,d?Qe(a):void 0);let u=[_(window,"popstate",r)];if(!d){let m;u.push(_(window,"load",()=>{m=setTimeout(i,0);}),()=>clearTimeout(m));}let l=window.history.pushState,p=function(...m){let T=l.apply(this,m);return r(),T};return window.history.pushState=p,u.push(()=>{window.history.pushState===p&&(window.history.pushState=l);}),{currentId:()=>{var m;return (m=t==null?void 0:t.event.id)!=null?m:null},start:m=>{s(m);},end:o,stop:()=>u.forEach(m=>m())}};var Ye=e=>e.replace(/\/+$/,""),me=(e,t)=>`${e.proxyUrl?`${Ye(e.proxyUrl)}/rum`:`${Ye(e.apiUrl)}/api/rum`}/${encodeURIComponent(e.applicationId)}/${t}?token=${encodeURIComponent(e.token)}`;var Ze="abyss-rum-config",jt=600*1e3,Je=e=>typeof e=="number"&&e>=0&&e<=1?e:0,et=e=>{var s,o;let t=e;if(!t||typeof t.enabled!="boolean"||typeof t.sessionSampleRate!="number")return null;let n=(s=t.replay)!=null?s:{};return {enabled:t.enabled,sessionSampleRate:Je(t.sessionSampleRate),sessionQuotaExhausted:t.sessionQuotaExhausted===true,country:typeof t.country=="string"?t.country:null,feedbackEnabled:t.feedbackEnabled===true,replay:{enabled:n.enabled===true,sampleRate:Je(n.sampleRate),unmaskSelectors:Array.isArray(n.unmaskSelectors)?n.unmaskSelectors.filter(r=>typeof r=="string"):[]},socketMessages:{enabled:((o=t.socketMessages)==null?void 0:o.enabled)===true}}},tt=(e,t)=>{let n=z(Ze);if(!n||n.key!==e||typeof n.at!="number")return;let s=t-n.at;return s>=0&&s<jt?et(n.config):void 0},nt=async(e,t,n,s)=>{let o=null;try{let r=await t(e,{credentials:"omit"});o=r.ok?et(await r.json()):null;}catch{o=null;}return Y(Ze,{key:n,at:s,config:o}),o};var ne=v(g()),Xt=/iPad|Tablet|PlayBook|Silk|Android(?!.*Mobile)/i,$t=/Mobi|iPhone|iPod|Android|Opera Mini|IEMobile/i,Qt=[[/Edg(e|A|iOS)?\//,"Edge"],[/OPR\/|Opera/,"Opera"],[/SamsungBrowser\//,"Samsung Internet"],[/Firefox\/|FxiOS\//,"Firefox"],[/Chrome\/|CriOS\//,"Chrome"],[/Safari\//,"Safari"]],st=e=>Xt.test(e)?ne.RumDeviceType.TABLET:$t.test(e)?ne.RumDeviceType.MOBILE:ne.RumDeviceType.DESKTOP,ot=e=>{var t,n;return (n=(t=Qt.find(([s])=>s.test(e)))==null?void 0:t[1])!=null?n:"Other"},rt=(e,t,n,s)=>{if(!e)return n;try{let o=e({...t,attributes:{...t.attributes}});if(typeof(o==null?void 0:o.session)=="boolean"&&typeof o.replay=="boolean")return {session:o.session,replay:o.replay}}catch{}return s(),n};var N=v(g());var zt=200,Yt=(e,t,n)=>({session:e<t,replay:e<t*n}),it=(e,t,n,s)=>{let o=Yt(e.random,e.sessionSampleRate,e.replaySampleRate),r=rt(t,e,o,s),i=r.session&&!n;return {session:i,replay:i&&r.replay}},Jt=e=>e.type===N.RumEventType.REQUEST&&(e.kind===N.RumRequestKind.FETCH||e.kind===N.RumRequestKind.XHR)&&e.outcome===N.RumRequestOutcome.SUCCESS,se=class{constructor(t){this.onDrop=t;this.held=null;this.released=new Set;this.successes=new Map;}accept(t,n){var o,r,i;if(n){if(Jt(t)){let a=(o=t.pageViewId)!=null?o:"",d=((r=this.successes.get(a))!=null?r:0)+1;if(this.successes.set(a,d),d>zt)return this.onDrop(),[]}return [t]}if(t.type===N.RumEventType.PAGE_VIEW)return this.released.has(t.id)?[t]:(this.held=t,[]);if(t.type!==N.RumEventType.ERROR)return [];let s=[];return t.pageViewId!==null&&!this.released.has(t.pageViewId)&&(this.released.add(t.pageViewId),((i=this.held)==null?void 0:i.id)===t.pageViewId&&(s.push(this.held),this.held=null)),s.push(t),s}reset(){this.held=null,this.released.clear(),this.successes.clear();}};var at=v(g());var fe="abyss-rum-session",Zt=1800*1e3,en=14400*1e3,he=(e,t)=>t-e.lastActivityAt>=Zt||t-e.startedAt>=en,tn=e=>typeof(e==null?void 0:e.session)=="boolean"&&typeof e.replay=="boolean",nn=()=>{let e=z(fe);return !e||!(0, at.isUuid)(e.id)||typeof e.startedAt!="number"||typeof e.lastActivityAt!="number"||typeof e.random!="number"?null:{id:e.id,startedAt:e.startedAt,lastActivityAt:e.lastActivityAt,random:e.random,decision:tn(e.decision)?e.decision:null,entryPath:typeof e.entryPath=="string"?e.entryPath:null,cut:e.cut===true}},K=e=>Y(fe,e),ut=()=>Be(fe),Re=e=>{let t={id:E(),startedAt:e,lastActivityAt:e,random:Math.random(),decision:null,entryPath:null,cut:false};return K(t),t},ct=e=>{let t=nn();return t&&!he(t,e)?t:Re(e)};var dt=64*1024,sn=60*1e3;var oe=class{constructor(t,n,s){this.url=t;this.fetchImpl=n;this.handlers=s;this.pausedUntil=0;}isPaused(t){return t<this.pausedUntil}send(t,n,s){let o=JSON.stringify({...t,events:[]}).slice(0,-2),r=H(o)+2,i=[],a=[],d=r;for(let c of n){let u=JSON.stringify(c),l=H(u);if(r+l>dt){this.handlers.onDrop(1);continue}let p=l+(i.length>0?1:0);d+p>dt&&(this.post(`${o}${i.join(",")}]}`,a,s,t.sessionId),i=[],a=[],d=r),d+=l+(i.length>0?1:0),i.push(u),a.push(c);}i.length>0&&this.post(`${o}${i.join(",")}]}`,a,s,t.sessionId);}post(t,n,s,o){let r=i=>this.handlers.onResult(n,i,o);if(s&&this.beacon(t)){r("OK");return}this.fetchImpl(this.url,{method:"POST",body:t,keepalive:true,credentials:"omit",headers:{"Content-Type":"text/plain;charset=UTF-8"}}).then(i=>this.handle(i,r),()=>r("FAIL")).catch(()=>this.handlers.onDrop(1));}beacon(t){try{return typeof navigator.sendBeacon=="function"&&navigator.sendBeacon(this.url,t)}catch{return false}}async handle(t,n){if(t.status===429){this.pausedUntil=Date.now()+sn,n("RETRY");return}if(t.status===401||t.status===403||t.status===404){n("CUT");return}if(!t.ok){n("FAIL");return}n("OK");let s=false;try{s=(await t.json()).liveWatched===!0;}catch{}this.handlers.onLiveWatched(s);}};var on=5e3,rn=50,lt=200,an=50,un=e=>{let t=e;return t&&typeof t=="object"&&typeof t.message=="string"?{name:typeof t.name=="string"&&t.name?t.name:"Error",message:t.message,stack:typeof t.stack=="string"?t.stack:null}:{name:"Error",message:$(e),stack:null}},cn=e=>{if(!e||typeof e!="object")return;let t=Object.entries(e).filter(([,n])=>typeof n=="string");return t.length>0?Object.fromEntries(t):void 0},re=class{constructor(t,n){this.options=t;this.shared=n;this.config=null;this.ready=false;this.stopped=false;this.flushing=false;this.pending=[];this.queue=[];this.teardowns=[];this.pageViews=null;this.connections=new Set;this.timings=new Map;this.sessionDirty=true;this.closed=false;this.liveWatched=false;this.drop=()=>{this.shared.dropped+=1;};var o;let s=window.fetch;this.nativeFetch=(r,i)=>s.call(window,r,i),this.instrumentedOrigins=((o=t.instrumentedOrigins)!=null?o:[]).map(r=>ue(String(r))).filter(r=>r!==null),this.filter=new se(this.drop),this.transport=new oe(me(t,"batch"),this.nativeFetch,{onResult:(r,i,a)=>this.guard(()=>this.onResult(r,i,a)),onLiveWatched:r=>{this.liveWatched=r;},onDrop:r=>{this.shared.dropped+=r;}}),this.session=ct(Date.now());}start(){if(this.session.cut){this.stopped=true;return}let t=Date.now(),n=`${this.options.applicationId}:${this.options.token}`,s=tt(n,t);if(s!==void 0){this.configure(s);return}nt(me(this.options,"config"),this.nativeFetch,n,t).then(o=>this.guard(()=>this.configure(o)),this.drop);}stop(){this.shutdown(),ut();}captureError(t,n){var o,r;let s=cn(n);this.record({id:E(),type:I.RumEventType.ERROR,pageViewId:(r=(o=this.pageViews)==null?void 0:o.currentId())!=null?r:null,occurredAt:M(Date.now()),route:this.resolveRoute(),...un(t),breadcrumbs:[],repeat:1,...s?{context:s}:{}});}markDirty(){this.sessionDirty=true;}replayState(){var n,s,o,r;let t=false;try{t=((s=(n=this.options).consent)==null?void 0:s.call(n).analytics)===!0;}catch{this.drop();}return {record:this.ready&&((o=this.session.decision)==null?void 0:o.replay)===true&&((r=this.config)==null?void 0:r.replay.enabled)===true&&t,liveWatched:this.liveWatched}}guard(t){try{t();}catch{this.drop();}}configure(t){var o,r;if(this.stopped)return;if(!t||!t.enabled){this.shutdown();return}this.config=t,this.session.decision||this.decide(),this.ready=true,this.install();let n=this.pending;this.pending=[];let s=(r=(o=this.pageViews)==null?void 0:o.currentId())!=null?r:null;for(let i of n)i.type===I.RumEventType.ERROR&&i.pageViewId===null&&(i.pageViewId=s),this.record(i);}decide(){let t=this.config,n=navigator.userAgent;this.session.decision=it({route:pe(this.resolveRoute()),deviceType:st(n),browserFamily:ot(n),country:t.country,attributes:{...this.shared.attributes},random:this.session.random,sessionSampleRate:t.sessionSampleRate,replaySampleRate:t.replay.sampleRate},this.options.sampler,t.sessionQuotaExhausted,this.drop),K(this.session);}install(){let t={instrumentedOrigins:this.instrumentedOrigins,sessionId:()=>this.session.id,pageViewId:()=>{var o,r;return (r=(o=this.pageViews)==null?void 0:o.currentId())!=null?r:null},record:o=>this.record(o),drop:this.drop,trackTiming:(o,r,i)=>this.timings.set(o,{url:r,startedAt:i}),trackConnection:o=>this.connections.add(o)};this.pageViews=ze({resolveRoute:()=>this.resolveRoute(),record:o=>this.record(o),onNavigation:()=>this.touch(),drop:this.drop});let n=setInterval(()=>this.guard(()=>this.flush(false)),on),s=()=>this.guard(()=>this.touch());this.teardowns=[this.pageViews.stop,()=>clearInterval(n),Ge(t),je(t),Ke(t),We(t),...this.options.captureConsole===false?[]:[qe(t)],_(window,"click",s,true),_(window,"keydown",s,true),_(window,"error",o=>this.guard(()=>{var r;return this.captureError((r=o.error)!=null?r:o.message)})),_(window,"pagehide",()=>this.guard(()=>this.onPageHide())),_(window,"pageshow",o=>this.guard(()=>{var r;o.persisted&&(this.closed=false,this.sessionDirty=true,(r=this.pageViews)==null||r.start(I.RumNavigationType.BACK_FORWARD));})),_(document,"visibilitychange",()=>this.guard(()=>{document.visibilityState==="hidden"&&this.flush(true);}))];}shutdown(){this.stopped=true,this.ready=false;let t=this.teardowns;this.teardowns=[],t.reverse().forEach(n=>this.guard(n)),this.pending=[],this.queue=[],this.connections.clear(),this.timings.clear();}resolveRoute(){let{routeResolver:t}=this.options;if(t)try{return String(t(window.location))}catch{this.drop();}return window.location.pathname}touch(){var n,s;if(!this.ready)return;let t=Date.now();if(!he(this.session,t)){this.session.lastActivityAt=t,K(this.session);return}(n=this.pageViews)==null||n.end(),this.flush(false),this.shared.dropped+=this.queue.length,this.queue=[],this.session=Re(t),this.decide(),this.filter.reset(),this.sessionDirty=true,this.closed=false,(s=this.pageViews)==null||s.start(I.RumNavigationType.SPA);}onPageHide(){var t;(t=this.pageViews)==null||t.end();for(let n of this.connections)n.done||(n.event.durationMs=Date.now()-n.startedAt,n.done=true,n.dirty=true);this.closed=true,this.sessionDirty=true,this.flush(true);}record(t){var n;try{if(this.stopped)return;if(!this.ready){this.pending.length<an?this.pending.push(t):this.drop();return}let s=((n=this.session.decision)==null?void 0:n.session)===!0;if(!s&&t.type!==I.RumEventType.ERROR&&t.type!==I.RumEventType.PAGE_VIEW)return;let o=He(t,this.options.beforeSend,this.drop);if(!o)return;Xe(o),o.type===I.RumEventType.PAGE_VIEW&&this.session.entryPath===null&&(this.session.entryPath=o.route,K(this.session));for(let r of this.filter.accept(o,s))this.enqueue(r);}catch{this.drop();}}enqueue(t){if(this.queue.length>=lt){this.drop();return}this.queue.push(t),this.queue.length>=rn&&!this.flushing&&this.flush(false);}flush(t){var n,s;if(!(!this.ready||this.flushing||this.transport.isPaused(Date.now()))){this.flushing=true;try{for(let d of this.connections)d.dirty&&(d.dirty=!1,this.record({...d.event})),d.done&&this.connections.delete(d);let o=this.queue;this.queue=[],this.fillTimings(o);let r=((n=this.session.decision)==null?void 0:n.session)===!0;if(o.length===0&&!(r&&this.sessionDirty))return;let a=this.sessionDirty||this.shared.dropped>0?{id:this.session.id,type:I.RumEventType.SESSION,entryPath:(s=this.session.entryPath)!=null?s:"/",sampled:r,closed:this.closed,droppedEvents:this.shared.dropped}:null;this.shared.dropped=0,this.sessionDirty=!1,this.transport.send(this.header(),a?[a,...o]:o,t);}finally{this.flushing=false;}}}header(){let t={sessionId:this.session.id,sessionStartedAt:M(this.session.startedAt)};return this.options.release&&(t.release=this.options.release),this.shared.actor!==void 0&&(t.actor=this.shared.actor),this.shared.attributesSet&&(t.attributes={...this.shared.attributes}),t}fillTimings(t){for(let n of t){let s=this.timings.get(n.id);s&&(this.timings.delete(n.id),Object.assign(n,Fe(s.url,s.startedAt)));}}onResult(t,n,s){if(n==="OK")return;if(n==="CUT"){this.session.cut=true,K(this.session),this.shutdown();return}let o=t.filter(i=>i.type!==I.RumEventType.SESSION),r=t.find(i=>i.type===I.RumEventType.SESSION);if(r&&(this.shared.dropped+=r.droppedEvents,this.sessionDirty=true),n==="RETRY"&&s===this.session.id){let i=o.slice(0,Math.max(0,lt-this.queue.length));this.shared.dropped+=o.length-i.length,this.queue=[...i,...this.queue];return}this.shared.dropped+=o.length;}},pt=null,y={actor:void 0,attributes:{},attributesSet:false,dropped:0},W=()=>pt,Ee=e=>{pt=e;};var X=e=>{try{e();}catch{y.dropped+=1;}},Ts={init(e){X(()=>{if(W()||!(e!=null&&e.token)||!e.applicationId||!e.apiUrl&&!e.proxyUrl||typeof window=="undefined"||typeof window.fetch!="function")return;let t=new re(e,y);Ee(t),t.start();});},setActor(e){X(()=>{var n;let t=ye(e);if(t===void 0){y.dropped+=1;return}y.actor=t,(n=W())==null||n.markDirty();});},setAttributes(e){X(()=>{var t;y.attributes=ve(y.attributes,e,()=>{y.dropped+=1;}),y.attributesSet=!0,(t=W())==null||t.markDirty();});},captureError(e,t){X(()=>{var n;return (n=W())==null?void 0:n.captureError(e,t)});},stop(){X(()=>{var e;(e=W())==null||e.stop(),Ee(null),y.actor=void 0,y.attributes={},y.attributesSet=!1,y.dropped=0;});}};
2
+ exports.AbyssRum=Ts;
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ var ft=Object.create;var Se=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var Et=Object.getPrototypeOf,gt=Object.prototype.hasOwnProperty;var V=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var St=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Rt(t))!gt.call(e,o)&&o!==n&&Se(e,o,{get:()=>t[o],enumerable:!(s=ht(t,o))||s.enumerable});return e};var v=(e,t,n)=>(n=e!=null?ft(Et(e)):{},St(!e||!e.__esModule?Se(n,"default",{value:e,enumerable:true}):n,e));var Pe=V(f=>{Object.defineProperty(f,"__esModule",{value:true});f.RumCspDisposition=f.RumBreadcrumbKind=f.RumConsoleLevel=f.RumTimingKind=f.RumSocketBinaryType=f.RumSocketDirection=f.RumFrustrationType=f.RumDeviceType=f.RumNavigationType=f.RumRequestKind=f.RumRequestOutcome=f.RumEventType=void 0;var Ie;(function(e){e.SESSION="session",e.PAGE_VIEW="pageView",e.VITALS="vitals",e.REQUEST="request",e.ERROR="error",e.CONSOLE="console",e.ACTION="action",e.FRUSTRATION="frustration",e.TIMING="timing",e.CSP_VIOLATION="cspViolation",e.SOCKET_MESSAGE="socketMessage",e.FEEDBACK="feedback";})(Ie||(f.RumEventType=Ie={}));var be;(function(e){e.SUCCESS="SUCCESS",e.HTTP_ERROR="HTTP_ERROR",e.NETWORK_ERROR="NETWORK_ERROR",e.OFFLINE="OFFLINE",e.ABORTED="ABORTED",e.TIMEOUT="TIMEOUT";})(be||(f.RumRequestOutcome=be={}));var Te;(function(e){e.FETCH="FETCH",e.XHR="XHR",e.RESOURCE="RESOURCE",e.WEBSOCKET="WEBSOCKET",e.SSE="SSE";})(Te||(f.RumRequestKind=Te={}));var Ae;(function(e){e.NAVIGATE="NAVIGATE",e.RELOAD="RELOAD",e.BACK_FORWARD="BACK_FORWARD",e.SPA="SPA";})(Ae||(f.RumNavigationType=Ae={}));var we;(function(e){e.DESKTOP="desktop",e.MOBILE="mobile",e.TABLET="tablet";})(we||(f.RumDeviceType=we={}));var Oe;(function(e){e.RAGE_CLICK="RAGE_CLICK",e.DEAD_CLICK="DEAD_CLICK",e.ERROR_CLICK="ERROR_CLICK";})(Oe||(f.RumFrustrationType=Oe={}));var _e;(function(e){e.IN="IN",e.OUT="OUT";})(_e||(f.RumSocketDirection=_e={}));var Ce;(function(e){e.BLOB="blob",e.ARRAYBUFFER="arraybuffer";})(Ce||(f.RumSocketBinaryType=Ce={}));var Me;(function(e){e.TIMING="TIMING",e.DURATION="DURATION";})(Me||(f.RumTimingKind=Me={}));var ke;(function(e){e.ERROR="error",e.WARN="warn";})(ke||(f.RumConsoleLevel=ke={}));var De;(function(e){e.NAVIGATION="NAVIGATION",e.REQUEST="REQUEST",e.CLICK="CLICK";})(De||(f.RumBreadcrumbKind=De={}));var Ne;(function(e){e.ENFORCE="enforce",e.REPORT="report";})(Ne||(f.RumCspDisposition=Ne={}));});var Le=V(Ue=>{Object.defineProperty(Ue,"__esModule",{value:true});});var ie=V(P=>{Object.defineProperty(P,"__esModule",{value:true});P.isUuid=P.UUID_PATTERN=void 0;P.UUID_PATTERN=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;var bt=e=>typeof e=="string"&&P.UUID_PATTERN.test(e);P.isUuid=bt;});var xe=V(O=>{Object.defineProperty(O,"__esModule",{value:true});O.maskUrl=O.MASK_URL_MAX_SEGMENT_LENGTH=O.MASKED_SEGMENT=void 0;var Tt=ie();O.MASKED_SEGMENT=":id";O.MASK_URL_MAX_SEGMENT_LENGTH=40;var At=/^\d{3,}$/,wt=/^[0-9a-f]{16,}$/i,Ot=/^[a-z][a-z0-9+.-]*:\/\//i,_t=e=>e.length>O.MASK_URL_MAX_SEGMENT_LENGTH||Tt.UUID_PATTERN.test(e)||At.test(e)||wt.test(e),Ct=e=>e===""?"/":e.split("/").map(t=>_t(t)?O.MASKED_SEGMENT:t).join("/"),Mt=e=>{try{let t=new URL(e.startsWith("//")?`https:${e}`:e);return {host:t.host===""?null:t.host.toLowerCase(),path:t.pathname}}catch{return {host:null,path:"/"}}},kt=e=>{let n=(typeof e=="string"?e.trim():"").split("#")[0].split("?")[0],{host:s,path:o}=Ot.test(n)||n.startsWith("//")?Mt(n):{host:null,path:n};return {host:s,path:Ct(o)}};O.maskUrl=kt;});var Ve=V(R=>{Object.defineProperty(R,"__esModule",{value:true});R.TIMING_ALLOW_ORIGIN_HEADER=R.SOCKET_SESSION_ID_PARAM=R.SOCKET_REQUEST_ID_PARAM=R.MONITOR_CORRELATION_HEADERS=R.SESSION_ID_HEADER=R.REQUEST_ID_HEADER=void 0;R.REQUEST_ID_HEADER="x-abyss-request-id";R.SESSION_ID_HEADER="x-abyss-session-id";R.MONITOR_CORRELATION_HEADERS=[R.REQUEST_ID_HEADER,R.SESSION_ID_HEADER];R.SOCKET_REQUEST_ID_PARAM="abyss_rid";R.SOCKET_SESSION_ID_PARAM="abyss_sid";R.TIMING_ALLOW_ORIGIN_HEADER="Timing-Allow-Origin";});var g=V(A=>{var Dt=A&&A.__createBinding||(Object.create?(function(e,t,n,s){s===void 0&&(s=n);var o=Object.getOwnPropertyDescriptor(t,n);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:true,get:function(){return t[n]}}),Object.defineProperty(e,s,o);}):(function(e,t,n,s){s===void 0&&(s=n),e[s]=t[n];})),G=A&&A.__exportStar||function(e,t){for(var n in e)n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n)&&Dt(t,e,n);};Object.defineProperty(A,"__esModule",{value:true});G(Pe(),A);G(Le(),A);G(xe(),A);G(Ve(),A);G(ie(),A);});var ye=e=>e===null?null:typeof e=="string"&&e.trim()!==""?e:void 0;var yt=/^[a-zA-Z0-9_.-]{1,64}$/,vt=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),It=e=>typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e)||typeof e=="string"&&e.length<=256,ve=(e,t,n)=>{let s={...e};if(!t||typeof t!="object"||Array.isArray(t))return n(),s;for(let[o,r]of Object.entries(t))!yt.test(o)||o==="__proto__"?n():r===null?delete s[o]:!It(r)||!vt(s,o)&&Object.keys(s).length>=30?n():s[o]=r;return s};var I=v(g());var Nt=["id","type","sessionId"],Pt=(e,t)=>e==null?t==null||["string","number","boolean"].includes(typeof t):Array.isArray(e)?Array.isArray(t):t!==null&&typeof t==typeof e,He=(e,t,n)=>{if(!t)return e;let s;try{s=t(JSON.parse(JSON.stringify(e)));}catch{return n(),e}if(s===null)return null;if(!s||typeof s!="object"||Array.isArray(s))return n(),null;let o=e,r=s,i={};for(let a of Object.keys(o))if(Nt.includes(a))i[a]=o[a];else if(Pt(o[a],r[a]))r[a]!==void 0&&(i[a]=r[a]);else return n(),null;return i};var j=v(g());var M=e=>new Date(e).toISOString(),S=(e,t)=>e>0&&t>=e?Math.round(t-e):null,$=e=>{var t;if(typeof e=="string")return e;if(e instanceof Error)return `${e.name}: ${e.message}`;try{return (t=JSON.stringify(e))!=null?t:String(e)}catch{return String(e)}},_=(e,t,n,s=false)=>{let o={capture:s,passive:true};return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)},H=e=>{let t=0;for(let n=0;n<e.length;n+=1){let s=e.charCodeAt(n);s<128?t+=1:s<2048?t+=2:s>=55296&&s<56320?(t+=4,n+=1):t+=3;}return t},Q=(e,t)=>{if(H(e)<=t)return e;let n=0;for(let s=0;s<e.length;s+=1){let o=e.charCodeAt(s)>=55296&&e.charCodeAt(s)<56320,r=H(e.slice(s,o?s+2:s+1));if(n+r>t)return e.slice(0,s);n+=r,o&&(s+=1);}return e},ae=e=>{if(typeof e=="string")return H(e);if(typeof Blob!="undefined"&&e instanceof Blob)return e.size;let t=e==null?void 0:e.byteLength;return typeof t=="number"?t:0},z=e=>{try{let t=sessionStorage.getItem(e);return t===null?null:JSON.parse(t)}catch{return null}},Y=(e,t)=>{try{sessionStorage.setItem(e,JSON.stringify(t));}catch{}},Be=e=>{try{sessionStorage.removeItem(e);}catch{}};var E=()=>{let e=globalThis.crypto;if(typeof(e==null?void 0:e.randomUUID)=="function")return e.randomUUID();let t=new Uint8Array(16);e.getRandomValues(t),t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=Array.from(t,s=>(s+256).toString(16).slice(1)).join("");return `${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`};var Ut=1024,Lt=50,qe=e=>{let t=[["error",j.RumConsoleLevel.ERROR],["warn",j.RumConsoleLevel.WARN]],n=null,s=0,o=t.map(([r,i])=>{let a=console[r],d=(...c)=>{try{let u=e.pageViewId();u!==n&&(n=u,s=0),s+=1,s>Lt?e.drop():e.record({id:E(),type:j.RumEventType.CONSOLE,pageViewId:u,occurredAt:M(Date.now()),level:i,message:Q(c.map($).join(" "),Ut)});}catch{e.drop();}a.apply(console,c);};return console[r]=d,()=>{console[r]===d&&(console[r]=a);}});return ()=>o.forEach(r=>r())};var C=v(g());var J=4096,U=e=>{try{return new URL(e,window.location.href)}catch{return null}},ue=e=>{let t=U(e);return t?`${t.protocol==="ws:"?"http:":t.protocol==="wss:"?"https:":t.protocol}//${t.host}`.toLowerCase():null},B=(e,t)=>{var n;return e.instrumentedOrigins.includes((n=ue(t.href))!=null?n:"")},k=e=>{let t=e==null?void 0:e.name;return t==="AbortError"?C.RumRequestOutcome.ABORTED:t==="TimeoutError"?C.RumRequestOutcome.TIMEOUT:navigator.onLine===false?C.RumRequestOutcome.OFFLINE:C.RumRequestOutcome.NETWORK_ERROR},Z=e=>e>=400?C.RumRequestOutcome.HTTP_ERROR:C.RumRequestOutcome.SUCCESS,q=(e,t,n,s,o,r)=>({id:E(),type:C.RumEventType.REQUEST,pageViewId:e.pageViewId(),kind:t,method:n,url:s,startedAt:M(o),status:null,outcome:C.RumRequestOutcome.SUCCESS,durationMs:null,dnsMs:null,tcpMs:null,tlsMs:null,ttfbMs:null,downloadMs:null,requestId:r,instrumented:r!==null}),Fe=(e,t)=>{let n;try{n=performance.getEntriesByName(e,"resource");}catch{return null}let s=n.filter(o=>performance.timeOrigin+o.startTime>=t-50).pop();return !s||!s.requestStart?null:{dnsMs:S(s.domainLookupStart,s.domainLookupEnd),tcpMs:S(s.connectStart,s.connectEnd),tlsMs:s.secureConnectionStart>0?S(s.secureConnectionStart,s.connectEnd):null,ttfbMs:S(s.requestStart,s.responseStart),downloadMs:S(s.responseStart,s.responseEnd)}};var L=v(g());var w=v(g());var xt=123,ce=(e,t,n)=>{let s=U(String(n));if(!s)return null;let o=s.href,r=null;B(e,s)&&(r=E(),s.searchParams.set(w.SOCKET_REQUEST_ID_PARAM,r),s.searchParams.set(w.SOCKET_SESSION_ID_PARAM,e.sessionId()));let i=Date.now(),a=q(e,t,"GET",o,i,r);Object.assign(a,{connectMs:null,messagesIn:0,messagesOut:0,bytesIn:0,bytesOut:0,droppedMessages:0});let d={event:a,startedAt:i,opened:false,dirty:true,done:false};return e.trackConnection(d),{connection:d,nativeUrl:r===null?String(n):s.href}},de=e=>{e.opened||(e.opened=true,e.event.connectMs=Date.now()-e.startedAt,e.dirty=true);},ee=(e,t,n)=>{var o,r,i,a;let{event:s}=e;t==="in"?(s.messagesIn=((o=s.messagesIn)!=null?o:0)+1,s.bytesIn=((r=s.bytesIn)!=null?r:0)+ae(n)):(s.messagesOut=((i=s.messagesOut)!=null?i:0)+1,s.bytesOut=((a=s.bytesOut)!=null?a:0)+ae(n)),e.dirty=true;},te=(e,t)=>{e.done||(e.event.durationMs=Date.now()-e.startedAt,e.event.outcome=t,e.done=true,e.dirty=true);},Vt=(e,t,n,s)=>{if(n)return w.RumRequestOutcome.ABORTED;if(e&&(t===1e3||t===1001||s&&t===1005))return w.RumRequestOutcome.SUCCESS;let o=k();return o===w.RumRequestOutcome.OFFLINE||!e?o:w.RumRequestOutcome.HTTP_ERROR},Ke=e=>{let t=window.WebSocket;if(typeof t!="function")return ()=>{};let n=t.prototype,s=n.send,o=n.close,r=new WeakMap,i=(u,l)=>{r.set(u,l),u.addEventListener("open",()=>de(l)),u.addEventListener("message",p=>ee(l,"in",p.data)),u.addEventListener("close",p=>{let h=r.get(u);l.event.closeCode=p.code,l.event.closeReason=p.reason?Q(p.reason,xt):null,te(l,Vt(l.opened,p.code,(h==null?void 0:h.abortedByApp)===true,(h==null?void 0:h.closedByApp)===true));});},a=new Proxy(t,{construct(u,l,p){let h=null;try{h=ce(e,w.RumRequestKind.WEBSOCKET,l[0]);}catch{e.drop();}let b=h?[h.nativeUrl,...l.slice(1)]:l,m=Reflect.construct(u,b,p===a?u:p);return h&&i(m,h.connection),m}}),d=function(u){s.call(this,u);let l=r.get(this);l&&ee(l,"out",u);},c=function(u,l){let p=r.get(this);return p&&(p.abortedByApp=this.readyState===t.CONNECTING,p.closedByApp=true),o.apply(this,arguments)};return window.WebSocket=a,n.send=d,n.close=c,()=>{window.WebSocket===a&&(window.WebSocket=t),n.send===d&&(n.send=s),n.close===c&&(n.close=o);}};var We=e=>{let t=window,n=t.EventSource;if(typeof n!="function")return ()=>{};let s=n.prototype,o=s.close,r=new WeakMap,i=(c,u)=>{r.set(c,u),u.event.reconnectCount=0,c.addEventListener("open",()=>de(u)),c.addEventListener("message",l=>ee(u,"in",l.data)),c.addEventListener("error",()=>{var p;if(c.readyState===n.CONNECTING){u.event.reconnectCount=((p=u.event.reconnectCount)!=null?p:0)+1,u.dirty=true;return}let l=k();te(u,u.opened&&l!==L.RumRequestOutcome.OFFLINE?L.RumRequestOutcome.HTTP_ERROR:l);});},a=new Proxy(n,{construct(c,u,l){let p=null;try{p=ce(e,L.RumRequestKind.SSE,u[0]);}catch{e.drop();}let h=p?[p.nativeUrl,...u.slice(1)]:u,b=Reflect.construct(c,h,l===a?c:l);return p&&i(b,p.connection),b}}),d=function(){o.call(this);let c=r.get(this);c&&te(c,c.opened?L.RumRequestOutcome.SUCCESS:L.RumRequestOutcome.ABORTED);};return t.EventSource=a,s.close=d,()=>{t.EventSource===a&&(t.EventSource=n),s.close===d&&(s.close=o);}};var F=v(g());var Ht=(e,t,n)=>{var u,l,p;let s=typeof Request!="undefined"&&t instanceof Request?t:null,o=U(s?s.url:String(t));if(!o)return null;let r=((l=(u=n==null?void 0:n.method)!=null?u:s==null?void 0:s.method)!=null?l:"GET").toUpperCase(),i=Date.now(),a=null,d=n;if(B(e,o)){a=E();let h=new Headers((p=n==null?void 0:n.headers)!=null?p:s==null?void 0:s.headers);h.set(F.REQUEST_ID_HEADER,a),h.set(F.SESSION_ID_HEADER,e.sessionId()),d={...n,headers:h};}let c=q(e,F.RumRequestKind.FETCH,r,o.href,i,a);return e.trackTiming(c.id,o.href,i),{event:c,init:d,startedAt:i}},Bt=(e,t,n)=>{let{event:s}=t;if(s.durationMs=Date.now()-t.startedAt,s.status=n.status,s.outcome=Z(n.status),s.instrumented||n.status<400){e.record(s);return}n.clone().text().then(o=>{s.responseBodyExcerpt=o.slice(0,J),e.record(s);},()=>e.record(s));},Ge=e=>{let t=window.fetch;if(typeof t!="function")return ()=>{};let n=(s,o)=>{let r=null;try{r=Ht(e,s,o);}catch{e.drop();}let i=t.call(window,s,r?r.init:o);if(r){let a=r;i.then(d=>{try{Bt(e,a,d);}catch{e.drop();}},d=>{a.event.durationMs=Date.now()-a.startedAt,a.event.outcome=k(d),e.record(a.event);});}return i};return window.fetch=n,()=>{window.fetch===n&&(window.fetch=t);}};var D=v(g());var je=e=>{let t=window.XMLHttpRequest;if(typeof t!="function")return ()=>{};let n=t.prototype,s=n.open,o=n.send,r=new WeakMap,i=function(c,u){try{r.set(this,{method:String(c).toUpperCase(),url:String(u)});}catch{e.drop();}return s.apply(this,arguments)},a=(c,u,l)=>{let p=U(l);if(!p)return;let h=Date.now(),b=null;B(e,p)&&(b=E(),c.setRequestHeader(D.REQUEST_ID_HEADER,b),c.setRequestHeader(D.SESSION_ID_HEADER,e.sessionId()));let m=q(e,D.RumRequestKind.XHR,u,p.href,h,b);e.trackTiming(m.id,p.href,h);let T=null;c.addEventListener("error",()=>T=k()),c.addEventListener("abort",()=>T=D.RumRequestOutcome.ABORTED),c.addEventListener("timeout",()=>T=D.RumRequestOutcome.TIMEOUT),c.addEventListener("loadend",()=>{m.durationMs=Date.now()-h,m.status=T===null&&c.status>0?c.status:null,m.outcome=m.status===null?T!=null?T:k():Z(m.status),!m.instrumented&&m.status!==null&&m.status>=400&&(c.responseType===""||c.responseType==="text")&&(m.responseBodyExcerpt=c.responseText.slice(0,J)),e.record(m);});},d=function(c){let u=r.get(this);if(u)try{a(this,u.method,u.url);}catch{e.drop();}return o.call(this,c)};return n.open=i,n.send=d,()=>{n.open===i&&(n.open=s),n.send===d&&(n.send=o);}};var le=v(g()),qt=/^([a-z][a-z0-9+.-]*:)\/\//i,Ft=["url","blockedUri","sourceFile"],Kt=["route","referrerRoute","entryPath"],Wt=e=>{let{host:t,path:n}=(0, le.maskUrl)(e);if(t===null)return n;let s=qt.exec(e.trim());return `${s?s[1].toLowerCase():"https:"}//${t}${n}`},pe=e=>(0, le.maskUrl)(e).path,Xe=e=>{let t=e;for(let n of Ft)typeof t[n]=="string"&&(t[n]=Wt(t[n]));for(let n of Kt)typeof t[n]=="string"&&(t[n]=pe(t[n]));return e};var x=v(g());var Gt={reload:x.RumNavigationType.RELOAD,back_forward:x.RumNavigationType.BACK_FORWARD},$e=()=>{try{return performance.getEntriesByType("navigation")[0]}catch{return}},Qe=e=>({dnsMs:e?S(e.domainLookupStart,e.domainLookupEnd):null,tcpMs:e?S(e.connectStart,e.connectEnd):null,tlsMs:e&&e.secureConnectionStart>0?S(e.secureConnectionStart,e.connectEnd):null,requestMs:e?S(e.requestStart,e.responseStart):null,responseMs:e?S(e.responseStart,e.responseEnd):null,domProcessingMs:e?S(e.responseEnd,e.domComplete):null,loadMs:e&&e.loadEventEnd>0?Math.round(e.loadEventEnd-e.startTime):null}),ze=e=>{var h,b;let t=null,n=null,s=(m,T=null,mt)=>{let ge=Date.now();return t={startedAt:ge,path:window.location.pathname,event:{id:E(),type:x.RumEventType.PAGE_VIEW,route:e.resolveRoute(),referrerRoute:T,startedAt:M(ge),durationMs:null,navigationType:m,lcpMs:null,inpMs:null,cls:null,fcpMs:null,ttfbMs:null,dnsMs:null,tcpMs:null,tlsMs:null,requestMs:null,responseMs:null,domProcessingMs:null,loadMs:null,longTaskCount:0,longTaskTotalMs:0,...mt}},e.record({...t.event}),t.event.id},o=()=>{t&&(t.event.durationMs=Date.now()-t.startedAt,e.record({...t.event}));},r=()=>{try{if(e.onNavigation(),t&&window.location.pathname!==t.path){let m=t.event.route;o(),s(x.RumNavigationType.SPA,m);}}catch{e.drop();}},i=()=>{t&&t.event.id===n&&(Object.assign(t.event,Qe($e())),e.record({...t.event}));},a=$e(),d=document.readyState==="complete",c=(b=Gt[(h=a==null?void 0:a.type)!=null?h:""])!=null?b:x.RumNavigationType.NAVIGATE;n=s(c,null,d?Qe(a):void 0);let u=[_(window,"popstate",r)];if(!d){let m;u.push(_(window,"load",()=>{m=setTimeout(i,0);}),()=>clearTimeout(m));}let l=window.history.pushState,p=function(...m){let T=l.apply(this,m);return r(),T};return window.history.pushState=p,u.push(()=>{window.history.pushState===p&&(window.history.pushState=l);}),{currentId:()=>{var m;return (m=t==null?void 0:t.event.id)!=null?m:null},start:m=>{s(m);},end:o,stop:()=>u.forEach(m=>m())}};var Ye=e=>e.replace(/\/+$/,""),me=(e,t)=>`${e.proxyUrl?`${Ye(e.proxyUrl)}/rum`:`${Ye(e.apiUrl)}/api/rum`}/${encodeURIComponent(e.applicationId)}/${t}?token=${encodeURIComponent(e.token)}`;var Ze="abyss-rum-config",jt=600*1e3,Je=e=>typeof e=="number"&&e>=0&&e<=1?e:0,et=e=>{var s,o;let t=e;if(!t||typeof t.enabled!="boolean"||typeof t.sessionSampleRate!="number")return null;let n=(s=t.replay)!=null?s:{};return {enabled:t.enabled,sessionSampleRate:Je(t.sessionSampleRate),sessionQuotaExhausted:t.sessionQuotaExhausted===true,country:typeof t.country=="string"?t.country:null,feedbackEnabled:t.feedbackEnabled===true,replay:{enabled:n.enabled===true,sampleRate:Je(n.sampleRate),unmaskSelectors:Array.isArray(n.unmaskSelectors)?n.unmaskSelectors.filter(r=>typeof r=="string"):[]},socketMessages:{enabled:((o=t.socketMessages)==null?void 0:o.enabled)===true}}},tt=(e,t)=>{let n=z(Ze);if(!n||n.key!==e||typeof n.at!="number")return;let s=t-n.at;return s>=0&&s<jt?et(n.config):void 0},nt=async(e,t,n,s)=>{let o=null;try{let r=await t(e,{credentials:"omit"});o=r.ok?et(await r.json()):null;}catch{o=null;}return Y(Ze,{key:n,at:s,config:o}),o};var ne=v(g()),Xt=/iPad|Tablet|PlayBook|Silk|Android(?!.*Mobile)/i,$t=/Mobi|iPhone|iPod|Android|Opera Mini|IEMobile/i,Qt=[[/Edg(e|A|iOS)?\//,"Edge"],[/OPR\/|Opera/,"Opera"],[/SamsungBrowser\//,"Samsung Internet"],[/Firefox\/|FxiOS\//,"Firefox"],[/Chrome\/|CriOS\//,"Chrome"],[/Safari\//,"Safari"]],st=e=>Xt.test(e)?ne.RumDeviceType.TABLET:$t.test(e)?ne.RumDeviceType.MOBILE:ne.RumDeviceType.DESKTOP,ot=e=>{var t,n;return (n=(t=Qt.find(([s])=>s.test(e)))==null?void 0:t[1])!=null?n:"Other"},rt=(e,t,n,s)=>{if(!e)return n;try{let o=e({...t,attributes:{...t.attributes}});if(typeof(o==null?void 0:o.session)=="boolean"&&typeof o.replay=="boolean")return {session:o.session,replay:o.replay}}catch{}return s(),n};var N=v(g());var zt=200,Yt=(e,t,n)=>({session:e<t,replay:e<t*n}),it=(e,t,n,s)=>{let o=Yt(e.random,e.sessionSampleRate,e.replaySampleRate),r=rt(t,e,o,s),i=r.session&&!n;return {session:i,replay:i&&r.replay}},Jt=e=>e.type===N.RumEventType.REQUEST&&(e.kind===N.RumRequestKind.FETCH||e.kind===N.RumRequestKind.XHR)&&e.outcome===N.RumRequestOutcome.SUCCESS,se=class{constructor(t){this.onDrop=t;this.held=null;this.released=new Set;this.successes=new Map;}accept(t,n){var o,r,i;if(n){if(Jt(t)){let a=(o=t.pageViewId)!=null?o:"",d=((r=this.successes.get(a))!=null?r:0)+1;if(this.successes.set(a,d),d>zt)return this.onDrop(),[]}return [t]}if(t.type===N.RumEventType.PAGE_VIEW)return this.released.has(t.id)?[t]:(this.held=t,[]);if(t.type!==N.RumEventType.ERROR)return [];let s=[];return t.pageViewId!==null&&!this.released.has(t.pageViewId)&&(this.released.add(t.pageViewId),((i=this.held)==null?void 0:i.id)===t.pageViewId&&(s.push(this.held),this.held=null)),s.push(t),s}reset(){this.held=null,this.released.clear(),this.successes.clear();}};var at=v(g());var fe="abyss-rum-session",Zt=1800*1e3,en=14400*1e3,he=(e,t)=>t-e.lastActivityAt>=Zt||t-e.startedAt>=en,tn=e=>typeof(e==null?void 0:e.session)=="boolean"&&typeof e.replay=="boolean",nn=()=>{let e=z(fe);return !e||!(0, at.isUuid)(e.id)||typeof e.startedAt!="number"||typeof e.lastActivityAt!="number"||typeof e.random!="number"?null:{id:e.id,startedAt:e.startedAt,lastActivityAt:e.lastActivityAt,random:e.random,decision:tn(e.decision)?e.decision:null,entryPath:typeof e.entryPath=="string"?e.entryPath:null,cut:e.cut===true}},K=e=>Y(fe,e),ut=()=>Be(fe),Re=e=>{let t={id:E(),startedAt:e,lastActivityAt:e,random:Math.random(),decision:null,entryPath:null,cut:false};return K(t),t},ct=e=>{let t=nn();return t&&!he(t,e)?t:Re(e)};var dt=64*1024,sn=60*1e3;var oe=class{constructor(t,n,s){this.url=t;this.fetchImpl=n;this.handlers=s;this.pausedUntil=0;}isPaused(t){return t<this.pausedUntil}send(t,n,s){let o=JSON.stringify({...t,events:[]}).slice(0,-2),r=H(o)+2,i=[],a=[],d=r;for(let c of n){let u=JSON.stringify(c),l=H(u);if(r+l>dt){this.handlers.onDrop(1);continue}let p=l+(i.length>0?1:0);d+p>dt&&(this.post(`${o}${i.join(",")}]}`,a,s,t.sessionId),i=[],a=[],d=r),d+=l+(i.length>0?1:0),i.push(u),a.push(c);}i.length>0&&this.post(`${o}${i.join(",")}]}`,a,s,t.sessionId);}post(t,n,s,o){let r=i=>this.handlers.onResult(n,i,o);if(s&&this.beacon(t)){r("OK");return}this.fetchImpl(this.url,{method:"POST",body:t,keepalive:true,credentials:"omit",headers:{"Content-Type":"text/plain;charset=UTF-8"}}).then(i=>this.handle(i,r),()=>r("FAIL")).catch(()=>this.handlers.onDrop(1));}beacon(t){try{return typeof navigator.sendBeacon=="function"&&navigator.sendBeacon(this.url,t)}catch{return false}}async handle(t,n){if(t.status===429){this.pausedUntil=Date.now()+sn,n("RETRY");return}if(t.status===401||t.status===403||t.status===404){n("CUT");return}if(!t.ok){n("FAIL");return}n("OK");let s=false;try{s=(await t.json()).liveWatched===!0;}catch{}this.handlers.onLiveWatched(s);}};var on=5e3,rn=50,lt=200,an=50,un=e=>{let t=e;return t&&typeof t=="object"&&typeof t.message=="string"?{name:typeof t.name=="string"&&t.name?t.name:"Error",message:t.message,stack:typeof t.stack=="string"?t.stack:null}:{name:"Error",message:$(e),stack:null}},cn=e=>{if(!e||typeof e!="object")return;let t=Object.entries(e).filter(([,n])=>typeof n=="string");return t.length>0?Object.fromEntries(t):void 0},re=class{constructor(t,n){this.options=t;this.shared=n;this.config=null;this.ready=false;this.stopped=false;this.flushing=false;this.pending=[];this.queue=[];this.teardowns=[];this.pageViews=null;this.connections=new Set;this.timings=new Map;this.sessionDirty=true;this.closed=false;this.liveWatched=false;this.drop=()=>{this.shared.dropped+=1;};var o;let s=window.fetch;this.nativeFetch=(r,i)=>s.call(window,r,i),this.instrumentedOrigins=((o=t.instrumentedOrigins)!=null?o:[]).map(r=>ue(String(r))).filter(r=>r!==null),this.filter=new se(this.drop),this.transport=new oe(me(t,"batch"),this.nativeFetch,{onResult:(r,i,a)=>this.guard(()=>this.onResult(r,i,a)),onLiveWatched:r=>{this.liveWatched=r;},onDrop:r=>{this.shared.dropped+=r;}}),this.session=ct(Date.now());}start(){if(this.session.cut){this.stopped=true;return}let t=Date.now(),n=`${this.options.applicationId}:${this.options.token}`,s=tt(n,t);if(s!==void 0){this.configure(s);return}nt(me(this.options,"config"),this.nativeFetch,n,t).then(o=>this.guard(()=>this.configure(o)),this.drop);}stop(){this.shutdown(),ut();}captureError(t,n){var o,r;let s=cn(n);this.record({id:E(),type:I.RumEventType.ERROR,pageViewId:(r=(o=this.pageViews)==null?void 0:o.currentId())!=null?r:null,occurredAt:M(Date.now()),route:this.resolveRoute(),...un(t),breadcrumbs:[],repeat:1,...s?{context:s}:{}});}markDirty(){this.sessionDirty=true;}replayState(){var n,s,o,r;let t=false;try{t=((s=(n=this.options).consent)==null?void 0:s.call(n).analytics)===!0;}catch{this.drop();}return {record:this.ready&&((o=this.session.decision)==null?void 0:o.replay)===true&&((r=this.config)==null?void 0:r.replay.enabled)===true&&t,liveWatched:this.liveWatched}}guard(t){try{t();}catch{this.drop();}}configure(t){var o,r;if(this.stopped)return;if(!t||!t.enabled){this.shutdown();return}this.config=t,this.session.decision||this.decide(),this.ready=true,this.install();let n=this.pending;this.pending=[];let s=(r=(o=this.pageViews)==null?void 0:o.currentId())!=null?r:null;for(let i of n)i.type===I.RumEventType.ERROR&&i.pageViewId===null&&(i.pageViewId=s),this.record(i);}decide(){let t=this.config,n=navigator.userAgent;this.session.decision=it({route:pe(this.resolveRoute()),deviceType:st(n),browserFamily:ot(n),country:t.country,attributes:{...this.shared.attributes},random:this.session.random,sessionSampleRate:t.sessionSampleRate,replaySampleRate:t.replay.sampleRate},this.options.sampler,t.sessionQuotaExhausted,this.drop),K(this.session);}install(){let t={instrumentedOrigins:this.instrumentedOrigins,sessionId:()=>this.session.id,pageViewId:()=>{var o,r;return (r=(o=this.pageViews)==null?void 0:o.currentId())!=null?r:null},record:o=>this.record(o),drop:this.drop,trackTiming:(o,r,i)=>this.timings.set(o,{url:r,startedAt:i}),trackConnection:o=>this.connections.add(o)};this.pageViews=ze({resolveRoute:()=>this.resolveRoute(),record:o=>this.record(o),onNavigation:()=>this.touch(),drop:this.drop});let n=setInterval(()=>this.guard(()=>this.flush(false)),on),s=()=>this.guard(()=>this.touch());this.teardowns=[this.pageViews.stop,()=>clearInterval(n),Ge(t),je(t),Ke(t),We(t),...this.options.captureConsole===false?[]:[qe(t)],_(window,"click",s,true),_(window,"keydown",s,true),_(window,"error",o=>this.guard(()=>{var r;return this.captureError((r=o.error)!=null?r:o.message)})),_(window,"pagehide",()=>this.guard(()=>this.onPageHide())),_(window,"pageshow",o=>this.guard(()=>{var r;o.persisted&&(this.closed=false,this.sessionDirty=true,(r=this.pageViews)==null||r.start(I.RumNavigationType.BACK_FORWARD));})),_(document,"visibilitychange",()=>this.guard(()=>{document.visibilityState==="hidden"&&this.flush(true);}))];}shutdown(){this.stopped=true,this.ready=false;let t=this.teardowns;this.teardowns=[],t.reverse().forEach(n=>this.guard(n)),this.pending=[],this.queue=[],this.connections.clear(),this.timings.clear();}resolveRoute(){let{routeResolver:t}=this.options;if(t)try{return String(t(window.location))}catch{this.drop();}return window.location.pathname}touch(){var n,s;if(!this.ready)return;let t=Date.now();if(!he(this.session,t)){this.session.lastActivityAt=t,K(this.session);return}(n=this.pageViews)==null||n.end(),this.flush(false),this.shared.dropped+=this.queue.length,this.queue=[],this.session=Re(t),this.decide(),this.filter.reset(),this.sessionDirty=true,this.closed=false,(s=this.pageViews)==null||s.start(I.RumNavigationType.SPA);}onPageHide(){var t;(t=this.pageViews)==null||t.end();for(let n of this.connections)n.done||(n.event.durationMs=Date.now()-n.startedAt,n.done=true,n.dirty=true);this.closed=true,this.sessionDirty=true,this.flush(true);}record(t){var n;try{if(this.stopped)return;if(!this.ready){this.pending.length<an?this.pending.push(t):this.drop();return}let s=((n=this.session.decision)==null?void 0:n.session)===!0;if(!s&&t.type!==I.RumEventType.ERROR&&t.type!==I.RumEventType.PAGE_VIEW)return;let o=He(t,this.options.beforeSend,this.drop);if(!o)return;Xe(o),o.type===I.RumEventType.PAGE_VIEW&&this.session.entryPath===null&&(this.session.entryPath=o.route,K(this.session));for(let r of this.filter.accept(o,s))this.enqueue(r);}catch{this.drop();}}enqueue(t){if(this.queue.length>=lt){this.drop();return}this.queue.push(t),this.queue.length>=rn&&!this.flushing&&this.flush(false);}flush(t){var n,s;if(!(!this.ready||this.flushing||this.transport.isPaused(Date.now()))){this.flushing=true;try{for(let d of this.connections)d.dirty&&(d.dirty=!1,this.record({...d.event})),d.done&&this.connections.delete(d);let o=this.queue;this.queue=[],this.fillTimings(o);let r=((n=this.session.decision)==null?void 0:n.session)===!0;if(o.length===0&&!(r&&this.sessionDirty))return;let a=this.sessionDirty||this.shared.dropped>0?{id:this.session.id,type:I.RumEventType.SESSION,entryPath:(s=this.session.entryPath)!=null?s:"/",sampled:r,closed:this.closed,droppedEvents:this.shared.dropped}:null;this.shared.dropped=0,this.sessionDirty=!1,this.transport.send(this.header(),a?[a,...o]:o,t);}finally{this.flushing=false;}}}header(){let t={sessionId:this.session.id,sessionStartedAt:M(this.session.startedAt)};return this.options.release&&(t.release=this.options.release),this.shared.actor!==void 0&&(t.actor=this.shared.actor),this.shared.attributesSet&&(t.attributes={...this.shared.attributes}),t}fillTimings(t){for(let n of t){let s=this.timings.get(n.id);s&&(this.timings.delete(n.id),Object.assign(n,Fe(s.url,s.startedAt)));}}onResult(t,n,s){if(n==="OK")return;if(n==="CUT"){this.session.cut=true,K(this.session),this.shutdown();return}let o=t.filter(i=>i.type!==I.RumEventType.SESSION),r=t.find(i=>i.type===I.RumEventType.SESSION);if(r&&(this.shared.dropped+=r.droppedEvents,this.sessionDirty=true),n==="RETRY"&&s===this.session.id){let i=o.slice(0,Math.max(0,lt-this.queue.length));this.shared.dropped+=o.length-i.length,this.queue=[...i,...this.queue];return}this.shared.dropped+=o.length;}},pt=null,y={actor:void 0,attributes:{},attributesSet:false,dropped:0},W=()=>pt,Ee=e=>{pt=e;};var X=e=>{try{e();}catch{y.dropped+=1;}},Ts={init(e){X(()=>{if(W()||!(e!=null&&e.token)||!e.applicationId||!e.apiUrl&&!e.proxyUrl||typeof window=="undefined"||typeof window.fetch!="function")return;let t=new re(e,y);Ee(t),t.start();});},setActor(e){X(()=>{var n;let t=ye(e);if(t===void 0){y.dropped+=1;return}y.actor=t,(n=W())==null||n.markDirty();});},setAttributes(e){X(()=>{var t;y.attributes=ve(y.attributes,e,()=>{y.dropped+=1;}),y.attributesSet=!0,(t=W())==null||t.markDirty();});},captureError(e,t){X(()=>{var n;return (n=W())==null?void 0:n.captureError(e,t)});},stop(){X(()=>{var e;(e=W())==null||e.stop(),Ee(null),y.actor=void 0,y.attributes={},y.attributesSet=!1,y.dropped=0;});}};
2
+ export{Ts as AbyssRum};
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@abyss-project/monitor-browser",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Browser SDK of Abyss-Monitor: real user monitoring (sessions, page views, requests, errors)",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.mts",
12
+ "default": "./dist/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "sideEffects": false,
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "keywords": [],
29
+ "author": "scylla",
30
+ "license": "ISC",
31
+ "bugs": {
32
+ "url": "https://gitlab.com/abyss-group/abyss-monitor/abyss-monitor"
33
+ },
34
+ "homepage": "https://gitlab.com/abyss-group/abyss-monitor/abyss-monitor",
35
+ "dependencies": {
36
+ "@abyss-project/monitor": "10.1.0"
37
+ },
38
+ "devDependencies": {
39
+ "@typescript-eslint/eslint-plugin": "8.71.0",
40
+ "@typescript-eslint/parser": "8.71.0",
41
+ "eslint": "^8.57.1",
42
+ "eslint-config-prettier": "^8.3.0",
43
+ "eslint-plugin-filenames-simple": "^0.7.0",
44
+ "eslint-plugin-prettier": "^3.4.0",
45
+ "jsdom": "^25.0.1",
46
+ "prettier": "2.3.1",
47
+ "tsup": "^8.3.5",
48
+ "typescript": "5.9.3",
49
+ "vitest": "^2.1.9"
50
+ },
51
+ "scripts": {
52
+ "build": "tsup",
53
+ "tsc": "tsc --noEmit",
54
+ "lint": "eslint \"src/**/*.ts\" --fix",
55
+ "lint:check": "eslint \"src/**/*.ts\" --max-warnings 0",
56
+ "test": "vitest run && tsup && node scripts/check-bundle.mjs",
57
+ "test:watch": "vitest",
58
+ "check-bundle": "node scripts/check-bundle.mjs"
59
+ }
6
60
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.