cca-auth-module 0.1.54 → 0.1.56

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.
@@ -1,27 +1,10 @@
1
1
  import { IBaseService } from "cca-core";
2
2
  import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
3
- import { JwtAuthService } from "../../infrastructure/services/JwtAuthService";
4
- import { UserDTO } from "../dtos/UserDTO";
5
3
  import { LoginDTO } from "../dtos/LoginDTO";
6
- interface TokenPair {
7
- accessToken: string;
8
- refreshToken: string;
9
- }
10
- interface LoginResponse {
11
- token: TokenPair;
12
- user: UserDTO;
13
- }
14
4
  export declare class LoginAdminUseCase implements IBaseService {
15
5
  private readonly repository;
16
- private readonly authService;
17
- constructor(repository: AuthRepository, authService: JwtAuthService);
6
+ constructor(repository: AuthRepository);
18
7
  initialize(): Promise<void>;
19
- execute(loginDTO: LoginDTO, adminPassword: string): Promise<LoginResponse>;
8
+ execute(loginDTO: LoginDTO, adminPassword: string): Promise<string>;
20
9
  private validateLogin;
21
- private handleAuthentication;
22
- private generateTokens;
23
- private updateUserStatus;
24
- private updateUserRefreshToken;
25
- private mapUserToDTO;
26
10
  }
27
- export {};
@@ -1,27 +1,10 @@
1
1
  import { IBaseService } from "cca-core";
2
2
  import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
3
- import { JwtAuthService } from "../../infrastructure/services/JwtAuthService";
4
- import { UserDTO } from "../dtos/UserDTO";
5
3
  import { LoginDTO } from "../dtos/LoginDTO";
6
- interface TokenPair {
7
- accessToken: string;
8
- refreshToken: string;
9
- }
10
- interface LoginResponse {
11
- token: TokenPair;
12
- user: UserDTO;
13
- }
14
4
  export declare class LoginUseCase implements IBaseService {
15
5
  private readonly repository;
16
- private readonly authService;
17
- constructor(repository: AuthRepository, authService: JwtAuthService);
6
+ constructor(repository: AuthRepository);
18
7
  initialize(): Promise<void>;
19
- execute(loginDTO: LoginDTO): Promise<LoginResponse>;
8
+ execute(loginDTO: LoginDTO): Promise<string>;
20
9
  private validateLogin;
21
- private handleAuthentication;
22
- private generateTokens;
23
- private updateUserStatus;
24
- private updateUserRefreshToken;
25
- private mapUserToDTO;
26
10
  }
27
- export {};
@@ -1,15 +1,11 @@
1
1
  import { IBaseService } from "cca-core";
2
- import { IDecodedToken } from "../../domain/interfaces/IDecodedToken";
3
2
  import { JwtAuthService } from "../../infrastructure/services/JwtAuthService";
4
3
  import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
4
+ import { TokenPair } from "../../domain/interfaces/TokenPair";
5
5
  export declare class RefreshTokenUseCase implements IBaseService {
6
6
  private readonly repository;
7
7
  private readonly service;
8
8
  constructor(repository: AuthRepository, service: JwtAuthService);
9
9
  initialize(): Promise<void>;
10
- execute(refreshToken: string): Promise<{
11
- accessToken: string;
12
- refreshToken: string;
13
- } | null>;
14
- verityToken(token: string): Promise<IDecodedToken>;
10
+ execute(refreshToken: string): Promise<TokenPair | null>;
15
11
  }
@@ -3,15 +3,23 @@ import { TwoFactorService } from '../../infrastructure/services/TwoFactorService
3
3
  import { AuthRepository } from '../../infrastructure/repository/AuthRepository';
4
4
  import { JwtAuthService } from '../../infrastructure/services/JwtAuthService';
5
5
  import { ITwoFactorVerify } from '../../domain/interfaces/ITwoFactorVerify';
6
+ import { AdminDTO } from '../dtos/AdminDTO';
7
+ import { UserDTO } from '../dtos/UserDTO';
6
8
  export declare class TwoFactorVerifyUseCase implements IBaseService {
7
- private twoFactorService;
8
- private authRepository;
9
- private jwtService;
9
+ private readonly twoFactorService;
10
+ private readonly authRepository;
11
+ private readonly jwtService;
10
12
  private isInitialized;
11
13
  constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository, jwtService: JwtAuthService);
12
14
  initialize(): Promise<void>;
13
15
  execute(dto: ITwoFactorVerify): Promise<{
14
16
  token: string;
15
17
  refreshToken: string;
16
- }>;
18
+ data?: AdminDTO | UserDTO;
19
+ } | null>;
20
+ private mapAdminToDTO;
21
+ private mapUserToDTO;
22
+ private updateUserStatus;
23
+ private updateUserRefreshToken;
24
+ private generateTokens;
17
25
  }
