feat(phase-3): workstream 1 — Multi-Tenancy

Introduces full multi-tenant organization model to AgentIdP:

Schema:
- 6 migrations: organizations + organization_members tables; organization_id FK
  added to agents, credentials, audit_logs; PostgreSQL RLS policies on all three
  tables; system org seed + backfill

API:
- 6 new /api/v1/organizations endpoints (CRUD + members) gated by admin:orgs scope
- OPA scopes.json updated with 6 new org endpoint → admin:orgs mappings

Implementation:
- OrgRepository, OrgService, OrgController, createOrgsRouter
- OrgContextMiddleware: sets app.organization_id session variable so RLS enforces
  per-request org isolation at the database layer
- JWT payload extended with organization_id claim; auth.ts backfills org_system
  for backward-compatible tokens
- New error classes: OrgNotFoundError, OrgHasActiveAgentsError, AlreadyMemberError

Tests: 373 passing, 80.64% branch coverage, zero any types

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
SentryAgent.ai Developer
2026-03-30 00:29:32 +00:00
parent cb7d079ef6
commit d252097f71
31 changed files with 3043 additions and 35 deletions

View File

@@ -17,29 +17,38 @@
"dependencies": {
"@open-policy-agent/opa-wasm": "^1.10.0",
"bcryptjs": "^2.4.3",
"bull": "^4.16.5",
"cors": "^2.8.5",
"did-resolver": "^4.1.0",
"dotenv": "^16.4.5",
"express": "^4.18.3",
"helmet": "^7.1.0",
"joi": "^17.12.3",
"jsonwebtoken": "^9.0.2",
"kafkajs": "^2.2.4",
"morgan": "^1.10.0",
"node-forge": "^1.4.0",
"node-vault": "^0.12.0",
"oidc-provider": "^9.7.1",
"pg": "^8.11.3",
"pino": "^8.19.0",
"pino-http": "^9.0.0",
"prom-client": "^15.1.3",
"redis": "^4.6.13",
"uuid": "^9.0.1"
"ulid": "^3.0.2",
"uuid": "^9.0.1",
"web-did-resolver": "^2.0.32"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/bull": "^3.15.9",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/jsonwebtoken": "^9.0.6",
"@types/morgan": "^1.9.9",
"@types/node": "^20.12.7",
"@types/node-forge": "^1.3.14",
"@types/node-vault": "^0.9.1",
"@types/pg": "^8.11.5",
"@types/supertest": "^6.0.2",