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