@lenne.tech/nest-server 12.8.2 → 12.8.4

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 (24) hide show
  1. package/.claude/rules/architecture.md +14 -4
  2. package/.claude/rules/configurable-features.md +1 -0
  3. package/.claude/rules/package-management.md +9 -7
  4. package/.claude/rules/testing.md +3 -3
  5. package/FRAMEWORK-API.md +2 -1
  6. package/dist/core/common/interfaces/server-options.interface.d.ts +1 -0
  7. package/dist/core/modules/better-auth/core-better-auth-email-verification.service.d.ts +1 -1
  8. package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js +7 -0
  9. package/dist/core/modules/better-auth/core-better-auth-email-verification.service.js.map +1 -1
  10. package/dist/core/modules/migrate/helpers/ts-compiler-hooks.mjs +4 -55
  11. package/dist/core/modules/migrate/helpers/ts-compiler-hooks.mjs.map +1 -1
  12. package/dist/core/modules/migrate/helpers/ts-compiler.cjs +100 -5
  13. package/dist/core/modules/migrate/helpers/ts-compiler.cjs.map +1 -1
  14. package/dist/core/modules/migrate/helpers/ts-compiler.d.cts +12 -1
  15. package/docs/security-overrides.md +6 -5
  16. package/migration-guides/12.8.2-to-12.8.3.md +111 -0
  17. package/migration-guides/12.8.3-to-12.8.4.md +109 -0
  18. package/package.json +36 -36
  19. package/src/core/common/interfaces/server-options.interface.ts +21 -0
  20. package/src/core/modules/better-auth/README.md +4 -1
  21. package/src/core/modules/better-auth/core-better-auth-email-verification.service.ts +18 -3
  22. package/src/core/modules/migrate/README.md +5 -3
  23. package/src/core/modules/migrate/helpers/ts-compiler-hooks.mjs +14 -65
  24. package/src/core/modules/migrate/helpers/ts-compiler.cjs +157 -12
