@lenne.tech/nest-server 10.4.1 → 10.4.3

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.1",
3
+ "version": "10.4.3",
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",
@@ -47,7 +47,6 @@
47
47
  "test:ci": "NODE_ENV=local jest --config jest-e2e.json --ci --forceExit",
48
48
  "test:watch": "NODE_ENV=local jest --watch",
49
49
  "prepack": "npm run prestart:prod",
50
- "prepare": "husky install",
51
50
  "prepublishOnly": "npm run lint && npm run test:ci",
52
51
  "preversion": "npm run lint",
53
52
  "watch": "npm-watch"
@@ -83,7 +82,7 @@
83
82
  "class-transformer": "0.5.1",
84
83
  "class-validator": "0.14.1",
85
84
  "compression": "1.7.4",
86
- "cookie-parser": "1.4.6",
85
+ "cookie-parser": "1.4.7",
87
86
  "ejs": "3.1.10",
88
87
  "graphql": "16.9.0",
89
88
  "graphql-query-complexity": "1.0.0",
@@ -91,7 +90,7 @@
91
90
  "graphql-upload": "15.0.2",
92
91
  "js-sha256": "0.11.0",
93
92
  "json-to-graphql-query": "2.3.0",
94
- "light-my-request": "6.0.0",
93
+ "light-my-request": "6.1.0",
95
94
  "lodash": "4.17.21",
96
95
  "mongodb": "6.9.0",
97
96
  "mongoose": "7.8.2",
@@ -115,16 +114,16 @@
115
114
  "@nestjs/schematics": "10.1.4",
116
115
  "@nestjs/testing": "10.4.4",
117
116
  "@swc/cli": "0.4.0",
118
- "@swc/core": "1.7.28",
117
+ "@swc/core": "1.7.35",
119
118
  "@swc/jest": "0.2.36",
120
119
  "@types/compression": "1.7.5",
121
120
  "@types/cookie-parser": "1.4.7",
122
121
  "@types/ejs": "3.1.5",
123
122
  "@types/express": "4.17.21",
124
123
  "@types/jest": "29.5.13",
125
- "@types/lodash": "4.17.9",
124
+ "@types/lodash": "4.17.10",
126
125
  "@types/multer": "1.4.12",
127
- "@types/node": "20.16.9",
126
+ "@types/node": "20.16.11",
128
127
  "@types/nodemailer": "6.4.16",
129
128
  "@types/passport": "1.0.16",
130
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
  */
@@ -79,15 +79,6 @@ export class UserResolver {
79
79
  return await this.userService.getVerifiedState(token);
80
80
  }
81
81
 
82
- /**
83
- * Request new password for user with email
84
- */
85
- @Roles(RoleEnum.S_EVERYONE)
86
- @Query(() => Boolean, { description: 'Request new password for user with email' })
87
- async requestPasswordResetMail(@Args('email') email: string): Promise<boolean> {
88
- return !!(await this.userService.sendPasswordResetMail(email));
89
- }
90
-
91
82
  // ===========================================================================
92
83
  // Mutations
93
84
  // ===========================================================================
@@ -128,6 +119,15 @@ export class UserResolver {
128
119
  return !!(await this.userService.resetPassword(token, password));
129
120
  }
130
121
 
122
+ /**
123
+ * Request new password for user with email
124
+ */
125
+ @Roles(RoleEnum.S_EVERYONE)
126
+ @Mutation(() => Boolean, { description: 'Request new password for user with email' })
127
+ async requestPasswordResetMail(@Args('email') email: string): Promise<boolean> {
128
+ return !!(await this.userService.sendPasswordResetMail(email));
129
+ }
130
+
131
131
  /**
132
132
  * Update existing user
133
133
  */
@@ -509,6 +509,13 @@ export class TestHelper {
509
509
  }
510
510
  }
511
511
 
512
+ // Process REST payload
513
+ if (attachments && requestConfig.payload) {
514
+ for (const [key, value] of Object.entries(requestConfig.payload)) {
515
+ request.field(key, value);
516
+ }
517
+ }
518
+
512
519
  // Response
513
520
  if (log) {
514
521
  console.info(requestConfig);
@@ -580,8 +587,14 @@ export class TestHelper {
580
587
  if (logError && response.statusCode !== statusCode && response.statusCode >= 400) {
581
588
  if (response && response.error && response.error.text) {
582
589
  const errors = JSON.parse(response.error.text).errors;
583
- for (const error of errors) {
584
- console.error(util.inspect(error, false, null, true));
590
+ if (!errors) {
591
+ console.error(util.inspect(response.error.text, false, null, true));
592
+ } else if (Array.isArray(errors)) {
593
+ for (const error of errors) {
594
+ console.error(util.inspect(error, false, null, true));
595
+ }
596
+ } else {
597
+ console.error(util.inspect(errors, false, null, true));
585
598
  }
586
599
  }
587
600
  }