@middy/validator 2.5.1 → 2.5.5

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/README.md CHANGED
@@ -57,11 +57,13 @@ npm install --save @middy/validator
57
57
  to validate the output (`request.response`) of the Lambda handler.
58
58
  - `ajvOptions` (object) (optional): Options to pass to [ajv](https://ajv.js.org/docs/api.html#options)
59
59
  class constructor. Defaults are `{ strict: true, coerceTypes: 'array', allErrors: true, useDefaults: 'empty', messages: false, defaultLanguage: 'en' }`.
60
+ - `i18nEnabled` (boolean) (optional): Option to disable i18n default package. Defaults to `true`
60
61
 
61
62
  NOTES:
62
63
  - At least one of `inputSchema` or `outputSchema` is required.
63
64
  - **Important** Compiling schemas on the fly will cause a 50-100ms performance hit during cold start for simple JSON Schemas. Precompiling is highly recommended.
64
65
  - Default ajv plugins used: `ajv-i18n`, `ajv-formats`, `ajv-formats-draft2019`
66
+ - If you'd like to have the error details as part of the response, it will need to be handled separately. You can access them from `request.error.details`, the original response can be found at `request.error.response`.
65
67
 
66
68
  ## Sample usage
67
69
 
package/index.d.ts CHANGED
@@ -8,6 +8,7 @@ interface Options {
8
8
  ajvOptions?: Partial<AjvOptions>
9
9
  ajvInstance?: Ajv
10
10
  defaultLanguage?: string
11
+ i18nEnabled?: boolean
11
12
  }
12
13
 
13
14
  declare function validator (options?: Options): middy.MiddlewareObj
package/index.js CHANGED
@@ -29,7 +29,8 @@ const defaults = {
29
29
  outputSchema: undefined,
30
30
  ajvOptions: {},
31
31
  ajvInstance: undefined,
32
- defaultLanguage: 'en'
32
+ defaultLanguage: 'en',
33
+ i18nEnabled: true
33
34
  };
34
35
 
35
36
  const validatorMiddleware = (opts = {}) => {
@@ -38,7 +39,8 @@ const validatorMiddleware = (opts = {}) => {
38
39
  outputSchema,
39
40
  ajvOptions,
40
41
  ajvInstance,
41
- defaultLanguage
42
+ defaultLanguage,
43
+ i18nEnabled
42
44
  } = { ...defaults,
43
45
  ...opts
44
46
  };
@@ -53,8 +55,12 @@ const validatorMiddleware = (opts = {}) => {
53
55
  const error = createError(400, 'Event object failed validation');
54
56
  request.event.headers = { ...request.event.headers
55
57
  };
56
- const language = chooseLanguage(request.event, defaultLanguage);
57
- localize[language](inputSchema.errors);
58
+
59
+ if (i18nEnabled) {
60
+ const language = chooseLanguage(request.event, defaultLanguage);
61
+ localize[language](inputSchema.errors);
62
+ }
63
+
58
64
  error.details = inputSchema.errors;
59
65
  throw error;
60
66
  }
@@ -108,7 +114,6 @@ const languageNormalizationMap = {
108
114
  'pt-br': 'pt-BR',
109
115
  pt_BR: 'pt-BR',
110
116
  pt_br: 'pt-BR',
111
- zh: 'zh-TW',
112
117
  'zh-tw': 'zh-TW',
113
118
  zh_TW: 'zh-TW',
114
119
  zh_tw: 'zh-TW'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/validator",
3
- "version": "2.5.1",
3
+ "version": "2.5.5",
4
4
  "description": "Validator middleware for the middy framework",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -45,17 +45,17 @@
45
45
  },
46
46
  "homepage": "https://github.com/middyjs/middy#readme",
47
47
  "dependencies": {
48
- "@middy/util": "^2.5.1",
49
- "ajv": "8.6.2",
50
- "ajv-formats": "2.1.0",
51
- "ajv-formats-draft2019": "1.6.0",
52
- "ajv-i18n": "4.0.1"
48
+ "@middy/util": "^2.5.5",
49
+ "ajv": "8.6.3",
50
+ "ajv-formats": "2.1.1",
51
+ "ajv-formats-draft2019": "1.6.1",
52
+ "ajv-i18n": "4.1.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@middy/core": "^2.5.1",
55
+ "@middy/core": "^2.5.5",
56
56
  "@types/http-errors": "^1.8.1",
57
57
  "ajv-bsontype": "^1.0.7",
58
58
  "http-errors": "^1.8.0"
59
59
  },
60
- "gitHead": "df18e5eff7d73492a96a2ca4780a2eae45d1cedb"
60
+ "gitHead": "b84840ec8afd289f6decfd0d645be4899051792d"
61
61
  }