diff --git a/.changeset/thick-rings-complain.md b/.changeset/thick-rings-complain.md new file mode 100644 index 00000000000..8e396729859 --- /dev/null +++ b/.changeset/thick-rings-complain.md @@ -0,0 +1,5 @@ +--- +'@clerk/backend': minor +--- + +Introduce a new getOrganizationInvitationList() method, along with support for filtering by status and the regular limit & offset parameters, which it can be used in order to list the invitations of a specific organization. We also marked the old getPendingOrganizationInvitationList() method as deprecated diff --git a/packages/backend/src/api/endpoints/OrganizationApi.ts b/packages/backend/src/api/endpoints/OrganizationApi.ts index 906bb35a973..5113fa3a638 100644 --- a/packages/backend/src/api/endpoints/OrganizationApi.ts +++ b/packages/backend/src/api/endpoints/OrganizationApi.ts @@ -1,8 +1,14 @@ import runtime from '../../runtime'; import { joinPaths } from '../../util/path'; -import type { Organization, OrganizationInvitation, OrganizationMembership } from '../resources'; +import type { + Organization, + OrganizationInvitation, + OrganizationInvitationStatus, + OrganizationMembership, +} from '../resources'; import type { OrganizationMembershipRole } from '../resources/Enums'; import { AbstractAPI } from './AbstractApi'; +import { deprecated } from '@clerk/shared'; const basePath = '/organizations'; @@ -74,6 +80,13 @@ type CreateOrganizationInvitationParams = { publicMetadata?: OrganizationInvitationPublicMetadata; }; +type GetOrganizationInvitationListParams = { + organizationId: string; + status?: OrganizationInvitationStatus[]; + limit?: number; + offset?: number; +}; + type GetPendingOrganizationInvitationListParams = { organizationId: string; limit?: number; @@ -228,7 +241,23 @@ export class OrganizationAPI extends AbstractAPI { }); } + public async getOrganizationInvitationList(params: GetOrganizationInvitationListParams) { + const { organizationId, status, limit, offset } = params; + this.requireId(organizationId); + + return this.request({ + method: 'GET', + path: joinPaths(basePath, organizationId, 'invitations'), + queryParams: { status, limit, offset }, + }); + } + + /** + * @deprecated Use `getOrganizationInvitationList` instead along with the status parameter. + */ public async getPendingOrganizationInvitationList(params: GetPendingOrganizationInvitationListParams) { + deprecated('getPendingOrganizationInvitationList', 'Use `getOrganizationInvitationList` instead.'); + const { organizationId, limit, offset } = params; this.requireId(organizationId);