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
PouchDB const db = 'http://localhost:5984'
API
db.addAdmins(names, roles)
- Arguments:
- names: It can be a
String
, anArray
of strings, anObject
ornull
. - roles: It can be a
String
, anArray
of strings ornull
.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Add mike to admins.names db // Add webmaster to admins.roles db db db
db.removeAdmins(names, roles)
- Arguments:
- names: It can be a
String
, anArray
of strings, anObject
ornull
. - roles: It can be a
String
, anArray
of strings ornull
.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Remove mike from admins.names db // Remove webmaster from admins.roles db db db
db.setAdmins(names, roles)
This method completely replace the admins.names
AND admins.roles
lists.
- Arguments:
- names: It can be a
String
, anArray
of strings, anObject
ornull
. - roles: It can be a
String
, anArray
of strings ornull
.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Set admins.names to ['mike'] and admins.roles to [] db // Set admin.names to [] and admins.roles to ['webmaster'] db db db
db.addMembers(names, roles)
- Arguments:
- names: It can be a
String
, anArray
of strings, anObject
ornull
. - roles: It can be a
String
, anArray
of strings ornull
.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Add mike to members.names db // Add webmaster to members.roles db db db
db.removeMembers(names, roles)
- Arguments:
- names: It can be a
String
, anArray
of strings, anObject
ornull
. - roles: It can be a
String
, anArray
of strings ornull
.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Remove mike from members.names db // Remove webmaster from members.roles db db db
db.setMembers(names, roles)
This method completely replace the members.names
AND members.roles
lists.
- Arguments:
- names: It can be a
String
, anArray
of strings, anObject
ornull
. - roles: It can be a
String
, anArray
of strings ornull
.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Set members.names to ['mike'] and members.roles to [] db // Set admin.names to [] and members.roles to ['webmaster'] db db db
db.addNames(names, groups)
- Arguments:
- names: It can be a
String
or anArray
of strings. - groups: It can be a
String
or anArray
of strings.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Add mike to admins.names db // Add john and jane to members.names db
db.removeNames(names, groups)
- Arguments:
- names: It can be a
String
or anArray
of strings. - groups: It can be a
String
or anArray
of strings.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Remove mike from admins.names db // Remove john and jane from members.names db
db.setNames(names, groups)
- Arguments:
- names: It can be a
String
or anArray
of strings. - groups: It can be a
String
or anArray
of strings.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Set admins.names to ['finances'] db // Set members.names to ['human_resources', 'stock'] db
db.addRoles(roles, groups)
- Arguments:
- roles: It can be a
String
or anArray
of strings. - groups: It can be a
String
or anArray
of strings.
- roles: It can be a
- Returns: A promise that resolves with the response body.
db // Add finances to admins.roles db // Add human_resources and stock to members.roles db
db.removeRoles(roles, groups)
- Arguments:
- roles: It can be a
String
or anArray
of strings. - groups: It can be a
String
or anArray
of strings.
- roles: It can be a
- Returns: A promise that resolves with the response body.
db // Remove finances from admins.roles db // Remove human_resources and stock from members.roles db
db.setRoles(roles, groups)
- Arguments:
- roles: It can be a
String
or anArray
of strings. - groups: It can be a
String
or anArray
of strings.
- roles: It can be a
- Returns: A promise that resolves with the response body.
db // Set admins.roles to ['finances'] db // Set members.roles to ['human_resources', 'stock'] db
db.addOwners(names)
- Arguments:
- names: It can be a
String
or anArray
of strings.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Add joey to admins.names and members.names db // Add ted and rick to admins.names and members.names
db.removeOwners(names)
- Arguments:
- names: It can be a
String
or anArray
of strings.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Remove joey from admins.names and members.names db // 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 anArray
of strings.
- names: It can be a
- Returns: A promise that resolves with the response body.
db // Set admins.names and members.names to ['joey'] db // Set admins.names and members.names to ['ted', 'rick']
License
This software is provided free of charge and without restriction under the MIT License