@blocklet/meta 1.15.17 → 1.16.0-beta-b16cb035
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/channel.d.ts +32 -0
- package/lib/channel.js +54 -0
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +5 -152
- package/lib/did.d.ts +3 -0
- package/lib/did.js +9 -9
- package/lib/engine.d.ts +7 -0
- package/lib/engine.js +21 -25
- package/lib/entry.d.ts +3 -0
- package/lib/entry.js +51 -64
- package/lib/extension.d.ts +14 -0
- package/lib/extension.js +82 -77
- package/lib/file.d.ts +23 -0
- package/lib/file.js +51 -36
- package/lib/fix.d.ts +36 -0
- package/lib/fix.js +231 -228
- package/lib/get-component-process-id.d.ts +5 -0
- package/lib/get-component-process-id.js +16 -0
- package/lib/has-reserved-key.d.ts +3 -0
- package/lib/has-reserved-key.js +15 -0
- package/lib/index.d.ts +86 -0
- package/lib/index.js +55 -34
- package/lib/info.d.ts +15 -0
- package/lib/info.js +70 -38
- package/lib/name.d.ts +15 -0
- package/lib/name.js +41 -8
- package/lib/nft-templates.d.ts +86 -0
- package/lib/nft-templates.js +52 -0
- package/lib/parse-navigation-from-blocklet.d.ts +92 -0
- package/lib/parse-navigation-from-blocklet.js +539 -0
- package/lib/parse-navigation.d.ts +3 -0
- package/lib/parse-navigation.js +197 -0
- package/lib/parse.d.ts +22 -0
- package/lib/parse.js +100 -89
- package/lib/payment/index.d.ts +254 -0
- package/lib/payment/index.js +14 -0
- package/lib/payment/v1.d.ts +185 -0
- package/lib/payment/v1.js +84 -0
- package/lib/payment/v2.d.ts +242 -0
- package/lib/payment/v2.js +576 -0
- package/lib/schema.d.ts +63 -0
- package/lib/schema.js +669 -283
- package/lib/service.d.ts +27 -0
- package/lib/service.js +71 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +18 -0
- package/lib/types/schema.d.ts +284 -0
- package/lib/types/schema.js +3 -0
- package/lib/url-friendly.d.ts +6 -0
- package/lib/url-friendly.js +20 -0
- package/lib/util-meta.d.ts +42 -0
- package/lib/util-meta.js +146 -0
- package/lib/util.d.ts +201 -0
- package/lib/util.js +501 -82
- package/lib/validate.d.ts +13 -0
- package/lib/validate.js +37 -61
- package/lib/verify-multi-sig.d.ts +3 -0
- package/lib/verify-multi-sig.js +86 -59
- package/lib/wallet.d.ts +9 -0
- package/lib/wallet.js +19 -30
- package/package.json +59 -20
- package/lib/payment.js +0 -114
package/lib/util.js
CHANGED
|
@@ -1,89 +1,508 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getBlockletAppIdList = exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.findComponent = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterfacePort = exports.findWebInterface = exports.fixBlockletStatus = exports.getAppDescription = exports.getDisplayName = exports.getAppName = exports.hasRunnableComponent = exports.wipeSensitiveData = exports.isEnvShareable = exports.getComponentMissingConfigs = exports.getAppMissingConfigs = exports.getSharedConfigObj = exports.isDeletableBlocklet = exports.forEachChildSync = exports.forEachChild = exports.forEachBlockletSync = exports.forEachBlocklet = exports.isComponentBlocklet = exports.isFreeComponent = exports.isFreeBlocklet = void 0;
|
|
1
7
|
/* eslint-disable no-await-in-loop */
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
9
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
10
|
+
const url_join_1 = __importDefault(require("url-join"));
|
|
11
|
+
const p_limit_1 = __importDefault(require("p-limit"));
|
|
12
|
+
const constant_1 = __importDefault(require("@abtnode/constant"));
|
|
13
|
+
const constants_1 = __importDefault(require("./constants"));
|
|
14
|
+
const { NODE_SERVICES, SLOT_FOR_IP_DNS_SITE, WHO_CAN_ACCESS, WHO_CAN_ACCESS_PREFIX_ROLES } = constant_1.default;
|
|
15
|
+
const { BlockletGroup, fromBlockletStatus, fromBlockletSource, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_CONFIGURABLE_KEY, CHAIN_INFO_CONFIG, BLOCKLET_PREFERENCE_PREFIX, } = constants_1.default;
|
|
16
|
+
const getComponentId = (component, ancestors = []) => `${ancestors.map((x) => (x && x.meta ? x.meta.did : '')).join('/')}${ancestors.length ? '/' : ''}${component && component.meta ? component.meta.did : ''}`;
|
|
17
|
+
exports.getComponentId = getComponentId;
|
|
18
|
+
const getComponentName = (component, ancestors = []) => `${ancestors.map((x) => (x && x.meta ? x.meta.name : '')).join('/')}${ancestors.length ? '/' : ''}${component && component.meta ? component.meta.name : ''}`;
|
|
19
|
+
exports.getComponentName = getComponentName;
|
|
20
|
+
const getComponentBundleId = (component) => `${component.meta.bundleName}@${component.meta.version}`;
|
|
21
|
+
exports.getComponentBundleId = getComponentBundleId;
|
|
22
|
+
/**
|
|
23
|
+
* a => ''
|
|
24
|
+
* @a/b => ''
|
|
25
|
+
* a/b => a
|
|
26
|
+
* @a/b/c => @a/b
|
|
27
|
+
* a/@b/c => a
|
|
28
|
+
* @a/b/@c/d => @a/b
|
|
29
|
+
* @a/b/@c/d/e => @a/b/@c/d
|
|
30
|
+
* @a/b/@c/d/@e/f => @a/b/@c/d
|
|
31
|
+
*/
|
|
32
|
+
const getParentComponentName = (name) => {
|
|
33
|
+
if (!name) {
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
36
|
+
const arr = name.split('/');
|
|
37
|
+
arr.pop();
|
|
38
|
+
if (!arr.length) {
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
if (arr[arr.length - 1].startsWith('@')) {
|
|
42
|
+
arr.pop();
|
|
43
|
+
}
|
|
44
|
+
if (!arr.length) {
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
return arr.join('/');
|
|
48
|
+
};
|
|
49
|
+
exports.getParentComponentName = getParentComponentName;
|
|
50
|
+
const forEachBlocklet = (blocklet, cb, { parallel = false, concurrencyLimit = 5, sync, params: inputParams, _parent, _root, _level = 0, _tasks: inputTasks, _ancestors = [], _limit, } = {}) => {
|
|
51
|
+
const root = _root || _parent || blocklet;
|
|
52
|
+
// id maybe meaningless if no meta in blocklet or _ancestors
|
|
53
|
+
const id = getComponentId(blocklet, _ancestors);
|
|
54
|
+
const newAncestors = _ancestors.concat(blocklet);
|
|
55
|
+
// sync
|
|
56
|
+
if (sync) {
|
|
57
|
+
const params = cb(blocklet, {
|
|
58
|
+
parent: _parent,
|
|
59
|
+
root,
|
|
60
|
+
level: _level,
|
|
61
|
+
params: inputParams,
|
|
62
|
+
ancestors: _ancestors,
|
|
63
|
+
id,
|
|
64
|
+
});
|
|
65
|
+
if (blocklet.children) {
|
|
66
|
+
for (const child of blocklet.children) {
|
|
67
|
+
forEachBlocklet(child, cb, {
|
|
68
|
+
sync,
|
|
69
|
+
params,
|
|
70
|
+
_parent: blocklet,
|
|
71
|
+
_root: root,
|
|
72
|
+
_level: _level + 1,
|
|
73
|
+
_ancestors: newAncestors,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
// serial
|
|
80
|
+
if (!parallel) {
|
|
81
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
82
|
+
return new Promise(async (resolve, reject) => {
|
|
83
|
+
try {
|
|
84
|
+
const params = await cb(blocklet, {
|
|
85
|
+
parent: _parent,
|
|
86
|
+
root,
|
|
87
|
+
level: _level,
|
|
88
|
+
ancestors: _ancestors,
|
|
89
|
+
params: inputParams,
|
|
90
|
+
id,
|
|
91
|
+
});
|
|
92
|
+
if (blocklet.children) {
|
|
93
|
+
for (const child of blocklet.children) {
|
|
94
|
+
await forEachBlocklet(child, cb, {
|
|
95
|
+
params,
|
|
96
|
+
_parent: blocklet,
|
|
97
|
+
_root: root,
|
|
98
|
+
_level: _level + 1,
|
|
99
|
+
_ancestors: newAncestors,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
resolve(null);
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
reject(err);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// parallel
|
|
111
|
+
const limit = _limit || (0, p_limit_1.default)(concurrencyLimit);
|
|
112
|
+
const tasks = inputTasks || [];
|
|
113
|
+
tasks.push(limit(() => cb(blocklet, { parent: _parent, root, level: _level, ancestors: _ancestors, id })));
|
|
8
114
|
if (blocklet.children) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
115
|
+
for (const child of blocklet.children) {
|
|
116
|
+
forEachBlocklet(child, cb, {
|
|
117
|
+
parallel,
|
|
118
|
+
_parent: blocklet,
|
|
119
|
+
_root: root,
|
|
120
|
+
_level: _level + 1,
|
|
121
|
+
_tasks: tasks,
|
|
122
|
+
_ancestors: newAncestors,
|
|
123
|
+
_limit: limit,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (inputTasks) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return Promise.all(tasks);
|
|
131
|
+
};
|
|
132
|
+
exports.forEachBlocklet = forEachBlocklet;
|
|
133
|
+
const forEachBlockletSync = (blocklet, cb) => forEachBlocklet(blocklet, cb, { sync: true });
|
|
134
|
+
exports.forEachBlockletSync = forEachBlockletSync;
|
|
135
|
+
const forEachChild = (blocklet, cb, params) => {
|
|
136
|
+
return forEachBlocklet(blocklet, (b, opt) => {
|
|
137
|
+
if (opt.level === 0) {
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
return cb(b, opt);
|
|
141
|
+
}, params);
|
|
142
|
+
};
|
|
143
|
+
exports.forEachChild = forEachChild;
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
145
|
+
const forEachChildSync = (blocklet, cb) => forEachChild(blocklet, cb, { sync: true });
|
|
146
|
+
exports.forEachChildSync = forEachChildSync;
|
|
147
|
+
const findComponent = (blocklet, isEqualFn, { _ancestors = [], returnAncestors = false, } = {}) => {
|
|
148
|
+
if (!isEqualFn) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
if (isEqualFn(blocklet, { ancestors: _ancestors })) {
|
|
152
|
+
if (returnAncestors) {
|
|
153
|
+
return {
|
|
154
|
+
component: blocklet,
|
|
155
|
+
ancestors: _ancestors,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return blocklet;
|
|
159
|
+
}
|
|
160
|
+
for (const child of blocklet.children || []) {
|
|
161
|
+
const ancestors = _ancestors.concat(blocklet);
|
|
162
|
+
const component = findComponent(child, isEqualFn, { _ancestors: ancestors, returnAncestors });
|
|
163
|
+
if (component) {
|
|
164
|
+
return component;
|
|
165
|
+
}
|
|
12
166
|
}
|
|
13
167
|
return null;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
168
|
+
};
|
|
169
|
+
exports.findComponent = findComponent;
|
|
170
|
+
const findComponentById = (blocklet, componentId, { returnAncestors = false, } = {}) => {
|
|
171
|
+
if (Array.isArray(componentId)) {
|
|
172
|
+
// eslint-disable-next-line no-param-reassign
|
|
173
|
+
componentId = componentId.join('/');
|
|
174
|
+
}
|
|
175
|
+
return findComponent(blocklet, (component, { ancestors }) => {
|
|
176
|
+
const id = getComponentId(component, ancestors);
|
|
177
|
+
return componentId === id;
|
|
178
|
+
}, { returnAncestors });
|
|
179
|
+
};
|
|
180
|
+
exports.findComponentById = findComponentById;
|
|
181
|
+
const isEnvShareable = (env) => {
|
|
182
|
+
return (!!env &&
|
|
183
|
+
!!(env.key || env.name) &&
|
|
184
|
+
!env.secure &&
|
|
185
|
+
env.shared !== false &&
|
|
186
|
+
!BLOCKLET_CONFIGURABLE_KEY[env.key || env.name]);
|
|
187
|
+
};
|
|
188
|
+
exports.isEnvShareable = isEnvShareable;
|
|
189
|
+
const getSharedConfigObj = (component, ancestors) => {
|
|
190
|
+
const res = {};
|
|
191
|
+
if (!ancestors) {
|
|
192
|
+
return res;
|
|
193
|
+
}
|
|
194
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
195
|
+
const ancestor = ancestors[i];
|
|
196
|
+
if (Array.isArray(ancestor.configs)) {
|
|
197
|
+
ancestor.configs.forEach(({ key, value, secure, shared }) => {
|
|
198
|
+
if (res[key]) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (!value || secure !== false || shared === false || BLOCKLET_CONFIGURABLE_KEY[key]) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const config = (component.configs || []).find((x) => x.key === key);
|
|
205
|
+
if (config && config.value) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
res[key] = (0, get_1.default)(ancestor, `configObj.${key}`) || value;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return res;
|
|
213
|
+
};
|
|
214
|
+
exports.getSharedConfigObj = getSharedConfigObj;
|
|
215
|
+
const isPreferenceKey = (x) => x.key.startsWith(BLOCKLET_PREFERENCE_PREFIX) === true;
|
|
216
|
+
exports.isPreferenceKey = isPreferenceKey;
|
|
217
|
+
const getAppMissingConfigs = (blocklet = {}) => {
|
|
218
|
+
const missingConfigs = [];
|
|
219
|
+
forEachBlockletSync(blocklet, (b, { ancestors, level }) => {
|
|
220
|
+
if (level === 0 && b.meta?.group === BlockletGroup.gateway) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const configs = b.configs || [];
|
|
224
|
+
const sharedConfigObj = getSharedConfigObj(b, ancestors);
|
|
225
|
+
configs.forEach((item) => {
|
|
226
|
+
if (item.required && !item.value && !sharedConfigObj[item.key]) {
|
|
227
|
+
missingConfigs.push({ did: b.meta.did, key: item.key, description: item.description });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
return missingConfigs.filter((x) => !isPreferenceKey(x));
|
|
232
|
+
};
|
|
233
|
+
exports.getAppMissingConfigs = getAppMissingConfigs;
|
|
234
|
+
const getComponentMissingConfigs = (component = {}, ancestors = []) => {
|
|
235
|
+
const missingConfigs = [];
|
|
236
|
+
const configs = component.configs || [];
|
|
237
|
+
const sharedConfigObj = getSharedConfigObj(component, ancestors);
|
|
238
|
+
configs.forEach((item) => {
|
|
239
|
+
if (item.required && !item.value && !sharedConfigObj[item.key]) {
|
|
240
|
+
missingConfigs.push({ did: component.meta.did, key: item.key, description: item.description });
|
|
23
241
|
}
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
})();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// parallel
|
|
30
|
-
const tasks = [];
|
|
31
|
-
tasks.push(cb(blocklet));
|
|
32
|
-
if (blocklet.children) {
|
|
33
|
-
for (const child of blocklet.children) {
|
|
34
|
-
tasks.push(cb(child));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return Promise.all(tasks);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const isAuthServiceEnabled = (blocklet) => {
|
|
41
|
-
const interfaces = get(blocklet, 'meta.interfaces') || [];
|
|
42
|
-
const isRootEnabled = interfaces.some((x) => {
|
|
43
|
-
const services = get(x, 'services') || [];
|
|
44
|
-
return services.some((s) => s.name === '@abtnode/auth-service');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (isRootEnabled) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const children = get(blocklet, 'children') || [];
|
|
52
|
-
for (const child of children) {
|
|
53
|
-
if (isAuthServiceEnabled(child)) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return false;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const getRequiredMissingConfigs = (blocklet) => {
|
|
62
|
-
const missingConfigs = [];
|
|
63
|
-
const configs = blocklet.configs || [];
|
|
64
|
-
configs.forEach((item) => {
|
|
65
|
-
if (item.required && !item.value) {
|
|
66
|
-
missingConfigs.push({ did: blocklet.meta.did, key: item.key });
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
71
|
-
for (const child of blocklet.children || []) {
|
|
72
|
-
const childConfigs = child.configs || [];
|
|
73
|
-
// configProp does not exist in root blocklet config
|
|
74
|
-
// or value of configProp in root blocklet config is empty.
|
|
75
|
-
childConfigs.forEach((x) => {
|
|
76
|
-
if (x.required && !x.value && !configs.some((y) => y.key === x.key && y.value)) {
|
|
77
|
-
missingConfigs.push({ did: child.meta.did, key: x.key });
|
|
78
|
-
}
|
|
79
242
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
243
|
+
return missingConfigs;
|
|
244
|
+
};
|
|
245
|
+
exports.getComponentMissingConfigs = getComponentMissingConfigs;
|
|
246
|
+
const isFreeBlocklet = (meta) => {
|
|
247
|
+
if (!meta.payment) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
const priceList = (meta.payment.price || []).map((x) => x.value || 0);
|
|
251
|
+
return priceList.every((x) => x === 0);
|
|
252
|
+
};
|
|
253
|
+
exports.isFreeBlocklet = isFreeBlocklet;
|
|
254
|
+
const isFreeComponent = (meta) => {
|
|
255
|
+
if (!meta.payment) {
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
if (!meta.payment.componentPrice) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
return !meta.payment.componentPrice.length;
|
|
262
|
+
};
|
|
263
|
+
exports.isFreeComponent = isFreeComponent;
|
|
264
|
+
const isComponentBlocklet = (meta) => {
|
|
265
|
+
return (0, get_1.default)(meta, 'capabilities.component') !== false;
|
|
266
|
+
};
|
|
267
|
+
exports.isComponentBlocklet = isComponentBlocklet;
|
|
268
|
+
const wipeSensitiveData = (blocklet) => {
|
|
269
|
+
if (!blocklet) {
|
|
270
|
+
return blocklet;
|
|
271
|
+
}
|
|
272
|
+
forEachBlocklet(blocklet, (d) => {
|
|
273
|
+
if (d.configs) {
|
|
274
|
+
d.configs = d.configs.filter((x) => !isPreferenceKey(x));
|
|
275
|
+
d.configs.forEach((x) => {
|
|
276
|
+
if (x.secure) {
|
|
277
|
+
x.value = x.value ? '__encrypted__' : '';
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
(d.environments || []).forEach((x) => {
|
|
282
|
+
if (['BLOCKLET_APP_SK', 'BLOCKLET_APP_PSK'].includes(x.key)) {
|
|
283
|
+
x.value = '__encrypted__';
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
(d.migratedFrom || []).forEach((x) => {
|
|
287
|
+
x.appSk = '__encrypted__';
|
|
288
|
+
});
|
|
289
|
+
// @ts-ignore
|
|
290
|
+
delete blocklet.configObj;
|
|
291
|
+
// @ts-ignore
|
|
292
|
+
delete blocklet.environmentObj;
|
|
293
|
+
}, { sync: true });
|
|
294
|
+
return blocklet;
|
|
295
|
+
};
|
|
296
|
+
exports.wipeSensitiveData = wipeSensitiveData;
|
|
297
|
+
const isDeletableBlocklet = (blocklet) => {
|
|
298
|
+
if (!blocklet) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
const config = blocklet.environments.find((x) => x.key === 'BLOCKLET_DELETABLE');
|
|
302
|
+
if (!config) {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
return config.value === 'yes';
|
|
306
|
+
};
|
|
307
|
+
exports.isDeletableBlocklet = isDeletableBlocklet;
|
|
308
|
+
const hasRunnableComponent = (blocklet) => {
|
|
309
|
+
let has = false;
|
|
310
|
+
forEachBlockletSync(blocklet, (x) => {
|
|
311
|
+
if (x.meta.group !== BlockletGroup.gateway) {
|
|
312
|
+
has = true;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
return has;
|
|
316
|
+
};
|
|
317
|
+
exports.hasRunnableComponent = hasRunnableComponent;
|
|
318
|
+
/**
|
|
319
|
+
* 获取 blocklet 的 name
|
|
320
|
+
* @param {Object} blocklet 应用数据
|
|
321
|
+
* @param {Boolean} onlyUseMeta 优先使用应用元数据的name
|
|
322
|
+
* @returns blocklet display name
|
|
323
|
+
*/
|
|
324
|
+
const getAppName = (blocklet, onlyUseMeta = false) => {
|
|
325
|
+
if (!blocklet) {
|
|
326
|
+
return '';
|
|
327
|
+
}
|
|
328
|
+
const { meta } = blocklet;
|
|
329
|
+
let name;
|
|
330
|
+
if (!onlyUseMeta && blocklet.environments) {
|
|
331
|
+
const target = blocklet.environments.find((e) => e.key === 'BLOCKLET_APP_NAME');
|
|
332
|
+
if (target && target.value) {
|
|
333
|
+
name = target.value;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return name || meta.title || meta.name;
|
|
337
|
+
};
|
|
338
|
+
exports.getAppName = getAppName;
|
|
339
|
+
exports.getDisplayName = getAppName;
|
|
340
|
+
/**
|
|
341
|
+
* 获取 blocklet 的 description
|
|
342
|
+
* @param {Object} blocklet 应用数据
|
|
343
|
+
* @param {Boolean} onlyUseMeta 优先使用应用元数据的name
|
|
344
|
+
* @returns blocklet display description
|
|
345
|
+
*/
|
|
346
|
+
const getAppDescription = (blocklet, onlyUseMeta = false) => {
|
|
347
|
+
if (!blocklet) {
|
|
348
|
+
return '';
|
|
349
|
+
}
|
|
350
|
+
const { meta } = blocklet;
|
|
351
|
+
let description;
|
|
352
|
+
if (!onlyUseMeta && blocklet.environments) {
|
|
353
|
+
const target = blocklet.environments.find((e) => e.key === 'BLOCKLET_APP_DESCRIPTION');
|
|
354
|
+
if (target && target.value) {
|
|
355
|
+
description = target.value;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return description || meta.description || meta.name;
|
|
359
|
+
};
|
|
360
|
+
exports.getAppDescription = getAppDescription;
|
|
361
|
+
const fixBlockletStatus = (blocklet) => {
|
|
362
|
+
if (!blocklet) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
forEachBlockletSync(blocklet, (b) => {
|
|
366
|
+
b.status = fromBlockletStatus(b.status);
|
|
367
|
+
if (b.source !== undefined) {
|
|
368
|
+
b.source = fromBlockletSource(b.source);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
if (blocklet.settings) {
|
|
372
|
+
(blocklet.settings.children || []).forEach((child) => {
|
|
373
|
+
forEachBlockletSync(child, (b) => {
|
|
374
|
+
b.status = fromBlockletStatus(b.status);
|
|
375
|
+
if (b.source !== undefined) {
|
|
376
|
+
b.source = fromBlockletSource(b.source);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
exports.fixBlockletStatus = fixBlockletStatus;
|
|
383
|
+
const findWebInterface = (blocklet) => {
|
|
384
|
+
if (!blocklet) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
// @ts-ignore
|
|
388
|
+
const meta = blocklet.meta || blocklet || {};
|
|
389
|
+
const { interfaces = [] } = meta;
|
|
390
|
+
if (!Array.isArray(interfaces)) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
return interfaces.find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
|
|
394
|
+
};
|
|
395
|
+
exports.findWebInterface = findWebInterface;
|
|
396
|
+
const findWebInterfacePort = (blocklet) => {
|
|
397
|
+
if (!blocklet) {
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
const webInterface = findWebInterface(blocklet);
|
|
401
|
+
const { ports } = blocklet;
|
|
402
|
+
if (!webInterface || !ports) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
return ports[webInterface.port];
|
|
406
|
+
};
|
|
407
|
+
exports.findWebInterfacePort = findWebInterfacePort;
|
|
408
|
+
const findServiceFromMeta = (meta, ServiceName) => {
|
|
409
|
+
const names = [ServiceName];
|
|
410
|
+
// backward compatible
|
|
411
|
+
if (ServiceName === NODE_SERVICES.AUTH) {
|
|
412
|
+
names.push(NODE_SERVICES.AUTH_SERVICE);
|
|
413
|
+
}
|
|
414
|
+
const webInterface = findWebInterface(meta);
|
|
415
|
+
if (!webInterface) {
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
return (webInterface.services || []).find((x) => names.includes(x.name));
|
|
419
|
+
};
|
|
420
|
+
exports.findServiceFromMeta = findServiceFromMeta;
|
|
421
|
+
const getWhoCanAccess = (blocklet) => {
|
|
422
|
+
if (!blocklet) {
|
|
423
|
+
return WHO_CAN_ACCESS.ALL;
|
|
424
|
+
}
|
|
425
|
+
if ((0, get_1.default)(blocklet, 'settings.whoCanAccess')) {
|
|
426
|
+
return blocklet.settings.whoCanAccess;
|
|
427
|
+
}
|
|
428
|
+
// @ts-ignore
|
|
429
|
+
const service = findServiceFromMeta(blocklet.meta, NODE_SERVICES.AUTH);
|
|
430
|
+
if ((0, get_1.default)(service, 'config.whoCanAccess')) {
|
|
431
|
+
return service.config.whoCanAccess;
|
|
432
|
+
}
|
|
433
|
+
return WHO_CAN_ACCESS.ALL;
|
|
434
|
+
};
|
|
435
|
+
exports.getWhoCanAccess = getWhoCanAccess;
|
|
436
|
+
const getConnectAppUrl = ({ request, baseUrl }) => {
|
|
437
|
+
const blockletDid = request.headers['x-blocklet-did'] || '';
|
|
438
|
+
const blockletRealDid = request.headers['x-blocklet-real-did'] || '';
|
|
439
|
+
const pathPrefix = request.headers['x-path-prefix'] || '/';
|
|
440
|
+
const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
|
|
441
|
+
// Child blocklets should set appInfo.link to exactly the same path as the root blocklet
|
|
442
|
+
let appUrl = baseUrl;
|
|
443
|
+
if (blockletDid !== blockletRealDid && pathPrefix !== groupPathPrefix) {
|
|
444
|
+
appUrl = (0, url_join_1.default)((0, url_join_1.default)(appUrl, '/').replace(pathPrefix, groupPathPrefix), '');
|
|
445
|
+
}
|
|
446
|
+
return appUrl;
|
|
447
|
+
};
|
|
448
|
+
exports.getConnectAppUrl = getConnectAppUrl;
|
|
449
|
+
const replaceSlotToIp = (url, ip) => (url || '').replace(SLOT_FOR_IP_DNS_SITE, (ip || '').replace(/\./g, '-'));
|
|
450
|
+
exports.replaceSlotToIp = replaceSlotToIp;
|
|
451
|
+
// transform process.env.CHAIN_x => { x: v }
|
|
452
|
+
const getChainInfo = (env) => Object.entries(CHAIN_INFO_CONFIG).reduce((info, x) => {
|
|
453
|
+
// @ts-expect-error TS(2488) FIXME: Type 'unknown' must have a '[Symbol.iterator]()' m... Remove this comment to see the full error message
|
|
454
|
+
const [envName, [key, value]] = x;
|
|
455
|
+
info[key] = (0, get_1.default)(env, envName) || value;
|
|
456
|
+
return info;
|
|
457
|
+
}, {});
|
|
458
|
+
exports.getChainInfo = getChainInfo;
|
|
459
|
+
const isExternalBlocklet = (blocklet) => !!blocklet?.controller;
|
|
460
|
+
exports.isExternalBlocklet = isExternalBlocklet;
|
|
461
|
+
const getRolesFromAuthConfig = (config) => {
|
|
462
|
+
if (!config.whoCanAccess.startsWith(WHO_CAN_ACCESS_PREFIX_ROLES)) {
|
|
463
|
+
return [];
|
|
464
|
+
}
|
|
465
|
+
return config.whoCanAccess.substring(WHO_CAN_ACCESS_PREFIX_ROLES.length).split(',');
|
|
466
|
+
};
|
|
467
|
+
exports.getRolesFromAuthConfig = getRolesFromAuthConfig;
|
|
468
|
+
const getBlockletAppIdList = (blocklet) => {
|
|
469
|
+
const migratedFrom = Array.isArray(blocklet.migratedFrom) ? blocklet.migratedFrom.map((x) => x.appDid) : [];
|
|
470
|
+
return (0, uniq_1.default)([blocklet.appDid, blocklet.appPid, ...migratedFrom].filter(Boolean));
|
|
471
|
+
};
|
|
472
|
+
exports.getBlockletAppIdList = getBlockletAppIdList;
|
|
473
|
+
exports.default = {
|
|
474
|
+
isFreeBlocklet,
|
|
475
|
+
isFreeComponent,
|
|
476
|
+
isComponentBlocklet,
|
|
477
|
+
forEachBlocklet,
|
|
478
|
+
forEachBlockletSync,
|
|
479
|
+
forEachChild,
|
|
480
|
+
forEachChildSync,
|
|
481
|
+
isDeletableBlocklet,
|
|
482
|
+
getSharedConfigObj,
|
|
483
|
+
getAppMissingConfigs,
|
|
484
|
+
getComponentMissingConfigs,
|
|
485
|
+
isEnvShareable,
|
|
486
|
+
wipeSensitiveData,
|
|
487
|
+
hasRunnableComponent,
|
|
488
|
+
getAppName,
|
|
489
|
+
getAppDescription,
|
|
490
|
+
getDisplayName: getAppName,
|
|
491
|
+
fixBlockletStatus,
|
|
492
|
+
findWebInterface,
|
|
493
|
+
findWebInterfacePort,
|
|
494
|
+
findServiceFromMeta,
|
|
495
|
+
getWhoCanAccess,
|
|
496
|
+
replaceSlotToIp,
|
|
497
|
+
getComponentId,
|
|
498
|
+
getComponentName,
|
|
499
|
+
getComponentBundleId,
|
|
500
|
+
findComponent,
|
|
501
|
+
findComponentById,
|
|
502
|
+
getParentComponentName,
|
|
503
|
+
getConnectAppUrl,
|
|
504
|
+
getChainInfo,
|
|
505
|
+
isExternalBlocklet,
|
|
506
|
+
isPreferenceKey,
|
|
507
|
+
getRolesFromAuthConfig,
|
|
89
508
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TBlockletMeta } from './types';
|
|
2
|
+
declare const fixAndValidateService: (meta: TBlockletMeta) => TBlockletMeta;
|
|
3
|
+
declare const validateMeta: (meta: any, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, ensureName, skipValidateDidName, schemaOptions, }?: {
|
|
4
|
+
ensureMain?: boolean;
|
|
5
|
+
ensureFiles?: boolean;
|
|
6
|
+
ensureDist?: boolean;
|
|
7
|
+
ensureComponentStore?: boolean;
|
|
8
|
+
ensureName?: boolean;
|
|
9
|
+
skipValidateDidName?: boolean;
|
|
10
|
+
schemaOptions?: any;
|
|
11
|
+
}) => TBlockletMeta;
|
|
12
|
+
export default validateMeta;
|
|
13
|
+
export { validateMeta, fixAndValidateService };
|