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