cca-auth-module 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 +0 -0
- package/dist/application/dtos/LoginDTO.d.ts +7 -0
- package/dist/application/dtos/RegisterDTO.d.ts +8 -0
- package/dist/application/dtos/UserDTO.d.ts +8 -0
- package/dist/application/mappers/createUserMappings.d.ts +2 -0
- package/dist/application/mappers/utils/mapper.d.ts +1 -0
- package/dist/application/useCase/LoginUseCase.d.ts +20 -0
- package/dist/application/useCase/RefreshTokenUseCase.d.ts +15 -0
- package/dist/application/useCase/RegisterUseCase.d.ts +13 -0
- package/dist/application/validators/authValidation.d.ts +10 -0
- package/dist/domain/interfaces/IAuthService.d.ts +9 -0
- package/dist/domain/interfaces/IBaseContainerConfig.d.ts +9 -0
- package/dist/domain/interfaces/IConfigFinderOptions.d.ts +5 -0
- package/dist/domain/interfaces/IDecodedToken.d.ts +6 -0
- package/dist/domain/interfaces/IJwtAuth.d.ts +9 -0
- package/dist/domain/interfaces/IJwtConfig.d.ts +6 -0
- package/dist/domain/interfaces/IRefreshTokenRequest.d.ts +3 -0
- package/dist/domain/interfaces/IResponse.d.ts +4 -0
- package/dist/domain/interfaces/ITokenConfig.d.ts +6 -0
- package/dist/index.d.mts +118 -0
- package/dist/index.d.ts +118 -0
- package/dist/index.js +569 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +535 -0
- package/dist/index.mjs.map +1 -0
- package/dist/infrastructure/auth/JwtAuthService.d.ts +19 -0
- package/dist/infrastructure/container/createAuthContainer.d.ts +7 -0
- package/dist/infrastructure/repository/AuthRepository.d.ts +8 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/presentation/controller/AuthController.d.ts +15 -0
- package/dist/utils/ConfigFinder.d.ts +9 -0
- package/dist/utils/Errors.d.ts +21 -0
- package/package.json +38 -0
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mapper: import("@automapper/core").Mapper;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IBaseService } from "cca-core";
|
|
2
|
+
import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
|
|
3
|
+
import { JwtAuthService } from "../../infrastructure/auth/JwtAuthService";
|
|
4
|
+
import { UserDTO } from "../dtos/UserDTO";
|
|
5
|
+
import { LoginDTO } from "../dtos/LoginDTO";
|
|
6
|
+
export declare class LoginUseCase implements IBaseService {
|
|
7
|
+
private readonly repository;
|
|
8
|
+
private readonly authService;
|
|
9
|
+
constructor(repository: AuthRepository, authService: JwtAuthService);
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
execute(loginDTO: LoginDTO, adminPassword?: string): Promise<{
|
|
12
|
+
token: {
|
|
13
|
+
accessToken: string;
|
|
14
|
+
refreshToken: string;
|
|
15
|
+
};
|
|
16
|
+
user: UserDTO;
|
|
17
|
+
}>;
|
|
18
|
+
private generateTokens;
|
|
19
|
+
private updateUserRefreshToken;
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IBaseService } from "cca-core";
|
|
2
|
+
import { IDecodedToken } from "../../domain/interfaces/IDecodedToken";
|
|
3
|
+
import { JwtAuthService } from "../../infrastructure/auth/JwtAuthService";
|
|
4
|
+
import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
|
|
5
|
+
export declare class RefreshTokenUseCase implements IBaseService {
|
|
6
|
+
private readonly repository;
|
|
7
|
+
private readonly service;
|
|
8
|
+
constructor(repository: AuthRepository, service: JwtAuthService);
|
|
9
|
+
initialize(): Promise<void>;
|
|
10
|
+
execute(refreshToken: string): Promise<{
|
|
11
|
+
accessToken: string;
|
|
12
|
+
refreshToken: string;
|
|
13
|
+
} | null>;
|
|
14
|
+
verityToken(token: string): Promise<IDecodedToken>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IBaseService } from "cca-core";
|
|
2
|
+
import { AuthEntity, UserRole } from "cca-entities";
|
|
3
|
+
import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
|
|
4
|
+
export declare class RegisterUseCase implements IBaseService {
|
|
5
|
+
private readonly repository;
|
|
6
|
+
private readonly SALT_ROUNDS;
|
|
7
|
+
constructor(repository: AuthRepository);
|
|
8
|
+
initialize(): Promise<void>;
|
|
9
|
+
execute(email: string, name: string, password: string, role?: UserRole): Promise<AuthEntity>;
|
|
10
|
+
private normalizeAuthDTO;
|
|
11
|
+
private hashPassword;
|
|
12
|
+
private createAuthEntity;
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthEntity } from "cca-entities";
|
|
2
|
+
import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
|
|
3
|
+
import { RegisterDTO } from "../dtos/RegisterDTO";
|
|
4
|
+
import { LoginDTO } from "../dtos/LoginDTO";
|
|
5
|
+
export declare const validateEmail: (email: string, repository: AuthRepository) => Promise<AuthEntity>;
|
|
6
|
+
export declare const validatePassword: (password?: string) => Promise<void>;
|
|
7
|
+
export declare const validateEmailUniqueness: (repository: AuthRepository, email: string, excludeUserId?: string) => Promise<void>;
|
|
8
|
+
export declare const validateRegisterDTO: (auth: RegisterDTO, repository: AuthRepository) => Promise<void>;
|
|
9
|
+
export declare const validateLoginDTO: (data: LoginDTO, repository: AuthRepository) => Promise<AuthEntity>;
|
|
10
|
+
export declare const validateAdminSecret: (secretPassword?: string) => Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthEntity, UserEntity } from "cca-entities";
|
|
2
|
+
import { IDecodedToken } from "./IDecodedToken";
|
|
3
|
+
export interface IAuthService {
|
|
4
|
+
validateUser(email: string, password: string): Promise<AuthEntity | null>;
|
|
5
|
+
generateAccessToken(user: UserEntity): string;
|
|
6
|
+
generateRefreshToken(user: UserEntity): string;
|
|
7
|
+
verifyAccessToken(token: string): Promise<IDecodedToken>;
|
|
8
|
+
verifyRefreshToken(token: string): IDecodedToken;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseDatabase } from 'cca-core';
|
|
2
|
+
import { IBaseCacheService } from 'cca-core';
|
|
3
|
+
import { Mapper } from '@automapper/core';
|
|
4
|
+
export interface IBaseContainerConfig {
|
|
5
|
+
database: BaseDatabase;
|
|
6
|
+
cacheService?: IBaseCacheService;
|
|
7
|
+
mapper?: Mapper;
|
|
8
|
+
jwtSecret: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthEntity, UserEntity } from "cca-entities";
|
|
2
|
+
import { IDecodedToken } from "./IDecodedToken";
|
|
3
|
+
export interface IJwtAuth {
|
|
4
|
+
validateUser(email: string, password: string): Promise<AuthEntity | null>;
|
|
5
|
+
generateAccessToken(user: UserEntity): string;
|
|
6
|
+
generateRefreshToken(user: UserEntity): string;
|
|
7
|
+
verifyAccessToken(token: string): Promise<IDecodedToken>;
|
|
8
|
+
verifyRefreshToken(token: string): IDecodedToken;
|
|
9
|
+
}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { BaseRepository, IExtendedBaseRepository, IBaseService, BaseDatabase, BaseContainer } from 'cca-core';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import { AuthEntity, UserRole, UserEntity } from 'cca-entities';
|
|
4
|
+
import { Repository } from 'typeorm';
|
|
5
|
+
import { JwtPayload } from 'jsonwebtoken';
|
|
6
|
+
|
|
7
|
+
declare class AuthRepository extends BaseRepository<AuthEntity> implements IExtendedBaseRepository<AuthEntity> {
|
|
8
|
+
constructor(repository: Repository<AuthEntity>);
|
|
9
|
+
findByEmail(email: string): Promise<AuthEntity | null>;
|
|
10
|
+
create(entity: Omit<AuthEntity, "createdAt">): Promise<AuthEntity>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class RegisterUseCase implements IBaseService {
|
|
14
|
+
private readonly repository;
|
|
15
|
+
private readonly SALT_ROUNDS;
|
|
16
|
+
constructor(repository: AuthRepository);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
execute(email: string, name: string, password: string, role?: UserRole): Promise<AuthEntity>;
|
|
19
|
+
private normalizeAuthDTO;
|
|
20
|
+
private hashPassword;
|
|
21
|
+
private createAuthEntity;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface IJwtConfig {
|
|
25
|
+
accessTokenSecret: string;
|
|
26
|
+
refreshTokenSecret: string;
|
|
27
|
+
accessTokenExpiry: string;
|
|
28
|
+
refreshTokenExpiry: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface IDecodedToken extends JwtPayload {
|
|
32
|
+
userId?: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
role?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface IAuthService {
|
|
38
|
+
validateUser(email: string, password: string): Promise<AuthEntity | null>;
|
|
39
|
+
generateAccessToken(user: UserEntity): string;
|
|
40
|
+
generateRefreshToken(user: UserEntity): string;
|
|
41
|
+
verifyAccessToken(token: string): Promise<IDecodedToken>;
|
|
42
|
+
verifyRefreshToken(token: string): IDecodedToken;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class JwtAuthService implements IBaseService, IAuthService {
|
|
46
|
+
private readonly jwtConfig;
|
|
47
|
+
private readonly repository;
|
|
48
|
+
constructor(repository: AuthRepository, config?: IJwtConfig);
|
|
49
|
+
initialize(): Promise<void>;
|
|
50
|
+
private validateConfiguration;
|
|
51
|
+
validateUser(email: string, password: string): Promise<AuthEntity | null>;
|
|
52
|
+
generateAccessToken(user: UserEntity): string;
|
|
53
|
+
generateRefreshToken(user: UserEntity): string;
|
|
54
|
+
verifyAccessToken(token: string): Promise<IDecodedToken>;
|
|
55
|
+
verifyRefreshToken(token: string): Promise<IDecodedToken>;
|
|
56
|
+
private verifyToken;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class UserDTO {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
email: string;
|
|
63
|
+
role: UserRole;
|
|
64
|
+
adminPassword?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare class LoginDTO {
|
|
68
|
+
email: string;
|
|
69
|
+
password: string;
|
|
70
|
+
adminPassword?: string;
|
|
71
|
+
role: UserRole;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare class LoginUseCase implements IBaseService {
|
|
75
|
+
private readonly repository;
|
|
76
|
+
private readonly authService;
|
|
77
|
+
constructor(repository: AuthRepository, authService: JwtAuthService);
|
|
78
|
+
initialize(): Promise<void>;
|
|
79
|
+
execute(loginDTO: LoginDTO, adminPassword?: string): Promise<{
|
|
80
|
+
token: {
|
|
81
|
+
accessToken: string;
|
|
82
|
+
refreshToken: string;
|
|
83
|
+
};
|
|
84
|
+
user: UserDTO;
|
|
85
|
+
}>;
|
|
86
|
+
private generateTokens;
|
|
87
|
+
private updateUserRefreshToken;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare class RefreshTokenUseCase implements IBaseService {
|
|
91
|
+
private readonly repository;
|
|
92
|
+
private readonly service;
|
|
93
|
+
constructor(repository: AuthRepository, service: JwtAuthService);
|
|
94
|
+
initialize(): Promise<void>;
|
|
95
|
+
execute(refreshToken: string): Promise<{
|
|
96
|
+
accessToken: string;
|
|
97
|
+
refreshToken: string;
|
|
98
|
+
} | null>;
|
|
99
|
+
verityToken(token: string): Promise<IDecodedToken>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare class AuthController {
|
|
103
|
+
private loginUseCase;
|
|
104
|
+
private registerUseCase;
|
|
105
|
+
private refreshTokenUseCase;
|
|
106
|
+
constructor(loginUseCase: LoginUseCase, registerUseCase: RegisterUseCase, refreshTokenUseCase: RefreshTokenUseCase);
|
|
107
|
+
login: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
108
|
+
register: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
109
|
+
refreshToken: (req: Request, res: Response) => Promise<void>;
|
|
110
|
+
verifyToken: (token: string) => Promise<IDecodedToken>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare function createAuthContainer(database: BaseDatabase): {
|
|
114
|
+
container: BaseContainer;
|
|
115
|
+
authController: AuthController;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export { createAuthContainer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { BaseRepository, IExtendedBaseRepository, IBaseService, BaseDatabase, BaseContainer } from 'cca-core';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import { AuthEntity, UserRole, UserEntity } from 'cca-entities';
|
|
4
|
+
import { Repository } from 'typeorm';
|
|
5
|
+
import { JwtPayload } from 'jsonwebtoken';
|
|
6
|
+
|
|
7
|
+
declare class AuthRepository extends BaseRepository<AuthEntity> implements IExtendedBaseRepository<AuthEntity> {
|
|
8
|
+
constructor(repository: Repository<AuthEntity>);
|
|
9
|
+
findByEmail(email: string): Promise<AuthEntity | null>;
|
|
10
|
+
create(entity: Omit<AuthEntity, "createdAt">): Promise<AuthEntity>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare class RegisterUseCase implements IBaseService {
|
|
14
|
+
private readonly repository;
|
|
15
|
+
private readonly SALT_ROUNDS;
|
|
16
|
+
constructor(repository: AuthRepository);
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
execute(email: string, name: string, password: string, role?: UserRole): Promise<AuthEntity>;
|
|
19
|
+
private normalizeAuthDTO;
|
|
20
|
+
private hashPassword;
|
|
21
|
+
private createAuthEntity;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface IJwtConfig {
|
|
25
|
+
accessTokenSecret: string;
|
|
26
|
+
refreshTokenSecret: string;
|
|
27
|
+
accessTokenExpiry: string;
|
|
28
|
+
refreshTokenExpiry: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface IDecodedToken extends JwtPayload {
|
|
32
|
+
userId?: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
role?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface IAuthService {
|
|
38
|
+
validateUser(email: string, password: string): Promise<AuthEntity | null>;
|
|
39
|
+
generateAccessToken(user: UserEntity): string;
|
|
40
|
+
generateRefreshToken(user: UserEntity): string;
|
|
41
|
+
verifyAccessToken(token: string): Promise<IDecodedToken>;
|
|
42
|
+
verifyRefreshToken(token: string): IDecodedToken;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class JwtAuthService implements IBaseService, IAuthService {
|
|
46
|
+
private readonly jwtConfig;
|
|
47
|
+
private readonly repository;
|
|
48
|
+
constructor(repository: AuthRepository, config?: IJwtConfig);
|
|
49
|
+
initialize(): Promise<void>;
|
|
50
|
+
private validateConfiguration;
|
|
51
|
+
validateUser(email: string, password: string): Promise<AuthEntity | null>;
|
|
52
|
+
generateAccessToken(user: UserEntity): string;
|
|
53
|
+
generateRefreshToken(user: UserEntity): string;
|
|
54
|
+
verifyAccessToken(token: string): Promise<IDecodedToken>;
|
|
55
|
+
verifyRefreshToken(token: string): Promise<IDecodedToken>;
|
|
56
|
+
private verifyToken;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class UserDTO {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
email: string;
|
|
63
|
+
role: UserRole;
|
|
64
|
+
adminPassword?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare class LoginDTO {
|
|
68
|
+
email: string;
|
|
69
|
+
password: string;
|
|
70
|
+
adminPassword?: string;
|
|
71
|
+
role: UserRole;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare class LoginUseCase implements IBaseService {
|
|
75
|
+
private readonly repository;
|
|
76
|
+
private readonly authService;
|
|
77
|
+
constructor(repository: AuthRepository, authService: JwtAuthService);
|
|
78
|
+
initialize(): Promise<void>;
|
|
79
|
+
execute(loginDTO: LoginDTO, adminPassword?: string): Promise<{
|
|
80
|
+
token: {
|
|
81
|
+
accessToken: string;
|
|
82
|
+
refreshToken: string;
|
|
83
|
+
};
|
|
84
|
+
user: UserDTO;
|
|
85
|
+
}>;
|
|
86
|
+
private generateTokens;
|
|
87
|
+
private updateUserRefreshToken;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
declare class RefreshTokenUseCase implements IBaseService {
|
|
91
|
+
private readonly repository;
|
|
92
|
+
private readonly service;
|
|
93
|
+
constructor(repository: AuthRepository, service: JwtAuthService);
|
|
94
|
+
initialize(): Promise<void>;
|
|
95
|
+
execute(refreshToken: string): Promise<{
|
|
96
|
+
accessToken: string;
|
|
97
|
+
refreshToken: string;
|
|
98
|
+
} | null>;
|
|
99
|
+
verityToken(token: string): Promise<IDecodedToken>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
declare class AuthController {
|
|
103
|
+
private loginUseCase;
|
|
104
|
+
private registerUseCase;
|
|
105
|
+
private refreshTokenUseCase;
|
|
106
|
+
constructor(loginUseCase: LoginUseCase, registerUseCase: RegisterUseCase, refreshTokenUseCase: RefreshTokenUseCase);
|
|
107
|
+
login: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
108
|
+
register: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
109
|
+
refreshToken: (req: Request, res: Response) => Promise<void>;
|
|
110
|
+
verifyToken: (token: string) => Promise<IDecodedToken>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare function createAuthContainer(database: BaseDatabase): {
|
|
114
|
+
container: BaseContainer;
|
|
115
|
+
authController: AuthController;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export { createAuthContainer };
|