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

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.2204-03
2
+ * Application Insights JavaScript SDK - Dependencies Plugin, 2.7.6
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.6
103
99
  * Copyright (c) Microsoft and contributors. All rights reserved.
104
100
  */
105
101
  var Constructor = 'constructor';
@@ -114,10 +110,13 @@
114
110
  var DynProtoDefaultOptions = '_dfOpts';
115
111
  var UnknownValue = '_unknown_';
116
112
  var str__Proto$1 = "__proto__";
113
+ var DynProtoBaseProto = "_dyn" + str__Proto$1;
114
+ var DynProtoCurrent = "_dynInstProto";
117
115
  var strUseBaseInst = 'useBaseInst';
118
116
  var strSetInstFuncs = 'setInstFuncs';
119
117
  var Obj = Object;
120
118
  var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
119
+ var _objGetOwnProps = Obj["getOwnPropertyNames"];
121
120
  var _dynamicNames = 0;
122
121
  function _hasOwnProperty(obj, prop) {
123
122
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -129,22 +128,25 @@
129
128
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
130
129
  }
131
130
  function _getObjProto$1(target) {
131
+ var newProto;
132
132
  if (target) {
133
133
  if (_objGetPrototypeOf$1) {
134
134
  return _objGetPrototypeOf$1(target);
135
135
  }
136
- var newProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
137
- if (newProto) {
138
- return newProto;
136
+ var curProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
137
+ newProto = target[DynProtoBaseProto] || curProto;
138
+ if (!_hasOwnProperty(target, DynProtoBaseProto)) {
139
+ delete target[DynProtoCurrent];
140
+ newProto = target[DynProtoBaseProto] = target[DynProtoCurrent] || target[DynProtoBaseProto];
141
+ target[DynProtoCurrent] = curProto;
139
142
  }
140
143
  }
141
- return null;
144
+ return newProto;
142
145
  }
143
146
  function _forEachProp(target, func) {
144
147
  var props = [];
145
- var getOwnProps = Obj["getOwnPropertyNames"];
146
- if (getOwnProps) {
147
- props = getOwnProps(target);
148
+ if (_objGetOwnProps) {
149
+ props = _objGetOwnProps(target);
148
150
  }
149
151
  else {
150
152
  for (var name_1 in target) {
@@ -293,8 +295,9 @@
293
295
  visited.push(thisProto);
294
296
  thisProto = _getObjProto$1(thisProto);
295
297
  }
298
+ return false;
296
299
  }
297
- return false;
300
+ return true;
298
301
  }
299
302
  function _getObjName(target, unknownValue) {
300
303
  if (_hasOwnProperty(target, Prototype)) {
@@ -339,22 +342,106 @@
339
342
  };
340
343
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
341
344
 
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";
345
+ var LoggingSeverity;
346
+ (function (LoggingSeverity) {
347
+ LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
348
+ LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
349
+ })(LoggingSeverity || (LoggingSeverity = {}));
350
+ var _InternalMessageId = {
351
+ BrowserDoesNotSupportLocalStorage: 0,
352
+ BrowserCannotReadLocalStorage: 1,
353
+ BrowserCannotReadSessionStorage: 2,
354
+ BrowserCannotWriteLocalStorage: 3,
355
+ BrowserCannotWriteSessionStorage: 4,
356
+ BrowserFailedRemovalFromLocalStorage: 5,
357
+ BrowserFailedRemovalFromSessionStorage: 6,
358
+ CannotSendEmptyTelemetry: 7,
359
+ ClientPerformanceMathError: 8,
360
+ ErrorParsingAISessionCookie: 9,
361
+ ErrorPVCalc: 10,
362
+ ExceptionWhileLoggingError: 11,
363
+ FailedAddingTelemetryToBuffer: 12,
364
+ FailedMonitorAjaxAbort: 13,
365
+ FailedMonitorAjaxDur: 14,
366
+ FailedMonitorAjaxOpen: 15,
367
+ FailedMonitorAjaxRSC: 16,
368
+ FailedMonitorAjaxSend: 17,
369
+ FailedMonitorAjaxGetCorrelationHeader: 18,
370
+ FailedToAddHandlerForOnBeforeUnload: 19,
371
+ FailedToSendQueuedTelemetry: 20,
372
+ FailedToReportDataLoss: 21,
373
+ FlushFailed: 22,
374
+ MessageLimitPerPVExceeded: 23,
375
+ MissingRequiredFieldSpecification: 24,
376
+ NavigationTimingNotSupported: 25,
377
+ OnError: 26,
378
+ SessionRenewalDateIsZero: 27,
379
+ SenderNotInitialized: 28,
380
+ StartTrackEventFailed: 29,
381
+ StopTrackEventFailed: 30,
382
+ StartTrackFailed: 31,
383
+ StopTrackFailed: 32,
384
+ TelemetrySampledAndNotSent: 33,
385
+ TrackEventFailed: 34,
386
+ TrackExceptionFailed: 35,
387
+ TrackMetricFailed: 36,
388
+ TrackPVFailed: 37,
389
+ TrackPVFailedCalc: 38,
390
+ TrackTraceFailed: 39,
391
+ TransmissionFailed: 40,
392
+ FailedToSetStorageBuffer: 41,
393
+ FailedToRestoreStorageBuffer: 42,
394
+ InvalidBackendResponse: 43,
395
+ FailedToFixDepricatedValues: 44,
396
+ InvalidDurationValue: 45,
397
+ TelemetryEnvelopeInvalid: 46,
398
+ CreateEnvelopeError: 47,
399
+ CannotSerializeObject: 48,
400
+ CannotSerializeObjectNonSerializable: 49,
401
+ CircularReferenceDetected: 50,
402
+ ClearAuthContextFailed: 51,
403
+ ExceptionTruncated: 52,
404
+ IllegalCharsInName: 53,
405
+ ItemNotInArray: 54,
406
+ MaxAjaxPerPVExceeded: 55,
407
+ MessageTruncated: 56,
408
+ NameTooLong: 57,
409
+ SampleRateOutOfRange: 58,
410
+ SetAuthContextFailed: 59,
411
+ SetAuthContextFailedAccountName: 60,
412
+ StringValueTooLong: 61,
413
+ StartCalledMoreThanOnce: 62,
414
+ StopCalledWithoutStart: 63,
415
+ TelemetryInitializerFailed: 64,
416
+ TrackArgumentsNotSpecified: 65,
417
+ UrlTooLong: 66,
418
+ SessionStorageBufferFull: 67,
419
+ CannotAccessCookie: 68,
420
+ IdTooLong: 69,
421
+ InvalidEvent: 70,
422
+ FailedMonitorAjaxSetRequestHeader: 71,
423
+ SendBrowserInfoOnUserInit: 72,
424
+ PluginException: 73,
425
+ NotificationException: 74,
426
+ SnippetScriptLoadFailure: 99,
427
+ InvalidInstrumentationKey: 100,
428
+ CannotParseAiBlobValue: 101,
429
+ InvalidContentBlob: 102,
430
+ TrackPageActionEventFailed: 103,
431
+ FailedAddingCustomDefinedRequestContext: 104,
432
+ InMemoryStorageBufferFull: 105
433
+ };
350
434
 
435
+ var strOnPrefix = "on";
436
+ var strAttachEvent = "attachEvent";
437
+ var strAddEventHelper = "addEventListener";
351
438
  var strToISOString = "toISOString";
439
+ var strIndexOf = "indexOf";
352
440
  var cStrTrim = "trim";
353
441
  var strToString = "toString";
354
442
  var str__Proto = "__proto__";
355
443
  var strConstructor = "constructor";
356
- var _objDefineProperty$1 = ObjDefineProperty;
357
- var _objFreeze = ObjClass.freeze;
444
+ var _objDefineProperty = ObjDefineProperty;
358
445
  var _objKeys = ObjClass.keys;
359
446
  var StringProto = String[strShimPrototype];
360
447
  var _strTrim = StringProto[cStrTrim];
@@ -363,7 +450,7 @@
363
450
  var _isArray = Array.isArray;
364
451
  var _objToString = ObjProto[strToString];
365
452
  var _fnToString = ObjHasOwnProperty[strToString];
366
- var _objFunctionString = _fnToString.call(ObjClass);
453
+ _fnToString.call(ObjClass);
367
454
  var rCamelCase = /-([a-z])/g;
368
455
  var rNormalizeInvalid = /([^\w\d_$])/g;
369
456
  var rLeadingNumeric = /^(\d+[\w\d_$])/;
@@ -395,6 +482,25 @@
395
482
  function isFunction(value) {
396
483
  return !!(value && typeof value === strShimFunction);
397
484
  }
485
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
486
+ if (useCapture === void 0) { useCapture = false; }
487
+ var result = false;
488
+ if (!isNullOrUndefined(obj)) {
489
+ try {
490
+ if (!isNullOrUndefined(obj[strAddEventHelper])) {
491
+ obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
492
+ result = true;
493
+ }
494
+ else if (!isNullOrUndefined(obj[strAttachEvent])) {
495
+ obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
496
+ result = true;
497
+ }
498
+ }
499
+ catch (e) {
500
+ }
501
+ }
502
+ return result;
503
+ }
398
504
  function normalizeJsName(name) {
399
505
  var value = name;
400
506
  if (value && isString(value)) {
@@ -433,25 +539,6 @@
433
539
  function isNumber(value) {
434
540
  return typeof value === "number";
435
541
  }
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
542
  function toISOString(date) {
456
543
  if (date) {
457
544
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -490,6 +577,25 @@
490
577
  catch (e) {
491
578
  }
492
579
  }
580
+ function arrIndexOf(arr, searchElement, fromIndex) {
581
+ if (arr) {
582
+ if (arr[strIndexOf]) {
583
+ return arr[strIndexOf](searchElement, fromIndex);
584
+ }
585
+ var len = arr.length;
586
+ var from = fromIndex || 0;
587
+ try {
588
+ for (var lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
589
+ if (lp in arr && arr[lp] === searchElement) {
590
+ return lp;
591
+ }
592
+ }
593
+ }
594
+ catch (e) {
595
+ }
596
+ }
597
+ return -1;
598
+ }
493
599
  function strTrim(str) {
494
600
  if (str) {
495
601
  str = (_strTrim && str[cStrTrim]) ? str[cStrTrim]() : (str.replace ? str.replace(/^\s+|\s+$/g, "") : str);
@@ -531,7 +637,7 @@
531
637
  return result;
532
638
  }
533
639
  function objDefineAccessors(target, prop, getProp, setProp) {
534
- if (_objDefineProperty$1) {
640
+ if (_objDefineProperty) {
535
641
  try {
536
642
  var descriptor = {
537
643
  enumerable: true,
@@ -543,7 +649,7 @@
543
649
  if (setProp) {
544
650
  descriptor.set = setProp;
545
651
  }
546
- _objDefineProperty$1(target, prop, descriptor);
652
+ _objDefineProperty(target, prop, descriptor);
547
653
  return true;
548
654
  }
549
655
  catch (e) {
@@ -551,10 +657,6 @@
551
657
  }
552
658
  return false;
553
659
  }
554
- function _doNothing(value) {
555
- return value;
556
- }
557
- var objFreeze = _objFreeze || _doNothing;
558
660
  function dateNow() {
559
661
  var dt = Date;
560
662
  return dt.now ? dt.now() : new dt().getTime();
@@ -570,91 +672,6 @@
570
672
  }
571
673
  return theValue;
572
674
  }
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
675
 
659
676
  var strWindow = "window";
660
677
  var strDocument = "document";
@@ -668,7 +685,6 @@
668
685
  var strMsCrypto = "msCrypto";
669
686
  var strMsie = "msie";
670
687
  var strTrident = "trident/";
671
- var strXMLHttpRequest = "XMLHttpRequest";
672
688
  var _isTrident = null;
673
689
  var _navUserAgentCheck = null;
674
690
  var _enableMocks = false;
@@ -743,7 +759,7 @@
743
759
  var nav = getNavigator();
744
760
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
745
761
  _navUserAgentCheck = nav.userAgent;
746
- var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
762
+ var userAgent = (_navUserAgentCheck || "").toLowerCase();
747
763
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
748
764
  }
749
765
  return _isTrident;
@@ -752,9 +768,9 @@
752
768
  if (userAgentStr === void 0) { userAgentStr = null; }
753
769
  if (!userAgentStr) {
754
770
  var navigator_1 = getNavigator() || {};
755
- userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
771
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
756
772
  }
757
- var ua = (userAgentStr || strEmpty$1).toLowerCase();
773
+ var ua = (userAgentStr || "").toLowerCase();
758
774
  if (strContains(ua, strMsie)) {
759
775
  var doc = getDocument() || {};
760
776
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -769,7 +785,7 @@
769
785
  }
770
786
  function dumpObj(object) {
771
787
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
772
- var propertyValueDump = strEmpty$1;
788
+ var propertyValueDump = "";
773
789
  if (objectTypeDump === "[object Error]") {
774
790
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
775
791
  }
@@ -781,7 +797,7 @@
781
797
  function isXhrSupported() {
782
798
  var isSupported = false;
783
799
  try {
784
- var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
800
+ var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
785
801
  isSupported = !!xmlHttpRequest;
786
802
  }
787
803
  catch (e) {
@@ -812,9 +828,9 @@
812
828
  var strWarnToConsole = "warnToConsole";
813
829
  function _sanitizeDiagnosticText(text) {
814
830
  if (text) {
815
- return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
831
+ return "\"" + text.replace(/\"/g, "") + "\"";
816
832
  }
817
- return strEmpty$1;
833
+ return "";
818
834
  }
819
835
  function _logToConsole(func, message) {
820
836
  var theConsole = getConsole();
@@ -836,12 +852,12 @@
836
852
  _self.message =
837
853
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
838
854
  msgId;
839
- var strProps = strEmpty$1;
855
+ var strProps = "";
840
856
  if (hasJSON()) {
841
857
  strProps = getJSON().stringify(properties);
842
858
  }
843
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
844
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
859
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
860
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
845
861
  _self.message += diagnosticText;
846
862
  }
847
863
  _InternalLogMessage.dataType = "MessageData";
@@ -868,10 +884,10 @@
868
884
  if (isUserAct === void 0) { isUserAct = false; }
869
885
  var message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
870
886
  if (_self.enableDebugExceptions()) {
871
- throw message;
887
+ throw dumpObj(message);
872
888
  }
873
889
  else {
874
- var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
890
+ var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
875
891
  if (!isUndefined(message.message)) {
876
892
  var logLevel = _self.consoleLoggingLevel();
877
893
  if (isUserAct) {
@@ -889,7 +905,7 @@
889
905
  _self.logInternalMessage(severity, message);
890
906
  }
891
907
  else {
892
- _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
908
+ _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
893
909
  }
894
910
  }
895
911
  };
@@ -921,13 +937,13 @@
921
937
  if (severity <= _self.telemetryLoggingLevel()) {
922
938
  _self.queue.push(message);
923
939
  _messageCount++;
924
- _debugExtMsg((severity === 1 ? "error" : "warn"), message);
940
+ _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
925
941
  }
926
942
  if (_messageCount === _self.maxInternalMessageLimit()) {
927
943
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
928
- var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
944
+ var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
929
945
  _self.queue.push(throttleMessage);
930
- if (severity === 1 ) {
946
+ if (severity === LoggingSeverity.CRITICAL) {
931
947
  _self.errorToConsole(throttleLimitMessage);
932
948
  }
933
949
  else {
@@ -956,10 +972,6 @@
956
972
  }
957
973
  return DiagnosticLogger;
958
974
  }());
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
975
 
964
976
  var strExecutionContextKey = "ctx";
965
977
  var PerfEvent = /** @class */ (function () {
@@ -1073,616 +1085,207 @@
1073
1085
  return func();
1074
1086
  }
1075
1087
 
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.2204-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
- }
1088
+ var TelemetryPluginChain = /** @class */ (function () {
1089
+ function TelemetryPluginChain(plugin, defItemCtx) {
1090
+ var _self = this;
1091
+ var _nextProxy = null;
1092
+ var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1093
+ var _hasSetNext = isFunction(plugin.setNextPlugin);
1094
+ _self._hasRun = false;
1095
+ _self.getPlugin = function () {
1096
+ return plugin;
1097
+ };
1098
+ _self.getNext = function () {
1099
+ return _nextProxy;
1100
+ };
1101
+ _self.setNext = function (nextPlugin) {
1102
+ _nextProxy = nextPlugin;
1103
+ };
1104
+ _self.processTelemetry = function (env, itemCtx) {
1105
+ if (!itemCtx) {
1106
+ itemCtx = defItemCtx;
1210
1107
  }
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) {
1108
+ var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1109
+ doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1110
+ if (plugin && _hasProcessTelemetry) {
1111
+ _self._hasRun = true;
1287
1112
  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));
1113
+ itemCtx.setNext(_nextProxy);
1114
+ if (_hasSetNext) {
1115
+ plugin.setNextPlugin(_nextProxy);
1116
+ }
1117
+ _nextProxy && (_nextProxy._hasRun = false);
1118
+ plugin.processTelemetry(env, itemCtx);
1292
1119
  }
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
- }
1120
+ catch (error) {
1121
+ var hasRun = _nextProxy && _nextProxy._hasRun;
1122
+ if (!_nextProxy || !hasRun) {
1123
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1322
1124
  }
1323
- });
1125
+ if (_nextProxy && !hasRun) {
1126
+ _nextProxy.processTelemetry(env, itemCtx);
1127
+ }
1128
+ }
1324
1129
  }
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;
1130
+ else if (_nextProxy) {
1131
+ _self._hasRun = true;
1132
+ _nextProxy.processTelemetry(env, itemCtx);
1133
+ }
1134
+ }, function () { return ({ item: env }); }, !(env.sync));
1135
+ };
1340
1136
  }
1341
- function _iterateChain(cb) {
1342
- var nextPlugin;
1343
- while (!!(nextPlugin = context._next())) {
1344
- var plugin = nextPlugin.getPlugin();
1345
- if (plugin) {
1346
- cb(plugin);
1137
+ return TelemetryPluginChain;
1138
+ }());
1139
+
1140
+ function _createProxyChain(plugins, itemCtx) {
1141
+ var proxies = [];
1142
+ if (plugins && plugins.length > 0) {
1143
+ var lastProxy = null;
1144
+ for (var idx = 0; idx < plugins.length; idx++) {
1145
+ var thePlugin = plugins[idx];
1146
+ if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1147
+ var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1148
+ proxies.push(newProxy);
1149
+ if (lastProxy) {
1150
+ lastProxy.setNext(newProxy);
1151
+ }
1152
+ lastProxy = newProxy;
1347
1153
  }
1348
1154
  }
1349
1155
  }
1350
- return context;
1156
+ return proxies.length > 0 ? proxies[0] : null;
1351
1157
  }
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);
1158
+ function _copyProxyChain(proxy, itemCtx, startAt) {
1159
+ var plugins = [];
1160
+ var add = startAt ? false : true;
1161
+ if (proxy) {
1162
+ while (proxy) {
1163
+ var thePlugin = proxy.getPlugin();
1164
+ if (add || thePlugin === startAt) {
1165
+ add = true;
1166
+ plugins.push(thePlugin);
1167
+ }
1168
+ proxy = proxy.getNext();
1364
1169
  }
1365
- return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1366
1170
  }
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
- }
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);
1171
+ if (!add) {
1172
+ plugins.push(startAt);
1385
1173
  }
1386
- context.processNext = _processNext;
1387
- context.createNew = _createNew;
1388
- return context;
1174
+ return _createProxyChain(plugins, itemCtx);
1389
1175
  }
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);
1176
+ function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1177
+ var plugins = srcPlugins;
1178
+ var add = false;
1179
+ if (startAt && srcPlugins) {
1180
+ plugins = [];
1181
+ arrForEach(srcPlugins, function (thePlugin) {
1182
+ if (add || thePlugin === startAt) {
1183
+ add = true;
1184
+ plugins.push(thePlugin);
1397
1185
  }
1398
1186
  });
1399
1187
  }
1400
- function _createNew(plugins, startAt) {
1401
- if (plugins === void 0) { plugins = null; }
1402
- if (isArray(plugins)) {
1403
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1188
+ if (startAt && !add) {
1189
+ if (!plugins) {
1190
+ plugins = [];
1404
1191
  }
1405
- return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1192
+ plugins.push(startAt);
1406
1193
  }
1407
- context.processNext = _processNext;
1408
- context.createNew = _createNew;
1409
- return context;
1194
+ return _createProxyChain(plugins, itemCtx);
1410
1195
  }
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;
1196
+ var ProcessTelemetryContext = /** @class */ (function () {
1197
+ function ProcessTelemetryContext(plugins, config, core, startAt) {
1198
+ var _self = this;
1199
+ var _nextProxy = null;
1200
+ if (startAt !== null) {
1201
+ if (plugins && isFunction(plugins.getPlugin)) {
1202
+ _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1419
1203
  }
1420
- if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1421
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1422
- if (!firstProxy) {
1423
- firstProxy = newProxy;
1204
+ else {
1205
+ if (startAt) {
1206
+ _nextProxy = _copyPluginChain(plugins, _self, startAt);
1424
1207
  }
1425
- if (lastProxy_1) {
1426
- lastProxy_1._setNext(newProxy);
1208
+ else if (isUndefined(startAt)) {
1209
+ _nextProxy = _createProxyChain(plugins, _self);
1427
1210
  }
1428
- lastProxy_1 = newProxy;
1429
1211
  }
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
1212
  }
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
- }
1213
+ _self.core = function () {
1214
+ return core;
1215
+ };
1216
+ _self.diagLog = function () {
1217
+ return safeGetLogger(core, config);
1218
+ };
1219
+ _self.getCfg = function () {
1220
+ return config;
1221
+ };
1222
+ _self.getExtCfg = function (identifier, defaultValue) {
1223
+ if (defaultValue === void 0) { defaultValue = {}; }
1224
+ var theConfig;
1225
+ if (config) {
1226
+ var extConfig = config.extensionConfig;
1227
+ if (extConfig && identifier) {
1228
+ theConfig = extConfig[identifier];
1499
1229
  }
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
- }
1510
- var pluginState = _getPluginState(plugin);
1511
- if (pluginState[strTeardown] || pluginState[strDisabled]) {
1512
- return false;
1513
1230
  }
1514
- if (hasSetNext) {
1515
- plugin.setNextPlugin(nextProxy);
1231
+ return (theConfig ? theConfig : defaultValue);
1232
+ };
1233
+ _self.getConfig = function (identifier, field, defaultValue) {
1234
+ if (defaultValue === void 0) { defaultValue = false; }
1235
+ var theValue;
1236
+ var extConfig = _self.getExtCfg(identifier, null);
1237
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1238
+ theValue = extConfig[field];
1516
1239
  }
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
- }
1240
+ else if (config && !isNullOrUndefined(config[field])) {
1241
+ theValue = config[field];
1538
1242
  }
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
- }
1243
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1244
+ };
1245
+ _self.hasNext = function () {
1246
+ return _nextProxy != null;
1247
+ };
1248
+ _self.getNext = function () {
1249
+ return _nextProxy;
1250
+ };
1251
+ _self.setNext = function (nextPlugin) {
1252
+ _nextProxy = nextPlugin;
1253
+ };
1254
+ _self.processNext = function (env) {
1255
+ var nextPlugin = _nextProxy;
1256
+ if (nextPlugin) {
1257
+ _nextProxy = nextPlugin.getNext();
1258
+ nextPlugin.processTelemetry(env, _self);
1556
1259
  }
1557
- return hasRun;
1558
- }
1559
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1560
- updateCtx.processNext(updateState);
1561
- }
1260
+ };
1261
+ _self.createNew = function (plugins, startAt) {
1262
+ if (plugins === void 0) { plugins = null; }
1263
+ return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1264
+ };
1562
1265
  }
1563
- return objFreeze(proxyChain);
1564
- }
1266
+ return ProcessTelemetryContext;
1267
+ }());
1565
1268
 
