@lenne.tech/nest-server 10.2.11 → 10.3.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.
Files changed (52) hide show
  1. package/dist/config.env.js +15 -0
  2. package/dist/config.env.js.map +1 -1
  3. package/dist/core/common/decorators/restricted.decorator.d.ts +1 -0
  4. package/dist/core/common/decorators/restricted.decorator.js +8 -4
  5. package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
  6. package/dist/core/common/helpers/context.helper.d.ts +1 -0
  7. package/dist/core/common/interfaces/server-options.interface.d.ts +5 -0
  8. package/dist/core/common/services/crud.service.d.ts +3 -3
  9. package/dist/core/common/services/mailjet.service.js +2 -2
  10. package/dist/core/common/services/mailjet.service.js.map +1 -1
  11. package/dist/core/common/services/module.service.d.ts +3 -3
  12. package/dist/core/common/types/require-only-one.type.d.ts +3 -3
  13. package/dist/core/common/types/required-at-least-one.type.d.ts +3 -3
  14. package/dist/core/modules/auth/core-auth.module.d.ts +2 -2
  15. package/dist/core/modules/auth/core-auth.module.js.map +1 -1
  16. package/dist/core/modules/auth/guards/auth.guard.d.ts +2 -2
  17. package/dist/core/modules/auth/services/core-auth.service.d.ts +2 -2
  18. package/dist/core/modules/auth/strategies/jwt-refresh.strategy.d.ts +1 -0
  19. package/dist/core/modules/file/core-file.service.d.ts +2 -2
  20. package/dist/core/modules/user/core-user.service.d.ts +2 -2
  21. package/dist/core.module.js +20 -4
  22. package/dist/core.module.js.map +1 -1
  23. package/dist/index.d.ts +11 -11
  24. package/dist/index.js +11 -11
  25. package/dist/index.js.map +1 -1
  26. package/dist/server/modules/user/user.model.d.ts +1 -1
  27. package/dist/server/server.controller.d.ts +1 -3
  28. package/dist/server/server.controller.js +1 -1
  29. package/dist/server/server.controller.js.map +1 -1
  30. package/dist/server/server.module.js +1 -12
  31. package/dist/server/server.module.js.map +1 -1
  32. package/dist/tsconfig.build.tsbuildinfo +1 -1
  33. package/package.json +48 -47
  34. package/src/config.env.ts +15 -0
  35. package/src/core/common/decorators/restricted.decorator.ts +11 -3
  36. package/src/core/common/interfaces/server-options.interface.ts +26 -0
  37. package/src/core/common/services/crud.service.ts +2 -2
  38. package/src/core/common/services/mailjet.service.ts +2 -1
  39. package/src/core/common/services/module.service.ts +3 -3
  40. package/src/core/common/types/require-only-one.type.ts +4 -2
  41. package/src/core/common/types/required-at-least-one.type.ts +4 -2
  42. package/src/core/modules/auth/core-auth.module.ts +2 -2
  43. package/src/core/modules/auth/guards/auth.guard.ts +2 -2
  44. package/src/core/modules/auth/services/core-auth.service.ts +1 -1
  45. package/src/core/modules/file/core-file.service.ts +1 -1
  46. package/src/core/modules/user/core-user.service.ts +1 -1
  47. package/src/core.module.ts +27 -7
  48. package/src/index.ts +15 -15
  49. package/src/server/modules/user/user.model.ts +1 -1
  50. package/src/server/server.controller.ts +1 -1
  51. package/src/server/server.module.ts +1 -12
  52. package/src/test/test.helper.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "10.2.11",
3
+ "version": "10.3.0",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
@@ -24,7 +24,8 @@
24
24
  "format:staged": "pretty-quick --staged",
25
25
  "lint": "eslint \"{src,tests}/**/*.ts\" --fix",
26
26
  "prestart:prod": "npm run build",
