@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
  */
@@ -62,18 +62,6 @@
62
62
 
63
63
  (getGlobal() || {})["Symbol"];
64
64
  (getGlobal() || {})["Reflect"];
65
- var __objAssignFnImpl = function (t) {
66
- for (var s, i = 1, n = arguments.length; i < n; i++) {
67
- s = arguments[i];
68
- for (var p in s) {
69
- if (ObjProto[strShimHasOwnProperty].call(s, p)) {
70
- t[p] = s[p];
71
- }
72
- }
73
- }
74
- return t;
75
- };
76
- var __assignFn = ObjAssign || __objAssignFnImpl;
77
65
  var extendStaticsFn = function (d, b) {
78
66
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
79
67
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -95,14 +83,356 @@
95
83
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
96
84
  }
97
85
 
98
- var EventsDiscardedReason = {
99
- Unknown: 0,
100
- NonRetryableStatus: 1,
101
- InvalidEvent: 2,
102
- SizeLimitExceeded: 3,
103
- KillSwitch: 4,
86
+ var strEmpty = "";
87
+ var strSetNextPlugin = "setNextPlugin";
88
+ var strIsInitialized = "isInitialized";
89
+ var strTeardown = "teardown";
90
+ var strCore = "core";
91
+ var strUpdate = "update";
92
+ var strDisabled = "disabled";
93
+ var strDoTeardown = "_doTeardown";
94
+
95
+ var cStrStartsWith = "startsWith";
96
+ var strIndexOf = "indexOf";
97
+ var cStrTrim = "trim";
98
+ var strToString = "toString";
99
+ var str__Proto$1 = "__proto__";
100
+ var strConstructor = "constructor";
101
+ var _objDefineProperty$1 = ObjDefineProperty;
102
+ var _objFreeze = ObjClass.freeze;
103
+ var _objKeys = ObjClass.keys;
104
+ var StringProto = String[strShimPrototype];
105
+ var _strTrim = StringProto[cStrTrim];
106
+ var _strStartsWith = StringProto[cStrStartsWith];
107
+ var _isArray = Array.isArray;
108
+ var _objToString = ObjProto[strToString];
109
+ var _fnToString = ObjHasOwnProperty[strToString];
110
+ var _objFunctionString = _fnToString.call(ObjClass);
111
+ var rCamelCase = /-([a-z])/g;
112
+ var rNormalizeInvalid = /([^\w\d_$])/g;
113
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
114
+ var _objGetPrototypeOf$1 = Object["getPrototypeOf"];
115
+ function _getObjProto$1(target) {
116
+ if (target) {
117
+ if (_objGetPrototypeOf$1) {
118
+ return _objGetPrototypeOf$1(target);
119
+ }
120
+ var newProto = target[str__Proto$1] || target[strShimPrototype] || target[strConstructor];
121
+ if (newProto) {
122
+ return newProto;
123
+ }
124
+ }
125
+ return null;
126
+ }
127
+ function isUndefined(value) {
128
+ return value === undefined || typeof value === strShimUndefined;
129
+ }
130
+ function isNullOrUndefined(value) {
131
+ return (value === null || isUndefined(value));
132
+ }
133
+ function hasOwnProperty(obj, prop) {
134
+ return !!(obj && ObjHasOwnProperty.call(obj, prop));
135
+ }
136
+ function isObject(value) {
137
+ return !!(value && typeof value === strShimObject);
138
+ }
139
+ function isFunction(value) {
140
+ return !!(value && typeof value === strShimFunction);
141
+ }
142
+ function normalizeJsName(name) {
143
+ var value = name;
144
+ if (value && isString(value)) {
145
+ value = value.replace(rCamelCase, function (_all, letter) {
146
+ return letter.toUpperCase();
147
+ });
148
+ value = value.replace(rNormalizeInvalid, "_");
149
+ value = value.replace(rLeadingNumeric, function (_all, match) {
150
+ return "_" + match;
151
+ });
152
+ }
153
+ return value;
154
+ }
155
+ function objForEachKey(target, callbackfn) {
156
+ if (target) {
157
+ for (var prop in target) {
158
+ if (ObjHasOwnProperty.call(target, prop)) {
159
+ callbackfn.call(target, prop, target[prop]);
160
+ }
161
+ }
162
+ }
163
+ }
164
+ function strStartsWith(value, checkValue) {
165
+ var result = false;
166
+ if (value && checkValue && !(result = value === checkValue)) {
167
+ result = _strStartsWith ? value[cStrStartsWith](checkValue) : _strStartsWithPoly(value, checkValue);
168
+ }
169
+ return result;
170
+ }
171
+ function _strStartsWithPoly(value, checkValue) {
172
+ var result = false;
173
+ var chkLen = checkValue ? checkValue.length : 0;
174
+ if (value && chkLen && value.length >= chkLen && !(result = value === checkValue)) {
175
+ for (var lp = 0; lp < chkLen; lp++) {
176
+ if (value[lp] !== checkValue[lp]) {
177
+ return false;
178
+ }
179
+ }
180
+ result = true;
181
+ }
182
+ return result;
183
+ }
184
+ function strContains(value, search) {
185
+ if (value && search) {
186
+ return value.indexOf(search) !== -1;
187
+ }
188
+ return false;
189
+ }
190
+ var isArray = _isArray || _isArrayPoly;
191
+ function _isArrayPoly(obj) {
192
+ return !!(obj && _objToString.call(obj) === "[object Array]");
193
+ }
194
+ function isString(value) {
195
+ return typeof value === "string";
196
+ }
197
+ function isNumber(value) {
198
+ return typeof value === "number";
199
+ }
200
+ function isBoolean(value) {
201
+ return typeof value === "boolean";
202
+ }
203
+ function isPlainObject(value) {
204
+ var result = false;
205
+ if (value && typeof value === "object") {
206
+ var proto = _objGetPrototypeOf$1 ? _objGetPrototypeOf$1(value) : _getObjProto$1(value);
207
+ if (!proto) {
208
+ result = true;
209
+ }
210
+ else {
211
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
212
+ proto = proto[strConstructor];
213
+ }
214
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
215
+ }
216
+ }
217
+ return result;
218
+ }
219
+ function arrForEach(arr, callbackfn, thisArg) {
220
+ var len = arr.length;
221
+ try {
222
+ for (var idx = 0; idx < len; idx++) {
223
+ if (idx in arr) {
224
+ if (callbackfn.call(thisArg || arr, arr[idx], idx, arr) === -1) {
225
+ break;
226
+ }
227
+ }
228
+ }
229
+ }
230
+ catch (e) {
231
+ }
232
+ }
233
+ function arrIndexOf(arr, searchElement, fromIndex) {
234
+ if (arr) {
235
+ if (arr[strIndexOf]) {
236
+ return arr[strIndexOf](searchElement, fromIndex);
237
+ }
238
+ var len = arr.length;
239
+ var from = fromIndex || 0;
240
+ try {
241
+ for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
242
+ if (lp in arr && arr[lp] === searchElement) {
243
+ return lp;
244
+ }
245
+ }
246
+ }
247
+ catch (e) {
248
+ }
249
+ }
250
+ return -1;
251
+ }
252
+ function strTrim(str) {
253
+ if (str) {
254
+ str = (_strTrim && str[cStrTrim]) ? str[cStrTrim]() : (str.replace ? str.replace(/^\s+|\s+$/g, "") : str);
255
+ }
256
+ return str;
257
+ }
258
+ var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
259
+ var _objKeysDontEnums = [
260
+ "toString",
261
+ "toLocaleString",
262
+ "valueOf",
263
+ "hasOwnProperty",
264
+ "isPrototypeOf",
265
+ "propertyIsEnumerable",
266
+ "constructor"
267
+ ];
268
+ function objKeys(obj) {
269
+ var objType = typeof obj;
270
+ if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
271
+ throwTypeError("objKeys called on non-object");
272
+ }
273
+ if (!_objKeysHasDontEnumBug && _objKeys) {
274
+ return _objKeys(obj);
275
+ }
276
+ var result = [];
277
+ for (var prop in obj) {
278
+ if (obj && ObjHasOwnProperty.call(obj, prop)) {
279
+ result.push(prop);
280
+ }
281
+ }
282
+ if (_objKeysHasDontEnumBug) {
283
+ var dontEnumsLength = _objKeysDontEnums.length;
284
+ for (var lp = 0; lp < dontEnumsLength; lp++) {
285
+ if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
286
+ result.push(_objKeysDontEnums[lp]);
287
+ }
288
+ }
289
+ }
290
+ return result;
291
+ }
292
+ function objDefineAccessors(target, prop, getProp, setProp) {
293
+ if (_objDefineProperty$1) {
294
+ try {
295
+ var descriptor = {
296
+ enumerable: true,
297
+ configurable: true
298
+ };
299
+ if (getProp) {
300
+ descriptor.get = getProp;
301
+ }
302
+ if (setProp) {
303
+ descriptor.set = setProp;
304
+ }
305
+ _objDefineProperty$1(target, prop, descriptor);
306
+ return true;
307
+ }
308
+ catch (e) {
309
+ }
310
+ }
311
+ return false;
312
+ }
313
+ function _doNothing(value) {
314
+ return value;
315
+ }
316
+ function deepFreeze(obj) {
317
+ if (_objFreeze) {
318
+ objForEachKey(obj, function (name, value) {
319
+ if (isArray(value) || isObject(value)) {
320
+ _objFreeze(value);
321
+ }
322
+ });
323
+ }
324
+ return objFreeze(obj);
325
+ }
326
+ var objFreeze = _objFreeze || _doNothing;
327
+ function dateNow() {
328
+ var dt = Date;
329
+ return dt.now ? dt.now() : new dt().getTime();
330
+ }
331
+ function setValue(target, field, value, valChk, srcChk) {
332
+ var theValue = value;
333
+ if (target) {
334
+ theValue = target[field];
335
+ if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
336
+ theValue = value;
337
+ target[field] = theValue;
338
+ }
339
+ }
340
+ return theValue;
341
+ }
342
+ function _createProxyFunction(source, funcName) {
343
+ var srcFunc = null;
344
+ var src = null;
345
+ if (isFunction(source)) {
346
+ srcFunc = source;
347
+ }
348
+ else {
349
+ src = source;
350
+ }
351
+ return function () {
352
+ var originalArguments = arguments;
353
+ if (srcFunc) {
354
+ src = srcFunc();
355
+ }
356
+ if (src) {
357
+ return src[funcName].apply(src, originalArguments);
358
+ }
359
+ };
360
+ }
361
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
362
+ if (target && name && source) {
363
+ if (overwriteTarget !== false || isUndefined(target[name])) {
364
+ target[name] = _createProxyFunction(source, theFunc);
365
+ }
366
+ }
367
+ }
368
+ function optimizeObject(theObject) {
369
+ if (theObject && ObjAssign) {
370
+ theObject = ObjClass(ObjAssign({}, theObject));
371
+ }
372
+ return theObject;
373
+ }
374
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
375
+ var theArgs = arguments;
376
+ var extended = theArgs[0] || {};
377
+ var argLen = theArgs.length;
378
+ var deep = false;
379
+ var idx = 1;
380
+ if (argLen > 0 && isBoolean(extended)) {
381
+ deep = extended;
382
+ extended = theArgs[idx] || {};
383
+ idx++;
384
+ }
385
+ if (!isObject(extended)) {
386
+ extended = {};
387
+ }
388
+ for (; idx < argLen; idx++) {
389
+ var arg = theArgs[idx];
390
+ var isArgArray = isArray(arg);
391
+ var isArgObj = isObject(arg);
392
+ for (var prop in arg) {
393
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
394
+ if (!propOk) {
395
+ continue;
396
+ }
397
+ var newValue = arg[prop];
398
+ var isNewArray = void 0;
399
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
400
+ var clone = extended[prop];
401
+ if (isNewArray) {
402
+ if (!isArray(clone)) {
403
+ clone = [];
404
+ }
405
+ }
406
+ else if (!isPlainObject(clone)) {
407
+ clone = {};
408
+ }
409
+ newValue = objExtend(deep, clone, newValue);
410
+ }
411
+ if (newValue !== undefined) {
412
+ extended[prop] = newValue;
413
+ }
414
+ }
415
+ }
416
+ return extended;
417
+ }
418
+
419
+ function createEnumStyle(values) {
420
+ var enumClass = {};
421
+ objForEachKey(values, function (field, value) {
422
+ enumClass[field] = value;
423
+ enumClass[value] = field;
424
+ });
425
+ return deepFreeze(enumClass);
426
+ }
427
+
428
+ var EventsDiscardedReason = createEnumStyle({
429
+ Unknown: 0 ,
430
+ NonRetryableStatus: 1 ,
431
+ InvalidEvent: 2 ,
432
+ SizeLimitExceeded: 3 ,
433
+ KillSwitch: 4 ,
104
434
  QueueFull: 5
105
- };
435
+ });
106
436
 
