@blocklet/sdk 1.16.14-beta-963cb583 → 1.16.14-beta-a2de000a
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.js +4 -6
- package/lib/util/login.d.ts +1 -0
- package/lib/util/login.js +20 -0
- package/package.json +7 -7
package/lib/connect/shared.js
CHANGED
|
@@ -13,6 +13,7 @@ const mcrypto_1 = require("@ocap/mcrypto");
|
|
|
13
13
|
const get_1 = __importDefault(require("lodash/get"));
|
|
14
14
|
const constants_1 = require("../util/constants");
|
|
15
15
|
const wallet_2 = __importDefault(require("../wallet"));
|
|
16
|
+
const login_1 = require("../util/login");
|
|
16
17
|
// wraps value in closure or returns closure
|
|
17
18
|
const closure = (value) => (typeof value === 'function' ? value : () => value);
|
|
18
19
|
const getDelegator = () => {
|
|
@@ -53,9 +54,6 @@ const getDelegation = (delegator, delegatee) => {
|
|
|
53
54
|
});
|
|
54
55
|
};
|
|
55
56
|
exports.getDelegation = getDelegation;
|
|
56
|
-
function getProvider(request) {
|
|
57
|
-
return request.headers['x-user-provider'] || constant_1.LOGIN_PROVIDER.WALLET;
|
|
58
|
-
}
|
|
59
57
|
const getAuthenticatorProps = (options = {}) => ({
|
|
60
58
|
chainInfo: () => (0, util_1.getChainInfo)(process.env),
|
|
61
59
|
...options,
|
|
@@ -64,7 +62,7 @@ const getAuthenticatorProps = (options = {}) => ({
|
|
|
64
62
|
const { request, baseUrl } = args[0];
|
|
65
63
|
const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
|
|
66
64
|
let agentDid;
|
|
67
|
-
const provider =
|
|
65
|
+
const provider = (0, login_1.getLoginProvider)(request);
|
|
68
66
|
// federated 登录模式下,需要告知原有的 blocklet-did
|
|
69
67
|
if (provider === constant_1.LOGIN_PROVIDER.FEDERATED) {
|
|
70
68
|
// 对于 ux 来说, 要展示的始终是 pid,所以这个给 agentDid 的赋值也需要是 pid
|
|
@@ -83,7 +81,7 @@ const getAuthenticatorProps = (options = {}) => ({
|
|
|
83
81
|
};
|
|
84
82
|
},
|
|
85
83
|
async delegator({ request }) {
|
|
86
|
-
const provider =
|
|
84
|
+
const provider = (0, login_1.getLoginProvider)(request);
|
|
87
85
|
if (provider === constant_1.LOGIN_PROVIDER.FEDERATED) {
|
|
88
86
|
let blocklet;
|
|
89
87
|
try {
|
|
@@ -110,7 +108,7 @@ const getAuthenticatorProps = (options = {}) => ({
|
|
|
110
108
|
return delegator;
|
|
111
109
|
},
|
|
112
110
|
async delegation({ request }) {
|
|
113
|
-
const provider =
|
|
111
|
+
const provider = (0, login_1.getLoginProvider)(request);
|
|
114
112
|
if (provider === constant_1.LOGIN_PROVIDER.FEDERATED) {
|
|
115
113
|
let blocklet;
|
|
116
114
|
try {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getLoginProvider(request: any): any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLoginProvider = void 0;
|
|
4
|
+
/* eslint-disable import/prefer-default-export */
|
|
5
|
+
const constant_1 = require("@blocklet/constant");
|
|
6
|
+
function getLoginProvider(request) {
|
|
7
|
+
let provider;
|
|
8
|
+
// 1. 优先读取当前登录用户的 provider
|
|
9
|
+
({ provider } = request.user || {});
|
|
10
|
+
if (!provider) {
|
|
11
|
+
// 2. 读取在 headers 中指定的 provider
|
|
12
|
+
provider = request.headers['x-user-provider'];
|
|
13
|
+
}
|
|
14
|
+
if (!provider) {
|
|
15
|
+
// 3. 读取在 extraParams 中指定的 provider
|
|
16
|
+
({ provider } = request?.context?.store?.extraParams || {});
|
|
17
|
+
}
|
|
18
|
+
return provider || constant_1.LOGIN_PROVIDER.WALLET;
|
|
19
|
+
}
|
|
20
|
+
exports.getLoginProvider = getLoginProvider;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.14-beta-
|
|
6
|
+
"version": "1.16.14-beta-a2de000a",
|
|
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",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@abtnode/client": "1.16.14-beta-
|
|
30
|
-
"@abtnode/constant": "1.16.14-beta-
|
|
29
|
+
"@abtnode/client": "1.16.14-beta-a2de000a",
|
|
30
|
+
"@abtnode/constant": "1.16.14-beta-a2de000a",
|
|
31
31
|
"@arcblock/did": "1.18.89",
|
|
32
32
|
"@arcblock/did-auth": "1.18.89",
|
|
33
33
|
"@arcblock/jwt": "1.18.89",
|
|
34
34
|
"@arcblock/ws": "1.18.89",
|
|
35
|
-
"@blocklet/constant": "1.16.14-beta-
|
|
36
|
-
"@blocklet/env": "1.16.14-beta-
|
|
37
|
-
"@blocklet/meta": "1.16.14-beta-
|
|
35
|
+
"@blocklet/constant": "1.16.14-beta-a2de000a",
|
|
36
|
+
"@blocklet/env": "1.16.14-beta-a2de000a",
|
|
37
|
+
"@blocklet/meta": "1.16.14-beta-a2de000a",
|
|
38
38
|
"@did-connect/authenticator": "^2.2.0",
|
|
39
39
|
"@did-connect/handler": "^2.2.0",
|
|
40
40
|
"@nedb/core": "^2.1.5",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"ts-node": "^10.9.1",
|
|
74
74
|
"typescript": "^5.0.4"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "ed1336f2b7d3e6a4d5eeafd3816e6573c53ad543"
|
|
77
77
|
}
|