@livechat/customer-sdk 3.1.4 → 3.1.5

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 +1 -1
  2. package/dist/customer-sdk.cjs.js +4 -4
  3. package/dist/customer-sdk.cjs.native.js +4 -4
  4. package/dist/customer-sdk.esm.js +3 -3
  5. package/dist/customer-sdk.js +170 -279
  6. package/dist/customer-sdk.min.js +1 -1
  7. package/package.json +3 -2
  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
@@ -105,125 +105,43 @@
105
105
 
106
106
  var _ref = {},
107
107
  hasOwnProperty = _ref.hasOwnProperty;
108
- /**
109
- * returns true or false depending if the provided property is present inside the provided object
110
- * @example
111
- * hasOwn('a', { a: 1, b: 2 })
112
- * // returns true
113
- */
114
108
  function hasOwn(prop, obj) {
115
109
  return hasOwnProperty.call(obj, prop);
116
110
  }
117
111
 
118
- /**
119
- * returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level
120
- * @example
121
- * const arr = [{ a: [1, 2] }, { a: [3, 4] }, { a: [5, 6] }]
122
- * flatMap(el => el.a, arr)
123
- * // returns [1, 2, 3, 4, 5, 6]
124
- */
125
112
  function flatMap(iteratee, arr) {
126
113
  var _ref;
127
114
  return (_ref = []).concat.apply(_ref, arr.map(iteratee));
128
115
  }
129
116
 
130
- /**
131
- * determines whether provided value is an array
132
- * @example
133
- * isArray([1, 2])
134
- * // returns true
135
- * isArray('hello')
136
- * // returns false
137
- */
138
- function isArray(arr) {
139
- return Array.isArray(arr);
140
- }
117
+ var isArray = Array.isArray;
141
118
 
142
- /**
143
- * returns true or false depending if the provided value is an object
144
- * @example
145
- * isObject({ a: 1 })
146
- * // returns true
147
- * isObject([1, 2])
148
- * // returns false
149
- */
150
119
  // eslint-disable-next-line @typescript-eslint/ban-types
151
120
  function isObject(obj) {
152
121
  return typeof obj === 'object' && obj !== null && !isArray(obj);
153
122
  }
154
123
 
