@microsoft/1ds-post-js 3.1.10 → 3.2.1

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 (57) hide show
  1. package/README.md +124 -6
  2. package/bundle/{ms.post-3.1.10.gbl.js → ms.post-3.2.1.gbl.js} +1502 -725
  3. package/bundle/ms.post-3.2.1.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.1.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.1.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.1.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.10.js → ms.post-3.2.1.js} +1502 -725
  8. package/bundle/ms.post-3.2.1.js.map +1 -0
  9. package/bundle/ms.post-3.2.1.min.js +7 -0
  10. package/bundle/ms.post-3.2.1.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1501 -724
  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 +1501 -724
  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 +264 -149
  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.d.ts +1 -0
  27. package/dist-esm/src/Constants.js +2 -1
  28. package/dist-esm/src/Constants.js.map +1 -1
  29. package/dist-esm/src/DataModels.d.ts +49 -0
  30. package/dist-esm/src/DataModels.js +1 -1
  31. package/dist-esm/src/EventBatch.js +1 -1
  32. package/dist-esm/src/HttpManager.d.ts +1 -1
  33. package/dist-esm/src/HttpManager.js +102 -58
  34. package/dist-esm/src/HttpManager.js.map +1 -1
  35. package/dist-esm/src/Index.js +1 -1
  36. package/dist-esm/src/KillSwitch.js +1 -1
  37. package/dist-esm/src/PostChannel.d.ts +0 -4
  38. package/dist-esm/src/PostChannel.js +171 -104
  39. package/dist-esm/src/PostChannel.js.map +1 -1
  40. package/dist-esm/src/RetryPolicy.d.ts +20 -25
  41. package/dist-esm/src/RetryPolicy.js +35 -44
  42. package/dist-esm/src/RetryPolicy.js.map +1 -1
  43. package/dist-esm/src/Serializer.js +1 -1
  44. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  45. package/package.json +2 -2
  46. package/src/Constants.ts +1 -0
  47. package/src/DataModels.ts +62 -1
  48. package/src/HttpManager.ts +110 -69
  49. package/src/PostChannel.ts +203 -127
  50. package/src/RetryPolicy.ts +33 -38
  51. package/bundle/ms.post-3.1.10.gbl.js.map +0 -1
  52. package/bundle/ms.post-3.1.10.gbl.min.js +0 -7
  53. package/bundle/ms.post-3.1.10.gbl.min.js.map +0 -1
  54. package/bundle/ms.post-3.1.10.integrity.json +0 -46
  55. package/bundle/ms.post-3.1.10.js.map +0 -1
  56. package/bundle/ms.post-3.1.10.min.js +0 -7
  57. package/bundle/ms.post-3.1.10.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.2.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -59,18 +59,6 @@
59
59
 
60
60
  (getGlobal() || {})["Symbol"];
61
61
  (getGlobal() || {})["Reflect"];
62
- var __objAssignFnImpl = function (t) {
63
- for (var s, i = 1, n = arguments.length; i < n; i++) {
64
- s = arguments[i];
65
- for (var p in s) {
66
- if (ObjProto[strShimHasOwnProperty].call(s, p)) {
67
- t[p] = s[p];
68
- }
69
- }
70
- }
71
- return t;
72
- };
73
- var __assignFn = ObjAssign || __objAssignFnImpl;
74
62
  var extendStaticsFn = function (d, b) {
75
63
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
76
64
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -92,14 +80,356 @@
92
80
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
93
81
  }
94
82
 
95
- var EventsDiscardedReason = {
96
- Unknown: 0,
97
- NonRetryableStatus: 1,
98
- InvalidEvent: 2,
99
- SizeLimitExceeded: 3,
100
- KillSwitch: 4,
83
+ var strEmpty = "";
84
+ var strSetNextPlugin = "setNextPlugin";
85
+ var strIsInitialized = "isInitialized";
86
+ var strTeardown = "teardown";
87
+ var strCore = "core";
88
+ var strUpdate = "update";
89
+ var strDisabled = "disabled";
90
+ var strDoTeardown = "_doTeardown";
91
+
92
+ var cStrStartsWith = "startsWith";
93
+ var strIndexOf = "indexOf";
94
+ var cStrTrim = "trim";
95
+ var strToString = "toString";
96
+ var str__Proto$1 = "__proto__";
97
+ var strConstructor = "constructor";
98
+ var _objDefineProperty$1 = ObjDefineProperty;
99
+ var _objFreeze = ObjClass.freeze;
100
+ var _objKeys = ObjClass.keys;
101
+ var StringProto = String[strShimPrototype];
102
+ var _strTrim = StringProto[cStrTrim];
103
+ var _strStartsWith = StringProto[cStrStartsWith];
104
+ var _isArray = Array.isArray;
105
+ var _objToString = ObjProto[strToString];
106
+ var _fnToString = ObjHasOwnProperty[strToString];
107
+ var _objFunctionString = _fnToString.call(ObjClass);
108
+ var rCamelCase = /-([a-z])/g;
109
+ var rNormalizeInvalid = /([^\w\d_$])/g;
110
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
111
+ var _objGetPrototypeOf$1 = Object["getPrototypeOf"];
112
+ function _getObjProto$1(target) {
113
+ if (target) {
114
+ if (_objGetPrototypeOf$1) {
115
+ return _objGetPrototypeOf$1(target);
116
+ }
117
+ var newProto = target[str__Proto$1] || target[strShimPrototype] || target[strConstructor];
118
+ if (newProto) {
119
+ return newProto;
120
+ }
121
+ }
122
+ return null;
123
+ }
124
+ function isUndefined(value) {
125
+ return value === undefined || typeof value === strShimUndefined;
126
+ }
127
+ function isNullOrUndefined(value) {
128
+ return (value === null || isUndefined(value));
129
+ }
130
+ function hasOwnProperty(obj, prop) {
131
+ return !!(obj && ObjHasOwnProperty.call(obj, prop));
132
+ }
133
+ function isObject(value) {
134
+ return !!(value && typeof value === strShimObject);
135
+ }
136
+ function isFunction(value) {
137
+ return !!(value && typeof value === strShimFunction);
138
+ }
139
+ function normalizeJsName(name) {
140
+ var value = name;
141
+ if (value && isString(value)) {
142
+ value = value.replace(rCamelCase, function (_all, letter) {
143
+ return letter.toUpperCase();
144
+ });
145
+ value = value.replace(rNormalizeInvalid, "_");
146
+ value = value.replace(rLeadingNumeric, function (_all, match) {
147
+ return "_" + match;
148
+ });
149
+ }
150
+ return value;
151
+ }
152
+ function objForEachKey(target, callbackfn) {
153
+ if (target) {
154
+ for (var prop in target) {
155
+ if (ObjHasOwnProperty.call(target, prop)) {
156
+ callbackfn.call(target, prop, target[prop]);
157
+ }
158
+ }
159
+ }
160
+ }
161
+ function strStartsWith(value, checkValue) {
162
+ var result = false;
163
+ if (value && checkValue && !(result = value === checkValue)) {
164
+ result = _strStartsWith ? value[cStrStartsWith](checkValue) : _strStartsWithPoly(value, checkValue);
165
+ }
166
+ return result;
167
+ }
168
+ function _strStartsWithPoly(value, checkValue) {
169
+ var result = false;
170
+ var chkLen = checkValue ? checkValue.length : 0;
171
+ if (value && chkLen && value.length >= chkLen && !(result = value === checkValue)) {
172
+ for (var lp = 0; lp < chkLen; lp++) {
173
+ if (value[lp] !== checkValue[lp]) {
174
+ return false;
175
+ }
176
+ }
177
+ result = true;
178
+ }
179
+ return result;
180
+ }
181
+ function strContains(value, search) {
182
+ if (value && search) {
183
+ return value.indexOf(search) !== -1;
184
+ }
185
+ return false;
186
+ }
187
+ var isArray = _isArray || _isArrayPoly;
188
+ function _isArrayPoly(obj) {
189
+ return !!(obj && _objToString.call(obj) === "[object Array]");
190
+ }
191
+ function isString(value) {
192
+ return typeof value === "string";
193
+ }
194
+ function isNumber(value) {
195
+ return typeof value === "number";
196
+ }
197
+ function isBoolean(value) {
198
+ return typeof value === "boolean";
199
+ }
200
+ function isPlainObject(value) {
201
+ var result = false;
202
+ if (value && typeof value === "object") {
203
+ var proto = _objGetPrototypeOf$1 ? _objGetPrototypeOf$1(value) : _getObjProto$1(value);
204
+ if (!proto) {
205
+ result = true;
206
+ }
207
+ else {
208
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
209
+ proto = proto[strConstructor];
210
+ }
211
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
212
+ }
213
+ }
214
+ return result;
215
+ }
216
+ function arrForEach(arr, callbackfn, thisArg) {
217
+ var len = arr.length;
218
+ try {
219
+ for (var idx = 0; idx < len; idx++) {
220
+ if (idx in arr) {
221
+ if (callbackfn.call(thisArg || arr, arr[idx], idx, arr) === -1) {
222
+ break;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ catch (e) {
228
+ }
229
+ }
230
+ function arrIndexOf(arr, searchElement, fromIndex) {
231
+ if (arr) {
232
+ if (arr[strIndexOf]) {
233
+ return arr[strIndexOf](searchElement, fromIndex);
234
+ }
235
+ var len = arr.length;
236
+ var from = fromIndex || 0;
237
+ try {
238
+ for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
239
+ if (lp in arr && arr[lp] === searchElement) {
240
+ return lp;
241
+ }
242
+ }
243
+ }
244
+ catch (e) {
245
+ }
246
+ }
247
+ return -1;
248
+ }
249
+ function strTrim(str) {
250
+ if (str) {
251
+ str = (_strTrim && str[cStrTrim]) ? str[cStrTrim]() : (str.replace ? str.replace(/^\s+|\s+$/g, "") : str);
252
+ }
253
+ return str;
254
+ }
255
+ var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
256
+ var _objKeysDontEnums = [
257
+ "toString",
258
+ "toLocaleString",
259
+ "valueOf",
260
+ "hasOwnProperty",
261
+ "isPrototypeOf",
262
+ "propertyIsEnumerable",
263
+ "constructor"
264
+ ];
265
+ function objKeys(obj) {
266
+ var objType = typeof obj;
267
+ if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
268
+ throwTypeError("objKeys called on non-object");
269
+ }
270
+ if (!_objKeysHasDontEnumBug && _objKeys) {
271
+ return _objKeys(obj);
272
+ }
273
+ var result = [];
274
+ for (var prop in obj) {
275
+ if (obj && ObjHasOwnProperty.call(obj, prop)) {
276
+ result.push(prop);
277
+ }
278
+ }
279
+ if (_objKeysHasDontEnumBug) {
280
+ var dontEnumsLength = _objKeysDontEnums.length;
281
+ for (var lp = 0; lp < dontEnumsLength; lp++) {
282
+ if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
283
+ result.push(_objKeysDontEnums[lp]);
284
+ }
285
+ }
286
+ }
287
+ return result;
288
+ }
289
+ function objDefineAccessors(target, prop, getProp, setProp) {
290
+ if (_objDefineProperty$1) {
291
+ try {
292
+ var descriptor = {
293
+ enumerable: true,
294
+ configurable: true
295
+ };
296
+ if (getProp) {
297
+ descriptor.get = getProp;
298
+ }
299
+ if (setProp) {
300
+ descriptor.set = setProp;
301
+ }
302
+ _objDefineProperty$1(target, prop, descriptor);
303
+ return true;
304
+ }
305
+ catch (e) {
306
+ }
307
+ }
308
+ return false;
309
+ }
310
+ function _doNothing(value) {
311
+ return value;
312
+ }
313
+ function deepFreeze(obj) {
314
+ if (_objFreeze) {
315
+ objForEachKey(obj, function (name, value) {
316
+ if (isArray(value) || isObject(value)) {
317
+ _objFreeze(value);
318
+ }
319
+ });
320
+ }
321
+ return objFreeze(obj);
322
+ }
323
+ var objFreeze = _objFreeze || _doNothing;
324
+ function dateNow() {
325
+ var dt = Date;
326
+ return dt.now ? dt.now() : new dt().getTime();
327
+ }
328
+ function setValue(target, field, value, valChk, srcChk) {
329
+ var theValue = value;
330
+ if (target) {
331
+ theValue = target[field];
332
+ if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
333
+ theValue = value;
334
+ target[field] = theValue;
335
+ }
336
+ }
337
+ return theValue;
338
+ }
339
+ function _createProxyFunction(source, funcName) {
340
+ var srcFunc = null;
341
+ var src = null;
342
+ if (isFunction(source)) {
343
+ srcFunc = source;
344
+ }
345
+ else {
346
+ src = source;
347
+ }
348
+ return function () {
349
+ var originalArguments = arguments;
350
+ if (srcFunc) {
351
+ src = srcFunc();
352
+ }
353
+ if (src) {
354
+ return src[funcName].apply(src, originalArguments);
355
+ }
356
+ };
357
+ }
358
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
359
+ if (target && name && source) {
360
+ if (overwriteTarget !== false || isUndefined(target[name])) {
361
+ target[name] = _createProxyFunction(source, theFunc);
362
+ }
363
+ }
364
+ }
365
+ function optimizeObject(theObject) {
366
+ if (theObject && ObjAssign) {
367
+ theObject = ObjClass(ObjAssign({}, theObject));
368
+ }
369
+ return theObject;
370
+ }
371
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
372
+ var theArgs = arguments;
373
+ var extended = theArgs[0] || {};
374
+ var argLen = theArgs.length;
375
+ var deep = false;
376
+ var idx = 1;
377
+ if (argLen > 0 && isBoolean(extended)) {
378
+ deep = extended;
379
+ extended = theArgs[idx] || {};
380
+ idx++;
381
+ }
382
+ if (!isObject(extended)) {
383
+ extended = {};
384
+ }
385
+ for (; idx < argLen; idx++) {
386
+ var arg = theArgs[idx];
387
+ var isArgArray = isArray(arg);
388
+ var isArgObj = isObject(arg);
389
+ for (var prop in arg) {
390
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
391
+ if (!propOk) {
392
+ continue;
393
+ }
394
+ var newValue = arg[prop];
395
+ var isNewArray = void 0;
396
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
397
+ var clone = extended[prop];
398
+ if (isNewArray) {
399
+ if (!isArray(clone)) {
400
+ clone = [];
401
+ }
402
+ }
403
+ else if (!isPlainObject(clone)) {
404
+ clone = {};
405
+ }
406
+ newValue = objExtend(deep, clone, newValue);
407
+ }
408
+ if (newValue !== undefined) {
409
+ extended[prop] = newValue;
410
+ }
411
+ }
412
+ }
413
+ return extended;
414
+ }
415
+
416
+ function createEnumStyle(values) {
417
+ var enumClass = {};
418
+ objForEachKey(values, function (field, value) {
419
+ enumClass[field] = value;
420
+ enumClass[value] = field;
421
+ });
422
+ return deepFreeze(enumClass);
423
+ }
424
+
425
+ var EventsDiscardedReason = createEnumStyle({
426
+ Unknown: 0 ,
427
+ NonRetryableStatus: 1 ,
428
+ InvalidEvent: 2 ,
429
+ SizeLimitExceeded: 3 ,
430
+ KillSwitch: 4 ,
101
431
  QueueFull: 5
102
- };
432
+ });
103
433
 
