@casbin/redis-watcher 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +63 -22
  2. package/package.json +10 -3
package/README.md CHANGED
@@ -1,47 +1,88 @@
1
- # Redis-watcher
1
+ # Redis Watcher
2
2
 
3
- Redis watcher for node-casbin based on [ioredis](https://github.com/luin/ioredis).
3
+ [![CI](https://github.com/node-casbin/redis-watcher/actions/workflows/ci.yml/badge.svg)](https://github.com/node-casbin/redis-watcher/actions/workflows/ci.yml)
4
+ [![Coverage Status](https://coveralls.io/repos/github/node-casbin/redis-watcher/badge.svg?branch=master)](https://coveralls.io/github/node-casbin/redis-watcher?branch=master)
5
+ [![NPM version][npm-image]][npm-url]
6
+ [![NPM download][download-image]][download-url]
7
+ [![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)
4
8
 
5
- # Installation
9
+ [npm-image]: https://img.shields.io/npm/v/@casbin/redis-watcher.svg?style=flat-square
10
+ [npm-url]: https://npmjs.com/package/@casbin/redis-watcher
11
+ [download-image]: https://img.shields.io/npm/dm/@casbin/redis-watcher.svg?style=flat-square
12
+ [download-url]: https://npmjs.com/package/@casbin/redis-watcher
6
13
 
7
- ```shell script
8
- # NPM
9
- npm install --save @casbin/redis-watcher
14
+ Redis Watcher is the [Redis](https://redis.io/) watcher for [Node-Casbin](https://github.com/casbin/node-casbin). With this library, Node-Casbin can synchronize policy changes across multiple enforcer instances via Redis pub/sub.
10
15
 
11
- # Yarn
12
- yarn add @casbin/redis-watcher
16
+ This watcher is based on [ioredis](https://github.com/luin/ioredis) and supports both single Redis instances and Redis clusters.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @casbin/redis-watcher
13
22
  ```
14
23
 
15
- **Note: redis-watcher has been deprecated on NPM.**
24
+ **Note: The old package name `redis-watcher` has been deprecated on NPM. Please use `@casbin/redis-watcher` instead.**
25
+
26
+ ## Simple Example
16
27
 
17
- # Example
18
28
  Using Redis:
19
29
 
20
30
  ```typescript
21
31
  import { RedisWatcher } from '@casbin/redis-watcher';
22
32
  import { newEnforcer } from 'casbin';
23
33
 
24
- // Initialize the watcher, see https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
25
- const watcher = await RedisWatcher.newWatcher('redis://localhost:6379/5');
34
+ async function myFunction() {
35
+ // Initialize the watcher
36
+ // See https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
37
+ const watcher = await RedisWatcher.newWatcher('redis://localhost:6379/5');
38
+
39
+ // Initialize the enforcer
40
+ const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');
26
41
 
27
- // Initialize the enforcer.
28
- const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');
42
+ // Set the watcher for the enforcer
43
+ enforcer.setWatcher(watcher);
29
44
 
30
- enforcer.setWatcher(watcher);
45
+ // Update the policy
46
+ await enforcer.addPolicy('alice', 'data1', 'read');
47
+
48
+ // The policy change will be synchronized to other enforcers via Redis pub/sub
49
+ }
31
50
  ```
32
51
 
33
- Using Redis cluster:
52
+ Using Redis Cluster:
34
53
 
35
54
  ```typescript
36
55
  import { RedisWatcher } from '@casbin/redis-watcher';
37
56
  import { newEnforcer } from 'casbin';
38
57
 
39
- // Initialize the watcher, see https://github.com/luin/ioredis/blob/master/API.md#new-clusterstartupnodes-options.
40
- const watcher = await RedisWatcher.newWatcherWithCluster([{ port: 7000, host: 'localhost' }]);
58
+ async function myFunction() {
59
+ // Initialize the watcher with Redis cluster
60
+ // See https://github.com/luin/ioredis/blob/master/API.md#new-clusterstartupnodes-options
61
+ const watcher = await RedisWatcher.newWatcherWithCluster([
62
+ { port: 7000, host: 'localhost' },
63
+ { port: 7001, host: 'localhost' },
64
+ { port: 7002, host: 'localhost' }
65
+ ]);
66
+
67
+ // Initialize the enforcer
68
+ const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');
69
+
70
+ // Set the watcher for the enforcer
71
+ enforcer.setWatcher(watcher);
72
+
73
+ // Update the policy
74
+ await enforcer.addPolicy('bob', 'data2', 'write');
75
+
76
+ // The policy change will be synchronized to other enforcers via Redis pub/sub
77
+ }
78
+ ```
41
79
 
42
- // Initialize the enforcer.
43
- const enforcer = await newEnforcer('examples/authz_model.conf', 'examples/authz_policy.csv');
80
+ ## Getting Help
44
81
 
45
- enforcer.setWatcher(watcher);
46
- ```
82
+ - [Node-Casbin](https://github.com/casbin/node-casbin)
83
+ - [Casbin Forum](https://forum.casbin.com/)
84
+
85
+ ## License
86
+
87
+ This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.
47
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@casbin/redis-watcher",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "description": "Redis watcher for node-casbin",
5
5
  "main": "lib/watcher.js",
6
6
  "typings": "lib/watcher.d.ts",
@@ -10,7 +10,9 @@
10
10
  "prettier": "prettier --write **/*.{ts,js}",
11
11
  "build": "rimraf lib && tsc -p tsconfig.json",
12
12
  "lint": "tslint -p . -c tslint.json",
13
- "test": "jest --forceExit"
13
+ "test": "jest --forceExit",
14
+ "coverage": "jest --coverage --forceExit",
15
+ "release": "npx -p semantic-release -p @semantic-release/git -p @semantic-release/changelog semantic-release"
14
16
  },
15
17
  "devDependencies": {
16
18
  "@semantic-release/changelog": "^5.0.1",
@@ -19,10 +21,12 @@
19
21
  "@semantic-release/github": "^7.2.0",
20
22
  "@semantic-release/npm": "^7.0.8",
21
23
  "@semantic-release/release-notes-generator": "^9.0.1",
24
+ "@types/babel__core": "7.1.7",
25
+ "@types/babel__traverse": "7.0.8",
22
26
  "@types/ioredis": "^4.14.3",
23
27
  "@types/jest": "^24.0.11",
24
28
  "@types/node": "^10.5.3",
25
- "casbin": "^5.2.1",
29
+ "casbin": "5.2.1",
26
30
  "coveralls": "^3.0.2",
27
31
  "jest": "^24.9.0",
28
32
  "lint-staged": "^8.1.7",
@@ -36,6 +40,9 @@
36
40
  "dependencies": {
37
41
  "ioredis": "^4.11.1"
38
42
  },
43
+ "resolutions": {
44
+ "@types/babel__traverse": "7.0.8"
45
+ },
39
46
  "files": [
40
47
  "lib",
41
48
  "examples"