@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
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Authentication Package Guide
2
2
 
3
3
  > **Package:** `@flusys/nestjs-auth`
4
- > **Version:** 3.0.0
4
+ > **Version:** 3.0.1
5
5
  > **Type:** Authentication system with JWT, email verification, multi-tenant, and company/branch support
6
6
 
7
7
  ## Table of Contents
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  _export_star(require("./auth.constants"), exports);
6
+ _export_star(require("./message-keys"), exports);
6
7
  function _export_star(from, to) {
7
8
  Object.keys(from).forEach(function(k) {
8
9
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,150 @@
1
+ // ==================== AUTH MODULE MESSAGE KEYS ====================
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: Object.getOwnPropertyDescriptor(all, name).get
10
+ });
11
+ }
12
+ _export(exports, {
13
+ get AUTH_MESSAGES () {
14
+ return AUTH_MESSAGES;
15
+ },
16
+ get AUTH_MODULE_MESSAGES () {
17
+ return AUTH_MODULE_MESSAGES;
18
+ },
19
+ get BRANCH_MESSAGES () {
20
+ return BRANCH_MESSAGES;
21
+ },
22
+ get COMPANY_MESSAGES () {
23
+ return COMPANY_MESSAGES;
24
+ },
25
+ get EMAIL_VERIFICATION_MESSAGES () {
26
+ return EMAIL_VERIFICATION_MESSAGES;
27
+ },
28
+ get USER_MESSAGES () {
29
+ return USER_MESSAGES;
30
+ },
31
+ get USER_PERMISSION_MESSAGES () {
32
+ return USER_PERMISSION_MESSAGES;
33
+ }
34
+ });
35
+ const AUTH_MESSAGES = {
36
+ LOGIN_SUCCESS: 'auth.login.success',
37
+ LOGIN_FAILED: 'auth.login.failed',
38
+ LOGIN_INVALID_CREDENTIALS: 'auth.login.invalid.credentials',
39
+ LOGIN_EMAIL_NOT_VERIFIED: 'auth.login.email.not.verified',
40
+ LOGIN_REQUIRES_SELECTION: 'auth.login.requires.selection',
41
+ LOGIN_ACCOUNT_DEACTIVATED: 'auth.login.account.deactivated',
42
+ LOGOUT_SUCCESS: 'auth.logout.success',
43
+ REGISTER_SUCCESS: 'auth.register.success',
44
+ REGISTER_FAILED: 'auth.register.failed',
45
+ REGISTER_EMAIL_EXISTS: 'auth.register.email.exists',
46
+ REGISTER_COMPANY_ALREADY_ASSIGNED: 'auth.register.company.already.assigned',
47
+ PASSWORD_CHANGE_SUCCESS: 'auth.password.change.success',
48
+ PASSWORD_CHANGE_FAILED: 'auth.password.change.failed',
49
+ PASSWORD_CHANGE_INVALID_CURRENT: 'auth.password.change.invalid.current',
50
+ PASSWORD_CHANGE_CURRENT_REQUIRED: 'auth.password.change.current.required',
51
+ PASSWORD_RESET_EMAIL_SENT: 'auth.password.reset.email.sent',
52
+ PASSWORD_RESET_SUCCESS: 'auth.password.reset.success',
53
+ PASSWORD_RESET_FAILED: 'auth.password.reset.failed',
54
+ TOKEN_REFRESH_SUCCESS: 'auth.token.refresh.success',
55
+ TOKEN_REQUIRED: 'auth.token.required',
56
+ TOKEN_INVALID: 'auth.token.invalid',
57
+ TOKEN_EXPIRED: 'auth.token.expired',
58
+ TOKEN_REVOKED: 'auth.token.revoked',
59
+ TOKEN_TOO_LARGE: 'auth.token.too.large',
60
+ COMPANY_SELECT_SUCCESS: 'auth.company.select.success',
61
+ COMPANY_SWITCH_SUCCESS: 'auth.company.switch.success',
62
+ COMPANY_LIST_SUCCESS: 'auth.company.list.success',
63
+ COMPANY_NO_ACCESS: 'auth.company.no.access',
64
+ COMPANY_NOT_FOUND: 'auth.company.not.found',
65
+ COMPANY_REQUIRED: 'auth.company.required',
66
+ COMPANY_FEATURE_NOT_ENABLED: 'auth.company.feature.not.enabled',
67
+ BRANCH_LIST_SUCCESS: 'auth.branch.list.success',
68
+ BRANCH_NO_ACCESS: 'auth.branch.no.access',
69
+ BRANCH_NOT_FOUND: 'auth.branch.not.found',
70
+ ME_SUCCESS: 'auth.me.success',
71
+ EMAIL_NOT_CONFIGURED: 'auth.email.not.configured',
72
+ EMAIL_SEND_FAILED: 'auth.email.send.failed',
73
+ SESSION_INVALID: 'auth.session.invalid',
74
+ SESSION_NOT_AVAILABLE: 'auth.session.not.available',
75
+ PROFILE_ACCESS_DENIED: 'auth.profile.access.denied',
76
+ PROFILE_SECTIONS_NOT_SUPPORTED: 'auth.profile.sections.not.supported',
77
+ LOGOUT_SERVICE_UNAVAILABLE: 'auth.logout.service.unavailable',
78
+ PASSWORD_RESET_TOKEN_EXPIRED: 'auth.password.reset.token.expired',
79
+ PASSWORD_RESET_TOKEN_USED: 'auth.password.reset.token.used'
80
+ };
81
+ const EMAIL_VERIFICATION_MESSAGES = {
82
+ VERIFICATION_SENT: 'email.verification.sent',
83
+ VERIFICATION_SUCCESS: 'email.verification.success',
84
+ VERIFICATION_FAILED: 'email.verification.failed',
85
+ VERIFICATION_TOKEN_INVALID: 'email.verification.token.invalid',
86
+ VERIFICATION_TOKEN_EXPIRED: 'email.verification.token.expired',
87
+ VERIFICATION_NOT_ENABLED: 'email.verification.not.enabled',
88
+ RESEND_SUCCESS: 'email.verification.resend.success',
89
+ RESEND_THROTTLED: 'email.verification.resend.throttled'
90
+ };
91
+ const USER_MESSAGES = {
92
+ CREATE_SUCCESS: 'user.create.success',
93
+ CREATE_MANY_SUCCESS: 'user.create.many.success',
94
+ GET_SUCCESS: 'user.get.success',
95
+ GET_ALL_SUCCESS: 'user.get.all.success',
96
+ UPDATE_SUCCESS: 'user.update.success',
97
+ UPDATE_MANY_SUCCESS: 'user.update.many.success',
98
+ DELETE_SUCCESS: 'user.delete.success',
99
+ RESTORE_SUCCESS: 'user.restore.success',
100
+ NOT_FOUND: 'user.not.found',
101
+ PROFILE_SUCCESS: 'user.profile.success',
102
+ PROFILE_UPDATE_SUCCESS: 'user.profile.update.success',
103
+ PROFILE_EXTRAS_SUCCESS: 'user.profile.extras.success',
104
+ PROFILE_SECTIONS_SUCCESS: 'user.profile.sections.success',
105
+ PROFILE_SECTION_DATA_SUCCESS: 'user.profile.section.data.success',
106
+ PROFILE_SECTION_UPDATE_SUCCESS: 'user.profile.section.update.success',
107
+ PROFILE_COMPLETION_SUCCESS: 'user.profile.completion.success',
108
+ EMAIL_VERIFY_SUCCESS: 'user.email.verify.success',
109
+ PHONE_VERIFY_SUCCESS: 'user.phone.verify.success',
110
+ STATUS_UPDATE_SUCCESS: 'user.status.update.success'
111
+ };
112
+ const COMPANY_MESSAGES = {
113
+ CREATE_SUCCESS: 'company.create.success',
114
+ CREATE_MANY_SUCCESS: 'company.create.many.success',
115
+ GET_SUCCESS: 'company.get.success',
116
+ GET_ALL_SUCCESS: 'company.get.all.success',
117
+ UPDATE_SUCCESS: 'company.update.success',
118
+ UPDATE_MANY_SUCCESS: 'company.update.many.success',
119
+ DELETE_SUCCESS: 'company.delete.success',
120
+ RESTORE_SUCCESS: 'company.restore.success',
121
+ NOT_FOUND: 'company.not.found'
122
+ };
123
+ const BRANCH_MESSAGES = {
124
+ CREATE_SUCCESS: 'branch.create.success',
125
+ CREATE_MANY_SUCCESS: 'branch.create.many.success',
126
+ GET_SUCCESS: 'branch.get.success',
127
+ GET_ALL_SUCCESS: 'branch.get.all.success',
128
+ UPDATE_SUCCESS: 'branch.update.success',
129
+ UPDATE_MANY_SUCCESS: 'branch.update.many.success',
130
+ DELETE_SUCCESS: 'branch.delete.success',
131
+ RESTORE_SUCCESS: 'branch.restore.success',
132
+ NOT_FOUND: 'branch.not.found'
133
+ };
134
+ const USER_PERMISSION_MESSAGES = {
135
+ COMPANY_ASSIGN_SUCCESS: 'user.permission.company.assign.success',
136
+ COMPANY_LIST_SUCCESS: 'user.permission.company.list.success',
137
+ BRANCH_ASSIGN_SUCCESS: 'user.permission.branch.assign.success',
138
+ BRANCH_LIST_SUCCESS: 'user.permission.branch.list.success',
139
+ BATCH_SUCCESS: 'user.permission.batch.success',
140
+ ALREADY_ASSIGNED: 'user.permission.already.assigned',
141
+ PERMISSION_NOT_FOUND: 'user.permission.not.found'
142
+ };
143
+ const AUTH_MODULE_MESSAGES = {
144
+ AUTH: AUTH_MESSAGES,
145
+ EMAIL_VERIFICATION: EMAIL_VERIFICATION_MESSAGES,
146
+ USER: USER_MESSAGES,
147
+ COMPANY: COMPANY_MESSAGES,
148
+ BRANCH: BRANCH_MESSAGES,
149
+ USER_PERMISSION: USER_PERMISSION_MESSAGES
150
+ };
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "AuthenticationController", {
8
8
  return AuthenticationController;
9
9
  }
