@microsoft/1ds-post-js 3.1.9 → 3.2.0

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 (60) hide show
  1. package/README.md +124 -5
  2. package/bundle/{ms.post-3.1.9.gbl.js → ms.post-3.2.0.gbl.js} +1706 -825
  3. package/bundle/ms.post-3.2.0.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.0.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.0.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.0.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.9.js → ms.post-3.2.0.js} +1706 -825
  8. package/bundle/ms.post-3.2.0.js.map +1 -0
  9. package/bundle/ms.post-3.2.0.min.js +7 -0
  10. package/bundle/ms.post-3.2.0.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1705 -824
  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 +1705 -824
  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 +395 -212
  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 +25 -0
  27. package/dist-esm/src/Constants.js +31 -0
  28. package/dist-esm/src/Constants.js.map +1 -0
  29. package/dist-esm/src/DataModels.d.ts +55 -0
  30. package/dist-esm/src/DataModels.js +1 -1
  31. package/dist-esm/src/EventBatch.d.ts +5 -2
  32. package/dist-esm/src/EventBatch.js +35 -15
  33. package/dist-esm/src/EventBatch.js.map +1 -1
  34. package/dist-esm/src/HttpManager.d.ts +2 -2
  35. package/dist-esm/src/HttpManager.js +186 -94
  36. package/dist-esm/src/HttpManager.js.map +1 -1
  37. package/dist-esm/src/Index.js +1 -1
  38. package/dist-esm/src/KillSwitch.js +1 -1
  39. package/dist-esm/src/PostChannel.d.ts +0 -4
  40. package/dist-esm/src/PostChannel.js +175 -107
  41. package/dist-esm/src/PostChannel.js.map +1 -1
  42. package/dist-esm/src/RetryPolicy.d.ts +20 -25
  43. package/dist-esm/src/RetryPolicy.js +35 -44
  44. package/dist-esm/src/RetryPolicy.js.map +1 -1
  45. package/dist-esm/src/Serializer.js +1 -1
  46. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  47. package/package.json +3 -3
  48. package/src/Constants.ts +28 -0
  49. package/src/DataModels.ts +68 -0
  50. package/src/EventBatch.ts +47 -14
  51. package/src/HttpManager.ts +216 -98
  52. package/src/PostChannel.ts +207 -130
  53. package/src/RetryPolicy.ts +33 -38
  54. package/bundle/ms.post-3.1.9.gbl.js.map +0 -1
  55. package/bundle/ms.post-3.1.9.gbl.min.js +0 -7
  56. package/bundle/ms.post-3.1.9.gbl.min.js.map +0 -1
  57. package/bundle/ms.post-3.1.9.integrity.json +0 -46
  58. package/bundle/ms.post-3.1.9.js.map +0 -1
  59. package/bundle/ms.post-3.1.9.min.js +0 -7
  60. package/bundle/ms.post-3.1.9.min.js.map +0 -1
package/bundle/ms.post.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK POST plugin, 3.1.9
2
+ * 1DS JS SDK POST plugin, 3.2.0
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -21,20 +21,24 @@
21
21
  var ObjDefineProperty = ObjClass["defineProperty"];
22
22
  var ObjHasOwnProperty = ObjProto[strShimHasOwnProperty];
23
23
 
24
- function getGlobal() {
25
- if (typeof globalThis !== strShimUndefined && globalThis) {
26
- return globalThis;
27
- }
28
- if (typeof self !== strShimUndefined && self) {
29
- return self;
30
- }
31
- if (typeof window !== strShimUndefined && window) {
32
- return window;
33
- }
34
- if (typeof global !== strShimUndefined && global) {
35
- return global;
24
+ var _cachedGlobal = null;
25
+ function getGlobal(useCached) {
26
+ if (useCached === void 0) { useCached = true; }
27
+ if (!_cachedGlobal || !useCached) {
28
+ if (typeof globalThis !== strShimUndefined && globalThis) {
29
+ _cachedGlobal = globalThis;
30
+ }
31
+ if (typeof self !== strShimUndefined && self) {
32
+ _cachedGlobal = self;
33
+ }
34
+ if (typeof window !== strShimUndefined && window) {
35
+ _cachedGlobal = window;
36
+ }
37
+ if (typeof global !== strShimUndefined && global) {
38
+ _cachedGlobal = global;
39
+ }
36
40
  }
37
- return null;
41
+ return _cachedGlobal;
38
42
  }
39
43
  function throwTypeError(message) {
40
44
  throw new TypeError(message);
@@ -49,7 +53,7 @@
49
53
  }
50
54
  var type = typeof obj;
51
55
  if (type !== strShimObject && type !== strShimFunction) {
52
- throwTypeError('Object prototype may only be an Object:' + obj);
56
+ throwTypeError("Object prototype may only be an Object:" + obj);
53
57
  }
54
58
  function tmpFunc() { }
55
59
  tmpFunc[strShimPrototype] = obj;
@@ -58,18 +62,6 @@
58
62
 
59
63
  (getGlobal() || {})["Symbol"];
60
64
  (getGlobal() || {})["Reflect"];
61
- var __objAssignFnImpl = function (t) {
62
- for (var s, i = 1, n = arguments.length; i < n; i++) {
63
- s = arguments[i];
64
- for (var p in s) {
65
- if (ObjProto[strShimHasOwnProperty].call(s, p)) {
66
- t[p] = s[p];
67
- }
68
- }
69
- }
70
- return t;
71
- };
72
- var __assignFn = ObjAssign || __objAssignFnImpl;
73
65
  var extendStaticsFn = function (d, b) {
74
66
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
75
67
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -91,14 +83,356 @@
91
83
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
92
84
  }
93
85
 
94
- var EventsDiscardedReason = {
95
- Unknown: 0,
96
- NonRetryableStatus: 1,
97
- InvalidEvent: 2,
98
- SizeLimitExceeded: 3,
99
- 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 ,
100
434
  QueueFull: 5
101
- };
435
+ });
102
436
 
