@lenne.tech/nest-server 11.27.6 → 11.27.7

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 (132) hide show
  1. package/.claude/rules/architecture.md +66 -0
  2. package/.claude/rules/better-auth.md +88 -2
  3. package/.claude/rules/package-management.md +23 -14
  4. package/CLAUDE.md +8 -2
  5. package/FRAMEWORK-API.md +1 -1
  6. package/dist/core/common/decorators/restricted.decorator.d.ts +4 -4
  7. package/dist/core/common/decorators/restricted.decorator.js +21 -22
  8. package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
  9. package/dist/core/common/helpers/clone.helper.d.ts +6 -0
  10. package/dist/core/common/helpers/clone.helper.js +67 -0
  11. package/dist/core/common/helpers/clone.helper.js.map +1 -0
  12. package/dist/core/common/helpers/db.helper.d.ts +2 -14
  13. package/dist/core/common/helpers/db.helper.js +13 -106
  14. package/dist/core/common/helpers/db.helper.js.map +1 -1
  15. package/dist/core/common/helpers/id.helper.d.ts +15 -0
  16. package/dist/core/common/helpers/id.helper.js +104 -0
  17. package/dist/core/common/helpers/id.helper.js.map +1 -0
  18. package/dist/core/common/helpers/input.helper.d.ts +1 -6
  19. package/dist/core/common/helpers/input.helper.js +11 -70
  20. package/dist/core/common/helpers/input.helper.js.map +1 -1
  21. package/dist/core/common/inputs/combined-filter.input.d.ts +1 -12
  22. package/dist/core/common/inputs/combined-filter.input.js +2 -51
  23. package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
  24. package/dist/core/common/inputs/filter.input.d.ts +10 -1
  25. package/dist/core/common/inputs/filter.input.js +40 -5
  26. package/dist/core/common/inputs/filter.input.js.map +1 -1
  27. package/dist/core/common/services/config.service.js +5 -5
  28. package/dist/core/common/services/config.service.js.map +1 -1
  29. package/dist/core/modules/ai/core-ai.constants.d.ts +22 -0
  30. package/dist/core/modules/ai/core-ai.constants.js +26 -0
  31. package/dist/core/modules/ai/core-ai.constants.js.map +1 -0
  32. package/dist/core/modules/ai/index.d.ts +1 -0
  33. package/dist/core/modules/ai/index.js +1 -0
  34. package/dist/core/modules/ai/index.js.map +1 -1
  35. package/dist/core/modules/ai/interfaces/ai-interaction-record.interface.d.ts +17 -0
  36. package/dist/core/modules/ai/interfaces/ai-interaction-record.interface.js +3 -0
  37. package/dist/core/modules/ai/interfaces/ai-interaction-record.interface.js.map +1 -0
  38. package/dist/core/modules/ai/services/core-ai-budget.service.d.ts +1 -2
  39. package/dist/core/modules/ai/services/core-ai-budget.service.js +7 -5
  40. package/dist/core/modules/ai/services/core-ai-budget.service.js.map +1 -1
  41. package/dist/core/modules/ai/services/core-ai-connection-preference.service.d.ts +1 -2
  42. package/dist/core/modules/ai/services/core-ai-connection-preference.service.js +7 -5
  43. package/dist/core/modules/ai/services/core-ai-connection-preference.service.js.map +1 -1
  44. package/dist/core/modules/ai/services/core-ai-connection.service.d.ts +1 -2
  45. package/dist/core/modules/ai/services/core-ai-connection.service.js +7 -5
  46. package/dist/core/modules/ai/services/core-ai-connection.service.js.map +1 -1
  47. package/dist/core/modules/ai/services/core-ai-conversation.service.d.ts +1 -2
  48. package/dist/core/modules/ai/services/core-ai-conversation.service.js +7 -5
  49. package/dist/core/modules/ai/services/core-ai-conversation.service.js.map +1 -1
  50. package/dist/core/modules/ai/services/core-ai-interaction.service.d.ts +2 -3
  51. package/dist/core/modules/ai/services/core-ai-interaction.service.js +7 -5
  52. package/dist/core/modules/ai/services/core-ai-interaction.service.js.map +1 -1
  53. package/dist/core/modules/ai/services/core-ai-mode.service.d.ts +1 -2
  54. package/dist/core/modules/ai/services/core-ai-mode.service.js +7 -5
  55. package/dist/core/modules/ai/services/core-ai-mode.service.js.map +1 -1
  56. package/dist/core/modules/ai/services/core-ai-prompt-hint.service.d.ts +1 -3
  57. package/dist/core/modules/ai/services/core-ai-prompt-hint.service.js +7 -5
  58. package/dist/core/modules/ai/services/core-ai-prompt-hint.service.js.map +1 -1
  59. package/dist/core/modules/ai/services/core-ai-prompt.service.d.ts +1 -2
  60. package/dist/core/modules/ai/services/core-ai-prompt.service.js +7 -5
  61. package/dist/core/modules/ai/services/core-ai-prompt.service.js.map +1 -1
  62. package/dist/core/modules/ai/services/core-ai-slot.service.d.ts +1 -2
  63. package/dist/core/modules/ai/services/core-ai-slot.service.js +7 -5
  64. package/dist/core/modules/ai/services/core-ai-slot.service.js.map +1 -1
  65. package/dist/core/modules/ai/services/core-ai-tool-grant.service.d.ts +1 -2
  66. package/dist/core/modules/ai/services/core-ai-tool-grant.service.js +7 -5
  67. package/dist/core/modules/ai/services/core-ai-tool-grant.service.js.map +1 -1
  68. package/dist/core/modules/ai/services/core-ai-tool-policy.service.d.ts +1 -2
  69. package/dist/core/modules/ai/services/core-ai-tool-policy.service.js +7 -5
  70. package/dist/core/modules/ai/services/core-ai-tool-policy.service.js.map +1 -1
  71. package/dist/core/modules/ai/services/core-ai.service.d.ts +2 -17
  72. package/dist/core/modules/ai/services/core-ai.service.js.map +1 -1
  73. package/dist/core/modules/better-auth/better-auth-roles.guard.js +2 -2
  74. package/dist/core/modules/better-auth/better-auth-roles.guard.js.map +1 -1
  75. package/dist/core/modules/better-auth/better-auth.config.js +6 -0
  76. package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
  77. package/dist/core/modules/better-auth/core-better-auth.constants.d.ts +3 -0
  78. package/dist/core/modules/better-auth/core-better-auth.constants.js +7 -0
  79. package/dist/core/modules/better-auth/core-better-auth.constants.js.map +1 -0
  80. package/dist/core/modules/better-auth/core-better-auth.module.d.ts +1 -2
  81. package/dist/core/modules/better-auth/core-better-auth.module.js +23 -20
  82. package/dist/core/modules/better-auth/core-better-auth.module.js.map +1 -1
  83. package/dist/core/modules/better-auth/core-better-auth.registry.d.ts +4 -0
  84. package/dist/core/modules/better-auth/core-better-auth.registry.js +16 -0
  85. package/dist/core/modules/better-auth/core-better-auth.registry.js.map +1 -0
  86. package/dist/core/modules/better-auth/core-better-auth.service.d.ts +1 -2
  87. package/dist/core/modules/better-auth/core-better-auth.service.js +7 -6
  88. package/dist/core/modules/better-auth/core-better-auth.service.js.map +1 -1
  89. package/dist/core/modules/better-auth/index.d.ts +1 -0
  90. package/dist/core/modules/better-auth/index.js +1 -0
  91. package/dist/core/modules/better-auth/index.js.map +1 -1
  92. package/dist/core/modules/tus/tus.constants.d.ts +1 -0
  93. package/dist/core/modules/tus/tus.constants.js +5 -0
  94. package/dist/core/modules/tus/tus.constants.js.map +1 -0
  95. package/dist/core/modules/tus/tus.module.d.ts +1 -1
  96. package/dist/core/modules/tus/tus.module.js +8 -6
  97. package/dist/core/modules/tus/tus.module.js.map +1 -1
  98. package/dist/tsconfig.build.tsbuildinfo +1 -1
  99. package/migration-guides/11.27.6-to-11.27.7.md +374 -0
  100. package/package.json +6 -104
  101. package/src/core/common/decorators/restricted.decorator.ts +33 -8
  102. package/src/core/common/helpers/clone.helper.ts +110 -0
  103. package/src/core/common/helpers/db.helper.ts +14 -161
  104. package/src/core/common/helpers/id.helper.ts +198 -0
  105. package/src/core/common/helpers/input.helper.ts +12 -84
  106. package/src/core/common/inputs/combined-filter.input.ts +10 -57
  107. package/src/core/common/inputs/filter.input.ts +92 -1
  108. package/src/core/common/services/config.service.ts +4 -1
  109. package/src/core/modules/ai/core-ai.constants.ts +92 -0
  110. package/src/core/modules/ai/index.ts +1 -0
  111. package/src/core/modules/ai/interfaces/ai-interaction-record.interface.ts +34 -0
  112. package/src/core/modules/ai/services/core-ai-budget.service.ts +8 -4
  113. package/src/core/modules/ai/services/core-ai-connection-preference.service.ts +8 -4
  114. package/src/core/modules/ai/services/core-ai-connection.service.ts +5 -6
  115. package/src/core/modules/ai/services/core-ai-conversation.service.ts +5 -6
  116. package/src/core/modules/ai/services/core-ai-interaction.service.ts +6 -7
  117. package/src/core/modules/ai/services/core-ai-mode.service.ts +8 -2
  118. package/src/core/modules/ai/services/core-ai-prompt-hint.service.ts +7 -4
  119. package/src/core/modules/ai/services/core-ai-prompt.service.ts +8 -2
  120. package/src/core/modules/ai/services/core-ai-slot.service.ts +7 -4
  121. package/src/core/modules/ai/services/core-ai-tool-grant.service.ts +8 -4
  122. package/src/core/modules/ai/services/core-ai-tool-policy.service.ts +8 -4
  123. package/src/core/modules/ai/services/core-ai.service.ts +8 -11
  124. package/src/core/modules/better-auth/better-auth-roles.guard.ts +11 -5
  125. package/src/core/modules/better-auth/better-auth.config.ts +16 -0
  126. package/src/core/modules/better-auth/core-better-auth.constants.ts +73 -0
  127. package/src/core/modules/better-auth/core-better-auth.module.ts +34 -8
  128. package/src/core/modules/better-auth/core-better-auth.registry.ts +53 -0
  129. package/src/core/modules/better-auth/core-better-auth.service.ts +19 -12
  130. package/src/core/modules/better-auth/index.ts +9 -0
  131. package/src/core/modules/tus/tus.constants.ts +25 -0
  132. package/src/core/modules/tus/tus.module.ts +7 -2
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Dependency-injection tokens of the better-auth module.
3
+ *
4
+ * These live in a dedicated file — instead of core-better-auth.module.ts /
5
+ * core-better-auth.service.ts — so that module and service never have to import
6
+ * each other. The tokens used to be split across both files
7
+ * (BETTER_AUTH_INSTANCE in the module, BETTER_AUTH_CONFIG /
8
+ * BETTER_AUTH_COOKIE_DOMAIN in the service), which made the two files import
9
+ * each other in a cycle. That cycle happened to work under tsc/CommonJS by
10
+ * evaluation-order luck, but crashed SWC-compiled builds (`nest start -b swc`)
11
+ * with a temporal-dead-zone error:
12
+ *
13
+ * ReferenceError: Cannot access 'BETTER_AUTH_INSTANCE' before initialization
14
+ *
15
+ * The lethal ingredient is not the cycle by itself — it is a cycle PLUS a read of
16
+ * the cyclic binding at module-evaluation time. `@Inject(BETTER_AUTH_INSTANCE)` is
17
+ * a constructor-parameter decorator, and decorator arguments are evaluated when the
18
+ * class is defined, i.e. while the module is still initializing. On a cycle the
19
+ * importing side then reads a `const` that has not been initialized yet.
20
+ *
21
+ * This file imports nothing, so it can never be mid-evaluation when someone
22
+ * imports it — in any module system, under any compiler. That makes the
23
+ * initialization order of the tokens deterministic everywhere.
24
+ *
25
+ * WHY THIS MATTERS FOR FUTURE CHANGES
26
+ * -----------------------------------
27
+ * `tsc` does NOT catch a regression here, and neither does the test suite: vitest
28
+ * runs SWC through Vite's module runner, whose getter-based live bindings tolerate
29
+ * cycles. Only the SWC → CommonJS → `require()` path fails, which is exactly what
30
+ * `pnpm run check:swc-tdz` exercises. If you move a token back into the module or
31
+ * the service, everything stays green locally and breaks for consumers.
32
+ *
33
+ * The rule, in short: **DI tokens belong in an import-free leaf file.**
34
+ * See .claude/rules/better-auth.md §6.
35
+ */
36
+
37
+ /**
38
+ * Token for injecting the better-auth instance.
39
+ *
40
+ * Injected type: `BetterAuthInstance | null` — null when better-auth is disabled.
41
+ * Declared `@Optional()` in the CoreBetterAuthService constructor.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import { Inject, Injectable, Optional } from '@nestjs/common';
46
+ * import { BETTER_AUTH_INSTANCE, BetterAuthInstance } from '@lenne.tech/nest-server';
47
+ *
48
+ * @Injectable()
49
+ * export class MyService {
50
+ * constructor(
51
+ * @Optional() @Inject(BETTER_AUTH_INSTANCE) private readonly auth: BetterAuthInstance | null,
52
+ * ) {}
53
+ * }
54
+ * ```
55
+ */
56
+ export const BETTER_AUTH_INSTANCE = 'BETTER_AUTH_INSTANCE';
57
+
58
+ /**
59
+ * Injection token for the resolved BetterAuth configuration.
60
+ *
61
+ * Injected type: `IBetterAuth | null` — null when better-auth is disabled.
62
+ * Declared `@Optional()` in the CoreBetterAuthService constructor.
63
+ */
64
+ export const BETTER_AUTH_CONFIG = 'BETTER_AUTH_CONFIG';
65
+
66
+ /**
67
+ * Injection token for the resolved cross-subdomain cookie domain.
68
+ * Set during Better-Auth instance creation, undefined if disabled.
69
+ *
70
+ * Injected type: `string | null | undefined`.
71
+ * Declared `@Optional()` in the CoreBetterAuthService constructor.
72
+ */
73
+ export const BETTER_AUTH_COOKIE_DOMAIN = 'BETTER_AUTH_COOKIE_DOMAIN';
@@ -28,15 +28,34 @@ import { CoreBetterAuthRateLimitMiddleware } from './core-better-auth-rate-limit
28
28
  import { CoreBetterAuthRateLimiter } from './core-better-auth-rate-limiter.service';
