@microsoft/applicationinsights-web-basic 2.7.5-nightly.2203-03 → 2.7.5

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.7.5-nightly.2203-03
2
+ * Application Insights JavaScript Web SDK - Basic, 2.7.5
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -8,8 +8,109 @@
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
+
11
112
  /*!
12
- * Microsoft Dynamic Proto Utility, 1.1.4
113
+ * Microsoft Dynamic Proto Utility, 1.1.5
13
114
  * Copyright (c) Microsoft and contributors. All rights reserved.
14
115
  */
15
116
  var Constructor = 'constructor';
@@ -22,12 +123,13 @@
22
123
  var DynInstChkTag = '_dynInstChk';
23
124
  var DynAllowInstChkTag = DynInstChkTag;
24
125
  var DynProtoDefaultOptions = '_dfOpts';
126
+ var DynProtoPolyProto = "_dynProto";
25
127
  var UnknownValue = '_unknown_';
26
- var str__Proto$1 = "__proto__";
128
+ var str__Proto = "__proto__";
27
129
  var strUseBaseInst = 'useBaseInst';
28
130
  var strSetInstFuncs = 'setInstFuncs';
29
131
  var Obj = Object;
30
- var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
132
+ var _objGetPrototypeOf = Obj["getPrototypeOf"];
31
133
  var _dynamicNames = 0;
32
134
  function _hasOwnProperty(obj, prop) {
33
135
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -38,13 +140,16 @@
38
140
  function _isObjectArrayOrFunctionPrototype(target) {
39
141
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
40
142
  }
41
- function _getObjProto$1(target) {
143
+ function _getObjProto(target) {
42
144
  if (target) {
43
- if (_objGetPrototypeOf$1) {
44
- return _objGetPrototypeOf$1(target);
145
+ if (_objGetPrototypeOf) {
146
+ return _objGetPrototypeOf(target);
45
147
  }
46
- var newProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
148
+ var newProto = target[DynProtoPolyProto] || target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
47
149
  if (newProto) {
150
+ if (!target[DynProtoPolyProto]) {
151
+ target[DynProtoPolyProto] = newProto;
152
+ }
48
153
  return newProto;
49
154
  }
50
155
  }
@@ -109,16 +214,16 @@
109
214
  _forEachProp(instFuncs, function (name) {
110
215
  baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
111
216
  });
112
- var baseProto = _getObjProto$1(classProto);
217
+ var baseProto = _getObjProto(classProto);
113
218
  var visited = [];
114
219
  while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
115
220
  _forEachProp(baseProto, function (name) {
116
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf$1)) {
221
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
117
222
  baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
118
223
  }
119
224
  });
120
225
  visited.push(baseProto);
121
- baseProto = _getObjProto$1(baseProto);
226
+ baseProto = _getObjProto(baseProto);
122
227
  }
123
228
  return baseFuncs;
124
229
  }
@@ -132,7 +237,7 @@
132
237
  }
133
238
  if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
134
239
  var canAddInst = !_hasOwnProperty(target, funcName);
135
- var objProto = _getObjProto$1(target);
240
+ var objProto = _getObjProto(target);
136
241
  var visited = [];
137
242
  while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
138
243
  var protoFunc = objProto[funcName];
@@ -141,7 +246,7 @@
141
246
  break;
142
247
  }
143
248
  visited.push(objProto);
144
- objProto = _getObjProto$1(objProto);
249
+ objProto = _getObjProto(objProto);
145
250
  }
146
251
  try {
147
252
  if (canAddInst) {
@@ -159,7 +264,7 @@
159
264
  function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
160
265
  var protoFunc = proto[funcName];
161
266
  if (protoFunc === currentDynProtoProxy) {
162
- protoFunc = _getObjProto$1(proto)[funcName];
267
+ protoFunc = _getObjProto(proto)[funcName];
163
268
  }
164
269
  if (typeof protoFunc !== strFunction) {
165
270
  _throwTypeError("[" + funcName + "] is not a " + strFunction);
@@ -193,18 +298,19 @@
193
298
  }
194
299
  }
195
300
  function _checkPrototype(classProto, thisTarget) {
196
- if (_objGetPrototypeOf$1) {
301
+ if (_objGetPrototypeOf) {
197
302
  var visited = [];
198
- var thisProto = _getObjProto$1(thisTarget);
303
+ var thisProto = _getObjProto(thisTarget);
199
304
  while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
200
305
  if (thisProto === classProto) {
201
306
  return true;
202
307
  }
203
308
  visited.push(thisProto);
204
- thisProto = _getObjProto$1(thisProto);
309
+ thisProto = _getObjProto(thisProto);
205
310
  }
311
+ return false;
206
312
  }
207
- return false;
313
+ return true;
208
314
  }
209
315
  function _getObjName(target, unknownValue) {
210
316
  if (_hasOwnProperty(target, Prototype)) {
@@ -237,7 +343,7 @@
237
343
  var instFuncs = _getInstanceFuncs(target);
238
344
  var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
239
345
  delegateFunc(target, baseFuncs);
240
- var setInstanceFunc = !!_objGetPrototypeOf$1 && !!perfOptions[strSetInstFuncs];
346
+ var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
241
347
  if (setInstanceFunc && options) {
242
348
  setInstanceFunc = !!options[strSetInstFuncs];
243
349
  }
@@ -249,132 +355,99 @@
249
355
  };
250
356
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
251
357
 
252
- var EventsDiscardedReason = {
253
- Unknown: 0,
254
- NonRetryableStatus: 1,
255
- InvalidEvent: 2,
256
- SizeLimitExceeded: 3,
257
- KillSwitch: 4,
258
- QueueFull: 5
259
- };
260
-
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);
358
+ var LoggingSeverity;
359
+ (function (LoggingSeverity) {
360
+ LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
361
+ LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
362
+ })(LoggingSeverity || (LoggingSeverity = {}));
363
+ var _InternalMessageId = {
364
+ BrowserDoesNotSupportLocalStorage: 0,
365
+ BrowserCannotReadLocalStorage: 1,
366
+ BrowserCannotReadSessionStorage: 2,
367
+ BrowserCannotWriteLocalStorage: 3,
368
+ BrowserCannotWriteSessionStorage: 4,
369
+ BrowserFailedRemovalFromLocalStorage: 5,
370
+ BrowserFailedRemovalFromSessionStorage: 6,
371
+ CannotSendEmptyTelemetry: 7,
372
+ ClientPerformanceMathError: 8,
373
+ ErrorParsingAISessionCookie: 9,
374
+ ErrorPVCalc: 10,
375
+ ExceptionWhileLoggingError: 11,
376
+ FailedAddingTelemetryToBuffer: 12,
377
+ FailedMonitorAjaxAbort: 13,
378
+ FailedMonitorAjaxDur: 14,
379
+ FailedMonitorAjaxOpen: 15,
380
+ FailedMonitorAjaxRSC: 16,
381
+ FailedMonitorAjaxSend: 17,
382
+ FailedMonitorAjaxGetCorrelationHeader: 18,
383
+ FailedToAddHandlerForOnBeforeUnload: 19,
384
+ FailedToSendQueuedTelemetry: 20,
385
+ FailedToReportDataLoss: 21,
386
+ FlushFailed: 22,
387
+ MessageLimitPerPVExceeded: 23,
388
+ MissingRequiredFieldSpecification: 24,
389
+ NavigationTimingNotSupported: 25,
390
+ OnError: 26,
391
+ SessionRenewalDateIsZero: 27,
392
+ SenderNotInitialized: 28,
393
+ StartTrackEventFailed: 29,
394
+ StopTrackEventFailed: 30,
395
+ StartTrackFailed: 31,
396
+ StopTrackFailed: 32,
397
+ TelemetrySampledAndNotSent: 33,
398
+ TrackEventFailed: 34,
399
+ TrackExceptionFailed: 35,
400
+ TrackMetricFailed: 36,
401
+ TrackPVFailed: 37,
402
+ TrackPVFailedCalc: 38,
403
+ TrackTraceFailed: 39,
404
+ TransmissionFailed: 40,
405
+ FailedToSetStorageBuffer: 41,
406
+ FailedToRestoreStorageBuffer: 42,
407
+ InvalidBackendResponse: 43,
408
+ FailedToFixDepricatedValues: 44,
409
+ InvalidDurationValue: 45,
410
+ TelemetryEnvelopeInvalid: 46,
411
+ CreateEnvelopeError: 47,
412
+ CannotSerializeObject: 48,
413
+ CannotSerializeObjectNonSerializable: 49,
414
+ CircularReferenceDetected: 50,
415
+ ClearAuthContextFailed: 51,
416
+ ExceptionTruncated: 52,
417
+ IllegalCharsInName: 53,
418
+ ItemNotInArray: 54,
419
+ MaxAjaxPerPVExceeded: 55,
420
+ MessageTruncated: 56,
421
+ NameTooLong: 57,
422
+ SampleRateOutOfRange: 58,
423
+ SetAuthContextFailed: 59,
424
+ SetAuthContextFailedAccountName: 60,
425
+ StringValueTooLong: 61,
426
+ StartCalledMoreThanOnce: 62,
427
+ StopCalledWithoutStart: 63,
428
+ TelemetryInitializerFailed: 64,
429
+ TrackArgumentsNotSpecified: 65,
430
+ UrlTooLong: 66,
431
+ SessionStorageBufferFull: 67,
432
+ CannotAccessCookie: 68,
433
+ IdTooLong: 69,
434
+ InvalidEvent: 70,
435
+ FailedMonitorAjaxSetRequestHeader: 71,
436
+ SendBrowserInfoOnUserInit: 72,
437
+ PluginException: 73,
438
+ NotificationException: 74,
439
+ SnippetScriptLoadFailure: 99,
440
+ InvalidInstrumentationKey: 100,
441
+ CannotParseAiBlobValue: 101,
442
+ InvalidContentBlob: 102,
443
+ TrackPageActionEventFailed: 103,
444
+ FailedAddingCustomDefinedRequestContext: 104,
445
+ InMemoryStorageBufferFull: 105
339
446
  };
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
447
 
448
+ var strOnPrefix = "on";
449
+ var strAttachEvent = "attachEvent";
450
+ var strAddEventHelper = "addEventListener";
378
451
  var strToISOString = "toISOString";
379
452
  var cStrEndsWith = "endsWith";
380
453
  var cStrStartsWith = "startsWith";
@@ -383,10 +456,8 @@
383
456
  var strReduce = "reduce";
384
457
  var cStrTrim = "trim";
385
458
  var strToString = "toString";
386
- var str__Proto = "__proto__";
387
- var strConstructor = "constructor";
388
- var _objDefineProperty$1 = ObjDefineProperty;
389
- var _objFreeze = ObjClass.freeze;
459
+ var _objDefineProperty = ObjDefineProperty;
460
+ ObjClass.freeze;
390
461
  ObjClass.seal;
391
462
  var _objKeys = ObjClass.keys;
392
463
  var StringProto = String[strShimPrototype];
@@ -398,23 +469,7 @@
398
469
  var _isArray = Array.isArray;
399
470
  var _objToString = ObjProto[strToString];
400
471
  var _fnToString = ObjHasOwnProperty[strToString];
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
- }
472
+ _fnToString.call(ObjClass);
418
473
  function isTypeof(value, theType) {
419
474
  return typeof value === theType;
420
475
  }
