Socket
Socket
Sign inDemoInstall

middy

Package Overview
Dependencies
Maintainers
8
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy - npm Package Compare versions

Comparing version 0.25.1 to 0.26.0

6

middlewares.d.ts

@@ -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>;

8

package.json
{
"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')

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc