1import{i as d,ar as w,U as M,a6 as y,as as v,D as I,S as a,p as m,q as f,at as p,au as D,av as x,aw as O,ax as g,ay as k,w as l,s as c,m as A,l as E,x as T,az as F,aA as _,d as u,ao as N,aB as S,aC as P}from"./root-HIFWb3i6.js";import{T as b}from"./timer--QM2LZfv.js";import"./chunk-EPOLDU6W-Cy0pbNoL.js";import"./jsx-runtime-u17CrQMm.js";import"./index-e26oBipY.js";import"./index-hDuMSH-s.js";import"./mutation-BhTIUPuz.js";import"./QueryClientProvider-CC4TKqza.js";import"./main-BIrbTr-V.js";import"./status-announcer-provider-twgJHQuP.js";import"./i18nInstance-CHFDjdcJ.js";import"./constant-DgzOUPqJ.js";import"./Info.es-qYAWktLB.js";import"./data-layer-1kvIXlWL.js";import"./sbs-login-instance-QtxHg8-X.js";import"./user-provider-BVDzkoqu.js";import"./preload-helper-BXl3LOEh.js";import"./helpers-Dqt3x3rr.js";class j extends b{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(d&&e.ee){if(e.ee){this.ee=e.ee;const s=w(this.refresh.bind(this),500,{leading:!0});this.refreshHandler=n=>{e.refreshEvents.includes(n?.[0]?.type)&&s()},e.ee.on("fn-end",this.refreshHandler)}M(s=>{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{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:p.OFF,sessionReplaySentFirstChunk:!1,sessionTraceMode:p.OFF,traceHarvestStarted:!1,loggingMode:f.OFF,logApiMode:f.OFF,serverTimeDiff:null,custom:{},numOfResets:0,consent:!1};class C{constructor(e){const{agentIdentifier:t,key:s,storage:n}=e;if(!t||!s||!n)throw new Error("Missing required field(s):".concat(t?"":" agentID").concat(s?"":" key").concat(n?"":" storage"));this.agentIdentifier=t,this.storage=n,this.state={},this.key=s,this.ee=y.get(t),v(this.ee),this.setup(e),d&&I("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,[m.CROSS_TAB,this.state])}})}setup({value:e=D(16),expiresMs:t=x,inactiveMs:s=O,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 b({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(g(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(g(this.state,h),!0):this.sync(o),this.initialized=!0,this.ee.emit(a.STARTED,[this.isNew])}get lookupKey(){return"".concat(k,"_").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 l(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 l(11,t),null}}reset(){try{return l(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({agentIdentifier:this.agentIdentifier,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&&A(T,[i,n],void 0,E.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(d)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 R{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 U(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 ie(r){if(r.runtime.session)return r.runtime.session;const e=r.init.session;r.runtime.session=new C({agentIdentifier:r.agentIdentifier,key:F,storage:new R,expiresMs:e?.expiresMs,inactiveMs:e?.inactiveMs});const t=r.runtime.session.state.custom;t&&Object.keys(t).length&&(r.info=_({...r.info,jsAttributes:{...t,...r.info.jsAttributes}})),r.runtime.jsAttributesMetadata=U(r.info,"jsAttributes");const s=y.get(r.agentIdentifier);return u("api-setCustomAttribute",(n,i,o)=>{r.runtime.session.syncCustomAttribute(i,o)},"session",s),u("api-setUserId",(n,i,o)=>{r.runtime.session.syncCustomAttribute(i,o)},"session",s),u("api-setUserIdAndResetSession",n=>{r.runtime.session.reset(),A(T,["API/"+S+"/resetSession/called"],void 0,E.metrics,s),P(r,"enduser.id",n,S,!0)},"session",s),u("api-consent",n=>{r.runtime.session.write({consent:n===void 0?!0:n})},"session",s),N(r.agentIdentifier,"session"),r.runtime.session}export{ie 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.