107
437
  /*!
108
438
  * Microsoft Dynamic Proto Utility, 1.1.4
@@ -345,287 +675,6 @@
345
675
  };
346
676
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
347
677
 
348
- var LoggingSeverity;
349
- (function (LoggingSeverity) {
350
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
351
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
352
- })(LoggingSeverity || (LoggingSeverity = {}));
353
- var _InternalMessageId = {
354
- BrowserDoesNotSupportLocalStorage: 0,
355
- BrowserCannotReadLocalStorage: 1,
356
- BrowserCannotReadSessionStorage: 2,
357
- BrowserCannotWriteLocalStorage: 3,
358
- BrowserCannotWriteSessionStorage: 4,
359
- BrowserFailedRemovalFromLocalStorage: 5,
360
- BrowserFailedRemovalFromSessionStorage: 6,
361
- CannotSendEmptyTelemetry: 7,
362
- ClientPerformanceMathError: 8,
363
- ErrorParsingAISessionCookie: 9,
364
- ErrorPVCalc: 10,
365
- ExceptionWhileLoggingError: 11,
366
- FailedAddingTelemetryToBuffer: 12,
367
- FailedMonitorAjaxAbort: 13,
368
- FailedMonitorAjaxDur: 14,
369
- FailedMonitorAjaxOpen: 15,
370
- FailedMonitorAjaxRSC: 16,
371
- FailedMonitorAjaxSend: 17,
372
- FailedMonitorAjaxGetCorrelationHeader: 18,
373
- FailedToAddHandlerForOnBeforeUnload: 19,
374
- FailedToSendQueuedTelemetry: 20,
375
- FailedToReportDataLoss: 21,
376
- FlushFailed: 22,
377
- MessageLimitPerPVExceeded: 23,
378
- MissingRequiredFieldSpecification: 24,
379
- NavigationTimingNotSupported: 25,
380
- OnError: 26,
381
- SessionRenewalDateIsZero: 27,
382
- SenderNotInitialized: 28,
383
- StartTrackEventFailed: 29,
384
- StopTrackEventFailed: 30,
385
- StartTrackFailed: 31,
386
- StopTrackFailed: 32,
387
- TelemetrySampledAndNotSent: 33,
388
- TrackEventFailed: 34,
389
- TrackExceptionFailed: 35,
390
- TrackMetricFailed: 36,
391
- TrackPVFailed: 37,
392
- TrackPVFailedCalc: 38,
393
- TrackTraceFailed: 39,
394
- TransmissionFailed: 40,
395
- FailedToSetStorageBuffer: 41,
396
- FailedToRestoreStorageBuffer: 42,
397
- InvalidBackendResponse: 43,
398
- FailedToFixDepricatedValues: 44,
399
- InvalidDurationValue: 45,
400
- TelemetryEnvelopeInvalid: 46,
401
- CreateEnvelopeError: 47,
402
- CannotSerializeObject: 48,
403
- CannotSerializeObjectNonSerializable: 49,
404
- CircularReferenceDetected: 50,
405
- ClearAuthContextFailed: 51,
406
- ExceptionTruncated: 52,
407
- IllegalCharsInName: 53,
408
- ItemNotInArray: 54,
409
- MaxAjaxPerPVExceeded: 55,
410
- MessageTruncated: 56,
411
- NameTooLong: 57,
412
- SampleRateOutOfRange: 58,
413
- SetAuthContextFailed: 59,
414
- SetAuthContextFailedAccountName: 60,
415
- StringValueTooLong: 61,
416
- StartCalledMoreThanOnce: 62,
417
- StopCalledWithoutStart: 63,
418
- TelemetryInitializerFailed: 64,
419
- TrackArgumentsNotSpecified: 65,
420
- UrlTooLong: 66,
421
- SessionStorageBufferFull: 67,
422
- CannotAccessCookie: 68,
423
- IdTooLong: 69,
424
- InvalidEvent: 70,
425
- FailedMonitorAjaxSetRequestHeader: 71,
426
- SendBrowserInfoOnUserInit: 72,
427
- PluginException: 73,
428
- NotificationException: 74,
429
- SnippetScriptLoadFailure: 99,
430
- InvalidInstrumentationKey: 100,
431
- CannotParseAiBlobValue: 101,
432
- InvalidContentBlob: 102,
433
- TrackPageActionEventFailed: 103,
434
- FailedAddingCustomDefinedRequestContext: 104,
435
- InMemoryStorageBufferFull: 105
436
- };
437
-
438
- var strOnPrefix = "on";
439
- var strAttachEvent = "attachEvent";
440
- var strAddEventHelper = "addEventListener";
441
- var _objDefineProperty = ObjDefineProperty;
442
- function objToString(obj) {
443
- return ObjProto.toString.call(obj);
444
- }
445
- function isUndefined(value) {
446
- return value === undefined || typeof value === strShimUndefined;
447
- }
448
- function isNullOrUndefined(value) {
449
- return (value === null || isUndefined(value));
450
- }
451
- function hasOwnProperty(obj, prop) {
452
- return obj && ObjHasOwnProperty.call(obj, prop);
453
- }
454
- function isObject(value) {
455
- return typeof value === strShimObject;
456
- }
457
- function isFunction(value) {
458
- return typeof value === strShimFunction;
459
- }
460
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
461
- if (useCapture === void 0) { useCapture = false; }
462
- var result = false;
463
- if (!isNullOrUndefined(obj)) {
464
- try {
465
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
466
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
467
- result = true;
468
- }
469
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
470
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
471
- result = true;
472
- }
473
- }
474
- catch (e) {
475
- }
476
- }
477
- return result;
478
- }
479
- function objForEachKey(target, callbackfn) {
480
- if (target) {
481
- for (var prop in target) {
482
- if (ObjHasOwnProperty.call(target, prop)) {
483
- callbackfn.call(target, prop, target[prop]);
484
- }
485
- }
486
- }
487
- }
488
- function strStartsWith(value, checkValue) {
489
- var result = false;
490
- if (value && checkValue) {
491
- var chkLen = checkValue.length;
492
- if (value === checkValue) {
493
- return true;
494
- }
495
- else if (value.length >= chkLen) {
496
- for (var lp = 0; lp < chkLen; lp++) {
497
- if (value[lp] !== checkValue[lp]) {
498
- return false;
499
- }
500
- }
501
- result = true;
502
- }
503
- }
504
- return result;
505
- }
506
- function isArray(obj) {
507
- return objToString(obj) === "[object Array]";
508
- }
509
- function isString(value) {
510
- return typeof value === "string";
511
- }
512
- function isNumber(value) {
513
- return typeof value === "number";
514
- }
515
- function isBoolean(value) {
516
- return typeof value === "boolean";
517
- }
518
- function arrForEach(arr, callbackfn, thisArg) {
519
- var len = arr.length;
520
- try {
521
- for (var idx = 0; idx < len; idx++) {
522
- if (idx in arr) {
523
- if (callbackfn.call(thisArg || arr, arr[idx], idx, arr) === -1) {
524
- break;
525
- }
526
- }
527
- }
528
- }
529
- catch (e) {
530
- }
531
- }
532
- function arrIndexOf(arr, searchElement, fromIndex) {
533
- var len = arr.length;
534
- var from = fromIndex || 0;
535
- try {
536
- for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
537
- if (lp in arr && arr[lp] === searchElement) {
538
- return lp;
539
- }
540
- }
541
- }
542
- catch (e) {
543
- }
544
- return -1;
545
- }
546
- function strTrim(str) {
547
- if (typeof str !== "string") {
548
- return str;
549
- }
550
- return str.replace(/^\s+|\s+$/g, "");
551
- }
552
- var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
553
- var _objKeysDontEnums = [
554
- "toString",
555
- "toLocaleString",
556
- "valueOf",
557
- "hasOwnProperty",
558
- "isPrototypeOf",
559
- "propertyIsEnumerable",
560
- "constructor"
561
- ];
562
- function objKeys(obj) {
563
- var objType = typeof obj;
564
- if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
565
- throwTypeError("objKeys called on non-object");
566
- }
567
- var result = [];
568
- for (var prop in obj) {
569
- if (obj && ObjHasOwnProperty.call(obj, prop)) {
570
- result.push(prop);
571
- }
572
- }
573
- if (_objKeysHasDontEnumBug) {
574
- var dontEnumsLength = _objKeysDontEnums.length;
575
- for (var lp = 0; lp < dontEnumsLength; lp++) {
576
- if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
577
- result.push(_objKeysDontEnums[lp]);
578
- }
579
- }
580
- }
581
- return result;
582
- }
583
- function objDefineAccessors(target, prop, getProp, setProp) {
584
- if (_objDefineProperty) {
585
- try {
586
- var descriptor = {
587
- enumerable: true,
588
- configurable: true
589
- };
590
- if (getProp) {
591
- descriptor.get = getProp;
592
- }
593
- if (setProp) {
594
- descriptor.set = setProp;
595
- }
596
- _objDefineProperty(target, prop, descriptor);
597
- return true;
598
- }
599
- catch (e) {
600
- }
601
- }
602
- return false;
603
- }
604
- function dateNow() {
605
- var dt = Date;
606
- if (dt.now) {
607
- return dt.now();
608
- }
609
- return new dt().getTime();
610
- }
611
- function setValue(target, field, value, valChk, srcChk) {
612
- var theValue = value;
613
- if (target) {
614
- theValue = target[field];
615
- if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
616
- theValue = value;
617
- target[field] = theValue;
618
- }
619
- }
620
- return theValue;
621
- }
622
- function optimizeObject(theObject) {
623
- if (theObject) {
624
- theObject = ObjClass(ObjAssign ? ObjAssign({}, theObject) : theObject);
625
- }
626
- return theObject;
627
- }
628
-
629
678
  var strWindow = "window";
630
679
  var strDocument = "document";
631
680
  var strNavigator = "navigator";
@@ -633,7 +682,14 @@
633
682
  var strConsole = "console";
634
683
  var strPerformance = "performance";
635
684
  var strJSON = "JSON";
685
+ var strCrypto = "crypto";
686
+ var strMsCrypto = "msCrypto";
636
687
  var strReactNative = "ReactNative";
688
+ var strMsie = "msie";
689
+ var strTrident = "trident/";
690
+ var strXMLHttpRequest = "XMLHttpRequest";
691
+ var _isTrident = null;
692
+ var _navUserAgentCheck = null;
637
693
  var _enableMocks = false;
638
694
  var _useXDomainRequest = null;
639
695
  var _beaconsSupported = null;
@@ -729,6 +785,12 @@
729
785
  }
730
786
  return null;
731
787
  }
788
+ function getCrypto() {
789
+ return getGlobalInst(strCrypto);
790
+ }
791
+ function getMsCrypto() {
792
+ return getGlobalInst(strMsCrypto);
793
+ }
732
794
  function isReactNative() {
733
795
  var nav = getNavigator();
734
796
  if (nav && nav.product) {
@@ -736,9 +798,18 @@
736
798
  }
737
799
  return false;
738
800
  }
801
+ function isIE() {
802
+ var nav = getNavigator();
803
+ if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
804
+ _navUserAgentCheck = nav.userAgent;
805
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
806
+ _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
807
+ }
808
+ return _isTrident;
809
+ }
739
810
  function dumpObj(object) {
740
811
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
741
- var propertyValueDump = "";
812
+ var propertyValueDump = strEmpty;
742
813
  if (objectTypeDump === "[object Error]") {
743
814
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
744
815
  }
@@ -756,8 +827,7 @@
756
827
  function isFetchSupported(withKeepAlive) {
757
828
  var isSupported = false;
758
829
  try {
759
- var fetchApi = getGlobalInst("fetch");
760
- isSupported = !!fetchApi;
830
+ isSupported = !!getGlobalInst("fetch");
761
831
  var request = getGlobalInst("Request");
762
832
  if (isSupported && withKeepAlive && request) {
763
833
  isSupported = _hasProperty(request, "keepalive");
@@ -769,9 +839,9 @@
769
839
  }
770
840
  function useXDomainRequest() {
771
841
  if (_useXDomainRequest === null) {
772
- _useXDomainRequest = (typeof XDomainRequest !== "undefined");
842
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
773
843
  if (_useXDomainRequest && isXhrSupported()) {
774
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
844
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
775
845
  }
776
846
  }
777
847
  return _useXDomainRequest;
@@ -779,7 +849,7 @@
779
849
  function isXhrSupported() {
780
850
  var isSupported = false;
781
851
  try {
782
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
852
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
783
853
  isSupported = !!xmlHttpRequest;
784
854
  }
785
855
  catch (e) {
@@ -810,9 +880,9 @@
810
880
  var strWarnToConsole = "warnToConsole";
811
881
  function _sanitizeDiagnosticText(text) {
812
882
  if (text) {
813
- return "\"" + text.replace(/\"/g, "") + "\"";
883
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
814
884
  }
815
- return "";
885
+ return strEmpty;
816
886
  }
817
887
  function _logToConsole(func, message) {
818
888
  var theConsole = getConsole();
@@ -834,12 +904,12 @@
834
904
  _self.message =
835
905
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
836
906
  msgId;
837
- var strProps = "";
907
+ var strProps = strEmpty;
838
908
  if (hasJSON()) {
839
909
  strProps = getJSON().stringify(properties);
840
910
  }
841
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
842
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
911
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
912
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
843
913
  _self.message += diagnosticText;
844
914
  }
845
915
  _InternalLogMessage.dataType = "MessageData";
@@ -869,7 +939,7 @@
869
939
  throw message;
870
940
  }
871
941
  else {
872
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
942
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
873
943
  if (!isUndefined(message.message)) {
874
944
  var logLevel = _self.consoleLoggingLevel();
875
945
  if (isUserAct) {
@@ -887,7 +957,7 @@
887
957
  _self.logInternalMessage(severity, message);
888
958
  }
889
959
  else {
890
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
960
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
891
961
  }
892
962
  }
893
963
  };
@@ -919,13 +989,13 @@
919
989
  if (severity <= _self.telemetryLoggingLevel()) {
920
990
  _self.queue.push(message);
921
991
  _messageCount++;
922
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
992
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
923
993
  }
924
994
  if (_messageCount === _self.maxInternalMessageLimit()) {
925
995
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
926
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
996
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
927
997
  _self.queue.push(throttleMessage);
928
- if (severity === LoggingSeverity.CRITICAL) {
998
+ if (severity === 1 ) {
929
999
  _self.errorToConsole(throttleLimitMessage);
930
1000
  }
931
1001
  else {
@@ -954,6 +1024,10 @@
954
1024
  }
955
1025
  return DiagnosticLogger;
956
1026
  }());
1027
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1028
+ if (isUserAct === void 0) { isUserAct = false; }
1029
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1030
+ }
957
1031
 
958
1032
  var strExecutionContextKey = "ctx";
959
1033
  var PerfEvent = /** @class */ (function () {
@@ -1067,207 +1141,621 @@
1067
1141
  return func();
1068
1142
  }
1069
1143
 
1070
- var TelemetryPluginChain = /** @class */ (function () {
1071
- function TelemetryPluginChain(plugin, defItemCtx) {
1072
- var _self = this;
1073
- var _nextProxy = null;
1074
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1075
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1076
- _self._hasRun = false;
1077
- _self.getPlugin = function () {
1078
- return plugin;
1079
- };
1080
- _self.getNext = function () {
1081
- return _nextProxy;
1082
- };
1083
- _self.setNext = function (nextPlugin) {
1084
- _nextProxy = nextPlugin;
1085
- };
1086
- _self.processTelemetry = function (env, itemCtx) {
1087
- if (!itemCtx) {
1088
- itemCtx = defItemCtx;
1144
+ var UInt32Mask = 0x100000000;
1145
+ var MaxUInt32 = 0xffffffff;
1146
+ var _mwcSeeded = false;
1147
+ var _mwcW = 123456789;
1148
+ var _mwcZ = 987654321;
1149
+ function _mwcSeed(seedValue) {
1150
+ if (seedValue < 0) {
1151
+ seedValue >>>= 0;
1152
+ }
1153
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1154
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1155
+ _mwcSeeded = true;
1156
+ }
1157
+ function _autoSeedMwc() {
1158
+ try {
1159
+ var now = dateNow() & 0x7fffffff;
1160
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1161
+ }
1162
+ catch (e) {
1163
+ }
1164
+ }
1165
+ function random32(signed) {
1166
+ var value = 0;
1167
+ var c = getCrypto() || getMsCrypto();
1168
+ if (c && c.getRandomValues) {
1169
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1170
+ }
1171
+ if (value === 0 && isIE()) {
1172
+ if (!_mwcSeeded) {
1173
+ _autoSeedMwc();
1174
+ }
1175
+ value = mwcRandom32() & MaxUInt32;
1176
+ }
1177
+ if (value === 0) {
1178
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1179
+ }
1180
+ if (!signed) {
1181
+ value >>>= 0;
1182
+ }
1183
+ return value;
1184
+ }
1185
+ function mwcRandom32(signed) {
1186
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1187
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1188
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1189
+ if (!signed) {
1190
+ value >>>= 0;
1191
+ }
1192
+ return value;
1193
+ }
1194
+ function newId(maxLength) {
1195
+ if (maxLength === void 0) { maxLength = 22; }
1196
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1197
+ var number = random32() >>> 0;
1198
+ var chars = 0;
1199
+ var result = strEmpty;
1200
+ while (result.length < maxLength) {
1201
+ chars++;
1202
+ result += base64chars.charAt(number & 0x3F);
1203
+ number >>>= 6;
1204
+ if (chars === 5) {
1205
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1206
+ chars = 0;
1207
+ }
1208
+ }
1209
+ return result;
1210
+ }
1211
+
1212
+ var _objDefineProperty = ObjDefineProperty;
1213
+ var version = "2.8.1";
1214
+ var instanceName = "." + newId(6);
1215
+ var _dataUid = 0;
1216
+ function _createAccessor(target, prop, value) {
1217
+ if (_objDefineProperty) {
1218
+ try {
1219
+ _objDefineProperty(target, prop, {
1220
+ value: value,
1221
+ enumerable: false,
1222
+ configurable: true
1223
+ });
1224
+ return true;
1225
+ }
1226
+ catch (e) {
1227
+ }
1228
+ }
1229
+ return false;
1230
+ }
1231
+ function _canAcceptData(target) {
1232
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1233
+ }
1234
+ function _getCache(data, target) {
1235
+ var theCache = target[data.id];
1236
+ if (!theCache) {
1237
+ theCache = {};
1238
+ try {
1239
+ if (_canAcceptData(target)) {
1240
+ if (!_createAccessor(target, data.id, theCache)) {
1241
+ target[data.id] = theCache;
1242
+ }
1089
1243
  }
1090
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1091
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1092
- if (plugin && _hasProcessTelemetry) {
1093
- _self._hasRun = true;
1244
+ }
1245
+ catch (e) {
1246
+ }
1247
+ }
1248
+ return theCache;
1249
+ }
1250
+ function createUniqueNamespace(name, includeVersion) {
1251
+ if (includeVersion === void 0) { includeVersion = false; }
1252
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1253
+ }
1254
+ function createElmNodeData(name) {
1255
+ var data = {
1256
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1257
+ accept: function (target) {
1258
+ return _canAcceptData(target);
1259
+ },
1260
+ get: function (target, name, defValue, addDefault) {
1261
+ var theCache = target[data.id];
1262
+ if (!theCache) {
1263
+ if (addDefault) {
1264
+ theCache = _getCache(data, target);
1265
+ theCache[normalizeJsName(name)] = defValue;
1266
+ }
1267
+ return defValue;
1268
+ }
1269
+ return theCache[normalizeJsName(name)];
1270
+ },
1271
+ kill: function (target, name) {
1272
+ if (target && target[name]) {
1273
+ try {
1274
+ delete target[name];
1275
+ }
1276
+ catch (e) {
1277
+ }
1278
+ }
1279
+ }
1280
+ };
1281
+ return data;
1282
+ }
1283
+
1284
+ var pluginStateData = createElmNodeData("plugin");
1285
+ function _getPluginState(plugin) {
1286
+ return pluginStateData.get(plugin, "state", {}, true);
1287
+ }
1288
+
1289
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1290
+ var strHasRunFlags = "_hasRun";
1291
+ var strGetTelCtx = "_getTelCtx";
1292
+ var _chainId = 0;
1293
+ function _getNextProxyStart(proxy, core, startAt) {
1294
+ while (proxy) {
1295
+ if (proxy.getPlugin() === startAt) {
1296
+ return proxy;
1297
+ }
1298
+ proxy = proxy.getNext();
1299
+ }
1300
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
1301
+ }
1302
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1303
+ var _nextProxy = null;
1304
+ var _onComplete = [];
1305
+ if (startAt !== null) {
1306
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1307
+ }
1308
+ var context = {
1309
+ _next: _moveNext,
1310
+ ctx: {
1311
+ core: function () {
1312
+ return core;
1313
+ },
1314
+ diagLog: function () {
1315
+ return safeGetLogger(core, config);
1316
+ },
1317
+ getCfg: function () {
1318
+ return config;
1319
+ },
1320
+ getExtCfg: _getExtCfg,
1321
+ getConfig: _getConfig,
1322
+ hasNext: function () {
1323
+ return !!_nextProxy;
1324
+ },
1325
+ getNext: function () {
1326
+ return _nextProxy;
1327
+ },
1328
+ setNext: function (nextPlugin) {
1329
+ _nextProxy = nextPlugin;
1330
+ },
1331
+ iterate: _iterateChain,
1332
+ onComplete: _addOnComplete
1333
+ }
1334
+ };
1335
+ function _addOnComplete(onComplete, that) {
1336
+ var args = [];
1337
+ for (var _i = 2; _i < arguments.length; _i++) {
1338
+ args[_i - 2] = arguments[_i];
1339
+ }
1340
+ if (onComplete) {
1341
+ _onComplete.push({
1342
+ func: onComplete,
1343
+ self: !isUndefined(that) ? that : context.ctx,
1344
+ args: args
1345
+ });
1346
+ }
1347
+ }
1348
+ function _moveNext() {
1349
+ var nextProxy = _nextProxy;
1350
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1351
+ if (!nextProxy) {
1352
+ var onComplete = _onComplete;
1353
+ if (onComplete && onComplete.length > 0) {
1354
+ arrForEach(onComplete, function (completeDetails) {
1094
1355
  try {
1095
- itemCtx.setNext(_nextProxy);
1096
- if (_hasSetNext) {
1097
- plugin.setNextPlugin(_nextProxy);
1098
- }
1099
- _nextProxy && (_nextProxy._hasRun = false);
1100
- plugin.processTelemetry(env, itemCtx);
1356
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1101
1357
  }
1102
- catch (error) {
1103
- var hasRun = _nextProxy && _nextProxy._hasRun;
1104
- if (!_nextProxy || !hasRun) {
1105
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1106
- }
1107
- if (_nextProxy && !hasRun) {
1108
- _nextProxy.processTelemetry(env, itemCtx);
1109
- }
1358
+ catch (e) {
1359
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1110
1360
  }
1361
+ });
1362
+ _onComplete = [];
1363
+ }
1364
+ }
1365
+ return nextProxy;
1366
+ }
1367
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1368
+ if (defaultValue === void 0) { defaultValue = {}; }
1369
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1370
+ var theConfig;
1371
+ if (config) {
1372
+ var extConfig = config.extensionConfig;
1373
+ if (extConfig && identifier) {
1374
+ theConfig = extConfig[identifier];
1375
+ }
1376
+ }
1377
+ if (!theConfig) {
1378
+ theConfig = defaultValue;
1379
+ }
1380
+ else if (isObject(defaultValue)) {
1381
+ if (mergeDefault !== 0 ) {
1382
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1383
+ if (config && mergeDefault === 2 ) {
1384
+ objForEachKey(defaultValue, function (field) {
1385
+ if (isNullOrUndefined(newConfig_1[field])) {
1386
+ var cfgValue = config[field];
1387
+ if (!isNullOrUndefined(cfgValue)) {
1388
+ newConfig_1[field] = cfgValue;
1389
+ }
1390
+ }
1391
+ });
1111
1392
  }
1112
- else if (_nextProxy) {
1113
- _self._hasRun = true;
1114
- _nextProxy.processTelemetry(env, itemCtx);
1393
+ theConfig = newConfig_1;
1394
+ }
1395
+ }
1396
+ return theConfig;
1397
+ }
1398
+ function _getConfig(identifier, field, defaultValue) {
1399
+ if (defaultValue === void 0) { defaultValue = false; }
1400
+ var theValue;
1401
+ var extConfig = _getExtCfg(identifier, null);
1402
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1403
+ theValue = extConfig[field];
1404
+ }
1405
+ else if (config && !isNullOrUndefined(config[field])) {
1406
+ theValue = config[field];
1407
+ }
1408
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1409
+ }
1410
+ function _iterateChain(cb) {
1411
+ var nextPlugin;
1412
+ while (!!(nextPlugin = context._next())) {
1413
+ var plugin = nextPlugin.getPlugin();
1414
+ if (plugin) {
1415
+ cb(plugin);
1416
+ }
1417
+ }
1418
+ }
1419
+ return context;
1420
+ }
1421
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1422
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1423
+ var context = internalContext.ctx;
1424
+ function _processNext(env) {
1425
+ var nextPlugin = internalContext._next();
1426
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1427
+ return !nextPlugin;
1428
+ }
1429
+ function _createNew(plugins, startAt) {
1430
+ if (plugins === void 0) { plugins = null; }
1431
+ if (isArray(plugins)) {
1432
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1433
+ }
1434
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1435
+ }
1436
+ context.processNext = _processNext;
1437
+ context.createNew = _createNew;
1438
+ return context;
1439
+ }
1440
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1441
+ var config = core.config || {};
1442
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1443
+ var context = internalContext.ctx;
1444
+ function _processNext(unloadState) {
1445
+ var nextPlugin = internalContext._next();
1446
+ nextPlugin && nextPlugin.unload(context, unloadState);
1447
+ return !nextPlugin;
1448
+ }
1449
+ function _createNew(plugins, startAt) {
1450
+ if (plugins === void 0) { plugins = null; }
1451
+ if (isArray(plugins)) {
1452
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1453
+ }
1454
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1455
+ }
1456
+ context.processNext = _processNext;
1457
+ context.createNew = _createNew;
1458
+ return context;
1459
+ }
1460
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1461
+ var config = core.config || {};
1462
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1463
+ var context = internalContext.ctx;
1464
+ function _processNext(updateState) {
1465
+ return context.iterate(function (plugin) {
1466
+ if (isFunction(plugin.update)) {
1467
+ plugin.update(context, updateState);
1468
+ }
1469
+ });
1470
+ }
1471
+ function _createNew(plugins, startAt) {
1472
+ if (plugins === void 0) { plugins = null; }
1473
+ if (isArray(plugins)) {
1474
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1475
+ }
1476
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1477
+ }
1478
+ context.processNext = _processNext;
1479
+ context.createNew = _createNew;
1480
+ return context;
1481
+ }
1482
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1483
+ var firstProxy = null;
1484
+ var add = startAt ? false : true;
1485
+ if (isArray(plugins) && plugins.length > 0) {
1486
+ var lastProxy_1 = null;
1487
+ arrForEach(plugins, function (thePlugin) {
1488
+ if (!add && startAt === thePlugin) {
1489
+ add = true;
1490
+ }
1491
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1492
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1493
+ if (!firstProxy) {
1494
+ firstProxy = newProxy;
1115
1495
  }
1116
- }, function () { return ({ item: env }); }, !(env.sync));
1117
- };
1496
+ if (lastProxy_1) {
1497
+ lastProxy_1._setNext(newProxy);
1498
+ }
1499
+ lastProxy_1 = newProxy;
1500
+ }
1501
+ });
1118
1502
  }
