@blocklet/sdk 1.16.32-beta-20240919-083324-82550492 → 1.16.32-beta-20240924-105841-08174626

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/config.js CHANGED
@@ -63,7 +63,11 @@ if (appDataDir) {
63
63
  try {
64
64
  const configFile = path_1.default.join(appDataDir, constant_1.APP_CONFIG_FILE_PATH);
65
65
  if (fs_1.default.existsSync(configFile)) {
66
- const config = JSON.parse(fs_1.default.readFileSync(configFile).toString());
66
+ let configRaw = fs_1.default.readFileSync(configFile).toString();
67
+ if (process.env.DOCKER_HOST_SERVER_DIR && process.env.DOCKER_CONTAINER_SERVER_DIR) {
68
+ configRaw = configRaw.replace(process.env.DOCKER_HOST_SERVER_DIR, process.env.DOCKER_CONTAINER_SERVER_DIR);
69
+ }
70
+ const config = JSON.parse(configRaw);
67
71
  appEnvFromDisk = config.env || {};
68
72
  componentsFromDisk = config.components;
69
73
  }
@@ -43,7 +43,7 @@ const AuthMiddleware = ({ roles, permissions, kyc, methods, getClient = getServi
43
43
  const userDid = req.user?.did || req.headers['x-user-did'];
44
44
  const userRole = req.user?.role || req.headers['x-user-role'];
45
45
  const userKyc = req.user?.kyc || req.headers['x-user-kyc'];
46
- const userMethod = req.user?.method || 'loginToken';
46
+ const userMethod = req.user?.method || '';
47
47
  if (!userDid) {
48
48
  res.status(401).json({ code: 'forbidden', error: 'not authorized' });
49
49
  return;
@@ -67,6 +67,7 @@ declare const _default: {
67
67
  }) => void, req?: import("express").Request) => Promise<void>) => (req: import("express").Request, res: import("express").Response) => Promise<void>;
68
68
  csrf: typeof csrf;
69
69
  session: (options?: {
70
+ strictMode?: boolean;
70
71
  loginToken?: boolean;
71
72
  componentCall?: boolean;
72
73
  signedToken?: boolean;
@@ -1,6 +1,7 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
2
  import { SessionUser } from '../util/login';
3
3
  type SessionOptions = {
4
+ strictMode?: boolean;
4
5
  loginToken?: boolean;
5
6
  componentCall?: boolean;
6
7
  signedToken?: boolean;
@@ -12,7 +12,7 @@ const wallet_1 = __importDefault(require("../wallet"));
12
12
  const sessionMiddleware = (options = {}) => {
13
13
  const wallet = (0, wallet_1.default)();
14
14
  const secret = mcrypto_1.Hasher.SHA3.hash256(Buffer.concat([wallet.secretKey, wallet.address].map((v) => Buffer.from(v))));
15
- const { loginToken = true, componentCall = false, signedToken = '' } = options;
15
+ const { loginToken = true, componentCall = false, signedToken = '', strictMode = false } = options;
16
16
  return (req, res, next) => {
17
17
  // authenticate by login token
18
18
  if (loginToken) {
@@ -20,7 +20,12 @@ const sessionMiddleware = (options = {}) => {
20
20
  if (token) {
21
21
  return jsonwebtoken_1.default.verify(token, secret, (err, decoded) => {
22
22
  if (err) {
23
- res.status(401).json({ message: 'Unauthorized: Invalid login token' });
23
+ if (strictMode) {
24
+ res.status(401).json({ message: 'Unauthorized: Invalid login token' });
25
+ }
26
+ else {
27
+ next();
28
+ }
24
29
  }
25
30
  else {
26
31
  const { did, role, fullName, provider = constant_1.LOGIN_PROVIDER.WALLET, walletOS, kyc = 0 } = decoded;
@@ -45,7 +50,10 @@ const sessionMiddleware = (options = {}) => {
45
50
  // FIXME: @zhanghan please check this
46
51
  const data = typeof req.body === 'undefined' ? {} : req.body;
47
52
  if ((0, verify_sign_1.verify)(data, signature) === false) {
48
- return res.status(401).json({ error: 'Unauthorized: Invalid signature' });
53
+ if (strictMode) {
54
+ return res.status(401).json({ error: 'Unauthorized: Invalid signature' });
55
+ }
56
+ return next();
49
57
  }
50
58
  req.user = {
51
59
  did: req.get('x-component-did'),
@@ -65,7 +73,10 @@ const sessionMiddleware = (options = {}) => {
65
73
  const token = req.query.__jwt || '';
66
74
  if (token) {
67
75
  if ((0, jwt_1.verify)(token, secret) === false) {
68
- return res.status(401).json({ error: 'Unauthorized: Invalid signed token' });
76
+ if (strictMode) {
77
+ return res.status(401).json({ error: 'Unauthorized: Invalid signed token' });
78
+ }
79
+ return next();
69
80
  }
70
81
  req.user = {
71
82
  did: wallet.address,
@@ -13,10 +13,13 @@ const constant_1 = require("@abtnode/constant");
13
13
  const login_1 = require("./login");
14
14
  function getFederatedMasterAppInfo({ blocklet, sourceAppPid, version, groupPathPrefix, nodeInfo, }) {
15
15
  const { federated } = blocklet.settings;
16
+ if (!federated) {
17
+ return null;
18
+ }
16
19
  const master = federated.sites.find((x) => x.appPid === sourceAppPid);
17
20
  return {
18
21
  name: master.appName,
19
- description: master.appescription || `Connect to ${master.appName}`,
22
+ description: master.appDescription || `Connect to ${master.appName}`,
20
23
  icon: (0, ufo_1.joinURL)(master.appUrl, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/blocklet/logo?v=${version}`),
21
24
  link: master.appUrl,
22
25
  updateSubEndpoint: true,
@@ -32,7 +35,7 @@ async function getAppInfo({ request, baseUrl, getBlocklet, getNodeInfo, }) {
32
35
  returnWallet: false,
33
36
  });
34
37
  const { version, name, description } = blockletInfo;
35
- if (sourceAppPid) {
38
+ if (sourceAppPid && blocklet?.settings?.federated) {
36
39
  return getFederatedMasterAppInfo({
37
40
  blocklet,
38
41
  sourceAppPid,
@@ -60,7 +63,7 @@ async function getMemberAppInfo({ request, baseUrl, getBlocklet, getNodeInfo, })
60
63
  returnWallet: false,
61
64
  });
62
65
  const { version, name, description } = blockletInfo;
63
- if (sourceAppPid && blocklet) {
66
+ if (sourceAppPid && blocklet?.settings?.federated) {
64
67
  return {
65
68
  name,
66
69
  description: description || `Connect to ${name}`,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.32-beta-20240919-083324-82550492",
6
+ "version": "1.16.32-beta-20240924-105841-08174626",
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-20240919-083324-82550492",
31
- "@abtnode/constant": "1.16.32-beta-20240919-083324-82550492",
30
+ "@abtnode/client": "1.16.32-beta-20240924-105841-08174626",
31
+ "@abtnode/constant": "1.16.32-beta-20240924-105841-08174626",
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-20240919-083324-82550492",
37
- "@blocklet/env": "1.16.32-beta-20240919-083324-82550492",
38
- "@blocklet/meta": "1.16.32-beta-20240919-083324-82550492",
36
+ "@blocklet/constant": "1.16.32-beta-20240924-105841-08174626",
37
+ "@blocklet/env": "1.16.32-beta-20240924-105841-08174626",
38
+ "@blocklet/meta": "1.16.32-beta-20240924-105841-08174626",
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": "591bfa762d9fe1ca1edf30c2d02f8e4a03de4cf5"
79
+ "gitHead": "09da4510de3aeb2fd493ce22a5a913835725a13f"
80
80
  }