@blocklet/meta 1.6.16 → 1.6.17
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/constants.js +88 -55
- package/lib/fix.js +4 -9
- package/lib/util.js +30 -7
- package/package.json +10 -10
package/lib/constants.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const fromEntry = (entries) => (v) => {
|
|
2
|
+
const match = Object.entries(entries).find((x) => x[1] === Number(v));
|
|
3
|
+
return match ? match[0] : 'unknown';
|
|
4
|
+
};
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
const BLOCKLET_INTERFACE_TYPE_WELLKNOWN = 'wellknown';
|
|
6
|
+
const toEntry = (entries) => (v) => Object.keys(entries).find((x) => entries[x] === Number(v));
|
|
7
|
+
|
|
8
|
+
// Blocklet Status
|
|
8
9
|
|
|
9
10
|
const BlockletStatus = Object.freeze({
|
|
10
11
|
added: 0,
|
|
@@ -23,13 +24,52 @@ const BlockletStatus = Object.freeze({
|
|
|
23
24
|
waiting: 13,
|
|
24
25
|
});
|
|
25
26
|
|
|
27
|
+
const fromBlockletStatus = fromEntry(BlockletStatus);
|
|
28
|
+
const toBlockletStatus = toEntry(BlockletStatus);
|
|
29
|
+
|
|
30
|
+
// Blocklet Source
|
|
31
|
+
|
|
26
32
|
const BlockletSource = Object.freeze({
|
|
33
|
+
// Installed from Blocklet Store
|
|
27
34
|
registry: 0,
|
|
35
|
+
|
|
36
|
+
// Installed from local development source folder
|
|
28
37
|
local: 1,
|
|
38
|
+
|
|
39
|
+
// Installed from uploading bundle directly
|
|
29
40
|
upload: 2,
|
|
41
|
+
|
|
42
|
+
// Installed from a url (similar to Blocklet Store)
|
|
30
43
|
url: 3,
|
|
44
|
+
|
|
45
|
+
// Installed by custom creation
|
|
46
|
+
custom: 4,
|
|
31
47
|
});
|
|
32
48
|
|
|
49
|
+
const fromBlockletSource = fromEntry(BlockletSource);
|
|
50
|
+
const toBlockletSource = toEntry(BlockletSource);
|
|
51
|
+
|
|
52
|
+
// Blocklet Group(Type)
|
|
53
|
+
|
|
54
|
+
const BlockletGroup = Object.freeze({
|
|
55
|
+
// Only static website
|
|
56
|
+
// The website is served by by Blocklet Server at runtime
|
|
57
|
+
static: 'static',
|
|
58
|
+
|
|
59
|
+
// The runtime instance is provided by its own backend server
|
|
60
|
+
dapp: 'dapp',
|
|
61
|
+
|
|
62
|
+
starter: false, // deprecated
|
|
63
|
+
|
|
64
|
+
// This type is used to combine other component blocklets
|
|
65
|
+
// No instance will be spawned at runtime
|
|
66
|
+
gateway: 'gateway',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const BLOCKLET_GROUPS = ['dapp', 'static', 'gateway'];
|
|
70
|
+
|
|
71
|
+
// Blocklet Events
|
|
72
|
+
|
|
33
73
|
const BlockletEvents = Object.freeze({
|
|
34
74
|
added: 'blocklet.added',
|
|
35
75
|
downloadFailed: 'blocklet.downloadFailed',
|
|
@@ -48,45 +88,52 @@ const BlockletEvents = Object.freeze({
|
|
|
48
88
|
purchaseChange: 'blocklet.purchaseChange',
|
|
49
89
|
});
|
|
50
90
|
|
|
51
|
-
|
|
52
|
-
const match = Object.entries(entries).find((x) => x[1] === Number(v));
|
|
53
|
-
return match ? match[0] : 'unknown';
|
|
54
|
-
};
|
|
91
|
+
// Blocklet Interface
|
|
55
92
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const fromBlockletStatus = fromEntry(BlockletStatus);
|
|
59
|
-
const toBlockletStatus = toEntry(BlockletStatus);
|
|
93
|
+
const BLOCKLET_INTERFACE_TYPE_WEB = 'web';
|
|
94
|
+
const BLOCKLET_INTERFACE_TYPE_SERVICE = 'service';
|
|
60
95
|
|
|
61
|
-
|
|
62
|
-
|
|
96
|
+
// Wellknown interface declares an sub-interface under web interface
|
|
97
|
+
// The path of the wellknown interface must starts with /.well-known, e.g. /.well-known/acme-challenge)
|
|
98
|
+
// The wellknown interface can be mounted to every endpoint of the abtnode and all blocklets on the abtnode
|
|
99
|
+
const BLOCKLET_INTERFACE_TYPE_WELLKNOWN = 'wellknown';
|
|
100
|
+
const BLOCKLET_INTERFACE_TYPES = [
|
|
101
|
+
BLOCKLET_INTERFACE_TYPE_WEB,
|
|
102
|
+
BLOCKLET_INTERFACE_TYPE_SERVICE,
|
|
103
|
+
BLOCKLET_INTERFACE_TYPE_WELLKNOWN,
|
|
104
|
+
];
|
|
63
105
|
|
|
64
106
|
const BLOCKLET_INTERFACE_PUBLIC = 'publicUrl';
|
|
65
|
-
const BLOCKLET_INTERFACE_ADMIN = 'adminUrl';
|
|
66
|
-
const BLOCKLET_INTERFACE_CONFIG = 'configUrl';
|
|
67
|
-
const BLOCKLET_INTERFACE_DOC = 'docUrl';
|
|
68
107
|
const BLOCKLET_INTERFACE_WELLKNOWN = 'wellknownUrl'; // Deprecated
|
|
108
|
+
const BLOCKLET_UI_INTERFACES = [BLOCKLET_INTERFACE_PUBLIC];
|
|
109
|
+
const BLOCKLET_STANDARD_INTERFACES = [BLOCKLET_INTERFACE_PUBLIC, BLOCKLET_INTERFACE_WELLKNOWN];
|
|
110
|
+
|
|
111
|
+
const BLOCKLET_INTERFACE_PROTOCOL_HTTP = 'http';
|
|
112
|
+
const BLOCKLET_INTERFACE_PROTOCOL_TCP = 'tcp';
|
|
113
|
+
const BLOCKLET_INTERFACE_PROTOCOL_UDP = 'udp';
|
|
114
|
+
const BLOCKLET_INTERFACE_PROTOCOLS = [
|
|
115
|
+
BLOCKLET_INTERFACE_PROTOCOL_TCP,
|
|
116
|
+
BLOCKLET_INTERFACE_PROTOCOL_UDP,
|
|
117
|
+
BLOCKLET_INTERFACE_PROTOCOL_HTTP,
|
|
118
|
+
];
|
|
69
119
|
|
|
70
120
|
module.exports = Object.freeze({
|
|
71
121
|
BlockletStatus,
|
|
72
|
-
BlockletSource,
|
|
73
122
|
fromBlockletStatus,
|
|
74
123
|
toBlockletStatus,
|
|
124
|
+
|
|
125
|
+
BlockletSource,
|
|
75
126
|
fromBlockletSource,
|
|
76
127
|
toBlockletSource,
|
|
77
128
|
|
|
78
|
-
BlockletGroup
|
|
79
|
-
|
|
80
|
-
dapp: 'dapp',
|
|
81
|
-
starter: false,
|
|
82
|
-
gateway: 'gateway',
|
|
83
|
-
}),
|
|
84
|
-
BLOCKLET_GROUPS: ['dapp', 'static', 'gateway'],
|
|
129
|
+
BlockletGroup,
|
|
130
|
+
BLOCKLET_GROUPS,
|
|
85
131
|
|
|
86
132
|
BlockletEvents,
|
|
87
133
|
|
|
88
134
|
BLOCKLET_PLATFORMS: ['aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', 'win32'],
|
|
89
135
|
BLOCKLET_ARCHITECTURES: ['arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', 'x64'],
|
|
136
|
+
|
|
90
137
|
BLOCKLET_MODES: Object.freeze({
|
|
91
138
|
PRODUCTION: 'production',
|
|
92
139
|
DEVELOPMENT: 'development',
|
|
@@ -94,40 +141,27 @@ module.exports = Object.freeze({
|
|
|
94
141
|
|
|
95
142
|
BLOCKLET_FACTORY_SHARES: { developer: 0.7, store: 0.3 },
|
|
96
143
|
|
|
97
|
-
|
|
98
|
-
|
|
144
|
+
// interface
|
|
99
145
|
BLOCKLET_INTERFACE_PUBLIC,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
BLOCKLET_INTERFACE_WELLKNOWN,
|
|
104
|
-
|
|
105
|
-
BLOCKLET_UI_INTERFACES: [
|
|
106
|
-
BLOCKLET_INTERFACE_PUBLIC,
|
|
107
|
-
BLOCKLET_INTERFACE_ADMIN,
|
|
108
|
-
BLOCKLET_INTERFACE_CONFIG,
|
|
109
|
-
BLOCKLET_INTERFACE_DOC,
|
|
110
|
-
],
|
|
111
|
-
|
|
112
|
-
BLOCKLET_STANDARD_INTERFACES: [
|
|
113
|
-
BLOCKLET_INTERFACE_PUBLIC,
|
|
114
|
-
BLOCKLET_INTERFACE_ADMIN,
|
|
115
|
-
BLOCKLET_INTERFACE_CONFIG,
|
|
116
|
-
BLOCKLET_INTERFACE_DOC,
|
|
117
|
-
BLOCKLET_INTERFACE_WELLKNOWN,
|
|
118
|
-
],
|
|
146
|
+
BLOCKLET_INTERFACE_WELLKNOWN, // Deprecated
|
|
147
|
+
BLOCKLET_UI_INTERFACES,
|
|
148
|
+
BLOCKLET_STANDARD_INTERFACES,
|
|
119
149
|
|
|
120
150
|
BLOCKLET_INTERFACE_TYPE_WEB,
|
|
121
151
|
BLOCKLET_INTERFACE_TYPE_SERVICE,
|
|
122
152
|
BLOCKLET_INTERFACE_TYPE_WELLKNOWN,
|
|
123
|
-
BLOCKLET_INTERFACE_TYPES
|
|
124
|
-
BLOCKLET_INTERFACE_TYPE_WEB,
|
|
125
|
-
BLOCKLET_INTERFACE_TYPE_SERVICE,
|
|
126
|
-
BLOCKLET_INTERFACE_TYPE_WELLKNOWN,
|
|
127
|
-
],
|
|
153
|
+
BLOCKLET_INTERFACE_TYPES,
|
|
128
154
|
|
|
129
|
-
|
|
155
|
+
BLOCKLET_INTERFACE_PROTOCOL_HTTP,
|
|
156
|
+
BLOCKLET_INTERFACE_PROTOCOL_TCP,
|
|
157
|
+
BLOCKLET_INTERFACE_PROTOCOL_UDP,
|
|
158
|
+
BLOCKLET_INTERFACE_PROTOCOLS,
|
|
130
159
|
|
|
160
|
+
BLOCKLET_DYNAMIC_PATH_PREFIX: '*',
|
|
161
|
+
BLOCKLET_DEFAULT_PORT_NAME: 'BLOCKLET_PORT',
|
|
162
|
+
BLOCKLET_DEFAULT_PATH_REWRITE: '/',
|
|
163
|
+
|
|
164
|
+
// bundle
|
|
131
165
|
BLOCKLET_RELEASE_FOLDER: '.blocklet/release',
|
|
132
166
|
BLOCKLET_RELEASE_FILE: 'blocklet.json',
|
|
133
167
|
BLOCKLET_BUNDLE_FOLDER: '.blocklet/bundle',
|
|
@@ -138,7 +172,6 @@ module.exports = Object.freeze({
|
|
|
138
172
|
BLOCKLET_META_FILE_OLD: 'blocklet.json',
|
|
139
173
|
|
|
140
174
|
BLOCKLET_DEFAULT_VERSION: '1.0.0',
|
|
141
|
-
BLOCKLET_DEFAULT_PORT_NAME: 'BLOCKLET_PORT',
|
|
142
175
|
|
|
143
176
|
BLOCKLET_LATEST_SPEC_VERSION: '1.2.1',
|
|
144
177
|
BLOCKLET_LATEST_REQUIREMENT_SERVER: '>=1.6.2',
|
package/lib/fix.js
CHANGED
|
@@ -12,9 +12,6 @@ const {
|
|
|
12
12
|
BLOCKLET_DYNAMIC_PATH_PREFIX,
|
|
13
13
|
BLOCKLET_INTERFACE_TYPE_WEB,
|
|
14
14
|
BLOCKLET_INTERFACE_PUBLIC,
|
|
15
|
-
BLOCKLET_INTERFACE_ADMIN,
|
|
16
|
-
BLOCKLET_INTERFACE_CONFIG,
|
|
17
|
-
BLOCKLET_INTERFACE_DOC,
|
|
18
15
|
} = require('./constants');
|
|
19
16
|
|
|
20
17
|
// Assign sensible defaults: name/description/main/group/version/public_url
|
|
@@ -203,13 +200,11 @@ const fixInterfaces = (meta, removeMerged = true) => {
|
|
|
203
200
|
meta.interfaces.push({ type, name, path, prefix, port, protocol });
|
|
204
201
|
};
|
|
205
202
|
|
|
206
|
-
[BLOCKLET_INTERFACE_PUBLIC
|
|
207
|
-
(x)
|
|
208
|
-
|
|
209
|
-
addInterface({ name: x, path: meta[x] });
|
|
210
|
-
}
|
|
203
|
+
[BLOCKLET_INTERFACE_PUBLIC].forEach((x) => {
|
|
204
|
+
if (meta[x]) {
|
|
205
|
+
addInterface({ name: x, path: meta[x] });
|
|
211
206
|
}
|
|
212
|
-
);
|
|
207
|
+
});
|
|
213
208
|
|
|
214
209
|
if (Array.isArray(meta.exposeServices)) {
|
|
215
210
|
meta.exposeServices.forEach((x) => {
|
package/lib/util.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable no-await-in-loop */
|
|
2
2
|
const get = require('lodash/get');
|
|
3
3
|
|
|
4
|
+
const { BlockletGroup } = require('./constants');
|
|
5
|
+
|
|
4
6
|
const forEachBlocklet = (blocklet, cb, { parallel = false, sync } = {}) => {
|
|
5
7
|
// sync
|
|
6
8
|
if (sync) {
|
|
@@ -15,15 +17,21 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, sync } = {}) => {
|
|
|
15
17
|
|
|
16
18
|
// serial
|
|
17
19
|
if (!parallel) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
21
|
+
return new Promise(async (resolve, reject) => {
|
|
22
|
+
try {
|
|
23
|
+
await cb(blocklet);
|
|
24
|
+
if (blocklet.children) {
|
|
25
|
+
for (const child of blocklet.children) {
|
|
26
|
+
await cb(child);
|
|
27
|
+
}
|
|
23
28
|
}
|
|
29
|
+
|
|
30
|
+
resolve(null);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
reject(err);
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
})();
|
|
34
|
+
});
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
// parallel
|
|
@@ -37,6 +45,8 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, sync } = {}) => {
|
|
|
37
45
|
return Promise.all(tasks);
|
|
38
46
|
};
|
|
39
47
|
|
|
48
|
+
const forEachBlockletSync = (blocklet, cb) => forEachBlocklet(blocklet, cb, { sync: true });
|
|
49
|
+
|
|
40
50
|
const isAuthServiceEnabled = (blocklet) => {
|
|
41
51
|
const interfaces = get(blocklet, 'meta.interfaces') || [];
|
|
42
52
|
const isRootEnabled = interfaces.some((x) => {
|
|
@@ -132,11 +142,24 @@ const isDeletableBlocklet = (blocklet) => {
|
|
|
132
142
|
return config.value === 'yes';
|
|
133
143
|
};
|
|
134
144
|
|
|
145
|
+
const hasRunnableComponent = (blocklet) => {
|
|
146
|
+
let has = false;
|
|
147
|
+
forEachBlockletSync(blocklet, (x) => {
|
|
148
|
+
if (x.meta.group !== BlockletGroup.gateway) {
|
|
149
|
+
has = true;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return has;
|
|
154
|
+
};
|
|
155
|
+
|
|
135
156
|
module.exports = {
|
|
136
157
|
isFreeBlocklet,
|
|
158
|
+
forEachBlockletSync,
|
|
137
159
|
isDeletableBlocklet,
|
|
138
160
|
forEachBlocklet,
|
|
139
161
|
isAuthServiceEnabled,
|
|
140
162
|
getRequiredMissingConfigs,
|
|
141
163
|
wipeSensitiveData,
|
|
164
|
+
hasRunnableComponent,
|
|
142
165
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.6.
|
|
6
|
+
"version": "1.6.17",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@arcblock/did": "^1.14.
|
|
22
|
-
"@arcblock/did-ext": "^1.14.
|
|
23
|
-
"@arcblock/did-util": "^1.14.
|
|
24
|
-
"@arcblock/nft": "^1.14.
|
|
25
|
-
"@ocap/asset": "^1.14.
|
|
26
|
-
"@ocap/mcrypto": "^1.14.
|
|
27
|
-
"@ocap/util": "^1.14.
|
|
28
|
-
"@ocap/wallet": "^1.14.
|
|
21
|
+
"@arcblock/did": "^1.14.8",
|
|
22
|
+
"@arcblock/did-ext": "^1.14.8",
|
|
23
|
+
"@arcblock/did-util": "^1.14.8",
|
|
24
|
+
"@arcblock/nft": "^1.14.8",
|
|
25
|
+
"@ocap/asset": "^1.14.8",
|
|
26
|
+
"@ocap/mcrypto": "^1.14.8",
|
|
27
|
+
"@ocap/util": "^1.14.8",
|
|
28
|
+
"@ocap/wallet": "^1.14.8",
|
|
29
29
|
"ajv": "^7.0.3",
|
|
30
30
|
"debug": "^4.3.3",
|
|
31
31
|
"fs-extra": "^10.0.0",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"jest": "^27.4.5"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "d567a622a779eba43c95eaeb4633cb2b276bb7b9"
|
|
46
46
|
}
|