29
29
  import { CoreBetterAuthSignUpValidatorService } from './core-better-auth-signup-validator.service';
30
30
  import { CoreBetterAuthUserMapper } from './core-better-auth-user.mapper';
31
+ import { BETTER_AUTH_CONFIG, BETTER_AUTH_COOKIE_DOMAIN, BETTER_AUTH_INSTANCE } from './core-better-auth.constants';
31
32
  import { CoreBetterAuthController } from './core-better-auth.controller';
32
33
  import { CoreBetterAuthMiddleware } from './core-better-auth.middleware';
34
+ import {
35
+ getBetterAuthTokenService,
36
+ resetBetterAuthRegistry,
37
+ setBetterAuthTokenService,
38
+ } from './core-better-auth.registry';
33
39
  import { CoreBetterAuthResolver } from './core-better-auth.resolver';
34
- import { BETTER_AUTH_CONFIG, BETTER_AUTH_COOKIE_DOMAIN, CoreBetterAuthService } from './core-better-auth.service';
40
+ import { CoreBetterAuthService } from './core-better-auth.service';
35
41
 
36
42
  /**
37
- * Token for injecting the better-auth instance
43
+ * @deprecated Import from `./core-better-auth.constants` instead. Re-exported only
44
+ * so existing deep imports keep working; it will be dropped in a future MINOR.
45
+ *
46
+ * Do NOT import this token from here inside the better-auth module itself — the
47
+ * token must come from the constants leaf, or module and service start importing
48
+ * each other again and SWC builds crash with a temporal-dead-zone ReferenceError
49
+ * (see core-better-auth.constants.ts).
50
+ *
51
+ * NOTE: the `@deprecated` tag above is documentation only — TypeScript does not
52
+ * honor JSDoc on an `export … from` declaration. Do NOT try to "fix" that by
53
+ * re-declaring the token as a local `const`: that would give the barrel two
54
+ * distinct declarations of the same name and turn its `export *` into a TS2308
55
+ * ambiguity error. The mechanical guards are `pnpm run check:swc-tdz` and
56
+ * `tests/unit/better-auth-di-tokens.spec.ts`.
38
57
  */