@@ -436,18 +491,24 @@
436
491
  function isFunction(value) {
437
492
  return !!(value && typeof value === strShimFunction);
438
493
  }
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
- });
494
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
495
+ if (useCapture === void 0) { useCapture = false; }
496
+ var result = false;
497
+ if (!isNullOrUndefined(obj)) {
498
+ try {
499
+ if (!isNullOrUndefined(obj[strAddEventHelper])) {
500
+ obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
501
+ result = true;
502
+ }
503
+ else if (!isNullOrUndefined(obj[strAttachEvent])) {
504
+ obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
505
+ result = true;
506
+ }
507
+ }
508
+ catch (e) {
509
+ }
449
510
  }
450
- return value;
511
+ return result;
451
512
  }
452
513
  function objForEachKey(target, callbackfn) {
453
514
  if (target) {
@@ -506,22 +567,6 @@
506
567
  function isBoolean(value) {
507
568
  return typeof value === "boolean";
508
569
  }
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
- }
525
570
  function toISOString(date) {
526
571
  if (date) {
527
572
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -667,7 +712,7 @@
667
712
  return result;
668
713
  }
669
714
  function objDefineAccessors(target, prop, getProp, setProp) {
670
- if (_objDefineProperty$1) {
715
+ if (_objDefineProperty) {
671
716
  try {
672
717
  var descriptor = {
673
718
  enumerable: true,
@@ -679,7 +724,7 @@
679
724
  if (setProp) {
680
725
  descriptor.set = setProp;
681
726
  }
682
- _objDefineProperty$1(target, prop, descriptor);
727
+ _objDefineProperty(target, prop, descriptor);
683
728
  return true;
684
729
  }
685
730
  catch (e) {
@@ -687,10 +732,6 @@
687
732
  }
688
733
  return false;
689
734
  }
690
- function _doNothing(value) {
691
- return value;
692
- }
693
- var objFreeze = _objFreeze || _doNothing;
694
735
  function dateNow() {
695
736
  var dt = Date;
696
737
  return dt.now ? dt.now() : new dt().getTime();
@@ -699,7 +740,7 @@
699
740
  if (isError(object)) {
700
741
  return object.name;
701
742
  }
702
- return strEmpty$1;
743
+ return "";
703
744
  }
704
745
  function setValue(target, field, value, valChk, srcChk) {
705
746
  var theValue = value;
@@ -735,44 +776,6 @@
735
776
  function throwError(message) {
736
777
  throw new Error(message);
737
778
  }
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
779
  function createClassFromInterface(defaults) {
777
780
  return /** @class */ (function () {
778
781
  function class_1() {
@@ -786,67 +789,12 @@
786
789
  return class_1;
787
790
  }());
788
791
  }
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);
799
- }
800
792
  function optimizeObject(theObject) {
801
793
  if (theObject && ObjAssign) {
802
794
  theObject = ObjClass(ObjAssign({}, theObject));
803
795
  }
804
796
  return theObject;
805
797
  }
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
- }
850
798
 
851
799
  var strWindow = "window";
852
800
  var strDocument = "document";
@@ -860,7 +808,6 @@
860
808
  var strMsCrypto = "msCrypto";
861
809
  var strMsie = "msie";
862
810
  var strTrident = "trident/";
863
- var strXMLHttpRequest = "XMLHttpRequest";
864
811
  var _isTrident = null;
865
812
  var _navUserAgentCheck = null;
866
813
  var _enableMocks = false;
@@ -968,7 +915,7 @@
968
915
  var nav = getNavigator();
969
916
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
970
917
  _navUserAgentCheck = nav.userAgent;
971
- var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
918
+ var userAgent = (_navUserAgentCheck || "").toLowerCase();
972
919
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
973
920
  }
974
921
  return _isTrident;
@@ -977,9 +924,9 @@
977
924
  if (userAgentStr === void 0) { userAgentStr = null; }
978
925
  if (!userAgentStr) {
979
926
  var navigator_1 = getNavigator() || {};
980
- userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
927
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
981
928
  }
982
- var ua = (userAgentStr || strEmpty$1).toLowerCase();
929
+ var ua = (userAgentStr || "").toLowerCase();
983
930
  if (strContains(ua, strMsie)) {
984
931
  var doc = getDocument() || {};
985
932
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -994,7 +941,7 @@
994
941
  }
995
942
  function dumpObj(object) {
996
943
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
997
- var propertyValueDump = strEmpty$1;
944
+ var propertyValueDump = "";
998
945
  if (objectTypeDump === "[object Error]") {
999
946
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
1000
947
  }
@@ -1012,7 +959,8 @@
1012
959
  function isFetchSupported(withKeepAlive) {
1013
960
  var isSupported = false;
1014
961
  try {
1015
- isSupported = !!getGlobalInst("fetch");
962
+ var fetchApi = getGlobalInst("fetch");
963
+ isSupported = !!fetchApi;
1016
964
  var request = getGlobalInst("Request");
1017
965
  if (isSupported && withKeepAlive && request) {
1018
966
  isSupported = _hasProperty(request, "keepalive");
@@ -1024,9 +972,9 @@
1024
972
  }
1025
973
  function useXDomainRequest() {
1026
974
  if (_useXDomainRequest === null) {
1027
- _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
975
+ _useXDomainRequest = (typeof XDomainRequest !== "undefined");
1028
976
  if (_useXDomainRequest && isXhrSupported()) {
1029
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
977
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
1030
978
  }
1031
979
  }
1032
980
  return _useXDomainRequest;
@@ -1034,7 +982,7 @@
1034
982
  function isXhrSupported() {
1035
983
  var isSupported = false;
1036
984
  try {
1037
- var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
985
+ var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
1038
986
  isSupported = !!xmlHttpRequest;
1039
987
  }
1040
988
  catch (e) {
@@ -1088,9 +1036,9 @@
1088
1036
  var strWarnToConsole = "warnToConsole";
1089
1037
  function _sanitizeDiagnosticText(text) {
1090
1038
  if (text) {
1091
- return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
1039
+ return "\"" + text.replace(/\"/g, "") + "\"";
1092
1040
  }
1093
- return strEmpty$1;
1041
+ return "";
1094
1042
  }
1095
1043
  function _logToConsole(func, message) {
1096
1044
  var theConsole = getConsole();
@@ -1112,12 +1060,12 @@
1112
1060
  _self.message =
1113
1061
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
1114
1062
  msgId;
1115
- var strProps = strEmpty$1;
1063
+ var strProps = "";
1116
1064
  if (hasJSON()) {
1117
1065
  strProps = getJSON().stringify(properties);
1118
1066
  }
1119
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
1120
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
1067
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
1068
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
1121
1069
  _self.message += diagnosticText;
1122
1070
  }
1123
1071
  _InternalLogMessage.dataType = "MessageData";
@@ -1144,10 +1092,10 @@
1144
1092
  if (isUserAct === void 0) { isUserAct = false; }
1145
1093
  var message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
1146
1094
  if (_self.enableDebugExceptions()) {
1147
- throw message;
1095
+ throw dumpObj(message);
1148
1096
  }
1149
1097
  else {
1150
- var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
1098
+ var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
1151
1099
  if (!isUndefined(message.message)) {
1152
1100
  var logLevel = _self.consoleLoggingLevel();
1153
1101
  if (isUserAct) {
@@ -1165,7 +1113,7 @@
1165
1113
  _self.logInternalMessage(severity, message);
1166
1114
  }
1167
1115
  else {
1168
- _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
1116
+ _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
1169
1117
  }
1170
1118
  }
1171
1119
  };
@@ -1197,13 +1145,13 @@
1197
1145
  if (severity <= _self.telemetryLoggingLevel()) {
1198
1146
  _self.queue.push(message);
1199
1147
  _messageCount++;
1200
- _debugExtMsg((severity === 1 ? "error" : "warn"), message);
1148
+ _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
1201
1149
  }
1202
1150
  if (_messageCount === _self.maxInternalMessageLimit()) {
1203
1151
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
1204
- var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
1152
+ var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
1205
1153
  _self.queue.push(throttleMessage);
1206
- if (severity === 1 ) {
1154
+ if (severity === LoggingSeverity.CRITICAL) {
1207
1155
  _self.errorToConsole(throttleLimitMessage);
1208
1156
  }
1209
1157
  else {
@@ -1232,10 +1180,6 @@
1232
1180
  }
1233
1181
  return DiagnosticLogger;
1234
1182
  }());
1235
- function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1236
- if (isUserAct === void 0) { isUserAct = false; }
1237
- (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1238
- }
1239
1183
 
1240
1184
  var strExecutionContextKey = "ctx";
1241
1185
  var _defaultPerfManager = null;
@@ -1381,186 +1325,271 @@
1381
1325
  return _defaultPerfManager;
1382
1326
  }
1383
1327
 
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;
1392
- }
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) {
1403
- }
1404
- }
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;
1328
+ var TelemetryPluginChain = /** @class */ (function () {
1329
+ function TelemetryPluginChain(plugin, defItemCtx) {
1330
+ var _self = this;
1331
+ var _nextProxy = null;
1332
+ var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1333
+ var _hasSetNext = isFunction(plugin.setNextPlugin);
1334
+ _self._hasRun = false;
1335
+ _self.getPlugin = function () {
1336
+ return plugin;
1337
+ };
1338
+ _self.getNext = function () {
1339
+ return _nextProxy;
1340
+ };
1341
+ _self.setNext = function (nextPlugin) {
1342
+ _nextProxy = nextPlugin;
1343
+ };
1344
+ _self.processTelemetry = function (env, itemCtx) {
1345
+ if (!itemCtx) {
1346
+ itemCtx = defItemCtx;
1347
+ }
1348
+ var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1349
+ doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1350
+ if (plugin && _hasProcessTelemetry) {
1351
+ _self._hasRun = true;
1352
+ try {
1353
+ itemCtx.setNext(_nextProxy);
1354
+ if (_hasSetNext) {
1355
+ plugin.setNextPlugin(_nextProxy);
1356
+ }
1357
+ _nextProxy && (_nextProxy._hasRun = false);
1358
+ plugin.processTelemetry(env, itemCtx);
1359
+ }
1360
+ catch (error) {
1361
+ var hasRun = _nextProxy && _nextProxy._hasRun;
1362
+ if (!_nextProxy || !hasRun) {
1363
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1364
+ }
1365
+ if (_nextProxy && !hasRun) {
1366
+ _nextProxy.processTelemetry(env, itemCtx);
1367
+ }
1368
+ }
1369
+ }
1370
+ else if (_nextProxy) {
1371
+ _self._hasRun = true;
1372
+ _nextProxy.processTelemetry(env, itemCtx);
1373
+ }
1374
+ }, function () { return ({ item: env }); }, !(env.sync));
1375
+ };
1416
1376
  }
1417
- if (value === 0 && isIE()) {
1418
- if (!_mwcSeeded) {
1419
- _autoSeedMwc();
1377
+ return TelemetryPluginChain;
1378
+ }());
1379
+
1380
+ function _createProxyChain(plugins, itemCtx) {
1381
+ var proxies = [];
1382
+ if (plugins && plugins.length > 0) {
1383
+ var lastProxy = null;
1384
+ for (var idx = 0; idx < plugins.length; idx++) {
1385
+ var thePlugin = plugins[idx];
1386
+ if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1387
+ var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1388
+ proxies.push(newProxy);
1389
+ if (lastProxy) {
1390
+ lastProxy.setNext(newProxy);
1391
+ }
1392
+ lastProxy = newProxy;
1393
+ }
1420
1394
  }
1421
- value = mwcRandom32() & MaxUInt32;
1422
- }
1423
- if (value === 0) {
1424
- value = Math.floor((UInt32Mask * Math.random()) | 0);
1425
- }
1426
- if (!signed) {
1427
- value >>>= 0;
1428
1395
  }
1429
- return value;
1396
+ return proxies.length > 0 ? proxies[0] : null;
1430
1397
  }
1431
- function mwcRandomSeed(value) {
1432
- if (!value) {
1433
- _autoSeedMwc();
1434
- }
1435
- else {
1436
- _mwcSeed(value);
1398
+ function _copyProxyChain(proxy, itemCtx, startAt) {
1399
+ var plugins = [];
1400
+ var add = startAt ? false : true;
1401
+ if (proxy) {
1402
+ while (proxy) {
1403
+ var thePlugin = proxy.getPlugin();
1404
+ if (add || thePlugin === startAt) {
1405
+ add = true;
1406
+ plugins.push(thePlugin);
1407
+ }
1408
+ proxy = proxy.getNext();
1409
+ }
1437
1410
  }
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;
1411
+ if (!add) {
1412
+ plugins.push(startAt);
1445
1413
  }
1446
- return value;
1414
+ return _createProxyChain(plugins, itemCtx);
1447
1415
  }
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
- }
1416
+ function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1417
+ var plugins = srcPlugins;
1418
+ var add = false;
1419
+ if (startAt && srcPlugins) {
1420
+ plugins = [];
1421
+ arrForEach(srcPlugins, function (thePlugin) {
1422
+ if (add || thePlugin === startAt) {
1423
+ add = true;
1424
+ plugins.push(thePlugin);
1425
+ }
1426
+ });
1462
1427
  }
1463
- return result;
1464
- }
1465
-
1466
- var _objDefineProperty = ObjDefineProperty;
1467
- var version = "2.7.5-nightly.2203-03";
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) {
1428
+ if (startAt && !add) {
1429
+ if (!plugins) {
1430
+ plugins = [];
1481
1431
  }
1432
+ plugins.push(startAt);
1482
1433
  }
1483
- return false;
1434
+ return _createProxyChain(plugins, itemCtx);
1484
1435
  }
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;
1436
+ var ProcessTelemetryContext = /** @class */ (function () {
1437
+ function ProcessTelemetryContext(plugins, config, core, startAt) {
1438
+ var _self = this;
1439
+ var _nextProxy = null;
1440
+ if (startAt !== null) {
1441
+ if (plugins && isFunction(plugins.getPlugin)) {
1442
+ _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1443
+ }
1444
+ else {
1445
+ if (startAt) {
1446
+ _nextProxy = _copyPluginChain(plugins, _self, startAt);
1447
+ }
1448
+ else if (isUndefined(startAt)) {
1449
+ _nextProxy = _createProxyChain(plugins, _self);
1496
1450
  }
1497
1451
  }
1498
1452
  }
1499
- catch (e) {
1500
- }
1501
- }
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;
1453
+ _self.core = function () {
1454
+ return core;
1455
+ };
1456
+ _self.diagLog = function () {
1457
+ return safeGetLogger(core, config);
1458
+ };
1459
+ _self.getCfg = function () {
1460
+ return config;
1461
+ };
1462
+ _self.getExtCfg = function (identifier, defaultValue) {
1463
+ if (defaultValue === void 0) { defaultValue = {}; }
1464
+ var theConfig;
1465
+ if (config) {
1466
+ var extConfig = config.extensionConfig;
1467
+ if (extConfig && identifier) {
1468
+ theConfig = extConfig[identifier];
1520
1469
  }
1521
- return defValue;
1522
1470
  }
1523
- return theCache[normalizeJsName(name)];
1524
- },
1525
- kill: function (target, name) {
1526
- if (target && target[name]) {
1527
- try {
1528
- delete target[name];
1471
+ return (theConfig ? theConfig : defaultValue);
1472
+ };
1473
+ _self.getConfig = function (identifier, field, defaultValue) {
1474
+ if (defaultValue === void 0) { defaultValue = false; }
1475
+ var theValue;
1476
+ var extConfig = _self.getExtCfg(identifier, null);
1477
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1478
+ theValue = extConfig[field];
1479
+ }
1480
+ else if (config && !isNullOrUndefined(config[field])) {
1481
+ theValue = config[field];
1482
+ }
1483
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1484
+ };
1485
+ _self.hasNext = function () {
1486
+ return _nextProxy != null;
1487
+ };
1488
+ _self.getNext = function () {
1489
+ return _nextProxy;
1490
+ };
1491
+ _self.setNext = function (nextPlugin) {
1492
+ _nextProxy = nextPlugin;
1493
+ };
1494
+ _self.processNext = function (env) {
1495
+ var nextPlugin = _nextProxy;
1496
+ if (nextPlugin) {
1497
+ _nextProxy = nextPlugin.getNext();
1498
+ nextPlugin.processTelemetry(env, _self);
1499
+ }
1500
+ };
1501
+ _self.createNew = function (plugins, startAt) {
1502
+ if (plugins === void 0) { plugins = null; }
1503
+ return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1504
+ };
1505
+ }
1506
+ return ProcessTelemetryContext;
1507
+ }());
1508
+
1509
+ var strIKey = "iKey";
1510
+ var strExtensionConfig = "extensionConfig";
1511
+
1512
+ var strGetPlugin = "getPlugin";
1513
+ var BaseTelemetryPlugin = /** @class */ (function () {
1514
+ function BaseTelemetryPlugin() {
1515
+ var _self = this;
1516
+ var _isinitialized = false;
1517
+ var _rootCtx = null;
1518
+ var _nextPlugin = null;
1519
+ _self.core = null;
1520
+ _self.diagLog = function (itemCtx) {
1521
+ return _self._getTelCtx(itemCtx).diagLog();
1522
+ };
1523
+ _self.isInitialized = function () {
1524
+ return _isinitialized;
1525
+ };
1526
+ _self.setInitialized = function (isInitialized) {
1527
+ _isinitialized = isInitialized;
1528
+ };
1529
+ _self.setNextPlugin = function (next) {
1530
+ _nextPlugin = next;
1531
+ };
1532
+ _self.processNext = function (env, itemCtx) {
1533
+ if (itemCtx) {
1534
+ itemCtx.processNext(env);
1535
+ }
1536
+ else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
1537
+ _nextPlugin.processTelemetry(env, null);
1538
+ }
1539
+ };
1540
+ _self._getTelCtx = function (currentCtx) {
1541
+ if (currentCtx === void 0) { currentCtx = null; }
1542
+ var itemCtx = currentCtx;
1543
+ if (!itemCtx) {
1544
+ var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1545
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1546
+ itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1529
1547
  }
1530
- catch (e) {
1548
+ else {
1549
+ itemCtx = rootCtx.createNew(null, _nextPlugin);
1531
1550
  }
1532
1551
  }
1533
- }
1552
+ return itemCtx;
1553
+ };
1554
+ _self._baseTelInit = function (config, core, extensions, pluginChain) {
1555
+ if (config) {
1556
+ setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1557
+ }
1558
+ if (!pluginChain && core) {
1559
+ pluginChain = core.getProcessTelContext().getNext();
1560
+ }
1561
+ var nextPlugin = _nextPlugin;
1562
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1563
+ nextPlugin = _nextPlugin[strGetPlugin]();
1564
+ }
1565
+ _self.core = core;
1566
+ _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1567
+ _isinitialized = true;
1568
+ };
1569
+ }
1570
+ BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1571
+ this._baseTelInit(config, core, extensions, pluginChain);
1534
1572
  };
1535
- return data;
1536
- }
1573
+ return BaseTelemetryPlugin;
1574
+ }());
1537
1575
 
