@flusys/nestjs-auth 3.0.0 → 4.0.0-rc

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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/cjs/config/index.js +1 -0
  3. package/cjs/config/message-keys.js +150 -0
  4. package/cjs/controllers/authentication.controller.js +9 -4
  5. package/cjs/controllers/branch.controller.js +1 -0
  6. package/cjs/controllers/company-selection.controller.js +3 -0
  7. package/cjs/controllers/company.controller.js +1 -0
  8. package/cjs/controllers/email-verification.controller.js +7 -2
  9. package/cjs/controllers/user-permission.controller.js +9 -1
  10. package/cjs/controllers/user.controller.js +16 -4
  11. package/cjs/dtos/authentication.dto.js +8 -0
  12. package/cjs/dtos/user-permission.dto.js +14 -0
  13. package/cjs/interceptors/set-token.interceptor.js +14 -5
  14. package/cjs/services/auth-config.service.js +9 -8
  15. package/cjs/services/auth-datasource.provider.js +7 -4
  16. package/cjs/services/auth-email.service.js +155 -45
  17. package/cjs/services/authentication.service.js +306 -71
  18. package/cjs/services/branch.service.js +1 -1
  19. package/cjs/services/company-selection-session.service.js +25 -6
  20. package/cjs/services/company.service.js +1 -1
  21. package/cjs/services/user-permission.service.js +52 -4
  22. package/cjs/services/user.service.js +122 -26
  23. package/cjs/strategies/jwt.strategy.js +18 -4
  24. package/config/index.d.ts +1 -0
  25. package/config/message-keys.d.ts +218 -0
  26. package/controllers/company-selection.controller.d.ts +2 -0
  27. package/controllers/user-permission.controller.d.ts +4 -0
  28. package/controllers/user.controller.d.ts +10 -0
  29. package/dtos/authentication.dto.d.ts +1 -0
  30. package/dtos/user-permission.dto.d.ts +2 -0
  31. package/entities/index.d.ts +10 -1
  32. package/fesm/config/index.js +1 -0
  33. package/fesm/config/message-keys.js +118 -0
  34. package/fesm/controllers/authentication.controller.js +9 -3
  35. package/fesm/controllers/branch.controller.js +1 -0
  36. package/fesm/controllers/company-selection.controller.js +3 -0
  37. package/fesm/controllers/company.controller.js +1 -0
  38. package/fesm/controllers/email-verification.controller.js +7 -2
  39. package/fesm/controllers/user-permission.controller.js +9 -1
  40. package/fesm/controllers/user.controller.js +16 -4
  41. package/fesm/dtos/authentication.dto.js +8 -0
  42. package/fesm/dtos/user-permission.dto.js +14 -0
  43. package/fesm/interceptors/set-token.interceptor.js +14 -4
  44. package/fesm/services/auth-config.service.js +10 -9
  45. package/fesm/services/auth-datasource.provider.js +7 -4
  46. package/fesm/services/auth-email.service.js +156 -45
  47. package/fesm/services/authentication.service.js +297 -61
  48. package/fesm/services/branch.service.js +1 -1
  49. package/fesm/services/company-selection-session.service.js +25 -6
  50. package/fesm/services/company.service.js +1 -1
  51. package/fesm/services/user-permission.service.js +52 -4
  52. package/fesm/services/user.service.js +122 -25
  53. package/fesm/strategies/jwt.strategy.js +18 -4
  54. package/interfaces/auth-module-options.interface.d.ts +2 -2
  55. package/interfaces/authentication.interface.d.ts +1 -0
  56. package/modules/auth.module.d.ts +2 -1
  57. package/package.json +3 -3
  58. package/services/auth-config.service.d.ts +0 -2
  59. package/services/auth-datasource.provider.d.ts +1 -3
  60. package/services/auth-email.service.d.ts +6 -3
  61. package/services/authentication.service.d.ts +5 -2
  62. package/services/branch.service.d.ts +2 -1
  63. package/services/user.service.d.ts +7 -7
@@ -89,7 +89,7 @@ let BranchService = class BranchService extends _classes.RequestScopedApiService
89
89
  return result;
90
90
  }
91
91
  constructor(cacheManager, utilsService, dataSourceProvider, authConfig){
92
- super('company_branch', null, cacheManager, utilsService, BranchService.name, true), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "authConfig", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.dataSourceProvider = dataSourceProvider, this.authConfig = authConfig;
92
+ super('company_branch', null, cacheManager, utilsService, BranchService.name, true, 'auth'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "authConfig", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.dataSourceProvider = dataSourceProvider, this.authConfig = authConfig;
93
93
  }
94
94
  };
