@flusys/nestjs-auth 0.1.0-beta.2 → 1.0.0-beta
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.
- package/README.md +1 -11
- package/cjs/config/auth.constants.js +10 -4
- package/cjs/controllers/authentication.controller.js +7 -32
- package/cjs/controllers/branch.controller.js +3 -4
- package/cjs/controllers/company.controller.js +3 -4
- package/cjs/controllers/user-permission.controller.js +6 -18
- package/cjs/controllers/user.controller.js +17 -22
- package/cjs/interfaces/authentication.interface.js +0 -3
- package/cjs/services/auth-config.service.js +18 -44
- package/cjs/services/auth-datasource.provider.js +13 -31
- package/cjs/services/authentication.service.js +80 -85
- package/cjs/services/branch.service.js +10 -44
- package/cjs/services/company.service.js +7 -36
- package/cjs/services/user-permission.service.js +9 -27
- package/cjs/services/user.service.js +33 -91
- package/cjs/strategies/jwt.strategy.js +14 -1
- package/config/auth.constants.d.ts +2 -0
- package/fesm/config/auth.constants.js +7 -8
- package/fesm/controllers/authentication.controller.js +7 -32
- package/fesm/controllers/branch.controller.js +5 -6
- package/fesm/controllers/company.controller.js +5 -6
- package/fesm/controllers/user-permission.controller.js +6 -18
- package/fesm/controllers/user.controller.js +17 -22
- package/fesm/dtos/authentication.dto.js +17 -97
- package/fesm/interfaces/authentication.interface.js +1 -7
- package/fesm/services/auth-config.service.js +18 -44
- package/fesm/services/auth-datasource.provider.js +13 -31
- package/fesm/services/authentication.service.js +78 -83
- package/fesm/services/branch.service.js +11 -45
- package/fesm/services/company.service.js +8 -37
- package/fesm/services/user-permission.service.js +9 -27
- package/fesm/services/user.service.js +34 -92
- package/fesm/strategies/jwt.strategy.js +14 -1
- package/package.json +4 -4
- package/services/authentication.service.d.ts +6 -2
- package/services/branch.service.d.ts +2 -5
- package/services/company.service.d.ts +1 -4
- package/services/user.service.d.ts +1 -3
package/README.md
CHANGED
|
@@ -763,14 +763,4 @@ The authentication package provides:
|
|
|
763
763
|
|
|
764
764
|
---
|
|
765
765
|
|
|
766
|
-
**Last Updated:** 2026-02-
|
|
767
|
-
**Version:** 4.1.6
|
|
768
|
-
|
|
769
|
-
**Recent Improvements:**
|
|
770
|
-
- 2026-02-09: Added explicit `@Inject()` decorators to all services for esbuild bundling compatibility
|
|
771
|
-
- 2026-02-09: All services now use REQUEST scope with DataSource Provider pattern
|
|
772
|
-
- 2026-02-07: Fixed entity diagram to show polymorphic design (permissionType/targetId)
|
|
773
|
-
- 2026-02-07: Updated service names to match actual implementation
|
|
774
|
-
- 2026-02-07: Simplified login flow diagrams
|
|
775
|
-
- 2026-01-15: Fixed JwtStrategy to use `ModuleRef` for request-scoped `AuthDataSourceProvider` resolution
|
|
776
|
-
- 2026-01-14: Added `UserPermissionController` for batch permission management
|
|
766
|
+
**Last Updated:** 2026-02-16
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
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,17 @@ _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
|
+
},
|
|
18
19
|
get SESSION_CACHE_PREFIX () {
|
|
19
20
|
return SESSION_CACHE_PREFIX;
|
|
21
|
+
},
|
|
22
|
+
get TOKEN_REVOKED_PREFIX () {
|
|
23
|
+
return TOKEN_REVOKED_PREFIX;
|
|
20
24
|
}
|
|
21
25
|
});
|
|
22
26
|
const AUTH_MODULE_OPTIONS = 'AUTH_MODULE_OPTIONS';
|
|
27
|
+
const BCRYPT_SALT_ROUNDS = 12;
|
|
23
28
|
const SESSION_CACHE_PREFIX = 'auth:session';
|
|
29
|
+
const TOKEN_REVOKED_PREFIX = 'auth:revoked';
|
|
@@ -47,37 +47,22 @@ function _ts_param(paramIndex, decorator) {
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
let AuthenticationController = class AuthenticationController {
|
|
50
|
-
//
|
|
51
|
-
|
|
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) {
|
|
50
|
+
// Core Endpoints
|
|
51
|
+
/** Login - Returns tokens or company/branch selection requirement */ async login(loginDto) {
|
|
59
52
|
const result = await this.authService.login(loginDto.email, loginDto.password);
|
|
60
53
|
if ('requiresSelection' in result) {
|
|
61
54
|
return result;
|
|
62
55
|
}
|
|
63
56
|
return result;
|
|
64
57
|
}
|
|
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) {
|
|
58
|
+
/** Register new user. If company feature enabled, can join/create company. */ async register(registrationDto) {
|
|
70
59
|
const result = await this.authService.register(registrationDto);
|
|
71
60
|
return {
|
|
72
61
|
...result,
|
|
73
62
|
companyFeatureEnabled: this.authConfig?.isCompanyFeatureEnabled() ?? false
|
|
74
63
|
};
|
|
75
64
|
}
|
|
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) {
|
|
65
|
+
/** Refresh access token. Browser uses HTTP-only cookie, API/Mobile uses request body. */ async refreshToken(req, refreshTokenDto) {
|
|
81
66
|
// Get refresh token from cookie (browser) or body (API/mobile)
|
|
82
67
|
const cookieName = this.authConfig?.getRefreshTokenCookieName() ?? 'fsn_refresh_token';
|
|
83
68
|
const refreshToken = req.cookies?.[cookieName] || refreshTokenDto.refreshToken;
|
|
@@ -86,26 +71,16 @@ let AuthenticationController = class AuthenticationController {
|
|
|
86
71
|
}
|
|
87
72
|
return this.authService.refreshToken(refreshToken);
|
|
88
73
|
}
|
|
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) {
|
|
74
|
+
/** Get current user info. Returns user, company, and branch data (no tokens). */ async getCurrentUser(user) {
|
|
95
75
|
return this.authService.getUserInfo(user.id, user.companyId, user.branchId);
|
|
96
76
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Logout
|
|
99
|
-
* Clears refresh token cookie for browsers
|
|
100
|
-
*/ async logout(userId) {
|
|
77
|
+
/** Logout - Clears refresh token cookie for browsers */ async logout(userId) {
|
|
101
78
|
await this.authService.logout(userId);
|
|
102
79
|
return {
|
|
103
80
|
message: 'Logged out successfully'
|
|
104
81
|
};
|
|
105
82
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Change password
|
|
108
|
-
*/ async changePassword(userId, dto) {
|
|
83
|
+
/** Change password */ async changePassword(userId, dto) {
|
|
109
84
|
await this.authService.changePassword(userId, dto.currentPassword, dto.newPassword);
|
|
110
85
|
return {
|
|
111
86
|
message: 'Password changed successfully'
|
|
@@ -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,16 @@ 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: 'jwt'
|
|
45
|
+
}) {
|
|
45
46
|
constructor(branchService){
|
|
46
47
|
super(branchService), _define_property(this, "branchService", void 0), this.branchService = branchService;
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
50
|
BranchController = _ts_decorate([
|
|
50
51
|
(0, _swagger.ApiTags)('Branches'),
|
|
51
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
52
52
|
(0, _common.Controller)('administration/branch'),
|
|
53
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
54
53
|
_ts_param(0, (0, _common.Inject)(_branchservice.BranchService)),
|
|
55
54
|
_ts_metadata("design:type", Function),
|
|
56
55
|
_ts_metadata("design:paramtypes", [
|
|
@@ -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,16 @@ 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: 'jwt'
|
|
45
|
+
}) {
|
|
45
46
|
constructor(companyService){
|
|
46
47
|
super(companyService), _define_property(this, "companyService", void 0), this.companyService = companyService;
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
50
|
CompanyController = _ts_decorate([
|
|
50
51
|
(0, _swagger.ApiTags)('Companies'),
|
|
51
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
52
52
|
(0, _common.Controller)('administration/company'),
|
|
53
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
54
53
|
_ts_param(0, (0, _common.Inject)(_companyservice.CompanyService)),
|
|
55
54
|
_ts_metadata("design:type", Function),
|
|
56
55
|
_ts_metadata("design:paramtypes", [
|
|
@@ -41,12 +41,8 @@ function _ts_param(paramIndex, decorator) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
let UserPermissionController = class UserPermissionController {
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
// ========================================================================
|
|
47
|
-
/**
|
|
48
|
-
* Batch assign/revoke user-company permissions
|
|
49
|
-
*/ async assignUserCompany(dto) {
|
|
44
|
+
// User-Company Permissions
|
|
45
|
+
/** Batch assign/revoke user-company permissions */ async assignUserCompany(dto) {
|
|
50
46
|
let addedCount = 0;
|
|
51
47
|
let removedCount = 0;
|
|
52
48
|
for (const item of dto.items){
|
|
@@ -66,9 +62,7 @@ let UserPermissionController = class UserPermissionController {
|
|
|
66
62
|
message: `Processed ${addedCount} additions and ${removedCount} removals`
|
|
67
63
|
};
|
|
68
64
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Get user's companies
|
|
71
|
-
*/ async getUserCompanies(userId) {
|
|
65
|
+
/** Get user's companies */ async getUserCompanies(userId) {
|
|
72
66
|
const permissions = await this.userPermissionService.findUserCompanies(userId);
|
|
73
67
|
// Map to DTO format with populated company details
|
|
74
68
|
const data = permissions.map((permission)=>({
|
|
@@ -82,12 +76,8 @@ let UserPermissionController = class UserPermissionController {
|
|
|
82
76
|
data
|
|
83
77
|
};
|
|
84
78
|
}
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
// ========================================================================
|
|
88
|
-
/**
|
|
89
|
-
* Batch assign/revoke user-branch permissions
|
|
90
|
-
*/ async assignUserBranch(dto) {
|
|
79
|
+
// User-Branch Permissions
|
|
80
|
+
/** Batch assign/revoke user-branch permissions */ async assignUserBranch(dto) {
|
|
91
81
|
let addedCount = 0;
|
|
92
82
|
let removedCount = 0;
|
|
93
83
|
for (const item of dto.items){
|
|
@@ -107,9 +97,7 @@ let UserPermissionController = class UserPermissionController {
|
|
|
107
97
|
message: `Processed ${addedCount} additions and ${removedCount} removals`
|
|
108
98
|
};
|
|
109
99
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Get user's branches
|
|
112
|
-
*/ async getUserBranches(userId) {
|
|
100
|
+
/** Get user's branches */ async getUserBranches(userId) {
|
|
113
101
|
const permissions = await this.userPermissionService.findUserBranches(userId);
|
|
114
102
|
// Map to DTO format with populated branch details
|
|
115
103
|
const data = permissions.map((permission)=>({
|
|
@@ -10,11 +10,11 @@ Object.defineProperty(exports, "UserController", {
|
|
|
10
10
|
});
|
|
11
11
|
const _classes = require("@flusys/nestjs-shared/classes");
|
|
12
12
|
const _decorators = require("@flusys/nestjs-shared/decorators");
|
|
13
|
+
const _guards = require("@flusys/nestjs-shared/guards");
|
|
13
14
|
const _interfaces = require("@flusys/nestjs-shared/interfaces");
|
|
14
15
|
const _common = require("@nestjs/common");
|
|
15
16
|
const _swagger = require("@nestjs/swagger");
|
|
16
17
|
const _userdto = require("../dtos/user.dto");
|
|
17
|
-
const _guards = require("@flusys/nestjs-shared/guards");
|
|
18
18
|
const _userservice = require("../services/user.service");
|
|
19
19
|
function _define_property(obj, key, value) {
|
|
20
20
|
if (key in obj) {
|
|
@@ -43,40 +43,29 @@ function _ts_param(paramIndex, decorator) {
|
|
|
43
43
|
decorator(target, key, paramIndex);
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
let UserController = class UserController extends (0, _classes.createApiController)(_userdto.CreateUserDto, _userdto.UpdateUserDto, _userdto.UserResponseDto
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
/**
|
|
51
|
-
* Verify user email
|
|
52
|
-
*/ async verifyEmail(id) {
|
|
46
|
+
let UserController = class UserController extends (0, _classes.createApiController)(_userdto.CreateUserDto, _userdto.UpdateUserDto, _userdto.UserResponseDto, {
|
|
47
|
+
security: 'jwt'
|
|
48
|
+
}) {
|
|
49
|
+
// Custom Endpoints
|
|
50
|
+
/** Verify user email */ async verifyEmail(id) {
|
|
53
51
|
await this.service.verifyEmail(id);
|
|
54
52
|
return {
|
|
55
53
|
message: 'Email verified successfully'
|
|
56
54
|
};
|
|
57
55
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Verify user phone
|
|
60
|
-
*/ async verifyPhone(id) {
|
|
56
|
+
/** Verify user phone */ async verifyPhone(id) {
|
|
61
57
|
await this.service.verifyPhone(id);
|
|
62
58
|
return {
|
|
63
59
|
message: 'Phone verified successfully'
|
|
64
60
|
};
|
|
65
61
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Update user active status
|
|
68
|
-
*
|
|
69
|
-
* When company feature is disabled: Updates User.isActive directly
|
|
70
|
-
* When company feature is enabled: Updates UserCompanyPermission.isActive for logged user's company
|
|
71
|
-
*/ async updateStatus(id, isActive, user) {
|
|
62
|
+
/** Update user active status. When company feature enabled, updates permission isActive for logged user's company. */ async updateStatus(id, isActive, user) {
|
|
72
63
|
await this.service.updateStatus(id, isActive, user);
|
|
73
64
|
return {
|
|
74
65
|
message: 'Status updated successfully'
|
|
75
66
|
};
|
|
76
67
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Update user profile
|
|
79
|
-
*/ async profile(dto, user) {
|
|
68
|
+
/** Update user profile */ async profile(dto, user) {
|
|
80
69
|
const data = await this.service.profile(dto, user);
|
|
81
70
|
return {
|
|
82
71
|
message: 'Profile updated successfully',
|
|
@@ -89,6 +78,8 @@ let UserController = class UserController extends (0, _classes.createApiControll
|
|
|
89
78
|
};
|
|
90
79
|
_ts_decorate([
|
|
91
80
|
(0, _common.Post)(':id/verify-email'),
|
|
81
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
82
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
92
83
|
(0, _swagger.ApiOperation)({
|
|
93
84
|
summary: 'Verify user email'
|
|
94
85
|
}),
|
|
@@ -105,6 +96,8 @@ _ts_decorate([
|
|
|
105
96
|
], UserController.prototype, "verifyEmail", null);
|
|
106
97
|
_ts_decorate([
|
|
107
98
|
(0, _common.Post)(':id/verify-phone'),
|
|
99
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
100
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
108
101
|
(0, _swagger.ApiOperation)({
|
|
109
102
|
summary: 'Verify user phone'
|
|
110
103
|
}),
|
|
@@ -121,6 +114,8 @@ _ts_decorate([
|
|
|
121
114
|
], UserController.prototype, "verifyPhone", null);
|
|
122
115
|
_ts_decorate([
|
|
123
116
|
(0, _common.Put)(':id/status'),
|
|
117
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
118
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
124
119
|
(0, _swagger.ApiOperation)({
|
|
125
120
|
summary: 'Update user active status',
|
|
126
121
|
description: 'Updates user active status. When company feature is enabled, updates the status for the current company context.'
|
|
@@ -149,6 +144,8 @@ _ts_decorate([
|
|
|
149
144
|
], UserController.prototype, "updateStatus", null);
|
|
150
145
|
_ts_decorate([
|
|
151
146
|
(0, _common.Post)('profile'),
|
|
147
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
148
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
152
149
|
(0, _swagger.ApiOperation)({
|
|
153
150
|
summary: 'Update user profile'
|
|
154
151
|
}),
|
|
@@ -166,9 +163,7 @@ _ts_decorate([
|
|
|
166
163
|
], UserController.prototype, "profile", null);
|
|
167
164
|
UserController = _ts_decorate([
|
|
168
165
|
(0, _swagger.ApiTags)('Users'),
|
|
169
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
170
166
|
(0, _common.Controller)('administration/users'),
|
|
171
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
172
167
|
_ts_param(0, (0, _common.Inject)(_userservice.UserService)),
|
|
173
168
|
_ts_metadata("design:type", Function),
|
|
174
169
|
_ts_metadata("design:paramtypes", [
|
|
@@ -39,76 +39,50 @@ function _ts_param(paramIndex, decorator) {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
let AuthConfigService = class AuthConfigService {
|
|
42
|
-
//
|
|
43
|
-
/**
|
|
44
|
-
* Get database mode (single or multi-tenant)
|
|
45
|
-
*/ getDatabaseMode() {
|
|
42
|
+
// Database Mode
|
|
43
|
+
/** Get database mode (single or multi-tenant) */ getDatabaseMode() {
|
|
46
44
|
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
47
45
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Check if running in multi-tenant mode
|
|
50
|
-
*/ isMultiTenant() {
|
|
46
|
+
/** Check if running in multi-tenant mode */ isMultiTenant() {
|
|
51
47
|
return this.getDatabaseMode() === 'multi-tenant';
|
|
52
48
|
}
|
|
53
|
-
//
|
|
54
|
-
/**
|
|
55
|
-
* Check if company feature is enabled
|
|
56
|
-
*/ isCompanyFeatureEnabled() {
|
|
49
|
+
// Feature Flags
|
|
50
|
+
/** Check if company feature is enabled */ isCompanyFeatureEnabled() {
|
|
57
51
|
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
58
52
|
}
|
|
59
|
-
//
|
|
60
|
-
/**
|
|
61
|
-
* Get JWT secret key
|
|
62
|
-
*/ getJwtSecret() {
|
|
53
|
+
// JWT Configuration
|
|
54
|
+
/** Get JWT secret key */ getJwtSecret() {
|
|
63
55
|
return this.config.jwtSecret ?? 'default-secret-change-in-production';
|
|
64
56
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Get JWT expiration time
|
|
67
|
-
*/ getJwtExpiration() {
|
|
57
|
+
/** Get JWT expiration time */ getJwtExpiration() {
|
|
68
58
|
return this.config.jwtExpiration ?? '1h';
|
|
69
59
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Get refresh token secret key
|
|
72
|
-
*/ getRefreshTokenSecret() {
|
|
60
|
+
/** Get refresh token secret key */ getRefreshTokenSecret() {
|
|
73
61
|
return this.config.refreshTokenSecret ?? this.getJwtSecret();
|
|
74
62
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Get refresh token expiration time
|
|
77
|
-
*/ getRefreshTokenExpiration() {
|
|
63
|
+
/** Get refresh token expiration time */ getRefreshTokenExpiration() {
|
|
78
64
|
return this.config.refreshTokenExpiration ?? '7d';
|
|
79
65
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Get refresh token cookie name
|
|
82
|
-
*/ getRefreshTokenCookieName() {
|
|
66
|
+
/** Get refresh token cookie name */ getRefreshTokenCookieName() {
|
|
83
67
|
return this.config.refreshTokenCookieName ?? 'fsn_refresh_token';
|
|
84
68
|
}
|
|
85
|
-
//
|
|
86
|
-
/**
|
|
87
|
-
* Get default database config
|
|
88
|
-
*/ getDefaultDatabaseConfig() {
|
|
69
|
+
// Database Configuration
|
|
70
|
+
/** Get default database config */ getDefaultDatabaseConfig() {
|
|
89
71
|
return this.config.defaultDatabaseConfig ?? this.config.tenantDefaultDatabaseConfig;
|
|
90
72
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Get tenant default database config (for multi-tenant)
|
|
93
|
-
*/ getTenantDefaultDatabaseConfig() {
|
|
73
|
+
/** Get tenant default database config (for multi-tenant) */ getTenantDefaultDatabaseConfig() {
|
|
94
74
|
return this.config.tenantDefaultDatabaseConfig;
|
|
95
75
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Get registered tenants
|
|
98
|
-
*/ getTenants() {
|
|
76
|
+
/** Get registered tenants */ getTenants() {
|
|
99
77
|
return this.config.tenants ?? [];
|
|
100
78
|
}
|
|
101
|
-
//
|
|
102
|
-
/**
|
|
103
|
-
* Get full module options
|
|
104
|
-
*/ getOptions() {
|
|
79
|
+
// Raw Options
|
|
80
|
+
/** Get full module options */ getOptions() {
|
|
105
81
|
return {
|
|
106
82
|
...this.options
|
|
107
83
|
};
|
|
108
84
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Get runtime config
|
|
111
|
-
*/ getConfig() {
|
|
85
|
+
/** Get runtime config */ getConfig() {
|
|
112
86
|
return {
|
|
113
87
|
...this.config
|
|
114
88
|
};
|
|
@@ -83,11 +83,8 @@ function _ts_param(paramIndex, decorator) {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.MultiTenantDataSourceService {
|
|
86
|
-
//
|
|
87
|
-
/**
|
|
88
|
-
* CRITICAL: Override to access Auth-specific static properties
|
|
89
|
-
* Without this, parent class methods would access parent's static properties
|
|
90
|
-
*/ async getSingleDataSource() {
|
|
86
|
+
// Override Static Cache Access Methods
|
|
87
|
+
/** Override to access Auth-specific static properties */ async getSingleDataSource() {
|
|
91
88
|
if (!AuthDataSourceProvider.singleDataSource) {
|
|
92
89
|
if (AuthDataSourceProvider.singleConnectionLock) {
|
|
93
90
|
return AuthDataSourceProvider.singleConnectionLock;
|
|
@@ -111,9 +108,7 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
|
|
|
111
108
|
}
|
|
112
109
|
return AuthDataSourceProvider.singleDataSource;
|
|
113
110
|
}
|
|
114
|
-
/**
|
|
115
|
-
* CRITICAL: Override to use Auth-specific static cache for tenant connections
|
|
116
|
-
*/ async getOrCreateTenantConnection(tenant) {
|
|
111
|
+
/** Override to use Auth-specific static cache for tenant connections */ async getOrCreateTenantConnection(tenant) {
|
|
117
112
|
// Return existing initialized connection from Auth-specific cache
|
|
118
113
|
const existing = AuthDataSourceProvider.tenantConnections.get(tenant.id);
|
|
119
114
|
if (existing?.isInitialized) {
|
|
@@ -136,10 +131,8 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
|
|
|
136
131
|
AuthDataSourceProvider.connectionLocks.delete(tenant.id);
|
|
137
132
|
}
|
|
138
133
|
}
|
|
139
|
-
//
|
|
140
|
-
/**
|
|
141
|
-
* Build parent options from AuthModuleOptions
|
|
142
|
-
*/ static buildParentOptions(options) {
|
|
134
|
+
// Factory Methods
|
|
135
|
+
/** Build parent options from AuthModuleOptions */ static buildParentOptions(options) {
|
|
143
136
|
return {
|
|
144
137
|
bootstrapAppConfig: options.bootstrapAppConfig,
|
|
145
138
|
defaultDatabaseConfig: options.config?.defaultDatabaseConfig,
|
|
@@ -147,27 +140,18 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
|
|
|
147
140
|
tenants: options.config?.tenants
|
|
148
141
|
};
|
|
149
142
|
}
|
|
150
|
-
//
|
|
151
|
-
/**
|
|
152
|
-
* Get global enable company feature flag
|
|
153
|
-
*/ getEnableCompanyFeature() {
|
|
143
|
+
// Feature Flags
|
|
144
|
+
/** Get global enable company feature flag */ getEnableCompanyFeature() {
|
|
154
145
|
return this.authOptions.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
155
146
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Get enable company feature for specific tenant
|
|
158
|
-
* Falls back to global setting if not specified per-tenant
|
|
159
|
-
*/ getEnableCompanyFeatureForTenant(tenant) {
|
|
147
|
+
/** Get enable company feature for specific tenant. Falls back to global setting. */ getEnableCompanyFeatureForTenant(tenant) {
|
|
160
148
|
return tenant?.enableCompanyFeature ?? this.getEnableCompanyFeature();
|
|
161
149
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Get enable company feature for current request context
|
|
164
|
-
*/ getEnableCompanyFeatureForCurrentTenant() {
|
|
150
|
+
/** Get enable company feature for current request context */ getEnableCompanyFeatureForCurrentTenant() {
|
|
165
151
|
return this.getEnableCompanyFeatureForTenant(this.getCurrentTenant() ?? undefined);
|
|
166
152
|
}
|
|
167
|
-
//
|
|
168
|
-
/**
|
|
169
|
-
* Get auth entities based on company feature flag
|
|
170
|
-
*/ async getAuthEntities(enableCompanyFeature) {
|
|
153
|
+
// Entity Management
|
|
154
|
+
/** Get auth entities based on company feature flag */ async getAuthEntities(enableCompanyFeature) {
|
|
171
155
|
const enable = enableCompanyFeature ?? this.getEnableCompanyFeature();
|
|
172
156
|
const { Company, CompanyBranch, User, UserCompanyPermission } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../entities")));
|
|
173
157
|
const coreEntities = [
|
|
@@ -183,10 +167,8 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
|
|
|
183
167
|
...companyEntities
|
|
184
168
|
];
|
|
185
169
|
}
|
|
186
|
-
//
|
|
187
|
-
/**
|
|
188
|
-
* Override to dynamically set entities based on tenant config
|
|
189
|
-
*/ async createDataSourceFromConfig(config) {
|
|
170
|
+
// Overrides
|
|
171
|
+
/** Override to dynamically set entities based on tenant config */ async createDataSourceFromConfig(config) {
|
|
190
172
|
const currentTenant = this.getCurrentTenant();
|
|
191
173
|
const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
|
|
192
174
|
const entities = await this.getAuthEntities(enableCompanyFeature);
|