@bymax-one/nest-auth 1.2.0 → 1.3.1

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.
@@ -426,7 +426,7 @@ interface BymaxAuthModuleOptions {
426
426
  refreshExpiresInDays?: number;
427
427
  /**
428
428
  * Hard cap on how long one login can be extended by rotation, in days.
429
- * Default: `0` — no cap.
429
+ * Default: `30`. Set to `0` to disable the cap.
430
430
  *
431
431
  * `refreshExpiresInDays` bounds how long a single refresh token lives, not how long a
432
432
  * *session* lives: a client that rotates every fifteen minutes renews that lifetime
@@ -435,9 +435,12 @@ interface BymaxAuthModuleOptions {
435
435
  * carried through every rotation, and once the cap is passed the rotation is refused and
436
436
  * the user signs in again.
437
437
  *
438
- * Left off by default because switching it on ends sessions that are already older than
439
- * the cap. Pick a value the product can justify asking a user to re-authenticate at (30
440
- * or 90 days are common), and set it deliberately.
438
+ * On by default at 30 days, because NIST SP 800-63B-4 §3 makes a definite reauthentication
439
+ * timeout a SHALL and puts it at no more than 30 days for AAL1. Without the cap a refresh
440
+ * token stolen once converts into permanent access: reuse detection only fires if the
441
+ * legitimate client also replays, which it never will once the victim has stopped using
442
+ * that device. Raise it to a value the product can justify asking a user to re-authenticate
443
+ * at, or set `0` to accept unbounded sessions deliberately.
441
444
  *
442
445
  * Sessions written before this existed carry no birth time and are not capped; they age
443
446
  * out under `refreshExpiresInDays` like any other.
@@ -1063,6 +1066,12 @@ interface BymaxAuthModuleOptions {
1063
1066
  * **ignores** any `tenantId` field in the request body. This prevents tenant
1064
1067
  * spoofing where a client sends a different tenant's ID.
1065
1068
  *
1069
+ * Because a configured resolver makes the body's value dead weight, `tenantId` is optional on
1070
+ * every DTO that carries it and a client may omit it entirely. With no resolver configured the
1071
+ * body is the only thing that can name a tenant, and a request naming none is refused with
1072
+ * `auth.validation` — the deployment has to choose one of the two, and neither choice is
1073
+ * guessed on its behalf.
1074
+ *
1066
1075
  * @param req - The Express request object
1067
1076
  * @returns The tenant ID string, or a Promise resolving to it
1068
1077
  *
@@ -2135,11 +2144,13 @@ interface IEmailProvider {
2135
2144
  * The email should contain a time-limited URL with the token embedded as a
2136
2145
  * query parameter (e.g. `/reset-password?token=...`).
2137
2146
  *
2147
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2148
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2138
2149
  * @param email - Recipient's email address.
2139
2150
  * @param token - Signed, opaque reset token. Never log or expose this value.
2140
2151
  * @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
2141
2152
  */
2142
- sendPasswordResetToken(email: string, token: string, locale?: string): Promise<void>;
2153
+ sendPasswordResetToken(tenantId: string, email: string, token: string, locale?: string): Promise<void>;
2143
2154
  /**
2144
2155
  * Sends a one-time password (OTP) code for password reset to the user.
2145
2156
  *
@@ -2147,11 +2158,13 @@ interface IEmailProvider {
2147
2158
  * The email should display the numeric/alphanumeric code clearly and state
2148
2159
  * its expiry time.
2149
2160
  *
2161
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2162
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2150
2163
  * @param email - Recipient's email address.
2151
2164
  * @param otp - Short-lived OTP code. Never log or expose this value.
2152
2165
  * @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
2153
2166
  */
2154
- sendPasswordResetOtp(email: string, otp: string, locale?: string): Promise<void>;
2167
+ sendPasswordResetOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
2155
2168
  /**
2156
2169
  * Sends an OTP code to verify the user's email address during registration or
2157
2170
  * email-change flows.
@@ -2159,11 +2172,13 @@ interface IEmailProvider {
2159
2172
  * Called immediately after account creation (when email verification is enabled)
2160
2173
  * or when the user requests a new verification code.
2161
2174
  *
2175
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2176
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2162
2177
  * @param email - Recipient's email address to be verified.
2163
2178
  * @param otp - Short-lived OTP code for verification. Never log or expose this value.
2164
2179
  * @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
2165
2180
  */
2166
- sendEmailVerificationOtp(email: string, otp: string, locale?: string): Promise<void>;
2181
+ sendEmailVerificationOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
2167
2182
  /**
2168
2183
  * Notifies the user that the password on their account has changed.
2169
2184
  *
@@ -2179,10 +2194,12 @@ interface IEmailProvider {
2179
2194
  * it when present and logs at debug when it is not, rather than failing a password change
2180
2195
  * over a missing notification.
2181
2196
  *
2197
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2198
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2182
2199
  * @param email - Recipient's email address.
2183
2200
  * @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
2184
2201
  */
2185
- sendPasswordChangedNotification?(email: string, locale?: string): Promise<void>;
2202
+ sendPasswordChangedNotification?(tenantId: string, email: string, locale?: string): Promise<void>;
2186
2203
  /**
2187
2204
  * Sends the address-change verification link to the **new** address.
2188
2205
  *
@@ -2193,11 +2210,13 @@ interface IEmailProvider {
2193
2210
  * Optional on the interface so an existing consumer keeps compiling, but the flow refuses
2194
2211
  * to mint a token when it is absent rather than writing one nobody will ever receive.
2195
2212
  *
2213
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2214
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2196
2215
  * @param newEmail - The address being moved to.
2197
2216
  * @param token - The raw single-use token. The provider builds the confirmation URL.
2198
2217
  * @param locale - Optional locale for the template.
2199
2218
  */
2200
- sendEmailChangeVerification?(newEmail: string, token: string, locale?: string): Promise<void>;
2219
+ sendEmailChangeVerification?(tenantId: string, newEmail: string, token: string, locale?: string): Promise<void>;
2201
2220
  /**
2202
2221
  * Notifies the **old** address that the account's address has changed.
2203
2222
  *
@@ -2209,11 +2228,13 @@ interface IEmailProvider {
2209
2228
  * Fire-and-forget — a delivery failure does not roll back a change the user asked for and
2210
2229
  * has already proven.
2211
2230
  *
2231
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2232
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2212
2233
  * @param oldEmail - The address the account is leaving.
2213
2234
  * @param newEmail - The address it moved to, so the notice can say what happened.
2214
2235
  * @param locale - Optional locale for the template.
2215
2236
  */
2216
- sendEmailChangedNotification?(oldEmail: string, newEmail: string, locale?: string): Promise<void>;
2237
+ sendEmailChangedNotification?(tenantId: string, oldEmail: string, newEmail: string, locale?: string): Promise<void>;
2217
2238
  /**
2218
2239
  * Notifies the user that multi-factor authentication (MFA) has been enabled on
2219
2240
  * their account.
@@ -2222,10 +2243,12 @@ interface IEmailProvider {
2222
2243
  * security alert — if the user did not initiate this change, they should be
2223
2244
  * directed to contact support or reset their credentials.
2224
2245
  *
2246
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2247
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2225
2248
  * @param email - Recipient's email address.
2226
2249
  * @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
2227
2250
  */
2228
- sendMfaEnabledNotification(email: string, locale?: string): Promise<void>;
2251
+ sendMfaEnabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
2229
2252
  /**
2230
2253
  * Notifies the user that multi-factor authentication (MFA) has been disabled on
2231
2254
  * their account.
@@ -2234,10 +2257,12 @@ interface IEmailProvider {
2234
2257
  * alert — if the user did not initiate this change, they should be directed to
2235
2258
  * contact support or reset their credentials immediately.
2236
2259
  *
2260
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2261
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2237
2262
  * @param email - Recipient's email address.
2238
2263
  * @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
2239
2264
  */
2240
- sendMfaDisabledNotification(email: string, locale?: string): Promise<void>;
2265
+ sendMfaDisabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
2241
2266
  /**
2242
2267
  * Sends a security alert about a newly established session.
2243
2268
  *
@@ -2258,11 +2283,13 @@ interface IEmailProvider {
2258
2283
  * So: decide in your `onNewSession` hook whether the session is worth alerting about, and
2259
2284
  * call this when it is.
2260
2285
  *
2286
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2287
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2261
2288
  * @param email - Recipient's email address.
2262
2289
  * @param sessionInfo - Device, IP, and session identifier details.
2263
2290
  * @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
2264
2291
  */
2265
- sendNewSessionAlert?(email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
2292
+ sendNewSessionAlert?(tenantId: string, email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
2266
2293
  /**
2267
2294
  * Sends a tenant invitation email to a prospective member.
2268
2295
  *
@@ -2270,11 +2297,13 @@ interface IEmailProvider {
2270
2297
  * The email should prominently display the inviter's name, the tenant name,
2271
2298
  * the accept URL, and the expiry date/time.
2272
2299
  *
2300
+ * @param tenantId - The tenant the account belongs to, so a multi-tenant provider can
2301
+ * attribute and route the message. Resolved by the auth flow; a single-tenant provider ignores it.
2273
2302
  * @param email - Recipient's email address (the invitee).
2274
2303
  * @param inviteData - Invitation metadata required to render the email.
2275
2304
  * @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
2276
2305
  */
2277
- sendInvitation(email: string, inviteData: InviteData, locale?: string): Promise<void>;
2306
+ sendInvitation(tenantId: string, email: string, inviteData: InviteData, locale?: string): Promise<void>;
2278
2307
  }
2279
2308
 
2280
2309
  /**
@@ -3387,19 +3416,211 @@ interface OAuthMfaChallengeResult {
3387
3416
  declare class NoOpEmailProvider implements IEmailProvider {
3388
3417
  private readonly logger;
3389
3418
  /** @inheritdoc */
3390
- sendPasswordResetToken(email: string, _token: string, _locale?: string): Promise<void>;
3419
+ sendPasswordResetToken(_tenantId: string, email: string, _token: string, _locale?: string): Promise<void>;
3391
3420
  /** @inheritdoc */
3392
- sendPasswordResetOtp(email: string, _otp: string, _locale?: string): Promise<void>;
3421
+ sendPasswordResetOtp(_tenantId: string, email: string, _otp: string, _locale?: string): Promise<void>;
3393
3422
  /** @inheritdoc */
3394
- sendEmailVerificationOtp(email: string, _otp: string, _locale?: string): Promise<void>;
3423
+ sendEmailVerificationOtp(_tenantId: string, email: string, _otp: string, _locale?: string): Promise<void>;
3395
3424
  /** @inheritdoc */
3396
- sendMfaEnabledNotification(email: string, _locale?: string): Promise<void>;
3425
+ sendMfaEnabledNotification(_tenantId: string, email: string, _locale?: string): Promise<void>;
3397
3426
  /** @inheritdoc */
3398
- sendMfaDisabledNotification(email: string, _locale?: string): Promise<void>;
3427
+ sendMfaDisabledNotification(_tenantId: string, email: string, _locale?: string): Promise<void>;
3399
3428
  /** @inheritdoc */
3400
- sendNewSessionAlert(email: string, _sessionInfo: SessionInfo$1, _locale?: string): Promise<void>;
3429
+ sendNewSessionAlert(_tenantId: string, email: string, _sessionInfo: SessionInfo$1, _locale?: string): Promise<void>;
3401
3430
  /** @inheritdoc */
3402
- sendInvitation(email: string, _inviteData: InviteData, _locale?: string): Promise<void>;
3431
+ sendInvitation(_tenantId: string, email: string, _inviteData: InviteData, _locale?: string): Promise<void>;
3432
+ }
3433
+
3434
+ /**
3435
+ * The delivery channel {@link DefaultAuthEmailProvider} sends through.
3436
+ *
3437
+ * Narrow by design: it names only the one call the provider makes, so the provider couples to no
3438
+ * concrete mailer. `@bymax-one/nest-notification`'s `EmailService.send` satisfies it structurally
3439
+ * — its input carries these fields and more, all the extras optional — and so does any adapter
3440
+ * exposing the same shape.
3441
+ */
3442
+ interface AuthEmailSink {
3443
+ /**
3444
+ * Delivers one rendered message.
3445
+ *
3446
+ * @param input - Tenant, recipient, and the rendered subject and bodies.
3447
+ * @returns Anything; the provider ignores the result and never surfaces a rejection.
3448
+ */
3449
+ send(input: {
3450
+ /** Tenant the message is attributed to, for the channel's audit log and routing. */
3451
+ tenantId: string;
3452
+ /** Recipient address. */
3453
+ to: string;
3454
+ /** Subject line. */
3455
+ subject: string;
3456
+ /** HTML body. */
3457
+ html: string;
3458
+ /** Plain-text body. */
3459
+ text: string;
3460
+ }): Promise<unknown>;
3461
+ }
3462
+ /** One rendered message, before the tenant and recipient are attached to it. */
3463
+ interface AuthEmailMessage {
3464
+ /** Subject line. Plain text — never rendered as HTML, so it needs no escaping. */
3465
+ readonly subject: string;
3466
+ /** Body as plain text. Rendered to minimal, escaped HTML by the provider when `html` is absent. */
3467
+ readonly text: string;
3468
+ /**
3469
+ * Body as HTML, used verbatim when present. The provider does not escape it — an override that
3470
+ * sets this owns its own escaping, which is the point: it is the seam for a product's real
3471
+ * `<a>` links, layout and branding, none of which the escaped-text default can carry. Leave it
3472
+ * unset to have the provider render {@link text} into safe, escaped paragraphs.
3473
+ */
3474
+ readonly html?: string | undefined;
3475
+ }
3476
+ /**
3477
+ * The copy for every message the port can send, as pure renderers keyed by event.
3478
+ *
3479
+ * Each returns an {@link AuthEmailMessage}; the provider attaches the tenant and recipient and
3480
+ * handles escaping and delivery. Override any subset through
3481
+ * {@link DefaultAuthEmailProviderOptions.messages} — an entry left unset keeps the secure default.
3482
+ */
3483
+ interface AuthEmailCatalogue {
3484
+ /** Password-reset link carrying a signed token. */
3485
+ passwordResetToken(input: {
3486
+ token: string;
3487
+ locale?: string | undefined;
3488
+ }): AuthEmailMessage;
3489
+ /** One-time code for the password-reset flow. */
3490
+ passwordResetOtp(input: {
3491
+ otp: string;
3492
+ locale?: string | undefined;
3493
+ }): AuthEmailMessage;
3494
+ /** One-time code that activates a newly registered account. */
3495
+ emailVerificationOtp(input: {
3496
+ otp: string;
3497
+ locale?: string | undefined;
3498
+ }): AuthEmailMessage;
3499
+ /** Notice that the account password changed (NIST SP 800-63B §4.6). */
3500
+ passwordChanged(input: {
3501
+ locale?: string | undefined;
3502
+ }): AuthEmailMessage;
3503
+ /** Code confirming ownership of an address the user is moving to. */
3504
+ emailChangeVerification(input: {
3505
+ token: string;
3506
+ locale?: string | undefined;
3507
+ }): AuthEmailMessage;
3508
+ /** Notice to the previous address that the account's email moved. */
3509
+ emailChanged(input: {
3510
+ oldEmail: string;
3511
+ newEmail: string;
3512
+ locale?: string | undefined;
3513
+ }): AuthEmailMessage;
3514
+ /** Notice that a second factor was added. */
3515
+ mfaEnabled(input: {
3516
+ locale?: string | undefined;
3517
+ }): AuthEmailMessage;
3518
+ /** Notice that a second factor was removed. */
3519
+ mfaDisabled(input: {
3520
+ locale?: string | undefined;
3521
+ }): AuthEmailMessage;
3522
+ /** Security alert about a newly established session. */
3523
+ newSessionAlert(input: {
3524
+ sessionInfo: SessionInfo$1;
3525
+ locale?: string | undefined;
3526
+ }): AuthEmailMessage;
3527
+ /** Invitation to join a tenant. */
3528
+ invitation(input: {
3529
+ invite: InviteData;
3530
+ locale?: string | undefined;
3531
+ }): AuthEmailMessage;
3532
+ }
3533
+ /** How the provider reacts to a delivery failure. */
3534
+ type DeliveryErrorPolicy = 'swallow' | 'rethrow';
3535
+ /** Options for {@link DefaultAuthEmailProvider}. */
3536
+ interface DefaultAuthEmailProviderOptions {
3537
+ /**
3538
+ * Per-event copy overrides. Any renderer set here replaces the default for that message; every
3539
+ * unset event keeps its secure default. The escaping and delivery-error policy apply to
3540
+ * overrides too.
3541
+ */
3542
+ readonly messages?: Partial<AuthEmailCatalogue>;
3543
+ /**
3544
+ * What to do when the channel rejects a send. `'swallow'` (the default) logs the failure and
3545
+ * resolves, so a down channel never turns a notification into a failed user request. `'rethrow'`
3546
+ * logs and then re-throws, restoring the throw the two flows that react to one expect —
3547
+ * `PasswordResetService` deletes an undelivered reset token early, and `EmailChangeService` lets
3548
+ * a failed verification send surface rather than reporting "sent". The trade is symmetric: under
3549
+ * `'rethrow'` a channel outage also fails MFA, invitation and the other awaited sends. Pick the
3550
+ * failure mode the deployment's channel reliability warrants.
3551
+ */
3552
+ readonly onDeliveryError?: DeliveryErrorPolicy;
3553
+ }
3554
+ /**
3555
+ * Default {@link IEmailProvider} over a {@link AuthEmailSink} delivery channel.
3556
+ *
3557
+ * Wire it by binding the auth email-provider token to a factory that hands it the channel:
3558
+ *
3559
+ * ```typescript
3560
+ * {
3561
+ * provide: BYMAX_AUTH_EMAIL_PROVIDER,
3562
+ * useFactory: (email: EmailService) => new DefaultAuthEmailProvider(email),
3563
+ * inject: [EmailService]
3564
+ * }
3565
+ * ```
3566
+ *
3567
+ * No method throws on a delivery failure — the library awaits most of these calls (enabling MFA,
3568
+ * sending an invitation, confirming an address change), so a channel that is down would turn each
3569
+ * into a failed request over a message that is a notification rather than the operation itself.
3570
+ * The failure is logged and the flow continues.
3571
+ *
3572
+ * That choice has a cost worth stating, because two flows react to a *throw* from the port. A
3573
+ * reset-token send that rejects lets `PasswordResetService` delete the stored token early rather
3574
+ * than leave it to its TTL; and `EmailChangeService` awaits the verification send before it records
3575
+ * "verification sent". Under the default both degrade gracefully rather than break: the reset token
3576
+ * still expires at its TTL and was never delivered to anyone, and the change still requires the
3577
+ * verification the recipient never got, so it cannot complete. A deployment that wants the throw
3578
+ * back on those flows constructs the provider with `{ onDeliveryError: 'rethrow' }`, accepting that
3579
+ * an outage then also fails the awaited sends (MFA, invitation). The default optimizes for the
3580
+ * common case: a transient channel outage must not fail the user's action.
3581
+ */
3582
+ declare class DefaultAuthEmailProvider implements IEmailProvider {
3583
+ private readonly sink;
3584
+ /** Records a delivery this provider swallowed, so a silent channel is still visible somewhere. */
3585
+ private readonly logger;
3586
+ /** The copy in effect: the defaults, with any provided overrides layered on top. */
3587
+ private readonly messages;
3588
+ /** Whether a rejected send is re-thrown after logging; `false` (swallow) unless asked otherwise. */
3589
+ private readonly rethrowOnError;
3590
+ /**
3591
+ * @param sink - The delivery channel to send through.
3592
+ * @param options - Optional copy overrides and delivery-error policy.
3593
+ */
3594
+ constructor(sink: AuthEmailSink, options?: DefaultAuthEmailProviderOptions);
3595
+ /** @inheritdoc */
3596
+ sendPasswordResetToken(tenantId: string, email: string, token: string, locale?: string): Promise<void>;
3597
+ /** @inheritdoc */
3598
+ sendPasswordResetOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
3599
+ /** @inheritdoc */
3600
+ sendEmailVerificationOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
3601
+ /** @inheritdoc */
3602
+ sendPasswordChangedNotification(tenantId: string, email: string, locale?: string): Promise<void>;
3603
+ /** @inheritdoc */
3604
+ sendEmailChangeVerification(tenantId: string, newEmail: string, token: string, locale?: string): Promise<void>;
3605
+ /** @inheritdoc */
3606
+ sendEmailChangedNotification(tenantId: string, oldEmail: string, newEmail: string, locale?: string): Promise<void>;
3607
+ /** @inheritdoc */
3608
+ sendMfaEnabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
3609
+ /** @inheritdoc */
3610
+ sendMfaDisabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
3611
+ /** @inheritdoc */
3612
+ sendNewSessionAlert(tenantId: string, email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
3613
+ /** @inheritdoc */
3614
+ sendInvitation(tenantId: string, email: string, inviteData: InviteData, locale?: string): Promise<void>;
3615
+ /**
3616
+ * Renders the body to HTML (unless the message already carries its own), hands the message to the
3617
+ * channel, and swallows any delivery error.
3618
+ *
3619
+ * @param tenantId - Tenant the message is attributed to.
3620
+ * @param to - Recipient address.
3621
+ * @param message - The rendered subject and body, and optionally its own HTML.
3622
+ */
3623
+ private deliver;
3403
3624
  }
3404
3625
 
3405
3626
  /**
@@ -4087,6 +4308,55 @@ declare class AuthRedisService {
4087
4308
  redeemWsTicket(ticket: string): Promise<WsTicketSnapshot | null>;
4088
4309
  }
4089
4310
 
4311
+ /**
4312
+ * The claims a revocation check reads off a verified access token. A caller passes the payload it
4313
+ * already verified; nothing here re-checks the signature.
4314
+ */
4315
+ interface RevocableTokenPayload {
4316
+ /** The token's unique id, the key of the per-token blacklist (`rv:{jti}`). */
4317
+ readonly jti: string;
4318
+ /** The subject the token authenticates, the key of the per-user token epoch. */
4319
+ readonly sub: string;
4320
+ /** The epoch the token was stamped with, if any; an absent or malformed value reads as 0. */
4321
+ readonly epoch?: unknown;
4322
+ }
4323
+ /**
4324
+ * Answers whether an already-verified access token has been revoked, across both channels the auth
4325
+ * module writes to.
4326
+ *
4327
+ * There are two, and a check that consults only the first is not a revocation check. A single
4328
+ * logout writes `rv:{jti}` with the token's remaining TTL — the per-token blacklist. A password
4329
+ * reset, an MFA reset or an administrative revoke-all advances the user's token epoch — the bulk
4330
+ * channel, which invalidates every access token stamped below it in one write. Both channels this
4331
+ * service reads gate access tokens only; a refresh token is opaque and carries no epoch, so a bulk
4332
+ * flow revokes it through a separate session invalidation, not through either read here.
4333
+ *
4334
+ * `JwtAuthGuard`, `WsJwtGuard` and `JwtPlatformGuard` all consult both, and did so through three
4335
+ * separate copies of the same two Redis reads. This is that logic in one place — the guards
4336
+ * delegate to it, and it is exported so a consumer bridging `@bymax-one/nest-auth` to a realtime
4337
+ * transport can consult the same two channels rather than verifying a token's signature and
4338
+ * granting a stream that outlives every revocation. Without it, a socket that logs out keeps its
4339
+ * stream until the access token expires, while its HTTP requests are refused at once.
4340
+ *
4341
+ * @layer Service
4342
+ */
4343
+ declare class AuthRevocationService {
4344
+ private readonly redis;
4345
+ /**
4346
+ * @param redis - The auth module's Redis service, holding both revocation channels.
4347
+ */
4348
+ constructor(redis: AuthRedisService);
4349
+ /**
4350
+ * Whether a verified access token has been revoked.
4351
+ *
4352
+ * @param payload - The verified token's `jti`, `sub` and stamped `epoch`.
4353
+ * @param kind - Which plane the token belongs to; selects the epoch namespace, defaulting to the
4354
+ * dashboard plane an ordinary user token uses. The per-token blacklist is shared across planes.
4355
+ * @returns `true` when the token is on the blacklist or predates the user's current epoch.
4356
+ */
4357
+ isAccessTokenRevoked(payload: RevocableTokenPayload, kind?: 'dashboard' | 'platform'): Promise<boolean>;
4358
+ }
4359
+
4090
4360
  /**
4091
4361
  * Auth response for cookie mode — tokens delivered via HttpOnly cookies.
4092
4362
  * The response body contains only the user object.
@@ -4295,10 +4565,10 @@ declare class TokenDeliveryService {
4295
4565
  declare class JwtAuthGuard implements CanActivate {
4296
4566
  protected readonly jwtService: JwtService;
4297
4567
  protected readonly tokenDelivery: TokenDeliveryService;
4298
- protected readonly redis: AuthRedisService;
4568
+ protected readonly revocation: AuthRevocationService;
4299
4569
  protected readonly reflector: Reflector;
4300
4570
  protected readonly options: ResolvedOptions;
4301
- constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService, redis: AuthRedisService, reflector: Reflector, options: ResolvedOptions);
4571
+ constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService, revocation: AuthRevocationService, reflector: Reflector, options: ResolvedOptions);
4302
4572
  canActivate(context: ExecutionContext): Promise<boolean>;
4303
4573
  }
4304
4574
 
@@ -4333,10 +4603,10 @@ declare class JwtAuthGuard implements CanActivate {
4333
4603
  declare class JwtPlatformGuard implements CanActivate {
4334
4604
  private readonly jwtService;
4335
4605
  private readonly tokenDelivery;
4336
- private readonly redis;
4606
+ private readonly revocation;
4337
4607
  private readonly reflector;
4338
4608
  private readonly options;
4339
- constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService, redis: AuthRedisService, reflector: Reflector, options: ResolvedOptions);
4609
+ constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService, revocation: AuthRevocationService, reflector: Reflector, options: ResolvedOptions);
4340
4610
  canActivate(context: ExecutionContext): Promise<boolean>;
4341
4611
  }
4342
4612
 
@@ -4770,10 +5040,10 @@ declare class WsTicketService {
4770
5040
  */
4771
5041
  declare class WsJwtGuard implements CanActivate, OnModuleInit {
4772
5042
  private readonly jwtService;
4773
- private readonly redis;
5043
+ private readonly revocation;
4774
5044
  private readonly wsTickets;
4775
5045
  private readonly options;
4776
- constructor(jwtService: JwtService, redis: AuthRedisService, wsTickets: WsTicketService, options: ResolvedOptions);
5046
+ constructor(jwtService: JwtService, revocation: AuthRevocationService, wsTickets: WsTicketService, options: ResolvedOptions);
4777
5047
  /**
4778
5048
  * Verifies that `@nestjs/websockets` is installed and throws a descriptive
4779
5049
  * error at application startup if the package is absent.
@@ -5130,7 +5400,7 @@ declare class ForgotPasswordDto {
5130
5400
  /**
5131
5401
  * Tenant identifier that scopes the reset request to a specific organization.
5132
5402
  */
5133
- tenantId: string;
5403
+ tenantId?: string;
5134
5404
  }
5135
5405
 
5136
5406
  /**
@@ -5174,7 +5444,7 @@ declare class LoginDto {
5174
5444
  * Bounded to 128 characters — tenant IDs are part of HMAC pre-images and
5175
5445
  * Redis keys, so an unbounded string is rejected at the boundary.
5176
5446
  */
5177
- tenantId: string;
5447
+ tenantId?: string;
5178
5448
  }
5179
5449
 
5180
5450
  /**
@@ -5374,7 +5644,7 @@ declare class RegisterDto {
5374
5644
  * Tenant identifier that scopes the new user to a specific organization.
5375
5645
  * Bounded to 128 characters — part of HMAC pre-images and Redis keys.
5376
5646
  */
5377
- tenantId: string;
5647
+ tenantId?: string;
5378
5648
  }
