feat(api): add workspace administration to the public API - #1175
Open
realcodesiman wants to merge 2 commits into
Open
realcodesiman wants to merge 2 commits into
realcodesiman wants to merge 2 commits into
Conversation
Add a new "workspace" workspace-token scope covering workspace settings, API tokens, members, templates, and audit logs — the one area with no public surface today. - workspace: get/update/updateStatus, schedule/cancel deletion, support-access toggle, and channel-token refresh - apiTokens: full CRUD + rotate, gated behind an unrestricted (all-scopes) token so a token can never mint one broader than itself - workspaceMembers: invite/update/remove write routes alongside the existing list/get - templates: full CRUD, share settings, installations, and auto-update toggle - auditLogs: enterprise-gated list Lifts the per-integration channel-token refresh loop out of refresh-all-channel-tokens.action.ts into a new channelTokenRefreshService, and the invitation insert out of invite-workspace-member.action.ts into invitationService.create, so both the builder action and the new public route share one implementation. workspaceId is always taken from the authenticated token's context; secrets (tokenHash, encryptedToken, template payload, tenantId) are never serialized.
- requireUnrestrictedToken (guards /v1/api-tokens) treated a missing apiToken context as an unrestricted token instead of rejecting it; now explicitly requires a present, scopes:null token. - workspace-token-auth blocked every route once a workspace was scheduled for deletion, including DELETE /v1/workspace/deletion itself, leaving no way to cancel via the public API; the owner trial/quota gate now takes the request path too, exempting the deletion-lifecycle routes the same way workspaceActionClient already does for session callers (invariant #14). - Consolidated logic duplicated between the new public routes and their private builder-action counterparts into shared business services: invitationService.create (audit failures no longer reject the invite), workspaceMemberService.updateMember (diff + role_change audit), templateService.enqueueInstallation (install/enqueue/fail sequence), and channelTokenRefreshService.refreshWorkspaces (batches every provider lookup across all workspace ids in one query instead of one query per workspace). - Added cross-workspace-isolation (IDOR) regression tests for workspace API tokens, workspace members, and templates, plus coverage for the two auth-gate fixes above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
workspaceworkspace-token scope and its public routes, closing the one gap in the public API: workspace administration (settings, API tokens, member writes, templates, audit logs) was builder-session-only.workspace— get/update/updateStatus, schedule/cancel deletion, support-access toggle, channel-token refreshapiTokens— full CRUD + rotate, gated behind an unrestricted (all-scopes) token so a token can never mint one broader than itself; the default token ({{api_key}}) is immutableworkspaceMembers— new invite/update/remove write routes alongside the existinglist/gettemplates— full CRUD, share settings, installations, install auto-update toggleauditLogs— enterprise-gated listEvery route:
workspaceIdalways comes from the authenticated token'scontext.workspace.id(never client input), actor fields arenullfor a token caller (no human actor), and responses never serialize secrets (tokenHash,encryptedToken, templatepayload,tenantId).Refactors (clean cutover, no duplicated logic)
refresh-all-channel-tokens.action.tsintochannelTokenRefreshService.refreshWorkspace(packages/business/src/workspace/channel-token-refresh.ts); the builder action now calls the same service.invite-workspace-member.action.tsintoinvitationService.create; the builder action now calls the same service.findByIdForWorkspace/updateByIdForWorkspace/rotateTokenByIdto the workspace-API-token repository, andfindTokenOrFail/updateToken/rotateTokento its service, invalidating the token-auth cache tag on both mutations.Verification
New test coverage:
*-public-scope.test.ts/*-public-api.test.tsfor each ofworkspace,apiTokens,templates,auditLogs, plus extendedworkspace-members-actions.test.ts,workspace-token-scope-registry.test.ts, andworkspace-api-token.service.test.ts. The public-spec snapshot (public-spec-operations.test.ts.snap) is refreshed for the new operations.Not included: invitation acceptance (requires the invitee's browser session) — everything else the builder UI can do in this area is covered.