@lenne.tech/nest-server 11.8.0 → 11.10.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 (173) hide show
  1. package/dist/config.env.js +5 -0
  2. package/dist/config.env.js.map +1 -1
  3. package/dist/core/common/helpers/logging.helper.d.ts +6 -0
  4. package/dist/core/common/helpers/logging.helper.js +55 -0
  5. package/dist/core/common/helpers/logging.helper.js.map +1 -0
  6. package/dist/core/common/interfaces/server-options.interface.d.ts +50 -19
  7. package/dist/core/modules/auth/guards/roles.guard.js +37 -5
  8. package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
  9. package/dist/core/modules/auth/services/core-auth.service.d.ts +5 -5
  10. package/dist/core/modules/auth/services/core-auth.service.js +9 -8
  11. package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
  12. package/dist/core/modules/auth/tokens.decorator.d.ts +1 -1
  13. package/dist/core/modules/better-auth/better-auth.config.js +32 -10
  14. package/dist/core/modules/better-auth/better-auth.config.js.map +1 -1
  15. package/dist/core/modules/better-auth/better-auth.resolver.d.ts +16 -16
  16. package/dist/core/modules/better-auth/better-auth.resolver.js +34 -34
  17. package/dist/core/modules/better-auth/better-auth.resolver.js.map +1 -1
  18. package/dist/core/modules/better-auth/better-auth.types.d.ts +2 -1
  19. package/dist/core/modules/better-auth/better-auth.types.js.map +1 -1
  20. package/dist/core/modules/better-auth/core-better-auth-api.middleware.d.ts +10 -0
  21. package/dist/core/modules/better-auth/core-better-auth-api.middleware.js +91 -0
  22. package/dist/core/modules/better-auth/core-better-auth-api.middleware.js.map +1 -0
  23. package/dist/core/modules/better-auth/core-better-auth-auth.model.d.ts +9 -0
  24. package/dist/core/modules/better-auth/{better-auth-auth.model.js → core-better-auth-auth.model.js} +17 -17
  25. package/dist/core/modules/better-auth/core-better-auth-auth.model.js.map +1 -0
  26. package/dist/core/modules/better-auth/{better-auth-migration-status.model.d.ts → core-better-auth-migration-status.model.d.ts} +1 -1
  27. package/dist/core/modules/better-auth/{better-auth-migration-status.model.js → core-better-auth-migration-status.model.js} +14 -14
  28. package/dist/core/modules/better-auth/core-better-auth-migration-status.model.js.map +1 -0
  29. package/dist/core/modules/better-auth/{better-auth-models.d.ts → core-better-auth-models.d.ts} +8 -8
  30. package/dist/core/modules/better-auth/{better-auth-models.js → core-better-auth-models.js} +61 -61
  31. package/dist/core/modules/better-auth/core-better-auth-models.js.map +1 -0
  32. package/dist/core/modules/better-auth/core-better-auth-rate-limit.middleware.d.ts +12 -0
  33. package/dist/core/modules/better-auth/{better-auth-rate-limit.middleware.js → core-better-auth-rate-limit.middleware.js} +10 -10
  34. package/dist/core/modules/better-auth/core-better-auth-rate-limit.middleware.js.map +1 -0
  35. package/dist/core/modules/better-auth/{better-auth-rate-limiter.service.d.ts → core-better-auth-rate-limiter.service.d.ts} +1 -1
  36. package/dist/core/modules/better-auth/{better-auth-rate-limiter.service.js → core-better-auth-rate-limiter.service.js} +8 -8
  37. package/dist/core/modules/better-auth/core-better-auth-rate-limiter.service.js.map +1 -0
  38. package/dist/core/modules/better-auth/{better-auth-user.mapper.d.ts → core-better-auth-user.mapper.d.ts} +1 -1
  39. package/dist/core/modules/better-auth/{better-auth-user.mapper.js → core-better-auth-user.mapper.js} +10 -9
  40. package/dist/core/modules/better-auth/core-better-auth-user.mapper.js.map +1 -0
  41. package/dist/core/modules/better-auth/core-better-auth-web.helper.d.ts +19 -0
  42. package/dist/core/modules/better-auth/core-better-auth-web.helper.js +152 -0
  43. package/dist/core/modules/better-auth/core-better-auth-web.helper.js.map +1 -0
  44. package/dist/core/modules/better-auth/core-better-auth.controller.d.ts +23 -32
  45. package/dist/core/modules/better-auth/core-better-auth.controller.js +184 -201
  46. package/dist/core/modules/better-auth/core-better-auth.controller.js.map +1 -1
  47. package/dist/core/modules/better-auth/core-better-auth.middleware.d.ts +22 -0
  48. package/dist/core/modules/better-auth/{better-auth.middleware.js → core-better-auth.middleware.js} +45 -18
  49. package/dist/core/modules/better-auth/core-better-auth.middleware.js.map +1 -0
  50. package/dist/core/modules/better-auth/{better-auth.module.d.ts → core-better-auth.module.d.ts} +6 -6
  51. package/dist/core/modules/better-auth/{better-auth.module.js → core-better-auth.module.js} +65 -60
  52. package/dist/core/modules/better-auth/core-better-auth.module.js.map +1 -0
  53. package/dist/core/modules/better-auth/core-better-auth.resolver.d.ts +19 -19
  54. package/dist/core/modules/better-auth/core-better-auth.resolver.js +18 -18
  55. package/dist/core/modules/better-auth/core-better-auth.resolver.js.map +1 -1
  56. package/dist/core/modules/better-auth/{better-auth.service.d.ts → core-better-auth.service.d.ts} +3 -2
  57. package/dist/core/modules/better-auth/{better-auth.service.js → core-better-auth.service.js} +75 -35
  58. package/dist/core/modules/better-auth/core-better-auth.service.js.map +1 -0
  59. package/dist/core/modules/better-auth/index.d.ts +11 -9
  60. package/dist/core/modules/better-auth/index.js +11 -9
  61. package/dist/core/modules/better-auth/index.js.map +1 -1
  62. package/dist/core/modules/error-code/core-error-code.controller.d.ts +7 -0
  63. package/dist/core/modules/error-code/core-error-code.controller.js +45 -0
  64. package/dist/core/modules/error-code/core-error-code.controller.js.map +1 -0
  65. package/dist/core/modules/error-code/core-error-code.service.d.ts +16 -0
  66. package/dist/core/modules/error-code/core-error-code.service.js +65 -0
  67. package/dist/core/modules/error-code/core-error-code.service.js.map +1 -0
  68. package/dist/core/modules/error-code/error-code.module.d.ts +7 -0
  69. package/dist/core/modules/error-code/error-code.module.js +64 -0
  70. package/dist/core/modules/error-code/error-code.module.js.map +1 -0
  71. package/dist/core/modules/error-code/error-codes.d.ts +219 -0
  72. package/dist/core/modules/error-code/error-codes.js +204 -0
  73. package/dist/core/modules/error-code/error-codes.js.map +1 -0
  74. package/dist/core/modules/error-code/index.d.ts +5 -0
  75. package/dist/core/modules/error-code/index.js +22 -0
  76. package/dist/core/modules/error-code/index.js.map +1 -0
  77. package/dist/core/modules/error-code/interfaces/error-code.interfaces.d.ts +12 -0
  78. package/dist/core/modules/error-code/interfaces/error-code.interfaces.js +3 -0
  79. package/dist/core/modules/error-code/interfaces/error-code.interfaces.js.map +1 -0
  80. package/dist/core/modules/user/interfaces/core-user-service-options.interface.d.ts +2 -2
  81. package/dist/core.module.js +14 -6
  82. package/dist/core.module.js.map +1 -1
  83. package/dist/index.d.ts +2 -0
  84. package/dist/index.js +2 -0
  85. package/dist/index.js.map +1 -1
  86. package/dist/server/modules/better-auth/better-auth.controller.d.ts +5 -5
  87. package/dist/server/modules/better-auth/better-auth.controller.js +4 -4
  88. package/dist/server/modules/better-auth/better-auth.controller.js.map +1 -1
  89. package/dist/server/modules/better-auth/better-auth.module.js +3 -3
  90. package/dist/server/modules/better-auth/better-auth.module.js.map +1 -1
  91. package/dist/server/modules/better-auth/better-auth.resolver.d.ts +17 -17
  92. package/dist/server/modules/better-auth/better-auth.resolver.js +18 -18
  93. package/dist/server/modules/better-auth/better-auth.resolver.js.map +1 -1
  94. package/dist/server/modules/error-code/error-code.controller.d.ts +8 -0
  95. package/dist/server/modules/error-code/error-code.controller.js +55 -0
  96. package/dist/server/modules/error-code/error-code.controller.js.map +1 -0
  97. package/dist/server/modules/error-code/error-code.service.d.ts +4 -0
  98. package/dist/server/modules/error-code/error-code.service.js +27 -0
  99. package/dist/server/modules/error-code/error-code.service.js.map +1 -0
  100. package/dist/server/modules/error-code/error-codes.d.ts +45 -0
  101. package/dist/server/modules/error-code/error-codes.js +24 -0
  102. package/dist/server/modules/error-code/error-codes.js.map +1 -0
  103. package/dist/server/modules/error-code/index.d.ts +3 -0
  104. package/dist/server/modules/error-code/index.js +20 -0
  105. package/dist/server/modules/error-code/index.js.map +1 -0
  106. package/dist/server/modules/user/user.service.d.ts +2 -2
  107. package/dist/server/modules/user/user.service.js +2 -2
  108. package/dist/server/modules/user/user.service.js.map +1 -1
  109. package/dist/server/server.module.js +7 -0
  110. package/dist/server/server.module.js.map +1 -1
  111. package/dist/test/test.helper.d.ts +1 -0
  112. package/dist/test/test.helper.js +5 -1
  113. package/dist/test/test.helper.js.map +1 -1
  114. package/dist/tsconfig.build.tsbuildinfo +1 -1
  115. package/package.json +6 -4
  116. package/src/config.env.ts +19 -0
  117. package/src/core/common/helpers/logging.helper.ts +134 -0
  118. package/src/core/common/interfaces/server-options.interface.ts +511 -237
  119. package/src/core/modules/auth/guards/roles.guard.ts +49 -7
  120. package/src/core/modules/auth/services/core-auth.service.ts +9 -8
  121. package/src/core/modules/better-auth/ARCHITECTURE.md +102 -0
  122. package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +277 -8
  123. package/src/core/modules/better-auth/README.md +97 -53
  124. package/src/core/modules/better-auth/better-auth.config.ts +66 -18
  125. package/src/core/modules/better-auth/better-auth.resolver.ts +32 -32
  126. package/src/core/modules/better-auth/better-auth.types.ts +3 -2
  127. package/src/core/modules/better-auth/core-better-auth-api.middleware.ts +134 -0
  128. package/src/core/modules/better-auth/{better-auth-auth.model.ts → core-better-auth-auth.model.ts} +6 -6
  129. package/src/core/modules/better-auth/{better-auth-migration-status.model.ts → core-better-auth-migration-status.model.ts} +1 -1
  130. package/src/core/modules/better-auth/{better-auth-models.ts → core-better-auth-models.ts} +9 -9
  131. package/src/core/modules/better-auth/{better-auth-rate-limit.middleware.ts → core-better-auth-rate-limit.middleware.ts} +5 -5
  132. package/src/core/modules/better-auth/{better-auth-rate-limiter.service.ts → core-better-auth-rate-limiter.service.ts} +2 -2
  133. package/src/core/modules/better-auth/{better-auth-user.mapper.ts → core-better-auth-user.mapper.ts} +4 -3
  134. package/src/core/modules/better-auth/core-better-auth-web.helper.ts +272 -0
  135. package/src/core/modules/better-auth/core-better-auth.controller.ts +386 -230
  136. package/src/core/modules/better-auth/{better-auth.middleware.ts → core-better-auth.middleware.ts} +57 -17
  137. package/src/core/modules/better-auth/{better-auth.module.ts → core-better-auth.module.ts} +77 -66
  138. package/src/core/modules/better-auth/core-better-auth.resolver.ts +42 -42
  139. package/src/core/modules/better-auth/{better-auth.service.ts → core-better-auth.service.ts} +86 -40
  140. package/src/core/modules/better-auth/index.ts +18 -11
  141. package/src/core/modules/error-code/INTEGRATION-CHECKLIST.md +291 -0
  142. package/src/core/modules/error-code/core-error-code.controller.ts +55 -0
  143. package/src/core/modules/error-code/core-error-code.service.ts +135 -0
  144. package/src/core/modules/error-code/error-code.module.ts +119 -0
  145. package/src/core/modules/error-code/error-codes.ts +405 -0
  146. package/src/core/modules/error-code/index.ts +14 -0
  147. package/src/core/modules/error-code/interfaces/error-code.interfaces.ts +99 -0
  148. package/src/core/modules/user/interfaces/core-user-service-options.interface.ts +3 -3
  149. package/src/core.module.ts +28 -12
  150. package/src/index.ts +7 -0
  151. package/src/server/modules/better-auth/better-auth.controller.ts +4 -4
  152. package/src/server/modules/better-auth/better-auth.module.ts +1 -1
  153. package/src/server/modules/better-auth/better-auth.resolver.ts +31 -31
  154. package/src/server/modules/error-code/README.md +131 -0
  155. package/src/server/modules/error-code/error-code.controller.ts +91 -0
  156. package/src/server/modules/error-code/error-code.service.ts +42 -0
  157. package/src/server/modules/error-code/error-codes.ts +65 -0
  158. package/src/server/modules/error-code/index.ts +8 -0
  159. package/src/server/modules/user/user.service.ts +2 -2
  160. package/src/server/server.module.ts +10 -0
  161. package/src/test/test.helper.ts +13 -1
  162. package/dist/core/modules/better-auth/better-auth-auth.model.d.ts +0 -9
  163. package/dist/core/modules/better-auth/better-auth-auth.model.js.map +0 -1
  164. package/dist/core/modules/better-auth/better-auth-migration-status.model.js.map +0 -1
  165. package/dist/core/modules/better-auth/better-auth-models.js.map +0 -1
  166. package/dist/core/modules/better-auth/better-auth-rate-limit.middleware.d.ts +0 -12
  167. package/dist/core/modules/better-auth/better-auth-rate-limit.middleware.js.map +0 -1
  168. package/dist/core/modules/better-auth/better-auth-rate-limiter.service.js.map +0 -1
  169. package/dist/core/modules/better-auth/better-auth-user.mapper.js.map +0 -1
  170. package/dist/core/modules/better-auth/better-auth.middleware.d.ts +0 -21
  171. package/dist/core/modules/better-auth/better-auth.middleware.js.map +0 -1
  172. package/dist/core/modules/better-auth/better-auth.module.js.map +0 -1
  173. package/dist/core/modules/better-auth/better-auth.service.js.map +0 -1
