@bymax-one/nest-auth 1.4.14 → 1.4.15

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 CHANGED
@@ -18,6 +18,40 @@ what moves, and that note is the compatibility contract until strict SemVer begi
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [1.4.15] - 2026-11-01
22
+
23
+ ### Apply to a derived backend
24
+
25
+ - **`POST /password/forgot-password` and `POST /password/resend-otp` now answer `200` with an
26
+ empty JSON object, `{}`, where they answered `200` with no body.** The status and the
27
+ anti-enumeration behaviour are unchanged, and the body is the same for a known and an unknown
28
+ account. The wire contract now pins it. A client that asserted an empty body must accept JSON;
29
+ the bundled client discards the body and is unaffected.
30
+
31
+ ### Fixed
32
+
33
+ - **`POST /password/change` refuses an empty `refreshToken` and accepts a long one.** The field is
34
+ the caller's own refresh token, sent in the body under bearer delivery. It was capped at 512
35
+ characters and an empty string passed validation, so a present-but-empty value was read as "no
36
+ token" and the request silently degraded. It is now held to the wire contract's opaque-token
37
+ bound: 1 to 2048 characters, answered `400 auth.validation` outside it. An absent field is
38
+ unchanged.
39
+ - **`registerAsync` with `imports` and `inject` from a non-global module failed at boot.** The
40
+ options factory was run a second time to configure the internal JWT registration, and that
41
+ registration was given `inject` but not `imports`, so Nest could not resolve the injected
42
+ provider. It worked only
43
+ when the module providing the injected token, typically `ConfigModule`, was global. The internal
44
+ registration now receives the same `imports`.
45
+
46
+ ### Documentation
47
+
48
+ - **The Quick Start now runs as written.** A test executes its repository, email provider,
49
+ module, `main.ts` and controller blocks in a real application. Three gaps it found are closed:
50
+ the module block did not bind the email provider the previous step told the reader to bind, so a
51
+ verification code never reached the reader's mailer; it did not say which of the modules it
52
+ uses are the reader's own; and `tokenDelivery: 'cookie'` needs `cookie-parser` mounted, without
53
+ which a signed-in user is answered `401 auth.token_invalid` on every protected route.
54
+
21
55
  ## [1.4.14] - 2026-11-01
22
56
 
23
57
  ### Apply to a derived backend
@@ -4259,7 +4293,8 @@ ever installable.
4259
4293
  - Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
4260
4294
  - Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
4261
4295
 
4262
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.14...HEAD
4296
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.15...HEAD
4297
+ [1.4.15]: https://github.com/bymaxone/nest-auth/compare/v1.4.14...v1.4.15
4263
4298
  [1.4.14]: https://github.com/bymaxone/nest-auth/compare/v1.4.13...v1.4.14
4264
4299
  [1.4.13]: https://github.com/bymaxone/nest-auth/compare/v1.4.12...v1.4.13
4265
4300
  [1.4.12]: https://github.com/bymaxone/nest-auth/compare/v1.4.11...v1.4.12
package/README.md CHANGED
@@ -143,6 +143,9 @@ yarn add @bymax-one/nest-auth
143
143
  # Server subpath (required)
144
144
  pnpm add @nestjs/common @nestjs/core @nestjs/jwt @nestjs/throttler @nestjs/websockets ioredis class-validator class-transformer reflect-metadata
145
145
 
146
+ # Also needed with `tokenDelivery: 'cookie'` or `'both'` (see step 4): the library reads `req.cookies`
147
+ pnpm add cookie-parser
148
+
146
149
  # React subpath (optional)
147
150
  pnpm add react
148
151
 
@@ -524,9 +527,14 @@ import { Module } from '@nestjs/common'
524
527
  import {
525
528
  BymaxAuthModule,
526
529
  BYMAX_AUTH_USER_REPOSITORY,
527
- BYMAX_AUTH_REDIS_CLIENT
530
+ BYMAX_AUTH_REDIS_CLIENT,
531
+ BYMAX_AUTH_EMAIL_PROVIDER
528
532
  } from '@bymax-one/nest-auth'
529
533
 
