Skip to content

feat(backend): Add Backend API calls for organization perms, roles#8774

Merged
wobsoriano merged 1 commit into
mainfrom
daniel/feat-backend-add-orgs-endpoints
Jun 8, 2026
Merged

feat(backend): Add Backend API calls for organization perms, roles#8774
wobsoriano merged 1 commit into
mainfrom
daniel/feat-backend-add-orgs-endpoints

Conversation

@dmoerner
Copy link
Copy Markdown
Contributor

@dmoerner dmoerner commented Jun 8, 2026

Description

Add Backend API support for managing instance-level organization RBAC. createClerkClient() now exposes:

  • organizationPermissions — list, get, create, update, and delete organization permissions.
  • organizationRoles — list, get, create, update, and delete organization roles, plus assign/remove a permission to/from a role.
  • roleSets — list, get, create, update, add roles to, replace a role in, and replace a role set.

This was a request from Plain.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

Release Notes

  • New Features
    • Backend API now exposes comprehensive role-based access control (RBAC) management. Create and manage organization permissions, configure roles with granular permission assignments, organize roles into role sets, add or remove permissions from roles, and handle all role set operations through dedicated API endpoints for complete access control administration.

…le sets

Add Backend API support for managing instance-level organization RBAC. `createClerkClient()` now exposes:

- `organizationPermissions` — list, get, create, update, and delete organization permissions.
- `organizationRoles` — list, get, create, update, and delete organization roles, plus assign/remove a permission to/from a role.
- `roleSets` — list, get, create, update, add roles to, replace a role in, and replace a role set.
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jun 8, 2026 12:13pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 8, 2026

🦋 Changeset detected

Latest commit: 2554467

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@clerk/backend Minor
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 8, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds backend API support for managing instance-level organization RBAC. It introduces resource models for permissions, roles, and role sets; three new endpoint client classes with full CRUD operations; comprehensive test coverage for all endpoints; and factory integration to expose these managers via createClerkClient().

Changes

Organization RBAC Backend API Support

Layer / File(s) Summary
Domain resource models
packages/backend/src/api/resources/Permission.ts, packages/backend/src/api/resources/Role.ts, packages/backend/src/api/resources/RoleSet.ts, packages/backend/src/api/resources/JSON.ts, packages/backend/src/api/resources/index.ts
Permission, Role, RoleSet, RoleSetItem, and RoleSetMigration classes with fromJSON factories map API payloads to domain objects. Role.description becomes nullable. Resources are re-exported from the module barrel.
Organization Permission API client
packages/backend/src/api/endpoints/OrganizationPermissionApi.ts, packages/backend/src/api/__tests__/OrganizationPermissionApi.test.ts
OrganizationPermissionAPI endpoint client provides list/get/create/update/delete operations for permissions with paginated and typed responses. Tests validate request parameters, JSON bodies, and response shapes.
Organization Role API client
packages/backend/src/api/endpoints/OrganizationRoleApi.ts, packages/backend/src/api/__tests__/OrganizationRoleApi.test.ts
OrganizationRoleAPI endpoint client provides CRUD for roles plus assign/remove permission operations on specific roles. Tests cover all seven operation flows with request/response validation.
Role Set API client
packages/backend/src/api/endpoints/RoleSetApi.ts, packages/backend/src/api/__tests__/RoleSetApi.test.ts
RoleSetAPI endpoint client provides list/get/create/update, add roles to, replace role, and replace entire role set operations. Tests validate seven scenarios including pagination, role replacement, and role set replacement flows.
Client factory and deserialization
packages/backend/src/api/factory.ts, packages/backend/src/api/endpoints/index.ts, packages/backend/src/api/resources/Deserializer.ts
Backend API factory exposes organizationPermissions, organizationRoles, and roleSets managers; endpoint barrel re-exports new API classes; deserializer recognizes Permission, Role, and RoleSet resource types.
Release notes
.changeset/orgs-rbac-backend-endpoints.md
Changeset entry documents new RBAC managers available via createClerkClient().

