@workos-inc/node 7.2.0 → 7.4.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/event.interface.d.ts +19 -3
- package/lib/common/interfaces/request-exception.interface.d.ts +5 -0
- package/lib/common/interfaces/request-exception.interface.js +2 -0
- package/lib/common/serializers/event.serializer.js +4 -0
- package/lib/user-management/fixtures/invitation.json +2 -0
- package/lib/user-management/fixtures/list-invitations.json +2 -0
- package/lib/user-management/fixtures/magic_auth.json +10 -0
- package/lib/user-management/interfaces/create-magic-auth-options.interface.d.ts +8 -0
- package/lib/user-management/interfaces/create-magic-auth-options.interface.js +2 -0
- package/lib/user-management/interfaces/index.d.ts +2 -0
- package/lib/user-management/interfaces/index.js +2 -0
- package/lib/user-management/interfaces/invitation.interface.d.ts +30 -0
- package/lib/user-management/interfaces/magic-auth.interface.d.ts +38 -0
- package/lib/user-management/interfaces/magic-auth.interface.js +2 -0
- package/lib/user-management/serializers/create-magic-auth-options.serializer.d.ts +2 -0
- package/lib/user-management/serializers/create-magic-auth-options.serializer.js +8 -0
- package/lib/user-management/serializers/index.d.ts +3 -0
- package/lib/user-management/serializers/index.js +3 -0
- package/lib/user-management/serializers/invitation.serializer.d.ts +2 -1
- package/lib/user-management/serializers/invitation.serializer.js +17 -1
- package/lib/user-management/serializers/magic-auth.serializer.d.ts +3 -0
- package/lib/user-management/serializers/magic-auth.serializer.js +24 -0
- package/lib/user-management/user-management.d.ts +6 -1
- package/lib/user-management/user-management.js +15 -0
- package/lib/user-management/user-management.spec.js +39 -0
- 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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectoryUser, DirectoryUserResponse, DirectoryGroup, DirectoryGroupResponse, EventDirectory, EventDirectoryResponse } from '../../directory-sync/interfaces';
|
|
2
2
|
import { Organization, OrganizationResponse } from '../../organizations/interfaces';
|
|
3
3
|
import { Connection, ConnectionResponse } from '../../sso/interfaces';
|
|
4
|
-
import { Session, SessionResponse, User, UserResponse } from '../../user-management/interfaces';
|
|
4
|
+
import { InvitationEvent, InvitationEventResponse, MagicAuthEvent, MagicAuthEventResponse, Session, SessionResponse, User, UserResponse } from '../../user-management/interfaces';
|
|
5
5
|
import { OrganizationMembership, OrganizationMembershipResponse } from '../../user-management/interfaces/organization-membership.interface';
|
|
6
6
|
import { RoleEvent, RoleEventResponse } from '../../user-management/interfaces/role.interface';
|
|
7
7
|
export interface EventBase {
|
|
@@ -140,6 +140,22 @@ export interface DsyncUserUpdatedEventResponse extends EventResponseBase {
|
|
|
140
140
|
event: 'dsync.user.updated';
|
|
141
141
|
data: DirectoryUserResponse & Record<'previous_attributes', any>;
|
|
142
142
|
}
|
|
143
|
+
export interface InvitationCreatedEvent extends EventBase {
|
|
144
|
+
event: 'invitation.created';
|
|
145
|
+
data: InvitationEvent;
|
|
146
|
+
}
|
|
147
|
+
export interface InvitationCreatedEventResponse extends EventResponseBase {
|
|
148
|
+
event: 'invitation.created';
|
|
149
|
+
data: InvitationEventResponse;
|
|
150
|
+
}
|
|
151
|
+
export interface MagicAuthCreatedEvent extends EventBase {
|
|
152
|
+
event: 'magic_auth.created';
|
|
153
|
+
data: MagicAuthEvent;
|
|
154
|
+
}
|
|
155
|
+
export interface MagicAuthCreatedEventResponse extends EventResponseBase {
|
|
156
|
+
event: 'magic_auth.created';
|
|
157
|
+
data: MagicAuthEventResponse;
|
|
158
|
+
}
|
|
143
159
|
export interface UserCreatedEvent extends EventBase {
|
|
144
160
|
event: 'user.created';
|
|
145
161
|
data: User;
|
|
@@ -264,7 +280,7 @@ export interface SessionCreatedEventResponse extends EventResponseBase {
|
|
|
264
280
|
event: 'session.created';
|
|
265
281
|
data: SessionResponse;
|
|
266
282
|
}
|
|
267
|
-
export type Event = ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent | UserCreatedEvent | UserUpdatedEvent | UserDeletedEvent | OrganizationMembershipAdded | OrganizationMembershipCreated | OrganizationMembershipDeleted | OrganizationMembershipUpdated | OrganizationMembershipRemoved | RoleCreatedEvent | RoleDeletedEvent | SessionCreatedEvent | OrganizationCreatedEvent | OrganizationUpdatedEvent | OrganizationDeletedEvent;
|
|
268
|
-
export type EventResponse = ConnectionActivatedEventResponse | ConnectionDeactivatedEventResponse | ConnectionDeletedEventResponse | DsyncActivatedEventResponse | DsyncDeactivatedEventResponse | DsyncDeletedEventResponse | DsyncGroupCreatedEventResponse | DsyncGroupUpdatedEventResponse | DsyncGroupDeletedEventResponse | DsyncGroupUserAddedEventResponse | DsyncGroupUserRemovedEventResponse | DsyncUserCreatedEventResponse | DsyncUserUpdatedEventResponse | DsyncUserDeletedEventResponse | UserCreatedEventResponse | UserUpdatedEventResponse | UserDeletedEventResponse | OrganizationMembershipAddedResponse | OrganizationMembershipCreatedResponse | OrganizationMembershipDeletedResponse | OrganizationMembershipUpdatedResponse | OrganizationMembershipRemovedResponse | RoleCreatedEventResponse | RoleDeletedEventResponse | SessionCreatedEventResponse | OrganizationCreatedResponse | OrganizationUpdatedResponse | OrganizationDeletedResponse;
|
|
283
|
+
export type Event = ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent | InvitationCreatedEvent | MagicAuthCreatedEvent | UserCreatedEvent | UserUpdatedEvent | UserDeletedEvent | OrganizationMembershipAdded | OrganizationMembershipCreated | OrganizationMembershipDeleted | OrganizationMembershipUpdated | OrganizationMembershipRemoved | RoleCreatedEvent | RoleDeletedEvent | SessionCreatedEvent | OrganizationCreatedEvent | OrganizationUpdatedEvent | OrganizationDeletedEvent;
|
|
284
|
+
export type EventResponse = ConnectionActivatedEventResponse | ConnectionDeactivatedEventResponse | ConnectionDeletedEventResponse | DsyncActivatedEventResponse | DsyncDeactivatedEventResponse | DsyncDeletedEventResponse | DsyncGroupCreatedEventResponse | DsyncGroupUpdatedEventResponse | DsyncGroupDeletedEventResponse | DsyncGroupUserAddedEventResponse | DsyncGroupUserRemovedEventResponse | DsyncUserCreatedEventResponse | DsyncUserUpdatedEventResponse | DsyncUserDeletedEventResponse | InvitationCreatedEventResponse | MagicAuthCreatedEventResponse | UserCreatedEventResponse | UserUpdatedEventResponse | UserDeletedEventResponse | OrganizationMembershipAddedResponse | OrganizationMembershipCreatedResponse | OrganizationMembershipDeletedResponse | OrganizationMembershipUpdatedResponse | OrganizationMembershipRemovedResponse | RoleCreatedEventResponse | RoleDeletedEventResponse | SessionCreatedEventResponse | OrganizationCreatedResponse | OrganizationUpdatedResponse | OrganizationDeletedResponse;
|
|
269
285
|
export type EventName = Event['event'];
|
|
270
286
|
export {};
|
|
@@ -40,6 +40,10 @@ const deserializeEvent = (event) => {
|
|
|
40
40
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_1.deserializeDirectoryUser)(event.data) });
|
|
41
41
|
case 'dsync.user.updated':
|
|
42
42
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_1.deserializeUpdatedEventDirectoryUser)(event.data) });
|
|
43
|
+
case 'invitation.created':
|
|
44
|
+
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_4.deserializeInvitationEvent)(event.data) });
|
|
45
|
+
case 'magic_auth.created':
|
|
46
|
+
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_4.deserializeMagicAuthEvent)(event.data) });
|
|
43
47
|
case 'user.created':
|
|
44
48
|
case 'user.updated':
|
|
45
49
|
case 'user.deleted':
|
|
@@ -7,7 +7,9 @@
|
|
|
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",
|
|
12
|
+
"accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
11
13
|
"created_at": "2023-07-18T02:07:19.911Z",
|
|
12
14
|
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
13
15
|
}
|
|
@@ -10,7 +10,9 @@
|
|
|
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",
|
|
15
|
+
"accept_invitation_url": "https://myauthkit.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
|
|
14
16
|
"created_at": "2023-07-18T02:07:19.911Z",
|
|
15
17
|
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
16
18
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"object": "magic_auth",
|
|
3
|
+
"id": "magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
4
|
+
"user_id": "user_01H5JQDV7R7ATEYZDEG0W5PRYS",
|
|
5
|
+
"email": "dane@workos.com",
|
|
6
|
+
"expires_at": "2023-07-18T02:07:19.911Z",
|
|
7
|
+
"code": "123456",
|
|
8
|
+
"created_at": "2023-07-18T02:07:19.911Z",
|
|
9
|
+
"updated_at": "2023-07-18T02:07:19.911Z"
|
|
10
|
+
}
|
|
@@ -9,6 +9,7 @@ export * from './authenticate-with-password-options.interface';
|
|
|
9
9
|
export * from './authenticate-with-refresh-token-options.interface';
|
|
10
10
|
export * from './authenticate-with-totp-options.interface';
|
|
11
11
|
export * from './authentication-response.interface';
|
|
12
|
+
export * from './create-magic-auth-options.interface';
|
|
12
13
|
export * from './create-organization-membership-options.interface';
|
|
13
14
|
export * from './create-user-options.interface';
|
|
14
15
|
export * from './enroll-auth-factor.interface';
|
|
@@ -19,6 +20,7 @@ export * from './list-auth-factors-options.interface';
|
|
|
19
20
|
export * from './list-invitations-options.interface';
|
|
20
21
|
export * from './list-organization-memberships-options.interface';
|
|
21
22
|
export * from './list-users-options.interface';
|
|
23
|
+
export * from './magic-auth.interface';
|
|
22
24
|
export * from './organization-membership.interface';
|
|
23
25
|
export * from './reset-password-options.interface';
|
|
24
26
|
export * from './revoke-session-options.interface';
|
|
@@ -25,6 +25,7 @@ __exportStar(require("./authenticate-with-password-options.interface"), exports)
|
|
|
25
25
|
__exportStar(require("./authenticate-with-refresh-token-options.interface"), exports);
|
|
26
26
|
__exportStar(require("./authenticate-with-totp-options.interface"), exports);
|
|
27
27
|
__exportStar(require("./authentication-response.interface"), exports);
|
|
28
|
+
__exportStar(require("./create-magic-auth-options.interface"), exports);
|
|
28
29
|
__exportStar(require("./create-organization-membership-options.interface"), exports);
|
|
29
30
|
__exportStar(require("./create-user-options.interface"), exports);
|
|
30
31
|
__exportStar(require("./enroll-auth-factor.interface"), exports);
|
|
@@ -35,6 +36,7 @@ __exportStar(require("./list-auth-factors-options.interface"), exports);
|
|
|
35
36
|
__exportStar(require("./list-invitations-options.interface"), exports);
|
|
36
37
|
__exportStar(require("./list-organization-memberships-options.interface"), exports);
|
|
37
38
|
__exportStar(require("./list-users-options.interface"), exports);
|
|
39
|
+
__exportStar(require("./magic-auth.interface"), exports);
|
|
38
40
|
__exportStar(require("./organization-membership.interface"), exports);
|
|
39
41
|
__exportStar(require("./reset-password-options.interface"), exports);
|
|
40
42
|
__exportStar(require("./revoke-session-options.interface"), exports);
|
|
@@ -7,7 +7,22 @@ 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;
|
|
12
|
+
acceptInvitationUrl: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
}
|
|
16
|
+
export interface InvitationEvent {
|
|
17
|
+
object: 'invitation';
|
|
18
|
+
id: string;
|
|
19
|
+
email: string;
|
|
20
|
+
state: 'pending' | 'accepted' | 'expired' | 'revoked';
|
|
21
|
+
acceptedAt: string | null;
|
|
22
|
+
revokedAt: string | null;
|
|
23
|
+
expiresAt: string;
|
|
24
|
+
organizationId: string | null;
|
|
25
|
+
inviterUserId: string | null;
|
|
11
26
|
createdAt: string;
|
|
12
27
|
updatedAt: string;
|
|
13
28
|
}
|
|
@@ -20,7 +35,22 @@ export interface InvitationResponse {
|
|
|
20
35
|
revoked_at: string | null;
|
|
21
36
|
expires_at: string;
|
|
22
37
|
organization_id: string | null;
|
|
38
|
+
inviter_user_id: string | null;
|
|
23
39
|
token: string;
|
|
40
|
+
accept_invitation_url: string;
|
|
41
|
+
created_at: string;
|
|
42
|
+
updated_at: string;
|
|
43
|
+
}
|
|
44
|
+
export interface InvitationEventResponse {
|
|
45
|
+
object: 'invitation';
|
|
46
|
+
id: string;
|
|
47
|
+
email: string;
|
|
48
|
+
state: 'pending' | 'accepted' | 'expired' | 'revoked';
|
|
49
|
+
accepted_at: string | null;
|
|
50
|
+
revoked_at: string | null;
|
|
51
|
+
expires_at: string;
|
|
52
|
+
organization_id: string | null;
|
|
53
|
+
inviter_user_id: string | null;
|
|
24
54
|
created_at: string;
|
|
25
55
|
updated_at: string;
|
|
26
56
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface MagicAuth {
|
|
2
|
+
object: 'magic_auth';
|
|
3
|
+
id: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
email: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
code: string;
|
|
8
|
+
createdAt: string;
|
|
9
|
+
updatedAt: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MagicAuthEvent {
|
|
12
|
+
object: 'magic_auth';
|
|
13
|
+
id: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
email: string;
|
|
16
|
+
expiresAt: string;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
updatedAt: string;
|
|
19
|
+
}
|
|
20
|
+
export interface MagicAuthResponse {
|
|
21
|
+
object: 'magic_auth';
|
|
22
|
+
id: string;
|
|
23
|
+
user_id: string;
|
|
24
|
+
email: string;
|
|
25
|
+
expires_at: string;
|
|
26
|
+
code: string;
|
|
27
|
+
created_at: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
}
|
|
30
|
+
export interface MagicAuthEventResponse {
|
|
31
|
+
object: 'magic_auth';
|
|
32
|
+
id: string;
|
|
33
|
+
user_id: string;
|
|
34
|
+
email: string;
|
|
35
|
+
expires_at: string;
|
|
36
|
+
created_at: string;
|
|
37
|
+
updated_at: string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeCreateMagicAuthOptions = void 0;
|
|
4
|
+
const serializeCreateMagicAuthOptions = (options) => ({
|
|
5
|
+
email: options.email,
|
|
6
|
+
invitation_token: options.invitationToken,
|
|
7
|
+
});
|
|
8
|
+
exports.serializeCreateMagicAuthOptions = serializeCreateMagicAuthOptions;
|
|
@@ -4,8 +4,11 @@ export * from './authenticate-with-password-options.serializer';
|
|
|
4
4
|
export * from './authenticate-with-refresh-token.options.serializer';
|
|
5
5
|
export * from './authenticate-with-totp-options.serializer';
|
|
6
6
|
export * from './authentication-response.serializer';
|
|
7
|
+
export * from './create-magic-auth-options.serializer';
|
|
7
8
|
export * from './enroll-auth-factor-options.serializer';
|
|
8
9
|
export * from './factor.serializer';
|
|
10
|
+
export * from './invitation.serializer';
|
|
11
|
+
export * from './magic-auth.serializer';
|
|
9
12
|
export * from './reset-password-options.serializer';
|
|
10
13
|
export * from './send-password-reset-email.serializer';
|
|
11
14
|
export * from './create-user-options.serializer';
|
|
@@ -20,8 +20,11 @@ __exportStar(require("./authenticate-with-password-options.serializer"), exports
|
|
|
20
20
|
__exportStar(require("./authenticate-with-refresh-token.options.serializer"), exports);
|
|
21
21
|
__exportStar(require("./authenticate-with-totp-options.serializer"), exports);
|
|
22
22
|
__exportStar(require("./authentication-response.serializer"), exports);
|
|
23
|
+
__exportStar(require("./create-magic-auth-options.serializer"), exports);
|
|
23
24
|
__exportStar(require("./enroll-auth-factor-options.serializer"), exports);
|
|
24
25
|
__exportStar(require("./factor.serializer"), exports);
|
|
26
|
+
__exportStar(require("./invitation.serializer"), exports);
|
|
27
|
+
__exportStar(require("./magic-auth.serializer"), exports);
|
|
25
28
|
__exportStar(require("./reset-password-options.serializer"), exports);
|
|
26
29
|
__exportStar(require("./send-password-reset-email.serializer"), exports);
|
|
27
30
|
__exportStar(require("./create-user-options.serializer"), exports);
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { Invitation, InvitationResponse } from '../interfaces/invitation.interface';
|
|
1
|
+
import { Invitation, InvitationEvent, InvitationEventResponse, InvitationResponse } from '../interfaces/invitation.interface';
|
|
2
2
|
export declare const deserializeInvitation: (invitation: InvitationResponse) => Invitation;
|
|
3
|
+
export declare const deserializeInvitationEvent: (invitation: InvitationEventResponse) => InvitationEvent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deserializeInvitation = void 0;
|
|
3
|
+
exports.deserializeInvitationEvent = exports.deserializeInvitation = void 0;
|
|
4
4
|
const deserializeInvitation = (invitation) => ({
|
|
5
5
|
object: invitation.object,
|
|
6
6
|
id: invitation.id,
|
|
@@ -10,8 +10,24 @@ 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,
|
|
15
|
+
acceptInvitationUrl: invitation.accept_invitation_url,
|
|
14
16
|
createdAt: invitation.created_at,
|
|
15
17
|
updatedAt: invitation.updated_at,
|
|
16
18
|
});
|
|
17
19
|
exports.deserializeInvitation = deserializeInvitation;
|
|
20
|
+
const deserializeInvitationEvent = (invitation) => ({
|
|
21
|
+
object: invitation.object,
|
|
22
|
+
id: invitation.id,
|
|
23
|
+
email: invitation.email,
|
|
24
|
+
state: invitation.state,
|
|
25
|
+
acceptedAt: invitation.accepted_at,
|
|
26
|
+
revokedAt: invitation.revoked_at,
|
|
27
|
+
expiresAt: invitation.expires_at,
|
|
28
|
+
organizationId: invitation.organization_id,
|
|
29
|
+
inviterUserId: invitation.inviter_user_id,
|
|
30
|
+
createdAt: invitation.created_at,
|
|
31
|
+
updatedAt: invitation.updated_at,
|
|
32
|
+
});
|
|
33
|
+
exports.deserializeInvitationEvent = deserializeInvitationEvent;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MagicAuth, MagicAuthEvent, MagicAuthEventResponse, MagicAuthResponse } from '../interfaces/magic-auth.interface';
|
|
2
|
+
export declare const deserializeMagicAuth: (magicAuth: MagicAuthResponse) => MagicAuth;
|
|
3
|
+
export declare const deserializeMagicAuthEvent: (magicAuth: MagicAuthEventResponse) => MagicAuthEvent;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeMagicAuthEvent = exports.deserializeMagicAuth = void 0;
|
|
4
|
+
const deserializeMagicAuth = (magicAuth) => ({
|
|
5
|
+
object: magicAuth.object,
|
|
6
|
+
id: magicAuth.id,
|
|
7
|
+
userId: magicAuth.user_id,
|
|
8
|
+
email: magicAuth.email,
|
|
9
|
+
expiresAt: magicAuth.expires_at,
|
|
10
|
+
code: magicAuth.code,
|
|
11
|
+
createdAt: magicAuth.created_at,
|
|
12
|
+
updatedAt: magicAuth.updated_at,
|
|
13
|
+
});
|
|
14
|
+
exports.deserializeMagicAuth = deserializeMagicAuth;
|
|
15
|
+
const deserializeMagicAuthEvent = (magicAuth) => ({
|
|
16
|
+
object: magicAuth.object,
|
|
17
|
+
id: magicAuth.id,
|
|
18
|
+
userId: magicAuth.user_id,
|
|
19
|
+
email: magicAuth.email,
|
|
20
|
+
expiresAt: magicAuth.expires_at,
|
|
21
|
+
createdAt: magicAuth.created_at,
|
|
22
|
+
updatedAt: magicAuth.updated_at,
|
|
23
|
+
});
|
|
24
|
+
exports.deserializeMagicAuthEvent = deserializeMagicAuthEvent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
2
|
import { AutoPaginatable } from '../common/utils/pagination';
|
|
3
|
-
import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, CreateUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions, AuthenticateWithRefreshTokenOptions, RefreshAuthenticationResponse } from './interfaces';
|
|
3
|
+
import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, CreateUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions, AuthenticateWithRefreshTokenOptions, RefreshAuthenticationResponse, MagicAuth, CreateMagicAuthOptions } from './interfaces';
|
|
4
4
|
import { Challenge } from '../mfa/interfaces';
|
|
5
5
|
import { OrganizationMembership } from './interfaces/organization-membership.interface';
|
|
6
6
|
import { ListOrganizationMembershipsOptions } from './interfaces/list-organization-memberships-options.interface';
|
|
@@ -30,6 +30,11 @@ export declare class UserManagement {
|
|
|
30
30
|
sendVerificationEmail({ userId, }: SendVerificationEmailOptions): Promise<{
|
|
31
31
|
user: User;
|
|
32
32
|
}>;
|
|
33
|
+
getMagicAuth(magicAuthId: string): Promise<MagicAuth>;
|
|
34
|
+
createMagicAuth(options: CreateMagicAuthOptions): Promise<MagicAuth>;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Please use `createMagicAuth` instead. This method will be removed in a future major version.
|
|
37
|
+
*/
|
|
33
38
|
sendMagicAuthCode(options: SendMagicAuthCodeOptions): Promise<void>;
|
|
34
39
|
verifyEmail({ code, userId, }: VerifyEmailOptions): Promise<{
|
|
35
40
|
user: User;
|
|
@@ -106,6 +106,21 @@ class UserManagement {
|
|
|
106
106
|
return { user: (0, serializers_1.deserializeUser)(data.user) };
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
+
getMagicAuth(magicAuthId) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const { data } = yield this.workos.get(`/user_management/magic_auth/${magicAuthId}`);
|
|
112
|
+
return (0, serializers_1.deserializeMagicAuth)(data);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
createMagicAuth(options) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const { data } = yield this.workos.post('/user_management/magic_auth', (0, serializers_1.serializeCreateMagicAuthOptions)(Object.assign({}, options)));
|
|
118
|
+
return (0, serializers_1.deserializeMagicAuth)(data);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated Please use `createMagicAuth` instead. This method will be removed in a future major version.
|
|
123
|
+
*/
|
|
109
124
|
sendMagicAuthCode(options) {
|
|
110
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
126
|
yield this.workos.post('/user_management/magic_auth/send', (0, serializers_1.serializeSendMagicAuthCodeOptions)(options));
|
|
@@ -22,10 +22,12 @@ const organization_membership_json_1 = __importDefault(require("./fixtures/organ
|
|
|
22
22
|
const list_organization_memberships_json_1 = __importDefault(require("./fixtures/list-organization-memberships.json"));
|
|
23
23
|
const invitation_json_1 = __importDefault(require("./fixtures/invitation.json"));
|
|
24
24
|
const list_invitations_json_1 = __importDefault(require("./fixtures/list-invitations.json"));
|
|
25
|
+
const magic_auth_json_1 = __importDefault(require("./fixtures/magic_auth.json"));
|
|
25
26
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
26
27
|
const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
27
28
|
const organizationMembershipId = 'om_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
28
29
|
const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
30
|
+
const magicAuthId = 'magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
29
31
|
describe('UserManagement', () => {
|
|
30
32
|
beforeEach(() => jest_fetch_mock_1.default.resetMocks());
|
|
31
33
|
describe('getUser', () => {
|
|
@@ -324,6 +326,43 @@ describe('UserManagement', () => {
|
|
|
324
326
|
}));
|
|
325
327
|
});
|
|
326
328
|
});
|
|
329
|
+
describe('getMagicAuth', () => {
|
|
330
|
+
it('sends a Get Magic Auth request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
331
|
+
(0, test_utils_1.fetchOnce)(magic_auth_json_1.default);
|
|
332
|
+
const magicAuth = yield workos.userManagement.getMagicAuth(magicAuthId);
|
|
333
|
+
expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/magic_auth/${magicAuthId}`);
|
|
334
|
+
expect(magicAuth).toMatchObject({
|
|
335
|
+
id: 'magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
336
|
+
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
337
|
+
email: 'dane@workos.com',
|
|
338
|
+
expiresAt: '2023-07-18T02:07:19.911Z',
|
|
339
|
+
code: '123456',
|
|
340
|
+
createdAt: '2023-07-18T02:07:19.911Z',
|
|
341
|
+
updatedAt: '2023-07-18T02:07:19.911Z',
|
|
342
|
+
});
|
|
343
|
+
}));
|
|
344
|
+
});
|
|
345
|
+
describe('createMagicAuth', () => {
|
|
346
|
+
it('sends a Create Magic Auth request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
347
|
+
(0, test_utils_1.fetchOnce)(magic_auth_json_1.default);
|
|
348
|
+
const response = yield workos.userManagement.createMagicAuth({
|
|
349
|
+
email: 'bob.loblaw@example.com',
|
|
350
|
+
});
|
|
351
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/magic_auth');
|
|
352
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
353
|
+
email: 'bob.loblaw@example.com',
|
|
354
|
+
});
|
|
355
|
+
expect(response).toMatchObject({
|
|
356
|
+
id: 'magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
357
|
+
userId: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
358
|
+
email: 'dane@workos.com',
|
|
359
|
+
expiresAt: '2023-07-18T02:07:19.911Z',
|
|
360
|
+
code: '123456',
|
|
361
|
+
createdAt: '2023-07-18T02:07:19.911Z',
|
|
362
|
+
updatedAt: '2023-07-18T02:07:19.911Z',
|
|
363
|
+
});
|
|
364
|
+
}));
|
|
365
|
+
});
|
|
327
366
|
describe('sendMagicAuthCode', () => {
|
|
328
367
|
it('sends a Send Magic Auth Code request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
329
368
|
(0, test_utils_1.fetchOnce)();
|
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.4.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