@microsoft/applicationinsights-react-native 2.5.0-beta.2203-01 → 2.5.0-beta.2203-04

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 - React Native Plugin, 2.5.0-beta.2203-01
2
+ * Application Insights JavaScript SDK - React Native Plugin, 2.5.0-beta.2203-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -326,105 +326,26 @@
326
326
  };
327
327
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
328
328
 
329
- var LoggingSeverity;
330
- (function (LoggingSeverity) {
331
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
332
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
333
- })(LoggingSeverity || (LoggingSeverity = {}));
334
- var _InternalMessageId = {
335
- BrowserDoesNotSupportLocalStorage: 0,
336
- BrowserCannotReadLocalStorage: 1,
337
- BrowserCannotReadSessionStorage: 2,
338
- BrowserCannotWriteLocalStorage: 3,
339
- BrowserCannotWriteSessionStorage: 4,
340
- BrowserFailedRemovalFromLocalStorage: 5,
341
- BrowserFailedRemovalFromSessionStorage: 6,
342
- CannotSendEmptyTelemetry: 7,
343
- ClientPerformanceMathError: 8,
344
- ErrorParsingAISessionCookie: 9,
345
- ErrorPVCalc: 10,
346
- ExceptionWhileLoggingError: 11,
347
- FailedAddingTelemetryToBuffer: 12,
348
- FailedMonitorAjaxAbort: 13,
349
- FailedMonitorAjaxDur: 14,
350
- FailedMonitorAjaxOpen: 15,
351
- FailedMonitorAjaxRSC: 16,
352
- FailedMonitorAjaxSend: 17,
353
- FailedMonitorAjaxGetCorrelationHeader: 18,
354
- FailedToAddHandlerForOnBeforeUnload: 19,
355
- FailedToSendQueuedTelemetry: 20,
356
- FailedToReportDataLoss: 21,
357
- FlushFailed: 22,
358
- MessageLimitPerPVExceeded: 23,
359
- MissingRequiredFieldSpecification: 24,
360
- NavigationTimingNotSupported: 25,
361
- OnError: 26,
362
- SessionRenewalDateIsZero: 27,
363
- SenderNotInitialized: 28,
364
- StartTrackEventFailed: 29,
365
- StopTrackEventFailed: 30,
366
- StartTrackFailed: 31,
367
- StopTrackFailed: 32,
368
- TelemetrySampledAndNotSent: 33,
369
- TrackEventFailed: 34,
370
- TrackExceptionFailed: 35,
371
- TrackMetricFailed: 36,
372
- TrackPVFailed: 37,
373
- TrackPVFailedCalc: 38,
374
- TrackTraceFailed: 39,
375
- TransmissionFailed: 40,
376
- FailedToSetStorageBuffer: 41,
377
- FailedToRestoreStorageBuffer: 42,
378
- InvalidBackendResponse: 43,
379
- FailedToFixDepricatedValues: 44,
380
- InvalidDurationValue: 45,
381
- TelemetryEnvelopeInvalid: 46,
382
- CreateEnvelopeError: 47,
383
- CannotSerializeObject: 48,
384
- CannotSerializeObjectNonSerializable: 49,
385
- CircularReferenceDetected: 50,
386
- ClearAuthContextFailed: 51,
387
- ExceptionTruncated: 52,
388
- IllegalCharsInName: 53,
389
- ItemNotInArray: 54,
390
- MaxAjaxPerPVExceeded: 55,
391
- MessageTruncated: 56,
392
- NameTooLong: 57,
393
- SampleRateOutOfRange: 58,
394
- SetAuthContextFailed: 59,
395
- SetAuthContextFailedAccountName: 60,
396
- StringValueTooLong: 61,
397
- StartCalledMoreThanOnce: 62,
398
- StopCalledWithoutStart: 63,
399
- TelemetryInitializerFailed: 64,
400
- TrackArgumentsNotSpecified: 65,
401
- UrlTooLong: 66,
402
- SessionStorageBufferFull: 67,
403
- CannotAccessCookie: 68,
404
- IdTooLong: 69,
405
- InvalidEvent: 70,
406
- FailedMonitorAjaxSetRequestHeader: 71,
407
- SendBrowserInfoOnUserInit: 72,
408
- PluginException: 73,
409
- NotificationException: 74,
410
- SnippetScriptLoadFailure: 99,
411
- InvalidInstrumentationKey: 100,
412
- CannotParseAiBlobValue: 101,
413
- InvalidContentBlob: 102,
414
- TrackPageActionEventFailed: 103,
415
- FailedAddingCustomDefinedRequestContext: 104,
416
- InMemoryStorageBufferFull: 105
417
- };
329
+ var strEmpty = "";
330
+ var strSetNextPlugin = "setNextPlugin";
331
+ var strIsInitialized = "isInitialized";
332
+ var strTeardown = "teardown";
333
+ var strCore = "core";
334
+ var strDisabled = "disabled";
335
+ var strDoTeardown = "_doTeardown";
418
336
 
