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