@abtnode/util 1.8.36 → 1.8.38

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/nft.js ADDED
@@ -0,0 +1,15 @@
1
+ const last = require('lodash/last');
2
+ const get = require('lodash/get');
3
+
4
+ const getNftExpirationDate = (asset) => last(get(asset, 'data.value.expirationDate', []));
5
+
6
+ const isNFTExpired = (asset) => {
7
+ const expirationDate = getNftExpirationDate(asset);
8
+ return isDateExpired(expirationDate);
9
+ };
10
+
11
+ const isDateExpired = (expirationDate) => !!expirationDate && new Date(expirationDate).getTime() <= Date.now();
12
+
13
+ const isNFTConsumed = (asset) => !!asset.data.value.consumedTime;
14
+
15
+ module.exports = { isNFTExpired, getNftExpirationDate, isNFTConsumed };
package/lib/security.js CHANGED
@@ -4,7 +4,34 @@ const AES = require('@ocap/mcrypto/lib/crypter/aes').default;
4
4
  const encrypt = (m, s, i) => AES.encrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, 'sha512').toString('hex'));
5
5
  const decrypt = (m, s, i) => AES.decrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, 'sha512').toString('hex'));
6
6
 
7
+ const formatEnv = (raw, stringifyObject = true) => {
8
+ let value = raw;
9
+
10
+ // ensure no
11
+ if (Array.isArray(value) && value.every((x) => x.originFileObj && x.url)) {
12
+ value = value.map((x) => x.url);
13
+ if (value.length === 1) {
14
+ [value] = value;
15
+ }
16
+ }
17
+
18
+ // ensure no objects
19
+ if (stringifyObject) {
20
+ if (value && typeof value === 'object') {
21
+ value = JSON.stringify(value);
22
+ }
23
+ }
24
+
25
+ // ensure no line breaks for environment variables
26
+ if (value && typeof value === 'string') {
27
+ value = value.replace(/(\r\n|\n|\r)/gm, ' ');
28
+ }
29
+
30
+ return value;
31
+ };
32
+
7
33
  module.exports = {
8
34
  encrypt,
9
35
  decrypt,
36
+ formatEnv,
10
37
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.36",
6
+ "version": "1.8.38",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,13 +18,13 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.8.36",
22
- "@abtnode/logger": "1.8.36",
23
- "@arcblock/jwt": "^1.18.15",
24
- "@blocklet/constant": "1.8.36",
25
- "@ocap/mcrypto": "1.18.15",
26
- "@ocap/util": "1.18.15",
27
- "@ocap/wallet": "1.18.15",
21
+ "@abtnode/constant": "1.8.38",
22
+ "@abtnode/logger": "1.8.38",
23
+ "@arcblock/jwt": "^1.18.18",
24
+ "@blocklet/constant": "1.8.38",
25
+ "@ocap/mcrypto": "1.18.18",
26
+ "@ocap/util": "1.18.18",
27
+ "@ocap/wallet": "1.18.18",
28
28
  "axios": "^0.27.2",
29
29
  "axios-mock-adapter": "^1.21.2",
30
30
  "axon": "^2.0.3",
@@ -63,5 +63,5 @@
63
63
  "fs-extra": "^10.1.0",
64
64
  "jest": "^27.5.1"
65
65
  },
66
- "gitHead": "507e974ce88bad1aa002c593130b32982207f803"
66
+ "gitHead": "cbb88f107eb6b403c8cd47a765920575860c7bc7"
67
67
  }