@flusys/nestjs-auth 3.0.0-rc → 3.0.0

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 (40) hide show
  1. package/README.md +610 -95
  2. package/cjs/controllers/authentication.controller.js +2 -173
  3. package/cjs/controllers/email-verification.controller.js +220 -0
  4. package/cjs/controllers/index.js +1 -0
  5. package/cjs/dtos/authentication.dto.js +12 -2
  6. package/cjs/entities/index.js +16 -17
  7. package/cjs/entities/pending-registration.entity.js +9 -0
  8. package/cjs/modules/auth.module.js +33 -24
  9. package/cjs/services/auth-config.service.js +11 -7
  10. package/cjs/services/auth-datasource.provider.js +15 -27
  11. package/cjs/services/auth-email.service.js +8 -33
  12. package/cjs/services/authentication.service.js +123 -99
  13. package/cjs/services/user.service.js +28 -83
  14. package/controllers/authentication.controller.d.ts +2 -10
  15. package/controllers/email-verification.controller.d.ts +20 -0
  16. package/controllers/index.d.ts +1 -0
  17. package/dtos/authentication.dto.d.ts +1 -0
  18. package/entities/index.d.ts +5 -10
  19. package/entities/pending-registration.entity.d.ts +1 -0
  20. package/fesm/controllers/authentication.controller.js +3 -174
  21. package/fesm/controllers/email-verification.controller.js +210 -0
  22. package/fesm/controllers/index.js +1 -0
  23. package/fesm/dtos/authentication.dto.js +32 -25
  24. package/fesm/entities/index.js +17 -9
  25. package/fesm/entities/pending-registration.entity.js +9 -0
  26. package/fesm/interfaces/user-enricher.interface.js +2 -24
  27. package/fesm/modules/auth.module.js +35 -26
  28. package/fesm/services/auth-config.service.js +11 -7
  29. package/fesm/services/auth-datasource.provider.js +15 -27
  30. package/fesm/services/auth-email.service.js +8 -33
  31. package/fesm/services/authentication.service.js +124 -100
  32. package/fesm/services/user.service.js +28 -83
  33. package/interfaces/user-enricher.interface.d.ts +3 -2
  34. package/modules/auth.module.d.ts +3 -1
  35. package/package.json +3 -3
  36. package/services/auth-config.service.d.ts +1 -0
  37. package/services/auth-datasource.provider.d.ts +1 -0
  38. package/services/auth-email.service.d.ts +1 -0
  39. package/services/authentication.service.d.ts +4 -1
  40. package/services/user.service.d.ts +5 -0
@@ -21,7 +21,6 @@ const _authenticationdto = require("../dtos/authentication.dto");
21
21
  const _cleartokeninterceptor = require("../interceptors/clear-token.interceptor");
22
22
  const _settokeninterceptor = require("../interceptors/set-token.interceptor");
23
23
  const _authconfigservice = require("../services/auth-config.service");
24
- const _authemailservice = require("../services/auth-email.service");
25
24
  const _authenticationservice = require("../services/authentication.service");
