postman-runtime 7.52.0 → 7.54.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.
@@ -24,6 +24,7 @@ var _ = require('lodash'),
24
24
  EXECUTION_SKIP_REQUEST_EVENT_BASE = 'execution.skipRequest.',
25
25
 
26
26
  EXECUTION_VAULT_BASE = 'execution.vault.',
27
+ EXECUTION_DATASETS_BASE = 'execution.datasets.',
27
28
 
28
29
  COOKIES_EVENT_STORE_ACTION = 'store',
29
30
  COOKIE_STORE_PUT_METHOD = 'putCookie',
@@ -487,6 +488,40 @@ module.exports = {
487
488
  dispatch(null, vaultSecrets[cmd](...args));
488
489
  }.bind(this));
489
490
 
491
+ this.host.on(EXECUTION_DATASETS_BASE + executionId, function (id, cmd, datasetId, ...args) {
492
+ const datasetsResolver = _.get(this, 'options.script.datasetsResolver'),
493
+
494
+ // Ensure error is string
495
+ // TODO identify why error objects are not being serialized correctly
496
+ dispatch = (e, r) => {
497
+ this.host.dispatch(EXECUTION_DATASETS_BASE + executionId, id, e, r);
498
+ };
499
+
500
+ if (!datasetsResolver) {
501
+ return dispatch('Datasets API is not available');
502
+ }
503
+
504
+ if (!['executeView', 'executeQuery'].includes(cmd)) {
505
+ return dispatch(`Invalid datasets command: ${cmd}`);
506
+ }
507
+
508
+ try {
509
+ datasetsResolver(cmd, datasetId, args, function (err, result) {
510
+ if (err) {
511
+ return dispatch(err instanceof Error ? err.message :
512
+ (typeof err === 'string' ? err : String(err && err.message || err)));
513
+ }
514
+
515
+ dispatch(null, result);
516
+ });
517
+ }
518
+ catch (error) {
519
+ const detail = error && error.message ? `: ${error.message}` : '';
520
+
521
+ dispatch(`Datasets: error executing "${cmd}"${detail}`);
522
+ }
523
+ }.bind(this));
524
+
490
525
  this.host.on(EXECUTION_REQUEST_EVENT_BASE + executionId,
491
526
  function (scriptCursor, id, requestId, request) {
492
527
  // remove files in request body if any
@@ -570,8 +605,12 @@ module.exports = {
570
605
  context: contextToUse,
571
606
  resolvedPackages: resolvedPackages,
572
607
 
573
- disabledAPIs: !_.get(this, 'options.script.requestResolver') ?
574
- ['execution.runRequest'] : [],
608
+ disabledAPIs: [
609
+ ...(!_.get(this, 'options.script.requestResolver') ?
610
+ ['execution.runRequest'] : []),
611
+ ...(!_.get(this, 'options.script.datasetsResolver') ?
612
+ ['datasets'] : [])
613
+ ],
575
614
 
576
615
  // legacy options
577
616
  legacy: {
@@ -589,6 +628,7 @@ module.exports = {
589
628
  this.host.removeAllListeners(EXECUTION_ERROR_EVENT_BASE + executionId);
590
629
  this.host.removeAllListeners(EXECUTION_SKIP_REQUEST_EVENT_BASE + executionId);
591
630
  this.host.removeAllListeners(EXECUTION_VAULT_BASE + executionId);
631
+ this.host.removeAllListeners(EXECUTION_DATASETS_BASE + executionId);
592
632
 
593
633
  // Handle async errors as well.
594
634
  // If there was an error running the script itself, that takes precedence
@@ -79,15 +79,15 @@ _.assign(Runner.prototype, {
79
79
  * the request being resolved
80
80
  * @param {Number} [options.nestedRequest.hasVaultAccess] - Mutated and set by any nested or parent request
81
81
  * to indicate whether vault access check has been performed.
82
- * @param {Number} [options.nestedRequest.invocationCount] - The number of requests currently accummulated
83
- * by the nested request chain.
82
+ * @param {Array} [options.nestedRequest.callStack] - The current stack of nested request item ids
83
+ * used to enforce max nested depth. Internally set and used.
84
84
  * @param {Object} [options.requester] - Options specific to the requester
85
85
  * @param {Function} [options.script.requestResolver] - Resolver that receives an id from
86
86
  * pm.execution.runRequest and returns the JSON for the request collection.
87
87
  * Should return a postman-collection compatible collection JSON with `item` containing the request to run,
88
88
  * `variable` array containing list of request-specific-collection variables and `event` with scripts to execute.
89
- * @param {Number} [options.maxInvokableNestedRequests] - The maximum number of nested requests
90
- * that a script can invoke, combined in total and recursively nested
89
+ * @param {Number} [options.maxInvokableNestedRequests] - The maximum nested depth
90
+ * that a script can invoke via pm.execution.runRequest
91
91
  * @param {Number} [options.iterationCount] -
92
92
  * @param {CertificateList} [options.certificates] -
93
93
  * @param {ProxyConfigList} [options.proxies] -
@@ -11,9 +11,27 @@ function runNestedRequest ({ executionId, isExecutionSkipped, vaultSecrets, item
11
11
  const self = this,
12
12
  requestResolver = _.get(self, 'options.script.requestResolver'),
13
13
  runRequestRespEvent = EXECUTION_RUN_REQUEST_RESPONSE_EVENT_BASE + eventId,
14
- maxInvokableNestedRequests = _.get(self, 'options.maxInvokableNestedRequests');
14
+ maxInvokableNestedRequests = _.get(self, 'options.maxInvokableNestedRequests'),
15
+ itemId = item.id,
16
+ currentItemState = { isPoppedFromCallStack: false },
17
+ popCurrentItemFromCallStack = () => {
18
+ if (currentItemState.isPoppedFromCallStack) { return; }
19
+
20
+ currentItemState.isPoppedFromCallStack = true;
21
+
22
+ if (!self.state.nestedRequest.callStack.length) { return; }
23
+
24
+ const { callStack } = self.state.nestedRequest,
25
+ itemIndex = callStack.lastIndexOf(itemId);
26
+
27
+ if (itemIndex !== -1) {
28
+ self.state.nestedRequest.callStack.splice(itemIndex, 1);
29
+ }
30
+ };
15
31
 
16
32
  function dispatchErrorToListener (err) {
33
+ popCurrentItemFromCallStack();
34
+
17
35
  const error = serialisedError(err);
18
36
 
19
37
  delete error.stack;
@@ -28,15 +46,15 @@ function runNestedRequest ({ executionId, isExecutionSkipped, vaultSecrets, item
28
46
  isNestedRequest: true,
29
47
  rootCursor: cursor,
30
48
  rootItem: item,
31
- invocationCount: 0
49
+ callStack: []
32
50
  });
33
51
 
34
- self.state.nestedRequest.invocationCount++;
52
+ self.state.nestedRequest.callStack.push(itemId);
35
53
 
36
- // No more than maxInvokableNestedRequests runRequest calls per script or any of its nested request scripts
37
- if (self.state.nestedRequest.invocationCount > maxInvokableNestedRequests) {
38
- return dispatchErrorToListener(new Error('The maximum number of pm.execution.runRequest()' +
39
- ' calls have been reached for this request.'));
54
+ // No more than maxInvokableNestedRequests nested depth
55
+ if (self.state.nestedRequest.callStack.length > maxInvokableNestedRequests) {
56
+ return dispatchErrorToListener(new Error('Max pm.execution.runRequest depth of ' +
57
+ maxInvokableNestedRequests + ' has been reached.'));
40
58
  }
41
59
 
42
60
  let rootRequestEventsList = self.state.nestedRequest.rootItem.events?.all?.() || [],
@@ -137,6 +155,8 @@ function runNestedRequest ({ executionId, isExecutionSkipped, vaultSecrets, item
137
155
  variableMutationsFromThisExecution = {};
138
156
 
139
157
  if (err) {
158
+ popCurrentItemFromCallStack();
159
+
140
160
  return self.host
141
161
  .dispatch(EXECUTION_RUN_REQUEST_RESPONSE_EVENT_BASE + eventId,
142
162
  requestId, err);
@@ -206,6 +226,8 @@ function runNestedRequest ({ executionId, isExecutionSkipped, vaultSecrets, item
206
226
  delete error.stack;
207
227
  }
208
228
 
229
+ popCurrentItemFromCallStack();
230
+
209
231
  return self.host.dispatch(runRequestRespEvent,
210
232
  requestId, error || null,
211
233
  responseForThisRequest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postman-runtime",
3
- "version": "7.52.0",
3
+ "version": "7.54.0",
4
4
  "description": "Underlying library of executing Postman Collections",
5
5
  "author": "Postman Inc.",
6
6
  "license": "Apache-2.0",
@@ -45,18 +45,18 @@
45
45
  "@postman/tough-cookie": "4.1.3-postman.1",
46
46
  "async": "3.2.6",
47
47
  "aws4": "1.13.2",
48
- "handlebars": "4.7.8",
48
+ "handlebars": "4.7.9",
49
49
  "httpntlm": "1.8.13",
50
50
  "jose": "5.10.0",
51
51
  "js-sha512": "0.9.0",
52
52
  "lodash": "4.17.23",
53
53
  "mime-types": "2.1.35",
54
- "node-forge": "1.3.3",
54
+ "node-forge": "1.4.0",
55
55
  "node-oauth1": "1.3.0",
56
56
  "performance-now": "2.1.0",
57
57
  "postman-collection": "5.3.0",
58
58
  "postman-request": "2.88.1-postman.48",
59
- "postman-sandbox": "6.6.1",
59
+ "postman-sandbox": "6.7.0",
60
60
  "postman-url-encoder": "3.0.8",
61
61
  "serialised-error": "1.1.3",
62
62
  "strip-json-comments": "3.1.1",