@abtnode/core 1.17.0 → 1.17.1
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 +90 -3
- package/lib/blocklet/migration-dist/migration.cjs +1 -1
- package/lib/states/README.md +1 -1
- package/lib/states/org.js +11 -5
- package/package.json +37 -37
package/lib/api/team.js
CHANGED
|
@@ -3090,6 +3090,49 @@ class TeamAPI extends EventEmitter {
|
|
|
3090
3090
|
}
|
|
3091
3091
|
}
|
|
3092
3092
|
|
|
3093
|
+
getFederatedMasterBlockletInfo({ blocklet }) {
|
|
3094
|
+
const sites = blocklet.settings?.federated?.sites || [];
|
|
3095
|
+
const federatedMaster = sites.find((item) => item.isMaster !== false);
|
|
3096
|
+
const federatedCurrent = sites.find((item) => item.appId === blocklet.appDid);
|
|
3097
|
+
const isFederated = !!federatedMaster || !!federatedCurrent;
|
|
3098
|
+
if (!isFederated) {
|
|
3099
|
+
return undefined;
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
const formatBlockletInfo = (federateBlocklet) => ({
|
|
3103
|
+
appId: federateBlocklet?.appId,
|
|
3104
|
+
appName: federateBlocklet?.appName,
|
|
3105
|
+
appDescription: federateBlocklet?.appDescription,
|
|
3106
|
+
appLogo: federateBlocklet?.appLogo,
|
|
3107
|
+
appPid: federateBlocklet?.appPid,
|
|
3108
|
+
appUrl: federateBlocklet?.appUrl,
|
|
3109
|
+
version: federateBlocklet?.version,
|
|
3110
|
+
sourceAppPid: federateBlocklet?.appPid,
|
|
3111
|
+
provider: 'wallet',
|
|
3112
|
+
});
|
|
3113
|
+
|
|
3114
|
+
const blocklets = [];
|
|
3115
|
+
if (federatedCurrent?.status === 'approved') {
|
|
3116
|
+
blocklets.push(formatBlockletInfo(federatedMaster));
|
|
3117
|
+
}
|
|
3118
|
+
if (federatedCurrent) {
|
|
3119
|
+
blocklets.push({
|
|
3120
|
+
...formatBlockletInfo(federatedCurrent),
|
|
3121
|
+
sourceAppPid: null,
|
|
3122
|
+
});
|
|
3123
|
+
} else {
|
|
3124
|
+
const blockletInfo = getBlockletInfo(blocklet, undefined, { returnWallet: false });
|
|
3125
|
+
blocklets.push({
|
|
3126
|
+
...formatBlockletInfo(blockletInfo),
|
|
3127
|
+
appPid: blocklet?.appPid,
|
|
3128
|
+
appLogo: joinURL(blockletInfo.appUrl, WELLKNOWN_SERVICE_PATH_PREFIX, '/blocklet/logo'),
|
|
3129
|
+
sourceAppPid: null,
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
return blocklets[0];
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3093
3136
|
/**
|
|
3094
3137
|
* 邀请成员到组织
|
|
3095
3138
|
* 1. 批量添加成员到组织 - 记录添加成功和添加失败的用户 DID
|
|
@@ -3124,13 +3167,26 @@ class TeamAPI extends EventEmitter {
|
|
|
3124
3167
|
// Step 1: 批量添加成员到组织 - 记录添加成功和添加失败的用户 DID
|
|
3125
3168
|
const successUserDids = [];
|
|
3126
3169
|
const failedUserDids = [];
|
|
3170
|
+
const skipInviteUserDids = [];
|
|
3127
3171
|
|
|
3128
3172
|
// 内部邀请
|
|
3129
3173
|
if (inviteType === 'internal') {
|
|
3130
3174
|
for (const userDid of userDids) {
|
|
3131
3175
|
try {
|
|
3132
3176
|
// eslint-disable-next-line no-await-in-loop
|
|
3133
|
-
await
|
|
3177
|
+
const currentUser = await this.getUser({
|
|
3178
|
+
teamDid,
|
|
3179
|
+
user: { did: userDid },
|
|
3180
|
+
});
|
|
3181
|
+
const walletDid = getWalletDid(currentUser);
|
|
3182
|
+
// 如果当前用户不是钱包用户,则跳过邀请 (参考颁发通行证逻辑)
|
|
3183
|
+
const skipInvite = walletDid !== userDid;
|
|
3184
|
+
if (skipInvite) {
|
|
3185
|
+
skipInviteUserDids.push(userDid);
|
|
3186
|
+
}
|
|
3187
|
+
const status = skipInvite ? 'active' : 'inviting';
|
|
3188
|
+
// eslint-disable-next-line no-await-in-loop
|
|
3189
|
+
await state.addOrgMember({ orgId, userDid, status }, context);
|
|
3134
3190
|
successUserDids.push(userDid);
|
|
3135
3191
|
} catch (addErr) {
|
|
3136
3192
|
failedUserDids.push(userDid);
|
|
@@ -3153,19 +3209,50 @@ class TeamAPI extends EventEmitter {
|
|
|
3153
3209
|
}
|
|
3154
3210
|
}
|
|
3155
3211
|
|
|
3212
|
+
// 要排除 OAuth 用户
|
|
3213
|
+
const inviteUserDids = successUserDids.filter((did) => !skipInviteUserDids.includes(did));
|
|
3214
|
+
|
|
3215
|
+
if (skipInviteUserDids.length > 0) {
|
|
3216
|
+
logger.info('OAuth users were successfully added to org', { teamDid, orgId, skipInviteUserDids });
|
|
3217
|
+
// 向 OAuth 用户颁发通行证
|
|
3218
|
+
for (const userDid of skipInviteUserDids) {
|
|
3219
|
+
// eslint-disable-next-line no-await-in-loop
|
|
3220
|
+
await this.issuePassportToUser({
|
|
3221
|
+
teamDid,
|
|
3222
|
+
userDid,
|
|
3223
|
+
role,
|
|
3224
|
+
notification: {},
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
|
|
3229
|
+
// 如果没有其他用户,那么直接返回即可
|
|
3230
|
+
if (inviteType === 'internal' && inviteUserDids.length === 0) {
|
|
3231
|
+
return {
|
|
3232
|
+
successDids: successUserDids,
|
|
3233
|
+
failedDids: failedUserDids,
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
// Previous Step 2: 要判断站点是否是站点群内,如果是站点群中,需要使用 master 的 appPid 作为 sourceAppPid 创建邀请链接
|
|
3238
|
+
|
|
3239
|
+
const blocklet = await getBlocklet({ did: teamDid, states: this.states, dataDirs: this.dataDirs });
|
|
3240
|
+
const masterBlockletInfo = this.getFederatedMasterBlockletInfo({ blocklet });
|
|
3241
|
+
|
|
3156
3242
|
// Step 2: 创建邀请链接,只创建添加成功的用户邀请链接
|
|
3243
|
+
|
|
3157
3244
|
const inviteInfo = await this.createMemberInvitation(
|
|
3158
3245
|
{
|
|
3159
3246
|
teamDid,
|
|
3160
3247
|
role,
|
|
3161
3248
|
expireTime: this.memberInvitationExpireTime,
|
|
3162
3249
|
orgId,
|
|
3163
|
-
inviteUserDids: inviteType === 'internal' ?
|
|
3250
|
+
inviteUserDids: inviteType === 'internal' ? inviteUserDids : [],
|
|
3251
|
+
sourceAppPid: masterBlockletInfo?.appPid,
|
|
3164
3252
|
},
|
|
3165
3253
|
context
|
|
3166
3254
|
);
|
|
3167
3255
|
|
|
3168
|
-
const blocklet = await getBlocklet({ did: teamDid, states: this.states, dataDirs: this.dataDirs });
|
|
3169
3256
|
const inviteLink = getOrgInviteLink(inviteInfo, blocklet);
|
|
3170
3257
|
|
|
3171
3258
|
logger.info('Invite link created for successful users', {
|
|
@@ -39024,7 +39024,7 @@ module.exports = require("zlib");
|
|
|
39024
39024
|
/***/ ((module) => {
|
|
39025
39025
|
|
|
39026
39026
|
"use strict";
|
|
39027
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@abtnode/core","publishConfig":{"access":"public"},"version":"1.
|
|
39027
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@abtnode/core","publishConfig":{"access":"public"},"version":"1.17.0","description":"","main":"lib/index.js","files":["lib"],"scripts":{"lint":"eslint tests lib --ignore-pattern \'tests/assets/*\'","lint:fix":"eslint --fix tests lib"},"keywords":[],"author":"wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)","license":"Apache-2.0","dependencies":{"@abtnode/analytics":"1.17.0","@abtnode/auth":"1.17.0","@abtnode/certificate-manager":"1.17.0","@abtnode/constant":"1.17.0","@abtnode/cron":"1.17.0","@abtnode/db-cache":"1.17.0","@abtnode/docker-utils":"1.17.0","@abtnode/logger":"1.17.0","@abtnode/models":"1.17.0","@abtnode/queue":"1.17.0","@abtnode/rbac":"1.17.0","@abtnode/router-provider":"1.17.0","@abtnode/static-server":"1.17.0","@abtnode/timemachine":"1.17.0","@abtnode/util":"1.17.0","@aigne/aigne-hub":"^0.10.4","@arcblock/did":"^1.27.3","@arcblock/did-connect-js":"^1.27.3","@arcblock/did-ext":"^1.27.3","@arcblock/did-motif":"^1.1.14","@arcblock/did-util":"^1.27.3","@arcblock/event-hub":"^1.27.3","@arcblock/jwt":"^1.27.3","@arcblock/pm2-events":"^0.0.5","@arcblock/validator":"^1.27.3","@arcblock/vc":"^1.27.3","@blocklet/constant":"1.17.0","@blocklet/did-space-js":"^1.2.1","@blocklet/env":"1.17.0","@blocklet/error":"^0.3.2","@blocklet/meta":"1.17.0","@blocklet/resolver":"1.17.0","@blocklet/sdk":"1.17.0","@blocklet/server-js":"1.17.0","@blocklet/store":"1.17.0","@blocklet/theme":"^3.2.0","@fidm/x509":"^1.2.1","@ocap/mcrypto":"^1.27.3","@ocap/util":"^1.27.3","@ocap/wallet":"^1.27.3","@slack/webhook":"^5.0.4","archiver":"^7.0.1","axios":"^1.7.9","axon":"^2.0.3","chalk":"^4.1.2","cross-spawn":"^7.0.3","dayjs":"^1.11.13","deep-diff":"^1.0.2","detect-port":"^1.5.1","envfile":"^7.1.0","escape-string-regexp":"^4.0.0","fast-glob":"^3.3.2","filesize":"^10.1.1","flat":"^5.0.2","fs-extra":"^11.2.0","get-port":"^5.1.1","hasha":"^5.2.2","is-base64":"^1.1.0","is-cidr":"4","is-ip":"3","is-url":"^1.2.4","joi":"17.12.2","joi-extension-semver":"^5.0.0","js-yaml":"^4.1.0","kill-port":"^2.0.1","lodash":"^4.17.21","node-stream-zip":"^1.15.0","p-all":"^3.0.0","p-limit":"^3.1.0","p-map":"^4.0.0","p-retry":"^4.6.2","p-wait-for":"^3.2.0","private-ip":"^2.3.4","rate-limiter-flexible":"^5.0.5","read-last-lines":"^1.8.0","semver":"^7.6.3","sequelize":"^6.35.0","shelljs":"^0.8.5","slugify":"^1.6.6","ssri":"^8.0.1","stream-throttle":"^0.1.3","stream-to-promise":"^3.0.0","systeminformation":"^5.23.3","tail":"^2.2.4","tar":"^6.1.11","transliteration":"^2.3.5","ua-parser-js":"^1.0.2","ufo":"^1.5.3","uuid":"^11.1.0","valid-url":"^1.0.9","which":"^2.0.2","xbytes":"^1.8.0"},"devDependencies":{"axios-mock-adapter":"^2.1.0","expand-tilde":"^2.0.2","express":"^4.18.2","unzipper":"^0.10.11"},"gitHead":"e5764f753181ed6a7c615cd4fc6682aacf0cb7cd"}');
|
|
39028
39028
|
|
|
39029
39029
|
/***/ }),
|
|
39030
39030
|
|
package/lib/states/README.md
CHANGED
|
@@ -28,7 +28,7 @@ All Blocklet Server states are managed by files in this folder.
|
|
|
28
28
|
- `mode` app mode
|
|
29
29
|
- `ports` runtime port resolved from meta
|
|
30
30
|
- `<ENV_NAME>`: `<port number>`
|
|
31
|
-
- `environments[]`: env variables generated by server, e.g. BLOCKLET_APP_SK,
|
|
31
|
+
- `environments[]`: env variables generated by server, e.g. BLOCKLET_APP_SK, BLOCKLET_APP_ID
|
|
32
32
|
- `<key>`: `<value>`
|
|
33
33
|
- `children`: component of app, same structure as parent, can be nested
|
|
34
34
|
- `mountPoint` mount path of web site. _component only_
|
package/lib/states/org.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { CustomError } = require('@blocklet/error');
|
|
2
2
|
const { SERVER_ROLES } = require('@abtnode/constant');
|
|
3
3
|
const { Sequelize, Op } = require('sequelize');
|
|
4
|
+
const pick = require('lodash/pick');
|
|
4
5
|
const logger = require('@abtnode/logger')('@abtnode/core:states:orgs');
|
|
5
6
|
const { PASSPORT_STATUS } = require('@abtnode/constant');
|
|
6
7
|
|
|
@@ -69,8 +70,9 @@ class OrgState extends BaseState {
|
|
|
69
70
|
/**
|
|
70
71
|
* 用户是否存在组织中
|
|
71
72
|
*/
|
|
72
|
-
canAccessOrg({ userDid, orgId }) {
|
|
73
|
-
|
|
73
|
+
async canAccessOrg({ userDid, orgId }) {
|
|
74
|
+
const result = await this.userOrgs.findOne({ where: { userDid, orgId } });
|
|
75
|
+
return result && result.status === ACTIVE_STATUS;
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
async get({ id }, context) {
|
|
@@ -448,7 +450,11 @@ class OrgState extends BaseState {
|
|
|
448
450
|
throw new CustomError(400, 'the length of search text should not more than 50');
|
|
449
451
|
} else {
|
|
450
452
|
const likeOp = this.model.sequelize.getDialect() === 'postgres' ? Op.iLike : Op.like;
|
|
451
|
-
where[Op.or] = [
|
|
453
|
+
where[Op.or] = [
|
|
454
|
+
{ did: { [likeOp]: `%${search}%` } },
|
|
455
|
+
{ fullName: { [likeOp]: `%${search}%` } },
|
|
456
|
+
{ email: { [likeOp]: `%${search}%` } },
|
|
457
|
+
];
|
|
452
458
|
}
|
|
453
459
|
}
|
|
454
460
|
|
|
@@ -464,14 +470,14 @@ class OrgState extends BaseState {
|
|
|
464
470
|
const result = await this.user.paginate(
|
|
465
471
|
{
|
|
466
472
|
where,
|
|
467
|
-
attributes: ['did', 'avatar', 'fullName'],
|
|
473
|
+
attributes: ['did', 'avatar', 'fullName', 'email'],
|
|
468
474
|
},
|
|
469
475
|
{ updatedAt: -1 },
|
|
470
476
|
newPaging
|
|
471
477
|
);
|
|
472
478
|
|
|
473
479
|
return {
|
|
474
|
-
users: result.list,
|
|
480
|
+
users: result.list.map((d) => pick(d, ['did', 'avatar', 'fullName'])),
|
|
475
481
|
paging: result.paging,
|
|
476
482
|
};
|
|
477
483
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.17.
|
|
6
|
+
"version": "1.17.1",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -17,46 +17,46 @@
|
|
|
17
17
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
18
18
|
"license": "Apache-2.0",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@abtnode/analytics": "1.17.
|
|
21
|
-
"@abtnode/auth": "1.17.
|
|
22
|
-
"@abtnode/certificate-manager": "1.17.
|
|
23
|
-
"@abtnode/constant": "1.17.
|
|
24
|
-
"@abtnode/cron": "1.17.
|
|
25
|
-
"@abtnode/db-cache": "1.17.
|
|
26
|
-
"@abtnode/docker-utils": "1.17.
|
|
27
|
-
"@abtnode/logger": "1.17.
|
|
28
|
-
"@abtnode/models": "1.17.
|
|
29
|
-
"@abtnode/queue": "1.17.
|
|
30
|
-
"@abtnode/rbac": "1.17.
|
|
31
|
-
"@abtnode/router-provider": "1.17.
|
|
32
|
-
"@abtnode/static-server": "1.17.
|
|
33
|
-
"@abtnode/timemachine": "1.17.
|
|
34
|
-
"@abtnode/util": "1.17.
|
|
20
|
+
"@abtnode/analytics": "1.17.1",
|
|
21
|
+
"@abtnode/auth": "1.17.1",
|
|
22
|
+
"@abtnode/certificate-manager": "1.17.1",
|
|
23
|
+
"@abtnode/constant": "1.17.1",
|
|
24
|
+
"@abtnode/cron": "1.17.1",
|
|
25
|
+
"@abtnode/db-cache": "1.17.1",
|
|
26
|
+
"@abtnode/docker-utils": "1.17.1",
|
|
27
|
+
"@abtnode/logger": "1.17.1",
|
|
28
|
+
"@abtnode/models": "1.17.1",
|
|
29
|
+
"@abtnode/queue": "1.17.1",
|
|
30
|
+
"@abtnode/rbac": "1.17.1",
|
|
31
|
+
"@abtnode/router-provider": "1.17.1",
|
|
32
|
+
"@abtnode/static-server": "1.17.1",
|
|
33
|
+
"@abtnode/timemachine": "1.17.1",
|
|
34
|
+
"@abtnode/util": "1.17.1",
|
|
35
35
|
"@aigne/aigne-hub": "^0.10.4",
|
|
36
|
-
"@arcblock/did": "^1.27.
|
|
37
|
-
"@arcblock/did-connect-js": "^1.27.
|
|
38
|
-
"@arcblock/did-ext": "^1.27.
|
|
36
|
+
"@arcblock/did": "^1.27.3",
|
|
37
|
+
"@arcblock/did-connect-js": "^1.27.3",
|
|
38
|
+
"@arcblock/did-ext": "^1.27.3",
|
|
39
39
|
"@arcblock/did-motif": "^1.1.14",
|
|
40
|
-
"@arcblock/did-util": "^1.27.
|
|
41
|
-
"@arcblock/event-hub": "^1.27.
|
|
42
|
-
"@arcblock/jwt": "^1.27.
|
|
40
|
+
"@arcblock/did-util": "^1.27.3",
|
|
41
|
+
"@arcblock/event-hub": "^1.27.3",
|
|
42
|
+
"@arcblock/jwt": "^1.27.3",
|
|
43
43
|
"@arcblock/pm2-events": "^0.0.5",
|
|
44
|
-
"@arcblock/validator": "^1.27.
|
|
45
|
-
"@arcblock/vc": "^1.27.
|
|
46
|
-
"@blocklet/constant": "1.17.
|
|
44
|
+
"@arcblock/validator": "^1.27.3",
|
|
45
|
+
"@arcblock/vc": "^1.27.3",
|
|
46
|
+
"@blocklet/constant": "1.17.1",
|
|
47
47
|
"@blocklet/did-space-js": "^1.2.1",
|
|
48
|
-
"@blocklet/env": "1.17.
|
|
49
|
-
"@blocklet/error": "^0.3.
|
|
50
|
-
"@blocklet/meta": "1.17.
|
|
51
|
-
"@blocklet/resolver": "1.17.
|
|
52
|
-
"@blocklet/sdk": "1.17.
|
|
53
|
-
"@blocklet/server-js": "1.17.
|
|
54
|
-
"@blocklet/store": "1.17.
|
|
55
|
-
"@blocklet/theme": "^3.
|
|
48
|
+
"@blocklet/env": "1.17.1",
|
|
49
|
+
"@blocklet/error": "^0.3.2",
|
|
50
|
+
"@blocklet/meta": "1.17.1",
|
|
51
|
+
"@blocklet/resolver": "1.17.1",
|
|
52
|
+
"@blocklet/sdk": "1.17.1",
|
|
53
|
+
"@blocklet/server-js": "1.17.1",
|
|
54
|
+
"@blocklet/store": "1.17.1",
|
|
55
|
+
"@blocklet/theme": "^3.2.0",
|
|
56
56
|
"@fidm/x509": "^1.2.1",
|
|
57
|
-
"@ocap/mcrypto": "^1.27.
|
|
58
|
-
"@ocap/util": "^1.27.
|
|
59
|
-
"@ocap/wallet": "^1.27.
|
|
57
|
+
"@ocap/mcrypto": "^1.27.3",
|
|
58
|
+
"@ocap/util": "^1.27.3",
|
|
59
|
+
"@ocap/wallet": "^1.27.3",
|
|
60
60
|
"@slack/webhook": "^5.0.4",
|
|
61
61
|
"archiver": "^7.0.1",
|
|
62
62
|
"axios": "^1.7.9",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"express": "^4.18.2",
|
|
117
117
|
"unzipper": "^0.10.11"
|
|
118
118
|
},
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "0d57fbc64a22fd09267166b26af46dd84e545287"
|
|
120
120
|
}
|