Socket
Book a DemoInstallSign in
Socket

hapi-couchdb-account-api

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-couchdb-account-api

Account REST API backed by CouchDB

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

hapi-couchdb-account-api

Account REST API backed by CouchDB

Build Status Coverage Status Dependency Status devDependency Status

RESTful API

See current work in progress here http://docs.accountrestapi.apiary.io/ Comment / send PRs for apiary.apib.

Have a glance (might be outdated, check links above)

# sign in, check session, sign out
PUT /session
GET /session
DELETE /session

# sign up, get / update / destroy account
PUT /session/account
GET /session/account
PATCH /session/account
DELETE /session/account

# get / update profile
GET /session/account/profile
PATCH /session/account/profile

# requests (e.g. password resets / username reminder, user account confirmation)
POST /requests
GET /requests # admins only
GET /requests/{id}
DELETE /requests/{id}

# admins only: manage accounts
POST /accounts
GET /accounts
GET /accounts/{username}
PATCH /accounts/{username}
DELETE /accounts/{username}

Plugin API

var Hapi = require('hapi')
var hapiAccount = require('hapi-couchdb-account-api')

var options = {
  couchdb: {
    url: 'http://localhost:5984',
    admin: {
      username: 'admin',
      password: 'secret'
    }
  },
  confirmation: 'auto',
  notifications: {
    service: 'gmail',
    auth: {
      user: 'gmail.user@gmail.com',
      pass: 'userpass'
    },
    templates: {
      passwordreset: 'Dear {account.username},\n\nyou can reset your password at:\n{server.info.uri}/#resetPassword/{request.token}',
      confirmation: 'Dear {account.profile.name},\n\nyour confirmation code is {token}'
    }
  },
  schema: {
    username: {
      minlength: 3
    },
    password: {
      minlength: 6
    },
    profile: {
      required: ['name'],
      properties: {
        name: {
          type: 'string',
          minlength: 3
        }
      }
    }
  },
  requests: {
    upgrade: function (request, reply) {
      var server = request.connection.server
      var user = request.auth.credentials

      var promise = server.app.users.update({
        id: user.id,
        plan: request.params.plan
      })

      reply(promise)
    }
  }
})

server.register({register: hapiAccount}, options, function (error) {
  // server is ready
});

server.connection({
  port: 8000
});

server.start(function () {
  console.log('Server running at %s', server.info.uri);
});

hapi-couchdb-account-api also adds a server.app.account.admin API, which is the same as the account admin client API.

options.couchdb

Location & admin credentials for CouchDB, either set as object or as string.

Example 1

couchdb: {
  url: 'http://localhost:5984',
  admin: {
    username: 'admin',
    password: 'secret'
  }
}

Example 2

couchdb: 'http://admin:secret@localhost@5984'

options.confirmation

Account confirmation strategy.

  • "auto": accounts get confirmed automatically
  • "email": user receives email with confirmation token / url
  • "invite-only": user receives email with invitation token, that needs to be passed on sign up
  • false: Admins confirm manually, or custom logic / 3rd-party plugins

options.notifications

Settings to send notifications to users like password resets and account confirmations. notifications.service and notifications.auth should be compatible with nodemailer

options.notifications.templates are templates for notifications being sent out by the server.

options.schema

A JSON schema to validate account properties against.

options.requests

Handlers for custom requests

Testing

Local setup

git clone git@github.com:hoodiehq/hapi-couchdb-account-api.git
cd hapi-couchdb-account-api
npm install

Run all tests and code style checks

npm test

Run all tests on file change

npm run test:watch

License

Apache-2.0

Keywords

hapi

FAQs

Package last updated on 28 Oct 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.