@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
@@ -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
  */
@@ -18,20 +18,24 @@
18
18
  var ObjDefineProperty = ObjClass["defineProperty"];
19
19
  var ObjHasOwnProperty = ObjProto[strShimHasOwnProperty];
20
20
 
21
- function getGlobal() {
22
- if (typeof globalThis !== strShimUndefined && globalThis) {
23
- return globalThis;
24
- }
25
- if (typeof self !== strShimUndefined && self) {
26
- return self;
27
- }
28
- if (typeof window !== strShimUndefined && window) {
29
- return window;
30
- }
31
- if (typeof global !== strShimUndefined && global) {
32
- return global;
21
+ var _cachedGlobal = null;
22
+ function getGlobal(useCached) {
23
+ if (useCached === void 0) { useCached = true; }
24
+ if (!_cachedGlobal || !useCached) {
25
+ if (typeof globalThis !== strShimUndefined && globalThis) {
26
+ _cachedGlobal = globalThis;
27
+ }
28
+ if (typeof self !== strShimUndefined && self) {
29
+ _cachedGlobal = self;
30
+ }
31
+ if (typeof window !== strShimUndefined && window) {
32
+ _cachedGlobal = window;
33
+ }
34
+ if (typeof global !== strShimUndefined && global) {
35
+ _cachedGlobal = global;
36
+ }
33
37
  }
34
- return null;
38
+ return _cachedGlobal;
35
39
  }
36
40
  function throwTypeError(message) {
37
41
  throw new TypeError(message);
@@ -46,7 +50,7 @@
46
50
  }
47
51
  var type = typeof obj;
48
52
  if (type !== strShimObject && type !== strShimFunction) {
49
- throwTypeError('Object prototype may only be an Object:' + obj);
53
+ throwTypeError("Object prototype may only be an Object:" + obj);
50
54
  }
51
55
  function tmpFunc() { }
52
56
  tmpFunc[strShimPrototype] = obj;
@@ -55,18 +59,6 @@
55
59
 
56
60
  (getGlobal() || {})["Symbol"];
57
61
  (getGlobal() || {})["Reflect"];
58
- var __objAssignFnImpl = function (t) {
59
- for (var s, i = 1, n = arguments.length; i < n; i++) {
60
- s = arguments[i];
61
- for (var p in s) {
62
- if (ObjProto[strShimHasOwnProperty].call(s, p)) {
63
- t[p] = s[p];
64
- }
65
- }
66
- }
67
- return t;
68
- };
69
- var __assignFn = ObjAssign || __objAssignFnImpl;
70
62
  var extendStaticsFn = function (d, b) {
71
63
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
72
64
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -88,14 +80,356 @@
88
80
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
89
81
  }
90
82
 
91
- var EventsDiscardedReason = {
92
- Unknown: 0,
93
- NonRetryableStatus: 1,
94
- InvalidEvent: 2,
95
- SizeLimitExceeded: 3,
96
- KillSwitch: 4,
83
+ var strEmpty = "";
84
+ var strSetNextPlugin = "setNextPlugin";
85
+ var strIsInitialized = "isInitialized";
86
+ var strTeardown = "teardown";
87
+ var strCore = "core";
88
+ var strUpdate = "update";
89
+ var strDisabled = "disabled";
90
+ var strDoTeardown = "_doTeardown";
91
+
92
+ var cStrStartsWith = "startsWith";
93
+ var strIndexOf = "indexOf";
94
+ var cStrTrim = "trim";
95
+ var strToString = "toString";
96
+ var str__Proto$1 = "__proto__";
97
+ var strConstructor = "constructor";
98
+ var _objDefineProperty$1 = ObjDefineProperty;
99
+ var _objFreeze = ObjClass.freeze;
100
+ var _objKeys = ObjClass.keys;
101
+ var StringProto = String[strShimPrototype];
102
+ var _strTrim = StringProto[cStrTrim];
103
+ var _strStartsWith = StringProto[cStrStartsWith];
104
+ var _isArray = Array.isArray;
105
+ var _objToString = ObjProto[strToString];
106
+ var _fnToString = ObjHasOwnProperty[strToString];
107
+ var _objFunctionString = _fnToString.call(ObjClass);
108
+ var rCamelCase = /-([a-z])/g;
109
+ var rNormalizeInvalid = /([^\w\d_$])/g;
110
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
111
+ var _objGetPrototypeOf$1 = Object["getPrototypeOf"];
112
+ function _getObjProto$1(target) {
113
+ if (target) {
114
+ if (_objGetPrototypeOf$1) {
115
+ return _objGetPrototypeOf$1(target);
116
+ }
117
+ var newProto = target[str__Proto$1] || target[strShimPrototype] || target[strConstructor];
118
+ if (newProto) {
119
+ return newProto;
120
+ }
121
+ }
122
+ return null;
123
+ }
124
+ function isUndefined(value) {
125
+ return value === undefined || typeof value === strShimUndefined;
126
+ }
127
+ function isNullOrUndefined(value) {
128
+ return (value === null || isUndefined(value));
129
+ }
130
+ function hasOwnProperty(obj, prop) {
131
+ return !!(obj && ObjHasOwnProperty.call(obj, prop));
132
+ }
133
+ function isObject(value) {
134
+ return !!(value && typeof value === strShimObject);
135
+ }
136
+ function isFunction(value) {
137
+ return !!(value && typeof value === strShimFunction);
138
+ }
139
+ function normalizeJsName(name) {
140
+ var value = name;
141
+ if (value && isString(value)) {
142
+ value = value.replace(rCamelCase, function (_all, letter) {
143
+ return letter.toUpperCase();
144
+ });
145
+ value = value.replace(rNormalizeInvalid, "_");
146
+ value = value.replace(rLeadingNumeric, function (_all, match) {
147
+ return "_" + match;
148
+ });
149
+ }
150
+ return value;
151
+ }
152
+ function objForEachKey(target, callbackfn) {
153
+ if (target) {
154
+ for (var prop in target) {
155
+ if (ObjHasOwnProperty.call(target, prop)) {
156
+ callbackfn.call(target, prop, target[prop]);
157
+ }
158
+ }
159
+ }
160
+ }
161
+ function strStartsWith(value, checkValue) {
162
+ var result = false;
163
+ if (value && checkValue && !(result = value === checkValue)) {
164
+ result = _strStartsWith ? value[cStrStartsWith](checkValue) : _strStartsWithPoly(value, checkValue);
165
+ }
166
+ return result;
167
+ }
168
+ function _strStartsWithPoly(value, checkValue) {
169
+ var result = false;
170
+ var chkLen = checkValue ? checkValue.length : 0;
171
+ if (value && chkLen && value.length >= chkLen && !(result = value === checkValue)) {
172
+ for (var lp = 0; lp < chkLen; lp++) {
173
+ if (value[lp] !== checkValue[lp]) {
174
+ return false;
175
+ }
176
+ }
177
+ result = true;
178
+ }
179
+ return result;
180
+ }
181
+ function strContains(value, search) {
182
+ if (value && search) {
183
+ return value.indexOf(search) !== -1;
184
+ }
185
+ return false;
186
+ }
187
+ var isArray = _isArray || _isArrayPoly;
188
+ function _isArrayPoly(obj) {
189
+ return !!(obj && _objToString.call(obj) === "[object Array]");
190
+ }
191
+ function isString(value) {
192
+ return typeof value === "string";
193
+ }
194
+ function isNumber(value) {
195
+ return typeof value === "number";
196
+ }
197
+ function isBoolean(value) {
198
+ return typeof value === "boolean";
199
+ }
200
+ function isPlainObject(value) {
201
+ var result = false;
202
+ if (value && typeof value === "object") {
203
+ var proto = _objGetPrototypeOf$1 ? _objGetPrototypeOf$1(value) : _getObjProto$1(value);
204
+ if (!proto) {
205
+ result = true;
206
+ }
207
+ else {
208
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
209
+ proto = proto[strConstructor];
210
+ }
211
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
212
+ }
213
+ }
214
+ return result;
215
+ }
216
+ function arrForEach(arr, callbackfn, thisArg) {
217
+ var len = arr.length;
218
+ try {
219
+ for (var idx = 0; idx < len; idx++) {
220
+ if (idx in arr) {
221
+ if (callbackfn.call(thisArg || arr, arr[idx], idx, arr) === -1) {
222
+ break;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ catch (e) {
228
+ }
229
+ }
230
+ function arrIndexOf(arr, searchElement, fromIndex) {
231
+ if (arr) {
232
+ if (arr[strIndexOf]) {
233
+ return arr[strIndexOf](searchElement, fromIndex);
234
+ }
235
+ var len = arr.length;
236
+ var from = fromIndex || 0;
237
+ try {
238
+ for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
239
+ if (lp in arr && arr[lp] === searchElement) {
240
+ return lp;
241
+ }
242
+ }
243
+ }
244
+ catch (e) {
245
+ }
246
+ }
247
+ return -1;
248
+ }
249
+ function strTrim(str) {
250
+ if (str) {
251
+ str = (_strTrim && str[cStrTrim]) ? str[cStrTrim]() : (str.replace ? str.replace(/^\s+|\s+$/g, "") : str);
252
+ }
253
+ return str;
254
+ }
255
+ var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
256
+ var _objKeysDontEnums = [
257
+ "toString",
258
+ "toLocaleString",
259
+ "valueOf",
260
+ "hasOwnProperty",
261
+ "isPrototypeOf",
262
+ "propertyIsEnumerable",
263
+ "constructor"
264
+ ];
265
+ function objKeys(obj) {
266
+ var objType = typeof obj;
267
+ if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
268
+ throwTypeError("objKeys called on non-object");
269
+ }
270
+ if (!_objKeysHasDontEnumBug && _objKeys) {
271
+ return _objKeys(obj);
272
+ }
273
+ var result = [];
274
+ for (var prop in obj) {
275
+ if (obj && ObjHasOwnProperty.call(obj, prop)) {
276
+ result.push(prop);
277
+ }
278
+ }
279
+ if (_objKeysHasDontEnumBug) {
280
+ var dontEnumsLength = _objKeysDontEnums.length;
281
+ for (var lp = 0; lp < dontEnumsLength; lp++) {
282
+ if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
283
+ result.push(_objKeysDontEnums[lp]);
284
+ }
285
+ }
286
+ }
287
+ return result;
288
+ }
289
+ function objDefineAccessors(target, prop, getProp, setProp) {
290
+ if (_objDefineProperty$1) {
291
+ try {
292
+ var descriptor = {
293
+ enumerable: true,
294
+ configurable: true
295
+ };
296
+ if (getProp) {
297
+ descriptor.get = getProp;
298
+ }
299
+ if (setProp) {
300
+ descriptor.set = setProp;
301
+ }
302
+ _objDefineProperty$1(target, prop, descriptor);
303
+ return true;
304
+ }
305
+ catch (e) {
306
+ }
307
+ }
308
+ return false;
309
+ }
310
+ function _doNothing(value) {
311
+ return value;
312
+ }
313
+ function deepFreeze(obj) {
314
+ if (_objFreeze) {
315
+ objForEachKey(obj, function (name, value) {
316
+ if (isArray(value) || isObject(value)) {
317
+ _objFreeze(value);
318
+ }
319
+ });
320
+ }
321
+ return objFreeze(obj);
322
+ }
323
+ var objFreeze = _objFreeze || _doNothing;
324
+ function dateNow() {
325
+ var dt = Date;
326
+ return dt.now ? dt.now() : new dt().getTime();
327
+ }
328
+ function setValue(target, field, value, valChk, srcChk) {
329
+ var theValue = value;
330
+ if (target) {
331
+ theValue = target[field];
332
+ if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
333
+ theValue = value;
334
+ target[field] = theValue;
335
+ }
336
+ }
337
+ return theValue;
338
+ }
339
+ function _createProxyFunction(source, funcName) {
340
+ var srcFunc = null;
341
+ var src = null;
342
+ if (isFunction(source)) {
343
+ srcFunc = source;
344
+ }
345
+ else {
346
+ src = source;
347
+ }
348
+ return function () {
349
+ var originalArguments = arguments;
350
+ if (srcFunc) {
351
+ src = srcFunc();
352
+ }
353
+ if (src) {
354
+ return src[funcName].apply(src, originalArguments);
355
+ }
356
+ };
357
+ }
358
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
359
+ if (target && name && source) {
360
+ if (overwriteTarget !== false || isUndefined(target[name])) {
361
+ target[name] = _createProxyFunction(source, theFunc);
362
+ }
363
+ }
364
+ }
365
+ function optimizeObject(theObject) {
366
+ if (theObject && ObjAssign) {
367
+ theObject = ObjClass(ObjAssign({}, theObject));
368
+ }
369
+ return theObject;
370
+ }
371
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
372
+ var theArgs = arguments;
373
+ var extended = theArgs[0] || {};
374
+ var argLen = theArgs.length;
375
+ var deep = false;
376
+ var idx = 1;
377
+ if (argLen > 0 && isBoolean(extended)) {
378
+ deep = extended;
379
+ extended = theArgs[idx] || {};
380
+ idx++;
381
+ }
382
+ if (!isObject(extended)) {
383
+ extended = {};
384
+ }
385
+ for (; idx < argLen; idx++) {
386
+ var arg = theArgs[idx];
387
+ var isArgArray = isArray(arg);
388
+ var isArgObj = isObject(arg);
389
+ for (var prop in arg) {
390
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
391
+ if (!propOk) {
392
+ continue;
393
+ }
394
+ var newValue = arg[prop];
395
+ var isNewArray = void 0;
396
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
397
+ var clone = extended[prop];
398
+ if (isNewArray) {
399
+ if (!isArray(clone)) {
400
+ clone = [];
401
+ }
402
+ }
403
+ else if (!isPlainObject(clone)) {
404
+ clone = {};
405
+ }
406
+ newValue = objExtend(deep, clone, newValue);
407
+ }
408
+ if (newValue !== undefined) {
409
+ extended[prop] = newValue;
410
+ }
411
+ }
412
+ }
413
+ return extended;
414
+ }
415
+
416
+ function createEnumStyle(values) {
417
+ var enumClass = {};
418
+ objForEachKey(values, function (field, value) {
419
+ enumClass[field] = value;
420
+ enumClass[value] = field;
421
+ });
422
+ return deepFreeze(enumClass);
423
+ }
424
+
425
+ var EventsDiscardedReason = createEnumStyle({
426
+ Unknown: 0 ,
427
+ NonRetryableStatus: 1 ,
428
+ InvalidEvent: 2 ,
429
+ SizeLimitExceeded: 3 ,
430
+ KillSwitch: 4 ,
97
431
  QueueFull: 5
98
- };
432
+ });
99
433
 
