@usebruno/js 0.9.1 → 0.9.3
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/package.json +4 -3
- package/src/bru.js +18 -7
- package/src/bruno-response.js +5 -0
- package/src/runtime/script-runtime.js +11 -3
- package/src/runtime/test-runtime.js +9 -2
- package/src/utils.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usebruno/js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@usebruno/query": "0.1.0",
|
|
18
18
|
"ajv": "^8.12.0",
|
|
19
19
|
"atob": "^2.1.2",
|
|
20
|
-
"axios": "^
|
|
20
|
+
"axios": "^1.5.1",
|
|
21
21
|
"btoa": "^1.2.1",
|
|
22
22
|
"chai": "^4.3.7",
|
|
23
23
|
"chai-string": "^1.5.0",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"moment": "^2.29.4",
|
|
29
29
|
"nanoid": "3.3.4",
|
|
30
30
|
"node-fetch": "2.*",
|
|
31
|
-
"uuid": "^9.0.0"
|
|
31
|
+
"uuid": "^9.0.0",
|
|
32
|
+
"node-vault": "^0.10.2"
|
|
32
33
|
}
|
|
33
34
|
}
|
package/src/bru.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Handlebars = require('handlebars');
|
|
2
2
|
const { cloneDeep } = require('lodash');
|
|
3
3
|
|
|
4
|
+
const variableNameRegex = /^[\w-.]*$/;
|
|
5
|
+
|
|
4
6
|
class Bru {
|
|
5
7
|
constructor(envVariables, collectionVariables, processEnvVars, collectionPath) {
|
|
6
8
|
this.envVariables = envVariables;
|
|
@@ -43,12 +45,7 @@ class Bru {
|
|
|
43
45
|
|
|
44
46
|
setEnvVar(key, value) {
|
|
45
47
|
if (!key) {
|
|
46
|
-
throw new Error('
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// gracefully ignore if key is not present in environment
|
|
50
|
-
if (!this.envVariables.hasOwnProperty(key)) {
|
|
51
|
-
return;
|
|
48
|
+
throw new Error('Creating a env variable without specifying a name is not allowed.');
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
this.envVariables[key] = value;
|
|
@@ -56,13 +53,27 @@ class Bru {
|
|
|
56
53
|
|
|
57
54
|
setVar(key, value) {
|
|
58
55
|
if (!key) {
|
|
59
|
-
throw new Error('
|
|
56
|
+
throw new Error('Creating a variable without specifying a name is not allowed.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (variableNameRegex.test(key) === false) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Variable name: "${key}" contains invalid characters!` +
|
|
62
|
+
' Names must only contain alpha-numeric characters, "-", "_", "."'
|
|
63
|
+
);
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
this.collectionVariables[key] = value;
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
getVar(key) {
|
|
70
|
+
if (variableNameRegex.test(key) === false) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Variable name: "${key}" contains invalid characters!` +
|
|
73
|
+
' Names must only contain alpha-numeric characters, "-", "_", "."'
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
66
77
|
return this.collectionVariables[key];
|
|
67
78
|
}
|
|
68
79
|
}
|
package/src/bruno-response.js
CHANGED
|
@@ -5,6 +5,7 @@ class BrunoResponse {
|
|
|
5
5
|
this.statusText = res ? res.statusText : null;
|
|
6
6
|
this.headers = res ? res.headers : null;
|
|
7
7
|
this.body = res ? res.data : null;
|
|
8
|
+
this.responseTime = res ? res.responseTime : null;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
getStatus() {
|
|
@@ -22,6 +23,10 @@ class BrunoResponse {
|
|
|
22
23
|
getBody() {
|
|
23
24
|
return this.res ? this.res.data : null;
|
|
24
25
|
}
|
|
26
|
+
|
|
27
|
+
getResponseTime() {
|
|
28
|
+
return this.res ? this.res.responseTime : null;
|
|
29
|
+
}
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
module.exports = BrunoResponse;
|
|
@@ -26,6 +26,7 @@ const axios = require('axios');
|
|
|
26
26
|
const fetch = require('node-fetch');
|
|
27
27
|
const chai = require('chai');
|
|
28
28
|
const CryptoJS = require('crypto-js');
|
|
29
|
+
const NodeVault = require('node-vault');
|
|
29
30
|
|
|
30
31
|
class ScriptRuntime {
|
|
31
32
|
constructor() {}
|
|
@@ -46,6 +47,11 @@ class ScriptRuntime {
|
|
|
46
47
|
const req = new BrunoRequest(request);
|
|
47
48
|
const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false);
|
|
48
49
|
const moduleWhitelist = get(scriptingConfig, 'moduleWhitelist', []);
|
|
50
|
+
const additionalContextRoots = get(scriptingConfig, 'additionalContextRoots', []);
|
|
51
|
+
const additionalContextRootsAbsolute = lodash
|
|
52
|
+
.chain(additionalContextRoots)
|
|
53
|
+
.map((acr) => (acr.startsWith('/') ? acr : path.join(collectionPath, acr)))
|
|
54
|
+
.value();
|
|
49
55
|
|
|
50
56
|
const whitelistedModules = {};
|
|
51
57
|
|
|
@@ -83,7 +89,7 @@ class ScriptRuntime {
|
|
|
83
89
|
require: {
|
|
84
90
|
context: 'sandbox',
|
|
85
91
|
external: true,
|
|
86
|
-
root: [collectionPath],
|
|
92
|
+
root: [collectionPath, ...additionalContextRootsAbsolute],
|
|
87
93
|
mock: {
|
|
88
94
|
// node libs
|
|
89
95
|
path,
|
|
@@ -107,7 +113,8 @@ class ScriptRuntime {
|
|
|
107
113
|
'node-fetch': fetch,
|
|
108
114
|
'crypto-js': CryptoJS,
|
|
109
115
|
...whitelistedModules,
|
|
110
|
-
fs: allowScriptFilesystemAccess ? fs : undefined
|
|
116
|
+
fs: allowScriptFilesystemAccess ? fs : undefined,
|
|
117
|
+
'node-vault': NodeVault
|
|
111
118
|
}
|
|
112
119
|
}
|
|
113
120
|
});
|
|
@@ -196,7 +203,8 @@ class ScriptRuntime {
|
|
|
196
203
|
'node-fetch': fetch,
|
|
197
204
|
'crypto-js': CryptoJS,
|
|
198
205
|
...whitelistedModules,
|
|
199
|
-
fs: allowScriptFilesystemAccess ? fs : undefined
|
|
206
|
+
fs: allowScriptFilesystemAccess ? fs : undefined,
|
|
207
|
+
'node-vault': NodeVault
|
|
200
208
|
}
|
|
201
209
|
}
|
|
202
210
|
});
|
|
@@ -28,6 +28,7 @@ const nanoid = require('nanoid');
|
|
|
28
28
|
const axios = require('axios');
|
|
29
29
|
const fetch = require('node-fetch');
|
|
30
30
|
const CryptoJS = require('crypto-js');
|
|
31
|
+
const NodeVault = require('node-vault');
|
|
31
32
|
|
|
32
33
|
class TestRuntime {
|
|
33
34
|
constructor() {}
|
|
@@ -48,6 +49,11 @@ class TestRuntime {
|
|
|
48
49
|
const res = new BrunoResponse(response);
|
|
49
50
|
const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false);
|
|
50
51
|
const moduleWhitelist = get(scriptingConfig, 'moduleWhitelist', []);
|
|
52
|
+
const additionalContextRoots = get(scriptingConfig, 'additionalContextRoots', []);
|
|
53
|
+
const additionalContextRootsAbsolute = lodash
|
|
54
|
+
.chain(additionalContextRoots)
|
|
55
|
+
.map((acr) => (acr.startsWith('/') ? acr : path.join(collectionPath, acr)))
|
|
56
|
+
.value();
|
|
51
57
|
|
|
52
58
|
const whitelistedModules = {};
|
|
53
59
|
|
|
@@ -101,7 +107,7 @@ class TestRuntime {
|
|
|
101
107
|
require: {
|
|
102
108
|
context: 'sandbox',
|
|
103
109
|
external: true,
|
|
104
|
-
root: [collectionPath],
|
|
110
|
+
root: [collectionPath, ...additionalContextRootsAbsolute],
|
|
105
111
|
mock: {
|
|
106
112
|
// node libs
|
|
107
113
|
path,
|
|
@@ -125,7 +131,8 @@ class TestRuntime {
|
|
|
125
131
|
'node-fetch': fetch,
|
|
126
132
|
'crypto-js': CryptoJS,
|
|
127
133
|
...whitelistedModules,
|
|
128
|
-
fs: allowScriptFilesystemAccess ? fs : undefined
|
|
134
|
+
fs: allowScriptFilesystemAccess ? fs : undefined,
|
|
135
|
+
'node-vault': NodeVault
|
|
129
136
|
}
|
|
130
137
|
}
|
|
131
138
|
});
|
package/src/utils.js
CHANGED
|
@@ -109,6 +109,7 @@ const createResponseParser = (response = {}) => {
|
|
|
109
109
|
res.statusText = response.statusText;
|
|
110
110
|
res.headers = response.headers;
|
|
111
111
|
res.body = response.data;
|
|
112
|
+
res.responseTime = response.responseTime;
|
|
112
113
|
|
|
113
114
|
res.jq = (expr) => {
|
|
114
115
|
const output = jsonQuery(expr, { data: response.data });
|