10
10
  });
11
+ const _config = require("../config");
11
12
  const _decorators = require("@flusys/nestjs-shared/decorators");
12
13
  const _dtos = require("@flusys/nestjs-shared/dtos");
13
14
  const _guards = require("@flusys/nestjs-shared/guards");
@@ -16,7 +17,6 @@ const _common = require("@nestjs/common");
16
17
  const _swagger = require("@nestjs/swagger");
17
18
  const _throttler = require("@nestjs/throttler");
18
19
  const _express = require("express");
19
- const _config = require("../config");
20
20
  const _authenticationdto = require("../dtos/authentication.dto");
21
21
  const _cleartokeninterceptor = require("../interceptors/clear-token.interceptor");
22
22
  const _settokeninterceptor = require("../interceptors/set-token.interceptor");
@@ -78,7 +78,10 @@ let AuthenticationController = class AuthenticationController {
78
78
  // Always check cookie first, then body - handles Browser, SSR, and Mobile/API
79
79
  const refreshToken = req.cookies?.[cookieName] || refreshTokenDto.refreshToken;
80
80
  if (!refreshToken) {
81
- throw new _common.UnauthorizedException('Refresh token is required');
81
+ throw new _common.UnauthorizedException({
82
+ message: 'Refresh token is required',
83
+ messageKey: _config.AUTH_MESSAGES.TOKEN_REQUIRED
84
+ });
82
85
  }
83
86
  return this.authService.refreshToken(refreshToken);
84
87
  }
