@supabase/auth-js 2.116.0-canary.2 → 2.116.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/dist/main/GoTrueClient.d.ts +20 -0
  2. package/dist/main/GoTrueClient.d.ts.map +1 -1
  3. package/dist/main/GoTrueClient.js +170 -1
  4. package/dist/main/GoTrueClient.js.map +1 -1
  5. package/dist/main/lib/error-codes.d.ts +1 -1
  6. package/dist/main/lib/error-codes.d.ts.map +1 -1
  7. package/dist/main/lib/helpers.d.ts +3 -0
  8. package/dist/main/lib/helpers.d.ts.map +1 -1
  9. package/dist/main/lib/helpers.js +6 -0
  10. package/dist/main/lib/helpers.js.map +1 -1
  11. package/dist/main/lib/types.d.ts +352 -4
  12. package/dist/main/lib/types.d.ts.map +1 -1
  13. package/dist/main/lib/types.js +2 -1
  14. package/dist/main/lib/types.js.map +1 -1
  15. package/dist/main/lib/version.d.ts +1 -1
  16. package/dist/main/lib/version.d.ts.map +1 -1
  17. package/dist/main/lib/version.js +1 -1
  18. package/dist/main/lib/version.js.map +1 -1
  19. package/dist/module/GoTrueClient.d.ts +20 -0
  20. package/dist/module/GoTrueClient.d.ts.map +1 -1
  21. package/dist/module/GoTrueClient.js +171 -2
  22. package/dist/module/GoTrueClient.js.map +1 -1
  23. package/dist/module/lib/error-codes.d.ts +1 -1
  24. package/dist/module/lib/error-codes.d.ts.map +1 -1
  25. package/dist/module/lib/helpers.d.ts +3 -0
  26. package/dist/module/lib/helpers.d.ts.map +1 -1
  27. package/dist/module/lib/helpers.js +5 -0
  28. package/dist/module/lib/helpers.js.map +1 -1
  29. package/dist/module/lib/types.d.ts +352 -4
  30. package/dist/module/lib/types.d.ts.map +1 -1
  31. package/dist/module/lib/types.js +2 -1
  32. package/dist/module/lib/types.js.map +1 -1
  33. package/dist/module/lib/version.d.ts +1 -1
  34. package/dist/module/lib/version.d.ts.map +1 -1
  35. package/dist/module/lib/version.js +1 -1
  36. package/dist/module/lib/version.js.map +1 -1
  37. package/dist/tsconfig.module.tsbuildinfo +1 -1
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +1 -1
  40. package/src/GoTrueClient.ts +214 -1
  41. package/src/lib/error-codes.ts +4 -0
  42. package/src/lib/helpers.ts +10 -0
  43. package/src/lib/types.ts +373 -3
  44. package/src/lib/version.ts +1 -1
