@abtnode/core 1.16.0-beta-ad6df3ae → 1.16.0-beta-7a7d5d97
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/blocklet/manager/disk.js +108 -49
- package/lib/blocklet/manager/helper/install-application-from-dev.js +2 -13
- package/lib/blocklet/manager/helper/install-component-from-url.js +5 -1
- package/lib/blocklet/storage/utils/disk.js +1 -1
- package/lib/util/blocklet.js +36 -6
- package/package.json +17 -17
|
@@ -11,12 +11,8 @@ const cloneDeep = require('lodash/cloneDeep');
|
|
|
11
11
|
const { isNFTExpired, getNftExpirationDate } = require('@abtnode/util/lib/nft');
|
|
12
12
|
const didDocument = require('@abtnode/util/lib/did-document');
|
|
13
13
|
const { sign } = require('@arcblock/jwt');
|
|
14
|
-
const { isEthereumDid } = require('@arcblock/did');
|
|
15
|
-
const { toSvg: createDidLogo } =
|
|
16
|
-
process.env.NODE_ENV !== 'test' ? require('@arcblock/did-motif') : require('@arcblock/did-motif/dist/did-motif.cjs');
|
|
17
|
-
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
18
|
-
const { createBlockiesSvg } = require('@blocklet/meta/lib/blockies');
|
|
19
14
|
const sleep = require('@abtnode/util/lib/sleep');
|
|
15
|
+
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
20
16
|
|
|
21
17
|
const logger = require('@abtnode/logger')('@abtnode/core:blocklet:manager');
|
|
22
18
|
const {
|
|
@@ -100,6 +96,7 @@ const {
|
|
|
100
96
|
isRotatingAppDid,
|
|
101
97
|
checkVersionCompatibility,
|
|
102
98
|
getBlockletKnownAs,
|
|
99
|
+
updateBlockletFallbackLogo,
|
|
103
100
|
} = require('../../util/blocklet');
|
|
104
101
|
const states = require('../../states');
|
|
105
102
|
const BaseBlockletManager = require('./base');
|
|
@@ -150,10 +147,19 @@ const pm2StatusMap = {
|
|
|
150
147
|
*/
|
|
151
148
|
const getBlockletEngineNameByPlatform = (blockletMeta) => getBlockletEngine(blockletMeta).interpreter;
|
|
152
149
|
|
|
153
|
-
|
|
150
|
+
/**
|
|
151
|
+
* @param {{
|
|
152
|
+
* newBlocklet,
|
|
153
|
+
* oldBlocklet,
|
|
154
|
+
* context: { forceStartProcessIds?: string[] },
|
|
155
|
+
* }}
|
|
156
|
+
* @returns {{ installedComponentNames: string[], skippedProcessIds: string[] }}
|
|
157
|
+
*/
|
|
158
|
+
const getComponentChangedInfoForUpgrade = ({ newBlocklet, oldBlocklet, context = {} }) => {
|
|
154
159
|
const { forceStartProcessIds = [] } = context;
|
|
155
160
|
const idMap = {};
|
|
156
|
-
const
|
|
161
|
+
const skippedProcessIds = [];
|
|
162
|
+
const installedComponentNames = [];
|
|
157
163
|
|
|
158
164
|
forEachBlockletSync(oldBlocklet, (b, { ancestors }) => {
|
|
159
165
|
if (b.meta.dist?.integrity) {
|
|
@@ -164,15 +170,18 @@ const getSkippedProcessIds = ({ newBlocklet, oldBlocklet, context = {} }) => {
|
|
|
164
170
|
forEachBlockletSync(newBlocklet, (b, { ancestors }) => {
|
|
165
171
|
const id = getComponentProcessId(b, ancestors);
|
|
166
172
|
if (forceStartProcessIds.includes(id)) {
|
|
173
|
+
installedComponentNames.push(b.meta.title);
|
|
167
174
|
return;
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
if (!b.meta.dist?.integrity || b.meta.dist.integrity === idMap[id]) {
|
|
171
|
-
|
|
178
|
+
skippedProcessIds.push(id);
|
|
179
|
+
} else {
|
|
180
|
+
installedComponentNames.push(b.meta.title);
|
|
172
181
|
}
|
|
173
182
|
});
|
|
174
183
|
|
|
175
|
-
return
|
|
184
|
+
return { skippedProcessIds, installedComponentNames };
|
|
176
185
|
};
|
|
177
186
|
|
|
178
187
|
// 10s 上报统计一次
|
|
@@ -506,7 +515,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
506
515
|
|
|
507
516
|
const error = Array.isArray(err) ? err[0] : err;
|
|
508
517
|
logger.error('Failed to start blocklet', { error, did, name: blocklet.meta.name });
|
|
509
|
-
const description = `Start blocklet ${blocklet.meta.
|
|
518
|
+
const description = `Start blocklet ${blocklet.meta.title} failed with error: ${error.message}`;
|
|
510
519
|
this._createNotification(did, {
|
|
511
520
|
title: 'Start Blocklet Failed',
|
|
512
521
|
description,
|
|
@@ -635,7 +644,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
635
644
|
|
|
636
645
|
this._createNotification(did, {
|
|
637
646
|
title: 'Blocklet Restart Failed',
|
|
638
|
-
description: `Blocklet ${
|
|
647
|
+
description: `Blocklet ${result.meta.title} restart failed with error: ${err.message || 'queue exception'}`,
|
|
639
648
|
entityType: 'blocklet',
|
|
640
649
|
entityId: did,
|
|
641
650
|
severity: 'error',
|
|
@@ -686,7 +695,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
686
695
|
const doc = await this._deleteBlocklet({ did, keepData, keepLogsDir, keepConfigs }, context);
|
|
687
696
|
this._createNotification(doc.meta.did, {
|
|
688
697
|
title: 'Blocklet Deleted',
|
|
689
|
-
description: `Blocklet ${doc.meta.
|
|
698
|
+
description: `Blocklet ${doc.meta.title} is deleted.`,
|
|
690
699
|
entityType: 'blocklet',
|
|
691
700
|
entityId: doc.meta.did,
|
|
692
701
|
severity: 'success',
|
|
@@ -699,7 +708,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
699
708
|
|
|
700
709
|
this._createNotification(doc.meta.did, {
|
|
701
710
|
title: 'Blocklet Deleted',
|
|
702
|
-
description: `Blocklet ${doc.meta.
|
|
711
|
+
description: `Blocklet ${doc.meta.title} is deleted.`,
|
|
703
712
|
entityType: 'blocklet',
|
|
704
713
|
entityId: doc.meta.did,
|
|
705
714
|
severity: 'success',
|
|
@@ -817,7 +826,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
817
826
|
|
|
818
827
|
this._createNotification(newBlocklet.meta.did, {
|
|
819
828
|
title: 'Component Deleted',
|
|
820
|
-
description: `Component ${child.meta.
|
|
829
|
+
description: `Component ${child.meta.title} of ${newBlocklet.meta.title} is successfully deleted.`,
|
|
821
830
|
entityType: 'blocklet',
|
|
822
831
|
entityId: newBlocklet.meta.did,
|
|
823
832
|
severity: 'success',
|
|
@@ -1069,6 +1078,24 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1069
1078
|
await this._updateDidDocument(blocklet);
|
|
1070
1079
|
}
|
|
1071
1080
|
|
|
1081
|
+
// update blocklet meta
|
|
1082
|
+
if (blocklet.structVersion && !childDids.length) {
|
|
1083
|
+
const changedTitle = newConfigs.find((x) => x.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_NAME)?.value;
|
|
1084
|
+
const changedDescription = newConfigs.find(
|
|
1085
|
+
(x) => x.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_DESCRIPTION
|
|
1086
|
+
)?.value;
|
|
1087
|
+
|
|
1088
|
+
if (changedTitle || changedDescription) {
|
|
1089
|
+
await states.blocklet.updateBlocklet(rootDid, {
|
|
1090
|
+
meta: {
|
|
1091
|
+
...blocklet.meta,
|
|
1092
|
+
title: changedTitle || blocklet.meta.title,
|
|
1093
|
+
description: changedDescription || blocklet.meta.description,
|
|
1094
|
+
},
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1072
1099
|
await this._updateBlockletEnvironment(rootDid);
|
|
1073
1100
|
|
|
1074
1101
|
// response
|
|
@@ -1418,7 +1445,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1418
1445
|
skipCheckIntegrity,
|
|
1419
1446
|
} = params;
|
|
1420
1447
|
const { meta } = blocklet;
|
|
1421
|
-
const { name, did, version } = meta;
|
|
1448
|
+
const { title, name, did, version } = meta;
|
|
1422
1449
|
|
|
1423
1450
|
// check status
|
|
1424
1451
|
if (!skipCheckStatusBeforeDownload) {
|
|
@@ -1489,7 +1516,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1489
1516
|
});
|
|
1490
1517
|
this._createNotification(did, {
|
|
1491
1518
|
title: 'Blocklet Download Failed',
|
|
1492
|
-
description: `Blocklet ${
|
|
1519
|
+
description: `Blocklet ${title} download failed with error: ${err.message}`,
|
|
1493
1520
|
entityType: 'blocklet',
|
|
1494
1521
|
entityId: did,
|
|
1495
1522
|
severity: 'error',
|
|
@@ -1610,7 +1637,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1610
1637
|
const blocklet = await this.getBlocklet(did);
|
|
1611
1638
|
|
|
1612
1639
|
const { meta } = blocklet;
|
|
1613
|
-
const { name } = meta;
|
|
1640
|
+
const { name, title } = meta;
|
|
1614
1641
|
|
|
1615
1642
|
try {
|
|
1616
1643
|
// healthy check
|
|
@@ -1633,7 +1660,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1633
1660
|
|
|
1634
1661
|
this._createNotification(did, {
|
|
1635
1662
|
title: 'Blocklet Start Failed',
|
|
1636
|
-
description: `Blocklet ${
|
|
1663
|
+
description: `Blocklet ${title} start failed: ${error.message}`,
|
|
1637
1664
|
entityType: 'blocklet',
|
|
1638
1665
|
entityId: did,
|
|
1639
1666
|
severity: 'error',
|
|
@@ -1886,11 +1913,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1886
1913
|
await fs.copy(src, dist);
|
|
1887
1914
|
}
|
|
1888
1915
|
|
|
1889
|
-
|
|
1890
|
-
await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.svg'), createBlockiesSvg(blocklet.meta.did));
|
|
1891
|
-
} else {
|
|
1892
|
-
await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.svg'), createDidLogo(blocklet.meta.did));
|
|
1893
|
-
}
|
|
1916
|
+
await updateBlockletFallbackLogo(blocklet);
|
|
1894
1917
|
|
|
1895
1918
|
// Init db
|
|
1896
1919
|
await this.teamManager.initTeam(blocklet.meta.did);
|
|
@@ -1915,12 +1938,13 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1915
1938
|
if (blocklet.controller && process.env.NODE_ENV !== 'test') {
|
|
1916
1939
|
const nodeInfo = await states.node.read();
|
|
1917
1940
|
await consumeServerlessNFT({ nftId: blocklet.controller.nftId, nodeInfo, blocklet });
|
|
1941
|
+
this.emit(BlockletEvents.nftConsumed, { blocklet, context });
|
|
1918
1942
|
}
|
|
1919
1943
|
|
|
1920
1944
|
if (createNotification) {
|
|
1921
1945
|
this._createNotification(did, {
|
|
1922
1946
|
title: 'Blocklet Installed',
|
|
1923
|
-
description: `Blocklet ${meta.
|
|
1947
|
+
description: `Blocklet ${meta.title} is installed successfully. (Source: ${
|
|
1924
1948
|
deployedFrom || fromBlockletSource(source)
|
|
1925
1949
|
})`,
|
|
1926
1950
|
action: `/blocklets/${did}/overview`,
|
|
@@ -1947,7 +1971,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1947
1971
|
});
|
|
1948
1972
|
this._createNotification(did, {
|
|
1949
1973
|
title: 'Blocklet Install Failed',
|
|
1950
|
-
description: `Blocklet ${meta.
|
|
1974
|
+
description: `Blocklet ${meta.title} install failed with error: ${err.message}`,
|
|
1951
1975
|
entityType: 'blocklet',
|
|
1952
1976
|
entityId: did,
|
|
1953
1977
|
severity: 'error',
|
|
@@ -1962,10 +1986,15 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1962
1986
|
|
|
1963
1987
|
async _upgradeBlocklet({ newBlocklet, oldBlocklet, context = {} }) {
|
|
1964
1988
|
const { meta, source, deployedFrom, children } = newBlocklet;
|
|
1965
|
-
const { did, version, name } = meta;
|
|
1989
|
+
const { did, version, name, title } = meta;
|
|
1966
1990
|
|
|
1967
1991
|
// ids
|
|
1968
|
-
|
|
1992
|
+
const { skippedProcessIds, installedComponentNames } = getComponentChangedInfoForUpgrade({
|
|
1993
|
+
newBlocklet,
|
|
1994
|
+
oldBlocklet,
|
|
1995
|
+
context,
|
|
1996
|
+
});
|
|
1997
|
+
context.skippedProcessIds = skippedProcessIds;
|
|
1969
1998
|
|
|
1970
1999
|
try {
|
|
1971
2000
|
// delete old process
|
|
@@ -2030,7 +2059,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2030
2059
|
|
|
2031
2060
|
blocklet = await this.getBlocklet(did, context);
|
|
2032
2061
|
|
|
2033
|
-
await
|
|
2062
|
+
await updateBlockletFallbackLogo(blocklet);
|
|
2034
2063
|
|
|
2035
2064
|
await this._updateDependents(did);
|
|
2036
2065
|
|
|
@@ -2040,9 +2069,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2040
2069
|
this.emit(BlockletEvents.upgraded, { blocklet, context });
|
|
2041
2070
|
this._createNotification(did, {
|
|
2042
2071
|
title: 'Blocklet Upgrade Success',
|
|
2043
|
-
description: `Blocklet ${
|
|
2044
|
-
deployedFrom || fromBlockletSource(source)
|
|
2045
|
-
})`,
|
|
2072
|
+
description: `Blocklet ${title} upgrade successfully. (Component: ${installedComponentNames.join(', ')})`,
|
|
2046
2073
|
action: `/blocklets/${did}/overview`,
|
|
2047
2074
|
entityType: 'blocklet',
|
|
2048
2075
|
entityId: did,
|
|
@@ -2071,7 +2098,9 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2071
2098
|
|
|
2072
2099
|
this._createNotification(did, {
|
|
2073
2100
|
title: 'Blocklet Upgrade Failed',
|
|
2074
|
-
description: `Blocklet ${
|
|
2101
|
+
description: `Blocklet ${title} upgrade failed with error: ${
|
|
2102
|
+
err.message
|
|
2103
|
+
}. (Component: ${installedComponentNames.join(', ')})`,
|
|
2075
2104
|
entityType: 'blocklet',
|
|
2076
2105
|
entityId: did,
|
|
2077
2106
|
severity: 'error',
|
|
@@ -2543,16 +2572,32 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2543
2572
|
const spacesRestore = new SpacesRestore({ ...input, event: this, userDid, referrer: context.referrer });
|
|
2544
2573
|
const params = await spacesRestore.restore();
|
|
2545
2574
|
|
|
2575
|
+
const removeRestoreDir = () => {
|
|
2576
|
+
if (fs.existsSync(spacesRestore.restoreDir)) {
|
|
2577
|
+
fs.remove(spacesRestore.restoreDir).catch((err) => {
|
|
2578
|
+
logger.error('failed to remove restore dir', { error: err, dir: spacesRestore.restoreDir });
|
|
2579
|
+
});
|
|
2580
|
+
}
|
|
2581
|
+
};
|
|
2582
|
+
|
|
2546
2583
|
this.emit(BlockletEvents.restoreProgress, { appDid: input.appDid, status: RESTORE_PROGRESS_STATUS.installing });
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2584
|
+
|
|
2585
|
+
try {
|
|
2586
|
+
await installApplicationFromBackup({
|
|
2587
|
+
url: `file://${spacesRestore.restoreDir}`,
|
|
2588
|
+
moveDir: true,
|
|
2589
|
+
...merge(...params),
|
|
2590
|
+
manager: this,
|
|
2591
|
+
states,
|
|
2592
|
+
controller: input.controller,
|
|
2593
|
+
context: { ...context, startImmediately: true },
|
|
2594
|
+
});
|
|
2595
|
+
|
|
2596
|
+
removeRestoreDir();
|
|
2597
|
+
} catch (error) {
|
|
2598
|
+
removeRestoreDir();
|
|
2599
|
+
throw error;
|
|
2600
|
+
}
|
|
2556
2601
|
|
|
2557
2602
|
this.emit(BlockletEvents.restoreProgress, { appDid: input.appDid, status: RESTORE_PROGRESS_STATUS.completed });
|
|
2558
2603
|
}
|
|
@@ -2565,14 +2610,28 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2565
2610
|
const diskRestore = new DiskRestore({ ...input, event: this });
|
|
2566
2611
|
const params = await diskRestore.restore();
|
|
2567
2612
|
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2613
|
+
const removeRestoreDir = () => {
|
|
2614
|
+
if (fs.existsSync(diskRestore.restoreDir)) {
|
|
2615
|
+
fs.remove(diskRestore.restoreDir).catch((err) => {
|
|
2616
|
+
logger.error('failed to remove restore dir', { error: err, dir: diskRestore.restoreDir });
|
|
2617
|
+
});
|
|
2618
|
+
}
|
|
2619
|
+
};
|
|
2620
|
+
|
|
2621
|
+
try {
|
|
2622
|
+
await installApplicationFromBackup({
|
|
2623
|
+
url: `file://${diskRestore.restoreDir}`,
|
|
2624
|
+
...merge(...params),
|
|
2625
|
+
manager: this,
|
|
2626
|
+
states,
|
|
2627
|
+
move: true,
|
|
2628
|
+
sync: false, // use queue to download and install application
|
|
2629
|
+
});
|
|
2630
|
+
removeRestoreDir();
|
|
2631
|
+
} catch (error) {
|
|
2632
|
+
removeRestoreDir();
|
|
2633
|
+
throw error;
|
|
2634
|
+
}
|
|
2576
2635
|
}
|
|
2577
2636
|
}
|
|
2578
2637
|
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs-extra');
|
|
3
|
-
const { isEthereumDid } = require('@arcblock/did');
|
|
4
|
-
const { createBlockiesSvg } = require('@blocklet/meta/lib/blockies');
|
|
5
|
-
|
|
6
|
-
const { toSvg: createDidLogo } =
|
|
7
|
-
process.env.NODE_ENV !== 'test' ? require('@arcblock/did-motif') : require('@arcblock/did-motif/dist/did-motif.cjs');
|
|
8
1
|
const { BlockletStatus, BLOCKLET_MODES, fromBlockletStatus, BlockletSource } = require('@blocklet/constant');
|
|
9
2
|
|
|
10
3
|
const logger = require('@abtnode/logger')('@abtnode/core:install-app-dev');
|
|
11
|
-
const { ensureMeta } = require('../../../util/blocklet');
|
|
4
|
+
const { ensureMeta, updateBlockletFallbackLogo } = require('../../../util/blocklet');
|
|
12
5
|
|
|
13
6
|
/**
|
|
14
7
|
*
|
|
@@ -88,11 +81,7 @@ const installApplicationFromDev = async ({ folder, meta, states, manager } = {})
|
|
|
88
81
|
|
|
89
82
|
blocklet = await manager.getBlocklet(did);
|
|
90
83
|
|
|
91
|
-
|
|
92
|
-
await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.svg'), createBlockiesSvg(blocklet.meta.did));
|
|
93
|
-
} else {
|
|
94
|
-
await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.svg'), createDidLogo(blocklet.meta.did));
|
|
95
|
-
}
|
|
84
|
+
await updateBlockletFallbackLogo(blocklet);
|
|
96
85
|
|
|
97
86
|
return blocklet;
|
|
98
87
|
};
|
|
@@ -66,7 +66,11 @@ const installComponentFromUrl = async ({
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (!isComponentBlocklet(meta)) {
|
|
69
|
-
throw new Error(
|
|
69
|
+
throw new Error(
|
|
70
|
+
`The blocklet cannot be a component : ${
|
|
71
|
+
meta.title || meta.name
|
|
72
|
+
}. The reason may be that the developer set capabilities.component to false in blocklet.yml`
|
|
73
|
+
);
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
if (title) {
|
|
@@ -9,7 +9,7 @@ const restoreDirName = 'tmp/restore-disk';
|
|
|
9
9
|
const getBackupList = (dataDir) => {
|
|
10
10
|
const baseBackupDir = path.join(dataDir, backupDirName);
|
|
11
11
|
const backupList = [];
|
|
12
|
-
const appDidList = fs.readdirSync(baseBackupDir);
|
|
12
|
+
const appDidList = fs.existsSync(baseBackupDir) ? fs.readdirSync(baseBackupDir) : [];
|
|
13
13
|
|
|
14
14
|
appDidList.forEach((appDid) => {
|
|
15
15
|
const metaFile = path.join(baseBackupDir, appDid, 'meta.json');
|
package/lib/util/blocklet.js
CHANGED
|
@@ -5,6 +5,7 @@ const path = require('path');
|
|
|
5
5
|
const joinURL = require('url-join');
|
|
6
6
|
const shelljs = require('shelljs');
|
|
7
7
|
const os = require('os');
|
|
8
|
+
const pRetry = require('p-retry');
|
|
8
9
|
const tar = require('tar');
|
|
9
10
|
const get = require('lodash/get');
|
|
10
11
|
const isEmpty = require('lodash/isEmpty');
|
|
@@ -21,7 +22,7 @@ const { stableStringify } = require('@arcblock/vc');
|
|
|
21
22
|
const { fromSecretKey, WalletType } = require('@ocap/wallet');
|
|
22
23
|
const { toHex, toBase58, isHex, toDid } = require('@ocap/util');
|
|
23
24
|
const { types } = require('@ocap/mcrypto');
|
|
24
|
-
const { isValid: isValidDid } = require('@arcblock/did');
|
|
25
|
+
const { isValid: isValidDid, isEthereumDid } = require('@arcblock/did');
|
|
25
26
|
const logger = require('@abtnode/logger')('@abtnode/core:util:blocklet');
|
|
26
27
|
const pm2 = require('@abtnode/util/lib/async-pm2');
|
|
27
28
|
const sleep = require('@abtnode/util/lib/sleep');
|
|
@@ -39,6 +40,9 @@ const {
|
|
|
39
40
|
APP_STRUCT_VERSION,
|
|
40
41
|
} = require('@abtnode/constant');
|
|
41
42
|
const formatBackSlash = require('@abtnode/util/lib/format-back-slash');
|
|
43
|
+
const { toSvg: createDidLogo } =
|
|
44
|
+
process.env.NODE_ENV !== 'test' ? require('@arcblock/did-motif') : require('@arcblock/did-motif/dist/did-motif.cjs');
|
|
45
|
+
const { createBlockiesSvg } = require('@blocklet/meta/lib/blockies');
|
|
42
46
|
|
|
43
47
|
const SCRIPT_ENGINES_WHITE_LIST = ['npm', 'npx', 'pnpm', 'yarn'];
|
|
44
48
|
|
|
@@ -814,7 +818,9 @@ const parseComponents = async (component, context = {}) => {
|
|
|
814
818
|
validateBlockletMeta(rawMeta, { ensureDist: true });
|
|
815
819
|
|
|
816
820
|
if (!isComponentBlocklet(rawMeta)) {
|
|
817
|
-
throw new Error(
|
|
821
|
+
throw new Error(
|
|
822
|
+
`The blocklet cannot be a component: ${rawMeta.title}. The reason may be that the developer set capabilities.component to false in blocklet.yml`
|
|
823
|
+
);
|
|
818
824
|
}
|
|
819
825
|
|
|
820
826
|
const webInterface = findWebInterface(rawMeta);
|
|
@@ -1508,13 +1514,28 @@ const consumeServerlessNFT = async ({ nftId, nodeInfo, blocklet }) => {
|
|
|
1508
1514
|
const body = { nftId, appURL };
|
|
1509
1515
|
|
|
1510
1516
|
const { launcherUrl } = state.data.value;
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1517
|
+
|
|
1518
|
+
const func = async () => {
|
|
1519
|
+
const { data } = await axios.post(joinURL(launcherUrl, '/api/serverless/consume'), body, {
|
|
1520
|
+
headers: {
|
|
1521
|
+
'x-sig': toBase58(wallet.sign(stableStringify(body))),
|
|
1522
|
+
},
|
|
1523
|
+
});
|
|
1524
|
+
|
|
1525
|
+
return data;
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
const delay = 10 * 1000;
|
|
1529
|
+
const result = await pRetry(func, {
|
|
1530
|
+
retries: 3,
|
|
1531
|
+
minTimeout: delay,
|
|
1532
|
+
maxTimeout: delay,
|
|
1533
|
+
onFailedAttempt: (error) => {
|
|
1534
|
+
logger.error(`attempt consume nft ${nftId} failed`, { error });
|
|
1514
1535
|
},
|
|
1515
1536
|
});
|
|
1516
1537
|
|
|
1517
|
-
logger.error('consume serverless nft success', { nftId, hash:
|
|
1538
|
+
logger.error('consume serverless nft success', { nftId, hash: result.hash });
|
|
1518
1539
|
} catch (error) {
|
|
1519
1540
|
logger.error('consume serverless nft failed', { nftId, error });
|
|
1520
1541
|
|
|
@@ -1861,7 +1882,16 @@ const getFixedBundleSource = (component) => {
|
|
|
1861
1882
|
return null;
|
|
1862
1883
|
};
|
|
1863
1884
|
|
|
1885
|
+
const updateBlockletFallbackLogo = async (blocklet) => {
|
|
1886
|
+
if (isEthereumDid(blocklet.meta.did)) {
|
|
1887
|
+
await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.svg'), createBlockiesSvg(blocklet.meta.did));
|
|
1888
|
+
} else {
|
|
1889
|
+
await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.svg'), createDidLogo(blocklet.meta.did));
|
|
1890
|
+
}
|
|
1891
|
+
};
|
|
1892
|
+
|
|
1864
1893
|
module.exports = {
|
|
1894
|
+
updateBlockletFallbackLogo,
|
|
1865
1895
|
consumeServerlessNFT,
|
|
1866
1896
|
forEachBlocklet,
|
|
1867
1897
|
getBlockletMetaFromUrl: (url) => getBlockletMetaFromUrl(url, { logger }),
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.0-beta-
|
|
6
|
+
"version": "1.16.0-beta-7a7d5d97",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/auth": "1.16.0-beta-
|
|
23
|
-
"@abtnode/certificate-manager": "1.16.0-beta-
|
|
24
|
-
"@abtnode/constant": "1.16.0-beta-
|
|
25
|
-
"@abtnode/cron": "1.16.0-beta-
|
|
26
|
-
"@abtnode/db": "1.16.0-beta-
|
|
27
|
-
"@abtnode/logger": "1.16.0-beta-
|
|
28
|
-
"@abtnode/queue": "1.16.0-beta-
|
|
29
|
-
"@abtnode/rbac": "1.16.0-beta-
|
|
30
|
-
"@abtnode/router-provider": "1.16.0-beta-
|
|
31
|
-
"@abtnode/static-server": "1.16.0-beta-
|
|
32
|
-
"@abtnode/timemachine": "1.16.0-beta-
|
|
33
|
-
"@abtnode/util": "1.16.0-beta-
|
|
22
|
+
"@abtnode/auth": "1.16.0-beta-7a7d5d97",
|
|
23
|
+
"@abtnode/certificate-manager": "1.16.0-beta-7a7d5d97",
|
|
24
|
+
"@abtnode/constant": "1.16.0-beta-7a7d5d97",
|
|
25
|
+
"@abtnode/cron": "1.16.0-beta-7a7d5d97",
|
|
26
|
+
"@abtnode/db": "1.16.0-beta-7a7d5d97",
|
|
27
|
+
"@abtnode/logger": "1.16.0-beta-7a7d5d97",
|
|
28
|
+
"@abtnode/queue": "1.16.0-beta-7a7d5d97",
|
|
29
|
+
"@abtnode/rbac": "1.16.0-beta-7a7d5d97",
|
|
30
|
+
"@abtnode/router-provider": "1.16.0-beta-7a7d5d97",
|
|
31
|
+
"@abtnode/static-server": "1.16.0-beta-7a7d5d97",
|
|
32
|
+
"@abtnode/timemachine": "1.16.0-beta-7a7d5d97",
|
|
33
|
+
"@abtnode/util": "1.16.0-beta-7a7d5d97",
|
|
34
34
|
"@arcblock/did": "1.18.64",
|
|
35
35
|
"@arcblock/did-motif": "^1.1.10",
|
|
36
36
|
"@arcblock/did-util": "1.18.64",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@arcblock/jwt": "^1.18.64",
|
|
39
39
|
"@arcblock/pm2-events": "^0.0.5",
|
|
40
40
|
"@arcblock/vc": "1.18.64",
|
|
41
|
-
"@blocklet/constant": "1.16.0-beta-
|
|
42
|
-
"@blocklet/meta": "1.16.0-beta-
|
|
43
|
-
"@blocklet/sdk": "1.16.0-beta-
|
|
41
|
+
"@blocklet/constant": "1.16.0-beta-7a7d5d97",
|
|
42
|
+
"@blocklet/meta": "1.16.0-beta-7a7d5d97",
|
|
43
|
+
"@blocklet/sdk": "1.16.0-beta-7a7d5d97",
|
|
44
44
|
"@did-space/client": "^0.2.45",
|
|
45
45
|
"@fidm/x509": "^1.2.1",
|
|
46
46
|
"@ocap/client": "1.18.64",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"express": "^4.18.2",
|
|
92
92
|
"jest": "^27.5.1"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "c25ddcc371454b2e2f7038aa5e64c7b7c27763cb"
|
|
95
95
|
}
|