104
434
  /*!
105
435
  * Microsoft Dynamic Proto Utility, 1.1.4
@@ -342,287 +672,6 @@
342
672
  };
343
673
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
344
674
 
345
- var LoggingSeverity;
346
- (function (LoggingSeverity) {
347
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
348
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
349
- })(LoggingSeverity || (LoggingSeverity = {}));
350
- var _InternalMessageId = {
351
- BrowserDoesNotSupportLocalStorage: 0,
352
- BrowserCannotReadLocalStorage: 1,
353
- BrowserCannotReadSessionStorage: 2,
354
- BrowserCannotWriteLocalStorage: 3,
355
- BrowserCannotWriteSessionStorage: 4,
356
- BrowserFailedRemovalFromLocalStorage: 5,
357
- BrowserFailedRemovalFromSessionStorage: 6,
358
- CannotSendEmptyTelemetry: 7,
359
- ClientPerformanceMathError: 8,
360
- ErrorParsingAISessionCookie: 9,
361
- ErrorPVCalc: 10,
362
- ExceptionWhileLoggingError: 11,
363
- FailedAddingTelemetryToBuffer: 12,
364
- FailedMonitorAjaxAbort: 13,
365
- FailedMonitorAjaxDur: 14,
366
- FailedMonitorAjaxOpen: 15,
367
- FailedMonitorAjaxRSC: 16,
368
- FailedMonitorAjaxSend: 17,
369
- FailedMonitorAjaxGetCorrelationHeader: 18,
370
- FailedToAddHandlerForOnBeforeUnload: 19,
371
- FailedToSendQueuedTelemetry: 20,
372
- FailedToReportDataLoss: 21,
373
- FlushFailed: 22,
374
- MessageLimitPerPVExceeded: 23,
375
- MissingRequiredFieldSpecification: 24,
376
- NavigationTimingNotSupported: 25,
377
- OnError: 26,
378
- SessionRenewalDateIsZero: 27,
379
- SenderNotInitialized: 28,
380
- StartTrackEventFailed: 29,
381
- StopTrackEventFailed: 30,
382
- StartTrackFailed: 31,
383
- StopTrackFailed: 32,
384
- TelemetrySampledAndNotSent: 33,
385
- TrackEventFailed: 34,
386
- TrackExceptionFailed: 35,
387
- TrackMetricFailed: 36,
388
- TrackPVFailed: 37,
389
- TrackPVFailedCalc: 38,
390
- TrackTraceFailed: 39,
391
- TransmissionFailed: 40,
392
- FailedToSetStorageBuffer: 41,
393
- FailedToRestoreStorageBuffer: 42,
394
- InvalidBackendResponse: 43,
395
- FailedToFixDepricatedValues: 44,
396
- InvalidDurationValue: 45,
397
- TelemetryEnvelopeInvalid: 46,
398
- CreateEnvelopeError: 47,
399
- CannotSerializeObject: 48,
400
- CannotSerializeObjectNonSerializable: 49,
401
- CircularReferenceDetected: 50,
402
- ClearAuthContextFailed: 51,
403
- ExceptionTruncated: 52,
404
- IllegalCharsInName: 53,
405
- ItemNotInArray: 54,
406
- MaxAjaxPerPVExceeded: 55,
407
- MessageTruncated: 56,
408
- NameTooLong: 57,
409
- SampleRateOutOfRange: 58,
410
- SetAuthContextFailed: 59,
411
- SetAuthContextFailedAccountName: 60,
412
- StringValueTooLong: 61,
413
- StartCalledMoreThanOnce: 62,
414
- StopCalledWithoutStart: 63,
415
- TelemetryInitializerFailed: 64,
416
- TrackArgumentsNotSpecified: 65,
417
- UrlTooLong: 66,
418
- SessionStorageBufferFull: 67,
419
- CannotAccessCookie: 68,
420
- IdTooLong: 69,
421
- InvalidEvent: 70,
422
- FailedMonitorAjaxSetRequestHeader: 71,
423
- SendBrowserInfoOnUserInit: 72,
424
- PluginException: 73,
425
- NotificationException: 74,
426
- SnippetScriptLoadFailure: 99,
427
- InvalidInstrumentationKey: 100,
428
- CannotParseAiBlobValue: 101,
429
- InvalidContentBlob: 102,
430
- TrackPageActionEventFailed: 103,
431
- FailedAddingCustomDefinedRequestContext: 104,
432
- InMemoryStorageBufferFull: 105
433
- };
434
-
435
- var strOnPrefix = "on";
436
- var strAttachEvent = "attachEvent";
437
- var strAddEventHelper = "addEventListener";
438
- var _objDefineProperty = ObjDefineProperty;
439
- function objToString(obj) {
440
- return ObjProto.toString.call(obj);
441
- }
442
- function isUndefined(value) {
443
- return value === undefined || typeof value === strShimUndefined;
444
- }
445
- function isNullOrUndefined(value) {
446
- return (value === null || isUndefined(value));
447
- }
448
- function hasOwnProperty(obj, prop) {
449
- return obj && ObjHasOwnProperty.call(obj, prop);
450
- }
451
- function isObject(value) {
452
- return typeof value === strShimObject;
453
- }
454
- function isFunction(value) {
455
- return typeof value === strShimFunction;
456
- }
457
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
458
- if (useCapture === void 0) { useCapture = false; }
459
- var result = false;
460
- if (!isNullOrUndefined(obj)) {
461
- try {
462
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
463
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
464
- result = true;
465
- }
466
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
467
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
468
- result = true;
469
- }
470
- }
471
- catch (e) {
472
- }
473
- }
474
- return result;
475
- }
476
- function objForEachKey(target, callbackfn) {
477
- if (target) {
478
- for (var prop in target) {
479
- if (ObjHasOwnProperty.call(target, prop)) {
480
- callbackfn.call(target, prop, target[prop]);
481
- }
482
- }
483
- }
484
- }
485
- function strStartsWith(value, checkValue) {
486
- var result = false;
487
- if (value && checkValue) {
488
- var chkLen = checkValue.length;
489
- if (value === checkValue) {
490
- return true;
491
- }
492
- else if (value.length >= chkLen) {
493
- for (var lp = 0; lp < chkLen; lp++) {
494
- if (value[lp] !== checkValue[lp]) {
495
- return false;
496
- }
497
- }
498
- result = true;
499
- }
500
- }
501
- return result;
502
- }
503
- function isArray(obj) {
504
- return objToString(obj) === "[object Array]";
505
- }
506
- function isString(value) {
507
- return typeof value === "string";
508
- }
509
- function isNumber(value) {
510
- return typeof value === "number";
511
- }
512
- function isBoolean(value) {
513
- return typeof value === "boolean";
514
- }
515
- function arrForEach(arr, callbackfn, thisArg) {
516
- var len = arr.length;
517
- try {
518
- for (var idx = 0; idx < len; idx++) {
519
- if (idx in arr) {
520
- if (callbackfn.call(thisArg || arr, arr[idx], idx, arr) === -1) {
521
- break;
522
- }
523
- }
524
- }
525
- }
526
- catch (e) {
527
- }
528
- }
529
- function arrIndexOf(arr, searchElement, fromIndex) {
530
- var len = arr.length;
531
- var from = fromIndex || 0;
532
- try {
533
- for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
534
- if (lp in arr && arr[lp] === searchElement) {
535
- return lp;
536
- }
537
- }
538
- }
539
- catch (e) {
540
- }
541
- return -1;
542
- }
543
- function strTrim(str) {
544
- if (typeof str !== "string") {
545
- return str;
546
- }
547
- return str.replace(/^\s+|\s+$/g, "");
548
- }
549
- var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
550
- var _objKeysDontEnums = [
551
- "toString",
552
- "toLocaleString",
553
- "valueOf",
554
- "hasOwnProperty",
555
- "isPrototypeOf",
556
- "propertyIsEnumerable",
557
- "constructor"
558
- ];
559
- function objKeys(obj) {
560
- var objType = typeof obj;
561
- if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
562
- throwTypeError("objKeys called on non-object");
563
- }
564
- var result = [];
565
- for (var prop in obj) {
566
- if (obj && ObjHasOwnProperty.call(obj, prop)) {
567
- result.push(prop);
568
- }
569
- }
570
- if (_objKeysHasDontEnumBug) {
571
- var dontEnumsLength = _objKeysDontEnums.length;
572
- for (var lp = 0; lp < dontEnumsLength; lp++) {
573
- if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
574
- result.push(_objKeysDontEnums[lp]);
575
- }
576
- }
577
- }
578
- return result;
579
- }
580
- function objDefineAccessors(target, prop, getProp, setProp) {
581
- if (_objDefineProperty) {
582
- try {
583
- var descriptor = {
584
- enumerable: true,
585
- configurable: true
586
- };
587
- if (getProp) {
588
- descriptor.get = getProp;
589
- }
590
- if (setProp) {
591
- descriptor.set = setProp;
592
- }
593
- _objDefineProperty(target, prop, descriptor);
594
- return true;
595
- }
596
- catch (e) {
597
- }
598
- }
599
- return false;
600
- }
601
- function dateNow() {
602
- var dt = Date;
603
- if (dt.now) {
604
- return dt.now();
605
- }
606
- return new dt().getTime();
607
- }
608
- function setValue(target, field, value, valChk, srcChk) {
609
- var theValue = value;
610
- if (target) {
611
- theValue = target[field];
612
- if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
613
- theValue = value;
614
- target[field] = theValue;
615
- }
616
- }
617
- return theValue;
618
- }
619
- function optimizeObject(theObject) {
620
- if (theObject) {
621
- theObject = ObjClass(ObjAssign ? ObjAssign({}, theObject) : theObject);
622
- }
623
- return theObject;
624
- }
625
-
626
675
  var strWindow = "window";
627
676
  var strDocument = "document";
628
677
  var strNavigator = "navigator";
@@ -630,7 +679,14 @@
630
679
  var strConsole = "console";
631
680
  var strPerformance = "performance";
632
681
  var strJSON = "JSON";
682
+ var strCrypto = "crypto";
683
+ var strMsCrypto = "msCrypto";
633
684
  var strReactNative = "ReactNative";
685
+ var strMsie = "msie";
686
+ var strTrident = "trident/";
687
+ var strXMLHttpRequest = "XMLHttpRequest";
688
+ var _isTrident = null;
689
+ var _navUserAgentCheck = null;
634
690
  var _enableMocks = false;
635
691
  var _useXDomainRequest = null;
636
692
  var _beaconsSupported = null;
@@ -726,6 +782,12 @@
726
782
  }
727
783
  return null;
728
784
  }
785
+ function getCrypto() {
786
+ return getGlobalInst(strCrypto);
787
+ }
788
+ function getMsCrypto() {
789
+ return getGlobalInst(strMsCrypto);
790
+ }
729
791
  function isReactNative() {
730
792
  var nav = getNavigator();
731
793
  if (nav && nav.product) {
@@ -733,9 +795,18 @@
733
795
  }
734
796
  return false;
735
797
  }
798
+ function isIE() {
799
+ var nav = getNavigator();
800
+ if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
801
+ _navUserAgentCheck = nav.userAgent;
802
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
803
+ _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
804
+ }
805
+ return _isTrident;
806
+ }
736
807
  function dumpObj(object) {
737
808
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
738
- var propertyValueDump = "";
809
+ var propertyValueDump = strEmpty;
739
810
  if (objectTypeDump === "[object Error]") {
740
811
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
741
812
  }
@@ -753,8 +824,7 @@
753
824
  function isFetchSupported(withKeepAlive) {
754
825
  var isSupported = false;
755
826
  try {
756
- var fetchApi = getGlobalInst("fetch");
757
- isSupported = !!fetchApi;
827
+ isSupported = !!getGlobalInst("fetch");
758
828
  var request = getGlobalInst("Request");
759
829
  if (isSupported && withKeepAlive && request) {
760
830
  isSupported = _hasProperty(request, "keepalive");
@@ -766,9 +836,9 @@
766
836
  }
767
837
  function useXDomainRequest() {
768
838
  if (_useXDomainRequest === null) {
769
- _useXDomainRequest = (typeof XDomainRequest !== "undefined");
839
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
770
840
  if (_useXDomainRequest && isXhrSupported()) {
771
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
841
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
772
842
  }
773
843
  }
774
844
  return _useXDomainRequest;
@@ -776,7 +846,7 @@
776
846
  function isXhrSupported() {
777
847
  var isSupported = false;
778
848
  try {
779
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
849
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
780
850
  isSupported = !!xmlHttpRequest;
781
851
  }
782
852
  catch (e) {
@@ -807,9 +877,9 @@
807
877
  var strWarnToConsole = "warnToConsole";
808
878
  function _sanitizeDiagnosticText(text) {
809
879
  if (text) {
810
- return "\"" + text.replace(/\"/g, "") + "\"";
880
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
811
881
  }
812
- return "";
882
+ return strEmpty;
813
883
  }
814
884
  function _logToConsole(func, message) {
815
885
  var theConsole = getConsole();
@@ -831,12 +901,12 @@
831
901
  _self.message =
832
902
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
833
903
  msgId;
834
- var strProps = "";
904
+ var strProps = strEmpty;
835
905
  if (hasJSON()) {
836
906
  strProps = getJSON().stringify(properties);
837
907
  }
838
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
839
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
908
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
909
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
840
910
  _self.message += diagnosticText;
841
911
  }
842
912
  _InternalLogMessage.dataType = "MessageData";
@@ -866,7 +936,7 @@
866
936
  throw message;
867
937
  }
868
938
  else {
869
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
939
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
870
940
  if (!isUndefined(message.message)) {
871
941
  var logLevel = _self.consoleLoggingLevel();
872
942
  if (isUserAct) {
@@ -884,7 +954,7 @@
884
954
  _self.logInternalMessage(severity, message);
885
955
  }
886
956
  else {
887
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
957
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
888
958
  }
889
959
  }
890
960
  };
@@ -916,13 +986,13 @@
916
986
  if (severity <= _self.telemetryLoggingLevel()) {
917
987
  _self.queue.push(message);
918
988
  _messageCount++;
919
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
989
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
920
990
  }
921
991
  if (_messageCount === _self.maxInternalMessageLimit()) {
922
992
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
923
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
993
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
924
994
  _self.queue.push(throttleMessage);
925
- if (severity === LoggingSeverity.CRITICAL) {
995
+ if (severity === 1 ) {
926
996
  _self.errorToConsole(throttleLimitMessage);
927
997
  }
928
998
  else {
@@ -951,6 +1021,10 @@
951
1021
  }
952
1022
  return DiagnosticLogger;
953
1023
  }());
1024
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1025
+ if (isUserAct === void 0) { isUserAct = false; }
1026
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1027
+ }
954
1028
 
955
1029
  var strExecutionContextKey = "ctx";
956
1030
  var PerfEvent = /** @class */ (function () {
@@ -1064,207 +1138,621 @@
1064
1138
  return func();
1065
1139
  }
1066
1140
 
1067
- var TelemetryPluginChain = /** @class */ (function () {
1068
- function TelemetryPluginChain(plugin, defItemCtx) {
1069
- var _self = this;
1070
- var _nextProxy = null;
1071
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1072
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1073
- _self._hasRun = false;
1074
- _self.getPlugin = function () {
1075
- return plugin;
1076
- };
1077
- _self.getNext = function () {
1078
- return _nextProxy;
1079
- };
1080
- _self.setNext = function (nextPlugin) {
1081
- _nextProxy = nextPlugin;
1082
- };
1083
- _self.processTelemetry = function (env, itemCtx) {
1084
- if (!itemCtx) {
1085
- itemCtx = defItemCtx;
1141
+ var UInt32Mask = 0x100000000;
1142
+ var MaxUInt32 = 0xffffffff;
1143
+ var _mwcSeeded = false;
1144
+ var _mwcW = 123456789;
1145
+ var _mwcZ = 987654321;
1146
+ function _mwcSeed(seedValue) {
1147
+ if (seedValue < 0) {
1148
+ seedValue >>>= 0;
1149
+ }
1150
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1151
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1152
+ _mwcSeeded = true;
1153
+ }
1154
+ function _autoSeedMwc() {
1155
+ try {
1156
+ var now = dateNow() & 0x7fffffff;
1157
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1158
+ }
1159
+ catch (e) {
1160
+ }
1161
+ }
1162
+ function random32(signed) {
1163
+ var value = 0;
1164
+ var c = getCrypto() || getMsCrypto();
1165
+ if (c && c.getRandomValues) {
1166
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1167
+ }
1168
+ if (value === 0 && isIE()) {
1169
+ if (!_mwcSeeded) {
1170
+ _autoSeedMwc();
1171
+ }
1172
+ value = mwcRandom32() & MaxUInt32;
1173
+ }
1174
+ if (value === 0) {
1175
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1176
+ }
1177
+ if (!signed) {
1178
+ value >>>= 0;
1179
+ }
1180
+ return value;
1181
+ }
1182
+ function mwcRandom32(signed) {
1183
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1184
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1185
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1186
+ if (!signed) {
1187
+ value >>>= 0;
1188
+ }
1189
+ return value;
1190
+ }
1191
+ function newId(maxLength) {
1192
+ if (maxLength === void 0) { maxLength = 22; }
1193
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1194
+ var number = random32() >>> 0;
1195
+ var chars = 0;
1196
+ var result = strEmpty;
1197
+ while (result.length < maxLength) {
1198
+ chars++;
1199
+ result += base64chars.charAt(number & 0x3F);
1200
+ number >>>= 6;
1201
+ if (chars === 5) {
1202
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1203
+ chars = 0;
1204
+ }
1205
+ }
1206
+ return result;
1207
+ }
1208
+
1209
+ var _objDefineProperty = ObjDefineProperty;
1210
+ var version = "2.8.1";
1211
+ var instanceName = "." + newId(6);
1212
+ var _dataUid = 0;
1213
+ function _createAccessor(target, prop, value) {
1214
+ if (_objDefineProperty) {
1215
+ try {
1216
+ _objDefineProperty(target, prop, {
1217
+ value: value,
1218
+ enumerable: false,
1219
+ configurable: true
1220
+ });
1221
+ return true;
1222
+ }
1223
+ catch (e) {
1224
+ }
1225
+ }
1226
+ return false;
1227
+ }
1228
+ function _canAcceptData(target) {
1229
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1230
+ }
1231
+ function _getCache(data, target) {
1232
+ var theCache = target[data.id];
1233
+ if (!theCache) {
1234
+ theCache = {};
1235
+ try {
1236
+ if (_canAcceptData(target)) {
1237
+ if (!_createAccessor(target, data.id, theCache)) {
1238
+ target[data.id] = theCache;
1239
+ }
1086
1240
  }
1087
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1088
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1089
- if (plugin && _hasProcessTelemetry) {
1090
- _self._hasRun = true;
1241
+ }
1242
+ catch (e) {
1243
+ }
1244
+ }
1245
+ return theCache;
1246
+ }
1247
+ function createUniqueNamespace(name, includeVersion) {
1248
+ if (includeVersion === void 0) { includeVersion = false; }
1249
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1250
+ }
1251
+ function createElmNodeData(name) {
1252
+ var data = {
1253
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1254
+ accept: function (target) {
1255
+ return _canAcceptData(target);
1256
+ },
1257
+ get: function (target, name, defValue, addDefault) {
1258
+ var theCache = target[data.id];
1259
+ if (!theCache) {
1260
+ if (addDefault) {
1261
+ theCache = _getCache(data, target);
1262
+ theCache[normalizeJsName(name)] = defValue;
1263
+ }
1264
+ return defValue;
1265
+ }
1266
+ return theCache[normalizeJsName(name)];
1267
+ },
1268
+ kill: function (target, name) {
1269
+ if (target && target[name]) {
1270
+ try {
1271
+ delete target[name];
1272
+ }
1273
+ catch (e) {
1274
+ }
1275
+ }
1276
+ }
1277
+ };
1278
+ return data;
1279
+ }
1280
+
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();
1296
+ }
1297
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
1298
+ }
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
1342
+ });
1343
+ }
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) {
1091
1352
  try {
1092
- itemCtx.setNext(_nextProxy);
1093
- if (_hasSetNext) {
1094
- plugin.setNextPlugin(_nextProxy);
1095
- }
1096
- _nextProxy && (_nextProxy._hasRun = false);
1097
- plugin.processTelemetry(env, itemCtx);
1353
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1098
1354
  }
1099
- catch (error) {
1100
- var hasRun = _nextProxy && _nextProxy._hasRun;
1101
- if (!_nextProxy || !hasRun) {
1102
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1103
- }
1104
- if (_nextProxy && !hasRun) {
1105
- _nextProxy.processTelemetry(env, itemCtx);
1106
- }
1355
+ catch (e) {
1356
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1107
1357
  }
1358
+ });
1359
+ _onComplete = [];
1360
+ }
1361
+ }
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];
1372
+ }
1373
+ }
1374
+ if (!theConfig) {
1375
+ theConfig = defaultValue;
1376
+ }
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
+ });
1108
1389
  }