package/src/lib/types.ts CHANGED
@@ -190,6 +190,16 @@ export type ExperimentalFeatureFlags = {
190
190
  * disabled throws a descriptive error at call time.
191
191
  */
192
192
  passkey?: boolean
193
+ /**
194
+ * Enables MFA recovery codes support:
195
+ * - `auth.mfa.recoveryCodes.*`
196
+ *
197
+ * Defaults to `false`. Calling any recovery codes method while this flag is
198
+ * disabled throws a descriptive error at call time.
199
+ *
200
+ * @experimental
201
+ */
202
+ recoveryCodes?: boolean
193
203
  /**
194
204
  * Appends a reserved `sb_flow_id` query parameter to `redirectTo` URLs on
195
205
  * PKCE flows. The parameter round-trips through the auth server back to
@@ -381,6 +391,7 @@ const AMRMethods = [
381
391
  'mfa/totp',
382
392
  'mfa/phone',
383
393
  'mfa/webauthn',
394
+ 'mfa/recovery_code',
384
395
  'anonymous',
385
396
  'sso/saml',
386
397
  'magiclink',
@@ -426,10 +437,14 @@ export interface UserIdentity {
426
437
  updated_at?: string
427
438
  }
428
439
 
429
- const FactorTypes = ['totp', 'phone', 'webauthn'] as const
440
+ const FactorTypes = ['totp', 'phone', 'webauthn', 'recovery_code'] as const
430
441
 
431
442
  /**
432
- * Type of factor. `totp` and `phone` supported with this version
443
+ * Type of factor. `totp`, `phone`, `webauthn` and `recovery_code` are supported.
444
+ *
445
+ * `recovery_code` factors are managed through {@link AuthMFARecoveryCodesApi}
446
+ * (`mfa.recoveryCodes.*`) and cannot be used with `enroll()`, `challenge()`,
447
+ * `verify()` or `unenroll()`.
433
448
  */
434
449
  export type FactorType = (typeof FactorTypes)[number]
435
450
 
@@ -458,7 +473,7 @@ export type Factor<
458
473
  friendly_name?: string
459
474
 
460
475
  /**
461
- * Type of factor. `totp` and `phone` supported with this version
476
+ * Type of factor. `totp`, `phone`, `webauthn` and `recovery_code` are supported.
462
477
  */
463
478
  factor_type: Type
464
479
 
@@ -1180,6 +1195,105 @@ export type AuthMFAUnenrollResponse = RequestResult<{
1180
1195
  id: string
1181
1196
  }>
1182
1197
 
1198
+ /**
1199
+ * Parameters for generating a set of MFA recovery codes.
1200
+ *
1201
+ * @see {@link AuthMFARecoveryCodesApi#generate}
1202
+ *
1203
+ * @experimental
1204
+ */
1205
+ export type MFARecoveryCodesGenerateParams = {
1206
+ /**
1207
+ * Friendly name for the recovery codes factor, as shown in `user.factors`
1208
+ * and `mfa.listFactors()`. Must be unique among the user's factors. The
1209
+ * server defaults it to `Recovery codes` when omitted.
1210
+ */
1211
+ friendlyName?: string
1212
+ }
1213
+
1214
+ /**
1215
+ * Parameters for verifying a single MFA recovery code.
1216
+ *
1217
+ * @see {@link AuthMFARecoveryCodesApi#verify}
1218
+ *
1219
+ * @experimental
1220
+ */
1221
+ export type MFARecoveryCodesVerifyParams = {
1222
+ /**
1223
+ * One of the user's unused recovery codes, exactly as entered by the user.
1224
+ * Letter case, whitespace and `-` separators are ignored by the server.
1225
+ * Each code can be used only once.
1226
+ */
1227
+ code: string
1228
+ }
1229
+
1230
+ /**
1231
+ * Enrollment status of a user's recovery codes. Never contains code values.
1232
+ *
1233
+ * @experimental
1234
+ */
1235
+ export type AuthMFARecoveryCodesStatusResponseData = {
1236
+ /** ID of the recovery codes factor, as it appears in `user.factors`. */
1237
+ id: string
1238
+
1239
+ /** Type of factor, always `recovery_code`. */
1240
+ type: 'recovery_code'
1241
+
1242
+ /** Number of codes in the current set. */
1243
+ total: number
1244
+
1245
+ /**
1246
+ * Number of codes in the current set that have not been used yet. `0` when
1247
+ * every code has been consumed.
1248
+ */
1249
+ remaining: number
1250
+ }
1251
+
1252
+ /**
1253
+ * Response type for {@link AuthMFARecoveryCodesApi#getStatus}.
1254
+ *
1255
+ * @experimental
1256
+ */
1257
+ export type AuthMFARecoveryCodesStatusResponse =
1258
+ RequestResult<AuthMFARecoveryCodesStatusResponseData>
1259
+
1260
+ /**
1261
+ * A newly generated set of recovery codes. The `codes` are returned exactly
1262
+ * once and cannot be retrieved again; use `regenerate()` to issue a new set.
1263
+ *
1264
+ * @experimental
1265
+ */
1266
+ export type AuthMFARecoveryCodesGenerateResponseData = {
1267
+ /** ID of the recovery codes factor. */
1268
+ id: string
1269
+
1270
+ /** Type of factor, always `recovery_code`. */
1271
+ type: 'recovery_code'
1272
+
1273
+ /** Friendly name of the recovery codes factor. */
1274
+ friendly_name?: string
1275
+
1276
+ /** Number of codes in the set. */
1277
+ total: number
1278
+
1279
+ /**
1280
+ * The plaintext recovery codes in canonical form.
1281
+ * They are returned exactly once and cannot be retrieved again. Show them to
1282
+ * the user in a copy/download-friendly layout and ask them to store the codes
1283
+ * safely.
1284
+ */
1285
+ codes: string[]
1286
+ }
1287
+
1288
+ /**
1289
+ * Response type for {@link AuthMFARecoveryCodesApi#generate} and
1290
+ * {@link AuthMFARecoveryCodesApi#regenerate}.
1291
+ *
1292
+ * @experimental
1293
+ */
1294
+ export type AuthMFARecoveryCodesGenerateResponse =
1295
+ RequestResult<AuthMFARecoveryCodesGenerateResponseData>
1296
+
1183
1297
  type AuthMFAChallengeResponseBase<T extends FactorType> = {
1184
1298
  /** ID of the newly created challenge. */
1185
1299
  id: string
@@ -1298,6 +1412,251 @@ export type AuthMFAGetAuthenticatorAssuranceLevelResponse = RequestResult<{
1298
1412
  currentAuthenticationMethods: AMREntry[] | string[]
1299
1413
  }>
1300
1414
 
1415
+ /**
1416
+ * Contains the MFA recovery codes API.
1417
+ *
1418
+ * Recovery codes are single-use backup codes that let a user reach `aal2`
1419
+ * when they cannot use their other MFA factors (for example, a lost
1420
+ * authenticator app). A user has a single set of recovery codes; the codes
1421
+ * are shown exactly once when generated.
1422
+ *
1423
+ * Requires `auth.experimental.recoveryCodes: true`; otherwise all methods
1424
+ * throw. Recovery codes must also be enabled on the Supabase Auth server.
1425
+ *
1426
+ * @experimental
1427
+ */
1428
+ export interface AuthMFARecoveryCodesApi {
1429
+ /**
1430
+ * Returns the enrollment status of the user's recovery codes: the total
1431
+ * number of codes in the current set and how many are still unused. Never
1432
+ * returns the codes themselves.
1433
+ *
1434
+ * Requires `auth.experimental.recoveryCodes: true`.
1435
+ *
1436
+ * @experimental
1437
+ *
1438
+ * @category Auth
1439
+ * @subcategory Auth MFA Recovery Codes
1440
+ *
1441
+ * @remarks
1442
+ * - Works at any authenticator assurance level (`aal1` or `aal2`).
1443
+ * - Returns an error with code `mfa_factor_not_found` when the user has not generated recovery codes yet.
1444
+ * - `remaining` can be `0` once every code has been used; prompt the user to call `mfa.recoveryCodes.regenerate()`.
1445
+ *
1446
+ * @example Get the recovery codes status
1447
+ * ```js
1448
+ * const { data, error } = await supabase.auth.mfa.recoveryCodes.getStatus()
1449
+ * ```
1450
+ *
1451
+ * @exampleResponse Get the recovery codes status
1452
+ * ```json
1453
+ * {
1454
+ * data: {
1455
+ * id: '<FACTOR_ID>',
1456
+ * type: 'recovery_code',
1457
+ * total: 10,
1458
+ * remaining: 7
1459
+ * },
1460
+ * error: null
1461
+ * }
1462
+ * ```
1463
+ */
1464
+ getStatus(): Promise<AuthMFARecoveryCodesStatusResponse>
1465
+
1466
+ /**
1467
+ * Generates the user's set of recovery codes. The plaintext codes are
1468
+ * returned exactly once in the response and cannot be retrieved again, so
1469
+ * show them to the user and ask them to store the codes safely.
1470
+ *
1471
+ * Requires `auth.experimental.recoveryCodes: true`.
1472
+ *
1473
+ * @experimental
1474
+ *
1475
+ * @category Auth
1476
+ * @subcategory Auth MFA Recovery Codes
1477
+ *
1478
+ * @remarks
1479
+ * - The session must be at `aal2` (verify another factor first), otherwise an error with code `insufficient_aal` is returned.
1480
+ * - The user must already have another verified factor (for example a TOTP factor): recovery codes can never be the only factor. Otherwise an error with code `mfa_recovery_codes_sole_factor` is returned.
1481
+ * - A user can only have one set of recovery codes. If one already exists, an error with code `mfa_verified_factor_exists` is returned; use `mfa.recoveryCodes.regenerate()` to replace it.
1482
+ * - The codes are returned in canonical form (lowercase, no separators). For display you can group them, for example in blocks of four characters. Avoid logging them to the console.
1483
+ * - Returns an error with code `mfa_recovery_codes_enroll_not_enabled` when recovery codes are disabled on the server.
1484
+ *
1485
+ * @example Generate recovery codes
1486
+ * ```js
1487
+ * const supabase = createClient(supabaseUrl, supabaseKey, {
1488
+ * auth: { experimental: { recoveryCodes: true } },
1489
+ * })
1490
+ *
1491
+ * const { data, error } = await supabase.auth.mfa.recoveryCodes.generate({
1492
+ * friendlyName: 'Backup codes',
1493
+ * })
1494
+ *
1495
+ * // Show the codes once, for example grouped in blocks of four characters
1496
+ * const formatted = data.codes.map((code) => code.match(/.{1,4}/g).join('-'))
1497
+ * ```
1498
+ *
1499
+ * @exampleResponse Generate recovery codes
1500
+ * ```json
1501
+ * {
1502
+ * data: {
1503
+ * id: '<FACTOR_ID>',
1504
+ * type: 'recovery_code',
1505
+ * friendly_name: 'Backup codes',
1506
+ * total: 10,
1507
+ * codes: [
1508
+ * 'k4m9x7qp2ab8ht3z',
1509
+ * '9wze6r5npd4cmq7v',
1510
+ * '...'
1511
+ * ]
1512
+ * },
1513
+ * error: null
1514
+ * }
1515
+ * ```
1516
+ */
1517
+ generate(params?: MFARecoveryCodesGenerateParams): Promise<AuthMFARecoveryCodesGenerateResponse>
1518
+
1519
+ /**
1520
+ * Verifies one of the user's recovery codes and upgrades the current
1521
+ * session to `aal2`. Each code can be used only once.
1522
+ *
1523
+ * Requires `auth.experimental.recoveryCodes: true`.
1524
+ *
1525
+ * @experimental
1526
+ *
1527
+ * @category Auth
1528
+ * @subcategory Auth MFA Recovery Codes
1529
+ *
1530
+ * @remarks
1531
+ * - On success the current session is upgraded to `aal2` in place and persisted, and the `MFA_CHALLENGE_VERIFIED` event is emitted. The user's other `aal1` sessions are signed out.
1532
+ * - The new access token includes `mfa/recovery_code` in its `amr` claim.
1533
+ * - The code can be passed exactly as the user typed it: letter case, whitespace and `-` separators are ignored.
1534
+ * - A wrong, already used, or missing code returns an error with code `mfa_verification_failed`.
1535
+ * - After too many failed attempts, verification is locked for a period and an error with code `mfa_recovery_codes_locked` (status `429`) is returned. Ask the user to wait or to use another factor.
1536
+ * - Returns an error with code `mfa_recovery_codes_verify_not_enabled` when recovery code verification is disabled on the server.
1537
+ *
1538
+ * @example Verify a recovery code
1539
+ * ```js
1540
+ * const { data, error } = await supabase.auth.mfa.recoveryCodes.verify({
1541
+ * code: 'K4M9-X7QP-2AB8-HT3Z',
1542
+ * })
1543
+ * ```
1544
+ *
1545
+ * @exampleResponse Verify a recovery code
1546
+ * ```json
1547
+ * {
1548
+ * data: {
1549
+ * access_token: '<ACCESS_TOKEN>',
1550
+ * token_type: 'bearer',
1551
+ * expires_in: 3600,
1552
+ * refresh_token: '<REFRESH_TOKEN>',
1553
+ * user: {
1554
+ * id: '11111111-1111-1111-1111-111111111111',
1555
+ * aud: 'authenticated',
1556
+ * role: 'authenticated',
1557
+ * email: 'example@email.com',
1558
+ * factors: [
1559
+ * {
1560
+ * id: '<TOTP_FACTOR_ID>',
1561
+ * friendly_name: 'Authenticator app',
1562
+ * factor_type: 'totp',
1563
+ * status: 'verified',
1564
+ * created_at: '2024-01-01T00:00:00Z',
1565
+ * updated_at: '2024-01-01T00:00:00Z'
1566
+ * },
1567
+ * {
1568
+ * id: '<RECOVERY_CODES_FACTOR_ID>',
1569
+ * friendly_name: 'Backup codes',
1570
+ * factor_type: 'recovery_code',
1571
+ * status: 'verified',
1572
+ * created_at: '2024-01-01T00:00:00Z',
1573
+ * updated_at: '2024-01-01T00:00:00Z'
1574
+ * }
1575
+ * ]
1576
+ * }
1577
+ * },
1578
+ * error: null
1579
+ * }
1580
+ * ```
1581
+ */
1582
+ verify(params: MFARecoveryCodesVerifyParams): Promise<AuthMFAVerifyResponse>
1583
+
1584
+ /**
1585
+ * Replaces the user's recovery codes with a brand new set. All remaining
1586
+ * codes from the previous set stop working immediately. The new plaintext
1587
+ * codes are returned exactly once.
1588
+ *
1589
+ * Requires `auth.experimental.recoveryCodes: true`.
1590
+ *
1591
+ * @experimental
1592
+ *
1593
+ * @category Auth
1594
+ * @subcategory Auth MFA Recovery Codes
1595
+ *
1596
+ * @remarks
1597
+ * - The session must be at `aal2`, otherwise an error with code `insufficient_aal` is returned.
1598
+ * - The factor `id` and `friendly_name` are preserved; only the codes change.
1599
+ * - Also clears any verification lockout on the recovery codes.
1600
+ * - Returns an error with code `mfa_factor_not_found` when the user has no recovery codes to regenerate; use `mfa.recoveryCodes.generate()` instead.
1601
+ * - Returns an error with code `mfa_recovery_codes_enroll_not_enabled` when recovery codes are disabled on the server.
1602
+ *
1603
+ * @example Regenerate recovery codes
1604
+ * ```js
1605
+ * const { data, error } = await supabase.auth.mfa.recoveryCodes.regenerate()
1606
+ * ```
1607
+ *
1608
+ * @exampleResponse Regenerate recovery codes
1609
+ * ```json
1610
+ * {
1611
+ * data: {
1612
+ * id: '<FACTOR_ID>',
1613
+ * type: 'recovery_code',
1614
+ * friendly_name: 'Backup codes',
1615
+ * total: 10,
1616
+ * codes: [
1617
+ * '2h8kqw3m7xt49rpn',
1618
+ * 'nq5v7xk2m9tp4wzs',
1619
+ * '...'
1620
+ * ]
1621
+ * },
1622
+ * error: null
1623
+ * }
1624
+ * ```
1625
+ */
1626
+ regenerate(): Promise<AuthMFARecoveryCodesGenerateResponse>
1627
+
1628
+ /**
1629
+ * Removes the user's recovery codes factor together with all of its codes.
1630
+ *
1631
+ * Requires `auth.experimental.recoveryCodes: true`.
1632
+ *
1633
+ * @experimental
1634
+ *
1635
+ * @category Auth
1636
+ * @subcategory Auth MFA Recovery Codes
1637
+ *
1638
+ * @remarks
1639
+ * - The session must be at `aal2`, otherwise an error with code `insufficient_aal` is returned.
1640
+ * - Returns an error with code `mfa_factor_not_found` when the user has no recovery codes.
1641
+ *
1642
+ * @example Unenroll recovery codes
1643
+ * ```js
1644
+ * const { data, error } = await supabase.auth.mfa.recoveryCodes.unenroll()
1645
+ * ```
1646
+ *
1647
+ * @exampleResponse Unenroll recovery codes
1648
+ * ```json
1649
+ * {
1650
+ * data: {
1651
+ * id: '<FACTOR_ID>'
1652
+ * },
1653
+ * error: null
1654
+ * }
1655
+ * ```
1656
+ */
1657
+ unenroll(): Promise<AuthMFAUnenrollResponse>
1658
+ }
1659
+
1301
1660
  /**
1302
1661
  * Contains the full multi-factor authentication API.
1303
1662
  *
@@ -1726,6 +2085,17 @@ export interface GoTrueMFAApi {
1726
2085
 
1727
2086
  // namespace for the webauthn methods
1728
2087
  webauthn: WebAuthnApi
2088
+
2089
+ /**
2090
+ * Namespace for the MFA recovery codes methods.
2091
+ *
2092
+ * Requires `auth.experimental.recoveryCodes: true`; otherwise all methods throw.
2093
+ *
2094
+ * @see {@link AuthMFARecoveryCodesApi}
2095
+ *
2096
+ * @experimental
2097
+ */
2098
+ recoveryCodes: AuthMFARecoveryCodesApi
1729
2099
  }
1730
2100
 
1731
2101
  /**
@@ -4,4 +4,4 @@
4
4
  // - Debugging and support (identifying which version is running)
5
5
  // - Telemetry and logging (version reporting in errors/analytics)
6
6
  // - Ensuring build artifacts match the published package version
7
- export const version = '2.116.0-canary.2'
7
+ export const version = '2.116.0'