@microsoft/applicationinsights-dependencies-js 2.7.5-nightly.2203-03 → 2.7.5

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Dependencies Plugin, 2.7.5-nightly.2203-03
2
+ * Application Insights JavaScript SDK - Dependencies Plugin, 2.7.5
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -75,9 +75,7 @@
75
75
  var __assignFn = ObjAssign || __objAssignFnImpl;
76
76
  var extendStaticsFn = function (d, b) {
77
77
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
78
- ({ __proto__: [] } instanceof Array && function (d, b) {
79
- d.__proto__ = b;
80
- }) ||
78
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
81
79
  function (d, b) {
82
80
  for (var p in b) {
83
81
  if (b[strShimHasOwnProperty](p)) {
@@ -92,14 +90,12 @@
92
90
  throwTypeError("Class extends value " + String(b) + " is not a constructor or null");
93
91
  }
94
92
  extendStaticsFn(d, b);
95
- function __() {
96
- this.constructor = d;
97
- }
93
+ function __() { this.constructor = d; }
98
94
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
99
95
  }
100
96
 
101
97
  /*!
102
- * Microsoft Dynamic Proto Utility, 1.1.4
98
+ * Microsoft Dynamic Proto Utility, 1.1.5
103
99
  * Copyright (c) Microsoft and contributors. All rights reserved.
104
100
  */
105
101
  var Constructor = 'constructor';
@@ -112,6 +108,7 @@
112
108
  var DynInstChkTag = '_dynInstChk';
113
109
  var DynAllowInstChkTag = DynInstChkTag;
114
110
  var DynProtoDefaultOptions = '_dfOpts';
111
+ var DynProtoPolyProto = "_dynProto";
115
112
  var UnknownValue = '_unknown_';
116
113
  var str__Proto$1 = "__proto__";
117
114
  var strUseBaseInst = 'useBaseInst';
@@ -133,8 +130,11 @@
133
130
  if (_objGetPrototypeOf$1) {
134
131
  return _objGetPrototypeOf$1(target);
135
132
  }
136
- var newProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
133
+ var newProto = target[DynProtoPolyProto] || target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
137
134
  if (newProto) {
135
+ if (!target[DynProtoPolyProto]) {
136
+ target[DynProtoPolyProto] = newProto;
137
+ }
138
138
  return newProto;
139
139
  }
140
140
  }
@@ -293,8 +293,9 @@
293
293
  visited.push(thisProto);
294
294
  thisProto = _getObjProto$1(thisProto);
295
295
  }
296
+ return false;
296
297
  }
297
- return false;
298
+ return true;
298
299
  }
299
300
  function _getObjName(target, unknownValue) {
300
301
  if (_hasOwnProperty(target, Prototype)) {
@@ -339,22 +340,106 @@
339
340
  };
340
341
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
341
342
 
342
- var strEmpty$1 = "";
343
- var strSetNextPlugin = "setNextPlugin";
344
- var strIsInitialized = "isInitialized";
345
- var strTeardown = "teardown";
346
- var strCore = "core";
347
- var strUpdate = "update";
348
- var strDisabled = "disabled";
349
- var strDoTeardown = "_doTeardown";
343
+ var LoggingSeverity;
344
+ (function (LoggingSeverity) {
345
+ LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
346
+ LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
347
+ })(LoggingSeverity || (LoggingSeverity = {}));
348
+ var _InternalMessageId = {
349
+ BrowserDoesNotSupportLocalStorage: 0,
350
+ BrowserCannotReadLocalStorage: 1,
351
+ BrowserCannotReadSessionStorage: 2,
352
+ BrowserCannotWriteLocalStorage: 3,
353
+ BrowserCannotWriteSessionStorage: 4,
354
+ BrowserFailedRemovalFromLocalStorage: 5,
355
+ BrowserFailedRemovalFromSessionStorage: 6,
356
+ CannotSendEmptyTelemetry: 7,
357
+ ClientPerformanceMathError: 8,
358
+ ErrorParsingAISessionCookie: 9,
359
+ ErrorPVCalc: 10,
360
+ ExceptionWhileLoggingError: 11,
361
+ FailedAddingTelemetryToBuffer: 12,
362
+ FailedMonitorAjaxAbort: 13,
363
+ FailedMonitorAjaxDur: 14,
364
+ FailedMonitorAjaxOpen: 15,
365
+ FailedMonitorAjaxRSC: 16,
366
+ FailedMonitorAjaxSend: 17,
367
+ FailedMonitorAjaxGetCorrelationHeader: 18,
368
+ FailedToAddHandlerForOnBeforeUnload: 19,
369
+ FailedToSendQueuedTelemetry: 20,
370
+ FailedToReportDataLoss: 21,
371
+ FlushFailed: 22,
372
+ MessageLimitPerPVExceeded: 23,
373
+ MissingRequiredFieldSpecification: 24,
374
+ NavigationTimingNotSupported: 25,
375
+ OnError: 26,
376
+ SessionRenewalDateIsZero: 27,
377
+ SenderNotInitialized: 28,
378
+ StartTrackEventFailed: 29,
379
+ StopTrackEventFailed: 30,
380
+ StartTrackFailed: 31,
381
+ StopTrackFailed: 32,
382
+ TelemetrySampledAndNotSent: 33,
383
+ TrackEventFailed: 34,
384
+ TrackExceptionFailed: 35,
385
+ TrackMetricFailed: 36,
386
+ TrackPVFailed: 37,
387
+ TrackPVFailedCalc: 38,
388
+ TrackTraceFailed: 39,
389
+ TransmissionFailed: 40,
390
+ FailedToSetStorageBuffer: 41,
391
+ FailedToRestoreStorageBuffer: 42,
392
+ InvalidBackendResponse: 43,
393
+ FailedToFixDepricatedValues: 44,
394
+ InvalidDurationValue: 45,
395
+ TelemetryEnvelopeInvalid: 46,
396
+ CreateEnvelopeError: 47,
397
+ CannotSerializeObject: 48,
398
+ CannotSerializeObjectNonSerializable: 49,
399
+ CircularReferenceDetected: 50,
400
+ ClearAuthContextFailed: 51,
401
+ ExceptionTruncated: 52,
402
+ IllegalCharsInName: 53,
403
+ ItemNotInArray: 54,
404
+ MaxAjaxPerPVExceeded: 55,
405
+ MessageTruncated: 56,
406
+ NameTooLong: 57,
407
+ SampleRateOutOfRange: 58,
408
+ SetAuthContextFailed: 59,
409
+ SetAuthContextFailedAccountName: 60,
410
+ StringValueTooLong: 61,
411
+ StartCalledMoreThanOnce: 62,
412
+ StopCalledWithoutStart: 63,
413
+ TelemetryInitializerFailed: 64,
414
+ TrackArgumentsNotSpecified: 65,
415
+ UrlTooLong: 66,
416
+ SessionStorageBufferFull: 67,
417
+ CannotAccessCookie: 68,
418
+ IdTooLong: 69,
419
+ InvalidEvent: 70,
420
+ FailedMonitorAjaxSetRequestHeader: 71,
421
+ SendBrowserInfoOnUserInit: 72,
422
+ PluginException: 73,
423
+ NotificationException: 74,
424
+ SnippetScriptLoadFailure: 99,
425
+ InvalidInstrumentationKey: 100,
426
+ CannotParseAiBlobValue: 101,
427
+ InvalidContentBlob: 102,
428
+ TrackPageActionEventFailed: 103,
429
+ FailedAddingCustomDefinedRequestContext: 104,
430
+ InMemoryStorageBufferFull: 105
431
+ };
350
432
 
433
+ var strOnPrefix = "on";
434
+ var strAttachEvent = "attachEvent";
435
+ var strAddEventHelper = "addEventListener";
351
436
  var strToISOString = "toISOString";
437
+ var strIndexOf = "indexOf";
352
438
  var cStrTrim = "trim";
353
439
  var strToString = "toString";
354
440
  var str__Proto = "__proto__";
355
441
  var strConstructor = "constructor";
356
- var _objDefineProperty$1 = ObjDefineProperty;
357
- var _objFreeze = ObjClass.freeze;
442
+ var _objDefineProperty = ObjDefineProperty;
358
443
  var _objKeys = ObjClass.keys;
359
444
  var StringProto = String[strShimPrototype];
360
445
  var _strTrim = StringProto[cStrTrim];
@@ -363,7 +448,7 @@
363
448
  var _isArray = Array.isArray;
364
449
  var _objToString = ObjProto[strToString];
365
450
  var _fnToString = ObjHasOwnProperty[strToString];
366
- var _objFunctionString = _fnToString.call(ObjClass);
451
+ _fnToString.call(ObjClass);
367
452
  var rCamelCase = /-([a-z])/g;
368
453
  var rNormalizeInvalid = /([^\w\d_$])/g;
369
454
  var rLeadingNumeric = /^(\d+[\w\d_$])/;
@@ -395,6 +480,25 @@
395
480
  function isFunction(value) {
396
481
  return !!(value && typeof value === strShimFunction);
397
482
  }
483
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
484
+ if (useCapture === void 0) { useCapture = false; }
485
+ var result = false;
486
+ if (!isNullOrUndefined(obj)) {
487
+ try {
488
+ if (!isNullOrUndefined(obj[strAddEventHelper])) {
489
+ obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
490
+ result = true;
491
+ }
492
+ else if (!isNullOrUndefined(obj[strAttachEvent])) {
493
+ obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
494
+ result = true;
495
+ }
496
+ }
497
+ catch (e) {
498
+ }
499
+ }
500
+ return result;
501
+ }
398
502
  function normalizeJsName(name) {
399
503
  var value = name;
400
504
  if (value && isString(value)) {
@@ -433,25 +537,6 @@
433
537
  function isNumber(value) {
434
538
  return typeof value === "number";
435
539
  }
436
- function isBoolean(value) {
437
- return typeof value === "boolean";
438
- }
439
- function isPlainObject(value) {
440
- var result = false;
441
- if (value && typeof value === "object") {
442
- var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
443
- if (!proto) {
444
- result = true;
445
- }
446
- else {
447
- if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
448
- proto = proto[strConstructor];
449
- }
450
- result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
451
- }
452
- }
453
- return result;
454
- }
455
540
  function toISOString(date) {
456
541
  if (date) {
457
542
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -490,6 +575,25 @@
490
575
  catch (e) {
491
576
  }
492
577
  }
578
+ function arrIndexOf(arr, searchElement, fromIndex) {
579
+ if (arr) {
580
+ if (arr[strIndexOf]) {
581
+ return arr[strIndexOf](searchElement, fromIndex);
582
+ }
583
+ var len = arr.length;
584
+ var from = fromIndex || 0;
585
+ try {
586
+ for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
587
+ if (lp in arr && arr[lp] === searchElement) {
588
+ return lp;
589
+ }
590
+ }
591
+ }
592
+ catch (e) {
593
+ }
594
+ }
595
+ return -1;
596
+ }
493
597
  function strTrim(str) {
494
598
  if (str) {
495
599
  str = (_strTrim && str[cStrTrim]) ? str[cStrTrim]() : (str.replace ? str.replace(/^\s+|\s+$/g, "") : str);
@@ -531,7 +635,7 @@
531
635
  return result;
532
636
  }
533
637
  function objDefineAccessors(target, prop, getProp, setProp) {
534
- if (_objDefineProperty$1) {
638
+ if (_objDefineProperty) {
535
639
  try {
536
640
  var descriptor = {
537
641
  enumerable: true,
@@ -543,7 +647,7 @@
543
647
  if (setProp) {
544
648
  descriptor.set = setProp;
545
649
  }
546
- _objDefineProperty$1(target, prop, descriptor);
650
+ _objDefineProperty(target, prop, descriptor);
547
651
  return true;
548
652
  }
549
653
  catch (e) {
@@ -551,10 +655,6 @@
551
655
  }
552
656
  return false;
553
657
  }
554
- function _doNothing(value) {
555
- return value;
556
- }
557
- var objFreeze = _objFreeze || _doNothing;
558
658
  function dateNow() {
559
659
  var dt = Date;
560
660
  return dt.now ? dt.now() : new dt().getTime();
@@ -570,91 +670,6 @@
570
670
  }
571
671
  return theValue;
572
672
  }
573
- function throwError(message) {
574
- throw new Error(message);
575
- }
576
- function _createProxyFunction(source, funcName) {
577
- var srcFunc = null;
578
- var src = null;
579
- if (isFunction(source)) {
580
- srcFunc = source;
581
- }
582
- else {
583
- src = source;
584
- }
585
- return function () {
586
- var originalArguments = arguments;
587
- if (srcFunc) {
588
- src = srcFunc();
589
- }
590
- if (src) {
591
- return src[funcName].apply(src, originalArguments);
592
- }
593
- };
594
- }
595
- function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
596
- if (overwriteTarget === void 0) { overwriteTarget = true; }
597
- if (target && name && source) {
598
- if (overwriteTarget || isUndefined(target[name])) {
599
- target[name] = _createProxyFunction(source, theFunc);
600
- }
601
- }
602
- }
603
- function createEnumStyle(values) {
604
- var enumClass = {};
605
- objForEachKey(values, function (field, value) {
606
- enumClass[field] = value;
607
- if (!isUndefined(enumClass[value])) {
608
- throwError("[" + value + "] exists for " + field);
609
- }
610
- enumClass[value] = field;
611
- });
612
- return objFreeze(enumClass);
613
- }
614
- function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
615
- var theArgs = arguments;
616
- var extended = theArgs[0] || {};
617
- var argLen = theArgs.length;
618
- var deep = false;
619
- var idx = 1;
620
- if (argLen > 0 && isBoolean(extended)) {
621
- deep = extended;
622
- extended = theArgs[idx] || {};
623
- idx++;
624
- }
625
- if (!isObject(extended)) {
626
- extended = {};
627
- }
628
- for (; idx < argLen; idx++) {
629
- var arg = theArgs[idx];
630
- var isArgArray = isArray(arg);
631
- var isArgObj = isObject(arg);
632
- for (var prop in arg) {
633
- var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
634
- if (!propOk) {
635
- continue;
636
- }
637
- var newValue = arg[prop];
638
- var isNewArray = void 0;
639
- if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
640
- var clone = extended[prop];
641
- if (isNewArray) {
642
- if (!isArray(clone)) {
643
- clone = [];
644
- }
645
- }
646
- else if (!isPlainObject(clone)) {
647
- clone = {};
648
- }
649
- newValue = objExtend(deep, clone, newValue);
650
- }
651
- if (newValue !== undefined) {
652
- extended[prop] = newValue;
653
- }
654
- }
655
- }
656
- return extended;
657
- }
658
673
 
659
674
  var strWindow = "window";
660
675
  var strDocument = "document";
@@ -668,7 +683,6 @@
668
683
  var strMsCrypto = "msCrypto";
669
684
  var strMsie = "msie";
670
685
  var strTrident = "trident/";
671
- var strXMLHttpRequest = "XMLHttpRequest";
672
686
  var _isTrident = null;
673
687
  var _navUserAgentCheck = null;
674
688
  var _enableMocks = false;
@@ -743,7 +757,7 @@
743
757
  var nav = getNavigator();
744
758
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
745
759
  _navUserAgentCheck = nav.userAgent;
746
- var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
760
+ var userAgent = (_navUserAgentCheck || "").toLowerCase();
747
761
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
748
762
  }
