@lenne.tech/nest-server 12.11.2 → 12.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/.claude/rules/architecture.md +3 -0
  2. package/.claude/rules/configurable-features.md +6 -0
  3. package/.claude/rules/package-management.md +6 -4
  4. package/.claude/rules/role-system.md +8 -0
  5. package/.claude/rules/testing.md +8 -7
  6. package/CLAUDE.md +2 -1
  7. package/FRAMEWORK-API.md +15 -1
  8. package/dist/core/common/decorators/common-error.decorator.d.ts +1 -1
  9. package/dist/core/common/interfaces/server-options.interface.d.ts +54 -0
  10. package/dist/core/common/persistence/audit-log.registry.d.ts +19 -0
  11. package/dist/core/common/persistence/audit-log.registry.js +84 -0
  12. package/dist/core/common/persistence/audit-log.registry.js.map +1 -0
  13. package/dist/core/common/persistence/policies/tenant.policy.js +3 -1
  14. package/dist/core/common/persistence/policies/tenant.policy.js.map +1 -1
  15. package/dist/core/common/services/core-trust-proxy.initializer.js +1 -1
  16. package/dist/core/common/services/core-trust-proxy.initializer.js.map +1 -1
  17. package/dist/core/common/services/crud.service.d.ts +10 -0
  18. package/dist/core/common/services/crud.service.js +79 -24
  19. package/dist/core/common/services/crud.service.js.map +1 -1
  20. package/dist/core/common/services/email.service.d.ts +5 -0
  21. package/dist/core/common/services/email.service.js +82 -6
  22. package/dist/core/common/services/email.service.js.map +1 -1
  23. package/dist/core/common/services/leased-interval.d.ts +22 -0
  24. package/dist/core/common/services/leased-interval.js +81 -0
  25. package/dist/core/common/services/leased-interval.js.map +1 -0
  26. package/dist/core/common/services/mail-outbox.registry.d.ts +26 -0
  27. package/dist/core/common/services/mail-outbox.registry.js +8 -0
  28. package/dist/core/common/services/mail-outbox.registry.js.map +1 -0
  29. package/dist/core/modules/audit-log/audited.decorator.d.ts +2 -0
  30. package/dist/core/modules/audit-log/audited.decorator.js +10 -0
  31. package/dist/core/modules/audit-log/audited.decorator.js.map +1 -0
  32. package/dist/core/modules/audit-log/core-audit-log.constants.d.ts +13 -0
  33. package/dist/core/modules/audit-log/core-audit-log.constants.js +11 -0
  34. package/dist/core/modules/audit-log/core-audit-log.constants.js.map +1 -0
  35. package/dist/core/modules/audit-log/core-audit-log.controller.d.ts +9 -0
  36. package/dist/core/modules/audit-log/core-audit-log.controller.js +87 -0
  37. package/dist/core/modules/audit-log/core-audit-log.controller.js.map +1 -0
  38. package/dist/core/modules/audit-log/core-audit-log.models.d.ts +10 -0
  39. package/dist/core/modules/audit-log/core-audit-log.models.js +11 -0
  40. package/dist/core/modules/audit-log/core-audit-log.models.js.map +1 -0
  41. package/dist/core/modules/audit-log/core-audit-log.module.d.ts +13 -0
  42. package/dist/core/modules/audit-log/core-audit-log.module.js +41 -0
  43. package/dist/core/modules/audit-log/core-audit-log.module.js.map +1 -0
  44. package/dist/core/modules/audit-log/core-audit-log.service.d.ts +49 -0
  45. package/dist/core/modules/audit-log/core-audit-log.service.js +169 -0
  46. package/dist/core/modules/audit-log/core-audit-log.service.js.map +1 -0
  47. package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js +4 -0
  48. package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js.map +1 -1
  49. package/dist/core/modules/mail-outbox/core-mail-outbox.constants.d.ts +22 -0
  50. package/dist/core/modules/mail-outbox/core-mail-outbox.constants.js +23 -0
  51. package/dist/core/modules/mail-outbox/core-mail-outbox.constants.js.map +1 -0
  52. package/dist/core/modules/mail-outbox/core-mail-outbox.controller.d.ts +10 -0
  53. package/dist/core/modules/mail-outbox/core-mail-outbox.controller.js +80 -0
  54. package/dist/core/modules/mail-outbox/core-mail-outbox.controller.js.map +1 -0
  55. package/dist/core/modules/mail-outbox/core-mail-outbox.models.d.ts +17 -0
  56. package/dist/core/modules/mail-outbox/core-mail-outbox.models.js +17 -0
  57. package/dist/core/modules/mail-outbox/core-mail-outbox.models.js.map +1 -0
  58. package/dist/core/modules/mail-outbox/core-mail-outbox.module.d.ts +12 -0
  59. package/dist/core/modules/mail-outbox/core-mail-outbox.module.js +42 -0
  60. package/dist/core/modules/mail-outbox/core-mail-outbox.module.js.map +1 -0
  61. package/dist/core/modules/mail-outbox/core-mail-outbox.service.d.ts +59 -0
  62. package/dist/core/modules/mail-outbox/core-mail-outbox.service.js +280 -0
  63. package/dist/core/modules/mail-outbox/core-mail-outbox.service.js.map +1 -0
  64. package/dist/core/modules/migrate/cli/migrate-cli.js +20 -2
  65. package/dist/core/modules/migrate/cli/migrate-cli.js.map +1 -1
  66. package/dist/core/modules/throttler/core-throttler.config.d.ts +16 -0
  67. package/dist/core/modules/throttler/core-throttler.config.js +107 -0
  68. package/dist/core/modules/throttler/core-throttler.config.js.map +1 -0
  69. package/dist/core/modules/throttler/core-throttler.constants.d.ts +10 -0
  70. package/dist/core/modules/throttler/core-throttler.constants.js +11 -0
  71. package/dist/core/modules/throttler/core-throttler.constants.js.map +1 -0
  72. package/dist/core/modules/throttler/core-throttler.decorators.d.ts +1 -0
  73. package/dist/core/modules/throttler/core-throttler.decorators.js +2 -0
  74. package/dist/core/modules/throttler/core-throttler.decorators.js.map +1 -0
  75. package/dist/core/modules/throttler/core-throttler.guard.d.ts +15 -0
  76. package/dist/core/modules/throttler/core-throttler.guard.js +65 -0
  77. package/dist/core/modules/throttler/core-throttler.guard.js.map +1 -0
  78. package/dist/core/modules/throttler/core-throttler.models.d.ts +1 -0
  79. package/dist/core/modules/throttler/core-throttler.models.js +11 -0
  80. package/dist/core/modules/throttler/core-throttler.models.js.map +1 -0
  81. package/dist/core/modules/throttler/core-throttler.module.d.ts +12 -0
  82. package/dist/core/modules/throttler/core-throttler.module.js +71 -0
  83. package/dist/core/modules/throttler/core-throttler.module.js.map +1 -0
  84. package/dist/core/modules/throttler/core-throttler.storages.d.ts +43 -0
  85. package/dist/core/modules/throttler/core-throttler.storages.js +174 -0
  86. package/dist/core/modules/throttler/core-throttler.storages.js.map +1 -0
  87. package/dist/core/modules/user/core-user.service.js +2 -2
  88. package/dist/core/modules/user/core-user.service.js.map +1 -1
  89. package/dist/core.module.js +26 -0
  90. package/dist/core.module.js.map +1 -1
  91. package/dist/index.d.ts +21 -0
  92. package/dist/index.js +21 -0
  93. package/dist/index.js.map +1 -1
  94. package/docs/REQUEST-LIFECYCLE.md +10 -3
  95. package/docs/security-overrides.md +20 -8
  96. package/migration-guides/12.11.2-to-12.11.3.md +96 -0
  97. package/migration-guides/12.11.x-to-12.12.x.md +182 -0
  98. package/package.json +28 -27
  99. package/src/core/common/interfaces/server-options.interface.ts +311 -1
  100. package/src/core/common/persistence/audit-log.registry.ts +150 -0
  101. package/src/core/common/persistence/policies/tenant.policy.ts +10 -5
  102. package/src/core/common/services/core-trust-proxy.initializer.ts +5 -4
  103. package/src/core/common/services/crud.service.ts +128 -33
  104. package/src/core/common/services/email.service.ts +101 -9
  105. package/src/core/common/services/leased-interval.ts +123 -0
  106. package/src/core/common/services/mail-outbox.registry.ts +53 -0
  107. package/src/core/modules/audit-log/README.md +95 -0
  108. package/src/core/modules/audit-log/audited.decorator.ts +27 -0
  109. package/src/core/modules/audit-log/core-audit-log.constants.ts +28 -0
  110. package/src/core/modules/audit-log/core-audit-log.controller.ts +77 -0
  111. package/src/core/modules/audit-log/core-audit-log.models.ts +34 -0
  112. package/src/core/modules/audit-log/core-audit-log.module.ts +54 -0
  113. package/src/core/modules/audit-log/core-audit-log.service.ts +270 -0
  114. package/src/core/modules/better-auth/README.md +18 -0
  115. package/src/core/modules/better-auth/core-better-auth-email-verification.service.ts +4 -0
  116. package/src/core/modules/mail-outbox/README.md +88 -0
  117. package/src/core/modules/mail-outbox/core-mail-outbox.constants.ts +42 -0
  118. package/src/core/modules/mail-outbox/core-mail-outbox.controller.ts +60 -0
  119. package/src/core/modules/mail-outbox/core-mail-outbox.models.ts +46 -0
  120. package/src/core/modules/mail-outbox/core-mail-outbox.module.ts +52 -0
  121. package/src/core/modules/mail-outbox/core-mail-outbox.service.ts +390 -0
  122. package/src/core/modules/migrate/README.md +4 -1
  123. package/src/core/modules/migrate/cli/migrate-cli.ts +30 -2
  124. package/src/core/modules/system-setup/README.md +4 -0
  125. package/src/core/modules/tenant/INTEGRATION-CHECKLIST.md +3 -3
  126. package/src/core/modules/tenant/README.md +4 -4
  127. package/src/core/modules/throttler/README.md +107 -0
  128. package/src/core/modules/throttler/core-throttler.config.ts +162 -0
  129. package/src/core/modules/throttler/core-throttler.constants.ts +33 -0
  130. package/src/core/modules/throttler/core-throttler.decorators.ts +14 -0
  131. package/src/core/modules/throttler/core-throttler.guard.ts +109 -0
  132. package/src/core/modules/throttler/core-throttler.models.ts +23 -0
  133. package/src/core/modules/throttler/core-throttler.module.ts +95 -0
  134. package/src/core/modules/throttler/core-throttler.storages.ts +299 -0
  135. package/src/core/modules/user/core-user.service.ts +3 -2
  136. package/src/core.module.ts +46 -0
  137. package/src/index.ts +36 -0
