@flusys/nestjs-auth 7.0.0 → 7.0.2
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/authentication.service.js +8 -14
- package/cjs/services/branch.service.js +1 -1
- package/cjs/services/company.service.js +1 -1
- package/cjs/services/user.service.js +2 -2
- package/fesm/services/authentication.service.js +8 -14
- package/fesm/services/branch.service.js +2 -2
- package/fesm/services/company.service.js +2 -2
- package/fesm/services/user.service.js +3 -3
- package/interfaces/auth-module-options.interface.d.ts +2 -3
- package/package.json +3 -3
- package/services/authentication.service.d.ts +0 -2
|
@@ -580,7 +580,7 @@ let AuthenticationService = class AuthenticationService {
|
|
|
580
580
|
});
|
|
581
581
|
}
|
|
582
582
|
const response = this.generateLoginResponseWithCompany(user, company, branch);
|
|
583
|
-
this.
|
|
583
|
+
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.SESSION, _config.AUTH_EVENT_ACTIONS.COMPANY_SWITCHED, user, {
|
|
584
584
|
companyId: company.id,
|
|
585
585
|
branchId: branch.id
|
|
586
586
|
});
|
|
@@ -690,7 +690,7 @@ let AuthenticationService = class AuthenticationService {
|
|
|
690
690
|
branchId: payload.branchId
|
|
691
691
|
}
|
|
692
692
|
});
|
|
693
|
-
this.
|
|
693
|
+
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.SESSION, _config.AUTH_EVENT_ACTIONS.TOKEN_REFRESHED, user, {
|
|
694
694
|
companyId: payload.companyId ?? null,
|
|
695
695
|
branchId: payload.branchId ?? null
|
|
696
696
|
});
|
|
@@ -721,7 +721,7 @@ let AuthenticationService = class AuthenticationService {
|
|
|
721
721
|
}
|
|
722
722
|
user.password = await _bcrypt.hash(newPassword, _config.BCRYPT_SALT_ROUNDS);
|
|
723
723
|
await userRepository.save(user);
|
|
724
|
-
this.
|
|
724
|
+
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.USER, _config.AUTH_EVENT_ACTIONS.PASSWORD_CHANGED, user);
|
|
725
725
|
}
|
|
726
726
|
async logout(userId) {
|
|
727
727
|
if (!this.cacheManager) {
|
|
@@ -919,7 +919,7 @@ let AuthenticationService = class AuthenticationService {
|
|
|
919
919
|
type: 'access'
|
|
920
920
|
});
|
|
921
921
|
this.sendLoginNotification(user.id);
|
|
922
|
-
this.
|
|
922
|
+
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.SESSION, _config.AUTH_EVENT_ACTIONS.LOGGED_IN, user);
|
|
923
923
|
return {
|
|
924
924
|
accessToken,
|
|
925
925
|
refreshToken,
|
|
@@ -935,7 +935,7 @@ let AuthenticationService = class AuthenticationService {
|
|
|
935
935
|
branchId: branch?.id
|
|
936
936
|
});
|
|
937
937
|
this.sendLoginNotification(user.id, company.id);
|
|
938
|
-
this.
|
|
938
|
+
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.SESSION, _config.AUTH_EVENT_ACTIONS.LOGGED_IN, user, {
|
|
939
939
|
companyId: company.id,
|
|
940
940
|
branchId: branch?.id ?? null
|
|
941
941
|
});
|
|
@@ -989,7 +989,7 @@ let AuthenticationService = class AuthenticationService {
|
|
|
989
989
|
...this.generateLoginResponse(user),
|
|
990
990
|
requiresEmailVerification: false
|
|
991
991
|
};
|
|
992
|
-
this.
|
|
992
|
+
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.USER, _config.AUTH_EVENT_ACTIONS.REGISTERED, user);
|
|
993
993
|
return response;
|
|
994
994
|
}
|
|
995
995
|
generateRegistrationResponseWithCompany(user, company, branch) {
|
|
@@ -997,19 +997,13 @@ let AuthenticationService = class AuthenticationService {
|
|
|
997
997
|
...this.generateLoginResponseWithCompany(user, company, branch),
|
|
998
998
|
requiresEmailVerification: false
|
|
999
999
|
};
|
|
1000
|
-
this.
|
|
1000
|
+
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.USER, _config.AUTH_EVENT_ACTIONS.REGISTERED, user, {
|
|
1001
1001
|
companyId: company.id,
|
|
1002
1002
|
branchId: branch?.id ?? null
|
|
1003
1003
|
});
|
|
1004
1004
|
return response;
|
|
1005
1005
|
}
|
|
1006
|
-
|
|
1007
|
-
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.SESSION, action, user, metadata);
|
|
1008
|
-
}
|
|
1009
|
-
publishUserEvent(action, user, metadata = {}) {
|
|
1010
|
-
this.publishAuthEvent(_config.AUTH_EVENT_ENTITIES.USER, action, user, metadata);
|
|
1011
|
-
}
|
|
1012
|
-
/** Never awaited - a login must not wait on, or fail because of, the event bus */ publishAuthEvent(entity, action, user, metadata) {
|
|
1006
|
+
/** Never awaited - a login must not wait on, or fail because of, the event bus */ publishAuthEvent(entity, action, user, metadata = {}) {
|
|
1013
1007
|
void (0, _classes.publishDomainEvent)({
|
|
1014
1008
|
module: _config.AUTH_EVENT_MODULE,
|
|
1015
1009
|
entity,
|
|
@@ -129,7 +129,7 @@ let BranchService = class BranchService extends _classes.ApiService {
|
|
|
129
129
|
return result;
|
|
130
130
|
}
|
|
131
131
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig, permissionSyncAdapter){
|
|
132
|
-
super(
|
|
132
|
+
super(_config.AUTH_EVENT_ENTITIES.COMPANY_BRANCH, cacheManager, utilsService, BranchService.name, true, _config.AUTH_EVENT_MODULE, dataSourceProvider, _companybranchentity.CompanyBranch), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "authConfig", void 0), _define_property(this, "permissionSyncAdapter", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.authConfig = authConfig, this.permissionSyncAdapter = permissionSyncAdapter;
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
BranchService = _ts_decorate([
|
|
@@ -118,7 +118,7 @@ let CompanyService = class CompanyService extends _classes.ApiService {
|
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
constructor(cacheManager, utilsService, dataSourceProvider, permissionSyncAdapter){
|
|
121
|
-
super(
|
|
121
|
+
super(_config.AUTH_EVENT_ENTITIES.COMPANY, cacheManager, utilsService, CompanyService.name, true, _config.AUTH_EVENT_MODULE, dataSourceProvider, _companyentity.Company), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "permissionSyncAdapter", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.permissionSyncAdapter = permissionSyncAdapter;
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
124
|
CompanyService = _ts_decorate([
|
|
@@ -101,7 +101,7 @@ let UserService = class UserService extends _classes.ApiService {
|
|
|
101
101
|
]);
|
|
102
102
|
}
|
|
103
103
|
if (!this.dataSource) {
|
|
104
|
-
this.dataSource = await this.
|
|
104
|
+
this.dataSource = await this.getDataSourceProvider().getDataSource();
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
async getUserForProfile(userId, user) {
|
|
@@ -571,7 +571,7 @@ let UserService = class UserService extends _classes.ApiService {
|
|
|
571
571
|
}
|
|
572
572
|
}
|
|
573
573
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig, userEnricher){
|
|
574
|
-
super(
|
|
574
|
+
super(_config.AUTH_EVENT_ENTITIES.USER, cacheManager, utilsService, UserService.name, true, _config.AUTH_EVENT_MODULE, dataSourceProvider, _appuserentity.AppUser), _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);
|
|
575
575
|
}
|
|
576
576
|
};
|
|
577
577
|
_ts_decorate([
|
|
@@ -529,7 +529,7 @@ export class AuthenticationService {
|
|
|
529
529
|
});
|
|
530
530
|
}
|
|
531
531
|
const response = this.generateLoginResponseWithCompany(user, company, branch);
|
|
532
|
-
this.
|
|
532
|
+
this.publishAuthEvent(AUTH_EVENT_ENTITIES.SESSION, AUTH_EVENT_ACTIONS.COMPANY_SWITCHED, user, {
|
|
533
533
|
companyId: company.id,
|
|
534
534
|
branchId: branch.id
|
|
535
535
|
});
|
|
@@ -639,7 +639,7 @@ export class AuthenticationService {
|
|
|
639
639
|
branchId: payload.branchId
|
|
640
640
|
}
|
|
641
641
|
});
|
|
642
|
-
this.
|
|
642
|
+
this.publishAuthEvent(AUTH_EVENT_ENTITIES.SESSION, AUTH_EVENT_ACTIONS.TOKEN_REFRESHED, user, {
|
|
643
643
|
companyId: payload.companyId ?? null,
|
|
644
644
|
branchId: payload.branchId ?? null
|
|
645
645
|
});
|
|
@@ -670,7 +670,7 @@ export class AuthenticationService {
|
|
|
670
670
|
}
|
|
671
671
|
user.password = await bcrypt.hash(newPassword, BCRYPT_SALT_ROUNDS);
|
|
672
672
|
await userRepository.save(user);
|
|
673
|
-
this.
|
|
673
|
+
this.publishAuthEvent(AUTH_EVENT_ENTITIES.USER, AUTH_EVENT_ACTIONS.PASSWORD_CHANGED, user);
|
|
674
674
|
}
|
|
675
675
|
async logout(userId) {
|
|
676
676
|
if (!this.cacheManager) {
|
|
@@ -868,7 +868,7 @@ export class AuthenticationService {
|
|
|
868
868
|
type: 'access'
|
|
869
869
|
});
|
|
870
870
|
this.sendLoginNotification(user.id);
|
|
871
|
-
this.
|
|
871
|
+
this.publishAuthEvent(AUTH_EVENT_ENTITIES.SESSION, AUTH_EVENT_ACTIONS.LOGGED_IN, user);
|
|
872
872
|
return {
|
|
873
873
|
accessToken,
|
|
874
874
|
refreshToken,
|
|
@@ -884,7 +884,7 @@ export class AuthenticationService {
|
|
|
884
884
|
branchId: branch?.id
|
|
885
885
|
});
|
|
886
886
|
this.sendLoginNotification(user.id, company.id);
|
|
887
|
-
this.
|
|
887
|
+
this.publishAuthEvent(AUTH_EVENT_ENTITIES.SESSION, AUTH_EVENT_ACTIONS.LOGGED_IN, user, {
|
|
888
888
|
companyId: company.id,
|
|
889
889
|
branchId: branch?.id ?? null
|
|
890
890
|
});
|
|
@@ -938,7 +938,7 @@ export class AuthenticationService {
|
|
|
938
938
|
...this.generateLoginResponse(user),
|
|
939
939
|
requiresEmailVerification: false
|
|
940
940
|
};
|
|
941
|
-
this.
|
|
941
|
+
this.publishAuthEvent(AUTH_EVENT_ENTITIES.USER, AUTH_EVENT_ACTIONS.REGISTERED, user);
|
|
942
942
|
return response;
|
|
943
943
|
}
|
|
944
944
|
generateRegistrationResponseWithCompany(user, company, branch) {
|
|
@@ -946,19 +946,13 @@ export class AuthenticationService {
|
|
|
946
946
|
...this.generateLoginResponseWithCompany(user, company, branch),
|
|
947
947
|
requiresEmailVerification: false
|
|
948
948
|
};
|
|
949
|
-
this.
|
|
949
|
+
this.publishAuthEvent(AUTH_EVENT_ENTITIES.USER, AUTH_EVENT_ACTIONS.REGISTERED, user, {
|
|
950
950
|
companyId: company.id,
|
|
951
951
|
branchId: branch?.id ?? null
|
|
952
952
|
});
|
|
953
953
|
return response;
|
|
954
954
|
}
|
|
955
|
-
|
|
956
|
-
this.publishAuthEvent(AUTH_EVENT_ENTITIES.SESSION, action, user, metadata);
|
|
957
|
-
}
|
|
958
|
-
publishUserEvent(action, user, metadata = {}) {
|
|
959
|
-
this.publishAuthEvent(AUTH_EVENT_ENTITIES.USER, action, user, metadata);
|
|
960
|
-
}
|
|
961
|
-
/** Never awaited - a login must not wait on, or fail because of, the event bus */ publishAuthEvent(entity, action, user, metadata) {
|
|
955
|
+
/** Never awaited - a login must not wait on, or fail because of, the event bus */ publishAuthEvent(entity, action, user, metadata = {}) {
|
|
962
956
|
void publishDomainEvent({
|
|
963
957
|
module: AUTH_EVENT_MODULE,
|
|
964
958
|
entity,
|
|
@@ -31,7 +31,7 @@ import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
|
31
31
|
import { applyCompanyFilter } from '@flusys/nestjs-shared/utils';
|
|
32
32
|
import { ForbiddenException, Inject, Injectable, Optional, Scope } from '@nestjs/common';
|
|
33
33
|
import { In, IsNull } from 'typeorm';
|
|
34
|
-
import { BRANCH_MESSAGES } from '../config';
|
|
34
|
+
import { AUTH_EVENT_ENTITIES, AUTH_EVENT_MODULE, BRANCH_MESSAGES } from '../config';
|
|
35
35
|
import { CompanyBranch } from '../entities/company-branch.entity';
|
|
36
36
|
import { UserCompanyPermission } from '../entities/user-company-permission.entity';
|
|
37
37
|
import { AuthConfigService } from './auth-config.service';
|
|
@@ -119,7 +119,7 @@ export class BranchService extends ApiService {
|
|
|
119
119
|
return result;
|
|
120
120
|
}
|
|
121
121
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig, permissionSyncAdapter){
|
|
122
|
-
super(
|
|
122
|
+
super(AUTH_EVENT_ENTITIES.COMPANY_BRANCH, cacheManager, utilsService, BranchService.name, true, AUTH_EVENT_MODULE, dataSourceProvider, CompanyBranch), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "authConfig", void 0), _define_property(this, "permissionSyncAdapter", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.authConfig = authConfig, this.permissionSyncAdapter = permissionSyncAdapter;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
BranchService = _ts_decorate([
|
|
@@ -30,7 +30,7 @@ import { IPermissionSyncAdapter, PERMISSION_SYNC_ADAPTER } from '@flusys/nestjs-
|
|
|
30
30
|
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
31
31
|
import { ForbiddenException, Inject, Injectable, Optional, Scope } from '@nestjs/common';
|
|
32
32
|
import { In, IsNull } from 'typeorm';
|
|
33
|
-
import { COMPANY_MESSAGES } from '../config';
|
|
33
|
+
import { AUTH_EVENT_ENTITIES, AUTH_EVENT_MODULE, COMPANY_MESSAGES } from '../config';
|
|
34
34
|
import { CompanyBranch } from '../entities/company-branch.entity';
|
|
35
35
|
import { Company } from '../entities/company.entity';
|
|
36
36
|
import { UserCompanyPermission } from '../entities/user-company-permission.entity';
|
|
@@ -108,7 +108,7 @@ export class CompanyService extends ApiService {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
constructor(cacheManager, utilsService, dataSourceProvider, permissionSyncAdapter){
|
|
111
|
-
super(
|
|
111
|
+
super(AUTH_EVENT_ENTITIES.COMPANY, cacheManager, utilsService, CompanyService.name, true, AUTH_EVENT_MODULE, dataSourceProvider, Company), _define_property(this, "cacheManager", void 0), _define_property(this, "utilsService", void 0), _define_property(this, "permissionSyncAdapter", void 0), this.cacheManager = cacheManager, this.utilsService = utilsService, this.permissionSyncAdapter = permissionSyncAdapter;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
CompanyService = _ts_decorate([
|
|
@@ -32,7 +32,7 @@ import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
|
32
32
|
import { UtilsService } from '@flusys/nestjs-shared/modules';
|
|
33
33
|
import { BadRequestException, ForbiddenException, Inject, Injectable, NotFoundException, Optional, Scope } from '@nestjs/common';
|
|
34
34
|
import * as bcrypt from 'bcrypt';
|
|
35
|
-
import { AUTH_MESSAGES, BCRYPT_SALT_ROUNDS, USER_ENRICHER, USER_MESSAGES, USER_PERMISSION_MESSAGES } from '../config';
|
|
35
|
+
import { AUTH_EVENT_ENTITIES, AUTH_EVENT_MODULE, AUTH_MESSAGES, BCRYPT_SALT_ROUNDS, USER_ENRICHER, USER_MESSAGES, USER_PERMISSION_MESSAGES } from '../config';
|
|
36
36
|
import { CreateUserDto } from '../dtos/user.dto';
|
|
37
37
|
import { AppUser } from '../entities/app-user.entity';
|
|
38
38
|
import { UserCompanyPermission } from '../entities/user-company-permission.entity';
|
|
@@ -50,7 +50,7 @@ export class UserService extends ApiService {
|
|
|
50
50
|
]);
|
|
51
51
|
}
|
|
52
52
|
if (!this.dataSource) {
|
|
53
|
-
this.dataSource = await this.
|
|
53
|
+
this.dataSource = await this.getDataSourceProvider().getDataSource();
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
async getUserForProfile(userId, user) {
|
|
@@ -520,7 +520,7 @@ export class UserService extends ApiService {
|
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
522
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig, userEnricher){
|
|
523
|
-
super(
|
|
523
|
+
super(AUTH_EVENT_ENTITIES.USER, cacheManager, utilsService, UserService.name, true, AUTH_EVENT_MODULE, dataSourceProvider, AppUser), _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);
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
_ts_decorate([
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBootstrapAppConfig, IDataSourceServiceOptions, IDynamicModuleConfig
|
|
1
|
+
import { IBootstrapAppConfig, IDataSourceServiceOptions, IDynamicModuleConfig } from '@flusys/nestjs-core';
|
|
2
2
|
import { IModuleEventsConfig } from '@flusys/nestjs-shared/interfaces';
|
|
3
3
|
import { ModuleMetadata, Provider, Type } from '@nestjs/common';
|
|
4
4
|
export interface IAuthModuleConfig extends IDataSourceServiceOptions {
|
|
@@ -14,9 +14,8 @@ export interface AuthModuleOptions extends IDynamicModuleConfig {
|
|
|
14
14
|
config?: IAuthModuleConfig;
|
|
15
15
|
providers?: Provider[];
|
|
16
16
|
}
|
|
17
|
-
export interface AuthOptionsFactory
|
|
17
|
+
export interface AuthOptionsFactory {
|
|
18
18
|
createAuthOptions(): Promise<IAuthModuleConfig> | IAuthModuleConfig;
|
|
19
|
-
createOptions(): Promise<IAuthModuleConfig> | IAuthModuleConfig;
|
|
20
19
|
}
|
|
21
20
|
export interface AuthModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'>, IDynamicModuleConfig {
|
|
22
21
|
bootstrapAppConfig: IBootstrapAppConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flusys/nestjs-auth",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "Authentication and authorization infrastructure for NestJS applications",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "fesm/index.js",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"rxjs": "^7.8.0"
|
|
99
99
|
},
|
|
100
100
|
"dependencies": {
|
|
101
|
-
"@flusys/nestjs-core": "7.0.
|
|
102
|
-
"@flusys/nestjs-shared": "7.0.
|
|
101
|
+
"@flusys/nestjs-core": "7.0.2",
|
|
102
|
+
"@flusys/nestjs-shared": "7.0.2"
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -61,7 +61,5 @@ export declare class AuthenticationService {
|
|
|
61
61
|
private generateCompanySelectionResponse;
|
|
62
62
|
private generateRegistrationResponse;
|
|
63
63
|
private generateRegistrationResponseWithCompany;
|
|
64
|
-
private publishSessionEvent;
|
|
65
|
-
private publishUserEvent;
|
|
66
64
|
private publishAuthEvent;
|
|
67
65
|
}
|