1538
- var pluginStateData = createElmNodeData("plugin");
1539
- function _getPluginState(plugin) {
1540
- return pluginStateData.get(plugin, "state", {}, true);
1541
- }
1576
+ var processTelemetry = "processTelemetry";
1577
+ var priority = "priority";
1578
+ var setNextPlugin = "setNextPlugin";
1579
+ var isInitialized = "isInitialized";
1542
1580
  function initializePlugins(processContext, extensions) {
1543
1581
  var initPlugins = [];
1544
1582
  var lastPlugin = null;
1545
1583
  var proxy = processContext.getNext();
1546
- var pluginState;
1547
1584
  while (proxy) {
1548
1585
  var thePlugin = proxy.getPlugin();
1549
1586
  if (thePlugin) {
1550
1587
  if (lastPlugin &&
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];
1588
+ isFunction(lastPlugin[setNextPlugin]) &&
1589
+ isFunction(thePlugin[processTelemetry])) {
1590
+ lastPlugin[setNextPlugin](thePlugin);
1562
1591
  }
1563
- if (!isInitialized) {
1592
+ if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {
1564
1593
  initPlugins.push(thePlugin);
1565
1594
  }
1566
1595
  lastPlugin = thePlugin;
@@ -1568,22 +1597,15 @@
1568
1597
  }
1569
1598
  }
1570
1599
  arrForEach(initPlugins, function (thePlugin) {
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];
1600
+ thePlugin.initialize(processContext.getCfg(), processContext.core(), extensions, processContext.getNext());
1579
1601
  });