1119
- return TelemetryPluginChain;
1120
- }());
1121
-
1122
- function _createProxyChain(plugins, itemCtx) {
1123
- var proxies = [];
1124
- if (plugins && plugins.length > 0) {
1125
- var lastProxy = null;
1126
- for (var idx = 0; idx < plugins.length; idx++) {
1127
- var thePlugin = plugins[idx];
1128
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1129
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1130
- proxies.push(newProxy);
1131
- if (lastProxy) {
1132
- lastProxy.setNext(newProxy);
1503
+ if (startAt && !firstProxy) {
1504
+ return createTelemetryProxyChain([startAt], config, core);
1505
+ }
1506
+ return firstProxy;
1507
+ }
1508
+ function createTelemetryPluginProxy(plugin, config, core) {
1509
+ var nextProxy = null;
1510
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1511
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1512
+ var chainId;
1513
+ if (plugin) {
1514
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1515
+ }
1516
+ else {
1517
+ chainId = "Unknown-0-" + _chainId++;
1518
+ }
1519
+ var proxyChain = {
1520
+ getPlugin: function () {
1521
+ return plugin;
1522
+ },
1523
+ getNext: function () {
1524
+ return nextProxy;
1525
+ },
1526
+ processTelemetry: _processTelemetry,
1527
+ unload: _unloadPlugin,
1528
+ update: _updatePlugin,
1529
+ _id: chainId,
1530
+ _setNext: function (nextPlugin) {
1531
+ nextProxy = nextPlugin;
1532
+ }
1533
+ };
1534
+ function _getTelCtx() {
1535
+ var itemCtx;
1536
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1537
+ itemCtx = plugin[strGetTelCtx]();
1538
+ }
1539
+ if (!itemCtx) {
1540
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1541
+ }
1542
+ return itemCtx;
1543
+ }
1544
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1545
+ var hasRun = false;
1546
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1547
+ var hasRunContext = itemCtx[strHasRunFlags];
1548
+ if (!hasRunContext) {
1549
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1550
+ }
1551
+ itemCtx.setNext(nextProxy);
1552
+ if (plugin) {
1553
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1554
+ hasRunContext[chainId] = true;
1555
+ try {
1556
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1557
+ if (nextId) {
1558
+ hasRunContext[nextId] = false;
1559
+ }
1560
+ hasRun = processPluginFn(itemCtx);
1133
1561
  }
1134
- lastProxy = newProxy;
1562
+ catch (error) {
1563
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1564
+ if (hasNextRun) {
1565
+ hasRun = true;
1566
+ }
1567
+ if (!nextProxy || !hasNextRun) {
1568
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1569
+ }
1570
+ }
1571
+ }, details, isAsync);
1572
+ }
1573
+ return hasRun;
1574
+ }
1575
+ function _processTelemetry(env, itemCtx) {
1576
+ itemCtx = itemCtx || _getTelCtx();
1577
+ function _callProcessTelemetry(itemCtx) {
1578
+ if (!plugin || !hasProcessTelemetry) {
1579
+ return false;
1580
+ }
1581
+ var pluginState = _getPluginState(plugin);
1582
+ if (pluginState.teardown || pluginState[strDisabled]) {
1583
+ return false;
1584
+ }
1585
+ if (hasSetNext) {
1586
+ plugin.setNextPlugin(nextProxy);
1135
1587
  }
1588
+ plugin.processTelemetry(env, itemCtx);
1589
+ return true;
1590
+ }
1591
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1592
+ itemCtx.processNext(env);
1136
1593
  }
