@abtnode/core 1.16.30-beta-cd65989e → 1.16.30

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
@@ -465,14 +465,23 @@ class TeamAPI extends EventEmitter {
465
465
  throw new Error('Cannot update owner\'s approval'); // prettier-ignore
466
466
  }
467
467
 
468
- const doc2 = await state.updateApproved(pick(user, ['did', 'approved']));
468
+ const changeData = pick(user, ['did', 'approved']);
469
+
470
+ const result = await state.updateApproved(changeData);
469
471
 
470
472
  logger.info('user approval updated successfully', { teamDid, userDid: user.did, approved: user.approved });
471
473
 
472
- this.emit(TeamEvents.userUpdated, { teamDid, user: doc2 });
473
- this.emit(TeamEvents.userPermissionUpdated, { teamDid, user: doc2 });
474
+ if (changeData?.approved === false) {
475
+ // 需要注销指定 userDid 在当前 member 和 master 中的所有 userSession
476
+ await this.logoutUser({
477
+ teamDid,
478
+ userDid: user.did,
479
+ });
480
+ }
481
+ this.emit(TeamEvents.userUpdated, { teamDid, user: result });
482
+ this.emit(TeamEvents.userPermissionUpdated, { teamDid, user: result });
474
483
 
475
- return doc2;
484
+ return result;
476
485
  }
477
486
 
478
487
  async issuePassportToUser({ teamDid, userDid, role: roleName, notify = true }, context = {}) {
@@ -1479,7 +1488,17 @@ class TeamAPI extends EventEmitter {
1479
1488
  include: {
1480
1489
  model: userState.model,
1481
1490
  as: 'user',
1482
- attributes: ['did', 'pk', 'sourceProvider', 'fullName', 'email', 'avatar', 'remark', 'sourceAppPid'],
1491
+ attributes: [
1492
+ 'did',
1493
+ 'pk',
1494
+ 'sourceProvider',
1495
+ 'fullName',
1496
+ 'email',
1497
+ 'avatar',
1498
+ 'remark',
1499
+ 'sourceAppPid',
1500
+ 'approved',
1501
+ ],
1483
1502
  },
1484
1503
  });
1485
1504
  return userSessions.map((x) => x.toJSON());
