@abtnode/core 1.8.36 → 1.8.38
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/lib/api/node.js +0 -73
- package/lib/api/team.js +61 -5
- package/lib/blocklet/manager/disk.js +251 -115
- package/lib/event.js +15 -11
- package/lib/index.js +4 -7
- package/lib/states/audit-log.js +1 -1
- package/lib/states/blocklet.js +15 -0
- package/lib/states/node.js +0 -4
- package/lib/states/notification.js +14 -28
- package/lib/team/manager.js +30 -0
- package/lib/util/blocklet.js +90 -5
- package/lib/util/default-node-config.js +3 -13
- package/lib/util/index.js +44 -0
- package/lib/util/store.js +6 -6
- package/lib/validators/blocklet.js +0 -2
- package/lib/validators/role.js +4 -0
- package/package.json +25 -25
package/lib/api/node.js
CHANGED
|
@@ -7,24 +7,14 @@ const isGitpod = require('@abtnode/util/lib/is-gitpod');
|
|
|
7
7
|
const getFolderSize = require('@abtnode/util/lib/get-folder-size');
|
|
8
8
|
const canPackageReadWrite = require('@abtnode/util/lib/can-pkg-rw');
|
|
9
9
|
const { toDelegateAddress } = require('@arcblock/did-util');
|
|
10
|
-
const { STORE_DETAIL_PAGE_PATH_PREFIX } = require('@abtnode/constant');
|
|
11
10
|
|
|
12
11
|
const logger = require('@abtnode/logger')('@abtnode/core:api:node');
|
|
13
12
|
|
|
14
13
|
const IP = require('../util/ip');
|
|
15
14
|
const { validateNodeInfo, validateUpdateGateway } = require('../validators/node');
|
|
16
15
|
const { getAll } = require('../blocklet/manager/engine');
|
|
17
|
-
const StoreUtil = require('../util/store');
|
|
18
16
|
const { getDelegateState } = require('../util');
|
|
19
17
|
|
|
20
|
-
const sanitizeUrl = (url) => {
|
|
21
|
-
if (!url) {
|
|
22
|
-
throw new Error('Registry URL should not be empty');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return url.trim();
|
|
26
|
-
};
|
|
27
|
-
|
|
28
18
|
class NodeAPI {
|
|
29
19
|
/**
|
|
30
20
|
*
|
|
@@ -37,69 +27,6 @@ class NodeAPI {
|
|
|
37
27
|
this.state = state;
|
|
38
28
|
}
|
|
39
29
|
|
|
40
|
-
// eslint-disable-next-line no-unused-vars
|
|
41
|
-
async addRegistry({ url }, context) {
|
|
42
|
-
logger.info('add registry', { url });
|
|
43
|
-
|
|
44
|
-
const urlObj = new URL(url);
|
|
45
|
-
let newUrl = urlObj.origin;
|
|
46
|
-
|
|
47
|
-
// if the pathname is store blocklet list or blocklet detail
|
|
48
|
-
if (urlObj.pathname?.includes(STORE_DETAIL_PAGE_PATH_PREFIX)) {
|
|
49
|
-
const lastIndex = urlObj.pathname.lastIndexOf(STORE_DETAIL_PAGE_PATH_PREFIX);
|
|
50
|
-
const pathnamePrefix = urlObj.pathname.substring(0, lastIndex);
|
|
51
|
-
newUrl = `${newUrl}${pathnamePrefix || ''}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const sanitized = sanitizeUrl(newUrl);
|
|
55
|
-
|
|
56
|
-
const info = await this.state.read();
|
|
57
|
-
const exist = info.blockletRegistryList.find((x) => x.url === sanitized);
|
|
58
|
-
if (exist) {
|
|
59
|
-
throw new Error(`Blocklet registry already exist: ${sanitized}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
await StoreUtil.validateRegistryURL(sanitized);
|
|
63
|
-
|
|
64
|
-
const newBlockletRegistry = await StoreUtil.getRegistryMeta(sanitized);
|
|
65
|
-
const newBlockletRegistryList = info.blockletRegistryList.map((x) => ({ ...x, selected: false }));
|
|
66
|
-
newBlockletRegistryList.push({ ...newBlockletRegistry, url: sanitized, selected: true, protected: false });
|
|
67
|
-
|
|
68
|
-
return this.state.updateNodeInfo({ blockletRegistryList: newBlockletRegistryList });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// eslint-disable-next-line no-unused-vars
|
|
72
|
-
async deleteRegistry({ url }, context) {
|
|
73
|
-
logger.info('delete registry', { url });
|
|
74
|
-
const sanitized = sanitizeUrl(url);
|
|
75
|
-
const info = await this.state.read();
|
|
76
|
-
const exist = info.blockletRegistryList.find((x) => x.url === sanitized);
|
|
77
|
-
if (!exist) {
|
|
78
|
-
throw new Error(`Blocklet registry does not exist: ${sanitized}`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const blockletRegistryList = info.blockletRegistryList.filter((x) => x.url !== sanitized);
|
|
82
|
-
if (!blockletRegistryList.find((x) => x.selected)) {
|
|
83
|
-
blockletRegistryList[0].selected = true;
|
|
84
|
-
}
|
|
85
|
-
return this.state.updateNodeInfo({ blockletRegistryList });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// eslint-disable-next-line no-unused-vars
|
|
89
|
-
async selectRegistry({ url }, context) {
|
|
90
|
-
logger.info('select registry', { url });
|
|
91
|
-
const sanitized = sanitizeUrl(url);
|
|
92
|
-
const info = await this.state.read();
|
|
93
|
-
const exist = info.blockletRegistryList.find((x) => x.url === sanitized);
|
|
94
|
-
if (!exist) {
|
|
95
|
-
throw new Error(`Blocklet registry does not exist: ${sanitized}`);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return this.state.updateNodeInfo({
|
|
99
|
-
blockletRegistryList: info.blockletRegistryList.map((x) => ({ ...x, selected: x.url === sanitized })),
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
30
|
async updateNodeInfo(entity = {}, context) {
|
|
104
31
|
await validateNodeInfo(entity, context);
|
|
105
32
|
|
package/lib/api/team.js
CHANGED
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
PASSPORT_STATUS,
|
|
12
12
|
WELLKNOWN_SERVICE_PATH_PREFIX,
|
|
13
13
|
MAX_USER_PAGE_SIZE,
|
|
14
|
+
STORE_DETAIL_PAGE_PATH_PREFIX,
|
|
14
15
|
} = require('@abtnode/constant');
|
|
15
16
|
const { isValid: isValidDid } = require('@arcblock/did');
|
|
16
17
|
const { BlockletEvents } = require('@blocklet/constant');
|
|
@@ -30,6 +31,15 @@ const { validateCreateRole, validateUpdateRole } = require('../validators/role')
|
|
|
30
31
|
const { validateCreatePermission, validateUpdatePermission } = require('../validators/permission');
|
|
31
32
|
|
|
32
33
|
const { getBlocklet } = require('../util/blocklet');
|
|
34
|
+
const StoreUtil = require('../util/store');
|
|
35
|
+
|
|
36
|
+
const sanitizeUrl = (url) => {
|
|
37
|
+
if (!url) {
|
|
38
|
+
throw new Error('Registry URL should not be empty');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return url.trim();
|
|
42
|
+
};
|
|
33
43
|
|
|
34
44
|
const validateReservedRole = (role) => {
|
|
35
45
|
if (Object.values(ROLES).includes(role)) {
|
|
@@ -170,6 +180,7 @@ class TeamAPI extends EventEmitter {
|
|
|
170
180
|
'lastLoginAt',
|
|
171
181
|
'remark',
|
|
172
182
|
'avatar',
|
|
183
|
+
'locale',
|
|
173
184
|
])
|
|
174
185
|
// eslint-disable-next-line function-paren-newline
|
|
175
186
|
),
|
|
@@ -682,11 +693,7 @@ class TeamAPI extends EventEmitter {
|
|
|
682
693
|
// Access Control
|
|
683
694
|
|
|
684
695
|
async getRoles({ teamDid }) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
const roles = await rbac.getRoles();
|
|
688
|
-
|
|
689
|
-
return roles.map((d) => pick(d, ['name', 'grants', 'title', 'description']));
|
|
696
|
+
return this.teamManager.getRoles(teamDid);
|
|
690
697
|
}
|
|
691
698
|
|
|
692
699
|
async createRole({ teamDid, name, description, title, childName, permissions = [] }) {
|
|
@@ -855,6 +862,55 @@ class TeamAPI extends EventEmitter {
|
|
|
855
862
|
);
|
|
856
863
|
}
|
|
857
864
|
|
|
865
|
+
// eslint-disable-next-line no-unused-vars
|
|
866
|
+
async addStore({ teamDid, url }, context) {
|
|
867
|
+
logger.info('add registry', { url });
|
|
868
|
+
|
|
869
|
+
const urlObj = new URL(url);
|
|
870
|
+
let newUrl = urlObj.origin;
|
|
871
|
+
|
|
872
|
+
// if the pathname is store blocklet list or blocklet detail
|
|
873
|
+
if (urlObj.pathname?.includes(STORE_DETAIL_PAGE_PATH_PREFIX)) {
|
|
874
|
+
const lastIndex = urlObj.pathname.lastIndexOf(STORE_DETAIL_PAGE_PATH_PREFIX);
|
|
875
|
+
const pathnamePrefix = urlObj.pathname.substring(0, lastIndex);
|
|
876
|
+
newUrl = `${newUrl}${pathnamePrefix || ''}`;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
const sanitized = sanitizeUrl(newUrl);
|
|
880
|
+
|
|
881
|
+
const storeList = await this.teamManager.getStoreList(teamDid);
|
|
882
|
+
|
|
883
|
+
const exist = storeList.find((x) => x.url === sanitized);
|
|
884
|
+
if (exist) {
|
|
885
|
+
throw new Error(`Blocklet registry already exist: ${sanitized}`);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
await StoreUtil.validateRegistryURL(sanitized);
|
|
889
|
+
|
|
890
|
+
const store = await StoreUtil.getRegistryMeta(sanitized);
|
|
891
|
+
|
|
892
|
+
storeList.push({ ...store, url: sanitized, protected: false });
|
|
893
|
+
|
|
894
|
+
return this.teamManager.updateStoreList(teamDid, storeList);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// eslint-disable-next-line no-unused-vars
|
|
898
|
+
async deleteStore({ teamDid, url }, context) {
|
|
899
|
+
logger.info('delete registry', { url });
|
|
900
|
+
const sanitized = sanitizeUrl(url);
|
|
901
|
+
|
|
902
|
+
const storeList = await this.teamManager.getStoreList(teamDid);
|
|
903
|
+
const exist = storeList.find((x) => x.url === sanitized);
|
|
904
|
+
if (!exist) {
|
|
905
|
+
throw new Error(`Blocklet registry does not exist: ${sanitized}`);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
return this.teamManager.updateStoreList(
|
|
909
|
+
teamDid,
|
|
910
|
+
storeList.filter((x) => x.url !== sanitized)
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
|
|
858
914
|
// =======
|
|
859
915
|
// Private
|
|
860
916
|
// =======
|