@anarchitects/auth-nest 0.0.1 → 0.4.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 (55) hide show
  1. package/README.md +217 -18
  2. package/package.json +26 -12
  3. package/src/application/application.module-definition.d.ts +4 -21
  4. package/src/application/application.module-definition.js.map +1 -1
  5. package/src/application/application.module.d.ts +6 -26
  6. package/src/application/application.module.js +47 -24
  7. package/src/application/application.module.js.map +1 -1
  8. package/src/application/index.d.ts +1 -0
  9. package/src/auth.module.d.ts +7 -0
  10. package/src/auth.module.js +60 -0
  11. package/src/auth.module.js.map +1 -0
  12. package/src/config/auth.config.d.ts +16 -0
  13. package/src/config/auth.config.js +44 -7
  14. package/src/config/auth.config.js.map +1 -1
  15. package/src/config/index.d.ts +1 -0
  16. package/src/config/index.js +1 -0
  17. package/src/config/index.js.map +1 -1
  18. package/src/config/module-options.d.ts +57 -0
  19. package/src/config/module-options.js +58 -0
  20. package/src/config/module-options.js.map +1 -0
  21. package/src/index.d.ts +1 -0
  22. package/src/index.js +1 -0
  23. package/src/index.js.map +1 -1
  24. package/src/infrastructure-mailer/adapters/node-mailer.adapter.d.ts +1 -8
  25. package/src/infrastructure-mailer/adapters/node-mailer.adapter.js +2 -19
  26. package/src/infrastructure-mailer/adapters/node-mailer.adapter.js.map +1 -1
  27. package/src/infrastructure-mailer/index.d.ts +1 -1
  28. package/src/infrastructure-mailer/index.js +0 -1
  29. package/src/infrastructure-mailer/index.js.map +1 -1
  30. package/src/infrastructure-mailer/mailer.module.d.ts +5 -1
  31. package/src/infrastructure-mailer/mailer.module.js +36 -17
  32. package/src/infrastructure-mailer/mailer.module.js.map +1 -1
  33. package/src/infrastructure-persistence/index.d.ts +2 -0
  34. package/src/infrastructure-persistence/index.js +1 -0
  35. package/src/infrastructure-persistence/index.js.map +1 -1
  36. package/src/infrastructure-persistence/migrations/{1720200000000-create-invalidated-tokens-cache.table.d.ts → 1720200000000-create-auth-schema.d.ts} +1 -1
  37. package/src/infrastructure-persistence/migrations/1720200000000-create-auth-schema.js +312 -0
  38. package/src/infrastructure-persistence/migrations/1720200000000-create-auth-schema.js.map +1 -0
  39. package/src/infrastructure-persistence/persistence.module-definition.d.ts +4 -9
  40. package/src/infrastructure-persistence/persistence.module-definition.js.map +1 -1
  41. package/src/infrastructure-persistence/persistence.module.d.ts +5 -5
  42. package/src/infrastructure-persistence/persistence.module.js +33 -22
  43. package/src/infrastructure-persistence/persistence.module.js.map +1 -1
  44. package/src/presentation/controllers/auth.controller.d.ts +9 -27
  45. package/src/presentation/controllers/auth.controller.js +18 -30
  46. package/src/presentation/controllers/auth.controller.js.map +1 -1
  47. package/src/presentation/index.d.ts +1 -0
  48. package/src/presentation/presentation.module.d.ts +5 -1
  49. package/src/presentation/presentation.module.js +42 -5
  50. package/src/presentation/presentation.module.js.map +1 -1
  51. package/src/infrastructure-mailer/adapters/mailer.adapter.d.ts +0 -4
  52. package/src/infrastructure-mailer/adapters/mailer.adapter.js +0 -7
  53. package/src/infrastructure-mailer/adapters/mailer.adapter.js.map +0 -1
  54. package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js +0 -29
  55. package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js.map +0 -1
package/README.md CHANGED
@@ -2,49 +2,208 @@
2
2
 
3
3
  NestJS services, controllers, and infrastructure for the Anarchitecture authentication domain. This package wires contract-driven DTOs from `@anarchitects/auth-ts`, orchestrates user lifecycle flows (registration, activation, login/logout, password management, email verification), and persists auth state through pluggable repositories.
4
4
 
5
+ ## Developer + AI Agent Start Here
6
+
7
+ - Read this README before generating integration code for `@anarchitects/auth-nest`.
8
+ - Start with `AuthModule.forRoot(...)` or `AuthModule.forRootFromConfig(...)` from the root entry point unless you need explicit layered composition.
9
+ - Keep shared mail transport setup at app root via `@anarchitects/common-nest-mailer`; keep auth mailer infrastructure adapter-only.
10
+ - Use DTO contracts from `@anarchitects/auth-ts` and preserve `presentation -> application <- infrastructure` boundaries.
11
+
5
12
  ## Features
6
13
 
7
- - Application layer (`JwtAuthService`, `BcryptHashService`, strategies) encapsulating business rules for tokens and password workflows.
8
- - Presentation controllers that expose REST handlers using shared DTOs.
9
- - Infrastructure persistence module (`PersistenceModule`) with TypeORM entities and repositories (users, roles, permissions, invalidated tokens).
10
- - Configurable persistence adapters to swap implementations while preserving the application contract.
14
+ - **Application layer** `JwtAuthService`, `BcryptHashService`, JWT Passport strategy, CASL-based `PoliciesService` and `AbilityFactory` encapsulating business rules for tokens, passwords, and fine-grained access control.
15
+ - **Presentation layer** `AuthController` exposing REST handlers for the full auth lifecycle, `PoliciesGuard` and `@Policies()` decorator for route-level authorization.
16
+ - **Infrastructure persistence** `PersistenceModule` with TypeORM entities and repositories (users, roles, permissions, invalidated tokens). Configurable adapters to swap implementations while preserving the application contract.
17
+ - **Infrastructure mailer** `AuthMailerModule` wrapper over shared `CommonMailerModule.forRoot(...)` provider wiring; `NodeMailerAdapter` is re-exported for compatibility.
18
+ - **Config** – Typed `authConfig` namespace using `@nestjs/config` with an `InjectAuthConfig()` helper decorator.
11
19
 
12
20
  ## Installation
13
21
 
14
22
  ```bash
15
- npm install @anarchitects/auth-nest
23
+ npm install @anarchitects/auth-nest @nestjs/common @nestjs/config @nestjs/core @nestjs/jwt @nestjs/passport @nestjs/platform-fastify @nestjs/typeorm typeorm
16
24
  # or
17
- yarn add @anarchitects/auth-nest
25
+ yarn add @anarchitects/auth-nest @nestjs/common @nestjs/config @nestjs/core @nestjs/jwt @nestjs/passport @nestjs/platform-fastify @nestjs/typeorm typeorm
18
26
  ```
19
27
 
20
28
  Peer requirements:
21
29
 
22
- - `@nestjs/common`, `@nestjs/core`, `@nestjs/jwt`, `@nestjs/typeorm`
23
- - `@anarchitects/auth-ts` for DTOs and shared models
30
+ - `@nestjs/common`, `@nestjs/core`, `@nestjs/jwt`, `@nestjs/typeorm`, `@nestjs/config`, `@nestjs/passport`
31
+ - `@nestjs/platform-fastify`, `typeorm`
32
+
33
+ The internal `@anarchitects/auth-ts` and `@anarchitects/common-nest-mailer` packages are installed transitively. Runtime utilities such as `@casl/ability`, `bcrypt`, and `passport-jwt` are direct dependencies of this package. Add `@nestjs-modules/mailer` only when your host app enables the shared/common mailer integration.
34
+
35
+ ## Exports
36
+
37
+ | Import path | Contents |
38
+ | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
39
+ | `@anarchitects/auth-nest` | `AuthModule.forRoot(...)`, `AuthModule.forRootFromConfig(...)`, plus re-exports of layered entry points for convenience |
40
+ | `@anarchitects/auth-nest/application` | `AuthApplicationModule`, `AuthService`, `JwtAuthService`, `HashService`, `BcryptHashService`, `PoliciesService`, `AbilityFactory`, `JwtStrategy` |
41
+ | `@anarchitects/auth-nest/presentation` | `AuthPresentationModule`, `AuthController`, `PoliciesGuard`, `@Policies()` decorator |
42
+ | `@anarchitects/auth-nest/infrastructure-persistence` | `AuthPersistenceModule`, `AuthUserRepository`, `TypeormAuthUserRepository`, migration |
43
+ | `@anarchitects/auth-nest/infrastructure-mailer` | `AuthMailerModule`, `NodeMailerAdapter` |
44
+ | `@anarchitects/auth-nest/config` | `authConfig`, `AuthConfig` type, `InjectAuthConfig()` |
45
+
46
+ ## Configuration
47
+
48
+ The library reads configuration through `@nestjs/config` using a namespaced `authConfig` registered under the key `auth`. Set the following environment variables to customise behaviour:
49
+
50
+ | Variable | Description | Default |
51
+ | --------------------------- | ------------------------------------------------------------------------------------ | ------------------------ |
52
+ | `AUTH_JWT_SECRET` | Secret key used to sign and verify JWTs. **Must** be overridden in production. | `default_jwt_secret` |
53
+ | `AUTH_JWT_EXPIRATION` | Token lifetime (e.g. `3600s`, `15m`, `1d`). | `3600s` |
54
+ | `AUTH_JWT_AUDIENCE` | Expected `aud` claim in the JWT. | `your_audience` |
55
+ | `AUTH_JWT_ISSUER` | Expected `iss` claim in the JWT. | `your_issuer` |
56
+ | `AUTH_ENCRYPTION_ALGORITHM` | Password hashing algorithm (`bcrypt`). | `bcrypt` |
57
+ | `AUTH_ENCRYPTION_KEY` | Symmetric key for additional encryption needs. **Must** be overridden in production. | `default_encryption_key` |
58
+ | `AUTH_PERSISTENCE` | Persistence adapter key used by `forRootFromConfig(...)`. | `typeorm` |
59
+ | `AUTH_MAILER_PROVIDER` | Domain mailer provider for `forRootFromConfig(...)` (`node` or `noop`). | `node` |
60
+ | `AUTH_STRATEGIES` | Comma-separated auth strategies for config-driven module composition. | `jwt` |
61
+
62
+ > **Security note:** The defaults for `AUTH_JWT_SECRET` and `AUTH_ENCRYPTION_KEY` are intentionally insecure placeholders. Always provide strong, unique values in any deployed environment.
63
+
64
+ ### Injecting the config
65
+
66
+ ```ts
67
+ import { InjectAuthConfig, AuthConfig } from '@anarchitects/auth-nest/config';
68
+
69
+ @Injectable()
70
+ export class MyService {
71
+ constructor(@InjectAuthConfig() private readonly config: AuthConfig) {}
72
+
73
+ someMethod() {
74
+ const secret = this.config.jwtSecret;
75
+ }
76
+ }
77
+ ```
78
+
79
+ Make sure to import `authConfig` into your module's `ConfigModule`:
80
+
81
+ ```ts
82
+ import { ConfigModule } from '@nestjs/config';
83
+ import { authConfig } from '@anarchitects/auth-nest/config';
84
+
85
+ @Module({
86
+ imports: [ConfigModule.forRoot({ load: [authConfig] })],
87
+ })
88
+ export class AppModule {}
89
+ ```
24
90
 
25
91
  ## Usage
26
92
 
27
- ### Importing modules
93
+ ### Easy mode (single facade import)
28
94
 
29
95
  ```ts
30
96
  import { Module } from '@nestjs/common';
31
- import { JwtModule } from '@nestjs/jwt';
32
- import { PersistenceModule } from '@anarchitects/auth-nest/infrastructure-persistence';
33
- import { PresentationModule } from '@anarchitects/auth-nest/presentation';
97
+ import { ConfigModule } from '@nestjs/config';
98
+ import {
99
+ CommonMailerModule,
100
+ mailerConfig,
101
+ } from '@anarchitects/common-nest-mailer';
102
+ import { AuthModule } from '@anarchitects/auth-nest';
103
+ import { authConfig } from '@anarchitects/auth-nest/config';
34
104
 
35
105
  @Module({
36
106
  imports: [
37
- JwtModule.register({
38
- secret: process.env.JWT_SECRET,
39
- signOptions: { expiresIn: '15m' },
107
+ ConfigModule.forRoot({
108
+ isGlobal: true,
109
+ load: [authConfig, mailerConfig],
110
+ }),
111
+ CommonMailerModule.forRootFromConfig(),
112
+ AuthModule.forRoot({
113
+ presentation: {
114
+ application: {
115
+ authStrategies: ['jwt'],
116
+ encryption: {
117
+ algorithm: 'bcrypt',
118
+ key: process.env.AUTH_ENCRYPTION_KEY!,
119
+ },
120
+ persistence: {
121
+ persistence: 'typeorm',
122
+ },
123
+ },
124
+ },
125
+ mailer: {
126
+ provider: 'node',
127
+ },
40
128
  }),
41
- PersistenceModule.register({ persistence: 'typeorm' }),
42
- PresentationModule,
43
129
  ],
44
130
  })
45
131
  export class AuthApiModule {}
46
132
  ```
47
133
 
134
+ `AuthModule.forRoot(...)` is the preferred integration path when you want a full auth stack with minimal host-module wiring.
135
+
136
+ Use `AuthModule.forRootFromConfig()` when you want module composition fully driven by `AUTH_*`
137
+ variables exposed via `authConfig`.
138
+
139
+ Disable domain mailer wiring when not needed:
140
+
141
+ ```ts
142
+ AuthModule.forRoot({
143
+ presentation: { application: { ... } },
144
+ mailer: { provider: 'noop' },
145
+ });
146
+ ```
147
+
148
+ ### Layered composition (advanced)
149
+
150
+ ```ts
151
+ import { Module } from '@nestjs/common';
152
+ import { ConfigModule } from '@nestjs/config';
153
+ import {
154
+ CommonMailerModule,
155
+ mailerConfig,
156
+ } from '@anarchitects/common-nest-mailer';
157
+ import { authConfig } from '@anarchitects/auth-nest/config';
158
+ import { AuthApplicationModule } from '@anarchitects/auth-nest/application';
159
+ import { AuthPresentationModule } from '@anarchitects/auth-nest/presentation';
160
+ import { AuthMailerModule } from '@anarchitects/auth-nest/infrastructure-mailer';
161
+
162
+ @Module({
163
+ imports: [
164
+ ConfigModule.forRoot({
165
+ isGlobal: true,
166
+ load: [authConfig, mailerConfig],
167
+ }),
168
+ CommonMailerModule.forRootFromConfig(),
169
+ AuthApplicationModule.forRoot({
170
+ authStrategies: ['jwt'],
171
+ encryption: {
172
+ algorithm: 'bcrypt',
173
+ key: process.env.AUTH_ENCRYPTION_KEY!,
174
+ },
175
+ persistence: { persistence: 'typeorm' },
176
+ }),
177
+ AuthPresentationModule.forRoot({
178
+ application: {
179
+ authStrategies: ['jwt'],
180
+ encryption: {
181
+ algorithm: 'bcrypt',
182
+ key: process.env.AUTH_ENCRYPTION_KEY!,
183
+ },
184
+ persistence: { persistence: 'typeorm' },
185
+ },
186
+ }),
187
+ AuthMailerModule.forRoot({
188
+ provider: 'node',
189
+ }),
190
+ ],
191
+ })
192
+ export class AuthApiModule {}
193
+ ```
194
+
195
+ Use layered composition when you need to replace or selectively compose infrastructure/application concerns.
196
+
197
+ ## Mailer Migration Note
198
+
199
+ `AuthMailerModule` is now adapter-only. It wraps shared `CommonMailerModule.forRoot(...)`
200
+ provider wiring from `@anarchitects/common-nest-mailer` and no longer configures transport with
201
+ `MailerModule.forRootAsync(...)`.
202
+ Configure transport once at app root with `CommonMailerModule`.
203
+ Set `mailer.provider: 'noop'` to disable active delivery behavior per domain.
204
+ The shared mailer DI contract (`MailerPort`) and concrete `NodeMailerAdapter` now live in
205
+ `@anarchitects/common-nest-mailer`.
206
+
48
207
  ### Injecting services
49
208
 
50
209
  ```ts
@@ -68,9 +227,47 @@ export class AuthController {
68
227
  ```ts
69
228
  import { TypeormAuthUserRepository } from '@anarchitects/auth-nest/infrastructure-persistence';
70
229
 
71
- await authUserRepository.invalidateTokens([hashedAccessToken, hashedRefreshToken], userId);
230
+ await authUserRepository.invalidateTokens(
231
+ [hashedAccessToken, hashedRefreshToken],
232
+ userId,
233
+ );
234
+ ```
235
+
236
+ ### Route-level authorization with policies
237
+
238
+ ```ts
239
+ import { Controller, Get, UseGuards } from '@nestjs/common';
240
+ import { PoliciesGuard, Policies } from '@anarchitects/auth-nest/presentation';
241
+
242
+ @Controller('admin')
243
+ @UseGuards(PoliciesGuard)
244
+ export class AdminController {
245
+ @Get()
246
+ @Policies({ action: 'manage', subject: 'User' })
247
+ getAdminDashboard() {
248
+ return { status: 'ok' };
249
+ }
250
+ }
72
251
  ```
73
252
 
253
+ ## REST endpoints
254
+
255
+ The `AuthController` exposes the following routes (all prefixed with `/auth`):
256
+
257
+ | Method | Path | Description |
258
+ | ------- | ------------------------------- | -------------------------------------- |
259
+ | `POST` | `/auth/register` | Register a new user |
260
+ | `PATCH` | `/auth/activate` | Activate a user account |
261
+ | `POST` | `/auth/login` | Log in and receive JWT tokens |
262
+ | `POST` | `/auth/logout` | Log out and invalidate tokens |
263
+ | `PATCH` | `/auth/change-password/:userId` | Change password for a user |
264
+ | `POST` | `/auth/forgot-password` | Request a password-reset email |
265
+ | `POST` | `/auth/reset-password` | Reset password with token |
266
+ | `POST` | `/auth/verify-email` | Verify an email address |
267
+ | `PATCH` | `/auth/update-email/:userId` | Update email for a user |
268
+ | `POST` | `/auth/refresh-tokens/:userId` | Refresh access/refresh tokens |
269
+ | `GET` | `/auth/me` | Get logged-in user info and RBAC rules |
270
+
74
271
  ## Nx scripts
75
272
 
76
273
  - `nx build auth-nest` – bundle the Nest library.
@@ -82,6 +279,8 @@ await authUserRepository.invalidateTokens([hashedAccessToken, hashedRefreshToken
82
279
  - DTO shapes live in `@anarchitects/auth-ts`; update the contract and regenerate DTOs before extending this library.
83
280
  - Default persistence is TypeORM with schema-qualified tables (see `libs/auth/nest/src/infrastructure-persistence`).
84
281
  - Invalidated tokens use an unlogged cache table for quick revocation lookups.
282
+ - Route schemas are defined in `@anarchitects/auth-ts/dtos` and imported into controller `@RouteSchema` decorators — do not define inline schemas.
283
+ - OpenAPI metadata (`operationId`, `tags`) is assigned in `tools/api-specs/route-metadata.ts`, not in controllers.
85
284
 
86
285
  ## License
87
286
 
package/package.json CHANGED
@@ -1,25 +1,27 @@
1
1
  {
2
2
  "name": "@anarchitects/auth-nest",
3
- "version": "0.0.1",
3
+ "version": "0.4.0",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
7
7
  "dependencies": {
8
+ "@anarchitects/auth-ts": "^0.4.0",
9
+ "@anarchitects/common-nest-mailer": "^0.3.0",
10
+ "@casl/ability": "^6.7.3",
11
+ "bcrypt": "^6.0.0",
12
+ "passport-jwt": "^4.0.1",
8
13
  "tslib": "^2.3.0",
14
+ "uuidv7": "^1.0.2"
15
+ },
16
+ "peerDependencies": {
9
17
  "@nestjs/common": "^11.0.0",
18
+ "@nestjs/config": "^4.0.2",
19
+ "@nestjs/core": "^11.0.0",
10
20
  "@nestjs/jwt": "^11.0.1",
11
- "@anarchitects/auth-ts": "0.0.1",
12
- "bcrypt": "^6.0.0",
13
21
  "@nestjs/passport": "^11.0.5",
14
- "passport-jwt": "^4.0.1",
15
- "@nestjs/config": "^4.0.2",
16
- "@nestjs-modules/mailer": "^2.0.2",
17
- "typeorm": "^0.3.27",
18
- "uuidv7": "^1.0.2",
19
- "@nestjs/typeorm": "^11.0.0",
20
22
  "@nestjs/platform-fastify": "^11.1.6",
21
- "@casl/ability": "^6.7.3",
22
- "@nestjs/core": "^11.0.0"
23
+ "@nestjs/typeorm": "^11.0.0",
24
+ "typeorm": "^0.3.27"
23
25
  },
24
26
  "publishConfig": {
25
27
  "access": "public"
@@ -37,9 +39,21 @@
37
39
  ],
38
40
  "presentation": [
39
41
  "src/presentation/index.d.ts"
42
+ ],
43
+ "config": [
44
+ "src/config/index.d.ts"
40
45
  ]
41
46
  }
42
47
  },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/anarchitects/anarchitecture-bricks-3tier.git",
51
+ "directory": "libs/auth/nest"
52
+ },
53
+ "homepage": "https://github.com/anarchitects/anarchitecture-bricks-3tier/tree/main/libs/auth/nest",
54
+ "bugs": {
55
+ "url": "https://github.com/anarchitects/anarchitecture-bricks-3tier/issues"
56
+ },
43
57
  "exports": {
44
58
  "./package.json": "./package.json",
45
59
  ".": {
@@ -57,4 +71,4 @@
57
71
  "./config": "./src/config/index.js",
58
72
  "./config/index": "./src/config/index.js"
59
73
  }
60
- }
74
+ }
@@ -1,25 +1,8 @@
1
- export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<{
2
- authStrategies: string[];
3
- encryption: {
4
- algorithm: "bcrypt" | "argon2";
5
- key: string;
6
- };
7
- }, "forRoot", "create", {
1
+ import type { ResolvedAuthApplicationModuleOptions } from '../config';
2
+ export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ResolvedAuthApplicationModuleOptions, "forRoot", "create", {
8
3
  isGlobal?: boolean;
9
- }>, AUTH_APPLICATION_MODULE_OPTIONS: string | symbol, OPTIONS_TYPE: {
10
- authStrategies: string[];
11
- encryption: {
12
- algorithm: "bcrypt" | "argon2";
13
- key: string;
14
- };
15
- } & Partial<{
4
+ }>, AUTH_APPLICATION_MODULE_OPTIONS: string | symbol, OPTIONS_TYPE: ResolvedAuthApplicationModuleOptions & Partial<{
16
5
  isGlobal?: boolean;
17
- }>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<{
18
- authStrategies: string[];
19
- encryption: {
20
- algorithm: "bcrypt" | "argon2";
21
- key: string;
22
- };
23
- }, "create"> & Partial<{
6
+ }>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<ResolvedAuthApplicationModuleOptions, "create"> & Partial<{
24
7
  isGlobal?: boolean;
25
8
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"application.module-definition.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAE9C,KAKT,IAAI,kCAAyB,EAG7B;KACD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,SAAS,CACR,EAAE,QAAQ,EAAE,IAAI,EAAE,EAClB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,UAAU;IACb,MAAM,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK;CACjC,CAAC,CACH;KACA,KAAK,EAAE,EAhBR,+BAAuB,+BACD,uCAA+B,4BACrD,oBAAY,oBACZ,0BAAkB,yBAaT"}
1
+ {"version":3,"file":"application.module-definition.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAG9C,KAKT,IAAI,kCAAyB,EAAwC;KACtE,kBAAkB,CAAC,SAAS,CAAC;KAC7B,SAAS,CACR,EAAE,QAAQ,EAAE,IAAI,EAAE,EAClB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,UAAU;IACb,MAAM,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK;CACjC,CAAC,CACH;KACA,KAAK,EAAE,EAbR,+BAAuB,+BACD,uCAA+B,4BACrD,oBAAY,oBACZ,0BAAkB,yBAUT"}
@@ -1,27 +1,7 @@
1
- import { AuthService } from './services/auth.service';
2
- import { JwtAuthService } from './services/jwt-auth.service';
3
- import { BcryptHashService } from './services/bcrypt-hash.service';
4
- import { ConfigurableModuleClass, OPTIONS_TYPE } from './application.module-definition';
5
- import { HashService } from './services/hash.service';
6
- import { AuthConfig } from '../config';
7
- import { JwtStrategy } from './strategies/jwt/strategy';
8
- import { PoliciesService } from './services/policies.service';
9
- export declare class ApplicationModule extends ConfigurableModuleClass {
10
- private options;
11
- private authConfig;
12
- constructor(options: string | symbol, authConfig: AuthConfig);
13
- static forRoot(options: typeof OPTIONS_TYPE): {
14
- imports: import("@nestjs/common").DynamicModule[];
15
- providers: (typeof JwtAuthService | typeof BcryptHashService | typeof JwtStrategy | typeof PoliciesService | {
16
- provide: typeof HashService;
17
- useExisting: typeof BcryptHashService;
18
- } | {
19
- provide: typeof AuthService;
20
- useExisting: typeof JwtAuthService;
21
- })[];
22
- exports: (typeof AuthService | typeof HashService)[];
23
- module: import("@nestjs/common").Type<any>;
24
- global?: boolean;
25
- controllers?: import("@nestjs/common").Type<any>[];
26
- };
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { ConfigurableModuleClass } from './application.module-definition';
3
+ import type { AuthApplicationModuleOptions } from '../config';
4
+ export declare class AuthApplicationModule extends ConfigurableModuleClass {
5
+ static forRoot(options?: AuthApplicationModuleOptions): DynamicModule;
6
+ static forRootFromConfig(overrides?: AuthApplicationModuleOptions): DynamicModule;
27
7
  }
@@ -1,29 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApplicationModule = void 0;
3
+ exports.AuthApplicationModule = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@nestjs/common");
6
+ const config_1 = require("@nestjs/config");
7
+ const jwt_1 = require("@nestjs/jwt");
8
+ const config_2 = require("../config");
9
+ const application_module_definition_1 = require("./application.module-definition");
10
+ const ability_factory_1 = require("./factories/ability.factory");
6
11
  const auth_service_1 = require("./services/auth.service");
7
- const jwt_auth_service_1 = require("./services/jwt-auth.service");
8
12
  const bcrypt_hash_service_1 = require("./services/bcrypt-hash.service");
9
- const application_module_definition_1 = require("./application.module-definition");
10
13
  const hash_service_1 = require("./services/hash.service");
11
- const jwt_1 = require("@nestjs/jwt");
12
- const config_1 = require("../config");
13
- const strategy_1 = require("./strategies/jwt/strategy");
14
+ const jwt_auth_service_1 = require("./services/jwt-auth.service");
14
15
  const policies_service_1 = require("./services/policies.service");
15
- let ApplicationModule = class ApplicationModule extends application_module_definition_1.ConfigurableModuleClass {
16
- constructor(options, authConfig) {
17
- super();
18
- this.options = options;
19
- this.authConfig = authConfig;
20
- }
21
- static forRoot(options) {
22
- const { authStrategies, encryption } = options;
23
- const imports = [];
16
+ const strategy_1 = require("./strategies/jwt/strategy");
17
+ const infrastructure_persistence_1 = require("../infrastructure-persistence");
18
+ let AuthApplicationModule = class AuthApplicationModule extends application_module_definition_1.ConfigurableModuleClass {
19
+ static forRoot(options = {}) {
20
+ const resolvedOptions = (0, config_2.resolveAuthApplicationModuleOptions)(options);
21
+ const { authStrategies, encryption, persistence } = resolvedOptions;
22
+ const imports = [
23
+ config_1.ConfigModule.forFeature(config_2.authConfig),
24
+ infrastructure_persistence_1.AuthPersistenceModule.forRoot(persistence),
25
+ ];
24
26
  const providers = [];
25
27
  const exports = [];
26
- providers.push(policies_service_1.PoliciesService);
28
+ providers.push(ability_factory_1.AbilityFactory, policies_service_1.PoliciesService);
27
29
  switch (encryption.algorithm) {
28
30
  case 'bcrypt':
29
31
  providers.push(bcrypt_hash_service_1.BcryptHashService, {
@@ -40,6 +42,8 @@ let ApplicationModule = class ApplicationModule extends application_module_defin
40
42
  }
41
43
  if (authStrategies.includes('jwt')) {
42
44
  imports.push(jwt_1.JwtModule.registerAsync({
45
+ imports: [config_1.ConfigModule.forFeature(config_2.authConfig)],
46
+ inject: [config_2.authConfig.KEY],
43
47
  useFactory: (authConfig) => ({
44
48
  secret: authConfig.jwtSecret,
45
49
  signOptions: {
@@ -56,18 +60,37 @@ let ApplicationModule = class ApplicationModule extends application_module_defin
56
60
  exports.push(auth_service_1.AuthService);
57
61
  }
58
62
  return {
59
- ...super.forRoot(options),
63
+ ...super.forRoot(resolvedOptions),
60
64
  imports,
61
65
  providers,
62
66
  exports,
63
67
  };
64
68
  }
69
+ static forRootFromConfig(overrides = {}) {
70
+ const configOptions = (0, config_2.mapAuthConfigToApplicationModuleOptions)((0, config_2.authConfig)());
71
+ const moduleDefinition = this.forRoot({
72
+ ...configOptions,
73
+ ...overrides,
74
+ encryption: {
75
+ ...configOptions.encryption,
76
+ ...overrides.encryption,
77
+ },
78
+ persistence: {
79
+ ...configOptions.persistence,
80
+ ...overrides.persistence,
81
+ },
82
+ });
83
+ return {
84
+ ...moduleDefinition,
85
+ imports: [
86
+ config_1.ConfigModule.forFeature(config_2.authConfig),
87
+ ...(moduleDefinition.imports ?? []),
88
+ ],
89
+ };
90
+ }
65
91
  };
66
- exports.ApplicationModule = ApplicationModule;
67
- exports.ApplicationModule = ApplicationModule = tslib_1.__decorate([
68
- (0, common_1.Module)({}),
69
- tslib_1.__param(0, (0, common_1.Inject)(application_module_definition_1.AUTH_APPLICATION_MODULE_OPTIONS)),
70
- tslib_1.__param(1, (0, config_1.InjectAuthConfig)()),
71
- tslib_1.__metadata("design:paramtypes", [Object, Object])
72
- ], ApplicationModule);
92
+ exports.AuthApplicationModule = AuthApplicationModule;
93
+ exports.AuthApplicationModule = AuthApplicationModule = tslib_1.__decorate([
94
+ (0, common_1.Module)({})
95
+ ], AuthApplicationModule);
73
96
  //# sourceMappingURL=application.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"application.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module.ts"],"names":[],"mappings":";;;;AAAA,2CAAgD;AAChD,0DAAsD;AACtD,kEAA6D;AAC7D,wEAAmE;AACnE,mFAIyC;AACzC,0DAAsD;AACtD,qCAAwC;AACxC,sCAAyD;AACzD,wDAAwD;AACxD,kEAA8D;AAGvD,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,uDAAuB;IAC5D,YACmD,OAAwB,EAC7C,UAAsB;QAElD,KAAK,EAAE,CAAC;QAHyC,YAAO,GAAP,OAAO,CAAiB;QAC7C,eAAU,GAAV,UAAU,CAAY;IAGpD,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,OAA4B;QACzC,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAC/C,MAAM,OAAO,GAAG,EAAE,CAAC;QACnB,MAAM,SAAS,GAAG,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,EAAE,CAAC;QACnB,SAAS,CAAC,IAAI,CAAC,kCAAe,CAAC,CAAC;QAChC,QAAQ,UAAU,CAAC,SAAS,EAAE,CAAC;YAC7B,KAAK,QAAQ;gBACX,SAAS,CAAC,IAAI,CAAC,uCAAiB,EAAE;oBAChC,OAAO,EAAE,0BAAW;oBACpB,WAAW,EAAE,uCAAiB;i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BAAU,CAAC;gBACnC,GAAG,CAAC,gBAAgB,CAAC,OAAO,IAAI,EAAE,CAAC;aACpC;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAlFY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,qBAAqB,CAkFjC"}
@@ -6,3 +6,4 @@ export * from './services/bcrypt-hash.service';
6
6
  export * from './services/policies.service';
7
7
  export * from './strategies/jwt/strategy';
8
8
  export * from './factories/ability.factory';
9
+ export type { AuthApplicationModuleOptions } from '../config';
@@ -0,0 +1,7 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import type { AuthModuleOptions } from './config';
3
+ export type { AuthModuleFeatures, AuthModuleOptions } from './config';
4
+ export declare class AuthModule {
5
+ static forRoot(options?: AuthModuleOptions): DynamicModule;
6
+ static forRootFromConfig(overrides?: AuthModuleOptions): DynamicModule;
7
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var AuthModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.AuthModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const config_1 = require("@nestjs/config");
8
+ const infrastructure_mailer_1 = require("./infrastructure-mailer");
9
+ const presentation_1 = require("./presentation");
10
+ const config_2 = require("./config");
11
+ let AuthModule = AuthModule_1 = class AuthModule {
12
+ static forRoot(options = {}) {
13
+ const presentationModule = presentation_1.AuthPresentationModule.forRoot(options.presentation);
14
+ const mailerModule = infrastructure_mailer_1.AuthMailerModule.forRoot(options.mailer);
15
+ return {
16
+ module: AuthModule_1,
17
+ imports: [presentationModule, mailerModule],
18
+ exports: [presentationModule, mailerModule],
19
+ };
20
+ }
21
+ static forRootFromConfig(overrides = {}) {
22
+ const configOptions = (0, config_2.mapAuthConfigToAuthModuleOptions)((0, config_2.authConfig)());
23
+ const moduleDefinition = this.forRoot({
24
+ ...configOptions,
25
+ ...overrides,
26
+ presentation: {
27
+ ...configOptions.presentation,
28
+ ...overrides.presentation,
29
+ application: {
30
+ ...configOptions.presentation?.application,
31
+ ...overrides.presentation?.application,
32
+ encryption: {
33
+ ...configOptions.presentation?.application?.encryption,
34
+ ...overrides.presentation?.application?.encryption,
35
+ },
36
+ persistence: {
37
+ ...configOptions.presentation?.application?.persistence,
38
+ ...overrides.presentation?.application?.persistence,
39
+ },
40
+ },
41
+ },
42
+ mailer: {
43
+ ...configOptions.mailer,
44
+ ...overrides.mailer,
45
+ },
46
+ });
47
+ return {
48
+ ...moduleDefinition,
49
+ imports: [
50
+ config_1.ConfigModule.forFeature(config_2.authConfig),
51
+ ...(moduleDefinition.imports ?? []),
52
+ ],
53
+ };
54
+ }
55
+ };
56
+ exports.AuthModule = AuthModule;
57
+ exports.AuthModule = AuthModule = AuthModule_1 = tslib_1.__decorate([
58
+ (0, common_1.Module)({})
59
+ ], AuthModule);
60
+ //# sourceMappingURL=auth.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../../../../libs/auth/nest/src/auth.module.ts"],"names":[],"mappings":";;;;;AAAA,2CAAuD;AACvD,2CAA8C;AAC9C,mEAA2D;AAC3D,iDAAwD;AACxD,qCAAwE;AAMjE,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,OAAO,CAAC,UAA6B,EAAE;QAC5C,MAAM,kBAAkB,GAAG,qCAAsB,CAAC,OAAO,CACvD,OAAO,CAAC,YAAY,CACrB,CAAC;QACF,MAAM,YAAY,GAAG,wCAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC9D,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,OAAO,EAAE,CAAC,kBAAkB,EAAE,YAAY,CAAC;YAC3C,OAAO,EAAE,CAAC,kBAAkB,EAAE,YAAY,CAAC;SAC5C,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,YAA+B,EAAE;QACxD,MAAM,aAAa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