@supabase/gotrue-js 2.0.1 → 2.2.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.
Files changed (44) hide show
  1. package/README.md +1 -1
  2. package/dist/main/GoTrueAdminApi.d.ts +6 -1
  3. package/dist/main/GoTrueAdminApi.d.ts.map +1 -1
  4. package/dist/main/GoTrueAdminApi.js +40 -2
  5. package/dist/main/GoTrueAdminApi.js.map +1 -1
  6. package/dist/main/GoTrueClient.d.ts +43 -1
  7. package/dist/main/GoTrueClient.d.ts.map +1 -1
  8. package/dist/main/GoTrueClient.js +207 -3
  9. package/dist/main/GoTrueClient.js.map +1 -1
  10. package/dist/main/index.d.ts.map +1 -1
  11. package/dist/main/index.js.map +1 -1
  12. package/dist/main/lib/helpers.d.ts +1 -0
  13. package/dist/main/lib/helpers.d.ts.map +1 -1
  14. package/dist/main/lib/helpers.js +11 -1
  15. package/dist/main/lib/helpers.js.map +1 -1
  16. package/dist/main/lib/types.d.ts +378 -1
  17. package/dist/main/lib/types.d.ts.map +1 -1
  18. package/dist/main/lib/version.d.ts +1 -1
  19. package/dist/main/lib/version.js +1 -1
  20. package/dist/module/GoTrueAdminApi.d.ts +6 -1
  21. package/dist/module/GoTrueAdminApi.d.ts.map +1 -1
  22. package/dist/module/GoTrueAdminApi.js +40 -2
  23. package/dist/module/GoTrueAdminApi.js.map +1 -1
  24. package/dist/module/GoTrueClient.d.ts +43 -1
  25. package/dist/module/GoTrueClient.d.ts.map +1 -1
  26. package/dist/module/GoTrueClient.js +208 -4
  27. package/dist/module/GoTrueClient.js.map +1 -1
  28. package/dist/module/index.d.ts.map +1 -1
  29. package/dist/module/index.js.map +1 -1
  30. package/dist/module/lib/helpers.d.ts +1 -0
  31. package/dist/module/lib/helpers.d.ts.map +1 -1
  32. package/dist/module/lib/helpers.js +9 -0
  33. package/dist/module/lib/helpers.js.map +1 -1
  34. package/dist/module/lib/types.d.ts +378 -1
  35. package/dist/module/lib/types.d.ts.map +1 -1
  36. package/dist/module/lib/version.d.ts +1 -1
  37. package/dist/module/lib/version.js +1 -1
  38. package/package.json +2 -2
  39. package/src/GoTrueAdminApi.ts +63 -3
  40. package/src/GoTrueClient.ts +259 -4
  41. package/src/index.ts +0 -1
  42. package/src/lib/helpers.ts +11 -0
  43. package/src/lib/types.ts +425 -0
  44. package/src/lib/version.ts +1 -1
package/src/lib/types.ts CHANGED
@@ -20,6 +20,11 @@ export type Provider =
20
20
  | 'twitter'
21
21
  | 'workos'
22
22
 
23
+ /**
24
+ * @experimental
25
+ */
26
+ export type AuthChangeEventMFA = 'MFA_CHALLENGE_VERIFIED'
27
+
23
28
  export type AuthChangeEvent =
24
29
  | 'PASSWORD_RECOVERY'
25
30
  | 'SIGNED_IN'
@@ -27,6 +32,7 @@ export type AuthChangeEvent =
27
32
  | 'TOKEN_REFRESHED'
28
33
  | 'USER_UPDATED'
29
34
  | 'USER_DELETED'
35
+ | AuthChangeEventMFA
30
36
 
