@lenne.tech/nest-server 9.1.0 → 9.2.1

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.
Files changed (121) hide show
  1. package/dist/config.env.js +41 -2
  2. package/dist/config.env.js.map +1 -1
  3. package/dist/core/common/filters/http-exception-log.filter.d.ts +4 -0
  4. package/dist/core/common/filters/http-exception-log.filter.js +30 -0
  5. package/dist/core/common/filters/http-exception-log.filter.js.map +1 -0
  6. package/dist/core/common/interceptors/check-security.interceptor.d.ts +5 -0
  7. package/dist/core/common/interceptors/check-security.interceptor.js +46 -0
  8. package/dist/core/common/interceptors/check-security.interceptor.js.map +1 -0
  9. package/dist/core/common/interfaces/server-options.interface.d.ts +16 -6
  10. package/dist/core/common/models/core-model.model.d.ts +1 -0
  11. package/dist/core/common/models/core-model.model.js +3 -0
  12. package/dist/core/common/models/core-model.model.js.map +1 -1
  13. package/dist/core/common/plugins/complexity.plugin.d.ts +9 -0
  14. package/dist/core/common/plugins/complexity.plugin.js +47 -0
  15. package/dist/core/common/plugins/complexity.plugin.js.map +1 -0
  16. package/dist/core/common/plugins/mongoose-id.plugin.d.ts +1 -2
  17. package/dist/core/common/plugins/mongoose-id.plugin.js +7 -2
  18. package/dist/core/common/plugins/mongoose-id.plugin.js.map +1 -1
  19. package/dist/core/common/services/config.service.d.ts +4 -4
  20. package/dist/core/common/services/config.service.js.map +1 -1
  21. package/dist/core/common/services/module.service.js +2 -2
  22. package/dist/core/common/services/module.service.js.map +1 -1
  23. package/dist/core/modules/auth/core-auth.model.d.ts +4 -1
  24. package/dist/core/modules/auth/core-auth.model.js +12 -1
  25. package/dist/core/modules/auth/core-auth.model.js.map +1 -1
  26. package/dist/core/modules/auth/core-auth.module.d.ts +3 -1
  27. package/dist/core/modules/auth/core-auth.module.js +7 -2
  28. package/dist/core/modules/auth/core-auth.module.js.map +1 -1
  29. package/dist/core/modules/auth/core-auth.resolver.d.ts +22 -2
  30. package/dist/core/modules/auth/core-auth.resolver.js +77 -9
  31. package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
  32. package/dist/core/modules/auth/guards/auth.guard.d.ts +1 -1
  33. package/dist/core/modules/auth/guards/auth.guard.js +9 -4
  34. package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
  35. package/dist/core/modules/auth/guards/refresh-token.guard.d.ts +4 -0
  36. package/dist/core/modules/auth/guards/refresh-token.guard.js +18 -0
  37. package/dist/core/modules/auth/guards/refresh-token.guard.js.map +1 -0
  38. package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
  39. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.d.ts +1 -0
  40. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js +5 -0
  41. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js.map +1 -1
  42. package/dist/core/modules/auth/inputs/core-auth-sign-up.input.d.ts +1 -0
  43. package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js +5 -0
  44. package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js.map +1 -1
  45. package/dist/core/modules/auth/interfaces/core-auth-user.interface.d.ts +3 -0
  46. package/dist/core/modules/auth/interfaces/jwt-payload.interface.d.ts +1 -1
  47. package/dist/core/modules/auth/services/core-auth-user.service.d.ts +3 -0
  48. package/dist/core/modules/auth/services/core-auth-user.service.js.map +1 -1
  49. package/dist/core/modules/auth/services/core-auth.service.d.ts +23 -5
  50. package/dist/core/modules/auth/services/core-auth.service.js +121 -13
  51. package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
  52. package/dist/core/modules/auth/strategies/jwt-refresh.strategy.d.ts +12 -0
  53. package/dist/core/modules/auth/strategies/jwt-refresh.strategy.js +61 -0
  54. package/dist/core/modules/auth/strategies/jwt-refresh.strategy.js.map +1 -0
  55. package/dist/core/modules/auth/{jwt.strategy.d.ts → strategies/jwt.strategy.d.ts} +4 -3
  56. package/dist/core/modules/auth/{jwt.strategy.js → strategies/jwt.strategy.js} +12 -5
  57. package/dist/core/modules/auth/strategies/jwt.strategy.js.map +1 -0
  58. package/dist/core/modules/file/core-file.controller.d.ts +2 -2
  59. package/dist/core/modules/file/core-file.controller.js +2 -2
  60. package/dist/core/modules/file/core-file.controller.js.map +1 -1
  61. package/dist/core/modules/user/core-user.model.d.ts +2 -0
  62. package/dist/core/modules/user/core-user.model.js +12 -0
  63. package/dist/core/modules/user/core-user.model.js.map +1 -1
  64. package/dist/core.module.js +12 -2
  65. package/dist/core.module.js.map +1 -1
  66. package/dist/index.d.ts +6 -1
  67. package/dist/index.js +6 -1
  68. package/dist/index.js.map +1 -1
  69. package/dist/main.js +23 -0
  70. package/dist/main.js.map +1 -1
  71. package/dist/server/modules/auth/auth.model.js.map +1 -1
  72. package/dist/server/modules/auth/auth.resolver.d.ts +13 -5
  73. package/dist/server/modules/auth/auth.resolver.js +21 -12
  74. package/dist/server/modules/auth/auth.resolver.js.map +1 -1
  75. package/dist/server/modules/auth/auth.service.d.ts +2 -1
  76. package/dist/server/modules/auth/auth.service.js +7 -48
  77. package/dist/server/modules/auth/auth.service.js.map +1 -1
  78. package/dist/server/modules/file/file.module.js +3 -3
  79. package/dist/server/modules/file/file.module.js.map +1 -1
  80. package/dist/server/modules/user/user.model.d.ts +1 -0
  81. package/dist/server/modules/user/user.model.js +19 -0
  82. package/dist/server/modules/user/user.model.js.map +1 -1
  83. package/dist/server/server.module.js +12 -1
  84. package/dist/server/server.module.js.map +1 -1
  85. package/dist/tsconfig.build.tsbuildinfo +1 -1
  86. package/package.json +32 -27
  87. package/src/config.env.ts +41 -2
  88. package/src/core/common/filters/http-exception-log.filter.ts +27 -0
  89. package/src/core/common/interceptors/check-security.interceptor.ts +52 -0
  90. package/src/core/common/interfaces/server-options.interface.ts +67 -30
  91. package/src/core/common/models/core-model.model.ts +7 -0
  92. package/src/core/common/plugins/complexity.plugin.ts +31 -0
  93. package/src/core/common/plugins/mongoose-id.plugin.js +4 -2
  94. package/src/core/common/services/config.service.ts +4 -4
  95. package/src/core/common/services/module.service.ts +2 -2
  96. package/src/core/modules/auth/core-auth.model.ts +15 -2
  97. package/src/core/modules/auth/core-auth.module.ts +8 -2
  98. package/src/core/modules/auth/core-auth.resolver.ts +93 -10
  99. package/src/core/modules/auth/guards/auth.guard.ts +12 -5
  100. package/src/core/modules/auth/guards/refresh-token.guard.ts +5 -0
  101. package/src/core/modules/auth/guards/roles.guard.ts +1 -1
  102. package/src/core/modules/auth/inputs/core-auth-sign-in.input.ts +3 -0
  103. package/src/core/modules/auth/inputs/core-auth-sign-up.input.ts +3 -0
  104. package/src/core/modules/auth/interfaces/core-auth-user.interface.ts +15 -0
  105. package/src/core/modules/auth/interfaces/jwt-payload.interface.ts +1 -1
  106. package/src/core/modules/auth/services/core-auth-user.service.ts +15 -0
  107. package/src/core/modules/auth/services/core-auth.service.ts +216 -18
  108. package/src/core/modules/auth/strategies/jwt-refresh.strategy.ts +56 -0
  109. package/src/core/modules/auth/{jwt.strategy.ts → strategies/jwt.strategy.ts} +16 -5
  110. package/src/core/modules/file/core-file.controller.ts +2 -2
  111. package/src/core/modules/user/core-user.model.ts +17 -2
  112. package/src/core.module.ts +14 -2
  113. package/src/index.ts +6 -1
  114. package/src/main.ts +29 -0
  115. package/src/server/modules/auth/auth.model.ts +1 -1
  116. package/src/server/modules/auth/auth.resolver.ts +26 -8
  117. package/src/server/modules/auth/auth.service.ts +20 -61
  118. package/src/server/modules/file/file.module.ts +3 -3
  119. package/src/server/modules/user/user.model.ts +29 -0
  120. package/src/server/server.module.ts +12 -1
  121. package/dist/core/modules/auth/jwt.strategy.js.map +0 -1