95
95
  BranchService = _ts_decorate([
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "CompanySelectionSessionService", {
8
8
  return CompanySelectionSessionService;
9
9
  }
10
10
  });
11
+ const _nestjsshared = require("@flusys/nestjs-shared");
11
12
  const _classes = require("@flusys/nestjs-shared/classes");
12
13
  const _common = require("@nestjs/common");
13
14
  const _crypto = require("crypto");
@@ -41,9 +42,7 @@ function _ts_param(paramIndex, decorator) {
41
42
  }
42
43
  const SESSION_TTL_MS = 5 * 60 * 1000; // 5 minutes
43
44
  let CompanySelectionSessionService = class CompanySelectionSessionService {
44
- /**
45
- * Create a new session for company/branch selection
46
- */ async createSession(userId) {
45
+ async createSession(userId) {
47
46
  const sessionId = (0, _crypto.randomUUID)();
48
47
  const now = new Date();
49
48
  const expiresAt = new Date(now.getTime() + SESSION_TTL_MS);
@@ -68,9 +67,7 @@ let CompanySelectionSessionService = class CompanySelectionSessionService {
68
67
  }
69
68
  return session;
70
69
  }
71
- /**
72
- * Get and delete session (one-time use)
73
- */ async consumeSession(sessionId) {
70
+ async consumeSession(sessionId) {
74
71
  const session = await this.getSession(sessionId);
75
72
  if (session) {
76
73
  await this.deleteSession(sessionId);
@@ -92,6 +89,28 @@ let CompanySelectionSessionService = class CompanySelectionSessionService {
92
89
  this.cacheManager = cacheManager;
93
90
  }
94
91
  };
92
+ _ts_decorate([
93
+ (0, _nestjsshared.LogAction)({
94
+ action: 'session.create',
95
+ module: 'auth'
96
+ }),
97
+ _ts_metadata("design:type", Function),
98
+ _ts_metadata("design:paramtypes", [
99
+ String
100
+ ]),
101
+ _ts_metadata("design:returntype", Promise)
102
+ ], CompanySelectionSessionService.prototype, "createSession", null);
103
+ _ts_decorate([
104
+ (0, _nestjsshared.LogAction)({
105
+ action: 'session.consume',
106
+ module: 'auth'
107
+ }),
108
+ _ts_metadata("design:type", Function),
109
+ _ts_metadata("design:paramtypes", [
110
+ String
111
+ ]),
112
+ _ts_metadata("design:returntype", Promise)
113
+ ], CompanySelectionSessionService.prototype, "consumeSession", null);
95
114
  CompanySelectionSessionService = _ts_decorate([
96
115
  (0, _common.Injectable)(),
97
116
  _ts_param(0, (0, _common.Inject)('CACHE_INSTANCE')),
@@ -74,7 +74,7 @@ let CompanyService = class CompanyService extends _classes.RequestScopedApiServi
74
74
  };
75
75
  }
76
76
  constructor(cacheManager, utilsService, dataSourceProvider){
77
- super('company', null, cacheManager, utilsService, CompanyService.name, true), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "dataSourceProvider", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.dataSourceProvider = dataSourceProvider;
77
+ super('company', null, cacheManager, utilsService, CompanyService.name, true, 'auth'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "dataSourceProvider", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.dataSourceProvider = dataSourceProvider;
78
78
  }
79
79
  };
80
80
  CompanyService = _ts_decorate([
@@ -8,7 +8,9 @@ Object.defineProperty(exports, "UserPermissionService", {
8
8
  return UserPermissionService;
9
9
  }
10
10
  });
11
+ const _nestjsshared = require("@flusys/nestjs-shared");
11
12
  const _common = require("@nestjs/common");
13
+ const _config = require("../config");
12
14
  const _usercompanypermissionentity = require("../entities/user-company-permission.entity");
13
15
  const _authdatasourceprovider = require("./auth-datasource.provider");
14
16
  function _define_property(obj, key, value) {
@@ -72,7 +74,13 @@ let UserPermissionService = class UserPermissionService {
72
74
  }
73
75
  });
74
76
  if (existing) {
75
- throw new _common.ConflictException(`User already assigned to this ${typeName}`);
77
+ throw new _common.ConflictException({
78
+ message: `User already assigned to this ${typeName}`,
79
+ messageKey: _config.USER_PERMISSION_MESSAGES.ALREADY_ASSIGNED,
80
+ messageParams: {
81
+ type: typeName
82
+ }
83
+ });
76
84
  }
77
85
  try {
78
86
  await repository.save(repository.create({
@@ -82,8 +90,15 @@ let UserPermissionService = class UserPermissionService {
82
90
  metadata
83
91
  }));
84
92
  } catch (error) {
85
- if (error?.code === 'ER_DUP_ENTRY' || error?.message?.includes('Duplicate entry')) {
86
- throw new _common.ConflictException(`User already assigned to this ${typeName}. Please refresh and try again.`);
93
+ const err = error;
94
+ if (err?.code === 'ER_DUP_ENTRY' || String(err?.message).includes('Duplicate entry')) {
95
+ throw new _common.ConflictException({
96
+ message: `User already assigned to this ${typeName}. Please refresh and try again.`,
97
+ messageKey: _config.USER_PERMISSION_MESSAGES.ALREADY_ASSIGNED,
98
+ messageParams: {
99
+ type: typeName
100
+ }
101
+ });
87
102
  }
88
103
  throw error;
89
104
  }
@@ -99,7 +114,13 @@ let UserPermissionService = class UserPermissionService {
99
114
  }
100
115
  });
101
116
  if (!permission) {
102
- throw new _common.NotFoundException(`${typeName.charAt(0).toUpperCase() + typeName.slice(1)} permission not found`);
117
+ throw new _common.NotFoundException({
118
+ message: `${typeName.charAt(0).toUpperCase() + typeName.slice(1)} permission not found`,
119
+ messageKey: _config.USER_PERMISSION_MESSAGES.PERMISSION_NOT_FOUND,
120
+ messageParams: {
121
+ type: typeName.charAt(0).toUpperCase() + typeName.slice(1)
122
+ }
123
+ });
103
124
  }
104
125
  await repository.remove(permission);
105
126
  }
@@ -127,6 +148,33 @@ let UserPermissionService = class UserPermissionService {
127
148
  this.findUserCompanies = (userId)=>this.findUserPermissions(userId, _usercompanypermissionentity.PermissionType.COMPANY);
128
149
  }
129
150
  };
151
+ _ts_decorate([
152
+ (0, _nestjsshared.LogAction)({
153
+ action: 'user.assignPermission',
154
+ module: 'auth'
155
+ }),
156
+ _ts_metadata("design:type", Function),
157
+ _ts_metadata("design:paramtypes", [
158
+ String,
159
+ String,
160
+ typeof _usercompanypermissionentity.PermissionType === "undefined" ? Object : _usercompanypermissionentity.PermissionType,
161
+ typeof Record === "undefined" ? Object : Record
162
+ ]),
163
+ _ts_metadata("design:returntype", Promise)
164
+ ], UserPermissionService.prototype, "assignPermission", null);
165
+ _ts_decorate([
166
+ (0, _nestjsshared.LogAction)({
167
+ action: 'user.revokePermission',
168
+ module: 'auth'
169
+ }),
170
+ _ts_metadata("design:type", Function),
171
+ _ts_metadata("design:paramtypes", [
172
+ String,
173
+ String,
174
+ typeof _usercompanypermissionentity.PermissionType === "undefined" ? Object : _usercompanypermissionentity.PermissionType
175
+ ]),
176
+ _ts_metadata("design:returntype", Promise)
177
+ ], UserPermissionService.prototype, "revokePermission", null);
130
178
  UserPermissionService = _ts_decorate([
131
179
  (0, _common.Injectable)({
132
180
  scope: _common.Scope.REQUEST
@@ -9,13 +9,16 @@ Object.defineProperty(exports, "UserService", {
9
9
  }
10
10
  });
11
11
  const _classes = require("@flusys/nestjs-shared/classes");
12
+ const _nestjsshared = require("@flusys/nestjs-shared");
13
+ const _interfaces = require("@flusys/nestjs-shared/interfaces");
12
14
  const _modules = require("@flusys/nestjs-shared/modules");
13
- const _utils = require("@flusys/nestjs-shared/utils");
14
15
  const _common = require("@nestjs/common");
16
+ const _constants = require("@flusys/nestjs-shared/constants");
17
+ const _config = require("../config");
15
18
  const _bcrypt = /*#__PURE__*/ _interop_require_wildcard(require("bcrypt"));
16
19
  const _authconfigservice = require("./auth-config.service");
17
20
  const _authdatasourceprovider = require("./auth-datasource.provider");
18
- const _config = require("../config");
21
+ const _userdto = require("../dtos/user.dto");
19
22
  const _enums = require("../enums");
20
23
  const _userenricherinterface = require("../interfaces/user-enricher.interface");
21
24
  const _usercompanypermissionentity = require("../entities/user-company-permission.entity");
@@ -109,7 +112,10 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
109
112
  }
110
113
  async getUserForProfile(userId, user) {
111
114
  if (userId !== user.id) {
112
- throw new _common.ForbiddenException('Cannot access another user\'s profile');
115
+ throw new _common.ForbiddenException({
116
+ message: 'Cannot access another user\'s profile',
117
+ messageKey: _config.AUTH_MESSAGES.PROFILE_ACCESS_DENIED
118
+ });
113
119
  }
114
120
  await this.ensureRepositoryInitialized();
115
121
  const userEntity = await this.repository.findOne({
@@ -118,7 +124,10 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
118
124
  }
119
125
  });
120
126
  if (!userEntity) {
121
- throw new _common.NotFoundException('User not found');
127
+ throw new _common.NotFoundException({
128
+ message: 'User not found',
129
+ messageKey: _config.USER_MESSAGES.NOT_FOUND
130
+ });
122
131
  }
123
132
  return userEntity;
124
133
  }
@@ -156,7 +165,10 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
156
165
  }
157
166
  });
