@livechat/customer-sdk 3.1.0 → 3.1.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.
Files changed (47) hide show
  1. package/README.md +32 -4
  2. package/dist/customer-sdk.cjs.js +187 -640
  3. package/dist/customer-sdk.cjs.native.js +187 -639
  4. package/dist/customer-sdk.esm.js +188 -641
  5. package/dist/customer-sdk.js +265 -867
  6. package/dist/customer-sdk.min.js +1 -1
  7. package/package.json +10 -9
  8. package/types/actions.d.ts +331 -0
  9. package/types/chatHistory.d.ts +19 -0
  10. package/types/clientDataParsers.d.ts +55 -0
  11. package/types/completionValues.d.ts +4 -0
  12. package/types/constants/clientErrorCodes.d.ts +11 -0
  13. package/types/constants/connectionStatuses.d.ts +6 -0
  14. package/types/constants/eventTypes.d.ts +8 -0
  15. package/types/constants/reduxActions.d.ts +23 -0
  16. package/types/constants/serverDisconnectionReasons.d.ts +15 -0
  17. package/types/constants/serverErrorCodes.d.ts +23 -0
  18. package/types/constants/serverPushActions.d.ts +26 -0
  19. package/types/constants/serverRequestActions.d.ts +30 -0
  20. package/types/constants/sortOrders.d.ts +3 -0
  21. package/types/constants/userTypes.d.ts +3 -0
  22. package/types/createError.d.ts +9 -0
  23. package/types/createStore.d.ts +12 -0
  24. package/types/debug.d.ts +3 -0
  25. package/types/graylog/index.d.ts +14 -0
  26. package/types/graylog/makeGrayLogRequest.d.ts +2 -0
  27. package/types/graylog/makeGrayLogRequest.native.d.ts +6 -0
  28. package/types/index.d.ts +239 -0
  29. package/types/reducer.d.ts +546 -0
  30. package/types/sendRequestAction.d.ts +4 -0
  31. package/types/sendTicketForm.d.ts +14 -0
  32. package/types/serverDataParser.d.ts +34 -0
  33. package/types/serverEventParser.d.ts +12 -0
  34. package/types/serverFrameParser.d.ts +385 -0
  35. package/types/sideEffects/checkGoals.d.ts +5 -0
  36. package/types/sideEffects/index.d.ts +12 -0
  37. package/types/sideStorage.d.ts +5 -0
  38. package/types/socketClient.d.ts +11 -0
  39. package/types/socketListener.d.ts +9 -0
  40. package/types/thunks.d.ts +4 -0
  41. package/types/types/actions.d.ts +157 -0
  42. package/types/types/clientEntities.d.ts +374 -0
  43. package/types/types/frames.d.ts +635 -0
  44. package/types/types/serverEntities.d.ts +408 -0
  45. package/types/types/state.d.ts +56 -0
  46. package/types/uploadFile.d.ts +19 -0
  47. package/types/validateFile/index.d.ts +3 -0
@@ -5,80 +5,64 @@
5
5
  }(this, (function (exports) { 'use strict';
6
6
 
7
7
  function _extends() {
8
- _extends = Object.assign || function (target) {
8
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
9
9
  for (var i = 1; i < arguments.length; i++) {
10
10
  var source = arguments[i];
11
-
12
11
  for (var key in source) {
13
12
  if (Object.prototype.hasOwnProperty.call(source, key)) {
14
13
  target[key] = source[key];
15
14
  }
16
15
  }
17
16
  }
18
-
19
17
  return target;
20
18
  };
21
-
22
19
  return _extends.apply(this, arguments);
23
20
  }
24
-
25
21
  function _objectWithoutPropertiesLoose(source, excluded) {
26
22
  if (source == null) return {};
27
23
  var target = {};
28
24
  var sourceKeys = Object.keys(source);
29
25
  var key, i;
30
-
31
26
  for (i = 0; i < sourceKeys.length; i++) {
32
27
  key = sourceKeys[i];
33
28
  if (excluded.indexOf(key) >= 0) continue;
34
29
  target[key] = source[key];
35
30
  }
36
-
37
31
  return target;
38
32
  }
39
-
40
33
  function _toPrimitive(input, hint) {
41
34
  if (typeof input !== "object" || input === null) return input;
42
35
  var prim = input[Symbol.toPrimitive];
43
-
44
36
  if (prim !== undefined) {
45
37
  var res = prim.call(input, hint || "default");
46
38
  if (typeof res !== "object") return res;
47
39
  throw new TypeError("@@toPrimitive must return a primitive value.");
48
40
  }
49
-
50
41
  return (hint === "string" ? String : Number)(input);
51
42
  }
52
-
53
43
  function _toPropertyKey(arg) {
54
44
  var key = _toPrimitive(arg, "string");
55
-
56
45
  return typeof key === "symbol" ? key : String(key);
57
46
  }
58
47
 
59
48
  var testKey = '__test_storage_support__';
60
49
  var testValue = '@@test';
61
-
62
50
  var testStorageSupport = function testStorageSupport(type) {
63
51
  if (type === void 0) {
64
52
  type = 'local';
65
53
  }
66
-
67
54
  try {
68
55
  var storage = type === 'session' ? window.sessionStorage : window.localStorage;
69
56
  storage.setItem(testKey, testValue);
70
-
71
57
  if (storage.getItem(testKey) !== testValue) {
72
58
  return false;
73
59
  }
74
-
75
60
  storage.removeItem(testKey);
76
61
  return true;
77
62
  } catch (err) {
78
63
  return false;
79
64
  }
80
65
  };
81
-
82
66
  var createStorage = function createStorage() {
83
67
  var memoryStorage = Object.create(null);
84
68
  return {
@@ -97,8 +81,8 @@
97
81
  }
98
82
  };
99
83
  };
100
-
101
- var index = /*#__PURE__*/createStorage();
84
+ var index = /*#__PURE__*/
85
+ createStorage();
102
86
 
103
87
  var usedStorage = testStorageSupport() ? window.localStorage : index;
104
88
  var storage = {
@@ -120,19 +104,19 @@
120
104
  };
121
105
 
122
106
  var _ref = {},
123
- hasOwnProperty = _ref.hasOwnProperty;
107
+ hasOwnProperty = _ref.hasOwnProperty;
124
108
  function hasOwn(prop, obj) {
125
109
  return hasOwnProperty.call(obj, prop);
126
110
  }
127
111
 
128
112
  function flatMap(iteratee, arr) {
129
113
  var _ref;
130
-
131
114
  return (_ref = []).concat.apply(_ref, arr.map(iteratee));
132
115
  }
133
116
 
134
117
  var isArray = Array.isArray;
135
118
 
119
+ // eslint-disable-next-line @typescript-eslint/ban-types
136
120
  function isObject(obj) {
137
121
  return typeof obj === 'object' && obj !== null && !isArray(obj);
138
122
  }
@@ -162,11 +146,9 @@
162
146
  var arrPath = typeof propPath === 'string' ? propPath.split('.') : propPath;
163
147
  var pathPartIndex = 0;
164
148
  var result = obj;
165
-
166
149
  while (result && pathPartIndex < arrPath.length) {
167
150
  result = result[arrPath[pathPartIndex++]];
168
151
  }
169
-
170
152
  return result;
171
153
  }
172
154
 
@@ -220,7 +202,6 @@
220
202
  if (hasOwn(prop, obj)) {
221
203
  acc[prop] = obj[prop];
222
204
  }
223
-
224
205
  return acc;
225
206
  }, {});
226
207
  }
@@ -235,7 +216,6 @@
235
216
  if (strA === strB) {
236
217
  return 0;
237
218
  }
238
-
239
219
  return strA < strB ? -1 : 1;
240
220
  };
241
221
 
@@ -244,12 +224,10 @@
244
224
  var seen = [];
245
225
  return arr.filter(function (element) {
246
226
  var key = iteratee(element);
247
-
248
227
  if (seen.indexOf(key) === -1) {
249
228
  seen.push(key);
250
229
  return true;
251
230
  }
252
-
253
231
  return false;
254
232
  });
255
233
  }
@@ -261,7 +239,6 @@
261
239
  };
262
240
 
263
241
  var originRegexp = /[^:]+:\/\/[^(/|?)\s]+/;
264
-
265
242
  var getOrigin = function getOrigin(url) {
266
243
  var domain = url.match(originRegexp);
267
244
  return domain && domain[0];
@@ -278,54 +255,56 @@
278
255
  var intersperseWithTabOrNewline = function intersperseWithTabOrNewline(str) {
279
256
  return str.replace(/\w/g, '$&[\\r\\n\\t]*');
280
257
  };
258
+ var unsafeProtocol = new RegExp("^[\0-\x1F]*(" + intersperseWithTabOrNewline('javascript') + "|" + intersperseWithTabOrNewline('data') + "):", 'i');
281
259
 
282
- var unsafeProtocol = new RegExp("^[\0-\x1F]*(" + intersperseWithTabOrNewline('javascript') + "|" + intersperseWithTabOrNewline('data') + "):", 'i'); // would be better to filter safe things
260
+ var protocolRegexp = /^((http(s)?:)?\/\/)/;
261
+ var removeProtocol = function removeProtocol(url) {
262
+ return url.replace(protocolRegexp, '');
263
+ };
283
264
 
284
265
  function unfetch (e, n) {
285
266
  return n = n || {}, new Promise(function (t, r) {
286
267
  var s = new XMLHttpRequest(),
287
- o = [],
288
- u = [],
289
- i = {},
290
- a = function () {
291
- return {
292
- ok: 2 == (s.status / 100 | 0),
293
- statusText: s.statusText,
294
- status: s.status,
295
- url: s.responseURL,
296
- text: function () {
297
- return Promise.resolve(s.responseText);
298
- },
299
- json: function () {
300
- return Promise.resolve(s.responseText).then(JSON.parse);
301
- },
302
- blob: function () {
303
- return Promise.resolve(new Blob([s.response]));
304
- },
305
- clone: a,
306
- headers: {
307
- keys: function () {
308
- return o;
268
+ o = [],
269
+ u = [],
270
+ i = {},
271
+ a = function () {
272
+ return {
273
+ ok: 2 == (s.status / 100 | 0),
274
+ statusText: s.statusText,
275
+ status: s.status,
276
+ url: s.responseURL,
277
+ text: function () {
278
+ return Promise.resolve(s.responseText);
309
279
  },
310
- entries: function () {
311
- return u;
280
+ json: function () {
281
+ return Promise.resolve(s.responseText).then(JSON.parse);
312
282
  },
313
- get: function (e) {
314
- return i[e.toLowerCase()];
283
+ blob: function () {
284
+ return Promise.resolve(new Blob([s.response]));
315
285
  },
316
- has: function (e) {
317
- return e.toLowerCase() in i;
286
+ clone: a,
287
+ headers: {
288
+ keys: function () {
289
+ return o;
290
+ },
291
+ entries: function () {
292
+ return u;
293
+ },
294
+ get: function (e) {
295
+ return i[e.toLowerCase()];
296
+ },
297
+ has: function (e) {
298
+ return e.toLowerCase() in i;
299
+ }
318
300
  }
319
- }
301
+ };
320
302
  };
321
- };
322
-
323
303
  for (var l in s.open(n.method || "get", e, !0), s.onload = function () {
324
304
  s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (e, n, t) {
325
305
  o.push(n = n.toLowerCase()), u.push([n, t]), i[n] = i[n] ? i[n] + "," + t : t;
326
306
  }), t(a());
327
307
  }, s.onerror = r, s.withCredentials = "include" == n.credentials, n.headers) s.setRequestHeader(l, n.headers[l]);
328
-
329
308
  s.send(n.body || null);
330
309
  });
331
310
  }
@@ -337,17 +316,14 @@
337
316
  setTimeout(next, 100);
338
317
  return;
339
318
  }
340
-
341
319
  resolve(document.body);
342
320
  };
343
-
344
321
  next();
345
322
  });
346
323
  }
347
324
 
348
325
  function removeNode(node) {
349
326
  var parentNode = node.parentNode;
350
-
351
327
  if (parentNode) {
352
328
  parentNode.removeChild(node);
353
329
  }
@@ -355,7 +331,7 @@
355
331
 
356
332
  var createError = function createError(_ref) {
357
333
  var code = _ref.code,
358
- message = _ref.message;
334
+ message = _ref.message;
359
335
  var err = new Error(message);
360
336
  err.code = code;
361
337
  return err;
@@ -368,14 +344,12 @@
368
344
  message: token.identity_exception
369
345
  });
370
346
  }
371
-
372
347
  if ('oauth_exception' in token) {
373
348
  throw createError({
374
349
  code: 'SSO_OAUTH_EXCEPTION',
375
350
  message: token.oauth_exception
376
351
  });
377
352
  }
378
-
379
353
  return {
380
354
  accessToken: token.access_token,
381
355
  entityId: token.entity_id,
@@ -387,14 +361,12 @@
387
361
  };
388
362
 
389
363
  var ACCOUNTS_URL = "https://accounts.livechatinc.com";
390
-
391
364
  var buildPath = function buildPath(_ref) {
392
365
  var uniqueGroups = _ref.uniqueGroups,
393
- licenseId = _ref.licenseId,
394
- groupId = _ref.groupId;
366
+ licenseId = _ref.licenseId,
367
+ groupId = _ref.groupId;
395
368
  return (uniqueGroups ? "/licence/g" + licenseId + "_" + groupId : '') + "/customer";
396
369
  };