@@ -8,6 +8,7 @@ import * as graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';
8
8
  import { merge } from './core/common/helpers/config.helper';
9
9
  import { IServerOptions } from './core/common/interfaces/server-options.interface';
10
10
  import { MapAndValidatePipe } from './core/common/pipes/map-and-validate.pipe';
11
+ import { ComplexityPlugin } from './core/common/plugins/complexity.plugin';
11
12
  import { ConfigService } from './core/common/services/config.service';
12
13
  import { EmailService } from './core/common/services/email.service';
13
14
  import { MailjetService } from './core/common/services/mailjet.service';
@@ -41,6 +42,13 @@ export class CoreModule implements NestModule {
41
42
  */
42
43
  static forRoot(AuthService: any, AuthModule: any, options: Partial<IServerOptions>): DynamicModule {
43
44
  // Process config
45
+ let cors = {};
46
+ if (options?.cookies) {
47
+ cors = {
48
+ credentials: true,
49
+ origin: true,
50
+ };
51
+ }
44
52
  const config: IServerOptions = merge(
45
53
  {
46
54
  env: 'develop',
@@ -52,7 +60,8 @@ export class CoreModule implements NestModule {
52
60
  Object.assign(
53
61
  {
54
62
  autoSchemaFile: 'schema.gql',
55
- context: ({ req }) => ({ req }),
63
+ context: ({ req, res }) => ({ req, res }),
64
+ cors,
56
65
  installSubscriptionHandlers: true,
57
66
  subscriptions: {
58
67
  'subscriptions-transport-ws': {
@@ -135,6 +144,9 @@ export class CoreModule implements NestModule {
135
144
  EmailService,
136
145
  TemplateService,
137
146
  MailjetService,
147
+
148
+ // Plugins
149
+ ComplexityPlugin,
138
150
  ];
139
151
 
140
152
  // Return dynamic module
@@ -147,7 +159,7 @@ export class CoreModule implements NestModule {
147
159
  ),
148
160
  ],
149
161
  providers,
150
- exports: [ConfigService, EmailService, TemplateService, MailjetService],
162
+ exports: [ConfigService, EmailService, TemplateService, MailjetService, ComplexityPlugin],
151
163
  };
152
164
  }
153
165
  }
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ export * from './core/common/enums/logical-operator.enum';
18
18
  export * from './core/common/enums/process-type.enum';
19
19
  export * from './core/common/enums/role.enum';
20
20
  export * from './core/common/enums/sort-order.emum';
21
+ export * from './core/common/filters/http-exception-log.filter';
21
22
  export * from './core/common/helpers/common.helper';
22
23
  export * from './core/common/helpers/config.helper';
23
24
  export * from './core/common/helpers/context.helper';
@@ -34,6 +35,7 @@ export * from './core/common/inputs/filter.input';
34
35
  export * from './core/common/inputs/single-filter.input';
35
36
  export * from './core/common/inputs/sort.input';
36
37
  export * from './core/common/interceptors/check-response.interceptor';
38
+ export * from './core/common/interceptors/check-security.interceptor';
37
39
  export * from './core/common/interfaces/core-persistence-model.interface';
38
40
  export * from './core/common/interfaces/cron-job-config.interface';
39
41
  export * from './core/common/interfaces/mailjet-options.interface';
@@ -46,6 +48,8 @@ export * from './core/common/models/core-model.model';
46
48
  export * from './core/common/models/core-persistence.model';
47
49
  export * from './core/common/pipes/check-input.pipe';
48
50
  export * from './core/common/pipes/map-and-validate.pipe';
51
+ export * from './core/common/plugins/complexity.plugin';
52
+ export * from './core/common/plugins/mongoose-id.plugin';
49
53
  export * from './core/common/scalars/any.scalar';
50
54
  export * from './core/common/scalars/date.scalar';
51
55
  export * from './core/common/scalars/json.scalar';
@@ -83,7 +87,8 @@ export * from './core/modules/auth/services/core-auth-user.service';
83
87
  export * from './core/modules/auth/core-auth.model';
84
88
  export * from './core/modules/auth/core-auth.module';
85
89
  export * from './core/modules/auth/core-auth.resolver';
86
- export * from './core/modules/auth/jwt.strategy';
90
+ export * from './core/modules/auth/strategies/jwt.strategy';
91
+ export * from './core/modules/auth/strategies/jwt-refresh.strategy';
87
92
 
88
93
  // =====================================================================================================================
89
94
  // Core - Modules - File
package/src/main.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { NestFactory } from '@nestjs/core';
2
2
  import { NestExpressApplication } from '@nestjs/platform-express';
3
3
  import { exec } from 'child_process';
4
+ import * as compression from 'compression';
5
+ import * as cookieParser from 'cookie-parser';
4
6
  import envConfig from './config.env';
7
+ import { HttpExceptionLogFilter } from './core/common/filters/http-exception-log.filter';
5
8
  import { ServerModule } from './server/server.module';
6
9
 
7
10
  /**
@@ -14,6 +17,32 @@ async function bootstrap() {
14
17
  ServerModule
15
18
  );
16
19
 
20
+ // Log exceptions
21
+ if (envConfig.logExceptions) {
22
+ server.useGlobalFilters(new HttpExceptionLogFilter());
23
+ }
24
+
25
+ // Compression (gzip)
26
+ if (envConfig.compression) {
27
+ let envCompressionOptions = {};
28
+ if (typeof envConfig.compression === 'object') {
29
+ envCompressionOptions = envConfig.compression;
30
+ }
31
+ const compressionOptions = {
32
+ filter: () => {
33
+ return true;
34
+ },
35
+ threshold: 0,
36
+ ...envCompressionOptions,
37
+ };
38
+ server.use(compression(compressionOptions));
39
+ }
40
+
41
+ // Cookie handling
42
+ if (envConfig.cookies) {
43
+ server.use(cookieParser());
44
+ }
45
+
17
46
  // Asset directory
18
47
  server.useStaticAssets(envConfig.staticAssets.path, envConfig.staticAssets.options);
19
48
 
@@ -16,7 +16,7 @@ export class Auth extends CoreAuthModel {
16
16
  * Signed-in user
17
17
  */
18
18
  @Field(() => User, { description: 'User who signed in' })
19
- user: User = undefined;
19
+ override user: User = undefined;
20
20
 
21
21
  // ===================================================================================================================
22
22
  // Methods
@@ -1,5 +1,8 @@
1
- import { Args, Info, Mutation, Query, Resolver } from '@nestjs/graphql';
1
+ import { Args, Context, Info, Mutation, Resolver } from '@nestjs/graphql';
2
+ import { Response as ResponseType } from 'express';
2
3
  import { GraphQLResolveInfo } from 'graphql';
4
+ import { ConfigService } from '../../../core/common/services/config.service';
5
+ import { CoreAuthResolver } from '../../../core/modules/auth/core-auth.resolver';
3
6
  import { Auth } from './auth.model';
4
7
  import { AuthService } from './auth.service';
5
8
  import { AuthSignInInput } from './inputs/auth-sign-in.input';
@@ -9,21 +12,31 @@ import { AuthSignUpInput } from './inputs/auth-sign-up.input';
9
12
  * Authentication resolver for the sign in
10
13
  */
11
14
  @Resolver(() => Auth)
12
- export class AuthResolver {
15
+ export class AuthResolver extends CoreAuthResolver {
13
16
  /**
14
17
  * Integrate services
15
18
  */
16
- constructor(private readonly authService: AuthService) {}
19
+ constructor(
20
+ protected override readonly authService: AuthService,
21
+ protected override readonly configService: ConfigService
22
+ ) {
23
+ super(authService, configService);
24
+ }
17
25
 
18
26
  /**
19
27
  * SignIn for User
20
28
  */
21
- @Query(() => Auth, { description: 'Sign in and get JWT token' })
22
- async signIn(@Info() info: GraphQLResolveInfo, @Args('input') input: AuthSignInInput): Promise<Auth> {
23
- return this.authService.signIn(input, {
29
+ @Mutation(() => Auth, { description: 'Sign in and get JWT token' })
30
+ override async signIn(
31
+ @Info() info: GraphQLResolveInfo,
32
+ @Context() ctx: { res: ResponseType },
33
+ @Args('input') input: AuthSignInInput
34
+ ): Promise<Auth> {
35
+ const result = await this.authService.signIn(input, {
24
36
  fieldSelection: { info, select: 'signIn' },
25
37
  inputType: AuthSignInInput,
26
38
  });
39
+ return this.processCookies(ctx, result);
27
40
  }
28
41
 
29
42
  /**
@@ -32,9 +45,14 @@ export class AuthResolver {
32
45
  @Mutation(() => Auth, {
33
46
  description: 'Sign up user and get JWT token',
34
47
  })
35
- async signUp(@Info() info: GraphQLResolveInfo, @Args('input') input: AuthSignUpInput): Promise<Auth> {
36
- return this.authService.signUp(input, {
48
+ override async signUp(
49
+ @Info() info: GraphQLResolveInfo,
50
+ @Context() ctx: { res: ResponseType },
51
+ @Args('input') input: AuthSignUpInput
52
+ ): Promise<Auth> {
53
+ const result = await this.authService.signUp(input, {
37
54
  fieldSelection: { info, select: 'signUp' },
38
55
  });
56
+ return this.processCookies(ctx, result);
39
57
  }
40
58
  }
@@ -1,79 +1,42 @@
1
- import { Injectable, UnauthorizedException } from '@nestjs/common';
1
+ import { Injectable } from '@nestjs/common';
2
2
  import { JwtService } from '@nestjs/jwt';
3
- import * as bcrypt from 'bcrypt';
4
- import { sha256 } from 'js-sha256';
5
- import { Roles } from '../../../core/common/decorators/roles.decorator';
6
- import { RoleEnum } from '../../../core/common/enums/role.enum';
7
- import { prepareServiceOptions } from '../../../core/common/helpers/service.helper';
8
3
  import { ServiceOptions } from '../../../core/common/interfaces/service-options.interface';
9
4
  import { ConfigService } from '../../../core/common/services/config.service';
10
5
  import { EmailService } from '../../../core/common/services/email.service';
11
- import { JwtPayload } from '../../../core/modules/auth/interfaces/jwt-payload.interface';
6
+ import { CoreAuthService } from '../../../core/modules/auth/services/core-auth.service';
12
7
  import { UserService } from '../user/user.service';
13
8
  import { Auth } from './auth.model';
14
9
  import { AuthSignInInput } from './inputs/auth-sign-in.input';
15
10
  import { AuthSignUpInput } from './inputs/auth-sign-up.input';
16
11
 
17
12
  @Injectable()
18
- @Roles(RoleEnum.ADMIN)
19
- export class AuthService {
13
+ export class AuthService extends CoreAuthService {
20
14
  constructor(
21
- protected readonly jwtService: JwtService,
15
+ protected override readonly jwtService: JwtService,
22
16
  protected readonly emailService: EmailService,
23
- protected readonly userService: UserService,
24
- protected readonly configService: ConfigService
25
- ) {}
17
+ protected override readonly userService: UserService,
18
+ protected override readonly configService: ConfigService
19
+ ) {
20
+ super(userService, jwtService, configService);
21
+ }
26
22
 
27
23
  /**
28
24
  * Sign in for user
25
+ *
26
+ * Overwrites the parent method for mapping
29
27
  */
30
- @Roles(RoleEnum.S_EVERYONE)
31
- async signIn(input: AuthSignInInput, serviceOptions?: ServiceOptions): Promise<Auth> {
32
- // Prepare service options
33
- const serviceOptionsForUserService = prepareServiceOptions(serviceOptions, {
34
- // We need password, so we can't use prepare output handling and have to deactivate it
35
- prepareOutput: null,
36
-
37
- // Select user field for automatic populate handling via user service
38
- subFieldSelection: 'user',
39
- });
40
-
41
- // Get and check user
42
- const user = await this.userService.getViaEmail(input.email, serviceOptionsForUserService);
43
- if (
44
- !user ||
45
- !(
46
- (await bcrypt.compare(input.password, user.password)) ||
47
- (await bcrypt.compare(sha256(input.password), user.password))
48
- )
49
- ) {
50
- throw new UnauthorizedException();
51
- }
52
-
53
- // Create JWT and return sign-in data
54
- const payload: JwtPayload = { email: user.email };
55
- return Auth.map({
56
- token: this.jwtService.sign(payload),
57
- user,
58
- });
28
+ override async signIn(input: AuthSignInInput, serviceOptions?: ServiceOptions): Promise<Auth> {
29
+ return Auth.map(await super.signIn(input, serviceOptions));
59
30
  }
60
31
 
61
32
  /**
62
33
  * Register a new user Account
34
+ *
35
+ * Overwrites the parent method for integrating email sending and mapping
63
36
  */
64
- @Roles(RoleEnum.S_EVERYONE)
65
- async signUp(input: AuthSignUpInput, serviceOptions?: ServiceOptions): Promise<Auth> {
66
- // Prepare service options
67
- const serviceOptionsForUserService = prepareServiceOptions(serviceOptions, {
68
- // Select user field for automatic populate handling via user service
69
- subFieldSelection: 'user',
70
- });
71
-
72
- // Get and check user
73
- const user = await this.userService.create(input, serviceOptionsForUserService);
74
- if (!user) {
75
- throw Error('Email Address already in use');
76
- }
37
+ override async signUp(input: AuthSignUpInput, serviceOptions?: ServiceOptions): Promise<Auth> {
38
+ const result = await super.signUp(input, serviceOptions);
39
+ const { user } = result;
77
40
 
78
41
  // Send email
79
42
  await this.emailService.sendMail(user.email, 'Welcome', {
@@ -84,11 +47,7 @@ export class AuthService {
84
47
  },
85
48
  });
86
49
 
87
- // Create JWT and return sign-in data
88
- const payload: JwtPayload = { email: user.email };
89
- return Auth.map({
90
- token: this.jwtService.sign(payload),
91
- user: user,
92
- });
50
+ // Return mapped result
51
+ return Auth.map(result);
93
52
  }
94
53
  }
@@ -1,10 +1,10 @@
1
1
  import { forwardRef, Module } from '@nestjs/common';
2
+ import { MulterModule } from '@nestjs/platform-express';
3
+ import { UserModule } from '../user/user.module';
4
+ import { FileController } from './file.controller';
2
5
  import { FileResolver } from './file.resolver';
3
6
  import { FileService } from './file.service';
4
- import { FileController } from './file.controller';
5
7
  import { GridFsMulterConfigService } from './multer-config.service';
6
- import { MulterModule } from '@nestjs/platform-express';
7
- import { UserModule } from '../user/user.module';
8
8
 
9
9
  /**
10
10
  * File module
@@ -1,6 +1,7 @@
1
1
  import { Field, ObjectType } from '@nestjs/graphql';
2
2
  import { Prop, Schema as MongooseSchema, SchemaFactory } from '@nestjs/mongoose';
3
3
  import { Document, Schema } from 'mongoose';
4
+ import { RoleEnum } from '../../../core/common/enums/role.enum';
4
5
  import { CoreUserModel } from '../../../core/modules/user/core-user.model';
5
6
  import { PersistenceModel } from '../../common/models/persistence.model';
6
7
 
@@ -69,6 +70,34 @@ export class User extends CoreUserModel implements PersistenceModel {
69
70
  // If something comes up, you can use `mapClasses` / `mapClassesAsync` from ModelHelper.
70
71
  return this;
71
72
  }
73
+
74
+ /**
75
+ * Verification of the user's rights to access the properties of this object
76
+ */
77
+ override securityCheck(user: User, force?: boolean) {
78
+ if (force || (user && (user.id === this.id || user.hasRole(RoleEnum.ADMIN)))) {
79
+ return this;
80
+ }
81
+
82
+ // Remove (values of) properties
83
+ if (!user || user.id !== this.id) {
84
+ this.roles = [];
85
+ this.username = null;
86
+ this.verified = null;
87
+ this.verifiedAt = null;
88
+
89
+ // PersistenceModel and CorePersistenceModel
90
+ this.createdAt = null;
91
+ this.createdBy = null;
92
+ this.labels = null;
93
+ this.tags = null;
94
+ this.updatedAt = null;
95
+ this.updatedBy = null;
96
+ }
97
+
98
+ // Return prepared user
99
+ return this;
100
+ }
72
101
  }
73
102
 
74
103
  export const UserSchema = SchemaFactory.createForClass(User);
@@ -1,7 +1,9 @@
1
1
  import { Module } from '@nestjs/common';
2
+ import { APP_INTERCEPTOR } from '@nestjs/core';
2
3
  import { ScheduleModule } from '@nestjs/schedule';
3
4
  import envConfig from '../config.env';
4
5
  import { CoreModule } from '../core.module';
6
+ import { CheckSecurityInterceptor } from '../core/common/interceptors/check-security.interceptor';
5
7
  import { Any } from '../core/common/scalars/any.scalar';
6
8
  import { DateScalar } from '../core/common/scalars/date.scalar';
7
9
  import { JSON } from '../core/common/scalars/json.scalar';
@@ -34,7 +36,16 @@ import { ServerController } from './server.controller';
34
36
  FileModule,
35
37
  ],
36
38
 
37
- providers: [Any, CronJobs, DateScalar, JSON],
39
+ providers: [
40
+ Any,
41
+ CronJobs,
42
+ DateScalar,
43
+ JSON,
44
+ {
45
+ provide: APP_INTERCEPTOR,
46
+ useClass: CheckSecurityInterceptor,
47
+ },
48
+ ],
38
49
 
39
50
  // Include REST controllers
40
51
  controllers: [ServerController],
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.strategy.js","sourceRoot":"","sources":["../../../../src/core/modules/auth/jwt.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAmE;AACnE,+CAAoD;AACpD,+CAAoD;AACpD,yEAAqE;AAErE,oEAA+D;AAMxD,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IAIzD,YAA+B,WAA4B,EAAqB,aAA4B;QAC1G,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,UAAU,EAAE,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC;YAC/C,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC;YAC7C,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,wBAAwB,CAAC;YACtF,WAAW,EAAE,aAAa,CAAC,GAAG,CAAC,wBAAwB,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC;YAC3F,mBAAmB,EAAE,aAAa,CAAC,GAAG,CAAC,yBAAyB,CAAC;SAClE,CAAC,CAAC;QAR0B,gBAAW,GAAX,WAAW,CAAiB;QAAqB,kBAAa,GAAb,aAAa,CAAe;IAS5G,CAAC;IAKD,KAAK,CAAC,QAAQ,CAAC,OAAmB;QAChC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,EAAE;YACT,MAAM,IAAI,8BAAqB,EAAE,CAAC;SACnC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzBY,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAKiC,mCAAe,EAAoC,8BAAa;GAJjG,WAAW,CAyBvB;AAzBY,kCAAW"}