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

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-02
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,20 @@
548
491
  }
549
492
  return theValue;
550
493
  }
494
+ function throwError(message) {
495
+ throw new Error(message);
496
+ }
497
+ function createEnumStyle(values) {
498
+ var enumClass = {};
499
+ objForEachKey$1(values, function (field, value) {
500
+ enumClass[field] = value;
501
+ if (!isUndefined(enumClass[value])) {
502
+ throwError("Value: [" + value + "] already exists for " + field);
503
+ }
504
+ enumClass[value] = field;
505
+ });
506
+ return objFreeze(enumClass);
507
+ }
551
508
  function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
552
509
  var theArgs = arguments;
553
510
  var extended = theArgs[0] || {};
@@ -594,8 +551,15 @@
594
551
  }
595
552
 
596
553
  var strWindow = "window";
554
+ var strNavigator = "navigator";
597
555
  var strConsole = "console";
598
556
  var strJSON = "JSON";
557
+ var strCrypto = "crypto";
558
+ var strMsCrypto = "msCrypto";
559
+ var strMsie = "msie";
560
+ var strTrident = "trident/";
561
+ var _isTrident = null;
562
+ var _navUserAgentCheck = null;
599
563
  function getGlobalInst(name) {
600
564
  var gbl = getGlobal();
601
565
  if (gbl && gbl[name]) {
@@ -609,6 +573,15 @@
609
573
  function hasWindow() {
610
574
  return Boolean(typeof window === strShimObject && window);
611
575
  }
576
+ function hasNavigator() {
577
+ return Boolean(typeof navigator === strShimObject && navigator);
578
+ }
579
+ function getNavigator() {
580
+ if (hasNavigator()) {
581
+ return navigator;
582
+ }
583
+ return getGlobalInst(strNavigator);
584
+ }
612
585
  function getConsole() {
613
586
  if (typeof console !== strShimUndefined) {
614
587
  return console;
@@ -624,9 +597,24 @@
624
597
  }
625
598
  return null;
626
599
  }
600
+ function getCrypto() {
601
+ return getGlobalInst(strCrypto);
602
+ }
603
+ function getMsCrypto() {
604
+ return getGlobalInst(strMsCrypto);
605
+ }
606
+ function isIE() {
607
+ var nav = getNavigator();
608
+ if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
609
+ _navUserAgentCheck = nav.userAgent;
610
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
611
+ _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
612
+ }
613
+ return _isTrident;
614
+ }
627
615
  function dumpObj(object) {
628
616
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
629
- var propertyValueDump = "";
617
+ var propertyValueDump = strEmpty;
630
618
  if (objectTypeDump === "[object Error]") {
631
619
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
632
620
  }
@@ -659,9 +647,9 @@
659
647
  var strWarnToConsole = "warnToConsole";
660
648
  function _sanitizeDiagnosticText(text) {
661
649
  if (text) {
662
- return "\"" + text.replace(/\"/g, "") + "\"";
650
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
663
651
  }
664
- return "";
652
+ return strEmpty;
665
653
  }
666
654
  function _logToConsole(func, message) {
667
655
  var theConsole = getConsole();
@@ -683,12 +671,12 @@
683
671
  _self.message =
684
672
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
685
673
  msgId;
686
- var strProps = "";
674
+ var strProps = strEmpty;
687
675
  if (hasJSON()) {
688
676
  strProps = getJSON().stringify(properties);
689
677
  }
690
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
691
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
678
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
679
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
692
680
  _self.message += diagnosticText;
693
681
  }
694
682
  _InternalLogMessage.dataType = "MessageData";
@@ -718,7 +706,7 @@
718
706
  throw message;
719
707
  }
720
708
  else {
721
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
709
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
722
710
  if (!isUndefined(message.message)) {
723
711
  var logLevel = _self.consoleLoggingLevel();
724
712
  if (isUserAct) {
@@ -736,7 +724,7 @@
736
724
  _self.logInternalMessage(severity, message);
737
725
  }
738
726
  else {
739
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
727
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
740
728
  }
741
729
  }
742
730
  };
@@ -768,13 +756,13 @@
768
756
  if (severity <= _self.telemetryLoggingLevel()) {
769
757
  _self.queue.push(message);
770
758
  _messageCount++;
771
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
759
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
772
760
  }
773
761
  if (_messageCount === _self.maxInternalMessageLimit()) {
774
762
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
775
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
763
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
776
764
  _self.queue.push(throttleMessage);
777
- if (severity === LoggingSeverity.CRITICAL) {
765
+ if (severity === 1 ) {
778
766
  _self.errorToConsole(throttleLimitMessage);
779
767
  }
780
768
  else {
@@ -916,6 +904,151 @@
916
904
  return func();
917
905
  }
918
906
 
907
+ var UInt32Mask = 0x100000000;
908
+ var MaxUInt32 = 0xffffffff;
909
+ var _mwcSeeded = false;
910
+ var _mwcW = 123456789;
911
+ var _mwcZ = 987654321;
912
+ function _mwcSeed(seedValue) {
913
+ if (seedValue < 0) {
914
+ seedValue >>>= 0;
915
+ }
916
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
917
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
918
+ _mwcSeeded = true;
919
+ }
920
+ function _autoSeedMwc() {
921
+ try {
922
+ var now = dateNow() & 0x7fffffff;
923
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
924
+ }
925
+ catch (e) {
926
+ }
927
+ }
928
+ function random32(signed) {
929
+ var value = 0;
930
+ var c = getCrypto() || getMsCrypto();
931
+ if (c && c.getRandomValues) {
932
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
933
+ }
934
+ if (value === 0 && isIE()) {
935
+ if (!_mwcSeeded) {
936
+ _autoSeedMwc();
937
+ }
938
+ value = mwcRandom32() & MaxUInt32;
939
+ }
940
+ if (value === 0) {
941
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
942
+ }
943
+ if (!signed) {
944
+ value >>>= 0;
945
+ }
946
+ return value;
947
+ }
948
+ function mwcRandom32(signed) {
949
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
950
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
951
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
952
+ if (!signed) {
953
+ value >>>= 0;
954
+ }
955
+ return value;
956
+ }
957
+ function newId(maxLength) {
958
+ if (maxLength === void 0) { maxLength = 22; }
959
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
960
+ var number = random32() >>> 0;
961
+ var chars = 0;
962
+ var result = strEmpty;
963
+ while (result.length < maxLength) {
964
+ chars++;
965
+ result += base64chars.charAt(number & 0x3F);
966
+ number >>>= 6;
967
+ if (chars === 5) {
968
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
969
+ chars = 0;
970
+ }
971
+ }
972
+ return result;
973
+ }
974
+
975
+ var _objDefineProperty = ObjDefineProperty;
976
+ var version = "2.7.3";
977
+ var instanceName = "." + newId(6);
978
+ var _dataUid = 0;
979
+ function _createAccessor(target, prop, value) {
980
+ if (_objDefineProperty) {
981
+ try {
982
+ _objDefineProperty(target, prop, {
983
+ value: value,
984
+ enumerable: false,
985
+ configurable: true
986
+ });
987
+ return true;
988
+ }
989
+ catch (e) {
990
+ }
991
+ }
992
+ return false;
993
+ }
994
+ function _canAcceptData(target) {
995
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
996
+ }
997
+ function _getCache(data, target) {
998
+ var theCache = target[data.id];
999
+ if (!theCache) {
1000
+ theCache = {};
1001
+ try {
1002
+ if (_canAcceptData(target)) {
1003
+ if (!_createAccessor(target, data.id, theCache)) {
1004
+ target[data.id] = theCache;
1005
+ }
1006
+ }
1007
+ }
1008
+ catch (e) {
1009
+ }
1010
+ }
1011
+ return theCache;
1012
+ }
1013
+ function createUniqueNamespace(name, includeVersion) {
1014
+ if (includeVersion === void 0) { includeVersion = false; }
1015
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1016
+ }
1017
+ function createElmNodeData(name) {
1018
+ var data = {
1019
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1020
+ accept: function (target) {
1021
+ return _canAcceptData(target);
1022
+ },
1023
+ get: function (target, name, defValue, addDefault) {
1024
+ var theCache = target[data.id];
1025
+ if (!theCache) {
1026
+ if (addDefault) {
1027
+ theCache = _getCache(data, target);
1028
+ theCache[normalizeJsName(name)] = defValue;
1029
+ }
1030
+ return defValue;
1031
+ }
1032
+ return theCache[normalizeJsName(name)];
1033
+ },
1034
+ kill: function (target, name) {
1035
+ if (target && target[name]) {
1036
+ try {
1037
+ delete target[name];
1038
+ }
1039
+ catch (e) {
1040
+ }
1041
+ }
1042
+ }
1043
+ };
1044
+ return data;
1045
+ }
1046
+
1047
+ var pluginStateData = createElmNodeData("plugin");
1048
+ function _getPluginState(plugin) {
1049
+ return pluginStateData.get(plugin, "state", {}, true);
1050
+ }
1051
+
919
1052
  var strTelemetryPluginChain = "TelemetryPluginChain";
920
1053
  var strHasRunFlags = "_hasRun";
921
1054
  var strGetTelCtx = "_getTelCtx";
@@ -929,53 +1062,66 @@
929
1062
  }
930
1063
  return createTelemetryProxyChain([startAt], config, core);
931
1064
  }
932
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
933
- var _nextProxy = null;
934
- var _onComplete = null;
935
- if (startAt) {
936
- _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
937
- }
938
- else {
939
- _nextProxy = telemetryChain;
940
- }
1065
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1066
+ var _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1067
+ var _onComplete = [];
941
1068
  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);
1069
+ _next: _moveNext,
1070
+ ctx: {
1071
+ core: function () { return core; },
1072
+ diagLog: function () {
1073
+ return safeGetLogger(core, config);
1074
+ },
1075
+ getCfg: function () {
1076
+ return config;
1077
+ },
1078
+ getExtCfg: _getExtCfg,
1079
+ getConfig: _getConfig,
1080
+ hasNext: function () {
1081
+ return !!_nextProxy;
1082
+ },
1083
+ getNext: function () {
1084
+ return _nextProxy;
1085
+ },
1086
+ setNext: function (nextPlugin) {
1087
+ _nextProxy = nextPlugin;
1088
+ },
1089
+ iterate: _iterateChain,
1090
+ onComplete: _addOnComplete
1091
+ }
1092
+ };
1093
+ function _addOnComplete(onComplete, that) {
1094
+ var args = [];
1095
+ for (var _i = 2; _i < arguments.length; _i++) {
1096
+ args[_i - 2] = arguments[_i];
1097
+ }
1098
+ if (onComplete) {
1099
+ _onComplete.push({
1100
+ func: onComplete,
1101
+ self: !isUndefined(that) ? that : context.ctx,
1102
+ args: args
965
1103
  });
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);
1104
+ }
1105
+ }
1106
+ function _moveNext() {
1107
+ var nextProxy = _nextProxy;
1108
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1109
+ if (!nextProxy) {
1110
+ var onComplete = _onComplete;
1111
+ if (onComplete && onComplete.length > 0) {
1112
+ arrForEach(onComplete, function (completeDetails) {
1113
+ try {
1114
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1115
+ }
1116
+ catch (e) {
1117
+ core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1118
+ }
1119
+ });
1120
+ _onComplete = [];
972
1121
  }
973
- return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
974
- },
975
- onComplete: function (onComplete) {
976
- _onComplete = onComplete;
977
1122
  }
978
- };
1123
+ return nextProxy;
1124
+ }
979
1125
  function _getExtCfg(identifier, defaultValue, mergeDefault) {
980
1126
  if (defaultValue === void 0) { defaultValue = {}; }
981
1127
  if (mergeDefault === void 0) { mergeDefault = 0 ; }
@@ -1018,29 +1164,53 @@
1018
1164
  }