@@ -3,18 +3,18 @@ import { Request, Response } from 'express';
3
3
 
4
4
  import { Roles } from '../../../core/common/decorators/roles.decorator';
5
5
  import { RoleEnum } from '../../../core/common/enums/role.enum';
6
- import { BetterAuthAuthModel } from '../../../core/modules/better-auth/better-auth-auth.model';
7
- import { BetterAuthMigrationStatusModel } from '../../../core/modules/better-auth/better-auth-migration-status.model';
6
+ import { CoreBetterAuthAuthModel } from '../../../core/modules/better-auth/core-better-auth-auth.model';
7
+ import { CoreBetterAuthMigrationStatusModel } from '../../../core/modules/better-auth/core-better-auth-migration-status.model';
8
8
  import {
9
- BetterAuth2FASetupModel,
10
- BetterAuthFeaturesModel,
11
- BetterAuthPasskeyChallengeModel,
12
- BetterAuthPasskeyModel,
13
- BetterAuthSessionModel,
14
- } from '../../../core/modules/better-auth/better-auth-models';
15
- import { BetterAuthUserMapper } from '../../../core/modules/better-auth/better-auth-user.mapper';
16
- import { BetterAuthService } from '../../../core/modules/better-auth/better-auth.service';
9
+ CoreBetterAuth2FASetupModel,
10
+ CoreBetterAuthFeaturesModel,
11
+ CoreBetterAuthPasskeyChallengeModel,
12
+ CoreBetterAuthPasskeyModel,
13
+ CoreBetterAuthSessionModel,
14
+ } from '../../../core/modules/better-auth/core-better-auth-models';
15
+ import { CoreBetterAuthUserMapper } from '../../../core/modules/better-auth/core-better-auth-user.mapper';
17
16
  import { CoreBetterAuthResolver } from '../../../core/modules/better-auth/core-better-auth.resolver';
