@naturalcycles/backend-lib 9.44.0 → 9.44.1

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.
@@ -18,6 +18,11 @@ export interface BackendRequest extends Request {
18
18
  * Only used for request logging purposes.
19
19
  */
20
20
  userId?: string;
21
+ /**
22
+ * It's set to unknown (instead of `any`) to prevent implicit use of any
23
+ * in unexpected places.
24
+ */
25
+ body: unknown;
21
26
  /**
22
27
  * Raw Buffer of the `req.body`, before it's stringified and json-parsed.
23
28
  * Useful for when something mutates `req.body` json (e.g j validation), and you
@@ -45,7 +45,7 @@ class AjvValidateRequest {
45
45
  });
46
46
  }
47
47
  validate(req, reqProperty, schema, getOriginalInput, opt = {}) {
48
- const input = req[reqProperty] || {};
48
+ const input = (req[reqProperty] || {});
49
49
  const { coerceTypes, mutateInput } = opt;
50
50
  const ajv = coerceTypes ? getCoercingAjv() : undefined;
51
51
  const ajvSchema = AjvSchema.create(schema, { ajv });
@@ -23,7 +23,7 @@ class ValidateRequest {
23
23
  return this.validate(req, 'headers', schema, opt);
24
24
  }
25
25
  validate(req, reqProperty, schema, opt = {}) {
26
- const originalProperty = req[reqProperty] || {};
26
+ const originalProperty = (req[reqProperty] || {});
27
27
  // Joi does not mutate the input
28
28
  const [error, value] = getValidationResult(originalProperty, schema, `request.${reqProperty}`);
29
29
  if (error) {
@@ -23,7 +23,7 @@ class ZodValidateRequest {
23
23
  return this.validate(req, 'headers', schema, opt);
24
24
  }
25
25
  validate(req, reqProperty, schema, opt = {}) {
26
- const originalProperty = req[reqProperty] || {};
26
+ const originalProperty = (req[reqProperty] || {});
27
27
  // Zod does not mutate the input
28
28
  const [error, data] = zSafeValidate(originalProperty, schema);
29
29
  if (error) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.44.0",
4
+ "version": "9.44.1",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -29,7 +29,7 @@
29
29
  "@sentry/node": "^10",
30
30
  "@types/ejs": "^3",
31
31
  "fastify": "^5",
32
- "@naturalcycles/dev-lib": "18.4.2"
32
+ "@naturalcycles/dev-lib": "20.12.11"
33
33
  },
34
34
  "exports": {
35
35
  ".": "./dist/index.js",
@@ -20,6 +20,13 @@ export interface BackendRequest extends Request {
20
20
  * Only used for request logging purposes.
21
21
  */
22
22
  userId?: string
23
+
24
+ /**
25
+ * It's set to unknown (instead of `any`) to prevent implicit use of any
26
+ * in unexpected places.
27
+ */
28
+ body: unknown
29
+
23
30
  /**
24
31
  * Raw Buffer of the `req.body`, before it's stringified and json-parsed.
25
32
  * Useful for when something mutates `req.body` json (e.g j validation), and you
@@ -84,7 +84,7 @@ class AjvValidateRequest {
84
84
  getOriginalInput?: () => IN,
85
85
  opt: ReqValidationOptions<AjvValidationError> = {},
86
86
  ): OUT {
87
- const input: IN = req[reqProperty] || {}
87
+ const input = (req[reqProperty] || {}) as IN
88
88
 
89
89
  const { coerceTypes, mutateInput } = opt
90
90
  const ajv = coerceTypes ? getCoercingAjv() : undefined
@@ -51,7 +51,7 @@ class ValidateRequest {
51
51
  schema: AnySchema<T>,
52
52
  opt: ReqValidationOptions<JoiValidationError> = {},
53
53
  ): T {
54
- const originalProperty = req[reqProperty] || {}
54
+ const originalProperty = (req[reqProperty] || {}) as T
55
55
 
56
56
  // Joi does not mutate the input
57
57
  const [error, value] = getValidationResult(originalProperty, schema, `request.${reqProperty}`)
@@ -50,7 +50,7 @@ class ZodValidateRequest {
50
50
  schema: ZodType<T>,
51
51
  opt: ReqValidationOptions<ZodValidationError> = {},
52
52
  ): T {
53
- const originalProperty = req[reqProperty] || {}
53
+ const originalProperty = (req[reqProperty] || {}) as T
54
54
 
55
55
  // Zod does not mutate the input
56
56
  const [error, data] = zSafeValidate(