103
437
  /*!
104
438
  * Microsoft Dynamic Proto Utility, 1.1.4
@@ -312,315 +646,34 @@
312
646
  if (!_checkPrototype(classProto, target)) {
313
647
  _throwTypeError("[" + _getObjName(theClass) + "] is not in class hierarchy of [" + _getObjName(target) + "]");
314
648
  }
315
- var className = null;
316
- if (_hasOwnProperty(classProto, DynClassName)) {
317
- className = classProto[DynClassName];
318
- }
319
- else {
320
- className = DynClassNamePrefix + _getObjName(theClass, "_") + "$" + _dynamicNames;
321
- _dynamicNames++;
322
- classProto[DynClassName] = className;
323
- }
324
- var perfOptions = dynamicProto[DynProtoDefaultOptions];
325
- var useBaseInst = !!perfOptions[strUseBaseInst];
326
- if (useBaseInst && options && options[strUseBaseInst] !== undefined) {
327
- useBaseInst = !!options[strUseBaseInst];
328
- }
329
- var instFuncs = _getInstanceFuncs(target);
330
- var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
331
- delegateFunc(target, baseFuncs);
332
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
333
- if (setInstanceFunc && options) {
334
- setInstanceFunc = !!options[strSetInstFuncs];
335
- }
336
- _populatePrototype(classProto, className, target, instFuncs, setInstanceFunc !== false);
337
- }
338
- var perfDefaults = {
339
- setInstFuncs: true,
340
- useBaseInst: true
341
- };
342
- dynamicProto[DynProtoDefaultOptions] = perfDefaults;
343
-
344
- var LoggingSeverity;
345
- (function (LoggingSeverity) {
346
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
347
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
348
- })(LoggingSeverity || (LoggingSeverity = {}));
349
- var _InternalMessageId = {
350
- BrowserDoesNotSupportLocalStorage: 0,
351
- BrowserCannotReadLocalStorage: 1,
352
- BrowserCannotReadSessionStorage: 2,
353
- BrowserCannotWriteLocalStorage: 3,
354
- BrowserCannotWriteSessionStorage: 4,
355
- BrowserFailedRemovalFromLocalStorage: 5,
356
- BrowserFailedRemovalFromSessionStorage: 6,
357
- CannotSendEmptyTelemetry: 7,
358
- ClientPerformanceMathError: 8,
359
- ErrorParsingAISessionCookie: 9,
360
- ErrorPVCalc: 10,
361
- ExceptionWhileLoggingError: 11,
362
- FailedAddingTelemetryToBuffer: 12,
363
- FailedMonitorAjaxAbort: 13,
364
- FailedMonitorAjaxDur: 14,
365
- FailedMonitorAjaxOpen: 15,
366
- FailedMonitorAjaxRSC: 16,
367
- FailedMonitorAjaxSend: 17,
368
- FailedMonitorAjaxGetCorrelationHeader: 18,
369
- FailedToAddHandlerForOnBeforeUnload: 19,
370
- FailedToSendQueuedTelemetry: 20,
371
- FailedToReportDataLoss: 21,
372
- FlushFailed: 22,
373
- MessageLimitPerPVExceeded: 23,
374
- MissingRequiredFieldSpecification: 24,
375
- NavigationTimingNotSupported: 25,
376
- OnError: 26,
377
- SessionRenewalDateIsZero: 27,
378
- SenderNotInitialized: 28,
379
- StartTrackEventFailed: 29,
380
- StopTrackEventFailed: 30,
381
- StartTrackFailed: 31,
382
- StopTrackFailed: 32,
383
- TelemetrySampledAndNotSent: 33,
384
- TrackEventFailed: 34,
385
- TrackExceptionFailed: 35,
386
- TrackMetricFailed: 36,
387
- TrackPVFailed: 37,
388
- TrackPVFailedCalc: 38,
389
- TrackTraceFailed: 39,
390
- TransmissionFailed: 40,
391
- FailedToSetStorageBuffer: 41,
392
- FailedToRestoreStorageBuffer: 42,
393
- InvalidBackendResponse: 43,
394
- FailedToFixDepricatedValues: 44,
395
- InvalidDurationValue: 45,
396
- TelemetryEnvelopeInvalid: 46,
397
- CreateEnvelopeError: 47,
398
- CannotSerializeObject: 48,
399
- CannotSerializeObjectNonSerializable: 49,
400
- CircularReferenceDetected: 50,
401
- ClearAuthContextFailed: 51,
402
- ExceptionTruncated: 52,
403
- IllegalCharsInName: 53,
404
- ItemNotInArray: 54,
405
- MaxAjaxPerPVExceeded: 55,
406
- MessageTruncated: 56,
407
- NameTooLong: 57,
408
- SampleRateOutOfRange: 58,
409
- SetAuthContextFailed: 59,
410
- SetAuthContextFailedAccountName: 60,
411
- StringValueTooLong: 61,
412
- StartCalledMoreThanOnce: 62,
413
- StopCalledWithoutStart: 63,
414
- TelemetryInitializerFailed: 64,
415
- TrackArgumentsNotSpecified: 65,
416
- UrlTooLong: 66,
417
- SessionStorageBufferFull: 67,
418
- CannotAccessCookie: 68,
419
- IdTooLong: 69,
420
- InvalidEvent: 70,
421
- FailedMonitorAjaxSetRequestHeader: 71,
422
- SendBrowserInfoOnUserInit: 72,
423
- PluginException: 73,
424
- NotificationException: 74,
425
- SnippetScriptLoadFailure: 99,
426
- InvalidInstrumentationKey: 100,
427
- CannotParseAiBlobValue: 101,
428
- InvalidContentBlob: 102,
429
- TrackPageActionEventFailed: 103,
430
- FailedAddingCustomDefinedRequestContext: 104,
431
- InMemoryStorageBufferFull: 105
432
- };
433
-
434
- var strOnPrefix = "on";
435
- var strAttachEvent = "attachEvent";
436
- var strAddEventHelper = "addEventListener";
437
- var _objDefineProperty = ObjDefineProperty;
438
- function objToString(obj) {
439
- return ObjProto.toString.call(obj);
440
- }
441
- function isUndefined(value) {
442
- return value === undefined || typeof value === strShimUndefined;
443
- }
444
- function isNullOrUndefined(value) {
445
- return (value === null || isUndefined(value));
446
- }
447
- function hasOwnProperty(obj, prop) {
448
- return obj && ObjHasOwnProperty.call(obj, prop);
449
- }
450
- function isObject(value) {
451
- return typeof value === strShimObject;
452
- }
453
- function isFunction(value) {
454
- return typeof value === strShimFunction;
455
- }
456
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
457
- if (useCapture === void 0) { useCapture = false; }
458
- var result = false;
459
- if (!isNullOrUndefined(obj)) {
460
- try {
461
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
462
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
463
- result = true;
464
- }
465
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
466
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
467
- result = true;
468
- }
469
- }
470
- catch (e) {
471
- }
472
- }
473
- return result;
474
- }
475
- function objForEachKey(target, callbackfn) {
476
- if (target) {
477
- for (var prop in target) {
478
- if (ObjHasOwnProperty.call(target, prop)) {
479
- callbackfn.call(target, prop, target[prop]);
480
- }
481
- }
482
- }
483
- }
484
- function strStartsWith(value, checkValue) {
485
- var result = false;
486
- if (value && checkValue) {
487
- var chkLen = checkValue.length;
488
- if (value === checkValue) {
489
- return true;
490
- }
491
- else if (value.length >= chkLen) {
492
- for (var lp = 0; lp < chkLen; lp++) {
493
- if (value[lp] !== checkValue[lp]) {
494
- return false;
495
- }
496
- }
497
- result = true;
498
- }
499
- }
500
- return result;
501
- }
502
- function isArray(obj) {
503
- return objToString(obj) === "[object Array]";
504
- }
505
- function isString(value) {
506
- return typeof value === "string";
507
- }
508
- function isNumber(value) {
509
- return typeof value === "number";
510
- }
511
- function isBoolean(value) {
512
- return typeof value === "boolean";
513
- }
514
- function arrForEach(arr, callbackfn, thisArg) {
515
- var len = arr.length;
516
- try {
517
- for (var idx = 0; idx < len; idx++) {
518
- if (idx in arr) {
519
- if (callbackfn.call(thisArg || arr, arr[idx], idx, arr) === -1) {
520
- break;
521
- }
522
- }
523
- }
524
- }
525
- catch (e) {
526
- }
527
- }
528
- function arrIndexOf(arr, searchElement, fromIndex) {
529
- var len = arr.length;
530
- var from = fromIndex || 0;
531
- try {
532
- for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
533
- if (lp in arr && arr[lp] === searchElement) {
534
- return lp;
535
- }
536
- }
537
- }
538
- catch (e) {
539
- }
540
- return -1;
541
- }
542
- function strTrim(str) {
543
- if (typeof str !== "string") {
544
- return str;
545
- }
546
- return str.replace(/^\s+|\s+$/g, "");
547
- }
548
- var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
549
- var _objKeysDontEnums = [
550
- "toString",
551
- "toLocaleString",
552
- "valueOf",
553
- "hasOwnProperty",
554
- "isPrototypeOf",
555
- "propertyIsEnumerable",
556
- "constructor"
557
- ];
558
- function objKeys(obj) {
559
- var objType = typeof obj;
560
- if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
561
- throwTypeError("objKeys called on non-object");
562
- }
563
- var result = [];
564
- for (var prop in obj) {
565
- if (obj && ObjHasOwnProperty.call(obj, prop)) {
566
- result.push(prop);
567
- }
568
- }
569
- if (_objKeysHasDontEnumBug) {
570
- var dontEnumsLength = _objKeysDontEnums.length;
571
- for (var lp = 0; lp < dontEnumsLength; lp++) {
572
- if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
573
- result.push(_objKeysDontEnums[lp]);
574
- }
575
- }
576
- }
577
- return result;
578
- }
579
- function objDefineAccessors(target, prop, getProp, setProp) {
580
- if (_objDefineProperty) {
581
- try {
582
- var descriptor = {
583
- enumerable: true,
584
- configurable: true
585
- };
586
- if (getProp) {
587
- descriptor.get = getProp;
588
- }
589
- if (setProp) {
590
- descriptor.set = setProp;
591
- }
592
- _objDefineProperty(target, prop, descriptor);
593
- return true;
594
- }
595
- catch (e) {
596
- }
649
+ var className = null;
650
+ if (_hasOwnProperty(classProto, DynClassName)) {
651
+ className = classProto[DynClassName];
597
652
  }
598
- return false;
599
- }
600
- function dateNow() {
601
- var dt = Date;
602
- if (dt.now) {
603
- return dt.now();
653
+ else {
654
+ className = DynClassNamePrefix + _getObjName(theClass, "_") + "$" + _dynamicNames;
655
+ _dynamicNames++;
656
+ classProto[DynClassName] = className;
604
657
  }
605
- return new dt().getTime();
606
- }
607
- function setValue(target, field, value, valChk, srcChk) {
608
- var theValue = value;
609
- if (target) {
610
- theValue = target[field];
611
- if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
612
- theValue = value;
613
- target[field] = theValue;
614
- }
658
+ var perfOptions = dynamicProto[DynProtoDefaultOptions];
659
+ var useBaseInst = !!perfOptions[strUseBaseInst];
660
+ if (useBaseInst && options && options[strUseBaseInst] !== undefined) {
661
+ useBaseInst = !!options[strUseBaseInst];
615
662
  }
616
- return theValue;
617
- }
618
- function optimizeObject(theObject) {
619
- if (theObject) {
620
- theObject = ObjClass(ObjAssign ? ObjAssign({}, theObject) : theObject);
663
+ var instFuncs = _getInstanceFuncs(target);
664
+ var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
665
+ delegateFunc(target, baseFuncs);
666
+ var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
667
+ if (setInstanceFunc && options) {
668
+ setInstanceFunc = !!options[strSetInstFuncs];
621
669
  }
622
- return theObject;
670
+ _populatePrototype(classProto, className, target, instFuncs, setInstanceFunc !== false);
623
671
  }
672
+ var perfDefaults = {
673
+ setInstFuncs: true,
674
+ useBaseInst: true
675
+ };
676
+ dynamicProto[DynProtoDefaultOptions] = perfDefaults;
624
677
 
625
678
  var strWindow = "window";
626
679
  var strDocument = "document";
@@ -629,7 +682,14 @@
629
682
  var strConsole = "console";
630
683
  var strPerformance = "performance";
631
684
  var strJSON = "JSON";
685
+ var strCrypto = "crypto";
686
+ var strMsCrypto = "msCrypto";
632
687
  var strReactNative = "ReactNative";
688
+ var strMsie = "msie";
689
+ var strTrident = "trident/";
690
+ var strXMLHttpRequest = "XMLHttpRequest";
691
+ var _isTrident = null;
692
+ var _navUserAgentCheck = null;
633
693
  var _enableMocks = false;
634
694
  var _useXDomainRequest = null;
635
695
  var _beaconsSupported = null;
@@ -725,6 +785,12 @@
725
785
  }
726
786
  return null;
727
787
  }
788
+ function getCrypto() {
789
+ return getGlobalInst(strCrypto);
790
+ }
791
+ function getMsCrypto() {
792
+ return getGlobalInst(strMsCrypto);
793
+ }
728
794
  function isReactNative() {
729
795
  var nav = getNavigator();
730
796
  if (nav && nav.product) {
@@ -732,9 +798,18 @@
732
798
  }
733
799
  return false;
734
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
+ }
735
810
  function dumpObj(object) {
736
811
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
737
- var propertyValueDump = "";
812
+ var propertyValueDump = strEmpty;
738
813
  if (objectTypeDump === "[object Error]") {
739
814
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
740
815
  }
@@ -752,8 +827,7 @@
752
827
  function isFetchSupported(withKeepAlive) {
753
828
  var isSupported = false;
754
829
  try {
755
- var fetchApi = getGlobalInst("fetch");
756
- isSupported = !!fetchApi;
830
+ isSupported = !!getGlobalInst("fetch");
757
831
  var request = getGlobalInst("Request");
758
832
  if (isSupported && withKeepAlive && request) {
759
833
  isSupported = _hasProperty(request, "keepalive");
@@ -765,9 +839,9 @@
765
839
  }
766
840
  function useXDomainRequest() {
767
841
  if (_useXDomainRequest === null) {
768
- _useXDomainRequest = (typeof XDomainRequest !== undefined);
842
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
769
843
  if (_useXDomainRequest && isXhrSupported()) {
770
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
844
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
771
845
  }
772
846
  }
773
847
  return _useXDomainRequest;
@@ -775,7 +849,7 @@
775
849
  function isXhrSupported() {
776
850
  var isSupported = false;
777
851
  try {
778
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
852
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
779
853
  isSupported = !!xmlHttpRequest;
780
854
  }
781
855
  catch (e) {
@@ -783,6 +857,22 @@
783
857
  return isSupported;
784
858
  }
785
859
 
860
+ var _aiNamespace = null;
861
+ function _getExtensionNamespace() {
862
+ var target = getGlobalInst("Microsoft");
863
+ if (target) {
864
+ _aiNamespace = target["ApplicationInsights"];
865
+ }
866
+ return _aiNamespace;
867
+ }
868
+ function getDebugExt(config) {
869
+ var ns = _aiNamespace;
870
+ if (!ns && config.disableDbgExt !== true) {
871
+ ns = _aiNamespace || _getExtensionNamespace();
872
+ }
873
+ return ns ? ns["ChromeDbgExt"] : null;
874
+ }
875
+
786
876
  var AiNonUserActionablePrefix = "AI (Internal): ";
787
877
  var AiUserActionablePrefix = "AI: ";
788
878
  var AIInternalMessagePrefix = "AITR_";
@@ -790,9 +880,9 @@
790
880
  var strWarnToConsole = "warnToConsole";
791
881
  function _sanitizeDiagnosticText(text) {
792
882
  if (text) {
793
- return "\"" + text.replace(/\"/g, "") + "\"";
883
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
794
884
  }
795
- return "";
885
+ return strEmpty;
796
886
  }
797
887
  function _logToConsole(func, message) {
798
888
  var theConsole = getConsole();
@@ -814,12 +904,12 @@
814
904
  _self.message =
815
905
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
816
906
  msgId;
817
- var strProps = "";
907
+ var strProps = strEmpty;
818
908
  if (hasJSON()) {
819
909
  strProps = getJSON().stringify(properties);
820
910
  }
821
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
822
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
911
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
912
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
823
913
  _self.message += diagnosticText;
824
914
  }
825
915
  _InternalLogMessage.dataType = "MessageData";
@@ -849,7 +939,7 @@
849
939
  throw message;
850
940
  }
851
941
  else {
852
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
942
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
853
943
  if (!isUndefined(message.message)) {
854
944
  var logLevel = _self.consoleLoggingLevel();
855
945
  if (isUserAct) {
@@ -866,13 +956,18 @@
866
956
  }
867
957
  _self.logInternalMessage(severity, message);
868
958
  }
959
+ else {
960
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
961
+ }
869
962
  }
870
963
  };
871
964
  _self.warnToConsole = function (message) {
872
965
  _logToConsole("warn", message);
966
+ _debugExtMsg("warning", message);
873
967
  };
874
968
  _self.errorToConsole = function (message) {
875
969
  _logToConsole("error", message);
970
+ _debugExtMsg("error", message);
876
971
  };
877
972
  _self.resetInternalMessageCount = function () {
878
973
  _messageCount = 0;
@@ -894,12 +989,18 @@
894
989
  if (severity <= _self.telemetryLoggingLevel()) {
895
990
  _self.queue.push(message);
896
991
  _messageCount++;
992
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
897
993
  }
898
994
  if (_messageCount === _self.maxInternalMessageLimit()) {
899
995
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
900
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
996
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
901
997
  _self.queue.push(throttleMessage);
902
- _self.warnToConsole(throttleLimitMessage);
998
+ if (severity === 1 ) {
999
+ _self.errorToConsole(throttleLimitMessage);
1000
+ }
1001
+ else {
1002
+ _self.warnToConsole(throttleLimitMessage);
1003
+ }
903
1004
  }
904
1005
  }
905
1006
  };
@@ -913,10 +1014,20 @@
913
1014
  function _areInternalMessagesThrottled() {
914
1015
  return _messageCount >= _self.maxInternalMessageLimit();
915
1016
  }
1017
+ function _debugExtMsg(name, data) {
1018
+ var dbgExt = getDebugExt(config);
1019
+ if (dbgExt && dbgExt.diagLog) {
1020
+ dbgExt.diagLog(name, data);
1021
+ }
1022
+ }
916
1023
  });
917
1024
  }
918
1025
  return DiagnosticLogger;
919
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
+ }
920
1031
 
921
1032
  var strExecutionContextKey = "ctx";
922
1033
  var PerfEvent = /** @class */ (function () {
@@ -1030,207 +1141,621 @@
1030
1141
  return func();
1031
1142
  }
1032
1143
 
1033
- var TelemetryPluginChain = /** @class */ (function () {
1034
- function TelemetryPluginChain(plugin, defItemCtx) {
1035
- var _self = this;
1036
- var _nextProxy = null;
1037
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1038
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1039
- _self._hasRun = false;
1040
- _self.getPlugin = function () {
1041
- return plugin;
1042
- };
1043
- _self.getNext = function () {
1044
- return _nextProxy;
1045
- };
1046
- _self.setNext = function (nextPlugin) {
1047
- _nextProxy = nextPlugin;
1048
- };
1049
- _self.processTelemetry = function (env, itemCtx) {
1050
- if (!itemCtx) {
1051
- 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.0";
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
+ }
1243
+ }
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
+ }
1052
1278
  }
1053
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1054
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1055
- if (plugin && _hasProcessTelemetry) {
1056
- _self._hasRun = true;
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) {
1057
1355
  try {
1058
- itemCtx.setNext(_nextProxy);
1059
- if (_hasSetNext) {
1060
- plugin.setNextPlugin(_nextProxy);
1061
- }
1062
- _nextProxy && (_nextProxy._hasRun = false);
1063
- plugin.processTelemetry(env, itemCtx);
1356
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1064
1357
  }
1065
- catch (error) {
1066
- var hasRun = _nextProxy && _nextProxy._hasRun;
1067
- if (!_nextProxy || !hasRun) {
1068
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1069
- }
1070
- if (_nextProxy && !hasRun) {
1071
- _nextProxy.processTelemetry(env, itemCtx);
1072
- }
1358
+ catch (e) {
1359
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1073
1360
  }
1074
- }
1075
- else if (_nextProxy) {
1076
- _self._hasRun = true;
1077
- _nextProxy.processTelemetry(env, itemCtx);
1078
- }
1079
- }, function () { return ({ item: env }); }, !(env.sync));
1080
- };
1361
+ });
1362
+ _onComplete = [];
1363
+ }
1364
+ }
1365
+ return nextProxy;
1081
1366
  }
