1import{C as p,s as r,a as i,d as a,u as h}from"./site.B0Uxz9u8.js";import{L as m}from"./LocalStorageCache.s6TLHOVx.js";import{f as k}from"./fetchData.E2TeMMfN.js";import{c as L}from"./cart.BfET_Op9.js";import{u as S}from"./createStore.Dm90ZrIA.js";import{g as y,b as T}from"./cache.Br0MEeF2.js";import{b as f}from"./checks.gB2AzUu8.js";import"./password-strength.AqUmoxgQ.js";const b=6e4,O=15e3,v=12e4,u="tessituraSync",d="tessituraLastResponse";class V{constructor(t){this.config=t,this.fetchFn=t.fetchFn??fetch.bind(window),this.cache=new m,this.syncTTL=this.clampSyncTtl(t.defaultTTL??b)}async synchronize(t=!1,e=!1){if(!t&&!this.shouldSync())return this.getLastResponse();try{const s=this.config.apiBase.replace(/\/+$/g,""),n=await this.fetchFn(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e?{forceSync:!0}:{})});if(!n.ok)return n.status===403?{success:!1}:null;const o=await n.json();return this.cacheResponse(o),this.markSync(),typeof o.ttl=="number"&&o.ttl>0&&(this.syncTTL=this.clampSyncTtl(o.ttl*1e3)),o}catch{return null}}getLastResponse(){const t=this.cache.get(d);return(t==null?void 0:t.data)??null}getSyncTTL(){return this.syncTTL}async logout(){try{const t=this.config.apiBase.replace(/\/+$/g,"");await this.fetchFn(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"logout"})})}catch{}}clearCache(){this.cache.remove(u),this.cache.remove(d)}shouldSync(){const t=this.cache.get(u);return t?Date.now()-t.timestamp>=this.syncTTL:!0}markSync(){this.cache.set(u,{data:{},timestamp:Date.now()})}cacheResponse(t){this.cache.set(d,{data:t,timestamp:Date.now()})}clampSyncTtl(t){return Math.min(v,Math.max(O,t))}}const w=l=>new V(l),g=async(l,t)=>{const e=`${l}?returnUrl=${encodeURIComponent(t)}`,s=await k(e,"GET");if(s.ok!==!0)return null;const{data:n}=s;return n.success!==!0||n.url===void 0||n.url===""?null:n.url},E=15e3,I=12e4,c=class c extends p{constructor(){super(...arguments),this.timer=null,this.clickHandlerTarget=null,this.isHandlingClick=!1}connect(){S(this);const t=y(Date.now(),this.sessionSyncFrequencyMs);typeof t=="number"&&this.setCartCountValue(t),this.client=w({apiBase:this.endpointValue,defaultTTL:this.intervalValue}),this.attachClickHandler(),this.boundOnLogin=e=>{this.onLoginClick(e.fallbackHref)},this.boundOnLinkClick=e=>{this.handleLinkClick(e.href)},this.boundAttemptLogout=this.attemptLogout.bind(this),r(i.SSOLogout,this.boundAttemptLogout),r(i.SSOLoginClick,this.boundOnLogin),r(i.SSOLinkClick,this.boundOnLinkClick),this.hasCookieValue&&this.isLoggedInValue&&this.isEnabledValue&&(this.tick(!0),this.adjustInterval(this.intervalValue)),this.isLoggedInValue&&!this.hasCookieValue&&this.attemptLogout()}async onLoginClick(t){if(this.isEnabledValue===!1||this.isLoggedInValue===!1){f(t)||this.redirectTo(t);return}a(i.SSOCheckStarted,{loggedIn:this.isLoggedInValue});const e=await this.client.synchronize(!0);if((e==null?void 0:e.success)===!0&&e.authed===!0){a(i.SSODone),this.refreshPage();return}a(i.SSODone),f(t)||(this.client.clearCache(),this.redirectTo(t))}get sessionSyncFrequencyMs(){return this.intervalValue*1e3}async tick(t=!1){a(i.SSOCheckStarted,{loggedIn:this.isLoggedInValue});const e=await this.client.synchronize(!1,t);e!==null?this.handleResponse(e):a(i.SSODone)}handleResponse(t){if(t.success===!1||t.action==="logout"){this.stopPolling(),this.client.clearCache(),a(i.SSOLogout);return}typeof t.ttl=="number"&&t.ttl>0&&this.adjustInterval(t.ttl*1e3),typeof t.cartCount=="number"&&(T(t.cartCount),this.setCartCountValue(t.cartCount)),a(i.SSODone)}adjustInterval(t){const e=Math.min(I,Math.max(E,t));this.timer!==null&&clearInterval(this.timer),this.timer=setInterval(()=>void this.tick(),e)}stopPolling(){this.timer!==null&&(clearInterval(this.timer),this.timer=null)}async attemptLogout(){this.stopPolling(),this.client.clearCache(),await this.client.logout(),a(i.SSOLogoutDone)}async handleLinkClick(t){if(!this.isEnabledValue||!this.isLoggedInValue||!this.hasCookieValue){this.redirectTo(t);return}if(!this.isHandlingClick){this.isHandlingClick=!0;try{const e=await g(this.linkEndpointValue,t);this.redirectTo(e??t)}finally{this.isHandlingClick=!1}}}attachClickHandler(){this.isEnabledValue!==!1&&(this.clickHandlerTarget=document.body,this.boundOnClick=t=>{const e=t.target.closest("a[href]");if(!e)return;const s=e.getAttribute("href")??"";this.isTnewLink(s)&&(!this.isLoggedInValue||!this.hasCookieValue||(t.preventDefault(),!this.isHandlingClick&&(this.isHandlingClick=!0,g(this.linkEndpointValue,s).then(n=>{this.redirectTo(n??s)}).finally(()=>{this.isHandlingClick=!1}))))},this.clickHandlerTarget.addEventListener("click",this.boundOnClick,{capture:!0}))}isTnewLink(t){if(this.tnewHostValue===""||t==="")return!1;try{return new URL(t,window.location.href).hostname===this.tnewHostValue}catch{return!1}}detachClickHandler(){!this.clickHandlerTarget||!this.boundOnClick||(this.clickHandlerTarget.removeEventListener("click",this.boundOnClick,{capture:!0}),this.clickHandlerTarget=null,this.boundOnClick=void 0)}disconnect(){this.stopPolling(),this.boundOnLogin&&h(i.SSOLoginClick,this.boundOnLogin),this.boundOnLinkClick&&h(i.SSOLinkClick,this.boundOnLinkClick),this.boundAttemptLogout&&h(i.SSOLogout,this.boundAttemptLogout),this.detachClickHandler()}redirectTo(t){window.location.href=t}refreshPage(){window.location.reload()}};c.stores=[L],c.values={endpoint:{type:String,default:"/my/sso"},interval:{type:Number,default:120},isLoggedIn:{type:Boolean,default:!1},hasCookie:{type:Boolean,default:!1},isEnabled:{type:Boolean,default:!1},tnewHost:{type:String,default:""},linkEndpoint:{type:String,default:"/sso/link"}};let C=c;export{C as default}; 2//# sourceMappingURL=tnew_sso_controller.Cs-7KLnJ.js.map
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.