@@ -0,0 +1,4 @@
1
+ export interface TokenPair {
2
+ accessToken: string;
3
+ refreshToken: string;
4
+ }
package/dist/index.d.mts CHANGED
@@ -24,6 +24,7 @@ declare class AuthRepository extends BaseRepository<AuthEntity> implements IExte
24
24
  findByEmail(email: string): Promise<AuthEntity | null>;
25
25
  create(entity: Omit<AuthEntity, "createdAt">): Promise<AuthEntity>;
26
26
  findByUserId(userId: string): Promise<AuthEntity | null>;
27
+ findByUseAdminId(userId: string, isAdmin?: boolean): Promise<AuthEntity | null>;
27
28
  logout(userId: string): Promise<void>;
28
29
  updateTwoFactorSecret(userId: string, secret: string): Promise<void>;
29
30
  enableTwoFactor(auth: AuthEntity): Promise<void>;
@@ -43,6 +44,36 @@ declare class RegisterUseCase implements IBaseService {
43
44
  private createAuthEntity;
44
45
  }
45
46
 
47
+ declare class LoginDTO {
48
+ email: string;
49
+ password: string;
50
+ adminPassword?: string;
51
+ role?: UserRole;
52
+ }
53
+
54
+ declare class LoginUseCase implements IBaseService {
55
+ private readonly repository;
56
+ constructor(repository: AuthRepository);
57
+ initialize(): Promise<void>;
58
+ execute(loginDTO: LoginDTO): Promise<string>;
59
+ private validateLogin;
60
+ }
61
+
62
+ declare class LoginAdminUseCase implements IBaseService {
63
+ private readonly repository;
64
+ constructor(repository: AuthRepository);
65
+ initialize(): Promise<void>;
66
+ execute(loginDTO: LoginDTO, adminPassword: string): Promise<string>;
67
+ private validateLogin;
68
+ }
69
+
70
+ declare class LogoutUseCase implements IBaseService {
71
+ private readonly repository;
72
+ constructor(repository: AuthRepository);
73
+ initialize(): Promise<void>;
74
+ execute(authId: string): Promise<void>;
75
+ }
76
+
46
77
  interface IJwtConfig {
47
78
  accessTokenSecret: string;
48
79
  refreshTokenSecret: string;
@@ -80,81 +111,17 @@ declare class JwtAuthService implements IBaseService, IAuthService {
80
111
  verifyRefreshToken(token: string): Promise<IDecodedToken>;
81
112
  }
82
113
 
83
- declare class UserDTO {
84
- id: string;
85
- name: string;
86
- email: string;
87
- role: UserRole;
88
- }
89
-
90
- declare class LoginDTO {
91
- email: string;
92
- password: string;
93
- adminPassword?: string;
94
- role?: UserRole;
95
- }
96
-
97
- interface TokenPair$1 {
98
- accessToken: string;
99
- refreshToken: string;
100
- }
101
- interface LoginResponse$1 {
102
- token: TokenPair$1;
103
- user: UserDTO;
104
- }
105
- declare class LoginUseCase implements IBaseService {
106
- private readonly repository;
107
- private readonly authService;
108
- constructor(repository: AuthRepository, authService: JwtAuthService);
109
- initialize(): Promise<void>;
110
- execute(loginDTO: LoginDTO): Promise<LoginResponse$1>;
111
- private validateLogin;
112
- private handleAuthentication;
113
- private generateTokens;
114
- private updateUserStatus;
115
- private updateUserRefreshToken;
116
- private mapUserToDTO;
117
- }
118
-
119
114
  interface TokenPair {
120
115
  accessToken: string;
121
116
  refreshToken: string;
122
117
  }
123
- interface LoginResponse {
124
- token: TokenPair;
125
- user: UserDTO;
126
- }
127
- declare class LoginAdminUseCase implements IBaseService {
128
- private readonly repository;
129
- private readonly authService;
130
- constructor(repository: AuthRepository, authService: JwtAuthService);
131
- initialize(): Promise<void>;
132
- execute(loginDTO: LoginDTO, adminPassword: string): Promise<LoginResponse>;
133
- private validateLogin;
134
- private handleAuthentication;
135
- private generateTokens;
136
- private updateUserStatus;
137
- private updateUserRefreshToken;
138
- private mapUserToDTO;
139
- }
140
-
141
- declare class LogoutUseCase implements IBaseService {
142
- private readonly repository;
143
- constructor(repository: AuthRepository);
144
- initialize(): Promise<void>;
145
- execute(authId: string): Promise<void>;
146
- }
147
118
 
148
119
  declare class RefreshTokenUseCase implements IBaseService {
149
120
  private readonly repository;
150
121
  private readonly service;
151
122
  constructor(repository: AuthRepository, service: JwtAuthService);
152
123
  initialize(): Promise<void>;
153
- execute(refreshToken: string): Promise<{
154
- accessToken: string;
155
- refreshToken: string;
156
- } | null>;
157
- verityToken(token: string): Promise<IDecodedToken>;
124
+ execute(refreshToken: string): Promise<TokenPair | null>;
158
125
  }
159
126
 
160
127
  declare class TwoFactorService implements IBaseService {
@@ -207,17 +174,38 @@ interface ITwoFactorVerify {
207
174
  token: string;
208
175
  }
209
176
 
177
+ declare class AdminDTO {
178
+ id: string;
179
+ name: string;
180
+ email: string;
181
+ role: UserRole;
182
+ adminPassword: string;
183
+ }
184
+
185
+ declare class UserDTO {
186
+ id: string;
187
+ name: string;
188
+ email: string;
189
+ role: UserRole;
190
+ }
191
+
210
192
  declare class TwoFactorVerifyUseCase implements IBaseService {
211
- private twoFactorService;
212
- private authRepository;
213
- private jwtService;
193
+ private readonly twoFactorService;
194
+ private readonly authRepository;
195
+ private readonly jwtService;
214
196
  private isInitialized;
215
197
  constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository, jwtService: JwtAuthService);
216
198
  initialize(): Promise<void>;
217
199
  execute(dto: ITwoFactorVerify): Promise<{
218
200
  token: string;
219
201
  refreshToken: string;
220
- }>;
202
+ data?: AdminDTO | UserDTO;
203
+ } | null>;
204
+ private mapAdminToDTO;
205
+ private mapUserToDTO;
206
+ private updateUserStatus;
207
+ private updateUserRefreshToken;
208
+ private generateTokens;
221
209
  }
