@lenne.tech/nest-server 12.11.3 → 12.12.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/architecture.md +3 -0
- package/.claude/rules/configurable-features.md +6 -0
- package/.claude/rules/package-management.md +6 -4
- package/.claude/rules/testing.md +8 -7
- package/CLAUDE.md +2 -1
- package/FRAMEWORK-API.md +15 -1
- package/dist/core/common/decorators/common-error.decorator.d.ts +1 -1
- package/dist/core/common/helpers/cookies.helper.js +5 -2
- package/dist/core/common/helpers/cookies.helper.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +54 -0
- package/dist/core/common/persistence/audit-log.registry.d.ts +19 -0
- package/dist/core/common/persistence/audit-log.registry.js +84 -0
- package/dist/core/common/persistence/audit-log.registry.js.map +1 -0
- package/dist/core/common/services/core-trust-proxy.initializer.js +1 -1
- package/dist/core/common/services/core-trust-proxy.initializer.js.map +1 -1
- package/dist/core/common/services/crud.service.d.ts +10 -0
- package/dist/core/common/services/crud.service.js +79 -24
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/common/services/email.service.d.ts +5 -0
- package/dist/core/common/services/email.service.js +82 -6
- package/dist/core/common/services/email.service.js.map +1 -1
- package/dist/core/common/services/leased-interval.d.ts +22 -0
- package/dist/core/common/services/leased-interval.js +81 -0
- package/dist/core/common/services/leased-interval.js.map +1 -0
- package/dist/core/common/services/mail-outbox.registry.d.ts +26 -0
- package/dist/core/common/services/mail-outbox.registry.js +8 -0
- package/dist/core/common/services/mail-outbox.registry.js.map +1 -0
- package/dist/core/modules/audit-log/audited.decorator.d.ts +2 -0
- package/dist/core/modules/audit-log/audited.decorator.js +10 -0
- package/dist/core/modules/audit-log/audited.decorator.js.map +1 -0
- package/dist/core/modules/audit-log/core-audit-log.constants.d.ts +13 -0
- package/dist/core/modules/audit-log/core-audit-log.constants.js +11 -0
- package/dist/core/modules/audit-log/core-audit-log.constants.js.map +1 -0
- package/dist/core/modules/audit-log/core-audit-log.controller.d.ts +9 -0
- package/dist/core/modules/audit-log/core-audit-log.controller.js +87 -0
- package/dist/core/modules/audit-log/core-audit-log.controller.js.map +1 -0
- package/dist/core/modules/audit-log/core-audit-log.models.d.ts +10 -0
- package/dist/core/modules/audit-log/core-audit-log.models.js +11 -0
- package/dist/core/modules/audit-log/core-audit-log.models.js.map +1 -0
- package/dist/core/modules/audit-log/core-audit-log.module.d.ts +13 -0
- package/dist/core/modules/audit-log/core-audit-log.module.js +41 -0
- package/dist/core/modules/audit-log/core-audit-log.module.js.map +1 -0
- package/dist/core/modules/audit-log/core-audit-log.service.d.ts +49 -0
- package/dist/core/modules/audit-log/core-audit-log.service.js +169 -0
- package/dist/core/modules/audit-log/core-audit-log.service.js.map +1 -0
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js +4 -0
- package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js.map +1 -1
- package/dist/core/modules/mail-outbox/core-mail-outbox.constants.d.ts +22 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.constants.js +23 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.constants.js.map +1 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.controller.d.ts +10 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.controller.js +80 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.controller.js.map +1 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.models.d.ts +17 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.models.js +17 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.models.js.map +1 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.module.d.ts +12 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.module.js +42 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.module.js.map +1 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.service.d.ts +59 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.service.js +280 -0
- package/dist/core/modules/mail-outbox/core-mail-outbox.service.js.map +1 -0
- package/dist/core/modules/migrate/cli/migrate-cli.js +38 -2
- package/dist/core/modules/migrate/cli/migrate-cli.js.map +1 -1
- package/dist/core/modules/throttler/core-throttler.config.d.ts +16 -0
- package/dist/core/modules/throttler/core-throttler.config.js +107 -0
- package/dist/core/modules/throttler/core-throttler.config.js.map +1 -0
- package/dist/core/modules/throttler/core-throttler.constants.d.ts +11 -0
- package/dist/core/modules/throttler/core-throttler.constants.js +35 -0
- package/dist/core/modules/throttler/core-throttler.constants.js.map +1 -0
- package/dist/core/modules/throttler/core-throttler.decorators.d.ts +1 -0
- package/dist/core/modules/throttler/core-throttler.decorators.js +2 -0
- package/dist/core/modules/throttler/core-throttler.decorators.js.map +1 -0
- package/dist/core/modules/throttler/core-throttler.guard.d.ts +15 -0
- package/dist/core/modules/throttler/core-throttler.guard.js +65 -0
- package/dist/core/modules/throttler/core-throttler.guard.js.map +1 -0
- package/dist/core/modules/throttler/core-throttler.models.d.ts +1 -0
- package/dist/core/modules/throttler/core-throttler.models.js +11 -0
- package/dist/core/modules/throttler/core-throttler.models.js.map +1 -0
- package/dist/core/modules/throttler/core-throttler.module.d.ts +12 -0
- package/dist/core/modules/throttler/core-throttler.module.js +71 -0
- package/dist/core/modules/throttler/core-throttler.module.js.map +1 -0
- package/dist/core/modules/throttler/core-throttler.storages.d.ts +43 -0
- package/dist/core/modules/throttler/core-throttler.storages.js +174 -0
- package/dist/core/modules/throttler/core-throttler.storages.js.map +1 -0
- package/dist/core/modules/user/core-user.service.js +2 -2
- package/dist/core/modules/user/core-user.service.js.map +1 -1
- package/dist/core.module.js +26 -0
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -1
- package/docs/REQUEST-LIFECYCLE.md +7 -0
- package/docs/security-overrides.md +20 -8
- package/migration-guides/12.11.x-to-12.12.x.md +187 -0
- package/migration-guides/12.12.0-to-12.12.1.md +100 -0
- package/package.json +24 -23
- package/src/core/common/helpers/cookies.helper.ts +12 -2
- package/src/core/common/interfaces/server-options.interface.ts +311 -1
- package/src/core/common/persistence/audit-log.registry.ts +150 -0
- package/src/core/common/services/core-trust-proxy.initializer.ts +5 -4
- package/src/core/common/services/crud.service.ts +128 -33
- package/src/core/common/services/email.service.ts +101 -9
- package/src/core/common/services/leased-interval.ts +123 -0
- package/src/core/common/services/mail-outbox.registry.ts +53 -0
- package/src/core/modules/audit-log/README.md +95 -0
- package/src/core/modules/audit-log/audited.decorator.ts +27 -0
- package/src/core/modules/audit-log/core-audit-log.constants.ts +28 -0
- package/src/core/modules/audit-log/core-audit-log.controller.ts +77 -0
- package/src/core/modules/audit-log/core-audit-log.models.ts +34 -0
- package/src/core/modules/audit-log/core-audit-log.module.ts +54 -0
- package/src/core/modules/audit-log/core-audit-log.service.ts +270 -0
- package/src/core/modules/better-auth/core-better-auth-email-verification.service.ts +4 -0
- package/src/core/modules/mail-outbox/README.md +88 -0
- package/src/core/modules/mail-outbox/core-mail-outbox.constants.ts +42 -0
- package/src/core/modules/mail-outbox/core-mail-outbox.controller.ts +60 -0
- package/src/core/modules/mail-outbox/core-mail-outbox.models.ts +46 -0
- package/src/core/modules/mail-outbox/core-mail-outbox.module.ts +52 -0
- package/src/core/modules/mail-outbox/core-mail-outbox.service.ts +390 -0
- package/src/core/modules/migrate/README.md +6 -1
- package/src/core/modules/migrate/cli/migrate-cli.ts +60 -2
- package/src/core/modules/throttler/README.md +115 -0
- package/src/core/modules/throttler/core-throttler.config.ts +162 -0
- package/src/core/modules/throttler/core-throttler.constants.ts +71 -0
- package/src/core/modules/throttler/core-throttler.decorators.ts +14 -0
- package/src/core/modules/throttler/core-throttler.guard.ts +109 -0
- package/src/core/modules/throttler/core-throttler.models.ts +23 -0
- package/src/core/modules/throttler/core-throttler.module.ts +95 -0
- package/src/core/modules/throttler/core-throttler.storages.ts +299 -0
- package/src/core/modules/user/core-user.service.ts +3 -2
- package/src/core.module.ts +46 -0
- package/src/index.ts +36 -0
|
@@ -122,6 +122,7 @@ JWT-based authentication for existing projects:
|
|
|
122
122
|
| **Tenant Plugin Safety Net** | Mongoose tenant plugin refuses a tenant-schema access without valid tenant context: 401 for a client operation nobody is signed in to (an expired session included — 12.11.3), 403 for a signed-in caller and for server work. Its post hooks (`find`, `findOne`, `findOneAnd*`) additionally check every RETURNED row (`assertRowsInTenantScope()`): a row of a tenant outside the caller's scope withholds the whole result with 403. The decisions live in `common/persistence/policies/tenant.policy.ts`, which every data store shares |
|
|
123
123
|
| **Data Store** | `DataStore<T>` (`common/persistence/`) is the database-neutral port below the CrudService pipeline; every `ModuleService` has one (`this.dataStore`, derived from `mainDbModel`, or passed as `dataStore`). On MongoDB it runs through Mongoose model methods, so every plugin fires. On PostgreSQL (`SqlDataStore`, phase 1) the same pipeline runs on plain records: before every statement the store applies the policies the plugins call (tenant filter and stamping, safety net, audit, password, role guard, system roles), the statement runs in its own transaction with the request's tenant scope so FORCED row-level security binds it (a query without a scope fails with 42501 → 403), and every returned row passes the tenant row check. References populate with one batched `id $in` read through the target model's store. Mongoose-only APIs (`aggregate`, `getModel`, native collection/connection) refuse on a SQL-stored model, and so does the Mongoose model itself (every data method of a model routed to SQL throws a named error). Since phase 2 the core's own models — users, tenant memberships, API tokens — are registered this way and their services run on the routed store; the port gained `updateOne` / `deleteOne` (atomic first match), `updateMany`, `deleteMany` and `updateById(…, { timestamps: false })`. Since phase 3 Better-Auth follows the user model: with the users on a SQL source (PostgreSQL; MySQL / MariaDB since 12.1.1) it runs its own Kysely adapter on that source's application pool, one `users` row per user, and the framework's reads of Better-Auth's data (session lookup by token in the middleware, token service, JWKS, passkey challenge mappings, e-mail-verified hook, user mapper, system setup, migration status, the MCP OAuth subject's roles) go through `BetterAuthSqlStore` — see `.claude/rules/better-auth.md` §11. Since phase 4 the AI module (eleven models, MCP OAuth clients, codes and refresh tokens) and the S3 / filesystem file metadata (`fileMetadataCollection()`, used by the file service, the TUS hand-off and the Hub) follow their routed store too; the port gained `sum()` and `find(…, { exclude })`, and an expiry sweep removes expired rows of TTL models and expired Better-Auth sessions on SQL, where no TTL index does. `CorePersistenceModule.forFeature()` + `@InjectStore()` register and inject the store; the `database` configuration routes each model to its source. Since phase 5 (12.1.0) MongoDB's libraries are optional peers: the core reaches them through `common/persistence/mongo/` (decorators that record the declaration and apply `@nestjs/mongoose`'s where installed, tokens, ObjectIds, GridFS), `CoreModule` connects MongoDB only when a source uses it, `forFeature()` provides the model tokens itself (a stand-in that refuses data access where no MongoDB is connected), and `database: false` runs without any database; the port gained `find(…, { sample })`, and the SQL update compiler skips a field given as `undefined` as Mongoose does |
|
|
124
124
|
| **API Tokens** | `apiTokens` config (opt-in): USER tokens act as their user without global roles; TENANT tokens (multi-tenancy only) act with the lowest tenant role in their own tenant. `CoreApiTokenMiddleware` authenticates `Authorization: Bearer` / `x-api-key`; every guard denies a token unless the route declares `@ApiTokenScopes()`. Signed short-lived assertions for embedded pages. See `src/core/modules/api-token/README.md` |
|
|
125
|
+
| **Rate limit for project routes** | `throttler` config (opt-in, 12.12.0, DEV-4431) on top of `@nestjs/throttler`: `CoreThrottlerGuard` is registered as the FIRST global guard, so an over-limit client gets 429 + `Retry-After` (`#LTNS_0020`) before authentication runs — also on a route that would answer it 401. It resolves the request like the role guards (`resolveGuardRequest()`: REST, GraphQL over HTTP, agent calls in a request); only a call without any request (a request-less agent call) is not counted. Counted per `request.ip` (follows `trustProxy`, IPv6 by /64); a request without an address — a GraphQL operation over the WebSocket, an HTTP request whose client already closed the connection — per signed-in user, else by the WebSocket's upgrade address, else in one shared bucket, never uncounted. `routes: 'decorated'` (default) limits only routes whose method or controller carries `@Throttle()`; `'all'` every route unless `@SkipThrottle()`. Counters in memory, Redis (default with `redis`) or the project's database through the persistence layer (`storage: 'database'`, MongoDB or SQL, exact across replicas); an outage of the shared store falls back to memory. CORS exposes `Retry-After` and `X-RateLimit-*` (`buildCorsConfig()`, 12.12.1), so an app on another origin can read the wait time. See `src/core/modules/throttler/README.md` |
|
|
125
126
|
|
|
126
127
|
### Data & CRUD
|
|
127
128
|
|
|
@@ -137,6 +138,7 @@ JWT-based authentication for existing projects:
|
|
|
137
138
|
| **Bulk Operations** | Batch create/update/delete |
|
|
138
139
|
| **Force Mode** | `force: true` bypasses all security checks |
|
|
139
140
|
| **Raw Mode** | `raw: true` skips prepareInput/prepareOutput |
|
|
141
|
+
| **Audit Log** | `auditLog` config (opt-in, 12.12.0, DEV-4432): `CrudService.create()` / `update()` / `delete()` (and their `Force` / `Raw` variants, `CoreUserService.create()`) report every successful write of a model carrying `@Audited()` or named in `auditLog.models` to the listener in `common/persistence/audit-log.registry.ts` — after the write, inside `process()`. An entry holds action, model, record id, user, time and the NAMES of the fields set (create) or changed (update: compared before and after the merge; an update that changed nothing leaves no entry) — never a value. Without the configuration no listener is registered and the report is one `undefined` check. A failed audit write is logged, never thrown. Readable by admins (`GET /audit-log`), hourly retention purge under a lease, `importEntries()` for entries of another system. See `src/core/modules/audit-log/README.md` |
|
|
140
142
|
| **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" |
|
|
141
143
|
|
|
142
144
|
### Models & Inputs
|
|
@@ -201,6 +203,7 @@ JWT-based authentication for existing projects:
|
|
|
201
203
|
| **TemplateService** | EJS template rendering for emails |
|
|
202
204
|
| **Template Inheritance** | Project templates override nest-server fallbacks |
|
|
203
205
|
| **Multi-Language** | Locale-aware template resolution (`template-de.ejs` → `template.ejs`) |
|
|
206
|
+
| **Mail Outbox** | `mailOutbox` config (opt-in, 12.12.0, DEV-4433): `EmailService.sendMail()` renders the mail, applies the production `jsonTransport` guard and the Hub mailbox, then STORES it (`mail-outbox.registry.ts`) and answers `{ queued: true, outboxId, messageId }` instead of sending; Better-Auth's auth mails take the same path. Every replica delivers due mails, each claimed with one atomic statement (exactly one replica sends it), retried with exponential backoff up to `maxAttempts`, then `failed` (logged, listed at `GET /mail-outbox`, `POST /mail-outbox/:id/retry`). A delivered mail loses its content at once. A call with its own `smtp` transport and Brevo / Mailjet template mails are sent directly. See `src/core/modules/mail-outbox/README.md` |
|
|
204
207
|
|
|
205
208
|
### Database & Migration
|
|
206
209
|
|
|
@@ -797,6 +800,10 @@ array of 2^32 − 1 elements whose coercion exhausted a 1 GB heap. graphql-uploa
|
|
|
797
800
|
|
|
798
801
|
Guards run after middleware but before the handler. The `@Roles()` decorator specifies who can access a method:
|
|
799
802
|
|
|
803
|
+
**With `throttler` configured, the rate limit guard runs first** (12.12.0): `CoreModule` imports `CoreThrottlerModule`
|
|
804
|
+
ahead of every other module, and global guards run in the order their modules are registered. An over-limit client is
|
|
805
|
+
refused with 429 before the role guards authenticate it; under the limit the role guards decide as below.
|
|
806
|
+
|
|
800
807
|
```typescript
|
|
801
808
|
@Query(() => User)
|
|
802
809
|
@Roles(RoleEnum.ADMIN) // Only admins
|
|
@@ -24,7 +24,16 @@ used to **exact-pin**, to a vulnerable version:
|
|
|
24
24
|
| `@graphql-tools/utils` | [GHSA-7mx3-vvmw-hjmv](https://github.com/advisories/GHSA-7mx3-vvmw-hjmv) — high: prototype pollution in `mergeDeep`, which runs while the GraphQL schema is assembled. Covers `<=12.0.0`, patched `>=12.0.1` (added 2026-10-06); [GHSA-c4qx-w738-7hr3](https://github.com/advisories/GHSA-c4qx-w738-7hr3) — high: prototype pollution in `mergeIncrementalResult` via non-primitive path segments. Covers `>=10.10.1 <=12.0.1`, patched `>=12.0.2` (published 2026-10-22) | `@nestjs/graphql` declares utils as an **exact pin**: 13.4.5 — the newest 13.x — `12.0.0`, and 14.0.3, the version this framework declares since 12.0.0, `12.0.1`. 12.0.1 clears the first advisory and is covered by the second, so **this entry is load-bearing on 13.x and on 14.0.x**. 14.1.0, the version this framework declares since 12.1.0, pins `12.1.0`, which clears both: there the entry is inert. `@apollo/server` reaches utils too, through `@graphql-tools/schema` / `merge` — and in a lockfile that still holds schema 10.0.x (resolved before 2026-08-12), as **utils 11.x**: vulnerable too, with no 11.x fix, and outside the override key. Lift it with `pnpm update --depth Infinity @graphql-tools/schema @graphql-tools/merge`; the current releases request utils `^12.1.0`, which needs Node >=22.15 — the framework's own floor since 11.42.10 |
|
|
25
25
|
| `multer` | [GHSA-wc9g-mqfw-jrwm](https://github.com/advisories/GHSA-wc9g-mqfw-jrwm), [GHSA-535w-7cp7-47q4](https://github.com/advisories/GHSA-535w-7cp7-47q4), [GHSA-qfvm-cv95-jqjf](https://github.com/advisories/GHSA-qfvm-cv95-jqjf) — high: DoS via crafted multipart input; [GHSA-qvfw-j98x-7q72](https://github.com/advisories/GHSA-qvfw-j98x-7q72) — low: file size limit bypass. Patched `>=2.3.0`; [GHSA-q7qp-rjg7-q26m](https://github.com/advisories/GHSA-q7qp-rjg7-q26m) — high: DoS via a pending asynchronous `fileFilter` after request teardown. Covers `>=2.0.0 <2.5.0`, patched `>=2.5.0` (published 2026-10-22) | `@nestjs/platform-express` declares multer as an **exact pin**: up to 11.2.5 `2.2.0`, 11.2.6 / 11.2.7 `2.4.0`, and so does 12.2.0, the version this framework declared in 12.0.x. 2.4.0 is covered by GHSA-q7qp-rjg7-q26m, so **this entry is load-bearing up to @nestjs/platform-express 12.2.0**. 12.3.2, the version this framework declares since 12.1.0, pins `2.5.0`: there the entry is inert. A direct `multer` dependency does not move the pin: you get both copies, and FileInterceptor uses the vulnerable one |
|
|
26
26
|
|
|
27
|
-
**Status since 12.
|
|
27
|
+
**Status since 12.12.0** (verified 2026-11-30): **the `ws` entry can go.** `@nestjs/graphql` 14.2.2, the version this
|
|
28
|
+
framework declares since 12.12.0, exact-pins `ws` 8.23.0, which clears GHSA-37g9-w4hg-h9qr; a fresh resolve of
|
|
29
|
+
nest-server's tree with and without the entry yields the same packages, a single `ws@8.23.0`, and the same audit. Raise
|
|
30
|
+
your project's `@nestjs/*` pins to the framework's (`pnpm run update` does it: `@nestjs/graphql` / `@nestjs/apollo`
|
|
31
|
+
14.2.2), remove the `ws` entry, run `pnpm install` and check that `pnpm why ws` lists one `ws@8.23.0`. Keep the entry
|
|
32
|
+
only while your project still pins `@nestjs/graphql` below 14.2.2. Do **not** pin `@apollo/server` 5.5.2 yourself: it
|
|
33
|
+
caps `@graphql-tools/utils` at `<12.0.2` (for Node 20 installs) and brings back 12.0.1, which GHSA-c4qx-w738-7hr3
|
|
34
|
+
(high) covers; the framework stays on 5.5.1 until that cap is lifted.
|
|
35
|
+
|
|
36
|
+
**Status 12.9.4 to 12.11.x** (verified 2026-11-14): **`ws` needs an entry again.**
|
|
28
37
|
[GHSA-37g9-w4hg-h9qr](https://github.com/websockets/ws/security/advisories/GHSA-37g9-w4hg-h9qr) — high: a client
|
|
29
38
|
floods ping frames without reading the replies, the server buffers the automatic pongs, and the process runs out of
|
|
30
39
|
memory. No authentication is needed, so every application with GraphQL subscriptions over WebSocket is reachable.
|
|
@@ -78,7 +87,8 @@ entries. None of them is optional in practice.
|
|
|
78
87
|
Add this to your project's `pnpm-workspace.yaml` (pnpm 11+; in pnpm 10 and earlier it lives under
|
|
79
88
|
`pnpm.overrides` in `package.json`).
|
|
80
89
|
|
|
81
|
-
**On nest-server 12.9.4
|
|
90
|
+
**On nest-server 12.9.4 to 12.11.x** this one entry is needed (see "Status 12.9.4 to 12.11.x"); on 12.12.0 and later
|
|
91
|
+
only while your project pins `@nestjs/graphql` below 14.2.2 (see "Status since 12.12.0"):
|
|
82
92
|
|
|
83
93
|
```yaml
|
|
84
94
|
overrides:
|
|
@@ -136,8 +146,9 @@ way, and remove the entries once your consumers move to minimatch 11 / glob 14.
|
|
|
136
146
|
`@nestjs/graphql` 13 and `@nestjs/swagger` 11 exact-pin vulnerable versions of these two; their 12.x
|
|
137
147
|
successors pin patched ones (`ws` 8.22.0, `js-yaml` 5.5.0). On nest-server 12 remove both entries — an
|
|
138
148
|
inert `ws` entry is not harmless there: pnpm rewrites `graphql-ws`'s `ws` peer range to the override
|
|
139
|
-
target, so a target below 8.22.0 makes `pnpm peers check` report `unmet peer ws`.
|
|
140
|
-
|
|
149
|
+
target, so a target below 8.22.0 makes `pnpm peers check` report `unmet peer ws`. From 12.9.4 to 12.11.x nest-server 12
|
|
150
|
+
needed its own `ws` entry again, for GHSA-37g9-w4hg-h9qr: replace the 11.x entry with the one from "The fix". Since
|
|
151
|
+
12.12.0 no entry is needed with the framework's `@nestjs/graphql` 14.2.2.
|
|
141
152
|
|
|
142
153
|
```yaml
|
|
143
154
|
# nest-server 11.x only (@nestjs/graphql 13 exact-pins ws; GHSA-96hv-2xvq-fx4p, patched >=8.21.0)
|
|
@@ -162,7 +173,8 @@ tree to `2.0.11` even though nothing needed help any more.
|
|
|
162
173
|
|
|
163
174
|
### The `ws` target must stay in lockstep with the declared `ws` version
|
|
164
175
|
|
|
165
|
-
This applies while a project carries a `ws` entry at all: on nest-server 11.x,
|
|
176
|
+
This applies while a project carries a `ws` entry at all: on nest-server 11.x, on 12.9.4 to 12.11.x, and on 12.12.0
|
|
177
|
+
and later while the project pins `@nestjs/graphql` below 14.2.2. `8.23.0`
|
|
166
178
|
(since 12.9.4; `8.22.0` since 12.0.0, `8.21.3` before) is not an arbitrary "latest patch" — it is the version
|
|
167
179
|
`@lenne.tech/nest-server` declares as an ordinary **dependency**, so it is already in your tree whether
|
|
168
180
|
or not you list `ws` yourself. The override target has to equal it.
|
|
@@ -196,9 +208,9 @@ pnpm test # nothing should regress
|
|
|
196
208
|
Commit `package.json`/`pnpm-workspace.yaml` **and** `pnpm-lock.yaml` together.
|
|
197
209
|
|
|
198
210
|
> Projects generated from `nest-server-starter` or `lt-monorepo` carry the starter's overrides as they were when the
|
|
199
|
-
> project was created.
|
|
200
|
-
> exact `8.22.1` that `@nestjs/graphql` 14.2.1 requests and must be **replaced** by the entry from "The fix"
|
|
201
|
-
> the rule above).
|
|
211
|
+
> project was created. From 12.9.4 to 12.11.x that was not enough for `ws`: their entry `'ws@>=8.0.0 <8.22.1': 8.22.1`
|
|
212
|
+
> misses the exact `8.22.1` that `@nestjs/graphql` 14.2.1 requests and must be **replaced** by the entry from "The fix"
|
|
213
|
+
> (see the rule above). On 12.12.0, with `@nestjs/graphql` raised to 14.2.2, remove the `ws` entry instead.
|
|
202
214
|
|
|
203
215
|
## Rules for writing your own overrides
|
|
204
216
|
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Migration Guide: 12.11.x → 12.12.x
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|----------|---------|
|
|
7
|
+
| **Breaking Changes** | None. All three features are off without configuration: no guard, no table or collection, no route, no work per request |
|
|
8
|
+
| **New Features** | Rate limit for a project's routes on `@nestjs/throttler` (`throttler`, §1); audit log — who, when, what, field names only (`auditLog`, §2); mail outbox with retries, delivered by exactly one replica (`mailOutbox`, §3) |
|
|
9
|
+
| **Bugfixes** | `migrate create` in a vendor-mode ES module project writes an import Node can load (§5) |
|
|
10
|
+
| **Dependencies** | `@nestjs/throttler` 6.8.0 is a new `dependencies` entry of the framework; `@nestjs/*` patch releases (12.6.3, `@nestjs/graphql` 14.2.2); the `ws` override is no longer needed (§4) |
|
|
11
|
+
| **Migration Effort** | None to update; ~10 minutes per feature a project switches on |
|
|
12
|
+
|
|
13
|
+
## Quick Migration
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @lenne.tech/nest-server@12.12.x
|
|
17
|
+
pnpm run update # only if you use the starter's update script
|
|
18
|
+
pnpm run build
|
|
19
|
+
pnpm test
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Nothing changes until a project configures one of the three features.
|
|
23
|
+
|
|
24
|
+
## 1. Rate limit for a project's routes (`throttler`)
|
|
25
|
+
|
|
26
|
+
Public routes of a project — a contact form, an application form — can be protected without a solution of the
|
|
27
|
+
project's own. The framework's sign-in routes keep their own limits (`auth.rateLimit`, `betterAuth.rateLimit`).
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
// config.env.ts
|
|
31
|
+
throttler: { storage: 'database' }, // or {} — memory, Redis when `redis` is configured
|
|
32
|
+
trustProxy: 1, // the number of proxies in front of the app — REQUIRED behind a reverse proxy
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { Roles, RoleEnum, Throttle } from '@lenne.tech/nest-server';
|
|
37
|
+
|
|
38
|
+
@Post('contact')
|
|
39
|
+
@Roles(RoleEnum.S_EVERYONE)
|
|
40
|
+
@Throttle({ default: { limit: 5, ttl: 60_000 } }) // 5 per minute and client; ttl in milliseconds
|
|
41
|
+
async contact(@Body() input: ContactInput) { … }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- Over the limit the route answers **429** with `Retry-After` and `#LTNS_0020: Too many requests`, also for GraphQL
|
|
45
|
+
operations.
|
|
46
|
+
- `routes: 'decorated'` (default) limits only routes whose method or controller carries `@Throttle()`. `routes: 'all'`
|
|
47
|
+
limits every route unless `@SkipThrottle()` exempts it — keep in mind that every user behind one NAT shares an
|
|
48
|
+
address.
|
|
49
|
+
- Counters: `'memory'` (per replica), `'redis'` (default with `redis`), `'database'` (the table `throttler_counters` /
|
|
50
|
+
collection `throttlerCounters`, exact across replicas without Redis; MongoDB, PostgreSQL, MySQL, MariaDB). An
|
|
51
|
+
explicit storage that cannot work stops the boot; an unreachable Redis or database falls back to memory.
|
|
52
|
+
- The guard is the first global guard: an over-limit client is refused before authentication.
|
|
53
|
+
- Import `Throttle` / `SkipThrottle` from `@lenne.tech/nest-server`, and **do not** import `ThrottlerModule` yourself —
|
|
54
|
+
`CoreModule` provides its tokens. A project that already registers `ThrottlerModule` and its own `ThrottlerGuard`
|
|
55
|
+
removes them when it switches to `throttler`.
|
|
56
|
+
|
|
57
|
+
Details: `src/core/modules/throttler/README.md`.
|
|
58
|
+
|
|
59
|
+
## 2. Audit log (`auditLog`)
|
|
60
|
+
|
|
61
|
+
Who created, changed, deleted or restored which record, and which fields a change touched — by name only, never a
|
|
62
|
+
value.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// config.env.ts
|
|
66
|
+
auditLog: { models: ['Institution'], retentionDays: 365 },
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Audited } from '@lenne.tech/nest-server';
|
|
71
|
+
|
|
72
|
+
@Audited() // alternative to auditLog.models
|
|
73
|
+
export class Institution extends CorePersistenceModel { … }
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- Logged are `CrudService.create()`, `update()` and `delete()` (and their `Force` / `Raw` variants) of the named
|
|
77
|
+
models; an update that changed nothing leaves no entry. Writes past `CrudService` (data store, Mongoose,
|
|
78
|
+
`pushToArray()`) are not logged — log them, and actions such as a restore, with `CoreAuditLogService.record()`.
|
|
79
|
+
- `GET /audit-log?model=&recordId=&userId=&action=&from=&to=&limit=&offset=` for administrators (`auditLog.roles`
|
|
80
|
+
adds roles).
|
|
81
|
+
- Entries older than `retentionDays` are removed hourly. Entries of another system come in through
|
|
82
|
+
`CoreAuditLogService.importEntries()`, which keeps their time and drops every value they carry.
|
|
83
|
+
- Table `audit_log_entries` / collection `auditLogEntries`, following `database`.
|
|
84
|
+
|
|
85
|
+
Details: `src/core/modules/audit-log/README.md`.
|
|
86
|
+
|
|
87
|
+
## 3. Mail outbox (`mailOutbox`)
|
|
88
|
+
|
|
89
|
+
A short SMTP outage no longer loses mail. Every mail of `EmailService` — the framework's verification and
|
|
90
|
+
password-reset mails included — is stored first and delivered from the store.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// config.env.ts
|
|
94
|
+
mailOutbox: {}, // maxAttempts 10, retries from 30 s doubling to 1 h
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- `EmailService.sendMail()` answers once the mail is STORED: `{ accepted, messageId, outboxId, queued: true }`. Code
|
|
98
|
+
that read nodemailer's delivery result (`response`, `envelope`) gets this receipt instead — the delivery happens
|
|
99
|
+
afterwards.
|
|
100
|
+
- With several replicas exactly one delivers each mail (an atomic claim in the database). Delivery is at least once: a
|
|
101
|
+
replica dying between the server's accept and the record may cause a second delivery, with the same Message-ID.
|
|
102
|
+
- Failed for good after `maxAttempts`: logged as an error, listed at `GET /mail-outbox?status=failed` (without the
|
|
103
|
+
content), retried with `POST /mail-outbox/:id/retry`.
|
|
104
|
+
- A delivered mail loses its content at once (it may carry a reset link).
|
|
105
|
+
- Sent directly as before: a call with a transport of its own (`sendMail(…, { smtp })`) and Brevo / Mailjet template
|
|
106
|
+
mails.
|
|
107
|
+
- Table `mail_outbox` / collection `mailOutbox`, following `database`.
|
|
108
|
+
|
|
109
|
+
Details: `src/core/modules/mail-outbox/README.md`.
|
|
110
|
+
|
|
111
|
+
## 4. Dependencies
|
|
112
|
+
|
|
113
|
+
`@nestjs/throttler` 6.8.0 is a new `dependencies` entry. npm-mode projects get it with the framework. A vendor-mode
|
|
114
|
+
project declares it in its own `dependencies` (6.8.0): the core imports it in `core.module.ts` whether or not `throttler`
|
|
115
|
+
is configured, so without it `tsc` fails with TS2307 and the API does not start. `/lt-dev:backend:update-nest-server-core`
|
|
116
|
+
adds it; a project vendored from 12.12.0 on gets it from the lt CLI's vendoring step.
|
|
117
|
+
|
|
118
|
+
The framework moved to these versions. A project that pins any of them raises its pin to the same version
|
|
119
|
+
(`pnpm run update` in a starter-derived project does it), otherwise it installs two copies:
|
|
120
|
+
|
|
121
|
+
| Package | Version |
|
|
122
|
+
|---------|---------|
|
|
123
|
+
| `@nestjs/common`, `@nestjs/core`, `@nestjs/platform-express`, `@nestjs/testing` | 12.6.3 |
|
|
124
|
+
| `@nestjs/apollo`, `@nestjs/graphql` | 14.2.2 |
|
|
125
|
+
| `@nestjs/swagger` | 12.1.3 |
|
|
126
|
+
| `@nestjs/mongoose` (MongoDB projects) | 12.0.2 |
|
|
127
|
+
|
|
128
|
+
**The `ws` override can go.** `@nestjs/graphql` 14.2.2 pins `ws` 8.23.0 itself, which clears GHSA-37g9-w4hg-h9qr. With
|
|
129
|
+
the raised pin, remove the entry `'ws@>=8.0.0 <8.23.0': '8.23.0'` from `pnpm-workspace.yaml`, run `pnpm install` and
|
|
130
|
+
check that `pnpm why ws` lists a single `ws@8.23.0`. Keep it only while the project still pins `@nestjs/graphql` below
|
|
131
|
+
14.2.2 (`docs/security-overrides.md`, "Status since 12.12.0").
|
|
132
|
+
|
|
133
|
+
**Do not pin `@apollo/server` 5.5.2.** It caps `@graphql-tools/utils` below 12.0.2 so that installs on Node 20 work, and
|
|
134
|
+
brings back 12.0.1, which GHSA-c4qx-w738-7hr3 (high) covers. The framework stays on 5.5.1.
|
|
135
|
+
|
|
136
|
+
The better-auth peer range is unchanged (`>=1.7.16 <1.8.0`); the framework is tested against 1.7.29. Which version a
|
|
137
|
+
project runs stays its own decision, because its api and app must resolve the same one.
|
|
138
|
+
|
|
139
|
+
## 5. `migrate create` in vendor-mode ES module projects
|
|
140
|
+
|
|
141
|
+
In a vendor-mode project `migrate create` rewrites the template's `@lenne.tech/nest-server` import to the vendored
|
|
142
|
+
core. In an ES module project (`"type": "module"`, the starter's format since 12.0.0) that path named the core
|
|
143
|
+
directory (`'../src/core'`), which ESM does not resolve: `migrate up` stopped with `ERR_UNSUPPORTED_DIR_IMPORT`. New
|
|
144
|
+
migrations now import `'../src/core/index.js'`, also with `--sql`. CommonJS projects keep `'../src/core'`.
|
|
145
|
+
|
|
146
|
+
Until 12.12.1 a migration created while a build lay in `dist/` imported the build instead, `'../dist/src/core/index.js'`:
|
|
147
|
+
`bin/migrate.js` runs the compiled CLI then, and the path was computed from its location. Since 12.12.1 it always names
|
|
148
|
+
the source core. Change such an import to `'../src/core/index.js'`.
|
|
149
|
+
|
|
150
|
+
Migrations created before keep their import. Fix one that fails by hand:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// Before
|
|
154
|
+
import { runSqlMigration } from '../src/core';
|
|
155
|
+
// After
|
|
156
|
+
import { runSqlMigration } from '../src/core/index.js';
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Compatibility Notes
|
|
160
|
+
|
|
161
|
+
| Pattern | Status |
|
|
162
|
+
|---------|--------|
|
|
163
|
+
| No `throttler` / `auditLog` / `mailOutbox` configuration | Unchanged — nothing is registered |
|
|
164
|
+
| A project's own `ThrottlerModule` + `ThrottlerGuard` | Keeps working while `throttler` is not configured; with `throttler` remove them (both would register the same tokens) |
|
|
165
|
+
| A `CrudService` subclass overriding `create()` / `update()` / `delete()` and calling `super` | Audited as usual; an override that does NOT call `super` writes past the audit log — call `this.reportAudit()` / `record()` |
|
|
166
|
+
| `EmailService.sendMail()` result used for logging | With the outbox it is the receipt (`queued: true`) |
|
|
167
|
+
| Hub mailbox in capture mode | Unchanged: capture mode suppresses the send before the outbox |
|
|
168
|
+
|
|
169
|
+
## Troubleshooting
|
|
170
|
+
|
|
171
|
+
| Symptom | Cause | Fix |
|
|
172
|
+
|---------|-------|-----|
|
|
173
|
+
| Every client gets 429 at once behind a reverse proxy | `trustProxy` unset: every request comes from the proxy | Set `trustProxy` to the number of proxies |
|
|
174
|
+
| An app on another origin sees the 429 but cannot read `Retry-After` | the CORS options do not expose it (12.12.0) | 12.12.1 exposes the rate limit headers through `buildCorsConfig()`; a `main.ts` building its own CORS options lists them in `exposedHeaders` |
|
|
175
|
+
| Boot error `throttler.storage is 'redis', but redis is not configured` | explicit storage without its backend | Configure `redis` or choose another storage |
|
|
176
|
+
| A route with `@Throttle()` is not limited | decorator imported from a second copy of `@nestjs/throttler` | Import it from `@lenne.tech/nest-server` |
|
|
177
|
+
| No audit entries for a model | the model is neither `@Audited()` nor in `auditLog.models`, or the write bypasses `CrudService` | Add it, or call `record()` |
|
|
178
|
+
| `migrate up` fails with `ERR_UNSUPPORTED_DIR_IMPORT` in a vendor-mode project | a migration created before 12.12.0 imports the core directory in an ES module project | Import `'../src/core/index.js'` (§5) |
|
|
179
|
+
| Mails stay `pending` | SMTP unreachable; see `lastError` at `GET /mail-outbox` | Fix the transport; the outbox retries by itself |
|
|
180
|
+
| Vendor mode: `Cannot find package '@nestjs/throttler'` at start (or TS2307 in `tsc`) | the core imports it since 12.12.0, also without `throttler` configured | Add `"@nestjs/throttler": "6.8.0"` to `dependencies` (§4) |
|
|
181
|
+
|
|
182
|
+
## Module Documentation
|
|
183
|
+
|
|
184
|
+
- `src/core/modules/throttler/README.md`
|
|
185
|
+
- `src/core/modules/audit-log/README.md`
|
|
186
|
+
- `src/core/modules/mail-outbox/README.md`
|
|
187
|
+
- `.claude/rules/configurable-features.md` — rows "Rate Limit for Project Routes", "Audit Log", "Mail Outbox"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Migration Guide: 12.12.0 → 12.12.1
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
| Category | Details |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Breaking Changes** | None |
|
|
8
|
+
| **New Features** | None |
|
|
9
|
+
| **Bugfixes** | `migrate create` writes the source core into a new migration while a build lies in `dist/` (§1); with `throttler` configured, CORS exposes the rate limit headers to an app on another origin (§2) |
|
|
10
|
+
| **Security** | None |
|
|
11
|
+
| **Migration Effort** | Package update. A vendor-mode project changes the import of a migration created under 12.12.0 while a build was present; a project that builds its CORS options itself in `main.ts` lists the rate limit headers there |
|
|
12
|
+
|
|
13
|
+
## Quick Migration
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @lenne.tech/nest-server@12.12.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: `migrate create` imports the source core, also while a build exists
|
|
25
|
+
|
|
26
|
+
**No action needed** in npm mode. A vendor-mode project checks the migrations it created under 12.12.0 (and before)
|
|
27
|
+
while a build lay in `dist/`.
|
|
28
|
+
|
|
29
|
+
In a vendor-mode project, `migrate create` writes the relative path to the vendored core into the new migration
|
|
30
|
+
(`'../src/core/index.js'` in an ES module project, `'../src/core'` in a CommonJS project). `bin/migrate.js` prefers the
|
|
31
|
+
compiled CLI in `dist/` when a build exists, and the path was computed from the CLI's own location. Such a migration
|
|
32
|
+
therefore imported the build output, `'../dist/src/core/index.js'`: it failed in a fresh checkout without a build, and
|
|
33
|
+
after the project's build it pointed at `dist/dist/src/core`.
|
|
34
|
+
|
|
35
|
+
Since 12.12.1 the path always names the source core (`<project>/src/core`), for a build in `dist/src/core` and in
|
|
36
|
+
`dist/core` alike. Only where no source core with an `index.ts` lies beside the build (a deployed image) does the CLI
|
|
37
|
+
keep the core it runs from. Find and fix the migrations written with the build path:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
grep -rln "dist/src/core" migrations/
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// Before (created while a build existed)
|
|
45
|
+
import { getDb } from '../dist/src/core/index.js';
|
|
46
|
+
|
|
47
|
+
// After
|
|
48
|
+
import { getDb } from '../src/core/index.js';
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 2. Bugfix: an app on another origin can read the rate limit headers
|
|
52
|
+
|
|
53
|
+
**No action needed** for a project whose `main.ts` calls `app.enableCors(buildCorsConfig(envConfig))`, as the
|
|
54
|
+
nest-server-starter does: REST and GraphQL share that configuration.
|
|
55
|
+
|
|
56
|
+
The rate limit of 12.12.0 (`throttler`) answers `429` with `Retry-After` and sets `X-RateLimit-Limit`,
|
|
57
|
+
`X-RateLimit-Remaining` and `X-RateLimit-Reset` on every limited response. A browser hides every response header but a
|
|
58
|
+
short safe list from a script on another origin, so an app on its own host (`app.example.com` calling
|
|
59
|
+
`api.example.com`) saw the `429` but not how long to wait.
|
|
60
|
+
|
|
61
|
+
Since 12.12.1 `buildCorsConfig()` lists these headers in `exposedHeaders` while `throttler` is configured, each with
|
|
62
|
+
`-<name>` for a throttler other than `default` (the names `@nestjs/throttler` sets). Nothing changes with `throttler`
|
|
63
|
+
unset, `{ enabled: false }` or `setHeaders: false`, and the allowed origins and credentials stay exactly as before.
|
|
64
|
+
`throttlerResponseHeaders(config)` returns the list.
|
|
65
|
+
|
|
66
|
+
A project that builds its CORS options itself adds them:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { throttlerResponseHeaders } from '@lenne.tech/nest-server';
|
|
70
|
+
|
|
71
|
+
app.enableCors({
|
|
72
|
+
credentials: true,
|
|
73
|
+
exposedHeaders: throttlerResponseHeaders(envConfig.throttler),
|
|
74
|
+
origin: ['https://app.example.com'],
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Compatibility Notes
|
|
79
|
+
|
|
80
|
+
| Pattern | Status |
|
|
81
|
+
|---|---|
|
|
82
|
+
| npm mode | Unchanged (`migrate create` keeps `@lenne.tech/nest-server`) |
|
|
83
|
+
| Vendor mode, `migrate create` without a build | Unchanged |
|
|
84
|
+
| Vendor mode, `migrate create` with a build in `dist/` | Writes the source core instead of the build |
|
|
85
|
+
| No `throttler` | CORS unchanged |
|
|
86
|
+
| `throttler` with `buildCorsConfig()` in `main.ts` | `Access-Control-Expose-Headers` lists the rate limit headers |
|
|
87
|
+
| Own CORS options in `main.ts` | Unchanged until the project adds `exposedHeaders` |
|
|
88
|
+
|
|
89
|
+
## Troubleshooting
|
|
90
|
+
|
|
91
|
+
| Symptom | Cause | Fix |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `migrate up` fails with `Cannot find module '../dist/src/core/index.js'` | the migration was created by 12.12.0 or earlier while a build existed | Change the import to `'../src/core/index.js'` (`'../src/core'` in a CommonJS project) |
|
|
94
|
+
| The app shows the `429` but cannot read `Retry-After` | the project builds its own CORS options | Add `exposedHeaders: throttlerResponseHeaders(envConfig.throttler)` |
|
|
95
|
+
|
|
96
|
+
## Module Documentation
|
|
97
|
+
|
|
98
|
+
- `src/core/modules/migrate/README.md`: framework import in vendor-mode migrations
|
|
99
|
+
- `src/core/modules/throttler/README.md`: "Reading the headers from another origin"
|
|
100
|
+
- `src/core/common/helpers/cookies.helper.ts`: `buildCorsConfig()`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.12.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": [
|
|
@@ -106,16 +106,17 @@
|
|
|
106
106
|
"@as-integrations/express5": "1.1.2",
|
|
107
107
|
"@getbrevo/brevo": "6.2.0",
|
|
108
108
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
109
|
-
"@nestjs/apollo": "14.2.
|
|
110
|
-
"@nestjs/common": "12.6.
|
|
111
|
-
"@nestjs/core": "12.6.
|
|
112
|
-
"@nestjs/graphql": "14.2.
|
|
109
|
+
"@nestjs/apollo": "14.2.2",
|
|
110
|
+
"@nestjs/common": "12.6.3",
|
|
111
|
+
"@nestjs/core": "12.6.3",
|
|
112
|
+
"@nestjs/graphql": "14.2.2",
|
|
113
113
|
"@nestjs/jwt": "12.0.5",
|
|
114
114
|
"@nestjs/passport": "12.0.2",
|
|
115
|
-
"@nestjs/platform-express": "12.6.
|
|
115
|
+
"@nestjs/platform-express": "12.6.3",
|
|
116
116
|
"@nestjs/schedule": "12.0.4",
|
|
117
|
-
"@nestjs/swagger": "12.1.
|
|
117
|
+
"@nestjs/swagger": "12.1.3",
|
|
118
118
|
"@nestjs/terminus": "12.2.0",
|
|
119
|
+
"@nestjs/throttler": "6.8.0",
|
|
119
120
|
"@tus/file-store": "2.1.2",
|
|
120
121
|
"@tus/server": "2.4.7",
|
|
121
122
|
"@types/supertest": "7.2.1",
|
|
@@ -244,20 +245,20 @@
|
|
|
244
245
|
}
|
|
245
246
|
},
|
|
246
247
|
"devDependencies": {
|
|
247
|
-
"@aws-sdk/client-s3": "3.
|
|
248
|
-
"@aws-sdk/lib-storage": "3.
|
|
249
|
-
"@aws-sdk/s3-request-presigner": "3.
|
|
250
|
-
"@better-auth/core": "1.7.
|
|
251
|
-
"@better-auth/passkey": "1.7.
|
|
248
|
+
"@aws-sdk/client-s3": "3.1179.0",
|
|
249
|
+
"@aws-sdk/lib-storage": "3.1179.0",
|
|
250
|
+
"@aws-sdk/s3-request-presigner": "3.1179.0",
|
|
251
|
+
"@better-auth/core": "1.7.29",
|
|
252
|
+
"@better-auth/passkey": "1.7.29",
|
|
252
253
|
"@compodoc/compodoc": "2.0.0",
|
|
253
254
|
"@modelcontextprotocol/server": "2.4.0",
|
|
254
255
|
"@nestjs/ai": "0.0.2",
|
|
255
256
|
"@nestjs/cli": "12.0.15",
|
|
256
|
-
"@nestjs/mcp": "0.0.
|
|
257
|
-
"@nestjs/mongoose": "12.0.
|
|
257
|
+
"@nestjs/mcp": "0.0.5",
|
|
258
|
+
"@nestjs/mongoose": "12.0.2",
|
|
258
259
|
"@nestjs/resilience": "0.0.3",
|
|
259
|
-
"@nestjs/schematics": "12.0.
|
|
260
|
-
"@nestjs/testing": "12.6.
|
|
260
|
+
"@nestjs/schematics": "12.0.17",
|
|
261
|
+
"@nestjs/testing": "12.6.3",
|
|
261
262
|
"@swc/cli": "0.8.2",
|
|
262
263
|
"@swc/core": "1.16.22",
|
|
263
264
|
"@tus/s3-store": "2.1.0",
|
|
@@ -267,15 +268,15 @@
|
|
|
267
268
|
"@types/ejs": "3.1.5",
|
|
268
269
|
"@types/express": "5.0.6",
|
|
269
270
|
"@types/http-errors": "2.0.5",
|
|
270
|
-
"@types/lodash": "4.17.
|
|
271
|
+
"@types/lodash": "4.17.28",
|
|
271
272
|
"@types/multer": "2.3.0",
|
|
272
|
-
"@types/node": "26.6.
|
|
273
|
+
"@types/node": "26.6.11",
|
|
273
274
|
"@types/object-path": "0.11.4",
|
|
274
275
|
"@types/passport": "1.0.17",
|
|
275
276
|
"@types/pg": "8.23.1",
|
|
276
|
-
"@vitest/coverage-v8": "5.1.
|
|
277
|
-
"ai": "7.0.
|
|
278
|
-
"better-auth": "1.7.
|
|
277
|
+
"@vitest/coverage-v8": "5.1.2",
|
|
278
|
+
"ai": "7.0.184",
|
|
279
|
+
"better-auth": "1.7.29",
|
|
279
280
|
"bullmq": "6.7.10",
|
|
280
281
|
"cross-env": "10.1.0",
|
|
281
282
|
"drizzle-orm": "1.0.0-rc.5",
|
|
@@ -298,8 +299,8 @@
|
|
|
298
299
|
"typeorm": "1.1.3",
|
|
299
300
|
"typescript": "6.0.3",
|
|
300
301
|
"unplugin-swc": "2.0.0",
|
|
301
|
-
"vite": "8.
|
|
302
|
-
"vitest": "5.1.
|
|
302
|
+
"vite": "8.4.0",
|
|
303
|
+
"vitest": "5.1.2",
|
|
303
304
|
"zod": "4.6.7"
|
|
304
305
|
},
|
|
305
306
|
"main": "dist/index.js",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Response } from 'express';
|
|
2
2
|
|
|
3
3
|
import type { ICookiesConfig, ICorsConfig, IServerOptions } from '../interfaces/server-options.interface.js';
|
|
4
|
+
import { throttlerResponseHeaders } from '../../modules/throttler/core-throttler.constants.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Module-scoped cache of `process.env.NODE_ENV === 'production'`.
|
|
@@ -561,6 +562,10 @@ export function resolveServerUrls(input: {
|
|
|
561
562
|
* `appUrl`/`baseUrl` are resolved via {@link resolveServerUrls}, the same function BetterAuth
|
|
562
563
|
* uses, so all three CORS layers (GraphQL, REST, BetterAuth `trustedOrigins`) agree.
|
|
563
564
|
*
|
|
565
|
+
* With `throttler` configured (12.12.0+) the config also carries `exposedHeaders`: `Retry-After` and `X-RateLimit-*`
|
|
566
|
+
* (`throttlerResponseHeaders()`). A browser hides response headers outside a short safe list from a script on another
|
|
567
|
+
* origin, so an app on its own host saw the 429 but not how long to wait.
|
|
568
|
+
*
|
|
564
569
|
* Used by both:
|
|
565
570
|
* - `CoreModule.buildCorsConfig()` for GraphQL (Apollo) CORS
|
|
566
571
|
* - `main.ts` reference implementation for REST (Express) CORS
|
|
@@ -589,9 +594,14 @@ export function buildCorsConfig(options: Partial<IServerOptions>): Record<string
|
|
|
589
594
|
|
|
590
595
|
const corsObj = typeof options?.cors === 'object' ? options.cors : {};
|
|
591
596
|
|
|
597
|
+
// Response headers a script on the app's origin must be able to read (the rate limit's wait time)
|
|
598
|
+
const exposed = throttlerResponseHeaders(options?.throttler);
|
|
599
|
+
const withExposedHeaders = (cors: Record<string, unknown>): Record<string, unknown> =>
|
|
600
|
+
exposed.length ? { ...cors, exposedHeaders: exposed } : cors;
|
|
601
|
+
|
|
592
602
|
// allowAll → mirror request origin (explicit opt-in for dev/test)
|
|
593
603
|
if (corsObj.allowAll) {
|
|
594
|
-
return { credentials: true, origin: true };
|
|
604
|
+
return withExposedHeaders({ credentials: true, origin: true });
|
|
595
605
|
}
|
|
596
606
|
|
|
597
607
|
// Build origin list from the shared URL resolution (appUrl auto-derived from baseUrl,
|
|
@@ -618,7 +628,7 @@ export function buildCorsConfig(options: Partial<IServerOptions>): Record<string
|
|
|
618
628
|
const uniqueOrigins = [...new Set(origins)];
|
|
619
629
|
|
|
620
630
|
if (uniqueOrigins.length > 0) {
|
|
621
|
-
return { credentials: true, origin: uniqueOrigins };
|
|
631
|
+
return withExposedHeaders({ credentials: true, origin: uniqueOrigins });
|
|
622
632
|
}
|
|
623
633
|
|
|
624
634
|
// No origins resolvable → return empty (secure default — no open CORS with credentials)
|