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

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