@microsoft/applicationinsights-react-native 2.4.5-nightly.2203-02 → 2.4.5-nightly.2203-03

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.4.5-nightly.2203-02
2
+ * Application Insights JavaScript SDK - React Native Plugin, 2.4.5-nightly.2203-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -66,7 +66,9 @@
66
66
  (getGlobal() || {})["Reflect"];
67
67
  var extendStaticsFn = function (d, b) {
68
68
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
69
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
69
+ ({ __proto__: [] } instanceof Array && function (d, b) {
70
+ d.__proto__ = b;
71
+ }) ||
70
72
  function (d, b) {
71
73
  for (var p in b) {
72
74
  if (b[strShimHasOwnProperty](p)) {
@@ -81,7 +83,9 @@
81
83
  throwTypeError("Class extends value " + String(b) + " is not a constructor or null");
82
84
  }
83
85
  extendStaticsFn(d, b);
84
- function __() { this.constructor = d; }
86
+ function __() {
87
+ this.constructor = d;
88
+ }
85
89
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
86
90
  }
87
91
 
@@ -100,11 +104,11 @@
100
104
  var DynAllowInstChkTag = DynInstChkTag;
101
105
  var DynProtoDefaultOptions = '_dfOpts';
102
106
  var UnknownValue = '_unknown_';
103
- var str__Proto = "__proto__";
107
+ var str__Proto$1 = "__proto__";
104
108
  var strUseBaseInst = 'useBaseInst';
105
109
  var strSetInstFuncs = 'setInstFuncs';
106
110
  var Obj = Object;
107
- var _objGetPrototypeOf = Obj["getPrototypeOf"];
111
+ var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
108
112
  var _dynamicNames = 0;
109
113
  function _hasOwnProperty(obj, prop) {
110
114
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -115,12 +119,12 @@
115
119
  function _isObjectArrayOrFunctionPrototype(target) {
116
120
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
117
121
  }
118
- function _getObjProto(target) {
122
+ function _getObjProto$1(target) {
119
123
  if (target) {
120
- if (_objGetPrototypeOf) {
121
- return _objGetPrototypeOf(target);
124
+ if (_objGetPrototypeOf$1) {
125
+ return _objGetPrototypeOf$1(target);
122
126
  }
123
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
127
+ var newProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
124
128
  if (newProto) {
125
129
  return newProto;
126
130
  }
@@ -186,16 +190,16 @@
186
190
  _forEachProp(instFuncs, function (name) {
187
191
  baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
188
192
  });
189
- var baseProto = _getObjProto(classProto);
193
+ var baseProto = _getObjProto$1(classProto);
190
194
  var visited = [];
191
195
  while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
192
196
  _forEachProp(baseProto, function (name) {
193
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
197
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf$1)) {
194
198
  baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
195
199
  }
196
200
  });
197
201
  visited.push(baseProto);
198
- baseProto = _getObjProto(baseProto);
202
+ baseProto = _getObjProto$1(baseProto);
199
203
  }
200
204
  return baseFuncs;
201
205
  }
@@ -209,7 +213,7 @@
209
213
  }
210
214
  if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
211
215
  var canAddInst = !_hasOwnProperty(target, funcName);
212
- var objProto = _getObjProto(target);
216
+ var objProto = _getObjProto$1(target);
213
217
  var visited = [];
214
218
  while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
215
219
  var protoFunc = objProto[funcName];
@@ -218,7 +222,7 @@
218
222
  break;
219
223
  }
220
224
  visited.push(objProto);
221
- objProto = _getObjProto(objProto);
225
+ objProto = _getObjProto$1(objProto);
222
226
  }
223
227
  try {
224
228
  if (canAddInst) {
@@ -236,7 +240,7 @@
236
240
  function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
237
241
  var protoFunc = proto[funcName];
238
242
  if (protoFunc === currentDynProtoProxy) {
239
- protoFunc = _getObjProto(proto)[funcName];
243
+ protoFunc = _getObjProto$1(proto)[funcName];
240
244
  }
241
245
  if (typeof protoFunc !== strFunction) {
242
246
  _throwTypeError("[" + funcName + "] is not a " + strFunction);
@@ -270,15 +274,15 @@
270
274
  }
271
275
  }
272
276
  function _checkPrototype(classProto, thisTarget) {
273
- if (_objGetPrototypeOf) {
277
+ if (_objGetPrototypeOf$1) {
274
278
  var visited = [];
275
- var thisProto = _getObjProto(thisTarget);
279
+ var thisProto = _getObjProto$1(thisTarget);
276
280
  while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
277
281
  if (thisProto === classProto) {
278
282
  return true;
279
283
  }
280
284
  visited.push(thisProto);
281
- thisProto = _getObjProto(thisProto);
285
+ thisProto = _getObjProto$1(thisProto);
282
286
  }
283
287
  }
284
288
  return false;
@@ -314,7 +318,7 @@
314
318
  var instFuncs = _getInstanceFuncs(target);
315
319
  var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
316
320
  delegateFunc(target, baseFuncs);
317
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
321
+ var setInstanceFunc = !!_objGetPrototypeOf$1 && !!perfOptions[strSetInstFuncs];
318
322
  if (setInstanceFunc && options) {
319
323
  setInstanceFunc = !!options[strSetInstFuncs];
320
324
  }
@@ -326,102 +330,40 @@
326
330
  };
327
331
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
328
332
 
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
- };
333
+ var strEmpty = "";
334
+ var strSetNextPlugin = "setNextPlugin";
335
+ var strIsInitialized = "isInitialized";
336
+ var strTeardown = "teardown";
337
+ var strCore = "core";
338
+ var strUpdate = "update";
339
+ var strDisabled = "disabled";
340
+ var strDoTeardown = "_doTeardown";
418
341
 
419
342
  var strToString = "toString";
420
- var _objDefineProperty = ObjDefineProperty;
343
+ var str__Proto = "__proto__";
344
+ var strConstructor = "constructor";
345
+ var _objDefineProperty$1 = ObjDefineProperty;
346
+ var _objFreeze = ObjClass.freeze;
421
347
  var _isArray = Array.isArray;
422
348
  var _objToString = ObjProto[strToString];
423
349
  var _fnToString = ObjHasOwnProperty[strToString];
