@lenne.tech/nest-server 11.4.2 → 11.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": "11.4.
|
|
3
|
+
"version": "11.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",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ArgumentMetadata, BadRequestException, Injectable, PipeTransform } from '@nestjs/common';
|
|
2
2
|
import { plainToInstance } from 'class-transformer';
|
|
3
3
|
import { validate, ValidationError } from 'class-validator';
|
|
4
|
+
import { inspect } from 'util';
|
|
4
5
|
|
|
5
6
|
import { isBasicType } from '../helpers/input.helper';
|
|
6
7
|
|
|
@@ -20,7 +21,7 @@ export class MapAndValidatePipe implements PipeTransform {
|
|
|
20
21
|
type: metadata.type,
|
|
21
22
|
});
|
|
22
23
|
console.debug('Input value type:', typeof value);
|
|
23
|
-
console.debug('Input value:',
|
|
24
|
+
console.debug('Input value:', inspect(value, { colors: true, depth: 3 }));
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
if (!value || typeof value !== 'object' || !metatype || isBasicType(metatype)) {
|
|
@@ -44,7 +45,7 @@ export class MapAndValidatePipe implements PipeTransform {
|
|
|
44
45
|
}
|
|
45
46
|
value = plainToInstance(metatype, value);
|
|
46
47
|
if (DEBUG_VALIDATION) {
|
|
47
|
-
console.debug('Transformed value:',
|
|
48
|
+
console.debug('Transformed value:', inspect(value, { colors: true, depth: 3 }));
|
|
48
49
|
console.debug('Transformed value instance of:', value?.constructor?.name);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -80,6 +81,7 @@ export class MapAndValidatePipe implements PipeTransform {
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
const result = {};
|
|
84
|
+
const errorSummary: string[] = [];
|
|
83
85
|
|
|
84
86
|
const processErrors = (errorList: ValidationError[], parentKey = '') => {
|
|
85
87
|
errorList.forEach((e) => {
|
|
@@ -89,6 +91,11 @@ export class MapAndValidatePipe implements PipeTransform {
|
|
|
89
91
|
processErrors(e.children, key);
|
|
90
92
|
} else {
|
|
91
93
|
result[key] = e.constraints;
|
|
94
|
+
// Build error summary without exposing values
|
|
95
|
+
if (e.constraints) {
|
|
96
|
+
const constraintTypes = Object.keys(e.constraints).join(', ');
|
|
97
|
+
errorSummary.push(`${key} (${constraintTypes})`);
|
|
98
|
+
}
|
|
92
99
|
}
|
|
93
100
|
});
|
|
94
101
|
};
|
|
@@ -97,12 +104,30 @@ export class MapAndValidatePipe implements PipeTransform {
|
|
|
97
104
|
|
|
98
105
|
if (DEBUG_VALIDATION) {
|
|
99
106
|
console.debug('\nProcessed validation result:');
|
|
100
|
-
console.debug(
|
|
107
|
+
console.debug(inspect(result, { colors: true, depth: 5 }));
|
|
101
108
|
console.debug('Result is empty:', Object.keys(result).length === 0);
|
|
109
|
+
console.debug('Error summary:', errorSummary);
|
|
102
110
|
console.debug('=== End Debug ===\n');
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
|
|
113
|
+
// Create meaningful error message without exposing sensitive values
|
|
114
|
+
let errorMessage = 'Validation failed';
|
|
115
|
+
if (errorSummary.length > 0) {
|
|
116
|
+
const fieldCount = errorSummary.length;
|
|
117
|
+
const fieldWord = fieldCount === 1 ? 'field' : 'fields';
|
|
118
|
+
errorMessage = `Validation failed for ${fieldCount} ${fieldWord}: ${errorSummary.join('; ')}`;
|
|
119
|
+
} else if (errors.length > 0) {
|
|
120
|
+
// Handle case where there are validation errors but no constraints (nested errors only)
|
|
121
|
+
const topLevelProperties = errors.map((e) => e.property).join(', ');
|
|
122
|
+
errorMessage = `Validation failed for properties: ${topLevelProperties} (nested validation errors)`;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Throw with message and validation errors (backward compatible structure)
|
|
126
|
+
// Add message property to result object for better error messages
|
|
127
|
+
throw new BadRequestException({
|
|
128
|
+
message: errorMessage,
|
|
129
|
+
...result,
|
|
130
|
+
});
|
|
106
131
|
}
|
|
107
132
|
|
|
108
133
|
if (DEBUG_VALIDATION) {
|