100
434
  /*!
101
435
  * Microsoft Dynamic Proto Utility, 1.1.4
@@ -309,315 +643,34 @@
309
643
  if (!_checkPrototype(classProto, target)) {
310
644
  _throwTypeError("[" + _getObjName(theClass) + "] is not in class hierarchy of [" + _getObjName(target) + "]");
311
645
  }
312
- var className = null;
313
- if (_hasOwnProperty(classProto, DynClassName)) {
314
- className = classProto[DynClassName];
315
- }
316
- else {
317
- className = DynClassNamePrefix + _getObjName(theClass, "_") + "$" + _dynamicNames;
318
- _dynamicNames++;
319
- classProto[DynClassName] = className;
320
- }
321
- var perfOptions = dynamicProto[DynProtoDefaultOptions];
322
- var useBaseInst = !!perfOptions[strUseBaseInst];
323
- if (useBaseInst && options && options[strUseBaseInst] !== undefined) {
324
- useBaseInst = !!options[strUseBaseInst];
325
- }
326
- var instFuncs = _getInstanceFuncs(target);
327
- var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
328
- delegateFunc(target, baseFuncs);
329
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
330
- if (setInstanceFunc && options) {
331
- setInstanceFunc = !!options[strSetInstFuncs];
332
- }
333
- _populatePrototype(classProto, className, target, instFuncs, setInstanceFunc !== false);
334
- }
335
- var perfDefaults = {
336
- setInstFuncs: true,
337
- useBaseInst: true
338
- };
339
- dynamicProto[DynProtoDefaultOptions] = perfDefaults;
340
-
341
- var LoggingSeverity;
342
- (function (LoggingSeverity) {
343
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
344
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
345
- })(LoggingSeverity || (LoggingSeverity = {}));
346
- var _InternalMessageId = {
347
- BrowserDoesNotSupportLocalStorage: 0,
348
- BrowserCannotReadLocalStorage: 1,
349
- BrowserCannotReadSessionStorage: 2,
350
- BrowserCannotWriteLocalStorage: 3,
351
- BrowserCannotWriteSessionStorage: 4,
352
- BrowserFailedRemovalFromLocalStorage: 5,
353
- BrowserFailedRemovalFromSessionStorage: 6,
354
- CannotSendEmptyTelemetry: 7,
355
- ClientPerformanceMathError: 8,
356
- ErrorParsingAISessionCookie: 9,
357
- ErrorPVCalc: 10,
358
- ExceptionWhileLoggingError: 11,
359
- FailedAddingTelemetryToBuffer: 12,
360
- FailedMonitorAjaxAbort: 13,
361
- FailedMonitorAjaxDur: 14,
362
- FailedMonitorAjaxOpen: 15,
363
- FailedMonitorAjaxRSC: 16,
364
- FailedMonitorAjaxSend: 17,
365
- FailedMonitorAjaxGetCorrelationHeader: 18,
366
- FailedToAddHandlerForOnBeforeUnload: 19,
367
- FailedToSendQueuedTelemetry: 20,
368
- FailedToReportDataLoss: 21,
369
- FlushFailed: 22,
370
- MessageLimitPerPVExceeded: 23,
371
- MissingRequiredFieldSpecification: 24,
372
- NavigationTimingNotSupported: 25,
373
- OnError: 26,
374
- SessionRenewalDateIsZero: 27,
375
- SenderNotInitialized: 28,
376
- StartTrackEventFailed: 29,
377
- StopTrackEventFailed: 30,
378
- StartTrackFailed: 31,
379
- StopTrackFailed: 32,
380
- TelemetrySampledAndNotSent: 33,
381
- TrackEventFailed: 34,
382
- TrackExceptionFailed: 35,
383
- TrackMetricFailed: 36,
384
- TrackPVFailed: 37,
385
- TrackPVFailedCalc: 38,
386
- TrackTraceFailed: 39,
387
- TransmissionFailed: 40,
388
- FailedToSetStorageBuffer: 41,
389
- FailedToRestoreStorageBuffer: 42,
390
- InvalidBackendResponse: 43,
391
- FailedToFixDepricatedValues: 44,
392
- InvalidDurationValue: 45,
393
- TelemetryEnvelopeInvalid: 46,
394
- CreateEnvelopeError: 47,
395
- CannotSerializeObject: 48,
396
- CannotSerializeObjectNonSerializable: 49,
397
- CircularReferenceDetected: 50,
398
- ClearAuthContextFailed: 51,
399
- ExceptionTruncated: 52,
400
- IllegalCharsInName: 53,
401
- ItemNotInArray: 54,
402
- MaxAjaxPerPVExceeded: 55,
403
- MessageTruncated: 56,
404
- NameTooLong: 57,
405
- SampleRateOutOfRange: 58,
406
- SetAuthContextFailed: 59,
407
- SetAuthContextFailedAccountName: 60,
408
- StringValueTooLong: 61,
409
- StartCalledMoreThanOnce: 62,
410
- StopCalledWithoutStart: 63,
411
- TelemetryInitializerFailed: 64,
412
- TrackArgumentsNotSpecified: 65,
413
- UrlTooLong: 66,
414
- SessionStorageBufferFull: 67,
415
- CannotAccessCookie: 68,
416
- IdTooLong: 69,
417
- InvalidEvent: 70,
418
- FailedMonitorAjaxSetRequestHeader: 71,
419
- SendBrowserInfoOnUserInit: 72,
420
- PluginException: 73,
421
- NotificationException: 74,
422
- SnippetScriptLoadFailure: 99,
423
- InvalidInstrumentationKey: 100,
424
- CannotParseAiBlobValue: 101,
425
- InvalidContentBlob: 102,
426
- TrackPageActionEventFailed: 103,
427
- FailedAddingCustomDefinedRequestContext: 104,
428
- InMemoryStorageBufferFull: 105
429
- };
430
-
431
- var strOnPrefix = "on";
432
- var strAttachEvent = "attachEvent";
433
- var strAddEventHelper = "addEventListener";
434
- var _objDefineProperty = ObjDefineProperty;
435
- function objToString(obj) {
436
- return ObjProto.toString.call(obj);
437
- }
438
- function isUndefined(value) {
439
- return value === undefined || typeof value === strShimUndefined;
440
- }
441
- function isNullOrUndefined(value) {
442
- return (value === null || isUndefined(value));
443
- }
444
- function hasOwnProperty(obj, prop) {
445
- return obj && ObjHasOwnProperty.call(obj, prop);
446
- }
447
- function isObject(value) {
448
- return typeof value === strShimObject;
449
- }
450
- function isFunction(value) {
451
- return typeof value === strShimFunction;
452
- }
453
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
454
- if (useCapture === void 0) { useCapture = false; }
455
- var result = false;
456
- if (!isNullOrUndefined(obj)) {
457
- try {
458
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
459
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
460
- result = true;
461
- }
462
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
463
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
464
- result = true;
465
- }
466
- }
467
- catch (e) {
468
- }
469
- }
470
- return result;
471
- }
472
- function objForEachKey(target, callbackfn) {
473
- if (target) {
474
- for (var prop in target) {
475
- if (ObjHasOwnProperty.call(target, prop)) {
476
- callbackfn.call(target, prop, target[prop]);
477
- }
478
- }
479
- }
480
- }
481
- function strStartsWith(value, checkValue) {
482
- var result = false;
483
- if (value && checkValue) {
484
- var chkLen = checkValue.length;
485
- if (value === checkValue) {
486
- return true;
487
- }
488
- else if (value.length >= chkLen) {
489
- for (var lp = 0; lp < chkLen; lp++) {
490
- if (value[lp] !== checkValue[lp]) {
491
- return false;
492
- }
493
- }
494
- result = true;
495
- }
496
- }
497
- return result;
498
- }
499
- function isArray(obj) {
500
- return objToString(obj) === "[object Array]";
501
- }
502
- function isString(value) {
503
- return typeof value === "string";
504
- }
505
- function isNumber(value) {
506
- return typeof value === "number";
507
- }
508
- function isBoolean(value) {
509
- return typeof value === "boolean";
510
- }
511
- function arrForEach(arr, callbackfn, thisArg) {
512
- var len = arr.length;
513
- try {
514
- for (var idx = 0; idx < len; idx++) {
515
- if (idx in arr) {
516
- if (callbackfn.call(thisArg || arr, arr[idx], idx, arr) === -1) {
517
- break;
518
- }
519
- }
520
- }
521
- }
522
- catch (e) {
523
- }
524
- }
525
- function arrIndexOf(arr, searchElement, fromIndex) {
526
- var len = arr.length;
527
- var from = fromIndex || 0;
528
- try {
529
- for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
530
- if (lp in arr && arr[lp] === searchElement) {
531
- return lp;
532
- }
533
- }
534
- }
535
- catch (e) {
536
- }
537
- return -1;
538
- }
539
- function strTrim(str) {
540
- if (typeof str !== "string") {
541
- return str;
542
- }
543
- return str.replace(/^\s+|\s+$/g, "");
544
- }
545
- var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
546
- var _objKeysDontEnums = [
547
- "toString",
548
- "toLocaleString",
549
- "valueOf",
550
- "hasOwnProperty",
551
- "isPrototypeOf",
552
- "propertyIsEnumerable",
553
- "constructor"
554
- ];
555
- function objKeys(obj) {
556
- var objType = typeof obj;
557
- if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
558
- throwTypeError("objKeys called on non-object");
559
- }
560
- var result = [];
561
- for (var prop in obj) {
562
- if (obj && ObjHasOwnProperty.call(obj, prop)) {
563
- result.push(prop);
564
- }
565
- }
566
- if (_objKeysHasDontEnumBug) {
567
- var dontEnumsLength = _objKeysDontEnums.length;
568
- for (var lp = 0; lp < dontEnumsLength; lp++) {
569
- if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
570
- result.push(_objKeysDontEnums[lp]);
571
- }
572
- }
573
- }
574
- return result;
575
- }
576
- function objDefineAccessors(target, prop, getProp, setProp) {
577
- if (_objDefineProperty) {
578
- try {
579
- var descriptor = {
580
- enumerable: true,
581
- configurable: true
582
- };
583
- if (getProp) {
584
- descriptor.get = getProp;
585
- }
586
- if (setProp) {
587
- descriptor.set = setProp;
588
- }
589
- _objDefineProperty(target, prop, descriptor);
590
- return true;
591
- }
592
- catch (e) {
593
- }
646
+ var className = null;
647
+ if (_hasOwnProperty(classProto, DynClassName)) {
648
+ className = classProto[DynClassName];
594
649
  }
595
- return false;
596
- }
597
- function dateNow() {
598
- var dt = Date;
599
- if (dt.now) {
600
- return dt.now();
650
+ else {
651
+ className = DynClassNamePrefix + _getObjName(theClass, "_") + "$" + _dynamicNames;
652
+ _dynamicNames++;
653
+ classProto[DynClassName] = className;
601
654
  }
602
- return new dt().getTime();
603
- }
604
- function setValue(target, field, value, valChk, srcChk) {
605
- var theValue = value;
606
- if (target) {
607
- theValue = target[field];
608
- if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
609
- theValue = value;
610
- target[field] = theValue;
611
- }
655
+ var perfOptions = dynamicProto[DynProtoDefaultOptions];
656
+ var useBaseInst = !!perfOptions[strUseBaseInst];
657
+ if (useBaseInst && options && options[strUseBaseInst] !== undefined) {
658
+ useBaseInst = !!options[strUseBaseInst];
612
659
  }
613
- return theValue;
614
- }
615
- function optimizeObject(theObject) {
616
- if (theObject) {
617
- theObject = ObjClass(ObjAssign ? ObjAssign({}, theObject) : theObject);
660
+ var instFuncs = _getInstanceFuncs(target);
661
+ var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
662
+ delegateFunc(target, baseFuncs);
663
+ var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
664
+ if (setInstanceFunc && options) {
665
+ setInstanceFunc = !!options[strSetInstFuncs];
618
666
  }
619
- return theObject;
667
+ _populatePrototype(classProto, className, target, instFuncs, setInstanceFunc !== false);
620
668
  }
669
+ var perfDefaults = {
670
+ setInstFuncs: true,
671
+ useBaseInst: true
672
+ };
673
+ dynamicProto[DynProtoDefaultOptions] = perfDefaults;
621
674
 
622
675
  var strWindow = "window";
623
676
  var strDocument = "document";
@@ -626,7 +679,14 @@
626
679
  var strConsole = "console";
627
680
  var strPerformance = "performance";
628
681
  var strJSON = "JSON";
682
+ var strCrypto = "crypto";
683
+ var strMsCrypto = "msCrypto";
629
684
  var strReactNative = "ReactNative";
685
+ var strMsie = "msie";
686
+ var strTrident = "trident/";
687
+ var strXMLHttpRequest = "XMLHttpRequest";
688
+ var _isTrident = null;
689
+ var _navUserAgentCheck = null;
630
690
  var _enableMocks = false;
631
691
  var _useXDomainRequest = null;
632
692
  var _beaconsSupported = null;
@@ -722,6 +782,12 @@
722
782
  }
723
783
  return null;
724
784
  }
785
+ function getCrypto() {
786
+ return getGlobalInst(strCrypto);
787
+ }
788
+ function getMsCrypto() {
789
+ return getGlobalInst(strMsCrypto);
790
+ }
725
791
  function isReactNative() {
726
792
  var nav = getNavigator();
727
793
  if (nav && nav.product) {
@@ -729,9 +795,18 @@
729
795
  }
730
796
  return false;
731
797
  }
798
+ function isIE() {
799
+ var nav = getNavigator();
800
+ if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
801
+ _navUserAgentCheck = nav.userAgent;
802
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
803
+ _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
804
+ }
805
+ return _isTrident;
806
+ }
732
807
  function dumpObj(object) {
733
808
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
734
- var propertyValueDump = "";
809
+ var propertyValueDump = strEmpty;
735
810
  if (objectTypeDump === "[object Error]") {
736
811
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
737
812
  }
@@ -749,8 +824,7 @@
749
824
  function isFetchSupported(withKeepAlive) {
750
825
  var isSupported = false;
751
826
  try {
752
- var fetchApi = getGlobalInst("fetch");
753
- isSupported = !!fetchApi;
827
+ isSupported = !!getGlobalInst("fetch");
754
828
  var request = getGlobalInst("Request");
755
829
  if (isSupported && withKeepAlive && request) {
756
830
  isSupported = _hasProperty(request, "keepalive");
@@ -762,9 +836,9 @@
762
836
  }
763
837
  function useXDomainRequest() {
764
838
  if (_useXDomainRequest === null) {
765
- _useXDomainRequest = (typeof XDomainRequest !== undefined);
839
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
766
840
  if (_useXDomainRequest && isXhrSupported()) {
767
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
841
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
768
842
  }
769
843
  }
770
844
  return _useXDomainRequest;
@@ -772,7 +846,7 @@
772
846
  function isXhrSupported() {
773
847
  var isSupported = false;
774
848
  try {
775
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
849
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
776
850
  isSupported = !!xmlHttpRequest;
777
851
  }
778
852
  catch (e) {
@@ -780,6 +854,22 @@
780
854
  return isSupported;
781
855
  }
782
856
 
857
+ var _aiNamespace = null;
858
+ function _getExtensionNamespace() {
859
+ var target = getGlobalInst("Microsoft");
860
+ if (target) {
861
+ _aiNamespace = target["ApplicationInsights"];
862
+ }
863
+ return _aiNamespace;
864
+ }
865
+ function getDebugExt(config) {
866
+ var ns = _aiNamespace;
867
+ if (!ns && config.disableDbgExt !== true) {
868
+ ns = _aiNamespace || _getExtensionNamespace();
869
+ }
870
+ return ns ? ns["ChromeDbgExt"] : null;
871
+ }
872
+
783
873
  var AiNonUserActionablePrefix = "AI (Internal): ";
784
874
  var AiUserActionablePrefix = "AI: ";
785
875
  var AIInternalMessagePrefix = "AITR_";
@@ -787,9 +877,9 @@
787
877
  var strWarnToConsole = "warnToConsole";
788
878
  function _sanitizeDiagnosticText(text) {
789
879
  if (text) {
790
- return "\"" + text.replace(/\"/g, "") + "\"";
880
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
791
881
  }
792
- return "";
882
+ return strEmpty;
793
883
  }
794
884
  function _logToConsole(func, message) {
795
885
  var theConsole = getConsole();
@@ -811,12 +901,12 @@
811
901
  _self.message =
812
902
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
813
903
  msgId;
814
- var strProps = "";
904
+ var strProps = strEmpty;
815
905
  if (hasJSON()) {
816
906
  strProps = getJSON().stringify(properties);
817
907
  }
818
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
819
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
908
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
909
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
820
910
  _self.message += diagnosticText;
821
911
  }
822
912
  _InternalLogMessage.dataType = "MessageData";
@@ -846,7 +936,7 @@
846
936
  throw message;
847
937
  }
848
938
  else {
849
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
939
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
850
940
  if (!isUndefined(message.message)) {
851
941
  var logLevel = _self.consoleLoggingLevel();
852
942
  if (isUserAct) {
@@ -863,13 +953,18 @@
863
953
  }
864
954
  _self.logInternalMessage(severity, message);
865
955
  }
956
+ else {
957
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
958
+ }
866
959
  }
867
960
  };
868
961
  _self.warnToConsole = function (message) {
869
962
  _logToConsole("warn", message);
963
+ _debugExtMsg("warning", message);
870
964
  };
871
965
  _self.errorToConsole = function (message) {
872
966
  _logToConsole("error", message);
967
+ _debugExtMsg("error", message);
873
968
  };
874
969
  _self.resetInternalMessageCount = function () {
875
970
  _messageCount = 0;
@@ -891,12 +986,18 @@
891
986
  if (severity <= _self.telemetryLoggingLevel()) {
892
987
  _self.queue.push(message);
893
988
  _messageCount++;
989
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
894
990
  }
895
991
  if (_messageCount === _self.maxInternalMessageLimit()) {
896
992
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
897
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
993
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
898
994
  _self.queue.push(throttleMessage);
899
- _self.warnToConsole(throttleLimitMessage);
995
+ if (severity === 1 ) {
996
+ _self.errorToConsole(throttleLimitMessage);
997
+ }
998
+ else {
999
+ _self.warnToConsole(throttleLimitMessage);
1000
+ }
900
1001
  }
901
1002
  }
902
1003
  };
@@ -910,10 +1011,20 @@
910
1011
  function _areInternalMessagesThrottled() {
911
1012
  return _messageCount >= _self.maxInternalMessageLimit();
912
1013
  }
1014
+ function _debugExtMsg(name, data) {
1015
+ var dbgExt = getDebugExt(config);
1016
+ if (dbgExt && dbgExt.diagLog) {
1017
+ dbgExt.diagLog(name, data);
1018
+ }
1019
+ }
913
1020
  });
914
1021
  }
915
1022
  return DiagnosticLogger;
916
1023
  }());
1024
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1025
+ if (isUserAct === void 0) { isUserAct = false; }
1026
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1027
+ }
917
1028
 
918
1029
  var strExecutionContextKey = "ctx";
919
1030
  var PerfEvent = /** @class */ (function () {
@@ -1027,207 +1138,621 @@
1027
1138
  return func();
1028
1139
  }
1029
1140
 
1030
- var TelemetryPluginChain = /** @class */ (function () {
1031
- function TelemetryPluginChain(plugin, defItemCtx) {
1032
- var _self = this;
1033
- var _nextProxy = null;
1034
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1035
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1036
- _self._hasRun = false;
1037
- _self.getPlugin = function () {
1038
- return plugin;
1039
- };
1040
- _self.getNext = function () {
1041
- return _nextProxy;
1042
- };
1043
- _self.setNext = function (nextPlugin) {
1044
- _nextProxy = nextPlugin;
1045
- };
1046
- _self.processTelemetry = function (env, itemCtx) {
1047
- if (!itemCtx) {
1048
- itemCtx = defItemCtx;
1141
+ var UInt32Mask = 0x100000000;
1142
+ var MaxUInt32 = 0xffffffff;
1143
+ var _mwcSeeded = false;
1144
+ var _mwcW = 123456789;
1145
+ var _mwcZ = 987654321;
1146
+ function _mwcSeed(seedValue) {
1147
+ if (seedValue < 0) {
1148
+ seedValue >>>= 0;
1149
+ }
1150
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1151
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1152
+ _mwcSeeded = true;
1153
+ }
1154
+ function _autoSeedMwc() {
1155
+ try {
1156
+ var now = dateNow() & 0x7fffffff;
1157
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1158
+ }
1159
+ catch (e) {
1160
+ }
1161
+ }
1162
+ function random32(signed) {
1163
+ var value = 0;
1164
+ var c = getCrypto() || getMsCrypto();
1165
+ if (c && c.getRandomValues) {
1166
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1167
+ }
1168
+ if (value === 0 && isIE()) {
1169
+ if (!_mwcSeeded) {
1170
+ _autoSeedMwc();
1171
+ }
1172
+ value = mwcRandom32() & MaxUInt32;
1173
+ }
1174
+ if (value === 0) {
1175
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1176
+ }
1177
+ if (!signed) {
1178
+ value >>>= 0;
1179
+ }
1180
+ return value;
1181
+ }
1182
+ function mwcRandom32(signed) {
1183
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1184
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1185
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1186
+ if (!signed) {
1187
+ value >>>= 0;
1188
+ }
1189
+ return value;
1190
+ }
1191
+ function newId(maxLength) {
1192
+ if (maxLength === void 0) { maxLength = 22; }
1193
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1194
+ var number = random32() >>> 0;
1195
+ var chars = 0;
1196
+ var result = strEmpty;
1197
+ while (result.length < maxLength) {
1198
+ chars++;
1199
+ result += base64chars.charAt(number & 0x3F);
1200
+ number >>>= 6;
1201
+ if (chars === 5) {
1202
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1203
+ chars = 0;
1204
+ }
1205
+ }
1206
+ return result;
1207
+ }
1208
+
1209
+ var _objDefineProperty = ObjDefineProperty;
1210
+ var version = "2.8.0";
1211
+ var instanceName = "." + newId(6);
1212
+ var _dataUid = 0;
1213
+ function _createAccessor(target, prop, value) {
1214
+ if (_objDefineProperty) {
1215
+ try {
1216
+ _objDefineProperty(target, prop, {
1217
+ value: value,
1218
+ enumerable: false,
1219
+ configurable: true
1220
+ });
1221
+ return true;
1222
+ }
1223
+ catch (e) {
1224
+ }
1225
+ }
1226
+ return false;
1227
+ }
1228
+ function _canAcceptData(target) {
1229
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1230
+ }
1231
+ function _getCache(data, target) {
1232
+ var theCache = target[data.id];
1233
+ if (!theCache) {
1234
+ theCache = {};
1235
+ try {
1236
+ if (_canAcceptData(target)) {
1237
+ if (!_createAccessor(target, data.id, theCache)) {
1238
+ target[data.id] = theCache;
1239
+ }
1240
+ }
1241
+ }
1242
+ catch (e) {
1243
+ }
1244
+ }
1245
+ return theCache;
1246
+ }
1247
+ function createUniqueNamespace(name, includeVersion) {
1248
+ if (includeVersion === void 0) { includeVersion = false; }
1249
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1250
+ }
1251
+ function createElmNodeData(name) {
1252
+ var data = {
1253
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1254
+ accept: function (target) {
1255
+ return _canAcceptData(target);
1256
+ },
1257
+ get: function (target, name, defValue, addDefault) {
1258
+ var theCache = target[data.id];
1259
+ if (!theCache) {
1260
+ if (addDefault) {
1261
+ theCache = _getCache(data, target);
1262
+ theCache[normalizeJsName(name)] = defValue;
1263
+ }
1264
+ return defValue;
1265
+ }
1266
+ return theCache[normalizeJsName(name)];
1267
+ },
1268
+ kill: function (target, name) {
1269
+ if (target && target[name]) {
1270
+ try {
1271
+ delete target[name];
1272
+ }
1273
+ catch (e) {
1274
+ }
1049
1275
  }
1050
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1051
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1052
- if (plugin && _hasProcessTelemetry) {
1053
- _self._hasRun = true;
1276
+ }
1277
+ };
1278
+ return data;
1279
+ }
1280
+
1281
+ var pluginStateData = createElmNodeData("plugin");
1282
+ function _getPluginState(plugin) {
1283
+ return pluginStateData.get(plugin, "state", {}, true);
1284
+ }
1285
+
1286
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1287
+ var strHasRunFlags = "_hasRun";
1288
+ var strGetTelCtx = "_getTelCtx";
1289
+ var _chainId = 0;
1290
+ function _getNextProxyStart(proxy, core, startAt) {
1291
+ while (proxy) {
1292
+ if (proxy.getPlugin() === startAt) {
1293
+ return proxy;
1294
+ }
1295
+ proxy = proxy.getNext();
1296
+ }
1297
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
1298
+ }
1299
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1300
+ var _nextProxy = null;
1301
+ var _onComplete = [];
1302
+ if (startAt !== null) {
1303
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1304
+ }
1305
+ var context = {
1306
+ _next: _moveNext,
1307
+ ctx: {
1308
+ core: function () {
1309
+ return core;
1310
+ },
1311
+ diagLog: function () {
1312
+ return safeGetLogger(core, config);
1313
+ },
1314
+ getCfg: function () {
1315
+ return config;
1316
+ },
1317
+ getExtCfg: _getExtCfg,
1318
+ getConfig: _getConfig,
1319
+ hasNext: function () {
1320
+ return !!_nextProxy;
1321
+ },
1322
+ getNext: function () {
1323
+ return _nextProxy;
1324
+ },
1325
+ setNext: function (nextPlugin) {
1326
+ _nextProxy = nextPlugin;
1327
+ },
1328
+ iterate: _iterateChain,
1329
+ onComplete: _addOnComplete
1330
+ }
1331
+ };
1332
+ function _addOnComplete(onComplete, that) {
1333
+ var args = [];
1334
+ for (var _i = 2; _i < arguments.length; _i++) {
1335
+ args[_i - 2] = arguments[_i];
1336
+ }
1337
+ if (onComplete) {
1338
+ _onComplete.push({
1339
+ func: onComplete,
1340
+ self: !isUndefined(that) ? that : context.ctx,
1341
+ args: args
1342
+ });
1343
+ }
1344
+ }
1345
+ function _moveNext() {
1346
+ var nextProxy = _nextProxy;
1347
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1348
+ if (!nextProxy) {
1349
+ var onComplete = _onComplete;
1350
+ if (onComplete && onComplete.length > 0) {
1351
+ arrForEach(onComplete, function (completeDetails) {
1054
1352
  try {
1055
- itemCtx.setNext(_nextProxy);
1056
- if (_hasSetNext) {
1057
- plugin.setNextPlugin(_nextProxy);
1058
- }
1059
- _nextProxy && (_nextProxy._hasRun = false);
1060
- plugin.processTelemetry(env, itemCtx);
1353
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1061
1354
  }
1062
- catch (error) {
1063
- var hasRun = _nextProxy && _nextProxy._hasRun;
1064
- if (!_nextProxy || !hasRun) {
1065
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1066
- }
1067
- if (_nextProxy && !hasRun) {
1068
- _nextProxy.processTelemetry(env, itemCtx);
1069
- }
1355
+ catch (e) {
1356
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1070
1357
  }
1071
- }
1072
- else if (_nextProxy) {
1073
- _self._hasRun = true;
1074
- _nextProxy.processTelemetry(env, itemCtx);
1075
- }
1076
- }, function () { return ({ item: env }); }, !(env.sync));
1077
- };
1358
+ });
1359
+ _onComplete = [];
1360
+ }
1361
+ }
1362
+ return nextProxy;
1078
1363
  }
1079
- return TelemetryPluginChain;
1080
- }());
1081
-
1082
- function _createProxyChain(plugins, itemCtx) {
1083
- var proxies = [];
1084
- if (plugins && plugins.length > 0) {
1085
- var lastProxy = null;
1086
- for (var idx = 0; idx < plugins.length; idx++) {
1087
- var thePlugin = plugins[idx];
1088
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1089
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1090
- proxies.push(newProxy);
1091
- if (lastProxy) {
1092
- lastProxy.setNext(newProxy);
1364
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1365
+ if (defaultValue === void 0) { defaultValue = {}; }
1366
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1367
+ var theConfig;
1368
+ if (config) {
1369
+ var extConfig = config.extensionConfig;
1370
+ if (extConfig && identifier) {
1371
+ theConfig = extConfig[identifier];
1372
+ }
1373
+ }
1374
+ if (!theConfig) {
1375
+ theConfig = defaultValue;
1376
+ }
1377
+ else if (isObject(defaultValue)) {
1378
+ if (mergeDefault !== 0 ) {
1379
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1380
+ if (config && mergeDefault === 2 ) {
1381
+ objForEachKey(defaultValue, function (field) {
1382
+ if (isNullOrUndefined(newConfig_1[field])) {
1383
+ var cfgValue = config[field];
1384
+ if (!isNullOrUndefined(cfgValue)) {
1385
+ newConfig_1[field] = cfgValue;
1386
+ }
1387
+ }
1388
+ });
1093
1389
  }
1094
- lastProxy = newProxy;
1390
+ theConfig = newConfig_1;
1095
1391
  }
1096
1392
  }
1393
+ return theConfig;
1097
1394
  }
1098
- return proxies.length > 0 ? proxies[0] : null;
1099
- }
1100
- function _copyProxyChain(proxy, itemCtx, startAt) {
1101
- var plugins = [];
1102
- var add = startAt ? false : true;
1103
- if (proxy) {
1104
- while (proxy) {
1105
- var thePlugin = proxy.getPlugin();
1106
- if (add || thePlugin === startAt) {
1107
- add = true;
1108
- plugins.push(thePlugin);
1395
+ function _getConfig(identifier, field, defaultValue) {
1396
+ if (defaultValue === void 0) { defaultValue = false; }
1397
+ var theValue;
1398
+ var extConfig = _getExtCfg(identifier, null);
1399
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1400
+ theValue = extConfig[field];
1401
+ }
1402
+ else if (config && !isNullOrUndefined(config[field])) {
1403
+ theValue = config[field];
1404
+ }
1405
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1406
+ }
1407
+ function _iterateChain(cb) {
1408
+ var nextPlugin;
1409
+ while (!!(nextPlugin = context._next())) {
1410
+ var plugin = nextPlugin.getPlugin();
1411
+ if (plugin) {
1412
+ cb(plugin);
1109
1413
  }
1110
- proxy = proxy.getNext();
1111
1414
  }
1112
1415
  }
1113
- if (!add) {
1114
- plugins.push(startAt);
1416
+ return context;
1417
+ }
1418
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1419
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1420
+ var context = internalContext.ctx;
1421
+ function _processNext(env) {
1422
+ var nextPlugin = internalContext._next();
1423
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1424
+ return !nextPlugin;
1425
+ }
1426
+ function _createNew(plugins, startAt) {
1427
+ if (plugins === void 0) { plugins = null; }
1428
+ if (isArray(plugins)) {
1429
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1430
+ }
1431
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1115
1432
  }
1116
- return _createProxyChain(plugins, itemCtx);
1433
+ context.processNext = _processNext;
1434
+ context.createNew = _createNew;
1435
+ return context;
1117
1436
  }
1118
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1119
- var plugins = srcPlugins;
1120
- var add = false;
1121
- if (startAt && srcPlugins) {
1122
- plugins = [];
1123
- arrForEach(srcPlugins, function (thePlugin) {
1124
- if (add || thePlugin === startAt) {
1125
- add = true;
1126
- plugins.push(thePlugin);
1437
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1438
+ var config = core.config || {};
1439
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1440
+ var context = internalContext.ctx;
1441
+ function _processNext(unloadState) {
1442
+ var nextPlugin = internalContext._next();
1443
+ nextPlugin && nextPlugin.unload(context, unloadState);
1444
+ return !nextPlugin;
1445
+ }
1446
+ function _createNew(plugins, startAt) {
1447
+ if (plugins === void 0) { plugins = null; }
1448
+ if (isArray(plugins)) {
1449
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1450
+ }
1451
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1452
+ }
1453
+ context.processNext = _processNext;
1454
+ context.createNew = _createNew;
1455
+ return context;
1456
+ }
1457
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1458
+ var config = core.config || {};
1459
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1460
+ var context = internalContext.ctx;
1461
+ function _processNext(updateState) {
1462
+ return context.iterate(function (plugin) {
1463
+ if (isFunction(plugin.update)) {
1464
+ plugin.update(context, updateState);
1127
1465
  }
1128
1466
  });
1129
1467
  }
1130
- if (startAt && !add) {
1131
- if (!plugins) {
1132
- plugins = [];
1468
+ function _createNew(plugins, startAt) {
1469
+ if (plugins === void 0) { plugins = null; }
1470
+ if (isArray(plugins)) {
1471
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1133
1472
  }
1134
- plugins.push(startAt);
1473
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1135
1474
  }
1136
- return _createProxyChain(plugins, itemCtx);
1475
+ context.processNext = _processNext;
1476
+ context.createNew = _createNew;
1477
+ return context;
1137
1478
  }
1138
- var ProcessTelemetryContext = /** @class */ (function () {
1139
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1140
- var _self = this;
1141
- var _nextProxy = null;
1142
- if (startAt !== null) {
1143
- if (plugins && isFunction(plugins.getPlugin)) {
1144
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1479
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1480
+ var firstProxy = null;
1481
+ var add = startAt ? false : true;
1482
+ if (isArray(plugins) && plugins.length > 0) {
1483
+ var lastProxy_1 = null;
1484
+ arrForEach(plugins, function (thePlugin) {
1485
+ if (!add && startAt === thePlugin) {
1486
+ add = true;
1145
1487
  }
1146
- else {
1147
- if (startAt) {
1148
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1488
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1489
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1490
+ if (!firstProxy) {
1491
+ firstProxy = newProxy;
1149
1492
  }
1150
- else if (isUndefined(startAt)) {
1151
- _nextProxy = _createProxyChain(plugins, _self);
1493
+ if (lastProxy_1) {
1494
+ lastProxy_1._setNext(newProxy);
1152
1495
  }
1496
+ lastProxy_1 = newProxy;
1153
1497
  }
1498
+ });
1499
+ }
1500
+ if (startAt && !firstProxy) {
1501
+ return createTelemetryProxyChain([startAt], config, core);
1502
+ }
1503
+ return firstProxy;
1504
+ }
1505
+ function createTelemetryPluginProxy(plugin, config, core) {
1506
+ var nextProxy = null;
1507
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1508
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1509
+ var chainId;
1510
+ if (plugin) {
1511
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1512
+ }
1513
+ else {
1514
+ chainId = "Unknown-0-" + _chainId++;
1515
+ }
1516
+ var proxyChain = {
1517
+ getPlugin: function () {
1518
+ return plugin;
1519
+ },
1520
+ getNext: function () {
1521
+ return nextProxy;
1522
+ },
1523
+ processTelemetry: _processTelemetry,
1524
+ unload: _unloadPlugin,
1525
+ update: _updatePlugin,
1526
+ _id: chainId,
1527
+ _setNext: function (nextPlugin) {
1528
+ nextProxy = nextPlugin;
1154
1529
  }
1155
- _self.core = function () {
1156
- return core;
1157
- };
1158
- _self.diagLog = function () {
1159
- return safeGetLogger(core, config);
1160
- };
1161
- _self.getCfg = function () {
1162
- return config;
1163
- };
1164
- _self.getExtCfg = function (identifier, defaultValue) {
1165
- if (defaultValue === void 0) { defaultValue = {}; }
1166
- var theConfig;
1167
- if (config) {
1168
- var extConfig = config.extensionConfig;
1169
- if (extConfig && identifier) {
1170
- theConfig = extConfig[identifier];
1530
+ };
1531
+ function _getTelCtx() {
1532
+ var itemCtx;
1533
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1534
+ itemCtx = plugin[strGetTelCtx]();
1535
+ }
1536
+ if (!itemCtx) {
1537
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1538
+ }
1539
+ return itemCtx;
1540
+ }
1541
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1542
+ var hasRun = false;
1543
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1544
+ var hasRunContext = itemCtx[strHasRunFlags];
1545
+ if (!hasRunContext) {
1546
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1547
+ }
1548
+ itemCtx.setNext(nextProxy);
1549
+ if (plugin) {
1550
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1551
+ hasRunContext[chainId] = true;
1552
+ try {
1553
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1554
+ if (nextId) {
1555
+ hasRunContext[nextId] = false;
1556
+ }
1557
+ hasRun = processPluginFn(itemCtx);
1558
+ }
1559
+ catch (error) {
1560
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1561
+ if (hasNextRun) {
1562
+ hasRun = true;
1563
+ }
1564
+ if (!nextProxy || !hasNextRun) {
1565
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1566
+ }
1567
+ }
1568
+ }, details, isAsync);
1569
+ }
1570
+ return hasRun;
1571
+ }
1572
+ function _processTelemetry(env, itemCtx) {
1573
+ itemCtx = itemCtx || _getTelCtx();
1574
+ function _callProcessTelemetry(itemCtx) {
1575
+ if (!plugin || !hasProcessTelemetry) {
1576
+ return false;
1577
+ }
1578
+ var pluginState = _getPluginState(plugin);
1579
+ if (pluginState.teardown || pluginState[strDisabled]) {
1580
+ return false;
1581
+ }
1582
+ if (hasSetNext) {
1583
+ plugin.setNextPlugin(nextProxy);
1584
+ }
1585
+ plugin.processTelemetry(env, itemCtx);
1586
+ return true;
1587
+ }
1588
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1589
+ itemCtx.processNext(env);
1590
+ }
1591
+ }
1592
+ function _unloadPlugin(unloadCtx, unloadState) {
1593
+ function _callTeardown() {
1594
+ var hasRun = false;
1595
+ if (plugin) {
1596
+ var pluginState = _getPluginState(plugin);
1597
+ var pluginCore = plugin[strCore] || pluginState.core;
1598
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1599
+ pluginState[strCore] = null;
1600
+ pluginState[strTeardown] = true;
1601
+ pluginState[strIsInitialized] = false;
1602
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1603
+ hasRun = true;
1604
+ }
1605
+ }
1606
+ }
1607
+ return hasRun;
1608
+ }
1609
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1610
+ unloadCtx.processNext(unloadState);
1611
+ }
1612
+ }
1613
+ function _updatePlugin(updateCtx, updateState) {
1614
+ function _callUpdate() {
1615
+ var hasRun = false;
1616
+ if (plugin) {
1617
+ var pluginState = _getPluginState(plugin);
1618
+ var pluginCore = plugin[strCore] || pluginState.core;
1619
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1620
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1621
+ hasRun = true;
1622
+ }
1623
+ }
1624
+ }
1625
+ return hasRun;
1626
+ }
1627
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1628
+ updateCtx.processNext(updateState);
1629
+ }
1630
+ }
1631
+ return objFreeze(proxyChain);
1632
+ }
1633
+
1634
+ var strExtensionConfig = "extensionConfig";
1635
+
1636
+ function createUnloadHandlerContainer() {
1637
+ var handlers = [];
1638
+ function _addHandler(handler) {
1639
+ if (handler) {
1640
+ handlers.push(handler);
1641
+ }
1642
+ }
1643
+ function _runHandlers(unloadCtx, unloadState) {
1644
+ arrForEach(handlers, function (handler) {
1645
+ try {
1646
+ handler(unloadCtx, unloadState);
1647
+ }
1648
+ catch (e) {
1649
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1650
+ }
1651
+ });
1652
+ handlers = [];
1653
+ }
1654
+ return {
1655
+ add: _addHandler,
1656
+ run: _runHandlers
1657
+ };
1658
+ }
1659
+
1660
+ var strGetPlugin = "getPlugin";
1661
+ var BaseTelemetryPlugin = /** @class */ (function () {
1662
+ function BaseTelemetryPlugin() {
1663
+ var _self = this;
1664
+ var _isinitialized;
1665
+ var _rootCtx;
1666
+ var _nextPlugin;
1667
+ var _unloadHandlerContainer;
1668
+ var _hooks;
1669
+ _initDefaults();
1670
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1671
+ _self.initialize = function (config, core, extensions, pluginChain) {
1672
+ _setDefaults(config, core, pluginChain);
1673
+ _isinitialized = true;
1674
+ };
1675
+ _self.teardown = function (unloadCtx, unloadState) {
1676
+ var core = _self.core;
1677
+ if (!core || (unloadCtx && core !== unloadCtx.core())) {
1678
+ return;
1679
+ }
1680
+ var result;
1681
+ var unloadDone = false;
1682
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1683
+ var theUnloadState = unloadState || {
1684
+ reason: 0 ,
1685
+ isAsync: false
1686
+ };
1687
+ function _unloadCallback() {
1688
+ if (!unloadDone) {
1689
+ unloadDone = true;
1690
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1691
+ arrForEach(_hooks, function (fn) {
1692
+ fn.rm();
1693
+ });
1694
+ _hooks = [];
1695
+ if (result === true) {
1696
+ theUnloadCtx.processNext(theUnloadState);
1697
+ }
1698
+ _initDefaults();
1699
+ }
1700
+ }
1701
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1702
+ _unloadCallback();
1703
+ }
1704
+ else {
1705
+ result = true;
1706
+ }
1707
+ return result;
1708
+ };
1709
+ _self.update = function (updateCtx, updateState) {
1710
+ var core = _self.core;
1711
+ if (!core || (updateCtx && core !== updateCtx.core())) {
1712
+ return;
1713
+ }
1714
+ var result;
1715
+ var updateDone = false;
1716
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1717
+ var theUpdateState = updateState || {
1718
+ reason: 0
1719
+ };
1720
+ function _updateCallback() {
1721
+ if (!updateDone) {
1722
+ updateDone = true;
1723
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1724
+ }
1725
+ }
1726
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1727
+ _updateCallback();
1728
+ }
1729
+ else {
1730
+ result = true;
1731
+ }
1732
+ return result;
1733
+ };
1734
+ _self._addHook = function (hooks) {
1735
+ if (hooks) {
1736
+ if (isArray(hooks)) {
1737
+ _hooks = _hooks.concat(hooks);
1738
+ }
1739
+ else {
1740
+ _hooks.push(hooks);
1741
+ }
1171
1742
  }
1172
- }
1173
- return (theConfig ? theConfig : defaultValue);
1174
- };
1175
- _self.getConfig = function (identifier, field, defaultValue) {
1176
- if (defaultValue === void 0) { defaultValue = false; }
1177
- var theValue;
1178
- var extConfig = _self.getExtCfg(identifier, null);
1179
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1180
- theValue = extConfig[field];
1181
- }
1182
- else if (config && !isNullOrUndefined(config[field])) {
1183
- theValue = config[field];
1184
- }
1185
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1186
- };
1187
- _self.hasNext = function () {
1188
- return _nextProxy != null;
1189
- };
1190
- _self.getNext = function () {
1191
- return _nextProxy;
1192
- };
1193
- _self.setNext = function (nextPlugin) {
1194
- _nextProxy = nextPlugin;
1195
- };
1196
- _self.processNext = function (env) {
1197
- var nextPlugin = _nextProxy;
1198
- if (nextPlugin) {
1199
- _nextProxy = nextPlugin.getNext();
1200
- nextPlugin.processTelemetry(env, _self);
1201
- }
1202
- };
1203
- _self.createNew = function (plugins, startAt) {
1204
- if (plugins === void 0) { plugins = null; }
1205
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1206
- };
1207
- }
1208
- return ProcessTelemetryContext;
1209
- }());
1210
-
1211
- var strExtensionConfig = "extensionConfig";
1212
-
1213
- var strGetPlugin = "getPlugin";
1214
- var BaseTelemetryPlugin = /** @class */ (function () {
1215
- function BaseTelemetryPlugin() {
1216
- var _self = this;
1217
- var _isinitialized = false;
1218
- var _rootCtx = null;
1219
- var _nextPlugin = null;
1220
- _self.core = null;
1743
+ };
1744
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1745
+ });
1221
1746
  _self.diagLog = function (itemCtx) {
1222
- return _self._getTelCtx(itemCtx).diagLog();
1747
+ return _getTelCtx(itemCtx).diagLog();
1223
1748
  };
1224
- _self.isInitialized = function () {
1749
+ _self[strIsInitialized] = function () {
1225
1750
  return _isinitialized;
1226
1751
  };
1227
1752
  _self.setInitialized = function (isInitialized) {
1228
1753
  _isinitialized = isInitialized;
1229
1754
  };
1230
- _self.setNextPlugin = function (next) {
1755
+ _self[strSetNextPlugin] = function (next) {
1231
1756
  _nextPlugin = next;
1232
1757
  };
1233
1758
  _self.processNext = function (env, itemCtx) {
@@ -1238,11 +1763,12 @@
1238
1763
  _nextPlugin.processTelemetry(env, null);
1239
1764
  }
1240
1765
  };
1241
- _self._getTelCtx = function (currentCtx) {
1766
+ _self._getTelCtx = _getTelCtx;
1767
+ function _getTelCtx(currentCtx) {
1242
1768
  if (currentCtx === void 0) { currentCtx = null; }
1243
1769
  var itemCtx = currentCtx;
1244
1770
  if (!itemCtx) {
1245
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1771
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1246
1772
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1247
1773
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1248
1774
  }
@@ -1251,8 +1777,8 @@
1251
1777
  }
1252
1778
  }
1253
1779
  return itemCtx;
1254
- };
1255
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1780
+ }
1781
+ function _setDefaults(config, core, pluginChain) {
1256
1782
  if (config) {
1257
1783
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1258
1784
  }
@@ -1264,93 +1790,300 @@
1264
1790
  nextPlugin = _nextPlugin[strGetPlugin]();
1265
1791
  }
1266
1792
  _self.core = core;
1267
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1268
- _isinitialized = true;
1269
- };
1793
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1794
+ }
1795
+ function _initDefaults() {
1796
+ _isinitialized = false;
1797
+ _self.core = null;
1798
+ _rootCtx = null;
1799
+ _nextPlugin = null;
1800
+ _hooks = [];
1801
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1802
+ }
1270
1803
  }