419
337
  var strToString = "toString";
420
338
  var str__Proto = "__proto__";
421
339
  var strConstructor = "constructor";
422
- var _objDefineProperty = ObjDefineProperty;
340
+ var _objDefineProperty$1 = ObjDefineProperty;
423
341
  var _objFreeze = ObjClass.freeze;
424
342
  var _isArray = Array.isArray;
425
343
  var _objToString = ObjProto[strToString];
426
344
  var _fnToString = ObjHasOwnProperty[strToString];
427
345
  var _objFunctionString = _fnToString.call(ObjClass);
346
+ var rCamelCase = /-([a-z])/g;
347
+ var rNormalizeInvalid = /([^\w\d_$])/g;
348
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
428
349
  var _objGetPrototypeOf = Object["getPrototypeOf"];
429
350
  function _getObjProto(target) {
430
351
  if (target) {
@@ -453,6 +374,19 @@
453
374
  function isFunction(value) {
454
375
  return !!(value && typeof value === strShimFunction);
455
376
  }
377
+ function normalizeJsName(name) {
378
+ var value = name;
379
+ if (value && isString(value)) {
380
+ value = value.replace(rCamelCase, function (_all, letter) {
381
+ return letter.toUpperCase();
382
+ });
383
+ value = value.replace(rNormalizeInvalid, "_");
384
+ value = value.replace(rLeadingNumeric, function (_all, match) {
385
+ return "_" + match;
386
+ });
387
+ }
388
+ return value;
389
+ }
456
390
  function objForEachKey$1(target, callbackfn) {
457
391
  if (target) {
458
392
  for (var prop in target) {
@@ -462,6 +396,12 @@
462
396
  }
463
397
  }
464
398
  }
399
+ function strContains(value, search) {
400
+ if (value && search) {
401
+ return value.indexOf(search) !== -1;
402
+ }
403
+ return false;
404
+ }
465
405
  var isArray = _isArray || _isArrayPoly;
466
406
  function _isArrayPoly(obj) {
467
407
  return !!(obj && _objToString.call(obj) === "[object Array]");
@@ -469,6 +409,9 @@
469
409
  function isError(obj) {
470
410
  return !!(obj && _objToString.call(obj) === "[object Error]");
471
411
  }
412
+ function isString(value) {
413
+ return typeof value === "string";
414
+ }
472
415
  function isBoolean(value) {
473
416
  return typeof value === "boolean";
474
417
  }
@@ -503,7 +446,7 @@
503
446
  }
504
447
  }
505
448
  function objDefineAccessors(target, prop, getProp, setProp) {
506
- if (_objDefineProperty) {
449
+ if (_objDefineProperty$1) {
507
450
  try {
508
451
  var descriptor = {
509
452
  enumerable: true,
@@ -515,7 +458,7 @@
515
458
  if (setProp) {
516
459
  descriptor.set = setProp;
517
460
  }
518
- _objDefineProperty(target, prop, descriptor);
461
+ _objDefineProperty$1(target, prop, descriptor);
519
462
  return true;
520
463
  }
521
464
  catch (e) {
@@ -535,7 +478,7 @@
535
478
  if (isError(object)) {
536
479
  return object.name;
537
480
  }
538
- return "";
481
+ return strEmpty;
539
482
  }
540
483
  function setValue(target, field, value, valChk, srcChk) {
541
484
  var theValue = value;
@@ -548,6 +491,47 @@
548
491
  }
549
492
  return theValue;
550
493
  }
494
+ function throwError(message) {
495
+ throw new Error(message);
496
+ }
497
+ function _createProxyFunction(source, funcName) {
498
+ var srcFunc = null;
499
+ var src = null;
500
+ if (isFunction(source)) {
501
+ srcFunc = source;
502
+ }
503
+ else {
504
+ src = source;
505
+ }
506
+ return function () {
507
+ var originalArguments = arguments;
508
+ if (srcFunc) {
509
+ src = srcFunc();
510
+ }
511
+ if (src) {
512
+ return src[funcName].apply(src, originalArguments);
513
+ }
514
+ };
515
+ }
516
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
517
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
518
+ if (target && name && source) {
519
+ if (overwriteTarget || isUndefined(target[name])) {
520
+ target[name] = _createProxyFunction(source, theFunc);
521
+ }
522
+ }
523
+ }
524
+ function createEnumStyle(values) {
525
+ var enumClass = {};
526
+ objForEachKey$1(values, function (field, value) {
527
+ enumClass[field] = value;
528
+ if (!isUndefined(enumClass[value])) {
529
+ throwError("[" + value + "] exists for " + field);
530
+ }
531
+ enumClass[value] = field;
532
+ });
533
+ return objFreeze(enumClass);
534
+ }
551
535
  function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
552
536
  var theArgs = arguments;
553
537
  var extended = theArgs[0] || {};
@@ -594,8 +578,15 @@
594
578
  }
595
579
 
596
580
  var strWindow = "window";
581
+ var strNavigator = "navigator";
597
582
  var strConsole = "console";
598
583
  var strJSON = "JSON";
584
+ var strCrypto = "crypto";
585
+ var strMsCrypto = "msCrypto";
586
+ var strMsie = "msie";
587
+ var strTrident = "trident/";
588
+ var _isTrident = null;
589
+ var _navUserAgentCheck = null;
599
590
  function getGlobalInst(name) {
600
591
  var gbl = getGlobal();
601
592
  if (gbl && gbl[name]) {
@@ -609,6 +600,15 @@
609
600
  function hasWindow() {
610
601
  return Boolean(typeof window === strShimObject && window);
611
602
  }
603
+ function hasNavigator() {
604
+ return Boolean(typeof navigator === strShimObject && navigator);
605
+ }
606
+ function getNavigator() {
607
+ if (hasNavigator()) {
608
+ return navigator;
609
+ }
610
+ return getGlobalInst(strNavigator);
611
+ }
612
612
  function getConsole() {
613
613
  if (typeof console !== strShimUndefined) {
614
614
  return console;
@@ -624,9 +624,24 @@
624
624
  }
625
625
  return null;
626
626
  }
627
+ function getCrypto() {
628
+ return getGlobalInst(strCrypto);
629
+ }
630
+ function getMsCrypto() {
631
+ return getGlobalInst(strMsCrypto);
632
+ }
633
+ function isIE() {
634
+ var nav = getNavigator();
635
+ if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
636
+ _navUserAgentCheck = nav.userAgent;
637
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
638
+ _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
639
+ }
640
+ return _isTrident;
641
+ }
627
642
  function dumpObj(object) {
628
643
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
629
- var propertyValueDump = "";
644
+ var propertyValueDump = strEmpty;
630
645
  if (objectTypeDump === "[object Error]") {
631
646
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
632
647
  }
@@ -659,9 +674,9 @@
659
674
  var strWarnToConsole = "warnToConsole";
660
675
  function _sanitizeDiagnosticText(text) {
661
676
  if (text) {
662
- return "\"" + text.replace(/\"/g, "") + "\"";
677
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
663
678
  }
664
- return "";
679
+ return strEmpty;
665
680
  }
666
681
  function _logToConsole(func, message) {
667
682
  var theConsole = getConsole();
@@ -683,12 +698,12 @@
683
698
  _self.message =
684
699
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
685
700
  msgId;
686
- var strProps = "";
701
+ var strProps = strEmpty;
687
702
  if (hasJSON()) {
688
703
  strProps = getJSON().stringify(properties);
689
704
  }
690
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
691
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
705
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
706
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
692
707
  _self.message += diagnosticText;
693
708
  }
694
709
  _InternalLogMessage.dataType = "MessageData";
@@ -718,7 +733,7 @@
718
733
  throw message;
719
734
  }
720
735
  else {
721
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
736
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
722
737
  if (!isUndefined(message.message)) {
723
738
  var logLevel = _self.consoleLoggingLevel();
724
739
  if (isUserAct) {
@@ -736,7 +751,7 @@
736
751
  _self.logInternalMessage(severity, message);
737
752
  }
738
753
  else {
739
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
754
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
740
755
  }
741
756
  }
742
757
  };
@@ -768,13 +783,13 @@
768
783
  if (severity <= _self.telemetryLoggingLevel()) {
769
784
  _self.queue.push(message);
770
785
  _messageCount++;
771
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
786
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
772
787
  }
773
788
  if (_messageCount === _self.maxInternalMessageLimit()) {
774
789
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
775
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
790
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
776
791
  _self.queue.push(throttleMessage);
777
- if (severity === LoggingSeverity.CRITICAL) {
792
+ if (severity === 1 ) {
778
793
  _self.errorToConsole(throttleLimitMessage);
779
794
  }
780
795
  else {
@@ -916,6 +931,151 @@
916
931
  return func();
917
932
  }
918
933
 
934
+ var UInt32Mask = 0x100000000;
935
+ var MaxUInt32 = 0xffffffff;
936
+ var _mwcSeeded = false;
937
+ var _mwcW = 123456789;
938
+ var _mwcZ = 987654321;
939
+ function _mwcSeed(seedValue) {
940
+ if (seedValue < 0) {
941
+ seedValue >>>= 0;
942
+ }
943
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
944
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
945
+ _mwcSeeded = true;
946
+ }
947
+ function _autoSeedMwc() {
948
+ try {
949
+ var now = dateNow() & 0x7fffffff;
950
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
951
+ }
952
+ catch (e) {
953
+ }
954
+ }
955
+ function random32(signed) {
956
+ var value = 0;
957
+ var c = getCrypto() || getMsCrypto();
958
+ if (c && c.getRandomValues) {
959
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
960
+ }
961
+ if (value === 0 && isIE()) {
962
+ if (!_mwcSeeded) {
963
+ _autoSeedMwc();
964
+ }
965
+ value = mwcRandom32() & MaxUInt32;
966
+ }
967
+ if (value === 0) {
968
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
969
+ }
970
+ if (!signed) {
971
+ value >>>= 0;
972
+ }
973
+ return value;
974
+ }
975
+ function mwcRandom32(signed) {
976
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
977
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
978
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
979
+ if (!signed) {
980
+ value >>>= 0;
981
+ }
982
+ return value;
983
+ }
984
+ function newId(maxLength) {
985
+ if (maxLength === void 0) { maxLength = 22; }
986
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
987
+ var number = random32() >>> 0;
988
+ var chars = 0;
989
+ var result = strEmpty;
990
+ while (result.length < maxLength) {
991
+ chars++;
992
+ result += base64chars.charAt(number & 0x3F);
993
+ number >>>= 6;
994
+ if (chars === 5) {
995
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
996
+ chars = 0;
997
+ }
998
+ }
999
+ return result;
1000
+ }
1001
+
1002
+ var _objDefineProperty = ObjDefineProperty;
1003
+ var version = "2.7.3";
1004
+ var instanceName = "." + newId(6);
1005
+ var _dataUid = 0;
1006
+ function _createAccessor(target, prop, value) {
1007
+ if (_objDefineProperty) {
1008
+ try {
1009
+ _objDefineProperty(target, prop, {
1010
+ value: value,
1011
+ enumerable: false,
1012
+ configurable: true
1013
+ });
1014
+ return true;
1015
+ }
1016
+ catch (e) {
1017
+ }
1018
+ }
1019
+ return false;
1020
+ }
1021
+ function _canAcceptData(target) {
1022
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1023
+ }
1024
+ function _getCache(data, target) {
1025
+ var theCache = target[data.id];
1026
+ if (!theCache) {
1027
+ theCache = {};
1028
+ try {
1029
+ if (_canAcceptData(target)) {
1030
+ if (!_createAccessor(target, data.id, theCache)) {
1031
+ target[data.id] = theCache;
1032
+ }
1033
+ }
1034
+ }
1035
+ catch (e) {
1036
+ }
1037
+ }
1038
+ return theCache;
1039
+ }
1040
+ function createUniqueNamespace(name, includeVersion) {
1041
+ if (includeVersion === void 0) { includeVersion = false; }
1042
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1043
+ }
1044
+ function createElmNodeData(name) {
1045
+ var data = {
1046
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1047
+ accept: function (target) {
1048
+ return _canAcceptData(target);
1049
+ },
1050
+ get: function (target, name, defValue, addDefault) {
1051
+ var theCache = target[data.id];
1052
+ if (!theCache) {
1053
+ if (addDefault) {
1054
+ theCache = _getCache(data, target);
1055
+ theCache[normalizeJsName(name)] = defValue;
1056
+ }
1057
+ return defValue;
1058
+ }
1059
+ return theCache[normalizeJsName(name)];
1060
+ },
1061
+ kill: function (target, name) {
1062
+ if (target && target[name]) {
1063
+ try {
1064
+ delete target[name];
1065
+ }
1066
+ catch (e) {
1067
+ }
1068
+ }
1069
+ }
1070
+ };
1071
+ return data;
1072
+ }
1073
+
1074
+ var pluginStateData = createElmNodeData("plugin");
1075
+ function _getPluginState(plugin) {
1076
+ return pluginStateData.get(plugin, "state", {}, true);
1077
+ }
1078
+
919
1079
  var strTelemetryPluginChain = "TelemetryPluginChain";
920
1080
  var strHasRunFlags = "_hasRun";
921
1081
  var strGetTelCtx = "_getTelCtx";
@@ -929,53 +1089,69 @@
929
1089
  }
930
1090
  return createTelemetryProxyChain([startAt], config, core);
931
1091
  }
932
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1092
+ function _createInternalContext(telemetryChain, config, core, startAt) {
933
1093
  var _nextProxy = null;
934
- var _onComplete = null;
935
- if (startAt) {
936
- _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
937
- }
938
- else {
939
- _nextProxy = telemetryChain;
1094
+ var _onComplete = [];
1095
+ if (startAt !== null) {
1096
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
940
1097
  }
941
1098
  var context = {
942
- core: function () {
943
- return core;
944
- },
945
- diagLog: function () {
946
- return safeGetLogger(core, config);
947
- },
948
- getCfg: function () {
949
- return config;
950
- },
951
- getExtCfg: _getExtCfg,
952
- getConfig: _getConfig,
953
- hasNext: function () {
954
- return _nextProxy != null;
955
- },
956
- getNext: function () {
957
- return _nextProxy;
958
- },
959
- setNext: function (nextPlugin) {
960
- _nextProxy = nextPlugin;
961
- },
962
- processNext: function (env) {
963
- _processChain(function (nextPlugin) {
964
- nextPlugin.processTelemetry(env, context);
1099
+ _next: _moveNext,
1100
+ ctx: {
1101
+ core: function () { return core; },
1102
+ diagLog: function () {
1103
+ return safeGetLogger(core, config);
1104
+ },
1105
+ getCfg: function () {
1106
+ return config;
1107
+ },
1108
+ getExtCfg: _getExtCfg,
1109
+ getConfig: _getConfig,
1110
+ hasNext: function () {
1111
+ return !!_nextProxy;
1112
+ },
1113
+ getNext: function () {
1114
+ return _nextProxy;
1115
+ },
1116
+ setNext: function (nextPlugin) {
1117
+ _nextProxy = nextPlugin;
1118
+ },
1119
+ iterate: _iterateChain,
1120
+ onComplete: _addOnComplete
1121
+ }
1122
+ };
1123
+ function _addOnComplete(onComplete, that) {
1124
+ var args = [];
1125
+ for (var _i = 2; _i < arguments.length; _i++) {
1126
+ args[_i - 2] = arguments[_i];
1127
+ }
1128
+ if (onComplete) {
1129
+ _onComplete.push({
1130
+ func: onComplete,
1131
+ self: !isUndefined(that) ? that : context.ctx,
1132
+ args: args
965
1133
  });
966
- },
967
- iterate: _iterateChain,
968
- createNew: function (plugins, startAt) {
969
- if (plugins === void 0) { plugins = null; }
970
- if (isArray(plugins)) {
971
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1134
+ }
1135
+ }
1136
+ function _moveNext() {
1137
+ var nextProxy = _nextProxy;
1138
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1139
+ if (!nextProxy) {
1140
+ var onComplete = _onComplete;
1141
+ if (onComplete && onComplete.length > 0) {
1142
+ arrForEach(onComplete, function (completeDetails) {
1143
+ try {
1144
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1145
+ }
1146
+ catch (e) {
1147
+ core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1148
+ }
1149
+ });
1150
+ _onComplete = [];
972
1151
  }
973
- return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
974
- },
975
- onComplete: function (onComplete) {
976
- _onComplete = onComplete;
977
1152
  }
978
- };
1153
+ return nextProxy;
1154
+ }
979
1155
  function _getExtCfg(identifier, defaultValue, mergeDefault) {
980
1156
  if (defaultValue === void 0) { defaultValue = {}; }
981
1157
  if (mergeDefault === void 0) { mergeDefault = 0 ; }
@@ -1018,29 +1194,53 @@
1018
1194
  }
1019
1195
  return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1020
1196
  }
1021
- function _processChain(cb) {
1022
- var nextPlugin = _nextProxy;
1023
- if (nextPlugin) {
1024
- _nextProxy = nextPlugin.getNext();
1025
- cb(nextPlugin);
1026
- }
1027
- else {
1028
- if (_onComplete) {
1029
- _onComplete();
1030
- _onComplete = null;
1197
+ function _iterateChain(cb) {
1198
+ var nextPlugin;
1199
+ while (!!(nextPlugin = context._next())) {
1200
+ var plugin = nextPlugin.getPlugin();
1201
+ if (plugin) {
1202
+ cb(plugin);
1031
1203
  }
1032
1204
  }
1033
1205
  }
1034
- function _iterateChain(cb) {
1035
- while (_nextProxy) {
1036
- _processChain(function (nextPlugin) {
1037
- var plugin = nextPlugin.getPlugin();
1038
- if (plugin) {
1039
- cb(plugin);
1040
- }
1041
- });
1206
+ return context;
1207
+ }
1208
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1209
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1210
+ var context = internalContext.ctx;
1211
+ function _processNext(env) {
1212
+ var nextPlugin = internalContext._next();
1213
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1214
+ return !nextPlugin;
1215
+ }
1216
+ function _createNew(plugins, startAt) {
1217
+ if (plugins === void 0) { plugins = null; }
1218
+ if (isArray(plugins)) {
1219
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1220
+ }
1221
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1222
+ }
1223
+ context.processNext = _processNext;
1224
+ context.createNew = _createNew;
1225
+ return context;
1226
+ }
1227
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1228
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1229
+ var context = internalContext.ctx;
1230
+ function _processNext(unloadState) {
1231
+ var nextPlugin = internalContext._next();
1232
+ nextPlugin && nextPlugin.unload(context, unloadState);
1233
+ return !nextPlugin;
1234
+ }
1235
+ function _createNew(plugins, startAt) {
1236
+ if (plugins === void 0) { plugins = null; }
1237
+ if (isArray(plugins)) {
1238
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1042
1239
  }
1240
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1043
1241
  }
1242
+ context.processNext = _processNext;
1243
+ context.createNew = _createNew;
1044
1244
  return context;
1045
1245
  }
1046
1246
  function createTelemetryProxyChain(plugins, config, core, startAt) {
@@ -1088,32 +1288,35 @@
1088
1288
  return nextProxy;
1089
1289
  },
1090
1290
  processTelemetry: _processTelemetry,
1291
+ unload: _unloadPlugin,
1091
1292
  _id: chainId,
1092
1293
  _setNext: function (nextPlugin) {
1093
1294
  nextProxy = nextPlugin;
1094
1295
  }
1095
1296
  };
1096
- function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1297
+ function _getTelCtx() {
1298
+ var itemCtx;
1299
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1300
+ itemCtx = plugin[strGetTelCtx]();
1301
+ }
1097
1302
  if (!itemCtx) {
1098
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1099
- itemCtx = plugin[strGetTelCtx]();
1100
- }
1101
- if (!itemCtx) {
1102
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1103
- }
1303
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1104
1304
  }
1305
+ return itemCtx;
1306
+ }
1307
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1308
+ var hasRun = false;
1105
1309
  var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1106
1310
  var hasRunContext = itemCtx[strHasRunFlags];
1107
1311
  if (!hasRunContext) {
1108
1312
  hasRunContext = itemCtx[strHasRunFlags] = {};
1109
1313
  }
1110
- doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1111
- hasRunContext[chainId] = true;
1112
- var hasRun = false;
1113
- itemCtx.setNext(nextProxy);
1114
- if (plugin) {
1314
+ itemCtx.setNext(nextProxy);
1315
+ if (plugin) {
1316
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1317
+ hasRunContext[chainId] = true;
1115
1318
  try {
1116
- var nextId = nextProxy ? nextProxy._id : "";
1319
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1117
1320
  if (nextId) {
1118
1321
  hasRunContext[nextId] = false;
1119
1322
  }
@@ -1125,18 +1328,21 @@
1125
1328
  hasRun = true;
1126
1329
  }
1127
1330
  if (!nextProxy || !hasNextRun) {
1128
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1331
+ itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1129
1332
  }
1130
1333
  }
1131
- }
1132
- if (nextProxy && !hasRun) {
1133
- processProxyFn(itemCtx);
1134
- }
1135
- }, details, isAsync);
1334
+ }, details, isAsync);
1335
+ }
1336
+ return hasRun;
1136
1337
  }
1137
1338
  function _processTelemetry(env, itemCtx) {
1138
- _processChain(itemCtx, function (itemCtx) {
1139
- if (!hasProcessTelemetry) {
1339
+ itemCtx = itemCtx || _getTelCtx();
1340
+ function _callProcessTelemetry(itemCtx) {
1341
+ if (!plugin || !hasProcessTelemetry) {
1342
+ return false;
1343
+ }
1344
+ var pluginState = _getPluginState(plugin);
1345
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1140
1346
  return false;
1141
1347
  }
1142
1348
  if (hasSetNext) {
@@ -1144,15 +1350,61 @@
1144
1350
  }
1145
1351
  plugin.processTelemetry(env, itemCtx);
1146
1352
  return true;
1147
- }, function (itemCtx) {
1148
- nextProxy.processTelemetry(env, itemCtx);
1149
- }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1353
+ }
1354
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1355
+ itemCtx.processNext(env);
1356
+ }
1357
+ }
1358
+ function _unloadPlugin(unloadCtx, unloadState) {
1359
+ function _callTeardown() {
1360
+ var hasRun = false;
1361
+ if (plugin) {
1362
+ var pluginState = _getPluginState(plugin);
1363
+ var pluginCore = plugin[strCore] || pluginState.core;
1364
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1365
+ pluginState[strCore] = null;
1366
+ pluginState[strTeardown] = true;
1367
+ pluginState[strIsInitialized] = false;
1368
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1369
+ hasRun = true;
1370
+ }
1371
+ }
1372
+ }
1373
+ return hasRun;
1374
+ }
1375
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1376
+ unloadCtx.processNext(unloadState);
1377
+ }
1150
1378
  }
