@stytch/vanilla-js 1.1.4 → 2.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @stytch/vanilla-js
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - a4083c7: Breaking Changes: The intermediate session token (IST) will no longer be accepted as an argument for the discovery list organizations, intermediate sessions exchange, and create organization via discovery endpoints. The IST will be passed in automatically. ISTs are stored as browser cookies or persisted on device when they are generated after calls to discovery authenticate endpoints, such as email magic link discovery authenticate, or primary authenticate endpoints in the case where MFA is required, such as email magic link authenticate or SSO authenticate.
8
+
9
+ New Features: Our B2B product now supports multi-factor authentication (MFA) with one-time passcodes (OTPs) via SMS. MFA policies can be set on the Organization level or on the Member level. See the Stytch docs for more information.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [a4083c7]
14
+ - @stytch/core@0.15.0
15
+
3
16
  ## 1.1.4
4
17
 
5
18
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { IHeadlessB2BSessionClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOAuthClient, IHeadlessB2BMemberClient, IHeadlessB2BSSOClient, IHeadlessB2BDiscoveryClient, StytchClientOptions } from "@stytch/core/public";
1
+ import { IHeadlessB2BSessionClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOAuthClient, IHeadlessB2BMemberClient, IHeadlessB2BSSOClient, IHeadlessB2BDiscoveryClient, IHeadlessB2BOTPsClient, StytchClientOptions } from "@stytch/core/public";
2
2
  import { Callbacks as Callbacks$0 } from "@stytch/core/public";
3
3
  import { StyleConfig as StyleConfig$0 } from "@stytch/core/public";
4
4
  import { StytchB2BUIConfig as StytchB2BUIConfig$0 } from "@stytch/core/public";
@@ -26,6 +26,7 @@ type SessionDurationOptions = {
26
26
  */
27
27
  session_duration_minutes: number;
28
28
  };
29
+ type locale = "en" | "es" | "pt-br" | string;
29
30
  // Authentication Factors
30
31
  interface B2BEmailFactor {
31
32
  delivery_method: "email";
@@ -35,8 +36,41 @@ interface B2BEmailFactor {
35
36
  email_id: string;
36
37
  email_address: string;
37
38
  };
39
+ sequence_order: "PRIMARY";
38
40
  }
39
- type B2BAuthenticationFactor = B2BEmailFactor;
41
+ interface B2BPhoneNumberFactor {
42
+ delivery_method: "sms" | "whatsapp";
43
+ type: string;
44
+ last_authenticated_at: string;
45
+ phone_number_factor: {
46
+ phone_id: string;
47
+ phone_number: string;
48
+ };
49
+ sequence_order: "SECONDARY";
50
+ }
51
+ interface B2BGoogleOAuthFactor {
52
+ delivery_method: "oauth_google";
53
+ type: string;
54
+ last_authenticated_at: string;
55
+ google_oauth_factor: {
56
+ id: string;
57
+ email_id: string;
58
+ provider_subject: string;
59
+ };
60
+ sequence_order: "PRIMARY";
61
+ }
62
+ interface B2BMicrosoftOAuthFactor {
63
+ delivery_method: "oauth_microsoft";
64
+ type: string;
65
+ last_authenticated_at: string;
66
+ microsoft_oauth_factor: {
67
+ id: string;
68
+ email_id: string;
69
+ provider_subject: string;
70
+ };
71
+ sequence_order: "PRIMARY";
72
+ }
73
+ type B2BAuthenticationFactor = B2BEmailFactor | B2BPhoneNumberFactor | B2BGoogleOAuthFactor | B2BMicrosoftOAuthFactor;
40
74
  type MemberResponseCommon = ResponseCommon & {
41
75
  /**
42
76
  * Globally unique UUID that identifies a specific member in the Stytch API.
@@ -146,6 +180,15 @@ interface Member {
146
180
  * Returned if the member has a registered password
147
181
  */
148
182
  member_password_id: string;
183
+ /**
184
+ * If true, the member must complete a secondary authentication flow, such as SMS OTP, along with their
185
+ * primary authentication factor in order to log in and attain a member session.
186
+ */
187
+ mfa_enrolled: boolean;
188
+ /**
189
+ * Returned if the member has a phone number
190
+ */
191
+ mfa_phone_number: string;
149
192
  }
150
193
  type B2BAuthenticateResponse = ResponseCommon & {
151
194
  /**
@@ -184,6 +227,30 @@ type B2BAuthenticateResponse = ResponseCommon & {
184
227
  */
185
228
  organization: Organization;
186
229
  };