1271
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1272
- this._baseTelInit(config, core, extensions, pluginChain);
1273
- };
1274
1804
  return BaseTelemetryPlugin;
1275
1805
  }());
1276
1806
 
1807
+ var strOnPrefix = "on";
1808
+ var strAttachEvent = "attachEvent";
1809
+ var strAddEventHelper = "addEventListener";
1810
+ var strDetachEvent = "detachEvent";
1811
+ var strRemoveEventListener = "removeEventListener";
1812
+ var strEvents = "events";
1277
1813
  var strVisibilityChangeEvt = "visibilitychange";
1278
1814
  var strPageHide = "pagehide";
1279
1815
  var strPageShow = "pageshow";
1280
- function addEventHandler(eventName, callback) {
1816
+ var strUnload = "unload";
1817
+ var strBeforeUnload = "beforeunload";
1818
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
1819
+ var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
1820
+ var rRemoveEmptyNs = /\.[\.]+/g;
1821
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1822
+ var _guid = 1;
1823
+ var elmNodeData = createElmNodeData("events");
1824
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1825
+ function _normalizeNamespace(name) {
1826
+ if (name && name.replace) {
1827
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1828
+ }
1829
+ return name;
1830
+ }
1831
+ function _getEvtNamespace(eventName, evtNamespace) {
1832
+ if (evtNamespace) {
1833
+ var theNamespace_1 = "";
1834
+ if (isArray(evtNamespace)) {
1835
+ theNamespace_1 = "";
1836
+ arrForEach(evtNamespace, function (name) {
1837
+ name = _normalizeNamespace(name);
1838
+ if (name) {
1839
+ if (name[0] !== ".") {
1840
+ name = "." + name;
1841
+ }
1842
+ theNamespace_1 += name;
1843
+ }
1844
+ });
1845
+ }
1846
+ else {
1847
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1848
+ }
1849
+ if (theNamespace_1) {
1850
+ if (theNamespace_1[0] !== ".") {
1851
+ theNamespace_1 = "." + theNamespace_1;
1852
+ }
1853
+ eventName = (eventName || "") + theNamespace_1;
1854
+ }
1855
+ }
1856
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1857
+ return {
1858
+ type: parsedEvent[1],
1859
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1860
+ };
1861
+ }
1862
+ function _getRegisteredEvents(target, evtName, addDefault) {
1863
+ if (addDefault === void 0) { addDefault = true; }
1864
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1865
+ var registeredEvents = aiEvts[evtName];
1866
+ if (!registeredEvents) {
1867
+ registeredEvents = aiEvts[evtName] = [];
1868
+ }
1869
+ return registeredEvents;
1870
+ }
1871
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
1872
+ if (obj && evtName && evtName.type) {
1873
+ if (obj[strRemoveEventListener]) {
1874
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1875
+ }
1876
+ else if (obj[strDetachEvent]) {
1877
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1878
+ }
1879
+ }
1880
+ }
1881
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1882
+ var result = false;
1883
+ if (obj && evtName && evtName.type && handlerRef) {
1884
+ if (obj[strAddEventHelper]) {
1885
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1886
+ result = true;
1887
+ }
1888
+ else if (obj[strAttachEvent]) {
1889
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1890
+ result = true;
1891
+ }
1892
+ }
1893
+ return result;
1894
+ }
1895
+ function _doUnregister(target, events, evtName, unRegFn) {
1896
+ var idx = events.length;
1897
+ while (idx--) {
1898
+ var theEvent = events[idx];
1899
+ if (theEvent) {
1900
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1901
+ if (!unRegFn || unRegFn(theEvent)) {
1902
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1903
+ events.splice(idx, 1);
1904
+ }
1905
+ }
1906
+ }
1907
+ }
1908
+ }
1909
+ function _unregisterEvents(target, evtName, unRegFn) {
1910
+ if (evtName.type) {
1911
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1912
+ }
1913
+ else {
1914
+ var eventCache = elmNodeData.get(target, strEvents, {});
1915
+ objForEachKey(eventCache, function (evtType, events) {
1916
+ _doUnregister(target, events, evtName, unRegFn);
1917
+ });
1918
+ if (objKeys(eventCache).length === 0) {
1919
+ elmNodeData.kill(target, strEvents);
1920
+ }
1921
+ }
1922
+ }
1923
+ function mergeEvtNamespace(theNamespace, namespaces) {
1924
+ var newNamespaces;
1925
+ if (namespaces) {
1926
+ if (isArray(namespaces)) {
1927
+ newNamespaces = [theNamespace].concat(namespaces);
1928
+ }
1929
+ else {
1930
+ newNamespaces = [theNamespace, namespaces];
1931
+ }
1932
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1933
+ }
1934
+ else {
1935
+ newNamespaces = theNamespace;
1936
+ }
1937
+ return newNamespaces;
1938
+ }
1939
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1940
+ if (useCapture === void 0) { useCapture = false; }
1941
+ var result = false;
1942
+ if (target) {
1943
+ try {
1944
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1945
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1946
+ if (result && elmNodeData.accept(target)) {
1947
+ var registeredEvent = {
1948
+ guid: _guid++,
1949
+ evtName: evtName,
1950
+ handler: handlerRef,
1951
+ capture: useCapture
1952
+ };
1953
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1954
+ }
1955
+ }
1956
+ catch (e) {
1957
+ }
1958
+ }
1959
+ return result;
1960
+ }
1961
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
1962
+ if (useCapture === void 0) { useCapture = false; }
1963
+ if (target) {
1964
+ try {
1965
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
1966
+ var found_1 = false;
1967
+ _unregisterEvents(target, evtName_1, function (regEvent) {
1968
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
1969
+ found_1 = true;
1970
+ return true;
1971
+ }
1972
+ return false;
1973
+ });
1974
+ if (!found_1) {
1975
+ _doDetach(target, evtName_1, handlerRef, useCapture);
1976
+ }
1977
+ }
1978
+ catch (e) {
1979
+ }
1980
+ }
1981
+ }
1982
+ function addEventHandler(eventName, callback, evtNamespace) {
1281
1983
  var result = false;
1282
1984
  var w = getWindow();
1283
1985
  if (w) {
1284
- result = attachEvent(w, eventName, callback);
1285
- result = attachEvent(w["body"], eventName, callback) || result;
1986
+ result = eventOn(w, eventName, callback, evtNamespace);
1987
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1286
1988
  }
1287
1989
  var doc = getDocument();
1288
1990
  if (doc) {
1289
- result = attachEvent(doc, eventName, callback) || result;
1991
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
1290
1992
  }
1291
1993
  return result;
1292
1994
  }
