@flusys/nestjs-auth 0.1.0-beta.3 → 1.1.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 +14 -4
- package/cjs/controllers/authentication.controller.js +173 -36
- 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 +168 -22
- package/cjs/dtos/authentication.dto.js +106 -3
- package/cjs/entities/index.js +5 -1
- package/cjs/entities/pending-registration.entity.js +125 -0
- package/cjs/entities/user-token.entity.js +129 -0
- package/cjs/interfaces/auth-email-provider.interface.js +45 -0
- package/cjs/interfaces/authentication.interface.js +0 -3
- package/cjs/interfaces/index.js +2 -0
- package/cjs/interfaces/user-enricher.interface.js +4 -0
- package/cjs/modules/auth.module.js +8 -2
- package/cjs/services/auth-config.service.js +22 -44
- package/cjs/services/auth-datasource.provider.js +17 -33
- package/cjs/services/auth-email.service.js +452 -0
- package/cjs/services/authentication.service.js +229 -115
- package/cjs/services/branch.service.js +10 -44
- package/cjs/services/company.service.js +7 -36
- package/cjs/services/index.js +1 -0
- package/cjs/services/user-permission.service.js +9 -27
- package/cjs/services/user.service.js +177 -99
- package/cjs/strategies/jwt.strategy.js +14 -1
- package/config/auth.constants.d.ts +3 -0
- package/controllers/authentication.controller.d.ts +13 -9
- package/controllers/user.controller.d.ts +27 -0
- package/dtos/authentication.dto.d.ts +21 -3
- package/dtos/user.dto.d.ts +1 -0
- package/entities/index.d.ts +7 -3
- package/entities/pending-registration.entity.d.ts +17 -0
- package/entities/user-token.entity.d.ts +15 -0
- package/fesm/config/auth.constants.js +18 -8
- package/fesm/controllers/authentication.controller.js +174 -37
- 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 +168 -22
- package/fesm/dtos/authentication.dto.js +109 -100
- package/fesm/entities/index.js +7 -1
- package/fesm/entities/pending-registration.entity.js +115 -0
- package/fesm/entities/user-token.entity.js +113 -0
- package/fesm/interfaces/auth-email-provider.interface.js +38 -0
- package/fesm/interfaces/authentication.interface.js +1 -7
- package/fesm/interfaces/index.js +2 -0
- package/fesm/interfaces/user-enricher.interface.js +26 -0
- package/fesm/modules/auth.module.js +9 -3
- package/fesm/services/auth-config.service.js +22 -44
- package/fesm/services/auth-datasource.provider.js +17 -33
- package/fesm/services/auth-email.service.js +401 -0
- package/fesm/services/authentication.service.js +227 -113
- package/fesm/services/branch.service.js +11 -45
- package/fesm/services/company.service.js +8 -37
- package/fesm/services/index.js +1 -0
- package/fesm/services/user-permission.service.js +9 -27
- package/fesm/services/user.service.js +178 -100
- package/fesm/strategies/jwt.strategy.js +14 -1
- package/interfaces/auth-email-provider.interface.d.ts +6 -0
- package/interfaces/auth-module-options.interface.d.ts +4 -1
- package/interfaces/authentication.interface.d.ts +14 -0
- package/interfaces/index.d.ts +2 -0
- package/interfaces/user-enricher.interface.d.ts +67 -0
- package/interfaces/user.interface.d.ts +1 -0
- package/package.json +3 -3
- package/services/auth-config.service.d.ts +1 -0
- package/services/auth-email.service.d.ts +50 -0
- package/services/authentication.service.d.ts +21 -5
- package/services/branch.service.d.ts +2 -5
- package/services/company.service.d.ts +1 -4
- package/services/index.d.ts +1 -0
- package/services/user.service.d.ts +17 -6
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get TokenType () {
|
|
13
|
+
return TokenType;
|
|
14
|
+
},
|
|
15
|
+
get UserToken () {
|
|
16
|
+
return UserToken;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _typeorm = require("typeorm");
|
|
20
|
+
function _define_property(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
34
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
35
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
36
|
+
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;
|
|
37
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
38
|
+
}
|
|
39
|
+
function _ts_metadata(k, v) {
|
|
40
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
41
|
+
}
|
|
42
|
+
var TokenType = /*#__PURE__*/ function(TokenType) {
|
|
43
|
+
TokenType["PASSWORD_RESET"] = "password_reset";
|
|
44
|
+
TokenType["EMAIL_VERIFICATION"] = "email_verification";
|
|
45
|
+
TokenType["EMAIL_CHANGE"] = "email_change";
|
|
46
|
+
return TokenType;
|
|
47
|
+
}({});
|
|
48
|
+
let UserToken = class UserToken {
|
|
49
|
+
constructor(){
|
|
50
|
+
_define_property(this, "id", void 0);
|
|
51
|
+
_define_property(this, "userId", void 0);
|
|
52
|
+
_define_property(this, "type", void 0);
|
|
53
|
+
_define_property(this, "token", void 0);
|
|
54
|
+
_define_property(this, "expiresAt", void 0);
|
|
55
|
+
_define_property(this, "usedAt", void 0);
|
|
56
|
+
_define_property(this, "metadata", void 0);
|
|
57
|
+
_define_property(this, "createdAt", void 0);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
_ts_decorate([
|
|
61
|
+
(0, _typeorm.PrimaryGeneratedColumn)('uuid'),
|
|
62
|
+
_ts_metadata("design:type", String)
|
|
63
|
+
], UserToken.prototype, "id", void 0);
|
|
64
|
+
_ts_decorate([
|
|
65
|
+
(0, _typeorm.Column)({
|
|
66
|
+
type: 'uuid',
|
|
67
|
+
name: 'user_id'
|
|
68
|
+
}),
|
|
69
|
+
_ts_metadata("design:type", String)
|
|
70
|
+
], UserToken.prototype, "userId", void 0);
|
|
71
|
+
_ts_decorate([
|
|
72
|
+
(0, _typeorm.Column)({
|
|
73
|
+
type: 'varchar',
|
|
74
|
+
length: 32
|
|
75
|
+
}),
|
|
76
|
+
_ts_metadata("design:type", String)
|
|
77
|
+
], UserToken.prototype, "type", void 0);
|
|
78
|
+
_ts_decorate([
|
|
79
|
+
(0, _typeorm.Column)({
|
|
80
|
+
type: 'varchar',
|
|
81
|
+
length: 64
|
|
82
|
+
}),
|
|
83
|
+
_ts_metadata("design:type", String)
|
|
84
|
+
], UserToken.prototype, "token", void 0);
|
|
85
|
+
_ts_decorate([
|
|
86
|
+
(0, _typeorm.Column)({
|
|
87
|
+
type: 'timestamp',
|
|
88
|
+
name: 'expires_at'
|
|
89
|
+
}),
|
|
90
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
91
|
+
], UserToken.prototype, "expiresAt", void 0);
|
|
92
|
+
_ts_decorate([
|
|
93
|
+
(0, _typeorm.Column)({
|
|
94
|
+
type: 'timestamp',
|
|
95
|
+
name: 'used_at',
|
|
96
|
+
nullable: true
|
|
97
|
+
}),
|
|
98
|
+
_ts_metadata("design:type", Object)
|
|
99
|
+
], UserToken.prototype, "usedAt", void 0);
|
|
100
|
+
_ts_decorate([
|
|
101
|
+
(0, _typeorm.Column)({
|
|
102
|
+
type: 'varchar',
|
|
103
|
+
length: 255,
|
|
104
|
+
nullable: true
|
|
105
|
+
}),
|
|
106
|
+
_ts_metadata("design:type", Object)
|
|
107
|
+
], UserToken.prototype, "metadata", void 0);
|
|
108
|
+
_ts_decorate([
|
|
109
|
+
(0, _typeorm.CreateDateColumn)({
|
|
110
|
+
type: 'timestamp',
|
|
111
|
+
name: 'created_at'
|
|
112
|
+
}),
|
|
113
|
+
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
114
|
+
], UserToken.prototype, "createdAt", void 0);
|
|
115
|
+
UserToken = _ts_decorate([
|
|
116
|
+
(0, _typeorm.Entity)('user_tokens'),
|
|
117
|
+
(0, _typeorm.Index)('IDX_user_token_token', [
|
|
118
|
+
'token'
|
|
119
|
+
], {
|
|
120
|
+
unique: true
|
|
121
|
+
}),
|
|
122
|
+
(0, _typeorm.Index)('IDX_user_token_user_type', [
|
|
123
|
+
'userId',
|
|
124
|
+
'type'
|
|
125
|
+
]),
|
|
126
|
+
(0, _typeorm.Index)('IDX_user_token_expires', [
|
|
127
|
+
'expiresAt'
|
|
128
|
+
])
|
|
129
|
+
], UserToken);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth Email Provider Interface
|
|
3
|
+
*
|
|
4
|
+
* This interface defines the contract for email sending in the auth module.
|
|
5
|
+
* It allows auth to work independently of the email module.
|
|
6
|
+
*
|
|
7
|
+
* To use email features in auth:
|
|
8
|
+
* 1. Provide AUTH_EMAIL_PROVIDER in your app module
|
|
9
|
+
* 2. Implement IAuthEmailProvider using EmailSendService from nestjs-email
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // In app.module.ts or a provider file
|
|
14
|
+
* {
|
|
15
|
+
* provide: AUTH_EMAIL_PROVIDER,
|
|
16
|
+
* useFactory: (emailSendService: EmailSendService) => ({
|
|
17
|
+
* sendPasswordResetEmail: async (email, token, resetUrl) => {
|
|
18
|
+
* await emailSendService.sendTemplateEmail({
|
|
19
|
+
* templateSlug: 'password-reset',
|
|
20
|
+
* to: email,
|
|
21
|
+
* variables: { resetUrl, token },
|
|
22
|
+
* });
|
|
23
|
+
* },
|
|
24
|
+
* sendVerificationEmail: async (email, token, verifyUrl) => {
|
|
25
|
+
* await emailSendService.sendTemplateEmail({
|
|
26
|
+
* templateSlug: 'email-verification',
|
|
27
|
+
* to: email,
|
|
28
|
+
* variables: { verifyUrl, token },
|
|
29
|
+
* });
|
|
30
|
+
* },
|
|
31
|
+
* }),
|
|
32
|
+
* inject: [EmailSendService],
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/ "use strict";
|
|
36
|
+
Object.defineProperty(exports, "__esModule", {
|
|
37
|
+
value: true
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "AUTH_EMAIL_PROVIDER", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function() {
|
|
42
|
+
return AUTH_EMAIL_PROVIDER;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const AUTH_EMAIL_PROVIDER = 'AUTH_EMAIL_PROVIDER';
|
package/cjs/interfaces/index.js
CHANGED
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
_export_star(require("./authentication.interface"), exports);
|
|
6
|
+
_export_star(require("./auth-email-provider.interface"), exports);
|
|
6
7
|
_export_star(require("./company-branch.interface"), exports);
|
|
7
8
|
_export_star(require("./company.interface"), exports);
|
|
8
9
|
_export_star(require("./user.interface"), exports);
|
|
10
|
+
_export_star(require("./user-enricher.interface"), exports);
|
|
9
11
|
_export_star(require("./auth-module-options.interface"), exports);
|
|
10
12
|
function _export_star(from, to) {
|
|
11
13
|
Object.keys(from).forEach(function(k) {
|
|
@@ -34,7 +34,7 @@ let AuthModule = class AuthModule {
|
|
|
34
34
|
return this.buildDynamicModule(options);
|
|
35
35
|
}
|
|
36
36
|
static forRootAsync(asyncOptions) {
|
|
37
|
-
const { global = false, includeController = true, bootstrapAppConfig: { enableCompanyFeature } = {}, imports: externalImports = [] } = asyncOptions;
|
|
37
|
+
const { global = false, includeController = true, bootstrapAppConfig: { enableCompanyFeature } = {}, imports: externalImports = [], providers: additionalProviders = [] } = asyncOptions;
|
|
38
38
|
const asyncProviders = this.createAsyncProviders(asyncOptions);
|
|
39
39
|
// Build imports
|
|
40
40
|
const imports = [
|
|
@@ -61,6 +61,7 @@ let AuthModule = class AuthModule {
|
|
|
61
61
|
// Build providers
|
|
62
62
|
const providers = [
|
|
63
63
|
...asyncProviders,
|
|
64
|
+
...additionalProviders,
|
|
64
65
|
// Config & Infrastructure
|
|
65
66
|
_authconfigservice.AuthConfigService,
|
|
66
67
|
_authdatasourceprovider.AuthDataSourceProvider,
|
|
@@ -68,6 +69,7 @@ let AuthModule = class AuthModule {
|
|
|
68
69
|
_jwtstrategy.JwtStrategy,
|
|
69
70
|
_guards.JwtAuthGuard,
|
|
70
71
|
_services.AuthenticationService,
|
|
72
|
+
_services.AuthEmailService,
|
|
71
73
|
// Interceptors
|
|
72
74
|
_settokeninterceptor.SetToken,
|
|
73
75
|
_cleartokeninterceptor.ClearToken,
|
|
@@ -87,6 +89,7 @@ let AuthModule = class AuthModule {
|
|
|
87
89
|
_jwtstrategy.JwtStrategy,
|
|
88
90
|
_guards.JwtAuthGuard,
|
|
89
91
|
_services.AuthenticationService,
|
|
92
|
+
_services.AuthEmailService,
|
|
90
93
|
_services.UserService
|
|
91
94
|
];
|
|
92
95
|
if (enableCompanyFeature) {
|
|
@@ -102,7 +105,7 @@ let AuthModule = class AuthModule {
|
|
|
102
105
|
};
|
|
103
106
|
}
|
|
104
107
|
static buildDynamicModule(options) {
|
|
105
|
-
const { bootstrapAppConfig: { enableCompanyFeature } = {}, includeController = true, global = false } = options;
|
|
108
|
+
const { bootstrapAppConfig: { enableCompanyFeature } = {}, includeController = true, global = false, providers: additionalProviders = [] } = options;
|
|
106
109
|
const imports = [
|
|
107
110
|
_passport.PassportModule.register({
|
|
108
111
|
defaultStrategy: 'jwt'
|
|
@@ -128,6 +131,7 @@ let AuthModule = class AuthModule {
|
|
|
128
131
|
provide: _authconstants.AUTH_MODULE_OPTIONS,
|
|
129
132
|
useValue: options
|
|
130
133
|
},
|
|
134
|
+
...additionalProviders,
|
|
131
135
|
// Config & Infrastructure
|
|
132
136
|
_authconfigservice.AuthConfigService,
|
|
133
137
|
_authdatasourceprovider.AuthDataSourceProvider,
|
|
@@ -135,6 +139,7 @@ let AuthModule = class AuthModule {
|
|
|
135
139
|
_jwtstrategy.JwtStrategy,
|
|
136
140
|
_guards.JwtAuthGuard,
|
|
137
141
|
_services.AuthenticationService,
|
|
142
|
+
_services.AuthEmailService,
|
|
138
143
|
// Interceptors
|
|
139
144
|
_settokeninterceptor.SetToken,
|
|
140
145
|
_cleartokeninterceptor.ClearToken,
|
|
@@ -153,6 +158,7 @@ let AuthModule = class AuthModule {
|
|
|
153
158
|
_jwtstrategy.JwtStrategy,
|
|
154
159
|
_guards.JwtAuthGuard,
|
|
155
160
|
_services.AuthenticationService,
|
|
161
|
+
_services.AuthEmailService,
|
|
156
162
|
_services.UserService
|
|
157
163
|
];
|
|
158
164
|
if (enableCompanyFeature) {
|
|
@@ -39,76 +39,54 @@ 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
|
-
|
|
88
|
-
|
|
69
|
+
// Frontend Configuration
|
|
70
|
+
/** Get frontend URL for email links */ getFrontendUrl() {
|
|
71
|
+
return this.config.frontendUrl;
|
|
72
|
+
}
|
|
73
|
+
// Database Configuration
|
|
74
|
+
/** Get default database config */ getDefaultDatabaseConfig() {
|
|
89
75
|
return this.config.defaultDatabaseConfig ?? this.config.tenantDefaultDatabaseConfig;
|
|
90
76
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Get tenant default database config (for multi-tenant)
|
|
93
|
-
*/ getTenantDefaultDatabaseConfig() {
|
|
77
|
+
/** Get tenant default database config (for multi-tenant) */ getTenantDefaultDatabaseConfig() {
|
|
94
78
|
return this.config.tenantDefaultDatabaseConfig;
|
|
95
79
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Get registered tenants
|
|
98
|
-
*/ getTenants() {
|
|
80
|
+
/** Get registered tenants */ getTenants() {
|
|
99
81
|
return this.config.tenants ?? [];
|
|
100
82
|
}
|
|
101
|
-
//
|
|
102
|
-
/**
|
|
103
|
-
* Get full module options
|
|
104
|
-
*/ getOptions() {
|
|
83
|
+
// Raw Options
|
|
84
|
+
/** Get full module options */ getOptions() {
|
|
105
85
|
return {
|
|
106
86
|
...this.options
|
|
107
87
|
};
|
|
108
88
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Get runtime config
|
|
111
|
-
*/ getConfig() {
|
|
89
|
+
/** Get runtime config */ getConfig() {
|
|
112
90
|
return {
|
|
113
91
|
...this.config
|
|
114
92
|
};
|
|
@@ -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,31 +140,24 @@ 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
|
-
const { Company, CompanyBranch, User, UserCompanyPermission } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../entities")));
|
|
156
|
+
const { Company, CompanyBranch, User, UserCompanyPermission, UserToken, PendingRegistration } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../entities")));
|
|
173
157
|
const coreEntities = [
|
|
174
|
-
User
|
|
158
|
+
User,
|
|
159
|
+
UserToken,
|
|
160
|
+
PendingRegistration
|
|
175
161
|
];
|
|
176
162
|
const companyEntities = enable ? [
|
|
177
163
|
Company,
|
|
@@ -183,10 +169,8 @@ let AuthDataSourceProvider = class AuthDataSourceProvider extends _modules.Multi
|
|
|
183
169
|
...companyEntities
|
|
184
170
|
];
|
|
185
171
|
}
|
|
186
|
-
//
|
|
187
|
-
/**
|
|
188
|
-
* Override to dynamically set entities based on tenant config
|
|
189
|
-
*/ async createDataSourceFromConfig(config) {
|
|
172
|
+
// Overrides
|
|
173
|
+
/** Override to dynamically set entities based on tenant config */ async createDataSourceFromConfig(config) {
|
|
190
174
|
const currentTenant = this.getCurrentTenant();
|
|
191
175
|
const enableCompanyFeature = this.getEnableCompanyFeatureForTenant(currentTenant ?? undefined);
|
|
192
176
|
const entities = await this.getAuthEntities(enableCompanyFeature);
|