1566
1269
  var strExtensionConfig = "extensionConfig";
1567
1270
 
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
1271
  var strGetPlugin = "getPlugin";
1593
1272
  var BaseTelemetryPlugin = /** @class */ (function () {
1594
1273
  function BaseTelemetryPlugin() {
1595
1274
  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
- });
1275
+ var _isinitialized = false;
1276
+ var _rootCtx = null;
1277
+ var _nextPlugin = null;
1278
+ _self.core = null;
1676
1279
  _self.diagLog = function (itemCtx) {
1677
- return _getTelCtx(itemCtx).diagLog();
1280
+ return _self._getTelCtx(itemCtx).diagLog();
1678
1281
  };
1679
- _self[strIsInitialized] = function () {
1282
+ _self.isInitialized = function () {
1680
1283
  return _isinitialized;
1681
1284
  };
1682
1285
  _self.setInitialized = function (isInitialized) {
1683
1286
  _isinitialized = isInitialized;
1684
1287
  };
1685
- _self[strSetNextPlugin] = function (next) {
1288
+ _self.setNextPlugin = function (next) {
1686
1289
  _nextPlugin = next;
1687
1290
  };
1688
1291
  _self.processNext = function (env, itemCtx) {
@@ -1693,12 +1296,11 @@
1693
1296
  _nextPlugin.processTelemetry(env, null);
1694
1297
  }
1695
1298
  };
1696
- _self._getTelCtx = _getTelCtx;
1697
- function _getTelCtx(currentCtx) {
1299
+ _self._getTelCtx = function (currentCtx) {
1698
1300
  if (currentCtx === void 0) { currentCtx = null; }
1699
1301
  var itemCtx = currentCtx;
1700
1302
  if (!itemCtx) {
1701
- var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1303
+ var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1702
1304
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1703
1305
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1704
1306
  }
@@ -1707,8 +1309,8 @@
1707
1309
  }
1708
1310
  }
1709
1311
  return itemCtx;
1710
- }
1711
- function _setDefaults(config, core, pluginChain) {
1312
+ };
1313
+ _self._baseTelInit = function (config, core, extensions, pluginChain) {
1712
1314
  if (config) {
1713
1315
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1714
1316
  }
@@ -1720,133 +1322,70 @@
1720
1322
  nextPlugin = _nextPlugin[strGetPlugin]();
1721
1323
  }
1722
1324
  _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
- }
1325
+ _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1326
+ _isinitialized = true;
1327
+ };
1733
1328
  }
