@anarchitects/auth-nest 0.0.1
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 +88 -0
- package/package.json +60 -0
- package/src/application/application.module-definition.d.ts +25 -0
- package/src/application/application.module-definition.js +13 -0
- package/src/application/application.module-definition.js.map +1 -0
- package/src/application/application.module.d.ts +27 -0
- package/src/application/application.module.js +73 -0
- package/src/application/application.module.js.map +1 -0
- package/src/application/factories/ability.factory.d.ts +6 -0
- package/src/application/factories/ability.factory.js +34 -0
- package/src/application/factories/ability.factory.js.map +1 -0
- package/src/application/index.d.ts +8 -0
- package/src/application/index.js +12 -0
- package/src/application/index.js.map +1 -0
- package/src/application/services/auth.service.d.ts +32 -0
- package/src/application/services/auth.service.js +12 -0
- package/src/application/services/auth.service.js.map +1 -0
- package/src/application/services/bcrypt-hash.service.d.ts +5 -0
- package/src/application/services/bcrypt-hash.service.js +20 -0
- package/src/application/services/bcrypt-hash.service.js.map +1 -0
- package/src/application/services/hash.service.d.ts +4 -0
- package/src/application/services/hash.service.js +12 -0
- package/src/application/services/hash.service.js.map +1 -0
- package/src/application/services/jwt-auth.service.d.ts +41 -0
- package/src/application/services/jwt-auth.service.js +220 -0
- package/src/application/services/jwt-auth.service.js.map +1 -0
- package/src/application/services/policies.service.d.ts +10 -0
- package/src/application/services/policies.service.js +42 -0
- package/src/application/services/policies.service.js.map +1 -0
- package/src/application/strategies/jwt/strategy.d.ts +16 -0
- package/src/application/strategies/jwt/strategy.js +25 -0
- package/src/application/strategies/jwt/strategy.js.map +1 -0
- package/src/config/auth.config.d.ts +18 -0
- package/src/config/auth.config.js +17 -0
- package/src/config/auth.config.js.map +1 -0
- package/src/config/index.d.ts +1 -0
- package/src/config/index.js +5 -0
- package/src/config/index.js.map +1 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +9 -0
- package/src/index.js.map +1 -0
- package/src/infrastructure-mailer/adapters/mailer.adapter.d.ts +4 -0
- package/src/infrastructure-mailer/adapters/mailer.adapter.js +7 -0
- package/src/infrastructure-mailer/adapters/mailer.adapter.js.map +1 -0
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.d.ts +8 -0
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.js +23 -0
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.js.map +1 -0
- package/src/infrastructure-mailer/index.d.ts +3 -0
- package/src/infrastructure-mailer/index.js +7 -0
- package/src/infrastructure-mailer/index.js.map +1 -0
- package/src/infrastructure-mailer/mailer.module.d.ts +2 -0
- package/src/infrastructure-mailer/mailer.module.js +23 -0
- package/src/infrastructure-mailer/mailer.module.js.map +1 -0
- package/src/infrastructure-persistence/entities/invalidated-token.entity.d.ts +7 -0
- package/src/infrastructure-persistence/entities/invalidated-token.entity.js +42 -0
- package/src/infrastructure-persistence/entities/invalidated-token.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/permission.entity.d.ts +17 -0
- package/src/infrastructure-persistence/entities/permission.entity.js +76 -0
- package/src/infrastructure-persistence/entities/permission.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/role.entity.d.ts +12 -0
- package/src/infrastructure-persistence/entities/role.entity.js +69 -0
- package/src/infrastructure-persistence/entities/role.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/user.entity.d.ts +14 -0
- package/src/infrastructure-persistence/entities/user.entity.js +77 -0
- package/src/infrastructure-persistence/entities/user.entity.js.map +1 -0
- package/src/infrastructure-persistence/index.d.ts +2 -0
- package/src/infrastructure-persistence/index.js +6 -0
- package/src/infrastructure-persistence/index.js.map +1 -0
- package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.d.ts +6 -0
- package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js +29 -0
- package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js.map +1 -0
- package/src/infrastructure-persistence/persistence.module-definition.d.ts +13 -0
- package/src/infrastructure-persistence/persistence.module-definition.js +13 -0
- package/src/infrastructure-persistence/persistence.module-definition.js.map +1 -0
- package/src/infrastructure-persistence/persistence.module.d.ts +7 -0
- package/src/infrastructure-persistence/persistence.module.js +52 -0
- package/src/infrastructure-persistence/persistence.module.js.map +1 -0
- package/src/infrastructure-persistence/repositories/auth-user.repository.d.ts +10 -0
- package/src/infrastructure-persistence/repositories/auth-user.repository.js +12 -0
- package/src/infrastructure-persistence/repositories/auth-user.repository.js.map +1 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.d.ts +17 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.js +62 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.js.map +1 -0
- package/src/infrastructure-persistence/schema.d.ts +1 -0
- package/src/infrastructure-persistence/schema.js +5 -0
- package/src/infrastructure-persistence/schema.js.map +1 -0
- package/src/presentation/controllers/auth.controller.d.ts +39 -0
- package/src/presentation/controllers/auth.controller.js +198 -0
- package/src/presentation/controllers/auth.controller.js.map +1 -0
- package/src/presentation/decorators/policies.decorator.d.ts +3 -0
- package/src/presentation/decorators/policies.decorator.js +8 -0
- package/src/presentation/decorators/policies.decorator.js.map +1 -0
- package/src/presentation/guards/policies.guard.d.ts +9 -0
- package/src/presentation/guards/policies.guard.js +38 -0
- package/src/presentation/guards/policies.guard.js.map +1 -0
- package/src/presentation/index.d.ts +4 -0
- package/src/presentation/index.js +8 -0
- package/src/presentation/index.js.map +1 -0
- package/src/presentation/presentation.module.d.ts +2 -0
- package/src/presentation/presentation.module.js +15 -0
- package/src/presentation/presentation.module.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @anarchitects/auth-nest
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
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.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @anarchitects/auth-nest
|
|
16
|
+
# or
|
|
17
|
+
yarn add @anarchitects/auth-nest
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Peer requirements:
|
|
21
|
+
|
|
22
|
+
- `@nestjs/common`, `@nestjs/core`, `@nestjs/jwt`, `@nestjs/typeorm`
|
|
23
|
+
- `@anarchitects/auth-ts` for DTOs and shared models
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### Importing modules
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
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';
|
|
34
|
+
|
|
35
|
+
@Module({
|
|
36
|
+
imports: [
|
|
37
|
+
JwtModule.register({
|
|
38
|
+
secret: process.env.JWT_SECRET,
|
|
39
|
+
signOptions: { expiresIn: '15m' },
|
|
40
|
+
}),
|
|
41
|
+
PersistenceModule.register({ persistence: 'typeorm' }),
|
|
42
|
+
PresentationModule,
|
|
43
|
+
],
|
|
44
|
+
})
|
|
45
|
+
export class AuthApiModule {}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Injecting services
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { Controller, Post, Body } from '@nestjs/common';
|
|
52
|
+
import { JwtAuthService } from '@anarchitects/auth-nest/application';
|
|
53
|
+
import { LoginRequestDTO } from '@anarchitects/auth-ts/dtos';
|
|
54
|
+
|
|
55
|
+
@Controller('auth')
|
|
56
|
+
export class AuthController {
|
|
57
|
+
constructor(private readonly authService: JwtAuthService) {}
|
|
58
|
+
|
|
59
|
+
@Post('login')
|
|
60
|
+
login(@Body() dto: LoginRequestDTO) {
|
|
61
|
+
return this.authService.login(dto);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Token invalidation
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { TypeormAuthUserRepository } from '@anarchitects/auth-nest/infrastructure-persistence';
|
|
70
|
+
|
|
71
|
+
await authUserRepository.invalidateTokens([hashedAccessToken, hashedRefreshToken], userId);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Nx scripts
|
|
75
|
+
|
|
76
|
+
- `nx build auth-nest` – bundle the Nest library.
|
|
77
|
+
- `nx test auth-nest` – execute Jest unit tests.
|
|
78
|
+
- `nx lint auth-nest` – run ESLint checks.
|
|
79
|
+
|
|
80
|
+
## Development notes
|
|
81
|
+
|
|
82
|
+
- DTO shapes live in `@anarchitects/auth-ts`; update the contract and regenerate DTOs before extending this library.
|
|
83
|
+
- Default persistence is TypeORM with schema-qualified tables (see `libs/auth/nest/src/infrastructure-persistence`).
|
|
84
|
+
- Invalidated tokens use an unlogged cache table for quick revocation lookups.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
Licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0). Unless required by applicable law or agreed to in writing, software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@anarchitects/auth-nest",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"tslib": "^2.3.0",
|
|
9
|
+
"@nestjs/common": "^11.0.0",
|
|
10
|
+
"@nestjs/jwt": "^11.0.1",
|
|
11
|
+
"@anarchitects/auth-ts": "0.0.1",
|
|
12
|
+
"bcrypt": "^6.0.0",
|
|
13
|
+
"@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
|
+
"@nestjs/platform-fastify": "^11.1.6",
|
|
21
|
+
"@casl/ability": "^6.7.3",
|
|
22
|
+
"@nestjs/core": "^11.0.0"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"typesVersions": {
|
|
28
|
+
"*": {
|
|
29
|
+
"application": [
|
|
30
|
+
"src/application/index.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"infrastructure-mailer": [
|
|
33
|
+
"src/infrastructure-mailer/index.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"infrastructure-persistence": [
|
|
36
|
+
"src/infrastructure-persistence/index.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"presentation": [
|
|
39
|
+
"src/presentation/index.d.ts"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
"./package.json": "./package.json",
|
|
45
|
+
".": {
|
|
46
|
+
"types": "./src/index.d.ts",
|
|
47
|
+
"default": "./src/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./application": "./src/application/index.js",
|
|
50
|
+
"./application/index": "./src/application/index.js",
|
|
51
|
+
"./infrastructure-mailer": "./src/infrastructure-mailer/index.js",
|
|
52
|
+
"./infrastructure-mailer/index": "./src/infrastructure-mailer/index.js",
|
|
53
|
+
"./infrastructure-persistence": "./src/infrastructure-persistence/index.js",
|
|
54
|
+
"./infrastructure-persistence/index": "./src/infrastructure-persistence/index.js",
|
|
55
|
+
"./presentation": "./src/presentation/index.js",
|
|
56
|
+
"./presentation/index": "./src/presentation/index.js",
|
|
57
|
+
"./config": "./src/config/index.js",
|
|
58
|
+
"./config/index": "./src/config/index.js"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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", {
|
|
8
|
+
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<{
|
|
16
|
+
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<{
|
|
24
|
+
isGlobal?: boolean;
|
|
25
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.AUTH_APPLICATION_MODULE_OPTIONS = exports.ConfigurableModuleClass = void 0;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
_a = new common_1.ConfigurableModuleBuilder()
|
|
7
|
+
.setClassMethodName('forRoot')
|
|
8
|
+
.setExtras({ isGlobal: true }, (definition, extras) => ({
|
|
9
|
+
...definition,
|
|
10
|
+
global: extras.isGlobal ?? false,
|
|
11
|
+
}))
|
|
12
|
+
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.AUTH_APPLICATION_MODULE_OPTIONS = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
13
|
+
//# sourceMappingURL=application.module-definition.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const auth_service_1 = require("./services/auth.service");
|
|
7
|
+
const jwt_auth_service_1 = require("./services/jwt-auth.service");
|
|
8
|
+
const bcrypt_hash_service_1 = require("./services/bcrypt-hash.service");
|
|
9
|
+
const application_module_definition_1 = require("./application.module-definition");
|
|
10
|
+
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 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 = [];
|
|
24
|
+
const providers = [];
|
|
25
|
+
const exports = [];
|
|
26
|
+
providers.push(policies_service_1.PoliciesService);
|
|
27
|
+
switch (encryption.algorithm) {
|
|
28
|
+
case 'bcrypt':
|
|
29
|
+
providers.push(bcrypt_hash_service_1.BcryptHashService, {
|
|
30
|
+
provide: hash_service_1.HashService,
|
|
31
|
+
useExisting: bcrypt_hash_service_1.BcryptHashService,
|
|
32
|
+
});
|
|
33
|
+
exports.push(hash_service_1.HashService);
|
|
34
|
+
break;
|
|
35
|
+
case 'argon2':
|
|
36
|
+
// Future implementation for Argon2HashService can be added here
|
|
37
|
+
throw new Error('Argon2HashService not implemented yet');
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Unsupported encryption algorithm: ${encryption.algorithm}`);
|
|
40
|
+
}
|
|
41
|
+
if (authStrategies.includes('jwt')) {
|
|
42
|
+
imports.push(jwt_1.JwtModule.registerAsync({
|
|
43
|
+
useFactory: (authConfig) => ({
|
|
44
|
+
secret: authConfig.jwtSecret,
|
|
45
|
+
signOptions: {
|
|
46
|
+
expiresIn: parseInt(authConfig.jwtExpiration, 10),
|
|
47
|
+
audience: authConfig.jwtAudience,
|
|
48
|
+
issuer: authConfig.jwtIssuer,
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
}));
|
|
52
|
+
providers.push(jwt_auth_service_1.JwtAuthService, strategy_1.JwtStrategy, {
|
|
53
|
+
provide: auth_service_1.AuthService,
|
|
54
|
+
useExisting: jwt_auth_service_1.JwtAuthService,
|
|
55
|
+
});
|
|
56
|
+
exports.push(auth_service_1.AuthService);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...super.forRoot(options),
|
|
60
|
+
imports,
|
|
61
|
+
providers,
|
|
62
|
+
exports,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
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);
|
|
73
|
+
//# sourceMappingURL=application.module.js.map
|
|
@@ -0,0 +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;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,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;AAxDY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,eAAM,EAAC,EAAE,CAAC;IAGN,mBAAA,IAAA,eAAM,EAAC,+DAA+B,CAAC,CAAA;IACvC,mBAAA,IAAA,yBAAgB,GAAE,CAAA;;GAHV,iBAAiB,CAwD7B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbilityFactory = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ability_1 = require("@casl/ability");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
let AbilityFactory = class AbilityFactory {
|
|
8
|
+
buildAbility(rules) {
|
|
9
|
+
const { can, cannot, build } = new ability_1.AbilityBuilder(ability_1.createMongoAbility);
|
|
10
|
+
for (const rule of rules) {
|
|
11
|
+
const args = [rule.action, rule.subject];
|
|
12
|
+
if (rule.conditions) {
|
|
13
|
+
args.push(rule.conditions);
|
|
14
|
+
}
|
|
15
|
+
if (rule.fields?.length) {
|
|
16
|
+
args.push({ fields: rule.fields });
|
|
17
|
+
}
|
|
18
|
+
if (rule.inverted) {
|
|
19
|
+
cannot(...args);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
can(...args);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return build({
|
|
26
|
+
detectSubjectType: (obj) => obj.__caslSubjectType__ ?? obj?.constructor?.name ?? 'all',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.AbilityFactory = AbilityFactory;
|
|
31
|
+
exports.AbilityFactory = AbilityFactory = tslib_1.__decorate([
|
|
32
|
+
(0, common_1.Injectable)()
|
|
33
|
+
], AbilityFactory);
|
|
34
|
+
//# sourceMappingURL=ability.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ability.factory.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/factories/ability.factory.ts"],"names":[],"mappings":";;;;AAEA,2CAIuB;AACvB,2CAA4C;AAIrC,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAAY,CAAC,KAAmB;QAC9B,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,wBAAc,CAC/C,4BAAkB,CACnB,CAAC;QACF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,GAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAChD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC7B,CAAC;YACD,IAAI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;gBACxB,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YACrC,CAAC;YACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACjB,MAAc,CAAC,GAAG,IAAI,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACL,GAAW,CAAC,GAAG,IAAI,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;YACX,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE,CACxB,GAAW,CAAC,mBAAmB,IAAI,GAAG,EAAE,WAAW,EAAE,IAAI,IAAI,KAAK;SACtE,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAxBY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAwB1B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './application.module';
|
|
2
|
+
export * from './services/auth.service';
|
|
3
|
+
export * from './services/jwt-auth.service';
|
|
4
|
+
export * from './services/hash.service';
|
|
5
|
+
export * from './services/bcrypt-hash.service';
|
|
6
|
+
export * from './services/policies.service';
|
|
7
|
+
export * from './strategies/jwt/strategy';
|
|
8
|
+
export * from './factories/ability.factory';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./application.module"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./services/auth.service"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./services/jwt-auth.service"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./services/hash.service"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./services/bcrypt-hash.service"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./services/policies.service"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./strategies/jwt/strategy"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./factories/ability.factory"), exports);
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/application/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,kEAAwC;AACxC,sEAA4C;AAC5C,kEAAwC;AACxC,yEAA+C;AAC/C,sEAA4C;AAC5C,oEAA0C;AAC1C,sEAA4C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PolicyRule, User } from '@anarchitects/auth-ts';
|
|
2
|
+
import { ActivateUserRequestDTO, ChangePasswordRequestDTO, ForgotPasswordRequestDTO, LoginRequestDTO, LoginResponseDTO, LogoutRequestDTO, RefreshTokenRequestDTO, RegisterRequestDTO, RegisterResponseDTO, ResetPasswordRequestDTO, UpdateEmailRequestDTO, VerifyEmailRequestDTO } from '@anarchitects/auth-ts/dtos';
|
|
3
|
+
export declare abstract class AuthService {
|
|
4
|
+
abstract registerUser(dto: RegisterRequestDTO): Promise<RegisterResponseDTO>;
|
|
5
|
+
abstract activateUser(dto: ActivateUserRequestDTO): Promise<{
|
|
6
|
+
success: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
abstract login(dto: LoginRequestDTO): Promise<LoginResponseDTO>;
|
|
9
|
+
abstract logout(dto: LogoutRequestDTO): Promise<{
|
|
10
|
+
success: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
abstract changePassword(userId: string, dto: ChangePasswordRequestDTO): Promise<{
|
|
13
|
+
success: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
abstract forgotPassword(dto: ForgotPasswordRequestDTO): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
abstract resetPassword(dto: ResetPasswordRequestDTO): Promise<{
|
|
19
|
+
success: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
abstract verifyEmail(dto: VerifyEmailRequestDTO): Promise<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
abstract updateEmail(userId: string, dto: UpdateEmailRequestDTO): Promise<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
abstract refreshTokens(userId: string, dto: RefreshTokenRequestDTO): Promise<LoginResponseDTO>;
|
|
28
|
+
abstract getLoggedInUserInfo(userId: string): Promise<{
|
|
29
|
+
user: User;
|
|
30
|
+
rbac: PolicyRule[];
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
let AuthService = class AuthService {
|
|
7
|
+
};
|
|
8
|
+
exports.AuthService = AuthService;
|
|
9
|
+
exports.AuthService = AuthService = tslib_1.__decorate([
|
|
10
|
+
(0, common_1.Injectable)()
|
|
11
|
+
], AuthService);
|
|
12
|
+
//# sourceMappingURL=auth.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/services/auth.service.ts"],"names":[],"mappings":";;;;AAeA,2CAA4C;AAGrC,IAAe,WAAW,GAA1B,MAAe,WAAW;CA+BhC,CAAA;AA/BqB,kCAAW;sBAAX,WAAW;IADhC,IAAA,mBAAU,GAAE;GACS,WAAW,CA+BhC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BcryptHashService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const bcrypt_1 = require("bcrypt");
|
|
7
|
+
let BcryptHashService = class BcryptHashService {
|
|
8
|
+
async hash(value) {
|
|
9
|
+
const salt = await (0, bcrypt_1.genSalt)();
|
|
10
|
+
return (0, bcrypt_1.hash)(value, salt);
|
|
11
|
+
}
|
|
12
|
+
compare(value, hash) {
|
|
13
|
+
return (0, bcrypt_1.compare)(value, hash);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.BcryptHashService = BcryptHashService;
|
|
17
|
+
exports.BcryptHashService = BcryptHashService = tslib_1.__decorate([
|
|
18
|
+
(0, common_1.Injectable)()
|
|
19
|
+
], BcryptHashService);
|
|
20
|
+
//# sourceMappingURL=bcrypt-hash.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bcrypt-hash.service.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/services/bcrypt-hash.service.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAE5C,mCAAgD;AAGzC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,KAAK,CAAC,IAAI,CAAC,KAAsB;QAC/B,MAAM,IAAI,GAAG,MAAM,IAAA,gBAAO,GAAE,CAAC;QAC7B,OAAO,IAAA,aAAI,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,CAAC,KAAsB,EAAE,IAAY;QAC1C,OAAO,IAAA,gBAAO,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;CACF,CAAA;AARY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;GACA,iBAAiB,CAQ7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HashService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
let HashService = class HashService {
|
|
7
|
+
};
|
|
8
|
+
exports.HashService = HashService;
|
|
9
|
+
exports.HashService = HashService = tslib_1.__decorate([
|
|
10
|
+
(0, common_1.Injectable)()
|
|
11
|
+
], HashService);
|
|
12
|
+
//# sourceMappingURL=hash.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.service.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/services/hash.service.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAGrC,IAAe,WAAW,GAA1B,MAAe,WAAW;CAGhC,CAAA;AAHqB,kCAAW;sBAAX,WAAW;IADhC,IAAA,mBAAU,GAAE;GACS,WAAW,CAGhC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ActivateUserRequestDTO, ChangePasswordRequestDTO, ForgotPasswordRequestDTO, LoginRequestDTO, LoginResponseDTO, LogoutRequestDTO, RefreshTokenRequestDTO, RegisterRequestDTO, RegisterResponseDTO, ResetPasswordRequestDTO, UpdateEmailRequestDTO, VerifyEmailRequestDTO } from '@anarchitects/auth-ts/dtos';
|
|
2
|
+
import { PolicyRule, User } from '@anarchitects/auth-ts/models';
|
|
3
|
+
import { JwtService } from '@nestjs/jwt';
|
|
4
|
+
import { AuthUserRepository } from '../../infrastructure-persistence/repositories/auth-user.repository';
|
|
5
|
+
import { AuthService } from './auth.service';
|
|
6
|
+
import { HashService } from './hash.service';
|
|
7
|
+
export declare class JwtAuthService implements AuthService {
|
|
8
|
+
private readonly hashService;
|
|
9
|
+
private readonly authUserRepository;
|
|
10
|
+
private readonly jwtService;
|
|
11
|
+
constructor(hashService: HashService, authUserRepository: AuthUserRepository, jwtService: JwtService);
|
|
12
|
+
registerUser(dto: RegisterRequestDTO): Promise<RegisterResponseDTO>;
|
|
13
|
+
activateUser(dto: ActivateUserRequestDTO): Promise<{
|
|
14
|
+
success: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
login(dto: LoginRequestDTO): Promise<LoginResponseDTO>;
|
|
17
|
+
logout(dto: LogoutRequestDTO): Promise<{
|
|
18
|
+
success: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
changePassword(userId: string, dto: ChangePasswordRequestDTO): Promise<{
|
|
21
|
+
success: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
forgotPassword(dto: ForgotPasswordRequestDTO): Promise<{
|
|
24
|
+
success: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
resetPassword(dto: ResetPasswordRequestDTO): Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
}>;
|
|
29
|
+
verifyEmail(dto: VerifyEmailRequestDTO): Promise<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
}>;
|
|
32
|
+
updateEmail(userId: string, dto: UpdateEmailRequestDTO): Promise<{
|
|
33
|
+
success: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
refreshTokens(userId: string, dto: RefreshTokenRequestDTO): Promise<LoginResponseDTO>;
|
|
36
|
+
getLoggedInUserInfo(userId: string): Promise<{
|
|
37
|
+
user: User;
|
|
38
|
+
rbac: PolicyRule[];
|
|
39
|
+
}>;
|
|
40
|
+
private generateTokens;
|
|
41
|
+
}
|