botium-core 1.12.1 → 1.12.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.
package/dist/botium-es.js CHANGED
@@ -36,7 +36,7 @@ import express from 'express';
36
36
  import bodyParser from 'body-parser';
37
37
 
38
38
  var name = "botium-core";
39
- var version$1 = "1.12.1";
39
+ var version$1 = "1.12.2";
40
40
  var description = "The Selenium for Chatbots";
41
41
  var main = "index.js";
42
42
  var module = "dist/botium-es.js";
@@ -314,6 +314,7 @@ var Capabilities = {
314
314
  // API Calls Rate Limiting
315
315
  RATELIMIT_USERSAYS_MAXCONCURRENT: 'RATELIMIT_USERSAYS_MAXCONCURRENT',
316
316
  RATELIMIT_USERSAYS_MINTIME: 'RATELIMIT_USERSAYS_MINTIME',
317
+ RATELIMIT_BOTTLENECK_FN: 'RATELIMIT_BOTTLENECK_FN',
317
318
  SECURITY_ALLOW_UNSAFE: 'SECURITY_ALLOW_UNSAFE',
318
319
  PRECOMPILERS: 'PRECOMPILERS'
319
320
  };
@@ -448,6 +449,7 @@ Capabilities.LOGIC_HOOKS;
448
449
  Capabilities.USER_INPUTS;
449
450
  Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT;
450
451
  Capabilities.RATELIMIT_USERSAYS_MINTIME;
452
+ Capabilities.RATELIMIT_BOTTLENECK_FN;
451
453
  Capabilities.SECURITY_ALLOW_UNSAFE;
452
454
  Capabilities.PRECOMPILERS;
453
455
 
@@ -7537,7 +7539,7 @@ var BaseContainer_1 = class BaseContainer {
7537
7539
  this.tempDirectory = tempDirectory;
7538
7540
  this.cleanupTasks = [];
7539
7541
  this.queues = {};
7540
- this.userSaysLimiter = null;
7542
+ this.bottleneck = null;
7541
7543
  }
7542
7544
 
7543
7545
  Validate() {
@@ -7547,18 +7549,33 @@ var BaseContainer_1 = class BaseContainer {
7547
7549
  this.onBotResponseHook = getHook$1(this.caps, this.caps[Capabilities.CUSTOMHOOK_ONBOTRESPONSE]);
7548
7550
  this.onStopHook = getHook$1(this.caps, this.caps[Capabilities.CUSTOMHOOK_ONSTOP]);
7549
7551
  this.onCleanHook = getHook$1(this.caps, this.caps[Capabilities.CUSTOMHOOK_ONCLEAN]);
7550
- return Promise.resolve();
7551
- }
7552
7552
 
7553
- Build() {
7554
- if (this.caps[Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT] || this.caps[Capabilities.RATELIMIT_USERSAYS_MINTIME]) {
7553
+ if (this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN]) {
7554
+ if (lodash.isFunction(this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN])) {
7555
+ this.bottleneck = this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN];
7556
+ debug$7('Validate: Applying userSays rate limits from capability');
7557
+ } else {
7558
+ const limiter = new bottleneck(this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN]);
7559
+
7560
+ this.bottleneck = fn => limiter.schedule(fn);
7561
+
7562
+ debug$7(`Validate: Applying userSays rate limits ${util.inspect(this.caps[Capabilities.RATELIMIT_BOTTLENECK_FN])}`);
7563
+ }
7564
+ } else if (this.caps[Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT] || this.caps[Capabilities.RATELIMIT_USERSAYS_MINTIME]) {
7555
7565
  const opts = {};
7556
7566
  if (this.caps[Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT]) opts.maxConcurrent = this.caps[Capabilities.RATELIMIT_USERSAYS_MAXCONCURRENT];
7557
7567
  if (this.caps[Capabilities.RATELIMIT_USERSAYS_MINTIME]) opts.minTime = this.caps[Capabilities.RATELIMIT_USERSAYS_MINTIME];
7558
- this.userSaysLimiter = new bottleneck(opts);
7559
- debug$7(`Build: Applying userSays rate limits ${util.inspect(opts)}`);
7568
+ const limiter = new bottleneck(opts);
7569
+
7570
+ this.bottleneck = fn => limiter.schedule(fn);
7571
+
7572
+ debug$7(`Validate: Applying userSays rate limits ${util.inspect(opts)}`);
7560
7573
  }
7561
7574
 
7575
+ return Promise.resolve();
7576
+ }
7577
+
7578
+ Build() {
7562
7579
  return new Promise((resolve, reject) => {
7563
7580
  this._RunCustomHook('onBuild', this.onBuildHook).then(() => resolve(this)).catch(err => reject(err));
7564
7581
  });
@@ -7584,8 +7601,8 @@ var BaseContainer_1 = class BaseContainer {
7584
7601
  meMsg
7585
7602
  }).then(() => this.UserSaysImpl(meMsg));
7586
7603
 
7587
- if (this.userSaysLimiter) {
7588
- return this.userSaysLimiter.schedule(run);
7604
+ if (this.bottleneck) {
7605
+ return this.bottleneck(run);
7589
7606
  } else {
7590
7607
  return run();
7591
7608
  }
@@ -8073,10 +8090,14 @@ mustache.escape = s => s;
8073
8090
  var SimpleRestContainer_1 = class SimpleRestContainer {
8074
8091
  constructor({
8075
8092
  queueBotSays,
8076
- caps
8093
+ caps,
8094
+ bottleneck
8077
8095
  }) {
8078
8096
  this.queueBotSays = queueBotSays;
8079
8097
  this.caps = Object.assign({}, Defaults, caps);
8098
+
8099
+ this.bottleneck = bottleneck || (fn => fn());
8100
+
8080
8101
  this.processInbound = false;
8081
8102
  this.redisTopic = this.caps[Capabilities.SIMPLEREST_REDIS_TOPIC] || 'SIMPLEREST_INBOUND_SUBSCRIPTION';
8082
8103
 
@@ -8615,7 +8636,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8615
8636
  err,
8616
8637
  response,
8617
8638
  body
8618
- } = await new Promise(resolve => {
8639
+ } = await this.bottleneck(() => new Promise(resolve => {
8619
8640
  request(pingConfig, (err, response, body) => {
8620
8641
  resolve({
8621
8642
  err,
@@ -8623,7 +8644,7 @@ var SimpleRestContainer_1 = class SimpleRestContainer {
8623
8644
  body
8624
8645
  });
8625
8646
  });
8626
- });
8647
+ }));
8627
8648
 
8628
8649
  if (err) {
8629
8650
  debug$4(`_waitForUrlResponse error on url check ${pingConfig.uri}: ${err}`);
@@ -9147,6 +9168,7 @@ var PluginConnectorContainer_1 = class PluginConnectorContainer extends BaseCont
9147
9168
  this.pluginInstance = tryLoadPlugin(this.caps[Capabilities.CONTAINERMODE], this.caps[Capabilities.PLUGINMODULEPATH], {
9148
9169
  container: this,
9149
9170
  queueBotSays: msg => this._QueueBotSays(msg),
9171
+ bottleneck: this.bottleneck,
9150
9172
  eventEmitter: this.eventEmitter,
9151
9173
  caps: this.caps,
9152
9174
  sources: this.sources,