cca-auth-module 0.1.90 → 0.1.91
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/index.d.mts +2 -10
- package/dist/index.d.ts +2 -10
- package/dist/index.js +25 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -42
- package/dist/index.mjs.map +1 -1
- package/dist/presentation/controller/AuthController.d.ts +1 -3
- package/package.json +1 -1
- package/dist/application/useCase/LoginAdminUseCase.d.ts +0 -9
|
@@ -7,7 +7,7 @@ export declare class LoginUseCase implements IBaseService {
|
|
|
7
7
|
private readonly jwtService;
|
|
8
8
|
constructor(repository: AuthRepository, jwtService: JwtAuthService);
|
|
9
9
|
initialize(): Promise<void>;
|
|
10
|
-
execute(loginDTO: LoginDTO): Promise<{
|
|
10
|
+
execute(loginDTO: LoginDTO, providedAdminPassword: string, admin: boolean): Promise<{
|
|
11
11
|
id: string;
|
|
12
12
|
accessToken: string;
|
|
13
13
|
expiresAt: number;
|
package/dist/index.d.mts
CHANGED
|
@@ -95,7 +95,7 @@ declare class LoginUseCase implements IBaseService {
|
|
|
95
95
|
private readonly jwtService;
|
|
96
96
|
constructor(repository: AuthRepository, jwtService: JwtAuthService);
|
|
97
97
|
initialize(): Promise<void>;
|
|
98
|
-
execute(loginDTO: LoginDTO): Promise<{
|
|
98
|
+
execute(loginDTO: LoginDTO, providedAdminPassword: string, admin: boolean): Promise<{
|
|
99
99
|
id: string;
|
|
100
100
|
accessToken: string;
|
|
101
101
|
expiresAt: number;
|
|
@@ -103,13 +103,6 @@ declare class LoginUseCase implements IBaseService {
|
|
|
103
103
|
}>;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
declare class LoginAdminUseCase implements IBaseService {
|
|
107
|
-
private readonly repository;
|
|
108
|
-
constructor(repository: AuthRepository);
|
|
109
|
-
initialize(): Promise<void>;
|
|
110
|
-
execute(loginDTO: LoginDTO, adminPassword: string): Promise<string>;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
106
|
declare class LogoutUseCase implements IBaseService {
|
|
114
107
|
private readonly repository;
|
|
115
108
|
constructor(repository: AuthRepository);
|
|
@@ -224,7 +217,6 @@ declare class TwoFactorDisableUseCase implements IBaseService {
|
|
|
224
217
|
|
|
225
218
|
declare class AuthController {
|
|
226
219
|
private readonly loginUseCase;
|
|
227
|
-
private readonly adminLoginUseCase;
|
|
228
220
|
private readonly logoutUseCase;
|
|
229
221
|
private readonly registerUseCase;
|
|
230
222
|
private readonly refreshTokenUseCase;
|
|
@@ -232,7 +224,7 @@ declare class AuthController {
|
|
|
232
224
|
private readonly twoFactorEnableUseCase;
|
|
233
225
|
private readonly twoFactorVerifyUseCase;
|
|
234
226
|
private readonly twoFactorDisableUseCase;
|
|
235
|
-
constructor(loginUseCase: LoginUseCase,
|
|
227
|
+
constructor(loginUseCase: LoginUseCase, logoutUseCase: LogoutUseCase, registerUseCase: RegisterUseCase, refreshTokenUseCase: RefreshTokenUseCase, twoFactorSetupUseCase: TwoFactorSetupUseCase, twoFactorEnableUseCase: TwoFactorEnableUseCase, twoFactorVerifyUseCase: TwoFactorVerifyUseCase, twoFactorDisableUseCase: TwoFactorDisableUseCase);
|
|
236
228
|
private createResponse;
|
|
237
229
|
private createAuthData;
|
|
238
230
|
private sendResponse;
|
package/dist/index.d.ts
CHANGED
|
@@ -95,7 +95,7 @@ declare class LoginUseCase implements IBaseService {
|
|
|
95
95
|
private readonly jwtService;
|
|
96
96
|
constructor(repository: AuthRepository, jwtService: JwtAuthService);
|
|
97
97
|
initialize(): Promise<void>;
|
|
98
|
-
execute(loginDTO: LoginDTO): Promise<{
|
|
98
|
+
execute(loginDTO: LoginDTO, providedAdminPassword: string, admin: boolean): Promise<{
|
|
99
99
|
id: string;
|
|
100
100
|
accessToken: string;
|
|
101
101
|
expiresAt: number;
|
|
@@ -103,13 +103,6 @@ declare class LoginUseCase implements IBaseService {
|
|
|
103
103
|
}>;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
declare class LoginAdminUseCase implements IBaseService {
|
|
107
|
-
private readonly repository;
|
|
108
|
-
constructor(repository: AuthRepository);
|
|
109
|
-
initialize(): Promise<void>;
|
|
110
|
-
execute(loginDTO: LoginDTO, adminPassword: string): Promise<string>;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
106
|
declare class LogoutUseCase implements IBaseService {
|
|
114
107
|
private readonly repository;
|
|
115
108
|
constructor(repository: AuthRepository);
|
|
@@ -224,7 +217,6 @@ declare class TwoFactorDisableUseCase implements IBaseService {
|
|
|
224
217
|
|
|
225
218
|
declare class AuthController {
|
|
226
219
|
private readonly loginUseCase;
|
|
227
|
-
private readonly adminLoginUseCase;
|
|
228
220
|
private readonly logoutUseCase;
|
|
229
221
|
private readonly registerUseCase;
|
|
230
222
|
private readonly refreshTokenUseCase;
|
|
@@ -232,7 +224,7 @@ declare class AuthController {
|
|
|
232
224
|
private readonly twoFactorEnableUseCase;
|
|
233
225
|
private readonly twoFactorVerifyUseCase;
|
|
234
226
|
private readonly twoFactorDisableUseCase;
|
|
235
|
-
constructor(loginUseCase: LoginUseCase,
|
|
227
|
+
constructor(loginUseCase: LoginUseCase, logoutUseCase: LogoutUseCase, registerUseCase: RegisterUseCase, refreshTokenUseCase: RefreshTokenUseCase, twoFactorSetupUseCase: TwoFactorSetupUseCase, twoFactorEnableUseCase: TwoFactorEnableUseCase, twoFactorVerifyUseCase: TwoFactorVerifyUseCase, twoFactorDisableUseCase: TwoFactorDisableUseCase);
|
|
236
228
|
private createResponse;
|
|
237
229
|
private createAuthData;
|
|
238
230
|
private sendResponse;
|
package/dist/index.js
CHANGED
|
@@ -163,7 +163,7 @@ var createConfigInstance = /* @__PURE__ */ __name(async () => {
|
|
|
163
163
|
}, "createConfigInstance");
|
|
164
164
|
|
|
165
165
|
// src/infrastructure/container/createAuthContainer.ts
|
|
166
|
-
var
|
|
166
|
+
var import_cca_core10 = require("cca-core");
|
|
167
167
|
var import_cca_entities5 = require("cca-entities");
|
|
168
168
|
|
|
169
169
|
// src/application/useCase/LoginUseCase.ts
|
|
@@ -275,7 +275,10 @@ var _LoginUseCase = class _LoginUseCase {
|
|
|
275
275
|
async initialize() {
|
|
276
276
|
await (0, import_cca_core.validateRepository)(this.repository, (repo) => repo.getAll());
|
|
277
277
|
}
|
|
278
|
-
async execute(loginDTO) {
|
|
278
|
+
async execute(loginDTO, providedAdminPassword, admin) {
|
|
279
|
+
if (admin) {
|
|
280
|
+
await validateAdminSecret(providedAdminPassword);
|
|
281
|
+
}
|
|
279
282
|
const auth = await validateLoginDTO(loginDTO, this.repository);
|
|
280
283
|
const accessToken = this.jwtService.generateAccessToken(auth.user, auth.role);
|
|
281
284
|
const expiresAt = (0, import_jwt_decode.jwtDecode)(accessToken).exp;
|
|
@@ -285,32 +288,14 @@ var _LoginUseCase = class _LoginUseCase {
|
|
|
285
288
|
__name(_LoginUseCase, "LoginUseCase");
|
|
286
289
|
var LoginUseCase = _LoginUseCase;
|
|
287
290
|
|
|
288
|
-
// src/application/useCase/LoginAdminUseCase.ts
|
|
289
|
-
var import_cca_core2 = require("cca-core");
|
|
290
|
-
var _LoginAdminUseCase = class _LoginAdminUseCase {
|
|
291
|
-
constructor(repository) {
|
|
292
|
-
this.repository = repository;
|
|
293
|
-
}
|
|
294
|
-
async initialize() {
|
|
295
|
-
await (0, import_cca_core2.validateRepository)(this.repository, (repo) => repo.getAll());
|
|
296
|
-
}
|
|
297
|
-
async execute(loginDTO, adminPassword) {
|
|
298
|
-
const auth = await validateLoginDTO(loginDTO, this.repository);
|
|
299
|
-
await validateAdminSecret(adminPassword);
|
|
300
|
-
return auth.user.id;
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
__name(_LoginAdminUseCase, "LoginAdminUseCase");
|
|
304
|
-
var LoginAdminUseCase = _LoginAdminUseCase;
|
|
305
|
-
|
|
306
291
|
// src/application/useCase/LogoutUseCase.ts
|
|
307
|
-
var
|
|
292
|
+
var import_cca_core2 = require("cca-core");
|
|
308
293
|
var _LogoutUseCase = class _LogoutUseCase {
|
|
309
294
|
constructor(repository) {
|
|
310
295
|
this.repository = repository;
|
|
311
296
|
}
|
|
312
297
|
async initialize() {
|
|
313
|
-
await (0,
|
|
298
|
+
await (0, import_cca_core2.validateRepository)(this.repository, (repo) => repo.getAll());
|
|
314
299
|
}
|
|
315
300
|
async execute(authId) {
|
|
316
301
|
try {
|
|
@@ -324,7 +309,7 @@ __name(_LogoutUseCase, "LogoutUseCase");
|
|
|
324
309
|
var LogoutUseCase = _LogoutUseCase;
|
|
325
310
|
|
|
326
311
|
// src/application/useCase/RegisterUseCase.ts
|
|
327
|
-
var
|
|
312
|
+
var import_cca_core3 = require("cca-core");
|
|
328
313
|
var bcrypt2 = __toESM(require("bcrypt"));
|
|
329
314
|
var import_cca_entities3 = require("cca-entities");
|
|
330
315
|
|
|
@@ -445,7 +430,7 @@ var _RegisterUseCase = class _RegisterUseCase {
|
|
|
445
430
|
this.SALT_ROUNDS = 10;
|
|
446
431
|
}
|
|
447
432
|
async initialize() {
|
|
448
|
-
await (0,
|
|
433
|
+
await (0, import_cca_core3.validateRepository)(this.repository, (repo) => repo.getAll());
|
|
449
434
|
}
|
|
450
435
|
async execute(email, name, password, role = import_cca_entities3.UserRole.GUEST, adminPassword) {
|
|
451
436
|
try {
|
|
@@ -502,14 +487,14 @@ __name(_RegisterUseCase, "RegisterUseCase");
|
|
|
502
487
|
var RegisterUseCase = _RegisterUseCase;
|
|
503
488
|
|
|
504
489
|
// src/application/useCase/RefreshTokenUseCase.ts
|
|
505
|
-
var
|
|
490
|
+
var import_cca_core4 = require("cca-core");
|
|
506
491
|
var _RefreshTokenUseCase = class _RefreshTokenUseCase {
|
|
507
492
|
constructor(repository, service) {
|
|
508
493
|
this.repository = repository;
|
|
509
494
|
this.service = service;
|
|
510
495
|
}
|
|
511
496
|
async initialize() {
|
|
512
|
-
await (0,
|
|
497
|
+
await (0, import_cca_core4.validateRepository)(this.repository, (repo) => repo.getAll());
|
|
513
498
|
}
|
|
514
499
|
async execute(refreshToken) {
|
|
515
500
|
try {
|
|
@@ -577,7 +562,7 @@ __name(_TwoFactorSetupUseCase, "TwoFactorSetupUseCase");
|
|
|
577
562
|
var TwoFactorSetupUseCase = _TwoFactorSetupUseCase;
|
|
578
563
|
|
|
579
564
|
// src/application/useCase/TwoFactorEnableUseCase.ts
|
|
580
|
-
var
|
|
565
|
+
var import_cca_core5 = require("cca-core");
|
|
581
566
|
var _TwoFactorEnableUseCase = class _TwoFactorEnableUseCase {
|
|
582
567
|
constructor(twoFactorService, authRepository) {
|
|
583
568
|
this.isInitialized = false;
|
|
@@ -588,7 +573,7 @@ var _TwoFactorEnableUseCase = class _TwoFactorEnableUseCase {
|
|
|
588
573
|
if (this.isInitialized) return;
|
|
589
574
|
await Promise.all([
|
|
590
575
|
this.twoFactorService.initialize(),
|
|
591
|
-
(0,
|
|
576
|
+
(0, import_cca_core5.validateRepository)(this.authRepository, (repo) => repo.getAll())
|
|
592
577
|
]);
|
|
593
578
|
this.isInitialized = true;
|
|
594
579
|
}
|
|
@@ -618,7 +603,7 @@ __name(_TwoFactorEnableUseCase, "TwoFactorEnableUseCase");
|
|
|
618
603
|
var TwoFactorEnableUseCase = _TwoFactorEnableUseCase;
|
|
619
604
|
|
|
620
605
|
// src/application/useCase/TwoFactorVerifyUseCase.ts
|
|
621
|
-
var
|
|
606
|
+
var import_cca_core6 = require("cca-core");
|
|
622
607
|
var import_cca_entities4 = require("cca-entities");
|
|
623
608
|
var _TwoFactorVerifyUseCase = class _TwoFactorVerifyUseCase {
|
|
624
609
|
constructor(twoFactorService, authRepository, jwtService) {
|
|
@@ -632,7 +617,7 @@ var _TwoFactorVerifyUseCase = class _TwoFactorVerifyUseCase {
|
|
|
632
617
|
await Promise.all([
|
|
633
618
|
this.twoFactorService.initialize(),
|
|
634
619
|
this.jwtService.initialize(),
|
|
635
|
-
(0,
|
|
620
|
+
(0, import_cca_core6.validateRepository)(this.authRepository, (repo) => repo.getAll())
|
|
636
621
|
]);
|
|
637
622
|
this.isInitialized = true;
|
|
638
623
|
}
|
|
@@ -697,7 +682,7 @@ __name(_TwoFactorVerifyUseCase, "TwoFactorVerifyUseCase");
|
|
|
697
682
|
var TwoFactorVerifyUseCase = _TwoFactorVerifyUseCase;
|
|
698
683
|
|
|
699
684
|
// src/application/useCase/TwoFactorDisableUseCase.ts
|
|
700
|
-
var
|
|
685
|
+
var import_cca_core7 = require("cca-core");
|
|
701
686
|
var _TwoFactorDisableUseCase = class _TwoFactorDisableUseCase {
|
|
702
687
|
constructor(twoFactorService, authRepository) {
|
|
703
688
|
this.isInitialized = false;
|
|
@@ -708,7 +693,7 @@ var _TwoFactorDisableUseCase = class _TwoFactorDisableUseCase {
|
|
|
708
693
|
if (this.isInitialized) return;
|
|
709
694
|
await Promise.all([
|
|
710
695
|
this.twoFactorService.initialize(),
|
|
711
|
-
(0,
|
|
696
|
+
(0, import_cca_core7.validateRepository)(this.authRepository, (repo) => repo.getAll())
|
|
712
697
|
]);
|
|
713
698
|
4;
|
|
714
699
|
this.isInitialized = true;
|
|
@@ -760,11 +745,11 @@ var MESSAGES = {
|
|
|
760
745
|
|
|
761
746
|
// src/presentation/controller/AuthController.ts
|
|
762
747
|
var _AuthController = class _AuthController {
|
|
763
|
-
constructor(loginUseCase,
|
|
748
|
+
constructor(loginUseCase, logoutUseCase, registerUseCase, refreshTokenUseCase, twoFactorSetupUseCase, twoFactorEnableUseCase, twoFactorVerifyUseCase, twoFactorDisableUseCase) {
|
|
764
749
|
this.login = /* @__PURE__ */ __name(async (req, res, next) => {
|
|
765
750
|
try {
|
|
766
751
|
const loginDTO = req.body;
|
|
767
|
-
const result = await this.loginUseCase.execute(loginDTO);
|
|
752
|
+
const result = await this.loginUseCase.execute(loginDTO, "", false);
|
|
768
753
|
const twoFactorEnabled = result.enabled ?? false;
|
|
769
754
|
const loginData = {
|
|
770
755
|
accessToken: result.accessToken,
|
|
@@ -791,7 +776,7 @@ var _AuthController = class _AuthController {
|
|
|
791
776
|
if (!adminPassword) {
|
|
792
777
|
throw new ForbiddenError("Admin password is required");
|
|
793
778
|
}
|
|
794
|
-
const result = await this.
|
|
779
|
+
const result = await this.loginUseCase.execute(loginDTO, adminPassword, true);
|
|
795
780
|
const adminLoginData = {
|
|
796
781
|
message: result,
|
|
797
782
|
auth: this.createAuthData(
|
|
@@ -946,7 +931,6 @@ var _AuthController = class _AuthController {
|
|
|
946
931
|
}
|
|
947
932
|
}, "disable2FA");
|
|
948
933
|
this.loginUseCase = loginUseCase;
|
|
949
|
-
this.adminLoginUseCase = adminLoginUseCase;
|
|
950
934
|
this.logoutUseCase = logoutUseCase;
|
|
951
935
|
this.registerUseCase = registerUseCase;
|
|
952
936
|
this.refreshTokenUseCase = refreshTokenUseCase;
|
|
@@ -1012,8 +996,8 @@ __name(_RequireComplete2FA, "RequireComplete2FA");
|
|
|
1012
996
|
var RequireComplete2FA = _RequireComplete2FA;
|
|
1013
997
|
|
|
1014
998
|
// src/infrastructure/repository/AuthRepository.ts
|
|
1015
|
-
var
|
|
1016
|
-
var _AuthRepository = class _AuthRepository extends
|
|
999
|
+
var import_cca_core8 = require("cca-core");
|
|
1000
|
+
var _AuthRepository = class _AuthRepository extends import_cca_core8.BaseRepository {
|
|
1017
1001
|
constructor(repository) {
|
|
1018
1002
|
super(repository);
|
|
1019
1003
|
}
|
|
@@ -1085,7 +1069,7 @@ var AuthRepository = _AuthRepository;
|
|
|
1085
1069
|
// src/infrastructure/services/JwtAuthService.ts
|
|
1086
1070
|
var jwt = __toESM(require("jsonwebtoken"));
|
|
1087
1071
|
var bcrypt3 = __toESM(require("bcrypt"));
|
|
1088
|
-
var
|
|
1072
|
+
var import_cca_core9 = require("cca-core");
|
|
1089
1073
|
var _JwtAuthService = class _JwtAuthService {
|
|
1090
1074
|
constructor(repository, config) {
|
|
1091
1075
|
this.repository = repository;
|
|
@@ -1103,7 +1087,7 @@ var _JwtAuthService = class _JwtAuthService {
|
|
|
1103
1087
|
this.validateConfiguration();
|
|
1104
1088
|
}
|
|
1105
1089
|
async initialize() {
|
|
1106
|
-
await (0,
|
|
1090
|
+
await (0, import_cca_core9.validateRepository)(this.repository, (repo) => repo.getAll());
|
|
1107
1091
|
}
|
|
1108
1092
|
validateConfiguration() {
|
|
1109
1093
|
if (!this.jwtConfig?.accessTokenSecret || !this.jwtConfig?.refreshTokenSecret) {
|
|
@@ -1255,7 +1239,7 @@ var TwoFactorService = _TwoFactorService;
|
|
|
1255
1239
|
|
|
1256
1240
|
// src/infrastructure/container/createAuthContainer.ts
|
|
1257
1241
|
async function createAuthContainer(database) {
|
|
1258
|
-
const container = new
|
|
1242
|
+
const container = new import_cca_core10.BaseContainer({ database });
|
|
1259
1243
|
const authRepository = new AuthRepository(
|
|
1260
1244
|
database.getRepository(import_cca_entities5.AuthEntity)
|
|
1261
1245
|
);
|
|
@@ -1267,9 +1251,6 @@ async function createAuthContainer(database) {
|
|
|
1267
1251
|
container.registerService("TwoFactorService", twoFactorService);
|
|
1268
1252
|
const requireComplete2FA = new RequireComplete2FA(jwtAuthService);
|
|
1269
1253
|
const loginUseCase = new LoginUseCase(authRepository, jwtAuthService);
|
|
1270
|
-
const loginAdminUseCase = new LoginAdminUseCase(
|
|
1271
|
-
authRepository
|
|
1272
|
-
);
|
|
1273
1254
|
const logoutUseCase = new LogoutUseCase(authRepository);
|
|
1274
1255
|
const registerUseCase = new RegisterUseCase(authRepository);
|
|
1275
1256
|
const refreshTokenUseCase = new RefreshTokenUseCase(
|
|
@@ -1285,7 +1266,6 @@ async function createAuthContainer(database) {
|
|
|
1285
1266
|
);
|
|
1286
1267
|
const twoFactorDisableUseCase = new TwoFactorDisableUseCase(twoFactorService, authRepository);
|
|
1287
1268
|
container.registerService("LoginUseCase", loginUseCase);
|
|
1288
|
-
container.registerService("LoginAdminUseCase", loginAdminUseCase);
|
|
1289
1269
|
container.registerService("LogoutUseCase", logoutUseCase);
|
|
1290
1270
|
container.registerService("RegisterUseCase", registerUseCase);
|
|
1291
1271
|
container.registerService("RefreshTokenUseCase", refreshTokenUseCase);
|
|
@@ -1295,7 +1275,6 @@ async function createAuthContainer(database) {
|
|
|
1295
1275
|
container.registerService("TwoFactorDisableUseCase", twoFactorDisableUseCase);
|
|
1296
1276
|
const authController = new AuthController(
|
|
1297
1277
|
loginUseCase,
|
|
1298
|
-
loginAdminUseCase,
|
|
1299
1278
|
logoutUseCase,
|
|
1300
1279
|
registerUseCase,
|
|
1301
1280
|
refreshTokenUseCase,
|