wingbot 3.67.13 → 3.67.14

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/BuildRouter.js +34 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.67.13",
3
+ "version": "3.67.14",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -4,6 +4,8 @@
4
4
  'use strict';
5
5
 
6
6
  const { decompress } = require('compress-json');
7
+ const { brotliCompress, brotliDecompress } = require('zlib');
8
+ const { promisify } = require('util');
7
9
  const { default: fetch } = require('node-fetch');
8
10
  const assert = require('assert');
9
11
  const path = require('path');
@@ -223,6 +225,9 @@ class BuildRouter extends Router {
223
225
 
224
226
  this._prebuiltGlobalIntents = null;
225
227
 
228
+ this._brotliCompress = promisify(brotliCompress);
229
+ this._brotliDecompress = promisify(brotliDecompress);
230
+
226
231
  this.resources = defaultResourceMap();
227
232
 
228
233
  this._loadBotAuthorization = 'token' in block ? block.token : null;
@@ -382,18 +387,19 @@ class BuildRouter extends Router {
382
387
  }
383
388
 
384
389
  if (snapshot) {
385
- snapshot = await configStorage.updateConfig(snapshot);
390
+ snapshot = await this._updateConfig(configStorage, snapshot);
386
391
  }
387
392
 
388
393
  if (ts !== 0 && !snapshot) {
389
394
  // probably someone has updated the configuration
390
395
  snapshot = await configStorage.getConfig();
396
+ snapshot = await this._decompressIfCompressed(snapshot);
391
397
  }
392
398
 
393
399
  if (!snapshot || typeof snapshot !== 'object' || !Array.isArray(snapshot.blocks)) {
394
400
  // there is no configuration, load it from server
395
401
  snapshot = await this.loadBot();
396
- snapshot = await configStorage.updateConfig(snapshot);
402
+ snapshot = await this._updateConfig(configStorage, snapshot);
397
403
  }
398
404
 
399
405
  // wait for running request
@@ -406,6 +412,32 @@ class BuildRouter extends Router {
406
412
  }
407
413
  }
408
414
 
415
+ async _updateConfig (configStorage, snapshot) {
416
+ const buf = await this._brotliCompress(Buffer.from(JSON.stringify(snapshot)));
417
+ const compressed = {
418
+ compression: 'brotli',
419
+ base64url: buf.toString('base64url'),
420
+ timestamp: snapshot.timestamp
421
+ };
422
+ const updated = await configStorage.updateConfig(compressed);
423
+ const decoded = await this._decompressIfCompressed(updated);
424
+ return decoded;
425
+ }
426
+
427
+ async _decompressIfCompressed (snapshot) {
428
+ if (!snapshot || snapshot.compression !== 'brotli' || !snapshot.base64url) {
429
+ return snapshot;
430
+ }
431
+ const buf = Buffer.from(snapshot.base64url, 'base64url');
432
+ const data = await this._brotliDecompress(buf);
433
+
434
+ const parsed = JSON.parse(data.toString('utf8'));
435
+ return {
436
+ ...parsed,
437
+ timestamp: snapshot.timestamp
438
+ };
439
+ }
440
+
409
441
  /**
410
442
  * Loads conversation configuration
411
443
  *