5379
5649
 
5380
5650
  /**
@@ -5396,7 +5666,7 @@ declare class ResendOtpDto {
5396
5666
  /**
5397
5667
  * Tenant identifier that scopes the resend request to a specific organization.
5398
5668
  */
5399
- tenantId: string;
5669
+ tenantId?: string;
5400
5670
  }
5401
5671
 
5402
5672
  /**
@@ -5417,7 +5687,7 @@ declare class ResendVerificationDto {
5417
5687
  /**
5418
5688
  * Tenant identifier that scopes the resend request to a specific organization.
5419
5689
  */
5420
- tenantId: string;
5690
+ tenantId?: string;
5421
5691
  }
5422
5692
 
5423
5693
  /**
@@ -5516,7 +5786,7 @@ declare class ResetPasswordDto {
5516
5786
  * Validated against the stored tenant in the verifiedToken flow to prevent
5517
5787
  * cross-tenant password reset attacks.
5518
5788
  */
5519
- tenantId: string;
5789
+ tenantId?: string;
5520
5790
  }
5521
5791
 
5522
5792
  /**
@@ -5542,7 +5812,7 @@ declare class VerifyEmailDto {
5542
5812
  /**
5543
5813
  * Tenant identifier that scopes the verification to a specific organization.
5544
5814
  */
