1import{a as y}from"./chunk-M2XJ75SP.js";import{c as R,f as j}from"./chunk-CGO6PRPN.js";import{b as x}from"./chunk-MCQL2SVU.js";import"./chunk-HE4QFQES.js";import{a as N}from"./chunk-IIET3LBA.js";import{A as D,D as _,F,H as P,s as b,y as w}from"./chunk-GAMMKM7I.js";import{F as I,G as k,H as a,I as M,J as v,P as S,T as A,V as l,W as c,b as f,m as O,q as d,w as p}from"./chunk-C2FQB64K.js";import{a as h,b as u}from"./chunk-6F4HVVOU.js";var E=class extends y{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(f&&e.ee){if(e.ee){this.ee=e.ee;let s=N(this.refresh.bind(this),500,{leading:!0});this.refreshHandler=n=>{e.refreshEvents.includes(n?.[0]?.type)&&s()},e.ee.on("fn-end",this.refreshHandler)}P(s=>
1{s==="hidden"?this.pause():this.resume()},!1,!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{let 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()}};var m={value:"",inactiveAt:0,expiresAt:0,updatedAt:Date.now(),sessionReplayMode:v.OFF,sessionReplaySentFirstChunk:!1,sessionTraceMode:v.OFF,traceHarvestStarted:!1,loggingMode:x.OFF,logApiMode:x.OFF,serverTimeDiff:null,custom:{},numOfResets:0,consent:!1},g=class{constructor(e){let{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,j(this.ee),this.setup(e),f&&F("storage",i=>{if(i.key===this.lookupKey){let o=typeof i.newValue=="string"?JSON.parse(i.newValue):i.newValue;this.sync(o),this.ee.emit(a.UPDATE,[M.CROSS_TAB,this.state])}})}setup({value:e=O(16),expiresMs:t=144e5,inactiveMs:s=18e5,numOfResets:n=0}){let i={serverTimeDiff:this.state.serverTimeDiff||m.serverTimeDiff,consent:this.state.consent||m.consent};this.state={},this.sync(h(h({},m),i)),this.state.value=e,this.expiresMs=t,this.inactiveMs=s;let o=this.read();t?(this.state.expiresAt=o?.expiresAt||this.getFutureTimestamp(t),this.state.numOfResets=o?.numOfResets||n,this.expiresTimer=new y({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 E({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(w(this.state,m))},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(w(this.state,m),!0):this.sync(o),this.initialized=!0,this.ee.emit(a.STARTED,[this.isNew])}get lookupKey(){return"".concat(I,"_").concat(this.key)}sync(e){Object.assign(this.state,e)}read(){try{let e=this.storage.get(this.lookupKey);if(!e)return{};let 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,[M.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({agentRef:this.agentRef,key:this.key,storage:this.storage,expiresMs:this.expiresMs,inactiveMs:this.inactiveMs,numOfResets:this.state.numOfResets}),this.read()}catch{return{}}}refresh(){let e=this.read();this.write(u(h({},e),{inactiveAt:this.getFutureTimestamp(this.inactiveMs)}))}isExpired(e){return Date.now()>e}isInvalid(e){return!Object.keys(m).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&&S(A,[i,n],void 0,p.metrics,this.ee)}getDuration(e=this.state,t){let s=e.expiresAt-this.expiresMs;return(t?Date.now():e.updatedAt)-s}getFutureTimestamp(e){return Date.now()+e}
1syncCustomAttribute(e,t){if(f)if(t===null){let s=this.read();s.custom&&(delete s.custom[e],this.write(h({},s)))}else{let s=this.read();this.custom=u(h({},s?.custom||{}),{[e]:t}),this.write(u(h({},s),{custom:this.custom}))}}};var T=class{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){let 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 be(r){if(r.runtime.session)return r.runtime.session;let e=r.init.session;r.runtime.session=new g({agentRef:r,key:k,storage:new T,expiresMs:e?.expiresMs,inactiveMs:e?.inactiveMs});let t=r.runtime.session.state.custom;t&&Object.keys(t).length&&(r.info=D(u(h({},r.info),{jsAttributes:h(h({},t),r.info.jsAttributes)}))),r.runtime.jsAttributesMetadata=C(r.info,"jsAttributes");let s=r.ee;return l("api-setCustomAttribute",(n,i,o)=>{r.runtime.session.syncCustomAttribute(i,o)},"session",s),l("api-setUserId",(n,i,o)=>{r.runtime.session.syncCustomAttribute(i,o)},"session",s),l("api-setUserIdAndResetSession",n=>{r.runtime.session.reset(),S(A,["API/"+b+"/resetSession/called"],void 0,p.metrics,s),R(r,"enduser.id",n,b,!0)},"session",s),l("api-consent",n=>{r.runtime.session.write({consent:n===void 0?!0:n})},"session",s),_(r,"session"),r.runtime.session}export{be 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.