1580
1602
  }
1581
1603
  function sortPlugins(plugins) {
1582
1604
  return plugins.sort(function (extA, extB) {
1583
1605
  var result = 0;
1584
- var bHasProcess = isFunction(extB[strProcessTelemetry]);
1585
- if (isFunction(extA[strProcessTelemetry])) {
1586
- result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1606
+ var bHasProcess = isFunction(extB[processTelemetry]);
1607
+ if (isFunction(extA[processTelemetry])) {
1608
+ result = bHasProcess ? extA[priority] - extB[priority] : 1;
1587
1609
  }
1588
1610
  else if (bHasProcess) {
1589
1611
  result = -1;
@@ -1592,350 +1614,80 @@
1592
1614
  });
1593
1615
  }
1594
1616
 
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;
1603
- }
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
1617
+ var ChannelControllerPriority = 500;
1618
+ var ChannelValidationMessage = "Channel has invalid priority";
1619
+ var ChannelController = /** @class */ (function (_super) {
1620
+ __extendsFn(ChannelController, _super);
1621
+ function ChannelController() {
1622
+ var _this = _super.call(this) || this;
1623
+ _this.identifier = "ChannelControllerPlugin";
1624
+ _this.priority = ChannelControllerPriority;
1625
+ var _channelQueue;
1626
+ dynamicProto(ChannelController, _this, function (_self, _base) {
1627
+ _self.setNextPlugin = function (next) {
1628
+ };
1629
+ _self.processTelemetry = function (item, itemCtx) {
1630
+ if (_channelQueue) {
1631
+ arrForEach(_channelQueue, function (queues) {
1632
+ if (queues.length > 0) {
1633
+ var chainCtx = _this._getTelCtx(itemCtx).createNew(queues);
1634
+ chainCtx.processNext(item);
1635
+ }
1636
+ });
1637
+ }
1638
+ };
1639
+ _self.getChannelControls = function () {
1640
+ return _channelQueue;
1641
+ };
1642
+ _self.initialize = function (config, core, extensions) {
1643
+ if (_self.isInitialized()) {
1644
+ return;
1645
+ }
1646
+ _base.initialize(config, core, extensions);
1647
+ _createChannelQueues((config || {}).channels, extensions);
1648
+ arrForEach(_channelQueue, function (queue) { return initializePlugins(new ProcessTelemetryContext(queue, config, core), extensions); });
1649
+ };
1650
+ });
1651
+ function _checkQueuePriority(queue) {
1652
+ arrForEach(queue, function (queueItem) {
1653
+ if (queueItem.priority < ChannelControllerPriority) {
1654
+ throwError(ChannelValidationMessage + queueItem.identifier);
1655
+ }
1651
1656
  });
1652
1657
  }
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));
1666
- }
1658
+ function _addChannelQueue(queue) {
1659
+ if (queue && queue.length > 0) {
1660
+ queue = queue.sort(function (a, b) {
1661
+ return a.priority - b.priority;
1667
1662
  });
1668
- _onComplete = [];
1663
+ _checkQueuePriority(queue);
1664
+ _channelQueue.push(queue);
1669
1665
  }
1670
1666
  }
1671
- return nextProxy;
1672
- }
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];
1667
+ function _createChannelQueues(channels, extensions) {
1668
+ _channelQueue = [];
1669
+ if (channels) {
1670
+ arrForEach(channels, function (queue) { return _addChannelQueue(queue); });
1671
+ }
1672
+ if (extensions) {
1673
+ var extensionQueue_1 = [];
1674
+ arrForEach(extensions, function (plugin) {
1675
+ if (plugin.priority > ChannelControllerPriority) {
1676
+ extensionQueue_1.push(plugin);
1677
+ }
1678
+ });
1679
+ _addChannelQueue(extensionQueue_1);
1681
1680
  }
1682
1681
  }
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
- }
1682
+ return _this;
1936
1683
  }
1937
- return objFreeze(proxyChain);
1938
- }
1684
+ ChannelController._staticInit = (function () {
1685
+ var proto = ChannelController.prototype;
1686
+ objDefineAccessors(proto, "ChannelControls", proto.getChannelControls);
1687
+ objDefineAccessors(proto, "channelQueue", proto.getChannelControls);
1688
+ })();
1689
+ return ChannelController;
1690
+ }(BaseTelemetryPlugin));
1939
1691
 
1940
1692
  var strToGMTString = "toGMTString";
1941
1693
  var strToUTCString = "toUTCString";
@@ -1945,6 +1697,7 @@
1945
1697
  var strIsCookieUseDisabled = "isCookieUseDisabled";
1946
1698
  var strDisableCookiesUsage = "disableCookiesUsage";
1947
1699
  var strConfigCookieMgr = "_ckMgr";
1700
+ var strEmpty = "";
1948
1701
  var _supportsCookies = null;
1949
1702
  var _allowUaSameSite = null;
1950
1703
  var _parsedCookieValue = null;
@@ -2002,7 +1755,7 @@
2002
1755
  var result = false;
2003
1756
  if (_isMgrEnabled(cookieMgr)) {
2004
1757
  var values = {};
2005
- var theValue = strTrim(value || strEmpty$1);
1758
+ var theValue = strTrim(value || strEmpty);
2006
1759
  var idx = theValue.indexOf(";");
2007
1760
  if (idx !== -1) {
2008
1761
  theValue = strTrim(value.substring(0, idx));
@@ -2017,11 +1770,11 @@
2017
1770
  if (expireMs > 0) {
2018
1771
  var expiry = new Date();
2019
1772
  expiry.setTime(expireMs);
2020
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty$1, isTruthy);
1773
+ setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty, isTruthy);
2021
1774
  }
2022
1775
  }
2023
1776
  if (!_isIE) {
2024
- setValue(values, "max-age", strEmpty$1 + maxAgeSec, null, isUndefined);
1777
+ setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
2025
1778
  }
2026
1779
  }
2027
1780
  var location_1 = getLocation();
@@ -2042,7 +1795,7 @@
2042
1795
  return result;
2043
1796
  },
2044
1797
  get: function (name) {
2045
- var value = strEmpty$1;
1798
+ var value = strEmpty;
2046
1799
  if (_isMgrEnabled(cookieMgr)) {
2047
1800
  value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
2048
1801
  }
@@ -2067,7 +1820,7 @@
2067
1820
  values["max-age"] = "0";
2068
1821
  }
2069
1822
  var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
2070
- delCookie(name, _formatCookieValue(strEmpty$1, values));
1823
+ delCookie(name, _formatCookieValue(strEmpty, values));
2071
1824
  result = true;
2072
1825
  }
2073
1826
  return result;
@@ -2084,7 +1837,7 @@
2084
1837
  _supportsCookies = doc[strCookie] !== undefined;
2085
1838
  }
2086
1839
  catch (e) {
2087
- _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
1840
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotAccessCookie, "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2088
1841
  }
2089
1842
  }
2090
1843
  return _supportsCookies;
