privilege-access-control
v1.0.2
Published
Reusable NestJS guard/decorators for privilege-based access control
Downloads
210
Maintainers
Readme
privilege-access-control
Reusable NestJS access-control primitives for microservices.
Includes
PrivilegesGuardRequirePrivilege()decoratorCurrentUserId()decorator- Header privilege utilities
- Enums:
PrivilegeGroup,PrivilegeName,ErrorMessage
Install
npm install privilege-access-controlPublish to npm
1. Login to npm (once per machine)
npm login2. Build and verify package contents
If your global npm cache has permission issues, use a local cache for this project:
npm_config_cache=.npm-cache npm run build
npm_config_cache=.npm-cache npm run packcheck3. Bump version
npm version patch
# or: npm version minor
# or: npm version major4. Publish
npm publish --access publicFor this unscoped package, --access public is optional.
Use in another microservice
npm install privilege-access-controlThen import from your module/controller/resolver:
import {
PrivilegesGuard,
RequirePrivilege,
CurrentUserId,
PrivilegeGroup,
PrivilegeName,
} from 'privilege-access-control';Usage
import {
PrivilegesGuard,
RequirePrivilege,
CurrentUserId,
PrivilegeGroup,
PrivilegeName,
} from 'privilege-access-control';
@UseGuards(PrivilegesGuard)
@RequirePrivilege(PrivilegeGroup.USER, PrivilegeName.READ)If your service is GraphQL, ensure the request context includes incoming headers used by this package.
Headers expected
x-user-idx-user-privileges(orprivileges/x-privileges)
