ah-validator-plugin

0.0.6 • Public • Published

ah-validator-plugin

Parameter validation middleware plugin for the actionhero.js API server built on Chris O'Hara's fantastic validator.js library and leaning on Sequelize's model validation definition/usage and validator extensions.

Installation

cd [actionhero-base-directory]
npm install ah-validator-plugin --save

Usage

Validators are either defined locally in the action definitions or globally in the api.config.validation configuration object.

Each key in the object will validate the values of matching keys from the connection.params object. The validation methods and usage match the Sequelize implementation at http://sequelizejs.com/docs/1.7.8/models#validations

Local definitions override global definitions for each key.

local example (inside an action definition)

inputs: {
    required: ['email', 'username'],
    optional: [],
},
validate: {
    'username' : {
      isAlpha : true,
    },
    'email' : {
      isEmail : true,
      notIn   : ['admin@ah.com']
    }
},

global example (sample config/validate.js file)

exports.default = {
  validate: function (api) {
    return {
      global: {
        'uuid' : {
          isUUID : 4
        }
      }
    }
  }
};

License

MIT

Package Sidebar

Install

npm i ah-validator-plugin

Weekly Downloads

1

Version

0.0.6

License

none

Last publish

Collaborators

  • dangerdespain