1293
- function addEventListeners(events, listener, excludeEvents) {
1995
+ function removeEventHandler(eventName, callback, evtNamespace) {
1996
+ var w = getWindow();
1997
+ if (w) {
1998
+ eventOff(w, eventName, callback, evtNamespace);
1999
+ eventOff(w["body"], eventName, callback, evtNamespace);
2000
+ }
2001
+ var doc = getDocument();
2002
+ if (doc) {
2003
+ eventOff(doc, eventName, callback, evtNamespace);
2004
+ }
2005
+ }
2006
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
1294
2007
  var added = false;
1295
- if (listener && events && isArray(events)) {
1296
- var excluded_1 = [];
2008
+ if (listener && events && events.length > 0) {
1297
2009
  arrForEach(events, function (name) {
1298
- if (isString(name)) {
2010
+ if (name) {
1299
2011
  if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
1300
- added = addEventHandler(name, listener) || added;
1301
- }
1302
- else {
1303
- excluded_1.push(name);
2012
+ added = addEventHandler(name, listener, evtNamespace) || added;
1304
2013
  }
1305
2014
  }
1306
2015
  });
1307
- if (!added && excluded_1.length > 0) {
1308
- added = addEventListeners(excluded_1, listener);
2016
+ }
2017
+ return added;
2018
+ }
2019
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
2020
+ var added = false;
2021
+ if (listener && events && isArray(events)) {
2022
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
2023
+ if (!added && excludeEvents && excludeEvents.length > 0) {
2024
+ added = _addEventListeners(events, listener, null, evtNamespace);
1309
2025
  }
1310
2026
  }
1311
2027
  return added;
1312
2028
  }
1313
- function addPageUnloadEventListener(listener, excludeEvents) {
1314
- return addEventListeners(["beforeunload", "unload", "pagehide"], listener, excludeEvents);
2029
+ function removeEventListeners(events, listener, evtNamespace) {
2030
+ if (events && isArray(events)) {
2031
+ arrForEach(events, function (name) {
2032
+ if (name) {
2033
+ removeEventHandler(name, listener, evtNamespace);
2034
+ }
2035
+ });
2036
+ }
2037
+ }
2038
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
2039
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
2040
+ }
2041
+ function removePageUnloadEventListener(listener, evtNamespace) {
2042
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
1315
2043
  }
1316
- function addPageHideEventListener(listener, excludeEvents) {
2044
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
1317
2045
  function _handlePageVisibility(evt) {
1318
2046
  var doc = getDocument();
1319
2047
  if (listener && doc && doc.visibilityState === "hidden") {
1320
2048
  listener(evt);
1321
2049
  }
1322
2050
  }
1323
- var pageUnloadAdded = false;
1324
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
1325
- pageUnloadAdded = addEventHandler(strPageHide, listener);
1326
- }
2051
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2052
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
1327
2053
  if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1328
- pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
2054
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
1329
2055
  }
