@livechat/customer-sdk 3.1.2 → 3.1.4

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 +279 -170
  6. package/dist/customer-sdk.min.js +1 -1
  7. package/package.json +3 -4
  8. package/types/actions.d.ts +0 -331
  9. package/types/chatHistory.d.ts +0 -19
  10. package/types/clientDataParsers.d.ts +0 -55
  11. package/types/completionValues.d.ts +0 -4
  12. package/types/constants/clientErrorCodes.d.ts +0 -11
  13. package/types/constants/connectionStatuses.d.ts +0 -6
  14. package/types/constants/eventTypes.d.ts +0 -8
  15. package/types/constants/reduxActions.d.ts +0 -23
  16. package/types/constants/serverDisconnectionReasons.d.ts +0 -15
  17. package/types/constants/serverErrorCodes.d.ts +0 -23
  18. package/types/constants/serverPushActions.d.ts +0 -26
  19. package/types/constants/serverRequestActions.d.ts +0 -30
  20. package/types/constants/sortOrders.d.ts +0 -3
  21. package/types/constants/userTypes.d.ts +0 -3
  22. package/types/createError.d.ts +0 -9
  23. package/types/createStore.d.ts +0 -12
  24. package/types/debug.d.ts +0 -3
  25. package/types/graylog/index.d.ts +0 -14
  26. package/types/graylog/makeGrayLogRequest.d.ts +0 -2
  27. package/types/graylog/makeGrayLogRequest.native.d.ts +0 -6
  28. package/types/index.d.ts +0 -239
  29. package/types/reducer.d.ts +0 -546
  30. package/types/sendRequestAction.d.ts +0 -4
  31. package/types/sendTicketForm.d.ts +0 -14
  32. package/types/serverDataParser.d.ts +0 -34
  33. package/types/serverEventParser.d.ts +0 -12
  34. package/types/serverFrameParser.d.ts +0 -385
  35. package/types/sideEffects/checkGoals.d.ts +0 -5
  36. package/types/sideEffects/index.d.ts +0 -12
  37. package/types/sideStorage.d.ts +0 -5
  38. package/types/socketClient.d.ts +0 -11
  39. package/types/socketListener.d.ts +0 -9
  40. package/types/thunks.d.ts +0 -4
  41. package/types/types/actions.d.ts +0 -157
  42. package/types/types/clientEntities.d.ts +0 -374
  43. package/types/types/frames.d.ts +0 -635
  44. package/types/types/serverEntities.d.ts +0 -408
  45. package/types/types/state.d.ts +0 -56
  46. package/types/uploadFile.d.ts +0 -19
  47. package/types/validateFile/index.d.ts +0 -3
@@ -105,43 +105,125 @@
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
+ */
108
114
  function hasOwn(prop, obj) {
109
115
  return hasOwnProperty.call(obj, prop);
110
116
  }
111
117
 
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
+ */
112
125
  function flatMap(iteratee, arr) {
113
126
  var _ref;
114
127
  return (_ref = []).concat.apply(_ref, arr.map(iteratee));
115
128
  }
116
129
 
117
- var isArray = Array.isArray;
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
+ }
118
141
 
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
+ */
119
150
  // eslint-disable-next-line @typescript-eslint/ban-types
120
151
  function isObject(obj) {
121
152
  return typeof obj === 'object' && obj !== null && !isArray(obj);
122
153
  }