🐰 Three new APIs hop into the backend,
Permissions, roles, and role sets connect,
RBAC is ready to manage with flair,
Organizations bloom everywhere!

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title directly and accurately summarizes the main change: adding backend API support for organization permissions and roles management via the Clerk client.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 8, 2026

Break Check: no API changes detected across the tracked packages.

Last ran on 2554467. Pushes that change no tracked declarations (no API surface change vs. base) are skipped and don't update this comment.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 8, 2026

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8774

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8774

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8774

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8774

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8774

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8774

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8774

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8774

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8774

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8774

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8774

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8774

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8774

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8774

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8774

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8774

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8774

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8774

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8774

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8774

commit: 2554467

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (9)
packages/backend/src/api/endpoints/OrganizationRoleApi.ts (1)

76-136: ⚡ Quick win

Add explicit return types for the public OrganizationRoleAPI methods.

Please annotate all public methods with explicit Promise<...> return types instead of relying on inference.

As per coding guidelines, “Always define explicit return types for functions, especially public APIs.” Based on learnings, this repo expects explicit return types on exported/public TS APIs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/endpoints/OrganizationRoleApi.ts` around lines 76 -
136, Add explicit Promise return types to all public methods on
OrganizationRoleApi: annotate getOrganizationRoleList, getOrganizationRole,
createOrganizationRole, updateOrganizationRole, deleteOrganizationRole,
assignPermissionToOrganizationRole, and removePermissionFromOrganizationRole
with their proper Promise<T> signatures (e.g.,
Promise<PaginatedResourceResponse<Role[]>> for getOrganizationRoleList,
Promise<Role> for single Role responses, Promise<DeletedObject> for delete).
Update the method declarations to return Promise<...> instead of relying on type
inference so the public API has explicit return types.

Sources: Coding guidelines, Learnings

packages/backend/src/api/endpoints/OrganizationPermissionApi.ts (1)

46-86: ⚡ Quick win

Add explicit return types to all public endpoint methods.

These exported API methods currently depend on inference. Please annotate each public method with its Promise<...> return type to keep the SDK contract explicit.

Suggested patch
 export class OrganizationPermissionAPI extends AbstractAPI {
-  public async getOrganizationPermissionList(params: GetOrganizationPermissionListParams = {}) {
+  public async getOrganizationPermissionList(
+    params: GetOrganizationPermissionListParams = {},
+  ): Promise<PaginatedResourceResponse<Permission[]>> {
@@
-  public async getOrganizationPermission(permissionId: string) {
+  public async getOrganizationPermission(permissionId: string): Promise<Permission> {
@@
-  public async createOrganizationPermission(params: CreateOrganizationPermissionParams) {
+  public async createOrganizationPermission(params: CreateOrganizationPermissionParams): Promise<Permission> {
@@
-  public async updateOrganizationPermission(params: UpdateOrganizationPermissionParams) {
+  public async updateOrganizationPermission(params: UpdateOrganizationPermissionParams): Promise<Permission> {
@@
-  public async deleteOrganizationPermission(permissionId: string) {
+  public async deleteOrganizationPermission(permissionId: string): Promise<DeletedObject> {

As per coding guidelines, “Always define explicit return types for functions, especially public APIs.” Based on learnings, explicit return annotations are expected for exported/public TypeScript APIs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/endpoints/OrganizationPermissionApi.ts` around lines
46 - 86, Public methods in OrganizationPermissionApi
(getOrganizationPermissionList, getOrganizationPermission,
createOrganizationPermission, updateOrganizationPermission,
deleteOrganizationPermission) lack explicit return type annotations; update each
method signature to declare the Promise return type that matches the request
generic (e.g., getOrganizationPermissionList():
Promise<PaginatedResourceResponse<Permission[]>>) so the SDK contract is
explicit, keeping method bodies unchanged and ensuring types align with the
this.request<...> generic used in each implementation.

