@supabase/auth-js 2.72.1-rc.1 → 2.73.0-rc.5

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 (72) hide show
  1. package/dist/main/GoTrueClient.d.ts +7 -1
  2. package/dist/main/GoTrueClient.d.ts.map +1 -1
  3. package/dist/main/GoTrueClient.js +114 -33
  4. package/dist/main/GoTrueClient.js.map +1 -1
  5. package/dist/main/lib/base64url.d.ts +3 -2
  6. package/dist/main/lib/base64url.d.ts.map +1 -1
  7. package/dist/main/lib/base64url.js.map +1 -1
  8. package/dist/main/lib/errors.d.ts +1 -1
  9. package/dist/main/lib/errors.d.ts.map +1 -1
  10. package/dist/main/lib/errors.js.map +1 -1
  11. package/dist/main/lib/helpers.d.ts +2 -1
  12. package/dist/main/lib/helpers.d.ts.map +1 -1
  13. package/dist/main/lib/helpers.js.map +1 -1
  14. package/dist/main/lib/types.d.ts +329 -314
  15. package/dist/main/lib/types.d.ts.map +1 -1
  16. package/dist/main/lib/types.js +17 -0
  17. package/dist/main/lib/types.js.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/main/lib/webauthn.d.ts +274 -0
  21. package/dist/main/lib/webauthn.d.ts.map +1 -0
  22. package/dist/main/lib/webauthn.dom.d.ts +583 -0
  23. package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
  24. package/dist/main/lib/webauthn.dom.js +4 -0
  25. package/dist/main/lib/webauthn.dom.js.map +1 -0
  26. package/dist/main/lib/webauthn.errors.d.ts +80 -0
  27. package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
  28. package/dist/main/lib/webauthn.errors.js +265 -0
  29. package/dist/main/lib/webauthn.errors.js.map +1 -0
  30. package/dist/main/lib/webauthn.js +702 -0
  31. package/dist/main/lib/webauthn.js.map +1 -0
  32. package/dist/module/GoTrueClient.d.ts +7 -1
  33. package/dist/module/GoTrueClient.d.ts.map +1 -1
  34. package/dist/module/GoTrueClient.js +120 -39
  35. package/dist/module/GoTrueClient.js.map +1 -1
  36. package/dist/module/lib/base64url.d.ts +3 -2
  37. package/dist/module/lib/base64url.d.ts.map +1 -1
  38. package/dist/module/lib/base64url.js.map +1 -1
  39. package/dist/module/lib/errors.d.ts +1 -1
  40. package/dist/module/lib/errors.d.ts.map +1 -1
  41. package/dist/module/lib/errors.js.map +1 -1
  42. package/dist/module/lib/helpers.d.ts +2 -1
  43. package/dist/module/lib/helpers.d.ts.map +1 -1
  44. package/dist/module/lib/helpers.js.map +1 -1
  45. package/dist/module/lib/types.d.ts +329 -314
  46. package/dist/module/lib/types.d.ts.map +1 -1
  47. package/dist/module/lib/types.js +17 -0
  48. package/dist/module/lib/types.js.map +1 -1
  49. package/dist/module/lib/version.d.ts +1 -1
  50. package/dist/module/lib/version.js +1 -1
  51. package/dist/module/lib/webauthn.d.ts +274 -0
  52. package/dist/module/lib/webauthn.d.ts.map +1 -0
  53. package/dist/module/lib/webauthn.dom.d.ts +583 -0
  54. package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
  55. package/dist/module/lib/webauthn.dom.js +3 -0
  56. package/dist/module/lib/webauthn.dom.js.map +1 -0
  57. package/dist/module/lib/webauthn.errors.d.ts +80 -0
  58. package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
  59. package/dist/module/lib/webauthn.errors.js +257 -0
  60. package/dist/module/lib/webauthn.errors.js.map +1 -0
  61. package/dist/module/lib/webauthn.js +685 -0
  62. package/dist/module/lib/webauthn.js.map +1 -0
  63. package/package.json +1 -1
  64. package/src/GoTrueClient.ts +282 -81
  65. package/src/lib/base64url.ts +4 -2
  66. package/src/lib/errors.ts +1 -1
  67. package/src/lib/helpers.ts +2 -1
  68. package/src/lib/types.ts +465 -353
  69. package/src/lib/version.ts +1 -1
  70. package/src/lib/webauthn.dom.ts +636 -0
  71. package/src/lib/webauthn.errors.ts +317 -0
  72. package/src/lib/webauthn.ts +929 -0
@@ -1,8 +1,9 @@
1
- import { EIP1193Provider } from './web3/ethereum';
2
1
  import { AuthError } from './errors';
3
2
  import { Fetch } from './fetch';
3
+ import { EIP1193Provider, EthereumSignInInput, Hex } from './web3/ethereum';
4
4
  import type { SolanaSignInInput, SolanaSignInOutput } from './web3/solana';
5
- import { EthereumSignInInput, Hex } from './web3/ethereum';
5
+ import { ServerCredentialCreationOptions, ServerCredentialRequestOptions, WebAuthnApi } from './webauthn';
6
+ import { AuthenticationCredential, PublicKeyCredentialCreationOptionsFuture, PublicKeyCredentialRequestOptionsFuture, RegistrationCredential } from './webauthn.dom';
6
7
  /** One of the providers supported by GoTrue. */
