@blocklet/sdk 1.16.27-beta-d27e19fa → 1.16.27-beta-21d213c5

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.
@@ -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: (...args: any[]) => Promise<{
7
- name: string | undefined;
8
- description: string | undefined;
9
- link: string;
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
- updateSubEndpoint: true;
14
+ link: string;
15
+ updateSubEndpoint: boolean;
12
16
  subscriptionEndpoint: string;
13
- nodeDid: string | undefined;
17
+ nodeDid: string;
18
+ publisher: string;
14
19
  }>;
15
20
  delegator({ request }: {
16
21
  request: any;
@@ -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
- appInfo: async (...args) => {
61
- const info = await closure(options.appInfo)(...args);
59
+ async appInfo(...args) {
60
+ const mergeInfo = await closure(options.appInfo)(...args);
62
61
  const { request, baseUrl } = args[0];
63
- const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
64
- let agentDid;
65
- const sourceAppPid = (0, login_1.getSourceAppPid)(request);
66
- // federated 登录模式下,需要告知原有的 blocklet-did
67
- if (sourceAppPid) {
68
- // 对于 ux 来说, 要展示的始终是 pid,所以这个给 agentDid 的赋值也需要是 pid
69
- agentDid = process.env.BLOCKLET_APP_PID;
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
- name: process.env.BLOCKLET_APP_NAME,
73
- description: process.env.BLOCKLET_APP_DESCRIPTION,
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
- // FIXME: @zhanghan 这里是否要增加 memberAppInfo 信息
84
- // 这里用于非 blocklet-service 提供的 did-connect,因为其逻辑的处理是交由 blocklet-app 自己完成的,所以之前一直展示的都是当前应用的信息(member blocklet)
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,72 @@
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
+ return {
41
+ name: blocklet.meta.name,
42
+ description: blocklet.meta.description || `Connect to ${blocklet.meta.name}`,
43
+ icon: (0, ufo_1.joinURL)(baseUrl, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/blocklet/logo?v=${version}`),
44
+ link: (0, util_1.getConnectAppUrl)({ request, baseUrl }),
45
+ updateSubEndpoint: true,
46
+ subscriptionEndpoint: (0, ufo_1.joinURL)(groupPathPrefix, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, 'websocket'),
47
+ nodeDid: info.did,
48
+ // NOTE: publisher 是 WalletAuthenticator 中自动添加的
49
+ };
50
+ }
51
+ exports.getAppInfo = getAppInfo;
52
+ async function getMemberAppInfo({ request, baseUrl, getBlocklet, getNodeInfo, }) {
53
+ const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
54
+ const [blocklet, info] = await Promise.all([getBlocklet(), getNodeInfo()]);
55
+ const sourceAppPid = (0, login_1.getSourceAppPid)(request);
56
+ const version = (0, get_1.default)(blocklet, 'meta.version', '');
57
+ if (sourceAppPid) {
58
+ return {
59
+ name: blocklet.meta.name,
60
+ description: blocklet.meta.description || `Connect to ${blocklet.meta.name}`,
61
+ icon: (0, ufo_1.joinURL)(baseUrl, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/blocklet/logo?v=${version}`),
62
+ link: (0, util_1.getConnectAppUrl)({ request, baseUrl }),
63
+ updateSubEndpoint: true,
64
+ subscriptionEndpoint: (0, ufo_1.joinURL)(groupPathPrefix, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, 'websocket'),
65
+ nodeDid: info.did,
66
+ // NOTICE: member appInfo 的 publisher 不是 delegator,所以需要手动指定
67
+ publisher: `did:abt:${blocklet.appPid}`,
68
+ };
69
+ }
70
+ return null;
71
+ }
72
+ 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-d27e19fa",
6
+ "version": "1.16.27-beta-21d213c5",
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-d27e19fa",
31
- "@abtnode/constant": "1.16.27-beta-d27e19fa",
30
+ "@abtnode/client": "1.16.27-beta-21d213c5",
31
+ "@abtnode/constant": "1.16.27-beta-21d213c5",
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-d27e19fa",
37
- "@blocklet/env": "1.16.27-beta-d27e19fa",
38
- "@blocklet/meta": "1.16.27-beta-d27e19fa",
36
+ "@blocklet/constant": "1.16.27-beta-21d213c5",
37
+ "@blocklet/env": "1.16.27-beta-21d213c5",
38
+ "@blocklet/meta": "1.16.27-beta-21d213c5",
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": "7a83c248c1e5738e6d95e54fc26699f865479dab"
79
+ "gitHead": "1beb3311565336a17ee1b049379a8c864f494242"
80
80
  }