@usebruno/js 0.39.0 → 0.41.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.39.0",
3
+ "version": "0.41.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.12.1",
19
+ "@usebruno/common": "0.14.0",
20
20
  "@usebruno/query": "0.1.0",
21
21
  "ajv": "^8.12.0",
22
22
  "ajv-formats": "^2.1.1",
@@ -28,6 +28,7 @@
28
28
  "cheerio": "^1.0.0",
29
29
  "crypto-js": "^4.2.0",
30
30
  "json-query": "^2.2.2",
31
+ "jsonwebtoken": "^9.0.2",
31
32
  "lodash": "^4.17.21",
32
33
  "moment": "^2.29.4",
33
34
  "nanoid": "3.3.8",
@@ -37,6 +38,7 @@
37
38
  "quickjs-emscripten": "^0.29.2",
38
39
  "tv4": "^1.3.0",
39
40
  "uuid": "^9.0.0",
41
+ "xml-formatter": "^3.5.0",
40
42
  "xml2js": "^0.6.2"
41
43
  },
42
44
  "devDependencies": {
package/src/bru.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const { cloneDeep } = require('lodash');
2
2
  const { uuid } = require('./utils');
3
+ const xmlFormat = require('xml-formatter');
3
4
  const { interpolate: _interpolate } = require('@usebruno/common');
4
5
  const { sendRequest } = require('@usebruno/requests').scripting;
5
6
  const { jar: createCookieJar } = require('@usebruno/requests').cookies;
@@ -82,6 +83,49 @@ class Bru {
82
83
  totalIterations: iterationDetails?.totalIterations
83
84
  };
84
85
 
86
+ this.utils = {
87
+ minifyJson: (json) => {
88
+ if (json === null || json === undefined) {
89
+ throw new Error('Failed to minify');
90
+ }
91
+
92
+ if (typeof json === 'object') {
93
+ try {
94
+ return JSON.stringify(json);
95
+ } catch (err) {
96
+ throw new Error(`Failed to minify: ${err?.message || err}`);
97
+ }
98
+ }
99
+
100
+ if (typeof json === 'string') {
101
+ const trimmed = json.trim();
102
+ if (trimmed === '') return trimmed;
103
+ try {
104
+ return JSON.stringify(JSON.parse(trimmed));
105
+ } catch (err) {
106
+ throw new Error(`Failed to minify: ${err?.message || err}`);
107
+ }
108
+ }
109
+
110
+ throw new TypeError('minifyJson expects a string or object');
111
+ },
112
+
113
+ minifyXml: (xml) => {
114
+ if (xml === null || xml === undefined) {
115
+ throw new Error('Failed to minify');
116
+ }
117
+
118
+ if (typeof xml === 'string') {
119
+ try {
120
+ return xmlFormat(xml, { collapseContent: false, indentation: '', lineSeparator: '' });
121
+ } catch (err) {
122
+ throw new Error(`Failed to minify: ${err?.message || err}`);
123
+ }
124
+ }
125
+
126
+ throw new TypeError('minifyXml expects a string');
127
+ }
128
+ };
85
129
  }
86
130
 
87
131
 
@@ -205,12 +249,12 @@ class Bru {
205
249
  this.historyLogger({
206
250
  uid: uuid(),
207
251
  type: 'setVar()',
208
- data: { key, value },
252
+ data: { key, value: this.interpolate(value) },
209
253
  createdAt: new Date().toISOString()
210
254
  });
211
255
  }
212
256
 
213
- this.runtimeVariables[key] = value;
257
+ this.runtimeVariables[key] = this.interpolate(value);
214
258
  }
215
259
 