1109
- else if (_nextProxy) {
1110
- _self._hasRun = true;
1111
- _nextProxy.processTelemetry(env, itemCtx);
1390
+ theConfig = newConfig_1;
1391
+ }
1392
+ }
1393
+ return theConfig;
1394
+ }
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];
1401
+ }
1402
+ else if (config && !isNullOrUndefined(config[field])) {
1403
+ theValue = config[field];
1404
+ }
1405
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1406
+ }
1407
+ function _iterateChain(cb) {
1408
+ var nextPlugin;
1409
+ while (!!(nextPlugin = context._next())) {
1410
+ var plugin = nextPlugin.getPlugin();
1411
+ if (plugin) {
1412
+ cb(plugin);
1413
+ }
1414
+ }
1415
+ }
1416
+ return context;
1417
+ }
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;
1425
+ }
1426
+ function _createNew(plugins, startAt) {
1427
+ if (plugins === void 0) { plugins = null; }
1428
+ if (isArray(plugins)) {
1429
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1430
+ }
1431
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1432
+ }
1433
+ context.processNext = _processNext;
1434
+ context.createNew = _createNew;
1435
+ return context;
1436
+ }
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);
1450
+ }
1451
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1452
+ }
1453
+ context.processNext = _processNext;
1454
+ context.createNew = _createNew;
1455
+ return context;
1456
+ }
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);
1465
+ }
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
+ }
1473
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1474
+ }
1475
+ context.processNext = _processNext;
1476
+ context.createNew = _createNew;
1477
+ return context;
1478
+ }
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;
1112
1492
  }
