@abtnode/util 1.16.41 → 1.16.42-beta-20250403-230303-c167c6a1

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.
@@ -0,0 +1,8 @@
1
+ function deepClone(o) {
2
+ if (typeof o === 'undefined') {
3
+ return undefined;
4
+ }
5
+ return JSON.parse(JSON.stringify(o));
6
+ }
7
+
8
+ module.exports = deepClone;
package/lib/device.js ADDED
@@ -0,0 +1,19 @@
1
+ const { DEVICE_HEADERS } = require('@blocklet/constant');
2
+
3
+ const getDeviceData = ({ req }) => {
4
+ const clientName = req.get(DEVICE_HEADERS.CLIENT_NAME);
5
+ const deviceMessageToken = req.get(DEVICE_HEADERS.MESSAGE_TOKEN);
6
+ const deviceId = req.get(DEVICE_HEADERS.DEVICE_ID);
7
+ const walletDeviceMessageToken = req.get(DEVICE_HEADERS.WALLET_MESSAGE_TOKEN);
8
+ const walletDeviceId = req.get(DEVICE_HEADERS.WALLET_DEVICE_ID);
9
+
10
+ return {
11
+ clientName,
12
+ id: deviceId || walletDeviceId,
13
+ messageToken: deviceMessageToken || walletDeviceMessageToken,
14
+ };
15
+ };
16
+
17
+ module.exports = {
18
+ getDeviceData,
19
+ };
@@ -0,0 +1,28 @@
1
+ function ensureLocale({ methods = ['body', 'query', 'cookies'], force = false } = {}) {
2
+ return (req, res, next) => {
3
+ if (req.blockletLocale && !force) {
4
+ next();
5
+ return;
6
+ }
7
+
8
+ let locale = req.blockletLocale || 'en';
9
+ if (methods.includes('body') && req.body?.locale) {
10
+ locale = req.body?.locale;
11
+ } else if (methods.includes('query') && req.query?.locale) {
12
+ locale = req.query?.locale;
13
+ } else if (methods.includes('cookies') && req.cookies?.nf_lang) {
14
+ locale = req.cookies?.nf_lang;
15
+ }
16
+
17
+ // 将 cookie 中的语言设置转换为标准语言
18
+ const localeMap = {
19
+ 'zh-CN': 'zh',
20
+ 'en-US': 'en',
21
+ };
22
+ req.blockletLocale = localeMap[locale] || locale;
23
+
24
+ next();
25
+ };
26
+ }
27
+
28
+ module.exports = { ensureLocale };
package/lib/security.js CHANGED
@@ -3,13 +3,14 @@ const crypto = require('crypto');
3
3
  const AES = require('@ocap/mcrypto/lib/crypter/aes-legacy').default;
4
4
  const semver = require('semver');
5
5
  const uniq = require('lodash/uniq');
6
- const cloneDeep = require('lodash/cloneDeep');
7
6
  const { dirname, join, sep } = require('path');
8
7
  const resolve = require('resolve/sync');
9
8
  const { tmpdir, homedir } = require('os');
10
9
  const which = require('which');
11
10
  const { parseURL, withHttps, withHttp } = require('ufo');
12
11
 
12
+ const cloneDeep = require('./deep-clone');
13
+
13
14
  const encrypt = (m, s, i) => AES.encrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, 'sha512').toString('hex'));
14
15
  const decrypt = (m, s, i) => AES.decrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, 'sha512').toString('hex'));
15
16
 
package/lib/user.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs-extra');
3
3
  const { joinURL } = require('ufo');
4
- const cloneDeep = require('lodash/cloneDeep');
5
4
 
6
5
  const {
7
6
  USER_AVATAR_DIR,
@@ -12,6 +11,7 @@ const {
12
11
 
13
12
  const md5 = require('./md5');
14
13
  const axios = require('./axios');
14
+ const cloneDeep = require('./deep-clone');
15
15
 
16
16
  const getAvatarFile = (dataDir, fileName) => {
17
17
  const result = path.join(dataDir, USER_AVATAR_DIR, fileName.substring(0, 2), fileName.substring(2));
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.41",
6
+ "version": "1.16.42-beta-20250403-230303-c167c6a1",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,11 +18,11 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "Apache-2.0",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.16.41",
22
- "@arcblock/did": "^1.19.15",
21
+ "@abtnode/constant": "1.16.42-beta-20250403-230303-c167c6a1",
22
+ "@arcblock/did": "^1.19.17",
23
23
  "@arcblock/pm2": "^5.4.0",
24
- "@blocklet/constant": "1.16.41",
25
- "@blocklet/meta": "1.16.41",
24
+ "@blocklet/constant": "1.16.42-beta-20250403-230303-c167c6a1",
25
+ "@blocklet/meta": "1.16.42-beta-20250403-230303-c167c6a1",
26
26
  "@ocap/client": "1.19.15",
27
27
  "@ocap/mcrypto": "1.19.15",
28
28
  "@ocap/util": "1.19.15",
@@ -82,5 +82,5 @@
82
82
  "fs-extra": "^11.2.0",
83
83
  "jest": "^29.7.0"
84
84
  },
85
- "gitHead": "54be9488459ae9a3544648d495e6204f9fad493a"
85
+ "gitHead": "34d6d981bb270af1d0ca59704715bfa82949a9fe"
86
86
  }