@nangazaki/vue-rbac
Version:
Role-Based Access Control (RBAC) implementation for Vue.js
3 lines (2 loc) • 1.15 kB
JavaScript
import{logger as t}from"../utils/logger.js";async function o(t){return new Promise(o=>setTimeout(o,t))}async function e(e,i,n,r){let a;for(let s=1;s<=i;s++)try{return await e()}catch(e){if(a=e,s<i){const e=n*Math.pow(r,s-1);t.warn(`RBAC dynamic load failed (attempt ${s}/${i}). Retrying in ${e}ms...`),await o(e)}}throw a}async function i(o,i,n=!1){var r;o.isLoading=!0;const{attempts:a=3,delay:s=1e3,backoff:c=2}=null!==(r=i.retry)&&void 0!==r?r:{};try{let r={};return"function"==typeof i.fetchRoles?r=await e(()=>Promise.resolve(i.fetchRoles()),a,s,c):i.apiEndpoint&&(t.warn("`apiEndpoint` is deprecated, use `fetchRoles` instead"),r=await e(async()=>{const t=await fetch(i.apiEndpoint,i.fetchOptions);if(!t.ok)throw new Error(`Failed to load configuration: ${t.status} ${t.statusText}`);const o=await t.json();return i.transformResponse(o).roles},a,s,c)),r||t.error("No valid configuration loader provided (fetchRoles or apiEndpoint)"),o.roles=n?{...o.roles,...r}:r,o.isInitialized=!0,o.roles}catch(o){throw t.error("Error loading RBAC configuration:",o),o}finally{o.isLoading=!1}}export{i as loadDynamicConfig};
//# sourceMappingURL=dynamic.js.map