424
- _fnToString.call(ObjClass);
350
+ var _objFunctionString = _fnToString.call(ObjClass);
351
+ var rCamelCase = /-([a-z])/g;
352
+ var rNormalizeInvalid = /([^\w\d_$])/g;
353
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
354
+ var _objGetPrototypeOf = Object["getPrototypeOf"];
355
+ function _getObjProto(target) {
356
+ if (target) {
357
+ if (_objGetPrototypeOf) {
358
+ return _objGetPrototypeOf(target);
359
+ }
360
+ var newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
361
+ if (newProto) {
362
+ return newProto;
363
+ }
364
+ }
365
+ return null;
366
+ }
425
367
  function isUndefined(value) {
426
368
  return value === undefined || typeof value === strShimUndefined;
427
369
  }
@@ -437,6 +379,34 @@
437
379
  function isFunction(value) {
438
380
  return !!(value && typeof value === strShimFunction);
439
381
  }
382
+ function normalizeJsName(name) {
383
+ var value = name;
384
+ if (value && isString(value)) {
385
+ value = value.replace(rCamelCase, function (_all, letter) {
386
+ return letter.toUpperCase();
387
+ });
388
+ value = value.replace(rNormalizeInvalid, "_");
389
+ value = value.replace(rLeadingNumeric, function (_all, match) {
390
+ return "_" + match;
391
+ });
392
+ }
393
+ return value;
394
+ }
395
+ function objForEachKey$1(target, callbackfn) {
396
+ if (target) {
397
+ for (var prop in target) {
398
+ if (ObjHasOwnProperty.call(target, prop)) {
399
+ callbackfn.call(target, prop, target[prop]);
400
+ }
401
+ }
402
+ }
403
+ }
404
+ function strContains(value, search) {
405
+ if (value && search) {
406
+ return value.indexOf(search) !== -1;
407
+ }
408
+ return false;
409
+ }
440
410
  var isArray = _isArray || _isArrayPoly;
441
411
  function _isArrayPoly(obj) {
442
412
  return !!(obj && _objToString.call(obj) === "[object Array]");
@@ -444,6 +414,28 @@
444
414
  function isError(obj) {
445
415
  return !!(obj && _objToString.call(obj) === "[object Error]");
446
416
  }
417
+ function isString(value) {
418
+ return typeof value === "string";
419
+ }
420
+ function isBoolean(value) {
421
+ return typeof value === "boolean";
422
+ }
423
+ function isPlainObject(value) {
424
+ var result = false;
425
+ if (value && typeof value === "object") {
426
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
427
+ if (!proto) {
428
+ result = true;
429
+ }
430
+ else {
431
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
432
+ proto = proto[strConstructor];
433
+ }
434
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
435
+ }
436
+ }
437
+ return result;
438
+ }
447
439
  function arrForEach(arr, callbackfn, thisArg) {
448
440
  var len = arr.length;
449
441
  try {
@@ -459,7 +451,7 @@
459
451
  }
460
452
  }
461
453
  function objDefineAccessors(target, prop, getProp, setProp) {
462
- if (_objDefineProperty) {
454
+ if (_objDefineProperty$1) {
463
455
  try {
464
456
  var descriptor = {
465
457
  enumerable: true,
@@ -471,7 +463,7 @@
471
463
  if (setProp) {
472
464
  descriptor.set = setProp;
473
465
  }
474
- _objDefineProperty(target, prop, descriptor);
466
+ _objDefineProperty$1(target, prop, descriptor);
475
467
  return true;
476
468
  }
477
469
  catch (e) {
@@ -479,6 +471,10 @@
479
471
  }
480
472
  return false;
481
473
  }
474
+ function _doNothing(value) {
475
+ return value;
476
+ }
477
+ var objFreeze = _objFreeze || _doNothing;
482
478
  function dateNow() {
483
479
  var dt = Date;
484
480
  return dt.now ? dt.now() : new dt().getTime();
@@ -487,7 +483,7 @@
487
483
  if (isError(object)) {
488
484
  return object.name;
489
485
  }
490
- return "";
486
+ return strEmpty;
491
487
  }
492
488
  function setValue(target, field, value, valChk, srcChk) {
493
489
  var theValue = value;
@@ -500,10 +496,102 @@
500
496
  }
501
497
  return theValue;
502
498
  }
499
+ function throwError(message) {
500
+ throw new Error(message);
501
+ }
502
+ function _createProxyFunction(source, funcName) {
503
+ var srcFunc = null;
504
+ var src = null;
505
+ if (isFunction(source)) {
506
+ srcFunc = source;
507
+ }
508
+ else {
509
+ src = source;
510
+ }
511
+ return function () {
512
+ var originalArguments = arguments;
513
+ if (srcFunc) {
514
+ src = srcFunc();
515
+ }
516
+ if (src) {
517
+ return src[funcName].apply(src, originalArguments);
518
+ }
519
+ };
520
+ }
521
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
522
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
523
+ if (target && name && source) {
524
+ if (overwriteTarget || isUndefined(target[name])) {
525
+ target[name] = _createProxyFunction(source, theFunc);
526
+ }
527
+ }
528
+ }
529
+ function createEnumStyle(values) {
530
+ var enumClass = {};
531
+ objForEachKey$1(values, function (field, value) {
532
+ enumClass[field] = value;
533
+ if (!isUndefined(enumClass[value])) {
534
+ throwError("[" + value + "] exists for " + field);
535
+ }
536
+ enumClass[value] = field;
537
+ });
538
+ return objFreeze(enumClass);
539
+ }
540
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
541
+ var theArgs = arguments;
542
+ var extended = theArgs[0] || {};
543
+ var argLen = theArgs.length;
544
+ var deep = false;
545
+ var idx = 1;
546
+ if (argLen > 0 && isBoolean(extended)) {
547
+ deep = extended;
548
+ extended = theArgs[idx] || {};
549
+ idx++;
550
+ }
551
+ if (!isObject(extended)) {
552
+ extended = {};
553
+ }
554
+ for (; idx < argLen; idx++) {
555
+ var arg = theArgs[idx];
556
+ var isArgArray = isArray(arg);
557
+ var isArgObj = isObject(arg);
558
+ for (var prop in arg) {
559
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
560
+ if (!propOk) {
561
+ continue;
562
+ }
563
+ var newValue = arg[prop];
564
+ var isNewArray = void 0;
565
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
566
+ var clone = extended[prop];
567
+ if (isNewArray) {
568
+ if (!isArray(clone)) {
569
+ clone = [];
570
+ }
571
+ }
572
+ else if (!isPlainObject(clone)) {
573
+ clone = {};
574
+ }
575
+ newValue = objExtend(deep, clone, newValue);
576
+ }
577
+ if (newValue !== undefined) {
578
+ extended[prop] = newValue;
579
+ }
580
+ }
581
+ }
582
+ return extended;
583
+ }
503
584
 
