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

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