230
+ type B2BAuthenticateResponseWithMFA = B2BAuthenticateResponse & {
231
+ /**
232
+ * The Member Session object.
233
+ * See {@link MemberSession} for details.
234
+ */
235
+ member_session: MemberSession | null;
236
+ /**
237
+ * Returns true if the member is fully authenticated, in which case a member session is returned.
238
+ * Returns false if the member still needs to complete a secondary authentication requirement,
239
+ * in which case an intermediate_session_token is returned.
240
+ */
241
+ member_authenticated: boolean;
242
+ /**
243
+ * If the intermediate_session_token is present, the member needs to complete MFA.
244
+ * The intermediate_session_token can be passed into a secondary authentication endpoint, such as OTP authenticate,
245
+ * in order to receive a member session. The intermediate_session_token can also be used with discovery endpoints
246
+ * to join a different organization or create a new organization.
247
+ */
248
+ intermediate_session_token: string;
249
+ /**
250
+ * Contains information about the member's options for completing MFA, if applicable.
251
+ */
252
+ mfa_required: MfaRequired | null;
253
+ };
187
254
  interface Organization {
188
255
  /**
189
256
  * Globally unique UUID that identifies an organization in the Stytch API.
@@ -218,6 +285,17 @@ interface Organization {
218
285
  email_invites: "ALL_ALLOWED" | "RESTRICTED" | "NOT_ALLOWED";
219
286
  auth_methods: "ALL_ALLOWED" | "RESTRICTED";
220
287
  allowed_auth_methods: string[];
288
+ mfa_policy: "OPTIONAL" | "REQUIRED_FOR_ALL";
289
+ }
290
+ interface MfaRequired {
291
+ member_options: MemberOptions;
292
+ /**
293
+ * Equal to 'sms_otp' if an OTP code was sent to the member's phone number.
294
+ */
295
+ secondary_auth_initiated: "sms_otp" | null;
296
+ }
297
+ interface MemberOptions {
298
+ mfa_phone_number: string;
221
299
  }
222
300
  type B2BPasswordAuthenticateOptions = SessionDurationOptions & {
223
301
  /**
@@ -232,8 +310,13 @@ type B2BPasswordAuthenticateOptions = SessionDurationOptions & {
232
310
  * The password for the Member.
233
311
  */
234
312
  password: string;
313
+ /**
314
+ * The locale will be used if an OTP code is sent to the member's phone number as part of a
315
+ * secondary authentication requirement.
316
+ */
317
+ locale?: locale;
235
318
  };
236
- type B2BPasswordAuthenticateResponse = B2BAuthenticateResponse;
319
+ type B2BPasswordAuthenticateResponse = B2BAuthenticateResponseWithMFA;
237
320
  type B2BPasswordResetByEmailStartOptions = {
238
321
  /**
239
322
  * The id of the Organization under which the Member and password belong
@@ -281,8 +364,13 @@ type B2BPasswordResetByEmailOptions = SessionDurationOptions & {
281
364
  * The new password for the Member.
282
365
  */
283
366
  password: string;
367
+ /**
368
+ * The locale will be used if an OTP code is sent to the member's phone number as part of a
369
+ * secondary authentication requirement.
370
+ */
371
+ locale?: locale;
284
372
  };
285
- type B2BPasswordResetByEmailResponse = B2BAuthenticateResponse;
373
+ type B2BPasswordResetByEmailResponse = B2BAuthenticateResponseWithMFA;
286
374
  type B2BPasswordResetByExistingPasswordOptions = SessionDurationOptions & {
287
375
  /**
288
376
  * The id of the Organization under which the Member and password belong
@@ -300,8 +388,13 @@ type B2BPasswordResetByExistingPasswordOptions = SessionDurationOptions & {
300
388
  * The new password for the Member.
301
389
  */
302
390
  new_password: string;
391
+ /**
392
+ * The locale will be used if an OTP code is sent to the member's phone number as part of a
393
+ * secondary authentication requirement.
394
+ */
395
+ locale?: locale;
303
396
  };