@@ -0,0 +1,111 @@
1
+ # Migration Guide: 12.8.2 → 12.8.3
2
+
3
+ ## Overview
4
+
5
+ | Category | Details |
6
+ |---|---|
7
+ | **Breaking Changes** | None |
8
+ | **New Features** | `betterAuth.emailVerification.appName`: the application name in the verification and password-reset mails, independent of `package.json` (§2) |
9
+ | **Bugfixes** | Under Node 26 every start and every migration run from source printed `[DEP0205] DeprecationWarning: module.register() is deprecated`. The TypeScript loader now registers its import hooks with `module.registerHooks()` where Node supports it (§1) |
10
+ | **Migration Effort** | None. Optional: set `appName` when the mails should not carry the `package.json` name (§2) |
11
+
12
+ 12.8.3 is a patch for 12.8.2. Nothing has to change in a project.
13
+
14
+ ## Quick Migration
15
+
16
+ ```bash
17
+ pnpm add @lenne.tech/nest-server@12.8.3
18
+ pnpm run update # nest-server-starter based projects
19
+ pnpm run build
20
+ pnpm test
21
+ ```
22
+
23
+ **Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual.
24
+
25
+ ## 1. The TypeScript loader without `module.register()` on Node 26
26
+
27
+ **Why:** the framework's TypeScript loader (`migrate/helpers/ts-compiler.js`) runs the dev server from source
28
+ (`node -r …/ts-compiler.js src/main.ts`), the migrate CLI (`--compiler ts:…/ts-compiler.js`) and `config.env.ts`. For
29
+ `import`ed TypeScript (an ESM project, a `.mts` file) it registered Node module hooks through `module.register()`.
30
+ Node 26 deprecates that function at runtime, so every one of those runs printed DEP0205, in npm and vendor projects
31
+ alike.
32
+
33
+ **What changed:** the loader picks the hook API per Node line:
34
+
35
+ | Node | API | Why |
36
+ |---|---|---|
37
+ | 24.12+ and 26+ | `module.registerHooks()`, in-thread | hands a CommonJS module imported from ESM back to the CommonJS loader, as the loader needs |
38
+ | 22.x, 24.0–24.11, 25.x | `module.register()` with `ts-compiler-hooks.mjs`, as before | these lines refuse that hand-back in synchronous hooks; none of them deprecates `module.register()` |
39
+
40
+ Both paths share one implementation in `ts-compiler.cjs`. The behaviour is the same on every line: decorators with
41
+ metadata, `./x.js` specifiers resolving to `x.ts`, JSON imports with attributes, CommonJS-scoped `.ts` / `.cts` files
42
+ compiled by the `require` hook with a real `require` (`require.cache`, `require.extensions`). The CommonJS path
43
+ (`require()` of a `.ts` file, every migration) is unchanged.
44
+
45
+ `engines.node` stays `>= 22.15`. Nothing to do: the loader path, its function export and `--compiler ts:…` are the same.
46
+
47
+ ## 2. `betterAuth.emailVerification.appName`
48
+
49
+ **Why:** the verification and password-reset mails name the application in the subject
50
+ (`<appName> - Verify your email address`), in the EJS templates (`appName`) and in the Brevo parameters (`appName`).
51
+ That name came from the `name` of the `package.json` in the working directory, formatted (`my-app` → `My App`). In a
52
+ monorepo the working directory is the API package: one named `api` sent `Api - Verify your email address`. Changing it
53
+ needed an override of `getAppName()`.
54
+
55
+ **What changed:** an optional setting:
56
+
57
+ ```typescript
58
+ // config.env.ts
59
+ betterAuth: {
60
+ emailVerification: {
61
+ appName: 'Kundenportal',
62
+ },
63
+ },
64
+ ```
65
+
66
+ or `NSC__BETTER_AUTH__EMAIL_VERIFICATION__APP_NAME=Kundenportal`. The value is trimmed. Unset or empty, the mails keep
67
+ the `package.json` name. A value that is not a string is ignored with one warning. An override of `getAppName()` or
68
+ `resolveAppName()` still wins.
69
+
70
+ **A project with email verification switched off** (`emailVerification: false`) still sends password-reset mails, so
71
+ the name matters there too. Write it with `enabled: false`:
72
+
73
+ ```typescript
74
+ betterAuth: {
75
+ emailVerification: { enabled: false, appName: 'Kundenportal' },
76
+ },
77
+ ```
78
+
79
+ With environment variables, set `NSC__BETTER_AUTH__EMAIL_VERIFICATION__ENABLED=false` next to
80
+ `NSC__BETTER_AUTH__EMAIL_VERIFICATION__APP_NAME`. `false` keeps no settings, so `appName` would be ignored; an object
81
+ without `enabled: false` (which is what the variable alone turns `false` into) switches verification ON, and every
82
+ sign-in of a user whose address was never verified is then answered with 401 `EMAIL_VERIFICATION_REQUIRED`.
83
+
84
+ Authenticator apps and passkey prompts are not affected: they read `betterAuth.twoFactor.appName` and
85
+ `betterAuth.passkey.rpName`, as before.
86
+
87
+ ## Compatibility Notes
88
+
89
+ | Pattern | Status |
90
+ |---|---|
91
+ | `node -r …/ts-compiler.js src/main.ts`, `migrate … --compiler ts:…` | unchanged, without DEP0205 on Node 26 |
92
+ | A project calling `require('…/ts-compiler.js')()` itself | unchanged (idempotent function export) |
93
+ | A subclass overriding `getAppName()` / `resolveAppName()` | unchanged, still wins over the setting |
94
+ | Own email templates using `appName` | receive the configured name when it is set |
95
+
96
+ ## Troubleshooting
97
+
98
+ | Symptom | Cause | Fix |
99
+ |---|---|---|
100
+ | `[DEP0205] DeprecationWarning: module.register() is deprecated` after the update | a second loader in the project (`tsx`, `ts-node/esm`, a `--loader` / `--import` flag) still calls `module.register()` | remove or update that loader; the framework's own no longer calls it on Node 26 |
101
+ | The mail subject still shows the package name | `appName` is set at the wrong level, or empty, or `emailVerification` is `false` (keeps no settings) | it belongs under `betterAuth.emailVerification`; with verification off write `{ enabled: false, appName }`; check the boot log for the "must be a string" warning |
102
+ | After setting `appName`, unverified users get 401 `EMAIL_VERIFICATION_REQUIRED` at sign-in | the project had `emailVerification: false`; the object (or `NSC__…__APP_NAME` alone) switched verification on | add `enabled: false` (`NSC__BETTER_AUTH__EMAIL_VERIFICATION__ENABLED=false`) |
103
+
104
+ ## References
105
+
106
+ - `src/core/modules/migrate/helpers/ts-compiler.cjs`: `registerEsmHooks()`, `registerHooksHandsBackCommonJs()`,
107
+ `loadTypeScript()`
108
+ - `src/core/modules/migrate/README.md`: the TypeScript loader
109
+ - `src/core/modules/better-auth/core-better-auth-email-verification.service.ts`: `resolveAppName()`
110
+ - `src/core/modules/better-auth/README.md`: email verification
111
+ - `tests/unit/ts-compiler.spec.ts`, `tests/unit/better-auth-mail-app-name.spec.ts`
@@ -0,0 +1,109 @@
1
+ # Migration Guide: 12.8.3 → 12.8.4
2
+
3
+ ## Overview
4
+
5
+ | Category | Details |
6
+ |---|---|
7
+ | **Breaking Changes** | None for the application. The minimum versions of the optional peers rise: mongodb `>= 7.8.0`, mongoose `>= 9.12.0` (§1) |
8
+ | **New Features** | None |
9
+ | **Bugfixes** | Security: mongodb 7.8.0 closes GHSA-77w5-j825-v4qm (`timeoutMS`) and a flaw in the host-name check of SRV lookups (`mongodb+srv://`) (§1) |
10
+ | **Migration Effort** | `pnpm run update`. A project that pins mongoose / mongodb itself — vendored cores included — raises them (§1). A test setup that registers the Better-Auth resolver twice gets an error from @nestjs/graphql 14.2 (§2) |
11
+
12
+ 12.8.4 is a maintenance release: dependencies only, the framework's code is unchanged.
13
+
14
+ ## Quick Migration
15
+
16
+ ```bash
17
+ pnpm add @lenne.tech/nest-server@12.8.4
18
+ pnpm run update # nest-server-starter based projects: raises mongoose / mongodb and the NestJS pins with the framework
19
+ pnpm run build
20
+ pnpm test
21
+ ```
22
+
23
+ **Vendor mode**: run `/lt-dev:backend:update-nest-server-core` as usual, and raise mongoose / mongodb in the project's own
24
+ `package.json` (§1).
25
+
26
+ ## 1. mongoose 9.12.0 and mongodb 7.8.0 (security)
27
+
28
+ mongoose 9.12.0 moves to the mongodb driver 7.8.0. That driver closes two flaws present in every earlier 7.x:
29
+
30
+ - **GHSA-77w5-j825-v4qm / CVE-2026-119179** (high): with `timeoutMS`, a connection-pool desynchronization after an
31
+ operation timeout could hand one user's data to another. Only projects that set `timeoutMS` themselves are affected —
32
+ the framework never sets it. Since 7.8.0 `timeoutMS` is a no-op; use `serverSelectionTimeoutMS`, `socketTimeoutMS`,
33
+ `waitQueueTimeoutMS` and `maxTimeMS` instead.
34
+ - **SRV host-name verification** (mongodb `>= 3.3.3 < 7.8.0`, no GHSA): a host returned by the SRV lookup of a
35
+ `mongodb+srv://` URL was not verified properly, so whoever controlled the DNS answer could redirect the driver to a
36
+ host outside your domain. Projects with `mongodb://host1,host2` URLs are not affected.
37
+
38
+ Neither appears in `pnpm audit` — GHSA-77w5 is a repository advisory of the driver, the SRV flaw has no GHSA at all — so
39
+ the update is the only signal.
40
+
41
+ **What changed:** the optional peers now require mongodb `>= 7.8.0` and mongoose `>= 9.12.0` (before: `>= 7.7.0` /
42
+ `>= 9.11.4`). mongoose 9.11 pins the driver to `~7.7`, so raising mongodb alone leaves mongoose's own copy vulnerable —
43
+ raise both.
44
+
45
+ **What to do:** nest-server-starter based projects get both through `pnpm run update`. A project that pins mongoose and
46
+ mongodb itself — every vendor-mode project on MongoDB does — sets them to `9.12.0` / `7.8.0`:
47
+
48
+ ```bash
49
+ pnpm add mongoose@9.12.0 mongodb@7.8.0
50
+ ```
51
+
52
+ ## 2. @nestjs/graphql 14.2: a field resolved by two unrelated resolvers fails the start
53
+
54
+ 12.8.4 raises NestJS to 12.4 and `@nestjs/graphql` to 14.2. `@nestjs/graphql` 14.2 now refuses a GraphQL field that two
55
+ resolver classes resolve when neither extends the other. The symptom, at application start:
56
+
57
+ ```
58
+ "Query.betterAuthSession" is resolved by both "DefaultBetterAuthResolver.betterAuthSession" and
59
+ "BetterAuthResolver.betterAuthSession", which do not override one another, so the order in which the modules are
60
+ scanned would decide which one runs.
61
+ ```
62
+
63
+ **Where it appears:** in a test setup that imports `CoreModule.forRoot(envConfig)` (IAM-only signature, which registers
64
+ the default Better-Auth module) **and** the project's own `BetterAuthModule.forRoot(…)` with its resolver. Outside tests
65
+ the framework's duplicate-registration safety net keeps the second registration out; under vitest (`VITEST` set) that
66
+ net is off on purpose, so both resolvers reached the schema — before 14.2 one of them won silently.
67
+
68
+ **Fix — use one of the documented registration patterns:**
69
+
70
+ ```typescript
71
+ // Pattern 3: the project registers Better-Auth itself
72
+ const config = { ...envConfig, betterAuth: { ...envConfig.betterAuth, autoRegister: false } };
73
+ CoreModule.forRoot(config);
74
+ BetterAuthModule.forRoot({ config: config.betterAuth, … });
75
+
76
+ // or Pattern 2: let CoreModule register the project's classes
77
+ CoreModule.forRoot(envConfig, { betterAuth: { controller: BetterAuthController, resolver: BetterAuthResolver } });
78
+ ```
79
+
80
+ ## 3. Further updates
81
+
82
+ better-auth, `@better-auth/core` and `@better-auth/passkey` 1.7.18 (bug fixes, no advisory against 1.7.16; the peer
83
+ range `>= 1.7.16 < 1.8.0` is unchanged), `@nestjs/swagger` 12.1.1, `@nestjs/jwt` 12.0.4, `@nestjs/schedule` 12.0.3,
84
+ `@nestjs/passport` 12.0.1, `@nestjs/mongoose` 12.0.1, nodemailer 10.4.0, graphql-ws 6.4.1, ws 8.22.1 and development
85
+ tooling. Majors are left for later (graphql 17, graphql-upload 18, TypeScript 7, undici 8).
86
+
87
+ ## Compatibility Notes
88
+
89
+ | Pattern | Status |
90
+ |---|---|
91
+ | nest-server-starter based project, `pnpm run update` | Unchanged — pins follow the framework |
92
+ | Project pinning mongoose 9.11 / mongodb 7.7 itself | Peer warning; raise to 9.12.0 / 7.8.0 (§1) |
93
+ | `timeoutMS` in a connection option | Now a no-op (mongodb 7.8.0) — use the per-stage timeouts (§1) |
94
+ | Test setup with `CoreModule.forRoot(envConfig)` + `BetterAuthModule.forRoot()` | Fails at start under vitest — §2 |
95
+ | Production app with the same registration | Unchanged (the safety net registers Better-Auth once) |
96
+
97
+ ## Troubleshooting
98
+
99
+ | Symptom | Cause | Fix |
100
+ |---|---|---|
101
+ | `"Query.betterAuthSession" is resolved by both "DefaultBetterAuthResolver…" and "BetterAuthResolver…"` | Better-Auth registered twice in a test setup (§2) | `autoRegister: false`, or the `overrides` parameter of `CoreModule.forRoot()` |
102
+ | Peer warning for mongoose / mongodb | The project pins 9.11 / 7.7 | `pnpm add mongoose@9.12.0 mongodb@7.8.0` |
103
+ | Operations no longer time out after `timeoutMS` | `timeoutMS` is a no-op since mongodb 7.8.0 | `serverSelectionTimeoutMS`, `socketTimeoutMS`, `maxTimeMS` |
104
+
105
+ ## References
106
+
107
+ - `package.json` — `peerDependencies` (mongodb, mongoose)
108
+ - `src/core/modules/better-auth/CUSTOMIZATION.md` — registration patterns
109
+ - `tests/stories/better-auth-autoregister-false.e2e-spec.ts` — Pattern 3 in a test setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "12.8.2",
3
+ "version": "12.8.4",
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": [
@@ -105,15 +105,15 @@
105
105
  "@as-integrations/express5": "1.1.2",
