@flusys/nestjs-auth 0.1.0-beta.3 → 1.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 (102) hide show
  1. package/README.md +274 -301
  2. package/cjs/config/auth.constants.js +22 -4
  3. package/cjs/controllers/authentication.controller.js +222 -38
  4. package/cjs/controllers/branch.controller.js +46 -4
  5. package/cjs/controllers/company-selection.controller.js +27 -20
  6. package/cjs/controllers/company.controller.js +46 -4
  7. package/cjs/controllers/user-permission.controller.js +40 -37
  8. package/cjs/controllers/user.controller.js +222 -23
  9. package/cjs/dtos/authentication.dto.js +119 -13
  10. package/cjs/dtos/user-permission.dto.js +28 -0
  11. package/cjs/dtos/user.dto.js +19 -4
  12. package/cjs/entities/index.js +5 -1
  13. package/cjs/entities/pending-registration.entity.js +125 -0
  14. package/cjs/entities/user-company-permission.entity.js +0 -6
  15. package/cjs/entities/user-token.entity.js +129 -0
  16. package/cjs/guards/auth-throttler.guard.js +53 -0
  17. package/cjs/interceptors/clear-token.interceptor.js +3 -6
  18. package/cjs/interceptors/set-token.interceptor.js +38 -31
  19. package/cjs/interfaces/auth-email-provider.interface.js +45 -0
  20. package/cjs/interfaces/authentication.interface.js +0 -3
  21. package/cjs/interfaces/index.js +2 -0
  22. package/cjs/interfaces/user-enricher.interface.js +4 -0
  23. package/cjs/modules/auth.module.js +8 -20
  24. package/cjs/services/auth-config.service.js +42 -47
  25. package/cjs/services/auth-datasource.provider.js +18 -34
  26. package/cjs/services/auth-email.service.js +471 -0
  27. package/cjs/services/authentication.service.js +240 -153
  28. package/cjs/services/branch.service.js +15 -48
  29. package/cjs/services/company-selection-session.service.js +1 -1
  30. package/cjs/services/company.service.js +7 -36
  31. package/cjs/services/index.js +1 -0
  32. package/cjs/services/user-permission.service.js +9 -29
  33. package/cjs/services/user.service.js +228 -107
  34. package/cjs/strategies/jwt.strategy.js +14 -1
  35. package/cjs/validators/password.validator.js +45 -0
  36. package/config/auth.constants.d.ts +5 -0
  37. package/controllers/authentication.controller.d.ts +13 -9
  38. package/controllers/company-selection.controller.d.ts +6 -2
  39. package/controllers/user.controller.d.ts +33 -0
  40. package/dtos/authentication.dto.d.ts +21 -3
  41. package/dtos/company-branch.dto.d.ts +0 -1
  42. package/dtos/company.dto.d.ts +0 -1
  43. package/dtos/user-permission.dto.d.ts +4 -0
  44. package/dtos/user.dto.d.ts +1 -2
  45. package/entities/index.d.ts +7 -3
  46. package/entities/pending-registration.entity.d.ts +17 -0
  47. package/entities/user-company-permission.entity.d.ts +0 -2
  48. package/entities/user-token.entity.d.ts +15 -0
  49. package/fesm/config/auth.constants.js +11 -8
  50. package/fesm/controllers/authentication.controller.js +224 -40
  51. package/fesm/controllers/branch.controller.js +49 -7
  52. package/fesm/controllers/company-selection.controller.js +28 -21
  53. package/fesm/controllers/company.controller.js +49 -7
  54. package/fesm/controllers/user-permission.controller.js +41 -38
  55. package/fesm/controllers/user.controller.js +225 -26
  56. package/fesm/dtos/authentication.dto.js +123 -111
  57. package/fesm/dtos/user-permission.dto.js +28 -0
  58. package/fesm/dtos/user.dto.js +20 -5
  59. package/fesm/entities/index.js +7 -1
  60. package/fesm/entities/pending-registration.entity.js +115 -0
  61. package/fesm/entities/user-company-permission.entity.js +0 -6
  62. package/fesm/entities/user-token.entity.js +113 -0
  63. package/fesm/guards/auth-throttler.guard.js +43 -0
  64. package/fesm/interceptors/clear-token.interceptor.js +2 -5
  65. package/fesm/interceptors/set-token.interceptor.js +37 -30
  66. package/fesm/interfaces/auth-email-provider.interface.js +38 -0
  67. package/fesm/interfaces/authentication.interface.js +1 -7
  68. package/fesm/interfaces/index.js +2 -0
  69. package/fesm/interfaces/user-enricher.interface.js +26 -0
  70. package/fesm/modules/auth.module.js +10 -22
  71. package/fesm/services/auth-config.service.js +42 -47
  72. package/fesm/services/auth-datasource.provider.js +19 -35
  73. package/fesm/services/auth-email.service.js +420 -0
  74. package/fesm/services/authentication.service.js +238 -151
  75. package/fesm/services/branch.service.js +16 -49
  76. package/fesm/services/company-selection-session.service.js +1 -1
  77. package/fesm/services/company.service.js +8 -37
  78. package/fesm/services/index.js +1 -0
  79. package/fesm/services/user-permission.service.js +10 -30
  80. package/fesm/services/user.service.js +229 -108
  81. package/fesm/strategies/jwt.strategy.js +14 -1
  82. package/fesm/validators/password.validator.js +48 -0
  83. package/guards/auth-throttler.guard.d.ts +7 -0
  84. package/interceptors/set-token.interceptor.d.ts +1 -0
  85. package/interfaces/auth-email-provider.interface.d.ts +6 -0
  86. package/interfaces/auth-module-options.interface.d.ts +4 -1
  87. package/interfaces/authentication.interface.d.ts +14 -0
  88. package/interfaces/index.d.ts +2 -0
  89. package/interfaces/user-enricher.interface.d.ts +64 -0
  90. package/interfaces/user.interface.d.ts +1 -0
  91. package/modules/auth.module.d.ts +0 -1
  92. package/package.json +4 -4
  93. package/services/auth-config.service.d.ts +5 -1
  94. package/services/auth-email.service.d.ts +51 -0
  95. package/services/authentication.service.d.ts +21 -12
  96. package/services/branch.service.d.ts +2 -5
  97. package/services/company-selection-session.service.d.ts +1 -1
  98. package/services/company.service.d.ts +1 -4
  99. package/services/index.d.ts +1 -0
  100. package/services/user-permission.service.d.ts +0 -1
  101. package/services/user.service.d.ts +20 -6
  102. package/validators/password.validator.d.ts +10 -0
