@abtnode/core 1.8.66-beta-7f4224af → 1.8.66-beta-b56e3b54

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.
@@ -243,7 +243,7 @@ class BlockletManager extends BaseBlockletManager {
243
243
  * title: string;
244
244
  * description: string;
245
245
  * storeUrl: string;
246
- * blockletSecretKey: string;
246
+ * appSk: string;
247
247
  * sync: boolean = false; // download synchronously, not use queue
248
248
  * delay: number; // push download task to queue after a delay
249
249
  * downloadTokenList: Array<{did: string, token: string}>;
@@ -280,28 +280,31 @@ class BlockletManager extends BaseBlockletManager {
280
280
  context.startImmediately = !!params.startImmediately;
281
281
  }
282
282
 
283
+ const { appSk } = params;
284
+
283
285
  if (type === BLOCKLET_INSTALL_TYPE.URL) {
284
286
  const { url, controller, sync, delay } = params;
285
- return this._installFromUrl({ url, controller, sync, delay }, context);
287
+ return this._installFromUrl({ url, controller, sync, delay, appSk }, context);
286
288
  }
287
289
 
288
290
  if (type === BLOCKLET_INSTALL_TYPE.UPLOAD) {
289
291
  const { file, did, diffVersion, deleteSet } = params;
290
- return this._installFromUpload({ file, did, diffVersion, deleteSet, context });
292
+ return this._installFromUpload({ file, did, diffVersion, deleteSet, appSk }, context);
291
293
  }
292
294
 
293
295
  if (type === BLOCKLET_INSTALL_TYPE.STORE) {
294
296
  const { did, controller, sync, delay, storeUrl } = params;
295
- return this._installFromStore({ did, controller, sync, delay, storeUrl }, context);
297
+ return this._installFromStore({ did, controller, sync, delay, storeUrl, appSk }, context);
296
298
  }
297
299
 
298
300
  if (type === BLOCKLET_INSTALL_TYPE.CREATE) {
299
- return this._installFromCreate({ title: params.title, description: params.description }, context);
301
+ const { title, description } = params;
302
+ return this._installFromCreate({ title, description, appSk }, context);
300
303
  }
301
304
 
302
305
  if (type === BLOCKLET_INSTALL_TYPE.RESTORE) {
303
- const { url, blockletSecretKey } = params;
304
- return this._installFromBackup({ url, blockletSecretKey }, context);
306
+ const { url } = params;
307
+ return this._installFromBackup({ url, appSk }, context);
305
308
  }
306
309
 
307
310
  // should not be here
@@ -624,7 +627,7 @@ class BlockletManager extends BaseBlockletManager {
624
627
  // FIXME: 需要改成队列执行,本次失败,下次还需要重试,页面刷新后也能知道最新的状态
625
628
  await this._installFromBackup({
626
629
  url: `file://${spacesRestore.blockletRestoreDir}`,
627
- blockletSecretKey: spacesRestore.blockletWallet.secretKey,
630
+ appSk: spacesRestore.blockletWallet.secretKey,
628
631
  moveDir: true,
629
632
  });
630
633
  }
@@ -997,7 +1000,7 @@ class BlockletManager extends BaseBlockletManager {
997
1000
  }
998
1001
 
999
1002
  // eslint-disable-next-line no-unused-vars
1000
- async config({ did, configs: newConfigs, skipHook }, context) {
1003
+ async config({ did, configs: newConfigs, skipHook, skipDidDocument }, context) {
1001
1004
  if (!Array.isArray(newConfigs)) {
1002
1005
  throw new Error('configs list is not an array');
1003
1006
  }
@@ -1057,7 +1060,7 @@ class BlockletManager extends BaseBlockletManager {
1057
1060
  [BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SK, BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_WALLET_TYPE].includes(item.key)
1058
1061
  );
1059
1062
 
1060
- if (isSkOrWalletTypeChanged) {
1063
+ if (isSkOrWalletTypeChanged && !skipDidDocument) {
1061
1064
  await this._updateDidDocument(blocklet);
1062
1065
  }
1063
1066
 
@@ -1672,13 +1675,13 @@ class BlockletManager extends BaseBlockletManager {
1672
1675
  * /blocklet.json
1673
1676
  * /blocklet_extras.json
1674
1677
  * @see Blocklet 端到端备份方案的设计与实现(一期) https://team.arcblock.io/comment/discussions/e62084d5-fafa-489e-91d5-defcd6e93223
1675
- * @param {{ url: string, blockletSecretKey: string, moveDir: boolean}} [{ url }={}]
1678
+ * @param {{ url: string, appSk: string, moveDir: boolean}} [{ url }={}]
1676
1679
  * @param {Record<string, string>} [context={}]
1677
1680
  * @return {Promise<any>}
1678
1681
  * @memberof BlockletManager
1679
1682
  */
1680
- async _installFromBackup({ url, blockletSecretKey, moveDir } = {}, context = {}) {
1681
- return installFromBackup({ url, blockletSecretKey, moveDir, context, manager: this, states });
1683
+ async _installFromBackup({ url, appSk, moveDir } = {}, context = {}) {
1684
+ return installFromBackup({ url, appSk, moveDir, context, manager: this, states });
1682
1685
  }
1683
1686
 
1684
1687
  async ensureBlocklet(did, opts = {}) {
@@ -2077,17 +2080,18 @@ class BlockletManager extends BaseBlockletManager {
2077
2080
  *
2078
2081
  * @param {{
2079
2082
  * did: string;
2080
- * registry: string;
2081
2083
  * sync: boolean;
2082
2084
  * delay: number;
2083
2085
  * controller: Controller;
2086
+ * appSk: string;
2087
+ * storeUrl: string;
2084
2088
  * }} params
2085
2089
  * @param {*} context
2086
2090
  * @return {*}
2087
2091
  * @memberof BlockletManager
2088
2092
  */
2089
2093
  async _installFromStore(params, context) {
2090
- const { did, storeUrl, sync, delay, controller } = params;
2094
+ const { did, storeUrl, sync, delay, controller, appSk } = params;
2091
2095
 
2092
2096
  logger.debug('start install blocklet', { did });
2093
2097
  if (!isValidDid(did)) {
@@ -2131,6 +2135,7 @@ class BlockletManager extends BaseBlockletManager {
2131
2135
  sync,
2132
2136
  delay,
2133
2137
  controller,
2138
+ appSk,
2134
2139
  context,
2135
2140
  });
2136
2141
  }
@@ -2147,13 +2152,14 @@ class BlockletManager extends BaseBlockletManager {
2147
2152
  * sync: boolean;
2148
2153
  * delay: number;
2149
2154
  * controller: Controller;
2155
+ * appSk: string;
2150
2156
  * }} params
2151
2157
  * @param {{}} context
2152
2158
  * @return {*}
2153
2159
  * @memberof BlockletManager
2154
2160
  */
2155
2161
  async _installFromUrl(params, context) {
2156
- const { url, sync, delay, controller } = params;
2162
+ const { url, sync, delay, controller, appSk } = params;
2157
2163
 
2158
2164
  logger.debug('start install blocklet', { url });
2159
2165
 
@@ -2178,7 +2184,7 @@ class BlockletManager extends BaseBlockletManager {
2178
2184
  return this.upgrade({ did: blockletDid, storeUrl: registryUrl, sync, delay }, context);
2179
2185
  }
2180
2186
 
2181
- return this._installFromStore({ did: bundleDid, storeUrl: registryUrl, controller, sync, delay }, context);
2187
+ return this._installFromStore({ did: bundleDid, storeUrl: registryUrl, controller, sync, delay, appSk }, context);
2182
2188
  }
2183
2189
 
2184
2190
  const meta = ensureMeta(bundleMeta, { name: blockletName, did: blockletDid });
@@ -2204,6 +2210,7 @@ class BlockletManager extends BaseBlockletManager {
2204
2210
  sync,
2205
2211
  delay,
2206
2212
  controller,
2213
+ appSk,
2207
2214
  context,
2208
2215
  });
2209
2216
  }
@@ -2308,7 +2315,7 @@ class BlockletManager extends BaseBlockletManager {
2308
2315
  );
2309
2316
  }
2310
2317
 
2311
- async _installFromCreate({ title, description }, context = {}) {
2318
+ async _installFromCreate({ title, description, appSk }, context = {}) {
2312
2319
  logger.debug('create blocklet', { title, description });
2313
2320
 
2314
2321
  await joi.string().label('title').max(20).required().validateAsync(title);
@@ -2336,11 +2343,9 @@ class BlockletManager extends BaseBlockletManager {
2336
2343
  };
2337
2344
  const meta = validateMeta(rawMeta);
2338
2345
 
2339
- await states.blocklet.addBlocklet({
2340
- meta,
2341
- source: BlockletSource.custom,
2342
- });
2346
+ await states.blocklet.addBlocklet({ meta, source: BlockletSource.custom });
2343
2347
  await this._setConfigsFromMeta(did);
2348
+ await this._setAppSk(did, appSk);
2344
2349
 
2345
2350
  // check duplicate appSk
2346
2351
  await checkDuplicateAppSk({ did, states });
@@ -2380,7 +2385,7 @@ class BlockletManager extends BaseBlockletManager {
2380
2385
  return { cwd, tarFile };
2381
2386
  }
2382
2387
 
2383
- async _installFromUpload({ file, did, diffVersion, deleteSet, context }) {
2388
+ async _installFromUpload({ file, did, diffVersion, deleteSet, appSk }, context) {
2384
2389
  logger.info('install blocklet', { from: 'upload file' });
2385
2390
  const { tarFile } = await this._downloadFromUpload(file);
2386
2391
 
@@ -2478,6 +2483,7 @@ class BlockletManager extends BaseBlockletManager {
2478
2483
  const oldState = { extraState: oldExtraState };
2479
2484
  try {
2480
2485
  await this._setConfigsFromMeta(meta.did);
2486
+ await this._setAppSk(appSk);
2481
2487
  await validateBlocklet(blocklet);
2482
2488
 
2483
2489
  // check duplicate appSk
@@ -2774,6 +2780,7 @@ class BlockletManager extends BaseBlockletManager {
2774
2780
  * meta: {}; // blocklet meta
2775
2781
  * source: number; // example: BlockletSource.registry,
2776
2782
  * deployedFrom: string;
2783
+ * appSk: string;
2777
2784
  * context: {}
2778
2785
  * sync: boolean = false;
2779
2786
  * delay: number;
@@ -2783,7 +2790,7 @@ class BlockletManager extends BaseBlockletManager {
2783
2790
  * @memberof BlockletManager
2784
2791
  */
2785
2792
  async _install(params) {
2786
- const { meta, source, deployedFrom, context, sync, delay, controller } = params;
2793
+ const { meta, source, deployedFrom, context, sync, delay, controller, appSk } = params;
2787
2794
 
2788
2795
  validateBlockletMeta(meta, { ensureDist: true });
2789
2796
 
@@ -2811,6 +2818,7 @@ class BlockletManager extends BaseBlockletManager {
2811
2818
  await states.blockletExtras.addMeta({ did, meta: { did, name }, controller });
2812
2819
 
2813
2820
  await this._setConfigsFromMeta(did);
2821
+ await this._setAppSk(did, appSk);
2814
2822
 
2815
2823
  // check duplicate appSk
2816
2824
  await checkDuplicateAppSk({ did, states });
@@ -3408,6 +3416,24 @@ class BlockletManager extends BaseBlockletManager {
3408
3416
  }
3409
3417
  }
3410
3418
 
3419
+ async _setAppSk(did, appSk, context) {
3420
+ if (process.env.NODE_ENV === 'production' && !appSk) {
3421
+ throw new Error(`appSk for blocklet ${did} is required`);
3422
+ }
3423
+
3424
+ if (appSk) {
3425
+ await this.config(
3426
+ {
3427
+ did,
3428
+ configs: [{ key: 'BLOCKLET_APP_SK', value: appSk, secure: true }],
3429
+ skipHook: true,
3430
+ skipDidDocument: true,
3431
+ },
3432
+ context
3433
+ );
3434
+ }
3435
+ }
3436
+
3411
3437
  async _findNextCustomBlockletName(leftTimes = 10) {
3412
3438
  if (leftTimes <= 0) {
3413
3439
  throw new Error('Generate custom blocklet did too many times');
@@ -19,7 +19,7 @@ const { validateBlocklet, checkDuplicateAppSk, getAppDirs } = require('../../../
19
19
  * }} param0
20
20
  * @returns
21
21
  */
22
- module.exports = async ({ url, blockletSecretKey, moveDir, context = {}, states, manager } = {}) => {
22
+ module.exports = async ({ url, appSk, moveDir, context = {}, states, manager } = {}) => {
23
23
  // TODO: support more url schema feature (http, did-spaces)
24
24
  if (!url.startsWith('file://')) {
25
25
  throw new Error('url must starts with file://');
@@ -71,17 +71,17 @@ module.exports = async ({ url, blockletSecretKey, moveDir, context = {}, states,
71
71
  throw new Error('blocklet is already exist');
72
72
  }
73
73
 
74
- if (blockletSecretKey) {
74
+ if (appSk) {
75
75
  extra.configs = extra.configs || [];
76
76
  const skConfig = extra.configs.find((x) => x.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SK);
77
77
  if (skConfig) {
78
- skConfig.value = blockletSecretKey;
78
+ skConfig.value = appSk;
79
79
  skConfig.secure = true;
80
80
  skConfig.shared = false;
81
81
  } else {
82
82
  extra.configs.push({
83
83
  key: BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SK,
84
- value: blockletSecretKey,
84
+ value: appSk,
85
85
  secure: true,
86
86
  shared: false,
87
87
  });
@@ -150,10 +150,10 @@ class SpacesBackup {
150
150
  const { errorCount } = await spaceClient.send(
151
151
  new SyncFolderPushCommand({
152
152
  source: join(this.blockletBackupDir, '/'),
153
- target: join('.did-objects', this.blocklet.appDid),
153
+ target: join('.did-objects', this.blocklet.appDid, '/'),
154
154
  debug: true,
155
155
  concurrency: 32,
156
- retryCount: 100,
156
+ retryCount: 10,
157
157
  filter: (object) => {
158
158
  return object.name !== '.DS_Store';
159
159
  },
@@ -1,4 +1,4 @@
1
- const { existsSync, remove } = require('fs-extra');
1
+ const { existsSync, remove, ensureDirSync } = require('fs-extra');
2
2
  const { join } = require('path');
3
3
  const fg = require('fast-glob');
4
4
  const { BaseRestore } = require('./base');
@@ -10,8 +10,11 @@ class BlockletsRestore extends BaseRestore {
10
10
  async import() {
11
11
  const blockletsDir = join(this.blockletRestoreDir, this.filename);
12
12
 
13
+ // blockletsDir 可以不存在, 因为还原的 blocklet 可能所有的组件都是来自 store 的
13
14
  if (!existsSync(blockletsDir)) {
14
- throw new Error(`dir not found: ${blockletsDir}`);
15
+ // FIXME: 如果文件夹不存在,需要创建文件夹,因为 installFromBackup 未做容错处理
16
+ ensureDirSync(blockletsDir);
17
+ return;
15
18
  }
16
19
 
17
20
  const paths = await fg('**/*.zip', {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @typedef {{
3
3
  * endpoint: string;
4
- * blockletSecretKey: string;
4
+ * appSk: string;
5
5
  * }} SpaceRestoreInput
6
6
  */
7
7
 
@@ -98,7 +98,7 @@ class SpacesRestore {
98
98
 
99
99
  async getBlockletWallet() {
100
100
  // @FIXME: blocklet 钱包类型如何得知呢?
101
- const wallet = fromSecretKey(this.input.blockletSecretKey, WalletType({ role: types.RoleType.ROLE_APPLICATION }));
101
+ const wallet = fromSecretKey(this.input.appSk, WalletType({ role: types.RoleType.ROLE_APPLICATION }));
102
102
 
103
103
  return wallet;
104
104
  }
@@ -115,10 +115,10 @@ class SpacesRestore {
115
115
  const { errorCount } = await spaceClient.send(
116
116
  new SyncFolderPullCommand({
117
117
  source: join('.did-objects', this.blockletWallet.address, '/'),
118
- target: this.blockletRestoreDir,
118
+ target: join(this.blockletRestoreDir, '/'),
119
119
  debug: true,
120
120
  concurrency: 32,
121
- retryCount: 100,
121
+ retryCount: 10,
122
122
  })
123
123
  );
124
124
 
package/lib/event.js CHANGED
@@ -81,7 +81,7 @@ module.exports = ({
81
81
  }
82
82
  };
83
83
 
84
- const handleBlockletAdd = async (name, { blocklet, context }) => {
84
+ const handleBlockletInstall = async (name, { blocklet, context }) => {
85
85
  try {
86
86
  const changed = await ensureBlockletRouting(blocklet, context);
87
87
  if (changed) {
@@ -173,7 +173,7 @@ module.exports = ({
173
173
  const blocklet = payload.blocklet || payload;
174
174
 
175
175
  if ([BlockletEvents.installed].includes(eventName)) {
176
- await handleBlockletAdd(eventName, payload);
176
+ await handleBlockletInstall(eventName, payload);
177
177
 
178
178
  try {
179
179
  await node.createAuditLog({
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.66-beta-7f4224af",
6
+ "version": "1.8.66-beta-b56e3b54",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,33 +19,33 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.8.66-beta-7f4224af",
23
- "@abtnode/certificate-manager": "1.8.66-beta-7f4224af",
24
- "@abtnode/constant": "1.8.66-beta-7f4224af",
25
- "@abtnode/cron": "1.8.66-beta-7f4224af",
26
- "@abtnode/db": "1.8.66-beta-7f4224af",
27
- "@abtnode/logger": "1.8.66-beta-7f4224af",
28
- "@abtnode/queue": "1.8.66-beta-7f4224af",
29
- "@abtnode/rbac": "1.8.66-beta-7f4224af",
30
- "@abtnode/router-provider": "1.8.66-beta-7f4224af",
31
- "@abtnode/static-server": "1.8.66-beta-7f4224af",
32
- "@abtnode/timemachine": "1.8.66-beta-7f4224af",
33
- "@abtnode/util": "1.8.66-beta-7f4224af",
34
- "@arcblock/did": "1.18.47",
22
+ "@abtnode/auth": "1.8.66-beta-b56e3b54",
23
+ "@abtnode/certificate-manager": "1.8.66-beta-b56e3b54",
24
+ "@abtnode/constant": "1.8.66-beta-b56e3b54",
25
+ "@abtnode/cron": "1.8.66-beta-b56e3b54",
26
+ "@abtnode/db": "1.8.66-beta-b56e3b54",
27
+ "@abtnode/logger": "1.8.66-beta-b56e3b54",
28
+ "@abtnode/queue": "1.8.66-beta-b56e3b54",
29
+ "@abtnode/rbac": "1.8.66-beta-b56e3b54",
30
+ "@abtnode/router-provider": "1.8.66-beta-b56e3b54",
31
+ "@abtnode/static-server": "1.8.66-beta-b56e3b54",
32
+ "@abtnode/timemachine": "1.8.66-beta-b56e3b54",
33
+ "@abtnode/util": "1.8.66-beta-b56e3b54",
34
+ "@arcblock/did": "1.18.52",
35
35
  "@arcblock/did-motif": "^1.1.10",
36
- "@arcblock/did-util": "1.18.47",
37
- "@arcblock/event-hub": "1.18.47",
38
- "@arcblock/jwt": "^1.18.47",
36
+ "@arcblock/did-util": "1.18.52",
37
+ "@arcblock/event-hub": "1.18.52",
38
+ "@arcblock/jwt": "^1.18.52",
39
39
  "@arcblock/pm2-events": "^0.0.5",
40
- "@arcblock/vc": "1.18.47",
41
- "@blocklet/constant": "1.8.66-beta-7f4224af",
42
- "@blocklet/meta": "1.8.66-beta-7f4224af",
43
- "@blocklet/sdk": "1.8.66-beta-7f4224af",
44
- "@did-space/client": "^0.1.73",
40
+ "@arcblock/vc": "1.18.52",
41
+ "@blocklet/constant": "1.8.66-beta-b56e3b54",
42
+ "@blocklet/meta": "1.8.66-beta-b56e3b54",
43
+ "@blocklet/sdk": "1.8.66-beta-b56e3b54",
44
+ "@did-space/client": "^0.1.76",
45
45
  "@fidm/x509": "^1.2.1",
46
- "@ocap/mcrypto": "1.18.47",
47
- "@ocap/util": "1.18.47",
48
- "@ocap/wallet": "1.18.47",
46
+ "@ocap/mcrypto": "1.18.52",
47
+ "@ocap/util": "1.18.52",
48
+ "@ocap/wallet": "1.18.52",
49
49
  "@slack/webhook": "^5.0.4",
50
50
  "archiver": "^5.3.1",
51
51
  "axios": "^0.27.2",
@@ -72,7 +72,6 @@
72
72
  "pm2": "^5.2.0",
73
73
  "semver": "^7.3.8",
74
74
  "shelljs": "^0.8.5",
75
- "slugify": "^1.6.5",
76
75
  "ssri": "^8.0.1",
77
76
  "stream-throttle": "^0.1.3",
78
77
  "stream-to-promise": "^3.0.0",
@@ -90,5 +89,5 @@
90
89
  "express": "^4.18.2",
91
90
  "jest": "^27.5.1"
92
91
  },
93
- "gitHead": "72d418f63ecb76b1d5d62edbcc5f336cb62bf308"
92
+ "gitHead": "4d95b431526128c14cd04c0741cac423afce8f48"
94
93
  }