1329
+ BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1330
+ this._baseTelInit(config, core, extensions, pluginChain);
1331
+ };
1734
1332
  return BaseTelemetryPlugin;
1735
1333
  }());
1736
1334
 
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
- }
1335
+ var UInt32Mask = 0x100000000;
1336
+ var MaxUInt32 = 0xffffffff;
1337
+ var _mwcSeeded = false;
1338
+ var _mwcW = 123456789;
1339
+ var _mwcZ = 987654321;
1340
+ function _mwcSeed(seedValue) {
1341
+ if (seedValue < 0) {
1342
+ seedValue >>>= 0;
1778
1343
  }
1779
- var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1780
- return {
1781
- type: parsedEvent[1],
1782
- ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1783
- };
1344
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1345
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1346
+ _mwcSeeded = true;
1784
1347
  }
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] = [];
1348
+ function _autoSeedMwc() {
1349
+ try {
1350
+ var now = dateNow() & 0x7fffffff;
1351
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1791
1352
  }
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
- }
1353
+ catch (e) {
1805
1354
  }
1806
- return result;
1807
1355
  }
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];
1356
+ function random32(signed) {
1357
+ var value;
1358
+ var c = getCrypto() || getMsCrypto();
1359
+ if (c && c.getRandomValues) {
1360
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1361
+ }
1362
+ else if (isIE()) {
1363
+ if (!_mwcSeeded) {
1364
+ _autoSeedMwc();
1816
1365
  }
1817
- newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1366
+ value = mwcRandom32() & MaxUInt32;
1818
1367
  }
1819
1368
  else {
1820
- newNamespaces = theNamespace;
1369
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1821
1370
  }
1822
- return newNamespaces;
1371
+ if (!signed) {
1372
+ value >>>= 0;
1373
+ }
1374
+ return value;
1823
1375
  }
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
- }
1376
+ function mwcRandom32(signed) {
1377
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1378
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1379
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1380
+ if (!signed) {
1381
+ value >>>= 0;
1843
1382
  }
1844
- return result;
1383
+ return value;
1845
1384
  }