Sources: Coding guidelines, Learnings

packages/backend/src/api/endpoints/RoleSetApi.ts (1)

132-194: ⚡ Quick win

Add explicit return types for the public RoleSetAPI methods.

These public SDK methods should use explicit Promise<...> return annotations for a stable, explicit API contract.

As per coding guidelines, “Always define explicit return types for functions, especially public APIs.” Based on learnings, explicit return typing is required for exported/public TS methods.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/endpoints/RoleSetApi.ts` around lines 132 - 194, The
public RoleSetApi methods lack explicit Promise return types; update each method
signature to declare its explicit Promise<...> return type: getRoleSetList
should return Promise<PaginatedResourceResponse<RoleSet[]>>,
getRoleSet/createRoleSet/updateRoleSet/addRolesToRoleSet/replaceRoleInRoleSet
should return Promise<RoleSet>, and replaceRoleSet should return
Promise<DeletedObject>; adjust the signatures for getRoleSetList, getRoleSet,
createRoleSet, updateRoleSet, addRolesToRoleSet, replaceRoleInRoleSet, and
replaceRoleSet to include these explicit Promise return annotations.

Sources: Coding guidelines, Learnings

packages/backend/src/api/endpoints/index.ts (1)

21-27: 🏗️ Heavy lift

Don’t grow index.ts barrels unless explicitly exempted.

These additions increase coupling risk in a disallowed pattern; prefer explicit module entry points or document an exception for this file.

As per coding guidelines, "**/index.ts: Avoid barrel files (index.ts re-exports) as they can cause circular dependencies."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/endpoints/index.ts` around lines 21 - 27, This
index.ts barrel is adding many re-exports (OrganizationPermissionApi,
OrganizationRoleApi, OAuthApplicationsApi, PhoneNumberApi, ProxyCheckApi,
RedirectUrlApi, RoleSetApi) which violates the no-barrel rule; remove these
export lines from index.ts and update consumers to import directly from each
module's explicit path (e.g., import from './OrganizationPermissionApi' etc.),
or if this file must remain a barrel for a validated reason, add a clear
exemption comment at the top of index.ts referencing the exception and ensure
reviewers approve it.

Source: Coding guidelines

packages/backend/src/api/__tests__/OrganizationRoleApi.test.ts (1)

43-166: ⚡ Quick win

Expand role API tests to include validation/error paths.

Please add edge-case tests for invalid IDs and failed backend responses, including assign/remove permission flows.

As per coding guidelines, "**/*.{test,spec}.{ts,tsx}: ... Verify proper error handling and edge cases."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/__tests__/OrganizationRoleApi.test.ts` around lines
43 - 166, Add unit tests in OrganizationRoleApi.test.ts to cover error/edge
cases: for getOrganizationRole (organizationRoles.getOrganizationRole),
updateOrganizationRole (organizationRoles.updateOrganizationRole),
deleteOrganizationRole (organizationRoles.deleteOrganizationRole),
assignPermissionToOrganizationRole
(organizationRoles.assignPermissionToOrganizationRole) and
removePermissionFromOrganizationRole
(organizationRoles.removePermissionFromOrganizationRole) add cases that assert
proper handling when the backend returns 4xx/5xx (mock server returning error
responses) and when invalid IDs (e.g., empty string or malformed id) are passed;
for createOrganizationRole also add a validation error case. Use server.use with
http.<method> for the failing responses and expect the API client to throw or
return the appropriate error shape/exception so tests assert that error
propagation/validation behavior matches guidelines.

Source: Coding guidelines

packages/backend/src/api/__tests__/OrganizationPermissionApi.test.ts (1)

30-127: ⚡ Quick win

Add negative-path coverage for permission endpoints.

Please add tests for error handling/edge cases (e.g., invalid/empty IDs and non-2xx responses) so these methods are covered beyond happy paths.

As per coding guidelines, "**/*.{test,spec}.{ts,tsx}: Unit tests are required for all new functionality ... Verify proper error handling and edge cases."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/__tests__/OrganizationPermissionApi.test.ts` around
lines 30 - 127, Add negative-path unit tests in
packages/backend/src/api/__tests__/OrganizationPermissionApi.test.ts to cover
error handling for organizationPermissions methods:
getOrganizationPermissionList, getOrganizationPermission,
createOrganizationPermission, updateOrganizationPermission, and
deleteOrganizationPermission. For each method add cases that simulate non-2xx
HTTP responses (e.g., 400/404/500 via server.use with HttpResponse.json or
HttpResponse.text and appropriate status) and assertions that the API client
throws or returns the expected error shape; also add edge-case tests for
invalid/empty IDs (call
getOrganizationPermission/updateOrganizationPermission/deleteOrganizationPermission
with '' or null and assert validation error or thrown exception) and for
create/update with invalid payloads to assert proper error propagation. Ensure
each new test mirrors the existing test style (using validateHeaders/http
helpers) and asserts on the thrown error or returned error properties so
negative flows are covered.