27
- "reinit": "rimraf package-lock.json && rimraf node_modules && npm cache clean --force && npm i && npm run test:e2e && npm run build",
27
+ "reinit": "rimraf package-lock.json && rimraf node_modules && npm i && npm run lint && npm run test:e2e && npm run test:ci && npm run build",
28
+ "reinit:clean": "rimraf package-lock.json && rimraf node_modules && npm cache clean --force && npm i && npm run test:e2e && npm run build",
28
29
  "reinit:force": "rimraf package-lock.json && rimraf node_modules && npm cache clean --force && npm i --force && npm run test:e2e",
29
30
  "reinit:legacy": "rimraf package-lock.json && rimraf node_modules && npm cache clean --force && npm i --legacy-peer-deps && npm run test:e2e",
30
31
  "start": "npm run start:local",
@@ -59,23 +60,23 @@
59
60
  "url": "https://github.com/lenneTech/nest-server/issues"
60
61
  },
61
62
  "engines": {
62
- "node": ">= 16.13.0"
63
+ "node": ">= 20"
63
64
  },
64
65
  "dependencies": {
65
- "@apollo/gateway": "2.6.3",
66
+ "@apollo/gateway": "2.8.4",
66
67
  "@getbrevo/brevo": "1.0.1",
67
68
  "@lenne.tech/mongoose-gridfs": "1.4.2",
68
69
  "@lenne.tech/multer-gridfs-storage": "5.0.6",
69
- "@nestjs/apollo": "12.0.11",
70
- "@nestjs/common": "10.3.0",
71
- "@nestjs/core": "10.3.0",
72
- "@nestjs/graphql": "12.0.11",
70
+ "@nestjs/apollo": "12.2.0",
71
+ "@nestjs/common": "10.4.0",
72
+ "@nestjs/core": "10.4.0",
73
+ "@nestjs/graphql": "12.2.0",
73
74
  "@nestjs/jwt": "10.2.0",
74
- "@nestjs/mongoose": "10.0.2",
75
+ "@nestjs/mongoose": "10.0.10",
75
76
  "@nestjs/passport": "10.0.3",
76
- "@nestjs/platform-express": "10.3.0",
77
- "@nestjs/schedule": "4.0.0",
78
- "@nestjs/terminus": "10.2.0",
77
+ "@nestjs/platform-express": "10.4.0",
78
+ "@nestjs/schedule": "4.1.0",
79
+ "@nestjs/terminus": "10.2.3",
79
80
  "apollo-server-core": "3.13.0",
80
81
  "apollo-server-express": "3.13.0",
81
82
  "bcrypt": "5.1.1",
@@ -83,72 +84,72 @@
83
84
  "class-validator": "0.14.1",
84
85
  "compression": "1.7.4",
85
86
  "cookie-parser": "1.4.6",
86
- "ejs": "3.1.9",
87
- "graphql": "16.8.1",
88
- "graphql-query-complexity": "0.12.0",
87
+ "ejs": "3.1.10",
88
+ "graphql": "16.9.0",
89
+ "graphql-query-complexity": "1.0.0",
89
90
  "graphql-subscriptions": "2.0.0",
90
91
  "graphql-upload": "15.0.2",
91
- "js-sha256": "0.10.1",
92
+ "js-sha256": "0.11.0",
92
93
  "json-to-graphql-query": "2.2.5",
93
- "light-my-request": "5.11.0",
94
+ "light-my-request": "5.13.0",
94
95
  "lodash": "4.17.21",
95
- "mongodb": "6.3.0",
96
- "mongoose": "7.6.8",
96
+ "mongodb": "6.8.0",
97
+ "mongoose": "7.8.0",
97
98
  "multer": "1.4.5-lts.1",
98
99
  "node-mailjet": "6.0.5",
99
- "nodemailer": "6.9.8",
100
- "nodemon": "3.0.3",
100
+ "nodemailer": "6.9.14",
101
+ "nodemon": "3.1.4",
101
102
  "passport": "0.7.0",
102
103
  "passport-jwt": "4.0.1",
103
- "reflect-metadata": "0.1.14",
104
- "rfdc": "1.3.0",
105
- "rimraf": "5.0.5",
104
+ "reflect-metadata": "0.2.2",
105
+ "rfdc": "1.4.1",
106
+ "rimraf": "6.0.1",
106
107
  "rxjs": "7.8.1",
107
108
  "yuml-diagram": "1.2.0"
108
109
  },
