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 🙏

© 2024 – Pkg Stats / Ryan Hefner

accountdown

v4.1.0

Published

persistent accounts backed to leveldb

Downloads

24

Readme

accountdown

manage accounts with leveldb

build status

example

create

To create a user, we can just do:

var accountdown = require('accountdown');
var level = require('level');
var db = level('./users.db');

var users = accountdown(db, {
    login: { basic: require('accountdown-basic') }
});

var opts = {
    login: { basic: { username: 'substack', password: 'beep boop' } },
    value: { bio: 'beep boop' }
};
users.create('substack', opts, function (err) {
    if (err) return console.error(err);
});

The string we gave to users.create() need not necessarily match the username credential. You might want to use a uid integer for example. In either case you will get implicitly encforced unique names because if a username already exists the users.create() call will fail even if the id is available and likewise if an id is unavailable but a username is available.

verify

To verify a credential (in this case, using accountdown-basic):

var accountdown = require('accountdown');
var level = require('level');
var db = level('./users.db');

var users = accountdown(db, {
    login: { basic: require('accountdown-basic') }
});

var creds = { username: 'substack', password: 'beep boop' };
users.verify('basic', creds, function (err, ok, id) {
    if (err) return console.error(err)
    console.log('ok=', ok);
    console.log('id=', id);
});

methods

var accountdown = require('accountdown')

var users = accountdown(db, opts)

Create a new account instance users given a leveldb database handle db and some options opts.

opts can be:

  • opts.login - map of type names to login plugin functions
  • opts.valueEncoding - value encoding to use, 'json' by default

users.create(id, opts, cb)

Create a user by an id.

users.verify(type, creds, cb)

Challenge credentials creds for a login type.

cb(err, ok, id) fires with an error or the boolean verify status ok - true for challenge success and false for challenge failure. On success, the id associated with challenge credentials, cred is defined.

users.list()

Return a readable object stream of row objects with row.key set to the user id of each user in the account system.

users.get(id, cb)

Get the value for a username by id as cb(err, value).

users.put(id, value, cb)

Put a value for a username id. The username id must already exist.

cb(err) fires with any errors.

users.remove(id, cb)

Remote an account by id, including all login information for that user id.

cb(err) fires with any errors.

users.register(type, plugin)

Register a login plugin at a string name type.

users.addLogin(id, type, creds, cb)

Add a login for id of type using the credentials creds.

cb(err) fires with any errors.

var s = users.listLogin(id)

Return a readable object stream s of rows with row.key set to each string login type present for the user at id. For example:

{ key: 'basic' }
{ key: 'rsa' }

users.removeLogin(id, type, cb)

Remove a login for id by its type.

cb(err) fires with any errors.

login plugins

Login plugins such as accountdown-basic should export a single function that will be created with db and prefix arguments and should return an object with .verify() and .create() functions:

module.exports = function (db, prefix) {
    return {
        verify: function (creds, cb) {
            // calls cb(err, success, id)
        },
        create: function (id, creds) {
            // returns an array of batch rows
        }
    };
};

plugin.verify(creds, cb)

Check whether creds are valid login credentials. cb(err, success, id) fires with any errors, the success as a boolean, and the user id.

plugin.create(id, creds)

Return an array of rows to batch insert if and only if all the keys do not already exist using level-create-batch.

install

With npm do:

npm install accountdown

license

MIT