1082
- return TelemetryPluginChain;
1083
- }());
1084
-
1085
- function _createProxyChain(plugins, itemCtx) {
1086
- var proxies = [];
1087
- if (plugins && plugins.length > 0) {
1088
- var lastProxy = null;
1089
- for (var idx = 0; idx < plugins.length; idx++) {
1090
- var thePlugin = plugins[idx];
1091
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1092
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1093
- proxies.push(newProxy);
1094
- if (lastProxy) {
1095
- lastProxy.setNext(newProxy);
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
+ });
1096
1392
  }
1097
- lastProxy = newProxy;
1393
+ theConfig = newConfig_1;
1098
1394
  }
1099
1395
  }
1396
+ return theConfig;
1100
1397
  }
1101
- return proxies.length > 0 ? proxies[0] : null;
1102
- }
1103
- function _copyProxyChain(proxy, itemCtx, startAt) {
1104
- var plugins = [];
1105
- var add = startAt ? false : true;
1106
- if (proxy) {
1107
- while (proxy) {
1108
- var thePlugin = proxy.getPlugin();
1109
- if (add || thePlugin === startAt) {
1110
- add = true;
1111
- plugins.push(thePlugin);
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);
1112
1416
  }
1113
- proxy = proxy.getNext();
1114
1417
  }
1115
1418
  }
1116
- if (!add) {
1117
- plugins.push(startAt);
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);
1118
1435
  }
1119
- return _createProxyChain(plugins, itemCtx);
1436
+ context.processNext = _processNext;
1437
+ context.createNew = _createNew;
1438
+ return context;
1120
1439
  }
1121
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1122
- var plugins = srcPlugins;
1123
- var add = false;
1124
- if (startAt && srcPlugins) {
1125
- plugins = [];
1126
- arrForEach(srcPlugins, function (thePlugin) {
1127
- if (add || thePlugin === startAt) {
1128
- add = true;
1129
- plugins.push(thePlugin);
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);
1130
1468
  }
1131
1469
  });
1132
1470
  }
1133
- if (startAt && !add) {
1134
- if (!plugins) {
1135
- plugins = [];
1471
+ function _createNew(plugins, startAt) {
1472
+ if (plugins === void 0) { plugins = null; }
1473
+ if (isArray(plugins)) {
1474
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1136
1475
  }
1137
- plugins.push(startAt);
1476
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1138
1477
  }
1139
- return _createProxyChain(plugins, itemCtx);
1478
+ context.processNext = _processNext;
1479
+ context.createNew = _createNew;
1480
+ return context;
1140
1481
  }
1141
- var ProcessTelemetryContext = /** @class */ (function () {
1142
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1143
- var _self = this;
1144
- var _nextProxy = null;
1145
- if (startAt !== null) {
1146
- if (plugins && isFunction(plugins.getPlugin)) {
1147
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
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;
1148
1490
  }
1149
- else {
1150
- if (startAt) {
1151
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1491
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1492
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1493
+ if (!firstProxy) {
1494
+ firstProxy = newProxy;
1152
1495
  }
1153
- else if (isUndefined(startAt)) {
1154
- _nextProxy = _createProxyChain(plugins, _self);
1496
+ if (lastProxy_1) {
1497
+ lastProxy_1._setNext(newProxy);
1155
1498
  }
1499
+ lastProxy_1 = newProxy;
1156
1500
  }
1501
+ });
1502
+ }
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;
1157
1532
  }
1158
- _self.core = function () {
1159
- return core;
1160
- };
1161
- _self.diagLog = function () {
1162
- return safeGetLogger(core, config);
1163
- };
1164
- _self.getCfg = function () {
1165
- return config;
1166
- };
1167
- _self.getExtCfg = function (identifier, defaultValue) {
1168
- if (defaultValue === void 0) { defaultValue = {}; }
1169
- var theConfig;
1170
- if (config) {
1171
- var extConfig = config.extensionConfig;
1172
- if (extConfig && identifier) {
1173
- theConfig = extConfig[identifier];
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);
1561
+ }
1562
+ catch (error) {
1563
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1564
+ if (hasNextRun) {
1565
+ hasRun = true;
1566
+ }
1567
+ if (!nextProxy || !hasNextRun) {
1568
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1569
+ }
1570
+ }
1571
+ }, details, isAsync);
1572
+ }
1573
+ return hasRun;
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);
1587
+ }
1588
+ plugin.processTelemetry(env, itemCtx);
1589
+ return true;
1590
+ }
1591
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1592
+ itemCtx.processNext(env);
1593
+ }
1594
+ }
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
+ }
1609
+ }
1610
+ return hasRun;
1611
+ }
1612
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1613
+ unloadCtx.processNext(unloadState);
1614
+ }
1615
+ }
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
+ }
1627
+ }
1628
+ return hasRun;
1629
+ }
1630
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1631
+ updateCtx.processNext(updateState);
1632
+ }
1633
+ }
1634
+ return objFreeze(proxyChain);
1635
+ }
1636
+
1637
+ var strExtensionConfig = "extensionConfig";
1638
+
1639
+ function createUnloadHandlerContainer() {
1640
+ var handlers = [];
1641
+ function _addHandler(handler) {
1642
+ if (handler) {
1643
+ handlers.push(handler);
1644
+ }
1645
+ }
1646
+ function _runHandlers(unloadCtx, unloadState) {
1647
+ arrForEach(handlers, function (handler) {
1648
+ try {
1649
+ handler(unloadCtx, unloadState);
1650
+ }
1651
+ catch (e) {
1652
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1653
+ }
1654
+ });
1655
+ handlers = [];
1656
+ }
1657
+ return {
1658
+ add: _addHandler,
1659
+ run: _runHandlers
1660
+ };
1661
+ }
1662
+
1663
+ var strGetPlugin = "getPlugin";
1664
+ var BaseTelemetryPlugin = /** @class */ (function () {
1665
+ function BaseTelemetryPlugin() {
1666
+ var _self = this;
1667
+ var _isinitialized;
1668
+ var _rootCtx;
1669
+ var _nextPlugin;
1670
+ var _unloadHandlerContainer;
1671
+ var _hooks;
1672
+ _initDefaults();
1673
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1674
+ _self.initialize = function (config, core, extensions, pluginChain) {
1675
+ _setDefaults(config, core, pluginChain);
1676
+ _isinitialized = true;
1677
+ };
1678
+ _self.teardown = function (unloadCtx, unloadState) {
1679
+ var core = _self.core;
1680
+ if (!core || (unloadCtx && core !== unloadCtx.core())) {
1681
+ return;
1682
+ }
1683
+ var result;
1684
+ var unloadDone = false;
1685
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1686
+ var theUnloadState = unloadState || {
1687
+ reason: 0 ,
1688
+ isAsync: false
1689
+ };
1690
+ function _unloadCallback() {
1691
+ if (!unloadDone) {
1692
+ unloadDone = true;
1693
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1694
+ arrForEach(_hooks, function (fn) {
1695
+ fn.rm();
1696
+ });
1697
+ _hooks = [];
1698
+ if (result === true) {
1699
+ theUnloadCtx.processNext(theUnloadState);
1700
+ }
1701
+ _initDefaults();
1702
+ }
1703
+ }
1704
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1705
+ _unloadCallback();
1706
+ }
1707
+ else {
1708
+ result = true;
1709
+ }
1710
+ return result;
1711
+ };
1712
+ _self.update = function (updateCtx, updateState) {
1713
+ var core = _self.core;
1714
+ if (!core || (updateCtx && core !== updateCtx.core())) {
1715
+ return;
1716
+ }
1717
+ var result;
1718
+ var updateDone = false;
1719
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1720
+ var theUpdateState = updateState || {
1721
+ reason: 0
1722
+ };
1723
+ function _updateCallback() {
1724
+ if (!updateDone) {
1725
+ updateDone = true;
1726
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1727
+ }
1728
+ }
1729
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1730
+ _updateCallback();
1731
+ }
1732
+ else {
1733
+ result = true;
1734
+ }
1735
+ return result;
1736
+ };
1737
+ _self._addHook = function (hooks) {
1738
+ if (hooks) {
1739
+ if (isArray(hooks)) {
1740
+ _hooks = _hooks.concat(hooks);
1741
+ }
1742
+ else {
1743
+ _hooks.push(hooks);
1744
+ }
1174
1745
  }
1175
- }
1176
- return (theConfig ? theConfig : defaultValue);
1177
- };
1178
- _self.getConfig = function (identifier, field, defaultValue) {
1179
- if (defaultValue === void 0) { defaultValue = false; }
1180
- var theValue;
1181
- var extConfig = _self.getExtCfg(identifier, null);
1182
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1183
- theValue = extConfig[field];
1184
- }
1185
- else if (config && !isNullOrUndefined(config[field])) {
1186
- theValue = config[field];
1187
- }
1188
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1189
- };
1190
- _self.hasNext = function () {
1191
- return _nextProxy != null;
1192
- };
1193
- _self.getNext = function () {
1194
- return _nextProxy;
1195
- };
1196
- _self.setNext = function (nextPlugin) {
1197
- _nextProxy = nextPlugin;
1198
- };
1199
- _self.processNext = function (env) {
1200
- var nextPlugin = _nextProxy;
1201
- if (nextPlugin) {
1202
- _nextProxy = nextPlugin.getNext();
1203
- nextPlugin.processTelemetry(env, _self);
1204
- }
1205
- };
1206
- _self.createNew = function (plugins, startAt) {
1207
- if (plugins === void 0) { plugins = null; }
1208
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1209
- };
1210
- }
1211
- return ProcessTelemetryContext;
1212
- }());
1213
-
1214
- var strExtensionConfig = "extensionConfig";
1215
-
1216
- var strGetPlugin = "getPlugin";
1217
- var BaseTelemetryPlugin = /** @class */ (function () {
1218
- function BaseTelemetryPlugin() {
1219
- var _self = this;
1220
- var _isinitialized = false;
1221
- var _rootCtx = null;
1222
- var _nextPlugin = null;
1223
- _self.core = null;
1746
+ };
1747
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1748
+ });
1224
1749
  _self.diagLog = function (itemCtx) {
1225
- return _self._getTelCtx(itemCtx).diagLog();
1750
+ return _getTelCtx(itemCtx).diagLog();
1226
1751
  };