1019
1165
  return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1020
1166
  }
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;
1167
+ function _iterateChain(cb) {
1168
+ var nextPlugin;
1169
+ while (!!(nextPlugin = context._next())) {
1170
+ var plugin = nextPlugin.getPlugin();
1171
+ if (plugin) {
1172
+ cb(plugin);
1031
1173
  }
1032
1174
  }
1033
1175
  }
1034
- function _iterateChain(cb) {
1035
- while (_nextProxy) {
1036
- _processChain(function (nextPlugin) {
1037
- var plugin = nextPlugin.getPlugin();
1038
- if (plugin) {
1039
- cb(plugin);
1040
- }
1041
- });
1176
+ return context;
1177
+ }
1178
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1179
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1180
+ var context = internalContext.ctx;
1181
+ function _processNext(env) {
1182
+ var nextPlugin = internalContext._next();
1183
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1184
+ return !nextPlugin;
1185
+ }
1186
+ function _createNew(plugins, startAt) {
1187
+ if (plugins === void 0) { plugins = null; }
1188
+ if (isArray(plugins)) {
1189
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1190
+ }
1191
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1192
+ }
1193
+ context.processNext = _processNext;
1194
+ context.createNew = _createNew;
1195
+ return context;
1196
+ }
1197
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1198
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1199
+ var context = internalContext.ctx;
1200
+ function _processNext(unloadState) {
1201
+ var nextPlugin = internalContext._next();
1202
+ nextPlugin && nextPlugin.unload(context, unloadState);
1203
+ return !nextPlugin;
1204
+ }
1205
+ function _createNew(plugins, startAt) {
1206
+ if (plugins === void 0) { plugins = null; }
1207
+ if (isArray(plugins)) {
1208
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1042
1209
  }
1210
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1043
1211
  }
