@lenne.tech/nest-server 10.4.2 → 10.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "10.4.2",
3
+ "version": "10.5.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",
@@ -62,18 +62,18 @@
62
62
  "node": ">= 20"
63
63
  },
64
64
  "dependencies": {
65
- "@apollo/gateway": "2.9.2",
65
+ "@apollo/gateway": "2.9.3",
66
66
  "@getbrevo/brevo": "1.0.1",
67
67
  "@lenne.tech/mongoose-gridfs": "1.4.2",
68
68
  "@lenne.tech/multer-gridfs-storage": "5.0.6",
69
- "@nestjs/apollo": "12.2.0",
70
- "@nestjs/common": "10.4.4",
71
- "@nestjs/core": "10.4.4",
72
- "@nestjs/graphql": "12.2.0",
69
+ "@nestjs/apollo": "12.2.1",
70
+ "@nestjs/common": "10.4.6",
71
+ "@nestjs/core": "10.4.6",
72
+ "@nestjs/graphql": "12.2.1",
73
73
  "@nestjs/jwt": "10.2.0",
74
- "@nestjs/mongoose": "10.0.10",
74
+ "@nestjs/mongoose": "10.1.0",
75
75
  "@nestjs/passport": "10.0.3",
76
- "@nestjs/platform-express": "10.4.4",
76
+ "@nestjs/platform-express": "10.4.6",
77
77
  "@nestjs/schedule": "4.1.1",
78
78
  "@nestjs/terminus": "10.2.3",
79
79
  "apollo-server-core": "3.13.0",
@@ -82,7 +82,7 @@
82
82
  "class-transformer": "0.5.1",
83
83
  "class-validator": "0.14.1",
84
84
  "compression": "1.7.4",
85
- "cookie-parser": "1.4.6",
85
+ "cookie-parser": "1.4.7",
86
86
  "ejs": "3.1.10",
87
87
  "graphql": "16.9.0",
88
88
  "graphql-query-complexity": "1.0.0",
@@ -90,9 +90,9 @@
90
90
  "graphql-upload": "15.0.2",
91
91
  "js-sha256": "0.11.0",
92
92
  "json-to-graphql-query": "2.3.0",
93
- "light-my-request": "6.0.0",
93
+ "light-my-request": "6.2.0",
94
94
  "lodash": "4.17.21",
95
- "mongodb": "6.9.0",
95
+ "mongodb": "6.10.0",
96
96
  "mongoose": "7.8.2",
97
97
  "multer": "1.4.5-lts.1",
98
98
  "node-mailjet": "6.0.6",
@@ -108,22 +108,22 @@
108
108
  },
