Skip to content

Commit

Permalink
feat(clerk-js): Introduce Organization.getInvitations and deprecate…
Browse files Browse the repository at this point in the history
… `getPendingInvitations`
  • Loading branch information
panteliselef committed Sep 26, 2023
1 parent 0bb978a commit c61ddf5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/three-carrots-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': patch
'@clerk/types': patch
---

Introduces a new method for fetching organization invitations called `Organization.getInvitations`.
Deprecate `Organization.getPendingInvitations`
25 changes: 25 additions & 0 deletions packages/clerk-js/src/core/resources/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ClerkResourceReloadParams,
CreateOrganizationParams,
GetDomainsParams,
GetInvitationsParams,
GetMembershipRequestParams,
GetMemberships,
GetPendingInvitationsParams,
Expand All @@ -12,6 +13,7 @@ import type {
OrganizationDomainJSON,
OrganizationDomainResource,
OrganizationInvitationJSON,
OrganizationInvitationResource,
OrganizationJSON,
OrganizationMembershipJSON,
OrganizationMembershipRequestJSON,
Expand Down Expand Up @@ -205,6 +207,29 @@ export class Organization extends BaseResource implements OrganizationResource {
.catch(() => []);
};

getInvitations = async (
getInvitationsParams?: GetInvitationsParams,
): Promise<ClerkPaginatedResponse<OrganizationInvitationResource>> => {
return await BaseResource._fetch({
path: `/organizations/${this.id}/invitations`,
method: 'GET',
search: convertPageToOffset(getInvitationsParams) as any,
})
.then(res => {
const { data: requests, total_count } =
res?.response as unknown as ClerkPaginatedResponse<OrganizationInvitationJSON>;

return {
total_count,
data: requests.map(request => new OrganizationInvitation(request)),
};
})
.catch(() => ({
total_count: 0,
data: [],
}));
};

addMember = async ({ userId, role }: AddMemberParams) => {
const newMember = await BaseResource._fetch({
method: 'POST',
Expand Down
20 changes: 20 additions & 0 deletions packages/types/src/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export interface OrganizationResource extends ClerkResource {
updatedAt: Date;
update: (params: UpdateOrganizationParams) => Promise<OrganizationResource>;
getMemberships: GetMemberships;
/**
* @deprecated Use `getInvitations` instead
*/
getPendingInvitations: (params?: GetPendingInvitationsParams) => Promise<OrganizationInvitationResource[]>;
getInvitations: (params?: GetInvitationsParams) => Promise<ClerkPaginatedResponse<OrganizationInvitationResource>>;
getDomains: (params?: GetDomainsParams) => Promise<ClerkPaginatedResponse<OrganizationDomainResource>>;
getMembershipRequests: (
params?: GetMembershipRequestParams,
Expand Down Expand Up @@ -80,6 +84,9 @@ export type GetMembersParams = {
role?: MembershipRole[];
};

/**
* @deprecated use `getInvitations` instead
*/
export type GetPendingInvitationsParams = ClerkPaginationParams;
export type GetDomainsParams = {
/**
Expand All @@ -94,6 +101,19 @@ export type GetDomainsParams = {
enrollmentMode?: OrganizationEnrollmentMode;
};

export type GetInvitationsParams = {
/**
* This is the starting point for your fetched results. The initial value persists between re-renders
*/
initialPage?: number;
/**
* Maximum number of items returned per request. The initial value persists between re-renders
*/
pageSize?: number;

status?: OrganizationInvitationStatus[];
};

export type GetMembershipRequestParams = {
/**
* This is the starting point for your fetched results. The initial value persists between re-renders
Expand Down

0 comments on commit c61ddf5

Please sign in to comment.