@supabase/auth-js 2.73.0-rc.3 → 2.73.0-rc.6

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 (66) hide show
  1. package/README.md +28 -1
  2. package/dist/main/GoTrueClient.d.ts +1 -1
  3. package/dist/main/GoTrueClient.d.ts.map +1 -1
  4. package/dist/main/GoTrueClient.js +43 -15
  5. package/dist/main/GoTrueClient.js.map +1 -1
  6. package/dist/main/lib/base64url.d.ts +3 -2
  7. package/dist/main/lib/base64url.d.ts.map +1 -1
  8. package/dist/main/lib/base64url.js.map +1 -1
  9. package/dist/main/lib/helpers.d.ts +2 -1
  10. package/dist/main/lib/helpers.d.ts.map +1 -1
  11. package/dist/main/lib/helpers.js.map +1 -1
  12. package/dist/main/lib/types.d.ts +140 -19
  13. package/dist/main/lib/types.d.ts.map +1 -1
  14. package/dist/main/lib/types.js +3 -2
  15. package/dist/main/lib/types.js.map +1 -1
  16. package/dist/main/lib/version.d.ts +1 -1
  17. package/dist/main/lib/version.js +1 -1
  18. package/dist/main/lib/webauthn.d.ts +274 -0
  19. package/dist/main/lib/webauthn.d.ts.map +1 -0
  20. package/dist/main/lib/webauthn.dom.d.ts +583 -0
  21. package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
  22. package/dist/main/lib/webauthn.dom.js +4 -0
  23. package/dist/main/lib/webauthn.dom.js.map +1 -0
  24. package/dist/main/lib/webauthn.errors.d.ts +80 -0
  25. package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
  26. package/dist/main/lib/webauthn.errors.js +265 -0
  27. package/dist/main/lib/webauthn.errors.js.map +1 -0
  28. package/dist/main/lib/webauthn.js +702 -0
  29. package/dist/main/lib/webauthn.js.map +1 -0
  30. package/dist/module/GoTrueClient.d.ts +1 -1
  31. package/dist/module/GoTrueClient.d.ts.map +1 -1
  32. package/dist/module/GoTrueClient.js +49 -21
  33. package/dist/module/GoTrueClient.js.map +1 -1
  34. package/dist/module/lib/base64url.d.ts +3 -2
  35. package/dist/module/lib/base64url.d.ts.map +1 -1
  36. package/dist/module/lib/base64url.js.map +1 -1
  37. package/dist/module/lib/helpers.d.ts +2 -1
  38. package/dist/module/lib/helpers.d.ts.map +1 -1
  39. package/dist/module/lib/helpers.js.map +1 -1
  40. package/dist/module/lib/types.d.ts +140 -19
  41. package/dist/module/lib/types.d.ts.map +1 -1
  42. package/dist/module/lib/types.js +2 -1
  43. package/dist/module/lib/types.js.map +1 -1
  44. package/dist/module/lib/version.d.ts +1 -1
  45. package/dist/module/lib/version.js +1 -1
  46. package/dist/module/lib/webauthn.d.ts +274 -0
  47. package/dist/module/lib/webauthn.d.ts.map +1 -0
  48. package/dist/module/lib/webauthn.dom.d.ts +583 -0
  49. package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
  50. package/dist/module/lib/webauthn.dom.js +3 -0
  51. package/dist/module/lib/webauthn.dom.js.map +1 -0
  52. package/dist/module/lib/webauthn.errors.d.ts +80 -0
  53. package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
  54. package/dist/module/lib/webauthn.errors.js +257 -0
  55. package/dist/module/lib/webauthn.errors.js.map +1 -0
  56. package/dist/module/lib/webauthn.js +685 -0
  57. package/dist/module/lib/webauthn.js.map +1 -0
  58. package/package.json +1 -1
  59. package/src/GoTrueClient.ts +198 -68
  60. package/src/lib/base64url.ts +4 -2
  61. package/src/lib/helpers.ts +2 -1
  62. package/src/lib/types.ts +205 -26
  63. package/src/lib/version.ts +1 -1
  64. package/src/lib/webauthn.dom.ts +636 -0
  65. package/src/lib/webauthn.errors.ts +317 -0
  66. package/src/lib/webauthn.ts +929 -0
package/src/lib/types.ts CHANGED
@@ -1,8 +1,18 @@
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 {
6
+ ServerCredentialCreationOptions,
7
+ ServerCredentialRequestOptions,
8
+ WebAuthnApi,
9
+ } from './webauthn'
10
+ import {
11
+ AuthenticationCredential,
12
+ PublicKeyCredentialCreationOptionsFuture,
13
+ PublicKeyCredentialRequestOptionsFuture,
14
+ RegistrationCredential,
15
+ } from './webauthn.dom'
6
16
 
