@flusys/nestjs-auth 5.1.2 → 5.2.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/cjs/services/auth-datasource.provider.js +0 -47
- package/cjs/services/branch.service.js +2 -8
- package/cjs/services/company.service.js +2 -8
- package/cjs/services/user.service.js +10 -16
- package/controllers/authentication.controller.d.ts +1 -1
- package/controllers/branch.controller.d.ts +2 -2
- package/controllers/company.controller.d.ts +2 -2
- package/controllers/user.controller.d.ts +3 -3
- package/fesm/services/auth-datasource.provider.js +2 -49
- package/fesm/services/branch.service.js +3 -9
- package/fesm/services/company.service.js +3 -9
- package/fesm/services/user.service.js +11 -17
- package/interceptors/clear-token.interceptor.d.ts +1 -1
- package/interceptors/set-token.interceptor.d.ts +1 -1
- package/package.json +15 -15
- package/services/auth-datasource.provider.d.ts +0 -2
- package/services/auth-email.service.d.ts +1 -1
- package/services/authentication.service.d.ts +1 -1
- package/services/branch.service.d.ts +3 -6
- package/services/company.service.d.ts +3 -6
- package/services/user.service.d.ts +5 -8
|
@@ -83,53 +83,6 @@ function _ts_param(paramIndex, decorator) {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
let AuthDataSourceProvider = class AuthDataSourceProvider extends _nestjsshared.MultiTenantDataSourceService {
|
|
86
|
-
async getSingleDataSource() {
|
|
87
|
-
if (!AuthDataSourceProvider.singleDataSource) {
|
|
88
|
-
if (AuthDataSourceProvider.singleConnectionLock) {
|
|
89
|
-
return AuthDataSourceProvider.singleConnectionLock;
|
|
90
|
-
}
|
|
91
|
-
const lockPromise = (async ()=>{
|
|
92
|
-
const config = this.getDefaultDatabaseConfig();
|
|
93
|
-
if (!config) {
|
|
94
|
-
throw new _common.InternalServerErrorException({
|
|
95
|
-
message: 'Default database config is not available',
|
|
96
|
-
messageKey: _nestjsshared.SYSTEM_MESSAGES.DATABASE_CONFIG_NOT_AVAILABLE
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
const ds = await this.createDataSourceFromConfig(config);
|
|
100
|
-
AuthDataSourceProvider.singleDataSource = ds;
|
|
101
|
-
AuthDataSourceProvider.initialized = true;
|
|
102
|
-
return ds;
|
|
103
|
-
})();
|
|
104
|
-
AuthDataSourceProvider.singleConnectionLock = lockPromise;
|
|
105
|
-
try {
|
|
106
|
-
return await lockPromise;
|
|
107
|
-
} finally{
|
|
108
|
-
AuthDataSourceProvider.singleConnectionLock = null;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return AuthDataSourceProvider.singleDataSource;
|
|
112
|
-
}
|
|
113
|
-
async getOrCreateTenantConnection(tenant) {
|
|
114
|
-
const existing = AuthDataSourceProvider.tenantConnections.get(tenant.id);
|
|
115
|
-
if (existing?.isInitialized) {
|
|
116
|
-
return existing;
|
|
117
|
-
}
|
|
118
|
-
const pendingConnection = AuthDataSourceProvider.connectionLocks.get(tenant.id);
|
|
119
|
-
if (pendingConnection) {
|
|
120
|
-
return pendingConnection;
|
|
121
|
-
}
|
|
122
|
-
const config = this.buildTenantDatabaseConfig(tenant);
|
|
123
|
-
const connectionPromise = this.createDataSourceFromConfig(config);
|
|
124
|
-
AuthDataSourceProvider.connectionLocks.set(tenant.id, connectionPromise);
|
|
125
|
-
try {
|
|
126
|
-
const dataSource = await connectionPromise;
|
|
127
|
-
AuthDataSourceProvider.tenantConnections.set(tenant.id, dataSource);
|
|
128
|
-
return dataSource;
|
|
129
|
-
} finally{
|
|
130
|
-
AuthDataSourceProvider.connectionLocks.delete(tenant.id);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
86
|
static buildParentOptions(options) {
|
|
134
87
|
return {
|
|
135
88
|
bootstrapAppConfig: options.bootstrapAppConfig,
|
|
@@ -42,13 +42,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
42
42
|
decorator(target, key, paramIndex);
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
let BranchService = class BranchService extends _classes.
|
|
46
|
-
resolveEntity() {
|
|
47
|
-
return _companybranchentity.CompanyBranch;
|
|
48
|
-
}
|
|
49
|
-
getDataSourceProvider() {
|
|
50
|
-
return this.dataSourceProvider;
|
|
51
|
-
}
|
|
45
|
+
let BranchService = class BranchService extends _classes.ApiService {
|
|
52
46
|
// Query Customization
|
|
53
47
|
async getSelectQuery(query, _user, select) {
|
|
54
48
|
if (!select?.length) {
|
|
@@ -91,7 +85,7 @@ let BranchService = class BranchService extends _classes.RequestScopedApiService
|
|
|
91
85
|
return result;
|
|
92
86
|
}
|
|
93
87
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig){
|
|
94
|
-
super('company_branch',
|
|
88
|
+
super('company_branch', cacheManager, utilsService, BranchService.name, true, 'auth', _companybranchentity.CompanyBranch, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "authConfig", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.authConfig = authConfig;
|
|
95
89
|
}
|
|
96
90
|
};
|
|
97
91
|
BranchService = _ts_decorate([
|
|
@@ -40,13 +40,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
40
40
|
decorator(target, key, paramIndex);
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
let CompanyService = class CompanyService extends _classes.
|
|
44
|
-
resolveEntity() {
|
|
45
|
-
return _companyentity.Company;
|
|
46
|
-
}
|
|
47
|
-
getDataSourceProvider() {
|
|
48
|
-
return this.dataSourceProvider;
|
|
49
|
-
}
|
|
43
|
+
let CompanyService = class CompanyService extends _classes.ApiService {
|
|
50
44
|
// Query Customization
|
|
51
45
|
async getSelectQuery(query, _user, select) {
|
|
52
46
|
if (!select?.length) {
|
|
@@ -76,7 +70,7 @@ let CompanyService = class CompanyService extends _classes.RequestScopedApiServi
|
|
|
76
70
|
};
|
|
77
71
|
}
|
|
78
72
|
constructor(cacheManager, utilsService, dataSourceProvider){
|
|
79
|
-
super('company',
|
|
73
|
+
super('company', cacheManager, utilsService, CompanyService.name, true, 'auth', _companyentity.Company, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService;
|
|
80
74
|
}
|
|
81
75
|
};
|
|
82
76
|
CompanyService = _ts_decorate([
|
|
@@ -91,18 +91,12 @@ function _ts_param(paramIndex, decorator) {
|
|
|
91
91
|
decorator(target, key, paramIndex);
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
let UserService = class UserService extends _classes.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
getDataSourceProvider() {
|
|
99
|
-
return this.dataSourceProvider;
|
|
100
|
-
}
|
|
101
|
-
async ensureRepositoryInitialized() {
|
|
102
|
-
await super.ensureRepositoryInitialized();
|
|
94
|
+
let UserService = class UserService extends _classes.ApiService {
|
|
95
|
+
async ensureDataSourceRepository() {
|
|
96
|
+
await super.ensureDataSourceRepository();
|
|
103
97
|
const isCompanyFeatureEnabled = this.authConfig.isCompanyFeatureEnabled();
|
|
104
98
|
if (isCompanyFeatureEnabled && !this.permissionRepository) {
|
|
105
|
-
[this.permissionRepository] = await this.
|
|
99
|
+
[this.permissionRepository] = await this.resolveRepositories([
|
|
106
100
|
_usercompanypermissionentity.UserCompanyPermission
|
|
107
101
|
]);
|
|
108
102
|
}
|
|
@@ -117,7 +111,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
|
|
|
117
111
|
messageKey: _config.AUTH_MESSAGES.PROFILE_ACCESS_DENIED
|
|
118
112
|
});
|
|
119
113
|
}
|
|
120
|
-
await this.
|
|
114
|
+
await this.ensureDataSourceRepository();
|
|
121
115
|
const userEntity = await this.repository.findOne({
|
|
122
116
|
where: {
|
|
123
117
|
id: userId
|
|
@@ -132,7 +126,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
|
|
|
132
126
|
return userEntity;
|
|
133
127
|
}
|
|
134
128
|
async verifyEmail(id) {
|
|
135
|
-
await this.
|
|
129
|
+
await this.ensureDataSourceRepository();
|
|
136
130
|
await this.repository.update(id, {
|
|
137
131
|
emailVerified: true
|
|
138
132
|
});
|
|
@@ -143,7 +137,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
|
|
|
143
137
|
]);
|
|
144
138
|
}
|
|
145
139
|
async verifyPhone(id) {
|
|
146
|
-
await this.
|
|
140
|
+
await this.ensureDataSourceRepository();
|
|
147
141
|
await this.repository.update(id, {
|
|
148
142
|
phoneVerified: true
|
|
149
143
|
});
|
|
@@ -154,7 +148,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
|
|
|
154
148
|
]);
|
|
155
149
|
}
|
|
156
150
|
async updateStatus(id, isActive, user) {
|
|
157
|
-
await this.
|
|
151
|
+
await this.ensureDataSourceRepository();
|
|
158
152
|
const isCompanyFeatureEnabled = this.authConfig.isCompanyFeatureEnabled();
|
|
159
153
|
if (isCompanyFeatureEnabled && user?.companyId && this.permissionRepository) {
|
|
160
154
|
const permission = await this.permissionRepository.findOne({
|
|
@@ -495,7 +489,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
|
|
|
495
489
|
return 100;
|
|
496
490
|
}
|
|
497
491
|
async profile(dto, user) {
|
|
498
|
-
await this.
|
|
492
|
+
await this.ensureDataSourceRepository();
|
|
499
493
|
if (!this.dataSource) {
|
|
500
494
|
throw new _common.BadRequestException({
|
|
501
495
|
message: 'DataSource not available',
|
|
@@ -559,7 +553,7 @@ let UserService = class UserService extends _classes.RequestScopedApiService {
|
|
|
559
553
|
}
|
|
560
554
|
}
|
|
561
555
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig, userEnricher){
|
|
562
|
-
super('appuser',
|
|
556
|
+
super('appuser', cacheManager, utilsService, UserService.name, true, 'auth', _appuserentity.AppUser, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "authConfig", void 0), _define_property(this, "userEnricher", void 0), _define_property(this, "permissionRepository", void 0), _define_property(this, "dataSource", void 0), _define_property(this, "logAdapter", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.authConfig = authConfig, this.userEnricher = userEnricher, this.logAdapter = (0, _classes.createModuleLogger)(this.constructor.name);
|
|
563
557
|
}
|
|
564
558
|
};
|
|
565
559
|
_ts_decorate([
|
|
@@ -7,7 +7,7 @@ import { AuthenticationService } from '../services/authentication.service';
|
|
|
7
7
|
export declare class AuthenticationController {
|
|
8
8
|
private readonly authService;
|
|
9
9
|
private readonly authConfig?;
|
|
10
|
-
constructor(authService: AuthenticationService, authConfig?: AuthConfigService);
|
|
10
|
+
constructor(authService: AuthenticationService, authConfig?: AuthConfigService | undefined);
|
|
11
11
|
login(loginDto: LoginDto): Promise<SingleResponseDto<LoginResponseDto | CompanySelectionResponseDto | LoginResponseRequiresEmailVerificationDto>>;
|
|
12
12
|
register(req: Request, registrationDto: RegistrationDto): Promise<SingleResponseDto<RegistrationResponseDto>>;
|
|
13
13
|
refreshToken(req: Request, refreshTokenDto: RefreshTokenDto): Promise<SingleResponseDto<{
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CompanyBranchResponseDto, CreateCompanyBranchDto, UpdateCompanyBranchDto } from '../dtos/company-branch.dto';
|
|
2
2
|
import { BranchService } from '../services/branch.service';
|
|
3
3
|
declare const BranchController_base: abstract new (service: BranchService) => {
|
|
4
|
-
readonly enabledEndpoints: import("@flusys/nestjs-shared
|
|
4
|
+
readonly enabledEndpoints: import("@flusys/nestjs-shared").ApiEndpoint[] | "all";
|
|
5
5
|
service: BranchService;
|
|
6
|
-
isEnabled(endpoint: import("@flusys/nestjs-shared
|
|
6
|
+
isEnabled(endpoint: import("@flusys/nestjs-shared").ApiEndpoint): boolean;
|
|
7
7
|
insert(addDto: CreateCompanyBranchDto, user: import("@flusys/nestjs-shared").ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").SingleResponseDto<CompanyBranchResponseDto>>;
|
|
8
8
|
insertMany(addDto: CreateCompanyBranchDto[], user: import("@flusys/nestjs-shared").ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<CompanyBranchResponseDto>>;
|
|
9
9
|
getById(id: string, body: import("@flusys/nestjs-shared").GetByIdBodyDto, user: import("@flusys/nestjs-shared").ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").SingleResponseDto<CompanyBranchResponseDto>>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CompanyResponseDto, CreateCompanyDto, UpdateCompanyDto } from '../dtos/company.dto';
|
|
2
2
|
import { CompanyService } from '../services/company.service';
|
|
3
3
|
declare const CompanyController_base: abstract new (service: CompanyService) => {
|
|
4
|
-
readonly enabledEndpoints: import("@flusys/nestjs-shared
|
|
4
|
+
readonly enabledEndpoints: import("@flusys/nestjs-shared").ApiEndpoint[] | "all";
|
|
5
5
|
service: CompanyService;
|
|
6
|
-
isEnabled(endpoint: import("@flusys/nestjs-shared
|
|
6
|
+
isEnabled(endpoint: import("@flusys/nestjs-shared").ApiEndpoint): boolean;
|
|
7
7
|
insert(addDto: CreateCompanyDto, user: import("@flusys/nestjs-shared").ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").SingleResponseDto<CompanyResponseDto>>;
|
|
8
8
|
insertMany(addDto: CreateCompanyDto[], user: import("@flusys/nestjs-shared").ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<CompanyResponseDto>>;
|
|
9
9
|
getById(id: string, body: import("@flusys/nestjs-shared").GetByIdBodyDto, user: import("@flusys/nestjs-shared").ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").SingleResponseDto<CompanyResponseDto>>;
|
|
@@ -3,9 +3,9 @@ import { CreateUserDto, UpdateUserDto, UserResponseDto } from '../dtos/user.dto'
|
|
|
3
3
|
import { IUser } from '../interfaces/user.interface';
|
|
4
4
|
import { UserService } from '../services/user.service';
|
|
5
5
|
declare const UserController_base: abstract new (service: UserService) => {
|
|
6
|
-
readonly enabledEndpoints: import("@flusys/nestjs-shared
|
|
6
|
+
readonly enabledEndpoints: import("@flusys/nestjs-shared").ApiEndpoint[] | "all";
|
|
7
7
|
service: UserService;
|
|
8
|
-
isEnabled(endpoint: import("@flusys/nestjs-shared
|
|
8
|
+
isEnabled(endpoint: import("@flusys/nestjs-shared").ApiEndpoint): boolean;
|
|
9
9
|
insert(addDto: CreateUserDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").SingleResponseDto<UserResponseDto>>;
|
|
10
10
|
insertMany(addDto: CreateUserDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").BulkResponseDto<UserResponseDto>>;
|
|
11
11
|
getById(id: string, body: import("@flusys/nestjs-shared").GetByIdBodyDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared").SingleResponseDto<UserResponseDto>>;
|
|
@@ -60,7 +60,7 @@ export declare class UserController extends UserController_base {
|
|
|
60
60
|
success: boolean;
|
|
61
61
|
message: string;
|
|
62
62
|
messageKey: "user.profile.section.data.success";
|
|
63
|
-
data: import("..").IProfileSectionData;
|
|
63
|
+
data: import("..").IProfileSectionData | null;
|
|
64
64
|
}>;
|
|
65
65
|
updateProfileSection(id: string, sectionId: string, data: Record<string, any>, user: ILoggedUserInfo): Promise<{
|
|
66
66
|
success: boolean;
|
|
@@ -25,60 +25,13 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
import { MultiTenantDataSourceService
|
|
29
|
-
import { Inject, Injectable,
|
|
28
|
+
import { MultiTenantDataSourceService } from '@flusys/nestjs-shared';
|
|
29
|
+
import { Inject, Injectable, Optional, Scope } from '@nestjs/common';
|
|
30
30
|
import { REQUEST } from '@nestjs/core';
|
|
31
31
|
import { Request } from 'express';
|
|
32
32
|
import { AuthModuleOptions } from '../interfaces/auth-module-options.interface';
|
|
33
33
|
import { AUTH_MODULE_OPTIONS } from '../config/auth.constants';
|
|
34
34
|
export class AuthDataSourceProvider extends MultiTenantDataSourceService {
|
|
35
|
-
async getSingleDataSource() {
|
|
36
|
-
if (!AuthDataSourceProvider.singleDataSource) {
|
|
37
|
-
if (AuthDataSourceProvider.singleConnectionLock) {
|
|
38
|
-
return AuthDataSourceProvider.singleConnectionLock;
|
|
39
|
-
}
|
|
40
|
-
const lockPromise = (async ()=>{
|
|
41
|
-
const config = this.getDefaultDatabaseConfig();
|
|
42
|
-
if (!config) {
|
|
43
|
-
throw new InternalServerErrorException({
|
|
44
|
-
message: 'Default database config is not available',
|
|
45
|
-
messageKey: SYSTEM_MESSAGES.DATABASE_CONFIG_NOT_AVAILABLE
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const ds = await this.createDataSourceFromConfig(config);
|
|
49
|
-
AuthDataSourceProvider.singleDataSource = ds;
|
|
50
|
-
AuthDataSourceProvider.initialized = true;
|
|
51
|
-
return ds;
|
|
52
|
-
})();
|
|
53
|
-
AuthDataSourceProvider.singleConnectionLock = lockPromise;
|
|
54
|
-
try {
|
|
55
|
-
return await lockPromise;
|
|
56
|
-
} finally{
|
|
57
|
-
AuthDataSourceProvider.singleConnectionLock = null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return AuthDataSourceProvider.singleDataSource;
|
|
61
|
-
}
|
|
62
|
-
async getOrCreateTenantConnection(tenant) {
|
|
63
|
-
const existing = AuthDataSourceProvider.tenantConnections.get(tenant.id);
|
|
64
|
-
if (existing?.isInitialized) {
|
|
65
|
-
return existing;
|
|
66
|
-
}
|
|
67
|
-
const pendingConnection = AuthDataSourceProvider.connectionLocks.get(tenant.id);
|
|
68
|
-
if (pendingConnection) {
|
|
69
|
-
return pendingConnection;
|
|
70
|
-
}
|
|
71
|
-
const config = this.buildTenantDatabaseConfig(tenant);
|
|
72
|
-
const connectionPromise = this.createDataSourceFromConfig(config);
|
|
73
|
-
AuthDataSourceProvider.connectionLocks.set(tenant.id, connectionPromise);
|
|
74
|
-
try {
|
|
75
|
-
const dataSource = await connectionPromise;
|
|
76
|
-
AuthDataSourceProvider.tenantConnections.set(tenant.id, dataSource);
|
|
77
|
-
return dataSource;
|
|
78
|
-
} finally{
|
|
79
|
-
AuthDataSourceProvider.connectionLocks.delete(tenant.id);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
35
|
static buildParentOptions(options) {
|
|
83
36
|
return {
|
|
84
37
|
bootstrapAppConfig: options.bootstrapAppConfig,
|
|
@@ -25,20 +25,14 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
import { HybridCache,
|
|
28
|
+
import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
|
|
29
29
|
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
30
30
|
import { applyCompanyFilter } from '@flusys/nestjs-shared/utils';
|
|
31
31
|
import { Inject, Injectable, Scope } from '@nestjs/common';
|
|
32
32
|
import { CompanyBranch } from '../entities/company-branch.entity';
|
|
33
33
|
import { AuthConfigService } from './auth-config.service';
|
|
34
34
|
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
35
|
-
export class BranchService extends
|
|
36
|
-
resolveEntity() {
|
|
37
|
-
return CompanyBranch;
|
|
38
|
-
}
|
|
39
|
-
getDataSourceProvider() {
|
|
40
|
-
return this.dataSourceProvider;
|
|
41
|
-
}
|
|
35
|
+
export class BranchService extends ApiService {
|
|
42
36
|
// Query Customization
|
|
43
37
|
async getSelectQuery(query, _user, select) {
|
|
44
38
|
if (!select?.length) {
|
|
@@ -81,7 +75,7 @@ export class BranchService extends RequestScopedApiService {
|
|
|
81
75
|
return result;
|
|
82
76
|
}
|
|
83
77
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig){
|
|
84
|
-
super('company_branch',
|
|
78
|
+
super('company_branch', cacheManager, utilsService, BranchService.name, true, 'auth', CompanyBranch, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "authConfig", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.authConfig = authConfig;
|
|
85
79
|
}
|
|
86
80
|
}
|
|
87
81
|
BranchService = _ts_decorate([
|
|
@@ -25,18 +25,12 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
import { HybridCache,
|
|
28
|
+
import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
|
|
29
29
|
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
30
30
|
import { Inject, Injectable, Scope } from '@nestjs/common';
|
|
31
31
|
import { Company } from '../entities/company.entity';
|
|
32
32
|
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
33
|
-
export class CompanyService extends
|
|
34
|
-
resolveEntity() {
|
|
35
|
-
return Company;
|
|
36
|
-
}
|
|
37
|
-
getDataSourceProvider() {
|
|
38
|
-
return this.dataSourceProvider;
|
|
39
|
-
}
|
|
33
|
+
export class CompanyService extends ApiService {
|
|
40
34
|
// Query Customization
|
|
41
35
|
async getSelectQuery(query, _user, select) {
|
|
42
36
|
if (!select?.length) {
|
|
@@ -66,7 +60,7 @@ export class CompanyService extends RequestScopedApiService {
|
|
|
66
60
|
};
|
|
67
61
|
}
|
|
68
62
|
constructor(cacheManager, utilsService, dataSourceProvider){
|
|
69
|
-
super('company',
|
|
63
|
+
super('company', cacheManager, utilsService, CompanyService.name, true, 'auth', Company, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService;
|
|
70
64
|
}
|
|
71
65
|
}
|
|
72
66
|
CompanyService = _ts_decorate([
|
|
@@ -26,7 +26,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
import { LogAction } from '@flusys/nestjs-shared';
|
|
29
|
-
import { createModuleLogger, HybridCache,
|
|
29
|
+
import { createModuleLogger, HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
|
|
30
30
|
import { SYSTEM_MESSAGES } from '@flusys/nestjs-shared/constants';
|
|
31
31
|
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
32
32
|
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
@@ -40,18 +40,12 @@ import { PermissionType } from '../enums';
|
|
|
40
40
|
import { IUserEnricher } from '../interfaces/user-enricher.interface';
|
|
41
41
|
import { AuthConfigService } from './auth-config.service';
|
|
42
42
|
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
43
|
-
export class UserService extends
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
getDataSourceProvider() {
|
|
48
|
-
return this.dataSourceProvider;
|
|
49
|
-
}
|
|
50
|
-
async ensureRepositoryInitialized() {
|
|
51
|
-
await super.ensureRepositoryInitialized();
|
|
43
|
+
export class UserService extends ApiService {
|
|
44
|
+
async ensureDataSourceRepository() {
|
|
45
|
+
await super.ensureDataSourceRepository();
|
|
52
46
|
const isCompanyFeatureEnabled = this.authConfig.isCompanyFeatureEnabled();
|
|
53
47
|
if (isCompanyFeatureEnabled && !this.permissionRepository) {
|
|
54
|
-
[this.permissionRepository] = await this.
|
|
48
|
+
[this.permissionRepository] = await this.resolveRepositories([
|
|
55
49
|
UserCompanyPermission
|
|
56
50
|
]);
|
|
57
51
|
}
|
|
@@ -66,7 +60,7 @@ export class UserService extends RequestScopedApiService {
|
|
|
66
60
|
messageKey: AUTH_MESSAGES.PROFILE_ACCESS_DENIED
|
|
67
61
|
});
|
|
68
62
|
}
|
|
69
|
-
await this.
|
|
63
|
+
await this.ensureDataSourceRepository();
|
|
70
64
|
const userEntity = await this.repository.findOne({
|
|
71
65
|
where: {
|
|
72
66
|
id: userId
|
|
@@ -81,7 +75,7 @@ export class UserService extends RequestScopedApiService {
|
|
|
81
75
|
return userEntity;
|
|
82
76
|
}
|
|
83
77
|
async verifyEmail(id) {
|
|
84
|
-
await this.
|
|
78
|
+
await this.ensureDataSourceRepository();
|
|
85
79
|
await this.repository.update(id, {
|
|
86
80
|
emailVerified: true
|
|
87
81
|
});
|
|
@@ -92,7 +86,7 @@ export class UserService extends RequestScopedApiService {
|
|
|
92
86
|
]);
|
|
93
87
|
}
|
|
94
88
|
async verifyPhone(id) {
|
|
95
|
-
await this.
|
|
89
|
+
await this.ensureDataSourceRepository();
|
|
96
90
|
await this.repository.update(id, {
|
|
97
91
|
phoneVerified: true
|
|
98
92
|
});
|
|
@@ -103,7 +97,7 @@ export class UserService extends RequestScopedApiService {
|
|
|
103
97
|
]);
|
|
104
98
|
}
|
|
105
99
|
async updateStatus(id, isActive, user) {
|
|
106
|
-
await this.
|
|
100
|
+
await this.ensureDataSourceRepository();
|
|
107
101
|
const isCompanyFeatureEnabled = this.authConfig.isCompanyFeatureEnabled();
|
|
108
102
|
if (isCompanyFeatureEnabled && user?.companyId && this.permissionRepository) {
|
|
109
103
|
const permission = await this.permissionRepository.findOne({
|
|
@@ -444,7 +438,7 @@ export class UserService extends RequestScopedApiService {
|
|
|
444
438
|
return 100;
|
|
445
439
|
}
|
|
446
440
|
async profile(dto, user) {
|
|
447
|
-
await this.
|
|
441
|
+
await this.ensureDataSourceRepository();
|
|
448
442
|
if (!this.dataSource) {
|
|
449
443
|
throw new BadRequestException({
|
|
450
444
|
message: 'DataSource not available',
|
|
@@ -508,7 +502,7 @@ export class UserService extends RequestScopedApiService {
|
|
|
508
502
|
}
|
|
509
503
|
}
|
|
510
504
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig, userEnricher){
|
|
511
|
-
super('appuser',
|
|
505
|
+
super('appuser', cacheManager, utilsService, UserService.name, true, 'auth', AppUser, dataSourceProvider), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "authConfig", void 0), _define_property(this, "userEnricher", void 0), _define_property(this, "permissionRepository", void 0), _define_property(this, "dataSource", void 0), _define_property(this, "logAdapter", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.authConfig = authConfig, this.userEnricher = userEnricher, this.logAdapter = createModuleLogger(this.constructor.name);
|
|
512
506
|
}
|
|
513
507
|
}
|
|
514
508
|
_ts_decorate([
|
|
@@ -3,7 +3,7 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { AuthConfigService } from '../services/auth-config.service';
|
|
4
4
|
export declare class ClearToken implements NestInterceptor {
|
|
5
5
|
private readonly authConfig?;
|
|
6
|
-
constructor(authConfig?: AuthConfigService);
|
|
6
|
+
constructor(authConfig?: AuthConfigService | undefined);
|
|
7
7
|
private get cookieName();
|
|
8
8
|
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
9
9
|
}
|
|
@@ -3,7 +3,7 @@ import { Observable } from 'rxjs';
|
|
|
3
3
|
import { AuthConfigService } from '../services/auth-config.service';
|
|
4
4
|
export declare class SetToken implements NestInterceptor {
|
|
5
5
|
private readonly authConfig?;
|
|
6
|
-
constructor(authConfig?: AuthConfigService);
|
|
6
|
+
constructor(authConfig?: AuthConfigService | undefined);
|
|
7
7
|
private get cookieName();
|
|
8
8
|
private get maxAgeMs();
|
|
9
9
|
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flusys/nestjs-auth",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Authentication and authorization infrastructure for NestJS applications",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "fesm/index.js",
|
|
@@ -74,26 +74,26 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@nestjs/common": "^
|
|
78
|
-
"@nestjs/config": "^
|
|
79
|
-
"@nestjs/core": "^
|
|
80
|
-
"@nestjs/jwt": "^
|
|
81
|
-
"@nestjs/passport": "^
|
|
82
|
-
"@nestjs/swagger": "^
|
|
83
|
-
"@nestjs/typeorm": "^
|
|
84
|
-
"bcrypt": "^
|
|
85
|
-
"class-transformer": "^0.5.
|
|
86
|
-
"class-validator": "^0.14.0",
|
|
87
|
-
"nodemailer": "^7.0.0",
|
|
77
|
+
"@nestjs/common": "^11.0.0",
|
|
78
|
+
"@nestjs/config": "^4.0.0",
|
|
79
|
+
"@nestjs/core": "^11.0.0",
|
|
80
|
+
"@nestjs/jwt": "^11.0.0",
|
|
81
|
+
"@nestjs/passport": "^11.0.0",
|
|
82
|
+
"@nestjs/swagger": "^11.0.0",
|
|
83
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
84
|
+
"bcrypt": "^6.0.0",
|
|
85
|
+
"class-transformer": "^0.5.1",
|
|
86
|
+
"class-validator": "^0.14.0 || ^0.15.0",
|
|
87
|
+
"nodemailer": "^7.0.0 || ^8.0.0",
|
|
88
88
|
"passport": "^0.7.0",
|
|
89
89
|
"passport-jwt": "^4.0.0",
|
|
90
90
|
"passport-local": "^1.0.0",
|
|
91
91
|
"typeorm": "^0.3.0",
|
|
92
|
-
"express": "^4.18.0",
|
|
92
|
+
"express": "^4.18.0 || ^5.0.0",
|
|
93
93
|
"rxjs": "^7.8.0"
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"@flusys/nestjs-core": "5.
|
|
97
|
-
"@flusys/nestjs-shared": "5.
|
|
96
|
+
"@flusys/nestjs-core": "5.2.0",
|
|
97
|
+
"@flusys/nestjs-shared": "5.2.0"
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -12,8 +12,6 @@ export declare class AuthDataSourceProvider extends MultiTenantDataSourceService
|
|
|
12
12
|
protected static readonly connectionLocks: Map<string, Promise<DataSource>>;
|
|
13
13
|
protected static singleConnectionLock: Promise<DataSource> | null;
|
|
14
14
|
constructor(authOptions: AuthModuleOptions, request?: Request);
|
|
15
|
-
protected getSingleDataSource(): Promise<DataSource>;
|
|
16
|
-
protected getOrCreateTenantConnection(tenant: ITenantDatabaseConfig): Promise<DataSource>;
|
|
17
15
|
private static buildParentOptions;
|
|
18
16
|
isCompanyFeatureEnabled(tenant?: ITenantDatabaseConfig): boolean;
|
|
19
17
|
isEmailVerificationEnabled(tenant?: ITenantDatabaseConfig): boolean;
|
|
@@ -6,7 +6,7 @@ export declare class AuthEmailService {
|
|
|
6
6
|
private readonly emailProvider?;
|
|
7
7
|
private readonly PASSWORD_RESET_EXPIRY;
|
|
8
8
|
private readonly EMAIL_VERIFICATION_EXPIRY;
|
|
9
|
-
constructor(dataSourceProvider?: AuthDataSourceProvider, emailProvider?: IAuthEmailProvider);
|
|
9
|
+
constructor(dataSourceProvider?: AuthDataSourceProvider | undefined, emailProvider?: IAuthEmailProvider | undefined);
|
|
10
10
|
isEmailEnabled(): boolean;
|
|
11
11
|
private getRepository;
|
|
12
12
|
private generateToken;
|
|
@@ -20,7 +20,7 @@ export declare class AuthenticationService {
|
|
|
20
20
|
private readonly authEmailService?;
|
|
21
21
|
private readonly userEnricher?;
|
|
22
22
|
private readonly notificationAdapter?;
|
|
23
|
-
constructor(jwtService: JwtService, authConfig: AuthConfigService, cacheManager?: HybridCache, dataSourceProvider?: AuthDataSourceProvider, sessionService?: CompanySelectionSessionService, authEmailService?: AuthEmailService, userEnricher?: IUserEnricher, notificationAdapter?: INotificationAdapter);
|
|
23
|
+
constructor(jwtService: JwtService, authConfig: AuthConfigService, cacheManager?: HybridCache | undefined, dataSourceProvider?: AuthDataSourceProvider | undefined, sessionService?: CompanySelectionSessionService | undefined, authEmailService?: AuthEmailService | undefined, userEnricher?: IUserEnricher | undefined, notificationAdapter?: INotificationAdapter | undefined);
|
|
24
24
|
private isCompanyFeatureEnabled;
|
|
25
25
|
private isEmailVerificationEnabled;
|
|
26
26
|
private getUserRepository;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { HybridCache,
|
|
1
|
+
import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
|
|
2
2
|
import { FilterAndPaginationDto } from '@flusys/nestjs-shared/dtos';
|
|
3
3
|
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
4
4
|
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
5
|
-
import {
|
|
5
|
+
import { SelectQueryBuilder } from 'typeorm';
|
|
6
6
|
import { CreateCompanyBranchDto, UpdateCompanyBranchDto } from '../dtos/company-branch.dto';
|
|
7
7
|
import { CompanyBranch } from '../entities/company-branch.entity';
|
|
8
8
|
import { ICompanyBranch } from '../interfaces/company-branch.interface';
|
|
9
9
|
import { AuthConfigService } from './auth-config.service';
|
|
10
10
|
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
11
|
-
export declare class BranchService extends
|
|
11
|
+
export declare class BranchService extends ApiService<CreateCompanyBranchDto, UpdateCompanyBranchDto, ICompanyBranch, CompanyBranch> {
|
|
12
12
|
protected cacheManager: HybridCache;
|
|
13
13
|
protected utilsService: UtilsService;
|
|
14
|
-
private readonly dataSourceProvider;
|
|
15
14
|
private readonly authConfig;
|
|
16
15
|
constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider, authConfig: AuthConfigService);
|
|
17
|
-
protected resolveEntity(): EntityTarget<CompanyBranch>;
|
|
18
|
-
protected getDataSourceProvider(): AuthDataSourceProvider;
|
|
19
16
|
getSelectQuery(query: SelectQueryBuilder<CompanyBranch>, _user: ILoggedUserInfo | null, select?: string[]): Promise<{
|
|
20
17
|
query: SelectQueryBuilder<CompanyBranch>;
|
|
21
18
|
isRaw: boolean;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { HybridCache,
|
|
1
|
+
import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
|
|
2
2
|
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
3
3
|
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
4
|
-
import {
|
|
4
|
+
import { SelectQueryBuilder } from 'typeorm';
|
|
5
5
|
import { CreateCompanyDto, UpdateCompanyDto } from '../dtos/company.dto';
|
|
6
6
|
import { Company } from '../entities/company.entity';
|
|
7
7
|
import { ICompany } from '../interfaces/company.interface';
|
|
8
8
|
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
9
|
-
export declare class CompanyService extends
|
|
9
|
+
export declare class CompanyService extends ApiService<CreateCompanyDto, UpdateCompanyDto, ICompany, Company> {
|
|
10
10
|
protected cacheManager: HybridCache;
|
|
11
11
|
protected utilsService: UtilsService;
|
|
12
|
-
private readonly dataSourceProvider;
|
|
13
12
|
constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider);
|
|
14
|
-
protected resolveEntity(): EntityTarget<Company>;
|
|
15
|
-
protected getDataSourceProvider(): AuthDataSourceProvider;
|
|
16
13
|
getSelectQuery(query: SelectQueryBuilder<Company>, _user: ILoggedUserInfo | null, select?: string[]): Promise<{
|
|
17
14
|
query: SelectQueryBuilder<Company>;
|
|
18
15
|
isRaw: boolean;
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import { HybridCache,
|
|
1
|
+
import { HybridCache, ApiService } from '@flusys/nestjs-shared/classes';
|
|
2
2
|
import { FilterAndPaginationDto } from '@flusys/nestjs-shared/dtos';
|
|
3
3
|
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
4
4
|
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
5
|
-
import {
|
|
5
|
+
import { SelectQueryBuilder } from 'typeorm';
|
|
6
6
|
import { CreateUserDto, UpdateUserDto } from '../dtos/user.dto';
|
|
7
7
|
import { AppUser } from '../entities/app-user.entity';
|
|
8
8
|
import { IEnrichedUser, IProfileExtras, IProfileSection, IProfileSectionData, IUserEnricher } from '../interfaces/user-enricher.interface';
|
|
9
9
|
import { IUser } from '../interfaces/user.interface';
|
|
10
10
|
import { AuthConfigService } from './auth-config.service';
|
|
11
11
|
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
12
|
-
export declare class UserService extends
|
|
12
|
+
export declare class UserService extends ApiService<CreateUserDto, UpdateUserDto, IUser, AppUser> {
|
|
13
13
|
protected cacheManager: HybridCache;
|
|
14
14
|
protected utilsService: UtilsService;
|
|
15
|
-
private readonly dataSourceProvider;
|
|
16
15
|
private readonly authConfig;
|
|
17
16
|
private readonly userEnricher?;
|
|
18
17
|
private permissionRepository?;
|
|
19
18
|
private dataSource?;
|
|
20
19
|
private readonly logAdapter;
|
|
21
|
-
constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider, authConfig: AuthConfigService, userEnricher?: IUserEnricher);
|
|
22
|
-
protected
|
|
23
|
-
protected getDataSourceProvider(): AuthDataSourceProvider;
|
|
24
|
-
protected ensureRepositoryInitialized(): Promise<void>;
|
|
20
|
+
constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider, authConfig: AuthConfigService, userEnricher?: IUserEnricher | undefined);
|
|
21
|
+
protected ensureDataSourceRepository(): Promise<void>;
|
|
25
22
|
private getUserForProfile;
|
|
26
23
|
verifyEmail(id: string): Promise<void>;
|
|
27
24
|
verifyPhone(id: string): Promise<void>;
|