534
+ // Yours, not this library's: `ConfigModule` and `ConfigService` come from `@nestjs/config`,
535
+ // `DatabaseModule` is your module exporting the database client the repository uses, and
536
+ // `RedisModule` is your module exporting `RedisService`, whose `client` is an `ioredis` instance.
537
+
530
538
  @Module({
531
539
  imports: [
532
540
  BymaxAuthModule.registerAsync({
@@ -556,6 +564,10 @@ import {
556
564
  provide: BYMAX_AUTH_USER_REPOSITORY,
557
565
  useClass: PrismaUserRepository
558
566
  },
567
+ {
568
+ provide: BYMAX_AUTH_EMAIL_PROVIDER,
569
+ useClass: ResendEmailProvider
570
+ },
559
571
  {
560
572
  provide: BYMAX_AUTH_REDIS_CLIENT,
561
573
  useFactory: (redis: RedisService) => redis.client,
@@ -568,6 +580,22 @@ import {
568
580
  export class AppModule {}
569
581
  ```
570
582
 
583
+ With `tokenDelivery: 'cookie'` (or `'both'`) the library reads the credential from `req.cookies`, and it takes no dependency on a parser, so mount one yourself. Without it a correctly signed-in user is answered `401 auth.token_invalid` on every protected route.
584
+
585
+ ```typescript
586
+ // main.ts
587
+ import { NestFactory } from '@nestjs/core'
588
+ import cookieParser from 'cookie-parser'
589
+ import { AppModule } from './app.module'
590
+
591
+ async function bootstrap() {
592
+ const app = await NestFactory.create(AppModule)
593
+ app.use(cookieParser())
594
+ await app.listen(3000)
595
+ }
596
+ bootstrap()
597
+ ```
598
+
571
599
  ### 5. Protect Routes
572
600
 
573
601
  ```typescript
@@ -11389,6 +11389,9 @@ var ChangePasswordDto = class {
11389
11389
  * `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
11390
11390
  * it — so the suite exercised a request production never sees. Optional, because under cookie
11391
11391
  * delivery the credential arrives in the cookie and no body field exists to declare.
11392
+ *
11393
+ * A present value is held to the contract's opaque-token bound (1 to 2048 characters), so an
11394
+ * empty string is refused instead of being read as "no token".
11392
11395
  */
11393
11396
  refreshToken;
11394
11397
  };
@@ -11407,7 +11410,8 @@ _ts_decorate38([
11407
11410
  _ts_decorate38([
11408
11411
  classValidator.IsOptional(),
11409
11412
  classValidator.IsString(),
11410
- classValidator.MaxLength(512),
11413
+ classValidator.IsNotEmpty(),
11414
+ classValidator.MaxLength(2048),
11411
11415
  _ts_metadata37("design:type", String)
11412
11416
  ], ChangePasswordDto.prototype, "refreshToken", void 0);
11413
11417
  function _ts_decorate39(decorators, target, key, desc) {
@@ -12356,12 +12360,15 @@ var PasswordResetController = class {
12356
12360
  * Initiates a password reset for the given email address.
12357
12361
  *
12358
12362
  * Sends a reset token or OTP to the user's email if the account exists and
12359
- * is eligible. Always returns `200 OK` regardless of outcome (anti-enumeration).
12363
+ * is eligible. Always returns `200 OK` with an empty JSON object regardless of outcome
12364
+ * (anti-enumeration; the body is pinned by the wire contract).
12360
12365
  *
12361
12366
  * @param dto - Validated DTO with `email` and `tenantId`.
12367
+ * @returns An empty object.
12362
12368
  */
12363
12369
  async forgotPassword(dto, req) {
12364
12370
  await this.passwordResetService.initiateReset(dto, req);
12371
+ return {};
12365
12372
  }
12366
12373
  // ---------------------------------------------------------------------------
12367
12374
  // POST /password/reset-password
@@ -12441,12 +12448,15 @@ var PasswordResetController = class {
12441
12448
  * Re-sends the password-reset OTP for the given email address.
12442
12449
  *
12443
12450
  * Subject to a 60-second atomic cooldown per `(tenantId, email)` pair.
12444
- * Always returns `200 OK` regardless of outcome (anti-enumeration).
12451
+ * Always returns `200 OK` with an empty JSON object regardless of outcome (anti-enumeration;
12452
+ * the body is pinned by the wire contract).
12445
12453
  *
12446
12454
  * @param dto - Validated DTO with `email` and `tenantId`.
12455
+ * @returns An empty object.
12447
12456
  */
12448
12457
  async resendOtp(dto, req) {
12449
12458
  await this.passwordResetService.resendOtp(dto, req);
12459
+ return {};
12450
12460
  }
12451
12461
  };
12452
12462
  _ts_decorate44([
@@ -15483,7 +15493,8 @@ var REQUEST_SCHEMAS = {
15483
15493
  },
15484
15494
  "refreshToken": {
15485
15495
  "type": "string",
15486
- "maxLength": 512
15496
+ "maxLength": 2048,
15497
+ "minLength": 1
15487
15498
  }
15488
15499
  },
15489
15500
  "required": [
@@ -17521,6 +17532,8 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
17521
17532
  // in the BYMAX_AUTH_OPTIONS provider above.
17522
17533
  // expiresIn is omitted — TokenManagerService sets it per-call via accessSignOptions().
17523
17534
  jwt.JwtModule.registerAsync({
17535
+ // The factory runs here too, so it needs the modules the consumer's `inject` tokens come from.
17536
+ imports: options.imports ?? [],
17524
17537
  useFactory: /* @__PURE__ */ __name(async (...args) => {
17525
17538
  const userOptions = await options.useFactory(...args);
17526
17539
  return {
@@ -4569,7 +4569,11 @@ declare const WS_TICKET_TTL_SECONDS = 30;
4569
4569
  interface WsTicketSnapshot {
4570
4570
  /** The subject — the internal user id. */
4571
4571
  sub: string;
4572
- /** The tenant scope. Absent for a platform ticket. */
4572
+ /**
4573
+ * The tenant scope. Optional because the shared `wst:` record can be written by another
4574
+ * backend without one; this library always sets it, and the WebSocket guard refuses a
4575
+ * snapshot that lacks it.
4576
+ */
4573
4577
  tenantId?: string;
4574
4578
  /** The user's role at mint time. */
4575
4579
  role: string;
@@ -6807,6 +6811,9 @@ declare class ChangePasswordDto {
6807
6811
  * `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
6808
6812
  * it — so the suite exercised a request production never sees. Optional, because under cookie
6809
6813
  * delivery the credential arrives in the cookie and no body field exists to declare.
6814
+ *
6815
+ * A present value is held to the contract's opaque-token bound (1 to 2048 characters), so an
6816
+ * empty string is refused instead of being read as "no token".
6810
6817
  */
6811
6818
  refreshToken?: string;
6812
6819
  }
@@ -4569,7 +4569,11 @@ declare const WS_TICKET_TTL_SECONDS = 30;
4569
4569
  interface WsTicketSnapshot {
4570
4570
  /** The subject — the internal user id. */
4571
4571
  sub: string;
4572
- /** The tenant scope. Absent for a platform ticket. */
4572
+ /**
4573
+ * The tenant scope. Optional because the shared `wst:` record can be written by another
4574
+ * backend without one; this library always sets it, and the WebSocket guard refuses a
4575
+ * snapshot that lacks it.
4576
+ */
4573
4577
  tenantId?: string;
4574
4578
  /** The user's role at mint time. */
4575
4579
  role: string;
@@ -6807,6 +6811,9 @@ declare class ChangePasswordDto {
6807
6811
  * `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
6808
6812
  * it — so the suite exercised a request production never sees. Optional, because under cookie
6809
6813
  * delivery the credential arrives in the cookie and no body field exists to declare.
6814
+ *
6815
+ * A present value is held to the contract's opaque-token bound (1 to 2048 characters), so an
6816
+ * empty string is refused instead of being read as "no token".
6810
6817
  */
6811
6818
  refreshToken?: string;
6812
6819
  }
@@ -11387,6 +11387,9 @@ var ChangePasswordDto = class {
11387
11387
  * `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
11388
11388
  * it — so the suite exercised a request production never sees. Optional, because under cookie
11389
11389
  * delivery the credential arrives in the cookie and no body field exists to declare.
11390
+ *
11391
+ * A present value is held to the contract's opaque-token bound (1 to 2048 characters), so an
11392
+ * empty string is refused instead of being read as "no token".
11390
11393
  */
11391
11394
  refreshToken;
11392
11395
  };
@@ -11405,7 +11408,8 @@ _ts_decorate38([
11405
11408
  _ts_decorate38([
11406
11409
  IsOptional(),
11407
11410
  IsString(),
11408
- MaxLength(512),
11411
+ IsNotEmpty(),
11412
+ MaxLength(2048),
11409
11413
  _ts_metadata37("design:type", String)
11410
11414
  ], ChangePasswordDto.prototype, "refreshToken", void 0);
11411
11415
  function _ts_decorate39(decorators, target, key, desc) {
@@ -12354,12 +12358,15 @@ var PasswordResetController = class {
12354
12358
  * Initiates a password reset for the given email address.
12355
12359
  *
12356
12360
  * Sends a reset token or OTP to the user's email if the account exists and
12357
- * is eligible. Always returns `200 OK` regardless of outcome (anti-enumeration).
12361
+ * is eligible. Always returns `200 OK` with an empty JSON object regardless of outcome
12362
+ * (anti-enumeration; the body is pinned by the wire contract).
12358
12363
  *
12359
12364
  * @param dto - Validated DTO with `email` and `tenantId`.
12365
+ * @returns An empty object.
12360
12366
  */
12361
12367
  async forgotPassword(dto, req) {
12362
12368
  await this.passwordResetService.initiateReset(dto, req);
12369
+ return {};
12363
12370
  }
12364
12371
  // ---------------------------------------------------------------------------
12365
12372
  // POST /password/reset-password
@@ -12439,12 +12446,15 @@ var PasswordResetController = class {
12439
12446
  * Re-sends the password-reset OTP for the given email address.
12440
12447
  *
12441
12448
  * Subject to a 60-second atomic cooldown per `(tenantId, email)` pair.
12442
- * Always returns `200 OK` regardless of outcome (anti-enumeration).
12449
+ * Always returns `200 OK` with an empty JSON object regardless of outcome (anti-enumeration;
12450
+ * the body is pinned by the wire contract).
12443
12451
  *
12444
12452
  * @param dto - Validated DTO with `email` and `tenantId`.
12453
+ * @returns An empty object.
12445
12454
  */
12446
12455
  async resendOtp(dto, req) {
12447
12456
  await this.passwordResetService.resendOtp(dto, req);
12457
+ return {};
12448
12458
  }
12449
12459
  };
12450
12460
  _ts_decorate44([
@@ -15481,7 +15491,8 @@ var REQUEST_SCHEMAS = {
15481
15491
  },
15482
15492
  "refreshToken": {
15483
15493
  "type": "string",
15484
- "maxLength": 512
15494
+ "maxLength": 2048,
15495
+ "minLength": 1
15485
15496
  }
15486
15497
  },
15487
15498
  "required": [
@@ -17519,6 +17530,8 @@ var BymaxAuthModule = class _BymaxAuthModule {
17519
17530
  // in the BYMAX_AUTH_OPTIONS provider above.
17520
17531
  // expiresIn is omitted — TokenManagerService sets it per-call via accessSignOptions().
17521
17532
  JwtModule.registerAsync({
17533
+ // The factory runs here too, so it needs the modules the consumer's `inject` tokens come from.
17534
+ imports: options.imports ?? [],
17522
17535
  useFactory: /* @__PURE__ */ __name(async (...args) => {
17523
17536
  const userOptions = await options.useFactory(...args);
17524
17537
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-auth",
3
- "version": "1.4.14",
3
+ "version": "1.4.15",
4
4
  "description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",
@@ -75,6 +75,7 @@
75
75
  },
76
76
  "scripts": {
77
77
  "build": "pnpm clean && tsup",
78
+ "check:api": "node scripts/check-api-surface.mjs",
78
79
  "check:exports": "node scripts/check-exports.mjs",
79
80
  "check:published": "node scripts/check-published-surface.mjs",
80
81
  "check:runtime": "node scripts/check-consumer-runtime.mjs",