@blocklet/sdk 1.16.33-beta-20241001-015316-119b726d → 1.16.33-beta-20241010-072121-fe74d5f7

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
@@ -151,10 +151,8 @@ const _setUpdatedComponents = (components) => {
151
151
  return list;
152
152
  };
153
153
  const _handleComponentStarted = (data) => {
154
- logger.debug('_handleComponentStarted.before', data.components, componentStore);
155
154
  const list = _setComponentStatus(data.components, constant_1.BlockletStatus.running);
156
155
  events.emit(Events.componentStarted, list);
157
- logger.debug('_handleComponentStarted.after', componentStore);
158
156
  };
159
157
  exports._handleComponentStarted = _handleComponentStarted;
160
158
  const _handleComponentStopped = (data) => {
@@ -175,10 +173,8 @@ const _handleComponentUpdated = (data) => {
175
173
  };
176
174
  exports._handleComponentUpdated = _handleComponentUpdated;
177
175
  const _handleComponentInstalled = (data) => {
178
- logger.debug('_handleComponentInstalled.before', data.components, componentStore);
179
176
  const list = _setUpdatedComponents(data.components);
180
177
  events.emit(Events.componentAdded, list);
181
- logger.debug('_handleComponentInstalled.after', componentStore);
182
178
  };
183
179
  exports._handleComponentInstalled = _handleComponentInstalled;
184
180
  const _handleConfigUpdate = (data) => {
@@ -8,7 +8,15 @@ const lodash_1 = require("lodash");
8
8
  const joi_1 = __importDefault(require("joi"));
9
9
  const digest_1 = require("../util/digest");
10
10
  const wallet_1 = require("../util/wallet");
11
+ const config_1 = require("../config");
12
+ function printCookieParserNotInstalledWarning() {
13
+ config_1.logger.warn('cookie-parser middleware is required for the csrf middleware to work properly.');
14
+ }
11
15
  function defaultGenerateToken(req, res) {
16
+ if (!req.cookies) {
17
+ printCookieParserNotInstalledWarning();
18
+ return;
19
+ }
12
20
  if (req.cookies.login_token && !req.cookies['x-csrf-token']) {
13
21
  const xCsrfTokenMd5 = (0, digest_1.hmac)(req.cookies.login_token);
14
22
  const xCsrfTokenSigned = (0, digest_1.hmac)(xCsrfTokenMd5);
@@ -19,13 +27,18 @@ function defaultGenerateToken(req, res) {
19
27
  }
20
28
  }
21
29
  function defaultVerifyToken(req) {
22
- if (!(0, lodash_1.isEmpty)(req.cookies['x-csrf-token']) && req.cookies['x-csrf-token'] === req.headers['x-csrf-token']) {
30
+ if (!req.cookies) {
31
+ printCookieParserNotInstalledWarning();
32
+ }
33
+ if (req.cookies &&
34
+ !(0, lodash_1.isEmpty)(req.cookies['x-csrf-token']) &&
35
+ req.cookies['x-csrf-token'] === req.headers['x-csrf-token']) {
23
36
  const [xCsrfTokenMd5, xCsrfTokenSigned] = req.headers['x-csrf-token'].split('.');
24
37
  if ((0, digest_1.hmac)(xCsrfTokenMd5) === xCsrfTokenSigned) {
25
38
  return;
26
39
  }
27
40
  }
28
- throw new Error('Current request status is abnormal, please retry later');
41
+ throw new Error('Invalid request: csrf token mismatch');
29
42
  }
30
43
  function shouldGenerateToken(req) {
31
44
  return ['GET'].includes(req.method);
@@ -53,12 +66,17 @@ function csrf(options = { generateToken: defaultGenerateToken, verifyToken: defa
53
66
  return async (req, res, next) => {
54
67
  res.locals.generateToken = defaultGenerateToken;
55
68
  res.locals.verifyToken = defaultVerifyToken;
56
- if (shouldGenerateToken(req)) {
57
- await data.generateToken(req, res);
69
+ try {
70
+ if (shouldGenerateToken(req)) {
71
+ await data.generateToken(req, res);
72
+ }
73
+ else if (shouldVerifyToken(req)) {
74
+ await data.verifyToken(req, res);
75
+ }
76
+ return next();
58
77
  }
59
- else if (shouldVerifyToken(req)) {
60
- await data.verifyToken(req, res);
78
+ catch (err) {
79
+ return next(err);
61
80
  }
62
- return next();
63
81
  };
64
82
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.33-beta-20241001-015316-119b726d",
6
+ "version": "1.16.33-beta-20241010-072121-fe74d5f7",
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.33-beta-20241001-015316-119b726d",
31
- "@abtnode/constant": "1.16.33-beta-20241001-015316-119b726d",
30
+ "@abtnode/client": "1.16.33-beta-20241010-072121-fe74d5f7",
31
+ "@abtnode/constant": "1.16.33-beta-20241010-072121-fe74d5f7",
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.33-beta-20241001-015316-119b726d",
37
- "@blocklet/env": "1.16.33-beta-20241001-015316-119b726d",
38
- "@blocklet/meta": "1.16.33-beta-20241001-015316-119b726d",
36
+ "@blocklet/constant": "1.16.33-beta-20241010-072121-fe74d5f7",
37
+ "@blocklet/env": "1.16.33-beta-20241010-072121-fe74d5f7",
38
+ "@blocklet/meta": "1.16.33-beta-20241010-072121-fe74d5f7",
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": "5cac4c3579c14ebae18810b1f27ecbc63603088d"
79
+ "gitHead": "c5abd249175ee1549de5d5d71cf32f52e3734bd0"
80
80
  }