@contractspec/lib.identity-rbac 0.0.0-canary-20260113162409
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/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/contracts/index.d.ts +4 -0
- package/dist/contracts/index.js +5 -0
- package/dist/contracts/organization.d.ts +896 -0
- package/dist/contracts/organization.d.ts.map +1 -0
- package/dist/contracts/organization.js +605 -0
- package/dist/contracts/organization.js.map +1 -0
- package/dist/contracts/rbac.d.ts +612 -0
- package/dist/contracts/rbac.d.ts.map +1 -0
- package/dist/contracts/rbac.js +484 -0
- package/dist/contracts/rbac.js.map +1 -0
- package/dist/contracts/user.d.ts +611 -0
- package/dist/contracts/user.d.ts.map +1 -0
- package/dist/contracts/user.js +333 -0
- package/dist/contracts/user.js.map +1 -0
- package/dist/entities/index.d.ts +177 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +36 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/organization.d.ts +87 -0
- package/dist/entities/organization.d.ts.map +1 -0
- package/dist/entities/organization.js +151 -0
- package/dist/entities/organization.js.map +1 -0
- package/dist/entities/rbac.d.ts +88 -0
- package/dist/entities/rbac.d.ts.map +1 -0
- package/dist/entities/rbac.js +138 -0
- package/dist/entities/rbac.js.map +1 -0
- package/dist/entities/user.d.ts +88 -0
- package/dist/entities/user.d.ts.map +1 -0
- package/dist/entities/user.js +194 -0
- package/dist/entities/user.js.map +1 -0
- package/dist/events.d.ts +690 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +683 -0
- package/dist/events.js.map +1 -0
- package/dist/identity-rbac.capability.d.ts +8 -0
- package/dist/identity-rbac.capability.d.ts.map +1 -0
- package/dist/identity-rbac.capability.js +29 -0
- package/dist/identity-rbac.capability.js.map +1 -0
- package/dist/identity-rbac.feature.d.ts +12 -0
- package/dist/identity-rbac.feature.d.ts.map +1 -0
- package/dist/identity-rbac.feature.js +195 -0
- package/dist/identity-rbac.feature.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +14 -0
- package/dist/policies/engine.d.ts +133 -0
- package/dist/policies/engine.d.ts.map +1 -0
- package/dist/policies/engine.js +168 -0
- package/dist/policies/engine.js.map +1 -0
- package/dist/policies/index.d.ts +2 -0
- package/dist/policies/index.js +3 -0
- package/package.json +85 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @contractspec/lib.identity-rbac
|
|
2
|
+
|
|
3
|
+
Website: https://contractspec.io/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Identity, Organizations, and Role-Based Access Control (RBAC) module for ContractSpec applications.
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Provides a reusable identity and authorization foundation for multi-tenant, multi-role applications. This module follows the spec-first approach where entity definitions generate database schemas.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **User Management**: User profiles, authentication accounts, sessions
|
|
15
|
+
- **Organizations**: Multi-tenant organization support with slugs, metadata
|
|
16
|
+
- **Memberships**: Role-based organization membership (owner, admin, member)
|
|
17
|
+
- **RBAC**: Roles, permissions, and policy bindings
|
|
18
|
+
- **Teams**: Optional team grouping within organizations
|
|
19
|
+
- **Events**: Domain events for user/org lifecycle changes
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun add @contractspec/lib.identity-rbac
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Entity Specs (for schema generation)
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { UserEntity, OrganizationEntity, MemberEntity } from '@contractspec/lib.identity-rbac/entities';
|
|
33
|
+
|
|
34
|
+
// Use in schema composition
|
|
35
|
+
const contribution = {
|
|
36
|
+
moduleId: '@contractspec/lib.identity-rbac',
|
|
37
|
+
entities: [UserEntity, OrganizationEntity, MemberEntity, ...],
|
|
38
|
+
};
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Contracts (for API generation)
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import {
|
|
45
|
+
CreateUserContract,
|
|
46
|
+
InviteToOrgContract,
|
|
47
|
+
AssignRoleContract
|
|
48
|
+
} from '@contractspec/lib.identity-rbac/contracts';
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Policies (for authorization)
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { RBACPolicyEngine, Permission } from '@contractspec/lib.identity-rbac/policies';
|
|
55
|
+
|
|
56
|
+
const engine = new RBACPolicyEngine();
|
|
57
|
+
const canManage = await engine.checkPermission({
|
|
58
|
+
userId: 'user-123',
|
|
59
|
+
orgId: 'org-456',
|
|
60
|
+
permission: Permission.MANAGE_MEMBERS,
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Events
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { UserCreatedEvent, OrgMemberAddedEvent } from '@contractspec/lib.identity-rbac/events';
|
|
68
|
+
|
|
69
|
+
bus.subscribe(UserCreatedEvent, async (event) => {
|
|
70
|
+
// Handle user creation
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Entity Overview
|
|
75
|
+
|
|
76
|
+
| Entity | Description |
|
|
77
|
+
|--------|-------------|
|
|
78
|
+
| User | Platform user with profile and auth |
|
|
79
|
+
| Organization | Tenant/company grouping |
|
|
80
|
+
| Member | User's membership in an organization |
|
|
81
|
+
| Role | Named set of permissions |
|
|
82
|
+
| Permission | Atomic access right |
|
|
83
|
+
| PolicyBinding | Binds roles to principals |
|
|
84
|
+
| Team | Optional team within organization |
|
|
85
|
+
|
|
86
|
+
## Schemas
|
|
87
|
+
|
|
88
|
+
All entities are defined in the `lssm_sigil` PostgreSQL schema for isolation.
|
|
89
|
+
|
|
90
|
+
## Events
|
|
91
|
+
|
|
92
|
+
| Event | Trigger |
|
|
93
|
+
|-------|---------|
|
|
94
|
+
| user.created | New user registered |
|
|
95
|
+
| user.updated | User profile changed |
|
|
96
|
+
| user.deleted | User account removed |
|
|
97
|
+
| org.created | New organization created |
|
|
98
|
+
| org.member.added | User joined organization |
|
|
99
|
+
| org.member.removed | User left organization |
|
|
100
|
+
| role.assigned | Role assigned to user/org |
|
|
101
|
+
| role.revoked | Role removed from user/org |
|
|
102
|
+
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CreateUserContract, CreateUserInputModel, DeleteUserContract, DeleteUserInputModel, GetCurrentUserContract, ListUsersContract, ListUsersInputModel, ListUsersOutputModel, SuccessResultModel, UpdateUserContract, UpdateUserInputModel, UserDeletedPayloadModel, UserProfileModel } from "./user.js";
|
|
2
|
+
import { AcceptInviteContract, AcceptInviteInputModel, CreateOrgContract, CreateOrgInputModel, GetOrgContract, GetOrgInputModel, InvitationModel, InviteMemberContract, InviteMemberInputModel, ListMembersContract, ListMembersInputModel, ListMembersOutputModel, ListUserOrgsContract, ListUserOrgsOutputModel, MemberModel, MemberRemovedPayloadModel, MemberUserModel, OrganizationModel, OrganizationWithRoleModel, RemoveMemberContract, RemoveMemberInputModel, UpdateOrgContract, UpdateOrgInputModel } from "./organization.js";
|
|
3
|
+
import { AssignRoleContract, AssignRoleInputModel, BindingIdPayloadModel, CheckPermissionContract, CheckPermissionInputModel, CreateRoleContract, CreateRoleInputModel, DeleteRoleContract, DeleteRoleInputModel, ListRolesContract, ListRolesOutputModel, ListUserPermissionsContract, ListUserPermissionsInputModel, ListUserPermissionsOutputModel, PermissionCheckResultModel, PolicyBindingModel, RevokeRoleContract, RevokeRoleInputModel, RoleModel, UpdateRoleContract, UpdateRoleInputModel } from "./rbac.js";
|
|
4
|
+
export { AcceptInviteContract, AcceptInviteInputModel, AssignRoleContract, AssignRoleInputModel, BindingIdPayloadModel, CheckPermissionContract, CheckPermissionInputModel, CreateOrgContract, CreateOrgInputModel, CreateRoleContract, CreateRoleInputModel, CreateUserContract, CreateUserInputModel, DeleteRoleContract, DeleteRoleInputModel, DeleteUserContract, DeleteUserInputModel, GetCurrentUserContract, GetOrgContract, GetOrgInputModel, InvitationModel, InviteMemberContract, InviteMemberInputModel, ListMembersContract, ListMembersInputModel, ListMembersOutputModel, ListRolesContract, ListRolesOutputModel, ListUserOrgsContract, ListUserOrgsOutputModel, ListUserPermissionsContract, ListUserPermissionsInputModel, ListUserPermissionsOutputModel, ListUsersContract, ListUsersInputModel, ListUsersOutputModel, MemberModel, MemberRemovedPayloadModel, MemberUserModel, OrganizationModel, OrganizationWithRoleModel, PermissionCheckResultModel, PolicyBindingModel, RemoveMemberContract, RemoveMemberInputModel, RevokeRoleContract, RevokeRoleInputModel, RoleModel, SuccessResultModel, UpdateOrgContract, UpdateOrgInputModel, UpdateRoleContract, UpdateRoleInputModel, UpdateUserContract, UpdateUserInputModel, UserDeletedPayloadModel, UserProfileModel };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CreateUserContract, CreateUserInputModel, DeleteUserContract, DeleteUserInputModel, GetCurrentUserContract, ListUsersContract, ListUsersInputModel, ListUsersOutputModel, SuccessResultModel, UpdateUserContract, UpdateUserInputModel, UserDeletedPayloadModel, UserProfileModel } from "./user.js";
|
|
2
|
+
import { AcceptInviteContract, AcceptInviteInputModel, CreateOrgContract, CreateOrgInputModel, GetOrgContract, GetOrgInputModel, InvitationModel, InviteMemberContract, InviteMemberInputModel, ListMembersContract, ListMembersInputModel, ListMembersOutputModel, ListUserOrgsContract, ListUserOrgsOutputModel, MemberModel, MemberRemovedPayloadModel, MemberUserModel, OrganizationModel, OrganizationWithRoleModel, RemoveMemberContract, RemoveMemberInputModel, UpdateOrgContract, UpdateOrgInputModel } from "./organization.js";
|
|
3
|
+
import { AssignRoleContract, AssignRoleInputModel, BindingIdPayloadModel, CheckPermissionContract, CheckPermissionInputModel, CreateRoleContract, CreateRoleInputModel, DeleteRoleContract, DeleteRoleInputModel, ListRolesContract, ListRolesOutputModel, ListUserPermissionsContract, ListUserPermissionsInputModel, ListUserPermissionsOutputModel, PermissionCheckResultModel, PolicyBindingModel, RevokeRoleContract, RevokeRoleInputModel, RoleModel, UpdateRoleContract, UpdateRoleInputModel } from "./rbac.js";
|
|
4
|
+
|
|
5
|
+
export { AcceptInviteContract, AcceptInviteInputModel, AssignRoleContract, AssignRoleInputModel, BindingIdPayloadModel, CheckPermissionContract, CheckPermissionInputModel, CreateOrgContract, CreateOrgInputModel, CreateRoleContract, CreateRoleInputModel, CreateUserContract, CreateUserInputModel, DeleteRoleContract, DeleteRoleInputModel, DeleteUserContract, DeleteUserInputModel, GetCurrentUserContract, GetOrgContract, GetOrgInputModel, InvitationModel, InviteMemberContract, InviteMemberInputModel, ListMembersContract, ListMembersInputModel, ListMembersOutputModel, ListRolesContract, ListRolesOutputModel, ListUserOrgsContract, ListUserOrgsOutputModel, ListUserPermissionsContract, ListUserPermissionsInputModel, ListUserPermissionsOutputModel, ListUsersContract, ListUsersInputModel, ListUsersOutputModel, MemberModel, MemberRemovedPayloadModel, MemberUserModel, OrganizationModel, OrganizationWithRoleModel, PermissionCheckResultModel, PolicyBindingModel, RemoveMemberContract, RemoveMemberInputModel, RevokeRoleContract, RevokeRoleInputModel, RoleModel, SuccessResultModel, UpdateOrgContract, UpdateOrgInputModel, UpdateRoleContract, UpdateRoleInputModel, UpdateUserContract, UpdateUserInputModel, UserDeletedPayloadModel, UserProfileModel };
|