@blocklet/sdk 1.16.27-beta-d27e19fa → 1.16.27-beta-8f022f16
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/connect/shared.d.ts +11 -6
- package/lib/connect/shared.js +46 -23
- package/lib/util/app-info.d.ts +48 -0
- package/lib/util/app-info.js +76 -0
- package/package.json +7 -7
package/lib/connect/shared.d.ts
CHANGED
|
@@ -3,14 +3,19 @@ declare const getDelegator: () => WalletObject<string>;
|
|
|
3
3
|
declare const getDelegatee: () => WalletObject<string>;
|
|
4
4
|
declare const getDelegation: (delegator: WalletObject, delegatee: WalletObject) => string;
|
|
5
5
|
declare const getAuthenticatorProps: (options?: {}) => {
|
|
6
|
-
appInfo
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
appInfo(...args: any[]): Promise<any>;
|
|
7
|
+
memberAppInfo({ request, baseUrl }: {
|
|
8
|
+
request: any;
|
|
9
|
+
baseUrl: any;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
name: any;
|
|
12
|
+
description: any;
|
|
10
13
|
icon: string;
|
|
11
|
-
|
|
14
|
+
link: string;
|
|
15
|
+
updateSubEndpoint: boolean;
|
|
12
16
|
subscriptionEndpoint: string;
|
|
13
|
-
nodeDid: string
|
|
17
|
+
nodeDid: string;
|
|
18
|
+
publisher: string;
|
|
14
19
|
}>;
|
|
15
20
|
delegator({ request }: {
|
|
16
21
|
request: any;
|
package/lib/connect/shared.js
CHANGED
|
@@ -4,15 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getAuthenticatorProps = exports.getDelegatee = exports.getDelegator = exports.getDelegation = void 0;
|
|
7
|
-
const url_join_1 = __importDefault(require("url-join"));
|
|
8
7
|
const jwt_1 = require("@arcblock/jwt");
|
|
9
8
|
const util_1 = require("@blocklet/meta/lib/util");
|
|
10
9
|
const wallet_1 = require("@ocap/wallet");
|
|
11
10
|
const mcrypto_1 = require("@ocap/mcrypto");
|
|
12
11
|
const get_1 = __importDefault(require("lodash/get"));
|
|
13
|
-
const constants_1 = require("../util/constants");
|
|
14
12
|
const wallet_2 = __importDefault(require("../wallet"));
|
|
15
13
|
const login_1 = require("../util/login");
|
|
14
|
+
const app_info_1 = require("../util/app-info");
|
|
16
15
|
// wraps value in closure or returns closure
|
|
17
16
|
const closure = (value) => (typeof value === 'function' ? value : () => value);
|
|
18
17
|
const getDelegator = () => {
|
|
@@ -57,31 +56,55 @@ exports.getDelegation = getDelegation;
|
|
|
57
56
|
const getAuthenticatorProps = (options = {}) => ({
|
|
58
57
|
chainInfo: () => (0, util_1.getChainInfo)(process.env),
|
|
59
58
|
...options,
|
|
60
|
-
|
|
61
|
-
const
|
|
59
|
+
async appInfo(...args) {
|
|
60
|
+
const mergeInfo = await closure(options.appInfo)(...args);
|
|
62
61
|
const { request, baseUrl } = args[0];
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
const appInfo = await (0, app_info_1.getAppInfo)({
|
|
63
|
+
request,
|
|
64
|
+
baseUrl,
|
|
65
|
+
getBlocklet: async () => {
|
|
66
|
+
let blocklet;
|
|
67
|
+
try {
|
|
68
|
+
({ blocklet } = await this.authClient.getBlocklet());
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
throw new Error('failed to get blocklet');
|
|
72
|
+
}
|
|
73
|
+
return blocklet;
|
|
74
|
+
},
|
|
75
|
+
getNodeInfo() {
|
|
76
|
+
return Promise.resolve({
|
|
77
|
+
did: process.env.ABT_NODE_DID,
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
});
|
|
71
81
|
return {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
...(info || {}),
|
|
75
|
-
link: (0, util_1.getConnectAppUrl)(args[0]),
|
|
76
|
-
icon: (0, url_join_1.default)(baseUrl, constants_1.SERVICE_PREFIX, `/blocklet/logo?v=${process.env.BLOCKLET_APP_VERSION || ''}`),
|
|
77
|
-
updateSubEndpoint: true,
|
|
78
|
-
subscriptionEndpoint: (0, url_join_1.default)(groupPathPrefix, constants_1.SERVICE_PREFIX, 'websocket'),
|
|
79
|
-
nodeDid: process.env.ABT_NODE_DID,
|
|
80
|
-
agentDid,
|
|
82
|
+
...(mergeInfo || {}),
|
|
83
|
+
...appInfo,
|
|
81
84
|
};
|
|
82
85
|
},
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
async memberAppInfo({ request, baseUrl }) {
|
|
87
|
+
const memberAppInfo = await (0, app_info_1.getMemberAppInfo)({
|
|
88
|
+
request,
|
|
89
|
+
baseUrl,
|
|
90
|
+
getBlocklet: async () => {
|
|
91
|
+
let blocklet;
|
|
92
|
+
try {
|
|
93
|
+
({ blocklet } = await this.authClient.getBlocklet());
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new Error('failed to get blocklet');
|
|
97
|
+
}
|
|
98
|
+
return blocklet;
|
|
99
|
+
},
|
|
100
|
+
getNodeInfo() {
|
|
101
|
+
return Promise.resolve({
|
|
102
|
+
did: process.env.ABT_NODE_DID,
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
return memberAppInfo;
|
|
107
|
+
},
|
|
85
108
|
async delegator({ request }) {
|
|
86
109
|
const sourceAppPid = (0, login_1.getSourceAppPid)(request);
|
|
87
110
|
if (sourceAppPid) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare function getFederatedMasterAppInfo({ blocklet, sourceAppPid, version, groupPathPrefix, nodeInfo, }: {
|
|
2
|
+
blocklet: any;
|
|
3
|
+
sourceAppPid: string;
|
|
4
|
+
version: string;
|
|
5
|
+
groupPathPrefix: string;
|
|
6
|
+
nodeInfo: any;
|
|
7
|
+
}): {
|
|
8
|
+
name: any;
|
|
9
|
+
description: any;
|
|
10
|
+
icon: string;
|
|
11
|
+
link: any;
|
|
12
|
+
updateSubEndpoint: boolean;
|
|
13
|
+
subscriptionEndpoint: string;
|
|
14
|
+
nodeDid: any;
|
|
15
|
+
};
|
|
16
|
+
export declare function getAppInfo({ request, baseUrl, getBlocklet, getNodeInfo, }: {
|
|
17
|
+
request: $TSFixMe;
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
getBlocklet: () => Promise<$TSFixMe>;
|
|
20
|
+
getNodeInfo: () => Promise<{
|
|
21
|
+
did: string;
|
|
22
|
+
}>;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
name: any;
|
|
25
|
+
description: any;
|
|
26
|
+
icon: string;
|
|
27
|
+
link: any;
|
|
28
|
+
updateSubEndpoint: boolean;
|
|
29
|
+
subscriptionEndpoint: string;
|
|
30
|
+
nodeDid: any;
|
|
31
|
+
}>;
|
|
32
|
+
export declare function getMemberAppInfo({ request, baseUrl, getBlocklet, getNodeInfo, }: {
|
|
33
|
+
request: any;
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
getBlocklet: () => Promise<$TSFixMe>;
|
|
36
|
+
getNodeInfo: () => Promise<{
|
|
37
|
+
did: string;
|
|
38
|
+
}>;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
name: any;
|
|
41
|
+
description: any;
|
|
42
|
+
icon: string;
|
|
43
|
+
link: string;
|
|
44
|
+
updateSubEndpoint: boolean;
|
|
45
|
+
subscriptionEndpoint: string;
|
|
46
|
+
nodeDid: string;
|
|
47
|
+
publisher: string;
|
|
48
|
+
}>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getMemberAppInfo = exports.getAppInfo = exports.getFederatedMasterAppInfo = void 0;
|
|
7
|
+
const ufo_1 = require("ufo");
|
|
8
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
9
|
+
const util_1 = require("@blocklet/meta/lib/util");
|
|
10
|
+
const constant_1 = require("@abtnode/constant");
|
|
11
|
+
const login_1 = require("./login");
|
|
12
|
+
function getFederatedMasterAppInfo({ blocklet, sourceAppPid, version, groupPathPrefix, nodeInfo, }) {
|
|
13
|
+
const { federated } = blocklet.settings;
|
|
14
|
+
const master = federated.sites.find((x) => x.appPid === sourceAppPid);
|
|
15
|
+
return {
|
|
16
|
+
name: master.appName,
|
|
17
|
+
description: master.appescription || `Connect to ${master.appName}`,
|
|
18
|
+
icon: (0, ufo_1.joinURL)(master.appUrl, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/blocklet/logo?v=${version}`),
|
|
19
|
+
link: master.appUrl,
|
|
20
|
+
updateSubEndpoint: true,
|
|
21
|
+
subscriptionEndpoint: (0, ufo_1.joinURL)(groupPathPrefix, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, 'websocket'),
|
|
22
|
+
nodeDid: nodeInfo.did,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.getFederatedMasterAppInfo = getFederatedMasterAppInfo;
|
|
26
|
+
async function getAppInfo({ request, baseUrl, getBlocklet, getNodeInfo, }) {
|
|
27
|
+
const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
|
|
28
|
+
const [blocklet, info] = await Promise.all([getBlocklet(), getNodeInfo()]);
|
|
29
|
+
const sourceAppPid = (0, login_1.getSourceAppPid)(request);
|
|
30
|
+
const version = (0, get_1.default)(blocklet, 'meta.version', '');
|
|
31
|
+
if (sourceAppPid) {
|
|
32
|
+
return getFederatedMasterAppInfo({
|
|
33
|
+
blocklet,
|
|
34
|
+
sourceAppPid,
|
|
35
|
+
version,
|
|
36
|
+
groupPathPrefix,
|
|
37
|
+
nodeInfo: info,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const blockletName = blocklet.environmentObj?.BLOCKLET_APP_NAME || blocklet.meta?.name;
|
|
41
|
+
const blockletDescription = blocklet.environmentObj?.BLOCKLET_APP_DESCRIPTION || blocklet.meta?.description;
|
|
42
|
+
return {
|
|
43
|
+
name: blockletName,
|
|
44
|
+
description: blockletDescription || `Connect to ${blockletName}`,
|
|
45
|
+
icon: (0, ufo_1.joinURL)(baseUrl, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/blocklet/logo?v=${version}`),
|
|
46
|
+
link: (0, util_1.getConnectAppUrl)({ request, baseUrl }),
|
|
47
|
+
updateSubEndpoint: true,
|
|
48
|
+
subscriptionEndpoint: (0, ufo_1.joinURL)(groupPathPrefix, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, 'websocket'),
|
|
49
|
+
nodeDid: info.did,
|
|
50
|
+
// NOTE: publisher 是 WalletAuthenticator 中自动添加的
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.getAppInfo = getAppInfo;
|
|
54
|
+
async function getMemberAppInfo({ request, baseUrl, getBlocklet, getNodeInfo, }) {
|
|
55
|
+
const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
|
|
56
|
+
const [blocklet, info] = await Promise.all([getBlocklet(), getNodeInfo()]);
|
|
57
|
+
const sourceAppPid = (0, login_1.getSourceAppPid)(request);
|
|
58
|
+
const version = (0, get_1.default)(blocklet, 'meta.version', '');
|
|
59
|
+
if (sourceAppPid && blocklet) {
|
|
60
|
+
const blockletName = blocklet.environmentObj?.BLOCKLET_APP_NAME || blocklet.meta?.name;
|
|
61
|
+
const blockletDescription = blocklet.environmentObj?.BLOCKLET_APP_DESCRIPTION || blocklet.meta?.description;
|
|
62
|
+
return {
|
|
63
|
+
name: blockletName,
|
|
64
|
+
description: blockletDescription || `Connect to ${blockletName}`,
|
|
65
|
+
icon: (0, ufo_1.joinURL)(baseUrl, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/blocklet/logo?v=${version}`),
|
|
66
|
+
link: (0, util_1.getConnectAppUrl)({ request, baseUrl }),
|
|
67
|
+
updateSubEndpoint: true,
|
|
68
|
+
subscriptionEndpoint: (0, ufo_1.joinURL)(groupPathPrefix, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, 'websocket'),
|
|
69
|
+
nodeDid: info.did,
|
|
70
|
+
// NOTICE: member appInfo 的 publisher 不是 delegator,所以需要手动指定
|
|
71
|
+
publisher: `did:abt:${blocklet.appPid}`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
exports.getMemberAppInfo = getMemberAppInfo;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.27-beta-
|
|
6
|
+
"version": "1.16.27-beta-8f022f16",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@abtnode/client": "1.16.27-beta-
|
|
31
|
-
"@abtnode/constant": "1.16.27-beta-
|
|
30
|
+
"@abtnode/client": "1.16.27-beta-8f022f16",
|
|
31
|
+
"@abtnode/constant": "1.16.27-beta-8f022f16",
|
|
32
32
|
"@arcblock/did": "1.18.123",
|
|
33
33
|
"@arcblock/did-auth": "1.18.123",
|
|
34
34
|
"@arcblock/jwt": "1.18.123",
|
|
35
35
|
"@arcblock/ws": "1.18.123",
|
|
36
|
-
"@blocklet/constant": "1.16.27-beta-
|
|
37
|
-
"@blocklet/env": "1.16.27-beta-
|
|
38
|
-
"@blocklet/meta": "1.16.27-beta-
|
|
36
|
+
"@blocklet/constant": "1.16.27-beta-8f022f16",
|
|
37
|
+
"@blocklet/env": "1.16.27-beta-8f022f16",
|
|
38
|
+
"@blocklet/meta": "1.16.27-beta-8f022f16",
|
|
39
39
|
"@did-connect/authenticator": "^2.2.4",
|
|
40
40
|
"@did-connect/handler": "^2.2.4",
|
|
41
41
|
"@nedb/core": "^2.1.5",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"ts-node": "^10.9.1",
|
|
77
77
|
"typescript": "^5.0.4"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "8889fa58ff4cc85b60cd999126341a4a8d0ae9d4"
|
|
80
80
|
}
|