158
167
  if (!permission) {
159
- throw new _common.NotFoundException('User company permission not found');
168
+ throw new _common.NotFoundException({
169
+ message: 'User company permission not found',
170
+ messageKey: _config.USER_PERMISSION_MESSAGES.PERMISSION_NOT_FOUND
171
+ });
160
172
  }
161
173
  permission.isActive = isActive;
162
174
  await this.permissionRepository.save(permission);
@@ -286,7 +298,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
286
298
  async insert(dto, user) {
287
299
  const isCompanyFeatureEnabled = this.authConfig.isCompanyFeatureEnabled();
288
300
  if (!isCompanyFeatureEnabled || !this.dataSource || !user?.companyId || !this.permissionRepository) {
289
- return super.insert(dto, user);
301
+ return await super.insert(dto, user);
290
302
  }
291
303
  const queryRunner = this.dataSource.createQueryRunner();
292
304
  await queryRunner.connect();
@@ -335,10 +347,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
335
347
  return this.convertEntityToResponseDto(savedUser, false);
336
348
  } catch (error) {
337
349
  await queryRunner.rollbackTransaction();
338
- _utils.ErrorHandler.logError(this.logger, error, 'insert', {
339
- entity: this.entityName
340
- });
341
- _utils.ErrorHandler.rethrowError(error);
350
+ throw error;
342
351
  } finally{
343
352
  await queryRunner.release();
344
353
  }
