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

pouchdb-permissions

v0.0.1

Published

Easy permission management for PouchDB/CouchDB

Readme

pouchdb-permissions

This plugin enables you to easily manipulate the _security document of a database in PouchDB/CouchDB, on the fly and with a super flexible API.

IMPORTANT: Make sure that the instances which will use this plugin have the permissions required to manipulate the _security document. Learn more.

Every operation made by the plugin ensures that names and roles are deduplicated for the admins and the members keys in the _security document.

Instalation

# Using NPM
npm install pouchdb-permissions --save
#Using Yarn
yarn add pouchdb-permissions

Usage

import PouchDB from 'pouchdb'
import PoucDBPermissions from 'pouchdb-permissions'

PouchDB.plugin(PouchDBPermissions)

const db = new PouchDB('http://localhost:5984')

API

db.addAdmins(names, roles)

  • Arguments:
    • names: It can be a String, an Array of strings, an Object or null.
    • roles: It can be a String, an Array of strings or null.
  • Returns: A promise that resolves with the response body.
db.addAdmins('mike') // Add mike to admins.names

db.addAdmins(null, 'webmaster') // Add webmaster to admins.roles

db.addAdmins(
  ['john', 'jane'], // Add john and jane to admins.names
  ['finances', 'human_resources'] // Add finances and human_resources to admins.roles
)

db.addAdmins({
  names: 'mike', // Add mike to admins.names
  roles: ['finances', 'stock'] // Add finances and stock to admins.roles
})

db.addAdmins({
  roles: 'webamster' // Add webmaster to admins.roles
})

db.removeAdmins(names, roles)

  • Arguments:
    • names: It can be a String, an Array of strings, an Object or null.
    • roles: It can be a String, an Array of strings or null.
  • Returns: A promise that resolves with the response body.
db.removeAdmins('mike') // Remove mike from admins.names

db.removeAdmins(null, 'webmaster') // Remove webmaster from admins.roles

db.removeAdmins(
  ['john', 'jane'], // Remove john and jane from admins.names
  ['finances', 'human_resources'] // Remove finances and human_resources from admins.roles
)

db.removeAdmins({
  names: 'mike', // Remove mike from admins.names
  roles: ['finances', 'stock'] // Remove finances and stock from admins.roles
})

db.removeAdmins({
  roles: 'webamster' // Remove webmaster from admins.roles
})

db.setAdmins(names, roles)

This method completely replace the admins.names AND admins.roles lists.

  • Arguments:
    • names: It can be a String, an Array of strings, an Object or null.
    • roles: It can be a String, an Array of strings or null.
  • Returns: A promise that resolves with the response body.
db.setAdmins('mike') // Set admins.names to ['mike'] and admins.roles to []

db.setAdmins(null, 'webmaster') // Set admin.names to [] and admins.roles to ['webmaster']

db.setAdmins(
  ['john', 'jane'], // Set admins.names to ['john', 'jane']
  ['finances', 'human_resources'] // Set admins.roles to ['finances', 'human_resources']
)

db.setAdmins({
  names: 'mike', // Set admins.names to ['mike']
  roles: ['finances', 'stock'] // Set admins.roles to ['finances', 'stock']
})

db.setAdmins({
  roles: 'webamster' // Set admins.roles to ['webmaster'] and admins.names to []
})

db.addMembers(names, roles)

  • Arguments:
    • names: It can be a String, an Array of strings, an Object or null.
    • roles: It can be a String, an Array of strings or null.
  • Returns: A promise that resolves with the response body.
db.addMembers('mike') // Add mike to members.names

db.addMembers(null, 'webmaster') // Add webmaster to members.roles

db.addMembers(
  ['john', 'jane'], // Add john and jane to members.names
  ['finances', 'human_resources'] // Add finances and human_resources to members.roles
)

db.addMembers({
  names: 'mike', // Add mike to members.names
  roles: ['finances', 'stock'] // Add finances and stock to members.roles
})

db.addMembers({
  roles: 'webamster' // Add webmaster to members.roles
})

db.removeMembers(names, roles)

  • Arguments:
    • names: It can be a String, an Array of strings, an Object or null.
    • roles: It can be a String, an Array of strings or null.
  • Returns: A promise that resolves with the response body.
db.removeMembers('mike') // Remove mike from members.names

db.removeMembers(null, 'webmaster') // Remove webmaster from members.roles

db.removeMembers(
  ['john', 'jane'], // Remove john and jane from members.names
  ['finances', 'human_resources'] // Remove finances and human_resources from members.roles
)

