Comparing version 0.25.1 to 0.26.0
@@ -49,2 +49,6 @@ import { SSM } from 'aws-sdk' | ||
interface IJsonBodyParserOptions { | ||
reviver?: (key: string, value: any) => any | ||
} | ||
interface ISecretsManagerOptions { | ||
@@ -122,3 +126,3 @@ cache?: boolean; | ||
declare const httpPartialResponse: middy.Middleware<IHTTPPartialResponseOptions>; | ||
declare const jsonBodyParser: middy.Middleware<never>; | ||
declare const jsonBodyParser: middy.Middleware<IJsonBodyParserOptions>; | ||
declare const multipartFormDataParser: middy.Middleware<never>; | ||
@@ -125,0 +129,0 @@ declare const s3KeyNormalizer: middy.Middleware<never>; |
{ | ||
"name": "middy", | ||
"version": "0.25.1", | ||
"version": "0.26.0", | ||
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda", | ||
@@ -59,6 +59,6 @@ "main": "./index.js", | ||
"husky": "^1.1.0", | ||
"jest": "^24.1.0", | ||
"jsdoc": "^3.5.5", | ||
"jest": "^24.8.0", | ||
"jsdoc": "^3.6.2", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"marked": "^0.6.0", | ||
"marked": "^0.6.2", | ||
"regenerator-runtime": "^0.13.1", | ||
@@ -65,0 +65,0 @@ "typescript": "^3.3.3", |
@@ -24,2 +24,23 @@ const middy = require('../../middy') | ||
test('It should use a reviver when parsing a JSON request', () => { | ||
const handler = middy((event, context, cb) => { | ||
cb(null, event.body) // propagates the body as a response | ||
}) | ||
const reviver = _ => _ | ||
handler.use(jsonBodyParser({ reviver })) | ||
// invokes the handler | ||
const event = { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ foo: 'bar' }) | ||
} | ||
const parse = jest.spyOn(JSON, 'parse') | ||
handler(event, {}, (_, body) => { | ||
expect(parse).toHaveBeenCalledWith(expect.anything(), reviver) | ||
}) | ||
parse.mockRestore() | ||
}) | ||
test('It should handle invalid JSON as an UnprocessableEntity', () => { | ||
@@ -26,0 +47,0 @@ const handler = middy((event, context, cb) => { |
const createError = require('http-errors') | ||
const contentTypeLib = require('content-type') | ||
module.exports = () => ({ | ||
module.exports = (opts) => ({ | ||
before: (handler, next) => { | ||
opts = opts || {} | ||
const { headers } = handler.event | ||
@@ -15,3 +16,3 @@ if (!headers) { | ||
try { | ||
handler.event.body = JSON.parse(handler.event.body) | ||
handler.event.body = JSON.parse(handler.event.body, opts.reviver) | ||
} catch (err) { | ||
@@ -18,0 +19,0 @@ throw new createError.UnprocessableEntity('Content type defined as JSON but an invalid JSON was provided') |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181810
4577