@@ -385,10 +394,16 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
385
394
  async updateProfileSection(userId, sectionId, data, user) {
386
395
  const userEntity = await this.getUserForProfile(userId, user);
387
396
  if (!this.dataSource) {
388
- throw new _common.BadRequestException('DataSource not available');
397
+ throw new _common.BadRequestException({
398
+ message: 'DataSource not available',
399
+ messageKey: _constants.SYSTEM_MESSAGES.DATASOURCE_NOT_AVAILABLE
400
+ });
389
401
  }
390
402
  if (!this.userEnricher?.updateProfileSection) {
391
- throw new _common.BadRequestException('Profile sections not supported');
403
+ throw new _common.BadRequestException({
404
+ message: 'Profile sections not supported',
405
+ messageKey: _config.AUTH_MESSAGES.PROFILE_SECTIONS_NOT_SUPPORTED
406
+ });
392
407
  }
393
408
  const queryRunner = this.dataSource.createQueryRunner();
394
409
  await queryRunner.connect();
@@ -401,11 +416,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
401
416
  ]);
402
417
  } catch (error) {
403
418
  await queryRunner.rollbackTransaction();
404
- _utils.ErrorHandler.logError(this.logger, error, 'updateProfileSection', {
405
- entity: this.entityName,
406
- sectionId
407
- });
408
- _utils.ErrorHandler.rethrowError(error);
419
+ throw error;
409
420
  } finally{
410
421
  await queryRunner.release();
411
422
  }
