@bymax-one/nest-auth 1.0.4 → 1.0.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.
@@ -422,6 +422,26 @@ interface BymaxAuthModuleOptions {
422
422
  * @returns Array of domain strings where cookies should be set (e.g. `['.example.com']`).
423
423
  */
424
424
  resolveDomains?: (requestDomain: string) => string[];
425
+ /**
426
+ * `SameSite` attribute applied to every cookie issued by the module
427
+ * (access token, refresh token, session signal). Default: `'lax'`.
428
+ *
429
+ * Trade-offs:
430
+ * - `'lax'` (default): cookies travel on top-level cross-site GET navigations.
431
+ * This is the standard posture for browser auth — OAuth redirects from a
432
+ * provider (Google, GitHub, …) back to the app deliver the auth cookies on
433
+ * the first navigation, which is exactly what users expect after sign-in.
434
+ * Aligns with Chromium's behavior for cookies that omit `SameSite`.
435
+ * - `'strict'`: cookies are withheld on every cross-site request, including
436
+ * the OAuth return-trip. Choose this only when the app does not use
437
+ * third-party identity providers and the extra CSRF margin justifies the
438
+ * broken OAuth flow.
439
+ * - `'none'`: cookies are sent on every cross-site request. The browser
440
+ * requires `Secure` for `SameSite=None`, so the resolver throws at startup
441
+ * when this combination would be unset (`secureCookies` must be `true`).
442
+ * Pick this for embedded scenarios (iframes, third-party widgets).
443
+ */
444
+ sameSite?: 'lax' | 'strict' | 'none';
425
445
  };
426
446
  /**
427
447
  * Multi-factor authentication (MFA/TOTP) configuration.
@@ -1939,6 +1959,19 @@ interface IAuthHooks {
1939
1959
  * @param context - Request metadata (IP, user agent, sanitized headers).
1940
1960
  */
1941
1961
  afterMfaDisabled?(user: SafeAuthUser, context: HookContext): Promise<void> | void;
1962
+ /**
1963
+ * Called after MFA recovery codes have been successfully regenerated.
1964
+ *
1965
+ * Use this hook to send a security alert reminding the user to store the new
1966
+ * codes safely, append an audit-log entry, or propagate the rotation to
1967
+ * downstream systems. The plain-text codes themselves are NOT passed to the
1968
+ * hook — they are only delivered to the requesting client.
1969
+ *
1970
+ * @param user - The user whose recovery codes were regenerated
1971
+ * (credential fields omitted).
1972
+ * @param context - Request metadata (IP, user agent, sanitized headers).
1973
+ */
1974
+ afterMfaRecoveryCodesRegenerated?(user: SafeAuthUser, context: HookContext): Promise<void> | void;
1942
1975
  /**
1943
1976
  * Called when a successful login originates from a new device or location.
1944
1977
  *
@@ -2881,6 +2914,13 @@ declare class TokenDeliveryService {
2881
2914
  */
2882
2915
  extractDomain(req: Request): string | undefined;
2883
2916
  private setAuthCookies;
2917
+ /**
2918
+ * Returns the shared cookie attributes applied to every cookie issued by
2919
+ * this service. `sameSite` comes from the resolved options (defaults to
2920
+ * `'lax'`); the `domain` is folded in only when the consumer supplies a
2921
+ * resolver. Other per-cookie attributes (`httpOnly`, `secure`, `path`,
2922
+ * `maxAge`) are spread on top of this base by the callers.
2923
+ */
2884
2924
  private baseCookieOptions;
2885
2925
  private readCookie;
2886
2926
  private readBearerHeader;
@@ -3545,6 +3585,34 @@ declare class MfaDisableDto {
3545
3585
  code: string;
3546
3586
  }
3547
3587
 
