Skip to Content
gentlemans-stack
ReferenceContracts

workspace-contracts

oRPC contract for workspace: the typed request/response surface a service implements and clients call against.

API

FileExports
workspace.contract.tsworkspaceContract

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

ProcedureRouteIntentInputOutput
invitations.createPOST /workspaces/{workspaceId}/invitationsmember:invite{ email, role, workspaceId }, role from invitableRoleSchema (admin, member, viewer)CreatedWorkspaceInvitation: the WorkspaceInvitation plus token, returned only here
invitations.listGET /workspaces/{workspaceId}/invitationsmember:invite{ workspaceId }pending WorkspaceInvitation[] (unused, unrevoked, unexpired), oldest first
invitations.revokeDELETE /workspaces/{workspaceId}/invitations/{invitationId}member:invite{ invitationId, workspaceId }the revoked WorkspaceInvitation; 404 when it is not pending in that workspace
invitations.acceptPOST /invitations/acceptnone (sign-in only){ token } in the body, never the paththe joined Workspace
invitations.listMineGET /invitations/minenone (sign-in only)nonethe pending MyWorkspaceInvitations addressed to the caller's email, each with workspaceName
invitations.acceptMinePOST /invitations/{invitationId}/acceptnone (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

  1. Generate or update models/workspace-model, then compose its portable schemas into this contract.
  2. Add the remaining procedures the resource needs (create, list, update, delete, ...), each with .route(...), .input(...), and .output(...).
  3. Implement the contract's router in the consuming service's composition root.

Commands

pnpm nx run workspace-contracts:typecheck   # type-check the package

On this page