1212
+ context.processNext = _processNext;
1213
+ context.createNew = _createNew;
1044
1214
  return context;
1045
1215
  }
1046
1216
  function createTelemetryProxyChain(plugins, config, core, startAt) {
@@ -1088,32 +1258,35 @@
1088
1258
  return nextProxy;
1089
1259
  },
1090
1260
  processTelemetry: _processTelemetry,
1261
+ unload: _unloadPlugin,
1091
1262
  _id: chainId,
1092
1263
  _setNext: function (nextPlugin) {
1093
1264
  nextProxy = nextPlugin;
1094
1265
  }
1095
1266
  };
1096
- function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1267
+ function _getTelCtx() {
1268
+ var itemCtx;
1269
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1270
+ itemCtx = plugin[strGetTelCtx]();
1271
+ }
1097
1272
  if (!itemCtx) {
1098
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1099
- itemCtx = plugin[strGetTelCtx]();
1100
- }
1101
- if (!itemCtx) {
1102
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1103
- }
1273
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1104
1274
  }
1275
+ return itemCtx;
1276
+ }
1277
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1278
+ var hasRun = false;
1105
1279
  var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1106
1280
  var hasRunContext = itemCtx[strHasRunFlags];
1107
1281
  if (!hasRunContext) {
1108
1282
  hasRunContext = itemCtx[strHasRunFlags] = {};
1109
1283
  }
