@lenne.tech/nest-server 8.6.6 → 8.6.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "8.6.6",
3
+ "version": "8.6.7",
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",
@@ -26,8 +26,9 @@
26
26
  "reinit": "rimraf package-lock.json && rimraf node_modules && npm cache clean --force && npm i && npm run test:e2e && npm run build",
27
27
  "reinit:force": "rimraf package-lock.json && rimraf node_modules && npm cache clean --force && npm i --force && npm run test:e2e",
28
28
  "reinit:legacy": "rimraf package-lock.json && rimraf node_modules && npm cache clean --force && npm i --legacy-peer-deps && npm run test:e2e",
29
- "start": "./node_modules/.bin/grunt",
29
+ "start": "npm run start:dev",
30
30
  "stop": "./node_modules/.bin/pm2 delete nest",
31
+ "start:pm2": "./node_modules/.bin/grunt",
31
32
  "start:prod": "./node_modules/.bin/grunt productive",
32
33
  "start:nodemon": "ts-node -r tsconfig-paths/register src/main.ts",
33
34
  "start:debug": "nodemon --config nodemon-debug.json",
@@ -56,17 +57,17 @@
56
57
  "node": ">= 16.13.0"
57
58
  },
58
59
  "dependencies": {
59
- "@apollo/gateway": "0.50.2",
60
- "@nestjs/apollo": "10.0.12",
61
- "@nestjs/common": "8.4.5",
62
- "@nestjs/core": "8.4.5",
63
- "@nestjs/graphql": "10.0.12",
60
+ "@apollo/gateway": "2.0.5",
61
+ "@nestjs/apollo": "10.0.14",
62
+ "@nestjs/common": "8.4.6",
63
+ "@nestjs/core": "8.4.6",
64
+ "@nestjs/graphql": "10.0.15",
64
65
  "@nestjs/jwt": "8.0.1",
65
66
  "@nestjs/mongoose": "9.1.0",
66
67
  "@nestjs/passport": "8.2.1",
67
- "@nestjs/platform-express": "8.4.5",
68
- "apollo-server-core": "3.7.0",
69
- "apollo-server-express": "3.7.0",
68
+ "@nestjs/platform-express": "8.4.6",
69
+ "apollo-server-core": "3.8.2",
70
+ "apollo-server-express": "3.8.2",
70
71
  "bcrypt": "5.0.1",
71
72
  "class-transformer": "0.5.1",
72
73
  "class-validator": "0.13.2",
@@ -77,8 +78,8 @@
77
78
  "json-to-graphql-query": "2.2.4",
78
79
  "light-my-request": "5.0.0",
79
80
  "lodash": "4.17.21",
80
- "mongodb": "4.6.0",
81
- "mongoose": "6.3.4",
81
+ "mongodb": "4.7.0",
82
+ "mongoose": "6.3.6",
82
83
  "multer": "1.4.4",
83
84
  "node-mailjet": "3.4.1",
84
85
  "nodemailer": "6.7.5",
@@ -90,20 +91,20 @@
90
91
  "rxjs": "7.5.5"
91
92
  },