397
-
398
370
  var buildRequestUrl = function buildRequestUrl(config, env) {
399
371
  var url = env === 'production' ? ACCOUNTS_URL : ACCOUNTS_URL.replace('accounts.', "accounts." + env + ".");
400
372
  var path = buildPath(config);
@@ -403,14 +375,12 @@
403
375
 
404
376
  var POST_MESSAGE_ORIGIN = 'https://accounts.livechatinc.com';
405
377
  var CUSTOMER_AUTH_FOOTPRINT = '@livechat/customer-auth';
406
-
407
378
  var getPostMessageOrigin = function getPostMessageOrigin(env) {
408
379
  return env === 'production' ? POST_MESSAGE_ORIGIN : POST_MESSAGE_ORIGIN.replace('accounts.', "accounts." + env + ".");
409
380
  };
410
-
411
381
  var buildParams = function buildParams(_ref, redirectUri) {
412
382
  var clientId = _ref.clientId,
413
- licenseId = _ref.licenseId;
383
+ licenseId = _ref.licenseId;
414
384
  return {
415
385
  license_id: String(licenseId),
416
386
  flow: 'button',
@@ -421,7 +391,6 @@
421
391
  state: CUSTOMER_AUTH_FOOTPRINT
422
392
  };
423
393
  };
424
-
425
394
  var buildIframe = function buildIframe(config, env) {
426
395
  var redirectUri = getOrigin(String(window.location)) + window.location.pathname;
427
396
  var params = buildParams(config, redirectUri);
@@ -430,23 +399,19 @@
430
399
  iframe.setAttribute('src', buildRequestUrl(config, env) + "?" + buildQueryString(params));
431
400
  return iframe;
432
401
  };
433
-
434
402
  var isTokenResponse = function isTokenResponse(data) {
435
403
  return data && data.state === CUSTOMER_AUTH_FOOTPRINT;
436
404
  };
437
-
438
405
  function fetchUsingIframe(config, env) {
439
406
  var licenseId = config.licenseId;
440
407
  var postMessageOrigin = getPostMessageOrigin(env);
441
408
  return new Promise(function (resolve, reject) {
442
409
  var iframe = buildIframe(config, env);
443
-
444
410
  var cleanup = function cleanup() {
445
- removeNode(iframe); // eslint-disable-next-line no-use-before-define
446
-
411
+ removeNode(iframe);
412
+ // eslint-disable-next-line no-use-before-define
447
413
  window.removeEventListener('message', listener, false);
448
414
  };
449
-
450
415
  var timeoutId = setTimeout(function () {
451
416
  cleanup();
452
417
  reject(createError({
@@ -454,29 +419,23 @@
454
419
  code: 'REQUEST_TIMEOUT'
455
420
  }));
456
421
  }, 15 * 1000);
457
-
458
422
  var listener = function listener(_ref2) {
459
423
  var origin = _ref2.origin,
460
- data = _ref2.data;
461
-
424
+ data = _ref2.data;
462
425
  if (origin !== postMessageOrigin) {
463
426
  return;
464
427
  }
465
-
466
428
  if (!isTokenResponse(data)) {
467
429
  return;
468
430
  }
469
-
470
431
  clearTimeout(timeoutId);
471
432
  cleanup();
472
-
473
433
  try {
474
434
  resolve(parseTokenResponse(data, licenseId));
475
435
  } catch (err) {
476
436
  reject(err);
477
437
  }
478
438
  };
479
-
480
439
  window.addEventListener('message', listener, false);
481
440
  getRoot().then(function (body) {
482
441
  body.appendChild(iframe);
@@ -488,7 +447,6 @@
488
447
  if (config.uniqueGroups) {
489
448
  return fetchUsingIframe(config, env);
490
449
  }
491
-
492
450
  return unfetch(buildRequestUrl(config, env) + "/token", {
493
451
  method: 'POST',
494
452
  credentials: 'include',
@@ -508,8 +466,7 @@
508
466
 
509
467
  var validateConfig = function validateConfig(_ref) {
510
468
  var licenseId = _ref.licenseId,
511
- clientId = _ref.clientId;
512
-
469
+ clientId = _ref.clientId;
513
470
  if (typeof licenseId !== 'number' || typeof clientId !== 'string') {
514
471
  throw new Error('You need to pass valid configuration object: { licenseId, clientId }.');
515
472
  }
@@ -517,10 +474,9 @@
517
474
 
518
475
  var isExpiredToken = function isExpiredToken(_ref) {
519
476
  var creationDate = _ref.creationDate,
520
- expiresIn = _ref.expiresIn;
477
+ expiresIn = _ref.expiresIn;
521
478
  return Date.now() >= creationDate + expiresIn;
522
479
  };
523
-
524
480
  var createAuth = function createAuth(config, env) {
525
481
  validateConfig(config);
526
482
  var cacheKey = "" + "@@lc_auth_token:" + config.licenseId + (config.uniqueGroups ? ":" + config.groupId : '');
@@ -530,16 +486,12 @@
530
486
  if (retrievingToken === null) {
531
487
  return;
532
488
  }
533
-
534
489
  retrievingToken = null;
535
-
536
490
  if (!token) {
537
491
  return;
538
492
  }
539
-
540
493
  cachedToken = JSON.parse(token);
541
494
  });
542
-
543
495
  var getFreshToken = function getFreshToken() {
544
496
  pendingTokenRequest = fetchToken(config, env).then(function (token) {
545
497
  pendingTokenRequest = null;
@@ -552,37 +504,29 @@
552
504
  });
553
505
  return pendingTokenRequest;
554
506
  };
555
-
556
507
  var getToken = function getToken() {
557
508
  if (pendingTokenRequest) {
558
509
  return pendingTokenRequest;
559
510
  }
560
-
561
511
  if (cachedToken && !isExpiredToken(cachedToken)) {
562
512
  return Promise.resolve(cachedToken);
563
513
  }
564
-
565
514
  if (retrievingToken) {
566
515
  return retrievingToken.then(getToken);
567
516
  }
568
-
569
517
  return getFreshToken();
570
518
  };
571
-
572
519
  var hasToken = function hasToken() {
573
520
  if (retrievingToken) {
574
521
  return retrievingToken.then(hasToken);
575
522
  }
576
-
577
523
  return Promise.resolve(!!cachedToken);
578
524
  };
579
-
580
525
  var invalidate = function invalidate() {
581
526
  cachedToken = null;
582
527
  retrievingToken = null;
583
528
  return storage.removeItem(cacheKey);
584
529
  };
585
-
586
530
  return {
587
531
  getFreshToken: getFreshToken,
588
532
  getToken: getToken,
@@ -596,18 +540,15 @@
596
540
  // Our wrapper over `mitt` starts here
597
541
  var createMitt = function createMitt() {
598
542
  var _mitt = mitt(),
599
- all = _mitt.all,
600
- instance = _objectWithoutPropertiesLoose(_mitt, ["all"]);
601
-
543
+ all = _mitt.all,
544
+ instance = _objectWithoutPropertiesLoose(_mitt, ["all"]);
602
545
  var off = function off(type, handler) {
603
546
  if (!type) {
604
547
  all.clear();
605
548
  return;
606
549
  }
607
-
608
550
  instance.off(type, handler);
609
551
  };
610
-
611
552
  var once = function once(type, handler) {
612
553
  // for '*' type handler is invoked with 2 arguments - type, evt
613
554
  instance.on(type, function onceHandler(data, maybeSecondArg) {
@@ -615,7 +556,6 @@
615
556
  handler(data, maybeSecondArg);
616
557
  });
617
558
  };
618
-
619
559
  return _extends({}, instance, {
620
560
  off: off,
621
561
  once: once
@@ -687,7 +627,6 @@
687
627
  function symbolObservablePonyfill(root) {
688
628
  var result;
689
629
  var Symbol = root.Symbol;
690
-
691
630
  if (typeof Symbol === 'function') {
692
631
  if (Symbol.observable) {
693
632
  result = Symbol.observable;
@@ -698,13 +637,11 @@
698
637
  } else {
699
638
  result = '@@observable';
700
639
  }
701
-
702
640
  return result;
703
641
  }
704
642
 
705
643
  /* global window */
706
644
  var root;
707
-
708
645
  if (typeof self !== 'undefined') {
709
646
  root = self;
710
647
  } else if (typeof window !== 'undefined') {
@@ -716,7 +653,6 @@
716
653
  } else {
717
654
  root = Function('return this')();
718
655
  }
719
-
720
656
  var result = symbolObservablePonyfill(root);
721
657
 
722
658
  /**
@@ -725,11 +661,9 @@
725
661
  * If the current state is undefined, you must return the initial state.
726
662
  * Do not reference these action types directly in your code.
727
663
  */
728
-
729
664
  var randomString = function randomString() {
730
665
  return Math.random().toString(36).substring(7).split('').join('.');
731
666
  };
732
-
733
667
  var ActionTypes = {
734
668
  INIT: "@@redux/INIT" + randomString(),
735
669
  REPLACE: "@@redux/REPLACE" + randomString(),
@@ -737,21 +671,20 @@
737
671
  return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
738
672
  }
739
673
  };
674
+
740
675
  /**
741
676
  * @param {any} obj The object to inspect.
742
677
  * @returns {boolean} True if the argument appears to be a plain object.
743
678
  */
744
-
745
679
  function isPlainObject(obj) {
746
680
  if (typeof obj !== 'object' || obj === null) return false;
747
681
  var proto = obj;
748
-
749
682
  while (Object.getPrototypeOf(proto) !== null) {
750
683
  proto = Object.getPrototypeOf(proto);
751
684
  }
752
-
753
685
  return Object.getPrototypeOf(obj) === proto;
754
686
  }
687
+
755
688
  /**
756
689
  * Creates a Redux store that holds the state tree.
757
690
  * The only way to change the data in the store is to call `dispatch()` on it.
@@ -778,31 +711,24 @@
778
711
  * and subscribe to changes.
779
712
  */
780
713
 
781
-
782
714
  function createStore(reducer, preloadedState, enhancer) {
783
715
  var _ref2;
784
-
785
716
  if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
786
717
  throw new Error('It looks like you are passing several store enhancers to ' + 'createStore(). This is not supported. Instead, compose them ' + 'together to a single function.');
787
718
  }
788
-
789
719
  if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
790
720
  enhancer = preloadedState;
791
721
  preloadedState = undefined;
792
722
  }
793
-
794
723
  if (typeof enhancer !== 'undefined') {
795
724
  if (typeof enhancer !== 'function') {
796
725
  throw new Error('Expected the enhancer to be a function.');
797
726
  }
798
-
799
727
  return enhancer(createStore)(reducer, preloadedState);
800
728
  }
801
-
802
729
  if (typeof reducer !== 'function') {
803
730
  throw new Error('Expected the reducer to be a function.');
804
731
  }
805
-
806
732
  var currentReducer = reducer;
807
733
  var currentState = preloadedState;
808
734
  var currentListeners = [];
@@ -827,12 +753,10 @@
827
753
  * @returns {any} The current state tree of your application.
828
754
  */
829
755
 
830
-
831
756
  function getState() {
832
757
  if (isDispatching) {
833
758
  throw new Error('You may not call store.getState() while the reducer is executing. ' + 'The reducer has already received the state as an argument. ' + 'Pass it down from the top reducer instead of reading it from the store.');
834
759
  }
835
-
836
760
  return currentState;
837
761
  }
838
762
  /**
@@ -859,16 +783,13 @@
859
783
  * @returns {Function} A function to remove this change listener.
860
784
  */
861
785
 
862
-
863
786
  function subscribe(listener) {
864
787
  if (typeof listener !== 'function') {
865
788
  throw new Error('Expected the listener to be a function.');
866
789
  }
867
-
868
790
  if (isDispatching) {
869
791
  throw new Error('You may not call store.subscribe() while the reducer is executing. ' + 'If you would like to be notified after the store has been updated, subscribe from a ' + 'component and invoke store.getState() in the callback to access the latest state. ' + 'See https://redux.js.org/api-reference/store#subscribe(listener) for more details.');
870
792
  }
871
-
872
793
  var isSubscribed = true;
873
794
  ensureCanMutateNextListeners();
874
795
  nextListeners.push(listener);
@@ -876,11 +797,9 @@
876
797
  if (!isSubscribed) {
877
798
  return;
878
799
  }
879
-
880
800
  if (isDispatching) {
881
801
  throw new Error('You may not unsubscribe from a store listener while the reducer is executing. ' + 'See https://redux.js.org/api-reference/store#subscribe(listener) for more details.');
882
802
  }
883
-
884
803
  isSubscribed = false;
885
804
  ensureCanMutateNextListeners();
886
805
  var index = nextListeners.indexOf(listener);
@@ -913,34 +832,27 @@
913
832
  * return something else (for example, a Promise you can await).
914
833
  */
915
834
 
916
-
917
835
  function dispatch(action) {
918
836
  if (!isPlainObject(action)) {
919
837
  throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.');
920
838
  }
921
-
922
839
  if (typeof action.type === 'undefined') {
923
840
  throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?');
924
841
  }
925
-
926
842
  if (isDispatching) {
927
843
  throw new Error('Reducers may not dispatch actions.');
928
844
  }
929
-
930
845
  try {
931
846
  isDispatching = true;
932
847
  currentState = currentReducer(currentState, action);
933
848
  } finally {
934
849
  isDispatching = false;
935
850
  }
936
-
937
851
  var listeners = currentListeners = nextListeners;
938
-
939
852
  for (var i = 0; i < listeners.length; i++) {
940
853
  var listener = listeners[i];
941
854
  listener();
942
855
  }
943
-
944
856
  return action;
945
857
  }
946
858
  /**
@@ -954,12 +866,10 @@
954
866
  * @returns {void}
955
867
  */
956
868
 
957
-
958
869
  function replaceReducer(nextReducer) {
959
870
  if (typeof nextReducer !== 'function') {
960
871
  throw new Error('Expected the nextReducer to be a function.');
961
872
  }
962
-
963
873
  currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
964
874
  // Any reducers that existed in both the new and old rootReducer
965
875
  // will receive the previous state. This effectively populates
@@ -976,10 +886,8 @@
976
886
  * https://github.com/tc39/proposal-observable
977
887
  */
978
888
 
979
-
980
889
  function observable() {
981
890
  var _ref;
982
-
983
891
  var outerSubscribe = subscribe;
984
892
  return _ref = {
985
893
  /**
@@ -994,13 +902,11 @@
994
902
  if (typeof observer !== 'object' || observer === null) {
995
903
  throw new TypeError('Expected the observer to be an object.');
996
904
  }
997
-
998
905
  function observeState() {
999
906
  if (observer.next) {
1000
907
  observer.next(getState());
1001
908
  }
1002
909
  }
1003
-
1004
910
  observeState();
1005
911
  var unsubscribe = outerSubscribe(observeState);
1006
912
  return {
@@ -1014,7 +920,6 @@
1014
920
  // reducer returns their initial state. This effectively populates
1015
921
  // the initial state tree.
1016
922
 
1017
-
1018
923
  dispatch({
1019
924
  type: ActionTypes.INIT
1020
925
  });
@@ -1025,14 +930,13 @@
1025
930
  replaceReducer: replaceReducer
1026
931
  }, _ref2[result] = observable, _ref2;
1027
932
  }
933
+
1028
934
  /**
1029
935
  * Prints a warning in the console if it exists.
1030
936
  *
1031
937
  * @param {String} message The warning message.
1032
938
  * @returns {void}
1033
939
  */
1034
-
1035
-
1036
940
  function warning(message) {
1037
941
  /* eslint-disable no-console */
1038
942
  if (typeof console !== 'undefined' && typeof console.error === 'function') {
@@ -1040,16 +944,13 @@
1040
944
  }
1041
945
  /* eslint-enable no-console */
1042
946
 
1043
-
1044
947
  try {
1045
948
  // This error was thrown as a convenience so that if you enable
1046
949
  // "break on all exceptions" in your console,
1047
950
  // it would pause the execution at this line.
1048
951
  throw new Error(message);
1049
952
  } catch (e) {} // eslint-disable-line no-empty
1050
-
1051
953
  }
1052
-
1053
954
  function _defineProperty(obj, key, value) {
1054
955
  if (key in obj) {
1055
956
  Object.defineProperty(obj, key, {
@@ -1061,27 +962,21 @@
1061
962
  } else {
1062
963
  obj[key] = value;
1063
964
  }
1064
-
1065
965
  return obj;
1066
966
  }
1067
-
1068
967
  function ownKeys(object, enumerableOnly) {
1069
968
  var keys = Object.keys(object);
1070
-
1071
969
  if (Object.getOwnPropertySymbols) {
1072
970
  keys.push.apply(keys, Object.getOwnPropertySymbols(object));
1073
971
  }
1074
-
1075
972
  if (enumerableOnly) keys = keys.filter(function (sym) {
1076
973
  return Object.getOwnPropertyDescriptor(object, sym).enumerable;
1077
974
  });
1078
975
  return keys;
1079
976
  }
1080
-
1081
977
  function _objectSpread2(target) {
1082
978
  for (var i = 1; i < arguments.length; i++) {
1083
979
  var source = arguments[i] != null ? arguments[i] : {};
1084
-
1085
980
  if (i % 2) {
1086
981
  ownKeys(source, true).forEach(function (key) {
1087
982
  _defineProperty(target, key, source[key]);
@@ -1094,9 +989,9 @@
1094
989
  });
1095
990
  }
1096
991
  }
1097
-
1098
992
  return target;
1099
993
  }
994
+
1100
995
  /**
1101
996
  * Composes single-argument functions from right to left. The rightmost
1102
997
  * function can take multiple arguments as it provides the signature for
@@ -1107,29 +1002,25 @@
1107
1002
  * from right to left. For example, compose(f, g, h) is identical to doing
1108
1003
  * (...args) => f(g(h(...args))).
1109
1004
  */
1110
-
1111
-
1112
1005
  function compose() {
1113
1006
  for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
1114
1007
  funcs[_key] = arguments[_key];
1115
1008
  }
1116
-
1117
1009
  if (funcs.length === 0) {
1118
1010
  return function (arg) {
1119
1011
  return arg;
1120
1012
  };
1121
1013
  }
1122
-
1123
1014
  if (funcs.length === 1) {
1124
1015
  return funcs[0];
1125
1016
  }
1126
-
1127
1017
  return funcs.reduce(function (a, b) {
1128
1018
  return function () {
1129
1019
  return a(b.apply(void 0, arguments));
1130
1020
  };
1131
1021
  });
1132
1022
  }
1023
+
1133
1024
  /**
1134
1025
  * Creates a store enhancer that applies middleware to the dispatch method
1135
1026
  * of the Redux store. This is handy for a variety of tasks, such as expressing
@@ -1147,20 +1038,16 @@
1147
1038
  * @returns {Function} A store enhancer applying the middleware.
1148
1039
  */
1149
1040
 
1150
-
1151
1041
  function applyMiddleware() {
1152
1042
  for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) {
1153
1043
  middlewares[_key] = arguments[_key];
1154
1044
  }
1155
-
1156
1045
  return function (createStore) {
1157
1046
  return function () {
1158
1047
  var store = createStore.apply(void 0, arguments);
1159
-
1160
1048
  var _dispatch = function dispatch() {
1161
1049
  throw new Error('Dispatching while constructing your middleware is not allowed. ' + 'Other middleware would not be applied to this dispatch.');
1162
1050
  };
1163
-
1164
1051
  var middlewareAPI = {
1165
1052
  getState: store.getState,
1166
1053
  dispatch: function dispatch() {
@@ -1177,21 +1064,19 @@
1177
1064
  };
1178
1065
  };
1179
1066
  }
1067
+
1180
1068
  /*
1181
1069
  * This is a dummy function to check if the function name has been altered by minification.
1182
1070
  * If the function has been minified and NODE_ENV !== 'production', warn the user.
1183
1071
  */
1184
1072
 
1185
-
1186
1073
  function isCrushed() {}
1187
-
1188
1074
  if ( typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
1189
1075
  warning('You are currently using minified code outside of NODE_ENV === "production". ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or setting mode to production in webpack (https://webpack.js.org/concepts/mode/) ' + 'to ensure you have the correct code for your production build.');
1190
1076
  }
1191
1077
 
1192
1078
  var createSideEffectsMiddleware = function createSideEffectsMiddleware() {
1193
1079
  var handlers = [];
1194
-
1195
1080
  var sideEffectsMiddleware = function sideEffectsMiddleware(store) {
1196
1081
  return function (next) {
1197
1082
  return function (action) {
@@ -1203,11 +1088,9 @@
1203
1088
  };
1204
1089
  };
1205
1090
  };
1206
-
1207
1091
  sideEffectsMiddleware.add = function (handler) {
1208
1092
  handlers.push(handler);
1209
1093
  };
1210
-
1211
1094
  return sideEffectsMiddleware;
1212
1095
  };
1213
1096
 
@@ -1221,19 +1104,16 @@
1221
1104
  }
1222
1105
 
1223
1106
  var createReducer = function createReducer(initialState, reducersMap) {
1224
-
1225
1107
  return function reducer(state, action) {
1226
1108
  if (state === void 0) {
1227
1109
  state = initialState;
1228
1110
  }
1229
-
1230
1111
  if (hasOwn(action.type, reducersMap)) {
1231
1112
  return reducersMap[action.type](state, action.payload);
1232
1113
  }
1233
-
1234
1114
  return state;
1235
1115
  };
1236
- }; // TODO: this is the same as built-in redux's combineReducers, should be remobed
1116
+ };
1237
1117
 
1238
1118
  var CONNECTED = 'connected';
1239
1119
  var DESTROYED = 'destroyed';
@@ -1266,22 +1146,17 @@
1266
1146
  var isDestroyed = function isDestroyed(state) {
1267
1147
  return getConnectionStatus(state) === DESTROYED;
1268
1148
  };
1269
-
1270
1149
  var getEnvPart = function getEnvPart(_ref) {
1271
1150
  var licenseId = _ref.licenseId,
1272
- env = _ref.env;
1273
-
1151
+ env = _ref.env;
1274
1152
  if (licenseId === 1520) {
1275
1153
  return '.staging';
1276
1154
  }
1277
-
1278
1155
  if (env === 'production') {
1279
1156
  return '';
1280
1157
  }
1281
-
1282
1158
  return "." + env;
1283
1159
  };
1284
-
1285
1160
  var getApiOrigin = function getApiOrigin(state) {
1286
1161
  var region = state.region;
1287
1162
  var regionPart = region ? "-" + region : '';
@@ -1292,25 +1167,25 @@
1292
1167
  };
1293
1168
  var createInitialState = function createInitialState(initialStateData) {
1294
1169
  var _initialStateData$app = initialStateData.application,
1295
- application = _initialStateData$app === void 0 ? {} : _initialStateData$app,
1296
- licenseId = initialStateData.licenseId,
1297
- _initialStateData$gro = initialStateData.groupId,
1298
- groupId = _initialStateData$gro === void 0 ? null : _initialStateData$gro,
1299
- env = initialStateData.env,
1300
- _initialStateData$pag = initialStateData.page,
1301
- page = _initialStateData$pag === void 0 ? null : _initialStateData$pag,
1302
- _initialStateData$reg = initialStateData.region,
1303
- region = _initialStateData$reg === void 0 ? null : _initialStateData$reg,
1304
- _initialStateData$ref = initialStateData.referrer,
1305
- referrer = _initialStateData$ref === void 0 ? null : _initialStateData$ref,
1306
- _initialStateData$uni = initialStateData.uniqueGroups,
1307
- uniqueGroups = _initialStateData$uni === void 0 ? false : _initialStateData$uni,
1308
- _initialStateData$mob = initialStateData.mobile,
1309
- mobile = _initialStateData$mob === void 0 ? false : _initialStateData$mob;
1170
+ application = _initialStateData$app === void 0 ? {} : _initialStateData$app,
1171
+ licenseId = initialStateData.licenseId,
1172
+ _initialStateData$gro = initialStateData.groupId,
1173
+ groupId = _initialStateData$gro === void 0 ? null : _initialStateData$gro,
1174
+ env = initialStateData.env,
1175
+ _initialStateData$pag = initialStateData.page,
1176
+ page = _initialStateData$pag === void 0 ? null : _initialStateData$pag,
1177
+ _initialStateData$reg = initialStateData.region,
1178
+ region = _initialStateData$reg === void 0 ? null : _initialStateData$reg,
1179
+ _initialStateData$ref = initialStateData.referrer,
1180
+ referrer = _initialStateData$ref === void 0 ? null : _initialStateData$ref,
1181
+ _initialStateData$uni = initialStateData.uniqueGroups,
1182
+ uniqueGroups = _initialStateData$uni === void 0 ? false : _initialStateData$uni,
1183
+ _initialStateData$mob = initialStateData.mobile,
1184
+ mobile = _initialStateData$mob === void 0 ? false : _initialStateData$mob;
1310
1185
  return {
1311
1186
  application: _extends({}, application, {
1312
1187
  name: "customer_sdk",
1313
- version: "3.1.0"
1188
+ version: "3.1.2"
1314
1189
  }),
1315
1190
  licenseId: licenseId,
1316
1191
  env: env,
@@ -1334,18 +1209,14 @@
1334
1209
  mobile: mobile
1335
1210
  };
1336
1211
  };
1337
-
1338
1212
  var removeStoredRequest = function removeStoredRequest(state, _ref2) {
1339
1213
  var id = _ref2.id;
1340
-
1341
1214
  var _state$requests = state.requests,
1342
- requests = _objectWithoutPropertiesLoose(_state$requests, [id].map(_toPropertyKey));
1343
-
1215
+ requests = _objectWithoutPropertiesLoose(_state$requests, [id].map(_toPropertyKey));
1344
1216
  return _extends({}, state, {
1345
1217
  requests: requests
1346
1218
  });
1347
1219
  };
1348
-
1349
1220
  var setConnectionStatus = function setConnectionStatus(status, state) {
1350
1221
  return _extends({}, state, {
1351
1222
  connection: _extends({}, state.connection, {
@@ -1353,10 +1224,8 @@
1353
1224
  })
1354
1225
  });
1355
1226
  };
1356
-
1357
1227
  var createReducer$1 = (function (state) {
1358
1228
  var _createReducer;
1359
-
1360
1229
  return createReducer(state, (_createReducer = {}, _createReducer[CHANGE_REGION] = function (state, _ref3) {
1361
1230
  var region = _ref3.region;
1362
1231
  return _extends({}, state, {
@@ -1370,12 +1239,11 @@
1370
1239
  return setConnectionStatus(PAUSED, state);
1371
1240
  }, _createReducer[REQUEST_FAILED] = removeStoredRequest, _createReducer[RESPONSE_RECEIVED] = removeStoredRequest, _createReducer[PUSH_RESPONSE_RECEIVED] = removeStoredRequest, _createReducer[SEND_REQUEST] = function (state, _ref4) {
1372
1241
  var _extends2;
1373
-
1374
1242
  var promise = _ref4.promise,
1375
- resolve = _ref4.resolve,
1376
- reject = _ref4.reject,
1377
- id = _ref4.id,
1378
- request = _ref4.request;
1243
+ resolve = _ref4.resolve,
1244
+ reject = _ref4.reject,
1245
+ id = _ref4.id,
1246
+ request = _ref4.request;
1379
1247
  return _extends({}, state, {
1380
1248
  requests: _extends({}, state.requests, (_extends2 = {}, _extends2[id] = {
1381
1249
  id: id,
@@ -1387,9 +1255,8 @@
1387
1255
  });
1388
1256
  }, _createReducer[SET_CHAT_ACTIVE] = function (state, _ref5) {
1389
1257
  var _extends3;
1390
-
1391
1258
  var id = _ref5.id,
1392
- active = _ref5.active;
1259
+ active = _ref5.active;
1393
1260
  return _extends({}, state, {
1394
1261
  chats: _extends({}, state.chats, (_extends3 = {}, _extends3[id] = _extends({}, state.chats[id], {
1395
1262
  active: active
@@ -1405,11 +1272,9 @@
1405
1272
  });
1406
1273
  }, _createReducer[SOCKET_DISCONNECTED] = function (state) {
1407
1274
  var previousStatus = getConnectionStatus(state);
1408
-
1409
1275
  if ( (previousStatus === PAUSED || previousStatus === DESTROYED)) {
1410
1276
  throw new Error("Got 'socket_disconnected' action when in " + previousStatus + " state. This should be an impossible state.");
1411
1277
  }
1412
-
1413
1278
  var state1 = setConnectionStatus(previousStatus === DISCONNECTED ? DISCONNECTED : RECONNECTING, state);
1414
1279
  return _extends({}, state1, {
1415
1280
  requests: {}
@@ -1433,27 +1298,27 @@
1433
1298
 
1434
1299
  function createError$1(_ref) {
1435
1300
  var message = _ref.message,
1436
- code = _ref.code;
1301
+ code = _ref.code;
1437
1302
  var error = new Error(message);
1438
1303
  error.code = code;
1439
1304
  return error;
1440
1305
  }
1441
1306
 
1442
1307
  var ACCESS_TOKEN_EXPIRED = 'access_token_expired';
1443
- var CUSTOMER_BANNED = 'customer_banned'; // customer tried reconnecting too many times after they received too_many_connections error
1444
-
1308
+ var CUSTOMER_BANNED = 'customer_banned';
1309
+ // customer tried reconnecting too many times after they received too_many_connections error
1445
1310
  var CUSTOMER_TEMPORARILY_BLOCKED = 'customer_temporarily_blocked';
1446
1311
  var LICENSE_EXPIRED = 'license_expired';
1447
1312
  var LICENSE_NOT_FOUND = 'license_not_found';
1448
1313
  var MISDIRECTED_CONNECTION$1 = 'misdirected_connection';
1449
- var PRODUCT_VERSION_CHANGED = 'product_version_changed'; // the limit of connections per user host has been exceeded
1314
+ var PRODUCT_VERSION_CHANGED = 'product_version_changed';
1315
+ // the limit of connections per user host has been exceeded
1450
1316
  // or rate limit for new connections has been hit
1451
1317
  // (in 3.2 only the latter case, the first one is using `too_many_connections` to avoid breaking changes)
1452
-
1453
- var SERVICE_TEMPORARILY_UNAVAILABLE$1 = 'service_temporarily_unavailable'; // the limit of those connections is per user
1454
-
1455
- var TOO_MANY_CONNECTIONS = 'too_many_connections'; // the limit of unauthorized connections is per IP
1456
-
1318
+ var SERVICE_TEMPORARILY_UNAVAILABLE$1 = 'service_temporarily_unavailable';
1319
+ // the limit of those connections is per user
1320
+ var TOO_MANY_CONNECTIONS = 'too_many_connections';
1321
+ // the limit of unauthorized connections is per IP
1457
1322
  var TOO_MANY_UNAUTHORIZED_CONNECTIONS = 'too_many_unauthorized_connections';
1458
1323
  var UNSUPPORTED_VERSION = 'unsupported_version';
1459
1324
 
@@ -1522,20 +1387,17 @@
1522
1387
 
1523
1388
  var createEventBase = function createEventBase(event) {
1524
1389
  var base = {};
1525
-
1526
1390
  if (typeof event.customId === 'string') {
1527
1391
  base.custom_id = event.customId;
1528
1392
  }
1529
-
1530
1393
  if (isObject(event.properties)) {
1531
1394
  base.properties = event.properties;
1532
1395
  }
1533
-
1534
1396
  return base;
1535
- }; // TODO: we could validate and throw here
1536
- // but should we? maybe only in DEV mode?
1537
-
1397
+ };
1538
1398
 
1399
+ // TODO: we could validate and throw here
1400
+ // but should we? maybe only in DEV mode?
1539
1401
  var parseEvent = function parseEvent(event) {
1540
1402
  switch (event.type) {
1541
1403
  case MESSAGE:
@@ -1544,7 +1406,6 @@
1544
1406
  type: event.type,
1545
1407
  text: event.text
1546
1408
  });
1547
-
1548
1409
  if (event.postback) {
1549
1410
  message.postback = {
1550
1411
  id: event.postback.id,
@@ -1554,10 +1415,8 @@
1554
1415
  value: event.postback.value
1555
1416
  };
1556
1417
  }
1557
-
1558
1418
  return message;
1559
1419
  }
1560
-
1561
1420
  case FILE:
1562
1421
  {
1563
1422
  var file = _extends({}, createEventBase(event), {
@@ -1565,10 +1424,8 @@
1565
1424
  url: event.url,
1566
1425
  alternative_text: event.alternativeText
1567
1426
  });
1568
-
1569
1427
  return file;
1570
1428
  }
1571
-
1572
1429
  case FILLED_FORM:
1573
1430
  {
1574
1431
  var filledForm = _extends({}, createEventBase(event), {
@@ -1581,27 +1438,22 @@
1581
1438
  if (!field.answer) {
1582
1439
  return field;
1583
1440
  }
1584
-
1585
1441
  var _field$answer = field.answer,
1586
- groupId = _field$answer.groupId,
1587
- answer = _objectWithoutPropertiesLoose(_field$answer, ["groupId"]);
1588
-
1442
+ groupId = _field$answer.groupId,
1443
+ answer = _objectWithoutPropertiesLoose(_field$answer, ["groupId"]);
1589
1444
  return _extends({}, field, {
1590
1445
  answer: _extends({}, answer, {
1591
1446
  group_id: groupId
1592
1447
  })
1593
1448
  });
1594
1449
  }
1595
-
1596
1450
  default:
1597
1451
  return field;
1598
1452
  }
1599
1453
  })
1600
1454
  });
1601
-
1602
1455
  return filledForm;
1603
1456
  }
1604
-
1605
1457
  case SYSTEM_MESSAGE:
1606
1458
  {
1607
1459
  var systemMessage = _extends({}, createEventBase(event), {
@@ -1609,81 +1461,64 @@
1609
1461
  text: event.text,
1610
1462
  system_message_type: event.systemMessageType
1611
1463
  });
1612
-
1613
1464
  if (event.recipients) {
1614
1465
  systemMessage.recipients = event.recipients;
1615
1466
  }
1616
-
1617
1467
  return systemMessage;
1618
1468
  }
1619
-
1620
1469
  case CUSTOM:
1621
1470
  {
1622
1471
  var customEvent = _extends({}, createEventBase(event), {
1623
1472
  type: event.type
1624
1473
  });
1625
-
1626
1474
  if (event.content) {
1627
1475
  customEvent.content = event.content;
1628
1476
  }
1629
-
1630
1477
  return customEvent;
1631
1478
  }
1632
1479
  }
1633
1480
  };
1634
-
1635
1481
  var parseThreadData = function parseThreadData(thread) {
1636
1482
  var data = {};
1637
1483
  var events = thread.events,
1638
- properties = thread.properties;
1639
-
1484
+ properties = thread.properties;
1640
1485
  if (events) {
1641
1486
  data.events = events.map(parseEvent);
1642
1487
  }
1643
-
1644
1488
  if (properties) {
1645
1489
  data.properties = properties;
1646
1490
  }
1647
-
1648
1491
  return data;
1649
1492
  };
1650
-
1651
1493
  var parseStartChatData = function parseStartChatData(_ref) {
1652
1494
  var _ref$active = _ref.active,
1653
- active = _ref$active === void 0 ? true : _ref$active,
1654
- chat = _ref.chat,
1655
- continuous = _ref.continuous;
1495
+ active = _ref$active === void 0 ? true : _ref$active,
1496
+ chat = _ref.chat,
1497
+ continuous = _ref.continuous;
1656
1498
  var data = {
1657
1499
  active: active,
1658
1500
  chat: {}
1659
1501
  };
1660
-
1661
1502
  if (typeof continuous === 'boolean') {
1662
1503
  data.continuous = continuous;
1663
1504
  }
1664
-
1665
1505
  if (!chat) {
1666
1506
  return data;
1667
1507
  }
1668
-
1669
1508
  var access = chat.access,
1670
- thread = chat.thread,
1671
- properties = chat.properties;
1672
-
1509
+ thread = chat.thread,
1510
+ properties = chat.properties;
1673
1511
  if (access && access.groupIds) {
1674
1512
  data.chat.access = {
1675
1513
  group_ids: access.groupIds
1676
1514
  };
1677
1515
  }
1678
-
1679
1516
  if (properties) {
1680
1517
  data.chat.properties = properties;
1681
1518
  }
1682
-
1683
1519
  if (thread) {
1684
1520
  data.chat.thread = parseThreadData(thread);
1685
1521
  }
1686
-
1687
1522
  return data;
1688
1523
  };
1689
1524
  var parseResumeChatData = function parseResumeChatData(requestData) {
@@ -1697,19 +1532,16 @@
1697
1532
  var parseCustomerSessionFields = function parseCustomerSessionFields(sessionFields) {
1698
1533
  return toPairs(sessionFields).map(function (_ref2) {
1699
1534
  var _ref3;
1700
-
1701
1535
  var key = _ref2[0],
1702
- value = _ref2[1];
1536
+ value = _ref2[1];
1703
1537
  return _ref3 = {}, _ref3[key] = value, _ref3;
1704
1538
  });
1705
1539
  };
1706
1540
  var parseCustomerUpdate = function parseCustomerUpdate(update) {
1707
1541
  var result = pickOwn(['avatar', 'name', 'email'], update);
1708
-
1709
1542
  if (update.sessionFields) {
1710
1543
  result.session_fields = parseCustomerSessionFields(update.sessionFields);
1711
1544
  }
1712
-
1713
1545
  return result;
1714
1546
  };
1715
1547
 
@@ -1739,7 +1571,6 @@
1739
1571
  if (fresh === void 0) {
1740
1572
  fresh = false;
1741
1573
  }
1742
-
1743
1574
  return {
1744
1575
  type: PREFETCH_TOKEN,
1745
1576
  payload: {
@@ -1754,9 +1585,10 @@
1754
1585
  delay: delay
1755
1586
  }
1756
1587
  };
1757
- }; // TODO: this one was currently pretty hard to type in full
1758
- // we should explore providing stricter types for this in the future
1588
+ };
1759
1589
 
1590
+ // TODO: this one was currently pretty hard to type in full
1591
+ // we should explore providing stricter types for this in the future
1760
1592
  var sendRequest = function sendRequest(action, payload, source) {
1761
1593
  return {
1762
1594
  type: SEND_REQUEST,
@@ -1772,17 +1604,15 @@
1772
1604
  };
1773
1605
  var sendEvent = function sendEvent(_ref) {
1774
1606
  var chatId = _ref.chatId,
1775
- event = _ref.event,
1776
- attachToLastThread = _ref.attachToLastThread;
1607
+ event = _ref.event,
1608
+ attachToLastThread = _ref.attachToLastThread;
1777
1609
  var payload = {
1778
1610
  chat_id: chatId,
1779
1611
  event: parseEvent(event)
1780
1612
  };
1781
-
1782
1613
  if (attachToLastThread) {
1783
1614
  payload.attach_to_last_thread = true;
1784
1615
  }
1785
-
1786
1616
  return sendRequest(SEND_EVENT, payload);
1787
1617
  };
1788
1618
  var setChatActive = function setChatActive(id, active) {
@@ -1811,12 +1641,10 @@
1811
1641
  // TODO: this thing is not really well typed and should be improved
1812
1642
  var sendRequestAction = function sendRequestAction(store, action) {
1813
1643
  action.payload.id = generateUniqueId(store.getState().requests);
1814
-
1815
1644
  var _deferred = deferred(),
1816
- resolve = _deferred.resolve,
1817
- reject = _deferred.reject,
1818
- promise = _deferred.promise;
1819
-
1645
+ resolve = _deferred.resolve,
1646
+ reject = _deferred.reject,
1647
+ promise = _deferred.promise;
1820
1648
  action.payload.promise = promise;
1821
1649
  action.payload.resolve = resolve;
1822
1650
  action.payload.reject = reject;
@@ -1832,22 +1660,20 @@
1832
1660
 
1833
1661
  var createBackoff = function createBackoff(_ref) {
1834
1662
  var _ref$min = _ref.min,
1835
- min = _ref$min === void 0 ? 1000 : _ref$min,
1836
- _ref$max = _ref.max,
1837
- max = _ref$max === void 0 ? 5000 : _ref$max,
1838
- _ref$jitter = _ref.jitter,
1839
- jitter = _ref$jitter === void 0 ? 0.5 : _ref$jitter;
1663
+ min = _ref$min === void 0 ? 1000 : _ref$min,
1664
+ _ref$max = _ref.max,
1665
+ max = _ref$max === void 0 ? 5000 : _ref$max,
1666
+ _ref$jitter = _ref.jitter,
1667
+ jitter = _ref$jitter === void 0 ? 0.5 : _ref$jitter;
1840
1668
  var attempts = 0;
1841
1669
  return {
1842
1670
  duration: function duration() {
1843
1671
  var ms = min * Math.pow(2, attempts++);
1844
-
1845
1672
  if (jitter) {
1846
1673
  var rand = Math.random();
1847
1674
  var deviation = Math.floor(rand * jitter * ms);
1848
1675
  ms = (Math.floor(rand * 10) & 1) === 0 ? ms - deviation : ms + deviation;
1849
1676
  }
1850
-
1851
1677
  return Math.min(ms, max) | 0;
1852
1678
  },
1853
1679
  reset: function reset() {
@@ -1863,17 +1689,16 @@
1863
1689
 
1864
1690
  var getSideStorageKey = function getSideStorageKey(store) {
1865
1691
  var _store$getState = store.getState(),
1866
- licenseId = _store$getState.licenseId,
1867
- groupId = _store$getState.groupId,
1868
- uniqueGroups = _store$getState.uniqueGroups;
1869
-
1692
+ licenseId = _store$getState.licenseId,
1693
+ groupId = _store$getState.groupId,
1694
+ uniqueGroups = _store$getState.uniqueGroups;
1870
1695
  return "side_storage_" + licenseId + (uniqueGroups ? ":" + groupId : '');
1871
1696
  };
1872
-
1873
1697
  var getSideStorage = function getSideStorage(store) {
1874
1698
  return storage.getItem(getSideStorageKey(store))["catch"](noop).then(function (sideStorage) {
1875
1699
  return JSON.parse(sideStorage || '{}');
1876
- }) // shouldnt get triggered, just a defensive measure against malformed storage entries
1700
+ })
1701
+ // shouldnt get triggered, just a defensive measure against malformed storage entries
1877
1702
  ["catch"](function () {
1878
1703
  return {};
1879
1704
  });
@@ -1884,9 +1709,7 @@
1884
1709
 
1885
1710
  var taskChain = function taskChain(_ref, onSuccess, onError) {
1886
1711
  var steps = _ref.slice(0);
1887
-
1888
1712
  var cancelled = false;
1889
-
1890
1713
  var next = function next(intermediateResult) {
1891
1714
  var step = steps.shift();
1892
1715
  promiseTry(function () {
@@ -1895,22 +1718,18 @@
1895
1718
  if (cancelled) {
1896
1719
  return;
1897
1720
  }
1898
-
1899
1721
  if (steps.length) {
1900
1722
  next(result);
1901
1723
  return;
1902
1724
  }
1903
-
1904
1725
  onSuccess(result);
1905
1726
  }, function (error) {
1906
1727
  if (cancelled) {
1907
1728
  return;
1908
1729
  }
1909
-
1910
1730
  onError(error);
1911
1731
  });
1912
1732
  };
1913
-
1914
1733
  next();
1915
1734
  return {
1916
1735
  cancel: function cancel() {
@@ -1918,17 +1737,14 @@
1918
1737
  }
1919
1738
  };
1920
1739
  };
1921
-
1922
1740
  var sendLoginFlowRequest = function sendLoginFlowRequest(store, type, payload) {
1923
1741
  return sendRequestAction(store, sendRequest(type, payload, 'login'));
1924
1742
  };
1925
-
1926
1743
  var delay = function delay(ms) {
1927
1744
  return new Promise(function (resolve) {
1928
1745
  setTimeout(resolve, ms);
1929
1746
  });
1930
1747
  };
1931
-
1932
1748
  function createLoginTask(auth, customerDataProvider) {
1933
1749
  var store;
1934
1750
  var sentPage = null;
@@ -1943,24 +1759,19 @@
1943
1759
  min: 1000
1944
1760
  }));
1945
1761
  var currentBackoffStrategy = defaultBackoffStrategy;
1946
-
1947
1762
  var destroy$1 = function destroy$1(reason) {
1948
1763
  return store.dispatch(destroy(reason));
1949
1764
  };
1950
-
1951
1765
  var reconnect$1 = function reconnect$1() {
1952
1766
  return store.dispatch(reconnect(currentBackoffStrategy.duration()));
1953
1767
  };
1954
-
1955
1768
  var getTokenAndSideStorage = function getTokenAndSideStorage() {
1956
1769
  return Promise.all([auth.getToken(), getSideStorage(store)]);
1957
1770
  };
1958
-
1959
1771
  var dispatchSelfId = function dispatchSelfId(_ref2) {
1960
1772
  var token = _ref2[0],
1961
- sideStorage = _ref2[1];
1773
+ sideStorage = _ref2[1];
1962
1774
  var selfId = getSelfId(store.getState());
1963
-
1964
1775
  if (selfId === null) {
1965
1776
  store.dispatch(setSelfId(token.entityId));
1966
1777
  } else if (selfId !== token.entityId) {
@@ -1968,19 +1779,17 @@
1968
1779
  err.code = IDENTITY_MISMATCH;
1969
1780
  throw err;
1970
1781
  }
1971
-
1972
1782
  return [token, sideStorage];
1973
1783
  };
1974
-
1975
1784
  var _sendLogin = function sendLogin(_ref3) {
1976
1785
  var token = _ref3[0],
1977
- sideStorage = _ref3[1];
1786
+ sideStorage = _ref3[1];
1978
1787
  var state = store.getState();
1979
1788
  var application = state.application,
1980
- groupId = state.groupId,
1981
- page = state.page,
1982
- referrer = state.referrer,
1983
- mobile = state.mobile;
1789
+ groupId = state.groupId,
1790
+ page = state.page,
1791
+ referrer = state.referrer,
1792
+ mobile = state.mobile;
1984
1793
  var payload = {
1985
1794
  token: token.tokenType + " " + token.accessToken,
1986
1795
  customer: typeof customerDataProvider === 'function' ? parseCustomerUpdate(customerDataProvider()) : {},
@@ -1988,24 +1797,19 @@
1988
1797
  is_mobile: mobile,
1989
1798
  application: pick(['name', 'version'], application)
1990
1799
  };
1991
-
1992
1800
  if (typeof groupId === 'number') {
1993
1801
  payload.group_id = groupId;
1994
1802
  }
1995
-
1996
1803
  if (application.channelType) {
1997
1804
  payload.application.channel_type = application.channelType;
1998
1805
  }
1999
-
2000
1806
  if (page !== null) {
2001
1807
  sentPage = page;
2002
1808
  payload.customer_page = page;
2003
1809
  }
2004
-
2005
1810
  if (referrer !== null) {
2006
1811
  payload.referrer = referrer;
2007
1812
  }
2008
-
2009
1813
  return Promise.race([sendLoginFlowRequest(store, LOGIN, payload), delay(15 * 1000).then(function () {
2010
1814
  return Promise.reject(createError$1({
2011
1815
  message: 'Request timed out.',
@@ -2013,22 +1817,17 @@
2013
1817
  }));
2014
1818
  })]);
2015
1819
  };
2016
-
2017
1820
  var updateCustomerPageIfNeeded = function updateCustomerPageIfNeeded() {
2018
1821
  var _store$getState = store.getState(),
2019
- page = _store$getState.page;
2020
-
1822
+ page = _store$getState.page;
2021
1823
  if (sentPage !== page) {
2022
1824
  sendLoginFlowRequest(store, UPDATE_CUSTOMER_PAGE$1, page)["catch"](noop);
2023
1825
  }
2024
-
2025
1826
  sentPage = null;
2026
1827
  };
2027
-
2028
1828
  return {
2029
1829
  sendLogin: function sendLogin(_store) {
2030
1830
  var _task;
2031
-
2032
1831
  // after switching to callbags, we should be able to use smth similar to redux-observable
2033
1832
  // and thus just use store given to epic
2034
1833
  store = _store;
@@ -2037,62 +1836,52 @@
2037
1836
  task = null;
2038
1837
  defaultBackoffStrategy.reset();
2039
1838
  slowerBackoffStrategy.reset();
2040
- currentBackoffStrategy = defaultBackoffStrategy; // TODO: rethink if this should be handled by SDK consumer
1839
+ currentBackoffStrategy = defaultBackoffStrategy;
2041
1840
 
1841
+ // TODO: rethink if this should be handled by SDK consumer
2042
1842
  updateCustomerPageIfNeeded();
2043
1843
  store.dispatch(loginSuccess(loginResponse));
2044
1844
  }, function (error) {
2045
1845
  task = null;
2046
-
2047
1846
  {
2048
1847
  console.error('[Customer SDK] Login flow has thrown code', error.code, 'with', error);
2049
1848
  }
2050
-
2051
1849
  switch (error.code) {
2052
1850
  case AUTHENTICATION:
2053
1851
  auth.getFreshToken();
2054
1852
  reconnect$1();
2055
1853
  return;
2056
-
2057
1854
  case CONNECTION_LOST:
2058
1855
  // this is connectivity problem, not a server error
2059
1856
  // and is taken care of in socket module
2060
1857
  // as it has its own backoff implementation
2061
1858
  return;
2062
-
2063
1859
  case MISDIRECTED_CONNECTION:
2064
1860
  // socket gets reinitialized on this anyway, so just ignore it here
2065
1861
  return;
2066
-
2067
1862
  case SDK_DESTROYED:
2068
1863
  return;
2069
1864
  // those are auth errors, we should maybe export those constants from the auth package
2070
-
2071
1865
  case 'SSO_IDENTITY_EXCEPTION':
2072
1866
  case 'SSO_OAUTH_EXCEPTION':
2073
1867
  if (error.message === 'server_error' || error.message === 'temporarily_unavailable') {
2074
1868
  reconnect$1();
2075
1869
  return;
2076
1870
  }
2077
-
2078
1871
  destroy$1(error.message);
2079
1872
  return;
2080
-
2081
1873
  case USERS_LIMIT_REACHED:
2082
1874
  store.dispatch(pauseConnection(error.code.toLowerCase()));
2083
1875
  return;
2084
-
2085
1876
  case IDENTITY_MISMATCH:
2086
1877
  case CUSTOMER_BANNED$1:
2087
1878
  case WRONG_PRODUCT_VERSION:
2088
1879
  destroy$1(error.code.toLowerCase());
2089
1880
  return;
2090
-
2091
1881
  case SERVICE_TEMPORARILY_UNAVAILABLE:
2092
1882
  currentBackoffStrategy = slowerBackoffStrategy;
2093
1883
  reconnect$1();
2094
1884
  return;
2095
-
2096
1885
  default:
2097
1886
  reconnect$1();
2098
1887
  return;
@@ -2101,7 +1890,6 @@
2101
1890
  },
2102
1891
  cancel: function cancel() {
2103
1892
  var _task2;
2104
-
2105
1893
  (_task2 = task) == null ? void 0 : _task2.cancel();
2106
1894
  }
2107
1895
  };
@@ -2110,17 +1898,13 @@
2110
1898
  var checkGoals = function checkGoals(store, auth, sessionFields) {
2111
1899
  return auth.getToken().then(function (token) {
2112
1900
  var state = store.getState();
2113
-
2114
1901
  if (getSelfId(state) === null) {
2115
1902
  store.dispatch(setSelfId(token.entityId));
2116
1903
  }
2117
-
2118
1904
  var page = state.page;
2119
-
2120
1905
  if (!page || !page.url) {
2121
1906
  return;
2122
1907
  }
2123
-
2124
1908
  var query = buildQueryString({
2125
1909
  license_id: state.licenseId
2126
1910
  });
@@ -2145,7 +1929,7 @@
2145
1929
 
2146
1930
  var failAllRequests = function failAllRequests(_ref, reason) {
2147
1931
  var getState = _ref.getState,
2148
- dispatch = _ref.dispatch;
1932
+ dispatch = _ref.dispatch;
2149
1933
  var state = getState();
2150
1934
  var requests = getAllRequests(state);
2151
1935
  dispatch({
@@ -2160,7 +1944,7 @@
2160
1944
  };
2161
1945
  var failRequest = function failRequest(_ref2, requestAction, error) {
2162
1946
  var getState = _ref2.getState,
2163
- dispatch = _ref2.dispatch;
1947
+ dispatch = _ref2.dispatch;
2164
1948
  var requestId = requestAction.payload.id;
2165
1949
  dispatch({
2166
1950
  type: REQUEST_FAILED,
@@ -2184,22 +1968,17 @@
2184
1968
  threadId: threadId,
2185
1969
  properties: event.properties || {}
2186
1970
  };
2187
-
2188
1971
  if (event.custom_id !== undefined) {
2189
1972
  parsed.customId = event.custom_id;
2190
1973
  }
2191
-
2192
1974
  return parsed;
2193
1975
  };
2194
-
2195
1976
  var downsizeWithRatio = function downsizeWithRatio(max, dimensions) {
2196
1977
  var _ref;
2197
-
2198
1978
  var biggerProp;
2199
1979
  var smallerProp;
2200
1980
  var bigger;
2201
1981
  var smaller;
2202
-
2203
1982
  if (dimensions.height > dimensions.width) {
2204
1983
  biggerProp = 'height';
2205
1984
  smallerProp = 'width';
@@ -2211,11 +1990,9 @@
2211
1990
  bigger = dimensions.width;
2212
1991
  smaller = dimensions.height;
2213
1992
  }
2214
-
2215
1993
  var ratio = max / bigger;
2216
1994
  return _ref = {}, _ref[biggerProp] = Math.ceil(Math.min(bigger, max)), _ref[smallerProp] = Math.ceil(Math.min(ratio * smaller, smaller)), _ref;
2217
1995
  };
2218
-
2219
1996
  var parseImage = function parseImage(thread, image) {
2220
1997
  return _extends({}, parseCommonEventProps(thread, image), {
2221
1998
  type: FILE,
@@ -2236,12 +2013,10 @@
2236
2013
  alternativeText: image.alternative_text
2237
2014
  });
2238
2015
  };
2239
-
2240
2016
  var parseFile = function parseFile(thread, file) {
2241
2017
  if (file.width !== undefined && file.height !== undefined) {
2242
2018
  return parseImage(thread, file);
2243
2019
  }
2244
-
2245
2020
  return _extends({}, parseCommonEventProps(thread, file), {
2246
2021
  type: FILE,
2247
2022
  contentType: file.content_type,
@@ -2268,18 +2043,15 @@
2268
2043
  if (!field.answer) {
2269
2044
  return field;
2270
2045
  }
2271
-
2272
2046
  var _field$answer = field.answer,
2273
- groupId = _field$answer.group_id,
2274
- answer = _objectWithoutPropertiesLoose(_field$answer, ["group_id"]);
2275
-
2047
+ groupId = _field$answer.group_id,
2048
+ answer = _objectWithoutPropertiesLoose(_field$answer, ["group_id"]);
2276
2049
  return _extends({}, field, {
2277
2050
  answer: _extends({}, answer, {
2278
2051
  groupId: groupId
2279
2052
  })
2280
2053
  });
2281
2054
  }
2282
-
2283
2055
  default:
2284
2056
  return field;
2285
2057
  }
@@ -2299,18 +2071,14 @@
2299
2071
  content: event.content
2300
2072
  });
2301
2073
  };
2302
-
2303
2074
  var parseRichMessageElement = function parseRichMessageElement(element) {
2304
2075
  var parsed = {};
2305
-
2306
2076
  if (typeof element.title === 'string') {
2307
2077
  parsed.title = element.title;
2308
2078
  }
2309
-
2310
2079
  if (typeof element.subtitle === 'string') {
2311
2080
  parsed.subtitle = element.subtitle;
2312
2081
  }
2313
-
2314
2082
  if (element.image) {
2315
2083
  // TODO: we should reuse parseImage here
2316
2084
  var image = element.image;
@@ -2321,7 +2089,6 @@
2321
2089
  alternativeText: image.alternative_text
2322
2090
  });
2323
2091
  }
2324
-
2325
2092
  if (element.buttons) {
2326
2093
  parsed.buttons = element.buttons.map(function (serverButton) {
2327
2094
  switch (serverButton.type) {
@@ -2337,7 +2104,6 @@
2337
2104
  role: serverButton.role || 'default'
2338
2105
  };
2339
2106
  }
2340
-
2341
2107
  case 'cancel':
2342
2108
  {
2343
2109
  return {
@@ -2348,7 +2114,6 @@
2348
2114
  role: serverButton.role || 'default'
2349
2115
  };
2350
2116
  }
2351
-
2352
2117
  case 'url':
2353
2118
  {
2354
2119
  var button = {
@@ -2359,14 +2124,11 @@
2359
2124
  value: serverButton.value,
2360
2125
  role: serverButton.role || 'default'
2361
2126
  };
2362
-
2363
2127
  if (serverButton.target) {
2364
2128
  button.target = serverButton.target;
2365
2129
  }
2366
-
2367
2130
  return button;
2368
2131
  }
2369
-
2370
2132
  case 'webview':
2371
2133
  {
2372
2134
  var _button = {
@@ -2377,14 +2139,11 @@
2377
2139
  value: serverButton.value,
2378
2140
  role: serverButton.role || 'default'
2379
2141
  };
2380
-
2381
2142
  if (typeof serverButton.webview_height === 'string') {
2382
2143
  _button.webviewHeight = serverButton.webview_height;
2383
2144
  }
2384
-
2385
2145
  return _button;
2386
2146
  }
2387
-
2388
2147
  default:
2389
2148
  {
2390
2149
  return {
@@ -2397,10 +2156,8 @@
2397
2156
  }
2398
2157
  });
2399
2158
  }
2400
-
2401
2159
  return parsed;
2402
2160
  };
2403
-
2404
2161
  var parseRichMessage = function parseRichMessage(thread, richMessage) {
2405
2162
  switch (richMessage.template_id) {
2406
2163
  case 'cards':
@@ -2411,7 +2168,6 @@
2411
2168
  template: richMessage.template_id,
2412
2169
  elements: richMessage.elements.map(parseRichMessageElement)
2413
2170
  });
2414
-
2415
2171
  default:
2416
2172
  return null;
2417
2173
  }
@@ -2424,36 +2180,27 @@
2424
2180
  text: systemMessage.text,
2425
2181
  systemMessageType: systemMessage.system_message_type
2426
2182
  });
2427
-
2428
2183
  if (systemMessage.text_vars) {
2429
2184
  parsed.textVars = systemMessage.text_vars;
2430
2185
  }
2431
-
2432
2186
  return parsed;
2433
2187
  };
2434
2188
  var parseEvent$1 = function parseEvent(thread, event) {
2435
2189
  switch (event.type) {
2436
2190
  case FILE:
2437
2191
  return parseFile(thread, event);
2438
-
2439
2192
  case FORM:
2440
2193
  return parseForm(thread, event);
2441
-
2442
2194
  case FILLED_FORM:
2443
2195
  return parseFilledForm(thread, event);
2444
-
2445
2196
  case MESSAGE:
2446
2197
  return parseMessage(thread, event);
2447
-
2448
2198
  case RICH_MESSAGE:
2449
2199
  return parseRichMessage(thread, event);
2450
-
2451
2200
  case SYSTEM_MESSAGE:
2452
2201
  return parseSystemMessage(thread, event);
2453
-
2454
2202
  case CUSTOM:
2455
2203
  return parseCustomEvent(thread, event);
2456
-
2457
2204
  default:
2458
2205
  return null;
2459
2206
  }
@@ -2478,23 +2225,20 @@
2478
2225
  };
2479
2226
  };
2480
2227
 
2228
+ // we could use `mergeAll` for this, but we need to preserve insertion order here
2481
2229
  // so it's better to rely on a custom implementation
2482
-
2483
2230
  var parseCustomerSessionFields$1 = function parseCustomerSessionFields(sessionFields) {
2484
2231
  return sessionFields.reduce(function (acc, field) {
2485
2232
  var _Object$keys = Object.keys(field),
2486
- key = _Object$keys[0];
2487
-
2233
+ key = _Object$keys[0];
2488
2234
  acc[key] = field[key];
2489
2235
  return acc;
2490
2236
  }, {});
2491
2237
  };
2492
-
2493
2238
  var parseAccess = function parseAccess(access) {
2494
2239
  if (access === void 0) {
2495
2240
  access = {};
2496
2241
  }
2497
-
2498
2242
  return access.group_ids ? {
2499
2243
  groupIds: access.group_ids
2500
2244
  } : {};
@@ -2546,14 +2290,11 @@
2546
2290
  };
2547
2291
  var parseCustomerOptionalProps = function parseCustomerOptionalProps(customerProps) {
2548
2292
  var optionalProps = pickOwn(['avatar', 'email', 'name'], customerProps);
2549
-
2550
2293
  if (customerProps.session_fields) {
2551
2294
  optionalProps.sessionFields = parseCustomerSessionFields$1(customerProps.session_fields);
2552
2295
  }
2553
-
2554
2296
  return optionalProps;
2555
2297
  };
2556
-
2557
2298
  var parseCustomerCommonProps = function parseCustomerCommonProps(customer) {
2558
2299
  var optionalProps = parseCustomerOptionalProps(customer);
2559
2300
  return _extends({
@@ -2563,7 +2304,6 @@
2563
2304
  sessionFields: optionalProps.sessionFields || {}
2564
2305
  });
2565
2306
  };
2566
-
2567
2307
  var parseChatCustomer = function parseChatCustomer(customer) {
2568
2308
  return _extends({}, parseCustomerCommonProps(customer), {
2569
2309
  present: customer.present
@@ -2584,7 +2324,7 @@
2584
2324
  };
2585
2325
  var parsePredictedAgent = function parsePredictedAgent(payload) {
2586
2326
  var agent = payload.agent,
2587
- queue = payload.queue;
2327
+ queue = payload.queue;
2588
2328
  return {
2589
2329
  agent: {
2590
2330
  id: agent.id,
@@ -2617,12 +2357,11 @@
2617
2357
 
2618
2358
  var _FAIL_ALL_REQUESTS_ME;
2619
2359
 
2360
+ // TODO: rethink how we handle reconnects
2620
2361
  var SMALL_RECONNECT_DELAY = 100;
2621
2362
  var FAIL_ALL_REQUESTS_MESSAGES = (_FAIL_ALL_REQUESTS_ME = {}, _FAIL_ALL_REQUESTS_ME[CONNECTION_LOST] = 'Connection lost.', _FAIL_ALL_REQUESTS_ME[MISDIRECTED_CONNECTION] = 'Connected to wrong region.', _FAIL_ALL_REQUESTS_ME);
2622
-
2623
2363
  var updateStateIfNeeded = function updateStateIfNeeded(store, action) {
2624
2364
  var state = store.getState();
2625
-
2626
2365
  switch (action.type) {
2627
2366
  case PUSH_RESPONSE_RECEIVED:
2628
2367
  case PUSH_RECEIVED:
@@ -2630,45 +2369,37 @@
2630
2369
  case CHAT_DEACTIVATED:
2631
2370
  store.dispatch(setChatActive(action.payload.payload.chatId, false));
2632
2371
  return;
2633
-
2634
2372
  case INCOMING_CHAT:
2635
2373
  store.dispatch(setChatActive(action.payload.payload.chat.id, true));
2636
2374
  return;
2637
-
2638
2375
  default:
2639
2376
  return;
2640
2377
  }
2641
-
2642
2378
  case RESPONSE_RECEIVED:
2643
2379
  switch (action.payload.action) {
2644
2380
  case LIST_CHATS:
2645
2381
  action.payload.payload.chatsSummary.filter(function (_ref) {
2646
2382
  var id = _ref.id,
2647
- active = _ref.active;
2383
+ active = _ref.active;
2648
2384
  return isChatActive(state, id) !== active;
2649
2385
  }).forEach(function (_ref2) {
2650
2386
  var id = _ref2.id,
2651
- active = _ref2.active;
2387
+ active = _ref2.active;
2652
2388
  store.dispatch(setChatActive(id, active));
2653
2389
  });
2654
2390
  return;
2655
-
2656
2391
  default:
2657
2392
  return;
2658
2393
  }
2659
-
2660
2394
  }
2661
2395
  };
2662
-
2663
2396
  var sendRequest$1 = function sendRequest(socket, _ref3) {
2664
2397
  var _ref3$payload = _ref3.payload,
2665
- id = _ref3$payload.id,
2666
- request = _ref3$payload.request;
2667
-
2398
+ id = _ref3$payload.id,
2399
+ request = _ref3$payload.request;
2668
2400
  var frame = _extends({
2669
2401
  request_id: id
2670
2402
  }, request);
2671
-
2672
2403
  switch (frame.action) {
2673
2404
  case LOGIN:
2674
2405
  {
@@ -2679,7 +2410,8 @@
2679
2410
  pushes: {
2680
2411
  // '3.4': upgradedPushes,
2681
2412
  '3.3': values(serverPushActions).filter(function (pushAction) {
2682
- return (// `customer_disconnected` can be sent immediately after opening the connection, before it even received login request
2413
+ return (
2414
+ // `customer_disconnected` can be sent immediately after opening the connection, before it even received login request
2683
2415
  // therefore it's not possible to subscribe for a particular version of this push - the "connection version" is always used
2684
2416
  pushAction !== CUSTOMER_DISCONNECTED && !includes(pushAction, upgradedPushes)
2685
2417
  );
@@ -2689,56 +2421,45 @@
2689
2421
  }));
2690
2422
  return;
2691
2423
  }
2692
-
2693
2424
  default:
2694
2425
  socket.emit(frame);
2695
2426
  return;
2696
2427
  }
2697
2428
  };
2698
-
2699
2429
  var emitUsers = function emitUsers(emit, users) {
2700
2430
  users.forEach(function (user) {
2701
2431
  if ('present' in user) {
2702
2432
  var rest = _objectWithoutPropertiesLoose(user, ["present"]);
2703
-
2704
2433
  emit('user_data', rest);
2705
2434
  return;
2706
2435
  }
2707
-
2708
2436
  if (user.type === CUSTOMER) {
2709
2437
  var _rest = _objectWithoutPropertiesLoose(user, ["statistics"]);
2710
-
2711
2438
  emit('user_data', _rest);
2712
2439
  return;
2713
2440
  }
2714
-
2715
2441
  emit('user_data', user);
2716
2442
  });
2717
2443
  };
2718
-
2719
2444
  var handleMulticast = function handleMulticast(emit, _ref4) {
2720
2445
  var type = _ref4.type,
2721
- content = _ref4.content;
2722
-
2446
+ content = _ref4.content;
2723
2447
  if (type !== 'lc2') {
2724
2448
  return;
2725
2449
  }
2726
-
2727
2450
  if (content.name === 'groups_update' && 'groups' in content && !isEmpty(content.groups)) {
2728
2451
  var _content$groups = content.groups,
2729
- group = _content$groups[0];
2452
+ group = _content$groups[0];
2730
2453
  var availability = parseGroupStatus(group.status);
2731
2454
  emit('availability_updated', {
2732
2455
  availability: availability
2733
2456
  });
2734
2457
  }
2735
2458
  };
2736
-
2737
2459
  var handlePush = function handlePush(_ref5, _ref6) {
2738
2460
  var emit = _ref5.emit,
2739
- store = _ref5.store;
2461
+ store = _ref5.store;
2740
2462
  var payload = _ref6.payload;
2741
-
2742
2463
  switch (payload.action) {
2743
2464
  case THREAD_PROPERTIES_UPDATED:
2744
2465
  if (payload.payload.properties.lc2 && 'queue_pos' in payload.payload.properties.lc2) {
@@ -2751,14 +2472,11 @@
2751
2472
  }
2752
2473
  });
2753
2474
  }
2754
-
2755
2475
  emit('thread_properties_updated', payload.payload);
2756
2476
  return;
2757
-
2758
2477
  case CUSTOMER_SIDE_STORAGE_UPDATED:
2759
2478
  saveSideStorage(store, payload.payload.customer_side_storage);
2760
2479
  return;
2761
-
2762
2480
  case CUSTOMER_DISCONNECTED:
2763
2481
  // each of those should currently lead to either reconnect or destroy call
2764
2482
  // after receiving this push server closes the connection with us
@@ -2775,7 +2493,6 @@
2775
2493
  store.dispatch(reconnect(SMALL_RECONNECT_DELAY));
2776
2494
  emit('disconnected', payload.payload);
2777
2495
  break;
2778
-
2779
2496
  case CUSTOMER_BANNED:
2780
2497
  case CUSTOMER_TEMPORARILY_BLOCKED:
2781
2498
  case LICENSE_NOT_FOUND:
@@ -2785,7 +2502,6 @@
2785
2502
  // this also emits `disconnected` event - but it's handled in response to this action by destroy handler
2786
2503
  store.dispatch(destroy(payload.payload.reason));
2787
2504
  break;
2788
-
2789
2505
  case MISDIRECTED_CONNECTION$1:
2790
2506
  failAllRequests(store, MISDIRECTED_CONNECTION);
2791
2507
  store.dispatch({
@@ -2793,119 +2509,98 @@
2793
2509
  payload: payload.payload.data
2794
2510
  });
2795
2511
  break;
2796
-
2797
2512
  case SERVICE_TEMPORARILY_UNAVAILABLE$1:
2798
2513
  case TOO_MANY_UNAUTHORIZED_CONNECTIONS:
2799
2514
  // this should only really fail a `login` request - as it's the only one sent before authorization
2800
2515
  // and login should reconnect on its own right now
2801
2516
  failAllRequests(store, payload.payload.reason.toUpperCase());
2802
2517
  break;
2803
-
2804
2518
  default:
2805
2519
  store.dispatch(reconnect(SMALL_RECONNECT_DELAY));
2806
2520
  emit('disconnected', payload.payload);
2807
2521
  break;
2808
2522
  }
2809
-
2810
2523
  return;
2811
-
2812
2524
  case INCOMING_CHAT:
2813
2525
  emitUsers(emit, payload.payload.chat.users);
2814
2526
  emit(payload.action, payload.payload);
2815
2527
  return;
2816
-
2817
2528
  case INCOMING_EVENT:
2818
2529
  if (payload.payload.event === null) {
2819
2530
  return;
2820
2531
  }
2821
-
2822
2532
  emit(payload.action, payload.payload);
2823
2533
  return;
2824
-
2825
2534
  case INCOMING_TYPING_INDICATOR:
2826
2535
  emit(payload.action, payload.payload);
2827
2536
  return;
2828
-
2829
2537
  case INCOMING_MULTICAST:
2830
- handleMulticast(emit, payload.payload); // we passthrough this action even if it was already handled above
2831
-
2538
+ handleMulticast(emit, payload.payload);
2539
+ // we passthrough this action even if it was already handled above
2832
2540
  emit(payload.action, payload.payload);
2833
2541
  return;
2834
-
2835
2542
  case USER_ADDED_TO_CHAT:
2836
2543
  emitUsers(emit, [payload.payload.user]);
2837
2544
  emit(payload.action, payload.payload);
2838
2545
  return;
2839
-
2840
2546
  default:
2841
2547
  emit(payload.action, payload.payload);
2842
2548
  return;
2843
2549
  }
2844
2550
  };
2845
-
2846
2551
  var handleResponse = function handleResponse(_ref7, _ref8) {
2847
2552
  var emit = _ref7.emit;
2848
2553
  var payload = _ref8.payload;
2849
-
2850
2554
  switch (payload.action) {
2851
2555
  case CHAT_DEACTIVATED:
2852
2556
  payload.resolve(SUCCESS);
2853
2557
  return;
2854
-
2855
2558
  case GET_CHAT:
2856
2559
  emitUsers(emit, payload.payload.users);
2857
2560
  payload.resolve(payload.payload);
2858
2561
  return;
2859
-
2860
2562
  case INCOMING_CHAT:
2861
2563
  emitUsers(emit, payload.payload.chat.users);
2862
2564
  payload.resolve(payload.payload);
2863
2565
  return;
2864
-
2865
2566
  case INCOMING_EVENT:
2866
2567
  payload.resolve(payload.payload.event);
2867
2568
  return;
2868
-
2869
2569
  case LIST_CHATS:
2870
2570
  emitUsers(emit, payload.payload.users);
2871
2571
  payload.resolve(payload.payload);
2872
2572
  return;
2873
-
2874
2573
  default:
2875
2574
  payload.resolve(payload.payload);
2876
2575
  return;
2877
2576
  }
2878
2577
  };
2879
-
2880
2578
  var createSideEffectsHandler = (function (_ref9) {
2881
2579
  var auth = _ref9.auth,
2882
- customerDataProvider = _ref9.customerDataProvider,
2883
- emitter = _ref9.emitter,
2884
- socket = _ref9.socket;
2580
+ customerDataProvider = _ref9.customerDataProvider,
2581
+ emitter = _ref9.emitter,
2582
+ socket = _ref9.socket;
2885
2583
  var emit = emitter.emit;
2886
- var loginTask = createLoginTask(auth, customerDataProvider); // TODO: using Store type here is a lie, middleware only provides MiddlewareAPI here
2584
+ var loginTask = createLoginTask(auth, customerDataProvider);
2887
2585
 
2586
+ // TODO: using Store type here is a lie, middleware only provides MiddlewareAPI here
2888
2587
  return function (action, store) {
2889
2588
  switch (action.type) {
2890
2589
  case CHANGE_REGION:
2891
2590
  socket.reinitialize();
2892
2591
  return;
2893
-
2894
2592
  case CHECK_GOALS:
2895
2593
  checkGoals(store, auth, action.payload.sessionFields)["catch"](noop);
2896
2594
  return;
2897
-
2898
2595
  case DESTROY:
2899
2596
  {
2900
2597
  var payload = action.payload;
2901
2598
  loginTask.cancel();
2902
2599
  socket.destroy();
2903
-
2904
2600
  switch (payload.reason) {
2905
2601
  case 'manual':
2906
2602
  failAllRequests(store, SDK_DESTROYED);
2907
2603
  break;
2908
-
2909
2604
  case CUSTOMER_BANNED:
2910
2605
  case LICENSE_EXPIRED:
2911
2606
  case PRODUCT_VERSION_CHANGED:
@@ -2913,7 +2608,6 @@
2913
2608
  failAllRequests(store, CONNECTION_LOST);
2914
2609
  emit('disconnected', payload);
2915
2610
  break;
2916
-
2917
2611
  default:
2918
2612
  // in general those deestroys should only come either from login errors
2919
2613
  // or from customer_disconnected pushes that are sent immediately after connection
@@ -2922,16 +2616,14 @@
2922
2616
  emit('disconnected', payload);
2923
2617
  break;
2924
2618
  }
2925
-
2926
2619
  emitter.off();
2927
2620
  return;
2928
2621
  }
2929
-
2930
2622
  case FAIL_ALL_REQUESTS:
2931
2623
  {
2932
2624
  var _action$payload = action.payload,
2933
- reason = _action$payload.reason,
2934
- rejects = _action$payload.rejects;
2625
+ reason = _action$payload.reason,
2626
+ rejects = _action$payload.rejects;
2935
2627
  var error = {
2936
2628
  message: FAIL_ALL_REQUESTS_MESSAGES[reason],
2937
2629
  code: reason
@@ -2941,23 +2633,20 @@
2941
2633
  });
2942
2634
  return;
2943
2635
  }
2944
-
2945
2636
  case LOGIN_SUCCESS:
2946
2637
  {
2947
2638
  var _action$payload2 = action.payload,
2948
- dynamicConfig = _action$payload2.dynamicConfig,
2949
- customer = _action$payload2.customer,
2950
- chats = _action$payload2.chats,
2951
- greeting = _action$payload2.greeting,
2952
- availability = _action$payload2.availability;
2953
-
2639
+ dynamicConfig = _action$payload2.dynamicConfig,
2640
+ customer = _action$payload2.customer,
2641
+ chats = _action$payload2.chats,
2642
+ greeting = _action$payload2.greeting,
2643
+ availability = _action$payload2.availability;
2954
2644
  var eventData = _extends({
2955
2645
  customer: customer,
2956
2646
  availability: availability
2957
2647
  }, greeting && {
2958
2648
  greeting: greeting
2959
2649
  });
2960
-
2961
2650
  Object.defineProperty(eventData, '__unsafeDynamicConfig', {
2962
2651
  value: dynamicConfig
2963
2652
  });
@@ -2967,45 +2656,37 @@
2967
2656
  emit('connected', eventData);
2968
2657
  return;
2969
2658
  }
2970
-
2971
2659
  case PAUSE_CONNECTION:
2972
2660
  {
2973
2661
  var _payload = action.payload;
2974
2662
  socket.disconnect();
2975
-
2976
2663
  if (_payload.reason !== 'manual') {
2977
2664
  emit('disconnected', _payload);
2978
2665
  }
2979
-
2980
2666
  return;
2981
2667
  }
2982
-
2983
2668
  case PREFETCH_TOKEN:
2984
2669
  if (action.payload.fresh) {
2985
2670
  auth.getFreshToken()["catch"](noop);
2986
2671
  return;
2987
2672
  }
2988
-
2989
2673
  auth.hasToken().then(function (hasToken) {
2990
2674
  if (!hasToken) {
2991
2675
  return auth.getToken();
2992
2676
  }
2993
-
2994
2677
  return auth.getToken().then(function (_ref10) {
2995
2678
  var creationDate = _ref10.creationDate,
2996
- expiresIn = _ref10.expiresIn;
2997
- var ONE_HOUR = 60 * 60 * 1000; // check if the token is worth reusing
2679
+ expiresIn = _ref10.expiresIn;
2680
+ var ONE_HOUR = 60 * 60 * 1000;
2681
+ // check if the token is worth reusing
2998
2682
  // we don't want to get disconnected in a moment because of expired token
2999
-
3000
2683
  if (creationDate + expiresIn - Date.now() > ONE_HOUR) {
3001
2684
  return;
3002
2685
  }
3003
-
3004
2686
  return auth.invalidate().then(auth.getFreshToken);
3005
2687
  });
3006
2688
  })["catch"](noop);
3007
2689
  return;
3008
-
3009
2690
  case PUSH_RECEIVED:
3010
2691
  // TODO: this if doesn't seem to make much sense
3011
2692
  // I'm too afraid to remove it right now though
@@ -3016,46 +2697,39 @@
3016
2697
  }, action);
3017
2698
  return;
3018
2699
  }
3019
-
3020
2700
  updateStateIfNeeded(store, action);
3021
2701
  handlePush({
3022
2702
  emit: emit,
3023
2703
  store: store
3024
2704
  }, action);
3025
2705
  return;
3026
-
3027
2706
  case PUSH_RESPONSE_RECEIVED:
3028
2707
  updateStateIfNeeded(store, action);
3029
2708
  handleResponse({
3030
2709
  emit: emit
3031
2710
  }, action);
3032
2711
  return;
3033
-
3034
2712
  case RECONNECT:
3035
2713
  failAllRequests(store, CONNECTION_LOST);
3036
2714
  socket.reconnect(action.payload.delay);
3037
2715
  return;
3038
-
3039
2716
  case REQUEST_FAILED:
3040
2717
  {
3041
2718
  var _action$payload3 = action.payload,
3042
- reject = _action$payload3.reject,
3043
- _error = _action$payload3.error;
2719
+ reject = _action$payload3.reject,
2720
+ _error = _action$payload3.error;
3044
2721
  reject(createError$1(_error));
3045
2722
  return;
3046
2723
  }
3047
-
3048
2724
  case RESPONSE_RECEIVED:
3049
2725
  updateStateIfNeeded(store, action);
3050
2726
  handleResponse({
3051
2727
  emit: emit
3052
2728
  }, action);
3053
2729
  return;
3054
-
3055
2730
  case SEND_REQUEST:
3056
2731
  {
3057
2732
  var state = store.getState();
3058
-
3059
2733
  if (isDestroyed(state)) {
3060
2734
  failRequest(store, action, {
3061
2735
  code: SDK_DESTROYED,
@@ -3063,7 +2737,6 @@
3063
2737
  });
3064
2738
  return;
3065
2739
  }
3066
-
3067
2740
  if (!isConnected(state) && action.payload.source !== 'login') {
3068
2741
  failRequest(store, action, {
3069
2742
  code: NO_CONNECTION,
@@ -3071,56 +2744,44 @@
3071
2744
  });
3072
2745
  return;
3073
2746
  }
3074
-
3075
2747
  sendRequest$1(socket, action);
3076
2748
  }
3077
2749
  return;
3078
-
3079
2750
  case SET_SELF_ID:
3080
2751
  emit('customer_id', action.payload.id);
3081
2752
  return;
3082
-
3083
2753
  case SOCKET_DISCONNECTED:
3084
2754
  emit('disconnected', {
3085
2755
  reason: 'connection_lost'
3086
2756
  });
3087
2757
  return;
3088
-
3089
2758
  case SOCKET_CONNECTED:
3090
2759
  loginTask.sendLogin(store);
3091
2760
  return;
3092
-
3093
2761
  case SOCKET_RECOVERED:
3094
2762
  // don't emit if from consumer's perspective we haven't been connected
3095
2763
  if (!isConnected(store.getState())) {
3096
2764
  return;
3097
2765
  }
3098
-
3099
2766
  emit('connection_recovered');
3100
2767
  return;
3101
-
3102
2768
  case SOCKET_UNSTABLE:
3103
2769
  // don't emit if from consumer's perspective we haven't been connected
3104
2770
  if (!isConnected(store.getState())) {
3105
2771
  return;
3106
2772
  }
3107
-
3108
2773
  emit('connection_unstable');
3109
2774
  return;
3110
-
3111
2775
  case START_CONNECTION:
3112
2776
  socket.connect();
3113
2777
  store.dispatch(prefetchToken());
3114
2778
  return;
3115
-
3116
2779
  case UPDATE_CUSTOMER_PAGE:
3117
2780
  if (!isConnected(store.getState())) {
3118
2781
  return;
3119
2782
  }
3120
-
3121
2783
  sendRequestAction(store, sendRequest(UPDATE_CUSTOMER_PAGE$1, action.payload))["catch"](noop);
3122
2784
  return;
3123
-
3124
2785
  default:
3125
2786
  return;
3126
2787
  }
@@ -3128,7 +2789,6 @@
3128
2789
  });
3129
2790
 
3130
2791
  var HISTORY_EVENT_COUNT_TARGET = 25;
3131
-
3132
2792
  var createState = function createState() {
3133
2793
  return {
3134
2794
  status: 'idle',
@@ -3136,10 +2796,8 @@
3136
2796
  nextPageId: null
3137
2797
  };
3138
2798
  };
3139
-
3140
2799
  var createChatHistoryIterator = function createChatHistoryIterator(sdk, chatId) {
3141
2800
  var historyState = createState();
3142
-
3143
2801
  var next = function next(resolve, reject) {
3144
2802
  switch (historyState.status) {
3145
2803
  case 'idle':
@@ -3152,9 +2810,8 @@
3152
2810
  minEventsCount: HISTORY_EVENT_COUNT_TARGET
3153
2811
  }).then(function (_ref) {
3154
2812
  var threads = _ref.threads,
3155
- nextPageId = _ref.nextPageId;
2813
+ nextPageId = _ref.nextPageId;
3156
2814
  historyState.nextPageId = nextPageId;
3157
-
3158
2815
  if (!historyState.nextPageId) {
3159
2816
  historyState.status = 'done';
3160
2817
  resolve({
@@ -3172,13 +2829,10 @@
3172
2829
  done: false
3173
2830
  });
3174
2831
  }
3175
-
3176
2832
  var queuedTask = historyState.queuedTasks.shift();
3177
-
3178
2833
  if (!queuedTask) {
3179
2834
  return;
3180
2835
  }
3181
-
3182
2836
  next(queuedTask.resolve, queuedTask.reject);
3183
2837
  }, function (err) {
3184
2838
  var queuedTasks = historyState.queuedTasks;
@@ -3190,14 +2844,12 @@
3190
2844
  });
3191
2845
  });
3192
2846
  return;
3193
-
3194
2847
  case 'fetching':
3195
2848
  historyState.queuedTasks.push({
3196
2849
  resolve: resolve,
3197
2850
  reject: reject
3198
2851
  });
3199
2852
  return;
3200
-
3201
2853
  case 'done':
3202
2854
  resolve({
3203
2855
  value: undefined,
@@ -3206,17 +2858,14 @@
3206
2858
  return;
3207
2859
  }
3208
2860
  };
3209
-
3210
2861
  return {
3211
2862
  next: function (_next) {
3212
2863
  function next() {
3213
2864
  return _next.apply(this, arguments);
3214
2865
  }
3215
-
3216
2866
  next.toString = function () {
3217
2867
  return _next.toString();
3218
2868
  };
3219
-
3220
2869
  return next;
3221
2870
  }(function () {
3222
2871
  return new Promise(next);
@@ -3229,13 +2878,13 @@
3229
2878
  var OPEN = 1;
3230
2879
  var CLOSED = 3;
3231
2880
 
2881
+ // required because our typescript-eslint doesn't support import type syntax yet
3232
2882
  // I've tried upgrading but it had some other problems and I couldn't debug the problem quickly
3233
2883
 
3234
2884
  var createWebSocketManager = function createWebSocketManager(url, _temp) {
3235
2885
  var _ref = _temp === void 0 ? {} : _temp,
3236
- _ref$query = _ref.query,
3237
- query = _ref$query === void 0 ? {} : _ref$query;
3238
-
2886
+ _ref$query = _ref.query,
2887
+ query = _ref$query === void 0 ? {} : _ref$query;
3239
2888
  var queryString = buildQueryString(query);
3240
2889
  var finalUrl = queryString ? url + "?" + queryString : url;
3241
2890
  var emitter = createMitt();
@@ -3247,86 +2896,69 @@
3247
2896
  var state = CLOSED;
3248
2897
  var reconnectTimer;
3249
2898
  var socket = null;
3250
-
3251
2899
  var openListener = function openListener() {
3252
2900
  state = OPEN;
3253
2901
  backoff.reset();
3254
2902
  emitter.emit('connect');
3255
2903
  };
3256
-
3257
2904
  var closeListener = function closeListener() {
3258
2905
  close();
3259
2906
  reconnect();
3260
2907
  emitter.emit('disconnect');
3261
2908
  };
3262
-
3263
2909
  var messageListener = function messageListener(_ref2) {
3264
2910
  var data = _ref2.data;
3265
2911
  emitter.emit('message', data);
3266
2912
  };
3267
-
3268
2913
  var addEventListeners = function addEventListeners(instance) {
3269
2914
  instance.addEventListener('open', openListener);
3270
2915
  instance.addEventListener('close', closeListener);
3271
2916
  instance.addEventListener('message', messageListener);
3272
2917
  };
3273
-
3274
2918
  var removeEventListeners = function removeEventListeners(instance) {
3275
2919
  instance.removeEventListener('open', openListener);
3276
2920
  instance.removeEventListener('close', closeListener);
3277
2921
  instance.removeEventListener('message', messageListener);
3278
2922
  };
3279
-
3280
2923
  var close = function close() {
3281
2924
  clearTimeout(reconnectTimer);
3282
2925
  state = CLOSED;
3283
-
3284
2926
  if (!socket) {
3285
2927
  return;
3286
2928
  }
3287
-
3288
2929
  removeEventListeners(socket);
3289
2930
  socket.close();
3290
2931
  socket = null;
3291
2932
  };
3292
-
3293
2933
  var connect = function connect() {
3294
2934
  state = CONNECTING;
3295
2935
  socket = new WebSocket(finalUrl);
3296
2936
  addEventListeners(socket);
3297
2937
  };
3298
-
3299
2938
  var reconnect = function reconnect(delay) {
3300
2939
  if (delay === void 0) {
3301
2940
  delay = backoff.duration();
3302
2941
  }
3303
-
3304
2942
  close();
3305
-
3306
2943
  if (delay === 0) {
3307
2944
  connect();
3308
2945
  return;
3309
2946
  }
3310
-
3311
2947
  reconnectTimer = setTimeout(connect, delay);
3312
2948
  };
3313
-
3314
2949
  return {
3315
2950
  connect: function (_connect) {
3316
2951
  function connect() {
3317
2952
  return _connect.apply(this, arguments);
3318
2953
  }
3319
-
3320
2954
  connect.toString = function () {
3321
2955
  return _connect.toString();
3322
2956
  };
3323
-
3324
2957
  return connect;
3325
2958
  }(function () {
3326
2959
  if (state !== CLOSED) {
3327
2960
  throw new Error('Socket is already open or connecting.');
3328
2961
  }
3329
-
3330
2962
  clearTimeout(reconnectTimer);
3331
2963
  connect();
3332
2964
  }),
@@ -3339,9 +2971,9 @@
3339
2971
  emit: function emit(data) {
3340
2972
  if (state !== OPEN) {
3341
2973
  throw new Error('Socket is not connected.');
3342
- } // if we are connected we can be sure that socket is defined
3343
-
2974
+ }
3344
2975
 
2976
+ // if we are connected we can be sure that socket is defined
3345
2977
  socket.send(data);
3346
2978
  },
3347
2979
  getReadyState: function getReadyState() {
@@ -3374,11 +3006,9 @@
3374
3006
  function resolve() {
3375
3007
  return _resolve.apply(this, arguments);
3376
3008
  }
3377
-
3378
3009
  resolve.toString = function () {
3379
3010
  return _resolve.toString();
3380
3011
  };
3381
-
3382
3012
  return resolve;
3383
3013
  }(function () {
3384
3014
  clearTimeout(timer);
@@ -3396,69 +3026,58 @@
3396
3026
  });
3397
3027
  });
3398
3028
  };
3399
-
3400
3029
  var createPlatformClient = function createPlatformClient(url, _temp) {
3401
3030
  var _ref = _temp === void 0 ? {} : _temp,
3402
- _ref$query = _ref.query,
3403
- query = _ref$query === void 0 ? {} : _ref$query,
3404
- _ref$emitter = _ref.emitter,
3405
- emitter = _ref$emitter === void 0 ? createMitt() : _ref$emitter;
3406
-
3031
+ _ref$query = _ref.query,
3032
+ query = _ref$query === void 0 ? {} : _ref$query,
3033
+ _ref$emitter = _ref.emitter,
3034
+ emitter = _ref$emitter === void 0 ? createMitt() : _ref$emitter;
3407
3035
  var manager = createWebSocketManager(url, {
3408
3036
  query: query
3409
3037
  });
3410
3038
  var connectionHero = createConnectionHero();
3411
-
3412
3039
  var isSocketOpen = function isSocketOpen() {
3413
3040
  return manager.getReadyState() === OPEN;
3414
3041
  };
3415
-
3416
3042
  var emit = function emit(frame) {
3417
3043
  manager.emit(JSON.stringify(frame));
3418
3044
  };
3419
-
3420
3045
  var cleanupPossiblyPendingTasks = function cleanupPossiblyPendingTasks() {
3421
3046
  connectionHero.cancel();
3422
3047
  };
3423
-
3424
3048
  forwardEvents(manager, emitter, ['connect', 'disconnect']);
3425
3049
  manager.on('disconnect', cleanupPossiblyPendingTasks);
3426
3050
  manager.on('message', function (data) {
3427
3051
  connectionHero.resolve();
3428
3052
  var message = JSON.parse(data);
3429
3053
  emitter.emit('message', message);
3430
- }); // React Native uses window as global object, but without addEventListener method
3054
+ });
3431
3055
 
3056
+ // React Native uses window as global object, but without addEventListener method
3432
3057
  if (typeof window !== 'undefined' && typeof window.addEventListener !== 'undefined') {
3433
3058
  window.addEventListener('online', function () {
3434
3059
  if (!isSocketOpen()) {
3435
3060
  return;
3436
3061
  }
3437
-
3438
3062
  connectionHero.check().then(function () {
3439
3063
  connectionHero.cancel();
3440
3064
  emitter.emit('connection_recovered');
3441
3065
  }, function (err) {
3442
3066
  connectionHero.cancel();
3443
-
3444
3067
  if (err.code !== 'TIMEOUT') {
3445
3068
  throw err;
3446
3069
  }
3447
-
3448
3070
  manager.reconnect();
3449
3071
  });
3450
3072
  });
3451
3073
  window.addEventListener('offline', function () {
3452
3074
  connectionHero.cancel();
3453
-
3454
3075
  if (!isSocketOpen()) {
3455
3076
  return;
3456
3077
  }
3457
-
3458
3078
  emitter.emit('connection_unstable');
3459
3079
  });
3460
3080
  }
3461
-
3462
3081
  return _extends({}, manager, {
3463
3082
  destroy: function destroy() {
3464
3083
  cleanupPossiblyPendingTasks();
@@ -3488,17 +3107,14 @@
3488
3107
  emitter: emitter
3489
3108
  });
3490
3109
  };
3491
-
3492
3110
  var createSocketClient = function createSocketClient(store) {
3493
3111
  var emitter = createMitt();
3494
3112
  var client = initialize(store, emitter);
3495
3113
  return _extends({}, Object.keys(client).reduce(function (proxy, method) {
3496
3114
  proxy[method] = function () {
3497
3115
  var _client;
3498
-
3499
3116
  return (_client = client)[method].apply(_client, arguments);
3500
3117
  };
3501
-
3502
3118
  return proxy;
3503
3119
  }, {}), {
3504
3120
  reinitialize: function reinitialize() {
@@ -3515,14 +3131,12 @@
3515
3131
  properties: payload.properties
3516
3132
  };
3517
3133
  };
3518
-
3519
3134
  var parseChatPropertiesUpdatedPush = function parseChatPropertiesUpdatedPush(payload) {
3520
3135
  return {
3521
3136
  chatId: payload.chat_id,
3522
3137
  properties: payload.properties
3523
3138
  };
3524
3139
  };
3525
-
3526
3140
  var parseChatTransferredPush = function parseChatTransferredPush(payload) {
3527
3141
  var basePayload = {
3528
3142
  chatId: payload.chat_id,
@@ -3534,19 +3148,16 @@
3534
3148
  }),
3535
3149
  queue: payload.queue ? parseQueue(payload.queue) : null
3536
3150
  };
3537
-
3538
3151
  if (payload.reason === 'manual') {
3539
3152
  return _extends({}, basePayload, {
3540
3153
  reason: payload.reason,
3541
3154
  requesterId: payload.requester_id
3542
3155
  });
3543
3156
  }
3544
-
3545
3157
  return _extends({}, basePayload, {
3546
3158
  reason: payload.reason
3547
3159
  });
3548
3160
  };
3549
-
3550
3161
  var parseCustomerPageUpdatedPush = function parseCustomerPageUpdatedPush(payload) {
3551
3162
  return {
3552
3163
  url: payload.url,
@@ -3554,13 +3165,11 @@
3554
3165
  openedAt: payload.opened_at
3555
3166
  };
3556
3167
  };
3557
-
3558
3168
  var parseCustomerUpdatedPush = function parseCustomerUpdatedPush(payload) {
3559
3169
  return _extends({
3560
3170
  id: payload.id
3561
3171
  }, parseCustomerOptionalProps(payload));
3562
3172
  };
3563
-
3564
3173
  var parseEventPropertiesDeletedPush = function parseEventPropertiesDeletedPush(payload) {
3565
3174
  return {
3566
3175
  chatId: payload.chat_id,
@@ -3569,7 +3178,6 @@
3569
3178
  properties: payload.properties
3570
3179
  };
3571
3180
  };
3572
-
3573
3181
  var parseEventPropertiesUpdatedPush = function parseEventPropertiesUpdatedPush(payload) {
3574
3182
  return {
3575
3183
  chatId: payload.chat_id,
@@ -3578,7 +3186,6 @@
3578
3186
  properties: payload.properties
3579
3187
  };
3580
3188
  };
3581
-
3582
3189
  var parseEventUpdatedPush = function parseEventUpdatedPush(payload) {
3583
3190
  var threadId = payload.thread_id;
3584
3191
  return {
@@ -3587,7 +3194,6 @@
3587
3194
  event: parseEvent$1(threadId, payload.event)
3588
3195
  };
3589
3196
  };
3590
-
3591
3197
  var parseEventsMarkedAsSeenPush = function parseEventsMarkedAsSeenPush(payload) {
3592
3198
  return {
3593
3199
  chatId: payload.chat_id,
@@ -3595,19 +3201,16 @@
3595
3201
  seenUpTo: payload.seen_up_to
3596
3202
  };
3597
3203
  };
3598
-
3599
3204
  var parseGreetingAcceptedPush = function parseGreetingAcceptedPush(payload) {
3600
3205
  return {
3601
3206
  uniqueId: payload.unique_id
3602
3207
  };
3603
3208
  };
3604
-
3605
3209
  var parseGetChatResponse = function parseGetChatResponse(payload) {
3606
3210
  return _extends({}, parseChatCommon(payload), {
3607
3211
  thread: payload.thread ? parseThread(payload.id, payload.thread) : null
3608
3212
  });
3609
3213
  };
3610
-
3611
3214
  var parseIncomingChatPush = function parseIncomingChatPush(payload) {
3612
3215
  var chat = payload.chat;
3613
3216
  return {
@@ -3616,18 +3219,15 @@
3616
3219
  })
3617
3220
  };
3618
3221
  };
3619
-
3620
3222
  var parseIncomingEventPush = function parseIncomingEventPush(payload) {
3621
3223
  return {
3622
3224
  chatId: payload.chat_id,
3623
3225
  event: parseEvent$1(payload.thread_id, payload.event)
3624
3226
  };
3625
3227
  };
3626
-
3627
3228
  var parseIncomingGreetingPush = function parseIncomingGreetingPush(payload) {
3628
3229
  return parseGreeting(payload);
3629
3230
  };
3630
-
3631
3231
  var parseIncomingRichMessagePostbackPush = function parseIncomingRichMessagePostbackPush(payload) {
3632
3232
  return {
3633
3233
  userId: payload.user_id,
@@ -3637,10 +3237,9 @@
3637
3237
  postback: payload.postback
3638
3238
  };
3639
3239
  };
3640
-
3641
3240
  var parseIncomingTypingIndicatorPush = function parseIncomingTypingIndicatorPush(payload) {
3642
3241
  var chatId = payload.chat_id,
3643
- typingIndicator = payload.typing_indicator;
3242
+ typingIndicator = payload.typing_indicator;
3644
3243
  return {
3645
3244
  chatId: chatId,
3646
3245
  typingIndicator: {
@@ -3649,7 +3248,6 @@
3649
3248
  }
3650
3249
  };
3651
3250
  };
3652
-
3653
3251
  var parseQueuePositionUpdatedPush = function parseQueuePositionUpdatedPush(payload) {
3654
3252
  return {
3655
3253
  chatId: payload.chat_id,
@@ -3657,7 +3255,6 @@
3657
3255
  queue: parseQueueUpdate(payload.queue)
3658
3256
  };
3659
3257
  };
3660
-
3661
3258
  var parseThreadPropertiesDeletedPush = function parseThreadPropertiesDeletedPush(payload) {
3662
3259
  return {
3663
3260
  chatId: payload.chat_id,
@@ -3665,7 +3262,6 @@
3665
3262
  properties: payload.properties
3666
3263
  };
3667
3264
  };
3668
-
3669
3265
  var parseThreadPropertiesUpdatedPush = function parseThreadPropertiesUpdatedPush(payload) {
3670
3266
  return {
3671
3267
  chatId: payload.chat_id,
@@ -3673,7 +3269,6 @@
3673
3269
  properties: payload.properties
3674
3270
  };
3675
3271
  };
3676
-
3677
3272
  var parseUserAddedToChatPush = function parseUserAddedToChatPush(payload) {
3678
3273
  return {
3679
3274
  chatId: payload.chat_id,
@@ -3681,14 +3276,12 @@
3681
3276
  present: payload.user.present
3682
3277
  };
3683
3278
  };
3684
-
3685
3279
  var parseUserRemovedFromChatPush = function parseUserRemovedFromChatPush(payload) {
3686
3280
  return {
3687
3281
  chatId: payload.chat_id,
3688
3282
  userId: payload.user_id
3689
3283
  };
3690
3284
  };
3691
-
3692
3285
  var parseFields = function parseFields(fields) {
3693
3286
  return fields.map(function (field) {
3694
3287
  switch (field.type) {
@@ -3696,30 +3289,25 @@
3696
3289
  return _extends({}, field, {
3697
3290
  options: field.options.map(function (_ref) {
3698
3291
  var groupId = _ref.group_id,
3699
- option = _objectWithoutPropertiesLoose(_ref, ["group_id"]);
3700
-
3292
+ option = _objectWithoutPropertiesLoose(_ref, ["group_id"]);
3701
3293
  return _extends({}, option, {
3702
3294
  groupId: groupId
3703
3295
  });
3704
3296
  })
3705
3297
  });
3706
-
3707
3298
  case 'rating':
3708
3299
  {
3709
3300
  var commentLabel = field.comment_label,
3710
- parsed = _objectWithoutPropertiesLoose(field, ["comment_label"]);
3711
-
3301
+ parsed = _objectWithoutPropertiesLoose(field, ["comment_label"]);
3712
3302
  return _extends({}, parsed, {
3713
3303
  commentLabel: commentLabel
3714
3304
  });
3715
3305
  }
3716
-
3717
3306
  default:
3718
3307
  return field;
3719
3308
  }
3720
3309
  });
3721
3310
  };
3722
-
3723
3311
  var parseTicketFormFields = function parseTicketFormFields(fields) {
3724
3312
  var withFakeIds = fields.map(function (field, index) {
3725
3313
  return _extends({}, field, {
@@ -3728,7 +3316,6 @@
3728
3316
  });
3729
3317
  return parseFields(withFakeIds);
3730
3318
  };
3731
-
3732
3319
  var parseForm$1 = function parseForm(form) {
3733
3320
  var isTicketForm = !('id' in form.fields[0]);
3734
3321
  return {
@@ -3736,66 +3323,54 @@
3736
3323
  fields: isTicketForm ? parseTicketFormFields(form.fields) : parseFields(form.fields)
3737
3324
  };
3738
3325
  };
3739
-
3740
3326
  var parseGetFormResponse = function parseGetFormResponse(payload) {
3741
3327
  if (!payload.enabled) {
3742
3328
  return payload;
3743
3329
  }
3744
-
3745
3330
  return _extends({}, payload, {
3746
3331
  form: parseForm$1(payload.form)
3747
3332
  });
3748
3333
  };
3749
-
3750
3334
  var parseGetUrlInfoResponse = function parseGetUrlInfoResponse(payload) {
3751
3335
  var urlInfo = {
3752
3336
  url: payload.url
3753
3337
  };
3754
-
3755
3338
  if (payload.title) {
3756
3339
  urlInfo.title = payload.title;
3757
3340
  }
3758
-
3759
3341
  if (payload.description) {
3760
3342
  urlInfo.description = payload.description;
3761
3343
  }
3762
-
3763
3344
  if (payload.image_url) {
3764
- urlInfo.imageUrl = "https://" + payload.image_url;
3765
-
3345
+ urlInfo.imageUrl = "https://" + removeProtocol(payload.image_url);
3766
3346
  if (payload.image_width && payload.image_height) {
3767
3347
  urlInfo.imageWidth = payload.image_width;
3768
3348
  urlInfo.imageHeight = payload.image_height;
3769
3349
  }
3770
3350
  }
3771
-
3772
3351
  return urlInfo;
3773
3352
  };
3774
-
3775
3353
  var getAvailabilityBasedOnDynamicConfig = function getAvailabilityBasedOnDynamicConfig(_ref2) {
3776
3354
  var onlineGroups = _ref2.online_groups_ids,
3777
- customerGroups = _ref2.customer_groups;
3778
-
3355
+ customerGroups = _ref2.customer_groups;
3779
3356
  // this might be missing if all groups are offline
3780
3357
  if (!onlineGroups) {
3781
3358
  return 'offline';
3782
3359
  }
3783
-
3784
3360
  var monitoringGroupId = customerGroups.monitoring.id;
3785
3361
  return includes(monitoringGroupId, onlineGroups) ? 'online' : 'offline';
3786
3362
  };
3787
-
3788
3363
  var parseListChatsResponse = function parseListChatsResponse(payload) {
3789
3364
  var chatsSummary = payload.chats_summary.map(function (_ref3) {
3790
3365
  var id = _ref3.id,
3791
- active = _ref3.active,
3792
- access = _ref3.access,
3793
- lastThreadCreatedAt = _ref3.last_thread_created_at,
3794
- lastThreadId = _ref3.last_thread_id,
3795
- lastEventsPerType = _ref3.last_event_per_type,
3796
- _ref3$properties = _ref3.properties,
3797
- properties = _ref3$properties === void 0 ? {} : _ref3$properties,
3798
- users = _ref3.users;
3366
+ active = _ref3.active,
3367
+ access = _ref3.access,
3368
+ lastThreadCreatedAt = _ref3.last_thread_created_at,
3369
+ lastThreadId = _ref3.last_thread_id,
3370
+ lastEventsPerType = _ref3.last_event_per_type,
3371
+ _ref3$properties = _ref3.properties,
3372
+ properties = _ref3$properties === void 0 ? {} : _ref3$properties,
3373
+ users = _ref3.users;
3799
3374
  var chatSummary = {
3800
3375
  id: id,
3801
3376
  active: active,
@@ -3806,11 +3381,9 @@
3806
3381
  lastThreadCreatedAt: lastThreadCreatedAt || null,
3807
3382
  eventsSeenUpToMap: getEventsSeenUpToMap(users)
3808
3383
  };
3809
-
3810
3384
  if (!lastEventsPerType) {
3811
3385
  return chatSummary;
3812
3386
  }
3813
-
3814
3387
  chatSummary.lastEventsPerType = mapValues(function (lastEventPerType) {
3815
3388
  return parseEvent$1(lastEventPerType.thread_id, lastEventPerType.event);
3816
3389
  }, lastEventsPerType);
@@ -3821,17 +3394,15 @@
3821
3394
  var lastEventSummary = last(lastEventSummariesArray.sort(function (eventSummaryA, eventSummaryB) {
3822
3395
  return eventSummaryA.thread_id === eventSummaryB.thread_id ? stringCompare(eventSummaryA.event.created_at, eventSummaryB.event.created_at) : stringCompare(eventSummaryA.thread_created_at, eventSummaryB.thread_created_at);
3823
3396
  }));
3824
-
3825
3397
  if (lastEventSummary) {
3826
3398
  chatSummary.lastEvent = chatSummary.lastEventsPerType[lastEventSummary.event.type];
3827
3399
  }
3828
-
3829
3400
  return chatSummary;
3830
3401
  });
3831
3402
  return {
3832
3403
  chatsSummary: numericSortBy(function (_ref4) {
3833
3404
  var lastEvent = _ref4.lastEvent,
3834
- order = _ref4.order;
3405
+ order = _ref4.order;
3835
3406
  return -1 * (lastEvent !== undefined ? lastEvent.timestamp : order);
3836
3407
  }, chatsSummary),
3837
3408
  totalChats: payload.total_chats,
@@ -3844,11 +3415,9 @@
3844
3415
  nextPageId: payload.next_page_id || null
3845
3416
  };
3846
3417
  };
3847
-
3848
3418
  var parseListGroupStatusesResponse = function parseListGroupStatusesResponse(payload) {
3849
3419
  return payload.groups_status;
3850
3420
  };
3851
-
3852
3421
  var parseListThreadsResponse = function parseListThreadsResponse(request, payload) {
3853
3422
  return {
3854
3423
  threads: payload.threads.map(function (thread) {
@@ -3858,11 +3427,10 @@
3858
3427
  nextPageId: payload.next_page_id || null
3859
3428
  };
3860
3429
  };
3861
-
3862
3430
  var parseLoginResponse = function parseLoginResponse(payload) {
3863
3431
  var dynamicConfig = payload.__priv_dynamic_config,
3864
- chats = payload.chats,
3865
- greeting = payload.greeting;
3432
+ chats = payload.chats,
3433
+ greeting = payload.greeting;
3866
3434
  return _extends({
3867
3435
  dynamicConfig: dynamicConfig,
3868
3436
  customer: parseCustomer(payload.customer),
@@ -3870,7 +3438,8 @@
3870
3438
  chats: chats.map(function (chat) {
3871
3439
  return {
3872
3440
  id: chat.chat_id,
3873
- active: 'has_active_thread' in chat ? chat.has_active_thread : // temporary fallback, waiting for API to move this flag into `chats` array
3441
+ active: 'has_active_thread' in chat ? chat.has_active_thread :
3442
+ // temporary fallback, waiting for API to move this flag into `chats` array
3874
3443
  payload.has_active_thread,
3875
3444
  hasUnreadEvents: chat.has_unread_events
3876
3445
  };
@@ -3879,7 +3448,6 @@
3879
3448
  greeting: parseGreeting(greeting)
3880
3449
  });
3881
3450
  };
3882
-
3883
3451
  var parsePush = function parsePush(push) {
3884
3452
  switch (push.action) {
3885
3453
  case CHAT_DEACTIVATED:
@@ -3889,146 +3457,122 @@
3889
3457
  chatId: push.payload.chat_id
3890
3458
  }
3891
3459
  };
3892
-
3893
3460
  case CHAT_PROPERTIES_DELETED:
3894
3461
  return {
3895
3462
  action: push.action,
3896
3463
  payload: parseChatPropertiesDeletedPush(push.payload)
3897
3464
  };
3898
-
3899
3465
  case CHAT_PROPERTIES_UPDATED:
3900
3466
  return {
3901
3467
  action: push.action,
3902
3468
  payload: parseChatPropertiesUpdatedPush(push.payload)
3903
3469
  };
3904
-
3905
3470
  case CHAT_TRANSFERRED:
3906
3471
  return {
3907
3472
  action: push.action,
3908
3473
  payload: parseChatTransferredPush(push.payload)
3909
3474
  };
3910
-
3911
3475
  case CUSTOMER_SIDE_STORAGE_UPDATED:
3912
3476
  return {
3913
3477
  action: push.action,
3914
3478
  payload: push.payload
3915
3479
  };
3916
-
3917
3480
  case CUSTOMER_DISCONNECTED:
3918
3481
  return {
3919
3482
  action: push.action,
3920
3483
  payload: push.payload
3921
3484
  };
3922
-
3923
3485
  case CUSTOMER_PAGE_UPDATED:
3924
3486
  return {
3925
3487
  action: push.action,
3926
3488
  payload: parseCustomerPageUpdatedPush(push.payload)
3927
3489
  };
3928
-
3929
3490
  case CUSTOMER_UPDATED:
3930
3491
  return {
3931
3492
  action: push.action,
3932
3493
  payload: parseCustomerUpdatedPush(push.payload)
3933
3494
  };
3934
-
3935
3495
  case EVENT_PROPERTIES_DELETED:
3936
3496
  return {
3937
3497
  action: push.action,
3938
3498
  payload: parseEventPropertiesDeletedPush(push.payload)
3939
3499
  };
3940
-
3941
3500
  case EVENT_PROPERTIES_UPDATED:
3942
3501
  return {
3943
3502
  action: push.action,
3944
3503
  payload: parseEventPropertiesUpdatedPush(push.payload)
3945
3504
  };
3946
-
3947
3505
  case EVENT_UPDATED:
3948
3506
  return {
3949
3507
  action: push.action,
3950
3508
  payload: parseEventUpdatedPush(push.payload)
3951
3509
  };
3952
-
3953
3510
  case EVENTS_MARKED_AS_SEEN:
3954
3511
  return {
3955
3512
  action: push.action,
3956
3513
  payload: parseEventsMarkedAsSeenPush(push.payload)
3957
3514
  };
3958
-
3959
3515
  case GREETING_ACCEPTED:
3960
3516
  return {
3961
3517
  action: push.action,
3962
3518
  payload: parseGreetingAcceptedPush(push.payload)
3963
3519
  };
3964
-
3965
3520
  case GREETING_CANCELED:
3966
3521
  return {
3967
3522
  action: push.action,
3968
3523
  // 'greeting_canceled' has the same payload as `greeting_accepted`
3969
3524
  payload: parseGreetingAcceptedPush(push.payload)
3970
3525
  };
3971
-
3972
3526
  case INCOMING_CHAT:
3973
3527
  return {
3974
3528
  action: push.action,
3975
3529
  payload: parseIncomingChatPush(push.payload)
3976
3530
  };
3977
-
3978
3531
  case INCOMING_EVENT:
3979
3532
  return {
3980
3533
  action: push.action,
3981
3534
  payload: parseIncomingEventPush(push.payload)
3982
3535
  };
3983
-
3984
3536
  case INCOMING_GREETING:
3985
3537
  return {
3986
3538
  action: push.action,
3987
3539
  payload: parseIncomingGreetingPush(push.payload)
3988
3540
  };
3989
-
3990
3541
  case INCOMING_MULTICAST:
3991
3542
  return {
3992
3543
  action: push.action,
3993
3544
  payload: push.payload
3994
3545
  };
3995
-
3996
3546
  case INCOMING_RICH_MESSAGE_POSTBACK:
3997
3547
  return {
3998
3548
  action: push.action,
3999
3549
  payload: parseIncomingRichMessagePostbackPush(push.payload)
4000
3550
  };
4001
-
4002
3551
  case INCOMING_TYPING_INDICATOR:
4003
3552
  return {
4004
3553
  action: push.action,
4005
3554
  payload: parseIncomingTypingIndicatorPush(push.payload)
4006
3555
  };
4007
-
4008
3556
  case QUEUE_POSITION_UPDATED:
4009
3557
  return {
4010
3558
  action: push.action,
4011
3559
  payload: parseQueuePositionUpdatedPush(push.payload)
4012
3560
  };
4013
-
4014
3561
  case THREAD_PROPERTIES_DELETED:
4015
3562
  return {
4016
3563
  action: push.action,
4017
3564
  payload: parseThreadPropertiesDeletedPush(push.payload)
4018
3565
  };
4019
-
4020
3566
  case THREAD_PROPERTIES_UPDATED:
4021
3567
  return {
4022
3568
  action: push.action,
4023
3569
  payload: parseThreadPropertiesUpdatedPush(push.payload)
4024
3570
  };
4025
-
4026
3571
  case USER_ADDED_TO_CHAT:
4027
3572
  return {
4028
3573
  action: push.action,
4029
3574
  payload: parseUserAddedToChatPush(push.payload)
4030
3575
  };
4031
-
4032
3576
  case USER_REMOVED_FROM_CHAT:
4033
3577
  return {
4034
3578
  action: push.action,
@@ -4038,141 +3582,118 @@
4038
3582
  };
4039
3583
  var parseResponse = function parseResponse(_ref5) {
4040
3584
  var request = _ref5.request,
4041
- response = _ref5.response;
4042
-
3585
+ response = _ref5.response;
4043
3586
  switch (response.action) {
4044
3587
  case ACCEPT_GREETING:
4045
3588
  return {
4046
3589
  action: response.action,
4047
3590
  payload: SUCCESS
4048
3591
  };
4049
-
4050
3592
  case CANCEL_GREETING:
4051
3593
  return {
4052
3594
  action: response.action,
4053
3595
  payload: SUCCESS
4054
3596
  };
4055
-
4056
3597
  case DELETE_CHAT_PROPERTIES:
4057
3598
  return {
4058
3599
  action: response.action,
4059
3600
  payload: SUCCESS
4060
3601
  };
4061
-
4062
3602
  case DELETE_EVENT_PROPERTIES:
4063
3603
  return {
4064
3604
  action: response.action,
4065
3605
  payload: SUCCESS
4066
3606
  };
4067
-
4068
3607
  case DELETE_THREAD_PROPERTIES:
4069
3608
  return {
4070
3609
  action: response.action,
4071
3610
  payload: SUCCESS
4072
3611
  };
4073
-
4074
3612
  case GET_CHAT:
4075
3613
  return {
4076
3614
  action: response.action,
4077
3615
  payload: parseGetChatResponse(response.payload)
4078
3616
  };
4079
-
4080
3617
  case GET_CUSTOMER:
4081
3618
  return {
4082
3619
  action: response.action,
4083
3620
  payload: parseCustomer(response.payload)
4084
3621
  };
4085
-
4086
3622
  case GET_FORM:
4087
3623
  return {
4088
3624
  action: response.action,
4089
3625
  payload: parseGetFormResponse(response.payload)
4090
3626
  };
4091
-
4092
3627
  case GET_PREDICTED_AGENT:
4093
3628
  return {
4094
3629
  action: response.action,
4095
3630
  payload: parsePredictedAgent(response.payload)
4096
3631
  };
4097
-
4098
3632
  case GET_URL_INFO:
4099
3633
  return {
4100
3634
  action: response.action,
4101
3635
  payload: parseGetUrlInfoResponse(response.payload)
4102
3636
  };
4103
-
4104
3637
  case LIST_CHATS:
4105
3638
  return {
4106
3639
  action: response.action,
4107
3640
  payload: parseListChatsResponse(response.payload)
4108
3641
  };
4109
-
4110
3642
  case LIST_GROUP_STATUSES:
4111
3643
  return {
4112
3644
  action: response.action,
4113
3645
  payload: parseListGroupStatusesResponse(response.payload)
4114
3646
  };
4115
-
4116
3647
  case LIST_THREADS:
4117
3648
  return {
4118
3649
  action: response.action,
4119
3650
  payload: parseListThreadsResponse(request, response.payload)
4120
3651
  };
4121
-
4122
3652
  case LOGIN:
4123
3653
  return {
4124
3654
  action: response.action,
4125
3655
  payload: parseLoginResponse(response.payload)
4126
3656
  };
4127
-
4128
3657
  case MARK_EVENTS_AS_SEEN:
4129
3658
  return {
4130
3659
  action: response.action,
4131
3660
  payload: SUCCESS
4132
3661
  };
4133
-
4134
3662
  case SEND_SNEAK_PEEK:
4135
3663
  return {
4136
3664
  action: response.action,
4137
3665
  payload: SUCCESS
4138
3666
  };
4139
-
4140
3667
  case SET_CUSTOMER_SESSION_FIELDS:
4141
3668
  return {
4142
3669
  action: response.action,
4143
3670
  payload: SUCCESS
4144
3671
  };
4145
-
4146
3672
  case SEND_RICH_MESSAGE_POSTBACK:
4147
3673
  return {
4148
3674
  action: response.action,
4149
3675
  payload: SUCCESS
4150
3676
  };
4151
-
4152
3677
  case UPDATE_CHAT_PROPERTIES:
4153
3678
  return {
4154
3679
  action: response.action,
4155
3680
  payload: SUCCESS
4156
3681
  };
4157
-
4158
3682
  case UPDATE_CUSTOMER:
4159
3683
  return {
4160
3684
  action: response.action,
4161
3685
  payload: SUCCESS
4162
3686
  };
4163
-
4164
3687
  case UPDATE_CUSTOMER_PAGE$1:
4165
3688
  return {
4166
3689
  action: response.action,
4167
3690
  payload: SUCCESS
4168
3691
  };
4169
-
4170
3692
  case UPDATE_EVENT_PROPERTIES:
4171
3693
  return {
4172
3694
  action: response.action,
4173
3695
  payload: SUCCESS
4174
3696
  };
4175
-
4176
3697
  case UPDATE_THREAD_PROPERTIES:
4177
3698
  return {
4178
3699
  action: response.action,
@@ -4189,13 +3710,11 @@
4189
3710
 
4190
3711
  var handleResponseError = function handleResponseError(_ref, response) {
4191
3712
  var dispatch = _ref.dispatch,
4192
- getState = _ref.getState;
3713
+ getState = _ref.getState;
4193
3714
  var requestId = response.request_id,
4194
- payload = response.payload;
4195
-
3715
+ payload = response.payload;
4196
3716
  var _getRequest = getRequest(getState(), requestId),
4197
- reject = _getRequest.reject;
4198
-
3717
+ reject = _getRequest.reject;
4199
3718
  dispatch({
4200
3719
  type: REQUEST_FAILED,
4201
3720
  payload: {
@@ -4205,17 +3724,14 @@
4205
3724
  }
4206
3725
  });
4207
3726
  };
4208
-
4209
3727
  var handleResponse$1 = function handleResponse(_ref2, response) {
4210
3728
  var dispatch = _ref2.dispatch,
4211
- getState = _ref2.getState;
3729
+ getState = _ref2.getState;
4212
3730
  var requestId = response.request_id;
4213
-
4214
3731
  var _getRequest2 = getRequest(getState(), requestId),
4215
- promise = _getRequest2.promise,
4216
- resolve = _getRequest2.resolve,
4217
- request = _getRequest2.request;
4218
-
3732
+ promise = _getRequest2.promise,
3733
+ resolve = _getRequest2.resolve,
3734
+ request = _getRequest2.request;
4219
3735
  var parsedResponse = parseResponse({
4220
3736
  request: request,
4221
3737
  response: response
@@ -4229,16 +3745,13 @@
4229
3745
  }, parsedResponse)
4230
3746
  });
4231
3747
  };
4232
-
4233
3748
  var handlePushResponse = function handlePushResponse(_ref3, response) {
4234
3749
  var dispatch = _ref3.dispatch,
4235
- getState = _ref3.getState;
3750
+ getState = _ref3.getState;
4236
3751
  var requestId = response.request_id;
4237
-
4238
3752
  var _getRequest3 = getRequest(getState(), requestId),
4239
- promise = _getRequest3.promise,
4240
- resolve = _getRequest3.resolve;
4241
-
3753
+ promise = _getRequest3.promise,
3754
+ resolve = _getRequest3.resolve;
4242
3755
  var parsedPush = parsePush(response);
4243
3756
  dispatch({
4244
3757
  type: PUSH_RESPONSE_RECEIVED,
@@ -4249,21 +3762,17 @@
4249
3762
  }, parsedPush)
4250
3763
  });
4251
3764
  };
4252
-
4253
3765
  var handlePush$1 = function handlePush(store, push) {
4254
3766
  var parsedPush = parsePush(push);
4255
-
4256
3767
  if (!parsedPush) {
4257
3768
  // defensive measure against receiving unknown push
4258
3769
  return;
4259
3770
  }
4260
-
4261
3771
  store.dispatch({
4262
3772
  type: PUSH_RECEIVED,
4263
3773
  payload: parsedPush
4264
3774
  });
4265
3775
  };
4266
-
4267
3776
  var socketListener = (function (store, socket) {
4268
3777
  var dispatch = store.dispatch;
4269
3778
  socket.on('connect', function () {
@@ -4277,24 +3786,19 @@
4277
3786
  handleResponseError(store, message);
4278
3787
  return;
4279
3788
  }
4280
-
4281
3789
  switch (message.action) {
4282
- case DEACTIVATE_CHAT:
4283
3790
  case RESUME_CHAT:
4284
3791
  case SEND_EVENT:
4285
3792
  case START_CHAT:
4286
3793
  // those are requests with indirect responses
4287
3794
  return;
4288
-
4289
3795
  default:
4290
3796
  handleResponse$1(store, message);
4291
3797
  return;
4292
3798
  }
4293
3799
  }
4294
-
4295
3800
  if ('request_id' in message) {
4296
3801
  switch (message.action) {
4297
- case CHAT_DEACTIVATED:
4298
3802
  case INCOMING_CHAT:
4299
3803
  case INCOMING_EVENT:
4300
3804
  // those are acting as indirect responses
@@ -4302,12 +3806,10 @@
4302
3806
  return;
4303
3807
  }
4304
3808
  }
4305
-
4306
3809
  handlePush$1(store, message);
4307
3810
  });
4308
3811
  socket.on('disconnect', function () {
4309
3812
  failAllRequests(store, CONNECTION_LOST);
4310
-
4311
3813
  if (getConnectionStatus(store.getState()) === CONNECTED) {
4312
3814
  store.dispatch(socketDisconnected());
4313
3815
  }
@@ -4326,18 +3828,15 @@
4326
3828
  });
4327
3829
 
4328
3830
  var INCORRECT_REQUESTER_STRUCTURE = 'incorrect requester structure';
4329
-
4330
3831
  var appendString = function appendString(input, str) {
4331
3832
  return input.length ? input + "\n" + str : str;
4332
3833
  };
4333
-
4334
3834
  var createTicketBody = function createTicketBody(state, _ref) {
4335
3835
  var fields = _ref.fields,
4336
- customerId = _ref.customerId,
4337
- _ref$groupId = _ref.groupId,
4338
- groupId = _ref$groupId === void 0 ? state.groupId : _ref$groupId,
4339
- timeZone = _ref.timeZone;
4340
-
3836
+ customerId = _ref.customerId,
3837
+ _ref$groupId = _ref.groupId,
3838
+ groupId = _ref$groupId === void 0 ? state.groupId : _ref$groupId,
3839
+ timeZone = _ref.timeZone;
4341
3840
  var ticketBody = _extends({
4342
3841
  licence_id: state.licenseId,
4343
3842
  ticket_message: '',
@@ -4353,101 +3852,78 @@
4353
3852
  }, timeZone && {
4354
3853
  timezone: timeZone
4355
3854
  });
4356
-
4357
3855
  return fields.reduce(function (body, field) {
4358
3856
  switch (field.type) {
4359
3857
  case 'subject':
4360
3858
  {
4361
3859
  var value = field.answer;
4362
3860
  var text = value ? field.label + " " + value : field.label;
4363
-
4364
3861
  if (value) {
4365
3862
  body.subject = value;
4366
3863
  }
4367
-
4368
3864
  body.offline_message = appendString(body.offline_message, text);
4369
3865
  return body;
4370
3866
  }
4371
-
4372
3867
  case 'name':
4373
3868
  {
4374
3869
  var _value = field.answer;
4375
-
4376
3870
  var _text = _value ? field.label + " " + _value : field.label;
4377
-
4378
3871
  if (_value) {
4379
3872
  body.requester.name = _value;
4380
3873
  }
4381
-
4382
3874
  body.offline_message = appendString(body.offline_message, _text);
4383
3875
  return body;
4384
3876
  }
4385
-
4386
3877
  case 'email':
4387
3878
  {
4388
3879
  var _value2 = field.answer;
4389
-
4390
3880
  var _text2 = _value2 ? field.label + " " + _value2 : field.label;
4391
-
4392
3881
  body.requester.mail = _value2;
4393
3882
  body.offline_message = appendString(body.offline_message, _text2);
4394
3883
  return body;
4395
3884
  }
4396
-
4397
3885
  case 'question':
4398
3886
  case 'textarea':
4399
3887
  {
4400
3888
  var _value3 = field.answer;
4401
-
4402
3889
  var _text3 = _value3 ? field.label + " " + _value3 : field.label;
4403
-
4404
3890
  body.offline_message = appendString(body.offline_message, _text3);
4405
3891
  body.ticket_message = appendString(body.ticket_message, _text3);
4406
3892
  return body;
4407
3893
  }
4408
-
4409
3894
  case 'radio':
4410
3895
  case 'select':
4411
3896
  {
4412
3897
  var _value4 = field.answer && field.answer.label;
4413
-
4414
3898
  var _text4 = _value4 ? field.label + " " + _value4 : field.label;
4415
-
4416
3899
  body.offline_message = appendString(body.offline_message, _text4);
4417
3900
  body.ticket_message = appendString(body.ticket_message, _text4);
4418
3901
  return body;
4419
3902
  }
4420
-
4421
3903
  case 'checkbox':
4422
3904
  {
4423
3905
  var _value5 = field.answers && field.answers.map(function (answer) {
4424
3906
  return answer.label;
4425
3907
  }).join(', ');
4426
-
4427
3908
  var _text5 = _value5 ? field.label + " " + _value5 : field.label;
4428
-
4429
3909
  body.offline_message = appendString(body.offline_message, _text5);
4430
3910
  body.ticket_message = appendString(body.ticket_message, _text5);
4431
3911
  return body;
4432
3912
  }
4433
-
4434
3913
  default:
4435
3914
  return body;
4436
3915
  }
4437
3916
  }, ticketBody);
4438
3917
  };
4439
-
4440
3918
  var sendTicketForm = function sendTicketForm(store, auth, _ref2) {
4441
3919
  var filledForm = _ref2.filledForm,
4442
- groupId = _ref2.groupId,
4443
- timeZone = _ref2.timeZone;
3920
+ groupId = _ref2.groupId,
3921
+ timeZone = _ref2.timeZone;
4444
3922
  return auth.getToken().then(function (token) {
4445
3923
  var state = store.getState();
4446
-
4447
3924
  if (getSelfId(state) === null) {
4448
3925
  store.dispatch(setSelfId(token.entityId));
4449
3926
  }
4450
-
4451
3927
  var url = getApiOrigin(state) + "/v2/tickets/new";
4452
3928
  var body = createTicketBody(state, {
4453
3929
  fields: filledForm.fields,
@@ -4468,33 +3944,28 @@
4468
3944
  text: body.ticket_message
4469
3945
  });
4470
3946
  });
4471
- } // we actually should normalize this somehow
4472
-
3947
+ }
4473
3948
 
3949
+ // we actually should normalize this somehow
4474
3950
  if (response.status === 400 || response.status === 422) {
4475
3951
  var errHandler = function errHandler(error) {
4476
3952
  if (!error || !error.errors) {
4477
3953
  // TODO: I honestly don't know if this can even be reached and even if it is - What error should be thrown here
4478
3954
  throw new Error();
4479
- } // we receive some hardcore aggregate error here 😱
4480
-
4481
-
3955
+ }
3956
+ // we receive some hardcore aggregate error here 😱
4482
3957
  var firstError = error.errors[0];
4483
3958
  var type = Object.keys(firstError)[0];
4484
-
4485
3959
  if (type === INCORRECT_REQUESTER_STRUCTURE) {
4486
3960
  throw createError$1({
4487
3961
  message: firstError[INCORRECT_REQUESTER_STRUCTURE][0],
4488
3962
  code: 'VALIDATION'
4489
3963
  });
4490
3964
  }
4491
-
4492
3965
  throw new Error();
4493
3966
  };
4494
-
4495
3967
  return response.json().then(errHandler, errHandler);
4496
3968
  }
4497
-
4498
3969
  throw new Error();
4499
3970
  });
4500
3971
  });
@@ -4507,19 +3978,16 @@
4507
3978
  });
4508
3979
  return formData;
4509
3980
  };
4510
-
4511
3981
  var UPLOAD_FAILED = 'UPLOAD_FAILED';
4512
3982
  var UPLOAD_CANCELED = 'UPLOAD_CANCELED';
4513
-
4514
3983
  var uploadFile = function uploadFile(url, data, _temp) {
4515
3984
  var _ref = _temp === void 0 ? {} : _temp,
4516
- headers = _ref.headers,
4517
- _ref$method = _ref.method,
4518
- method = _ref$method === void 0 ? 'POST' : _ref$method,
4519
- onProgress = _ref.onProgress,
4520
- _ref$withCredentials = _ref.withCredentials,
4521
- withCredentials = _ref$withCredentials === void 0 ? false : _ref$withCredentials;
4522
-
3985
+ headers = _ref.headers,
3986
+ _ref$method = _ref.method,
3987
+ method = _ref$method === void 0 ? 'POST' : _ref$method,
3988
+ onProgress = _ref.onProgress,
3989
+ _ref$withCredentials = _ref.withCredentials,
3990
+ withCredentials = _ref$withCredentials === void 0 ? false : _ref$withCredentials;
4523
3991
  var xhr = new XMLHttpRequest();
4524
3992
  var upload = new Promise(function (resolve, reject) {
4525
3993
  if (typeof onProgress === 'function') {
@@ -4527,48 +3995,39 @@
4527
3995
  onProgress(event.loaded / event.total);
4528
3996
  };
4529
3997
  }
4530
-
4531
3998
  xhr.onload = function () {
4532
3999
  var response;
4533
-
4534
4000
  try {
4535
4001
  response = JSON.parse(xhr.response);
4536
4002
  } catch (err) {
4537
4003
  response = xhr.response;
4538
4004
  }
4539
-
4540
4005
  if (xhr.status >= 200 && xhr.status < 300) {
4541
4006
  resolve(response);
4542
4007
  return;
4543
4008
  }
4544
-
4545
4009
  var err = new Error('Upload failed.');
4546
4010
  err.code = UPLOAD_FAILED;
4547
4011
  err.response = response;
4548
4012
  reject(err);
4549
4013
  };
4550
-
4551
4014
  xhr.onerror = function () {
4552
4015
  var err = new Error('Upload failed.');
4553
4016
  err.code = UPLOAD_FAILED;
4554
4017
  reject(err);
4555
4018
  };
4556
-
4557
4019
  xhr.onabort = function () {
4558
4020
  var err = new Error('Upload canceled.');
4559
4021
  err.code = UPLOAD_CANCELED;
4560
4022
  reject(err);
4561
4023
  };
4562
-
4563
4024
  xhr.open(method, url);
4564
4025
  xhr.withCredentials = withCredentials;
4565
-
4566
4026
  if (headers) {
4567
4027
  Object.keys(headers).forEach(function (header) {
4568
4028
  return xhr.setRequestHeader(header, headers[header]);
4569
4029
  });
4570
4030
  }
4571
-
4572
4031
  xhr.send(toFormData(data));
4573
4032
  });
4574
4033
  return {
@@ -4583,32 +4042,24 @@
4583
4042
  var MEGABYTE = 1024 * KILOBYTE;
4584
4043
  var GIGABYTE = 1024 * MEGABYTE;
4585
4044
  var SIZE_LIMIT = 10 * MEGABYTE;
4586
-
4587
4045
  var formatBytes = function formatBytes(bytes, precision) {
4588
4046
  if (precision === void 0) {
4589
4047
  precision = 2;
4590
4048
  }
4591
-
4592
4049
  if (bytes < KILOBYTE) {
4593
4050
  return bytes + " b";
4594
4051
  }
4595
-
4596
4052
  var kilobytes = bytes / 1024;
4597
-
4598
4053
  if (bytes < MEGABYTE) {
4599
4054
  return kilobytes.toFixed(precision) + " kb";
4600
4055
  }
4601
-
4602
4056
  var megabytes = kilobytes / 1024;
4603
-
4604
4057
  if (bytes < GIGABYTE) {
4605
4058
  return megabytes.toFixed(precision) + " MB";
4606
4059
  }
4607
-
4608
4060
  var gigabytes = megabytes / 1024;
4609
4061
  return gigabytes.toFixed(precision) + " GB";
4610
4062
  };
4611
-
4612
4063
  var validateFile = function validateFile(file) {
4613
4064
  if (file.size > SIZE_LIMIT) {
4614
4065
  throw createError$1({
@@ -4620,9 +4071,9 @@
4620
4071
 
4621
4072
  var uploadFile$1 = function uploadFile$1(_ref, _ref2) {
4622
4073
  var auth = _ref.auth,
4623
- store = _ref.store;
4074
+ store = _ref.store;
4624
4075
  var file = _ref2.file,
4625
- onProgress = _ref2.onProgress;
4076
+ onProgress = _ref2.onProgress;
4626
4077
  var upload;
4627
4078
  var cancelled = false;
4628
4079
  var send = new Promise(function (resolve, reject) {
@@ -4640,7 +4091,6 @@
4640
4091
  reject(new Error('Upload cancelled.'));
4641
4092
  return;
4642
4093
  }
4643
-
4644
4094
  upload = uploadFile(url, payload, {
4645
4095
  headers: {
4646
4096
  Authorization: token.tokenType + " " + token.accessToken
@@ -4653,10 +4103,9 @@
4653
4103
  reject(uploadError);
4654
4104
  return;
4655
4105
  }
4656
-
4657
4106
  var _uploadError$response = uploadError.response.error,
4658
- type = _uploadError$response.type,
4659
- message = _uploadError$response.message;
4107
+ type = _uploadError$response.type,
4108
+ message = _uploadError$response.message;
4660
4109
  reject(createError$1({
4661
4110
  message: message,
4662
4111
  code: type.toUpperCase()
@@ -4670,9 +4119,7 @@
4670
4119
  if (cancelled) {
4671
4120
  return;
4672
4121
  }
4673
-
4674
4122
  cancelled = true;
4675
-
4676
4123
  if (upload) {
4677
4124
  upload.cancel();
4678
4125
  }
@@ -4685,7 +4132,6 @@
4685
4132
  var img = new Image();
4686
4133
  img.src = url + "?" + body;
4687
4134
  img.onerror = noop;
4688
-
4689
4135
  img.onload = function () {
4690
4136
  return resolve();
4691
4137
  };
@@ -4700,17 +4146,15 @@
4700
4146
  */
4701
4147
  var log = function log(_ref) {
4702
4148
  var env = _ref.env,
4703
- licenseId = _ref.licenseId,
4704
- eventName = _ref.eventName;
4705
-
4149
+ licenseId = _ref.licenseId,
4150
+ eventName = _ref.eventName;
4706
4151
  if (env !== 'production' || "customer_sdk" !== 'customer_sdk') {
4707
4152
  return Promise.resolve();
4708
4153
  }
4709
-
4710
4154
  var message = {
4711
4155
  event_name: eventName,
4712
4156
  severity: 'Informational',
4713
- sdkVersion: "3.1.0"
4157
+ sdkVersion: "3.1.2"
4714
4158
  };
4715
4159
  var body = {
4716
4160
  licence_id: licenseId,
@@ -4722,26 +4166,20 @@
4722
4166
 
4723
4167
  var LISTENER_IDENTITY = 'LISTENER_IDENTITY';
4724
4168
  var listenersMap = {};
4725
-
4726
4169
  var createDebuggedMethods = function createDebuggedMethods(methods, prefix) {
4727
4170
  if (prefix === void 0) {
4728
4171
  prefix = '';
4729
4172
  }
4730
-
4731
4173
  var methodNames = Object.keys(methods);
4732
4174
  return methodNames.map(function (methodName) {
4733
4175
  var method = methods[methodName];
4734
4176
  return function () {
4735
4177
  var _console;
4736
-
4737
4178
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4738
4179
  args[_key] = arguments[_key];
4739
4180
  }
4740
-
4741
4181
  (_console = console).info.apply(_console, [prefix + "." + methodName + "() ===>"].concat(args));
4742
-
4743
4182
  var result = method.apply(void 0, args);
4744
-
4745
4183
  if (typeof (result == null ? void 0 : result.then) === 'function') {
4746
4184
  return result.then(function (data) {
4747
4185
  console.info(prefix + "." + methodName + "() <===", data);
@@ -4751,7 +4189,6 @@
4751
4189
  throw err;
4752
4190
  });
4753
4191
  }
4754
-
4755
4192
  return result;
4756
4193
  };
4757
4194
  }).reduce(function (acc, method, index) {
@@ -4759,74 +4196,58 @@
4759
4196
  return acc;
4760
4197
  }, {});
4761
4198
  };
4762
-
4763
4199
  var createEnhancedListener = function createEnhancedListener(label, event, listener) {
4764
4200
  if (listener[LISTENER_IDENTITY] === undefined) {
4765
4201
  Object.defineProperty(listener, LISTENER_IDENTITY, {
4766
4202
  value: {}
4767
4203
  });
4768
4204
  }
4769
-
4770
4205
  if (listener[LISTENER_IDENTITY][event]) {
4771
4206
  var enhancedListenerId = listener[LISTENER_IDENTITY][event];
4772
4207
  return listenersMap[enhancedListenerId];
4773
4208
  }
4774
-
4775
4209
  var enhancedListener = function enhancedListener(data) {
4776
4210
  console.info("." + label + "(\"" + event + "\") <===", data);
4777
4211
  listener(data);
4778
4212
  };
4779
-
4780
4213
  var uniqueId = generateUniqueId(listenersMap);
4781
4214
  listener[LISTENER_IDENTITY][event] = uniqueId;
4782
4215
  listenersMap[uniqueId] = enhancedListener;
4783
4216
  return enhancedListener;
4784
- }; // TODO: this really should just accept & return CustomerSdk type
4785
-
4217
+ };
4786
4218
 
4219
+ // TODO: this really should just accept & return CustomerSdk type
4787
4220
  var debug = (function (_sdk) {
4788
4221
  var sdk = _sdk;
4789
-
4790
4222
  var _on = sdk.on,
4791
- _once = sdk.once,
4792
- _off = sdk.off,
4793
- _getChatHistory = sdk.getChatHistory,
4794
- auth = sdk.auth,
4795
- rest = _objectWithoutPropertiesLoose(sdk, ["on", "once", "off", "getChatHistory", "auth"]);
4796
-
4223
+ _once = sdk.once,
4224
+ _off = sdk.off,
4225
+ _getChatHistory = sdk.getChatHistory,
4226
+ auth = sdk.auth,
4227
+ rest = _objectWithoutPropertiesLoose(sdk, ["on", "once", "off", "getChatHistory", "auth"]);
4797
4228
  var methods = createDebuggedMethods(rest);
4798
4229
  return Object.freeze(_extends({
4799
4230
  auth: Object.freeze(createDebuggedMethods(auth, '.auth'))
4800
4231
  }, methods, {
4801
4232
  getChatHistory: function getChatHistory() {
4802
4233
  var _console2;
4803
-
4804
4234
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
4805
4235
  args[_key2] = arguments[_key2];
4806
4236
  }
4807
-
4808
4237
  (_console2 = console).info.apply(_console2, [".getChatHistory()"].concat(args));
4809
-
4810
4238
  var history = _getChatHistory.apply(void 0, args);
4811
-
4812
4239
  var logLabel = 'history.next()';
4813
4240
  return {
4814
4241
  next: function next() {
4815
4242
  var _console3;
4816
-
4817
4243
  (_console3 = console).info.apply(_console3, [logLabel + " ===>"].concat(args));
4818
-
4819
4244
  return history.next().then(function (data) {
4820
4245
  var _console4;
4821
-
4822
4246
  (_console4 = console).info.apply(_console4, [logLabel + " <==="].concat(args, [data]));
4823
-
4824
4247
  return data;
4825
4248
  }, function (err) {
4826
4249
  var _console5;
4827
-
4828
4250
  (_console5 = console).error.apply(_console5, [logLabel + " <==="].concat(args, [err]));
4829
-
4830
4251
  throw err;
4831
4252
  });
4832
4253
  }
@@ -4835,12 +4256,10 @@
4835
4256
  off: function off(event, listener) {
4836
4257
  console.info(".off(\"" + event + "\", " + (listener.name || 'anonymous') + ")");
4837
4258
  var enhancedListener = listener;
4838
-
4839
4259
  if (listener[LISTENER_IDENTITY] !== undefined) {
4840
4260
  var enhancedListenerId = listener[LISTENER_IDENTITY][event];
4841
4261
  enhancedListener = listenersMap[enhancedListenerId];
4842
4262
  }
4843
-
4844
4263
  _off(event, enhancedListener);
4845
4264
  },
4846
4265
  on: function on(event, listener) {
@@ -4857,15 +4276,12 @@
4857
4276
  if (env === void 0) {
4858
4277
  env = 'production';
4859
4278
  }
4860
-
4861
4279
  validateConfig(config);
4862
-
4863
4280
  var _config$autoConnect = config.autoConnect,
4864
- autoConnect = _config$autoConnect === void 0 ? true : _config$autoConnect,
4865
- customerDataProvider = config.customerDataProvider,
4866
- identityProvider = config.identityProvider,
4867
- instanceConfig = _objectWithoutPropertiesLoose(config, ["autoConnect", "customerDataProvider", "identityProvider"]);
4868
-
4281
+ autoConnect = _config$autoConnect === void 0 ? true : _config$autoConnect,
4282
+ customerDataProvider = config.customerDataProvider,
4283
+ identityProvider = config.identityProvider,
4284
+ instanceConfig = _objectWithoutPropertiesLoose(config, ["autoConnect", "customerDataProvider", "identityProvider"]);
4869
4285
  var store = finalCreateStore(_extends({}, instanceConfig, {
4870
4286
  env: env
4871
4287
  }));
@@ -4879,19 +4295,16 @@
4879
4295
  customerDataProvider: customerDataProvider
4880
4296
  }));
4881
4297
  socketListener(store, socket);
4882
-
4883
4298
  var sendRequestAction$1 = sendRequestAction.bind(null, store);
4884
-
4885
4299
  var startConnection = function startConnection() {
4886
4300
  store.dispatch({
4887
4301
  type: START_CONNECTION
4888
4302
  });
4889
4303
  };
4890
-
4891
4304
  var api = Object.freeze({
4892
4305
  acceptGreeting: function acceptGreeting(_ref) {
4893
4306
  var greetingId = _ref.greetingId,
4894
- uniqueId = _ref.uniqueId;
4307
+ uniqueId = _ref.uniqueId;
4895
4308
  return sendRequestAction$1(sendRequest(ACCEPT_GREETING, {
4896
4309
  greeting_id: greetingId,
4897
4310
  unique_id: uniqueId
@@ -4906,20 +4319,18 @@
4906
4319
  },
4907
4320
  cancelRate: function cancelRate(params) {
4908
4321
  var chatId = params.chatId,
4909
- _params$properties = params.properties,
4910
- properties = _params$properties === void 0 ? ['score'] : _params$properties;
4322
+ _params$properties = params.properties,
4323
+ properties = _params$properties === void 0 ? ['score'] : _params$properties;
4911
4324
  return api.listThreads({
4912
4325
  chatId: chatId
4913
4326
  }).then(function (_ref3) {
4914
4327
  var threads = _ref3.threads;
4915
-
4916
4328
  if (!threads.length) {
4917
4329
  throw createError$1({
4918
4330
  message: "There is no thread in \"" + chatId + "\".",
4919
4331
  code: MISSING_CHAT_THREAD
4920
4332
  });
4921
4333
  }
4922
-
4923
4334
  return api.deleteThreadProperties({
4924
4335
  chatId: chatId,
4925
4336
  threadId: threads[0].id,
@@ -4938,7 +4349,7 @@
4938
4349
  },
4939
4350
  deleteChatProperties: function deleteChatProperties(_ref5) {
4940
4351
  var id = _ref5.id,
4941
- properties = _ref5.properties;
4352
+ properties = _ref5.properties;
4942
4353
  return sendRequestAction$1(sendRequest(DELETE_CHAT_PROPERTIES, {
4943
4354
  id: id,
4944
4355
  properties: properties
@@ -4946,9 +4357,9 @@
4946
4357
  },
4947
4358
  deleteEventProperties: function deleteEventProperties(_ref6) {
4948
4359
  var chatId = _ref6.chatId,
4949
- threadId = _ref6.threadId,
4950
- eventId = _ref6.eventId,
4951
- properties = _ref6.properties;
4360
+ threadId = _ref6.threadId,
4361
+ eventId = _ref6.eventId,
4362
+ properties = _ref6.properties;
4952
4363
  return sendRequestAction$1(sendRequest(DELETE_EVENT_PROPERTIES, {
4953
4364
  chat_id: chatId,
4954
4365
  thread_id: threadId,
@@ -4958,8 +4369,8 @@
4958
4369
  },
4959
4370
  deleteThreadProperties: function deleteThreadProperties(_ref7) {
4960
4371
  var chatId = _ref7.chatId,
4961
- threadId = _ref7.threadId,
4962
- properties = _ref7.properties;
4372
+ threadId = _ref7.threadId,
4373
+ properties = _ref7.properties;
4963
4374
  return sendRequestAction$1(sendRequest(DELETE_THREAD_PROPERTIES, {
4964
4375
  chat_id: chatId,
4965
4376
  thread_id: threadId,
@@ -4974,7 +4385,7 @@
4974
4385
  },
4975
4386
  getChat: function getChat(_ref8) {
4976
4387
  var chatId = _ref8.chatId,
4977
- threadId = _ref8.threadId;
4388
+ threadId = _ref8.threadId;
4978
4389
  return sendRequestAction$1(sendRequest(GET_CHAT, {
4979
4390
  chat_id: chatId,
4980
4391
  thread_id: threadId
@@ -4989,7 +4400,7 @@
4989
4400
  },
4990
4401
  getForm: function getForm(_ref10) {
4991
4402
  var groupId = _ref10.groupId,
4992
- type = _ref10.type;
4403
+ type = _ref10.type;
4993
4404
  return sendRequestAction$1(sendRequest(GET_FORM, {
4994
4405
  group_id: groupId,
4995
4406
  type: type
@@ -4999,9 +4410,8 @@
4999
4410
  if (params === void 0) {
5000
4411
  params = {};
5001
4412
  }
5002
-
5003
4413
  var _params = params,
5004
- groupId = _params.groupId;
4414
+ groupId = _params.groupId;
5005
4415
  return sendRequestAction$1(sendRequest(GET_PREDICTED_AGENT, typeof groupId === 'number' ? {
5006
4416
  group_id: groupId
5007
4417
  } : {}));
@@ -5016,11 +4426,9 @@
5016
4426
  if (params === void 0) {
5017
4427
  params = {};
5018
4428
  }
5019
-
5020
4429
  if ('limit' in params && typeof params.limit === 'number' && params.limit > CHATS_PAGINATION_MAX_LIMIT) {
5021
4430
  return Promise.reject(new Error("Specified limit is too high (max " + CHATS_PAGINATION_MAX_LIMIT + ")."));
5022
4431
  }
5023
-
5024
4432
  return sendRequestAction$1(sendRequest(LIST_CHATS, params.pageId === undefined ? {
5025
4433
  limit: params.limit || 10
5026
4434
  } : {
@@ -5029,8 +4437,7 @@
5029
4437
  },
5030
4438
  listGroupStatuses: function listGroupStatuses(_temp) {
5031
4439
  var _ref12 = _temp === void 0 ? {} : _temp,
5032
- groupIds = _ref12.groupIds;
5033
-
4440
+ groupIds = _ref12.groupIds;
5034
4441
  return sendRequestAction$1(sendRequest(LIST_GROUP_STATUSES, groupIds ? {
5035
4442
  group_ids: groupIds
5036
4443
  } : {
@@ -5050,7 +4457,7 @@
5050
4457
  },
5051
4458
  markEventsAsSeen: function markEventsAsSeen(_ref13) {
5052
4459
  var chatId = _ref13.chatId,
5053
- seenUpTo = _ref13.seenUpTo;
4460
+ seenUpTo = _ref13.seenUpTo;
5054
4461
  return sendRequestAction$1(sendRequest(MARK_EVENTS_AS_SEEN, {
5055
4462
  chat_id: chatId,
5056
4463
  seen_up_to: seenUpTo
@@ -5061,19 +4468,17 @@
5061
4468
  off: emitter.off,
5062
4469
  rateChat: function rateChat(params) {
5063
4470
  var chatId = params.chatId,
5064
- rating = params.rating;
4471
+ rating = params.rating;
5065
4472
  return api.listThreads({
5066
4473
  chatId: chatId
5067
4474
  }).then(function (_ref14) {
5068
4475
  var threads = _ref14.threads;
5069
-
5070
4476
  if (!threads.length) {
5071
4477
  throw createError$1({
5072
4478
  message: "There is no thread in \"" + chatId + "\".",
5073
4479
  code: MISSING_CHAT_THREAD
5074
4480
  });
5075
4481
  }
5076
-
5077
4482
  return api.updateThreadProperties({
5078
4483
  chatId: chatId,
5079
4484
  threadId: threads[0].id,
@@ -5095,11 +4500,9 @@
5095
4500
  function sendEvent(_x) {
5096
4501
  return _sendEvent.apply(this, arguments);
5097
4502
  }
5098
-
5099
4503
  sendEvent.toString = function () {
5100
4504
  return _sendEvent.toString();
5101
4505
  };
5102
-
5103
4506
  return sendEvent;
5104
4507
  }(function (params) {
5105
4508
  return sendRequestAction$1(sendEvent(params));
@@ -5109,9 +4512,9 @@
5109
4512
  },
5110
4513
  sendRichMessagePostback: function sendRichMessagePostback(_ref15) {
5111
4514
  var chatId = _ref15.chatId,
5112
- threadId = _ref15.threadId,
5113
- eventId = _ref15.eventId,
5114
- postback = _ref15.postback;
4515
+ threadId = _ref15.threadId,
4516
+ eventId = _ref15.eventId,
4517
+ postback = _ref15.postback;
5115
4518
  return sendRequestAction$1(sendRequest(SEND_RICH_MESSAGE_POSTBACK, {
5116
4519
  chat_id: chatId,
5117
4520
  event_id: eventId,
@@ -5127,13 +4530,11 @@
5127
4530
  },
5128
4531
  setSneakPeek: function setSneakPeek(_ref17) {
5129
4532
  var chatId = _ref17.chatId,
5130
- sneakPeekText = _ref17.sneakPeekText;
4533
+ sneakPeekText = _ref17.sneakPeekText;
5131
4534
  var state = store.getState();
5132
-
5133
4535
  if (!isChatActive(state, chatId) || !isConnected(state)) {
5134
4536
  return;
5135
4537
  }
5136
-
5137
4538
  sendRequestAction$1(sendRequest(SEND_SNEAK_PEEK, {
5138
4539
  chat_id: chatId,
5139
4540
  sneak_peek_text: sneakPeekText
@@ -5143,7 +4544,6 @@
5143
4544
  if (data === void 0) {
5144
4545
  data = {};
5145
4546
  }
5146
-
5147
4547
  log({
5148
4548
  env: env,
5149
4549
  licenseId: config.licenseId,
@@ -5153,7 +4553,7 @@
5153
4553
  },
5154
4554
  updateChatProperties: function updateChatProperties(_ref18) {
5155
4555
  var id = _ref18.id,
5156
- properties = _ref18.properties;
4556
+ properties = _ref18.properties;
5157
4557
  return sendRequestAction$1(sendRequest(UPDATE_CHAT_PROPERTIES, {
5158
4558
  id: id,
5159
4559
  properties: properties
@@ -5170,9 +4570,9 @@
5170
4570
  },
5171
4571
  updateEventProperties: function updateEventProperties(_ref19) {
5172
4572
  var chatId = _ref19.chatId,
5173
- threadId = _ref19.threadId,
5174
- eventId = _ref19.eventId,
5175
- properties = _ref19.properties;
4573
+ threadId = _ref19.threadId,
4574
+ eventId = _ref19.eventId,
4575
+ properties = _ref19.properties;
5176
4576
  return sendRequestAction$1(sendRequest(UPDATE_EVENT_PROPERTIES, {
5177
4577
  chat_id: chatId,
5178
4578
  event_id: eventId,
@@ -5182,8 +4582,8 @@
5182
4582
  },
5183
4583
  updateThreadProperties: function updateThreadProperties(_ref20) {
5184
4584
  var chatId = _ref20.chatId,
5185
- threadId = _ref20.threadId,
5186
- properties = _ref20.properties;
4585
+ threadId = _ref20.threadId,
4586
+ properties = _ref20.properties;
5187
4587
  return sendRequestAction$1(sendRequest(UPDATE_THREAD_PROPERTIES, {
5188
4588
  chat_id: chatId,
5189
4589
  thread_id: threadId,
@@ -5197,7 +4597,6 @@
5197
4597
  }, options);
5198
4598
  }
5199
4599
  });
5200
-
5201
4600
  if (autoConnect) {
5202
4601
  startConnection();
5203
4602
  } else {
@@ -5208,7 +4607,6 @@
5208
4607
  }
5209
4608
  });
5210
4609
  }
5211
-
5212
4610
  return api;
5213
4611
  };
5214
4612