@blocklet/sdk 1.5.3 → 1.5.7
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.
- package/README.md +35 -0
- package/lib/index.js +2 -0
- package/lib/service/auth.js +12 -4
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -134,3 +134,38 @@ Send notification to an account
|
|
|
134
134
|
- **color** `string`
|
|
135
135
|
- **bgColor** `string`
|
|
136
136
|
- **link** `string` uri
|
|
137
|
+
|
|
138
|
+
## WalletAuthenticator SDK
|
|
139
|
+
|
|
140
|
+
### Usage
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
const { WalletAuthenticator } = require('@blocklet/sdk');
|
|
144
|
+
|
|
145
|
+
const authenticator = new WalletAuthenticator();
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## WalletHandler SDK
|
|
149
|
+
|
|
150
|
+
### Usage
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
const AuthStorage = require('@arcblock/did-auth-storage-nedb');
|
|
154
|
+
const { WalletAuthenticator, WalletHandlers } = require('@blocklet/sdk');
|
|
155
|
+
|
|
156
|
+
const authenticator = new WalletAuthenticator();
|
|
157
|
+
|
|
158
|
+
const handlers = new WalletHandlers({
|
|
159
|
+
authenticator,
|
|
160
|
+
tokenGenerator: () => Date.now().toString(),
|
|
161
|
+
tokenStorage: new AuthStorage({
|
|
162
|
+
dbPath: path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db'),
|
|
163
|
+
onload: (err) => {
|
|
164
|
+
if (err) {
|
|
165
|
+
// eslint-disable-next-line no-console
|
|
166
|
+
console.error(`Failed to load database from ${path.join(process.env.BLOCKLET_DATA_DIR, 'auth.db')}`, err);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
}),
|
|
170
|
+
});
|
|
171
|
+
```
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const AuthService = require('./service/auth');
|
|
2
2
|
const NotificationService = require('./service/notification');
|
|
3
3
|
const WalletAuthenticator = require('./wallet-authenticator');
|
|
4
|
+
const WalletHandler = require('./wallet-handler');
|
|
4
5
|
|
|
5
6
|
module.exports = {
|
|
6
7
|
AuthService,
|
|
7
8
|
NotificationService,
|
|
9
|
+
WalletHandler,
|
|
8
10
|
WalletAuthenticator,
|
|
9
11
|
};
|
package/lib/service/auth.js
CHANGED
|
@@ -46,14 +46,15 @@ class AuthService extends Client {
|
|
|
46
46
|
// 'createInvitation',
|
|
47
47
|
// 'deleteInvitation',
|
|
48
48
|
|
|
49
|
-
//
|
|
49
|
+
// rbac
|
|
50
50
|
'getRoles',
|
|
51
51
|
'createRole',
|
|
52
52
|
'updateRole',
|
|
53
53
|
'deleteRole',
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
'grantPermissionForRole', // grant
|
|
55
|
+
'revokePermissionFromRole', // revoke
|
|
56
|
+
'updatePermissionsForRole', // grant many
|
|
57
|
+
'hasPermission',
|
|
57
58
|
|
|
58
59
|
// user passport
|
|
59
60
|
// 'getPassportIssuances',
|
|
@@ -97,6 +98,12 @@ class AuthService extends Client {
|
|
|
97
98
|
(name, { title, description }) =>
|
|
98
99
|
fn({ input: { role: pickBy({ name, title, description }, isNotNullOrUndefined), teamDid } }), // todo
|
|
99
100
|
deleteRole: (fn) => (name) => fn({ input: { name, teamDid } }),
|
|
101
|
+
grantPermissionForRole: (fn) => (roleName, permissionName) =>
|
|
102
|
+
fn({ input: { teamDid, roleName, grantName: permissionName } }),
|
|
103
|
+
revokePermissionFromRole: (fn) => (roleName, permissionName) =>
|
|
104
|
+
fn({ input: { teamDid, roleName, grantName: permissionName } }),
|
|
105
|
+
updatePermissionsForRole: (fn) => (roleName, permissionNames) =>
|
|
106
|
+
fn({ input: { teamDid, roleName, grantNames: permissionNames } }),
|
|
100
107
|
createPermission:
|
|
101
108
|
(fn) =>
|
|
102
109
|
({ name, description }) =>
|
|
@@ -106,6 +113,7 @@ class AuthService extends Client {
|
|
|
106
113
|
(name, { description }) =>
|
|
107
114
|
fn({ input: { permission: pickBy({ name, description }, isNotNullOrUndefined), teamDid } }), // todo
|
|
108
115
|
deletePermission: (fn) => (name) => fn({ input: { name, teamDid } }),
|
|
116
|
+
hasPermission: (fn) => (role, permission) => fn({ input: { teamDid, role, permission } }),
|
|
109
117
|
};
|
|
110
118
|
|
|
111
119
|
apiList.forEach((api) => {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.5.
|
|
6
|
+
"version": "1.5.7",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/client": "1.5.
|
|
23
|
-
"@abtnode/constant": "1.5.
|
|
24
|
-
"@arcblock/did-auth": "^1.13.
|
|
25
|
-
"@blocklet/meta": "1.5.
|
|
26
|
-
"@ocap/mcrypto": "^1.13.
|
|
27
|
-
"@ocap/wallet": "^1.13.
|
|
22
|
+
"@abtnode/client": "1.5.7",
|
|
23
|
+
"@abtnode/constant": "1.5.7",
|
|
24
|
+
"@arcblock/did-auth": "^1.13.45",
|
|
25
|
+
"@blocklet/meta": "1.5.7",
|
|
26
|
+
"@ocap/mcrypto": "^1.13.45",
|
|
27
|
+
"@ocap/wallet": "^1.13.45",
|
|
28
28
|
"axios": "^0.21.4",
|
|
29
29
|
"joi": "^17.4.0",
|
|
30
30
|
"lodash": "^4.17.21",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"detect-port": "^1.3.0",
|
|
35
35
|
"jest": "^26.4.2"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f6cef3cb175a4e355d2c70200a72b498d8ee494b"
|
|
38
38
|
}
|