1227
- _self.isInitialized = function () {
1752
+ _self[strIsInitialized] = function () {
1228
1753
  return _isinitialized;
1229
1754
  };
1230
1755
  _self.setInitialized = function (isInitialized) {
1231
1756
  _isinitialized = isInitialized;
1232
1757
  };
1233
- _self.setNextPlugin = function (next) {
1758
+ _self[strSetNextPlugin] = function (next) {
1234
1759
  _nextPlugin = next;
1235
1760
  };
1236
1761
  _self.processNext = function (env, itemCtx) {
@@ -1241,11 +1766,12 @@
1241
1766
  _nextPlugin.processTelemetry(env, null);
1242
1767
  }
1243
1768
  };
1244
- _self._getTelCtx = function (currentCtx) {
1769
+ _self._getTelCtx = _getTelCtx;
1770
+ function _getTelCtx(currentCtx) {
1245
1771
  if (currentCtx === void 0) { currentCtx = null; }
1246
1772
  var itemCtx = currentCtx;
1247
1773
  if (!itemCtx) {
1248
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1774
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1249
1775
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1250
1776
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1251
1777
  }
@@ -1254,8 +1780,8 @@
1254
1780
  }
1255
1781
  }
1256
1782
  return itemCtx;
1257
- };
1258
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1783
+ }
1784
+ function _setDefaults(config, core, pluginChain) {
1259
1785
  if (config) {
1260
1786
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1261
1787
  }
@@ -1267,93 +1793,300 @@
1267
1793
  nextPlugin = _nextPlugin[strGetPlugin]();
1268
1794
  }
1269
1795
  _self.core = core;
1270
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1271
- _isinitialized = true;
1272
- };
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
+ }
1273
1806
  }
1274
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1275
- this._baseTelInit(config, core, extensions, pluginChain);
1276
- };
1277
1807
  return BaseTelemetryPlugin;
1278
1808
  }());
1279
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";
1280
1816
  var strVisibilityChangeEvt = "visibilitychange";
1281
1817
  var strPageHide = "pagehide";
1282
1818
  var strPageShow = "pageshow";
1283
- 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) {
1284
1986
  var result = false;
1285
1987
  var w = getWindow();
1286
1988
  if (w) {
1287
- result = attachEvent(w, eventName, callback);
1288
- result = attachEvent(w["body"], eventName, callback) || result;
1989
+ result = eventOn(w, eventName, callback, evtNamespace);
1990
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1289
1991
  }
1290
1992
  var doc = getDocument();
1291
1993
  if (doc) {
1292
- result = attachEvent(doc, eventName, callback) || result;
1994
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
1293
1995
  }
1294
1996
  return result;
1295
1997
  }
1296
- 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) {
1297
2010
  var added = false;
1298
- if (listener && events && isArray(events)) {
1299
- var excluded_1 = [];
2011
+ if (listener && events && events.length > 0) {
1300
2012
  arrForEach(events, function (name) {
1301
- if (isString(name)) {
2013
+ if (name) {
1302
2014
  if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
1303
- added = addEventHandler(name, listener) || added;
1304
- }
1305
- else {
1306
- excluded_1.push(name);
2015
+ added = addEventHandler(name, listener, evtNamespace) || added;
1307
2016
  }
1308
2017
  }
1309
2018
  });
1310
- if (!added && excluded_1.length > 0) {
1311
- 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);
1312
2028
  }
1313
2029
  }
1314
2030
  return added;
1315
2031
  }
1316
- function addPageUnloadEventListener(listener, excludeEvents) {
1317
- 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);
2043
+ }
2044
+ function removePageUnloadEventListener(listener, evtNamespace) {
2045
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
1318
2046
  }
1319
- function addPageHideEventListener(listener, excludeEvents) {
2047
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
1320
2048
  function _handlePageVisibility(evt) {
1321
2049
  var doc = getDocument();
1322
2050
  if (listener && doc && doc.visibilityState === "hidden") {
1323
2051
  listener(evt);
1324
2052
  }
1325
2053
  }
1326
- var pageUnloadAdded = false;
1327
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
1328
- pageUnloadAdded = addEventHandler(strPageHide, listener);
1329
- }
2054
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2055
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
1330
2056
  if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1331
- pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
2057
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
1332
2058
  }
1333
2059
  if (!pageUnloadAdded && excludeEvents) {
1334
- pageUnloadAdded = addPageHideEventListener(listener);
2060
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
1335
2061
  }
1336
2062
  return pageUnloadAdded;
1337
2063
  }
1338
- 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) {
1339
2070
  function _handlePageVisibility(evt) {
1340
2071
  var doc = getDocument();
1341
2072
  if (listener && doc && doc.visibilityState === "visible") {
1342
2073
  listener(evt);
1343
2074
  }
1344
2075
  }
1345
- var pageShowAdded = false;
1346
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageShow) === -1) {
1347
- pageShowAdded = addEventHandler(strPageShow, listener);
1348
- }
1349
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1350
- pageShowAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageShowAdded;
1351
- }
2076
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2077
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
2078
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
1352
2079
  if (!pageShowAdded && excludeEvents) {
1353
- pageShowAdded = addPageShowEventListener(listener);
2080
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
1354
2081
  }
1355
2082
  return pageShowAdded;
1356
2083
  }
2084
+ function removePageShowEventListener(listener, evtNamespace) {
2085
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2086
+ removeEventListeners([strPageShow], listener, newNamespaces);
2087
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2088
+ }
2089
+
1357
2090
  function perfNow() {
1358
2091
  var perf = getPerformance();
1359
2092
  if (perf && perf.now) {
@@ -1362,56 +2095,20 @@
1362
2095
  return dateNow();
1363
2096
  }
1364
2097
 
1365
- var ValueKind = {
1366
- NotSet: 0,
1367
- Pii_DistinguishedName: 1,
1368
- Pii_GenericData: 2,
1369
- Pii_IPV4Address: 3,
1370
- Pii_IPv6Address: 4,
1371
- Pii_MailSubject: 5,
1372
- Pii_PhoneNumber: 6,
1373
- Pii_QueryString: 7,
1374
- Pii_SipAddress: 8,
1375
- Pii_SmtpAddress: 9,
1376
- Pii_Identity: 10,
1377
- Pii_Uri: 11,
1378
- Pii_Fqdn: 12,
1379
- Pii_IPV4AddressLegacy: 13,
1380
- CustomerContent_GenericContent: 32
1381
- };
1382
- var EventLatency = {
1383
- Normal: 1 ,
1384
- CostDeferred: 2 ,
1385
- RealTime: 3 ,
1386
- Immediate: 4
1387
- };
1388
- var EventPropertyType = {
1389
- Unspecified: 0,
1390
- String: 1,
1391
- Int32: 2,
1392
- UInt32: 3,
1393
- Int64: 4,
1394
- UInt64: 5,
1395
- Double: 6,
1396
- Bool: 7,
1397
- Guid: 8,
1398
- DateTime: 9
1399
- };
1400
- 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 });
1401
-
1402
2098
  var _a$1;
1403
- var Version = '3.1.9';
2099
+ var Version = '3.2.0';
1404
2100
  var FullVersionString = "1DS-Web-JS-" + Version;
1405
2101
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
1406
2102
  var strWithCredentials = "withCredentials";
2103
+ var strTimeout = "timeout";
1407
2104
  var _fieldTypeEventPropMap = (_a$1 = {},
1408
- _a$1[0 ] = EventPropertyType.Unspecified,
1409
- _a$1[2 ] = EventPropertyType.Double,
1410
- _a$1[1 ] = EventPropertyType.String,
1411
- _a$1[3 ] = EventPropertyType.Bool,
1412
- _a$1[4096 | 2 ] = EventPropertyType.Double,
1413
- _a$1[4096 | 1 ] = EventPropertyType.String,
1414
- _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 ,
1415
2112
  _a$1);