@@ -1,7 +1,5 @@
1
- // =============================================================================
2
- // INJECTION TOKENS
3
- // =============================================================================
4
- /** Injection token for auth module options */ "use strict";
1
+ // Injection Tokens
2
+ "use strict";
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -15,9 +13,29 @@ _export(exports, {
15
13
  get AUTH_MODULE_OPTIONS () {
16
14
  return AUTH_MODULE_OPTIONS;
17
15
  },
16
+ get BCRYPT_SALT_ROUNDS () {
17
+ return BCRYPT_SALT_ROUNDS;
18
+ },
19
+ get DEFAULT_COOKIE_NAME () {
20
+ return DEFAULT_COOKIE_NAME;
21
+ },
22
+ get MAX_COOKIE_BYTES () {
23
+ return MAX_COOKIE_BYTES;
24
+ },
18
25
  get SESSION_CACHE_PREFIX () {
19
26
  return SESSION_CACHE_PREFIX;
27
+ },
28
+ get TOKEN_REVOKED_PREFIX () {
29
+ return TOKEN_REVOKED_PREFIX;
30
+ },
31
+ get USER_ENRICHER () {
32
+ return USER_ENRICHER;
20
33
  }
21
34
  });
22
35
  const AUTH_MODULE_OPTIONS = 'AUTH_MODULE_OPTIONS';
36
+ const USER_ENRICHER = 'USER_ENRICHER';
37
+ const BCRYPT_SALT_ROUNDS = 12;
38
+ const DEFAULT_COOKIE_NAME = 'fsn_refresh_token';
39
+ const MAX_COOKIE_BYTES = 3500;
23
40
  const SESSION_CACHE_PREFIX = 'auth:session';
41
+ const TOKEN_REVOKED_PREFIX = 'auth:revoked';
@@ -13,11 +13,14 @@ const _guards = require("@flusys/nestjs-shared/guards");
13
13
  const _interfaces = require("@flusys/nestjs-shared/interfaces");
14
14
  const _common = require("@nestjs/common");
15
15
  const _swagger = require("@nestjs/swagger");
16
+ const _throttler = require("@nestjs/throttler");
16
17
  const _express = require("express");
17
18
  const _authenticationdto = require("../dtos/authentication.dto");
19
+ const _dtos = require("@flusys/nestjs-shared/dtos");
18
20
  const _cleartokeninterceptor = require("../interceptors/clear-token.interceptor");