304
- type B2BPasswordResetByExistingPasswordResponse = B2BAuthenticateResponse;
397
+ type B2BPasswordResetByExistingPasswordResponse = B2BAuthenticateResponseWithMFA;
305
398
  type B2BPasswordResetBySessionOptions = {
306
399
  /**
307
400
  * The id of the Organization under which the Member and password belong
@@ -529,6 +622,7 @@ declare class StytchB2BHeadlessClient {
529
622
  sso: IHeadlessB2BSSOClient;
530
623
  discovery: IHeadlessB2BDiscoveryClient;
531
624
  passwords: IHeadlessB2BPasswordClient;
625
+ otps: IHeadlessB2BOTPsClient;
532
626
  constructor(_PUBLIC_TOKEN: string, options?: StytchClientOptions);
533
627
  }
534
628
  /**
@@ -1,4 +1,4 @@
1
- import { IHeadlessB2BSessionClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOAuthClient, IHeadlessB2BMemberClient, IHeadlessB2BSSOClient, IHeadlessB2BDiscoveryClient, StytchClientOptions } from "@stytch/core/public";
1
+ import { IHeadlessB2BSessionClient, IHeadlessB2BMagicLinksClient, IHeadlessB2BOrganizationClient, IHeadlessB2BOAuthClient, IHeadlessB2BMemberClient, IHeadlessB2BSSOClient, IHeadlessB2BDiscoveryClient, IHeadlessB2BOTPsClient, StytchClientOptions } from "@stytch/core/public";
2
2
  import { Callbacks as Callbacks$0 } from "@stytch/core/public";
3
3
  import { StyleConfig as StyleConfig$0 } from "@stytch/core/public";
4
4
  import { StytchB2BUIConfig as StytchB2BUIConfig$0 } from "@stytch/core/public";
@@ -26,6 +26,7 @@ type SessionDurationOptions = {
26
26
  */
27
27
  session_duration_minutes: number;
28
28
  };
29
+ type locale = "en" | "es" | "pt-br" | string;
29
30
  // Authentication Factors
30
31
  interface B2BEmailFactor {
31
32
  delivery_method: "email";
@@ -35,8 +36,41 @@ interface B2BEmailFactor {
35
36
  email_id: string;
36
37
  email_address: string;
37
38
  };
39
+ sequence_order: "PRIMARY";
38
40
  }
39
- type B2BAuthenticationFactor = B2BEmailFactor;
41
+ interface B2BPhoneNumberFactor {
42
+ delivery_method: "sms" | "whatsapp";
43
+ type: string;
44
+ last_authenticated_at: string;
45
+ phone_number_factor: {
46
+ phone_id: string;
47
+ phone_number: string;
48
+ };
49
+ sequence_order: "SECONDARY";
50
+ }
51
+ interface B2BGoogleOAuthFactor {
52
+ delivery_method: "oauth_google";
53
+ type: string;
54
+ last_authenticated_at: string;
55
+ google_oauth_factor: {
56
+ id: string;
57
+ email_id: string;
58
+ provider_subject: string;
59
+ };
60
+ sequence_order: "PRIMARY";
61
+ }
62
+ interface B2BMicrosoftOAuthFactor {
63
+ delivery_method: "oauth_microsoft";
64
+ type: string;
65
+ last_authenticated_at: string;
66
+ microsoft_oauth_factor: {
67
+ id: string;
68
+ email_id: string;
69
+ provider_subject: string;
70
+ };
71
+ sequence_order: "PRIMARY";
72
+ }
73
+ type B2BAuthenticationFactor = B2BEmailFactor | B2BPhoneNumberFactor | B2BGoogleOAuthFactor | B2BMicrosoftOAuthFactor;
40
74
  type MemberResponseCommon = ResponseCommon & {
41
75
  /**
42
76
  * Globally unique UUID that identifies a specific member in the Stytch API.
@@ -146,6 +180,15 @@ interface Member {
146
180
  * Returned if the member has a registered password
147
181
  */
148
182
  member_password_id: string;
183
+ /**
184
+ * If true, the member must complete a secondary authentication flow, such as SMS OTP, along with their
185
+ * primary authentication factor in order to log in and attain a member session.
186
+ */
187
+ mfa_enrolled: boolean;
188
+ /**
189
+ * Returned if the member has a phone number
190
+ */
191
+ mfa_phone_number: string;
149
192
  }
150
193
  type B2BAuthenticateResponse = ResponseCommon & {
151
194
  /**
@@ -184,6 +227,30 @@ type B2BAuthenticateResponse = ResponseCommon & {
184
227
  */
185
228
  organization: Organization;
186
229
  };
