@bymax-one/nest-auth 1.4.1 → 1.4.3

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.
@@ -1070,15 +1070,18 @@ interface BymaxAuthModuleOptions {
1070
1070
  /**
1071
1071
  * Tenant ID resolver function.
1072
1072
  *
1073
- * When provided, the module resolves the tenant ID from the request object and
1074
- * **ignores** any `tenantId` field in the request body. This prevents tenant
1075
- * spoofing where a client sends a different tenant's ID.
1076
- *
1077
- * Because a configured resolver makes the body's value dead weight, `tenantId` is optional on
1078
- * every DTO that carries it and a client may omit it entirely. With no resolver configured the
1079
- * body is the only thing that can name a tenant, and a request naming none is refused with
1080
- * `auth.validation` — the deployment has to choose one of the two, and neither choice is
1081
- * guessed on its behalf.
1073
+ * When provided, the module resolves the tenant ID from the request object and **refuses** any
1074
+ * `tenantId` the request names — with `400 auth.validation` on the `tenantId` field. This
1075
+ * prevents tenant spoofing where a client sends a different tenant's ID, and it refuses rather
1076
+ * than ignoring on purpose: a discarded value answers `201` while putting the account
1077
+ * somewhere else, so the caller's belief and the server's state diverge on the tenancy
1078
+ * boundary with nothing saying so.
1079
+ *
1080
+ * A client under a resolver must therefore **omit the field**; `null` and an absent field are
1081
+ * both accepted, since neither asserts anything to contradict. With no resolver configured the
1082
+ * body is the only thing that can name a tenant, so there it is honoured, and a request naming
1083
+ * none is refused with the same `auth.validation` — the deployment has to choose one of the
1084
+ * two, and neither choice is guessed on its behalf.
1082
1085
  *
1083
1086
  * @param req - The Express request object
1084
1087
  * @returns The tenant ID string, or a Promise resolving to it
@@ -1681,7 +1684,7 @@ declare const AUTH_THROTTLE_CONFIGS: {
1681
1684
  readonly ttl: 60000;
1682
1685
  };
1683
1686
  };
1684
- /** DELETE /auth/sessions/all — 5 requests per minute per IP. */
1687
+ /** POST /auth/sessions/revoke-all — 5 requests per minute per IP. */
1685
1688
  readonly revokeAllSessions: {
1686
1689
  readonly default: {
1687
1690
  readonly limit: 5;
@@ -5152,8 +5155,25 @@ declare class WsJwtGuard implements CanActivate, OnModuleInit {
5152
5155
  * stack detail or a connection string reaches a response body, so the answer carries the
5153
5156
  * generic code and nothing else.
5154
5157
  *
5158
+ * **Do not register this alongside `@bymax-one/nest-core`'s envelope filter.** They are mutually
5159
+ * exclusive in practice and this one wins: `useGlobalFilters` binds ahead of an `APP_FILTER`
5160
+ * provider, and `@Catch()` with no argument catches everything, so nest-core's filter never runs.
5161
+ * Measured on a composed application — the same request answers
5162
+ * `{error: {code, message, details}}` with this filter registered and the flat
5163
+ * `{statusCode, code, message, timestamp, path, details}` without it. A derived backend that
5164
+ * registers both therefore loses `statusCode`, `timestamp`, `path` and the correlation id, which
5165
+ * is the opposite of what registering an extra filter looks like it should do.
5166
+ *
5167
+ * Pick one. On a backend built on nest-core, take theirs: it already recognises this library's
5168
+ * envelope and passes the code, message and per-field details through unchanged.
5169
+ *
5170
+ * Nothing in this repository asserts that, and deliberately so — verifying it would mean this
5171
+ * library depending on a consumer's stack. The behaviour above was measured once and the
5172
+ * dependency removed; the standing assertion belongs to whoever composes the two.
5173
+ *
5155
5174
  * @example
5156
5175
  * ```typescript
5176
+ * // Only when nest-core's envelope filter is NOT in the application.
5157
5177
  * app.useGlobalFilters(new AuthExceptionFilter())
5158
5178
  * ```
5159
5179
  *
@@ -5170,6 +5190,59 @@ declare class AuthExceptionFilter implements ExceptionFilter {
5170
5190
  catch(exception: unknown, host: ArgumentsHost): void;
5171
5191
  }
5172
5192
 
5193
+ /**
5194
+ * Gives a refused WebSocket client the library's error envelope instead of a generic failure.
5195
+ *
5196
+ * Register it on a gateway that applies {@link WsJwtGuard}. Without it, the guard's refusals do
5197
+ * not survive the transport: `AuthException` extends `HttpException`, Nest's WebSocket exception
5198
+ * layer understands only `WsException`, and everything else is delivered as
5199
+ * `{status: 'error', message: 'Internal server error'}` — so the whole `auth.*` catalogue stops
5200
+ * at the socket boundary.
5201
+ *
5202
+ * That is not only untidy. A client cannot tell a dead credential from a crashed handler, and a
5203
+ * reconnect policy has to choose: retrying an unknown error is the sensible default, so every
5204
+ * expired token becomes a reconnect loop against an endpoint that will refuse it forever. With
5205
+ * this filter the client reads `error.code` and can send the user to sign in instead.
5206
+ *
5207
+ * The payload keeps `status: 'error'` — the field Nest's own layer sets and every socket.io
5208
+ * client already branches on — and adds the envelope beside it, so a consumer handling both
5209
+ * shapes does not need a second listener:
5210
+ *
5211
+ * ```
5212
+ * without { status: 'error', message: 'Internal server error' }
5213
+ * with { status: 'error', error: { code: 'auth.token_invalid', message, details } }
5214
+ * ```
5215
+ *
5216
+ * **Scoped to `AuthException` on purpose.** An argument-less `@Catch()` would claim every
5217
+ * exception a gateway raises, so a `WsException` an unrelated handler throws — a domain error
5218
+ * with its own contract — would be rewritten as `auth.internal`, and following the README would
5219
+ * silently break a consumer's existing WebSocket errors. Everything that is not this library's
5220
+ * refusal keeps travelling through Nest's own exception layer.
5221
+ *
5222
+ * **Both transports.** A Socket.IO client is dispatched to with `emit`; a native `ws` client —
5223
+ * which also extends `EventEmitter`, so emitting on it succeeds and sends NOTHING — is written
5224
+ * to with `send`, in the `{event, data}` envelope `@nestjs/platform-ws` uses for every other
5225
+ * message. Both are driven over a real handshake in `test/e2e/ws-guard.e2e-spec.ts`.
5226
+ *
5227
+ * @example
5228
+ * ```typescript
5229
+ * @UseFilters(new WsAuthExceptionFilter())
5230
+ * @UseGuards(WsJwtGuard)
5231
+ * @WebSocketGateway()
5232
+ * export class FeedGateway { ... }
5233
+ * ```
5234
+ */
5235
+ declare class WsAuthExceptionFilter implements ExceptionFilter {
5236
+ private readonly logger;
5237
+ /**
5238
+ * Delivers the library envelope to the client whose request was refused.
5239
+ *
5240
+ * @param exception - The `AuthException` a guard, pipe or handler raised.
5241
+ * @param host - The arguments host, used to reach the connected client.
5242
+ */
5243
+ catch(exception: AuthException, host: ArgumentsHost): void;
5244
+ }
5245
+
5173
5246
  /**
5174
5247
  * @fileoverview The validation pipe every auth controller mounts.
5175
5248
  *
@@ -5813,6 +5886,23 @@ declare class ChangePasswordDto {
5813
5886
  * Hashed immediately by the service layer — never persisted in plaintext.
5814
5887
  */
5815
5888
  newPassword: string;
5889
+ /**
5890
+ * The caller's own refresh token, so the device making the change stays signed in.
5891
+ *
5892
+ * Declared because the handler reads it. `TokenDeliveryService.extractRefreshToken` takes it
5893
+ * from the refresh cookie under `tokenDelivery: 'cookie'` and from **this body field** under
5894
+ * `'bearer'`, cookie-first-then-body under `'both'` — and the controller pipe runs
5895
+ * `forbidNonWhitelisted: true`, so an undeclared property is refused. A bearer-mode caller
5896
+ * therefore could not send the field the endpoint needs: the request was answered
5897
+ * `auth.validation` naming `refreshToken`, and the only way to change a password was to give
5898
+ * up every other session.
5899
+ *
5900
+ * It stayed invisible because the E2E harness installed a global `ValidationPipe` with
5901
+ * `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
5902
+ * it — so the suite exercised a request production never sees. Optional, because under cookie
5903
+ * delivery the credential arrives in the cookie and no body field exists to declare.
5904
+ */
5905
+ refreshToken?: string;
5816
5906
  }
5817
5907
 
5818
5908
  /**
@@ -6734,7 +6824,21 @@ declare class TokenManagerService {
6734
6824
  * The `status` claim in the issued access token is intentionally empty during
6735
6825
  * rotation — the Redis session does not store full user data. Guards that enforce
6736
6826
  * status checks must read from the user repository or a status cache, not the
6737
- * JWT `status` claim.
6827
+ * JWT `status` claim. `rust-auth` stamps the same empty string at the same point, with a
6828
+ * test pinning it, so this is a shared contract rather than a local shortcut.
6829
+ *
6830
+ * **What that means for a consumer, which is where the cost lands.** `issueTokens` stamps the
6831
+ * account's value at that moment, this path stamps nothing, and `AuthService.refresh` re-stamps
6832
+ * it from the account when `role`, `tenantId` or `mfaEnabled` changed — so a session's tokens
6833
+ * carry a populated claim, then an empty one, then possibly a populated one again, with no
6834
+ * signal a client can read. A derived backend reading `request.user.status` is wrong in both
6835
+ * directions: `!== 'active'` refuses everyone whose session refreshed ordinarily, and
6836
+ * `=== 'suspended'` refuses nobody, ever.
6837
+ *
6838
+ * Backfilling it here would be worse than leaving it empty: the claim would become *usually*
6839
+ * true, which is the failure mode that survives testing, since status can still change under an
6840
+ * unexpired token. The claim cannot be authoritative, so it is not made to look like it — and
6841
+ * the empty string is the one state that cannot be mistaken for an answer.
6738
6842
  *
6739
6843
  * `mfaVerified` is always `false` after rotation because the Redis session does not
6740
6844
  * persist MFA verification state. A user who authenticated with MFA will lose the
@@ -6875,10 +6979,9 @@ declare class TokenManagerService {
6875
6979
  * @param token - The MFA temp JWT issued by {@link issueMfaTempToken}.
6876
6980
  * @returns The `userId`, `context`, and `jti` from the token. Pass the
6877
6981
  * `jti` to {@link consumeMfaTempToken} after TOTP validation succeeds.
6878
- * @throws {@link AuthException} with `MFA_TEMP_TOKEN_INVALID` if the
6879
- * Redis entry is missing (already consumed, expired, or never issued).
6880
- * @throws {Error} When JWT signature or expiry validation fails (propagated
6881
- * directly from `JwtService.verify()` — not wrapped in {@link AuthException}).
6982
+ * @throws {@link AuthException} with `MFA_TEMP_TOKEN_INVALID` for every way the token can be
6983
+ * unusable — a bad signature, an expired one, a shape no secret accepts, or a missing Redis
6984
+ * entry (already consumed, expired, or never issued).
6882
6985
  */
6883
6986
  verifyMfaTempToken(token: string): Promise<{
6884
6987
  userId: string;
@@ -8543,10 +8646,11 @@ declare class OAuthService {
8543
8646
  * 5. Issues a 302 redirect via the Express `res` object.
8544
8647
  *
8545
8648
  * @param provider - Provider name matching a registered {@link OAuthProviderPlugin}.
8546
- * @param tenantId - Tenant the user will join on successful login, as named by the caller.
8547
- * Superseded by the configured `tenantIdResolver` when there is one, and never validated
8548
- * against the database — implement `onOAuthLogin` to enforce tenant membership. Without
8549
- * the hook, OAuth sign-in is disabled.
8649
+ * @param tenantId - Tenant the user will join on successful login, as named by the caller in
8650
+ * the query string. **Refused** with `auth.validation` when a `tenantIdResolver` is
8651
+ * configured, since the deployment decides the tenant and a value it discards would only
8652
+ * mislead the caller. Never validated against the database — implement `onOAuthLogin` to
8653
+ * enforce tenant membership. Without the hook, OAuth sign-in is disabled.
8550
8654
  * @param req - Incoming Express request, read by the configured `tenantIdResolver`.
8551
8655
  * @param res - Express response in passthrough mode (used for the 302 redirect).
8552
8656
  * @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
@@ -8744,4 +8848,4 @@ declare function AuthRateLimit(config: {
8744
8848
  default: AuthRateLimitWindow;
8745
8849
  }): MethodDecorator;
8746
8850
 
8747
- export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
8851
+ export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
@@ -1070,15 +1070,18 @@ interface BymaxAuthModuleOptions {
1070
1070
  /**
1071
1071
  * Tenant ID resolver function.
1072
1072
  *
1073
- * When provided, the module resolves the tenant ID from the request object and
1074
- * **ignores** any `tenantId` field in the request body. This prevents tenant
1075
- * spoofing where a client sends a different tenant's ID.
1076
- *
1077
- * Because a configured resolver makes the body's value dead weight, `tenantId` is optional on
1078
- * every DTO that carries it and a client may omit it entirely. With no resolver configured the
1079
- * body is the only thing that can name a tenant, and a request naming none is refused with
1080
- * `auth.validation` — the deployment has to choose one of the two, and neither choice is
1081
- * guessed on its behalf.
1073
+ * When provided, the module resolves the tenant ID from the request object and **refuses** any
1074
+ * `tenantId` the request names — with `400 auth.validation` on the `tenantId` field. This
1075
+ * prevents tenant spoofing where a client sends a different tenant's ID, and it refuses rather
1076
+ * than ignoring on purpose: a discarded value answers `201` while putting the account
1077
+ * somewhere else, so the caller's belief and the server's state diverge on the tenancy
1078
+ * boundary with nothing saying so.
1079
+ *
1080
+ * A client under a resolver must therefore **omit the field**; `null` and an absent field are
1081
+ * both accepted, since neither asserts anything to contradict. With no resolver configured the
1082
+ * body is the only thing that can name a tenant, so there it is honoured, and a request naming
1083
+ * none is refused with the same `auth.validation` — the deployment has to choose one of the
1084
+ * two, and neither choice is guessed on its behalf.
1082
1085
  *
1083
1086
  * @param req - The Express request object
1084
1087
  * @returns The tenant ID string, or a Promise resolving to it
@@ -1681,7 +1684,7 @@ declare const AUTH_THROTTLE_CONFIGS: {
1681
1684
  readonly ttl: 60000;
1682
1685
  };
1683
1686
  };
1684
- /** DELETE /auth/sessions/all — 5 requests per minute per IP. */
1687
+ /** POST /auth/sessions/revoke-all — 5 requests per minute per IP. */
1685
1688
  readonly revokeAllSessions: {
1686
1689
  readonly default: {
1687
1690
  readonly limit: 5;
@@ -5152,8 +5155,25 @@ declare class WsJwtGuard implements CanActivate, OnModuleInit {
5152
5155
  * stack detail or a connection string reaches a response body, so the answer carries the
5153
5156
  * generic code and nothing else.
5154
5157
  *
5158
+ * **Do not register this alongside `@bymax-one/nest-core`'s envelope filter.** They are mutually
5159
+ * exclusive in practice and this one wins: `useGlobalFilters` binds ahead of an `APP_FILTER`
5160
+ * provider, and `@Catch()` with no argument catches everything, so nest-core's filter never runs.
5161
+ * Measured on a composed application — the same request answers
5162
+ * `{error: {code, message, details}}` with this filter registered and the flat
5163
+ * `{statusCode, code, message, timestamp, path, details}` without it. A derived backend that
5164
+ * registers both therefore loses `statusCode`, `timestamp`, `path` and the correlation id, which
5165
+ * is the opposite of what registering an extra filter looks like it should do.
5166
+ *
5167
+ * Pick one. On a backend built on nest-core, take theirs: it already recognises this library's
5168
+ * envelope and passes the code, message and per-field details through unchanged.
5169
+ *
5170
+ * Nothing in this repository asserts that, and deliberately so — verifying it would mean this
5171
+ * library depending on a consumer's stack. The behaviour above was measured once and the
5172
+ * dependency removed; the standing assertion belongs to whoever composes the two.
5173
+ *
5155
5174
  * @example
5156
5175
  * ```typescript
5176
+ * // Only when nest-core's envelope filter is NOT in the application.
5157
5177
  * app.useGlobalFilters(new AuthExceptionFilter())
5158
5178
  * ```
5159
5179
  *
@@ -5170,6 +5190,59 @@ declare class AuthExceptionFilter implements ExceptionFilter {
5170
5190
  catch(exception: unknown, host: ArgumentsHost): void;
5171
5191
  }
5172
5192
 
5193
+ /**
5194
+ * Gives a refused WebSocket client the library's error envelope instead of a generic failure.
5195
+ *
5196
+ * Register it on a gateway that applies {@link WsJwtGuard}. Without it, the guard's refusals do
5197
+ * not survive the transport: `AuthException` extends `HttpException`, Nest's WebSocket exception
5198
+ * layer understands only `WsException`, and everything else is delivered as
5199
+ * `{status: 'error', message: 'Internal server error'}` — so the whole `auth.*` catalogue stops
5200
+ * at the socket boundary.
5201
+ *
5202
+ * That is not only untidy. A client cannot tell a dead credential from a crashed handler, and a
5203
+ * reconnect policy has to choose: retrying an unknown error is the sensible default, so every
5204
+ * expired token becomes a reconnect loop against an endpoint that will refuse it forever. With
5205
+ * this filter the client reads `error.code` and can send the user to sign in instead.
5206
+ *
5207
+ * The payload keeps `status: 'error'` — the field Nest's own layer sets and every socket.io
5208
+ * client already branches on — and adds the envelope beside it, so a consumer handling both
5209
+ * shapes does not need a second listener:
5210
+ *
5211
+ * ```
5212
+ * without { status: 'error', message: 'Internal server error' }
5213
+ * with { status: 'error', error: { code: 'auth.token_invalid', message, details } }
5214
+ * ```
5215
+ *
5216
+ * **Scoped to `AuthException` on purpose.** An argument-less `@Catch()` would claim every
5217
+ * exception a gateway raises, so a `WsException` an unrelated handler throws — a domain error
5218
+ * with its own contract — would be rewritten as `auth.internal`, and following the README would
5219
+ * silently break a consumer's existing WebSocket errors. Everything that is not this library's
5220
+ * refusal keeps travelling through Nest's own exception layer.
5221
+ *
5222
+ * **Both transports.** A Socket.IO client is dispatched to with `emit`; a native `ws` client —
5223
+ * which also extends `EventEmitter`, so emitting on it succeeds and sends NOTHING — is written
5224
+ * to with `send`, in the `{event, data}` envelope `@nestjs/platform-ws` uses for every other
5225
+ * message. Both are driven over a real handshake in `test/e2e/ws-guard.e2e-spec.ts`.
5226
+ *
5227
+ * @example
5228
+ * ```typescript
5229
+ * @UseFilters(new WsAuthExceptionFilter())
5230
+ * @UseGuards(WsJwtGuard)
5231
+ * @WebSocketGateway()
5232
+ * export class FeedGateway { ... }
5233
+ * ```
5234
+ */
5235
+ declare class WsAuthExceptionFilter implements ExceptionFilter {
5236
+ private readonly logger;
5237
+ /**
5238
+ * Delivers the library envelope to the client whose request was refused.
5239
+ *
5240
+ * @param exception - The `AuthException` a guard, pipe or handler raised.
5241
+ * @param host - The arguments host, used to reach the connected client.
5242
+ */
5243
+ catch(exception: AuthException, host: ArgumentsHost): void;
5244
+ }
5245
+
5173
5246
  /**
5174
5247
  * @fileoverview The validation pipe every auth controller mounts.
5175
5248
  *
@@ -5813,6 +5886,23 @@ declare class ChangePasswordDto {
5813
5886
  * Hashed immediately by the service layer — never persisted in plaintext.
5814
5887
  */
5815
5888
  newPassword: string;
5889
+ /**
5890
+ * The caller's own refresh token, so the device making the change stays signed in.
5891
+ *
5892
+ * Declared because the handler reads it. `TokenDeliveryService.extractRefreshToken` takes it
5893
+ * from the refresh cookie under `tokenDelivery: 'cookie'` and from **this body field** under
5894
+ * `'bearer'`, cookie-first-then-body under `'both'` — and the controller pipe runs
5895
+ * `forbidNonWhitelisted: true`, so an undeclared property is refused. A bearer-mode caller
5896
+ * therefore could not send the field the endpoint needs: the request was answered
5897
+ * `auth.validation` naming `refreshToken`, and the only way to change a password was to give
5898
+ * up every other session.
5899
+ *
5900
+ * It stayed invisible because the E2E harness installed a global `ValidationPipe` with
5901
+ * `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
5902
+ * it — so the suite exercised a request production never sees. Optional, because under cookie
5903
+ * delivery the credential arrives in the cookie and no body field exists to declare.
5904
+ */
5905
+ refreshToken?: string;
5816
5906
  }
5817
5907
 
5818
5908
  /**
@@ -6734,7 +6824,21 @@ declare class TokenManagerService {
6734
6824
  * The `status` claim in the issued access token is intentionally empty during
6735
6825
  * rotation — the Redis session does not store full user data. Guards that enforce
6736
6826
  * status checks must read from the user repository or a status cache, not the
6737
- * JWT `status` claim.
6827
+ * JWT `status` claim. `rust-auth` stamps the same empty string at the same point, with a
6828
+ * test pinning it, so this is a shared contract rather than a local shortcut.
6829
+ *
6830
+ * **What that means for a consumer, which is where the cost lands.** `issueTokens` stamps the
6831
+ * account's value at that moment, this path stamps nothing, and `AuthService.refresh` re-stamps
6832
+ * it from the account when `role`, `tenantId` or `mfaEnabled` changed — so a session's tokens
6833
+ * carry a populated claim, then an empty one, then possibly a populated one again, with no
6834
+ * signal a client can read. A derived backend reading `request.user.status` is wrong in both
6835
+ * directions: `!== 'active'` refuses everyone whose session refreshed ordinarily, and
6836
+ * `=== 'suspended'` refuses nobody, ever.
6837
+ *
6838
+ * Backfilling it here would be worse than leaving it empty: the claim would become *usually*
6839
+ * true, which is the failure mode that survives testing, since status can still change under an
6840
+ * unexpired token. The claim cannot be authoritative, so it is not made to look like it — and
6841
+ * the empty string is the one state that cannot be mistaken for an answer.
6738
6842
  *
6739
6843
  * `mfaVerified` is always `false` after rotation because the Redis session does not
6740
6844
  * persist MFA verification state. A user who authenticated with MFA will lose the
@@ -6875,10 +6979,9 @@ declare class TokenManagerService {
6875
6979
  * @param token - The MFA temp JWT issued by {@link issueMfaTempToken}.
6876
6980
  * @returns The `userId`, `context`, and `jti` from the token. Pass the
6877
6981
  * `jti` to {@link consumeMfaTempToken} after TOTP validation succeeds.
6878
- * @throws {@link AuthException} with `MFA_TEMP_TOKEN_INVALID` if the
6879
- * Redis entry is missing (already consumed, expired, or never issued).
6880
- * @throws {Error} When JWT signature or expiry validation fails (propagated
6881
- * directly from `JwtService.verify()` — not wrapped in {@link AuthException}).
6982
+ * @throws {@link AuthException} with `MFA_TEMP_TOKEN_INVALID` for every way the token can be
6983
+ * unusable — a bad signature, an expired one, a shape no secret accepts, or a missing Redis
6984
+ * entry (already consumed, expired, or never issued).
6882
6985
  */
6883
6986
  verifyMfaTempToken(token: string): Promise<{
6884
6987
  userId: string;
@@ -8543,10 +8646,11 @@ declare class OAuthService {
8543
8646
  * 5. Issues a 302 redirect via the Express `res` object.
8544
8647
  *
8545
8648
  * @param provider - Provider name matching a registered {@link OAuthProviderPlugin}.
8546
- * @param tenantId - Tenant the user will join on successful login, as named by the caller.
8547
- * Superseded by the configured `tenantIdResolver` when there is one, and never validated
8548
- * against the database — implement `onOAuthLogin` to enforce tenant membership. Without
8549
- * the hook, OAuth sign-in is disabled.
8649
+ * @param tenantId - Tenant the user will join on successful login, as named by the caller in
8650
+ * the query string. **Refused** with `auth.validation` when a `tenantIdResolver` is
8651
+ * configured, since the deployment decides the tenant and a value it discards would only
8652
+ * mislead the caller. Never validated against the database — implement `onOAuthLogin` to
8653
+ * enforce tenant membership. Without the hook, OAuth sign-in is disabled.
8550
8654
  * @param req - Incoming Express request, read by the configured `tenantIdResolver`.
8551
8655
  * @param res - Express response in passthrough mode (used for the 302 redirect).
8552
8656
  * @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
@@ -8744,4 +8848,4 @@ declare function AuthRateLimit(config: {
8744
8848
  default: AuthRateLimitWindow;
8745
8849
  }): MethodDecorator;
8746
8850
 
8747
- export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
8851
+ export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthEmailCatalogue, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_BREACH_CHECKER, BYMAX_AUTH_EMAIL_PROVIDER, BYMAX_AUTH_HOOKS, BYMAX_AUTH_OPTIONS, BYMAX_AUTH_PLATFORM_USER_REPOSITORY, BYMAX_AUTH_REDIS_CLIENT, BYMAX_AUTH_USER_REPOSITORY, type BearerAuthResponse, type BeforeRegisterResult, type BothAuthResponse, BruteForceService, BymaxAuthModule, type BymaxAuthModuleOptions, type BymaxAuthRateLimitOptions, ChangePasswordDto, type ClientIpSource, CommonPasswordChecker, type CookieAuthResponse, CreateInvitationDto, type CreateUserData, type CreateWithOAuthData, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, type PlatformAuthResult, PlatformAuthService, type PlatformAuthenticatedRequest, type PlatformBearerAuthResponse, type PlatformJwtPayload, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, type ResolvedOptions, type RevocableTokenPayload, Roles, RolesGuard, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, type SessionInfo$1 as SessionInfo, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, type UpdateMfaData, type UpdatePlatformMfaData, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, type WsTicketSnapshot, createAuthValidationPipe, decrypt, encrypt, generateSecureToken, hasRole, hmacSha256, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };