@anarchitects/auth-nest 0.0.1 → 0.4.2
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.
- package/README.md +181 -16
- package/package.json +7 -4
- package/src/application/application.module.d.ts +6 -9
- package/src/application/application.module.js +17 -21
- package/src/application/application.module.js.map +1 -1
- package/src/auth.module.d.ts +14 -0
- package/src/auth.module.js +44 -0
- package/src/auth.module.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.d.ts +1 -8
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.js +2 -19
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.js.map +1 -1
- package/src/infrastructure-mailer/index.d.ts +0 -1
- package/src/infrastructure-mailer/index.js +0 -1
- package/src/infrastructure-mailer/index.js.map +1 -1
- package/src/infrastructure-mailer/mailer.module.d.ts +1 -1
- package/src/infrastructure-mailer/mailer.module.js +9 -15
- package/src/infrastructure-mailer/mailer.module.js.map +1 -1
- package/src/infrastructure-persistence/index.d.ts +1 -0
- package/src/infrastructure-persistence/index.js +1 -0
- package/src/infrastructure-persistence/index.js.map +1 -1
- package/src/infrastructure-persistence/migrations/{1720200000000-create-invalidated-tokens-cache.table.d.ts → 1720200000000-create-auth-schema.d.ts} +1 -1
- package/src/infrastructure-persistence/migrations/1720200000000-create-auth-schema.js +312 -0
- package/src/infrastructure-persistence/migrations/1720200000000-create-auth-schema.js.map +1 -0
- package/src/infrastructure-persistence/persistence.module.d.ts +1 -3
- package/src/infrastructure-persistence/persistence.module.js +12 -18
- package/src/infrastructure-persistence/persistence.module.js.map +1 -1
- package/src/presentation/controllers/auth.controller.d.ts +9 -27
- package/src/presentation/controllers/auth.controller.js +18 -30
- package/src/presentation/controllers/auth.controller.js.map +1 -1
- package/src/presentation/presentation.module.d.ts +1 -1
- package/src/presentation/presentation.module.js +5 -5
- package/src/presentation/presentation.module.js.map +1 -1
- package/src/infrastructure-mailer/adapters/mailer.adapter.d.ts +0 -4
- package/src/infrastructure-mailer/adapters/mailer.adapter.js +0 -7
- package/src/infrastructure-mailer/adapters/mailer.adapter.js.map +0 -1
- package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js +0 -29
- package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,47 +4,175 @@ NestJS services, controllers, and infrastructure for the Anarchitecture authenti
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- Application layer
|
|
8
|
-
- Presentation
|
|
9
|
-
- Infrastructure persistence
|
|
10
|
-
-
|
|
7
|
+
- **Application layer** – `JwtAuthService`, `BcryptHashService`, JWT Passport strategy, CASL-based `PoliciesService` and `AbilityFactory` encapsulating business rules for tokens, passwords, and fine-grained access control.
|
|
8
|
+
- **Presentation layer** – `AuthController` exposing REST handlers for the full auth lifecycle, `PoliciesGuard` and `@Policies()` decorator for route-level authorization.
|
|
9
|
+
- **Infrastructure persistence** – `PersistenceModule` with TypeORM entities and repositories (users, roles, permissions, invalidated tokens). Configurable adapters to swap implementations while preserving the application contract.
|
|
10
|
+
- **Infrastructure mailer** – `AuthMailerModule` wrapper over shared `CommonNodeMailerModule`; `NodeMailerAdapter` is re-exported for compatibility.
|
|
11
|
+
- **Config** – Typed `authConfig` namespace using `@nestjs/config` with an `InjectAuthConfig()` helper decorator.
|
|
11
12
|
|
|
12
13
|
## Installation
|
|
13
14
|
|
|
14
15
|
```bash
|
|
15
|
-
npm install @anarchitects/auth-nest
|
|
16
|
+
npm install @anarchitects/auth-nest @anarchitects/common-nest-mailer
|
|
16
17
|
# or
|
|
17
|
-
yarn add @anarchitects/auth-nest
|
|
18
|
+
yarn add @anarchitects/auth-nest @anarchitects/common-nest-mailer
|
|
18
19
|
```
|
|
19
20
|
|
|
20
21
|
Peer requirements:
|
|
21
22
|
|
|
22
|
-
- `@nestjs/common`, `@nestjs/core`, `@nestjs/jwt`, `@nestjs/typeorm`
|
|
23
|
+
- `@nestjs/common`, `@nestjs/core`, `@nestjs/jwt`, `@nestjs/typeorm`, `@nestjs/config`, `@nestjs/passport`
|
|
23
24
|
- `@anarchitects/auth-ts` for DTOs and shared models
|
|
25
|
+
- `@casl/ability` for RBAC policy evaluation
|
|
26
|
+
- `@nestjs-modules/mailer` (when using the mailer module)
|
|
27
|
+
|
|
28
|
+
## Exports
|
|
29
|
+
|
|
30
|
+
| Import path | Contents |
|
|
31
|
+
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
32
|
+
| `@anarchitects/auth-nest` | `AuthModule.forRoot(...)`, plus re-exports of layered entry points for convenience |
|
|
33
|
+
| `@anarchitects/auth-nest/application` | `AuthApplicationModule`, `AuthService`, `JwtAuthService`, `HashService`, `BcryptHashService`, `PoliciesService`, `AbilityFactory`, `JwtStrategy` |
|
|
34
|
+
| `@anarchitects/auth-nest/presentation` | `AuthPresentationModule`, `AuthController`, `PoliciesGuard`, `@Policies()` decorator |
|
|
35
|
+
| `@anarchitects/auth-nest/infrastructure-persistence` | `AuthPersistenceModule`, `AuthUserRepository`, `TypeormAuthUserRepository`, migration |
|
|
36
|
+
| `@anarchitects/auth-nest/infrastructure-mailer` | `AuthMailerModule`, `NodeMailerAdapter` |
|
|
37
|
+
| `@anarchitects/auth-nest/config` | `authConfig`, `AuthConfig` type, `InjectAuthConfig()` |
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
The library reads configuration through `@nestjs/config` using a namespaced `authConfig` registered under the key `auth`. Set the following environment variables to customise behaviour:
|
|
42
|
+
|
|
43
|
+
| Variable | Description | Default |
|
|
44
|
+
| --------------------------- | ------------------------------------------------------------------------------------ | ------------------------ |
|
|
45
|
+
| `AUTH_JWT_SECRET` | Secret key used to sign and verify JWTs. **Must** be overridden in production. | `default_jwt_secret` |
|
|
46
|
+
| `AUTH_JWT_EXPIRATION` | Token lifetime (e.g. `3600s`, `15m`, `1d`). | `3600s` |
|
|
47
|
+
| `AUTH_JWT_AUDIENCE` | Expected `aud` claim in the JWT. | `your_audience` |
|
|
48
|
+
| `AUTH_JWT_ISSUER` | Expected `iss` claim in the JWT. | `your_issuer` |
|
|
49
|
+
| `AUTH_ENCRYPTION_ALGORITHM` | Password hashing algorithm (`bcrypt`). | `bcrypt` |
|
|
50
|
+
| `AUTH_ENCRYPTION_KEY` | Symmetric key for additional encryption needs. **Must** be overridden in production. | `default_encryption_key` |
|
|
51
|
+
|
|
52
|
+
> **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.
|
|
53
|
+
|
|
54
|
+
### Injecting the config
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { InjectAuthConfig, AuthConfig } from '@anarchitects/auth-nest/config';
|
|
58
|
+
|
|
59
|
+
@Injectable()
|
|
60
|
+
export class MyService {
|
|
61
|
+
constructor(@InjectAuthConfig() private readonly config: AuthConfig) {}
|
|
62
|
+
|
|
63
|
+
someMethod() {
|
|
64
|
+
const secret = this.config.jwtSecret;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Make sure to import `authConfig` into your module's `ConfigModule`:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { ConfigModule } from '@nestjs/config';
|
|
73
|
+
import { authConfig } from '@anarchitects/auth-nest/config';
|
|
74
|
+
|
|
75
|
+
@Module({
|
|
76
|
+
imports: [ConfigModule.forRoot({ load: [authConfig] })],
|
|
77
|
+
})
|
|
78
|
+
export class AppModule {}
|
|
79
|
+
```
|
|
24
80
|
|
|
25
81
|
## Usage
|
|
26
82
|
|
|
27
|
-
###
|
|
83
|
+
### Easy mode (single facade import)
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { Module } from '@nestjs/common';
|
|
87
|
+
import { ConfigModule } from '@nestjs/config';
|
|
88
|
+
import { CommonMailerModule, mailerConfig } from '@anarchitects/common-nest-mailer';
|
|
89
|
+
import { AuthModule } from '@anarchitects/auth-nest';
|
|
90
|
+
import { authConfig } from '@anarchitects/auth-nest/config';
|
|
91
|
+
|
|
92
|
+
@Module({
|
|
93
|
+
imports: [
|
|
94
|
+
ConfigModule.forRoot({
|
|
95
|
+
isGlobal: true,
|
|
96
|
+
load: [authConfig, mailerConfig],
|
|
97
|
+
}),
|
|
98
|
+
CommonMailerModule.forRootFromConfig(),
|
|
99
|
+
AuthModule.forRoot({
|
|
100
|
+
application: {
|
|
101
|
+
authStrategies: ['jwt'],
|
|
102
|
+
encryption: {
|
|
103
|
+
algorithm: 'bcrypt',
|
|
104
|
+
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
persistence: {
|
|
108
|
+
persistence: 'typeorm',
|
|
109
|
+
},
|
|
110
|
+
features: {
|
|
111
|
+
mailer: true,
|
|
112
|
+
},
|
|
113
|
+
}),
|
|
114
|
+
],
|
|
115
|
+
})
|
|
116
|
+
export class AuthApiModule {}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`AuthModule.forRoot(...)` is the preferred integration path when you want a full auth stack with minimal host-module wiring.
|
|
120
|
+
|
|
121
|
+
Disable domain mailer wiring when not needed:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
AuthModule.forRoot({
|
|
125
|
+
application: { ... },
|
|
126
|
+
persistence: { persistence: 'typeorm' },
|
|
127
|
+
features: { mailer: false },
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Layered composition (advanced)
|
|
28
132
|
|
|
29
133
|
```ts
|
|
30
134
|
import { Module } from '@nestjs/common';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
135
|
+
import { ConfigModule } from '@nestjs/config';
|
|
136
|
+
import { CommonMailerModule, mailerConfig } from '@anarchitects/common-nest-mailer';
|
|
137
|
+
import { authConfig } from '@anarchitects/auth-nest/config';
|
|
138
|
+
import { AuthApplicationModule } from '@anarchitects/auth-nest/application';
|
|
139
|
+
import { AuthPersistenceModule } from '@anarchitects/auth-nest/infrastructure-persistence';
|
|
140
|
+
import { AuthPresentationModule } from '@anarchitects/auth-nest/presentation';
|
|
141
|
+
import { AuthMailerModule } from '@anarchitects/auth-nest/infrastructure-mailer';
|
|
34
142
|
|
|
35
143
|
@Module({
|
|
36
144
|
imports: [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
145
|
+
ConfigModule.forRoot({
|
|
146
|
+
isGlobal: true,
|
|
147
|
+
load: [authConfig, mailerConfig],
|
|
40
148
|
}),
|
|
41
|
-
|
|
42
|
-
|
|
149
|
+
CommonMailerModule.forRootFromConfig(),
|
|
150
|
+
AuthApplicationModule.forRoot({
|
|
151
|
+
authStrategies: ['jwt'],
|
|
152
|
+
encryption: {
|
|
153
|
+
algorithm: 'bcrypt',
|
|
154
|
+
key: process.env.AUTH_ENCRYPTION_KEY!,
|
|
155
|
+
},
|
|
156
|
+
}),
|
|
157
|
+
AuthPersistenceModule.forRoot({ persistence: 'typeorm' }),
|
|
158
|
+
AuthPresentationModule,
|
|
159
|
+
AuthMailerModule,
|
|
43
160
|
],
|
|
44
161
|
})
|
|
45
162
|
export class AuthApiModule {}
|
|
46
163
|
```
|
|
47
164
|
|
|
165
|
+
Use layered composition when you need to replace or selectively compose infrastructure/application concerns.
|
|
166
|
+
|
|
167
|
+
## Mailer Migration Note
|
|
168
|
+
|
|
169
|
+
`AuthMailerModule` is now adapter-only. It wraps the shared `CommonNodeMailerModule` from
|
|
170
|
+
`@anarchitects/common-nest-mailer` and no longer configures transport with
|
|
171
|
+
`MailerModule.forRootAsync(...)`.
|
|
172
|
+
Configure transport once at app root with `CommonMailerModule` when `features.mailer` is enabled.
|
|
173
|
+
The shared mailer DI contract (`MailerPort`) and concrete `NodeMailerAdapter` now live in
|
|
174
|
+
`@anarchitects/common-nest-mailer`.
|
|
175
|
+
|
|
48
176
|
### Injecting services
|
|
49
177
|
|
|
50
178
|
```ts
|
|
@@ -71,6 +199,41 @@ import { TypeormAuthUserRepository } from '@anarchitects/auth-nest/infrastructur
|
|
|
71
199
|
await authUserRepository.invalidateTokens([hashedAccessToken, hashedRefreshToken], userId);
|
|
72
200
|
```
|
|
73
201
|
|
|
202
|
+
### Route-level authorization with policies
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import { Controller, Get, UseGuards } from '@nestjs/common';
|
|
206
|
+
import { PoliciesGuard, Policies } from '@anarchitects/auth-nest/presentation';
|
|
207
|
+
|
|
208
|
+
@Controller('admin')
|
|
209
|
+
@UseGuards(PoliciesGuard)
|
|
210
|
+
export class AdminController {
|
|
211
|
+
@Get()
|
|
212
|
+
@Policies({ action: 'manage', subject: 'User' })
|
|
213
|
+
getAdminDashboard() {
|
|
214
|
+
return { status: 'ok' };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## REST endpoints
|
|
220
|
+
|
|
221
|
+
The `AuthController` exposes the following routes (all prefixed with `/auth`):
|
|
222
|
+
|
|
223
|
+
| Method | Path | Description |
|
|
224
|
+
| ------- | ------------------------------- | -------------------------------------- |
|
|
225
|
+
| `POST` | `/auth/register` | Register a new user |
|
|
226
|
+
| `PATCH` | `/auth/activate` | Activate a user account |
|
|
227
|
+
| `POST` | `/auth/login` | Log in and receive JWT tokens |
|
|
228
|
+
| `POST` | `/auth/logout` | Log out and invalidate tokens |
|
|
229
|
+
| `PATCH` | `/auth/change-password/:userId` | Change password for a user |
|
|
230
|
+
| `POST` | `/auth/forgot-password` | Request a password-reset email |
|
|
231
|
+
| `POST` | `/auth/reset-password` | Reset password with token |
|
|
232
|
+
| `POST` | `/auth/verify-email` | Verify an email address |
|
|
233
|
+
| `PATCH` | `/auth/update-email/:userId` | Update email for a user |
|
|
234
|
+
| `POST` | `/auth/refresh-tokens/:userId` | Refresh access/refresh tokens |
|
|
235
|
+
| `GET` | `/auth/me` | Get logged-in user info and RBAC rules |
|
|
236
|
+
|
|
74
237
|
## Nx scripts
|
|
75
238
|
|
|
76
239
|
- `nx build auth-nest` – bundle the Nest library.
|
|
@@ -82,6 +245,8 @@ await authUserRepository.invalidateTokens([hashedAccessToken, hashedRefreshToken
|
|
|
82
245
|
- DTO shapes live in `@anarchitects/auth-ts`; update the contract and regenerate DTOs before extending this library.
|
|
83
246
|
- Default persistence is TypeORM with schema-qualified tables (see `libs/auth/nest/src/infrastructure-persistence`).
|
|
84
247
|
- Invalidated tokens use an unlogged cache table for quick revocation lookups.
|
|
248
|
+
- Route schemas are defined in `@anarchitects/auth-ts/dtos` and imported into controller `@RouteSchema` decorators — do not define inline schemas.
|
|
249
|
+
- OpenAPI metadata (`operationId`, `tags`) is assigned in `tools/api-specs/route-metadata.ts`, not in controllers.
|
|
85
250
|
|
|
86
251
|
## License
|
|
87
252
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anarchitects/auth-nest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"tslib": "^2.3.0",
|
|
9
9
|
"@nestjs/common": "^11.0.0",
|
|
10
10
|
"@nestjs/jwt": "^11.0.1",
|
|
11
|
-
"@anarchitects/auth-ts": "0.
|
|
11
|
+
"@anarchitects/auth-ts": "0.1.4",
|
|
12
12
|
"bcrypt": "^6.0.0",
|
|
13
13
|
"@nestjs/passport": "^11.0.5",
|
|
14
14
|
"passport-jwt": "^4.0.1",
|
|
15
15
|
"@nestjs/config": "^4.0.2",
|
|
16
|
-
"@nestjs-modules/mailer": "^2.0.2",
|
|
17
16
|
"typeorm": "^0.3.27",
|
|
18
17
|
"uuidv7": "^1.0.2",
|
|
19
18
|
"@nestjs/typeorm": "^11.0.0",
|
|
20
19
|
"@nestjs/platform-fastify": "^11.1.6",
|
|
21
20
|
"@casl/ability": "^6.7.3",
|
|
22
|
-
"@nestjs/core": "^11.0.0"
|
|
21
|
+
"@nestjs/core": "^11.0.0",
|
|
22
|
+
"@anarchitects/common-nest-mailer": "0.0.10"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
],
|
|
38
38
|
"presentation": [
|
|
39
39
|
"src/presentation/index.d.ts"
|
|
40
|
+
],
|
|
41
|
+
"config": [
|
|
42
|
+
"src/config/index.d.ts"
|
|
40
43
|
]
|
|
41
44
|
}
|
|
42
45
|
},
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
+
import { ConfigurableModuleClass, OPTIONS_TYPE } from './application.module-definition';
|
|
2
|
+
import { AbilityFactory } from './factories/ability.factory';
|
|
1
3
|
import { AuthService } from './services/auth.service';
|
|
2
|
-
import { JwtAuthService } from './services/jwt-auth.service';
|
|
3
4
|
import { BcryptHashService } from './services/bcrypt-hash.service';
|
|
4
|
-
import { ConfigurableModuleClass, OPTIONS_TYPE } from './application.module-definition';
|
|
5
5
|
import { HashService } from './services/hash.service';
|
|
6
|
-
import {
|
|
7
|
-
import { JwtStrategy } from './strategies/jwt/strategy';
|
|
6
|
+
import { JwtAuthService } from './services/jwt-auth.service';
|
|
8
7
|
import { PoliciesService } from './services/policies.service';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
private authConfig;
|
|
12
|
-
constructor(options: string | symbol, authConfig: AuthConfig);
|
|
8
|
+
import { JwtStrategy } from './strategies/jwt/strategy';
|
|
9
|
+
export declare class AuthApplicationModule extends ConfigurableModuleClass {
|
|
13
10
|
static forRoot(options: typeof OPTIONS_TYPE): {
|
|
14
11
|
imports: import("@nestjs/common").DynamicModule[];
|
|
15
|
-
providers: (typeof
|
|
12
|
+
providers: (typeof AbilityFactory | typeof BcryptHashService | typeof JwtAuthService | typeof PoliciesService | typeof JwtStrategy | {
|
|
16
13
|
provide: typeof HashService;
|
|
17
14
|
useExisting: typeof BcryptHashService;
|
|
18
15
|
} | {
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
super();
|
|
18
|
-
this.options = options;
|
|
19
|
-
this.authConfig = authConfig;
|
|
20
|
-
}
|
|
16
|
+
const strategy_1 = require("./strategies/jwt/strategy");
|
|
17
|
+
let AuthApplicationModule = class AuthApplicationModule extends application_module_definition_1.ConfigurableModuleClass {
|
|
21
18
|
static forRoot(options) {
|
|
22
19
|
const { authStrategies, encryption } = options;
|
|
23
|
-
const imports = [];
|
|
20
|
+
const imports = [config_1.ConfigModule.forFeature(config_2.authConfig)];
|
|
24
21
|
const providers = [];
|
|
25
22
|
const exports = [];
|
|
26
|
-
providers.push(policies_service_1.PoliciesService);
|
|
23
|
+
providers.push(ability_factory_1.AbilityFactory, policies_service_1.PoliciesService);
|
|
27
24
|
switch (encryption.algorithm) {
|
|
28
25
|
case 'bcrypt':
|
|
29
26
|
providers.push(bcrypt_hash_service_1.BcryptHashService, {
|
|
@@ -40,6 +37,8 @@ let ApplicationModule = class ApplicationModule extends application_module_defin
|
|
|
40
37
|
}
|
|
41
38
|
if (authStrategies.includes('jwt')) {
|
|
42
39
|
imports.push(jwt_1.JwtModule.registerAsync({
|
|
40
|
+
imports: [config_1.ConfigModule.forFeature(config_2.authConfig)],
|
|
41
|
+
inject: [config_2.authConfig.KEY],
|
|
43
42
|
useFactory: (authConfig) => ({
|
|
44
43
|
secret: authConfig.jwtSecret,
|
|
45
44
|
signOptions: {
|
|
@@ -63,11 +62,8 @@ let ApplicationModule = class ApplicationModule extends application_module_defin
|
|
|
63
62
|
};
|
|
64
63
|
}
|
|
65
64
|
};
|
|
66
|
-
exports.
|
|
67
|
-
exports.
|
|
68
|
-
(0, common_1.Module)({})
|
|
69
|
-
|
|
70
|
-
tslib_1.__param(1, (0, config_1.InjectAuthConfig)()),
|
|
71
|
-
tslib_1.__metadata("design:paramtypes", [Object, Object])
|
|
72
|
-
], ApplicationModule);
|
|
65
|
+
exports.AuthApplicationModule = AuthApplicationModule;
|
|
66
|
+
exports.AuthApplicationModule = AuthApplicationModule = tslib_1.__decorate([
|
|
67
|
+
(0, common_1.Module)({})
|
|
68
|
+
], AuthApplicationModule);
|
|
73
69
|
//# 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,
|
|
1
|
+
{"version":3,"file":"application.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/application.module.ts"],"names":[],"mappings":";;;;AAAA,2CAAwC;AACxC,2CAA8C;AAC9C,qCAAwC;AACxC,sCAAmD;AACnD,mFAGyC;AACzC,iEAA6D;AAC7D,0DAAsD;AACtD,wEAAmE;AACnE,0DAAsD;AACtD,kEAA6D;AAC7D,kEAA8D;AAC9D,wDAAwD;AAGjD,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,uDAAuB;IAChE,MAAM,CAAC,OAAO,CAAC,OAA4B;QACzC,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAC/C,MAAM,OAAO,GAAG,CAAC,qBAAY,CAAC,UAAU,CAAC,mBAAU,CAAC,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,EAAE,CAAC;QACnB,SAAS,CAAC,IAAI,CAAC,gCAAc,EAAE,kCAAe,CAAC,CAAC;QAChD,QAAQ,UAAU,CAAC,SAAS,EAAE,CAAC;YAC7B,KAAK,QAAQ;gBACX,SAAS,CAAC,IAAI,CAAC,uCAAiB,EAAE;oBAChC,OAAO,EAAE,0BAAW;oBACpB,WAAW,EAAE,uCAAiB;iBAC/B,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,0BAAW,CAAC,CAAC;gBAC1B,MAAM;YACR,KAAK,QAAQ;gBACX,gEAAgE;gBAChE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D;gBACE,MAAM,IAAI,KAAK,CACb,qCAAqC,UAAU,CAAC,SAAS,EAAE,CAC5D,CAAC;QACN,CAAC;QACD,IAAI,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO,CAAC,IAAI,CACV,eAAS,CAAC,aAAa,CAAC;gBACtB,OAAO,EAAE,CAAC,qBAAY,CAAC,UAAU,CAAC,mBAAU,CAAC,CAAC;gBAC9C,MAAM,EAAE,CAAC,mBAAU,CAAC,GAAG,CAAC;gBACxB,UAAU,EAAE,CAAC,UAAsB,EAAE,EAAE,CAAC,CAAC;oBACvC,MAAM,EAAE,UAAU,CAAC,SAAS;oBAC5B,WAAW,EAAE;wBACX,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,aAAa,EAAE,EAAE,CAAC;wBACjD,QAAQ,EAAE,UAAU,CAAC,WAAW;wBAChC,MAAM,EAAE,UAAU,CAAC,SAAS;qBAC7B;iBACF,CAAC;aACH,CAAC,CACH,CAAC;YACF,SAAS,CAAC,IAAI,CAAC,iCAAc,EAAE,sBAAW,EAAE;gBAC1C,OAAO,EAAE,0BAAW;gBACpB,WAAW,EAAE,iCAAc;aAC5B,CAAC,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,0BAAW,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO;YACL,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;YACzB,OAAO;YACP,SAAS;YACT,OAAO;SACR,CAAC;IACJ,CAAC;CACF,CAAA;AAnDY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,qBAAqB,CAmDjC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { AuthApplicationModule } from './application';
|
|
3
|
+
import { AuthPersistenceModule } from './infrastructure-persistence';
|
|
4
|
+
export type AuthModuleFeatures = {
|
|
5
|
+
mailer?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type AuthModuleOptions = {
|
|
8
|
+
application: Parameters<typeof AuthApplicationModule.forRoot>[0];
|
|
9
|
+
persistence: Parameters<typeof AuthPersistenceModule.forRoot>[0];
|
|
10
|
+
features?: AuthModuleFeatures;
|
|
11
|
+
};
|
|
12
|
+
export declare class AuthModule {
|
|
13
|
+
static forRoot(options: AuthModuleOptions): DynamicModule;
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 application_1 = require("./application");
|
|
9
|
+
const config_2 = require("./config");
|
|
10
|
+
const infrastructure_mailer_1 = require("./infrastructure-mailer");
|
|
11
|
+
const infrastructure_persistence_1 = require("./infrastructure-persistence");
|
|
12
|
+
const presentation_1 = require("./presentation");
|
|
13
|
+
let AuthModule = AuthModule_1 = class AuthModule {
|
|
14
|
+
static forRoot(options) {
|
|
15
|
+
const mailerEnabled = options.features?.mailer ?? true;
|
|
16
|
+
const applicationModule = application_1.AuthApplicationModule.forRoot(options.application);
|
|
17
|
+
const persistenceModule = infrastructure_persistence_1.AuthPersistenceModule.forRoot(options.persistence);
|
|
18
|
+
const imports = [
|
|
19
|
+
config_1.ConfigModule.forFeature(config_2.authConfig),
|
|
20
|
+
applicationModule,
|
|
21
|
+
persistenceModule,
|
|
22
|
+
presentation_1.AuthPresentationModule,
|
|
23
|
+
];
|
|
24
|
+
const exports = [
|
|
25
|
+
applicationModule,
|
|
26
|
+
persistenceModule,
|
|
27
|
+
presentation_1.AuthPresentationModule,
|
|
28
|
+
];
|
|
29
|
+
if (mailerEnabled) {
|
|
30
|
+
imports.push(infrastructure_mailer_1.AuthMailerModule);
|
|
31
|
+
exports.push(infrastructure_mailer_1.AuthMailerModule);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
module: AuthModule_1,
|
|
35
|
+
imports,
|
|
36
|
+
exports,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.AuthModule = AuthModule;
|
|
41
|
+
exports.AuthModule = AuthModule = AuthModule_1 = tslib_1.__decorate([
|
|
42
|
+
(0, common_1.Module)({})
|
|
43
|
+
], AuthModule);
|
|
44
|
+
//# 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,+CAAsD;AACtD,qCAAsC;AACtC,mEAA2D;AAC3D,6EAAqE;AACrE,iDAAwD;AAajD,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CAAC,OAAO,CAAC,OAA0B;QACvC,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE,MAAM,IAAI,IAAI,CAAC;QACvD,MAAM,iBAAiB,GAAG,mCAAqB,CAAC,OAAO,CACrD,OAAO,CAAC,WAAW,CACpB,CAAC;QACF,MAAM,iBAAiB,GAAG,kDAAqB,CAAC,OAAO,CACrD,OAAO,CAAC,WAAW,CACpB,CAAC;QACF,MAAM,OAAO,GAAG;YACd,qBAAY,CAAC,UAAU,CAAC,mBAAU,CAAC;YACnC,iBAAiB;YACjB,iBAAiB;YACjB,qCAAsB;SACvB,CAAC;QACF,MAAM,OAAO,GAAG;YACd,iBAAiB;YACjB,iBAAiB;YACjB,qCAAsB;SACvB,CAAC;QAEF,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,wCAAgB,CAAC,CAAC;YAC/B,OAAO,CAAC,IAAI,CAAC,wCAAgB,CAAC,CAAC;QACjC,CAAC;QAED,OAAO;YACL,MAAM,EAAE,YAAU;YAClB,OAAO;YACP,OAAO;SACR,CAAC;IACJ,CAAC;CACF,CAAA;AAhCY,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,UAAU,CAgCtB"}
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./auth.module"), exports);
|
|
4
5
|
tslib_1.__exportStar(require("./application"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./presentation"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./infrastructure-persistence"), exports);
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/auth/nest/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,yDAA+B;AAC/B,uEAA6C;AAC7C,kEAAwC;AACxC,mDAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/auth/nest/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,wDAA8B;AAC9B,yDAA+B;AAC/B,uEAA6C;AAC7C,kEAAwC;AACxC,mDAAyB"}
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { MailerAdapter } from './mailer.adapter';
|
|
3
|
-
export declare class NodeMailerAdapter implements MailerAdapter {
|
|
4
|
-
private readonly mailer;
|
|
5
|
-
constructor(mailer: MailerService);
|
|
6
|
-
send(to: string, subject: string, html: string): Promise<SentMessageInfo>;
|
|
7
|
-
sendTemplate(to: string, subject: string, template: string, context?: Record<string, unknown>): Promise<SentMessageInfo>;
|
|
8
|
-
}
|
|
1
|
+
export { NodeMailerAdapter } from '@anarchitects/common-nest-mailer';
|
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeMailerAdapter = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const mailer_1 = require("@nestjs-modules/mailer");
|
|
7
|
-
let NodeMailerAdapter = class NodeMailerAdapter {
|
|
8
|
-
constructor(mailer) {
|
|
9
|
-
this.mailer = mailer;
|
|
10
|
-
}
|
|
11
|
-
async send(to, subject, html) {
|
|
12
|
-
return await this.mailer.sendMail({ to, subject, html });
|
|
13
|
-
}
|
|
14
|
-
async sendTemplate(to, subject, template, context) {
|
|
15
|
-
return await this.mailer.sendMail({ to, subject, template, context });
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
exports.NodeMailerAdapter = NodeMailerAdapter;
|
|
19
|
-
exports.NodeMailerAdapter = NodeMailerAdapter = tslib_1.__decorate([
|
|
20
|
-
(0, common_1.Injectable)(),
|
|
21
|
-
tslib_1.__metadata("design:paramtypes", [mailer_1.MailerService])
|
|
22
|
-
], NodeMailerAdapter);
|
|
4
|
+
var common_nest_mailer_1 = require("@anarchitects/common-nest-mailer");
|
|
5
|
+
Object.defineProperty(exports, "NodeMailerAdapter", { enumerable: true, get: function () { return common_nest_mailer_1.NodeMailerAdapter; } });
|
|
23
6
|
//# sourceMappingURL=node-mailer.adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-mailer.adapter.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-mailer/adapters/node-mailer.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-mailer.adapter.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-mailer/adapters/node-mailer.adapter.ts"],"names":[],"mappings":";;;AAAA,uEAAqE;AAA5D,uHAAA,iBAAiB,OAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./adapters/mailer.adapter"), exports);
|
|
5
4
|
tslib_1.__exportStar(require("./adapters/node-mailer.adapter"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./mailer.module"), exports);
|
|
7
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-mailer/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-mailer/index.ts"],"names":[],"mappings":";;;AAAA,yEAA+C;AAC/C,0DAAgC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare class
|
|
1
|
+
export declare class AuthMailerModule {
|
|
2
2
|
}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AuthMailerModule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
let MailerModule = class MailerModule {
|
|
6
|
+
const common_nest_mailer_1 = require("@anarchitects/common-nest-mailer");
|
|
7
|
+
let AuthMailerModule = class AuthMailerModule {
|
|
9
8
|
};
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
9
|
+
exports.AuthMailerModule = AuthMailerModule;
|
|
10
|
+
exports.AuthMailerModule = AuthMailerModule = tslib_1.__decorate([
|
|
11
|
+
(0, common_1.Global)(),
|
|
12
12
|
(0, common_1.Module)({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
provide: mailer_adapter_1.MailerAdapter,
|
|
17
|
-
useExisting: node_mailer_adapter_1.NodeMailerAdapter,
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
exports: [mailer_adapter_1.MailerAdapter],
|
|
13
|
+
imports: [common_nest_mailer_1.CommonNodeMailerModule],
|
|
14
|
+
exports: [common_nest_mailer_1.CommonNodeMailerModule],
|
|
21
15
|
})
|
|
22
|
-
],
|
|
16
|
+
], AuthMailerModule);
|
|
23
17
|
//# sourceMappingURL=mailer.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mailer.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-mailer/mailer.module.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"mailer.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-mailer/mailer.module.ts"],"names":[],"mappings":";;;;AAAA,2CAAgD;AAChD,yEAA0E;AAOnE,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAL5B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,2CAAsB,CAAC;QACjC,OAAO,EAAE,CAAC,2CAAsB,CAAC;KAClC,CAAC;GACW,gBAAgB,CAAG"}
|
|
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./persistence.module"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./repositories/auth-user.repository"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./migrations/1720200000000-create-auth-schema"), exports);
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-persistence/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,8EAAoD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-persistence/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,8EAAoD;AACpD,wFAA8D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class CreateAuthSchema1720200000000 implements MigrationInterface {
|
|
3
3
|
name: string;
|
|
4
4
|
up(queryRunner: QueryRunner): Promise<void>;
|
|
5
5
|
down(queryRunner: QueryRunner): Promise<void>;
|