@lbstack/accessx 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/engine.js +1 -1
- package/package.json +1 -1
- package/readme.md +3 -3
package/dist/src/core/engine.js
CHANGED
|
@@ -142,7 +142,7 @@ export function createEngine(config) {
|
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
144
|
* Check if a role has the specified permission.
|
|
145
|
-
* @param role The role or roles to check.
|
|
145
|
+
* @param role The role or roles to check (e.g. `user.role` from session).
|
|
146
146
|
* @param permission The permission to check.
|
|
147
147
|
* @param contextOrValidator
|
|
148
148
|
* - (Recommended) A callback function `() => boolean` that returns true if allowed.
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -155,7 +155,7 @@ access.allow("ADMIN", "USER:DELETE");
|
|
|
155
155
|
// Multiple permissions
|
|
156
156
|
access.allow("EDITOR", ["BLOGS:CREATE", "BLOGS:READ", "BLOGS:UPDATE"]);
|
|
157
157
|
|
|
158
|
-
// With custom ABAC conditions
|
|
158
|
+
// With custom ABAC conditions (DEPRECATED: Use Runtime Validation instead)
|
|
159
159
|
access.allow("USER", "BLOG:UPDATE", (context) => {
|
|
160
160
|
return context.post.authorId === context.user.id;
|
|
161
161
|
});
|
|
@@ -305,13 +305,13 @@ You can define dynamic permissions based on context.
|
|
|
305
305
|
Pass a validator function directly to `access.can`. This function is executed at runtime.
|
|
306
306
|
|
|
307
307
|
```typescript
|
|
308
|
-
const isAllowed = access.can(
|
|
308
|
+
const isAllowed = access.can(user.role, "BLOG:UPDATE", () => {
|
|
309
309
|
// Your logic here
|
|
310
310
|
return post.authorId === user.id;
|
|
311
311
|
});
|
|
312
312
|
```
|
|
313
313
|
|
|
314
|
-
This approach allows you to keep your permissions stored as pure data (strings) in your database while keeping the complex validation logic in your application code.
|
|
314
|
+
This approach allows you to keep your permissions stored as pure data (strings) in your database while keeping the complex validation logic in your application code. Use `user.role` dynamically from your session/token.
|
|
315
315
|
|
|
316
316
|
### 2. Stored Conditions (Deprecated ⚠️)
|
|
317
317
|
|