216
260
  getVar(key) {
@@ -22,6 +22,7 @@ class BrunoRequest {
22
22
  this.timeout = req.timeout;
23
23
  this.historyLogger = historyLogger;
24
24
  this.name = req.name;
25
+ this.tags = req.tags || [];
25
26
  /**
26
27
  * We automatically parse the JSON body if the content type is JSON
27
28
  * This is to make it easier for the user to access the body directly
@@ -210,6 +211,14 @@ class BrunoRequest {
210
211
  getName() {
211
212
  return this.req.name;
212
213
  }
214
+
215
+ /**
216
+ * Get the tags associated with this request
217
+ * @returns {Array<string>} Array of tag strings
218
+ */
219
+ getTags() {
220
+ return this.req.tags || [];
221
+ }
213
222
  }
214
223
 
215
224
  module.exports = BrunoRequest;
@@ -33,7 +33,9 @@ const NodeVault = require('node-vault');
33
33
  const xml2js = require('xml2js');
34
34
  const cheerio = require('cheerio');
35
35
  const tv4 = require('tv4');
36
+ const jsonwebtoken = require('jsonwebtoken');
36
37
  const { executeQuickJsVmAsync } = require('../sandbox/quickjs');
38
+ const { mixinTypedArrays } = require('../sandbox/mixins/typed-arrays');
37
39
 
38
40
  class ScriptRuntime {
39
41
  constructor(props) {
@@ -101,6 +103,10 @@ class ScriptRuntime {
101
103
  __brunoTestResults: __brunoTestResults
102
104
  };
103
105
 
106
+ if (this.runtime === 'vm2') {
107
+ mixinTypedArrays(context);
108
+ }
109
+
104
110
  if (onConsoleLog && typeof onConsoleLog === 'function') {
105
111
  const customLogger = (type) => {
106
112
  return (...args) => {
@@ -195,6 +201,7 @@ class ScriptRuntime {
195
201
  'node-fetch': fetch,
196
202
  'crypto-js': CryptoJS,
197
203
  xml2js: xml2js,
204
+ jsonwebtoken,
198
205
  cheerio,
199
206
  tv4,
200
207
  ...whitelistedModules,
@@ -281,6 +288,10 @@ class ScriptRuntime {
281
288
  __brunoTestResults: __brunoTestResults
282
289
  };
283
290
 
291
+ if (this.runtime === 'vm2') {
292
+ mixinTypedArrays(context);
293
+ }
294
+
284
295
  if (onConsoleLog && typeof onConsoleLog === 'function') {
285
296
  const customLogger = (type) => {
286
297
  return (...args) => {
@@ -374,6 +385,7 @@ class ScriptRuntime {
374
385
  'node-fetch': fetch,
375
386
  'crypto-js': CryptoJS,
376
387
  'xml2js': xml2js,
388
+ jsonwebtoken,
377
389
  cheerio,
378
390
  tv4,
379
391
  ...whitelistedModules,
@@ -35,7 +35,9 @@ const NodeVault = require('node-vault');
35
35
  const xml2js = require('xml2js');
36
36
  const cheerio = require('cheerio');
37
37
  const tv4 = require('tv4');
38
+ const jsonwebtoken = require('jsonwebtoken');
38
39
  const { executeQuickJsVmAsync } = require('../sandbox/quickjs');
40
+ const { mixinTypedArrays } = require('../sandbox/mixins/typed-arrays');
39
41
 
40
42
  class TestRuntime {
41
43
  constructor(props) {
@@ -107,9 +109,14 @@ class TestRuntime {
107
109
  res,
108
110
  expect: chai.expect,
109
111
  assert: chai.assert,
110
- __brunoTestResults: __brunoTestResults
112
+ __brunoTestResults: __brunoTestResults,
113
+ jwt: jsonwebtoken
111
114
  };
112
115
 
116
+ if (this.runtime === 'vm2') {
117
+ mixinTypedArrays(context);
118
+ }
119
+
113
120
  if (onConsoleLog && typeof onConsoleLog === 'function') {
114
121
  const customLogger = (type) => {
115
122
  return (...args) => {
@@ -180,6 +187,7 @@ class TestRuntime {
180
187
  'xml2js': xml2js,
181
188
  cheerio,
182
189
  tv4,
190
+ 'jsonwebtoken': jsonwebtoken,
183
191
  ...whitelistedModules,
184
192
  fs: allowScriptFilesystemAccess ? fs : undefined,
185
193
  'node-vault': NodeVault