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