92
93
  "devDependencies": {
93
- "@nestjs/testing": "8.4.5",
94
+ "@nestjs/testing": "8.4.6",
94
95
  "@types/ejs": "3.1.1",
95
- "@types/jest": "27.5.1",
96
+ "@types/jest": "28.1.1",
96
97
  "@types/lodash": "4.14.182",
97
98
  "@types/multer": "1.4.7",
98
- "@types/node": "16.11.36",
99
+ "@types/node": "16.11.39",
99
100
  "@types/node-mailjet": "3.3.9",
100
101
  "@types/nodemailer": "6.4.4",
101
- "@types/passport": "1.0.7",
102
+ "@types/passport": "1.0.8",
102
103
  "@types/supertest": "2.0.12",
103
- "@typescript-eslint/eslint-plugin": "5.25.0",
104
- "@typescript-eslint/parser": "5.25.0",
104
+ "@typescript-eslint/eslint-plugin": "5.27.1",
105
+ "@typescript-eslint/parser": "5.27.1",
105
106
  "coffeescript": "2.7.0",
106
- "eslint": "8.16.0",
107
+ "eslint": "8.17.0",
107
108
  "eslint-config-prettier": "8.5.0",
108
109
  "find-file-up": "2.0.1",
109
110
  "grunt": "1.5.3",
@@ -112,16 +113,16 @@
112
113
  "grunt-contrib-watch": "1.1.0",
113
114
  "grunt-sync": "0.8.2",
114
115
  "husky": "8.0.1",
115
- "jest": "28.1.0",
116
+ "jest": "28.1.1",
116
117
  "pm2": "5.2.0",
117
118
  "prettier": "2.6.2",
118
119
  "pretty-quick": "3.1.3",
119
120
  "supertest": "6.2.3",
120
- "ts-jest": "28.0.2",
121
- "ts-morph": "14.0.0",
122
- "ts-node": "10.8.0",
121
+ "ts-jest": "28.0.4",
122
+ "ts-morph": "15.1.0",
123
+ "ts-node": "10.8.1",
123
124
  "tsconfig-paths": "4.0.0",
124
- "typescript": "4.6.4"
125
+ "typescript": "4.7.3"
125
126
  },