504
585
  var strWindow = "window";
586
+ var strNavigator = "navigator";
505
587
  var strConsole = "console";
506
588
  var strJSON = "JSON";
589
+ var strCrypto = "crypto";
590
+ var strMsCrypto = "msCrypto";
591
+ var strMsie = "msie";
592
+ var strTrident = "trident/";
593
+ var _isTrident = null;
594
+ var _navUserAgentCheck = null;
507
595
  function getGlobalInst(name) {
508
596
  var gbl = getGlobal();
509
597
  if (gbl && gbl[name]) {
@@ -517,6 +605,15 @@
517
605
  function hasWindow() {
518
606
  return Boolean(typeof window === strShimObject && window);
519
607
  }
608
+ function hasNavigator() {
609
+ return Boolean(typeof navigator === strShimObject && navigator);
610
+ }
611
+ function getNavigator() {
612
+ if (hasNavigator()) {
613
+ return navigator;
614
+ }
615
+ return getGlobalInst(strNavigator);
616
+ }
520
617
  function getConsole() {
521
618
  if (typeof console !== strShimUndefined) {
522
619
  return console;
@@ -532,9 +629,24 @@
532
629
  }
533
630
  return null;
534
631
  }
632
+ function getCrypto() {
633
+ return getGlobalInst(strCrypto);
634
+ }
635
+ function getMsCrypto() {
636
+ return getGlobalInst(strMsCrypto);
637
+ }
638
+ function isIE() {
639
+ var nav = getNavigator();
640
+ if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
641
+ _navUserAgentCheck = nav.userAgent;
642
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
643
+ _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
644
+ }
645
+ return _isTrident;
646
+ }
535
647
  function dumpObj(object) {
536
648
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
537
- var propertyValueDump = "";
649
+ var propertyValueDump = strEmpty;
538
650
  if (objectTypeDump === "[object Error]") {
539
651
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
540
652
  }
@@ -567,9 +679,9 @@
567
679
  var strWarnToConsole = "warnToConsole";
568
680
  function _sanitizeDiagnosticText(text) {
569
681
  if (text) {
570
- return "\"" + text.replace(/\"/g, "") + "\"";
682
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
571
683
  }
572
- return "";
684
+ return strEmpty;
573
685
  }
574
686
  function _logToConsole(func, message) {
575
687
  var theConsole = getConsole();
@@ -591,12 +703,12 @@
591
703
  _self.message =
592
704
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
593
705
  msgId;
594
- var strProps = "";
706
+ var strProps = strEmpty;
595
707
  if (hasJSON()) {
596
708
  strProps = getJSON().stringify(properties);
597
709
  }
598
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
599
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
710
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
711
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
600
712
  _self.message += diagnosticText;
601
713
  }
602
714
  _InternalLogMessage.dataType = "MessageData";
@@ -626,7 +738,7 @@
626
738
  throw message;
627
739
  }
628
740
  else {
629
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
741
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
630
742
  if (!isUndefined(message.message)) {
631
743
  var logLevel = _self.consoleLoggingLevel();
632
744
  if (isUserAct) {
@@ -644,7 +756,7 @@
644
756
  _self.logInternalMessage(severity, message);
645
757
  }
646
758
  else {
647
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
759
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
648
760
  }
649
761
  }
650
762
  };
@@ -676,13 +788,13 @@
676
788
  if (severity <= _self.telemetryLoggingLevel()) {
677
789
  _self.queue.push(message);
678
790
  _messageCount++;
679
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
791
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
680
792
  }
681
793
  if (_messageCount === _self.maxInternalMessageLimit()) {
682
794
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
683
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
795
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
684
796
  _self.queue.push(throttleMessage);
685
- if (severity === LoggingSeverity.CRITICAL) {
797
+ if (severity === 1 ) {
686
798
  _self.errorToConsole(throttleLimitMessage);
687
799
  }
688
800
  else {
@@ -711,6 +823,10 @@
711
823
  }
712
824
  return DiagnosticLogger;
713
825
  }());
826
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
827
+ if (isUserAct === void 0) { isUserAct = false; }
828
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
829
+ }
714
830
 
715
831
  var strExecutionContextKey = "ctx";
716
832
  var PerfEvent = /** @class */ (function () {
@@ -824,207 +940,616 @@
824
940
  return func();
825
941
  }
826
942
 
827
- var TelemetryPluginChain = /** @class */ (function () {
828
- function TelemetryPluginChain(plugin, defItemCtx) {
829
- var _self = this;
830
- var _nextProxy = null;
831
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
832
- var _hasSetNext = isFunction(plugin.setNextPlugin);
833
- _self._hasRun = false;
834
- _self.getPlugin = function () {
835
- return plugin;
836
- };
837
- _self.getNext = function () {
838
- return _nextProxy;
839
- };
840
- _self.setNext = function (nextPlugin) {
841
- _nextProxy = nextPlugin;
842
- };
843
- _self.processTelemetry = function (env, itemCtx) {
844
- if (!itemCtx) {
845
- itemCtx = defItemCtx;
943
+ var UInt32Mask = 0x100000000;
944
+ var MaxUInt32 = 0xffffffff;
945
+ var _mwcSeeded = false;
946
+ var _mwcW = 123456789;
947
+ var _mwcZ = 987654321;
948
+ function _mwcSeed(seedValue) {
949
+ if (seedValue < 0) {
950
+ seedValue >>>= 0;
951
+ }
952
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
953
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
954
+ _mwcSeeded = true;
955
+ }
956
+ function _autoSeedMwc() {
957
+ try {
958
+ var now = dateNow() & 0x7fffffff;
959
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
960
+ }
961
+ catch (e) {
962
+ }
963
+ }
964
+ function random32(signed) {
965
+ var value = 0;
966
+ var c = getCrypto() || getMsCrypto();
967
+ if (c && c.getRandomValues) {
968
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
969
+ }
970
+ if (value === 0 && isIE()) {
971
+ if (!_mwcSeeded) {
972
+ _autoSeedMwc();
973
+ }
974
+ value = mwcRandom32() & MaxUInt32;
975
+ }
976
+ if (value === 0) {
977
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
978
+ }
979
+ if (!signed) {
980
+ value >>>= 0;
981
+ }
982
+ return value;
983
+ }
984
+ function mwcRandom32(signed) {
985
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
986
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
987
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
988
+ if (!signed) {
989
+ value >>>= 0;
990
+ }
991
+ return value;
992
+ }
993
+ function newId(maxLength) {
994
+ if (maxLength === void 0) { maxLength = 22; }
995
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
996
+ var number = random32() >>> 0;
997
+ var chars = 0;
998
+ var result = strEmpty;
999
+ while (result.length < maxLength) {
1000
+ chars++;
1001
+ result += base64chars.charAt(number & 0x3F);
1002
+ number >>>= 6;
1003
+ if (chars === 5) {
1004
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1005
+ chars = 0;
1006
+ }
1007
+ }
1008
+ return result;
1009
+ }
1010
+
1011
+ var _objDefineProperty = ObjDefineProperty;
1012
+ var version = "2.7.5-nightly.2203-03";
1013
+ var instanceName = "." + newId(6);
1014
+ var _dataUid = 0;
1015
+ function _createAccessor(target, prop, value) {
1016
+ if (_objDefineProperty) {
1017
+ try {
1018
+ _objDefineProperty(target, prop, {
1019
+ value: value,
1020
+ enumerable: false,
1021
+ configurable: true
1022
+ });
1023
+ return true;
1024
+ }
1025
+ catch (e) {
1026
+ }
1027
+ }
1028
+ return false;
1029
+ }
1030
+ function _canAcceptData(target) {
1031
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1032
+ }
1033
+ function _getCache(data, target) {
1034
+ var theCache = target[data.id];
1035
+ if (!theCache) {
1036
+ theCache = {};
1037
+ try {
1038
+ if (_canAcceptData(target)) {
1039
+ if (!_createAccessor(target, data.id, theCache)) {
1040
+ target[data.id] = theCache;
1041
+ }
1042
+ }
1043
+ }
1044
+ catch (e) {
1045
+ }
1046
+ }
1047
+ return theCache;
1048
+ }
1049
+ function createUniqueNamespace(name, includeVersion) {
1050
+ if (includeVersion === void 0) { includeVersion = false; }
1051
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1052
+ }
1053
+ function createElmNodeData(name) {
1054
+ var data = {
1055
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1056
+ accept: function (target) {
1057
+ return _canAcceptData(target);
1058
+ },
1059
+ get: function (target, name, defValue, addDefault) {
1060
+ var theCache = target[data.id];
1061
+ if (!theCache) {
1062
+ if (addDefault) {
1063
+ theCache = _getCache(data, target);
1064
+ theCache[normalizeJsName(name)] = defValue;
1065
+ }
1066
+ return defValue;
1067
+ }
1068
+ return theCache[normalizeJsName(name)];
1069
+ },
1070
+ kill: function (target, name) {
1071
+ if (target && target[name]) {
1072
+ try {
1073
+ delete target[name];
1074
+ }
1075
+ catch (e) {
1076
+ }
846
1077
  }
847
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
848
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
849
- if (plugin && _hasProcessTelemetry) {
850
- _self._hasRun = true;
1078
+ }
1079
+ };
1080
+ return data;
1081
+ }
1082
+
1083
+ var pluginStateData = createElmNodeData("plugin");
1084
+ function _getPluginState(plugin) {
1085
+ return pluginStateData.get(plugin, "state", {}, true);
1086
+ }
1087
+
1088
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1089
+ var strHasRunFlags = "_hasRun";
1090
+ var strGetTelCtx = "_getTelCtx";
1091
+ var _chainId = 0;
1092
+ function _getNextProxyStart(proxy, config, core, startAt) {
1093
+ while (proxy) {
1094
+ if (proxy.getPlugin() === startAt) {
1095
+ return proxy;
1096
+ }
1097
+ proxy = proxy.getNext();
1098
+ }
1099
+ return createTelemetryProxyChain([startAt], config, core);
1100
+ }
1101
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1102
+ var _nextProxy = null;
1103
+ var _onComplete = [];
1104
+ if (startAt !== null) {
1105
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1106
+ }
1107
+ var context = {
1108
+ _next: _moveNext,
1109
+ ctx: {
1110
+ core: function () {
1111
+ return core;
1112
+ },
1113
+ diagLog: function () {
1114
+ return safeGetLogger(core, config);
1115
+ },
1116
+ getCfg: function () {
1117
+ return config;
1118
+ },
1119
+ getExtCfg: _getExtCfg,
1120
+ getConfig: _getConfig,
1121
+ hasNext: function () {
1122
+ return !!_nextProxy;
1123
+ },
1124
+ getNext: function () {
1125
+ return _nextProxy;
1126
+ },
1127
+ setNext: function (nextPlugin) {
1128
+ _nextProxy = nextPlugin;
1129
+ },
1130
+ iterate: _iterateChain,
1131
+ onComplete: _addOnComplete
1132
+ }
1133
+ };
1134
+ function _addOnComplete(onComplete, that) {
1135
+ var args = [];
1136
+ for (var _i = 2; _i < arguments.length; _i++) {
1137
+ args[_i - 2] = arguments[_i];
1138
+ }
1139
+ if (onComplete) {
1140
+ _onComplete.push({
1141
+ func: onComplete,
1142
+ self: !isUndefined(that) ? that : context.ctx,
1143
+ args: args
1144
+ });
1145
+ }
1146
+ }
1147
+ function _moveNext() {
1148
+ var nextProxy = _nextProxy;
1149
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1150
+ if (!nextProxy) {
1151
+ var onComplete = _onComplete;
1152
+ if (onComplete && onComplete.length > 0) {
1153
+ arrForEach(onComplete, function (completeDetails) {
851
1154
  try {
852
- itemCtx.setNext(_nextProxy);
853
- if (_hasSetNext) {
854
- plugin.setNextPlugin(_nextProxy);
855
- }
856
- _nextProxy && (_nextProxy._hasRun = false);
857
- plugin.processTelemetry(env, itemCtx);
1155
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
858
1156
  }
859
- catch (error) {
860
- var hasRun = _nextProxy && _nextProxy._hasRun;
861
- if (!_nextProxy || !hasRun) {
862
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
863
- }
864
- if (_nextProxy && !hasRun) {
865
- _nextProxy.processTelemetry(env, itemCtx);
866
- }
1157
+ catch (e) {
1158
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
867
1159
  }
868
- }
869
- else if (_nextProxy) {
870
- _self._hasRun = true;
871
- _nextProxy.processTelemetry(env, itemCtx);
872
- }
873
- }, function () { return ({ item: env }); }, !(env.sync));
874
- };
1160
+ });
1161
+ _onComplete = [];
1162
+ }
1163
+ }
1164
+ return nextProxy;
875
1165
  }
876
- return TelemetryPluginChain;
877
- }());
878
-
879
- function _createProxyChain(plugins, itemCtx) {
880
- var proxies = [];
881
- if (plugins && plugins.length > 0) {
882
- var lastProxy = null;
883
- for (var idx = 0; idx < plugins.length; idx++) {
884
- var thePlugin = plugins[idx];
885
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
886
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
887
- proxies.push(newProxy);
888
- if (lastProxy) {
889
- lastProxy.setNext(newProxy);
1166
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1167
+ if (defaultValue === void 0) { defaultValue = {}; }
1168
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1169
+ var theConfig;
1170
+ if (config) {
1171
+ var extConfig = config.extensionConfig;
1172
+ if (extConfig && identifier) {
1173
+ theConfig = extConfig[identifier];
1174
+ }
1175
+ }
1176
+ if (!theConfig) {
1177
+ theConfig = defaultValue;
1178
+ }
1179
+ else if (isObject(defaultValue)) {
1180
+ if (mergeDefault !== 0 ) {
1181
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1182
+ if (config && mergeDefault === 2 ) {
1183
+ objForEachKey$1(defaultValue, function (field) {
1184
+ if (isNullOrUndefined(newConfig_1[field])) {
1185
+ var cfgValue = config[field];
1186
+ if (!isNullOrUndefined(cfgValue)) {
1187
+ newConfig_1[field] = cfgValue;
1188
+ }
1189
+ }
1190
+ });
890
1191
  }
891
- lastProxy = newProxy;
892
1192
  }
893
1193
  }
1194
+ return theConfig;
894
1195
  }
895
- return proxies.length > 0 ? proxies[0] : null;
896
- }
897
- function _copyProxyChain(proxy, itemCtx, startAt) {
898
- var plugins = [];
899
- var add = startAt ? false : true;
900
- if (proxy) {
901
- while (proxy) {
902
- var thePlugin = proxy.getPlugin();
903
- if (add || thePlugin === startAt) {
904
- add = true;
905
- plugins.push(thePlugin);
1196
+ function _getConfig(identifier, field, defaultValue) {
1197
+ if (defaultValue === void 0) { defaultValue = false; }
1198
+ var theValue;
1199
+ var extConfig = _getExtCfg(identifier, null);
1200
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1201
+ theValue = extConfig[field];
1202
+ }
1203
+ else if (config && !isNullOrUndefined(config[field])) {
1204
+ theValue = config[field];
1205
+ }
1206
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1207
+ }
1208
+ function _iterateChain(cb) {
1209
+ var nextPlugin;
1210
+ while (!!(nextPlugin = context._next())) {
1211
+ var plugin = nextPlugin.getPlugin();
1212
+ if (plugin) {
1213
+ cb(plugin);
906
1214
  }
907
- proxy = proxy.getNext();
908
1215
  }
909
1216
  }
910
- if (!add) {
911
- plugins.push(startAt);
1217
+ return context;
1218
+ }
1219
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1220
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1221
+ var context = internalContext.ctx;
1222
+ function _processNext(env) {
1223
+ var nextPlugin = internalContext._next();
1224
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1225
+ return !nextPlugin;
1226
+ }
1227
+ function _createNew(plugins, startAt) {
1228
+ if (plugins === void 0) { plugins = null; }
1229
+ if (isArray(plugins)) {
1230
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1231
+ }
1232
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
912
1233
  }
913
- return _createProxyChain(plugins, itemCtx);
1234
+ context.processNext = _processNext;
1235
+ context.createNew = _createNew;
1236
+ return context;
914
1237
  }
915
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
916
- var plugins = srcPlugins;
917
- var add = false;
918
- if (startAt && srcPlugins) {
919
- plugins = [];
920
- arrForEach(srcPlugins, function (thePlugin) {
921
- if (add || thePlugin === startAt) {
922
- add = true;
923
- plugins.push(thePlugin);
1238
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1239
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1240
+ var context = internalContext.ctx;
1241
+ function _processNext(unloadState) {
1242
+ var nextPlugin = internalContext._next();
1243
+ nextPlugin && nextPlugin.unload(context, unloadState);
1244
+ return !nextPlugin;
1245
+ }
1246
+ function _createNew(plugins, startAt) {
1247
+ if (plugins === void 0) { plugins = null; }
1248
+ if (isArray(plugins)) {
1249
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1250
+ }
1251
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1252
+ }
1253
+ context.processNext = _processNext;
1254
+ context.createNew = _createNew;
1255
+ return context;
1256
+ }
1257
+ function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1258
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1259
+ var context = internalContext.ctx;
1260
+ function _processNext(updateState) {
1261
+ return context.iterate(function (plugin) {
1262
+ if (isFunction(plugin[strUpdate])) {
1263
+ plugin[strUpdate](context, updateState);
924
1264
  }
925
1265
  });
926
1266
  }
927
- if (startAt && !add) {
928
- if (!plugins) {
929
- plugins = [];
1267
+ function _createNew(plugins, startAt) {
1268
+ if (plugins === void 0) { plugins = null; }
1269
+ if (isArray(plugins)) {
1270
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
930
1271
  }
931
- plugins.push(startAt);
1272
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
932
1273
  }
933
- return _createProxyChain(plugins, itemCtx);
1274
+ context.processNext = _processNext;
1275
+ context.createNew = _createNew;
1276
+ return context;
934
1277
  }
935
- var ProcessTelemetryContext = /** @class */ (function () {
936
- function ProcessTelemetryContext(plugins, config, core, startAt) {
937
- var _self = this;
938
- var _nextProxy = null;
939
- if (startAt !== null) {
940
- if (plugins && isFunction(plugins.getPlugin)) {
941
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1278
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1279
+ var firstProxy = null;
1280
+ var add = startAt ? false : true;
1281
+ if (isArray(plugins) && plugins.length > 0) {
1282
+ var lastProxy_1 = null;
1283
+ arrForEach(plugins, function (thePlugin) {
1284
+ if (!add && startAt === thePlugin) {
1285
+ add = true;
942
1286
  }
943
- else {
944
- if (startAt) {
945
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1287
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1288
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1289
+ if (!firstProxy) {
1290
+ firstProxy = newProxy;
946
1291
  }
947
- else if (isUndefined(startAt)) {
948
- _nextProxy = _createProxyChain(plugins, _self);
1292
+ if (lastProxy_1) {
1293
+ lastProxy_1._setNext(newProxy);
949
1294
  }
1295
+ lastProxy_1 = newProxy;
950
1296
  }
1297
+ });
1298
+ }
1299
+ if (startAt && !firstProxy) {
1300
+ return createTelemetryProxyChain([startAt], config, core);
1301
+ }
1302
+ return firstProxy;
1303
+ }
1304
+ function createTelemetryPluginProxy(plugin, config, core) {
1305
+ var nextProxy = null;
1306
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1307
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1308
+ var chainId;
1309
+ if (plugin) {
1310
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1311
+ }
1312
+ else {
1313
+ chainId = "Unknown-0-" + _chainId++;
1314
+ }
1315
+ var proxyChain = {
1316
+ getPlugin: function () {
1317
+ return plugin;
1318
+ },
1319
+ getNext: function () {
1320
+ return nextProxy;
1321
+ },
1322
+ processTelemetry: _processTelemetry,
1323
+ unload: _unloadPlugin,
1324
+ update: _updatePlugin,
1325
+ _id: chainId,
1326
+ _setNext: function (nextPlugin) {
1327
+ nextProxy = nextPlugin;
951
1328
  }
952
- _self.core = function () {
953
- return core;
954
- };
955
- _self.diagLog = function () {
956
- return safeGetLogger(core, config);
957
- };
958
- _self.getCfg = function () {
959
- return config;
960
- };
961
- _self.getExtCfg = function (identifier, defaultValue) {
962
- if (defaultValue === void 0) { defaultValue = {}; }
963
- var theConfig;
964
- if (config) {
965
- var extConfig = config.extensionConfig;
966
- if (extConfig && identifier) {
967
- theConfig = extConfig[identifier];
1329
+ };
1330
+ function _getTelCtx() {
1331
+ var itemCtx;
1332
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1333
+ itemCtx = plugin[strGetTelCtx]();
1334
+ }
1335
+ if (!itemCtx) {
1336
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1337
+ }
1338
+ return itemCtx;
1339
+ }
1340
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1341
+ var hasRun = false;
1342
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1343
+ var hasRunContext = itemCtx[strHasRunFlags];
1344
+ if (!hasRunContext) {
1345
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1346
+ }
1347
+ itemCtx.setNext(nextProxy);
1348
+ if (plugin) {
1349
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1350
+ hasRunContext[chainId] = true;
1351
+ try {
1352
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1353
+ if (nextId) {
1354
+ hasRunContext[nextId] = false;
1355
+ }
1356
+ hasRun = processPluginFn(itemCtx);
968
1357
  }
1358
+ catch (error) {
1359
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1360
+ if (hasNextRun) {
1361
+ hasRun = true;
1362
+ }
1363
+ if (!nextProxy || !hasNextRun) {
1364
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1365
+ }
1366
+ }
1367
+ }, details, isAsync);
1368
+ }
1369
+ return hasRun;
1370
+ }
1371
+ function _processTelemetry(env, itemCtx) {
1372
+ itemCtx = itemCtx || _getTelCtx();
1373
+ function _callProcessTelemetry(itemCtx) {
1374
+ if (!plugin || !hasProcessTelemetry) {
1375
+ return false;
969
1376
  }
970
- return (theConfig ? theConfig : defaultValue);
971
- };
972
- _self.getConfig = function (identifier, field, defaultValue) {
973
- if (defaultValue === void 0) { defaultValue = false; }
974
- var theValue;
975
- var extConfig = _self.getExtCfg(identifier, null);
976
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
977
- theValue = extConfig[field];
1377
+ var pluginState = _getPluginState(plugin);
1378
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1379
+ return false;
978
1380
  }
979
- else if (config && !isNullOrUndefined(config[field])) {
980
- theValue = config[field];
1381
+ if (hasSetNext) {
1382
+ plugin.setNextPlugin(nextProxy);
981
1383
  }
982
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
983
- };
984
- _self.hasNext = function () {
985
- return _nextProxy != null;
986
- };
987
- _self.getNext = function () {
988
- return _nextProxy;
989
- };
990
- _self.setNext = function (nextPlugin) {
991
- _nextProxy = nextPlugin;
992
- };
993
- _self.processNext = function (env) {
994
- var nextPlugin = _nextProxy;
995
- if (nextPlugin) {
996
- _nextProxy = nextPlugin.getNext();
997
- nextPlugin.processTelemetry(env, _self);
1384
+ plugin.processTelemetry(env, itemCtx);
1385
+ return true;
1386
+ }
1387
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1388
+ itemCtx.processNext(env);
1389
+ }
1390
+ }
1391
+ function _unloadPlugin(unloadCtx, unloadState) {
1392
+ function _callTeardown() {
1393
+ var hasRun = false;
1394
+ if (plugin) {
1395
+ var pluginState = _getPluginState(plugin);
1396
+ var pluginCore = plugin[strCore] || pluginState.core;
1397
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1398
+ pluginState[strCore] = null;
1399
+ pluginState[strTeardown] = true;
1400
+ pluginState[strIsInitialized] = false;
1401
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1402
+ hasRun = true;
1403
+ }
1404
+ }
998
1405
  }
999
- };
1000
- _self.createNew = function (plugins, startAt) {
1001
- if (plugins === void 0) { plugins = null; }
1002
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1003
- };
1406
+ return hasRun;
1407
+ }
1408
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1409
+ unloadCtx.processNext(unloadState);
1410
+ }
1004
1411
  }
1005
- return ProcessTelemetryContext;
1006
- }());
1412
+ function _updatePlugin(updateCtx, updateState) {
1413
+ function _callUpdate() {
1414
+ var hasRun = false;
1415
+ if (plugin) {
1416
+ var pluginState = _getPluginState(plugin);
1417
+ var pluginCore = plugin[strCore] || pluginState.core;
1418
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1419
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1420
+ hasRun = true;
1421
+ }
1422
+ }
1423
+ }
1424
+ return hasRun;
1425
+ }
1426
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1427
+ updateCtx.processNext(updateState);
1428
+ }
1429
+ }
1430
+ return objFreeze(proxyChain);
1431
+ }
1007
1432
 
1008
1433
  var strExtensionConfig = "extensionConfig";
1009
1434
 
1435
+ function createUnloadHandlerContainer() {
1436
+ var handlers = [];
1437
+ function _addHandler(handler) {
1438
+ if (handler) {
1439
+ handlers.push(handler);
1440
+ }
1441
+ }
1442
+ function _runHandlers(unloadCtx, unloadState) {
1443
+ arrForEach(handlers, function (handler) {
1444
+ try {
1445
+ handler(unloadCtx, unloadState);
1446
+ }
1447
+ catch (e) {
1448
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1449
+ }
1450
+ });
1451
+ handlers = [];
1452
+ }
1453
+ return {
1454
+ add: _addHandler,
1455
+ run: _runHandlers
1456
+ };
1457
+ }
1458
+
1010
1459
  var strGetPlugin = "getPlugin";
1011
1460
  var BaseTelemetryPlugin = /** @class */ (function () {
1012
1461
  function BaseTelemetryPlugin() {
1013
1462
  var _self = this;
1014
- var _isinitialized = false;
1015
- var _rootCtx = null;
1016
- var _nextPlugin = null;
1017
- _self.core = null;
1463
+ var _isinitialized;
1464
+ var _rootCtx;
1465
+ var _nextPlugin;
1466
+ var _unloadHandlerContainer;
1467
+ var _hooks;
1468
+ _initDefaults();
1469
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1470
+ _self.initialize = function (config, core, extensions, pluginChain) {
1471
+ _setDefaults(config, core, pluginChain);
1472
+ _isinitialized = true;
1473
+ };
1474
+ _self.teardown = function (unloadCtx, unloadState) {
1475
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1476
+ return;
1477
+ }
1478
+ var result;
1479
+ var unloadDone = false;
1480
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1481
+ var theUnloadState = unloadState || {
1482
+ reason: 0 ,
1483
+ isAsync: false
1484
+ };
1485
+ function _unloadCallback() {
1486
+ if (!unloadDone) {
1487
+ unloadDone = true;
1488
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1489
+ arrForEach(_hooks, function (fn) {
1490
+ fn.rm();
1491
+ });
1492
+ _hooks = [];
1493
+ if (result === true) {
1494
+ theUnloadCtx.processNext(theUnloadState);
1495
+ }
1496
+ _initDefaults();
1497
+ }
1498
+ }
1499
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1500
+ _unloadCallback();
1501
+ }
1502
+ else {
1503
+ result = true;
1504
+ }
1505
+ return result;
1506
+ };
1507
+ _self.update = function (updateCtx, updateState) {
1508
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
1509
+ return;
1510
+ }
1511
+ var result;
1512
+ var updateDone = false;
1513
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1514
+ var theUpdateState = updateState || {
1515
+ reason: 0
1516
+ };
1517
+ function _updateCallback() {
1518
+ if (!updateDone) {
1519
+ updateDone = true;
1520
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1521
+ }
1522
+ }
1523
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1524
+ _updateCallback();
1525
+ }
1526
+ else {
1527
+ result = true;
1528
+ }
1529
+ return result;
1530
+ };
1531
+ _self._addHook = function (hooks) {
1532
+ if (hooks) {
1533
+ if (isArray(hooks)) {
1534
+ _hooks = _hooks.concat(hooks);
1535
+ }
1536
+ else {
1537
+ _hooks.push(hooks);
1538
+ }
1539
+ }
1540
+ };
1541
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1542
+ });
1018
1543
  _self.diagLog = function (itemCtx) {
1019
- return _self._getTelCtx(itemCtx).diagLog();
1544
+ return _getTelCtx(itemCtx).diagLog();
1020
1545
  };
1021
- _self.isInitialized = function () {
1546
+ _self[strIsInitialized] = function () {
1022
1547
  return _isinitialized;
1023
1548
  };
1024
1549
  _self.setInitialized = function (isInitialized) {
1025
1550
  _isinitialized = isInitialized;
1026
1551
  };
1027
- _self.setNextPlugin = function (next) {
1552
+ _self[strSetNextPlugin] = function (next) {
1028
1553
  _nextPlugin = next;
1029
1554
  };
1030
1555
  _self.processNext = function (env, itemCtx) {
@@ -1035,11 +1560,12 @@
1035
1560
  _nextPlugin.processTelemetry(env, null);
1036
1561
  }
1037
1562
  };
1038
- _self._getTelCtx = function (currentCtx) {
1563
+ _self._getTelCtx = _getTelCtx;
1564
+ function _getTelCtx(currentCtx) {
1039
1565
  if (currentCtx === void 0) { currentCtx = null; }
1040
1566
  var itemCtx = currentCtx;
1041
1567
  if (!itemCtx) {
1042
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1568
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1043
1569
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1044
1570
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1045
1571
  }
@@ -1048,8 +1574,8 @@
1048
1574
  }
1049
1575
  }
1050
1576
  return itemCtx;
1051
- };
1052
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1577
+ }
1578
+ function _setDefaults(config, core, pluginChain) {
1053
1579
  if (config) {
1054
1580
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1055
1581
  }
@@ -1061,16 +1587,109 @@
1061
1587
  nextPlugin = _nextPlugin[strGetPlugin]();
1062
1588
  }
1063
1589
  _self.core = core;
1064
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1065
- _isinitialized = true;
1066
- };
1590
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1591
+ }
1592
+ function _initDefaults() {
1593
+ _isinitialized = false;
1594
+ _self.core = null;
1595
+ _rootCtx = null;
1596
+ _nextPlugin = null;
1597
+ _hooks = [];
1598
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1599
+ }
1067
1600
  }
