@microsoft/1ds-post-js 3.2.0 → 3.2.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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/bundle/{ms.post-3.2.0.gbl.js → ms.post-3.2.3.gbl.js} +1022 -986
  3. package/bundle/ms.post-3.2.3.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.3.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.3.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.3.integrity.json +46 -0
  7. package/bundle/{ms.post-3.2.0.js → ms.post-3.2.3.js} +1022 -986
  8. package/bundle/ms.post-3.2.3.js.map +1 -0
  9. package/bundle/ms.post-3.2.3.min.js +7 -0
  10. package/bundle/ms.post-3.2.3.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1021 -985
  12. package/bundle/ms.post.gbl.js.map +1 -1
  13. package/bundle/ms.post.gbl.min.js +2 -2
  14. package/bundle/ms.post.gbl.min.js.map +1 -1
  15. package/bundle/ms.post.integrity.json +17 -17
  16. package/bundle/ms.post.js +1021 -985
  17. package/bundle/ms.post.js.map +1 -1
  18. package/bundle/ms.post.min.js +2 -2
  19. package/bundle/ms.post.min.js.map +1 -1
  20. package/dist/ms.post.js +56 -27
  21. package/dist/ms.post.js.map +1 -1
  22. package/dist/ms.post.min.js +2 -2
  23. package/dist/ms.post.min.js.map +1 -1
  24. package/dist-esm/src/BatchNotificationActions.js +1 -1
  25. package/dist-esm/src/ClockSkewManager.js +1 -1
  26. package/dist-esm/src/Constants.js +1 -1
  27. package/dist-esm/src/DataModels.js +1 -1
  28. package/dist-esm/src/EventBatch.js +1 -1
  29. package/dist-esm/src/HttpManager.d.ts +2 -1
  30. package/dist-esm/src/HttpManager.js +67 -67
  31. package/dist-esm/src/HttpManager.js.map +1 -1
  32. package/dist-esm/src/Index.js +1 -1
  33. package/dist-esm/src/KillSwitch.js +1 -1
  34. package/dist-esm/src/PostChannel.d.ts +2 -5
  35. package/dist-esm/src/PostChannel.js +84 -66
  36. package/dist-esm/src/PostChannel.js.map +1 -1
  37. package/dist-esm/src/RetryPolicy.js +1 -1
  38. package/dist-esm/src/Serializer.js +1 -1
  39. package/dist-esm/src/TimeoutOverrideWrapper.d.ts +18 -0
  40. package/dist-esm/src/TimeoutOverrideWrapper.js +28 -0
  41. package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -0
  42. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  43. package/package.json +3 -3
  44. package/src/HttpManager.ts +5 -4
  45. package/src/PostChannel.ts +59 -27
  46. package/src/TimeoutOverrideWrapper.ts +29 -0
  47. package/bundle/ms.post-3.2.0.gbl.js.map +0 -1
  48. package/bundle/ms.post-3.2.0.gbl.min.js +0 -7
  49. package/bundle/ms.post-3.2.0.gbl.min.js.map +0 -1
  50. package/bundle/ms.post-3.2.0.integrity.json +0 -46
  51. package/bundle/ms.post-3.2.0.js.map +0 -1
  52. package/bundle/ms.post-3.2.0.min.js +0 -7
  53. package/bundle/ms.post-3.2.0.min.js.map +0 -1
package/bundle/ms.post.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK POST plugin, 3.2.0
2
+ * 1DS JS SDK POST plugin, 3.2.3
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -83,6 +83,254 @@
83
83
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
84
84
  }
85
85
 
86
+ /*!
87
+ * Microsoft Dynamic Proto Utility, 1.1.6
88
+ * Copyright (c) Microsoft and contributors. All rights reserved.
89
+ */
90
+ var Constructor = 'constructor';
91
+ var Prototype = 'prototype';
92
+ var strFunction = 'function';
93
+ var DynInstFuncTable = '_dynInstFuncs';
94
+ var DynProxyTag = '_isDynProxy';
95
+ var DynClassName = '_dynClass';
96
+ var DynClassNamePrefix = '_dynCls$';
97
+ var DynInstChkTag = '_dynInstChk';
98
+ var DynAllowInstChkTag = DynInstChkTag;
99
+ var DynProtoDefaultOptions = '_dfOpts';
100
+ var UnknownValue = '_unknown_';
101
+ var str__Proto$1 = "__proto__";
102
+ var DynProtoBaseProto = "_dyn" + str__Proto$1;
103
+ var DynProtoCurrent = "_dynInstProto";
104
+ var strUseBaseInst = 'useBaseInst';
105
+ var strSetInstFuncs = 'setInstFuncs';
106
+ var Obj = Object;
107
+ var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
108
+ var _objGetOwnProps = Obj["getOwnPropertyNames"];
109
+ var _dynamicNames = 0;
110
+ function _hasOwnProperty(obj, prop) {
111
+ return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
112
+ }
113
+ function _isObjectOrArrayPrototype(target) {
114
+ return target && (target === Obj[Prototype] || target === Array[Prototype]);
115
+ }
116
+ function _isObjectArrayOrFunctionPrototype(target) {
117
+ return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
118
+ }
119
+ function _getObjProto$1(target) {
120
+ var newProto;
121
+ if (target) {
122
+ if (_objGetPrototypeOf$1) {
123
+ return _objGetPrototypeOf$1(target);
124
+ }
125
+ var curProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
126
+ newProto = target[DynProtoBaseProto] || curProto;
127
+ if (!_hasOwnProperty(target, DynProtoBaseProto)) {
128
+ delete target[DynProtoCurrent];
129
+ newProto = target[DynProtoBaseProto] = target[DynProtoCurrent] || target[DynProtoBaseProto];
130
+ target[DynProtoCurrent] = curProto;
131
+ }
132
+ }
133
+ return newProto;
134
+ }
135
+ function _forEachProp(target, func) {
136
+ var props = [];
137
+ if (_objGetOwnProps) {
138
+ props = _objGetOwnProps(target);
139
+ }
140
+ else {
141
+ for (var name_1 in target) {
142
+ if (typeof name_1 === "string" && _hasOwnProperty(target, name_1)) {
143
+ props.push(name_1);
144
+ }
145
+ }
146
+ }
147
+ if (props && props.length > 0) {
148
+ for (var lp = 0; lp < props.length; lp++) {
149
+ func(props[lp]);
150
+ }
151
+ }
152
+ }
153
+ function _isDynamicCandidate(target, funcName, skipOwn) {
154
+ return (funcName !== Constructor && typeof target[funcName] === strFunction && (skipOwn || _hasOwnProperty(target, funcName)));
155
+ }
156
+ function _throwTypeError(message) {
157
+ throw new TypeError("DynamicProto: " + message);
158
+ }
159
+ function _getInstanceFuncs(thisTarget) {
160
+ var instFuncs = {};
161
+ _forEachProp(thisTarget, function (name) {
162
+ if (!instFuncs[name] && _isDynamicCandidate(thisTarget, name, false)) {
163
+ instFuncs[name] = thisTarget[name];
164
+ }
165
+ });
166
+ return instFuncs;
167
+ }
168
+ function _hasVisited(values, value) {
169
+ for (var lp = values.length - 1; lp >= 0; lp--) {
170
+ if (values[lp] === value) {
171
+ return true;
172
+ }
173
+ }
174
+ return false;
175
+ }
176
+ function _getBaseFuncs(classProto, thisTarget, instFuncs, useBaseInst) {
177
+ function _instFuncProxy(target, funcHost, funcName) {
178
+ var theFunc = funcHost[funcName];
179
+ if (theFunc[DynProxyTag] && useBaseInst) {
180
+ var instFuncTable = target[DynInstFuncTable] || {};
181
+ if (instFuncTable[DynAllowInstChkTag] !== false) {
182
+ theFunc = (instFuncTable[funcHost[DynClassName]] || {})[funcName] || theFunc;
183
+ }
184
+ }
185
+ return function () {
186
+ return theFunc.apply(target, arguments);
187
+ };
188
+ }
189
+ var baseFuncs = {};
190
+ _forEachProp(instFuncs, function (name) {
191
+ baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
192
+ });
193
+ var baseProto = _getObjProto$1(classProto);
194
+ var visited = [];
195
+ while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
196
+ _forEachProp(baseProto, function (name) {
197
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf$1)) {
198
+ baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
199
+ }
200
+ });
201
+ visited.push(baseProto);
202
+ baseProto = _getObjProto$1(baseProto);
203
+ }
204
+ return baseFuncs;
205
+ }
206
+ function _getInstFunc(target, funcName, proto, currentDynProtoProxy) {
207
+ var instFunc = null;
208
+ if (target && _hasOwnProperty(proto, DynClassName)) {
209
+ var instFuncTable = target[DynInstFuncTable] || {};
210
+ instFunc = (instFuncTable[proto[DynClassName]] || {})[funcName];
211
+ if (!instFunc) {
212
+ _throwTypeError("Missing [" + funcName + "] " + strFunction);
213
+ }
214
+ if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
215
+ var canAddInst = !_hasOwnProperty(target, funcName);
216
+ var objProto = _getObjProto$1(target);
217
+ var visited = [];
218
+ while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
219
+ var protoFunc = objProto[funcName];
220
+ if (protoFunc) {
221
+ canAddInst = (protoFunc === currentDynProtoProxy);
222
+ break;
223
+ }
224
+ visited.push(objProto);
225
+ objProto = _getObjProto$1(objProto);
226
+ }
227
+ try {
228
+ if (canAddInst) {
229
+ target[funcName] = instFunc;
230
+ }
231
+ instFunc[DynInstChkTag] = 1;
232
+ }
233
+ catch (e) {
234
+ instFuncTable[DynAllowInstChkTag] = false;
235
+ }
236
+ }
237
+ }
238
+ return instFunc;
239
+ }
240
+ function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
241
+ var protoFunc = proto[funcName];
242
+ if (protoFunc === currentDynProtoProxy) {
243
+ protoFunc = _getObjProto$1(proto)[funcName];
244
+ }
245
+ if (typeof protoFunc !== strFunction) {
246
+ _throwTypeError("[" + funcName + "] is not a " + strFunction);
247
+ }
248
+ return protoFunc;
249
+ }
250
+ function _populatePrototype(proto, className, target, baseInstFuncs, setInstanceFunc) {
251
+ function _createDynamicPrototype(proto, funcName) {
252
+ var dynProtoProxy = function () {
253
+ var instFunc = _getInstFunc(this, funcName, proto, dynProtoProxy) || _getProtoFunc(funcName, proto, dynProtoProxy);
254
+ return instFunc.apply(this, arguments);
255
+ };
256
+ dynProtoProxy[DynProxyTag] = 1;
257
+ return dynProtoProxy;
258
+ }
259
+ if (!_isObjectOrArrayPrototype(proto)) {
260
+ var instFuncTable = target[DynInstFuncTable] = target[DynInstFuncTable] || {};
261
+ var instFuncs_1 = instFuncTable[className] = (instFuncTable[className] || {});
262
+ if (instFuncTable[DynAllowInstChkTag] !== false) {
263
+ instFuncTable[DynAllowInstChkTag] = !!setInstanceFunc;
264
+ }
265
+ _forEachProp(target, function (name) {
266
+ if (_isDynamicCandidate(target, name, false) && target[name] !== baseInstFuncs[name]) {
267
+ instFuncs_1[name] = target[name];
268
+ delete target[name];
269
+ if (!_hasOwnProperty(proto, name) || (proto[name] && !proto[name][DynProxyTag])) {
270
+ proto[name] = _createDynamicPrototype(proto, name);
271
+ }
272
+ }
273
+ });
274
+ }
275
+ }
276
+ function _checkPrototype(classProto, thisTarget) {
277
+ if (_objGetPrototypeOf$1) {
278
+ var visited = [];
279
+ var thisProto = _getObjProto$1(thisTarget);
280
+ while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
281
+ if (thisProto === classProto) {
282
+ return true;
283
+ }
284
+ visited.push(thisProto);
285
+ thisProto = _getObjProto$1(thisProto);
286
+ }
287
+ return false;
288
+ }
289
+ return true;
290
+ }
291
+ function _getObjName(target, unknownValue) {
292
+ if (_hasOwnProperty(target, Prototype)) {
293
+ return target.name || unknownValue || UnknownValue;
294
+ }
295
+ return (((target || {})[Constructor]) || {}).name || unknownValue || UnknownValue;
296
+ }
297
+ function dynamicProto(theClass, target, delegateFunc, options) {
298
+ if (!_hasOwnProperty(theClass, Prototype)) {
299
+ _throwTypeError("theClass is an invalid class definition.");
300
+ }
301
+ var classProto = theClass[Prototype];
302
+ if (!_checkPrototype(classProto, target)) {
303
+ _throwTypeError("[" + _getObjName(theClass) + "] is not in class hierarchy of [" + _getObjName(target) + "]");
304
+ }
305
+ var className = null;
306
+ if (_hasOwnProperty(classProto, DynClassName)) {
307
+ className = classProto[DynClassName];
308
+ }
309
+ else {
310
+ className = DynClassNamePrefix + _getObjName(theClass, "_") + "$" + _dynamicNames;
311
+ _dynamicNames++;
312
+ classProto[DynClassName] = className;
313
+ }
314
+ var perfOptions = dynamicProto[DynProtoDefaultOptions];
315
+ var useBaseInst = !!perfOptions[strUseBaseInst];
316
+ if (useBaseInst && options && options[strUseBaseInst] !== undefined) {
317
+ useBaseInst = !!options[strUseBaseInst];
318
+ }
319
+ var instFuncs = _getInstanceFuncs(target);
320
+ var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
321
+ delegateFunc(target, baseFuncs);
322
+ var setInstanceFunc = !!_objGetPrototypeOf$1 && !!perfOptions[strSetInstFuncs];
323
+ if (setInstanceFunc && options) {
324
+ setInstanceFunc = !!options[strSetInstFuncs];
325
+ }
326
+ _populatePrototype(classProto, className, target, instFuncs, setInstanceFunc !== false);
327
+ }
328
+ var perfDefaults = {
329
+ setInstFuncs: true,
330
+ useBaseInst: true
331
+ };
332
+ dynamicProto[DynProtoDefaultOptions] = perfDefaults;
333
+
86
334
  var strEmpty = "";