1416
2113
  Boolean(getDocument());
1417
2114
  var isWindowObjectAvailable = Boolean(getWindow());
@@ -1478,7 +2175,7 @@
1478
2175
  if (encodedTypeValue !== -1 && propType !== -1) {
1479
2176
  encodedTypeValue |= propType;
1480
2177
  }
1481
- else if (propType === EventPropertyType.Double) {
2178
+ else if (propType === 6 ) {
1482
2179
  encodedTypeValue = propType;
1483
2180
  }
1484
2181
  }
@@ -1524,7 +2221,7 @@
1524
2221
  }
1525
2222
  var getTime = perfNow;
1526
2223
  function isValueKind(value) {
1527
- 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 )) {
1528
2225
  return true;
1529
2226
  }
1530
2227
  return false;
@@ -1575,7 +2272,7 @@
1575
2272
  function isChromium() {
1576
2273
  return !!getGlobalInst("chrome");
1577
2274
  }
1578
- function openXhr(method, urlString, withCredentials, disabled, isSync) {
2275
+ function openXhr(method, urlString, withCredentials, disabled, isSync, timeout) {
1579
2276
  if (disabled === void 0) { disabled = false; }
1580
2277
  if (isSync === void 0) { isSync = false; }
1581
2278
  function _wrapSetXhrProp(xhr, prop, value) {
@@ -1596,6 +2293,9 @@
1596
2293
  if (withCredentials) {
1597
2294
  _wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
1598
2295
  }
2296
+ if (!isSync && timeout) {
2297
+ _wrapSetXhrProp(xhr, strTimeout, timeout);
2298
+ }
1599
2299
  return xhr;
1600
2300
  }
1601
2301
 
@@ -1603,42 +2303,83 @@
1603
2303
  var NRT_PROFILE = "NEAR_REAL_TIME";
1604
2304
  var BE_PROFILE = "BEST_EFFORT";
1605
2305
 
2306
+ var Method = "POST";
2307
+ var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2308
+ var strDropped = "drop";
2309
+ var strSending = "send";
2310
+ var strRequeue = "requeue";
2311
+ var strResponseFail = "rspFail";
2312
+ var strOther = "oth";
2313
+ var defaultCacheControl = "no-cache, no-store";
2314
+ var defaultContentType = "application/x-json-stream";
2315
+ var strCacheControl = "cache-control";
2316
+ var strContentTypeHeader = "content-type";
2317
+ var strKillTokensHeader = "kill-tokens";
2318
+ var strKillDurationHeader = "kill-duration";
2319
+ var strKillDurationSecondsHeader = "kill-duration-seconds";
2320
+ var strTimeDeltaHeader = "time-delta-millis";
2321
+ var strClientVersion = "client-version";
2322
+ var strClientId = "client-id";
2323
+ var strTimeDeltaToApply = "time-delta-to-apply-millis";
2324
+ var strUploadTime = "upload-time";
2325
+ var strApiKey = "apikey";
2326
+ var strMsaDeviceTicket = "AuthMsaDeviceTicket";
2327
+ var strAuthXToken = "AuthXToken";
2328
+ var strNoResponseBody = "NoResponseBody";
2329
+ var strMsfpc = "msfpc";
2330
+
2331
+ function _getEventMsfpc(theEvent) {
2332
+ var intWeb = ((theEvent.ext || {})["intweb"]);
2333
+ if (intWeb && isValueAssigned(intWeb[strMsfpc])) {
2334
+ return intWeb[strMsfpc];
2335
+ }
2336
+ return null;
2337
+ }
2338
+ function _getMsfpc(theEvents) {
2339
+ var msfpc = null;
2340
+ for (var lp = 0; msfpc === null && lp < theEvents.length; lp++) {
2341
+ msfpc = _getEventMsfpc(theEvents[lp]);
2342
+ }
2343
+ return msfpc;
2344
+ }
1606
2345
  var EventBatch = /** @class */ (function () {
1607
2346
  function EventBatch(iKey, addEvents) {
1608
2347
  var events = addEvents ? [].concat(addEvents) : [];
1609
2348
  var _self = this;
2349
+ var _msfpc = _getMsfpc(events);
1610
2350
  _self.iKey = function () {
1611
2351
  return iKey;
1612
2352
  };
2353
+ _self.Msfpc = function () {
2354
+ return _msfpc || "";
2355
+ };
1613
2356
  _self.count = function () {
1614
2357
  return events.length;
1615
2358
  };
1616
2359
  _self.events = function () {
1617
2360
  return events;
1618
2361
  };
1619
- _self.addEvents = function (theEvents, append) {
1620
- if (append === void 0) { append = true; }
1621
- if (theEvents && theEvents.length > 0) {
1622
- if (append) {
1623
- events = events.concat(theEvents);
1624
- }
1625
- else {
1626
- events = theEvents.concat(events);
2362
+ _self.addEvent = function (theEvent) {
2363
+ if (theEvent) {
2364
+ events.push(theEvent);
2365
+ if (!_msfpc) {
2366
+ _msfpc = _getEventMsfpc(theEvent);
1627
2367
  }
1628
- return theEvents.length;
2368
+ return true;
1629
2369
  }
1630
- return 0;
2370
+ return false;
1631
2371
  };
1632
2372
  _self.split = function (fromEvent, numEvents) {
1633
- var newBatch = new EventBatch(iKey);
2373
+ var theEvents;
1634
2374
  if (fromEvent < events.length) {
1635
2375
  var cnt = events.length - fromEvent;
1636
2376
  if (!isNullOrUndefined(numEvents)) {
1637
2377
  cnt = numEvents < cnt ? numEvents : cnt;
1638
2378
  }
1639
- newBatch.addEvents(events.splice(fromEvent, cnt), true);
2379
+ theEvents = events.splice(fromEvent, cnt);
2380
+ _msfpc = _getMsfpc(events);
1640
2381
  }
1641
- return newBatch;
2382
+ return new EventBatch(iKey, theEvents);
1642
2383
  };
1643
2384
  }
1644
2385
  EventBatch.create = function (iKey, theEvents) {
@@ -1896,25 +2637,19 @@
1896
2637
  var RandomizationUpperThreshold = 1.2;
1897
2638
  var BaseBackoff = 3000;
1898
2639
  var MaxBackoff = 600000;
1899
- var RetryPolicy = /** @class */ (function () {
1900
- function RetryPolicy() {
1901
- }
1902
- RetryPolicy.shouldRetryForStatus = function (httpStatusCode) {
1903
- return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
1904
- || (httpStatusCode == 501)
1905
- || (httpStatusCode == 505));
1906
- };
1907
- RetryPolicy.getMillisToBackoffForRetry = function (retriesSoFar) {
1908
- var waitDuration = 0;
1909
- var minBackoff = BaseBackoff * RandomizationLowerThreshold;
1910
- var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
1911
- var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
1912
- waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
1913
- return Math.min(waitDuration, MaxBackoff);
1914
- };
1915
- return RetryPolicy;
1916
- }());
1917
- 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
+ }
1918
2653
 
1919
2654
  var SecToMsMultiplier = 1000;
1920
2655
  var KillSwitch = /** @class */ (function () {
@@ -2008,21 +2743,8 @@
2008
2743
  var EVTClockSkewManager = ClockSkewManager;
2009
2744
 
2010
2745
  var _a;
2011
- var Method = "POST";
2012
- var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2013
- var strDropped = "drop";
2014
- var strSending = "send";
2015
- var strRequeue = "requeue";
2016
- var strResponseFail = "rspFail";
2017
- var strOther = "oth";
2018
- var defaultCacheControl = "no-cache, no-store";
2019
- var defaultContentType = "application/x-json-stream";
2020
- var strCacheControl = "cache-control";
2021
- var strContentTypeHeader = "content-type";
2022
- var strKillTokensHeader = "kill-tokens";
2023
- var strKillDurationHeader = "kill-duration";
2024
- var strKillDurationSecondsHeader = "kill-duration-seconds";
2025
- var strTimeDeltaHeader = "time-delta-millis";
2746
+ var strSendAttempt = "sendAttempt";
2747
+ var _noResponseQs = "&" + strNoResponseBody + "=true";
2026
2748
  var _eventActionMap = (_a = {},
2027
2749
  _a[1 ] = strRequeue,
2028
2750
  _a[100 ] = strRequeue,
@@ -2030,6 +2752,21 @@
2030
2752
  _a[8004 ] = strDropped,
2031
2753
  _a[8003 ] = strDropped,
2032
2754
  _a);
2755
+ var _collectorQsHeaders = {};
2756
+ var _collectorHeaderToQs = {};
2757
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
2758
+ _collectorQsHeaders[qsName] = headerName;
2759
+ if (allowQs !== false) {
2760
+ _collectorHeaderToQs[headerName] = qsName;
2761
+ }
2762
+ }
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);
2033
2770
  function _getResponseText(xhr) {
2034
2771
  try {
2035
2772
  return xhr.responseText;
@@ -2056,11 +2793,21 @@
2056
2793
  }
2057
2794
  return hasHeader;
2058
2795
  }
2796
+ function _addRequestDetails(details, name, value, useHeaders) {
2797
+ if (name && value && value.length > 0) {
2798
+ if (useHeaders && _collectorQsHeaders[name]) {
2799
+ details.hdrs[_collectorQsHeaders[name]] = value;
2800
+ details.useHdrs = true;
2801
+ }
2802
+ else {
2803
+ details.url += "&" + name + "=" + value;
2804
+ }
2805
+ }
2806
+ }
2059
2807
  var HttpManager = /** @class */ (function () {
2060
- function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {
2808
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
2061
2809
  this._responseHandlers = [];
2062
- var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType + "&client-id=NO_AUTH&client-version="
2063
- + FullVersionString;
2810
+ var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
2064
2811
  var _killSwitch = new EVTKillSwitch();
2065
2812
  var _paused = false;
2066
2813
  var _clockSkewManager = new EVTClockSkewManager();
@@ -2077,6 +2824,9 @@
2077
2824
  var _enableEventTimings = false;
2078
2825
  var _cookieMgr;
2079
2826
  var _isUnloading = false;
2827
+ var _useHeaders = false;
2828
+ var _xhrTimeout;
2829
+ var _disableXhrSync;
2080
2830
  dynamicProto(HttpManager, this, function (_self) {
2081
2831
  var _sendCredentials = true;
2082
2832
  _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
@@ -2085,6 +2835,7 @@
2085
2835
  channelConfig = {};
2086
2836
  }
2087
2837
  _urlString = endpointUrl + _urlString;
2838
+ _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
2088
2839
  _core = core;
2089
2840
  _cookieMgr = core.getCookieMgr();
2090
2841
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -2095,9 +2846,13 @@
2095
2846
  if (!isUndefined(channelConfig.enableCompoundKey)) {
2096
2847
  enableCompoundKey = !!channelConfig.enableCompoundKey;
2097
2848
  }
2849
+ _xhrTimeout = channelConfig.xhrTimeout;
2850
+ _disableXhrSync = channelConfig.disableXhrSync;
2098
2851
  _useBeacons = !isReactNative();
2099
2852
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
2100
2853
  var syncHttpInterface = httpInterface;
2854
+ var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
2855
+ var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
2101
2856
  if (!httpInterface) {
2102
2857
  _customHttpInterface = false;
2103
2858
  var location_1 = getLocation();
@@ -2129,8 +2884,8 @@
2129
2884
  _sendInterfaces = (_a = {},
2130
2885
  _a[0 ] = httpInterface,
2131
2886
  _a[1 ] = syncHttpInterface || _getSenderInterface([1 , 2 , 3 ], true),
2132
- _a[2 ] = _getSenderInterface([3 , 2 , 1 ], true) || syncHttpInterface,
2133
- _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),
2134
2889
  _a);
2135
2890
  };
2136
2891
  function _getSenderInterface(transports, syncSupport) {
@@ -2170,6 +2925,9 @@
2170
2925
  function _xdrSendPost(payload, oncomplete, sync) {
2171
2926
  var xdr = new XDomainRequest();
2172
2927
  xdr.open(Method, payload.urlString);
2928
+ if (payload.timeout) {
2929
+ xdr.timeout = payload.timeout;
2930
+ }
2173
2931
  xdr.onload = function () {
2174
2932
  var response = _getResponseText(xdr);
2175
2933
  _doOnComplete(oncomplete, 200, {}, response);
@@ -2193,6 +2951,9 @@
2193
2951
  }
2194
2952
  function _fetchSendPost(payload, oncomplete, sync) {
2195
2953
  var _a;
2954
+ var theUrl = payload.urlString;
2955
+ var ignoreResponse = false;
2956
+ var responseHandled = false;
2196
2957
  var requestInit = (_a = {
2197
2958
  body: payload.data,
2198
2959
  method: Method
@@ -2201,6 +2962,10 @@
2201
2962
  _a);
2202
2963
  if (sync) {
2203
2964
  requestInit.keepalive = true;
2965
+ if (payload._sendReason === 2 ) {
2966
+ ignoreResponse = true;
2967
+ theUrl += _noResponseQs;
2968
+ }
2204
2969
  }
2205
2970
  if (_sendCredentials) {
2206
2971
  requestInit.credentials = "include";
@@ -2208,7 +2973,7 @@
2208
2973
  if (payload.headers && objKeys(payload.headers).length > 0) {
2209
2974
  requestInit.headers = payload.headers;
2210
2975
  }
2211
- fetch(payload.urlString, requestInit).then(function (response) {
2976
+ fetch(theUrl, requestInit).then(function (response) {
2212
2977
  var headerMap = {};
2213
2978
  var responseText = "";
2214
2979
  if (response.headers) {
@@ -2221,13 +2986,32 @@
2221
2986
  responseText = text;
2222
2987
  });
2223
2988
  }
2224
- _doOnComplete(oncomplete, response.status, headerMap, responseText);
2225
- _handleCollectorResponse(responseText);
2989
+ if (!responseHandled) {
2990
+ responseHandled = true;
2991
+ _doOnComplete(oncomplete, response.status, headerMap, responseText);
2992
+ _handleCollectorResponse(responseText);
2993
+ }
2226
2994
  })["catch"](function (error) {
2227
- _doOnComplete(oncomplete, 0, {});
2995
+ if (!responseHandled) {
2996
+ responseHandled = true;
2997
+ _doOnComplete(oncomplete, 0, {});
2998
+ }
2228
2999
  });
3000
+ if (ignoreResponse && !responseHandled) {
3001
+ responseHandled = true;
3002
+ _doOnComplete(oncomplete, 200, {});
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
+ }
2229
3012
  }
2230
3013
  function _xhrSendPost(payload, oncomplete, sync) {
3014
+ var theUrl = payload.urlString;
2231
3015
  function _appendHeader(theHeaders, xhr, name) {
2232
3016
  if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
2233
3017
  var value = xhr.getResponseHeader(name);
@@ -2252,45 +3036,49 @@
2252
3036
  function xhrComplete(xhr, responseTxt) {
2253
3037
  _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
2254
3038
  }
2255
- 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);
2256
3043
  objForEachKey(payload.headers, function (name, value) {
2257
- xhRequest.setRequestHeader(name, value);
3044
+ xhrRequest.setRequestHeader(name, value);
2258
3045
  });
2259
- xhRequest.onload = function () {
2260
- var response = _getResponseText(xhRequest);
2261
- xhrComplete(xhRequest, response);
3046
+ xhrRequest.onload = function () {
3047
+ var response = _getResponseText(xhrRequest);
3048
+ xhrComplete(xhrRequest, response);
2262
3049
  _handleCollectorResponse(response);
2263
3050
  };
2264
- xhRequest.onerror = function () {
2265
- xhrComplete(xhRequest);
3051
+ xhrRequest.onerror = function () {
3052
+ xhrComplete(xhrRequest);
2266
3053
  };
2267
- xhRequest.ontimeout = function () {
2268
- xhrComplete(xhRequest);
3054
+ xhrRequest.ontimeout = function () {
3055
+ xhrComplete(xhrRequest);
2269
3056
  };
2270
- xhRequest.send(payload.data);
3057
+ xhrRequest.send(payload.data);
2271
3058
  }
2272
3059
  function _doOnComplete(oncomplete, status, headers, response) {
2273
3060
  try {
2274
3061
  oncomplete(status, headers, response);
2275
3062
  }
2276
3063
  catch (e) {
2277
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));
3064
+ _throwInternal(_postManager.diagLog(), 2 , 518 , dumpObj(e));
2278
3065
  }
2279
3066
  }
2280
3067
  function _beaconSendPost(payload, oncomplete, sync) {
2281
3068
  var internalPayloadData = payload;
2282
3069
  var status = 200;
2283
3070
  var thePayload = internalPayloadData._thePayload;
3071
+ var theUrl = payload.urlString + _noResponseQs;
2284
3072
  try {
2285
3073
  var nav_1 = getNavigator();
2286
- if (!nav_1.sendBeacon(payload.urlString, payload.data)) {
3074
+ if (!nav_1.sendBeacon(theUrl, payload.data)) {
2287
3075
  if (thePayload) {
2288
3076
  var droppedBatches_1 = [];
2289
3077
  arrForEach(thePayload.batches, function (theBatch) {
2290
3078
  if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
2291
3079
  var theEvents = theBatch.events();
2292
3080
  for (var lp = 0; lp < theEvents.length; lp++) {
2293
- if (!nav_1.sendBeacon(payload.urlString, _serializer.getEventBlob(theEvents[lp]))) {
3081
+ if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
2294
3082
  droppedBatches_1.push(theBatch.split(lp));
2295
3083
  break;
2296
3084
  }
@@ -2308,7 +3096,7 @@
2308
3096
  }
2309
3097
  }
2310
3098
  catch (ex) {
2311
- _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));
2312
3100
  status = 0;
2313
3101
  }
2314
3102
  finally {
@@ -2472,11 +3260,32 @@
2472
3260
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
2473
3261
  }
2474
3262
  catch (ex) {
2475
- _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));
2476
3264
  }
2477
3265
  }
2478
- function _buildQueryString(thePayload) {
2479
- var urlString = _urlString;
3266
+ function _buildRequestDetails(thePayload, useHeaders) {
3267
+ var requestDetails = {
3268
+ url: _urlString,
3269
+ hdrs: {},
3270
+ useHdrs: false
3271
+ };
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
+ }
3287
+ _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
3288
+ _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
2480
3289
  var apiQsKeys = "";
2481
3290
  arrForEach(thePayload.apiKeys, function (apiKey) {
2482
3291
  if (apiQsKeys.length > 0) {
@@ -2484,27 +3293,25 @@
2484
3293
  }
2485
3294
  apiQsKeys += apiKey;
2486
3295
  });
2487
- if (apiQsKeys.length > 0) {
2488
- urlString += "&apikey=" + apiQsKeys;
2489
- }
2490
- urlString += "&upload-time=" + dateNow().toString();
3296
+ _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);
3297
+ _addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);
2491
3298
  var msfpc = _getMsfpc(thePayload);
2492
3299
  if (isValueAssigned(msfpc)) {
2493
- urlString = urlString + "&ext.intweb.msfpc=" + msfpc;
3300
+ requestDetails.url += "&ext.intweb.msfpc=" + msfpc;
2494
3301
  }
2495
3302
  if (_clockSkewManager.shouldAddClockSkewHeaders()) {
2496
- urlString += "&time-delta-to-apply-millis=" + _clockSkewManager.getClockSkewHeaderValue();
3303
+ _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);
2497
3304
  }
2498
3305
  if (_core.getWParam) {
2499
3306
  var wParam = _core.getWParam();
2500
3307
  if (wParam >= 0) {
2501
- urlString += "&w=" + wParam;
3308
+ requestDetails.url += "&w=" + wParam;
2502
3309
  }
2503
3310
  }
2504
3311
  for (var i = 0; i < _queryStringParameters.length; i++) {
2505
- urlString += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
3312
+ requestDetails.url += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
2506
3313
  }
2507
- return urlString;
3314
+ return requestDetails;
2508
3315
  }
2509
3316
  function _canUseSendBeaconApi() {
2510
3317
  return !_customHttpInterface && _useBeacons && isBeaconsSupported();
@@ -2515,9 +3322,18 @@
2515
3322
  }
2516
3323
  function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {
2517
3324
  if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {
2518
- var urlString_1 = _buildQueryString(thePayload);
3325
+ var useSendHook_1 = !!_self.sendHook;
3326
+ var sendInterface_1 = _sendInterfaces[thePayload.sendType];
3327
+ if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 ) {
3328
+ sendInterface_1 = _sendInterfaces[2 ] || _sendInterfaces[3 ] || sendInterface_1;
3329
+ }
3330
+ var useHeaders_1 = _useHeaders;
3331
+ if (thePayload.isBeacon || sendInterface_1._transport === 3 ) {
3332
+ useHeaders_1 = false;
3333
+ }
3334
+ var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
3335
+ useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
2519
3336
  var sendEventStart_1 = getTime();
2520
- var strSendAttempt_1 = "sendAttempt";
2521
3337
  doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
2522
3338
  for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
2523
3339
  var theBatch = thePayload.batches[batchLp];
@@ -2530,30 +3346,31 @@
2530
3346
  _setTimingValue(timings, "serializationStart", serializationStart);
2531
3347
  _setTimingValue(timings, "serializationCompleted", serializationCompleted);
2532
3348
  }
2533
- telemetryItem[strSendAttempt_1] > 0 ? telemetryItem[strSendAttempt_1]++ : telemetryItem[strSendAttempt_1] = 1;
3349
+ telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
2534
3350
  }
2535
3351
  }
2536
3352
  _sendBatchesNotification(thePayload.batches, (1000 + (sendReason || 0 )), thePayload.sendType, true);
2537
3353
  var orgPayloadData = {
2538
3354
  data: thePayload.payloadBlob,
2539
- urlString: urlString_1,
2540
- headers: extend({}, _headers),
3355
+ urlString: requestDetails_1.url,
3356
+ headers: requestDetails_1.hdrs,
2541
3357
  _thePayload: thePayload,
2542
- _sendReason: sendReason
3358
+ _sendReason: sendReason,
3359
+ timeout: _xhrTimeout
2543
3360
  };
2544
- if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
2545
- orgPayloadData.headers[strCacheControl] = defaultCacheControl;
3361
+ if (!isUndefined(_disableXhrSync)) {
3362
+ orgPayloadData.disableXhrSync = !!_disableXhrSync;
2546
3363
  }
2547
- if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
2548
- orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
3364
+ if (useHeaders_1) {
3365
+ if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
3366
+ orgPayloadData.headers[strCacheControl] = defaultCacheControl;
3367
+ }
3368
+ if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
3369
+ orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
3370
+ }
2549
3371
  }
2550
3372
  var sender = null;
2551
- var useSendHook = !!_self.sendHook;
2552
- var sendInterface = _sendInterfaces[thePayload.sendType];
2553
- if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 ) {
2554
- sendInterface = _sendInterfaces[2 ] || _sendInterfaces[3 ] || sendInterface;
2555
- }
2556
- if (sendInterface) {
3373
+ if (sendInterface_1) {
2557
3374
  sender = function (payload) {
2558
3375
  _clockSkewManager.firstRequestSent();
2559
3376
  var onComplete = function (status, headers) {
@@ -2561,7 +3378,7 @@
2561
3378
  };
2562
3379
  var isSync = thePayload.isTeardown || thePayload.isSync;
2563
3380
  try {
2564
- sendInterface.sendPOST(payload, onComplete, isSync);
3381
+ sendInterface_1.sendPOST(payload, onComplete, isSync);
2565
3382
  if (_self.sendListener) {
2566
3383
  _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);
2567
3384
  }
@@ -2577,11 +3394,13 @@
2577
3394
  if (thePayload.sendType === 0 ) {
2578
3395
  _outstandingRequests++;
2579
3396
  }
2580
- if (useSendHook && !thePayload.isBeacon && sendInterface._transport !== 3 ) {
3397
+ if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 ) {
2581
3398
  var hookData_1 = {
2582
3399
  data: orgPayloadData.data,
2583
3400
  urlString: orgPayloadData.urlString,
2584
- headers: extend({}, orgPayloadData.headers)
3401
+ headers: extend({}, orgPayloadData.headers),
3402
+ timeout: orgPayloadData.timeout,
3403
+ disableXhrSync: orgPayloadData.disableXhrSync
2585
3404
  };
2586
3405
  var senderCalled_1 = false;
2587
3406
  doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
@@ -2646,11 +3465,11 @@
2646
3465
  });
2647
3466
  });
2648
3467
  }
2649
- if (status == 200) {
3468
+ if (status == 200 || status == 204) {
2650
3469
  reason = 200 ;
2651
3470
  return;
2652
3471
  }
2653
- if (!RetryPolicy$1.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
3472
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
2654
3473
  shouldRetry = false;
2655
3474
  }
2656
3475
  reason = 9000 + (status % 1000);
@@ -2659,17 +3478,20 @@
2659
3478
  reason = 100 ;
2660
3479
  var retryCount_1 = thePayload.retryCnt;
2661
3480
  if (thePayload.sendType === 0 ) {
2662
- if (retryCount_1 < maxRetries) {
3481
+ if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
2663
3482
  isRetrying = true;
2664
3483
  _doAction(function () {
2665
3484
  if (thePayload.sendType === 0 ) {
2666
3485
  _outstandingRequests--;
2667
3486
  }
2668
3487
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
2669
- }, _isUnloading, RetryPolicy$1.getMillisToBackoffForRetry(retryCount_1));
3488
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
2670
3489
  }
2671
3490
  else {
2672
3491
  backOffTrans = true;
3492
+ if (_isUnloading) {
3493
+ reason = 8001 ;
3494
+ }
2673
3495
  }
2674
3496
  }
2675
3497
  }
@@ -2744,12 +3566,9 @@
2744
3566
  }
2745
3567
  function _getMsfpc(thePayload) {
2746
3568
  for (var lp = 0; lp < thePayload.batches.length; lp++) {
2747
- var batchEvents = thePayload.batches[lp].events();
2748
- for (var evtLp = 0; evtLp < batchEvents.length; evtLp++) {
2749
- var intWeb = ((batchEvents[evtLp].ext || {})["intweb"] || {});
2750
- if (isValueAssigned(intWeb["msfpc"])) {
2751
- return encodeURIComponent(intWeb["msfpc"]);
2752
- }
3569
+ var msfpc = thePayload.batches[lp].Msfpc();
3570
+ if (msfpc) {
3571
+ return encodeURIComponent(msfpc);
2753
3572
  }
2754
3573
  }
2755
3574
  return "";
@@ -2762,13 +3581,13 @@
2762
3581
  responseHandlers[i](responseText);
2763
3582
  }
2764
3583
  catch (e) {
2765
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
3584
+ _throwInternal(_postManager.diagLog(), 1 , 519 , "Response handler failed: " + e);
2766
3585
  }
2767
3586
  }
2768
3587
  if (responseText) {
2769
3588
  var response = JSON.parse(responseText);
2770
- if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult.msfpc)) {
2771
- _cookieMgr.set("MSFPC", response.webResult.msfpc, 365 * 86400);
3589
+ if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {
3590
+ _cookieMgr.set("MSFPC", response.webResult[strMsfpc], 365 * 86400);
2772
3591
  }
2773
3592
  }
2774
3593
  }
@@ -2786,7 +3605,7 @@
2786
3605
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
2787
3606
  }
2788
3607
  catch (e) {
2789
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, "send request notification failed: " + e);
3608
+ _throwInternal(_postManager.diagLog(), 1 , 74 , "send request notification failed: " + e);
2790
3609
  }
2791
3610
  }, sendSync || isSyncRequest_1, 0);
