Skip to content

The only tool you need to know what is happening and how to fix it.

2.0 KB
Raw Blame
import{j as g,k as c,g as o,l as i,u as z,aq as f,b as l}from"./BKFspo1J.js";import{g as m}from"./BHvJp7nu.js";const r="traceway_nav_depth";function s(){try{return parseInt(sessionStorage.getItem(r)||"0",10)}catch{return 0}}function h(e){try{sessionStorage.setItem(r,String(e))}catch{}}function k(){h(s()+1)}function _(){h(Math.max(0,s()-1))}function S(){try{sessionStorage.removeItem(r)}catch{}}function d(){return s()>0}function A(e){const{fallbackPath:t}=e;return n=>{if(n.ctrlKey||n.metaKey){window.open(t,"_blank");return}d()?history.back():m(t)}}function O(){const e=localStorage.getItem("AUTH_TOKEN");if(!e)return null;try{const{exp:t}=JSON.parse(atob(e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")));return t*1e3<=Date.now()?null:e}catch{return e}}class p{#t=g(c(O()));get token(){return o(this.#t)}set token(t){i(this.#t,t,!0)}#e=g(c(JSON.parse(localStorage.getItem("USER_ORGANIZATIONS")||"[]")));get organizations(){return o(this.#e)}set organizations(t){i(this.#e,t,!0)}#n=z(()=>!!this.token);get isAuthenticated(){return o(this.#n)}set isAuthenticated(t){i(this.#n,t)}constructor(){f(()=>{l(()=>{this.token?localStorage.setItem("AUTH_TOKEN",this.token):localStorage.removeItem("AUTH_TOKEN")}),l(()=>{this.organizations.length>0?localStorage.setItem("USER_ORGANIZATIONS",JSON.stringify(this.organizations)):localStorage.removeItem("USER_ORGANIZATIONS")})})}setToken(t){this.token=t}setOrganizations(t){this.organizations=t}getRoleForOrganization(t){return this.organizations.find(a=>a.id===t)?.role||null}canManageOrganization(t){const n=this.getRoleForOrganization(t);return n==="owner"||n==="admin"}canWriteOrganization(t){return this.getRoleForOrganization(t)!=="readonly"}getTimezoneForOrganization(t){return this.organizations.find(a=>a.id===t)?.timezone||null}updateOrganizationTimezone(t,n){const a=this.organizations.find(u=>u.id===t);a&&(a.timezone=n,this.organizations=[...this.organizations])}logout(){this.token=null,this.organizations=[],S()}}const T=new p;export{T as a,S as b,A as c,_ as d,k as i};