1151
1379
  return objFreeze(proxyChain);
1152
1380
  }
1153
1381
 
1154
1382
  var strExtensionConfig = "extensionConfig";
1155
1383
 
1384
+ function createUnloadHandlerContainer() {
1385
+ var handlers = [];
1386
+ function _addHandler(handler) {
1387
+ if (handler) {
1388
+ handlers.push(handler);
1389
+ }
1390
+ }
1391
+ function _runHandlers(unloadCtx, unloadState) {
1392
+ arrForEach(handlers, function (handler) {
1393
+ try {
1394
+ handler(unloadCtx, unloadState);
1395
+ }
1396
+ catch (e) {
1397
+ unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1398
+ }
1399
+ });
1400
+ handlers = [];
1401
+ }
1402
+ return {
1403
+ add: _addHandler,
1404
+ run: _runHandlers
1405
+ };
1406
+ }
1407
+
1156
1408
  var strGetPlugin = "getPlugin";
1157
1409
  var BaseTelemetryPlugin = /** @class */ (function () {
1158
1410
  function BaseTelemetryPlugin() {
@@ -1160,6 +1412,7 @@
1160
1412
  var _isinitialized;
1161
1413
  var _rootCtx;
1162
1414
  var _nextPlugin;
1415
+ var _unloadHandlerContainer;
1163
1416
  var _hooks;
1164
1417
  _initDefaults();
1165
1418
  dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
@@ -1167,6 +1420,39 @@
1167
1420
  _setDefaults(config, core, pluginChain);
1168
1421
  _isinitialized = true;
1169
1422
  };
1423
+ _self.teardown = function (unloadCtx, unloadState) {
1424
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1425
+ return;
1426
+ }
1427
+ var result;
1428
+ var unloadDone = false;
1429
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1430
+ var theUnloadState = unloadState || {
1431
+ reason: 0 ,
1432
+ isAsync: false
1433
+ };
1434
+ function _unloadCallback() {
1435
+ if (!unloadDone) {
1436
+ unloadDone = true;
1437
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1438
+ arrForEach(_hooks, function (fn) {
1439
+ fn.rm();
1440
+ });
1441
+ _hooks = [];
1442
+ if (result === true) {
1443
+ theUnloadCtx.processNext(theUnloadState);
1444
+ }
1445
+ _initDefaults();
1446
+ }
1447
+ }
1448
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1449
+ _unloadCallback();
1450
+ }
1451
+ else {
1452
+ result = true;
1453
+ }
1454
+ return result;
1455
+ };
1170
1456
  _self._addHook = function (hooks) {
1171
1457
  if (hooks) {
1172
1458
  if (isArray(hooks)) {
@@ -1177,17 +1463,18 @@
1177
1463
  }
1178
1464
  }
1179
1465
  };
