@microsoft/applicationinsights-web-basic 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-06

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.
package/browser/aib.2.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript Web SDK - Basic, 2.8.0-nightly.2202-06
2
+ * Application Insights JavaScript Web SDK - Basic, 2.8.0-nightly.2204-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -8,107 +8,6 @@
8
8
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Microsoft = global.Microsoft || {}, global.Microsoft.ApplicationInsights = global.Microsoft.ApplicationInsights || {})));
9
9
  })(this, (function (exports) { 'use strict';
10
10
 
11
- var EventsDiscardedReason = {
12
- Unknown: 0,
13
- NonRetryableStatus: 1,
14
- InvalidEvent: 2,
15
- SizeLimitExceeded: 3,
16
- KillSwitch: 4,
17
- QueueFull: 5
18
- };
19
-
20
- var strShimFunction = "function";
21
- var strShimObject = "object";
22
- var strShimUndefined = "undefined";
23
- var strShimPrototype = "prototype";
24
- var strShimHasOwnProperty = "hasOwnProperty";
25
- var ObjClass = Object;
26
- var ObjProto = ObjClass[strShimPrototype];
27
- var ObjAssign = ObjClass["assign"];
28
- var ObjCreate = ObjClass["create"];
29
- var ObjDefineProperty = ObjClass["defineProperty"];
30
- var ObjHasOwnProperty = ObjProto[strShimHasOwnProperty];
31
-
32
- var _cachedGlobal = null;
33
- function getGlobal(useCached) {
34
- if (useCached === void 0) { useCached = true; }
35
- if (!_cachedGlobal || !useCached) {
36
- if (typeof globalThis !== strShimUndefined && globalThis) {
37
- _cachedGlobal = globalThis;
38
- }
39
- if (typeof self !== strShimUndefined && self) {
40
- _cachedGlobal = self;
41
- }
42
- if (typeof window !== strShimUndefined && window) {
43
- _cachedGlobal = window;
44
- }
45
- if (typeof global !== strShimUndefined && global) {
46
- _cachedGlobal = global;
47
- }
48
- }
49
- return _cachedGlobal;
50
- }
51
- function throwTypeError(message) {
52
- throw new TypeError(message);
53
- }
54
- function objCreateFn(obj) {
55
- var func = ObjCreate;
56
- if (func) {
57
- return func(obj);
58
- }
59
- if (obj == null) {
60
- return {};
61
- }
62
- var type = typeof obj;
63
- if (type !== strShimObject && type !== strShimFunction) {
64
- throwTypeError("Object prototype may only be an Object:" + obj);
65
- }
66
- function tmpFunc() { }
67
- tmpFunc[strShimPrototype] = obj;
68
- return new tmpFunc();
69
- }
70
-
71
- (getGlobal() || {})["Symbol"];
72
- (getGlobal() || {})["Reflect"];
73
- var __objAssignFnImpl = function (t) {
74
- for (var s, i = 1, n = arguments.length; i < n; i++) {
75
- s = arguments[i];
76
- for (var p in s) {
77
- if (ObjProto[strShimHasOwnProperty].call(s, p)) {
78
- t[p] = s[p];
79
- }
80
- }
81
- }
82
- return t;
83
- };
84
- var __assignFn = ObjAssign || __objAssignFnImpl;
85
- var extendStaticsFn = function (d, b) {
86
- extendStaticsFn = ObjClass["setPrototypeOf"] ||
87
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
88
- function (d, b) {
89
- for (var p in b) {
90
- if (b[strShimHasOwnProperty](p)) {
91
- d[p] = b[p];
92
- }
93
- }
94
- };
95
- return extendStaticsFn(d, b);
96
- };
97
- function __extendsFn(d, b) {
98
- if (typeof b !== strShimFunction && b !== null) {
99
- throwTypeError("Class extends value " + String(b) + " is not a constructor or null");
100
- }
101
- extendStaticsFn(d, b);
102
- function __() { this.constructor = d; }
103
- d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
104
- }
105
- function __spreadArrayFn(to, from) {
106
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) {
107
- to[j] = from[i];
108
- }
109
- return to;
110
- }
111
-
112
11
  /*!
113
12
  * Microsoft Dynamic Proto Utility, 1.1.4
114
13
  * Copyright (c) Microsoft and contributors. All rights reserved.
@@ -124,11 +23,11 @@
124
23
  var DynAllowInstChkTag = DynInstChkTag;
125
24
  var DynProtoDefaultOptions = '_dfOpts';
126
25
  var UnknownValue = '_unknown_';
127
- var str__Proto = "__proto__";
26
+ var str__Proto$1 = "__proto__";
128
27
  var strUseBaseInst = 'useBaseInst';
129
28
  var strSetInstFuncs = 'setInstFuncs';
130
29
  var Obj = Object;
131
- var _objGetPrototypeOf = Obj["getPrototypeOf"];
30
+ var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
132
31
  var _dynamicNames = 0;
133
32
  function _hasOwnProperty(obj, prop) {
134
33
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -139,12 +38,12 @@
139
38
  function _isObjectArrayOrFunctionPrototype(target) {
140
39
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
141
40
  }
142
- function _getObjProto(target) {
41
+ function _getObjProto$1(target) {
143
42
  if (target) {
144
- if (_objGetPrototypeOf) {
145
- return _objGetPrototypeOf(target);
43
+ if (_objGetPrototypeOf$1) {
44
+ return _objGetPrototypeOf$1(target);
146
45
  }
147
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
46
+ var newProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
148
47
  if (newProto) {
149
48
  return newProto;
150
49
  }
@@ -210,16 +109,16 @@
210
109
  _forEachProp(instFuncs, function (name) {
211
110
  baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
212
111
  });
213
- var baseProto = _getObjProto(classProto);
112
+ var baseProto = _getObjProto$1(classProto);
214
113
  var visited = [];
215
114
  while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
216
115
  _forEachProp(baseProto, function (name) {
217
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
116
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf$1)) {
218
117
  baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
219
118
  }
220
119
  });
221
120
  visited.push(baseProto);
222
- baseProto = _getObjProto(baseProto);
121
+ baseProto = _getObjProto$1(baseProto);
223
122
  }
224
123
  return baseFuncs;
225
124
  }
@@ -233,7 +132,7 @@
233
132
  }
234
133
  if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
235
134
  var canAddInst = !_hasOwnProperty(target, funcName);
236
- var objProto = _getObjProto(target);
135
+ var objProto = _getObjProto$1(target);
237
136
  var visited = [];
238
137
  while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
239
138
  var protoFunc = objProto[funcName];
@@ -242,7 +141,7 @@
242
141
  break;
243
142
  }
244
143
  visited.push(objProto);
245
- objProto = _getObjProto(objProto);
144
+ objProto = _getObjProto$1(objProto);
246
145
  }
247
146
  try {
248
147
  if (canAddInst) {
@@ -260,7 +159,7 @@
260
159
  function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
261
160
  var protoFunc = proto[funcName];
262
161
  if (protoFunc === currentDynProtoProxy) {
263
- protoFunc = _getObjProto(proto)[funcName];
162
+ protoFunc = _getObjProto$1(proto)[funcName];
264
163
  }
265
164
  if (typeof protoFunc !== strFunction) {
266
165
  _throwTypeError("[" + funcName + "] is not a " + strFunction);
@@ -294,15 +193,15 @@
294
193
  }
295
194
  }
296
195
  function _checkPrototype(classProto, thisTarget) {
297
- if (_objGetPrototypeOf) {
196
+ if (_objGetPrototypeOf$1) {
298
197
  var visited = [];
299
- var thisProto = _getObjProto(thisTarget);
198
+ var thisProto = _getObjProto$1(thisTarget);
300
199
  while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
301
200
  if (thisProto === classProto) {
302
201
  return true;
303
202
  }
304
203
  visited.push(thisProto);
305
- thisProto = _getObjProto(thisProto);
204
+ thisProto = _getObjProto$1(thisProto);
306
205
  }
307
206
  }
308
207
  return false;
@@ -338,7 +237,7 @@
338
237
  var instFuncs = _getInstanceFuncs(target);
339
238
  var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
340
239
  delegateFunc(target, baseFuncs);
341
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
240
+ var setInstanceFunc = !!_objGetPrototypeOf$1 && !!perfOptions[strSetInstFuncs];
342
241
  if (setInstanceFunc && options) {
343
242
  setInstanceFunc = !!options[strSetInstFuncs];
344
243
  }
@@ -350,99 +249,123 @@
350
249
  };
351
250
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
352
251
 
353
- var LoggingSeverity;
354
- (function (LoggingSeverity) {
355
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
356
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
357
- })(LoggingSeverity || (LoggingSeverity = {}));
358
- var _InternalMessageId = {
359
- BrowserDoesNotSupportLocalStorage: 0,
360
- BrowserCannotReadLocalStorage: 1,
361
- BrowserCannotReadSessionStorage: 2,
362
- BrowserCannotWriteLocalStorage: 3,
363
- BrowserCannotWriteSessionStorage: 4,
364
- BrowserFailedRemovalFromLocalStorage: 5,
365
- BrowserFailedRemovalFromSessionStorage: 6,
366
- CannotSendEmptyTelemetry: 7,
367
- ClientPerformanceMathError: 8,
368
- ErrorParsingAISessionCookie: 9,
369
- ErrorPVCalc: 10,
370
- ExceptionWhileLoggingError: 11,
371
- FailedAddingTelemetryToBuffer: 12,
372
- FailedMonitorAjaxAbort: 13,
373
- FailedMonitorAjaxDur: 14,
374
- FailedMonitorAjaxOpen: 15,
375
- FailedMonitorAjaxRSC: 16,
376
- FailedMonitorAjaxSend: 17,
377
- FailedMonitorAjaxGetCorrelationHeader: 18,
378
- FailedToAddHandlerForOnBeforeUnload: 19,
379
- FailedToSendQueuedTelemetry: 20,
380
- FailedToReportDataLoss: 21,
381
- FlushFailed: 22,
382
- MessageLimitPerPVExceeded: 23,
383
- MissingRequiredFieldSpecification: 24,
384
- NavigationTimingNotSupported: 25,
385
- OnError: 26,
386
- SessionRenewalDateIsZero: 27,
387
- SenderNotInitialized: 28,
388
- StartTrackEventFailed: 29,
389
- StopTrackEventFailed: 30,
390
- StartTrackFailed: 31,
391
- StopTrackFailed: 32,
392
- TelemetrySampledAndNotSent: 33,
393
- TrackEventFailed: 34,
394
- TrackExceptionFailed: 35,
395
- TrackMetricFailed: 36,
396
- TrackPVFailed: 37,
397
- TrackPVFailedCalc: 38,
398
- TrackTraceFailed: 39,
399
- TransmissionFailed: 40,
400
- FailedToSetStorageBuffer: 41,
401
- FailedToRestoreStorageBuffer: 42,
402
- InvalidBackendResponse: 43,
403
- FailedToFixDepricatedValues: 44,
404
- InvalidDurationValue: 45,
405
- TelemetryEnvelopeInvalid: 46,
406
- CreateEnvelopeError: 47,
407
- CannotSerializeObject: 48,
408
- CannotSerializeObjectNonSerializable: 49,
409
- CircularReferenceDetected: 50,
410
- ClearAuthContextFailed: 51,
411
- ExceptionTruncated: 52,
412
- IllegalCharsInName: 53,
413
- ItemNotInArray: 54,
414
- MaxAjaxPerPVExceeded: 55,
415
- MessageTruncated: 56,
416
- NameTooLong: 57,
417
- SampleRateOutOfRange: 58,
418
- SetAuthContextFailed: 59,
419
- SetAuthContextFailedAccountName: 60,
420
- StringValueTooLong: 61,
421
- StartCalledMoreThanOnce: 62,
422
- StopCalledWithoutStart: 63,
423
- TelemetryInitializerFailed: 64,
424
- TrackArgumentsNotSpecified: 65,
425
- UrlTooLong: 66,
426
- SessionStorageBufferFull: 67,
427
- CannotAccessCookie: 68,
428
- IdTooLong: 69,
429
- InvalidEvent: 70,
430
- FailedMonitorAjaxSetRequestHeader: 71,
431
- SendBrowserInfoOnUserInit: 72,
432
- PluginException: 73,
433
- NotificationException: 74,
434
- SnippetScriptLoadFailure: 99,
435
- InvalidInstrumentationKey: 100,
436
- CannotParseAiBlobValue: 101,
437
- InvalidContentBlob: 102,
438
- TrackPageActionEventFailed: 103,
439
- FailedAddingCustomDefinedRequestContext: 104,
440
- InMemoryStorageBufferFull: 105
252
+ var strShimFunction = "function";
253
+ var strShimObject = "object";
254
+ var strShimUndefined = "undefined";
255
+ var strShimPrototype = "prototype";
256
+ var strShimHasOwnProperty = "hasOwnProperty";
257
+ var ObjClass = Object;
258
+ var ObjProto = ObjClass[strShimPrototype];
259
+ var ObjAssign = ObjClass["assign"];
260
+ var ObjCreate = ObjClass["create"];
261
+ var ObjDefineProperty = ObjClass["defineProperty"];
262
+ var ObjHasOwnProperty = ObjProto[strShimHasOwnProperty];
263
+
264
+ var _cachedGlobal = null;
265
+ function getGlobal(useCached) {
266
+ if (useCached === void 0) { useCached = true; }
267
+ if (!_cachedGlobal || !useCached) {
268
+ if (typeof globalThis !== strShimUndefined && globalThis) {
269
+ _cachedGlobal = globalThis;
270
+ }
271
+ if (typeof self !== strShimUndefined && self) {
272
+ _cachedGlobal = self;
273
+ }
274
+ if (typeof window !== strShimUndefined && window) {
275
+ _cachedGlobal = window;
276
+ }
277
+ if (typeof global !== strShimUndefined && global) {
278
+ _cachedGlobal = global;
279
+ }
280
+ }
281
+ return _cachedGlobal;
282
+ }
283
+ function throwTypeError(message) {
284
+ throw new TypeError(message);
285
+ }
286
+ function objCreateFn(obj) {
287
+ var func = ObjCreate;
288
+ if (func) {
289
+ return func(obj);
290
+ }
291
+ if (obj == null) {
292
+ return {};
293
+ }
294
+ var type = typeof obj;
295
+ if (type !== strShimObject && type !== strShimFunction) {
296
+ throwTypeError("Object prototype may only be an Object:" + obj);
297
+ }
298
+ function tmpFunc() { }
299
+ tmpFunc[strShimPrototype] = obj;
300
+ return new tmpFunc();
301
+ }
302
+
303
+ (getGlobal() || {})["Symbol"];
304
+ (getGlobal() || {})["Reflect"];
305
+ var __objAssignFnImpl = function (t) {
306
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
307
+ s = arguments[i];
308
+ for (var p in s) {
309
+ if (ObjProto[strShimHasOwnProperty].call(s, p)) {
310
+ t[p] = s[p];
311
+ }
312
+ }
313
+ }
314
+ return t;
441
315
  };
316
+ var __assignFn = ObjAssign || __objAssignFnImpl;
317
+ var extendStaticsFn = function (d, b) {
318
+ extendStaticsFn = ObjClass["setPrototypeOf"] ||
319
+ ({ __proto__: [] } instanceof Array && function (d, b) {
320
+ d.__proto__ = b;
321
+ }) ||
322
+ function (d, b) {
323
+ for (var p in b) {
324
+ if (b[strShimHasOwnProperty](p)) {
325
+ d[p] = b[p];
326
+ }
327
+ }
328
+ };
329
+ return extendStaticsFn(d, b);
330
+ };
331
+ function __extendsFn(d, b) {
332
+ if (typeof b !== strShimFunction && b !== null) {
333
+ throwTypeError("Class extends value " + String(b) + " is not a constructor or null");
334
+ }
335
+ extendStaticsFn(d, b);
336
+ function __() {
337
+ this.constructor = d;
338
+ }
339
+ d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
340
+ }
341
+ function __spreadArrayFn(to, from) {
342
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) {
343
+ to[j] = from[i];
344
+ }
345
+ return to;
346
+ }
347
+
348
+ var strEmpty$1 = "";
349
+ var strProcessTelemetry = "processTelemetry";
350
+ var strPriority = "priority";
351
+ var strSetNextPlugin = "setNextPlugin";
352
+ var strIsInitialized = "isInitialized";
353
+ var strTeardown = "teardown";
354
+ var strCore = "core";
355
+ var strUpdate = "update";
356
+ var strDisabled = "disabled";
357
+ var strDoTeardown = "_doTeardown";
358
+ var strProcessNext = "processNext";
359
+ var strResume = "resume";
360
+ var strPause = "pause";
361
+ var strNotificationListener = "NotificationListener";
362
+ var strAddNotificationListener = "add" + strNotificationListener;
363
+ var strRemoveNotificationListener = "remove" + strNotificationListener;
364
+ var strEventsSent = "eventsSent";
365
+ var strEventsDiscarded = "eventsDiscarded";
366
+ var strEventsSendRequest = "eventsSendRequest";
367
+ var strPerfEvent = "perfEvent";
442
368
 
443
- var strOnPrefix = "on";
444
- var strAttachEvent = "attachEvent";
445
- var strAddEventHelper = "addEventListener";
446
369
  var strToISOString = "toISOString";
447
370
  var cStrEndsWith = "endsWith";
448
371
  var cStrStartsWith = "startsWith";
@@ -451,8 +374,10 @@
451
374
  var strReduce = "reduce";
452
375
  var cStrTrim = "trim";
453
376
  var strToString = "toString";
454
- var _objDefineProperty = ObjDefineProperty;
455
- ObjClass.freeze;
377
+ var str__Proto = "__proto__";
378
+ var strConstructor = "constructor";
379
+ var _objDefineProperty$1 = ObjDefineProperty;
380
+ var _objFreeze = ObjClass.freeze;
456
381
  ObjClass.seal;
457
382
  var _objKeys = ObjClass.keys;
458
383
  var StringProto = String[strShimPrototype];
@@ -464,7 +389,23 @@
464
389
  var _isArray = Array.isArray;
465
390
  var _objToString = ObjProto[strToString];
466
391
  var _fnToString = ObjHasOwnProperty[strToString];
467
- _fnToString.call(ObjClass);
392
+ var _objFunctionString = _fnToString.call(ObjClass);
393
+ var rCamelCase = /-([a-z])/g;
394
+ var rNormalizeInvalid = /([^\w\d_$])/g;
395
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
396
+ var _objGetPrototypeOf = Object["getPrototypeOf"];
397
+ function _getObjProto(target) {
398
+ if (target) {
399
+ if (_objGetPrototypeOf) {
400
+ return _objGetPrototypeOf(target);
401
+ }
402
+ var newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
403
+ if (newProto) {
404
+ return newProto;
405
+ }
406
+ }
407
+ return null;
408
+ }
468
409
  function isTypeof(value, theType) {
469
410
  return typeof value === theType;
470
411
  }
@@ -486,24 +427,18 @@
486
427
  function isFunction(value) {
487
428
  return !!(value && typeof value === strShimFunction);
488
429
  }
489
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
490
- if (useCapture === void 0) { useCapture = false; }
491
- var result = false;
492
- if (!isNullOrUndefined(obj)) {
493
- try {
494
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
495
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
496
- result = true;
497
- }
498
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
499
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
500
- result = true;
501
- }
502
- }
503
- catch (e) {
504
- }
430
+ function normalizeJsName(name) {
431
+ var value = name;
432
+ if (value && isString(value)) {
433
+ value = value.replace(rCamelCase, function (_all, letter) {
434
+ return letter.toUpperCase();
435
+ });
436
+ value = value.replace(rNormalizeInvalid, "_");
437
+ value = value.replace(rLeadingNumeric, function (_all, match) {
438
+ return "_" + match;
439
+ });
505
440
  }
506
- return result;
441
+ return value;
507
442
  }
508
443
  function objForEachKey(target, callbackfn) {
509
444
  if (target) {
@@ -562,6 +497,22 @@
562
497
  function isBoolean(value) {
563
498
  return typeof value === "boolean";
564
499
  }
500
+ function isPlainObject(value) {
501
+ var result = false;
502
+ if (value && typeof value === "object") {
503
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
504
+ if (!proto) {
505
+ result = true;
506
+ }
507
+ else {
508
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
509
+ proto = proto[strConstructor];
510
+ }
511
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
512
+ }
513
+ }
514
+ return result;
515
+ }
565
516
  function toISOString(date) {
566
517
  if (date) {
567
518
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -707,7 +658,7 @@
707
658
  return result;
708
659
  }
709
660
  function objDefineAccessors(target, prop, getProp, setProp) {
710
- if (_objDefineProperty) {
661
+ if (_objDefineProperty$1) {
711
662
  try {
712
663
  var descriptor = {
713
664
  enumerable: true,
@@ -719,7 +670,7 @@
719
670
  if (setProp) {
720
671
  descriptor.set = setProp;
721
672
  }
722
- _objDefineProperty(target, prop, descriptor);
673
+ _objDefineProperty$1(target, prop, descriptor);
723
674
  return true;
724
675
  }
725
676
  catch (e) {
@@ -727,6 +678,20 @@
727
678
  }
728
679
  return false;
729
680
  }
681
+ function _doNothing(value) {
682
+ return value;
683
+ }
684
+ function deepFreeze(obj) {
685
+ if (_objFreeze) {
686
+ objForEachKey(obj, function (name, value) {
687
+ if (isArray(value) || isObject(value)) {
688
+ _objFreeze(value);
689
+ }
690
+ });
691
+ }
692
+ return objFreeze(obj);
693
+ }
694
+ var objFreeze = _objFreeze || _doNothing;
730
695
  function dateNow() {
731
696
  var dt = Date;
732
697
  return dt.now ? dt.now() : new dt().getTime();
@@ -735,7 +700,7 @@
735
700
  if (isError(object)) {
736
701
  return object.name;
737
702
  }
738
- return "";
703
+ return strEmpty$1;
739
704
  }
740
705
  function setValue(target, field, value, valChk, srcChk) {
741
706
  var theValue = value;
@@ -771,6 +736,42 @@
771
736
  function throwError(message) {
772
737
  throw new Error(message);
773
738
  }
739
+ function _createProxyFunction(source, funcName) {
740
+ var srcFunc = null;
741
+ var src = null;
742
+ if (isFunction(source)) {
743
+ srcFunc = source;
744
+ }
745
+ else {
746
+ src = source;
747
+ }
748
+ return function () {
749
+ var originalArguments = arguments;
750
+ if (srcFunc) {
751
+ src = srcFunc();
752
+ }
753
+ if (src) {
754
+ return src[funcName].apply(src, originalArguments);
755
+ }
756
+ };
757
+ }
758
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
759
+ if (target && name && source) {
760
+ if (overwriteTarget !== false || isUndefined(target[name])) {
761
+ target[name] = _createProxyFunction(source, theFunc);
762
+ }
763
+ }
764
+ }
765
+ function proxyFunctions(target, source, functionsToProxy, overwriteTarget) {
766
+ if (target && source && isObject(target) && isArray(functionsToProxy)) {
767
+ arrForEach(functionsToProxy, function (theFuncName) {
768
+ if (isString(theFuncName)) {
769
+ proxyFunctionAs(target, theFuncName, source, theFuncName, overwriteTarget);
770
+ }
771
+ });
772
+ }
773
+ return target;
774
+ }
774
775
  function createClassFromInterface(defaults) {
775
776
  return /** @class */ (function () {
776
777
  function class_1() {
@@ -790,8 +791,61 @@
790
791
  }
791
792
  return theObject;
792
793
  }
794
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
795
+ var theArgs = arguments;
796
+ var extended = theArgs[0] || {};
797
+ var argLen = theArgs.length;
798
+ var deep = false;
799
+ var idx = 1;
800
+ if (argLen > 0 && isBoolean(extended)) {
801
+ deep = extended;
802
+ extended = theArgs[idx] || {};
803
+ idx++;
804
+ }
805
+ if (!isObject(extended)) {
806
+ extended = {};
807
+ }
808
+ for (; idx < argLen; idx++) {
809
+ var arg = theArgs[idx];
810
+ var isArgArray = isArray(arg);
811
+ var isArgObj = isObject(arg);
812
+ for (var prop in arg) {
813
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
814
+ if (!propOk) {
815
+ continue;
816
+ }
817
+ var newValue = arg[prop];
818
+ var isNewArray = void 0;
819
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
820
+ var clone = extended[prop];
821
+ if (isNewArray) {
822
+ if (!isArray(clone)) {
823
+ clone = [];
824
+ }
825
+ }
826
+ else if (!isPlainObject(clone)) {
827
+ clone = {};
828
+ }
829
+ newValue = objExtend(deep, clone, newValue);
830
+ }
831
+ if (newValue !== undefined) {
832
+ extended[prop] = newValue;
833
+ }
834
+ }
835
+ }
836
+ return extended;
837
+ }
793
838
 
794
- var strWindow = "window";
839
+ function createEnumStyle(values) {
840
+ var enumClass = {};
841
+ objForEachKey(values, function (field, value) {
842
+ enumClass[field] = value;
843
+ enumClass[value] = field;
844
+ });
845
+ return deepFreeze(enumClass);
846
+ }
847
+
848
+ var strWindow = "window";
795
849
  var strDocument = "document";
796
850
  var strDocumentMode = "documentMode";
797
851
  var strNavigator = "navigator";
@@ -803,6 +857,7 @@
803
857
  var strMsCrypto = "msCrypto";
804
858
  var strMsie = "msie";
805
859
  var strTrident = "trident/";
860
+ var strXMLHttpRequest = "XMLHttpRequest";
806
861
  var _isTrident = null;
807
862
  var _navUserAgentCheck = null;
808
863
  var _enableMocks = false;
@@ -910,7 +965,7 @@
910
965
  var nav = getNavigator();
911
966
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
912
967
  _navUserAgentCheck = nav.userAgent;
913
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
968
+ var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
914
969
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
915
970
  }