123
154
 
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
+ */
124
180
  function mapValues(mapper, obj) {
125
- return Object.keys(obj).reduce(function (acc, key) {
181
+ return keys(obj).reduce(function (acc, key) {
126
182
  acc[key] = mapper(obj[key]);
127
183
  return acc;
128
184
  }, {});
129
185
  }
130
186
 
187
+ /**
188
+ * returns the provided value
189
+ * @example
190
+ * identity('hello')
191
+ * // returns 'hello'
192
+ */
131
193
  function identity(value) {
132
194
  return value;
133
195
  }
134
196
 
197
+ /**
198
+ * generates a random id
199
+ * @example
200
+ * generateRandomId()
201
+ * // returns 'd1rjknhhch8'
202
+ */
135
203
  function generateRandomId() {
136
204
  return Math.random().toString(36).substring(2);
137
205
  }
138
206
 
207
+ /**
208
+ * generates an unique id based on the provided object keys
209
+ * @example
210
+ * generateUniqueId({ xuvarw8cao: 1, b837g2nba1d: 2 })
211
+ * // returns 'd1rjknhhch8'
212
+ */
139
213
  function generateUniqueId(map) {
140
214
  var id = generateRandomId();
141
215
  return hasOwn(id, map) ? generateUniqueId(map) : id;
142
216
  }
143
217
 
144
- // based on https://github.com/developit/dlv/blob/d7ec976d12665f1c25dec2acf955dfc2e8757a9c/index.js
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
+ */
145
227
  function get(propPath, obj) {
146
228
  var arrPath = typeof propPath === 'string' ? propPath.split('.') : propPath;
147
229
  var pathPartIndex = 0;
@@ -152,14 +234,40 @@
152
234
  return result;
153
235
  }
154
236
 
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
+
155
246
  function includes(value, arrOrStr) {
156
247
  return arrOrStr.indexOf(value) !== -1;
157
248
  }
158
249
 
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
+ */
159
256
  function isEmpty(collection) {
160
257
  return (isArray(collection) ? collection : Object.keys(collection)).length === 0;
161
258
  }
162
259
 
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
+ */
163
271
  function keyBy(prop, arr) {
164
272
  return arr.reduce(function (acc, el) {
165
273
  acc[el[prop]] = el;
@@ -167,20 +275,47 @@
167
275
  }, {});
168
276
  }
169
277
 
170
- // TODO: this should return `T | undefined` to match native behavior
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
+ */
171
284
  function last(arr) {
172
- return arr.length > 0 ? arr[arr.length - 1] : null;
285
+ return arr.length > 0 ? arr[arr.length - 1] : undefined;
173
286
  }
174
287
 
288
+ /**
289
+ * does literally nothing
290
+ * @example
291
+ * somethingAsyncAndDangerous().catch(noop)
292
+ */
175
293
  // eslint-disable-next-line @typescript-eslint/no-empty-function
176
294
  function noop() {}
177
295
 
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
+ */
178
302
  function values(obj) {
179
- return Object.keys(obj).map(function (key) {
303
+ return keys(obj).map(function (key) {
180
304
  return obj[key];
181
305
  });
182
306
  }
183
307
 
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
+ */
184
319
  function numericSortBy(propOrMapper, collection) {
185
320
  var mapper = typeof propOrMapper === 'function' ? propOrMapper : function (element) {
186
321
  return get(propOrMapper, element);
@@ -190,13 +325,25 @@
190
325
  });
191
326
  }
192
327
 
193
- function pick(props, obj) {
194
- return props.reduce(function (acc, prop) {
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) {
195
336
  acc[prop] = obj[prop];
196
337
  return acc;
197
338
  }, {});
198
339
  }
199
340
 
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
+ */
200
347
  function pickOwn(props, obj) {
201
348
  return props.reduce(function (acc, prop) {
202
349
  if (hasOwn(prop, obj)) {
@@ -206,19 +353,41 @@
206
353
  }, {});
207
354
  }
208
355
 
209
- var toPairs = function toPairs(obj) {
210
- return Object.keys(obj).map(function (key) {
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) {
211
364
  return [key, obj[key]];
212
365
  });
213
- };
366
+ }
214
367
 
215
- var stringCompare = function stringCompare(strA, strB) {
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) {
216
379
  if (strA === strB) {
217
380
  return 0;
218
381
  }
219
382
  return strA < strB ? -1 : 1;
220
- };
383
+ }
221
384
 
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
+ */
222
391
  function uniqBy(iteratee, arr) {
223
392
  // with polyfills this could be just: return Array.from(new Set(arr.map(iteratee)))
224
393
  var seen = [];
@@ -309,25 +478,18 @@
309
478
  });
310
479
  }