@@ -2094,7 +1847,7 @@
2094
1847
  if (theValue && theValue.length) {
2095
1848
  var parts = strTrim(theValue).split(";");
2096
1849
  arrForEach(parts, function (thePart) {
2097
- thePart = strTrim(thePart || strEmpty$1);
1850
+ thePart = strTrim(thePart || strEmpty);
2098
1851
  if (thePart) {
2099
1852
  var idx = thePart.indexOf("=");
2100
1853
  if (idx === -1) {
@@ -2115,21 +1868,21 @@
2115
1868
  return null;
2116
1869
  }
2117
1870
  function _formatCookieValue(value, values) {
2118
- var cookieValue = value || strEmpty$1;
1871
+ var cookieValue = value || strEmpty;
2119
1872
  objForEachKey(values, function (name, theValue) {
2120
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty$1);
1873
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
2121
1874
  });
2122
1875
  return cookieValue;
2123
1876
  }
2124
1877
  function _getCookieValue(name) {
2125
- var cookieValue = strEmpty$1;
1878
+ var cookieValue = strEmpty;
2126
1879
  if (_doc) {
2127
- var theCookie = _doc[strCookie] || strEmpty$1;
1880
+ var theCookie = _doc[strCookie] || strEmpty;
2128
1881
  if (_parsedCookieValue !== theCookie) {
2129
1882
  _cookieCache = _extractParts(theCookie);
2130
1883
  _parsedCookieValue = theCookie;
2131
1884
  }
2132
- cookieValue = strTrim(_cookieCache[name] || strEmpty$1);
1885
+ cookieValue = strTrim(_cookieCache[name] || strEmpty);
2133
1886
  }
2134
1887
  return cookieValue;
2135
1888
  }
@@ -2163,519 +1916,26 @@
2163
1916
  return false;
2164
1917
  }
2165
1918
 
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";
1919
+ var validationError = "Extensions must provide callback to initialize";
2599
1920
  var strNotificationManager = "_notificationManager";
2600
- var strSdkUnloadingError = "SDK is still unloading...";
2601
- var strSdkNotInitialized = "SDK is not initialized";
2602
1921
  function _createPerfManager(core, notificationMgr) {
2603
1922
  return new PerfManager(notificationMgr);
2604
1923
  }
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
- }
2651
1924
  var BaseCore = /** @class */ (function () {
2652
1925
  function BaseCore() {
2653
- var _isInitialized;
1926
+ var _isInitialized = false;
2654
1927
  var _eventQueue;
1928
+ var _channelController;
2655
1929
  var _notificationManager;
2656
1930
  var _perfManager;
2657
- var _cfgPerfManager;
2658
1931
  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;
2672
1932
  dynamicProto(BaseCore, this, function (_self) {
2673
- _initDefaults();
1933
+ _self._extensions = new Array();
1934
+ _channelController = new ChannelController();
1935
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
1936
+ _eventQueue = [];
2674
1937
  _self.isInitialized = function () { return _isInitialized; };
2675
1938
  _self.initialize = function (config, extensions, logger, notificationManager) {
2676
- if (_isUnloading) {
2677
- throwError(strSdkUnloadingError);
2678
- }
2679
1939
  if (_self.isInitialized()) {
2680
1940
  throwError("Core should not be initialized more than once");
2681
1941
  }
@@ -2685,61 +1945,89 @@
2685
1945
  _notificationManager = notificationManager;
2686
1946
  _self[strNotificationManager] = notificationManager;
2687
1947
  _self.config = config || {};
2688
- _initDebugListener(config);
2689
- _initPerfManager(config);
1948
+ if (notificationManager && _self.config.disableDbgExt !== true) {
1949
+ notificationManager.addNotificationListener(getDebugListener(config));
1950
+ }
1951
+ if (_self.config.enablePerfMgr) {
1952
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
1953
+ }
2690
1954
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
2691
- _initExtConfig(config);
1955
+ var extConfig = getSetValue(config, strExtensionConfig);
1956
+ extConfig.NotificationManager = notificationManager;
2692
1957
  if (logger) {
2693
1958
  _self.logger = logger;
2694
1959
  }
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) {
1960
+ var allExtensions = [];
1961
+ allExtensions.push.apply(allExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
1962
+ allExtensions = sortPlugins(allExtensions);
1963
+ var coreExtensions = [];
1964
+ var extPriorities = {};
1965
+ arrForEach(allExtensions, function (ext) {
1966
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
1967
+ throwError(validationError);
1968
+ }
1969
+ var extPriority = ext.priority;
1970
+ var identifier = ext.identifier;
1971
+ if (ext && extPriority) {
1972
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
1973
+ logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
1974
+ }
1975
+ else {
1976
+ extPriorities[extPriority] = identifier;
1977
+ }
1978
+ }
1979
+ if (!extPriority || extPriority < _channelController.priority) {
1980
+ coreExtensions.push(ext);
1981
+ }
1982
+ });
1983
+ allExtensions.push(_channelController);
1984
+ coreExtensions.push(_channelController);
1985
+ allExtensions = sortPlugins(allExtensions);
1986
+ _self._extensions = allExtensions;
1987
+ initializePlugins(new ProcessTelemetryContext([_channelController], config, _self), allExtensions);
1988
+ initializePlugins(new ProcessTelemetryContext(coreExtensions, config, _self), allExtensions);
1989
+ _self._extensions = coreExtensions;
1990
+ if (_self.getTransmissionControls().length === 0) {
2700
1991
  throwError("No channels available");
2701
1992
  }
2702
1993
  _isInitialized = true;
2703
1994
  _self.releaseQueue();
2704
1995
  };
2705
1996
  _self.getTransmissionControls = function () {
2706
- var controls = [];
2707
- if (_channelQueue) {
2708
- arrForEach(_channelQueue, function (channels) {
2709
- controls.push(channels.queue);
2710
- });
2711
- }
2712
- return objFreeze(controls);
1997
+ return _channelController.getChannelControls();
2713
1998
  };
2714
1999
  _self.track = function (telemetryItem) {
2715
2000
  setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
2716
2001
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
2717
2002
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
2718
- if (!_isUnloading && _self.isInitialized()) {
2719
- _createTelCtx().processNext(telemetryItem);
2003
+ if (_self.isInitialized()) {
2004
+ _self.getProcessTelContext().processNext(telemetryItem);
2720
2005
  }
2721
2006
  else {
2722
2007
  _eventQueue.push(telemetryItem);
2723
2008
  }
2724
2009
  };
2725
- _self.getProcessTelContext = _createTelCtx;
2010
+ _self.getProcessTelContext = function () {
2011
+ var extensions = _self._extensions;
2012
+ var thePlugins = extensions;
2013
+ if (!extensions || extensions.length === 0) {
2014
+ thePlugins = [_channelController];
2015
+ }
2016
+ return new ProcessTelemetryContext(thePlugins, _self.config, _self);
2017
+ };
2726
2018
  _self.getNotifyMgr = function () {
2727
2019
  if (!_notificationManager) {
2728
- _notificationManager = _createDummyNotificationManager();
2020
+ _notificationManager = objCreateFn({
2021
+ addNotificationListener: function (listener) { },
2022
+ removeNotificationListener: function (listener) { },
2023
+ eventsSent: function (events) { },
2024
+ eventsDiscarded: function (events, reason) { },
2025
+ eventsSendRequest: function (sendReason, isAsync) { }
2026
+ });
2729
2027
  _self[strNotificationManager] = _notificationManager;
2730
2028
  }
2731
2029
  return _notificationManager;
2732
2030
  };
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
- };
2743
2031
  _self.getCookieMgr = function () {
2744
2032
  if (!_cookieManager) {
2745
2033
  _cookieManager = createCookieMgr(_self.config, _self.logger);
@@ -2748,397 +2036,94 @@
2748
2036
  };
2749
2037
  _self.setCookieMgr = function (cookieMgr) {
2750
2038
  _cookieManager = cookieMgr;
2751
- };
2752
- _self.getPerfMgr = function () {
2753
- if (!_perfManager && !_cfgPerfManager) {
2754
- if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
2755
- _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
2756
- }
2757
- }
2758
- return _perfManager || _cfgPerfManager || getGblPerfMgr();
2759
- };
2760
- _self.setPerfMgr = function (perfMgr) {
2761
- _perfManager = perfMgr;
2762
- };
2763
- _self.eventCnt = function () {
2764
- return _eventQueue.length;
2765
- };
2766
- _self.releaseQueue = function () {
2767
- if (_isInitialized && _eventQueue.length > 0) {
2768
- var eventQueue = _eventQueue;
2769
- _eventQueue = [];
2770
- arrForEach(eventQueue, function (event) {
2771
- _createTelCtx().processNext(event);
2772
- });
2773
- }
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);
2039
+ };
2040
+ _self.getPerfMgr = function () {
2041
+ if (!_perfManager) {
2042
+ if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
2043
+ _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
2044
+ }
3077
2045
  }
3078
- else {
3079
- throwError(message);
2046
+ return _perfManager || getGblPerfMgr();
2047
+ };
2048
+ _self.setPerfMgr = function (perfMgr) {
2049
+ _perfManager = perfMgr;
2050
+ };
2051
+ _self.eventCnt = function () {
2052
+ return _eventQueue.length;
2053
+ };
2054
+ _self.releaseQueue = function () {
2055
+ if (_eventQueue.length > 0) {
2056
+ arrForEach(_eventQueue, function (event) {
2057
+ _self.getProcessTelContext().processNext(event);
2058
+ });
2059
+ _eventQueue = [];
3080
2060
  }
3081
- }
2061
+ };
3082
2062
  });
3083
2063
  }
3084
2064
  return BaseCore;
3085
2065
  }());
