@stacksjs/auth 0.70.94 → 0.70.95
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/permissions.d.ts +16 -0
- package/dist/permissions.js +4 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from './tokens';
|
|
|
15
15
|
export * from './gate';
|
|
16
16
|
export * from './policy';
|
|
17
17
|
export * from './authorizable';
|
|
18
|
+
export * from './permissions';
|
|
18
19
|
// Role-Based Access Control (RBAC)
|
|
19
20
|
export * from './rbac';
|
|
20
21
|
export { createBqbRbacStore } from './rbac-store-bqb';
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./tokens";
|
|
|
11
11
|
export * from "./gate";
|
|
12
12
|
export * from "./policy";
|
|
13
13
|
export * from "./authorizable";
|
|
14
|
+
export * from "./permissions";
|
|
14
15
|
export * from "./rbac";
|
|
15
16
|
export { createBqbRbacStore } from "./rbac-store-bqb";
|
|
16
17
|
export { DEFAULT_ROLE_PACKS, seedDefaultRoles } from "./rbac-seed";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define a typed, deterministic role-to-permission resolver.
|
|
3
|
+
*
|
|
4
|
+
* This complements the database-backed `Rbac` facade for applications whose
|
|
5
|
+
* role grants live in source control, or whose tenant membership is the
|
|
6
|
+
* authorization subject rather than the authenticated user record itself.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineRolePermissions<const TRole extends string, const TPermission extends string>(grants: RolePermissionMap<TRole, TPermission>): RolePermissions<TRole, TPermission>;
|
|
9
|
+
export declare interface RolePermissions<TRole extends string, TPermission extends string> {
|
|
10
|
+
roleCan: (role: TRole | null | undefined, permission: TPermission) => boolean
|
|
11
|
+
can: (subject: { role: TRole } | null | undefined, permission: TPermission) => boolean
|
|
12
|
+
canAny: (subject: { role: TRole } | null | undefined, permissions: readonly TPermission[]) => boolean
|
|
13
|
+
canAll: (subject: { role: TRole } | null | undefined, permissions: readonly TPermission[]) => boolean
|
|
14
|
+
forRole: (role: TRole | null | undefined) => readonly TPermission[]
|
|
15
|
+
}
|
|
16
|
+
export type RolePermissionMap<TRole extends string, TPermission extends string> = Record<TRole, readonly TPermission[]>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export function defineRolePermissions(grants) {
|
|
2
|
+
const frozenGrants = Object.fromEntries(Object.entries(grants).map(([role, permissions]) => [role, Object.freeze([...permissions])])), forRole = (role) => role ? frozenGrants[role] ?? [] : [], roleCan = (role, permission) => forRole(role).includes(permission), can = (subject, permission) => roleCan(subject?.role, permission);
|
|
3
|
+
return Object.freeze({ roleCan, can, canAny: (subject, permissions) => permissions.some((permission) => can(subject, permission)), canAll: (subject, permissions) => permissions.every((permission) => can(subject, permission)), forRole });
|
|
4
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/auth",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.70.
|
|
5
|
+
"version": "0.70.95",
|
|
6
6
|
"description": "A more simplistic way to authenticate.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"better-dx": "^0.2.16",
|
|
58
|
-
"@stacksjs/error-handling": "0.70.
|
|
59
|
-
"@stacksjs/router": "0.70.
|
|
58
|
+
"@stacksjs/error-handling": "0.70.95",
|
|
59
|
+
"@stacksjs/router": "0.70.95"
|
|
60
60
|
}
|
|
61
61
|
}
|