126
127
  "jest": {
127
128
  "collectCoverage": true,
@@ -423,7 +423,9 @@ export function removeUnresolvedReferences<T = any>(
423
423
  if (typeof populated === 'object') {
424
424
  // populatedOptions is an array
425
425
  if (Array.isArray(populatedOptions)) {
426
- populatedOptions.forEach((po) => removeUnresolvedReferences(populated, ignoreFirst ? po.populate : po, false));
426
+ populatedOptions.forEach((po) =>
427
+ removeUnresolvedReferences(populated, ignoreFirst && typeof po === 'object' ? po.populate : po, false)
428
+ );
427
429
  return populated;
428
430
  }
429
431
 
@@ -462,7 +464,10 @@ export async function popAndMap<T extends CoreModel>(
462
464
  let result;
463
465
  let populateOptions: PopulateOptions[] = [];
464
466
  if (populate) {
465
- if (Array.isArray(populate) && typeof (populate as PopulateOptions[])[0]?.path === 'string') {
467
+ if (
468
+ Array.isArray(populate) &&
469
+ (typeof (populate as string[])[0] === 'string' || typeof (populate as PopulateOptions[])[0]?.path === 'string')
470
+ ) {
466
471
  populateOptions = populate as PopulateOptions[];
467
472
  } else if (Array.isArray(populate) && typeof (populate as SelectionNode[])[0]?.kind === 'string') {
468
473
  populateOptions = getPopulatOptionsFromSelections(populate as SelectionNode[]);
@@ -55,6 +55,7 @@ export async function prepareInput<T = any>(
55
55
  currentUser: { [key: string]: any; id: string },
56
56
  options: {
57
57
  [key: string]: any;
58
+ checkRoles?: boolean;
58
59
  create?: boolean;
59
60
  clone?: boolean;
60
61
  getNewArray?: boolean;
@@ -148,6 +149,7 @@ export async function prepareOutput<T = { [key: string]: any; map: (...args: any
148
149
  [key: string]: any;
149
150
  clone?: boolean;
150
151
  getNewArray?: boolean;
152
+ removeSecrets?: boolean;
151
153
  removeUndefined?: boolean;
152
154
  targetModel?: new (...args: any[]) => T;
153
155
  } = {}
@@ -156,6 +158,7 @@ export async function prepareOutput<T = { [key: string]: any; map: (...args: any
156
158
  const config = {
157
159
  clone: false,
158
160
  getNewArray: false,
161
+ removeSecrets: true,
159
162
  removeUndefined: false,
160
163
  targetModel: undefined,
161
164
  ...options,
@@ -191,17 +194,17 @@ export async function prepareOutput<T = { [key: string]: any; map: (...args: any
191
194
  }
192
195
 
193
196
  // Remove password if exists
194
- if (output.password) {
197
+ if (config.removeSecrets && output.password) {
195
198
  output.password = undefined;
196
199
  }
197
200
 
198
201
  // Remove verification token if exists
199
- if (output.verificationToken) {
202
+ if (config.removeSecrets && output.verificationToken) {
200
203
  output.verificationToken = undefined;
201
204
  }
202
205
 
203
206
  // Remove password reset token if exists
204
- if (output.passwordResetToken) {
207
+ if (config.removeSecrets && output.passwordResetToken) {
205
208
  output.passwordResetToken = undefined;
206
209
  }
207
210
 
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export interface PrepareInputOptions {
5
5
  [key: string]: any;
6
+ checkRoles?: boolean;
6
7
  create?: boolean;
7
8
  clone?: boolean;
8
9
  getNewArray?: boolean;
@@ -5,6 +5,7 @@ export interface PrepareOutputOptions {
5
5
  [key: string]: any;
6
6
  clone?: boolean;
7
7
  getNewArray?: boolean;
8
+ removeSecrets?: boolean;
8
9
  removeUndefined?: boolean;
9
10
  targetModel?: new (...args: any[]) => any;
10
11
  }
@@ -1,4 +1,4 @@
1
- import { Model } from 'mongoose';
1
+ import { Model, PopulateOptions } from 'mongoose';
2
2
  import { FieldSelection } from '../types/field-selection.type';
3
3
  import { PrepareInputOptions } from './prepare-input-options.interface';
4
4
  import { PrepareOutputOptions } from './prepare-output-options.interface';
@@ -22,15 +22,21 @@ export interface ServiceOptions {
22
22
  roles?: string[];
23
23
  };
24
24
 
25
- // Field selection for results
25
+ // Field selection for results (will be overwritten by populate if populate was set)
26
26
  fieldSelection?: FieldSelection;
27
27
 
28
+ // Determines whether all restrictions are ignored
29
+ force?: boolean;
30
+
28
31
  // Overwrites type of input (array items)
29
32
  inputType?: new (...params: any[]) => any;
30
33
 
31
34
  // Overwrites type of output (array items)
32
35
  outputType?: new (...params: any[]) => any;
33
36
 
37
+ // Alias for fieldSelection (if both are set fieldSelection is overwritten by populate)
38
+ populate?: PopulateOptions | (PopulateOptions | string)[];
39
+
34
40
  // Process field selection
35
41
  // If {} or not set, then the field selection runs with defaults
36
42
  // If falsy, then the field selection will not be automatically executed
@@ -74,6 +74,7 @@ export abstract class ModuleService<T extends CoreModel = any> {
74
74
  const config = {
75
75
  checkRights: true,
76
76
  dbObject: options?.dbObject,
77
+ force: false,
77
78
  input: options?.input,
78
79
  processFieldSelection: {},
79
80
  prepareInput: {},
@@ -82,6 +83,22 @@ export abstract class ModuleService<T extends CoreModel = any> {
82
83
  ...options?.serviceOptions,
83
84
  };
84
85
 
86
+ // Note force configuration
87
+ if (config.force) {
88
+ config.checkRights = false;
89
+ if (typeof config.prepareInput === 'object') {
90
+ config.prepareInput.checkRoles = false;
91
+ }
92
+ if (typeof config.prepareOutput === 'object') {
93
+ config.prepareOutput.removeSecrets = false;
94
+ }
95
+ }
96
+
97
+ // Note populate
98
+ if (config.populate) {
99
+ config.fieldSelection = config.populate;
100
+ }
101
+
85
102
  // Prepare input
86
103
  if (config.prepareInput && this.prepareInput) {
87
104
  const opts = config.prepareInput;
@@ -5,4 +5,4 @@ import { ResolveSelector } from '../interfaces/resolve-selector.interface';
5
5
  /**
6
6
  * Field selection to set fields of (populated) result
7
7
  */
8
- export type FieldSelection = PopulateOptions[] | SelectionNode[] | ResolveSelector;
8
+ export type FieldSelection = PopulateOptions | (PopulateOptions | string)[] | SelectionNode[] | ResolveSelector;