1113
- }, function () { return ({ item: env }); }, !(env.sync));
1114
- };
1493
+ if (lastProxy_1) {
1494
+ lastProxy_1._setNext(newProxy);
1495
+ }
1496
+ lastProxy_1 = newProxy;
1497
+ }
1498
+ });
1115
1499
  }
1116
- return TelemetryPluginChain;
1117
- }());
1118
-
1119
- function _createProxyChain(plugins, itemCtx) {
1120
- var proxies = [];
1121
- if (plugins && plugins.length > 0) {
1122
- var lastProxy = null;
1123
- for (var idx = 0; idx < plugins.length; idx++) {
1124
- var thePlugin = plugins[idx];
1125
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1126
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1127
- proxies.push(newProxy);
1128
- if (lastProxy) {
1129
- lastProxy.setNext(newProxy);
1500
+ if (startAt && !firstProxy) {
1501
+ return createTelemetryProxyChain([startAt], config, core);
1502
+ }
1503
+ return firstProxy;
1504
+ }
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++;
1515
+ }
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;
1540
+ }
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);
1130
1558
  }
1131
- lastProxy = newProxy;
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;
1571
+ }
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);
1132
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);
1133
1590
  }
1134
1591
  }
1135
- return proxies.length > 0 ? proxies[0] : null;
1136
- }
1137
- function _copyProxyChain(proxy, itemCtx, startAt) {
1138
- var plugins = [];
1139
- var add = startAt ? false : true;
1140
- if (proxy) {
1141
- while (proxy) {
1142
- var thePlugin = proxy.getPlugin();
1143
- if (add || thePlugin === startAt) {
1144
- add = true;
1145
- plugins.push(thePlugin);
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
+ }
1605
+ }
1146
1606
  }
1147
- proxy = proxy.getNext();
1607
+ return hasRun;
1608
+ }
1609
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1610
+ unloadCtx.processNext(unloadState);
1148
1611
  }
1149
1612
  }
1150
- if (!add) {
1151
- plugins.push(startAt);
1152
- }
1153
- return _createProxyChain(plugins, itemCtx);
1154
- }
1155
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1156
- var plugins = srcPlugins;
1157
- var add = false;
1158
- if (startAt && srcPlugins) {
1159
- plugins = [];
1160
- arrForEach(srcPlugins, function (thePlugin) {
1161
- if (add || thePlugin === startAt) {
1162
- add = true;
1163
- plugins.push(thePlugin);
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
+ }
1164
1624
  }
1165
- });
1166
- }
1167
- if (startAt && !add) {
1168
- if (!plugins) {
1169
- plugins = [];
1625
+ return hasRun;
1626
+ }
1627
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1628
+ updateCtx.processNext(updateState);
1170
1629
  }
1171
- plugins.push(startAt);
1172
1630
  }
1173
- return _createProxyChain(plugins, itemCtx);
1631
+ return objFreeze(proxyChain);
1174
1632
  }
1175
- var ProcessTelemetryContext = /** @class */ (function () {
1176
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1177
- var _self = this;
1178
- var _nextProxy = null;
1179
- if (startAt !== null) {
1180
- if (plugins && isFunction(plugins.getPlugin)) {
1181
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1182
- }
1183
- else {
1184
- if (startAt) {
1185
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1186
- }
1187
- else if (isUndefined(startAt)) {
1188
- _nextProxy = _createProxyChain(plugins, _self);
1189
- }
1190
- }
1633
+
1634
+ var strExtensionConfig = "extensionConfig";
1635
+
1636
+ function createUnloadHandlerContainer() {
1637
+ var handlers = [];
1638
+ function _addHandler(handler) {
1639
+ if (handler) {
1640
+ handlers.push(handler);
1191
1641
  }
1192
- _self.core = function () {
1193
- return core;
1194
- };
1195
- _self.diagLog = function () {
1196
- return safeGetLogger(core, config);
1197
- };
1198
- _self.getCfg = function () {
1199
- return config;
1200
- };
1201
- _self.getExtCfg = function (identifier, defaultValue) {
1202
- if (defaultValue === void 0) { defaultValue = {}; }
1203
- var theConfig;
1204
- if (config) {
1205
- var extConfig = config.extensionConfig;
1206
- if (extConfig && identifier) {
1207
- theConfig = extConfig[identifier];
1208
- }
1209
- }
1210
- return (theConfig ? theConfig : defaultValue);
1211
- };
1212
- _self.getConfig = function (identifier, field, defaultValue) {
1213
- if (defaultValue === void 0) { defaultValue = false; }
1214
- var theValue;
1215
- var extConfig = _self.getExtCfg(identifier, null);
1216
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1217
- theValue = extConfig[field];
1218
- }
1219
- else if (config && !isNullOrUndefined(config[field])) {
1220
- theValue = config[field];
1642
+ }
1643
+ function _runHandlers(unloadCtx, unloadState) {
1644
+ arrForEach(handlers, function (handler) {
1645
+ try {
1646
+ handler(unloadCtx, unloadState);
1221
1647
  }
1222
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1223
- };
1224
- _self.hasNext = function () {
1225
- return _nextProxy != null;
1226
- };
1227
- _self.getNext = function () {
1228
- return _nextProxy;
1229
- };
1230
- _self.setNext = function (nextPlugin) {
1231
- _nextProxy = nextPlugin;
1232
- };
1233
- _self.processNext = function (env) {
1234
- var nextPlugin = _nextProxy;
1235
- if (nextPlugin) {
1236
- _nextProxy = nextPlugin.getNext();
1237
- nextPlugin.processTelemetry(env, _self);
1648
+ catch (e) {
1649
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1238
1650
  }
1239
- };
1240
- _self.createNew = function (plugins, startAt) {
1241
- if (plugins === void 0) { plugins = null; }
1242
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1243
- };
1651
+ });
1652
+ handlers = [];
1244
1653
  }
1245
- return ProcessTelemetryContext;
1246
- }());
1247
-
1248
- var strExtensionConfig = "extensionConfig";
1654
+ return {
1655
+ add: _addHandler,
1656
+ run: _runHandlers
1657
+ };
1658
+ }
1249
1659
 
1250
1660
  var strGetPlugin = "getPlugin";
1251
1661
  var BaseTelemetryPlugin = /** @class */ (function () {
1252
1662
  function BaseTelemetryPlugin() {
1253
1663
  var _self = this;
1254
- var _isinitialized = false;
1255
- var _rootCtx = null;
1256
- var _nextPlugin = null;
1257
- _self.core = null;
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);
1738
+ }
1739
+ else {
1740
+ _hooks.push(hooks);
1741
+ }
1742
+ }
1743
+ };
1744
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1745
+ });
1258
1746
  _self.diagLog = function (itemCtx) {
1259
- return _self._getTelCtx(itemCtx).diagLog();
1747
+ return _getTelCtx(itemCtx).diagLog();
1260
1748
  };
1261
- _self.isInitialized = function () {
1749
+ _self[strIsInitialized] = function () {
1262
1750
  return _isinitialized;
1263
1751
  };
1264
1752
  _self.setInitialized = function (isInitialized) {
1265
1753
  _isinitialized = isInitialized;
1266
1754
  };
1267
- _self.setNextPlugin = function (next) {
1755
+ _self[strSetNextPlugin] = function (next) {
1268
1756
  _nextPlugin = next;
1269
1757
  };
1270
1758
  _self.processNext = function (env, itemCtx) {
@@ -1275,11 +1763,12 @@
1275
1763
  _nextPlugin.processTelemetry(env, null);
1276
1764
  }
1277
1765
  };
1278
- _self._getTelCtx = function (currentCtx) {
1766
+ _self._getTelCtx = _getTelCtx;
1767
+ function _getTelCtx(currentCtx) {
1279
1768
  if (currentCtx === void 0) { currentCtx = null; }
1280
1769
  var itemCtx = currentCtx;
1281
1770
  if (!itemCtx) {
1282
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1771
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1283
1772
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1284
1773
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1285
1774
  }
@@ -1288,8 +1777,8 @@
1288
1777
  }
1289
1778
  }
1290
1779
  return itemCtx;
1291
- };
1292
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1780
+ }
1781
+ function _setDefaults(config, core, pluginChain) {
1293
1782
  if (config) {
1294
1783
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1295
1784
  }
@@ -1301,93 +1790,300 @@
1301
1790
  nextPlugin = _nextPlugin[strGetPlugin]();
1302
1791
  }
1303
1792
  _self.core = core;
1304
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1305
- _isinitialized = true;
1306
- };
1793
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1794
+ }
1795
+ function _initDefaults() {
1796
+ _isinitialized = false;
1797
+ _self.core = null;
1798
+ _rootCtx = null;
1799
+ _nextPlugin = null;
1800
+ _hooks = [];
1801
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1802
+ }
1307
1803
  }
1308
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1309
- this._baseTelInit(config, core, extensions, pluginChain);
1310
- };
1311
1804
  return BaseTelemetryPlugin;
1312
1805
  }());
1313
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";
1314
1813
  var strVisibilityChangeEvt = "visibilitychange";
1315
1814
  var strPageHide = "pagehide";
1316
1815
  var strPageShow = "pageshow";
