@workos-inc/node 2.5.0 → 2.5.1

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.
@@ -1,6 +1,6 @@
1
1
  export declare type ChallengeFactorOptions = {
2
- authentication_factor_id: string;
2
+ authenticationFactorId: string;
3
3
  } | {
4
- authentication_factor_id: string;
5
- sms_template: string;
4
+ authenticationFactorId: string;
5
+ smsTemplate: string;
6
6
  };
@@ -1,4 +1,4 @@
1
1
  export declare type VerifyFactorOptions = {
2
- authentication_challenge_id: string;
2
+ authenticationChallengeId: string;
3
3
  code: string;
4
4
  };
package/lib/mfa/mfa.js CHANGED
@@ -27,19 +27,39 @@ class Mfa {
27
27
  }
28
28
  enrollFactor(options) {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- const { data } = yield this.workos.post('/auth/factors/enroll', options);
30
+ const { data } = yield this.workos.post('/auth/factors/enroll', Object.assign({ type: options.type }, (() => {
31
+ switch (options.type) {
32
+ case 'sms':
33
+ return {
34
+ phone_number: options.phoneNumber,
35
+ };
36
+ case 'totp':
37
+ return {
38
+ totp_issuer: options.issuer,
39
+ totp_user: options.user,
40
+ };
41
+ default:
42
+ return {};
43
+ }
44
+ })()));
31
45
  return data;
32
46
  });
33
47
  }
34
48
  challengeFactor(options) {
35
49
  return __awaiter(this, void 0, void 0, function* () {
36
- const { data } = yield this.workos.post('/auth/factors/challenge', options);
50
+ const { data } = yield this.workos.post('/auth/factors/challenge', {
51
+ authentication_factor_id: options.authenticationFactorId,
52
+ sms_template: 'smsTemplate' in options ? options.smsTemplate : undefined,
53
+ });
37
54
  return data;
38
55
  });
39
56
  }
40
57
  verifyFactor(options) {
41
58
  return __awaiter(this, void 0, void 0, function* () {
42
- const { data } = yield this.workos.post('/auth/factors/verify', options);
59
+ const { data } = yield this.workos.post('/auth/factors/verify', {
60
+ authentication_challenge_id: options.authenticationChallengeId,
61
+ code: options.code,
62
+ });
43
63
  return data;
44
64
  });
45
65
  }
@@ -144,7 +144,11 @@ describe('MFA', () => {
144
144
  describe('with no sms template', () => {
145
145
  it('challenge a factor with no sms template', () => __awaiter(void 0, void 0, void 0, function* () {
146
146
  const mock = new axios_mock_adapter_1.default(axios_1.default);
147
- mock.onPost('/auth/factors/challenge').reply(200, {
147
+ mock
148
+ .onPost('/auth/factors/challenge', {
149
+ authentication_factor_id: 'auth_factor_1234',
150
+ })
151
+ .reply(200, {
148
152
  object: 'authentication_challenge',
149
153
  id: 'auth_challenge_1234',
150
154
  created_at: '2022-03-15T20:39:19.892Z',
@@ -157,7 +161,7 @@ describe('MFA', () => {
157
161
  apiHostname: 'api.workos.dev',
158
162
  });
159
163
  const challengeResponse = yield workos.mfa.challengeFactor({
160
- authentication_factor_id: 'auth_factor_1234',
164
+ authenticationFactorId: 'auth_factor_1234',
161
165
  });
162
166
  expect(challengeResponse).toMatchInlineSnapshot(`
163
167
  Object {
@@ -172,10 +176,15 @@ describe('MFA', () => {
172
176
  `);
173
177
  }));
174
178
  });
175
- describe('with totp', () => {
179
+ describe('with sms template', () => {
176
180
  it('challenge a factor with sms template', () => __awaiter(void 0, void 0, void 0, function* () {
177
181
  const mock = new axios_mock_adapter_1.default(axios_1.default);
178
- mock.onPost('/auth/factors/challenge').reply(200, {
182
+ mock
183
+ .onPost('/auth/factors/challenge', {
184
+ authentication_factor_id: 'auth_factor_1234',
185
+ sms_template: 'This is your code: 12345',
186
+ })
187
+ .reply(200, {
179
188
  object: 'authentication_challenge',
180
189
  id: 'auth_challenge_1234',
181
190
  created_at: '2022-03-15T20:39:19.892Z',
@@ -188,8 +197,8 @@ describe('MFA', () => {
188
197
  apiHostname: 'api.workos.dev',
189
198
  });
190
199
  const challengeResponse = yield workos.mfa.challengeFactor({
191
- authentication_factor_id: 'auth_factor_1234',
192
- sms_template: 'This is your code: 12345',
200
+ authenticationFactorId: 'auth_factor_1234',
201
+ smsTemplate: 'This is your code: 12345',
193
202
  });
194
203
  expect(challengeResponse).toMatchInlineSnapshot(`
195
204
  Object {
@@ -209,7 +218,12 @@ describe('MFA', () => {
209
218
  describe('verify with successful response', () => {
210
219
  it('verifies a successful factor', () => __awaiter(void 0, void 0, void 0, function* () {
211
220
  const mock = new axios_mock_adapter_1.default(axios_1.default);
212
- mock.onPost('/auth/factors/verify').reply(200, {
221
+ mock
222
+ .onPost('/auth/factors/verify', {
223
+ authentication_challenge_id: 'auth_challenge_1234',
224
+ code: '12345',
225
+ })
226
+ .reply(200, {
213
227
  challenge: {
214
228
  object: 'authentication_challenge',
215
229
  id: 'auth_challenge_1234',
@@ -225,7 +239,7 @@ describe('MFA', () => {
225
239
  apiHostname: 'api.workos.dev',
226
240
  });
227
241
  const verifyResponse = yield workos.mfa.verifyFactor({
228
- authentication_challenge_id: 'auth_challenge_1234',
242
+ authenticationChallengeId: 'auth_challenge_1234',
229
243
  code: '12345',
230
244
  });
231
245
  expect(verifyResponse).toMatchInlineSnapshot(`
package/lib/workos.js CHANGED
@@ -23,7 +23,7 @@ const portal_1 = require("./portal/portal");
23
23
  const sso_1 = require("./sso/sso");
24
24
  const webhooks_1 = require("./webhooks/webhooks");
25
25
  const mfa_1 = require("./mfa/mfa");
26
- const VERSION = '2.5.0';
26
+ const VERSION = '2.5.1';
27
27
  const DEFAULT_HOSTNAME = 'api.workos.com';
28
28
  class WorkOS {
29
29
  constructor(key, options = {}) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.5.0",
2
+ "version": "2.5.1",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",
@@ -44,10 +44,10 @@
44
44
  "@types/pluralize": "0.0.29",
45
45
  "axios-mock-adapter": "1.20.0",
46
46
  "jest": "27.5.1",
47
- "prettier": "2.6.0",
47
+ "prettier": "2.6.1",
48
48
  "supertest": "6.2.2",
49
- "ts-jest": "27.1.3",
49
+ "ts-jest": "27.1.4",
50
50
  "tslint": "6.1.3",
51
- "typescript": "4.6.2"
51
+ "typescript": "4.6.3"
52
52
  }
53
53
  }