@usebruno/js 0.9.2 → 0.9.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/package.json +1 -1
- package/src/bru.js +11 -12
- package/src/bruno-response.js +5 -0
- package/src/runtime/script-runtime.js +4 -2
- package/src/utils.js +1 -0
package/package.json
CHANGED
package/src/bru.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const Handlebars = require('handlebars');
|
|
2
2
|
const { cloneDeep } = require('lodash');
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const variableNameRegex = /^[\w-.]*$/;
|
|
5
5
|
|
|
6
6
|
class Bru {
|
|
7
7
|
constructor(envVariables, collectionVariables, processEnvVars, collectionPath) {
|
|
@@ -45,12 +45,7 @@ class Bru {
|
|
|
45
45
|
|
|
46
46
|
setEnvVar(key, value) {
|
|
47
47
|
if (!key) {
|
|
48
|
-
throw new Error('
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// gracefully ignore if key is not present in environment
|
|
52
|
-
if (!this.envVariables.hasOwnProperty(key)) {
|
|
53
|
-
return;
|
|
48
|
+
throw new Error('Creating a env variable without specifying a name is not allowed.');
|
|
54
49
|
}
|
|
55
50
|
|
|
56
51
|
this.envVariables[key] = value;
|
|
@@ -58,13 +53,13 @@ class Bru {
|
|
|
58
53
|
|
|
59
54
|
setVar(key, value) {
|
|
60
55
|
if (!key) {
|
|
61
|
-
throw new Error('
|
|
56
|
+
throw new Error('Creating a variable without specifying a name is not allowed.');
|
|
62
57
|
}
|
|
63
58
|
|
|
64
|
-
if (
|
|
59
|
+
if (variableNameRegex.test(key) === false) {
|
|
65
60
|
throw new Error(
|
|
66
61
|
`Variable name: "${key}" contains invalid characters!` +
|
|
67
|
-
' Names must only contain alpha-numeric characters, "-", "_"
|
|
62
|
+
' Names must only contain alpha-numeric characters, "-", "_", "."'
|
|
68
63
|
);
|
|
69
64
|
}
|
|
70
65
|
|
|
@@ -72,15 +67,19 @@ class Bru {
|
|
|
72
67
|
}
|
|
73
68
|
|
|
74
69
|
getVar(key) {
|
|
75
|
-
if (
|
|
70
|
+
if (variableNameRegex.test(key) === false) {
|
|
76
71
|
throw new Error(
|
|
77
72
|
`Variable name: "${key}" contains invalid characters!` +
|
|
78
|
-
' Names must only contain alpha-numeric characters
|
|
73
|
+
' Names must only contain alpha-numeric characters, "-", "_", "."'
|
|
79
74
|
);
|
|
80
75
|
}
|
|
81
76
|
|
|
82
77
|
return this.collectionVariables[key];
|
|
83
78
|
}
|
|
79
|
+
|
|
80
|
+
setNextRequest(nextRequest) {
|
|
81
|
+
this.nextRequest = nextRequest;
|
|
82
|
+
}
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
module.exports = Bru;
|
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;
|
|
@@ -123,7 +123,8 @@ class ScriptRuntime {
|
|
|
123
123
|
return {
|
|
124
124
|
request,
|
|
125
125
|
envVariables: cleanJson(envVariables),
|
|
126
|
-
collectionVariables: cleanJson(collectionVariables)
|
|
126
|
+
collectionVariables: cleanJson(collectionVariables),
|
|
127
|
+
nextRequestName: bru.nextRequest
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
130
|
|
|
@@ -215,7 +216,8 @@ class ScriptRuntime {
|
|
|
215
216
|
return {
|
|
216
217
|
response,
|
|
217
218
|
envVariables: cleanJson(envVariables),
|
|
218
|
-
collectionVariables: cleanJson(collectionVariables)
|
|
219
|
+
collectionVariables: cleanJson(collectionVariables),
|
|
220
|
+
nextRequestName: bru.nextRequest
|
|
219
221
|
};
|
|
220
222
|
}
|
|
221
223
|
}
|
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 });
|