@abtnode/core 1.16.50 → 1.16.51-beta-20250905-023351-70af144b

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
@@ -59,6 +59,7 @@ const { getBlocklet } = require('../util/blocklet');
59
59
  const StoreUtil = require('../util/store');
60
60
  const { profileSchema } = require('../validators/user');
61
61
  const { passportDisplaySchema } = require('../validators/util');
62
+ const { validateUserRolePassport } = require('../util/validate-user-role-passport');
62
63
 
63
64
  const sanitizeUrl = (url) => {
64
65
  if (!url) {
@@ -683,9 +684,11 @@ class TeamAPI extends EventEmitter {
683
684
  }
684
685
  }
685
686
 
686
- async getUserFollowStats({ teamDid, userDids }) {
687
+ async getUserFollowStats({ teamDid, userDids }, context = {}) {
687
688
  const state = await this.getUserState(teamDid);
688
- return state.getFollowStats(userDids);
689
+ const info = await this.node.read();
690
+ const prefix = process.env.NODE_ENV === 'production' ? info.routing.adminPath : '';
691
+ return state.getFollowStats({ userDids, teamDid, prefix }, context);
689
692
  }
690
693
 
691
694
  async checkFollowing({ teamDid, userDids = [], followerDid }) {
@@ -1094,6 +1097,14 @@ class TeamAPI extends EventEmitter {
1094
1097
  throw new Error('Inviter does not exist');
1095
1098
  }
1096
1099
 
1100
+ if ((user?.role || '').startsWith('blocklet-')) {
1101
+ const userInfo = await this.getUser({ teamDid, user });
1102
+ validateUserRolePassport({
1103
+ role: (user?.role || '').replace('blocklet-', ''),
1104
+ passports: userInfo?.passports || [],
1105
+ });
1106
+ }
1107
+
1097
1108
  const expireDate = Date.now() + (expireTime || this.memberInviteExpireTime);
1098
1109
  const state = await this.getSessionState(teamDid);
1099
1110
  const { id: inviteId } = await state.start({
@@ -924,10 +924,14 @@ class DiskBlockletManager extends BaseBlockletManager {
924
924
  { parallel: true, concurrencyLimit: 4 }
925
925
  );
926
926
  if (nonEntryComponentIds.length) {
927
- nonEntryComponentRes = await states.blocklet.setBlockletStatus(did, BlockletStatus.running, {
927
+ const params = {
928
+ did,
929
+ context,
930
+ minConsecutiveTime: 3000,
931
+ timeout: 5000,
928
932
  componentDids: nonEntryComponentIds,
929
- operator,
930
- });
933
+ };
934
+ nonEntryComponentRes = await this._onCheckIfStarted(params, { throwOnError, skipRunningCheck: true });
931
935
  }
932
936
  } catch (err) {
933
937
  logger.error('Failed to categorize components into entry and non-entry types', { error: err.message });
@@ -1156,7 +1160,7 @@ class DiskBlockletManager extends BaseBlockletManager {
1156
1160
 
1157
1161
  logger.info('blocklet stopped successfully', { processId, did });
1158
1162
 
1159
- launcher.notifyBlockletUpdated(blocklet);
1163
+ launcher.notifyBlockletStopped(blocklet);
1160
1164
 
1161
1165
  if (updateStatus) {
1162
1166
  const res = await states.blocklet.setBlockletStatus(did, BlockletStatus.stopped, { componentDids, operator });
@@ -3379,7 +3383,7 @@ class DiskBlockletManager extends BaseBlockletManager {
3379
3383
  await this.start({ did, componentDids, operator }, context);
3380
3384
  }
3381
3385
 
3382
- async _onCheckIfStarted(jobInfo, { throwOnError } = {}) {
3386
+ async _onCheckIfStarted(jobInfo, { throwOnError, skipRunningCheck = false } = {}) {
3383
3387
  const startedAt = Date.now();
3384
3388
  const { did, context, minConsecutiveTime = 2000, timeout, componentDids } = jobInfo;
3385
3389
  const blocklet = await this.getBlocklet(did);
@@ -3389,18 +3393,19 @@ class DiskBlockletManager extends BaseBlockletManager {
3389
3393
 
3390
3394
  const nodeInfo = await states.node.read();
3391
3395
  try {
3392
- // healthy check
3393
- await checkBlockletProcessHealthy(blocklet, {
3394
- minConsecutiveTime,
3395
- timeout,
3396
- componentDids,
3397
- enableDocker: nodeInfo.enableDocker,
3398
- setBlockletRunning: async (componentDid) => {
3399
- await states.blocklet.setBlockletStatus(did, BlockletStatus.running, { componentDids: [componentDid] });
3400
- },
3401
- });
3396
+ if (!skipRunningCheck) {
3397
+ await checkBlockletProcessHealthy(blocklet, {
3398
+ minConsecutiveTime,
3399
+ timeout,
3400
+ componentDids,
3401
+ enableDocker: nodeInfo.enableDocker,
3402
+ setBlockletRunning: async (componentDid) => {
3403
+ await states.blocklet.setBlockletStatus(did, BlockletStatus.running, { componentDids: [componentDid] });
3404
+ },
3405
+ });
3406
+ }
3402
3407
 
3403
- await states.blocklet.setBlockletStatus(did, BlockletStatus.running, { componentDids });
3408
+ const runningRes = await states.blocklet.setBlockletStatus(did, BlockletStatus.running, { componentDids });
3404
3409
 
3405
3410
  const res = await this.getBlocklet(did);
3406
3411
 
@@ -3413,14 +3418,16 @@ class DiskBlockletManager extends BaseBlockletManager {
3413
3418
  this.emit(BlockletEvents.statusChange, res);
3414
3419
  this.emit(BlockletEvents.started, { ...res, componentDids });
3415
3420
 
3416
- launcher.notifyBlockletUpdated(blocklet);
3421
+ launcher.notifyBlockletStarted(blocklet);
3417
3422
 
3418
3423
  logger.info('blocklet healthy', { did, name, time: Date.now() - startedAt });
3424
+
3425
+ return runningRes;
3419
3426
  } catch (error) {
3420
3427
  const status = await states.blocklet.getBlockletStatus(did);
3421
3428
  if ([BlockletStatus.stopping, BlockletStatus.stopped].includes(status)) {
3422
3429
  logger.info(`Check blocklet healthy failing because blocklet is ${fromBlockletStatus(status)}`);
3423
- return;
3430
+ return {};
3424
3431
  }
3425
3432
 
3426
3433
  logger.error('check blocklet if started failed', { did, name, context, timeout, error });
@@ -3449,6 +3456,8 @@ class DiskBlockletManager extends BaseBlockletManager {
3449
3456
  if (throwOnError) {
3450
3457
  throw error;
3451
3458
  }
3459
+
3460
+ return doc;
3452
3461
  }
3453
3462
  }
3454
3463