postman-runtime 7.28.4 → 7.29.2

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.
Files changed (44) hide show
  1. package/CHANGELOG.yaml +26 -0
  2. package/README.md +3 -7
  3. package/dist/index.js +1 -1
  4. package/lib/authorizer/apikey.js +12 -11
  5. package/lib/authorizer/auth-interface.js +6 -6
  6. package/lib/authorizer/aws4.js +20 -20
  7. package/lib/authorizer/basic.js +12 -12
  8. package/lib/authorizer/bearer.js +12 -12
  9. package/lib/authorizer/digest.js +32 -31
  10. package/lib/authorizer/edgegrid.js +7 -7
  11. package/lib/authorizer/hawk.js +20 -20
  12. package/lib/authorizer/index.js +12 -8
  13. package/lib/authorizer/noauth.js +11 -11
  14. package/lib/authorizer/ntlm.js +21 -20
  15. package/lib/authorizer/oauth1.js +21 -21
  16. package/lib/authorizer/oauth2.js +12 -12
  17. package/lib/backpack/index.js +19 -19
  18. package/lib/requester/core-body-builder.js +16 -16
  19. package/lib/requester/core.js +25 -20
  20. package/lib/requester/dry-run.js +21 -21
  21. package/lib/requester/request-wrapper.js +6 -6
  22. package/lib/requester/requester-pool.js +1 -0
  23. package/lib/requester/requester.js +38 -43
  24. package/lib/runner/create-item-context.js +6 -6
  25. package/lib/runner/cursor.js +63 -63
  26. package/lib/runner/extensions/control.command.js +15 -14
  27. package/lib/runner/extensions/delay.command.js +12 -12
  28. package/lib/runner/extensions/event.command.js +33 -27
  29. package/lib/runner/extensions/http-request.command.js +20 -23
  30. package/lib/runner/extensions/item.command.js +6 -5
  31. package/lib/runner/extensions/request.command.js +12 -12
  32. package/lib/runner/extensions/waterfall.command.js +6 -6
  33. package/lib/runner/extract-runnable-items.js +25 -25
  34. package/lib/runner/index.js +20 -21
  35. package/lib/runner/instruction.js +11 -11
  36. package/lib/runner/replay-controller.js +6 -6
  37. package/lib/runner/request-helpers-postsend.js +5 -6
  38. package/lib/runner/request-helpers-presend.js +12 -16
  39. package/lib/runner/run.js +46 -41
  40. package/lib/runner/timings.js +7 -3
  41. package/lib/runner/util.js +10 -9
  42. package/lib/version.js +2 -2
  43. package/lib/visualizer/index.js +1 -1
  44. package/package.json +70 -74
@@ -1,8 +1,9 @@
1
+ /* eslint-disable jsdoc/require-param-type,jsdoc/require-param-description */
1
2
  var dns = require('dns'),
2
3
  constants = require('constants'),
3
4
 
4
5
  _ = require('lodash'),
5
- uuid = require('uuid/v4'),
6
+ uuid = require('uuid'),
6
7
  sdk = require('postman-collection'),
7
8
  urlEncoder = require('postman-url-encoder'),
8
9
 
@@ -69,6 +70,10 @@ var dns = require('dns'),
69
70
  followRedirect: 'followRedirects',
70
71
  followAllRedirects: 'followRedirects',
71
72
 
73
+ // Use an insecure HTTP parser that accepts invalid HTTP headers
74
+ // Refer: https://nodejs.org/api/cli.html#--insecure-http-parser
75
+ insecureHTTPParser: 'insecureHTTPParser',
76
+
72
77
  // retain `authorization` header when a redirect happens to a different hostname
73
78
  followAuthorizationHeader: 'followAuthorizationHeader',
74
79
 
@@ -146,13 +151,13 @@ var dns = require('dns'),
146
151
  headers = request.headers;
147
152
 