1466
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1180
1467
  });
1181
1468
  _self.diagLog = function (itemCtx) {
1182
1469
  return _getTelCtx(itemCtx).diagLog();
1183
1470
  };
1184
- _self.isInitialized = function () {
1471
+ _self[strIsInitialized] = function () {
1185
1472
  return _isinitialized;
1186
1473
  };
1187
1474
  _self.setInitialized = function (isInitialized) {
1188
1475
  _isinitialized = isInitialized;
1189
1476
  };
1190
- _self.setNextPlugin = function (next) {
1477
+ _self[strSetNextPlugin] = function (next) {
1191
1478
  _nextPlugin = next;
1192
1479
  };
1193
1480
  _self.processNext = function (env, itemCtx) {
@@ -1233,11 +1520,101 @@
1233
1520
  _rootCtx = null;
1234
1521
  _nextPlugin = null;
1235
1522
  _hooks = [];
1523
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1236
1524
  }
1237
1525
  }
1238
1526
  return BaseTelemetryPlugin;
1239
1527
  }());
1240
1528
 
1529
+ var LoggingSeverity = createEnumStyle({
1530
+ CRITICAL: 1 ,
1531
+ WARNING: 2
1532
+ });
1533
+ var _InternalMessageId = createEnumStyle({
1534
+ BrowserDoesNotSupportLocalStorage: 0 ,
1535
+ BrowserCannotReadLocalStorage: 1 ,
1536
+ BrowserCannotReadSessionStorage: 2 ,
1537
+ BrowserCannotWriteLocalStorage: 3 ,
1538
+ BrowserCannotWriteSessionStorage: 4 ,
1539
+ BrowserFailedRemovalFromLocalStorage: 5 ,
1540
+ BrowserFailedRemovalFromSessionStorage: 6 ,
1541
+ CannotSendEmptyTelemetry: 7 ,
1542
+ ClientPerformanceMathError: 8 ,
1543
+ ErrorParsingAISessionCookie: 9 ,
1544
+ ErrorPVCalc: 10 ,
1545
+ ExceptionWhileLoggingError: 11 ,
1546
+ FailedAddingTelemetryToBuffer: 12 ,
1547
+ FailedMonitorAjaxAbort: 13 ,
1548
+ FailedMonitorAjaxDur: 14 ,
1549
+ FailedMonitorAjaxOpen: 15 ,
1550
+ FailedMonitorAjaxRSC: 16 ,
1551
+ FailedMonitorAjaxSend: 17 ,
1552
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
1553
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
1554
+ FailedToSendQueuedTelemetry: 20 ,
1555
+ FailedToReportDataLoss: 21 ,
1556
+ FlushFailed: 22 ,
1557
+ MessageLimitPerPVExceeded: 23 ,
1558
+ MissingRequiredFieldSpecification: 24 ,
1559
+ NavigationTimingNotSupported: 25 ,
1560
+ OnError: 26 ,
1561
+ SessionRenewalDateIsZero: 27 ,
1562
+ SenderNotInitialized: 28 ,
1563
+ StartTrackEventFailed: 29 ,
1564
+ StopTrackEventFailed: 30 ,
1565
+ StartTrackFailed: 31 ,
1566
+ StopTrackFailed: 32 ,
1567
+ TelemetrySampledAndNotSent: 33 ,
1568
+ TrackEventFailed: 34 ,
1569
+ TrackExceptionFailed: 35 ,
1570
+ TrackMetricFailed: 36 ,
1571
+ TrackPVFailed: 37 ,
1572
+ TrackPVFailedCalc: 38 ,
1573
+ TrackTraceFailed: 39 ,
1574
+ TransmissionFailed: 40 ,
1575
+ FailedToSetStorageBuffer: 41 ,
1576
+ FailedToRestoreStorageBuffer: 42 ,
1577
+ InvalidBackendResponse: 43 ,
1578
+ FailedToFixDepricatedValues: 44 ,
1579
+ InvalidDurationValue: 45 ,
1580
+ TelemetryEnvelopeInvalid: 46 ,
1581
+ CreateEnvelopeError: 47 ,
1582
+ CannotSerializeObject: 48 ,
1583
+ CannotSerializeObjectNonSerializable: 49 ,
1584
+ CircularReferenceDetected: 50 ,
1585
+ ClearAuthContextFailed: 51 ,
1586
+ ExceptionTruncated: 52 ,
1587
+ IllegalCharsInName: 53 ,
1588
+ ItemNotInArray: 54 ,
1589
+ MaxAjaxPerPVExceeded: 55 ,
1590
+ MessageTruncated: 56 ,
1591
+ NameTooLong: 57 ,
1592
+ SampleRateOutOfRange: 58 ,
1593
+ SetAuthContextFailed: 59 ,
1594
+ SetAuthContextFailedAccountName: 60 ,
1595
+ StringValueTooLong: 61 ,
1596
+ StartCalledMoreThanOnce: 62 ,
1597
+ StopCalledWithoutStart: 63 ,
1598
+ TelemetryInitializerFailed: 64 ,
1599
+ TrackArgumentsNotSpecified: 65 ,
1600
+ UrlTooLong: 66 ,
1601
+ SessionStorageBufferFull: 67 ,
1602
+ CannotAccessCookie: 68 ,
1603
+ IdTooLong: 69 ,
1604
+ InvalidEvent: 70 ,
1605
+ FailedMonitorAjaxSetRequestHeader: 71 ,
1606
+ SendBrowserInfoOnUserInit: 72 ,
1607
+ PluginException: 73 ,
1608
+ NotificationException: 74 ,
1609
+ SnippetScriptLoadFailure: 99 ,
1610
+ InvalidInstrumentationKey: 100 ,
1611
+ CannotParseAiBlobValue: 101 ,
1612
+ InvalidContentBlob: 102 ,
1613
+ TrackPageActionEventFailed: 103 ,
1614
+ FailedAddingCustomDefinedRequestContext: 104 ,
1615
+ InMemoryStorageBufferFull: 105
1616
+ });
1617
+
1241
1618
  var SeverityLevel;
1242
1619
  (function (SeverityLevel) {
1243
1620
  SeverityLevel[SeverityLevel["Verbose"] = 0] = "Verbose";