39
- export const BETTER_AUTH_INSTANCE = 'BETTER_AUTH_INSTANCE';
58
+ export { BETTER_AUTH_INSTANCE } from './core-better-auth.constants';
40
59
 
41
60
  /**
42
61
  * Options for CoreBetterAuthModule.forRoot()
@@ -239,10 +258,11 @@ export class CoreBetterAuthModule implements NestModule, OnModuleInit {
239
258
  // Safety Net: Track if forRoot() has already been called to detect duplicate registration
240
259
  private static forRootCalled = false;
241
260
  private static cachedDynamicModule: DynamicModule | null = null;
242
- // Static references for lazy GraphQL driver (autoRegister: false) and BetterAuthRolesGuard
261
+ // Static references for lazy GraphQL driver (autoRegister: false).
262
+ // The BetterAuthTokenService reference lives in core-better-auth.registry.ts instead,
263
+ // so BetterAuthRolesGuard can read it without importing this module (cycle-free).
243
264
  private static serviceInstance: CoreBetterAuthService | null = null;
244
265
  private static userMapperInstance: CoreBetterAuthUserMapper | null = null;
245
- private static tokenServiceInstance: BetterAuthTokenService | null = null;
246
266
  private static resolvedCookieDomain: string | undefined = undefined;
247
267
 
248
268
  /**
@@ -279,11 +299,14 @@ export class CoreBetterAuthModule implements NestModule, OnModuleInit {
279
299
 
280
300
  /**
281
301
  * Gets the static BetterAuthTokenService instance.
282
- * Used by BetterAuthRolesGuard for token verification when user isn't already on request.
283
302
  * Safe because guards are invoked only after module initialization.
303
+ *
304
+ * Delegates to the core-better-auth.registry leaf module, which is the single
305
+ * source of truth. BetterAuthRolesGuard reads the registry directly instead of
306
+ * calling this method, so that guard and module never import each other.
284
307
  */