87
335
  var strSetNextPlugin = "setNextPlugin";
88
336
  var strIsInitialized = "isInitialized";
@@ -96,7 +344,7 @@
96
344
  var strIndexOf = "indexOf";
97
345
  var cStrTrim = "trim";
98
346
  var strToString = "toString";
99
- var str__Proto$1 = "__proto__";
347
+ var str__Proto = "__proto__";
100
348
  var strConstructor = "constructor";
101
349
  var _objDefineProperty$1 = ObjDefineProperty;
102
350
  var _objFreeze = ObjClass.freeze;
@@ -111,13 +359,13 @@
111
359
  var rCamelCase = /-([a-z])/g;
112
360
  var rNormalizeInvalid = /([^\w\d_$])/g;
113
361
  var rLeadingNumeric = /^(\d+[\w\d_$])/;
114
- var _objGetPrototypeOf$1 = Object["getPrototypeOf"];
115
- function _getObjProto$1(target) {
362
+ var _objGetPrototypeOf = Object["getPrototypeOf"];
363
+ function _getObjProto(target) {
116
364
  if (target) {
117
- if (_objGetPrototypeOf$1) {
118
- return _objGetPrototypeOf$1(target);
365
+ if (_objGetPrototypeOf) {
366
+ return _objGetPrototypeOf(target);
119
367
  }
120
- var newProto = target[str__Proto$1] || target[strShimPrototype] || target[strConstructor];
368
+ var newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
121
369
  if (newProto) {
122
370
  return newProto;
123
371
  }
@@ -203,7 +451,7 @@
203
451
  function isPlainObject(value) {
204
452
  var result = false;
205
453
  if (value && typeof value === "object") {
206
- var proto = _objGetPrototypeOf$1 ? _objGetPrototypeOf$1(value) : _getObjProto$1(value);
454
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
207
455
  if (!proto) {
208
456
  result = true;
209
457
  }
@@ -434,247 +682,6 @@
434
682
  QueueFull: 5
435
683
  });
436
684
 
437
- /*!
438
- * Microsoft Dynamic Proto Utility, 1.1.4
439
- * Copyright (c) Microsoft and contributors. All rights reserved.
440
- */
441
- var Constructor = 'constructor';
442
- var Prototype = 'prototype';
443
- var strFunction = 'function';
444
- var DynInstFuncTable = '_dynInstFuncs';
445
- var DynProxyTag = '_isDynProxy';
446
- var DynClassName = '_dynClass';
447
- var DynClassNamePrefix = '_dynCls$';
448
- var DynInstChkTag = '_dynInstChk';
449
- var DynAllowInstChkTag = DynInstChkTag;
450
- var DynProtoDefaultOptions = '_dfOpts';
451
- var UnknownValue = '_unknown_';
452
- var str__Proto = "__proto__";
453
- var strUseBaseInst = 'useBaseInst';
454
- var strSetInstFuncs = 'setInstFuncs';
455
- var Obj = Object;
456
- var _objGetPrototypeOf = Obj["getPrototypeOf"];
457
- var _dynamicNames = 0;
458
- function _hasOwnProperty(obj, prop) {
459
- return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
460
- }
461
- function _isObjectOrArrayPrototype(target) {
462
- return target && (target === Obj[Prototype] || target === Array[Prototype]);
463
- }
464
- function _isObjectArrayOrFunctionPrototype(target) {
465
- return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
466
- }
467
- function _getObjProto(target) {
468
- if (target) {
469
- if (_objGetPrototypeOf) {
470
- return _objGetPrototypeOf(target);
471
- }
472
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
473
- if (newProto) {
474
- return newProto;
475
- }
476
- }
477
- return null;
478
- }
479
- function _forEachProp(target, func) {
480
- var props = [];
481
- var getOwnProps = Obj["getOwnPropertyNames"];
482
- if (getOwnProps) {
483
- props = getOwnProps(target);
484
- }
485
- else {
486
- for (var name_1 in target) {
487
- if (typeof name_1 === "string" && _hasOwnProperty(target, name_1)) {
488
- props.push(name_1);
489
- }
490
- }
491
- }
492
- if (props && props.length > 0) {
493
- for (var lp = 0; lp < props.length; lp++) {
494
- func(props[lp]);
495
- }
496
- }
497
- }
498
- function _isDynamicCandidate(target, funcName, skipOwn) {
499
- return (funcName !== Constructor && typeof target[funcName] === strFunction && (skipOwn || _hasOwnProperty(target, funcName)));
500
- }
501
- function _throwTypeError(message) {
502
- throw new TypeError("DynamicProto: " + message);
503
- }
504
- function _getInstanceFuncs(thisTarget) {
505
- var instFuncs = {};
506
- _forEachProp(thisTarget, function (name) {
507
- if (!instFuncs[name] && _isDynamicCandidate(thisTarget, name, false)) {
508
- instFuncs[name] = thisTarget[name];
509
- }
510
- });
511
- return instFuncs;
512
- }
513
- function _hasVisited(values, value) {
514
- for (var lp = values.length - 1; lp >= 0; lp--) {
515
- if (values[lp] === value) {
516
- return true;
517
- }
518
- }
519
- return false;
520
- }
521
- function _getBaseFuncs(classProto, thisTarget, instFuncs, useBaseInst) {
522
- function _instFuncProxy(target, funcHost, funcName) {
523
- var theFunc = funcHost[funcName];
524
- if (theFunc[DynProxyTag] && useBaseInst) {
525
- var instFuncTable = target[DynInstFuncTable] || {};
526
- if (instFuncTable[DynAllowInstChkTag] !== false) {
527
- theFunc = (instFuncTable[funcHost[DynClassName]] || {})[funcName] || theFunc;
528
- }
529
- }
530
- return function () {
531
- return theFunc.apply(target, arguments);
532
- };
533
- }
534
- var baseFuncs = {};
535
- _forEachProp(instFuncs, function (name) {
536
- baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
537
- });
538
- var baseProto = _getObjProto(classProto);
539
- var visited = [];
540
- while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
541
- _forEachProp(baseProto, function (name) {
542
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
543
- baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
544
- }
545
- });
546
- visited.push(baseProto);
547
- baseProto = _getObjProto(baseProto);
548
- }
549
- return baseFuncs;
550
- }
551
- function _getInstFunc(target, funcName, proto, currentDynProtoProxy) {
552
- var instFunc = null;
553
- if (target && _hasOwnProperty(proto, DynClassName)) {
554
- var instFuncTable = target[DynInstFuncTable] || {};
555
- instFunc = (instFuncTable[proto[DynClassName]] || {})[funcName];
556
- if (!instFunc) {
557
- _throwTypeError("Missing [" + funcName + "] " + strFunction);
558
- }
559
- if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
560
- var canAddInst = !_hasOwnProperty(target, funcName);
561
- var objProto = _getObjProto(target);
562
- var visited = [];
563
- while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
564
- var protoFunc = objProto[funcName];
565
- if (protoFunc) {
566
- canAddInst = (protoFunc === currentDynProtoProxy);
567
- break;
568
- }
569
- visited.push(objProto);
570
- objProto = _getObjProto(objProto);
571
- }
572
- try {
573
- if (canAddInst) {
574
- target[funcName] = instFunc;
575
- }
576
- instFunc[DynInstChkTag] = 1;
577
- }
578
- catch (e) {
579
- instFuncTable[DynAllowInstChkTag] = false;
580
- }
581
- }
582
- }
583
- return instFunc;
584
- }
585
- function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
586
- var protoFunc = proto[funcName];
587
- if (protoFunc === currentDynProtoProxy) {
588
- protoFunc = _getObjProto(proto)[funcName];
589
- }
590
- if (typeof protoFunc !== strFunction) {
591
- _throwTypeError("[" + funcName + "] is not a " + strFunction);
592
- }
593
- return protoFunc;
594
- }
595
- function _populatePrototype(proto, className, target, baseInstFuncs, setInstanceFunc) {
596
- function _createDynamicPrototype(proto, funcName) {
597
- var dynProtoProxy = function () {
598
- var instFunc = _getInstFunc(this, funcName, proto, dynProtoProxy) || _getProtoFunc(funcName, proto, dynProtoProxy);
599
- return instFunc.apply(this, arguments);
600
- };
601
- dynProtoProxy[DynProxyTag] = 1;
602
- return dynProtoProxy;
603
- }
604
- if (!_isObjectOrArrayPrototype(proto)) {
605
- var instFuncTable = target[DynInstFuncTable] = target[DynInstFuncTable] || {};
606
- var instFuncs_1 = instFuncTable[className] = (instFuncTable[className] || {});
607
- if (instFuncTable[DynAllowInstChkTag] !== false) {
608
- instFuncTable[DynAllowInstChkTag] = !!setInstanceFunc;
609
- }
610
- _forEachProp(target, function (name) {
611
- if (_isDynamicCandidate(target, name, false) && target[name] !== baseInstFuncs[name]) {
612
- instFuncs_1[name] = target[name];
613
- delete target[name];
614
- if (!_hasOwnProperty(proto, name) || (proto[name] && !proto[name][DynProxyTag])) {
615
- proto[name] = _createDynamicPrototype(proto, name);
616
- }
617
- }
618
- });
619
- }
620
- }
621
- function _checkPrototype(classProto, thisTarget) {
622
- if (_objGetPrototypeOf) {
623
- var visited = [];
624
- var thisProto = _getObjProto(thisTarget);
625
- while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
626
- if (thisProto === classProto) {
627
- return true;
628
- }
629
- visited.push(thisProto);
630
- thisProto = _getObjProto(thisProto);
631
- }
632
- }
633
- return false;
634
- }
635
- function _getObjName(target, unknownValue) {
636
- if (_hasOwnProperty(target, Prototype)) {
637
- return target.name || unknownValue || UnknownValue;
638
- }
639
- return (((target || {})[Constructor]) || {}).name || unknownValue || UnknownValue;
640
- }
641
- function dynamicProto(theClass, target, delegateFunc, options) {
642
- if (!_hasOwnProperty(theClass, Prototype)) {
643
- _throwTypeError("theClass is an invalid class definition.");
644
- }
645
- var classProto = theClass[Prototype];
646
- if (!_checkPrototype(classProto, target)) {
647
- _throwTypeError("[" + _getObjName(theClass) + "] is not in class hierarchy of [" + _getObjName(target) + "]");
648
- }
649
- var className = null;
650
- if (_hasOwnProperty(classProto, DynClassName)) {
651
- className = classProto[DynClassName];
652
- }
653
- else {
654
- className = DynClassNamePrefix + _getObjName(theClass, "_") + "$" + _dynamicNames;
655
- _dynamicNames++;
656
- classProto[DynClassName] = className;
657
- }
658
- var perfOptions = dynamicProto[DynProtoDefaultOptions];
659
- var useBaseInst = !!perfOptions[strUseBaseInst];
660
- if (useBaseInst && options && options[strUseBaseInst] !== undefined) {
661
- useBaseInst = !!options[strUseBaseInst];
662
- }
663
- var instFuncs = _getInstanceFuncs(target);
664
- var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
665
- delegateFunc(target, baseFuncs);
666
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
667
- if (setInstanceFunc && options) {
668
- setInstanceFunc = !!options[strSetInstFuncs];
669
- }
670
- _populatePrototype(classProto, className, target, instFuncs, setInstanceFunc !== false);
671
- }
672
- var perfDefaults = {
673
- setInstFuncs: true,
674
- useBaseInst: true
675
- };
676
- dynamicProto[DynProtoDefaultOptions] = perfDefaults;
677
-
678
685
  var strWindow = "window";