106
106
  "@getbrevo/brevo": "6.2.0",
107
107
  "@modelcontextprotocol/sdk": "1.32.2",
108
- "@nestjs/apollo": "14.1.2",
109
- "@nestjs/common": "12.3.2",
110
- "@nestjs/core": "12.3.2",
111
- "@nestjs/graphql": "14.1.2",
112
- "@nestjs/jwt": "12.0.3",
113
- "@nestjs/passport": "12.0.0",
114
- "@nestjs/platform-express": "12.3.2",
115
- "@nestjs/schedule": "12.0.2",
116
- "@nestjs/swagger": "12.1.0",
108
+ "@nestjs/apollo": "14.2.0",
109
+ "@nestjs/common": "12.4.0",
110
+ "@nestjs/core": "12.4.0",
111
+ "@nestjs/graphql": "14.2.0",
112
+ "@nestjs/jwt": "12.0.4",
113
+ "@nestjs/passport": "12.0.1",
114
+ "@nestjs/platform-express": "12.4.0",
115
+ "@nestjs/schedule": "12.0.3",
116
+ "@nestjs/swagger": "12.1.1",
117
117
  "@nestjs/terminus": "12.1.0",
118
118
  "@tus/file-store": "2.1.2",
119
119
  "@tus/server": "2.4.7",