7
8
  export declare type Provider = 'apple' | 'azure' | 'bitbucket' | 'discord' | 'facebook' | 'figma' | 'github' | 'gitlab' | 'google' | 'kakao' | 'keycloak' | 'linkedin' | 'linkedin_oidc' | 'notion' | 'slack' | 'slack_oidc' | 'spotify' | 'twitch' | 'twitter' | 'workos' | 'zoom' | 'fly';
8
9
  export declare type AuthChangeEventMFA = 'MFA_CHALLENGE_VERIFIED';
@@ -56,86 +57,76 @@ export declare type GoTrueClientOptions = {
56
57
  */
57
58
  hasCustomAuthorizationHeader?: boolean;
58
59
  };
59
- export declare type WeakPasswordReasons = 'length' | 'characters' | 'pwned' | (string & {});
60
+ declare const WeakPasswordReasons: readonly ["length", "characters", "pwned"];
61
+ export declare type WeakPasswordReasons = typeof WeakPasswordReasons[number];
60
62
  export declare type WeakPassword = {
61
63
  reasons: WeakPasswordReasons[];
62
64
  message: string;
63
65
  };
64
- export declare type AuthResponse = {
65
- data: {
66
- user: User | null;
67
- session: Session | null;
68
- };
66
+ /**
67
+ * Resolve mapped types and show the derived keys and their types when hovering in
68
+ * VS Code, instead of just showing the names those mapped types are defined with.
69
+ */
70
+ export declare type Prettify<T> = T extends Function ? T : {
71
+ [K in keyof T]: T[K];
72
+ };
73
+ /**
74
+ * A stricter version of TypeScript's Omit that only allows omitting keys that actually exist.
75
+ * This prevents typos and ensures type safety at compile time.
76
+ * Unlike regular Omit, this will error if you try to omit a non-existent key.
77
+ */
78
+ export declare type StrictOmit<T, K extends keyof T> = Omit<T, K>;
79
+ /**
80
+ * a shared result type that encapsulates errors instead of throwing them, allows you to optionally specify the ErrorType
81
+ */
82
+ export declare type RequestResult<T, ErrorType extends Error = AuthError> = {
83
+ data: T;
69
84
  error: null;
70
85
  } | {
71
- data: {
72
- user: null;
73
- session: null;
74
- };
75
- error: AuthError;
86
+ data: null;
87
+ error: Error extends AuthError ? AuthError : ErrorType;
76
88
  };
77
- export declare type AuthResponsePassword = {
78
- data: {
79
- user: User | null;
80
- session: Session | null;
81
- weak_password?: WeakPassword | null;
82
- };
89
+ /**
90
+ * similar to RequestResult except it allows you to destructure the possible shape of the success response
91
+ * {@see RequestResult}
92
+ */
93
+ export declare type RequestResultSafeDestructure<T> = {
94
+ data: T;
83
95
  error: null;
84
96
  } | {
85
- data: {
86
- user: null;
87
- session: null;
88
- };
97
+ data: T extends object ? {
98
+ [K in keyof T]: null;
99
+ } : null;
89
100
  error: AuthError;
90
101
  };
102
+ export declare type AuthResponse = RequestResultSafeDestructure<{
103
+ user: User | null;
104
+ session: Session | null;
105
+ }>;
106
+ export declare type AuthResponsePassword = RequestResultSafeDestructure<{
107
+ user: User | null;
108
+ session: Session | null;
109
+ weak_password?: WeakPassword | null;
110
+ }>;
91
111
  /**
92
112
  * AuthOtpResponse is returned when OTP is used.
93
113
  *
94
114
  * {@see AuthResponse}
95
115
  */
96
- export declare type AuthOtpResponse = {
97
- data: {
98
- user: null;
99
- session: null;
100
- messageId?: string | null;
101
- };
102
- error: null;
103
- } | {
104
- data: {
105
- user: null;
106
- session: null;
107
- messageId?: string | null;
108
- };
109
- error: AuthError;
110
- };
111
- export declare type AuthTokenResponse = {
112
- data: {
113
- user: User;
114
- session: Session;
115
- };
116
- error: null;
117
- } | {
118
- data: {
119
- user: null;
120
- session: null;
121
- };
122
- error: AuthError;
123
- };
124
- export declare type AuthTokenResponsePassword = {
125
- data: {
126
- user: User;
127
- session: Session;
128
- weakPassword?: WeakPassword;
129
- };
130
- error: null;
131
- } | {
132
- data: {
133
- user: null;
134
- session: null;
135
- weakPassword?: null;
136
- };
137
- error: AuthError;
138
- };
116
+ export declare type AuthOtpResponse = RequestResultSafeDestructure<{
117
+ user: null;
118
+ session: null;
119
+ messageId?: string | null;
120
+ }>;
121
+ export declare type AuthTokenResponse = RequestResultSafeDestructure<{
122
+ user: User;
123
+ session: Session;
124
+ }>;
125
+ export declare type AuthTokenResponsePassword = RequestResultSafeDestructure<{
126
+ user: User;
127
+ session: Session;
128
+ weakPassword?: WeakPassword;
129
+ }>;
139
130
  export declare type OAuthResponse = {
140
131
  data: {
141
132
  provider: Provider;
@@ -149,33 +140,19 @@ export declare type OAuthResponse = {
149
140
  };
150
141
  error: AuthError;
151
142
  };
152
- export declare type SSOResponse = {
153
- data: {
154
- /**
155
- * URL to open in a browser which will complete the sign-in flow by
156
- * taking the user to the identity provider's authentication flow.
157
- *
158
- * On browsers you can set the URL to `window.location.href` to take
159
- * the user to the authentication flow.
160
- */
161
- url: string;
162
- };
163
- error: null;
164
- } | {
165
- data: null;
166
- error: AuthError;
167
- };
168
- export declare type UserResponse = {
169
- data: {
170
- user: User;
171
- };
172
- error: null;
173
- } | {
174
- data: {
175
- user: null;
176
- };
177
- error: AuthError;
178
- };
143
+ export declare type SSOResponse = RequestResult<{
144
+ /**
145
+ * URL to open in a browser which will complete the sign-in flow by
146
+ * taking the user to the identity provider's authentication flow.
147
+ *
148
+ * On browsers you can set the URL to `window.location.href` to take
149
+ * the user to the authentication flow.
150
+ */
151
+ url: string;
152
+ }>;
153
+ export declare type UserResponse = RequestResultSafeDestructure<{
154
+ user: User;
155
+ }>;
179
156
  export interface Session {
180
157
  /**
181
158
  * The oauth provider token. If present, this can be used to make external API requests to the oauth provider used.
@@ -202,12 +179,14 @@ export interface Session {
202
179
  * A timestamp of when the token will expire. Returned when a login is confirmed.
203
180
  */
204
181
  expires_at?: number;
205
- token_type: string;
182
+ token_type: 'bearer';
206
183
  /**
207
184
  * When using a separate user storage, accessing properties of this object will throw an error.
208
185
  */
209
186
  user: User;
210
187
  }
188
+ declare const AMRMethods: readonly ["password", "otp", "oauth", "totp", "mfa/totp", "mfa/phone", "mfa/webauthn", "anonymous", "sso/saml", "magiclink", "web3"];
189
+ export declare type AMRMethod = typeof AMRMethods[number] | (string & {});
211
190
  /**
212
191
  * An authentication methord reference (AMR) entry.
213
192
  *
@@ -218,7 +197,7 @@ export interface Session {
218
197
  */
219
198
  export interface AMREntry {
220
199
  /** Authentication method name. */
221
- method: 'password' | 'otp' | 'oauth' | 'mfa/totp' | (string & {});
200
+ method: AMRMethod;
222
201
  /**
223
202
  * Timestamp when the method was successfully used. Represents number of
224
203
  * seconds since 1st January 1970 (UNIX epoch) in UTC.
@@ -237,6 +216,16 @@ export interface UserIdentity {
237
216
  last_sign_in_at?: string;
238
217
  updated_at?: string;
239
218
  }
219
+ declare const FactorTypes: readonly ["totp", "phone", "webauthn"];
220
+ /**
221
+ * Type of factor. `totp` and `phone` supported with this version
222
+ */
223
+ export declare type FactorType = typeof FactorTypes[number];
224
+ declare const FactorVerificationStatuses: readonly ["verified", "unverified"];
225
+ /**
226
+ * The verification status of the factor, default is `unverified` after `.enroll()`, then `verified` after the user verifies it with `.verify()`
227
+ */
228
+ declare type FactorVerificationStatus = typeof FactorVerificationStatuses[number];
240
229
  /**
241
230
  * A MFA factor.
242
231
  *
@@ -244,7 +233,7 @@ export interface UserIdentity {
244
233
  * @see {@link GoTrueMFAApi#listFactors}
245
234
  * @see {@link GoTrueMFAAdminApi#listFactors}
246
235
  */
247
- export interface Factor {
236
+ export declare type Factor<Type extends FactorType = FactorType, Status extends FactorVerificationStatus = typeof FactorVerificationStatuses[number]> = {
248
237
  /** ID of the factor. */
249
238
  id: string;
250
239
  /** Friendly name of the factor, useful to disambiguate between multiple factors. */
@@ -252,12 +241,14 @@ export interface Factor {
252
241
  /**
253
242
  * Type of factor. `totp` and `phone` supported with this version
254
243
  */
255
- factor_type: 'totp' | 'phone' | (string & {});
256
- /** Factor's status. */
257
- status: 'verified' | 'unverified';
244
+ factor_type: Type;
245
+ /**
246
+ * The verification status of the factor, default is `unverified` after `.enroll()`, then `verified` after the user verifies it with `.verify()`
247
+ */
248
+ status: Status;
258
249
  created_at: string;
259
250
  updated_at: string;
260
- }
251
+ };
261
252
  export interface UserAppMetadata {
262
253
  provider?: string;
263
254
  [key: string]: any;
@@ -289,7 +280,7 @@ export interface User {
289
280
  identities?: UserIdentity[];
290
281
  is_anonymous?: boolean;
291
282
  is_sso_user?: boolean;
292
- factors?: Factor[];
283
+ factors?: (Factor<FactorType, 'verified'> | Factor<FactorType, 'unverified'>)[];
293
284
  deleted_at?: string;
294
285
  }
295
286
  export interface UserAttributes {
@@ -412,57 +403,23 @@ export declare type SignInAnonymouslyCredentials = {
412
403
  captchaToken?: string;
413
404
  };
414
405
  };
415
- export declare type SignUpWithPasswordCredentials = {
416
- /** The user's email address. */
417
- email: string;
418
- /** The user's password. */
419
- password: string;
406
+ export declare type SignUpWithPasswordCredentials = Prettify<PasswordCredentialsBase & {
420
407
  options?: {
421
- /** The redirect url embedded in the email link */
422
408
  emailRedirectTo?: string;
423
- /**
424
- * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
425
- *
426
- * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
427
- */
428
409
  data?: object;
429
- /** Verification token received when the user completes the captcha on the site. */
430
410
  captchaToken?: string;
431
- };
432
- } | {
433
- /** The user's phone number. */
434
- phone: string;
435
- /** The user's password. */
436
- password: string;
437
- options?: {
438
- /**
439
- * A custom data object to store the user's metadata. This maps to the `auth.users.raw_user_meta_data` column.
440
- *
441
- * The `data` should be a JSON object that includes user-specific info, such as their first and last name.
442
- */
443
- data?: object;
444
- /** Verification token received when the user completes the captcha on the site. Requires a configured WhatsApp sender on Twilio */
445
- captchaToken?: string;
446
- /** Messaging channel to use (e.g. whatsapp or sms) */
447
411
  channel?: 'sms' | 'whatsapp';
448
412
  };
449
- };
450
- export declare type SignInWithPasswordCredentials = {
451
- /** The user's email address. */
413
+ }>;
414
+ declare type PasswordCredentialsBase = {
452
415
  email: string;
453
- /** The user's password. */
454
416
  password: string;
455
- options?: {
456
- /** Verification token received when the user completes the captcha on the site. */
457
- captchaToken?: string;
458
- };
459
417
  } | {
460
- /** The user's phone number. */
461
418
  phone: string;
462
- /** The user's password. */
463
419
  password: string;
420
+ };
421
+ export declare type SignInWithPasswordCredentials = PasswordCredentialsBase & {
464
422
  options?: {
465
- /** Verification token received when the user completes the captcha on the site. */
466
423
  captchaToken?: string;
467
424
  };
468
425
  };
@@ -708,19 +665,10 @@ export interface GenerateLinkOptions {
708
665
  redirectTo?: string;
709
666
  }
710
667
  export declare type GenerateLinkParams = GenerateSignupLinkParams | GenerateInviteOrMagiclinkParams | GenerateRecoveryLinkParams | GenerateEmailChangeLinkParams;
711
- export declare type GenerateLinkResponse = {
712
- data: {
713
- properties: GenerateLinkProperties;
714
- user: User;
715
- };
716
- error: null;
717
- } | {
718
- data: {
719
- properties: null;
720
- user: null;
721
- };
722
- error: AuthError;
723
- };
668
+ export declare type GenerateLinkResponse = RequestResultSafeDestructure<{
669
+ properties: GenerateLinkProperties;
670
+ user: User;
671
+ }>;
724
672
  /** The properties related to the email link generated */
725
673
  export declare type GenerateLinkProperties = {
726
674
  /**
@@ -743,112 +691,190 @@ export declare type GenerateLinkProperties = {
743
691
  verification_type: GenerateLinkType;
744
692
  };
745
693
  export declare type GenerateLinkType = 'signup' | 'invite' | 'magiclink' | 'recovery' | 'email_change_current' | 'email_change_new';
746
- export declare type MFAEnrollParams = MFAEnrollTOTPParams | MFAEnrollPhoneParams;
694
+ export declare type MFAEnrollParams = MFAEnrollTOTPParams | MFAEnrollPhoneParams | MFAEnrollWebauthnParams;
747
695
  export declare type MFAUnenrollParams = {
748
696
  /** ID of the factor being unenrolled. */
749
697
  factorId: string;
750
698
  };
751
- export declare type MFAVerifyParams = {
699
+ declare type MFAVerifyParamsBase = {
752
700
  /** ID of the factor being verified. Returned in enroll(). */
753
701
  factorId: string;
754
702
  /** ID of the challenge being verified. Returned in challenge(). */
755
703
  challengeId: string;
704
+ };
705
+ declare type MFAVerifyTOTPParamFields = {
756
706
  /** Verification code provided by the user. */
757
707
  code: string;
758
708
  };
759
- export declare type MFAChallengeParams = {
709
+ export declare type MFAVerifyTOTPParams = Prettify<MFAVerifyParamsBase & MFAVerifyTOTPParamFields>;
710
+ declare type MFAVerifyPhoneParamFields = MFAVerifyTOTPParamFields;
711
+ export declare type MFAVerifyPhoneParams = Prettify<MFAVerifyParamsBase & MFAVerifyPhoneParamFields>;
712
+ declare type MFAVerifyWebauthnParamFieldsBase = {
713
+ /** Relying party ID */
714
+ rpId: string;
715
+ /** Relying party origins */
716
+ rpOrigins?: string[];
717
+ };
718
+ declare type MFAVerifyWebauthnCredentialParamFields<T extends 'create' | 'request' = 'create' | 'request'> = {
719
+ /** Operation type */
720
+ type: T;
721
+ /** Creation response from the authenticator (for enrollment/unverified factors) */
722
+ credential_response: T extends 'create' ? RegistrationCredential : AuthenticationCredential;
723
+ };
724
+ /**
725
+ * WebAuthn-specific fields for MFA verification.
726
+ * Supports both credential creation (registration) and request (authentication) flows.
727
+ * @template T - Type of WebAuthn operation: 'create' for registration, 'request' for authentication
728
+ */
729
+ export declare type MFAVerifyWebauthnParamFields<T extends 'create' | 'request' = 'create' | 'request'> = {
730
+ webauthn: MFAVerifyWebauthnParamFieldsBase & MFAVerifyWebauthnCredentialParamFields<T>;
731
+ };
732
+ /**
733
+ * Parameters for WebAuthn MFA verification.
734
+ * Used to verify WebAuthn credentials after challenge.
735
+ * @template T - Type of WebAuthn operation: 'create' for registration, 'request' for authentication
736
+ * @see {@link https://w3c.github.io/webauthn/#sctn-verifying-assertion W3C WebAuthn Spec - Verifying an Authentication Assertion}
737
+ */
738
+ export declare type MFAVerifyWebauthnParams<T extends 'create' | 'request' = 'create' | 'request'> = Prettify<MFAVerifyParamsBase & MFAVerifyWebauthnParamFields<T>>;
739
+ export declare type MFAVerifyParams = MFAVerifyTOTPParams | MFAVerifyPhoneParams | MFAVerifyWebauthnParams;
740
+ declare type MFAChallengeParamsBase = {
760
741
  /** ID of the factor to be challenged. Returned in enroll(). */
761
742
  factorId: string;
762
- /** Messaging channel to use (e.g. whatsapp or sms). Only relevant for phone factors */
763
- channel?: 'sms' | 'whatsapp';
764
743
  };
765
- export declare type MFAChallengeAndVerifyParams = {
766
- /** ID of the factor being verified. Returned in enroll(). */
767
- factorId: string;
768
- /** Verification code provided by the user. */
769
- code: string;
744
+ declare const MFATOTPChannels: readonly ["sms", "whatsapp"];
745
+ export declare type MFATOTPChannel = typeof MFATOTPChannels[number];
746
+ export declare type MFAChallengeTOTPParams = Prettify<MFAChallengeParamsBase>;
747
+ declare type MFAChallengePhoneParamFields<Channel extends MFATOTPChannel = MFATOTPChannel> = {
748
+ /** Messaging channel to use (e.g. whatsapp or sms). Only relevant for phone factors */
749
+ channel: Channel;
770
750
  };
771
- export declare type AuthMFAVerifyResponse = {
772
- data: {
773
- /** New access token (JWT) after successful verification. */
774
- access_token: string;
775
- /** Type of token, typically `Bearer`. */
776
- token_type: string;
777
- /** Number of seconds in which the access token will expire. */
778
- expires_in: number;
779
- /** Refresh token you can use to obtain new access tokens when expired. */
780
- refresh_token: string;
781
- /** Updated user profile. */
782
- user: User;
751
+ export declare type MFAChallengePhoneParams = Prettify<MFAChallengeParamsBase & MFAChallengePhoneParamFields>;
752
+ /** WebAuthn parameters for WebAuthn factor challenge */
753
+ declare type MFAChallengeWebauthnParamFields = {
754
+ webauthn: {
755
+ /** Relying party ID */
756
+ rpId: string;
757
+ /** Relying party origins*/
758
+ rpOrigins?: string[];
783
759
  };
784
- error: null;
785
- } | {
786
- data: null;
787
- error: AuthError;
788
760
  };
789
- export declare type AuthMFAEnrollResponse = AuthMFAEnrollTOTPResponse | AuthMFAEnrollPhoneResponse;
790
- export declare type AuthMFAUnenrollResponse = {
791
- data: {
792
- /** ID of the factor that was successfully unenrolled. */
793
- id: string;
794
- };
795
- error: null;
796
- } | {
797
- data: null;
798
- error: AuthError;
761
+ /**
762
+ * Parameters for initiating a WebAuthn MFA challenge.
763
+ * Includes Relying Party information needed for WebAuthn ceremonies.
764
+ * @see {@link https://w3c.github.io/webauthn/#sctn-rp-operations W3C WebAuthn Spec - Relying Party Operations}
765
+ */
766
+ export declare type MFAChallengeWebauthnParams = Prettify<MFAChallengeParamsBase & MFAChallengeWebauthnParamFields>;
767
+ export declare type MFAChallengeParams = MFAChallengeTOTPParams | MFAChallengePhoneParams | MFAChallengeWebauthnParams;
768
+ declare type MFAChallengeAndVerifyParamsBase = Omit<MFAVerifyParamsBase, 'challengeId'>;
769
+ declare type MFAChallengeAndVerifyTOTPParamFields = MFAVerifyTOTPParamFields;
770
+ declare type MFAChallengeAndVerifyTOTPParams = Prettify<MFAChallengeAndVerifyParamsBase & MFAChallengeAndVerifyTOTPParamFields>;
771
+ export declare type MFAChallengeAndVerifyParams = MFAChallengeAndVerifyTOTPParams;
772
+ /**
773
+ * Data returned after successful MFA verification.
774
+ * Contains new session tokens and updated user information.
775
+ */
776
+ export declare type AuthMFAVerifyResponseData = {
777
+ /** New access token (JWT) after successful verification. */
778
+ access_token: string;
779
+ /** Type of token, always `bearer`. */
780
+ token_type: 'bearer';
781
+ /** Number of seconds in which the access token will expire. */
782
+ expires_in: number;
783
+ /** Refresh token you can use to obtain new access tokens when expired. */
784
+ refresh_token: string;
785
+ /** Updated user profile. */
786
+ user: User;
799
787
  };
800
- export declare type AuthMFAChallengeResponse = {
801
- data: {
802
- /** ID of the newly created challenge. */
803
- id: string;
804
- /** Factor Type which generated the challenge */
805
- type: 'totp' | 'phone';
806
- /** Timestamp in UNIX seconds when this challenge will no longer be usable. */
807
- expires_at: number;
808
- };
809
- error: null;
810
- } | {
811
- data: null;
812
- error: AuthError;
788
+ /**
789
+ * Response type for MFA verification operations.
790
+ * Returns session tokens on successful verification.
791
+ */
792
+ export declare type AuthMFAVerifyResponse = RequestResult<AuthMFAVerifyResponseData>;
793
+ export declare type AuthMFAEnrollResponse = AuthMFAEnrollTOTPResponse | AuthMFAEnrollPhoneResponse | AuthMFAEnrollWebauthnResponse;
794
+ export declare type AuthMFAUnenrollResponse = RequestResult<{
795
+ /** ID of the factor that was successfully unenrolled. */
796
+ id: string;
797
+ }>;
798
+ declare type AuthMFAChallengeResponseBase<T extends FactorType> = {
799
+ /** ID of the newly created challenge. */
800
+ id: string;
801
+ /** Factor Type which generated the challenge */
802
+ type: T;
803
+ /** Timestamp in UNIX seconds when this challenge will no longer be usable. */
804
+ expires_at: number;
813
805
  };
814
- export declare type AuthMFAListFactorsResponse = {
815
- data: {
816
- /** All available factors (verified and unverified). */
817
- all: Factor[];
818
- /** Only verified TOTP factors. (A subset of `all`.) */
819
- totp: Factor[];
820
- /** Only verified Phone factors. (A subset of `all`.) */
821
- phone: Factor[];
806
+ declare type AuthMFAChallengeTOTPResponseFields = {};
807
+ export declare type AuthMFAChallengeTOTPResponse = RequestResult<Prettify<AuthMFAChallengeResponseBase<'totp'> & AuthMFAChallengeTOTPResponseFields>>;
808
+ declare type AuthMFAChallengePhoneResponseFields = {};
809
+ export declare type AuthMFAChallengePhoneResponse = RequestResult<Prettify<AuthMFAChallengeResponseBase<'phone'> & AuthMFAChallengePhoneResponseFields>>;
810
+ declare type AuthMFAChallengeWebauthnResponseFields = {
811
+ webauthn: {
812
+ type: 'create';
813
+ credential_options: {
814
+ publicKey: PublicKeyCredentialCreationOptionsFuture;
815
+ };
816
+ } | {
817
+ type: 'request';
818
+ credential_options: {
819
+ publicKey: PublicKeyCredentialRequestOptionsFuture;
820
+ };
822
821
  };
823
- error: null;
824
- } | {
825
- data: null;
826
- error: AuthError;
827
822
  };
828
- export declare type AuthenticatorAssuranceLevels = 'aal1' | 'aal2';
829
- export declare type AuthMFAGetAuthenticatorAssuranceLevelResponse = {
830
- data: {
831
- /** Current AAL level of the session. */
832
- currentLevel: AuthenticatorAssuranceLevels | null;
833
- /**
834
- * Next possible AAL level for the session. If the next level is higher
835
- * than the current one, the user should go through MFA.
836
- *
837
- * @see {@link GoTrueMFAApi#challenge}
838
- */
839
- nextLevel: AuthenticatorAssuranceLevels | null;
840
- /**
841
- * A list of all authentication methods attached to this session. Use
842
- * the information here to detect the last time a user verified a
843
- * factor, for example if implementing a step-up scenario.
844
- */
845
- currentAuthenticationMethods: AMREntry[];
823
+ /**
824
+ * Response type for WebAuthn MFA challenge.
825
+ * Contains credential creation or request options from the server.
826
+ * @see {@link https://w3c.github.io/webauthn/#sctn-credential-creation W3C WebAuthn Spec - Credential Creation}
827
+ */
828
+ export declare type AuthMFAChallengeWebauthnResponse = RequestResult<Prettify<AuthMFAChallengeResponseBase<'webauthn'> & AuthMFAChallengeWebauthnResponseFields>>;
829
+ declare type AuthMFAChallengeWebauthnResponseFieldsJSON = {
830
+ webauthn: {
831
+ type: 'create';
832
+ credential_options: {
833
+ publicKey: ServerCredentialCreationOptions;
834
+ };
835
+ } | {
836
+ type: 'request';
837
+ credential_options: {
838
+ publicKey: ServerCredentialRequestOptions;
839
+ };
846
840
  };
847
- error: null;
848
- } | {
849
- data: null;
850
- error: AuthError;
851
841
  };
842
+ /**
843
+ * JSON-serializable version of WebAuthn challenge response.
844
+ * Used for server communication with base64url-encoded binary fields.
845
+ */
846
+ export declare type AuthMFAChallengeWebauthnResponseDataJSON = Prettify<AuthMFAChallengeResponseBase<'webauthn'> & AuthMFAChallengeWebauthnResponseFieldsJSON>;
847
+ /**
848
+ * Server response type for WebAuthn MFA challenge.
849
+ * Contains JSON-formatted WebAuthn options ready for browser API.
850
+ */
851
+ export declare type AuthMFAChallengeWebauthnServerResponse = RequestResult<AuthMFAChallengeWebauthnResponseDataJSON>;
852
+ export declare type AuthMFAChallengeResponse = AuthMFAChallengeTOTPResponse | AuthMFAChallengePhoneResponse | AuthMFAChallengeWebauthnResponse;
853
+ /** response of ListFactors, which should contain all the types of factors that are available, this ensures we always include all */
854
+ export declare type AuthMFAListFactorsResponse<T extends typeof FactorTypes = typeof FactorTypes> = RequestResult<{
855
+ /** All available factors (verified and unverified). */
856
+ all: Prettify<Factor>[];
857
+ } & {
858
+ [K in T[number]]: Prettify<Factor<K, 'verified'>>[];
859
+ }>;
860
+ export declare type AuthenticatorAssuranceLevels = 'aal1' | 'aal2';
861
+ export declare type AuthMFAGetAuthenticatorAssuranceLevelResponse = RequestResult<{
862
+ /** Current AAL level of the session. */
863
+ currentLevel: AuthenticatorAssuranceLevels | null;
864
+ /**
865
+ * Next possible AAL level for the session. If the next level is higher
866
+ * than the current one, the user should go through MFA.
867
+ *
868
+ * @see {@link GoTrueMFAApi#challenge}
869
+ */
870
+ nextLevel: AuthenticatorAssuranceLevels | null;
871
+ /**
872
+ * A list of all authentication methods attached to this session. Use
873
+ * the information here to detect the last time a user verified a
874
+ * factor, for example if implementing a step-up scenario.
875
+ */
876
+ currentAuthenticationMethods: AMREntry[];
877
+ }>;
852
878
  /**
853
879
  * Contains the full multi-factor authentication API.
854
880
  *
@@ -862,20 +888,26 @@ export interface GoTrueMFAApi {
862
888
  * The user has to enter the code from their authenticator app to verify it.
863
889
  *
864
890
  * Upon verifying a factor, all other sessions are logged out and the current session's authenticator level is promoted to `aal2`.
865
- *
866
891
  */
867
892
  enroll(params: MFAEnrollTOTPParams): Promise<AuthMFAEnrollTOTPResponse>;
868
893
  enroll(params: MFAEnrollPhoneParams): Promise<AuthMFAEnrollPhoneResponse>;
894
+ enroll(params: MFAEnrollWebauthnParams): Promise<AuthMFAEnrollWebauthnResponse>;
869
895
  enroll(params: MFAEnrollParams): Promise<AuthMFAEnrollResponse>;
870
896
  /**
871
897
  * Prepares a challenge used to verify that a user has access to a MFA
872
898
  * factor.
873
899
  */
900
+ challenge(params: MFAChallengeTOTPParams): Promise<Prettify<AuthMFAChallengeTOTPResponse>>;
901
+ challenge(params: MFAChallengePhoneParams): Promise<Prettify<AuthMFAChallengePhoneResponse>>;
902
+ challenge(params: MFAChallengeWebauthnParams): Promise<Prettify<AuthMFAChallengeWebauthnResponse>>;
874
903
  challenge(params: MFAChallengeParams): Promise<AuthMFAChallengeResponse>;
875
904
  /**
876
905
  * Verifies a code against a challenge. The verification code is
877
906
  * provided by the user by entering a code seen in their authenticator app.
878
907
  */
908
+ verify(params: MFAVerifyTOTPParams): Promise<AuthMFAVerifyResponse>;
909
+ verify(params: MFAVerifyPhoneParams): Promise<AuthMFAVerifyResponse>;
910
+ verify(params: MFAVerifyWebauthnParams): Promise<AuthMFAVerifyResponse>;
879
911
  verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse>;
880
912
  /**
881
913
  * Unenroll removes a MFA factor.
@@ -910,20 +942,15 @@ export interface GoTrueMFAApi {
910
942
  *
911
943
  */
912
944
  getAuthenticatorAssuranceLevel(): Promise<AuthMFAGetAuthenticatorAssuranceLevelResponse>;
945
+ webauthn: WebAuthnApi;
913
946
  }
914
947
  /**
915
948
  * @expermental
916
949
  */
917
- export declare type AuthMFAAdminDeleteFactorResponse = {
918
- data: {
919
- /** ID of the factor that was successfully deleted. */
920
- id: string;
921
- };
922
- error: null;
923
- } | {
924
- data: null;
925
- error: AuthError;
926
- };
950
+ export declare type AuthMFAAdminDeleteFactorResponse = RequestResult<{
951
+ /** ID of the factor that was successfully deleted. */
952
+ id: string;
953
+ }>;
927
954
  /**
928
955
  * @expermental
929
956
  */
@@ -936,16 +963,10 @@ export declare type AuthMFAAdminDeleteFactorParams = {
936
963
  /**
937
964
  * @expermental
938
965
  */
939
- export declare type AuthMFAAdminListFactorsResponse = {
940
- data: {
941
- /** All factors attached to the user. */
942
- factors: Factor[];
943
- };
944
- error: null;
945
- } | {
946
- data: null;
947
- error: AuthError;
948
- };
966
+ export declare type AuthMFAAdminListFactorsResponse = RequestResult<{
967
+ /** All factors attached to the user. */
968
+ factors: Factor[];
969
+ }>;
949
970
  /**
950
971
  * @expermental
951
972
  */
@@ -992,13 +1013,7 @@ export declare type SupportedStorage = PromisifyMethods<Pick<Storage, 'getItem'
992
1013
  export declare type InitializeResult = {
993
1014
  error: AuthError | null;
994
1015
  };
995
- export declare type CallRefreshTokenResult = {
996
- session: Session;
997
- error: null;
998
- } | {
999
- session: null;
1000
- error: AuthError;
1001
- };
1016
+ export declare type CallRefreshTokenResult = RequestResult<Session>;
1002
1017
  export declare type Pagination = {
1003
1018
  [key: string]: any;
1004
1019
  nextPage: number | null;
@@ -1024,66 +1039,66 @@ export declare type SignOut = {
1024
1039
  */
1025
1040
  scope?: 'global' | 'local' | 'others';
1026
1041
  };
1027
- export declare type MFAEnrollTOTPParams = {
1042
+ declare type MFAEnrollParamsBase<T extends FactorType> = {
1028
1043
  /** The type of factor being enrolled. */
1029
- factorType: 'totp';
1030
- /** Domain which the user is enrolled with. */
1031
- issuer?: string;
1044
+ factorType: T;
1032
1045
  /** Human readable name assigned to the factor. */
1033
1046
  friendlyName?: string;
1034
1047
  };
1035
- export declare type MFAEnrollPhoneParams = {
1036
- /** The type of factor being enrolled. */
1037
- factorType: 'phone';
1038
- /** Human readable name assigned to the factor. */
1039
- friendlyName?: string;
1048
+ declare type MFAEnrollTOTPParamFields = {
1049
+ /** Domain which the user is enrolled with. */
1050
+ issuer?: string;
1051
+ };
1052
+ export declare type MFAEnrollTOTPParams = Prettify<MFAEnrollParamsBase<'totp'> & MFAEnrollTOTPParamFields>;
1053
+ declare type MFAEnrollPhoneParamFields = {
1040
1054
  /** Phone number associated with a factor. Number should conform to E.164 format */
1041
1055
  phone: string;
1042
1056
  };
1043
- export declare type AuthMFAEnrollTOTPResponse = {
1044
- data: {
1045
- /** ID of the factor that was just enrolled (in an unverified state). */
1046
- id: string;
1047
- /** Type of MFA factor.*/
1048
- type: 'totp';
1049
- /** TOTP enrollment information. */
1050
- totp: {
1051
- /** Contains a QR code encoding the authenticator URI. You can
1052
- * convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
1053
- * the value. Avoid logging this value to the console. */
1054
- qr_code: string;
1055
- /** The TOTP secret (also encoded in the QR code). Show this secret
1056
- * in a password-style field to the user, in case they are unable to
1057
- * scan the QR code. Avoid logging this value to the console. */
1058
- secret: string;
1059
- /** The authenticator URI encoded within the QR code, should you need
1060
- * to use it. Avoid loggin this value to the console. */
1061
- uri: string;
1062
- };
1063
- /** Friendly name of the factor, useful for distinguishing between factors **/
1064
- friendly_name?: string;
1065
- };
1066
- error: null;
1067
- } | {
1068
- data: null;
1069
- error: AuthError;
1057
+ export declare type MFAEnrollPhoneParams = Prettify<MFAEnrollParamsBase<'phone'> & MFAEnrollPhoneParamFields>;
1058
+ declare type MFAEnrollWebauthnFields = {};
1059
+ /**
1060
+ * Parameters for enrolling a WebAuthn factor.
1061
+ * Creates an unverified WebAuthn factor that must be verified with a credential.
1062
+ * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential}
1063
+ */
1064
+ export declare type MFAEnrollWebauthnParams = Prettify<MFAEnrollParamsBase<'webauthn'> & MFAEnrollWebauthnFields>;
1065
+ declare type AuthMFAEnrollResponseBase<T extends FactorType> = {
1066
+ /** ID of the factor that was just enrolled (in an unverified state). */
1067
+ id: string;
1068
+ /** Type of MFA factor.*/
1069
+ type: T;
1070
+ /** Friendly name of the factor, useful for distinguishing between factors **/
1071
+ friendly_name?: string;
1070
1072
  };
1071
- export declare type AuthMFAEnrollPhoneResponse = {
1072
- data: {
1073
- /** ID of the factor that was just enrolled (in an unverified state). */
1074
- id: string;
1075
- /** Type of MFA factor. */
1076
- type: 'phone';
1077
- /** Friendly name of the factor, useful for distinguishing between factors **/
1078
- friendly_name?: string;
1079
- /** Phone number of the MFA factor in E.164 format. Used to send messages */
1080
- phone: string;
1073
+ declare type AuthMFAEnrollTOTPResponseFields = {
1074
+ /** TOTP enrollment information. */
1075
+ totp: {
1076
+ /** Contains a QR code encoding the authenticator URI. You can
1077
+ * convert it to a URL by prepending `data:image/svg+xml;utf-8,` to
1078
+ * the value. Avoid logging this value to the console. */
1079
+ qr_code: string;
1080
+ /** The TOTP secret (also encoded in the QR code). Show this secret
1081
+ * in a password-style field to the user, in case they are unable to
1082
+ * scan the QR code. Avoid logging this value to the console. */
1083
+ secret: string;
1084
+ /** The authenticator URI encoded within the QR code, should you need
1085
+ * to use it. Avoid loggin this value to the console. */
1086
+ uri: string;
1081
1087
  };
1082
- error: null;
1083
- } | {
1084
- data: null;
1085
- error: AuthError;
1086
1088
  };
1089
+ export declare type AuthMFAEnrollTOTPResponse = RequestResult<Prettify<AuthMFAEnrollResponseBase<'totp'> & AuthMFAEnrollTOTPResponseFields>>;
1090
+ declare type AuthMFAEnrollPhoneResponseFields = {
1091
+ /** Phone number of the MFA factor in E.164 format. Used to send messages */
1092
+ phone: string;
1093
+ };
1094
+ export declare type AuthMFAEnrollPhoneResponse = RequestResult<Prettify<AuthMFAEnrollResponseBase<'phone'> & AuthMFAEnrollPhoneResponseFields>>;
1095
+ declare type AuthMFAEnrollWebauthnFields = {};
1096
+ /**
1097
+ * Response type for WebAuthn factor enrollment.
1098
+ * Returns the enrolled factor ID and metadata.
1099
+ * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential}
1100
+ */
1101
+ export declare type AuthMFAEnrollWebauthnResponse = RequestResult<Prettify<AuthMFAEnrollResponseBase<'webauthn'> & AuthMFAEnrollWebauthnFields>>;
1087
1102
  export declare type JwtHeader = {
1088
1103
  alg: 'RS256' | 'ES256' | 'HS256';
1089
1104
  kid: string;