-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clerk-js,types): Introduce UserOrganizationInvitation
+ UserOrganizationInvitationResource + UserOrganizationInvitationJSON + ClerkPaginatedResponse that handles FAPI paginated responses
- Loading branch information
1 parent
aad6351
commit 5e1a09d
Showing
9 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Introduces a new internal class `UserOrganizationInvitation` that represents and invitation to join an organization with the organization data populated | ||
Additions to support the above | ||
- UserOrganizationInvitationResource | ||
- UserOrganizationInvitationJSON | ||
- ClerkPaginatedResponse | ||
|
||
ClerkPaginatedResponse represents a paginated FAPI response |
This file contains 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
64 changes: 64 additions & 0 deletions
64
packages/clerk-js/src/core/resources/UserOrganizationInvitation.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { | ||
ClerkPaginatedResponse, | ||
GetUserOrganizationInvitationsParams, | ||
MembershipRole, | ||
OrganizationInvitationStatus, | ||
OrganizationResource, | ||
UserOrganizationInvitationJSON, | ||
UserOrganizationInvitationResource, | ||
} from '@clerk/types'; | ||
|
||
import { unixEpochToDate } from '../../utils/date'; | ||
import { BaseResource, Organization } from './internal'; | ||
|
||
export class UserOrganizationInvitation extends BaseResource implements UserOrganizationInvitationResource { | ||
id!: string; | ||
emailAddress!: string; | ||
organization!: OrganizationResource; | ||
publicMetadata: OrganizationInvitationPublicMetadata = {}; | ||
status!: OrganizationInvitationStatus; | ||
role!: MembershipRole; | ||
createdAt!: Date; | ||
updatedAt!: Date; | ||
|
||
static async retrieve( | ||
params?: GetUserOrganizationInvitationsParams, | ||
): Promise<ClerkPaginatedResponse<UserOrganizationInvitation>> { | ||
return await BaseResource._fetch({ | ||
path: '/me/organization_invitations', | ||
method: 'GET', | ||
search: params as any, | ||
}) | ||
.then(res => { | ||
const { data: invites, total_count } = | ||
res?.response as unknown as ClerkPaginatedResponse<UserOrganizationInvitationJSON>; | ||
|
||
return { | ||
total_count, | ||
data: invites.map(invitation => new UserOrganizationInvitation(invitation)), | ||
}; | ||
}) | ||
.catch(() => ({ | ||
total_count: 0, | ||
data: [], | ||
})); | ||
} | ||
|
||
constructor(data: UserOrganizationInvitationJSON) { | ||
super(); | ||
this.fromJSON(data); | ||
} | ||
protected fromJSON(data: UserOrganizationInvitationJSON | null): this { | ||
if (data) { | ||
this.id = data.id; | ||
this.emailAddress = data.email_address; | ||
this.organization = new Organization(data.organization); | ||
this.publicMetadata = data.public_metadata; | ||
this.role = data.role; | ||
this.status = data.status; | ||
this.createdAt = unixEpochToDate(data.created_at); | ||
this.updatedAt = unixEpochToDate(data.updated_at); | ||
} | ||
return this; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { OrganizationResource } from './organization'; | ||
import type { OrganizationInvitationStatus } from './organizationInvitation'; | ||
import type { MembershipRole } from './organizationMembership'; | ||
import type { ClerkResource } from './resource'; | ||
|
||
declare global { | ||
/** | ||
* If you want to provide custom types for the organizationInvitation.publicMetadata | ||
* object, simply redeclare this rule in the global namespace. | ||
* Every organizationInvitation object will use the provided type. | ||
*/ | ||
interface UserOrganizationInvitationPublicMetadata { | ||
[k: string]: unknown; | ||
} | ||
|
||
interface UserOrganizationInvitationPrivateMetadata { | ||
[k: string]: unknown; | ||
} | ||
} | ||
|
||
export interface UserOrganizationInvitationResource extends ClerkResource { | ||
id: string; | ||
emailAddress: string; | ||
organization: OrganizationResource; | ||
publicMetadata: UserOrganizationInvitationPublicMetadata; | ||
role: MembershipRole; | ||
status: OrganizationInvitationStatus; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} |