285
308
  static getTokenServiceInstance(): BetterAuthTokenService | null {
286
- return this.tokenServiceInstance;
309
+ return getBetterAuthTokenService();
287
310
  }
288
311
 
289
312
  /**
@@ -315,7 +338,7 @@ export class CoreBetterAuthModule implements NestModule, OnModuleInit {
315
338
  CoreBetterAuthModule.userMapperInstance = this.userMapper;
316
339
  }
317
340
  if (this.tokenService) {
318
- CoreBetterAuthModule.tokenServiceInstance = this.tokenService;
341
+ setBetterAuthTokenService(this.tokenService);
319
342
  }
320
343
 
321
344
  // Configure rate limiter with stored config
@@ -747,6 +770,9 @@ export class CoreBetterAuthModule implements NestModule, OnModuleInit {
747
770
  this.serviceInstance = null;
748
771
  this.userMapperInstance = null;
749
772
  this.resolvedCookieDomain = undefined;
773
+ // Reset the BetterAuthTokenService reference used by BetterAuthRolesGuard.
774
+ // Without this a token service from a previous testing module leaks into the next one.
775
+ resetBetterAuthRegistry();
750
776
  // Reset shared RolesGuard registry (shared with CoreAuthModule)
751
777
  RolesGuardRegistry.reset();
752
778
  }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Runtime registry for better-auth singletons that must be reachable from files
3
+ * which cannot import core-better-auth.module.ts.
4
+ *
5
+ * `BetterAuthRolesGuard` deliberately has no constructor dependencies (see
6
+ * .claude/rules/better-auth.md §5), so it cannot receive `BetterAuthTokenService`
7
+ * through DI and has to look it up statically. Reading it from
8
+ * `CoreBetterAuthModule` would make guard and module import each other — the same
9
+ * cycle shape that crashed SWC builds when the DI tokens still lived in the module
10
+ * and the service (see core-better-auth.constants.ts).
11
+ *
12
+ * This file therefore holds the reference instead. It uses only `import type`,
13
+ * which both tsc and SWC erase entirely, so it emits no `require()` at all and is
14
+ * a true leaf: it can never be mid-evaluation when someone imports it, in any
15
+ * module system, under any compiler.
16
+ *
17
+ * @internal Populated by CoreBetterAuthModule.onModuleInit(). Read it through the
18
+ * public `CoreBetterAuthModule.getTokenServiceInstance()` unless you are in a file
19
+ * that the module itself imports — importing the module from there would re-create
20
+ * the cycle.
21
+ */
22
+
23
+ import type { BetterAuthTokenService } from './better-auth-token.service';
24
+
25
+ let tokenServiceInstance: BetterAuthTokenService | null = null;
26
+
27
+ /**
28
+ * Stores the BetterAuthTokenService singleton.
29
+ * Called by CoreBetterAuthModule during module initialization.
30
+ * @internal
31
+ */
32
+ export function setBetterAuthTokenService(service: BetterAuthTokenService | null): void {
33
+ tokenServiceInstance = service;
34
+ }
35
+
36
+ /**
37
+ * Returns the BetterAuthTokenService singleton, or null when better-auth is
38
+ * disabled or the module has not initialized yet.
39
+ *
40
+ * Safe to call from guards: they run only after module initialization.
41
+ */
42
+ export function getBetterAuthTokenService(): BetterAuthTokenService | null {
43
+ return tokenServiceInstance;
44
+ }
45
+
46
+ /**
47
+ * Clears the registry. Called by CoreBetterAuthModule.reset() so tests do not
48
+ * leak a token service from a previous testing module into the next one.
49
+ * @internal
50
+ */
51
+ export function resetBetterAuthRegistry(): void {
52
+ tokenServiceInstance = null;
53
+ }
@@ -13,7 +13,7 @@ import { resolveBetterAuthCookiePrefix } from './better-auth-cookie-prefix.helpe
13
13
  import { BetterAuthInstance } from './better-auth.config';