@@ -89,14 +92,16 @@ let AuthenticationController = class AuthenticationController {
89
92
  await this.authService.logout(userId);
90
93
  return {
91
94
  success: true,
92
- message: 'Logged out successfully'
95
+ message: 'Logged out successfully',
96
+ messageKey: _config.AUTH_MESSAGES.LOGOUT_SUCCESS
93
97
  };
94
98
  }
95
99
  async changePassword(userId, dto) {
96
100
  await this.authService.changePassword(userId, dto.currentPassword, dto.newPassword);
97
101
  return {
98
102
  success: true,
99
- message: 'Password changed successfully'
103
+ message: 'Password changed successfully',
104
+ messageKey: _config.AUTH_MESSAGES.PASSWORD_CHANGE_SUCCESS
100
105
  };
101
106
  }
102
107
  constructor(authService, authConfig){
@@ -41,6 +41,7 @@ function _ts_param(paramIndex, decorator) {
41
41
  };
42
42
  }
43
43
  let BranchController = class BranchController extends (0, _classes.createApiController)(_companybranchdto.CreateCompanyBranchDto, _companybranchdto.UpdateCompanyBranchDto, _companybranchdto.CompanyBranchResponseDto, {
44
+ entityName: 'branch',
44
45
  security: {
45
46
  insert: {
46
47
  level: 'permission',
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "CompanySelectionController", {
8
8
  return CompanySelectionController;
9
9
  }
10
10
  });
11
+ const _config = require("../config");
11
12
  const _decorators = require("@flusys/nestjs-shared/decorators");
12
13
  const _common = require("@nestjs/common");
13
14
  const _swagger = require("@nestjs/swagger");
@@ -54,6 +55,7 @@ let CompanySelectionController = class CompanySelectionController {
54
55
  return {
55
56
  success: true,
56
57
  message: 'User companies retrieved successfully',
58
+ messageKey: _config.AUTH_MESSAGES.COMPANY_LIST_SUCCESS,
57
59
  data: companies
58
60
  };
59
61
  }
@@ -62,6 +64,7 @@ let CompanySelectionController = class CompanySelectionController {
62
64
  return {
63
65
  success: true,
64
66
  message: 'Company branches retrieved successfully',
67
+ messageKey: _config.AUTH_MESSAGES.BRANCH_LIST_SUCCESS,
65
68
  data: branches
66
69
  };
67
70
  }
@@ -41,6 +41,7 @@ function _ts_param(paramIndex, decorator) {
41
41
  };
42
42
  }
43
43
  let CompanyController = class CompanyController extends (0, _classes.createApiController)(_companydto.CreateCompanyDto, _companydto.UpdateCompanyDto, _companydto.CompanyResponseDto, {
44
+ entityName: 'company',
44
45
  security: {
45
46
  insert: {
46
47
  level: 'permission',
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "EmailVerificationController", {
8
8
  return EmailVerificationController;
9
9
  }
10
10
  });
11
+ const _config = require("../config");
11
12
  const _dtos = require("@flusys/nestjs-shared/dtos");
12
13
  const _common = require("@nestjs/common");
13
14
  const _swagger = require("@nestjs/swagger");
@@ -49,7 +50,10 @@ function _ts_param(paramIndex, decorator) {
49
50
  let EmailVerificationController = class EmailVerificationController {
50
51
  ensureEmailVerificationEnabled() {
51
52
  if (!this.dataSourceProvider.isEmailVerificationEnabled()) {
52
- throw new _common.BadRequestException('Email verification is not enabled for this tenant');
53
+ throw new _common.BadRequestException({
54
+ message: 'Email verification is not enabled for this tenant',
55
+ messageKey: _config.EMAIL_VERIFICATION_MESSAGES.VERIFICATION_NOT_ENABLED
56
+ });
53
57
  }
54
58
  }
55
59
  buildAuthUrl(req, path) {
@@ -76,7 +80,8 @@ let EmailVerificationController = class EmailVerificationController {
76
80
  }
77
81
  return {
78
82
  success: true,
79
- message: result.message
83
+ message: result.message,
84
+ messageKey: result.messageKey
80
85
  };
81
86
  }
82
87
  constructor(authService, authEmailService, authConfig, dataSourceProvider){
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "UserPermissionController", {
9
9
  }
10
10
  });
11
11
  const _nestjsshared = require("@flusys/nestjs-shared");
12
+ const _config = require("../config");
12
13
  const _common = require("@nestjs/common");
13
14
  const _swagger = require("@nestjs/swagger");
14
15
  const _userpermissiondto = require("../dtos/user-permission.dto");
@@ -50,6 +51,7 @@ let UserPermissionController = class UserPermissionController {
50
51
  return {
51
52
  success: true,
52
53
  message: 'User companies retrieved successfully',
54
+ messageKey: _config.USER_PERMISSION_MESSAGES.COMPANY_LIST_SUCCESS,
53
55
  data: permissions.map((p)=>({
54
56
  id: p.id,
55
57
  userId: p.userId,
@@ -67,6 +69,7 @@ let UserPermissionController = class UserPermissionController {
67
69
  return {
68
70
  success: true,
69
71
  message: 'User branches retrieved successfully',
72
+ messageKey: _config.USER_PERMISSION_MESSAGES.BRANCH_LIST_SUCCESS,
70
73
  data: permissions.map((p)=>({
71
74
  id: p.id,
72
75
  userId: p.userId,
@@ -90,7 +93,12 @@ let UserPermissionController = class UserPermissionController {
90
93
  }
91
94
  return {
92
95
  success: true,
93
- message: `Processed ${added} additions and ${removed} removals`
96
+ message: `Processed ${added} additions and ${removed} removals`,
97
+ messageKey: _config.USER_PERMISSION_MESSAGES.BATCH_SUCCESS,
98
+ messageVariables: {
99
+ added,
100
+ removed
101
+ }
94
102
  };
95
103
  }
96
104
  constructor(permissionService){
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "UserController", {
9
9
  }
10
10
  });
11
11
  const _classes = require("@flusys/nestjs-shared/classes");
12
+ const _config = require("../config");
12
13
  const _decorators = require("@flusys/nestjs-shared/decorators");
13
14
  const _guards = require("@flusys/nestjs-shared/guards");
14
15
  const _interfaces = require("@flusys/nestjs-shared/interfaces");
@@ -44,6 +45,7 @@ function _ts_param(paramIndex, decorator) {
44
45
  };
45
46
  }
46
47
  let UserController = class UserController extends (0, _classes.createApiController)(_userdto.CreateUserDto, _userdto.UpdateUserDto, _userdto.UserResponseDto, {
48
+ entityName: 'user',
47
49
  security: {
48
50
  insert: {
49
51
  level: 'permission',
@@ -93,6 +95,8 @@ let UserController = class UserController extends (0, _classes.createApiControll
93
95
  const data = await this.service.getProfileWithExtras(id, user);
94
96
  return {
95
97
  success: true,
98
+ message: 'Profile extras retrieved successfully',
99
+ messageKey: _config.USER_MESSAGES.PROFILE_EXTRAS_SUCCESS,
96
100
  data
97
101
  };
98
102
  }
@@ -100,21 +104,24 @@ let UserController = class UserController extends (0, _classes.createApiControll
100
104
  await this.service.verifyEmail(id);
101
105
  return {
102
106
  success: true,
103
- message: 'Email verified successfully'
107
+ message: 'Email verified successfully',
108
+ messageKey: _config.USER_MESSAGES.EMAIL_VERIFY_SUCCESS
104
109
  };
105
110
  }
106
111
  async verifyPhone(id) {
107
112
  await this.service.verifyPhone(id);
108
113
  return {
109
114
  success: true,
110
- message: 'Phone verified successfully'
115
+ message: 'Phone verified successfully',
116
+ messageKey: _config.USER_MESSAGES.PHONE_VERIFY_SUCCESS
111
117
  };
112
118
  }
113
119
  async updateStatus(id, isActive, user) {
114
120
  await this.service.updateStatus(id, isActive, user);
115
121
  return {
116
122
  success: true,
117
- message: 'Status updated successfully'
123
+ message: 'Status updated successfully',
124
+ messageKey: _config.USER_MESSAGES.STATUS_UPDATE_SUCCESS
118
125
  };
119
126
  }
120
127
  async profile(dto, user) {
@@ -122,6 +129,7 @@ let UserController = class UserController extends (0, _classes.createApiControll
122
129
  return {
123
130
  success: true,
124
131
  message: 'Profile updated successfully',
132
+ messageKey: _config.USER_MESSAGES.PROFILE_UPDATE_SUCCESS,
125
133
  data
126
134
  };
127
135
  }
@@ -130,6 +138,7 @@ let UserController = class UserController extends (0, _classes.createApiControll
130
138
  return {
131
139
  success: true,
132
140
  message: 'Profile sections retrieved successfully',
141
+ messageKey: _config.USER_MESSAGES.PROFILE_SECTIONS_SUCCESS,
133
142
  data: sections
134
143
  };
135
144
  }
@@ -138,6 +147,7 @@ let UserController = class UserController extends (0, _classes.createApiControll
138
147
  return {
139
148
  success: true,
140
149
  message: 'Profile section data retrieved successfully',
150
+ messageKey: _config.USER_MESSAGES.PROFILE_SECTION_DATA_SUCCESS,
141
151
  data
142
152
  };
143
153
  }
@@ -145,7 +155,8 @@ let UserController = class UserController extends (0, _classes.createApiControll
145
155
  await this.service.updateProfileSection(id, sectionId, data, user);
146
156
  return {
147
157
  success: true,
148
- message: 'Section updated successfully'
158
+ message: 'Section updated successfully',
159
+ messageKey: _config.USER_MESSAGES.PROFILE_SECTION_UPDATE_SUCCESS
149
160
  };
150
161
  }
151
162
  async getProfileCompletion(id, user) {
@@ -153,6 +164,7 @@ let UserController = class UserController extends (0, _classes.createApiControll
153
164
  return {
154
165
  success: true,
155
166
  message: 'Profile completion retrieved successfully',
167
+ messageKey: _config.USER_MESSAGES.PROFILE_COMPLETION_SUCCESS,
156
168
  data: {
157
169
  completionPercentage: percentage
158
170
  }
@@ -685,6 +685,7 @@ let LoginResponseRequiresEmailVerificationDto = class LoginResponseRequiresEmail
685
685
  _define_property(this, "requiresEmailVerification", void 0);
686
686
  _define_property(this, "email", void 0);
687
687
  _define_property(this, "message", void 0);
688
+ _define_property(this, "messageKey", void 0);
688
689
  }
689
690
  };
690
691
  _ts_decorate([
@@ -705,6 +706,13 @@ _ts_decorate([
705
706
  }),
706
707
  _ts_metadata("design:type", String)
707
708
  ], LoginResponseRequiresEmailVerificationDto.prototype, "message", void 0);
709
+ _ts_decorate([
710
+ (0, _swagger.ApiProperty)({
711
+ example: 'auth.login.email.not.verified',
712
+ description: 'Translation key for localization'
713
+ }),
714
+ _ts_metadata("design:type", String)
715
+ ], LoginResponseRequiresEmailVerificationDto.prototype, "messageKey", void 0);
708
716
  let ForgotPasswordDto = class ForgotPasswordDto {
709
717
  constructor(){
710
718
  _define_property(this, "email", void 0);
@@ -256,6 +256,7 @@ let UserCompaniesResponseDto = class UserCompaniesResponseDto {
256
256
  constructor(){
257
257
  _define_property(this, "success", void 0);
258
258
  _define_property(this, "message", void 0);
259
+ _define_property(this, "messageKey", void 0);
259
260
  _define_property(this, "data", void 0);
260
261
  }
261
262
  };
@@ -271,6 +272,12 @@ _ts_decorate([
271
272
  }),
272
273
  _ts_metadata("design:type", String)
273
274
  ], UserCompaniesResponseDto.prototype, "message", void 0);
275
+ _ts_decorate([
276
+ (0, _swagger.ApiProperty)({
277
+ example: 'userPermission.company.list.success'
278
+ }),
279
+ _ts_metadata("design:type", String)
280
+ ], UserCompaniesResponseDto.prototype, "messageKey", void 0);
274
281
  _ts_decorate([
275
282
  (0, _swagger.ApiProperty)({
276
283
  description: 'List of companies the user has access to',
@@ -300,6 +307,7 @@ let UserBranchesResponseDto = class UserBranchesResponseDto {
300
307
  constructor(){
301
308
  _define_property(this, "success", void 0);
302
309
  _define_property(this, "message", void 0);
310
+ _define_property(this, "messageKey", void 0);
303
311
  _define_property(this, "data", void 0);
304
312
  }
305
313
  };
@@ -315,6 +323,12 @@ _ts_decorate([
315
323
  }),
316
324
  _ts_metadata("design:type", String)
317
325
  ], UserBranchesResponseDto.prototype, "message", void 0);
326
+ _ts_decorate([
327
+ (0, _swagger.ApiProperty)({
328
+ example: 'userPermission.branch.list.success'
329
+ }),
330
+ _ts_metadata("design:type", String)
331
+ ], UserBranchesResponseDto.prototype, "messageKey", void 0);
318
332
  _ts_decorate([
319
333
  (0, _swagger.ApiProperty)({
320
334
  description: 'List of branches the user has access to',
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "SetToken", {
9
9
  }
10
10
  });
11
11
  const _utils = require("@flusys/nestjs-shared/utils");
12
+ const _config = require("../config");
12
13
  const _common = require("@nestjs/common");
13
14
  const _buffer = require("buffer");
14
15
  const _rxjs = require("rxjs");
15
- const _config = require("../config");
16
16
  const _authconfigservice = require("../services/auth-config.service");
17
17
  function _define_property(obj, key, value) {
18
18
  if (key in obj) {
@@ -52,10 +52,13 @@ let SetToken = class SetToken {
52
52
  const req = context.switchToHttp().getRequest();
53
53
  const res = context.switchToHttp().getResponse();
54
54
  return next.handle().pipe((0, _rxjs.map)((value)=>{
55
- if (!value?.refreshToken) return value;
55
+ if (typeof value !== 'object' || value === null || !('refreshToken' in value)) {
56
+ return value;
57
+ }
58
+ const response = value;
56
59
  if ((0, _utils.isBrowserRequest)(req)) {
57
- this.setRefreshTokenCookie(req, res, value.refreshToken);
58
- const { refreshToken, ...responseWithoutToken } = value;
60
+ this.setRefreshTokenCookie(req, res, String(response.refreshToken));
61
+ const { refreshToken, ...responseWithoutToken } = response;
59
62
  return responseWithoutToken;
60
63
  }
61
64
  return value;
@@ -65,7 +68,13 @@ let SetToken = class SetToken {
65
68
  const rawCookieString = `${this.cookieName}=${tokenValue}; HttpOnly`;
66
69
  const estimatedBytes = _buffer.Buffer.byteLength(rawCookieString, 'utf8');
67
70
  if (estimatedBytes > _config.MAX_COOKIE_BYTES) {
68
- throw new _common.PayloadTooLargeException(`Refresh token too large (≈${estimatedBytes} bytes)`);
71
+ throw new _common.PayloadTooLargeException({
72
+ message: `Refresh token too large (≈${estimatedBytes} bytes)`,
73
+ messageKey: _config.AUTH_MESSAGES.TOKEN_TOO_LARGE,
74
+ messageParams: {
75
+ size: estimatedBytes
76
+ }
77
+ });
69
78
  }
70
79
  res.cookie(this.cookieName, tokenValue, {
71
80
  httpOnly: true,
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "AuthConfigService", {
9
9
  }
10
10
  });
11
11
  const _config = require("@flusys/nestjs-core/config");
12
+ const _constants = require("@flusys/nestjs-shared/constants");
12
13
  const _common = require("@nestjs/common");
13
14
  const _authconstants = require("../config/auth.constants");
14
15
  const _authmoduleoptionsinterface = require("../interfaces/auth-module-options.interface");
@@ -57,7 +58,10 @@ let AuthConfigService = class AuthConfigService {
57
58
  // JWT Configuration
58
59
  getJwtSecret() {
59
60
  if (!this.config.jwtSecret) {
60
- throw new _common.InternalServerErrorException('[AuthModule] JWT_SECRET is required - set via environment or module config');
61
+ throw new _common.InternalServerErrorException({
62
+ message: '[AuthModule] JWT_SECRET is required - set via environment or module config',
63
+ messageKey: _constants.SYSTEM_MESSAGES.CONFIG_REQUIRED
64
+ });
61
65
  }
62
66
  return this.config.jwtSecret;
63
67
  }
@@ -69,11 +73,10 @@ let AuthConfigService = class AuthConfigService {
69
73
  return this.config.refreshTokenSecret;
70
74
  }
71
75
  if (_config.envConfig.isProduction()) {
72
- throw new _common.InternalServerErrorException('[AuthModule] REFRESH_TOKEN_SECRET is required in production - ' + 'using the same secret for access and refresh tokens is a security risk');
73
- }
74
- if (!this.refreshTokenSecretWarned) {
75
- this.refreshTokenSecretWarned = true;
76
- this.logger.warn('REFRESH_TOKEN_SECRET not configured - using JWT_SECRET as fallback. ' + 'For better security, configure a separate refresh token secret.');
76
+ throw new _common.InternalServerErrorException({
77
+ message: '[AuthModule] REFRESH_TOKEN_SECRET is required in production - using the same secret for access and refresh tokens is a security risk',
78
+ messageKey: _constants.SYSTEM_MESSAGES.CONFIG_REQUIRED
79
+ });
77
80
  }
78
81
  return this.getJwtSecret();
79
82
  }
@@ -88,10 +91,8 @@ let AuthConfigService = class AuthConfigService {
88
91
  return this.config.frontendUrl;
89
92
  }
90
93
  constructor(injectedOptions){
91
- _define_property(this, "logger", new _common.Logger(AuthConfigService.name));
92
94
  _define_property(this, "options", void 0);
93
95
  _define_property(this, "config", void 0);
94
- _define_property(this, "refreshTokenSecretWarned", false);
95
96
  this.options = injectedOptions ?? {
96
97
  global: false,
97
98
  includeController: true
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "AuthDataSourceProvider", {
8
8
  return AuthDataSourceProvider;
9
9
  }
10
10
  });
11
- const _modules = require("@flusys/nestjs-shared/modules");
11
+ const _nestjsshared = require("@flusys/nestjs-shared");
12
12
  const _common = require("@nestjs/common");
13
13
  const _core = require("@nestjs/core");
14
14
  const _express = require("express");
@@ -82,7 +82,7 @@ function _ts_param(paramIndex, decorator) {
82
82
  decorator(target, key, paramIndex);
83
83
  };
84
84
  }
85
- let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.MultiTenantDataSourceService {
85
+ let AuthDataSourceProvider = class AuthDataSourceProvider extends _nestjsshared.MultiTenantDataSourceService {
86
86
  async getSingleDataSource() {
87
87
  if (!AuthDataSourceProvider.singleDataSource) {
88
88
  if (AuthDataSourceProvider.singleConnectionLock) {
@@ -91,7 +91,10 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
91
91
  const lockPromise = (async ()=>{
92
92
  const config = this.getDefaultDatabaseConfig();
93
93
  if (!config) {
94
- throw new _common.InternalServerErrorException('Default database config is not available');
94
+ throw new _common.InternalServerErrorException({
95
+ message: 'Default database config is not available',
96
+ messageKey: _nestjsshared.SYSTEM_MESSAGES.DATABASE_CONFIG_NOT_AVAILABLE
97
+ });
95
98
  }
96
99
  const ds = await this.createDataSourceFromConfig(config);
97
100
  AuthDataSourceProvider.singleDataSource = ds;
@@ -154,7 +157,7 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
154
157
  return super.createDataSourceFromConfig(config, await this.getAuthEntities());
155
158
  }
156
159
  constructor(authOptions, request){
157
- super(AuthDataSourceProvider.buildParentOptions(authOptions), request), _define_property(this, "authOptions", void 0), _define_property(this, "logger", void 0), this.authOptions = authOptions, this.logger = new _common.Logger(AuthDataSourceProvider.name);
160
+ super(AuthDataSourceProvider.buildParentOptions(authOptions), request), _define_property(this, "authOptions", void 0), this.authOptions = authOptions;
158
161
  }
159
162
  };
160
163
  _define_property(AuthDataSourceProvider, "tenantConnections", new Map());