749
763
  return _isTrident;
@@ -752,9 +766,9 @@
752
766
  if (userAgentStr === void 0) { userAgentStr = null; }
753
767
  if (!userAgentStr) {
754
768
  var navigator_1 = getNavigator() || {};
755
- userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
769
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
756
770
  }
757
- var ua = (userAgentStr || strEmpty$1).toLowerCase();
771
+ var ua = (userAgentStr || "").toLowerCase();
758
772
  if (strContains(ua, strMsie)) {
759
773
  var doc = getDocument() || {};
760
774
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -769,7 +783,7 @@
769
783
  }
770
784
  function dumpObj(object) {
771
785
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
772
- var propertyValueDump = strEmpty$1;
786
+ var propertyValueDump = "";
773
787
  if (objectTypeDump === "[object Error]") {
774
788
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
775
789
  }
@@ -781,7 +795,7 @@
781
795
  function isXhrSupported() {
782
796
  var isSupported = false;
783
797
  try {
784
- var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
798
+ var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
785
799
  isSupported = !!xmlHttpRequest;
786
800
  }
787
801
  catch (e) {
@@ -812,9 +826,9 @@
812
826
  var strWarnToConsole = "warnToConsole";
813
827
  function _sanitizeDiagnosticText(text) {
814
828
  if (text) {
815
- return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
829
+ return "\"" + text.replace(/\"/g, "") + "\"";
816
830
  }
817
- return strEmpty$1;
831
+ return "";
818
832
  }
819
833
  function _logToConsole(func, message) {
820
834
  var theConsole = getConsole();
@@ -836,12 +850,12 @@
836
850
  _self.message =
837
851
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
838
852
  msgId;
839
- var strProps = strEmpty$1;
853
+ var strProps = "";
840
854
  if (hasJSON()) {
841
855
  strProps = getJSON().stringify(properties);
842
856
  }
843
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
844
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
857
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
858
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
845
859
  _self.message += diagnosticText;
846
860
  }
847
861
  _InternalLogMessage.dataType = "MessageData";
@@ -868,10 +882,10 @@
868
882
  if (isUserAct === void 0) { isUserAct = false; }
869
883
  var message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
870
884
  if (_self.enableDebugExceptions()) {
871
- throw message;
885
+ throw dumpObj(message);
872
886
  }
873
887
  else {
874
- var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
888
+ var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
875
889
  if (!isUndefined(message.message)) {
876
890
  var logLevel = _self.consoleLoggingLevel();
877
891
  if (isUserAct) {
@@ -889,7 +903,7 @@
889
903
  _self.logInternalMessage(severity, message);
890
904
  }
891
905
  else {
892
- _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
906
+ _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
893
907
  }
894
908
  }
895
909
  };
@@ -921,13 +935,13 @@
921
935
  if (severity <= _self.telemetryLoggingLevel()) {
922
936
  _self.queue.push(message);
923
937
  _messageCount++;
924
- _debugExtMsg((severity === 1 ? "error" : "warn"), message);
938
+ _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
925
939
  }
926
940
  if (_messageCount === _self.maxInternalMessageLimit()) {
927
941
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
928
- var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
942
+ var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
929
943
  _self.queue.push(throttleMessage);
930
- if (severity === 1 ) {
944
+ if (severity === LoggingSeverity.CRITICAL) {
931
945
  _self.errorToConsole(throttleLimitMessage);
932
946
  }
933
947
  else {
@@ -956,10 +970,6 @@
956
970
  }
957
971
  return DiagnosticLogger;
958
972
  }());
959
- function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
960
- if (isUserAct === void 0) { isUserAct = false; }
961
- (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
962
- }
963
973
 
964
974
  var strExecutionContextKey = "ctx";
965
975
  var PerfEvent = /** @class */ (function () {
@@ -1073,616 +1083,207 @@
1073
1083
  return func();
1074
1084
  }
1075
1085
 
1076
- var UInt32Mask = 0x100000000;
1077
- var MaxUInt32 = 0xffffffff;
1078
- var _mwcSeeded = false;
1079
- var _mwcW = 123456789;
1080
- var _mwcZ = 987654321;
1081
- function _mwcSeed(seedValue) {
1082
- if (seedValue < 0) {
1083
- seedValue >>>= 0;
1084
- }
1085
- _mwcW = (123456789 + seedValue) & MaxUInt32;
1086
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
1087
- _mwcSeeded = true;
1088
- }
1089
- function _autoSeedMwc() {
1090
- try {
1091
- var now = dateNow() & 0x7fffffff;
1092
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1093
- }
1094
- catch (e) {
1095
- }
1096
- }
1097
- function random32(signed) {
1098
- var value = 0;
1099
- var c = getCrypto() || getMsCrypto();
1100
- if (c && c.getRandomValues) {
1101
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1102
- }
1103
- if (value === 0 && isIE()) {
1104
- if (!_mwcSeeded) {
1105
- _autoSeedMwc();
1106
- }
1107
- value = mwcRandom32() & MaxUInt32;
1108
- }
1109
- if (value === 0) {
1110
- value = Math.floor((UInt32Mask * Math.random()) | 0);
1111
- }
1112
- if (!signed) {
1113
- value >>>= 0;
1114
- }
1115
- return value;
1116
- }
1117
- function mwcRandom32(signed) {
1118
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1119
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1120
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1121
- if (!signed) {
1122
- value >>>= 0;
1123
- }
1124
- return value;
1125
- }
1126
- function newId(maxLength) {
1127
- if (maxLength === void 0) { maxLength = 22; }
1128
- var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1129
- var number = random32() >>> 0;
1130
- var chars = 0;
1131
- var result = strEmpty$1;
1132
- while (result.length < maxLength) {
1133
- chars++;
1134
- result += base64chars.charAt(number & 0x3F);
1135
- number >>>= 6;
1136
- if (chars === 5) {
1137
- number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1138
- chars = 0;
1139
- }
1140
- }
1141
- return result;
1142
- }
1143
-
1144
- var _objDefineProperty = ObjDefineProperty;
1145
- var version = "2.7.5-nightly.2203-03";
1146
- var instanceName = "." + newId(6);
1147
- var _dataUid = 0;
1148
- function _createAccessor(target, prop, value) {
1149
- if (_objDefineProperty) {
1150
- try {
1151
- _objDefineProperty(target, prop, {
1152
- value: value,
1153
- enumerable: false,
1154
- configurable: true
1155
- });
1156
- return true;
1157
- }
1158
- catch (e) {
1159
- }
1160
- }
1161
- return false;
1162
- }
1163
- function _canAcceptData(target) {
1164
- return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1165
- }
1166
- function _getCache(data, target) {
1167
- var theCache = target[data.id];
1168
- if (!theCache) {
1169
- theCache = {};
1170
- try {
1171
- if (_canAcceptData(target)) {
1172
- if (!_createAccessor(target, data.id, theCache)) {
1173
- target[data.id] = theCache;
1174
- }
1175
- }
1176
- }
1177
- catch (e) {
1178
- }
1179
- }
1180
- return theCache;
1181
- }
1182
- function createUniqueNamespace(name, includeVersion) {
1183
- if (includeVersion === void 0) { includeVersion = false; }
1184
- return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1185
- }
1186
- function createElmNodeData(name) {
1187
- var data = {
1188
- id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1189
- accept: function (target) {
1190
- return _canAcceptData(target);
1191
- },
1192
- get: function (target, name, defValue, addDefault) {
1193
- var theCache = target[data.id];
1194
- if (!theCache) {
1195
- if (addDefault) {
1196
- theCache = _getCache(data, target);
1197
- theCache[normalizeJsName(name)] = defValue;
1198
- }
1199
- return defValue;
1200
- }
1201
- return theCache[normalizeJsName(name)];
1202
- },
1203
- kill: function (target, name) {
1204
- if (target && target[name]) {
1205
- try {
1206
- delete target[name];
1207
- }
1208
- catch (e) {
1209
- }
1086
+ var TelemetryPluginChain = /** @class */ (function () {
1087
+ function TelemetryPluginChain(plugin, defItemCtx) {
1088
+ var _self = this;
1089
+ var _nextProxy = null;
1090
+ var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1091
+ var _hasSetNext = isFunction(plugin.setNextPlugin);
1092
+ _self._hasRun = false;
1093
+ _self.getPlugin = function () {
1094
+ return plugin;
1095
+ };
1096
+ _self.getNext = function () {
1097
+ return _nextProxy;
1098
+ };
1099
+ _self.setNext = function (nextPlugin) {
1100
+ _nextProxy = nextPlugin;
1101
+ };
1102
+ _self.processTelemetry = function (env, itemCtx) {
1103
+ if (!itemCtx) {
1104
+ itemCtx = defItemCtx;
1210
1105
  }
1211
- }
1212
- };
1213
- return data;
1214
- }
1215
-
1216
- var pluginStateData = createElmNodeData("plugin");
1217
- function _getPluginState(plugin) {
1218
- return pluginStateData.get(plugin, "state", {}, true);
1219
- }
1220
-
1221
- var strTelemetryPluginChain = "TelemetryPluginChain";
1222
- var strHasRunFlags = "_hasRun";
1223
- var strGetTelCtx = "_getTelCtx";
1224
- var _chainId = 0;
1225
- function _getNextProxyStart(proxy, config, core, startAt) {
1226
- while (proxy) {
1227
- if (proxy.getPlugin() === startAt) {
1228
- return proxy;
1229
- }
1230
- proxy = proxy.getNext();
1231
- }
1232
- return createTelemetryProxyChain([startAt], config, core);
1233
- }
1234
- function _createInternalContext(telemetryChain, config, core, startAt) {
1235
- var _nextProxy = null;
1236
- var _onComplete = [];
1237
- if (startAt !== null) {
1238
- _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1239
- }
1240
- var context = {
1241
- _next: _moveNext,
1242
- ctx: {
1243
- core: function () {
1244
- return core;
1245
- },
1246
- diagLog: function () {
1247
- return safeGetLogger(core, config);
1248
- },
1249
- getCfg: function () {
1250
- return config;
1251
- },
1252
- getExtCfg: _getExtCfg,
1253
- getConfig: _getConfig,
1254
- hasNext: function () {
1255
- return !!_nextProxy;
1256
- },
1257
- getNext: function () {
1258
- return _nextProxy;
1259
- },
1260
- setNext: function (nextPlugin) {
1261
- _nextProxy = nextPlugin;
1262
- },
1263
- iterate: _iterateChain,
1264
- onComplete: _addOnComplete
1265
- }
1266
- };
1267
- function _addOnComplete(onComplete, that) {
1268
- var args = [];
1269
- for (var _i = 2; _i < arguments.length; _i++) {
1270
- args[_i - 2] = arguments[_i];
1271
- }
1272
- if (onComplete) {
1273
- _onComplete.push({
1274
- func: onComplete,
1275
- self: !isUndefined(that) ? that : context.ctx,
1276
- args: args
1277
- });
1278
- }
1279
- }
1280
- function _moveNext() {
1281
- var nextProxy = _nextProxy;
1282
- _nextProxy = nextProxy ? nextProxy.getNext() : null;
1283
- if (!nextProxy) {
1284
- var onComplete = _onComplete;
1285
- if (onComplete && onComplete.length > 0) {
1286
- arrForEach(onComplete, function (completeDetails) {
1106
+ var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1107
+ doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1108
+ if (plugin && _hasProcessTelemetry) {
1109
+ _self._hasRun = true;
1287
1110
  try {
1288
- completeDetails.func.call(completeDetails.self, completeDetails.args);
1289
- }
1290
- catch (e) {
1291
- _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1111
+ itemCtx.setNext(_nextProxy);
1112
+ if (_hasSetNext) {
1113
+ plugin.setNextPlugin(_nextProxy);
1114
+ }
1115
+ _nextProxy && (_nextProxy._hasRun = false);
1116
+ plugin.processTelemetry(env, itemCtx);
1292
1117
  }
1293
- });
1294
- _onComplete = [];
1295
- }
1296
- }
1297
- return nextProxy;
1298
- }
1299
- function _getExtCfg(identifier, defaultValue, mergeDefault) {
1300
- if (defaultValue === void 0) { defaultValue = {}; }
1301
- if (mergeDefault === void 0) { mergeDefault = 0 ; }
1302
- var theConfig;
1303
- if (config) {
1304
- var extConfig = config.extensionConfig;
1305
- if (extConfig && identifier) {
1306
- theConfig = extConfig[identifier];
1307
- }
1308
- }
1309
- if (!theConfig) {
1310
- theConfig = defaultValue;
1311
- }
1312
- else if (isObject(defaultValue)) {
1313
- if (mergeDefault !== 0 ) {
1314
- var newConfig_1 = objExtend(true, defaultValue, theConfig);
1315
- if (config && mergeDefault === 2 ) {
1316
- objForEachKey(defaultValue, function (field) {
1317
- if (isNullOrUndefined(newConfig_1[field])) {
1318
- var cfgValue = config[field];
1319
- if (!isNullOrUndefined(cfgValue)) {
1320
- newConfig_1[field] = cfgValue;
1321
- }
1118
+ catch (error) {
1119
+ var hasRun = _nextProxy && _nextProxy._hasRun;
1120
+ if (!_nextProxy || !hasRun) {
1121
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1322
1122
  }
1323
- });
1123
+ if (_nextProxy && !hasRun) {
1124
+ _nextProxy.processTelemetry(env, itemCtx);
1125
+ }
1126
+ }
1324
1127
  }
1325
- }
1326
- }
1327
- return theConfig;
1328
- }
1329
- function _getConfig(identifier, field, defaultValue) {
1330
- if (defaultValue === void 0) { defaultValue = false; }
1331
- var theValue;
1332
- var extConfig = _getExtCfg(identifier, null);
1333
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1334
- theValue = extConfig[field];
1335
- }
1336
- else if (config && !isNullOrUndefined(config[field])) {
1337
- theValue = config[field];
1338
- }
1339
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1128
+ else if (_nextProxy) {
1129
+ _self._hasRun = true;
1130
+ _nextProxy.processTelemetry(env, itemCtx);
1131
+ }
1132
+ }, function () { return ({ item: env }); }, !(env.sync));
1133
+ };
1340
1134
  }
1341
- function _iterateChain(cb) {
1342
- var nextPlugin;
1343
- while (!!(nextPlugin = context._next())) {
1344
- var plugin = nextPlugin.getPlugin();
1345
- if (plugin) {
1346
- cb(plugin);
1135
+ return TelemetryPluginChain;
1136
+ }());
1137
+
1138
+ function _createProxyChain(plugins, itemCtx) {
1139
+ var proxies = [];
1140
+ if (plugins && plugins.length > 0) {
1141
+ var lastProxy = null;
1142
+ for (var idx = 0; idx < plugins.length; idx++) {
1143
+ var thePlugin = plugins[idx];
1144
+ if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1145
+ var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1146
+ proxies.push(newProxy);
1147
+ if (lastProxy) {
1148
+ lastProxy.setNext(newProxy);
1149
+ }
1150
+ lastProxy = newProxy;
1347
1151
  }
1348
1152
  }
1349
1153
  }
1350
- return context;
1154
+ return proxies.length > 0 ? proxies[0] : null;
1351
1155
  }
1352
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1353
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1354
- var context = internalContext.ctx;
1355
- function _processNext(env) {
1356
- var nextPlugin = internalContext._next();
1357
- nextPlugin && nextPlugin.processTelemetry(env, context);
1358
- return !nextPlugin;
1359
- }
1360
- function _createNew(plugins, startAt) {
1361
- if (plugins === void 0) { plugins = null; }
1362
- if (isArray(plugins)) {
1363
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1156
+ function _copyProxyChain(proxy, itemCtx, startAt) {
1157
+ var plugins = [];
1158
+ var add = startAt ? false : true;
1159
+ if (proxy) {
1160
+ while (proxy) {
1161
+ var thePlugin = proxy.getPlugin();
1162
+ if (add || thePlugin === startAt) {
1163
+ add = true;
1164
+ plugins.push(thePlugin);
1165
+ }
1166
+ proxy = proxy.getNext();
1364
1167
  }
1365
- return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1366
- }
1367
- context.processNext = _processNext;
1368
- context.createNew = _createNew;
1369
- return context;
1370
- }
1371
- function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1372
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1373
- var context = internalContext.ctx;
1374
- function _processNext(unloadState) {
1375
- var nextPlugin = internalContext._next();
1376
- nextPlugin && nextPlugin.unload(context, unloadState);
1377
- return !nextPlugin;
1378
1168
  }
1379
- function _createNew(plugins, startAt) {
1380
- if (plugins === void 0) { plugins = null; }
1381
- if (isArray(plugins)) {
1382
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1383
- }
1384
- return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1169
+ if (!add) {
1170
+ plugins.push(startAt);
1385
1171
  }
1386
- context.processNext = _processNext;
1387
- context.createNew = _createNew;
1388
- return context;
1172
+ return _createProxyChain(plugins, itemCtx);
1389
1173
  }
1390
- function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1391
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1392
- var context = internalContext.ctx;
1393
- function _processNext(updateState) {
1394
- return context.iterate(function (plugin) {
1395
- if (isFunction(plugin[strUpdate])) {
1396
- plugin[strUpdate](context, updateState);
1174
+ function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1175
+ var plugins = srcPlugins;
1176
+ var add = false;
1177
+ if (startAt && srcPlugins) {
1178
+ plugins = [];
1179
+ arrForEach(srcPlugins, function (thePlugin) {
1180
+ if (add || thePlugin === startAt) {
1181
+ add = true;
1182
+ plugins.push(thePlugin);
1397
1183
  }
1398
1184
  });
1399
1185
  }
1400
- function _createNew(plugins, startAt) {
1401
- if (plugins === void 0) { plugins = null; }
1402
- if (isArray(plugins)) {
1403
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1186
+ if (startAt && !add) {
1187
+ if (!plugins) {
1188
+ plugins = [];
1404
1189
  }
1405
- return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1190
+ plugins.push(startAt);
1406
1191
  }
1407
- context.processNext = _processNext;
1408
- context.createNew = _createNew;
1409
- return context;
1192
+ return _createProxyChain(plugins, itemCtx);
1410
1193
  }
1411
- function createTelemetryProxyChain(plugins, config, core, startAt) {
1412
- var firstProxy = null;
1413
- var add = startAt ? false : true;
1414
- if (isArray(plugins) && plugins.length > 0) {
1415
- var lastProxy_1 = null;
1416
- arrForEach(plugins, function (thePlugin) {
1417
- if (!add && startAt === thePlugin) {
1418
- add = true;
1194
+ var ProcessTelemetryContext = /** @class */ (function () {
1195
+ function ProcessTelemetryContext(plugins, config, core, startAt) {
1196
+ var _self = this;
1197
+ var _nextProxy = null;
1198
+ if (startAt !== null) {
1199
+ if (plugins && isFunction(plugins.getPlugin)) {
1200
+ _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1419
1201
  }
1420
- if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1421
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1422
- if (!firstProxy) {
1423
- firstProxy = newProxy;
1202
+ else {
1203
+ if (startAt) {
1204
+ _nextProxy = _copyPluginChain(plugins, _self, startAt);
1424
1205
  }
1425
- if (lastProxy_1) {
1426
- lastProxy_1._setNext(newProxy);
1206
+ else if (isUndefined(startAt)) {
1207
+ _nextProxy = _createProxyChain(plugins, _self);
1427
1208
  }
1428
- lastProxy_1 = newProxy;
1429
1209
  }
1430
- });
1431
- }
1432
- if (startAt && !firstProxy) {
1433
- return createTelemetryProxyChain([startAt], config, core);
1434
- }
1435
- return firstProxy;
1436
- }
1437
- function createTelemetryPluginProxy(plugin, config, core) {
1438
- var nextProxy = null;
1439
- var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1440
- var hasSetNext = isFunction(plugin.setNextPlugin);
1441
- var chainId;
1442
- if (plugin) {
1443
- chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1444
- }
1445
- else {
1446
- chainId = "Unknown-0-" + _chainId++;
1447
- }
1448
- var proxyChain = {
1449
- getPlugin: function () {
1450
- return plugin;
1451
- },
1452
- getNext: function () {
1453
- return nextProxy;
1454
- },
1455
- processTelemetry: _processTelemetry,
1456
- unload: _unloadPlugin,
1457
- update: _updatePlugin,
1458
- _id: chainId,
1459
- _setNext: function (nextPlugin) {
1460
- nextProxy = nextPlugin;
1461
1210
  }
1462
- };
1463
- function _getTelCtx() {
1464
- var itemCtx;
1465
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1466
- itemCtx = plugin[strGetTelCtx]();
1467
- }
1468
- if (!itemCtx) {
1469
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1470
- }
1471
- return itemCtx;
1472
- }
1473
- function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1474
- var hasRun = false;
1475
- var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1476
- var hasRunContext = itemCtx[strHasRunFlags];
1477
- if (!hasRunContext) {
1478
- hasRunContext = itemCtx[strHasRunFlags] = {};
1479
- }
1480
- itemCtx.setNext(nextProxy);
1481
- if (plugin) {
1482
- doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1483
- hasRunContext[chainId] = true;
1484
- try {
1485
- var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1486
- if (nextId) {
1487
- hasRunContext[nextId] = false;
1488
- }
1489
- hasRun = processPluginFn(itemCtx);
1490
- }
1491
- catch (error) {
1492
- var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1493
- if (hasNextRun) {
1494
- hasRun = true;
1495
- }
1496
- if (!nextProxy || !hasNextRun) {
1497
- _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1498
- }
1211
+ _self.core = function () {
1212
+ return core;
1213
+ };
1214
+ _self.diagLog = function () {
1215
+ return safeGetLogger(core, config);
1216
+ };
1217
+ _self.getCfg = function () {
1218
+ return config;
1219
+ };
1220
+ _self.getExtCfg = function (identifier, defaultValue) {
1221
+ if (defaultValue === void 0) { defaultValue = {}; }
1222
+ var theConfig;
1223
+ if (config) {
1224
+ var extConfig = config.extensionConfig;
1225
+ if (extConfig && identifier) {
1226
+ theConfig = extConfig[identifier];
1499
1227
  }
1500
- }, details, isAsync);
1501
- }
1502
- return hasRun;
1503
- }
1504
- function _processTelemetry(env, itemCtx) {
1505
- itemCtx = itemCtx || _getTelCtx();
1506
- function _callProcessTelemetry(itemCtx) {
1507
- if (!plugin || !hasProcessTelemetry) {
1508
- return false;
1509
1228
  }
1510
- var pluginState = _getPluginState(plugin);
1511
- if (pluginState[strTeardown] || pluginState[strDisabled]) {
1512
- return false;
1513
- }
1514
- if (hasSetNext) {
1515
- plugin.setNextPlugin(nextProxy);
1229
+ return (theConfig ? theConfig : defaultValue);
1230
+ };
1231
+ _self.getConfig = function (identifier, field, defaultValue) {
1232
+ if (defaultValue === void 0) { defaultValue = false; }
1233
+ var theValue;
1234
+ var extConfig = _self.getExtCfg(identifier, null);
1235
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1236
+ theValue = extConfig[field];
1516
1237
  }
1517
- plugin.processTelemetry(env, itemCtx);
1518
- return true;
1519
- }
1520
- if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1521
- itemCtx.processNext(env);
1522
- }
1523
- }
1524
- function _unloadPlugin(unloadCtx, unloadState) {
1525
- function _callTeardown() {
1526
- var hasRun = false;
1527
- if (plugin) {
1528
- var pluginState = _getPluginState(plugin);
1529
- var pluginCore = plugin[strCore] || pluginState.core;
1530
- if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1531
- pluginState[strCore] = null;
1532
- pluginState[strTeardown] = true;
1533
- pluginState[strIsInitialized] = false;
1534
- if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1535
- hasRun = true;
1536
- }
1537
- }
1238
+ else if (config && !isNullOrUndefined(config[field])) {
1239
+ theValue = config[field];
1538
1240
  }
1539
- return hasRun;
1540
- }
1541
- if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1542
- unloadCtx.processNext(unloadState);
1543
- }
1544
- }
1545
- function _updatePlugin(updateCtx, updateState) {
1546
- function _callUpdate() {
1547
- var hasRun = false;
1548
- if (plugin) {
1549
- var pluginState = _getPluginState(plugin);
1550
- var pluginCore = plugin[strCore] || pluginState.core;
1551
- if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1552
- if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1553
- hasRun = true;
1554
- }
1555
- }
1241
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1242
+ };
1243
+ _self.hasNext = function () {
1244
+ return _nextProxy != null;
1245
+ };
1246
+ _self.getNext = function () {
1247
+ return _nextProxy;
1248
+ };
1249
+ _self.setNext = function (nextPlugin) {
1250
+ _nextProxy = nextPlugin;
1251
+ };
1252
+ _self.processNext = function (env) {
1253
+ var nextPlugin = _nextProxy;
1254
+ if (nextPlugin) {
1255
+ _nextProxy = nextPlugin.getNext();
1256
+ nextPlugin.processTelemetry(env, _self);
1556
1257
  }
1557
- return hasRun;
1558
- }
1559
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1560
- updateCtx.processNext(updateState);
1561
- }
1258
+ };
1259
+ _self.createNew = function (plugins, startAt) {
1260
+ if (plugins === void 0) { plugins = null; }
1261
+ return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1262
+ };
1562
1263
  }
1563
- return objFreeze(proxyChain);
1564
- }
1264
+ return ProcessTelemetryContext;
1265
+ }());
1565
1266
 
1566
1267
  var strExtensionConfig = "extensionConfig";
1567
1268
 
1568
- function createUnloadHandlerContainer() {
1569
- var handlers = [];
1570
- function _addHandler(handler) {
1571
- if (handler) {
1572
- handlers.push(handler);
1573
- }
1574
- }
1575
- function _runHandlers(unloadCtx, unloadState) {
1576
- arrForEach(handlers, function (handler) {
1577
- try {
1578
- handler(unloadCtx, unloadState);
1579
- }
1580
- catch (e) {
1581
- _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1582
- }
1583
- });
1584
- handlers = [];
1585
- }
1586
- return {
1587
- add: _addHandler,
1588
- run: _runHandlers
1589
- };
1590
- }
1591
-
1592
1269
  var strGetPlugin = "getPlugin";
1593
1270
  var BaseTelemetryPlugin = /** @class */ (function () {
1594
1271
  function BaseTelemetryPlugin() {
1595
1272
  var _self = this;
1596
- var _isinitialized;
1597
- var _rootCtx;
1598
- var _nextPlugin;
1599
- var _unloadHandlerContainer;
1600
- var _hooks;
1601
- _initDefaults();
1602
- dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1603
- _self.initialize = function (config, core, extensions, pluginChain) {
1604
- _setDefaults(config, core, pluginChain);
1605
- _isinitialized = true;
1606
- };
1607
- _self.teardown = function (unloadCtx, unloadState) {
1608
- if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1609
- return;
1610
- }
1611
- var result;
1612
- var unloadDone = false;
1613
- var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1614
- var theUnloadState = unloadState || {
1615
- reason: 0 ,
1616
- isAsync: false
1617
- };
1618
- function _unloadCallback() {
1619
- if (!unloadDone) {
1620
- unloadDone = true;
1621
- _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1622
- arrForEach(_hooks, function (fn) {
1623
- fn.rm();
1624
- });
1625
- _hooks = [];
1626
- if (result === true) {
1627
- theUnloadCtx.processNext(theUnloadState);
1628
- }
1629
- _initDefaults();
1630
- }
1631
- }
1632
- if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1633
- _unloadCallback();
1634
- }
1635
- else {
1636
- result = true;
1637
- }
1638
- return result;
1639
- };
1640
- _self.update = function (updateCtx, updateState) {
1641
- if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
1642
- return;
1643
- }
1644
- var result;
1645
- var updateDone = false;
1646
- var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1647
- var theUpdateState = updateState || {
1648
- reason: 0
1649
- };
1650
- function _updateCallback() {
1651
- if (!updateDone) {
1652
- updateDone = true;
1653
- _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1654
- }
1655
- }
1656
- if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1657
- _updateCallback();
1658
- }
1659
- else {
1660
- result = true;
1661
- }
1662
- return result;
1663
- };
1664
- _self._addHook = function (hooks) {
1665
- if (hooks) {
1666
- if (isArray(hooks)) {
1667
- _hooks = _hooks.concat(hooks);
1668
- }
1669
- else {
1670
- _hooks.push(hooks);
1671
- }
1672
- }
1673
- };
1674
- proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1675
- });
1273
+ var _isinitialized = false;
1274
+ var _rootCtx = null;
1275
+ var _nextPlugin = null;
1276
+ _self.core = null;
1676
1277
  _self.diagLog = function (itemCtx) {
1677
- return _getTelCtx(itemCtx).diagLog();
1278
+ return _self._getTelCtx(itemCtx).diagLog();
1678
1279
  };
1679
- _self[strIsInitialized] = function () {
1280
+ _self.isInitialized = function () {
1680
1281
  return _isinitialized;
1681
1282
  };
1682
1283
  _self.setInitialized = function (isInitialized) {
1683
1284
  _isinitialized = isInitialized;
1684
1285
  };
1685
- _self[strSetNextPlugin] = function (next) {
1286
+ _self.setNextPlugin = function (next) {
1686
1287
  _nextPlugin = next;
1687
1288
  };
1688
1289
  _self.processNext = function (env, itemCtx) {
@@ -1693,12 +1294,11 @@
1693
1294
  _nextPlugin.processTelemetry(env, null);
1694
1295
  }
1695
1296
  };
1696
- _self._getTelCtx = _getTelCtx;
1697
- function _getTelCtx(currentCtx) {
1297
+ _self._getTelCtx = function (currentCtx) {
1698
1298
  if (currentCtx === void 0) { currentCtx = null; }
1699
1299
  var itemCtx = currentCtx;
1700
1300
  if (!itemCtx) {
1701
- var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1301
+ var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1702
1302
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1703
1303
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1704
1304
  }
@@ -1707,8 +1307,8 @@
1707
1307
  }
1708
1308
  }
1709
1309
  return itemCtx;
1710
- }
1711
- function _setDefaults(config, core, pluginChain) {
1310
+ };
1311
+ _self._baseTelInit = function (config, core, extensions, pluginChain) {
1712
1312
  if (config) {
1713
1313
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1714
1314
  }
@@ -1720,133 +1320,70 @@
1720
1320
  nextPlugin = _nextPlugin[strGetPlugin]();
1721
1321
  }
1722
1322
  _self.core = core;
1723
- _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1724
- }
1725
- function _initDefaults() {
1726
- _isinitialized = false;
1727
- _self.core = null;
1728
- _rootCtx = null;
1729
- _nextPlugin = null;
1730
- _hooks = [];
1731
- _unloadHandlerContainer = createUnloadHandlerContainer();
1732
- }
1323
+ _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1324
+ _isinitialized = true;
1325
+ };
1733
1326
  }
1327
+ BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1328
+ this._baseTelInit(config, core, extensions, pluginChain);
1329
+ };
1734
1330
  return BaseTelemetryPlugin;
1735
1331
  }());
1736
1332
 
1737
- var strOnPrefix = "on";
1738
- var strAttachEvent = "attachEvent";
1739
- var strAddEventHelper = "addEventListener";
1740
- var strEvents = "events";
1741
- createUniqueNamespace("aiEvtPageHide");
1742
- createUniqueNamespace("aiEvtPageShow");
1743
- var rRemoveEmptyNs = /\.[\.]+/g;
1744
- var rRemoveTrailingEmptyNs = /[\.]+$/;
1745
- var _guid = 1;
1746
- var elmNodeData = createElmNodeData("events");
1747
- var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1748
- function _normalizeNamespace(name) {
1749
- if (name && name.replace) {
1750
- return name.replace(/^\s*\.*|\.*\s*$/g, "");
1751
- }
1752
- return name;
1753
- }
1754
- function _getEvtNamespace(eventName, evtNamespace) {
1755
- if (evtNamespace) {
1756
- var theNamespace_1 = "";
1757
- if (isArray(evtNamespace)) {
1758
- theNamespace_1 = "";
1759
- arrForEach(evtNamespace, function (name) {
1760
- name = _normalizeNamespace(name);
1761
- if (name) {
1762
- if (name[0] !== ".") {
1763
- name = "." + name;
1764
- }
1765
- theNamespace_1 += name;
1766
- }
1767
- });
1768
- }
1769
- else {
1770
- theNamespace_1 = _normalizeNamespace(evtNamespace);
1771
- }
1772
- if (theNamespace_1) {
1773
- if (theNamespace_1[0] !== ".") {
1774
- theNamespace_1 = "." + theNamespace_1;
1775
- }
1776
- eventName = (eventName || "") + theNamespace_1;
1777
- }
1333
+ var UInt32Mask = 0x100000000;
1334
+ var MaxUInt32 = 0xffffffff;
1335
+ var _mwcSeeded = false;
1336
+ var _mwcW = 123456789;
1337
+ var _mwcZ = 987654321;
1338
+ function _mwcSeed(seedValue) {
1339
+ if (seedValue < 0) {
1340
+ seedValue >>>= 0;
1778
1341
  }
1779
- var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1780
- return {
1781
- type: parsedEvent[1],
1782
- ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1783
- };
1342
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1343
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1344
+ _mwcSeeded = true;
1784
1345
  }
1785
- function _getRegisteredEvents(target, evtName, addDefault) {
1786
- if (addDefault === void 0) { addDefault = true; }
1787
- var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1788
- var registeredEvents = aiEvts[evtName];
1789
- if (!registeredEvents) {
1790
- registeredEvents = aiEvts[evtName] = [];
1346
+ function _autoSeedMwc() {
1347
+ try {
1348
+ var now = dateNow() & 0x7fffffff;
1349
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1791
1350
  }
1792
- return registeredEvents;
1793
- }
1794
- function _doAttach(obj, evtName, handlerRef, useCapture) {
1795
- var result = false;
1796
- if (obj && evtName && evtName.type && handlerRef) {
1797
- if (obj[strAddEventHelper]) {
1798
- obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1799
- result = true;
1800
- }
1801
- else if (obj[strAttachEvent]) {
1802
- obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1803
- result = true;
1804
- }
1351
+ catch (e) {
1805
1352
  }
1806
- return result;
1807
1353
  }
1808
- function mergeEvtNamespace(theNamespace, namespaces) {
1809
- var newNamespaces;
1810
- if (namespaces) {
1811
- if (isArray(namespaces)) {
1812
- newNamespaces = [theNamespace].concat(namespaces);
1813
- }
1814
- else {
1815
- newNamespaces = [theNamespace, namespaces];
1354
+ function random32(signed) {
1355
+ var value;
1356
+ var c = getCrypto() || getMsCrypto();
1357
+ if (c && c.getRandomValues) {
1358
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1359
+ }
1360
+ else if (isIE()) {
1361
+ if (!_mwcSeeded) {
1362
+ _autoSeedMwc();
1816
1363
  }
1817
- newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1364
+ value = mwcRandom32() & MaxUInt32;
1818
1365
  }
1819
1366
  else {
1820
- newNamespaces = theNamespace;
1367
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1821
1368
  }
1822
- return newNamespaces;
1369
+ if (!signed) {
1370
+ value >>>= 0;
1371
+ }
1372
+ return value;
1823
1373
  }
1824
- function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1825
- if (useCapture === void 0) { useCapture = false; }
1826
- var result = false;
1827
- if (target) {
1828
- try {
1829
- var evtName = _getEvtNamespace(eventName, evtNamespace);
1830
- result = _doAttach(target, evtName, handlerRef, useCapture);
1831
- if (result && elmNodeData.accept(target)) {
1832
- var registeredEvent = {
1833
- guid: _guid++,
1834
- evtName: evtName,
1835
- handler: handlerRef,
1836
- capture: useCapture
1837
- };
1838
- _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1839
- }
1840
- }
1841
- catch (e) {
1842
- }
1374
+ function mwcRandom32(signed) {
1375
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1376
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1377
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1378
+ if (!signed) {
1379
+ value >>>= 0;
1843
1380
  }
1844
- return result;
1381
+ return value;
1845
1382
  }
1846
1383
 
1847
1384
  function generateW3CId() {
1848
1385
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
1849
- var oct = strEmpty$1, tmp;
1386
+ var oct = "", tmp;
1850
1387
  for (var a = 0; a < 4; a++) {
1851
1388
  tmp = random32();
1852
1389
  oct +=
@@ -1863,95 +1400,6 @@
1863
1400
  return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
1864
1401
  }
1865
1402
 
1866
- var LoggingSeverity = createEnumStyle({
1867
- CRITICAL: 1 ,
1868
- WARNING: 2
1869
- });
1870
- var _InternalMessageId = createEnumStyle({
1871
- BrowserDoesNotSupportLocalStorage: 0 ,
1872
- BrowserCannotReadLocalStorage: 1 ,
1873
- BrowserCannotReadSessionStorage: 2 ,
1874
- BrowserCannotWriteLocalStorage: 3 ,
1875
- BrowserCannotWriteSessionStorage: 4 ,
1876
- BrowserFailedRemovalFromLocalStorage: 5 ,
1877
- BrowserFailedRemovalFromSessionStorage: 6 ,
1878
- CannotSendEmptyTelemetry: 7 ,
1879
- ClientPerformanceMathError: 8 ,
1880
- ErrorParsingAISessionCookie: 9 ,
1881
- ErrorPVCalc: 10 ,
1882
- ExceptionWhileLoggingError: 11 ,
1883
- FailedAddingTelemetryToBuffer: 12 ,
1884
- FailedMonitorAjaxAbort: 13 ,
1885
- FailedMonitorAjaxDur: 14 ,
1886
- FailedMonitorAjaxOpen: 15 ,
1887
- FailedMonitorAjaxRSC: 16 ,
1888
- FailedMonitorAjaxSend: 17 ,
1889
- FailedMonitorAjaxGetCorrelationHeader: 18 ,
1890
- FailedToAddHandlerForOnBeforeUnload: 19 ,
1891
- FailedToSendQueuedTelemetry: 20 ,
1892
- FailedToReportDataLoss: 21 ,
1893
- FlushFailed: 22 ,
1894
- MessageLimitPerPVExceeded: 23 ,
1895
- MissingRequiredFieldSpecification: 24 ,
1896
- NavigationTimingNotSupported: 25 ,
1897
- OnError: 26 ,
1898
- SessionRenewalDateIsZero: 27 ,
1899
- SenderNotInitialized: 28 ,
1900
- StartTrackEventFailed: 29 ,
1901
- StopTrackEventFailed: 30 ,
1902
- StartTrackFailed: 31 ,
1903
- StopTrackFailed: 32 ,
1904
- TelemetrySampledAndNotSent: 33 ,
1905
- TrackEventFailed: 34 ,
1906
- TrackExceptionFailed: 35 ,
1907
- TrackMetricFailed: 36 ,
1908
- TrackPVFailed: 37 ,
1909
- TrackPVFailedCalc: 38 ,
1910
- TrackTraceFailed: 39 ,
1911
- TransmissionFailed: 40 ,
1912
- FailedToSetStorageBuffer: 41 ,
1913
- FailedToRestoreStorageBuffer: 42 ,
1914
- InvalidBackendResponse: 43 ,
1915
- FailedToFixDepricatedValues: 44 ,
1916
- InvalidDurationValue: 45 ,
1917
- TelemetryEnvelopeInvalid: 46 ,
1918
- CreateEnvelopeError: 47 ,
1919
- CannotSerializeObject: 48 ,
1920
- CannotSerializeObjectNonSerializable: 49 ,
1921
- CircularReferenceDetected: 50 ,
1922
- ClearAuthContextFailed: 51 ,
1923
- ExceptionTruncated: 52 ,
1924
- IllegalCharsInName: 53 ,
1925
- ItemNotInArray: 54 ,
1926
- MaxAjaxPerPVExceeded: 55 ,
1927
- MessageTruncated: 56 ,
1928
- NameTooLong: 57 ,
1929
- SampleRateOutOfRange: 58 ,
1930
- SetAuthContextFailed: 59 ,
1931
- SetAuthContextFailedAccountName: 60 ,
1932
- StringValueTooLong: 61 ,
1933
- StartCalledMoreThanOnce: 62 ,
1934
- StopCalledWithoutStart: 63 ,
1935
- TelemetryInitializerFailed: 64 ,
1936
- TrackArgumentsNotSpecified: 65 ,
1937
- UrlTooLong: 66 ,
1938
- SessionStorageBufferFull: 67 ,
1939
- CannotAccessCookie: 68 ,
1940
- IdTooLong: 69 ,
1941
- InvalidEvent: 70 ,
1942
- FailedMonitorAjaxSetRequestHeader: 71 ,
1943
- SendBrowserInfoOnUserInit: 72 ,
1944
- PluginException: 73 ,
1945
- NotificationException: 74 ,
1946
- SnippetScriptLoadFailure: 99 ,
1947
- InvalidInstrumentationKey: 100 ,
1948
- CannotParseAiBlobValue: 101 ,
1949
- InvalidContentBlob: 102 ,
1950
- TrackPageActionEventFailed: 103 ,
1951
- FailedAddingCustomDefinedRequestContext: 104 ,
1952
- InMemoryStorageBufferFull: 105
1953
- });
1954
-
1955
1403
  var aiInstrumentHooks = "_aiHooks";
1956
1404
  var cbNames = [
1957
1405
  "req", "rsp", "hkErr", "fnErr"
@@ -2010,7 +1458,6 @@
2010
1458
  };
2011
1459
  var hookCtx = [];
2012
1460
  var cbArgs = _createArgs([funcArgs], orgArgs);
2013
- funcArgs.evt = getGlobalInst("event");
2014
1461
  function _createArgs(target, theArgs) {
2015
1462
  _arrLoop(theArgs, function (arg) {
2016
1463
  target.push(arg);
@@ -2127,7 +1574,7 @@
2127
1574
  name = strTrim(name.toString());
2128
1575
  if (name.length > 150 ) {
2129
1576
  nameTrunc = name.substring(0, 150 );
2130
- _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
1577
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2131
1578
  }
2132
1579
  }
2133
1580
  return nameTrunc || name;
@@ -2140,7 +1587,7 @@
2140
1587
  value = strTrim(value);
2141
1588
  if (value.toString().length > maxLength) {
2142
1589
  valueTrunc = value.toString().substring(0, maxLength);
2143
- _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
1590
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2144
1591
  }
2145
1592
  }
2146
1593
  return valueTrunc || value;
@@ -2157,7 +1604,7 @@
2157
1604
  value = getJSON().stringify(value);
2158
1605
  }
2159
1606
  catch (e) {
2160
- _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
1607
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2161
1608
  }
2162
1609
  }
2163
1610
  value = dataSanitizeString(logger, value, 8192 );
@@ -2185,7 +1632,7 @@
2185
1632
  input = strTrim(input);
2186
1633
  if (input.length > maxLength) {
2187
1634
  inputTrunc = input.substring(0, maxLength);
2188
- _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
1635
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2189
1636
  }
2190
1637
  }
2191
1638
  return inputTrunc || input;
@@ -2195,28 +1642,39 @@
2195
1642
  return s.substr(s.length - 3);
2196
1643
  }
2197
1644
 
2198
- var strEmpty = "";
2199
1645
  function msToTimeSpan(totalms) {
2200
1646
  if (isNaN(totalms) || totalms < 0) {
2201
1647
  totalms = 0;
2202
1648
  }
2203
1649
  totalms = Math.round(totalms);
2204
- var ms = strEmpty + totalms % 1000;
2205
- var sec = strEmpty + Math.floor(totalms / 1000) % 60;
2206
- var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
2207
- var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
1650
+ var ms = "" + totalms % 1000;
1651
+ var sec = "" + Math.floor(totalms / 1000) % 60;
1652
+ var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
1653
+ var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
2208
1654
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
2209
1655
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
2210
1656
  sec = sec.length < 2 ? "0" + sec : sec;
2211
1657
  min = min.length < 2 ? "0" + min : min;
2212
1658
  hour = hour.length < 2 ? "0" + hour : hour;
2213
- return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
1659
+ return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
2214
1660
  }
2215
1661
 
2216
1662
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2217
1663
  var strNotSpecified = "not_specified";
2218
1664
  var strIkey = "iKey";
2219
1665
 
1666
+ var StorageType;
1667
+ (function (StorageType) {
1668
+ StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
1669
+ StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
1670
+ })(StorageType || (StorageType = {}));
1671
+ var DistributedTracingModes;
1672
+ (function (DistributedTracingModes) {
1673
+ DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
1674
+ DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
1675
+ DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
1676
+ })(DistributedTracingModes || (DistributedTracingModes = {}));
1677
+
2220
1678
  var _document = getDocument() || {};
2221
1679
  var _htmlAnchorIdx = 0;
2222
1680
  var _htmlAnchorElement = [null, null, null, null, null];
@@ -2290,7 +1748,7 @@
2290
1748
  "https://dc-int.services.visualstudio.com/v2/track"
2291
1749
  ];
2292
1750
  function isInternalApplicationInsightsEndpoint(endpointUrl) {
2293
- return _internalEndpoints.indexOf(endpointUrl.toLowerCase()) !== -1;
1751
+ return arrIndexOf(_internalEndpoints, endpointUrl.toLowerCase()) !== -1;
2294
1752
  }
2295
1753
  var CorrelationIdHelper = {
2296
1754
  correlationIdPrefix: "cid-v1:",
@@ -2746,7 +2204,6 @@
2746
2204
  var strAjaxData = "ajaxData";
2747
2205
  var strThrowInternal = "throwInternal";
2748
2206
  var strFetch = "fetch";
2749
- var strTrackDependencyDataInternal = "trackDependencyDataInternal";
2750
2207
  var _markCount = 0;
2751
2208
  function _supportsFetch() {
2752
2209
  var _global = getGlobal();
@@ -2826,41 +2283,80 @@
2826
2283
  var _this = _super.call(this) || this;
2827
2284
  _this.identifier = AjaxMonitor.identifier;
2828
2285
  _this.priority = 120;
2829
- var _fetchInitialized;
2830
- var _xhrInitialized;
2831
- var _currentWindowHost;
2832
- var _config;
2833
- var _enableRequestHeaderTracking;
2834
- var _enableAjaxErrorStatusText;
2835
- var _trackAjaxAttempts;
2286
+ var strTrackDependencyDataInternal = "trackDependencyDataInternal";
2287
+ var location = getLocation();
2288
+ var _fetchInitialized = false;
2289
+ var _xhrInitialized = false;
2290
+ var _currentWindowHost = location && location.host && location.host.toLowerCase();
2291
+ var _config = AjaxMonitor.getEmptyConfig();
2292
+ var _enableRequestHeaderTracking = false;
2293
+ var _enableAjaxErrorStatusText = false;
2294
+ var _trackAjaxAttempts = 0;
2836
2295
  var _context;
2837
2296
  var _isUsingW3CHeaders;
2838
2297
  var _isUsingAIHeaders;
2839
2298
  var _markPrefix;
2840
- var _enableAjaxPerfTracking;
2841
- var _maxAjaxCallsPerView;
2842
- var _enableResponseHeaderTracking;
2843
- var _disabledUrls;
2844
- var _disableAjaxTracking;
2845
- var _disableFetchTracking;
2299
+ var _enableAjaxPerfTracking = false;
2300
+ var _maxAjaxCallsPerView = 0;
2301
+ var _enableResponseHeaderTracking = false;
2302
+ var _hooks = [];
2303
+ var _disabledUrls = {};
2846
2304
  var _excludeRequestFromAutoTrackingPatterns;
2847
2305
  var _addRequestContext;
2848
- var _evtNamespace;
2849
- dynamicProto(AjaxMonitor, _this, function (_self, _base) {
2850
- var _addHook = _base._addHook;
2851
- _initDefaults();
2306
+ dynamicProto(AjaxMonitor, _this, function (_self, base) {
2852
2307
  _self.initialize = function (config, core, extensions, pluginChain) {
2853
2308
  if (!_self.isInitialized()) {
2854
- _base.initialize(config, core, extensions, pluginChain);
2855
- _evtNamespace = mergeEvtNamespace(createUniqueNamespace("ajax"), core && core.evtNamespace && core.evtNamespace());
2856
- _populateDefaults(config);
2857
- _instrumentXhr();
2309
+ base.initialize(config, core, extensions, pluginChain);
2310
+ var ctx_1 = _self._getTelCtx();
2311
+ var defaultConfig = AjaxMonitor.getDefaultConfig();
2312
+ objForEachKey(defaultConfig, function (field, value) {
2313
+ _config[field] = ctx_1.getConfig(AjaxMonitor.identifier, field, value);
2314
+ });
2315
+ var distributedTracingMode = _config.distributedTracingMode;
2316
+ _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
2317
+ _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
2318
+ _enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
2319
+ _maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
2320
+ _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
2321
+ _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
2322
+ _addRequestContext = _config.addRequestContext;
2323
+ _isUsingAIHeaders = distributedTracingMode === DistributedTracingModes.AI || distributedTracingMode === DistributedTracingModes.AI_AND_W3C;
2324
+ _isUsingW3CHeaders = distributedTracingMode === DistributedTracingModes.AI_AND_W3C || distributedTracingMode === DistributedTracingModes.W3C;
2325
+ if (_enableAjaxPerfTracking) {
2326
+ var iKey = config.instrumentationKey || "unkwn";
2327
+ if (iKey.length > 5) {
2328
+ _markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
2329
+ }
2330
+ else {
2331
+ _markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
2332
+ }
2333
+ }
2334
+ if (_config.disableAjaxTracking === false) {
2335
+ _instrumentXhr();
2336
+ }
2858
2337
  _instrumentFetch();
2859
- _populateContext();
2338
+ if (extensions.length > 0 && extensions) {
2339
+ var propExt = void 0, extIx = 0;
2340
+ while (!propExt && extIx < extensions.length) {
2341
+ if (extensions[extIx] && extensions[extIx].identifier === PropertiesPluginIdentifier) {
2342
+ propExt = extensions[extIx];
2343
+ }
2344
+ extIx++;
2345
+ }
2346
+ if (propExt) {
2347
+ _context = propExt.context;
2348
+ }
2349
+ }
2860
2350
  }
2861
2351
  };
2862
- _self._doTeardown = function () {
2863
- _initDefaults();
2352
+ _self.teardown = function () {
2353
+ arrForEach(_hooks, function (fn) {
2354
+ fn.rm();
2355
+ });
2356
+ _hooks = [];
2357
+ _fetchInitialized = false;
2358
+ _xhrInitialized = false;
2359
+ _self.setInitialized(false);
2864
2360
  };
2865
2361
  _self.trackDependencyData = function (dependency, properties) {
2866
2362
  _self[strTrackDependencyDataInternal](dependency, properties);
@@ -2927,8 +2423,8 @@
2927
2423
  };
2928
2424
  _self[strTrackDependencyDataInternal] = function (dependency, properties, systemProperties) {
2929
2425
  if (_maxAjaxCallsPerView === -1 || _trackAjaxAttempts < _maxAjaxCallsPerView) {
2930
- if ((_config.distributedTracingMode === 2
2931
- || _config.distributedTracingMode === 1 )
2426
+ if ((_config.distributedTracingMode === DistributedTracingModes.W3C
2427
+ || _config.distributedTracingMode === DistributedTracingModes.AI_AND_W3C)
2932
2428
  && typeof dependency.id === "string" && dependency.id[dependency.id.length - 1] !== ".") {
2933
2429
  dependency.id += ".";
2934
2430
  }
@@ -2943,64 +2439,6 @@
2943
2439
  }
2944
2440
  ++_trackAjaxAttempts;
2945
2441
  };
2946
- function _initDefaults() {
2947
- var location = getLocation();
2948
- _fetchInitialized = false;
2949
- _xhrInitialized = false;
2950
- _currentWindowHost = location && location.host && location.host.toLowerCase();
2951
- _config = AjaxMonitor.getEmptyConfig();
2952
- _enableRequestHeaderTracking = false;
2953
- _enableAjaxErrorStatusText = false;
2954
- _trackAjaxAttempts = 0;
2955
- _context = null;
2956
- _isUsingW3CHeaders = false;
2957
- _isUsingAIHeaders = false;
2958
- _markPrefix = null;
2959
- _enableAjaxPerfTracking = false;
2960
- _maxAjaxCallsPerView = 0;
2961
- _enableResponseHeaderTracking = false;
2962
- _disabledUrls = {};
2963
- _disableAjaxTracking = false;
2964
- _disableFetchTracking = true;
2965
- _excludeRequestFromAutoTrackingPatterns = null;
2966
- _addRequestContext = null;
2967
- _evtNamespace = null;
2968
- }
2969
- function _populateDefaults(config) {
2970
- var ctx = createProcessTelemetryContext(null, config, _self.core);
2971
- _config = AjaxMonitor.getEmptyConfig();
2972
- var defaultConfig = AjaxMonitor.getDefaultConfig();
2973
- objForEachKey(defaultConfig, function (field, value) {
2974
- _config[field] = ctx.getConfig(AjaxMonitor.identifier, field, value);
2975
- });
2976
- var distributedTracingMode = _config.distributedTracingMode;
2977
- _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
2978
- _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
2979
- _enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
2980
- _maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
2981
- _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
2982
- _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
2983
- _addRequestContext = _config.addRequestContext;
2984
- _isUsingAIHeaders = distributedTracingMode === 0 || distributedTracingMode === 1 ;
2985
- _isUsingW3CHeaders = distributedTracingMode === 1 || distributedTracingMode === 2 ;
2986
- if (_enableAjaxPerfTracking) {
2987
- var iKey = config.instrumentationKey || "unkwn";
2988
- if (iKey.length > 5) {
2989
- _markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
2990
- }
2991
- else {
2992
- _markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
2993
- }
2994
- }
2995
- _disableAjaxTracking = !!_config.disableAjaxTracking;
2996
- _disableFetchTracking = !!_config.disableFetchTracking;
2997
- }
2998
- function _populateContext() {
2999
- var propExt = _self.core.getPlugin(PropertiesPluginIdentifier);
3000
- if (propExt) {
3001
- _context = propExt.plugin.context;
3002
- }
3003
- }
3004
2442
  function _canIncludeHeaders(header) {
3005
2443
  var rlt = true;
3006
2444
  if (header || _config.ignoreHeaders) {
@@ -3020,12 +2458,11 @@
3020
2458
  }
3021
2459
  var global = getGlobal();
3022
2460
  var isPolyfill = fetch.polyfill;
3023
- if (!_disableFetchTracking && !_fetchInitialized) {
3024
- _addHook(InstrumentFunc(global, strFetch, {
3025
- ns: _evtNamespace,
2461
+ if (_config.disableFetchTracking === false) {
2462
+ _hooks.push(InstrumentFunc(global, strFetch, {
3026
2463
  req: function (callDetails, input, init) {
3027
2464
  var fetchData;
3028
- if (!_disableFetchTracking && _fetchInitialized &&
2465
+ if (_fetchInitialized &&
3029
2466
  !_isDisabledRequest(null, input, init) &&
3030
2467
  !(isPolyfill && _xhrInitialized)) {
3031
2468
  var ctx = callDetails.ctx();
@@ -3038,33 +2475,31 @@
3038
2475
  }
3039
2476
  },
3040
2477
  rsp: function (callDetails, input) {
3041
- if (!_disableFetchTracking) {
3042
- var fetchData_1 = callDetails.ctx().data;
3043
- if (fetchData_1) {
3044
- callDetails.rslt = callDetails.rslt.then(function (response) {
3045
- _reportFetchMetrics(callDetails, (response || {}).status, input, response, fetchData_1, function () {
3046
- var ajaxResponse = {
3047
- statusText: response.statusText,
3048
- headerMap: null,
3049
- correlationContext: _getFetchCorrelationContext(response)
3050
- };
3051
- if (_enableResponseHeaderTracking) {
3052
- var responseHeaderMap_1 = {};
3053
- response.headers.forEach(function (value, name) {
3054
- if (_canIncludeHeaders(name)) {
3055
- responseHeaderMap_1[name] = value;
3056
- }
3057
- });
3058
- ajaxResponse.headerMap = responseHeaderMap_1;
3059
- }
3060
- return ajaxResponse;
3061
- });
3062
- return response;
3063
- })["catch"](function (reason) {
3064
- _reportFetchMetrics(callDetails, 0, input, null, fetchData_1, null, { error: reason.message });
3065
- throw reason;
2478
+ var fetchData = callDetails.ctx().data;
2479
+ if (fetchData) {
2480
+ callDetails.rslt = callDetails.rslt.then(function (response) {
2481
+ _reportFetchMetrics(callDetails, (response || {}).status, input, response, fetchData, function () {
2482
+ var ajaxResponse = {
2483
+ statusText: response.statusText,
2484
+ headerMap: null,
2485
+ correlationContext: _getFetchCorrelationContext(response)
2486
+ };
2487
+ if (_enableResponseHeaderTracking) {
2488
+ var responseHeaderMap_1 = {};
2489
+ response.headers.forEach(function (value, name) {
2490
+ if (_canIncludeHeaders(name)) {
2491
+ responseHeaderMap_1[name] = value;
2492
+ }
2493
+ });
2494
+ ajaxResponse.headerMap = responseHeaderMap_1;
2495
+ }
2496
+ return ajaxResponse;
3066
2497
  });
3067
- }
2498
+ return response;
2499
+ })["catch"](function (reason) {
2500
+ _reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message });
2501
+ throw reason;
2502
+ });
3068
2503
  }
3069
2504
  },
3070
2505
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxOpen, "Failed to monitor Window.fetch, monitoring data for this fetch call may be incorrect.")
@@ -3072,8 +2507,7 @@
3072
2507
  _fetchInitialized = true;
3073
2508
  }
3074
2509
  else if (isPolyfill) {
3075
- _addHook(InstrumentFunc(global, strFetch, {
3076
- ns: _evtNamespace,
2510
+ _hooks.push(InstrumentFunc(global, strFetch, {
3077
2511
  req: function (callDetails, input, init) {
3078
2512
  _isDisabledRequest(null, input, init);
3079
2513
  }
@@ -3084,68 +2518,58 @@
3084
2518
  }
3085
2519
  }
3086
2520
  function _hookProto(target, funcName, callbacks) {
3087
- _addHook(InstrumentProto(target, funcName, callbacks));
2521
+ _hooks.push(InstrumentProto(target, funcName, callbacks));
3088
2522
  }
3089
2523
  function _instrumentXhr() {
3090
- if (_supportsAjaxMonitoring(_self) && !_disableAjaxTracking && !_xhrInitialized) {
2524
+ if (_supportsAjaxMonitoring(_self) && !_xhrInitialized) {
3091
2525
  _hookProto(XMLHttpRequest, "open", {
3092
- ns: _evtNamespace,
3093
2526
  req: function (args, method, url, async) {
3094
- if (!_disableAjaxTracking) {
3095
- var xhr = args.inst;
3096
- var ajaxData = xhr[strAjaxData];
3097
- if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
3098
- if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
3099
- _openHandler(xhr, method, url, async);
3100
- }
3101
- _attachToOnReadyStateChange(xhr);
2527
+ var xhr = args.inst;
2528
+ var ajaxData = xhr[strAjaxData];
2529
+ if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
2530
+ if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
2531
+ _openHandler(xhr, method, url, async);
3102
2532
  }
2533
+ _attachToOnReadyStateChange(xhr);
3103
2534
  }
3104
2535
  },
3105
2536
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxOpen, "Failed to monitor XMLHttpRequest.open, monitoring data for this ajax call may be incorrect.")
3106
2537
  });
3107
2538
  _hookProto(XMLHttpRequest, "send", {
3108
- ns: _evtNamespace,
3109
2539
  req: function (args, context) {
3110
- if (!_disableAjaxTracking) {
3111
- var xhr = args.inst;
3112
- var ajaxData = xhr[strAjaxData];
3113
- if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
3114
- _createMarkId("xhr", ajaxData);
3115
- ajaxData.requestSentTime = dateTimeUtilsNow();
3116
- _self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
3117
- ajaxData.xhrMonitoringState.sendDone = true;
3118
- }
2540
+ var xhr = args.inst;
2541
+ var ajaxData = xhr[strAjaxData];
2542
+ if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
2543
+ _createMarkId("xhr", ajaxData);
2544
+ ajaxData.requestSentTime = dateTimeUtilsNow();
2545
+ _self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
2546
+ ajaxData.xhrMonitoringState.sendDone = true;
3119
2547
  }
3120
2548
  },
3121
2549
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSend, "Failed to monitor XMLHttpRequest, monitoring data for this ajax call may be incorrect.")
3122
2550
  });
3123
2551
  _hookProto(XMLHttpRequest, "abort", {
3124
- ns: _evtNamespace,
3125
2552
  req: function (args) {
3126
- if (!_disableAjaxTracking) {
3127
- var xhr = args.inst;
3128
- var ajaxData = xhr[strAjaxData];
3129
- if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
3130
- ajaxData.aborted = 1;
3131
- ajaxData.xhrMonitoringState.abortDone = true;
3132
- }
2553
+ var xhr = args.inst;
2554
+ var ajaxData = xhr[strAjaxData];
2555
+ if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
2556
+ ajaxData.aborted = 1;
2557
+ ajaxData.xhrMonitoringState.abortDone = true;
3133
2558
  }
3134
2559
  },
3135
2560
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxAbort, "Failed to monitor XMLHttpRequest.abort, monitoring data for this ajax call may be incorrect.")
3136
2561
  });
3137
- _hookProto(XMLHttpRequest, "setRequestHeader", {
3138
- ns: _evtNamespace,
3139
- req: function (args, header, value) {
3140
- if (!_disableAjaxTracking && _enableRequestHeaderTracking) {
2562
+ if (_enableRequestHeaderTracking) {
2563
+ _hookProto(XMLHttpRequest, "setRequestHeader", {
2564
+ req: function (args, header, value) {
3141
2565
  var xhr = args.inst;
3142
2566
  if (_isMonitoredXhrInstance(xhr) && _canIncludeHeaders(header)) {
3143
2567
  xhr[strAjaxData].requestHeaders[header] = value;
3144
2568
  }
3145
- }
3146
- },
3147
- hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSetRequestHeader, "Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
3148
- });
2569
+ },
2570
+ hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSetRequestHeader, "Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
2571
+ });
2572
+ }
3149
2573
  _xhrInitialized = true;
3150
2574
  }
3151
2575
  }
@@ -3216,7 +2640,7 @@
3216
2640
  xhr[strAjaxData] = ajaxData;
3217
2641
  }
3218
2642
  function _attachToOnReadyStateChange(xhr) {
3219
- xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", function () {
2643
+ xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = attachEvent(xhr, "readystatechange", function () {
3220
2644
  try {
3221
2645
  if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
3222
2646
  _onAjaxComplete(xhr);
@@ -3231,7 +2655,7 @@
3231
2655
  });
3232
2656
  }
3233
2657
  }
3234
- }, _evtNamespace);
2658
+ });
3235
2659
  }
3236
2660
  function _getResponseText(xhr) {
3237
2661
  try {
@@ -3516,7 +2940,7 @@
3516
2940
  disableFetchTracking: true,
3517
2941
  excludeRequestFromAutoTrackingPatterns: undefined,
3518
2942
  disableCorrelationHeaders: false,
3519
- distributedTracingMode: 1 ,
2943
+ distributedTracingMode: DistributedTracingModes.AI_AND_W3C,
3520
2944
  correlationHeaderExcludedDomains: [
3521
2945
  "*.blob.core.windows.net",
3522
2946
  "*.blob.core.chinacloudapi.cn",