@abtnode/core 1.7.18 → 1.7.21

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/node.js CHANGED
@@ -6,6 +6,7 @@ const isDocker = require('@abtnode/util/lib/is-docker');
6
6
  const isGitpod = require('@abtnode/util/lib/is-gitpod');
7
7
  const getFolderSize = require('@abtnode/util/lib/get-folder-size');
8
8
  const canPackageReadWrite = require('@abtnode/util/lib/can-pkg-rw');
9
+ const { toDelegateAddress } = require('@arcblock/did-util');
9
10
 
10
11
  const logger = require('@abtnode/logger')('@abtnode/core:api:node');
11
12
 
@@ -13,6 +14,7 @@ const IP = require('../util/ip');
13
14
  const { validateNodeInfo, validateUpdateGateway } = require('../validators/node');
14
15
  const BlockletRegistry = require('../blocklet/registry');
15
16
  const { getAll } = require('../blocklet/manager/engine');
17
+ const { getDelegateState } = require('../util');
16
18
 
17
19
  const sanitizeUrl = (url) => {
18
20
  if (!url) {
@@ -160,6 +162,24 @@ class NodeAPI {
160
162
 
161
163
  return this.state.updateGateway(data);
162
164
  }
165
+
166
+ async getDelegationState() {
167
+ const info = await this.state.read();
168
+
169
+ const { ownerNft } = info;
170
+ if (!ownerNft.did) {
171
+ throw new Error('Invalid owner NFT');
172
+ }
173
+
174
+ const address = toDelegateAddress(ownerNft.holder, info.did);
175
+ const state = await getDelegateState(info.launcher.chainHost, address);
176
+ if (!state) {
177
+ return { delegated: false };
178
+ }
179
+
180
+ const transferV2Delegation = (state.ops || []).find(({ key }) => key === 'fg:t:transfer_v2');
181
+ return { delegated: !!transferV2Delegation };
182
+ }
163
183
  }
164
184
 
165
185
  module.exports = NodeAPI;
package/lib/api/team.js CHANGED
@@ -25,7 +25,8 @@ class TeamAPI extends EventEmitter {
25
25
 
26
26
  this.notification = states.notification;
27
27
  this.node = states.node;
28
- this.inviteExpireTime = 1000 * 3600 * 24 * 30; // 30 days
28
+ this.memberInviteExpireTime = 1000 * 3600 * 24 * 30; // 30 days
29
+ this.serverInviteExpireTime = 1000 * 3600; // 1 hour
29
30
  this.teamManager = teamManager;
30
31
  }
31
32
 
@@ -224,9 +225,13 @@ class TeamAPI extends EventEmitter {
224
225
 
225
226
  // Invite member
226
227
 
227
- async createInvitation({ teamDid, role, remark }, context) {
228
+ async createMemberInvitation({ teamDid, role, expireTime, remark }, context) {
228
229
  await this.teamManager.checkEnablePassportIssuance(teamDid);
229
230
 
231
+ if (expireTime && expireTime <= 0) {
232
+ throw new Error('Expire time must be greater than 0');
233
+ }
234
+
230
235
  if (!role) {
231
236
  throw new Error('Role cannot be empty');
232
237
  }
@@ -246,7 +251,7 @@ class TeamAPI extends EventEmitter {
246
251
  throw new Error('Inviter does not exist');
247
252
  }
248
253
 
249
- const expireDate = Date.now() + this.inviteExpireTime;
254
+ const expireDate = Date.now() + (expireTime || this.memberInviteExpireTime);
250
255
  const state = await this.getSessionState(teamDid);
251
256
  const { id: inviteId } = await state.start({
252
257
  type: 'invite',
@@ -269,6 +274,36 @@ class TeamAPI extends EventEmitter {
269
274
  };
270
275
  }
271
276
 
277
+ async createTransferInvitation({ teamDid, remark }, context) {
278
+ return this.createMemberInvitation(
279
+ { teamDid, expireTime: this.serverInviteExpireTime, remark, role: 'owner' },
280
+ context
281
+ );
282
+ }
283
+
284
+ async getInvitation({ teamDid, inviteId }) {
285
+ if (!teamDid || !inviteId) {
286
+ return null;
287
+ }
288
+
289
+ const state = await this.getSessionState(teamDid);
290
+
291
+ const invitation = await state.findOne({ _id: inviteId, type: 'invite' });
292
+ if (!invitation) {
293
+ return null;
294
+ }
295
+
296
+ return {
297
+ // eslint-disable-next-line no-underscore-dangle
298
+ inviteId: invitation._id,
299
+ role: invitation.role,
300
+ remark: invitation.remark,
301
+ expireDate: new Date(invitation.expireDate).toString(),
302
+ inviter: invitation.inviter,
303
+ teamDid: invitation.teamDid,
304
+ };
305
+ }
306
+
272
307
  async getInvitations({ teamDid }) {
273
308
  const state = await this.getSessionState(teamDid);
274
309
 
@@ -350,7 +385,7 @@ class TeamAPI extends EventEmitter {
350
385
  throw new Error(`Passport does not exist: ${name}`);
351
386
  }
352
387
 
353
- const expireDate = Date.now() + this.inviteExpireTime;
388
+ const expireDate = Date.now() + this.memberInviteExpireTime;
354
389
 
355
390
  const state = await this.getSessionState(teamDid);
356
391
  const { id } = await state.start({
@@ -668,7 +703,7 @@ class TeamAPI extends EventEmitter {
668
703
  // Just for test
669
704
  // =============
670
705
  setInviteExpireTime(ms) {
671
- this.inviteExpireTime = ms;
706
+ this.memberInviteExpireTime = ms;
672
707
  }
673
708
  }
674
709
 
@@ -51,11 +51,7 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
51
51
  return true;
52
52
  }
53
53
 
54
- if (key.toString().startsWith('ABT_NODE_') || key.toString().startsWith('BLOCKLET_')) {
55
- return false;
56
- }
57
-
58
- return true;
54
+ return !(key.toString().startsWith('ABT_NODE_') || key.toString().startsWith('BLOCKLET_'));
59
55
  });
60
56
 
61
57
  newConfig.forEach((config) => {
@@ -7,7 +7,7 @@ const logger = require('@abtnode/logger')(`${require('../../package.json').name}
7
7
 
8
8
  const { getSafeEnv } = require('../util');
9
9
 
10
- const runUserHook = async (appId, hookName, args) => {
10
+ const runUserHook = async (processId, hookName, args) => {
11
11
  const { appDir, hooks, env, exitOnError = true, silent = false, notification, did } = args;
12
12
  const hook = get(hooks, `[${hookName}]`) || get(hooks, `[${camelCase(hookName)}]`);
13
13
 
@@ -17,7 +17,7 @@ const runUserHook = async (appId, hookName, args) => {
17
17
  }
18
18
 
19
19
  logger.info(`run hook:${hookName}:`, { hook });
20
- await runScript(hook, [appId, hookName].join(':'), { cwd: appDir, env: getSafeEnv(env), silent });
20
+ await runScript(hook, [processId, hookName].join(':'), { cwd: appDir, env: getSafeEnv(env), silent });
21
21
  } catch (error) {
22
22
  logger.error(`run ${hook} error:`, { error });
23
23
 
@@ -37,10 +37,10 @@ const runUserHook = async (appId, hookName, args) => {
37
37
  }
38
38
  };
39
39
 
40
- const preDeploy = (appId, ...args) => runUserHook(appId, 'pre-deploy', ...args);
41
- const preInstall = (appId, ...args) => runUserHook(appId, 'pre-install', ...args);
42
- const postInstall = (appId, ...args) => runUserHook(appId, 'post-install', ...args);
43
- const preConfig = (appId, ...args) => runUserHook(appId, 'pre-config', ...args);
40
+ const preDeploy = (processId, ...args) => runUserHook(processId, 'pre-deploy', ...args);
41
+ const preInstall = (processId, ...args) => runUserHook(processId, 'pre-install', ...args);
42
+ const postInstall = (processId, ...args) => runUserHook(processId, 'post-install', ...args);
43
+ const preConfig = (processId, ...args) => runUserHook(processId, 'pre-config', ...args);
44
44
  const preStart = async (blocklet, options) => {
45
45
  // check required environments
46
46
  let environments = get(blocklet, 'meta.environments', []);
@@ -53,10 +53,10 @@ const preStart = async (blocklet, options) => {
53
53
  throw new Error(`Required environments is not set: ${tmp.join(',')}`);
54
54
  }
55
55
 
56
- return runUserHook(blocklet.env.appId, 'pre-start', options);
56
+ return runUserHook(blocklet.env.processId, 'pre-start', options);
57
57
  };
58
58
 
59
- const preUninstall = (appId, ...args) => runUserHook(appId, 'pre-uninstall', ...args);
60
- const preStop = (appId, ...args) => runUserHook(appId, 'pre-stop', ...args);
59
+ const preUninstall = (processId, ...args) => runUserHook(processId, 'pre-uninstall', ...args);
60
+ const preStop = (processId, ...args) => runUserHook(processId, 'pre-stop', ...args);
61
61
 
62
62
  module.exports = { preDeploy, preInstall, postInstall, preStart, preUninstall, preStop, preConfig };