@middy/http-json-body-parser 2.5.4 → 3.0.0-alpha.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -53,13 +53,16 @@ npm install --save @middy/http-json-body-parser
53
53
 
54
54
  ```javascript
55
55
  import middy from '@middy/core'
56
+ import httpHeaderNormalizer from '@middy/http-header-normalizer'
56
57
  import httpJsonBodyParser from '@middy/http-json-body-parser'
57
58
 
58
59
  const handler = middy((event, context) => {
59
60
  return {}
60
61
  })
61
62
 
62
- handler.use(httpJsonBodyParser())
63
+ handler
64
+ .use(httpHeaderNormalizer())
65
+ .use(httpJsonBodyParser())
63
66
 
64
67
  // invokes the handler
65
68
  const event = {
@@ -86,7 +89,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
86
89
 
87
90
  ## License
88
91
 
89
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
92
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
90
93
 
91
94
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
92
95
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@middy/http-json-body-parser",
3
- "version": "2.5.4",
3
+ "version": "3.0.0-alpha.0",
4
4
  "description": "Http JSON body parser middleware for the middy framework",
5
- "type": "commonjs",
5
+ "type": "module",
6
6
  "engines": {
7
- "node": ">=12"
7
+ "node": ">=14"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "index.js",
13
+ "exports": "./index.js",
14
14
  "types": "index.d.ts",
15
15
  "files": [
16
16
  "index.d.ts"
@@ -48,11 +48,10 @@
48
48
  },
49
49
  "homepage": "https://github.com/middyjs/middy#readme",
50
50
  "dependencies": {
51
- "@middy/util": "^2.5.4"
51
+ "@middy/util": "^3.0.0-alpha.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@middy/core": "^2.5.4",
55
- "http-errors": "^1.8.0"
54
+ "@middy/core": "^3.0.0-alpha.0"
56
55
  },
57
- "gitHead": "a4134a579c757a9fdfed3006877ba2c0ec8a2cfa"
56
+ "gitHead": "c533f62841c8a39d061d7b94f30ba178f002c8db"
58
57
  }
package/index.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- const mimePattern = /^application\/(.+\+)?json(;.*)?$/;
4
- const defaults = {
5
- reviver: undefined
6
- };
7
-
8
- const httpJsonBodyParserMiddleware = (opts = {}) => {
9
- const options = { ...defaults,
10
- ...opts
11
- };
12
-
13
- const httpJsonBodyParserMiddlewareBefore = async request => {
14
- var _headers$ContentType;
15
-
16
- const {
17
- headers,
18
- body
19
- } = request.event;
20
- const contentTypeHeader = (_headers$ContentType = headers === null || headers === void 0 ? void 0 : headers['Content-Type']) !== null && _headers$ContentType !== void 0 ? _headers$ContentType : headers === null || headers === void 0 ? void 0 : headers['content-type'];
21
-
22
- if (mimePattern.test(contentTypeHeader)) {
23
- try {
24
- const data = request.event.isBase64Encoded ? Buffer.from(body, 'base64').toString() : body;
25
- request.event.rawBody = body;
26
- request.event.body = JSON.parse(data, options.reviver);
27
- } catch (err) {
28
- const {
29
- createError
30
- } = require('@middy/util'); // UnprocessableEntity
31
-
32
-
33
- throw createError(422, 'Content type defined as JSON but an invalid JSON was provided');
34
- }
35
- }
36
- };
37
-
38
- return {
39
- before: httpJsonBodyParserMiddlewareBefore
40
- };
41
- };
42
-
43
- module.exports = httpJsonBodyParserMiddleware;