Fix tsconfig.json
2 files changed
tree: 29f602aa94df1292b5b779aa4b6ee1631fae79cb
  1. .github/
  2. examples/
  3. src/
  4. test/
  5. .gitignore
  6. babel.config.cjs
  7. jest.config.cjs
  8. LICENSE
  9. package.json
  10. README.md
  11. tsconfig.json
  12. yarn.lock
README.md

CouchDB Adapter

NPM version NPM download ci Coverage Status Gitter

CouchDB policy storage, implemented as an adapter for node-casbin.

Installation

NPM Install

npm install casbin-couchdb-adapter --save

Yarn Install

yarn add casbin-couchdb-adapter

Simple Example

import { newEnforcer } from 'casbin';
import { CouchdbAdapter } from 'casbin-couchdb-adapter';
import { join } from 'path';

async function myFunction() {
    // Initialize a CouchdbAdapter adapter and use it in a Node-Casbin enforcer:
    const adapter = await CouchdbAdapter.newAdapter("http://admin:password@localhost:5984");

    // The location of your Casbin model configuration file
    const model = join(__dirname, 'casbin_conf/model.conf');

    const enforcer = await newEnforcer(model, adapter);

    // Check the permission.
    enforcer.enforce('alice', 'data1', 'read');

    // Modify the policy.
    // await enforcer.addPolicy(...);
    // await enforcer.removePolicy(...);

    // Save the policy back to DB.
    await enforcer.savePolicy();
}

Configuration

You need to create a database named "casbin" and a document like this:

{
  "_id": "policies",
  "value": []
}

CouchdbAdapter.newAdapter() takes the following parameters as an object to establish the connection with couchdb-server

databaseUrl: string = "http://{admin}:{password}@{ip}:{port}"

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.