3086
2066
 
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
- }
3103
2067
  var NotificationManager = /** @class */ (function () {
3104
2068
  function NotificationManager(config) {
3105
2069
  this.listeners = [];
3106
2070
  var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
3107
2071
  dynamicProto(NotificationManager, this, function (_self) {
3108
- _self[strAddNotificationListener] = function (listener) {
2072
+ _self.addNotificationListener = function (listener) {
3109
2073
  _self.listeners.push(listener);
3110
2074
  };
3111
- _self[strRemoveNotificationListener] = function (listener) {
2075
+ _self.removeNotificationListener = function (listener) {
3112
2076
  var index = arrIndexOf(_self.listeners, listener);
3113
2077
  while (index > -1) {
3114
2078
  _self.listeners.splice(index, 1);
3115
2079
  index = arrIndexOf(_self.listeners, listener);
3116
2080
  }
3117
2081
  };
3118
- _self[strEventsSent] = function (events) {
3119
- _runListeners(_self.listeners, strEventsSent, true, function (listener) {
3120
- listener[strEventsSent](events);
2082
+ _self.eventsSent = function (events) {
2083
+ arrForEach(_self.listeners, function (listener) {
2084
+ if (listener && listener.eventsSent) {
2085
+ setTimeout(function () { return listener.eventsSent(events); }, 0);
2086
+ }
3121
2087
  });
3122
2088
  };
3123
- _self[strEventsDiscarded] = function (events, reason) {
3124
- _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
3125
- listener[strEventsDiscarded](events, reason);
2089
+ _self.eventsDiscarded = function (events, reason) {
2090
+ arrForEach(_self.listeners, function (listener) {
2091
+ if (listener && listener.eventsDiscarded) {
2092
+ setTimeout(function () { return listener.eventsDiscarded(events, reason); }, 0);
2093
+ }
3126
2094
  });
3127
2095
  };
3128
- _self[strEventsSendRequest] = function (sendReason, isAsync) {
3129
- _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
3130
- listener[strEventsSendRequest](sendReason, isAsync);
2096
+ _self.eventsSendRequest = function (sendReason, isAsync) {
2097
+ arrForEach(_self.listeners, function (listener) {
2098
+ if (listener && listener.eventsSendRequest) {
2099
+ if (isAsync) {
2100
+ setTimeout(function () { return listener.eventsSendRequest(sendReason, isAsync); }, 0);
2101
+ }
2102
+ else {
2103
+ try {
2104
+ listener.eventsSendRequest(sendReason, isAsync);
2105
+ }
2106
+ catch (e) {
2107
+ }
2108
+ }
2109
+ }
3131
2110
  });
3132
2111
  };
3133
- _self[strPerfEvent] = function (perfEvent) {
2112
+ _self.perfEvent = function (perfEvent) {
3134
2113
  if (perfEvent) {
3135
2114
  if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
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);
2115
+ arrForEach(_self.listeners, function (listener) {
2116
+ if (listener && listener.perfEvent) {
2117
+ if (perfEvent.isAsync) {
2118
+ setTimeout(function () { return listener.perfEvent(perfEvent); }, 0);
2119
+ }
2120
+ else {
2121
+ try {
2122
+ listener.perfEvent(perfEvent);
2123
+ }
2124
+ catch (e) {
2125
+ }
2126
+ }
3142
2127
  }
3143
2128
  });
3144
2129
  }
@@ -3153,6 +2138,7 @@
3153
2138
  __extendsFn(AppInsightsCore, _super);
3154
2139
  function AppInsightsCore() {
3155
2140
  var _this = _super.call(this) || this;
2141
+ var _internalLogPoller = 0;
3156
2142
  dynamicProto(AppInsightsCore, _this, function (_self, _base) {
3157
2143
  _self.initialize = function (config, extensions, logger, notificationManager) {
3158
2144
  _base.initialize(config, extensions, logger || new DiagnosticLogger(config), notificationManager || new NotificationManager(config));
@@ -3167,6 +2153,48 @@
3167
2153
  _base.track(telemetryItem);
3168
2154
  }, function () { return ({ item: telemetryItem }); }, !(telemetryItem.sync));
3169
2155
  };
2156
+ _self.addNotificationListener = function (listener) {
2157
+ var manager = _self.getNotifyMgr();
2158
+ if (manager) {
2159
+ manager.addNotificationListener(listener);
2160
+ }
2161
+ };
2162
+ _self.removeNotificationListener = function (listener) {
2163
+ var manager = _self.getNotifyMgr();
2164
+ if (manager) {
2165
+ manager.removeNotificationListener(listener);
2166
+ }
2167
+ };
2168
+ _self.pollInternalLogs = function (eventName) {
2169
+ var interval = _self.config.diagnosticLogInterval;
2170
+ if (!interval || !(interval > 0)) {
2171
+ interval = 10000;
2172
+ }
2173
+ if (_internalLogPoller) {
2174
+ _self.stopPollingInternalLogs();
2175
+ }
2176
+ _internalLogPoller = setInterval(function () {
2177
+ var queue = _self.logger ? _self.logger.queue : [];
2178
+ arrForEach(queue, function (logMessage) {
2179
+ var item = {
2180
+ name: eventName ? eventName : "InternalMessageId: " + logMessage.messageId,
2181
+ iKey: _self.config.instrumentationKey,
2182
+ time: toISOString(new Date()),
2183
+ baseType: _InternalLogMessage.dataType,
2184
+ baseData: { message: logMessage.message }
2185
+ };
2186
+ _self.track(item);
2187
+ });
2188
+ queue.length = 0;
2189
+ }, interval);
2190
+ return _internalLogPoller;
2191
+ };
2192
+ _self.stopPollingInternalLogs = function () {
2193
+ if (!_internalLogPoller)
2194
+ return;
2195
+ clearInterval(_internalLogPoller);
2196
+ _internalLogPoller = 0;
2197
+ };
3170
2198
  function _validateTelemetryItem(telemetryItem) {
3171
2199
  if (isNullOrUndefined(telemetryItem.name)) {
3172
2200
  _notifyInvalidEvent(telemetryItem);
@@ -3185,192 +2213,86 @@
3185
2213
  return AppInsightsCore;
3186
2214
  }(BaseCore));
3187
2215
 
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
- }
2216
+ var UInt32Mask = 0x100000000;
2217
+ var MaxUInt32 = 0xffffffff;
2218
+ var _mwcSeeded = false;
2219
+ var _mwcW = 123456789;
2220
+ var _mwcZ = 987654321;
2221
+ function _mwcSeed(seedValue) {
2222
+ if (seedValue < 0) {
2223
+ seedValue >>>= 0;
3231
2224
  }
3232
- var parsedEvent = (eventNamespace.exec(eventName || "") || []);
3233
- return {
3234
- type: parsedEvent[1],
3235
- ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
3236
- };
2225
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
2226
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
2227
+ _mwcSeeded = true;
3237
2228
  }
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] = [];
2229
+ function _autoSeedMwc() {
2230
+ try {
2231
+ var now = dateNow() & 0x7fffffff;
2232
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
3244
2233
  }
3245
- return registeredEvents;
3246
- }
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
- }
2234
+ catch (e) {
3255
2235
  }
3256
2236
  }
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
- }
2237
+ function randomValue(maxValue) {
2238
+ if (maxValue > 0) {
2239
+ return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
3268
2240
  }
3269
- return result;
2241
+ return 0;
3270
2242
  }
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
- }
3282
- }
2243
+ function random32(signed) {
2244
+ var value;
2245
+ var c = getCrypto() || getMsCrypto();
2246
+ if (c && c.getRandomValues) {
2247
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
3283
2248
  }
3284
- }
3285
- function _unregisterEvents(target, evtName, unRegFn) {
3286
- if (evtName.type) {
3287
- _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
2249
+ else if (isIE()) {
2250
+ if (!_mwcSeeded) {
2251
+ _autoSeedMwc();
2252
+ }
2253
+ value = mwcRandom32() & MaxUInt32;
3288
2254
  }
3289
2255
  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
- }
2256
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
2257
+ }
2258
+ if (!signed) {
2259
+ value >>>= 0;
3297
2260
  }
2261
+ return value;
3298
2262
  }
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(".");
2263
+ function mwcRandomSeed(value) {
2264
+ if (!value) {
2265
+ _autoSeedMwc();
3309
2266
  }
3310
2267
  else {
3311
- newNamespaces = theNamespace;
3312
- }
3313
- return newNamespaces;
3314
- }
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
- }
2268
+ _mwcSeed(value);
3334
2269
  }
3335
- return result;
3336
2270
  }
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
- }
2271
+ function mwcRandom32(signed) {
2272
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
2273
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
2274
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
2275
+ if (!signed) {
2276
+ value >>>= 0;
3356
2277
  }
2278
+ return value;
3357
2279
  }
3358
- function addEventHandler(eventName, callback, evtNamespace) {
2280
+
2281
+ var _cookieMgrs = null;
2282
+ var _canUseCookies;
2283
+ function addEventHandler(eventName, callback) {
3359
2284
  var result = false;
3360
2285
  var w = getWindow();
3361
2286
  if (w) {
3362
- result = eventOn(w, eventName, callback, evtNamespace);
3363
- result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
2287
+ result = attachEvent(w, eventName, callback);
2288
+ result = attachEvent(w["body"], eventName, callback) || result;
3364
2289
  }
3365
2290
  var doc = getDocument();
3366
2291
  if (doc) {
3367
- result = eventOn(doc, eventName, callback, evtNamespace) || result;
2292
+ result = attachEvent(doc, eventName, callback) || result;
3368
2293
  }
3369
2294
  return result;
3370
2295
  }
3371
-
3372
- var _cookieMgrs = null;
3373
- var _canUseCookies;
3374
2296
  function newGuid() {
3375
2297
  function randomHexDigit() {
3376
2298
  return randomValue(15);
@@ -3387,9 +2309,26 @@
3387
2309
  }
3388
2310
  return dateNow();
3389
2311
  }
2312
+ function newId(maxLength) {
2313
+ if (maxLength === void 0) { maxLength = 22; }
2314
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2315
+ var number = random32() >>> 0;
2316
+ var chars = 0;
2317
+ var result = "";
2318
+ while (result.length < maxLength) {
2319
+ chars++;
2320
+ result += base64chars.charAt(number & 0x3F);
2321
+ number >>>= 6;
2322
+ if (chars === 5) {
2323
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
2324
+ chars = 0;
2325
+ }
2326
+ }
2327
+ return result;
2328
+ }
3390
2329
  function generateW3CId() {
3391
2330
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
3392
- var oct = strEmpty$1, tmp;
2331
+ var oct = "", tmp;
3393
2332
  for (var a = 0; a < 4; a++) {
3394
2333
  tmp = random32();
3395
2334
  oct +=
@@ -3472,95 +2411,6 @@
3472
2411
  _legacyCookieMgr().setEnabled(false);
3473
2412
  }
3474
2413
 
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
-
3564
2414
  var RequestHeaders = {
3565
2415
  requestContextHeader: "Request-Context",
3566
2416
  requestContextTargetKey: "appId",
@@ -3593,7 +2443,7 @@
3593
2443
  name = strTrim(name.toString());
3594
2444
  if (name.length > 150 ) {
3595
2445
  nameTrunc = name.substring(0, 150 );
3596
- _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2446
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3597
2447
  }
3598
2448
  }
3599
2449
  return nameTrunc || name;
@@ -3606,7 +2456,7 @@
3606
2456
  value = strTrim(value);
3607
2457
  if (value.toString().length > maxLength) {
3608
2458
  valueTrunc = value.toString().substring(0, maxLength);
3609
- _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2459
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3610
2460
  }
3611
2461
  }
3612
2462
  return valueTrunc || value;
@@ -3619,7 +2469,7 @@
3619
2469
  if (message) {
3620
2470
  if (message.length > 32768 ) {
3621
2471
  messageTrunc = message.substring(0, 32768 );
3622
- _throwInternal(logger, 2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
2472
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3623
2473
  }
3624
2474
  }
3625
2475
  return messageTrunc || message;
@@ -3630,7 +2480,7 @@
3630
2480
  var value = "" + exception;
3631
2481
  if (value.length > 32768 ) {
3632
2482
  exceptionTrunc = value.substring(0, 32768 );
3633
- _throwInternal(logger, 2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
2483
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3634
2484
  }
3635
2485
  }
3636
2486
  return exceptionTrunc || exception;
@@ -3644,7 +2494,7 @@
3644
2494
  value = getJSON().stringify(value);
3645
2495
  }
3646
2496
  catch (e) {
3647
- _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2497
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3648
2498
  }
3649
2499
  }
3650
2500
  value = dataSanitizeString(logger, value, 8192 );
@@ -3675,7 +2525,7 @@
3675
2525
  input = strTrim(input);
3676
2526
  if (input.length > maxLength) {
3677
2527
  inputTrunc = input.substring(0, maxLength);
3678
- _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2528
+ logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3679
2529
  }
3680
2530
  }
3681
2531
  return inputTrunc || input;
@@ -3685,22 +2535,21 @@
3685
2535
  return s.substr(s.length - 3);
3686
2536
  }
3687
2537
 
3688
- var strEmpty = "";
3689
2538
  function msToTimeSpan(totalms) {
3690
2539
  if (isNaN(totalms) || totalms < 0) {
3691
2540
  totalms = 0;
3692
2541
  }
3693
2542
  totalms = Math.round(totalms);
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;
2543
+ var ms = "" + totalms % 1000;
2544
+ var sec = "" + Math.floor(totalms / 1000) % 60;
2545
+ var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
2546
+ var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
3698
2547
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
3699
2548
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
3700
2549
  sec = sec.length < 2 ? "0" + sec : sec;
3701
2550
  min = min.length < 2 ? "0" + min : min;
3702
2551
  hour = hour.length < 2 ? "0" + hour : hour;
3703
- return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
2552
+ return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
3704
2553
  }
3705
2554
 
3706
2555
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
@@ -3709,15 +2558,17 @@
3709
2558
  var HttpMethod = "http.method";
3710
2559
  var strNotSpecified = "not_specified";
3711
2560
 
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
- });
2561
+ var StorageType;
2562
+ (function (StorageType) {
2563
+ StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
2564
+ StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
2565
+ })(StorageType || (StorageType = {}));
2566
+ var DistributedTracingModes;
2567
+ (function (DistributedTracingModes) {
2568
+ DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
2569
+ DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
2570
+ DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
2571
+ })(DistributedTracingModes || (DistributedTracingModes = {}));
3721
2572
 