109
109
  "devDependencies": {
110
110
  "@babel/plugin-proposal-private-methods": "7.18.6",
111
- "@compodoc/compodoc": "1.1.25",
111
+ "@compodoc/compodoc": "1.1.26",
112
112
  "@lenne.tech/eslint-config-ts": "0.0.16",
113
113
  "@nestjs/cli": "10.4.5",
114
- "@nestjs/schematics": "10.1.4",
115
- "@nestjs/testing": "10.4.4",
114
+ "@nestjs/schematics": "10.2.2",
115
+ "@nestjs/testing": "10.4.6",
116
116
  "@swc/cli": "0.4.0",
117
- "@swc/core": "1.7.28",
117
+ "@swc/core": "1.7.39",
118
118
  "@swc/jest": "0.2.36",
119
119
  "@types/compression": "1.7.5",
120
120
  "@types/cookie-parser": "1.4.7",
121
121
  "@types/ejs": "3.1.5",
122
122
  "@types/express": "4.17.21",
123
- "@types/jest": "29.5.13",
124
- "@types/lodash": "4.17.9",
123
+ "@types/jest": "29.5.14",
124
+ "@types/lodash": "4.17.12",
125
125
  "@types/multer": "1.4.12",
126
- "@types/node": "20.16.9",
126
+ "@types/node": "20.17.0",
127
127
  "@types/nodemailer": "6.4.16",
128
128
  "@types/passport": "1.0.16",
129
129
  "@types/supertest": "6.0.2",
package/src/config.env.ts CHANGED
@@ -9,7 +9,7 @@ import { IServerOptions } from './core/common/interfaces/server-options.interfac
9
9
  */
10
10
  const config: { [env: string]: IServerOptions } = {
11
11
  // ===========================================================================
12
- // Local environment
12
+ // Development environment
13
13
  // ===========================================================================
14
14
  development: {
15
15
  automaticObjectIdFiltering: true,
@@ -1,7 +1,7 @@
1
1
  import { MongoGridFSOptions, MongooseGridFS, createBucket } from '@lenne.tech/mongoose-gridfs';
2
2
  import { NotFoundException } from '@nestjs/common';
3
3
  import { GridFSBucket, GridFSBucketReadStream, GridFSBucketReadStreamOptions } from 'mongodb';
4
- import { Connection, Types } from 'mongoose';
4
+ import mongoose, { Connection, Types } from 'mongoose';
5
5
 
6
6
  import { FilterArgs } from '../../common/args/filter.args';
7
7
  import { getObjectIds, getStringIds } from '../../common/helpers/db.helper';
@@ -66,6 +66,45 @@ export abstract class CoreFileService {
66
66
  return await Promise.all(promises);
67
67
  }
68
68
 
69
+ /**
70
+ * Duplicate file by name
71
+ */
72
+ async duplicateByName(name: string, newName: string): Promise<any> {
73
+ return new Promise(async (resolve) => {
74
+ resolve(this.files.openDownloadStreamByName(name).pipe(this.files.openUploadStream(newName)));
75
+ });
76
+ }
77
+
78
+ /**
79
+ * Duplicate file by ID
80
+ */
81
+ async duplicateById(id: string): Promise<string> {
82
+ const objectId = getObjectIds(id);
83
+ const file = await this.getFileInfo(objectId);
84
+ return new Promise((resolve, reject) => {
85
+ const downloadStream = this.files.openDownloadStream(objectId);
86
+
87
+ const newFileId = new mongoose.Types.ObjectId();
88
+ const uploadStream = this.files.openUploadStreamWithId(newFileId, file.filename, {
89
+ contentType: file.contentType,
90
+ });
91
+
92
+ downloadStream.pipe(uploadStream);
93
+
94
+ uploadStream.on('finish', () => {
95
+ resolve(getStringIds(newFileId));
96
+ });
97
+
98
+ uploadStream.on('error', (err: { message: any }) => {
99
+ reject(new Error(`File duplication failed: ${err.message}`));
100
+ });
101
+
102
+ downloadStream.on('error', (err: { message: any }) => {
103
+ reject(new Error(`File download failed: ${err.message}`));
104
+ });
105
+ });
106
+ }
107
+
69
108
  /**
70
109
  * Get file infos via filter
71
110
  */
@@ -155,6 +155,7 @@ export class TestHelper {
155
155
 
156
156
  /**
157
157
  * Download file from URL
158
+ * To compare content data via string comparison
158
159
  * @return Superagent response with additional data field containing the content of the file
159
160
  */
160
161
  download(url: string, token?: string): Promise<any> {
@@ -183,6 +184,40 @@ export class TestHelper {
183
184
  });
184
185
  }
185
186
 
187
+ /**
188
+ * Download file from URL and get buffer
189
+ * To compare content data via buffer comparison and with the possibility to save the file
190
+ */
191
+ downloadBuffer(url: string, token?: string): Promise<Buffer> {
192
+ return new Promise((resolve, reject) => {
193
+ const request = supertest(this.app.getHttpServer()).get(url);
194
+ if (token) {
195
+ request.set('Authorization', `bearer ${token}`);
196
+ }
197
+
198
+ // Array to store the data chunks
199
+ const chunks: any[] = [];
200
+
201
+ request
202
+ .buffer()
203
+ .parse((res: any, callback) => {
204
+ res.on('data', (chunk) => {
205
+ chunks.push(chunk);
206
+ });
207
+ res.on('error', reject);
208
+ res.on('end', (err) => {
209
+ err ? reject(err) : callback(null, Buffer.concat(chunks));
210
+ });
211
+ })
212
+ .end((err, res: any) => {
213
+ if (err) {
214
+ return reject(err);
215
+ }
216
+ resolve(res.body); // res.body should be a Buffer
217
+ });
218
+ });
219
+ }
220
+
186
221
  /**
187
222
  * GraphQL request
188
223
  */
@@ -509,6 +544,13 @@ export class TestHelper {
509
544
  }
510
545
  }
511
546
 
547
+ // Process REST payload
548
+ if (attachments && requestConfig.payload) {
549
+ for (const [key, value] of Object.entries(requestConfig.payload)) {
550
+ request.field(key, value);
551
+ }
552
+ }
553
+
512
554
  // Response
513
555
  if (log) {
514
556
  console.info(requestConfig);
@@ -580,8 +622,14 @@ export class TestHelper {
580
622
  if (logError && response.statusCode !== statusCode && response.statusCode >= 400) {
581
623
  if (response && response.error && response.error.text) {
582
624
  const errors = JSON.parse(response.error.text).errors;
583
- for (const error of errors) {
584
- console.error(util.inspect(error, false, null, true));
625
+ if (!errors) {
626
+ console.error(util.inspect(response.error.text, false, null, true));
627
+ } else if (Array.isArray(errors)) {
628
+ for (const error of errors) {
629
+ console.error(util.inspect(error, false, null, true));
630
+ }
631
+ } else {
632
+ console.error(util.inspect(errors, false, null, true));
585
633
  }
586
634
  }
587
635
  }