3588
+ /**
3589
+ * Data Transfer Object for the MFA recovery code regeneration endpoint.
3590
+ *
3591
+ * Submitted when an MFA-enabled user wants to rotate their recovery codes
3592
+ * (e.g. after suspecting they have been written down somewhere insecure, or
3593
+ * after consuming several entries from the original list). The endpoint
3594
+ * requires a valid TOTP code from the user's authenticator app to confirm
3595
+ * the action.
3596
+ *
3597
+ * @remarks
3598
+ * **TOTP codes only** — recovery codes are intentionally not accepted as
3599
+ * the proof factor here. If a user has lost access to their authenticator
3600
+ * and is relying on recovery codes, the safe path is to disable MFA and
3601
+ * re-enrol (which forces a fresh secret AND a fresh recovery code set),
3602
+ * not to silently rotate recovery codes using one of the codes the user
3603
+ * may already have leaked.
3604
+ */
3605
+ declare class MfaRegenerateRecoveryCodesDto {
3606
+ /**
3607
+ * The 6-digit TOTP code generated by the user's authenticator app.
3608
+ *
3609
+ * Must be exactly 6 decimal digits. Recovery codes are not accepted by design.
3610
+ * Alphabetic characters, spaces, or other symbols are rejected before reaching
3611
+ * the service layer.
3612
+ */
3613
+ code: string;
3614
+ }
3615
+
3548
3616
  /**
3549
3617
  * Data Transfer Object for the MFA TOTP verification step during setup.
3550
3618
  *
@@ -4638,7 +4706,7 @@ declare class MfaService {
4638
4706
  */
4639
4707
  private platformUserAsSafeUser;
4640
4708
  /**
4641
- * Initiates the MFA setup flow for a dashboard user.
4709
+ * Initiates the MFA setup flow for a dashboard user or platform administrator.
4642
4710
  *
4643
4711
  * Generates a TOTP secret and 8 recovery codes, stores them temporarily in
4644
4712
  * Redis (10 minutes), and returns the data needed to display the QR code and
@@ -4649,10 +4717,15 @@ declare class MfaService {
4649
4717
  * requests cannot generate different secrets.
4650
4718
  *
4651
4719
  * @param userId - Internal ID of the user enabling MFA.
4720
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
4652
4721
  * @returns Setup result containing the secret, QR URI, and plain recovery codes.
4653
4722
  * @throws `MFA_ALREADY_ENABLED` if MFA is already active on the account.
4723
+ * @throws `MFA_NOT_ENABLED` if `context === 'platform'` and the platform user
4724
+ * repository was not configured at module registration. The error code is
4725
+ * reused (rather than introducing a new one) because the consumer-facing
4726
+ * meaning is the same: "platform MFA cannot operate".
4654
4727
  */
4655
- setup(userId: string): Promise<MfaSetupResult>;
4728
+ setup(userId: string, context?: 'dashboard' | 'platform'): Promise<MfaSetupResult>;
4656
4729
  /**
4657
4730
  * Verifies the first TOTP code from the user's authenticator app and permanently
4658
4731
  * enables MFA on the account.
@@ -4666,10 +4739,13 @@ declare class MfaService {
4666
4739
  * @param code - 6-digit TOTP code from the authenticator app.
4667
4740
  * @param ip - Client IP address (forwarded to hooks).
4668
4741
  * @param userAgent - User-Agent header (forwarded to hooks).
4742
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
4669
4743
  * @throws `MFA_SETUP_REQUIRED` if no pending setup data is found in Redis.
4670
4744
  * @throws `MFA_INVALID_CODE` if the submitted TOTP code is invalid.
4745
+ * @throws `MFA_NOT_ENABLED` if `context === 'platform'` and the platform user
4746
+ * repository was not configured at module registration.
4671
4747
  */
4672
- verifyAndEnable(userId: string, code: string, ip: string, userAgent: string): Promise<void>;
4748
+ verifyAndEnable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<void>;
4673
4749
  /**
4674
4750
  * Validates a TOTP or recovery code and exchanges the MFA temp token for full
4675
4751
  * access tokens.
@@ -4713,6 +4789,46 @@ declare class MfaService {
4713
4789
  * @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
4714
4790
  */