222
210
 
223
211
  declare class TwoFactorDisableUseCase implements IBaseService {
@@ -245,7 +233,6 @@ declare class AuthController {
245
233
  logout: (req: Request, res: Response, next: NextFunction) => Promise<void>;
246
234
  register: (req: Request, res: Response, next: NextFunction) => Promise<void>;
247
235
  refreshToken: (req: Request, res: Response) => Promise<void>;
248
- verifyToken: (token: string) => Promise<IDecodedToken>;
249
236
  setup2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
250
237
  enable2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
251
238
  verify2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ declare class AuthRepository extends BaseRepository<AuthEntity> implements IExte
24
24
  findByEmail(email: string): Promise<AuthEntity | null>;
25
25
  create(entity: Omit<AuthEntity, "createdAt">): Promise<AuthEntity>;
26
26
  findByUserId(userId: string): Promise<AuthEntity | null>;
27
+ findByUseAdminId(userId: string, isAdmin?: boolean): Promise<AuthEntity | null>;
27
28
  logout(userId: string): Promise<void>;
28
29
  updateTwoFactorSecret(userId: string, secret: string): Promise<void>;
29
30
  enableTwoFactor(auth: AuthEntity): Promise<void>;
@@ -43,6 +44,36 @@ declare class RegisterUseCase implements IBaseService {
43
44
  private createAuthEntity;
44
45
  }
45
46
 
47
+ declare class LoginDTO {
48
+ email: string;
49
+ password: string;
50
+ adminPassword?: string;
51
+ role?: UserRole;
52
+ }
53
+
54
+ declare class LoginUseCase implements IBaseService {
55
+ private readonly repository;
56
+ constructor(repository: AuthRepository);
57
+ initialize(): Promise<void>;
58
+ execute(loginDTO: LoginDTO): Promise<string>;
59
+ private validateLogin;
60
+ }
61
+
62
+ declare class LoginAdminUseCase implements IBaseService {
63
+ private readonly repository;
64
+ constructor(repository: AuthRepository);
65
+ initialize(): Promise<void>;
66
+ execute(loginDTO: LoginDTO, adminPassword: string): Promise<string>;
67
+ private validateLogin;
68
+ }
69
+
70
+ declare class LogoutUseCase implements IBaseService {
71
+ private readonly repository;
72
+ constructor(repository: AuthRepository);
73
+ initialize(): Promise<void>;
74
+ execute(authId: string): Promise<void>;
75
+ }
76
+
46
77
  interface IJwtConfig {
47
78
  accessTokenSecret: string;
48
79
  refreshTokenSecret: string;
@@ -80,81 +111,17 @@ declare class JwtAuthService implements IBaseService, IAuthService {
80
111
  verifyRefreshToken(token: string): Promise<IDecodedToken>;
81
112
  }
82
113
 
83
- declare class UserDTO {
84
- id: string;
85
- name: string;
86
- email: string;
87
- role: UserRole;
88
- }
89
-
90
- declare class LoginDTO {
91
- email: string;
92
- password: string;
93
- adminPassword?: string;
94
- role?: UserRole;
95
- }
96
-
97
- interface TokenPair$1 {
98
- accessToken: string;
99
- refreshToken: string;
100
- }
101
- interface LoginResponse$1 {
102
- token: TokenPair$1;
103
- user: UserDTO;
104
- }
105
- declare class LoginUseCase implements IBaseService {
106
- private readonly repository;
107
- private readonly authService;
108
- constructor(repository: AuthRepository, authService: JwtAuthService);
109
- initialize(): Promise<void>;
110
- execute(loginDTO: LoginDTO): Promise<LoginResponse$1>;
111
- private validateLogin;
112
- private handleAuthentication;
113
- private generateTokens;
114
- private updateUserStatus;
115
- private updateUserRefreshToken;
116
- private mapUserToDTO;
117
- }
118
-
119
114
  interface TokenPair {
120
115
  accessToken: string;
121
116
  refreshToken: string;
122
117
  }
123
- interface LoginResponse {
124
- token: TokenPair;
125
- user: UserDTO;
126
- }
127
- declare class LoginAdminUseCase implements IBaseService {
128
- private readonly repository;
129
- private readonly authService;
130
- constructor(repository: AuthRepository, authService: JwtAuthService);
131
- initialize(): Promise<void>;
132
- execute(loginDTO: LoginDTO, adminPassword: string): Promise<LoginResponse>;
133
- private validateLogin;
134
- private handleAuthentication;
135
- private generateTokens;
136
- private updateUserStatus;
137
- private updateUserRefreshToken;
138
- private mapUserToDTO;
139
- }
140
-
141
- declare class LogoutUseCase implements IBaseService {
142
- private readonly repository;
143
- constructor(repository: AuthRepository);
144
- initialize(): Promise<void>;
145
- execute(authId: string): Promise<void>;
146
- }
147
118
 
148
119
  declare class RefreshTokenUseCase implements IBaseService {
149
120
  private readonly repository;
150
121
  private readonly service;
151
122
  constructor(repository: AuthRepository, service: JwtAuthService);
152
123
  initialize(): Promise<void>;
153
- execute(refreshToken: string): Promise<{
154
- accessToken: string;
155
- refreshToken: string;
156
- } | null>;
157
- verityToken(token: string): Promise<IDecodedToken>;
124
+ execute(refreshToken: string): Promise<TokenPair | null>;
158
125
  }
159
126
 
160
127
  declare class TwoFactorService implements IBaseService {
@@ -207,17 +174,38 @@ interface ITwoFactorVerify {
207
174
  token: string;
208
175
  }
209
176
 
177
+ declare class AdminDTO {
178
+ id: string;
179
+ name: string;
180
+ email: string;
181
+ role: UserRole;
182
+ adminPassword: string;
183
+ }
184
+
185
+ declare class UserDTO {
186
+ id: string;
187
+ name: string;
188
+ email: string;
189
+ role: UserRole;
190
+ }
191
+
210
192
  declare class TwoFactorVerifyUseCase implements IBaseService {
211
- private twoFactorService;
212
- private authRepository;
213
- private jwtService;
193
+ private readonly twoFactorService;
194
+ private readonly authRepository;
195
+ private readonly jwtService;
214
196
  private isInitialized;
215
197
  constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository, jwtService: JwtAuthService);
216
198
  initialize(): Promise<void>;
217
199
  execute(dto: ITwoFactorVerify): Promise<{
218
200
  token: string;
219
201
  refreshToken: string;
220
- }>;
202
+ data?: AdminDTO | UserDTO;
203
+ } | null>;
204
+ private mapAdminToDTO;
205
+ private mapUserToDTO;
206
+ private updateUserStatus;
207
+ private updateUserRefreshToken;
208
+ private generateTokens;
221
209
  }
222
210
 
223
211
  declare class TwoFactorDisableUseCase implements IBaseService {
@@ -245,7 +233,6 @@ declare class AuthController {
245
233
  logout: (req: Request, res: Response, next: NextFunction) => Promise<void>;
246
234
  register: (req: Request, res: Response, next: NextFunction) => Promise<void>;
247
235
  refreshToken: (req: Request, res: Response) => Promise<void>;
248
- verifyToken: (token: string) => Promise<IDecodedToken>;
249
236
  setup2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
250
237
  enable2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
251
238
  verify2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;