@naturalcycles/backend-lib 9.49.2 → 9.50.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.49.2",
4
+ "version": "9.50.0",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -46,7 +46,6 @@
46
46
  "./deploy/*.js": "./dist/deploy/*.js",
47
47
  "./express/*.js": "./dist/express/*.js",
48
48
  "./ajvValidateRequest": "./dist/validation/ajv/ajvValidateRequest.js",
49
- "./joiValidateRequest": "./dist/validation/joi/joiValidateRequest.js",
50
49
  "./zodValidateRequest": "./dist/validation/zod/zodValidateRequest.js",
51
50
  "./onFinished": "./dist/onFinished.js",
52
51
  "./testing": "./dist/testing/index.js"
@@ -1,21 +0,0 @@
1
- import type { AnySchema, JoiValidationError } from '@naturalcycles/nodejs-lib/joi';
2
- import type { BackendRequest } from '../../server/server.model.js';
3
- import { type ReqValidationOptions } from '../validateRequest.util.js';
4
- declare class ValidateRequest {
5
- body<T>(req: BackendRequest, schema: AnySchema<T>, opt?: ReqValidationOptions<JoiValidationError>): T;
6
- query<T>(req: BackendRequest, schema: AnySchema<T>, opt?: ReqValidationOptions<JoiValidationError>): T;
7
- params<T>(req: BackendRequest, schema: AnySchema<T>, opt?: ReqValidationOptions<JoiValidationError>): T;
8
- /**
9
- * Validates `req.headers` against the provided Joi schema.
10
- *
11
- * Note: as opposed to other methods, this method does not mutate `req.headers` in case of success,
12
- * i.e. schemas that cast values will not have any effect.
13
- *
14
- * If you wish to mutate `req.headers` with the validated value, use `keepOriginal: false` option.
15
- * Keep in mind that this will also remove all values that are not in the schema.
16
- */
17
- headers<T>(req: BackendRequest, schema: AnySchema<T>, opt?: ReqValidationOptions<JoiValidationError>): T;
18
- private validate;
19
- }
20
- export declare const validateRequest: ValidateRequest;
21
- export {};
@@ -1,41 +0,0 @@
1
- import { getValidationResult } from '@naturalcycles/nodejs-lib/joi';
2
- import { handleValidationError } from '../validateRequest.util.js';
3
- class ValidateRequest {
4
- body(req, schema, opt = {}) {
5
- return this.validate(req, 'body', schema, opt);
6
- }
7
- query(req, schema, opt = {}) {
8
- return this.validate(req, 'query', schema, opt);
9
- }
10
- params(req, schema, opt = {}) {
11
- return this.validate(req, 'params', schema, opt);
12
- }
13
- /**
14
- * Validates `req.headers` against the provided Joi schema.
15
- *
16
- * Note: as opposed to other methods, this method does not mutate `req.headers` in case of success,
17
- * i.e. schemas that cast values will not have any effect.
18
- *
19
- * If you wish to mutate `req.headers` with the validated value, use `keepOriginal: false` option.
20
- * Keep in mind that this will also remove all values that are not in the schema.
21
- */
22
- headers(req, schema, opt = {}) {
23
- return this.validate(req, 'headers', schema, opt);
24
- }
25
- validate(req, reqProperty, schema, opt = {}) {
26
- const originalProperty = (req[reqProperty] || {});
27
- // Joi does not mutate the input
28
- const [error, value] = getValidationResult(originalProperty, schema, `request.${reqProperty}`);
29
- if (error) {
30
- if (opt.redactPaths) {
31
- error.data.joiValidationErrorItems.length = 0; // clears the array
32
- delete error.data.annotation;
33
- }
34
- handleValidationError(error, originalProperty, opt);
35
- }
36
- // Kirill: decide to not do it, let's see
37
- // req[reqProperty] = value
38
- return value;
39
- }
40
- }
41
- export const validateRequest = new ValidateRequest();
@@ -1,75 +0,0 @@
1
- import type { AnySchema, JoiValidationError } from '@naturalcycles/nodejs-lib/joi'
2
- import { getValidationResult } from '@naturalcycles/nodejs-lib/joi'
3
- import type { BackendRequest } from '../../server/server.model.js'
4
- import { handleValidationError, type ReqValidationOptions } from '../validateRequest.util.js'
5
-
6
- class ValidateRequest {
7
- body<T>(
8
- req: BackendRequest,
9
- schema: AnySchema<T>,
10
- opt: ReqValidationOptions<JoiValidationError> = {},
11
- ): T {
12
- return this.validate(req, 'body', schema, opt)
13
- }
14
-
15
- query<T>(
16
- req: BackendRequest,
17
- schema: AnySchema<T>,
18
- opt: ReqValidationOptions<JoiValidationError> = {},
19
- ): T {
20
- return this.validate(req, 'query', schema, opt)
21
- }
22
-
23
- params<T>(
24
- req: BackendRequest,
25
- schema: AnySchema<T>,
26
- opt: ReqValidationOptions<JoiValidationError> = {},
27
- ): T {
28
- return this.validate(req, 'params', schema, opt)
29
- }
30
-
31
- /**
32
- * Validates `req.headers` against the provided Joi schema.
33
- *
34
- * Note: as opposed to other methods, this method does not mutate `req.headers` in case of success,
35
- * i.e. schemas that cast values will not have any effect.
36
- *
37
- * If you wish to mutate `req.headers` with the validated value, use `keepOriginal: false` option.
38
- * Keep in mind that this will also remove all values that are not in the schema.
39
- */
40
- headers<T>(
41
- req: BackendRequest,
42
- schema: AnySchema<T>,
43
- opt: ReqValidationOptions<JoiValidationError> = {},
44
- ): T {
45
- return this.validate(req, 'headers', schema, opt)
46
- }
47
-
48
- private validate<T>(
49
- req: BackendRequest,
50
- reqProperty: 'body' | 'params' | 'query' | 'headers',
51
- schema: AnySchema<T>,
52
- opt: ReqValidationOptions<JoiValidationError> = {},
53
- ): T {
54
- const originalProperty = (req[reqProperty] || {}) as T
55
-
56
- // Joi does not mutate the input
57
- const [error, value] = getValidationResult(originalProperty, schema, `request.${reqProperty}`)
58
-
59
- if (error) {
60
- if (opt.redactPaths) {
61
- error.data.joiValidationErrorItems.length = 0 // clears the array
62
- delete error.data.annotation
63
- }
64
-
65
- handleValidationError(error, originalProperty, opt)
66
- }
67
-
68
- // Kirill: decide to not do it, let's see
69
- // req[reqProperty] = value
70
-
71
- return value
72
- }
73
- }
74
-
75
- export const validateRequest = new ValidateRequest()