@@ -420,7 +431,10 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
420
431
  async profile(dto, user) {
421
432
  await this.ensureRepositoryInitialized();
422
433
  if (!this.dataSource) {
423
- throw new _common.BadRequestException('DataSource not available');
434
+ throw new _common.BadRequestException({
435
+ message: 'DataSource not available',
436
+ messageKey: _constants.SYSTEM_MESSAGES.DATASOURCE_NOT_AVAILABLE
437
+ });
424
438
  }
425
439
  const userId = dto.id ?? user.id;
426
440
  if (dto.extras && this.userEnricher?.validateProfileExtras) {
@@ -436,17 +450,26 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
436
450
  }
437
451
  });
438
452
  if (!findUser) {
439
- throw new _common.NotFoundException('User not found');
453
+ throw new _common.NotFoundException({
454
+ message: 'User not found',
455
+ messageKey: _config.USER_MESSAGES.NOT_FOUND
456
+ });
440
457
  }
441
458
  if (dto.password) {
442
459
  const isOwnProfile = !dto.id || dto.id === user.id;
443
460
  if (isOwnProfile) {
444
461
  if (!dto.oldPassword) {
445
- throw new _common.BadRequestException('Current password is required to change your password');
462
+ throw new _common.BadRequestException({
463
+ message: 'Current password is required to change your password',
464
+ messageKey: _config.AUTH_MESSAGES.PASSWORD_CHANGE_CURRENT_REQUIRED
465
+ });
446
466
  }
447
467
  const isPasswordValid = await _bcrypt.compare(dto.oldPassword, findUser.password);
448
468
  if (!isPasswordValid) {
449
- throw new _common.BadRequestException('Current password is incorrect');
469
+ throw new _common.BadRequestException({
470
+ message: 'Current password is incorrect',
471
+ messageKey: _config.AUTH_MESSAGES.PASSWORD_CHANGE_INVALID_CURRENT
472
+ });
450
473
  }
451
474
  }
452
475
  findUser.password = await _bcrypt.hash(dto.password, _config.BCRYPT_SALT_ROUNDS);
@@ -464,18 +487,91 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
464
487
  return findUser.id;
465
488
  } catch (error) {
466
489
  await queryRunner.rollbackTransaction();
467
- _utils.ErrorHandler.logError(this.logger, error, 'profile', {
468
- entity: this.entityName
469
- });
470
- _utils.ErrorHandler.rethrowError(error);
490
+ throw error;
471
491
  } finally{
472
492
  await queryRunner.release();
473
493
  }
474
494
  }
475
495
  constructor(cacheManager, utilsService, dataSourceProvider, authConfig, userEnricher){
476
- super('user', null, cacheManager, utilsService, UserService.name, true), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "authConfig", void 0), _define_property(this, "userEnricher", void 0), _define_property(this, "permissionRepository", void 0), _define_property(this, "dataSource", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.dataSourceProvider = dataSourceProvider, this.authConfig = authConfig, this.userEnricher = userEnricher;
496
+ super('user', null, cacheManager, utilsService, UserService.name, true, 'auth'), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "dataSourceProvider", void 0), _define_property(this, "authConfig", void 0), _define_property(this, "userEnricher", void 0), _define_property(this, "permissionRepository", void 0), _define_property(this, "dataSource", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.dataSourceProvider = dataSourceProvider, this.authConfig = authConfig, this.userEnricher = userEnricher;
477
497
  }
478
498
  };