1846
1385
 
1847
1386
  function generateW3CId() {
1848
1387
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
1849
- var oct = strEmpty$1, tmp;
1388
+ var oct = "", tmp;
1850
1389
  for (var a = 0; a < 4; a++) {
1851
1390
  tmp = random32();
1852
1391
  oct +=
@@ -1863,95 +1402,6 @@
1863
1402
  return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
1864
1403
  }
1865
1404
 
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
1405
  var aiInstrumentHooks = "_aiHooks";
1956
1406
  var cbNames = [
1957
1407
  "req", "rsp", "hkErr", "fnErr"
@@ -2010,7 +1460,6 @@
2010
1460
  };
2011
1461
  var hookCtx = [];
2012
1462
  var cbArgs = _createArgs([funcArgs], orgArgs);
2013
- funcArgs.evt = getGlobalInst("event");
2014
1463
  function _createArgs(target, theArgs) {
2015
1464
  _arrLoop(theArgs, function (arg) {
2016
1465
  target.push(arg);
@@ -2127,7 +1576,7 @@
2127
1576
  name = strTrim(name.toString());
2128
1577
  if (name.length > 150 ) {
2129
1578
  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);
1579
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2131
1580
  }
2132
1581
  }
2133
1582
  return nameTrunc || name;
@@ -2140,7 +1589,7 @@
2140
1589
  value = strTrim(value);
2141
1590
  if (value.toString().length > maxLength) {
2142
1591
  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);
1592
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2144
1593
  }
2145
1594
  }
