@abtnode/core 1.16.17-beta-6f0c7674 → 1.16.17-beta-952ef53d

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/api/team.js CHANGED
@@ -1100,10 +1100,28 @@ class TeamAPI extends EventEmitter {
1100
1100
  return this.teamManager.getRoles(teamDid);
1101
1101
  }
1102
1102
 
1103
- async createRole({ teamDid, name, description, title, childName, permissions = [] }) {
1104
- logger.info('create role', { teamDid, name, description, childName, permissions });
1103
+ async getRole({ teamDid, role: { name } = {} }) {
1104
+ if (!name) {
1105
+ throw new Error('role name is invalid');
1106
+ }
1107
+ const rbac = await this.getRBAC(teamDid);
1108
+ const role = await rbac.getRole(name);
1109
+ return role ? pick(role, ['name', 'grants', 'title', 'description', 'extra']) : null;
1110
+ }
1111
+
1112
+ async createRole({ teamDid, name, description, title, childName, permissions = [], extra: raw }) {
1113
+ logger.info('create role', { teamDid, name, description, childName, permissions, raw });
1114
+ const attrs = { name, title, description, childName, permissions };
1105
1115
 
1106
- await validateCreateRole({ name, title, description });
1116
+ if (raw) {
1117
+ try {
1118
+ attrs.extra = JSON.parse(raw);
1119
+ } catch (err) {
1120
+ throw new Error('extra should be a valid json string');
1121
+ }
1122
+ }
1123
+
1124
+ await validateCreateRole(pick(attrs, ['name', 'title', 'description', 'extra']));
1107
1125
 
1108
1126
  validateReservedRole(name);
1109
1127
 
@@ -1111,8 +1129,8 @@ class TeamAPI extends EventEmitter {
1111
1129
 
1112
1130
  let role;
1113
1131
  try {
1114
- role = await rbac.createRole({ name, title, description, childName, permissions });
1115
- return pick(role, ['name', 'grants', 'title', 'description']);
1132
+ role = await rbac.createRole(attrs);
1133
+ return pick(role, ['name', 'title', 'grants', 'description', 'extra']);
1116
1134
  } catch (err) {
1117
1135
  if (new RegExp(`Item ${name} already exists`).test(err.message)) {
1118
1136
  throw new Error(`Id ${name} already exists`);
@@ -1121,16 +1139,23 @@ class TeamAPI extends EventEmitter {
1121
1139
  }
1122
1140
  }
1123
1141
 
1124
- async updateRole({ teamDid, role: { name, title, description } = {} }) {
1125
- logger.info('update role', { teamDid, name, title, description });
1126
-
1127
- await validateUpdateRole({ name, title, description });
1142
+ async updateRole({ teamDid, role: { name, title, description, extra: raw } = {} }) {
1143
+ logger.info('update role', { teamDid, name, title, description, raw });
1128
1144
 
1129
- const rbac = await this.getRBAC(teamDid);
1145
+ const attrs = { name, title, description };
1130
1146
 
1131
- const state = await rbac.updateRole({ name, title, description });
1147
+ if (raw) {
1148
+ try {
1149
+ attrs.extra = JSON.parse(raw);
1150
+ } catch (err) {
1151
+ throw new Error('extra should be a valid json string');
1152
+ }
1153
+ }
1132
1154
 
1133
- return pick(state, ['name', 'title', 'grants', 'description']);
1155
+ await validateUpdateRole(attrs);
1156
+ const rbac = await this.getRBAC(teamDid);
1157
+ const state = await rbac.updateRole(attrs);
1158
+ return pick(state, ['name', 'title', 'grants', 'description', 'extra']);
1134
1159
  }
1135
1160
 
1136
1161
  async getPermissions({ teamDid }) {
@@ -162,7 +162,12 @@ const UpgradeComponents = require('./helper/upgrade-components');
162
162
  const BlockletDownloader = require('../downloader/blocklet-downloader');
163
163
  const RollbackCache = require('./helper/rollback-cache');
164
164
  const { migrateApplicationToStructV2 } = require('./helper/migrate-application-to-struct-v2');
165
- const { getBackupFilesUrlFromEndpoint, getBackupEndpoint, getSpaceNameByEndpoint } = require('../../util/spaces');
165
+ const {
166
+ getBackupFilesUrlFromEndpoint,
167
+ getBackupEndpoint,
168
+ getSpaceNameByEndpoint,
169
+ getBackupJobId,
170
+ } = require('../../util/spaces');
166
171
  const { validateAddSpaceGateway, validateUpdateSpaceGateway } = require('../../validators/space-gateway');
167
172
  const { sessionConfigSchema } = require('../../validators/util');
168
173
 
@@ -221,12 +226,19 @@ class DiskBlockletManager extends BaseBlockletManager {
221
226
  this.teamManager = teamManager;
222
227
 
223
228
  if (isFunction(this.backupQueue.on)) {
224
- const handleBackupComplete = async ({ id, job }) => {
225
- await this.backupQueue.delete(id);
226
-
227
- const autoBackup = await this.getAutoBackup({ did: id });
229
+ /**
230
+ *
231
+ * @param {{
232
+ * id: string,
233
+ * job: { blocklet: import('@abtnode/client').BlockletState }
234
+ * }} param0
235
+ */
236
+ const handleBackupComplete = async ({ id: jobId, job }) => {
237
+ await this.backupQueue.delete(jobId);
238
+
239
+ const autoBackup = await this.getAutoBackup({ did: job.blocklet.meta.did });
228
240
  if (autoBackup?.enabled) {
229
- this.backupQueue.push(job, id, true, BACKUPS.JOB.INTERVAL);
241
+ this.backupQueue.push(job, jobId, true, BACKUPS.JOB.INTERVAL);
230
242
  }
231
243
  };
232
244
  this.backupQueue.on('finished', handleBackupComplete).on('failed', handleBackupComplete);
@@ -1898,12 +1910,14 @@ class DiskBlockletManager extends BaseBlockletManager {
1898
1910
  const value = { ...autoBackup };
1899
1911
  await states.blockletExtras.setSettings(did, { autoBackup: value });
1900
1912
 
1901
- await this.backupQueue.delete(did);
1913
+ const jobId = getBackupJobId(did);
1914
+ await this.backupQueue.delete(jobId);
1902
1915
 
1903
1916
  logger.info('updateAutoBackup.$value', value);
1904
1917
 
1905
1918
  if (value.enabled) {
1906
1919
  const blocklet = await states.blocklet.getBlocklet(did);
1920
+
1907
1921
  this.backupQueue.push(
1908
1922
  {
1909
1923
  entity: 'blocklet',
@@ -1911,7 +1925,7 @@ class DiskBlockletManager extends BaseBlockletManager {
1911
1925
  blocklet,
1912
1926
  context,
1913
1927
  },
1914
- did,
1928
+ jobId,
1915
1929
  true,
1916
1930
  BACKUPS.JOB.INTERVAL
1917
1931
  );
@@ -3568,7 +3582,8 @@ class DiskBlockletManager extends BaseBlockletManager {
3568
3582
  try {
3569
3583
  const { did } = blocklet.meta;
3570
3584
 
3571
- await this.backupQueue.delete(did);
3585
+ const jobId = getBackupJobId(did);
3586
+ await this.backupQueue.delete(jobId);
3572
3587
 
3573
3588
  this.backupQueue.push(
3574
3589
  {
@@ -3580,7 +3595,7 @@ class DiskBlockletManager extends BaseBlockletManager {
3580
3595
  strategy: BACKUPS.STRATEGY.MANUAL,
3581
3596
  },
3582
3597
  },
3583
- did
3598
+ jobId
3584
3599
  );
3585
3600
 
3586
3601
  return blocklet;
@@ -1,5 +1,6 @@
1
1
  const debounce = require('lodash/debounce');
2
2
  const logger = require('@abtnode/logger')('@abtnode/core:event/auto-backup-handler');
3
+ const { getBackupJobId } = require('../util/spaces');
3
4
 
4
5
  /**
5
6
  * @description
@@ -15,7 +16,8 @@ async function autoBackupHandler(eventName, payload, blockletManager) {
15
16
  logger.info('autoBackupHandler.$Boolean(payload.context)', Boolean(payload.context));
16
17
 
17
18
  if (autoBackup.enabled && payload.context) {
18
- await blockletManager.backupQueue.delete(did);
19
+ const jobId = getBackupJobId(did);
20
+ await blockletManager.backupQueue.delete(jobId);
19
21
 
20
22
  blockletManager.backupQueue.push(
21
23
  {
@@ -24,7 +26,7 @@ async function autoBackupHandler(eventName, payload, blockletManager) {
24
26
  blocklet: payload,
25
27
  context: payload.context,
26
28
  },
27
- did
29
+ jobId
28
30
  );
29
31
  }
30
32
  }
package/lib/index.js CHANGED
@@ -399,6 +399,7 @@ function ABTNode(options) {
399
399
  getRBAC: (did = options.nodeDid) => teamManager.getRBAC(did),
400
400
 
401
401
  getRoles: teamAPI.getRoles.bind(teamAPI),
402
+ getRole: teamAPI.getRole.bind(teamAPI),
402
403
  createRole: teamAPI.createRole.bind(teamAPI),
403
404
  updateRole: teamAPI.updateRole.bind(teamAPI),
404
405
  deleteRole: teamAPI.deleteRole.bind(teamAPI),
@@ -234,7 +234,7 @@ class BlockletState extends BaseState {
234
234
  } = {}) {
235
235
  let doc = await this.getBlocklet(meta.did);
236
236
  if (doc) {
237
- throw new Error('Blocklet already added');
237
+ throw new Error(`Blocklet already added: ${meta.did}`);
238
238
  }
239
239
 
240
240
  try {
@@ -288,7 +288,7 @@ class BlockletState extends BaseState {
288
288
  async updateBlocklet(did, updates) {
289
289
  const doc = await this.getBlocklet(did);
290
290
  if (!doc) {
291
- throw new Error('Blocklet does not exist');
291
+ throw new Error(`Blocklet does not exist on update: ${did}`);
292
292
  }
293
293
 
294
294
  const formatted = formatBlocklet(cloneDeep(updates), 'onUpdate', this.config.dek);
@@ -302,7 +302,7 @@ class BlockletState extends BaseState {
302
302
  async upgradeBlocklet({ meta, source, deployedFrom = '', children } = {}) {
303
303
  const doc = await this.getBlocklet(meta.did);
304
304
  if (!doc) {
305
- throw new Error('Blocklet does not exist');
305
+ throw new Error(`Blocklet does not exist on upgrade: ${meta.did}`);
306
306
  }
307
307
 
308
308
  try {
@@ -427,7 +427,7 @@ class BlockletState extends BaseState {
427
427
  async refreshBlockletPorts(did, componentDids = []) {
428
428
  const blocklet = await this.getBlocklet(did);
429
429
  if (!blocklet) {
430
- throw new Error('Blocklet does not exist');
430
+ throw new Error(`Blocklet does not exist on refresh: ${did}`);
431
431
  }
432
432
 
433
433
  const { occupiedExternalPorts, occupiedInternalPorts } = await this._getOccupiedPorts();
@@ -626,7 +626,7 @@ class BlockletState extends BaseState {
626
626
  async addChildren(did, children) {
627
627
  const parent = await this.getBlocklet(did);
628
628
  if (!parent) {
629
- throw new Error('Blocklet does not exist');
629
+ throw new Error(`Blocklet does not exist on addChildren: ${did}`);
630
630
  }
631
631
 
632
632
  const oldChildren = parent.children || [];
@@ -326,7 +326,7 @@ class TeamManager extends EventEmitter {
326
326
  async getRoles(did) {
327
327
  const rbac = await this.getRBAC(did);
328
328
  const roles = await rbac.getRoles();
329
- return roles.map((d) => pick(d, ['name', 'grants', 'title', 'description']));
329
+ return roles.map((d) => pick(d, ['name', 'grants', 'title', 'description', 'extra']));
330
330
  }
331
331
 
332
332
  async initTeam(did) {
@@ -12,6 +12,7 @@ const toLower = require('lodash/toLower');
12
12
  const isEmpty = require('lodash/isEmpty');
13
13
  const streamToPromise = require('stream-to-promise');
14
14
  const { Throttle } = require('stream-throttle');
15
+ const { slugify } = require('transliteration');
15
16
  const ssri = require('ssri');
16
17
  const diff = require('deep-diff');
17
18
  const createArchive = require('archiver');
@@ -19,6 +20,7 @@ const isUrl = require('is-url');
19
20
  const semver = require('semver');
20
21
  const { chainInfo: chainInfoSchema } = require('@arcblock/did-auth/lib/schema');
21
22
 
23
+ const urlPathFriendly = require('@blocklet/meta/lib/url-path-friendly').default;
22
24
  const { fromSecretKey, fromPublicKey } = require('@ocap/wallet');
23
25
  const { toHex, isHex, toDid, toAddress, toBuffer } = require('@ocap/util');
24
26
  const { isValid: isValidDid, isEthereumDid } = require('@arcblock/did');
@@ -309,6 +311,7 @@ const getAppSystemEnvironments = (blocklet, nodeInfo, dataDirs) => {
309
311
  BLOCKLET_APP_PSK: appPsk, // permanent sk even the blocklet has been migrated
310
312
  BLOCKLET_APP_PID: appPid, // permanent did even the blocklet has been migrated
311
313
  BLOCKLET_APP_NAME: appName,
314
+ BLOCKLET_APP_NAME_SLUG: urlPathFriendly(slugify(appName)),
312
315
  BLOCKLET_APP_DESCRIPTION: appDescription,
313
316
  BLOCKLET_APP_URL: appUrl,
314
317
  BLOCKLET_APP_DATA_DIR: path.join(dataDirs.data, blocklet.meta.name),
@@ -72,9 +72,19 @@ async function getSpaceNameByEndpoint(endpoint, defaultValue = '') {
72
72
  }
73
73
  }
74
74
 
75
+ /**
76
+ * @description
77
+ * @param {string} did
78
+ * @return {string}
79
+ */
80
+ function getBackupJobId(did) {
81
+ return `${did}.backupToSpaces`;
82
+ }
83
+
75
84
  module.exports = {
76
85
  getBackupEndpoint,
77
86
  getBackupFilesUrlFromEndpoint,
78
87
  getDIDSpacesUrlFromEndpoint,
79
88
  getSpaceNameByEndpoint,
89
+ getBackupJobId,
80
90
  };
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable newline-per-chained-call */
2
- const JOI = require('joi');
2
+ const Joi = require('joi');
3
3
  const { getMultipleLangParams } = require('./util');
4
4
 
5
- const roleNameSchema = JOI.string()
5
+ const roleNameSchema = Joi.string()
6
6
  .trim()
7
7
  .max(64)
8
8
  .custom((value) => {
@@ -17,19 +17,41 @@ const roleNameSchema = JOI.string()
17
17
  return value;
18
18
  });
19
19
 
20
- const titleSchema = JOI.string().trim().max(25);
21
- const descriptionSchema = JOI.string().trim().max(600);
20
+ const roleAcquireSchema = Joi.object({
21
+ pay: Joi.string().optional().allow(''),
22
+ exchange: Joi.string().optional().allow(''),
23
+ invite: Joi.boolean().optional(),
24
+ transfer: Joi.boolean().optional(),
25
+ request: Joi.boolean().optional(),
26
+ }).default({
27
+ pay: '',
28
+ exchange: '',
29
+ invite: true,
30
+ transfer: false,
31
+ request: false,
32
+ });
33
+
34
+ const titleSchema = Joi.string().trim().max(25);
35
+ const descriptionSchema = Joi.string().trim().max(600);
22
36
 
23
- const createRoleSchema = JOI.object({
37
+ const createRoleSchema = Joi.object({
24
38
  name: roleNameSchema.required(),
25
39
  title: titleSchema.required(),
26
40
  description: descriptionSchema.required(),
41
+ extra: Joi.object({
42
+ acquire: roleAcquireSchema,
43
+ payment: Joi.any().optional(),
44
+ }).optional(),
27
45
  });
28
46
 
29
- const updateRoleSchema = JOI.object({
47
+ const updateRoleSchema = Joi.object({
30
48
  name: roleNameSchema.required(),
31
49
  title: titleSchema,
32
50
  description: descriptionSchema,
51
+ extra: Joi.object({
52
+ acquire: roleAcquireSchema,
53
+ payment: Joi.any().optional(),
54
+ }).optional(),
33
55
  });
34
56
 
35
57
  module.exports = {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.17-beta-6f0c7674",
6
+ "version": "1.16.17-beta-952ef53d",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,19 +19,19 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/analytics": "1.16.17-beta-6f0c7674",
23
- "@abtnode/auth": "1.16.17-beta-6f0c7674",
24
- "@abtnode/certificate-manager": "1.16.17-beta-6f0c7674",
25
- "@abtnode/constant": "1.16.17-beta-6f0c7674",
26
- "@abtnode/cron": "1.16.17-beta-6f0c7674",
27
- "@abtnode/logger": "1.16.17-beta-6f0c7674",
28
- "@abtnode/models": "1.16.17-beta-6f0c7674",
29
- "@abtnode/queue": "1.16.17-beta-6f0c7674",
30
- "@abtnode/rbac": "1.16.17-beta-6f0c7674",
31
- "@abtnode/router-provider": "1.16.17-beta-6f0c7674",
32
- "@abtnode/static-server": "1.16.17-beta-6f0c7674",
33
- "@abtnode/timemachine": "1.16.17-beta-6f0c7674",
34
- "@abtnode/util": "1.16.17-beta-6f0c7674",
22
+ "@abtnode/analytics": "1.16.17-beta-952ef53d",
23
+ "@abtnode/auth": "1.16.17-beta-952ef53d",
24
+ "@abtnode/certificate-manager": "1.16.17-beta-952ef53d",
25
+ "@abtnode/constant": "1.16.17-beta-952ef53d",
26
+ "@abtnode/cron": "1.16.17-beta-952ef53d",
27
+ "@abtnode/logger": "1.16.17-beta-952ef53d",
28
+ "@abtnode/models": "1.16.17-beta-952ef53d",
29
+ "@abtnode/queue": "1.16.17-beta-952ef53d",
30
+ "@abtnode/rbac": "1.16.17-beta-952ef53d",
31
+ "@abtnode/router-provider": "1.16.17-beta-952ef53d",
32
+ "@abtnode/static-server": "1.16.17-beta-952ef53d",
33
+ "@abtnode/timemachine": "1.16.17-beta-952ef53d",
34
+ "@abtnode/util": "1.16.17-beta-952ef53d",
35
35
  "@arcblock/did": "1.18.92",
36
36
  "@arcblock/did-auth": "1.18.92",
37
37
  "@arcblock/did-ext": "^1.18.92",
@@ -42,11 +42,11 @@
42
42
  "@arcblock/pm2-events": "^0.0.5",
43
43
  "@arcblock/validator": "^1.18.92",
44
44
  "@arcblock/vc": "1.18.92",
45
- "@blocklet/constant": "1.16.17-beta-6f0c7674",
46
- "@blocklet/env": "1.16.17-beta-6f0c7674",
47
- "@blocklet/meta": "1.16.17-beta-6f0c7674",
48
- "@blocklet/resolver": "1.16.17-beta-6f0c7674",
49
- "@blocklet/sdk": "1.16.17-beta-6f0c7674",
45
+ "@blocklet/constant": "1.16.17-beta-952ef53d",
46
+ "@blocklet/env": "1.16.17-beta-952ef53d",
47
+ "@blocklet/meta": "1.16.17-beta-952ef53d",
48
+ "@blocklet/resolver": "1.16.17-beta-952ef53d",
49
+ "@blocklet/sdk": "1.16.17-beta-952ef53d",
50
50
  "@did-space/client": "^0.3.11",
51
51
  "@fidm/x509": "^1.2.1",
52
52
  "@ocap/mcrypto": "1.18.92",
@@ -101,5 +101,5 @@
101
101
  "jest": "^27.5.1",
102
102
  "unzipper": "^0.10.11"
103
103
  },
104
- "gitHead": "8123f54b0f572c47f1ea704607aae113576c2a76"
104
+ "gitHead": "a575050c7ffd08961a5f4072f4048f6e37976810"
105
105
  }