wingbot 3.73.14-alpha.0 → 3.73.15

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": "wingbot",
3
- "version": "3.73.14-alpha.0",
3
+ "version": "3.73.15",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -181,10 +181,17 @@ class BotAppSender extends ReturnSender {
181
181
 
182
182
  headers.set('Authorization', token);
183
183
 
184
- const response = await this._fetch(`${this._apiUrl}/${this._pageId}`, {
184
+ const res = await this._fetch(`${this._apiUrl}/${this._pageId}`, {
185
185
  headers, body: formData, agent, method: 'POST'
186
- })
187
- .then((r) => r.json());
186
+ });
187
+
188
+ const responseText = await res.text();
189
+ let response;
190
+ try {
191
+ response = JSON.parse(responseText);
192
+ } catch (e) {
193
+ throw new Error(`[${res.status}] Invalid JSON response: ${responseText}`);
194
+ }
188
195
 
189
196
  return response;
190
197
  }
@@ -212,10 +219,17 @@ class BotAppSender extends ReturnSender {
212
219
  headers.set('Authorization', token);
213
220
  headers.set('Content-Type', 'application/json');
214
221
 
215
- const response = await this._fetch(this._apiUrl, {
222
+ const res = await this._fetch(this._apiUrl, {
216
223
  headers, body, agent, method: 'POST'
217
- })
218
- .then((r) => r.json());
224
+ });
225
+
226
+ const responseText = await res.text();
227
+ let response;
228
+ try {
229
+ response = JSON.parse(responseText);
230
+ } catch (e) {
231
+ throw new Error(`[${res.status}] Invalid JSON response: ${responseText}`);
232
+ }
219
233
 
220
234
  const { request, errors = null } = response;
221
235
 
@@ -395,12 +395,7 @@ class BuildRouter extends Router {
395
395
  if (!snapshot) {
396
396
  snapshot = await this.loadBot();
397
397
  }
398
- this.buildWithSnapshot(
399
- snapshot.blocks,
400
- undefined,
401
- undefined,
402
- snapshot.deployedConfiguration
403
- );
398
+ this.buildWithSnapshot(snapshot.blocks);
404
399
  } catch (e) {
405
400
  if (this._configTs > 0 && !snapshot) {
406
401
  // mute
@@ -442,12 +437,7 @@ class BuildRouter extends Router {
442
437
  // wait for running request
443
438
  await Promise.all(this._runningReqs);
444
439
 
445
- this.buildWithSnapshot(
446
- snapshot.blocks,
447
- snapshot.timestamp,
448
- snapshot.lastmod,
449
- snapshot.deployedConfiguration
450
- );
440
+ this.buildWithSnapshot(snapshot.blocks, snapshot.timestamp, snapshot.lastmod);
451
441
  } catch (e) {
452
442
  await configStorage.invalidateConfig();
453
443
  throw e;
@@ -538,20 +528,9 @@ class BuildRouter extends Router {
538
528
  blocks.forEach((b) => this._validateBlock(b, action));
539
529
  }
540
530
 
541
- buildWithSnapshot (blocks, setConfigTimestamp = Number.MAX_SAFE_INTEGER, lastmod = '-', deployedConfiguration = null) {
531
+ buildWithSnapshot (blocks, setConfigTimestamp = Number.MAX_SAFE_INTEGER, lastmod = '-') {
542
532
  this._validateBlocks(blocks);
543
533
 
544
- if (deployedConfiguration && typeof deployedConfiguration === 'object') {
545
- if (this._configuration instanceof Promise) {
546
- this._configuration = this._configuration
547
- .then((c) => Object.assign(c || /** @type {C} */ ({}), deployedConfiguration));
548
- } else {
549
- const cfg = this._configuration || /** @type {C} */ ({});
550
- Object.assign(cfg, deployedConfiguration);
551
- this._configuration = cfg;
552
- }
553
- }
554
-
555
534
  Object.assign(this._resolvedContext, {
556
535
  blocks,
557
536
  nestedBlocksByStaticId: null
@@ -272,7 +272,14 @@ class OrchestratorClient {
272
272
 
273
273
  const response = await this._fetch(this._apiUrl, { headers, body, method: 'POST' });
274
274
 
275
- const responseJson = response.json();
275
+ const responseText = await response.text();
276
+ let responseJson;
277
+ try {
278
+ responseJson = JSON.parse(responseText);
279
+ } catch (e) {
280
+ throw new Error(`[${response.status}] Invalid JSON response: ${responseText}`);
281
+ }
282
+
276
283
  const { errors = null } = responseJson;
277
284
 
278
285
  if (errors) {
@@ -21,12 +21,7 @@ const apiAuthorizer = require('./apiAuthorizer');
21
21
  */
22
22
  async function validate (bot, validationRequestBody, postBackTest = null, textTest = null) {
23
23
  try {
24
- bot.buildWithSnapshot(
25
- validationRequestBody.blocks,
26
- Number.MAX_SAFE_INTEGER,
27
- undefined,
28
- validationRequestBody.deployedConfiguration
29
- );
24
+ bot.buildWithSnapshot(validationRequestBody.blocks, Number.MAX_SAFE_INTEGER);
30
25
  } catch (e) {
31
26
  const error = `Bot build failed: ${e.message}`;
32
27
  // eslint-disable-next-line no-console