@@ -61,6 +61,7 @@ proves the build loads and runs with them unresolvable. Rules: `.claude/rules/pe
61
61
 
62
62
  | Module | Purpose |
63
63
  |--------|---------|
64
+ | **AuditLog** | Opt-in (`auditLog`): who created, changed, deleted or restored which record of the models carrying `@Audited()` / named in `auditLog.models`, field names only, never values; `CrudService` reports through `common/persistence/audit-log.registry.ts`; `GET /audit-log` for admins, retention purge |
64
65
  | **ApiToken** | Opt-in bearer tokens: USER tokens (act as their user, no global roles) and TENANT tokens (lowest tenant role, own tenant only); deny by default via `@ApiTokenScopes()`; signed short-lived assertions |
65
66
  | **Auth** | JWT authentication, refresh tokens, role-based access |
66
67
  | **BetterAuth** | Modern auth integration (2FA, Passkey, Social) |
@@ -68,10 +69,12 @@ proves the build loads and runs with them unresolvable. Rules: `.claude/rules/pe
68
69
  | **File** | File upload/download with GridFS storage |
69
70
  | **HealthCheck** | Application health monitoring |
70
71
  | **Hub** | Build-free ADMIN-gated operator cockpit at `/hub` (config-gated per environment; 17 panels, runtime collectors, mailbox, admin actions) |
72
+ | **MailOutbox** | Opt-in (`mailOutbox`): every `EmailService` mail stored first, delivered by exactly one replica (atomic claim), retried with backoff, failed mails listed for admins |
71
73
  | **Migrate** | Database migration utilities |
72
74
  | **Permissions** | ADMIN-gated security-map report (routes + roles + `@Restricted` fields); also surfaced in the Hub's "Routes / Permissions" panel |
73
75
  | **Sync** | Opt-in (`sync`) offline sync for models declared `@PersistedModel({ sync })`: pull by cursor, push with idempotency and conflict strategies, resync on access loss — through the model's CrudService; change hints over SSE and GraphQL, filtered per subscriber; hourly tombstone purge under a lease |
74
76
  | **SystemSetup** | Initial admin creation for fresh deployments |
77
+ | **Throttler** | Opt-in (`throttler`): rate limit for a project's routes on top of `@nestjs/throttler` (`@Throttle()` / `@SkipThrottle()`), first global guard, counters in memory, Redis or the project's database |
75
78
  | **Tus** | Resumable file uploads via tus.io protocol |
76
79
  | **User** | Core user management functionality |
77
80
 
@@ -303,6 +303,9 @@ This pattern is currently applied to:
303
303
  | SMTP TLS Mode | `email.smtp.secure` + `SMTP_REQUIRE_TLS` | Derived from the port | **`secure` follows `SMTP_PORT` unless set to `'true'`/`'false'`.** It is not an independent setting: 465 negotiates TLS immediately, everything else upgrades via STARTTLS. The production profile shipped 587 + `secure: true` — a pair that cannot connect — so a deployment configuring only host and credentials sent NO mail, invisibly, because authentication mail is not awaited. Only the two canonical values override; anything else defers to the port, which is the only rule under which no input produces an unconnectable pair. `requireTLS` defaults to **true**: `secure: false` alone means opportunistic STARTTLS, and an on-path attacker stripping the capability line gets credentials and a live reset link in plaintext. `EmailService` warns once when the resolved pair cannot connect — reported, not overruled. Implementation: `config.helper.ts` → `resolveSmtpSecure()` / `isImpossibleSmtpTlsCombination()` |
304
304
  | Mail Reply-To | `email.defaultReplyTo` | Explicit Value — absent = no header | **Absent → no `Reply-To` header, exactly as before (12.3.2+).** A string (an address, or `"Name" <address>`) becomes the Reply-To of every mail `EmailService.sendMail()` sends; a call overrides it with `replyTo`, and `replyTo: false` (or `''`) sends that one mail without it. Env: `NSC__EMAIL__DEFAULT_REPLY_TO`. A value that is not a string is ignored with one warning — a misconfigured default must not stop password-reset or verification mail. SMTP path only (`email.smtp`, nodemailer, Hub capture unaffected): Brevo and Mailjet templates carry their own reply-to. Pinned by `tests/unit/email-smtp-roundtrip.spec.ts` (Reply-To block, real SMTP). Implementation: `common/services/email.service.ts` → `resolveReplyTo()` |
305
305
  | Auth Mail App Name | `betterAuth.emailVerification.appName` | Explicit Value — absent = the `package.json` name | **Absent or empty → the formatted `name` of the working directory's `package.json` (`my-app` → `My App`, `'Nest Server'` without one), exactly as before (12.8.3+).** A string becomes the application name in the verification and password-reset mails: the subject (`<appName> - Verify your email address`, `<appName> - Reset your password`), the EJS variable `appName` and the Brevo parameter `appName`; trimmed. Env: `NSC__BETTER_AUTH__EMAIL_VERIFICATION__APP_NAME`. Exists because in a monorepo the working directory is the API package, whose name (`api`) became the subject of every auth mail; before, only an override of `getAppName()` changed it, which still works and wins. A value that is not a string is ignored with one warning — a misconfigured name must not stop an auth mail. Mails only: authenticator apps read `twoFactor.appName`, passkey prompts `passkey.rpName`. **With verification switched off it needs `enabled: false` beside it** (`{ enabled: false, appName }`, or `NSC__BETTER_AUTH__EMAIL_VERIFICATION__ENABLED=false` next to the variable): `emailVerification: false` keeps no settings, and an object without `enabled: false` — what the variable alone makes of `false` — switches verification on, so every unverified user's sign-in answers 401. The reset mail goes through this service with verification off too. Pinned by `tests/unit/better-auth-mail-app-name.spec.ts` (mutation `mail-app-name-config-ignored`). Implementation: `core-better-auth-email-verification.service.ts` → `resolveAppName()` |
