@bymax-one/nest-auth 1.4.15 → 1.4.17

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.
@@ -772,6 +772,10 @@ interface BymaxAuthModuleOptions {
772
772
  * @remarks
773
773
  * Set this explicitly to `true` in a non-production environment that is nonetheless served
774
774
  * over HTTPS, so the cookies are marked `Secure` there too.
775
+ *
776
+ * `false` is refused at startup unless {@link BymaxAuthModuleOptions.environment} is
777
+ * `'development'` or `'test'`: a session cookie without `Secure` travels over plain HTTP, and a
778
+ * TLS-terminating proxy does not change that for the browser's side of the connection.
775
779
  */
776
780
  secureCookies?: boolean;
777
781
  /**
@@ -1476,8 +1480,12 @@ interface AuthModuleAsyncOptions {
1476
1480
  /**
1477
1481
  * Factory function that produces `BymaxAuthModuleOptions`.
1478
1482
  * Receives injected dependencies as arguments.
1483
+ *
1484
+ * The parameters are typed `never[]` so a factory may declare the types of what it injects,
1485
+ * `(config: ConfigService) => ...`: Nest supplies the values, and their types are the
1486
+ * consumer's declaration. A factory written with `...args: unknown[]` is accepted too.
1479
1487
  */
1480
- useFactory: (...args: unknown[]) => BymaxAuthModuleOptions | Promise<BymaxAuthModuleOptions>;
1488
+ useFactory: (...args: never[]) => BymaxAuthModuleOptions | Promise<BymaxAuthModuleOptions>;
1481
1489
  /** Injection tokens or providers to inject into `useFactory`. */
1482
1490
  inject?: (InjectionToken | OptionalFactoryDependency)[];
1483
1491
  /** Additional providers available within the async options scope. */
@@ -5360,7 +5368,15 @@ declare class TokenDeliveryService {
5360
5368
  private readCookie;
5361
5369
  /** Reads the access token from the Authorization Bearer header. */
5362
5370
  private readBearerHeader;
5363
- /** Reads the refresh token from the request body field. */
5371
+ /**
5372
+ * Reads the refresh token from the request body field.
5373
+ *
5374
+ * An omitted field and JSON `null` both mean "no token". Any other value that is not a string
5375
+ * of 1 to {@link REFRESH_TOKEN_MAX_LENGTH} characters is a malformed request, not a missing
5376
+ * token, and is refused before any caller acts on it.
5377
+ *
5378
+ * @throws {@link AuthException} `VALIDATION` when the field is present and malformed.
5379
+ */
5364
5380
  private readBodyRefresh;
5365
5381
  }
5366
5382
 
@@ -6057,6 +6073,11 @@ declare class WsJwtGuard implements CanActivate, OnModuleInit {
6057
6073
  * stack detail or a connection string reaches a response body, so the answer carries the
6058
6074
  * generic code and nothing else.
6059
6075
  *
6076
+ * Requests the HTTP layer refused before any route ran — a malformed body, an oversized one, an
6077
+ * unsupported charset or content-encoding — answer `auth.validation` with a fixed message and the
6078
+ * status the transport reported, never the parser's text. Express only: the filter writes through
6079
+ * Express's `Response` and reads `req.route`, so its behaviour on another adapter is not defined.
6080
+ *
6060
6081
  * **Do not register this alongside `@bymax-one/nest-core`'s envelope filter.** They are mutually
6061
6082
  * exclusive in practice and this one wins: `useGlobalFilters` binds ahead of an `APP_FILTER`
6062
6083
  * provider, and `@Catch()` with no argument catches everything, so nest-core's filter never runs.
@@ -7327,6 +7348,15 @@ interface RevokeSessionParams {
7327
7348
  /** SHA-256 hash of the session being revoked. */
7328
7349
  sessionHash: string;
7329
7350
  }
7351
+ /** Names the session {@link SessionService.assertLiveSession} checks. See {@link CreateSessionParams}. */
7352
+ interface LiveSessionParams {
7353
+ /** Internal user ID that must own the session. */
7354
+ userId: string;
7355
+ /** Tenant that user belongs to; scopes the session index. */
7356
+ tenantId: string;
7357
+ /** SHA-256 hash of the session that must be live. */
7358
+ sessionHash: string;
7359
+ }
7330
7360
  /** Everything {@link SessionService.revokeAllExceptCurrent} needs. See {@link CreateSessionParams}. */
7331
7361
  interface RevokeAllExceptCurrentParams {
7332
7362
  /** Internal user ID whose other sessions are ending. */
@@ -7408,18 +7438,29 @@ declare class SessionService {
7408
7438
  *
7409
7439
  * Reads all `rt:`-prefixed members from `sess:{userId}`, fetches the
7410
7440
  * corresponding `sd:{hash}` detail records, and marks the caller's own
7411
- * session via `isCurrent`. A member whose detail record is missing, unreadable
7412
- * or malformed is excluded from the result, and removed from the SET
7413
- * asynchronously (fire-and-forget) only if its `rt:` key is also gone — see
7414
- * {@link AuthRedisService.pruneDeadMembers} for why the detail record alone
7415
- * does not settle it.
7441
+ * session via `isCurrent`. A member whose detail record is missing or malformed
7442
+ * is excluded from the result. A member whose record cannot be read at all is not
7443
+ * left out quietly: the call rejects, because a session missing from the list is
7444
+ * one the caller cannot revoke. Either way the member is offered to a
7445
+ * fire-and-forget prune that removes it from the SET only if its `rt:` key is
7446
+ * also gone — see {@link AuthRedisService.pruneDeadMembers} for why the detail
7447
+ * record alone does not settle it.
7416
7448
  *
7417
7449
  * Results are sorted by `createdAt` descending (newest session first).
7418
7450
  *
7419
7451
  * @param params - See {@link ListSessionsParams}.
7420
7452
  * @returns Array of {@link SessionInfo} sorted newest-first.
7453
+ * @throws The store's error when a session's detail record cannot be read.
7421
7454
  */
7422
7455
  listSessions({ userId, tenantId, currentSessionHash }: ListSessionsParams): Promise<SessionInfo[]>;
7456
+ /**
7457
+ * Reads one index member's session detail and shapes it for the listing.
7458
+ *
7459
+ * @param member - The `rt:{hash}` index member.
7460
+ * @param currentSessionHash - Hash of the caller's own refresh token, when it sent one.
7461
+ * @returns The session, or why this member is not one: a data state or a read fault.
7462
+ */
7463
+ private readSession;
7423
7464
  /**
7424
7465
  * Revokes a single session belonging to the specified user.
7425
7466
  *
@@ -7458,12 +7499,42 @@ declare class SessionService {
7458
7499
  * @throws {@link AuthException} `SESSION_NOT_FOUND` when the session is not owned by the user.
7459
7500
  */
7460
7501
  revokeOtherSession({ userId, tenantId, sessionHash }: RevokeSessionParams): Promise<void>;
7502
+ /**
7503
+ * Refuses a session hash that names no live session of this user.
7504
+ *
7505
+ * For an operation that keeps one session and ends the rest and so has to be told which one,
7506
+ * checked before it changes anything. The membership test is the one {@link resolveLiveSession}
7507
+ * applies, so a token that has just rotated is accepted here exactly as it is there.
7508
+ *
7509
+ * @param params - See {@link LiveSessionParams}.
7510
+ * @throws {@link AuthException} `SESSION_NOT_FOUND` when the hash is not a live session.
7511
+ */
7512
+ assertLiveSession(params: LiveSessionParams): Promise<void>;
7513
+ /**
7514
+ * Names the live session a presented refresh-token hash stands for.
7515
+ *
7516
+ * The hash itself when it is a live session. When it is a token that rotated away moments ago,
7517
+ * the session the rotation produced: the rotation grace pointer `rp:{hash}` names that successor,
7518
+ * and the presented token still identifies the same device. A request that carries a refresh
7519
+ * token can lose a race to a refresh of the same session, and an operation that must keep "the
7520
+ * caller's session" would otherwise refuse the caller for having been refreshed. The pointer is
7521
+ * read, never consumed, and the successor has to be live in the index too, so a pointer left
7522
+ * behind by a session that was since revoked names nothing.
7523
+ *
7524
+ * @param params - See {@link LiveSessionParams}.
7525
+ * @returns The hash of the live session to keep: `sessionHash`, or its live successor.
7526
+ * @throws {@link AuthException} `SESSION_NOT_FOUND` when the hash is neither a live session nor
7527
+ * the predecessor of one.
7528
+ */
7529
+ resolveLiveSession({ userId, tenantId, sessionHash }: LiveSessionParams): Promise<string>;
7461
7530
  /**
7462
7531
  * Revokes all sessions for a user except the caller's current session.
7463
7532
  *
7464
7533
  * Reads all `rt:`-prefixed members from `sess:{userId}` and calls
7465
7534
  * {@link revokeSession} for each session whose hash differs from
7466
- * `currentSessionHash`. The current session is always preserved.
7535
+ * `currentSessionHash`. The current session is always preserved, and it has to exist: a hash
7536
+ * that names no live session of this user is refused before anything is revoked, since keeping
7537
+ * nothing would revoke every session the account has, the caller's own included.
7467
7538
  *
7468
7539
  * The user's token epoch is advanced as part of this, which is what makes the revocation
7469
7540
  * take effect *now* rather than whenever each device's access token happens to expire.
@@ -7482,6 +7553,8 @@ declare class SessionService {
7482
7553
  *
7483
7554
  * @param userId - Internal user ID whose other sessions are being revoked.
7484
7555
  * @param currentSessionHash - SHA-256 hash of the session to preserve.
7556
+ * @throws {@link AuthException} `SESSION_NOT_FOUND` when `currentSessionHash` names no live
7557
+ * session of this user.
7485
7558
  * @throws {unknown} Propagates any error thrown by `revokeSession` — including
7486
7559
  * {@link AuthException} with various codes, Redis errors, or other runtime errors.
7487
7560
  */
@@ -7537,6 +7610,21 @@ declare class SessionService {
7537
7610
  * @throws {@link AuthException} `VALIDATION` when the value is not 64 lowercase hex characters.
7538
7611
  */
7539
7612
  private assertValidSessionHash;
7613
+ /**
7614
+ * The hash of the live refresh session `sessionHash` stands for within `members`.
7615
+ *
7616
+ * @throws {@link AuthException} `SESSION_NOT_FOUND`.
7617
+ */
7618
+ private resolveLiveMember;
7619
+ /** Whether `members` holds a live refresh session with this hash. */
7620
+ private isLiveMember;
7621
+ /**
7622
+ * The successor hash a rotation grace pointer names, or `undefined` when there is none.
7623
+ *
7624
+ * The pointer's value is `{successorHash}:{record}`, split on the first colon exactly as the
7625
+ * rotation script writes it.
7626
+ */
7627
+ private graceSuccessor;
7540
7628
  /**
7541
7629
  * The Redis key of this user's session index.
7542
7630
  *
@@ -7573,6 +7661,15 @@ declare class SessionService {
7573
7661
  * @param userAgent - User-Agent string (forwarded to the `onSessionEvicted` hook context).
7574
7662
  */
7575
7663
  private enforceSessionLimit;
7664
+ /**
7665
+ * The creation time of a session, for ranking sessions by age.
7666
+ *
7667
+ * An absent record and one that is not a detail record both rank as `0`, the oldest: a state the
7668
+ * store reported, not a fault. A read the store fails propagates, because no age can be named.
7669
+ *
7670
+ * @param memberHash - SHA-256 hash of the session's refresh token.
7671
+ */
7672
+ private readCreatedAt;
7576
7673
  /**
7577
7674
  * Resolves the maximum number of concurrent sessions allowed for a user.
7578
7675
  *
@@ -9726,6 +9823,24 @@ declare class PasswordResetService {
9726
9823
  * the configured breach checker.
9727
9824
  */
9728
9825
  changePassword(userId: string, tenantId: string, dto: ChangePasswordDto, currentRefreshToken?: string): Promise<void>;
9826
+ /**
9827
+ * The hash of the live session a presented refresh token stands for, or `undefined` when the
9828
+ * request carried none. Refuses a token that names no live session of the account; a token that
9829
+ * rotated away while the password was being verified stands for the session that replaced it.
9830
+ */
9831
+ private resolveCurrentSession;
9832
+ /**
9833
+ * Ends every session but the one to keep, once the new password is already written.
9834
+ *
9835
+ * With no session to keep every session ends. A kept session can rotate away while the new
9836
+ * password is hashed; the sweep follows it to its successor, and when it cannot be followed
9837
+ * there is no current session left to spare, so every session ends and the cleanup that makes
9838
+ * the change safe is never aborted by the session it was told to spare. Any other failure of
9839
+ * the sweep propagates.
9840
+ */
9841
+ private endOtherSessions;
9842
+ /** Ends every session the account has and advances its token epoch. */
9843
+ private endAllSessions;
9729
9844
  /**
9730
9845
  * Sends the "your password changed" notice, fire-and-forget.
9731
9846
  *
@@ -10972,4 +11087,5 @@ declare class ApiKeyService {
10972
11087
  private validatedExpiry;
10973
11088
  }
10974
11089
 
10975
- export { API_KEY_MAX_LABEL_LENGTH, API_KEY_MAX_OVERLAP_SECONDS, AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AccountStatusService, AllowAllBreachChecker, type ApiKeyAccessEvent, type ApiKeyClock, type ApiKeyDenyReason, ApiKeyGuard, type ApiKeyPrincipal, ApiKeyScopes, ApiKeyService, type AuthApiKey, type AuthApiKeySummary, type AuthDocumentSecurityParams, type AuthEmailCatalogue, type AuthEmailContext, type AuthEmailKind, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthGuardFamily, type AuthModuleAsyncOptions, type AuthPlane, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, AuthTokenVerifierService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_API_KEY_CLOCK, BYMAX_AUTH_API_KEY_REPOSITORY, 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 CreateSessionParams, type CreateUserData, type CreateWithOAuthData, CurrentApiKey, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, type DeliveryErrorPolicyMap, EmailChangeService, type FindUserByEmailParams, type FindUserByOAuthIdParams, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IApiKeyRepository, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, type IssueApiKeyInput, type IssuedApiKey, JwtAuthGuard, JwtPlatformGuard, type LinkOAuthParams, type ListSessionsParams, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, type OpenApiSecurityRequirement, 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, type RevokeAllExceptCurrentParams, type RevokeAllSessionsParams, type RevokeSessionParams, Roles, RolesGuard, type RotateApiKeyInput, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, ServiceKey, type SessionAlertInfo, type SessionInfo, SessionService, SkipMfa, type TenantResolverRequest, type TenantScopedUserRef, TokenDeliveryService, TrustedOriginGuard, type UpdateEmailParams, type UpdateEmailVerifiedParams, type UpdateMfaData, type UpdateMfaParams, type UpdatePasswordParams, type UpdatePlatformMfaData, type UpdateStatusParams, UserStatusGuard, type VerifiedAccessToken, type VerifyAccessTokenOptions, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, type WsTicketSnapshot, authDocumentSecurity, createAuthValidationPipe, decrypt, describeChannelStatus, describeError, encrypt, generateSecureToken, hasRole, hmacSha256, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
11090
+ export { API_KEY_MAX_LABEL_LENGTH, API_KEY_MAX_OVERLAP_SECONDS, AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AccountStatusService, AllowAllBreachChecker, ApiKeyGuard, ApiKeyScopes, ApiKeyService, AuthException, AuthExceptionFilter, AuthRateLimit, AuthRateLimitGuard, AuthRevocationService, AuthService, AuthTokenVerifierService, Authenticated, BYMAX_AUTH_API_KEY_CLOCK, BYMAX_AUTH_API_KEY_REPOSITORY, 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, BruteForceService, BymaxAuthModule, ChangePasswordDto, CommonPasswordChecker, CreateInvitationDto, CurrentApiKey, CurrentUser, DefaultAuthEmailProvider, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, IS_PUBLIC_KEY, InvitationService, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformAuthService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, ServiceKey, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, authDocumentSecurity, createAuthValidationPipe, decrypt, describeChannelStatus, describeError, encrypt, generateSecureToken, hasRole, hmacSha256, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
11091
+ export type { ApiKeyAccessEvent, ApiKeyClock, ApiKeyDenyReason, ApiKeyPrincipal, AuthApiKey, AuthApiKeySummary, AuthDocumentSecurityParams, AuthEmailCatalogue, AuthEmailContext, AuthEmailKind, AuthEmailMessage, AuthEmailSink, AuthErrorCode, AuthFieldError, AuthGuardFamily, AuthModuleAsyncOptions, AuthPlane, AuthPlatformUser, AuthRateLimitWindow, AuthResult, AuthUser, AuthenticatedRequest, BearerAuthResponse, BeforeRegisterResult, BothAuthResponse, BymaxAuthModuleOptions, BymaxAuthRateLimitOptions, ClientIpSource, CookieAuthResponse, CreateSessionParams, CreateUserData, CreateWithOAuthData, DashboardJwtPayload, DefaultAuthEmailProviderOptions, DeliveryErrorPolicy, DeliveryErrorPolicyMap, FindUserByEmailParams, FindUserByOAuthIdParams, HookContext, IApiKeyRepository, IAuthHooks, IEmailProvider, IPasswordBreachChecker, IPlatformUserRepository, IUserRepository, InviteData, IssueApiKeyInput, IssuedApiKey, LinkOAuthParams, ListSessionsParams, LiveSessionParams, MfaChallengeResult, MfaSetupResult, MfaTempPayload, OAuthLoginResult, OAuthMfaChallengeResult, OAuthProfile, OAuthProviderPlugin, OpenApiSecurityRequirement, PlatformAuthResult, PlatformAuthenticatedRequest, PlatformBearerAuthResponse, PlatformJwtPayload, ResolvedOptions, RevocableTokenPayload, RevokeAllExceptCurrentParams, RevokeAllSessionsParams, RevokeSessionParams, RotateApiKeyInput, RotatedTokenResult, SafeAuthPlatformUser, SafeAuthUser, SessionAlertInfo, SessionInfo, TenantResolverRequest, TenantScopedUserRef, UpdateEmailParams, UpdateEmailVerifiedParams, UpdateMfaData, UpdateMfaParams, UpdatePasswordParams, UpdatePlatformMfaData, UpdateStatusParams, VerifiedAccessToken, VerifyAccessTokenOptions, WsTicketSnapshot };
@@ -772,6 +772,10 @@ interface BymaxAuthModuleOptions {
772
772
  * @remarks
773
773
  * Set this explicitly to `true` in a non-production environment that is nonetheless served
774
774
  * over HTTPS, so the cookies are marked `Secure` there too.
775
+ *
776
+ * `false` is refused at startup unless {@link BymaxAuthModuleOptions.environment} is
777
+ * `'development'` or `'test'`: a session cookie without `Secure` travels over plain HTTP, and a
778
+ * TLS-terminating proxy does not change that for the browser's side of the connection.
775
779
  */
776
780
  secureCookies?: boolean;
777
781
  /**
@@ -1476,8 +1480,12 @@ interface AuthModuleAsyncOptions {
1476
1480
  /**
1477
1481
  * Factory function that produces `BymaxAuthModuleOptions`.
1478
1482
  * Receives injected dependencies as arguments.
1483
+ *
1484
+ * The parameters are typed `never[]` so a factory may declare the types of what it injects,
1485
+ * `(config: ConfigService) => ...`: Nest supplies the values, and their types are the
1486
+ * consumer's declaration. A factory written with `...args: unknown[]` is accepted too.
1479
1487
  */
1480
- useFactory: (...args: unknown[]) => BymaxAuthModuleOptions | Promise<BymaxAuthModuleOptions>;
1488
+ useFactory: (...args: never[]) => BymaxAuthModuleOptions | Promise<BymaxAuthModuleOptions>;
1481
1489
  /** Injection tokens or providers to inject into `useFactory`. */
1482
1490
  inject?: (InjectionToken | OptionalFactoryDependency)[];
1483
1491
  /** Additional providers available within the async options scope. */
@@ -5360,7 +5368,15 @@ declare class TokenDeliveryService {
5360
5368
  private readCookie;
5361
5369
  /** Reads the access token from the Authorization Bearer header. */
5362
5370
  private readBearerHeader;
5363
- /** Reads the refresh token from the request body field. */
5371
+ /**
5372
+ * Reads the refresh token from the request body field.
5373
+ *
5374
+ * An omitted field and JSON `null` both mean "no token". Any other value that is not a string
5375
+ * of 1 to {@link REFRESH_TOKEN_MAX_LENGTH} characters is a malformed request, not a missing
5376
+ * token, and is refused before any caller acts on it.
5377
+ *
5378
+ * @throws {@link AuthException} `VALIDATION` when the field is present and malformed.
5379
+ */
5364
5380
  private readBodyRefresh;
5365
5381
  }
5366
5382
 
@@ -6057,6 +6073,11 @@ declare class WsJwtGuard implements CanActivate, OnModuleInit {
6057
6073
  * stack detail or a connection string reaches a response body, so the answer carries the
6058
6074
  * generic code and nothing else.
6059
6075
  *
6076
+ * Requests the HTTP layer refused before any route ran — a malformed body, an oversized one, an
6077
+ * unsupported charset or content-encoding — answer `auth.validation` with a fixed message and the
6078
+ * status the transport reported, never the parser's text. Express only: the filter writes through
6079
+ * Express's `Response` and reads `req.route`, so its behaviour on another adapter is not defined.
6080
+ *
6060
6081
  * **Do not register this alongside `@bymax-one/nest-core`'s envelope filter.** They are mutually
6061
6082
  * exclusive in practice and this one wins: `useGlobalFilters` binds ahead of an `APP_FILTER`
6062
6083
  * provider, and `@Catch()` with no argument catches everything, so nest-core's filter never runs.
@@ -7327,6 +7348,15 @@ interface RevokeSessionParams {
7327
7348
  /** SHA-256 hash of the session being revoked. */
7328
7349
  sessionHash: string;
7329
7350
  }
7351
+ /** Names the session {@link SessionService.assertLiveSession} checks. See {@link CreateSessionParams}. */
7352
+ interface LiveSessionParams {
7353
+ /** Internal user ID that must own the session. */
7354
+ userId: string;
7355
+ /** Tenant that user belongs to; scopes the session index. */
7356
+ tenantId: string;
7357
+ /** SHA-256 hash of the session that must be live. */
7358
+ sessionHash: string;
7359
+ }
7330
7360
  /** Everything {@link SessionService.revokeAllExceptCurrent} needs. See {@link CreateSessionParams}. */
7331
7361
  interface RevokeAllExceptCurrentParams {
7332
7362
  /** Internal user ID whose other sessions are ending. */
@@ -7408,18 +7438,29 @@ declare class SessionService {
7408
7438
  *
7409
7439
  * Reads all `rt:`-prefixed members from `sess:{userId}`, fetches the
7410
7440
  * corresponding `sd:{hash}` detail records, and marks the caller's own
7411
- * session via `isCurrent`. A member whose detail record is missing, unreadable
7412
- * or malformed is excluded from the result, and removed from the SET
7413
- * asynchronously (fire-and-forget) only if its `rt:` key is also gone — see
7414
- * {@link AuthRedisService.pruneDeadMembers} for why the detail record alone
7415
- * does not settle it.
7441
+ * session via `isCurrent`. A member whose detail record is missing or malformed
7442
+ * is excluded from the result. A member whose record cannot be read at all is not
7443
+ * left out quietly: the call rejects, because a session missing from the list is
7444
+ * one the caller cannot revoke. Either way the member is offered to a
7445
+ * fire-and-forget prune that removes it from the SET only if its `rt:` key is
7446
+ * also gone — see {@link AuthRedisService.pruneDeadMembers} for why the detail
7447
+ * record alone does not settle it.
7416
7448
  *
7417
7449
  * Results are sorted by `createdAt` descending (newest session first).
7418
7450
  *
7419
7451
  * @param params - See {@link ListSessionsParams}.
7420
7452
  * @returns Array of {@link SessionInfo} sorted newest-first.
7453
+ * @throws The store's error when a session's detail record cannot be read.
7421
7454
  */
7422
7455
  listSessions({ userId, tenantId, currentSessionHash }: ListSessionsParams): Promise<SessionInfo[]>;
7456
+ /**
7457
+ * Reads one index member's session detail and shapes it for the listing.
7458
+ *
7459
+ * @param member - The `rt:{hash}` index member.
7460
+ * @param currentSessionHash - Hash of the caller's own refresh token, when it sent one.
7461
+ * @returns The session, or why this member is not one: a data state or a read fault.
7462
+ */
7463
+ private readSession;
7423
7464
  /**
7424
7465
  * Revokes a single session belonging to the specified user.
7425
7466
  *
@@ -7458,12 +7499,42 @@ declare class SessionService {
7458
7499
  * @throws {@link AuthException} `SESSION_NOT_FOUND` when the session is not owned by the user.
7459
7500
  */
7460
7501
  revokeOtherSession({ userId, tenantId, sessionHash }: RevokeSessionParams): Promise<void>;
7502
+ /**
7503
+ * Refuses a session hash that names no live session of this user.
7504
+ *
7505
+ * For an operation that keeps one session and ends the rest and so has to be told which one,
7506
+ * checked before it changes anything. The membership test is the one {@link resolveLiveSession}
7507
+ * applies, so a token that has just rotated is accepted here exactly as it is there.
7508
+ *
7509
+ * @param params - See {@link LiveSessionParams}.
7510
+ * @throws {@link AuthException} `SESSION_NOT_FOUND` when the hash is not a live session.
7511
+ */
7512
+ assertLiveSession(params: LiveSessionParams): Promise<void>;
7513
+ /**
7514
+ * Names the live session a presented refresh-token hash stands for.
7515
+ *
7516
+ * The hash itself when it is a live session. When it is a token that rotated away moments ago,
7517
+ * the session the rotation produced: the rotation grace pointer `rp:{hash}` names that successor,
7518
+ * and the presented token still identifies the same device. A request that carries a refresh
7519
+ * token can lose a race to a refresh of the same session, and an operation that must keep "the
7520
+ * caller's session" would otherwise refuse the caller for having been refreshed. The pointer is
7521
+ * read, never consumed, and the successor has to be live in the index too, so a pointer left
7522
+ * behind by a session that was since revoked names nothing.
7523
+ *
7524
+ * @param params - See {@link LiveSessionParams}.
7525
+ * @returns The hash of the live session to keep: `sessionHash`, or its live successor.
7526
+ * @throws {@link AuthException} `SESSION_NOT_FOUND` when the hash is neither a live session nor
7527
+ * the predecessor of one.
7528
+ */
7529
+ resolveLiveSession({ userId, tenantId, sessionHash }: LiveSessionParams): Promise<string>;
7461
7530
  /**
7462
7531
  * Revokes all sessions for a user except the caller's current session.
7463
7532
  *
7464
7533
  * Reads all `rt:`-prefixed members from `sess:{userId}` and calls
7465
7534
  * {@link revokeSession} for each session whose hash differs from
7466
- * `currentSessionHash`. The current session is always preserved.
7535
+ * `currentSessionHash`. The current session is always preserved, and it has to exist: a hash
7536
+ * that names no live session of this user is refused before anything is revoked, since keeping
7537
+ * nothing would revoke every session the account has, the caller's own included.
7467
7538
  *
7468
7539
  * The user's token epoch is advanced as part of this, which is what makes the revocation
7469
7540
  * take effect *now* rather than whenever each device's access token happens to expire.
@@ -7482,6 +7553,8 @@ declare class SessionService {
7482
7553
  *
7483
7554
  * @param userId - Internal user ID whose other sessions are being revoked.
7484
7555
  * @param currentSessionHash - SHA-256 hash of the session to preserve.
7556
+ * @throws {@link AuthException} `SESSION_NOT_FOUND` when `currentSessionHash` names no live
7557
+ * session of this user.
7485
7558
  * @throws {unknown} Propagates any error thrown by `revokeSession` — including
7486
7559
  * {@link AuthException} with various codes, Redis errors, or other runtime errors.
7487
7560
  */
@@ -7537,6 +7610,21 @@ declare class SessionService {
7537
7610
  * @throws {@link AuthException} `VALIDATION` when the value is not 64 lowercase hex characters.
7538
7611
  */
7539
7612
  private assertValidSessionHash;
7613
+ /**
7614
+ * The hash of the live refresh session `sessionHash` stands for within `members`.
7615
+ *
7616
+ * @throws {@link AuthException} `SESSION_NOT_FOUND`.
7617
+ */
7618
+ private resolveLiveMember;
7619
+ /** Whether `members` holds a live refresh session with this hash. */
7620
+ private isLiveMember;
7621
+ /**
7622
+ * The successor hash a rotation grace pointer names, or `undefined` when there is none.
7623
+ *
7624
+ * The pointer's value is `{successorHash}:{record}`, split on the first colon exactly as the
7625
+ * rotation script writes it.
7626
+ */
7627
+ private graceSuccessor;
7540
7628
  /**
7541
7629
  * The Redis key of this user's session index.
7542
7630
  *
@@ -7573,6 +7661,15 @@ declare class SessionService {
7573
7661
  * @param userAgent - User-Agent string (forwarded to the `onSessionEvicted` hook context).
7574
7662
  */
7575
7663
  private enforceSessionLimit;
7664
+ /**
7665
+ * The creation time of a session, for ranking sessions by age.
7666
+ *
7667
+ * An absent record and one that is not a detail record both rank as `0`, the oldest: a state the
7668
+ * store reported, not a fault. A read the store fails propagates, because no age can be named.
7669
+ *
7670
+ * @param memberHash - SHA-256 hash of the session's refresh token.
7671
+ */
7672
+ private readCreatedAt;
7576
7673
  /**
7577
7674
  * Resolves the maximum number of concurrent sessions allowed for a user.
7578
7675
  *
@@ -9726,6 +9823,24 @@ declare class PasswordResetService {
9726
9823
  * the configured breach checker.
9727
9824
  */
9728
9825
  changePassword(userId: string, tenantId: string, dto: ChangePasswordDto, currentRefreshToken?: string): Promise<void>;
9826
+ /**
9827
+ * The hash of the live session a presented refresh token stands for, or `undefined` when the
9828
+ * request carried none. Refuses a token that names no live session of the account; a token that
9829
+ * rotated away while the password was being verified stands for the session that replaced it.
9830
+ */
9831
+ private resolveCurrentSession;
9832
+ /**
9833
+ * Ends every session but the one to keep, once the new password is already written.
9834
+ *
9835
+ * With no session to keep every session ends. A kept session can rotate away while the new
9836
+ * password is hashed; the sweep follows it to its successor, and when it cannot be followed
9837
+ * there is no current session left to spare, so every session ends and the cleanup that makes
9838
+ * the change safe is never aborted by the session it was told to spare. Any other failure of
9839
+ * the sweep propagates.
9840
+ */
9841
+ private endOtherSessions;
9842
+ /** Ends every session the account has and advances its token epoch. */
9843
+ private endAllSessions;
9729
9844
  /**
9730
9845
  * Sends the "your password changed" notice, fire-and-forget.
9731
9846
  *
@@ -10972,4 +11087,5 @@ declare class ApiKeyService {
10972
11087
  private validatedExpiry;
10973
11088
  }
10974
11089
 
10975
- export { API_KEY_MAX_LABEL_LENGTH, API_KEY_MAX_OVERLAP_SECONDS, AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AccountStatusService, AllowAllBreachChecker, type ApiKeyAccessEvent, type ApiKeyClock, type ApiKeyDenyReason, ApiKeyGuard, type ApiKeyPrincipal, ApiKeyScopes, ApiKeyService, type AuthApiKey, type AuthApiKeySummary, type AuthDocumentSecurityParams, type AuthEmailCatalogue, type AuthEmailContext, type AuthEmailKind, type AuthEmailMessage, type AuthEmailSink, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthGuardFamily, type AuthModuleAsyncOptions, type AuthPlane, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, AuthRevocationService, AuthService, AuthTokenVerifierService, type AuthUser, Authenticated, type AuthenticatedRequest, BYMAX_AUTH_API_KEY_CLOCK, BYMAX_AUTH_API_KEY_REPOSITORY, 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 CreateSessionParams, type CreateUserData, type CreateWithOAuthData, CurrentApiKey, CurrentUser, type DashboardJwtPayload, DefaultAuthEmailProvider, type DefaultAuthEmailProviderOptions, type DeliveryErrorPolicy, type DeliveryErrorPolicyMap, EmailChangeService, type FindUserByEmailParams, type FindUserByOAuthIdParams, ForgotPasswordDto, HibpBreachChecker, type HookContext, type IApiKeyRepository, type IAuthHooks, type IEmailProvider, type IPasswordBreachChecker, type IPlatformUserRepository, IS_PUBLIC_KEY, type IUserRepository, InvitationService, type InviteData, type IssueApiKeyInput, type IssuedApiKey, JwtAuthGuard, JwtPlatformGuard, type LinkOAuthParams, type ListSessionsParams, LoginDto, MfaChallengeDto, type MfaChallengeResult, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, type MfaSetupResult, type MfaTempPayload, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, type OAuthLoginResult, type OAuthMfaChallengeResult, type OAuthProfile, type OAuthProviderPlugin, OAuthService, type OpenApiSecurityRequirement, 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, type RevokeAllExceptCurrentParams, type RevokeAllSessionsParams, type RevokeSessionParams, Roles, RolesGuard, type RotateApiKeyInput, type RotatedTokenResult, SKIP_MFA_KEY, type SafeAuthPlatformUser, type SafeAuthUser, SelfOrAdminGuard, ServiceKey, type SessionAlertInfo, type SessionInfo, SessionService, SkipMfa, type TenantResolverRequest, type TenantScopedUserRef, TokenDeliveryService, TrustedOriginGuard, type UpdateEmailParams, type UpdateEmailVerifiedParams, type UpdateMfaData, type UpdateMfaParams, type UpdatePasswordParams, type UpdatePlatformMfaData, type UpdateStatusParams, UserStatusGuard, type VerifiedAccessToken, type VerifyAccessTokenOptions, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, type WsTicketSnapshot, authDocumentSecurity, createAuthValidationPipe, decrypt, describeChannelStatus, describeError, encrypt, generateSecureToken, hasRole, hmacSha256, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
11090
+ export { API_KEY_MAX_LABEL_LENGTH, API_KEY_MAX_OVERLAP_SECONDS, AUTH_EMAIL_KINDS, AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_ERROR_STATUS, AUTH_SECURITY_SCHEMES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, AccountStatusService, AllowAllBreachChecker, ApiKeyGuard, ApiKeyScopes, ApiKeyService, AuthException, AuthExceptionFilter, AuthRateLimit, AuthRateLimitGuard, AuthRevocationService, AuthService, AuthTokenVerifierService, Authenticated, BYMAX_AUTH_API_KEY_CLOCK, BYMAX_AUTH_API_KEY_REPOSITORY, 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, BruteForceService, BymaxAuthModule, ChangePasswordDto, CommonPasswordChecker, CreateInvitationDto, CurrentApiKey, CurrentUser, DefaultAuthEmailProvider, EmailChangeService, ForgotPasswordDto, HibpBreachChecker, IS_PUBLIC_KEY, InvitationService, JwtAuthGuard, JwtPlatformGuard, LoginDto, MfaChallengeDto, MfaDisableDto, MfaRegenerateRecoveryCodesDto, MfaRequiredGuard, MfaService, MfaVerifyDto, NoOpAuthHooks, NoOpEmailProvider, OAuthService, OptionalAuthGuard, OtpService, PLATFORM_ROLES_KEY, PasswordResetService, PlatformAuthService, PlatformLoginDto, PlatformRoles, PlatformRolesGuard, Public, ROLES_KEY, RegisterDto, ResendOtpDto, ResendVerificationDto, ResetPasswordDto, Roles, RolesGuard, SKIP_MFA_KEY, SelfOrAdminGuard, ServiceKey, SessionService, SkipMfa, TokenDeliveryService, TrustedOriginGuard, UserStatusGuard, VerifyEmailDto, VerifyOtpDto, WS_TICKET_TTL_SECONDS, WsAuthExceptionFilter, WsJwtGuard, WsTicketService, authDocumentSecurity, createAuthValidationPipe, decrypt, describeChannelStatus, describeError, encrypt, generateSecureToken, hasRole, hmacSha256, redactSecrets, reduceToBaseWord, sanitizeHeaders, sha256, sleep, timingSafeCompare };
11091
+ export type { ApiKeyAccessEvent, ApiKeyClock, ApiKeyDenyReason, ApiKeyPrincipal, AuthApiKey, AuthApiKeySummary, AuthDocumentSecurityParams, AuthEmailCatalogue, AuthEmailContext, AuthEmailKind, AuthEmailMessage, AuthEmailSink, AuthErrorCode, AuthFieldError, AuthGuardFamily, AuthModuleAsyncOptions, AuthPlane, AuthPlatformUser, AuthRateLimitWindow, AuthResult, AuthUser, AuthenticatedRequest, BearerAuthResponse, BeforeRegisterResult, BothAuthResponse, BymaxAuthModuleOptions, BymaxAuthRateLimitOptions, ClientIpSource, CookieAuthResponse, CreateSessionParams, CreateUserData, CreateWithOAuthData, DashboardJwtPayload, DefaultAuthEmailProviderOptions, DeliveryErrorPolicy, DeliveryErrorPolicyMap, FindUserByEmailParams, FindUserByOAuthIdParams, HookContext, IApiKeyRepository, IAuthHooks, IEmailProvider, IPasswordBreachChecker, IPlatformUserRepository, IUserRepository, InviteData, IssueApiKeyInput, IssuedApiKey, LinkOAuthParams, ListSessionsParams, LiveSessionParams, MfaChallengeResult, MfaSetupResult, MfaTempPayload, OAuthLoginResult, OAuthMfaChallengeResult, OAuthProfile, OAuthProviderPlugin, OpenApiSecurityRequirement, PlatformAuthResult, PlatformAuthenticatedRequest, PlatformBearerAuthResponse, PlatformJwtPayload, ResolvedOptions, RevocableTokenPayload, RevokeAllExceptCurrentParams, RevokeAllSessionsParams, RevokeSessionParams, RotateApiKeyInput, RotatedTokenResult, SafeAuthPlatformUser, SafeAuthUser, SessionAlertInfo, SessionInfo, TenantResolverRequest, TenantScopedUserRef, UpdateEmailParams, UpdateEmailVerifiedParams, UpdateMfaData, UpdateMfaParams, UpdatePasswordParams, UpdatePlatformMfaData, UpdateStatusParams, VerifiedAccessToken, VerifyAccessTokenOptions, WsTicketSnapshot };