19
21
  const _settokeninterceptor = require("../interceptors/set-token.interceptor");
20
22
  const _authconfigservice = require("../services/auth-config.service");
23
+ const _authemailservice = require("../services/auth-email.service");
21
24
  const _authenticationservice = require("../services/authentication.service");
22
25
  function _define_property(obj, key, value) {
23
26
  if (key in obj) {
@@ -47,37 +50,26 @@ function _ts_param(paramIndex, decorator) {
47
50
  };
48
51
  }
49
52
  let AuthenticationController = class AuthenticationController {
50
- // ==========================================================================
51
- // CORE ENDPOINTS (Always available)
52
- // ==========================================================================
53
- /**
54
- * Login
55
- * Returns either tokens directly or company/branch selection requirement
56
- * Browser: refreshToken set in HTTP-only cookie, not in response body
57
- * API/Mobile: refreshToken included in response body
58
- */ async login(loginDto) {
53
+ buildAuthUrl(req, path) {
54
+ const frontendUrl = this.authConfig?.getFrontendUrl();
55
+ return frontendUrl ? `${frontendUrl}${path}` : `${req.protocol}://${req.get('host')}${path}`;
56
+ }
57
+ async login(loginDto) {
59
58
  const result = await this.authService.login(loginDto.email, loginDto.password);
60
59
  if ('requiresSelection' in result) {
61
60
  return result;
62
61
  }
63
62
  return result;
64
63
  }
65
- /**
66
- * Register new user
67
- * If company feature enabled, can optionally join/create company
68
- * Browser: refreshToken set in HTTP-only cookie
69
- */ async register(registrationDto) {
70
- const result = await this.authService.register(registrationDto);
64
+ /** Register new user. If company feature enabled, can join/create company. */ async register(req, registrationDto) {
65
+ const verifyUrlBase = this.buildAuthUrl(req, '/auth/verify-email');
66
+ const result = await this.authService.register(registrationDto, verifyUrlBase);
71
67
  return {
72
68
  ...result,
73
69
  companyFeatureEnabled: this.authConfig?.isCompanyFeatureEnabled() ?? false
74
70
  };
75
71
  }
76
- /**
77
- * Refresh access token
78
- * Browser: Gets refreshToken from HTTP-only cookie
79
- * API/Mobile: Gets refreshToken from request body
80
- */ async refreshToken(req, refreshTokenDto) {
72
+ /** Refresh access token. Browser uses HTTP-only cookie, API/Mobile uses request body. */ async refreshToken(req, refreshTokenDto) {
81
73
  // Get refresh token from cookie (browser) or body (API/mobile)
82
74
  const cookieName = this.authConfig?.getRefreshTokenCookieName() ?? 'fsn_refresh_token';
83
75
  const refreshToken = req.cookies?.[cookieName] || refreshTokenDto.refreshToken;
@@ -86,42 +78,88 @@ let AuthenticationController = class AuthenticationController {
86
78
  }
87
79
  return this.authService.refreshToken(refreshToken);
88
80
  }
89
- /**
90
- * Get current user info
91
- * Returns only user, company, and branch data (no tokens)
92
- * Uses existing access token from Authorization header
93
- * Company/branch fields are automatically excluded from Swagger when company feature is disabled
94
- */ async getCurrentUser(user) {
81
+ /** Get current user info. Returns user, company, and branch data (no tokens). */ async getCurrentUser(user) {
95
82
  return this.authService.getUserInfo(user.id, user.companyId, user.branchId);
96
83
  }
97
- /**
98
- * Logout
99
- * Clears refresh token cookie for browsers
100
- */ async logout(userId) {
84
+ /** Logout - Clears refresh token cookie for browsers */ async logout(userId) {
101
85
  await this.authService.logout(userId);
102
86
  return {
87
+ success: true,
103
88
  message: 'Logged out successfully'
104
89
  };
105
90
  }
106
- /**
107
- * Change password
108
- */ async changePassword(userId, dto) {
91
+ async changePassword(userId, dto) {
109
92
  await this.authService.changePassword(userId, dto.currentPassword, dto.newPassword);
110
93
  return {
94
+ success: true,
111
95
  message: 'Password changed successfully'
112
96
  };
113
97
  }
114
- // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
115
- constructor(authService, authConfig){
98
+ async forgotPassword(req, dto) {
99
+ if (!this.authEmailService) {
100
+ return {
101
+ success: false,
102
+ message: 'Email service is not configured'
103
+ };
104
+ }
105
+ return this.authEmailService.forgotPassword(dto.email, this.buildAuthUrl(req, '/auth/reset-password'));
106
+ }
107
+ async resetPassword(dto) {
108
+ if (!this.authEmailService) {
109
+ return {
110
+ success: false,
111
+ message: 'Email service is not configured'
112
+ };
113
+ }
114
+ return this.authEmailService.resetPassword(dto.token, dto.newPassword);
115
+ }
116
+ async resendVerification(req, dto) {
117
+ if (!this.authEmailService) {
118
+ return {
119
+ success: false,
120
+ message: 'Email service is not configured'
121
+ };
122
+ }
123
+ return this.authEmailService.resendVerificationEmail(dto.email, this.buildAuthUrl(req, '/auth/verify-email'));
124
+ }
125
+ /** Verify email - Verify email using token. Handles both pending registration and existing user verification. */ async verifyEmail(dto) {
126
+ if (!this.authEmailService) {
127
+ return {
128
+ success: false,
129
+ message: 'Email service is not configured'
130
+ };
131
+ }
132
+ const result = await this.authEmailService.verifyEmail(dto.token);
133
+ if (result.type === 'pending') {
134
+ const registrationResult = await this.authService.createUserFromPendingRegistration(result.pending);
135
+ return {
136
+ ...registrationResult,
137
+ companyFeatureEnabled: this.authConfig?.isCompanyFeatureEnabled() ?? false
138
+ };
139
+ }
140
+ return {
141
+ success: true,
142
+ message: result.message
143
+ };
144
+ }
145
+ constructor(authService, authConfig, authEmailService){
116
146
  _define_property(this, "authService", void 0);
117
147
  _define_property(this, "authConfig", void 0);
148
+ _define_property(this, "authEmailService", void 0);
118
149
  this.authService = authService;
119
150
  this.authConfig = authConfig;
151
+ this.authEmailService = authEmailService;
120
152
  }
121
153
  };
122
154
  _ts_decorate([
123
155
  (0, _common.Post)('login'),
124
156
  (0, _common.HttpCode)(_common.HttpStatus.OK),
157
+ (0, _throttler.Throttle)({
158
+ default: {
159
+ limit: 5,
160
+ ttl: 60000
161
+ }
162
+ }),
125
163
  (0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
126
164
  (0, _swagger.ApiOperation)({
127
165
  summary: 'User login'
@@ -147,6 +185,12 @@ _ts_decorate([
147
185
  _ts_decorate([
148
186
  (0, _common.Post)('register'),
149
187
  (0, _common.HttpCode)(_common.HttpStatus.CREATED),
188
+ (0, _throttler.Throttle)({
189
+ default: {
190
+ limit: 3,
191
+ ttl: 60000
192
+ }
193
+ }),
150
194
  (0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
151
195
  (0, _swagger.ApiOperation)({
152
196
  summary: 'Register new user'
@@ -158,9 +202,11 @@ _ts_decorate([
158
202
  status: 201,
159
203
  type: _authenticationdto.RegistrationResponseDto
160
204
  }),
161
- _ts_param(0, (0, _common.Body)()),
205
+ _ts_param(0, (0, _common.Req)()),
206
+ _ts_param(1, (0, _common.Body)()),
162
207
  _ts_metadata("design:type", Function),
163
208
  _ts_metadata("design:paramtypes", [
209
+ typeof _express.Request === "undefined" ? Object : _express.Request,
164
210
  typeof _authenticationdto.RegistrationDto === "undefined" ? Object : _authenticationdto.RegistrationDto
165
211
  ]),
166
212
  _ts_metadata("design:returntype", Promise)
@@ -168,6 +214,12 @@ _ts_decorate([
168
214
  _ts_decorate([
169
215
  (0, _common.Post)('refresh'),
170
216
  (0, _common.HttpCode)(_common.HttpStatus.OK),
217
+ (0, _throttler.Throttle)({
218
+ default: {
219
+ limit: 30,
220
+ ttl: 60000
221
+ }
222
+ }),
171
223
  (0, _swagger.ApiOperation)({
172
224
  summary: 'Refresh access token'
173
225
  }),
@@ -185,7 +237,8 @@ _ts_decorate([
185
237
  ], AuthenticationController.prototype, "refreshToken", null);
186
238
  _ts_decorate([
187
239
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
188
- (0, _common.Get)('me'),
240
+ (0, _common.Post)('me'),
241
+ (0, _throttler.SkipThrottle)(),
189
242
  (0, _swagger.ApiBearerAuth)(),
190
243
  (0, _swagger.ApiOperation)({
191
244
  summary: 'Get current user info'
@@ -205,11 +258,16 @@ _ts_decorate([
205
258
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
206
259
  (0, _common.Post)('logout'),
207
260
  (0, _common.HttpCode)(_common.HttpStatus.OK),
261
+ (0, _throttler.SkipThrottle)(),
208
262
  (0, _common.UseInterceptors)(_cleartokeninterceptor.ClearToken),
209
263
  (0, _swagger.ApiBearerAuth)(),
210
264
  (0, _swagger.ApiOperation)({
211
265
  summary: 'Logout user'
212
266
  }),
267
+ (0, _swagger.ApiResponse)({
268
+ status: 200,
269
+ type: _dtos.MessageResponseDto
270
+ }),
213
271
  _ts_param(0, (0, _decorators.CurrentUser)('id')),
214
272
  _ts_metadata("design:type", Function),
215
273
  _ts_metadata("design:paramtypes", [
@@ -221,6 +279,12 @@ _ts_decorate([
221
279
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
222
280
  (0, _common.Post)('change-password'),
223
281
  (0, _common.HttpCode)(_common.HttpStatus.OK),
282
+ (0, _throttler.Throttle)({
283
+ default: {
284
+ limit: 5,
285
+ ttl: 60000
286
+ }
287
+ }),
224
288
  (0, _swagger.ApiBearerAuth)(),
225
289
  (0, _swagger.ApiOperation)({
226
290
  summary: 'Change password'
@@ -228,6 +292,10 @@ _ts_decorate([
228
292
  (0, _swagger.ApiBody)({
229
293
  type: _authenticationdto.ChangePasswordDto
230
294
  }),
295
+ (0, _swagger.ApiResponse)({
296
+ status: 200,
297
+ type: _dtos.MessageResponseDto
298
+ }),
231
299
  _ts_param(0, (0, _decorators.CurrentUser)('id')),
232
300
  _ts_param(1, (0, _common.Body)()),
233
301
  _ts_metadata("design:type", Function),
@@ -237,15 +305,131 @@ _ts_decorate([
237
305
  ]),
238
306
  _ts_metadata("design:returntype", Promise)
239
307
  ], AuthenticationController.prototype, "changePassword", null);
308
+ _ts_decorate([
309
+ (0, _common.Post)('forgot-password'),
310
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
311
+ (0, _throttler.Throttle)({
312
+ default: {
313
+ limit: 3,
314
+ ttl: 300000
315
+ }
316
+ }),
317
+ (0, _swagger.ApiOperation)({
318
+ summary: 'Request password reset email'
319
+ }),
320
+ (0, _swagger.ApiBody)({
321
+ type: _authenticationdto.ForgotPasswordDto
322
+ }),
323
+ (0, _swagger.ApiResponse)({
324
+ status: 200,
325
+ type: _dtos.MessageResponseDto
326
+ }),
327
+ _ts_param(0, (0, _common.Req)()),
328
+ _ts_param(1, (0, _common.Body)()),
329
+ _ts_metadata("design:type", Function),
330
+ _ts_metadata("design:paramtypes", [
331
+ typeof _express.Request === "undefined" ? Object : _express.Request,
332
+ typeof _authenticationdto.ForgotPasswordDto === "undefined" ? Object : _authenticationdto.ForgotPasswordDto
333
+ ]),
334
+ _ts_metadata("design:returntype", Promise)
335
+ ], AuthenticationController.prototype, "forgotPassword", null);
336
+ _ts_decorate([
337
+ (0, _common.Post)('reset-password'),
338
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
339
+ (0, _throttler.Throttle)({
340
+ default: {
341
+ limit: 5,
342
+ ttl: 900000
343
+ }
344
+ }),
345
+ (0, _swagger.ApiOperation)({
346
+ summary: 'Reset password using token'
347
+ }),
348
+ (0, _swagger.ApiBody)({
349
+ type: _authenticationdto.ResetPasswordDto
350
+ }),
351
+ (0, _swagger.ApiResponse)({
352
+ status: 200,
353
+ type: _dtos.MessageResponseDto
354
+ }),
355
+ _ts_param(0, (0, _common.Body)()),
356
+ _ts_metadata("design:type", Function),
357
+ _ts_metadata("design:paramtypes", [
358
+ typeof _authenticationdto.ResetPasswordDto === "undefined" ? Object : _authenticationdto.ResetPasswordDto
359
+ ]),
360
+ _ts_metadata("design:returntype", Promise)
361
+ ], AuthenticationController.prototype, "resetPassword", null);
362
+ _ts_decorate([
363
+ (0, _common.Post)('resend-verification'),
364
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
365
+ (0, _throttler.Throttle)({
366
+ default: {
367
+ limit: 3,
368
+ ttl: 300000
369
+ }
370
+ }),
371
+ (0, _swagger.ApiOperation)({
372
+ summary: 'Resend email verification link'
373
+ }),
374
+ (0, _swagger.ApiBody)({
375
+ type: _authenticationdto.ResendVerificationDto
376
+ }),
377
+ (0, _swagger.ApiResponse)({
378
+ status: 200,
379
+ type: _dtos.MessageResponseDto
380
+ }),
381
+ _ts_param(0, (0, _common.Req)()),
382
+ _ts_param(1, (0, _common.Body)()),
383
+ _ts_metadata("design:type", Function),
384
+ _ts_metadata("design:paramtypes", [
385
+ typeof _express.Request === "undefined" ? Object : _express.Request,
386
+ typeof _authenticationdto.ResendVerificationDto === "undefined" ? Object : _authenticationdto.ResendVerificationDto
387
+ ]),
388
+ _ts_metadata("design:returntype", Promise)
389
+ ], AuthenticationController.prototype, "resendVerification", null);
390
+ _ts_decorate([
391
+ (0, _common.Post)('verify-email'),
392
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
393
+ (0, _throttler.Throttle)({
394
+ default: {
395
+ limit: 10,
396
+ ttl: 60000
397
+ }
398
+ }),
399
+ (0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
400
+ (0, _swagger.ApiOperation)({
401
+ summary: 'Verify email using token'
402
+ }),
403
+ (0, _swagger.ApiBody)({
404
+ type: _authenticationdto.VerifyEmailDto
405
+ }),
406
+ (0, _swagger.ApiResponse)({
407
+ status: 200,
408
+ type: _dtos.MessageResponseDto
409
+ }),
410
+ (0, _swagger.ApiResponse)({
411
+ status: 200,
412
+ type: _authenticationdto.RegistrationResponseDto
413
+ }),
414
+ _ts_param(0, (0, _common.Body)()),
415
+ _ts_metadata("design:type", Function),
416
+ _ts_metadata("design:paramtypes", [
417
+ typeof _authenticationdto.VerifyEmailDto === "undefined" ? Object : _authenticationdto.VerifyEmailDto
418
+ ]),
419
+ _ts_metadata("design:returntype", Promise)
420
+ ], AuthenticationController.prototype, "verifyEmail", null);
240
421
  AuthenticationController = _ts_decorate([
241
422
  (0, _swagger.ApiTags)('Authentication'),
242
423
  (0, _common.Controller)('auth'),
243
424
  _ts_param(0, (0, _common.Inject)(_authenticationservice.AuthenticationService)),
244
425
  _ts_param(1, (0, _common.Optional)()),
245
426
  _ts_param(1, (0, _common.Inject)(_authconfigservice.AuthConfigService)),
427
+ _ts_param(2, (0, _common.Optional)()),
428
+ _ts_param(2, (0, _common.Inject)(_authemailservice.AuthEmailService)),
246
429
  _ts_metadata("design:type", Function),
247
430
  _ts_metadata("design:paramtypes", [
248
431
  typeof _authenticationservice.AuthenticationService === "undefined" ? Object : _authenticationservice.AuthenticationService,
249
- typeof _authconfigservice.AuthConfigService === "undefined" ? Object : _authconfigservice.AuthConfigService
432
+ typeof _authconfigservice.AuthConfigService === "undefined" ? Object : _authconfigservice.AuthConfigService,
433
+ typeof _authemailservice.AuthEmailService === "undefined" ? Object : _authemailservice.AuthEmailService
250
434
  ])
251
435
  ], AuthenticationController);
@@ -12,7 +12,6 @@ const _classes = require("@flusys/nestjs-shared/classes");
12
12
  const _common = require("@nestjs/common");
13
13
  const _swagger = require("@nestjs/swagger");
14
14
  const _companybranchdto = require("../dtos/company-branch.dto");
15
- const _guards = require("@flusys/nestjs-shared/guards");
16
15
  const _branchservice = require("../services/branch.service");
17
16
  function _define_property(obj, key, value) {
18
17
  if (key in obj) {
@@ -41,16 +40,59 @@ function _ts_param(paramIndex, decorator) {
41
40
  decorator(target, key, paramIndex);
42
41
  };
43
42
  }
44
- let BranchController = class BranchController extends (0, _classes.createApiController)(_companybranchdto.CreateCompanyBranchDto, _companybranchdto.UpdateCompanyBranchDto, _companybranchdto.CompanyBranchResponseDto) {
43
+ let BranchController = class BranchController extends (0, _classes.createApiController)(_companybranchdto.CreateCompanyBranchDto, _companybranchdto.UpdateCompanyBranchDto, _companybranchdto.CompanyBranchResponseDto, {
44
+ security: {
45
+ insert: {
46
+ level: 'permission',
47
+ permissions: [
48
+ _classes.BRANCH_PERMISSIONS.CREATE
49
+ ]
50
+ },
51
+ insertMany: {
52
+ level: 'permission',
53
+ permissions: [
54
+ _classes.BRANCH_PERMISSIONS.CREATE
55
+ ]
56
+ },
57
+ getById: {
58
+ level: 'permission',
59
+ permissions: [
60
+ _classes.BRANCH_PERMISSIONS.READ
61
+ ]
62
+ },
63
+ getAll: {
64
+ level: 'permission',
65
+ permissions: [
66
+ _classes.BRANCH_PERMISSIONS.READ
67
+ ]
68
+ },
69
+ update: {
70
+ level: 'permission',
71
+ permissions: [
72
+ _classes.BRANCH_PERMISSIONS.UPDATE
73
+ ]
74
+ },
75
+ updateMany: {
76
+ level: 'permission',
77
+ permissions: [
78
+ _classes.BRANCH_PERMISSIONS.UPDATE
79
+ ]
80
+ },
81
+ delete: {
82
+ level: 'permission',
83
+ permissions: [
84
+ _classes.BRANCH_PERMISSIONS.DELETE
85
+ ]
86
+ }
87
+ }
88
+ }) {
45
89
  constructor(branchService){
46
90
  super(branchService), _define_property(this, "branchService", void 0), this.branchService = branchService;
47
91
  }
48
92
  };
49
93
  BranchController = _ts_decorate([
50
94
  (0, _swagger.ApiTags)('Branches'),
51
- (0, _swagger.ApiBearerAuth)(),
52
95
  (0, _common.Controller)('administration/branch'),
53
- (0, _common.UseGuards)(_guards.JwtAuthGuard),
54
96
  _ts_param(0, (0, _common.Inject)(_branchservice.BranchService)),
55
97
  _ts_metadata("design:type", Function),
56
98
  _ts_metadata("design:paramtypes", [
@@ -43,35 +43,28 @@ function _ts_param(paramIndex, decorator) {
43
43
  };
44
44
  }
45
45
  let CompanySelectionController = class CompanySelectionController {
46
- /**
47
- * Select Company & Branch
48
- * Used after login when user needs to select company and branch
49
- */ async select(dto) {
46
+ async select(dto) {
50
47
  return this.authService.select(dto.sessionId, dto.companyId, dto.branchId);
51
48
  }
52
- /**
53
- * Switch Company/Branch
54
- * Used to switch company/branch after already logged in
55
- */ async switchCompany(userId, dto) {
49
+ async switchCompany(userId, dto) {
56
50
  return this.authService.switchCompany(userId, dto.companyId, dto.branchId);
57
51
  }
58
- /**
59
- * Get user's companies
60
- */ async getUserCompanies(userId) {
52
+ async getUserCompanies(userId) {
61
53
  const companies = await this.authService.getUserCompanies(userId);
62
54
  return {
63
- companies
55
+ success: true,
56
+ message: 'User companies retrieved successfully',
57
+ data: companies
64
58
  };
65
59
  }
66
- /**
67
- * Get branches for a specific company
68
- */ async getUserBranches(userId, companyId) {
60
+ async getUserBranches(userId, companyId) {
69
61
  const branches = await this.authService.getUserBranches(userId, companyId);
70
62
  return {
71
- branches
63
+ success: true,
64
+ message: 'Company branches retrieved successfully',
65
+ data: branches
72
66
  };
73
67
  }
74
- // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
75
68
  constructor(authService){
76
69
  _define_property(this, "authService", void 0);
77
70
  this.authService = authService;
@@ -127,7 +120,8 @@ _ts_decorate([
127
120
  ], CompanySelectionController.prototype, "switchCompany", null);
128
121
  _ts_decorate([
129
122
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
130
- (0, _common.Get)('companies'),
123
+ (0, _common.Post)('get-companies'),
124
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
131
125
  (0, _swagger.ApiBearerAuth)(),
132
126
  (0, _swagger.ApiOperation)({
133
127
  summary: "Get user's available companies",
@@ -142,14 +136,27 @@ _ts_decorate([
142
136
  ], CompanySelectionController.prototype, "getUserCompanies", null);
143
137
  _ts_decorate([
144
138
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
145
- (0, _common.Get)('companies/:companyId/branches'),
139
+ (0, _common.Post)('get-company-branches'),
140
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
146
141
  (0, _swagger.ApiBearerAuth)(),
147
142
  (0, _swagger.ApiOperation)({
148
143
  summary: 'Get branches for a company',
149
144
  description: 'Get list of branches for a specific company that the user has access to'
150
145
  }),
146
+ (0, _swagger.ApiBody)({
147
+ schema: {
148
+ properties: {
149
+ companyId: {
150
+ type: 'string'
151
+ }
152
+ },
153
+ required: [
154
+ 'companyId'
155
+ ]
156
+ }
157
+ }),
151
158
  _ts_param(0, (0, _decorators.CurrentUser)('id')),
152
- _ts_param(1, (0, _common.Param)('companyId')),
159
+ _ts_param(1, (0, _common.Body)('companyId')),
153
160
  _ts_metadata("design:type", Function),
154
161
  _ts_metadata("design:paramtypes", [
155
162
  String,
@@ -12,7 +12,6 @@ const _classes = require("@flusys/nestjs-shared/classes");
12
12
  const _common = require("@nestjs/common");
13
13
  const _swagger = require("@nestjs/swagger");
14
14
  const _companydto = require("../dtos/company.dto");
15
- const _guards = require("@flusys/nestjs-shared/guards");
16
15
  const _companyservice = require("../services/company.service");
17
16
  function _define_property(obj, key, value) {
18
17
  if (key in obj) {
@@ -41,16 +40,59 @@ function _ts_param(paramIndex, decorator) {
41
40
  decorator(target, key, paramIndex);
42
41
  };
43
42
  }
44
- let CompanyController = class CompanyController extends (0, _classes.createApiController)(_companydto.CreateCompanyDto, _companydto.UpdateCompanyDto, _companydto.CompanyResponseDto) {
43
+ let CompanyController = class CompanyController extends (0, _classes.createApiController)(_companydto.CreateCompanyDto, _companydto.UpdateCompanyDto, _companydto.CompanyResponseDto, {
44
+ security: {
45
+ insert: {
46
+ level: 'permission',
47
+ permissions: [
48
+ _classes.COMPANY_PERMISSIONS.CREATE
49
+ ]
50
+ },
51
+ insertMany: {
52
+ level: 'permission',
53
+ permissions: [
54
+ _classes.COMPANY_PERMISSIONS.CREATE
55
+ ]
56
+ },
57
+ getById: {
58
+ level: 'permission',
59
+ permissions: [
60
+ _classes.COMPANY_PERMISSIONS.READ
61
+ ]
62
+ },
63
+ getAll: {
64
+ level: 'permission',
65
+ permissions: [
66
+ _classes.COMPANY_PERMISSIONS.READ
67
+ ]
68
+ },
69
+ update: {
70
+ level: 'permission',
71
+ permissions: [
72
+ _classes.COMPANY_PERMISSIONS.UPDATE
73
+ ]
74
+ },
75
+ updateMany: {
76
+ level: 'permission',
77
+ permissions: [
78
+ _classes.COMPANY_PERMISSIONS.UPDATE
79
+ ]
80
+ },
81
+ delete: {
82
+ level: 'permission',
83
+ permissions: [
84
+ _classes.COMPANY_PERMISSIONS.DELETE
85
+ ]
86
+ }
87
+ }
88
+ }) {
45
89
  constructor(companyService){
46
90
  super(companyService), _define_property(this, "companyService", void 0), this.companyService = companyService;
47
91
  }
48
92
  };
49
93
  CompanyController = _ts_decorate([
50
94
  (0, _swagger.ApiTags)('Companies'),
51
- (0, _swagger.ApiBearerAuth)(),
52
95
  (0, _common.Controller)('administration/company'),
53
- (0, _common.UseGuards)(_guards.JwtAuthGuard),
54
96
  _ts_param(0, (0, _common.Inject)(_companyservice.CompanyService)),
55
97
  _ts_metadata("design:type", Function),
56
98
  _ts_metadata("design:paramtypes", [