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

accountdown-parser

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accountdown-parser

Facilitates account creation and user input validation using accountdown and json-schema

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

accountdown-parser

Account creation and user input validation for accountdown using json-schema. Primary usage is on the server.

example

create an accountdown-parser instance and define a json-schema

  var validator = require('is-my-json-valid');
  var validate = validator({
    required: true,
    type: 'object',
    properties: {
      login: {
        required: false,
        type: 'object',
        properties: {
          basic: {
            required: true,
            type: 'object',
            properties: {
              uuid: {
                required: true,
                type: 'string'
              },
              password: {
                required: true,
                type: 'string'
              }
            }
          }

        },
      value: {
        required: true,
        type: 'object',
        properties: {
          key: {
            required: true,
            type: 'string'
          },
          admin: {
            required: false,
            type: 'boolean'
          },
          color: {
            required: false,
            type: 'string'
          },
          username: {
            required: false,
            type: 'string'
          },
          email: {
            required: false,
            type: 'string'
          }
        }
      }

      }
    }
  }, {
    verbose: true
  });
  opts = {
    validate: validate,
    format: function (body) {
      body.value.admin = !!(body.value.admin);
      if (body.value.key && body.login) {
        body.login.basic.uuid = body.value.key;
      }
      return body;
    },
    updateLoginCreds: function (account) {
      return account.hasOwnProperty('login');
    }

methods

var p = accountdown-parser(accountdown, opts)

Return a parser instance p given an accountdown instance a.

Set opts.validate as an instance of is-my-json-valid to define the schema that will be validated for each user instance.

Set an optional opts.format to define how client-side requests should be parsed.

Another optional, but useful, opts.updateLoginCreds function defines whether the client's input is updating the login creds, which will require deletion and re-creation of the account when it returns true. Otherwise, only the account's value will be updated.

p.create(req, res, callback)

req, res: Parses the req and res objects using the body's body/any module, along with a querystring, and creates an account

Internally, all accounts are created with the key generated from uuid, version 1.

callback(err, account) fires with any errors or an account containing the account values.

p.update(req, res, callback)

The same as p.create except the function opts.updateLoginCreds is checked to determine whether to delete and recreate the accounts (when opts.updateLoginCreds exists and returns true), otherwise the new accounts values are put into the new account.

install

With npm do:

npm install accountdown-parser

Keywords

FAQs

Package last updated on 23 Jun 2015

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