@meridianjs/workspace-member 0.1.0 → 1.0.0
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/README.md +75 -0
- package/package.json +9 -5
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @meridianjs/workspace-member
|
|
2
|
+
|
|
3
|
+
Workspace membership module for MeridianJS. Tracks which users belong to which workspaces and their workspace-level role (`admin` or `member`). Used by route handlers to enforce workspace isolation.
|
|
4
|
+
|
|
5
|
+
Auto-loaded by `@meridianjs/meridian` — you do not need to add this to `modules[]` yourself.
|
|
6
|
+
|
|
7
|
+
## Service: `workspaceMemberModuleService`
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
const svc = req.scope.resolve("workspaceMemberModuleService") as any
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Methods
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// Get all workspace IDs a user belongs to
|
|
17
|
+
const workspaceIds = await svc.getWorkspaceIdsForUser(userId)
|
|
18
|
+
|
|
19
|
+
// Get a specific membership record (returns null if not a member)
|
|
20
|
+
const membership = await svc.getMembership(workspaceId, userId)
|
|
21
|
+
|
|
22
|
+
// Check if a user is a member of a workspace
|
|
23
|
+
const isMember = await svc.isMember(workspaceId, userId) // → boolean
|
|
24
|
+
|
|
25
|
+
// Add a user to a workspace if not already a member
|
|
26
|
+
await svc.ensureMember(workspaceId, userId, "member")
|
|
27
|
+
|
|
28
|
+
// Standard CRUD
|
|
29
|
+
await svc.listWorkspaceMembers(filters?)
|
|
30
|
+
await svc.createWorkspaceMember({ workspace_id, user_id, role })
|
|
31
|
+
await svc.updateWorkspaceMember(id, { role })
|
|
32
|
+
await svc.deleteWorkspaceMember(id)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Access Control Pattern
|
|
36
|
+
|
|
37
|
+
Route handlers use this service to filter data by membership:
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const roles = req.user?.roles ?? []
|
|
41
|
+
const isPrivileged = roles.includes("admin") || roles.includes("super-admin")
|
|
42
|
+
|
|
43
|
+
if (isPrivileged) {
|
|
44
|
+
// Return all workspaces
|
|
45
|
+
const workspaces = await workspaceSvc.listWorkspaces()
|
|
46
|
+
} else {
|
|
47
|
+
// Return only workspaces the user belongs to
|
|
48
|
+
const ids = await memberSvc.getWorkspaceIdsForUser(req.user.id)
|
|
49
|
+
const workspaces = await workspaceSvc.listWorkspaces({ id: ids })
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Data Model
|
|
54
|
+
|
|
55
|
+
### WorkspaceMember
|
|
56
|
+
|
|
57
|
+
| Field | Type | Description |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `id` | `uuid` | Primary key |
|
|
60
|
+
| `workspace_id` | `text` | Workspace |
|
|
61
|
+
| `user_id` | `text` | User |
|
|
62
|
+
| `role` | `text` | `"admin"` \| `"member"` |
|
|
63
|
+
| `created_at` | `datetime` | — |
|
|
64
|
+
|
|
65
|
+
## API Routes
|
|
66
|
+
|
|
67
|
+
| Method | Path | Description |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `GET/POST` | `/admin/workspaces/:id/members` | List / add members |
|
|
70
|
+
| `PATCH` | `/admin/workspaces/:id/members/:userId` | Update member role |
|
|
71
|
+
| `DELETE` | `/admin/workspaces/:id/members/:userId` | Remove member |
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meridianjs/workspace-member",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Meridian workspace-member module — tracks workspace membership and roles",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"prepublishOnly": "npm run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@meridianjs/framework-utils": "^
|
|
29
|
-
"@meridianjs/types": "^
|
|
28
|
+
"@meridianjs/framework-utils": "^1.0.0",
|
|
29
|
+
"@meridianjs/types": "^1.0.0",
|
|
30
30
|
"@mikro-orm/core": "^6.4.3",
|
|
31
31
|
"@mikro-orm/postgresql": "^6.4.3"
|
|
32
32
|
},
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"tsup": "^8.3.5",
|
|
35
35
|
"typescript": "*"
|
|
36
36
|
},
|
|
37
|
-
"files": [
|
|
38
|
-
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
39
43
|
}
|