4715
4791
  disable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<void>;
4792
+ /**
4793
+ * Regenerates the user's MFA recovery codes after verifying a current TOTP code.
4794
+ *
4795
+ * Mirrors {@link disable} in its security posture: only TOTP codes are accepted
4796
+ * (recovery codes cannot rotate themselves by design), the brute-force counter
4797
+ * is checked, and the regeneration is fired against the correct repository for
4798
+ * the supplied `context`. The TOTP secret on the user record is unchanged — only
4799
+ * the recovery code list is replaced.
4800
+ *
4801
+ * Returns the plain-text codes once. They are NOT persisted in plain form; only
4802
+ * scrypt hashes go into the database. The caller is responsible for showing the
4803
+ * codes to the user exactly once and warning them to save them safely.
4804
+ *
4805
+ * @remarks
4806
+ * **Sessions are intentionally NOT invalidated after this call.** Unlike
4807
+ * {@link verifyAndEnable} (which flips `mfaEnabled` from `false` to `true`) and
4808
+ * {@link disable} (which flips it back to `false`), this method does not change
4809
+ * the verification credential — the TOTP secret stays the same and existing
4810
+ * `mfaVerified: true` access tokens remain valid. Invalidating sessions here
4811
+ * would force a redundant re-auth on every recovery-code rotation, which is a
4812
+ * routine hygiene action a user might perform several times over the lifetime
4813
+ * of an account.
4814
+ *
4815
+ * @param userId - Internal ID of the user rotating recovery codes.
4816
+ * @param totpCode - 6-digit TOTP code from the authenticator app.
4817
+ * @param ip - Client IP address (forwarded to hooks).
4818
+ * @param userAgent - User-Agent header (forwarded to hooks).
4819
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
4820
+ * @throws `TOKEN_INVALID` if the user is not found or `mfaSecret` is missing
4821
+ * when `mfaEnabled` is `true` (database inconsistency).
4822
+ * @throws `MFA_NOT_ENABLED` if MFA is not currently active, or if
4823
+ * `context === 'platform'` and the platform user repository was not
4824
+ * configured at module registration.
4825
+ * @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
4826
+ * @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
4827
+ * @returns The freshly generated plain-text recovery codes, one-time display.
4828
+ */
4829
+ regenerateRecoveryCodes(userId: string, totpCode: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<{
4830
+ recoveryCodes: string[];
4831
+ }>;
4716
4832
  /**
4717
4833
  * Verifies a TOTP code and enforces anti-replay within the validation window.
4718
4834
  *
@@ -5115,4 +5231,4 @@ declare function sleep(ms: number): Promise<void>;
5115
5231
  */
5116
5232
  declare function hasRole(userRole: string, requiredRole: string, hierarchy: Record<string, string[]>): boolean;
5117
5233
 
5118
- export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, type AuthErrorCode, AuthException, type AuthModuleAsyncOptions, type AuthPlatformUser, type AuthResult, AuthService, type AuthUser, type AuthenticatedRequest, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BeforeRegisterResult, BymaxAuthModule, type BymaxAuthModuleOptions, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, ForgotPasswordDto, type HookContext, type IAuthHooks, type IEmailProvider, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, type PlatformAuthenticatedRequest, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WsJwtGuard, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, sanitizeHeaders, sha256, sleep, timingSafeCompare };
5234
+ export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, type AuthErrorCode, AuthException, type AuthModuleAsyncOptions, type AuthPlatformUser, type AuthResult, AuthService, type AuthUser, type AuthenticatedRequest, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BeforeRegisterResult, BymaxAuthModule, type BymaxAuthModuleOptions, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, ForgotPasswordDto, type HookContext, type IAuthHooks, type IEmailProvider, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, type PlatformAuthenticatedRequest, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WsJwtGuard, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, sanitizeHeaders, sha256, sleep, timingSafeCompare };
@@ -422,6 +422,26 @@ interface BymaxAuthModuleOptions {
422
422
  * @returns Array of domain strings where cookies should be set (e.g. `['.example.com']`).
423
423
  */
424
424
  resolveDomains?: (requestDomain: string) => string[];
425
+ /**
426
+ * `SameSite` attribute applied to every cookie issued by the module
427
+ * (access token, refresh token, session signal). Default: `'lax'`.
428
+ *
429
+ * Trade-offs:
430
+ * - `'lax'` (default): cookies travel on top-level cross-site GET navigations.
431
+ * This is the standard posture for browser auth — OAuth redirects from a
432
+ * provider (Google, GitHub, …) back to the app deliver the auth cookies on
433
+ * the first navigation, which is exactly what users expect after sign-in.
434
+ * Aligns with Chromium's behavior for cookies that omit `SameSite`.
435
+ * - `'strict'`: cookies are withheld on every cross-site request, including
436
+ * the OAuth return-trip. Choose this only when the app does not use
437
+ * third-party identity providers and the extra CSRF margin justifies the
438
+ * broken OAuth flow.
439
+ * - `'none'`: cookies are sent on every cross-site request. The browser
440
+ * requires `Secure` for `SameSite=None`, so the resolver throws at startup
441
+ * when this combination would be unset (`secureCookies` must be `true`).
442
+ * Pick this for embedded scenarios (iframes, third-party widgets).
443
+ */
444
+ sameSite?: 'lax' | 'strict' | 'none';
425
445
  };
