fix(backend): correct createOrganizationInvitationBulk return type to PaginatedResourceResponse#8751
Conversation
… PaginatedResourceResponse
The Backend API returns bulk-created organization invitations in a { data, total_count } envelope (the same shape as getOrganizationInvitationList), but the method was typed as OrganizationInvitation[]. Align the return type with PaginatedResourceResponse<OrganizationInvitation[]> and add a regression test.
Fixes clerk#8740
|
@VihAMBR is attempting to deploy a commit to the Clerk Production Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: e767fa2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
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 |
📝 WalkthroughWalkthroughThe PR fixes a type mismatch in Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
Fixes #8740
clerkClient.organizations.createOrganizationInvitationBulk()is typed as returningPromise<OrganizationInvitation[]>, but the Backend API endpoint it wraps returns a paginated{ data, total_count }envelope. The request goes through the same deserializer as every other list endpoint, so at runtime the method already resolves to{ data, totalCount }— only the type was wrong, which made the declared type impossible to use correctly.This aligns the return type with
PaginatedResourceResponse<OrganizationInvitation[]>, matching the siblinggetOrganizationInvitationList()method directly above it.Verification of the API shape — confirmed against the Backend API OpenAPI spec rather than assuming. The
CreateOrganizationInvitationBulkoperation's200response references theOrganizationInvitationscomponent, which is:(Note: this is intentionally different from the instance-level
invitations.createInvitationBulk(), whose response is a bare array — see #7702 — which is why the two bulk methods have different return types.)This is consistent with the prior return-type corrections shipped as patches, e.g.
getOrganizationMembershipList()(#2681) andJwtTemplatesApi.list(#7868).Note on impact
The runtime value is unchanged; this only corrects the static type. It is technically a type-level breaking change for anyone who wrote code against the old (non-functional)
OrganizationInvitation[]type — but since that type never matched the value returned at runtime, such code could not have worked. Consumers now access the invitations via.dataand the count via.totalCount, the same as the sibling list methods.How to test
A unit test was added at
packages/backend/src/api/__tests__/OrganizationApi.test.tsthat:{ data, total_count }payload,{ data, totalCount }, andexpectTypeOf) the return type equalsPaginatedResourceResponse<OrganizationInvitation[]>(this assertion fails type-check without the fix).Full
pnpm testfor@clerk/backendpasses across all three environments (node, edge-runtime, miniflare) andpnpm buildsucceeds.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change