Source: Coding guidelines

packages/backend/src/api/factory.ts (1)

46-120: 🏗️ Heavy lift

Add an explicit return type for createBackendApiClient.

This exported public API currently relies on inference; define and annotate a named return type/interface to lock the contract.

As per coding guidelines, "**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/factory.ts` around lines 46 - 120, Add an explicit
exported return type for createBackendApiClient: declare and export an interface
(e.g. BackendApiClient) that lists the public members returned (use the exact
symbols from the factory such as __experimental_accountlessApplications:
AccountlessApplicationAPI, actorTokens: ActorTokenAPI, agentTasks: AgentTaskAPI,
apiKeys: APIKeysAPI, m2m: M2MTokenApi, samlConnections: SamlConnectionAPI,
etc.), then annotate the function signature as createBackendApiClient(options:
CreateBackendApiOptions): BackendApiClient. Keep the interface members' types
aligned with the existing classes/constructors used in the return object so the
public contract is locked and the function no longer relies on type inference.

Source: Coding guidelines

packages/backend/src/api/resources/index.ts (1)

52-57: 🏗️ Heavy lift

Avoid expanding index.ts barrel exports without an explicit exception.

These new re-exports add more surface to a barrel file; prefer concrete module exports/imports (or document a scoped exception if this barrel is intentionally allowed).