230
+ type B2BAuthenticateResponseWithMFA = B2BAuthenticateResponse & {
231
+ /**
232
+ * The Member Session object.
233
+ * See {@link MemberSession} for details.
234
+ */
235
+ member_session: MemberSession | null;
236
+ /**
237
+ * Returns true if the member is fully authenticated, in which case a member session is returned.
238
+ * Returns false if the member still needs to complete a secondary authentication requirement,
239
+ * in which case an intermediate_session_token is returned.
240
+ */
241
+ member_authenticated: boolean;
242
+ /**
243
+ * If the intermediate_session_token is present, the member needs to complete MFA.
244
+ * The intermediate_session_token can be passed into a secondary authentication endpoint, such as OTP authenticate,
245
+ * in order to receive a member session. The intermediate_session_token can also be used with discovery endpoints
246
+ * to join a different organization or create a new organization.
247
+ */
248
+ intermediate_session_token: string;
249
+ /**
250
+ * Contains information about the member's options for completing MFA, if applicable.
251
+ */
252
+ mfa_required: MfaRequired | null;
253
+ };
187
254
  interface Organization {
188
255
  /**
189
256
  * Globally unique UUID that identifies an organization in the Stytch API.
@@ -218,6 +285,17 @@ interface Organization {
218
285
  email_invites: "ALL_ALLOWED" | "RESTRICTED" | "NOT_ALLOWED";
219
286
  auth_methods: "ALL_ALLOWED" | "RESTRICTED";
220
287
  allowed_auth_methods: string[];
288
+ mfa_policy: "OPTIONAL" | "REQUIRED_FOR_ALL";
289
+ }
290
+ interface MfaRequired {
291
+ member_options: MemberOptions;
292
+ /**
293
+ * Equal to 'sms_otp' if an OTP code was sent to the member's phone number.
294
+ */
295
+ secondary_auth_initiated: "sms_otp" | null;
296
+ }
297
+ interface MemberOptions {
298
+ mfa_phone_number: string;
221
299
  }
222
300
  type B2BPasswordAuthenticateOptions = SessionDurationOptions & {
223
301
  /**
@@ -232,8 +310,13 @@ type B2BPasswordAuthenticateOptions = SessionDurationOptions & {
232
310
  * The password for the Member.
233
311
  */
234
312
  password: string;
313
+ /**
314
+ * The locale will be used if an OTP code is sent to the member's phone number as part of a
315
+ * secondary authentication requirement.
316
+ */
317
+ locale?: locale;
235
318
  };
236
- type B2BPasswordAuthenticateResponse = B2BAuthenticateResponse;
319
+ type B2BPasswordAuthenticateResponse = B2BAuthenticateResponseWithMFA;
237
320
  type B2BPasswordResetByEmailStartOptions = {
238
321
  /**
239
322
  * The id of the Organization under which the Member and password belong
@@ -281,8 +364,13 @@ type B2BPasswordResetByEmailOptions = SessionDurationOptions & {
281
364
  * The new password for the Member.
282
365
  */
283
366
  password: string;
367
+ /**
368
+ * The locale will be used if an OTP code is sent to the member's phone number as part of a
369
+ * secondary authentication requirement.
370
+ */
371
+ locale?: locale;
284
372
  };
285
- type B2BPasswordResetByEmailResponse = B2BAuthenticateResponse;
373
+ type B2BPasswordResetByEmailResponse = B2BAuthenticateResponseWithMFA;
286
374
  type B2BPasswordResetByExistingPasswordOptions = SessionDurationOptions & {
287
375
  /**
288
376
  * The id of the Organization under which the Member and password belong
@@ -300,8 +388,13 @@ type B2BPasswordResetByExistingPasswordOptions = SessionDurationOptions & {
300
388
  * The new password for the Member.
301
389
  */
302
390
  new_password: string;
391
+ /**
392
+ * The locale will be used if an OTP code is sent to the member's phone number as part of a
393
+ * secondary authentication requirement.
394
+ */
395
+ locale?: locale;
303
396
  };
304
- type B2BPasswordResetByExistingPasswordResponse = B2BAuthenticateResponse;
397
+ type B2BPasswordResetByExistingPasswordResponse = B2BAuthenticateResponseWithMFA;
305
398
  type B2BPasswordResetBySessionOptions = {
306
399
  /**
307
400
  * The id of the Organization under which the Member and password belong
@@ -529,6 +622,7 @@ declare class StytchB2BHeadlessClient {
529
622
  sso: IHeadlessB2BSSOClient;
530
623
  discovery: IHeadlessB2BDiscoveryClient;
531
624
  passwords: IHeadlessB2BPasswordClient;
625
+ otps: IHeadlessB2BOTPsClient;
532
626
  constructor(_PUBLIC_TOKEN: string, options?: StytchClientOptions);
533
627
  }
534
628
  /**