@abtnode/core 1.8.13 → 1.8.14
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/states/blocklet.js +3 -1
- package/lib/util/blocklet.js +9 -83
- package/lib/util/index.js +0 -64
- package/package.json +23 -24
package/lib/states/blocklet.js
CHANGED
package/lib/util/blocklet.js
CHANGED
|
@@ -9,8 +9,6 @@ const streamToPromise = require('stream-to-promise');
|
|
|
9
9
|
const { Throttle } = require('stream-throttle');
|
|
10
10
|
const ssri = require('ssri');
|
|
11
11
|
const diff = require('deep-diff');
|
|
12
|
-
const any = require('promise.any');
|
|
13
|
-
const joinUrl = require('url-join');
|
|
14
12
|
|
|
15
13
|
const { toHex } = require('@ocap/util');
|
|
16
14
|
const logger = require('@abtnode/logger')('@abtnode/core:util:blocklet');
|
|
@@ -22,7 +20,7 @@ const getFolderSize = require('@abtnode/util/lib/get-folder-size');
|
|
|
22
20
|
const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
|
|
23
21
|
const hashFiles = require('@abtnode/util/lib/hash-files');
|
|
24
22
|
const isPathPrefixEqual = require('@abtnode/util/lib/is-path-prefix-equal');
|
|
25
|
-
const { BLOCKLET_MAX_MEM_LIMIT_IN_MB
|
|
23
|
+
const { BLOCKLET_MAX_MEM_LIMIT_IN_MB } = require('@abtnode/constant');
|
|
26
24
|
|
|
27
25
|
const {
|
|
28
26
|
BlockletStatus,
|
|
@@ -55,19 +53,17 @@ const {
|
|
|
55
53
|
} = require('@blocklet/meta/lib/util');
|
|
56
54
|
const toBlockletDid = require('@blocklet/meta/lib/did');
|
|
57
55
|
const { titleSchema, descriptionSchema } = require('@blocklet/meta/lib/schema');
|
|
56
|
+
const {
|
|
57
|
+
getSourceUrlsFromConfig,
|
|
58
|
+
getBlockletMetaFromUrls,
|
|
59
|
+
getBlockletMetaFromUrl,
|
|
60
|
+
} = require('@blocklet/meta/lib/util-meta');
|
|
58
61
|
|
|
59
62
|
const { validate: validateEngine, get: getEngine } = require('../blocklet/manager/engine');
|
|
60
63
|
|
|
61
64
|
const isRequirementsSatisfied = require('./requirement');
|
|
62
65
|
const { getDidDomainForBlocklet } = require('./get-domain-for-blocklet');
|
|
63
|
-
const {
|
|
64
|
-
isBeforeInstalled,
|
|
65
|
-
expandBundle,
|
|
66
|
-
getBlockletMetaByUrl,
|
|
67
|
-
validateUrl,
|
|
68
|
-
findInterfacePortByName,
|
|
69
|
-
validateBlockletMeta,
|
|
70
|
-
} = require('./index');
|
|
66
|
+
const { isBeforeInstalled, expandBundle, findInterfacePortByName, validateBlockletMeta } = require('./index');
|
|
71
67
|
|
|
72
68
|
/**
|
|
73
69
|
* get blocklet engine info, default is node
|
|
@@ -406,45 +402,6 @@ const getHealthyCheckTimeout = (blocklet, { checkHealthImmediately } = {}) => {
|
|
|
406
402
|
};
|
|
407
403
|
};
|
|
408
404
|
|
|
409
|
-
const getBlockletMetaFromUrl = async (url) => {
|
|
410
|
-
const meta = await getBlockletMetaByUrl(url);
|
|
411
|
-
delete meta.htmlAst;
|
|
412
|
-
|
|
413
|
-
validateBlockletMeta(meta, { ensureDist: true });
|
|
414
|
-
|
|
415
|
-
try {
|
|
416
|
-
const { href } = new URL(meta.dist.tarball, url);
|
|
417
|
-
const tarball = decodeURIComponent(href);
|
|
418
|
-
|
|
419
|
-
try {
|
|
420
|
-
await validateUrl(tarball, ['application/octet-stream', 'application/x-gzip']);
|
|
421
|
-
} catch (error) {
|
|
422
|
-
if (!error.message.startsWith('Cannot get content-type')) {
|
|
423
|
-
throw error;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
logger.info('resolve tarball url base on meta url', { meta: url, tarball });
|
|
427
|
-
|
|
428
|
-
meta.dist.tarball = tarball;
|
|
429
|
-
} catch (err) {
|
|
430
|
-
const msg = `Invalid blocklet meta: dist.tarball is not a valid url ${err.message}`;
|
|
431
|
-
logger.error(msg);
|
|
432
|
-
throw new Error(msg);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return meta;
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
const getBlockletMetaFromUrls = async (urls) => {
|
|
439
|
-
try {
|
|
440
|
-
const meta = await any(urls.map(getBlockletMetaFromUrl));
|
|
441
|
-
return meta;
|
|
442
|
-
} catch (err) {
|
|
443
|
-
logger.error('failed get blocklet meta', { urls, error: err });
|
|
444
|
-
throw new Error('Failed get blocklet meta');
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
|
|
448
405
|
/**
|
|
449
406
|
* Start all precesses of a blocklet
|
|
450
407
|
* @param {*} blocklet should contain env props
|
|
@@ -695,36 +652,6 @@ const parseChildren = (children, parentMeta = {}, { dynamic } = {}) => {
|
|
|
695
652
|
return children;
|
|
696
653
|
};
|
|
697
654
|
|
|
698
|
-
/**
|
|
699
|
-
* @param {*} config defined in childrenSchema in blocklet meta schema
|
|
700
|
-
*/
|
|
701
|
-
const getSourceUrlsFromConfig = (config) => {
|
|
702
|
-
if (config.source) {
|
|
703
|
-
if (config.source.url) {
|
|
704
|
-
return [config.source.url].flat();
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
const { store, version, name } = config.source;
|
|
708
|
-
return [store]
|
|
709
|
-
.flat()
|
|
710
|
-
.map((x) =>
|
|
711
|
-
joinUrl(
|
|
712
|
-
x,
|
|
713
|
-
BLOCKLET_STORE_API_BLOCKLET_PREFIX,
|
|
714
|
-
toBlockletDid(name),
|
|
715
|
-
!version || version === 'latest' ? '' : version,
|
|
716
|
-
'blocklet.json'
|
|
717
|
-
)
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
if (config.resolved) {
|
|
722
|
-
return [config.resolved];
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
throw new Error('Invalid child config');
|
|
726
|
-
};
|
|
727
|
-
|
|
728
655
|
/**
|
|
729
656
|
* this function has side effect on children
|
|
730
657
|
*/
|
|
@@ -752,7 +679,7 @@ const parseChildrenFromMeta = async (src, context = {}) => {
|
|
|
752
679
|
|
|
753
680
|
let m;
|
|
754
681
|
try {
|
|
755
|
-
m = await getBlockletMetaFromUrls(urls);
|
|
682
|
+
m = await getBlockletMetaFromUrls(urls, { logger });
|
|
756
683
|
} catch {
|
|
757
684
|
throw new Error(`Failed get component meta: ${config.title || config.name}`);
|
|
758
685
|
}
|
|
@@ -1298,7 +1225,7 @@ const ensureMeta = (meta, { name, did } = {}) => {
|
|
|
1298
1225
|
|
|
1299
1226
|
module.exports = {
|
|
1300
1227
|
forEachBlocklet,
|
|
1301
|
-
getBlockletMetaFromUrl,
|
|
1228
|
+
getBlockletMetaFromUrl: (url) => getBlockletMetaFromUrl(url, { logger }),
|
|
1302
1229
|
parseChildrenFromMeta,
|
|
1303
1230
|
parseChildren,
|
|
1304
1231
|
getComponentDirs,
|
|
@@ -1334,5 +1261,4 @@ module.exports = {
|
|
|
1334
1261
|
needBlockletDownload,
|
|
1335
1262
|
findAvailableDid,
|
|
1336
1263
|
ensureMeta,
|
|
1337
|
-
getSourceUrlsFromConfig,
|
|
1338
1264
|
};
|
package/lib/util/index.js
CHANGED
|
@@ -36,8 +36,6 @@ const DEFAULT_WELLKNOWN_PORT = 8088;
|
|
|
36
36
|
|
|
37
37
|
const logger = require('@abtnode/logger')('@abtnode/core:util');
|
|
38
38
|
|
|
39
|
-
const request = require('./request');
|
|
40
|
-
|
|
41
39
|
const validateOwner = (owner) => {
|
|
42
40
|
try {
|
|
43
41
|
return owner && owner.did && owner.pk && isFromPublicKey(owner.did, owner.pk);
|
|
@@ -351,66 +349,6 @@ const getBaseUrls = async (node, ips) => {
|
|
|
351
349
|
}));
|
|
352
350
|
};
|
|
353
351
|
|
|
354
|
-
const getBlockletMetaByUrl = async (url) => {
|
|
355
|
-
const { protocol, pathname } = new URL(url);
|
|
356
|
-
|
|
357
|
-
if (protocol.startsWith('file')) {
|
|
358
|
-
const decoded = decodeURIComponent(pathname);
|
|
359
|
-
if (!fs.existsSync(decoded)) {
|
|
360
|
-
throw new Error(`File does not exist: ${decoded}`);
|
|
361
|
-
}
|
|
362
|
-
const d = await fs.promises.readFile(decoded);
|
|
363
|
-
const meta = JSON.parse(d);
|
|
364
|
-
return meta;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (protocol.startsWith('http')) {
|
|
368
|
-
const { data: meta } = await request({ url, method: 'GET', timeout: 1000 * 20 });
|
|
369
|
-
if (Object.prototype.toString.call(meta) !== '[object Object]') {
|
|
370
|
-
throw new Error('Url is not valid');
|
|
371
|
-
}
|
|
372
|
-
return meta;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
throw new Error(`Invalid url protocol: ${protocol.replace(/:$/, '')}`);
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
const validateUrl = async (url, expectedHttpResTypes = ['application/json', 'text/plain']) => {
|
|
379
|
-
const parsed = new URL(url);
|
|
380
|
-
const { protocol, pathname } = parsed;
|
|
381
|
-
|
|
382
|
-
// file
|
|
383
|
-
if (protocol.startsWith('file')) {
|
|
384
|
-
const decoded = decodeURIComponent(pathname);
|
|
385
|
-
if (!fs.existsSync(decoded)) {
|
|
386
|
-
throw new Error(`File does not exist: ${decoded}`);
|
|
387
|
-
}
|
|
388
|
-
return true;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// http(s)
|
|
392
|
-
if (protocol.startsWith('http')) {
|
|
393
|
-
let res;
|
|
394
|
-
|
|
395
|
-
try {
|
|
396
|
-
res = await request({ url, method: 'HEAD', timeout: 1000 * 10 });
|
|
397
|
-
} catch (err) {
|
|
398
|
-
throw new Error(`Cannot get content-type from ${url}: ${err.message}`);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (
|
|
402
|
-
res.headers['content-type'] &&
|
|
403
|
-
expectedHttpResTypes.some((x) => res.headers['content-type'].includes(x)) === false
|
|
404
|
-
) {
|
|
405
|
-
throw new Error(`Unexpected content-type from ${url}: ${res.headers['content-type']}`);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
return true;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
throw new Error(`Invalid url protocol: ${protocol.replace(/:$/, '')}`);
|
|
412
|
-
};
|
|
413
|
-
|
|
414
352
|
const expandBundle = (bundlePath, destDir) =>
|
|
415
353
|
unzipper.Open.file(bundlePath).then((d) => d.extract({ path: destDir, concurrency: 20 }));
|
|
416
354
|
|
|
@@ -567,8 +505,6 @@ const lib = {
|
|
|
567
505
|
fixAndValidateService(meta);
|
|
568
506
|
return validateMeta(meta, opts);
|
|
569
507
|
},
|
|
570
|
-
getBlockletMetaByUrl,
|
|
571
|
-
validateUrl,
|
|
572
508
|
expandBundle,
|
|
573
509
|
findInterfaceByName,
|
|
574
510
|
findInterfacePortByName,
|
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.14",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,32 +19,32 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/certificate-manager": "1.8.
|
|
23
|
-
"@abtnode/constant": "1.8.
|
|
24
|
-
"@abtnode/cron": "1.8.
|
|
25
|
-
"@abtnode/db": "1.8.
|
|
26
|
-
"@abtnode/logger": "1.8.
|
|
27
|
-
"@abtnode/queue": "1.8.
|
|
28
|
-
"@abtnode/rbac": "1.8.
|
|
29
|
-
"@abtnode/router-provider": "1.8.
|
|
30
|
-
"@abtnode/static-server": "1.8.
|
|
31
|
-
"@abtnode/timemachine": "1.8.
|
|
32
|
-
"@abtnode/util": "1.8.
|
|
33
|
-
"@arcblock/did": "1.17.
|
|
22
|
+
"@abtnode/certificate-manager": "1.8.14",
|
|
23
|
+
"@abtnode/constant": "1.8.14",
|
|
24
|
+
"@abtnode/cron": "1.8.14",
|
|
25
|
+
"@abtnode/db": "1.8.14",
|
|
26
|
+
"@abtnode/logger": "1.8.14",
|
|
27
|
+
"@abtnode/queue": "1.8.14",
|
|
28
|
+
"@abtnode/rbac": "1.8.14",
|
|
29
|
+
"@abtnode/router-provider": "1.8.14",
|
|
30
|
+
"@abtnode/static-server": "1.8.14",
|
|
31
|
+
"@abtnode/timemachine": "1.8.14",
|
|
32
|
+
"@abtnode/util": "1.8.14",
|
|
33
|
+
"@arcblock/did": "1.17.17",
|
|
34
34
|
"@arcblock/did-motif": "^1.1.10",
|
|
35
|
-
"@arcblock/did-util": "1.17.
|
|
36
|
-
"@arcblock/event-hub": "1.17.
|
|
37
|
-
"@arcblock/jwt": "^1.17.
|
|
35
|
+
"@arcblock/did-util": "1.17.17",
|
|
36
|
+
"@arcblock/event-hub": "1.17.17",
|
|
37
|
+
"@arcblock/jwt": "^1.17.17",
|
|
38
38
|
"@arcblock/pm2-events": "^0.0.5",
|
|
39
|
-
"@arcblock/vc": "1.17.
|
|
40
|
-
"@blocklet/meta": "1.8.
|
|
41
|
-
"@blocklet/sdk": "1.8.
|
|
39
|
+
"@arcblock/vc": "1.17.17",
|
|
40
|
+
"@blocklet/meta": "1.8.14",
|
|
41
|
+
"@blocklet/sdk": "1.8.14",
|
|
42
42
|
"@fidm/x509": "^1.2.1",
|
|
43
43
|
"@nedb/core": "^1.3.4",
|
|
44
44
|
"@nedb/multi": "^1.3.4",
|
|
45
|
-
"@ocap/mcrypto": "1.17.
|
|
46
|
-
"@ocap/util": "1.17.
|
|
47
|
-
"@ocap/wallet": "1.17.
|
|
45
|
+
"@ocap/mcrypto": "1.17.17",
|
|
46
|
+
"@ocap/util": "1.17.17",
|
|
47
|
+
"@ocap/wallet": "1.17.17",
|
|
48
48
|
"@slack/webhook": "^5.0.4",
|
|
49
49
|
"axios": "^0.27.2",
|
|
50
50
|
"axon": "^2.0.3",
|
|
@@ -62,7 +62,6 @@
|
|
|
62
62
|
"lodash": "^4.17.21",
|
|
63
63
|
"lru-cache": "^6.0.0",
|
|
64
64
|
"pm2": "^5.2.0",
|
|
65
|
-
"promise.any": "^2.0.4",
|
|
66
65
|
"semver": "^7.3.7",
|
|
67
66
|
"shelljs": "^0.8.5",
|
|
68
67
|
"slugify": "^1.6.5",
|
|
@@ -82,5 +81,5 @@
|
|
|
82
81
|
"express": "^4.18.1",
|
|
83
82
|
"jest": "^27.5.1"
|
|
84
83
|
},
|
|
85
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "4b0cee41fd03d09301e2c35af46dd9e513473ef8"
|
|
86
85
|
}
|