679
686
  var strDocument = "document";
680
687
  var strNavigator = "navigator";
@@ -936,7 +943,7 @@
936
943
  if (isUserAct === void 0) { isUserAct = false; }
937
944
  var message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
938
945
  if (_self.enableDebugExceptions()) {
939
- throw message;
946
+ throw dumpObj(message);
940
947
  }
941
948
  else {
942
949
  var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
@@ -1210,7 +1217,7 @@
1210
1217
  }
1211
1218
 
1212
1219
  var _objDefineProperty = ObjDefineProperty;
1213
- var version = "2.8.0";
1220
+ var version = "2.8.4";
1214
1221
  var instanceName = "." + newId(6);
1215
1222
  var _dataUid = 0;
1216
1223
  function _createAccessor(target, prop, value) {
@@ -1281,822 +1288,822 @@
1281
1288
  return data;
1282
1289
  }
1283
1290
 
1284
- var pluginStateData = createElmNodeData("plugin");
1285
- function _getPluginState(plugin) {
1286
- return pluginStateData.get(plugin, "state", {}, true);
1287
- }
1288
-
1289
- var strTelemetryPluginChain = "TelemetryPluginChain";
1290
- var strHasRunFlags = "_hasRun";
1291
- var strGetTelCtx = "_getTelCtx";
1292
- var _chainId = 0;
1293
- function _getNextProxyStart(proxy, core, startAt) {
1294
- while (proxy) {
1295
- if (proxy.getPlugin() === startAt) {
1296
- return proxy;
1297
- }
1298
- proxy = proxy.getNext();
1291
+ var strOnPrefix = "on";
1292
+ var strAttachEvent = "attachEvent";
1293
+ var strAddEventHelper = "addEventListener";
1294
+ var strDetachEvent = "detachEvent";
1295
+ var strRemoveEventListener = "removeEventListener";
1296
+ var strEvents = "events";
1297
+ var strVisibilityChangeEvt = "visibilitychange";
1298
+ var strPageHide = "pagehide";
1299
+ var strPageShow = "pageshow";
1300
+ var strUnload = "unload";
1301
+ var strBeforeUnload = "beforeunload";
1302
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
1303
+ var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
1304
+ var rRemoveEmptyNs = /\.[\.]+/g;
1305
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1306
+ var _guid = 1;
1307
+ var elmNodeData = createElmNodeData("events");
1308
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1309
+ function _normalizeNamespace(name) {
1310
+ if (name && name.replace) {
1311
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1299
1312
  }
1300
- return createTelemetryProxyChain([startAt], core.config || {}, core);
1313
+ return name;
1301
1314
  }
1302
- function _createInternalContext(telemetryChain, config, core, startAt) {
1303
- var _nextProxy = null;
1304
- var _onComplete = [];
1305
- if (startAt !== null) {
1306
- _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1307
- }
1308
- var context = {
1309
- _next: _moveNext,
1310
- ctx: {
1311
- core: function () {
1312
- return core;
1313
- },
1314
- diagLog: function () {
1315
- return safeGetLogger(core, config);
1316
- },
1317
- getCfg: function () {
1318
- return config;
1319
- },
1320
- getExtCfg: _getExtCfg,
1321
- getConfig: _getConfig,
1322
- hasNext: function () {
1323
- return !!_nextProxy;
1324
- },
1325
- getNext: function () {
1326
- return _nextProxy;
1327
- },
1328
- setNext: function (nextPlugin) {
1329
- _nextProxy = nextPlugin;
1330
- },
1331
- iterate: _iterateChain,
1332
- onComplete: _addOnComplete
1333
- }
1334
- };
1335
- function _addOnComplete(onComplete, that) {
1336
- var args = [];
1337
- for (var _i = 2; _i < arguments.length; _i++) {
1338
- args[_i - 2] = arguments[_i];
1339
- }
1340
- if (onComplete) {
1341
- _onComplete.push({
1342
- func: onComplete,
1343
- self: !isUndefined(that) ? that : context.ctx,
1344
- args: args
1315
+ function _getEvtNamespace(eventName, evtNamespace) {
1316
+ if (evtNamespace) {
1317
+ var theNamespace_1 = "";
1318
+ if (isArray(evtNamespace)) {
1319
+ theNamespace_1 = "";
1320
+ arrForEach(evtNamespace, function (name) {
1321
+ name = _normalizeNamespace(name);
1322
+ if (name) {
1323
+ if (name[0] !== ".") {
1324
+ name = "." + name;
1325
+ }
1326
+ theNamespace_1 += name;
1327
+ }
1345
1328
  });
1346
1329
  }
1347
- }
1348
- function _moveNext() {
1349
- var nextProxy = _nextProxy;
1350
- _nextProxy = nextProxy ? nextProxy.getNext() : null;
1351
- if (!nextProxy) {
1352
- var onComplete = _onComplete;
1353
- if (onComplete && onComplete.length > 0) {
1354
- arrForEach(onComplete, function (completeDetails) {
1355
- try {
1356
- completeDetails.func.call(completeDetails.self, completeDetails.args);
1357
- }
1358
- catch (e) {
1359
- _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1360
- }
1361
- });
1362
- _onComplete = [];
1363
- }
1330
+ else {
1331
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1364
1332
  }
1365
- return nextProxy;
1366
- }
1367
- function _getExtCfg(identifier, defaultValue, mergeDefault) {
1368
- if (defaultValue === void 0) { defaultValue = {}; }
1369
- if (mergeDefault === void 0) { mergeDefault = 0 ; }
1370
- var theConfig;
1371
- if (config) {
1372
- var extConfig = config.extensionConfig;
1373
- if (extConfig && identifier) {
1374
- theConfig = extConfig[identifier];
1333
+ if (theNamespace_1) {
1334
+ if (theNamespace_1[0] !== ".") {
1335
+ theNamespace_1 = "." + theNamespace_1;
1375
1336
  }
1337
+ eventName = (eventName || "") + theNamespace_1;
1376
1338
  }
1377
- if (!theConfig) {
1378
- theConfig = defaultValue;
1339
+ }
1340
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1341
+ return {
1342
+ type: parsedEvent[1],
1343
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1344
+ };
1345
+ }
1346
+ function _getRegisteredEvents(target, evtName, addDefault) {
1347
+ if (addDefault === void 0) { addDefault = true; }
1348
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1349
+ var registeredEvents = aiEvts[evtName];
1350
+ if (!registeredEvents) {
1351
+ registeredEvents = aiEvts[evtName] = [];
1352
+ }
1353
+ return registeredEvents;
1354
+ }
1355
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
1356
+ if (obj && evtName && evtName.type) {
1357
+ if (obj[strRemoveEventListener]) {
1358
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1379
1359
  }
1380
- else if (isObject(defaultValue)) {
1381
- if (mergeDefault !== 0 ) {
1382
- var newConfig_1 = objExtend(true, defaultValue, theConfig);
1383
- if (config && mergeDefault === 2 ) {
1384
- objForEachKey(defaultValue, function (field) {
1385
- if (isNullOrUndefined(newConfig_1[field])) {
1386
- var cfgValue = config[field];
1387
- if (!isNullOrUndefined(cfgValue)) {
1388
- newConfig_1[field] = cfgValue;
1389
- }
1390
- }
1391
- });
1392
- }
1393
- theConfig = newConfig_1;
1394
- }
1360
+ else if (obj[strDetachEvent]) {
1361
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1395
1362
  }
1396
- return theConfig;
1397
1363
  }
1398
- function _getConfig(identifier, field, defaultValue) {
1399
- if (defaultValue === void 0) { defaultValue = false; }
1400
- var theValue;
1401
- var extConfig = _getExtCfg(identifier, null);
1402
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1403
- theValue = extConfig[field];
1364
+ }
1365
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1366
+ var result = false;
1367
+ if (obj && evtName && evtName.type && handlerRef) {
1368
+ if (obj[strAddEventHelper]) {
1369
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1370
+ result = true;
1404
1371
  }
1405
- else if (config && !isNullOrUndefined(config[field])) {
1406
- theValue = config[field];
1372
+ else if (obj[strAttachEvent]) {
1373
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1374
+ result = true;
1407
1375
  }
1408
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1409
1376
  }
1410
- function _iterateChain(cb) {
1411
- var nextPlugin;
1412
- while (!!(nextPlugin = context._next())) {
1413
- var plugin = nextPlugin.getPlugin();
1414
- if (plugin) {
1415
- cb(plugin);
1377
+ return result;
1378
+ }
1379
+ function _doUnregister(target, events, evtName, unRegFn) {
1380
+ var idx = events.length;
1381
+ while (idx--) {
1382
+ var theEvent = events[idx];
1383
+ if (theEvent) {
1384
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1385
+ if (!unRegFn || unRegFn(theEvent)) {
1386
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1387
+ events.splice(idx, 1);
1388
+ }
1416
1389
  }
1417
1390
  }
1418
1391
  }
1419
- return context;
1420
1392
  }
1421
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1422
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1423
- var context = internalContext.ctx;
1424
- function _processNext(env) {
1425
- var nextPlugin = internalContext._next();
1426
- nextPlugin && nextPlugin.processTelemetry(env, context);
1427
- return !nextPlugin;
1393
+ function _unregisterEvents(target, evtName, unRegFn) {
1394
+ if (evtName.type) {
1395
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1428
1396
  }
1429
- function _createNew(plugins, startAt) {
1430
- if (plugins === void 0) { plugins = null; }
1431
- if (isArray(plugins)) {
1432
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1397
+ else {
1398
+ var eventCache = elmNodeData.get(target, strEvents, {});
1399
+ objForEachKey(eventCache, function (evtType, events) {
1400
+ _doUnregister(target, events, evtName, unRegFn);
1401
+ });
1402
+ if (objKeys(eventCache).length === 0) {
1403
+ elmNodeData.kill(target, strEvents);
1433
1404
  }
1434
- return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1435
1405
  }
1436
- context.processNext = _processNext;
1437
- context.createNew = _createNew;
1438
- return context;
1439
1406
  }
1440
- function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1441
- var config = core.config || {};
1442
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1443
- var context = internalContext.ctx;
1444
- function _processNext(unloadState) {
1445
- var nextPlugin = internalContext._next();
1446
- nextPlugin && nextPlugin.unload(context, unloadState);
1447
- return !nextPlugin;
1448
- }
1449
- function _createNew(plugins, startAt) {
1450
- if (plugins === void 0) { plugins = null; }
1451
- if (isArray(plugins)) {
1452
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1407
+ function mergeEvtNamespace(theNamespace, namespaces) {
1408
+ var newNamespaces;
1409
+ if (namespaces) {
1410
+ if (isArray(namespaces)) {
1411
+ newNamespaces = [theNamespace].concat(namespaces);
1453
1412
  }
1454
- return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1413
+ else {
1414
+ newNamespaces = [theNamespace, namespaces];
1415
+ }
1416
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1455
1417
  }
1456
- context.processNext = _processNext;
1457
- context.createNew = _createNew;
1458
- return context;
1418
+ else {
1419
+ newNamespaces = theNamespace;
1420
+ }
1421
+ return newNamespaces;
1459
1422
  }
1460
- function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1461
- var config = core.config || {};
1462
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1463
- var context = internalContext.ctx;
1464
- function _processNext(updateState) {
1465
- return context.iterate(function (plugin) {
1466
- if (isFunction(plugin.update)) {
1467
- plugin.update(context, updateState);
1423
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1424
+ if (useCapture === void 0) { useCapture = false; }
1425
+ var result = false;
1426
+ if (target) {
1427
+ try {
1428
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1429
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1430
+ if (result && elmNodeData.accept(target)) {
1431
+ var registeredEvent = {
1432
+ guid: _guid++,
1433
+ evtName: evtName,
1434
+ handler: handlerRef,
1435
+ capture: useCapture
1436
+ };
1437
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1468
1438
  }
1469
- });
1470
- }
1471
- function _createNew(plugins, startAt) {
1472
- if (plugins === void 0) { plugins = null; }
1473
- if (isArray(plugins)) {
1474
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1475
1439
  }
1476
- return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1440
+ catch (e) {
1441
+ }
1477
1442
  }
1478
- context.processNext = _processNext;
1479
- context.createNew = _createNew;
1480
- return context;
1443
+ return result;
1481
1444
  }
1482
- function createTelemetryProxyChain(plugins, config, core, startAt) {
1483
- var firstProxy = null;
1484
- var add = startAt ? false : true;
1485
- if (isArray(plugins) && plugins.length > 0) {
1486
- var lastProxy_1 = null;
1487
- arrForEach(plugins, function (thePlugin) {
1488
- if (!add && startAt === thePlugin) {
1489
- add = true;
1490
- }
1491
- if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1492
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1493
- if (!firstProxy) {
1494
- firstProxy = newProxy;
1495
- }
1496
- if (lastProxy_1) {
1497
- lastProxy_1._setNext(newProxy);
1498
- }
1499
- lastProxy_1 = newProxy;
1445
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
1446
+ if (useCapture === void 0) { useCapture = false; }
1447
+ if (target) {
1448
+ try {
1449
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
1450
+ var found_1 = false;
1451
+ _unregisterEvents(target, evtName_1, function (regEvent) {
1452
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
1453
+ found_1 = true;
1454
+ return true;
1455
+ }
1456
+ return false;
1457
+ });
1458
+ if (!found_1) {
1459
+ _doDetach(target, evtName_1, handlerRef, useCapture);
1500
1460
  }
1501
- });
1502
- }
1503
- if (startAt && !firstProxy) {
1504
- return createTelemetryProxyChain([startAt], config, core);
1461
+ }
1462
+ catch (e) {
1463
+ }
1505
1464
  }
1506
- return firstProxy;
1507
1465
  }
1508
- function createTelemetryPluginProxy(plugin, config, core) {
1509
- var nextProxy = null;
1510
- var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1511
- var hasSetNext = isFunction(plugin.setNextPlugin);
1512
- var chainId;
1513
- if (plugin) {
1514
- chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1515
- }
1516
- else {
1517
- chainId = "Unknown-0-" + _chainId++;
1466
+ function addEventHandler(eventName, callback, evtNamespace) {
1467
+ var result = false;
1468
+ var w = getWindow();
1469
+ if (w) {
1470
+ result = eventOn(w, eventName, callback, evtNamespace);
1471
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1518
1472
  }
1519
- var proxyChain = {
1520
- getPlugin: function () {
1521
- return plugin;
1522
- },
1523
- getNext: function () {
1524
- return nextProxy;
1525
- },
1526
- processTelemetry: _processTelemetry,
1527
- unload: _unloadPlugin,
1528
- update: _updatePlugin,
1529
- _id: chainId,
1530
- _setNext: function (nextPlugin) {
1531
- nextProxy = nextPlugin;
1532
- }
1533
- };
1534
- function _getTelCtx() {
1535
- var itemCtx;
1536
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1537
- itemCtx = plugin[strGetTelCtx]();
1538
- }
1539
- if (!itemCtx) {
1540
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1541
- }
1542
- return itemCtx;
1473
+ var doc = getDocument();
1474
+ if (doc) {
1475
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
1543
1476
  }
1544
- function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1545
- var hasRun = false;
1546
- var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1547
- var hasRunContext = itemCtx[strHasRunFlags];
1548
- if (!hasRunContext) {
1549
- hasRunContext = itemCtx[strHasRunFlags] = {};
1550
- }
1551
- itemCtx.setNext(nextProxy);
1552
- if (plugin) {
1553
- doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1554
- hasRunContext[chainId] = true;
1555
- try {
1556
- var nextId = nextProxy ? nextProxy._id : strEmpty;
1557
- if (nextId) {
1558
- hasRunContext[nextId] = false;
1559
- }
1560
- hasRun = processPluginFn(itemCtx);
1561
- }
1562
- catch (error) {
1563
- var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1564
- if (hasNextRun) {
1565
- hasRun = true;
1566
- }
1567
- if (!nextProxy || !hasNextRun) {
1568
- _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1569
- }
1570
- }
1571
- }, details, isAsync);
1572
- }
1573
- return hasRun;
1477
+ return result;
1478
+ }
1479
+ function removeEventHandler(eventName, callback, evtNamespace) {
1480
+ var w = getWindow();
1481
+ if (w) {
1482
+ eventOff(w, eventName, callback, evtNamespace);
1483
+ eventOff(w["body"], eventName, callback, evtNamespace);
1574
1484
  }
1575
- function _processTelemetry(env, itemCtx) {
1576
- itemCtx = itemCtx || _getTelCtx();
1577
- function _callProcessTelemetry(itemCtx) {
1578
- if (!plugin || !hasProcessTelemetry) {
1579
- return false;
1580
- }
1581
- var pluginState = _getPluginState(plugin);
1582
- if (pluginState.teardown || pluginState[strDisabled]) {
1583
- return false;
1584
- }
1585
- if (hasSetNext) {
1586
- plugin.setNextPlugin(nextProxy);
1587
- }
1588
- plugin.processTelemetry(env, itemCtx);
1589
- return true;
1590
- }
1591
- if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1592
- itemCtx.processNext(env);
1593
- }
1485
+ var doc = getDocument();
1486
+ if (doc) {
1487
+ eventOff(doc, eventName, callback, evtNamespace);
1594
1488
  }
1595
- function _unloadPlugin(unloadCtx, unloadState) {
1596
- function _callTeardown() {
1597
- var hasRun = false;
1598
- if (plugin) {
1599
- var pluginState = _getPluginState(plugin);
1600
- var pluginCore = plugin[strCore] || pluginState.core;
1601
- if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1602
- pluginState[strCore] = null;
1603
- pluginState[strTeardown] = true;
1604
- pluginState[strIsInitialized] = false;
1605
- if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1606
- hasRun = true;
1607
- }
1489
+ }
1490
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
1491
+ var added = false;
1492
+ if (listener && events && events.length > 0) {
1493
+ arrForEach(events, function (name) {
1494
+ if (name) {
1495
+ if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
1496
+ added = addEventHandler(name, listener, evtNamespace) || added;
1608
1497
  }
1609
1498
  }
1610
- return hasRun;
1611
- }
1612
- if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1613
- unloadCtx.processNext(unloadState);
1499
+ });
1500
+ }
1501
+ return added;
1502
+ }
1503
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
1504
+ var added = false;
1505
+ if (listener && events && isArray(events)) {
1506
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
1507
+ if (!added && excludeEvents && excludeEvents.length > 0) {
1508
+ added = _addEventListeners(events, listener, null, evtNamespace);
1614
1509
  }
1615
1510
  }
1616
- function _updatePlugin(updateCtx, updateState) {
1617
- function _callUpdate() {
1618
- var hasRun = false;
1619
- if (plugin) {
1620
- var pluginState = _getPluginState(plugin);
1621
- var pluginCore = plugin[strCore] || pluginState.core;
1622
- if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1623
- if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1624
- hasRun = true;
1625
- }
1626
- }
1511
+ return added;
1512
+ }
1513
+ function removeEventListeners(events, listener, evtNamespace) {
1514
+ if (events && isArray(events)) {
1515
+ arrForEach(events, function (name) {
1516
+ if (name) {
1517
+ removeEventHandler(name, listener, evtNamespace);
1627
1518
  }
1628
- return hasRun;
1629
- }
1630
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1631
- updateCtx.processNext(updateState);
1519
+ });
1520
+ }
1521
+ }
1522
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
1523
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
1524
+ }
1525
+ function removePageUnloadEventListener(listener, evtNamespace) {
1526
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
1527
+ }
1528
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
1529
+ function _handlePageVisibility(evt) {
1530
+ var doc = getDocument();
1531
+ if (listener && doc && doc.visibilityState === "hidden") {
1532
+ listener(evt);
1632
1533
  }
1633
1534
  }
1634
- return objFreeze(proxyChain);
1535
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
1536
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
1537
+ if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1538
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
1539
+ }
1540
+ if (!pageUnloadAdded && excludeEvents) {
1541
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
1542
+ }
1543
+ return pageUnloadAdded;
1635
1544
  }
1636
-
1637
- var strExtensionConfig = "extensionConfig";
1638
-
1639
- function createUnloadHandlerContainer() {
1640
- var handlers = [];
1641
- function _addHandler(handler) {
1642
- if (handler) {
1643
- handlers.push(handler);
1545
+ function removePageHideEventListener(listener, evtNamespace) {
1546
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
1547
+ removeEventListeners([strPageHide], listener, newNamespaces);
1548
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
1549
+ }
1550
+ function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
1551
+ function _handlePageVisibility(evt) {
1552
+ var doc = getDocument();
1553
+ if (listener && doc && doc.visibilityState === "visible") {
1554
+ listener(evt);
1644
1555
  }
1645
1556
  }
1646
- function _runHandlers(unloadCtx, unloadState) {
1647
- arrForEach(handlers, function (handler) {
1648
- try {
1649
- handler(unloadCtx, unloadState);
1650
- }
1651
- catch (e) {
1652
- _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1653
- }
1654
- });
1655
- handlers = [];
1557
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
1558
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
1559
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
1560
+ if (!pageShowAdded && excludeEvents) {
1561
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
1656
1562
  }
1657
- return {
1658
- add: _addHandler,
1659
- run: _runHandlers
1660
- };
1563
+ return pageShowAdded;
1564
+ }
1565
+ function removePageShowEventListener(listener, evtNamespace) {
1566
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
1567
+ removeEventListeners([strPageShow], listener, newNamespaces);
1568
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
1661
1569
  }
1662
1570
 
1663
- var strGetPlugin = "getPlugin";
1664
- var BaseTelemetryPlugin = /** @class */ (function () {
1665
- function BaseTelemetryPlugin() {
1666
- var _self = this;
1667
- var _isinitialized;
1668
- var _rootCtx;
1669
- var _nextPlugin;
1670
- var _unloadHandlerContainer;
1671
- var _hooks;
1672
- _initDefaults();
1673
- dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1674
- _self.initialize = function (config, core, extensions, pluginChain) {
1675
- _setDefaults(config, core, pluginChain);
1676
- _isinitialized = true;
1677
- };
1678
- _self.teardown = function (unloadCtx, unloadState) {
1679
- var core = _self.core;
1680
- if (!core || (unloadCtx && core !== unloadCtx.core())) {
1681
- return;
1682
- }
1683
- var result;
1684
- var unloadDone = false;
1685
- var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1686
- var theUnloadState = unloadState || {
1687
- reason: 0 ,
1688
- isAsync: false
1689
- };
1690
- function _unloadCallback() {
1691
- if (!unloadDone) {
1692
- unloadDone = true;
1693
- _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1694
- arrForEach(_hooks, function (fn) {
1695
- fn.rm();
1696
- });
1697
- _hooks = [];
1698
- if (result === true) {
1699
- theUnloadCtx.processNext(theUnloadState);
1700
- }
1701
- _initDefaults();
1702
- }
1703
- }
1704
- if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1705
- _unloadCallback();
1706
- }
1707
- else {
1708
- result = true;
1709
- }
1710
- return result;
1711
- };
1712
- _self.update = function (updateCtx, updateState) {
1713
- var core = _self.core;
1714
- if (!core || (updateCtx && core !== updateCtx.core())) {
1715
- return;
1716
- }
1717
- var result;
1718
- var updateDone = false;
1719
- var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1720
- var theUpdateState = updateState || {
1721
- reason: 0
1722
- };
1723
- function _updateCallback() {
1724
- if (!updateDone) {
1725
- updateDone = true;
1726
- _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1727
- }
1728
- }
1729
- if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1730
- _updateCallback();
1731
- }
1732
- else {
1733
- result = true;
1734
- }
1735
- return result;
1736
- };
1737
- _self._addHook = function (hooks) {
1738
- if (hooks) {
1739
- if (isArray(hooks)) {
1740
- _hooks = _hooks.concat(hooks);
1571
+ function perfNow() {
1572
+ var perf = getPerformance();
1573
+ if (perf && perf.now) {
1574
+ return perf.now();
1575
+ }
1576
+ return dateNow();
1577
+ }
1578
+
1579
+ var pluginStateData = createElmNodeData("plugin");
1580
+ function _getPluginState(plugin) {
1581
+ return pluginStateData.get(plugin, "state", {}, true);
1582
+ }
1583
+
1584
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1585
+ var strHasRunFlags = "_hasRun";
1586
+ var strGetTelCtx = "_getTelCtx";
1587
+ var _chainId = 0;
1588
+ function _getNextProxyStart(proxy, core, startAt) {
1589
+ while (proxy) {
1590
+ if (proxy.getPlugin() === startAt) {
1591
+ return proxy;
1592
+ }
1593
+ proxy = proxy.getNext();
1594
+ }
1595
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
1596
+ }
1597
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1598
+ var _nextProxy = null;
1599
+ var _onComplete = [];
1600
+ if (startAt !== null) {
1601
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1602
+ }
1603
+ var context = {
1604
+ _next: _moveNext,
1605
+ ctx: {
1606
+ core: function () {
1607
+ return core;
1608
+ },
1609
+ diagLog: function () {
1610
+ return safeGetLogger(core, config);
1611
+ },
1612
+ getCfg: function () {
1613
+ return config;
1614
+ },
1615
+ getExtCfg: _getExtCfg,
1616
+ getConfig: _getConfig,
1617
+ hasNext: function () {
1618
+ return !!_nextProxy;
1619
+ },
1620
+ getNext: function () {
1621
+ return _nextProxy;
1622
+ },
1623
+ setNext: function (nextPlugin) {
1624
+ _nextProxy = nextPlugin;
1625
+ },
1626
+ iterate: _iterateChain,
1627
+ onComplete: _addOnComplete
1628
+ }
1629
+ };
1630
+ function _addOnComplete(onComplete, that) {
1631
+ var args = [];
1632
+ for (var _i = 2; _i < arguments.length; _i++) {
1633
+ args[_i - 2] = arguments[_i];
1634
+ }
1635
+ if (onComplete) {
1636
+ _onComplete.push({
1637
+ func: onComplete,
1638
+ self: !isUndefined(that) ? that : context.ctx,
1639
+ args: args
1640
+ });
1641
+ }
1642
+ }
1643
+ function _moveNext() {
1644
+ var nextProxy = _nextProxy;
1645
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1646
+ if (!nextProxy) {
1647
+ var onComplete = _onComplete;
1648
+ if (onComplete && onComplete.length > 0) {
1649
+ arrForEach(onComplete, function (completeDetails) {
1650
+ try {
1651
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1741
1652
  }
1742
- else {
1743
- _hooks.push(hooks);
1653
+ catch (e) {
1654
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1744
1655
  }
1745
- }
1746
- };
1747
- proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1748
- });
1749
- _self.diagLog = function (itemCtx) {
1750
- return _getTelCtx(itemCtx).diagLog();
1751
- };
1752
- _self[strIsInitialized] = function () {
1753
- return _isinitialized;
1754
- };
1755
- _self.setInitialized = function (isInitialized) {
1756
- _isinitialized = isInitialized;
1757
- };
1758
- _self[strSetNextPlugin] = function (next) {
1759
- _nextPlugin = next;
1760
- };
1761
- _self.processNext = function (env, itemCtx) {
1762
- if (itemCtx) {
1763
- itemCtx.processNext(env);
1764
- }
1765
- else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
1766
- _nextPlugin.processTelemetry(env, null);
1767
- }
1768
- };
1769
- _self._getTelCtx = _getTelCtx;
1770
- function _getTelCtx(currentCtx) {
1771
- if (currentCtx === void 0) { currentCtx = null; }
1772
- var itemCtx = currentCtx;
1773
- if (!itemCtx) {
1774
- var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1775
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1776
- itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1777
- }
1778
- else {
1779
- itemCtx = rootCtx.createNew(null, _nextPlugin);
1780
- }
1656
+ });
1657
+ _onComplete = [];
1781
1658
  }
1782
- return itemCtx;
1783
1659
  }
1784
- function _setDefaults(config, core, pluginChain) {
1785
- if (config) {
1786
- setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1787
- }
1788
- if (!pluginChain && core) {
1789
- pluginChain = core.getProcessTelContext().getNext();
1790
- }
1791
- var nextPlugin = _nextPlugin;
1792
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1793
- nextPlugin = _nextPlugin[strGetPlugin]();
1660
+ return nextProxy;
1661
+ }
1662
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1663
+ if (defaultValue === void 0) { defaultValue = {}; }
1664
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1665
+ var theConfig;
1666
+ if (config) {
1667
+ var extConfig = config.extensionConfig;
1668
+ if (extConfig && identifier) {
1669
+ theConfig = extConfig[identifier];
1794
1670
  }
1795
- _self.core = core;
1796
- _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1797
1671
  }
1798
- function _initDefaults() {
1799
- _isinitialized = false;
1800
- _self.core = null;
1801
- _rootCtx = null;
1802
- _nextPlugin = null;
1803
- _hooks = [];
1804
- _unloadHandlerContainer = createUnloadHandlerContainer();
1672
+ if (!theConfig) {
1673
+ theConfig = defaultValue;
1805
1674
  }
1806
- }
1807
- return BaseTelemetryPlugin;
1808
- }());
1809
-
1810
- var strOnPrefix = "on";
1811
- var strAttachEvent = "attachEvent";
1812
- var strAddEventHelper = "addEventListener";
1813
- var strDetachEvent = "detachEvent";
1814
- var strRemoveEventListener = "removeEventListener";
1815
- var strEvents = "events";
1816
- var strVisibilityChangeEvt = "visibilitychange";
1817
- var strPageHide = "pagehide";
1818
- var strPageShow = "pageshow";
1819
- var strUnload = "unload";
1820
- var strBeforeUnload = "beforeunload";
1821
- var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
1822
- var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
1823
- var rRemoveEmptyNs = /\.[\.]+/g;
1824
- var rRemoveTrailingEmptyNs = /[\.]+$/;
1825
- var _guid = 1;
1826
- var elmNodeData = createElmNodeData("events");
1827
- var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1828
- function _normalizeNamespace(name) {
1829
- if (name && name.replace) {
1830
- return name.replace(/^\s*\.*|\.*\s*$/g, "");
1831
- }
1832
- return name;
1833
- }
1834
- function _getEvtNamespace(eventName, evtNamespace) {
1835
- if (evtNamespace) {
1836
- var theNamespace_1 = "";
1837
- if (isArray(evtNamespace)) {
1838
- theNamespace_1 = "";
1839
- arrForEach(evtNamespace, function (name) {
1840
- name = _normalizeNamespace(name);
1841
- if (name) {
1842
- if (name[0] !== ".") {
1843
- name = "." + name;
1844
- }
1845
- theNamespace_1 += name;
1675
+ else if (isObject(defaultValue)) {
1676
+ if (mergeDefault !== 0 ) {
1677
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1678
+ if (config && mergeDefault === 2 ) {
1679
+ objForEachKey(defaultValue, function (field) {
1680
+ if (isNullOrUndefined(newConfig_1[field])) {
1681
+ var cfgValue = config[field];
1682
+ if (!isNullOrUndefined(cfgValue)) {
1683
+ newConfig_1[field] = cfgValue;
1684
+ }
1685
+ }
1686
+ });
1846
1687
  }
1847
- });
1688
+ theConfig = newConfig_1;
1689
+ }
1848
1690
  }
1849
- else {
1850
- theNamespace_1 = _normalizeNamespace(evtNamespace);
1691
+ return theConfig;
1692
+ }
1693
+ function _getConfig(identifier, field, defaultValue) {
1694
+ if (defaultValue === void 0) { defaultValue = false; }
1695
+ var theValue;
1696
+ var extConfig = _getExtCfg(identifier, null);
1697
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1698
+ theValue = extConfig[field];
1851
1699
  }
1852
- if (theNamespace_1) {
1853
- if (theNamespace_1[0] !== ".") {
1854
- theNamespace_1 = "." + theNamespace_1;
1700
+ else if (config && !isNullOrUndefined(config[field])) {
1701
+ theValue = config[field];
1702
+ }
1703
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1704
+ }
1705
+ function _iterateChain(cb) {
1706
+ var nextPlugin;
1707
+ while (!!(nextPlugin = context._next())) {
1708
+ var plugin = nextPlugin.getPlugin();
1709
+ if (plugin) {
1710
+ cb(plugin);
1855
1711
  }
1856
- eventName = (eventName || "") + theNamespace_1;
1857
1712
  }
1858
1713
  }
1859
- var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1860
- return {
1861
- type: parsedEvent[1],
1862
- ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1863
- };
1714
+ return context;
1864
1715
  }
1865
- function _getRegisteredEvents(target, evtName, addDefault) {
1866
- if (addDefault === void 0) { addDefault = true; }
1867
- var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1868
- var registeredEvents = aiEvts[evtName];
1869
- if (!registeredEvents) {
1870
- registeredEvents = aiEvts[evtName] = [];
1716
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1717
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1718
+ var context = internalContext.ctx;
1719
+ function _processNext(env) {
1720
+ var nextPlugin = internalContext._next();
1721
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1722
+ return !nextPlugin;
1871
1723
  }
1872
- return registeredEvents;
1873
- }
1874
- function _doDetach(obj, evtName, handlerRef, useCapture) {
1875
- if (obj && evtName && evtName.type) {
1876
- if (obj[strRemoveEventListener]) {
1877
- obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1878
- }
1879
- else if (obj[strDetachEvent]) {
1880
- obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1724
+ function _createNew(plugins, startAt) {
1725
+ if (plugins === void 0) { plugins = null; }
1726
+ if (isArray(plugins)) {
1727
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1881
1728
  }
1729
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1882
1730
  }
1731
+ context.processNext = _processNext;
1732
+ context.createNew = _createNew;
1733
+ return context;
1883
1734
  }
1884
- function _doAttach(obj, evtName, handlerRef, useCapture) {
1885
- var result = false;
1886
- if (obj && evtName && evtName.type && handlerRef) {
1887
- if (obj[strAddEventHelper]) {
1888
- obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1889
- result = true;
1735
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1736
+ var config = core.config || {};
1737
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1738
+ var context = internalContext.ctx;
1739
+ function _processNext(unloadState) {
1740
+ var nextPlugin = internalContext._next();
1741
+ nextPlugin && nextPlugin.unload(context, unloadState);
1742
+ return !nextPlugin;
1743
+ }
1744
+ function _createNew(plugins, startAt) {
1745
+ if (plugins === void 0) { plugins = null; }
1746
+ if (isArray(plugins)) {
1747
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1890
1748
  }
1891
- else if (obj[strAttachEvent]) {
1892
- obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1893
- result = true;
1749
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1750
+ }
1751
+ context.processNext = _processNext;
1752
+ context.createNew = _createNew;
1753
+ return context;
1754
+ }
1755
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1756
+ var config = core.config || {};
1757
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1758
+ var context = internalContext.ctx;
1759
+ function _processNext(updateState) {
1760
+ return context.iterate(function (plugin) {
1761
+ if (isFunction(plugin.update)) {
1762
+ plugin.update(context, updateState);
1763
+ }
1764
+ });
1765
+ }
1766
+ function _createNew(plugins, startAt) {
1767
+ if (plugins === void 0) { plugins = null; }
1768
+ if (isArray(plugins)) {
1769
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1894
1770
  }
1771
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1895
1772
  }
1896
- return result;
1773
+ context.processNext = _processNext;
1774
+ context.createNew = _createNew;
1775
+ return context;
1897
1776
  }
1898
- function _doUnregister(target, events, evtName, unRegFn) {
1899
- var idx = events.length;
1900
- while (idx--) {
1901
- var theEvent = events[idx];
1902
- if (theEvent) {
1903
- if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1904
- if (!unRegFn || unRegFn(theEvent)) {
1905
- _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1906
- events.splice(idx, 1);
1777
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1778
+ var firstProxy = null;
1779
+ var add = startAt ? false : true;
1780
+ if (isArray(plugins) && plugins.length > 0) {
1781
+ var lastProxy_1 = null;
1782
+ arrForEach(plugins, function (thePlugin) {
1783
+ if (!add && startAt === thePlugin) {
1784
+ add = true;
1785
+ }
1786
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1787
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1788
+ if (!firstProxy) {
1789
+ firstProxy = newProxy;
1790
+ }
1791
+ if (lastProxy_1) {
1792
+ lastProxy_1._setNext(newProxy);
1907
1793
  }
1794
+ lastProxy_1 = newProxy;
1908
1795
  }
1909
- }
1796
+ });
1910
1797
  }
1798
+ if (startAt && !firstProxy) {
1799
+ return createTelemetryProxyChain([startAt], config, core);
1800
+ }
1801
+ return firstProxy;
1911
1802
  }
1912
- function _unregisterEvents(target, evtName, unRegFn) {
1913
- if (evtName.type) {
1914
- _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1803
+ function createTelemetryPluginProxy(plugin, config, core) {
1804
+ var nextProxy = null;
1805
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1806
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1807
+ var chainId;
1808
+ if (plugin) {
1809
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1915
1810
  }
1916
1811
  else {
1917
- var eventCache = elmNodeData.get(target, strEvents, {});
1918
- objForEachKey(eventCache, function (evtType, events) {
1919
- _doUnregister(target, events, evtName, unRegFn);
1920
- });
1921
- if (objKeys(eventCache).length === 0) {
1922
- elmNodeData.kill(target, strEvents);
1923
- }
1812
+ chainId = "Unknown-0-" + _chainId++;
1924
1813
  }
1925
- }
1926
- function mergeEvtNamespace(theNamespace, namespaces) {
1927
- var newNamespaces;
1928
- if (namespaces) {
1929
- if (isArray(namespaces)) {
1930
- newNamespaces = [theNamespace].concat(namespaces);
1814
+ var proxyChain = {
1815
+ getPlugin: function () {
1816
+ return plugin;
1817
+ },
1818
+ getNext: function () {
1819
+ return nextProxy;
1820
+ },
1821
+ processTelemetry: _processTelemetry,
1822
+ unload: _unloadPlugin,
1823
+ update: _updatePlugin,
1824
+ _id: chainId,
1825
+ _setNext: function (nextPlugin) {
1826
+ nextProxy = nextPlugin;
1931
1827
  }
1932
- else {
1933
- newNamespaces = [theNamespace, namespaces];
1828
+ };
1829
+ function _getTelCtx() {
1830
+ var itemCtx;
1831
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1832
+ itemCtx = plugin[strGetTelCtx]();
1934
1833
  }
1935
- newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1834
+ if (!itemCtx) {
1835
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1836
+ }
1837
+ return itemCtx;
1936
1838
  }
1937
- else {
1938
- newNamespaces = theNamespace;
1839
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1840
+ var hasRun = false;
1841
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1842
+ var hasRunContext = itemCtx[strHasRunFlags];
1843
+ if (!hasRunContext) {
1844
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1845
+ }
1846
+ itemCtx.setNext(nextProxy);
1847
+ if (plugin) {
1848
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1849
+ hasRunContext[chainId] = true;
1850
+ try {
1851
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1852
+ if (nextId) {
1853
+ hasRunContext[nextId] = false;
1854
+ }
1855
+ hasRun = processPluginFn(itemCtx);
1856
+ }
1857
+ catch (error) {
1858
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1859
+ if (hasNextRun) {
1860
+ hasRun = true;
1861
+ }
1862
+ if (!nextProxy || !hasNextRun) {
1863
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1864
+ }
1865
+ }
1866
+ }, details, isAsync);
1867
+ }
1868
+ return hasRun;
1939
1869
  }
1940
- return newNamespaces;
1941
- }
1942
- function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1943
- if (useCapture === void 0) { useCapture = false; }
1944
- var result = false;
1945
- if (target) {
1946
- try {
1947
- var evtName = _getEvtNamespace(eventName, evtNamespace);
1948
- result = _doAttach(target, evtName, handlerRef, useCapture);
1949
- if (result && elmNodeData.accept(target)) {
1950
- var registeredEvent = {
1951
- guid: _guid++,
1952
- evtName: evtName,
1953
- handler: handlerRef,
1954
- capture: useCapture
1955
- };
1956
- _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1870
+ function _processTelemetry(env, itemCtx) {
1871
+ itemCtx = itemCtx || _getTelCtx();
1872
+ function _callProcessTelemetry(itemCtx) {
1873
+ if (!plugin || !hasProcessTelemetry) {
1874
+ return false;
1875
+ }
1876
+ var pluginState = _getPluginState(plugin);
1877
+ if (pluginState.teardown || pluginState[strDisabled]) {
1878
+ return false;
1879
+ }
1880
+ if (hasSetNext) {
1881
+ plugin.setNextPlugin(nextProxy);
1957
1882
  }
1883
+ plugin.processTelemetry(env, itemCtx);
1884
+ return true;
1958
1885
  }
1959
- catch (e) {
1886
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1887
+ itemCtx.processNext(env);
1960
1888
  }
1961
1889
  }
1962
- return result;
1963
- }
1964
- function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
1965
- if (useCapture === void 0) { useCapture = false; }
1966
- if (target) {
1967
- try {
1968
- var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
1969
- var found_1 = false;
1970
- _unregisterEvents(target, evtName_1, function (regEvent) {
1971
- if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
1972
- found_1 = true;
1973
- return true;
1890
+ function _unloadPlugin(unloadCtx, unloadState) {
1891
+ function _callTeardown() {
1892
+ var hasRun = false;
1893
+ if (plugin) {
1894
+ var pluginState = _getPluginState(plugin);
1895
+ var pluginCore = plugin[strCore] || pluginState.core;
1896
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1897
+ pluginState[strCore] = null;
1898
+ pluginState[strTeardown] = true;
1899
+ pluginState[strIsInitialized] = false;
1900
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1901
+ hasRun = true;
1902
+ }
1974
1903
  }
1975
- return false;
1976
- });
1977
- if (!found_1) {
1978
- _doDetach(target, evtName_1, handlerRef, useCapture);
1979
1904
  }
1905
+ return hasRun;
1980
1906
  }
1981
- catch (e) {
1907
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1908
+ unloadCtx.processNext(unloadState);
1982
1909
  }
1983
1910
  }
1984
- }
1985
- function addEventHandler(eventName, callback, evtNamespace) {
1986
- var result = false;
1987
- var w = getWindow();
1988
- if (w) {
1989
- result = eventOn(w, eventName, callback, evtNamespace);
1990
- result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1991
- }
1992
- var doc = getDocument();
1993
- if (doc) {
1994
- result = eventOn(doc, eventName, callback, evtNamespace) || result;
1995
- }
1996
- return result;
1997
- }
1998
- function removeEventHandler(eventName, callback, evtNamespace) {
1999
- var w = getWindow();
2000
- if (w) {
2001
- eventOff(w, eventName, callback, evtNamespace);
2002
- eventOff(w["body"], eventName, callback, evtNamespace);
2003
- }
2004
- var doc = getDocument();
2005
- if (doc) {
2006
- eventOff(doc, eventName, callback, evtNamespace);
2007
- }
2008
- }
2009
- function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
2010
- var added = false;
2011
- if (listener && events && events.length > 0) {
2012
- arrForEach(events, function (name) {
2013
- if (name) {
2014
- if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
2015
- added = addEventHandler(name, listener, evtNamespace) || added;
1911
+ function _updatePlugin(updateCtx, updateState) {
1912
+ function _callUpdate() {
1913
+ var hasRun = false;
1914
+ if (plugin) {
1915
+ var pluginState = _getPluginState(plugin);
1916
+ var pluginCore = plugin[strCore] || pluginState.core;
1917
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1918
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1919
+ hasRun = true;
1920
+ }
2016
1921
  }
2017
1922
  }
2018
- });
1923
+ return hasRun;
1924
+ }
1925
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1926
+ updateCtx.processNext(updateState);
1927
+ }
2019
1928
  }
2020
- return added;
1929
+ return objFreeze(proxyChain);
2021
1930
  }
2022
- function addEventListeners(events, listener, excludeEvents, evtNamespace) {
2023
- var added = false;
2024
- if (listener && events && isArray(events)) {
2025
- added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
2026
- if (!added && excludeEvents && excludeEvents.length > 0) {
2027
- added = _addEventListeners(events, listener, null, evtNamespace);
1931
+
1932
+ var strExtensionConfig = "extensionConfig";
1933
+
1934
+ function createUnloadHandlerContainer() {
1935
+ var handlers = [];
1936
+ function _addHandler(handler) {
1937
+ if (handler) {
1938
+ handlers.push(handler);
2028
1939
  }
2029
1940
  }
2030
- return added;
2031
- }
2032
- function removeEventListeners(events, listener, evtNamespace) {
2033
- if (events && isArray(events)) {
2034
- arrForEach(events, function (name) {
2035
- if (name) {
2036
- removeEventHandler(name, listener, evtNamespace);
1941
+ function _runHandlers(unloadCtx, unloadState) {
1942
+ arrForEach(handlers, function (handler) {
1943
+ try {
1944
+ handler(unloadCtx, unloadState);
1945
+ }
1946
+ catch (e) {
1947
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2037
1948
  }
2038
1949
  });
1950
+ handlers = [];
2039
1951
  }
1952
+ return {
1953
+ add: _addHandler,
1954
+ run: _runHandlers
1955
+ };
2040
1956
  }
2041
- function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
2042
- return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
2043
- }
2044
- function removePageUnloadEventListener(listener, evtNamespace) {
2045
- removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
2046
- }
2047
- function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
2048
- function _handlePageVisibility(evt) {
2049
- var doc = getDocument();
2050
- if (listener && doc && doc.visibilityState === "hidden") {
2051
- listener(evt);
1957
+
1958
+ var strGetPlugin = "getPlugin";
1959
+ var BaseTelemetryPlugin = /** @class */ (function () {
1960
+ function BaseTelemetryPlugin() {
1961
+ var _self = this;
1962
+ var _isinitialized;
1963
+ var _rootCtx;
1964
+ var _nextPlugin;
1965
+ var _unloadHandlerContainer;
1966
+ var _hooks;
1967
+ _initDefaults();
1968
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1969
+ _self.initialize = function (config, core, extensions, pluginChain) {
1970
+ _setDefaults(config, core, pluginChain);
1971
+ _isinitialized = true;
1972
+ };
1973
+ _self.teardown = function (unloadCtx, unloadState) {
1974
+ var core = _self.core;
1975
+ if (!core || (unloadCtx && core !== unloadCtx.core())) {
1976
+ return;
1977
+ }
1978
+ var result;
1979
+ var unloadDone = false;
1980
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1981
+ var theUnloadState = unloadState || {
1982
+ reason: 0 ,
1983
+ isAsync: false
1984
+ };
1985
+ function _unloadCallback() {
1986
+ if (!unloadDone) {
1987
+ unloadDone = true;
1988
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1989
+ arrForEach(_hooks, function (fn) {
1990
+ fn.rm();
1991
+ });
1992
+ _hooks = [];
1993
+ if (result === true) {
1994
+ theUnloadCtx.processNext(theUnloadState);
1995
+ }
1996
+ _initDefaults();
1997
+ }
1998
+ }
1999
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
2000
+ _unloadCallback();
2001
+ }
2002
+ else {
2003
+ result = true;
2004
+ }
2005
+ return result;
2006
+ };
2007
+ _self.update = function (updateCtx, updateState) {
2008
+ var core = _self.core;
2009
+ if (!core || (updateCtx && core !== updateCtx.core())) {
2010
+ return;
2011
+ }
2012
+ var result;
2013
+ var updateDone = false;
2014
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2015
+ var theUpdateState = updateState || {
2016
+ reason: 0
2017
+ };
2018
+ function _updateCallback() {
2019
+ if (!updateDone) {
2020
+ updateDone = true;
2021
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
2022
+ }
2023
+ }
2024
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
2025
+ _updateCallback();
2026
+ }
2027
+ else {
2028
+ result = true;
2029
+ }
2030
+ return result;
2031
+ };
2032
+ _self._addHook = function (hooks) {
2033
+ if (hooks) {
2034
+ if (isArray(hooks)) {
2035
+ _hooks = _hooks.concat(hooks);
2036
+ }
2037
+ else {
2038
+ _hooks.push(hooks);
2039
+ }
2040
+ }
2041
+ };
2042
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
2043
+ });
2044
+ _self.diagLog = function (itemCtx) {
2045
+ return _getTelCtx(itemCtx).diagLog();
2046
+ };
2047
+ _self[strIsInitialized] = function () {
2048
+ return _isinitialized;
2049
+ };
2050
+ _self.setInitialized = function (isInitialized) {
2051
+ _isinitialized = isInitialized;
2052
+ };
2053
+ _self[strSetNextPlugin] = function (next) {
2054
+ _nextPlugin = next;
2055
+ };
2056
+ _self.processNext = function (env, itemCtx) {
2057
+ if (itemCtx) {
2058
+ itemCtx.processNext(env);
2059
+ }
2060
+ else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
2061
+ _nextPlugin.processTelemetry(env, null);
2062
+ }
2063
+ };
2064
+ _self._getTelCtx = _getTelCtx;
2065
+ function _getTelCtx(currentCtx) {
2066
+ if (currentCtx === void 0) { currentCtx = null; }
2067
+ var itemCtx = currentCtx;
2068
+ if (!itemCtx) {
2069
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
2070
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2071
+ itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
2072
+ }
2073
+ else {
2074
+ itemCtx = rootCtx.createNew(null, _nextPlugin);
2075
+ }
2076
+ }
2077
+ return itemCtx;
2052
2078
  }
2053
- }
2054
- var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2055
- var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
2056
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
2057
- pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
2058
- }
2059
- if (!pageUnloadAdded && excludeEvents) {
2060
- pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
2061
- }
2062
- return pageUnloadAdded;
2063
- }
2064
- function removePageHideEventListener(listener, evtNamespace) {
2065
- var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2066
- removeEventListeners([strPageHide], listener, newNamespaces);
2067
- removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2068
- }
2069
- function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
2070
- function _handlePageVisibility(evt) {
2071
- var doc = getDocument();
2072
- if (listener && doc && doc.visibilityState === "visible") {
2073
- listener(evt);
2079
+ function _setDefaults(config, core, pluginChain) {
2080
+ if (config) {
2081
+ setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
2082
+ }
2083
+ if (!pluginChain && core) {
2084
+ pluginChain = core.getProcessTelContext().getNext();
2085
+ }
2086
+ var nextPlugin = _nextPlugin;
2087
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2088
+ nextPlugin = _nextPlugin[strGetPlugin]();
2089
+ }
2090
+ _self.core = core;
2091
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
2092
+ }
2093
+ function _initDefaults() {
2094
+ _isinitialized = false;
2095
+ _self.core = null;
2096
+ _rootCtx = null;
2097
+ _nextPlugin = null;
2098
+ _hooks = [];
2099
+ _unloadHandlerContainer = createUnloadHandlerContainer();
2074
2100
  }
2075
2101
  }
2076
- var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2077
- var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
2078
- pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
2079
- if (!pageShowAdded && excludeEvents) {
2080
- pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
2081
- }
2082
- return pageShowAdded;
2083
- }
2084
- function removePageShowEventListener(listener, evtNamespace) {
2085
- var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2086
- removeEventListeners([strPageShow], listener, newNamespaces);
2087
- removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2088
- }
2089
-
2090
- function perfNow() {
2091
- var perf = getPerformance();
2092
- if (perf && perf.now) {
2093
- return perf.now();
2094
- }
2095
- return dateNow();
2096
- }
2102
+ return BaseTelemetryPlugin;
2103
+ }());
2097
2104
 
2098
2105
  var _a$1;
2099
- var Version = '3.2.0';
2106
+ var Version = '3.2.3';
2100
2107
  var FullVersionString = "1DS-Web-JS-" + Version;
2101
2108
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2102
2109
  var strWithCredentials = "withCredentials";
@@ -2111,7 +2118,7 @@
2111
2118
  _a$1[4096 | 3 ] = 7 ,
2112
2119
  _a$1);
2113
2120
  Boolean(getDocument());
2114
- var isWindowObjectAvailable = Boolean(getWindow());
2121
+ Boolean(getWindow());
2115
2122
  function isValueAssigned(value) {
2116
2123
  return !(value === "" || isNullOrUndefined(value));
2117
2124
  }
@@ -2805,7 +2812,7 @@
2805
2812
  }
2806
2813
  }
2807
2814
  var HttpManager = /** @class */ (function () {
2808
- function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
2815
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions, timeoutOverride) {
2809
2816
  this._responseHandlers = [];
2810
2817
  var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
2811
2818
  var _killSwitch = new EVTKillSwitch();
@@ -2944,7 +2951,7 @@
2944
2951
  xdr.send(payload.data);
2945
2952
  }
2946
2953
  else {
2947
- _postManager._setTimeoutOverride(function () {
2954
+ timeoutOverride.set(function () {
2948
2955
  xdr.send(payload.data);
2949
2956
  }, 0);
2950
2957
  }
@@ -3002,7 +3009,7 @@
3002
3009
  _doOnComplete(oncomplete, 200, {});
3003
3010
  }
3004
3011
  if (!responseHandled && payload.timeout > 0) {
3005
- _postManager._setTimeoutOverride(function () {
3012
+ timeoutOverride.set(function () {
3006
3013
  if (!responseHandled) {
3007
3014
  responseHandled = true;
3008
3015
  _doOnComplete(oncomplete, 500, {});
@@ -3541,7 +3548,7 @@
3541
3548
  cb();
3542
3549
  }
3543
3550
  else {
3544
- _postManager._setTimeoutOverride(cb, interval);
3551
+ timeoutOverride.set(cb, interval);
3545
3552
  }
3546
3553
  }
3547
3554
  function _convertAllHeadersToMap(headersString) {
@@ -3633,13 +3640,29 @@
3633
3640
  return HttpManager;
3634
3641
  }());
3635
3642
 
3643
+ function defaultSetTimeout(callback, ms) {
3644
+ var args = [];
3645
+ for (var _i = 2; _i < arguments.length; _i++) {
3646
+ args[_i - 2] = arguments[_i];
3647
+ }
3648
+ return setTimeout(callback, ms, args);
3649
+ }
3650
+ function defaultClearTimeout(timeoutId) {
3651
+ clearTimeout(timeoutId);
3652
+ }
3653
+ function createTimeoutWrapper(argSetTimeout, argClearTimeout) {
3654
+ return {
3655
+ set: argSetTimeout || defaultSetTimeout,
3656
+ clear: argClearTimeout || defaultClearTimeout
3657
+ };
3658
+ }
3659
+
3636
3660
  var FlushCheckTimer = 0.250;
3637
3661
  var MaxNumberEventPerBatch = 500;
3638
3662
  var EventsDroppedAtOneTime = 20;
3639
3663
  var MaxSendAttempts = 6;
3640
3664
  var MaxSyncUnloadSendAttempts = 2;
3641
3665
  var MaxBackoffCount = 4;
3642
- var globalContext = isWindowObjectAvailable ? window : undefined;
3643
3666
  var MaxConnections = 2;
3644
3667
  var MaxRequestRetriesBeforeBackoff = 1;
3645
3668
  var strEventsDiscarded = "eventsDiscarded";
@@ -3653,7 +3676,7 @@
3653
3676
  var _this = _super.call(this) || this;
3654
3677
  _this.identifier = "PostChannel";
3655
3678
  _this.priority = 1011;
3656
- _this.version = '3.2.0';
3679
+ _this.version = '3.2.3';
3657
3680
  var _config;
3658
3681
  var _isTeardownCalled = false;
3659
3682
  var _flushCallbackQueue = [];
@@ -3678,10 +3701,10 @@
3678
3701
  var _delayedBatchReason;
3679
3702
  var _optimizeObject = true;
3680
3703
  var _isPageUnloadTriggered = false;
3681
- var _disableXhrSync = false;
3682
3704
  var _maxEventSendAttempts = MaxSendAttempts;
3683
3705
  var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
3684
3706
  var _evtNamespace;
3707
+ var _timeoutWrapper;
3685
3708
  dynamicProto(PostChannel, _this, function (_self, _base) {
3686
3709
  _initDefaults();
3687
3710
  _self["_getDbgPlgTargets"] = function () {
@@ -3697,8 +3720,7 @@
3697
3720
  var ctx = _self._getTelCtx();
3698
3721
  coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
3699
3722
  _config = ctx.getExtCfg(_self.identifier);
3700
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
3701
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
3723
+ _timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
3702
3724
  _optimizeObject = !_config.disableOptimizeObj && isChromium();
3703
3725
  _hookWParam(extendedCore);
3704
3726
  if (_config.eventsLimitInMem > 0) {
@@ -3710,7 +3732,6 @@
3710
3732
  if (_config.autoFlushEventsLimit > 0) {
3711
3733
  _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3712
3734
  }
3713
- _disableXhrSync = _config.disableXhrSync;
3714
3735
  if (isNumber(_config[strMaxEventRetryAttempts])) {
3715
3736
  _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
3716
3737
  }
@@ -3918,13 +3939,13 @@
3918
3939
  _self.flush = function (async, callback, sendReason) {
3919
3940
  if (async === void 0) { async = true; }
3920
3941
  if (!_paused) {
3921
- _clearScheduledTimer();
3922
3942
  sendReason = sendReason || 1 ;
3923
3943
  if (async) {
3924
- _queueBatches(1 , 0 , sendReason);
3925
- _resetQueueCounts();
3926
3944
  if (_flushCallbackTimerId == null) {
3945
+ _clearScheduledTimer();
3946
+ _queueBatches(1 , 0 , sendReason);
3927
3947
  _flushCallbackTimerId = _createTimer(function () {
3948
+ _flushCallbackTimerId = null;
3928
3949
  _flushImpl(callback, sendReason);
3929
3950
  }, 0);
3930
3951
  }
@@ -3933,10 +3954,14 @@
3933
3954
  }
3934
3955
  }
3935
3956
  else {
3957
+ var cleared = _clearScheduledTimer();
3936
3958
  _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
3937
3959
  if (callback !== null && callback !== undefined) {
3938
3960
  callback();
3939
3961
  }
3962
+ if (cleared) {
3963
+ _scheduleTimer();
3964
+ }
3940
3965
  }
3941
3966
  }
3942
3967
  };
@@ -4027,10 +4052,10 @@
4027
4052
  _delayedBatchReason = null;
4028
4053
  _optimizeObject = true;
4029
4054
  _isPageUnloadTriggered = false;
4030
- _disableXhrSync = false;
4031
4055
  _maxEventSendAttempts = MaxSendAttempts;
4032
4056
  _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
4033
4057
  _evtNamespace = null;
4058
+ _timeoutWrapper = createTimeoutWrapper();
4034
4059
  _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
4035
4060
  requeue: _requeueEvents,
4036
4061
  send: _sendingEvent,
@@ -4038,7 +4063,7 @@
4038
4063
  drop: _eventsDropped,
4039
4064
  rspFail: _eventsResponseFail,
4040
4065
  oth: _otherEvent
4041
- });
4066
+ }, _timeoutWrapper);
4042
4067
  _initializeProfiles();
4043
4068
  _clearQueues();
4044
4069
  _setAutoLimits();
@@ -4051,19 +4076,21 @@
4051
4076
  if (_currentBackoffCount) {
4052
4077
  timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
4053
4078
  }
4054
- return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
4079
+ return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
4055
4080
  }
4056
4081
  function _clearScheduledTimer() {
4057
4082
  if (_scheduledTimerId !== null) {
4058
- _self._clearTimeoutOverride(_scheduledTimerId);
4083
+ _timeoutWrapper.clear(_scheduledTimerId);
4059
4084
  _scheduledTimerId = null;
4060
4085
  _timerCount = 0;
4086
+ return true;
4061
4087
  }
4088
+ return false;
4062
4089
  }
4063
4090
  function _releaseAllQueues(sendType, sendReason) {
4064
4091
  _clearScheduledTimer();
4065
4092
  if (_flushCallbackTimerId) {
4066
- _self._clearTimeoutOverride(_flushCallbackTimerId);
4093
+ _timeoutWrapper.clear(_flushCallbackTimerId);
4067
4094
  _flushCallbackTimerId = null;
4068
4095
  }
4069
4096
  if (!_paused) {
@@ -4222,18 +4249,20 @@
4222
4249
  }
4223
4250
  function _flushImpl(callback, sendReason) {
4224
4251
  _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
4252
+ _resetQueueCounts();
4225
4253
  _waitForIdleManager(function () {
4226
4254
  if (callback) {
4227
4255
  callback();
4228
4256
  }
4229
4257
  if (_flushCallbackQueue.length > 0) {
4230
- _flushCallbackTimerId = _createTimer(function () { return _flushImpl(_flushCallbackQueue.shift(), sendReason); }, 0);
4258
+ _flushCallbackTimerId = _createTimer(function () {
4259
+ _flushCallbackTimerId = null;
4260
+ _flushImpl(_flushCallbackQueue.shift(), sendReason);
4261
+ }, 0);
4231
4262
  }
4232
4263
  else {
4233
4264
  _flushCallbackTimerId = null;
4234
- if (_hasEvents()) {
4235
- _scheduleTimer();
4236
- }
4265
+ _scheduleTimer();
4237
4266
  }
4238
4267
  });
4239
4268
  }
@@ -4243,6 +4272,7 @@
4243
4272
  }
4244
4273
  else {
4245
4274
  _flushCallbackTimerId = _createTimer(function () {
4275
+ _flushCallbackTimerId = null;
4246
4276
  _waitForIdleManager(callback);
4247
4277
  }, FlushCheckTimer);
4248
4278
  }
@@ -4357,6 +4387,12 @@
4357
4387
  _autoFlushBatchLimit = 0;
4358
4388
  }
4359
4389
  }
4390
+ objDefineAccessors(_self, "_setTimeoutOverride", function () { return _timeoutWrapper.set; }, function (value) {
4391
+ _timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
4392
+ });
4393
+ objDefineAccessors(_self, "_clearTimeoutOverride", function () { return _timeoutWrapper.clear; }, function (value) {
4394
+ _timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
4395
+ });
4360
4396
  });
4361
4397
  return _this;
4362
4398
  }