155
- /**
156
- * returns an array of the provided object keys
157
- * @example
158
- * keys({ a: 1, b: 2, c: 3 })
159
- * // returns ['a', 'b', 'c']
160
- */
161
- function keys(obj) {
162
- if ('keys' in Object && typeof Object.keys === 'function') {
163
- return Object.keys(obj);
164
- }
165
- var keysArray = [];
166
- for (var property in obj) {
167
- if (Object.prototype.hasOwnProperty.call(obj, property)) {
168
- keysArray.push(property);
169
- }
170
- }
171
- return keysArray;
172
- }
173
-
174
- /**
175
- * maps values of the provided object
176
- * @example
177
- * mapValues(val => val.toUpperCase(), { a: 'foo', b: 'bar' })
178
- * // returns { a: 'FOO', b: 'BAR' }
179
- */
180
124
  function mapValues(mapper, obj) {
181
- return keys(obj).reduce(function (acc, key) {
125
+ return Object.keys(obj).reduce(function (acc, key) {
182
126
  acc[key] = mapper(obj[key]);
183
127
  return acc;
184
128
  }, {});
185
129
  }
186
130
 
187
- /**
188
- * returns the provided value
189
- * @example
190
- * identity('hello')
191
- * // returns 'hello'
192
- */
193
131
  function identity(value) {
194
132
  return value;
195
133
  }
196
134
 
197
- /**
198
- * generates a random id
199
- * @example
200
- * generateRandomId()
201
- * // returns 'd1rjknhhch8'
202
- */
203
135
  function generateRandomId() {
204
136
  return Math.random().toString(36).substring(2);
205
137
  }
206
138
 
207
- /**
208
- * generates an unique id based on the provided object keys
209
- * @example
210
- * generateUniqueId({ xuvarw8cao: 1, b837g2nba1d: 2 })
211
- * // returns 'd1rjknhhch8'
212
- */
213
139
  function generateUniqueId(map) {
214
140
  var id = generateRandomId();
215
141
  return hasOwn(id, map) ? generateUniqueId(map) : id;
216
142
  }
217
143
 
218
- /**
219
- * returns the value from the specififed path from the provided object
220
- * @example
221
- * const obj = { a: { b: [1, 2, 3] } }
222
- * get('a.b.1', obj)
223
- * // returns 2
224
- * get(['a', 'b', '1'], obj)
225
- * // returns 2
226
- */
144
+ // based on https://github.com/developit/dlv/blob/d7ec976d12665f1c25dec2acf955dfc2e8757a9c/index.js
227
145
  function get(propPath, obj) {
228
146
  var arrPath = typeof propPath === 'string' ? propPath.split('.') : propPath;
229
147
  var pathPartIndex = 0;
@@ -234,40 +152,14 @@
234
152
  return result;
235
153
  }
236
154
 
237
- /**
238
- * returns true or false depending if the provided value is present inside the provided array or string
239
- * @example
240
- * includes('a', ['a', 'b', 'c'])
241
- * // returns true
242
- * includes('d', 'abc')
243
- * // returns false
244
- */
245
-
246
155
  function includes(value, arrOrStr) {
247
156
  return arrOrStr.indexOf(value) !== -1;
248
157
  }
249
158
 
250
- /**
251
- * returns true or false depending if the provided value is an empty object or an empty array
252
- * @example
253
- * isEmpty({})
254
- * // returns true
255
- */
256
159
  function isEmpty(collection) {
257
160
  return (isArray(collection) ? collection : Object.keys(collection)).length === 0;
258
161
  }
259
162
 
260
- /**
261
- * constructs an object from the provided array of objects, grouped by the value of the specified key
262
- * @example
263
- * const arr = [
264
- * { a: 'foo', b: 'bar' },
265
- * { a: 'foo', b: 'baz' },
266
- * { a: 'test', b: 'bab' },
267
- * ]
268
- * keyBy('a', arr)
269
- * // returns { foo: { a: 'foo', b: 'baz' }, test: { a: 'test', b: 'bab' } }
270
- */
271
163
  function keyBy(prop, arr) {
272
164
  return arr.reduce(function (acc, el) {
273
165
  acc[el[prop]] = el;
@@ -275,47 +167,20 @@
275
167
  }, {});
276
168
  }
277
169
 
278
- /**
279
- * returns the last element of the provided array or undefined when array is empty
280
- * @example
281
- * last([1, 2, 3])
282
- * // returns 3
283
- */
170
+ // TODO: this should return `T | undefined` to match native behavior
284
171
  function last(arr) {
285
- return arr.length > 0 ? arr[arr.length - 1] : undefined;
172
+ return arr.length > 0 ? arr[arr.length - 1] : null;
286
173
  }
287
174
 
288
- /**
289
- * does literally nothing
290
- * @example
291
- * somethingAsyncAndDangerous().catch(noop)
292
- */
293
175
  // eslint-disable-next-line @typescript-eslint/no-empty-function
294
176
  function noop() {}
295
177
 
296
- /**
297
- * returns an array of values of the provided object
298
- * @example
299
- * values({ a: 1, b: 2, c: 3 })
300
- * // returns [1, 2, 3]
301
- */
302
178
  function values(obj) {
303
- return keys(obj).map(function (key) {
179
+ return Object.keys(obj).map(function (key) {
304
180
  return obj[key];
305
181
  });
306
182
  }
307
183
 
308
- /**
309
- * sorts values of the provided object or array based on the provided mapping function or the provided prop string
310
- * @example
311
- * const obj = {
312
- * a: { chats: 1 },
313
- * b: { chats: 3 },
314
- * c: { chats: 2 },
315
- * }
316
- * numericSortBy(el => el.chats * -1, obj)
317
- * // returns [{ chats: 3 }, { chats: 2 }, { chats: 1 }]
318
- */
319
184
  function numericSortBy(propOrMapper, collection) {
320
185
  var mapper = typeof propOrMapper === 'function' ? propOrMapper : function (element) {
321
186
  return get(propOrMapper, element);
@@ -325,25 +190,13 @@
325
190
  });
326
191
  }
327
192
 
328
- /**
329
- * picks specified properties from the object
330
- * @example
331
- * pick(['b'], { a: 1, b: 2 })
332
- * // returns { b: 2 }
333
- */
334
- function pick(keys, obj) {
335
- return keys.reduce(function (acc, prop) {
193
+ function pick(props, obj) {
194
+ return props.reduce(function (acc, prop) {
336
195
  acc[prop] = obj[prop];
337
196
  return acc;
338
197
  }, {});
339
198
  }
340
199
 
341
- /**
342
- * picks specified props only if they exist on the provided object
343
- * @example
344
- * pickOwn(['b'], { a: 1, b: 2 })
345
- * // returns { b: 2 }
346
- */
347
200
  function pickOwn(props, obj) {
348
201
  return props.reduce(function (acc, prop) {
349
202
  if (hasOwn(prop, obj)) {
@@ -353,41 +206,19 @@
353
206
  }, {});
354
207
  }
355
208
 
356
- /**
357
- * returns an array of derived from the provided object key-value tuples
358
- * @example
359
- * toPairs({ a: 1, b: 2 })
360
- * // returns [['a', 1], ['b', 2]]
361
- */
362
- function toPairs(obj) {
363
- return keys(obj).map(function (key) {
209
+ var toPairs = function toPairs(obj) {
210
+ return Object.keys(obj).map(function (key) {
364
211
  return [key, obj[key]];
365
212
  });
366
- }
213
+ };
367
214
 
368
- /**
369
- * returns 0 for matching strings
370
- * return -1 for string with lower char code at some position
371
- * return 1 for string with greater char code at some position
372
- * @example
373
- * stringCompare('abc', 'abc')
374
- * // returns 0
375
- * stringCompare('abc', 'abd')
376
- * // returns -1
377
- */
378
- function stringCompare(strA, strB) {
215
+ var stringCompare = function stringCompare(strA, strB) {
379
216
  if (strA === strB) {
380
217
  return 0;
381
218
  }
382
219
  return strA < strB ? -1 : 1;
383
- }
220
+ };
384
221
 
385
- /**
386
- * returns an array with all the duplicates from the provided array removed based on the iteratee function
387
- * @example
388
- * uniqBy(el => el.toString(), [1, '1', 2, '3', 3])
389
- * // returns [1, 2, '3']
390
- */
391
222
  function uniqBy(iteratee, arr) {
392
223
  // with polyfills this could be just: return Array.from(new Set(arr.map(iteratee)))
393
224
  var seen = [];
@@ -478,18 +309,25 @@
478
309
  });
479
310
  }
480
311
 
481
- var ACCOUNTS_URL = "https://accounts.livechatinc.com";
482
- var buildPath = function buildPath(_ref) {
483
- var uniqueGroups = _ref.uniqueGroups,
484
- organizationId = _ref.organizationId,
485
- groupId = _ref.groupId;
486
- return "" + (uniqueGroups ? "/v2/customer/" + organizationId + "/" + groupId + "/token" : '/v2/customer/token');
487
- };
488
- var buildRequestUrl = function buildRequestUrl(config, env) {
489
- var url = env === 'production' ? ACCOUNTS_URL : ACCOUNTS_URL.replace('accounts.', "accounts." + env + ".");
490
- var path = buildPath(config);
491
- return "" + url + path;
492
- };
312
+ function getRoot() {
313
+ return new Promise(function (resolve) {
314
+ var next = function next() {
315
+ if (!document.body) {
316
+ setTimeout(next, 100);
317
+ return;
318
+ }
319
+ resolve(document.body);
320
+ };
321
+ next();
322
+ });
323
+ }
324
+
325
+ function removeNode(node) {
326
+ var parentNode = node.parentNode;
327
+ if (parentNode) {
328
+ parentNode.removeChild(node);
329
+ }
330
+ }
493
331
 
494
332
  var createError = function createError(_ref) {
495
333
  var code = _ref.code,
@@ -499,7 +337,7 @@
499
337
  return err;
500
338
  };
501
339
 
502
- var parseTokenResponse = function parseTokenResponse(token, organizationId) {
340
+ var parseTokenResponse = function parseTokenResponse(token, licenseId) {
503
341
  if ('identity_exception' in token) {
504
342
  throw createError({
505
343
  code: 'SSO_IDENTITY_EXCEPTION',
@@ -518,33 +356,119 @@
518
356
  expiresIn: token.expires_in * 1000,
519
357
  tokenType: token.token_type,
520
358
  creationDate: Date.now(),
521
- organizationId: organizationId
359
+ licenseId: licenseId
522
360
  };
523
361
  };
524
362
 
363
+ var ACCOUNTS_URL = "https://accounts.livechatinc.com";
364
+ var buildPath = function buildPath(_ref) {
365
+ var uniqueGroups = _ref.uniqueGroups,
366
+ licenseId = _ref.licenseId,
367
+ groupId = _ref.groupId;
368
+ return (uniqueGroups ? "/licence/g" + licenseId + "_" + groupId : '') + "/customer";
369
+ };
370
+ var buildRequestUrl = function buildRequestUrl(config, env) {
371
+ var url = env === 'production' ? ACCOUNTS_URL : ACCOUNTS_URL.replace('accounts.', "accounts." + env + ".");
372
+ var path = buildPath(config);
373
+ return "" + url + path;
374
+ };
375
+
376
+ var POST_MESSAGE_ORIGIN = 'https://accounts.livechatinc.com';
377
+ var CUSTOMER_AUTH_FOOTPRINT = '@livechat/customer-auth';
378
+ var getPostMessageOrigin = function getPostMessageOrigin(env) {
379
+ return env === 'production' ? POST_MESSAGE_ORIGIN : POST_MESSAGE_ORIGIN.replace('accounts.', "accounts." + env + ".");
380
+ };
381
+ var buildParams = function buildParams(_ref, redirectUri) {
382
+ var clientId = _ref.clientId,
383
+ licenseId = _ref.licenseId;
384
+ return {
385
+ license_id: String(licenseId),
386
+ flow: 'button',
387
+ response_type: 'token',
388
+ client_id: clientId,
389
+ redirect_uri: redirectUri,
390
+ post_message_uri: redirectUri,
391
+ state: CUSTOMER_AUTH_FOOTPRINT
392
+ };
393
+ };
394
+ var buildIframe = function buildIframe(config, env) {
395
+ var redirectUri = getOrigin(String(window.location)) + window.location.pathname;
396
+ var params = buildParams(config, redirectUri);
397
+ var iframe = document.createElement('iframe');
398
+ iframe.style.display = 'none';
399
+ iframe.setAttribute('src', buildRequestUrl(config, env) + "?" + buildQueryString(params));
400
+ return iframe;
401
+ };
402
+ var isTokenResponse = function isTokenResponse(data) {
403
+ return data && data.state === CUSTOMER_AUTH_FOOTPRINT;
404
+ };
405
+ function fetchUsingIframe(config, env) {
406
+ var licenseId = config.licenseId;
407
+ var postMessageOrigin = getPostMessageOrigin(env);
408
+ return new Promise(function (resolve, reject) {
409
+ var iframe = buildIframe(config, env);
410
+ var cleanup = function cleanup() {
411
+ removeNode(iframe);
412
+ // eslint-disable-next-line no-use-before-define
413
+ window.removeEventListener('message', listener, false);
414
+ };
415
+ var timeoutId = setTimeout(function () {
416
+ cleanup();
417
+ reject(createError({
418
+ message: 'Request timed out.',
419
+ code: 'REQUEST_TIMEOUT'
420
+ }));
421
+ }, 15 * 1000);
422
+ var listener = function listener(_ref2) {
423
+ var origin = _ref2.origin,
424
+ data = _ref2.data;
425
+ if (origin !== postMessageOrigin) {
426
+ return;
427
+ }
428
+ if (!isTokenResponse(data)) {
429
+ return;
430
+ }
431
+ clearTimeout(timeoutId);
432
+ cleanup();
433
+ try {
434
+ resolve(parseTokenResponse(data, licenseId));
435
+ } catch (err) {
436
+ reject(err);
437
+ }
438
+ };
439
+ window.addEventListener('message', listener, false);
440
+ getRoot().then(function (body) {
441
+ body.appendChild(iframe);
442
+ });
443
+ });
444
+ }
445
+
525
446
  var fetchToken = function fetchToken(config, env) {
526
- return unfetch("" + buildRequestUrl(config, env), {
447
+ if (config.uniqueGroups) {
448
+ return fetchUsingIframe(config, env);
449
+ }
450
+ return unfetch(buildRequestUrl(config, env) + "/token", {
527
451
  method: 'POST',
528
452
  credentials: 'include',
529
453
  body: JSON.stringify({
530
454
  response_type: 'token',
531
455
  grant_type: 'cookie',
532
456
  client_id: config.clientId,
533
- organization_id: config.organizationId,
457
+ license_id: config.licenseId,
534
458
  redirect_uri: getOrigin(String(window.location)) + window.location.pathname
535
459
  })
536
460
  }).then(function (res) {
537
461
  return res.json();
538
462
  }).then(function (token) {
539
- return parseTokenResponse(token, config.organizationId);
463
+ return parseTokenResponse(token, config.licenseId);
540
464
  });
541
465
  };
542
466
 
543
467
  var validateConfig = function validateConfig(_ref) {
544
- var organizationId = _ref.organizationId,
468
+ var licenseId = _ref.licenseId,
545
469
  clientId = _ref.clientId;
546
- if (typeof organizationId !== 'string' || typeof clientId !== 'string') {
547
- throw new Error('You need to pass valid configuration object: { organizationId, clientId }.');
470
+ if (typeof licenseId !== 'number' || typeof clientId !== 'string') {
471
+ throw new Error('You need to pass valid configuration object: { licenseId, clientId }.');
548
472
  }
549
473
  };
550
474
 
@@ -553,39 +477,25 @@
553
477
  expiresIn = _ref.expiresIn;
554
478
  return Date.now() >= creationDate + expiresIn;
555
479
  };
556
- var createAuth = function createAuth(config, licenseId, env) {
480
+ var createAuth = function createAuth(config, env) {
557
481
  validateConfig(config);
558
- var tokenStoragePrefix = config.tokenStoragePrefix || "@@lc_auth_token:";
559
- var oldCacheKey = "" + tokenStoragePrefix + licenseId + (config.uniqueGroups ? ":" + config.groupId : '');
560
- var newCacheKey = "" + tokenStoragePrefix + config.organizationId + (config.uniqueGroups ? ":" + config.groupId : '');
482
+ var cacheKey = "" + "@@lc_auth_token:" + config.licenseId + (config.uniqueGroups ? ":" + config.groupId : '');
561
483
  var pendingTokenRequest = null;
562
484
  var cachedToken = null;
563
- var retrievingToken = storage.getItem(oldCacheKey).then(function (token) {
485
+ var retrievingToken = storage.getItem(cacheKey).then(function (token) {
564
486
  if (retrievingToken === null) {
565
487
  return;
566
488
  }
567
489
  retrievingToken = null;
568
490
  if (!token) {
569
- storage.removeItem(oldCacheKey).then(function () {
570
- return storage.getItem(newCacheKey).then(function (newKeyToken) {
571
- if (!newKeyToken) {
572
- return;
573
- }
574
- cachedToken = JSON.parse(newKeyToken);
575
- });
576
- });
577
491
  return;
578
492
  }
579
- storage.setItem(newCacheKey, token).then(function () {
580
- storage.removeItem(oldCacheKey).then(function () {
581
- cachedToken = JSON.parse(token);
582
- });
583
- });
493
+ cachedToken = JSON.parse(token);
584
494
  });
585
495
  var getFreshToken = function getFreshToken() {
586
496
  pendingTokenRequest = fetchToken(config, env).then(function (token) {
587
497
  pendingTokenRequest = null;
588
- storage.setItem(newCacheKey, JSON.stringify(token));
498
+ storage.setItem(cacheKey, JSON.stringify(token));
589
499
  cachedToken = token;
590
500
  return token;
591
501
  }, function (err) {
@@ -615,7 +525,7 @@
615
525
  var invalidate = function invalidate() {
616
526
  cachedToken = null;
617
527
  retrievingToken = null;
618
- return storage.removeItem(newCacheKey);
528
+ return storage.removeItem(cacheKey);
619
529
  };
620
530
  return {
621
531
  getFreshToken: getFreshToken,
@@ -1184,47 +1094,13 @@
1184
1094
  return sideEffectsMiddleware;
1185
1095
  };
1186
1096
 
1187
- var createBackoff = function createBackoff(_ref) {
1188
- var _ref$min = _ref.min,
1189
- min = _ref$min === void 0 ? 1000 : _ref$min,
1190
- _ref$max = _ref.max,
1191
- max = _ref$max === void 0 ? 5000 : _ref$max,
1192
- _ref$jitter = _ref.jitter,
1193
- jitter = _ref$jitter === void 0 ? 0.5 : _ref$jitter;
1194
- var attempts = 0;
1195
- return {
1196
- duration: function duration() {
1197
- var ms = min * Math.pow(2, attempts++);
1198
- if (jitter) {
1199
- var rand = Math.random();
1200
- var deviation = Math.floor(rand * jitter * ms);
1201
- ms = (Math.floor(rand * 10) & 1) === 0 ? ms - deviation : ms + deviation;
1202
- }
1203
- return Math.min(ms, max) | 0;
1204
- },
1205
- reset: function reset() {
1206
- attempts = 0;
1207
- }
1208
- };
1209
- };
1210
-
1211
- /**
1212
- * Creates a deferred object that can be resolved or rejected later.
1213
- * @returns A deferred object with a promise and resolve and reject functions.
1214
- * @example
1215
- * const def = promiseDeferred()
1216
- * const promise = def.promise
1217
- * def.resolve(1)
1218
- * return promise.then(res => console.log(res)) // 1
1219
- */
1220
-
1221
- function promiseDeferred() {
1222
- var deferred = {};
1223
- deferred.promise = new Promise(function (resolve, reject) {
1224
- deferred.resolve = resolve;
1225
- deferred.reject = reject;
1097
+ function deferred() {
1098
+ var def = {};
1099
+ def.promise = new Promise(function (resolve, reject) {
1100
+ def.resolve = resolve;
1101
+ def.reject = reject;
1226
1102
  });
1227
- return deferred;
1103
+ return def;
1228
1104
  }
1229
1105
 
1230
1106
  var createReducer = function createReducer(initialState, reducersMap) {
@@ -1309,7 +1185,7 @@
1309
1185
  return {
1310
1186
  application: _extends({}, application, {
1311
1187
  name: "customer_sdk",
1312
- version: "3.1.4"
1188
+ version: "3.1.5"
1313
1189
  }),
1314
1190
  licenseId: licenseId,
1315
1191
  env: env,
@@ -1762,15 +1638,6 @@
1762
1638
  };
1763
1639
  };
1764
1640
 
1765
- function deferred() {
1766
- var def = {};
1767
- def.promise = new Promise(function (resolve, reject) {
1768
- def.resolve = resolve;
1769
- def.reject = reject;
1770
- });
1771
- return def;
1772
- }
1773
-
1774
1641
  // TODO: this thing is not really well typed and should be improved
1775
1642
  var sendRequestAction = function sendRequestAction(store, action) {
1776
1643
  action.payload.id = generateUniqueId(store.getState().requests);
@@ -1785,10 +1652,34 @@
1785
1652
  return promise;
1786
1653
  };
1787
1654
 
1788
- var index$1 = function (fn) {
1655
+ var promiseTry = (function (fn) {
1789
1656
  return new Promise(function (resolve) {
1790
1657
  resolve(fn());
1791
1658
  });
1659
+ });
1660
+
1661
+ var createBackoff = function createBackoff(_ref) {
1662
+ var _ref$min = _ref.min,
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;
1668
+ var attempts = 0;
1669
+ return {
1670
+ duration: function duration() {
1671
+ var ms = min * Math.pow(2, attempts++);
1672
+ if (jitter) {
1673
+ var rand = Math.random();
1674
+ var deviation = Math.floor(rand * jitter * ms);
1675
+ ms = (Math.floor(rand * 10) & 1) === 0 ? ms - deviation : ms + deviation;
1676
+ }
1677
+ return Math.min(ms, max) | 0;
1678
+ },
1679
+ reset: function reset() {
1680
+ attempts = 0;
1681
+ }
1682
+ };
1792
1683
  };
1793
1684
 
1794
1685
  var AUTHENTICATION = 'AUTHENTICATION';
@@ -1821,7 +1712,7 @@
1821
1712
  var cancelled = false;
1822
1713
  var next = function next(intermediateResult) {
1823
1714
  var step = steps.shift();
1824
- index$1(function () {
1715
+ promiseTry(function () {
1825
1716
  return step(intermediateResult);
1826
1717
  }).then(function (result) {
1827
1718
  if (cancelled) {
@@ -3102,14 +2993,14 @@
3102
2993
  resolve = noop;
3103
2994
  },
3104
2995
  check: function check() {
3105
- var deferred = promiseDeferred();
3106
- resolve = deferred.resolve;
2996
+ var deferred$1 = deferred();
2997
+ resolve = deferred$1.resolve;
3107
2998
  timer = setTimeout(function () {
3108
2999
  var err = new Error('Timeout.');
3109
3000
  err.code = 'TIMEOUT';
3110
- deferred.reject(err);
3001
+ deferred$1.reject(err);
3111
3002
  }, 2000);
3112
- return deferred.promise;
3003
+ return deferred$1.promise;
3113
3004
  },
3114
3005
  resolve: function (_resolve) {
3115
3006
  function resolve() {
@@ -4263,7 +4154,7 @@
4263
4154
  var message = {
4264
4155
  event_name: eventName,
4265
4156
  severity: 'Informational',
4266
- sdkVersion: "3.1.4"
4157
+ sdkVersion: "3.1.5"
4267
4158
  };
4268
4159
  var body = {
4269
4160
  licence_id: licenseId,