@usebruno/js 0.24.0 → 0.26.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.26.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"ajv": "^8.12.0",
|
|
22
22
|
"ajv-formats": "^2.1.1",
|
|
23
23
|
"atob": "^2.1.2",
|
|
24
|
-
"axios": "1.
|
|
24
|
+
"axios": "^1.8.3",
|
|
25
25
|
"btoa": "^1.2.1",
|
|
26
26
|
"chai": "^4.3.7",
|
|
27
27
|
"chai-string": "^1.5.0",
|
|
28
|
+
"cheerio": "^1.0.0",
|
|
28
29
|
"crypto-js": "^4.1.1",
|
|
29
30
|
"json-query": "^2.2.2",
|
|
30
31
|
"lodash": "^4.17.21",
|
|
@@ -34,7 +35,8 @@
|
|
|
34
35
|
"node-vault": "^0.10.2",
|
|
35
36
|
"path": "^0.12.7",
|
|
36
37
|
"quickjs-emscripten": "^0.29.2",
|
|
37
|
-
"uuid": "^9.0.0"
|
|
38
|
+
"uuid": "^9.0.0",
|
|
39
|
+
"xml2js": "^0.6.2"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@rollup/plugin-commonjs": "^23.0.2",
|
package/src/bruno-response.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { get } = require('@usebruno/query');
|
|
2
|
+
|
|
1
3
|
class BrunoResponse {
|
|
2
4
|
constructor(res) {
|
|
3
5
|
this.res = res;
|
|
@@ -6,12 +8,23 @@ class BrunoResponse {
|
|
|
6
8
|
this.headers = res ? res.headers : null;
|
|
7
9
|
this.body = res ? res.data : null;
|
|
8
10
|
this.responseTime = res ? res.responseTime : null;
|
|
11
|
+
|
|
12
|
+
// Make the instance callable
|
|
13
|
+
const callable = (...args) => get(this.body, ...args);
|
|
14
|
+
Object.setPrototypeOf(callable, this.constructor.prototype);
|
|
15
|
+
Object.assign(callable, this);
|
|
16
|
+
|
|
17
|
+
return callable;
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
getStatus() {
|
|
12
21
|
return this.res ? this.res.status : null;
|
|
13
22
|
}
|
|
14
23
|
|
|
24
|
+
getStatusText() {
|
|
25
|
+
return this.res ? this.res.statusText : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
15
28
|
getHeader(name) {
|
|
16
29
|
return this.res && this.res.headers ? this.res.headers[name] : null;
|
|
17
30
|
}
|
|
@@ -28,6 +28,8 @@ const fetch = require('node-fetch');
|
|
|
28
28
|
const chai = require('chai');
|
|
29
29
|
const CryptoJS = require('crypto-js');
|
|
30
30
|
const NodeVault = require('node-vault');
|
|
31
|
+
const xml2js = require('xml2js');
|
|
32
|
+
const cheerio = require('cheerio');
|
|
31
33
|
const { executeQuickJsVmAsync } = require('../sandbox/quickjs');
|
|
32
34
|
|
|
33
35
|
class ScriptRuntime {
|
|
@@ -152,6 +154,8 @@ class ScriptRuntime {
|
|
|
152
154
|
chai,
|
|
153
155
|
'node-fetch': fetch,
|
|
154
156
|
'crypto-js': CryptoJS,
|
|
157
|
+
'xml2js': xml2js,
|
|
158
|
+
cheerio,
|
|
155
159
|
...whitelistedModules,
|
|
156
160
|
fs: allowScriptFilesystemAccess ? fs : undefined,
|
|
157
161
|
'node-vault': NodeVault
|
|
@@ -30,6 +30,8 @@ const axios = require('axios');
|
|
|
30
30
|
const fetch = require('node-fetch');
|
|
31
31
|
const CryptoJS = require('crypto-js');
|
|
32
32
|
const NodeVault = require('node-vault');
|
|
33
|
+
const xml2js = require('xml2js');
|
|
34
|
+
const cheerio = require('cheerio');
|
|
33
35
|
const { executeQuickJsVmAsync } = require('../sandbox/quickjs');
|
|
34
36
|
|
|
35
37
|
const getResultsSummary = (results) => {
|
|
@@ -207,6 +209,8 @@ class TestRuntime {
|
|
|
207
209
|
chai,
|
|
208
210
|
'node-fetch': fetch,
|
|
209
211
|
'crypto-js': CryptoJS,
|
|
212
|
+
'xml2js': xml2js,
|
|
213
|
+
cheerio,
|
|
210
214
|
...whitelistedModules,
|
|
211
215
|
fs: allowScriptFilesystemAccess ? fs : undefined,
|
|
212
216
|
'node-vault': NodeVault
|
|
@@ -35,16 +35,25 @@ const executeQuickJsVm = ({ script: externalScript, context: externalContext, sc
|
|
|
35
35
|
}
|
|
36
36
|
externalScript = externalScript?.trim();
|
|
37
37
|
|
|
38
|
-
if
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if(scriptType === 'template-literal') {
|
|
39
|
+
if (!isNaN(Number(externalScript))) {
|
|
40
|
+
const number = Number(externalScript);
|
|
41
|
+
|
|
42
|
+
// Check if the number is too high. Too high number might get altered, see #1000
|
|
43
|
+
if (number > Number.MAX_SAFE_INTEGER) {
|
|
44
|
+
return externalScript;
|
|
45
|
+
}
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (externalScript === 'null') return null;
|
|
45
|
-
if (externalScript === 'undefined') return undefined;
|
|
47
|
+
return toNumber(externalScript);
|
|
48
|
+
}
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
if (externalScript === 'true') return true;
|
|
51
|
+
if (externalScript === 'false') return false;
|
|
52
|
+
if (externalScript === 'null') return null;
|
|
53
|
+
if (externalScript === 'undefined') return undefined;
|
|
54
|
+
|
|
55
|
+
externalScript = removeQuotes(externalScript);
|
|
56
|
+
}
|
|
48
57
|
|
|
49
58
|
const vm = QuickJSSyncContext;
|
|
50
59
|
|
|
@@ -85,17 +94,6 @@ const executeQuickJsVmAsync = async ({ script: externalScript, context: external
|
|
|
85
94
|
}
|
|
86
95
|
externalScript = externalScript?.trim();
|
|
87
96
|
|
|
88
|
-
if (!isNaN(Number(externalScript))) {
|
|
89
|
-
return toNumber(externalScript);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (externalScript === 'true') return true;
|
|
93
|
-
if (externalScript === 'false') return false;
|
|
94
|
-
if (externalScript === 'null') return null;
|
|
95
|
-
if (externalScript === 'undefined') return undefined;
|
|
96
|
-
|
|
97
|
-
externalScript = removeQuotes(externalScript);
|
|
98
|
-
|
|
99
97
|
try {
|
|
100
98
|
const module = await newQuickJSWASMModule();
|
|
101
99
|
const vm = module.newContext();
|
|
@@ -189,8 +189,8 @@ const addBruShimToContext = (vm, bru) => {
|
|
|
189
189
|
const promise = vm.newPromise();
|
|
190
190
|
bru.runRequest(vm.dump(args))
|
|
191
191
|
.then((response) => {
|
|
192
|
-
const { status, headers, data, dataBuffer, size } = response || {};
|
|
193
|
-
promise.resolve(marshallToVm(cleanJson({ status, headers, data, dataBuffer, size }), vm));
|
|
192
|
+
const { status, headers, data, dataBuffer, size, statusText } = response || {};
|
|
193
|
+
promise.resolve(marshallToVm(cleanJson({ status, statusText, headers, data, dataBuffer, size }), vm));
|
|
194
194
|
})
|
|
195
195
|
.catch((err) => {
|
|
196
196
|
promise.resolve(
|
|
@@ -6,11 +6,13 @@ const addBrunoResponseShimToContext = (vm, res) => {
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
const status = marshallToVm(res?.status, vm);
|
|
9
|
+
const statusText = marshallToVm(res?.statusText, vm);
|
|
9
10
|
const headers = marshallToVm(res?.headers, vm);
|
|
10
11
|
const body = marshallToVm(res?.body, vm);
|
|
11
12
|
const responseTime = marshallToVm(res?.responseTime, vm);
|
|
12
13
|
|
|
13
14
|
vm.setProp(resFn, 'status', status);
|
|
15
|
+
vm.setProp(resFn, 'statusText', statusText);
|
|
14
16
|
vm.setProp(resFn, 'headers', headers);
|
|
15
17
|
vm.setProp(resFn, 'body', body);
|
|
16
18
|
vm.setProp(resFn, 'responseTime', responseTime);
|
|
@@ -19,6 +21,13 @@ const addBrunoResponseShimToContext = (vm, res) => {
|
|
|
19
21
|
headers.dispose();
|
|
20
22
|
body.dispose();
|
|
21
23
|
responseTime.dispose();
|
|
24
|
+
statusText.dispose();
|
|
25
|
+
|
|
26
|
+
let getStatusText = vm.newFunction('getStatusText', function () {
|
|
27
|
+
return marshallToVm(res.getStatusText(), vm);
|
|
28
|
+
});
|
|
29
|
+
vm.setProp(resFn, 'getStatusText', getStatusText);
|
|
30
|
+
getStatusText.dispose();
|
|
22
31
|
|
|
23
32
|
let getStatus = vm.newFunction('getStatus', function () {
|
|
24
33
|
return marshallToVm(res.getStatus(), vm);
|