@@ -131,23 +131,23 @@
131
131
  "graphql-query-complexity": "2.0.0",
132
132
  "graphql-subscriptions": "3.0.0",
133
133
  "graphql-upload": "17.1.0",
134
- "graphql-ws": "6.3.0",
134
+ "graphql-ws": "6.4.1",
135
135
  "jose": "6.2.15",
136
136
  "js-sha256": "1.0.0",
137
137
  "json-to-graphql-query": "2.3.0",
138
138
  "lodash": "4.18.1",
139
139
  "multer": "2.5.0",
140
140
  "node-mailjet": "6.0.11",
141
- "nodemailer": "10.3.1",
141
+ "nodemailer": "10.4.0",
142
142
  "passport": "0.7.0",
143
143
  "passport-jwt": "4.0.1",
144
144
  "reflect-metadata": "0.2.2",
145
145
  "rfdc": "1.4.1",
146
146
  "rxjs": "7.8.2",
147
- "supertest": "7.3.1",
147
+ "supertest": "7.3.2",
148
148
  "ts-morph": "28.0.0",
149
149
  "undici": "7.30.1",
150
- "ws": "8.22.0",
150
+ "ws": "8.22.1",
151
151
  "yuml-diagram": "1.2.0"
152
152
  },
153
153
  "peerDependencies": {
@@ -164,8 +164,8 @@
164
164
  "drizzle-orm": "1.0.0-rc.5",
165
165
  "ioredis": ">=5.0.0 <7",
166
166
  "kysely": ">=0.29.0 <0.30.0",
167
- "mongodb": ">=7.7.0 <8",
168
- "mongoose": ">=9.11.4 <10",
167
+ "mongodb": ">=7.8.0 <8",
168
+ "mongoose": ">=9.12.0 <10",
169
169
  "mysql2": ">=3.24.6 <4",
170
170
  "pg": ">=8.23.0 <9",
171
171
  "typeorm": ">=1.1.0 <2"
@@ -227,18 +227,18 @@
227
227
  }
