workspace-contracts
oRPC contract for workspace: the typed request/response surface a service implements and clients call against.
API
| File | Exports |
|---|---|
| workspace.contract.ts | workspaceContract |
workspaceContract = { audit: { list }, invitations: { accept, acceptMine, create, list, listMine, revoke }, members: { list, remove, setRole }, workspaces: { create, delete, get, listMine, transferOwner, update } }.
Every workspace-scoped procedure takes workspaceId and declares an intent in its meta (WorkspaceContractMeta), which
createRequireIntent in libs/auth checks against ROLE_INTENTS in workspace-model. create and listMine have no
intent: signing in is enough. setRole accepts admin, member or viewer only; ownership moves through transferOwner.
create carries a rateLimit meta. audit.list (GET /workspaces/{workspaceId}/audit, intent audit:read: owner and admin) takes action?, actorId?, cursor? and limit and returns a page of events without context.ip, spanId and traceId (auditPageViewSchema). A procedure that changes something also declares an audit meta beside intent (audit: { action, changes?, target? }, see audit-domain); the audit middleware reads it. The service implementing it is services/iam-service.
Invitations
| Procedure | Route | Intent | Input | Output |
|---|---|---|---|---|
invitations.create | POST /workspaces/{workspaceId}/invitations | member:invite | { email, role, workspaceId }, role from invitableRoleSchema (admin, member, viewer) | CreatedWorkspaceInvitation: the WorkspaceInvitation plus token, returned only here |
invitations.list | GET /workspaces/{workspaceId}/invitations | member:invite | { workspaceId } | pending WorkspaceInvitation[] (unused, unrevoked, unexpired), oldest first |
invitations.revoke | DELETE /workspaces/{workspaceId}/invitations/{invitationId} | member:invite | { invitationId, workspaceId } | the revoked WorkspaceInvitation; 404 when it is not pending in that workspace |
invitations.accept | POST /invitations/accept | none (sign-in only) | { token } in the body, never the path | the joined Workspace |
invitations.listMine | GET /invitations/mine | none (sign-in only) | none | the pending MyWorkspaceInvitations addressed to the caller's email, each with workspaceName |
invitations.acceptMine | POST /invitations/{invitationId}/accept | none (sign-in only) | { invitationId } | the joined Workspace; the caller's email must match the invite's (USER_UNAUTHORIZED / email_mismatch otherwise) |
create and accept carry a rateLimit meta. The token (InvitationToken) is 43 base64url characters. Accept
refusals: an unknown token or a deleted workspace is RESOURCE_NOT_FOUND (resource: "invitation" or "workspace");
another signed-in email is USER_UNAUTHORIZED email_mismatch; RESOURCE_CONFLICT with invite_expired or
invite_used (used or revoked; resource: "invitation"), or already_member (resource: "workspace").
Complete the contract
- Generate or update
models/workspace-model, then compose its portable schemas into this contract. - Add the remaining procedures the resource needs (create, list, update, delete, ...), each with
.route(...),.input(...), and.output(...). - Implement the contract's router in the consuming service's composition root.
Commands
pnpm nx run workspace-contracts:typecheck # type-check the package