@blocklet/sdk 1.16.32-beta-4d47ae7f → 1.16.32-beta-17be26d7
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/component/index.d.ts +3 -0
- package/lib/component/index.js +8 -1
- package/lib/middlewares/auth.d.ts +2 -1
- package/lib/middlewares/auth.js +12 -1
- package/lib/middlewares/index.d.ts +4 -1
- package/lib/middlewares/user.d.ts +2 -0
- package/lib/middlewares/user.js +2 -0
- package/lib/service/auth.js +1 -3
- package/lib/util/login.d.ts +5 -0
- package/lib/util/login.js +19 -0
- package/package.json +7 -7
package/lib/component/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ type CallComponent = {
|
|
|
21
21
|
declare const call: CallComponent;
|
|
22
22
|
declare const getComponentMountPoint: (keyword: string) => string;
|
|
23
23
|
declare const getUrl: (...parts: string[]) => string;
|
|
24
|
+
declare const getRelativeUrl: (...parts: string[]) => string;
|
|
24
25
|
declare const getResourceExportDir: ({ projectId, releaseId }?: {
|
|
25
26
|
projectId: string;
|
|
26
27
|
releaseId?: string;
|
|
@@ -47,6 +48,7 @@ declare const getPackResources: ({ types, }?: {
|
|
|
47
48
|
declare const waitForComponentRunning: (name: string, timeout?: number, interval?: number) => Promise<boolean>;
|
|
48
49
|
export { call };
|
|
49
50
|
export { getUrl };
|
|
51
|
+
export { getRelativeUrl };
|
|
50
52
|
export { getComponentMountPoint };
|
|
51
53
|
export { getComponentWebEndpoint };
|
|
52
54
|
export { waitForComponentRunning };
|
|
@@ -57,6 +59,7 @@ export { getPackResources };
|
|
|
57
59
|
declare const _default: {
|
|
58
60
|
call: CallComponent;
|
|
59
61
|
getUrl: (...parts: string[]) => string;
|
|
62
|
+
getRelativeUrl: (...parts: string[]) => string;
|
|
60
63
|
getComponentMountPoint: (keyword: string) => string;
|
|
61
64
|
getComponentWebEndpoint: (keyword: string) => string;
|
|
62
65
|
waitForComponentRunning: (name: string, timeout?: number, interval?: number) => Promise<boolean>;
|
package/lib/component/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getPackResources = exports.getResources = exports.getReleaseExportDir = exports.getResourceExportDir = exports.waitForComponentRunning = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getUrl = exports.call = void 0;
|
|
29
|
+
exports.getPackResources = exports.getResources = exports.getReleaseExportDir = exports.getResourceExportDir = exports.waitForComponentRunning = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getRelativeUrl = exports.getUrl = exports.call = void 0;
|
|
30
30
|
const path_1 = require("path");
|
|
31
31
|
const axios_1 = __importDefault(require("axios"));
|
|
32
32
|
const get_1 = __importDefault(require("lodash/get"));
|
|
@@ -106,6 +106,12 @@ const getUrl = (...parts) => {
|
|
|
106
106
|
return (0, ufo_1.joinURL)(BLOCKLET_APP_URL, mountPoint === '/' ? '' : mountPoint, ...parts);
|
|
107
107
|
};
|
|
108
108
|
exports.getUrl = getUrl;
|
|
109
|
+
const getRelativeUrl = (...parts) => {
|
|
110
|
+
const { BLOCKLET_COMPONENT_DID } = process.env;
|
|
111
|
+
const mountPoint = getComponentMountPoint(BLOCKLET_COMPONENT_DID);
|
|
112
|
+
return (0, ufo_1.joinURL)(mountPoint === '/' ? '' : mountPoint, ...parts);
|
|
113
|
+
};
|
|
114
|
+
exports.getRelativeUrl = getRelativeUrl;
|
|
109
115
|
const getResourceExportDir = ({ projectId, releaseId } = { projectId: '' }) => {
|
|
110
116
|
if (!projectId) {
|
|
111
117
|
throw new Error('projectId is required');
|
|
@@ -161,6 +167,7 @@ exports.waitForComponentRunning = waitForComponentRunning;
|
|
|
161
167
|
exports.default = {
|
|
162
168
|
call,
|
|
163
169
|
getUrl,
|
|
170
|
+
getRelativeUrl,
|
|
164
171
|
getComponentMountPoint,
|
|
165
172
|
getComponentWebEndpoint,
|
|
166
173
|
waitForComponentRunning,
|
|
@@ -2,7 +2,8 @@ import { NextFunction, Request, Response } from 'express';
|
|
|
2
2
|
type MiddlewareParams = {
|
|
3
3
|
roles?: string[];
|
|
4
4
|
permissions?: string[];
|
|
5
|
+
kyc?: string[];
|
|
5
6
|
getClient?: Function;
|
|
6
7
|
};
|
|
7
|
-
declare const AuthMiddleware: ({ roles, permissions, getClient }?: MiddlewareParams) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
8
|
+
declare const AuthMiddleware: ({ roles, permissions, kyc, getClient }?: MiddlewareParams) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
8
9
|
export = AuthMiddleware;
|
package/lib/middlewares/auth.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
const lru_cache_1 = __importDefault(require("lru-cache"));
|
|
6
6
|
const auth_1 = __importDefault(require("../service/auth"));
|
|
7
|
+
const login_1 = require("../util/login");
|
|
7
8
|
const cache = new lru_cache_1.default({ max: 10, maxAge: 60 * 1000 });
|
|
8
9
|
const clients = {};
|
|
9
10
|
const getServiceClient = () => {
|
|
@@ -25,13 +26,16 @@ const getPermissionsByRole = async (getClient, role) => {
|
|
|
25
26
|
cache.set(role, res);
|
|
26
27
|
return res;
|
|
27
28
|
};
|
|
28
|
-
const AuthMiddleware = ({ roles, permissions, getClient = getServiceClient } = {}) => {
|
|
29
|
+
const AuthMiddleware = ({ roles, permissions, kyc, getClient = getServiceClient } = {}) => {
|
|
29
30
|
if (roles && !Array.isArray(roles)) {
|
|
30
31
|
throw new Error('roles must be array');
|
|
31
32
|
}
|
|
32
33
|
if (permissions && !Array.isArray(permissions)) {
|
|
33
34
|
throw new Error('permissions must be array');
|
|
34
35
|
}
|
|
36
|
+
if (kyc && !Array.isArray(kyc)) {
|
|
37
|
+
throw new Error('kyc must be array');
|
|
38
|
+
}
|
|
35
39
|
return async (req, res, next) => {
|
|
36
40
|
if (!req.headers['x-user-did']) {
|
|
37
41
|
res.status(401).json({ code: 'forbidden', error: 'not authorized' });
|
|
@@ -48,6 +52,13 @@ const AuthMiddleware = ({ roles, permissions, getClient = getServiceClient } = {
|
|
|
48
52
|
return;
|
|
49
53
|
}
|
|
50
54
|
}
|
|
55
|
+
if (kyc) {
|
|
56
|
+
const kycStatus = (0, login_1.decodeKycStatus)(Number(req.headers['x-user-kyc']) || 0);
|
|
57
|
+
if (kyc.some((x) => !kycStatus[`${x}Verified`])) {
|
|
58
|
+
res.status(403).json({ code: 'forbidden', error: 'kyc required' });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
51
62
|
next();
|
|
52
63
|
};
|
|
53
64
|
};
|
|
@@ -16,11 +16,14 @@ declare const _default: {
|
|
|
16
16
|
provider: string;
|
|
17
17
|
fullName: string;
|
|
18
18
|
walletOS: string;
|
|
19
|
+
emailVerified: boolean;
|
|
20
|
+
phoneVerified: boolean;
|
|
19
21
|
};
|
|
20
22
|
}, res: import("express").Response, next: import("express").NextFunction) => void;
|
|
21
|
-
auth: ({ roles, permissions, getClient }?: {
|
|
23
|
+
auth: ({ roles, permissions, kyc, getClient }?: {
|
|
22
24
|
roles?: string[];
|
|
23
25
|
permissions?: string[];
|
|
26
|
+
kyc?: string[];
|
|
24
27
|
getClient?: Function;
|
|
25
28
|
}) => (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction) => Promise<void>;
|
|
26
29
|
component: {
|
package/lib/middlewares/user.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const login_1 = require("../util/login");
|
|
2
3
|
const userMiddleware = () => (req, res, next) => {
|
|
3
4
|
if (req.headers['x-user-did']) {
|
|
4
5
|
req.user = {
|
|
@@ -7,6 +8,7 @@ const userMiddleware = () => (req, res, next) => {
|
|
|
7
8
|
provider: req.headers['x-user-provider'],
|
|
8
9
|
fullName: decodeURIComponent(req.headers['x-user-fullname']),
|
|
9
10
|
walletOS: req.headers['x-user-wallet-os'],
|
|
11
|
+
...(0, login_1.decodeKycStatus)(Number(req.headers['x-user-kyc']) || 0),
|
|
10
12
|
};
|
|
11
13
|
}
|
|
12
14
|
next();
|
package/lib/service/auth.js
CHANGED
|
@@ -19,7 +19,7 @@ const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env
|
|
|
19
19
|
const version_1 = require("../version");
|
|
20
20
|
const wallet_2 = __importDefault(require("../wallet"));
|
|
21
21
|
const service_api_1 = __importDefault(require("../util/service-api"));
|
|
22
|
-
const {
|
|
22
|
+
const { WELLKNOWN_SERVICE_PATH_PREFIX, USER_AVATAR_URL_PREFIX, USER_AVATAR_PATH_PREFIX } = constant_1.default;
|
|
23
23
|
const VERSION = version_1.version; // version of notification sdk
|
|
24
24
|
const isNotNullOrUndefined = (x) => ![null, undefined].includes(x);
|
|
25
25
|
// BLOCKLET_WALLET_TYPE is for backward compatibility
|
|
@@ -52,8 +52,6 @@ class AuthClient extends client_1.default {
|
|
|
52
52
|
const headers = super._getAuthHeaders();
|
|
53
53
|
// BLOCKLET_DID is always same as BLOCKLET_APP_PID in structV2 application
|
|
54
54
|
headers['x-access-blocklet'] = process.env.BLOCKLET_DID;
|
|
55
|
-
// x-access-service is not used since 1.8.35
|
|
56
|
-
headers['x-access-service'] = NODE_SERVICES.AUTH_SERVICE;
|
|
57
55
|
return headers;
|
|
58
56
|
}
|
|
59
57
|
}
|
package/lib/util/login.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare function getLoginProvider(request: any): any;
|
|
2
2
|
export declare function getSourceAppPid(request: any): any;
|
|
3
|
+
export declare const encodeKycStatus: (emailVerified: boolean, phoneVerified: boolean) => number;
|
|
4
|
+
export declare const decodeKycStatus: (status: number) => {
|
|
5
|
+
emailVerified: boolean;
|
|
6
|
+
phoneVerified: boolean;
|
|
7
|
+
};
|
package/lib/util/login.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeKycStatus = exports.encodeKycStatus = void 0;
|
|
3
4
|
exports.getLoginProvider = getLoginProvider;
|
|
4
5
|
exports.getSourceAppPid = getSourceAppPid;
|
|
5
6
|
/* eslint-disable import/prefer-default-export */
|
|
@@ -12,3 +13,21 @@ function getSourceAppPid(request) {
|
|
|
12
13
|
const extraParams = request?.context?.store?.extraParams || request.query || {};
|
|
13
14
|
return extraParams?.sourceAppPid || null;
|
|
14
15
|
}
|
|
16
|
+
const encodeKycStatus = (emailVerified, phoneVerified) => {
|
|
17
|
+
const emailVerifiedBit = emailVerified ? 1 : 0;
|
|
18
|
+
const phoneVerifiedBit = phoneVerified ? 1 : 0;
|
|
19
|
+
// eslint-disable-next-line no-bitwise
|
|
20
|
+
return emailVerifiedBit | (phoneVerifiedBit << 1);
|
|
21
|
+
};
|
|
22
|
+
exports.encodeKycStatus = encodeKycStatus;
|
|
23
|
+
const decodeKycStatus = (status) => {
|
|
24
|
+
// eslint-disable-next-line no-bitwise
|
|
25
|
+
const emailVerifiedBit = status & 1;
|
|
26
|
+
// eslint-disable-next-line no-bitwise
|
|
27
|
+
const phoneVerifiedBit = (status >> 1) & 1;
|
|
28
|
+
return {
|
|
29
|
+
emailVerified: emailVerifiedBit === 1,
|
|
30
|
+
phoneVerified: phoneVerifiedBit === 1,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.decodeKycStatus = decodeKycStatus;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.32-beta-
|
|
6
|
+
"version": "1.16.32-beta-17be26d7",
|
|
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.32-beta-
|
|
31
|
-
"@abtnode/constant": "1.16.32-beta-
|
|
30
|
+
"@abtnode/client": "1.16.32-beta-17be26d7",
|
|
31
|
+
"@abtnode/constant": "1.16.32-beta-17be26d7",
|
|
32
32
|
"@arcblock/did": "1.18.135",
|
|
33
33
|
"@arcblock/did-auth": "1.18.135",
|
|
34
34
|
"@arcblock/jwt": "1.18.135",
|
|
35
35
|
"@arcblock/ws": "1.18.135",
|
|
36
|
-
"@blocklet/constant": "1.16.32-beta-
|
|
37
|
-
"@blocklet/env": "1.16.32-beta-
|
|
38
|
-
"@blocklet/meta": "1.16.32-beta-
|
|
36
|
+
"@blocklet/constant": "1.16.32-beta-17be26d7",
|
|
37
|
+
"@blocklet/env": "1.16.32-beta-17be26d7",
|
|
38
|
+
"@blocklet/meta": "1.16.32-beta-17be26d7",
|
|
39
39
|
"@did-connect/authenticator": "^2.2.4",
|
|
40
40
|
"@did-connect/handler": "^2.2.4",
|
|
41
41
|
"@nedb/core": "^2.1.5",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"ts-node": "^10.9.1",
|
|
76
76
|
"typescript": "^5.0.4"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "9fa42d5a545aea6d57d2e1c51849fe227c8acb5e"
|
|
79
79
|
}
|