1068
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1069
- this._baseTelInit(config, core, extensions, pluginChain);
1070
- };
1071
1601
  return BaseTelemetryPlugin;
1072
1602
  }());
1073
1603
 
1604
+ var LoggingSeverity = createEnumStyle({
1605
+ CRITICAL: 1 ,
1606
+ WARNING: 2
1607
+ });
1608
+ var _InternalMessageId = createEnumStyle({
1609
+ BrowserDoesNotSupportLocalStorage: 0 ,
1610
+ BrowserCannotReadLocalStorage: 1 ,
1611
+ BrowserCannotReadSessionStorage: 2 ,
1612
+ BrowserCannotWriteLocalStorage: 3 ,
1613
+ BrowserCannotWriteSessionStorage: 4 ,
1614
+ BrowserFailedRemovalFromLocalStorage: 5 ,
1615
+ BrowserFailedRemovalFromSessionStorage: 6 ,
1616
+ CannotSendEmptyTelemetry: 7 ,
1617
+ ClientPerformanceMathError: 8 ,
1618
+ ErrorParsingAISessionCookie: 9 ,
1619
+ ErrorPVCalc: 10 ,
1620
+ ExceptionWhileLoggingError: 11 ,
1621
+ FailedAddingTelemetryToBuffer: 12 ,
1622
+ FailedMonitorAjaxAbort: 13 ,
1623
+ FailedMonitorAjaxDur: 14 ,
1624
+ FailedMonitorAjaxOpen: 15 ,
1625
+ FailedMonitorAjaxRSC: 16 ,
1626
+ FailedMonitorAjaxSend: 17 ,
1627
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
1628
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
1629
+ FailedToSendQueuedTelemetry: 20 ,
1630
+ FailedToReportDataLoss: 21 ,
1631
+ FlushFailed: 22 ,
1632
+ MessageLimitPerPVExceeded: 23 ,
1633
+ MissingRequiredFieldSpecification: 24 ,
1634
+ NavigationTimingNotSupported: 25 ,
1635
+ OnError: 26 ,
1636
+ SessionRenewalDateIsZero: 27 ,
1637
+ SenderNotInitialized: 28 ,
1638
+ StartTrackEventFailed: 29 ,
1639
+ StopTrackEventFailed: 30 ,
1640
+ StartTrackFailed: 31 ,
1641
+ StopTrackFailed: 32 ,
1642
+ TelemetrySampledAndNotSent: 33 ,
1643
+ TrackEventFailed: 34 ,
1644
+ TrackExceptionFailed: 35 ,
1645
+ TrackMetricFailed: 36 ,
1646
+ TrackPVFailed: 37 ,
1647
+ TrackPVFailedCalc: 38 ,
1648
+ TrackTraceFailed: 39 ,
1649
+ TransmissionFailed: 40 ,
1650
+ FailedToSetStorageBuffer: 41 ,
1651
+ FailedToRestoreStorageBuffer: 42 ,
1652
+ InvalidBackendResponse: 43 ,
1653
+ FailedToFixDepricatedValues: 44 ,
1654
+ InvalidDurationValue: 45 ,
1655
+ TelemetryEnvelopeInvalid: 46 ,
1656
+ CreateEnvelopeError: 47 ,
1657
+ CannotSerializeObject: 48 ,
1658
+ CannotSerializeObjectNonSerializable: 49 ,
1659
+ CircularReferenceDetected: 50 ,
1660
+ ClearAuthContextFailed: 51 ,
1661
+ ExceptionTruncated: 52 ,
1662
+ IllegalCharsInName: 53 ,
1663
+ ItemNotInArray: 54 ,
1664
+ MaxAjaxPerPVExceeded: 55 ,
1665
+ MessageTruncated: 56 ,
1666
+ NameTooLong: 57 ,
1667
+ SampleRateOutOfRange: 58 ,
1668
+ SetAuthContextFailed: 59 ,
1669
+ SetAuthContextFailedAccountName: 60 ,
1670
+ StringValueTooLong: 61 ,
1671
+ StartCalledMoreThanOnce: 62 ,
1672
+ StopCalledWithoutStart: 63 ,
1673
+ TelemetryInitializerFailed: 64 ,
1674
+ TrackArgumentsNotSpecified: 65 ,
1675
+ UrlTooLong: 66 ,
1676
+ SessionStorageBufferFull: 67 ,
1677
+ CannotAccessCookie: 68 ,
1678
+ IdTooLong: 69 ,
1679
+ InvalidEvent: 70 ,
1680
+ FailedMonitorAjaxSetRequestHeader: 71 ,
1681
+ SendBrowserInfoOnUserInit: 72 ,
1682
+ PluginException: 73 ,
1683
+ NotificationException: 74 ,
1684
+ SnippetScriptLoadFailure: 99 ,
1685
+ InvalidInstrumentationKey: 100 ,
1686
+ CannotParseAiBlobValue: 101 ,
1687
+ InvalidContentBlob: 102 ,
1688
+ TrackPageActionEventFailed: 103 ,
1689
+ FailedAddingCustomDefinedRequestContext: 104 ,
1690
+ InMemoryStorageBufferFull: 105
1691
+ });
1692
+
1074
1693
  var SeverityLevel;