7
17
  /** One of the providers supported by GoTrue. */
8
18
  export type Provider =
@@ -113,6 +123,13 @@ export type WeakPassword = {
113
123
  */
114
124
  export type Prettify<T> = T extends Function ? T : { [K in keyof T]: T[K] }
115
125
 
126
+ /**
127
+ * A stricter version of TypeScript's Omit that only allows omitting keys that actually exist.
128
+ * This prevents typos and ensures type safety at compile time.
129
+ * Unlike regular Omit, this will error if you try to omit a non-existent key.
130
+ */
131
+ export type StrictOmit<T, K extends keyof T> = Omit<T, K>
132
+
116
133
  /**
117
134
  * a shared result type that encapsulates errors instead of throwing them, allows you to optionally specify the ErrorType
118
135
  */
@@ -242,6 +259,7 @@ const AMRMethods = [
242
259
  'totp',
243
260
  'mfa/totp',
244
261
  'mfa/phone',
262
+ 'mfa/webauthn',
245
263
  'anonymous',
246
264
  'sso/saml',
247
265
  'magiclink',
@@ -282,7 +300,8 @@ export interface UserIdentity {
282
300
  updated_at?: string
283
301
  }
284
302
 
285
- export const FactorTypes = ['totp', 'phone'] as const
303
+ const FactorTypes = ['totp', 'phone', 'webauthn'] as const
304
+
286
305
  /**
287
306
  * Type of factor. `totp` and `phone` supported with this version
288
307
  */
@@ -359,7 +378,7 @@ export interface User {
359
378
  identities?: UserIdentity[]
360
379
  is_anonymous?: boolean
361
380
  is_sso_user?: boolean
362
- factors?: Factor<FactorType>[]
381
+ factors?: (Factor<FactorType, 'verified'> | Factor<FactorType, 'unverified'>)[]
363
382
  deleted_at?: string
364
383
  }
365
384
 
@@ -853,7 +872,7 @@ export type GenerateLinkType =
853
872
  | 'email_change_current'
854
873
  | 'email_change_new'
855
874
 
856
- export type MFAEnrollParams = MFAEnrollTOTPParams | MFAEnrollPhoneParams
875
+ export type MFAEnrollParams = MFAEnrollTOTPParams | MFAEnrollPhoneParams | MFAEnrollWebauthnParams
857
876
 
858
877
  export type MFAUnenrollParams = {
859
878
  /** ID of the factor being unenrolled. */
@@ -878,7 +897,40 @@ type MFAVerifyPhoneParamFields = MFAVerifyTOTPParamFields
878
897
 
879
898
  export type MFAVerifyPhoneParams = Prettify<MFAVerifyParamsBase & MFAVerifyPhoneParamFields>
880
899
 
881
- export type MFAVerifyParams = MFAVerifyTOTPParams | MFAVerifyPhoneParams
900
+ type MFAVerifyWebauthnParamFieldsBase = {
901
+ /** Relying party ID */
902
+ rpId: string
903
+ /** Relying party origins */
904
+ rpOrigins?: string[]
905
+ }
906
+
907
+ type MFAVerifyWebauthnCredentialParamFields<T extends 'create' | 'request' = 'create' | 'request'> =
908
+ {
909
+ /** Operation type */
910
+ type: T
911
+ /** Creation response from the authenticator (for enrollment/unverified factors) */
912
+ credential_response: T extends 'create' ? RegistrationCredential : AuthenticationCredential
913
+ }
914
+
915
+ /**
916
+ * WebAuthn-specific fields for MFA verification.
917
+ * Supports both credential creation (registration) and request (authentication) flows.
918
+ * @template T - Type of WebAuthn operation: 'create' for registration, 'request' for authentication
919
+ */
920
+ export type MFAVerifyWebauthnParamFields<T extends 'create' | 'request' = 'create' | 'request'> = {
921
+ webauthn: MFAVerifyWebauthnParamFieldsBase & MFAVerifyWebauthnCredentialParamFields<T>
922
+ }
923
+
924
+ /**
925
+ * Parameters for WebAuthn MFA verification.
926
+ * Used to verify WebAuthn credentials after challenge.
927
+ * @template T - Type of WebAuthn operation: 'create' for registration, 'request' for authentication
928
+ * @see {@link https://w3c.github.io/webauthn/#sctn-verifying-assertion W3C WebAuthn Spec - Verifying an Authentication Assertion}
929
+ */
930
+ export type MFAVerifyWebauthnParams<T extends 'create' | 'request' = 'create' | 'request'> =
931
+ Prettify<MFAVerifyParamsBase & MFAVerifyWebauthnParamFields<T>>
932
+
933
+ export type MFAVerifyParams = MFAVerifyTOTPParams | MFAVerifyPhoneParams | MFAVerifyWebauthnParams
882
934
 
883
935
  type MFAChallengeParamsBase = {
884
936
  /** ID of the factor to be challenged. Returned in enroll(). */
@@ -899,7 +951,29 @@ export type MFAChallengePhoneParams = Prettify<
899
951
  MFAChallengeParamsBase & MFAChallengePhoneParamFields
900
952
  >
901
953
 
902
- export type MFAChallengeParams = MFAChallengeTOTPParams | MFAChallengePhoneParams
954
+ /** WebAuthn parameters for WebAuthn factor challenge */
955
+ type MFAChallengeWebauthnParamFields = {
956
+ webauthn: {
957
+ /** Relying party ID */
958
+ rpId: string
959
+ /** Relying party origins*/
960
+ rpOrigins?: string[]
961
+ }
962
+ }
963
+
964
+ /**
965
+ * Parameters for initiating a WebAuthn MFA challenge.
966
+ * Includes Relying Party information needed for WebAuthn ceremonies.
967
+ * @see {@link https://w3c.github.io/webauthn/#sctn-rp-operations W3C WebAuthn Spec - Relying Party Operations}
968
+ */
969
+ export type MFAChallengeWebauthnParams = Prettify<
970
+ MFAChallengeParamsBase & MFAChallengeWebauthnParamFields
971
+ >
972
+
973
+ export type MFAChallengeParams =
974
+ | MFAChallengeTOTPParams
975
+ | MFAChallengePhoneParams
976
+ | MFAChallengeWebauthnParams
903
977
 
904
978
  type MFAChallengeAndVerifyParamsBase = Omit<MFAVerifyParamsBase, 'challengeId'>
905
979
 
@@ -909,17 +983,13 @@ type MFAChallengeAndVerifyTOTPParams = Prettify<
909
983
  MFAChallengeAndVerifyParamsBase & MFAChallengeAndVerifyTOTPParamFields
910
984
  >
911
985
 
912
- type MFAChallengeAndVerifyPhoneParamFields = MFAVerifyPhoneParamFields
913
-
914
- type MFAChallengeAndVerifyPhoneParams = Prettify<
915
- MFAChallengeAndVerifyParamsBase & MFAChallengeAndVerifyPhoneParamFields
916
- >
917
-
918
- export type MFAChallengeAndVerifyParams =
919
- | MFAChallengeAndVerifyTOTPParams
920
- | MFAChallengeAndVerifyPhoneParams
986
+ export type MFAChallengeAndVerifyParams = MFAChallengeAndVerifyTOTPParams
921
987
 
922
- export type AuthMFAVerifyResponse = RequestResult<{
988
+ /**
989
+ * Data returned after successful MFA verification.
990
+ * Contains new session tokens and updated user information.
991
+ */
992
+ export type AuthMFAVerifyResponseData = {
923
993
  /** New access token (JWT) after successful verification. */
924
994
  access_token: string
925
995
 
@@ -934,16 +1004,25 @@ export type AuthMFAVerifyResponse = RequestResult<{
934
1004
 
935
1005
  /** Updated user profile. */
936
1006
  user: User
937
- }>
1007
+ }
938
1008
 
939
- export type AuthMFAEnrollResponse = AuthMFAEnrollTOTPResponse | AuthMFAEnrollPhoneResponse
1009
+ /**
1010
+ * Response type for MFA verification operations.
1011
+ * Returns session tokens on successful verification.
1012
+ */
1013
+ export type AuthMFAVerifyResponse = RequestResult<AuthMFAVerifyResponseData>
1014
+
1015
+ export type AuthMFAEnrollResponse =
1016
+ | AuthMFAEnrollTOTPResponse
1017
+ | AuthMFAEnrollPhoneResponse
1018
+ | AuthMFAEnrollWebauthnResponse
940
1019
 
941
1020
  export type AuthMFAUnenrollResponse = RequestResult<{
942
1021
  /** ID of the factor that was successfully unenrolled. */
943
1022
  id: string
944
1023
  }>
945
1024
 
946
- export type AuthMFAChallengeResponse<T extends FactorType> = RequestResult<{
1025
+ type AuthMFAChallengeResponseBase<T extends FactorType> = {
947
1026
  /** ID of the newly created challenge. */
948
1027
  id: string
949
1028
 
@@ -952,7 +1031,76 @@ export type AuthMFAChallengeResponse<T extends FactorType> = RequestResult<{
952
1031
 
953
1032
  /** Timestamp in UNIX seconds when this challenge will no longer be usable. */
954
1033
  expires_at: number
955
- }>
1034
+ }
1035
+
1036
+ type AuthMFAChallengeTOTPResponseFields = {
1037
+ /** no extra fields for now, kept for consistency and for possible future changes */
1038
+ }
1039
+
1040
+ export type AuthMFAChallengeTOTPResponse = RequestResult<
1041
+ Prettify<AuthMFAChallengeResponseBase<'totp'> & AuthMFAChallengeTOTPResponseFields>
1042
+ >
1043
+
1044
+ type AuthMFAChallengePhoneResponseFields = {
1045
+ /** no extra fields for now, kept for consistency and for possible future changes */
1046
+ }
1047
+
1048
+ export type AuthMFAChallengePhoneResponse = RequestResult<
1049
+ Prettify<AuthMFAChallengeResponseBase<'phone'> & AuthMFAChallengePhoneResponseFields>
1050
+ >
1051
+
1052
+ type AuthMFAChallengeWebauthnResponseFields = {
1053
+ webauthn:
1054
+ | {
1055
+ type: 'create'
1056
+ credential_options: { publicKey: PublicKeyCredentialCreationOptionsFuture }
1057
+ }
1058
+ | {
1059
+ type: 'request'
1060
+ credential_options: { publicKey: PublicKeyCredentialRequestOptionsFuture }
1061
+ }
1062
+ }
1063
+
1064
+ /**
1065
+ * Response type for WebAuthn MFA challenge.
1066
+ * Contains credential creation or request options from the server.
1067
+ * @see {@link https://w3c.github.io/webauthn/#sctn-credential-creation W3C WebAuthn Spec - Credential Creation}
1068
+ */
1069
+ export type AuthMFAChallengeWebauthnResponse = RequestResult<
1070
+ Prettify<AuthMFAChallengeResponseBase<'webauthn'> & AuthMFAChallengeWebauthnResponseFields>
1071
+ >
1072
+
1073
+ type AuthMFAChallengeWebauthnResponseFieldsJSON = {
1074
+ webauthn:
1075
+ | {
1076
+ type: 'create'
1077
+ credential_options: { publicKey: ServerCredentialCreationOptions }
1078
+ }
1079
+ | {
1080
+ type: 'request'
1081
+ credential_options: { publicKey: ServerCredentialRequestOptions }
1082
+ }
1083
+ }
1084
+
1085
+ /**
1086
+ * JSON-serializable version of WebAuthn challenge response.
1087
+ * Used for server communication with base64url-encoded binary fields.
1088
+ */
1089
+ export type AuthMFAChallengeWebauthnResponseDataJSON = Prettify<
1090
+ AuthMFAChallengeResponseBase<'webauthn'> & AuthMFAChallengeWebauthnResponseFieldsJSON
1091
+ >
1092
+
1093
+ /**
1094
+ * Server response type for WebAuthn MFA challenge.
1095
+ * Contains JSON-formatted WebAuthn options ready for browser API.
1096
+ */
1097
+ export type AuthMFAChallengeWebauthnServerResponse =
1098
+ RequestResult<AuthMFAChallengeWebauthnResponseDataJSON>
1099
+
1100
+ export type AuthMFAChallengeResponse =
1101
+ | AuthMFAChallengeTOTPResponse
1102
+ | AuthMFAChallengePhoneResponse
1103
+ | AuthMFAChallengeWebauthnResponse
956
1104
 
957
1105
  /** response of ListFactors, which should contain all the types of factors that are available, this ensures we always include all */
958
1106
  export type AuthMFAListFactorsResponse<T extends typeof FactorTypes = typeof FactorTypes> =
@@ -1005,17 +1153,17 @@ export interface GoTrueMFAApi {
1005
1153
  */
1006
1154
  enroll(params: MFAEnrollTOTPParams): Promise<AuthMFAEnrollTOTPResponse>
1007
1155
  enroll(params: MFAEnrollPhoneParams): Promise<AuthMFAEnrollPhoneResponse>
1156
+ enroll(params: MFAEnrollWebauthnParams): Promise<AuthMFAEnrollWebauthnResponse>
1008
1157
  enroll(params: MFAEnrollParams): Promise<AuthMFAEnrollResponse>
1009
1158
 
1010
1159
  /**
1011
1160
  * Prepares a challenge used to verify that a user has access to a MFA
1012
1161
  * factor.
1013
1162
  */
1014
- challenge(params: MFAChallengeTOTPParams): Promise<Prettify<AuthMFAChallengeResponse<'totp'>>>
1015
- challenge(params: MFAChallengePhoneParams): Promise<Prettify<AuthMFAChallengeResponse<'phone'>>>
1016
- challenge(
1017
- params: MFAChallengeParams
1018
- ): Promise<Prettify<AuthMFAChallengeResponse<'totp' | 'phone'>>>
1163
+ challenge(params: MFAChallengeTOTPParams): Promise<Prettify<AuthMFAChallengeTOTPResponse>>
1164
+ challenge(params: MFAChallengePhoneParams): Promise<Prettify<AuthMFAChallengePhoneResponse>>
1165
+ challenge(params: MFAChallengeWebauthnParams): Promise<Prettify<AuthMFAChallengeWebauthnResponse>>
1166
+ challenge(params: MFAChallengeParams): Promise<AuthMFAChallengeResponse>
1019
1167
 
1020
1168
  /**
1021
1169
  * Verifies a code against a challenge. The verification code is
@@ -1023,6 +1171,7 @@ export interface GoTrueMFAApi {
1023
1171
  */
1024
1172
  verify(params: MFAVerifyTOTPParams): Promise<AuthMFAVerifyResponse>
1025
1173
  verify(params: MFAVerifyPhoneParams): Promise<AuthMFAVerifyResponse>
1174
+ verify(params: MFAVerifyWebauthnParams): Promise<AuthMFAVerifyResponse>
1026
1175
  verify(params: MFAVerifyParams): Promise<AuthMFAVerifyResponse>
1027
1176
 
1028
1177
  /**
@@ -1061,6 +1210,9 @@ export interface GoTrueMFAApi {
1061
1210
  *
1062
1211
  */
1063
1212
  getAuthenticatorAssuranceLevel(): Promise<AuthMFAGetAuthenticatorAssuranceLevelResponse>
1213
+
1214
+ // namespace for the webauthn methods
1215
+ webauthn: WebAuthnApi
1064
1216
  }
1065
1217
 
1066
1218
  /**
@@ -1196,6 +1348,19 @@ export type MFAEnrollPhoneParams = Prettify<
1196
1348
  MFAEnrollParamsBase<'phone'> & MFAEnrollPhoneParamFields
1197
1349
  >
1198
1350
 
1351
+ type MFAEnrollWebauthnFields = {
1352
+ /** no extra fields for now, kept for consistency and for possible future changes */
1353
+ }
1354
+
1355
+ /**
1356
+ * Parameters for enrolling a WebAuthn factor.
1357
+ * Creates an unverified WebAuthn factor that must be verified with a credential.
1358
+ * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential}
1359
+ */
1360
+ export type MFAEnrollWebauthnParams = Prettify<
1361
+ MFAEnrollParamsBase<'webauthn'> & MFAEnrollWebauthnFields
1362
+ >
1363
+
1199
1364
  type AuthMFAEnrollResponseBase<T extends FactorType> = {
1200
1365
  /** ID of the factor that was just enrolled (in an unverified state). */
1201
1366
  id: string
@@ -1234,10 +1399,24 @@ type AuthMFAEnrollPhoneResponseFields = {
1234
1399
  /** Phone number of the MFA factor in E.164 format. Used to send messages */
1235
1400
  phone: string
1236
1401
  }
1402
+
1237
1403
  export type AuthMFAEnrollPhoneResponse = RequestResult<
1238
1404
  Prettify<AuthMFAEnrollResponseBase<'phone'> & AuthMFAEnrollPhoneResponseFields>
1239
1405
  >
1240
1406
 
1407
+ type AuthMFAEnrollWebauthnFields = {
1408
+ /** no extra fields for now, kept for consistency and for possible future changes */
1409
+ }
1410
+
1411
+ /**
1412
+ * Response type for WebAuthn factor enrollment.
1413
+ * Returns the enrolled factor ID and metadata.
1414
+ * @see {@link https://w3c.github.io/webauthn/#sctn-registering-a-new-credential W3C WebAuthn Spec - Registering a New Credential}
1415
+ */
1416
+ export type AuthMFAEnrollWebauthnResponse = RequestResult<
1417
+ Prettify<AuthMFAEnrollResponseBase<'webauthn'> & AuthMFAEnrollWebauthnFields>
1418
+ >
1419
+
1241
1420
  export type JwtHeader = {
1242
1421
  alg: 'RS256' | 'ES256' | 'HS256'
1243
1422
  kid: string
@@ -1 +1 @@
1
- export const version = '2.73.0-rc.3'
1
+ export const version = '2.73.0-rc.6'