1137
1594
  }
1138
- return proxies.length > 0 ? proxies[0] : null;
1139
- }
1140
- function _copyProxyChain(proxy, itemCtx, startAt) {
1141
- var plugins = [];
1142
- var add = startAt ? false : true;
1143
- if (proxy) {
1144
- while (proxy) {
1145
- var thePlugin = proxy.getPlugin();
1146
- if (add || thePlugin === startAt) {
1147
- add = true;
1148
- plugins.push(thePlugin);
1595
+ function _unloadPlugin(unloadCtx, unloadState) {
1596
+ function _callTeardown() {
1597
+ var hasRun = false;
1598
+ if (plugin) {
1599
+ var pluginState = _getPluginState(plugin);
1600
+ var pluginCore = plugin[strCore] || pluginState.core;
1601
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1602
+ pluginState[strCore] = null;
1603
+ pluginState[strTeardown] = true;
1604
+ pluginState[strIsInitialized] = false;
1605
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1606
+ hasRun = true;
1607
+ }
1608
+ }
1149
1609
  }
1150
- proxy = proxy.getNext();
1610
+ return hasRun;
1611
+ }
1612
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1613
+ unloadCtx.processNext(unloadState);
1151
1614
  }
1152
1615
  }
1153
- if (!add) {
1154
- plugins.push(startAt);
1155
- }
1156
- return _createProxyChain(plugins, itemCtx);
1157
- }
1158
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1159
- var plugins = srcPlugins;
1160
- var add = false;
1161
- if (startAt && srcPlugins) {
1162
- plugins = [];
1163
- arrForEach(srcPlugins, function (thePlugin) {
1164
- if (add || thePlugin === startAt) {
1165
- add = true;
1166
- plugins.push(thePlugin);
1616
+ function _updatePlugin(updateCtx, updateState) {
1617
+ function _callUpdate() {
1618
+ var hasRun = false;
1619
+ if (plugin) {
1620
+ var pluginState = _getPluginState(plugin);
1621
+ var pluginCore = plugin[strCore] || pluginState.core;
1622
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1623
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1624
+ hasRun = true;
1625
+ }
1626
+ }
1167
1627
  }
1168
- });
1169
- }
1170
- if (startAt && !add) {
1171
- if (!plugins) {
1172
- plugins = [];
1628
+ return hasRun;
1629
+ }
1630
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1631
+ updateCtx.processNext(updateState);
1173
1632
  }
1174
- plugins.push(startAt);
1175
1633
  }
1176
- return _createProxyChain(plugins, itemCtx);
1634
+ return objFreeze(proxyChain);
1177
1635
  }
1178
- var ProcessTelemetryContext = /** @class */ (function () {
1179
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1180
- var _self = this;
1181
- var _nextProxy = null;
1182
- if (startAt !== null) {
1183
- if (plugins && isFunction(plugins.getPlugin)) {
1184
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1185
- }
1186
- else {
1187
- if (startAt) {
1188
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1189
- }
1190
- else if (isUndefined(startAt)) {
1191
- _nextProxy = _createProxyChain(plugins, _self);
1192
- }
1193
- }
1636
+
1637
+ var strExtensionConfig = "extensionConfig";
1638
+
1639
+ function createUnloadHandlerContainer() {
1640
+ var handlers = [];
1641
+ function _addHandler(handler) {
1642
+ if (handler) {
1643
+ handlers.push(handler);
1194
1644
  }
1195
- _self.core = function () {
1196
- return core;
1197
- };
1198
- _self.diagLog = function () {
1199
- return safeGetLogger(core, config);
1200
- };
1201
- _self.getCfg = function () {
1202
- return config;
1203
- };
1204
- _self.getExtCfg = function (identifier, defaultValue) {
1205
- if (defaultValue === void 0) { defaultValue = {}; }
1206
- var theConfig;
1207
- if (config) {
1208
- var extConfig = config.extensionConfig;
1209
- if (extConfig && identifier) {
1210
- theConfig = extConfig[identifier];
1211
- }
1212
- }
1213
- return (theConfig ? theConfig : defaultValue);
1214
- };
1215
- _self.getConfig = function (identifier, field, defaultValue) {
1216
- if (defaultValue === void 0) { defaultValue = false; }
1217
- var theValue;
1218
- var extConfig = _self.getExtCfg(identifier, null);
1219
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1220
- theValue = extConfig[field];
1221
- }
1222
- else if (config && !isNullOrUndefined(config[field])) {
1223
- theValue = config[field];
1645
+ }
1646
+ function _runHandlers(unloadCtx, unloadState) {
1647
+ arrForEach(handlers, function (handler) {
1648
+ try {
1649
+ handler(unloadCtx, unloadState);
1224
1650
  }
1225
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1226
- };
1227
- _self.hasNext = function () {
1228
- return _nextProxy != null;
1229
- };
1230
- _self.getNext = function () {
1231
- return _nextProxy;
1232
- };
1233
- _self.setNext = function (nextPlugin) {
1234
- _nextProxy = nextPlugin;
1235
- };
1236
- _self.processNext = function (env) {
1237
- var nextPlugin = _nextProxy;
1238
- if (nextPlugin) {
1239
- _nextProxy = nextPlugin.getNext();
1240
- nextPlugin.processTelemetry(env, _self);
1651
+ catch (e) {
1652
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1241
1653
  }
1242
- };
1243
- _self.createNew = function (plugins, startAt) {
1244
- if (plugins === void 0) { plugins = null; }
1245
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1246
- };
1654
+ });
1655
+ handlers = [];
1247
1656
  }
1248
- return ProcessTelemetryContext;
1249
- }());
1250
-
1251
- var strExtensionConfig = "extensionConfig";
1657
+ return {
1658
+ add: _addHandler,
1659
+ run: _runHandlers
1660
+ };
1661
+ }
1252
1662
 
1253
1663
  var strGetPlugin = "getPlugin";
1254
1664
  var BaseTelemetryPlugin = /** @class */ (function () {
1255
1665
  function BaseTelemetryPlugin() {
1256
1666
  var _self = this;
1257
- var _isinitialized = false;
1258
- var _rootCtx = null;
1259
- var _nextPlugin = null;
1260
- _self.core = null;
1667
+ var _isinitialized;
1668
+ var _rootCtx;
1669
+ var _nextPlugin;
1670
+ var _unloadHandlerContainer;
1671
+ var _hooks;
1672
+ _initDefaults();
1673
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1674
+ _self.initialize = function (config, core, extensions, pluginChain) {
1675
+ _setDefaults(config, core, pluginChain);
1676
+ _isinitialized = true;
1677
+ };
1678
+ _self.teardown = function (unloadCtx, unloadState) {
1679
+ var core = _self.core;
1680
+ if (!core || (unloadCtx && core !== unloadCtx.core())) {
1681
+ return;
1682
+ }
1683
+ var result;
1684
+ var unloadDone = false;
1685
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1686
+ var theUnloadState = unloadState || {
1687
+ reason: 0 ,
1688
+ isAsync: false
1689
+ };
1690
+ function _unloadCallback() {
1691
+ if (!unloadDone) {
1692
+ unloadDone = true;
1693
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1694
+ arrForEach(_hooks, function (fn) {
1695
+ fn.rm();
1696
+ });
1697
+ _hooks = [];
1698
+ if (result === true) {
1699
+ theUnloadCtx.processNext(theUnloadState);
1700
+ }
1701
+ _initDefaults();
1702
+ }
1703
+ }
1704
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1705
+ _unloadCallback();
1706
+ }
1707
+ else {
1708
+ result = true;
1709
+ }
1710
+ return result;
1711
+ };
1712
+ _self.update = function (updateCtx, updateState) {
1713
+ var core = _self.core;
1714
+ if (!core || (updateCtx && core !== updateCtx.core())) {
1715
+ return;
1716
+ }
1717
+ var result;
1718
+ var updateDone = false;
1719
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1720
+ var theUpdateState = updateState || {
1721
+ reason: 0
1722
+ };
1723
+ function _updateCallback() {
1724
+ if (!updateDone) {
1725
+ updateDone = true;
1726
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1727
+ }
1728
+ }
1729
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1730
+ _updateCallback();
1731
+ }
1732
+ else {
1733
+ result = true;
1734
+ }
1735
+ return result;
1736
+ };
1737
+ _self._addHook = function (hooks) {
1738
+ if (hooks) {
1739
+ if (isArray(hooks)) {
1740
+ _hooks = _hooks.concat(hooks);
1741
+ }
1742
+ else {
1743
+ _hooks.push(hooks);
1744
+ }
1745
+ }
1746
+ };
1747
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1748
+ });
1261
1749
  _self.diagLog = function (itemCtx) {
1262
- return _self._getTelCtx(itemCtx).diagLog();
1750
+ return _getTelCtx(itemCtx).diagLog();
1263
1751
  };
1264
- _self.isInitialized = function () {
1752
+ _self[strIsInitialized] = function () {
1265
1753
  return _isinitialized;
1266
1754
  };
1267
1755
  _self.setInitialized = function (isInitialized) {
1268
1756
  _isinitialized = isInitialized;
1269
1757
  };
1270
- _self.setNextPlugin = function (next) {
1758
+ _self[strSetNextPlugin] = function (next) {
1271
1759
  _nextPlugin = next;
1272
1760
  };
1273
1761
  _self.processNext = function (env, itemCtx) {
@@ -1278,11 +1766,12 @@
1278
1766
  _nextPlugin.processTelemetry(env, null);
1279
1767
  }
1280
1768
  };
1281
- _self._getTelCtx = function (currentCtx) {
1769
+ _self._getTelCtx = _getTelCtx;
1770
+ function _getTelCtx(currentCtx) {
1282
1771
  if (currentCtx === void 0) { currentCtx = null; }
1283
1772
  var itemCtx = currentCtx;
1284
1773
  if (!itemCtx) {
1285
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1774
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1286
1775
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1287
1776
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1288
1777
  }
@@ -1291,8 +1780,8 @@
1291
1780
  }
1292
1781
  }
1293
1782
  return itemCtx;
1294
- };
1295
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1783
+ }
1784
+ function _setDefaults(config, core, pluginChain) {
1296
1785
  if (config) {
1297
1786
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1298
1787
  }
@@ -1304,93 +1793,300 @@
1304
1793
  nextPlugin = _nextPlugin[strGetPlugin]();
1305
1794
  }
1306
1795
  _self.core = core;
1307
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1308
- _isinitialized = true;
1309
- };
1796
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1797
+ }
1798
+ function _initDefaults() {
1799
+ _isinitialized = false;
1800
+ _self.core = null;
1801
+ _rootCtx = null;
1802
+ _nextPlugin = null;
1803
+ _hooks = [];
1804
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1805
+ }
1310
1806
  }
1311
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1312
- this._baseTelInit(config, core, extensions, pluginChain);
1313
- };
1314
1807
  return BaseTelemetryPlugin;
1315
1808
  }());
1316
1809
 
1810
+ var strOnPrefix = "on";
1811
+ var strAttachEvent = "attachEvent";
1812
+ var strAddEventHelper = "addEventListener";
1813
+ var strDetachEvent = "detachEvent";
1814
+ var strRemoveEventListener = "removeEventListener";
1815
+ var strEvents = "events";
1317
1816
  var strVisibilityChangeEvt = "visibilitychange";
1318
1817
  var strPageHide = "pagehide";
1319
1818
  var strPageShow = "pageshow";
1320
- function addEventHandler(eventName, callback) {
1819
+ var strUnload = "unload";
1820
+ var strBeforeUnload = "beforeunload";
1821
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
1822
+ var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
1823
+ var rRemoveEmptyNs = /\.[\.]+/g;
1824
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1825
+ var _guid = 1;
1826
+ var elmNodeData = createElmNodeData("events");
1827
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1828
+ function _normalizeNamespace(name) {
1829
+ if (name && name.replace) {
1830
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1831
+ }
1832
+ return name;
1833
+ }
1834
+ function _getEvtNamespace(eventName, evtNamespace) {
1835
+ if (evtNamespace) {
1836
+ var theNamespace_1 = "";
1837
+ if (isArray(evtNamespace)) {
1838
+ theNamespace_1 = "";
1839
+ arrForEach(evtNamespace, function (name) {
1840
+ name = _normalizeNamespace(name);
1841
+ if (name) {
1842
+ if (name[0] !== ".") {
1843
+ name = "." + name;
1844
+ }
1845
+ theNamespace_1 += name;
1846
+ }
1847
+ });
1848
+ }
1849
+ else {
1850
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1851
+ }
1852
+ if (theNamespace_1) {
1853
+ if (theNamespace_1[0] !== ".") {
1854
+ theNamespace_1 = "." + theNamespace_1;
1855
+ }
1856
+ eventName = (eventName || "") + theNamespace_1;
1857
+ }
1858
+ }
1859
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1860
+ return {
1861
+ type: parsedEvent[1],
1862
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1863
+ };
1864
+ }
1865
+ function _getRegisteredEvents(target, evtName, addDefault) {
1866
+ if (addDefault === void 0) { addDefault = true; }
1867
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1868
+ var registeredEvents = aiEvts[evtName];
1869
+ if (!registeredEvents) {
1870
+ registeredEvents = aiEvts[evtName] = [];
1871
+ }
1872
+ return registeredEvents;
1873
+ }
1874
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
1875
+ if (obj && evtName && evtName.type) {
1876
+ if (obj[strRemoveEventListener]) {
1877
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1878
+ }
1879
+ else if (obj[strDetachEvent]) {
1880
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1881
+ }
1882
+ }
1883
+ }
1884
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1885
+ var result = false;
1886
+ if (obj && evtName && evtName.type && handlerRef) {
1887
+ if (obj[strAddEventHelper]) {
1888
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1889
+ result = true;
1890
+ }
1891
+ else if (obj[strAttachEvent]) {
1892
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1893
+ result = true;
1894
+ }
1895
+ }
1896
+ return result;
1897
+ }
1898
+ function _doUnregister(target, events, evtName, unRegFn) {
1899
+ var idx = events.length;
1900
+ while (idx--) {
1901
+ var theEvent = events[idx];
1902
+ if (theEvent) {
1903
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1904
+ if (!unRegFn || unRegFn(theEvent)) {
1905
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1906
+ events.splice(idx, 1);
1907
+ }
1908
+ }
1909
+ }
1910
+ }
1911
+ }
1912
+ function _unregisterEvents(target, evtName, unRegFn) {
1913
+ if (evtName.type) {
1914
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1915
+ }
1916
+ else {
1917
+ var eventCache = elmNodeData.get(target, strEvents, {});
1918
+ objForEachKey(eventCache, function (evtType, events) {
1919
+ _doUnregister(target, events, evtName, unRegFn);
1920
+ });
1921
+ if (objKeys(eventCache).length === 0) {
1922
+ elmNodeData.kill(target, strEvents);
1923
+ }
1924
+ }
1925
+ }
1926
+ function mergeEvtNamespace(theNamespace, namespaces) {
1927
+ var newNamespaces;
1928
+ if (namespaces) {
1929
+ if (isArray(namespaces)) {
1930
+ newNamespaces = [theNamespace].concat(namespaces);
1931
+ }
1932
+ else {
1933
+ newNamespaces = [theNamespace, namespaces];
1934
+ }
1935
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1936
+ }
1937
+ else {
1938
+ newNamespaces = theNamespace;
1939
+ }
1940
+ return newNamespaces;
1941
+ }
1942
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1943
+ if (useCapture === void 0) { useCapture = false; }
1944
+ var result = false;
1945
+ if (target) {
1946
+ try {
1947
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1948
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1949
+ if (result && elmNodeData.accept(target)) {
1950
+ var registeredEvent = {
1951
+ guid: _guid++,
1952
+ evtName: evtName,
1953
+ handler: handlerRef,
1954
+ capture: useCapture
1955
+ };
1956
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1957
+ }
1958
+ }
1959
+ catch (e) {
1960
+ }
1961
+ }
1962
+ return result;
1963
+ }
1964
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
1965
+ if (useCapture === void 0) { useCapture = false; }
1966
+ if (target) {
1967
+ try {
1968
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
1969
+ var found_1 = false;
1970
+ _unregisterEvents(target, evtName_1, function (regEvent) {
1971
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
1972
+ found_1 = true;
1973
+ return true;
1974
+ }
1975
+ return false;
1976
+ });
1977
+ if (!found_1) {
1978
+ _doDetach(target, evtName_1, handlerRef, useCapture);
1979
+ }
1980
+ }
1981
+ catch (e) {
1982
+ }
1983
+ }
1984
+ }
1985
+ function addEventHandler(eventName, callback, evtNamespace) {
1321
1986
  var result = false;
1322
1987
  var w = getWindow();
1323
1988
  if (w) {
1324
- result = attachEvent(w, eventName, callback);
1325
- result = attachEvent(w["body"], eventName, callback) || result;
1989
+ result = eventOn(w, eventName, callback, evtNamespace);
1990
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1326
1991
  }
1327
1992
  var doc = getDocument();
1328
1993
  if (doc) {
1329
- result = attachEvent(doc, eventName, callback) || result;
1994
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
1330
1995
  }
1331
1996
  return result;
1332
1997
  }
1333
- function addEventListeners(events, listener, excludeEvents) {
1998
+ function removeEventHandler(eventName, callback, evtNamespace) {
1999
+ var w = getWindow();
2000
+ if (w) {
2001
+ eventOff(w, eventName, callback, evtNamespace);
2002
+ eventOff(w["body"], eventName, callback, evtNamespace);
2003
+ }
2004
+ var doc = getDocument();
2005
+ if (doc) {
2006
+ eventOff(doc, eventName, callback, evtNamespace);
2007
+ }
2008
+ }
2009
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
1334
2010
  var added = false;
1335
- if (listener && events && isArray(events)) {
1336
- var excluded_1 = [];
2011
+ if (listener && events && events.length > 0) {
1337
2012
  arrForEach(events, function (name) {
1338
- if (isString(name)) {
2013
+ if (name) {
1339
2014
  if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
1340
- added = addEventHandler(name, listener) || added;
1341
- }
1342
- else {
1343
- excluded_1.push(name);
2015
+ added = addEventHandler(name, listener, evtNamespace) || added;
1344
2016
  }
1345
2017
  }
1346
2018
  });
1347
- if (!added && excluded_1.length > 0) {
1348
- added = addEventListeners(excluded_1, listener);
2019
+ }
2020
+ return added;
2021
+ }
2022
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
2023
+ var added = false;
2024
+ if (listener && events && isArray(events)) {
2025
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
2026
+ if (!added && excludeEvents && excludeEvents.length > 0) {
2027
+ added = _addEventListeners(events, listener, null, evtNamespace);
1349
2028
  }
1350
2029
  }
1351
2030
  return added;
1352
2031
  }
1353
- function addPageUnloadEventListener(listener, excludeEvents) {
1354
- return addEventListeners(["beforeunload", "unload", "pagehide"], listener, excludeEvents);
2032
+ function removeEventListeners(events, listener, evtNamespace) {
2033
+ if (events && isArray(events)) {
2034
+ arrForEach(events, function (name) {
2035
+ if (name) {
2036
+ removeEventHandler(name, listener, evtNamespace);
2037
+ }
2038
+ });
2039
+ }
2040
+ }
2041
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
2042
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
1355
2043
  }
1356
- function addPageHideEventListener(listener, excludeEvents) {
2044
+ function removePageUnloadEventListener(listener, evtNamespace) {
2045
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
2046
+ }
2047
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
1357
2048
  function _handlePageVisibility(evt) {
1358
2049
  var doc = getDocument();
1359
2050
  if (listener && doc && doc.visibilityState === "hidden") {
1360
2051
  listener(evt);
1361
2052
  }
1362
2053
  }
1363
- var pageUnloadAdded = false;
1364
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
1365
- pageUnloadAdded = addEventHandler(strPageHide, listener);
1366
- }
2054
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2055
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
1367
2056
  if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1368
- pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
2057
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
1369
2058
  }
1370
2059
  if (!pageUnloadAdded && excludeEvents) {
1371
- pageUnloadAdded = addPageHideEventListener(listener);
2060
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
1372
2061
  }
1373
2062
  return pageUnloadAdded;
1374
2063
  }
1375
- function addPageShowEventListener(listener, excludeEvents) {
2064
+ function removePageHideEventListener(listener, evtNamespace) {
2065
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2066
+ removeEventListeners([strPageHide], listener, newNamespaces);
2067
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2068
+ }
2069
+ function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
1376
2070
  function _handlePageVisibility(evt) {
1377
2071
  var doc = getDocument();
1378
2072
  if (listener && doc && doc.visibilityState === "visible") {
1379
2073
  listener(evt);
1380
2074
  }
1381
2075
  }
1382
- var pageShowAdded = false;
1383
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageShow) === -1) {
1384
- pageShowAdded = addEventHandler(strPageShow, listener);
1385
- }
1386
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1387
- pageShowAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageShowAdded;
1388
- }
2076
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2077
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
2078
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
1389
2079
  if (!pageShowAdded && excludeEvents) {
1390
- pageShowAdded = addPageShowEventListener(listener);
2080
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
1391
2081
  }
1392
2082
  return pageShowAdded;
1393
2083
  }
2084
+ function removePageShowEventListener(listener, evtNamespace) {
2085
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2086
+ removeEventListeners([strPageShow], listener, newNamespaces);
2087
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2088
+ }
2089
+
1394
2090
  function perfNow() {
1395
2091
  var perf = getPerformance();
1396
2092
  if (perf && perf.now) {
@@ -1399,56 +2095,20 @@
1399
2095
  return dateNow();
1400
2096
  }
1401
2097
 
1402
- var ValueKind = {
1403
- NotSet: 0,
1404
- Pii_DistinguishedName: 1,
1405
- Pii_GenericData: 2,
1406
- Pii_IPV4Address: 3,
1407
- Pii_IPv6Address: 4,
1408
- Pii_MailSubject: 5,
1409
- Pii_PhoneNumber: 6,
1410
- Pii_QueryString: 7,
1411
- Pii_SipAddress: 8,
1412
- Pii_SmtpAddress: 9,
1413
- Pii_Identity: 10,
1414
- Pii_Uri: 11,
1415
- Pii_Fqdn: 12,
1416
- Pii_IPV4AddressLegacy: 13,
1417
- CustomerContent_GenericContent: 32
1418
- };
1419
- var EventLatency = {
1420
- Normal: 1 ,
1421
- CostDeferred: 2 ,
1422
- RealTime: 3 ,
1423
- Immediate: 4
1424
- };
1425
- var EventPropertyType = {
1426
- Unspecified: 0,
1427
- String: 1,
1428
- Int32: 2,
1429
- UInt32: 3,
1430
- Int64: 4,
1431
- UInt64: 5,
1432
- Double: 6,
1433
- Bool: 7,
1434
- Guid: 8,
1435
- DateTime: 9
1436
- };
1437
- 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 });
1438
-
1439
2098
  var _a$1;
1440
- var Version = '3.1.10';
2099
+ var Version = '3.2.1';
1441
2100
  var FullVersionString = "1DS-Web-JS-" + Version;
1442
2101
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
1443
2102
  var strWithCredentials = "withCredentials";
2103
+ var strTimeout = "timeout";
1444
2104
  var _fieldTypeEventPropMap = (_a$1 = {},
1445
- _a$1[0 ] = EventPropertyType.Unspecified,
1446
- _a$1[2 ] = EventPropertyType.Double,
1447
- _a$1[1 ] = EventPropertyType.String,
1448
- _a$1[3 ] = EventPropertyType.Bool,
1449
- _a$1[4096 | 2 ] = EventPropertyType.Double,
1450
- _a$1[4096 | 1 ] = EventPropertyType.String,
1451
- _a$1[4096 | 3 ] = EventPropertyType.Bool,
2105
+ _a$1[0 ] = 0 ,
2106
+ _a$1[2 ] = 6 ,
2107
+ _a$1[1 ] = 1 ,
2108
+ _a$1[3 ] = 7 ,
2109
+ _a$1[4096 | 2 ] = 6 ,
2110
+ _a$1[4096 | 1 ] = 1 ,
2111
+ _a$1[4096 | 3 ] = 7 ,
1452
2112
  _a$1);