14
14
  import { BetterAuthSessionUser } from './core-better-auth-user.mapper';
15
15
  import { convertExpressHeaders, parseCookieHeader, signCookieValueIfNeeded } from './core-better-auth-web.helper';
16
- import { BETTER_AUTH_INSTANCE } from './core-better-auth.module';
16
+ import { BETTER_AUTH_CONFIG, BETTER_AUTH_COOKIE_DOMAIN, BETTER_AUTH_INSTANCE } from './core-better-auth.constants';
17
17
 
18
18
  /**
19
19
  * Result of a session validation
@@ -28,6 +28,24 @@ export interface SessionResult {
28
28
  user: BetterAuthSessionUser | null;
29
29
  }
30
30
 
31
+ /**
32
+ * @deprecated Import from `./core-better-auth.constants` instead. Re-exported only
33
+ * so existing deep imports keep working; it will be dropped in a future MINOR.
34
+ *
35
+ * Do NOT import these tokens from here inside the better-auth module itself — they
36
+ * must come from the constants leaf, or module and service start importing each
37
+ * other again and SWC builds crash with a temporal-dead-zone ReferenceError
38
+ * (see core-better-auth.constants.ts).
39
+ *
40
+ * NOTE: the `@deprecated` tag above is documentation only — TypeScript does not
41
+ * honor JSDoc on an `export … from` declaration. Do NOT try to "fix" that by
42
+ * re-declaring the tokens as local `const`s: that would give the barrel two
43
+ * distinct declarations of the same name and turn its `export *` into a TS2308
44
+ * ambiguity error. The mechanical guards are `pnpm run check:swc-tdz` and
45
+ * `tests/unit/better-auth-di-tokens.spec.ts`.
46
+ */
47
+ export { BETTER_AUTH_CONFIG, BETTER_AUTH_COOKIE_DOMAIN } from './core-better-auth.constants';
48
+
31
49
  /**
32
50
  * CoreBetterAuthService provides a NestJS-friendly wrapper around the better-auth instance.
33
51
  *
@@ -51,17 +69,6 @@ export interface SessionResult {
51
69
  * }
52
70
  * ```
53
71
  */