2792
3611
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
@@ -2813,25 +3632,28 @@
2813
3632
  }
2814
3633
  return HttpManager;
2815
3634
  }());
2816
- var HttpManager$1 = HttpManager;
2817
3635
 
2818
3636
  var FlushCheckTimer = 0.250;
2819
3637
  var MaxNumberEventPerBatch = 500;
2820
3638
  var EventsDroppedAtOneTime = 20;
2821
3639
  var MaxSendAttempts = 6;
3640
+ var MaxSyncUnloadSendAttempts = 2;
2822
3641
  var MaxBackoffCount = 4;
2823
3642
  var globalContext = isWindowObjectAvailable ? window : undefined;
2824
3643
  var MaxConnections = 2;
2825
- var MaxRetries = 1;
3644
+ var MaxRequestRetriesBeforeBackoff = 1;
2826
3645
  var strEventsDiscarded = "eventsDiscarded";
2827
3646
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
3647
+ var strMaxEventRetryAttempts = "maxEventRetryAttempts";
3648
+ var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
3649
+ var strAddUnloadCb = "addUnloadCb";
2828
3650
  var PostChannel = /** @class */ (function (_super) {
2829
3651
  __extendsFn(PostChannel, _super);
2830
3652
  function PostChannel() {
2831
3653
  var _this = _super.call(this) || this;
2832
3654
  _this.identifier = "PostChannel";
2833
3655
  _this.priority = 1011;
2834
- _this.version = '3.1.9';
3656
+ _this.version = '3.2.0';
2835
3657
  var _config;
2836
3658
  var _isTeardownCalled = false;
2837
3659
  var _flushCallbackQueue = [];
@@ -2856,18 +3678,12 @@
2856
3678
  var _delayedBatchReason;
2857
3679
  var _optimizeObject = true;
2858
3680
  var _isPageUnloadTriggered = false;
3681
+ var _disableXhrSync = false;
3682
+ var _maxEventSendAttempts = MaxSendAttempts;
3683
+ var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
3684
+ var _evtNamespace;
2859
3685
  dynamicProto(PostChannel, _this, function (_self, _base) {
2860
- _initializeProfiles();
2861
- _clearQueues();
2862
- _setAutoLimits();
2863
- _httpManager = new HttpManager$1(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
2864
- requeue: _requeueEvents,
2865
- send: _sendingEvent,
2866
- sent: _eventsSentEvent,
2867
- drop: _eventsDropped,
2868
- rspFail: _eventsResponseFail,
2869
- oth: _otherEvent
2870
- });
3686
+ _initDefaults();
2871
3687
  _self["_getDbgPlgTargets"] = function () {
2872
3688
  return [_httpManager];
2873
3689
  };
@@ -2875,58 +3691,53 @@
2875
3691
  doPerf(core, function () { return "PostChannel:initialize"; }, function () {
2876
3692
  var extendedCore = core;
2877
3693
  _base.initialize(coreConfig, core, extensions);
2878
- _self.setInitialized(false);
2879
- var ctx = _self._getTelCtx();
2880
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
2881
- _config = ctx.getExtCfg(_self.identifier);
2882
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
2883
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
2884
- _optimizeObject = !_config.disableOptimizeObj && isChromium();
2885
- var existingGetWParamMethod = extendedCore.getWParam;
2886
- extendedCore.getWParam = function () {
2887
- var wparam = 0;
2888
- if (_config.ignoreMc1Ms0CookieProcessing) {
2889
- wparam = wparam | 2;
2890
- }
2891
- return wparam | existingGetWParamMethod();
2892
- };
2893
- if (_config.eventsLimitInMem > 0) {
2894
- _queueSizeLimit = _config.eventsLimitInMem;
2895
- }
2896
- if (_config.immediateEventLimit > 0) {
2897
- _immediateQueueSizeLimit = _config.immediateEventLimit;
2898
- }
2899
- if (_config.autoFlushEventsLimit > 0) {
2900
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
2901
- }
2902
- _setAutoLimits();
2903
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
2904
- _xhrOverride = _config.httpXHROverride;
2905
- }
2906
- if (isValueAssigned(coreConfig.anonCookieName)) {
2907
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
2908
- }
2909
- _httpManager.sendHook = _config.payloadPreprocessor;
2910
- _httpManager.sendListener = _config.payloadListener;
2911
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
2912
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
2913
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
2914
- function _handleUnloadEvents(evt) {
2915
- var theEvt = evt || getWindow().event;
2916
- if (theEvt.type !== "beforeunload") {
2917
- _isPageUnloadTriggered = true;
2918
- _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;
2919
3706
  }
2920
- _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;
2921
3740
  }
2922
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
2923
- addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
2924
- addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
2925
- addPageShowEventListener(function (evt) {
2926
- _isPageUnloadTriggered = false;
2927
- _httpManager.setUnloading(_isPageUnloadTriggered);
2928
- }, coreConfig.disablePageShowEvents);
2929
- _self.setInitialized(true);
2930
3741
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
2931
3742
  };
2932
3743
  _self.processTelemetry = function (ev, itemCtx) {
@@ -2955,12 +3766,43 @@
2955
3766
  }
2956
3767
  _self.processNext(event, itemCtx);
2957
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
+ }
2958
3800
  function _addEventToQueues(event, append) {
2959
3801
  if (!event.sendAttempt) {
2960
3802
  event.sendAttempt = 0;
2961
3803
  }
2962
3804
  if (!event.latency) {
2963
- event.latency = EventLatency.Normal;
3805
+ event.latency = 1 ;
2964
3806
  }
2965
3807
  if (event.ext && event.ext["trace"]) {
2966
3808
  delete (event.ext["trace"]);
@@ -2979,7 +3821,7 @@
2979
3821
  }
2980
3822
  if (event.sync) {
2981
3823
  if (_currentBackoffCount || _paused) {
2982
- event.latency = EventLatency.RealTime;
3824
+ event.latency = 3 ;
2983
3825
  event.sync = false;
2984
3826
  }
2985
3827
  else {
@@ -2995,7 +3837,7 @@
2995
3837
  var evtLatency = event.latency;
2996
3838
  var queueSize = _queueSize;
2997
3839
  var queueLimit = _queueSizeLimit;
2998
- if (evtLatency === EventLatency.Immediate) {
3840
+ if (evtLatency === 4 ) {
2999
3841
  queueSize = _immediateQueueSize;
3000
3842
  queueLimit = _immediateQueueSizeLimit;
3001
3843
  }
@@ -3004,10 +3846,10 @@
3004
3846
  eventDropped = !_addEventToProperQueue(event, append);
3005
3847
  }
3006
3848
  else {
3007
- var dropLatency = EventLatency.Normal;
3849
+ var dropLatency = 1 ;
3008
3850
  var dropNumber = EventsDroppedAtOneTime;
3009
- if (evtLatency === EventLatency.Immediate) {
3010
- dropLatency = EventLatency.Immediate;
3851
+ if (evtLatency === 4 ) {
3852
+ dropLatency = 4 ;
3011
3853
  dropNumber = 1;
3012
3854
  }
3013
3855
  eventDropped = true;
@@ -3025,7 +3867,7 @@
3025
3867
  _setAutoLimits();
3026
3868
  var doFlush = _queueSize > eventLimit;
3027
3869
  if (!doFlush && _autoFlushBatchLimit > 0) {
3028
- for (var latency = EventLatency.Normal; !doFlush && latency <= EventLatency.RealTime; latency++) {
3870
+ for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
3029
3871
  var batchQueue = _batchQueues[latency];
3030
3872
  if (batchQueue && batchQueue.batches) {
3031
3873
  arrForEach(batchQueue.batches, function (theBatch) {
@@ -3038,11 +3880,6 @@
3038
3880
  }
3039
3881
  _performAutoFlush(true, doFlush);
3040
3882
  };
3041
- _self.teardown = function () {
3042
- _releaseAllQueues(2 , 2 );
3043
- _isTeardownCalled = true;
3044
- _httpManager.teardown();
3045
- };
3046
3883
  _self.pause = function () {
3047
3884
  _clearScheduledTimer();
3048
3885
  _paused = true;
@@ -3084,7 +3921,7 @@
3084
3921
  _clearScheduledTimer();
3085
3922
  sendReason = sendReason || 1 ;
3086
3923
  if (async) {
3087
- _queueBatches(EventLatency.Normal, 0 , sendReason);
3924
+ _queueBatches(1 , 0 , sendReason);
3088
3925
  _resetQueueCounts();
3089
3926
  if (_flushCallbackTimerId == null) {
3090
3927
  _flushCallbackTimerId = _createTimer(function () {
@@ -3096,7 +3933,7 @@
3096
3933
  }
3097
3934
  }
3098
3935
  else {
3099
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 1 , sendReason);
3936
+ _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
3100
3937
  if (callback !== null && callback !== undefined) {
3101
3938
  callback();
3102
3939
  }
@@ -3104,7 +3941,7 @@
3104
3941
  }
3105
3942
  };
3106
3943
  _self.setMsaAuthTicket = function (ticket) {
3107
- _httpManager.addHeader("AuthMsaDeviceTicket", ticket);
3944
+ _httpManager.addHeader(strMsaDeviceTicket, ticket);
3108
3945
  };
3109
3946
  _self.hasEvents = _hasEvents;
3110
3947
  _self._setTransmitProfile = function (profileName) {
@@ -3131,7 +3968,7 @@
3131
3968
  if (immediateTimeOut >= 0) {
3132
3969
  _immediateTimerId = _createTimer(function () {
3133
3970
  _immediateTimerId = null;
3134
- _sendEventsForLatencyAndAbove(EventLatency.Immediate, 0 , 1 );
3971
+ _sendEventsForLatencyAndAbove(4 , 0 , 1 );
3135
3972
  _scheduleTimer();
3136
3973
  }, immediateTimeOut);
3137
3974
  }
@@ -3141,7 +3978,7 @@
3141
3978
  if (_hasEvents()) {
3142
3979
  _scheduledTimerId = _createTimer(function () {
3143
3980
  _scheduledTimerId = null;
3144
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? EventLatency.RealTime : EventLatency.Normal, 0 , 1 );
3981
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
3145
3982
  _timerCount++;
3146
3983
  _timerCount %= 2;
3147
3984
  _scheduleTimer();
@@ -3166,13 +4003,53 @@
3166
4003
  _scheduleTimer();
3167
4004
  }
3168
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
+ }
3169
4046
  function _createTimer(theTimerFunc, timeOut) {
3170
4047
  if (timeOut === 0 && _currentBackoffCount) {
3171
4048
  timeOut = 1;
3172
4049
  }
3173
4050
  var timerMultiplier = 1000;
3174
4051
  if (_currentBackoffCount) {
3175
- timerMultiplier = RetryPolicy$1.getMillisToBackoffForRetry(_currentBackoffCount - 1);
4052
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
3176
4053
  }
3177
4054
  return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
3178
4055
  }
@@ -3190,23 +4067,23 @@
3190
4067
  _flushCallbackTimerId = null;
3191
4068
  }
3192
4069
  if (!_paused) {
3193
- _sendEventsForLatencyAndAbove(EventLatency.Normal, sendType, sendReason);
4070
+ _sendEventsForLatencyAndAbove(1 , sendType, sendReason);
3194
4071
  }
3195
4072
  }
3196
4073
  function _clearQueues() {
3197
- _batchQueues[EventLatency.Immediate] = {
4074
+ _batchQueues[4 ] = {
3198
4075
  batches: [],
3199
4076
  iKeyMap: {}
3200
4077
  };
3201
- _batchQueues[EventLatency.RealTime] = {
4078
+ _batchQueues[3 ] = {
3202
4079
  batches: [],
3203
4080
  iKeyMap: {}
3204
4081
  };
3205
- _batchQueues[EventLatency.CostDeferred] = {
4082
+ _batchQueues[2 ] = {
3206
4083
  batches: [],
3207
4084
  iKeyMap: {}
3208
4085
  };
3209
- _batchQueues[EventLatency.Normal] = {
4086
+ _batchQueues[1 ] = {
3210
4087
  batches: [],
3211
4088
  iKeyMap: {}
3212
4089
  };
@@ -3214,7 +4091,7 @@
3214
4091
  function _getEventBatch(iKey, latency, create) {
3215
4092
  var batchQueue = _batchQueues[latency];
3216
4093
  if (!batchQueue) {
3217
- latency = EventLatency.Normal;
4094
+ latency = 1 ;
3218
4095
  batchQueue = _batchQueues[latency];
3219
4096
  }
3220
4097
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -3241,8 +4118,8 @@
3241
4118
  }
3242
4119
  var latency = event.latency;
3243
4120
  var eventBatch = _getEventBatch(event.iKey, latency, true);
3244
- if (eventBatch.addEvents([event], append)) {
3245
- if (latency !== EventLatency.Immediate) {
4121
+ if (eventBatch.addEvent(event)) {
4122
+ if (latency !== 4 ) {
3246
4123
  _queueSize++;
3247
4124
  if (append && event.sendAttempt === 0) {
3248
4125
  _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
@@ -3262,7 +4139,7 @@
3262
4139
  var droppedEvents = eventBatch.split(0, dropNumber);
3263
4140
  var droppedCount = droppedEvents.count();
3264
4141
  if (droppedCount > 0) {
3265
- if (currentLatency === EventLatency.Immediate) {
4142
+ if (currentLatency === 4 ) {
3266
4143
  _immediateQueueSize -= droppedCount;
3267
4144
  }
3268
4145
  else {
@@ -3284,7 +4161,7 @@
3284
4161
  var batchQueue = _batchQueues[latency];
3285
4162
  if (batchQueue && batchQueue.batches) {
3286
4163
  arrForEach(batchQueue.batches, function (theBatch) {
3287
- if (latency === EventLatency.Immediate) {
4164
+ if (latency === 4 ) {
3288
4165
  immediateQueue += theBatch.count();
3289
4166
  }
3290
4167
  else {
@@ -3293,7 +4170,7 @@
3293
4170
  });
3294
4171
  }
3295
4172
  };
3296
- for (var latency = EventLatency.Normal; latency <= EventLatency.Immediate; latency++) {
4173
+ for (var latency = 1 ; latency <= 4 ; latency++) {
3297
4174
  _loop_1(latency);
3298
4175
  }
3299
4176
  _queueSize = normalQueue;
@@ -3305,7 +4182,7 @@
3305
4182
  if (!isAsync || _httpManager.canSendRequest()) {
3306
4183
  doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
3307
4184
  var droppedEvents = [];
3308
- var latencyToProcess = EventLatency.Immediate;
4185
+ var latencyToProcess = 4 ;
3309
4186
  while (latencyToProcess >= latency) {
3310
4187
  var batchQueue = _batchQueues[latencyToProcess];
3311
4188
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -3316,7 +4193,7 @@
3316
4193
  else {
3317
4194
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
3318
4195
  }
3319
- if (latencyToProcess === EventLatency.Immediate) {
4196
+ if (latencyToProcess === 4 ) {
3320
4197
  _immediateQueueSize -= theBatch.count();
3321
4198
  }
3322
4199
  else {
@@ -3344,7 +4221,7 @@
3344
4221
  return eventsQueued;
3345
4222
  }
3346
4223
  function _flushImpl(callback, sendReason) {
3347
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 0 , sendReason);
4224
+ _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
3348
4225
  _waitForIdleManager(function () {
3349
4226
  if (callback) {
3350
4227
  callback();
@@ -3384,15 +4261,19 @@
3384
4261
  }
3385
4262
  function _requeueEvents(batches, reason) {
3386
4263
  var droppedEvents = [];
4264
+ var maxSendAttempts = _maxEventSendAttempts;
4265
+ if (_isPageUnloadTriggered) {
4266
+ maxSendAttempts = _maxUnloadEventSendAttempts;
4267
+ }
3387
4268
  arrForEach(batches, function (theBatch) {
3388
4269
  if (theBatch && theBatch.count() > 0) {
3389
4270
  arrForEach(theBatch.events(), function (theEvent) {
3390
4271
  if (theEvent) {
3391
4272
  if (theEvent.sync) {
3392
- theEvent.latency = EventLatency.Immediate;
4273
+ theEvent.latency = 4 ;
3393
4274
  theEvent.sync = false;
3394
4275
  }
3395
- if (theEvent.sendAttempt < MaxSendAttempts) {
4276
+ if (theEvent.sendAttempt < maxSendAttempts) {
3396
4277
  setProcessTelemetryTimings(theEvent, _self.identifier);
3397
4278
  _addEventToQueues(theEvent, false);
3398
4279
  }
@@ -3418,7 +4299,7 @@
3418
4299
  notifyFunc.apply(manager, theArgs);
3419
4300
  }
3420
4301
  catch (e) {
3421
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
4302
+ _throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
3422
4303
  }
3423
4304
  }
3424
4305
  }