2146
1595
  return valueTrunc || value;
@@ -2157,7 +1606,7 @@
2157
1606
  value = getJSON().stringify(value);
2158
1607
  }
2159
1608
  catch (e) {
2160
- _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
1609
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2161
1610
  }
2162
1611
  }
2163
1612
  value = dataSanitizeString(logger, value, 8192 );
@@ -2185,7 +1634,7 @@
2185
1634
  input = strTrim(input);
2186
1635
  if (input.length > maxLength) {
2187
1636
  inputTrunc = input.substring(0, maxLength);
2188
- _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
1637
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2189
1638
  }
2190
1639
  }
2191
1640
  return inputTrunc || input;
@@ -2195,28 +1644,39 @@
2195
1644
  return s.substr(s.length - 3);
2196
1645
  }
2197
1646
 
2198
- var strEmpty = "";
2199
1647
  function msToTimeSpan(totalms) {
2200
1648
  if (isNaN(totalms) || totalms < 0) {
2201
1649
  totalms = 0;
2202
1650
  }
2203
1651
  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;
1652
+ var ms = "" + totalms % 1000;
1653
+ var sec = "" + Math.floor(totalms / 1000) % 60;
1654
+ var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
1655
+ var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
2208
1656
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
2209
1657
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
2210
1658
  sec = sec.length < 2 ? "0" + sec : sec;
2211
1659
  min = min.length < 2 ? "0" + min : min;
2212
1660
  hour = hour.length < 2 ? "0" + hour : hour;
2213
- return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
1661
+ return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
2214
1662
  }