109
110
  "devDependencies": {
110
111
  "@babel/plugin-proposal-private-methods": "7.18.6",
111
- "@compodoc/compodoc": "1.1.23",
112
+ "@compodoc/compodoc": "1.1.25",
112
113
  "@lenne.tech/eslint-config-ts": "0.0.16",
113
- "@nestjs/cli": "10.3.0",
114
- "@nestjs/schematics": "10.1.0",
115
- "@nestjs/testing": "10.3.0",
116
- "@swc/cli": "0.1.63",
117
- "@swc/core": "1.3.104",
118
- "@swc/jest": "0.2.29",
114
+ "@nestjs/cli": "10.4.4",
115
+ "@nestjs/schematics": "10.1.3",
116
+ "@nestjs/testing": "10.4.0",
117
+ "@swc/cli": "0.4.0",
118
+ "@swc/core": "1.7.10",
119
+ "@swc/jest": "0.2.36",
119
120
  "@types/compression": "1.7.5",
120
- "@types/cookie-parser": "1.4.6",
121
+ "@types/cookie-parser": "1.4.7",
121
122
  "@types/ejs": "3.1.5",
122
123
  "@types/express": "4.17.21",
123
- "@types/jest": "29.5.11",
124
- "@types/lodash": "4.14.202",
124
+ "@types/jest": "29.5.12",
125
+ "@types/lodash": "4.17.7",
125
126
  "@types/multer": "1.4.11",
126
- "@types/node": "20.11.5",
127
- "@types/nodemailer": "6.4.14",
127
+ "@types/node": "22.2.0",
128
+ "@types/nodemailer": "6.4.15",
128
129
  "@types/passport": "1.0.16",
129
130
  "@types/supertest": "6.0.2",
130
- "@typescript-eslint/eslint-plugin": "6.19.0",
131
- "@typescript-eslint/parser": "6.19.0",
131
+ "@typescript-eslint/eslint-plugin": "6.21.0",
132
+ "@typescript-eslint/parser": "6.21.0",
132
133
  "coffeescript": "2.7.0",
133
- "eslint": "8.56.0",
134
+ "eslint": "8.57.0",
134
135
  "eslint-config-prettier": "9.1.0",
135
- "eslint-plugin-unused-imports": "3.0.0",
136
+ "eslint-plugin-unused-imports": "3.2.0",
136
137
  "find-file-up": "2.0.1",
137
138
  "grunt": "1.6.1",
138
139
  "grunt-bg-shell": "2.3.3",
139
140
  "grunt-contrib-clean": "2.0.1",
140
141
  "grunt-contrib-watch": "1.1.0",
141
142
  "grunt-sync": "0.8.2",
142
- "husky": "8.0.3",
143
+ "husky": "9.1.4",
143
144
  "jest": "29.7.0",
144
- "npm-watch": "0.11.0",
145
- "pm2": "5.3.0",
146
- "prettier": "3.2.4",
145
+ "npm-watch": "0.13.0",
146
+ "pm2": "5.4.2",
147
+ "prettier": "3.3.3",
147
148
  "pretty-quick": "4.0.0",
148
- "supertest": "6.3.4",
149
- "ts-jest": "29.1.1",
149
+ "supertest": "7.0.0",
150
+ "ts-jest": "29.2.4",
150
151
  "ts-loader": "9.5.1",
151
- "ts-morph": "20.0.0",
152
+ "ts-morph": "21.0.1",
152
153
  "ts-node": "10.9.2",
153
154
  "tsconfig-paths": "4.2.0",
154
155
  "typescript": "5.3.3",
package/src/config.env.ts CHANGED
@@ -88,6 +88,11 @@ const config: { [env: string]: IServerOptions } = {
88
88
  uri: 'mongodb://127.0.0.1/nest-server-dev',
89
89
  },
90
90
  port: 3000,
91
+ security: {
92
+ checkResponseInterceptor: true,
93
+ checkSecurityInterceptor: true,
94
+ mapAndValidatePipe: true,
95
+ },
91
96
  sha256: true,
92
97
  staticAssets: {
93
98
  options: { prefix: '' },
@@ -190,6 +195,11 @@ const config: { [env: string]: IServerOptions } = {
190
195
  uri: 'mongodb://127.0.0.1/nest-server-local',
191
196
  },
192
197
  port: 3000,
198
+ security: {
199
+ checkResponseInterceptor: true,
200
+ checkSecurityInterceptor: true,
201
+ mapAndValidatePipe: true,
202
+ },
193
203
  sha256: true,
194
204
  staticAssets: {
195
205
  options: { prefix: '' },
@@ -281,6 +291,11 @@ const config: { [env: string]: IServerOptions } = {
281
291
  uri: 'mongodb://127.0.0.1/nest-server-prod',
282
292
  },
283
293
  port: 3000,
294
+ security: {
295
+ checkResponseInterceptor: true,
296
+ checkSecurityInterceptor: true,
297
+ mapAndValidatePipe: true,
298
+ },
284
299
  sha256: true,
285
300
  staticAssets: {
286
301
  options: { prefix: '' },
@@ -65,6 +65,7 @@ export const checkRestricted = (
65
65
  options: {
66
66
  checkObjectItself?: boolean;
67
67
  dbObject?: any;
68
+ debug?: boolean;
68
69
  ignoreUndefined?: boolean;
69
70
  processType?: ProcessType;
70
71
  removeUndefinedFromResultArray?: boolean;
@@ -73,7 +74,7 @@ export const checkRestricted = (
73
74
  processedObjects: any[] = [],
74
75
  ) => {
75
76
  const config = {
76
- checkObjectItself: false,
77
+ checkObjectItself: true,
77
78
  ignoreUndefined: true,
78
79
  removeUndefinedFromResultArray: true,
79
80
  throwError: true,
@@ -199,6 +200,9 @@ export const checkRestricted = (
199
200
  if (config.checkObjectItself) {
200
201
  const objectIsValid = validateRestricted(objectRestrictions);
201
202
  if (!objectIsValid) {
203
+ if (config.debug) {
204
+ console.debug(`The current user has no access rights for ${data.constructor?.name}`);
205
+ }
202
206
  // Throw error
203
207
  if (config.throwError) {
204
208
  throw new UnauthorizedException(`The current user has no access rights for ${data.constructor?.name}`);
@@ -216,14 +220,18 @@ export const checkRestricted = (
216
220
 
217
221
  // Check restricted
218
222
  const restricted = getRestricted(data, propertyKey) || [];
219
- const concatenatedRestrictions = _.uniq(objectRestrictions.concat(restricted));
220
- const valid = validateRestricted(concatenatedRestrictions);
223
+ const valid = validateRestricted(restricted);
221
224
 
222
225
  // Check rights
223
226
  if (valid) {
224
227
  // Check deep
225
228
  data[propertyKey] = checkRestricted(data[propertyKey], user, config, processedObjects);
226
229
  } else {
230
+ if (config.debug) {
231
+ console.debug(
232
+ `The current user has no access rights for ${propertyKey}${data.constructor?.name ? ` of ${data.constructor.name}` : ''}`,
233
+ );
234
+ }
227
235
  // Throw error
228
236
  if (config.throwError) {
229
237
  throw new UnauthorizedException(
@@ -403,6 +403,32 @@ export interface IServerOptions {
403
403
  */
404
404
  port?: number;
405
405
 
406
+ /**
407
+ * Configuration for security pipes and interceptors
408
+ */
409
+ security?: {
410
+ /**
411
+ * Check restrictions for output (models and output objects)
412
+ * See @lenne.tech/nest-server/src/core/common/interceptors/check-response.interceptor.ts
413
+ * default = true
414
+ */
415
+ checkResponseInterceptor?: boolean;
416
+
417
+ /**
418
+ * Process securityCheck() methode of Object before response
419
+ * See @lenne.tech/nest-server/src/core/common/interceptors/check-security.interceptor.ts
420
+ * default = true
421
+ */
422
+ checkSecurityInterceptor?: boolean;
423
+
424
+ /**
425
+ * Map incoming plain objects to meta-type and validate
426
+ * See @lenne.tech/nest-server/src/core/common/pipes/map-and-validate.pipe.ts
427
+ * default = true
428
+ */
429
+ mapAndValidatePipe?: boolean;
430
+ };
431
+
406
432
  /**
407
433
  * Whether to enable verification and automatic encryption for received passwords that are not in sha256 format
408
434
  * default = false, sha256 format check: /^[a-f0-9]{64}$/i
@@ -32,7 +32,7 @@ export abstract class CrudService<
32
32
  */
33
33
  async aggregate<T = any>(
34
34
  pipeline: PipelineStage[],
35
- serviceOptions?: ServiceOptions & { aggregateOptions?: AggregateOptions },
35
+ serviceOptions?: { aggregateOptions?: AggregateOptions } & ServiceOptions,
36
36
  ): Promise<T> {
37
37
  return this.process(
38
38
  async () => {
@@ -439,7 +439,7 @@ export abstract class CrudService<
439
439
  * Get service model to process queries directly
440
440
  * See https://mongoosejs.com/docs/api/model.html
441
441
  */
442
- getModel(): MongooseModel<Model & Document> {
442
+ getModel(): MongooseModel<Document & Model> {
443
443
  return this.mainDbModel;
444
444
  }
445
445
 
@@ -1,8 +1,9 @@
1
1
  import { HttpException, Injectable } from '@nestjs/common';
2
- import Mailjet from 'node-mailjet';
3
2
 
4
3
  import { ConfigService } from './config.service';
5
4
 
5
+ const Mailjet = require('node-mailjet');
6
+
6
7
  /**
7
8
  * Mailjet service
8
9
  */
@@ -28,14 +28,14 @@ export abstract class ModuleService<T extends CoreModel = any> {
28
28
  /**
29
29
  * Main DB model of the service, will be used as default for populate and mapping
30
30
  */
31
- protected mainDbModel: Model<T & Document>;
31
+ protected mainDbModel: Model<Document & T>;
32
32
 
33
33
  /**
34
34
  * Set main properties
35
35
  */
36
36
  protected constructor(options?: {
37
37
  configService?: ConfigService;
38
- mainDbModel?: Model<T & Document>;
38
+ mainDbModel?: Model<Document & T>;
39
39
  mainModelConstructor?: new (...args: any[]) => T;
40
40
  }) {
41
41
  this.configService = options?.configService;
@@ -272,7 +272,7 @@ export abstract class ModuleService<T extends CoreModel = any> {
272
272
  data: any,
273
273
  fieldsSelection: FieldSelection,
274
274
  options: {
275
- dbModel?: Model<T & Document>;
275
+ dbModel?: Model<Document & T>;
276
276
  ignoreSelections?: boolean;
277
277
  model?: new (...args: any[]) => T;
278
278
  } = {},
@@ -2,5 +2,7 @@
2
2
  * Require only one of the optional properties
3
3
  * See https://stackoverflow.com/a/49725198
4
4
  */
5
- export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
6
- { [K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>> }[Keys];
5
+ export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = {
6
+ [K in Keys]-?: Partial<Record<Exclude<Keys, K>, undefined>> & Required<Pick<T, K>>;
7
+ }[Keys] &
8
+ Pick<T, Exclude<keyof T, Keys>>;
@@ -2,5 +2,7 @@
2
2
  * Require at least on of optional properties
3
3
  * See https://stackoverflow.com/a/49725198
4
4
  */
5
- export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
6
- { [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>> }[Keys];
5
+ export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = {
6
+ [K in Keys]-?: Partial<Pick<T, Exclude<Keys, K>>> & Required<Pick<T, K>>;
7
+ }[Keys] &
8
+ Pick<T, Exclude<keyof T, Keys>>;
@@ -23,13 +23,13 @@ export class CoreAuthModule {
23
23
  static forRoot(
24
24
  UserModule: Type<any>,
25
25
  UserService: Type<CoreAuthUserService>,
26
- options: JwtModuleOptions & {
26
+ options: {
27
27
  authService?: Type<CoreAuthService>;
28
28
  imports?: Array<DynamicModule | ForwardReference | Promise<DynamicModule> | Type<any>>;
29
29
  jwtRefreshStrategy?: Type<JwtRefreshStrategy>;
30
30
  jwtStrategy?: Type<JwtStrategy>;
31
31
  providers?: Provider[];
32
- },
32
+ } & JwtModuleOptions,
33
33
  ): DynamicModule {
34
34
  // Process imports
35
35
  let imports: any[] = [
@@ -21,9 +21,9 @@ const NO_STRATEGY_ERROR
21
21
  /**
22
22
  * Interface for auth guard
23
23
  */
24
- export type IAuthGuard = CanActivate & {
24
+ export type IAuthGuard = {
25
25
  handleRequest<TUser = any>(err, user, info, context): TUser;
26
- };
26
+ } & CanActivate;
27
27
 
28
28
  /**
29
29
  * Create passport context
@@ -42,7 +42,7 @@ export class CoreAuthService {
42
42
  */
43
43
  async logout(
44
44
  tokenOrRefreshToken: string,
45
- serviceOptions: ServiceOptions & { allDevices?: boolean },
45
+ serviceOptions: { allDevices?: boolean } & ServiceOptions,
46
46
  ): Promise<boolean> {
47
47
  // Check authentication
48
48
  const user = serviceOptions.currentUser;
@@ -202,7 +202,7 @@ export abstract class CoreFileService {
202
202
  */
203
203
  protected checkRights(
204
204
  input: any, // eslint-disable-line unused-imports/no-unused-vars
205
- options?: FileServiceOptions & { checkInputType: FileInputCheckType }, // eslint-disable-line unused-imports/no-unused-vars
205
+ options?: { checkInputType: FileInputCheckType } & FileServiceOptions, // eslint-disable-line unused-imports/no-unused-vars
206
206
  ): MaybePromise<boolean> {
207
207
  return true;
208
208
  }
@@ -26,7 +26,7 @@ export abstract class CoreUserService<
26
26
  protected constructor(
27
27
  protected override readonly configService: ConfigService,
28
28
  protected readonly emailService: EmailService,
29
- protected override readonly mainDbModel: Model<TUser & Document>,
29
+ protected override readonly mainDbModel: Model<Document & TUser>,
30
30
  protected override readonly mainModelConstructor: CoreModelConstructor<TUser>,
31
31
  ) {
32
32
  super();
@@ -1,12 +1,14 @@
1
1
  import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
2
2
  import { DynamicModule, Global, MiddlewareConsumer, Module, NestModule, UnauthorizedException } from '@nestjs/common';
3
- import { APP_PIPE } from '@nestjs/core';
3
+ import { APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
4
4
  import { GraphQLModule } from '@nestjs/graphql';
5
5
  import { MongooseModule } from '@nestjs/mongoose';
6
6
  import { Context } from 'apollo-server-core';
7
7
  import mongoose from 'mongoose';
8
8
 
9
9
  import { merge } from './core/common/helpers/config.helper';
10
+ import { CheckResponseInterceptor } from './core/common/interceptors/check-response.interceptor';
11
+ import { CheckSecurityInterceptor } from './core/common/interceptors/check-security.interceptor';
10
12
  import { IServerOptions } from './core/common/interfaces/server-options.interface';
11
13
  import { MapAndValidatePipe } from './core/common/pipes/map-and-validate.pipe';
12
14
  import { ComplexityPlugin } from './core/common/plugins/complexity.plugin';
@@ -172,12 +174,6 @@ export class CoreModule implements NestModule {
172
174
  useValue: new ConfigService(config),
173
175
  },
174
176
 
175
- // [Global] Map plain objects to meta-type and validate
176
- {
177
- provide: APP_PIPE,
178
- useClass: MapAndValidatePipe,
179
- },
180
-
181
177
  // Core Services
182
178
  EmailService,
183
179
  TemplateService,
@@ -187,6 +183,30 @@ export class CoreModule implements NestModule {
187
183
  ComplexityPlugin,
188
184
  ];
189
185
 
186
+ if (config.security?.checkResponseInterceptor ?? true) {
187
+ // Check restrictions for output (models and output objects)
188
+ providers.push({
189
+ provide: APP_INTERCEPTOR,
190
+ useClass: CheckResponseInterceptor,
191
+ });
192
+ }
193
+
194
+ if (config.security?.checkSecurityInterceptor ?? true) {
195
+ // Process securityCheck() methode of Object before response
196
+ providers.push({
197
+ provide: APP_INTERCEPTOR,
198
+ useClass: CheckSecurityInterceptor,
199
+ });
200
+ }
201
+
202
+ if (config.security?.mapAndValidatePipe ?? true) {
203
+ // [Global] Map plain objects to meta-type and validate
204
+ providers.push({
205
+ provide: APP_PIPE,
206
+ useClass: MapAndValidatePipe,
207
+ });
208
+ }
209
+
190
210
  if (config.mongoose?.modelDocumentation) {
191
211
  providers.push(ModelDocService);
192
212
  }
package/src/index.ts CHANGED
@@ -91,6 +91,11 @@ export * from './core/common/types/wrapper.type';
91
91
  // Core - Modules - Auth
92
92
  // =====================================================================================================================
93
93
 
94
+ export * from './core/modules/auth/auth-guard-strategy.enum';
95
+ export * from './core/modules/auth/core-auth.controller';
96
+ export * from './core/modules/auth/core-auth.model';
97
+ export * from './core/modules/auth/core-auth.module';
98
+ export * from './core/modules/auth/core-auth.resolver';
94
99
  export * from './core/modules/auth/exceptions/expired-refresh-token.exception';
95
100
  export * from './core/modules/auth/exceptions/expired-token.exception';
96
101
  export * from './core/modules/auth/exceptions/invalid-token.exception';
@@ -105,42 +110,37 @@ export * from './core/modules/auth/services/core-auth.service';
105
110
  export * from './core/modules/auth/services/core-auth-user.service';
106
111
  export * from './core/modules/auth/strategies/jwt.strategy';
107
112
  export * from './core/modules/auth/strategies/jwt-refresh.strategy';
108
- export * from './core/modules/auth/auth-guard-strategy.enum';
109
- export * from './core/modules/auth/core-auth.controller';
110
- export * from './core/modules/auth/core-auth.model';
111
- export * from './core/modules/auth/core-auth.module';
112
- export * from './core/modules/auth/core-auth.resolver';
113
113
  export * from './core/modules/auth/tokens.decorator';
114
114
 
115
115
  // =====================================================================================================================
116
116
  // Core - Modules - File
117
117
  // =====================================================================================================================
118
118
 
119
- export * from './core/modules/file/interfaces/file-service-options.interface';
120
- export * from './core/modules/file/interfaces/file-upload.interface';
121
119
  export * from './core/modules/file/core-file.controller';
122
120
  export * from './core/modules/file/core-file.resolver';
123
121
  export * from './core/modules/file/core-file.service';
124
122
  export * from './core/modules/file/core-file-info.model';
123
+ export * from './core/modules/file/interfaces/file-service-options.interface';
124
+ export * from './core/modules/file/interfaces/file-upload.interface';
125
125
 
126
126
  // =====================================================================================================================
127
127
  // Core - Modules - User
128
128
  // =====================================================================================================================
129
129
 
130
- export * from './core/modules/user/inputs/core-user.input';
131
- export * from './core/modules/user/inputs/core-user-create.input';
132
- export * from './core/modules/user/core-user.model';
133
- export * from './core/modules/user/core-user.service';
130
+ export * from './core/modules/health-check/core-health-check.controller';
131
+ export * from './core/modules/health-check/core-health-check.module';
132
+ export * from './core/modules/health-check/core-health-check.resolver';
133
+ export * from './core/modules/health-check/core-health-check.service';
134
134
 
135
135
  // =====================================================================================================================
136
136
  // Core - Modules - HealthCheck
137
137
  // =====================================================================================================================
138
138
 
139
- export * from './core/modules/health-check/core-health-check.controller';
140
- export * from './core/modules/health-check/core-health-check.module';
141
- export * from './core/modules/health-check/core-health-check.resolver';
142
- export * from './core/modules/health-check/core-health-check.service';
143
139
  export * from './core/modules/health-check/core-health-check-result.model';
140
+ export * from './core/modules/user/core-user.model';
141
+ export * from './core/modules/user/core-user.service';
142
+ export * from './core/modules/user/inputs/core-user.input';
143
+ export * from './core/modules/user/inputs/core-user-create.input';
144
144
 
145
145
  // =====================================================================================================================
146
146
  // Tests
@@ -6,7 +6,7 @@ import { RoleEnum } from '../../../core/common/enums/role.enum';
6
6
  import { CoreUserModel } from '../../../core/modules/user/core-user.model';
7
7
  import { PersistenceModel } from '../../common/models/persistence.model';
8
8
 
9
- export type UserDocument = User & Document;
9
+ export type UserDocument = Document & User;
10
10
 
11
11
  /**
12
12
  * User model
@@ -17,6 +17,6 @@ export class ServerController {
17
17
  @Get('config')
18
18
  @Roles(RoleEnum.ADMIN)
19
19
  config() {
20
- return this.configService.configFastButReadOnly;
20
+ return JSON.parse(JSON.stringify(this.configService.configFastButReadOnly));
21
21
  }
22
22
  }
@@ -1,10 +1,8 @@
1
1
  import { Module } from '@nestjs/common';
2
- import { APP_INTERCEPTOR } from '@nestjs/core';
3
2
  import { ScheduleModule } from '@nestjs/schedule';
4
3
 
5
4
  import envConfig from '../config.env';
6
5
  import { CoreModule } from '../core.module';
7
- import { CheckSecurityInterceptor } from '../core/common/interceptors/check-security.interceptor';
8
6
  import { Any } from '../core/common/scalars/any.scalar';
9
7
  import { DateScalar } from '../core/common/scalars/date.scalar';
10
8
  import { JSON } from '../core/common/scalars/json.scalar';
@@ -43,15 +41,6 @@ import { ServerController } from './server.controller';
43
41
  FileModule,
44
42
  ],
45
43
 
46
- providers: [
47
- Any,
48
- CronJobs,
49
- DateScalar,
50
- JSON,
51
- {
52
- provide: APP_INTERCEPTOR,
53
- useClass: CheckSecurityInterceptor,
54
- },
55
- ],
44
+ providers: [Any, CronJobs, DateScalar, JSON],
56
45
  })
57
46
  export class ServerModule {}
@@ -176,7 +176,7 @@ export class TestHelper {
176
176
  });
177
177
  })
178
178
  .end((err, res: any) => {
179
- (res as any & { data: string }).data = Buffer.from(data, 'binary').toString();
179
+ (res as { data: string } & any).data = Buffer.from(data, 'binary').toString();
180
180
  err ? reject(err) : resolve(res as any);
181
181
  });
182
182
  });