As per coding guidelines, "**/index.ts: Avoid barrel files (index.ts re-exports) as they can cause circular dependencies."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/resources/index.ts` around lines 52 - 57, The
index.ts barrel export was expanded to re-export Permission, PhoneNumber,
ProxyCheck, RedirectUrl, Role, and RoleSet which violates the "avoid barrel
files" guideline; revert those re-exports and instead import the specific
modules where needed (or, if this barrel is intentionally allowed, add a
documented, scoped exception comment above the exports explaining why these
resources must be re-exported). Locate the index.ts barrel (the file that
currently exports Permission, PhoneNumber, ProxyCheck, RedirectUrl, Role,
RoleSet) and either remove those export lines and use direct imports in callers,
or add a clear comment and update project documentation to justify keeping them.

Source: Coding guidelines

packages/backend/src/api/__tests__/RoleSetApi.test.ts (1)

67-191: ⚡ Quick win

Complete RoleSet coverage for ID variant and failure paths.

The “key or ID” contract should be tested for an ID input too, and this suite should also include error/edge-case assertions (invalid IDs, failed responses).

As per coding guidelines, "**/*.{test,spec}.{ts,tsx}: Unit tests are required for all new functionality ... Verify proper error handling and edge cases."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/__tests__/RoleSetApi.test.ts` around lines 67 - 191,
Tests currently only exercise roleSets.getRoleSet using the key variant and lack
negative/ID-path coverage; add unit tests in RoleSetApi.test.ts that call
roleSets.getRoleSet with roleSetId (the numeric/ID variant) and assert the same
fields as the key test, plus add tests simulating error responses via server.use
(e.g., return 404 and 500 HttpResponse) to assert the client throws or returns
the expected error shape, and add an invalid-ID input test (call
roleSets.getRoleSet with a malformed id and expect validation/error) so both
success-by-ID and failure/edge cases for getRoleSet (and similarly for other
methods if desired) are covered; use the existing helpers (server.use,
HttpResponse.json, validateHeaders) and reference roleSets.getRoleSet,
roleSets.createRoleSet, roleSets.updateRoleSet, roleSets.addRolesToRoleSet,
roleSets.replaceRoleInRoleSet, and roleSets.replaceRoleSet to locate where to
add these tests.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/backend/src/api/factory.ts`:
- Around line 101-106: Add clear JSDoc comments for the new public client
members organizationPermissions, organizationRoles, and roleSets in the API
factory (the variables OrganizationPermissionAPI, OrganizationRoleAPI,
RoleSetAPI) describing their purpose, public usage surface, and any return types
or important behaviors; ensure the JSDoc style matches existing entries for
phoneNumbers, proxyChecks, and redirectUrls so generated docs remain consistent,
then mark the change for Docs-team review so reference documentation in
clerk/javascript can be updated if necessary.

---

Nitpick comments:
In `@packages/backend/src/api/__tests__/OrganizationPermissionApi.test.ts`:
- Around line 30-127: Add negative-path unit tests in
packages/backend/src/api/__tests__/OrganizationPermissionApi.test.ts to cover
error handling for organizationPermissions methods:
getOrganizationPermissionList, getOrganizationPermission,
createOrganizationPermission, updateOrganizationPermission, and
deleteOrganizationPermission. For each method add cases that simulate non-2xx
HTTP responses (e.g., 400/404/500 via server.use with HttpResponse.json or
HttpResponse.text and appropriate status) and assertions that the API client
throws or returns the expected error shape; also add edge-case tests for
invalid/empty IDs (call
getOrganizationPermission/updateOrganizationPermission/deleteOrganizationPermission
with '' or null and assert validation error or thrown exception) and for
create/update with invalid payloads to assert proper error propagation. Ensure
each new test mirrors the existing test style (using validateHeaders/http
helpers) and asserts on the thrown error or returned error properties so
negative flows are covered.

In `@packages/backend/src/api/__tests__/OrganizationRoleApi.test.ts`:
- Around line 43-166: Add unit tests in OrganizationRoleApi.test.ts to cover
error/edge cases: for getOrganizationRole
(organizationRoles.getOrganizationRole), updateOrganizationRole
(organizationRoles.updateOrganizationRole), deleteOrganizationRole
(organizationRoles.deleteOrganizationRole), assignPermissionToOrganizationRole
(organizationRoles.assignPermissionToOrganizationRole) and
removePermissionFromOrganizationRole
(organizationRoles.removePermissionFromOrganizationRole) add cases that assert
proper handling when the backend returns 4xx/5xx (mock server returning error
responses) and when invalid IDs (e.g., empty string or malformed id) are passed;
for createOrganizationRole also add a validation error case. Use server.use with
http.<method> for the failing responses and expect the API client to throw or
return the appropriate error shape/exception so tests assert that error
propagation/validation behavior matches guidelines.

In `@packages/backend/src/api/__tests__/RoleSetApi.test.ts`:
- Around line 67-191: Tests currently only exercise roleSets.getRoleSet using
the key variant and lack negative/ID-path coverage; add unit tests in
RoleSetApi.test.ts that call roleSets.getRoleSet with roleSetId (the numeric/ID
variant) and assert the same fields as the key test, plus add tests simulating
error responses via server.use (e.g., return 404 and 500 HttpResponse) to assert
the client throws or returns the expected error shape, and add an invalid-ID
input test (call roleSets.getRoleSet with a malformed id and expect
validation/error) so both success-by-ID and failure/edge cases for getRoleSet
(and similarly for other methods if desired) are covered; use the existing
helpers (server.use, HttpResponse.json, validateHeaders) and reference
roleSets.getRoleSet, roleSets.createRoleSet, roleSets.updateRoleSet,
roleSets.addRolesToRoleSet, roleSets.replaceRoleInRoleSet, and
roleSets.replaceRoleSet to locate where to add these tests.

In `@packages/backend/src/api/endpoints/index.ts`:
- Around line 21-27: This index.ts barrel is adding many re-exports
(OrganizationPermissionApi, OrganizationRoleApi, OAuthApplicationsApi,
PhoneNumberApi, ProxyCheckApi, RedirectUrlApi, RoleSetApi) which violates the
no-barrel rule; remove these export lines from index.ts and update consumers to
import directly from each module's explicit path (e.g., import from
'./OrganizationPermissionApi' etc.), or if this file must remain a barrel for a
validated reason, add a clear exemption comment at the top of index.ts
referencing the exception and ensure reviewers approve it.

In `@packages/backend/src/api/endpoints/OrganizationPermissionApi.ts`:
- Around line 46-86: Public methods in OrganizationPermissionApi
(getOrganizationPermissionList, getOrganizationPermission,
createOrganizationPermission, updateOrganizationPermission,
deleteOrganizationPermission) lack explicit return type annotations; update each
method signature to declare the Promise return type that matches the request
generic (e.g., getOrganizationPermissionList():
Promise<PaginatedResourceResponse<Permission[]>>) so the SDK contract is
explicit, keeping method bodies unchanged and ensuring types align with the
this.request<...> generic used in each implementation.

In `@packages/backend/src/api/endpoints/OrganizationRoleApi.ts`:
- Around line 76-136: Add explicit Promise return types to all public methods on
OrganizationRoleApi: annotate getOrganizationRoleList, getOrganizationRole,
createOrganizationRole, updateOrganizationRole, deleteOrganizationRole,
assignPermissionToOrganizationRole, and removePermissionFromOrganizationRole
with their proper Promise<T> signatures (e.g.,
Promise<PaginatedResourceResponse<Role[]>> for getOrganizationRoleList,
Promise<Role> for single Role responses, Promise<DeletedObject> for delete).
Update the method declarations to return Promise<...> instead of relying on type
inference so the public API has explicit return types.

In `@packages/backend/src/api/endpoints/RoleSetApi.ts`:
- Around line 132-194: The public RoleSetApi methods lack explicit Promise
return types; update each method signature to declare its explicit Promise<...>
return type: getRoleSetList should return
Promise<PaginatedResourceResponse<RoleSet[]>>,
getRoleSet/createRoleSet/updateRoleSet/addRolesToRoleSet/replaceRoleInRoleSet
should return Promise<RoleSet>, and replaceRoleSet should return
Promise<DeletedObject>; adjust the signatures for getRoleSetList, getRoleSet,
createRoleSet, updateRoleSet, addRolesToRoleSet, replaceRoleInRoleSet, and
replaceRoleSet to include these explicit Promise return annotations.

In `@packages/backend/src/api/factory.ts`:
- Around line 46-120: Add an explicit exported return type for
createBackendApiClient: declare and export an interface (e.g. BackendApiClient)
that lists the public members returned (use the exact symbols from the factory
such as __experimental_accountlessApplications: AccountlessApplicationAPI,
actorTokens: ActorTokenAPI, agentTasks: AgentTaskAPI, apiKeys: APIKeysAPI, m2m:
M2MTokenApi, samlConnections: SamlConnectionAPI, etc.), then annotate the
function signature as createBackendApiClient(options: CreateBackendApiOptions):
BackendApiClient. Keep the interface members' types aligned with the existing
classes/constructors used in the return object so the public contract is locked
and the function no longer relies on type inference.

In `@packages/backend/src/api/resources/index.ts`:
- Around line 52-57: The index.ts barrel export was expanded to re-export
Permission, PhoneNumber, ProxyCheck, RedirectUrl, Role, and RoleSet which
violates the "avoid barrel files" guideline; revert those re-exports and instead
import the specific modules where needed (or, if this barrel is intentionally
allowed, add a documented, scoped exception comment above the exports explaining
why these resources must be re-exported). Locate the index.ts barrel (the file
that currently exports Permission, PhoneNumber, ProxyCheck, RedirectUrl, Role,
RoleSet) and either remove those export lines and use direct imports in callers,
or add a clear comment and update project documentation to justify keeping them.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 24124557-ba10-4117-9d0f-79d513879419

📥 Commits

Reviewing files that changed from the base of the PR and between 565a516 and 2554467.

📒 Files selected for processing (15)
  • .changeset/orgs-rbac-backend-endpoints.md
  • packages/backend/src/api/__tests__/OrganizationPermissionApi.test.ts
  • packages/backend/src/api/__tests__/OrganizationRoleApi.test.ts
  • packages/backend/src/api/__tests__/RoleSetApi.test.ts
  • packages/backend/src/api/endpoints/OrganizationPermissionApi.ts
  • packages/backend/src/api/endpoints/OrganizationRoleApi.ts
  • packages/backend/src/api/endpoints/RoleSetApi.ts
  • packages/backend/src/api/endpoints/index.ts
  • packages/backend/src/api/factory.ts
  • packages/backend/src/api/resources/Deserializer.ts
  • packages/backend/src/api/resources/JSON.ts
  • packages/backend/src/api/resources/Permission.ts
  • packages/backend/src/api/resources/Role.ts
  • packages/backend/src/api/resources/RoleSet.ts
  • packages/backend/src/api/resources/index.ts

Comment on lines +101 to +106
organizationPermissions: new OrganizationPermissionAPI(request),
organizationRoles: new OrganizationRoleAPI(request),
phoneNumbers: new PhoneNumberAPI(request),
proxyChecks: new ProxyCheckAPI(request),
redirectUrls: new RedirectUrlAPI(request),
roleSets: new RoleSetAPI(request),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Document the new public client members for generated docs.

organizationPermissions, organizationRoles, and roleSets expand public/reference-facing API surface. Please add/align JSDoc for these additions and flag for Docs-team review if this impacts generated reference pages.

As per coding guidelines, "Clerk Docs generates reference documentation from JSDoc in clerk/javascript; public/reference-facing API changes should have accurate JSDoc and may need Docs-team review."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/backend/src/api/factory.ts` around lines 101 - 106, Add clear JSDoc
comments for the new public client members organizationPermissions,
organizationRoles, and roleSets in the API factory (the variables
OrganizationPermissionAPI, OrganizationRoleAPI, RoleSetAPI) describing their
purpose, public usage surface, and any return types or important behaviors;
ensure the JSDoc style matches existing entries for phoneNumbers, proxyChecks,
and redirectUrls so generated docs remain consistent, then mark the change for
Docs-team review so reference documentation in clerk/javascript can be updated
if necessary.

Source: Coding guidelines

@dmoerner dmoerner changed the title feat(backend): Add Bckend API calls for organization perms, roles feat(backend): Add Backend API calls for organization perms, roles Jun 8, 2026
@SergeyVolynkin
Copy link
Copy Markdown

Thank you @dmoerner !

@wobsoriano wobsoriano self-requested a review June 8, 2026 15:19
Copy link
Copy Markdown
Member

@wobsoriano wobsoriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍🏼 thanks for adding

@wobsoriano wobsoriano merged commit 955e998 into main Jun 8, 2026
50 checks passed
@wobsoriano wobsoriano deleted the daniel/feat-backend-add-orgs-endpoints branch June 8, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants