Skip to content

Commit d3280cd

Browse files
author
Giannis Katsanos
authored
Merge pull request #486 from clerkinc/org-invitation-metadata
feat(clerk-js,types): Organization invitation metadata
2 parents fc06ec7 + 87764b8 commit d3280cd

6 files changed

Lines changed: 26 additions & 2 deletions

File tree

packages/clerk-js/src/core/resources/OrganizationInvitation.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ describe('OrganizationInvitation', () => {
77
email_address: 'test_email',
88
id: 'test_id',
99
organization_id: 'test_organization_id',
10+
public_metadata: {
11+
public: 'metadata',
12+
},
1013
role: 'basic_member',
1114
created_at: 12345,
1215
updated_at: 5678,

packages/clerk-js/src/core/resources/OrganizationInvitation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ export class OrganizationInvitation extends BaseResource implements Organization
1212
id!: string;
1313
emailAddress!: string;
1414
organizationId!: string;
15+
publicMetadata: Record<string, unknown> = {};
1516
status!: OrganizationInvitationStatus;
1617
role!: MembershipRole;
1718
createdAt!: Date;
1819
updatedAt!: Date;
1920

2021
static async create(
2122
organizationId: string,
22-
{ emailAddress, role, redirectUrl }: CreateOrganizationInvitationParams,
23+
{ emailAddress, role, redirectUrl, publicMetadata }: CreateOrganizationInvitationParams,
2324
): Promise<OrganizationInvitationResource> {
2425
const json = (
2526
await BaseResource._fetch<OrganizationInvitationJSON>({
@@ -29,6 +30,7 @@ export class OrganizationInvitation extends BaseResource implements Organization
2930
email_address: emailAddress,
3031
role,
3132
redirect_url: redirectUrl,
33+
public_metadata: JSON.stringify(publicMetadata),
3234
} as any,
3335
})
3436
)?.response as unknown as OrganizationInvitationJSON;
@@ -55,6 +57,7 @@ export class OrganizationInvitation extends BaseResource implements Organization
5557
this.id = data.id;
5658
this.emailAddress = data.email_address;
5759
this.organizationId = data.organization_id;
60+
this.publicMetadata = data.public_metadata;
5861
this.role = data.role;
5962
this.status = data.status;
6063
this.createdAt = unixEpochToDate(data.created_at);
@@ -67,4 +70,5 @@ export type CreateOrganizationInvitationParams = {
6770
emailAddress: string;
6871
role: MembershipRole;
6972
redirectUrl?: string;
73+
publicMetadata?: Record<string, unknown>;
7074
};

packages/clerk-js/src/core/resources/__snapshots__/OrganizationInvitation.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ OrganizationInvitation {
77
"id": "test_id",
88
"organizationId": "test_organization_id",
99
"pathRoot": "",
10+
"publicMetadata": Object {
11+
"public": "metadata",
12+
},
1013
"revoke": [Function],
1114
"role": "basic_member",
1215
"status": "pending",

packages/types/src/json.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ export interface OrganizationMembershipJSON extends ClerkResourceJSON {
275275
export interface OrganizationInvitationJSON extends ClerkResourceJSON {
276276
object: 'organization_invitation';
277277
id: string;
278-
organization_id: string;
279278
email_address: string;
279+
organization_id: string;
280+
public_metadata: Record<string, unknown>;
280281
status: OrganizationInvitationStatus;
281282
role: MembershipRole;
282283
created_at: number;

packages/types/src/organization.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface AddMemberParams {
4545
export interface InviteMemberParams {
4646
emailAddress: string;
4747
role: MembershipRole;
48+
publicMetadata?: Record<string, unknown>;
4849
redirectUrl?: string;
4950
}
5051

packages/types/src/organizationInvitation.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import { MembershipRole } from './organizationMembership';
22

3+
declare global {
4+
/**
5+
* If you want to provide custom types for the organizationInvitation.publicMetadata
6+
* object, simply redeclare this rule in the global namespace.
7+
* Every organizationInvitation object will use the provided type.
8+
*/
9+
interface OrganizationInvitationPublicMetadata {
10+
[k: string]: unknown;
11+
}
12+
}
13+
314
export interface OrganizationInvitationResource {
415
id: string;
516
emailAddress: string;
617
organizationId: string;
18+
publicMetadata: OrganizationInvitationPublicMetadata;
719
role: MembershipRole;
820
status: OrganizationInvitationStatus;
921
createdAt: Date;

0 commit comments

Comments
 (0)