Skip to content

Commit 9ba9795

Browse files
authored
Add ability to resend invitation (#1387)
Toward AUTH-5512. ## Description This adds support for the new resend invitation endpoint. It can be used like this: ```js await workos.userManagement.resendInvitation( 'invitation_01E4ZCR3C56J083X43JQXF3JK5', ); ``` ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [x] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required. workos/workos#47145
1 parent ee7d609 commit 9ba9795

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/user-management/user-management.spec.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,85 @@ describe('UserManagement', () => {
21282128
});
21292129
});
21302130

2131+
describe('resendInvitation', () => {
2132+
it('send a Resend Invitation request', async () => {
2133+
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
2134+
fetchOnce(invitationFixture);
2135+
2136+
const response = await workos.userManagement.resendInvitation(
2137+
invitationId,
2138+
);
2139+
2140+
expect(fetchURL()).toContain(
2141+
`/user_management/invitations/${invitationId}/resend`,
2142+
);
2143+
expect(response).toMatchObject({
2144+
object: 'invitation',
2145+
2146+
});
2147+
});
2148+
2149+
it('throws an error when invitation is not found (404)', async () => {
2150+
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
2151+
fetchOnce(
2152+
{
2153+
message: 'Invitation not found',
2154+
code: 'not_found',
2155+
},
2156+
{ status: 404 },
2157+
);
2158+
2159+
await expect(
2160+
workos.userManagement.resendInvitation(invitationId),
2161+
).rejects.toThrow();
2162+
});
2163+
2164+
it('throws an error when invitation is expired (400)', async () => {
2165+
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
2166+
fetchOnce(
2167+
{
2168+
message: 'Invite has expired.',
2169+
code: 'invite_expired',
2170+
},
2171+
{ status: 400 },
2172+
);
2173+
2174+
await expect(
2175+
workos.userManagement.resendInvitation(invitationId),
2176+
).rejects.toThrow();
2177+
});
2178+
2179+
it('throws an error when invitation is revoked (400)', async () => {
2180+
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
2181+
fetchOnce(
2182+
{
2183+
message: 'Invite has been revoked.',
2184+
code: 'invite_revoked',
2185+
},
2186+
{ status: 400 },
2187+
);
2188+
2189+
await expect(
2190+
workos.userManagement.resendInvitation(invitationId),
2191+
).rejects.toThrow();
2192+
});
2193+
2194+
it('throws an error when invitation is accepted (400)', async () => {
2195+
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
2196+
fetchOnce(
2197+
{
2198+
message: 'Invite has already been accepted.',
2199+
code: 'invite_accepted',
2200+
},
2201+
{ status: 400 },
2202+
);
2203+
2204+
await expect(
2205+
workos.userManagement.resendInvitation(invitationId),
2206+
).rejects.toThrow();
2207+
});
2208+
});
2209+
21312210
describe('revokeSession', () => {
21322211
it('sends a Revoke Session request', async () => {
21332212
const sessionId = 'session_12345';

src/user-management/user-management.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,15 @@ export class UserManagement {
10571057
return deserializeInvitation(data);
10581058
}
10591059

1060+
async resendInvitation(invitationId: string): Promise<Invitation> {
1061+
const { data } = await this.workos.post<InvitationResponse, any>(
1062+
`/user_management/invitations/${invitationId}/resend`,
1063+
null,
1064+
);
1065+
1066+
return deserializeInvitation(data);
1067+
}
1068+
10601069
async revokeSession(payload: RevokeSessionOptions): Promise<void> {
10611070
await this.workos.post<void, SerializedRevokeSessionOptions>(
10621071
'/user_management/sessions/revoke',

0 commit comments

Comments
 (0)