db.removeMembers({
  names: 'mike', // Remove mike from members.names
  roles: ['finances', 'stock'] // Remove finances and stock from members.roles
})

db.removeMembers({
  roles: 'webamster' // Remove webmaster from members.roles
})

db.setMembers(names, roles)

This method completely replace the members.names AND members.roles lists.

  • Arguments:
    • names: It can be a String, an Array of strings, an Object or null.
    • roles: It can be a String, an Array of strings or null.
  • Returns: A promise that resolves with the response body.
db.setMembers('mike') // Set members.names to ['mike'] and members.roles to []

db.setMembers(null, 'webmaster') // Set admin.names to [] and members.roles to ['webmaster']

db.setMembers(
  ['john', 'jane'], // Set members.names to ['john', 'jane']
  ['finances', 'human_resources'] // Set members.roles to ['finances', 'human_resources']
)

db.setMembers({
  names: 'mike', // Set members.names to ['mike']
  roles: ['finances', 'stock'] // Set members.roles to ['finances', 'stock']
})

db.setMembers({
  roles: 'webamster' // Set members.roles to ['webmaster'] and members.names to []
})

db.addNames(names, groups)

  • Arguments:
    • names: It can be a String or an Array of strings.
    • groups: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.addNames('mike', 'admins') // Add mike to admins.names

db.addNames(['john', 'jane'], 'members') // Add john and jane to members.names

db.addNames(
  ['john', 'jane'], // Add john and jane
  ['admins', 'members'] // to admins.names and members.names
)

db.removeNames(names, groups)

  • Arguments:
    • names: It can be a String or an Array of strings.
    • groups: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.removeNames('mike', 'admins') // Remove mike from admins.names

db.removeNames(['john', 'jane'], 'members') // Remove john and jane from members.names

db.removeNames(
  ['john', 'jane'], // Remove john and jane
  ['admins', 'members'] // from admins.names and members.names
)

db.setNames(names, groups)

  • Arguments:
    • names: It can be a String or an Array of strings.
    • groups: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.setNames('finances', 'admins') // Set admins.names to ['finances']

db.setNames(['human_resources', 'stock'], 'members') // Set members.names to ['human_resources', 'stock']

db.setNames(
  ['webmaster', 'sales'], // Set admins.names and members.names
  ['admins', 'members'] // to ['webmaster', 'sales']
)

db.addRoles(roles, groups)

  • Arguments:
    • roles: It can be a String or an Array of strings.
    • groups: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.addRoles('finances', 'admins') // Add finances to admins.roles

db.addRoles(['human_resources', 'stock'], 'members') // Add human_resources and stock to members.roles

db.addRoles(
  ['webmaster', 'sales'], // Add webmaster and sales
  ['admins', 'members'] // to admins.roles and members.roles
)

db.removeRoles(roles, groups)

  • Arguments:
    • roles: It can be a String or an Array of strings.
    • groups: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.removeRoles('finances', 'admins') // Remove finances from admins.roles

db.removeRoles(['human_resources', 'stock'], 'members') // Remove human_resources and stock from members.roles

db.removeRoles(
  ['webmaster', 'sales'], // Remove webmaster and sales
  ['admins', 'members'] // from admins.roles and members.roles
)

db.setRoles(roles, groups)

  • Arguments:
    • roles: It can be a String or an Array of strings.
    • groups: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.setRoles('finances', 'admins') // Set admins.roles to ['finances']

db.setRoles(['human_resources', 'stock'], 'members') // Set members.roles to ['human_resources', 'stock']

db.setRoles(
  ['webmaster', 'sales'], // Set admins.roles and members.roles
  ['admins', 'members'] // to ['webmaster', 'sales']
)

db.addOwners(names)

  • Arguments:
    • names: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.addOwners('joey') // Add joey to admins.names and members.names

db.addOwners(['ted', 'rick']) // Add ted and rick to admins.names and members.names

db.removeOwners(names)

  • Arguments:
    • names: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.removeOwners('joey') // Remove joey from admins.names and members.names

db.removeOwners(['ted', 'rick']) // Remove ted and rick from admins.names and members.names

db.setOwners(names)

This method completely replace the admins.names AND members.names lists.

  • Arguments:
    • names: It can be a String or an Array of strings.
  • Returns: A promise that resolves with the response body.
db.setOwners('joey') // Set admins.names and members.names to ['joey']

db.setOwners(['ted', 'rick']) // Set admins.names and members.names to ['ted', 'rick']

License

This software is provided free of charge and without restriction under the MIT License