426
446
  /**
427
447
  * Multi-factor authentication (MFA/TOTP) configuration.
@@ -1939,6 +1959,19 @@ interface IAuthHooks {
1939
1959
  * @param context - Request metadata (IP, user agent, sanitized headers).
1940
1960
  */
1941
1961
  afterMfaDisabled?(user: SafeAuthUser, context: HookContext): Promise<void> | void;
1962
+ /**
1963
+ * Called after MFA recovery codes have been successfully regenerated.
1964
+ *
1965
+ * Use this hook to send a security alert reminding the user to store the new
1966
+ * codes safely, append an audit-log entry, or propagate the rotation to
1967
+ * downstream systems. The plain-text codes themselves are NOT passed to the
1968
+ * hook — they are only delivered to the requesting client.
1969
+ *
1970
+ * @param user - The user whose recovery codes were regenerated
1971
+ * (credential fields omitted).
1972
+ * @param context - Request metadata (IP, user agent, sanitized headers).
1973
+ */
1974
+ afterMfaRecoveryCodesRegenerated?(user: SafeAuthUser, context: HookContext): Promise<void> | void;
1942
1975
  /**
1943
1976
  * Called when a successful login originates from a new device or location.
1944
1977
  *
@@ -2881,6 +2914,13 @@ declare class TokenDeliveryService {
2881
2914
  */
2882
2915
  extractDomain(req: Request): string | undefined;
2883
2916
  private setAuthCookies;
2917
+ /**
2918
+ * Returns the shared cookie attributes applied to every cookie issued by
2919
+ * this service. `sameSite` comes from the resolved options (defaults to
2920
+ * `'lax'`); the `domain` is folded in only when the consumer supplies a
2921
+ * resolver. Other per-cookie attributes (`httpOnly`, `secure`, `path`,
2922
+ * `maxAge`) are spread on top of this base by the callers.
2923
+ */
2884
2924
  private baseCookieOptions;
2885
2925
  private readCookie;
2886
2926
  private readBearerHeader;
@@ -3545,6 +3585,34 @@ declare class MfaDisableDto {
3545
3585
  code: string;
3546
3586
  }
3547
3587
 
