@lenne.tech/nest-server 12.10.1 → 12.11.0
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/.claude/rules/better-auth.md +19 -0
- package/.claude/rules/configurable-features.md +11 -9
- package/.claude/rules/package-management.md +1 -1
- package/.claude/rules/role-system.md +4 -1
- package/.claude/rules/testing.md +4 -4
- package/CLAUDE.md +5 -0
- package/FRAMEWORK-API.md +2 -1
- package/dist/core/common/decorators/unified-field.decorator.js +5 -2
- package/dist/core/common/decorators/unified-field.decorator.js.map +1 -1
- package/dist/core/common/helpers/config.helper.js +31 -9
- package/dist/core/common/helpers/config.helper.js.map +1 -1
- package/dist/core/common/helpers/graceful-shutdown.helper.js +3 -1
- package/dist/core/common/helpers/graceful-shutdown.helper.js.map +1 -1
- package/dist/core/common/helpers/graphql-ws-connection.helper.d.ts +8 -3
- package/dist/core/common/helpers/graphql-ws-connection.helper.js +44 -0
- package/dist/core/common/helpers/graphql-ws-connection.helper.js.map +1 -1
- package/dist/core/common/helpers/http-stream-auth.helper.d.ts +13 -0
- package/dist/core/common/helpers/http-stream-auth.helper.js +90 -0
- package/dist/core/common/helpers/http-stream-auth.helper.js.map +1 -0
- package/dist/core/common/helpers/shutdown-state.helper.d.ts +3 -0
- package/dist/core/common/helpers/shutdown-state.helper.js +11 -0
- package/dist/core/common/helpers/shutdown-state.helper.js.map +1 -0
- package/dist/core/common/interfaces/cron-job-config-with-utc-offset.interface.d.ts +1 -1
- package/dist/core/common/interfaces/cron-job-config.interface.d.ts +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +14 -0
- package/dist/core/common/services/core-cron-jobs.service.d.ts +13 -0
- package/dist/core/common/services/core-cron-jobs.service.js +129 -4
- package/dist/core/common/services/core-cron-jobs.service.js.map +1 -1
- package/dist/core/modules/better-auth/better-auth.config.js +48 -4
- package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-jwt-session.cache.d.ts +8 -0
- package/dist/core/modules/better-auth/core-better-auth-jwt-session.cache.js +47 -0
- package/dist/core/modules/better-auth/core-better-auth-jwt-session.cache.js.map +1 -0
- package/dist/core/modules/better-auth/core-better-auth-models.d.ts +1 -0
- package/dist/core/modules/better-auth/core-better-auth-models.js +7 -0
- package/dist/core/modules/better-auth/core-better-auth-models.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth-sign-in-factors.helper.d.ts +11 -0
- package/dist/core/modules/better-auth/core-better-auth-sign-in-factors.helper.js +62 -0
- package/dist/core/modules/better-auth/core-better-auth-sign-in-factors.helper.js.map +1 -0
- package/dist/core/modules/better-auth/core-better-auth-user.mapper.d.ts +1 -0
- package/dist/core/modules/better-auth/core-better-auth-user.mapper.js +28 -1
- package/dist/core/modules/better-auth/core-better-auth-user.mapper.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.controller.js +2 -1
- package/dist/core/modules/better-auth/core-better-auth.controller.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.middleware.js +2 -2
- package/dist/core/modules/better-auth/core-better-auth.middleware.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.resolver.js +1 -0
- package/dist/core/modules/better-auth/core-better-auth.resolver.js.map +1 -1
- package/dist/core/modules/better-auth/core-better-auth.service.d.ts +10 -0
- package/dist/core/modules/better-auth/core-better-auth.service.js +105 -19
- package/dist/core/modules/better-auth/core-better-auth.service.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check-readiness.controller.d.ts +6 -0
- package/dist/core/modules/health-check/core-health-check-readiness.controller.js +36 -0
- package/dist/core/modules/health-check/core-health-check-readiness.controller.js.map +1 -0
- package/dist/core/modules/health-check/core-health-check.helpers.d.ts +10 -0
- package/dist/core/modules/health-check/core-health-check.helpers.js +31 -0
- package/dist/core/modules/health-check/core-health-check.helpers.js.map +1 -0
- package/dist/core/modules/health-check/core-health-check.module.d.ts +9 -0
- package/dist/core/modules/health-check/core-health-check.module.js +13 -2
- package/dist/core/modules/health-check/core-health-check.module.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check.service.d.ts +8 -1
- package/dist/core/modules/health-check/core-health-check.service.js +66 -29
- package/dist/core/modules/health-check/core-health-check.service.js.map +1 -1
- package/dist/core/modules/sync/core-sync.service.d.ts +2 -0
- package/dist/core/modules/sync/core-sync.service.js +11 -1
- package/dist/core/modules/sync/core-sync.service.js.map +1 -1
- package/dist/core.module.js +5 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/main.js.map +1 -1
- package/docs/REQUEST-LIFECYCLE.md +4 -4
- package/docs/offline-sync-protocol.md +5 -3
- package/migration-guides/12.10.x-to-12.11.x.md +295 -0
- package/package.json +17 -17
- package/src/core/common/decorators/unified-field.decorator.ts +14 -4
- package/src/core/common/helpers/config.helper.ts +55 -8
- package/src/core/common/helpers/graceful-shutdown.helper.ts +10 -3
- package/src/core/common/helpers/graphql-ws-connection.helper.ts +99 -4
- package/src/core/common/helpers/http-stream-auth.helper.ts +197 -0
- package/src/core/common/helpers/shutdown-state.helper.ts +28 -0
- package/src/core/common/interfaces/cron-job-config-with-utc-offset.interface.ts +1 -1
- package/src/core/common/interfaces/cron-job-config.interface.ts +1 -1
- package/src/core/common/interfaces/server-options.interface.ts +113 -1
- package/src/core/common/services/core-cron-jobs.service.ts +241 -14
- package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +26 -10
- package/src/core/modules/better-auth/README.md +37 -8
- package/src/core/modules/better-auth/better-auth.config.ts +83 -12
- package/src/core/modules/better-auth/core-better-auth-api.middleware.ts +1 -1
- package/src/core/modules/better-auth/core-better-auth-jwt-session.cache.ts +104 -0
- package/src/core/modules/better-auth/core-better-auth-models.ts +5 -0
- package/src/core/modules/better-auth/core-better-auth-sign-in-factors.helper.ts +105 -0
- package/src/core/modules/better-auth/core-better-auth-user.mapper.ts +37 -1
- package/src/core/modules/better-auth/core-better-auth.controller.ts +6 -3
- package/src/core/modules/better-auth/core-better-auth.middleware.ts +4 -3
- package/src/core/modules/better-auth/core-better-auth.module.ts +1 -1
- package/src/core/modules/better-auth/core-better-auth.resolver.ts +1 -0
- package/src/core/modules/better-auth/core-better-auth.service.ts +160 -27
- package/src/core/modules/health-check/core-health-check-readiness.controller.ts +27 -0
- package/src/core/modules/health-check/core-health-check.helpers.ts +65 -0
- package/src/core/modules/health-check/core-health-check.module.ts +37 -2
- package/src/core/modules/health-check/core-health-check.service.ts +154 -59
- package/src/core/modules/sync/README.md +18 -6
- package/src/core/modules/sync/core-sync.service.ts +35 -6
- package/src/core.module.ts +9 -1
- package/src/index.ts +4 -0
- package/src/main.ts +2 -1
|
@@ -134,7 +134,7 @@ JWT-based authentication for existing projects:
|
|
|
134
134
|
| **Bulk Operations** | Batch create/update/delete |
|
|
135
135
|
| **Force Mode** | `force: true` bypasses all security checks |
|
|
136
136
|
| **Raw Mode** | `raw: true` skips prepareInput/prepareOutput |
|
|
137
|
-
| **Synchronized models** | `@PersistedModel({ sync })` (offline sync, 12.x): the store writes `version`, `deletedAt` and the change position on every write path (on MongoDB through `mongo/sync-schema.plugin.ts`, applied to these schemas only); `CrudService.delete()` and every port delete leave a tombstone, reads leave tombstones out unless `includeTombstones`, and `ServiceOptions.expectedVersion` makes `update()` / `delete()` one conditional statement (409 `VersionConflictError` on another version). Unique indexes apply to live records only. With the `sync` configuration (12.2.0) the sync module serves `GET/POST /sync/{model}` for models whose CrudService carries `@SyncService()`: `@Roles(S_USER)` on the route, the model's `sync.roles` passed as `serviceOptions.roles` on every CrudService call, every pulled record through `securityCheck()`, a header-less request scoped to the caller's memberships, the 410 resync body written by the controller itself (`src/core/modules/sync/README.md`). Change hints (`GET /sync/hints`, SSE, and the GraphQL subscription `syncHint`) carry `{ model, at }` only, sent from the CrudService's create / update / delete of such a model and delivered to a subscriber only with the model's pull roles and access to the tenant of the change; the SSE stream registers with the WebSocket re-check registry and ends on every invalidation or re-check, so the client reconnects with its current rights. An hourly purge removes tombstones past `sync.retention.tombstonesDays` after moving the retention horizon past them. What a client must delete on logout is in the module's `SECURITY.md`. See `.claude/rules/persistence.md` → "Synchronized models" |
|
|
137
|
+
| **Synchronized models** | `@PersistedModel({ sync })` (offline sync, 12.x): the store writes `version`, `deletedAt` and the change position on every write path (on MongoDB through `mongo/sync-schema.plugin.ts`, applied to these schemas only); `CrudService.delete()` and every port delete leave a tombstone, reads leave tombstones out unless `includeTombstones`, and `ServiceOptions.expectedVersion` makes `update()` / `delete()` one conditional statement (409 `VersionConflictError` on another version). Unique indexes apply to live records only. With the `sync` configuration (12.2.0) the sync module serves `GET/POST /sync/{model}` for models whose CrudService carries `@SyncService()`: `@Roles(S_USER)` on the route, the model's `sync.roles` passed as `serviceOptions.roles` on every CrudService call, every pulled record through `securityCheck()`, a header-less request scoped to the caller's memberships, the 410 resync body written by the controller itself (`src/core/modules/sync/README.md`). Change hints (`GET /sync/hints`, SSE, and the GraphQL subscription `syncHint`) carry `{ model, at }` only, sent from the CrudService's create / update / delete of such a model and delivered to a subscriber only with the model's pull roles and access to the tenant of the change; the SSE stream registers with the WebSocket re-check registry; opened with a Better-Auth credential it is re-checked in place and stays open while the rights are unchanged (12.11.0), otherwise it ends on every invalidation or re-check, so the client reconnects with its current rights. An hourly purge removes tombstones past `sync.retention.tombstonesDays` after moving the retention horizon past them. What a client must delete on logout is in the module's `SECURITY.md`. See `.claude/rules/persistence.md` → "Synchronized models" |
|
|
138
138
|
|
|
139
139
|
### Models & Inputs
|
|
140
140
|
|
|
@@ -217,7 +217,7 @@ JWT-based authentication for existing projects:
|
|
|
217
217
|
| **Custom Scalars** | `Date`, `DateTime` (timestamp), `JSON`, `Any` |
|
|
218
218
|
| **Subscriptions** | WebSocket support via `graphql-ws` with auth. The `PUB_SUB` provider is built from a factory: `CoreRedisPubSub` when `redis` is configured (delivery is then cluster-wide), the in-memory `PubSub` otherwise (delivery only to clients connected to the publishing replica). **Constraint once Redis is in play: every published payload must be JSON-serializable** — it crosses the wire as JSON, so `Date`, class instances, `Map`/`Set` and `undefined` do not survive the round trip. An in-process `PubSub` never had this constraint, so a payload that worked on one replica can silently lose fields on a cluster. Publish plain objects and ISO strings |
|
|
219
219
|
| **Subscription request context** | Since 11.35.0 `CoreModule` installs a context-aware `execute` / `subscribe` pair (inside `subscriptions`, where `ApolloDriver` forwards it) on all three GraphQL driver builders, so every WebSocket operation runs inside a `RequestContext`. Before that a WS operation had **none** — no Express middleware runs on an upgrade, and `CoreTenantGuard.getRequest()` finds no `req` on a subscription context — and `mongooseTenantPlugin` reads "no context" as "system operation, no filter", so a tenant-scoped read while delivering a subscription message returned EVERY tenant's rows. The tenant comes from the handshake's tenant header **validated against an active membership**, else from the subscriber's memberships; an unresolvable tenant leaves the safety net to refuse the read. The async iterator is wrapped too, not only the subscribe call: graphql-js runs `resolve` / `filter` / field resolvers inside its `next()`. See `.claude/rules/role-system.md` → "Tenant context on non-HTTP transports" |
|
|
220
|
-
| **Subscription re-check** | Since 11.42.3 that context is not trusted for the life of the socket. Every connection a `CoreModule` `onConnect` accepts is registered (`registerWsConnection()`) and checked again — at once on an invalidation (tenant guard, role change, password reset, Better-Auth deleting the session), otherwise before the next operation or event once `graphQl.subscriptionRevalidationMs` (30 s) has passed. The check re-runs the handshake's authentication and the tenant resolution; a connection whose rights changed is closed with 4403 (retried by the graphql-ws client, which then reconnects with its current rights) and the event that triggered the check is dropped. Before, a removed membership, a deactivated tenant, a withdrawn role or a revoked session kept receiving events on an open socket until the client reconnected. See `.claude/rules/role-system.md` → "Open WebSockets" |
|
|
220
|
+
| **Subscription re-check** | Since 11.42.3 that context is not trusted for the life of the socket. Every connection a `CoreModule` `onConnect` accepts is registered (`registerWsConnection()`) and checked again — at once on an invalidation (tenant guard, role change, password reset, Better-Auth deleting the session), otherwise before the next operation or event once `graphQl.subscriptionRevalidationMs` (30 s) has passed. The check re-runs the handshake's authentication and the tenant resolution; a connection whose rights changed is closed with 4403 (retried by the graphql-ws client, which then reconnects with its current rights) and the event that triggered the check is dropped. HTTP streams (SSE) use the same registry through `registerHttpStream()` (12.11.0): re-checked in place when their Better-Auth credential can be run again, ended on every re-check otherwise. Before, a removed membership, a deactivated tenant, a withdrawn role or a revoked session kept receiving events on an open socket until the client reconnected. See `.claude/rules/role-system.md` → "Open WebSockets" |
|
|
221
221
|
| **Complexity Analysis** | Query cost calculation to prevent DoS attacks. Since 12.10.1 `ComplexityPlugin` analyses only the operation Apollo resolved (none resolved: left to execution, which refuses it before coercing a variable), first checks whether its variables coerce (stopping at the first error) and leaves invalid ones to execution, which refuses them with graphql's cap (50), refuses an operation whose fields × declared variables exceed 250,000, computes graphql-query-complexity's number with each fragment evaluated once, and stops at its first error. Before, a document of many operations, a list of invalid items, a fragment spread thousands of times, tens of thousands of variables or thousands of failing arguments each blocked the event loop for seconds from one anonymous request |
|
|
222
222
|
| **Enum Registration** | `registerEnum()` helper for GraphQL enum types |
|
|
223
223
|
| **Upload Support** | `graphqlUploadExpress()` for multipart file uploads, with the framework's `processGraphQlUploadRequest` (graphql-upload's parser with the GHSA-5vm7-vc2x-p3w2 and GHSA-qwwm-252j-9whw fixes, since 12.10.0; `map` bounded to 64 keys per path and 10,000 entries, path keys and array elements together, since 12.10.1) |
|
|
@@ -226,14 +226,14 @@ JWT-based authentication for existing projects:
|
|
|
226
226
|
|
|
227
227
|
| Feature | Description |
|
|
228
228
|
|---------|-------------|
|
|
229
|
-
| **Health Check Module** | `GET /health` + GraphQL `healthCheck` query |
|
|
229
|
+
| **Health Check Module** | `GET /health-check` (liveness) + GraphQL `healthCheck` query, both public (`@Roles(S_EVERYONE)`), registered by the `healthCheck` config. With `healthCheck.readiness` (12.11.0) also `GET /health-check/ready` (readiness: the checks `readiness.checks` lists, default `database` + `build`; 503 when one is down, and from the first shutdown signal on when `installGracefulShutdown()` handles it). Project checks: extend `CoreHealthCheckService`, override `additionalHealthIndicators(kind)`, pass the subclass as `CoreModule.forRoot(env, { healthCheck: { service } })` |
|
|
230
230
|
| **Error Code Module** | Centralized error registry with unique IDs |
|
|
231
231
|
| **Permissions Report** | Interactive HTML dashboard, JSON, and Markdown reports |
|
|
232
232
|
| **Hub (Operator Cockpit)** | Build-free ADMIN-gated dashboard at `/hub` (config-gated per environment). Adds an optional HTTP trace middleware (registered by `CoreHubModule.configure()` only when traces are enabled), a chaining `Logger.overrideLogger()` delegate for the log buffer, an optional `EmailService` capture hook (`HUB_EMAIL_CAPTURE` token) for the mailbox, and — when the query profiler is enabled — opts the MongoDB driver into `monitorCommands` from `core.module.ts`. See `src/core/modules/hub/README.md`. |
|
|
233
233
|
| **Process Diagnostics** | Opt-in process-level exit diagnostics (`installProcessDiagnostics()` + `handleFatalBootstrapError`, `src/core/common/helpers/process-diagnostics.helper.ts`). Wired into `main.ts` — **NOT** into `CoreModule.forRoot()`, because it must run before `NestFactory.create()` and installs a `process.exit(1)` path that must never arm inside `Test.createTestingModule()`. Logs unhandled rejections without crashing (configurable), uncaught exceptions before the exit, non-zero exit codes, and labels SIGTERM/SIGINT/SIGHUP/SIGQUIT as external terminations. Pair with `installGracefulShutdown(server)` — **not** with `server.enableShutdownHooks()`, see the Graceful Shutdown row below |
|
|
234
234
|
| **Graceful Shutdown** | `installGracefulShutdown(app)` (`src/core/common/helpers/graceful-shutdown.helper.ts`), wired in `main.ts`. It **REPLACES** `server.enableShutdownHooks()` and must not be used alongside it: with `shutdownDelayMs` set, Nest would register its own listener for the same signals and close the app in parallel with the wait, so the delay silently never happens. At `shutdownDelayMs: 0` (the default) the helper simply *is* `enableShutdownHooks()`, so the single call is correct either way. With a delay it waits **inside the SIGTERM/SIGINT handler, before `close()` is entered** — a NestJS lifecycle hook cannot do this, because `close()` runs `onModuleDestroy` → `beforeApplicationShutdown` → dispose → `onApplicationShutdown`, i.e. a delay in a hook would wait with every module already torn down while the socket still accepts. A second signal cancels the pending wait and closes immediately. Warns above 10 000 ms, capped at 60 000 ms — keep it below the orchestrator grace period (Compose 10 s, Kubernetes 30 s) and below `installProcessDiagnostics()`'s 30 s force-exit |
|
|
235
235
|
| **System Setup Module** | Initial admin creation for fresh deployments |
|
|
236
|
-
| **Cron Jobs** | `CoreCronJobsService` with timezone/UTC offset support |
|
|
236
|
+
| **Cron Jobs** | `CoreCronJobsService` with timezone/UTC offset support. `rescheduleCronJob(name, schedule)` (12.11.0) changes a registered job's schedule at runtime — local timer and BullMQ scheduler alike; call it on every replica, it is not stored |
|
|
237
237
|
| **Model Documentation** | Auto-generated model docs via `ModelDocService` |
|
|
238
238
|
| **SCIM Support** | SCIM filtering and query parsing utilities |
|
|
239
239
|
|
|
@@ -305,9 +305,11 @@ Sync API exists only in Chromium).
|
|
|
305
305
|
* A hint carries the model name and a time — no record, no id, no tenant. It is sent only to subscribers who hold the
|
|
306
306
|
model's pull roles and may read the changed tenant's records of that model; bursts are collapsed (default 250 ms).
|
|
307
307
|
* Both channels are long-lived, so the server checks them again during their lifetime like its GraphQL WebSockets: a
|
|
308
|
-
channel whose user lost access, signed out or changed roles is closed; the client reconnects and is checked anew.
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
channel whose user lost access, signed out or changed roles is closed; the client reconnects and is checked anew. A
|
|
309
|
+
hint is never delivered on rights older than the re-check interval (30 s by default): before the first hint after it
|
|
310
|
+
the server checks again. An SSE stream opened with a Better-Auth credential (session cookie, bearer session token or
|
|
311
|
+
JWT) is checked in place and stays open while the rights are unchanged (12.11.0); one opened with another credential
|
|
312
|
+
ends at that point and is reconnected.
|
|
311
313
|
* On reconnect a client pulls once, because hints sent while it was disconnected are not replayed.
|
|
312
314
|
|
|
313
315
|
## 10. HTTP errors
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# Migration Guide: 12.10.x → 12.11.x
|
|
2
|
+
|
|
3
|
+
> **This minor contains breaking changes** (see "Breaking Changes"): a Better-Auth JWT is bound to its session and
|
|
4
|
+
> stops working when the session ends; Passkey and two-factor are off in projects without e-mail and password sign-in;
|
|
5
|
+
> a client-submitted id token no longer signs in; `NSC__` environment values are read differently; unnamed list enums
|
|
6
|
+
> no longer share an OpenAPI schema `Array`. The MAJOR digit follows NestJS, so a breaking change ships as a minor here
|
|
7
|
+
> — read this guide before updating.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
| Category | Details |
|
|
12
|
+
|----------|---------|
|
|
13
|
+
| **Breaking Changes** | (1) A Better-Auth JWT is refused once the session it was issued from is signed out, revoked, expired or its user deleted; a JWT issued before 12.11.0 is refused once (§1). (2) With `emailAndPassword.enabled: false` and no plugin sign-in route of the project's own (sign-in through a provider alone), Passkey and two-factor are off unless switched on explicitly (§2). (3) `POST /iam/sign-in/social` and `/iam/link-social` with a client-submitted `idToken` answer `ID_TOKEN_NOT_SUPPORTED` unless the provider sets `disableIdTokenSignIn: false` (§3). (4) `NSC__` values: empty = not set, `true` / `false` in any case, `enabled` keys take only `true` / `false` / `1` / `0` (§4). (5) A plain list given as `@UnifiedField({ enum: [...] })` without `enumName` stays inline in the OpenAPI document instead of becoming a schema `Array` (§5) |
|
|
14
|
+
| **Security fixes** | §1 to §3: nothing the framework offers keeps someone signed in after a sign-out or after a sign-in provider withdrew the assignment — the JWT outlived a sign-out by up to 15 minutes, a passkey registered once kept working after the withdrawal, and an id token kept from an earlier sign-in signed its owner in again for about an hour. A JWT client's `POST /iam/sign-out` ended no session at all. §4: an off switch written as empty, `0`, `FALSE` or `off` left the feature on |
|
|
15
|
+
| **New Features** | `betterAuth.session` (fixed session lifetime, §6); `emailAndPassword` in `GET /iam/features` and `betterAuthFeatures` (§2); `CoreCronJobs.rescheduleCronJob()`, SSE streams re-checked in place (`registerHttpStream()`, the sync hints stream), a readiness endpoint `GET /health-check/ready` and `CoreHealthCheckService.additionalHealthIndicators()` (§7) |
|
|
16
|
+
| **Bugfixes** | `POST /iam/sign-out` with a JWT ends the JWT's session; Better-Auth's plugin routes act on the JWT's own session instead of the user's newest one (§1). `CronJobConfig.utcOffset` is typed as a number (minutes), as cron expects it — it was typed as a boolean by mistake |
|
|
17
|
+
| **Dependencies** | NestJS 12.6.0 and patch updates; keep `@apollo/server` at 5.5.1 (§8) |
|
|
18
|
+
| **Migration Effort** | ~10 minutes: check JWT clients (§1), SSO-only projects (§2), native apps with id token sign-in and the starter's Microsoft example test (§3), deployment variables (§4) and generated API clients (§5) |
|
|
19
|
+
|
|
20
|
+
## Quick Migration
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @lenne.tech/nest-server@12.11.x
|
|
24
|
+
pnpm run update # only if you use the starter's update script
|
|
25
|
+
pnpm run build
|
|
26
|
+
pnpm test
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
No new dependency is required.
|
|
30
|
+
|
|
31
|
+
## 1. Breaking (security): a Better-Auth JWT is bound to its session
|
|
32
|
+
|
|
33
|
+
Up to 12.10.x the API accepted a Better-Auth JWT on its signature and expiry alone. Measured in a project: after
|
|
34
|
+
`POST /iam/sign-out` the session cookie answered 401 at once, while the JWT kept reading and writing for 14 min 57 s of
|
|
35
|
+
its 15 — and so did any copy of it. A session revoked by an administrator, an expired session and a deleted user were
|
|
36
|
+
no different. Two more defects sat on the same path: a JWT client's `POST /iam/sign-out` read the session from the
|
|
37
|
+
cookie alone, found none, ended nothing and answered `{ success: true }`; and the middleware handed Better-Auth's
|
|
38
|
+
plugin routes the user's NEWEST session for a JWT request, so a sign-out on one device ended another one.
|
|
39
|
+
|
|
40
|
+
Since 12.11.0:
|
|
41
|
+
|
|
42
|
+
- The JWT carries the id of the session it was issued from (claim `sid`), next to Better-Auth's default payload.
|
|
43
|
+
- The API accepts it only while that session exists, belongs to the token's subject and has not expired. The answer is
|
|
44
|
+
cached for 10 seconds; when Better-Auth deletes the session (sign-out, revoke, password reset with
|
|
45
|
+
`revokeSessionsOnPasswordReset`, user deletion) it is forgotten at once — with `redis` on every replica, without it on
|
|
46
|
+
this one and on the others within 10 seconds. A session removed directly in the database is caught by the interval.
|
|
47
|
+
- `POST /iam/sign-out` with a JWT ends the JWT's own session, and plugin routes (2FA, passkey, …) act on it.
|
|
48
|
+
|
|
49
|
+
**What changes for clients:**
|
|
50
|
+
|
|
51
|
+
| Situation | Since 12.11.0 | What to do |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| A JWT issued before the update | `401` on its next request | With a session cookie (the default `cookies: true`): nothing for `@lenne.tech/nuxt-extensions` / `@lenne.tech/ng-base`, they fetch a new JWT with the session on the 401; other clients fetch `GET /iam/token` with the session again. **With `cookies: false` the client holds the JWT alone and cannot renew it: every user signs in once more after the update** |
|
|
54
|
+
| Sign-out, revoked session, deleted user | The session's JWTs answer `401` at once | — |
|
|
55
|
+
| Enabling 2FA (the first `verify-totp`) | Better-Auth replaces the session; the old JWT answers `401`. The answer's `token` is the JWT of the new session | A JWT client continues with that `token` (or fetches a new one on the 401) |
|
|
56
|
+
| Several devices | Each JWT follows its own session; signing out one leaves the others signed in | — |
|
|
57
|
+
|
|
58
|
+
A JWT is still verified without a call to the identity provider, and the session check costs at most one lookup per
|
|
59
|
+
session and 10 seconds per replica. Before 12.11.0 the middleware looked up the user's newest session on every JWT
|
|
60
|
+
request; that lookup is gone.
|
|
61
|
+
|
|
62
|
+
**A project that verifies Better-Auth JWTs itself** (`jwtVerify()` against the JWKS) checks the signature only — call
|
|
63
|
+
`CoreBetterAuthService.verifyJwtToken()` instead, which checks the session.
|
|
64
|
+
|
|
65
|
+
## 2. Breaking (security): Passkey and two-factor follow e-mail and password sign-in
|
|
66
|
+
|
|
67
|
+
**Who is affected:** projects that sign in through a single sign-on provider alone —
|
|
68
|
+
`betterAuth.emailAndPassword.enabled: false` and no plugin of the project with a sign-in route of its own. A project
|
|
69
|
+
that signs in by username or phone number (`username()`, `phoneNumber()` in `betterAuth.plugins`) keeps both on, since
|
|
70
|
+
two-factor is what enforces the second factor on those routes. Every other project keeps both on, as before.
|
|
71
|
+
|
|
72
|
+
Passkey and two-factor were on whatever `emailAndPassword` said. Whoever signed in through Microsoft once and registered
|
|
73
|
+
a passkey kept signing in with it after Entra withdrew the assignment: the provider no longer decided who gets in.
|
|
74
|
+
|
|
75
|
+
Since 12.11.0 both are off while sign-in runs through a provider alone. Their routes answer `404`, also for a passkey
|
|
76
|
+
registered earlier, and `GET /iam/features` reports `passkey: false` / `twoFactor: false`. The boot names what it
|
|
77
|
+
switched off — as a warning when the factor carried settings of its own (`twoFactor: { appName }`). To keep one
|
|
78
|
+
deliberately:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
betterAuth: {
|
|
82
|
+
emailAndPassword: { enabled: false },
|
|
83
|
+
passkey: true, // or { enabled: true, rpName: '…' }
|
|
84
|
+
twoFactor: { appName: 'My App', enabled: true },
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
An object without `enabled: true` (a `twoFactor: { appName }` kept from a password setup) does not switch it on.
|
|
89
|
+
|
|
90
|
+
`GET /iam/features` (and the GraphQL `betterAuthFeatures`) report `emailAndPassword` since 12.11.0, so a login page
|
|
91
|
+
can hide the e-mail form instead of subclassing the controller for it.
|
|
92
|
+
|
|
93
|
+
## 3. Breaking (security): no sign-in with a client-submitted id token
|
|
94
|
+
|
|
95
|
+
`POST /iam/sign-in/social` accepts `{ provider, idToken: { token } }`: the client submits the provider's id token, and
|
|
96
|
+
Better-Auth checks its signature, audience and expiry — and asks the provider nothing. `GET /iam/list-accounts` and
|
|
97
|
+
`POST /iam/get-access-token` hand a signed-in user the id token of their last sign-in, so within its lifetime (about an
|
|
98
|
+
hour at Microsoft) that token signed its owner in again after Entra had withdrawn the app role or the assignment. Proven
|
|
99
|
+
end to end against a mock of the Entra endpoints.
|
|
100
|
+
|
|
101
|
+
Since 12.11.0 every social provider gets `disableIdTokenSignIn: true` unless the project sets it to `false`. Such a
|
|
102
|
+
request answers `ID_TOKEN_NOT_SUPPORTED`, on `/iam/link-social` too. The redirect flow (`signIn.social` with a
|
|
103
|
+
`callbackURL`, what the lenne.Tech frontends use) never uses this path and keeps working.
|
|
104
|
+
|
|
105
|
+
**Native apps and Google One Tap** send the provider's id token themselves. Open it for that provider:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
betterAuth: {
|
|
109
|
+
socialProviders: {
|
|
110
|
+
google: { clientId, clientSecret, disableIdTokenSignIn: false },
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Only the boolean `false` opens it; any other value keeps it closed. nest-server-starter's Microsoft example sets
|
|
116
|
+
`disableIdTokenSignIn: true` since 12.10.1 — that line can stay, it states the default now.
|
|
117
|
+
|
|
118
|
+
**Projects created from nest-server-starter 12.10.1 or later** carry `tests/unit/microsoft-sign-in-example.spec.ts`.
|
|
119
|
+
Its third case removes the option and expects the id token to be verified, so after the update it fails with
|
|
120
|
+
`expected 'ID_TOKEN_NOT_SUPPORTED' not to be 'ID_TOKEN_NOT_SUPPORTED'`. Open the path explicitly there, as the starter
|
|
121
|
+
does:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
it('would verify a submitted ID token with the option set to false, so the option is what closes the path', async () => {
|
|
125
|
+
const code = await idTokenSignInCode({ ...EXAMPLE, disableIdTokenSignIn: false });
|
|
126
|
+
expect(code).toBeDefined();
|
|
127
|
+
expect(code).not.toBe('ID_TOKEN_NOT_SUPPORTED');
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 4. Breaking: `NSC__` environment values
|
|
132
|
+
|
|
133
|
+
Deployments set the configuration through `NSC__…` variables. Two ways of writing an off switch left the feature on:
|
|
134
|
+
|
|
135
|
+
| Variable | Up to 12.10.x | Since 12.11.0 |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| `NSC__X__ENABLED=` (empty, or spaces) | `0` — `enabled !== false` reads it as **on** | not set: the default applies, and no object is created along the path (`NSC__REDIS__HOST=` no longer creates `redis: {}`, which switches Redis on) |
|
|
138
|
+
| `NSC__X__ENABLED=FALSE`, `=False`, `= false ` | the text `"FALSE"` — **on** | `false` |
|
|
139
|
+
| `NSC__X__ENABLED=0` / `=1` | `0` / `1` — both **on** | `false` / `true` |
|
|
140
|
+
| `NSC__X__ENABLED=off`, `=no`, `=yes` | text — **on** | **the start stops**: `NSC__X__ENABLED="off" is not a switch value: write true or false (1 or 0 work too)` |
|
|
141
|
+
| `NSC__X__ROLE=` | `"0"` | not set |
|
|
142
|
+
| any other key: `TRUE`, `True` | text | `true` |
|
|
143
|
+
| numbers, other text | unchanged | unchanged |
|
|
144
|
+
|
|
145
|
+
**Check before updating:** `env | grep '^NSC__'` on each stage. Empty variables now leave the default in place instead
|
|
146
|
+
of `0`; a key named `ENABLED` with any value but `true`, `false`, `1` or `0` must be corrected, or the service does not
|
|
147
|
+
start. A text value that must stay exactly `TRUE` or `False` (a password, say) is now a boolean — pass it through
|
|
148
|
+
`NEST_SERVER_CONFIG` or `config.env.ts` instead (exactly `true` / `false` were converted before as well).
|
|
149
|
+
|
|
150
|
+
## 5. Breaking: unnamed list enums in the OpenAPI document
|
|
151
|
+
|
|
152
|
+
`@UnifiedField({ enum: ['red', 'green'] })` without `enumName` named its OpenAPI schema after the list's constructor:
|
|
153
|
+
`Array`. Every such field of a project shared that one schema, and a client generated from the document declared
|
|
154
|
+
`export type Array = …`, shadowing the built-in type (36 type errors in one project).
|
|
155
|
+
|
|
156
|
+
Since 12.11.0 such an enum stays inline (`{ "enum": ["red", "green"] }`), as an unregistered TypeScript enum does, and
|
|
157
|
+
no schema is named after a built-in type. **Regenerate API clients** (e.g. `pnpm run generate-types` in an app): a
|
|
158
|
+
type `Array` disappears, fields that used it carry their own values. To keep a named schema, set `enumName` on the
|
|
159
|
+
field or register the enum with `registerEnum()`.
|
|
160
|
+
|
|
161
|
+
## 6. New: a fixed session lifetime (`betterAuth.session`)
|
|
162
|
+
|
|
163
|
+
Better-Auth's sessions last 7 days and are extended once a day while they are used — a session used every day never
|
|
164
|
+
ends, and a withdrawal at the sign-in provider never reaches it. A project that wants the provider to be asked again
|
|
165
|
+
after a fixed time:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
betterAuth: {
|
|
169
|
+
session: { expiresInHours: 8, extendOnUse: false }, // sign in again after 8 hours, every time
|
|
170
|
+
},
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
| Option | Maps to | Default |
|
|
174
|
+
|---|---|---|
|
|
175
|
+
| `expiresInHours` | Better-Auth's `session.expiresIn` (seconds) | 168 (7 days) |
|
|
176
|
+
| `extendOnUse: false` | `session.disableSessionRefresh: true` | extended once a day of use |
|
|
177
|
+
|
|
178
|
+
A value of `expiresInHours` that is not a positive number is ignored with a warning (never "unlimited").
|
|
179
|
+
`betterAuth.options.session` still wins key by key.
|
|
180
|
+
|
|
181
|
+
## 7. New: cron schedules at runtime, SSE streams re-checked in place, health readiness
|
|
182
|
+
|
|
183
|
+
### `CoreCronJobs.rescheduleCronJob(name, schedule)`
|
|
184
|
+
|
|
185
|
+
Changes the schedule of a registered job without touching protected internals: a cron expression, a date,
|
|
186
|
+
`{ cronTime, timeZone }` or `{ cronTime, utcOffset }` (type `CronJobSchedule`). Only the schedule changes —
|
|
187
|
+
`distributed`, `runParallel`, the leases and `bullJobOptions` stay; `runOnInit` is not repeated. An invalid expression,
|
|
188
|
+
an unknown time zone, a date in the past or an unregistered job rejects and leaves the job as it was.
|
|
189
|
+
|
|
190
|
+
- **BullMQ** (with `redis`): the scheduler in Redis changes for the whole fleet; calling it on every replica is safe.
|
|
191
|
+
- **Local timer**: changes on the calling replica only — call it on every replica (from the settings change each one
|
|
192
|
+
observes, and at startup).
|
|
193
|
+
- A reschedule is not stored: the next bootstrap schedules from the configuration again, so a project re-applies a
|
|
194
|
+
stored schedule after `super.onApplicationBootstrap()`.
|
|
195
|
+
|
|
196
|
+
### SSE streams keep running while the rights are unchanged
|
|
197
|
+
|
|
198
|
+
A Server-Sent Events stream registered for re-checks (`endsOnRecheck`) ENDED on the first event after
|
|
199
|
+
`graphQl.subscriptionRevalidationMs`, and the client received that event only after reconnecting (about 3 s later). The
|
|
200
|
+
sync hints stream (`GET /sync/hints`) behaved that way. Since 12.11.0 a stream whose credential is a Better-Auth session
|
|
201
|
+
or JWT is re-checked in place, like a WebSocket: the request's bearer token, `lt-jwt-token` cookie or session cookie is
|
|
202
|
+
authenticated again, and the stream ends only when user, roles, verification or tenant scope changed (log lines
|
|
203
|
+
"User authorization changed", "Session no longer valid", "Tenant access changed"). Streams on legacy JWTs or API tokens
|
|
204
|
+
keep ending on every re-check, as before.
|
|
205
|
+
|
|
206
|
+
A project with its own SSE stream registers it with `registerHttpStream({ … })` (`http-stream-auth.helper.ts`) to get
|
|
207
|
+
the same behaviour; `CoreSyncService.recheckHintStreamInPlace()` is the protected override point of the hints stream.
|
|
208
|
+
|
|
209
|
+
### Health check: readiness endpoint and project checks
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
healthCheck: {
|
|
213
|
+
configs: { database: { enabled: true }, build: { enabled: true } },
|
|
214
|
+
readiness: true, // GET /health-check/ready — or { checks: ['database'] }
|
|
215
|
+
},
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
- `GET /health-check/ready` runs the checks named in `readiness.checks` (default `['database', 'build']`, a list or a
|
|
219
|
+
comma-separated string) and answers `503` while one is down — and `shutting_down` from the first SIGTERM / SIGINT on
|
|
220
|
+
when `installGracefulShutdown(app)` handles the signals with a `shutdownDelayMs`, before that wait, so a load balancer
|
|
221
|
+
polling readiness drains the replica while it still serves. Without
|
|
222
|
+
`readiness` the route does not exist (404), and `GET /health-check` is unchanged. A project with a shutdown flow of
|
|
223
|
+
its own (a preStop hook, its own signal handler) calls the exported `markShutdownDraining()` at its start.
|
|
224
|
+
- A project adds checks of its own by extending `CoreHealthCheckService` and overriding the protected
|
|
225
|
+
`additionalHealthIndicators(kind: 'liveness' | 'readiness')`, registered with
|
|
226
|
+
`CoreModule.forRoot(env, { healthCheck: { service } })` (`readinessController` overrides the readiness controller).
|
|
227
|
+
|
|
228
|
+
## 8. Dependencies
|
|
229
|
+
|
|
230
|
+
12.11.0 declares NestJS 12.6.0. `pnpm run update` raises these pins where a nest-server-starter based project already
|
|
231
|
+
declares them:
|
|
232
|
+
|
|
233
|
+
| Package | From | To |
|
|
234
|
+
|---|---|---|
|
|
235
|
+
| `@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express`, `@nestjs/testing` | 12.5.1 | 12.6.0 |
|
|
236
|
+
| `@nestjs/cli` / `@nestjs/schematics` | 12.0.13 | 12.0.15 / 12.0.16 |
|
|
237
|
+
| `jose` | 6.2.17 | 6.2.18 |
|
|
238
|
+
| `nodemailer` | 10.6.0 | 10.6.1 |
|
|
239
|
+
| `mongoose` (MongoDB projects) | 9.12.2 | 9.12.3 |
|
|
240
|
+
|
|
241
|
+
Where declared, also the optional peers `bullmq` 6.7.8, `@aws-sdk/*` 3.1175.0 and `ai` 7.0.179. With NestJS 12.6.0 a
|
|
242
|
+
testing module's `createNestApplication()` applies its `logger` option like `NestFactory.create()` does, so an e2e
|
|
243
|
+
setup that passes `logger: true` (or a log level list) now logs. An override of a core handler declared with
|
|
244
|
+
`@Res({ passthrough: true })` (the IAM `signIn` / `signUp` / `signOut`, the sync routes) no longer inherits
|
|
245
|
+
`passthrough` when it re-declares a plain `@Res()`: its return value is no longer sent and the request hangs —
|
|
246
|
+
re-declare `@Res({ passthrough: true })`, as `INTEGRATION-CHECKLIST.md` shows.
|
|
247
|
+
|
|
248
|
+
**Keep `@apollo/server` at 5.5.1.** 5.5.2 caps `@graphql-tools/utils` below 12.0.2 (for Node 20) and brings back
|
|
249
|
+
GHSA-c4qx-w738-7hr3 (high); this package requires Node 22.15 or later and stays on 5.5.1.
|
|
250
|
+
|
|
251
|
+
**Refresh two transitive packages** of `@modelcontextprotocol/sdk` if your lockfile still holds older ones:
|
|
252
|
+
`@hono/node-server` 2.1.11 (GHSA-8wcc-wqxr-28qp, GHSA-qhm2-7mpr-ghjp) and `express-rate-limit` 8.7.5
|
|
253
|
+
(GHSA-cppf-2hm6-mrvm). Both sit inside the SDK's ranges; `pnpm update @hono/node-server express-rate-limit --depth
|
|
254
|
+
Infinity` lifts them. The advisories were published in the projects' own repositories, so `pnpm audit` may not report
|
|
255
|
+
them yet.
|
|
256
|
+
|
|
257
|
+
A project that mirrors this package's `minimatch@>=11.0.0 <11.0.9` override can drop it with `@nestjs/cli` 12.0.15,
|
|
258
|
+
which pins 11.0.9 itself.
|
|
259
|
+
|
|
260
|
+
## Compatibility Notes
|
|
261
|
+
|
|
262
|
+
| Pattern | Status |
|
|
263
|
+
|---|---|
|
|
264
|
+
| Frontends on `@lenne.tech/nuxt-extensions` / `@lenne.tech/ng-base` in cookie mode | Unaffected |
|
|
265
|
+
| The same frontends in JWT mode | One extra token fetch after the update and after enabling 2FA (handled on the 401); with `cookies: false` one sign-in after the update |
|
|
266
|
+
| A backend-to-backend client holding a JWT | Fetch `GET /iam/token` again on a 401; a JWT dies with its session |
|
|
267
|
+
| A project with `emailAndPassword.enabled: false` that uses Passkey / 2FA and signs in through a provider alone | Set `passkey: true` / `twoFactor: { …, enabled: true }` (§2); with `username()` / `phoneNumber()` nothing changes |
|
|
268
|
+
| A native app / Google One Tap sign-in | Set `disableIdTokenSignIn: false` on that provider (§3) |
|
|
269
|
+
| A project verifying Better-Auth JWTs with its own `jwtVerify()` | Use `CoreBetterAuthService.verifyJwtToken()` (§1) |
|
|
270
|
+
| A maintenance line (12.6.x, 11.x) | Not backported (behavior changes). The switches a project sets itself: `passkey: false` / `twoFactor: false` for SSO-only, `disableIdTokenSignIn: true` per provider, `jwt: false` (cookie mode) or a shorter `jwt.expiresIn` |
|
|
271
|
+
|
|
272
|
+
## Troubleshooting
|
|
273
|
+
|
|
274
|
+
| Symptom | Cause | Fix |
|
|
275
|
+
|---|---|---|
|
|
276
|
+
| Every JWT answers 401 right after the update | JWTs issued before 12.11.0 carry no session reference (§1) | Fetch a new one with the session (`GET /iam/token`); the frontend libraries do it on the 401. With `cookies: false` users sign in once more |
|
|
277
|
+
| 401 right after enabling 2FA in JWT mode | The first `verify-totp` replaced the session (§1) | Use the `token` of the `verify-totp` answer |
|
|
278
|
+
| Passkey or 2FA routes answer 404 | Sign-in through a provider alone: `emailAndPassword.enabled: false`, no plugin sign-in route (§2) | `passkey: true` / `twoFactor: { enabled: true }` |
|
|
279
|
+
| `ID_TOKEN_NOT_SUPPORTED` from a native app | Id token sign-in closed by default (§3) | `disableIdTokenSignIn: false` on that provider |
|
|
280
|
+
| `microsoft-sign-in-example.spec.ts` fails: `expected 'ID_TOKEN_NOT_SUPPORTED' not to be 'ID_TOKEN_NOT_SUPPORTED'` | The starter's test removes the option and expected an open path (§3) | Set `disableIdTokenSignIn: false` in that case instead of removing it |
|
|
281
|
+
| The start stops with `NSC__…ENABLED="…" is not a switch value` | An `enabled` variable holds neither `true`/`false` nor `1`/`0` (§4) | Write `true` or `false` |
|
|
282
|
+
| A feature configured as `NSC__…=` now uses its default instead of `0` | Empty values count as not set (§4) | Write the value you mean (`0`) |
|
|
283
|
+
| A generated client lost its type `Array` | Unnamed list enums stay inline (§5) | Regenerate the client; name the enum with `enumName` if you want a schema |
|
|
284
|
+
|
|
285
|
+
## Module Documentation
|
|
286
|
+
|
|
287
|
+
- `src/core/modules/better-auth/README.md` — "Sign-in through a provider alone", "Social providers"
|
|
288
|
+
- `src/core/modules/better-auth/INTEGRATION-CHECKLIST.md` — "Optional: Sign-in through a provider alone"
|
|
289
|
+
- `src/core/modules/better-auth/core-better-auth-jwt-session.cache.ts` — the session cache of JWTs
|
|
290
|
+
- `src/core/modules/better-auth/core-better-auth-sign-in-factors.helper.ts` — when Passkey and two-factor are on
|
|
291
|
+
- `src/core/common/helpers/config.helper.ts` — `getEnvironmentObject()`
|
|
292
|
+
- `.claude/rules/better-auth.md` — §12 "A Better-Auth JWT is bound to its session"
|
|
293
|
+
- `src/core/common/services/core-cron-jobs.service.ts` — `rescheduleCronJob()`
|
|
294
|
+
- `src/core/common/helpers/http-stream-auth.helper.ts` — SSE streams re-checked in place
|
|
295
|
+
- `src/core/modules/health-check/core-health-check.service.ts` — `additionalHealthIndicators()`, readiness
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Server framework in TypeScript on top of NestJS: GraphQL and REST APIs on MongoDB, PostgreSQL, MySQL or MariaDB, with authentication, field-level permissions, multi-tenancy, offline sync and an AI assistant.",
|
|
6
6
|
"keywords": [
|
|
@@ -107,12 +107,12 @@
|
|
|
107
107
|
"@getbrevo/brevo": "6.2.0",
|
|
108
108
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
109
109
|
"@nestjs/apollo": "14.2.1",
|
|
110
|
-
"@nestjs/common": "12.
|
|
111
|
-
"@nestjs/core": "12.
|
|
110
|
+
"@nestjs/common": "12.6.0",
|
|
111
|
+
"@nestjs/core": "12.6.0",
|
|
112
112
|
"@nestjs/graphql": "14.2.1",
|
|
113
113
|
"@nestjs/jwt": "12.0.5",
|
|
114
114
|
"@nestjs/passport": "12.0.2",
|
|
115
|
-
"@nestjs/platform-express": "12.
|
|
115
|
+
"@nestjs/platform-express": "12.6.0",
|
|
116
116
|
"@nestjs/schedule": "12.0.4",
|
|
117
117
|
"@nestjs/swagger": "12.1.2",
|
|
118
118
|
"@nestjs/terminus": "12.2.0",
|
|
@@ -136,13 +136,13 @@
|
|
|
136
136
|
"graphql-upload": "17.1.0",
|
|
137
137
|
"graphql-ws": "6.4.1",
|
|
138
138
|
"http-errors": "2.0.1",
|
|
139
|
-
"jose": "6.2.
|
|
139
|
+
"jose": "6.2.18",
|
|
140
140
|
"js-sha256": "1.1.0",
|
|
141
141
|
"json-to-graphql-query": "2.3.0",
|
|
142
142
|
"lodash": "4.18.1",
|
|
143
143
|
"multer": "2.5.0",
|
|
144
144
|
"node-mailjet": "6.0.11",
|
|
145
|
-
"nodemailer": "10.6.
|
|
145
|
+
"nodemailer": "10.6.1",
|
|
146
146
|
"object-path": "0.11.8",
|
|
147
147
|
"passport": "0.7.0",
|
|
148
148
|
"passport-jwt": "4.0.1",
|
|
@@ -244,20 +244,20 @@
|
|
|
244
244
|
}
|
|
245
245
|
},
|
|
246
246
|
"devDependencies": {
|
|
247
|
-
"@aws-sdk/client-s3": "3.
|
|
248
|
-
"@aws-sdk/lib-storage": "3.
|
|
249
|
-
"@aws-sdk/s3-request-presigner": "3.
|
|
247
|
+
"@aws-sdk/client-s3": "3.1175.0",
|
|
248
|
+
"@aws-sdk/lib-storage": "3.1175.0",
|
|
249
|
+
"@aws-sdk/s3-request-presigner": "3.1175.0",
|
|
250
250
|
"@better-auth/core": "1.7.23",
|
|
251
251
|
"@better-auth/passkey": "1.7.23",
|
|
252
252
|
"@compodoc/compodoc": "2.0.0",
|
|
253
253
|
"@modelcontextprotocol/server": "2.4.0",
|
|
254
254
|
"@nestjs/ai": "0.0.2",
|
|
255
|
-
"@nestjs/cli": "12.0.
|
|
255
|
+
"@nestjs/cli": "12.0.15",
|
|
256
256
|
"@nestjs/mcp": "0.0.4",
|
|
257
257
|
"@nestjs/mongoose": "12.0.1",
|
|
258
258
|
"@nestjs/resilience": "0.0.3",
|
|
259
|
-
"@nestjs/schematics": "12.0.
|
|
260
|
-
"@nestjs/testing": "12.
|
|
259
|
+
"@nestjs/schematics": "12.0.16",
|
|
260
|
+
"@nestjs/testing": "12.6.0",
|
|
261
261
|
"@swc/cli": "0.8.2",
|
|
262
262
|
"@swc/core": "1.16.22",
|
|
263
263
|
"@tus/s3-store": "2.1.0",
|
|
@@ -274,25 +274,25 @@
|
|
|
274
274
|
"@types/passport": "1.0.17",
|
|
275
275
|
"@types/pg": "8.23.1",
|
|
276
276
|
"@vitest/coverage-v8": "5.1.1",
|
|
277
|
-
"ai": "7.0.
|
|
277
|
+
"ai": "7.0.179",
|
|
278
278
|
"better-auth": "1.7.23",
|
|
279
|
-
"bullmq": "6.7.
|
|
279
|
+
"bullmq": "6.7.8",
|
|
280
280
|
"cross-env": "10.1.0",
|
|
281
281
|
"drizzle-orm": "1.0.0-rc.5",
|
|
282
282
|
"ioredis": "6.0.0",
|
|
283
283
|
"kysely": "0.29.9",
|
|
284
284
|
"mongodb": "7.8.0",
|
|
285
|
-
"mongoose": "9.12.
|
|
285
|
+
"mongoose": "9.12.3",
|
|
286
286
|
"mysql2": "3.24.6",
|
|
287
287
|
"nodemon": "3.1.14",
|
|
288
288
|
"otpauth": "9.6.0",
|
|
289
289
|
"oxfmt": "0.79.0",
|
|
290
290
|
"oxlint": "1.94.0",
|
|
291
|
-
"oxlint-tsgolint": "7.0.
|
|
291
|
+
"oxlint-tsgolint": "7.0.2008",
|
|
292
292
|
"pg": "8.23.1",
|
|
293
293
|
"playwright-core": "1.65.1",
|
|
294
294
|
"rimraf": "6.1.4",
|
|
295
|
-
"smtp-server": "3.21.
|
|
295
|
+
"smtp-server": "3.21.7",
|
|
296
296
|
"tsx": "4.23.15",
|
|
297
297
|
"tus-js-client": "4.3.1",
|
|
298
298
|
"typeorm": "1.1.3",
|
|
@@ -693,16 +693,18 @@ function getEnumName(enumObj: any): string | undefined {
|
|
|
693
693
|
return enumObj.name;
|
|
694
694
|
}
|
|
695
695
|
|
|
696
|
-
// Check if it's a constructor function with a name
|
|
697
|
-
if (typeof enumObj === 'function' && enumObj.name && enumObj
|
|
696
|
+
// Check if it's a constructor function with a name — never a built-in one (`Array`, `String`, …)
|
|
697
|
+
if (typeof enumObj === 'function' && enumObj.name && !isBuiltInConstructor(enumObj)) {
|
|
698
698
|
return enumObj.name;
|
|
699
699
|
}
|
|
700
700
|
|
|
701
701
|
// For regular TypeScript enums, try to find the global variable name
|
|
702
702
|
// This is a heuristic approach - not guaranteed to work in all cases
|
|
703
703
|
if (enumObj && typeof enumObj === 'object') {
|
|
704
|
-
// Check constructor name (though this usually returns 'Object' for enums)
|
|
705
|
-
|
|
704
|
+
// Check constructor name (though this usually returns 'Object' for enums). A list of values has the constructor
|
|
705
|
+
// `Array`: until 12.11.0 every unnamed list enum of a project became one OpenAPI schema `Array`, and a client
|
|
706
|
+
// generated from the document declared `export type Array = …`, shadowing the built-in type (12.11.0)
|
|
707
|
+
if (enumObj.constructor && enumObj.constructor.name && !isBuiltInConstructor(enumObj.constructor)) {
|
|
706
708
|
return enumObj.constructor.name;
|
|
707
709
|
}
|
|
708
710
|
}
|
|
@@ -710,6 +712,14 @@ function getEnumName(enumObj: any): string | undefined {
|
|
|
710
712
|
return undefined;
|
|
711
713
|
}
|
|
712
714
|
|
|
715
|
+
/**
|
|
716
|
+
* Whether `fn` is a built-in constructor (`Object`, `Array`, `String`, `Map`, …): the global binding of its name is the
|
|
717
|
+
* function itself. Its name is never an enum's name.
|
|
718
|
+
*/
|
|
719
|
+
function isBuiltInConstructor(fn: unknown): boolean {
|
|
720
|
+
return typeof fn === 'function' && !!fn.name && (globalThis as Record<string, unknown>)[fn.name] === fn;
|
|
721
|
+
}
|
|
722
|
+
|
|
713
723
|
function isGraphQLScalar(type: any): boolean {
|
|
714
724
|
// CustomScalar check (The CustomScalar interface implements these functions below)
|
|
715
725
|
return (
|
|
@@ -196,7 +196,55 @@ export function getEnvironmentConfig(options: { config?: Record<string, any>; de
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
*
|
|
199
|
+
* Converts one `NSC__…` value (see {@link getEnvironmentObject}). `key` names the variable in the error, `segment` is
|
|
200
|
+
* the last segment of its path.
|
|
201
|
+
*/
|
|
202
|
+
function prepareEnvironmentValue(
|
|
203
|
+
key: string,
|
|
204
|
+
segment: string,
|
|
205
|
+
value: boolean | number | string,
|
|
206
|
+
): boolean | number | string {
|
|
207
|
+
if (typeof value !== 'string') {
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
const trimmed = value.trim();
|
|
211
|
+
const lower = trimmed.toLowerCase();
|
|
212
|
+
if (lower === 'true') {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
if (lower === 'false') {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
if (segment === 'enabled') {
|
|
219
|
+
if (trimmed === '1') {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
if (trimmed === '0') {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
throw new Error(
|
|
226
|
+
`${key}="${value}" is not a switch value: write true or false (1 or 0 work too). ` +
|
|
227
|
+
'Before 12.11.0 any other text counted as switched on.',
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
if (!isNaN(Number(value))) {
|
|
231
|
+
return Number(value);
|
|
232
|
+
}
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get environment object from environment variables (`NSC__…`).
|
|
238
|
+
*
|
|
239
|
+
* Values, since 12.11.0:
|
|
240
|
+
* - an empty value (or one of spaces only) counts as NOT SET — the entry is left out, and so are the objects of its
|
|
241
|
+
* path. Before, `NSC__X__ENABLED=` became `0`, which every `enabled !== false` check reads as on, and
|
|
242
|
+
* `NSC__REDIS__HOST=` would have created `redis: {}`, which switches Redis on;
|
|
243
|
+
* - `true` / `false` in any case and with surrounding spaces become booleans (before: only exactly `true` / `false`;
|
|
244
|
+
* `FALSE` stayed text and switched a feature ON);
|
|
245
|
+
* - a key named `enabled` takes only `true`, `false`, `1` or `0` and refuses anything else with an error, so a
|
|
246
|
+
* misspelled off switch (`off`, `no`) stops the start instead of leaving the feature on;
|
|
247
|
+
* - anything `Number()` reads becomes a number, everything else stays text.
|
|
200
248
|
*/
|
|
201
249
|
export function getEnvironmentObject(options?: {
|
|
202
250
|
prefix?: string;
|
|
@@ -212,6 +260,11 @@ export function getEnvironmentObject(options?: {
|
|
|
212
260
|
Object.entries(config.processEnv)
|
|
213
261
|
.filter(([key]) => key.startsWith(config.prefix))
|
|
214
262
|
.forEach(([key, value]) => {
|
|
263
|
+
// An empty value counts as not set: no entry, and no objects along its path (12.11.0)
|
|
264
|
+
if (typeof value === 'string' && value.trim() === '') {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
215
268
|
// Remove prefix from key
|
|
216
269
|
const adjustedKey = key.slice(config.prefix?.length || 0);
|
|
217
270
|
|
|
@@ -229,13 +282,7 @@ export function getEnvironmentObject(options?: {
|
|
|
229
282
|
const segment = path[i];
|
|
230
283
|
if (i === path.length - 1) {
|
|
231
284
|
// value preparation
|
|
232
|
-
|
|
233
|
-
value = true;
|
|
234
|
-
} else if (value === 'false') {
|
|
235
|
-
value = false;
|
|
236
|
-
} else if (!isNaN(Number(value))) {
|
|
237
|
-
value = Number(value);
|
|
238
|
-
}
|
|
285
|
+
value = prepareEnvironmentValue(key, segment, value);
|
|
239
286
|
|
|
240
287
|
current[segment] = value;
|
|
241
288
|
} else {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { INestApplication, Logger } from '@nestjs/common';
|
|
2
2
|
|
|
3
3
|
import { ConfigService } from '../services/config.service.js';
|
|
4
|
+
import { markShutdownDraining } from './shutdown-state.helper.js';
|
|
4
5
|
|
|
5
6
|
/** Signals an orchestrator uses to ask a container to stop */
|
|
6
7
|
const SHUTDOWN_SIGNALS: NodeJS.Signals[] = ['SIGTERM', 'SIGINT'];
|
|
@@ -41,8 +42,10 @@ const SHUTDOWN_DELAY_ADVISORY_MS = 10_000;
|
|
|
41
42
|
*
|
|
42
43
|
* **What the delay is for.** An orchestrator sends SIGTERM and deregisters the instance from the
|
|
43
44
|
* load balancer at the same moment, but deregistration propagates asynchronously — for a beat,
|
|
44
|
-
* requests still arrive.
|
|
45
|
-
*
|
|
45
|
+
* requests still arrive. Serving through that beat is what lets them be answered instead of
|
|
46
|
+
* dropped. The readiness check (`GET /health-check/ready`, 12.11.0) answers 503 from the signal on
|
|
47
|
+
* (`markShutdownDraining()`), so a load balancer that polls readiness deregisters the instance
|
|
48
|
+
* during the wait instead of after it; liveness stays healthy, so nothing restarts it.
|
|
46
49
|
*
|
|
47
50
|
* Without a configured delay this is exactly `app.enableShutdownHooks()`, which is what the
|
|
48
51
|
* framework did before.
|
|
@@ -105,7 +108,11 @@ export function installGracefulShutdown<T extends INestApplication>(app: T): T {
|
|
|
105
108
|
return;
|
|
106
109
|
}
|
|
107
110
|
shuttingDown = true;
|
|
108
|
-
|
|
111
|
+
// Readiness answers 503 from here on (GET /health-check/ready), liveness stays healthy (12.11.0)
|
|
112
|
+
markShutdownDraining();
|
|
113
|
+
logger.log(
|
|
114
|
+
`${signal} received — serving for ${effectiveDelayMs}ms more, readiness answers 503, so the load balancer can deregister`,
|
|
115
|
+
);
|
|
109
116
|
|
|
110
117
|
timer = setTimeout(() => {
|
|
111
118
|
app
|