@workos-inc/node 3.4.0 → 3.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.
@@ -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,9 @@ 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';
15
+ export * from './send-verification-email-options';
16
16
  export * from './session.interface';
17
17
  export * from './update-user-options.interface';
18
18
  export * from './update-user-password-options.interface';
19
19
  export * from './user.interface';
20
- export * from './verify-email-options.interface';
20
+ 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,9 @@ __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);
31
+ __exportStar(require("./send-verification-email-options"), exports);
32
32
  __exportStar(require("./session.interface"), exports);
33
33
  __exportStar(require("./update-user-options.interface"), exports);
34
34
  __exportStar(require("./update-user-password-options.interface"), exports);
35
35
  __exportStar(require("./user.interface"), exports);
36
- __exportStar(require("./verify-email-options.interface"), exports);
36
+ __exportStar(require("./verify-email-code-options.interface"), exports);
@@ -0,0 +1,3 @@
1
+ export interface SendVerificationEmailOptions {
2
+ userId: string;
3
+ }
@@ -0,0 +1,7 @@
1
+ export interface VerifyEmailCodeOptions {
2
+ code: string;
3
+ userId: string;
4
+ }
5
+ export interface SerializedVerifyEmailCodeOptions {
6
+ code: string;
7
+ }
@@ -3,7 +3,6 @@ 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';
@@ -19,7 +19,6 @@ __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);
@@ -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, CreateEmailVerificationChallengeOptions, CreateEmailVerificationChallengeResponse, CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreateUserOptions, DeleteUserOptions, EnrollUserInMfaFactorOptions, ListUsersOptions, MagicAuthChallenge, RemoveUserFromOrganizationOptions, SendMagicAuthCodeOptions, UpdateUserOptions, UpdateUserPasswordOptions, User, VerifyEmailOptions } from './interfaces';
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
- createEmailVerificationChallenge({ userId, verificationUrl, }: CreateEmailVerificationChallengeOptions): Promise<CreateEmailVerificationChallengeResponse>;
15
- sendMagicAuthCode(options: SendMagicAuthCodeOptions): Promise<MagicAuthChallenge>;
16
- verifyEmail({ code, userId }: VerifyEmailOptions): Promise<User>;
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>;
@@ -54,23 +54,21 @@ class Users {
54
54
  return (0, serializers_1.deserializeAuthenticationResponse)(data);
55
55
  });
56
56
  }
57
- createEmailVerificationChallenge({ userId, verificationUrl, }) {
57
+ sendVerificationEmail({ userId, }) {
58
58
  return __awaiter(this, void 0, void 0, function* () {
59
- const { data } = yield this.workos.post(`/users/${userId}/email_verification_challenge`, {
60
- verification_url: verificationUrl,
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
- verifyEmail({ code, userId }) {
69
+ verifyEmailCode({ code, userId, }) {
72
70
  return __awaiter(this, void 0, void 0, function* () {
73
- const { data } = yield this.workos.post(`/users/${userId}/verify_email`, {
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);
@@ -168,32 +168,38 @@ describe('UserManagement', () => {
168
168
  });
169
169
  }));
170
170
  });
171
- describe('createEmailVerificationChallenge', () => {
171
+ describe('sendVerificationEmail', () => {
172
172
  it('sends a Create Email Verification Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
173
- mock.onPost(`/users/${userId}/email_verification_challenge`).reply(200, {
174
- token: 'email-verification-challenge',
175
- user: user_json_1.default,
176
- });
177
- const resp = yield workos.users.createEmailVerificationChallenge({
173
+ mock
174
+ .onPost(`/users/${userId}/send_verification_email`)
175
+ .reply(200, { user: user_json_1.default });
176
+ const resp = yield workos.users.sendVerificationEmail({
178
177
  userId,
179
- verificationUrl: 'https://example.com/verify-email',
180
178
  });
181
- expect(mock.history.post[0].url).toEqual(`/users/${userId}/email_verification_challenge`);
179
+ expect(mock.history.post[0].url).toEqual(`/users/${userId}/send_verification_email`);
182
180
  expect(resp).toMatchObject({
183
- token: 'email-verification-challenge',
184
181
  user: {
182
+ createdAt: '2023-07-18T02:07:19.911Z',
185
183
  email: 'test01@example.com',
184
+ emailVerified: true,
185
+ firstName: 'Test 01',
186
+ id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
187
+ lastName: 'User',
188
+ object: 'user',
189
+ updatedAt: '2023-07-18T02:07:19.911Z',
186
190
  },
187
191
  });
188
192
  }));
189
- describe('verifyEmail', () => {
193
+ describe('verifyEmailCode', () => {
190
194
  it('sends a Complete Email Verification request', () => __awaiter(void 0, void 0, void 0, function* () {
191
- mock.onPost(`/users/user_123/verify_email`).reply(200, user_json_1.default);
192
- const resp = yield workos.users.verifyEmail({
195
+ mock
196
+ .onPost(`/users/user_123/verify_email_code`)
197
+ .reply(200, user_json_1.default);
198
+ const resp = yield workos.users.verifyEmailCode({
193
199
  userId: 'user_123',
194
200
  code: '123456',
195
201
  });
196
- expect(mock.history.post[0].url).toEqual(`/users/user_123/verify_email`);
202
+ expect(mock.history.post[0].url).toEqual(`/users/user_123/verify_email_code`);
197
203
  expect(resp).toMatchObject({
198
204
  email: 'test01@example.com',
199
205
  });
@@ -207,14 +213,30 @@ describe('UserManagement', () => {
207
213
  email_address: 'bob.loblaw@example.com',
208
214
  })
209
215
  .reply(200, {
210
- id: 'auth_challenge_01E4ZCR3C56J083X43JQXF3JK5',
216
+ user: {
217
+ object: 'user',
218
+ email: 'test01@example.com',
219
+ first_name: 'Test 01',
220
+ last_name: 'User',
221
+ email_verified: true,
222
+ created_at: '2023-07-18T02:07:19.911Z',
223
+ updated_at: '2023-07-18T02:07:19.911Z',
224
+ },
211
225
  });
212
226
  const response = yield workos.users.sendMagicAuthCode({
213
227
  emailAddress: 'bob.loblaw@example.com',
214
228
  });
215
229
  expect(mock.history.post[0].url).toEqual('/users/magic_auth/send');
216
230
  expect(response).toMatchObject({
217
- id: 'auth_challenge_01E4ZCR3C56J083X43JQXF3JK5',
231
+ user: {
232
+ object: 'user',
233
+ email: 'test01@example.com',
234
+ firstName: 'Test 01',
235
+ lastName: 'User',
236
+ emailVerified: true,
237
+ createdAt: '2023-07-18T02:07:19.911Z',
238
+ updatedAt: '2023-07-18T02:07:19.911Z',
239
+ },
218
240
  });
219
241
  }));
220
242
  });
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.4.0';
30
+ const VERSION = '3.5.0';
31
31
  const DEFAULT_HOSTNAME = 'api.workos.com';
32
32
  class WorkOS {
33
33
  constructor(key, options = {}) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.4.0",
2
+ "version": "3.5.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -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,7 +0,0 @@
1
- export interface VerifyEmailOptions {
2
- code: string;
3
- userId: string;
4
- }
5
- export interface SerializedVerifyEmailOptions {
6
- code: string;
7
- }
@@ -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;