@naturalcycles/backend-lib 8.0.2 → 8.0.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/dist/server/validation/validateMiddleware.js +1 -1
- package/dist/server/validation/validateRequest.js +1 -1
- package/dist/server/validation/zodValidateMiddleware.js +1 -1
- package/package.json +1 -1
- package/src/server/validation/validateMiddleware.ts +1 -1
- package/src/server/validation/validateRequest.ts +5 -1
- package/src/server/validation/zodValidateMiddleware.ts +1 -1
|
@@ -31,7 +31,7 @@ function validateObject(prop, schema, opt = {}) {
|
|
|
31
31
|
});
|
|
32
32
|
const reportPredicate = typeof opt.report === 'function' ? opt.report : () => opt.report;
|
|
33
33
|
return (req, _res, next) => {
|
|
34
|
-
const error = ajvSchema.getValidationError(req[prop]);
|
|
34
|
+
const error = ajvSchema.getValidationError(req[prop] || {});
|
|
35
35
|
if (error) {
|
|
36
36
|
const report = reportPredicate(error);
|
|
37
37
|
if (opt.redactPaths) {
|
|
@@ -42,7 +42,7 @@ class ValidateRequest {
|
|
|
42
42
|
return this.validate(req, 'headers', schema, options);
|
|
43
43
|
}
|
|
44
44
|
validate(req, reqProperty, schema, opt = {}) {
|
|
45
|
-
const { value, error } = (0, nodejs_lib_1.getValidationResult)(req[reqProperty], schema, `request ${reqProperty}`);
|
|
45
|
+
const { value, error } = (0, nodejs_lib_1.getValidationResult)(req[reqProperty] || {}, schema, `request ${reqProperty}`);
|
|
46
46
|
if (error) {
|
|
47
47
|
let report;
|
|
48
48
|
if (typeof opt.report === 'boolean') {
|
|
@@ -12,7 +12,7 @@ const REDACTED = 'REDACTED';
|
|
|
12
12
|
function zodReqValidate(prop, schema, opt = {}) {
|
|
13
13
|
const reportPredicate = typeof opt.report === 'function' ? opt.report : () => opt.report;
|
|
14
14
|
return (req, _res, next) => {
|
|
15
|
-
const { error } = (0, js_lib_1.zSafeValidate)(req[prop], schema);
|
|
15
|
+
const { error } = (0, js_lib_1.zSafeValidate)(req[prop] || {}, schema);
|
|
16
16
|
if (!error) {
|
|
17
17
|
return next();
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -52,7 +52,7 @@ function validateObject(
|
|
|
52
52
|
typeof opt.report === 'function' ? opt.report : () => opt.report as boolean | undefined
|
|
53
53
|
|
|
54
54
|
return (req, _res, next) => {
|
|
55
|
-
const error = ajvSchema.getValidationError(req[prop])
|
|
55
|
+
const error = ajvSchema.getValidationError(req[prop] || {})
|
|
56
56
|
if (error) {
|
|
57
57
|
const report = reportPredicate(error)
|
|
58
58
|
|
|
@@ -89,7 +89,11 @@ class ValidateRequest {
|
|
|
89
89
|
schema: AnySchema<T>,
|
|
90
90
|
opt: ReqValidationOptions<JoiValidationError> = {},
|
|
91
91
|
): T {
|
|
92
|
-
const { value, error } = getValidationResult(
|
|
92
|
+
const { value, error } = getValidationResult(
|
|
93
|
+
req[reqProperty] || {},
|
|
94
|
+
schema,
|
|
95
|
+
`request ${reqProperty}`,
|
|
96
|
+
)
|
|
93
97
|
if (error) {
|
|
94
98
|
let report: boolean | undefined
|
|
95
99
|
if (typeof opt.report === 'boolean') {
|
|
@@ -19,7 +19,7 @@ export function zodReqValidate(
|
|
|
19
19
|
typeof opt.report === 'function' ? opt.report : () => opt.report as boolean | undefined
|
|
20
20
|
|
|
21
21
|
return (req, _res, next) => {
|
|
22
|
-
const { error } = zSafeValidate(req[prop], schema)
|
|
22
|
+
const { error } = zSafeValidate(req[prop] || {}, schema)
|
|
23
23
|
if (!error) {
|
|
24
24
|
return next()
|
|
25
25
|
}
|