54
- /**
55
- * Injection token for resolved BetterAuth configuration
56
- */
57
- export const BETTER_AUTH_CONFIG = 'BETTER_AUTH_CONFIG';
58
-
59
- /**
60
- * Injection token for resolved cross-subdomain cookie domain.
61
- * Set during Better-Auth instance creation, undefined if disabled.
62
- */
63
- export const BETTER_AUTH_COOKIE_DOMAIN = 'BETTER_AUTH_COOKIE_DOMAIN';
64
-
65
72
  @Injectable()
66
73
  export class CoreBetterAuthService implements OnModuleInit {
67
74
  private readonly logger = new Logger(CoreBetterAuthService.name);
@@ -39,8 +39,17 @@ export * from './core-better-auth-signup-validator.service';
39
39
  export * from './core-better-auth-token.helper';
40
40
  export * from './core-better-auth-user.mapper';
41
41
  export * from './core-better-auth-web.helper';
42
+ export * from './core-better-auth.constants';
42
43
  export * from './core-better-auth.controller';
43
44
  export * from './core-better-auth.middleware';
44
45
  export * from './core-better-auth.module';
46
+ // NOT exported: './core-better-auth.registry'.
47
+ //
48
+ // It is module-internal plumbing that only exists so BetterAuthRolesGuard can reach
49
+ // BetterAuthTokenService without importing CoreBetterAuthModule (see .claude/rules/better-auth.md
50
+ // §6). Re-exporting it would put `setBetterAuthTokenService()` on the public API — letting a
51
+ // consumer swap or null the very token service the guard makes its authorization decisions with.
52
+ // Consumers that need the instance already have the public, read-only
53
+ // `CoreBetterAuthModule.getTokenServiceInstance()`.
45
54
  export * from './core-better-auth.resolver';
46
55
  export * from './core-better-auth.service';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Dependency-injection tokens of the TUS module.
3
+ *
4
+ * They live in a dedicated, import-free leaf file — never in `tus.module.ts` or a service — so that
5
+ * no file needing a token has to import the module (or vice versa) and close an import cycle.
6
+ *
7
+ * On a cycle, a token read at MODULE-EVALUATION time — inside an `@Inject()` decorator argument, in
8
+ * `design:paramtypes` metadata, or in a static field initializer — reads a `const` still in its
9
+ * temporal dead zone, and SWC-compiled builds (`nest start -b swc`) die at startup with:
10
+ *
11
+ * ReferenceError: Cannot access 'TUS_CONFIG' before initialization
12
+ *
13
+ * A file that imports nothing can never be mid-evaluation when someone imports it, in any module
14
+ * system, under any compiler. That is the whole point — keep it import-free.
15
+ *
16
+ * `tsc`, `pnpm test` and `oxlint` are all blind to a regression here; only `pnpm run check:swc-tdz`
17
+ * sees it. See .claude/rules/architecture.md → "DI Token Placement (SWC-Safe)".
18
+ */
19
+
20
+ /**
21
+ * Token for injecting the resolved TUS configuration.
22
+ *
23
+ * Injected type: `Required<ITusConfig>`.
24
+ */
25
+ export const TUS_CONFIG = 'TUS_CONFIG';
@@ -5,12 +5,17 @@ import { Connection } from 'mongoose';
5
5
  import { ITusConfig } from '../../common/interfaces/server-options.interface';
6
6
  import { CoreTusController } from './core-tus.controller';
7
7
  import { CoreTusService } from './core-tus.service';
8
+ import { TUS_CONFIG } from './tus.constants';
8
9
  import { normalizeTusConfig } from './interfaces/tus-config.interface';
9
10
 
10
11
  /**
11
- * Token for injecting the TUS configuration
12
+ * @deprecated Import from `./tus.constants` instead. Re-exported only so existing deep imports keep
13
+ * working; the token is declared in an import-free leaf so module and services stay acyclic
14
+ * (SWC-safe — see tus.constants.ts).
15
+ *
16
+ * Do NOT import it from here inside the TUS module itself — that is what re-creates the cycle.
12
17
  */
13
- export const TUS_CONFIG = 'TUS_CONFIG';
18
+ export { TUS_CONFIG } from './tus.constants';
14
19
 
15
20
  /**
16
21
  * Options for TusModule.forRoot()