@abtnode/core 1.16.11-next-09bc31f8 → 1.16.11-next-7cff3891

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.
@@ -70,6 +70,8 @@ const {
70
70
  BLOCKLET_CONFIGURABLE_KEY,
71
71
  RESTORE_PROGRESS_STATUS,
72
72
  CHAIN_PROP_MAP_REVERSE,
73
+ BLOCKLET_CONTROLLER_STATUS,
74
+ SUSPENDED_REASON,
73
75
  } = require('@blocklet/constant');
74
76
  const { consumeServerlessNFT, consumeLauncherSession } = require('../../util/launcher');
75
77
  const util = require('../../util');
@@ -111,7 +113,7 @@ const {
111
113
  getProcessState,
112
114
  getBlockletStatus,
113
115
  shouldSkipComponent,
114
- shouldCleanExpiredBlocklet,
116
+ exceedRedemptionPeriod,
115
117
  } = require('../../util/blocklet');
116
118
  const states = require('../../states');
117
119
  const BaseBlockletManager = require('./base');
@@ -457,6 +459,8 @@ class BlockletManager extends BaseBlockletManager {
457
459
  // should check blocklet integrity
458
460
  const blocklet = await this.ensureBlocklet(did, { e2eMode });
459
461
 
462
+ await this.checkControllerStatus(blocklet, 'start');
463
+
460
464
  try {
461
465
  // blocklet may be manually stopped durning starting
462
466
  // so error message would not be sent if blocklet is stopped
@@ -651,7 +655,6 @@ class BlockletManager extends BaseBlockletManager {
651
655
  }
652
656
 
653
657
  /**
654
- * FIXME: @linchen support cancel
655
658
  * @param {import('@abtnode/client').RequestRestoreBlockletInput} input
656
659
  * @memberof BlockletManager
657
660
  */
@@ -677,6 +680,8 @@ class BlockletManager extends BaseBlockletManager {
677
680
  */
678
681
  async restart({ did, componentDids }, context) {
679
682
  logger.info('restart blocklet', { did });
683
+ const blocklet = await this.getBlocklet(did);
684
+ await this.checkControllerStatus(blocklet, 'restart');
680
685
 
681
686
  await states.blocklet.setBlockletStatus(did, BlockletStatus.stopping, { componentDids });
682
687
  const result = await states.blocklet.getBlocklet(did);
@@ -712,6 +717,8 @@ class BlockletManager extends BaseBlockletManager {
712
717
  async reload({ did, componentDids: list }, context) {
713
718
  const blocklet = await this.getBlocklet(did);
714
719
 
720
+ await this.checkControllerStatus(blocklet, 'reload');
721
+
715
722
  const componentDids = (blocklet.children || [])
716
723
  .filter((x) => x.status === BlockletStatus.running)
717
724
  .filter((x) => !shouldSkipComponent(x.meta.did, list))
@@ -1042,22 +1049,9 @@ class BlockletManager extends BaseBlockletManager {
1042
1049
  }
1043
1050
  }
1044
1051
 
1045
- async list({ includeRuntimeInfo = true, query, filter } = {}, context) {
1052
+ async list({ includeRuntimeInfo = true, query } = {}, context) {
1046
1053
  const condition = { ...flat(query || {}) };
1047
- if (filter === 'external-only') {
1048
- condition.controller = {
1049
- $exists: true,
1050
- };
1051
- }
1052
-
1053
- if (filter === 'external-excluded') {
1054
- condition.controller = {
1055
- $exists: false,
1056
- };
1057
- }
1058
-
1059
1054
  const blocklets = await states.blocklet.getBlocklets(condition);
1060
-
1061
1055
  if (includeRuntimeInfo) {
1062
1056
  return this._attachBlockletListRuntimeInfo({ blocklets }, context);
1063
1057
  }
@@ -1559,22 +1553,29 @@ class BlockletManager extends BaseBlockletManager {
1559
1553
  {
1560
1554
  name: 'refresh-accessible-ip',
1561
1555
  time: '0 */10 * * * *', // 10min
1556
+ options: { runOnInit: true },
1562
1557
  fn: async () => {
1563
1558
  const nodeInfo = await states.node.read();
1564
1559
  await refreshAccessibleExternalNodeIp(nodeInfo);
1565
1560
  },
1566
1561
  },
1567
1562
  {
1568
- name: 'delete-expired-external-blocklet',
1563
+ name: 'check-renewed-blocklet',
1564
+ time: '0 */10 * * * *', // 10min
1565
+ options: { runOnInit: false },
1566
+ fn: () => this.checkRenewedBlocklet(),
1567
+ },
1568
+ {
1569
+ name: 'stop-expired-external-blocklet',
1569
1570
  time: '0 */30 * * * *', // 30min
1570
1571
  options: { runOnInit: false },
1571
- fn: () => this._deleteExpiredExternalBlocklet(),
1572
+ fn: () => this.stopExpiredBlocklets(),
1572
1573
  },
1573
1574
  {
1574
1575
  name: 'clean-expired-blocklet-data',
1575
1576
  time: '0 */20 0 * * *', // 每天凌晨 0 点的每 20 分钟
1576
1577
  options: { runOnInit: false },
1577
- fn: () => this._cleanExpiredBlockletData(),
1578
+ fn: () => this.cleanExpiredBlocklets(),
1578
1579
  },
1579
1580
  {
1580
1581
  name: 'record-blocklet-runtime-history',
@@ -2856,71 +2857,102 @@ class BlockletManager extends BaseBlockletManager {
2856
2857
  }
2857
2858
  }
2858
2859
 
2859
- async _deleteExpiredExternalBlocklet() {
2860
+ async checkRenewedBlocklet() {
2860
2861
  try {
2861
- logger.info('start check expired external blocklet');
2862
+ logger.info('start check renewed blocklet');
2863
+
2864
+ // 只检查因为过期而被 suspended 的 blocklet
2865
+ const blockletExtras = await states.blockletExtras.find(
2866
+ {
2867
+ 'controller.status.value': BLOCKLET_CONTROLLER_STATUS.suspended,
2868
+ 'controller.status.reason': SUSPENDED_REASON.expired,
2869
+ },
2870
+ { did: 1, meta: 1, controller: 1 }
2871
+ );
2872
+
2873
+ for (const data of blockletExtras) {
2874
+ const blocklet = await states.blocklet.getBlocklet(data.did);
2875
+ if (!blocklet) {
2876
+ logger.error('blocklet not found', { did: data.did });
2877
+ // eslint-disable-next-line no-continue
2878
+ continue;
2879
+ }
2880
+
2881
+ const assetState = await util.getNFTState(data.controller.chainHost, data.controller.nftId);
2882
+ const isExpired = isNFTExpired(assetState);
2883
+ if (isExpired === false) {
2884
+ logger.info('blocklet is renewed', { did: data.did });
2885
+ await states.blockletExtras.updateByDid(data.did, {
2886
+ ...data.controller,
2887
+ status: { value: BLOCKLET_CONTROLLER_STATUS.normal, reason: '' },
2888
+ });
2889
+
2890
+ logger.info('start to start blocklet', { did: data.did });
2891
+
2892
+ if (![BlockletStatus.starting, BlockletStatus.running].includes(blocklet.status)) {
2893
+ await this.start({ did: data.did });
2894
+ logger.info('start blocklet success', { did: data.did });
2895
+ }
2896
+ }
2897
+ }
2898
+ } catch (error) {
2899
+ logger.error('start check renewed blocklet failed', { error });
2900
+ }
2901
+ }
2902
+
2903
+ async stopExpiredBlocklets() {
2904
+ try {
2905
+ logger.info('start checking expired blocklet');
2862
2906
  const blockletExtras = await states.blockletExtras.find(
2863
2907
  {
2864
2908
  controller: {
2865
2909
  $exists: true,
2866
2910
  },
2867
- expiredAt: {
2868
- $exists: false,
2869
- },
2870
2911
  },
2871
2912
  { did: 1, meta: 1, controller: 1 }
2872
2913
  );
2873
2914
 
2874
- logger.info('external blocklet count', { count: blockletExtras.length });
2915
+ if (blockletExtras.length === 0) {
2916
+ logger.info('no expired blocklet');
2917
+ return;
2918
+ }
2919
+
2920
+ logger.info('expired blocklet count', { count: blockletExtras.length });
2875
2921
 
2876
2922
  for (const data of blockletExtras) {
2877
2923
  try {
2878
- if (isEmpty(data.controller)) {
2879
- logger.info('skip the blocklet without controller', { blockletDid: data.did, controller: data.controller });
2880
- // eslint-disable-next-line no-continue
2881
- continue;
2882
- }
2883
-
2884
2924
  const { did } = data;
2885
2925
  const assetState = await util.getNFTState(data.controller.chainHost, data.controller.nftId);
2886
2926
  const isExpired = isNFTExpired(assetState);
2927
+ const blocklet = await states.blocklet.getBlocklet(did);
2887
2928
 
2888
- if (isExpired) {
2889
- logger.info('the blocklet already expired', {
2929
+ if (isExpired && blocklet.status !== BlockletStatus.stopped) {
2930
+ const expiredAt = getNftExpirationDate(assetState);
2931
+ logger.info('the blocklet already expired and will be stopped', {
2890
2932
  blockletDid: did,
2891
2933
  nftId: data.controller.nftId,
2934
+ expiredAt,
2892
2935
  });
2893
2936
 
2894
- const blocklet = await states.blocklet.getBlocklet(did);
2895
- if (blocklet) {
2896
- // 预防 Blocklet 已经删除,但是 blocklet extra data 没有清理的场景
2897
- await this._backupToDisk({ blocklet });
2898
- logger.info('backed up the expired blocklet', {
2899
- blockletDid: did,
2900
- nftId: data.controller.nftId,
2901
- });
2902
-
2903
- await this.delete({ did, keepData: true, keepConfigs: true, keepLogsDir: true });
2904
- logger.info('the expired blocklet already deleted', {
2905
- blockletDid: did,
2906
- nftId: data.controller.nftId,
2907
- });
2908
- }
2909
-
2910
- const expiredAt = getNftExpirationDate(assetState);
2911
- await states.blockletExtras.updateExpireInfo({ did, expiredAt });
2912
- logger.info('updated expired blocklet extra info', {
2913
- nftId: data.controller.nftId,
2914
- blockletDid: did,
2937
+ await this.stop({ did });
2938
+ await states.blockletExtras.updateByDid(did, {
2939
+ controller: {
2940
+ ...data.controller,
2941
+ status: {
2942
+ value: BLOCKLET_CONTROLLER_STATUS.suspended,
2943
+ reason: SUSPENDED_REASON.expired,
2944
+ },
2945
+ },
2915
2946
  });
2947
+ logger.info('the expired blocklet is stopped', { did });
2916
2948
 
2917
- // 删除 blocklet 后会 reload nginx, 所以这里每次删除一个
2949
+ // 为了减小服务器压力,每次删除一个 blocklet 后,休息 10s
2918
2950
  if (process.env.NODE_ENV !== 'test') {
2919
2951
  await sleep(10 * 1000);
2920
2952
  }
2921
2953
  }
2922
2954
  } catch (error) {
2923
- logger.error('delete expired blocklet failed', {
2955
+ logger.error('stop expired blocklet failed', {
2924
2956
  blockletDid: data.did,
2925
2957
  nftId: data.controller?.nftId,
2926
2958
  error,
@@ -2934,62 +2966,68 @@ class BlockletManager extends BaseBlockletManager {
2934
2966
  }
2935
2967
  }
2936
2968
 
2937
- async _cleanExpiredBlockletData() {
2969
+ async cleanExpiredBlocklets() {
2938
2970
  try {
2939
- logger.info('start clean expired blocklet data');
2940
- const blockletExtras = await states.blockletExtras.getExpiredList();
2971
+ logger.info('start checking exceeding the redemption period blocklet');
2972
+ const blockletExtras = await states.blockletExtras.find(
2973
+ {
2974
+ 'controller.status.value': BLOCKLET_CONTROLLER_STATUS.suspended,
2975
+ },
2976
+ { did: 1, meta: 1, controller: 1 }
2977
+ );
2978
+
2941
2979
  if (blockletExtras.length === 0) {
2942
- logger.info('no expired blocklet data');
2980
+ logger.info('no exceeding the redemption blocklet need to be cleaned');
2943
2981
  return;
2944
2982
  }
2945
2983
 
2946
- const tasks = blockletExtras.map(async ({ appDid, did, meta, controller }) => {
2947
- const blocklet = await this.getBlocklet(did);
2948
- if (blocklet) {
2949
- logger.error('skip cleaning the blocklet which is not deleted', { blockletDid: did });
2950
- return;
2951
- }
2952
-
2953
- const assetState = await util.getNFTState(controller.chainHost, controller.nftId);
2954
- const expirationDate = getNftExpirationDate(assetState);
2984
+ logger.info('exceeding the redemption blocklet count', { count: blockletExtras.length });
2955
2985
 
2956
- if (!shouldCleanExpiredBlocklet(expirationDate)) {
2957
- logger.error('skip cleaning the blocklet which is not expired', { blockletDid: did, expirationDate });
2958
- await blockletExtras.updateExpireInfo({ did, expiredAt: expirationDate });
2959
- return;
2960
- }
2961
-
2962
- let blockletMeta = meta;
2963
- if (isEmpty(blockletMeta)) {
2964
- // 旧版本的 blocklet 没有 meta 信息,这里补充一下
2965
- blockletMeta = { did, name: did };
2966
- logger.error('the blocklet original meta is empty', { did, blockletMeta });
2967
- }
2986
+ for (const data of blockletExtras) {
2987
+ try {
2988
+ const { did } = data;
2989
+ const assetState = await util.getNFTState(data.controller.chainHost, data.controller.nftId);
2990
+ const expiredAt = getNftExpirationDate(assetState);
2968
2991
 
2969
- await this._cleanBlockletData({
2970
- blocklet: { meta: blockletMeta },
2971
- keepData: false,
2972
- keepLogsDir: false,
2973
- keepConfigs: false,
2974
- });
2975
- logger.info(`clean blocklet ${blockletMeta.did} extra data`);
2992
+ if (!exceedRedemptionPeriod(expiredAt)) {
2993
+ logger.error('skip cleaning the non-exceed redemption blocklet', {
2994
+ blockletDid: did,
2995
+ expiredAt,
2996
+ });
2997
+ // eslint-disable-next-line no-continue
2998
+ continue;
2999
+ }
2976
3000
 
2977
- await removeBackup(this.dataDirs.data, appDid);
2978
- logger.info(`removed blocklet ${blockletMeta.did} backup`);
3001
+ logger.info('the blocklet already exceed redemption and will be deleted', {
3002
+ blockletDid: did,
3003
+ nftId: data.controller.nftId,
3004
+ expiredAt,
3005
+ });
2979
3006
 
2980
- this.emit(BlockletEvents.dataCleaned, {
2981
- blocklet: { meta: blockletMeta },
2982
- keepRouting: false,
2983
- });
3007
+ // TODO: 如果绑定了 DID Space 备份到 DID Space
2984
3008
 
2985
- logger.info(`cleaned expired blocklet blocklet ${blockletMeta.did} data`);
2986
- });
3009
+ await this.delete({ did, keepData: false, keepConfigs: false, keepLogsDir: false });
3010
+ logger.info('the exceed redemption blocklet already deleted', {
3011
+ blockletDid: did,
3012
+ nftId: data.controller.nftId,
3013
+ });
2987
3014
 
2988
- await Promise.all(tasks);
3015
+ // 删除 blocklet 后会 reload nginx, 所以这里每次删除一个
3016
+ if (process.env.NODE_ENV !== 'test') {
3017
+ await sleep(10 * 1000);
3018
+ }
3019
+ } catch (error) {
3020
+ logger.error('delete exceed redemption blocklet failed', {
3021
+ blockletDid: data.did,
3022
+ nftId: data.controller?.nftId,
3023
+ error,
3024
+ });
3025
+ }
3026
+ }
2989
3027
 
2990
- logger.info('clean expired blocklet data done');
3028
+ logger.info('check exceeding the redemption period blocklet end');
2991
3029
  } catch (error) {
2992
- logger.error('clean expired blocklet data failed', { error });
3030
+ logger.error('checking exceeding the redemption period blocklet failed', { error });
2993
3031
  }
2994
3032
  }
2995
3033
 
@@ -3193,6 +3231,38 @@ class BlockletManager extends BaseBlockletManager {
3193
3231
  }
3194
3232
  await this._setConfigsFromMeta(did);
3195
3233
  }
3234
+
3235
+ async checkControllerStatus(blocklet, action) {
3236
+ if (isEmpty(blocklet.controller)) {
3237
+ return;
3238
+ }
3239
+
3240
+ const assetState = await util.getNFTState(blocklet.controller?.chainHost, blocklet.controller?.nftId);
3241
+
3242
+ if (isNFTExpired(assetState)) {
3243
+ logger.error(`try to ${action} an expired blocklet`, {
3244
+ did: blocklet.meta.did,
3245
+ nftId: blocklet.controller?.nftId,
3246
+ });
3247
+ throw new Error(`can not ${action} an expired blocklet`);
3248
+ }
3249
+
3250
+ if (
3251
+ blocklet.controller.status?.value === BLOCKLET_CONTROLLER_STATUS.suspended &&
3252
+ blocklet.controller.status?.reason === SUSPENDED_REASON.expired
3253
+ ) {
3254
+ // 如果是因为过期被暂停的,续期后, 并且不影响启动
3255
+ await states.blockletExtras.updateByDid(blocklet.meta.did, {
3256
+ controller: {
3257
+ ...blocklet.controller,
3258
+ status: {
3259
+ value: BLOCKLET_CONTROLLER_STATUS.normal,
3260
+ reason: '',
3261
+ },
3262
+ },
3263
+ });
3264
+ }
3265
+ }
3196
3266
  }
3197
3267
 
3198
3268
  module.exports = BlockletManager;
@@ -2,15 +2,13 @@
2
2
  /* eslint-disable no-underscore-dangle */
3
3
  /* eslint-disable consistent-return */
4
4
  const logger = require('@abtnode/logger')('@abtnode/core:states:blocklet-extras');
5
- const { EXPIRED_BLOCKLET_DATA_RETENTION_DAYS } = require('@abtnode/constant');
6
5
  const camelCase = require('lodash/camelCase');
7
6
  const get = require('lodash/get');
8
- const dayjs = require('dayjs');
9
7
 
10
8
  const BaseState = require('./base');
11
9
 
12
10
  const { mergeConfigs, parseConfigs, encryptConfigs } = require('../blocklet/extras');
13
- const { validateAddMeta, validateExpiredInfo } = require('../validators/blocklet-extra');
11
+ const { validateAddMeta } = require('../validators/blocklet-extra');
14
12
 
15
13
  const noop = (k) => (v) => v[k];
16
14
 
@@ -213,19 +211,6 @@ class BlockletExtrasState extends BaseState {
213
211
  return super.findOne({ did }, { did: 1, controller: 1, meta: 1 });
214
212
  }
215
213
 
216
- async updateExpireInfo({ did, expiredAt } = {}) {
217
- const entity = { did, expiredAt };
218
- await validateExpiredInfo(entity);
219
-
220
- return this.updateByDid(did, { expiredAt });
221
- }
222
-
223
- async getExpiredList() {
224
- const deadline = dayjs().subtract(EXPIRED_BLOCKLET_DATA_RETENTION_DAYS, 'days').toISOString();
225
- const docs = await super.find({ expiredAt: { $exists: true } });
226
- return docs.filter((x) => x.controller?.nftId).filter((x) => x.expiredAt <= deadline);
227
- }
228
-
229
214
  async isLauncherSessionConsumed(sessionId) {
230
215
  const count = await super.count({ 'controller.sessionId': sessionId });
231
216
  return count > 0;
@@ -104,7 +104,7 @@ class TeamManager extends EventEmitter {
104
104
  return this.getState(teamDid, 'passport');
105
105
  }
106
106
 
107
- async getConnectedAccount(teamDid) {
107
+ async getConnectedAccountState(teamDid) {
108
108
  return this.getState(teamDid, 'connectedAccount');
109
109
  }
110
110
 
@@ -892,13 +892,15 @@ const checkBlockletProcessHealthy = async (blocklet, { minConsecutiveTime, timeo
892
892
  return;
893
893
  }
894
894
 
895
- await _checkProcessHealthy(b, { minConsecutiveTime, timeout });
895
+ const logToTerminal = [blocklet.mode, b.mode].includes(BLOCKLET_MODES.DEVELOPMENT);
896
+
897
+ await _checkProcessHealthy(b, { minConsecutiveTime, timeout, logToTerminal });
896
898
  },
897
899
  { parallel: true }
898
900
  );
899
901
  };
900
902
 
901
- const _checkProcessHealthy = async (blocklet, { minConsecutiveTime, timeout }) => {
903
+ const _checkProcessHealthy = async (blocklet, { minConsecutiveTime, timeout, logToTerminal }) => {
902
904
  const { meta, ports, env } = blocklet;
903
905
  const { name } = meta;
904
906
  const { processId } = env;
@@ -934,6 +936,14 @@ const _checkProcessHealthy = async (blocklet, { minConsecutiveTime, timeout }) =
934
936
  }
935
937
 
936
938
  const port = findInterfacePortByName({ meta, ports }, webInterface.name);
939
+ if (logToTerminal) {
940
+ // eslint-disable-next-line no-console
941
+ console.log(
942
+ `Checking endpoint healthy for ${meta.title}, port: ${port}, minConsecutiveTime: ${
943
+ minConsecutiveTime / 1000
944
+ }s, timeout: ${timeout / 1000}s`
945
+ );
946
+ }
937
947
  try {
938
948
  await ensureEndpointHealthy({
939
949
  port,
@@ -1953,7 +1963,7 @@ const shouldSkipComponent = (componentDid, whiteList) => {
1953
1963
  return !arr.includes(componentDid);
1954
1964
  };
1955
1965
 
1956
- const shouldCleanExpiredBlocklet = (expirationDate) => {
1966
+ const exceedRedemptionPeriod = (expirationDate) => {
1957
1967
  return dayjs().diff(dayjs(expirationDate), 'day') > EXPIRED_BLOCKLET_DATA_RETENTION_DAYS;
1958
1968
  };
1959
1969
 
@@ -2016,6 +2026,6 @@ module.exports = {
2016
2026
  getProcessState,
2017
2027
  getBlockletStatus,
2018
2028
  shouldSkipComponent,
2019
- shouldCleanExpiredBlocklet,
2020
2029
  getBlockletURLForLauncher,
2030
+ exceedRedemptionPeriod,
2021
2031
  };
@@ -1,6 +1,7 @@
1
1
  const joinUrl = require('url-join');
2
2
  const axios = require('@abtnode/util/lib/axios');
3
3
  const { DEFAULT_IP_DOMAIN, DEFAULT_ADMIN_PATH } = require('@abtnode/constant');
4
+ const logger = require('@abtnode/logger')('@abtnode/core:util:get-accessible-external-node-ip');
4
5
  const { get: getIp } = require('./ip');
5
6
 
6
7
  const getNodeDomain = (ip) => (ip ? DEFAULT_IP_DOMAIN.replace(/^\*/, ip.replace(/\./g, '-')) : '');
@@ -23,6 +24,7 @@ const checkConnected = async ({ ip, nodeInfo }) => {
23
24
  */
24
25
  const fetch = async (nodeInfo) => {
25
26
  const { external } = await getIp();
27
+ logger.info('refresh external ip:', external);
26
28
 
27
29
  if (!external) {
28
30
  return null;
@@ -12,9 +12,13 @@ const resetOwner = async ({ teamManager }) => {
12
12
  const nodeInfo = await states.node.read();
13
13
  const teamDid = nodeInfo.did;
14
14
  const userState = await teamManager.getUserState(teamDid);
15
- const count = await userState.remove({ role: 'owner' });
15
+ const passportState = await teamManager.getPassportState(teamDid);
16
+ const connectedAccountState = await teamManager.getConnectedAccountState(teamDid);
17
+ await passportState.remove({ userDid: nodeInfo.nodeOwner.did });
18
+ await connectedAccountState.remove({ userDid: nodeInfo.nodeOwner.did });
19
+ await userState.remove({ did: nodeInfo.nodeOwner.did });
16
20
  await states.node.updateNodeInfo({ nodeOwner: null });
17
- logger.info('reset node owner', result, count);
21
+ logger.info('reset node owner', result);
18
22
  } catch (err) {
19
23
  // Do nothing
20
24
  }
@@ -69,22 +73,21 @@ const resetCertificates = async ({ certManager }) => {
69
73
  };
70
74
 
71
75
  const resetUsers = async ({ teamManager }) => {
72
- const nodeInfo = await states.node.read();
73
-
74
- const teamDid = nodeInfo.did;
75
- const userState = await teamManager.getUserState(teamDid);
76
- const users = await userState.find({});
76
+ try {
77
+ const nodeInfo = await states.node.read();
77
78
 
78
- let count = 0;
79
- for (const user of users) {
80
- if (nodeInfo.nodeOwner.did !== user.did) {
81
- // eslint-disable-next-line no-await-in-loop
82
- await userState.remove({ did: user.did });
83
- count++;
84
- }
79
+ const teamDid = nodeInfo.did;
80
+ const userState = await teamManager.getUserState(teamDid);
81
+ const passportState = await teamManager.getPassportState(teamDid);
82
+ const connectedAccountState = await teamManager.getConnectedAccountState(teamDid);
83
+ await passportState.remove({ userDid: { $ne: nodeInfo.nodeOwner.did } });
84
+ await connectedAccountState.remove({ userDid: { $ne: nodeInfo.nodeOwner.did } });
85
+ await userState.remove({ did: { $ne: nodeInfo.nodeOwner.did } });
86
+
87
+ logger.info('reset users');
88
+ } catch (error) {
89
+ logger.error('failed reset users', { error });
85
90
  }
86
-
87
- logger.info('reset users', { count });
88
91
  };
89
92
 
90
93
  const resetInvitations = async ({ teamManager }) => {
@@ -13,12 +13,6 @@ const addMeta = Joi.object({
13
13
  controller: blockletController.optional(),
14
14
  }).required();
15
15
 
16
- const updateExpiredInfo = Joi.object({
17
- did: Joi.DID().required(),
18
- expiredAt: Joi.string().required(),
19
- });
20
-
21
16
  module.exports = {
22
17
  validateAddMeta: createValidator(addMeta),
23
- validateExpiredInfo: createValidator(updateExpiredInfo),
24
18
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.11-next-09bc31f8",
6
+ "version": "1.16.11-next-7cff3891",
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": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.16.11-next-09bc31f8",
23
- "@abtnode/certificate-manager": "1.16.11-next-09bc31f8",
24
- "@abtnode/constant": "1.16.11-next-09bc31f8",
25
- "@abtnode/cron": "1.16.11-next-09bc31f8",
26
- "@abtnode/logger": "1.16.11-next-09bc31f8",
27
- "@abtnode/models": "1.16.11-next-09bc31f8",
28
- "@abtnode/queue": "1.16.11-next-09bc31f8",
29
- "@abtnode/rbac": "1.16.11-next-09bc31f8",
30
- "@abtnode/router-provider": "1.16.11-next-09bc31f8",
31
- "@abtnode/static-server": "1.16.11-next-09bc31f8",
32
- "@abtnode/timemachine": "1.16.11-next-09bc31f8",
33
- "@abtnode/util": "1.16.11-next-09bc31f8",
22
+ "@abtnode/auth": "1.16.11-next-7cff3891",
23
+ "@abtnode/certificate-manager": "1.16.11-next-7cff3891",
24
+ "@abtnode/constant": "1.16.11-next-7cff3891",
25
+ "@abtnode/cron": "1.16.11-next-7cff3891",
26
+ "@abtnode/logger": "1.16.11-next-7cff3891",
27
+ "@abtnode/models": "1.16.11-next-7cff3891",
28
+ "@abtnode/queue": "1.16.11-next-7cff3891",
29
+ "@abtnode/rbac": "1.16.11-next-7cff3891",
30
+ "@abtnode/router-provider": "1.16.11-next-7cff3891",
31
+ "@abtnode/static-server": "1.16.11-next-7cff3891",
32
+ "@abtnode/timemachine": "1.16.11-next-7cff3891",
33
+ "@abtnode/util": "1.16.11-next-7cff3891",
34
34
  "@arcblock/did": "1.18.80",
35
35
  "@arcblock/did-auth": "1.18.80",
36
36
  "@arcblock/did-ext": "^1.18.80",
@@ -41,10 +41,10 @@
41
41
  "@arcblock/pm2-events": "^0.0.5",
42
42
  "@arcblock/validator": "^1.18.80",
43
43
  "@arcblock/vc": "1.18.80",
44
- "@blocklet/constant": "1.16.11-next-09bc31f8",
45
- "@blocklet/meta": "1.16.11-next-09bc31f8",
46
- "@blocklet/sdk": "1.16.11-next-09bc31f8",
47
- "@did-space/client": "^0.2.112",
44
+ "@blocklet/constant": "1.16.11-next-7cff3891",
45
+ "@blocklet/meta": "1.16.11-next-7cff3891",
46
+ "@blocklet/sdk": "1.16.11-next-7cff3891",
47
+ "@did-space/client": "^0.2.113",
48
48
  "@fidm/x509": "^1.2.1",
49
49
  "@ocap/mcrypto": "1.18.80",
50
50
  "@ocap/util": "1.18.80",
@@ -96,5 +96,5 @@
96
96
  "express": "^4.18.2",
97
97
  "jest": "^27.5.1"
98
98
  },
99
- "gitHead": "c51355ac77d07dc27e2fb6c44ce2a45432a9469b"
99
+ "gitHead": "53ffbcdca9cda278337d80bfafa44e7ef5635af1"
100
100
  }