3588
+ /**
3589
+ * Data Transfer Object for the MFA recovery code regeneration endpoint.
3590
+ *
3591
+ * Submitted when an MFA-enabled user wants to rotate their recovery codes
3592
+ * (e.g. after suspecting they have been written down somewhere insecure, or
3593
+ * after consuming several entries from the original list). The endpoint
3594
+ * requires a valid TOTP code from the user's authenticator app to confirm
3595
+ * the action.
3596
+ *
3597
+ * @remarks
3598
+ * **TOTP codes only** — recovery codes are intentionally not accepted as
3599
+ * the proof factor here. If a user has lost access to their authenticator
3600
+ * and is relying on recovery codes, the safe path is to disable MFA and
3601
+ * re-enrol (which forces a fresh secret AND a fresh recovery code set),
3602
+ * not to silently rotate recovery codes using one of the codes the user
3603
+ * may already have leaked.
3604
+ */
3605
+ declare class MfaRegenerateRecoveryCodesDto {
3606
+ /**
3607
+ * The 6-digit TOTP code generated by the user's authenticator app.
3608
+ *
3609
+ * Must be exactly 6 decimal digits. Recovery codes are not accepted by design.
3610
+ * Alphabetic characters, spaces, or other symbols are rejected before reaching
3611
+ * the service layer.
3612
+ */
3613
+ code: string;
3614
+ }
3615
+
3548
3616
  /**
3549
3617
  * Data Transfer Object for the MFA TOTP verification step during setup.
3550
3618
  *
@@ -4638,7 +4706,7 @@ declare class MfaService {
4638
4706
  */
4639
4707
  private platformUserAsSafeUser;
4640
4708
  /**
4641
- * Initiates the MFA setup flow for a dashboard user.
4709
+ * Initiates the MFA setup flow for a dashboard user or platform administrator.
4642
4710
  *
4643
4711
  * Generates a TOTP secret and 8 recovery codes, stores them temporarily in
4644
4712
  * Redis (10 minutes), and returns the data needed to display the QR code and
@@ -4649,10 +4717,15 @@ declare class MfaService {
4649
4717
  * requests cannot generate different secrets.
4650
4718
  *
4651
4719
  * @param userId - Internal ID of the user enabling MFA.
4720
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
4652
4721
  * @returns Setup result containing the secret, QR URI, and plain recovery codes.
4653
4722
  * @throws `MFA_ALREADY_ENABLED` if MFA is already active on the account.
4723
+ * @throws `MFA_NOT_ENABLED` if `context === 'platform'` and the platform user
4724
+ * repository was not configured at module registration. The error code is
4725
+ * reused (rather than introducing a new one) because the consumer-facing
4726
+ * meaning is the same: "platform MFA cannot operate".
4654
4727
  */
4655
- setup(userId: string): Promise<MfaSetupResult>;
4728
+ setup(userId: string, context?: 'dashboard' | 'platform'): Promise<MfaSetupResult>;
4656
4729
  /**
4657
4730
  * Verifies the first TOTP code from the user's authenticator app and permanently
4658
4731
  * enables MFA on the account.
@@ -4666,10 +4739,13 @@ declare class MfaService {
4666
4739
  * @param code - 6-digit TOTP code from the authenticator app.
4667
4740
  * @param ip - Client IP address (forwarded to hooks).
4668
4741
  * @param userAgent - User-Agent header (forwarded to hooks).
4742
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
4669
4743
  * @throws `MFA_SETUP_REQUIRED` if no pending setup data is found in Redis.
4670
4744
  * @throws `MFA_INVALID_CODE` if the submitted TOTP code is invalid.
4745
+ * @throws `MFA_NOT_ENABLED` if `context === 'platform'` and the platform user
4746
+ * repository was not configured at module registration.
4671
4747
  */
4672
- verifyAndEnable(userId: string, code: string, ip: string, userAgent: string): Promise<void>;
4748
+ verifyAndEnable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<void>;
4673
4749
  /**
4674
4750
  * Validates a TOTP or recovery code and exchanges the MFA temp token for full
4675
4751
  * access tokens.
@@ -4713,6 +4789,46 @@ declare class MfaService {
4713
4789
  * @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
4714
4790
  */