311
480
 
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
- }
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
+ };
331
493
 
332
494
  var createError = function createError(_ref) {
333
495
  var code = _ref.code,
@@ -337,7 +499,7 @@
337
499
  return err;
338
500
  };
339
501
 
340
- var parseTokenResponse = function parseTokenResponse(token, licenseId) {
502
+ var parseTokenResponse = function parseTokenResponse(token, organizationId) {
341
503
  if ('identity_exception' in token) {
342
504
  throw createError({
343
505
  code: 'SSO_IDENTITY_EXCEPTION',
@@ -356,119 +518,33 @@
356
518
  expiresIn: token.expires_in * 1000,
357
519
  tokenType: token.token_type,
358
520
  creationDate: Date.now(),
359
- licenseId: licenseId
521
+ organizationId: organizationId
360
522
  };
361
523
  };
362
524
 
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
-
446
525
  var fetchToken = function fetchToken(config, env) {
447
- if (config.uniqueGroups) {
448
- return fetchUsingIframe(config, env);
449
- }
450
- return unfetch(buildRequestUrl(config, env) + "/token", {
526
+ return unfetch("" + buildRequestUrl(config, env), {
451
527
  method: 'POST',
452
528
  credentials: 'include',
453
529
  body: JSON.stringify({
454
530
  response_type: 'token',
455
531
  grant_type: 'cookie',
456
532
  client_id: config.clientId,
457
- license_id: config.licenseId,
533
+ organization_id: config.organizationId,
458
534
  redirect_uri: getOrigin(String(window.location)) + window.location.pathname
459
535
  })
460
536
  }).then(function (res) {
461
537
  return res.json();
462
538
  }).then(function (token) {
463
- return parseTokenResponse(token, config.licenseId);
539
+ return parseTokenResponse(token, config.organizationId);
464
540
  });
465
541
  };
466
542
 
467
543
  var validateConfig = function validateConfig(_ref) {
468
- var licenseId = _ref.licenseId,
544
+ var organizationId = _ref.organizationId,
469
545
  clientId = _ref.clientId;
470
- if (typeof licenseId !== 'number' || typeof clientId !== 'string') {
471
- throw new Error('You need to pass valid configuration object: { licenseId, clientId }.');
546
+ if (typeof organizationId !== 'string' || typeof clientId !== 'string') {
547
+ throw new Error('You need to pass valid configuration object: { organizationId, clientId }.');
472
548
  }
473
549
  };
474
550
 
@@ -477,25 +553,39 @@
477
553
  expiresIn = _ref.expiresIn;
478
554
  return Date.now() >= creationDate + expiresIn;
479
555
  };
480
- var createAuth = function createAuth(config, env) {
556
+ var createAuth = function createAuth(config, licenseId, env) {
481
557
  validateConfig(config);
482
- var cacheKey = "" + "@@lc_auth_token:" + config.licenseId + (config.uniqueGroups ? ":" + config.groupId : '');
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 : '');
483
561
  var pendingTokenRequest = null;
484
562
  var cachedToken = null;
485
- var retrievingToken = storage.getItem(cacheKey).then(function (token) {
563
+ var retrievingToken = storage.getItem(oldCacheKey).then(function (token) {
486
564
  if (retrievingToken === null) {
487
565
  return;
488
566
  }
489
567
  retrievingToken = null;
490
568
  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
+ });
491
577
  return;
492
578
  }
493
- cachedToken = JSON.parse(token);
579
+ storage.setItem(newCacheKey, token).then(function () {
580
+ storage.removeItem(oldCacheKey).then(function () {
581
+ cachedToken = JSON.parse(token);
582
+ });
583
+ });
494
584
  });
495
585
  var getFreshToken = function getFreshToken() {
496
586
  pendingTokenRequest = fetchToken(config, env).then(function (token) {
497
587
  pendingTokenRequest = null;
498
- storage.setItem(cacheKey, JSON.stringify(token));
588
+ storage.setItem(newCacheKey, JSON.stringify(token));
499
589
  cachedToken = token;
500
590
  return token;
501
591
  }, function (err) {
@@ -525,7 +615,7 @@
525
615
  var invalidate = function invalidate() {
526
616
  cachedToken = null;
527
617
  retrievingToken = null;
528
- return storage.removeItem(cacheKey);
618
+ return storage.removeItem(newCacheKey);
529
619
  };
530
620
  return {
531
621
  getFreshToken: getFreshToken,
@@ -1094,13 +1184,47 @@
1094
1184
  return sideEffectsMiddleware;
1095
1185
  };
1096
1186
 
1097
- function deferred() {
1098
- var def = {};
1099
- def.promise = new Promise(function (resolve, reject) {
1100
- def.resolve = resolve;
1101
- def.reject = reject;
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;
1102
1226
  });
1103
- return def;
1227
+ return deferred;
1104
1228
  }
1105
1229
 
1106
1230
  var createReducer = function createReducer(initialState, reducersMap) {
@@ -1185,7 +1309,7 @@
1185
1309
  return {
1186
1310
  application: _extends({}, application, {
1187
1311
  name: "customer_sdk",
1188
- version: "3.1.2"
1312
+ version: "3.1.4"
1189
1313
  }),
1190
1314
  licenseId: licenseId,
1191
1315
  env: env,
@@ -1638,6 +1762,15 @@
1638
1762
  };
1639
1763
  };
1640
1764
 
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
+
1641
1774
  // TODO: this thing is not really well typed and should be improved
1642
1775
  var sendRequestAction = function sendRequestAction(store, action) {
1643
1776
  action.payload.id = generateUniqueId(store.getState().requests);
@@ -1652,34 +1785,10 @@
1652
1785
  return promise;
1653
1786
  };
1654
1787
 
1655
- var promiseTry = (function (fn) {
1788
+ var index$1 = function (fn) {
1656
1789
  return new Promise(function (resolve) {
1657
1790
  resolve(fn());
1658
1791
  });
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
- };
1683
1792
  };
1684
1793
 
1685
1794
  var AUTHENTICATION = 'AUTHENTICATION';
@@ -1712,7 +1821,7 @@
1712
1821
  var cancelled = false;
1713
1822
  var next = function next(intermediateResult) {
1714
1823
  var step = steps.shift();
1715
- promiseTry(function () {
1824
+ index$1(function () {
1716
1825
  return step(intermediateResult);
1717
1826
  }).then(function (result) {
1718
1827
  if (cancelled) {
@@ -2993,14 +3102,14 @@
2993
3102
  resolve = noop;
2994
3103
  },
2995
3104
  check: function check() {
2996
- var deferred$1 = deferred();
2997
- resolve = deferred$1.resolve;
3105
+ var deferred = promiseDeferred();
3106
+ resolve = deferred.resolve;
2998
3107
  timer = setTimeout(function () {
2999
3108
  var err = new Error('Timeout.');
3000
3109
  err.code = 'TIMEOUT';
3001
- deferred$1.reject(err);
3110
+ deferred.reject(err);
3002
3111
  }, 2000);
3003
- return deferred$1.promise;
3112
+ return deferred.promise;
3004
3113
  },
3005
3114
  resolve: function (_resolve) {
3006
3115
  function resolve() {
@@ -4154,7 +4263,7 @@
4154
4263
  var message = {
4155
4264
  event_name: eventName,
4156
4265
  severity: 'Informational',
4157
- sdkVersion: "3.1.2"
4266
+ sdkVersion: "3.1.4"
4158
4267
  };
4159
4268
  var body = {
4160
4269
  licence_id: licenseId,