31
37
  export type GoTrueClientOptions = {
32
38
  /* The URL of the GoTrue server. */
@@ -123,6 +129,25 @@ export interface Session {
123
129
  user: User
124
130
  }
125
131
 
132
+ /**
133
+ * An authentication methord reference (AMR) entry.
134
+ *
135
+ * An entry designates what method was used by the user to verify their
136
+ * identity and at what time.
137
+ *
138
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}.
139
+ */
140
+ export interface AMREntry {
141
+ /** Authentication method name. */
142
+ method: 'password' | 'otp' | 'oauth' | 'mfa/totp' | string
143
+
144
+ /**
145
+ * Timestamp when the method was successfully used. Represents number of
146
+ * seconds since 1st January 1970 (UNIX epoch) in UTC.
147
+ */
148
+ timestamp: number
149
+ }
150
+
126
151
  export interface UserIdentity {
127
152
  id: string
128
153
  user_id: string
@@ -135,6 +160,33 @@ export interface UserIdentity {
135
160
  updated_at?: string
136
161
  }
137
162
 
163
+ /**
164
+ * A MFA factor.
165
+ *
166
+ * @see {@link GoTrueMFAApi#enroll}
167
+ * @see {@link GoTrueMFAApi#listFactors}
168
+ * @see {@link GoTrueMFAAdminApi#listFactors}
169
+ */
170
+ export interface Factor {
171
+ /** ID of the factor. */
172
+ id: string
173
+
174
+ /** Friendly name of the factor, useful to disambiguate between multiple factors. */
175
+ friendly_name?: string
176
+
177
+ /**
178
+ * Type of factor. Only `totp` supported with this version but may change in
179
+ * future versions.
180
+ */
181
+ factor_type: 'totp' | string
182
+
183
+ /** Factor's status. */
184
+ status: 'verified' | 'unverified'
185
+
186
+ created_at: string
187
+ updated_at: string
188
+ }
189
+
138
190
  export interface UserAppMetadata {
139
191
  provider?: string
140
192
  [key: string]: any
@@ -165,6 +217,7 @@ export interface User {
165
217
  role?: string
166
218
  updated_at?: string
167
219
  identities?: UserIdentity[]
220
+ factors?: Factor[]
168
221
  }
169
222
 
170
223
  export interface UserAttributes {
@@ -258,6 +311,10 @@ export interface Subscription {
258
311
  unsubscribe: () => void
259
312
  }
260
313
 
314
+ export interface UpdatableFactorAttributes {
315
+ friendlyName: string
316
+ }
317
+
261
318
  export type SignUpWithPasswordCredentials =
262
319
  | {
263
320
  /** The user's email address. */
@@ -300,6 +357,12 @@ export type SignInWithPasswordCredentials =
300
357
  /** The user's password. */
301
358
  password: string
302
359
  options?: {
360
+ /**
361
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
362
+ *
363
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
364
+ */
365
+ data?: object
303
366
  /** Verification token received when the user completes the captcha on the site. */
304
367
  captchaToken?: string
305
368
  }
@@ -310,6 +373,12 @@ export type SignInWithPasswordCredentials =
310
373
  /** The user's password. */
311
374
  password: string
312
375
  options?: {
376
+ /**
377
+ * A custom data object to store the user's metadata. This maps to the `auth.users.user_metadata` column.
378
+ *
379
+ * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
380
+ */
381
+ data?: object
313
382
  /** Verification token received when the user completes the captcha on the site. */
314
383
  captchaToken?: string
315
384
  }
@@ -492,6 +561,362 @@ export type GenerateLinkType =
492
561
  | 'email_change_current'
493
562
  | 'email_change_new'
494
563
 
564
+ /**
565
+ * @experimental
566
+ */
567
+ export type MFAEnrollParams = {
568
+ factorType: 'totp'
569
+ issuer?: string
570
+ friendlyName?: string
571
+ }
572
+
573
+ /**
574
+ * @experimental
575
+ */
576
+ export type MFAUnenrollParams = {
577
+ /** ID of the factor being unenrolled. */
578
+ factorId: string
579
+ }
580
+
581
+ /**
582
+ * @experimental
583
+ */
584
+ export type MFAVerifyParams = {
585
+ /** ID of the factor being verified. */
586
+ factorId: string
587
+
588
+ /** ID of the challenge being verified. */
589
+ challengeId: string
590
+
591
+ /** Verification code provided by the user. */
592
+ code: string
593
+ }
594
+
595
+ /**
596
+ * @experimental
597
+ */
598
+ export type MFAChallengeParams = {
599
+ /** ID of the factor to be challenged. */
600
+ factorId: string
601
+ }
602
+
603
+ /**
604
+ * @experimental
605
+ */
606
+ export type MFAChallengeAndVerifyParams = {
607
+ /** ID of the factor being verified. */
608
+ factorId: string
609
+ /** Verification code provided by the user. */
610
+ code: string
611
+ }
612
+
613
+ /**
614
+ * @experimental
615
+ */
616
+ export type AuthMFAVerifyResponse =
617
+ | {
618
+ data: {
619
+ /** New access token (JWT) after successful verification. */
620
+ access_token: string
621
+
622
+ /** Type of token, typically `Bearer`. */
623
+ token_type: string
624
+
625
+ /** Number of seconds in which the access token will expire. */
626
+ expires_in: number
627
+
628
+ /** Refresh token you can use to obtain new access tokens when expired. */
629
+ refresh_token: string
630
+
631
+ /** Updated user profile. */
632
+ user: User
633
+ }
634
+ error: null
635
+ }
636
+ | {
637
+ data: null
638
+ error: AuthError
639
+ }
640
+
641
+ /**
642
+ * @experimental
643
+ */
644
+ export type AuthMFAEnrollResponse =
645
+ | {
646
+ data: {
647
+ /** ID of the factor that was just enrolled (in an unverified state). */
648
+ id: string
649
+
650
+ /** Type of MFA factor. Only `totp` supported for now. */
651
+ type: 'totp'
652
+
653
+ /** TOTP enrollment information. */
654
+ totp: {
655
+ /** Contains a QR code encoding the authenticator URI. You can
656
+ * convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
657
+ * the value. Avoid logging this value to the console. */
658
+ qr_code: string
659
+
660
+ /** The TOTP secret (also encoded in the QR code). Show this secret
661
+ * in a password-style field to the user, in case they are unable to
662
+ * scan the QR code. Avoid logging this value to the console. */
663
+ secret: string
664
+
665
+ /** The authenticator URI encoded within the QR code, should you need
666
+ * to use it. Avoid loggin this value to the console. */
667
+ uri: string
668
+ }
669
+ }
670
+ error: null
671
+ }
672
+ | {
673
+ data: null
674
+ error: AuthError
675
+ }
676
+
677
+ /**
678
+ * @experimental
679
+ */
680
+ export type AuthMFAUnenrollResponse =
681
+ | {
682
+ data: {
683
+ /** ID of the factor that was successfully unenrolled. */
684
+ id: string
685
+ }
686
+ error: null
687
+ }
688
+ | { data: null; error: AuthError }
689
+
690
+ /**
691
+ * @experimental
692
+ */
693
+ export type AuthMFAChallengeResponse =
694
+ | {
695
+ data: {
696
+ /** ID of the newly created challenge. */
697
+ id: string
698
+
699
+ /** Timestamp in UNIX seconds when this challenge will no longer be usable. */
700
+ expires_at: number
701
+ }
702
+ error: null
703
+ }
704
+ | { data: null; error: AuthError }
705
+
706
+ /**
707
+ * @experimental
708
+ */
709
+ export type AuthMFAListFactorsResponse =
710
+ | {
711
+ data: {
712
+ /** All available factors (verified and unverified). */
713
+ all: Factor[]
714
+
715
+ /** Only verified TOTP factors. (A subset of `all`.) */
716
+ totp: Factor[]
717
+ }
718
+ error: null
719
+ }
720
+ | { data: null; error: AuthError }
721
+
722
+ /**
723
+ * @experimental
724
+ */
725
+ export type AuthenticatorAssuranceLevels = 'aal1' | 'aal2'
726
+
727
+ /**
728
+ * @experimental
729
+ */
730
+ export type AuthMFAGetAuthenticatorAssuranceLevelResponse =
731
+ | {
732
+ data: {
733
+ /** Current AAL level of the session. */
734
+ currentLevel: AuthenticatorAssuranceLevels | null
735
+
736
+ /**
737
+ * Next possible AAL level for the session. If the next level is higher
738
+ * than the current one, the user should go through MFA.
739
+ *
740
+ * @see {@link GoTrueMFAApi#challenge}
741
+ */
742
+ nextLevel: AuthenticatorAssuranceLevels | null
743
+
744
+ /**
745
+ * A list of all authentication methods attached to this session. Use
746
+ * the information here to detect the last time a user verified a
747
+ * factor, for example if implementing a step-up scenario.
748
+ */
749
+ currentAuthenticationMethods: AMREntry[]
750
+ }
751
+ error: null
752
+ }
753
+ | { data: null; error: AuthError }
754
+
755
+ /**
756
+ * Contains the full multi-factor authentication API.
757
+ *
758
+ * @experimental
759
+ */
760
+ export interface GoTrueMFAApi {
761
+ /**
762
+ * Starts the enrollment process for a new Multi-Factor Authentication
763
+ * factor. This method creates a new factor in the 'unverified' state.
764
+ * Present the QR code or secret to the user and ask them to add it to their
765
+ * authenticator app. Ask the user to provide you with an authenticator code
766
+ * from their app and verify it by calling challenge and then verify.
767
+ *
768
+ * The first successful verification of an unverified factor activates the
769
+ * factor. All other sessions are logged out and the current one gets an
770
+ * `aal2` authenticator level.
771
+ *
772
+ * @see {@link GoTrueMFAApi#challenge}
773
+ * @see {@link GoTrueMFAApi#verify}
774
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}
775
+ *
776
+ * @experimental
777
+ */
778
+ enroll(params: MFAEnrollParams): Promise<AuthMFAEnrollResponse>
779
+
780
+ /**
781
+ * Prepares a challenge used to verify that a user has access to a MFA
782
+ * factor. Provide the challenge ID and verification code by calling
783
+ * {@link GoTrueMFAApi#verify}.
784
+ *
785
+ * @experimental
786
+ */
787
+ challenge(params: MFAChallengeParams): Promise<AuthMFAChallengeResponse>
788
+
789
+ /**
790
+ * Verifies a verification code against a challenge. The verification code is
791
+ * provided by the user by entering a code seen in their authenticator app.
792
+ *
793
+ * @see {@link GoTrueMFAApi#challenge}
794
+ *
795
+ * @experimental
796
+ */
797
+ verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse>
798
+
799
+ /**
800
+ * Unenroll removes a MFA factor. Unverified factors can safely be ignored
801
+ * and it's not necessary to unenroll them. Unenrolling a verified MFA factor
802
+ * cannot be done from a session with an `aal1` authenticator level.
803
+ *
804
+ * @experimental
805
+ */
806
+ unenroll(params: MFAUnenrollParams): Promise<AuthMFAUnenrollResponse>
807
+
808
+ /**
809
+ * Helper method which creates a challenge and immediately uses the given code to verify against it thereafter. The verification code is
810
+ * provided by the user by entering a code seen in their authenticator app.
811
+ *
812
+ * @see {@link GoTrueMFAApi#challengeAndVerify}
813
+ *
814
+ * @experimental
815
+ */
816
+ challengeAndVerify(params: MFAChallengeAndVerifyParams): Promise<AuthMFAVerifyResponse>
817
+
818
+ /**
819
+ * Returns the list of MFA factors enabled for this user. For most use cases
820
+ * you should consider using {@link
821
+ * GoTrueMFAApi#getAuthenticatorAssuranceLevel}. This uses a cached version
822
+ * of the factors and avoids incurring a network call. If you need to update
823
+ * this list, call {@link GoTrueClient#getUser} first.
824
+ *
825
+ * @see {@link GoTrueMFAApi#enroll}
826
+ * @see {@link GoTrueMFAApi#getAuthenticatorAssuranceLevel}
827
+ * @see {@link GoTrueClient#getUser}
828
+ *
829
+ * @experimental
830
+ */
831
+ listFactors(): Promise<AuthMFAListFactorsResponse>
832
+
833
+ /**
834
+ * Returns the Authenticator Assurance Level (AAL) for the active session.
835
+ *
836
+ * - `aal1` (or `null`) means that the user's identity has been verified only
837
+ * with a conventional login (email+password, OTP, magic link, social login,
838
+ * etc.).
839
+ * - `aal2` means that the user's identity has been verified both with a conventional login and at least one MFA factor.
840
+ *
841
+ * Although this method returns a promise, it's fairly quick (microseconds)
842
+ * and rarely uses the network. You can use this to check whether the current
843
+ * user needs to be shown a screen to verify their MFA factors.
844
+ *
845
+ * @experimental
846
+ */
847
+ getAuthenticatorAssuranceLevel(): Promise<AuthMFAGetAuthenticatorAssuranceLevelResponse>
848
+ }
849
+
850
+ /**
851
+ * @expermental
852
+ */
853
+ export type AuthMFAAdminDeleteFactorResponse =
854
+ | {
855
+ data: {
856
+ /** ID of the factor that was successfully deleted. */
857
+ id: string
858
+ }
859
+ error: null
860
+ }
861
+ | { data: null; error: AuthError }
862
+
863
+ /**
864
+ * @expermental
865
+ */
866
+ export type AuthMFAAdminDeleteFactorParams = {
867
+ /** ID of the MFA factor to delete. */
868
+ id: string
869
+
870
+ /** ID of the user whose factor is being deleted. */
871
+ userId: string
872
+ }
873
+
874
+ /**
875
+ * @expermental
876
+ */
877
+ export type AuthMFAAdminListFactorsResponse =
878
+ | {
879
+ data: {
880
+ /** All factors attached to the user. */
881
+ factors: Factor[]
882
+ }
883
+ error: null
884
+ }
885
+ | { data: null; error: AuthError }
886
+
887
+ /**
888
+ * @expermental
889
+ */
890
+ export type AuthMFAAdminListFactorsParams = {
891
+ /** ID of the user for which to list all MFA factors. */
892
+ userId: string
893
+ }
894
+
895
+ /**
896
+ * Contains the full multi-factor authentication administration API.
897
+ *
898
+ * @expermental
899
+ */
900
+ export interface GoTrueAdminMFAApi {
901
+ /**
902
+ * Lists all factors attached to a user.
903
+ *
904
+ * @experimental
905
+ */
906
+ listFactors(params: AuthMFAAdminListFactorsParams): Promise<AuthMFAAdminListFactorsResponse>
907
+
908
+ /**
909
+ * Deletes a factor on a user. This will log the user out of all active
910
+ * sessions (if the deleted factor was verified). There's no need to delete
911
+ * unverified factors.
912
+ *
913
+ * @see {@link GoTrueMFAApi#unenroll}
914
+ *
915
+ * @expermental
916
+ */
917
+ deleteFactor(params: AuthMFAAdminDeleteFactorParams): Promise<AuthMFAAdminDeleteFactorResponse>
918
+ }
919
+
495
920
  type AnyFunction = (...args: any[]) => any
496
921
  type MaybePromisify<T> = T | Promise<T>
497
922
 
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '2.0.1'
2
+ export const version = '2.2.0'