@flusys/nestjs-auth 1.1.0-beta → 2.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.
- package/README.md +590 -473
- package/cjs/config/auth.constants.js +8 -0
- package/cjs/controllers/authentication.controller.js +218 -39
- package/cjs/controllers/branch.controller.js +44 -1
- package/cjs/controllers/company-selection.controller.js +27 -20
- package/cjs/controllers/company.controller.js +44 -1
- package/cjs/controllers/user-permission.controller.js +82 -154
- package/cjs/controllers/user.controller.js +68 -15
- package/cjs/docs/auth-swagger.config.js +14 -7
- package/cjs/dtos/authentication.dto.js +16 -43
- package/cjs/dtos/index.js +0 -1
- package/cjs/dtos/user-permission.dto.js +28 -0
- package/cjs/dtos/user.dto.js +19 -4
- package/cjs/entities/user-company-permission.entity.js +0 -6
- package/cjs/interceptors/clear-token.interceptor.js +10 -23
- package/cjs/interceptors/set-token.interceptor.js +15 -55
- package/cjs/interfaces/auth-email-provider.interface.js +1 -1
- package/cjs/modules/auth.module.js +63 -147
- package/cjs/services/auth-config.service.js +22 -28
- package/cjs/services/auth-datasource.provider.js +9 -21
- package/cjs/services/auth-email.service.js +89 -85
- package/cjs/services/authentication.service.js +225 -396
- package/cjs/services/branch.service.js +9 -4
- package/cjs/services/company-selection-session.service.js +1 -1
- package/cjs/services/user-permission.service.js +43 -73
- package/cjs/services/user.service.js +78 -64
- package/cjs/strategies/jwt.strategy.js +44 -44
- package/cjs/validators/password.validator.js +45 -0
- package/config/auth.constants.d.ts +2 -0
- package/controllers/authentication.controller.d.ts +5 -3
- package/controllers/company-selection.controller.d.ts +6 -2
- package/controllers/user-permission.controller.d.ts +5 -4
- package/controllers/user.controller.d.ts +6 -0
- package/dtos/authentication.dto.d.ts +0 -4
- package/dtos/company-branch.dto.d.ts +0 -1
- package/dtos/company.dto.d.ts +0 -1
- package/dtos/index.d.ts +0 -1
- package/dtos/user-permission.dto.d.ts +4 -0
- package/dtos/user.dto.d.ts +1 -3
- package/entities/index.d.ts +3 -3
- package/entities/user-company-permission.entity.d.ts +0 -2
- package/fesm/config/auth.constants.js +6 -13
- package/fesm/controllers/authentication.controller.js +221 -42
- package/fesm/controllers/branch.controller.js +45 -2
- package/fesm/controllers/company-selection.controller.js +28 -21
- package/fesm/controllers/company.controller.js +45 -2
- package/fesm/controllers/user-permission.controller.js +84 -156
- package/fesm/controllers/user.controller.js +71 -18
- package/fesm/docs/auth-swagger.config.js +14 -7
- package/fesm/dtos/authentication.dto.js +17 -44
- package/fesm/dtos/index.js +0 -1
- package/fesm/dtos/user-permission.dto.js +28 -0
- package/fesm/dtos/user.dto.js +20 -5
- package/fesm/entities/user-company-permission.entity.js +0 -6
- package/fesm/interceptors/clear-token.interceptor.js +9 -22
- package/fesm/interceptors/set-token.interceptor.js +14 -54
- package/fesm/interfaces/auth-email-provider.interface.js +1 -1
- package/fesm/modules/auth.module.js +64 -148
- package/fesm/services/auth-config.service.js +23 -29
- package/fesm/services/auth-datasource.provider.js +10 -22
- package/fesm/services/auth-email.service.js +90 -86
- package/fesm/services/authentication.service.js +225 -396
- package/fesm/services/branch.service.js +9 -4
- package/fesm/services/company-selection-session.service.js +1 -1
- package/fesm/services/user-permission.service.js +44 -74
- package/fesm/services/user.service.js +79 -65
- package/fesm/strategies/jwt.strategy.js +44 -44
- package/fesm/validators/password.validator.js +48 -0
- package/interceptors/clear-token.interceptor.d.ts +0 -1
- package/interceptors/set-token.interceptor.d.ts +1 -1
- package/interfaces/authentication.interface.d.ts +0 -4
- package/interfaces/user-enricher.interface.d.ts +1 -4
- package/modules/auth.module.d.ts +6 -3
- package/package.json +4 -4
- package/services/auth-config.service.d.ts +6 -8
- package/services/auth-datasource.provider.d.ts +2 -4
- package/services/auth-email.service.d.ts +8 -4
- package/services/authentication.service.d.ts +15 -16
- package/services/company-selection-session.service.d.ts +1 -1
- package/services/user-permission.service.d.ts +6 -9
- package/services/user.service.d.ts +3 -0
- package/strategies/jwt.strategy.d.ts +4 -1
- package/validators/password.validator.d.ts +10 -0
- package/cjs/dtos/user-company-permission.dto.js +0 -110
- package/dtos/user-company-permission.dto.d.ts +0 -10
- package/fesm/dtos/user-company-permission.dto.js +0 -98
|
@@ -12,16 +12,15 @@ const _modules = require("@flusys/nestjs-shared/modules");
|
|
|
12
12
|
const _common = require("@nestjs/common");
|
|
13
13
|
const _jwt = require("@nestjs/jwt");
|
|
14
14
|
const _passport = require("@nestjs/passport");
|
|
15
|
-
const
|
|
16
|
-
const _authconfigservice = require("../services/auth-config.service");
|
|
17
|
-
const _authdatasourceprovider = require("../services/auth-datasource.provider");
|
|
15
|
+
const _guards = require("@flusys/nestjs-shared/guards");
|
|
18
16
|
const _authconstants = require("../config/auth.constants");
|
|
19
17
|
const _controllers = require("../controllers");
|
|
20
18
|
const _entities = require("../entities");
|
|
21
|
-
const _guards = require("@flusys/nestjs-shared/guards");
|
|
22
19
|
const _cleartokeninterceptor = require("../interceptors/clear-token.interceptor");
|
|
23
20
|
const _settokeninterceptor = require("../interceptors/set-token.interceptor");
|
|
24
21
|
const _services = require("../services");
|
|
22
|
+
const _authconfigservice = require("../services/auth-config.service");
|
|
23
|
+
const _authdatasourceprovider = require("../services/auth-datasource.provider");
|
|
25
24
|
const _jwtstrategy = require("../strategies/jwt.strategy");
|
|
26
25
|
function _ts_decorate(decorators, target, key, desc) {
|
|
27
26
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -31,82 +30,42 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
31
30
|
}
|
|
32
31
|
let AuthModule = class AuthModule {
|
|
33
32
|
static forRoot(options) {
|
|
34
|
-
|
|
33
|
+
const optionsProvider = {
|
|
34
|
+
provide: _authconstants.AUTH_MODULE_OPTIONS,
|
|
35
|
+
useValue: options
|
|
36
|
+
};
|
|
37
|
+
return this.buildModule(options, [
|
|
38
|
+
optionsProvider,
|
|
39
|
+
...options.providers ?? []
|
|
40
|
+
]);
|
|
35
41
|
}
|
|
36
|
-
static forRootAsync(
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
// Build imports
|
|
40
|
-
const imports = [
|
|
41
|
-
...externalImports,
|
|
42
|
-
_passport.PassportModule.register({
|
|
43
|
-
defaultStrategy: 'jwt'
|
|
44
|
-
}),
|
|
45
|
-
_jwt.JwtModule.register({}),
|
|
46
|
-
_modules.CacheModule,
|
|
47
|
-
_modules.UtilsModule
|
|
48
|
-
];
|
|
49
|
-
// Build controllers based on configuration
|
|
50
|
-
const controllers = [];
|
|
51
|
-
if (includeController) {
|
|
52
|
-
// Core authentication controller (always included)
|
|
53
|
-
controllers.push(_controllers.AuthenticationController);
|
|
54
|
-
// User controller (always included)
|
|
55
|
-
controllers.push(_controllers.UserController);
|
|
56
|
-
// Company feature controllers (conditional)
|
|
57
|
-
if (enableCompanyFeature) {
|
|
58
|
-
controllers.push(_controllers.CompanySelectionController, _controllers.CompanyController, _controllers.BranchController, _controllers.UserPermissionController);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// Build providers
|
|
62
|
-
const providers = [
|
|
42
|
+
static forRootAsync(options) {
|
|
43
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
44
|
+
return this.buildModule(options, [
|
|
63
45
|
...asyncProviders,
|
|
64
|
-
...
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
_guards.JwtAuthGuard,
|
|
71
|
-
_services.AuthenticationService,
|
|
72
|
-
_services.AuthEmailService,
|
|
73
|
-
// Interceptors
|
|
74
|
-
_settokeninterceptor.SetToken,
|
|
75
|
-
_cleartokeninterceptor.ClearToken,
|
|
76
|
-
// Core services (always included)
|
|
77
|
-
_services.UserService
|
|
78
|
-
];
|
|
79
|
-
// Company feature services (conditional)
|
|
80
|
-
if (enableCompanyFeature) {
|
|
81
|
-
providers.push(_services.CompanySelectionSessionService, _services.CompanyService, _services.BranchService, _services.UserPermissionService);
|
|
82
|
-
}
|
|
83
|
-
// Build exports
|
|
84
|
-
const exports1 = [
|
|
85
|
-
_passport.PassportModule,
|
|
86
|
-
_authconstants.AUTH_MODULE_OPTIONS,
|
|
87
|
-
_authconfigservice.AuthConfigService,
|
|
88
|
-
_authdatasourceprovider.AuthDataSourceProvider,
|
|
89
|
-
_jwtstrategy.JwtStrategy,
|
|
90
|
-
_guards.JwtAuthGuard,
|
|
91
|
-
_services.AuthenticationService,
|
|
92
|
-
_services.AuthEmailService,
|
|
93
|
-
_services.UserService
|
|
94
|
-
];
|
|
95
|
-
if (enableCompanyFeature) {
|
|
96
|
-
exports1.push(_services.CompanySelectionSessionService, _services.CompanyService, _services.BranchService, _services.UserPermissionService);
|
|
97
|
-
}
|
|
46
|
+
...options.providers ?? []
|
|
47
|
+
], options.imports);
|
|
48
|
+
}
|
|
49
|
+
/** Build the dynamic module with shared logic */ static buildModule(options, providers, externalImports = []) {
|
|
50
|
+
const { global = false, includeController = true, bootstrapAppConfig } = options;
|
|
51
|
+
const enableCompanyFeature = bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
98
52
|
return {
|
|
99
53
|
module: AuthModule,
|
|
100
54
|
global,
|
|
101
|
-
imports
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
55
|
+
imports: [
|
|
56
|
+
...externalImports,
|
|
57
|
+
...this.buildImports()
|
|
58
|
+
],
|
|
59
|
+
controllers: this.buildControllers(includeController, enableCompanyFeature),
|
|
60
|
+
providers: [
|
|
61
|
+
...providers,
|
|
62
|
+
...this.buildProviders(enableCompanyFeature)
|
|
63
|
+
],
|
|
64
|
+
exports: this.buildExports(enableCompanyFeature)
|
|
105
65
|
};
|
|
106
66
|
}
|
|
107
|
-
static
|
|
108
|
-
|
|
109
|
-
const imports = [
|
|
67
|
+
/** Common module imports */ static buildImports() {
|
|
68
|
+
return [
|
|
110
69
|
_passport.PassportModule.register({
|
|
111
70
|
defaultStrategy: 'jwt'
|
|
112
71
|
}),
|
|
@@ -114,42 +73,36 @@ let AuthModule = class AuthModule {
|
|
|
114
73
|
_modules.CacheModule,
|
|
115
74
|
_modules.UtilsModule
|
|
116
75
|
];
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (includeController)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
controllers.push(_controllers.CompanySelectionController, _controllers.CompanyController, _controllers.BranchController, _controllers.UserPermissionController);
|
|
127
|
-
}
|
|
76
|
+
}
|
|
77
|
+
/** Build controllers based on feature flags */ static buildControllers(includeController, enableCompanyFeature) {
|
|
78
|
+
if (!includeController) return [];
|
|
79
|
+
const controllers = [
|
|
80
|
+
_controllers.AuthenticationController,
|
|
81
|
+
_controllers.UserController
|
|
82
|
+
];
|
|
83
|
+
if (enableCompanyFeature) {
|
|
84
|
+
controllers.push(_controllers.CompanySelectionController, _controllers.CompanyController, _controllers.BranchController, _controllers.UserPermissionController);
|
|
128
85
|
}
|
|
86
|
+
return controllers;
|
|
87
|
+
}
|
|
88
|
+
/** Core providers (without AUTH_MODULE_OPTIONS - that's added separately) */ static buildProviders(enableCompanyFeature) {
|
|
129
89
|
const providers = [
|
|
130
|
-
{
|
|
131
|
-
provide: _authconstants.AUTH_MODULE_OPTIONS,
|
|
132
|
-
useValue: options
|
|
133
|
-
},
|
|
134
|
-
...additionalProviders,
|
|
135
|
-
// Config & Infrastructure
|
|
136
90
|
_authconfigservice.AuthConfigService,
|
|
137
91
|
_authdatasourceprovider.AuthDataSourceProvider,
|
|
138
|
-
// Auth core
|
|
139
92
|
_jwtstrategy.JwtStrategy,
|
|
140
93
|
_guards.JwtAuthGuard,
|
|
141
94
|
_services.AuthenticationService,
|
|
142
95
|
_services.AuthEmailService,
|
|
143
|
-
// Interceptors
|
|
144
96
|
_settokeninterceptor.SetToken,
|
|
145
97
|
_cleartokeninterceptor.ClearToken,
|
|
146
|
-
// Core services (always included)
|
|
147
98
|
_services.UserService
|
|
148
99
|
];
|
|
149
|
-
// Company feature services (conditional)
|
|
150
100
|
if (enableCompanyFeature) {
|
|
151
101
|
providers.push(_services.CompanySelectionSessionService, _services.CompanyService, _services.BranchService, _services.UserPermissionService);
|
|
152
102
|
}
|
|
103
|
+
return providers;
|
|
104
|
+
}
|
|
105
|
+
/** Build module exports */ static buildExports(enableCompanyFeature) {
|
|
153
106
|
const exports1 = [
|
|
154
107
|
_passport.PassportModule,
|
|
155
108
|
_authconstants.AUTH_MODULE_OPTIONS,
|
|
@@ -164,16 +117,9 @@ let AuthModule = class AuthModule {
|
|
|
164
117
|
if (enableCompanyFeature) {
|
|
165
118
|
exports1.push(_services.CompanySelectionSessionService, _services.CompanyService, _services.BranchService, _services.UserPermissionService);
|
|
166
119
|
}
|
|
167
|
-
return
|
|
168
|
-
module: AuthModule,
|
|
169
|
-
global,
|
|
170
|
-
imports,
|
|
171
|
-
controllers,
|
|
172
|
-
providers,
|
|
173
|
-
exports: exports1
|
|
174
|
-
};
|
|
120
|
+
return exports1;
|
|
175
121
|
}
|
|
176
|
-
static createAsyncProviders(options) {
|
|
122
|
+
/** Create async providers for forRootAsync */ static createAsyncProviders(options) {
|
|
177
123
|
const staticOptions = {
|
|
178
124
|
global: options.global,
|
|
179
125
|
includeController: options.includeController,
|
|
@@ -183,13 +129,10 @@ let AuthModule = class AuthModule {
|
|
|
183
129
|
return [
|
|
184
130
|
{
|
|
185
131
|
provide: _authconstants.AUTH_MODULE_OPTIONS,
|
|
186
|
-
useFactory: async (...args)=>{
|
|
187
|
-
const config = await options.useFactory(...args);
|
|
188
|
-
return {
|
|
132
|
+
useFactory: async (...args)=>({
|
|
189
133
|
...staticOptions,
|
|
190
|
-
config
|
|
191
|
-
}
|
|
192
|
-
},
|
|
134
|
+
config: await options.useFactory(...args)
|
|
135
|
+
}),
|
|
193
136
|
inject: options.inject || []
|
|
194
137
|
}
|
|
195
138
|
];
|
|
@@ -202,13 +145,10 @@ let AuthModule = class AuthModule {
|
|
|
202
145
|
},
|
|
203
146
|
{
|
|
204
147
|
provide: _authconstants.AUTH_MODULE_OPTIONS,
|
|
205
|
-
useFactory: async (factory)=>{
|
|
206
|
-
const config = await factory.createAuthOptions();
|
|
207
|
-
return {
|
|
148
|
+
useFactory: async (factory)=>({
|
|
208
149
|
...staticOptions,
|
|
209
|
-
config
|
|
210
|
-
}
|
|
211
|
-
},
|
|
150
|
+
config: await factory.createAuthOptions()
|
|
151
|
+
}),
|
|
212
152
|
inject: [
|
|
213
153
|
options.useClass
|
|
214
154
|
]
|
|
@@ -219,13 +159,10 @@ let AuthModule = class AuthModule {
|
|
|
219
159
|
return [
|
|
220
160
|
{
|
|
221
161
|
provide: _authconstants.AUTH_MODULE_OPTIONS,
|
|
222
|
-
useFactory: async (factory)=>{
|
|
223
|
-
const config = await factory.createAuthOptions();
|
|
224
|
-
return {
|
|
162
|
+
useFactory: async (factory)=>({
|
|
225
163
|
...staticOptions,
|
|
226
|
-
config
|
|
227
|
-
}
|
|
228
|
-
},
|
|
164
|
+
config: await factory.createAuthOptions()
|
|
165
|
+
}),
|
|
229
166
|
inject: [
|
|
230
167
|
options.useExisting
|
|
231
168
|
]
|
|
@@ -239,35 +176,14 @@ let AuthModule = class AuthModule {
|
|
|
239
176
|
}
|
|
240
177
|
];
|
|
241
178
|
}
|
|
242
|
-
/**
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
* Note: Must be REQUEST-scoped since AuthDataSourceProvider is REQUEST-scoped
|
|
246
|
-
*/ static getRepositoryProviders(enableCompanyFeature) {
|
|
247
|
-
const entities = this.getEntities(enableCompanyFeature);
|
|
248
|
-
return entities.map((entity)=>({
|
|
249
|
-
provide: (0, _typeorm.getRepositoryToken)(entity),
|
|
250
|
-
scope: _common.Scope.REQUEST,
|
|
251
|
-
useFactory: async (dataSourceProvider)=>{
|
|
252
|
-
return await dataSourceProvider.getRepository(entity);
|
|
253
|
-
},
|
|
254
|
-
inject: [
|
|
255
|
-
_authdatasourceprovider.AuthDataSourceProvider
|
|
256
|
-
]
|
|
257
|
-
}));
|
|
258
|
-
}
|
|
259
|
-
static getEntities(enableCompanyFeature = false) {
|
|
260
|
-
const coreEntities = [
|
|
261
|
-
_entities.User
|
|
262
|
-
];
|
|
263
|
-
const companyEntities = enableCompanyFeature ? [
|
|
179
|
+
/** Get auth entities based on feature flags */ static getEntities(enableCompanyFeature = false) {
|
|
180
|
+
return enableCompanyFeature ? [
|
|
181
|
+
_entities.User,
|
|
264
182
|
_entities.Company,
|
|
265
183
|
_entities.CompanyBranch,
|
|
266
184
|
_entities.UserCompanyPermission
|
|
267
|
-
] : [
|
|
268
|
-
|
|
269
|
-
...coreEntities,
|
|
270
|
-
...companyEntities
|
|
185
|
+
] : [
|
|
186
|
+
_entities.User
|
|
271
187
|
];
|
|
272
188
|
}
|
|
273
189
|
};
|
|
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "AuthConfigService", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _common = require("@nestjs/common");
|
|
12
|
-
const _authmoduleoptionsinterface = require("../interfaces/auth-module-options.interface");
|
|
13
12
|
const _authconstants = require("../config/auth.constants");
|
|
13
|
+
const _authmoduleoptionsinterface = require("../interfaces/auth-module-options.interface");
|
|
14
14
|
function _define_property(obj, key, value) {
|
|
15
15
|
if (key in obj) {
|
|
16
16
|
Object.defineProperty(obj, key, {
|
|
@@ -39,26 +39,39 @@ function _ts_param(paramIndex, decorator) {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
let AuthConfigService = class AuthConfigService {
|
|
42
|
-
// Database Mode
|
|
43
|
-
|
|
42
|
+
// Database Mode (required by IModuleConfigService)
|
|
43
|
+
getDatabaseMode() {
|
|
44
44
|
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
isMultiTenant() {
|
|
47
47
|
return this.getDatabaseMode() === 'multi-tenant';
|
|
48
48
|
}
|
|
49
49
|
// Feature Flags
|
|
50
|
-
|
|
50
|
+
isCompanyFeatureEnabled() {
|
|
51
51
|
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
52
52
|
}
|
|
53
53
|
// JWT Configuration
|
|
54
54
|
/** Get JWT secret key */ getJwtSecret() {
|
|
55
|
-
|
|
55
|
+
if (!this.config.jwtSecret) {
|
|
56
|
+
throw new _common.InternalServerErrorException('[AuthModule] JWT_SECRET is required - set via environment or module config');
|
|
57
|
+
}
|
|
58
|
+
return this.config.jwtSecret;
|
|
56
59
|
}
|
|
57
60
|
/** Get JWT expiration time */ getJwtExpiration() {
|
|
58
61
|
return this.config.jwtExpiration ?? '1h';
|
|
59
62
|
}
|
|
60
63
|
/** Get refresh token secret key */ getRefreshTokenSecret() {
|
|
61
|
-
|
|
64
|
+
if (this.config.refreshTokenSecret) {
|
|
65
|
+
return this.config.refreshTokenSecret;
|
|
66
|
+
}
|
|
67
|
+
if (process.env.NODE_ENV === 'production') {
|
|
68
|
+
throw new _common.InternalServerErrorException('[AuthModule] REFRESH_TOKEN_SECRET is required in production - ' + 'using the same secret for access and refresh tokens is a security risk');
|
|
69
|
+
}
|
|
70
|
+
if (!this.refreshTokenSecretWarned) {
|
|
71
|
+
this.refreshTokenSecretWarned = true;
|
|
72
|
+
this.logger.warn('REFRESH_TOKEN_SECRET not configured - using JWT_SECRET as fallback. ' + 'For better security, configure a separate refresh token secret.');
|
|
73
|
+
}
|
|
74
|
+
return this.getJwtSecret();
|
|
62
75
|
}
|
|
63
76
|
/** Get refresh token expiration time */ getRefreshTokenExpiration() {
|
|
64
77
|
return this.config.refreshTokenExpiration ?? '7d';
|
|
@@ -70,30 +83,11 @@ let AuthConfigService = class AuthConfigService {
|
|
|
70
83
|
/** Get frontend URL for email links */ getFrontendUrl() {
|
|
71
84
|
return this.config.frontendUrl;
|
|
72
85
|
}
|
|
73
|
-
// Database Configuration
|
|
74
|
-
/** Get default database config */ getDefaultDatabaseConfig() {
|
|
75
|
-
return this.config.defaultDatabaseConfig ?? this.config.tenantDefaultDatabaseConfig;
|
|
76
|
-
}
|
|
77
|
-
/** Get tenant default database config (for multi-tenant) */ getTenantDefaultDatabaseConfig() {
|
|
78
|
-
return this.config.tenantDefaultDatabaseConfig;
|
|
79
|
-
}
|
|
80
|
-
/** Get registered tenants */ getTenants() {
|
|
81
|
-
return this.config.tenants ?? [];
|
|
82
|
-
}
|
|
83
|
-
// Raw Options
|
|
84
|
-
/** Get full module options */ getOptions() {
|
|
85
|
-
return {
|
|
86
|
-
...this.options
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/** Get runtime config */ getConfig() {
|
|
90
|
-
return {
|
|
91
|
-
...this.config
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
86
|
constructor(injectedOptions){
|
|
87
|
+
_define_property(this, "logger", new _common.Logger(AuthConfigService.name));
|
|
95
88
|
_define_property(this, "options", void 0);
|
|
96
89
|
_define_property(this, "config", void 0);
|
|
90
|
+
_define_property(this, "refreshTokenSecretWarned", false);
|
|
97
91
|
this.options = injectedOptions ?? {
|
|
98
92
|
global: false,
|
|
99
93
|
includeController: true
|
|
@@ -92,7 +92,7 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
|
|
|
92
92
|
const lockPromise = (async ()=>{
|
|
93
93
|
const config = this.getDefaultDatabaseConfig();
|
|
94
94
|
if (!config) {
|
|
95
|
-
throw new
|
|
95
|
+
throw new _common.InternalServerErrorException('Default database config is not available');
|
|
96
96
|
}
|
|
97
97
|
const ds = await this.createDataSourceFromConfig(config);
|
|
98
98
|
AuthDataSourceProvider.singleDataSource = ds;
|
|
@@ -141,40 +141,28 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
// Feature Flags
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
/** Get enable company feature for specific tenant. Falls back to global setting. */ getEnableCompanyFeatureForTenant(tenant) {
|
|
148
|
-
return tenant?.enableCompanyFeature ?? this.getEnableCompanyFeature();
|
|
149
|
-
}
|
|
150
|
-
/** Get enable company feature for current request context */ getEnableCompanyFeatureForCurrentTenant() {
|
|
151
|
-
return this.getEnableCompanyFeatureForTenant(this.getCurrentTenant() ?? undefined);
|
|
144
|
+
/** Check if company feature is enabled (tenant-specific or global fallback) */ isCompanyFeatureEnabled(tenant) {
|
|
145
|
+
const effectiveTenant = tenant ?? this.getCurrentTenant();
|
|
146
|
+
return effectiveTenant?.enableCompanyFeature ?? this.authOptions.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
152
147
|
}
|
|
153
148
|
// Entity Management
|
|
154
|
-
/** Get auth entities based on company feature flag */ async getAuthEntities(
|
|
155
|
-
const enable = enableCompanyFeature ?? this.getEnableCompanyFeature();
|
|
149
|
+
/** Get auth entities based on company feature flag */ async getAuthEntities() {
|
|
156
150
|
const { Company, CompanyBranch, User, UserCompanyPermission, UserToken, PendingRegistration } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../entities")));
|
|
157
151
|
const coreEntities = [
|
|
158
152
|
User,
|
|
159
153
|
UserToken,
|
|
160
154
|
PendingRegistration
|
|
161
155
|
];
|
|
162
|
-
|
|
156
|
+
return this.isCompanyFeatureEnabled() ? [
|
|
157
|
+
...coreEntities,
|
|
163
158
|
Company,
|
|
164
159
|
CompanyBranch,
|
|
165
160
|
UserCompanyPermission
|
|
166
|
-
] :
|
|
167
|
-
return [
|
|
168
|
-
...coreEntities,
|
|
169
|
-
...companyEntities
|
|
170
|
-
];
|
|
161
|
+
] : coreEntities;
|
|
171
162
|
}
|
|
172
163
|
// Overrides
|
|
173
164
|
/** Override to dynamically set entities based on tenant config */ async createDataSourceFromConfig(config) {
|
|
174
|
-
|
|
175
|
-
const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
|
|
176
|
-
const entities = await this.getAuthEntities(enableCompanyFeature);
|
|
177
|
-
return super.createDataSourceFromConfig(config, entities);
|
|
165
|
+
return super.createDataSourceFromConfig(config, await this.getAuthEntities());
|
|
178
166
|
}
|
|
179
167
|
constructor(authOptions, request){
|
|
180
168
|
super(AuthDataSourceProvider.buildParentOptions(authOptions), request), _define_property(this, "authOptions", void 0), _define_property(this, "logger", void 0), this.authOptions = authOptions, this.logger = new _common.Logger(AuthDataSourceProvider.name);
|