1import{c as u}from"./chunk-SMUEECAA.js";import{$ as g,A as w,Y as d,aa as k,ba as c,h as m,l as f}from"./chunk-UKF3GMO7.js";var T=new g("JWT_OPTIONS"),b=(()=>{class s{constructor(e=null){this.tokenGetter=e&&e.tokenGetter||function(){}}urlBase64Decode(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:{t+="==";break}case 3:{t+="=";break}default:throw new Error("Illegal base64url string!")}return this.b64DecodeUnicode(t)}b64decode(e){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",r="";if(e=String(e).replace(/=+$/,""),e.length%4===1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(let i=0,n,a,v=0;a=e.charAt(v++);~a&&(n=i%4?n*64+a:a,i++%4)?r+=String.fromCharCode(255&n>>(-2*i&6)):0)a=t.indexOf(a);return r}b64DecodeUnicode(e){return decodeURIComponent(Array.prototype.map.call(this.b64decode(e),t=>"%"+("00"+t.charCodeAt(0).toString(16)).slice(-2)).join(""))}decodeToken(e=this.tokenGetter()){return e instanceof Promise?e.then(t=>this._decodeToken(t)):this._decodeToken(e)}_decodeToken(e){if(!e||e==="")return null;let t=e.split(".");if(t.length!==3)throw new Error("The inspected token doesn't appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.");let r=this.urlBase64Decode(t[1]);if(!r)throw new Error("Cannot decode the token.");return JSON.parse(r)}getTokenExpirationDate(e=this.tokenGetter()){return e instanceof Promise?e.then(t=>this._getTokenExpirationDate(t)):this._getTokenExpirationDate(e)}_getTokenExpirationDate(e){let t;if(t=this.decodeToken(e),!t||!t.hasOwnProperty("exp"))return null;let r=new Date(0);return r.setUTCSeconds(t.exp),r}isTokenExpired(e=this.tokenGetter(),t){return e instanceof Promise?e.then(r=>this._isTokenExpired(r,t)):this._isTokenExpired(e,t)}_isTokenExpired(e,t){if(!e||e==="")return!0;let r=this.getTokenExpirationDate(e);return t=t||0,r===null?!1:!(r.valueOf()>new Date().valueOf()+t*1e3)}getAuthScheme(e,t){return typeof e=="function"?e(t):e}}return s.\u0275fac=function(e){return new(e||s)(k(T))},s.\u0275prov=d({token:s,factory:s.\u0275fac}),s})();var h=class{},l=class{constructor(o){this.username="",this.token="",this.permissions=new h,this.logged=o}},p=(()=>{class s{get securityDetails(){return this.detailsSubject.asObservable()}get token(){return this.details.token}get logged(){return this.details.logged}constructor(){this.router=c(u),this.detailsKey="securityDetails",this.detailsSubject=new m(1),this.jwtHelper=new b,this.details=new l(!1),this.detailsSubject.subscribe(e=>this.details=e),this.loadDetails(),this.checkTokenExpiration()}logout(){this.detailsSubject.next(new l(!1)),localStorage.removeItem(this.detailsKey),this.router.navigate(["/"])}setDetails(e,t,r){let i=new l(e);if(t){i.token=t;let n=this.jwtHelper.decodeToken(t);n&&(i.username=n.sub||"",i.permissions=new h,n.permissions&&typeof n.permissions=="object"&&Object.assign(i.permissions,n.permissions))}return this.detailsSubject.next(i),r?localStorage.setItem(this.detailsKey,JSON.stringify(i)):localStorage.removeItem(this.detailsKey),i}hasPermission(e){return this.containsPermission(this.details,e.resource,e.action)}hasAnyPermission(e){return e.some(t=>this.containsPermission(this.details,t.resource,t.action))}loadDetails(){let e=localStorage.getItem(this.detailsKey);if(e)try{let t=JSON.parse(e),r=new l(t.logged);r.token=t.token||"",r.username=t.username||"",r.permissions=new h,t.permissions&&typeof t.permissions=="object"&&Object.assign(r.permissions,t.permissions),this.detailsSubject.next(r)}catch{this.detailsSubject.next(new l(!1))}else this.detailsSubject.next(new l(!1))}checkTokenExpiration(){this.token&&this.jwtHelper.isTokenExpired(this.token)&&this.logout()}containsPermission(e,t,r){return e.permissions[t]?.includes(r)??!1}static{this.\u0275fac=function(t){return new(t||s)}}static{this.\u0275prov=d({token:s,factory:s.\u0275fac,providedIn:"root"})}}return s})(),K=(s,o)=>{let e=c(u),t=c(p),r="/login",i;if(t.logged||o.url===r)i=!0;else{let n={queryParams:o.url!==r?{returnUrl:o.url}:{}};i=e.createUrlTree([r],n)}return i},$=(s,o)=>{let e=c(p),t=c(u),r="/",i;return o.url===r?i=!0:e.logged?i=t.createUrlTree([r]):i=!0,i},B=s=>
1()=>{let o=c(u),e=c(p),t="/",r;return e.hasPermission(s)?r=!0:r=o.createUrlTree([t]),r},x="Authorization",S="Bearer",F=s=>(o,e)=>{let t=c(p),r;if(o.url.startsWith(s)){let n=t.logged,a=t.token;n&&a?r=o.clone({headers:o.headers.set(x,`${S} ${a}`)}):r=o}else r=o;return e(r)},L=s=>(o,e)=>e(o).pipe(w(t=>o.url.startsWith(s)?(t.status,f(()=>t)):f(()=>t)));var D=class{constructor(o="",e=[]){this.name=o,this.permissions=e}};var j=class{constructor(){this.username="",this.name="",this.email="",this.enabled=!1,this.notExpired=!0,this.passwordNotExpired=!0,this.notLocked=!0,this.roles=[]}},y=class{constructor(){this.creationDate=new Date,this.expirationDate=new Date,this.scope="",this.token="",this.name="",this.username="",this.consumed=!1,this.revoked=!1}};export{p as a,K as b,$ as c,B as d,F as e,L as f,D as g,j as h,y as i};
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.