@workos-inc/node 7.3.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/exceptions/bad-request.exception.d.ts +4 -3
- package/lib/common/exceptions/generic-server.exception.d.ts +2 -1
- package/lib/common/exceptions/index.d.ts +1 -0
- package/lib/common/exceptions/index.js +1 -0
- package/lib/common/exceptions/no-api-key-provided.exception.d.ts +2 -2
- package/lib/common/exceptions/not-found.exception.d.ts +4 -3
- package/lib/common/exceptions/oauth.exception.d.ts +3 -2
- package/lib/common/exceptions/rate-limit-exceeded.exception.d.ts +13 -0
- package/lib/common/exceptions/rate-limit-exceeded.exception.js +20 -0
- package/lib/common/exceptions/signature-verification.exception.d.ts +1 -1
- package/lib/common/exceptions/unauthorized.exception.d.ts +4 -3
- package/lib/common/exceptions/unprocessable-entity.exception.d.ts +4 -3
- package/lib/common/interfaces/request-exception.interface.d.ts +5 -0
- package/lib/common/interfaces/request-exception.interface.js +2 -0
- package/lib/user-management/fixtures/deactivate-organization-membership.json +12 -0
- package/lib/user-management/fixtures/invitation.json +1 -0
- package/lib/user-management/fixtures/list-invitations.json +1 -0
- package/lib/user-management/interfaces/invitation.interface.d.ts +4 -0
- package/lib/user-management/interfaces/list-organization-memberships-options.interface.d.ts +3 -0
- package/lib/user-management/interfaces/organization-membership.interface.d.ts +3 -2
- package/lib/user-management/serializers/invitation.serializer.js +2 -0
- package/lib/user-management/serializers/list-organization-memberships-options.serializer.js +12 -8
- package/lib/user-management/user-management.d.ts +2 -0
- package/lib/user-management/user-management.js +12 -0
- package/lib/user-management/user-management.spec.js +40 -5
- package/lib/workos.js +5 -1
- package/lib/workos.spec.js +13 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
readonly
|
|
1
|
+
import { RequestException } from '../interfaces/request-exception.interface';
|
|
2
|
+
export declare class BadRequestException extends Error implements RequestException {
|
|
3
|
+
readonly status = 400;
|
|
4
|
+
readonly name = "BadRequestException";
|
|
4
5
|
readonly message: string;
|
|
5
6
|
readonly code?: string;
|
|
6
7
|
readonly errors?: unknown[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { RequestException } from '../interfaces/request-exception.interface';
|
|
2
|
+
export declare class GenericServerException extends Error implements RequestException {
|
|
2
3
|
readonly status: number;
|
|
3
4
|
readonly rawData: unknown;
|
|
4
5
|
readonly requestID: string;
|
|
@@ -3,6 +3,7 @@ export * from './bad-request.exception';
|
|
|
3
3
|
export * from './no-api-key-provided.exception';
|
|
4
4
|
export * from './not-found.exception';
|
|
5
5
|
export * from './oauth.exception';
|
|
6
|
+
export * from './rate-limit-exceeded.exception';
|
|
6
7
|
export * from './signature-verification.exception';
|
|
7
8
|
export * from './unauthorized.exception';
|
|
8
9
|
export * from './unprocessable-entity.exception';
|
|
@@ -19,6 +19,7 @@ __exportStar(require("./bad-request.exception"), exports);
|
|
|
19
19
|
__exportStar(require("./no-api-key-provided.exception"), exports);
|
|
20
20
|
__exportStar(require("./not-found.exception"), exports);
|
|
21
21
|
__exportStar(require("./oauth.exception"), exports);
|
|
22
|
+
__exportStar(require("./rate-limit-exceeded.exception"), exports);
|
|
22
23
|
__exportStar(require("./signature-verification.exception"), exports);
|
|
23
24
|
__exportStar(require("./unauthorized.exception"), exports);
|
|
24
25
|
__exportStar(require("./unprocessable-entity.exception"), exports);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
readonly
|
|
1
|
+
import { RequestException } from '../interfaces/request-exception.interface';
|
|
2
|
+
export declare class NotFoundException extends Error implements RequestException {
|
|
3
|
+
readonly status = 404;
|
|
4
|
+
readonly name = "NotFoundException";
|
|
4
5
|
readonly message: string;
|
|
5
6
|
readonly code?: string;
|
|
6
7
|
readonly requestID: string;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { RequestException } from '../interfaces/request-exception.interface';
|
|
2
|
+
export declare class OauthException extends Error implements RequestException {
|
|
2
3
|
readonly status: number;
|
|
3
4
|
readonly requestID: string;
|
|
4
5
|
readonly error: string | undefined;
|
|
5
6
|
readonly errorDescription: string | undefined;
|
|
6
7
|
readonly rawData: unknown;
|
|
7
|
-
readonly name
|
|
8
|
+
readonly name = "OauthException";
|
|
8
9
|
constructor(status: number, requestID: string, error: string | undefined, errorDescription: string | undefined, rawData: unknown);
|
|
9
10
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GenericServerException } from './generic-server.exception';
|
|
2
|
+
export declare class RateLimitExceededException extends GenericServerException {
|
|
3
|
+
/**
|
|
4
|
+
* The number of seconds to wait before retrying the request.
|
|
5
|
+
*/
|
|
6
|
+
readonly retryAfter: number | null;
|
|
7
|
+
readonly name = "RateLimitExceededException";
|
|
8
|
+
constructor(message: string, requestID: string,
|
|
9
|
+
/**
|
|
10
|
+
* The number of seconds to wait before retrying the request.
|
|
11
|
+
*/
|
|
12
|
+
retryAfter: number | null);
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimitExceededException = void 0;
|
|
4
|
+
const generic_server_exception_1 = require("./generic-server.exception");
|
|
5
|
+
// Inheriting from `GenericServerException` in order to maintain backwards
|
|
6
|
+
// compatibility with what 429 errors would have previously been thrown as.
|
|
7
|
+
//
|
|
8
|
+
// TODO: Consider making it the base class for all request errors.
|
|
9
|
+
class RateLimitExceededException extends generic_server_exception_1.GenericServerException {
|
|
10
|
+
constructor(message, requestID,
|
|
11
|
+
/**
|
|
12
|
+
* The number of seconds to wait before retrying the request.
|
|
13
|
+
*/
|
|
14
|
+
retryAfter) {
|
|
15
|
+
super(429, message, {}, requestID);
|
|
16
|
+
this.retryAfter = retryAfter;
|
|
17
|
+
this.name = 'RateLimitExceededException';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.RateLimitExceededException = RateLimitExceededException;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { RequestException } from '../interfaces/request-exception.interface';
|
|
2
|
+
export declare class UnauthorizedException extends Error implements RequestException {
|
|
2
3
|
readonly requestID: string;
|
|
3
|
-
readonly status
|
|
4
|
-
readonly name
|
|
4
|
+
readonly status = 401;
|
|
5
|
+
readonly name = "UnauthorizedException";
|
|
5
6
|
readonly message: string;
|
|
6
7
|
constructor(requestID: string);
|
|
7
8
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { UnprocessableEntityError } from '../interfaces';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
readonly
|
|
2
|
+
import { RequestException } from '../interfaces/request-exception.interface';
|
|
3
|
+
export declare class UnprocessableEntityException extends Error implements RequestException {
|
|
4
|
+
readonly status = 422;
|
|
5
|
+
readonly name = "UnprocessableEntityException";
|
|
5
6
|
readonly message: string;
|
|
6
7
|
readonly code?: string;
|
|
7
8
|
readonly requestID: string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"object": "organization_membership",
|
|
3
|
+
"id": "om_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
4
|
+
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
5
|
+
"organization_id": "organization_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
6
|
+
"status": "inactive",
|
|
7
|
+
"role": {
|
|
8
|
+
"slug": "member"
|
|
9
|
+
},
|
|
10
|
+
"created_at": "2023-07-18T02:07:19.911Z",
|
|
11
|
+
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
12
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"revoked_at": "2023-07-18T02:07:19.911Z",
|
|
8
8
|
"expires_at": "2023-07-18T02:07:19.911Z",
|
|
9
9
|
"organization_id": "org_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
10
|
+
"inviter_user_id": null,
|
|
10
11
|
"token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
11
12
|
"accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
12
13
|
"created_at": "2023-07-18T02:07:19.911Z",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"revoked_at": "2023-07-18T02:07:19.911Z",
|
|
11
11
|
"expires_at": "2023-07-18T02:07:19.911Z",
|
|
12
12
|
"organization_id": "org_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
13
|
+
"inviter_user_id": null,
|
|
13
14
|
"token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
14
15
|
"accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
15
16
|
"created_at": "2023-07-18T02:07:19.911Z",
|
|
@@ -7,6 +7,7 @@ export interface Invitation {
|
|
|
7
7
|
revokedAt: string | null;
|
|
8
8
|
expiresAt: string;
|
|
9
9
|
organizationId: string | null;
|
|
10
|
+
inviterUserId: string | null;
|
|
10
11
|
token: string;
|
|
11
12
|
acceptInvitationUrl: string;
|
|
12
13
|
createdAt: string;
|
|
@@ -21,6 +22,7 @@ export interface InvitationEvent {
|
|
|
21
22
|
revokedAt: string | null;
|
|
22
23
|
expiresAt: string;
|
|
23
24
|
organizationId: string | null;
|
|
25
|
+
inviterUserId: string | null;
|
|
24
26
|
createdAt: string;
|
|
25
27
|
updatedAt: string;
|
|
26
28
|
}
|
|
@@ -33,6 +35,7 @@ export interface InvitationResponse {
|
|
|
33
35
|
revoked_at: string | null;
|
|
34
36
|
expires_at: string;
|
|
35
37
|
organization_id: string | null;
|
|
38
|
+
inviter_user_id: string | null;
|
|
36
39
|
token: string;
|
|
37
40
|
accept_invitation_url: string;
|
|
38
41
|
created_at: string;
|
|
@@ -47,6 +50,7 @@ export interface InvitationEventResponse {
|
|
|
47
50
|
revoked_at: string | null;
|
|
48
51
|
expires_at: string;
|
|
49
52
|
organization_id: string | null;
|
|
53
|
+
inviter_user_id: string | null;
|
|
50
54
|
created_at: string;
|
|
51
55
|
updated_at: string;
|
|
52
56
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { PaginationOptions } from '../../common/interfaces';
|
|
2
|
+
import { OrganizationMembershipStatus } from './organization-membership.interface';
|
|
2
3
|
export interface ListOrganizationMembershipsOptions extends PaginationOptions {
|
|
3
4
|
organizationId?: string;
|
|
4
5
|
userId?: string;
|
|
6
|
+
statuses?: OrganizationMembershipStatus[];
|
|
5
7
|
}
|
|
6
8
|
export interface SerializedListOrganizationMembershipsOptions extends PaginationOptions {
|
|
7
9
|
organization_id?: string;
|
|
8
10
|
user_id?: string;
|
|
11
|
+
statuses?: string;
|
|
9
12
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RoleResponse } from './role.interface';
|
|
2
|
+
export type OrganizationMembershipStatus = 'active' | 'inactive' | 'pending';
|
|
2
3
|
export interface OrganizationMembership {
|
|
3
4
|
object: 'organization_membership';
|
|
4
5
|
id: string;
|
|
5
6
|
organizationId: string;
|
|
6
|
-
status:
|
|
7
|
+
status: OrganizationMembershipStatus;
|
|
7
8
|
userId: string;
|
|
8
9
|
createdAt: string;
|
|
9
10
|
updatedAt: string;
|
|
@@ -13,7 +14,7 @@ export interface OrganizationMembershipResponse {
|
|
|
13
14
|
object: 'organization_membership';
|
|
14
15
|
id: string;
|
|
15
16
|
organization_id: string;
|
|
16
|
-
status:
|
|
17
|
+
status: OrganizationMembershipStatus;
|
|
17
18
|
user_id: string;
|
|
18
19
|
created_at: string;
|
|
19
20
|
updated_at: string;
|
|
@@ -10,6 +10,7 @@ const deserializeInvitation = (invitation) => ({
|
|
|
10
10
|
revokedAt: invitation.revoked_at,
|
|
11
11
|
expiresAt: invitation.expires_at,
|
|
12
12
|
organizationId: invitation.organization_id,
|
|
13
|
+
inviterUserId: invitation.inviter_user_id,
|
|
13
14
|
token: invitation.token,
|
|
14
15
|
acceptInvitationUrl: invitation.accept_invitation_url,
|
|
15
16
|
createdAt: invitation.created_at,
|
|
@@ -25,6 +26,7 @@ const deserializeInvitationEvent = (invitation) => ({
|
|
|
25
26
|
revokedAt: invitation.revoked_at,
|
|
26
27
|
expiresAt: invitation.expires_at,
|
|
27
28
|
organizationId: invitation.organization_id,
|
|
29
|
+
inviterUserId: invitation.inviter_user_id,
|
|
28
30
|
createdAt: invitation.created_at,
|
|
29
31
|
updatedAt: invitation.updated_at,
|
|
30
32
|
});
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializeListOrganizationMembershipsOptions = void 0;
|
|
4
|
-
const serializeListOrganizationMembershipsOptions = (options) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
const serializeListOrganizationMembershipsOptions = (options) => {
|
|
5
|
+
var _a;
|
|
6
|
+
return ({
|
|
7
|
+
user_id: options.userId,
|
|
8
|
+
organization_id: options.organizationId,
|
|
9
|
+
statuses: (_a = options.statuses) === null || _a === void 0 ? void 0 : _a.join(','),
|
|
10
|
+
limit: options.limit,
|
|
11
|
+
before: options.before,
|
|
12
|
+
after: options.after,
|
|
13
|
+
order: options.order,
|
|
14
|
+
});
|
|
15
|
+
};
|
|
12
16
|
exports.serializeListOrganizationMembershipsOptions = serializeListOrganizationMembershipsOptions;
|
|
@@ -55,6 +55,8 @@ export declare class UserManagement {
|
|
|
55
55
|
createOrganizationMembership(options: CreateOrganizationMembershipOptions): Promise<OrganizationMembership>;
|
|
56
56
|
updateOrganizationMembership(organizationMembershipId: string, options: UpdateOrganizationMembershipOptions): Promise<OrganizationMembership>;
|
|
57
57
|
deleteOrganizationMembership(organizationMembershipId: string): Promise<void>;
|
|
58
|
+
deactivateOrganizationMembership(organizationMembershipId: string): Promise<OrganizationMembership>;
|
|
59
|
+
reactivateOrganizationMembership(organizationMembershipId: string): Promise<OrganizationMembership>;
|
|
58
60
|
getInvitation(invitationId: string): Promise<Invitation>;
|
|
59
61
|
listInvitations(options: ListInvitationsOptions): Promise<AutoPaginatable<Invitation>>;
|
|
60
62
|
sendInvitation(payload: SendInvitationOptions): Promise<Invitation>;
|
|
@@ -202,6 +202,18 @@ class UserManagement {
|
|
|
202
202
|
yield this.workos.delete(`/user_management/organization_memberships/${organizationMembershipId}`);
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
+
deactivateOrganizationMembership(organizationMembershipId) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
const { data } = yield this.workos.put(`/user_management/organization_memberships/${organizationMembershipId}/deactivate`, {});
|
|
208
|
+
return (0, organization_membership_serializer_1.deserializeOrganizationMembership)(data);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
reactivateOrganizationMembership(organizationMembershipId) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
const { data } = yield this.workos.put(`/user_management/organization_memberships/${organizationMembershipId}/reactivate`, {});
|
|
214
|
+
return (0, organization_membership_serializer_1.deserializeOrganizationMembership)(data);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
205
217
|
getInvitation(invitationId) {
|
|
206
218
|
return __awaiter(this, void 0, void 0, function* () {
|
|
207
219
|
const { data } = yield this.workos.get(`/user_management/invitations/${invitationId}`);
|
|
@@ -15,14 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const jest_fetch_mock_1 = __importDefault(require("jest-fetch-mock"));
|
|
16
16
|
const test_utils_1 = require("../common/utils/test-utils");
|
|
17
17
|
const workos_1 = require("../workos");
|
|
18
|
-
const
|
|
19
|
-
const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
|
|
20
|
-
const list_factors_json_1 = __importDefault(require("./fixtures/list-factors.json"));
|
|
21
|
-
const organization_membership_json_1 = __importDefault(require("./fixtures/organization-membership.json"));
|
|
22
|
-
const list_organization_memberships_json_1 = __importDefault(require("./fixtures/list-organization-memberships.json"));
|
|
18
|
+
const deactivate_organization_membership_json_1 = __importDefault(require("./fixtures/deactivate-organization-membership.json"));
|
|
23
19
|
const invitation_json_1 = __importDefault(require("./fixtures/invitation.json"));
|
|
20
|
+
const list_factors_json_1 = __importDefault(require("./fixtures/list-factors.json"));
|
|
24
21
|
const list_invitations_json_1 = __importDefault(require("./fixtures/list-invitations.json"));
|
|
22
|
+
const list_organization_memberships_json_1 = __importDefault(require("./fixtures/list-organization-memberships.json"));
|
|
23
|
+
const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
|
|
25
24
|
const magic_auth_json_1 = __importDefault(require("./fixtures/magic_auth.json"));
|
|
25
|
+
const organization_membership_json_1 = __importDefault(require("./fixtures/organization-membership.json"));
|
|
26
|
+
const user_json_1 = __importDefault(require("./fixtures/user.json"));
|
|
26
27
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
27
28
|
const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
28
29
|
const organizationMembershipId = 'om_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
@@ -583,12 +584,14 @@ describe('UserManagement', () => {
|
|
|
583
584
|
yield workos.userManagement.listOrganizationMemberships({
|
|
584
585
|
userId: 'user_someuser',
|
|
585
586
|
organizationId: 'org_someorg',
|
|
587
|
+
statuses: ['active', 'inactive'],
|
|
586
588
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
587
589
|
limit: 10,
|
|
588
590
|
});
|
|
589
591
|
expect((0, test_utils_1.fetchSearchParams)()).toEqual({
|
|
590
592
|
user_id: 'user_someuser',
|
|
591
593
|
organization_id: 'org_someorg',
|
|
594
|
+
statuses: 'active,inactive',
|
|
592
595
|
after: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
593
596
|
limit: '10',
|
|
594
597
|
order: 'desc',
|
|
@@ -644,6 +647,38 @@ describe('UserManagement', () => {
|
|
|
644
647
|
expect(resp).toBeUndefined();
|
|
645
648
|
}));
|
|
646
649
|
});
|
|
650
|
+
describe('deactivateOrganizationMembership', () => {
|
|
651
|
+
it('sends a deactivateOrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
652
|
+
(0, test_utils_1.fetchOnce)(deactivate_organization_membership_json_1.default);
|
|
653
|
+
const organizationMembership = yield workos.userManagement.deactivateOrganizationMembership(organizationMembershipId);
|
|
654
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/organization_memberships/${organizationMembershipId}/deactivate`);
|
|
655
|
+
expect(organizationMembership).toMatchObject({
|
|
656
|
+
object: 'organization_membership',
|
|
657
|
+
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
658
|
+
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
659
|
+
status: 'inactive',
|
|
660
|
+
role: {
|
|
661
|
+
slug: 'member',
|
|
662
|
+
},
|
|
663
|
+
});
|
|
664
|
+
}));
|
|
665
|
+
});
|
|
666
|
+
describe('reactivateOrganizationMembership', () => {
|
|
667
|
+
it('sends a reactivateOrganizationMembership request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
668
|
+
(0, test_utils_1.fetchOnce)(organization_membership_json_1.default);
|
|
669
|
+
const organizationMembership = yield workos.userManagement.reactivateOrganizationMembership(organizationMembershipId);
|
|
670
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/organization_memberships/${organizationMembershipId}/reactivate`);
|
|
671
|
+
expect(organizationMembership).toMatchObject({
|
|
672
|
+
object: 'organization_membership',
|
|
673
|
+
organizationId: 'organization_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
674
|
+
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
675
|
+
status: 'active',
|
|
676
|
+
role: {
|
|
677
|
+
slug: 'member',
|
|
678
|
+
},
|
|
679
|
+
});
|
|
680
|
+
}));
|
|
681
|
+
});
|
|
647
682
|
describe('getInvitation', () => {
|
|
648
683
|
it('sends a Get Invitation request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
649
684
|
(0, test_utils_1.fetchOnce)(invitation_json_1.default);
|
package/lib/workos.js
CHANGED
|
@@ -24,7 +24,7 @@ const audit_logs_1 = require("./audit-logs/audit-logs");
|
|
|
24
24
|
const user_management_1 = require("./user-management/user-management");
|
|
25
25
|
const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
|
|
26
26
|
const fetch_client_1 = require("./common/utils/fetch-client");
|
|
27
|
-
const VERSION = '7.
|
|
27
|
+
const VERSION = '7.5.0';
|
|
28
28
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
29
29
|
class WorkOS {
|
|
30
30
|
constructor(key, options = {}) {
|
|
@@ -170,6 +170,10 @@ class WorkOS {
|
|
|
170
170
|
requestID,
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
|
+
case 429: {
|
|
174
|
+
const retryAfter = headers.get('Retry-After');
|
|
175
|
+
throw new exceptions_1.RateLimitExceededException(data.message, requestID, retryAfter ? Number(retryAfter) : null);
|
|
176
|
+
}
|
|
173
177
|
default: {
|
|
174
178
|
if (error || errorDescription) {
|
|
175
179
|
throw new exceptions_1.OauthException(status, requestID, error, errorDescription, data);
|
package/lib/workos.spec.js
CHANGED
|
@@ -17,6 +17,7 @@ const test_utils_1 = require("./common/utils/test-utils");
|
|
|
17
17
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
18
18
|
const exceptions_1 = require("./common/exceptions");
|
|
19
19
|
const workos_1 = require("./workos");
|
|
20
|
+
const rate_limit_exceeded_exception_1 = require("./common/exceptions/rate-limit-exceeded.exception");
|
|
20
21
|
describe('WorkOS', () => {
|
|
21
22
|
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
22
23
|
describe('constructor', () => {
|
|
@@ -163,6 +164,18 @@ describe('WorkOS', () => {
|
|
|
163
164
|
yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.OauthException(400, 'a-request-id', 'error', 'error description', { error: 'error', error_description: 'error description' }));
|
|
164
165
|
}));
|
|
165
166
|
});
|
|
167
|
+
describe('when the api responses with a 429', () => {
|
|
168
|
+
it('throws a RateLimitExceededException', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
(0, test_utils_1.fetchOnce)({
|
|
170
|
+
message: 'Too many requests',
|
|
171
|
+
}, {
|
|
172
|
+
status: 429,
|
|
173
|
+
headers: { 'X-Request-ID': 'a-request-id', 'Retry-After': '10' },
|
|
174
|
+
});
|
|
175
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
176
|
+
yield expect(workos.get('/path')).rejects.toStrictEqual(new rate_limit_exceeded_exception_1.RateLimitExceededException('Too many requests', 'a-request-id', 10));
|
|
177
|
+
}));
|
|
178
|
+
});
|
|
166
179
|
describe('when the entity is null', () => {
|
|
167
180
|
it('sends a null body', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
181
|
(0, test_utils_1.fetchOnce)();
|
package/package.json
CHANGED