cca-auth-module 0.1.32 → 0.1.34
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/dist/application/useCase/LoginUseCase.d.ts +1 -1
- package/dist/application/useCase/RefreshTokenUseCase.d.ts +1 -1
- package/dist/application/useCase/TwoFactorDisableUseCase.d.ts +12 -0
- package/dist/application/useCase/TwoFactorEnableUseCase.d.ts +12 -0
- package/dist/application/useCase/TwoFactorSetupUseCase.d.ts +12 -0
- package/dist/application/useCase/TwoFactorVerifyUseCase.d.ts +17 -0
- package/dist/domain/interfaces/ITwoFactorEnable.d.ts +3 -0
- package/dist/domain/interfaces/ITwoFactorSetupResponse.d.ts +5 -0
- package/dist/domain/interfaces/ITwoFactorVerify.d.ts +4 -0
- package/dist/domain/interfaces/configTypes.d.ts +3 -0
- package/dist/index.d.mts +100 -6
- package/dist/index.d.ts +100 -6
- package/dist/index.js +392 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +388 -10
- package/dist/index.mjs.map +1 -1
- package/dist/infrastructure/container/createAuthContainer.d.ts +4 -2
- package/dist/infrastructure/repository/AuthRepository.d.ts +5 -0
- package/dist/infrastructure/services/TwoFactorService.d.ts +17 -0
- package/dist/presentation/controller/AuthController.d.ts +17 -5
- package/dist/presentation/middleware/RequireComplete2FA.d.ts +7 -0
- package/dist/utils/Errors.d.ts +3 -0
- package/package.json +6 -2
- /package/dist/application/useCase/{LogoutUseCase .d.ts → LogoutUseCase.d.ts} +0 -0
- /package/dist/infrastructure/{auth → services}/JwtAuthService.d.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IBaseService } from "cca-core";
|
|
2
2
|
import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
|
|
3
|
-
import { JwtAuthService } from "../../infrastructure/
|
|
3
|
+
import { JwtAuthService } from "../../infrastructure/services/JwtAuthService";
|
|
4
4
|
import { UserDTO } from "../dtos/UserDTO";
|
|
5
5
|
import { LoginDTO } from "../dtos/LoginDTO";
|
|
6
6
|
interface TokenPair {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IBaseService } from "cca-core";
|
|
2
2
|
import { IDecodedToken } from "../../domain/interfaces/IDecodedToken";
|
|
3
|
-
import { JwtAuthService } from "../../infrastructure/
|
|
3
|
+
import { JwtAuthService } from "../../infrastructure/services/JwtAuthService";
|
|
4
4
|
import { AuthRepository } from "../../infrastructure/repository/AuthRepository";
|
|
5
5
|
export declare class RefreshTokenUseCase implements IBaseService {
|
|
6
6
|
private readonly repository;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IBaseService } from 'cca-core';
|
|
2
|
+
import { TwoFactorService } from '../../infrastructure/services/TwoFactorService';
|
|
3
|
+
import { AuthRepository } from '../../infrastructure/repository/AuthRepository';
|
|
4
|
+
import { ITwoFactorEnable } from '../../domain/interfaces/ITwoFactorEnable';
|
|
5
|
+
export declare class TwoFactorDisableUseCase implements IBaseService {
|
|
6
|
+
private twoFactorService;
|
|
7
|
+
private authRepository;
|
|
8
|
+
private isInitialized;
|
|
9
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
execute(userId: string, dto: ITwoFactorEnable): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IBaseService } from 'cca-core';
|
|
2
|
+
import { TwoFactorService } from '../../infrastructure/services/TwoFactorService';
|
|
3
|
+
import { AuthRepository } from '../../infrastructure/repository/AuthRepository';
|
|
4
|
+
import { ITwoFactorEnable } from '../../domain/interfaces/ITwoFactorEnable';
|
|
5
|
+
export declare class TwoFactorEnableUseCase implements IBaseService {
|
|
6
|
+
private twoFactorService;
|
|
7
|
+
private authRepository;
|
|
8
|
+
private isInitialized;
|
|
9
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
execute(userId: string, dto: ITwoFactorEnable): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IBaseService } from 'cca-core';
|
|
2
|
+
import { TwoFactorService } from '../../infrastructure/services/TwoFactorService';
|
|
3
|
+
import { AuthRepository } from '../../infrastructure/repository/AuthRepository';
|
|
4
|
+
import { ITwoFactorSetupResponse } from '../../domain/interfaces/ITwoFactorSetupResponse';
|
|
5
|
+
export declare class TwoFactorSetupUseCase implements IBaseService {
|
|
6
|
+
private twoFactorService;
|
|
7
|
+
private authRepository;
|
|
8
|
+
private isInitialized;
|
|
9
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
10
|
+
initialize(): Promise<void>;
|
|
11
|
+
execute(userId: string): Promise<ITwoFactorSetupResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IBaseService } from 'cca-core';
|
|
2
|
+
import { TwoFactorService } from '../../infrastructure/services/TwoFactorService';
|
|
3
|
+
import { AuthRepository } from '../../infrastructure/repository/AuthRepository';
|
|
4
|
+
import { JwtAuthService } from '../../infrastructure/services/JwtAuthService';
|
|
5
|
+
import { ITwoFactorVerify } from '../../domain/interfaces/ITwoFactorVerify';
|
|
6
|
+
export declare class TwoFactorVerifyUseCase implements IBaseService {
|
|
7
|
+
private twoFactorService;
|
|
8
|
+
private authRepository;
|
|
9
|
+
private jwtService;
|
|
10
|
+
private isInitialized;
|
|
11
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository, jwtService: JwtAuthService);
|
|
12
|
+
initialize(): Promise<void>;
|
|
13
|
+
execute(dto: ITwoFactorVerify): Promise<{
|
|
14
|
+
token: string;
|
|
15
|
+
refreshToken: string;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,9 @@ interface IConfig {
|
|
|
11
11
|
accessTokenExpiry: string;
|
|
12
12
|
refreshTokenExpiry: string;
|
|
13
13
|
adminSecretPassword: string;
|
|
14
|
+
app_name: string;
|
|
15
|
+
secretLength: string;
|
|
16
|
+
tokenWindow: string;
|
|
14
17
|
}
|
|
15
18
|
type ConfigSource = () => Promise<IConfig>;
|
|
16
19
|
|
|
@@ -22,6 +25,11 @@ declare class AuthRepository extends BaseRepository<AuthEntity> implements IExte
|
|
|
22
25
|
create(entity: Omit<AuthEntity, "createdAt">): Promise<AuthEntity>;
|
|
23
26
|
findByUserId(userId: string): Promise<AuthEntity | null>;
|
|
24
27
|
logout(userId: string): Promise<void>;
|
|
28
|
+
updateTwoFactorSecret(userId: string, secret: string): Promise<void>;
|
|
29
|
+
enableTwoFactor(userId: string): Promise<void>;
|
|
30
|
+
disableTwoFactor(userId: string): Promise<void>;
|
|
31
|
+
isTwoFactorEnabled(userId: string): Promise<boolean>;
|
|
32
|
+
getTwoFactorSecret(userId: string): Promise<string | null>;
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
declare class RegisterUseCase implements IBaseService {
|
|
@@ -128,22 +136,108 @@ declare class RefreshTokenUseCase implements IBaseService {
|
|
|
128
136
|
verityToken(token: string): Promise<IDecodedToken>;
|
|
129
137
|
}
|
|
130
138
|
|
|
139
|
+
declare class TwoFactorService implements IBaseService {
|
|
140
|
+
private readonly config;
|
|
141
|
+
private initialized;
|
|
142
|
+
private readonly twoFactorConfig;
|
|
143
|
+
constructor(config: IConfig);
|
|
144
|
+
initialize(): Promise<void>;
|
|
145
|
+
private validateConfiguration;
|
|
146
|
+
private ensureInitialized;
|
|
147
|
+
generateSecret(email: string): {
|
|
148
|
+
secret: string;
|
|
149
|
+
otpAuthUrl: string;
|
|
150
|
+
};
|
|
151
|
+
generateQRCode(otpAuthUrl: string): Promise<string>;
|
|
152
|
+
verifyToken(token: string, secret: string): boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface ITwoFactorSetupResponse {
|
|
156
|
+
secret: string;
|
|
157
|
+
otpAuthUrl: string;
|
|
158
|
+
qrCodeUrl: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
declare class TwoFactorSetupUseCase implements IBaseService {
|
|
162
|
+
private twoFactorService;
|
|
163
|
+
private authRepository;
|
|
164
|
+
private isInitialized;
|
|
165
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
166
|
+
initialize(): Promise<void>;
|
|
167
|
+
execute(userId: string): Promise<ITwoFactorSetupResponse>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
interface ITwoFactorEnable {
|
|
171
|
+
token: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class TwoFactorEnableUseCase implements IBaseService {
|
|
175
|
+
private twoFactorService;
|
|
176
|
+
private authRepository;
|
|
177
|
+
private isInitialized;
|
|
178
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
179
|
+
initialize(): Promise<void>;
|
|
180
|
+
execute(userId: string, dto: ITwoFactorEnable): Promise<void>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface ITwoFactorVerify {
|
|
184
|
+
userId: string;
|
|
185
|
+
token: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare class TwoFactorVerifyUseCase implements IBaseService {
|
|
189
|
+
private twoFactorService;
|
|
190
|
+
private authRepository;
|
|
191
|
+
private jwtService;
|
|
192
|
+
private isInitialized;
|
|
193
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository, jwtService: JwtAuthService);
|
|
194
|
+
initialize(): Promise<void>;
|
|
195
|
+
execute(dto: ITwoFactorVerify): Promise<{
|
|
196
|
+
token: string;
|
|
197
|
+
refreshToken: string;
|
|
198
|
+
}>;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
declare class TwoFactorDisableUseCase implements IBaseService {
|
|
202
|
+
private twoFactorService;
|
|
203
|
+
private authRepository;
|
|
204
|
+
private isInitialized;
|
|
205
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
206
|
+
initialize(): Promise<void>;
|
|
207
|
+
execute(userId: string, dto: ITwoFactorEnable): Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
|
|
131
210
|
declare class AuthController {
|
|
132
|
-
private loginUseCase;
|
|
211
|
+
private readonly loginUseCase;
|
|
133
212
|
private readonly logoutUseCase;
|
|
134
|
-
private registerUseCase;
|
|
135
|
-
private refreshTokenUseCase;
|
|
136
|
-
|
|
213
|
+
private readonly registerUseCase;
|
|
214
|
+
private readonly refreshTokenUseCase;
|
|
215
|
+
private twoFactorSetupUseCase;
|
|
216
|
+
private twoFactorEnableUseCase;
|
|
217
|
+
private twoFactorVerifyUseCase;
|
|
218
|
+
private twoFactorDisableUseCase;
|
|
219
|
+
constructor(loginUseCase: LoginUseCase, logoutUseCase: LogoutUseCase, registerUseCase: RegisterUseCase, refreshTokenUseCase: RefreshTokenUseCase, twoFactorSetupUseCase: TwoFactorSetupUseCase, twoFactorEnableUseCase: TwoFactorEnableUseCase, twoFactorVerifyUseCase: TwoFactorVerifyUseCase, twoFactorDisableUseCase: TwoFactorDisableUseCase);
|
|
137
220
|
login: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
138
221
|
logout: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
139
222
|
register: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
140
223
|
refreshToken: (req: Request, res: Response) => Promise<void>;
|
|
141
224
|
verifyToken: (token: string) => Promise<IDecodedToken>;
|
|
225
|
+
setup2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
226
|
+
enable2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
227
|
+
verify2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
228
|
+
disable2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare class RequireComplete2FA {
|
|
232
|
+
private readonly jwtService;
|
|
233
|
+
constructor(jwtService: JwtAuthService);
|
|
234
|
+
execute(req: Request, res: Response, next: NextFunction): Promise<Response<any, Record<string, any>> | undefined>;
|
|
142
235
|
}
|
|
143
236
|
|
|
144
|
-
declare function createAuthContainer(database: BaseDatabase): {
|
|
237
|
+
declare function createAuthContainer(database: BaseDatabase): Promise<{
|
|
145
238
|
container: BaseContainer;
|
|
146
239
|
authController: AuthController;
|
|
147
|
-
|
|
240
|
+
requireComplete2FA: RequireComplete2FA;
|
|
241
|
+
}>;
|
|
148
242
|
|
|
149
243
|
export { AuthController, type ConfigSource, type IConfig, authConfig, createAuthContainer };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ interface IConfig {
|
|
|
11
11
|
accessTokenExpiry: string;
|
|
12
12
|
refreshTokenExpiry: string;
|
|
13
13
|
adminSecretPassword: string;
|
|
14
|
+
app_name: string;
|
|
15
|
+
secretLength: string;
|
|
16
|
+
tokenWindow: string;
|
|
14
17
|
}
|
|
15
18
|
type ConfigSource = () => Promise<IConfig>;
|
|
16
19
|
|
|
@@ -22,6 +25,11 @@ declare class AuthRepository extends BaseRepository<AuthEntity> implements IExte
|
|
|
22
25
|
create(entity: Omit<AuthEntity, "createdAt">): Promise<AuthEntity>;
|
|
23
26
|
findByUserId(userId: string): Promise<AuthEntity | null>;
|
|
24
27
|
logout(userId: string): Promise<void>;
|
|
28
|
+
updateTwoFactorSecret(userId: string, secret: string): Promise<void>;
|
|
29
|
+
enableTwoFactor(userId: string): Promise<void>;
|
|
30
|
+
disableTwoFactor(userId: string): Promise<void>;
|
|
31
|
+
isTwoFactorEnabled(userId: string): Promise<boolean>;
|
|
32
|
+
getTwoFactorSecret(userId: string): Promise<string | null>;
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
declare class RegisterUseCase implements IBaseService {
|
|
@@ -128,22 +136,108 @@ declare class RefreshTokenUseCase implements IBaseService {
|
|
|
128
136
|
verityToken(token: string): Promise<IDecodedToken>;
|
|
129
137
|
}
|
|
130
138
|
|
|
139
|
+
declare class TwoFactorService implements IBaseService {
|
|
140
|
+
private readonly config;
|
|
141
|
+
private initialized;
|
|
142
|
+
private readonly twoFactorConfig;
|
|
143
|
+
constructor(config: IConfig);
|
|
144
|
+
initialize(): Promise<void>;
|
|
145
|
+
private validateConfiguration;
|
|
146
|
+
private ensureInitialized;
|
|
147
|
+
generateSecret(email: string): {
|
|
148
|
+
secret: string;
|
|
149
|
+
otpAuthUrl: string;
|
|
150
|
+
};
|
|
151
|
+
generateQRCode(otpAuthUrl: string): Promise<string>;
|
|
152
|
+
verifyToken(token: string, secret: string): boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface ITwoFactorSetupResponse {
|
|
156
|
+
secret: string;
|
|
157
|
+
otpAuthUrl: string;
|
|
158
|
+
qrCodeUrl: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
declare class TwoFactorSetupUseCase implements IBaseService {
|
|
162
|
+
private twoFactorService;
|
|
163
|
+
private authRepository;
|
|
164
|
+
private isInitialized;
|
|
165
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
166
|
+
initialize(): Promise<void>;
|
|
167
|
+
execute(userId: string): Promise<ITwoFactorSetupResponse>;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
interface ITwoFactorEnable {
|
|
171
|
+
token: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class TwoFactorEnableUseCase implements IBaseService {
|
|
175
|
+
private twoFactorService;
|
|
176
|
+
private authRepository;
|
|
177
|
+
private isInitialized;
|
|
178
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
179
|
+
initialize(): Promise<void>;
|
|
180
|
+
execute(userId: string, dto: ITwoFactorEnable): Promise<void>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface ITwoFactorVerify {
|
|
184
|
+
userId: string;
|
|
185
|
+
token: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare class TwoFactorVerifyUseCase implements IBaseService {
|
|
189
|
+
private twoFactorService;
|
|
190
|
+
private authRepository;
|
|
191
|
+
private jwtService;
|
|
192
|
+
private isInitialized;
|
|
193
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository, jwtService: JwtAuthService);
|
|
194
|
+
initialize(): Promise<void>;
|
|
195
|
+
execute(dto: ITwoFactorVerify): Promise<{
|
|
196
|
+
token: string;
|
|
197
|
+
refreshToken: string;
|
|
198
|
+
}>;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
declare class TwoFactorDisableUseCase implements IBaseService {
|
|
202
|
+
private twoFactorService;
|
|
203
|
+
private authRepository;
|
|
204
|
+
private isInitialized;
|
|
205
|
+
constructor(twoFactorService: TwoFactorService, authRepository: AuthRepository);
|
|
206
|
+
initialize(): Promise<void>;
|
|
207
|
+
execute(userId: string, dto: ITwoFactorEnable): Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
|
|
131
210
|
declare class AuthController {
|
|
132
|
-
private loginUseCase;
|
|
211
|
+
private readonly loginUseCase;
|
|
133
212
|
private readonly logoutUseCase;
|
|
134
|
-
private registerUseCase;
|
|
135
|
-
private refreshTokenUseCase;
|
|
136
|
-
|
|
213
|
+
private readonly registerUseCase;
|
|
214
|
+
private readonly refreshTokenUseCase;
|
|
215
|
+
private twoFactorSetupUseCase;
|
|
216
|
+
private twoFactorEnableUseCase;
|
|
217
|
+
private twoFactorVerifyUseCase;
|
|
218
|
+
private twoFactorDisableUseCase;
|
|
219
|
+
constructor(loginUseCase: LoginUseCase, logoutUseCase: LogoutUseCase, registerUseCase: RegisterUseCase, refreshTokenUseCase: RefreshTokenUseCase, twoFactorSetupUseCase: TwoFactorSetupUseCase, twoFactorEnableUseCase: TwoFactorEnableUseCase, twoFactorVerifyUseCase: TwoFactorVerifyUseCase, twoFactorDisableUseCase: TwoFactorDisableUseCase);
|
|
137
220
|
login: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
138
221
|
logout: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
139
222
|
register: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
140
223
|
refreshToken: (req: Request, res: Response) => Promise<void>;
|
|
141
224
|
verifyToken: (token: string) => Promise<IDecodedToken>;
|
|
225
|
+
setup2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
226
|
+
enable2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
227
|
+
verify2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
228
|
+
disable2FA: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare class RequireComplete2FA {
|
|
232
|
+
private readonly jwtService;
|
|
233
|
+
constructor(jwtService: JwtAuthService);
|
|
234
|
+
execute(req: Request, res: Response, next: NextFunction): Promise<Response<any, Record<string, any>> | undefined>;
|
|
142
235
|
}
|
|
143
236
|
|
|
144
|
-
declare function createAuthContainer(database: BaseDatabase): {
|
|
237
|
+
declare function createAuthContainer(database: BaseDatabase): Promise<{
|
|
145
238
|
container: BaseContainer;
|
|
146
239
|
authController: AuthController;
|
|
147
|
-
|
|
240
|
+
requireComplete2FA: RequireComplete2FA;
|
|
241
|
+
}>;
|
|
148
242
|
|
|
149
243
|
export { AuthController, type ConfigSource, type IConfig, authConfig, createAuthContainer };
|