17
+ import { CoreBetterAuthService } from '../../../core/modules/better-auth/core-better-auth.service';
18
18
 
19
19
  /**
20
20
  * Server BetterAuth GraphQL Resolver
@@ -40,12 +40,12 @@ import { CoreBetterAuthResolver } from '../../../core/modules/better-auth/core-b
40
40
  * }
41
41
  * ```
42
42
  */
43
- @Resolver(() => BetterAuthAuthModel)
43
+ @Resolver(() => CoreBetterAuthAuthModel)
44
44
  @Roles(RoleEnum.ADMIN)
45
45
  export class BetterAuthResolver extends CoreBetterAuthResolver {
46
46
  constructor(
47
- protected override readonly betterAuthService: BetterAuthService,
48
- protected override readonly userMapper: BetterAuthUserMapper,
47
+ protected override readonly betterAuthService: CoreBetterAuthService,
48
+ protected override readonly userMapper: CoreBetterAuthUserMapper,
49
49
  ) {
50
50
  super(betterAuthService, userMapper);
51
51
  }
@@ -54,12 +54,12 @@ export class BetterAuthResolver extends CoreBetterAuthResolver {
54
54
  // Queries
55
55
  // ===========================================================================
56
56
 
57
- @Query(() => BetterAuthSessionModel, {
57
+ @Query(() => CoreBetterAuthSessionModel, {
58
58
  description: 'Get current Better-Auth session',
59
59
  nullable: true,
60
60
  })
61
61
  @Roles(RoleEnum.S_USER)
62
- override async betterAuthSession(@Context() ctx: { req: Request }): Promise<BetterAuthSessionModel | null> {
62
+ override async betterAuthSession(@Context() ctx: { req: Request }): Promise<CoreBetterAuthSessionModel | null> {
63
63
  return super.betterAuthSession(ctx);
64
64
  }
65
65
 
@@ -69,17 +69,17 @@ export class BetterAuthResolver extends CoreBetterAuthResolver {
69
69
  return super.betterAuthEnabled();
70
70
  }
71
71
 
72
- @Query(() => BetterAuthFeaturesModel, { description: 'Get enabled Better-Auth features' })
72
+ @Query(() => CoreBetterAuthFeaturesModel, { description: 'Get enabled Better-Auth features' })
73
73
  @Roles(RoleEnum.S_EVERYONE)
74
- override betterAuthFeatures(): BetterAuthFeaturesModel {
74
+ override betterAuthFeatures(): CoreBetterAuthFeaturesModel {
75
75
  return super.betterAuthFeatures();
76
76
  }
77
77
 
78
- @Query(() => BetterAuthMigrationStatusModel, {
78
+ @Query(() => CoreBetterAuthMigrationStatusModel, {
79
79
  description: 'Get migration status from Legacy Auth to Better-Auth (IAM) - Admin only',
80
80
  })
81
81
  @Roles(RoleEnum.ADMIN)
82
- override async betterAuthMigrationStatus(): Promise<BetterAuthMigrationStatusModel> {
82
+ override async betterAuthMigrationStatus(): Promise<CoreBetterAuthMigrationStatusModel> {
83
83
  return super.betterAuthMigrationStatus();
84
84
  }
85
85
 
@@ -92,12 +92,12 @@ export class BetterAuthResolver extends CoreBetterAuthResolver {
92
92
  return super.betterAuthToken(ctx);
93
93
  }
94
94
 
95
- @Query(() => [BetterAuthPasskeyModel], {
95
+ @Query(() => [CoreBetterAuthPasskeyModel], {
96
96
  description: 'List passkeys for the current user',
97
97
  nullable: true,
98
98
  })
99
99
  @Roles(RoleEnum.S_USER)
100
- override async betterAuthListPasskeys(@Context() ctx: { req: Request }): Promise<BetterAuthPasskeyModel[] | null> {
100
+ override async betterAuthListPasskeys(@Context() ctx: { req: Request }): Promise<CoreBetterAuthPasskeyModel[] | null> {
101
101
  return super.betterAuthListPasskeys(ctx);
102
102
  }
103
103
 
@@ -105,7 +105,7 @@ export class BetterAuthResolver extends CoreBetterAuthResolver {
105
105
  // Authentication Mutations
106
106
  // ===========================================================================
107
107
 
108
- @Mutation(() => BetterAuthAuthModel, {
108
+ @Mutation(() => CoreBetterAuthAuthModel, {
109
109
  description: 'Sign in via Better-Auth (email/password)',
110
110
  })
111
111
  @Roles(RoleEnum.S_EVERYONE)
@@ -113,11 +113,11 @@ export class BetterAuthResolver extends CoreBetterAuthResolver {
113
113
  @Args('email') email: string,
114
114
  @Args('password') password: string,
115
115
  @Context() ctx: { req: Request; res: Response },
116
- ): Promise<BetterAuthAuthModel> {
116
+ ): Promise<CoreBetterAuthAuthModel> {
117
117
  return super.betterAuthSignIn(email, password, ctx);
118
118
  }
119
119
 
120
- @Mutation(() => BetterAuthAuthModel, {
120
+ @Mutation(() => CoreBetterAuthAuthModel, {
121
121
  description: 'Sign up via Better-Auth (email/password)',
122
122
  })
123
123
  @Roles(RoleEnum.S_EVERYONE)
@@ -125,7 +125,7 @@ export class BetterAuthResolver extends CoreBetterAuthResolver {
125
125
  @Args('email') email: string,
126
126
  @Args('password') password: string,
127
127
  @Args('name', { nullable: true }) name?: string,
128
- ): Promise<BetterAuthAuthModel> {
128
+ ): Promise<CoreBetterAuthAuthModel> {
129
129
  return super.betterAuthSignUp(email, password, name);
130
130
  }
131
131
 
@@ -139,25 +139,25 @@ export class BetterAuthResolver extends CoreBetterAuthResolver {
139
139
  // 2FA Mutations
140
140
  // ===========================================================================
141
141
 
142
- @Mutation(() => BetterAuthAuthModel, {
142
+ @Mutation(() => CoreBetterAuthAuthModel, {
143
143
  description: 'Verify 2FA code during sign-in',
144
144
  })
145
145
  @Roles(RoleEnum.S_EVERYONE)
146
146
  override async betterAuthVerify2FA(
147
147
  @Args('code') code: string,
148
148
  @Context() ctx: { req: Request },
149
- ): Promise<BetterAuthAuthModel> {
149
+ ): Promise<CoreBetterAuthAuthModel> {
150
150
  return super.betterAuthVerify2FA(code, ctx);
151
151
  }
152
152
 
153
- @Mutation(() => BetterAuth2FASetupModel, {
153
+ @Mutation(() => CoreBetterAuth2FASetupModel, {
154
154
  description: 'Enable 2FA for the current user',
155
155
  })
156
156
  @Roles(RoleEnum.S_USER)
157
157
  override async betterAuthEnable2FA(
158
158
  @Args('password') password: string,
159
159
  @Context() ctx: { req: Request },
160
- ): Promise<BetterAuth2FASetupModel> {
160
+ ): Promise<CoreBetterAuth2FASetupModel> {
161
161
  return super.betterAuthEnable2FA(password, ctx);
162
162
  }
163
163
 
@@ -185,13 +185,13 @@ export class BetterAuthResolver extends CoreBetterAuthResolver {
185
185
  // Passkey Mutations
186
186
  // ===========================================================================
187
187
 
188
- @Mutation(() => BetterAuthPasskeyChallengeModel, {
188
+ @Mutation(() => CoreBetterAuthPasskeyChallengeModel, {
189
189
  description: 'Get passkey registration challenge for WebAuthn',
190
190
  })
191
191
  @Roles(RoleEnum.S_USER)
192
192
  override async betterAuthGetPasskeyChallenge(
193
193
  @Context() ctx: { req: Request },
194
- ): Promise<BetterAuthPasskeyChallengeModel> {
194
+ ): Promise<CoreBetterAuthPasskeyChallengeModel> {
195
195
  return super.betterAuthGetPasskeyChallenge(ctx);
196
196
  }
197
197
 
@@ -0,0 +1,131 @@
1
+ # Error Code Module - Reference Implementation
2
+
3
+ This directory contains the reference implementation for extending the ErrorCodeModule.
4
+
5
+ ## Purpose
6
+
7
+ Demonstrates **Scenario C: Custom Service + Controller via forRoot()** where a project:
8
+ 1. Defines its own error codes with a unique prefix (`SRV_*`)
9
+ 2. Creates a custom service extending `CoreErrorCodeService`
10
+ 3. Creates a **standalone** controller (not extending CoreErrorCodeController - see below)
11
+ 4. Uses `ErrorCodeModule.forRoot({ service, controller })` from Core
12
+
13
+ **No custom module needed!** The Core ErrorCodeModule handles everything.
14
+
15
+ ## Files
16
+
17
+ | File | Description |
18
+ |------|-------------|
19
+ | `error-codes.ts` | Server-specific error definitions (`SRV_*` prefix) |
20
+ | `error-code.service.ts` | Custom service registering `ServerErrors` |
21
+ | `error-code.controller.ts` | Custom controller with `/codes` endpoint |
22
+ | `index.ts` | Module exports |
23
+
24
+ ## Architecture
25
+
26
+ ```
27
+ ┌──────────────────────────────────────────────────────────────┐
28
+ │ Core ErrorCodeModule.forRoot() │
29
+ │ (@Global) │
30
+ ├──────────────────────────────────────────────────────────────┤
31
+ │ ┌─────────────────────┐ ┌─────────────────────────────┐ │
32
+ │ │ ErrorCodeService │ │ ErrorCodeController │ │
33
+ │ │ extends Core... │ │ (standalone - see below) │ │
34
+ │ │ │ │ │ │
35
+ │ │ - LTNS_* (core) │ │ GET /api/i18n/errors/codes│ │
36
+ │ │ - SRV_* (server) │ │ GET /api/i18n/errors/de │ │
37
+ │ │ │ │ GET /api/i18n/errors/en │ │
38
+ │ └─────────────────────┘ └─────────────────────────────┘ │
39
+ └──────────────────────────────────────────────────────────────┘
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ### In ServerModule
45
+
46
+ ```typescript
47
+ import { ErrorCodeModule } from '@lenne.tech/nest-server';
48
+ import { ErrorCodeController } from './modules/error-code/error-code.controller';
49
+ import { ErrorCodeService } from './modules/error-code/error-code.service';
50
+
51
+ @Module({
52
+ imports: [
53
+ CoreModule.forRoot({
54
+ // ...config
55
+ errorCode: {
56
+ autoRegister: false, // Required! Prevents CoreModule auto-registration
57
+ },
58
+ }),
59
+ // Use Core ErrorCodeModule with custom service and controller
60
+ ErrorCodeModule.forRoot({
61
+ controller: ErrorCodeController,
62
+ service: ErrorCodeService,
63
+ }),
64
+ ],
65
+ })
66
+ export class ServerModule {}
67
+ ```
68
+
69
+ ### In Code
70
+
71
+ ```typescript
72
+ import { ErrorCode } from './modules/error-code/error-codes';
73
+ import { Errors } from '@lenne.tech/nest-server';
74
+
75
+ // Access error codes
76
+ console.log(ErrorCode.DEMO_ERROR); // '#SRV_0001: Demo error for testing'
77
+
78
+ // Use factory functions
79
+ throw new BadRequestException(Errors.userNotFound({ email: 'test@example.com' }));
80
+ ```
81
+
82
+ ## When to Use This Pattern
83
+
84
+ Use Scenario C when you need:
85
+ - Custom REST endpoints (like `/codes`)
86
+ - Different route paths
87
+ - Complex controller logic
88
+
89
+ For simpler cases, see:
90
+ - **Scenario A**: `additionalErrorRegistry` in config (simplest)
91
+ - **Scenario B**: Custom service via inheritance
92
+
93
+ See `src/core/modules/error-code/INTEGRATION-CHECKLIST.md` for all scenarios.
94
+
95
+ ## Important Notes
96
+
97
+ ### Why Standalone Controller Instead of Extending?
98
+
99
+ The controller is **standalone** (does not extend `CoreErrorCodeController`) because:
100
+
101
+ **NestJS registers routes from parent classes first**, regardless of method declaration
102
+ order in child classes. This causes parameterized routes (`:locale`) to intercept
103
+ static routes (`/codes`), even if you re-declare the methods.
104
+
105
+ ```typescript
106
+ // DOES NOT WORK - parent route registered first!
107
+ @Controller('api/i18n/errors')
108
+ export class ErrorCodeController extends CoreErrorCodeController {
109
+ @Get('codes') // Registered AFTER parent's :locale
110
+ getAllCodes(): string[] { }
111
+
112
+ @Get(':locale') // Parent already registered this
113
+ override getTranslations() { }
114
+ }
115
+
116
+ // WORKS - standalone ensures correct order
117
+ @Controller('api/i18n/errors')
118
+ export class ErrorCodeController {
119
+ @Get('codes') // Registered first
120
+ getAllCodes(): string[] { }
121
+
122
+ @Get(':locale') // Registered second
123
+ getTranslations() { }
124
+ }
125
+ ```
126
+
127
+ **Key insight:** NestJS Controller inheritance does NOT work like Service inheritance for route ordering.
128
+
129
+ ### Why is `autoRegister: false` required?
130
+
131
+ NestJS `@Global()` modules use "first wins" for provider registration. Without `autoRegister: false`, CoreModule registers its ErrorCodeModule first, and your custom service is ignored.
@@ -0,0 +1,91 @@
1
+ import { Controller, Get, NotFoundException, Param } from '@nestjs/common';
2
+
3
+ import { Roles } from '../../../core/common/decorators/roles.decorator';
4
+ import { RoleEnum } from '../../../core/common/enums/role.enum';
5
+ import { IErrorTranslationResponse, SupportedLocale } from '../../../core/modules/error-code/interfaces/error-code.interfaces';
6
+ import { ErrorCodeService } from './error-code.service';
7
+
8
+ /**
9
+ * Server Error Code Controller
10
+ *
11
+ * Project-specific Error Code controller that provides error translation endpoints.
12
+ * This is a standalone controller (not extending CoreErrorCodeController) to ensure
13
+ * correct route registration order.
14
+ *
15
+ * Endpoints:
16
+ * - GET /api/i18n/errors/codes - Get all available error codes (custom)
17
+ * - GET /api/i18n/errors/:locale - Get translations for a locale
18
+ *
19
+ * **WHY standalone instead of extending CoreErrorCodeController?**
20
+ * NestJS registers routes from parent classes first, regardless of method declaration
21
+ * order in child classes. This causes parameterized routes (`:locale`) to intercept
22
+ * static routes (`/codes`). A standalone controller ensures predictable route ordering.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // In your module
27
+ * ErrorCodeModule.forRoot({
28
+ * controller: ErrorCodeController,
29
+ * service: ErrorCodeService,
30
+ * })
31
+ * ```
32
+ */
33
+ @Controller('api/i18n/errors')
34
+ export class ErrorCodeController {
35
+ constructor(protected readonly errorCodeService: ErrorCodeService) {}
36
+
37
+ /**
38
+ * Get all available error codes
39
+ *
40
+ * Returns a list of all registered error codes from all registries.
41
+ * This endpoint must be defined BEFORE the :locale endpoint to prevent
42
+ * "codes" being interpreted as a locale parameter.
43
+ *
44
+ * @returns Array of error codes
45
+ *
46
+ * @example
47
+ * Response:
48
+ * ```json
49
+ * ["LTNS_0001", "LTNS_0002", "SRV_0001", "SRV_0002"]
50
+ * ```
51
+ */
52
+ @Get('codes')
53
+ @Roles(RoleEnum.S_EVERYONE)
54
+ getAllCodes(): string[] {
55
+ return this.errorCodeService.getErrorCodes();
56
+ }
57
+
58
+ /**
59
+ * Get error translations for a specific locale
60
+ *
61
+ * Returns all error codes with their translations in Nuxt i18n compatible format.
62
+ *
63
+ * @param locale - Locale code (e.g., 'de', 'en')
64
+ * @returns Translations object
65
+ * @throws NotFoundException if locale is not supported
66
+ *
67
+ * @example
68
+ * Response:
69
+ * ```json
70
+ * {
71
+ * "errors": {
72
+ * "LTNS_0001": "Benutzer mit E-Mail {email} wurde nicht gefunden.",
73
+ * "LTNS_0002": "Das eingegebene Passwort ist ungültig.",
74
+ * "SRV_0001": "Dies ist ein Demo-Fehler zu Testzwecken."
75
+ * }
76
+ * }
77
+ * ```
78
+ */
79
+ @Get(':locale')
80
+ @Roles(RoleEnum.S_EVERYONE)
81
+ getTranslations(@Param('locale') locale: string): IErrorTranslationResponse {
82
+ if (!this.errorCodeService.isLocaleSupported(locale)) {
83
+ throw new NotFoundException(
84
+ `Locale "${locale}" is not supported. ` +
85
+ `Supported locales: ${this.errorCodeService.getSupportedLocales().join(', ')}`,
86
+ );
87
+ }
88
+
89
+ return this.errorCodeService.getTranslations(locale as SupportedLocale);
90
+ }
91
+ }
@@ -0,0 +1,42 @@
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import { CoreErrorCodeService } from '../../../core/modules/error-code/core-error-code.service';
4
+ import { ServerErrors } from './error-codes';
5
+
6
+ /**
7
+ * Server Error Code Service
8
+ *
9
+ * Extends CoreErrorCodeService with project-specific error codes.
10
+ * This service is automatically registered when using ErrorCodeModule.forRoot()
11
+ * with the service option.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // In your module
16
+ * ErrorCodeModule.forRoot({
17
+ * service: ErrorCodeService,
18
+ * })
19
+ * ```
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Extend with additional locales
24
+ * @Injectable()
25
+ * export class ErrorCodeService extends CoreErrorCodeService {
26
+ * protected override supportedLocales = ['de', 'en', 'fr', 'es'] as const;
27
+ *
28
+ * constructor() {
29
+ * super();
30
+ * this.registerErrorRegistry(ProjectErrors);
31
+ * }
32
+ * }
33
+ * ```
34
+ */
35
+ @Injectable()
36
+ export class ErrorCodeService extends CoreErrorCodeService {
37
+ constructor() {
38
+ super();
39
+ // Register project-specific errors
40
+ this.registerErrorRegistry(ServerErrors);
41
+ }
42
+ }
@@ -0,0 +1,65 @@
1
+ import { IErrorRegistry, mergeErrorCodes } from '../../../core/modules/error-code/error-codes';
2
+
3
+ /**
4
+ * Server-specific Error Registry
5
+ *
6
+ * Project-specific error codes that extend the core LTNS_* errors.
7
+ * Use a unique prefix (e.g., SRV_ for Server) to avoid conflicts.
8
+ *
9
+ * Error code ranges for this project:
10
+ * - SRV_0001-SRV_0099: Business logic errors
11
+ * - SRV_0100-SRV_0199: Integration errors
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { UnprocessableEntityException } from '@nestjs/common';
16
+ * import { ErrorCode } from './error-codes';
17
+ *
18
+ * throw new UnprocessableEntityException(ErrorCode.DEMO_ERROR);
19
+ * // Response: { statusCode: 422, message: "#SRV_0001: Demo error for testing" }
20
+ * ```
21
+ */
22
+ export const ServerErrors = {
23
+ // =====================================================
24
+ // Business Logic Errors (SRV_0001-SRV_0099)
25
+ // =====================================================
26
+
27
+ DEMO_ERROR: {
28
+ code: 'SRV_0001',
29
+ message: 'Demo error for testing',
30
+ translations: {
31
+ de: 'Dies ist ein Demo-Fehler zu Testzwecken.',
32
+ en: 'This is a demo error for testing purposes.',
33
+ },
34
+ },
35
+
36
+ FEATURE_NOT_AVAILABLE: {
37
+ code: 'SRV_0002',
38
+ message: 'Feature not available in this environment',
39
+ translations: {
40
+ de: 'Diese Funktion ist in dieser Umgebung nicht verfügbar.',
41
+ en: 'This feature is not available in this environment.',
42
+ },
43
+ },
44
+ } as const satisfies IErrorRegistry;
45
+
46
+ /**
47
+ * Merged ErrorCode object for use in this project
48
+ *
49
+ * Contains both core LTNS_* errors and project-specific SRV_* errors.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * // Core error
54
+ * throw new UnauthorizedException(ErrorCode.UNAUTHORIZED);
55
+ *
56
+ * // Project error
57
+ * throw new UnprocessableEntityException(ErrorCode.DEMO_ERROR);
58
+ * ```
59
+ */
60
+ export const ErrorCode = mergeErrorCodes(ServerErrors);
61
+
62
+ /**
63
+ * Type for all available error code keys
64
+ */
65
+ export type ServerErrorCodeKey = keyof typeof ErrorCode;
@@ -0,0 +1,8 @@
1
+ // Controller
2
+ export * from './error-code.controller';
3
+
4
+ // Service
5
+ export * from './error-code.service';
6
+
7
+ // Error Codes
8
+ export * from './error-codes';
@@ -9,7 +9,7 @@ import { ServiceOptions } from '../../../core/common/interfaces/service-options.
9
9
  import { ConfigService } from '../../../core/common/services/config.service';
10
10
  import { EmailService } from '../../../core/common/services/email.service';
11
11
  import { CoreModelConstructor } from '../../../core/common/types/core-model-constructor.type';
12
- import { BetterAuthUserMapper } from '../../../core/modules/better-auth/better-auth-user.mapper';
12
+ import { CoreBetterAuthUserMapper } from '../../../core/modules/better-auth/core-better-auth-user.mapper';
13
13
  import { CoreUserService } from '../../../core/modules/user/core-user.service';
14
14
  import { UserCreateInput } from './inputs/user-create.input';
15
15
  import { UserInput } from './inputs/user.input';
@@ -33,7 +33,7 @@ export class UserService extends CoreUserService<User, UserInput, UserCreateInpu
33
33
  @Inject('USER_CLASS') protected override readonly mainModelConstructor: CoreModelConstructor<User>,
34
34
  @InjectModel('User') protected override readonly mainDbModel: Model<UserDocument>,
35
35
  @Inject('PUB_SUB') protected readonly pubSub: PubSub,
36
- @Optional() private readonly betterAuthUserMapper?: BetterAuthUserMapper,
36
+ @Optional() private readonly betterAuthUserMapper?: CoreBetterAuthUserMapper,
37
37
  ) {
38
38
  super(configService, emailService, mainDbModel, mainModelConstructor, { betterAuthUserMapper });
39
39
  }
@@ -7,11 +7,14 @@ import { Any } from '../core/common/scalars/any.scalar';
7
7
  import { DateScalar } from '../core/common/scalars/date.scalar';
8
8
  import { JSON } from '../core/common/scalars/json.scalar';
9
9
  import { CoreAuthService } from '../core/modules/auth/services/core-auth.service';
10
+ import { ErrorCodeModule } from '../core/modules/error-code/error-code.module';
10
11
  import { TusModule } from '../core/modules/tus';
11
12
  import { CronJobs } from './common/services/cron-jobs.service';
12
13
  import { AuthController } from './modules/auth/auth.controller';
13
14
  import { AuthModule } from './modules/auth/auth.module';
14
15
  import { BetterAuthModule } from './modules/better-auth/better-auth.module';
16
+ import { ErrorCodeController } from './modules/error-code/error-code.controller';
17
+ import { ErrorCodeService } from './modules/error-code/error-code.service';
15
18
  import { FileModule } from './modules/file/file.module';
16
19
  import { ServerController } from './server.controller';
17
20
 
@@ -48,6 +51,13 @@ import { ServerController } from './server.controller';
48
51
  fallbackSecrets: [envConfig.jwt?.secret, envConfig.jwt?.refresh?.secret],
49
52
  }),
50
53
 
54
+ // Include ErrorCodeModule with project-specific error codes
55
+ // Uses Core ErrorCodeModule.forRoot() with custom service and controller
56
+ ErrorCodeModule.forRoot({
57
+ controller: ErrorCodeController,
58
+ service: ErrorCodeService,
59
+ }),
60
+
51
61
  // Include FileModule for file handling
52
62
  FileModule,
53
63
 
@@ -134,6 +134,11 @@ export interface TestRestOptions {
134
134
  logError?: boolean;
135
135
  method?: 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
136
136
  payload?: any;
137
+ /**
138
+ * Return the full response object including headers instead of just the body.
139
+ * Useful for inspecting Set-Cookie headers and other response metadata.
140
+ */
141
+ returnResponse?: boolean;
137
142
  statusCode?: number;
138
143
  token?: string;
139
144
  }
@@ -392,13 +397,14 @@ export class TestHelper {
392
397
  logError: false,
393
398
  method: options?.attachments ? 'POST' : 'GET',
394
399
  payload: null,
400
+ returnResponse: false,
395
401
  statusCode: 200,
396
402
  token: null,
397
403
  ...options,
398
404
  };
399
405
 
400
406
  // Init vars
401
- const { attachments, log, logError, statusCode, token } = config;
407
+ const { attachments, log, logError, returnResponse, statusCode, token } = config;
402
408
 
403
409
  // Request configuration
404
410
  const requestConfig: any = {
@@ -412,6 +418,12 @@ export class TestHelper {
412
418
 
413
419
  // Process response
414
420
  const response = await this.getResponse(token, requestConfig, statusCode, log, logError, null, attachments);
421
+
422
+ // Return full response if requested (useful for inspecting headers like Set-Cookie)
423
+ if (returnResponse) {
424
+ return response;
425
+ }
426
+
415
427
  let result = response.text;
416
428
  if (response.text === '') {
417
429
  return null;
@@ -1,9 +0,0 @@
1
- import { BetterAuthSessionInfoModel, BetterAuthUserModel } from './better-auth-models';
2
- export declare class BetterAuthAuthModel {
3
- success: boolean;
4
- requiresTwoFactor?: boolean;
5
- token?: string;
6
- user?: BetterAuthUserModel;
7
- session?: BetterAuthSessionInfoModel;
8
- error?: string;
9
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"better-auth-auth.model.js","sourceRoot":"","sources":["../../../../src/core/modules/better-auth/better-auth-auth.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAoD;AAEpD,uFAA0E;AAC1E,4DAAwD;AACxD,6DAAuF;AAWhF,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;CAqD/B,CAAA;AArDY,kDAAmB;AAK9B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,uCAAuC,EAAE,CAAC;;oDAC9D;AAUjB;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE;QACpB,WAAW,EAAE,0DAA0D;QACvE,QAAQ,EAAE,IAAI;KACf,CAAC;;8DAC0B;AAU5B;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE;QACnB,WAAW,EAAE,6DAA6D;QAC1E,QAAQ,EAAE,IAAI;KACf,CAAC;;kDACa;AASf;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,wCAAmB,EAAE;QAChC,WAAW,EAAE,oBAAoB;QACjC,QAAQ,EAAE,IAAI;KACf,CAAC;8BACK,wCAAmB;iDAAC;AAS3B;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,+CAA0B,EAAE;QACvC,WAAW,EAAE,qBAAqB;QAClC,QAAQ,EAAE,IAAI;KACf,CAAC;8BACQ,+CAA0B;oDAAC;AASrC;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE;QACnB,WAAW,EAAE,wCAAwC;QACrD,QAAQ,EAAE,IAAI;KACf,CAAC;;kDACa;8BApDJ,mBAAmB;IAF/B,IAAA,oBAAU,EAAC,EAAE,WAAW,EAAE,qCAAqC,EAAE,CAAC;IAClE,IAAA,iCAAU,EAAC,oBAAQ,CAAC,UAAU,CAAC;GACnB,mBAAmB,CAqD/B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"better-auth-migration-status.model.js","sourceRoot":"","sources":["../../../../src/core/modules/better-auth/better-auth-migration-status.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAyD;AAUlD,IAAM,8BAA8B,GAApC,MAAM,8BAA8B;CA8D1C,CAAA;AA9DY,wEAA8B;AAKzC;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,aAAG,EAAE,EAAE,WAAW,EAAE,qCAAqC,EAAE,CAAC;;kEACtD;AAOnB;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,aAAG,EAAE,EAAE,WAAW,EAAE,4CAA4C,EAAE,CAAC;;sEACzD;AAOvB;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,aAAG,EAAE,EAAE,WAAW,EAAE,6CAA6C,EAAE,CAAC;;2EACrD;AAM5B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,aAAG,EAAE,EAAE,WAAW,EAAE,6DAA6D,EAAE,CAAC;;0EACtE;AAO3B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,aAAG,EAAE,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;;6EACxC;AAM9B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,4CAA4C,EAAE,CAAC;;2EACvD;AAa5B;IAHC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE;QACpB,WAAW,EAAE,2FAA2F;KACzG,CAAC;;4EAC4B;AAU9B;IAJC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE;QACrB,WAAW,EAAE,6CAA6C;QAC1D,QAAQ,EAAE,IAAI;KACf,CAAC;;yEAC2B;yCA7DlB,8BAA8B;IAD1C,IAAA,oBAAU,EAAC,EAAE,WAAW,EAAE,wDAAwD,EAAE,CAAC;GACzE,8BAA8B,CA8D1C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"better-auth-models.js","sourceRoot":"","sources":["../../../../src/core/modules/better-auth/better-auth-models.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAoD;AAEpD,uFAA0E;AAC1E,4DAAwD;AAOjD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;CAqB/B,CAAA;AArBY,kDAAmB;AAE9B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;;+CACrC;AAGX;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,0CAA0C,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;kDAClF;AAGf;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;;kDACxC;AAGd;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,IAA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EAAE,CAAC;IACzE,IAAA,iCAAU,EAAC,oBAAQ,CAAC,MAAM,CAAC;GACf,+BAA+B,CAS3C;AAOM,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;CAenC,CAAA;AAfY,0DAAuB;AAElC;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;;wDACvD;AAGjB;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;;oDAC1D;AAGb;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC;;0DAC7C;AAGnB;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,4BAA4B,EAAE,CAAC;;wDACnD;AAGjB;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;;gEACjD;kCAdf,uBAAuB;IAFnC,IAAA,oBAAU,EAAC,EAAE,WAAW,EAAE,6BAA6B,EAAE,CAAC;IAC1D,IAAA,iCAAU,EAAC,oBAAQ,CAAC,UAAU,CAAC;GACnB,uBAAuB,CAenC"}
@@ -1,12 +0,0 @@
1
- import { NestMiddleware } from '@nestjs/common';
2
- import { NextFunction, Request, Response } from 'express';
3
- import { BetterAuthRateLimiter } from './better-auth-rate-limiter.service';
4
- import { BetterAuthService } from './better-auth.service';
5
- export declare class BetterAuthRateLimitMiddleware implements NestMiddleware {
6
- private readonly rateLimiter;
7
- private readonly betterAuthService;
8
- constructor(rateLimiter: BetterAuthRateLimiter, betterAuthService: BetterAuthService);
9
- use(req: Request, res: Response, next: NextFunction): void;
10
- private getClientIp;
11
- private addRateLimitHeaders;
12
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"better-auth-rate-limit.middleware.js","sourceRoot":"","sources":["../../../../src/core/modules/better-auth/better-auth-rate-limit.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAuF;AAGvF,yFAA4F;AAC5F,+DAA0D;AA4BnD,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IACxC,YACmB,WAAkC,EAClC,iBAAoC;QADpC,gBAAW,GAAX,WAAW,CAAuB;QAClC,sBAAiB,GAAjB,iBAAiB,CAAmB;IACpD,CAAC;IAEJ,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QAEjD,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,EAAE,CAAC;YACxC,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAGD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,CAAC;YAClC,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAGD,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAGjC,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC;QACtD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;QAG5F,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAGhD,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAGtC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,sBAAa,CACrB;gBACE,KAAK,EAAE,mBAAmB;gBAC1B,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE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