1110
- doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1111
- hasRunContext[chainId] = true;
1112
- var hasRun = false;
1113
- itemCtx.setNext(nextProxy);
1114
- if (plugin) {
1284
+ itemCtx.setNext(nextProxy);
1285
+ if (plugin) {
1286
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1287
+ hasRunContext[chainId] = true;
1115
1288
  try {
1116
- var nextId = nextProxy ? nextProxy._id : "";
1289
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1117
1290
  if (nextId) {
1118
1291
  hasRunContext[nextId] = false;
1119
1292
  }
@@ -1125,18 +1298,21 @@
1125
1298
  hasRun = true;
1126
1299
  }
1127
1300
  if (!nextProxy || !hasNextRun) {
1128
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1301
+ itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1129
1302
  }
1130
1303
  }
1131
- }
1132
- if (nextProxy && !hasRun) {
1133
- processProxyFn(itemCtx);
1134
- }
1135
- }, details, isAsync);
1304
+ }, details, isAsync);
1305
+ }
1306
+ return hasRun;
1136
1307
  }
1137
1308
  function _processTelemetry(env, itemCtx) {
1138
- _processChain(itemCtx, function (itemCtx) {
1139
- if (!hasProcessTelemetry) {
1309
+ itemCtx = itemCtx || _getTelCtx();
1310
+ function _callProcessTelemetry(itemCtx) {
1311
+ if (!plugin || !hasProcessTelemetry) {
1312
+ return false;
1313
+ }
1314
+ var pluginState = _getPluginState(plugin);
1315
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1140
1316
  return false;
1141
1317
  }
1142
1318
  if (hasSetNext) {
@@ -1144,9 +1320,31 @@
1144
1320
  }
1145
1321
  plugin.processTelemetry(env, itemCtx);
1146
1322
  return true;
1147
- }, function (itemCtx) {
1148
- nextProxy.processTelemetry(env, itemCtx);
1149
- }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1323
+ }
1324
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1325
+ itemCtx.processNext(env);
1326
+ }
1327
+ }
1328
+ function _unloadPlugin(unloadCtx, unloadState) {
1329
+ function _callTeardown() {
1330
+ var hasRun = false;
1331
+ if (plugin) {
1332
+ var pluginState = _getPluginState(plugin);
1333
+ var pluginCore = plugin[strCore] || pluginState.core;
1334
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1335
+ pluginState[strCore] = null;
1336
+ pluginState[strTeardown] = true;
1337
+ pluginState[strIsInitialized] = false;
1338
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1339
+ hasRun = true;
1340
+ }
1341
+ }
1342
+ }
1343
+ return hasRun;
1344
+ }
1345
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1346
+ unloadCtx.processNext(unloadState);
1347
+ }
1150
1348
  }
