@lenne.tech/nest-server 12.10.1 → 12.11.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/.claude/rules/better-auth.md +28 -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 +6 -1
- 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-api.middleware.js +7 -3
- package/dist/core/modules/better-auth/core-better-auth-api.middleware.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-session-token.helper.d.ts +1 -0
- package/dist/core/modules/better-auth/core-better-auth-session-token.helper.js +3 -1
- package/dist/core/modules/better-auth/core-better-auth-session-token.helper.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 +3 -2
- 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 +16 -2
- package/dist/core/modules/better-auth/core-better-auth.service.js +109 -22
- 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/.navigation.yml +4 -0
- package/docs/REQUEST-LIFECYCLE.md +8 -5
- package/docs/choosing-a-database.md +4 -1
- package/docs/error-codes.md +4 -1
- package/docs/index.md +34 -0
- package/docs/{brevo-manual-test.md → internal/brevo-manual-test.md} +1 -1
- package/docs/native-driver-security.md +4 -1
- package/docs/offline-sync-protocol.md +9 -4
- package/docs/process-performance-optimization.md +158 -126
- package/docs/security-overrides.md +5 -2
- package/migration-guides/12.10.x-to-12.11.x.md +297 -0
- package/migration-guides/12.11.0-to-12.11.1.md +86 -0
- package/package.json +20 -20
- 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 +27 -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 +8 -4
- 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-session-token.helper.ts +18 -1
- 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 +7 -4
- 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 +177 -31
- 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
|
@@ -0,0 +1,297 @@
|
|
|
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
|
+
| Disabling 2FA (`POST /iam/two-factor/disable`); enabling it with `method: 'otp'` or `skipVerificationOnEnable` | Better-Auth replaces the session; the old JWT answers `401`. **Since 12.11.1** the answer carries `token`, the JWT of the new session (`{ status: true, token }`, `{ method: 'otp', token }`). 12.11.0 answered without it, so with `cookies: false` turning 2FA off signed the user out | Update to 12.11.1; a JWT client continues with that `token`, like after `verify-totp` |
|
|
57
|
+
| Several devices | Each JWT follows its own session; signing out one leaves the others signed in | — |
|
|
58
|
+
|
|
59
|
+
A JWT is still verified without a call to the identity provider, and the session check costs at most one lookup per
|
|
60
|
+
session and 10 seconds per replica. Before 12.11.0 the middleware looked up the user's newest session on every JWT
|
|
61
|
+
request; that lookup is gone.
|
|
62
|
+
|
|
63
|
+
**A project that verifies Better-Auth JWTs itself** (`jwtVerify()` against the JWKS) checks the signature only — call
|
|
64
|
+
`CoreBetterAuthService.verifyJwtToken()` instead, which checks the session.
|
|
65
|
+
|
|
66
|
+
## 2. Breaking (security): Passkey and two-factor follow e-mail and password sign-in
|
|
67
|
+
|
|
68
|
+
**Who is affected:** projects that sign in through a single sign-on provider alone —
|
|
69
|
+
`betterAuth.emailAndPassword.enabled: false` and no plugin of the project with a sign-in route of its own. A project
|
|
70
|
+
that signs in by username or phone number (`username()`, `phoneNumber()` in `betterAuth.plugins`) keeps both on, since
|
|
71
|
+
two-factor is what enforces the second factor on those routes. Every other project keeps both on, as before.
|
|
72
|
+
|
|
73
|
+
Passkey and two-factor were on whatever `emailAndPassword` said. Whoever signed in through Microsoft once and registered
|
|
74
|
+
a passkey kept signing in with it after Entra withdrew the assignment: the provider no longer decided who gets in.
|
|
75
|
+
|
|
76
|
+
Since 12.11.0 both are off while sign-in runs through a provider alone. Their routes answer `404`, also for a passkey
|
|
77
|
+
registered earlier, and `GET /iam/features` reports `passkey: false` / `twoFactor: false`. The boot names what it
|
|
78
|
+
switched off — as a warning when the factor carried settings of its own (`twoFactor: { appName }`). To keep one
|
|
79
|
+
deliberately:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
betterAuth: {
|
|
83
|
+
emailAndPassword: { enabled: false },
|
|
84
|
+
passkey: true, // or { enabled: true, rpName: '…' }
|
|
85
|
+
twoFactor: { appName: 'My App', enabled: true },
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
An object without `enabled: true` (a `twoFactor: { appName }` kept from a password setup) does not switch it on.
|
|
90
|
+
|
|
91
|
+
`GET /iam/features` (and the GraphQL `betterAuthFeatures`) report `emailAndPassword` since 12.11.0, so a login page
|
|
92
|
+
can hide the e-mail form instead of subclassing the controller for it.
|
|
93
|
+
|
|
94
|
+
## 3. Breaking (security): no sign-in with a client-submitted id token
|
|
95
|
+
|
|
96
|
+
`POST /iam/sign-in/social` accepts `{ provider, idToken: { token } }`: the client submits the provider's id token, and
|
|
97
|
+
Better-Auth checks its signature, audience and expiry — and asks the provider nothing. `GET /iam/list-accounts` and
|
|
98
|
+
`POST /iam/get-access-token` hand a signed-in user the id token of their last sign-in, so within its lifetime (about an
|
|
99
|
+
hour at Microsoft) that token signed its owner in again after Entra had withdrawn the app role or the assignment. Proven
|
|
100
|
+
end to end against a mock of the Entra endpoints.
|
|
101
|
+
|
|
102
|
+
Since 12.11.0 every social provider gets `disableIdTokenSignIn: true` unless the project sets it to `false`. Such a
|
|
103
|
+
request answers `ID_TOKEN_NOT_SUPPORTED`, on `/iam/link-social` too. The redirect flow (`signIn.social` with a
|
|
104
|
+
`callbackURL`, what the lenne.Tech frontends use) never uses this path and keeps working.
|
|
105
|
+
|
|
106
|
+
**Native apps and Google One Tap** send the provider's id token themselves. Open it for that provider:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
betterAuth: {
|
|
110
|
+
socialProviders: {
|
|
111
|
+
google: { clientId, clientSecret, disableIdTokenSignIn: false },
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Only the boolean `false` opens it; any other value keeps it closed. nest-server-starter's Microsoft example sets
|
|
117
|
+
`disableIdTokenSignIn: true` since 12.10.1 — that line can stay, it states the default now.
|
|
118
|
+
|
|
119
|
+
**Projects created from nest-server-starter 12.10.1 or later** carry `tests/unit/microsoft-sign-in-example.spec.ts`.
|
|
120
|
+
Its third case removes the option and expects the id token to be verified, so after the update it fails with
|
|
121
|
+
`expected 'ID_TOKEN_NOT_SUPPORTED' not to be 'ID_TOKEN_NOT_SUPPORTED'`. Open the path explicitly there, as the starter
|
|
122
|
+
does:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
it('would verify a submitted ID token with the option set to false, so the option is what closes the path', async () => {
|
|
126
|
+
const code = await idTokenSignInCode({ ...EXAMPLE, disableIdTokenSignIn: false });
|
|
127
|
+
expect(code).toBeDefined();
|
|
128
|
+
expect(code).not.toBe('ID_TOKEN_NOT_SUPPORTED');
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 4. Breaking: `NSC__` environment values
|
|
133
|
+
|
|
134
|
+
Deployments set the configuration through `NSC__…` variables. Two ways of writing an off switch left the feature on:
|
|
135
|
+
|
|
136
|
+
| Variable | Up to 12.10.x | Since 12.11.0 |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `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) |
|
|
139
|
+
| `NSC__X__ENABLED=FALSE`, `=False`, `= false ` | the text `"FALSE"` — **on** | `false` |
|
|
140
|
+
| `NSC__X__ENABLED=0` / `=1` | `0` / `1` — both **on** | `false` / `true` |
|
|
141
|
+
| `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)` |
|
|
142
|
+
| `NSC__X__ROLE=` | `"0"` | not set |
|
|
143
|
+
| any other key: `TRUE`, `True` | text | `true` |
|
|
144
|
+
| numbers, other text | unchanged | unchanged |
|
|
145
|
+
|
|
146
|
+
**Check before updating:** `env | grep '^NSC__'` on each stage. Empty variables now leave the default in place instead
|
|
147
|
+
of `0`; a key named `ENABLED` with any value but `true`, `false`, `1` or `0` must be corrected, or the service does not
|
|
148
|
+
start. A text value that must stay exactly `TRUE` or `False` (a password, say) is now a boolean — pass it through
|
|
149
|
+
`NEST_SERVER_CONFIG` or `config.env.ts` instead (exactly `true` / `false` were converted before as well).
|
|
150
|
+
|
|
151
|
+
## 5. Breaking: unnamed list enums in the OpenAPI document
|
|
152
|
+
|
|
153
|
+
`@UnifiedField({ enum: ['red', 'green'] })` without `enumName` named its OpenAPI schema after the list's constructor:
|
|
154
|
+
`Array`. Every such field of a project shared that one schema, and a client generated from the document declared
|
|
155
|
+
`export type Array = …`, shadowing the built-in type (36 type errors in one project).
|
|
156
|
+
|
|
157
|
+
Since 12.11.0 such an enum stays inline (`{ "enum": ["red", "green"] }`), as an unregistered TypeScript enum does, and
|
|
158
|
+
no schema is named after a built-in type. **Regenerate API clients** (e.g. `pnpm run generate-types` in an app): a
|
|
159
|
+
type `Array` disappears, fields that used it carry their own values. To keep a named schema, set `enumName` on the
|
|
160
|
+
field or register the enum with `registerEnum()`.
|
|
161
|
+
|
|
162
|
+
## 6. New: a fixed session lifetime (`betterAuth.session`)
|
|
163
|
+
|
|
164
|
+
Better-Auth's sessions last 7 days and are extended once a day while they are used — a session used every day never
|
|
165
|
+
ends, and a withdrawal at the sign-in provider never reaches it. A project that wants the provider to be asked again
|
|
166
|
+
after a fixed time:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
betterAuth: {
|
|
170
|
+
session: { expiresInHours: 8, extendOnUse: false }, // sign in again after 8 hours, every time
|
|
171
|
+
},
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
| Option | Maps to | Default |
|
|
175
|
+
|---|---|---|
|
|
176
|
+
| `expiresInHours` | Better-Auth's `session.expiresIn` (seconds) | 168 (7 days) |
|
|
177
|
+
| `extendOnUse: false` | `session.disableSessionRefresh: true` | extended once a day of use |
|
|
178
|
+
|
|
179
|
+
A value of `expiresInHours` that is not a positive number is ignored with a warning (never "unlimited").
|
|
180
|
+
`betterAuth.options.session` still wins key by key.
|
|
181
|
+
|
|
182
|
+
## 7. New: cron schedules at runtime, SSE streams re-checked in place, health readiness
|
|
183
|
+
|
|
184
|
+
### `CoreCronJobs.rescheduleCronJob(name, schedule)`
|
|
185
|
+
|
|
186
|
+
Changes the schedule of a registered job without touching protected internals: a cron expression, a date,
|
|
187
|
+
`{ cronTime, timeZone }` or `{ cronTime, utcOffset }` (type `CronJobSchedule`). Only the schedule changes —
|
|
188
|
+
`distributed`, `runParallel`, the leases and `bullJobOptions` stay; `runOnInit` is not repeated. An invalid expression,
|
|
189
|
+
an unknown time zone, a date in the past or an unregistered job rejects and leaves the job as it was.
|
|
190
|
+
|
|
191
|
+
- **BullMQ** (with `redis`): the scheduler in Redis changes for the whole fleet; calling it on every replica is safe.
|
|
192
|
+
- **Local timer**: changes on the calling replica only — call it on every replica (from the settings change each one
|
|
193
|
+
observes, and at startup).
|
|
194
|
+
- A reschedule is not stored: the next bootstrap schedules from the configuration again, so a project re-applies a
|
|
195
|
+
stored schedule after `super.onApplicationBootstrap()`.
|
|
196
|
+
|
|
197
|
+
### SSE streams keep running while the rights are unchanged
|
|
198
|
+
|
|
199
|
+
A Server-Sent Events stream registered for re-checks (`endsOnRecheck`) ENDED on the first event after
|
|
200
|
+
`graphQl.subscriptionRevalidationMs`, and the client received that event only after reconnecting (about 3 s later). The
|
|
201
|
+
sync hints stream (`GET /sync/hints`) behaved that way. Since 12.11.0 a stream whose credential is a Better-Auth session
|
|
202
|
+
or JWT is re-checked in place, like a WebSocket: the request's bearer token, `lt-jwt-token` cookie or session cookie is
|
|
203
|
+
authenticated again, and the stream ends only when user, roles, verification or tenant scope changed (log lines
|
|
204
|
+
"User authorization changed", "Session no longer valid", "Tenant access changed"). Streams on legacy JWTs or API tokens
|
|
205
|
+
keep ending on every re-check, as before.
|
|
206
|
+
|
|
207
|
+
A project with its own SSE stream registers it with `registerHttpStream({ … })` (`http-stream-auth.helper.ts`) to get
|
|
208
|
+
the same behaviour; `CoreSyncService.recheckHintStreamInPlace()` is the protected override point of the hints stream.
|
|
209
|
+
|
|
210
|
+
### Health check: readiness endpoint and project checks
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
healthCheck: {
|
|
214
|
+
configs: { database: { enabled: true }, build: { enabled: true } },
|
|
215
|
+
readiness: true, // GET /health-check/ready — or { checks: ['database'] }
|
|
216
|
+
},
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
- `GET /health-check/ready` runs the checks named in `readiness.checks` (default `['database', 'build']`, a list or a
|
|
220
|
+
comma-separated string) and answers `503` while one is down — and `shutting_down` from the first SIGTERM / SIGINT on
|
|
221
|
+
when `installGracefulShutdown(app)` handles the signals with a `shutdownDelayMs`, before that wait, so a load balancer
|
|
222
|
+
polling readiness drains the replica while it still serves. Without
|
|
223
|
+
`readiness` the route does not exist (404), and `GET /health-check` is unchanged. A project with a shutdown flow of
|
|
224
|
+
its own (a preStop hook, its own signal handler) calls the exported `markShutdownDraining()` at its start.
|
|
225
|
+
- A project adds checks of its own by extending `CoreHealthCheckService` and overriding the protected
|
|
226
|
+
`additionalHealthIndicators(kind: 'liveness' | 'readiness')`, registered with
|
|
227
|
+
`CoreModule.forRoot(env, { healthCheck: { service } })` (`readinessController` overrides the readiness controller).
|
|
228
|
+
|
|
229
|
+
## 8. Dependencies
|
|
230
|
+
|
|
231
|
+
12.11.0 declares NestJS 12.6.0. `pnpm run update` raises these pins where a nest-server-starter based project already
|
|
232
|
+
declares them:
|
|
233
|
+
|
|
234
|
+
| Package | From | To |
|
|
235
|
+
|---|---|---|
|
|
236
|
+
| `@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express`, `@nestjs/testing` | 12.5.1 | 12.6.0 |
|
|
237
|
+
| `@nestjs/cli` / `@nestjs/schematics` | 12.0.13 | 12.0.15 / 12.0.16 |
|
|
238
|
+
| `jose` | 6.2.17 | 6.2.18 |
|
|
239
|
+
| `nodemailer` | 10.6.0 | 10.6.1 |
|
|
240
|
+
| `mongoose` (MongoDB projects) | 9.12.2 | 9.12.3 |
|
|
241
|
+
|
|
242
|
+
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
|
|
243
|
+
testing module's `createNestApplication()` applies its `logger` option like `NestFactory.create()` does, so an e2e
|
|
244
|
+
setup that passes `logger: true` (or a log level list) now logs. An override of a core handler declared with
|
|
245
|
+
`@Res({ passthrough: true })` (the IAM `signIn` / `signUp` / `signOut`, the sync routes) no longer inherits
|
|
246
|
+
`passthrough` when it re-declares a plain `@Res()`: its return value is no longer sent and the request hangs —
|
|
247
|
+
re-declare `@Res({ passthrough: true })`, as `INTEGRATION-CHECKLIST.md` shows.
|
|
248
|
+
|
|
249
|
+
**Keep `@apollo/server` at 5.5.1.** 5.5.2 caps `@graphql-tools/utils` below 12.0.2 (for Node 20) and brings back
|
|
250
|
+
GHSA-c4qx-w738-7hr3 (high); this package requires Node 22.15 or later and stays on 5.5.1.
|
|
251
|
+
|
|
252
|
+
**Refresh two transitive packages** of `@modelcontextprotocol/sdk` if your lockfile still holds older ones:
|
|
253
|
+
`@hono/node-server` 2.1.11 (GHSA-8wcc-wqxr-28qp, GHSA-qhm2-7mpr-ghjp) and `express-rate-limit` 8.7.5
|
|
254
|
+
(GHSA-cppf-2hm6-mrvm). Both sit inside the SDK's ranges; `pnpm update @hono/node-server express-rate-limit --depth
|
|
255
|
+
Infinity` lifts them. The advisories were published in the projects' own repositories, so `pnpm audit` may not report
|
|
256
|
+
them yet.
|
|
257
|
+
|
|
258
|
+
A project that mirrors this package's `minimatch@>=11.0.0 <11.0.9` override can drop it with `@nestjs/cli` 12.0.15,
|
|
259
|
+
which pins 11.0.9 itself.
|
|
260
|
+
|
|
261
|
+
## Compatibility Notes
|
|
262
|
+
|
|
263
|
+
| Pattern | Status |
|
|
264
|
+
|---|---|
|
|
265
|
+
| Frontends on `@lenne.tech/nuxt-extensions` / `@lenne.tech/ng-base` in cookie mode | Unaffected |
|
|
266
|
+
| 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 |
|
|
267
|
+
| A backend-to-backend client holding a JWT | Fetch `GET /iam/token` again on a 401; a JWT dies with its session |
|
|
268
|
+
| 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 |
|
|
269
|
+
| A native app / Google One Tap sign-in | Set `disableIdTokenSignIn: false` on that provider (§3) |
|
|
270
|
+
| A project verifying Better-Auth JWTs with its own `jwtVerify()` | Use `CoreBetterAuthService.verifyJwtToken()` (§1) |
|
|
271
|
+
| 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` |
|
|
272
|
+
|
|
273
|
+
## Troubleshooting
|
|
274
|
+
|
|
275
|
+
| Symptom | Cause | Fix |
|
|
276
|
+
|---|---|---|
|
|
277
|
+
| 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 |
|
|
278
|
+
| 401 right after enabling 2FA in JWT mode | The first `verify-totp` replaced the session (§1) | Use the `token` of the `verify-totp` answer |
|
|
279
|
+
| Signed out right after turning 2FA off in JWT mode (`cookies: false`) | `two-factor/disable` replaced the session, and 12.11.0 answered without the new JWT (§1) | Update to 12.11.1 and use the `token` of the answer |
|
|
280
|
+
| 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 }` |
|
|
281
|
+
| `ID_TOKEN_NOT_SUPPORTED` from a native app | Id token sign-in closed by default (§3) | `disableIdTokenSignIn: false` on that provider |
|
|
282
|
+
| `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 |
|
|
283
|
+
| 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` |
|
|
284
|
+
| 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`) |
|
|
285
|
+
| 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 |
|
|
286
|
+
|
|
287
|
+
## Module Documentation
|
|
288
|
+
|
|
289
|
+
- `src/core/modules/better-auth/README.md` — "Sign-in through a provider alone", "Social providers"
|
|
290
|
+
- `src/core/modules/better-auth/INTEGRATION-CHECKLIST.md` — "Optional: Sign-in through a provider alone"
|
|
291
|
+
- `src/core/modules/better-auth/core-better-auth-jwt-session.cache.ts` — the session cache of JWTs
|
|
292
|
+
- `src/core/modules/better-auth/core-better-auth-sign-in-factors.helper.ts` — when Passkey and two-factor are on
|
|
293
|
+
- `src/core/common/helpers/config.helper.ts` — `getEnvironmentObject()`
|
|
294
|
+
- `.claude/rules/better-auth.md` — §12 "A Better-Auth JWT is bound to its session"
|
|
295
|
+
- `src/core/common/services/core-cron-jobs.service.ts` — `rescheduleCronJob()`
|
|
296
|
+
- `src/core/common/helpers/http-stream-auth.helper.ts` — SSE streams re-checked in place
|
|
297
|
+
- `src/core/modules/health-check/core-health-check.service.ts` — `additionalHealthIndicators()`, readiness
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Migration Guide: 12.11.0 → 12.11.1
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | None |
|
|
8
|
+
| **New Features** | None |
|
|
9
|
+
| **Bugfixes** | Turning two-factor authentication off no longer signs out a client that holds a JWT alone (`cookies: false`): the answer of `POST /iam/two-factor/disable` carries the JWT of the new session (§1) |
|
|
10
|
+
| **Security** | MongoDB driver 7.9.1 (three medium advisories, §2) |
|
|
11
|
+
| **Migration Effort** | Package update (`pnpm run update` raises the MongoDB driver pins). JWT clients store the `token` of the disable answer, as they do after `verify-totp` |
|
|
12
|
+
|
|
13
|
+
## Quick Migration
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @lenne.tech/nest-server@12.11.1
|
|
17
|
+
pnpm run update # nest-server-starter based projects
|
|
18
|
+
pnpm run build
|
|
19
|
+
pnpm test
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual.
|
|
23
|
+
|
|
24
|
+
## 1. Bugfix: two-factor disable answers with the JWT of the new session
|
|
25
|
+
|
|
26
|
+
**No backend action needed.** A JWT client takes the new `token` from the answer.
|
|
27
|
+
|
|
28
|
+
Since 12.11.0 a Better-Auth JWT is bound to the session it was issued from (see the 12.10.x → 12.11.x guide, §1).
|
|
29
|
+
Better-Auth replaces the session on these routes: it creates a new one, sets its cookie and deletes the request's
|
|
30
|
+
session.
|
|
31
|
+
|
|
32
|
+
| Route | Answer in 12.11.0 | Answer since 12.11.1, where the body carries a token |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `POST /iam/two-factor/disable` | `{ status: true }` | `{ status: true, token }` |
|
|
35
|
+
| `POST /iam/two-factor/enable` with `method: 'otp'` | `{ method: 'otp' }` | `{ method: 'otp', token }` |
|
|
36
|
+
| `POST /iam/two-factor/enable` with `skipVerificationOnEnable` | `{ method: 'totp', totpURI, backupCodes }` | the same plus `token` |
|
|
37
|
+
| `POST /iam/two-factor/verify-totp` (first confirmation while enabling) | `{ token, user }` with the JWT of the new session | unchanged |
|
|
38
|
+
|
|
39
|
+
`token` is the JWT of the new session. The body carries a token when cookies are disabled (`cookies: false`) or
|
|
40
|
+
`cookies.exposeTokenInBody` is on; in the default cookie mode the answer stays as it is, and the session cookie carries
|
|
41
|
+
the new session.
|
|
42
|
+
|
|
43
|
+
In 12.11.0 a client without a session cookie kept a JWT of the deleted session after turning 2FA off: every request
|
|
44
|
+
answered `401`, and it could not fetch a new JWT from `GET /iam/token` either. The user had to sign in again. The
|
|
45
|
+
framework's default configuration reaches only the disable route; the two enable variants need a project's own
|
|
46
|
+
`twoFactor` setup (`otpOptions.sendOTP`, `skipVerificationOnEnable`).
|
|
47
|
+
|
|
48
|
+
**Clients:** store the `token` of these answers when it is present, the same way as after `verify-totp`.
|
|
49
|
+
`@lenne.tech/nuxt-extensions` 4.0.5 and `@lenne.tech/ng-base` 22.1.3 do this. Against 12.11.0 the field is absent and
|
|
50
|
+
nothing changes.
|
|
51
|
+
|
|
52
|
+
## 2. Dependencies: MongoDB driver security fix
|
|
53
|
+
|
|
54
|
+
| Package | 12.11.0 | 12.11.1 | Why |
|
|
55
|
+
|---|---|---|---|
|
|
56
|
+
| `mongodb` (optional peer) | 7.8.0 | 7.9.1 | GHSA-779g-w5r4-wr2x (credentials from the connection string in parse errors and in logged clients), GHSA-prmg-mvj2-c4f7 (NUL bytes in SASL PLAIN credentials change the authenticated identity), GHSA-c5cf-gf4q-92vj (OIDC bearer token leak); all medium, fixed in 7.9.x only |
|
|
57
|
+
| `mongoose` (optional peer) | 9.12.3 | 9.13.0 | the first mongoose that allows `mongodb ~7.9` |
|
|
58
|
+
| `ioredis` (optional peer) | 6.0.0 | 6.1.0 | maintenance |
|
|
59
|
+
|
|
60
|
+
These packages are optional peers: the project pins them. In a nest-server-starter based project, `pnpm run update`
|
|
61
|
+
raises its `mongoose` and `mongodb` pins (and `ioredis`, where declared) to these versions. Raise `mongoose` and `mongodb`
|
|
62
|
+
together; mongoose 9.12.3 accepts only `mongodb ~7.8`, and two driver copies give two `bson` copies, which breaks
|
|
63
|
+
Better-Auth's MongoDB adapter (`instanceof ObjectId`). The peer ranges stay as they are (`mongodb >=7.8.0 <8`,
|
|
64
|
+
`mongoose >=9.12.0 <10`).
|
|
65
|
+
|
|
66
|
+
## Compatibility Notes
|
|
67
|
+
|
|
68
|
+
| Pattern | Status |
|
|
69
|
+
|---|---|
|
|
70
|
+
| Cookie mode (`cookies: true`, the default) | Unchanged |
|
|
71
|
+
| JWT mode (`cookies: false`) with a frontend library that takes the token | Stays signed in after turning 2FA off |
|
|
72
|
+
| A project's own controller that forwards to Better-Auth through `sendBetterAuthResponse(res, response)` | Works as before; pass `{ requestSessionToken }` as the third argument to get the new rule on its routes |
|
|
73
|
+
| An override of `CoreBetterAuthService.presentSessionTokens(response)` | Still called; the second argument `{ requestSessionToken }` is new and optional |
|
|
74
|
+
|
|
75
|
+
## Troubleshooting
|
|
76
|
+
|
|
77
|
+
| Symptom | Cause | Fix |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| Signed out right after turning 2FA off in JWT mode | The client keeps the JWT of the replaced session | Update to 12.11.1 and store the `token` of the disable answer |
|
|
80
|
+
| `401` right after enabling 2FA in JWT mode | The first `verify-totp` replaced the session (12.10.x → 12.11.x guide, §1) | Use the `token` of the `verify-totp` answer |
|
|
81
|
+
|
|
82
|
+
## Module Documentation
|
|
83
|
+
|
|
84
|
+
- `src/core/modules/better-auth/README.md`: "The Better-Auth JWT"
|
|
85
|
+
- `src/core/modules/better-auth/core-better-auth-session-token.helper.ts`: `presentSessionTokens()` and its rules
|
|
86
|
+
- `migration-guides/12.10.x-to-12.11.x.md`, §1: the JWT session binding
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.11.1",
|
|
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": [
|
|
@@ -100,19 +100,19 @@
|
|
|
100
100
|
"node": ">= 22.15",
|
|
101
101
|
"pnpm": "^11.0.0"
|
|
102
102
|
},
|
|
103
|
-
"packageManager": "pnpm@11.
|
|
103
|
+
"packageManager": "pnpm@11.29.0+sha512.d913f9b37cd5fe6780052e809774edabb7bdcf69a6e6d9b8fd3b38bc052fa8a7d891b6c201a38fb504a07ffce2e5e8c262ef54fb8f57db62f22d353a30bc8a96",
|
|
104
104
|
"dependencies": {
|
|
105
105
|
"@apollo/server": "5.5.1",
|
|
106
106
|
"@as-integrations/express5": "1.1.2",
|
|
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
|
-
"ioredis": "6.
|
|
282
|
+
"ioredis": "6.1.0",
|
|
283
283
|
"kysely": "0.29.9",
|
|
284
|
-
"mongodb": "7.
|
|
285
|
-
"mongoose": "9.
|
|
284
|
+
"mongodb": "7.9.1",
|
|
285
|
+
"mongoose": "9.13.0",
|
|
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
|