@sudobility/entity_service 1.0.26 → 1.0.27
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 +83 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @sudobility/entity_service
|
|
2
|
+
|
|
3
|
+
Shared backend library for multi-tenant entity/organization management with Drizzle ORM and Hono middleware.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @sudobility/entity_service
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import {
|
|
15
|
+
createEntityHelpers,
|
|
16
|
+
createEntitiesTable,
|
|
17
|
+
createEntityMembersTable,
|
|
18
|
+
createEntityContextMiddleware,
|
|
19
|
+
} from '@sudobility/entity_service';
|
|
20
|
+
|
|
21
|
+
// Setup helpers
|
|
22
|
+
const helpers = createEntityHelpers({
|
|
23
|
+
db: drizzleDb,
|
|
24
|
+
entitiesTable: schema.entities,
|
|
25
|
+
membersTable: schema.entityMembers,
|
|
26
|
+
invitationsTable: schema.entityInvitations,
|
|
27
|
+
usersTable: schema.users,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Entity operations
|
|
31
|
+
const entity = await helpers.entity.getOrCreatePersonalEntity(userId, email);
|
|
32
|
+
const org = await helpers.entity.createOrganizationEntity(userId, { displayName: 'My Org' });
|
|
33
|
+
const entities = await helpers.entity.getUserEntities(userId);
|
|
34
|
+
|
|
35
|
+
// Hono middleware
|
|
36
|
+
app.use('/api/v1/entities/:entitySlug/*', createEntityContextMiddleware(config, {
|
|
37
|
+
getUserId: (c) => c.get('userId'),
|
|
38
|
+
}));
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### Schema Factories
|
|
44
|
+
|
|
45
|
+
| Export | Description |
|
|
46
|
+
|--------|-------------|
|
|
47
|
+
| `createEntitiesTable(pgSchema, prefix)` | Entities table definition |
|
|
48
|
+
| `createEntityMembersTable(pgSchema, prefix)` | Entity members table |
|
|
49
|
+
| `createEntityInvitationsTable(pgSchema, prefix)` | Invitations table |
|
|
50
|
+
|
|
51
|
+
### Helpers
|
|
52
|
+
|
|
53
|
+
| Helper | Key Methods |
|
|
54
|
+
|--------|-------------|
|
|
55
|
+
| `EntityHelper` | `getOrCreatePersonalEntity`, `createOrganizationEntity`, `getUserEntities`, CRUD |
|
|
56
|
+
| `EntityMemberHelper` | Member listing, role updates, removal |
|
|
57
|
+
| `InvitationHelper` | Create, accept, decline, cancel, renew invitations |
|
|
58
|
+
| `PermissionHelper` | Role-based permission checks (Owner > Manager > Member) |
|
|
59
|
+
|
|
60
|
+
### Middleware
|
|
61
|
+
|
|
62
|
+
| Export | Description |
|
|
63
|
+
|--------|-------------|
|
|
64
|
+
| `createEntityContextMiddleware` | Hono middleware injecting entity context, role, and permissions |
|
|
65
|
+
|
|
66
|
+
### Types
|
|
67
|
+
|
|
68
|
+
Re-exports from `@sudobility/types`: `Entity`, `EntityMember`, `EntityInvitation`, `EntityType`, `EntityRole`, `EntityPermissions`
|
|
69
|
+
|
|
70
|
+
## Development
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
bun run build # Build ESM-only
|
|
74
|
+
bun run verify # All checks + build (use before commit)
|
|
75
|
+
bun test # Run tests (vitest)
|
|
76
|
+
bun run typecheck # TypeScript check
|
|
77
|
+
bun run lint # ESLint
|
|
78
|
+
bun run clean # Remove dist/
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
BUSL-1.1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/entity_service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "Shared entity/organization management library for multi-tenant workspaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
"author": "Sudobility",
|
|
49
49
|
"license": "BUSL-1.1",
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@sudobility/types": "^1.9.
|
|
51
|
+
"@sudobility/types": "^1.9.56",
|
|
52
52
|
"drizzle-orm": "^0.45.0",
|
|
53
53
|
"hono": "^4.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"vitest": "^4.0.4",
|
|
57
|
-
"@sudobility/types": "^1.9.
|
|
57
|
+
"@sudobility/types": "^1.9.56",
|
|
58
58
|
"@types/bun": "latest",
|
|
59
59
|
"@types/node": "^24.0.0",
|
|
60
60
|
"@typescript-eslint/eslint-plugin": "^8.50.0",
|