26
25
  function _define_property(obj, key, value) {
27
26
  if (key in obj) {
@@ -55,15 +54,6 @@ let AuthenticationController = class AuthenticationController {
55
54
  const frontendUrl = this.authConfig?.getFrontendUrl();
56
55
  return frontendUrl ? `${frontendUrl}${path}` : `${req.protocol}://${req.get('host')}${path}`;
57
56
  }
58
- get emailService() {
59
- if (!this.authEmailService) {
60
- throw new Error('Email service is not configured');
61
- }
62
- return this.authEmailService;
63
- }
64
- get isEmailEnabled() {
65
- return !!this.authEmailService;
66
- }
67
57
  async login(loginDto) {
68
58
  const result = await this.authService.login(loginDto.email, loginDto.password);
69
59
  if ('requiresEmailVerification' in result) {
@@ -109,56 +99,11 @@ let AuthenticationController = class AuthenticationController {
109
99
  message: 'Password changed successfully'
110
100
  };
111
101
  }
112
- async forgotPassword(req, dto) {
113
- if (!this.isEmailEnabled) {
114
- return {
115
- success: false,
116
- message: 'Email service is not configured'
117
- };
118
- }
119
- return this.emailService.forgotPassword(dto.email, this.buildAuthUrl(req, '/auth/reset-password'));
120
- }
121
- async resetPassword(dto) {
122
- if (!this.isEmailEnabled) {
123
- return {
124
- success: false,
125
- message: 'Email service is not configured'
126
- };
127
- }
128
- return this.emailService.resetPassword(dto.token, dto.newPassword);
129
- }
130
- async resendVerification(req, dto) {
131
- if (!this.isEmailEnabled) {
132
- return {
133
- success: false,
134
- message: 'Email service is not configured'
135
- };
136
- }
137
- return this.emailService.resendVerificationEmail(dto.email, this.buildAuthUrl(req, '/auth/verify-email'));
138
- }
139
- /** Verify email - Verify email using token. Handles both pending registration and existing user verification. */ async verifyEmail(dto) {
140
- if (!this.isEmailEnabled) {
141
- return {
142
- success: false,
143
- message: 'Email service is not configured'
144
- };
145
- }
146
- const result = await this.emailService.verifyEmail(dto.token);
147
- if (result.type === 'pending') {
148
- return this.authService.createUserFromPendingRegistration(result.pending);
149
- }
150
- return {
151
- success: true,
152
- message: result.message
153
- };
154
- }
155
- constructor(authService, authConfig, authEmailService){
102
+ constructor(authService, authConfig){
156
103
  _define_property(this, "authService", void 0);
157
104
  _define_property(this, "authConfig", void 0);
158
- _define_property(this, "authEmailService", void 0);
159
105
  this.authService = authService;
160
106
  this.authConfig = authConfig;
161
- this.authEmailService = authEmailService;
162
107
  }
163
108
  };
164
109
  _ts_decorate([
@@ -437,131 +382,15 @@ _ts_decorate([
437
382
  ]),
438
383
  _ts_metadata("design:returntype", Promise)
439
384
  ], AuthenticationController.prototype, "changePassword", null);
440
- _ts_decorate([
441
- (0, _common.Post)('forgot-password'),
442
- (0, _common.HttpCode)(_common.HttpStatus.OK),
443
- (0, _throttler.Throttle)({
444
- default: {
445
- limit: 3,
446
- ttl: 300000
447
- }
448
- }),
449
- (0, _swagger.ApiOperation)({
450
- summary: 'Request password reset email'
451
- }),
452
- (0, _swagger.ApiBody)({
453
- type: _authenticationdto.ForgotPasswordDto
454
- }),
455
- (0, _swagger.ApiResponse)({
456
- status: 200,
457
- type: _dtos.MessageResponseDto
458
- }),
459
- _ts_param(0, (0, _common.Req)()),
460
- _ts_param(1, (0, _common.Body)()),
461
- _ts_metadata("design:type", Function),
462
- _ts_metadata("design:paramtypes", [
463
- typeof _express.Request === "undefined" ? Object : _express.Request,
464
- typeof _authenticationdto.ForgotPasswordDto === "undefined" ? Object : _authenticationdto.ForgotPasswordDto
465
- ]),
466
- _ts_metadata("design:returntype", Promise)
467
- ], AuthenticationController.prototype, "forgotPassword", null);
468
- _ts_decorate([
469
- (0, _common.Post)('reset-password'),
470
- (0, _common.HttpCode)(_common.HttpStatus.OK),
471
- (0, _throttler.Throttle)({
472
- default: {
473
- limit: 5,
474
- ttl: 900000
475
- }
476
- }),
477
- (0, _swagger.ApiOperation)({
478
- summary: 'Reset password using token'
479
- }),
480
- (0, _swagger.ApiBody)({
481
- type: _authenticationdto.ResetPasswordDto
482
- }),
483
- (0, _swagger.ApiResponse)({
484
- status: 200,
485
- type: _dtos.MessageResponseDto
486
- }),
487
- _ts_param(0, (0, _common.Body)()),
488
- _ts_metadata("design:type", Function),
489
- _ts_metadata("design:paramtypes", [
490
- typeof _authenticationdto.ResetPasswordDto === "undefined" ? Object : _authenticationdto.ResetPasswordDto
491
- ]),
492
- _ts_metadata("design:returntype", Promise)
493
- ], AuthenticationController.prototype, "resetPassword", null);
494
- _ts_decorate([
495
- (0, _common.Post)('resend-verification'),
496
- (0, _common.HttpCode)(_common.HttpStatus.OK),
497
- (0, _throttler.Throttle)({
498
- default: {
499
- limit: 3,
500
- ttl: 300000
501
- }
502
- }),
503
- (0, _swagger.ApiOperation)({
504
- summary: 'Resend email verification link'
505
- }),
506
- (0, _swagger.ApiBody)({
507
- type: _authenticationdto.ResendVerificationDto
508
- }),
509
- (0, _swagger.ApiResponse)({
510
- status: 200,
511
- type: _dtos.MessageResponseDto
512
- }),
513
- _ts_param(0, (0, _common.Req)()),
514
- _ts_param(1, (0, _common.Body)()),
515
- _ts_metadata("design:type", Function),
516
- _ts_metadata("design:paramtypes", [
517
- typeof _express.Request === "undefined" ? Object : _express.Request,
518
- typeof _authenticationdto.ResendVerificationDto === "undefined" ? Object : _authenticationdto.ResendVerificationDto
519
- ]),
520
- _ts_metadata("design:returntype", Promise)
521
- ], AuthenticationController.prototype, "resendVerification", null);
522
- _ts_decorate([
523
- (0, _common.Post)('verify-email'),
524
- (0, _common.HttpCode)(_common.HttpStatus.OK),
525
- (0, _throttler.Throttle)({
526
- default: {
527
- limit: 10,
528
- ttl: 60000
529
- }
530
- }),
531
- (0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
532
- (0, _swagger.ApiOperation)({
533
- summary: 'Verify email using token'
534
- }),
535
- (0, _swagger.ApiBody)({
536
- type: _authenticationdto.VerifyEmailDto
537
- }),
538
- (0, _swagger.ApiResponse)({
539
- status: 200,
540
- type: _dtos.MessageResponseDto
541
- }),
542
- (0, _swagger.ApiResponse)({
543
- status: 200,
544
- type: _authenticationdto.RegistrationResponseDto
545
- }),
546
- _ts_param(0, (0, _common.Body)()),
547
- _ts_metadata("design:type", Function),
548
- _ts_metadata("design:paramtypes", [
549
- typeof _authenticationdto.VerifyEmailDto === "undefined" ? Object : _authenticationdto.VerifyEmailDto
550
- ]),
551
- _ts_metadata("design:returntype", Promise)
552
- ], AuthenticationController.prototype, "verifyEmail", null);
553
385
  AuthenticationController = _ts_decorate([
554
386
  (0, _swagger.ApiTags)('Authentication'),
555
387
  (0, _common.Controller)('auth'),
556
388
  _ts_param(0, (0, _common.Inject)(_authenticationservice.AuthenticationService)),
557
389
  _ts_param(1, (0, _common.Optional)()),
558
390
  _ts_param(1, (0, _common.Inject)(_authconfigservice.AuthConfigService)),
559
- _ts_param(2, (0, _common.Optional)()),
560
- _ts_param(2, (0, _common.Inject)(_authemailservice.AuthEmailService)),
561
391
  _ts_metadata("design:type", Function),
562
392
  _ts_metadata("design:paramtypes", [
563
393
  typeof _authenticationservice.AuthenticationService === "undefined" ? Object : _authenticationservice.AuthenticationService,
564
- typeof _authconfigservice.AuthConfigService === "undefined" ? Object : _authconfigservice.AuthConfigService,
565
- typeof _authemailservice.AuthEmailService === "undefined" ? Object : _authemailservice.AuthEmailService
394
+ typeof _authconfigservice.AuthConfigService === "undefined" ? Object : _authconfigservice.AuthConfigService
566
395
  ])
567
396
  ], AuthenticationController);
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "EmailVerificationController", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return EmailVerificationController;
9
+ }
10
+ });
11
+ const _dtos = require("@flusys/nestjs-shared/dtos");
12
+ const _common = require("@nestjs/common");
13
+ const _swagger = require("@nestjs/swagger");
14
+ const _throttler = require("@nestjs/throttler");
15
+ const _express = require("express");
16
+ const _authenticationdto = require("../dtos/authentication.dto");
17
+ const _settokeninterceptor = require("../interceptors/set-token.interceptor");
18
+ const _authconfigservice = require("../services/auth-config.service");
19
+ const _authdatasourceprovider = require("../services/auth-datasource.provider");
20
+ const _authemailservice = require("../services/auth-email.service");
21
+ const _authenticationservice = require("../services/authentication.service");
22
+ function _define_property(obj, key, value) {
23
+ if (key in obj) {
24
+ Object.defineProperty(obj, key, {
25
+ value: value,
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true
29
+ });
30
+ } else {
31
+ obj[key] = value;
32
+ }
33
+ return obj;
34
+ }
35
+ function _ts_decorate(decorators, target, key, desc) {
36
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
37
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
38
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
39
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
40
+ }
41
+ function _ts_metadata(k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ }
44
+ function _ts_param(paramIndex, decorator) {
45
+ return function(target, key) {
46
+ decorator(target, key, paramIndex);
47
+ };
48
+ }
49
+ let EmailVerificationController = class EmailVerificationController {
50
+ ensureEmailVerificationEnabled() {
51
+ if (!this.dataSourceProvider.isEmailVerificationEnabled()) {
52
+ throw new _common.BadRequestException('Email verification is not enabled for this tenant');
53
+ }
54
+ }
55
+ buildAuthUrl(req, path) {
56
+ const frontendUrl = this.authConfig.getFrontendUrl();
57
+ return frontendUrl ? `${frontendUrl}${path}` : `${req.protocol}://${req.get('host')}${path}`;
58
+ }
59
+ async forgotPassword(req, dto) {
60
+ this.ensureEmailVerificationEnabled();
61
+ return this.authEmailService.forgotPassword(dto.email, this.buildAuthUrl(req, '/auth/reset-password'));
62
+ }
63
+ async resetPassword(dto) {
64
+ this.ensureEmailVerificationEnabled();
65
+ return this.authEmailService.resetPassword(dto.token, dto.newPassword);
66
+ }
67
+ async resendVerification(req, dto) {
68
+ this.ensureEmailVerificationEnabled();
69
+ return this.authEmailService.resendVerificationEmail(dto.email, this.buildAuthUrl(req, '/auth/verify-email'));
70
+ }
71
+ async verifyEmail(dto) {
72
+ this.ensureEmailVerificationEnabled();
73
+ const result = await this.authEmailService.verifyEmail(dto.token);
74
+ if (result.type === 'pending') {
75
+ return this.authService.createUserFromPendingRegistration(result.pending);
76
+ }
77
+ return {
78
+ success: true,
79
+ message: result.message
80
+ };
81
+ }
82
+ constructor(authService, authEmailService, authConfig, dataSourceProvider){
83
+ _define_property(this, "authService", void 0);
84
+ _define_property(this, "authEmailService", void 0);
85
+ _define_property(this, "authConfig", void 0);
86
+ _define_property(this, "dataSourceProvider", void 0);
87
+ this.authService = authService;
88
+ this.authEmailService = authEmailService;
89
+ this.authConfig = authConfig;
90
+ this.dataSourceProvider = dataSourceProvider;
91
+ }
92
+ };
93
+ _ts_decorate([
94
+ (0, _common.Post)('forgot-password'),
95
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
96
+ (0, _throttler.Throttle)({
97
+ default: {
98
+ limit: 3,
99
+ ttl: 300000
100
+ }
101
+ }),
102
+ (0, _swagger.ApiOperation)({
103
+ summary: 'Request password reset email'
104
+ }),
105
+ (0, _swagger.ApiBody)({
106
+ type: _authenticationdto.ForgotPasswordDto
107
+ }),
108
+ (0, _swagger.ApiResponse)({
109
+ status: 200,
110
+ type: _dtos.MessageResponseDto
111
+ }),
112
+ _ts_param(0, (0, _common.Req)()),
113
+ _ts_param(1, (0, _common.Body)()),
114
+ _ts_metadata("design:type", Function),
115
+ _ts_metadata("design:paramtypes", [
116
+ typeof _express.Request === "undefined" ? Object : _express.Request,
117
+ typeof _authenticationdto.ForgotPasswordDto === "undefined" ? Object : _authenticationdto.ForgotPasswordDto
118
+ ]),
119
+ _ts_metadata("design:returntype", Promise)
120
+ ], EmailVerificationController.prototype, "forgotPassword", null);
121
+ _ts_decorate([
122
+ (0, _common.Post)('reset-password'),
123
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
124
+ (0, _throttler.Throttle)({
125
+ default: {
126
+ limit: 5,
127
+ ttl: 900000
128
+ }
129
+ }),
130
+ (0, _swagger.ApiOperation)({
131
+ summary: 'Reset password using token'
132
+ }),
133
+ (0, _swagger.ApiBody)({
134
+ type: _authenticationdto.ResetPasswordDto
135
+ }),
136
+ (0, _swagger.ApiResponse)({
137
+ status: 200,
138
+ type: _dtos.MessageResponseDto
139
+ }),
140
+ _ts_param(0, (0, _common.Body)()),
141
+ _ts_metadata("design:type", Function),
142
+ _ts_metadata("design:paramtypes", [
143
+ typeof _authenticationdto.ResetPasswordDto === "undefined" ? Object : _authenticationdto.ResetPasswordDto
144
+ ]),
145
+ _ts_metadata("design:returntype", Promise)
146
+ ], EmailVerificationController.prototype, "resetPassword", null);
147
+ _ts_decorate([
148
+ (0, _common.Post)('resend-verification'),
149
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
150
+ (0, _throttler.Throttle)({
151
+ default: {
152
+ limit: 3,
153
+ ttl: 300000
154
+ }
155
+ }),
156
+ (0, _swagger.ApiOperation)({
157
+ summary: 'Resend email verification link'
158
+ }),
159
+ (0, _swagger.ApiBody)({
160
+ type: _authenticationdto.ResendVerificationDto
161
+ }),
162
+ (0, _swagger.ApiResponse)({
163
+ status: 200,
164
+ type: _dtos.MessageResponseDto
165
+ }),
166
+ _ts_param(0, (0, _common.Req)()),
167
+ _ts_param(1, (0, _common.Body)()),
168
+ _ts_metadata("design:type", Function),
169
+ _ts_metadata("design:paramtypes", [
170
+ typeof _express.Request === "undefined" ? Object : _express.Request,
171
+ typeof _authenticationdto.ResendVerificationDto === "undefined" ? Object : _authenticationdto.ResendVerificationDto
172
+ ]),
173
+ _ts_metadata("design:returntype", Promise)
174
+ ], EmailVerificationController.prototype, "resendVerification", null);
175
+ _ts_decorate([
176
+ (0, _common.Post)('verify-email'),
177
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
178
+ (0, _throttler.Throttle)({
179
+ default: {
180
+ limit: 10,
181
+ ttl: 60000
182
+ }
183
+ }),
184
+ (0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
185
+ (0, _swagger.ApiOperation)({
186
+ summary: 'Verify email using token'
187
+ }),
188
+ (0, _swagger.ApiBody)({
189
+ type: _authenticationdto.VerifyEmailDto
190
+ }),
191
+ (0, _swagger.ApiResponse)({
192
+ status: 200,
193
+ type: _dtos.MessageResponseDto
194
+ }),
195
+ (0, _swagger.ApiResponse)({
196
+ status: 200,
197
+ type: _authenticationdto.RegistrationResponseDto
198
+ }),
199
+ _ts_param(0, (0, _common.Body)()),
200
+ _ts_metadata("design:type", Function),
201
+ _ts_metadata("design:paramtypes", [
202
+ typeof _authenticationdto.VerifyEmailDto === "undefined" ? Object : _authenticationdto.VerifyEmailDto
203
+ ]),
204
+ _ts_metadata("design:returntype", Promise)
205
+ ], EmailVerificationController.prototype, "verifyEmail", null);
206
+ EmailVerificationController = _ts_decorate([
207
+ (0, _swagger.ApiTags)('Authentication'),
208
+ (0, _common.Controller)('auth'),
209
+ _ts_param(0, (0, _common.Inject)(_authenticationservice.AuthenticationService)),
210
+ _ts_param(1, (0, _common.Inject)(_authemailservice.AuthEmailService)),
211
+ _ts_param(2, (0, _common.Inject)(_authconfigservice.AuthConfigService)),
212
+ _ts_param(3, (0, _common.Inject)(_authdatasourceprovider.AuthDataSourceProvider)),
213
+ _ts_metadata("design:type", Function),
214
+ _ts_metadata("design:paramtypes", [
215
+ typeof _authenticationservice.AuthenticationService === "undefined" ? Object : _authenticationservice.AuthenticationService,
216
+ typeof _authemailservice.AuthEmailService === "undefined" ? Object : _authemailservice.AuthEmailService,
217
+ typeof _authconfigservice.AuthConfigService === "undefined" ? Object : _authconfigservice.AuthConfigService,
218
+ typeof _authdatasourceprovider.AuthDataSourceProvider === "undefined" ? Object : _authdatasourceprovider.AuthDataSourceProvider
219
+ ])
220
+ ], EmailVerificationController);
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  _export_star(require("./authentication.controller"), exports);
6
6
  _export_star(require("./company-selection.controller"), exports);
7
+ _export_star(require("./email-verification.controller"), exports);
7
8
  _export_star(require("./user.controller"), exports);
8
9
  _export_star(require("./company.controller"), exports);
9
10
  _export_star(require("./branch.controller"), exports);
@@ -126,13 +126,12 @@ let RegistrationDto = class RegistrationDto {
126
126
  _define_property(this, "email", void 0);
127
127
  _define_property(this, "password", void 0);
128
128
  _define_property(this, "phone", void 0);
129
- // Company Feature Fields (Optional - only used when company feature is enabled)
130
129
  _define_property(this, "companySlug", void 0);
131
130
  _define_property(this, "branchSlug", void 0);
132
- // New Company Creation Fields (Optional - for creating new company)
133
131
  _define_property(this, "newCompanyName", void 0);
134
132
  _define_property(this, "newCompanyPhone", void 0);
135
133
  _define_property(this, "newCompanyAddress", void 0);
134
+ _define_property(this, "additionalFields", void 0);
136
135
  }
137
136
  };
138
137
  _ts_decorate([
@@ -226,6 +225,17 @@ _ts_decorate([
226
225
  (0, _classvalidator.MaxLength)(500),
227
226
  _ts_metadata("design:type", String)
228
227
  ], RegistrationDto.prototype, "newCompanyAddress", void 0);
228
+ _ts_decorate([
229
+ (0, _swagger.ApiPropertyOptional)({
230
+ example: {
231
+ prevCompanyName: 'Acme Corp',
232
+ employeeId: 'EMP001'
233
+ },
234
+ description: 'Additional fields for profile extension (handled by USER_ENRICHER)'
235
+ }),
236
+ (0, _classvalidator.IsOptional)(),
237
+ _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
238
+ ], RegistrationDto.prototype, "additionalFields", void 0);
229
239
  let RefreshTokenDto = class RefreshTokenDto {
230
240
  constructor(){
231
241
  _define_property(this, "refreshToken", void 0);
@@ -9,15 +9,6 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- get AllEntities () {
13
- return AllEntities;
14
- },
15
- get CompanyEntities () {
16
- return CompanyEntities;
17
- },
18
- get CoreEntities () {
19
- return CoreEntities;
20
- },
21
12
  get PermissionType () {
22
13
  return _usercompanypermissionentity.PermissionType;
23
14
  },
@@ -47,9 +38,11 @@ function _export_star(from, to) {
47
38
  });
48
39
  return from;
49
40
  }
50
- const CoreEntities = [
41
+ const BaseEntities = [
51
42
  _userentity.User,
52
- _usertokenentity.UserToken,
43
+ _usertokenentity.UserToken
44
+ ];
45
+ const EmailEntities = [
53
46
  _pendingregistrationentity.PendingRegistration
54
47
  ];
55
48
  const CompanyEntities = [
@@ -57,10 +50,16 @@ const CompanyEntities = [
57
50
  _companybranchentity.CompanyBranch,
58
51
  _usercompanypermissionentity.UserCompanyPermission
59
52
  ];
60
- const AllEntities = [
61
- ...CoreEntities,
62
- ...CompanyEntities
63
- ];
64
- function getEntitiesByConfig(enableCompanyFeature) {
65
- return enableCompanyFeature ? AllEntities : CoreEntities;
53
+ function getEntitiesByConfig(config) {
54
+ const { enableCompanyFeature = false, enableEmailVerification = true } = config;
55
+ const entities = [
56
+ ...BaseEntities
57
+ ];
58
+ if (enableEmailVerification) {
59
+ entities.push(...EmailEntities);
60
+ }
61
+ if (enableCompanyFeature) {
62
+ entities.push(...CompanyEntities);
63
+ }
64
+ return entities;
66
65
  }
@@ -41,6 +41,7 @@ let PendingRegistration = class PendingRegistration {
41
41
  _define_property(this, "token", void 0);
42
42
  _define_property(this, "expiresAt", void 0);
43
43
  _define_property(this, "companyData", void 0);
44
+ _define_property(this, "additionalFields", void 0);
44
45
  _define_property(this, "createdAt", void 0);
45
46
  }
46
47
  };
@@ -100,6 +101,14 @@ _ts_decorate([
100
101
  }),
101
102
  _ts_metadata("design:type", Object)
102
103
  ], PendingRegistration.prototype, "companyData", void 0);
104
+ _ts_decorate([
105
+ (0, _typeorm.Column)({
106
+ type: 'json',
107
+ nullable: true,
108
+ name: 'additional_fields'
109
+ }),
110
+ _ts_metadata("design:type", Object)
111
+ ], PendingRegistration.prototype, "additionalFields", void 0);
103
112
  _ts_decorate([
104
113
  (0, _typeorm.CreateDateColumn)({
105
114
  type: 'timestamp',
@@ -46,9 +46,9 @@ let AuthModule = class AuthModule {
46
46
  ...options.providers ?? []
47
47
  ], options.imports);
48
48
  }
49
- /** Build the dynamic module with shared logic */ static buildModule(options, providers, externalImports = []) {
49
+ static buildModule(options, providers, externalImports = []) {
50
50
  const { global = false, includeController = true, bootstrapAppConfig } = options;
51
- const enableCompanyFeature = bootstrapAppConfig?.enableCompanyFeature ?? false;
51
+ const featureFlags = this.getFeatureFlags(bootstrapAppConfig);
52
52
  return {
53
53
  module: AuthModule,
54
54
  global,
@@ -56,15 +56,21 @@ let AuthModule = class AuthModule {
56
56
  ...externalImports,
57
57
  ...this.buildImports()
58
58
  ],
59
- controllers: this.buildControllers(includeController, enableCompanyFeature),
59
+ controllers: this.buildControllers(includeController, featureFlags),
60
60
  providers: [
61
61
  ...providers,
62
- ...this.buildProviders(enableCompanyFeature)
62
+ ...this.buildProviders(featureFlags)
63
63
  ],
64
- exports: this.buildExports(enableCompanyFeature)
64
+ exports: this.buildExports(featureFlags)
65
65
  };
66
66
  }
67
- /** Common module imports */ static buildImports() {
67
+ static getFeatureFlags(bootstrapAppConfig) {
68
+ return {
69
+ enableCompanyFeature: bootstrapAppConfig?.enableCompanyFeature ?? false,
70
+ enableEmailVerification: bootstrapAppConfig?.enableEmailVerification ?? true
71
+ };
72
+ }
73
+ static buildImports() {
68
74
  return [
69
75
  _passport.PassportModule.register({
70
76
  defaultStrategy: 'jwt'
@@ -74,35 +80,40 @@ let AuthModule = class AuthModule {
74
80
  _modules.UtilsModule
75
81
  ];
76
82
  }
77
- /** Build controllers based on feature flags */ static buildControllers(includeController, enableCompanyFeature) {
83
+ static buildControllers(includeController, flags) {
78
84
  if (!includeController) return [];
79
85
  const controllers = [
80
86
  _controllers.AuthenticationController,
81
87
  _controllers.UserController
82
88
  ];
83
- if (enableCompanyFeature) {
89
+ if (flags.enableEmailVerification) {
90
+ controllers.push(_controllers.EmailVerificationController);
91
+ }
92
+ if (flags.enableCompanyFeature) {
84
93
  controllers.push(_controllers.CompanySelectionController, _controllers.CompanyController, _controllers.BranchController, _controllers.UserPermissionController);
85
94
  }
86
95
  return controllers;
87
96
  }
88
- /** Core providers (without AUTH_MODULE_OPTIONS - that's added separately) */ static buildProviders(enableCompanyFeature) {
97
+ static buildProviders(flags) {
89
98
  const providers = [
90
99
  _authconfigservice.AuthConfigService,
91
100
  _authdatasourceprovider.AuthDataSourceProvider,
92
101
  _jwtstrategy.JwtStrategy,
93
102
  _guards.JwtAuthGuard,
94
103
  _services.AuthenticationService,
95
- _services.AuthEmailService,
96
104
  _settokeninterceptor.SetToken,
97
105
  _cleartokeninterceptor.ClearToken,
98
106
  _services.UserService
99
107
  ];
100
- if (enableCompanyFeature) {
108
+ if (flags.enableEmailVerification) {
109
+ providers.push(_services.AuthEmailService);
110
+ }
111
+ if (flags.enableCompanyFeature) {
101
112
  providers.push(_services.CompanySelectionSessionService, _services.CompanyService, _services.BranchService, _services.UserPermissionService);
102
113
  }
103
114
  return providers;
104
115
  }
105
- /** Build module exports */ static buildExports(enableCompanyFeature) {
116
+ static buildExports(flags) {
106
117
  const exports1 = [
107
118
  _passport.PassportModule,
108
119
  _authconstants.AUTH_MODULE_OPTIONS,
@@ -111,15 +122,17 @@ let AuthModule = class AuthModule {
111
122
  _jwtstrategy.JwtStrategy,
112
123
  _guards.JwtAuthGuard,
113
124
  _services.AuthenticationService,
114
- _services.AuthEmailService,
115
125
  _services.UserService
116
126
  ];
117
- if (enableCompanyFeature) {
127
+ if (flags.enableEmailVerification) {
128
+ exports1.push(_services.AuthEmailService);
129
+ }
130
+ if (flags.enableCompanyFeature) {
118
131
  exports1.push(_services.CompanySelectionSessionService, _services.CompanyService, _services.BranchService, _services.UserPermissionService);
119
132
  }
120
133
  return exports1;
121
134
  }
122
- /** Create async providers for forRootAsync */ static createAsyncProviders(options) {
135
+ static createAsyncProviders(options) {
123
136
  const staticOptions = {
124
137
  global: options.global,
125
138
  includeController: options.includeController,
@@ -176,15 +189,11 @@ let AuthModule = class AuthModule {
176
189
  }
177
190
  ];
178
191
  }
179
- /** Get auth entities based on feature flags */ static getEntities(enableCompanyFeature = false) {
180
- return enableCompanyFeature ? [
181
- _entities.User,
182
- _entities.Company,
183
- _entities.CompanyBranch,
184
- _entities.UserCompanyPermission
185
- ] : [
186
- _entities.User
187
- ];
192
+ static getEntities(config) {
193
+ return (0, _entities.getEntitiesByConfig)({
194
+ enableCompanyFeature: config.enableCompanyFeature ?? false,
195
+ enableEmailVerification: config.enableEmailVerification ?? true
196
+ });
188
197
  }
189
198
  };
190
199
  AuthModule = _ts_decorate([