3722
2573
  var _canUseSessionStorage = undefined;
3723
2574
  function _getVerifiedStorageObject(storageType) {
@@ -3744,8 +2595,8 @@
3744
2595
  }
3745
2596
  return null;
3746
2597
  }
3747
- function utlCanUseSessionStorage(reset) {
3748
- if (reset || _canUseSessionStorage === undefined) {
2598
+ function utlCanUseSessionStorage() {
2599
+ if (_canUseSessionStorage === undefined) {
3749
2600
  _canUseSessionStorage = !!_getVerifiedStorageObject(StorageType.SessionStorage);
3750
2601
  }
3751
2602
  return _canUseSessionStorage;
@@ -3758,7 +2609,7 @@
3758
2609
  }
3759
2610
  catch (e) {
3760
2611
  _canUseSessionStorage = false;
3761
- _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
2612
+ logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3762
2613
  }
3763
2614
  }
3764
2615
  return null;
@@ -3772,7 +2623,7 @@
3772
2623
  }
3773
2624
  catch (e) {
3774
2625
  _canUseSessionStorage = false;
3775
- _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
2626
+ logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3776
2627
  }
3777
2628
  }
3778
2629
  return false;
@@ -3837,7 +2688,7 @@
3837
2688
  "https://dc-int.services.visualstudio.com/v2/track"
3838
2689
  ];
3839
2690
  function isInternalApplicationInsightsEndpoint(endpointUrl) {
3840
- return _internalEndpoints.indexOf(endpointUrl.toLowerCase()) !== -1;
2691
+ return arrIndexOf(_internalEndpoints, endpointUrl.toLowerCase()) !== -1;
3841
2692
  }
3842
2693
  function AjaxHelperParseDependencyPath(logger, absoluteUrl, method, commandName) {
3843
2694
  var target, name = commandName, data = commandName;
@@ -5058,7 +3909,7 @@
5058
3909
  }
5059
3910
  }
5060
3911
  var EnvelopeCreator = {
5061
- Version: "2.7.5-nightly.2203-03"
3912
+ Version: "2.7.5"
5062
3913
  };
5063
3914
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
5064
3915
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -5353,81 +4204,65 @@
5353
4204
  return Serializer;
5354
4205
  }());
5355
4206
 
5356
- function _disableEvents(target, evtNamespace) {
5357
- eventOff(target, null, null, evtNamespace);
5358
- }
5359
- function createOfflineListener(parentEvtNamespace) {
5360
- var _document = getDocument();
5361
- var _navigator = getNavigator();
5362
- var _isListening = false;
5363
- var _onlineStatus = true;
5364
- var _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
5365
- try {
5366
- if (_enableEvents(getWindow())) {
5367
- _isListening = true;
5368
- }
5369
- if (_document) {
5370
- var target = _document.body || _document;
5371
- if (target.ononline) {
5372
- if (_enableEvents(target)) {
5373
- _isListening = true;
4207
+ var OfflineListener = /** @class */ (function () {
4208
+ function OfflineListener() {
4209
+ var _window = getWindow();
4210
+ var _document = getDocument();
4211
+ var isListening = false;
4212
+ var _onlineStatus = true;
4213
+ dynamicProto(OfflineListener, this, function (_self) {
4214
+ try {
4215
+ if (_window) {
4216
+ if (attachEvent(_window, "online", _setOnline)) {
4217
+ attachEvent(_window, "offline", _setOffline);
4218
+ isListening = true;
4219
+ }
4220
+ }
4221
+ if (_document) {
4222
+ var target = _document.body || _document;
4223
+ if (!isUndefined(target.ononline)) {
4224
+ target.ononline = _setOnline;
4225
+ target.onoffline = _setOffline;
4226
+ isListening = true;
4227
+ }
4228
+ }
4229
+ if (isListening) {
4230
+ var _navigator = getNavigator();
4231
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
4232
+ _onlineStatus = _navigator.onLine;
4233
+ }
5374
4234
  }
5375
4235
  }
5376
- }
5377
- if (_isListening) {
5378
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
5379
- _onlineStatus = _navigator.onLine;
5380
- }
5381
- }
5382
- }
5383
- catch (e) {
5384
- _isListening = false;
5385
- }
5386
- function _enableEvents(target) {
5387
- var enabled = false;
5388
- if (target) {
5389
- enabled = eventOn(target, "online", _setOnline, _evtNamespace);
5390
- if (enabled) {
5391
- eventOn(target, "offline", _setOffline, _evtNamespace);
4236
+ catch (e) {
4237
+ isListening = false;
5392
4238
  }
5393
- }
5394
- return enabled;
5395
- }
5396
- function _setOnline() {
5397
- _onlineStatus = true;
5398
- }
5399
- function _setOffline() {
5400
- _onlineStatus = false;
5401
- }
5402
- function _isOnline() {
5403
- var result = true;
5404
- if (_isListening) {
5405
- result = _onlineStatus;
5406
- }
5407
- else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
5408
- result = _navigator.onLine;
5409
- }
5410
- return result;
5411
- }
5412
- function _unload() {
5413
- var win = getWindow();
5414
- if (win && _isListening) {
5415
- _disableEvents(win, _evtNamespace);
5416
- if (_document) {
5417
- var target = _document.body || _document;
5418
- if (!isUndefined(target.ononline)) {
5419
- _disableEvents(target, _evtNamespace);
4239
+ _self.isListening = isListening;
4240
+ _self.isOnline = function () {
4241
+ var result = true;
4242
+ var _navigator = getNavigator();
4243
+ if (isListening) {
4244
+ result = _onlineStatus;
5420
4245
  }
4246
+ else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
4247
+ result = _navigator.onLine;
4248
+ }
4249
+ return result;
4250
+ };
4251
+ _self.isOffline = function () {
4252
+ return !_self.isOnline();
4253
+ };
4254
+ function _setOnline() {
4255
+ _onlineStatus = true;
5421
4256
  }
5422
- _isListening = false;
5423
- }
4257
+ function _setOffline() {
4258
+ _onlineStatus = false;
4259
+ }
4260
+ });
5424
4261
  }
5425
- return {
5426
- isOnline: _isOnline,
5427
- isListening: function () { return _isListening; },
5428
- unload: _unload
5429
- };
5430
- }
4262
+ OfflineListener.Offline = new OfflineListener;
4263
+ return OfflineListener;
4264
+ }());
4265
+ var Offline = OfflineListener.Offline;
5431
4266
 
5432
4267
  var MIN_INPUT_LENGTH = 8;
5433
4268
  var HashCodeScoreGenerator = /** @class */ (function () {
@@ -5555,22 +4390,22 @@
5555
4390
  var _this = _super.call(this) || this;
5556
4391
  _this.priority = 1001;
5557
4392
  _this.identifier = BreezeChannelIdentifier;
5558
- _this._senderConfig = _getDefaultAppInsightsChannelConfig();
5559
4393
  var _consecutiveErrors;
5560
4394
  var _retryAt;
5561
4395
  var _lastSend;
5562
- var _paused;
4396
+ var _paused = false;
5563
4397
  var _timeoutHandle;
5564
4398
  var _serializer;
5565
4399
  var _stamp_specific_redirects;
5566
- var _headers;
4400
+ var _headers = {};
5567
4401
  var _syncFetchPayload = 0;
5568
4402
  var _fallbackSender;
5569
4403
  var _syncUnloadSender;
5570
- var _offlineListener;
5571
- var _evtNamespace;
4404
+ _this._senderConfig = _getDefaultAppInsightsChannelConfig();
5572
4405
  dynamicProto(Sender, _this, function (_self, _base) {
5573
- _initDefaults();
4406
+ function _notImplemented() {
4407
+ throwError("Method not implemented.");
4408
+ }
5574
4409
  _self.pause = function () {
5575
4410
  _clearScheduledTimer();
5576
4411
  _paused = true;
@@ -5585,15 +4420,14 @@
5585
4420
  _setupTimer();
5586
4421
  }
5587
4422
  };
5588
- _self.flush = function (isAsync, callBack, sendReason) {
5589
- if (isAsync === void 0) { isAsync = true; }
4423
+ _self.flush = function () {
5590
4424
  if (!_paused) {
5591
4425
  _clearScheduledTimer();
5592
4426
  try {
5593
- _self.triggerSend(isAsync, null, sendReason || 1 );
4427
+ _self.triggerSend(true, null, 1 );
5594
4428
  }
5595
4429
  catch (e) {
5596
- _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4430
+ _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5597
4431
  }
5598
4432
  }
5599
4433
  };
@@ -5604,7 +4438,7 @@
5604
4438
  _self.triggerSend(true, _doUnloadSend, 2 );
5605
4439
  }
5606
4440
  catch (e) {
5607
- _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) });
4441
+ _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) });
5608
4442
  }
5609
4443
  }
5610
4444
  else {
@@ -5612,13 +4446,11 @@
5612
4446
  }
5613
4447
  }
5614
4448
  };
4449
+ _self.teardown = _notImplemented;
5615
4450
  _self.addHeader = function (name, value) {
5616
4451
  _headers[name] = value;
5617
4452
  };
