@dccs/teff-jeff
v1.2.0
Published
TypeScript library for managing hierarchical user permissions in frontend applications with a contract-driven approach.
Readme
@dccs/teff-jeff
@dccs/teff-jeff is a lightweight TypeScript library for managing and calculating user permissions in a hierarchical security model. It allows you to determine the permission level of a user for a specific path based on their roles and the application's security configuration.
📦 Installation
npm install @dccs/teff-jeff🚀 Usage
import { getPermission, PermissionType, Realm } from '@dccs/teff-jeff';
const securityConfig: Realm = {
dashboard: {
__p: {
admin: PermissionType.FULL,
user: PermissionType.READ
}
},
settings: {
__p: {
admin: PermissionType.FULL
}
}
};
const userRoles = ['user'];
const permission = getPermission('dashboard', securityConfig, userRoles);
console.log(permission); // Output: PermissionType.READRealm
Represents a node in the hierarchical security configuration. Each node can have a __p object mapping roles to PermissionType values, and nested nodes for sub-paths.
Example:
const realm: Realm = {
dashboard: {
__p: { admin: PermissionType.FULL, user: PermissionType.READ },
analytics: {
__p: { admin: PermissionType.FULL }
}
}
};📄 License
MIT — see LICENSE.
