@openaddresses/batch-schema 1.0.1 → 2.3.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/.eslintrc.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "extends": "eslint:recommended",
3
3
  "root": true,
4
- "parser": "@babel/eslint-parser",
5
- "parserOptions": {
6
- "ecmaVersion": 2018,
7
- "babelOptions": {
8
- "configFile": "./.babelrc"
9
- }
10
- },
11
4
  "env": {
12
- "node": true,
13
- "es6": true
5
+ "node": true
6
+ },
7
+ "globals": {
8
+ "Map": true
9
+ },
10
+ "parserOptions": {
11
+ "ecmaVersion": 13
14
12
  },
15
- "plugins": [ "node", "@babel" ],
13
+ "plugins": [ "node" ],
16
14
  "rules": {
17
15
  "no-console": 0,
18
16
  "arrow-parens": [ "error", "always" ],
@@ -0,0 +1,29 @@
1
+ name: Test
2
+
3
+ on:
4
+ pull_request:
5
+ types:
6
+ - opened
7
+ - synchronize
8
+ - reopened
9
+ - ready_for_review
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ if: github.event.pull_request.draft == false
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ with:
18
+ ref: ${{ github.event.pull_request.head.sha }}
19
+
20
+ - uses: actions/setup-node@v2
21
+ with:
22
+ node-version: '16'
23
+
24
+ - run: npm install
25
+
26
+ - run: npm run lint
27
+
28
+ - run: npm test
29
+
package/CHANGELOG.md CHANGED
@@ -10,6 +10,23 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v2.3.0
14
+
15
+ - :rocket: Remove babel in favour of ESLint's new ECMA13 support
16
+
17
+ ### v2.2.0
18
+
19
+ - :tada: Add support for errors with `status` set from external libraries (IE OpenAddresses/tilebase)
20
+
21
+ ### v2.1.0
22
+
23
+ - :tada: Add more detailed schema error messages
24
+
25
+ ### v2.0.0
26
+
27
+ - :tada: Add support for populating `default` keys in schema
28
+ - :arrow_up: General Dep Update
29
+
13
30
  ### v1.0.1
14
31
 
15
32
  - :bug: Check for schema in library before looking for schema in calling project
package/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  module.exports = {
2
4
  Schema: require('./lib/schema'),
3
5
  Err: require('./lib/error')
package/lib/error.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  /**
2
4
  * @class
3
5
  */
@@ -15,12 +17,21 @@ class PublicError {
15
17
 
16
18
  static respond(err, res, messages = []) {
17
19
  if (err instanceof PublicError) {
18
-
19
20
  res.status(err.status).json({
20
21
  status: err.status,
21
22
  message: err.safe,
22
23
  messages: messages
23
24
  });
25
+
26
+ // Duplicate Express supported Error extensions
27
+ } else if (err instanceof Error && (err.status || err.statusCode)) {
28
+ res.status(err.status).json({
29
+ status: err.status || err.statusCode,
30
+ message: err.message || 'Generic Error',
31
+ messages: messages
32
+ });
33
+
34
+ // Handle generic errors
24
35
  } else {
25
36
  console.error(err);
26
37
 
package/lib/schema.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  const { Validator } = require('express-json-validator-middleware');
2
4
  const $RefParser = require('json-schema-ref-parser');
3
5
  const path = require('path');
@@ -54,6 +56,8 @@ class Schemas {
54
56
  }
55
57
 
56
58
  this.validator = new Validator({
59
+ removeAdditional: true,
60
+ useDefaults: true,
57
61
  allErrors: true
58
62
  });
59
63
 
@@ -239,17 +243,12 @@ class Schemas {
239
243
  this.router.use((err, req, res, next) => {
240
244
  if (err instanceof ValidationError) {
241
245
  let errs = [];
242
-
243
246
  if (err.validationErrors.body) {
244
- errs = errs.concat(err.validationErrors.body.map((e) => {
245
- return { message: e.message };
246
- }));
247
+ errs = errs.concat(err.validationErrors.body);
247
248
  }
248
249
 
249
250
  if (err.validationErrors.query) {
250
- errs = errs.concat(err.validationErrors.query.map((e) => {
251
- return { message: e.message };
252
- }));
251
+ errs = errs.concat(err.validationErrors.query);
253
252
  }
254
253
 
255
254
  return Err.respond(