@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
@@ -71,12 +71,13 @@ export declare class LoginResponseDto {
71
71
  companyFeatureEnabled?: boolean;
72
72
  }
73
73
  export declare class RegistrationResponseDto {
74
- accessToken: string;
75
- refreshToken: string;
74
+ accessToken?: string;
75
+ refreshToken?: string;
76
76
  user: UserInfoDto;
77
77
  company?: CompanyInfoDto;
78
78
  branch?: BranchInfoDto;
79
- companyFeatureEnabled: boolean;
79
+ companyFeatureEnabled?: boolean;
80
+ requiresEmailVerification?: boolean;
80
81
  }
81
82
  export declare class MeResponseDto {
82
83
  user: UserInfoDto;
@@ -90,3 +91,20 @@ export declare class CompanySelectionResponseDto {
90
91
  user: UserInfoDto;
91
92
  companies: CompanyWithBranchesDto[];
92
93
  }
94
+ export declare class LoginResponseRequiresEmailVerificationDto {
95
+ requiresEmailVerification: true;
96
+ email: string;
97
+ message: string;
98
+ }
99
+ export declare class ForgotPasswordDto {
100
+ email: string;
101
+ }
102
+ export declare class ResetPasswordDto {
103
+ token: string;
104
+ newPassword: string;
105
+ }
106
+ export declare class VerifyEmailDto {
107
+ token: string;
108
+ }
109
+ export declare class ResendVerificationDto extends ForgotPasswordDto {
110
+ }
@@ -1,5 +1,4 @@
1
1
  export declare class CreateCompanyBranchDto {
2
- [key: string]: unknown;
3
2
  name: string;
4
3
  slug: string;
5
4
  companyId: string;
@@ -1,5 +1,4 @@
1
1
  export declare class CreateCompanyDto {
2
- [key: string]: unknown;
3
2
  name: string;
4
3
  slug: string;
5
4
  logoId?: string;
@@ -26,8 +26,12 @@ export declare class UserBranchPermissionDto {
26
26
  companyId: string;
27
27
  }
28
28
  export declare class UserCompaniesResponseDto {
29
+ success: boolean;
30
+ message: string;
29
31
  data: UserCompanyPermissionDto[];
30
32
  }
31
33
  export declare class UserBranchesResponseDto {
34
+ success: boolean;
35
+ message: string;
32
36
  data: UserBranchPermissionDto[];
33
37
  }
@@ -1,5 +1,4 @@
1
1
  export declare class CreateUserDto {
2
- [key: string]: unknown;
3
2
  name: string;
4
3
  phone?: string;
5
4
  email: string;
@@ -16,6 +15,7 @@ export declare class UpdateUserDto {
16
15
  phone?: string;
17
16
  email?: string;
18
17
  password?: string;
18
+ oldPassword?: string;
19
19
  profilePictureId?: string;
20
20
  isActive?: boolean;
21
21
  emailVerified?: boolean;
@@ -23,7 +23,6 @@ export declare class UpdateUserDto {
23
23
  additionalFields?: Record<string, any>;
24
24
  }
25
25
  export declare class UserResponseDto {
26
- [key: string]: unknown;
27
26
  id: string;
28
27
  name: string;
29
28
  phone?: string | null;
@@ -1,12 +1,16 @@
1
1
  export * from './company-branch.entity';
2
2
  export * from './company.entity';
3
+ export * from './pending-registration.entity';
3
4
  export { PermissionType, UserCompanyPermission } from './user-company-permission.entity';
4
5
  export * from './user.entity';
6
+ export * from './user-token.entity';
5
7
  import { CompanyBranch } from './company-branch.entity';
6
8
  import { Company } from './company.entity';
9
+ import { PendingRegistration } from './pending-registration.entity';
7
10
  import { UserCompanyPermission } from './user-company-permission.entity';
8
11
  import { User } from './user.entity';
9
- export declare const CoreEntities: (typeof User)[];
12
+ import { UserToken } from './user-token.entity';
13
+ export declare const CoreEntities: (typeof PendingRegistration | typeof User | typeof UserToken)[];
10
14
  export declare const CompanyEntities: (typeof Company | typeof CompanyBranch | typeof UserCompanyPermission)[];
11
- export declare const AllEntities: (typeof Company | typeof CompanyBranch | typeof User | typeof UserCompanyPermission)[];
12
- export declare function getEntitiesByConfig(enableCompanyFeature: boolean): (typeof Company | typeof CompanyBranch | typeof User | typeof UserCompanyPermission)[];
15
+ export declare const AllEntities: (typeof Company | typeof CompanyBranch | typeof PendingRegistration | typeof User | typeof UserCompanyPermission | typeof UserToken)[];
16
+ export declare function getEntitiesByConfig(enableCompanyFeature: boolean): (typeof Company | typeof CompanyBranch | typeof PendingRegistration | typeof User | typeof UserCompanyPermission | typeof UserToken)[];
@@ -0,0 +1,17 @@
1
+ export declare class PendingRegistration {
2
+ id: string;
3
+ email: string;
4
+ name: string | null;
5
+ phone: string | null;
6
+ passwordHash: string;
7
+ token: string;
8
+ expiresAt: Date;
9
+ companyData: {
10
+ companySlug?: string;
11
+ branchSlug?: string;
12
+ newCompanyName?: string;
13
+ newCompanyPhone?: string;
14
+ newCompanyAddress?: string;
15
+ } | null;
16
+ createdAt: Date;
17
+ }
@@ -15,6 +15,4 @@ export declare class UserCompanyPermission {
15
15
  branch?: CompanyBranch;
16
16
  createdAt: Date;
17
17
  updatedAt: Date;
18
- isCompanyPermission(): boolean;
19
- isBranchPermission(): boolean;
20
18
  }
@@ -0,0 +1,15 @@
1
+ export declare enum TokenType {
2
+ PASSWORD_RESET = "password_reset",
3
+ EMAIL_VERIFICATION = "email_verification",
4
+ EMAIL_CHANGE = "email_change"
5
+ }
6
+ export declare class UserToken {
7
+ id: string;
8
+ userId: string;
9
+ type: TokenType;
10
+ token: string;
11
+ expiresAt: Date;
12
+ usedAt: Date | null;
13
+ metadata: string | null;
14
+ createdAt: Date;
15
+ }
@@ -1,8 +1,11 @@
1
- // =============================================================================
2
- // INJECTION TOKENS
3
- // =============================================================================
4
- /** Injection token for auth module options */ export const AUTH_MODULE_OPTIONS = 'AUTH_MODULE_OPTIONS';
5
- // =============================================================================
6
- // CACHE KEY PREFIXES (Auth-specific)
7
- // =============================================================================
8
- /** Cache key prefix for authentication sessions */ export const SESSION_CACHE_PREFIX = 'auth:session';
1
+ // Injection Tokens
2
+ export const AUTH_MODULE_OPTIONS = 'AUTH_MODULE_OPTIONS';
3
+ export const USER_ENRICHER = 'USER_ENRICHER';
4
+ // Security
5
+ export const BCRYPT_SALT_ROUNDS = 12;
6
+ // Cookie
7
+ export const DEFAULT_COOKIE_NAME = 'fsn_refresh_token';
8
+ export const MAX_COOKIE_BYTES = 3500;
9
+ // Cache Key Prefixes
10
+ export const SESSION_CACHE_PREFIX = 'auth:session';
11
+ export const TOKEN_REVOKED_PREFIX = 'auth:revoked';
@@ -28,46 +28,38 @@ function _ts_param(paramIndex, decorator) {
28
28
  import { CurrentUser } from '@flusys/nestjs-shared/decorators';
29
29
  import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
30
30
  import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
31
- import { Body, Controller, Get, HttpCode, HttpStatus, Inject, Optional, Post, Req, UnauthorizedException, UseGuards, UseInterceptors } from '@nestjs/common';
31
+ import { Body, Controller, HttpCode, HttpStatus, Inject, Optional, Post, Req, UnauthorizedException, UseGuards, UseInterceptors } from '@nestjs/common';
32
32
  import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
33
+ import { SkipThrottle, Throttle } from '@nestjs/throttler';
33
34
  import { Request } from 'express';
34
- import { ChangePasswordDto, CompanySelectionResponseDto, LoginDto, LoginResponseDto, MeResponseDto, RefreshTokenDto, RegistrationDto, RegistrationResponseDto } from '../dtos/authentication.dto';
35
+ import { ChangePasswordDto, CompanySelectionResponseDto, ForgotPasswordDto, LoginDto, LoginResponseDto, MeResponseDto, RefreshTokenDto, RegistrationDto, RegistrationResponseDto, ResendVerificationDto, ResetPasswordDto, VerifyEmailDto } from '../dtos/authentication.dto';
36
+ import { MessageResponseDto } from '@flusys/nestjs-shared/dtos';
35
37
  import { ClearToken } from '../interceptors/clear-token.interceptor';
36
38
  import { SetToken } from '../interceptors/set-token.interceptor';
37
39
  import { AuthConfigService } from '../services/auth-config.service';
40
+ import { AuthEmailService } from '../services/auth-email.service';
38
41
  import { AuthenticationService } from '../services/authentication.service';
39
42
  export class AuthenticationController {
40
- // ==========================================================================
41
- // CORE ENDPOINTS (Always available)
42
- // ==========================================================================
43
- /**
44
- * Login
45
- * Returns either tokens directly or company/branch selection requirement
46
- * Browser: refreshToken set in HTTP-only cookie, not in response body
47
- * API/Mobile: refreshToken included in response body
48
- */ async login(loginDto) {
43
+ buildAuthUrl(req, path) {
44
+ const frontendUrl = this.authConfig?.getFrontendUrl();
45
+ return frontendUrl ? `${frontendUrl}${path}` : `${req.protocol}://${req.get('host')}${path}`;
46
+ }
47
+ async login(loginDto) {
49
48
  const result = await this.authService.login(loginDto.email, loginDto.password);
50
49
  if ('requiresSelection' in result) {
51
50
  return result;
52
51
  }
53
52
  return result;
54
53
  }
55
- /**
56
- * Register new user
57
- * If company feature enabled, can optionally join/create company
58
- * Browser: refreshToken set in HTTP-only cookie
59
- */ async register(registrationDto) {
60
- const result = await this.authService.register(registrationDto);
54
+ /** Register new user. If company feature enabled, can join/create company. */ async register(req, registrationDto) {
55
+ const verifyUrlBase = this.buildAuthUrl(req, '/auth/verify-email');
56
+ const result = await this.authService.register(registrationDto, verifyUrlBase);
61
57
  return {
62
58
  ...result,
63
59
  companyFeatureEnabled: this.authConfig?.isCompanyFeatureEnabled() ?? false
64
60
  };
65
61
  }
66
- /**
67
- * Refresh access token
68
- * Browser: Gets refreshToken from HTTP-only cookie
69
- * API/Mobile: Gets refreshToken from request body
70
- */ async refreshToken(req, refreshTokenDto) {
62
+ /** Refresh access token. Browser uses HTTP-only cookie, API/Mobile uses request body. */ async refreshToken(req, refreshTokenDto) {
71
63
  // Get refresh token from cookie (browser) or body (API/mobile)
72
64
  const cookieName = this.authConfig?.getRefreshTokenCookieName() ?? 'fsn_refresh_token';
73
65
  const refreshToken = req.cookies?.[cookieName] || refreshTokenDto.refreshToken;
@@ -76,42 +68,88 @@ export class AuthenticationController {
76
68
  }
77
69
  return this.authService.refreshToken(refreshToken);
78
70
  }
79
- /**
80
- * Get current user info
81
- * Returns only user, company, and branch data (no tokens)
82
- * Uses existing access token from Authorization header
83
- * Company/branch fields are automatically excluded from Swagger when company feature is disabled
84
- */ async getCurrentUser(user) {
71
+ /** Get current user info. Returns user, company, and branch data (no tokens). */ async getCurrentUser(user) {
85
72
  return this.authService.getUserInfo(user.id, user.companyId, user.branchId);
86
73
  }
87
- /**
88
- * Logout
89
- * Clears refresh token cookie for browsers
90
- */ async logout(userId) {
74
+ /** Logout - Clears refresh token cookie for browsers */ async logout(userId) {
91
75
  await this.authService.logout(userId);
92
76
  return {
77
+ success: true,
93
78
  message: 'Logged out successfully'
94
79
  };
95
80
  }
96
- /**
97
- * Change password
98
- */ async changePassword(userId, dto) {
81
+ async changePassword(userId, dto) {
99
82
  await this.authService.changePassword(userId, dto.currentPassword, dto.newPassword);
100
83
  return {
84
+ success: true,
101
85
  message: 'Password changed successfully'
102
86
  };
103
87
  }
104
- // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
105
- constructor(authService, authConfig){
88
+ async forgotPassword(req, dto) {
89
+ if (!this.authEmailService) {
90
+ return {
91
+ success: false,
92
+ message: 'Email service is not configured'
93
+ };
94
+ }
95
+ return this.authEmailService.forgotPassword(dto.email, this.buildAuthUrl(req, '/auth/reset-password'));
96
+ }
97
+ async resetPassword(dto) {
98
+ if (!this.authEmailService) {
99
+ return {
100
+ success: false,
101
+ message: 'Email service is not configured'
102
+ };
103
+ }
104
+ return this.authEmailService.resetPassword(dto.token, dto.newPassword);
105
+ }
106
+ async resendVerification(req, dto) {
107
+ if (!this.authEmailService) {
108
+ return {
109
+ success: false,
110
+ message: 'Email service is not configured'
111
+ };
112
+ }
113
+ return this.authEmailService.resendVerificationEmail(dto.email, this.buildAuthUrl(req, '/auth/verify-email'));
114
+ }
115
+ /** Verify email - Verify email using token. Handles both pending registration and existing user verification. */ async verifyEmail(dto) {
116
+ if (!this.authEmailService) {
117
+ return {
118
+ success: false,
119
+ message: 'Email service is not configured'
120
+ };
121
+ }
122
+ const result = await this.authEmailService.verifyEmail(dto.token);
123
+ if (result.type === 'pending') {
124
+ const registrationResult = await this.authService.createUserFromPendingRegistration(result.pending);
125
+ return {
126
+ ...registrationResult,
127
+ companyFeatureEnabled: this.authConfig?.isCompanyFeatureEnabled() ?? false
128
+ };
129
+ }
130
+ return {
131
+ success: true,
132
+ message: result.message
133
+ };
134
+ }
135
+ constructor(authService, authConfig, authEmailService){
106
136
  _define_property(this, "authService", void 0);
107
137
  _define_property(this, "authConfig", void 0);
138
+ _define_property(this, "authEmailService", void 0);
108
139
  this.authService = authService;
109
140
  this.authConfig = authConfig;
141
+ this.authEmailService = authEmailService;
110
142
  }
111
143
  }
112
144
  _ts_decorate([
113
145
  Post('login'),
114
146
  HttpCode(HttpStatus.OK),
147
+ Throttle({
148
+ default: {
149
+ limit: 5,
150
+ ttl: 60000
151
+ }
152
+ }),
115
153
  UseInterceptors(SetToken),
116
154
  ApiOperation({
117
155
  summary: 'User login'
@@ -137,6 +175,12 @@ _ts_decorate([
137
175
  _ts_decorate([
138
176
  Post('register'),
139
177
  HttpCode(HttpStatus.CREATED),
178
+ Throttle({
179
+ default: {
180
+ limit: 3,
181
+ ttl: 60000
182
+ }
183
+ }),
140
184
  UseInterceptors(SetToken),
141
185
  ApiOperation({
142
186
  summary: 'Register new user'
@@ -148,9 +192,11 @@ _ts_decorate([
148
192
  status: 201,
149
193
  type: RegistrationResponseDto
150
194
  }),
151
- _ts_param(0, Body()),
195
+ _ts_param(0, Req()),
196
+ _ts_param(1, Body()),
152
197
  _ts_metadata("design:type", Function),
153
198
  _ts_metadata("design:paramtypes", [
199
+ typeof Request === "undefined" ? Object : Request,
154
200
  typeof RegistrationDto === "undefined" ? Object : RegistrationDto
155
201
  ]),
156
202
  _ts_metadata("design:returntype", Promise)
@@ -158,6 +204,12 @@ _ts_decorate([
158
204
  _ts_decorate([
159
205
  Post('refresh'),
160
206
  HttpCode(HttpStatus.OK),
207
+ Throttle({
208
+ default: {
209
+ limit: 30,
210
+ ttl: 60000
211
+ }
212
+ }),
161
213
  ApiOperation({
162
214
  summary: 'Refresh access token'
163
215
  }),
@@ -175,7 +227,8 @@ _ts_decorate([
175
227
  ], AuthenticationController.prototype, "refreshToken", null);
176
228
  _ts_decorate([
177
229
  UseGuards(JwtAuthGuard),
178
- Get('me'),
230
+ Post('me'),
231
+ SkipThrottle(),
179
232
  ApiBearerAuth(),
180
233
  ApiOperation({
181
234
  summary: 'Get current user info'
@@ -195,11 +248,16 @@ _ts_decorate([
195
248
  UseGuards(JwtAuthGuard),
196
249
  Post('logout'),
197
250
  HttpCode(HttpStatus.OK),
251
+ SkipThrottle(),
198
252
  UseInterceptors(ClearToken),
199
253
  ApiBearerAuth(),
200
254
  ApiOperation({
201
255
  summary: 'Logout user'
202
256
  }),
257
+ ApiResponse({
258
+ status: 200,
259
+ type: MessageResponseDto
260
+ }),
203
261
  _ts_param(0, CurrentUser('id')),
204
262
  _ts_metadata("design:type", Function),
205
263
  _ts_metadata("design:paramtypes", [
@@ -211,6 +269,12 @@ _ts_decorate([
211
269
  UseGuards(JwtAuthGuard),
212
270
  Post('change-password'),
213
271
  HttpCode(HttpStatus.OK),
272
+ Throttle({
273
+ default: {
274
+ limit: 5,
275
+ ttl: 60000
276
+ }
277
+ }),
214
278
  ApiBearerAuth(),
215
279
  ApiOperation({
216
280
  summary: 'Change password'
@@ -218,6 +282,10 @@ _ts_decorate([
218
282
  ApiBody({
219
283
  type: ChangePasswordDto
220
284
  }),
285
+ ApiResponse({
286
+ status: 200,
287
+ type: MessageResponseDto
288
+ }),
221
289
  _ts_param(0, CurrentUser('id')),
222
290
  _ts_param(1, Body()),
223
291
  _ts_metadata("design:type", Function),
@@ -227,15 +295,131 @@ _ts_decorate([
227
295
  ]),
228
296
  _ts_metadata("design:returntype", Promise)
229
297
  ], AuthenticationController.prototype, "changePassword", null);
298
+ _ts_decorate([
299
+ Post('forgot-password'),
300
+ HttpCode(HttpStatus.OK),
301
+ Throttle({
302
+ default: {
303
+ limit: 3,
304
+ ttl: 300000
305
+ }
306
+ }),
307
+ ApiOperation({
308
+ summary: 'Request password reset email'
309
+ }),
310
+ ApiBody({
311
+ type: ForgotPasswordDto
312
+ }),
313
+ ApiResponse({
314
+ status: 200,
315
+ type: MessageResponseDto
316
+ }),
317
+ _ts_param(0, Req()),
318
+ _ts_param(1, Body()),
319
+ _ts_metadata("design:type", Function),
320
+ _ts_metadata("design:paramtypes", [
321
+ typeof Request === "undefined" ? Object : Request,
322
+ typeof ForgotPasswordDto === "undefined" ? Object : ForgotPasswordDto
323
+ ]),
324
+ _ts_metadata("design:returntype", Promise)
325
+ ], AuthenticationController.prototype, "forgotPassword", null);
326
+ _ts_decorate([
327
+ Post('reset-password'),
328
+ HttpCode(HttpStatus.OK),
329
+ Throttle({
330
+ default: {
331
+ limit: 5,
332
+ ttl: 900000
333
+ }
334
+ }),
335
+ ApiOperation({
336
+ summary: 'Reset password using token'
337
+ }),
338
+ ApiBody({
339
+ type: ResetPasswordDto
340
+ }),
341
+ ApiResponse({
342
+ status: 200,
343
+ type: MessageResponseDto
344
+ }),
345
+ _ts_param(0, Body()),
346
+ _ts_metadata("design:type", Function),
347
+ _ts_metadata("design:paramtypes", [
348
+ typeof ResetPasswordDto === "undefined" ? Object : ResetPasswordDto
349
+ ]),
350
+ _ts_metadata("design:returntype", Promise)
351
+ ], AuthenticationController.prototype, "resetPassword", null);
352
+ _ts_decorate([
353
+ Post('resend-verification'),
354
+ HttpCode(HttpStatus.OK),
355
+ Throttle({
356
+ default: {
357
+ limit: 3,
358
+ ttl: 300000
359
+ }
360
+ }),
361
+ ApiOperation({
362
+ summary: 'Resend email verification link'
363
+ }),
364
+ ApiBody({
365
+ type: ResendVerificationDto
366
+ }),
367
+ ApiResponse({
368
+ status: 200,
369
+ type: MessageResponseDto
370
+ }),
371
+ _ts_param(0, Req()),
372
+ _ts_param(1, Body()),
373
+ _ts_metadata("design:type", Function),
374
+ _ts_metadata("design:paramtypes", [
375
+ typeof Request === "undefined" ? Object : Request,
376
+ typeof ResendVerificationDto === "undefined" ? Object : ResendVerificationDto
377
+ ]),
378
+ _ts_metadata("design:returntype", Promise)
379
+ ], AuthenticationController.prototype, "resendVerification", null);
380
+ _ts_decorate([
381
+ Post('verify-email'),
382
+ HttpCode(HttpStatus.OK),
383
+ Throttle({
384
+ default: {
385
+ limit: 10,
386
+ ttl: 60000
387
+ }
388
+ }),
389
+ UseInterceptors(SetToken),
390
+ ApiOperation({
391
+ summary: 'Verify email using token'
392
+ }),
393
+ ApiBody({
394
+ type: VerifyEmailDto
395
+ }),
396
+ ApiResponse({
397
+ status: 200,
398
+ type: MessageResponseDto
399
+ }),
400
+ ApiResponse({
401
+ status: 200,
402
+ type: RegistrationResponseDto
403
+ }),
404
+ _ts_param(0, Body()),
405
+ _ts_metadata("design:type", Function),
406
+ _ts_metadata("design:paramtypes", [
407
+ typeof VerifyEmailDto === "undefined" ? Object : VerifyEmailDto
408
+ ]),
409
+ _ts_metadata("design:returntype", Promise)
410
+ ], AuthenticationController.prototype, "verifyEmail", null);
230
411
  AuthenticationController = _ts_decorate([
231
412
  ApiTags('Authentication'),
232
413
  Controller('auth'),
233
414
  _ts_param(0, Inject(AuthenticationService)),
234
415
  _ts_param(1, Optional()),
235
416
  _ts_param(1, Inject(AuthConfigService)),
417
+ _ts_param(2, Optional()),
418
+ _ts_param(2, Inject(AuthEmailService)),
236
419
  _ts_metadata("design:type", Function),
237
420
  _ts_metadata("design:paramtypes", [
238
421
  typeof AuthenticationService === "undefined" ? Object : AuthenticationService,
239
- typeof AuthConfigService === "undefined" ? Object : AuthConfigService
422
+ typeof AuthConfigService === "undefined" ? Object : AuthConfigService,
423
+ typeof AuthEmailService === "undefined" ? Object : AuthEmailService
240
424
  ])
241
425
  ], AuthenticationController);
@@ -25,22 +25,64 @@ function _ts_param(paramIndex, decorator) {
25
25
  decorator(target, key, paramIndex);
26
26
  };
27
27
  }
28
- import { createApiController } from '@flusys/nestjs-shared/classes';
29
- import { Controller, Inject, UseGuards } from '@nestjs/common';
30
- import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
28
+ import { createApiController, BRANCH_PERMISSIONS } from '@flusys/nestjs-shared/classes';
29
+ import { Controller, Inject } from '@nestjs/common';
30
+ import { ApiTags } from '@nestjs/swagger';
31
31
  import { CompanyBranchResponseDto, CreateCompanyBranchDto, UpdateCompanyBranchDto } from '../dtos/company-branch.dto';
32
- import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
33
32
  import { BranchService } from '../services/branch.service';
34
- export class BranchController extends createApiController(CreateCompanyBranchDto, UpdateCompanyBranchDto, CompanyBranchResponseDto) {
33
+ export class BranchController extends createApiController(CreateCompanyBranchDto, UpdateCompanyBranchDto, CompanyBranchResponseDto, {
34
+ security: {
35
+ insert: {
36
+ level: 'permission',
37
+ permissions: [
38
+ BRANCH_PERMISSIONS.CREATE
39
+ ]
40
+ },
41
+ insertMany: {
42
+ level: 'permission',
43
+ permissions: [
44
+ BRANCH_PERMISSIONS.CREATE
45
+ ]
46
+ },
47
+ getById: {
48
+ level: 'permission',
49
+ permissions: [
50
+ BRANCH_PERMISSIONS.READ
51
+ ]
52
+ },
53
+ getAll: {
54
+ level: 'permission',
55
+ permissions: [
56
+ BRANCH_PERMISSIONS.READ
57
+ ]
58
+ },
59
+ update: {
60
+ level: 'permission',
61
+ permissions: [
62
+ BRANCH_PERMISSIONS.UPDATE
63
+ ]
64
+ },
65
+ updateMany: {
66
+ level: 'permission',
67
+ permissions: [
68
+ BRANCH_PERMISSIONS.UPDATE
69
+ ]
70
+ },
71
+ delete: {
72
+ level: 'permission',
73
+ permissions: [
74
+ BRANCH_PERMISSIONS.DELETE
75
+ ]
76
+ }
77
+ }
78
+ }) {
35
79
  constructor(branchService){
36
80
  super(branchService), _define_property(this, "branchService", void 0), this.branchService = branchService;
37
81
  }
38
82
  }
39
83
  BranchController = _ts_decorate([
40
84
  ApiTags('Branches'),
41
- ApiBearerAuth(),
42
85
  Controller('administration/branch'),
43
- UseGuards(JwtAuthGuard),
44
86
  _ts_param(0, Inject(BranchService)),
45
87
  _ts_metadata("design:type", Function),
46
88
  _ts_metadata("design:paramtypes", [