@fonderie/permissions 1.0.1 → 1.0.3
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/brain/outcomes.md +28 -0
- package/brain/signatures.md +72 -0
- package/dist/migrations/sql/001_permissions.sql +17 -0
- package/package.json +5 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<!-- GENERATED — do not edit. Regenerate with: npm run docs:signatures -->
|
|
2
|
+
|
|
3
|
+
# @fonderie/permissions — outcomes
|
|
4
|
+
|
|
5
|
+
What this package does to a running app: tables its migrations create,
|
|
6
|
+
rows it seeds, routes it registers. Generated from the migration SQL and
|
|
7
|
+
route tables in source — trust this file instead of reading `dist/` or
|
|
8
|
+
downloading tarballs.
|
|
9
|
+
|
|
10
|
+
## Database tables (after all migrations)
|
|
11
|
+
|
|
12
|
+
### `fonderie_role_permissions`
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid()
|
|
16
|
+
role_id UUID NOT NULL
|
|
17
|
+
workspace_id UUID
|
|
18
|
+
permission_key TEXT NOT NULL
|
|
19
|
+
can_create BOOLEAN NOT NULL DEFAULT false
|
|
20
|
+
can_read BOOLEAN NOT NULL DEFAULT false
|
|
21
|
+
can_update BOOLEAN NOT NULL DEFAULT false
|
|
22
|
+
can_delete BOOLEAN NOT NULL DEFAULT false
|
|
23
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
24
|
+
-- UNIQUE (role_id, permission_key)
|
|
25
|
+
-- INDEX idx_frp_permission_key (permission_key)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Raw SQL ships in `node_modules/@fonderie/permissions/dist/migrations/sql/` — read it there if you must; never download tarballs.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<!-- GENERATED — do not edit. Regenerate with: npm run docs:signatures -->
|
|
2
|
+
|
|
3
|
+
# @fonderie/permissions — signatures
|
|
4
|
+
|
|
5
|
+
## @fonderie/permissions
|
|
6
|
+
|
|
7
|
+
Subpath exports: `@fonderie/permissions/config`, `@fonderie/permissions/types`, `@fonderie/permissions/middleware`, `@fonderie/permissions/migrations`
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
type Operation = 'create' | 'read' | 'update' | 'delete';
|
|
11
|
+
|
|
12
|
+
type PermissionKey = string;
|
|
13
|
+
|
|
14
|
+
interface IRole {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
isSystem: boolean;
|
|
18
|
+
workspaceId: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IPermission {
|
|
22
|
+
permissionKey: PermissionKey;
|
|
23
|
+
canCreate: boolean;
|
|
24
|
+
canRead: boolean;
|
|
25
|
+
canUpdate: boolean;
|
|
26
|
+
canDelete: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface IMembership {
|
|
30
|
+
userId: string;
|
|
31
|
+
workspaceId: string;
|
|
32
|
+
roleId: string;
|
|
33
|
+
roleName: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface IRoleWithPermissions extends IRole {
|
|
37
|
+
permissions: IPermission[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
new PermissionsModule(store: IStoreAdapter, config?: IPermissionsConfig): PermissionsModule
|
|
41
|
+
.engine: PermissionsEngine
|
|
42
|
+
.name: "@fonderie/permissions"
|
|
43
|
+
.deps: string[]
|
|
44
|
+
.install(app: IFonderieApp): void
|
|
45
|
+
|
|
46
|
+
new PermissionsEngine(store: IStoreAdapter, config?: IPermissionsConfig): PermissionsEngine
|
|
47
|
+
.getMembership(userId: string, workspaceId: string): Promise<IMembership | null>
|
|
48
|
+
.can(userId: string, operation: Operation, permissionKey: string, workspaceId: string): Promise<boolean>
|
|
49
|
+
.assert(userId: string, operation: Operation, permissionKey: string, workspaceId: string): Promise<void>
|
|
50
|
+
.canAll(userId: string, checks: { operation: Operation; permissionKey: string; }[], workspaceId: string): Promise<boolean>
|
|
51
|
+
.canAny(userId: string, checks: { operation: Operation; permissionKey: string; }[], workspaceId: string): Promise<boolean>
|
|
52
|
+
|
|
53
|
+
new PermissionDeniedError(operation: string, permissionKey: string): PermissionDeniedError
|
|
54
|
+
.status: 403
|
|
55
|
+
.name: string
|
|
56
|
+
.message: string
|
|
57
|
+
.stack: string
|
|
58
|
+
.cause: unknown
|
|
59
|
+
|
|
60
|
+
interface IPermissionsConfig {
|
|
61
|
+
wildcards?: boolean;
|
|
62
|
+
superRole?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const OPERATIONS: { readonly CREATE: "create"; readonly READ: "read"; readonly UPDATE: "update"; readonly DELETE: "delete"; }
|
|
66
|
+
|
|
67
|
+
const PERMISSION_COLUMN: { create: string; read: string; update: string; delete: string; }
|
|
68
|
+
|
|
69
|
+
function requireRole(roleName: string | string[], store: IStoreAdapter): Middleware
|
|
70
|
+
|
|
71
|
+
function requirePermission(operation: Operation, permissionKey: string): Middleware
|
|
72
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
-- fonderie_role_permissions: CRUD bit flags per role per resource key
|
|
2
|
+
CREATE TABLE IF NOT EXISTS fonderie_role_permissions (
|
|
3
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
4
|
+
role_id UUID NOT NULL,
|
|
5
|
+
workspace_id UUID,
|
|
6
|
+
permission_key TEXT NOT NULL,
|
|
7
|
+
can_create BOOLEAN NOT NULL DEFAULT false,
|
|
8
|
+
can_read BOOLEAN NOT NULL DEFAULT false,
|
|
9
|
+
can_update BOOLEAN NOT NULL DEFAULT false,
|
|
10
|
+
can_delete BOOLEAN NOT NULL DEFAULT false,
|
|
11
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
12
|
+
UNIQUE (role_id, permission_key)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE INDEX IF NOT EXISTS idx_frp_role_id ON fonderie_role_permissions (role_id);
|
|
16
|
+
CREATE INDEX IF NOT EXISTS idx_frp_workspace_id ON fonderie_role_permissions (workspace_id);
|
|
17
|
+
CREATE INDEX IF NOT EXISTS idx_frp_permission_key ON fonderie_role_permissions (permission_key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonderie/permissions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Role-based access control for SaaS — define roles, assign CRUD permissions per resource, and gate any route with requirePermission. Supports multiple roles per user via BOOL_OR aggregation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fonderie-js",
|
|
@@ -72,16 +72,17 @@
|
|
|
72
72
|
},
|
|
73
73
|
"files": [
|
|
74
74
|
"dist",
|
|
75
|
+
"brain",
|
|
75
76
|
"LICENSE",
|
|
76
77
|
"README.md"
|
|
77
78
|
],
|
|
78
79
|
"repository": {
|
|
79
80
|
"type": "git",
|
|
80
|
-
"url": "git+https://github.com/
|
|
81
|
+
"url": "git+https://github.com/fonderiejs/sdk.git",
|
|
81
82
|
"directory": "packages/permissions"
|
|
82
83
|
},
|
|
83
|
-
"homepage": "https://github.com/
|
|
84
|
+
"homepage": "https://github.com/fonderiejs/sdk/tree/main/packages/permissions#readme",
|
|
84
85
|
"bugs": {
|
|
85
|
-
"url": "https://github.com/
|
|
86
|
+
"url": "https://github.com/fonderiejs/sdk/issues"
|
|
86
87
|
}
|
|
87
88
|
}
|