1import{r as g,t as b}from"./chunk-HqyZykBt.js";import{B as Hu,Fi as wn,Mn as ay,Ni as we,Or as ld,Q as Je,Vn as di,Xn as fr,gn as Ye,j as Fs,ki as w,kr as le,mn as Y,mr as iy,nt as Ju,or as he,pn as Xu,rt as K,tr as gn,u as Bu,ur as hy,xr as ju,z as Hs,zn as cd}from"./chunk-CbatPwMz.js";import{u as Xe}from"./chunk-BJqFN5gC.js";import{B as be,G as jh,J as oi,R as Zh,Y as pe,g as Jh,j as Tn,x as Me}from"./chunk-Db587L4_.js";import{a as q$1,i as W,o as z}from"./chunk-CLinj7k3.js";import{t as D}from"./chunk-CGio_-pY.js";import{t as a}from"./chunk-ZmH8-ug0.js";import{n as r}from"./chunk-DUYi7Rbe2.js";import{l as W$1}from"./chunk-CrlcDeEH2.js";var q=(()=>{class i{#e=Ye(null);currentContext=this.#e.asReadonly();currentContext$=W(this.currentContext);parsedContext=he(()=>{let e=this.currentContext();if(!e)return;let t=e.split(`_`),s=t.pop();return{entity:t.join(`_`),identifier:s}});parsedContext$=W(this.parsedContext).pipe(jh());setNewContext(e){this.#e.set(e)}removeContext(){this.#e.set(null)}static ɵfac=function(t){return new(t||i)};static ɵprov=gn({token:i,factory:i.ɵfac})}return i})();var Q=Symbol(`User permissions currently loading`);var h=Symbol(`User permissions not yet loaded or loading`);var X=2e3;var Z=100;function ee({matchAll:i,requiredPermissions:b,userPermissions:e}){if(!b.length)return!0;let t=new Set(e);return b[i?`every`:`some`](s=>t.has(s))}var ie=(()=>{class i{actionIdGenerator=w(r);baseUrlPath=w(D);contextService=w(q);destroyRef=w(we);httpClient=w(Tn);location=w(Xe);router=w(pe);permissionsApiBasePath=`${this.baseUrlPath.replace(/\/+$/,``)}/identity/v1/Profile/Permissions`;latestPermissionsSubject=new fr(h);#e=Ye([]);permissionCheckResults=this.#e.asReadonly();permissionCheckResults$=W(this.permissionCheckResults);permissionCheckResultsBuffer=[];#t=Ye(void 0);logEnabled=this.#t.asReadonly();context$=this.contextService.parsedContext$.pipe(le(e=>{if(e)return{dataContextKey:e.identifier,dataContextType:e.entity}}),jh());routePath$=this.router.events.pipe(wn(e=>e instanceof Me),le(({url:e})=>e),cd(this.location.path()),le(e=>W$1(e)),ju());
1fetchUserPermissionsActionSubject=new K;fetchUserPermissions$=this.fetchUserPermissionsActionSubject.pipe(Xu(Z),Hu(e=>{let t=!1,s=this.latestPermissionsSubject.pipe(wn(n=>n===h),Jh(),Bu(()=>t=!0));return this.fetchUserPermissionsFromServer(e).pipe(ld(s),Zh(n=>{t||this.setLatestPermissions(n)}))}),q$1(this.destroyRef));checkUserPermissionsActionSubject=new K;loadPendingUserPermissions$=iy({context:this.createCacheInvalidationLogic(this.context$),routePath:this.createCacheInvalidationLogic(this.routePath$),checkUserPermissionsAction:this.checkUserPermissionsActionSubject}).pipe(wn(()=>this.latestPermissionsSubject.value===h),Bu(({context:e})=>{this.latestPermissionsSubject.value===h&&(this.setLatestPermissions(Q),this.fetchUserPermissionsActionSubject.next(e))}),q$1(this.destroyRef));invalidateBackendPermissionCacheSubject=new K;invalidateBackendPermissionCache$=this.invalidateBackendPermissionCacheSubject.pipe(Ju(()=>this.httpClient.post(`${this.permissionsApiBasePath}/ClearCache`,{}).pipe(Hs(e=>(e instanceof be||console.error(e),Je)))),q$1(this.destroyRef));constructor(){hy(this.fetchUserPermissions$,this.invalidateBackendPermissionCache$,this.loadPendingUserPermissions$).subscribe()}setLogEnabled(e){this.#t.set(e),e&&this.#e.set([...this.permissionCheckResultsBuffer]),this.permissionCheckResultsBuffer.length=0}clearPermissionCheckResults(){this.#e.set([])}checkCachedPermissions(e,t=!1){return e.length?this.latestPermissionsSubject.pipe(oi(()=>this.checkUserPermissionsActionSubject.next()),wn(s=>g(s)),le(s=>this.createPermissionCheckResult({date:new Date().toISOString(),id:this.actionIdGenerator.next().value,matchAll:t,requiredPermissions:e,url:this.location.path(),userPermissions:s})),ju()):Fs(!0)}checkPermissionsForDataContext(e,t,s){return s.length?this.httpClient.get(`${this.permissionsApiBasePath}/${e}/${t}`).pipe(le(n=>s.some(o=>n.includes(o))),Hs(()=>Fs(!1))):Fs(!0)}checkPermissionsForDataContexts(e,t,s){let n=[...new Set(t)];return n.length?ay(n.map(o=>this.checkPermissionsForDataContext(e,o,s).pipe(le(te=>[o,te])))).pipe(le(o=>new Map(o))):Fs(new Map)}invalidateCache(e=!0){this.setLatestPermissions(h),e&&this.checkUserPermissionsActionSubject.next()}invalidateBackendPermissionCache(){this.invalidateBackendPermissionCacheSubject.next()}createCacheInvalidationLogic(e){return e.pipe(Hu((t,s)=>Fs(t).pipe(s===0?Y:oi(()=>this.invalidateCache(!1)))))}setLatestPermissions(e){this.latestPermissionsSubject.value!==e&&this.latestPermissionsSubject.next(e)}createPermissionCheckResult(e){let t=this.logEnabled(),s=ee(e);if(t===!1)return s;let n={permissionCheck:e,result:s};return t?this.#e.update(o=>[...b(o,X-1),n]):this.permissionCheckResultsBuffer.push(n),s}fetchUserPermissionsFromServer(e){let t=!!e&&e.dataContextKey!==`create`,s=this.permissionsApiBasePath;return t&&(s+=`/${e.dataContextType}/${e.dataContextKey}`),this.httpClient.get(s).pipe(Hs(()=>Fs([])))}static ɵfac=function(t){return new(t||i)};static ɵprov=gn({token:i,factory:i.ɵfac})}return i})();var ne=`initialValue`;function re(i){return di(a({fn:re,injector:i.injector}),()=>{let e=w(ie).checkCachedPermissions(i.requiredPermissions);return ne in i?z(e,{initialValue:i.initialValue}):z(e,{initialValue:!1})})}export{q as n,re as r,ie as t};
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.