1330
2056
  if (!pageUnloadAdded && excludeEvents) {
1331
- pageUnloadAdded = addPageHideEventListener(listener);
2057
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
1332
2058
  }
1333
2059
  return pageUnloadAdded;
1334
2060
  }
1335
- function addPageShowEventListener(listener, excludeEvents) {
2061
+ function removePageHideEventListener(listener, evtNamespace) {
2062
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2063
+ removeEventListeners([strPageHide], listener, newNamespaces);
2064
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2065
+ }
2066
+ function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
1336
2067
  function _handlePageVisibility(evt) {
1337
2068
  var doc = getDocument();
1338
2069
  if (listener && doc && doc.visibilityState === "visible") {
1339
2070
  listener(evt);
1340
2071
  }
1341
2072
  }
1342
- var pageShowAdded = false;
1343
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageShow) === -1) {
1344
- pageShowAdded = addEventHandler(strPageShow, listener);
1345
- }
1346
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1347
- pageShowAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageShowAdded;
1348
- }
2073
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2074
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
2075
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
1349
2076
  if (!pageShowAdded && excludeEvents) {
1350
- pageShowAdded = addPageShowEventListener(listener);
2077
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
1351
2078
  }
1352
2079
  return pageShowAdded;
1353
2080
  }
2081
+ function removePageShowEventListener(listener, evtNamespace) {
2082
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2083
+ removeEventListeners([strPageShow], listener, newNamespaces);
2084
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2085
+ }
2086
+
1354
2087
  function perfNow() {
1355
2088
  var perf = getPerformance();
1356
2089
  if (perf && perf.now) {
@@ -1359,56 +2092,20 @@
1359
2092
  return dateNow();
1360
2093
  }
1361
2094
 
1362
- var ValueKind = {
1363
- NotSet: 0,
1364
- Pii_DistinguishedName: 1,
1365
- Pii_GenericData: 2,
1366
- Pii_IPV4Address: 3,
1367
- Pii_IPv6Address: 4,
1368
- Pii_MailSubject: 5,
1369
- Pii_PhoneNumber: 6,
1370
- Pii_QueryString: 7,
1371
- Pii_SipAddress: 8,
1372
- Pii_SmtpAddress: 9,
1373
- Pii_Identity: 10,
1374
- Pii_Uri: 11,
1375
- Pii_Fqdn: 12,
1376
- Pii_IPV4AddressLegacy: 13,
1377
- CustomerContent_GenericContent: 32
1378
- };
1379
- var EventLatency = {
1380
- Normal: 1 ,
1381
- CostDeferred: 2 ,
1382
- RealTime: 3 ,
1383
- Immediate: 4
1384
- };
1385
- var EventPropertyType = {
1386
- Unspecified: 0,
1387
- String: 1,
1388
- Int32: 2,
1389
- UInt32: 3,
1390
- Int64: 4,
1391
- UInt64: 5,
1392
- Double: 6,
1393
- Bool: 7,
1394
- Guid: 8,
1395
- DateTime: 9
1396
- };
1397
- 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 });
1398
-
1399
2095
  var _a$1;
1400
- var Version = '3.1.9';
2096
+ var Version = '3.2.0';
1401
2097
  var FullVersionString = "1DS-Web-JS-" + Version;
1402
2098
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
1403
2099
  var strWithCredentials = "withCredentials";
2100
+ var strTimeout = "timeout";
1404
2101
  var _fieldTypeEventPropMap = (_a$1 = {},
1405
- _a$1[0 ] = EventPropertyType.Unspecified,
1406
- _a$1[2 ] = EventPropertyType.Double,
1407
- _a$1[1 ] = EventPropertyType.String,
1408
- _a$1[3 ] = EventPropertyType.Bool,
1409
- _a$1[4096 | 2 ] = EventPropertyType.Double,
1410
- _a$1[4096 | 1 ] = EventPropertyType.String,
1411
- _a$1[4096 | 3 ] = EventPropertyType.Bool,
2102
+ _a$1[0 ] = 0 ,
2103
+ _a$1[2 ] = 6 ,
2104
+ _a$1[1 ] = 1 ,
2105
+ _a$1[3 ] = 7 ,
2106
+ _a$1[4096 | 2 ] = 6 ,
2107
+ _a$1[4096 | 1 ] = 1 ,
2108
+ _a$1[4096 | 3 ] = 7 ,
1412
2109
  _a$1);
1413
2110
  Boolean(getDocument());
1414
2111
  var isWindowObjectAvailable = Boolean(getWindow());
@@ -1475,7 +2172,7 @@
1475
2172
  if (encodedTypeValue !== -1 && propType !== -1) {
1476
2173
  encodedTypeValue |= propType;
1477
2174
  }
1478
- else if (propType === EventPropertyType.Double) {
2175
+ else if (propType === 6 ) {
1479
2176
  encodedTypeValue = propType;
1480
2177
  }
1481
2178
  }
@@ -1521,7 +2218,7 @@
1521
2218
  }
1522
2219
  var getTime = perfNow;