2215
1663
 
2216
1664
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2217
1665
  var strNotSpecified = "not_specified";
2218
1666
  var strIkey = "iKey";
2219
1667
 
1668
+ var StorageType;
1669
+ (function (StorageType) {
1670
+ StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
1671
+ StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
1672
+ })(StorageType || (StorageType = {}));
1673
+ var DistributedTracingModes;
1674
+ (function (DistributedTracingModes) {
1675
+ DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
1676
+ DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
1677
+ DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
1678
+ })(DistributedTracingModes || (DistributedTracingModes = {}));
1679
+
2220
1680
  var _document = getDocument() || {};
2221
1681
  var _htmlAnchorIdx = 0;
2222
1682
  var _htmlAnchorElement = [null, null, null, null, null];
@@ -2290,7 +1750,7 @@
2290
1750
  "https://dc-int.services.visualstudio.com/v2/track"
2291
1751
  ];
2292
1752
  function isInternalApplicationInsightsEndpoint(endpointUrl) {
2293
- return _internalEndpoints.indexOf(endpointUrl.toLowerCase()) !== -1;
1753
+ return arrIndexOf(_internalEndpoints, endpointUrl.toLowerCase()) !== -1;
2294
1754
  }
2295
1755
  var CorrelationIdHelper = {
2296
1756
  correlationIdPrefix: "cid-v1:",
@@ -2746,7 +2206,6 @@
2746
2206
  var strAjaxData = "ajaxData";
2747
2207
  var strThrowInternal = "throwInternal";
2748
2208
  var strFetch = "fetch";
2749
- var strTrackDependencyDataInternal = "trackDependencyDataInternal";
2750
2209
  var _markCount = 0;
2751
2210
  function _supportsFetch() {
2752
2211
  var _global = getGlobal();
@@ -2826,41 +2285,80 @@
2826
2285
  var _this = _super.call(this) || this;
2827
2286
  _this.identifier = AjaxMonitor.identifier;
2828
2287
  _this.priority = 120;
2829
- var _fetchInitialized;
2830
- var _xhrInitialized;
2831
- var _currentWindowHost;
2832
- var _config;
2833
- var _enableRequestHeaderTracking;
2834
- var _enableAjaxErrorStatusText;
2835
- var _trackAjaxAttempts;
2288
+ var strTrackDependencyDataInternal = "trackDependencyDataInternal";
2289
+ var location = getLocation();
2290
+ var _fetchInitialized = false;
2291
+ var _xhrInitialized = false;
2292
+ var _currentWindowHost = location && location.host && location.host.toLowerCase();
2293
+ var _config = AjaxMonitor.getEmptyConfig();
2294
+ var _enableRequestHeaderTracking = false;
2295
+ var _enableAjaxErrorStatusText = false;
2296
+ var _trackAjaxAttempts = 0;
2836
2297
  var _context;
2837
2298
  var _isUsingW3CHeaders;
2838
2299
  var _isUsingAIHeaders;
2839
2300
  var _markPrefix;
2840
- var _enableAjaxPerfTracking;
2841
- var _maxAjaxCallsPerView;
2842
- var _enableResponseHeaderTracking;
2843
- var _disabledUrls;
2844
- var _disableAjaxTracking;
2845
- var _disableFetchTracking;
2301
+ var _enableAjaxPerfTracking = false;
2302
+ var _maxAjaxCallsPerView = 0;
2303
+ var _enableResponseHeaderTracking = false;
2304
+ var _hooks = [];
2305
+ var _disabledUrls = {};
2846
2306
  var _excludeRequestFromAutoTrackingPatterns;
2847
2307
  var _addRequestContext;
2848
- var _evtNamespace;
2849
- dynamicProto(AjaxMonitor, _this, function (_self, _base) {
2850
- var _addHook = _base._addHook;
2851
- _initDefaults();
2308
+ dynamicProto(AjaxMonitor, _this, function (_self, base) {
2852
2309
  _self.initialize = function (config, core, extensions, pluginChain) {
2853
2310
  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();
2311
+ base.initialize(config, core, extensions, pluginChain);
2312
+ var ctx_1 = _self._getTelCtx();
2313
+ var defaultConfig = AjaxMonitor.getDefaultConfig();
2314
+ objForEachKey(defaultConfig, function (field, value) {
2315
+ _config[field] = ctx_1.getConfig(AjaxMonitor.identifier, field, value);
2316
+ });
2317
+ var distributedTracingMode = _config.distributedTracingMode;
2318
+ _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
2319
+ _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
2320
+ _enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
2321
+ _maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
2322
+ _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
2323
+ _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
2324
+ _addRequestContext = _config.addRequestContext;
2325
+ _isUsingAIHeaders = distributedTracingMode === DistributedTracingModes.AI || distributedTracingMode === DistributedTracingModes.AI_AND_W3C;
2326
+ _isUsingW3CHeaders = distributedTracingMode === DistributedTracingModes.AI_AND_W3C || distributedTracingMode === DistributedTracingModes.W3C;
2327
+ if (_enableAjaxPerfTracking) {
2328
+ var iKey = config.instrumentationKey || "unkwn";
2329
+ if (iKey.length > 5) {
2330
+ _markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
2331
+ }
2332
+ else {
2333
+ _markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
2334
+ }
2335
+ }
2336
+ if (_config.disableAjaxTracking === false) {
2337
+ _instrumentXhr();
2338
+ }
2858
2339
  _instrumentFetch();
2859
- _populateContext();
2340
+ if (extensions.length > 0 && extensions) {
2341
+ var propExt = void 0, extIx = 0;
2342
+ while (!propExt && extIx < extensions.length) {
2343
+ if (extensions[extIx] && extensions[extIx].identifier === PropertiesPluginIdentifier) {
2344
+ propExt = extensions[extIx];
2345
+ }
2346
+ extIx++;
2347
+ }
2348
+ if (propExt) {
2349
+ _context = propExt.context;
2350
+ }
2351
+ }
2860
2352
  }
2861
2353
  };
2862
- _self._doTeardown = function () {
2863
- _initDefaults();
2354
+ _self.teardown = function () {
2355
+ arrForEach(_hooks, function (fn) {
2356
+ fn.rm();
2357
+ });
2358
+ _hooks = [];
2359
+ _fetchInitialized = false;
2360
+ _xhrInitialized = false;
2361
+ _self.setInitialized(false);
2864
2362
  };
2865
2363
  _self.trackDependencyData = function (dependency, properties) {
2866
2364
  _self[strTrackDependencyDataInternal](dependency, properties);
@@ -2927,8 +2425,8 @@
2927
2425
  };
2928
2426
  _self[strTrackDependencyDataInternal] = function (dependency, properties, systemProperties) {
2929
2427
  if (_maxAjaxCallsPerView === -1 || _trackAjaxAttempts < _maxAjaxCallsPerView) {
2930
- if ((_config.distributedTracingMode === 2
2931
- || _config.distributedTracingMode === 1 )
2428
+ if ((_config.distributedTracingMode === DistributedTracingModes.W3C
2429
+ || _config.distributedTracingMode === DistributedTracingModes.AI_AND_W3C)
2932
2430
  && typeof dependency.id === "string" && dependency.id[dependency.id.length - 1] !== ".") {
2933
2431
  dependency.id += ".";
2934
2432
  }
@@ -2943,64 +2441,6 @@
2943
2441
  }
2944
2442
  ++_trackAjaxAttempts;
2945
2443
  };
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
2444
  function _canIncludeHeaders(header) {
3005
2445
  var rlt = true;
3006
2446
  if (header || _config.ignoreHeaders) {
@@ -3020,12 +2460,11 @@
3020
2460
  }
3021
2461
  var global = getGlobal();
3022
2462
  var isPolyfill = fetch.polyfill;
3023
- if (!_disableFetchTracking && !_fetchInitialized) {
3024
- _addHook(InstrumentFunc(global, strFetch, {
3025
- ns: _evtNamespace,
2463
+ if (_config.disableFetchTracking === false) {
2464
+ _hooks.push(InstrumentFunc(global, strFetch, {
3026
2465
  req: function (callDetails, input, init) {
3027
2466
  var fetchData;
3028
- if (!_disableFetchTracking && _fetchInitialized &&
2467
+ if (_fetchInitialized &&
3029
2468
  !_isDisabledRequest(null, input, init) &&
3030
2469
  !(isPolyfill && _xhrInitialized)) {
3031
2470
  var ctx = callDetails.ctx();
@@ -3038,33 +2477,31 @@
3038
2477
  }
3039
2478
  },
3040
2479
  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;
2480
+ var fetchData = callDetails.ctx().data;
2481
+ if (fetchData) {
2482
+ callDetails.rslt = callDetails.rslt.then(function (response) {
2483
+ _reportFetchMetrics(callDetails, (response || {}).status, input, response, fetchData, function () {
2484
+ var ajaxResponse = {
2485
+ statusText: response.statusText,
2486
+ headerMap: null,
2487
+ correlationContext: _getFetchCorrelationContext(response)
2488
+ };
2489
+ if (_enableResponseHeaderTracking) {
2490
+ var responseHeaderMap_1 = {};
2491
+ response.headers.forEach(function (value, name) {
2492
+ if (_canIncludeHeaders(name)) {
2493
+ responseHeaderMap_1[name] = value;
2494
+ }
2495
+ });
2496
+ ajaxResponse.headerMap = responseHeaderMap_1;
2497
+ }
2498
+ return ajaxResponse;
3066
2499
  });
3067
- }
2500
+ return response;
2501
+ })["catch"](function (reason) {
2502
+ _reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message });
2503
+ throw reason;
2504
+ });
3068
2505
  }
3069
2506
  },
3070
2507
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxOpen, "Failed to monitor Window.fetch, monitoring data for this fetch call may be incorrect.")
@@ -3072,8 +2509,7 @@
3072
2509
  _fetchInitialized = true;
3073
2510
  }
3074
2511
  else if (isPolyfill) {
3075
- _addHook(InstrumentFunc(global, strFetch, {
3076
- ns: _evtNamespace,
2512
+ _hooks.push(InstrumentFunc(global, strFetch, {
3077
2513
  req: function (callDetails, input, init) {
3078
2514
  _isDisabledRequest(null, input, init);
3079
2515
  }
@@ -3084,68 +2520,58 @@
3084
2520
  }
3085
2521
  }
3086
2522
  function _hookProto(target, funcName, callbacks) {
3087
- _addHook(InstrumentProto(target, funcName, callbacks));
2523
+ _hooks.push(InstrumentProto(target, funcName, callbacks));
3088
2524
  }
3089
2525
  function _instrumentXhr() {
3090
- if (_supportsAjaxMonitoring(_self) && !_disableAjaxTracking && !_xhrInitialized) {
2526
+ if (_supportsAjaxMonitoring(_self) && !_xhrInitialized) {
3091
2527
  _hookProto(XMLHttpRequest, "open", {
3092
- ns: _evtNamespace,
3093
2528
  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);
2529
+ var xhr = args.inst;
2530
+ var ajaxData = xhr[strAjaxData];
2531
+ if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
2532
+ if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
2533
+ _openHandler(xhr, method, url, async);
3102
2534
  }
2535
+ _attachToOnReadyStateChange(xhr);
3103
2536
  }
3104
2537
  },
3105
2538
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxOpen, "Failed to monitor XMLHttpRequest.open, monitoring data for this ajax call may be incorrect.")
3106
2539
  });
3107
2540
  _hookProto(XMLHttpRequest, "send", {
3108
- ns: _evtNamespace,
3109
2541
  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
- }
2542
+ var xhr = args.inst;
2543
+ var ajaxData = xhr[strAjaxData];
2544
+ if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
2545
+ _createMarkId("xhr", ajaxData);
2546
+ ajaxData.requestSentTime = dateTimeUtilsNow();
2547
+ _self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
2548
+ ajaxData.xhrMonitoringState.sendDone = true;
3119
2549
  }
3120
2550
  },
3121
2551
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSend, "Failed to monitor XMLHttpRequest, monitoring data for this ajax call may be incorrect.")
3122
2552
  });
3123
2553
  _hookProto(XMLHttpRequest, "abort", {
3124
- ns: _evtNamespace,
3125
2554
  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
- }
2555
+ var xhr = args.inst;
2556
+ var ajaxData = xhr[strAjaxData];
2557
+ if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
2558
+ ajaxData.aborted = 1;
2559
+ ajaxData.xhrMonitoringState.abortDone = true;
3133
2560
  }
3134
2561
  },
3135
2562
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxAbort, "Failed to monitor XMLHttpRequest.abort, monitoring data for this ajax call may be incorrect.")
3136
2563
  });
3137
- _hookProto(XMLHttpRequest, "setRequestHeader", {
3138
- ns: _evtNamespace,
3139
- req: function (args, header, value) {
3140
- if (!_disableAjaxTracking && _enableRequestHeaderTracking) {
2564
+ if (_enableRequestHeaderTracking) {
2565
+ _hookProto(XMLHttpRequest, "setRequestHeader", {
2566
+ req: function (args, header, value) {
3141
2567
  var xhr = args.inst;
3142
2568
  if (_isMonitoredXhrInstance(xhr) && _canIncludeHeaders(header)) {
3143
2569
  xhr[strAjaxData].requestHeaders[header] = value;
3144
2570
  }
3145
- }
3146
- },
3147
- hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSetRequestHeader, "Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
3148
- });
2571
+ },
2572
+ hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSetRequestHeader, "Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
2573
+ });
2574
+ }
3149
2575
  _xhrInitialized = true;
3150
2576
  }
3151
2577
  }
@@ -3216,7 +2642,7 @@
3216
2642
  xhr[strAjaxData] = ajaxData;
3217
2643
  }
3218
2644
  function _attachToOnReadyStateChange(xhr) {
3219
- xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", function () {
2645
+ xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = attachEvent(xhr, "readystatechange", function () {
3220
2646
  try {
3221
2647
  if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
3222
2648
  _onAjaxComplete(xhr);
@@ -3231,7 +2657,7 @@
3231
2657
  });
3232
2658
  }
3233
2659
  }
3234
- }, _evtNamespace);
2660
+ });
3235
2661
  }
3236
2662
  function _getResponseText(xhr) {
3237
2663
  try {
@@ -3516,7 +2942,7 @@
3516
2942
  disableFetchTracking: true,
3517
2943
  excludeRequestFromAutoTrackingPatterns: undefined,
3518
2944
  disableCorrelationHeaders: false,
3519
- distributedTracingMode: 1 ,
2945
+ distributedTracingMode: DistributedTracingModes.AI_AND_W3C,
3520
2946
  correlationHeaderExcludedDomains: [
3521
2947
  "*.blob.core.windows.net",
3522
2948
  "*.blob.core.chinacloudapi.cn",