Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@keboola/middy-event-validator

Package Overview
Dependencies
Maintainers
5
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@keboola/middy-event-validator

Event validation middleware for Middy

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
5
Weekly downloads
 
Created
Source

Event Validation Middleware for Middy

Build Status

Joi powered event validation middleware for Middy.

The middleware integrates Joi validation library to validate AWS Lambda events triggered by API Gateway.

Failed validations throw error of http-errors instance with status code 422.

Usage

import middy from 'middy';
import eventValidator from '@keboola/middy-event-validator';

export const handler = middy(() => {
  // ...
});

handler
  .use(eventValidator({
    path: {
      id: Joi.string().required()
    },
    body: {
      size: Joi.number().integer()
    },
    pagination: true
  }));

The configuration accepts following options:

  • headers - validation of HTTP headers
  • body - validation of HTTP body in JSON format
  • path - validation of path parameters (shortcut for API Gateway's pathParameters)
  • query - validation of query string (shortcut for API Gateway's queryStringParameters)
  • pagination: true - shortcut for two query string parameters offset and limit validated as numbers.
    • Default and maximum for limit is 1000. It can be changed by a definition: pagination: { max: 10 }

The module also offers a set of validation shortcuts using class Validation:

import middy from 'middy';
import eventValidator, { Validation } from '@keboola/middy-event-validator';

handler
  .use(eventValidator({
    path: {
      id: Validation.string('id').required()
    }
  }));

List of available shortcuts:

  • getJoi() - returns Joi instance for custom validation
  • forbidden(param) - setting of the parameter is forbidden
  • boolean(param) - boolean value
  • string(param) - string. All string shortcuts promote trimming of trailing white spaces
  • stringMaxLength(param, length) - string with maximal length
  • integer(param)
  • object(param)
  • enum(param, values)
  • array(param)
  • arrayOfStrings(param)

All shortcuts create optional parameters, for required parameters add .required().

FAQs

Package last updated on 29 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc