@abtnode/blocklet-services 1.8.59 → 1.8.60
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.
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const get = require('lodash/get');
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
const { getDefaultServiceConfig
|
|
3
|
+
const { findComponentById } = require('@blocklet/meta/lib/util');
|
|
4
|
+
const { getDefaultServiceConfig } = require('@blocklet/meta/lib/service');
|
|
5
5
|
const { WHO_CAN_ACCESS } = require('@abtnode/constant');
|
|
6
6
|
const cache = require('../cache');
|
|
7
7
|
|
|
8
8
|
const formatContext = require('./format-context');
|
|
9
9
|
const getDynamicServiceConfig = require('./get-dynamic-service-config');
|
|
10
|
+
const getStaticServiceConfig = require('./get-static-service-config');
|
|
10
11
|
|
|
11
12
|
module.exports = ({ node, req, options }) => {
|
|
12
13
|
req.getBlockletUrl = () => req.headers['x-blocklet-url'] || get(options, 'blockletUrl', '');
|
|
@@ -34,7 +35,7 @@ module.exports = ({ node, req, options }) => {
|
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* @return obj | null
|
|
37
|
-
* @
|
|
38
|
+
* @FIXME this api should ensure high performance
|
|
38
39
|
*/
|
|
39
40
|
req.getServiceConfig = async (serviceName, { componentId } = {}) => {
|
|
40
41
|
if (!serviceName) {
|
|
@@ -66,32 +67,21 @@ module.exports = ({ node, req, options }) => {
|
|
|
66
67
|
appDynamicConfig = null;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
const defaultConfigWithAppDynamic = { ...defaultConfig, ...appDynamicConfig };
|
|
70
|
-
|
|
71
70
|
const _componentId = componentId || req.getBlockletComponentId();
|
|
72
71
|
|
|
72
|
+
const componentStaticConfig = getStaticServiceConfig(serviceName, app, _componentId);
|
|
73
|
+
|
|
74
|
+
const config = { ...defaultConfig, ...componentStaticConfig, ...appDynamicConfig };
|
|
75
|
+
|
|
73
76
|
const component = findComponentById(app, _componentId);
|
|
74
77
|
|
|
75
78
|
if (!component) {
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const _interface = findWebInterface(component);
|
|
80
|
-
if (!_interface) {
|
|
81
|
-
return defaultConfigWithAppDynamic;
|
|
79
|
+
return config;
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
// find service
|
|
85
|
-
const service = findService(_interface.services, serviceName);
|
|
86
|
-
const componentStaticConfig = service?.config;
|
|
87
|
-
|
|
88
82
|
const componentDynamicConfig = getDynamicServiceConfig(serviceName, component, { type: 'component' });
|
|
89
83
|
|
|
90
|
-
|
|
91
|
-
return defaultConfigWithAppDynamic;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return { ...defaultConfig, ...componentStaticConfig, ...appDynamicConfig, ...componentDynamicConfig };
|
|
84
|
+
return { ...config, ...componentDynamicConfig };
|
|
95
85
|
};
|
|
96
86
|
|
|
97
87
|
req.getBlocklet = async ({ useCache = true } = {}) => {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const omit = require('lodash/omit');
|
|
2
|
+
const difference = require('lodash/difference');
|
|
3
|
+
const { findWebInterface, forEachBlockletSync } = require('@blocklet/meta/lib/util');
|
|
4
|
+
const { findService } = require('@blocklet/meta/lib/service');
|
|
5
|
+
const { NODE_SERVICES } = require('@abtnode/constant');
|
|
6
|
+
|
|
7
|
+
// [a, b], [b, c] => [a, b, c]
|
|
8
|
+
const mergeProfileFields = (a = [], b = []) => a.concat(difference(b, a));
|
|
9
|
+
|
|
10
|
+
const getAuthConfig = (app, componentId) => {
|
|
11
|
+
const ret = {};
|
|
12
|
+
|
|
13
|
+
let rootConfig = null;
|
|
14
|
+
let hasComponent = false;
|
|
15
|
+
|
|
16
|
+
forEachBlockletSync(app, (component, { id, level }) => {
|
|
17
|
+
if (id === componentId) {
|
|
18
|
+
hasComponent = true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const _interface = findWebInterface(component);
|
|
22
|
+
if (_interface) {
|
|
23
|
+
const service = findService(_interface.services, NODE_SERVICES.AUTH);
|
|
24
|
+
const { config } = service || {};
|
|
25
|
+
if (config) {
|
|
26
|
+
if (level === 0) {
|
|
27
|
+
rootConfig = config;
|
|
28
|
+
// 统一使用 root component 的 allowSwitchProfile
|
|
29
|
+
if (config.allowSwitchProfile !== undefined) {
|
|
30
|
+
ret.allowSwitchProfile = config.allowSwitchProfile;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (id === componentId) {
|
|
35
|
+
hasComponent = true;
|
|
36
|
+
// 忽略 component 的 allowSwitchProfile
|
|
37
|
+
Object.assign(ret, omit(config, ['profileFields', 'allowSwitchProfile']));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (config.profileFields) {
|
|
41
|
+
ret.profileFields = mergeProfileFields(ret.profileFields, config.profileFields);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// 如果没找到 component 时, 使用 root component 的 config #6101
|
|
48
|
+
if (!hasComponent && rootConfig) {
|
|
49
|
+
Object.assign(ret, omit(rootConfig, ['profileFields']));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return ret;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const getStaticServiceConfig = (serviceName, app, componentId) => {
|
|
56
|
+
if (serviceName === NODE_SERVICES.AUTH) {
|
|
57
|
+
return getAuthConfig(app, componentId);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
throw new Error(`Invalid service name: ${serviceName}`);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = getStaticServiceConfig;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.60",
|
|
7
7
|
"description": "Provide unified services for every blocklet",
|
|
8
8
|
"main": "api/index.js",
|
|
9
9
|
"files": [
|
|
@@ -31,26 +31,26 @@
|
|
|
31
31
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@abtnode/auth": "1.8.
|
|
35
|
-
"@abtnode/client": "1.8.
|
|
36
|
-
"@abtnode/constant": "1.8.
|
|
37
|
-
"@abtnode/core": "1.8.
|
|
38
|
-
"@abtnode/cron": "1.8.
|
|
39
|
-
"@abtnode/db": "1.8.
|
|
40
|
-
"@abtnode/logger": "1.8.
|
|
41
|
-
"@abtnode/router-adapter": "1.8.
|
|
42
|
-
"@abtnode/router-templates": "1.8.
|
|
43
|
-
"@abtnode/util": "1.8.
|
|
34
|
+
"@abtnode/auth": "1.8.60",
|
|
35
|
+
"@abtnode/client": "1.8.60",
|
|
36
|
+
"@abtnode/constant": "1.8.60",
|
|
37
|
+
"@abtnode/core": "1.8.60",
|
|
38
|
+
"@abtnode/cron": "1.8.60",
|
|
39
|
+
"@abtnode/db": "1.8.60",
|
|
40
|
+
"@abtnode/logger": "1.8.60",
|
|
41
|
+
"@abtnode/router-adapter": "1.8.60",
|
|
42
|
+
"@abtnode/router-templates": "1.8.60",
|
|
43
|
+
"@abtnode/util": "1.8.60",
|
|
44
44
|
"@arcblock/did-auth": "1.18.34",
|
|
45
45
|
"@arcblock/did-auth-storage-nedb": "^1.7.1",
|
|
46
46
|
"@arcblock/event-hub": "1.18.34",
|
|
47
47
|
"@arcblock/jwt": "1.18.34",
|
|
48
48
|
"@arcblock/ws": "1.18.34",
|
|
49
|
-
"@blocklet/constant": "1.8.
|
|
49
|
+
"@blocklet/constant": "1.8.60",
|
|
50
50
|
"@blocklet/form-builder": "^0.1.10",
|
|
51
51
|
"@blocklet/form-collector": "^0.1.5",
|
|
52
|
-
"@blocklet/meta": "1.8.
|
|
53
|
-
"@blocklet/sdk": "1.8.
|
|
52
|
+
"@blocklet/meta": "1.8.60",
|
|
53
|
+
"@blocklet/sdk": "1.8.60",
|
|
54
54
|
"@did-connect/authenticator": "^2.1.33",
|
|
55
55
|
"@did-connect/relay-adapter-express": "^2.1.33",
|
|
56
56
|
"@did-connect/storage-nedb": "^2.1.33",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"@nedb/multi": "^2.0.5"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@abtnode/ux": "1.8.
|
|
86
|
+
"@abtnode/ux": "1.8.60",
|
|
87
87
|
"@arcblock/did-connect": "^2.4.64",
|
|
88
88
|
"@arcblock/icons": "^2.4.64",
|
|
89
89
|
"@arcblock/ux": "^2.4.64",
|
|
@@ -147,5 +147,5 @@
|
|
|
147
147
|
"url": "https://github.com/ArcBlock/blocklet-server/issues",
|
|
148
148
|
"email": "shijun@arcblock.io"
|
|
149
149
|
},
|
|
150
|
-
"gitHead": "
|
|
150
|
+
"gitHead": "0a56dc596f58d83f22d1ea0d0145d84e7151f5be"
|
|
151
151
|
}
|