@bymax-one/nest-auth 1.3.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.
- package/CHANGELOG.md +82 -1
- package/README.md +38 -9
- package/dist/server/index.cjs +1243 -984
- package/dist/server/index.d.cts +285 -24
- package/dist/server/index.d.ts +285 -24
- package/dist/server/index.mjs +1243 -985
- package/package.json +1 -1
package/dist/server/index.d.cts
CHANGED
|
@@ -2144,11 +2144,13 @@ interface IEmailProvider {
|
|
|
2144
2144
|
* The email should contain a time-limited URL with the token embedded as a
|
|
2145
2145
|
* query parameter (e.g. `/reset-password?token=...`).
|
|
2146
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.
|
|
2147
2149
|
* @param email - Recipient's email address.
|
|
2148
2150
|
* @param token - Signed, opaque reset token. Never log or expose this value.
|
|
2149
2151
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2150
2152
|
*/
|
|
2151
|
-
sendPasswordResetToken(email: string, token: string, locale?: string): Promise<void>;
|
|
2153
|
+
sendPasswordResetToken(tenantId: string, email: string, token: string, locale?: string): Promise<void>;
|
|
2152
2154
|
/**
|
|
2153
2155
|
* Sends a one-time password (OTP) code for password reset to the user.
|
|
2154
2156
|
*
|
|
@@ -2156,11 +2158,13 @@ interface IEmailProvider {
|
|
|
2156
2158
|
* The email should display the numeric/alphanumeric code clearly and state
|
|
2157
2159
|
* its expiry time.
|
|
2158
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.
|
|
2159
2163
|
* @param email - Recipient's email address.
|
|
2160
2164
|
* @param otp - Short-lived OTP code. Never log or expose this value.
|
|
2161
2165
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2162
2166
|
*/
|
|
2163
|
-
sendPasswordResetOtp(email: string, otp: string, locale?: string): Promise<void>;
|
|
2167
|
+
sendPasswordResetOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
|
|
2164
2168
|
/**
|
|
2165
2169
|
* Sends an OTP code to verify the user's email address during registration or
|
|
2166
2170
|
* email-change flows.
|
|
@@ -2168,11 +2172,13 @@ interface IEmailProvider {
|
|
|
2168
2172
|
* Called immediately after account creation (when email verification is enabled)
|
|
2169
2173
|
* or when the user requests a new verification code.
|
|
2170
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.
|
|
2171
2177
|
* @param email - Recipient's email address to be verified.
|
|
2172
2178
|
* @param otp - Short-lived OTP code for verification. Never log or expose this value.
|
|
2173
2179
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2174
2180
|
*/
|
|
2175
|
-
sendEmailVerificationOtp(email: string, otp: string, locale?: string): Promise<void>;
|
|
2181
|
+
sendEmailVerificationOtp(tenantId: string, email: string, otp: string, locale?: string): Promise<void>;
|
|
2176
2182
|
/**
|
|
2177
2183
|
* Notifies the user that the password on their account has changed.
|
|
2178
2184
|
*
|
|
@@ -2188,10 +2194,12 @@ interface IEmailProvider {
|
|
|
2188
2194
|
* it when present and logs at debug when it is not, rather than failing a password change
|
|
2189
2195
|
* over a missing notification.
|
|
2190
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.
|
|
2191
2199
|
* @param email - Recipient's email address.
|
|
2192
2200
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2193
2201
|
*/
|
|
2194
|
-
sendPasswordChangedNotification?(email: string, locale?: string): Promise<void>;
|
|
2202
|
+
sendPasswordChangedNotification?(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
2195
2203
|
/**
|
|
2196
2204
|
* Sends the address-change verification link to the **new** address.
|
|
2197
2205
|
*
|
|
@@ -2202,11 +2210,13 @@ interface IEmailProvider {
|
|
|
2202
2210
|
* Optional on the interface so an existing consumer keeps compiling, but the flow refuses
|
|
2203
2211
|
* to mint a token when it is absent rather than writing one nobody will ever receive.
|
|
2204
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.
|
|
2205
2215
|
* @param newEmail - The address being moved to.
|
|
2206
2216
|
* @param token - The raw single-use token. The provider builds the confirmation URL.
|
|
2207
2217
|
* @param locale - Optional locale for the template.
|
|
2208
2218
|
*/
|
|
2209
|
-
sendEmailChangeVerification?(newEmail: string, token: string, locale?: string): Promise<void>;
|
|
2219
|
+
sendEmailChangeVerification?(tenantId: string, newEmail: string, token: string, locale?: string): Promise<void>;
|
|
2210
2220
|
/**
|
|
2211
2221
|
* Notifies the **old** address that the account's address has changed.
|
|
2212
2222
|
*
|
|
@@ -2218,11 +2228,13 @@ interface IEmailProvider {
|
|
|
2218
2228
|
* Fire-and-forget — a delivery failure does not roll back a change the user asked for and
|
|
2219
2229
|
* has already proven.
|
|
2220
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.
|
|
2221
2233
|
* @param oldEmail - The address the account is leaving.
|
|
2222
2234
|
* @param newEmail - The address it moved to, so the notice can say what happened.
|
|
2223
2235
|
* @param locale - Optional locale for the template.
|
|
2224
2236
|
*/
|
|
2225
|
-
sendEmailChangedNotification?(oldEmail: string, newEmail: string, locale?: string): Promise<void>;
|
|
2237
|
+
sendEmailChangedNotification?(tenantId: string, oldEmail: string, newEmail: string, locale?: string): Promise<void>;
|
|
2226
2238
|
/**
|
|
2227
2239
|
* Notifies the user that multi-factor authentication (MFA) has been enabled on
|
|
2228
2240
|
* their account.
|
|
@@ -2231,10 +2243,12 @@ interface IEmailProvider {
|
|
|
2231
2243
|
* security alert — if the user did not initiate this change, they should be
|
|
2232
2244
|
* directed to contact support or reset their credentials.
|
|
2233
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.
|
|
2234
2248
|
* @param email - Recipient's email address.
|
|
2235
2249
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2236
2250
|
*/
|
|
2237
|
-
sendMfaEnabledNotification(email: string, locale?: string): Promise<void>;
|
|
2251
|
+
sendMfaEnabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
2238
2252
|
/**
|
|
2239
2253
|
* Notifies the user that multi-factor authentication (MFA) has been disabled on
|
|
2240
2254
|
* their account.
|
|
@@ -2243,10 +2257,12 @@ interface IEmailProvider {
|
|
|
2243
2257
|
* alert — if the user did not initiate this change, they should be directed to
|
|
2244
2258
|
* contact support or reset their credentials immediately.
|
|
2245
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.
|
|
2246
2262
|
* @param email - Recipient's email address.
|
|
2247
2263
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2248
2264
|
*/
|
|
2249
|
-
sendMfaDisabledNotification(email: string, locale?: string): Promise<void>;
|
|
2265
|
+
sendMfaDisabledNotification(tenantId: string, email: string, locale?: string): Promise<void>;
|
|
2250
2266
|
/**
|
|
2251
2267
|
* Sends a security alert about a newly established session.
|
|
2252
2268
|
*
|
|
@@ -2267,11 +2283,13 @@ interface IEmailProvider {
|
|
|
2267
2283
|
* So: decide in your `onNewSession` hook whether the session is worth alerting about, and
|
|
2268
2284
|
* call this when it is.
|
|
2269
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.
|
|
2270
2288
|
* @param email - Recipient's email address.
|
|
2271
2289
|
* @param sessionInfo - Device, IP, and session identifier details.
|
|
2272
2290
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2273
2291
|
*/
|
|
2274
|
-
sendNewSessionAlert?(email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
2292
|
+
sendNewSessionAlert?(tenantId: string, email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
2275
2293
|
/**
|
|
2276
2294
|
* Sends a tenant invitation email to a prospective member.
|
|
2277
2295
|
*
|
|
@@ -2279,11 +2297,13 @@ interface IEmailProvider {
|
|
|
2279
2297
|
* The email should prominently display the inviter's name, the tenant name,
|
|
2280
2298
|
* the accept URL, and the expiry date/time.
|
|
2281
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.
|
|
2282
2302
|
* @param email - Recipient's email address (the invitee).
|
|
2283
2303
|
* @param inviteData - Invitation metadata required to render the email.
|
|
2284
2304
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2285
2305
|
*/
|
|
2286
|
-
sendInvitation(email: string, inviteData: InviteData, locale?: string): Promise<void>;
|
|
2306
|
+
sendInvitation(tenantId: string, email: string, inviteData: InviteData, locale?: string): Promise<void>;
|
|
2287
2307
|
}
|
|
2288
2308
|
|
|
2289
2309
|
/**
|
|
@@ -3396,19 +3416,211 @@ interface OAuthMfaChallengeResult {
|
|
|
3396
3416
|
declare class NoOpEmailProvider implements IEmailProvider {
|
|
3397
3417
|
private readonly logger;
|
|
3398
3418
|
/** @inheritdoc */
|
|
3399
|
-
sendPasswordResetToken(email: string, _token: string, _locale?: string): Promise<void>;
|
|
3419
|
+
sendPasswordResetToken(_tenantId: string, email: string, _token: string, _locale?: string): Promise<void>;
|
|
3400
3420
|
/** @inheritdoc */
|
|
3401
|
-
sendPasswordResetOtp(email: string, _otp: string, _locale?: string): Promise<void>;
|
|
3421
|
+
sendPasswordResetOtp(_tenantId: string, email: string, _otp: string, _locale?: string): Promise<void>;
|
|
3402
3422
|
/** @inheritdoc */
|
|
3403
|
-
sendEmailVerificationOtp(email: string, _otp: string, _locale?: string): Promise<void>;
|
|
3423
|
+
sendEmailVerificationOtp(_tenantId: string, email: string, _otp: string, _locale?: string): Promise<void>;
|
|
3404
3424
|
/** @inheritdoc */
|
|
3405
|
-
sendMfaEnabledNotification(email: string, _locale?: string): Promise<void>;
|
|
3425
|
+
sendMfaEnabledNotification(_tenantId: string, email: string, _locale?: string): Promise<void>;
|
|
3406
3426
|
/** @inheritdoc */
|
|
3407
|
-
sendMfaDisabledNotification(email: string, _locale?: string): Promise<void>;
|
|
3427
|
+
sendMfaDisabledNotification(_tenantId: string, email: string, _locale?: string): Promise<void>;
|
|
3408
3428
|
/** @inheritdoc */
|
|
3409
|
-
sendNewSessionAlert(email: string, _sessionInfo: SessionInfo$1, _locale?: string): Promise<void>;
|
|
3429
|
+
sendNewSessionAlert(_tenantId: string, email: string, _sessionInfo: SessionInfo$1, _locale?: string): Promise<void>;
|
|
3410
3430
|
/** @inheritdoc */
|
|
3411
|
-
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;
|
|
3412
3624
|
}
|
|
3413
3625
|
|
|
3414
3626
|
/**
|
|
@@ -4096,6 +4308,55 @@ declare class AuthRedisService {
|
|
|
4096
4308
|
redeemWsTicket(ticket: string): Promise<WsTicketSnapshot | null>;
|
|
4097
4309
|
}
|
|
4098
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
|
+
|
|
4099
4360
|
/**
|
|
4100
4361
|
* Auth response for cookie mode — tokens delivered via HttpOnly cookies.
|
|
4101
4362
|
* The response body contains only the user object.
|
|
@@ -4304,10 +4565,10 @@ declare class TokenDeliveryService {
|
|
|
4304
4565
|
declare class JwtAuthGuard implements CanActivate {
|
|
4305
4566
|
protected readonly jwtService: JwtService;
|
|
4306
4567
|
protected readonly tokenDelivery: TokenDeliveryService;
|
|
4307
|
-
protected readonly
|
|
4568
|
+
protected readonly revocation: AuthRevocationService;
|
|
4308
4569
|
protected readonly reflector: Reflector;
|
|
4309
4570
|
protected readonly options: ResolvedOptions;
|
|
4310
|
-
constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService,
|
|
4571
|
+
constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService, revocation: AuthRevocationService, reflector: Reflector, options: ResolvedOptions);
|
|
4311
4572
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
4312
4573
|
}
|
|
4313
4574
|
|
|
@@ -4342,10 +4603,10 @@ declare class JwtAuthGuard implements CanActivate {
|
|
|
4342
4603
|
declare class JwtPlatformGuard implements CanActivate {
|
|
4343
4604
|
private readonly jwtService;
|
|
4344
4605
|
private readonly tokenDelivery;
|
|
4345
|
-
private readonly
|
|
4606
|
+
private readonly revocation;
|
|
4346
4607
|
private readonly reflector;
|
|
4347
4608
|
private readonly options;
|
|
4348
|
-
constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService,
|
|
4609
|
+
constructor(jwtService: JwtService, tokenDelivery: TokenDeliveryService, revocation: AuthRevocationService, reflector: Reflector, options: ResolvedOptions);
|
|
4349
4610
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
4350
4611
|
}
|
|
4351
4612
|
|
|
@@ -4779,10 +5040,10 @@ declare class WsTicketService {
|
|
|
4779
5040
|
*/
|
|
4780
5041
|
declare class WsJwtGuard implements CanActivate, OnModuleInit {
|
|
4781
5042
|
private readonly jwtService;
|
|
4782
|
-
private readonly
|
|
5043
|
+
private readonly revocation;
|
|
4783
5044
|
private readonly wsTickets;
|
|
4784
5045
|
private readonly options;
|
|
4785
|
-
constructor(jwtService: JwtService,
|
|
5046
|
+
constructor(jwtService: JwtService, revocation: AuthRevocationService, wsTickets: WsTicketService, options: ResolvedOptions);
|
|
4786
5047
|
/**
|
|
4787
5048
|
* Verifies that `@nestjs/websockets` is installed and throws a descriptive
|
|
4788
5049
|
* error at application startup if the package is absent.
|
|
@@ -8329,4 +8590,4 @@ declare function AuthRateLimit(config: {
|
|
|
8329
8590
|
default: AuthRateLimitWindow;
|
|
8330
8591
|
}): MethodDecorator;
|
|
8331
8592
|
|
|
8332
|
-
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 };
|