@workos-inc/node 3.4.0 → 3.6.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/generic-server.exception.d.ts +1 -1
- package/lib/common/exceptions/generic-server.exception.js +1 -1
- package/lib/common/exceptions/oauth.exception.d.ts +2 -1
- package/lib/common/exceptions/oauth.exception.js +2 -1
- package/lib/users/interfaces/authenticate-user-with-magic-auth-options.interface.d.ts +0 -2
- package/lib/users/interfaces/authenticate-user-with-password-options.interface.d.ts +0 -2
- package/lib/users/interfaces/authenticate-user-with-token-options.interface.d.ts +0 -2
- package/lib/users/interfaces/authentication-response.interface.d.ts +0 -3
- package/lib/users/interfaces/index.d.ts +2 -3
- package/lib/users/interfaces/index.js +2 -3
- package/lib/users/interfaces/send-verification-email-options.d.ts +3 -0
- package/lib/users/interfaces/verify-email-code-options.interface.d.ts +7 -0
- package/lib/users/serializers/authenticate-user-with-code-options.serializer.js +0 -1
- package/lib/users/serializers/authenticate-user-with-magic-auth-options.serializer.js +0 -1
- package/lib/users/serializers/authenticate-user-with-password-options.serializer.js +0 -1
- package/lib/users/serializers/authentication-response.serializer.js +0 -2
- package/lib/users/serializers/index.d.ts +0 -2
- package/lib/users/serializers/index.js +0 -2
- package/lib/users/users.d.ts +8 -4
- package/lib/users/users.js +9 -11
- package/lib/users/users.spec.js +43 -39
- package/lib/workos.js +2 -2
- package/lib/workos.spec.js +1 -1
- package/package.json +1 -1
- package/lib/users/fixtures/session.json +0 -8
- package/lib/users/interfaces/create-email-verification-challenge-options.interface.d.ts +0 -16
- package/lib/users/interfaces/session.interface.d.ts +0 -41
- package/lib/users/interfaces/verify-email-options.interface.d.ts +0 -7
- package/lib/users/interfaces/verify-email-options.interface.js +0 -2
- package/lib/users/serializers/create-email-verification-challenge.serializer.d.ts +0 -2
- package/lib/users/serializers/create-email-verification-challenge.serializer.js +0 -9
- package/lib/users/serializers/session.serializer.d.ts +0 -4
- package/lib/users/serializers/session.serializer.js +0 -22
- /package/lib/users/interfaces/{create-email-verification-challenge-options.interface.js → send-verification-email-options.js} +0 -0
- /package/lib/users/interfaces/{session.interface.js → verify-email-code-options.interface.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class GenericServerException extends Error {
|
|
2
2
|
readonly status: number;
|
|
3
|
+
readonly rawData: unknown;
|
|
3
4
|
readonly requestID: string;
|
|
4
5
|
readonly name: string;
|
|
5
|
-
readonly rawData: unknown;
|
|
6
6
|
readonly message: string;
|
|
7
7
|
constructor(status: number, message: string | undefined, rawData: unknown, requestID: string);
|
|
8
8
|
}
|
|
@@ -5,12 +5,12 @@ class GenericServerException extends Error {
|
|
|
5
5
|
constructor(status, message, rawData, requestID) {
|
|
6
6
|
super();
|
|
7
7
|
this.status = status;
|
|
8
|
+
this.rawData = rawData;
|
|
8
9
|
this.requestID = requestID;
|
|
9
10
|
this.name = 'GenericServerException';
|
|
10
11
|
this.message = 'The request could not be completed.';
|
|
11
12
|
if (message) {
|
|
12
13
|
this.message = message;
|
|
13
|
-
this.rawData = rawData;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -3,6 +3,7 @@ export declare class OauthException extends Error {
|
|
|
3
3
|
readonly requestID: string;
|
|
4
4
|
readonly error: string | undefined;
|
|
5
5
|
readonly errorDescription: string | undefined;
|
|
6
|
+
readonly rawData: unknown;
|
|
6
7
|
readonly name: string;
|
|
7
|
-
constructor(status: number, requestID: string, error: string | undefined, errorDescription: string | undefined);
|
|
8
|
+
constructor(status: number, requestID: string, error: string | undefined, errorDescription: string | undefined, rawData: unknown);
|
|
8
9
|
}
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OauthException = void 0;
|
|
4
4
|
class OauthException extends Error {
|
|
5
|
-
constructor(status, requestID, error, errorDescription) {
|
|
5
|
+
constructor(status, requestID, error, errorDescription, rawData) {
|
|
6
6
|
super();
|
|
7
7
|
this.status = status;
|
|
8
8
|
this.requestID = requestID;
|
|
9
9
|
this.error = error;
|
|
10
10
|
this.errorDescription = errorDescription;
|
|
11
|
+
this.rawData = rawData;
|
|
11
12
|
this.name = 'OauthException';
|
|
12
13
|
if (error && errorDescription) {
|
|
13
14
|
this.message = `Error: ${error}\nError Description: ${errorDescription}`;
|
|
@@ -4,7 +4,6 @@ export interface AuthenticateUserWithMagicAuthOptions {
|
|
|
4
4
|
magicAuthChallengeId: string;
|
|
5
5
|
ipAddress?: string;
|
|
6
6
|
userAgent?: string;
|
|
7
|
-
expiresIn?: number;
|
|
8
7
|
}
|
|
9
8
|
export interface AuthenticateUserWithMagicAuthCredentials {
|
|
10
9
|
clientSecret: string | undefined;
|
|
@@ -17,5 +16,4 @@ export interface SerializedAuthenticateUserWithMagicAuthOptions {
|
|
|
17
16
|
magic_auth_challenge_id: string;
|
|
18
17
|
ip_address?: string;
|
|
19
18
|
user_agent?: string;
|
|
20
|
-
expires_in?: number;
|
|
21
19
|
}
|
|
@@ -4,7 +4,6 @@ export interface AuthenticateUserWithPasswordOptions {
|
|
|
4
4
|
password: string;
|
|
5
5
|
ipAddress?: string;
|
|
6
6
|
userAgent?: string;
|
|
7
|
-
expiresIn?: number;
|
|
8
7
|
}
|
|
9
8
|
export interface AuthenticateUserWithPasswordCredentials {
|
|
10
9
|
clientSecret: string | undefined;
|
|
@@ -17,5 +16,4 @@ export interface SerializedAuthenticateUserWithPasswordOptions {
|
|
|
17
16
|
password: string;
|
|
18
17
|
ip_address?: string;
|
|
19
18
|
user_agent?: string;
|
|
20
|
-
expires_in?: number;
|
|
21
19
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export interface AuthenticateUserWithCodeOptions {
|
|
2
2
|
clientId: string;
|
|
3
3
|
code: string;
|
|
4
|
-
expiresIn?: number;
|
|
5
4
|
}
|
|
6
5
|
export interface AuthenticateUserWithCodeCredentials {
|
|
7
6
|
clientSecret: string | undefined;
|
|
@@ -11,5 +10,4 @@ export interface SerializedAuthenticateUserWithCodeOptions {
|
|
|
11
10
|
client_id: string;
|
|
12
11
|
client_secret: string | undefined;
|
|
13
12
|
code: string;
|
|
14
|
-
expires_in?: number;
|
|
15
13
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { User, UserResponse } from './user.interface';
|
|
2
|
-
import { Session, SessionResponse } from './session.interface';
|
|
3
2
|
export interface AuthenticationResponse {
|
|
4
|
-
session: Session;
|
|
5
3
|
user: User;
|
|
6
4
|
}
|
|
7
5
|
export interface AuthenticationResponseResponse {
|
|
8
|
-
session: SessionResponse;
|
|
9
6
|
user: UserResponse;
|
|
10
7
|
}
|
|
@@ -4,7 +4,6 @@ export * from './authenticate-user-with-password-options.interface';
|
|
|
4
4
|
export * from './authenticate-user-with-token-options.interface';
|
|
5
5
|
export * from './authentication-response.interface';
|
|
6
6
|
export * from './complete-password-reset-options.interface';
|
|
7
|
-
export * from './create-email-verification-challenge-options.interface';
|
|
8
7
|
export * from './create-password-reset-challenge-options.interface';
|
|
9
8
|
export * from './create-user-options.interface';
|
|
10
9
|
export * from './delete-user-options.interface';
|
|
@@ -13,8 +12,8 @@ export * from './list-users-options.interface';
|
|
|
13
12
|
export * from './magic-auth-challenge.interface';
|
|
14
13
|
export * from './remove-user-from-organization-options.interface';
|
|
15
14
|
export * from './send-magic-auth-code-options.interface';
|
|
16
|
-
export * from './
|
|
15
|
+
export * from './send-verification-email-options';
|
|
17
16
|
export * from './update-user-options.interface';
|
|
18
17
|
export * from './update-user-password-options.interface';
|
|
19
18
|
export * from './user.interface';
|
|
20
|
-
export * from './verify-email-options.interface';
|
|
19
|
+
export * from './verify-email-code-options.interface';
|
|
@@ -20,7 +20,6 @@ __exportStar(require("./authenticate-user-with-password-options.interface"), exp
|
|
|
20
20
|
__exportStar(require("./authenticate-user-with-token-options.interface"), exports);
|
|
21
21
|
__exportStar(require("./authentication-response.interface"), exports);
|
|
22
22
|
__exportStar(require("./complete-password-reset-options.interface"), exports);
|
|
23
|
-
__exportStar(require("./create-email-verification-challenge-options.interface"), exports);
|
|
24
23
|
__exportStar(require("./create-password-reset-challenge-options.interface"), exports);
|
|
25
24
|
__exportStar(require("./create-user-options.interface"), exports);
|
|
26
25
|
__exportStar(require("./delete-user-options.interface"), exports);
|
|
@@ -29,8 +28,8 @@ __exportStar(require("./list-users-options.interface"), exports);
|
|
|
29
28
|
__exportStar(require("./magic-auth-challenge.interface"), exports);
|
|
30
29
|
__exportStar(require("./remove-user-from-organization-options.interface"), exports);
|
|
31
30
|
__exportStar(require("./send-magic-auth-code-options.interface"), exports);
|
|
32
|
-
__exportStar(require("./
|
|
31
|
+
__exportStar(require("./send-verification-email-options"), exports);
|
|
33
32
|
__exportStar(require("./update-user-options.interface"), exports);
|
|
34
33
|
__exportStar(require("./update-user-password-options.interface"), exports);
|
|
35
34
|
__exportStar(require("./user.interface"), exports);
|
|
36
|
-
__exportStar(require("./verify-email-options.interface"), exports);
|
|
35
|
+
__exportStar(require("./verify-email-code-options.interface"), exports);
|
|
@@ -6,6 +6,5 @@ const serializeAuthenticateUserWithCodeOptions = (options) => ({
|
|
|
6
6
|
client_id: options.clientId,
|
|
7
7
|
client_secret: options.clientSecret,
|
|
8
8
|
code: options.code,
|
|
9
|
-
expires_in: options.expiresIn,
|
|
10
9
|
});
|
|
11
10
|
exports.serializeAuthenticateUserWithCodeOptions = serializeAuthenticateUserWithCodeOptions;
|
|
@@ -9,6 +9,5 @@ const serializeAuthenticateUserWithMagicAuthOptions = (options) => ({
|
|
|
9
9
|
magic_auth_challenge_id: options.magicAuthChallengeId,
|
|
10
10
|
ip_address: options.ipAddress,
|
|
11
11
|
user_agent: options.userAgent,
|
|
12
|
-
expires_in: options.expiresIn,
|
|
13
12
|
});
|
|
14
13
|
exports.serializeAuthenticateUserWithMagicAuthOptions = serializeAuthenticateUserWithMagicAuthOptions;
|
|
@@ -9,6 +9,5 @@ const serializeAuthenticateUserWithPasswordOptions = (options) => ({
|
|
|
9
9
|
password: options.password,
|
|
10
10
|
ip_address: options.ipAddress,
|
|
11
11
|
user_agent: options.userAgent,
|
|
12
|
-
expires_in: options.expiresIn,
|
|
13
12
|
});
|
|
14
13
|
exports.serializeAuthenticateUserWithPasswordOptions = serializeAuthenticateUserWithPasswordOptions;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deserializeAuthenticationResponse = void 0;
|
|
4
|
-
const session_serializer_1 = require("./session.serializer");
|
|
5
4
|
const user_serializer_1 = require("./user.serializer");
|
|
6
5
|
const deserializeAuthenticationResponse = (authenticationResponse) => ({
|
|
7
|
-
session: (0, session_serializer_1.deserializeSession)(authenticationResponse.session),
|
|
8
6
|
user: (0, user_serializer_1.deserializeUser)(authenticationResponse.user),
|
|
9
7
|
});
|
|
10
8
|
exports.deserializeAuthenticationResponse = deserializeAuthenticationResponse;
|
|
@@ -3,11 +3,9 @@ export * from './authenticate-user-with-magic-auth-options.serializer';
|
|
|
3
3
|
export * from './authenticate-user-with-password-options.serializer';
|
|
4
4
|
export * from './authentication-response.serializer';
|
|
5
5
|
export * from './complete-password-reset-options.serializer';
|
|
6
|
-
export * from './create-email-verification-challenge.serializer';
|
|
7
6
|
export * from './create-password-reset-challenge.serializer';
|
|
8
7
|
export * from './create-user-options.serializer';
|
|
9
8
|
export * from './send-magic-auth-code-options.serializer';
|
|
10
|
-
export * from './session.serializer';
|
|
11
9
|
export * from './update-user-options.serializer';
|
|
12
10
|
export * from './update-user-password-options.serializer';
|
|
13
11
|
export * from './user.serializer';
|
|
@@ -19,11 +19,9 @@ __exportStar(require("./authenticate-user-with-magic-auth-options.serializer"),
|
|
|
19
19
|
__exportStar(require("./authenticate-user-with-password-options.serializer"), exports);
|
|
20
20
|
__exportStar(require("./authentication-response.serializer"), exports);
|
|
21
21
|
__exportStar(require("./complete-password-reset-options.serializer"), exports);
|
|
22
|
-
__exportStar(require("./create-email-verification-challenge.serializer"), exports);
|
|
23
22
|
__exportStar(require("./create-password-reset-challenge.serializer"), exports);
|
|
24
23
|
__exportStar(require("./create-user-options.serializer"), exports);
|
|
25
24
|
__exportStar(require("./send-magic-auth-code-options.serializer"), exports);
|
|
26
|
-
__exportStar(require("./session.serializer"), exports);
|
|
27
25
|
__exportStar(require("./update-user-options.serializer"), exports);
|
|
28
26
|
__exportStar(require("./update-user-password-options.serializer"), exports);
|
|
29
27
|
__exportStar(require("./user.serializer"), exports);
|
package/lib/users/users.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
2
|
import { AutoPaginatable } from '../common/utils/pagination';
|
|
3
|
-
import { AddUserToOrganizationOptions, AuthenticateUserWithCodeOptions, AuthenticateUserWithMagicAuthOptions, AuthenticateUserWithPasswordOptions, AuthenticationResponse, CompletePasswordResetOptions,
|
|
3
|
+
import { AddUserToOrganizationOptions, AuthenticateUserWithCodeOptions, AuthenticateUserWithMagicAuthOptions, AuthenticateUserWithPasswordOptions, AuthenticationResponse, CompletePasswordResetOptions, CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreateUserOptions, DeleteUserOptions, EnrollUserInMfaFactorOptions, ListUsersOptions, RemoveUserFromOrganizationOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, UpdateUserPasswordOptions, User, VerifyEmailCodeOptions } from './interfaces';
|
|
4
4
|
import { Challenge, Factor } from '../mfa/interfaces';
|
|
5
5
|
export declare class Users {
|
|
6
6
|
private readonly workos;
|
|
@@ -11,9 +11,13 @@ export declare class Users {
|
|
|
11
11
|
authenticateUserWithMagicAuth(payload: AuthenticateUserWithMagicAuthOptions): Promise<AuthenticationResponse>;
|
|
12
12
|
authenticateUserWithPassword(payload: AuthenticateUserWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
13
13
|
authenticateUserWithCode(payload: AuthenticateUserWithCodeOptions): Promise<AuthenticationResponse>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
sendVerificationEmail({ userId, }: SendVerificationEmailOptions): Promise<{
|
|
15
|
+
user: User;
|
|
16
|
+
}>;
|
|
17
|
+
sendMagicAuthCode(options: SendMagicAuthCodeOptions): Promise<{
|
|
18
|
+
user: User;
|
|
19
|
+
}>;
|
|
20
|
+
verifyEmailCode({ code, userId, }: VerifyEmailCodeOptions): Promise<User>;
|
|
17
21
|
createPasswordResetChallenge(payload: CreatePasswordResetChallengeOptions): Promise<CreatePasswordResetChallengeResponse>;
|
|
18
22
|
completePasswordReset(payload: CompletePasswordResetOptions): Promise<User>;
|
|
19
23
|
addUserToOrganization({ userId, organizationId, }: AddUserToOrganizationOptions): Promise<User>;
|
package/lib/users/users.js
CHANGED
|
@@ -38,39 +38,37 @@ class Users {
|
|
|
38
38
|
}
|
|
39
39
|
authenticateUserWithMagicAuth(payload) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const { data } = yield this.workos.post('/users/
|
|
41
|
+
const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateUserWithMagicAuthOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
42
42
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
authenticateUserWithPassword(payload) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const { data } = yield this.workos.post('/users/
|
|
47
|
+
const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateUserWithPasswordOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
48
48
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
authenticateUserWithCode(payload) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const { data } = yield this.workos.post('/users/
|
|
53
|
+
const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateUserWithCodeOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
54
54
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
sendVerificationEmail({ userId, }) {
|
|
58
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const { data } = yield this.workos.post(`/users/${userId}/
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
return (0, serializers_1.deserializeCreateEmailVerificationChallengeResponse)(data);
|
|
59
|
+
const { data } = yield this.workos.post(`/users/${userId}/send_verification_email`, {});
|
|
60
|
+
return { user: (0, serializers_1.deserializeUser)(data.user) };
|
|
63
61
|
});
|
|
64
62
|
}
|
|
65
63
|
sendMagicAuthCode(options) {
|
|
66
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
65
|
const { data } = yield this.workos.post('/users/magic_auth/send', (0, serializers_1.serializeSendMagicAuthCodeOptions)(options));
|
|
68
|
-
return data;
|
|
66
|
+
return { user: (0, serializers_1.deserializeUser)(data.user) };
|
|
69
67
|
});
|
|
70
68
|
}
|
|
71
|
-
|
|
69
|
+
verifyEmailCode({ code, userId, }) {
|
|
72
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const { data } = yield this.workos.post(`/users/${userId}/
|
|
71
|
+
const { data } = yield this.workos.post(`/users/${userId}/verify_email_code`, {
|
|
74
72
|
code,
|
|
75
73
|
});
|
|
76
74
|
return (0, serializers_1.deserializeUser)(data);
|
package/lib/users/users.spec.js
CHANGED
|
@@ -17,7 +17,6 @@ const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
|
|
|
17
17
|
const workos_1 = require("../workos");
|
|
18
18
|
const user_json_1 = __importDefault(require("./fixtures/user.json"));
|
|
19
19
|
const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
|
|
20
|
-
const session_json_1 = __importDefault(require("./fixtures/session.json"));
|
|
21
20
|
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
22
21
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
23
22
|
const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
@@ -98,61 +97,48 @@ describe('UserManagement', () => {
|
|
|
98
97
|
});
|
|
99
98
|
describe('authenticateUserWithMagicAuth', () => {
|
|
100
99
|
it('sends a magic auth authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
-
mock.onPost('/users/
|
|
100
|
+
mock.onPost('/users/authenticate').reply(200, {
|
|
102
101
|
user: user_json_1.default,
|
|
103
|
-
session: session_json_1.default,
|
|
104
102
|
});
|
|
105
103
|
const resp = yield workos.users.authenticateUserWithMagicAuth({
|
|
106
104
|
clientId: 'proj_whatever',
|
|
107
105
|
code: '123456',
|
|
108
106
|
magicAuthChallengeId: 'auth_challenge_123',
|
|
109
107
|
});
|
|
110
|
-
expect(mock.history.post[0].url).toEqual('/users/
|
|
108
|
+
expect(mock.history.post[0].url).toEqual('/users/authenticate');
|
|
111
109
|
expect(resp).toMatchObject({
|
|
112
110
|
user: {
|
|
113
111
|
email: 'test01@example.com',
|
|
114
112
|
},
|
|
115
|
-
session: {
|
|
116
|
-
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
117
|
-
token: 'really-long-token',
|
|
118
|
-
},
|
|
119
113
|
});
|
|
120
114
|
}));
|
|
121
115
|
});
|
|
122
116
|
describe('authenticateUserWithPassword', () => {
|
|
123
117
|
it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
-
mock.onPost('/users/
|
|
118
|
+
mock.onPost('/users/authenticate').reply(200, {
|
|
125
119
|
user: user_json_1.default,
|
|
126
|
-
session: session_json_1.default,
|
|
127
120
|
});
|
|
128
121
|
const resp = yield workos.users.authenticateUserWithPassword({
|
|
129
122
|
clientId: 'proj_whatever',
|
|
130
123
|
email: 'test01@example.com',
|
|
131
124
|
password: 'extra-secure',
|
|
132
125
|
});
|
|
133
|
-
expect(mock.history.post[0].url).toEqual('/users/
|
|
126
|
+
expect(mock.history.post[0].url).toEqual('/users/authenticate');
|
|
134
127
|
expect(resp).toMatchObject({
|
|
135
128
|
user: {
|
|
136
129
|
email: 'test01@example.com',
|
|
137
130
|
},
|
|
138
|
-
session: {
|
|
139
|
-
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
140
|
-
token: 'really-long-token',
|
|
141
|
-
},
|
|
142
131
|
});
|
|
143
132
|
}));
|
|
144
133
|
});
|
|
145
134
|
describe('authenticateUserWithCode', () => {
|
|
146
135
|
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
-
mock
|
|
148
|
-
.onPost('/users/sessions/token')
|
|
149
|
-
.reply(200, { user: user_json_1.default, session: session_json_1.default });
|
|
136
|
+
mock.onPost('/users/authenticate').reply(200, { user: user_json_1.default });
|
|
150
137
|
const resp = yield workos.users.authenticateUserWithCode({
|
|
151
138
|
clientId: 'proj_whatever',
|
|
152
139
|
code: 'or this',
|
|
153
|
-
expiresIn: 15,
|
|
154
140
|
});
|
|
155
|
-
expect(mock.history.post[0].url).toEqual('/users/
|
|
141
|
+
expect(mock.history.post[0].url).toEqual('/users/authenticate');
|
|
156
142
|
expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
|
|
157
143
|
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
158
144
|
grant_type: 'authorization_code',
|
|
@@ -161,39 +147,41 @@ describe('UserManagement', () => {
|
|
|
161
147
|
user: {
|
|
162
148
|
email: 'test01@example.com',
|
|
163
149
|
},
|
|
164
|
-
session: {
|
|
165
|
-
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
166
|
-
token: 'really-long-token',
|
|
167
|
-
},
|
|
168
150
|
});
|
|
169
151
|
}));
|
|
170
152
|
});
|
|
171
|
-
describe('
|
|
153
|
+
describe('sendVerificationEmail', () => {
|
|
172
154
|
it('sends a Create Email Verification Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
-
mock
|
|
174
|
-
|
|
175
|
-
user: user_json_1.default
|
|
176
|
-
|
|
177
|
-
const resp = yield workos.users.createEmailVerificationChallenge({
|
|
155
|
+
mock
|
|
156
|
+
.onPost(`/users/${userId}/send_verification_email`)
|
|
157
|
+
.reply(200, { user: user_json_1.default });
|
|
158
|
+
const resp = yield workos.users.sendVerificationEmail({
|
|
178
159
|
userId,
|
|
179
|
-
verificationUrl: 'https://example.com/verify-email',
|
|
180
160
|
});
|
|
181
|
-
expect(mock.history.post[0].url).toEqual(`/users/${userId}/
|
|
161
|
+
expect(mock.history.post[0].url).toEqual(`/users/${userId}/send_verification_email`);
|
|
182
162
|
expect(resp).toMatchObject({
|
|
183
|
-
token: 'email-verification-challenge',
|
|
184
163
|
user: {
|
|
164
|
+
createdAt: '2023-07-18T02:07:19.911Z',
|
|
185
165
|
email: 'test01@example.com',
|
|
166
|
+
emailVerified: true,
|
|
167
|
+
firstName: 'Test 01',
|
|
168
|
+
id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
|
|
169
|
+
lastName: 'User',
|
|
170
|
+
object: 'user',
|
|
171
|
+
updatedAt: '2023-07-18T02:07:19.911Z',
|
|
186
172
|
},
|
|
187
173
|
});
|
|
188
174
|
}));
|
|
189
|
-
describe('
|
|
175
|
+
describe('verifyEmailCode', () => {
|
|
190
176
|
it('sends a Complete Email Verification request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
191
|
-
mock
|
|
192
|
-
|
|
177
|
+
mock
|
|
178
|
+
.onPost(`/users/user_123/verify_email_code`)
|
|
179
|
+
.reply(200, user_json_1.default);
|
|
180
|
+
const resp = yield workos.users.verifyEmailCode({
|
|
193
181
|
userId: 'user_123',
|
|
194
182
|
code: '123456',
|
|
195
183
|
});
|
|
196
|
-
expect(mock.history.post[0].url).toEqual(`/users/user_123/
|
|
184
|
+
expect(mock.history.post[0].url).toEqual(`/users/user_123/verify_email_code`);
|
|
197
185
|
expect(resp).toMatchObject({
|
|
198
186
|
email: 'test01@example.com',
|
|
199
187
|
});
|
|
@@ -207,14 +195,30 @@ describe('UserManagement', () => {
|
|
|
207
195
|
email_address: 'bob.loblaw@example.com',
|
|
208
196
|
})
|
|
209
197
|
.reply(200, {
|
|
210
|
-
|
|
198
|
+
user: {
|
|
199
|
+
object: 'user',
|
|
200
|
+
email: 'test01@example.com',
|
|
201
|
+
first_name: 'Test 01',
|
|
202
|
+
last_name: 'User',
|
|
203
|
+
email_verified: true,
|
|
204
|
+
created_at: '2023-07-18T02:07:19.911Z',
|
|
205
|
+
updated_at: '2023-07-18T02:07:19.911Z',
|
|
206
|
+
},
|
|
211
207
|
});
|
|
212
208
|
const response = yield workos.users.sendMagicAuthCode({
|
|
213
209
|
emailAddress: 'bob.loblaw@example.com',
|
|
214
210
|
});
|
|
215
211
|
expect(mock.history.post[0].url).toEqual('/users/magic_auth/send');
|
|
216
212
|
expect(response).toMatchObject({
|
|
217
|
-
|
|
213
|
+
user: {
|
|
214
|
+
object: 'user',
|
|
215
|
+
email: 'test01@example.com',
|
|
216
|
+
firstName: 'Test 01',
|
|
217
|
+
lastName: 'User',
|
|
218
|
+
emailVerified: true,
|
|
219
|
+
createdAt: '2023-07-18T02:07:19.911Z',
|
|
220
|
+
updatedAt: '2023-07-18T02:07:19.911Z',
|
|
221
|
+
},
|
|
218
222
|
});
|
|
219
223
|
}));
|
|
220
224
|
});
|
package/lib/workos.js
CHANGED
|
@@ -27,7 +27,7 @@ const mfa_1 = require("./mfa/mfa");
|
|
|
27
27
|
const audit_logs_1 = require("./audit-logs/audit-logs");
|
|
28
28
|
const users_1 = require("./users/users");
|
|
29
29
|
const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
|
|
30
|
-
const VERSION = '3.
|
|
30
|
+
const VERSION = '3.6.0';
|
|
31
31
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
32
32
|
class WorkOS {
|
|
33
33
|
constructor(key, options = {}) {
|
|
@@ -170,7 +170,7 @@ class WorkOS {
|
|
|
170
170
|
}
|
|
171
171
|
default: {
|
|
172
172
|
if (error || errorDescription) {
|
|
173
|
-
throw new exceptions_1.OauthException(status, requestID, error, errorDescription);
|
|
173
|
+
throw new exceptions_1.OauthException(status, requestID, error, errorDescription, data);
|
|
174
174
|
}
|
|
175
175
|
else if (code && errors) {
|
|
176
176
|
// Note: ideally this should be mapped directly with a `400` status code.
|
package/lib/workos.spec.js
CHANGED
|
@@ -149,7 +149,7 @@ describe('WorkOS', () => {
|
|
|
149
149
|
'X-Request-ID': 'a-request-id',
|
|
150
150
|
});
|
|
151
151
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
152
|
-
yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.OauthException(400, 'a-request-id', 'error', 'error description'));
|
|
152
|
+
yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.OauthException(400, 'a-request-id', 'error', 'error description', { error: 'error', error_description: 'error description' }));
|
|
153
153
|
}));
|
|
154
154
|
});
|
|
155
155
|
});
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { User, UserResponse } from './user.interface';
|
|
2
|
-
export interface CreateEmailVerificationChallengeOptions {
|
|
3
|
-
userId: string;
|
|
4
|
-
verificationUrl: string;
|
|
5
|
-
}
|
|
6
|
-
export interface SerializedCreateEmailVerificationChallengeOptions {
|
|
7
|
-
verification_url: string;
|
|
8
|
-
}
|
|
9
|
-
export interface CreateEmailVerificationChallengeResponse {
|
|
10
|
-
token: string;
|
|
11
|
-
user: User;
|
|
12
|
-
}
|
|
13
|
-
export interface CreateEmailVerificationChallengeResponseResponse {
|
|
14
|
-
token: string;
|
|
15
|
-
user: UserResponse;
|
|
16
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export interface Session {
|
|
2
|
-
id: string;
|
|
3
|
-
createdAt: string;
|
|
4
|
-
expiresAt: string;
|
|
5
|
-
authorizedOrganizations: AuthorizedOrganization[];
|
|
6
|
-
unauthorizedOrganizations: UnauthorizedOrganization[];
|
|
7
|
-
token: string;
|
|
8
|
-
}
|
|
9
|
-
interface OrganizationSummary {
|
|
10
|
-
id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
}
|
|
13
|
-
interface AuthorizedOrganization {
|
|
14
|
-
organization: OrganizationSummary;
|
|
15
|
-
}
|
|
16
|
-
type SessionAuthenticationMethod = 'GoogleOauth' | 'MagicAuth' | 'MicrosoftOauth' | 'Password';
|
|
17
|
-
export type UnauthorizedOrganizationReason = {
|
|
18
|
-
type: 'authentication_method_required';
|
|
19
|
-
allowedAuthenticationMethods: SessionAuthenticationMethod[];
|
|
20
|
-
};
|
|
21
|
-
export type UnauthorizedOrganizationReasonResponse = {
|
|
22
|
-
type: 'authentication_method_required';
|
|
23
|
-
allowed_authentication_methods: SessionAuthenticationMethod[];
|
|
24
|
-
};
|
|
25
|
-
export interface UnauthorizedOrganization {
|
|
26
|
-
organization: OrganizationSummary;
|
|
27
|
-
reasons: UnauthorizedOrganizationReason[];
|
|
28
|
-
}
|
|
29
|
-
export interface UnauthorizedOrganizationResponse {
|
|
30
|
-
organization: OrganizationSummary;
|
|
31
|
-
reasons: UnauthorizedOrganizationReasonResponse[];
|
|
32
|
-
}
|
|
33
|
-
export interface SessionResponse {
|
|
34
|
-
id: string;
|
|
35
|
-
created_at: string;
|
|
36
|
-
expires_at: string;
|
|
37
|
-
authorized_organizations: AuthorizedOrganization[];
|
|
38
|
-
unauthorized_organizations: UnauthorizedOrganizationResponse[];
|
|
39
|
-
token: string;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { CreateEmailVerificationChallengeResponse, CreateEmailVerificationChallengeResponseResponse } from '../interfaces';
|
|
2
|
-
export declare const deserializeCreateEmailVerificationChallengeResponse: (createEmailVerificationChallengeResponse: CreateEmailVerificationChallengeResponseResponse) => CreateEmailVerificationChallengeResponse;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deserializeCreateEmailVerificationChallengeResponse = void 0;
|
|
4
|
-
const user_serializer_1 = require("./user.serializer");
|
|
5
|
-
const deserializeCreateEmailVerificationChallengeResponse = (createEmailVerificationChallengeResponse) => ({
|
|
6
|
-
token: createEmailVerificationChallengeResponse.token,
|
|
7
|
-
user: (0, user_serializer_1.deserializeUser)(createEmailVerificationChallengeResponse.user),
|
|
8
|
-
});
|
|
9
|
-
exports.deserializeCreateEmailVerificationChallengeResponse = deserializeCreateEmailVerificationChallengeResponse;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Session, SessionResponse, UnauthorizedOrganization, UnauthorizedOrganizationReason, UnauthorizedOrganizationReasonResponse, UnauthorizedOrganizationResponse } from '../interfaces/session.interface';
|
|
2
|
-
export declare const deserializeSession: (session: SessionResponse) => Session;
|
|
3
|
-
export declare const deserializeUnauthorizedOrganization: (unauthorizedOrganization: UnauthorizedOrganizationResponse) => UnauthorizedOrganization;
|
|
4
|
-
export declare const deserializeUnauthorizedOrganizationReason: (unauthorizedOrganizationReason: UnauthorizedOrganizationReasonResponse) => UnauthorizedOrganizationReason;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deserializeUnauthorizedOrganizationReason = exports.deserializeUnauthorizedOrganization = exports.deserializeSession = void 0;
|
|
4
|
-
const deserializeSession = (session) => ({
|
|
5
|
-
id: session.id,
|
|
6
|
-
createdAt: session.created_at,
|
|
7
|
-
expiresAt: session.expires_at,
|
|
8
|
-
authorizedOrganizations: session.authorized_organizations,
|
|
9
|
-
unauthorizedOrganizations: session.unauthorized_organizations.map(exports.deserializeUnauthorizedOrganization),
|
|
10
|
-
token: session.token,
|
|
11
|
-
});
|
|
12
|
-
exports.deserializeSession = deserializeSession;
|
|
13
|
-
const deserializeUnauthorizedOrganization = (unauthorizedOrganization) => ({
|
|
14
|
-
organization: unauthorizedOrganization.organization,
|
|
15
|
-
reasons: unauthorizedOrganization.reasons.map(exports.deserializeUnauthorizedOrganizationReason),
|
|
16
|
-
});
|
|
17
|
-
exports.deserializeUnauthorizedOrganization = deserializeUnauthorizedOrganization;
|
|
18
|
-
const deserializeUnauthorizedOrganizationReason = (unauthorizedOrganizationReason) => ({
|
|
19
|
-
type: unauthorizedOrganizationReason.type,
|
|
20
|
-
allowedAuthenticationMethods: unauthorizedOrganizationReason.allowed_authentication_methods,
|
|
21
|
-
});
|
|
22
|
-
exports.deserializeUnauthorizedOrganizationReason = deserializeUnauthorizedOrganizationReason;
|
|
File without changes
|
/package/lib/users/interfaces/{session.interface.js → verify-email-code-options.interface.js}
RENAMED
|
File without changes
|