npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@greghearn/accept-message-middyware

v2.0.0

Published

Middy middleware module used to validate message event data via json schema related syntax

Downloads

11

Readme

nodejs-toolbelt package accept-message-middyware for aws lambda functions

This module is a aws lambda event validation middleware wrapper providing a way for applying a schema to validate an incoming message leaving the developer to concentrate on implementing their main handlers business logic requirements. If the schema can validate the message then no error response message is populated at the middleware level and the handler continues as normal. If the schema cant validate the message then this middleware handles the error and adds the error message to the middleware error chain propagated to all the other middlewares if others exist and they have a chance to update or replace the response as needed. Finally at the end of the sequence, the response is returned to the user.

This module depends on the use of ajv under the hood for schema related validation & the middy framework for the middleware engine. Install dependancy framework middy for wrapping your handler in middy.

Getting started

npm install --save @greghearn/accept-message-middyware

Options

All Options are optional, therefore this middleware could be used just for schema validation and/or could be used for parsing the incoming message event for object notation usage.

  • schema (optional) default = {} A valid ajv schema object used to test the incoming event for validity
  • debug (optional) default = false A boolean value used to output and error messages from the ajv schema tests. Debugging currently sent to default console.

Usage

const acceptMessageMiddyware = require('@greghearn/accept-message-middyware')

*** EXAMPLE PAYLOAD ***
// example of an incoming event message payload
{
  "httpMethod": "POST",
  "headers": {
    "Content-Type": "application/json",
  },
  "body": "{\"merchant_id\":\"6SSW7HV8K2ST5\",\"type\":\"inventory.count.updated\",\"event_id\":\"df5f3813-a913-45a1-94e9-fdc3f7d5e3b6\"}",
}

*** YOUR CODE ***
/**
 * Setup a schema relating to your incoming data for validating.
 * All we are doing here is saying that the body property must 
 * have 3 required fields in the payload and a regular expression 
 * is to be matched on the `type` properties value. If the
 * message payloads matches this then we have a valid message.
 */
const schema = {
  required: ['body'],
  properties: {
    body: {
      type: 'object',
      required: ['merchant_id', 'type', 'event_id'],
      properties: {
        type: {
          regexp: '/^inventory\\.count\\.updated$/i'
        }
      }
    }
  }
}
/**
 * applying this schema when the above example payload message 
 * comes in will yield a successful result.
 */
module.exports.handler = middy((event, context, callback) => { 
  // prints "{\"merchant_id\":\"6SSW7HV8K2ST5\",\"type\":\"inventory.count.updated\",\"event_id\":\"df5f3813-a913-45a1-94e9-fdc3f7d5e3b6\"}"
  console.log(event.body)

}).use(acceptMessageMiddyware({ 
  schema: schema,
  debug: false
}))

License

MIT