@@ -1524,7 +1543,7 @@ class TeamAPI extends EventEmitter {
1524
1543
 
1525
1544
  async upsertUserSession({ teamDid, appPid, userDid, visitorId, ua, lastLoginIp, passportId, status, extra }) {
1526
1545
  if (!userDid) {
1527
- throw new Error('userDid are required');
1546
+ throw new Error('userDid is required');
1528
1547
  }
1529
1548
 
1530
1549
  const state = await this.getUserSessionState(teamDid);
@@ -1663,9 +1682,26 @@ class TeamAPI extends EventEmitter {
1663
1682
  }
1664
1683
 
1665
1684
  async logoutUser({ teamDid, userDid, visitorId, appPid }) {
1666
- const state = await this.getUserSessionState(teamDid);
1667
- const data = await state.remove({ userDid, visitorId, appPid });
1685
+ if (!userDid) {
1686
+ throw new Error('userDid is required');
1687
+ }
1688
+ if (!teamDid) {
1689
+ throw new Error('teamDid is required');
1690
+ }
1691
+
1668
1692
  const nodeInfo = await this.node.read();
1693
+ if (nodeInfo.did === teamDid) {
1694
+ return 0;
1695
+ }
1696
+ const state = await this.getUserSessionState(teamDid);
1697
+ const userSessionParams = { userDid };
1698
+ if (visitorId) {
1699
+ userSessionParams.visitorId = visitorId;
1700
+ }
1701
+ if (appPid) {
1702
+ userSessionParams.appPid = appPid;
1703
+ }
1704
+ const result = await state.remove(userSessionParams);
1669
1705
  const blocklet = await getBlocklet({ did: teamDid, states: this.states, dataDirs: this.dataDirs });
1670
1706
  const { permanentWallet } = getBlockletInfo(blocklet, nodeInfo.sk);
1671
1707
  const federated = defaults(cloneDeep(blocklet.settings.federated || {}), {
@@ -1677,6 +1713,7 @@ class TeamAPI extends EventEmitter {
1677
1713
  callFederated({
1678
1714
  action: 'sync',
1679
1715
  permanentWallet,
1716
+ // FIXME: @zhanghan 是否还需要通知其他 Member 站点,执行退出登录的操作
1680
1717
  site: masterSite,
1681
1718
  data: {
1682
1719
  userSessions: [
@@ -1684,13 +1721,14 @@ class TeamAPI extends EventEmitter {
1684
1721
  action: 'logout',
1685
1722
  userDid,
1686
1723
  visitorId,
1687
- appPid: teamDid,
1724
+ // HACK: 如果未传入 appPid,代表要注销当前用户在 master 中所有登录状态,所以传入 undefined;否则就只注销 master 中记录的当前 member 的登录状态
1725
+ appPid: appPid ? teamDid : undefined,
1688
1726
  },
1689
1727
  ],
1690
1728
  },
1691
1729
  });
1692
1730
  }
1693
- return data;
1731
+ return result;
1694
1732
  }
1695
1733
  }
1696
1734
 
@@ -14,7 +14,8 @@ const timeout = process.env.NODE_ENV === 'test' ? 500 : 5000;
14
14
  // FIXME: check connected by wellknown endpoint
15
15
  const checkConnected = async ({ ip, info }) => {
16
16
  const { adminPath = WELLKNOWN_SERVER_ADMIN_PATH } = info.routing || {};
17
- const origin = `https://${getNodeDomain(ip)}`;
17
+ // dev 模式下,检查的地址不一样
18
+ const origin = process.env.NODE_ENV === 'development' ? `http://${ip}:3000` : `https://${getNodeDomain(ip)}`;
18
19
  const endpoint = joinURL(origin, adminPath);
19
20
  await axios.get(endpoint, { timeout });
20
21
  };
@@ -1,9 +1,11 @@
1
1
  const path = require('path');
2
+ const os = require('os');
2
3
  const fs = require('fs-extra');
3
4
  const { joinURL } = require('ufo');
4
5
  const dayjs = require('@abtnode/util/lib/dayjs');
5
6
  const pick = require('lodash/pick');
6
7
  const uniq = require('lodash/uniq');
8
+ const trim = require('lodash/trim');
7
9
  const isEmpty = require('lodash/isEmpty');
8
10
  const {
9
11
  getUserAvatarUrl,
@@ -415,7 +417,25 @@ const getLaunchSessionStatus = async (blockletDid, controller) => {
415
417
  return launcherSession.status;
416
418
  };
417
419
 
420
+ const isBlockletProtected = (blockletDid) => {
421
+ if (!process.env.ABT_NODE_DATA_DIR) {
422
+ return false;
423
+ }
424
+
425
+ const configFile = path.join(process.env.ABT_NODE_DATA_DIR, '.protected-serverless-apps');
426
+ if (fs.existsSync(configFile)) {
427
+ const protectedAppIds = fs.readFileSync(configFile, 'utf8').split(os.EOL).map(trim).filter(Boolean);
428
+ return protectedAppIds.includes(blockletDid);
429
+ }
430
+
431
+ return false;
432
+ };
433
+
418
434
  const isBlockletExpired = async (blockletDid, controller) => {
435
+ if (isBlockletProtected(blockletDid)) {
436
+ logger.info('skip expire protected serverless app', { blockletDid, controller });
437
+ return false;
438
+ }
419
439
  const status = await getLaunchSessionStatus(blockletDid, controller);
420
440
  return [LAUNCH_SESSION_STATUS.overdue, LAUNCH_SESSION_STATUS.canceled, LAUNCH_SESSION_STATUS.terminated].includes(
421
441
  status
@@ -425,6 +445,10 @@ const isBlockletExpired = async (blockletDid, controller) => {
425
445
  const isLaunchSessionTerminated = (session) => session.status === LAUNCH_SESSION_STATUS.terminated;
426
446
 
427
447
  const isBlockletTerminated = async (blockletDid, controller) => {
448
+ if (isBlockletProtected(blockletDid)) {
449
+ logger.info('skip terminate protected serverless app', { blockletDid, controller });
450
+ return false;
451
+ }
428
452
  const status = await getLaunchSessionStatus(blockletDid, controller);
429
453
  return status === LAUNCH_SESSION_STATUS.terminated;
430
454
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.30-beta-cd65989e",
6
+ "version": "1.16.30",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,40 +19,40 @@
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.30-beta-cd65989e",
23
- "@abtnode/auth": "1.16.30-beta-cd65989e",
24
- "@abtnode/certificate-manager": "1.16.30-beta-cd65989e",
25
- "@abtnode/constant": "1.16.30-beta-cd65989e",
26
- "@abtnode/cron": "1.16.30-beta-cd65989e",
27
- "@abtnode/logger": "1.16.30-beta-cd65989e",
28
- "@abtnode/models": "1.16.30-beta-cd65989e",
29
- "@abtnode/queue": "1.16.30-beta-cd65989e",
30
- "@abtnode/rbac": "1.16.30-beta-cd65989e",
31
- "@abtnode/router-provider": "1.16.30-beta-cd65989e",
32
- "@abtnode/static-server": "1.16.30-beta-cd65989e",
33
- "@abtnode/timemachine": "1.16.30-beta-cd65989e",
34
- "@abtnode/util": "1.16.30-beta-cd65989e",
35
- "@arcblock/did": "1.18.131",
36
- "@arcblock/did-auth": "1.18.131",
37
- "@arcblock/did-ext": "^1.18.131",
22
+ "@abtnode/analytics": "1.16.30",
23
+ "@abtnode/auth": "1.16.30",
24
+ "@abtnode/certificate-manager": "1.16.30",
25
+ "@abtnode/constant": "1.16.30",
26
+ "@abtnode/cron": "1.16.30",
27
+ "@abtnode/logger": "1.16.30",
28
+ "@abtnode/models": "1.16.30",
29
+ "@abtnode/queue": "1.16.30",
30
+ "@abtnode/rbac": "1.16.30",
31
+ "@abtnode/router-provider": "1.16.30",
32
+ "@abtnode/static-server": "1.16.30",
33
+ "@abtnode/timemachine": "1.16.30",
34
+ "@abtnode/util": "1.16.30",
35
+ "@arcblock/did": "1.18.132",
36
+ "@arcblock/did-auth": "1.18.132",
37
+ "@arcblock/did-ext": "^1.18.132",
38
38
  "@arcblock/did-motif": "^1.1.13",
39
- "@arcblock/did-util": "1.18.131",
40
- "@arcblock/event-hub": "1.18.131",
41
- "@arcblock/jwt": "^1.18.131",
39
+ "@arcblock/did-util": "1.18.132",
40
+ "@arcblock/event-hub": "1.18.132",
41
+ "@arcblock/jwt": "^1.18.132",
42
42
  "@arcblock/pm2-events": "^0.0.5",
43
- "@arcblock/validator": "^1.18.131",
44
- "@arcblock/vc": "1.18.131",
45
- "@blocklet/constant": "1.16.30-beta-cd65989e",
46
- "@blocklet/env": "1.16.30-beta-cd65989e",
47
- "@blocklet/meta": "1.16.30-beta-cd65989e",
48
- "@blocklet/resolver": "1.16.30-beta-cd65989e",
49
- "@blocklet/sdk": "1.16.30-beta-cd65989e",
50
- "@blocklet/store": "1.16.30-beta-cd65989e",
51
- "@did-space/client": "^0.5.27",
43
+ "@arcblock/validator": "^1.18.132",
44
+ "@arcblock/vc": "1.18.132",
45
+ "@blocklet/constant": "1.16.30",
46
+ "@blocklet/env": "1.16.30",
47
+ "@blocklet/meta": "1.16.30",
48
+ "@blocklet/resolver": "1.16.30",
49
+ "@blocklet/sdk": "1.16.30",
50
+ "@blocklet/store": "1.16.30",
51
+ "@did-space/client": "^0.5.28",
52
52
  "@fidm/x509": "^1.2.1",
53
- "@ocap/mcrypto": "1.18.131",
54
- "@ocap/util": "1.18.131",
55
- "@ocap/wallet": "1.18.131",
53
+ "@ocap/mcrypto": "1.18.132",
54
+ "@ocap/util": "1.18.132",
55
+ "@ocap/wallet": "1.18.132",
56
56
  "@slack/webhook": "^5.0.4",
57
57
  "archiver": "^7.0.1",
58
58
  "axios": "^1.7.2",
@@ -103,5 +103,5 @@
103
103
  "jest": "^29.7.0",
104
104
  "unzipper": "^0.10.11"
105
105
  },
106
- "gitHead": "8646768b8ac83cdb8c213ab17fe8030f3d5dc6fc"
106
+ "gitHead": "18420639259c736016b19152229183d9fc1c1656"
107
107
  }