1import{t as m,aa as T,u as w,a8 as b,c as a,aE as f,aF as v,aG as M,aH as S,a1 as D,Y as x,w as d,z as c,h as y,F as A,aj as g,aI as I,ay as u,aD as O,g as p,e as k}from"./D51U_mVh.js";import{T as E}from"./-QM2LZfv.js";import{w as R,g as _}from"./DhS5Pgpw.js";import"./DDPjZhl-.js";import"./Be_Bl_Aq.js";class j extends E{constructor(e,t){super(e,t),this.onPause=typeof e.onPause=="function"?e.onPause:()=>{},this.onRefresh=typeof e.onRefresh=="function"?e.onRefresh:()=>{},this.onResume=typeof e.onResume=="function"?e.onResume:()=>{},this.readStorage=e.readStorage,this.remainingMs=void 0,e.refreshEvents||(e.refreshEvents=["click","keydown","scroll"]);try{this.abortController=new AbortController}catch{}if(m&&e.ee){if(e.ee){this.ee=e.ee;const s=T(this.refresh.bind(this),500,{leading:!0});this.refreshHandler=n=>{e.refreshEvents.includes(n?.[0]?.type)&&s()},e.ee.on("fn-end",this.refreshHandler)}w(s=>{s==="hidden"?this.pause():this.resume()},!1,this.abortController?.signal)}}abort(){this.clear(),this.abortController?.abort(),this.refreshHandler&&(this.ee.removeEventListener("fn-end",this.refreshHandler),this.refreshHandler=this.ee=null)}pause(){this.onPause(),clearTimeout(this.timer),this.remainingMs=this.initialMs-(Date.now()-this.startTimestamp)}resume(){try{const t=this.readStorage(),s=typeof t=="string"?JSON.parse(t):t;e(s.expiresAt)||e(s.inactiveAt)?this.end():(this.refresh(),this.onResume())}catch{this.end()}function e(t){return Date.now()>t}}refresh(e,t){this.clear(),this.timer=this.create(e,t),this.startTimestamp=Date.now(),this.remainingMs=void 0,this.onRefresh()}}const h={value:"",inactiveAt:0,expiresAt:0,updatedAt:Date.now(),sessionReplayMode:null,sessionReplaySentFirstChunk:!1,sessionTraceMode:null,traceHarvestStarted:!1,loggingMode:null,logApiMode:null,serverTimeDiff:null,custom:{},numOfResets:0,consent:!1,cachedRumResponse:null};class N{constructor(e){const{agentRef:t,key:s,storage:n}=e;if(!t||!s||!n)throw new Error("Missing required field(s):".concat(t?"":" agentRef").concat(s?"":" key").concat(n?"":" storage"));this.agentRef=t,this.storage=n,this.state={},this.key=s,this.ee=t.ee,R(this.ee,t),this.setup(e),m&&b("storage",i=>{if(i.key===this.lookupKey){const o=typeof i.newValue=="string"?JSON.parse(i.newValue):i.newValue;this.sync(o),this.ee.emit(a.UPDATE,[f.CROSS_TAB,this.state])}})}setup({value:e=D(16),expiresMs:t=v,inactiveMs:s=M,numOfResets:n=0}){const i={serverTimeDiff:this.state.serverTimeDiff||h.serverTimeDiff,consent:this.state.consent||h.consent};this.state={},this.sync({...h,...i}),this.state.value=e,this.expiresMs=t,this.inactiveMs=s;const o=this.read();t?(this.state.expiresAt=o?.expiresAt||this.getFutureTimestamp(t),this.state.numOfResets=o?.numOfResets||n,this.expiresTimer=new E({onEnd:()=>{this.collectSM("expired"),this.collectSM("duration"),this.reset()}},this.state.expiresAt-Date.now())):this.state.expiresAt=1/0,s?(this.state.inactiveAt=o?.inactiveAt||this.getFutureTimestamp(s),this.inactiveTimer=new j({onEnd:()=>{this.collectSM("inactive"),this.collectSM("duration"),this.reset()},onRefresh:this.refresh.bind(this),onResume:()=>{this.ee.emit(a.RESUME)},onPause:()=>{this.initialized&&this.ee.emit(a.PAUSE),this.write(S(this.state,h))},ee:this.ee,refreshEvents:["click","keydown","scroll"],readStorage:()=>this.storage.get(this.lookupKey)},this.state.inactiveAt-Date.now())):this.state.inactiveAt=1/0,this.isNew||=!Object.keys(o).length,this.isNew?this.write(S(this.state,h),!0):this.sync(o),this.initialized=!0,this.ee.emit(a.STARTED,[this.isNew])}get lookupKey(){return"".concat(x).concat(this.key)}sync(e){Object.assign(this.state,e)}read(){try{const e=this.storage.get(this.lookupKey);if(!e)return{};const t=typeof e=="string"?JSON.parse(e):e;return this.isInvalid(t)?{}:this.isExpired(t.expiresAt)?(this.collectSM("expired"),this.collectSM("duration",t,!0),this.reset()):this.isExpired(t.inactiveAt)?(this.collectSM("inactive"),this.collectSM("duration",t,!0),this.reset()):t}catch(e){return d(10,e),{}}}write(e){try{return!e||typeof e!="object"?void 0:(e.updatedAt=Date.now(),this.sync(e),this.storage.set(this.lookupKey,c(this.state)),this.ee.emit(a.UPDATE,[f.SAME_TAB,this.state]),e)}catch(t){return d(11,t),null}}reset(){try{return d(66),this.initialized&&(this.ee.emit(a.RESET),this.state.numOfResets++),this.storage.remove(this.lookupKey),this.inactiveTimer?.abort?.(),this.expiresTimer?.clear?.(),delete this.isNew,this.setup({key:this.key,storage:this.storage,expiresMs:this.expiresMs,inactiveMs:this.inactiveMs,numOfResets:this.state.numOfResets}),this.read()}catch{return{}}}refresh(){const e=this.read();this.write({...e,inactiveAt:this.getFutureTimestamp(this.inactiveMs)})}isExpired(e){return Date.now()>e}isInvalid(e){return!Object.keys(h).every(s=>Object.keys(e).includes(s))}collectSM(e,t,s){let n,i;e==="duration"&&(n=this.getDuration(t,s),i="Session/Duration/Ms"),e==="expired"&&(i="Session/Expired/Seen"),e==="inactive"&&(i="Session/Inactive/Seen"),i&&y(g,[i,n],void 0,A.metrics,this.ee)}getDuration(e=this.state,t){const s=e.expiresAt-this.expiresMs;return(t?Date.now():e.updatedAt)-s}getFutureTimestamp(e){return Date.now()+e}
1syncCustomAttribute(e,t){if(m)if(t===null){const s=this.read();s.custom&&(delete s.custom[e],this.write({...s}))}else{const s=this.read();this.custom={...s?.custom||{},[e]:t},this.write({...s,custom:this.custom})}}}class P{get(e){try{return localStorage.getItem(e)||void 0}catch{return""}}set(e,t){try{return t==null?this.remove(e):localStorage.setItem(e,t)}catch{}}remove(e){try{localStorage.removeItem(e)}catch{}}}function C(r,e){const t=r[e]??={},s={bytes:Object.keys(t).reduce((n,i)=>n+i.length+c(t[i]).length,0)};return r[e]=new Proxy(t,{set(n,i,o){return s.bytes+=i.length+c(o).length,n[i]=o,!0},deleteProperty(n,i){return s.bytes-=i.length+c(n[i]).length,delete n[i]}}),s}function V(r){if(r.runtime.session)return r.runtime.session;const e=r.init.session,t=_(r.info.licenseKey,r.info.applicationID);r.runtime.session=new N({agentRef:r,key:t,storage:new P,expiresMs:e?.expiresMs,inactiveMs:e?.inactiveMs});const s=r.runtime.session.state.custom;s&&Object.keys(s).length&&(r.info=I({...r.info,jsAttributes:{...s,...r.info.jsAttributes}})),r.runtime.jsAttributesMetadata=C(r.info,"jsAttributes");const n=r.ee;return u("api-setCustomAttribute",(i,o,l)=>{r.runtime.session.syncCustomAttribute(o,l)},"session",n),u("api-setUserId",(i,o,l)=>{r.runtime.session.syncCustomAttribute(o,l)},"session",n),u("api-setUserIdAndResetSession",i=>{r.runtime.session.reset(),y(g,["API/"+p+"/resetSession/called"],void 0,A.metrics,n),k(r,"enduser.id",i,p,!0)},"session",n),u("api-consent",i=>{r.runtime.session.write({consent:i===void 0?!0:i})},"session",n),O(r,"session"),r.runtime.session}export{V as setupAgentSession};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.