1453
2113
  Boolean(getDocument());
1454
2114
  var isWindowObjectAvailable = Boolean(getWindow());
@@ -1515,7 +2175,7 @@
1515
2175
  if (encodedTypeValue !== -1 && propType !== -1) {
1516
2176
  encodedTypeValue |= propType;
1517
2177
  }
1518
- else if (propType === EventPropertyType.Double) {
2178
+ else if (propType === 6 ) {
1519
2179
  encodedTypeValue = propType;
1520
2180
  }
1521
2181
  }
@@ -1561,7 +2221,7 @@
1561
2221
  }
1562
2222
  var getTime = perfNow;
1563
2223
  function isValueKind(value) {
1564
- if (value === ValueKind.NotSet || ((value > ValueKind.NotSet && value <= ValueKind.Pii_IPV4AddressLegacy) || value === ValueKind.CustomerContent_GenericContent)) {
2224
+ if (value === 0 || ((value > 0 && value <= 13 ) || value === 32 )) {
1565
2225
  return true;
1566
2226
  }
1567
2227
  return false;
@@ -1612,7 +2272,7 @@
1612
2272
  function isChromium() {
1613
2273
  return !!getGlobalInst("chrome");
1614
2274
  }
1615
- function openXhr(method, urlString, withCredentials, disabled, isSync) {
2275
+ function openXhr(method, urlString, withCredentials, disabled, isSync, timeout) {
1616
2276
  if (disabled === void 0) { disabled = false; }
1617
2277
  if (isSync === void 0) { isSync = false; }
1618
2278
  function _wrapSetXhrProp(xhr, prop, value) {
@@ -1633,6 +2293,9 @@
1633
2293
  if (withCredentials) {
1634
2294
  _wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
1635
2295
  }
2296
+ if (!isSync && timeout) {
2297
+ _wrapSetXhrProp(xhr, strTimeout, timeout);
2298
+ }
1636
2299
  return xhr;
1637
2300
  }
1638
2301
 
@@ -1661,6 +2324,8 @@
1661
2324
  var strUploadTime = "upload-time";
1662
2325
  var strApiKey = "apikey";
1663
2326
  var strMsaDeviceTicket = "AuthMsaDeviceTicket";
2327
+ var strAuthXToken = "AuthXToken";
2328
+ var strNoResponseBody = "NoResponseBody";
1664
2329
  var strMsfpc = "msfpc";
1665
2330
 
1666
2331
  function _getEventMsfpc(theEvent) {
@@ -1972,25 +2637,19 @@
1972
2637
  var RandomizationUpperThreshold = 1.2;
1973
2638
  var BaseBackoff = 3000;
1974
2639
  var MaxBackoff = 600000;
1975
- var RetryPolicy = /** @class */ (function () {
1976
- function RetryPolicy() {
1977
- }
1978
- RetryPolicy.shouldRetryForStatus = function (httpStatusCode) {
1979
- return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
1980
- || (httpStatusCode == 501)
1981
- || (httpStatusCode == 505));
1982
- };
1983
- RetryPolicy.getMillisToBackoffForRetry = function (retriesSoFar) {
1984
- var waitDuration = 0;
1985
- var minBackoff = BaseBackoff * RandomizationLowerThreshold;
1986
- var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
1987
- var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
1988
- waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
1989
- return Math.min(waitDuration, MaxBackoff);
1990
- };
1991
- return RetryPolicy;
1992
- }());
1993
- var RetryPolicy$1 = RetryPolicy;
2640
+ function retryPolicyShouldRetryForStatus(httpStatusCode) {
2641
+ return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
2642
+ || (httpStatusCode == 501)
2643
+ || (httpStatusCode == 505));
2644
+ }
2645
+ function retryPolicyGetMillisToBackoffForRetry(retriesSoFar) {
2646
+ var waitDuration = 0;
2647
+ var minBackoff = BaseBackoff * RandomizationLowerThreshold;
2648
+ var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
2649
+ var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
2650
+ waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
2651
+ return Math.min(waitDuration, MaxBackoff);
2652
+ }
1994
2653
 
1995
2654
  var SecToMsMultiplier = 1000;
1996
2655
  var KillSwitch = /** @class */ (function () {
@@ -2084,6 +2743,8 @@
2084
2743
  var EVTClockSkewManager = ClockSkewManager;
2085
2744
 
2086
2745
  var _a;
2746
+ var strSendAttempt = "sendAttempt";
2747
+ var _noResponseQs = "&" + strNoResponseBody + "=true";
2087
2748
  var _eventActionMap = (_a = {},
2088
2749
  _a[1 ] = strRequeue,
2089
2750
  _a[100 ] = strRequeue,
@@ -2093,11 +2754,19 @@
2093
2754
  _a);
2094
2755
  var _collectorQsHeaders = {};
2095
2756
  var _collectorHeaderToQs = {};
2096
- function _addCollectorHeaderQsMapping(qsName, headerName) {
2757
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
2097
2758
  _collectorQsHeaders[qsName] = headerName;
2098
- _collectorHeaderToQs[headerName] = qsName;
2759
+ if (allowQs !== false) {
2760
+ _collectorHeaderToQs[headerName] = qsName;
2761
+ }
2099
2762
  }
2100
- _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);
2763
+ _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);
2764
+ _addCollectorHeaderQsMapping(strClientVersion, strClientVersion);
2765
+ _addCollectorHeaderQsMapping(strClientId, "Client-Id");
2766
+ _addCollectorHeaderQsMapping(strApiKey, strApiKey);
2767
+ _addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
2768
+ _addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
2769
+ _addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
2101
2770
  function _getResponseText(xhr) {
2102
2771
  try {
2103
2772
  return xhr.responseText;
@@ -2136,7 +2805,7 @@
2136
2805
  }
2137
2806
  }
2138
2807
  var HttpManager = /** @class */ (function () {
2139
- function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {
2808
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
2140
2809
  this._responseHandlers = [];
2141
2810
  var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
2142
2811
  var _killSwitch = new EVTKillSwitch();
@@ -2156,6 +2825,8 @@
2156
2825
  var _cookieMgr;
2157
2826
  var _isUnloading = false;
2158
2827
  var _useHeaders = false;
2828
+ var _xhrTimeout;
2829
+ var _disableXhrSync;
2159
2830
  dynamicProto(HttpManager, this, function (_self) {
2160
2831
  var _sendCredentials = true;
2161
2832
  _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
@@ -2164,7 +2835,7 @@
2164
2835
  channelConfig = {};
2165
2836
  }
2166
2837
  _urlString = endpointUrl + _urlString;
2167
- _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
2838
+ _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
2168
2839
  _core = core;
2169
2840
  _cookieMgr = core.getCookieMgr();
2170
2841
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -2175,9 +2846,13 @@
2175
2846
  if (!isUndefined(channelConfig.enableCompoundKey)) {
2176
2847
  enableCompoundKey = !!channelConfig.enableCompoundKey;
2177
2848
  }
2849
+ _xhrTimeout = channelConfig.xhrTimeout;
2850
+ _disableXhrSync = channelConfig.disableXhrSync;
2178
2851
  _useBeacons = !isReactNative();
2179
2852
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
2180
2853
  var syncHttpInterface = httpInterface;
2854
+ var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
2855
+ var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
2181
2856
  if (!httpInterface) {
2182
2857
  _customHttpInterface = false;
2183
2858
  var location_1 = getLocation();
@@ -2209,8 +2884,8 @@
2209
2884
  _sendInterfaces = (_a = {},
2210
2885
  _a[0 ] = httpInterface,
2211
2886
  _a[1 ] = syncHttpInterface || _getSenderInterface([1 , 2 , 3 ], true),
2212
- _a[2 ] = _getSenderInterface([3 , 2 , 1 ], true) || syncHttpInterface,
2213
- _a[3 ] = _getSenderInterface([2 , 3 , 1 ], true) || syncHttpInterface,
2887
+ _a[2 ] = beaconHttpInterface || _getSenderInterface([3 , 2 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
2888
+ _a[3 ] = fetchSyncHttpInterface || _getSenderInterface([2 , 3 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
2214
2889
  _a);
2215
2890
  };
2216
2891
  function _getSenderInterface(transports, syncSupport) {
@@ -2250,6 +2925,9 @@
2250
2925
  function _xdrSendPost(payload, oncomplete, sync) {
2251
2926
  var xdr = new XDomainRequest();
2252
2927
  xdr.open(Method, payload.urlString);
2928
+ if (payload.timeout) {
2929
+ xdr.timeout = payload.timeout;
2930
+ }
2253
2931
  xdr.onload = function () {
2254
2932
  var response = _getResponseText(xdr);
2255
2933
  _doOnComplete(oncomplete, 200, {}, response);
@@ -2273,6 +2951,7 @@
2273
2951
  }
2274
2952
  function _fetchSendPost(payload, oncomplete, sync) {
2275
2953
  var _a;
2954
+ var theUrl = payload.urlString;
2276
2955
  var ignoreResponse = false;
2277
2956
  var responseHandled = false;
2278
2957
  var requestInit = (_a = {
@@ -2285,6 +2964,7 @@
2285
2964
  requestInit.keepalive = true;
2286
2965
  if (payload._sendReason === 2 ) {
2287
2966
  ignoreResponse = true;
2967
+ theUrl += _noResponseQs;
2288
2968
  }
2289
2969
  }
2290
2970
  if (_sendCredentials) {
@@ -2293,7 +2973,7 @@
2293
2973
  if (payload.headers && objKeys(payload.headers).length > 0) {
2294
2974
  requestInit.headers = payload.headers;
2295
2975
  }
2296
- fetch(payload.urlString, requestInit).then(function (response) {
2976
+ fetch(theUrl, requestInit).then(function (response) {
2297
2977
  var headerMap = {};
2298
2978
  var responseText = "";
2299
2979
  if (response.headers) {
@@ -2321,8 +3001,17 @@
2321
3001
  responseHandled = true;
2322
3002
  _doOnComplete(oncomplete, 200, {});
2323
3003
  }
3004
+ if (!responseHandled && payload.timeout > 0) {
3005
+ _postManager._setTimeoutOverride(function () {
3006
+ if (!responseHandled) {
3007
+ responseHandled = true;
3008
+ _doOnComplete(oncomplete, 500, {});
3009
+ }
3010
+ }, payload.timeout);
3011
+ }
2324
3012
  }
2325
3013
  function _xhrSendPost(payload, oncomplete, sync) {
3014
+ var theUrl = payload.urlString;
2326
3015
  function _appendHeader(theHeaders, xhr, name) {
2327
3016
  if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
2328
3017
  var value = xhr.getResponseHeader(name);
@@ -2347,45 +3036,49 @@
2347
3036
  function xhrComplete(xhr, responseTxt) {
2348
3037
  _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
2349
3038
  }
2350
- var xhRequest = openXhr(Method, payload.urlString, _sendCredentials, true, sync);
3039
+ if (sync && payload.disableXhrSync) {
3040
+ sync = false;
3041
+ }
3042
+ var xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);
2351
3043
  objForEachKey(payload.headers, function (name, value) {
2352
- xhRequest.setRequestHeader(name, value);
3044
+ xhrRequest.setRequestHeader(name, value);
2353
3045
  });
2354
- xhRequest.onload = function () {
2355
- var response = _getResponseText(xhRequest);
2356
- xhrComplete(xhRequest, response);
3046
+ xhrRequest.onload = function () {
3047
+ var response = _getResponseText(xhrRequest);
3048
+ xhrComplete(xhrRequest, response);
2357
3049
  _handleCollectorResponse(response);
2358
3050
  };
2359
- xhRequest.onerror = function () {
2360
- xhrComplete(xhRequest);
3051
+ xhrRequest.onerror = function () {
3052
+ xhrComplete(xhrRequest);
2361
3053
  };
2362
- xhRequest.ontimeout = function () {
2363
- xhrComplete(xhRequest);
3054
+ xhrRequest.ontimeout = function () {
3055
+ xhrComplete(xhrRequest);
2364
3056
  };
2365
- xhRequest.send(payload.data);
3057
+ xhrRequest.send(payload.data);
2366
3058
  }
2367
3059
  function _doOnComplete(oncomplete, status, headers, response) {
2368
3060
  try {
2369
3061
  oncomplete(status, headers, response);
2370
3062
  }
2371
3063
  catch (e) {
2372
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));
3064
+ _throwInternal(_postManager.diagLog(), 2 , 518 , dumpObj(e));
2373
3065
  }
2374
3066
  }
2375
3067
  function _beaconSendPost(payload, oncomplete, sync) {
2376
3068
  var internalPayloadData = payload;
2377
3069
  var status = 200;
2378
3070
  var thePayload = internalPayloadData._thePayload;
3071
+ var theUrl = payload.urlString + _noResponseQs;
2379
3072
  try {
2380
3073
  var nav_1 = getNavigator();
2381
- if (!nav_1.sendBeacon(payload.urlString, payload.data)) {
3074
+ if (!nav_1.sendBeacon(theUrl, payload.data)) {
2382
3075
  if (thePayload) {
2383
3076
  var droppedBatches_1 = [];
2384
3077
  arrForEach(thePayload.batches, function (theBatch) {
2385
3078
  if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
2386
3079
  var theEvents = theBatch.events();
2387
3080
  for (var lp = 0; lp < theEvents.length; lp++) {
2388
- if (!nav_1.sendBeacon(payload.urlString, _serializer.getEventBlob(theEvents[lp]))) {
3081
+ if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
2389
3082
  droppedBatches_1.push(theBatch.split(lp));
2390
3083
  break;
2391
3084
  }
@@ -2403,7 +3096,7 @@
2403
3096
  }
2404
3097
  }
2405
3098
  catch (ex) {
2406
- _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + ex);
3099
+ _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
2407
3100
  status = 0;
2408
3101
  }
2409
3102
  finally {
@@ -2567,7 +3260,7 @@
2567
3260
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
2568
3261
  }
2569
3262
  catch (ex) {
2570
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + dumpObj(ex));
3263
+ _throwInternal(_postManager.diagLog(), 2 , 48 , "Unexpected Exception sending batch: " + dumpObj(ex));
2571
3264
  }
2572
3265
  }
2573
3266
  function _buildRequestDetails(thePayload, useHeaders) {
@@ -2576,8 +3269,21 @@
2576
3269
  hdrs: {},
2577
3270
  useHdrs: false
2578
3271
  };
2579
- requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
2580
- requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
3272
+ if (!useHeaders) {
3273
+ objForEachKey(_headers, function (name, value) {
3274
+ if (_collectorHeaderToQs[name]) {
3275
+ _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
3276
+ }
3277
+ else {
3278
+ requestDetails.hdrs[name] = value;
3279
+ requestDetails.useHdrs = true;
3280
+ }
3281
+ });
3282
+ }
3283
+ else {
3284
+ requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
3285
+ requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
3286
+ }
2581
3287
  _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
2582
3288
  _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
2583
3289
  var apiQsKeys = "";
@@ -2628,7 +3334,6 @@
2628
3334
  var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
2629
3335
  useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
2630
3336
  var sendEventStart_1 = getTime();
2631
- var strSendAttempt_1 = "sendAttempt";
2632
3337
  doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
2633
3338
  for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
2634
3339
  var theBatch = thePayload.batches[batchLp];
@@ -2641,7 +3346,7 @@
2641
3346
  _setTimingValue(timings, "serializationStart", serializationStart);
2642
3347
  _setTimingValue(timings, "serializationCompleted", serializationCompleted);
2643
3348
  }
2644
- telemetryItem[strSendAttempt_1] > 0 ? telemetryItem[strSendAttempt_1]++ : telemetryItem[strSendAttempt_1] = 1;
3349
+ telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
2645
3350
  }
2646
3351
  }
2647
3352
  _sendBatchesNotification(thePayload.batches, (1000 + (sendReason || 0 )), thePayload.sendType, true);
@@ -2650,8 +3355,12 @@
2650
3355
  urlString: requestDetails_1.url,
2651
3356
  headers: requestDetails_1.hdrs,
2652
3357
  _thePayload: thePayload,
2653
- _sendReason: sendReason
3358
+ _sendReason: sendReason,
3359
+ timeout: _xhrTimeout
2654
3360
  };
3361
+ if (!isUndefined(_disableXhrSync)) {
3362
+ orgPayloadData.disableXhrSync = !!_disableXhrSync;
3363
+ }
2655
3364
  if (useHeaders_1) {
2656
3365
  if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
2657
3366
  orgPayloadData.headers[strCacheControl] = defaultCacheControl;
@@ -2689,7 +3398,9 @@
2689
3398
  var hookData_1 = {
2690
3399
  data: orgPayloadData.data,
2691
3400
  urlString: orgPayloadData.urlString,
2692
- headers: extend({}, orgPayloadData.headers)
3401
+ headers: extend({}, orgPayloadData.headers),
3402
+ timeout: orgPayloadData.timeout,
3403
+ disableXhrSync: orgPayloadData.disableXhrSync
2693
3404
  };
2694
3405
  var senderCalled_1 = false;
2695
3406
  doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
@@ -2754,11 +3465,11 @@
2754
3465
  });
2755
3466
  });
2756
3467
  }
2757
- if (status == 200) {
3468
+ if (status == 200 || status == 204) {
2758
3469
  reason = 200 ;
2759
3470
  return;
2760
3471
  }
2761
- if (!RetryPolicy$1.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
3472
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
2762
3473
  shouldRetry = false;
2763
3474
  }
2764
3475
  reason = 9000 + (status % 1000);
@@ -2767,17 +3478,20 @@
2767
3478
  reason = 100 ;
2768
3479
  var retryCount_1 = thePayload.retryCnt;
2769
3480
  if (thePayload.sendType === 0 ) {
2770
- if (retryCount_1 < maxRetries) {
3481
+ if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
2771
3482
  isRetrying = true;
2772
3483
  _doAction(function () {
2773
3484
  if (thePayload.sendType === 0 ) {
2774
3485
  _outstandingRequests--;
2775
3486
  }
2776
3487
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
2777
- }, _isUnloading, RetryPolicy$1.getMillisToBackoffForRetry(retryCount_1));
3488
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
2778
3489
  }
2779
3490
  else {
2780
3491
  backOffTrans = true;
3492
+ if (_isUnloading) {
3493
+ reason = 8001 ;
3494
+ }
2781
3495
  }
2782
3496
  }
2783
3497
  }
@@ -2867,7 +3581,7 @@
2867
3581
  responseHandlers[i](responseText);
2868
3582
  }
2869
3583
  catch (e) {
2870
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
3584
+ _throwInternal(_postManager.diagLog(), 1 , 519 , "Response handler failed: " + e);
2871
3585
  }
2872
3586
  }
2873
3587
  if (responseText) {
@@ -2891,7 +3605,7 @@
2891
3605
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
2892
3606
  }
2893
3607
  catch (e) {
2894
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, "send request notification failed: " + e);
3608
+ _throwInternal(_postManager.diagLog(), 1 , 74 , "send request notification failed: " + e);
2895
3609
  }
2896
3610
  }, sendSync || isSyncRequest_1, 0);
2897
3611
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
@@ -2923,19 +3637,23 @@
2923
3637
  var MaxNumberEventPerBatch = 500;
2924
3638
  var EventsDroppedAtOneTime = 20;
2925
3639
  var MaxSendAttempts = 6;
3640
+ var MaxSyncUnloadSendAttempts = 2;
2926
3641
  var MaxBackoffCount = 4;
2927
3642
  var globalContext = isWindowObjectAvailable ? window : undefined;
2928
3643
  var MaxConnections = 2;
2929
- var MaxRetries = 1;
3644
+ var MaxRequestRetriesBeforeBackoff = 1;
2930
3645
  var strEventsDiscarded = "eventsDiscarded";
2931
3646
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
3647
+ var strMaxEventRetryAttempts = "maxEventRetryAttempts";
3648
+ var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
3649
+ var strAddUnloadCb = "addUnloadCb";
2932
3650
  var PostChannel = /** @class */ (function (_super) {
2933
3651
  __extendsFn(PostChannel, _super);
2934
3652
  function PostChannel() {
2935
3653
  var _this = _super.call(this) || this;
2936
3654
  _this.identifier = "PostChannel";
2937
3655
  _this.priority = 1011;
2938
- _this.version = '3.1.10';
3656
+ _this.version = '3.2.1';
2939
3657
  var _config;
2940
3658
  var _isTeardownCalled = false;
2941
3659
  var _flushCallbackQueue = [];
@@ -2960,18 +3678,12 @@
2960
3678
  var _delayedBatchReason;
2961
3679
  var _optimizeObject = true;
2962
3680
  var _isPageUnloadTriggered = false;
3681
+ var _disableXhrSync = false;
3682
+ var _maxEventSendAttempts = MaxSendAttempts;
3683
+ var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
3684
+ var _evtNamespace;
2963
3685
  dynamicProto(PostChannel, _this, function (_self, _base) {
2964
- _initializeProfiles();
2965
- _clearQueues();
2966
- _setAutoLimits();
2967
- _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
2968
- requeue: _requeueEvents,
2969
- send: _sendingEvent,
2970
- sent: _eventsSentEvent,
2971
- drop: _eventsDropped,
2972
- rspFail: _eventsResponseFail,
2973
- oth: _otherEvent
2974
- });
3686
+ _initDefaults();
2975
3687
  _self["_getDbgPlgTargets"] = function () {
2976
3688
  return [_httpManager];
2977
3689
  };
@@ -2979,58 +3691,53 @@
2979
3691
  doPerf(core, function () { return "PostChannel:initialize"; }, function () {
2980
3692
  var extendedCore = core;
2981
3693
  _base.initialize(coreConfig, core, extensions);
2982
- _self.setInitialized(false);
2983
- var ctx = _self._getTelCtx();
2984
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
2985
- _config = ctx.getExtCfg(_self.identifier);
2986
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
2987
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
2988
- _optimizeObject = !_config.disableOptimizeObj && isChromium();
2989
- var existingGetWParamMethod = extendedCore.getWParam;
2990
- extendedCore.getWParam = function () {
2991
- var wparam = 0;
2992
- if (_config.ignoreMc1Ms0CookieProcessing) {
2993
- wparam = wparam | 2;
2994
- }
2995
- return wparam | existingGetWParamMethod();
2996
- };
2997
- if (_config.eventsLimitInMem > 0) {
2998
- _queueSizeLimit = _config.eventsLimitInMem;
2999
- }
3000
- if (_config.immediateEventLimit > 0) {
3001
- _immediateQueueSizeLimit = _config.immediateEventLimit;
3002
- }
3003
- if (_config.autoFlushEventsLimit > 0) {
3004
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3005
- }
3006
- _setAutoLimits();
3007
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
3008
- _xhrOverride = _config.httpXHROverride;
3009
- }
3010
- if (isValueAssigned(coreConfig.anonCookieName)) {
3011
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
3012
- }
3013
- _httpManager.sendHook = _config.payloadPreprocessor;
3014
- _httpManager.sendListener = _config.payloadListener;
3015
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
3016
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
3017
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
3018
- function _handleUnloadEvents(evt) {
3019
- var theEvt = evt || getWindow().event;
3020
- if (theEvt.type !== "beforeunload") {
3021
- _isPageUnloadTriggered = true;
3022
- _httpManager.setUnloading(_isPageUnloadTriggered);
3694
+ try {
3695
+ var hasAddUnloadCb = !!core[strAddUnloadCb];
3696
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
3697
+ var ctx = _self._getTelCtx();
3698
+ coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
3699
+ _config = ctx.getExtCfg(_self.identifier);
3700
+ _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
3701
+ _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
3702
+ _optimizeObject = !_config.disableOptimizeObj && isChromium();
3703
+ _hookWParam(extendedCore);
3704
+ if (_config.eventsLimitInMem > 0) {
3705
+ _queueSizeLimit = _config.eventsLimitInMem;
3023
3706
  }
3024
- _releaseAllQueues(2 , 2 );
3707
+ if (_config.immediateEventLimit > 0) {
3708
+ _immediateQueueSizeLimit = _config.immediateEventLimit;
3709
+ }
3710
+ if (_config.autoFlushEventsLimit > 0) {
3711
+ _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3712
+ }
3713
+ _disableXhrSync = _config.disableXhrSync;
3714
+ if (isNumber(_config[strMaxEventRetryAttempts])) {
3715
+ _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
3716
+ }
3717
+ if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
3718
+ _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
3719
+ }
3720
+ _setAutoLimits();
3721
+ if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
3722
+ _xhrOverride = _config.httpXHROverride;
3723
+ }
3724
+ if (isValueAssigned(coreConfig.anonCookieName)) {
3725
+ _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
3726
+ }
3727
+ _httpManager.sendHook = _config.payloadPreprocessor;
3728
+ _httpManager.sendListener = _config.payloadListener;
3729
+ var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
3730
+ _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
3731
+ _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
3732
+ var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
3733
+ addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
3734
+ addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
3735
+ addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
3736
+ }
3737
+ catch (e) {
3738
+ _self.setInitialized(false);
3739
+ throw e;
3025
3740
  }
3026
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
3027
- addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
3028
- addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
3029
- addPageShowEventListener(function (evt) {
3030
- _isPageUnloadTriggered = false;
3031
- _httpManager.setUnloading(_isPageUnloadTriggered);
3032
- }, coreConfig.disablePageShowEvents);
3033
- _self.setInitialized(true);
3034
3741
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
3035
3742
  };
3036
3743
  _self.processTelemetry = function (ev, itemCtx) {
@@ -3059,12 +3766,43 @@
3059
3766
  }
3060
3767
  _self.processNext(event, itemCtx);
3061
3768
  };
3769
+ _self._doTeardown = function (unloadCtx, unloadState) {
3770
+ _releaseAllQueues(2 , 2 );
3771
+ _isTeardownCalled = true;
3772
+ _httpManager.teardown();
3773
+ removePageUnloadEventListener(null, _evtNamespace);
3774
+ removePageHideEventListener(null, _evtNamespace);
3775
+ removePageShowEventListener(null, _evtNamespace);
3776
+ _initDefaults();
3777
+ };
3778
+ function _hookWParam(extendedCore) {
3779
+ var existingGetWParamMethod = extendedCore.getWParam;
3780
+ extendedCore.getWParam = function () {
3781
+ var wparam = 0;
3782
+ if (_config.ignoreMc1Ms0CookieProcessing) {
3783
+ wparam = wparam | 2;
3784
+ }
3785
+ return wparam | existingGetWParamMethod();
3786
+ };
3787
+ }
3788
+ function _handleUnloadEvents(evt) {
3789
+ var theEvt = evt || getWindow().event;
3790
+ if (theEvt.type !== "beforeunload") {
3791
+ _isPageUnloadTriggered = true;
3792
+ _httpManager.setUnloading(_isPageUnloadTriggered);
3793
+ }
3794
+ _releaseAllQueues(2 , 2 );
3795
+ }
3796
+ function _handleShowEvents(evt) {
3797
+ _isPageUnloadTriggered = false;
3798
+ _httpManager.setUnloading(_isPageUnloadTriggered);
3799
+ }
3062
3800
  function _addEventToQueues(event, append) {
3063
3801
  if (!event.sendAttempt) {
3064
3802
  event.sendAttempt = 0;
3065
3803
  }
3066
3804
  if (!event.latency) {
3067
- event.latency = EventLatency.Normal;
3805
+ event.latency = 1 ;
3068
3806
  }
3069
3807
  if (event.ext && event.ext["trace"]) {
3070
3808
  delete (event.ext["trace"]);
@@ -3083,7 +3821,7 @@
3083
3821
  }
3084
3822
  if (event.sync) {
3085
3823
  if (_currentBackoffCount || _paused) {
3086
- event.latency = EventLatency.RealTime;
3824
+ event.latency = 3 ;
3087
3825
  event.sync = false;
3088
3826
  }
3089
3827
  else {
@@ -3099,7 +3837,7 @@
3099
3837
  var evtLatency = event.latency;
3100
3838
  var queueSize = _queueSize;
3101
3839
  var queueLimit = _queueSizeLimit;
3102
- if (evtLatency === EventLatency.Immediate) {
3840
+ if (evtLatency === 4 ) {
3103
3841
  queueSize = _immediateQueueSize;
3104
3842
  queueLimit = _immediateQueueSizeLimit;
3105
3843
  }
@@ -3108,10 +3846,10 @@
3108
3846
  eventDropped = !_addEventToProperQueue(event, append);
3109
3847
  }
3110
3848
  else {
3111
- var dropLatency = EventLatency.Normal;
3849
+ var dropLatency = 1 ;
3112
3850
  var dropNumber = EventsDroppedAtOneTime;
3113
- if (evtLatency === EventLatency.Immediate) {
3114
- dropLatency = EventLatency.Immediate;
3851
+ if (evtLatency === 4 ) {
3852
+ dropLatency = 4 ;
3115
3853
  dropNumber = 1;
3116
3854
  }
3117
3855
  eventDropped = true;
@@ -3129,7 +3867,7 @@
3129
3867
  _setAutoLimits();
3130
3868
  var doFlush = _queueSize > eventLimit;
3131
3869
  if (!doFlush && _autoFlushBatchLimit > 0) {
3132
- for (var latency = EventLatency.Normal; !doFlush && latency <= EventLatency.RealTime; latency++) {
3870
+ for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
3133
3871
  var batchQueue = _batchQueues[latency];
3134
3872
  if (batchQueue && batchQueue.batches) {
3135
3873
  arrForEach(batchQueue.batches, function (theBatch) {
@@ -3142,11 +3880,6 @@
3142
3880
  }
3143
3881
  _performAutoFlush(true, doFlush);
3144
3882
  };
3145
- _self.teardown = function () {
3146
- _releaseAllQueues(2 , 2 );
3147
- _isTeardownCalled = true;
3148
- _httpManager.teardown();
3149
- };
3150
3883
  _self.pause = function () {
3151
3884
  _clearScheduledTimer();
3152
3885
  _paused = true;
@@ -3188,7 +3921,7 @@
3188
3921
  _clearScheduledTimer();
3189
3922
  sendReason = sendReason || 1 ;
3190
3923
  if (async) {
3191
- _queueBatches(EventLatency.Normal, 0 , sendReason);
3924
+ _queueBatches(1 , 0 , sendReason);
3192
3925
  _resetQueueCounts();
3193
3926
  if (_flushCallbackTimerId == null) {
3194
3927
  _flushCallbackTimerId = _createTimer(function () {
@@ -3200,7 +3933,7 @@
3200
3933
  }
3201
3934
  }
3202
3935
  else {
3203
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 1 , sendReason);
3936
+ _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
3204
3937
  if (callback !== null && callback !== undefined) {
3205
3938
  callback();
3206
3939
  }
@@ -3235,7 +3968,7 @@
3235
3968
  if (immediateTimeOut >= 0) {
3236
3969
  _immediateTimerId = _createTimer(function () {
3237
3970
  _immediateTimerId = null;
3238
- _sendEventsForLatencyAndAbove(EventLatency.Immediate, 0 , 1 );
3971
+ _sendEventsForLatencyAndAbove(4 , 0 , 1 );
3239
3972
  _scheduleTimer();
3240
3973
  }, immediateTimeOut);
3241
3974
  }
@@ -3245,7 +3978,7 @@
3245
3978
  if (_hasEvents()) {
3246
3979
  _scheduledTimerId = _createTimer(function () {
3247
3980
  _scheduledTimerId = null;
3248
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? EventLatency.RealTime : EventLatency.Normal, 0 , 1 );
3981
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
3249
3982
  _timerCount++;
3250
3983
  _timerCount %= 2;
3251
3984
  _scheduleTimer();
@@ -3270,13 +4003,53 @@
3270
4003
  _scheduleTimer();
3271
4004
  }
3272
4005
  };
4006
+ function _initDefaults() {
4007
+ _config = null;
4008
+ _isTeardownCalled = false;
4009
+ _flushCallbackQueue = [];
4010
+ _flushCallbackTimerId = null;
4011
+ _paused = false;
4012
+ _immediateQueueSize = 0;
4013
+ _immediateQueueSizeLimit = 500;
4014
+ _queueSize = 0;
4015
+ _queueSizeLimit = 10000;
4016
+ _profiles = {};
4017
+ _currentProfile = RT_PROFILE;
4018
+ _scheduledTimerId = null;
4019
+ _immediateTimerId = null;
4020
+ _currentBackoffCount = 0;
4021
+ _timerCount = 0;
4022
+ _xhrOverride = null;
4023
+ _batchQueues = {};
4024
+ _autoFlushEventsLimit = undefined;
4025
+ _autoFlushBatchLimit = 0;
4026
+ _delayedBatchSendLatency = -1;
4027
+ _delayedBatchReason = null;
4028
+ _optimizeObject = true;
4029
+ _isPageUnloadTriggered = false;
4030
+ _disableXhrSync = false;
4031
+ _maxEventSendAttempts = MaxSendAttempts;
4032
+ _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
4033
+ _evtNamespace = null;
4034
+ _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
4035
+ requeue: _requeueEvents,
4036
+ send: _sendingEvent,
4037
+ sent: _eventsSentEvent,
4038
+ drop: _eventsDropped,
4039
+ rspFail: _eventsResponseFail,
4040
+ oth: _otherEvent
4041
+ });
4042
+ _initializeProfiles();
4043
+ _clearQueues();
4044
+ _setAutoLimits();
4045
+ }
3273
4046
  function _createTimer(theTimerFunc, timeOut) {
3274
4047
  if (timeOut === 0 && _currentBackoffCount) {
3275
4048
  timeOut = 1;
3276
4049
  }
3277
4050
  var timerMultiplier = 1000;
3278
4051
  if (_currentBackoffCount) {
3279
- timerMultiplier = RetryPolicy$1.getMillisToBackoffForRetry(_currentBackoffCount - 1);
4052
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
3280
4053
  }
3281
4054
  return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
3282
4055
  }
@@ -3294,23 +4067,23 @@
3294
4067
  _flushCallbackTimerId = null;
3295
4068
  }
3296
4069
  if (!_paused) {
3297
- _sendEventsForLatencyAndAbove(EventLatency.Normal, sendType, sendReason);
4070
+ _sendEventsForLatencyAndAbove(1 , sendType, sendReason);
3298
4071
  }
3299
4072
  }
3300
4073
  function _clearQueues() {
3301
- _batchQueues[EventLatency.Immediate] = {
4074
+ _batchQueues[4 ] = {
3302
4075
  batches: [],
3303
4076
  iKeyMap: {}
3304
4077
  };
3305
- _batchQueues[EventLatency.RealTime] = {
4078
+ _batchQueues[3 ] = {
3306
4079
  batches: [],
3307
4080
  iKeyMap: {}
3308
4081
  };
3309
- _batchQueues[EventLatency.CostDeferred] = {
4082
+ _batchQueues[2 ] = {
3310
4083
  batches: [],
3311
4084
  iKeyMap: {}
3312
4085
  };
3313
- _batchQueues[EventLatency.Normal] = {
4086
+ _batchQueues[1 ] = {
3314
4087
  batches: [],
3315
4088
  iKeyMap: {}
3316
4089
  };
@@ -3318,7 +4091,7 @@
3318
4091
  function _getEventBatch(iKey, latency, create) {
3319
4092
  var batchQueue = _batchQueues[latency];
3320
4093
  if (!batchQueue) {
3321
- latency = EventLatency.Normal;
4094
+ latency = 1 ;
3322
4095
  batchQueue = _batchQueues[latency];
3323
4096
  }
3324
4097
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -3346,7 +4119,7 @@
3346
4119
  var latency = event.latency;
3347
4120
  var eventBatch = _getEventBatch(event.iKey, latency, true);
3348
4121
  if (eventBatch.addEvent(event)) {
3349
- if (latency !== EventLatency.Immediate) {
4122
+ if (latency !== 4 ) {
3350
4123
  _queueSize++;
3351
4124
  if (append && event.sendAttempt === 0) {
3352
4125
  _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
@@ -3366,7 +4139,7 @@
3366
4139
  var droppedEvents = eventBatch.split(0, dropNumber);
3367
4140
  var droppedCount = droppedEvents.count();
3368
4141
  if (droppedCount > 0) {
3369
- if (currentLatency === EventLatency.Immediate) {
4142
+ if (currentLatency === 4 ) {
3370
4143
  _immediateQueueSize -= droppedCount;
3371
4144
  }
3372
4145
  else {
@@ -3388,7 +4161,7 @@
3388
4161
  var batchQueue = _batchQueues[latency];
3389
4162
  if (batchQueue && batchQueue.batches) {
3390
4163
  arrForEach(batchQueue.batches, function (theBatch) {
3391
- if (latency === EventLatency.Immediate) {
4164
+ if (latency === 4 ) {
3392
4165
  immediateQueue += theBatch.count();
3393
4166
  }
3394
4167
  else {
@@ -3397,7 +4170,7 @@
3397
4170
  });
3398
4171
  }
3399
4172
  };
3400
- for (var latency = EventLatency.Normal; latency <= EventLatency.Immediate; latency++) {
4173
+ for (var latency = 1 ; latency <= 4 ; latency++) {
3401
4174
  _loop_1(latency);
3402
4175
  }
3403
4176
  _queueSize = normalQueue;
@@ -3409,7 +4182,7 @@
3409
4182
  if (!isAsync || _httpManager.canSendRequest()) {
3410
4183
  doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
3411
4184
  var droppedEvents = [];
3412
- var latencyToProcess = EventLatency.Immediate;
4185
+ var latencyToProcess = 4 ;
3413
4186
  while (latencyToProcess >= latency) {
3414
4187
  var batchQueue = _batchQueues[latencyToProcess];
3415
4188
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -3420,7 +4193,7 @@
3420
4193
  else {
3421
4194
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
3422
4195
  }
3423
- if (latencyToProcess === EventLatency.Immediate) {
4196
+ if (latencyToProcess === 4 ) {
3424
4197
  _immediateQueueSize -= theBatch.count();
3425
4198
  }
3426
4199
  else {
@@ -3448,7 +4221,7 @@
3448
4221
  return eventsQueued;
3449
4222
  }
3450
4223
  function _flushImpl(callback, sendReason) {
3451
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 0 , sendReason);
4224
+ _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
3452
4225
  _waitForIdleManager(function () {
3453
4226
  if (callback) {
3454
4227
  callback();
@@ -3488,15 +4261,19 @@
3488
4261
  }
3489
4262
  function _requeueEvents(batches, reason) {
3490
4263
  var droppedEvents = [];
4264
+ var maxSendAttempts = _maxEventSendAttempts;
4265
+ if (_isPageUnloadTriggered) {
4266
+ maxSendAttempts = _maxUnloadEventSendAttempts;
4267
+ }
3491
4268
  arrForEach(batches, function (theBatch) {
3492
4269
  if (theBatch && theBatch.count() > 0) {
3493
4270
  arrForEach(theBatch.events(), function (theEvent) {
3494
4271
  if (theEvent) {
3495
4272
  if (theEvent.sync) {
3496
- theEvent.latency = EventLatency.Immediate;
4273
+ theEvent.latency = 4 ;
3497
4274
  theEvent.sync = false;
3498
4275
  }
3499
- if (theEvent.sendAttempt < MaxSendAttempts) {
4276
+ if (theEvent.sendAttempt < maxSendAttempts) {
3500
4277
  setProcessTelemetryTimings(theEvent, _self.identifier);
3501
4278
  _addEventToQueues(theEvent, false);
3502
4279
  }
@@ -3522,7 +4299,7 @@
3522
4299
  notifyFunc.apply(manager, theArgs);
3523
4300
  }
3524
4301
  catch (e) {
3525
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
4302
+ _throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
3526
4303
  }
3527
4304
  }
3528
4305
  }
@@ -3595,4 +4372,4 @@
3595
4372
  (function(obj, prop, descriptor) { /* ai_es3_polyfil defineProperty */ var func = Object["defineProperty"]; if (func) { try { return func(obj, prop, descriptor); } catch(e) { /* IE8 defines defineProperty, but will throw */ } } if (descriptor && typeof descriptor.value !== undefined) { obj[prop] = descriptor.value; } return obj; })(exports, '__esModule', { value: true });
3596
4373
 
3597
4374
  }));
3598
- //# sourceMappingURL=ms.post-3.1.10.js.map
4375
+ //# sourceMappingURL=ms.post-3.2.1.js.map