228
228
  },
229
229
  "devDependencies": {
230
- "@aws-sdk/client-s3": "3.1161.0",
231
- "@aws-sdk/lib-storage": "3.1161.0",
232
- "@aws-sdk/s3-request-presigner": "3.1161.0",
233
- "@better-auth/core": "1.7.16",
234
- "@better-auth/passkey": "1.7.16",
230
+ "@aws-sdk/client-s3": "3.1164.0",
231
+ "@aws-sdk/lib-storage": "3.1164.0",
232
+ "@aws-sdk/s3-request-presigner": "3.1164.0",
233
+ "@better-auth/core": "1.7.18",
234
+ "@better-auth/passkey": "1.7.18",
235
235
  "@compodoc/compodoc": "2.0.0",
236
- "@nestjs/cli": "12.0.11",
237
- "@nestjs/mongoose": "12.0.0",
238
- "@nestjs/schematics": "12.0.12",
239
- "@nestjs/testing": "12.3.2",
236
+ "@nestjs/cli": "12.0.12",
237
+ "@nestjs/mongoose": "12.0.1",
238
+ "@nestjs/schematics": "12.0.13",
239
+ "@nestjs/testing": "12.4.0",
240
240
  "@swc/cli": "0.8.2",
241
- "@swc/core": "1.16.21",
241
+ "@swc/core": "1.16.22",
242
242
  "@tus/s3-store": "2.1.0",
243
243
  "@types/compression": "1.8.1",
244
244
  "@types/cookie-parser": "1.4.10",
@@ -250,30 +250,30 @@
250
250
  "@types/passport": "1.0.17",
251
251
  "@types/pg": "8.23.1",
252
252
  "@vitest/coverage-v8": "5.1.0",
253
- "better-auth": "1.7.16",
254
- "bullmq": "6.5.4",
253
+ "better-auth": "1.7.18",
254
+ "bullmq": "6.7.2",
255
255
  "cross-env": "10.1.0",
256
256
  "drizzle-orm": "1.0.0-rc.5",
257
257
  "ioredis": "6.0.0",
258
258
  "kysely": "0.29.8",
259
- "mongodb": "7.7.0",
260
- "mongoose": "9.11.4",
259
+ "mongodb": "7.8.0",
260
+ "mongoose": "9.12.0",
261
261
  "mysql2": "3.24.6",
262
262
  "nodemon": "3.1.14",
263
263
  "otpauth": "9.6.0",
264
- "oxfmt": "0.75.0",
265
- "oxlint": "1.90.0",
266
- "oxlint-tsgolint": "7.0.2005",
264
+ "oxfmt": "0.77.0",
265
+ "oxlint": "1.92.0",
266
+ "oxlint-tsgolint": "7.0.2006",
267
267
  "pg": "8.23.1",
268
- "playwright-core": "1.64.1",
269
- "rimraf": "6.1.3",
268
+ "playwright-core": "1.65.0",
269
+ "rimraf": "6.1.4",
270
270
  "smtp-server": "3.21.3",
271
271
  "tsx": "4.23.15",
272
272
  "tus-js-client": "4.3.1",
273
273
  "typeorm": "1.1.2",
274
274
  "typescript": "6.0.3",
275
275
  "unplugin-swc": "2.0.0",
276
- "vite": "8.3.5",
276
+ "vite": "8.3.6",
277
277
  "vitest": "5.1.0"
278
278
  },