5618
4453
  _self.initialize = function (config, core, extensions, pluginChain) {
5619
- if (_self.isInitialized()) {
5620
- _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender is already initialized");
5621
- }
5622
4454
  _base.initialize(config, core, extensions, pluginChain);
5623
4455
  var ctx = _self._getTelCtx();
5624
4456
  var identifier = _self.identifier;
@@ -5629,8 +4461,6 @@
5629
4461
  _self._sender = null;
5630
4462
  _stamp_specific_redirects = 0;
5631
4463
  var diagLog = _self.diagLog();
5632
- _evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
5633
- _offlineListener = createOfflineListener(_evtNamespace);
5634
4464
  var defaultConfig = _getDefaultAppInsightsChannelConfig();
5635
4465
  objForEachKey(defaultConfig, function (field, value) {
5636
4466
  _self._senderConfig[field] = function () { return ctx.getConfig(identifier, field, value()); };
@@ -5639,7 +4469,7 @@
5639
4469
  ? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
5640
4470
  _self._sample = new Sample(_self._senderConfig.samplingPercentage(), diagLog);
5641
4471
  if (!_validateInstrumentationKey(config)) {
5642
- _throwInternal(diagLog, LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
4472
+ diagLog.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
5643
4473
  }
5644
4474
  if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders().length > 0) {
5645
4475
  arrForEach(_self._senderConfig.customHeaders(), function (customHeader) {
@@ -5685,22 +4515,22 @@
5685
4515
  return;
5686
4516
  }
5687
4517
  if (!telemetryItem) {
5688
- _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
4518
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
5689
4519
  return;
5690
4520
  }
5691
4521
  if (telemetryItem.baseData && !telemetryItem.baseType) {
5692
- _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
4522
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
5693
4523
  return;
5694
4524
  }
5695
4525
  if (!telemetryItem.baseType) {
5696
4526
  telemetryItem.baseType = "EventData";
5697
4527
  }
5698
4528
  if (!_self._sender) {
5699
- _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
4529
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
5700
4530
  return;
5701
4531
  }
5702
4532
  if (!_isSampledIn(telemetryItem)) {
5703
- _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
4533
+ itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
5704
4534
  return;
5705
4535
  }
5706
4536
  else {
@@ -5710,7 +4540,7 @@
5710
4540
  var defaultEnvelopeIkey = telemetryItem.iKey || _self._senderConfig.instrumentationKey();
5711
4541
  var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, itemCtx.diagLog(), convertUndefined);
5712
4542
  if (!aiEnvelope_1) {
5713
- _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
4543
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
5714
4544
  return;
5715
4545
  }
5716
4546
  var doNotSendItem_1 = false;
@@ -5723,7 +4553,7 @@
5723
4553
  }
5724
4554
  }
5725
4555
  catch (e) {
5726
- _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
4556
+ itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
5727
4557
  }
5728
4558
  });
5729
4559
  delete telemetryItem.tags[ProcessLegacy];
@@ -5741,7 +4571,7 @@
5741
4571
  _setupTimer();
5742
4572
  }
5743
4573
  catch (e) {
5744
- _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) });
4574
+ 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) });
5745
4575
  }
5746
4576
  _self.processNext(telemetryItem, itemCtx);
5747
4577
  };
@@ -5776,18 +4606,13 @@
5776
4606
  catch (e) {
5777
4607
  var ieVer = getIEVersion();
5778
4608
  if (!ieVer || ieVer > 9) {
5779
- _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
4609
+ _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
5780
4610
  }
5781
4611
  }
5782
4612
  }
5783
4613
  };
5784
- _self._doTeardown = function (unloadCtx, unloadState) {
5785
- _self.onunloadFlush();
5786
- _offlineListener.unload();
5787
- _initDefaults();
5788
- };
5789
4614
  _self._onError = function (payload, message, event) {
5790
- _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
4615
+ _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
5791
4616
  _self._buffer.clearSent(payload);
5792
4617
  };
5793
4618
  _self._onPartialSuccess = function (payload, results) {
@@ -5812,7 +4637,7 @@
5812
4637
  }
5813
4638
  if (retry.length > 0) {
5814
4639
  _resendPayload(retry);
5815
- _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
4640
+ _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
5816
4641
  "Delivered: " + payload.length + ", Failed: " + failed.length +
5817
4642
  ". Will retry to send " + retry.length + " our of " + results.itemsReceived + " items");
5818
4643
  }
@@ -5857,18 +4682,18 @@
5857
4682
  }
5858
4683
  if (!_self._senderConfig.isRetryDisabled() && _isRetriable(status)) {
5859
4684
  _resendPayload(payload);
5860
- _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
4685
+ _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
5861
4686
  "Response code " + status + ". Will retry to send " + payload.length + " items.");
5862
4687
  }
5863
4688
  else {
5864
4689
  _self._onError(payload, errorMessage);
5865
4690
  }
5866
4691
  }
5867
- else if (_offlineListener && !_offlineListener.isOnline()) {
4692
+ else if (Offline.isOffline()) {
5868
4693
  if (!_self._senderConfig.isRetryDisabled()) {
5869
4694
  var offlineBackOffMultiplier = 10;
5870
4695
  _resendPayload(payload, offlineBackOffMultiplier);
5871
- _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."));
4696
+ _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."));
5872
4697
  }
5873
4698
  }
5874
4699
  else {
@@ -5935,8 +4760,8 @@
5935
4760
  }
5936
4761
  }
5937
4762
  if (droppedPayload.length > 0) {
5938
- _fallbackSender && _fallbackSender(droppedPayload, true);
5939
- _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
4763
+ _fallbackSender(droppedPayload, true);
4764
+ _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
5940
4765
  }
5941
4766
  }
5942
4767
  }
@@ -5977,7 +4802,7 @@
5977
4802
  }
5978
4803
  else {
5979
4804
  _fallbackSender && _fallbackSender(payload, true);
5980
- _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
4805
+ _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
5981
4806
  }
5982
4807
  }
5983
4808
  }
@@ -6068,7 +4893,7 @@
6068
4893
  }
6069
4894
  }
6070
4895
  catch (e) {
6071
- _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
4896
+ _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
6072
4897
  response: response
6073
4898
  });
6074
4899
  }
@@ -6139,7 +4964,7 @@
6139
4964
  xdr.onerror = function (event) { return _self._onError(payload, _formatErrorMessageXdr(xdr), event); };
6140
4965
  var hostingProtocol = _window && _window.location && _window.location.protocol || "";
6141
4966
  if (_self._senderConfig.endpointUrl().lastIndexOf(hostingProtocol, 0) !== 0) {
6142
- _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
4967
+ _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
6143
4968
  "Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.");
6144
4969
  buffer.clear();
6145
4970
  return;
@@ -6170,7 +4995,7 @@
6170
4995
  manager.eventsSendRequest(sendRequest, isAsync);
6171
4996
  }
6172
4997
  catch (e) {
6173
- _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
4998
+ _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
6174
4999
  }
6175
5000
  }
6176
5001
  }
@@ -6183,25 +5008,6 @@
6183
5008
  var regexp = new RegExp(UUID_Regex);
6184
5009
  return regexp.test(config.instrumentationKey);
6185
5010
  }
6186
- function _initDefaults() {
6187
- _self._sender = null;
6188
- _self._buffer = null;
6189
- _self._appId = null;
6190
- _self._sample = null;
6191
- _headers = {};
6192
- _offlineListener = null;
6193
- _consecutiveErrors = 0;
6194
- _retryAt = null;
6195
- _lastSend = null;
6196
- _paused = false;
6197
- _timeoutHandle = null;
6198
- _serializer = null;
6199
- _stamp_specific_redirects = 0;
6200
- _syncFetchPayload = 0;
6201
- _fallbackSender = null;
6202
- _syncUnloadSender = null;
6203
- _evtNamespace = null;
6204
- }
6205
5011
  });
6206
5012
  return _this;
6207
5013
  }
@@ -6221,41 +5027,46 @@
6221
5027
 
6222
5028
  var ApplicationInsights = /** @class */ (function () {
6223
5029
  function ApplicationInsights(config) {
6224
- var core = new AppInsightsCore();
6225
5030
  if (isNullOrUndefined(config) ||
6226
5031
  isNullOrUndefined(config.instrumentationKey)) {
6227
5032
  throwError("Invalid input configuration");
6228
5033
  }
6229
- dynamicProto(ApplicationInsights, this, function (_self) {
6230
- _self.config = config;
6231
- _self.getSKUDefaults();
6232
- _initialize();
6233
- _self.initialize = _initialize;
6234
- _self.getSKUDefaults = function () {
6235
- _self.config.diagnosticLogInterval =
6236
- _self.config.diagnosticLogInterval && _self.config.diagnosticLogInterval > 0 ? _self.config.diagnosticLogInterval : 10000;
6237
- };
6238
- proxyFunctions(_self, core, [
6239
- "track",
6240
- "flush",
6241
- "pollInternalLogs",
6242
- "stopPollingInternalLogs",
6243
- "unload",
6244
- "getPlugin",
6245
- "addPlugin",
6246
- "evtNamespace",
6247
- "addUnloadCb"
6248
- ]);
6249
- function _initialize() {
6250
- var extensions = [];
6251
- var appInsightsChannel = new Sender();
6252
- extensions.push(appInsightsChannel);
6253
- core.initialize(this.config, extensions);
6254
- appInsightsChannel.initialize(this.config, core, extensions);
6255
- core.pollInternalLogs();
6256
- }
5034
+ this.config = config;
5035
+ this.getSKUDefaults();
5036
+ this.initialize();
5037
+ }
5038
+ ApplicationInsights.prototype.initialize = function () {
5039
+ this.core = new AppInsightsCore();
5040
+ var extensions = [];
5041
+ var appInsightsChannel = new Sender();
5042
+ extensions.push(appInsightsChannel);
5043
+ this.core.initialize(this.config, extensions);
5044
+ appInsightsChannel.initialize(this.config, this.core, extensions);
5045
+ this.pollInternalLogs();
5046
+ };
5047
+ ApplicationInsights.prototype.track = function (item) {
5048
+ this.core.track(item);
5049
+ };
5050
+ ApplicationInsights.prototype.flush = function (async) {
5051
+ if (async === void 0) { async = true; }
5052
+ arrForEach(this.core.getTransmissionControls(), function (controls) {
5053
+ arrForEach(controls, function (plugin) {
5054
+ async
5055
+ ? plugin.flush()
5056
+ : plugin.triggerSend(async, null, 1 );
5057
+ });
6257
5058
  });
6258
- }
5059
+ };
5060
+ ApplicationInsights.prototype.pollInternalLogs = function () {
5061
+ this.core.pollInternalLogs();
5062
+ };
5063
+ ApplicationInsights.prototype.stopPollingInternalLogs = function () {
5064
+ this.core.stopPollingInternalLogs();
5065
+ };
5066
+ ApplicationInsights.prototype.getSKUDefaults = function () {
5067
+ this.config.diagnosticLogInterval =
5068
+ this.config.diagnosticLogInterval && this.config.diagnosticLogInterval > 0 ? this.config.diagnosticLogInterval : 10000;
5069
+ };
6259
5070
  return ApplicationInsights;
6260
5071
  }());
6261
5072
 
@@ -6263,13 +5074,8 @@
6263
5074
  exports.ApplicationInsights = ApplicationInsights;
6264
5075
  exports.CoreUtils = CoreUtils;
6265
5076
  exports.Sender = Sender;
6266
- exports._InternalMessageId = _InternalMessageId;
6267
- exports.arrForEach = arrForEach;
6268
- exports.isNullOrUndefined = isNullOrUndefined;
6269
- exports.proxyFunctions = proxyFunctions;
6270
- exports.throwError = throwError;
6271
5077
 
6272
5078
  (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 });
6273
5079
 
6274
5080
  }));
6275
- //# sourceMappingURL=aib.2.7.5-nightly.2203-03.js.map
5081
+ //# sourceMappingURL=aib.2.7.5.js.map