1523
2220
  function isValueKind(value) {
1524
- if (value === ValueKind.NotSet || ((value > ValueKind.NotSet && value <= ValueKind.Pii_IPV4AddressLegacy) || value === ValueKind.CustomerContent_GenericContent)) {
2221
+ if (value === 0 || ((value > 0 && value <= 13 ) || value === 32 )) {
1525
2222
  return true;
1526
2223
  }
1527
2224
  return false;
@@ -1572,7 +2269,7 @@
1572
2269
  function isChromium() {
1573
2270
  return !!getGlobalInst("chrome");
1574
2271
  }
1575
- function openXhr(method, urlString, withCredentials, disabled, isSync) {
2272
+ function openXhr(method, urlString, withCredentials, disabled, isSync, timeout) {
1576
2273
  if (disabled === void 0) { disabled = false; }
1577
2274
  if (isSync === void 0) { isSync = false; }
1578
2275
  function _wrapSetXhrProp(xhr, prop, value) {
@@ -1593,6 +2290,9 @@
1593
2290
  if (withCredentials) {
1594
2291
  _wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
1595
2292
  }
2293
+ if (!isSync && timeout) {
2294
+ _wrapSetXhrProp(xhr, strTimeout, timeout);
2295
+ }
1596
2296
  return xhr;
1597
2297
  }
1598
2298
 
@@ -1600,42 +2300,83 @@
1600
2300
  var NRT_PROFILE = "NEAR_REAL_TIME";
1601
2301
  var BE_PROFILE = "BEST_EFFORT";
1602
2302
 
2303
+ var Method = "POST";
2304
+ var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2305
+ var strDropped = "drop";
2306
+ var strSending = "send";
2307
+ var strRequeue = "requeue";
2308
+ var strResponseFail = "rspFail";
2309
+ var strOther = "oth";
2310
+ var defaultCacheControl = "no-cache, no-store";
2311
+ var defaultContentType = "application/x-json-stream";
2312
+ var strCacheControl = "cache-control";
2313
+ var strContentTypeHeader = "content-type";
2314
+ var strKillTokensHeader = "kill-tokens";
2315
+ var strKillDurationHeader = "kill-duration";
2316
+ var strKillDurationSecondsHeader = "kill-duration-seconds";
2317
+ var strTimeDeltaHeader = "time-delta-millis";
2318
+ var strClientVersion = "client-version";
2319
+ var strClientId = "client-id";
2320
+ var strTimeDeltaToApply = "time-delta-to-apply-millis";
2321
+ var strUploadTime = "upload-time";
2322
+ var strApiKey = "apikey";
2323
+ var strMsaDeviceTicket = "AuthMsaDeviceTicket";
2324
+ var strAuthXToken = "AuthXToken";
2325
+ var strNoResponseBody = "NoResponseBody";
2326
+ var strMsfpc = "msfpc";
2327
+
2328
+ function _getEventMsfpc(theEvent) {
2329
+ var intWeb = ((theEvent.ext || {})["intweb"]);
2330
+ if (intWeb && isValueAssigned(intWeb[strMsfpc])) {
2331
+ return intWeb[strMsfpc];
2332
+ }
2333
+ return null;
2334
+ }
2335
+ function _getMsfpc(theEvents) {
2336
+ var msfpc = null;
2337
+ for (var lp = 0; msfpc === null && lp < theEvents.length; lp++) {
2338
+ msfpc = _getEventMsfpc(theEvents[lp]);
2339
+ }
2340
+ return msfpc;
2341
+ }
1603
2342
  var EventBatch = /** @class */ (function () {
1604
2343
  function EventBatch(iKey, addEvents) {
1605
2344
  var events = addEvents ? [].concat(addEvents) : [];
1606
2345
  var _self = this;
2346
+ var _msfpc = _getMsfpc(events);
1607
2347
  _self.iKey = function () {
1608
2348
  return iKey;
1609
2349
  };
2350
+ _self.Msfpc = function () {
2351
+ return _msfpc || "";
2352
+ };
1610
2353
  _self.count = function () {
1611
2354
  return events.length;
1612
2355
  };
1613
2356
  _self.events = function () {
1614
2357
  return events;
1615
2358
  };
1616
- _self.addEvents = function (theEvents, append) {
1617
- if (append === void 0) { append = true; }
1618
- if (theEvents && theEvents.length > 0) {
1619
- if (append) {
1620
- events = events.concat(theEvents);
1621
- }
1622
- else {
1623
- events = theEvents.concat(events);
2359
+ _self.addEvent = function (theEvent) {
2360
+ if (theEvent) {
2361
+ events.push(theEvent);
2362
+ if (!_msfpc) {
2363
+ _msfpc = _getEventMsfpc(theEvent);
1624
2364
  }
1625
- return theEvents.length;
2365
+ return true;
1626
2366
  }
1627
- return 0;
2367
+ return false;
1628
2368
  };
1629
2369
  _self.split = function (fromEvent, numEvents) {
1630
- var newBatch = new EventBatch(iKey);
2370
+ var theEvents;
1631
2371
  if (fromEvent < events.length) {
1632
2372
  var cnt = events.length - fromEvent;
1633
2373
  if (!isNullOrUndefined(numEvents)) {
1634
2374
  cnt = numEvents < cnt ? numEvents : cnt;
1635
2375
  }
1636
- newBatch.addEvents(events.splice(fromEvent, cnt), true);
2376
+ theEvents = events.splice(fromEvent, cnt);
2377
+ _msfpc = _getMsfpc(events);
1637
2378
  }
1638
- return newBatch;
2379
+ return new EventBatch(iKey, theEvents);
1639
2380
  };
1640
2381
  }
1641
2382
  EventBatch.create = function (iKey, theEvents) {
@@ -1893,25 +2634,19 @@
1893
2634
  var RandomizationUpperThreshold = 1.2;
1894
2635
  var BaseBackoff = 3000;
1895
2636
  var MaxBackoff = 600000;
1896
- var RetryPolicy = /** @class */ (function () {
1897
- function RetryPolicy() {
1898
- }
1899
- RetryPolicy.shouldRetryForStatus = function (httpStatusCode) {
1900
- return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
1901
- || (httpStatusCode == 501)
1902
- || (httpStatusCode == 505));
1903
- };
1904
- RetryPolicy.getMillisToBackoffForRetry = function (retriesSoFar) {
1905
- var waitDuration = 0;
1906
- var minBackoff = BaseBackoff * RandomizationLowerThreshold;
1907
- var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
1908
- var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
1909
- waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
1910
- return Math.min(waitDuration, MaxBackoff);
1911
- };
1912
- return RetryPolicy;
1913
- }());
1914
- var RetryPolicy$1 = RetryPolicy;
2637
+ function retryPolicyShouldRetryForStatus(httpStatusCode) {
2638
+ return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
2639
+ || (httpStatusCode == 501)
2640
+ || (httpStatusCode == 505));
2641
+ }
2642
+ function retryPolicyGetMillisToBackoffForRetry(retriesSoFar) {
2643
+ var waitDuration = 0;
2644
+ var minBackoff = BaseBackoff * RandomizationLowerThreshold;
2645
+ var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
2646
+ var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
2647
+ waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
2648
+ return Math.min(waitDuration, MaxBackoff);
2649
+ }
1915
2650
 
1916
2651
  var SecToMsMultiplier = 1000;
1917
2652
  var KillSwitch = /** @class */ (function () {
@@ -2005,21 +2740,8 @@
2005
2740
  var EVTClockSkewManager = ClockSkewManager;
2006
2741
 
2007
2742
  var _a;
2008
- var Method = "POST";
2009
- var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2010
- var strDropped = "drop";
2011
- var strSending = "send";
2012
- var strRequeue = "requeue";
2013
- var strResponseFail = "rspFail";
2014
- var strOther = "oth";
2015
- var defaultCacheControl = "no-cache, no-store";
2016
- var defaultContentType = "application/x-json-stream";
2017
- var strCacheControl = "cache-control";
2018
- var strContentTypeHeader = "content-type";
2019
- var strKillTokensHeader = "kill-tokens";
2020
- var strKillDurationHeader = "kill-duration";
2021
- var strKillDurationSecondsHeader = "kill-duration-seconds";
2022
- var strTimeDeltaHeader = "time-delta-millis";
2743
+ var strSendAttempt = "sendAttempt";
2744
+ var _noResponseQs = "&" + strNoResponseBody + "=true";
2023
2745
  var _eventActionMap = (_a = {},
2024
2746
  _a[1 ] = strRequeue,
2025
2747
  _a[100 ] = strRequeue,
@@ -2027,6 +2749,21 @@
2027
2749
  _a[8004 ] = strDropped,
2028
2750
  _a[8003 ] = strDropped,
2029
2751
  _a);
2752
+ var _collectorQsHeaders = {};
2753
+ var _collectorHeaderToQs = {};
2754
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
2755
+ _collectorQsHeaders[qsName] = headerName;
2756
+ if (allowQs !== false) {
2757
+ _collectorHeaderToQs[headerName] = qsName;
2758
+ }
2759
+ }
2760
+ _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);
2761
+ _addCollectorHeaderQsMapping(strClientVersion, strClientVersion);
2762
+ _addCollectorHeaderQsMapping(strClientId, "Client-Id");
2763
+ _addCollectorHeaderQsMapping(strApiKey, strApiKey);
2764
+ _addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
2765
+ _addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
2766
+ _addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
2030
2767
  function _getResponseText(xhr) {
2031
2768
  try {
2032
2769
  return xhr.responseText;
@@ -2053,11 +2790,21 @@
2053
2790
  }
2054
2791
  return hasHeader;
2055
2792
  }
2793
+ function _addRequestDetails(details, name, value, useHeaders) {
2794
+ if (name && value && value.length > 0) {
2795
+ if (useHeaders && _collectorQsHeaders[name]) {
2796
+ details.hdrs[_collectorQsHeaders[name]] = value;
2797
+ details.useHdrs = true;
2798
+ }
2799
+ else {
2800
+ details.url += "&" + name + "=" + value;
2801
+ }
2802
+ }
2803
+ }
2056
2804
  var HttpManager = /** @class */ (function () {
2057
- function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {
2805
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
2058
2806
  this._responseHandlers = [];
2059
- var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType + "&client-id=NO_AUTH&client-version="
2060
- + FullVersionString;
2807
+ var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
2061
2808
  var _killSwitch = new EVTKillSwitch();
2062
2809
  var _paused = false;
2063
2810
  var _clockSkewManager = new EVTClockSkewManager();
@@ -2074,6 +2821,9 @@
2074
2821
  var _enableEventTimings = false;
2075
2822
  var _cookieMgr;
2076
2823
  var _isUnloading = false;
2824
+ var _useHeaders = false;
2825
+ var _xhrTimeout;
2826
+ var _disableXhrSync;
2077
2827
  dynamicProto(HttpManager, this, function (_self) {
2078
2828
  var _sendCredentials = true;
2079
2829
  _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
@@ -2082,6 +2832,7 @@
2082
2832
  channelConfig = {};
2083
2833
  }
2084
2834
  _urlString = endpointUrl + _urlString;
2835
+ _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
2085
2836
  _core = core;
2086
2837
  _cookieMgr = core.getCookieMgr();
2087
2838
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -2092,9 +2843,13 @@
2092
2843
  if (!isUndefined(channelConfig.enableCompoundKey)) {
2093
2844
  enableCompoundKey = !!channelConfig.enableCompoundKey;
2094
2845
  }
2846
+ _xhrTimeout = channelConfig.xhrTimeout;
2847
+ _disableXhrSync = channelConfig.disableXhrSync;
2095
2848
  _useBeacons = !isReactNative();
2096
2849
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
2097
2850
  var syncHttpInterface = httpInterface;
2851
+ var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
2852
+ var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
2098
2853
  if (!httpInterface) {
2099
2854
  _customHttpInterface = false;
2100
2855
  var location_1 = getLocation();
@@ -2126,8 +2881,8 @@
2126
2881
  _sendInterfaces = (_a = {},
2127
2882
  _a[0 ] = httpInterface,
2128
2883
  _a[1 ] = syncHttpInterface || _getSenderInterface([1 , 2 , 3 ], true),
2129
- _a[2 ] = _getSenderInterface([3 , 2 , 1 ], true) || syncHttpInterface,
2130
- _a[3 ] = _getSenderInterface([2 , 3 , 1 ], true) || syncHttpInterface,
2884
+ _a[2 ] = beaconHttpInterface || _getSenderInterface([3 , 2 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
2885
+ _a[3 ] = fetchSyncHttpInterface || _getSenderInterface([2 , 3 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
2131
2886
  _a);
2132
2887
  };
2133
2888
  function _getSenderInterface(transports, syncSupport) {
@@ -2167,6 +2922,9 @@
2167
2922
  function _xdrSendPost(payload, oncomplete, sync) {
2168
2923
  var xdr = new XDomainRequest();
2169
2924
  xdr.open(Method, payload.urlString);
2925
+ if (payload.timeout) {
2926
+ xdr.timeout = payload.timeout;
2927
+ }
2170
2928
  xdr.onload = function () {
2171
2929
  var response = _getResponseText(xdr);
2172
2930
  _doOnComplete(oncomplete, 200, {}, response);
@@ -2190,6 +2948,9 @@
2190
2948
  }
2191
2949
  function _fetchSendPost(payload, oncomplete, sync) {
2192
2950
  var _a;
2951
+ var theUrl = payload.urlString;
2952
+ var ignoreResponse = false;
2953
+ var responseHandled = false;
2193
2954
  var requestInit = (_a = {
2194
2955
  body: payload.data,
2195
2956
  method: Method
@@ -2198,6 +2959,10 @@
2198
2959
  _a);
2199
2960
  if (sync) {
2200
2961
  requestInit.keepalive = true;
2962
+ if (payload._sendReason === 2 ) {
2963
+ ignoreResponse = true;
2964
+ theUrl += _noResponseQs;
2965
+ }
2201
2966
  }
2202
2967
  if (_sendCredentials) {
2203
2968
  requestInit.credentials = "include";
@@ -2205,7 +2970,7 @@
2205
2970
  if (payload.headers && objKeys(payload.headers).length > 0) {
2206
2971
  requestInit.headers = payload.headers;
2207
2972
  }
2208
- fetch(payload.urlString, requestInit).then(function (response) {
2973
+ fetch(theUrl, requestInit).then(function (response) {
2209
2974
  var headerMap = {};
2210
2975
  var responseText = "";
2211
2976
  if (response.headers) {
@@ -2218,13 +2983,32 @@
2218
2983
  responseText = text;
2219
2984
  });
2220
2985
  }
2221
- _doOnComplete(oncomplete, response.status, headerMap, responseText);
2222
- _handleCollectorResponse(responseText);
2986
+ if (!responseHandled) {
2987
+ responseHandled = true;
2988
+ _doOnComplete(oncomplete, response.status, headerMap, responseText);
2989
+ _handleCollectorResponse(responseText);
2990
+ }
2223
2991
  })["catch"](function (error) {
2224
- _doOnComplete(oncomplete, 0, {});
2992
+ if (!responseHandled) {
2993
+ responseHandled = true;
2994
+ _doOnComplete(oncomplete, 0, {});
2995
+ }
2225
2996
  });
2997
+ if (ignoreResponse && !responseHandled) {
2998
+ responseHandled = true;
2999
+ _doOnComplete(oncomplete, 200, {});
3000
+ }
3001
+ if (!responseHandled && payload.timeout > 0) {
3002
+ _postManager._setTimeoutOverride(function () {
3003
+ if (!responseHandled) {
3004
+ responseHandled = true;
3005
+ _doOnComplete(oncomplete, 500, {});
3006
+ }
3007
+ }, payload.timeout);
3008
+ }
2226
3009
  }
2227
3010
  function _xhrSendPost(payload, oncomplete, sync) {
3011
+ var theUrl = payload.urlString;
2228
3012
  function _appendHeader(theHeaders, xhr, name) {
2229
3013
  if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
2230
3014
  var value = xhr.getResponseHeader(name);
@@ -2249,45 +3033,49 @@
2249
3033
  function xhrComplete(xhr, responseTxt) {
2250
3034
  _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
2251
3035
  }
2252
- var xhRequest = openXhr(Method, payload.urlString, _sendCredentials, true, sync);
3036
+ if (sync && payload.disableXhrSync) {
3037
+ sync = false;
3038
+ }
3039
+ var xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);
2253
3040
  objForEachKey(payload.headers, function (name, value) {
2254
- xhRequest.setRequestHeader(name, value);
3041
+ xhrRequest.setRequestHeader(name, value);
2255
3042
  });
2256
- xhRequest.onload = function () {
2257
- var response = _getResponseText(xhRequest);
2258
- xhrComplete(xhRequest, response);
3043
+ xhrRequest.onload = function () {
3044
+ var response = _getResponseText(xhrRequest);
3045
+ xhrComplete(xhrRequest, response);
2259
3046
  _handleCollectorResponse(response);
2260
3047
  };
2261
- xhRequest.onerror = function () {
2262
- xhrComplete(xhRequest);
3048
+ xhrRequest.onerror = function () {
3049
+ xhrComplete(xhrRequest);
2263
3050
  };
2264
- xhRequest.ontimeout = function () {
2265
- xhrComplete(xhRequest);
3051
+ xhrRequest.ontimeout = function () {
3052
+ xhrComplete(xhrRequest);
2266
3053
  };
2267
- xhRequest.send(payload.data);
3054
+ xhrRequest.send(payload.data);
2268
3055
  }
2269
3056
  function _doOnComplete(oncomplete, status, headers, response) {
2270
3057
  try {
2271
3058
  oncomplete(status, headers, response);
2272
3059
  }
2273
3060
  catch (e) {
2274
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));
3061
+ _throwInternal(_postManager.diagLog(), 2 , 518 , dumpObj(e));
2275
3062
  }
2276
3063
  }
2277
3064
  function _beaconSendPost(payload, oncomplete, sync) {
2278
3065
  var internalPayloadData = payload;
2279
3066
  var status = 200;
2280
3067
  var thePayload = internalPayloadData._thePayload;
3068
+ var theUrl = payload.urlString + _noResponseQs;
2281
3069
  try {
2282
3070
  var nav_1 = getNavigator();
2283
- if (!nav_1.sendBeacon(payload.urlString, payload.data)) {
3071
+ if (!nav_1.sendBeacon(theUrl, payload.data)) {
2284
3072
  if (thePayload) {
2285
3073
  var droppedBatches_1 = [];
2286
3074
  arrForEach(thePayload.batches, function (theBatch) {
2287
3075
  if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
2288
3076
  var theEvents = theBatch.events();
2289
3077
  for (var lp = 0; lp < theEvents.length; lp++) {
2290
- if (!nav_1.sendBeacon(payload.urlString, _serializer.getEventBlob(theEvents[lp]))) {
3078
+ if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
2291
3079
  droppedBatches_1.push(theBatch.split(lp));
2292
3080
  break;
2293
3081
  }
@@ -2305,7 +3093,7 @@
2305
3093
  }
2306
3094
  }
2307
3095
  catch (ex) {
2308
- _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + ex);
3096
+ _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
2309
3097
  status = 0;
2310
3098
  }
2311
3099
  finally {
@@ -2469,11 +3257,32 @@
2469
3257
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
2470
3258
  }
2471
3259
  catch (ex) {
2472
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + dumpObj(ex));
3260
+ _throwInternal(_postManager.diagLog(), 2 , 48 , "Unexpected Exception sending batch: " + dumpObj(ex));
2473
3261
  }
2474
3262
  }
2475
- function _buildQueryString(thePayload) {
2476
- var urlString = _urlString;
3263
+ function _buildRequestDetails(thePayload, useHeaders) {
3264
+ var requestDetails = {
3265
+ url: _urlString,
3266
+ hdrs: {},
3267
+ useHdrs: false
3268
+ };
3269
+ if (!useHeaders) {
3270
+ objForEachKey(_headers, function (name, value) {
3271
+ if (_collectorHeaderToQs[name]) {
3272
+ _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
3273
+ }
3274
+ else {
3275
+ requestDetails.hdrs[name] = value;
3276
+ requestDetails.useHdrs = true;
3277
+ }
3278
+ });
3279
+ }
3280
+ else {
3281
+ requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
3282
+ requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
3283
+ }
3284
+ _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
3285
+ _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
2477
3286
  var apiQsKeys = "";
2478
3287
  arrForEach(thePayload.apiKeys, function (apiKey) {
2479
3288
  if (apiQsKeys.length > 0) {
@@ -2481,27 +3290,25 @@
2481
3290
  }
2482
3291
  apiQsKeys += apiKey;
2483
3292
  });
2484
- if (apiQsKeys.length > 0) {
2485
- urlString += "&apikey=" + apiQsKeys;
2486
- }
2487
- urlString += "&upload-time=" + dateNow().toString();
3293
+ _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);
3294
+ _addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);
2488
3295
  var msfpc = _getMsfpc(thePayload);
2489
3296
  if (isValueAssigned(msfpc)) {
2490
- urlString = urlString + "&ext.intweb.msfpc=" + msfpc;
3297
+ requestDetails.url += "&ext.intweb.msfpc=" + msfpc;
2491
3298
  }
2492
3299
  if (_clockSkewManager.shouldAddClockSkewHeaders()) {
2493
- urlString += "&time-delta-to-apply-millis=" + _clockSkewManager.getClockSkewHeaderValue();
3300
+ _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);
2494
3301
  }
2495
3302
  if (_core.getWParam) {
2496
3303
  var wParam = _core.getWParam();
2497
3304
  if (wParam >= 0) {
2498
- urlString += "&w=" + wParam;
3305
+ requestDetails.url += "&w=" + wParam;
2499
3306
  }
2500
3307
  }
2501
3308
  for (var i = 0; i < _queryStringParameters.length; i++) {
2502
- urlString += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
3309
+ requestDetails.url += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
2503
3310
  }
2504
- return urlString;
3311
+ return requestDetails;
2505
3312
  }
2506
3313
  function _canUseSendBeaconApi() {
2507
3314
  return !_customHttpInterface && _useBeacons && isBeaconsSupported();
@@ -2512,9 +3319,18 @@
2512
3319
  }
2513
3320
  function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {
2514
3321
  if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {
2515
- var urlString_1 = _buildQueryString(thePayload);
3322
+ var useSendHook_1 = !!_self.sendHook;
3323
+ var sendInterface_1 = _sendInterfaces[thePayload.sendType];
3324
+ if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 ) {
3325
+ sendInterface_1 = _sendInterfaces[2 ] || _sendInterfaces[3 ] || sendInterface_1;
3326
+ }
3327
+ var useHeaders_1 = _useHeaders;
3328
+ if (thePayload.isBeacon || sendInterface_1._transport === 3 ) {
3329
+ useHeaders_1 = false;
3330
+ }
3331
+ var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
3332
+ useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
2516
3333
  var sendEventStart_1 = getTime();
2517
- var strSendAttempt_1 = "sendAttempt";
2518
3334
  doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
2519
3335
  for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
2520
3336
  var theBatch = thePayload.batches[batchLp];
@@ -2527,30 +3343,31 @@
2527
3343
  _setTimingValue(timings, "serializationStart", serializationStart);
2528
3344
  _setTimingValue(timings, "serializationCompleted", serializationCompleted);
2529
3345
  }
2530
- telemetryItem[strSendAttempt_1] > 0 ? telemetryItem[strSendAttempt_1]++ : telemetryItem[strSendAttempt_1] = 1;
3346
+ telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
2531
3347
  }
2532
3348
  }
2533
3349
  _sendBatchesNotification(thePayload.batches, (1000 + (sendReason || 0 )), thePayload.sendType, true);
2534
3350
  var orgPayloadData = {
2535
3351
  data: thePayload.payloadBlob,
2536
- urlString: urlString_1,
2537
- headers: extend({}, _headers),
3352
+ urlString: requestDetails_1.url,
3353
+ headers: requestDetails_1.hdrs,
2538
3354
  _thePayload: thePayload,
2539
- _sendReason: sendReason
3355
+ _sendReason: sendReason,
3356
+ timeout: _xhrTimeout
2540
3357
  };
2541
- if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
2542
- orgPayloadData.headers[strCacheControl] = defaultCacheControl;
3358
+ if (!isUndefined(_disableXhrSync)) {
3359
+ orgPayloadData.disableXhrSync = !!_disableXhrSync;
2543
3360
  }
2544
- if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
2545
- orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
3361
+ if (useHeaders_1) {
3362
+ if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
3363
+ orgPayloadData.headers[strCacheControl] = defaultCacheControl;
3364
+ }
3365
+ if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
3366
+ orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
3367
+ }
2546
3368
  }
2547
3369
  var sender = null;
2548
- var useSendHook = !!_self.sendHook;
2549
- var sendInterface = _sendInterfaces[thePayload.sendType];
2550
- if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 ) {
2551
- sendInterface = _sendInterfaces[2 ] || _sendInterfaces[3 ] || sendInterface;
2552
- }
2553
- if (sendInterface) {
3370
+ if (sendInterface_1) {
2554
3371
  sender = function (payload) {
2555
3372
  _clockSkewManager.firstRequestSent();
2556
3373
  var onComplete = function (status, headers) {
@@ -2558,7 +3375,7 @@
2558
3375
  };
2559
3376
  var isSync = thePayload.isTeardown || thePayload.isSync;
2560
3377
  try {
2561
- sendInterface.sendPOST(payload, onComplete, isSync);
3378
+ sendInterface_1.sendPOST(payload, onComplete, isSync);
2562
3379
  if (_self.sendListener) {
2563
3380
  _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);
2564
3381
  }
@@ -2574,11 +3391,13 @@
2574
3391
  if (thePayload.sendType === 0 ) {
2575
3392
  _outstandingRequests++;
2576
3393
  }
2577
- if (useSendHook && !thePayload.isBeacon && sendInterface._transport !== 3 ) {
3394
+ if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 ) {
2578
3395
  var hookData_1 = {
2579
3396
  data: orgPayloadData.data,
2580
3397
  urlString: orgPayloadData.urlString,
2581
- headers: extend({}, orgPayloadData.headers)
3398
+ headers: extend({}, orgPayloadData.headers),
3399
+ timeout: orgPayloadData.timeout,
3400
+ disableXhrSync: orgPayloadData.disableXhrSync
2582
3401
  };
2583
3402
  var senderCalled_1 = false;
2584
3403
  doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
@@ -2643,11 +3462,11 @@
2643
3462
  });
2644
3463
  });
2645
3464
  }
2646
- if (status == 200) {
3465
+ if (status == 200 || status == 204) {
2647
3466
  reason = 200 ;
2648
3467
  return;
2649
3468
  }
2650
- if (!RetryPolicy$1.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
3469
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
2651
3470
  shouldRetry = false;
2652
3471
  }
2653
3472
  reason = 9000 + (status % 1000);
@@ -2656,17 +3475,20 @@
2656
3475
  reason = 100 ;
2657
3476
  var retryCount_1 = thePayload.retryCnt;
2658
3477
  if (thePayload.sendType === 0 ) {
2659
- if (retryCount_1 < maxRetries) {
3478
+ if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
2660
3479
  isRetrying = true;
2661
3480
  _doAction(function () {
2662
3481
  if (thePayload.sendType === 0 ) {
2663
3482
  _outstandingRequests--;
2664
3483
  }
2665
3484
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
2666
- }, _isUnloading, RetryPolicy$1.getMillisToBackoffForRetry(retryCount_1));
3485
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
2667
3486
  }
2668
3487
  else {
2669
3488
  backOffTrans = true;
3489
+ if (_isUnloading) {
3490
+ reason = 8001 ;
3491
+ }
2670
3492
  }
2671
3493
  }
2672
3494
  }
@@ -2741,12 +3563,9 @@
2741
3563
  }
2742
3564
  function _getMsfpc(thePayload) {
2743
3565
  for (var lp = 0; lp < thePayload.batches.length; lp++) {
2744
- var batchEvents = thePayload.batches[lp].events();
2745
- for (var evtLp = 0; evtLp < batchEvents.length; evtLp++) {
2746
- var intWeb = ((batchEvents[evtLp].ext || {})["intweb"] || {});
2747
- if (isValueAssigned(intWeb["msfpc"])) {
2748
- return encodeURIComponent(intWeb["msfpc"]);
2749
- }
3566
+ var msfpc = thePayload.batches[lp].Msfpc();
3567
+ if (msfpc) {
3568
+ return encodeURIComponent(msfpc);
2750
3569
  }
2751
3570
  }
2752
3571
  return "";
@@ -2759,13 +3578,13 @@
2759
3578
  responseHandlers[i](responseText);
2760
3579
  }
2761
3580
  catch (e) {
2762
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
3581
+ _throwInternal(_postManager.diagLog(), 1 , 519 , "Response handler failed: " + e);
2763
3582
  }
2764
3583
  }
2765
3584
  if (responseText) {
2766
3585
  var response = JSON.parse(responseText);
2767
- if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult.msfpc)) {
2768
- _cookieMgr.set("MSFPC", response.webResult.msfpc, 365 * 86400);
3586
+ if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {
3587
+ _cookieMgr.set("MSFPC", response.webResult[strMsfpc], 365 * 86400);
2769
3588
  }
2770
3589
  }
2771
3590
  }
@@ -2783,7 +3602,7 @@
2783
3602
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
2784
3603
  }
2785
3604
  catch (e) {
2786
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, "send request notification failed: " + e);
3605
+ _throwInternal(_postManager.diagLog(), 1 , 74 , "send request notification failed: " + e);
2787
3606
  }
2788
3607
  }, sendSync || isSyncRequest_1, 0);
2789
3608
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
@@ -2810,25 +3629,28 @@
2810
3629
  }
2811
3630
  return HttpManager;
2812
3631
  }());
2813
- var HttpManager$1 = HttpManager;
2814
3632
 
2815
3633
  var FlushCheckTimer = 0.250;
2816
3634
  var MaxNumberEventPerBatch = 500;
2817
3635
  var EventsDroppedAtOneTime = 20;
2818
3636
  var MaxSendAttempts = 6;
3637
+ var MaxSyncUnloadSendAttempts = 2;
2819
3638
  var MaxBackoffCount = 4;
2820
3639
  var globalContext = isWindowObjectAvailable ? window : undefined;
2821
3640
  var MaxConnections = 2;
2822
- var MaxRetries = 1;
3641
+ var MaxRequestRetriesBeforeBackoff = 1;
2823
3642
  var strEventsDiscarded = "eventsDiscarded";
2824
3643
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
3644
+ var strMaxEventRetryAttempts = "maxEventRetryAttempts";
3645
+ var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
3646
+ var strAddUnloadCb = "addUnloadCb";
2825
3647
  var PostChannel = /** @class */ (function (_super) {
2826
3648
  __extendsFn(PostChannel, _super);
2827
3649
  function PostChannel() {
2828
3650
  var _this = _super.call(this) || this;
2829
3651
  _this.identifier = "PostChannel";
2830
3652
  _this.priority = 1011;
2831
- _this.version = '3.1.9';
3653
+ _this.version = '3.2.0';
2832
3654
  var _config;
2833
3655
  var _isTeardownCalled = false;
2834
3656
  var _flushCallbackQueue = [];
@@ -2853,18 +3675,12 @@
2853
3675
  var _delayedBatchReason;
2854
3676
  var _optimizeObject = true;
2855
3677
  var _isPageUnloadTriggered = false;
3678
+ var _disableXhrSync = false;
3679
+ var _maxEventSendAttempts = MaxSendAttempts;
3680
+ var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
3681
+ var _evtNamespace;
2856
3682
  dynamicProto(PostChannel, _this, function (_self, _base) {
2857
- _initializeProfiles();
2858
- _clearQueues();
2859
- _setAutoLimits();
2860
- _httpManager = new HttpManager$1(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
2861
- requeue: _requeueEvents,
2862
- send: _sendingEvent,
2863
- sent: _eventsSentEvent,
2864
- drop: _eventsDropped,
2865
- rspFail: _eventsResponseFail,
2866
- oth: _otherEvent
2867
- });
3683
+ _initDefaults();
2868
3684
  _self["_getDbgPlgTargets"] = function () {
2869
3685
  return [_httpManager];
2870
3686
  };
@@ -2872,58 +3688,53 @@
2872
3688
  doPerf(core, function () { return "PostChannel:initialize"; }, function () {
2873
3689
  var extendedCore = core;
2874
3690
  _base.initialize(coreConfig, core, extensions);
2875
- _self.setInitialized(false);
2876
- var ctx = _self._getTelCtx();
2877
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
2878
- _config = ctx.getExtCfg(_self.identifier);
2879
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
2880
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
2881
- _optimizeObject = !_config.disableOptimizeObj && isChromium();
2882
- var existingGetWParamMethod = extendedCore.getWParam;
2883
- extendedCore.getWParam = function () {
2884
- var wparam = 0;
2885
- if (_config.ignoreMc1Ms0CookieProcessing) {
2886
- wparam = wparam | 2;
2887
- }
2888
- return wparam | existingGetWParamMethod();
2889
- };
2890
- if (_config.eventsLimitInMem > 0) {
2891
- _queueSizeLimit = _config.eventsLimitInMem;
2892
- }
2893
- if (_config.immediateEventLimit > 0) {
2894
- _immediateQueueSizeLimit = _config.immediateEventLimit;
2895
- }
2896
- if (_config.autoFlushEventsLimit > 0) {
2897
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
2898
- }
2899
- _setAutoLimits();
2900
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
2901
- _xhrOverride = _config.httpXHROverride;
2902
- }
2903
- if (isValueAssigned(coreConfig.anonCookieName)) {
2904
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
2905
- }
2906
- _httpManager.sendHook = _config.payloadPreprocessor;
2907
- _httpManager.sendListener = _config.payloadListener;
2908
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
2909
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
2910
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
2911
- function _handleUnloadEvents(evt) {
2912
- var theEvt = evt || getWindow().event;
2913
- if (theEvt.type !== "beforeunload") {
2914
- _isPageUnloadTriggered = true;
2915
- _httpManager.setUnloading(_isPageUnloadTriggered);
3691
+ try {
3692
+ var hasAddUnloadCb = !!core[strAddUnloadCb];
3693
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
3694
+ var ctx = _self._getTelCtx();
3695
+ coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
3696
+ _config = ctx.getExtCfg(_self.identifier);
3697
+ _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
3698
+ _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
3699
+ _optimizeObject = !_config.disableOptimizeObj && isChromium();
3700
+ _hookWParam(extendedCore);
3701
+ if (_config.eventsLimitInMem > 0) {
3702
+ _queueSizeLimit = _config.eventsLimitInMem;
2916
3703
  }
2917
- _releaseAllQueues(2 , 2 );
3704
+ if (_config.immediateEventLimit > 0) {
3705
+ _immediateQueueSizeLimit = _config.immediateEventLimit;
3706
+ }
3707
+ if (_config.autoFlushEventsLimit > 0) {
3708
+ _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3709
+ }
3710
+ _disableXhrSync = _config.disableXhrSync;
3711
+ if (isNumber(_config[strMaxEventRetryAttempts])) {
3712
+ _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
3713
+ }
3714
+ if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
3715
+ _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
3716
+ }
3717
+ _setAutoLimits();
3718
+ if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
3719
+ _xhrOverride = _config.httpXHROverride;
3720
+ }
3721
+ if (isValueAssigned(coreConfig.anonCookieName)) {
3722
+ _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
3723
+ }
3724
+ _httpManager.sendHook = _config.payloadPreprocessor;
3725
+ _httpManager.sendListener = _config.payloadListener;
3726
+ var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
3727
+ _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
3728
+ _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
3729
+ var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
3730
+ addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
3731
+ addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
3732
+ addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
3733
+ }
3734
+ catch (e) {
3735
+ _self.setInitialized(false);
3736
+ throw e;
2918
3737
  }
2919
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
2920
- addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
2921
- addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
2922
- addPageShowEventListener(function (evt) {
2923
- _isPageUnloadTriggered = false;
2924
- _httpManager.setUnloading(_isPageUnloadTriggered);
2925
- }, coreConfig.disablePageShowEvents);
2926
- _self.setInitialized(true);
2927
3738
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
2928
3739
  };
2929
3740
  _self.processTelemetry = function (ev, itemCtx) {
@@ -2952,12 +3763,43 @@
2952
3763
  }
2953
3764
  _self.processNext(event, itemCtx);
2954
3765
  };
3766
+ _self._doTeardown = function (unloadCtx, unloadState) {
3767
+ _releaseAllQueues(2 , 2 );
3768
+ _isTeardownCalled = true;
3769
+ _httpManager.teardown();
3770
+ removePageUnloadEventListener(null, _evtNamespace);
3771
+ removePageHideEventListener(null, _evtNamespace);
3772
+ removePageShowEventListener(null, _evtNamespace);
3773
+ _initDefaults();
3774
+ };
3775
+ function _hookWParam(extendedCore) {
3776
+ var existingGetWParamMethod = extendedCore.getWParam;
3777
+ extendedCore.getWParam = function () {
3778
+ var wparam = 0;
3779
+ if (_config.ignoreMc1Ms0CookieProcessing) {
3780
+ wparam = wparam | 2;
3781
+ }
3782
+ return wparam | existingGetWParamMethod();
3783
+ };
3784
+ }
3785
+ function _handleUnloadEvents(evt) {
3786
+ var theEvt = evt || getWindow().event;
3787
+ if (theEvt.type !== "beforeunload") {
3788
+ _isPageUnloadTriggered = true;
3789
+ _httpManager.setUnloading(_isPageUnloadTriggered);
3790
+ }
3791
+ _releaseAllQueues(2 , 2 );
3792
+ }
3793
+ function _handleShowEvents(evt) {
3794
+ _isPageUnloadTriggered = false;
3795
+ _httpManager.setUnloading(_isPageUnloadTriggered);
3796
+ }
2955
3797
  function _addEventToQueues(event, append) {
2956
3798
  if (!event.sendAttempt) {
2957
3799
  event.sendAttempt = 0;
2958
3800
  }
2959
3801
  if (!event.latency) {
2960
- event.latency = EventLatency.Normal;
3802
+ event.latency = 1 ;
2961
3803
  }
2962
3804
  if (event.ext && event.ext["trace"]) {
2963
3805
  delete (event.ext["trace"]);
@@ -2976,7 +3818,7 @@
2976
3818
  }
2977
3819
  if (event.sync) {
2978
3820
  if (_currentBackoffCount || _paused) {
2979
- event.latency = EventLatency.RealTime;
3821
+ event.latency = 3 ;
2980
3822
  event.sync = false;
2981
3823
  }
2982
3824
  else {
@@ -2992,7 +3834,7 @@
2992
3834
  var evtLatency = event.latency;
2993
3835
  var queueSize = _queueSize;
2994
3836
  var queueLimit = _queueSizeLimit;
2995
- if (evtLatency === EventLatency.Immediate) {
3837
+ if (evtLatency === 4 ) {
2996
3838
  queueSize = _immediateQueueSize;
2997
3839
  queueLimit = _immediateQueueSizeLimit;
2998
3840
  }
@@ -3001,10 +3843,10 @@
3001
3843
  eventDropped = !_addEventToProperQueue(event, append);
3002
3844
  }
3003
3845
  else {
3004
- var dropLatency = EventLatency.Normal;
3846
+ var dropLatency = 1 ;
3005
3847
  var dropNumber = EventsDroppedAtOneTime;
3006
- if (evtLatency === EventLatency.Immediate) {
3007
- dropLatency = EventLatency.Immediate;
3848
+ if (evtLatency === 4 ) {
3849
+ dropLatency = 4 ;
3008
3850
  dropNumber = 1;
3009
3851
  }
3010
3852
  eventDropped = true;
@@ -3022,7 +3864,7 @@
3022
3864
  _setAutoLimits();
3023
3865
  var doFlush = _queueSize > eventLimit;
3024
3866
  if (!doFlush && _autoFlushBatchLimit > 0) {
3025
- for (var latency = EventLatency.Normal; !doFlush && latency <= EventLatency.RealTime; latency++) {
3867
+ for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
3026
3868
  var batchQueue = _batchQueues[latency];
3027
3869
  if (batchQueue && batchQueue.batches) {
3028
3870
  arrForEach(batchQueue.batches, function (theBatch) {
@@ -3035,11 +3877,6 @@
3035
3877
  }
3036
3878
  _performAutoFlush(true, doFlush);
3037
3879
  };
3038
- _self.teardown = function () {
3039
- _releaseAllQueues(2 , 2 );
3040
- _isTeardownCalled = true;
3041
- _httpManager.teardown();
3042
- };
3043
3880
  _self.pause = function () {
3044
3881
  _clearScheduledTimer();
3045
3882
  _paused = true;
@@ -3081,7 +3918,7 @@
3081
3918
  _clearScheduledTimer();
3082
3919
  sendReason = sendReason || 1 ;
3083
3920
  if (async) {
3084
- _queueBatches(EventLatency.Normal, 0 , sendReason);
3921
+ _queueBatches(1 , 0 , sendReason);
3085
3922
  _resetQueueCounts();
3086
3923
  if (_flushCallbackTimerId == null) {
3087
3924
  _flushCallbackTimerId = _createTimer(function () {
@@ -3093,7 +3930,7 @@
3093
3930
  }
3094
3931
  }
3095
3932
  else {
3096
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 1 , sendReason);
3933
+ _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
3097
3934
  if (callback !== null && callback !== undefined) {
3098
3935
  callback();
3099
3936
  }
@@ -3101,7 +3938,7 @@
3101
3938
  }
3102
3939
  };
3103
3940
  _self.setMsaAuthTicket = function (ticket) {
3104
- _httpManager.addHeader("AuthMsaDeviceTicket", ticket);
3941
+ _httpManager.addHeader(strMsaDeviceTicket, ticket);
3105
3942
  };
3106
3943
  _self.hasEvents = _hasEvents;
3107
3944
  _self._setTransmitProfile = function (profileName) {
@@ -3128,7 +3965,7 @@
3128
3965
  if (immediateTimeOut >= 0) {
3129
3966
  _immediateTimerId = _createTimer(function () {
3130
3967
  _immediateTimerId = null;
3131
- _sendEventsForLatencyAndAbove(EventLatency.Immediate, 0 , 1 );
3968
+ _sendEventsForLatencyAndAbove(4 , 0 , 1 );
3132
3969
  _scheduleTimer();
3133
3970
  }, immediateTimeOut);
3134
3971
  }
@@ -3138,7 +3975,7 @@
3138
3975
  if (_hasEvents()) {
3139
3976
  _scheduledTimerId = _createTimer(function () {
3140
3977
  _scheduledTimerId = null;
3141
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? EventLatency.RealTime : EventLatency.Normal, 0 , 1 );
3978
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
3142
3979
  _timerCount++;
3143
3980
  _timerCount %= 2;
3144
3981
  _scheduleTimer();
@@ -3163,13 +4000,53 @@
3163
4000
  _scheduleTimer();
3164
4001
  }
3165
4002
  };
4003
+ function _initDefaults() {
4004
+ _config = null;
4005
+ _isTeardownCalled = false;
4006
+ _flushCallbackQueue = [];
4007
+ _flushCallbackTimerId = null;
4008
+ _paused = false;
4009
+ _immediateQueueSize = 0;
4010
+ _immediateQueueSizeLimit = 500;
4011
+ _queueSize = 0;
4012
+ _queueSizeLimit = 10000;
4013
+ _profiles = {};
4014
+ _currentProfile = RT_PROFILE;
4015
+ _scheduledTimerId = null;
4016
+ _immediateTimerId = null;
4017
+ _currentBackoffCount = 0;
4018
+ _timerCount = 0;
4019
+ _xhrOverride = null;
4020
+ _batchQueues = {};
4021
+ _autoFlushEventsLimit = undefined;
4022
+ _autoFlushBatchLimit = 0;
4023
+ _delayedBatchSendLatency = -1;
4024
+ _delayedBatchReason = null;
4025
+ _optimizeObject = true;
4026
+ _isPageUnloadTriggered = false;
4027
+ _disableXhrSync = false;
4028
+ _maxEventSendAttempts = MaxSendAttempts;
4029
+ _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
4030
+ _evtNamespace = null;
4031
+ _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
4032
+ requeue: _requeueEvents,
4033
+ send: _sendingEvent,
4034
+ sent: _eventsSentEvent,
4035
+ drop: _eventsDropped,
4036
+ rspFail: _eventsResponseFail,
4037
+ oth: _otherEvent
4038
+ });
4039
+ _initializeProfiles();
4040
+ _clearQueues();
4041
+ _setAutoLimits();
4042
+ }
3166
4043
  function _createTimer(theTimerFunc, timeOut) {
3167
4044
  if (timeOut === 0 && _currentBackoffCount) {
3168
4045
  timeOut = 1;
3169
4046
  }
3170
4047
  var timerMultiplier = 1000;
3171
4048
  if (_currentBackoffCount) {
3172
- timerMultiplier = RetryPolicy$1.getMillisToBackoffForRetry(_currentBackoffCount - 1);
4049
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
3173
4050
  }
3174
4051
  return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
3175
4052
  }
@@ -3187,23 +4064,23 @@
3187
4064
  _flushCallbackTimerId = null;
3188
4065
  }
3189
4066
  if (!_paused) {
3190
- _sendEventsForLatencyAndAbove(EventLatency.Normal, sendType, sendReason);
4067
+ _sendEventsForLatencyAndAbove(1 , sendType, sendReason);
3191
4068
  }
3192
4069
  }
3193
4070
  function _clearQueues() {
3194
- _batchQueues[EventLatency.Immediate] = {
4071
+ _batchQueues[4 ] = {
3195
4072
  batches: [],
3196
4073
  iKeyMap: {}
3197
4074
  };
3198
- _batchQueues[EventLatency.RealTime] = {
4075
+ _batchQueues[3 ] = {
3199
4076
  batches: [],
3200
4077
  iKeyMap: {}
3201
4078
  };
3202
- _batchQueues[EventLatency.CostDeferred] = {
4079
+ _batchQueues[2 ] = {
3203
4080
  batches: [],
3204
4081
  iKeyMap: {}
3205
4082
  };
3206
- _batchQueues[EventLatency.Normal] = {
4083
+ _batchQueues[1 ] = {
3207
4084
  batches: [],
3208
4085
  iKeyMap: {}
3209
4086
  };
@@ -3211,7 +4088,7 @@
3211
4088
  function _getEventBatch(iKey, latency, create) {
3212
4089
  var batchQueue = _batchQueues[latency];
3213
4090
  if (!batchQueue) {
3214
- latency = EventLatency.Normal;
4091
+ latency = 1 ;
3215
4092
  batchQueue = _batchQueues[latency];
3216
4093
  }
3217
4094
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -3238,8 +4115,8 @@
3238
4115
  }
3239
4116
  var latency = event.latency;
3240
4117
  var eventBatch = _getEventBatch(event.iKey, latency, true);
3241
- if (eventBatch.addEvents([event], append)) {
3242
- if (latency !== EventLatency.Immediate) {
4118
+ if (eventBatch.addEvent(event)) {
4119
+ if (latency !== 4 ) {
3243
4120
  _queueSize++;
3244
4121
  if (append && event.sendAttempt === 0) {
3245
4122
  _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
@@ -3259,7 +4136,7 @@
3259
4136
  var droppedEvents = eventBatch.split(0, dropNumber);
3260
4137
  var droppedCount = droppedEvents.count();
3261
4138
  if (droppedCount > 0) {
3262
- if (currentLatency === EventLatency.Immediate) {
4139
+ if (currentLatency === 4 ) {
3263
4140
  _immediateQueueSize -= droppedCount;
3264
4141
  }
3265
4142
  else {
@@ -3281,7 +4158,7 @@
3281
4158
  var batchQueue = _batchQueues[latency];
3282
4159
  if (batchQueue && batchQueue.batches) {
3283
4160
  arrForEach(batchQueue.batches, function (theBatch) {
3284
- if (latency === EventLatency.Immediate) {
4161
+ if (latency === 4 ) {
3285
4162
  immediateQueue += theBatch.count();
3286
4163
  }
3287
4164
  else {
@@ -3290,7 +4167,7 @@
3290
4167
  });
3291
4168
  }
3292
4169
  };
3293
- for (var latency = EventLatency.Normal; latency <= EventLatency.Immediate; latency++) {
4170
+ for (var latency = 1 ; latency <= 4 ; latency++) {
3294
4171
  _loop_1(latency);
3295
4172
  }
3296
4173
  _queueSize = normalQueue;
@@ -3302,7 +4179,7 @@
3302
4179
  if (!isAsync || _httpManager.canSendRequest()) {
3303
4180
  doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
3304
4181
  var droppedEvents = [];
3305
- var latencyToProcess = EventLatency.Immediate;
4182
+ var latencyToProcess = 4 ;
3306
4183
  while (latencyToProcess >= latency) {
3307
4184
  var batchQueue = _batchQueues[latencyToProcess];
3308
4185
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -3313,7 +4190,7 @@
3313
4190
  else {
3314
4191
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
3315
4192
  }
3316
- if (latencyToProcess === EventLatency.Immediate) {
4193
+ if (latencyToProcess === 4 ) {
3317
4194
  _immediateQueueSize -= theBatch.count();
3318
4195
  }
3319
4196
  else {
@@ -3341,7 +4218,7 @@
3341
4218
  return eventsQueued;
3342
4219
  }
3343
4220
  function _flushImpl(callback, sendReason) {
3344
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 0 , sendReason);
4221
+ _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
3345
4222
  _waitForIdleManager(function () {
3346
4223
  if (callback) {
3347
4224
  callback();
@@ -3381,15 +4258,19 @@
3381
4258
  }
3382
4259
  function _requeueEvents(batches, reason) {
3383
4260
  var droppedEvents = [];
4261
+ var maxSendAttempts = _maxEventSendAttempts;
4262
+ if (_isPageUnloadTriggered) {
4263
+ maxSendAttempts = _maxUnloadEventSendAttempts;
4264
+ }
3384
4265
  arrForEach(batches, function (theBatch) {
3385
4266
  if (theBatch && theBatch.count() > 0) {
3386
4267
  arrForEach(theBatch.events(), function (theEvent) {
3387
4268
  if (theEvent) {
3388
4269
  if (theEvent.sync) {
3389
- theEvent.latency = EventLatency.Immediate;
4270
+ theEvent.latency = 4 ;
3390
4271
  theEvent.sync = false;
3391
4272
  }
3392
- if (theEvent.sendAttempt < MaxSendAttempts) {
4273
+ if (theEvent.sendAttempt < maxSendAttempts) {
3393
4274
  setProcessTelemetryTimings(theEvent, _self.identifier);
3394
4275
  _addEventToQueues(theEvent, false);
3395
4276
  }
@@ -3415,7 +4296,7 @@
3415
4296
  notifyFunc.apply(manager, theArgs);
3416
4297
  }
3417
4298
  catch (e) {
3418
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
4299
+ _throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
3419
4300
  }
3420
4301
  }
3421
4302
  }