916
971
  return _isTrident;
@@ -919,9 +974,9 @@
919
974
  if (userAgentStr === void 0) { userAgentStr = null; }
920
975
  if (!userAgentStr) {
921
976
  var navigator_1 = getNavigator() || {};
922
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
977
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
923
978
  }
924
- var ua = (userAgentStr || "").toLowerCase();
979
+ var ua = (userAgentStr || strEmpty$1).toLowerCase();
925
980
  if (strContains(ua, strMsie)) {
926
981
  var doc = getDocument() || {};
927
982
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -936,7 +991,7 @@
936
991
  }
937
992
  function dumpObj(object) {
938
993
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
939
- var propertyValueDump = "";
994
+ var propertyValueDump = strEmpty$1;
940
995
  if (objectTypeDump === "[object Error]") {
941
996
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
942
997
  }
@@ -954,8 +1009,7 @@
954
1009
  function isFetchSupported(withKeepAlive) {
955
1010
  var isSupported = false;
956
1011
  try {
957
- var fetchApi = getGlobalInst("fetch");
958
- isSupported = !!fetchApi;
1012
+ isSupported = !!getGlobalInst("fetch");
959
1013
  var request = getGlobalInst("Request");
960
1014
  if (isSupported && withKeepAlive && request) {
961
1015
  isSupported = _hasProperty(request, "keepalive");
@@ -967,9 +1021,9 @@
967
1021
  }
968
1022
  function useXDomainRequest() {
969
1023
  if (_useXDomainRequest === null) {
970
- _useXDomainRequest = (typeof XDomainRequest !== "undefined");
1024
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
971
1025
  if (_useXDomainRequest && isXhrSupported()) {
972
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
1026
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
973
1027
  }
974
1028
  }
975
1029
  return _useXDomainRequest;
@@ -977,7 +1031,7 @@
977
1031
  function isXhrSupported() {
978
1032
  var isSupported = false;
979
1033
  try {
980
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
1034
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
981
1035
  isSupported = !!xmlHttpRequest;
982
1036
  }
983
1037
  catch (e) {
@@ -1031,9 +1085,9 @@
1031
1085
  var strWarnToConsole = "warnToConsole";
1032
1086
  function _sanitizeDiagnosticText(text) {
1033
1087
  if (text) {
1034
- return "\"" + text.replace(/\"/g, "") + "\"";
1088
+ return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
1035
1089
  }
1036
- return "";
1090
+ return strEmpty$1;
1037
1091
  }
1038
1092
  function _logToConsole(func, message) {
1039
1093
  var theConsole = getConsole();
@@ -1055,12 +1109,12 @@
1055
1109
  _self.message =
1056
1110
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
1057
1111
  msgId;
1058
- var strProps = "";
1112
+ var strProps = strEmpty$1;
1059
1113
  if (hasJSON()) {
1060
1114
  strProps = getJSON().stringify(properties);
1061
1115
  }
1062
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
1063
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
1116
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
1117
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
1064
1118
  _self.message += diagnosticText;
1065
1119
  }
1066
1120
  _InternalLogMessage.dataType = "MessageData";
@@ -1090,7 +1144,7 @@
1090
1144
  throw message;
1091
1145
  }
1092
1146
  else {
1093
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
1147
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
1094
1148
  if (!isUndefined(message.message)) {
1095
1149
  var logLevel = _self.consoleLoggingLevel();
1096
1150
  if (isUserAct) {
@@ -1108,7 +1162,7 @@
1108
1162
  _self.logInternalMessage(severity, message);
1109
1163
  }
1110
1164
  else {
1111
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
1165
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
1112
1166
  }
1113
1167
  }
1114
1168
  };
@@ -1140,13 +1194,13 @@
1140
1194
  if (severity <= _self.telemetryLoggingLevel()) {
1141
1195
  _self.queue.push(message);
1142
1196
  _messageCount++;
1143
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
1197
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
1144
1198
  }
1145
1199
  if (_messageCount === _self.maxInternalMessageLimit()) {
1146
1200
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
1147
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
1201
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
1148
1202
  _self.queue.push(throttleMessage);
1149
- if (severity === LoggingSeverity.CRITICAL) {
1203
+ if (severity === 1 ) {
1150
1204
  _self.errorToConsole(throttleLimitMessage);
1151
1205
  }
1152
1206
  else {
@@ -1175,6 +1229,16 @@
1175
1229
  }
1176
1230
  return DiagnosticLogger;
1177
1231
  }());
1232
+ function _getLogger(logger) {
1233
+ return (logger || new DiagnosticLogger());
1234
+ }
1235
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1236
+ if (isUserAct === void 0) { isUserAct = false; }
1237
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1238
+ }
1239
+ function _warnToConsole(logger, message) {
1240
+ _getLogger(logger).warnToConsole(message);
1241
+ }
1178
1242
 
1179
1243
  var strExecutionContextKey = "ctx";
1180
1244
  var _defaultPerfManager = null;
@@ -1320,271 +1384,186 @@
1320
1384
  return _defaultPerfManager;
1321
1385
  }
1322
1386
 
1323
- var TelemetryPluginChain = /** @class */ (function () {
1324
- function TelemetryPluginChain(plugin, defItemCtx) {
1325
- var _self = this;
1326
- var _nextProxy = null;
1327
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1328
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1329
- _self._hasRun = false;
1330
- _self.getPlugin = function () {
1331
- return plugin;
1332
- };
1333
- _self.getNext = function () {
1334
- return _nextProxy;
1335
- };
1336
- _self.setNext = function (nextPlugin) {
1337
- _nextProxy = nextPlugin;
1338
- };
1339
- _self.processTelemetry = function (env, itemCtx) {
1340
- if (!itemCtx) {
1341
- itemCtx = defItemCtx;
1342
- }
1343
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1344
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1345
- if (plugin && _hasProcessTelemetry) {
1346
- _self._hasRun = true;
1347
- try {
1348
- itemCtx.setNext(_nextProxy);
1349
- if (_hasSetNext) {
1350
- plugin.setNextPlugin(_nextProxy);
1351
- }
1352
- _nextProxy && (_nextProxy._hasRun = false);
1353
- plugin.processTelemetry(env, itemCtx);
1354
- }
1355
- catch (error) {
1356
- var hasRun = _nextProxy && _nextProxy._hasRun;
1357
- if (!_nextProxy || !hasRun) {
1358
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1359
- }
1360
- if (_nextProxy && !hasRun) {
1361
- _nextProxy.processTelemetry(env, itemCtx);
1362
- }
1363
- }
1364
- }
1365
- else if (_nextProxy) {
1366
- _self._hasRun = true;
1367
- _nextProxy.processTelemetry(env, itemCtx);
1368
- }
1369
- }, function () { return ({ item: env }); }, !(env.sync));
1370
- };
1387
+ var UInt32Mask = 0x100000000;
1388
+ var MaxUInt32 = 0xffffffff;
1389
+ var _mwcSeeded = false;
1390
+ var _mwcW = 123456789;
1391
+ var _mwcZ = 987654321;
1392
+ function _mwcSeed(seedValue) {
1393
+ if (seedValue < 0) {
1394
+ seedValue >>>= 0;
1371
1395
  }
1372
- return TelemetryPluginChain;
1373
- }());
1374
-
1375
- function _createProxyChain(plugins, itemCtx) {
1376
- var proxies = [];
1377
- if (plugins && plugins.length > 0) {
1378
- var lastProxy = null;
1379
- for (var idx = 0; idx < plugins.length; idx++) {
1380
- var thePlugin = plugins[idx];
1381
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1382
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1383
- proxies.push(newProxy);
1384
- if (lastProxy) {
1385
- lastProxy.setNext(newProxy);
1386
- }
1387
- lastProxy = newProxy;
1388
- }
1389
- }
1396
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1397
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1398
+ _mwcSeeded = true;
1399
+ }
1400
+ function _autoSeedMwc() {
1401
+ try {
1402
+ var now = dateNow() & 0x7fffffff;
1403
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1404
+ }
1405
+ catch (e) {
1390
1406
  }
1391
- return proxies.length > 0 ? proxies[0] : null;
1392
1407
  }
1393
- function _copyProxyChain(proxy, itemCtx, startAt) {
1394
- var plugins = [];
1395
- var add = startAt ? false : true;
1396
- if (proxy) {
1397
- while (proxy) {
1398
- var thePlugin = proxy.getPlugin();
1399
- if (add || thePlugin === startAt) {
1400
- add = true;
1401
- plugins.push(thePlugin);
1402
- }
1403
- proxy = proxy.getNext();
1408
+ function randomValue(maxValue) {
1409
+ if (maxValue > 0) {
1410
+ return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
1411
+ }
1412
+ return 0;
1413
+ }
1414
+ function random32(signed) {
1415
+ var value = 0;
1416
+ var c = getCrypto() || getMsCrypto();
1417
+ if (c && c.getRandomValues) {
1418
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1419
+ }
1420
+ if (value === 0 && isIE()) {
1421
+ if (!_mwcSeeded) {
1422
+ _autoSeedMwc();
1404
1423
  }
1424
+ value = mwcRandom32() & MaxUInt32;
1405
1425
  }
1406
- if (!add) {
1407
- plugins.push(startAt);
1426
+ if (value === 0) {
1427
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1428
+ }
1429
+ if (!signed) {
1430
+ value >>>= 0;
1408
1431
  }
1409
- return _createProxyChain(plugins, itemCtx);
1432
+ return value;
1410
1433
  }
1411
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1412
- var plugins = srcPlugins;
1413
- var add = false;
1414
- if (startAt && srcPlugins) {
1415
- plugins = [];
1416
- arrForEach(srcPlugins, function (thePlugin) {
1417
- if (add || thePlugin === startAt) {
1418
- add = true;
1419
- plugins.push(thePlugin);
1420
- }
1421
- });
1434
+ function mwcRandomSeed(value) {
1435
+ if (!value) {
1436
+ _autoSeedMwc();
1437
+ }
1438
+ else {
1439
+ _mwcSeed(value);
1440
+ }
1441
+ }
1442
+ function mwcRandom32(signed) {
1443
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1444
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1445
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1446
+ if (!signed) {
1447
+ value >>>= 0;
1422
1448
  }
1423
- if (startAt && !add) {
1424
- if (!plugins) {
1425
- plugins = [];
1449
+ return value;
1450
+ }
1451
+ function newId(maxLength) {
1452
+ if (maxLength === void 0) { maxLength = 22; }
1453
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1454
+ var number = random32() >>> 0;
1455
+ var chars = 0;
1456
+ var result = strEmpty$1;
1457
+ while (result.length < maxLength) {
1458
+ chars++;
1459
+ result += base64chars.charAt(number & 0x3F);
1460
+ number >>>= 6;
1461
+ if (chars === 5) {
1462
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1463
+ chars = 0;
1426
1464
  }
1427
- plugins.push(startAt);
1428
1465
  }
1429
- return _createProxyChain(plugins, itemCtx);
1466
+ return result;
1430
1467
  }
1431
- var ProcessTelemetryContext = /** @class */ (function () {
1432
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1433
- var _self = this;
1434
- var _nextProxy = null;
1435
- if (startAt !== null) {
1436
- if (plugins && isFunction(plugins.getPlugin)) {
1437
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1438
- }
1439
- else {
1440
- if (startAt) {
1441
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1442
- }
1443
- else if (isUndefined(startAt)) {
1444
- _nextProxy = _createProxyChain(plugins, _self);
1445
- }
1446
- }
1468
+
1469
+ var _objDefineProperty = ObjDefineProperty;
1470
+ var version = "2.8.0-nightly.2204-06";
1471
+ var instanceName = "." + newId(6);
1472
+ var _dataUid = 0;
1473
+ function _createAccessor(target, prop, value) {
1474
+ if (_objDefineProperty) {
1475
+ try {
1476
+ _objDefineProperty(target, prop, {
1477
+ value: value,
1478
+ enumerable: false,
1479
+ configurable: true
1480
+ });
1481
+ return true;
1447
1482
  }
1448
- _self.core = function () {
1449
- return core;
1450
- };
1451
- _self.diagLog = function () {
1452
- return safeGetLogger(core, config);
1453
- };
1454
- _self.getCfg = function () {
1455
- return config;
1456
- };
1457
- _self.getExtCfg = function (identifier, defaultValue) {
1458
- if (defaultValue === void 0) { defaultValue = {}; }
1459
- var theConfig;
1460
- if (config) {
1461
- var extConfig = config.extensionConfig;
1462
- if (extConfig && identifier) {
1463
- theConfig = extConfig[identifier];
1483
+ catch (e) {
1484
+ }
1485
+ }
1486
+ return false;
1487
+ }
1488
+ function _canAcceptData(target) {
1489
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1490
+ }
1491
+ function _getCache(data, target) {
1492
+ var theCache = target[data.id];
1493
+ if (!theCache) {
1494
+ theCache = {};
1495
+ try {
1496
+ if (_canAcceptData(target)) {
1497
+ if (!_createAccessor(target, data.id, theCache)) {
1498
+ target[data.id] = theCache;
1464
1499
  }
1465
1500
  }
1466
- return (theConfig ? theConfig : defaultValue);
1467
- };
1468
- _self.getConfig = function (identifier, field, defaultValue) {
1469
- if (defaultValue === void 0) { defaultValue = false; }
1470
- var theValue;
1471
- var extConfig = _self.getExtCfg(identifier, null);
1472
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1473
- theValue = extConfig[field];
1474
- }
1475
- else if (config && !isNullOrUndefined(config[field])) {
1476
- theValue = config[field];
1477
- }
1478
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1479
- };
1480
- _self.hasNext = function () {
1481
- return _nextProxy != null;
1482
- };
1483
- _self.getNext = function () {
1484
- return _nextProxy;
1485
- };
1486
- _self.setNext = function (nextPlugin) {
1487
- _nextProxy = nextPlugin;
1488
- };
1489
- _self.processNext = function (env) {
1490
- var nextPlugin = _nextProxy;
1491
- if (nextPlugin) {
1492
- _nextProxy = nextPlugin.getNext();
1493
- nextPlugin.processTelemetry(env, _self);
1494
- }
1495
- };
1496
- _self.createNew = function (plugins, startAt) {
1497
- if (plugins === void 0) { plugins = null; }
1498
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1499
- };
1501
+ }
1502
+ catch (e) {
1503
+ }
1500
1504
  }
1501
- return ProcessTelemetryContext;
1502
- }());
1503
-
1504
- var strIKey = "iKey";
1505
- var strExtensionConfig = "extensionConfig";
1506
-
1507
- var strGetPlugin = "getPlugin";
1508
- var BaseTelemetryPlugin = /** @class */ (function () {
1509
- function BaseTelemetryPlugin() {
1510
- var _self = this;
1511
- var _isinitialized = false;
1512
- var _rootCtx = null;
1513
- var _nextPlugin = null;
1514
- _self.core = null;
1515
- _self.diagLog = function (itemCtx) {
1516
- return _self._getTelCtx(itemCtx).diagLog();
1517
- };
1518
- _self.isInitialized = function () {
1519
- return _isinitialized;
1520
- };
1521
- _self.setInitialized = function (isInitialized) {
1522
- _isinitialized = isInitialized;
1523
- };
1524
- _self.setNextPlugin = function (next) {
1525
- _nextPlugin = next;
1526
- };
1527
- _self.processNext = function (env, itemCtx) {
1528
- if (itemCtx) {
1529
- itemCtx.processNext(env);
1530
- }
1531
- else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
1532
- _nextPlugin.processTelemetry(env, null);
1505
+ return theCache;
1506
+ }
1507
+ function createUniqueNamespace(name, includeVersion) {
1508
+ if (includeVersion === void 0) { includeVersion = false; }
1509
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1510
+ }
1511
+ function createElmNodeData(name) {
1512
+ var data = {
1513
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1514
+ accept: function (target) {
1515
+ return _canAcceptData(target);
1516
+ },
1517
+ get: function (target, name, defValue, addDefault) {
1518
+ var theCache = target[data.id];
1519
+ if (!theCache) {
1520
+ if (addDefault) {
1521
+ theCache = _getCache(data, target);
1522
+ theCache[normalizeJsName(name)] = defValue;
1523
+ }
1524
+ return defValue;
1533
1525
  }
1534
- };
1535
- _self._getTelCtx = function (currentCtx) {
1536
- if (currentCtx === void 0) { currentCtx = null; }
1537
- var itemCtx = currentCtx;
1538
- if (!itemCtx) {
1539
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1540
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1541
- itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1526
+ return theCache[normalizeJsName(name)];
1527
+ },
1528
+ kill: function (target, name) {
1529
+ if (target && target[name]) {
1530
+ try {
1531
+ delete target[name];
1542
1532
  }
1543
- else {
1544
- itemCtx = rootCtx.createNew(null, _nextPlugin);
1533
+ catch (e) {
1545
1534
  }
1546
1535
  }
1547
- return itemCtx;
1548
- };
1549
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1550
- if (config) {
1551
- setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1552
- }
1553
- if (!pluginChain && core) {
1554
- pluginChain = core.getProcessTelContext().getNext();
1555
- }
1556
- var nextPlugin = _nextPlugin;
1557
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1558
- nextPlugin = _nextPlugin[strGetPlugin]();
1559
- }
1560
- _self.core = core;
1561
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1562
- _isinitialized = true;
1563
- };
1564
- }
1565
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1566
- this._baseTelInit(config, core, extensions, pluginChain);
1536
+ }
1567
1537
  };
1568
- return BaseTelemetryPlugin;
1569
- }());
1538
+ return data;
1539
+ }
1570
1540
 
1571
- var processTelemetry = "processTelemetry";
1572
- var priority = "priority";
1573
- var setNextPlugin = "setNextPlugin";
1574
- var isInitialized = "isInitialized";
1541
+ var pluginStateData = createElmNodeData("plugin");
1542
+ function _getPluginState(plugin) {
1543
+ return pluginStateData.get(plugin, "state", {}, true);
1544
+ }
1575
1545
  function initializePlugins(processContext, extensions) {
1576
1546
  var initPlugins = [];
1577
1547
  var lastPlugin = null;
1578
1548
  var proxy = processContext.getNext();
1549
+ var pluginState;
1579
1550
  while (proxy) {
1580
1551
  var thePlugin = proxy.getPlugin();
1581
1552
  if (thePlugin) {
1582
1553
  if (lastPlugin &&
1583
- isFunction(lastPlugin[setNextPlugin]) &&
1584
- isFunction(thePlugin[processTelemetry])) {
1585
- lastPlugin[setNextPlugin](thePlugin);
1554
+ isFunction(lastPlugin[strSetNextPlugin]) &&
1555
+ isFunction(thePlugin[strProcessTelemetry])) {
1556
+ lastPlugin[strSetNextPlugin](thePlugin);
1557
+ }
1558
+ var isInitialized = false;
1559
+ if (isFunction(thePlugin[strIsInitialized])) {
1560
+ isInitialized = thePlugin[strIsInitialized]();
1561
+ }
1562
+ else {
1563
+ pluginState = _getPluginState(thePlugin);
1564
+ isInitialized = pluginState[strIsInitialized];
1586
1565
  }
1587
- if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {
1566
+ if (!isInitialized) {
1588
1567
  initPlugins.push(thePlugin);
1589
1568
  }
1590
1569
  lastPlugin = thePlugin;
@@ -1592,15 +1571,22 @@
1592
1571
  }
1593
1572
  }
1594
1573
  arrForEach(initPlugins, function (thePlugin) {
1595
- thePlugin.initialize(processContext.getCfg(), processContext.core(), extensions, processContext.getNext());
1574
+ var core = processContext.core();
1575
+ thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
1576
+ pluginState = _getPluginState(thePlugin);
1577
+ if (!thePlugin[strCore] && !pluginState[strCore]) {
1578
+ pluginState[strCore] = core;
1579
+ }
1580
+ pluginState[strIsInitialized] = true;
1581
+ delete pluginState[strTeardown];
1596
1582
  });
1597
1583
  }
1598
1584
  function sortPlugins(plugins) {
1599
1585
  return plugins.sort(function (extA, extB) {
1600
1586
  var result = 0;
1601
- var bHasProcess = isFunction(extB[processTelemetry]);
1602
- if (isFunction(extA[processTelemetry])) {
1603
- result = bHasProcess ? extA[priority] - extB[priority] : 1;
1587
+ var bHasProcess = isFunction(extB[strProcessTelemetry]);
1588
+ if (isFunction(extA[strProcessTelemetry])) {
1589
+ result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1604
1590
  }
1605
1591
  else if (bHasProcess) {
1606
1592
  result = -1;
@@ -1609,90 +1595,359 @@
1609
1595
  });
1610
1596
  }
1611
1597
 
1612
- var ChannelControllerPriority = 500;
1613
- var ChannelValidationMessage = "Channel has invalid priority";
1614
- var ChannelController = /** @class */ (function (_super) {
1615
- __extendsFn(ChannelController, _super);
1616
- function ChannelController() {
1617
- var _this = _super.call(this) || this;
1618
- _this.identifier = "ChannelControllerPlugin";
1619
- _this.priority = ChannelControllerPriority;
1620
- var _channelQueue;
1621
- dynamicProto(ChannelController, _this, function (_self, _base) {
1622
- _self.setNextPlugin = function (next) {
1623
- };
1624
- _self.processTelemetry = function (item, itemCtx) {
1625
- if (_channelQueue) {
1626
- arrForEach(_channelQueue, function (queues) {
1627
- if (queues.length > 0) {
1628
- var chainCtx = _this._getTelCtx(itemCtx).createNew(queues);
1629
- chainCtx.processNext(item);
1630
- }
1631
- });
1632
- }
1633
- };
1634
- _self.getChannelControls = function () {
1635
- return _channelQueue;
1636
- };
1637
- _self.initialize = function (config, core, extensions) {
1638
- if (_self.isInitialized()) {
1639
- return;
1640
- }
1641
- _base.initialize(config, core, extensions);
1642
- _createChannelQueues((config || {}).channels, extensions);
1643
- arrForEach(_channelQueue, function (queue) { return initializePlugins(new ProcessTelemetryContext(queue, config, core), extensions); });
1644
- };
1645
- });
1646
- function _checkQueuePriority(queue) {
1647
- arrForEach(queue, function (queueItem) {
1648
- if (queueItem.priority < ChannelControllerPriority) {
1649
- throwError(ChannelValidationMessage + queueItem.identifier);
1650
- }
1598
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1599
+ var strHasRunFlags = "_hasRun";
1600
+ var strGetTelCtx = "_getTelCtx";
1601
+ var _chainId = 0;
1602
+ function _getNextProxyStart(proxy, config, core, startAt) {
1603
+ while (proxy) {
1604
+ if (proxy.getPlugin() === startAt) {
1605
+ return proxy;
1606
+ }
1607
+ proxy = proxy.getNext();
1608
+ }
1609
+ return createTelemetryProxyChain([startAt], config, core);
1610
+ }
1611
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1612
+ var _nextProxy = null;
1613
+ var _onComplete = [];
1614
+ if (startAt !== null) {
1615
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1616
+ }
1617
+ var context = {
1618
+ _next: _moveNext,
1619
+ ctx: {
1620
+ core: function () {
1621
+ return core;
1622
+ },
1623
+ diagLog: function () {
1624
+ return safeGetLogger(core, config);
1625
+ },
1626
+ getCfg: function () {
1627
+ return config;
1628
+ },
1629
+ getExtCfg: _getExtCfg,
1630
+ getConfig: _getConfig,
1631
+ hasNext: function () {
1632
+ return !!_nextProxy;
1633
+ },
1634
+ getNext: function () {
1635
+ return _nextProxy;
1636
+ },
1637
+ setNext: function (nextPlugin) {
1638
+ _nextProxy = nextPlugin;
1639
+ },
1640
+ iterate: _iterateChain,
1641
+ onComplete: _addOnComplete
1642
+ }
1643
+ };
1644
+ function _addOnComplete(onComplete, that) {
1645
+ var args = [];
1646
+ for (var _i = 2; _i < arguments.length; _i++) {
1647
+ args[_i - 2] = arguments[_i];
1648
+ }
1649
+ if (onComplete) {
1650
+ _onComplete.push({
1651
+ func: onComplete,
1652
+ self: !isUndefined(that) ? that : context.ctx,
1653
+ args: args
1651
1654
  });
1652
1655
  }
1653
- function _addChannelQueue(queue) {
1654
- if (queue && queue.length > 0) {
1655
- queue = queue.sort(function (a, b) {
1656
- return a.priority - b.priority;
1656
+ }
1657
+ function _moveNext() {
1658
+ var nextProxy = _nextProxy;
1659
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1660
+ if (!nextProxy) {
1661
+ var onComplete = _onComplete;
1662
+ if (onComplete && onComplete.length > 0) {
1663
+ arrForEach(onComplete, function (completeDetails) {
1664
+ try {
1665
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1666
+ }
1667
+ catch (e) {
1668
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1669
+ }
1657
1670
  });
1658
- _checkQueuePriority(queue);
1659
- _channelQueue.push(queue);
1671
+ _onComplete = [];
1660
1672
  }
1661
1673
  }
1662
- function _createChannelQueues(channels, extensions) {
1663
- _channelQueue = [];
1664
- if (channels) {
1665
- arrForEach(channels, function (queue) { return _addChannelQueue(queue); });
1674
+ return nextProxy;
1675
+ }
1676
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1677
+ if (defaultValue === void 0) { defaultValue = {}; }
1678
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1679
+ var theConfig;
1680
+ if (config) {
1681
+ var extConfig = config.extensionConfig;
1682
+ if (extConfig && identifier) {
1683
+ theConfig = extConfig[identifier];
1666
1684
  }
1667
- if (extensions) {
1668
- var extensionQueue_1 = [];
1669
- arrForEach(extensions, function (plugin) {
1670
- if (plugin.priority > ChannelControllerPriority) {
1671
- extensionQueue_1.push(plugin);
1672
- }
1673
- });
1674
- _addChannelQueue(extensionQueue_1);
1685
+ }
1686
+ if (!theConfig) {
1687
+ theConfig = defaultValue;
1688
+ }
1689
+ else if (isObject(defaultValue)) {
1690
+ if (mergeDefault !== 0 ) {
1691
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1692
+ if (config && mergeDefault === 2 ) {
1693
+ objForEachKey(defaultValue, function (field) {
1694
+ if (isNullOrUndefined(newConfig_1[field])) {
1695
+ var cfgValue = config[field];
1696
+ if (!isNullOrUndefined(cfgValue)) {
1697
+ newConfig_1[field] = cfgValue;
1698
+ }
1699
+ }
1700
+ });
1701
+ }
1675
1702
  }
1676
1703
  }
1677
- return _this;
1704
+ return theConfig;
1705
+ }
1706
+ function _getConfig(identifier, field, defaultValue) {
1707
+ if (defaultValue === void 0) { defaultValue = false; }
1708
+ var theValue;
1709
+ var extConfig = _getExtCfg(identifier, null);
1710
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1711
+ theValue = extConfig[field];
1712
+ }
1713
+ else if (config && !isNullOrUndefined(config[field])) {
1714
+ theValue = config[field];
1715
+ }
1716
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1678
1717
  }
1679
- ChannelController._staticInit = (function () {
1680
- var proto = ChannelController.prototype;
1681
- objDefineAccessors(proto, "ChannelControls", proto.getChannelControls);
1682
- objDefineAccessors(proto, "channelQueue", proto.getChannelControls);
1683
- })();
1684
- return ChannelController;
1685
- }(BaseTelemetryPlugin));
1686
-
1687
- var strToGMTString = "toGMTString";
1688
- var strToUTCString = "toUTCString";
1689
- var strCookie = "cookie";
1690
- var strExpires = "expires";
1718
+ function _iterateChain(cb) {
1719
+ var nextPlugin;
1720
+ while (!!(nextPlugin = context._next())) {
1721
+ var plugin = nextPlugin.getPlugin();
1722
+ if (plugin) {
1723
+ cb(plugin);
1724
+ }
1725
+ }
1726
+ }
1727
+ return context;
1728
+ }
1729
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1730
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1731
+ var context = internalContext.ctx;
1732
+ function _processNext(env) {
1733
+ var nextPlugin = internalContext._next();
1734
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1735
+ return !nextPlugin;
1736
+ }
1737
+ function _createNew(plugins, startAt) {
1738
+ if (plugins === void 0) { plugins = null; }
1739
+ if (isArray(plugins)) {
1740
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1741
+ }
1742
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1743
+ }
1744
+ context.processNext = _processNext;
1745
+ context.createNew = _createNew;
1746
+ return context;
1747
+ }
1748
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1749
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1750
+ var context = internalContext.ctx;
1751
+ function _processNext(unloadState) {
1752
+ var nextPlugin = internalContext._next();
1753
+ nextPlugin && nextPlugin.unload(context, unloadState);
1754
+ return !nextPlugin;
1755
+ }
1756
+ function _createNew(plugins, startAt) {
1757
+ if (plugins === void 0) { plugins = null; }
1758
+ if (isArray(plugins)) {
1759
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1760
+ }
1761
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1762
+ }
1763
+ context.processNext = _processNext;
1764
+ context.createNew = _createNew;
1765
+ return context;
1766
+ }
1767
+ function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1768
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1769
+ var context = internalContext.ctx;
1770
+ function _processNext(updateState) {
1771
+ return context.iterate(function (plugin) {
1772
+ if (isFunction(plugin[strUpdate])) {
1773
+ plugin[strUpdate](context, updateState);
1774
+ }
1775
+ });
1776
+ }
1777
+ function _createNew(plugins, startAt) {
1778
+ if (plugins === void 0) { plugins = null; }
1779
+ if (isArray(plugins)) {
1780
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1781
+ }
1782
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1783
+ }
1784
+ context.processNext = _processNext;
1785
+ context.createNew = _createNew;
1786
+ return context;
1787
+ }
1788
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1789
+ var firstProxy = null;
1790
+ var add = startAt ? false : true;
1791
+ if (isArray(plugins) && plugins.length > 0) {
1792
+ var lastProxy_1 = null;
1793
+ arrForEach(plugins, function (thePlugin) {
1794
+ if (!add && startAt === thePlugin) {
1795
+ add = true;
1796
+ }
1797
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1798
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1799
+ if (!firstProxy) {
1800
+ firstProxy = newProxy;
1801
+ }
1802
+ if (lastProxy_1) {
1803
+ lastProxy_1._setNext(newProxy);
1804
+ }
1805
+ lastProxy_1 = newProxy;
1806
+ }
1807
+ });
1808
+ }
1809
+ if (startAt && !firstProxy) {
1810
+ return createTelemetryProxyChain([startAt], config, core);
1811
+ }
1812
+ return firstProxy;
1813
+ }
1814
+ function createTelemetryPluginProxy(plugin, config, core) {
1815
+ var nextProxy = null;
1816
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1817
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1818
+ var chainId;
1819
+ if (plugin) {
1820
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1821
+ }
1822
+ else {
1823
+ chainId = "Unknown-0-" + _chainId++;
1824
+ }
1825
+ var proxyChain = {
1826
+ getPlugin: function () {
1827
+ return plugin;
1828
+ },
1829
+ getNext: function () {
1830
+ return nextProxy;
1831
+ },
1832
+ processTelemetry: _processTelemetry,
1833
+ unload: _unloadPlugin,
1834
+ update: _updatePlugin,
1835
+ _id: chainId,
1836
+ _setNext: function (nextPlugin) {
1837
+ nextProxy = nextPlugin;
1838
+ }
1839
+ };
1840
+ function _getTelCtx() {
1841
+ var itemCtx;
1842
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1843
+ itemCtx = plugin[strGetTelCtx]();
1844
+ }
1845
+ if (!itemCtx) {
1846
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1847
+ }
1848
+ return itemCtx;
1849
+ }
1850
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1851
+ var hasRun = false;
1852
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1853
+ var hasRunContext = itemCtx[strHasRunFlags];
1854
+ if (!hasRunContext) {
1855
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1856
+ }
1857
+ itemCtx.setNext(nextProxy);
1858
+ if (plugin) {
1859
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1860
+ hasRunContext[chainId] = true;
1861
+ try {
1862
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1863
+ if (nextId) {
1864
+ hasRunContext[nextId] = false;
1865
+ }
1866
+ hasRun = processPluginFn(itemCtx);
1867
+ }
1868
+ catch (error) {
1869
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1870
+ if (hasNextRun) {
1871
+ hasRun = true;
1872
+ }
1873
+ if (!nextProxy || !hasNextRun) {
1874
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1875
+ }
1876
+ }
1877
+ }, details, isAsync);
1878
+ }
1879
+ return hasRun;
1880
+ }
1881
+ function _processTelemetry(env, itemCtx) {
1882
+ itemCtx = itemCtx || _getTelCtx();
1883
+ function _callProcessTelemetry(itemCtx) {
1884
+ if (!plugin || !hasProcessTelemetry) {
1885
+ return false;
1886
+ }
1887
+ var pluginState = _getPluginState(plugin);
1888
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1889
+ return false;
1890
+ }
1891
+ if (hasSetNext) {
1892
+ plugin.setNextPlugin(nextProxy);
1893
+ }
1894
+ plugin.processTelemetry(env, itemCtx);
1895
+ return true;
1896
+ }
1897
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1898
+ itemCtx.processNext(env);
1899
+ }
1900
+ }
1901
+ function _unloadPlugin(unloadCtx, unloadState) {
1902
+ function _callTeardown() {
1903
+ var hasRun = false;
1904
+ if (plugin) {
1905
+ var pluginState = _getPluginState(plugin);
1906
+ var pluginCore = plugin[strCore] || pluginState.core;
1907
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1908
+ pluginState[strCore] = null;
1909
+ pluginState[strTeardown] = true;
1910
+ pluginState[strIsInitialized] = false;
1911
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1912
+ hasRun = true;
1913
+ }
1914
+ }
1915
+ }
1916
+ return hasRun;
1917
+ }
1918
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1919
+ unloadCtx.processNext(unloadState);
1920
+ }
1921
+ }
1922
+ function _updatePlugin(updateCtx, updateState) {
1923
+ function _callUpdate() {
1924
+ var hasRun = false;
1925
+ if (plugin) {
1926
+ var pluginState = _getPluginState(plugin);
1927
+ var pluginCore = plugin[strCore] || pluginState.core;
1928
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1929
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1930
+ hasRun = true;
1931
+ }
1932
+ }
1933
+ }
1934
+ return hasRun;
1935
+ }
1936
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1937
+ updateCtx.processNext(updateState);
1938
+ }
1939
+ }
1940
+ return objFreeze(proxyChain);
1941
+ }
1942
+
1943
+ var strToGMTString = "toGMTString";
1944
+ var strToUTCString = "toUTCString";
1945
+ var strCookie = "cookie";
1946
+ var strExpires = "expires";
1691
1947
  var strEnabled = "enabled";
1692
1948
  var strIsCookieUseDisabled = "isCookieUseDisabled";
1693
1949
  var strDisableCookiesUsage = "disableCookiesUsage";
1694
1950
  var strConfigCookieMgr = "_ckMgr";
1695
- var strEmpty = "";
1696
1951
  var _supportsCookies = null;
1697
1952
  var _allowUaSameSite = null;
1698
1953
  var _parsedCookieValue = null;
@@ -1750,7 +2005,7 @@
1750
2005
  var result = false;
1751
2006
  if (_isMgrEnabled(cookieMgr)) {
1752
2007
  var values = {};
1753
- var theValue = strTrim(value || strEmpty);
2008
+ var theValue = strTrim(value || strEmpty$1);
1754
2009
  var idx = theValue.indexOf(";");
1755
2010
  if (idx !== -1) {
1756
2011
  theValue = strTrim(value.substring(0, idx));
@@ -1765,11 +2020,11 @@
1765
2020
  if (expireMs > 0) {
1766
2021
  var expiry = new Date();
1767
2022
  expiry.setTime(expireMs);
1768
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty, isTruthy);
2023
+ setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty$1, isTruthy);
1769
2024
  }
1770
2025
  }
1771
2026
  if (!_isIE) {
1772
- setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
2027
+ setValue(values, "max-age", strEmpty$1 + maxAgeSec, null, isUndefined);
1773
2028
  }
1774
2029
  }
1775
2030
  var location_1 = getLocation();
@@ -1790,7 +2045,7 @@
1790
2045
  return result;
1791
2046
  },
1792
2047
  get: function (name) {
1793
- var value = strEmpty;
2048
+ var value = strEmpty$1;
1794
2049
  if (_isMgrEnabled(cookieMgr)) {
1795
2050
  value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
1796
2051
  }
@@ -1815,7 +2070,7 @@
1815
2070
  values["max-age"] = "0";
1816
2071
  }
1817
2072
  var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
1818
- delCookie(name, _formatCookieValue(strEmpty, values));
2073
+ delCookie(name, _formatCookieValue(strEmpty$1, values));
1819
2074
  result = true;
1820
2075
  }
1821
2076
  return result;
@@ -1832,7 +2087,7 @@
1832
2087
  _supportsCookies = doc[strCookie] !== undefined;
1833
2088
  }
1834
2089
  catch (e) {
1835
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotAccessCookie, "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2090
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
1836
2091
  }
1837
2092
  }
1838
2093
  return _supportsCookies;
@@ -1842,7 +2097,7 @@
1842
2097
  if (theValue && theValue.length) {
1843
2098
  var parts = strTrim(theValue).split(";");
1844
2099
  arrForEach(parts, function (thePart) {
1845
- thePart = strTrim(thePart || strEmpty);
2100
+ thePart = strTrim(thePart || strEmpty$1);
1846
2101
  if (thePart) {
1847
2102
  var idx = thePart.indexOf("=");
1848
2103
  if (idx === -1) {
@@ -1863,21 +2118,21 @@
1863
2118
  return null;
1864
2119
  }
1865
2120
  function _formatCookieValue(value, values) {
1866
- var cookieValue = value || strEmpty;
2121
+ var cookieValue = value || strEmpty$1;
1867
2122
  objForEachKey(values, function (name, theValue) {
1868
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
2123
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty$1);
1869
2124
  });
1870
2125
  return cookieValue;
1871
2126
  }
1872
2127
  function _getCookieValue(name) {
1873
- var cookieValue = strEmpty;
2128
+ var cookieValue = strEmpty$1;
1874
2129
  if (_doc) {
1875
- var theCookie = _doc[strCookie] || strEmpty;
2130
+ var theCookie = _doc[strCookie] || strEmpty$1;
1876
2131
  if (_parsedCookieValue !== theCookie) {
1877
2132
  _cookieCache = _extractParts(theCookie);
1878
2133
  _parsedCookieValue = theCookie;
1879
2134
  }
1880
- cookieValue = strTrim(_cookieCache[name] || strEmpty);
2135
+ cookieValue = strTrim(_cookieCache[name] || strEmpty$1);
1881
2136
  }
1882
2137
  return cookieValue;
1883
2138
  }
@@ -1911,26 +2166,519 @@
1911
2166
  return false;
1912
2167
  }
1913
2168
 
1914
- var validationError = "Extensions must provide callback to initialize";
2169
+ var strIKey = "iKey";
2170
+ var strExtensionConfig = "extensionConfig";
2171
+
2172
+ var ChannelControllerPriority = 500;
2173
+ var ChannelValidationMessage = "Channel has invalid priority - ";
2174
+ function _addChannelQueue(channelQueue, queue, config, core) {
2175
+ if (queue && isArray(queue) && queue.length > 0) {
2176
+ queue = queue.sort(function (a, b) {
2177
+ return a.priority - b.priority;
2178
+ });
2179
+ arrForEach(queue, function (queueItem) {
2180
+ if (queueItem.priority < ChannelControllerPriority) {
2181
+ throwError(ChannelValidationMessage + queueItem.identifier);
2182
+ }
2183
+ });
2184
+ channelQueue.push({
2185
+ queue: objFreeze(queue),
2186
+ chain: createTelemetryProxyChain(queue, config, core)
2187
+ });
2188
+ }
2189
+ }
2190
+ function createChannelControllerPlugin(channelQueue, core) {
2191
+ var _a;
2192
+ function _getTelCtx() {
2193
+ return createProcessTelemetryContext(null, core.config, core, null);
2194
+ }
2195
+ function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2196
+ var waiting = theChannels ? (theChannels.length + 1) : 1;
2197
+ function _runChainOnComplete() {
2198
+ waiting--;
2199
+ if (waiting === 0) {
2200
+ onComplete && onComplete();
2201
+ onComplete = null;
2202
+ }
2203
+ }
2204
+ if (waiting > 0) {
2205
+ arrForEach(theChannels, function (channels) {
2206
+ if (channels && channels.queue.length > 0) {
2207
+ var channelChain = channels.chain;
2208
+ var chainCtx = itemCtx.createNew(channelChain);
2209
+ chainCtx.onComplete(_runChainOnComplete);
2210
+ processFn(chainCtx);
2211
+ }
2212
+ else {
2213
+ waiting--;
2214
+ }
2215
+ });
2216
+ }
2217
+ _runChainOnComplete();
2218
+ }
2219
+ function _doUpdate(updateCtx, updateState) {
2220
+ var theUpdateState = updateState || {
2221
+ reason: 0
2222
+ };
2223
+ _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2224
+ chainCtx[strProcessNext](theUpdateState);
2225
+ }, function () {
2226
+ updateCtx[strProcessNext](theUpdateState);
2227
+ });
2228
+ return true;
2229
+ }
2230
+ function _doTeardown(unloadCtx, unloadState) {
2231
+ var theUnloadState = unloadState || {
2232
+ reason: 0 ,
2233
+ isAsync: false
2234
+ };
2235
+ _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2236
+ chainCtx[strProcessNext](theUnloadState);
2237
+ }, function () {
2238
+ unloadCtx[strProcessNext](theUnloadState);
2239
+ isInitialized = false;
2240
+ });
2241
+ return true;
2242
+ }
2243
+ function _getChannel(pluginIdentifier) {
2244
+ var thePlugin = null;
2245
+ if (channelQueue && channelQueue.length > 0) {
2246
+ arrForEach(channelQueue, function (channels) {
2247
+ if (channels && channels.queue.length > 0) {
2248
+ arrForEach(channels.queue, function (ext) {
2249
+ if (ext.identifier === pluginIdentifier) {
2250
+ thePlugin = ext;
2251
+ return -1;
2252
+ }
2253
+ });
2254
+ if (thePlugin) {
2255
+ return -1;
2256
+ }
2257
+ }
2258
+ });
2259
+ }
2260
+ return thePlugin;
2261
+ }
2262
+ var isInitialized = false;
2263
+ var channelController = (_a = {
2264
+ identifier: "ChannelControllerPlugin",
2265
+ priority: ChannelControllerPriority,
2266
+ initialize: function (config, core, extensions, pluginChain) {
2267
+ isInitialized = true;
2268
+ arrForEach(channelQueue, function (channels) {
2269
+ if (channels && channels.queue.length > 0) {
2270
+ initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2271
+ }
2272
+ });
2273
+ },
2274
+ isInitialized: function () {
2275
+ return isInitialized;
2276
+ },
2277
+ processTelemetry: function (item, itemCtx) {
2278
+ _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2279
+ chainCtx[strProcessNext](item);
2280
+ }, function () {
2281
+ itemCtx[strProcessNext](item);
2282
+ });
2283
+ },
2284
+ update: _doUpdate
2285
+ },
2286
+ _a[strPause] = function () {
2287
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2288
+ chainCtx.iterate(function (plugin) {
2289
+ plugin[strPause] && plugin[strPause]();
2290
+ });
2291
+ }, null);
2292
+ },
2293
+ _a[strResume] = function () {
2294
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2295
+ chainCtx.iterate(function (plugin) {
2296
+ plugin[strResume] && plugin[strResume]();
2297
+ });
2298
+ }, null);
2299
+ },
2300
+ _a[strTeardown] = _doTeardown,
2301
+ _a.getChannel = _getChannel,
2302
+ _a.flush = function (isAsync, callBack, sendReason, cbTimeout) {
2303
+ var waiting = 1;
2304
+ var doneIterating = false;
2305
+ var cbTimer = null;
2306
+ cbTimeout = cbTimeout || 5000;
2307
+ function doCallback() {
2308
+ waiting--;
2309
+ if (doneIterating && waiting === 0) {
2310
+ if (cbTimer) {
2311
+ clearTimeout(cbTimer);
2312
+ cbTimer = null;
2313
+ }
2314
+ callBack && callBack(doneIterating);
2315
+ callBack = null;
2316
+ }
2317
+ }
2318
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2319
+ chainCtx.iterate(function (plugin) {
2320
+ if (plugin.flush) {
2321
+ waiting++;
2322
+ var handled_1 = false;
2323
+ if (!plugin.flush(isAsync, function () {
2324
+ handled_1 = true;
2325
+ doCallback();
2326
+ }, sendReason)) {
2327
+ if (!handled_1) {
2328
+ if (isAsync && cbTimer == null) {
2329
+ cbTimer = setTimeout(function () {
2330
+ cbTimer = null;
2331
+ doCallback();
2332
+ }, cbTimeout);
2333
+ }
2334
+ else {
2335
+ doCallback();
2336
+ }
2337
+ }
2338
+ }
2339
+ }
2340
+ });
2341
+ }, function () {
2342
+ doneIterating = true;
2343
+ doCallback();
2344
+ });
2345
+ return true;
2346
+ },
2347
+ _a._setQueue = function (queue) {
2348
+ channelQueue = queue;
2349
+ },
2350
+ _a);
2351
+ return channelController;
2352
+ }
2353
+ function createChannelQueues(channels, extensions, config, core) {
2354
+ var channelQueue = [];
2355
+ if (channels) {
2356
+ arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, config, core); });
2357
+ }
2358
+ if (extensions) {
2359
+ var extensionQueue_1 = [];
2360
+ arrForEach(extensions, function (plugin) {
2361
+ if (plugin.priority > ChannelControllerPriority) {
2362
+ extensionQueue_1.push(plugin);
2363
+ }
2364
+ });
2365
+ _addChannelQueue(channelQueue, extensionQueue_1, config, core);
2366
+ }
2367
+ return channelQueue;
2368
+ }
2369
+
2370
+ function createUnloadHandlerContainer() {
2371
+ var handlers = [];
2372
+ function _addHandler(handler) {
2373
+ if (handler) {
2374
+ handlers.push(handler);
2375
+ }
2376
+ }
2377
+ function _runHandlers(unloadCtx, unloadState) {
2378
+ arrForEach(handlers, function (handler) {
2379
+ try {
2380
+ handler(unloadCtx, unloadState);
2381
+ }
2382
+ catch (e) {
2383
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2384
+ }
2385
+ });
2386
+ handlers = [];
2387
+ }
2388
+ return {
2389
+ add: _addHandler,
2390
+ run: _runHandlers
2391
+ };
2392
+ }
2393
+
2394
+ var strGetPlugin = "getPlugin";
2395
+ var BaseTelemetryPlugin = /** @class */ (function () {
2396
+ function BaseTelemetryPlugin() {
2397
+ var _self = this;
2398
+ var _isinitialized;
2399
+ var _rootCtx;
2400
+ var _nextPlugin;
2401
+ var _unloadHandlerContainer;
2402
+ var _hooks;
2403
+ _initDefaults();
2404
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
2405
+ _self.initialize = function (config, core, extensions, pluginChain) {
2406
+ _setDefaults(config, core, pluginChain);
2407
+ _isinitialized = true;
2408
+ };
2409
+ _self.teardown = function (unloadCtx, unloadState) {
2410
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
2411
+ return;
2412
+ }
2413
+ var result;
2414
+ var unloadDone = false;
2415
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2416
+ var theUnloadState = unloadState || {
2417
+ reason: 0 ,
2418
+ isAsync: false
2419
+ };
2420
+ function _unloadCallback() {
2421
+ if (!unloadDone) {
2422
+ unloadDone = true;
2423
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
2424
+ arrForEach(_hooks, function (fn) {
2425
+ fn.rm();
2426
+ });
2427
+ _hooks = [];
2428
+ if (result === true) {
2429
+ theUnloadCtx.processNext(theUnloadState);
2430
+ }
2431
+ _initDefaults();
2432
+ }
2433
+ }
2434
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
2435
+ _unloadCallback();
2436
+ }
2437
+ else {
2438
+ result = true;
2439
+ }
2440
+ return result;
2441
+ };
2442
+ _self.update = function (updateCtx, updateState) {
2443
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
2444
+ return;
2445
+ }
2446
+ var result;
2447
+ var updateDone = false;
2448
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2449
+ var theUpdateState = updateState || {
2450
+ reason: 0
2451
+ };
2452
+ function _updateCallback() {
2453
+ if (!updateDone) {
2454
+ updateDone = true;
2455
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
2456
+ }
2457
+ }
2458
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
2459
+ _updateCallback();
2460
+ }
2461
+ else {
2462
+ result = true;
2463
+ }
2464
+ return result;
2465
+ };
2466
+ _self._addHook = function (hooks) {
2467
+ if (hooks) {
2468
+ if (isArray(hooks)) {
2469
+ _hooks = _hooks.concat(hooks);
2470
+ }
2471
+ else {
2472
+ _hooks.push(hooks);
2473
+ }
2474
+ }
2475
+ };
2476
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
2477
+ });
2478
+ _self.diagLog = function (itemCtx) {
2479
+ return _getTelCtx(itemCtx).diagLog();
2480
+ };
2481
+ _self[strIsInitialized] = function () {
2482
+ return _isinitialized;
2483
+ };
2484
+ _self.setInitialized = function (isInitialized) {
2485
+ _isinitialized = isInitialized;
2486
+ };
2487
+ _self[strSetNextPlugin] = function (next) {
2488
+ _nextPlugin = next;
2489
+ };
2490
+ _self.processNext = function (env, itemCtx) {
2491
+ if (itemCtx) {
2492
+ itemCtx.processNext(env);
2493
+ }
2494
+ else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
2495
+ _nextPlugin.processTelemetry(env, null);
2496
+ }
2497
+ };
2498
+ _self._getTelCtx = _getTelCtx;
2499
+ function _getTelCtx(currentCtx) {
2500
+ if (currentCtx === void 0) { currentCtx = null; }
2501
+ var itemCtx = currentCtx;
2502
+ if (!itemCtx) {
2503
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
2504
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2505
+ itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
2506
+ }
2507
+ else {
2508
+ itemCtx = rootCtx.createNew(null, _nextPlugin);
2509
+ }
2510
+ }
2511
+ return itemCtx;
2512
+ }
2513
+ function _setDefaults(config, core, pluginChain) {
2514
+ if (config) {
2515
+ setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
2516
+ }
2517
+ if (!pluginChain && core) {
2518
+ pluginChain = core.getProcessTelContext().getNext();
2519
+ }
2520
+ var nextPlugin = _nextPlugin;
2521
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2522
+ nextPlugin = _nextPlugin[strGetPlugin]();
2523
+ }
2524
+ _self.core = core;
2525
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
2526
+ }
2527
+ function _initDefaults() {
2528
+ _isinitialized = false;
2529
+ _self.core = null;
2530
+ _rootCtx = null;
2531
+ _nextPlugin = null;
2532
+ _hooks = [];
2533
+ _unloadHandlerContainer = createUnloadHandlerContainer();
2534
+ }
2535
+ }
2536
+ return BaseTelemetryPlugin;
2537
+ }());
2538
+
2539
+ var TelemetryInitializerPlugin = /** @class */ (function (_super) {
2540
+ __extendsFn(TelemetryInitializerPlugin, _super);
2541
+ function TelemetryInitializerPlugin() {
2542
+ var _this = _super.call(this) || this;
2543
+ _this.identifier = "TelemetryInitializerPlugin";
2544
+ _this.priority = 199;
2545
+ var _id;
2546
+ var _initializers;
2547
+ _initDefaults();
2548
+ dynamicProto(TelemetryInitializerPlugin, _this, function (_self, _base) {
2549
+ _self.addTelemetryInitializer = function (telemetryInitializer) {
2550
+ var theInitializer = {
2551
+ id: _id++,
2552
+ fn: telemetryInitializer
2553
+ };
2554
+ _initializers.push(theInitializer);
2555
+ var handler = {
2556
+ remove: function () {
2557
+ arrForEach(_initializers, function (initializer, idx) {
2558
+ if (initializer.id === theInitializer.id) {
2559
+ _initializers.splice(idx, 1);
2560
+ return -1;
2561
+ }
2562
+ });
2563
+ }
2564
+ };
2565
+ return handler;
2566
+ };
2567
+ _self.processTelemetry = function (item, itemCtx) {
2568
+ var doNotSendItem = false;
2569
+ var telemetryInitializersCount = _initializers.length;
2570
+ for (var i = 0; i < telemetryInitializersCount; ++i) {
2571
+ var telemetryInitializer = _initializers[i];
2572
+ if (telemetryInitializer) {
2573
+ try {
2574
+ if (telemetryInitializer.fn.apply(null, [item]) === false) {
2575
+ doNotSendItem = true;
2576
+ break;
2577
+ }
2578
+ }
2579
+ catch (e) {
2580
+ _throwInternal(itemCtx.diagLog(), 1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2581
+ }
2582
+ }
2583
+ }
2584
+ if (!doNotSendItem) {
2585
+ _self.processNext(item, itemCtx);
2586
+ }
2587
+ };
2588
+ _self[strDoTeardown] = function () {
2589
+ _initDefaults();
2590
+ };
2591
+ });
2592
+ function _initDefaults() {
2593
+ _id = 0;
2594
+ _initializers = [];
2595
+ }
2596
+ return _this;
2597
+ }
2598
+ return TelemetryInitializerPlugin;
2599
+ }(BaseTelemetryPlugin));
2600
+
2601
+ var strValidationError = "Plugins must provide initialize method";
1915
2602
  var strNotificationManager = "_notificationManager";
2603
+ var strSdkUnloadingError = "SDK is still unloading...";
2604
+ var strSdkNotInitialized = "SDK is not initialized";
1916
2605
  function _createPerfManager(core, notificationMgr) {
1917
2606
  return new PerfManager(notificationMgr);
1918
2607
  }
2608
+ function _validateExtensions(logger, channelPriority, allExtensions) {
2609
+ var coreExtensions = [];
2610
+ var extPriorities = {};
2611
+ arrForEach(allExtensions, function (ext) {
2612
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
2613
+ throwError(strValidationError);
2614
+ }
2615
+ var extPriority = ext.priority;
2616
+ var identifier = ext.identifier;
2617
+ if (ext && extPriority) {
2618
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
2619
+ _warnToConsole(logger, "Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
2620
+ }
2621
+ else {
2622
+ extPriorities[extPriority] = identifier;
2623
+ }
2624
+ }
2625
+ if (!extPriority || extPriority < channelPriority) {
2626
+ coreExtensions.push(ext);
2627
+ }
2628
+ });
2629
+ return {
2630
+ all: allExtensions,
2631
+ core: coreExtensions
2632
+ };
2633
+ }
2634
+ function _isPluginPresent(thePlugin, plugins) {
2635
+ var exists = false;
2636
+ arrForEach(plugins, function (plugin) {
2637
+ if (plugin === thePlugin) {
2638
+ exists = true;
2639
+ return -1;
2640
+ }
2641
+ });
2642
+ return exists;
2643
+ }
2644
+ function _createDummyNotificationManager() {
2645
+ var _a;
2646
+ return objCreateFn((_a = {},
2647
+ _a[strAddNotificationListener] = function (listener) { },
2648
+ _a[strRemoveNotificationListener] = function (listener) { },
2649
+ _a[strEventsSent] = function (events) { },
2650
+ _a[strEventsDiscarded] = function (events, reason) { },
2651
+ _a[strEventsSendRequest] = function (sendReason, isAsync) { },
2652
+ _a));
2653
+ }
1919
2654
  var BaseCore = /** @class */ (function () {
1920
2655
  function BaseCore() {
1921
- var _isInitialized = false;
2656
+ var _isInitialized;
1922
2657
  var _eventQueue;
1923
- var _channelController;
1924
2658
  var _notificationManager;
1925
2659
  var _perfManager;
2660
+ var _cfgPerfManager;
1926
2661
  var _cookieManager;
2662
+ var _pluginChain;
2663
+ var _configExtensions;
2664
+ var _coreExtensions;
2665
+ var _channelControl;
2666
+ var _channelConfig;
2667
+ var _channelQueue;
2668
+ var _isUnloading;
2669
+ var _telemetryInitializerPlugin;
2670
+ var _internalLogsEventName;
2671
+ var _evtNamespace;
2672
+ var _unloadHandlers;
2673
+ var _debugListener;
2674
+ var _internalLogPoller = 0;
1927
2675
  dynamicProto(BaseCore, this, function (_self) {
1928
- _self._extensions = new Array();
1929
- _channelController = new ChannelController();
1930
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
1931
- _eventQueue = [];
2676
+ _initDefaults();
1932
2677
  _self.isInitialized = function () { return _isInitialized; };
1933
2678
  _self.initialize = function (config, extensions, logger, notificationManager) {
2679
+ if (_isUnloading) {
2680
+ throwError(strSdkUnloadingError);
2681
+ }
1934
2682
  if (_self.isInitialized()) {
1935
2683
  throwError("Core should not be initialized more than once");
1936
2684
  }
@@ -1940,89 +2688,61 @@
1940
2688
  _notificationManager = notificationManager;
1941
2689
  _self[strNotificationManager] = notificationManager;
1942
2690
  _self.config = config || {};
1943
- if (notificationManager && _self.config.disableDbgExt !== true) {
1944
- notificationManager.addNotificationListener(getDebugListener(config));
1945
- }
1946
- if (_self.config.enablePerfMgr) {
1947
- setValue(_self.config, "createPerfMgr", _createPerfManager);
1948
- }
2691
+ _initDebugListener(config);
2692
+ _initPerfManager(config);
1949
2693
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
1950
- var extConfig = getSetValue(config, strExtensionConfig);
1951
- extConfig.NotificationManager = notificationManager;
2694
+ _initExtConfig(config);
1952
2695
  if (logger) {
1953
2696
  _self.logger = logger;
1954
2697
  }
1955
- var allExtensions = [];
1956
- allExtensions.push.apply(allExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
1957
- allExtensions = sortPlugins(allExtensions);
1958
- var coreExtensions = [];
1959
- var extPriorities = {};
1960
- arrForEach(allExtensions, function (ext) {
1961
- if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
1962
- throwError(validationError);
1963
- }
1964
- var extPriority = ext.priority;
1965
- var identifier = ext.identifier;
1966
- if (ext && extPriority) {
1967
- if (!isNullOrUndefined(extPriorities[extPriority])) {
1968
- logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
1969
- }
1970
- else {
1971
- extPriorities[extPriority] = identifier;
1972
- }
1973
- }
1974
- if (!extPriority || extPriority < _channelController.priority) {
1975
- coreExtensions.push(ext);
1976
- }
1977
- });
1978
- allExtensions.push(_channelController);
1979
- coreExtensions.push(_channelController);
1980
- allExtensions = sortPlugins(allExtensions);
1981
- _self._extensions = allExtensions;
1982
- initializePlugins(new ProcessTelemetryContext([_channelController], config, _self), allExtensions);
1983
- initializePlugins(new ProcessTelemetryContext(coreExtensions, config, _self), allExtensions);
1984
- _self._extensions = coreExtensions;
1985
- if (_self.getTransmissionControls().length === 0) {
2698
+ _configExtensions = [];
2699
+ _configExtensions.push.apply(_configExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2700
+ _channelConfig = (config || {}).channels;
2701
+ _initPluginChain(config, null);
2702
+ if (!_channelQueue || _channelQueue.length === 0) {
1986
2703
  throwError("No channels available");
1987
2704
  }
1988
2705
  _isInitialized = true;
1989
2706
  _self.releaseQueue();
1990
2707
  };
1991
2708
  _self.getTransmissionControls = function () {
1992
- return _channelController.getChannelControls();
2709
+ var controls = [];
2710
+ if (_channelQueue) {
2711
+ arrForEach(_channelQueue, function (channels) {
2712
+ controls.push(channels.queue);
2713
+ });
2714
+ }
2715
+ return objFreeze(controls);
1993
2716
  };
1994
2717
  _self.track = function (telemetryItem) {
1995
2718
  setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
1996
2719
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
1997
2720
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
1998
- if (_self.isInitialized()) {
1999
- _self.getProcessTelContext().processNext(telemetryItem);
2721
+ if (!_isUnloading && _self.isInitialized()) {
2722
+ _createTelCtx().processNext(telemetryItem);
2000
2723
  }
2001
2724
  else {
2002
2725
  _eventQueue.push(telemetryItem);
2003
2726
  }
2004
2727
  };
2005
- _self.getProcessTelContext = function () {
2006
- var extensions = _self._extensions;
2007
- var thePlugins = extensions;
2008
- if (!extensions || extensions.length === 0) {
2009
- thePlugins = [_channelController];
2010
- }
2011
- return new ProcessTelemetryContext(thePlugins, _self.config, _self);
2012
- };
2728
+ _self.getProcessTelContext = _createTelCtx;
2013
2729
  _self.getNotifyMgr = function () {
2014
2730
  if (!_notificationManager) {
2015
- _notificationManager = objCreateFn({
2016
- addNotificationListener: function (listener) { },
2017
- removeNotificationListener: function (listener) { },
2018
- eventsSent: function (events) { },
2019
- eventsDiscarded: function (events, reason) { },
2020
- eventsSendRequest: function (sendReason, isAsync) { }
2021
- });
2731
+ _notificationManager = _createDummyNotificationManager();
2022
2732
  _self[strNotificationManager] = _notificationManager;
2023
2733
  }
2024
2734
  return _notificationManager;
2025
2735
  };
2736
+ _self[strAddNotificationListener] = function (listener) {
2737
+ if (_notificationManager) {
2738
+ _notificationManager[strAddNotificationListener](listener);
2739
+ }
2740
+ };
2741
+ _self[strRemoveNotificationListener] = function (listener) {
2742
+ if (_notificationManager) {
2743
+ _notificationManager[strRemoveNotificationListener](listener);
2744
+ }
2745
+ };
2026
2746
  _self.getCookieMgr = function () {
2027
2747
  if (!_cookieManager) {
2028
2748
  _cookieManager = createCookieMgr(_self.config, _self.logger);
@@ -2033,12 +2753,12 @@
2033
2753
  _cookieManager = cookieMgr;
2034
2754
  };
2035
2755
  _self.getPerfMgr = function () {
2036
- if (!_perfManager) {
2756
+ if (!_perfManager && !_cfgPerfManager) {
2037
2757
  if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
2038
- _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
2758
+ _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
2039
2759
  }
2040
2760
  }
2041
- return _perfManager || getGblPerfMgr();
2761
+ return _perfManager || _cfgPerfManager || getGblPerfMgr();
2042
2762
  };
2043
2763
  _self.setPerfMgr = function (perfMgr) {
2044
2764
  _perfManager = perfMgr;
@@ -2047,78 +2767,381 @@
2047
2767
  return _eventQueue.length;
2048
2768
  };
2049
2769
  _self.releaseQueue = function () {
2050
- if (_eventQueue.length > 0) {
2051
- arrForEach(_eventQueue, function (event) {
2052
- _self.getProcessTelContext().processNext(event);
2053
- });
2770
+ if (_isInitialized && _eventQueue.length > 0) {
2771
+ var eventQueue = _eventQueue;
2054
2772
  _eventQueue = [];
2773
+ arrForEach(eventQueue, function (event) {
2774
+ _createTelCtx().processNext(event);
2775
+ });
2776
+ }
2777
+ };
2778
+ _self.pollInternalLogs = function (eventName) {
2779
+ _internalLogsEventName = eventName || null;
2780
+ var interval = _self.config.diagnosticLogInterval;
2781
+ if (!interval || !(interval > 0)) {
2782
+ interval = 10000;
2783
+ }
2784
+ if (_internalLogPoller) {
2785
+ clearInterval(_internalLogPoller);
2786
+ }
2787
+ _internalLogPoller = setInterval(function () {
2788
+ _flushInternalLogs();
2789
+ }, interval);
2790
+ return _internalLogPoller;
2791
+ };
2792
+ _self.stopPollingInternalLogs = function () {
2793
+ if (_internalLogPoller) {
2794
+ clearInterval(_internalLogPoller);
2795
+ _internalLogPoller = 0;
2796
+ _flushInternalLogs();
2797
+ }
2798
+ };
2799
+ proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
2800
+ _self.unload = function (isAsync, unloadComplete, cbTimeout) {
2801
+ if (isAsync === void 0) { isAsync = true; }
2802
+ if (!_isInitialized) {
2803
+ throwError(strSdkNotInitialized);
2804
+ }
2805
+ if (_isUnloading) {
2806
+ throwError(strSdkUnloadingError);
2807
+ }
2808
+ var unloadState = {
2809
+ reason: 50 ,
2810
+ isAsync: isAsync,
2811
+ flushComplete: false
2812
+ };
2813
+ var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
2814
+ processUnloadCtx.onComplete(function () {
2815
+ _initDefaults();
2816
+ unloadComplete && unloadComplete(unloadState);
2817
+ }, _self);
2818
+ function _doUnload(flushComplete) {
2819
+ unloadState.flushComplete = flushComplete;
2820
+ _isUnloading = true;
2821
+ _unloadHandlers.run(processUnloadCtx, unloadState);
2822
+ _self.stopPollingInternalLogs();
2823
+ processUnloadCtx.processNext(unloadState);
2824
+ }
2825
+ if (!_flushChannels(isAsync, _doUnload, 6 , cbTimeout)) {
2826
+ _doUnload(false);
2827
+ }
2828
+ };
2829
+ _self.getPlugin = _getPlugin;
2830
+ _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
2831
+ if (!plugin) {
2832
+ addCb && addCb(false);
2833
+ _logOrThrowError(strValidationError);
2834
+ return;
2835
+ }
2836
+ var existingPlugin = _getPlugin(plugin.identifier);
2837
+ if (existingPlugin && !replaceExisting) {
2838
+ addCb && addCb(false);
2839
+ _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2840
+ return;
2841
+ }
2842
+ var updateState = {
2843
+ reason: 16
2844
+ };
2845
+ function _addPlugin(removed) {
2846
+ _configExtensions.push(plugin);
2847
+ updateState.added = [plugin];
2848
+ _initPluginChain(_self.config, updateState);
2849
+ addCb && addCb(true);
2850
+ }
2851
+ if (existingPlugin) {
2852
+ var removedPlugins_1 = [existingPlugin.plugin];
2853
+ var unloadState = {
2854
+ reason: 2 ,
2855
+ isAsync: !!isAsync
2856
+ };
2857
+ _removePlugins(removedPlugins_1, unloadState, function (removed) {
2858
+ if (!removed) {
2859
+ addCb && addCb(false);
2860
+ }
2861
+ else {
2862
+ updateState.removed = removedPlugins_1;
2863
+ updateState.reason |= 32 ;
2864
+ _addPlugin();
2865
+ }
2866
+ });
2867
+ }
2868
+ else {
2869
+ _addPlugin();
2055
2870
  }
2056
2871
  };
2872
+ _self.evtNamespace = function () {
2873
+ return _evtNamespace;
2874
+ };
2875
+ _self.flush = _flushChannels;
2876
+ proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2877
+ function _initDefaults() {
2878
+ _isInitialized = false;
2879
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 });
2880
+ _self.config = {};
2881
+ _self._extensions = [];
2882
+ _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
2883
+ _eventQueue = [];
2884
+ _notificationManager = null;
2885
+ _perfManager = null;
2886
+ _cfgPerfManager = null;
2887
+ _cookieManager = null;
2888
+ _pluginChain = null;
2889
+ _coreExtensions = null;
2890
+ _configExtensions = [];
2891
+ _channelControl = null;
2892
+ _channelConfig = null;
2893
+ _channelQueue = null;
2894
+ _isUnloading = false;
2895
+ _internalLogsEventName = null;
2896
+ _evtNamespace = createUniqueNamespace("AIBaseCore", true);
2897
+ _unloadHandlers = createUnloadHandlerContainer();
2898
+ }
2899
+ function _createTelCtx() {
2900
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2901
+ }
2902
+ function _initPluginChain(config, updateState) {
2903
+ var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
2904
+ _coreExtensions = theExtensions.core;
2905
+ _pluginChain = null;
2906
+ var allExtensions = theExtensions.all;
2907
+ _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
2908
+ if (_channelControl) {
2909
+ var idx = allExtensions.indexOf(_channelControl);
2910
+ if (idx !== -1) {
2911
+ allExtensions.splice(idx, 1);
2912
+ }
2913
+ idx = _coreExtensions.indexOf(_channelControl);
2914
+ if (idx !== -1) {
2915
+ _coreExtensions.splice(idx, 1);
2916
+ }
2917
+ _channelControl._setQueue(_channelQueue);
2918
+ }
2919
+ else {
2920
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
2921
+ }
2922
+ allExtensions.push(_channelControl);
2923
+ _coreExtensions.push(_channelControl);
2924
+ _self._extensions = sortPlugins(allExtensions);
2925
+ _channelControl.initialize(config, _self, allExtensions);
2926
+ initializePlugins(_createTelCtx(), allExtensions);
2927
+ _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2928
+ if (updateState) {
2929
+ _doUpdate(updateState);
2930
+ }
2931
+ }
2932
+ function _getPlugin(pluginIdentifier) {
2933
+ var theExt = null;
2934
+ var thePlugin = null;
2935
+ arrForEach(_self._extensions, function (ext) {
2936
+ if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
2937
+ thePlugin = ext;
2938
+ return -1;
2939
+ }
2940
+ });
2941
+ if (!thePlugin && _channelControl) {
2942
+ thePlugin = _channelControl.getChannel(pluginIdentifier);
2943
+ }
2944
+ if (thePlugin) {
2945
+ theExt = {
2946
+ plugin: thePlugin,
2947
+ setEnabled: function (enabled) {
2948
+ _getPluginState(thePlugin)[strDisabled] = !enabled;
2949
+ },
2950
+ isEnabled: function () {
2951
+ var pluginState = _getPluginState(thePlugin);
2952
+ return !pluginState[strTeardown] && !pluginState[strDisabled];
2953
+ },
2954
+ remove: function (isAsync, removeCb) {
2955
+ if (isAsync === void 0) { isAsync = true; }
2956
+ var pluginsToRemove = [thePlugin];
2957
+ var unloadState = {
2958
+ reason: 1 ,
2959
+ isAsync: isAsync
2960
+ };
2961
+ _removePlugins(pluginsToRemove, unloadState, function (removed) {
2962
+ if (removed) {
2963
+ _initPluginChain(_self.config, {
2964
+ reason: 32 ,
2965
+ removed: pluginsToRemove
2966
+ });
2967
+ }
2968
+ removeCb && removeCb(removed);
2969
+ });
2970
+ }
2971
+ };
2972
+ }
2973
+ return theExt;
2974
+ }
2975
+ function _getPluginChain() {
2976
+ if (!_pluginChain) {
2977
+ var extensions = (_coreExtensions || []).slice();
2978
+ if (extensions.indexOf(_telemetryInitializerPlugin) === -1) {
2979
+ extensions.push(_telemetryInitializerPlugin);
2980
+ }
2981
+ _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
2982
+ }
2983
+ return _pluginChain;
2984
+ }
2985
+ function _removePlugins(thePlugins, unloadState, removeComplete) {
2986
+ if (thePlugins && thePlugins.length > 0) {
2987
+ var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
2988
+ var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
2989
+ unloadCtx.onComplete(function () {
2990
+ var removed = false;
2991
+ var newConfigExtensions = [];
2992
+ arrForEach(_configExtensions, function (plugin, idx) {
2993
+ if (!_isPluginPresent(plugin, thePlugins)) {
2994
+ newConfigExtensions.push(plugin);
2995
+ }
2996
+ else {
2997
+ removed = true;
2998
+ }
2999
+ });
3000
+ _configExtensions = newConfigExtensions;
3001
+ var newChannelConfig = [];
3002
+ if (_channelConfig) {
3003
+ arrForEach(_channelConfig, function (queue, idx) {
3004
+ var newQueue = [];
3005
+ arrForEach(queue, function (channel) {
3006
+ if (!_isPluginPresent(channel, thePlugins)) {
3007
+ newQueue.push(channel);
3008
+ }
3009
+ else {
3010
+ removed = true;
3011
+ }
3012
+ });
3013
+ newChannelConfig.push(newQueue);
3014
+ });
3015
+ _channelConfig = newChannelConfig;
3016
+ }
3017
+ removeComplete && removeComplete(removed);
3018
+ });
3019
+ unloadCtx.processNext(unloadState);
3020
+ }
3021
+ else {
3022
+ removeComplete(false);
3023
+ }
3024
+ }
3025
+ function _flushInternalLogs() {
3026
+ var queue = _self.logger ? _self.logger.queue : [];
3027
+ if (queue) {
3028
+ arrForEach(queue, function (logMessage) {
3029
+ var item = {
3030
+ name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
3031
+ iKey: _self.config.instrumentationKey,
3032
+ time: toISOString(new Date()),
3033
+ baseType: _InternalLogMessage.dataType,
3034
+ baseData: { message: logMessage.message }
3035
+ };
3036
+ _self.track(item);
3037
+ });
3038
+ queue.length = 0;
3039
+ }
3040
+ }
3041
+ function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
3042
+ if (_channelControl) {
3043
+ return _channelControl.flush(isAsync, callBack, sendReason || 6 , cbTimeout);
3044
+ }
3045
+ callBack && callBack(false);
3046
+ return true;
3047
+ }
3048
+ function _initDebugListener(config) {
3049
+ if (config.disableDbgExt === true && _debugListener) {
3050
+ _notificationManager[strRemoveNotificationListener](_debugListener);
3051
+ _debugListener = null;
3052
+ }
3053
+ if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
3054
+ _debugListener = getDebugListener(config);
3055
+ _notificationManager[strAddNotificationListener](_debugListener);
3056
+ }
3057
+ }
3058
+ function _initPerfManager(config) {
3059
+ if (!config.enablePerfMgr && _cfgPerfManager) {
3060
+ _cfgPerfManager = null;
3061
+ }
3062
+ if (config.enablePerfMgr) {
3063
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
3064
+ }
3065
+ }
3066
+ function _initExtConfig(config) {
3067
+ var extConfig = getSetValue(config, strExtensionConfig);
3068
+ extConfig.NotificationManager = _notificationManager;
3069
+ }
3070
+ function _doUpdate(updateState) {
3071
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self.config, _self);
3072
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3073
+ updateCtx.processNext(updateState);
3074
+ }
3075
+ }
3076
+ function _logOrThrowError(message) {
3077
+ var logger = _self.logger;
3078
+ if (logger) {
3079
+ _throwInternal(logger, 2 , 73 , message);
3080
+ }
3081
+ else {
3082
+ throwError(message);
3083
+ }
3084
+ }
2057
3085
  });
2058
3086
  }
2059
3087
  return BaseCore;
2060
3088
  }());
2061
3089
 
3090
+ function _runListeners(listeners, name, isAsync, callback) {
3091
+ arrForEach(listeners, function (listener) {
3092
+ if (listener && listener[name]) {
3093
+ if (isAsync) {
3094
+ setTimeout(function () { return callback(listener); }, 0);
3095
+ }
3096
+ else {
3097
+ try {
3098
+ callback(listener);
3099
+ }
3100
+ catch (e) {
3101
+ }
3102
+ }
3103
+ }
3104
+ });
3105
+ }
2062
3106
  var NotificationManager = /** @class */ (function () {
2063
3107
  function NotificationManager(config) {
2064
3108
  this.listeners = [];
2065
3109
  var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
2066
3110
  dynamicProto(NotificationManager, this, function (_self) {
2067
- _self.addNotificationListener = function (listener) {
3111
+ _self[strAddNotificationListener] = function (listener) {
2068
3112
  _self.listeners.push(listener);
2069
3113
  };
2070
- _self.removeNotificationListener = function (listener) {
3114
+ _self[strRemoveNotificationListener] = function (listener) {
2071
3115
  var index = arrIndexOf(_self.listeners, listener);
2072
3116
  while (index > -1) {
2073
3117
  _self.listeners.splice(index, 1);
2074
3118
  index = arrIndexOf(_self.listeners, listener);
2075
3119
  }
2076
3120
  };
2077
- _self.eventsSent = function (events) {
2078
- arrForEach(_self.listeners, function (listener) {
2079
- if (listener && listener.eventsSent) {
2080
- setTimeout(function () { return listener.eventsSent(events); }, 0);
2081
- }
3121
+ _self[strEventsSent] = function (events) {
3122
+ _runListeners(_self.listeners, strEventsSent, true, function (listener) {
3123
+ listener[strEventsSent](events);
2082
3124
  });
2083
3125
  };
2084
- _self.eventsDiscarded = function (events, reason) {
2085
- arrForEach(_self.listeners, function (listener) {
2086
- if (listener && listener.eventsDiscarded) {
2087
- setTimeout(function () { return listener.eventsDiscarded(events, reason); }, 0);
2088
- }
3126
+ _self[strEventsDiscarded] = function (events, reason) {
3127
+ _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
3128
+ listener[strEventsDiscarded](events, reason);
2089
3129
  });
2090
3130
  };
2091
- _self.eventsSendRequest = function (sendReason, isAsync) {
2092
- arrForEach(_self.listeners, function (listener) {
2093
- if (listener && listener.eventsSendRequest) {
2094
- if (isAsync) {
2095
- setTimeout(function () { return listener.eventsSendRequest(sendReason, isAsync); }, 0);
2096
- }
2097
- else {
2098
- try {
2099
- listener.eventsSendRequest(sendReason, isAsync);
2100
- }
2101
- catch (e) {
2102
- }
2103
- }
2104
- }
3131
+ _self[strEventsSendRequest] = function (sendReason, isAsync) {
3132
+ _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
3133
+ listener[strEventsSendRequest](sendReason, isAsync);
2105
3134
  });
2106
3135
  };
2107
- _self.perfEvent = function (perfEvent) {
3136
+ _self[strPerfEvent] = function (perfEvent) {
2108
3137
  if (perfEvent) {
2109
3138
  if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
2110
- arrForEach(_self.listeners, function (listener) {
2111
- if (listener && listener.perfEvent) {
2112
- if (perfEvent.isAsync) {
2113
- setTimeout(function () { return listener.perfEvent(perfEvent); }, 0);
2114
- }
2115
- else {
2116
- try {
2117
- listener.perfEvent(perfEvent);
2118
- }
2119
- catch (e) {
2120
- }
2121
- }
3139
+ _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
3140
+ if (perfEvent.isAsync) {
3141
+ setTimeout(function () { return listener[strPerfEvent](perfEvent); }, 0);
3142
+ }
3143
+ else {
3144
+ listener[strPerfEvent](perfEvent);
2122
3145
  }
2123
3146
  });
2124
3147
  }
@@ -2133,7 +3156,6 @@
2133
3156
  __extendsFn(AppInsightsCore, _super);
2134
3157
  function AppInsightsCore() {
2135
3158
  var _this = _super.call(this) || this;
2136
- var _internalLogPoller = 0;
2137
3159
  dynamicProto(AppInsightsCore, _this, function (_self, _base) {
2138
3160
  _self.initialize = function (config, extensions, logger, notificationManager) {
2139
3161
  _base.initialize(config, extensions, logger || new DiagnosticLogger(config), notificationManager || new NotificationManager(config));
@@ -2148,48 +3170,6 @@
2148
3170
  _base.track(telemetryItem);
2149
3171
  }, function () { return ({ item: telemetryItem }); }, !(telemetryItem.sync));
2150
3172
  };
2151
- _self.addNotificationListener = function (listener) {
2152
- var manager = _self.getNotifyMgr();
2153
- if (manager) {
2154
- manager.addNotificationListener(listener);
2155
- }
2156
- };
2157
- _self.removeNotificationListener = function (listener) {
2158
- var manager = _self.getNotifyMgr();
2159
- if (manager) {
2160
- manager.removeNotificationListener(listener);
2161
- }
2162
- };
2163
- _self.pollInternalLogs = function (eventName) {
2164
- var interval = _self.config.diagnosticLogInterval;
2165
- if (!interval || !(interval > 0)) {
2166
- interval = 10000;
2167
- }
2168
- if (_internalLogPoller) {
2169
- _self.stopPollingInternalLogs();
2170
- }
2171
- _internalLogPoller = setInterval(function () {
2172
- var queue = _self.logger ? _self.logger.queue : [];
2173
- arrForEach(queue, function (logMessage) {
2174
- var item = {
2175
- name: eventName ? eventName : "InternalMessageId: " + logMessage.messageId,
2176
- iKey: _self.config.instrumentationKey,
2177
- time: toISOString(new Date()),
2178
- baseType: _InternalLogMessage.dataType,
2179
- baseData: { message: logMessage.message }
2180
- };
2181
- _self.track(item);
2182
- });
2183
- queue.length = 0;
2184
- }, interval);
2185
- return _internalLogPoller;
2186
- };
2187
- _self.stopPollingInternalLogs = function () {
2188
- if (!_internalLogPoller)
2189
- return;
2190
- clearInterval(_internalLogPoller);
2191
- _internalLogPoller = 0;
2192
- };
2193
3173
  function _validateTelemetryItem(telemetryItem) {
2194
3174
  if (isNullOrUndefined(telemetryItem.name)) {
2195
3175
  _notifyInvalidEvent(telemetryItem);
@@ -2199,95 +3179,201 @@
2199
3179
  function _notifyInvalidEvent(telemetryItem) {
2200
3180
  var manager = _self.getNotifyMgr();
2201
3181
  if (manager) {
2202
- manager.eventsDiscarded([telemetryItem], EventsDiscardedReason.InvalidEvent);
3182
+ manager.eventsDiscarded([telemetryItem], 2 );
2203
3183
  }
2204
3184
  }
2205
3185
  });
2206
3186
  return _this;
2207
3187
  }
2208
- return AppInsightsCore;
2209
- }(BaseCore));
2210
-
2211
- var UInt32Mask = 0x100000000;
2212
- var MaxUInt32 = 0xffffffff;
2213
- var _mwcSeeded = false;
2214
- var _mwcW = 123456789;
2215
- var _mwcZ = 987654321;
2216
- function _mwcSeed(seedValue) {
2217
- if (seedValue < 0) {
2218
- seedValue >>>= 0;
3188
+ return AppInsightsCore;
3189
+ }(BaseCore));
3190
+
3191
+ var strOnPrefix = "on";
3192
+ var strAttachEvent = "attachEvent";
3193
+ var strAddEventHelper = "addEventListener";
3194
+ var strDetachEvent = "detachEvent";
3195
+ var strRemoveEventListener = "removeEventListener";
3196
+ var strEvents = "events";
3197
+ createUniqueNamespace("aiEvtPageHide");
3198
+ createUniqueNamespace("aiEvtPageShow");
3199
+ var rRemoveEmptyNs = /\.[\.]+/g;
3200
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
3201
+ var _guid = 1;
3202
+ var elmNodeData = createElmNodeData("events");
3203
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
3204
+ function _normalizeNamespace(name) {
3205
+ if (name && name.replace) {
3206
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
3207
+ }
3208
+ return name;
3209
+ }
3210
+ function _getEvtNamespace(eventName, evtNamespace) {
3211
+ if (evtNamespace) {
3212
+ var theNamespace_1 = "";
3213
+ if (isArray(evtNamespace)) {
3214
+ theNamespace_1 = "";
3215
+ arrForEach(evtNamespace, function (name) {
3216
+ name = _normalizeNamespace(name);
3217
+ if (name) {
3218
+ if (name[0] !== ".") {
3219
+ name = "." + name;
3220
+ }
3221
+ theNamespace_1 += name;
3222
+ }
3223
+ });
3224
+ }
3225
+ else {
3226
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
3227
+ }
3228
+ if (theNamespace_1) {
3229
+ if (theNamespace_1[0] !== ".") {
3230
+ theNamespace_1 = "." + theNamespace_1;
3231
+ }
3232
+ eventName = (eventName || "") + theNamespace_1;
3233
+ }
2219
3234
  }
2220
- _mwcW = (123456789 + seedValue) & MaxUInt32;
2221
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
2222
- _mwcSeeded = true;
3235
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
3236
+ return {
3237
+ type: parsedEvent[1],
3238
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
3239
+ };
2223
3240
  }
2224
- function _autoSeedMwc() {
2225
- try {
2226
- var now = dateNow() & 0x7fffffff;
2227
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
2228
- }
2229
- catch (e) {
3241
+ function _getRegisteredEvents(target, evtName, addDefault) {
3242
+ if (addDefault === void 0) { addDefault = true; }
3243
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
3244
+ var registeredEvents = aiEvts[evtName];
3245
+ if (!registeredEvents) {
3246
+ registeredEvents = aiEvts[evtName] = [];
2230
3247
  }
3248
+ return registeredEvents;
2231
3249
  }
2232
- function randomValue(maxValue) {
2233
- if (maxValue > 0) {
2234
- return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
3250
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
3251
+ if (obj && evtName && evtName.type) {
3252
+ if (obj[strRemoveEventListener]) {
3253
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3254
+ }
3255
+ else if (obj[strDetachEvent]) {
3256
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3257
+ }
2235
3258
  }
2236
- return 0;
2237
3259
  }
2238
- function random32(signed) {
2239
- var value;
2240
- var c = getCrypto() || getMsCrypto();
2241
- if (c && c.getRandomValues) {
2242
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
3260
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
3261
+ var result = false;
3262
+ if (obj && evtName && evtName.type && handlerRef) {
3263
+ if (obj[strAddEventHelper]) {
3264
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
3265
+ result = true;
3266
+ }
3267
+ else if (obj[strAttachEvent]) {
3268
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
3269
+ result = true;
3270
+ }
2243
3271
  }
2244
- else if (isIE()) {
2245
- if (!_mwcSeeded) {
2246
- _autoSeedMwc();
3272
+ return result;
3273
+ }
3274
+ function _doUnregister(target, events, evtName, unRegFn) {
3275
+ var idx = events.length;
3276
+ while (idx--) {
3277
+ var theEvent = events[idx];
3278
+ if (theEvent) {
3279
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3280
+ if (!unRegFn || unRegFn(theEvent)) {
3281
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3282
+ events.splice(idx, 1);
3283
+ }
3284
+ }
2247
3285
  }
2248
- value = mwcRandom32() & MaxUInt32;
2249
3286
  }
2250
- else {
2251
- value = Math.floor((UInt32Mask * Math.random()) | 0);
3287
+ }
3288
+ function _unregisterEvents(target, evtName, unRegFn) {
3289
+ if (evtName.type) {
3290
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
2252
3291
  }
2253
- if (!signed) {
2254
- value >>>= 0;
3292
+ else {
3293
+ var eventCache = elmNodeData.get(target, strEvents, {});
3294
+ objForEachKey(eventCache, function (evtType, events) {
3295
+ _doUnregister(target, events, evtName, unRegFn);
3296
+ });
3297
+ if (objKeys(eventCache).length === 0) {
3298
+ elmNodeData.kill(target, strEvents);
3299
+ }
2255
3300
  }
2256
- return value;
2257
3301
  }
2258
- function mwcRandomSeed(value) {
2259
- if (!value) {
2260
- _autoSeedMwc();
3302
+ function mergeEvtNamespace(theNamespace, namespaces) {
3303
+ var newNamespaces;
3304
+ if (namespaces) {
3305
+ if (isArray(namespaces)) {
3306
+ newNamespaces = [theNamespace].concat(namespaces);
3307
+ }
3308
+ else {
3309
+ newNamespaces = [theNamespace, namespaces];
3310
+ }
3311
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
2261
3312
  }
2262
3313
  else {
2263
- _mwcSeed(value);
3314
+ newNamespaces = theNamespace;
2264
3315
  }
3316
+ return newNamespaces;
2265
3317
  }
2266
- function mwcRandom32(signed) {
2267
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
2268
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
2269
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
2270
- if (!signed) {
2271
- value >>>= 0;
3318
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3319
+ if (useCapture === void 0) { useCapture = false; }
3320
+ var result = false;
3321
+ if (target) {
3322
+ try {
3323
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
3324
+ result = _doAttach(target, evtName, handlerRef, useCapture);
3325
+ if (result && elmNodeData.accept(target)) {
3326
+ var registeredEvent = {
3327
+ guid: _guid++,
3328
+ evtName: evtName,
3329
+ handler: handlerRef,
3330
+ capture: useCapture
3331
+ };
3332
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
3333
+ }
3334
+ }
3335
+ catch (e) {
3336
+ }
2272
3337
  }
2273
- return value;
3338
+ return result;
2274
3339
  }
2275
-
2276
- var _cookieMgrs = null;
2277
- var _canUseCookies;
2278
- function addEventHandler(eventName, callback) {
3340
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3341
+ if (useCapture === void 0) { useCapture = false; }
3342
+ if (target) {
3343
+ try {
3344
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3345
+ var found_1 = false;
3346
+ _unregisterEvents(target, evtName_1, function (regEvent) {
3347
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3348
+ found_1 = true;
3349
+ return true;
3350
+ }
3351
+ return false;
3352
+ });
3353
+ if (!found_1) {
3354
+ _doDetach(target, evtName_1, handlerRef, useCapture);
3355
+ }
3356
+ }
3357
+ catch (e) {
3358
+ }
3359
+ }
3360
+ }
3361
+ function addEventHandler(eventName, callback, evtNamespace) {
2279
3362
  var result = false;
2280
3363
  var w = getWindow();
2281
3364
  if (w) {
2282
- result = attachEvent(w, eventName, callback);
2283
- result = attachEvent(w["body"], eventName, callback) || result;
3365
+ result = eventOn(w, eventName, callback, evtNamespace);
3366
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
2284
3367
  }
2285
3368
  var doc = getDocument();
2286
3369
  if (doc) {
2287
- result = attachEvent(doc, eventName, callback) || result;
3370
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
2288
3371
  }
2289
3372
  return result;
2290
3373
  }
3374
+
3375
+ var _cookieMgrs = null;
3376
+ var _canUseCookies;
2291
3377
  function newGuid() {
2292
3378
  function randomHexDigit() {
2293
3379
  return randomValue(15);
@@ -2304,26 +3390,9 @@
2304
3390
  }
2305
3391
  return dateNow();
2306
3392
  }
2307
- function newId(maxLength) {
2308
- if (maxLength === void 0) { maxLength = 22; }
2309
- var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2310
- var number = random32() >>> 0;
2311
- var chars = 0;
2312
- var result = "";
2313
- while (result.length < maxLength) {
2314
- chars++;
2315
- result += base64chars.charAt(number & 0x3F);
2316
- number >>>= 6;
2317
- if (chars === 5) {
2318
- number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
2319
- chars = 0;
2320
- }
2321
- }
2322
- return result;
2323
- }
2324
3393
  function generateW3CId() {
2325
3394
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
2326
- var oct = "", tmp;
3395
+ var oct = strEmpty$1, tmp;
2327
3396
  for (var a = 0; a < 4; a++) {
2328
3397
  tmp = random32();
2329
3398
  oct +=
@@ -2406,6 +3475,95 @@
2406
3475
  _legacyCookieMgr().setEnabled(false);
2407
3476
  }
2408
3477
 
3478
+ var LoggingSeverity = createEnumStyle({
3479
+ CRITICAL: 1 ,
3480
+ WARNING: 2
3481
+ });
3482
+ var _InternalMessageId = createEnumStyle({
3483
+ BrowserDoesNotSupportLocalStorage: 0 ,
3484
+ BrowserCannotReadLocalStorage: 1 ,
3485
+ BrowserCannotReadSessionStorage: 2 ,
3486
+ BrowserCannotWriteLocalStorage: 3 ,
3487
+ BrowserCannotWriteSessionStorage: 4 ,
3488
+ BrowserFailedRemovalFromLocalStorage: 5 ,
3489
+ BrowserFailedRemovalFromSessionStorage: 6 ,
3490
+ CannotSendEmptyTelemetry: 7 ,
3491
+ ClientPerformanceMathError: 8 ,
3492
+ ErrorParsingAISessionCookie: 9 ,
3493
+ ErrorPVCalc: 10 ,
3494
+ ExceptionWhileLoggingError: 11 ,
3495
+ FailedAddingTelemetryToBuffer: 12 ,
3496
+ FailedMonitorAjaxAbort: 13 ,
3497
+ FailedMonitorAjaxDur: 14 ,
3498
+ FailedMonitorAjaxOpen: 15 ,
3499
+ FailedMonitorAjaxRSC: 16 ,
3500
+ FailedMonitorAjaxSend: 17 ,
3501
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
3502
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
3503
+ FailedToSendQueuedTelemetry: 20 ,
3504
+ FailedToReportDataLoss: 21 ,
3505
+ FlushFailed: 22 ,
3506
+ MessageLimitPerPVExceeded: 23 ,
3507
+ MissingRequiredFieldSpecification: 24 ,
3508
+ NavigationTimingNotSupported: 25 ,
3509
+ OnError: 26 ,
3510
+ SessionRenewalDateIsZero: 27 ,
3511
+ SenderNotInitialized: 28 ,
3512
+ StartTrackEventFailed: 29 ,
3513
+ StopTrackEventFailed: 30 ,
3514
+ StartTrackFailed: 31 ,
3515
+ StopTrackFailed: 32 ,
3516
+ TelemetrySampledAndNotSent: 33 ,
3517
+ TrackEventFailed: 34 ,
3518
+ TrackExceptionFailed: 35 ,
3519
+ TrackMetricFailed: 36 ,
3520
+ TrackPVFailed: 37 ,
3521
+ TrackPVFailedCalc: 38 ,
3522
+ TrackTraceFailed: 39 ,
3523
+ TransmissionFailed: 40 ,
3524
+ FailedToSetStorageBuffer: 41 ,
3525
+ FailedToRestoreStorageBuffer: 42 ,
3526
+ InvalidBackendResponse: 43 ,
3527
+ FailedToFixDepricatedValues: 44 ,
3528
+ InvalidDurationValue: 45 ,
3529
+ TelemetryEnvelopeInvalid: 46 ,
3530
+ CreateEnvelopeError: 47 ,
3531
+ CannotSerializeObject: 48 ,
3532
+ CannotSerializeObjectNonSerializable: 49 ,
3533
+ CircularReferenceDetected: 50 ,
3534
+ ClearAuthContextFailed: 51 ,
3535
+ ExceptionTruncated: 52 ,
3536
+ IllegalCharsInName: 53 ,
3537
+ ItemNotInArray: 54 ,
3538
+ MaxAjaxPerPVExceeded: 55 ,
3539
+ MessageTruncated: 56 ,
3540
+ NameTooLong: 57 ,
3541
+ SampleRateOutOfRange: 58 ,
3542
+ SetAuthContextFailed: 59 ,
3543
+ SetAuthContextFailedAccountName: 60 ,
3544
+ StringValueTooLong: 61 ,
3545
+ StartCalledMoreThanOnce: 62 ,
3546
+ StopCalledWithoutStart: 63 ,
3547
+ TelemetryInitializerFailed: 64 ,
3548
+ TrackArgumentsNotSpecified: 65 ,
3549
+ UrlTooLong: 66 ,
3550
+ SessionStorageBufferFull: 67 ,
3551
+ CannotAccessCookie: 68 ,
3552
+ IdTooLong: 69 ,
3553
+ InvalidEvent: 70 ,
3554
+ FailedMonitorAjaxSetRequestHeader: 71 ,
3555
+ SendBrowserInfoOnUserInit: 72 ,
3556
+ PluginException: 73 ,
3557
+ NotificationException: 74 ,
3558
+ SnippetScriptLoadFailure: 99 ,
3559
+ InvalidInstrumentationKey: 100 ,
3560
+ CannotParseAiBlobValue: 101 ,
3561
+ InvalidContentBlob: 102 ,
3562
+ TrackPageActionEventFailed: 103 ,
3563
+ FailedAddingCustomDefinedRequestContext: 104 ,
3564
+ InMemoryStorageBufferFull: 105
3565
+ });
3566
+
2409
3567
  var RequestHeaders = {
2410
3568
  requestContextHeader: "Request-Context",
2411
3569
  requestContextTargetKey: "appId",
@@ -2438,7 +3596,7 @@
2438
3596
  name = strTrim(name.toString());
2439
3597
  if (name.length > 150 ) {
2440
3598
  nameTrunc = name.substring(0, 150 );
2441
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3599
+ _throwInternal(logger, 2 , 57 , "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2442
3600
  }
2443
3601
  }
2444
3602
  return nameTrunc || name;
@@ -2451,20 +3609,20 @@
2451
3609
  value = strTrim(value);
2452
3610
  if (value.toString().length > maxLength) {
2453
3611
  valueTrunc = value.toString().substring(0, maxLength);
2454
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3612
+ _throwInternal(logger, 2 , 61 , "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2455
3613
  }
2456
3614
  }
2457
3615
  return valueTrunc || value;
2458
3616
  }
2459
3617
  function dataSanitizeUrl(logger, url) {
2460
- return dataSanitizeInput(logger, url, 2048 , _InternalMessageId.UrlTooLong);
3618
+ return dataSanitizeInput(logger, url, 2048 , 66 );
2461
3619
  }
2462
3620
  function dataSanitizeMessage(logger, message) {
2463
3621
  var messageTrunc;
2464
3622
  if (message) {
2465
3623
  if (message.length > 32768 ) {
2466
3624
  messageTrunc = message.substring(0, 32768 );
2467
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3625
+ _throwInternal(logger, 2 , 56 , "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
2468
3626
  }
2469
3627
  }
2470
3628
  return messageTrunc || message;
@@ -2475,7 +3633,7 @@
2475
3633
  var value = "" + exception;
2476
3634
  if (value.length > 32768 ) {
2477
3635
  exceptionTrunc = value.substring(0, 32768 );
2478
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3636
+ _throwInternal(logger, 2 , 52 , "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
2479
3637
  }
2480
3638
  }
2481
3639
  return exceptionTrunc || exception;
@@ -2489,7 +3647,7 @@
2489
3647
  value = getJSON().stringify(value);
2490
3648
  }
2491
3649
  catch (e) {
2492
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3650
+ _throwInternal(logger, 2 , 49 , "custom property is not valid", { exception: e }, true);
2493
3651
  }
2494
3652
  }
2495
3653
  value = dataSanitizeString(logger, value, 8192 );
@@ -2512,7 +3670,7 @@
2512
3670
  return measurements;
2513
3671
  }
2514
3672
  function dataSanitizeId(logger, id) {
2515
- return id ? dataSanitizeInput(logger, id, 128 , _InternalMessageId.IdTooLong).toString() : id;
3673
+ return id ? dataSanitizeInput(logger, id, 128 , 69 ).toString() : id;
2516
3674
  }
2517
3675
  function dataSanitizeInput(logger, input, maxLength, _msgId) {
2518
3676
  var inputTrunc;
@@ -2520,7 +3678,7 @@
2520
3678
  input = strTrim(input);
2521
3679
  if (input.length > maxLength) {
2522
3680
  inputTrunc = input.substring(0, maxLength);
2523
- logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3681
+ _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2524
3682
  }
2525
3683
  }
2526
3684
  return inputTrunc || input;
@@ -2530,21 +3688,22 @@
2530
3688
  return s.substr(s.length - 3);
2531
3689
  }
2532
3690
 
3691
+ var strEmpty = "";
2533
3692
  function msToTimeSpan(totalms) {
2534
3693
  if (isNaN(totalms) || totalms < 0) {
2535
3694
  totalms = 0;
2536
3695
  }
2537
3696
  totalms = Math.round(totalms);
2538
- var ms = "" + totalms % 1000;
2539
- var sec = "" + Math.floor(totalms / 1000) % 60;
2540
- var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
2541
- var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
3697
+ var ms = strEmpty + totalms % 1000;
3698
+ var sec = strEmpty + Math.floor(totalms / 1000) % 60;
3699
+ var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
3700
+ var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
2542
3701
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
2543
3702
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
2544
3703
  sec = sec.length < 2 ? "0" + sec : sec;
2545
3704
  min = min.length < 2 ? "0" + min : min;
2546
3705
  hour = hour.length < 2 ? "0" + hour : hour;
2547
- return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
3706
+ return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
2548
3707
  }
2549
3708
 
2550
3709
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
@@ -2553,17 +3712,15 @@
2553
3712
  var HttpMethod = "http.method";
2554
3713
  var strNotSpecified = "not_specified";
2555
3714
 
2556
- var StorageType;
2557
- (function (StorageType) {
2558
- StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
2559
- StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
2560
- })(StorageType || (StorageType = {}));
2561
- var DistributedTracingModes;
2562
- (function (DistributedTracingModes) {
2563
- DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
2564
- DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
2565
- DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
2566
- })(DistributedTracingModes || (DistributedTracingModes = {}));
3715
+ var StorageType = createEnumStyle({
3716
+ LocalStorage: 0 ,
3717
+ SessionStorage: 1
3718
+ });
3719
+ createEnumStyle({
3720
+ AI: 0 ,
3721
+ AI_AND_W3C: 1 ,
3722
+ W3C: 2
3723
+ });
2567
3724
 
2568
3725
  var _canUseSessionStorage = undefined;
2569
3726
  function _getVerifiedStorageObject(storageType) {
@@ -2590,8 +3747,8 @@
2590
3747
  }
2591
3748
  return null;
2592
3749
  }
2593
- function utlCanUseSessionStorage() {
2594
- if (_canUseSessionStorage === undefined) {
3750
+ function utlCanUseSessionStorage(reset) {
3751
+ if (reset || _canUseSessionStorage === undefined) {
2595
3752
  _canUseSessionStorage = !!_getVerifiedStorageObject(StorageType.SessionStorage);
2596
3753
  }
2597
3754
  return _canUseSessionStorage;
@@ -2604,7 +3761,7 @@
2604
3761
  }
2605
3762
  catch (e) {
2606
3763
  _canUseSessionStorage = false;
2607
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3764
+ _throwInternal(logger, 2 , 2 , "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
2608
3765
  }
2609
3766
  }
2610
3767
  return null;
@@ -2618,7 +3775,7 @@
2618
3775
  }
2619
3776
  catch (e) {
2620
3777
  _canUseSessionStorage = false;
2621
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3778
+ _throwInternal(logger, 2 , 4 , "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
2622
3779
  }
2623
3780
  }
2624
3781
  return false;
@@ -2715,37 +3872,17 @@
2715
3872
  };
2716
3873
  }
2717
3874
 
2718
- var Base = /** @class */ (function () {
2719
- function Base() {
2720
- }
2721
- return Base;
2722
- }());
2723
-
2724
- var Data$1 = /** @class */ (function (_super) {
2725
- __extendsFn(Data, _super);
2726
- function Data() {
2727
- return _super.call(this) || this;
2728
- }
2729
- return Data;
2730
- }(Base));
2731
-
2732
- var Envelope$1 = /** @class */ (function () {
2733
- function Envelope() {
2734
- this.ver = 1;
2735
- this.sampleRate = 100.0;
2736
- this.tags = {};
2737
- }
2738
- return Envelope;
2739
- }());
2740
-
2741
- var Envelope = /** @class */ (function (_super) {
2742
- __extendsFn(Envelope, _super);
3875
+ var Envelope = /** @class */ (function () {
2743
3876
  function Envelope(logger, data, name) {
2744
- var _this = _super.call(this) || this;
2745
- _this.name = dataSanitizeString(logger, name) || strNotSpecified;
2746
- _this.data = data;
2747
- _this.time = toISOString(new Date());
2748
- _this.aiDataContract = {
3877
+ var _this = this;
3878
+ var _self = this;
3879
+ _self.ver = 1;
3880
+ _self.sampleRate = 100.0;
3881
+ _self.tags = {};
3882
+ _self.name = dataSanitizeString(logger, name) || strNotSpecified;
3883
+ _self.data = data;
3884
+ _self.time = toISOString(new Date());
3885
+ _self.aiDataContract = {
2749
3886
  time: 1 ,
2750
3887
  iKey: 1 ,
2751
3888
  name: 1 ,
@@ -2755,62 +3892,27 @@
2755
3892
  tags: 1 ,
2756
3893
  data: 1
2757
3894
  };
2758
- return _this;
2759
3895
  }
2760
3896
  return Envelope;
2761
- }(Envelope$1));
2762
-
2763
- var EventData = /** @class */ (function () {
2764
- function EventData() {
2765
- this.ver = 2;
2766
- this.properties = {};
2767
- this.measurements = {};
2768
- }
2769
- return EventData;
2770
3897
  }());
2771
3898
 
2772
- var Event = /** @class */ (function (_super) {
2773
- __extendsFn(Event, _super);
3899
+ var Event = /** @class */ (function () {
2774
3900
  function Event(logger, name, properties, measurements) {
2775
- var _this = _super.call(this) || this;
2776
- _this.aiDataContract = {
3901
+ this.aiDataContract = {
2777
3902
  ver: 1 ,
2778
3903
  name: 1 ,
2779
3904
  properties: 0 ,
2780
3905
  measurements: 0
2781
3906
  };
2782
- _this.name = dataSanitizeString(logger, name) || strNotSpecified;
2783
- _this.properties = dataSanitizeProperties(logger, properties);
2784
- _this.measurements = dataSanitizeMeasurements(logger, measurements);
2785
- return _this;
3907
+ var _self = this;
3908
+ _self.ver = 2;
3909
+ _self.name = dataSanitizeString(logger, name) || strNotSpecified;
3910
+ _self.properties = dataSanitizeProperties(logger, properties);
3911
+ _self.measurements = dataSanitizeMeasurements(logger, measurements);
2786
3912
  }
2787
3913
  Event.envelopeType = "Microsoft.ApplicationInsights.{0}.Event";
2788
3914
  Event.dataType = "EventData";
2789
3915
  return Event;
2790
- }(EventData));
2791
-
2792
- var StackFrame = /** @class */ (function () {
2793
- function StackFrame() {
2794
- }
2795
- return StackFrame;
2796
- }());
2797
-
2798
- var ExceptionData = /** @class */ (function () {
2799
- function ExceptionData() {
2800
- this.ver = 2;
2801
- this.exceptions = [];
2802
- this.properties = {};
2803
- this.measurements = {};
2804
- }
2805
- return ExceptionData;
2806
- }());
2807
-
2808
- var ExceptionDetails = /** @class */ (function () {
2809
- function ExceptionDetails() {
2810
- this.hasFullStack = true;
2811
- this.parsedStack = [];
2812
- }
2813
- return ExceptionDetails;
2814
3916
  }());
2815
3917
 
2816
3918
  var NoMethod = "<no_method>";
@@ -3054,50 +4156,48 @@
3054
4156
  }
3055
4157
  return "" + (errorObj || "");
3056
4158
  }
3057
- var Exception = /** @class */ (function (_super) {
3058
- __extendsFn(Exception, _super);
4159
+ var Exception = /** @class */ (function () {
3059
4160
  function Exception(logger, exception, properties, measurements, severityLevel, id) {
3060
- var _this = _super.call(this) || this;
3061
- _this.aiDataContract = {
4161
+ this.aiDataContract = {
3062
4162
  ver: 1 ,
3063
4163
  exceptions: 1 ,
3064
4164
  severityLevel: 0 ,
3065
4165
  properties: 0 ,
3066
4166
  measurements: 0
3067
4167
  };
4168
+ var _self = this;
4169
+ _self.ver = 2;
3068
4170
  if (!_isExceptionInternal(exception)) {
3069
4171
  if (!properties) {
3070
4172
  properties = {};
3071
4173
  }
3072
- _this.exceptions = [new _ExceptionDetails(logger, exception, properties)];
3073
- _this.properties = dataSanitizeProperties(logger, properties);
3074
- _this.measurements = dataSanitizeMeasurements(logger, measurements);
4174
+ _self.exceptions = [new _ExceptionDetails(logger, exception, properties)];
4175
+ _self.properties = dataSanitizeProperties(logger, properties);
4176
+ _self.measurements = dataSanitizeMeasurements(logger, measurements);
3075
4177
  if (severityLevel) {
3076
- _this.severityLevel = severityLevel;
4178
+ _self.severityLevel = severityLevel;
3077
4179
  }
3078
4180
  if (id) {
3079
- _this.id = id;
4181
+ _self.id = id;
3080
4182
  }
3081
4183
  }
3082
4184
  else {
3083
- _this.exceptions = exception.exceptions;
3084
- _this.properties = exception.properties;
3085
- _this.measurements = exception.measurements;
4185
+ _self.exceptions = exception.exceptions || [];
4186
+ _self.properties = exception.properties;
4187
+ _self.measurements = exception.measurements;
3086
4188
  if (exception.severityLevel) {
3087
- _this.severityLevel = exception.severityLevel;
4189
+ _self.severityLevel = exception.severityLevel;
3088
4190
  }
3089
4191
  if (exception.id) {
3090
- _this.id = exception.id;
4192
+ _self.id = exception.id;
3091
4193
  }
3092
4194
  if (exception.problemGroup) {
3093
- _this.problemGroup = exception.problemGroup;
4195
+ _self.problemGroup = exception.problemGroup;
3094
4196
  }
3095
- _this.ver = 2;
3096
4197
  if (!isNullOrUndefined(exception.isManual)) {
3097
- _this.isManual = exception.isManual;
4198
+ _self.isManual = exception.isManual;
3098
4199
  }
3099
4200
  }
3100
- return _this;
3101
4201
  }
3102
4202
  Exception.CreateAutoException = function (message, url, lineNumber, columnNumber, error, evt, stack, errorSrc) {
3103
4203
  var errorType = _getErrorType(error || evt || message);
@@ -3151,12 +4251,10 @@
3151
4251
  Exception.dataType = "ExceptionData";
3152
4252
  Exception.formatError = _formatErrorCode;
3153
4253
  return Exception;
3154
- }(ExceptionData));
3155
- var _ExceptionDetails = /** @class */ (function (_super) {
3156
- __extendsFn(_ExceptionDetails, _super);
4254
+ }());
4255
+ var _ExceptionDetails = /** @class */ (function () {
3157
4256
  function _ExceptionDetails(logger, exception, properties) {
3158
- var _this = _super.call(this) || this;
3159
- _this.aiDataContract = {
4257
+ this.aiDataContract = {
3160
4258
  id: 0 ,
3161
4259
  outerId: 0 ,
3162
4260
  typeName: 1 ,
@@ -3165,41 +4263,42 @@
3165
4263
  stack: 0 ,
3166
4264
  parsedStack: 2
3167
4265
  };
4266
+ var _self = this;
3168
4267
  if (!_isExceptionDetailsInternal(exception)) {
3169
4268
  var error = exception;
3170
4269
  var evt = error && error.evt;
3171
4270
  if (!isError(error)) {
3172
4271
  error = error[strError] || evt || error;
3173
4272
  }
3174
- _this.typeName = dataSanitizeString(logger, _getErrorType(error)) || strNotSpecified;
3175
- _this.message = dataSanitizeMessage(logger, _formatMessage(exception || error, _this.typeName)) || strNotSpecified;
4273
+ _self.typeName = dataSanitizeString(logger, _getErrorType(error)) || strNotSpecified;
4274
+ _self.message = dataSanitizeMessage(logger, _formatMessage(exception || error, _self.typeName)) || strNotSpecified;
3176
4275
  var stack = exception[strStackDetails] || _getStackFromErrorObj(exception);
3177
- _this.parsedStack = _parseStack(stack);
3178
- _this[strStack] = dataSanitizeException(logger, _formatStackTrace(stack));
3179
- _this.hasFullStack = isArray(_this.parsedStack) && _this.parsedStack.length > 0;
4276
+ _self.parsedStack = _parseStack(stack);
4277
+ _self[strStack] = dataSanitizeException(logger, _formatStackTrace(stack));
4278
+ _self.hasFullStack = isArray(_self.parsedStack) && _self.parsedStack.length > 0;
3180
4279
  if (properties) {
3181
- properties.typeName = properties.typeName || _this.typeName;
4280
+ properties.typeName = properties.typeName || _self.typeName;
3182
4281
  }
3183
4282
  }
3184
4283
  else {
3185
- _this.typeName = exception.typeName;
3186
- _this.message = exception.message;
3187
- _this[strStack] = exception[strStack];
3188
- _this.parsedStack = exception.parsedStack;
3189
- _this.hasFullStack = exception.hasFullStack;
4284
+ _self.typeName = exception.typeName;
4285
+ _self.message = exception.message;
4286
+ _self[strStack] = exception[strStack];
4287
+ _self.parsedStack = exception.parsedStack || [];
4288
+ _self.hasFullStack = exception.hasFullStack;
3190
4289
  }
3191
- return _this;
3192
4290
  }
3193
4291
  _ExceptionDetails.prototype.toInterface = function () {
3194
- var parsedStack = this.parsedStack instanceof Array
3195
- && arrMap(this.parsedStack, function (frame) { return frame.toInterface(); });
4292
+ var _self = this;
4293
+ var parsedStack = _self.parsedStack instanceof Array
4294
+ && arrMap(_self.parsedStack, function (frame) { return frame.toInterface(); });
3196
4295
  var exceptionDetailsInterface = {
3197
- id: this.id,
3198
- outerId: this.outerId,
3199
- typeName: this.typeName,
3200
- message: this.message,
3201
- hasFullStack: this.hasFullStack,
3202
- stack: this[strStack],
4296
+ id: _self.id,
4297
+ outerId: _self.outerId,
4298
+ typeName: _self.typeName,
4299
+ message: _self.message,
4300
+ hasFullStack: _self.hasFullStack,
4301
+ stack: _self[strStack],
3203
4302
  parsedStack: parsedStack || undefined
3204
4303
  };
3205
4304
  return exceptionDetailsInterface;
@@ -3212,94 +4311,68 @@
3212
4311
  return exceptionDetails;
3213
4312
  };
3214
4313
  return _ExceptionDetails;
3215
- }(ExceptionDetails));
3216
- var _StackFrame = /** @class */ (function (_super) {
3217
- __extendsFn(_StackFrame, _super);
4314
+ }());
4315
+ var _StackFrame = /** @class */ (function () {
3218
4316
  function _StackFrame(sourceFrame, level) {
3219
- var _this = _super.call(this) || this;
3220
- _this.sizeInBytes = 0;
3221
- _this.aiDataContract = {
4317
+ this.aiDataContract = {
3222
4318
  level: 1 ,
3223
4319
  method: 1 ,
3224
4320
  assembly: 0 ,
3225
4321
  fileName: 0 ,
3226
4322
  line: 0
3227
4323
  };
4324
+ var _self = this;
4325
+ _self.sizeInBytes = 0;
3228
4326
  if (typeof sourceFrame === "string") {
3229
4327
  var frame = sourceFrame;
3230
- _this.level = level;
3231
- _this.method = NoMethod;
3232
- _this.assembly = strTrim(frame);
3233
- _this.fileName = "";
3234
- _this.line = 0;
4328
+ _self.level = level;
4329
+ _self.method = NoMethod;
4330
+ _self.assembly = strTrim(frame);
4331
+ _self.fileName = "";
4332
+ _self.line = 0;
3235
4333
  var matches = frame.match(_StackFrame.regex);
3236
4334
  if (matches && matches.length >= 5) {
3237
- _this.method = strTrim(matches[2]) || _this.method;
3238
- _this.fileName = strTrim(matches[4]);
3239
- _this.line = parseInt(matches[5]) || 0;
4335
+ _self.method = strTrim(matches[2]) || _self.method;
4336
+ _self.fileName = strTrim(matches[4]);
4337
+ _self.line = parseInt(matches[5]) || 0;
3240
4338
  }
3241
4339
  }
3242
4340
  else {
3243
- _this.level = sourceFrame.level;
3244
- _this.method = sourceFrame.method;
3245
- _this.assembly = sourceFrame.assembly;
3246
- _this.fileName = sourceFrame.fileName;
3247
- _this.line = sourceFrame.line;
3248
- _this.sizeInBytes = 0;
3249
- }
3250
- _this.sizeInBytes += _this.method.length;
3251
- _this.sizeInBytes += _this.fileName.length;
3252
- _this.sizeInBytes += _this.assembly.length;
3253
- _this.sizeInBytes += _StackFrame.baseSize;
3254
- _this.sizeInBytes += _this.level.toString().length;
3255
- _this.sizeInBytes += _this.line.toString().length;
3256
- return _this;
4341
+ _self.level = sourceFrame.level;
4342
+ _self.method = sourceFrame.method;
4343
+ _self.assembly = sourceFrame.assembly;
4344
+ _self.fileName = sourceFrame.fileName;
4345
+ _self.line = sourceFrame.line;
4346
+ _self.sizeInBytes = 0;
4347
+ }
4348
+ _self.sizeInBytes += _self.method.length;
4349
+ _self.sizeInBytes += _self.fileName.length;
4350
+ _self.sizeInBytes += _self.assembly.length;
4351
+ _self.sizeInBytes += _StackFrame.baseSize;
4352
+ _self.sizeInBytes += _self.level.toString().length;
4353
+ _self.sizeInBytes += _self.line.toString().length;
3257
4354
  }
3258
4355
  _StackFrame.CreateFromInterface = function (frame) {
3259
4356
  return new _StackFrame(frame, null );
3260
4357
  };
3261
4358
  _StackFrame.prototype.toInterface = function () {
4359
+ var _self = this;
3262
4360
  return {
3263
- level: this.level,
3264
- method: this.method,
3265
- assembly: this.assembly,
3266
- fileName: this.fileName,
3267
- line: this.line
4361
+ level: _self.level,
4362
+ method: _self.method,
4363
+ assembly: _self.assembly,
4364
+ fileName: _self.fileName,
4365
+ line: _self.line
3268
4366
  };
3269
4367
  };
3270
4368
  _StackFrame.regex = /^([\s]+at)?[\s]{0,50}([^\@\()]+?)[\s]{0,50}(\@|\()([^\(\n]+):([0-9]+):([0-9]+)(\)?)$/;
3271
4369
  _StackFrame.baseSize = 58;
3272
4370
  return _StackFrame;
3273
- }(StackFrame));
3274
-
3275
- var MetricData = /** @class */ (function () {
3276
- function MetricData() {
3277
- this.ver = 2;
3278
- this.metrics = [];
3279
- this.properties = {};
3280
- this.measurements = {};
3281
- }
3282
- return MetricData;
3283
- }());
3284
-
3285
- var DataPointType;
3286
- (function (DataPointType) {
3287
- DataPointType[DataPointType["Measurement"] = 0] = "Measurement";
3288
- DataPointType[DataPointType["Aggregation"] = 1] = "Aggregation";
3289
- })(DataPointType || (DataPointType = {}));
3290
-
3291
- var DataPoint$1 = /** @class */ (function () {
3292
- function DataPoint() {
3293
- this.kind = DataPointType.Measurement;
3294
- }
3295
- return DataPoint;
3296
4371
  }());
3297
4372
 
3298
- var DataPoint = /** @class */ (function (_super) {
3299
- __extendsFn(DataPoint, _super);
4373
+ var DataPoint = /** @class */ (function () {
3300
4374
  function DataPoint() {
3301
- var _this = _super !== null && _super.apply(this, arguments) || this;
3302
- _this.aiDataContract = {
4375
+ this.aiDataContract = {
3303
4376
  name: 1 ,
3304
4377
  kind: 0 ,
3305
4378
  value: 1 ,
@@ -3308,20 +4381,20 @@
3308
4381
  max: 0 ,
3309
4382
  stdDev: 0
3310
4383
  };
3311
- return _this;
4384
+ this.kind = 0 ;
3312
4385
  }
3313
4386
  return DataPoint;
3314
- }(DataPoint$1));
4387
+ }());
3315
4388
 
3316
- var Metric = /** @class */ (function (_super) {
3317
- __extendsFn(Metric, _super);
4389
+ var Metric = /** @class */ (function () {
3318
4390
  function Metric(logger, name, value, count, min, max, stdDev, properties, measurements) {
3319
- var _this = _super.call(this) || this;
3320
- _this.aiDataContract = {
4391
+ this.aiDataContract = {
3321
4392
  ver: 1 ,
3322
4393
  metrics: 1 ,
3323
4394
  properties: 0
3324
4395
  };
4396
+ var _self = this;
4397
+ _self.ver = 2;
3325
4398
  var dataPoint = new DataPoint();
3326
4399
  dataPoint.count = count > 0 ? count : undefined;
3327
4400
  dataPoint.max = isNaN(max) || max === null ? undefined : max;
@@ -3329,33 +4402,18 @@
3329
4402
  dataPoint.name = dataSanitizeString(logger, name) || strNotSpecified;
3330
4403
  dataPoint.value = value;
3331
4404
  dataPoint.stdDev = isNaN(stdDev) || stdDev === null ? undefined : stdDev;
3332
- _this.metrics = [dataPoint];
3333
- _this.properties = dataSanitizeProperties(logger, properties);
3334
- _this.measurements = dataSanitizeMeasurements(logger, measurements);
3335
- return _this;
4405
+ _self.metrics = [dataPoint];
4406
+ _self.properties = dataSanitizeProperties(logger, properties);
4407
+ _self.measurements = dataSanitizeMeasurements(logger, measurements);
3336
4408
  }
3337
4409
  Metric.envelopeType = "Microsoft.ApplicationInsights.{0}.Metric";
3338
4410
  Metric.dataType = "MetricData";
3339
4411
  return Metric;
3340
- }(MetricData));
3341
-
3342
- var PageViewData = /** @class */ (function (_super) {
3343
- __extendsFn(PageViewData, _super);
3344
- function PageViewData() {
3345
- var _this = _super.call(this) || this;
3346
- _this.ver = 2;
3347
- _this.properties = {};
3348
- _this.measurements = {};
3349
- return _this;
3350
- }
3351
- return PageViewData;
3352
- }(EventData));
4412
+ }());
3353
4413
 
3354
- var PageView = /** @class */ (function (_super) {
3355
- __extendsFn(PageView, _super);
4414
+ var PageView = /** @class */ (function () {
3356
4415
  function PageView(logger, name, url, durationMs, properties, measurements, id) {
3357
- var _this = _super.call(this) || this;
3358
- _this.aiDataContract = {
4416
+ this.aiDataContract = {
3359
4417
  ver: 1 ,
3360
4418
  name: 0 ,
3361
4419
  url: 0 ,
@@ -3364,37 +4422,26 @@
3364
4422
  measurements: 0 ,
3365
4423
  id: 0
3366
4424
  };
3367
- _this.id = dataSanitizeId(logger, id);
3368
- _this.url = dataSanitizeUrl(logger, url);
3369
- _this.name = dataSanitizeString(logger, name) || strNotSpecified;
4425
+ var _self = this;
4426
+ _self.ver = 2;
4427
+ _self.id = dataSanitizeId(logger, id);
4428
+ _self.url = dataSanitizeUrl(logger, url);
4429
+ _self.name = dataSanitizeString(logger, name) || strNotSpecified;
3370
4430
  if (!isNaN(durationMs)) {
3371
- _this.duration = msToTimeSpan(durationMs);
4431
+ _self.duration = msToTimeSpan(durationMs);
3372
4432
  }
3373
- _this.properties = dataSanitizeProperties(logger, properties);
3374
- _this.measurements = dataSanitizeMeasurements(logger, measurements);
3375
- return _this;
4433
+ _self.properties = dataSanitizeProperties(logger, properties);
4434
+ _self.measurements = dataSanitizeMeasurements(logger, measurements);
3376
4435
  }
3377
4436
  PageView.envelopeType = "Microsoft.ApplicationInsights.{0}.Pageview";
3378
4437
  PageView.dataType = "PageviewData";
3379
4438
  return PageView;
3380
- }(PageViewData));
3381
-
3382
- var RemoteDependencyData$1 = /** @class */ (function () {
3383
- function RemoteDependencyData() {
3384
- this.ver = 2;
3385
- this.success = true;
3386
- this.properties = {};
3387
- this.measurements = {};
3388
- }
3389
- return RemoteDependencyData;
3390
4439
  }());
3391
4440
 
3392
- var RemoteDependencyData = /** @class */ (function (_super) {
3393
- __extendsFn(RemoteDependencyData, _super);
4441
+ var RemoteDependencyData = /** @class */ (function () {
3394
4442
  function RemoteDependencyData(logger, id, absoluteUrl, commandName, value, success, resultCode, method, requestAPI, correlationContext, properties, measurements) {
3395
4443
  if (requestAPI === void 0) { requestAPI = "Ajax"; }
3396
- var _this = _super.call(this) || this;
3397
- _this.aiDataContract = {
4444
+ this.aiDataContract = {
3398
4445
  id: 1 ,
3399
4446
  ver: 1 ,
3400
4447
  name: 0 ,
@@ -3417,77 +4464,54 @@
3417
4464
  commandName: 0 ,
3418
4465
  dependencyTypeName: 0
3419
4466
  };
3420
- _this.id = id;
3421
- _this.duration = msToTimeSpan(value);
3422
- _this.success = success;
3423
- _this.resultCode = resultCode + "";
3424
- _this.type = dataSanitizeString(logger, requestAPI);
4467
+ var _self = this;
4468
+ _self.ver = 2;
4469
+ _self.id = id;
4470
+ _self.duration = msToTimeSpan(value);
4471
+ _self.success = success;
4472
+ _self.resultCode = resultCode + "";
4473
+ _self.type = dataSanitizeString(logger, requestAPI);
3425
4474
  var dependencyFields = AjaxHelperParseDependencyPath(logger, absoluteUrl, method, commandName);
3426
- _this.data = dataSanitizeUrl(logger, commandName) || dependencyFields.data;
3427
- _this.target = dataSanitizeString(logger, dependencyFields.target);
4475
+ _self.data = dataSanitizeUrl(logger, commandName) || dependencyFields.data;
4476
+ _self.target = dataSanitizeString(logger, dependencyFields.target);
3428
4477
  if (correlationContext) {
3429
- _this.target = "".concat(_this.target, " | ").concat(correlationContext);
4478
+ _self.target = "".concat(_self.target, " | ").concat(correlationContext);
3430
4479
  }
3431
- _this.name = dataSanitizeString(logger, dependencyFields.name);
3432
- _this.properties = dataSanitizeProperties(logger, properties);
3433
- _this.measurements = dataSanitizeMeasurements(logger, measurements);
3434
- return _this;
4480
+ _self.name = dataSanitizeString(logger, dependencyFields.name);
4481
+ _self.properties = dataSanitizeProperties(logger, properties);
4482
+ _self.measurements = dataSanitizeMeasurements(logger, measurements);
3435
4483
  }
3436
4484
  RemoteDependencyData.envelopeType = "Microsoft.ApplicationInsights.{0}.RemoteDependency";
3437
4485
  RemoteDependencyData.dataType = "RemoteDependencyData";
3438
4486
  return RemoteDependencyData;
3439
- }(RemoteDependencyData$1));
3440
-
3441
- var MessageData = /** @class */ (function () {
3442
- function MessageData() {
3443
- this.ver = 2;
3444
- this.properties = {};
3445
- this.measurements = {};
3446
- }
3447
- return MessageData;
3448
4487
  }());
3449
4488
 
3450
- var Trace = /** @class */ (function (_super) {
3451
- __extendsFn(Trace, _super);
4489
+ var Trace = /** @class */ (function () {
3452
4490
  function Trace(logger, message, severityLevel, properties, measurements) {
3453
- var _this = _super.call(this) || this;
3454
- _this.aiDataContract = {
4491
+ this.aiDataContract = {
3455
4492
  ver: 1 ,
3456
4493
  message: 1 ,
3457
4494
  severityLevel: 0 ,
3458
4495
  properties: 0
3459
4496
  };
4497
+ var _self = this;
4498
+ _self.ver = 2;
3460
4499
  message = message || strNotSpecified;
3461
- _this.message = dataSanitizeMessage(logger, message);
3462
- _this.properties = dataSanitizeProperties(logger, properties);
3463
- _this.measurements = dataSanitizeMeasurements(logger, measurements);
4500
+ _self.message = dataSanitizeMessage(logger, message);
4501
+ _self.properties = dataSanitizeProperties(logger, properties);
4502
+ _self.measurements = dataSanitizeMeasurements(logger, measurements);
3464
4503
  if (severityLevel) {
3465
- _this.severityLevel = severityLevel;
4504
+ _self.severityLevel = severityLevel;
3466
4505
  }
3467
- return _this;
3468
4506
  }
3469
4507
  Trace.envelopeType = "Microsoft.ApplicationInsights.{0}.Message";
3470
4508
  Trace.dataType = "MessageData";
3471
4509
  return Trace;
3472
- }(MessageData));
3473
-
3474
- var PageViewPerfData = /** @class */ (function (_super) {
3475
- __extendsFn(PageViewPerfData, _super);
3476
- function PageViewPerfData() {
3477
- var _this = _super.call(this) || this;
3478
- _this.ver = 2;
3479
- _this.properties = {};
3480
- _this.measurements = {};
3481
- return _this;
3482
- }
3483
- return PageViewPerfData;
3484
- }(PageViewData));
4510
+ }());
3485
4511
 
3486
- var PageViewPerformance = /** @class */ (function (_super) {
3487
- __extendsFn(PageViewPerformance, _super);
4512
+ var PageViewPerformance = /** @class */ (function () {
3488
4513
  function PageViewPerformance(logger, name, url, unused, properties, measurements, cs4BaseData) {
3489
- var _this = _super.call(this) || this;
3490
- _this.aiDataContract = {
4514
+ this.aiDataContract = {
3491
4515
  ver: 1 ,
3492
4516
  name: 0 ,
3493
4517
  url: 0 ,
@@ -3500,39 +4524,37 @@
3500
4524
  properties: 0 ,
3501
4525
  measurements: 0
3502
4526
  };
3503
- _this.url = dataSanitizeUrl(logger, url);
3504
- _this.name = dataSanitizeString(logger, name) || strNotSpecified;
3505
- _this.properties = dataSanitizeProperties(logger, properties);
3506
- _this.measurements = dataSanitizeMeasurements(logger, measurements);
4527
+ var _self = this;
4528
+ _self.ver = 2;
4529
+ _self.url = dataSanitizeUrl(logger, url);
4530
+ _self.name = dataSanitizeString(logger, name) || strNotSpecified;
4531
+ _self.properties = dataSanitizeProperties(logger, properties);
4532
+ _self.measurements = dataSanitizeMeasurements(logger, measurements);
3507
4533
  if (cs4BaseData) {
3508
- _this.domProcessing = cs4BaseData.domProcessing;
3509
- _this.duration = cs4BaseData.duration;
3510
- _this.networkConnect = cs4BaseData.networkConnect;
3511
- _this.perfTotal = cs4BaseData.perfTotal;
3512
- _this.receivedResponse = cs4BaseData.receivedResponse;
3513
- _this.sentRequest = cs4BaseData.sentRequest;
4534
+ _self.domProcessing = cs4BaseData.domProcessing;
4535
+ _self.duration = cs4BaseData.duration;
4536
+ _self.networkConnect = cs4BaseData.networkConnect;
4537
+ _self.perfTotal = cs4BaseData.perfTotal;
4538
+ _self.receivedResponse = cs4BaseData.receivedResponse;
4539
+ _self.sentRequest = cs4BaseData.sentRequest;
3514
4540
  }
3515
- return _this;
3516
4541
  }
3517
4542
  PageViewPerformance.envelopeType = "Microsoft.ApplicationInsights.{0}.PageviewPerformance";
3518
4543
  PageViewPerformance.dataType = "PageviewPerformanceData";
3519
4544
  return PageViewPerformance;
3520
- }(PageViewPerfData));
4545
+ }());
3521
4546
 
3522
- var Data = /** @class */ (function (_super) {
3523
- __extendsFn(Data, _super);
4547
+ var Data = /** @class */ (function () {
3524
4548
  function Data(baseType, data) {
3525
- var _this = _super.call(this) || this;
3526
- _this.aiDataContract = {
4549
+ this.aiDataContract = {
3527
4550
  baseType: 1 ,
3528
4551
  baseData: 1
3529
4552
  };
3530
- _this.baseType = baseType;
3531
- _this.baseData = data;
3532
- return _this;
4553
+ this.baseType = baseType;
4554
+ this.baseData = data;
3533
4555
  }
3534
4556
  return Data;
3535
- }(Data$1));
4557
+ }());
3536
4558
 
3537
4559
  exports.SeverityLevel = void 0;
3538
4560
  (function (SeverityLevel) {
@@ -3642,7 +4664,7 @@
3642
4664
  _self.enqueue = function (payload) {
3643
4665
  if (_self.count() >= config.eventsLimitInMem()) {
3644
4666
  if (!_bufferFullMessageSent) {
3645
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.InMemoryStorageBufferFull, "Maximum in-memory buffer size reached: " + _self.count(), true);
4667
+ _throwInternal(logger, 2 , 105 , "Maximum in-memory buffer size reached: " + _self.count(), true);
3646
4668
  _bufferFullMessageSent = true;
3647
4669
  }
3648
4670
  return;
@@ -3714,7 +4736,7 @@
3714
4736
  _self.enqueue = function (payload) {
3715
4737
  if (_self.count() >= SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
3716
4738
  if (!_bufferFullMessageSent) {
3717
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.SessionStorageBufferFull, "Maximum buffer size reached: " + _self.count(), true);
4739
+ _throwInternal(logger, 2 , 67 , "Maximum buffer size reached: " + _self.count(), true);
3718
4740
  _bufferFullMessageSent = true;
3719
4741
  }
3720
4742
  return;
@@ -3734,7 +4756,7 @@
3734
4756
  if (sentElements instanceof Array && payload instanceof Array) {
3735
4757
  sentElements = sentElements.concat(payload);
3736
4758
  if (sentElements.length > SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
3737
- logger.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.SessionStorageBufferFull, "Sent buffer reached its maximum size: " + sentElements.length, true);
4759
+ _throwInternal(logger, 1 , 67 , "Sent buffer reached its maximum size: " + sentElements.length, true);
3738
4760
  sentElements.length = SessionStorageSendBuffer.MAX_BUFFER_SIZE;
3739
4761
  }
3740
4762
  _setBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY, sentElements);
@@ -3770,7 +4792,7 @@
3770
4792
  }
3771
4793
  }
3772
4794
  catch (e) {
3773
- logger.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FailedToRestoreStorageBuffer, " storage key: " + prefixedKey + ", " + getExceptionName(e), { exception: dumpObj(e) });
4795
+ _throwInternal(logger, 1 , 42 , " storage key: " + prefixedKey + ", " + getExceptionName(e), { exception: dumpObj(e) });
3774
4796
  }
3775
4797
  return [];
3776
4798
  }
@@ -3783,7 +4805,7 @@
3783
4805
  }
3784
4806
  catch (e) {
3785
4807
  utlSetSessionStorage(logger, prefixedKey, JSON.stringify([]));
3786
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.FailedToSetStorageBuffer, " storage key: " + prefixedKey + ", " + getExceptionName(e) + ". Buffer cleared", { exception: dumpObj(e) });
4808
+ _throwInternal(logger, 2 , 41 , " storage key: " + prefixedKey + ", " + getExceptionName(e) + ". Buffer cleared", { exception: dumpObj(e) });
3787
4809
  }
3788
4810
  }
3789
4811
  });
@@ -3900,11 +4922,11 @@
3900
4922
  }
3901
4923
  function EnvelopeCreatorInit(logger, telemetryItem) {
3902
4924
  if (isNullOrUndefined(telemetryItem[strBaseData])) {
3903
- logger.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryEnvelopeInvalid, "telemetryItem.baseData cannot be null.");
4925
+ _throwInternal(logger, 1 , 46 , "telemetryItem.baseData cannot be null.");
3904
4926
  }
3905
4927
  }
3906
4928
  var EnvelopeCreator = {
3907
- Version: "2.8.0-nightly.2202-06"
4929
+ Version: "2.8.0-nightly.2204-06"
3908
4930
  };
3909
4931
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
3910
4932
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -3916,7 +4938,7 @@
3916
4938
  }
3917
4939
  var bd = telemetryItem[strBaseData];
3918
4940
  if (isNullOrUndefined(bd)) {
3919
- logger.warnToConsole("Invalid input for dependency data");
4941
+ _warnToConsole(logger, "Invalid input for dependency data");
3920
4942
  return null;
3921
4943
  }
3922
4944
  var method = bd[strProperties] && bd[strProperties][HttpMethod] ? bd[strProperties][HttpMethod] : "GET";
@@ -4063,18 +5085,18 @@
4063
5085
  return getJSON().stringify(output);
4064
5086
  }
4065
5087
  catch (e) {
4066
- logger.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSerializeObject, (e && isFunction(e.toString)) ? e.toString() : "Error serializing object", null, true);
5088
+ _throwInternal(logger, 1 , 48 , (e && isFunction(e.toString)) ? e.toString() : "Error serializing object", null, true);
4067
5089
  }
4068
5090
  };
4069
5091
  function _serializeObject(source, name) {
4070
5092
  var circularReferenceCheck = "__aiCircularRefCheck";
4071
5093
  var output = {};
4072
5094
  if (!source) {
4073
- logger.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSerializeObject, "cannot serialize object because it is null or undefined", { name: name }, true);
5095
+ _throwInternal(logger, 1 , 48 , "cannot serialize object because it is null or undefined", { name: name }, true);
4074
5096
  return output;
4075
5097
  }
4076
5098
  if (source[circularReferenceCheck]) {
4077
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CircularReferenceDetected, "Circular reference detected while serializing object", { name: name }, true);
5099
+ _throwInternal(logger, 2 , 50 , "Circular reference detected while serializing object", { name: name }, true);
4078
5100
  return output;
4079
5101
  }
4080
5102
  if (!source.aiDataContract) {
@@ -4091,13 +5113,13 @@
4091
5113
  output = _serializeArray(source, name);
4092
5114
  }
4093
5115
  else {
4094
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "Attempting to serialize an object which does not implement ISerializable", { name: name }, true);
5116
+ _throwInternal(logger, 2 , 49 , "Attempting to serialize an object which does not implement ISerializable", { name: name }, true);
4095
5117
  try {
4096
5118
  getJSON().stringify(source);
4097
5119
  output = source;
4098
5120
  }
4099
5121
  catch (e) {
4100
- logger.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSerializeObject, (e && isFunction(e.toString)) ? e.toString() : "Error serializing object", null, true);
5122
+ _throwInternal(logger, 1 , 48 , (e && isFunction(e.toString)) ? e.toString() : "Error serializing object", null, true);
4101
5123
  }
4102
5124
  }
4103
5125
  return output;
@@ -4110,7 +5132,7 @@
4110
5132
  var isPresent = source[field] !== undefined;
4111
5133
  var isObj = isObject(source[field]) && source[field] !== null;
4112
5134
  if (isRequired && !isPresent && !isArray) {
4113
- logger.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.MissingRequiredFieldSpecification, "Missing required field specification. The field is required but not present on source", { field: field, name: name });
5135
+ _throwInternal(logger, 1 , 24 , "Missing required field specification. The field is required but not present on source", { field: field, name: name });
4114
5136
  }
4115
5137
  else if (!isHidden) {
4116
5138
  var value = void 0;
@@ -4137,7 +5159,7 @@
4137
5159
  var output;
4138
5160
  if (!!sources) {
4139
5161
  if (!isArray(sources)) {
4140
- logger.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ItemNotInArray, "This field was specified as an array in the contract but the item is not an array.\r\n", { name: name }, true);
5162
+ _throwInternal(logger, 1 , 54 , "This field was specified as an array in the contract but the item is not an array.\r\n", { name: name }, true);
4141
5163
  }
4142
5164
  else {
4143
5165
  output = [];
@@ -4188,7 +5210,7 @@
4188
5210
  }
4189
5211
  else {
4190
5212
  output[field] = "invalid field: " + name + " is of unknown type.";
4191
- logger.throwInternal(LoggingSeverity.CRITICAL, output[field], null, true);
5213
+ _throwInternal(logger, 1 , output[field], null, true);
4192
5214
  }
4193
5215
  });
4194
5216
  }
@@ -4199,65 +5221,81 @@
4199
5221
  return Serializer;
4200
5222
  }());
4201
5223
 
4202
- var OfflineListener = /** @class */ (function () {
4203
- function OfflineListener() {
4204
- var _window = getWindow();
4205
- var _document = getDocument();
4206
- var isListening = false;
4207
- var _onlineStatus = true;
4208
- dynamicProto(OfflineListener, this, function (_self) {
4209
- try {
4210
- if (_window) {
4211
- if (attachEvent(_window, "online", _setOnline)) {
4212
- attachEvent(_window, "offline", _setOffline);
4213
- isListening = true;
4214
- }
4215
- }
4216
- if (_document) {
4217
- var target = _document.body || _document;
4218
- if (!isUndefined(target.ononline)) {
4219
- target.ononline = _setOnline;
4220
- target.onoffline = _setOffline;
4221
- isListening = true;
4222
- }
4223
- }
4224
- if (isListening) {
4225
- var _navigator = getNavigator();
4226
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
4227
- _onlineStatus = _navigator.onLine;
4228
- }
5224
+ function _disableEvents(target, evtNamespace) {
5225
+ eventOff(target, null, null, evtNamespace);
5226
+ }
5227
+ function createOfflineListener(parentEvtNamespace) {
5228
+ var _document = getDocument();
5229
+ var _navigator = getNavigator();
5230
+ var _isListening = false;
5231
+ var _onlineStatus = true;
5232
+ var _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
5233
+ try {
5234
+ if (_enableEvents(getWindow())) {
5235
+ _isListening = true;
5236
+ }
5237
+ if (_document) {
5238
+ var target = _document.body || _document;
5239
+ if (target.ononline) {
5240
+ if (_enableEvents(target)) {
5241
+ _isListening = true;
4229
5242
  }
4230
5243
  }
4231
- catch (e) {
4232
- isListening = false;
5244
+ }
5245
+ if (_isListening) {
5246
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
5247
+ _onlineStatus = _navigator.onLine;
4233
5248
  }
4234
- _self.isListening = isListening;
4235
- _self.isOnline = function () {
4236
- var result = true;
4237
- var _navigator = getNavigator();
4238
- if (isListening) {
4239
- result = _onlineStatus;
4240
- }
4241
- else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
4242
- result = _navigator.onLine;
4243
- }
4244
- return result;
4245
- };
4246
- _self.isOffline = function () {
4247
- return !_self.isOnline();
4248
- };
4249
- function _setOnline() {
4250
- _onlineStatus = true;
5249
+ }
5250
+ }
5251
+ catch (e) {
5252
+ _isListening = false;
5253
+ }
5254
+ function _enableEvents(target) {
5255
+ var enabled = false;
5256
+ if (target) {
5257
+ enabled = eventOn(target, "online", _setOnline, _evtNamespace);
5258
+ if (enabled) {
5259
+ eventOn(target, "offline", _setOffline, _evtNamespace);
4251
5260
  }
4252
- function _setOffline() {
4253
- _onlineStatus = false;
5261
+ }
5262
+ return enabled;
5263
+ }
5264
+ function _setOnline() {
5265
+ _onlineStatus = true;
5266
+ }
5267
+ function _setOffline() {
5268
+ _onlineStatus = false;
5269
+ }
5270
+ function _isOnline() {
5271
+ var result = true;
5272
+ if (_isListening) {
5273
+ result = _onlineStatus;
5274
+ }
5275
+ else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
5276
+ result = _navigator.onLine;
5277
+ }
5278
+ return result;
5279
+ }
5280
+ function _unload() {
5281
+ var win = getWindow();
5282
+ if (win && _isListening) {
5283
+ _disableEvents(win, _evtNamespace);
5284
+ if (_document) {
5285
+ var target = _document.body || _document;
5286
+ if (!isUndefined(target.ononline)) {
5287
+ _disableEvents(target, _evtNamespace);
5288
+ }
4254
5289
  }
4255
- });
5290
+ _isListening = false;
5291
+ }
4256
5292
  }
4257
- OfflineListener.Offline = new OfflineListener;
4258
- return OfflineListener;
4259
- }());
4260
- var Offline = OfflineListener.Offline;
5293
+ return {
5294
+ isOnline: _isOnline,
5295
+ isListening: function () { return _isListening; },
5296
+ unload: _unload
5297
+ };
5298
+ }
4261
5299
 
4262
5300
  var MIN_INPUT_LENGTH = 8;
4263
5301
  var HashCodeScoreGenerator = /** @class */ (function () {
@@ -4385,22 +5423,22 @@
4385
5423
  var _this = _super.call(this) || this;
4386
5424
  _this.priority = 1001;
4387
5425
  _this.identifier = BreezeChannelIdentifier;
5426
+ _this._senderConfig = _getDefaultAppInsightsChannelConfig();
4388
5427
  var _consecutiveErrors;
4389
5428
  var _retryAt;
4390
5429
  var _lastSend;
4391
- var _paused = false;
5430
+ var _paused;
4392
5431
  var _timeoutHandle;
4393
5432
  var _serializer;
4394
5433
  var _stamp_specific_redirects;
4395
- var _headers = {};
5434
+ var _headers;
4396
5435
  var _syncFetchPayload = 0;
4397
5436
  var _fallbackSender;
4398
5437
  var _syncUnloadSender;
4399
- _this._senderConfig = _getDefaultAppInsightsChannelConfig();
5438
+ var _offlineListener;
5439
+ var _evtNamespace;
4400
5440
  dynamicProto(Sender, _this, function (_self, _base) {
4401
- function _notImplemented() {
4402
- throwError("Method not implemented.");
4403
- }
5441
+ _initDefaults();
4404
5442
  _self.pause = function () {
4405
5443
  _clearScheduledTimer();
4406
5444
  _paused = true;
@@ -4415,14 +5453,15 @@
4415
5453
  _setupTimer();
4416
5454
  }
4417
5455
  };
4418
- _self.flush = function () {
5456
+ _self.flush = function (isAsync, callBack, sendReason) {
5457
+ if (isAsync === void 0) { isAsync = true; }
4419
5458
  if (!_paused) {
4420
5459
  _clearScheduledTimer();
4421
5460
  try {
4422
- _self.triggerSend(true, null, 1 );
5461
+ _self.triggerSend(isAsync, null, sendReason || 1 );
4423
5462
  }
4424
5463
  catch (e) {
4425
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5464
+ _throwInternal(_self.diagLog(), 1 , 22 , "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4426
5465
  }
4427
5466
  }
4428
5467
  };
@@ -4433,7 +5472,7 @@
4433
5472
  _self.triggerSend(true, _doUnloadSend, 2 );
4434
5473
  }
4435
5474
  catch (e) {
4436
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FailedToSendQueuedTelemetry, "failed to flush with beacon sender on page unload, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5475
+ _throwInternal(_self.diagLog(), 1 , 20 , "failed to flush with beacon sender on page unload, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4437
5476
  }
4438
5477
  }
4439
5478
  else {
@@ -4441,11 +5480,13 @@
4441
5480
  }
4442
5481
  }
4443
5482
  };
4444
- _self.teardown = _notImplemented;
4445
5483
  _self.addHeader = function (name, value) {
4446
5484
  _headers[name] = value;
4447
5485
  };
4448
5486
  _self.initialize = function (config, core, extensions, pluginChain) {
5487
+ if (_self.isInitialized()) {
5488
+ _throwInternal(_self.diagLog(), 1 , 28 , "Sender is already initialized");
5489
+ }
4449
5490
  _base.initialize(config, core, extensions, pluginChain);
4450
5491
  var ctx = _self._getTelCtx();
4451
5492
  var identifier = _self.identifier;
@@ -4456,6 +5497,8 @@
4456
5497
  _self._sender = null;
4457
5498
  _stamp_specific_redirects = 0;
4458
5499
  var diagLog = _self.diagLog();
5500
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
5501
+ _offlineListener = createOfflineListener(_evtNamespace);
4459
5502
  var defaultConfig = _getDefaultAppInsightsChannelConfig();
4460
5503
  objForEachKey(defaultConfig, function (field, value) {
4461
5504
  _self._senderConfig[field] = function () { return ctx.getConfig(identifier, field, value()); };
@@ -4464,7 +5507,7 @@
4464
5507
  ? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
4465
5508
  _self._sample = new Sample(_self._senderConfig.samplingPercentage(), diagLog);
4466
5509
  if (!_validateInstrumentationKey(config)) {
4467
- diagLog.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
5510
+ _throwInternal(diagLog, 1 , 100 , "Invalid Instrumentation key " + config.instrumentationKey);
4468
5511
  }
4469
5512
  if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders().length > 0) {
4470
5513
  arrForEach(_self._senderConfig.customHeaders(), function (customHeader) {
@@ -4510,22 +5553,22 @@
4510
5553
  return;
4511
5554
  }
4512
5555
  if (!telemetryItem) {
4513
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
5556
+ _throwInternal(itemCtx.diagLog(), 1 , 7 , "Cannot send empty telemetry");
4514
5557
  return;
4515
5558
  }
4516
5559
  if (telemetryItem.baseData && !telemetryItem.baseType) {
4517
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
5560
+ _throwInternal(itemCtx.diagLog(), 1 , 70 , "Cannot send telemetry without baseData and baseType");
4518
5561
  return;
4519
5562
  }
4520
5563
  if (!telemetryItem.baseType) {
4521
5564
  telemetryItem.baseType = "EventData";
4522
5565
  }
4523
5566
  if (!_self._sender) {
4524
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
5567
+ _throwInternal(itemCtx.diagLog(), 1 , 28 , "Sender was not initialized");
4525
5568
  return;
4526
5569
  }
4527
5570
  if (!_isSampledIn(telemetryItem)) {
4528
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
5571
+ _throwInternal(itemCtx.diagLog(), 2 , 33 , "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
4529
5572
  return;
4530
5573
  }
4531
5574
  else {
@@ -4535,7 +5578,7 @@
4535
5578
  var defaultEnvelopeIkey = telemetryItem.iKey || _self._senderConfig.instrumentationKey();
4536
5579
  var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, itemCtx.diagLog(), convertUndefined);
4537
5580
  if (!aiEnvelope_1) {
4538
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
5581
+ _throwInternal(itemCtx.diagLog(), 1 , 47 , "Unable to create an AppInsights envelope");
4539
5582
  return;
4540
5583
  }
4541
5584
  var doNotSendItem_1 = false;
@@ -4544,11 +5587,11 @@
4544
5587
  try {
4545
5588
  if (callBack && callBack(aiEnvelope_1) === false) {
4546
5589
  doNotSendItem_1 = true;
4547
- itemCtx.diagLog().warnToConsole("Telemetry processor check returns false");
5590
+ _warnToConsole(itemCtx.diagLog(), "Telemetry processor check returns false");
4548
5591
  }
4549
5592
  }
4550
5593
  catch (e) {
4551
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
5594
+ _throwInternal(itemCtx.diagLog(), 1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
4552
5595
  }
4553
5596
  });
4554
5597
  delete telemetryItem.tags[ProcessLegacy];
@@ -4566,7 +5609,7 @@
4566
5609
  _setupTimer();
4567
5610
  }
4568
5611
  catch (e) {
4569
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.FailedAddingTelemetryToBuffer, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
5612
+ _throwInternal(itemCtx.diagLog(), 2 , 12 , "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
4570
5613
  }
4571
5614
  _self.processNext(telemetryItem, itemCtx);
4572
5615
  };
@@ -4601,13 +5644,18 @@
4601
5644
  catch (e) {
4602
5645
  var ieVer = getIEVersion();
4603
5646
  if (!ieVer || ieVer > 9) {
4604
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
5647
+ _throwInternal(_self.diagLog(), 1 , 40 , "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
4605
5648
  }
4606
5649
  }
4607
5650
  }
4608
5651
  };
5652
+ _self._doTeardown = function (unloadCtx, unloadState) {
5653
+ _self.onunloadFlush();
5654
+ _offlineListener.unload();
5655
+ _initDefaults();
5656
+ };
4609
5657
  _self._onError = function (payload, message, event) {
4610
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
5658
+ _throwInternal(_self.diagLog(), 2 , 26 , "Failed to send telemetry.", { message: message });
4611
5659
  _self._buffer.clearSent(payload);
4612
5660
  };
4613
5661
  _self._onPartialSuccess = function (payload, results) {
@@ -4632,7 +5680,7 @@
4632
5680
  }
4633
5681
  if (retry.length > 0) {
4634
5682
  _resendPayload(retry);
4635
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
5683
+ _throwInternal(_self.diagLog(), 2 , 40 , "Partial success. " +
4636
5684
  "Delivered: " + payload.length + ", Failed: " + failed.length +
4637
5685
  ". Will retry to send " + retry.length + " our of " + results.itemsReceived + " items");
4638
5686
  }
@@ -4677,18 +5725,18 @@
4677
5725
  }
4678
5726
  if (!_self._senderConfig.isRetryDisabled() && _isRetriable(status)) {
4679
5727
  _resendPayload(payload);
4680
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
5728
+ _throwInternal(_self.diagLog(), 2 , 40 , ". " +
4681
5729
  "Response code " + status + ". Will retry to send " + payload.length + " items.");
4682
5730
  }
4683
5731
  else {
4684
5732
  _self._onError(payload, errorMessage);
4685
5733
  }
4686
5734
  }
4687
- else if (Offline.isOffline()) {
5735
+ else if (_offlineListener && !_offlineListener.isOnline()) {
4688
5736
  if (!_self._senderConfig.isRetryDisabled()) {
4689
5737
  var offlineBackOffMultiplier = 10;
4690
5738
  _resendPayload(payload, offlineBackOffMultiplier);
4691
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(Offline.isOffline(), ". Will retry to send ").concat(payload.length, " items."));
5739
+ _throwInternal(_self.diagLog(), 2 , 40 , ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(!_offlineListener.isOnline(), ". Will retry to send ").concat(payload.length, " items."));
4692
5740
  }
4693
5741
  }
4694
5742
  else {
@@ -4755,8 +5803,8 @@
4755
5803
  }
4756
5804
  }
4757
5805
  if (droppedPayload.length > 0) {
4758
- _fallbackSender(droppedPayload, true);
4759
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
5806
+ _fallbackSender && _fallbackSender(droppedPayload, true);
5807
+ _throwInternal(_self.diagLog(), 2 , 40 , ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
4760
5808
  }
4761
5809
  }
4762
5810
  }
@@ -4797,7 +5845,7 @@
4797
5845
  }
4798
5846
  else {
4799
5847
  _fallbackSender && _fallbackSender(payload, true);
4800
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
5848
+ _throwInternal(_self.diagLog(), 2 , 40 , ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
4801
5849
  }
4802
5850
  }
4803
5851
  }
@@ -4888,7 +5936,7 @@
4888
5936
  }
4889
5937
  }
4890
5938
  catch (e) {
4891
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
5939
+ _throwInternal(_self.diagLog(), 1 , 43 , "Cannot parse the response. " + getExceptionName(e), {
4892
5940
  response: response
4893
5941
  });
4894
5942
  }
@@ -4959,7 +6007,7 @@
4959
6007
  xdr.onerror = function (event) { return _self._onError(payload, _formatErrorMessageXdr(xdr), event); };
4960
6008
  var hostingProtocol = _window && _window.location && _window.location.protocol || "";
4961
6009
  if (_self._senderConfig.endpointUrl().lastIndexOf(hostingProtocol, 0) !== 0) {
4962
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
6010
+ _throwInternal(_self.diagLog(), 2 , 40 , ". " +
4963
6011
  "Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.");
4964
6012
  buffer.clear();
4965
6013
  return;
@@ -4990,7 +6038,7 @@
4990
6038
  manager.eventsSendRequest(sendRequest, isAsync);
4991
6039
  }
4992
6040
  catch (e) {
4993
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
6041
+ _throwInternal(_self.diagLog(), 1 , 74 , "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
4994
6042
  }
4995
6043
  }
4996
6044
  }
@@ -5003,6 +6051,25 @@
5003
6051
  var regexp = new RegExp(UUID_Regex);
5004
6052
  return regexp.test(config.instrumentationKey);
5005
6053
  }
6054
+ function _initDefaults() {
6055
+ _self._sender = null;
6056
+ _self._buffer = null;
6057
+ _self._appId = null;
6058
+ _self._sample = null;
6059
+ _headers = {};
6060
+ _offlineListener = null;
6061
+ _consecutiveErrors = 0;
6062
+ _retryAt = null;
6063
+ _lastSend = null;
6064
+ _paused = false;
6065
+ _timeoutHandle = null;
6066
+ _serializer = null;
6067
+ _stamp_specific_redirects = 0;
6068
+ _syncFetchPayload = 0;
6069
+ _fallbackSender = null;
6070
+ _syncUnloadSender = null;
6071
+ _evtNamespace = null;
6072
+ }
5006
6073
  });
5007
6074
  return _this;
5008
6075
  }
@@ -5022,46 +6089,41 @@
5022
6089
 
5023
6090
  var ApplicationInsights = /** @class */ (function () {
5024
6091
  function ApplicationInsights(config) {
6092
+ var core = new AppInsightsCore();
5025
6093
  if (isNullOrUndefined(config) ||
5026
6094
  isNullOrUndefined(config.instrumentationKey)) {
5027
6095
  throwError("Invalid input configuration");
5028
6096
  }
5029
- this.config = config;
5030
- this.getSKUDefaults();
5031
- this.initialize();
5032
- }
5033
- ApplicationInsights.prototype.initialize = function () {
5034
- this.core = new AppInsightsCore();
5035
- var extensions = [];
5036
- var appInsightsChannel = new Sender();
5037
- extensions.push(appInsightsChannel);
5038
- this.core.initialize(this.config, extensions);
5039
- appInsightsChannel.initialize(this.config, this.core, extensions);
5040
- this.pollInternalLogs();
5041
- };
5042
- ApplicationInsights.prototype.track = function (item) {
5043
- this.core.track(item);
5044
- };
5045
- ApplicationInsights.prototype.flush = function (async) {
5046
- if (async === void 0) { async = true; }
5047
- arrForEach(this.core.getTransmissionControls(), function (controls) {
5048
- arrForEach(controls, function (plugin) {
5049
- async
5050
- ? plugin.flush()
5051
- : plugin.triggerSend(async, null, 1 );
5052
- });
6097
+ dynamicProto(ApplicationInsights, this, function (_self) {
6098
+ _self.config = config;
6099
+ _self.getSKUDefaults();
6100
+ _initialize();
6101
+ _self.initialize = _initialize;
6102
+ _self.getSKUDefaults = function () {
6103
+ _self.config.diagnosticLogInterval =
6104
+ _self.config.diagnosticLogInterval && _self.config.diagnosticLogInterval > 0 ? _self.config.diagnosticLogInterval : 10000;
6105
+ };
6106
+ proxyFunctions(_self, core, [
6107
+ "track",
6108
+ "flush",
6109
+ "pollInternalLogs",
6110
+ "stopPollingInternalLogs",
6111
+ "unload",
6112
+ "getPlugin",
6113
+ "addPlugin",
6114
+ "evtNamespace",
6115
+ "addUnloadCb"
6116
+ ]);
6117
+ function _initialize() {
6118
+ var extensions = [];
6119
+ var appInsightsChannel = new Sender();
6120
+ extensions.push(appInsightsChannel);
6121
+ core.initialize(this.config, extensions);
6122
+ appInsightsChannel.initialize(this.config, core, extensions);
6123
+ core.pollInternalLogs();
6124
+ }
5053
6125
  });
5054
- };
5055
- ApplicationInsights.prototype.pollInternalLogs = function () {
5056
- this.core.pollInternalLogs();
5057
- };
5058
- ApplicationInsights.prototype.stopPollingInternalLogs = function () {
5059
- this.core.stopPollingInternalLogs();
5060
- };
5061
- ApplicationInsights.prototype.getSKUDefaults = function () {
5062
- this.config.diagnosticLogInterval =
5063
- this.config.diagnosticLogInterval && this.config.diagnosticLogInterval > 0 ? this.config.diagnosticLogInterval : 10000;
5064
- };
6126
+ }
5065
6127
  return ApplicationInsights;
5066
6128
  }());
5067
6129
 
@@ -5069,6 +6131,11 @@
5069
6131
  exports.ApplicationInsights = ApplicationInsights;
5070
6132
  exports.CoreUtils = CoreUtils;
5071
6133
  exports.Sender = Sender;
6134
+ exports._InternalMessageId = _InternalMessageId;
6135
+ exports.arrForEach = arrForEach;
6136
+ exports.isNullOrUndefined = isNullOrUndefined;
6137
+ exports.proxyFunctions = proxyFunctions;
6138
+ exports.throwError = throwError;
5072
6139
 
5073
6140
  (function(obj, prop, descriptor) { /* ai_es3_polyfil defineProperty */ var func = Object["defineProperty"]; if (func) { try { return func(obj, prop, descriptor); } catch(e) { /* IE8 defines defineProperty, but will throw */ } } if (descriptor && typeof descriptor.value !== undefined) { obj[prop] = descriptor.value; } return obj; })(exports, '__esModule', { value: true });
5074
6141