5545
- tenantId: string;
5815
+ tenantId?: string;
5546
5816
  }
5547
5817
 
5548
5818
  /**
@@ -5570,7 +5840,7 @@ declare class VerifyOtpDto {
5570
5840
  /**
5571
5841
  * Tenant identifier that scopes the verification to a specific organization.
5572
5842
  */
5573
- tenantId: string;
5843
+ tenantId?: string;
5574
5844
  }
5575
5845
 
5576
5846
  /**
@@ -6607,7 +6877,7 @@ declare class AuthService {
6607
6877
  email: string;
6608
6878
  password: string;
6609
6879
  name: string;
6610
- tenantId: string;
6880
+ tenantId?: string;
6611
6881
  }, req: Request): Promise<AuthResult>;
6612
6882
  /**
6613
6883
  * Authenticates a dashboard user with email and password.
@@ -6624,7 +6894,7 @@ declare class AuthService {
6624
6894
  login(dto: {
6625
6895
  email: string;
6626
6896
  password: string;
6627
- tenantId: string;
6897
+ tenantId?: string;
6628
6898
  }, req: Request): Promise<AuthResult | MfaChallengeResult>;
6629
6899
  /**
6630
6900
  * Logs out a dashboard user by revoking the access token and deleting the refresh session.
@@ -6751,7 +7021,7 @@ declare class AuthService {
6751
7021
  * or the user does not exist (response shape is identical to prevent
6752
7022
  * account enumeration via this endpoint).
6753
7023
  */
