@qlibs/utils-fe
v1.1.0
Published
Just general reusable functions
Downloads
6
Readme
LIBS-UTILS-FE
Just general reusable functions
How to Install
npm install @qlibs/utils-fe
or yarn add @qlibs/utils-fe
Supported Permission Data (Example)
const EXAMPLE_BASE_PERMISSIONS: IFeaturePermissionV2 = {
AUTH: ['LOGIN_CMS', 'LOGIN_WEB'],
BANNER: ['VIEW', 'CREATE', 'UPDATE'],
PROJECT: {
PROJECT_1: ['VIEW', 'CREATE', 'UPDATE'],
PROJECT_2: ['VIEW'],
},
USER: ['VIEW', 'CREATE', 'UPDATE'],
};
const EXAMPLE_USER_PERMISSIONS: IFeaturePermissionV2 = {
AUTH: ['LOGIN_CMS', 'LOGIN_WEB'],
PROJECT: {
PROJECT_1: ['VIEW', 'CREATE', 'UPDATE'],
PROJECT_2: ['VIEW'],
},
USER: ['VIEW', 'CREATE', 'UPDATE'],
};
Available Methods
- detectPermission
const permissionVersion = detectPermissionVersion(EXAMPLE_USER_PERMISSIONS);
console.info('permissionVersion', permissionVersion); // v1 | v2 | null
- hasPermission
const isHasPermission = hasPermission(
EXAMPLE_USER_PERMISSIONS,
requiredPermissions: ["USER.VIEW"],
"OR"
);
console.info('isHasPermission', isHasPermission); // true | false
- injectSubFeatures
const result = injectSubFeatures("USER", ["project_id_1", "project_id_2"], EXAMPLE_USER_PERMISSIONS)
- syncExistingDataWithBasePermission
const syncResult = syncExistingDataWithBasePermission(
EXAMPLE_USER_PERMISSIONS, // data from database
EXAMPLE_BASE_PERMISSIONS, // all features & permissions
{
autoEnableAllActionsForNewFeature: false;
}
)
console.info('syncResult', syncResult); // result will follow the type "IFeaturePermissionV2"
- generateFrontendPermissionData
const generatedFrontendPermissionData = generateFrontendPermissionData(
EXAMPLE_USER_PERMISSIONS, // data from database
)
console.info('generatedFrontendPermissionData', generatedFrontendPermissionData); // result will follow the type "IFeaturePermissionV2"