499
+ _ts_decorate([
500
+ (0, _nestjsshared.LogAction)({
501
+ action: 'user.verifyEmail',
502
+ module: 'auth'
503
+ }),
504
+ _ts_metadata("design:type", Function),
505
+ _ts_metadata("design:paramtypes", [
506
+ String
507
+ ]),
508
+ _ts_metadata("design:returntype", Promise)
509
+ ], UserService.prototype, "verifyEmail", null);
510
+ _ts_decorate([
511
+ (0, _nestjsshared.LogAction)({
512
+ action: 'user.verifyPhone',
513
+ module: 'auth'
514
+ }),
515
+ _ts_metadata("design:type", Function),
516
+ _ts_metadata("design:paramtypes", [
517
+ String
518
+ ]),
519
+ _ts_metadata("design:returntype", Promise)
520
+ ], UserService.prototype, "verifyPhone", null);
521
+ _ts_decorate([
522
+ (0, _nestjsshared.LogAction)({
523
+ action: 'user.updateStatus',
524
+ module: 'auth'
525
+ }),
526
+ _ts_metadata("design:type", Function),
527
+ _ts_metadata("design:paramtypes", [
528
+ String,
529
+ Boolean,
530
+ Object
531
+ ]),
532
+ _ts_metadata("design:returntype", Promise)
533
+ ], UserService.prototype, "updateStatus", null);
534
+ _ts_decorate([
535
+ (0, _nestjsshared.LogAction)({
536
+ action: 'user.create',
537
+ module: 'auth',
538
+ includeParams: false
539
+ }),
540
+ _ts_metadata("design:type", Function),
541
+ _ts_metadata("design:paramtypes", [
542
+ typeof _userdto.CreateUserDto === "undefined" ? Object : _userdto.CreateUserDto,
543
+ Object
544
+ ]),
545
+ _ts_metadata("design:returntype", Promise)
546
+ ], UserService.prototype, "insert", null);
547
+ _ts_decorate([
548
+ (0, _nestjsshared.LogAction)({
549
+ action: 'user.updateProfileSection',
550
+ module: 'auth',
551
+ includeParams: false
552
+ }),
553
+ _ts_metadata("design:type", Function),
554
+ _ts_metadata("design:paramtypes", [
555
+ String,
556
+ String,
557
+ typeof Record === "undefined" ? Object : Record,
558
+ typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
559
+ ]),
560
+ _ts_metadata("design:returntype", Promise)
561
+ ], UserService.prototype, "updateProfileSection", null);
562
+ _ts_decorate([
563
+ (0, _nestjsshared.LogAction)({
564
+ action: 'user.updateProfile',
565
+ module: 'auth',
566
+ includeParams: false
567
+ }),
568
+ _ts_metadata("design:type", Function),
569
+ _ts_metadata("design:paramtypes", [
570
+ Object,
571
+ typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
572
+ ]),
573
+ _ts_metadata("design:returntype", Promise)
574
+ ], UserService.prototype, "profile", null);
479
575
  UserService = _ts_decorate([
480
576
  (0, _common.Injectable)({
481
577
  scope: _common.Scope.REQUEST
@@ -8,7 +8,9 @@ Object.defineProperty(exports, "JwtStrategy", {
8
8
  return JwtStrategy;
9
9
  }
10
10
  });
11
+ const _constants = require("@flusys/nestjs-shared/constants");
11
12
  const _common = require("@nestjs/common");
13
+ const _config = require("../config");
12
14
  const _core = require("@nestjs/core");
13
15
  const _passport = require("@nestjs/passport");
14
16
  const _passportjwt = require("passport-jwt");
@@ -52,7 +54,10 @@ let JwtStrategy = class JwtStrategy extends (0, _passport.PassportStrategy)(_pas
52
54
  }
53
55
  });
54
56
  if (!user) {
55
- throw new _common.UnauthorizedException('User not found or inactive');
57
+ throw new _common.UnauthorizedException({
58
+ message: 'User not found or inactive',
59
+ messageKey: _config.USER_MESSAGES.NOT_FOUND
60
+ });
56
61
  }
57
62
  return this.buildUserInfo(payload);
58
63
  }
@@ -65,9 +70,15 @@ let JwtStrategy = class JwtStrategy extends (0, _passport.PassportStrategy)(_pas
65
70
  return provider.getRepository(_userentity.User);
66
71
  }
67
72
  } catch {
68
- throw new _common.UnauthorizedException('Unable to access user data');
73
+ throw new _common.UnauthorizedException({
74
+ message: 'Unable to access user data',
75
+ messageKey: _constants.SYSTEM_MESSAGES.SERVICE_NOT_AVAILABLE
76
+ });
69
77
  }
70
- throw new _common.UnauthorizedException('User repository not available');
78
+ throw new _common.UnauthorizedException({
79
+ message: 'User repository not available',
80
+ messageKey: _constants.SYSTEM_MESSAGES.REPOSITORY_NOT_AVAILABLE
81
+ });
71
82
  }
72
83
  async checkTokenRevocation(payload) {
73
84
  if (!payload.iat) return;
@@ -76,7 +87,10 @@ let JwtStrategy = class JwtStrategy extends (0, _passport.PassportStrategy)(_pas
76
87
  strict: false
77
88
  });
78
89
  if (authService && await authService.isTokenRevoked(payload.id, payload.iat)) {
79
- throw new _common.UnauthorizedException('Token has been revoked');
90
+ throw new _common.UnauthorizedException({
91
+ message: 'Token has been revoked',
92
+ messageKey: _config.AUTH_MESSAGES.TOKEN_REVOKED
93
+ });
80
94
  }
81
95
  } catch (err) {
82
96
  if (err instanceof _common.UnauthorizedException) throw err;
package/config/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './auth.constants';
2
+ export * from './message-keys';