@secrez/core 1.0.3 → 1.0.4
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/LICENSE +0 -0
- package/README.md +16 -17
- package/_sullof/mom.js +23 -0
- package/coverage.report +95 -99
- package/package.json +40 -43
- package/src/Entry.js +44 -42
- package/src/Secrez.js +234 -198
- package/src/_Secrez.js +135 -130
- package/src/config/ConfigUtils.js +98 -75
- package/src/config/booleans.js +3 -6
- package/src/config/index.js +9 -12
- package/src/index.js +6 -6
- package/.eslintignore +0 -0
- package/.eslintrc +0 -33
- package/.jshintrc +0 -3
- package/pnpm-lock.yaml +0 -2460
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -4,15 +4,15 @@ Secrez is the secrets manager for the cryptocurrencies era.
|
|
|
4
4
|
|
|
5
5
|
@secrez/core is the basic library.
|
|
6
6
|
|
|
7
|
-
It exposes
|
|
8
|
-
* Secrez
|
|
9
|
-
* Crypto
|
|
10
|
-
* Entry
|
|
11
|
-
* config
|
|
12
|
-
* ConfigUtils
|
|
7
|
+
It exposes
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
- Secrez
|
|
10
|
+
- Crypto
|
|
11
|
+
- Entry
|
|
12
|
+
- config
|
|
13
|
+
- ConfigUtils
|
|
15
14
|
|
|
15
|
+
Those classes are used by other Secrez packages to interact with the encrypted database.
|
|
16
16
|
|
|
17
17
|
## TODO
|
|
18
18
|
|
|
@@ -20,32 +20,31 @@ API documentation
|
|
|
20
20
|
|
|
21
21
|
## History
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
* improve _Secrez and Secrez encapsulation of private data
|
|
25
|
-
* when changing the password, compares the existent password with the derivated one to avoid brute force attacks from inside Secrez (for example, in a future plugin)
|
|
23
|
+
**0.8.5**
|
|
26
24
|
|
|
25
|
+
- improve \_Secrez and Secrez encapsulation of private data
|
|
26
|
+
- when changing the password, compares the existent password with the derivated one to avoid brute force attacks from inside Secrez (for example, in a future plugin)
|
|
27
27
|
|
|
28
28
|
## Test coverage
|
|
29
29
|
|
|
30
30
|
```
|
|
31
|
-
60 passing (
|
|
31
|
+
60 passing (1s)
|
|
32
32
|
|
|
33
33
|
-----------------|---------|----------|---------|---------|-------------------
|
|
34
34
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
35
35
|
-----------------|---------|----------|---------|---------|-------------------
|
|
36
36
|
All files | 99.75 | 94.31 | 100 | 99.75 |
|
|
37
37
|
src | 100 | 96.07 | 100 | 100 |
|
|
38
|
-
Entry.js | 100 | 95.65 | 100 | 100 |
|
|
39
|
-
Secrez.js | 100 | 96.95 | 100 | 100 |
|
|
40
|
-
_Secrez.js | 100 | 91.67 | 100 | 100 |
|
|
41
|
-
src/config | 98.57 | 84.85 | 100 | 98.
|
|
42
|
-
ConfigUtils.js | 98.48 | 84.85 | 100 | 98.
|
|
38
|
+
Entry.js | 100 | 95.65 | 100 | 100 | 39
|
|
39
|
+
Secrez.js | 100 | 96.95 | 100 | 100 | 154,319,442
|
|
40
|
+
_Secrez.js | 100 | 91.67 | 100 | 100 | 14,226
|
|
41
|
+
src/config | 98.57 | 84.85 | 100 | 98.57 |
|
|
42
|
+
ConfigUtils.js | 98.48 | 84.85 | 100 | 98.48 | 137
|
|
43
43
|
booleans.js | 100 | 100 | 100 | 100 |
|
|
44
44
|
index.js | 100 | 100 | 100 | 100 |
|
|
45
45
|
-----------------|---------|----------|---------|---------|-------------------
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
|
|
49
48
|
## Copyright
|
|
50
49
|
|
|
51
50
|
(c) 2020-present [Francesco Sullo](https://francesco.sullo.co) (<francesco@sullo.co>)
|
package/_sullof/mom.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const Crypto = require('@secrez/crypto')
|
|
2
|
+
let a = `function kriminal(ts) {
|
|
3
|
+
ts = ts % 1e4
|
|
4
|
+
const R = []
|
|
5
|
+
const is = {}
|
|
6
|
+
for (; ;) {
|
|
7
|
+
let h = ethers.utils.id('' + ts)
|
|
8
|
+
for (let i = 2; i < h.length; i++) {
|
|
9
|
+
let v = parseInt(h.substring(i, i + 1))
|
|
10
|
+
if (!isNaN(v) && v < 7 && !is[v]) {
|
|
11
|
+
R.push(v)
|
|
12
|
+
if (~R.length === -4) {
|
|
13
|
+
return R
|
|
14
|
+
}
|
|
15
|
+
is[v] = 1
|
|
16
|
+
}
|
|
17
|
+
ts++
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}`
|
|
21
|
+
|
|
22
|
+
console.log(Crypto.toBase64(a))
|
|
23
|
+
|
package/coverage.report
CHANGED
|
@@ -1,112 +1,108 @@
|
|
|
1
1
|
|
|
2
|
-
> @secrez/core@1.0.
|
|
3
|
-
> cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text
|
|
2
|
+
> @secrez/core@1.0.4 test /Users/francescosullo/Projects/Personal/secrez/packages/core
|
|
3
|
+
> cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
[0m[0m
|
|
7
|
-
[0m #Entry[0m
|
|
8
|
-
[0m #constructor[0m
|
|
9
|
-
[32m ✓[0m[90m should instantiate the Entry[0m
|
|
10
|
-
[32m ✓[0m[90m should ignore wrong parameters[0m
|
|
11
|
-
[0m #set[0m
|
|
12
|
-
[32m ✓[0m[90m should set some options for the Entry[0m
|
|
13
|
-
[32m ✓[0m[90m should skip invalid options[0m
|
|
14
|
-
[0m #unset[0m
|
|
15
|
-
[32m ✓[0m[90m should unset some options[0m
|
|
16
|
-
[32m ✓[0m[90m should skip invalid or undefined options[0m
|
|
17
|
-
[0m #sanitizeName[0m
|
|
18
|
-
[32m ✓[0m[90m should sanitize names[0m
|
|
19
|
-
[0m #sanitizePath[0m
|
|
20
|
-
[32m ✓[0m[90m should sanitize path[0m
|
|
21
6
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
[0m should throw an error[0m
|
|
37
|
-
[32m ✓[0m[90m trying to signup if Secrez has not been initiated[0m
|
|
38
|
-
[32m ✓[0m[90m trying to signin if Secrez has not been initiated[0m
|
|
39
|
-
[32m ✓[0m[90m trying to signup if account already exists[0m
|
|
40
|
-
[32m ✓[0m[90m trying to signin if account is not set yet[0m
|
|
41
|
-
[32m ✓[0m[90m trying to signin with missed iterations[0m
|
|
42
|
-
[32m ✓[0m[90m trying to signin with the wrong password[0m[33m (40ms)[0m
|
|
43
|
-
[32m ✓[0m[90m trying to signin with the right password but wrong number of iterations[0m
|
|
44
|
-
[32m ✓[0m[90m trying to signin with the right password but using a wrong hash on file[0m[33m (55ms)[0m
|
|
45
|
-
[32m ✓[0m[90m trying to sign out if never signed-in[0m
|
|
46
|
-
[0m encryptEntry and decryptEntry[0m
|
|
47
|
-
[32m ✓[0m[90m should encrypt a name and decrypt it[0m
|
|
48
|
-
[32m ✓[0m[90m should encrypt a very long name and decrypt it[0m
|
|
49
|
-
[32m ✓[0m[90m should encrypt name and content and decrypt it[0m
|
|
50
|
-
[32m ✓[0m[90m should encrypt only the content and decrypt it[0m
|
|
51
|
-
[32m ✓[0m[90m should re-encrypt the content and decrypt it[0m
|
|
52
|
-
[32m ✓[0m[90m should throw if the user is not logged in[0m
|
|
53
|
-
[32m ✓[0m[90m should throw if wrong type[0m
|
|
54
|
-
[32m ✓[0m[90m should throw if no entry is passed[0m
|
|
55
|
-
[32m ✓[0m[90m should throw if encrypted data are corrupted[0m
|
|
56
|
-
[32m ✓[0m[90m should throw if content has not the same id of the name[0m
|
|
57
|
-
[32m ✓[0m[90m should throw if parameters are missed[0m
|
|
58
|
-
[0m encryptData and decryptData[0m
|
|
59
|
-
[32m ✓[0m[90m should encrypt some data and decrypt it[0m
|
|
60
|
-
[32m ✓[0m[90m should throw trying to get box and sign secret keys[0m
|
|
61
|
-
[0m preEncryptData and preDecryptData[0m
|
|
62
|
-
[32m ✓[0m[90m should encrypt some data with the derivedPassword and decrypt it[0m
|
|
63
|
-
[32m ✓[0m[90m should throw trying to get the master key[0m
|
|
64
|
-
[0m generateSharedSecrets && recoverSharedSecrets[0m
|
|
65
|
-
[32m ✓[0m[90m should set up a second factor[0m[33m (65ms)[0m
|
|
66
|
-
[32m ✓[0m[90m should set up a second factor and then upgrade from derivationVersion 1 to 2[0m[33m (61ms)[0m
|
|
67
|
-
[32m ✓[0m[90m should set up a second factor and a recovery code and remove them[0m[33m (72ms)[0m
|
|
68
|
-
[32m ✓[0m[90m should set up a second factor and a recovery code and remove the recovery code[0m[33m (70ms)[0m
|
|
69
|
-
[32m ✓[0m[90m should throw if wrong secret[0m[33m (58ms)[0m
|
|
70
|
-
[32m ✓[0m[90m should throw if wrong authenticator[0m[33m (38ms)[0m
|
|
71
|
-
[0m #readConf[0m
|
|
72
|
-
[32m ✓[0m[90m should encrypt some data with the derivedPassword and decrypt it[0m
|
|
73
|
-
[32m ✓[0m[90m should throw trying to get the master key[0m
|
|
74
|
-
[32m ✓[0m[90m should throw trying to get the master key[0m
|
|
75
|
-
[0m #signMessage[0m
|
|
76
|
-
[32m ✓[0m[90m should sign a message and verify it[0m[33m (46ms)[0m
|
|
77
|
-
[0m #getPublicKey[0m
|
|
78
|
-
[32m ✓[0m[90m should sign a message and verify it[0m[33m (39ms)[0m
|
|
79
|
-
[0m #encrypt and decrypt shared data[0m
|
|
80
|
-
[32m ✓[0m[90m should get a shared ket[0m[33m (61ms)[0m
|
|
7
|
+
#Entry
|
|
8
|
+
#constructor
|
|
9
|
+
✓ should instantiate the Entry
|
|
10
|
+
✓ should ignore wrong parameters
|
|
11
|
+
#set
|
|
12
|
+
✓ should set some options for the Entry
|
|
13
|
+
✓ should skip invalid options
|
|
14
|
+
#unset
|
|
15
|
+
✓ should unset some options
|
|
16
|
+
✓ should skip invalid or undefined options
|
|
17
|
+
#sanitizeName
|
|
18
|
+
✓ should sanitize names
|
|
19
|
+
#sanitizePath
|
|
20
|
+
✓ should sanitize path
|
|
81
21
|
|
|
82
|
-
|
|
83
|
-
|
|
22
|
+
#Secrez
|
|
23
|
+
default secrez dir
|
|
24
|
+
✓ should throw trying to test in the default ~/.secrez folder
|
|
25
|
+
custom (testing) secrez dir
|
|
26
|
+
derivePassword
|
|
27
|
+
✓ should derive a password and obtain a predeterminded hash
|
|
28
|
+
signup and signin
|
|
29
|
+
✓ should signup the user and signin without saving the iterations (71ms)
|
|
30
|
+
✓ should signup in two instances without conflicts (41ms)
|
|
31
|
+
✓ should signup the user and signin saved the iterations (38ms)
|
|
32
|
+
✓ should signup with version one, and signin and upgrade to version two (68ms)
|
|
33
|
+
✓ should signup the user, change password and signin (56ms)
|
|
34
|
+
✓ should signup the user, change iterations and signin (49ms)
|
|
35
|
+
✓ should signup the user, change password and iterations and signin (67ms)
|
|
36
|
+
should throw an error
|
|
37
|
+
✓ trying to signup if Secrez has not been initiated
|
|
38
|
+
✓ trying to signin if Secrez has not been initiated
|
|
39
|
+
✓ trying to signup if account already exists
|
|
40
|
+
✓ trying to signin if account is not set yet
|
|
41
|
+
✓ trying to signin with missed iterations
|
|
42
|
+
✓ trying to signin with the wrong password
|
|
43
|
+
✓ trying to signin with the right password but wrong number of iterations
|
|
44
|
+
✓ trying to signin with the right password but using a wrong hash on file
|
|
45
|
+
✓ trying to sign out if never signed-in
|
|
46
|
+
encryptEntry and decryptEntry
|
|
47
|
+
✓ should encrypt a name and decrypt it
|
|
48
|
+
✓ should encrypt a very long name and decrypt it
|
|
49
|
+
✓ should encrypt name and content and decrypt it
|
|
50
|
+
✓ should encrypt only the content and decrypt it
|
|
51
|
+
✓ should re-encrypt the content and decrypt it
|
|
52
|
+
✓ should throw if the user is not logged in
|
|
53
|
+
✓ should throw if wrong type
|
|
54
|
+
✓ should throw if no entry is passed
|
|
55
|
+
✓ should throw if encrypted data are corrupted
|
|
56
|
+
✓ should throw if content has not the same id of the name
|
|
57
|
+
✓ should throw if parameters are missed
|
|
58
|
+
encryptData and decryptData
|
|
59
|
+
✓ should encrypt some data and decrypt it
|
|
60
|
+
✓ should throw trying to get box and sign secret keys
|
|
61
|
+
preEncryptData and preDecryptData
|
|
62
|
+
✓ should encrypt some data with the derivedPassword and decrypt it
|
|
63
|
+
✓ should throw trying to get the master key
|
|
64
|
+
generateSharedSecrets && recoverSharedSecrets
|
|
65
|
+
✓ should set up a second factor (57ms)
|
|
66
|
+
✓ should set up a second factor and then upgrade from derivationVersion 1 to 2
|
|
67
|
+
✓ should set up a second factor and a recovery code and remove them (58ms)
|
|
68
|
+
✓ should set up a second factor and a recovery code and remove the recovery code (58ms)
|
|
69
|
+
✓ should throw if wrong secret
|
|
70
|
+
✓ should throw if wrong authenticator
|
|
71
|
+
#readConf
|
|
72
|
+
✓ should encrypt some data with the derivedPassword and decrypt it
|
|
73
|
+
✓ should throw trying to get the master key
|
|
74
|
+
✓ should throw trying to get the master key
|
|
75
|
+
#signMessage
|
|
76
|
+
✓ should sign a message and verify it (40ms)
|
|
77
|
+
#getPublicKey
|
|
78
|
+
✓ should sign a message and verify it
|
|
79
|
+
#encrypt and decrypt shared data
|
|
80
|
+
✓ should get a shared ket (50ms)
|
|
84
81
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[32m ✓[0m[90m #setSecrez should configure a secrez environment[0m
|
|
88
|
-
[32m ✓[0m[90m #setAndGetDataset should set and get a secondary db[0m
|
|
89
|
-
[32m ✓[0m[90m #deleteDataset should delete a dataset path[0m
|
|
90
|
-
[32m ✓[0m[90m #getDatasetPath should get a dataset path[0m
|
|
91
|
-
[32m ✓[0m[90m #getEnv should return the environment[0m
|
|
82
|
+
#config
|
|
83
|
+
✓ all field should be correctly configured
|
|
92
84
|
|
|
85
|
+
#ConfigUtils
|
|
86
|
+
✓ should check if a type is valid
|
|
87
|
+
✓ #setSecrez should configure a secrez environment
|
|
88
|
+
✓ #setAndGetDataset should set and get a secondary db
|
|
89
|
+
✓ #deleteDataset should delete a dataset path
|
|
90
|
+
✓ #getDatasetPath should get a dataset path
|
|
91
|
+
✓ #getEnv should return the environment
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
|
|
94
|
+
60 passing (1s)
|
|
95
95
|
|
|
96
96
|
-----------------|---------|----------|---------|---------|-------------------
|
|
97
97
|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
98
98
|
-----------------|---------|----------|---------|---------|-------------------
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
All files | 99.75 | 94.31 | 100 | 99.75 |
|
|
100
|
+
src | 100 | 96.07 | 100 | 100 |
|
|
101
|
+
Entry.js | 100 | 95.65 | 100 | 100 | 39
|
|
102
|
+
Secrez.js | 100 | 96.95 | 100 | 100 | 154,319,442
|
|
103
|
+
_Secrez.js | 100 | 91.67 | 100 | 100 | 14,226
|
|
104
|
+
src/config | 98.57 | 84.85 | 100 | 98.57 |
|
|
105
|
+
ConfigUtils.js | 98.48 | 84.85 | 100 | 98.48 | 137
|
|
106
|
+
booleans.js | 100 | 100 | 100 | 100 |
|
|
107
|
+
index.js | 100 | 100 | 100 | 100 |
|
|
108
108
|
-----------------|---------|----------|---------|---------|-------------------
|
|
109
|
-
|
|
110
|
-
> @secrez/core@1.0.3 posttest /Users/sullof/Projects/Personal/secrez/packages/core
|
|
111
|
-
> nyc check-coverage --statements 99 --branches 94 --functions 99 --lines 99
|
|
112
|
-
|
package/package.json
CHANGED
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"node": ">=10.0.0"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
2
|
+
"name": "@secrez/core",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@secrez/crypto": "~1.0.3",
|
|
10
|
+
"@secrez/utils": "~1.0.3",
|
|
11
|
+
"fs-extra": "^9.1.0",
|
|
12
|
+
"homedir": "^0.6.0",
|
|
13
|
+
"lodash": "^4.17.15"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@secrez/test-helpers": "~2.0.0",
|
|
17
|
+
"chai": "^4.2.0",
|
|
18
|
+
"cross-env": "^7.0.2",
|
|
19
|
+
"mocha": "^7.1.2",
|
|
20
|
+
"nyc": "^15.1.0"
|
|
21
|
+
},
|
|
22
|
+
"description": "The Secrez core library.",
|
|
23
|
+
"main": "src/index.js",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/secrez/secrez.git"
|
|
27
|
+
},
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "Francesco Sullo",
|
|
30
|
+
"email": "francesco@sullo.co"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=10.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"all-tests": "find test/** -name '*.test.js' | xargs ./node_modules/.bin/mocha -R spec",
|
|
37
|
+
"test-only": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js test/**/*.test.js --exit",
|
|
38
|
+
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js --exit",
|
|
39
|
+
"posttest": "nyc check-coverage --statements 99 --branches 94 --functions 99 --lines 99"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/Entry.js
CHANGED
|
@@ -1,89 +1,91 @@
|
|
|
1
|
-
const {removeNotPrintableChars} = require(
|
|
1
|
+
const { removeNotPrintableChars } = require("@secrez/utils");
|
|
2
2
|
|
|
3
3
|
class Entry {
|
|
4
|
-
|
|
5
4
|
isValid(option) {
|
|
6
|
-
return Entry.validOptions.includes(option)
|
|
5
|
+
return Entry.validOptions.includes(option);
|
|
7
6
|
}
|
|
8
7
|
|
|
9
8
|
constructor(options) {
|
|
10
|
-
this.set(options)
|
|
9
|
+
this.set(options);
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
get(options = Entry.validOptions) {
|
|
14
|
-
let obj = {}
|
|
13
|
+
let obj = {};
|
|
15
14
|
for (let o of options) {
|
|
16
|
-
if (this.isValid(o) && typeof this[o] !==
|
|
17
|
-
obj[o] = this[o]
|
|
15
|
+
if (this.isValid(o) && typeof this[o] !== "undefined") {
|
|
16
|
+
obj[o] = this[o];
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
return obj
|
|
19
|
+
return obj;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
set(key, value) {
|
|
24
|
-
let options = {}
|
|
25
|
-
if (typeof key ===
|
|
26
|
-
options = key
|
|
23
|
+
let options = {};
|
|
24
|
+
if (typeof key === "object") {
|
|
25
|
+
options = key;
|
|
27
26
|
} else {
|
|
28
|
-
options[key] = value
|
|
27
|
+
options[key] = value;
|
|
29
28
|
}
|
|
30
29
|
if (options.name) {
|
|
31
|
-
options.name = Entry.sanitizeName(options.name)
|
|
30
|
+
options.name = Entry.sanitizeName(options.name);
|
|
32
31
|
}
|
|
33
32
|
for (let o in options) {
|
|
34
|
-
if (this.isValid(o) && typeof options[o] !==
|
|
35
|
-
this[o] = options[o]
|
|
33
|
+
if (this.isValid(o) && typeof options[o] !== "undefined") {
|
|
34
|
+
this[o] = options[o];
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
unset(options = []) {
|
|
41
40
|
if (!Array.isArray(options)) {
|
|
42
|
-
options = [options]
|
|
41
|
+
options = [options];
|
|
43
42
|
}
|
|
44
43
|
for (let o of options) {
|
|
45
|
-
if (this.isValid(o) && typeof this[o] !==
|
|
46
|
-
delete this[o]
|
|
44
|
+
if (this.isValid(o) && typeof this[o] !== "undefined") {
|
|
45
|
+
delete this[o];
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
static sanitizeName(name, subst =
|
|
50
|
+
static sanitizeName(name, subst = "") {
|
|
52
51
|
// removes character forbidden by operating systems
|
|
53
52
|
// eslint-disable-next-line no-useless-escape
|
|
54
|
-
return removeNotPrintableChars(name).replace(
|
|
53
|
+
return removeNotPrintableChars(name).replace(
|
|
54
|
+
/[\\\/\>\<\|\:\&\?\*\^\$]/gi,
|
|
55
|
+
subst
|
|
56
|
+
);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
static sanitizePath(p, subst) {
|
|
58
|
-
if (typeof p ===
|
|
60
|
+
if (typeof p === "string") {
|
|
59
61
|
// removes character forbidden by operating systems
|
|
60
62
|
// eslint-disable-next-line no-useless-escape
|
|
61
|
-
return p
|
|
63
|
+
return p
|
|
64
|
+
.split("/")
|
|
65
|
+
.map((e) => Entry.sanitizeName(e, subst))
|
|
66
|
+
.join("/");
|
|
62
67
|
} else {
|
|
63
|
-
throw new Error(
|
|
68
|
+
throw new Error("Path must be a string");
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
Entry.validOptions = [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
"type",
|
|
75
|
+
"id",
|
|
76
|
+
"ts",
|
|
74
77
|
// 'scrambledTs',
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
]
|
|
87
|
-
|
|
78
|
+
"name",
|
|
79
|
+
"content",
|
|
80
|
+
"encryptedName",
|
|
81
|
+
"encryptedContent",
|
|
82
|
+
"microseconds",
|
|
83
|
+
"extraName",
|
|
84
|
+
"nameId",
|
|
85
|
+
"nameTs",
|
|
86
|
+
"preserveContent",
|
|
87
|
+
"parent",
|
|
88
|
+
"treeIndex",
|
|
89
|
+
];
|
|
88
90
|
|
|
89
|
-
module.exports = Entry
|
|
91
|
+
module.exports = Entry;
|