6754
- verifyEmail(tenantId: string, email: string, otp: string, req: Request): Promise<void>;
7024
+ verifyEmail(tenantId: string | undefined, email: string, otp: string, req: Request): Promise<void>;
6755
7025
  /**
6756
7026
  * Resends an email verification OTP with an atomic cooldown.
6757
7027
  *
@@ -6762,7 +7032,7 @@ declare class AuthService {
6762
7032
  * @param tenantId - Tenant scope.
6763
7033
  * @param email - The email address to re-send to (not validated — always succeeds).
6764
7034
  */
6765
- resendVerificationEmail(tenantId: string, email: string, req: Request): Promise<void>;
7035
+ resendVerificationEmail(tenantId: string | undefined, email: string, req: Request): Promise<void>;
6766
7036
  /**
6767
7037
  * Clears an account's brute-force lockout so the next attempt is judged on its merits.
6768
7038
  *
@@ -8127,7 +8397,7 @@ declare class OAuthService {
8127
8397
  * @param res - Express response in passthrough mode (used for the 302 redirect).
8128
8398
  * @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
8129
8399
  */
8130
- initiateOAuth(provider: string, tenantId: string, req: Request, res: Response): Promise<void>;
8400
+ initiateOAuth(provider: string, tenantId: string | undefined, req: Request, res: Response): Promise<void>;
8131
8401
  /**
8132
8402
  * Processes the OAuth provider callback and issues auth tokens.
8133
8403
  *
@@ -8320,4 +8590,4 @@ declare function AuthRateLimit(config: {
8320
8590
  default: AuthRateLimitWindow;
8321
8591
  }): MethodDecorator;
8322
8592
 
8323
- export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, AUTH_THROTTLE_CONFIGS, AcceptInvitationDto, type SessionInfo as ActiveSessionInfo, AllowAllBreachChecker, type AuthErrorCode, AuthException, AuthExceptionFilter, type AuthFieldError, type AuthModuleAsyncOptions, type AuthPlatformUser, AuthRateLimit, AuthRateLimitGuard, type AuthRateLimitWindow, type AuthResult, 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, 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, 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 };
8593
+ export { AUTH_ERROR_CODES, AUTH_ERROR_MESSAGES, 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 };