1075
1694
  (function (SeverityLevel) {
1076
1695
  SeverityLevel[SeverityLevel["Verbose"] = 0] = "Verbose";
@@ -1114,11 +1733,12 @@
1114
1733
  var _this = _super.call(this) || this;
1115
1734
  _this.identifier = "AppInsightsReactNativePlugin";
1116
1735
  _this.priority = 140;
1117
- var _device = {};
1118
- var _config = config || _getDefaultConfig();
1736
+ var _device;
1737
+ var _config;
1119
1738
  var _analyticsPlugin;
1120
1739
  var _defaultHandler;
1121
1740
  dynamicProto(ReactNativePlugin, _this, function (_self, _base) {
1741
+ _initDefaults();
1122
1742
  _self.initialize = function (config,
1123
1743
  core, extensions) {
1124
1744
  if (!_self.isInitialized()) {
@@ -1167,6 +1787,16 @@
1167
1787
  _self.diagLog().warnToConsole("Failed to get DeviceInfo: " + getExceptionName(e) + " - " + dumpObj(e));
1168
1788
  }
1169
1789
  };
1790
+ _self._doTeardown = function (unloadCtx, unloadState, asyncCallback) {
1791
+ _resetGlobalErrorHandler();
1792
+ _initDefaults();
1793
+ };
1794
+ function _initDefaults() {
1795
+ _device = {};
1796
+ _config = config || _getDefaultConfig();
1797
+ _analyticsPlugin = null;
1798
+ _defaultHandler = null;
1799
+ }
1170
1800
  function _applyDeviceContext(item) {
1171
1801
  if (_device) {
1172
1802
  item.ext = item.ext || {};
@@ -1192,9 +1822,15 @@
1192
1822
  var _global = _getGlobal();
1193
1823
  if (_global && _global.ErrorUtils) {
1194
1824
  _defaultHandler = (typeof _global.ErrorUtils.getGlobalHandler === "function" && _global.ErrorUtils.getGlobalHandler()) || _global.ErrorUtils._globalHandler;
1195
- _global.ErrorUtils.setGlobalHandler(_trackException.bind(_this));
1825
+ _global.ErrorUtils.setGlobalHandler(_trackException);
1196
1826
  }
1197
1827
  };
1828
+ function _resetGlobalErrorHandler() {
1829
+ var _global = _getGlobal();
1830
+ if (_global && _global.ErrorUtils && _global.ErrorUtils.getGlobalHandler() === _trackException) {
1831
+ _global.ErrorUtils.setGlobalHandler(_defaultHandler || null);
1832
+ }
1833
+ }
1198
1834
  function _trackException(e, isFatal) {
1199
1835
  var exception = { exception: e, severityLevel: SeverityLevel.Error };
1200
1836
  if (_analyticsPlugin) {