@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
|
@@ -26,6 +26,7 @@ import { PassportStrategy } from '@nestjs/passport';
|
|
|
26
26
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
27
27
|
import { AuthConfigService } from '../services/auth-config.service';
|
|
28
28
|
import { AuthDataSourceProvider } from '../services/auth-datasource.provider';
|
|
29
|
+
import { AuthenticationService } from '../services/authentication.service';
|
|
29
30
|
import { User } from '../entities/user.entity';
|
|
30
31
|
/**
|
|
31
32
|
* Type guard to check if payload includes company context
|
|
@@ -34,8 +35,9 @@ import { User } from '../entities/user.entity';
|
|
|
34
35
|
}
|
|
35
36
|
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|
36
37
|
async validate(_req, payload) {
|
|
37
|
-
// Resolve request-scoped
|
|
38
|
+
// Resolve request-scoped services for this request
|
|
38
39
|
let userRepository = null;
|
|
40
|
+
let authService = null;
|
|
39
41
|
try {
|
|
40
42
|
const dataSourceProvider = await this.moduleRef.resolve(AuthDataSourceProvider, undefined, {
|
|
41
43
|
strict: false
|
|
@@ -43,12 +45,23 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|
|
43
45
|
if (dataSourceProvider) {
|
|
44
46
|
userRepository = await dataSourceProvider.getRepository(User);
|
|
45
47
|
}
|
|
48
|
+
// Resolve AuthenticationService for token revocation check
|
|
49
|
+
authService = await this.moduleRef.resolve(AuthenticationService, undefined, {
|
|
50
|
+
strict: false
|
|
51
|
+
});
|
|
46
52
|
} catch (error) {
|
|
47
53
|
throw new UnauthorizedException('Unable to access user data');
|
|
48
54
|
}
|
|
49
55
|
if (!userRepository) {
|
|
50
56
|
throw new UnauthorizedException('User repository not available');
|
|
51
57
|
}
|
|
58
|
+
// Check if token is revoked (logged out)
|
|
59
|
+
if (authService && payload.iat) {
|
|
60
|
+
const isRevoked = await authService.isTokenRevoked(payload.id, payload.iat);
|
|
61
|
+
if (isRevoked) {
|
|
62
|
+
throw new UnauthorizedException('Token has been revoked');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
52
65
|
// Find user and check if active
|
|
53
66
|
const user = await userRepository.findOne({
|
|
54
67
|
where: {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface IAuthEmailProvider {
|
|
2
|
+
sendPasswordResetEmail(email: string, token: string, resetUrl: string): Promise<void>;
|
|
3
|
+
sendVerificationEmail(email: string, token: string, verifyUrl: string): Promise<void>;
|
|
4
|
+
sendWelcomeEmail?(email: string, name: string): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare const AUTH_EMAIL_PROVIDER = "AUTH_EMAIL_PROVIDER";
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { IBootstrapAppConfig, IDataSourceServiceOptions, IDynamicModuleConfig, IModuleOptionsFactory } from '@flusys/nestjs-core';
|
|
2
|
-
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
import { ModuleMetadata, Provider, Type } from '@nestjs/common';
|
|
3
3
|
export interface IAuthModuleConfig extends IDataSourceServiceOptions {
|
|
4
4
|
jwtSecret?: string;
|
|
5
5
|
jwtExpiration?: string;
|
|
6
6
|
refreshTokenSecret?: string;
|
|
7
7
|
refreshTokenExpiration?: string;
|
|
8
8
|
refreshTokenCookieName?: string;
|
|
9
|
+
frontendUrl?: string;
|
|
9
10
|
}
|
|
10
11
|
export interface AuthModuleOptions extends IDynamicModuleConfig {
|
|
11
12
|
bootstrapAppConfig?: IBootstrapAppConfig;
|
|
12
13
|
config?: IAuthModuleConfig;
|
|
14
|
+
providers?: Provider[];
|
|
13
15
|
}
|
|
14
16
|
export interface AuthOptionsFactory extends IModuleOptionsFactory<IAuthModuleConfig> {
|
|
15
17
|
createAuthOptions(): Promise<IAuthModuleConfig> | IAuthModuleConfig;
|
|
@@ -21,4 +23,5 @@ export interface AuthModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'>,
|
|
|
21
23
|
inject?: any[];
|
|
22
24
|
useClass?: Type<AuthOptionsFactory>;
|
|
23
25
|
useExisting?: Type<AuthOptionsFactory>;
|
|
26
|
+
providers?: Provider[];
|
|
24
27
|
}
|
|
@@ -51,3 +51,17 @@ export interface LoginResponseRequiresSelection {
|
|
|
51
51
|
user: IUserMini;
|
|
52
52
|
companies: CompanyWithBranches[];
|
|
53
53
|
}
|
|
54
|
+
export interface RegistrationResponse {
|
|
55
|
+
accessToken?: string;
|
|
56
|
+
refreshToken?: string;
|
|
57
|
+
user: IUserMini;
|
|
58
|
+
company?: ICompanyMini;
|
|
59
|
+
branch?: ICompanyBranchMini;
|
|
60
|
+
companyFeatureEnabled?: boolean;
|
|
61
|
+
requiresEmailVerification?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface LoginResponseRequiresEmailVerification {
|
|
64
|
+
requiresEmailVerification: true;
|
|
65
|
+
email: string;
|
|
66
|
+
message: string;
|
|
67
|
+
}
|
package/interfaces/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './authentication.interface';
|
|
2
|
+
export * from './auth-email-provider.interface';
|
|
2
3
|
export * from './company-branch.interface';
|
|
3
4
|
export * from './company.interface';
|
|
4
5
|
export * from './user.interface';
|
|
6
|
+
export * from './user-enricher.interface';
|
|
5
7
|
export * from './auth-module-options.interface';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
2
|
+
import { QueryRunner, SelectQueryBuilder } from 'typeorm';
|
|
3
|
+
import { User } from '../entities/user.entity';
|
|
4
|
+
import { IUser } from './user.interface';
|
|
5
|
+
export interface IProfileSection {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
order: number;
|
|
9
|
+
icon?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
hasFileUpload?: boolean;
|
|
12
|
+
editPermission?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface IProfileSectionData {
|
|
15
|
+
sectionId: string;
|
|
16
|
+
data: Record<string, any>;
|
|
17
|
+
isComplete: boolean;
|
|
18
|
+
files?: IProfileFile[];
|
|
19
|
+
}
|
|
20
|
+
export interface IProfileFile {
|
|
21
|
+
field: string;
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
url?: string;
|
|
25
|
+
type?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface IProfileExtras {
|
|
28
|
+
roles?: IProfileRole[];
|
|
29
|
+
actions?: IProfileAction[];
|
|
30
|
+
sections?: IProfileSectionData[];
|
|
31
|
+
completionPercentage?: number;
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}
|
|
34
|
+
export interface IProfileRole {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
description?: string | null;
|
|
38
|
+
}
|
|
39
|
+
export interface IProfileAction {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
code: string;
|
|
43
|
+
description?: string | null;
|
|
44
|
+
}
|
|
45
|
+
export interface IEnrichedUser extends IUser {
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}
|
|
48
|
+
export interface IUserEnricher {
|
|
49
|
+
enrichListQuery?(query: SelectQueryBuilder<User>, user: ILoggedUserInfo | null): Promise<{
|
|
50
|
+
extraFields: string[];
|
|
51
|
+
}>;
|
|
52
|
+
enrichListItems?(users: IUser[], user: ILoggedUserInfo | null): Promise<IEnrichedUser[]>;
|
|
53
|
+
getProfileExtras?(userId: string, user: ILoggedUserInfo): Promise<IProfileExtras>;
|
|
54
|
+
updateProfileExtras?(userId: string, extras: Record<string, any>, queryRunner: QueryRunner): Promise<void>;
|
|
55
|
+
validateProfileExtras?(userId: string, extras: Record<string, any>, user: ILoggedUserInfo): Promise<void>;
|
|
56
|
+
getProfileSections?(): IProfileSection[];
|
|
57
|
+
getProfileSectionData?(userId: string, sectionId: string, user: ILoggedUserInfo): Promise<IProfileSectionData>;
|
|
58
|
+
updateProfileSection?(userId: string, sectionId: string, data: Record<string, any>, queryRunner: QueryRunner): Promise<void>;
|
|
59
|
+
handleSectionFileUpload?(userId: string, sectionId: string, field: string, fileInfo: {
|
|
60
|
+
name: string;
|
|
61
|
+
url: string;
|
|
62
|
+
size: number;
|
|
63
|
+
type: string;
|
|
64
|
+
}, queryRunner: QueryRunner): Promise<IProfileFile>;
|
|
65
|
+
handleSectionFileDelete?(userId: string, sectionId: string, field: string, fileId: string, queryRunner: QueryRunner): Promise<void>;
|
|
66
|
+
calculateProfileCompletion?(userId: string, user: ILoggedUserInfo): Promise<number>;
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flusys/nestjs-auth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0-beta",
|
|
4
4
|
"description": "Authentication and authorization infrastructure for NestJS applications",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "fesm/index.js",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"typeorm": "^0.3.0"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"@flusys/nestjs-core": "
|
|
95
|
-
"@flusys/nestjs-shared": "
|
|
94
|
+
"@flusys/nestjs-core": "1.1.0-beta",
|
|
95
|
+
"@flusys/nestjs-shared": "1.1.0-beta"
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -12,6 +12,7 @@ export declare class AuthConfigService {
|
|
|
12
12
|
getRefreshTokenSecret(): string;
|
|
13
13
|
getRefreshTokenExpiration(): string;
|
|
14
14
|
getRefreshTokenCookieName(): string;
|
|
15
|
+
getFrontendUrl(): string | undefined;
|
|
15
16
|
getDefaultDatabaseConfig(): IDatabaseConfig | undefined;
|
|
16
17
|
getTenantDefaultDatabaseConfig(): IDatabaseConfig | undefined;
|
|
17
18
|
getTenants(): ITenantDatabaseConfig[];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
2
|
+
import { PendingRegistration } from '../entities/pending-registration.entity';
|
|
3
|
+
import { IAuthEmailProvider } from '../interfaces';
|
|
4
|
+
export declare class AuthEmailService {
|
|
5
|
+
private readonly dataSourceProvider?;
|
|
6
|
+
private readonly emailProvider?;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
private readonly PASSWORD_RESET_EXPIRY;
|
|
9
|
+
private readonly EMAIL_VERIFICATION_EXPIRY;
|
|
10
|
+
constructor(dataSourceProvider?: AuthDataSourceProvider, emailProvider?: IAuthEmailProvider);
|
|
11
|
+
private getUserRepository;
|
|
12
|
+
private getUserTokenRepository;
|
|
13
|
+
private getPendingRegistrationRepository;
|
|
14
|
+
isEmailEnabled(): boolean;
|
|
15
|
+
private generateToken;
|
|
16
|
+
createPendingRegistration(data: {
|
|
17
|
+
email: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
phone?: string;
|
|
20
|
+
password: string;
|
|
21
|
+
companyData?: PendingRegistration['companyData'];
|
|
22
|
+
verifyUrlBase: string;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
success: boolean;
|
|
25
|
+
message: string;
|
|
26
|
+
}>;
|
|
27
|
+
forgotPassword(email: string, resetUrlBase: string): Promise<{
|
|
28
|
+
success: boolean;
|
|
29
|
+
message: string;
|
|
30
|
+
}>;
|
|
31
|
+
resetPassword(token: string, newPassword: string): Promise<{
|
|
32
|
+
success: boolean;
|
|
33
|
+
message: string;
|
|
34
|
+
}>;
|
|
35
|
+
verifyEmail(token: string): Promise<{
|
|
36
|
+
type: 'pending';
|
|
37
|
+
pending: PendingRegistration;
|
|
38
|
+
} | {
|
|
39
|
+
type: 'verified';
|
|
40
|
+
message: string;
|
|
41
|
+
}>;
|
|
42
|
+
resendVerificationEmail(email: string, verifyUrlBase: string): Promise<{
|
|
43
|
+
success: boolean;
|
|
44
|
+
message: string;
|
|
45
|
+
}>;
|
|
46
|
+
cleanupExpired(): Promise<{
|
|
47
|
+
deletedTokens: number;
|
|
48
|
+
deletedPending: number;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
@@ -3,31 +3,43 @@ import { Repository } from 'typeorm';
|
|
|
3
3
|
import { AuthConfigService } from './auth-config.service';
|
|
4
4
|
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
5
5
|
import { RegistrationDto } from '../dtos/authentication.dto';
|
|
6
|
-
import {
|
|
6
|
+
import { HybridCache } from '@flusys/nestjs-shared/classes';
|
|
7
|
+
import { LoginResponse, LoginResponseRequiresEmailVerification, LoginResponseRequiresSelection, MeResponse, RegistrationResponse } from '../interfaces/authentication.interface';
|
|
8
|
+
import { AuthEmailService } from './auth-email.service';
|
|
7
9
|
import { CompanyBranch } from '../entities/company-branch.entity';
|
|
8
10
|
import { Company } from '../entities/company.entity';
|
|
11
|
+
import { PendingRegistration } from '../entities/pending-registration.entity';
|
|
9
12
|
import { UserCompanyPermission } from '../entities/user-company-permission.entity';
|
|
10
13
|
import { User } from '../entities/user.entity';
|
|
11
14
|
import { CompanySelectionSessionService } from './company-selection-session.service';
|
|
12
15
|
export declare class AuthenticationService {
|
|
13
16
|
private readonly jwtService;
|
|
14
17
|
private readonly authConfig;
|
|
18
|
+
private readonly cacheManager?;
|
|
15
19
|
private readonly dataSourceProvider?;
|
|
16
20
|
private readonly sessionService?;
|
|
21
|
+
private readonly authEmailService?;
|
|
17
22
|
private readonly injectedUserRepository?;
|
|
18
23
|
private readonly injectedPermissionRepository?;
|
|
19
24
|
private readonly injectedCompanyRepository?;
|
|
20
25
|
private readonly injectedBranchRepository?;
|
|
21
26
|
private readonly logger;
|
|
22
|
-
constructor(jwtService: JwtService, authConfig: AuthConfigService, dataSourceProvider?: AuthDataSourceProvider, sessionService?: CompanySelectionSessionService, injectedUserRepository?: Repository<User>, injectedPermissionRepository?: Repository<UserCompanyPermission>, injectedCompanyRepository?: Repository<Company>, injectedBranchRepository?: Repository<CompanyBranch>);
|
|
27
|
+
constructor(jwtService: JwtService, authConfig: AuthConfigService, cacheManager?: HybridCache, dataSourceProvider?: AuthDataSourceProvider, sessionService?: CompanySelectionSessionService, authEmailService?: AuthEmailService, injectedUserRepository?: Repository<User>, injectedPermissionRepository?: Repository<UserCompanyPermission>, injectedCompanyRepository?: Repository<Company>, injectedBranchRepository?: Repository<CompanyBranch>);
|
|
23
28
|
private getUserRepository;
|
|
24
29
|
private getPermissionRepository;
|
|
25
30
|
private getCompanyRepository;
|
|
26
31
|
private getBranchRepository;
|
|
27
|
-
login(email: string, password: string): Promise<LoginResponse | LoginResponseRequiresSelection>;
|
|
32
|
+
login(email: string, password: string): Promise<LoginResponse | LoginResponseRequiresSelection | LoginResponseRequiresEmailVerification>;
|
|
28
33
|
private handleCompanyBasedLogin;
|
|
29
|
-
register(dto: RegistrationDto): Promise<
|
|
34
|
+
register(dto: RegistrationDto, verifyUrlBase?: string): Promise<RegistrationResponse | {
|
|
35
|
+
requiresEmailVerification: true;
|
|
36
|
+
message: string;
|
|
37
|
+
}>;
|
|
38
|
+
private createUserDirectly;
|
|
39
|
+
createUserFromPendingRegistration(pending: PendingRegistration): Promise<RegistrationResponse>;
|
|
40
|
+
private handleCompanyRegistrationFromPending;
|
|
30
41
|
private handleCompanyRegistration;
|
|
42
|
+
private processCompanyRegistration;
|
|
31
43
|
private generateSlug;
|
|
32
44
|
select(sessionId: string, companyId: string, branchId: string): Promise<LoginResponse>;
|
|
33
45
|
switchCompany(userId: string, companyId: string, branchId: string): Promise<LoginResponse>;
|
|
@@ -36,7 +48,9 @@ export declare class AuthenticationService {
|
|
|
36
48
|
refreshToken: string;
|
|
37
49
|
}>;
|
|
38
50
|
changePassword(userId: string, currentPassword: string, newPassword: string): Promise<void>;
|
|
39
|
-
logout(
|
|
51
|
+
logout(userId: string): Promise<void>;
|
|
52
|
+
isTokenRevoked(userId: string, tokenIssuedAt?: number): Promise<boolean>;
|
|
53
|
+
private parseExpiryToMs;
|
|
40
54
|
getUserCompanies(userId: string): Promise<Company[]>;
|
|
41
55
|
getUserBranches(userId: string, companyId: string): Promise<CompanyBranch[]>;
|
|
42
56
|
getCompanyById(companyId: string): Promise<Company | null>;
|
|
@@ -47,4 +61,6 @@ export declare class AuthenticationService {
|
|
|
47
61
|
private generateLoginResponse;
|
|
48
62
|
private generateLoginResponseWithCompany;
|
|
49
63
|
private generateCompanySelectionResponse;
|
|
64
|
+
private generateRegistrationResponse;
|
|
65
|
+
private generateRegistrationResponseWithCompany;
|
|
50
66
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RequestScopedApiService, HybridCache } 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 { Logger } from '@nestjs/common';
|
|
5
4
|
import { EntityTarget, Repository, SelectQueryBuilder } from 'typeorm';
|
|
6
5
|
import { CreateCompanyBranchDto, UpdateCompanyBranchDto } from '../dtos/company-branch.dto';
|
|
7
6
|
import { ICompanyBranch } from '../interfaces/company-branch.interface';
|
|
@@ -13,20 +12,18 @@ export declare class BranchService extends RequestScopedApiService<CreateCompany
|
|
|
13
12
|
protected utilsService: UtilsService;
|
|
14
13
|
private readonly dataSourceProvider;
|
|
15
14
|
private readonly authConfig;
|
|
16
|
-
protected logger: Logger;
|
|
17
15
|
constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider, authConfig: AuthConfigService);
|
|
18
16
|
protected resolveEntity(): EntityTarget<CompanyBranch>;
|
|
19
17
|
protected getDataSourceProvider(): AuthDataSourceProvider;
|
|
20
|
-
convertSingleDtoToEntity(dto: CreateCompanyBranchDto | UpdateCompanyBranchDto, _user: ILoggedUserInfo): Promise<CompanyBranch>;
|
|
21
18
|
getSelectQuery(query: SelectQueryBuilder<CompanyBranch>, _user: ILoggedUserInfo | null, select?: string[]): Promise<{
|
|
22
19
|
query: SelectQueryBuilder<CompanyBranch>;
|
|
23
20
|
isRaw: boolean;
|
|
24
21
|
}>;
|
|
25
|
-
protected getGlobalSearchQuery(query: SelectQueryBuilder<CompanyBranch>, search: string
|
|
22
|
+
protected getGlobalSearchQuery(query: SelectQueryBuilder<CompanyBranch>, search: string): Promise<{
|
|
26
23
|
query: SelectQueryBuilder<CompanyBranch>;
|
|
27
24
|
isRaw: boolean;
|
|
28
25
|
}>;
|
|
29
|
-
protected getExtraManipulateQuery(query: SelectQueryBuilder<CompanyBranch>,
|
|
26
|
+
protected getExtraManipulateQuery(query: SelectQueryBuilder<CompanyBranch>, filterDto: any, user: ILoggedUserInfo | null): Promise<{
|
|
30
27
|
query: SelectQueryBuilder<CompanyBranch>;
|
|
31
28
|
isRaw: boolean;
|
|
32
29
|
}>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RequestScopedApiService, HybridCache } 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 { Logger } from '@nestjs/common';
|
|
5
4
|
import { EntityTarget, Repository, SelectQueryBuilder } from 'typeorm';
|
|
6
5
|
import { CreateCompanyDto, UpdateCompanyDto } from '../dtos/company.dto';
|
|
7
6
|
import { Company } from '../entities/company.entity';
|
|
@@ -11,16 +10,14 @@ export declare class CompanyService extends RequestScopedApiService<CreateCompan
|
|
|
11
10
|
protected cacheManager: HybridCache;
|
|
12
11
|
protected utilsService: UtilsService;
|
|
13
12
|
private readonly dataSourceProvider;
|
|
14
|
-
protected logger: Logger;
|
|
15
13
|
constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider);
|
|
16
14
|
protected resolveEntity(): EntityTarget<Company>;
|
|
17
15
|
protected getDataSourceProvider(): AuthDataSourceProvider;
|
|
18
|
-
convertSingleDtoToEntity(dto: CreateCompanyDto | UpdateCompanyDto, _user: ILoggedUserInfo): Promise<Company>;
|
|
19
16
|
getSelectQuery(query: SelectQueryBuilder<Company>, _user: ILoggedUserInfo | null, select?: string[]): Promise<{
|
|
20
17
|
query: SelectQueryBuilder<Company>;
|
|
21
18
|
isRaw: boolean;
|
|
22
19
|
}>;
|
|
23
|
-
protected getGlobalSearchQuery(query: SelectQueryBuilder<Company>, search: string
|
|
20
|
+
protected getGlobalSearchQuery(query: SelectQueryBuilder<Company>, search: string): Promise<{
|
|
24
21
|
query: SelectQueryBuilder<Company>;
|
|
25
22
|
isRaw: boolean;
|
|
26
23
|
}>;
|
package/services/index.d.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { RequestScopedApiService, HybridCache } 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 { Logger } from '@nestjs/common';
|
|
5
4
|
import { EntityTarget, Repository } from 'typeorm';
|
|
6
5
|
import { AuthConfigService } from './auth-config.service';
|
|
7
6
|
import { AuthDataSourceProvider } from './auth-datasource.provider';
|
|
8
7
|
import { CreateUserDto, UpdateUserDto } from '../dtos/user.dto';
|
|
9
8
|
import { IUser } from '../interfaces/user.interface';
|
|
9
|
+
import { IEnrichedUser, IProfileExtras, IProfileSection, IProfileSectionData, IUserEnricher } from '../interfaces/user-enricher.interface';
|
|
10
10
|
import { User } from '../entities/user.entity';
|
|
11
11
|
export declare class UserService extends RequestScopedApiService<CreateUserDto, UpdateUserDto, IUser, User, Repository<User>> {
|
|
12
12
|
protected cacheManager: HybridCache;
|
|
13
13
|
protected utilsService: UtilsService;
|
|
14
14
|
private readonly dataSourceProvider;
|
|
15
15
|
private readonly authConfig;
|
|
16
|
-
|
|
16
|
+
private readonly userEnricher?;
|
|
17
17
|
private permissionRepository?;
|
|
18
18
|
private dataSource?;
|
|
19
|
-
constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider, authConfig: AuthConfigService);
|
|
19
|
+
constructor(cacheManager: HybridCache, utilsService: UtilsService, dataSourceProvider: AuthDataSourceProvider, authConfig: AuthConfigService, userEnricher?: IUserEnricher);
|
|
20
20
|
protected resolveEntity(): EntityTarget<User>;
|
|
21
21
|
protected getDataSourceProvider(): AuthDataSourceProvider;
|
|
22
22
|
protected ensureRepositoryInitialized(): Promise<void>;
|
|
23
|
-
updateLastLogin(id: string): Promise<void>;
|
|
24
23
|
verifyEmail(id: string): Promise<void>;
|
|
25
24
|
verifyPhone(id: string): Promise<void>;
|
|
26
25
|
updateStatus(id: string, isActive: boolean, user?: ILoggedUserInfo | null): Promise<void>;
|
|
27
|
-
protected convertSingleDtoToEntity(dto: CreateUserDto | UpdateUserDto, user:
|
|
26
|
+
protected convertSingleDtoToEntity(dto: CreateUserDto | UpdateUserDto, user: ILoggedUserInfo | null): Promise<User>;
|
|
28
27
|
protected convertEntityToResponseDto(entity: User, isRaw: boolean): IUser;
|
|
28
|
+
protected convertEntityListToResponseListDto(entities: User[], isRaw: boolean): IUser[];
|
|
29
29
|
protected getGlobalSearchQuery(query: any, search: string, _user: any): Promise<{
|
|
30
30
|
query: any;
|
|
31
31
|
isRaw: boolean;
|
|
@@ -35,5 +35,16 @@ export declare class UserService extends RequestScopedApiService<CreateUserDto,
|
|
|
35
35
|
isRaw: boolean;
|
|
36
36
|
}>;
|
|
37
37
|
insert(dto: CreateUserDto, user: ILoggedUserInfo | null): Promise<IUser>;
|
|
38
|
-
|
|
38
|
+
getProfileWithExtras(userId: string, user: ILoggedUserInfo): Promise<{
|
|
39
|
+
user: IUser;
|
|
40
|
+
extras?: IProfileExtras;
|
|
41
|
+
}>;
|
|
42
|
+
getEnrichedList(users: IUser[], user: ILoggedUserInfo | null): Promise<IEnrichedUser[]>;
|
|
43
|
+
getProfileSections(): Promise<IProfileSection[]>;
|
|
44
|
+
getProfileSectionData(userId: string, sectionId: string, user: ILoggedUserInfo): Promise<IProfileSectionData | null>;
|
|
45
|
+
updateProfileSection(userId: string, sectionId: string, data: Record<string, any>, user: ILoggedUserInfo): Promise<void>;
|
|
46
|
+
getProfileCompletion(userId: string, user: ILoggedUserInfo): Promise<number>;
|
|
47
|
+
profile(dto: UpdateUserDto & {
|
|
48
|
+
extras?: Record<string, any>;
|
|
49
|
+
}, user: ILoggedUserInfo): Promise<string>;
|
|
39
50
|
}
|