148
153
  [
149
- {key: 'User-Agent', value: `PostmanRuntime/${version}`},
150
- {key: 'Accept', value: '*/*'},
151
- {key: 'Cache-Control', value: 'no-cache'},
152
- {key: 'Postman-Token', value: uuid()},
153
- {key: 'Host', value: options.url && options.url.host},
154
- {key: 'Accept-Encoding', value: 'gzip, deflate, br'},
155
- {key: 'Connection', value: 'keep-alive'}
154
+ { key: 'User-Agent', value: `PostmanRuntime/${version}` },
155
+ { key: 'Accept', value: '*/*' },
156
+ { key: 'Cache-Control', value: 'no-cache' },
157
+ { key: 'Postman-Token', value: uuid.v4() },
158
+ { key: 'Host', value: options.url && options.url.host },
159
+ { key: 'Accept-Encoding', value: 'gzip, deflate, br' },
160
+ { key: 'Connection', value: 'keep-alive' }
156
161
  ].forEach(function (header) {
157
162
  key = header.key.toLowerCase();
158
163
 
@@ -168,7 +173,7 @@ var dns = require('dns'),
168
173
  });
169
174
 
170
175
  for (key in systemHeaders) {
171
- if (systemHeaders.hasOwnProperty(key)) {
176
+ if (Object.hasOwnProperty.call(systemHeaders, key)) {
172
177
  // upsert instead of add to replace user-defined headers also
173
178
  headers.upsert({
174
179
  key: key,
@@ -311,11 +316,11 @@ var dns = require('dns'),
311
316
  */
312
317
  urlParser = function (disableUrlEncoding) {
313
318
  return {
314
- parse: function (urlToParse) {
319
+ parse (urlToParse) {
315
320
  return urlEncoder.toNodeUrl(urlToParse, disableUrlEncoding);
316
321
  },
317
322
 
318
- resolve: function (base, relative) {
323
+ resolve (base, relative) {
319
324
  if (typeof base === STRING) {
320
325
  // @note we parse base URL here to respect `disableUrlEncoding`
321
326
  // option even though resolveNodeUrl() accepts it as a string
@@ -341,7 +346,7 @@ var dns = require('dns'),
341
346
  // bail out if property or defaultOpts is not defined
342
347
  if (!(property && defaultOpts)) { return; }
343
348
 
344
- if (protocolProfileBehavior && protocolProfileBehavior.hasOwnProperty(property)) {
349
+ if (Object.hasOwnProperty.call(protocolProfileBehavior, property)) {
345
350
  return protocolProfileBehavior[property];
346
351
  }
347
352
 
@@ -372,7 +377,7 @@ module.exports = {
372
377
  * @param protocolProfileBehavior
373
378
  * @returns {{}}
374
379
  */
375
- getRequestOptions: function (request, defaultOpts, protocolProfileBehavior) {
380
+ getRequestOptions (request, defaultOpts, protocolProfileBehavior) {
376
381
  !defaultOpts && (defaultOpts = {});
377
382
  !protocolProfileBehavior && (protocolProfileBehavior = {});
378
383
 
@@ -532,7 +537,7 @@ module.exports = {
532
537
  });
533
538
 
534
539
  // Finally, get headers object
535
- options.headers = request.getHeaders({enabled: true, sanitizeKeys: true});
540
+ options.headers = request.getHeaders({ enabled: true, sanitizeKeys: true });
536
541
 
537
542
  // override URL parser to WhatWG URL parser
538
543
  if (useWhatWGUrlParser) {
@@ -579,7 +584,7 @@ module.exports = {
579
584
  *
580
585
  * @returns {Object}
581
586
  */
582
- getRequestBody: function (request, protocolProfileBehavior) {
587
+ getRequestBody (request, protocolProfileBehavior) {
583
588
  if (!(request && request.body)) {
584
589
  return;
585
590
  }
@@ -631,7 +636,7 @@ module.exports = {
631
636
  //
632
637
  // @note if you'd like to support additional body types beyond formdata, url-encoding, etc, add the same to
633
638
  // the builder module
634
- if (!requestBodyBuilders.hasOwnProperty(requestBodyType)) {
639
+ if (!Object.hasOwnProperty.call(requestBodyBuilders, requestBodyType)) {
635
640
  return;
636
641
  }
637
642
 
@@ -646,7 +651,7 @@ module.exports = {
646
651
  * @param requestOptions Options that were used to send the request.
647
652
  * @param responseBody Body as a string.
648
653
  */
649
- jsonifyResponse: function (rawResponse, requestOptions, responseBody) {
654
+ jsonifyResponse (rawResponse, requestOptions, responseBody) {
650
655
  if (!rawResponse) {
651
656
  return;
652
657
  }
@@ -703,7 +708,7 @@ module.exports = {
703
708
  * @param {ArrayBuffer} buffer
704
709
  * @returns {String}
705
710
  */
706
- arrayBufferToString: function (buffer) {
711
+ arrayBufferToString (buffer) {
707
712
  var str = '',
708
713
  uArrayVal = new Uint8Array(buffer),
709
714
 
@@ -726,7 +731,7 @@ module.exports = {
726
731
  * @example
727
732
  * ['a', 'b', 'c', 'd'] ====> {a: 'b', c: 'd' }
728
733
  */
729
- arrayPairsToObject: function (arr) {
734
+ arrayPairsToObject (arr) {
730
735
  if (!_.isArray(arr)) {
731
736
  return;
732
737
  }
@@ -762,7 +767,7 @@ module.exports = {
762
767
  *
763
768
  * @returns {Boolean}
764
769
  */
765
- isAddressRestricted: function (host, networkOptions) {
770
+ isAddressRestricted (host, networkOptions) {
766
771
  return networkOptions.restrictedAddresses &&
767
772
  networkOptions.restrictedAddresses[(host && host.toLowerCase())];
768
773
  }
@@ -21,11 +21,11 @@ const _ = require('lodash'),
21
21
  CONTENT_TYPE_FORMDATA = 'multipart/form-data; boundary=' + CALCULATED_AT_RUNTIME,
22
22
 
23
23
  CONTENT_TYPE_LANGUAGE = {
24
- 'html': 'text/html',
25
- 'text': 'text/plain',
26
- 'json': 'application/json',
27
- 'javascript': 'application/javascript',
28
- 'xml': 'application/xml'
24
+ html: 'text/html',
25
+ text: 'text/plain',
26
+ json: 'application/json',
27
+ javascript: 'application/javascript',
28
+ xml: 'application/xml'
29
29
  },
30
30
 
31
31
  BODY_MODE = {
@@ -43,7 +43,7 @@ const _ = require('lodash'),
43
43
  * @todo Update Collection SDK isEmpty method to account for this.
44
44
  *
45
45
  * @private
46
- * @param {RequestBody} body
46
+ * @param {RequestBody} body -
47
47
  * @returns {Boolean}
48
48
  */
49
49
  function bodyIsEmpty (body) {
@@ -73,9 +73,9 @@ function bodyIsEmpty (body) {
73
73
  /**
74
74
  * Add new System header.
75
75
  *
76
- * @param {object} headers
77
- * @param {String} key
78
- * @param {String} value
76
+ * @param {object} headers -
77
+ * @param {String} key -
78
+ * @param {String} value -
79
79
  */
80
80
  function addSystemHeader (headers, key, value) {
81
81
  headers.add({
@@ -89,8 +89,8 @@ function addSystemHeader (headers, key, value) {
89
89
  * Authorize the given request.
90
90
  *
91
91
  * @private
92
- * @param {Request} request
93
- * @param {Function} callback
92
+ * @param {Request} request -
93
+ * @param {Function} callback -
94
94
  */
95
95
  function setAuthorization (request, callback) {
96
96
  authorizeRequest(request, function (err, clonedRequest) {
@@ -158,8 +158,8 @@ function setAuthorization (request, callback) {
158
158
  * Adds Content-Type header based on selected request body.
159
159
  *
160
160
  * @private
161
- * @param {Request} request
162
- * @param {Function} callback
161
+ * @param {Request} request -
162
+ * @param {Function} callback -
163
163
  */
164
164
  function setContentType (request, callback) {
165
165
  // bail out if body is empty
@@ -201,9 +201,9 @@ function setContentType (request, callback) {
201
201
  * Adds Cookie header for the given request url.
202
202
  *
203
203
  * @private
204
- * @param {Request} request
205
- * @param {Object} cookieJar
206
- * @param {Function} callback
204
+ * @param {Request} request -
205
+ * @param {Object} cookieJar -
206
+ * @param {Function} callback -
207
207
  */
208
208
  function setCookie (request, cookieJar, callback) {
209
209
  // bail out if not a valid instance of CookieJar
@@ -229,11 +229,11 @@ function setCookie (request, cookieJar, callback) {
229
229
  * A helper method to dry run the given request instance.
230
230
  * It returns the cloned request instance with the system added properties.
231
231
  *
232
- * @param {Request} request
233
- * @param {Object} options
234
- * @param {Object} options.cookieJar
235
- * @param {Object} options.protocolProfileBehavior
236
- * @param {Function} done
232
+ * @param {Request} request -
233
+ * @param {Object} options -
234
+ * @param {Object} options.cookieJar -
235
+ * @param {Object} options.protocolProfileBehavior -
236
+ * @param {Function} done -
237
237
  */
238
238
  function dryRun (request, options, done) {
239
239
  if (!done && typeof options === FUNCTION) {
@@ -5,9 +5,9 @@ var _ = require('lodash'),
5
5
  /**
6
6
  * Sets the Proxy and tunnel to the options
7
7
  *
8
- * @param request
9
- * @param options
10
- * @param cb
8
+ * @param {Object} request -
9
+ * @param {Object} options -
10
+ * @param {Function} cb -
11
11
  */
12
12
  setProxy = function (request, options, cb) {
13
13
  var proxyConfig;
@@ -35,9 +35,9 @@ var _ = require('lodash'),
35
35
  * Gets the certificate from the options.certificate
36
36
  * And appends it with the options provided
37
37
  *
38
- * @param request
39
- * @param options
40
- * @param cb
38
+ * @param {Object} request -
39
+ * @param {Object} options -
40
+ * @param {Function} cb -
41
41
  */
42
42
  setCertificate = function (request, options, cb) {
43
43
  var certificate,
@@ -26,6 +26,7 @@ RequesterPool = function (options, callback) {
26
26
  maxResponseSize: _.get(options, 'requester.maxResponseSize'),
27
27
  // @todo drop support in v8
28
28
  useWhatWGUrlParser: _.get(options, 'requester.useWhatWGUrlParser', false),
29
+ insecureHTTPParser: _.get(options, 'requester.insecureHTTPParser'),
29
30
  followRedirects: _.get(options, 'requester.followRedirects', true),
30
31
  followOriginalHttpMethod: _.get(options, 'requester.followOriginalHttpMethod'),
31
32
  maxRedirects: _.get(options, 'requester.maxRedirects'),
@@ -1,7 +1,7 @@
1
+ /* eslint-disable jsdoc/require-param-type,jsdoc/require-param-description */
1
2
  var _ = require('lodash'),
2
3
  core = require('./core'),
3
- Emitter = require('events'),
4
- inherits = require('inherits'),
4
+ EventEmitter = require('events'),
5
5
  now = require('performance-now'),
6
6
  sdk = require('postman-collection'),
7
7
  requests = require('./request-wrapper'),
@@ -111,39 +111,34 @@ var _ = require('lodash'),
111
111
  }
112
112
 
113
113
  return offset;
114
- },
114
+ };
115
115
 
116
- Requester;
117
-
118
- /**
119
- * Creates a new Requester, which is used to make HTTP(s) requests.
120
- *
121
- * @param trace
122
- * @param options
123
- * @param {Boolean} [options.keepAlive=true] Optimizes HTTP connections by keeping them alive, so that new requests
124
- * to the same host are made over the same underlying TCP connection.
125
- * @param {CookieJar} [options.cookieJar] A cookie jar to use with Node requests.
126
- * @param {Boolean} [options.strictSSL]
127
- * @param {Boolean} [options.followRedirects=true] If false, returns a 301/302 as the response code
128
- * instead of following the redirect
129
- * @note `options.keepAlive` is only supported in Node.
130
- * @note `options.cookieJar` is only supported in Node.
131
- *
132
- * @constructor
133
- */
134
- inherits(Requester = function (trace, options) {
135
- this.options = options || {};
136
-
137
- // protect the timeout value from being non-numeric or infinite
138
- if (!_.isFinite(this.options.timeout)) {
139
- this.options.timeout = undefined;
140
- }
116
+ class Requester extends EventEmitter {
117
+ /**
118
+ * Creates a new Requester, which is used to make HTTP(s) requests.
119
+ *
120
+ * @param trace
121
+ * @param options
122
+ * @param {Boolean} [options.keepAlive=true] Optimizes HTTP connections by keeping them alive, so that new requests
123
+ * to the same host are made over the same underlying TCP connection.
124
+ * @param {CookieJar} [options.cookieJar] A cookie jar to use with Node requests.
125
+ * @param {Boolean} [options.strictSSL]
126
+ * @param {Boolean} [options.followRedirects=true] If false, returns a 301/302 as the response code
127
+ * instead of following the redirect
128
+ * @note `options.keepAlive` is only supported in Node.
129
+ * @note `options.cookieJar` is only supported in Node.
130
+ */
131
+ constructor (trace, options) {
132
+ super();
141
133
 
142
- this.trace = trace;
143
- Requester.super_.call(this);
144
- }, Emitter);
134
+ this.trace = trace;
135
+ this.options = options || {};
145
136
 
146
- _.assign(Requester.prototype, /** @lends Requester.prototype */ {
137
+ // protect the timeout value from being non-numeric or infinite
138
+ if (!_.isFinite(this.options.timeout)) {
139
+ this.options.timeout = undefined;
140
+ }
141
+ }
147
142
 
148
143
  /**
149
144
  * Perform an HTTP request.
@@ -153,7 +148,7 @@ _.assign(Requester.prototype, /** @lends Requester.prototype */ {
153
148
  * @param {Object} protocolProfileBehavior
154
149
  * @param {Function} callback
155
150
  */
156
- request: function (id, request, protocolProfileBehavior, callback) {
151
+ request (id, request, protocolProfileBehavior, callback) {
157
152
  var self = this,
158
153
  hostname,
159
154
  cookieJar,
@@ -299,8 +294,8 @@ _.assign(Requester.prototype, /** @lends Requester.prototype */ {
299
294
  // wait for responseStart and cache response callback data
300
295
  _responseEnded = true;
301
296
  _responseData = {
302
- response: response,
303
- history: history
297
+ response,
298
+ history
304
299
  };
305
300
  },
306
301
 
@@ -441,7 +436,7 @@ _.assign(Requester.prototype, /** @lends Requester.prototype */ {
441
436
 
442
437
  onComplete(RESPONSE_END, response, history);
443
438
  });
444
- },
439
+ }
445
440
 
446
441
  /**
447
442
  * Removes all current event listeners on the requester, and makes it ready for garbage collection :).
@@ -450,7 +445,7 @@ _.assign(Requester.prototype, /** @lends Requester.prototype */ {
450
445
  *
451
446
  * @todo - In the future, when the requester manages its own connections etc, close them all here.
452
447
  */
453
- dispose: function (cb) {
448
+ dispose (cb) {
454
449
  // This is safe for us, because we do not use wait on events. (i.e, no part of Runtime ever waits on
455
450
  // any event to occur). We rely on callbacks for that, only choosing to use events as a way of streaming
456
451
  // information outside runtime.
@@ -458,9 +453,7 @@ _.assign(Requester.prototype, /** @lends Requester.prototype */ {
458
453
 
459
454
  _.isFunction(cb) && cb();
460
455
  }
461
- });
462
456
 
463
- _.assign(Requester, /** @lends Requester */ {
464
457
  /**
465
458
  * Asynchronously create a new requester.
466
459
  *
@@ -472,9 +465,9 @@ _.assign(Requester, /** @lends Requester */ {
472
465
  * @param callback
473
466
  * @returns {*}
474
467
  */
475
- create: function (trace, options, callback) {
468
+ static create (trace, options, callback) {
476
469
  return callback(null, new Requester(trace, options));
477
- },
470
+ }
478
471
 
479
472
  /**
480
473
  * A helper method to dry run the given request instance.
@@ -488,7 +481,9 @@ _.assign(Requester, /** @lends Requester */ {
488
481
  * @param {Object} options.implicitTraceHeader
489
482
  * @param {Function} done
490
483
  */
491
- dryRun
492
- });
484
+ static dryRun (request, options, done) {
485
+ return dryRun(request, options, done);
486
+ }
487
+ }
493
488
 
494
489
  module.exports.Requester = Requester;
@@ -14,12 +14,12 @@ var _ = require('lodash'),
14
14
  *
15
15
  * @function createItemContext
16
16
  *
17
- * @param {Object} payload
18
- * @param {Item} payload.item
19
- * @param {Object} [payload.coords]
20
- * @param {Object} [defaults]
21
- * @param {Object} [defaults.replayState]
22
- * @param {Object} [defaults.coords]
17
+ * @param {Object} payload -
18
+ * @param {Item} payload.item -
19
+ * @param {Object} [payload.coords] -
20
+ * @param {Object} [defaults] -
21
+ * @param {Object} [defaults.replayState] -
22
+ * @param {Object} [defaults.coords] -
23
23
  *
24
24
  * @returns {ItemContext}
25
25
  */