@usebruno/js 0.36.0 → 0.37.0
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usebruno/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"prepack": "npm run test"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@usebruno/common": "0.
|
|
19
|
+
"@usebruno/common": "0.11.0",
|
|
20
20
|
"@usebruno/crypto-js": "^3.1.9",
|
|
21
21
|
"@usebruno/query": "0.1.0",
|
|
22
22
|
"ajv": "^8.12.0",
|
|
@@ -44,8 +44,6 @@
|
|
|
44
44
|
"@rollup/plugin-commonjs": "^23.0.2",
|
|
45
45
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
46
46
|
"rollup": "3.29.5",
|
|
47
|
-
"rollup-plugin-terser": "^7.0.2"
|
|
48
|
-
"stream": "^0.0.2",
|
|
49
|
-
"util": "^0.12.5"
|
|
47
|
+
"rollup-plugin-terser": "^7.0.2"
|
|
50
48
|
}
|
|
51
|
-
}
|
|
49
|
+
}
|
package/src/bru.js
CHANGED
|
@@ -2,7 +2,7 @@ const { cloneDeep } = require('lodash');
|
|
|
2
2
|
const { uuid } = require('./utils');
|
|
3
3
|
const { interpolate: _interpolate } = require('@usebruno/common');
|
|
4
4
|
const { sendRequest } = require('@usebruno/requests').scripting;
|
|
5
|
-
const { jar: createCookieJar } = require('@usebruno/
|
|
5
|
+
const { jar: createCookieJar } = require('@usebruno/requests').cookies;
|
|
6
6
|
|
|
7
7
|
const variableNameRegex = /^[\w-.]*$/;
|
|
8
8
|
|
|
@@ -22,7 +22,6 @@ class Bru {
|
|
|
22
22
|
this.setVisualizations = setVisualizations;
|
|
23
23
|
this.collectionName = collectionName;
|
|
24
24
|
this.sendRequest = sendRequest;
|
|
25
|
-
|
|
26
25
|
this.cookies = {
|
|
27
26
|
jar: () => {
|
|
28
27
|
const cookieJar = createCookieJar();
|
|
@@ -66,6 +65,8 @@ class Bru {
|
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
67
|
};
|
|
68
|
+
// Holds variables that are marked as persistent by scripts
|
|
69
|
+
this.persistentEnvVariables = {};
|
|
69
70
|
this.runner = {
|
|
70
71
|
skipRequest: () => {
|
|
71
72
|
this.skipRequest = true;
|
|
@@ -128,10 +129,21 @@ class Bru {
|
|
|
128
129
|
return this.interpolate(this.envVariables[key]);
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
setEnvVar(key, value) {
|
|
132
|
+
setEnvVar(key, value, options = {}) {
|
|
132
133
|
if (!key) {
|
|
133
134
|
throw new Error('Creating a env variable without specifying a name is not allowed.');
|
|
134
135
|
}
|
|
136
|
+
|
|
137
|
+
if (variableNameRegex.test(key) === false) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`Variable name: "${key}" contains invalid characters! Names must only contain alpha-numeric characters, "-", "_", "."`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// When persist is true, only string values are allowed
|
|
144
|
+
if (options?.persist && typeof value !== 'string') {
|
|
145
|
+
throw new Error(`Persistent environment variables must be strings. Received ${typeof value} for key "${key}".`);
|
|
146
|
+
}
|
|
135
147
|
|
|
136
148
|
if (this.historyLogger) {
|
|
137
149
|
this.historyLogger({
|
|
@@ -143,6 +155,14 @@ class Bru {
|
|
|
143
155
|
}
|
|
144
156
|
|
|
145
157
|
this.envVariables[key] = value;
|
|
158
|
+
|
|
159
|
+
if (options?.persist) {
|
|
160
|
+
this.persistentEnvVariables[key] = value;
|
|
161
|
+
} else {
|
|
162
|
+
if (this.persistentEnvVariables[key]) {
|
|
163
|
+
delete this.persistentEnvVariables[key];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
146
166
|
}
|
|
147
167
|
|
|
148
168
|
deleteEnvVar(key) {
|
|
@@ -131,6 +131,7 @@ class ScriptRuntime {
|
|
|
131
131
|
envVariables: cleanJson(envVariables),
|
|
132
132
|
runtimeVariables: cleanJson(runtimeVariables),
|
|
133
133
|
visualizations,
|
|
134
|
+
persistentEnvVariables: bru.persistentEnvVariables,
|
|
134
135
|
globalEnvironmentVariables: cleanJson(globalEnvironmentVariables),
|
|
135
136
|
results: cleanJson(__brunoTestResults.getResults()),
|
|
136
137
|
nextRequestName: bru.nextRequest,
|
|
@@ -187,6 +188,7 @@ class ScriptRuntime {
|
|
|
187
188
|
envVariables: cleanJson(envVariables),
|
|
188
189
|
runtimeVariables: cleanJson(runtimeVariables),
|
|
189
190
|
visualizations,
|
|
191
|
+
persistentEnvVariables: bru.persistentEnvVariables,
|
|
190
192
|
globalEnvironmentVariables: cleanJson(globalEnvironmentVariables),
|
|
191
193
|
results: cleanJson(__brunoTestResults.getResults()),
|
|
192
194
|
nextRequestName: bru.nextRequest,
|
|
@@ -285,6 +287,7 @@ class ScriptRuntime {
|
|
|
285
287
|
return {
|
|
286
288
|
response,
|
|
287
289
|
envVariables: cleanJson(envVariables),
|
|
290
|
+
persistentEnvVariables: cleanJson(bru.persistentEnvVariables),
|
|
288
291
|
runtimeVariables: cleanJson(runtimeVariables),
|
|
289
292
|
visualizations,
|
|
290
293
|
globalEnvironmentVariables: cleanJson(globalEnvironmentVariables),
|
|
@@ -341,6 +344,7 @@ class ScriptRuntime {
|
|
|
341
344
|
return {
|
|
342
345
|
response,
|
|
343
346
|
envVariables: cleanJson(envVariables),
|
|
347
|
+
persistentEnvVariables: cleanJson(bru.persistentEnvVariables),
|
|
344
348
|
runtimeVariables: cleanJson(runtimeVariables),
|
|
345
349
|
visualizations,
|
|
346
350
|
globalEnvironmentVariables: cleanJson(globalEnvironmentVariables),
|
|
@@ -197,6 +197,7 @@ class TestRuntime {
|
|
|
197
197
|
envVariables: cleanJson(envVariables),
|
|
198
198
|
runtimeVariables: cleanJson(runtimeVariables),
|
|
199
199
|
globalEnvironmentVariables: cleanJson(globalEnvironmentVariables),
|
|
200
|
+
persistentEnvVariables: cleanJson(bru.persistentEnvVariables),
|
|
200
201
|
results: cleanJson(__brunoTestResults.getResults()),
|
|
201
202
|
nextRequestName: bru.nextRequest
|
|
202
203
|
};
|
|
@@ -48,8 +48,8 @@ const addBruShimToContext = (vm, bru) => {
|
|
|
48
48
|
vm.setProp(bruObject, 'getEnvVar', getEnvVar);
|
|
49
49
|
getEnvVar.dispose();
|
|
50
50
|
|
|
51
|
-
let setEnvVar = vm.newFunction('setEnvVar', function (key, value) {
|
|
52
|
-
bru.setEnvVar(vm.dump(key), vm.dump(value));
|
|
51
|
+
let setEnvVar = vm.newFunction('setEnvVar', function (key, value, options = {}) {
|
|
52
|
+
bru.setEnvVar(vm.dump(key), vm.dump(value), vm.dump(options));
|
|
53
53
|
});
|
|
54
54
|
vm.setProp(bruObject, 'setEnvVar', setEnvVar);
|
|
55
55
|
setEnvVar.dispose();
|