279
279
  "main": "dist/index.js",
@@ -509,6 +509,27 @@ export type IBetterAuth = IBetterAuthWithoutPasskey | IBetterAuthWithPasskey;
509
509
  * ```
510
510
  */
511
511
  export interface IBetterAuthEmailVerificationConfig {
512
+ /**
513
+ * The application name in the verification and password-reset mails: the subject (`<appName> - Verify your email
514
+ * address`), the `appName` variable of the EJS templates and the `appName` parameter of the Brevo templates.
515
+ *
516
+ * Unset (or empty), the name comes from the `name` of the `package.json` in the working directory, formatted
517
+ * (`my-app` → `My App`), as before 12.8.3 — in a monorepo that is the API package (`api`). A value that is not a
518
+ * string is ignored with a warning. `twoFactor.appName` and `passkey.rpName` name the application in authenticator
519
+ * apps and passkey prompts; they are separate settings.
520
+ *
521
+ * With email verification switched off, write `emailVerification: { enabled: false, appName }`
522
+ * (`NSC__BETTER_AUTH__EMAIL_VERIFICATION__ENABLED=false` next to the variable): `false` keeps no settings, and an
523
+ * object without `enabled: false` switches verification on — every sign-in of an unverified user then answers 401.
524
+ *
525
+ * **Environment Variable:** `NSC__BETTER_AUTH__EMAIL_VERIFICATION__APP_NAME`
526
+ *
527
+ * @default undefined (the formatted package.json name, 'Nest Server' without one)
528
+ * @example 'Kundenportal'
529
+ * @since 12.8.3
530
+ */
531
+ appName?: string;
532
+
512
533
  /**
513
534
  * Whether `GET /iam/verify-email` signs in the browser that opens the verification link.
514
535
  *
@@ -539,6 +539,7 @@ const config = {
539
539
  template: 'custom-verify', // Custom template name
540
540
  locale: 'en', // Template locale (default: 'de')
541
541
  brevoTemplateId: 42, // Send via Brevo transactional API (optional)
542
+ appName: 'Kundenportal', // Name in the mails (12.8.3+; default: the formatted package.json name)
542
543
  },
543
544
  // To disable:
544
545
  emailVerification: false,
@@ -548,6 +549,8 @@ const config = {
548
549
 
549
550
  **Custom Templates:** Create `templates/email-verification-{locale}.ejs` in your project. Available variables: `name`, `link`, `expiresIn`, `appName`.
550
551
 
552
+ **Application name:** `appName` in the verification and password-reset mails (subject, EJS variable, Brevo parameter) is `emailVerification.appName` when set (12.8.3+, `NSC__BETTER_AUTH__EMAIL_VERIFICATION__APP_NAME`), otherwise the `name` of the `package.json` in the working directory, formatted (`my-app` → `My App`). In a monorepo that is the API package, so set it there. Authenticator apps and passkey prompts read `twoFactor.appName` and `passkey.rpName`. With email verification switched off, write `emailVerification: { enabled: false, appName: '…' }` (`NSC__BETTER_AUTH__EMAIL_VERIFICATION__ENABLED=false` next to the variable): `false` keeps no settings, and an object without `enabled: false` switches verification on, which answers every sign-in of an unverified user with 401.
553
+
551
554
  **Brevo Integration:** When `brevoTemplateId` is set and Brevo is configured (`config.brevo`), verification emails are sent via Brevo's transactional API instead of SMTP/EJS templates. The same template variables (`name`, `link`, `appName`, `expiresIn`) are passed to the Brevo template.
552
555
 
553
556
  **Auto sign-in after verification (`autoSignInAfterVerification`, default `false` since 12.3.0):** with it on,
@@ -1988,7 +1991,7 @@ src/assets/templates/password-reset-de.ejs # or -en, or plain password-reset.e
1988
1991
  | --------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1989
1992
  | `name` | yes | `user.name`, falling back to the local part of the address |
1990
1993
  | `link` | yes | the ready-made reset URL |
1991
- | `appName` | yes | derived from `package.json` `name` |
1994
+ | `appName` | yes | `emailVerification.appName`, else derived from `package.json` `name` |
1992
1995
  | `logoSrc` | **no** | optional. The shipped templates render an `<img>` when it is present and the app name as text otherwise. Nothing in the framework supplies it — pass it from a subclass that overrides `sendPasswordResetEmail()`, or reference it from your own template. |
1993
1996
 
1994
1997
  > **Keep the un-suffixed `password-reset.ejs` renderable from `{ link, name }` alone.**
@@ -32,12 +32,17 @@ import { callerDirectory } from '../../common/helpers/module-location.helper.js'
32
32
  */
33
33
  type ResolvedEmailVerificationConfig = Pick<
34
34
  IBetterAuthEmailVerificationConfig,
35
- 'brevoTemplateId' | 'callbackURL' | 'passwordResetBrevoTemplateId' | 'passwordResetLink'
35
+ 'appName' | 'brevoTemplateId' | 'callbackURL' | 'passwordResetBrevoTemplateId' | 'passwordResetLink'
36
36
  > &
37
37
  Required<
38
38
  Omit<
39
39
  IBetterAuthEmailVerificationConfig,
40
- 'brevoTemplateId' | 'callbackURL' | 'passwordResetBrevoTemplateId' | 'passwordResetLink' | 'resendCooldownSeconds'
40
+ | 'appName'
41
+ | 'brevoTemplateId'
42
+ | 'callbackURL'
43
+ | 'passwordResetBrevoTemplateId'
44
+ | 'passwordResetLink'
45
+ | 'resendCooldownSeconds'
41
46
  >
42
47
  > & {
43
48
  resendCooldownSeconds: number;
@@ -1175,9 +1180,19 @@ export class CoreBetterAuthEmailVerificationService {
1175
1180
  }
1176
1181
 
1177
1182
  /**
1178
- * Resolve the application name from package.json, falling back to a framework default.
1183
+ * Resolve the application name: `betterAuth.emailVerification.appName` when set (12.8.3), otherwise the formatted
1184
+ * `name` of the working directory's package.json, otherwise a framework default.
1179
1185
  */
1180
1186
  protected resolveAppName(): string {
1187
+ const configured: unknown = this.config.appName;
1188
+ if (typeof configured === 'string' && configured.trim()) {
1189
+ return configured.trim();
1190
+ }
1191
+ if (configured !== undefined && configured !== null && typeof configured !== 'string') {
1192
+ this.logger.warn(
1193
+ `betterAuth.emailVerification.appName must be a string and is ignored (got ${typeof configured}); the mails use the package.json name`,
1194
+ );
1195
+ }
1181
1196
  // Try to get from package.json name
1182
1197
  try {
1183
1198
  const packageJsonPath = path.join(process.cwd(), 'package.json');
@@ -545,9 +545,11 @@ semantics for class fields), and type-checks nothing — `tsc` and the IDE do th
545
545
  (`pnpm add -D @swc/core`; starter-based projects have it), resolved from the working directory. The same file runs
546
546
  the dev server from source: `node -r <path>/ts-compiler.js src/main.ts`.
547
547
 
548
- It covers both module systems: a `require` hook for CommonJS, and Node module hooks (`ts-compiler-hooks.mjs`,
549
- registered on load) for ES modules — an ESM project's entry and everything it imports. Both map a `./x.js` specifier to
550
- `./x.ts` when only the source exists. The implementation is `ts-compiler.cjs`; `ts-compiler.js` is the established
548
+ It covers both module systems: a `require` hook for CommonJS, and Node module hooks, registered on load, for ES
549
+ modules — an ESM project's entry and everything it imports. Both map a `./x.js` specifier to `./x.ts` when only the
550
+ source exists. The module hooks run through `module.registerHooks()` on Node 24.12+ and 26+, so Node 26 prints no
551
+ `module.register()` deprecation (DEP0205) on every start and migration (12.8.3); Node 22, 24.0–24.11 and 25 keep
552
+ `module.register()` with `ts-compiler-hooks.mjs`, which none of them deprecates. The implementation is `ts-compiler.cjs`; `ts-compiler.js` is the established
551
553
  entry path and forwards to it. `helpers/package.json` declares `"type": "commonjs"`, so that path works in CommonJS and
552
554
  ESM projects, in npm and vendor mode.
553
555
 
@@ -1,65 +1,31 @@
1
1
  /**
2
- * ESM hooks of the framework's TypeScript loader, registered by `ts-compiler.cjs` through `module.register()`.
2
+ * Asynchronous module hooks of the framework's TypeScript loader, registered by `ts-compiler.cjs` through
3
+ * `module.register()` on the Node lines whose `module.registerHooks()` cannot hand CommonJS back to the CommonJS loader
4
+ * (22.x, 24.0–24.11, 25.x; see `registerHooksHandsBackCommonJs()`). Newer lines run the synchronous twins in
5
+ * `ts-compiler.cjs` in-thread instead, and this file is not loaded there.
6
+ *
7
+ * Both share one implementation in `ts-compiler.cjs`, so the two paths cannot drift:
3
8
  *
4
9
  * - `resolve`: a relative `./x.js` from a TypeScript file finds `x.ts` when no `x.js` exists (ESM requires the
5
10
  * extension of the EMITTED file, so sources written for both module systems name files that exist only after a
6
11
  * build). A real `.js` file always wins.
7
- * - `load`: a TypeScript file in ESM scope (`.mts`, or `.ts` under `"type": "module"`) is compiled with SWC to ESM,
8
- * with the options of the CommonJS hook. One in CommonJS scope is handed back to the CommonJS loader, where the
9
- * `require` hook compiles it — the same file must not be compiled two different ways.
12
+ * - `load`: a TypeScript file in ESM scope (`.mts`, or `.ts` under `"type": "module"`) is compiled with SWC to ESM. One
13
+ * in CommonJS scope is handed back to the CommonJS loader, where the `require` hook compiles it.
14
+ *
15
+ * Runs on the hooks thread `module.register()` creates; loading `ts-compiler.cjs` there registers no hooks again.
10
16
  */
11
- import { readFileSync } from 'node:fs';
12
17
  import { createRequire } from 'node:module';
13
- import { dirname, join } from 'node:path';
14
- import { fileURLToPath } from 'node:url';
15
18
 
16
19
  const require = createRequire(import.meta.url);
17
- const { loadSwc, SOURCE_EXTENSIONS, SWC_OPTIONS } = require('./ts-compiler.cjs');
18
-
19
- const TYPESCRIPT = /\.(c|m)?ts$/;
20
- const packageTypes = new Map();
21
- let swc;
22
-
23
- /** `"module"` or `"commonjs"`, from the nearest package.json — how Node itself decides a `.ts` file's format. */
24
- function packageType(directory) {
25
- if (packageTypes.has(directory)) {
26
- return packageTypes.get(directory);
27
- }
28
- let type = 'commonjs';
29
- try {
30
- type = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8')).type === 'module' ? 'module' : 'commonjs';
31
- } catch {
32
- const parent = dirname(directory);
33
- type = parent === directory ? 'commonjs' : packageType(parent);
34
- }
35
- packageTypes.set(directory, type);
36
- return type;
37
- }
38
-
39
- function formatOf(filename) {
40
- if (filename.endsWith('.mts')) {
41
- return 'module';
42
- }
43
- if (filename.endsWith('.cts')) {
44
- return 'commonjs';
45
- }
46
- return packageType(dirname(filename));
47
- }
20
+ const { loadTypeScript, typeScriptSpecifiers } = require('./ts-compiler.cjs');
48
21
 
49
22
  export async function resolve(specifier, context, nextResolve) {
50
23
  try {
51
24
  return await nextResolve(specifier, context);
52
25
  } catch (error) {
53
- const extension = specifier.match(/\.(c|m)?js$/)?.[0];
54
- const fromTypeScript = TYPESCRIPT.test(context.parentURL ?? '');
55
- const pathLike = /^\.{0,2}\//.test(specifier) || specifier.startsWith('file:');
56
- if (error?.code !== 'ERR_MODULE_NOT_FOUND' || !extension || !fromTypeScript || !pathLike) {
57
- throw error;
58
- }
59
- const sources = { ...SOURCE_EXTENSIONS, '.mjs': ['.mts'] }[extension] ?? [];
60
- for (const sourceExtension of sources) {
26
+ for (const candidate of typeScriptSpecifiers(specifier, context, error) ?? []) {
61
27
  try {
62
- return await nextResolve(specifier.slice(0, -extension.length) + sourceExtension, context);
28
+ return await nextResolve(candidate, context);
63
29
  } catch {
64
30
  // try the next one; the original error is the one worth reporting
65
31
  }
@@ -69,22 +35,5 @@ export async function resolve(specifier, context, nextResolve) {
69
35
  }
70
36
 
71
37
  export async function load(url, context, nextLoad) {
72
- if (!url.startsWith('file:') || !TYPESCRIPT.test(new URL(url).pathname)) {
73
- return nextLoad(url, context);
74
- }
75
- const filename = fileURLToPath(url);
76
- if (formatOf(filename) === 'commonjs') {
77
- // No source: Node loads it with the CommonJS loader, i.e. through the `require` hook.
78
- return { format: 'commonjs', shortCircuit: true };
79
- }
80
- swc ??= loadSwc();
81
- const { code } = swc.transformSync(readFileSync(filename, 'utf8'), {
82
- ...SWC_OPTIONS,
83
- filename,
84
- // SWC drops import attributes unless told to keep them, and Node refuses a JSON import without
85
- // `with { type: 'json' }` (ERR_IMPORT_ATTRIBUTE_MISSING) — `import pkg from '../package.json' with { type: 'json' }`.
86
- jsc: { ...SWC_OPTIONS.jsc, experimental: { keepImportAssertions: true } },
87
- module: { type: 'es6' },
88
- });
89
- return { format: 'module', shortCircuit: true, source: code };
38
+ return loadTypeScript(url) ?? nextLoad(url, context);
90
39
  }