4715
4791
  disable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<void>;
4792
+ /**
4793
+ * Regenerates the user's MFA recovery codes after verifying a current TOTP code.
4794
+ *
4795
+ * Mirrors {@link disable} in its security posture: only TOTP codes are accepted
4796
+ * (recovery codes cannot rotate themselves by design), the brute-force counter
4797
+ * is checked, and the regeneration is fired against the correct repository for
4798
+ * the supplied `context`. The TOTP secret on the user record is unchanged — only
4799
+ * the recovery code list is replaced.
4800
+ *
4801
+ * Returns the plain-text codes once. They are NOT persisted in plain form; only
4802
+ * scrypt hashes go into the database. The caller is responsible for showing the
4803
+ * codes to the user exactly once and warning them to save them safely.
4804
+ *
4805
+ * @remarks
4806
+ * **Sessions are intentionally NOT invalidated after this call.** Unlike
4807
+ * {@link verifyAndEnable} (which flips `mfaEnabled` from `false` to `true`) and
4808
+ * {@link disable} (which flips it back to `false`), this method does not change
4809
+ * the verification credential — the TOTP secret stays the same and existing
4810
+ * `mfaVerified: true` access tokens remain valid. Invalidating sessions here
4811
+ * would force a redundant re-auth on every recovery-code rotation, which is a
4812
+ * routine hygiene action a user might perform several times over the lifetime
4813
+ * of an account.
4814
+ *
4815
+ * @param userId - Internal ID of the user rotating recovery codes.
4816
+ * @param totpCode - 6-digit TOTP code from the authenticator app.
4817
+ * @param ip - Client IP address (forwarded to hooks).
4818
+ * @param userAgent - User-Agent header (forwarded to hooks).
4819
+ * @param context - Which repository to use: `'dashboard'` (default) or `'platform'`.
4820
+ * @throws `TOKEN_INVALID` if the user is not found or `mfaSecret` is missing
4821
+ * when `mfaEnabled` is `true` (database inconsistency).
4822
+ * @throws `MFA_NOT_ENABLED` if MFA is not currently active, or if
4823
+ * `context === 'platform'` and the platform user repository was not
4824
+ * configured at module registration.
4825
+ * @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
4826
+ * @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
4827
+ * @returns The freshly generated plain-text recovery codes, one-time display.
4828
+ */
4829
+ regenerateRecoveryCodes(userId: string, totpCode: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<{
4830
+ recoveryCodes: string[];
4831
+ }>;
4716
4832
  /**
4717
4833
  * Verifies a TOTP code and enforces anti-replay within the validation window.
4718
4834
  *
@@ -5115,4 +5231,4 @@ declare function sleep(ms: number): Promise<void>;
5115
5231
  */
5116
5232
  declare function hasRole(userRole: string, requiredRole: string, hierarchy: Record<string, string[]>): boolean;
5117
5233
 
5118
- export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, type AuthErrorCode, AuthException, type AuthModuleAsyncOptions, type AuthPlatformUser, type AuthResult, AuthService, type AuthUser, type AuthenticatedRequest, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BeforeRegisterResult, BymaxAuthModule, type BymaxAuthModuleOptions, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, ForgotPasswordDto, type HookContext, type IAuthHooks, type IEmailProvider, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, type PlatformAuthenticatedRequest, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WsJwtGuard, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, sanitizeHeaders, sha256, sleep, timingSafeCompare };
5234
+ export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, type AuthErrorCode, AuthException, type AuthModuleAsyncOptions, type AuthPlatformUser, type AuthResult, AuthService, type AuthUser, type AuthenticatedRequest, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BeforeRegisterResult, BymaxAuthModule, type BymaxAuthModuleOptions, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, ForgotPasswordDto, type HookContext, type IAuthHooks, type IEmailProvider, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, type PlatformAuthenticatedRequest, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WsJwtGuard, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, sanitizeHeaders, sha256, sleep, timingSafeCompare };