306
+ | Rate Limit for Project Routes | `throttler` | Boolean Shorthand + Presence Implies Enabled — absent = off | **Absent → no guard, no storage, no table (12.12.0, DEV-4431).** `true` / `{}` registers `CoreThrottlerModule` FIRST in `CoreModule`'s imports, so `CoreThrottlerGuard` (`@nestjs/throttler`'s `ThrottlerGuard`, request resolved through `resolveGuardRequest()`) is the first global guard: an over-limit client gets 429, `Retry-After` and `#LTNS_0020` before the role guards authenticate it. Defaults: `limit: 10`, `ttl: 60000` (ms, `@nestjs/throttler`'s unit), `blockDuration: ttl`, `routes: 'decorated'` (only routes whose method or controller carries `@Throttle()`, by the throttlers it names — implemented as a per-throttler `skipIf`; `'all'` limits every route unless `@SkipThrottle()`), `setHeaders: true`, `ipv6SubnetPrefix: 64`; `throttlers: [{ name, limit, ttl, blockDuration }]` replaces the `default` throttler. An invalid number → its default with a warning (Family C: never "no limit", never `0`, which would refuse everything). `storage`: unset → `'redis'` with `redis`, else `'memory'` (`@nestjs/throttler`'s `ThrottlerStorageService`); `'database'` → the framework model `CoreThrottlerCounter` (table `throttler_counters`) through `CorePersistenceModule.forFeature()`, a fixed window per throttler and client counted with ONE atomic `updateOne` per step, exact across replicas without Redis; `'redis'` → one Lua script per hit. An explicit storage that cannot work (`'redis'` without `redis`, `'database'` with `database: false`, an unknown name) stops the boot; an unreachable Redis / database falls back to memory, logged once per transition — never 500, never "allowed". Counted per `request.ip`, so the trust-proxy boot warning lists `throttler` too; 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 (mutation `throttler-skips-addressless-request`). `@Throttle` / `@SkipThrottle` are re-exported from `@lenne.tech/nest-server`; a project must not import `ThrottlerModule` itself. Guard override: `CoreModule.forRoot(env, { throttler: { guard } })`. Pinned by `tests/unit/throttler.spec.ts` and `tests/throttler.e2e-spec.ts` (mutations `throttler-*`). Implementation: `src/core/modules/throttler/` |
307
+ | Audit Log | `auditLog` | Boolean Shorthand + Presence Implies Enabled — absent = off | **Absent → no model, no route, no listener; a write costs one `undefined` check (12.12.0, DEV-4432).** `true` / `{}` registers `CoreAuditLogModule`; its service registers itself in `common/persistence/audit-log.registry.ts`, and `CrudService.create()` / `update()` / `delete()` (variants included, `CoreUserService.create()` too) report each successful write of a model whose class carries `@Audited()` or whose name is in `models` — action, model, record id, user (`serviceOptions.currentUser`, else the request's), time and the field NAMES (create: what the input set; update: what changed, compared before and after the merge, bookkeeping fields excluded; an update that changed nothing leaves no entry). Never a value — the model has no field for one. `CoreAuditLogService.record()` logs a project's own actions (restore); `importEntries()` takes entries of another system (keeps `at`, drops every other field). Model `CoreAuditLogEntry` (table `audit_log_entries`), not tenant-scoped. `retentionDays` (365; `false` keeps; invalid → 365): hourly purge on one replica (`LeasedInterval`, `frameworkJobLeaseStore()`: Redis → SQL lease table → `cron-locks`), 1000 per batch. `GET /audit-log` (`path`), `ADMIN` plus `roles` (global, `@SkipTenantCheck()`). Not logged: writes past `CrudService` (data store, Mongoose, `pushToArray`). Overrides: `{ auditLog: { controller, service } }`. Pinned by `tests/audit-log.e2e-spec.ts` (mutations `audit-log-*`). Implementation: `src/core/modules/audit-log/` |
308
+ | Mail Outbox | `mailOutbox` | Boolean Shorthand + Presence Implies Enabled — absent = off | **Absent → `EmailService` sends directly, as before (12.12.0, DEV-4433).** `true` / `{}` registers `CoreMailOutboxModule`; its service registers itself in `common/services/mail-outbox.registry.ts` and `EmailService.sendMail()` stores the rendered mail (after the templates, the production `jsonTransport` guard and the Hub capture) and answers `{ accepted, messageId, outboxId, queued: true, rejected }`; Better-Auth's SMTP auth mails take the same path. Delivery at once and every `pollIntervalSeconds` (10) on every replica; a mail is CLAIMED with one atomic `updateOne` (pending and due, or a claim older than `lockSeconds`, 900), so exactly one replica sends it, with the same Message-ID on every attempt. Failure → retry after `retryDelaySeconds` (30) doubled per attempt up to `maxRetryDelaySeconds` (3600); after `maxAttempts` (10) `failed`, logged as an error with the recipient masked. A delivered mail loses its content at once (`mail: null`); `retention.sentDays` (7) / `retention.failedDays` (30), `false` keeps, hourly purge under a lease. At least once: a replica dying between the server's accept and the record leaves a claim another replica takes over. Not through the outbox: a call with its own `smtp` (credentials are never stored), Brevo / Mailjet templates. Model `CoreMailOutboxEntry` (table `mail_outbox`). `GET /mail-outbox` (no content), `POST /mail-outbox/:id/retry`; `ADMIN` plus `roles`. Overrides: `{ mailOutbox: { controller, service } }`. Pinned by `tests/mail-outbox.e2e-spec.ts` and `tests/unit/audit-log-outbox.spec.ts` (mutations `mail-outbox-*`). Implementation: `src/core/modules/mail-outbox/` |
306
309
  | Legacy Auth Rate Limiting | `auth.rateLimit` | Presence Implies Enabled | `max: 10`, `windowSeconds: 60`. Counters live in a `RateLimitStore`: `RedisRateLimitStore` when `redis` is configured (limit enforced EXACTLY across replicas instead of `max × replicas`), else `InMemoryRateLimitStore` (previous behavior). On a Redis outage it degrades to the in-memory counter and logs once per transition — never a 500, never "allowed". `check()` / `reset()` / `clear()` are ASYNC since 11.33.0; `getStats().activeEntries` is `-1` on the Redis store |
307
310
  | BetterAuth Rate Limiting | `betterAuth.rateLimit` | Presence Implies Enabled | `max: 10`, `windowSeconds: 60`. Same `RateLimitStore` selection, degradation and async signatures as the Legacy Auth row (namespace `better-auth`) |
308
311
  | BetterAuth JWT Plugin | `betterAuth.jwt` | Boolean Shorthand | `expiresIn: '15m'`. **Since 12.11.0 a JWT is bound to the session it was issued from** (claim `sid`, `definePayload` in `buildPlugins()`): `verifyJwtToken()` accepts it only while that session exists, belongs to the token's `sub` and has not expired — asked through Better-Auth's adapter by id (the user's session list where sessions live only in `secondaryStorage`), cached 10 s (`jwtSessionCacheTtlMs`, protected) in the import-free leaf `core-better-auth-jwt-session.cache.ts` (10,000 entries max), and forgotten at once when Better-Auth deletes the session (`wsSessionRevocationPlugin()` → `jwtSessionEnded()`), on every replica over the user mapper's Redis invalidation channel (`{ sessionId }`). A JWT without `sid` is refused; a failed lookup refuses and is not cached. The middleware hands Better-Auth's plugin routes the JWT's OWN session (`getJwtSession()`), and `POST /iam/sign-out` revokes it — before, the user's newest session, and a JWT client's sign-out read the cookie alone and ended nothing. After a session rotation (first `verify-totp` while enabling 2FA; since 12.11.1 also `two-factor/disable` and enabling with OTP / `skipVerificationOnEnable`, whose answers name no token, recognised by the request's session token that every forwarding hands `sendBetterAuthResponse()`) the answer's token is the JWT of the new session. Pinned by `tests/unit/better-auth-jwt-session-binding.spec.ts` and `tests/better-auth-jwt-session.e2e-spec.ts` (mutations `jwt-session-*`, `jwt-payload-without-session-id`, `jwt-middleware-newest-session`, `jwt-sign-out-reads-cookie-only`) |
@@ -393,6 +396,9 @@ CoreModule.forRoot(CoreAuthService, AuthModule.forRoot(envConfig.jwt), envConfig
393
396
 
394
397
  | Module | Fields | Description |
395
398
  |--------|--------|-------------|
399
+ | `auditLog` | `controller`, `service` | Custom audit log read endpoint and/or service (12.12.0) |
400
+ | `mailOutbox` | `controller`, `service` | Custom mail outbox admin endpoints and/or service (12.12.0) |
401
+ | `throttler` | `guard` | Custom rate limit guard extending `CoreThrottlerGuard` (12.12.0) |
396
402
  | `ai` | `budgetService`, `connectionResolver`, `connectionService`, `controller`, `conversationService`, `interactionService`, `mcpClientService`, `mcpOAuthService`, `modeService`, `placeholderRegistry`, `preferenceService`, `promptBuilder`, `promptHintService`, `promptService`, `resolver`, `service`, `slotService`, `toolGrantService`, `toolPolicyService`, `userSettingService` | Custom AI orchestrator, connection-resolution chain, connection/preference/budget/conversation/interaction/MCP-client services, MCP OAuth service (the consent step), slot + user-prompt + learning-hint stores, mode service, placeholder registry, tool-grant + tool-policy services, personal-settings store, endpoints |
397
403
  | `errorCode` | `controller`, `service` | Custom error code endpoint and/or service |
398
404
  | `healthCheck` | `readinessController`, `service` | Custom health check service (project checks via `additionalHealthIndicators(kind)`) and/or readiness controller (12.11.0) |
@@ -174,12 +174,14 @@ load-bearing (it has since grown back to as many as 20, mostly as new advisories
174
174
  and they were removed, leaving `@graphql-tools/utils` and `multer`, both on an upstream EXACT pin with
175
175
  an open advisory. Those two left on 2026-10-29 (nest-server 12.1.0), once `@nestjs/graphql` 14.1.0 and
176
176
  `@nestjs/platform-express` 12.3.2 moved their pins past the fixes: the set was empty (`overrides: {}`,
177
- written explicitly so `check:overrides` reads it as a decision) from 12.1.0 to 12.9.3. Since 12.9.4 it holds one
178
- entry, `ws`: GHSA-37g9-w4hg-h9qr (high, pre-auth memory-exhaustion DoS, patched 8.23.0) covers the 8.22.1 that
179
- `@nestjs/graphql` 14.2.1 exact-pins, and the GraphQL WebSocket server runs on that copy. The advisory was published
177
+ written explicitly so `check:overrides` reads it as a decision) from 12.1.0 to 12.9.3. From 12.9.4 to 12.11.3 it held
178
+ `ws`: GHSA-37g9-w4hg-h9qr (high, pre-auth memory-exhaustion DoS, patched 8.23.0) covered the 8.22.1 that
179
+ `@nestjs/graphql` 14.2.1 exact-pinned, and the GraphQL WebSocket server ran on that copy. The advisory was published
180
180
  by the ws maintainers on 2026-11-12 and was not yet in GitHub's global database when the entry was added, so
181
181
  `pnpm audit` did not report it — read the advisories of a package's own repository when a release announces a
182
- security fix. Its target moves in lockstep with the declared `ws` dependency (`docs/security-overrides.md`). From 12.10.0 to 12.10.1 a second entry, `minimatch` 11 -> 11.0.9: `@nestjs/cli` 12.0.13 exact-pins 11.0.5, covered by three moderate advisories (dev tooling only; the target is the newest 11.x, because an older one held every other `^11` consumer back). It left in 12.11.0, once `@nestjs/cli` 12.0.15 pinned 11.0.9 itself. Since 12.10.0 a second entry, `i18next` 26 -> 26.4.4: `@compodoc/compodoc` 2.0.0 exact-pins 26.3.3, covered by two repository advisories that were not yet in GitHub's global database (dev tooling only). An override is only necessary if removing it lets the package resolve
182
+ security fix. It left in 12.12.0, once `@nestjs/graphql` 14.2.2 pinned ws 8.23.0 itself (two fresh resolves with and
183
+ without the entry: identical package set, one `ws@8.23.0`). `check:overrides` could not report it as UNUSED: every
184
+ edge resolved to the override's target either way, so only the with/without resolve shows such an entry is inert. From 12.10.0 to 12.10.1 a second entry, `minimatch` 11 -> 11.0.9: `@nestjs/cli` 12.0.13 exact-pins 11.0.5, covered by three moderate advisories (dev tooling only; the target is the newest 11.x, because an older one held every other `^11` consumer back). It left in 12.11.0, once `@nestjs/cli` 12.0.15 pinned 11.0.9 itself. Since 12.10.0 the set holds `i18next` 26 -> 26.4.4 (its only entry since 12.12.0): `@compodoc/compodoc` 2.0.0 exact-pins 26.3.3, covered by two advisories (dev tooling only); GHSA-6jcc is in GitHub's global database since 2026-11-23, GHSA-5jr9 was still repository-only at 12.12.0. An override is only necessary if removing it lets the package resolve
183
185
  back INTO its vulnerable range (verify with a with/without lockfile diff; `pnpm audit` is the arbiter).
184
186
  "Cheap insurance against a parent re-pinning downwards" is not a reason to keep one: `pnpm audit` and
185
187
  `check:overrides` run on every `check` and report such a regression the day it happens. Each surviving entry carries its CVE rationale as a comment. Remove an entry once its parent dependency ships a fixed version.
@@ -540,6 +540,14 @@ permission error returned as 401 kicks a logged-in user out of the whole app.
540
540
  `S_NO_ONE` is 403 even without a session because authenticating can *never* unlock it — a 401 would
541
541
  tell the client to log in and retry, which is a lie.
542
542
 
543
+ "Not authenticated" includes a session that has ENDED: a browser keeps sending the cookie of an expired session, and
544
+ the API answers it like no cookie at all. Since 12.11.3 the tenant safety net (`resolveTenantFilter()`) follows the
545
+ rule too — 401 for a client operation nobody is signed in to, 403 for a signed-in caller and for server work; before,
546
+ it answered 403 to everyone, so a frontend with an expired session reading tenant data from a public route showed an
547
+ error instead of the sign-in (DEV-4393). Pinned against both role guards, REST and GraphQL, by
548
+ `tests/session-expired-status.e2e-spec.ts` (`RolesGuard`) and `tests/session-expired-status-iam.e2e-spec.ts`
549
+ (`BetterAuthRolesGuard`); the cases live in `tests/helpers/session-expiry-cases.ts`.
550
+
543
551
  Exception: `ErrorCode.EMAIL_VERIFICATION_REQUIRED` is a legitimate **401** (thrown at sign-in, where
544
552
  no session exists yet). Frontends must branch on the ErrorCode, not on the status alone, so this one
545
553
  does not trigger the logout flow.
@@ -34,7 +34,7 @@ mis-named suite fails the build instead of silently passing. Type-only tests
34
34
 
35
35
  ## Infrastructure containers (Redis + S3 + PostgreSQL + MySQL + MariaDB + MongoDB replica set)
36
36
 
37
- **Twenty-two** e2e suites talk to a **real** Redis, a **real** S3-compatible store and/or a **real**
37
+ **Twenty-three** e2e suites talk to a **real** Redis, a **real** S3-compatible store and/or a **real**
38
38
  PostgreSQL, MySQL, MariaDB or MongoDB replica set rather than a mock, and they **fail loudly** when it is missing — a silently skipped
39
39
  infrastructure test is how an untested driver ships:
40
40
 
@@ -62,13 +62,14 @@ infrastructure test is how an untested driver ships:
62
62
  | `tests/persistence-mysql-wiring.e2e-spec.ts` | MySQL + MariaDB |
63
63
  | `tests/sync-contract.e2e-spec.ts` | PostgreSQL + MySQL + MariaDB + MongoDB replica set (and MongoDB) |
64
64
  | `tests/sync-clock-skew.e2e-spec.ts` | PostgreSQL + MySQL + MongoDB replica set (and MongoDB) |
65
+ | `tests/throttler.e2e-spec.ts` | Redis (its Redis describes; the memory and database describes need only the run's database) |
65
66
 
66
- Beyond these twenty-two, the `postgres` vitest project runs the whole e2e suite once more on PostgreSQL (see "Behaviour
67
+ Beyond these twenty-three, the `postgres` vitest project runs the whole e2e suite once more on PostgreSQL (see "Behaviour
67
68
  matrices" below), so without the PostgreSQL container that project fails as a whole while `e2e` runs.
68
69
 
69
70
  `tests/global-setup.ts` starts all six containers automatically, so `pnpm test` works from a clean
70
71
  machine with no manual docker command. It is idempotent (a running container is reused) and never
71
- fatal: without Docker every other suite still runs, and the twenty-two above report their own actionable
72
+ fatal: without Docker every other suite still runs, and the twenty-three above report their own actionable
72
73
  error.
73
74
 
74
75
  ```bash
@@ -412,7 +413,7 @@ pnpm run check:mutations -- --id=<id> # one mutation
412
413
  pnpm run check:mutations -- --list # the registry, without running anything
413
414
  pnpm run check:mutations -- --allow-dirty # when the fix and its evidence share a working tree
414
415
  pnpm run check:mutations -- --jobs=4 # N mutations at a time (default: 2, or 4 on >=12 cores)
415
- pnpm run check:mutations -- --no-infra # only the 518 that need no MongoDB
416
+ pnpm run check:mutations -- --no-infra # only the 529 that need no MongoDB
416
417
  pnpm run check:mutations -- --since=<ref> # only mutations touching files changed since <ref>
417
418
  pnpm run check:mutations -- --shard=2/4 # this job's quarter of the selection (CI splits the full run)
418
419
  ```
@@ -432,7 +433,7 @@ when the registry, a vitest config or a setup file changed, since those can move
432
433
  commit, and in CI alongside the publish without blocking it. The price of caching is a cache that
433
434
  has to model each spec's full dependency closure correctly, and getting that wrong produces a stale
434
435
  PASS for a test that has since gone vacuous — exactly what the gate is there to prevent. Bad trade
435
- at 768 mutations.
436
+ at 787 mutations.
436
437
 
437
438
  **Decided 2026-10-03 (repo owner): keep the full run.** Measured at 128 mutations, the CI job for
438
439
  11.41.6 took **14 minutes**. The trigger to revisit is that wall time, not the mutation count —
@@ -503,9 +504,9 @@ exactly the environment where the answer matters.
503
504
 
504
505
  ### The cost is vitest's cold start, not the tests
505
506
 
506
- Worth knowing before optimising the wrong thing: the specs behind all 250 e2e mutations add up to
507
+ Worth knowing before optimising the wrong thing: the specs behind all 258 e2e mutations add up to
507
508
  **~40 seconds**. The step takes ~740s. The remaining ~700s is paying vitest's startup — process
508
- spawn, transform, module graph, mongod connect, DB create and drop — once per mutation, 768 times.
509
+ spawn, transform, module graph, mongod connect, DB create and drop — once per mutation, 787 times.
509
510
  That work is largely single-threaded I/O and barely scales with cores: the full registry measures
510
511
  **744s on a 12-core laptop and 777s on a 4-vCPU CI runner**.
511
512
 
package/CLAUDE.md CHANGED
@@ -214,10 +214,11 @@ contents into a tracked file, a commit message or a PR. Pinned by `tests/unit/pu
214
214
  **Key Components:**
215
215
  - `CoreModule` - Dynamic module with GraphQL (optional, disable via `graphQl: false`), MongoDB, security
216
216
  - `src/core/common/` - Decorators, helpers, interceptors, services
217
- - `src/core/modules/` - ApiToken, Auth, BetterAuth, ErrorCode, File, HealthCheck, Hub, Migrate, Permissions, Sync, SystemSetup, Tus, User
217
+ - `src/core/modules/` - ApiToken, AuditLog, Auth, BetterAuth, ErrorCode, File, HealthCheck, Hub, MailOutbox, Migrate, Permissions, Sync, SystemSetup, Throttler, Tus, User
218
218
  - **ApiToken** - Opt-in (`apiTokens`) USER and TENANT tokens + signed assertions. Denied on every route without `@ApiTokenScopes()`; all three guards share `enforceApiTokenRoute()`. See `src/core/modules/api-token/README.md`.
219
219
  - **Hub** - Build-free ADMIN-gated operator cockpit at `/hub` (config-gated per environment; 17 panels, runtime collectors, mailbox, admin actions). See `src/core/modules/hub/README.md`.
220
220
  - **Permissions** - ADMIN-gated security-map report (routes + roles + `@Restricted` fields); also surfaced in the Hub's "Routes / Permissions" panel.
221
+ - **AuditLog / MailOutbox / Throttler** (12.12.0) - Opt-in (`auditLog`, `mailOutbox`, `throttler`): who changed which record (field names, never values, reported by `CrudService`); every mail stored first and delivered by exactly one replica with retries; a rate limit for a project's routes on `@nestjs/throttler` with counters in memory, Redis or the database. Absent config = nothing registered. See each module's README.
221
222
  - **Sync** - Opt-in (`sync`) offline sync: `GET/POST /sync/{model}` for models declared `@PersistedModel({ sync })` whose CrudService carries `@SyncService()`, change hints over SSE (`GET /sync/hints`) and GraphQL (`syncHint`), hourly tombstone purge; protocol in `docs/offline-sync-protocol.md`, client duties in the module's `SECURITY.md`, reference test clients in `tests/clients/`. See `src/core/modules/sync/README.md`.
222
223
  - **Optional central infrastructure** (11.33.0+) - `CoreRedisService` (`redis` config) and `CoreS3Service` (`s3` config) turn process-local state into shared state for multi-replica deployments: rate-limit counters, cron deduplication, GraphQL subscriptions, tenant-cache and IAM role-cache invalidation, Hub collectors, file storage (`file.storage: 's3'`; the driver is otherwise derived — S3 → GridFS → filesystem — and an unavailable one fails the boot rather than falling back) and TUS staging. Both are inert without their config, and their client libraries are **optional peer dependencies** (`ioredis`, `bullmq`, `@aws-sdk/client-s3`, `@aws-sdk/lib-storage`, `@aws-sdk/s3-request-presigner`, `@tus/s3-store`) — a project that uses neither installs nothing extra. When adding a distributed feature, always keep the non-configured fallback path.
223
224
 
package/FRAMEWORK-API.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @lenne.tech/nest-server — Framework API Reference
2
2
 
3
- > Auto-generated from source code as of 2026-11-24 (v12.11.2)
3
+ > Auto-generated from source code as of 2026-11-26 (v12.12.0)
4
4
  > File: `FRAMEWORK-API.md` — compact, machine-readable API surface for Claude Code
5
5
 
6
6
  ## CoreModule.forRoot()
@@ -15,6 +15,7 @@
15
15
  - `ai?`: `boolean | IAi` — Configuration for the AI assistant module.
16
16
  - `appUrl?`: `string` — Base URL of the frontend/app application.
17
17
  - `apiTokens?`: `boolean | IApiTokens` (default: `undefined (disabled)`) — API tokens: bearer credentials for machine clients and embedded pages that cannot carry a session
18
+ - `auditLog?`: `boolean | IAuditLog` — Audit log (DEV-4432): who created, changed, deleted or restored which record of the models a project names, and
18
19
  - `auth?`: `IAuth` — Authentication system configuration
19
20
  - `automaticObjectIdFiltering?`: `boolean` — Automatically detect ObjectIds in string values in FilterQueries
20
21
  - `baseUrl?`: `string` — Base URL of the API server.
@@ -43,6 +44,7 @@
43
44
  - `jwt?`: `IJwt & JwtModuleOptions & { refresh?: IJwt & { renewal?: boolean; }; sameToke...` — Configuration of JavaScript Web Token (JWT) module
44
45
  - `loadLocalConfig?`: `string | boolean` (default: `false`) — Load a local configuration file and merge it over this environment's configuration
45
46
  - `logExceptions?`: `boolean` — Log exceptions (for better debugging)
47
+ - `mailOutbox?`: `boolean | IMailOutbox` — Mail outbox (DEV-4433): every mail of `EmailService` — the framework's auth mails included — is stored first and
46
48
  - `mongoose?`: `{ collation?: CollationOptions; modelDocumentation?: boolean; options?: Mongo...` — Configuration for Mongoose
47
49
  - `multiTenancy?`: `IMultiTenancy` (default: `undefined (disabled)`) — Multi-tenancy configuration for tenant-based data isolation.
48
50
  - `permissions?`: `boolean | IPermissions` (default: `undefined (disabled)`) — Permissions report module (development tool).
@@ -57,6 +59,7 @@
57
59
  - `swagger?`: `boolean` (default: `undefined (served only in `local`, `ci` and `e2e`)`) — Whether `setupSwagger()` serves the API documentation (12.7.0+), decided by `isSwaggerEnabled()`.
58
60
  - `systemSetup?`: `ISystemSetup` — System setup configuration for initial admin creation.
59
61
  - `templates?`: `{ engine?: string; path?: string; }` — Templates
62
+ - `throttler?`: `boolean | IThrottler` — Rate limit for a project's routes, on top of `@nestjs/throttler` (DEV-4431): `@Throttle()` on a route or a
60
63
  - `trustProxy?`: `string | number | boolean | string[]` (default: `false (Express default — the forwarded chain is not trusted)`) — Express `trust proxy` setting — how far up the `X-Forwarded-For` chain this app believes.
61
64
  - `tus?`: `boolean | ITusConfig` — TUS resumable upload configuration.
62
65
 
@@ -226,6 +229,9 @@ When `passkey` is enabled, `trustedOrigins` is required (compile-time enforcemen
226
229
  ### ICoreModuleOverrides
227
230
 
228
231
  - `apiToken?`: `{ model?: Type<any>; service?: Type<any>; }` — Override API token collaborators with project-specific subclasses (`apiTokens` config).
232
+ - `auditLog?`: `{ controller?: Type<any>; service?: Type<any>; }` — Override the audit log's read endpoint and/or service (`auditLog` config).
233
+ - `mailOutbox?`: `{ controller?: Type<any>; service?: Type<any>; }` — Override the mail outbox's admin endpoints and/or service (`mailOutbox` config).
234
+ - `throttler?`: `{ guard?: Type<any>; }` — Override the rate limit guard (`throttler` config). `guard` must extend `CoreThrottlerGuard` (e.g. to count a
229
235
  - `sync?`: `{ controller?: Type<any>; hintsController?: Type<any>; resolver?: Type<any>; ...` — Override the offline sync endpoints, the hint subscription and their service (`sync` config).
230
236
  - `ai?`: `{ budgetService?: Type<any>; connectionResolver?: Type<any>; connectionServic...` — Override AI module collaborators with project-specific subclasses.
231
237
  - `betterAuth?`: `{ controller?: Type<any>; resolver?: Type<any>; }` — Override BetterAuth controller and/or resolver.
@@ -326,6 +332,7 @@ Generic: `CrudService<Model, CreateInput, UpdateInput>`
326
332
  - `async aggregateForce(pipeline: PipelineStage[], serviceOptions?: ServiceOptions)`: `Promise<T>` — Aggregate without checks or restrictions
327
333
  - `async aggregateRaw(pipeline: PipelineStage[], serviceOptions?: ServiceOptions)`: `Promise<T>` — Aggregate without checks, restrictions or preparations
328
334
  - `async create(input: PlainObject<CreateInput>, serviceOptions?: ServiceOptions)`: `Promise<Model>` — Create item
335
+ - `async createInProcess(data: { input?: any; }, serviceOptions?: ServiceOptions)`: `Promise<any>` — The write of `create()`, inside `process()`
329
336
  - `async createForce(input: PlainObject<CreateInput>, serviceOptions?: ServiceOptions)`: `Promise<Model>` — Create item without checks or restrictions
330
337
  - `async createRaw(input: PlainObject<CreateInput>, serviceOptions?: ServiceOptions)`: `Promise<Model>` — Create item without checks, restrictions or preparations
331
338
  - `distinct(property: string, serviceOptions?: ServiceOptions)`: `Promise<string[]>` — Get distinct values of a property
@@ -355,6 +362,10 @@ Generic: `CrudService<Model, CreateInput, UpdateInput>`
355
362
  - `async updateForce(id: string, input: PlainObject<UpdateInput>, serviceOptions?: ServiceOptions)`: `Promise<Model>` — Update item via ID without checks or restrictions
356
363
  - `async updateRaw(id: string, input: PlainObject<UpdateInput>, serviceOptions?: ServiceOptions)`: `Promise<Model>` — Update item via ID without checks, restrictions or preparations
357
364
  - `async delete(id: string, serviceOptions?: ServiceOptions)`: `Promise<Model>` — Delete item via ID
365
+ - `auditBefore(stored: Record<string, any>, input: unknown)`: `Map<string, string>` — The stored values of the fields an update names, compared after the write; `undefined` when nobody logs
366
+ - `async auditCreated(created: R, input: unknown, serviceOptions?: ServiceOptions)`: `Promise<R>` — Log a created record with the names of the fields its input set; answers the record
367
+ - `async auditUpdated(id: string, before: Map<string, string>, written: Record<string, any>, serviceOptions?: ServiceOptions)`: `Promise<void>` — Log an update with the names of the fields whose value changed; an update that changed nothing is not logged
368
+ - `async reportAudit(action: AuditAction, recordId: string, fields: string[], serviceOptions?: ServiceOptions)`: `Promise<void>` — Hand a successful write to the audit log — names only, never values. A no-op without the module or for a model it
358
369
  - `withTombstones(query: Q, serviceOptions?: ServiceOptions)`: `Q` — A Mongoose query or aggregation that also sees tombstones when the caller asked (`includeTombstones`)
359
370
  - `expectedVersionOf(serviceOptions?: ServiceOptions)`: `number` — `serviceOptions.expectedVersion`, checked; only a synchronized model has a version
360
371
  - `assertVersion(id: string, stored: any, expectedVersion: number)`: `void` — The early answer to a conditional change on a record that already has another version
@@ -382,17 +393,20 @@ Generic: `CrudService<Model, CreateInput, UpdateInput>`
382
393
  |--------|------|------|
383
394
  | `ai` | README, CHECKLIST | `src/core/modules/ai/` |
384
395
  | `api-token` | README, CHECKLIST | `src/core/modules/api-token/` |
396
+ | `audit-log` | README | `src/core/modules/audit-log/` |
385
397
  | `auth` | README | `src/core/modules/auth/` |
386
398
  | `better-auth` | README, CHECKLIST | `src/core/modules/better-auth/` |
387
399
  | `error-code` | CHECKLIST | `src/core/modules/error-code/` |
388
400
  | `file` | README, CHECKLIST | `src/core/modules/file/` |
389
401
  | `health-check` | — | `src/core/modules/health-check/` |
390
402
  | `hub` | README, CHECKLIST | `src/core/modules/hub/` |
403
+ | `mail-outbox` | README | `src/core/modules/mail-outbox/` |
391
404
  | `migrate` | README | `src/core/modules/migrate/` |
392
405
  | `permissions` | README, CHECKLIST | `src/core/modules/permissions/` |
393
406
  | `sync` | README, CHECKLIST | `src/core/modules/sync/` |
394
407
  | `system-setup` | README, CHECKLIST | `src/core/modules/system-setup/` |
395
408
  | `tenant` | README, CHECKLIST | `src/core/modules/tenant/` |
409
+ | `throttler` | README | `src/core/modules/throttler/` |
396
410
  | `tus` | README, CHECKLIST | `src/core/modules/tus/` |
397
411
  | `user` | — | `src/core/modules/user/` |
398
412
 
@@ -56,4 +56,4 @@ export declare const badRequestSchema: {
56
56
  };
57
57
  type: string;
58
58
  };
59
- export declare function ApiCommonErrorResponses(): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
59
+ export declare function ApiCommonErrorResponses(): ClassDecorator & MethodDecorator & ParameterDecorator & ((target: object, propertyKey?: string | symbol, descriptor?: undefined) => void);
@@ -311,6 +311,7 @@ export interface IServerOptions {
311
311
  ai?: boolean | IAi;
312
312
  appUrl?: string;
313
313
  apiTokens?: boolean | IApiTokens;
314
+ auditLog?: boolean | IAuditLog;
314
315
  auth?: IAuth;
315
316
  automaticObjectIdFiltering?: boolean;
316
317
  baseUrl?: string;
@@ -403,6 +404,7 @@ export interface IServerOptions {
403
404
  };
404
405
  loadLocalConfig?: boolean | string;
405
406
  logExceptions?: boolean;
407
+ mailOutbox?: boolean | IMailOutbox;
406
408
  mongoose?: {
407
409
  collation?: CollationOptions;
408
410
  modelDocumentation?: boolean;
@@ -465,6 +467,7 @@ export interface IServerOptions {
465
467
  engine?: string;
466
468
  path?: string;
467
469
  };
470
+ throttler?: boolean | IThrottler;
468
471
  trustProxy?: boolean | number | string | string[];
469
472
  tus?: boolean | ITusConfig;
470
473
  }
@@ -498,6 +501,46 @@ export interface IS3Config {
498
501
  socketTimeoutMs?: number;
499
502
  stagingBucket?: string;
500
503
  }
504
+ export interface IThrottlerLimit {
505
+ blockDuration?: number;
506
+ limit: number;
507
+ name?: string;
508
+ ttl: number;
509
+ }
510
+ export interface IThrottler {
511
+ blockDuration?: number;
512
+ enabled?: boolean;
513
+ errorMessage?: string;
514
+ ignoreUserAgents?: RegExp[];
515
+ ipv6SubnetPrefix?: number;
516
+ limit?: number;
517
+ routes?: 'all' | 'decorated';
518
+ setHeaders?: boolean;
519
+ storage?: 'database' | 'memory' | 'redis';
520
+ throttlers?: IThrottlerLimit[];
521
+ ttl?: number;
522
+ }
523
+ export interface IAuditLog {
524
+ enabled?: boolean;
525
+ models?: string[];
526
+ path?: string;
527
+ retentionDays?: false | number;
528
+ roles?: string[];
529
+ }
530
+ export interface IMailOutbox {
531
+ enabled?: boolean;
532
+ lockSeconds?: number;
533
+ maxAttempts?: number;
534
+ maxRetryDelaySeconds?: number;
535
+ path?: string;
536
+ pollIntervalSeconds?: number;
537
+ retention?: {
538
+ failedDays?: false | number;
539
+ sentDays?: false | number;
540
+ };
541
+ retryDelaySeconds?: number;
542
+ roles?: string[];
543
+ }
501
544
  export interface ISync {
502
545
  cursorSecret?: string;
503
546
  enabled?: boolean;
@@ -622,6 +665,17 @@ export interface ICoreModuleOverrides {
622
665
  model?: Type<any>;
623
666
  service?: Type<any>;
624
667
  };
668
+ auditLog?: {
669
+ controller?: Type<any>;
670
+ service?: Type<any>;
671
+ };
672
+ mailOutbox?: {
673
+ controller?: Type<any>;
674
+ service?: Type<any>;
675
+ };
676
+ throttler?: {
677
+ guard?: Type<any>;
678
+ };
625
679
  sync?: {
626
680
  controller?: Type<any>;
627
681
  hintsController?: Type<any>;
@@ -0,0 +1,19 @@
1
+ export type AuditAction = 'create' | 'delete' | 'restore' | 'update' | (string & {});
2
+ export interface AuditWrite {
3
+ action: AuditAction;
4
+ fields: string[];
5
+ model: string;
6
+ recordId: string;
7
+ userId?: string;
8
+ }
9
+ export interface AuditLogListener {
10
+ isAudited(model: string, modelClass?: Function): boolean;
11
+ recordWrite(write: AuditWrite): Promise<void>;
12
+ }
13
+ export declare function setAuditLogListener(value: AuditLogListener | undefined): void;
14
+ export declare function getAuditLogListener(): AuditLogListener | undefined;
15
+ export declare const AUDIT_IGNORED_FIELDS: ReadonlySet<string>;
16
+ export declare function auditFingerprint(value: unknown): string;
17
+ export declare function auditInputFields(input: Record<string, any> | null | undefined): string[];
18
+ export declare function auditSnapshot(stored: Record<string, any> | null | undefined, input: Record<string, any> | null | undefined): Map<string, string>;
19
+ export declare function auditChangedFields(snapshot: Map<string, string>, written: Record<string, any>): string[];
@@ -0,0 +1,84 @@
1
+ let listener;
2
+ export function setAuditLogListener(value) {
3
+ listener = value;
4
+ }
5
+ export function getAuditLogListener() {
6
+ return listener;
7
+ }
8
+ export const AUDIT_IGNORED_FIELDS = new Set([
9
+ '_id',
10
+ 'createdAt',
11
+ 'createdBy',
12
+ 'id',
13
+ 'syncAt',
14
+ 'syncSeq',
15
+ 'updatedAt',
16
+ 'updatedBy',
17
+ 'version',
18
+ ]);
19
+ const MAX_DEPTH = 20;
20
+ function normalize(value, depth) {
21
+ if (value === undefined || value === null) {
22
+ return null;
23
+ }
24
+ if (depth > MAX_DEPTH) {
25
+ return { $deep: Math.random() };
26
+ }
27
+ if (value instanceof Date) {
28
+ return Number.isNaN(value.getTime()) ? 'Invalid Date' : value.toISOString();
29
+ }
30
+ if (typeof value === 'bigint') {
31
+ return { $bigint: value.toString() };
32
+ }
33
+ if (typeof value !== 'object') {
34
+ return value;
35
+ }
36
+ const object = value;
37
+ if (typeof object.toHexString === 'function') {
38
+ return object.toHexString();
39
+ }
40
+ if (typeof Buffer !== 'undefined' && Buffer.isBuffer(object)) {
41
+ return object.toString('base64');
42
+ }
43
+ if (Array.isArray(object)) {
44
+ return object.map((item) => normalize(item, depth + 1));
45
+ }
46
+ const plain = typeof object.toObject === 'function' ? object.toObject() : object;
47
+ return Object.fromEntries(Object.keys(plain)
48
+ .filter((key) => plain[key] !== undefined)
49
+ .sort()
50
+ .map((key) => [key, normalize(plain[key], depth + 1)]));
51
+ }
52
+ export function auditFingerprint(value) {
53
+ try {
54
+ return JSON.stringify(normalize(value, 0));
55
+ }
56
+ catch {
57
+ return `{"$uncomparable":${Math.random()}}`;
58
+ }
59
+ }
60
+ export function auditInputFields(input) {
61
+ if (!input || typeof input !== 'object') {
62
+ return [];
63
+ }
64
+ return Object.keys(input)
65
+ .filter((key) => input[key] !== undefined && !AUDIT_IGNORED_FIELDS.has(key))
66
+ .sort();
67
+ }
68
+ export function auditSnapshot(stored, input) {
69
+ const snapshot = new Map();
70
+ for (const key of auditInputFields(input)) {
71
+ snapshot.set(key, auditFingerprint(stored?.[key]));
72
+ }
73
+ return snapshot;
74
+ }
75
+ export function auditChangedFields(snapshot, written) {
76
+ const changed = [];
77
+ for (const [key, before] of snapshot) {
78
+ if (auditFingerprint(written?.[key]) !== before) {
79
+ changed.push(key);
80
+ }
81
+ }
82
+ return changed.sort();
83
+ }
84
+ //# sourceMappingURL=audit-log.registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-log.registry.js","sourceRoot":"","sources":["../../../../src/core/common/persistence/audit-log.registry.ts"],"names":[],"mappings":"AAmCA,IAAI,QAAsC,CAAC;AAG3C,MAAM,UAAU,mBAAmB,CAAC,KAAmC;IACrE,QAAQ,GAAG,KAAK,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAMD,MAAM,CAAC,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IAC/D,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,MAA8C,EAC9C,KAA6C;IAE7C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1C,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAGD,MAAM,UAAU,kBAAkB,CAAC,QAA6B,EAAE,OAA4B;IAC5F,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACrC,IAAI,gBAAgB,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC;YAChD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { ForbiddenException, Logger } from '@nestjs/common';
2
+ import { accessDeniedException } from '../../exceptions/access-denied.exception.js';
2
3
  import { ConfigService } from '../../services/config.service.js';
3
4
  import { RequestContext } from '../../services/request-context.service.js';
4
5
  const isolationDisabledWarned = new Set();
@@ -51,7 +52,8 @@ export function resolveTenantFilter(modelName) {
51
52
  return { tenantId: { $in: tenantIds } };
52
53
  if (context?.isAdminBypass)
53
54
  return {};
54
- throw new ForbiddenException('Tenant context required: this data is tenant-scoped but no valid tenant context was provided');
55
+ const message = 'Tenant context required: this data is tenant-scoped but no valid tenant context was provided';
56
+ throw context?.fromRequest ? accessDeniedException(context.currentUser, message) : new ForbiddenException(message);
55
57
  }
56
58
  export function resolveTenantScope() {
57
59
  if (isTenantPolicyBypassed()) {
@@ -1 +1 @@
1
- {"version":3,"file":"tenant.policy.js","sourceRoot":"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AC,IAAI,CAAC,EAAE,CAAC;QACtD,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACpC,SAAS;QACX,CAAC;QACD,MAAM,QAAQ,GAAI,GAA8B,CAAC,QAAQ,CAAC;QAC1D,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,SAAS;QACX,CAAC;QACD,IAAI,QAAQ,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAC7D,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC,KAAK,CACjC,cAAc,SAAS,IAAI,eAAe,4DAA4D;gBACpG,oEAAoE,CACvE,CAAC;YACF,MAAM,IAAI,kBAAkB,CAAC,8DAA8D,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;AACH,CAAC;AAQD,MAAM,UAAU,8BAA8B,CAAC,SAAkB;IAC/D,IAAI,sBAAsB,CAAC,SAAS,CAAC,EAAE,CAAC;QACtC,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC;IACrC,IAAI,OAAO,EAAE,aAAa,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;QACjD,OAAO;IACT,CAAC;IACD,MAAM,IAAI,kBAAkB,CAC1B,kGAAkG;QAChG,8BAA8B,CACjC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"tenant.policy.js","sourceRoot":"","sources":["../../../../../src/core/common/persistence/policies/tenant.policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAY3E,MAAM,uBAAuB,G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AS;QACX,CAAC;QACD,MAAM,QAAQ,GAAI,GAA8B,CAAC,QAAQ,CAAC;QAC1D,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,SAAS;QACX,CAAC;QACD,IAAI,QAAQ,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAC7D,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC,KAAK,CACjC,cAAc,SAAS,IAAI,eAAe,4DAA4D;gBACpG,oEAAoE,CACvE,CAAC;YACF,MAAM,IAAI,kBAAkB,CAAC,8DAA8D,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;AACH,CAAC;AAQD,MAAM,UAAU,8BAA8B,CAAC,SAAkB;IAC/D,IAAI,sBAAsB,CAAC,SAAS,CAAC,EAAE,CAAC;QACtC,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC;IACrC,IAAI,OAAO,EAAE,aAAa,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;QACjD,OAAO;IACT,CAAC;IACD,MAAM,IAAI,kBAAkB,CAC1B,kGAAkG;QAChG,8BAA8B,CACjC,CAAC;AACJ,CAAC"}
@@ -49,7 +49,7 @@ let CoreTrustProxyInitializer = CoreTrustProxyInitializer_1 = class CoreTrustPro
49
49
  '(e.g. `trustProxy: 1`), or `trustProxy: false` if nothing proxies it — which also silences this warning.');
50
50
  }
51
51
  enabledIpRateLimiters() {
52
- return ['auth.rateLimit', 'betterAuth.rateLimit'].filter((path) => {
52
+ return ['auth.rateLimit', 'betterAuth.rateLimit', 'throttler'].filter((path) => {
53
53
  const config = ConfigService.getFastButReadOnly(path);
54
54
  if (config === undefined || config === null || config === false) {
55
55
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"core-trust-proxy.initializer.js","sourceRoot":"","sources":["../../../../src/core/common/services/core-trust-proxy.initializer.ts"],"names":[],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6B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,0CAA0C;YACxF,6GAA6G;YAC7G,2GAA2G;YAC3G,iGAAiG;YACjG,0GAA0G,CAC7G,CAAC;IACJ,CAAC;IASS,qBAAqB;QAC7B,OAAQ,CAAC,gBAAgB,EAAE,sBAAsB,CAAW,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YAC3E,MAAM,MAAM,GAAG,aAAa,CAAC,kBAAkB,CAAkC,IAAI,CAAC,CAAC;YACvF,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;gBAChE,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC;QACzE,CAAC,CAAC,CAAC;IACL,CAAC;IAGS,aAAa;QACrB,OAAO,aAAa,CAAC,kBAAkB,CAA+B,YAAY,CAAC,CAAC;IACtF,CAAC;IAGS,aAAa;QACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,CAAC;QACpE,OAAO,OAAO,QAAQ,EAAE,GAAG,KAAK,UAAU,IAAI,OAAO,QAAQ,EAAE,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3G,CAAC;CACF,CAAA;AAzFY,yBAAyB;IADrC,UAAU,EAAE;IAIE,WAAA,QAAQ,EAAE,CAAA;qCAAsC,eAAe;GAHjE,yBAAyB,CAyFrC"}
1
+ {"version":3,"file":"core-trust-proxy.initializer.js","sourceRoot":"","sources":["../../../../src/core/common/services/core-trust-proxy.initializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAwC,QAAQ,EAAE,MAAM,gBAAgB,CAAC;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G,0GAA0G,CAC7G,CAAC;IACJ,CAAC;IAUS,qBAAqB;QAC7B,OAAQ,CAAC,gBAAgB,EAAE,sBAAsB,EAAE,WAAW,CAAW,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACxF,MAAM,MAAM,GAAG,aAAa,CAAC,kBAAkB,CAAkC,IAAI,CAAC,CAAC;YACvF,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;gBAChE,OAAO,KAAK,CAAC;YACf,CAAC;YACD,OAAO,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC;QACzE,CAAC,CAAC,CAAC;IACL,CAAC;IAGS,aAAa;QACrB,OAAO,aAAa,CAAC,kBAAkB,CAA+B,YAAY,CAAC,CAAC;IACtF,CAAC;IAGS,aAAa;QACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,CAAC;QACpE,OAAO,OAAO,QAAQ,EAAE,GAAG,KAAK,UAAU,IAAI,OAAO,QAAQ,EAAE,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3G,CAAC;CACF,CAAA;AA1FY,yBAAyB;IADrC,UAAU,EAAE;IAIE,WAAA,QAAQ,EAAE,CAAA;qCAAsC,eAAe;GAHjE,yBAAyB,CA0FrC"}
@@ -3,6 +3,7 @@ import type { Query } from 'mongoose';
3
3
  import type { AggregateOptions, Connection, QueryOptions, Types } from 'mongoose';
4
4
  import { FilterArgs } from '../args/filter.args.js';
5
5
  import { ServiceOptions } from '../interfaces/service-options.interface.js';
6
+ import { type AuditAction } from '../persistence/audit-log.registry.js';
6
7
  import type { SyncDescriptor } from '../persistence/model-descriptor.interface.js';
7
8
  import { CoreModel } from '../models/core-model.model.js';
8
9
  import { PaginationInfo } from '../models/pagination-info.model.js';
@@ -15,6 +16,9 @@ export declare abstract class CrudService<Model extends CoreModel = any, CreateI
15
16
  aggregateForce<T = any>(pipeline: PipelineStage[], serviceOptions?: ServiceOptions): Promise<T>;
16
17
  aggregateRaw<T = any>(pipeline: PipelineStage[], serviceOptions?: ServiceOptions): Promise<T>;
17
18
  create(input: PlainObject<CreateInput>, serviceOptions?: ServiceOptions): Promise<Model>;
19
+ protected createInProcess(data: {
20
+ input?: any;
21
+ }, serviceOptions?: ServiceOptions): Promise<any>;
18
22
  createForce(input: PlainObject<CreateInput>, serviceOptions?: ServiceOptions): Promise<Model>;
19
23
  createRaw(input: PlainObject<CreateInput>, serviceOptions?: ServiceOptions): Promise<Model>;
20
24
  distinct(property: string, serviceOptions?: ServiceOptions): Promise<string[]>;
@@ -115,6 +119,12 @@ export declare abstract class CrudService<Model extends CoreModel = any, CreateI
115
119
  updateForce(id: string, input: PlainObject<UpdateInput>, serviceOptions?: ServiceOptions): Promise<Model>;
116
120
  updateRaw(id: string, input: PlainObject<UpdateInput>, serviceOptions?: ServiceOptions): Promise<Model>;
117
121
  delete(id: string, serviceOptions?: ServiceOptions): Promise<Model>;
122
+ protected get auditListener(): import("../persistence/audit-log.registry.js").AuditLogListener;
123
+ protected get auditModelName(): string;
124
+ protected auditBefore(stored: Record<string, any> | undefined, input: unknown): Map<string, string> | undefined;
125
+ protected auditCreated<R>(created: R, input: unknown, serviceOptions?: ServiceOptions): Promise<R>;
126
+ protected auditUpdated(id: string, before: Map<string, string> | undefined, written: Record<string, any>, serviceOptions?: ServiceOptions): Promise<void>;
127
+ protected reportAudit(action: AuditAction, recordId: string, fields: string[], serviceOptions?: ServiceOptions): Promise<void>;
118
128
  protected get mongoSync(): SyncDescriptor | undefined;
119
129
  protected get isSynchronized(): boolean;
120
130
  protected withTombstones<Q extends object>(query: Q, serviceOptions?: ServiceOptions): Q;