botversion-sdk 2.1.1 → 2.2.1

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.
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
4
  var path = require("path");
@@ -29,7 +29,7 @@ var BotVersionClient = require("../client");
29
29
 
30
30
  var apiKey = process.env.BOTVERSION_API_KEY;
31
31
  var platformUrl =
32
- process.env.BOTVERSION_PLATFORM_URL || "https://console.botversion.com";
32
+ process.env.BOTVERSION_PLATFORM_URL || "http://localhost:3000";
33
33
 
34
34
  if (!apiKey) {
35
35
  console.error(
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
4
  var path = require("path");
@@ -30,7 +30,7 @@ var sdk = require("../index");
30
30
 
31
31
  var apiKey = process.env.BOTVERSION_API_KEY;
32
32
  var platformUrl =
33
- process.env.BOTVERSION_PLATFORM_URL || "https://console.botversion.com";
33
+ process.env.BOTVERSION_PLATFORM_URL || "http://localhost:3000";
34
34
 
35
35
  if (!apiKey) {
36
36
  console.error(
package/client.js CHANGED
@@ -11,7 +11,7 @@ const url = require("url");
11
11
  */
12
12
  function BotVersionClient(options) {
13
13
  this.apiKey = options.apiKey;
14
- this.platformUrl = options.platformUrl || "https://console.botversion.com";
14
+ this.platformUrl = options.platformUrl || "http://localhost:3000";
15
15
  this.debug = options.debug || false;
16
16
  this.timeout = options.timeout || 30000;
17
17
 
@@ -19,6 +19,8 @@ function BotVersionClient(options) {
19
19
  this._queue = [];
20
20
  this._flushTimer = null;
21
21
  this._flushDelay = options.flushDelay || 3000;
22
+ // Tracks in-flight updates per endpoint so they are sent one after another
23
+ this._inflight = {};
22
24
  var self = this;
23
25
  process.on("beforeExit", function () {
24
26
  if (self._queue.length > 0) self._flush();
@@ -74,13 +76,10 @@ BotVersionClient.prototype._flush = function () {
74
76
  var toSend = self._queue.slice();
75
77
  self._queue = [];
76
78
 
77
- self
78
- ._post("/api/sdk/register-endpoints", {
79
- workspaceKey: self.apiKey,
80
- endpoints: toSend,
81
- })
82
- .then(function (data) {})
83
- .catch(function (err) {});
79
+ self._post("/api/sdk/register-endpoints", {
80
+ workspaceKey: self.apiKey,
81
+ endpoints: toSend,
82
+ });
84
83
  };
85
84
 
86
85
  /**
@@ -89,14 +88,38 @@ BotVersionClient.prototype._flush = function () {
89
88
  BotVersionClient.prototype.updateEndpoint = function (endpoint) {
90
89
  var self = this;
91
90
 
92
- return self._post("/api/sdk/update-endpoint", {
91
+ var payload = {
93
92
  workspaceKey: self.apiKey,
94
93
  method: endpoint.method,
95
94
  path: endpoint.path,
96
95
  requestBody: endpoint.requestBody || null,
97
96
  responseBody: endpoint.responseBody || null,
98
97
  detectedBy: endpoint.detectedBy || "runtime",
99
- });
98
+ };
99
+
100
+ // Updates for the same endpoint go out one after another, so a later update
101
+ // (e.g. its reply shape) can never race the first registration of that endpoint.
102
+ var key = String(endpoint.method).toUpperCase() + ":" + endpoint.path;
103
+ var previous = self._inflight[key] || Promise.resolve();
104
+ var send = function () {
105
+ return self._post("/api/sdk/update-endpoint", payload).then(
106
+ function (res) {
107
+ return res;
108
+ },
109
+ function (err) {
110
+ throw err;
111
+ },
112
+ );
113
+ };
114
+ var current = previous.then(send, send);
115
+ self._inflight[key] = current;
116
+
117
+ var cleanup = function () {
118
+ if (self._inflight[key] === current) delete self._inflight[key];
119
+ };
120
+ current.then(cleanup, cleanup);
121
+
122
+ return current;
100
123
  };
101
124
 
102
125
  BotVersionClient.prototype.registerRoutePatterns = function (
package/index.js CHANGED
@@ -226,6 +226,9 @@ function runFullScan(
226
226
  if (shouldScanBackend) {
227
227
  var endpoints = runBackendScanner(detectedBackend, app, options, cwd);
228
228
  result.endpointCount = endpoints.length;
229
+ endpoints.filter(function (e) {
230
+ return e.method === "GET" || e.method === "DELETE";
231
+ });
229
232
 
230
233
  if (endpoints.length > 0) {
231
234
  client.registerEndpoints(endpoints);
@@ -421,7 +424,7 @@ var BotVersion = {
421
424
 
422
425
  this._client = new BotVersionClient({
423
426
  apiKey: options.apiKey,
424
- platformUrl: options.platformUrl || "https://console.botversion.com",
427
+ platformUrl: options.platformUrl || "http://localhost:3000",
425
428
  debug: options.debug || false,
426
429
  timeout: options.timeout || 30000,
427
430
  });