@lenne.tech/nest-server 8.6.28 → 9.0.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.
- package/dist/config.env.js +37 -12
- package/dist/config.env.js.map +1 -1
- package/dist/core/common/helpers/input.helper.js +3 -3
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/model.helper.js +12 -12
- package/dist/core/common/helpers/model.helper.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +1 -0
- package/dist/core/common/services/core-cron-jobs.service.d.ts +3 -1
- package/dist/core/common/services/core-cron-jobs.service.js +5 -0
- package/dist/core/common/services/core-cron-jobs.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +28 -28
- package/src/config.env.ts +39 -12
- package/src/core/common/helpers/input.helper.ts +3 -3
- package/src/core/common/helpers/model.helper.ts +12 -12
- package/src/core/common/interfaces/server-options.interface.ts +8 -0
- package/src/core/common/services/core-cron-jobs.service.ts +12 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.1",
|
|
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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"build:pack": "npm pack && echo 'use file:/ROOT_PATH_TO_TGZ_FILE to integrate the package'",
|
|
19
19
|
"docs": "npm run docs:ci && open ./public/index.html",
|
|
20
20
|
"docs:bootstrap": "node extras/update-spectaql-version.mjs && npx -y spectaql ./spectaql.yml",
|
|
21
|
-
"docs:ci": "ts-node ./scripts/init-server.ts && npm run docs:
|
|
21
|
+
"docs:ci": "ts-node ./scripts/init-server.ts && npm run docs:bootstrap",
|
|
22
22
|
"format": "prettier --write 'src/**/*.ts'",
|
|
23
23
|
"format:staged": "pretty-quick --staged",
|
|
24
24
|
"lint": "eslint \"{src,tests}/**/*.ts\" --fix",
|
|
@@ -59,17 +59,17 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@apollo/gateway": "2.0.5",
|
|
62
|
-
"@nestjs/apollo": "10.0.
|
|
63
|
-
"@nestjs/common": "
|
|
64
|
-
"@nestjs/core": "
|
|
65
|
-
"@nestjs/graphql": "10.0.
|
|
66
|
-
"@nestjs/jwt": "
|
|
67
|
-
"@nestjs/mongoose": "9.
|
|
68
|
-
"@nestjs/passport": "
|
|
69
|
-
"@nestjs/platform-express": "
|
|
70
|
-
"@nestjs/schedule": "2.0
|
|
71
|
-
"apollo-server-core": "3.
|
|
72
|
-
"apollo-server-express": "3.
|
|
62
|
+
"@nestjs/apollo": "10.0.17",
|
|
63
|
+
"@nestjs/common": "9.0.3",
|
|
64
|
+
"@nestjs/core": "9.0.3",
|
|
65
|
+
"@nestjs/graphql": "10.0.18",
|
|
66
|
+
"@nestjs/jwt": "9.0.0",
|
|
67
|
+
"@nestjs/mongoose": "9.2.0",
|
|
68
|
+
"@nestjs/passport": "9.0.0",
|
|
69
|
+
"@nestjs/platform-express": "9.0.3",
|
|
70
|
+
"@nestjs/schedule": "2.1.0",
|
|
71
|
+
"apollo-server-core": "3.10.0",
|
|
72
|
+
"apollo-server-express": "3.10.0",
|
|
73
73
|
"bcrypt": "5.0.1",
|
|
74
74
|
"class-transformer": "0.5.1",
|
|
75
75
|
"class-validator": "0.13.2",
|
|
@@ -79,37 +79,37 @@
|
|
|
79
79
|
"graphql-upload": "15.0.2",
|
|
80
80
|
"js-sha256": "0.9.0",
|
|
81
81
|
"json-to-graphql-query": "2.2.4",
|
|
82
|
-
"light-my-request": "5.
|
|
82
|
+
"light-my-request": "5.1.0",
|
|
83
83
|
"lodash": "4.17.21",
|
|
84
|
-
"mongodb": "4.
|
|
85
|
-
"mongoose": "6.4.
|
|
84
|
+
"mongodb": "4.8.0",
|
|
85
|
+
"mongoose": "6.4.4",
|
|
86
86
|
"mongoose-gridfs": "1.3.0",
|
|
87
87
|
"multer": "1.4.5-lts.1",
|
|
88
88
|
"node-mailjet": "5.0.1",
|
|
89
|
-
"nodemailer": "6.7.
|
|
90
|
-
"nodemon": "2.0.
|
|
89
|
+
"nodemailer": "6.7.7",
|
|
90
|
+
"nodemon": "2.0.19",
|
|
91
91
|
"passport": "0.6.0",
|
|
92
92
|
"passport-jwt": "4.0.0",
|
|
93
93
|
"reflect-metadata": "0.1.13",
|
|
94
94
|
"rfdc": "1.3.0",
|
|
95
95
|
"rimraf": "3.0.2",
|
|
96
|
-
"rxjs": "7.5.
|
|
96
|
+
"rxjs": "7.5.6"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
-
"@nestjs/testing": "
|
|
99
|
+
"@nestjs/testing": "9.0.3",
|
|
100
100
|
"@types/cron": "2.0.0",
|
|
101
101
|
"@types/ejs": "3.1.1",
|
|
102
|
-
"@types/jest": "28.1.
|
|
102
|
+
"@types/jest": "28.1.6",
|
|
103
103
|
"@types/lodash": "4.14.182",
|
|
104
104
|
"@types/multer": "1.4.7",
|
|
105
|
-
"@types/node": "18.0.
|
|
105
|
+
"@types/node": "18.0.5",
|
|
106
106
|
"@types/nodemailer": "6.4.4",
|
|
107
107
|
"@types/passport": "1.0.9",
|
|
108
108
|
"@types/supertest": "2.0.12",
|
|
109
|
-
"@typescript-eslint/eslint-plugin": "5.30.
|
|
110
|
-
"@typescript-eslint/parser": "5.30.
|
|
109
|
+
"@typescript-eslint/eslint-plugin": "5.30.6",
|
|
110
|
+
"@typescript-eslint/parser": "5.30.6",
|
|
111
111
|
"coffeescript": "2.7.0",
|
|
112
|
-
"eslint": "8.
|
|
112
|
+
"eslint": "8.20.0",
|
|
113
113
|
"eslint-config-prettier": "8.5.0",
|
|
114
114
|
"find-file-up": "2.0.1",
|
|
115
115
|
"grunt": "1.5.3",
|
|
@@ -118,14 +118,14 @@
|
|
|
118
118
|
"grunt-contrib-watch": "1.1.0",
|
|
119
119
|
"grunt-sync": "0.8.2",
|
|
120
120
|
"husky": "8.0.1",
|
|
121
|
-
"jest": "28.1.
|
|
121
|
+
"jest": "28.1.3",
|
|
122
122
|
"pm2": "5.2.0",
|
|
123
123
|
"prettier": "2.7.1",
|
|
124
124
|
"pretty-quick": "3.1.3",
|
|
125
125
|
"supertest": "6.2.4",
|
|
126
|
-
"ts-jest": "28.0.
|
|
126
|
+
"ts-jest": "28.0.7",
|
|
127
127
|
"ts-morph": "15.1.0",
|
|
128
|
-
"ts-node": "10.
|
|
128
|
+
"ts-node": "10.9.1",
|
|
129
129
|
"tsconfig-paths": "4.0.0",
|
|
130
130
|
"typescript": "4.7.4"
|
|
131
131
|
},
|
package/src/config.env.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CronExpression } from '@nestjs/schedule';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
+
import { merge } from './core/common/helpers/config.helper';
|
|
3
4
|
import { IServerOptions } from './core/common/interfaces/server-options.interface';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -22,8 +23,8 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
22
23
|
email: {
|
|
23
24
|
smtp: {
|
|
24
25
|
auth: {
|
|
25
|
-
user: '
|
|
26
|
-
pass: '
|
|
26
|
+
user: 'sandra98@ethereal.email',
|
|
27
|
+
pass: 'JCQQdz8xJEfBSewahK',
|
|
27
28
|
},
|
|
28
29
|
host: 'smtp.ethereal.email',
|
|
29
30
|
port: 587,
|
|
@@ -34,8 +35,8 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
34
35
|
api_key_private: 'MAILJET_API_KEY_PRIVATE',
|
|
35
36
|
},
|
|
36
37
|
defaultSender: {
|
|
37
|
-
email: '
|
|
38
|
-
name: '
|
|
38
|
+
email: 'sandra98@ethereal.email',
|
|
39
|
+
name: 'Sandra Klein',
|
|
39
40
|
},
|
|
40
41
|
verificationLink: 'http://localhost:4200/user/verification',
|
|
41
42
|
passwordResetLink: 'http://localhost:4200/user/password-reset',
|
|
@@ -51,6 +52,7 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
51
52
|
jwt: {
|
|
52
53
|
secret: 'SECRET_OR_PRIVATE_KEY_DEV',
|
|
53
54
|
},
|
|
55
|
+
loadLocalConfig: false,
|
|
54
56
|
mongoose: {
|
|
55
57
|
uri: 'mongodb://localhost/nest-server-dev',
|
|
56
58
|
},
|
|
@@ -73,8 +75,8 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
73
75
|
email: {
|
|
74
76
|
smtp: {
|
|
75
77
|
auth: {
|
|
76
|
-
user: '
|
|
77
|
-
pass: '
|
|
78
|
+
user: 'sandra98@ethereal.email',
|
|
79
|
+
pass: 'JCQQdz8xJEfBSewahK',
|
|
78
80
|
},
|
|
79
81
|
host: 'smtp.ethereal.email',
|
|
80
82
|
port: 587,
|
|
@@ -85,8 +87,8 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
85
87
|
api_key_private: 'MAILJET_API_KEY_PRIVATE',
|
|
86
88
|
},
|
|
87
89
|
defaultSender: {
|
|
88
|
-
email: '
|
|
89
|
-
name: '
|
|
90
|
+
email: 'sandra98@ethereal.email',
|
|
91
|
+
name: 'Sandra Klein',
|
|
90
92
|
},
|
|
91
93
|
verificationLink: 'http://localhost:4200/user/verification',
|
|
92
94
|
passwordResetLink: 'http://localhost:4200/user/password-reset',
|
|
@@ -102,6 +104,7 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
102
104
|
jwt: {
|
|
103
105
|
secret: 'SECRET_OR_PRIVATE_KEY_DEV',
|
|
104
106
|
},
|
|
107
|
+
loadLocalConfig: false,
|
|
105
108
|
mongoose: {
|
|
106
109
|
uri: 'mongodb://localhost/nest-server-dev',
|
|
107
110
|
},
|
|
@@ -124,8 +127,8 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
124
127
|
email: {
|
|
125
128
|
smtp: {
|
|
126
129
|
auth: {
|
|
127
|
-
user: '
|
|
128
|
-
pass: '
|
|
130
|
+
user: 'sandra98@ethereal.email',
|
|
131
|
+
pass: 'JCQQdz8xJEfBSewahK',
|
|
129
132
|
},
|
|
130
133
|
host: 'smtp.ethereal.email',
|
|
131
134
|
port: 587,
|
|
@@ -136,8 +139,8 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
136
139
|
api_key_private: 'MAILJET_API_KEY_PRIVATE',
|
|
137
140
|
},
|
|
138
141
|
defaultSender: {
|
|
139
|
-
email: '
|
|
140
|
-
name: '
|
|
142
|
+
email: 'sandra98@ethereal.email',
|
|
143
|
+
name: 'Sandra Klein',
|
|
141
144
|
},
|
|
142
145
|
verificationLink: 'http://localhost:4200/user/verification',
|
|
143
146
|
passwordResetLink: 'http://localhost:4200/user/password-reset',
|
|
@@ -153,6 +156,7 @@ const config: { [env: string]: IServerOptions } = {
|
|
|
153
156
|
jwt: {
|
|
154
157
|
secret: 'SECRET_OR_PRIVATE_KEY_PROD',
|
|
155
158
|
},
|
|
159
|
+
loadLocalConfig: false,
|
|
156
160
|
mongoose: {
|
|
157
161
|
uri: 'mongodb://localhost/nest-server-prod',
|
|
158
162
|
},
|
|
@@ -178,6 +182,29 @@ const env = process.env['NODE' + '_ENV'] || 'development';
|
|
|
178
182
|
const envConfig = config[env] || config.development;
|
|
179
183
|
console.info('Configured for: ' + envConfig.env + (env !== envConfig.env ? ' (requested: ' + env + ')' : ''));
|
|
180
184
|
|
|
185
|
+
// Merge with localConfig (e.g. config.json)
|
|
186
|
+
if (envConfig.loadLocalConfig) {
|
|
187
|
+
let localConfig;
|
|
188
|
+
if (typeof envConfig.loadLocalConfig === 'string') {
|
|
189
|
+
localConfig = require(envConfig.loadLocalConfig);
|
|
190
|
+
merge(envConfig, localConfig);
|
|
191
|
+
} else {
|
|
192
|
+
try {
|
|
193
|
+
// get config from src directory
|
|
194
|
+
localConfig = require(__dirname + '/config.json');
|
|
195
|
+
merge(envConfig, localConfig);
|
|
196
|
+
} catch {
|
|
197
|
+
try {
|
|
198
|
+
// if not found try to find in project directory
|
|
199
|
+
localConfig = require(__dirname + '/../config.json');
|
|
200
|
+
merge(envConfig, localConfig);
|
|
201
|
+
} catch (e) {
|
|
202
|
+
// No config.json found => nothing to do
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
181
208
|
/**
|
|
182
209
|
* Export envConfig as default
|
|
183
210
|
*/
|
|
@@ -322,12 +322,12 @@ export function clone(object: any, options?: { proto?: boolean; circles?: boolea
|
|
|
322
322
|
try {
|
|
323
323
|
return rfdc(config)(object);
|
|
324
324
|
} catch (e) {
|
|
325
|
-
console.
|
|
326
|
-
if (
|
|
325
|
+
console.debug(e);
|
|
326
|
+
if (!config.circles) {
|
|
327
327
|
try {
|
|
328
328
|
return rfdc({ ...config, ...{ circles: true } })(object);
|
|
329
329
|
} catch (e) {
|
|
330
|
-
console.
|
|
330
|
+
console.debug(e);
|
|
331
331
|
return _.clone(object);
|
|
332
332
|
}
|
|
333
333
|
} else {
|
|
@@ -202,18 +202,18 @@ export function mapClasses<T = Record<string, any>>(
|
|
|
202
202
|
if (Array.isArray(value)) {
|
|
203
203
|
const arr = [];
|
|
204
204
|
for (const item of value) {
|
|
205
|
-
if (
|
|
206
|
-
arr.push(
|
|
207
|
-
} else if (
|
|
208
|
-
config.objectIdsToString ? arr.push(
|
|
209
|
-
} else if (typeof
|
|
205
|
+
if (item instanceof targetClass) {
|
|
206
|
+
arr.push(item);
|
|
207
|
+
} else if (item instanceof Types.ObjectId) {
|
|
208
|
+
config.objectIdsToString ? arr.push(item.toHexString()) : arr.push(item);
|
|
209
|
+
} else if (typeof item === 'object') {
|
|
210
210
|
if (targetClass.map) {
|
|
211
211
|
arr.push(targetClass.map(item));
|
|
212
212
|
} else {
|
|
213
213
|
arr.push(plainToInstance(targetClass, item));
|
|
214
214
|
}
|
|
215
215
|
} else {
|
|
216
|
-
arr.push(
|
|
216
|
+
arr.push(item);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
target[prop] = arr as any;
|
|
@@ -285,18 +285,18 @@ export async function mapClassesAsync<T = Record<string, any>>(
|
|
|
285
285
|
if (Array.isArray(value)) {
|
|
286
286
|
const arr = [];
|
|
287
287
|
for (const item of value) {
|
|
288
|
-
if (
|
|
289
|
-
arr.push(
|
|
290
|
-
} else if (
|
|
291
|
-
config.objectIdsToString ? arr.push(
|
|
292
|
-
} else if (typeof
|
|
288
|
+
if (item instanceof targetClass) {
|
|
289
|
+
arr.push(item);
|
|
290
|
+
} else if (item instanceof Types.ObjectId) {
|
|
291
|
+
config.objectIdsToString ? arr.push(item.toHexString()) : arr.push(item);
|
|
292
|
+
} else if (typeof item === 'object') {
|
|
293
293
|
if (targetClass.map) {
|
|
294
294
|
arr.push(await targetClass.map(item));
|
|
295
295
|
} else {
|
|
296
296
|
arr.push(plainToInstance(targetClass, item));
|
|
297
297
|
}
|
|
298
298
|
} else {
|
|
299
|
-
arr.push(
|
|
299
|
+
arr.push(item);
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
target[prop] = arr as any;
|
|
@@ -128,6 +128,14 @@ export interface IServerOptions {
|
|
|
128
128
|
secretOrPrivateKey?: string;
|
|
129
129
|
} & JwtModuleOptions;
|
|
130
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Load local configuration
|
|
133
|
+
* false: no local configuration is loaded,
|
|
134
|
+
* true: it tries to load ./config.json or ../config.json,
|
|
135
|
+
* string: path to configuration
|
|
136
|
+
*/
|
|
137
|
+
loadLocalConfig?: boolean | string;
|
|
138
|
+
|
|
131
139
|
/**
|
|
132
140
|
* Configuration for Mongoose
|
|
133
141
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OnApplicationBootstrap } from '@nestjs/common';
|
|
1
2
|
import { CronExpression, SchedulerRegistry } from '@nestjs/schedule';
|
|
2
3
|
import { CronJob } from 'cron';
|
|
3
4
|
import { CronJobConfig } from '../interfaces/cron-job-config.interface';
|
|
@@ -6,7 +7,7 @@ import { Falsy } from '../types/falsy.type';
|
|
|
6
7
|
/**
|
|
7
8
|
* Cron jobs service to extend
|
|
8
9
|
*/
|
|
9
|
-
export abstract class CoreCronJobs {
|
|
10
|
+
export abstract class CoreCronJobs implements OnApplicationBootstrap {
|
|
10
11
|
/**
|
|
11
12
|
* Config for cron jobs
|
|
12
13
|
*/
|
|
@@ -36,6 +37,16 @@ export abstract class CoreCronJobs {
|
|
|
36
37
|
log: true,
|
|
37
38
|
...options,
|
|
38
39
|
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Lifecycle hook method: Called once all modules have been initialized, but before listening for connections.
|
|
44
|
+
* Required to ensure that all services have been previously initiated
|
|
45
|
+
*/
|
|
46
|
+
onApplicationBootstrap() {
|
|
47
|
+
if (this.config.log) {
|
|
48
|
+
console.info('Init CronJobs after application bootstrap');
|
|
49
|
+
}
|
|
39
50
|
this.initCronJobs();
|
|
40
51
|
}
|
|
41
52
|
|