1317
- function addEventHandler(eventName, callback) {
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;
1843
+ }
1844
+ });
1845
+ }
1846
+ else {
1847
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1848
+ }
1849
+ if (theNamespace_1) {
1850
+ if (theNamespace_1[0] !== ".") {
1851
+ theNamespace_1 = "." + theNamespace_1;
1852
+ }
1853
+ eventName = (eventName || "") + theNamespace_1;
1854
+ }
1855
+ }
1856
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1857
+ return {
1858
+ type: parsedEvent[1],
1859
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1860
+ };
1861
+ }
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] = [];
1868
+ }
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);
1878
+ }
1879
+ }
1880
+ }
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;
1887
+ }
1888
+ else if (obj[strAttachEvent]) {
1889
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1890
+ result = true;
1891
+ }
1892
+ }
1893
+ return result;
1894
+ }
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);
1904
+ }
1905
+ }
1906
+ }
1907
+ }
1908
+ }
1909
+ function _unregisterEvents(target, evtName, unRegFn) {
1910
+ if (evtName.type) {
1911
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1912
+ }
1913
+ 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
+ }
1921
+ }
1922
+ }
1923
+ function mergeEvtNamespace(theNamespace, namespaces) {
1924
+ var newNamespaces;
1925
+ if (namespaces) {
1926
+ if (isArray(namespaces)) {
1927
+ newNamespaces = [theNamespace].concat(namespaces);
1928
+ }
1929
+ else {
1930
+ newNamespaces = [theNamespace, namespaces];
1931
+ }
1932
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1933
+ }
1934
+ else {
1935
+ newNamespaces = theNamespace;
1936
+ }
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);
1954
+ }
1955
+ }
1956
+ catch (e) {
1957
+ }
1958
+ }
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;
1971
+ }
1972
+ return false;
1973
+ });
1974
+ if (!found_1) {
1975
+ _doDetach(target, evtName_1, handlerRef, useCapture);
1976
+ }
1977
+ }
1978
+ catch (e) {
1979
+ }
1980
+ }
1981
+ }
1982
+ function addEventHandler(eventName, callback, evtNamespace) {
1318
1983
  var result = false;
1319
1984
  var w = getWindow();
1320
1985
  if (w) {
1321
- result = attachEvent(w, eventName, callback);
1322
- result = attachEvent(w["body"], eventName, callback) || result;
1986
+ result = eventOn(w, eventName, callback, evtNamespace);
1987
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1323
1988
  }
1324
1989
  var doc = getDocument();
1325
1990
  if (doc) {
1326
- result = attachEvent(doc, eventName, callback) || result;
1991
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
1327
1992
  }
1328
1993
  return result;
1329
1994
  }
1330
- function addEventListeners(events, listener, excludeEvents) {
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) {
1331
2007
  var added = false;
1332
- if (listener && events && isArray(events)) {
1333
- var excluded_1 = [];
2008
+ if (listener && events && events.length > 0) {
1334
2009
  arrForEach(events, function (name) {
1335
- if (isString(name)) {
2010
+ if (name) {
1336
2011
  if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
1337
- added = addEventHandler(name, listener) || added;
1338
- }
1339
- else {
1340
- excluded_1.push(name);
2012
+ added = addEventHandler(name, listener, evtNamespace) || added;
1341
2013
  }
1342
2014
  }
1343
2015
  });
1344
- if (!added && excluded_1.length > 0) {
1345
- added = addEventListeners(excluded_1, listener);
2016
+ }
2017
+ return added;
2018
+ }
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);
1346
2025
  }
1347
2026
  }
1348
2027
  return added;
1349
2028
  }
1350
- function addPageUnloadEventListener(listener, excludeEvents) {
1351
- return addEventListeners(["beforeunload", "unload", "pagehide"], listener, excludeEvents);
2029
+ function removeEventListeners(events, listener, evtNamespace) {
2030
+ if (events && isArray(events)) {
2031
+ arrForEach(events, function (name) {
2032
+ if (name) {
2033
+ removeEventHandler(name, listener, evtNamespace);
2034
+ }
2035
+ });
2036
+ }
2037
+ }
2038
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
2039
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
1352
2040
  }
1353
- function addPageHideEventListener(listener, excludeEvents) {
2041
+ function removePageUnloadEventListener(listener, evtNamespace) {
2042
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
2043
+ }
2044
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
1354
2045
  function _handlePageVisibility(evt) {
1355
2046
  var doc = getDocument();
1356
2047
  if (listener && doc && doc.visibilityState === "hidden") {
1357
2048
  listener(evt);
1358
2049
  }
1359
2050
  }
1360
- var pageUnloadAdded = false;
1361
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
1362
- pageUnloadAdded = addEventHandler(strPageHide, listener);
1363
- }
2051
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2052
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
1364
2053
  if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1365
- pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
2054
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
1366
2055
  }
1367
2056
  if (!pageUnloadAdded && excludeEvents) {
1368
- pageUnloadAdded = addPageHideEventListener(listener);
2057
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
1369
2058
  }
1370
2059
  return pageUnloadAdded;
1371
2060
  }
1372
- function addPageShowEventListener(listener, excludeEvents) {
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) {
1373
2067
  function _handlePageVisibility(evt) {
1374
2068
  var doc = getDocument();
1375
2069
  if (listener && doc && doc.visibilityState === "visible") {
1376
2070
  listener(evt);
1377
2071
  }
1378
2072
  }
1379
- var pageShowAdded = false;
1380
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageShow) === -1) {
1381
- pageShowAdded = addEventHandler(strPageShow, listener);
1382
- }
1383
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1384
- pageShowAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageShowAdded;
1385
- }
2073
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2074
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
2075
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
1386
2076
  if (!pageShowAdded && excludeEvents) {
1387
- pageShowAdded = addPageShowEventListener(listener);
2077
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
1388
2078
  }
1389
2079
  return pageShowAdded;
1390
2080
  }
2081
+ function removePageShowEventListener(listener, evtNamespace) {
2082
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2083
+ removeEventListeners([strPageShow], listener, newNamespaces);
2084
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2085
+ }
2086
+
1391
2087
  function perfNow() {
1392
2088
  var perf = getPerformance();
1393
2089
  if (perf && perf.now) {
@@ -1396,56 +2092,20 @@
1396
2092
  return dateNow();
1397
2093
  }
1398
2094
 
1399
- var ValueKind = {
1400
- NotSet: 0,
1401
- Pii_DistinguishedName: 1,
1402
- Pii_GenericData: 2,
1403
- Pii_IPV4Address: 3,
1404
- Pii_IPv6Address: 4,
1405
- Pii_MailSubject: 5,
1406
- Pii_PhoneNumber: 6,
1407
- Pii_QueryString: 7,
1408
- Pii_SipAddress: 8,
1409
- Pii_SmtpAddress: 9,
1410
- Pii_Identity: 10,
1411
- Pii_Uri: 11,
1412
- Pii_Fqdn: 12,
1413
- Pii_IPV4AddressLegacy: 13,
1414
- CustomerContent_GenericContent: 32
1415
- };
1416
- var EventLatency = {
1417
- Normal: 1 ,
1418
- CostDeferred: 2 ,
1419
- RealTime: 3 ,
1420
- Immediate: 4
1421
- };
1422
- var EventPropertyType = {
1423
- Unspecified: 0,
1424
- String: 1,
1425
- Int32: 2,
1426
- UInt32: 3,
1427
- Int64: 4,
1428
- UInt64: 5,
1429
- Double: 6,
1430
- Bool: 7,
1431
- Guid: 8,
1432
- DateTime: 9
1433
- };
1434
- var _ExtendedInternalMessageId = __assignFn(__assignFn({}, _InternalMessageId), { AuthHandShakeError: 501, AuthRedirectFail: 502, BrowserCannotReadLocalStorage: 503, BrowserCannotWriteLocalStorage: 504, BrowserDoesNotSupportLocalStorage: 505, CannotParseBiBlobValue: 506, CannotParseDataAttribute: 507, CVPluginNotAvailable: 508, DroppedEvent: 509, ErrorParsingAISessionCookie: 510, ErrorProvidedChannels: 511, FailedToGetCookies: 512, FailedToInitializeCorrelationVector: 513, FailedToInitializeSDK: 514, InvalidContentBlob: 515, InvalidCorrelationValue: 516, SessionRenewalDateIsZero: 517, SendPostOnCompleteFailure: 518, PostResponseHandler: 519, SDKNotInitialized: 520 });
1435
-
1436
2095
  var _a$1;
1437
- var Version = '3.1.10';
2096
+ var Version = '3.2.1';
1438
2097
  var FullVersionString = "1DS-Web-JS-" + Version;
1439
2098
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
1440
2099
  var strWithCredentials = "withCredentials";
2100
+ var strTimeout = "timeout";
1441
2101
  var _fieldTypeEventPropMap = (_a$1 = {},
1442
- _a$1[0 ] = EventPropertyType.Unspecified,
1443
- _a$1[2 ] = EventPropertyType.Double,
1444
- _a$1[1 ] = EventPropertyType.String,
1445
- _a$1[3 ] = EventPropertyType.Bool,
1446
- _a$1[4096 | 2 ] = EventPropertyType.Double,
1447
- _a$1[4096 | 1 ] = EventPropertyType.String,
1448
- _a$1[4096 | 3 ] = EventPropertyType.Bool,
2102
+ _a$1[0 ] = 0 ,
2103
+ _a$1[2 ] = 6 ,
2104
+ _a$1[1 ] = 1 ,
2105
+ _a$1[3 ] = 7 ,
2106
+ _a$1[4096 | 2 ] = 6 ,
2107
+ _a$1[4096 | 1 ] = 1 ,
2108
+ _a$1[4096 | 3 ] = 7 ,
1449
2109
  _a$1);
1450
2110
  Boolean(getDocument());
1451
2111
  var isWindowObjectAvailable = Boolean(getWindow());
@@ -1512,7 +2172,7 @@
1512
2172
  if (encodedTypeValue !== -1 && propType !== -1) {
1513
2173
  encodedTypeValue |= propType;
1514
2174
  }
1515
- else if (propType === EventPropertyType.Double) {
2175
+ else if (propType === 6 ) {
1516
2176
  encodedTypeValue = propType;
1517
2177
  }
1518
2178
  }
@@ -1558,7 +2218,7 @@
1558
2218
  }
1559
2219
  var getTime = perfNow;