1151
1349
  return objFreeze(proxyChain);
1152
1350
  }
@@ -1167,6 +1365,38 @@
1167
1365
  _setDefaults(config, core, pluginChain);
1168
1366
  _isinitialized = true;
1169
1367
  };
1368
+ _self.teardown = function (unloadCtx, unloadState) {
1369
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1370
+ return;
1371
+ }
1372
+ var result;
1373
+ var unloadDone = false;
1374
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1375
+ var theUnloadState = unloadState || {
1376
+ reason: 0 ,
1377
+ isAsync: false
1378
+ };
1379
+ function _unloadCallback() {
1380
+ if (!unloadDone) {
1381
+ unloadDone = true;
1382
+ arrForEach(_hooks, function (fn) {
1383
+ fn.rm();
1384
+ });
1385
+ _hooks = [];
1386
+ if (result === true) {
1387
+ theUnloadCtx.processNext(theUnloadState);
1388
+ }
1389
+ _initDefaults();
1390
+ }
1391
+ }
1392
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1393
+ _unloadCallback();
1394
+ }
1395
+ else {
1396
+ result = true;
1397
+ }
1398
+ return result;
1399
+ };
1170
1400
  _self._addHook = function (hooks) {
1171
1401
  if (hooks) {
1172
1402
  if (isArray(hooks)) {
@@ -1181,13 +1411,13 @@
1181
1411
  _self.diagLog = function (itemCtx) {
1182
1412
  return _getTelCtx(itemCtx).diagLog();
1183
1413
  };
1184
- _self.isInitialized = function () {
1414
+ _self[strIsInitialized] = function () {
1185
1415
  return _isinitialized;
1186
1416
  };
1187
1417
  _self.setInitialized = function (isInitialized) {
1188
1418
  _isinitialized = isInitialized;
1189
1419
  };
1190
- _self.setNextPlugin = function (next) {
1420
+ _self[strSetNextPlugin] = function (next) {
1191
1421
  _nextPlugin = next;
1192
1422
  };
1193
1423
  _self.processNext = function (env, itemCtx) {
@@ -1238,6 +1468,95 @@
1238
1468
  return BaseTelemetryPlugin;
1239
1469
  }());
1240
1470
 
1471
+ var LoggingSeverity = createEnumStyle({
1472
+ CRITICAL: 1 ,
1473
+ WARNING: 2
1474
+ });
1475
+ var _InternalMessageId = createEnumStyle({
1476
+ BrowserDoesNotSupportLocalStorage: 0 ,
1477
+ BrowserCannotReadLocalStorage: 1 ,
1478
+ BrowserCannotReadSessionStorage: 2 ,
1479
+ BrowserCannotWriteLocalStorage: 3 ,
1480
+ BrowserCannotWriteSessionStorage: 4 ,
1481
+ BrowserFailedRemovalFromLocalStorage: 5 ,
1482
+ BrowserFailedRemovalFromSessionStorage: 6 ,
1483
+ CannotSendEmptyTelemetry: 7 ,
1484
+ ClientPerformanceMathError: 8 ,
1485
+ ErrorParsingAISessionCookie: 9 ,
1486
+ ErrorPVCalc: 10 ,
1487
+ ExceptionWhileLoggingError: 11 ,
1488
+ FailedAddingTelemetryToBuffer: 12 ,
1489
+ FailedMonitorAjaxAbort: 13 ,
1490
+ FailedMonitorAjaxDur: 14 ,
1491
+ FailedMonitorAjaxOpen: 15 ,
1492
+ FailedMonitorAjaxRSC: 16 ,
1493
+ FailedMonitorAjaxSend: 17 ,
1494
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
1495
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
1496
+ FailedToSendQueuedTelemetry: 20 ,
1497
+ FailedToReportDataLoss: 21 ,
1498
+ FlushFailed: 22 ,
1499
+ MessageLimitPerPVExceeded: 23 ,
1500
+ MissingRequiredFieldSpecification: 24 ,
1501
+ NavigationTimingNotSupported: 25 ,
1502
+ OnError: 26 ,
1503
+ SessionRenewalDateIsZero: 27 ,
1504
+ SenderNotInitialized: 28 ,
1505
+ StartTrackEventFailed: 29 ,
1506
+ StopTrackEventFailed: 30 ,
1507
+ StartTrackFailed: 31 ,
1508
+ StopTrackFailed: 32 ,
1509
+ TelemetrySampledAndNotSent: 33 ,
1510
+ TrackEventFailed: 34 ,
1511
+ TrackExceptionFailed: 35 ,
1512
+ TrackMetricFailed: 36 ,
1513
+ TrackPVFailed: 37 ,
1514
+ TrackPVFailedCalc: 38 ,
1515
+ TrackTraceFailed: 39 ,
1516
+ TransmissionFailed: 40 ,
1517
+ FailedToSetStorageBuffer: 41 ,
1518
+ FailedToRestoreStorageBuffer: 42 ,
1519
+ InvalidBackendResponse: 43 ,
1520
+ FailedToFixDepricatedValues: 44 ,
1521
+ InvalidDurationValue: 45 ,
1522
+ TelemetryEnvelopeInvalid: 46 ,
1523
+ CreateEnvelopeError: 47 ,
1524
+ CannotSerializeObject: 48 ,
1525
+ CannotSerializeObjectNonSerializable: 49 ,
1526
+ CircularReferenceDetected: 50 ,
1527
+ ClearAuthContextFailed: 51 ,
1528
+ ExceptionTruncated: 52 ,
1529
+ IllegalCharsInName: 53 ,
1530
+ ItemNotInArray: 54 ,
1531
+ MaxAjaxPerPVExceeded: 55 ,
1532
+ MessageTruncated: 56 ,
1533
+ NameTooLong: 57 ,
1534
+ SampleRateOutOfRange: 58 ,
1535
+ SetAuthContextFailed: 59 ,
1536
+ SetAuthContextFailedAccountName: 60 ,
1537
+ StringValueTooLong: 61 ,
1538
+ StartCalledMoreThanOnce: 62 ,
1539
+ StopCalledWithoutStart: 63 ,
1540
+ TelemetryInitializerFailed: 64 ,
1541
+ TrackArgumentsNotSpecified: 65 ,
1542
+ UrlTooLong: 66 ,
1543
+ SessionStorageBufferFull: 67 ,
1544
+ CannotAccessCookie: 68 ,
1545
+ IdTooLong: 69 ,
1546
+ InvalidEvent: 70 ,
1547
+ FailedMonitorAjaxSetRequestHeader: 71 ,
1548
+ SendBrowserInfoOnUserInit: 72 ,
1549
+ PluginException: 73 ,
1550
+ NotificationException: 74 ,
1551
+ SnippetScriptLoadFailure: 99 ,
1552
+ InvalidInstrumentationKey: 100 ,
1553
+ CannotParseAiBlobValue: 101 ,
1554
+ InvalidContentBlob: 102 ,
1555
+ TrackPageActionEventFailed: 103 ,
1556
+ FailedAddingCustomDefinedRequestContext: 104 ,
1557
+ InMemoryStorageBufferFull: 105
1558
+ });
1559
+
1241
1560
  var SeverityLevel;
1242
1561
  (function (SeverityLevel) {
1243
1562
  SeverityLevel[SeverityLevel["Verbose"] = 0] = "Verbose";