@casbin/pubsub-watcher
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

pubsub-watcher

NPM version

Google Cloud Pub/Sub watcher for node-casbin

Installation

# NPM
npm install --save @casbin/pubsub-watcher

# Yarn
yarn add @casbin/pubsub-watcher

Simple Example

import { PubsubWatcher } from '@casbin/pubsub-watcher';
import { newEnforcer } from 'casbin';

// Initialize the watcher.
// You need to create Pubsub topic and subscription(per casbin instance) first
const watcher = await PubsubWatcher.newWatcher();

// Initialize the enforcer.
const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');

enforcer.setWatcher(watcher);

// By default, the watcher's callback is automatically set to the
// enforcer's loadPolicy() in the setWatcher() call.
// We can change it by explicitly setting a callback.
watcher.setUpdateCallback(() => console.log('Casbin need update'));

Test

Set GOOGLE_APPLICATION_CREDENTIALS in environment variable and npm run test

Readme

Keywords

none

Package Sidebar

Install

npm i @casbin/pubsub-watcher

Homepage

casbin.org

Weekly Downloads

5

Version

1.0.1

License

none

Unpacked Size

18.3 kB

Total Files

9

Last publish

Collaborators

  • chalin
  • hsluoyz
  • elaijuh