1560
2220
  function isValueKind(value) {
1561
- if (value === ValueKind.NotSet || ((value > ValueKind.NotSet && value <= ValueKind.Pii_IPV4AddressLegacy) || value === ValueKind.CustomerContent_GenericContent)) {
2221
+ if (value === 0 || ((value > 0 && value <= 13 ) || value === 32 )) {
1562
2222
  return true;
1563
2223
  }
1564
2224
  return false;
@@ -1609,7 +2269,7 @@
1609
2269
  function isChromium() {
1610
2270
  return !!getGlobalInst("chrome");
1611
2271
  }
1612
- function openXhr(method, urlString, withCredentials, disabled, isSync) {
2272
+ function openXhr(method, urlString, withCredentials, disabled, isSync, timeout) {
1613
2273
  if (disabled === void 0) { disabled = false; }
1614
2274
  if (isSync === void 0) { isSync = false; }
1615
2275
  function _wrapSetXhrProp(xhr, prop, value) {
@@ -1630,6 +2290,9 @@
1630
2290
  if (withCredentials) {
1631
2291
  _wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
1632
2292
  }
2293
+ if (!isSync && timeout) {
2294
+ _wrapSetXhrProp(xhr, strTimeout, timeout);
2295
+ }
1633
2296
  return xhr;
1634
2297
  }
1635
2298
 
@@ -1658,6 +2321,8 @@
1658
2321
  var strUploadTime = "upload-time";
1659
2322
  var strApiKey = "apikey";
1660
2323
  var strMsaDeviceTicket = "AuthMsaDeviceTicket";
2324
+ var strAuthXToken = "AuthXToken";
2325
+ var strNoResponseBody = "NoResponseBody";
1661
2326
  var strMsfpc = "msfpc";
1662
2327
 
1663
2328
  function _getEventMsfpc(theEvent) {
@@ -1969,25 +2634,19 @@
1969
2634
  var RandomizationUpperThreshold = 1.2;
1970
2635
  var BaseBackoff = 3000;
1971
2636
  var MaxBackoff = 600000;
1972
- var RetryPolicy = /** @class */ (function () {
1973
- function RetryPolicy() {
1974
- }
1975
- RetryPolicy.shouldRetryForStatus = function (httpStatusCode) {
1976
- return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
1977
- || (httpStatusCode == 501)
1978
- || (httpStatusCode == 505));
1979
- };
1980
- RetryPolicy.getMillisToBackoffForRetry = function (retriesSoFar) {
1981
- var waitDuration = 0;
1982
- var minBackoff = BaseBackoff * RandomizationLowerThreshold;
1983
- var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
1984
- var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
1985
- waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
1986
- return Math.min(waitDuration, MaxBackoff);
1987
- };
1988
- return RetryPolicy;
1989
- }());
1990
- var RetryPolicy$1 = RetryPolicy;
2637
+ function retryPolicyShouldRetryForStatus(httpStatusCode) {
2638
+ return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
2639
+ || (httpStatusCode == 501)
2640
+ || (httpStatusCode == 505));
2641
+ }
2642
+ function retryPolicyGetMillisToBackoffForRetry(retriesSoFar) {
2643
+ var waitDuration = 0;
2644
+ var minBackoff = BaseBackoff * RandomizationLowerThreshold;
2645
+ var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
2646
+ var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
2647
+ waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
2648
+ return Math.min(waitDuration, MaxBackoff);
2649
+ }
1991
2650
 
1992
2651
  var SecToMsMultiplier = 1000;
1993
2652
  var KillSwitch = /** @class */ (function () {
@@ -2081,6 +2740,8 @@
2081
2740
  var EVTClockSkewManager = ClockSkewManager;
2082
2741
 
2083
2742
  var _a;
2743
+ var strSendAttempt = "sendAttempt";
2744
+ var _noResponseQs = "&" + strNoResponseBody + "=true";
2084
2745
  var _eventActionMap = (_a = {},
2085
2746
  _a[1 ] = strRequeue,
2086
2747
  _a[100 ] = strRequeue,
@@ -2090,11 +2751,19 @@
2090
2751
  _a);
2091
2752
  var _collectorQsHeaders = {};
2092
2753
  var _collectorHeaderToQs = {};
2093
- function _addCollectorHeaderQsMapping(qsName, headerName) {
2754
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
2094
2755
  _collectorQsHeaders[qsName] = headerName;
2095
- _collectorHeaderToQs[headerName] = qsName;
2756
+ if (allowQs !== false) {
2757
+ _collectorHeaderToQs[headerName] = qsName;
2758
+ }
2096
2759
  }
2097
- _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);
2760
+ _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);
2761
+ _addCollectorHeaderQsMapping(strClientVersion, strClientVersion);
2762
+ _addCollectorHeaderQsMapping(strClientId, "Client-Id");
2763
+ _addCollectorHeaderQsMapping(strApiKey, strApiKey);
2764
+ _addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
2765
+ _addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
2766
+ _addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
2098
2767
  function _getResponseText(xhr) {
2099
2768
  try {
2100
2769
  return xhr.responseText;
@@ -2133,7 +2802,7 @@
2133
2802
  }
2134
2803
  }
2135
2804
  var HttpManager = /** @class */ (function () {
2136
- function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {
2805
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
2137
2806
  this._responseHandlers = [];
2138
2807
  var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
2139
2808
  var _killSwitch = new EVTKillSwitch();
@@ -2153,6 +2822,8 @@
2153
2822
  var _cookieMgr;
2154
2823
  var _isUnloading = false;
2155
2824
  var _useHeaders = false;
2825
+ var _xhrTimeout;
2826
+ var _disableXhrSync;
2156
2827
  dynamicProto(HttpManager, this, function (_self) {
2157
2828
  var _sendCredentials = true;
2158
2829
  _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
@@ -2161,7 +2832,7 @@
2161
2832
  channelConfig = {};
2162
2833
  }
2163
2834
  _urlString = endpointUrl + _urlString;
2164
- _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
2835
+ _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
2165
2836
  _core = core;
2166
2837
  _cookieMgr = core.getCookieMgr();
2167
2838
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -2172,9 +2843,13 @@
2172
2843
  if (!isUndefined(channelConfig.enableCompoundKey)) {
2173
2844
  enableCompoundKey = !!channelConfig.enableCompoundKey;
2174
2845
  }
2846
+ _xhrTimeout = channelConfig.xhrTimeout;
2847
+ _disableXhrSync = channelConfig.disableXhrSync;
2175
2848
  _useBeacons = !isReactNative();
2176
2849
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
2177
2850
  var syncHttpInterface = httpInterface;
2851
+ var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
2852
+ var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
2178
2853
  if (!httpInterface) {
2179
2854
  _customHttpInterface = false;
2180
2855
  var location_1 = getLocation();
@@ -2206,8 +2881,8 @@
2206
2881
  _sendInterfaces = (_a = {},
2207
2882
  _a[0 ] = httpInterface,
2208
2883
  _a[1 ] = syncHttpInterface || _getSenderInterface([1 , 2 , 3 ], true),
2209
- _a[2 ] = _getSenderInterface([3 , 2 , 1 ], true) || syncHttpInterface,
2210
- _a[3 ] = _getSenderInterface([2 , 3 , 1 ], true) || syncHttpInterface,
2884
+ _a[2 ] = beaconHttpInterface || _getSenderInterface([3 , 2 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
2885
+ _a[3 ] = fetchSyncHttpInterface || _getSenderInterface([2 , 3 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
2211
2886
  _a);
2212
2887
  };
2213
2888
  function _getSenderInterface(transports, syncSupport) {
@@ -2247,6 +2922,9 @@
2247
2922
  function _xdrSendPost(payload, oncomplete, sync) {
2248
2923
  var xdr = new XDomainRequest();
2249
2924
  xdr.open(Method, payload.urlString);
2925
+ if (payload.timeout) {
2926
+ xdr.timeout = payload.timeout;
2927
+ }
2250
2928
  xdr.onload = function () {
2251
2929
  var response = _getResponseText(xdr);
2252
2930
  _doOnComplete(oncomplete, 200, {}, response);
@@ -2270,6 +2948,7 @@
2270
2948
  }
2271
2949
  function _fetchSendPost(payload, oncomplete, sync) {
2272
2950
  var _a;
2951
+ var theUrl = payload.urlString;
2273
2952
  var ignoreResponse = false;
2274
2953
  var responseHandled = false;
2275
2954
  var requestInit = (_a = {
@@ -2282,6 +2961,7 @@
2282
2961
  requestInit.keepalive = true;
2283
2962
  if (payload._sendReason === 2 ) {
2284
2963
  ignoreResponse = true;
2964
+ theUrl += _noResponseQs;
2285
2965
  }
2286
2966
  }
2287
2967
  if (_sendCredentials) {
@@ -2290,7 +2970,7 @@
2290
2970
  if (payload.headers && objKeys(payload.headers).length > 0) {
2291
2971
  requestInit.headers = payload.headers;
2292
2972
  }
2293
- fetch(payload.urlString, requestInit).then(function (response) {
2973
+ fetch(theUrl, requestInit).then(function (response) {
2294
2974
  var headerMap = {};
2295
2975
  var responseText = "";
2296
2976
  if (response.headers) {
@@ -2318,8 +2998,17 @@
2318
2998
  responseHandled = true;
2319
2999
  _doOnComplete(oncomplete, 200, {});
2320
3000
  }
3001
+ if (!responseHandled && payload.timeout > 0) {
3002
+ _postManager._setTimeoutOverride(function () {
3003
+ if (!responseHandled) {
3004
+ responseHandled = true;
3005
+ _doOnComplete(oncomplete, 500, {});
3006
+ }
3007
+ }, payload.timeout);
3008
+ }
2321
3009
  }
2322
3010
  function _xhrSendPost(payload, oncomplete, sync) {
3011
+ var theUrl = payload.urlString;
2323
3012
  function _appendHeader(theHeaders, xhr, name) {
2324
3013
  if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
2325
3014
  var value = xhr.getResponseHeader(name);
@@ -2344,45 +3033,49 @@
2344
3033
  function xhrComplete(xhr, responseTxt) {
2345
3034
  _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
2346
3035
  }
2347
- var xhRequest = openXhr(Method, payload.urlString, _sendCredentials, true, sync);
3036
+ if (sync && payload.disableXhrSync) {
3037
+ sync = false;
3038
+ }
3039
+ var xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);
2348
3040
  objForEachKey(payload.headers, function (name, value) {
2349
- xhRequest.setRequestHeader(name, value);
3041
+ xhrRequest.setRequestHeader(name, value);
2350
3042
  });
2351
- xhRequest.onload = function () {
2352
- var response = _getResponseText(xhRequest);
2353
- xhrComplete(xhRequest, response);
3043
+ xhrRequest.onload = function () {
3044
+ var response = _getResponseText(xhrRequest);
3045
+ xhrComplete(xhrRequest, response);
2354
3046
  _handleCollectorResponse(response);
2355
3047
  };
2356
- xhRequest.onerror = function () {
2357
- xhrComplete(xhRequest);
3048
+ xhrRequest.onerror = function () {
3049
+ xhrComplete(xhrRequest);
2358
3050
  };
2359
- xhRequest.ontimeout = function () {
2360
- xhrComplete(xhRequest);
3051
+ xhrRequest.ontimeout = function () {
3052
+ xhrComplete(xhrRequest);
2361
3053
  };
2362
- xhRequest.send(payload.data);
3054
+ xhrRequest.send(payload.data);
2363
3055
  }
2364
3056
  function _doOnComplete(oncomplete, status, headers, response) {
2365
3057
  try {
2366
3058
  oncomplete(status, headers, response);
2367
3059
  }
2368
3060
  catch (e) {
2369
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));
3061
+ _throwInternal(_postManager.diagLog(), 2 , 518 , dumpObj(e));
2370
3062
  }
2371
3063
  }
2372
3064
  function _beaconSendPost(payload, oncomplete, sync) {
2373
3065
  var internalPayloadData = payload;
2374
3066
  var status = 200;
2375
3067
  var thePayload = internalPayloadData._thePayload;
3068
+ var theUrl = payload.urlString + _noResponseQs;
2376
3069
  try {
2377
3070
  var nav_1 = getNavigator();
2378
- if (!nav_1.sendBeacon(payload.urlString, payload.data)) {
3071
+ if (!nav_1.sendBeacon(theUrl, payload.data)) {
2379
3072
  if (thePayload) {
2380
3073
  var droppedBatches_1 = [];
2381
3074
  arrForEach(thePayload.batches, function (theBatch) {
2382
3075
  if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
2383
3076
  var theEvents = theBatch.events();
2384
3077
  for (var lp = 0; lp < theEvents.length; lp++) {
2385
- if (!nav_1.sendBeacon(payload.urlString, _serializer.getEventBlob(theEvents[lp]))) {
3078
+ if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
2386
3079
  droppedBatches_1.push(theBatch.split(lp));
2387
3080
  break;
2388
3081
  }
@@ -2400,7 +3093,7 @@
2400
3093
  }
2401
3094
  }
2402
3095
  catch (ex) {
2403
- _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + ex);
3096
+ _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
2404
3097
  status = 0;
2405
3098
  }
2406
3099
  finally {
@@ -2564,7 +3257,7 @@
2564
3257
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
2565
3258
  }
2566
3259
  catch (ex) {
2567
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + dumpObj(ex));
3260
+ _throwInternal(_postManager.diagLog(), 2 , 48 , "Unexpected Exception sending batch: " + dumpObj(ex));
2568
3261
  }
2569
3262
  }
2570
3263
  function _buildRequestDetails(thePayload, useHeaders) {
@@ -2573,8 +3266,21 @@
2573
3266
  hdrs: {},
2574
3267
  useHdrs: false
2575
3268
  };
2576
- requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
2577
- requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
3269
+ if (!useHeaders) {
3270
+ objForEachKey(_headers, function (name, value) {
3271
+ if (_collectorHeaderToQs[name]) {
3272
+ _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
3273
+ }
3274
+ else {
3275
+ requestDetails.hdrs[name] = value;
3276
+ requestDetails.useHdrs = true;
3277
+ }
3278
+ });
3279
+ }
3280
+ else {
3281
+ requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
3282
+ requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
3283
+ }
2578
3284
  _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
2579
3285
  _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
2580
3286
  var apiQsKeys = "";
@@ -2625,7 +3331,6 @@
2625
3331
  var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
2626
3332
  useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
2627
3333
  var sendEventStart_1 = getTime();
2628
- var strSendAttempt_1 = "sendAttempt";
2629
3334
  doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
2630
3335
  for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
2631
3336
  var theBatch = thePayload.batches[batchLp];
@@ -2638,7 +3343,7 @@
2638
3343
  _setTimingValue(timings, "serializationStart", serializationStart);
2639
3344
  _setTimingValue(timings, "serializationCompleted", serializationCompleted);
2640
3345
  }
2641
- telemetryItem[strSendAttempt_1] > 0 ? telemetryItem[strSendAttempt_1]++ : telemetryItem[strSendAttempt_1] = 1;
3346
+ telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
2642
3347
  }
2643
3348
  }
2644
3349
  _sendBatchesNotification(thePayload.batches, (1000 + (sendReason || 0 )), thePayload.sendType, true);
@@ -2647,8 +3352,12 @@
2647
3352
  urlString: requestDetails_1.url,
2648
3353
  headers: requestDetails_1.hdrs,
2649
3354
  _thePayload: thePayload,
2650
- _sendReason: sendReason
3355
+ _sendReason: sendReason,
3356
+ timeout: _xhrTimeout
2651
3357
  };
3358
+ if (!isUndefined(_disableXhrSync)) {
3359
+ orgPayloadData.disableXhrSync = !!_disableXhrSync;
3360
+ }
2652
3361
  if (useHeaders_1) {
2653
3362
  if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
2654
3363
  orgPayloadData.headers[strCacheControl] = defaultCacheControl;
@@ -2686,7 +3395,9 @@
2686
3395
  var hookData_1 = {
2687
3396
  data: orgPayloadData.data,
2688
3397
  urlString: orgPayloadData.urlString,
2689
- headers: extend({}, orgPayloadData.headers)
3398
+ headers: extend({}, orgPayloadData.headers),
3399
+ timeout: orgPayloadData.timeout,
3400
+ disableXhrSync: orgPayloadData.disableXhrSync
2690
3401
  };
2691
3402
  var senderCalled_1 = false;
2692
3403
  doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
@@ -2751,11 +3462,11 @@
2751
3462
  });
2752
3463
  });
2753
3464
  }
2754
- if (status == 200) {
3465
+ if (status == 200 || status == 204) {
2755
3466
  reason = 200 ;
2756
3467
  return;
2757
3468
  }
2758
- if (!RetryPolicy$1.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
3469
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
2759
3470
  shouldRetry = false;
2760
3471
  }
2761
3472
  reason = 9000 + (status % 1000);
@@ -2764,17 +3475,20 @@
2764
3475
  reason = 100 ;
2765
3476
  var retryCount_1 = thePayload.retryCnt;
2766
3477
  if (thePayload.sendType === 0 ) {
2767
- if (retryCount_1 < maxRetries) {
3478
+ if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
2768
3479
  isRetrying = true;
2769
3480
  _doAction(function () {
2770
3481
  if (thePayload.sendType === 0 ) {
2771
3482
  _outstandingRequests--;
2772
3483
  }
2773
3484
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
2774
- }, _isUnloading, RetryPolicy$1.getMillisToBackoffForRetry(retryCount_1));
3485
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
2775
3486
  }
2776
3487
  else {
2777
3488
  backOffTrans = true;
3489
+ if (_isUnloading) {
3490
+ reason = 8001 ;
3491
+ }
2778
3492
  }
2779
3493
  }
2780
3494
  }
@@ -2864,7 +3578,7 @@
2864
3578
  responseHandlers[i](responseText);
2865
3579
  }
2866
3580
  catch (e) {
2867
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
3581
+ _throwInternal(_postManager.diagLog(), 1 , 519 , "Response handler failed: " + e);
2868
3582
  }
2869
3583
  }
2870
3584
  if (responseText) {
@@ -2888,7 +3602,7 @@
2888
3602
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
2889
3603
  }
2890
3604
  catch (e) {
2891
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, "send request notification failed: " + e);
3605
+ _throwInternal(_postManager.diagLog(), 1 , 74 , "send request notification failed: " + e);
2892
3606
  }
2893
3607
  }, sendSync || isSyncRequest_1, 0);
2894
3608
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
@@ -2920,19 +3634,23 @@
2920
3634
  var MaxNumberEventPerBatch = 500;
2921
3635
  var EventsDroppedAtOneTime = 20;
2922
3636
  var MaxSendAttempts = 6;
3637
+ var MaxSyncUnloadSendAttempts = 2;
2923
3638
  var MaxBackoffCount = 4;
2924
3639
  var globalContext = isWindowObjectAvailable ? window : undefined;
2925
3640
  var MaxConnections = 2;
2926
- var MaxRetries = 1;
3641
+ var MaxRequestRetriesBeforeBackoff = 1;
2927
3642
  var strEventsDiscarded = "eventsDiscarded";
2928
3643
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
3644
+ var strMaxEventRetryAttempts = "maxEventRetryAttempts";
3645
+ var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
3646
+ var strAddUnloadCb = "addUnloadCb";
2929
3647
  var PostChannel = /** @class */ (function (_super) {
2930
3648
  __extendsFn(PostChannel, _super);
2931
3649
  function PostChannel() {
2932
3650
  var _this = _super.call(this) || this;
2933
3651
  _this.identifier = "PostChannel";
2934
3652
  _this.priority = 1011;
2935
- _this.version = '3.1.10';
3653
+ _this.version = '3.2.1';
2936
3654
  var _config;
2937
3655
  var _isTeardownCalled = false;
2938
3656
  var _flushCallbackQueue = [];
@@ -2957,18 +3675,12 @@
2957
3675
  var _delayedBatchReason;
2958
3676
  var _optimizeObject = true;
2959
3677
  var _isPageUnloadTriggered = false;
3678
+ var _disableXhrSync = false;
3679
+ var _maxEventSendAttempts = MaxSendAttempts;
3680
+ var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
3681
+ var _evtNamespace;
2960
3682
  dynamicProto(PostChannel, _this, function (_self, _base) {
2961
- _initializeProfiles();
2962
- _clearQueues();
2963
- _setAutoLimits();
2964
- _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
2965
- requeue: _requeueEvents,
2966
- send: _sendingEvent,
2967
- sent: _eventsSentEvent,
2968
- drop: _eventsDropped,
2969
- rspFail: _eventsResponseFail,
2970
- oth: _otherEvent
2971
- });
3683
+ _initDefaults();
2972
3684
  _self["_getDbgPlgTargets"] = function () {
2973
3685
  return [_httpManager];
2974
3686
  };
@@ -2976,58 +3688,53 @@
2976
3688
  doPerf(core, function () { return "PostChannel:initialize"; }, function () {
2977
3689
  var extendedCore = core;
2978
3690
  _base.initialize(coreConfig, core, extensions);
2979
- _self.setInitialized(false);
2980
- var ctx = _self._getTelCtx();
2981
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
2982
- _config = ctx.getExtCfg(_self.identifier);
2983
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
2984
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
2985
- _optimizeObject = !_config.disableOptimizeObj && isChromium();
2986
- var existingGetWParamMethod = extendedCore.getWParam;
2987
- extendedCore.getWParam = function () {
2988
- var wparam = 0;
2989
- if (_config.ignoreMc1Ms0CookieProcessing) {
2990
- wparam = wparam | 2;
2991
- }
2992
- return wparam | existingGetWParamMethod();
2993
- };
2994
- if (_config.eventsLimitInMem > 0) {
2995
- _queueSizeLimit = _config.eventsLimitInMem;
2996
- }
2997
- if (_config.immediateEventLimit > 0) {
2998
- _immediateQueueSizeLimit = _config.immediateEventLimit;
2999
- }
3000
- if (_config.autoFlushEventsLimit > 0) {
3001
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3002
- }
3003
- _setAutoLimits();
3004
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
3005
- _xhrOverride = _config.httpXHROverride;
3006
- }
3007
- if (isValueAssigned(coreConfig.anonCookieName)) {
3008
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
3009
- }
3010
- _httpManager.sendHook = _config.payloadPreprocessor;
3011
- _httpManager.sendListener = _config.payloadListener;
3012
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
3013
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
3014
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
3015
- function _handleUnloadEvents(evt) {
3016
- var theEvt = evt || getWindow().event;
3017
- if (theEvt.type !== "beforeunload") {
3018
- _isPageUnloadTriggered = true;
3019
- _httpManager.setUnloading(_isPageUnloadTriggered);
3691
+ try {
3692
+ var hasAddUnloadCb = !!core[strAddUnloadCb];
3693
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
3694
+ var ctx = _self._getTelCtx();
3695
+ coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
3696
+ _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);
3699
+ _optimizeObject = !_config.disableOptimizeObj && isChromium();
3700
+ _hookWParam(extendedCore);
3701
+ if (_config.eventsLimitInMem > 0) {
3702
+ _queueSizeLimit = _config.eventsLimitInMem;
3020
3703
  }
3021
- _releaseAllQueues(2 , 2 );
3704
+ if (_config.immediateEventLimit > 0) {
3705
+ _immediateQueueSizeLimit = _config.immediateEventLimit;
3706
+ }
3707
+ if (_config.autoFlushEventsLimit > 0) {
3708
+ _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3709
+ }
3710
+ _disableXhrSync = _config.disableXhrSync;
3711
+ if (isNumber(_config[strMaxEventRetryAttempts])) {
3712
+ _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
3713
+ }
3714
+ if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
3715
+ _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
3716
+ }
3717
+ _setAutoLimits();
3718
+ if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
3719
+ _xhrOverride = _config.httpXHROverride;
3720
+ }
3721
+ if (isValueAssigned(coreConfig.anonCookieName)) {
3722
+ _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
3723
+ }
3724
+ _httpManager.sendHook = _config.payloadPreprocessor;
3725
+ _httpManager.sendListener = _config.payloadListener;
3726
+ var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
3727
+ _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
3728
+ _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
3729
+ var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
3730
+ addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
3731
+ addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
3732
+ addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
3733
+ }
3734
+ catch (e) {
3735
+ _self.setInitialized(false);
3736
+ throw e;
3022
3737
  }
3023
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
3024
- addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
3025
- addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
3026
- addPageShowEventListener(function (evt) {
3027
- _isPageUnloadTriggered = false;
3028
- _httpManager.setUnloading(_isPageUnloadTriggered);
3029
- }, coreConfig.disablePageShowEvents);
3030
- _self.setInitialized(true);
3031
3738
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
3032
3739
  };
3033
3740
  _self.processTelemetry = function (ev, itemCtx) {
@@ -3056,12 +3763,43 @@
3056
3763
  }
3057
3764
  _self.processNext(event, itemCtx);
3058
3765
  };
3766
+ _self._doTeardown = function (unloadCtx, unloadState) {
3767
+ _releaseAllQueues(2 , 2 );
3768
+ _isTeardownCalled = true;
3769
+ _httpManager.teardown();
3770
+ removePageUnloadEventListener(null, _evtNamespace);
3771
+ removePageHideEventListener(null, _evtNamespace);
3772
+ removePageShowEventListener(null, _evtNamespace);
3773
+ _initDefaults();
3774
+ };
3775
+ function _hookWParam(extendedCore) {
3776
+ var existingGetWParamMethod = extendedCore.getWParam;
3777
+ extendedCore.getWParam = function () {
3778
+ var wparam = 0;
3779
+ if (_config.ignoreMc1Ms0CookieProcessing) {
3780
+ wparam = wparam | 2;
3781
+ }
3782
+ return wparam | existingGetWParamMethod();
3783
+ };
3784
+ }
3785
+ function _handleUnloadEvents(evt) {
3786
+ var theEvt = evt || getWindow().event;
3787
+ if (theEvt.type !== "beforeunload") {
3788
+ _isPageUnloadTriggered = true;
3789
+ _httpManager.setUnloading(_isPageUnloadTriggered);
3790
+ }
3791
+ _releaseAllQueues(2 , 2 );
3792
+ }
3793
+ function _handleShowEvents(evt) {
3794
+ _isPageUnloadTriggered = false;
3795
+ _httpManager.setUnloading(_isPageUnloadTriggered);
3796
+ }
3059
3797
  function _addEventToQueues(event, append) {
3060
3798
  if (!event.sendAttempt) {
3061
3799
  event.sendAttempt = 0;
3062
3800
  }
3063
3801
  if (!event.latency) {
3064
- event.latency = EventLatency.Normal;
3802
+ event.latency = 1 ;
3065
3803
  }
3066
3804
  if (event.ext && event.ext["trace"]) {
3067
3805
  delete (event.ext["trace"]);
@@ -3080,7 +3818,7 @@
3080
3818
  }
3081
3819
  if (event.sync) {
3082
3820
  if (_currentBackoffCount || _paused) {
3083
- event.latency = EventLatency.RealTime;
3821
+ event.latency = 3 ;
3084
3822
  event.sync = false;
3085
3823
  }
3086
3824
  else {
@@ -3096,7 +3834,7 @@
3096
3834
  var evtLatency = event.latency;
3097
3835
  var queueSize = _queueSize;
3098
3836
  var queueLimit = _queueSizeLimit;
3099
- if (evtLatency === EventLatency.Immediate) {
3837
+ if (evtLatency === 4 ) {
3100
3838
  queueSize = _immediateQueueSize;
3101
3839
  queueLimit = _immediateQueueSizeLimit;
3102
3840
  }
@@ -3105,10 +3843,10 @@
3105
3843
  eventDropped = !_addEventToProperQueue(event, append);
3106
3844
  }
3107
3845
  else {
3108
- var dropLatency = EventLatency.Normal;
3846
+ var dropLatency = 1 ;
3109
3847
  var dropNumber = EventsDroppedAtOneTime;
3110
- if (evtLatency === EventLatency.Immediate) {
3111
- dropLatency = EventLatency.Immediate;
3848
+ if (evtLatency === 4 ) {
3849
+ dropLatency = 4 ;
3112
3850
  dropNumber = 1;
3113
3851
  }
3114
3852
  eventDropped = true;
@@ -3126,7 +3864,7 @@
3126
3864
  _setAutoLimits();
3127
3865
  var doFlush = _queueSize > eventLimit;
3128
3866
  if (!doFlush && _autoFlushBatchLimit > 0) {
3129
- for (var latency = EventLatency.Normal; !doFlush && latency <= EventLatency.RealTime; latency++) {
3867
+ for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
3130
3868
  var batchQueue = _batchQueues[latency];
3131
3869
  if (batchQueue && batchQueue.batches) {
3132
3870
  arrForEach(batchQueue.batches, function (theBatch) {
@@ -3139,11 +3877,6 @@
3139
3877
  }
3140
3878
  _performAutoFlush(true, doFlush);
3141
3879
  };
3142
- _self.teardown = function () {
3143
- _releaseAllQueues(2 , 2 );
3144
- _isTeardownCalled = true;
3145
- _httpManager.teardown();
3146
- };
3147
3880
  _self.pause = function () {
3148
3881
  _clearScheduledTimer();
3149
3882
  _paused = true;
@@ -3185,7 +3918,7 @@
3185
3918
  _clearScheduledTimer();
3186
3919
  sendReason = sendReason || 1 ;
3187
3920
  if (async) {
3188
- _queueBatches(EventLatency.Normal, 0 , sendReason);
3921
+ _queueBatches(1 , 0 , sendReason);
3189
3922
  _resetQueueCounts();
3190
3923
  if (_flushCallbackTimerId == null) {
3191
3924
  _flushCallbackTimerId = _createTimer(function () {
@@ -3197,7 +3930,7 @@
3197
3930
  }
3198
3931
  }
3199
3932
  else {
3200
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 1 , sendReason);
3933
+ _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
3201
3934
  if (callback !== null && callback !== undefined) {
3202
3935
  callback();
3203
3936
  }
@@ -3232,7 +3965,7 @@
3232
3965
  if (immediateTimeOut >= 0) {
3233
3966
  _immediateTimerId = _createTimer(function () {
3234
3967
  _immediateTimerId = null;
3235
- _sendEventsForLatencyAndAbove(EventLatency.Immediate, 0 , 1 );
3968
+ _sendEventsForLatencyAndAbove(4 , 0 , 1 );
3236
3969
  _scheduleTimer();
3237
3970
  }, immediateTimeOut);
3238
3971
  }
@@ -3242,7 +3975,7 @@
3242
3975
  if (_hasEvents()) {
3243
3976
  _scheduledTimerId = _createTimer(function () {
3244
3977
  _scheduledTimerId = null;
3245
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? EventLatency.RealTime : EventLatency.Normal, 0 , 1 );
3978
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
3246
3979
  _timerCount++;
3247
3980
  _timerCount %= 2;
3248
3981
  _scheduleTimer();
@@ -3267,13 +4000,53 @@
3267
4000
  _scheduleTimer();
3268
4001
  }
3269
4002
  };
4003
+ function _initDefaults() {
4004
+ _config = null;
4005
+ _isTeardownCalled = false;
4006
+ _flushCallbackQueue = [];
4007
+ _flushCallbackTimerId = null;
4008
+ _paused = false;
4009
+ _immediateQueueSize = 0;
4010
+ _immediateQueueSizeLimit = 500;
4011
+ _queueSize = 0;
4012
+ _queueSizeLimit = 10000;
4013
+ _profiles = {};
4014
+ _currentProfile = RT_PROFILE;
4015
+ _scheduledTimerId = null;
4016
+ _immediateTimerId = null;
4017
+ _currentBackoffCount = 0;
4018
+ _timerCount = 0;
4019
+ _xhrOverride = null;
4020
+ _batchQueues = {};
4021
+ _autoFlushEventsLimit = undefined;
4022
+ _autoFlushBatchLimit = 0;
4023
+ _delayedBatchSendLatency = -1;
4024
+ _delayedBatchReason = null;
4025
+ _optimizeObject = true;
4026
+ _isPageUnloadTriggered = false;
4027
+ _disableXhrSync = false;
4028
+ _maxEventSendAttempts = MaxSendAttempts;
4029
+ _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
4030
+ _evtNamespace = null;
4031
+ _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
4032
+ requeue: _requeueEvents,
4033
+ send: _sendingEvent,
4034
+ sent: _eventsSentEvent,
4035
+ drop: _eventsDropped,
4036
+ rspFail: _eventsResponseFail,
4037
+ oth: _otherEvent
4038
+ });
4039
+ _initializeProfiles();
4040
+ _clearQueues();
4041
+ _setAutoLimits();
4042
+ }
3270
4043
  function _createTimer(theTimerFunc, timeOut) {
3271
4044
  if (timeOut === 0 && _currentBackoffCount) {
3272
4045
  timeOut = 1;
3273
4046
  }
3274
4047
  var timerMultiplier = 1000;
3275
4048
  if (_currentBackoffCount) {
3276
- timerMultiplier = RetryPolicy$1.getMillisToBackoffForRetry(_currentBackoffCount - 1);
4049
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
3277
4050
  }
3278
4051
  return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
3279
4052
  }
@@ -3291,23 +4064,23 @@
3291
4064
  _flushCallbackTimerId = null;
3292
4065
  }
3293
4066
  if (!_paused) {
3294
- _sendEventsForLatencyAndAbove(EventLatency.Normal, sendType, sendReason);
4067
+ _sendEventsForLatencyAndAbove(1 , sendType, sendReason);
3295
4068
  }
3296
4069
  }
3297
4070
  function _clearQueues() {
3298
- _batchQueues[EventLatency.Immediate] = {
4071
+ _batchQueues[4 ] = {
3299
4072
  batches: [],
3300
4073
  iKeyMap: {}
3301
4074
  };
3302
- _batchQueues[EventLatency.RealTime] = {
4075
+ _batchQueues[3 ] = {
3303
4076
  batches: [],
3304
4077
  iKeyMap: {}
3305
4078
  };
3306
- _batchQueues[EventLatency.CostDeferred] = {
4079
+ _batchQueues[2 ] = {
3307
4080
  batches: [],
3308
4081
  iKeyMap: {}
3309
4082
  };
3310
- _batchQueues[EventLatency.Normal] = {
4083
+ _batchQueues[1 ] = {
3311
4084
  batches: [],
3312
4085
  iKeyMap: {}
3313
4086
  };
@@ -3315,7 +4088,7 @@
3315
4088
  function _getEventBatch(iKey, latency, create) {
3316
4089
  var batchQueue = _batchQueues[latency];
3317
4090
  if (!batchQueue) {
3318
- latency = EventLatency.Normal;
4091
+ latency = 1 ;
3319
4092
  batchQueue = _batchQueues[latency];
3320
4093
  }
3321
4094
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -3343,7 +4116,7 @@
3343
4116
  var latency = event.latency;
3344
4117
  var eventBatch = _getEventBatch(event.iKey, latency, true);
3345
4118
  if (eventBatch.addEvent(event)) {
3346
- if (latency !== EventLatency.Immediate) {
4119
+ if (latency !== 4 ) {
3347
4120
  _queueSize++;
3348
4121
  if (append && event.sendAttempt === 0) {
3349
4122
  _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
@@ -3363,7 +4136,7 @@
3363
4136
  var droppedEvents = eventBatch.split(0, dropNumber);
3364
4137
  var droppedCount = droppedEvents.count();
3365
4138
  if (droppedCount > 0) {
3366
- if (currentLatency === EventLatency.Immediate) {
4139
+ if (currentLatency === 4 ) {
3367
4140
  _immediateQueueSize -= droppedCount;
3368
4141
  }
3369
4142
  else {
@@ -3385,7 +4158,7 @@
3385
4158
  var batchQueue = _batchQueues[latency];
3386
4159
  if (batchQueue && batchQueue.batches) {
3387
4160
  arrForEach(batchQueue.batches, function (theBatch) {
3388
- if (latency === EventLatency.Immediate) {
4161
+ if (latency === 4 ) {
3389
4162
  immediateQueue += theBatch.count();
3390
4163
  }
3391
4164
  else {
@@ -3394,7 +4167,7 @@
3394
4167
  });
3395
4168
  }
3396
4169
  };
3397
- for (var latency = EventLatency.Normal; latency <= EventLatency.Immediate; latency++) {
4170
+ for (var latency = 1 ; latency <= 4 ; latency++) {
3398
4171
  _loop_1(latency);
3399
4172
  }
3400
4173
  _queueSize = normalQueue;
@@ -3406,7 +4179,7 @@
3406
4179
  if (!isAsync || _httpManager.canSendRequest()) {
3407
4180
  doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
3408
4181
  var droppedEvents = [];
3409
- var latencyToProcess = EventLatency.Immediate;
4182
+ var latencyToProcess = 4 ;
3410
4183
  while (latencyToProcess >= latency) {
3411
4184
  var batchQueue = _batchQueues[latencyToProcess];
3412
4185
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -3417,7 +4190,7 @@
3417
4190
  else {
3418
4191
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
3419
4192
  }
3420
- if (latencyToProcess === EventLatency.Immediate) {
4193
+ if (latencyToProcess === 4 ) {
3421
4194
  _immediateQueueSize -= theBatch.count();
3422
4195
  }
3423
4196
  else {
@@ -3445,7 +4218,7 @@
3445
4218
  return eventsQueued;
3446
4219
  }
3447
4220
  function _flushImpl(callback, sendReason) {
3448
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 0 , sendReason);
4221
+ _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
3449
4222
  _waitForIdleManager(function () {
3450
4223
  if (callback) {
3451
4224
  callback();
@@ -3485,15 +4258,19 @@
3485
4258
  }
3486
4259
  function _requeueEvents(batches, reason) {
3487
4260
  var droppedEvents = [];
4261
+ var maxSendAttempts = _maxEventSendAttempts;
4262
+ if (_isPageUnloadTriggered) {
4263
+ maxSendAttempts = _maxUnloadEventSendAttempts;
4264
+ }
3488
4265
  arrForEach(batches, function (theBatch) {
3489
4266
  if (theBatch && theBatch.count() > 0) {
3490
4267
  arrForEach(theBatch.events(), function (theEvent) {
3491
4268
  if (theEvent) {
3492
4269
  if (theEvent.sync) {
3493
- theEvent.latency = EventLatency.Immediate;
4270
+ theEvent.latency = 4 ;
3494
4271
  theEvent.sync = false;
3495
4272
  }
3496
- if (theEvent.sendAttempt < MaxSendAttempts) {
4273
+ if (theEvent.sendAttempt < maxSendAttempts) {
3497
4274
  setProcessTelemetryTimings(theEvent, _self.identifier);
3498
4275
  _addEventToQueues(theEvent, false);
3499
4276
  }
@@ -3519,7 +4296,7 @@
3519
4296
  notifyFunc.apply(manager, theArgs);
3520
4297
  }
3521
4298
  catch (e) {
3522
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
4299
+ _throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
3523
4300
  }
3524
4301
  }
3525
4302
  }