@microsoft/1ds-core-js 3.1.11 → 3.2.2

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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/bundle/{ms.core-3.1.11.gbl.js → ms.core-3.2.2.gbl.js} +2500 -1253
  3. package/bundle/ms.core-3.2.2.gbl.js.map +1 -0
  4. package/bundle/ms.core-3.2.2.gbl.min.js +7 -0
  5. package/bundle/ms.core-3.2.2.gbl.min.js.map +1 -0
  6. package/bundle/ms.core-3.2.2.integrity.json +46 -0
  7. package/bundle/{ms.core-3.1.11.js → ms.core-3.2.2.js} +2500 -1253
  8. package/bundle/ms.core-3.2.2.js.map +1 -0
  9. package/bundle/ms.core-3.2.2.min.js +7 -0
  10. package/bundle/ms.core-3.2.2.min.js.map +1 -0
  11. package/bundle/ms.core.gbl.js +2499 -1252
  12. package/bundle/ms.core.gbl.js.map +1 -1
  13. package/bundle/ms.core.gbl.min.js +2 -2
  14. package/bundle/ms.core.gbl.min.js.map +1 -1
  15. package/bundle/ms.core.integrity.json +17 -17
  16. package/bundle/ms.core.js +2499 -1252
  17. package/bundle/ms.core.js.map +1 -1
  18. package/bundle/ms.core.min.js +2 -2
  19. package/bundle/ms.core.min.js.map +1 -1
  20. package/dist/ms.core.js +92 -55
  21. package/dist/ms.core.js.map +1 -1
  22. package/dist/ms.core.min.js +2 -2
  23. package/dist/ms.core.min.js.map +1 -1
  24. package/dist-esm/src/AppInsightsCore.js +5 -6
  25. package/dist-esm/src/AppInsightsCore.js.map +1 -1
  26. package/dist-esm/src/BaseCore.js +3 -4
  27. package/dist-esm/src/BaseCore.js.map +1 -1
  28. package/dist-esm/src/DataModels.js +1 -1
  29. package/dist-esm/src/ESPromise.js +1 -1
  30. package/dist-esm/src/ESPromiseScheduler.js +1 -1
  31. package/dist-esm/src/Enums.d.ts +174 -172
  32. package/dist-esm/src/Enums.js +63 -103
  33. package/dist-esm/src/Enums.js.map +1 -1
  34. package/dist-esm/src/Index.d.ts +4 -3
  35. package/dist-esm/src/Index.js +4 -6
  36. package/dist-esm/src/Index.js.map +1 -1
  37. package/dist-esm/src/Utils.d.ts +2 -2
  38. package/dist-esm/src/Utils.js +12 -13
  39. package/dist-esm/src/Utils.js.map +1 -1
  40. package/dist-esm/src/ValueSanitizer.js +1 -1
  41. package/package.json +4 -4
  42. package/src/AppInsightsCore.ts +6 -6
  43. package/src/BaseCore.ts +5 -5
  44. package/src/Enums.ts +155 -65
  45. package/src/Index.ts +14 -7
  46. package/src/Utils.ts +12 -12
  47. package/bundle/ms.core-3.1.11.gbl.js.map +0 -1
  48. package/bundle/ms.core-3.1.11.gbl.min.js +0 -7
  49. package/bundle/ms.core-3.1.11.gbl.min.js.map +0 -1
  50. package/bundle/ms.core-3.1.11.integrity.json +0 -46
  51. package/bundle/ms.core-3.1.11.js.map +0 -1
  52. package/bundle/ms.core-3.1.11.min.js +0 -7
  53. package/bundle/ms.core-3.1.11.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK Core, 3.1.11
2
+ * 1DS JS SDK Core, 3.2.2
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -100,351 +100,27 @@
100
100
 
101
101
  var MinChannelPriorty = 100;
102
102
 
103
- var EventsDiscardedReason = {
104
- Unknown: 0,
105
- NonRetryableStatus: 1,
106
- InvalidEvent: 2,
107
- SizeLimitExceeded: 3,
108
- KillSwitch: 4,
109
- QueueFull: 5
110
- };
111
-
112
- /*!
113
- * Microsoft Dynamic Proto Utility, 1.1.4
114
- * Copyright (c) Microsoft and contributors. All rights reserved.
115
- */
116
- var Constructor = 'constructor';
117
- var Prototype = 'prototype';
118
- var strFunction = 'function';
119
- var DynInstFuncTable = '_dynInstFuncs';
120
- var DynProxyTag = '_isDynProxy';
121
- var DynClassName = '_dynClass';
122
- var DynClassNamePrefix = '_dynCls$';
123
- var DynInstChkTag = '_dynInstChk';
124
- var DynAllowInstChkTag = DynInstChkTag;
125
- var DynProtoDefaultOptions = '_dfOpts';
126
- var UnknownValue = '_unknown_';
127
- var str__Proto = "__proto__";
128
- var strUseBaseInst = 'useBaseInst';
129
- var strSetInstFuncs = 'setInstFuncs';
130
- var Obj = Object;
131
- var _objGetPrototypeOf = Obj["getPrototypeOf"];
132
- var _dynamicNames = 0;
133
- function _hasOwnProperty(obj, prop) {
134
- return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
135
- }
136
- function _isObjectOrArrayPrototype(target) {
137
- return target && (target === Obj[Prototype] || target === Array[Prototype]);
138
- }
139
- function _isObjectArrayOrFunctionPrototype(target) {
140
- return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
141
- }
142
- function _getObjProto(target) {
143
- if (target) {
144
- if (_objGetPrototypeOf) {
145
- return _objGetPrototypeOf(target);
146
- }
147
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
148
- if (newProto) {
149
- return newProto;
150
- }
151
- }
152
- return null;
153
- }
154
- function _forEachProp(target, func) {
155
- var props = [];
156
- var getOwnProps = Obj["getOwnPropertyNames"];
157
- if (getOwnProps) {
158
- props = getOwnProps(target);
159
- }
160
- else {
161
- for (var name_1 in target) {
162
- if (typeof name_1 === "string" && _hasOwnProperty(target, name_1)) {
163
- props.push(name_1);
164
- }
165
- }
166
- }
167
- if (props && props.length > 0) {
168
- for (var lp = 0; lp < props.length; lp++) {
169
- func(props[lp]);
170
- }
171
- }
172
- }
173
- function _isDynamicCandidate(target, funcName, skipOwn) {
174
- return (funcName !== Constructor && typeof target[funcName] === strFunction && (skipOwn || _hasOwnProperty(target, funcName)));
175
- }
176
- function _throwTypeError(message) {
177
- throw new TypeError("DynamicProto: " + message);
178
- }
179
- function _getInstanceFuncs(thisTarget) {
180
- var instFuncs = {};
181
- _forEachProp(thisTarget, function (name) {
182
- if (!instFuncs[name] && _isDynamicCandidate(thisTarget, name, false)) {
183
- instFuncs[name] = thisTarget[name];
184
- }
185
- });
186
- return instFuncs;
187
- }
188
- function _hasVisited(values, value) {
189
- for (var lp = values.length - 1; lp >= 0; lp--) {
190
- if (values[lp] === value) {
191
- return true;
192
- }
193
- }
194
- return false;
195
- }
196
- function _getBaseFuncs(classProto, thisTarget, instFuncs, useBaseInst) {
197
- function _instFuncProxy(target, funcHost, funcName) {
198
- var theFunc = funcHost[funcName];
199
- if (theFunc[DynProxyTag] && useBaseInst) {
200
- var instFuncTable = target[DynInstFuncTable] || {};
201
- if (instFuncTable[DynAllowInstChkTag] !== false) {
202
- theFunc = (instFuncTable[funcHost[DynClassName]] || {})[funcName] || theFunc;
203
- }
204
- }
205
- return function () {
206
- return theFunc.apply(target, arguments);
207
- };
208
- }
209
- var baseFuncs = {};
210
- _forEachProp(instFuncs, function (name) {
211
- baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
212
- });
213
- var baseProto = _getObjProto(classProto);
214
- var visited = [];
215
- while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
216
- _forEachProp(baseProto, function (name) {
217
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
218
- baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
219
- }
220
- });
221
- visited.push(baseProto);
222
- baseProto = _getObjProto(baseProto);
223
- }
224
- return baseFuncs;
225
- }
226
- function _getInstFunc(target, funcName, proto, currentDynProtoProxy) {
227
- var instFunc = null;
228
- if (target && _hasOwnProperty(proto, DynClassName)) {
229
- var instFuncTable = target[DynInstFuncTable] || {};
230
- instFunc = (instFuncTable[proto[DynClassName]] || {})[funcName];
231
- if (!instFunc) {
232
- _throwTypeError("Missing [" + funcName + "] " + strFunction);
233
- }
234
- if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
235
- var canAddInst = !_hasOwnProperty(target, funcName);
236
- var objProto = _getObjProto(target);
237
- var visited = [];
238
- while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
239
- var protoFunc = objProto[funcName];
240
- if (protoFunc) {
241
- canAddInst = (protoFunc === currentDynProtoProxy);
242
- break;
243
- }
244
- visited.push(objProto);
245
- objProto = _getObjProto(objProto);
246
- }
247
- try {
248
- if (canAddInst) {
249
- target[funcName] = instFunc;
250
- }
251
- instFunc[DynInstChkTag] = 1;
252
- }
253
- catch (e) {
254
- instFuncTable[DynAllowInstChkTag] = false;
255
- }
256
- }
257
- }
258
- return instFunc;
259
- }
260
- function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
261
- var protoFunc = proto[funcName];
262
- if (protoFunc === currentDynProtoProxy) {
263
- protoFunc = _getObjProto(proto)[funcName];
264
- }
265
- if (typeof protoFunc !== strFunction) {
266
- _throwTypeError("[" + funcName + "] is not a " + strFunction);
267
- }
268
- return protoFunc;
269
- }
270
- function _populatePrototype(proto, className, target, baseInstFuncs, setInstanceFunc) {
271
- function _createDynamicPrototype(proto, funcName) {
272
- var dynProtoProxy = function () {
273
- var instFunc = _getInstFunc(this, funcName, proto, dynProtoProxy) || _getProtoFunc(funcName, proto, dynProtoProxy);
274
- return instFunc.apply(this, arguments);
275
- };
276
- dynProtoProxy[DynProxyTag] = 1;
277
- return dynProtoProxy;
278
- }
279
- if (!_isObjectOrArrayPrototype(proto)) {
280
- var instFuncTable = target[DynInstFuncTable] = target[DynInstFuncTable] || {};
281
- var instFuncs_1 = instFuncTable[className] = (instFuncTable[className] || {});
282
- if (instFuncTable[DynAllowInstChkTag] !== false) {
283
- instFuncTable[DynAllowInstChkTag] = !!setInstanceFunc;
284
- }
285
- _forEachProp(target, function (name) {
286
- if (_isDynamicCandidate(target, name, false) && target[name] !== baseInstFuncs[name]) {
287
- instFuncs_1[name] = target[name];
288
- delete target[name];
289
- if (!_hasOwnProperty(proto, name) || (proto[name] && !proto[name][DynProxyTag])) {
290
- proto[name] = _createDynamicPrototype(proto, name);
291
- }
292
- }
293
- });
294
- }
295
- }
296
- function _checkPrototype(classProto, thisTarget) {
297
- if (_objGetPrototypeOf) {
298
- var visited = [];
299
- var thisProto = _getObjProto(thisTarget);
300
- while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
301
- if (thisProto === classProto) {
302
- return true;
303
- }
304
- visited.push(thisProto);
305
- thisProto = _getObjProto(thisProto);
306
- }
307
- }
308
- return false;
309
- }
310
- function _getObjName(target, unknownValue) {
311
- if (_hasOwnProperty(target, Prototype)) {
312
- return target.name || unknownValue || UnknownValue;
313
- }
314
- return (((target || {})[Constructor]) || {}).name || unknownValue || UnknownValue;
315
- }
316
- function dynamicProto(theClass, target, delegateFunc, options) {
317
- if (!_hasOwnProperty(theClass, Prototype)) {
318
- _throwTypeError("theClass is an invalid class definition.");
319
- }
320
- var classProto = theClass[Prototype];
321
- if (!_checkPrototype(classProto, target)) {
322
- _throwTypeError("[" + _getObjName(theClass) + "] is not in class hierarchy of [" + _getObjName(target) + "]");
323
- }
324
- var className = null;
325
- if (_hasOwnProperty(classProto, DynClassName)) {
326
- className = classProto[DynClassName];
327
- }
328
- else {
329
- className = DynClassNamePrefix + _getObjName(theClass, "_") + "$" + _dynamicNames;
330
- _dynamicNames++;
331
- classProto[DynClassName] = className;
332
- }
333
- var perfOptions = dynamicProto[DynProtoDefaultOptions];
334
- var useBaseInst = !!perfOptions[strUseBaseInst];
335
- if (useBaseInst && options && options[strUseBaseInst] !== undefined) {
336
- useBaseInst = !!options[strUseBaseInst];
337
- }
338
- var instFuncs = _getInstanceFuncs(target);
339
- var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
340
- delegateFunc(target, baseFuncs);
341
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
342
- if (setInstanceFunc && options) {
343
- setInstanceFunc = !!options[strSetInstFuncs];
344
- }
345
- _populatePrototype(classProto, className, target, instFuncs, setInstanceFunc !== false);
346
- }
347
- var perfDefaults = {
348
- setInstFuncs: true,
349
- useBaseInst: true
350
- };
351
- dynamicProto[DynProtoDefaultOptions] = perfDefaults;
352
-
353
- exports.LoggingSeverity = void 0;
354
- (function (LoggingSeverity) {
355
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
356
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
357
- })(exports.LoggingSeverity || (exports.LoggingSeverity = {}));
358
- var _InternalMessageId = {
359
- BrowserDoesNotSupportLocalStorage: 0,
360
- BrowserCannotReadLocalStorage: 1,
361
- BrowserCannotReadSessionStorage: 2,
362
- BrowserCannotWriteLocalStorage: 3,
363
- BrowserCannotWriteSessionStorage: 4,
364
- BrowserFailedRemovalFromLocalStorage: 5,
365
- BrowserFailedRemovalFromSessionStorage: 6,
366
- CannotSendEmptyTelemetry: 7,
367
- ClientPerformanceMathError: 8,
368
- ErrorParsingAISessionCookie: 9,
369
- ErrorPVCalc: 10,
370
- ExceptionWhileLoggingError: 11,
371
- FailedAddingTelemetryToBuffer: 12,
372
- FailedMonitorAjaxAbort: 13,
373
- FailedMonitorAjaxDur: 14,
374
- FailedMonitorAjaxOpen: 15,
375
- FailedMonitorAjaxRSC: 16,
376
- FailedMonitorAjaxSend: 17,
377
- FailedMonitorAjaxGetCorrelationHeader: 18,
378
- FailedToAddHandlerForOnBeforeUnload: 19,
379
- FailedToSendQueuedTelemetry: 20,
380
- FailedToReportDataLoss: 21,
381
- FlushFailed: 22,
382
- MessageLimitPerPVExceeded: 23,
383
- MissingRequiredFieldSpecification: 24,
384
- NavigationTimingNotSupported: 25,
385
- OnError: 26,
386
- SessionRenewalDateIsZero: 27,
387
- SenderNotInitialized: 28,
388
- StartTrackEventFailed: 29,
389
- StopTrackEventFailed: 30,
390
- StartTrackFailed: 31,
391
- StopTrackFailed: 32,
392
- TelemetrySampledAndNotSent: 33,
393
- TrackEventFailed: 34,
394
- TrackExceptionFailed: 35,
395
- TrackMetricFailed: 36,
396
- TrackPVFailed: 37,
397
- TrackPVFailedCalc: 38,
398
- TrackTraceFailed: 39,
399
- TransmissionFailed: 40,
400
- FailedToSetStorageBuffer: 41,
401
- FailedToRestoreStorageBuffer: 42,
402
- InvalidBackendResponse: 43,
403
- FailedToFixDepricatedValues: 44,
404
- InvalidDurationValue: 45,
405
- TelemetryEnvelopeInvalid: 46,
406
- CreateEnvelopeError: 47,
407
- CannotSerializeObject: 48,
408
- CannotSerializeObjectNonSerializable: 49,
409
- CircularReferenceDetected: 50,
410
- ClearAuthContextFailed: 51,
411
- ExceptionTruncated: 52,
412
- IllegalCharsInName: 53,
413
- ItemNotInArray: 54,
414
- MaxAjaxPerPVExceeded: 55,
415
- MessageTruncated: 56,
416
- NameTooLong: 57,
417
- SampleRateOutOfRange: 58,
418
- SetAuthContextFailed: 59,
419
- SetAuthContextFailedAccountName: 60,
420
- StringValueTooLong: 61,
421
- StartCalledMoreThanOnce: 62,
422
- StopCalledWithoutStart: 63,
423
- TelemetryInitializerFailed: 64,
424
- TrackArgumentsNotSpecified: 65,
425
- UrlTooLong: 66,
426
- SessionStorageBufferFull: 67,
427
- CannotAccessCookie: 68,
428
- IdTooLong: 69,
429
- InvalidEvent: 70,
430
- FailedMonitorAjaxSetRequestHeader: 71,
431
- SendBrowserInfoOnUserInit: 72,
432
- PluginException: 73,
433
- NotificationException: 74,
434
- SnippetScriptLoadFailure: 99,
435
- InvalidInstrumentationKey: 100,
436
- CannotParseAiBlobValue: 101,
437
- InvalidContentBlob: 102,
438
- TrackPageActionEventFailed: 103,
439
- FailedAddingCustomDefinedRequestContext: 104,
440
- InMemoryStorageBufferFull: 105
441
- };
103
+ var strEmpty = "";
104
+ var strProcessTelemetry = "processTelemetry";
105
+ var strPriority = "priority";
106
+ var strSetNextPlugin = "setNextPlugin";
107
+ var strIsInitialized = "isInitialized";
108
+ var strTeardown = "teardown";
109
+ var strCore = "core";
110
+ var strUpdate = "update";
111
+ var strDisabled = "disabled";
112
+ var strDoTeardown = "_doTeardown";
113
+ var strProcessNext = "processNext";
114
+ var strResume = "resume";
115
+ var strPause = "pause";
116
+ var strNotificationListener = "NotificationListener";
117
+ var strAddNotificationListener = "add" + strNotificationListener;
118
+ var strRemoveNotificationListener = "remove" + strNotificationListener;
119
+ var strEventsSent = "eventsSent";
120
+ var strEventsDiscarded = "eventsDiscarded";
121
+ var strEventsSendRequest = "eventsSendRequest";
122
+ var strPerfEvent = "perfEvent";
442
123
 
443
- var strOnPrefix = "on";
444
- var strAttachEvent = "attachEvent";
445
- var strAddEventHelper = "addEventListener";
446
- var strDetachEvent = "detachEvent";
447
- var strRemoveEventListener = "removeEventListener";
448
124
  var strToISOString = "toISOString";
449
125
  var cStrEndsWith = "endsWith";
450
126
  var cStrStartsWith = "startsWith";
@@ -453,7 +129,11 @@
453
129
  var strReduce = "reduce";
454
130
  var cStrTrim = "trim";
455
131
  var strToString = "toString";
456
- var _objDefineProperty = ObjDefineProperty;
132
+ var str__Proto$1 = "__proto__";
133
+ var strConstructor = "constructor";
134
+ var _objDefineProperty$1 = ObjDefineProperty;
135
+ var _objFreeze = ObjClass.freeze;
136
+ var _objSeal = ObjClass.seal;
457
137
  var _objKeys = ObjClass.keys;
458
138
  var StringProto = String[strShimPrototype];
459
139
  var _strTrim = StringProto[cStrTrim];
@@ -464,10 +144,23 @@
464
144
  var _isArray = Array.isArray;
465
145
  var _objToString = ObjProto[strToString];
466
146
  var _fnToString = ObjHasOwnProperty[strToString];
467
- _fnToString.call(ObjClass);
147
+ var _objFunctionString = _fnToString.call(ObjClass);
468
148
  var rCamelCase = /-([a-z])/g;
469
149
  var rNormalizeInvalid = /([^\w\d_$])/g;
470
150
  var rLeadingNumeric = /^(\d+[\w\d_$])/;
151
+ var _objGetPrototypeOf$1 = Object["getPrototypeOf"];
152
+ function _getObjProto$1(target) {
153
+ if (target) {
154
+ if (_objGetPrototypeOf$1) {
155
+ return _objGetPrototypeOf$1(target);
156
+ }
157
+ var newProto = target[str__Proto$1] || target[strShimPrototype] || target[strConstructor];
158
+ if (newProto) {
159
+ return newProto;
160
+ }
161
+ }
162
+ return null;
163
+ }
471
164
  function isTypeof(value, theType) {
472
165
  return typeof value === theType;
473
166
  }
@@ -489,40 +182,6 @@
489
182
  function isFunction(value) {
490
183
  return !!(value && typeof value === strShimFunction);
491
184
  }
492
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
493
- if (useCapture === void 0) { useCapture = false; }
494
- var result = false;
495
- if (!isNullOrUndefined(obj)) {
496
- try {
497
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
498
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
499
- result = true;
500
- }
501
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
502
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
503
- result = true;
504
- }
505
- }
506
- catch (e) {
507
- }
508
- }
509
- return result;
510
- }
511
- function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
512
- if (useCapture === void 0) { useCapture = false; }
513
- if (!isNullOrUndefined(obj)) {
514
- try {
515
- if (!isNullOrUndefined(obj[strRemoveEventListener])) {
516
- obj[strRemoveEventListener](eventNameWithoutOn, handlerRef, useCapture);
517
- }
518
- else if (!isNullOrUndefined(obj[strDetachEvent])) {
519
- obj[strDetachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
520
- }
521
- }
522
- catch (e) {
523
- }
524
- }
525
- }
526
185
  function normalizeJsName(name) {
527
186
  var value = name;
528
187
  if (value && isString(value)) {
@@ -613,6 +272,22 @@
613
272
  function isBoolean(value) {
614
273
  return typeof value === "boolean";
615
274
  }
275
+ function isPlainObject(value) {
276
+ var result = false;
277
+ if (value && typeof value === "object") {
278
+ var proto = _objGetPrototypeOf$1 ? _objGetPrototypeOf$1(value) : _getObjProto$1(value);
279
+ if (!proto) {
280
+ result = true;
281
+ }
282
+ else {
283
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
284
+ proto = proto[strConstructor];
285
+ }
286
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
287
+ }
288
+ }
289
+ return result;
290
+ }
616
291
  function toISOString(date) {
617
292
  if (date) {
618
293
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -702,167 +377,523 @@
702
377
  if (arguments.length >= 3) {
703
378
  value = arguments[2];
704
379
  }
705
- else {
706
- while (lp < len && !(lp in arr)) {
707
- lp++;
380
+ else {
381
+ while (lp < len && !(lp in arr)) {
382
+ lp++;
383
+ }
384
+ value = arr[lp++];
385
+ }
386
+ while (lp < len) {
387
+ if (lp in arr) {
388
+ value = callbackfn(value, arr[lp], lp, arr);
389
+ }
390
+ lp++;
391
+ }
392
+ }
393
+ return value;
394
+ }
395
+ function strTrim(str) {
396
+ if (str) {
397
+ str = (_strTrim && str[cStrTrim]) ? str[cStrTrim]() : (str.replace ? str.replace(/^\s+|\s+$/g, "") : str);
398
+ }
399
+ return str;
400
+ }
401
+ var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
402
+ var _objKeysDontEnums = [
403
+ "toString",
404
+ "toLocaleString",
405
+ "valueOf",
406
+ "hasOwnProperty",
407
+ "isPrototypeOf",
408
+ "propertyIsEnumerable",
409
+ "constructor"
410
+ ];
411
+ function objKeys(obj) {
412
+ var objType = typeof obj;
413
+ if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
414
+ throwTypeError("objKeys called on non-object");
415
+ }
416
+ if (!_objKeysHasDontEnumBug && _objKeys) {
417
+ return _objKeys(obj);
418
+ }
419
+ var result = [];
420
+ for (var prop in obj) {
421
+ if (obj && ObjHasOwnProperty.call(obj, prop)) {
422
+ result.push(prop);
423
+ }
424
+ }
425
+ if (_objKeysHasDontEnumBug) {
426
+ var dontEnumsLength = _objKeysDontEnums.length;
427
+ for (var lp = 0; lp < dontEnumsLength; lp++) {
428
+ if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
429
+ result.push(_objKeysDontEnums[lp]);
430
+ }
431
+ }
432
+ }
433
+ return result;
434
+ }
435
+ function objDefineAccessors(target, prop, getProp, setProp) {
436
+ if (_objDefineProperty$1) {
437
+ try {
438
+ var descriptor = {
439
+ enumerable: true,
440
+ configurable: true
441
+ };
442
+ if (getProp) {
443
+ descriptor.get = getProp;
444
+ }
445
+ if (setProp) {
446
+ descriptor.set = setProp;
447
+ }
448
+ _objDefineProperty$1(target, prop, descriptor);
449
+ return true;
450
+ }
451
+ catch (e) {
452
+ }
453
+ }
454
+ return false;
455
+ }
456
+ function _doNothing(value) {
457
+ return value;
458
+ }
459
+ function deepFreeze(obj) {
460
+ if (_objFreeze) {
461
+ objForEachKey(obj, function (name, value) {
462
+ if (isArray(value) || isObject(value)) {
463
+ _objFreeze(value);
464
+ }
465
+ });
466
+ }
467
+ return objFreeze(obj);
468
+ }
469
+ var objFreeze = _objFreeze || _doNothing;
470
+ var objSeal = _objSeal || _doNothing;
471
+ function dateNow() {
472
+ var dt = Date;
473
+ return dt.now ? dt.now() : new dt().getTime();
474
+ }
475
+ function getExceptionName(object) {
476
+ if (isError(object)) {
477
+ return object.name;
478
+ }
479
+ return strEmpty;
480
+ }
481
+ function setValue(target, field, value, valChk, srcChk) {
482
+ var theValue = value;
483
+ if (target) {
484
+ theValue = target[field];
485
+ if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
486
+ theValue = value;
487
+ target[field] = theValue;
488
+ }
489
+ }
490
+ return theValue;
491
+ }
492
+ function getSetValue(target, field, defValue) {
493
+ var theValue;
494
+ if (target) {
495
+ theValue = target[field];
496
+ if (!theValue && isNullOrUndefined(theValue)) {
497
+ theValue = !isUndefined(defValue) ? defValue : {};
498
+ target[field] = theValue;
499
+ }
500
+ }
501
+ else {
502
+ theValue = !isUndefined(defValue) ? defValue : {};
503
+ }
504
+ return theValue;
505
+ }
506
+ function isNotTruthy(value) {
507
+ return !value;
508
+ }
509
+ function isTruthy(value) {
510
+ return !!value;
511
+ }
512
+ function throwError(message) {
513
+ throw new Error(message);
514
+ }
515
+ function _createProxyFunction(source, funcName) {
516
+ var srcFunc = null;
517
+ var src = null;
518
+ if (isFunction(source)) {
519
+ srcFunc = source;
520
+ }
521
+ else {
522
+ src = source;
523
+ }
524
+ return function () {
525
+ var originalArguments = arguments;
526
+ if (srcFunc) {
527
+ src = srcFunc();
528
+ }
529
+ if (src) {
530
+ return src[funcName].apply(src, originalArguments);
531
+ }
532
+ };
533
+ }
534
+ function proxyAssign(target, source, chkSet) {
535
+ if (target && source && isObject(target) && isObject(source)) {
536
+ var _loop_1 = function (field) {
537
+ if (isString(field)) {
538
+ var value = source[field];
539
+ if (isFunction(value)) {
540
+ if (!chkSet || chkSet(field, true, source, target)) {
541
+ target[field] = _createProxyFunction(source, field);
542
+ }
543
+ }
544
+ else if (!chkSet || chkSet(field, false, source, target)) {
545
+ if (hasOwnProperty(target, field)) {
546
+ delete target[field];
547
+ }
548
+ if (!objDefineAccessors(target, field, function () {
549
+ return source[field];
550
+ }, function (theValue) {
551
+ source[field] = theValue;
552
+ })) {
553
+ target[field] = value;
554
+ }
555
+ }
556
+ }
557
+ };
558
+ for (var field in source) {
559
+ _loop_1(field);
560
+ }
561
+ }
562
+ return target;
563
+ }
564
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
565
+ if (target && name && source) {
566
+ if (overwriteTarget !== false || isUndefined(target[name])) {
567
+ target[name] = _createProxyFunction(source, theFunc);
568
+ }
569
+ }
570
+ }
571
+ function proxyFunctions(target, source, functionsToProxy, overwriteTarget) {
572
+ if (target && source && isObject(target) && isArray(functionsToProxy)) {
573
+ arrForEach(functionsToProxy, function (theFuncName) {
574
+ if (isString(theFuncName)) {
575
+ proxyFunctionAs(target, theFuncName, source, theFuncName, overwriteTarget);
576
+ }
577
+ });
578
+ }
579
+ return target;
580
+ }
581
+ function optimizeObject(theObject) {
582
+ if (theObject && ObjAssign) {
583
+ theObject = ObjClass(ObjAssign({}, theObject));
584
+ }
585
+ return theObject;
586
+ }
587
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
588
+ var theArgs = arguments;
589
+ var extended = theArgs[0] || {};
590
+ var argLen = theArgs.length;
591
+ var deep = false;
592
+ var idx = 1;
593
+ if (argLen > 0 && isBoolean(extended)) {
594
+ deep = extended;
595
+ extended = theArgs[idx] || {};
596
+ idx++;
597
+ }
598
+ if (!isObject(extended)) {
599
+ extended = {};
600
+ }
601
+ for (; idx < argLen; idx++) {
602
+ var arg = theArgs[idx];
603
+ var isArgArray = isArray(arg);
604
+ var isArgObj = isObject(arg);
605
+ for (var prop in arg) {
606
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
607
+ if (!propOk) {
608
+ continue;
609
+ }
610
+ var newValue = arg[prop];
611
+ var isNewArray = void 0;
612
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
613
+ var clone = extended[prop];
614
+ if (isNewArray) {
615
+ if (!isArray(clone)) {
616
+ clone = [];
617
+ }
618
+ }
619
+ else if (!isPlainObject(clone)) {
620
+ clone = {};
621
+ }
622
+ newValue = objExtend(deep, clone, newValue);
623
+ }
624
+ if (newValue !== undefined) {
625
+ extended[prop] = newValue;
626
+ }
627
+ }
628
+ }
629
+ return extended;
630
+ }
631
+
632
+ function createEnumStyle(values) {
633
+ var enumClass = {};
634
+ objForEachKey(values, function (field, value) {
635
+ enumClass[field] = value;
636
+ enumClass[value] = field;
637
+ });
638
+ return deepFreeze(enumClass);
639
+ }
640
+
641
+ var EventsDiscardedReason = createEnumStyle({
642
+ Unknown: 0 ,
643
+ NonRetryableStatus: 1 ,
644
+ InvalidEvent: 2 ,
645
+ SizeLimitExceeded: 3 ,
646
+ KillSwitch: 4 ,
647
+ QueueFull: 5
648
+ });
649
+
650
+ /*!
651
+ * Microsoft Dynamic Proto Utility, 1.1.6
652
+ * Copyright (c) Microsoft and contributors. All rights reserved.
653
+ */
654
+ var Constructor = 'constructor';
655
+ var Prototype = 'prototype';
656
+ var strFunction = 'function';
657
+ var DynInstFuncTable = '_dynInstFuncs';
658
+ var DynProxyTag = '_isDynProxy';
659
+ var DynClassName = '_dynClass';
660
+ var DynClassNamePrefix = '_dynCls$';
661
+ var DynInstChkTag = '_dynInstChk';
662
+ var DynAllowInstChkTag = DynInstChkTag;
663
+ var DynProtoDefaultOptions = '_dfOpts';
664
+ var UnknownValue = '_unknown_';
665
+ var str__Proto = "__proto__";
666
+ var DynProtoBaseProto = "_dyn" + str__Proto;
667
+ var DynProtoCurrent = "_dynInstProto";
668
+ var strUseBaseInst = 'useBaseInst';
669
+ var strSetInstFuncs = 'setInstFuncs';
670
+ var Obj = Object;
671
+ var _objGetPrototypeOf = Obj["getPrototypeOf"];
672
+ var _objGetOwnProps = Obj["getOwnPropertyNames"];
673
+ var _dynamicNames = 0;
674
+ function _hasOwnProperty(obj, prop) {
675
+ return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
676
+ }
677
+ function _isObjectOrArrayPrototype(target) {
678
+ return target && (target === Obj[Prototype] || target === Array[Prototype]);
679
+ }
680
+ function _isObjectArrayOrFunctionPrototype(target) {
681
+ return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
682
+ }
683
+ function _getObjProto(target) {
684
+ var newProto;
685
+ if (target) {
686
+ if (_objGetPrototypeOf) {
687
+ return _objGetPrototypeOf(target);
688
+ }
689
+ var curProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
690
+ newProto = target[DynProtoBaseProto] || curProto;
691
+ if (!_hasOwnProperty(target, DynProtoBaseProto)) {
692
+ delete target[DynProtoCurrent];
693
+ newProto = target[DynProtoBaseProto] = target[DynProtoCurrent] || target[DynProtoBaseProto];
694
+ target[DynProtoCurrent] = curProto;
695
+ }
696
+ }
697
+ return newProto;
698
+ }
699
+ function _forEachProp(target, func) {
700
+ var props = [];
701
+ if (_objGetOwnProps) {
702
+ props = _objGetOwnProps(target);
703
+ }
704
+ else {
705
+ for (var name_1 in target) {
706
+ if (typeof name_1 === "string" && _hasOwnProperty(target, name_1)) {
707
+ props.push(name_1);
708
+ }
709
+ }
710
+ }
711
+ if (props && props.length > 0) {
712
+ for (var lp = 0; lp < props.length; lp++) {
713
+ func(props[lp]);
714
+ }
715
+ }
716
+ }
717
+ function _isDynamicCandidate(target, funcName, skipOwn) {
718
+ return (funcName !== Constructor && typeof target[funcName] === strFunction && (skipOwn || _hasOwnProperty(target, funcName)));
719
+ }
720
+ function _throwTypeError(message) {
721
+ throw new TypeError("DynamicProto: " + message);
722
+ }
723
+ function _getInstanceFuncs(thisTarget) {
724
+ var instFuncs = {};
725
+ _forEachProp(thisTarget, function (name) {
726
+ if (!instFuncs[name] && _isDynamicCandidate(thisTarget, name, false)) {
727
+ instFuncs[name] = thisTarget[name];
728
+ }
729
+ });
730
+ return instFuncs;
731
+ }
732
+ function _hasVisited(values, value) {
733
+ for (var lp = values.length - 1; lp >= 0; lp--) {
734
+ if (values[lp] === value) {
735
+ return true;
736
+ }
737
+ }
738
+ return false;
739
+ }
740
+ function _getBaseFuncs(classProto, thisTarget, instFuncs, useBaseInst) {
741
+ function _instFuncProxy(target, funcHost, funcName) {
742
+ var theFunc = funcHost[funcName];
743
+ if (theFunc[DynProxyTag] && useBaseInst) {
744
+ var instFuncTable = target[DynInstFuncTable] || {};
745
+ if (instFuncTable[DynAllowInstChkTag] !== false) {
746
+ theFunc = (instFuncTable[funcHost[DynClassName]] || {})[funcName] || theFunc;
747
+ }
748
+ }
749
+ return function () {
750
+ return theFunc.apply(target, arguments);
751
+ };
752
+ }
753
+ var baseFuncs = {};
754
+ _forEachProp(instFuncs, function (name) {
755
+ baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
756
+ });
757
+ var baseProto = _getObjProto(classProto);
758
+ var visited = [];
759
+ while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
760
+ _forEachProp(baseProto, function (name) {
761
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
762
+ baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
763
+ }
764
+ });
765
+ visited.push(baseProto);
766
+ baseProto = _getObjProto(baseProto);
767
+ }
768
+ return baseFuncs;
769
+ }
770
+ function _getInstFunc(target, funcName, proto, currentDynProtoProxy) {
771
+ var instFunc = null;
772
+ if (target && _hasOwnProperty(proto, DynClassName)) {
773
+ var instFuncTable = target[DynInstFuncTable] || {};
774
+ instFunc = (instFuncTable[proto[DynClassName]] || {})[funcName];
775
+ if (!instFunc) {
776
+ _throwTypeError("Missing [" + funcName + "] " + strFunction);
777
+ }
778
+ if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
779
+ var canAddInst = !_hasOwnProperty(target, funcName);
780
+ var objProto = _getObjProto(target);
781
+ var visited = [];
782
+ while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
783
+ var protoFunc = objProto[funcName];
784
+ if (protoFunc) {
785
+ canAddInst = (protoFunc === currentDynProtoProxy);
786
+ break;
787
+ }
788
+ visited.push(objProto);
789
+ objProto = _getObjProto(objProto);
708
790
  }
709
- value = arr[lp++];
710
- }
711
- while (lp < len) {
712
- if (lp in arr) {
713
- value = callbackfn(value, arr[lp], lp, arr);
791
+ try {
792
+ if (canAddInst) {
793
+ target[funcName] = instFunc;
794
+ }
795
+ instFunc[DynInstChkTag] = 1;
796
+ }
797
+ catch (e) {
798
+ instFuncTable[DynAllowInstChkTag] = false;
714
799
  }
715
- lp++;
716
800
  }
717
801
  }
718
- return value;
802
+ return instFunc;
719
803
  }
720
- function strTrim(str) {
721
- if (str) {
722
- str = (_strTrim && str[cStrTrim]) ? str[cStrTrim]() : (str.replace ? str.replace(/^\s+|\s+$/g, "") : str);
804
+ function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
805
+ var protoFunc = proto[funcName];
806
+ if (protoFunc === currentDynProtoProxy) {
807
+ protoFunc = _getObjProto(proto)[funcName];
723
808
  }
724
- return str;
725
- }
726
- var _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
727
- var _objKeysDontEnums = [
728
- "toString",
729
- "toLocaleString",
730
- "valueOf",
731
- "hasOwnProperty",
732
- "isPrototypeOf",
733
- "propertyIsEnumerable",
734
- "constructor"
735
- ];
736
- function objKeys(obj) {
737
- var objType = typeof obj;
738
- if (objType !== strShimFunction && (objType !== strShimObject || obj === null)) {
739
- throwTypeError("objKeys called on non-object");
809
+ if (typeof protoFunc !== strFunction) {
810
+ _throwTypeError("[" + funcName + "] is not a " + strFunction);
740
811
  }
741
- if (!_objKeysHasDontEnumBug && _objKeys) {
742
- return _objKeys(obj);
812
+ return protoFunc;
813
+ }
814
+ function _populatePrototype(proto, className, target, baseInstFuncs, setInstanceFunc) {
815
+ function _createDynamicPrototype(proto, funcName) {
816
+ var dynProtoProxy = function () {
817
+ var instFunc = _getInstFunc(this, funcName, proto, dynProtoProxy) || _getProtoFunc(funcName, proto, dynProtoProxy);
818
+ return instFunc.apply(this, arguments);
819
+ };
820
+ dynProtoProxy[DynProxyTag] = 1;
821
+ return dynProtoProxy;
743
822
  }
744
- var result = [];
745
- for (var prop in obj) {
746
- if (obj && ObjHasOwnProperty.call(obj, prop)) {
747
- result.push(prop);
823
+ if (!_isObjectOrArrayPrototype(proto)) {
824
+ var instFuncTable = target[DynInstFuncTable] = target[DynInstFuncTable] || {};
825
+ var instFuncs_1 = instFuncTable[className] = (instFuncTable[className] || {});
826
+ if (instFuncTable[DynAllowInstChkTag] !== false) {
827
+ instFuncTable[DynAllowInstChkTag] = !!setInstanceFunc;
748
828
  }
749
- }
750
- if (_objKeysHasDontEnumBug) {
751
- var dontEnumsLength = _objKeysDontEnums.length;
752
- for (var lp = 0; lp < dontEnumsLength; lp++) {
753
- if (obj && ObjHasOwnProperty.call(obj, _objKeysDontEnums[lp])) {
754
- result.push(_objKeysDontEnums[lp]);
829
+ _forEachProp(target, function (name) {
830
+ if (_isDynamicCandidate(target, name, false) && target[name] !== baseInstFuncs[name]) {
831
+ instFuncs_1[name] = target[name];
832
+ delete target[name];
833
+ if (!_hasOwnProperty(proto, name) || (proto[name] && !proto[name][DynProxyTag])) {
834
+ proto[name] = _createDynamicPrototype(proto, name);
835
+ }
755
836
  }
756
- }
837
+ });
757
838
  }
758
- return result;
759
839
  }
760
- function objDefineAccessors(target, prop, getProp, setProp) {
761
- if (_objDefineProperty) {
762
- try {
763
- var descriptor = {
764
- enumerable: true,
765
- configurable: true
766
- };
767
- if (getProp) {
768
- descriptor.get = getProp;
769
- }
770
- if (setProp) {
771
- descriptor.set = setProp;
840
+ function _checkPrototype(classProto, thisTarget) {
841
+ if (_objGetPrototypeOf) {
842
+ var visited = [];
843
+ var thisProto = _getObjProto(thisTarget);
844
+ while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
845
+ if (thisProto === classProto) {
846
+ return true;
772
847
  }
773
- _objDefineProperty(target, prop, descriptor);
774
- return true;
775
- }
776
- catch (e) {
848
+ visited.push(thisProto);
849
+ thisProto = _getObjProto(thisProto);
777
850
  }
851
+ return false;
778
852
  }
779
- return false;
780
- }
781
- function dateNow() {
782
- var dt = Date;
783
- return dt.now ? dt.now() : new dt().getTime();
853
+ return true;
784
854
  }
785
- function getExceptionName(object) {
786
- if (isError(object)) {
787
- return object.name;
855
+ function _getObjName(target, unknownValue) {
856
+ if (_hasOwnProperty(target, Prototype)) {
857
+ return target.name || unknownValue || UnknownValue;
788
858
  }
789
- return "";
859
+ return (((target || {})[Constructor]) || {}).name || unknownValue || UnknownValue;
790
860
  }
791
- function setValue(target, field, value, valChk, srcChk) {
792
- var theValue = value;
793
- if (target) {
794
- theValue = target[field];
795
- if (theValue !== value && (!srcChk || srcChk(theValue)) && (!valChk || valChk(value))) {
796
- theValue = value;
797
- target[field] = theValue;
798
- }
861
+ function dynamicProto(theClass, target, delegateFunc, options) {
862
+ if (!_hasOwnProperty(theClass, Prototype)) {
863
+ _throwTypeError("theClass is an invalid class definition.");
799
864
  }
800
- return theValue;
801
- }
802
- function getSetValue(target, field, defValue) {
803
- var theValue;
804
- if (target) {
805
- theValue = target[field];
806
- if (!theValue && isNullOrUndefined(theValue)) {
807
- theValue = !isUndefined(defValue) ? defValue : {};
808
- target[field] = theValue;
809
- }
865
+ var classProto = theClass[Prototype];
866
+ if (!_checkPrototype(classProto, target)) {
867
+ _throwTypeError("[" + _getObjName(theClass) + "] is not in class hierarchy of [" + _getObjName(target) + "]");
868
+ }
869
+ var className = null;
870
+ if (_hasOwnProperty(classProto, DynClassName)) {
871
+ className = classProto[DynClassName];
810
872
  }
811
873
  else {
812
- theValue = !isUndefined(defValue) ? defValue : {};
874
+ className = DynClassNamePrefix + _getObjName(theClass, "_") + "$" + _dynamicNames;
875
+ _dynamicNames++;
876
+ classProto[DynClassName] = className;
813
877
  }
814
- return theValue;
815
- }
816
- function isNotTruthy(value) {
817
- return !value;
818
- }
819
- function isTruthy(value) {
820
- return !!value;
821
- }
822
- function throwError(message) {
823
- throw new Error(message);
824
- }
825
- function proxyAssign(target, source, chkSet) {
826
- if (target && source && target !== source && isObject(target) && isObject(source)) {
827
- var _loop_1 = function (field) {
828
- if (isString(field)) {
829
- var value = source[field];
830
- if (isFunction(value)) {
831
- if (!chkSet || chkSet(field, true, source, target)) {
832
- target[field] = (function (funcName) {
833
- return function () {
834
- var originalArguments = arguments;
835
- return source[funcName].apply(source, originalArguments);
836
- };
837
- })(field);
838
- }
839
- }
840
- else if (!chkSet || chkSet(field, false, source, target)) {
841
- if (hasOwnProperty(target, field)) {
842
- delete target[field];
843
- }
844
- if (!objDefineAccessors(target, field, function () {
845
- return source[field];
846
- }, function (theValue) {
847
- source[field] = theValue;
848
- })) {
849
- target[field] = value;
850
- }
851
- }
852
- }
853
- };
854
- for (var field in source) {
855
- _loop_1(field);
856
- }
878
+ var perfOptions = dynamicProto[DynProtoDefaultOptions];
879
+ var useBaseInst = !!perfOptions[strUseBaseInst];
880
+ if (useBaseInst && options && options[strUseBaseInst] !== undefined) {
881
+ useBaseInst = !!options[strUseBaseInst];
857
882
  }
858
- return target;
859
- }
860
- function optimizeObject(theObject) {
861
- if (theObject && ObjAssign) {
862
- theObject = ObjClass(ObjAssign({}, theObject));
883
+ var instFuncs = _getInstanceFuncs(target);
884
+ var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
885
+ delegateFunc(target, baseFuncs);
886
+ var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
887
+ if (setInstanceFunc && options) {
888
+ setInstanceFunc = !!options[strSetInstFuncs];
863
889
  }
864
- return theObject;
890
+ _populatePrototype(classProto, className, target, instFuncs, setInstanceFunc !== false);
865
891
  }
892
+ var perfDefaults = {
893
+ setInstFuncs: true,
894
+ useBaseInst: true
895
+ };
896
+ dynamicProto[DynProtoDefaultOptions] = perfDefaults;
866
897
 
867
898
  var strWindow = "window";
868
899
  var strDocument = "document";
@@ -878,6 +909,7 @@
878
909
  var strReactNative = "ReactNative";
879
910
  var strMsie = "msie";
880
911
  var strTrident = "trident/";
912
+ var strXMLHttpRequest = "XMLHttpRequest";
881
913
  var _isTrident = null;
882
914
  var _navUserAgentCheck = null;
883
915
  var _enableMocks = false;
@@ -1004,7 +1036,7 @@
1004
1036
  var nav = getNavigator();
1005
1037
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
1006
1038
  _navUserAgentCheck = nav.userAgent;
1007
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
1039
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
1008
1040
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
1009
1041
  }
1010
1042
  return _isTrident;
@@ -1013,9 +1045,9 @@
1013
1045
  if (userAgentStr === void 0) { userAgentStr = null; }
1014
1046
  if (!userAgentStr) {
1015
1047
  var navigator_1 = getNavigator() || {};
1016
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
1048
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty).toLowerCase() : strEmpty;
1017
1049
  }
1018
- var ua = (userAgentStr || "").toLowerCase();
1050
+ var ua = (userAgentStr || strEmpty).toLowerCase();
1019
1051
  if (strContains(ua, strMsie)) {
1020
1052
  var doc = getDocument() || {};
1021
1053
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -1030,7 +1062,7 @@
1030
1062
  }
1031
1063
  function dumpObj(object) {
1032
1064
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
1033
- var propertyValueDump = "";
1065
+ var propertyValueDump = strEmpty;
1034
1066
  if (objectTypeDump === "[object Error]") {
1035
1067
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
1036
1068
  }
@@ -1048,8 +1080,7 @@
1048
1080
  function isFetchSupported(withKeepAlive) {
1049
1081
  var isSupported = false;
1050
1082
  try {
1051
- var fetchApi = getGlobalInst("fetch");
1052
- isSupported = !!fetchApi;
1083
+ isSupported = !!getGlobalInst("fetch");
1053
1084
  var request = getGlobalInst("Request");
1054
1085
  if (isSupported && withKeepAlive && request) {
1055
1086
  isSupported = _hasProperty(request, "keepalive");
@@ -1061,9 +1092,9 @@
1061
1092
  }
1062
1093
  function useXDomainRequest() {
1063
1094
  if (_useXDomainRequest === null) {
1064
- _useXDomainRequest = (typeof XDomainRequest !== "undefined");
1095
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
1065
1096
  if (_useXDomainRequest && isXhrSupported()) {
1066
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
1097
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
1067
1098
  }
1068
1099
  }
1069
1100
  return _useXDomainRequest;
@@ -1071,7 +1102,7 @@
1071
1102
  function isXhrSupported() {
1072
1103
  var isSupported = false;
1073
1104
  try {
1074
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
1105
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
1075
1106
  isSupported = !!xmlHttpRequest;
1076
1107
  }
1077
1108
  catch (e) {
@@ -1125,9 +1156,9 @@
1125
1156
  var strWarnToConsole = "warnToConsole";
1126
1157
  function _sanitizeDiagnosticText(text) {
1127
1158
  if (text) {
1128
- return "\"" + text.replace(/\"/g, "") + "\"";
1159
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
1129
1160
  }
1130
- return "";
1161
+ return strEmpty;
1131
1162
  }
1132
1163
  function _logToConsole(func, message) {
1133
1164
  var theConsole = getConsole();
@@ -1149,12 +1180,12 @@
1149
1180
  _self.message =
1150
1181
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
1151
1182
  msgId;
1152
- var strProps = "";
1183
+ var strProps = strEmpty;
1153
1184
  if (hasJSON()) {
1154
1185
  strProps = getJSON().stringify(properties);
1155
1186
  }
1156
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
1157
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
1187
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
1188
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
1158
1189
  _self.message += diagnosticText;
1159
1190
  }
1160
1191
  _InternalLogMessage.dataType = "MessageData";
@@ -1181,10 +1212,10 @@
1181
1212
  if (isUserAct === void 0) { isUserAct = false; }
1182
1213
  var message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
1183
1214
  if (_self.enableDebugExceptions()) {
1184
- throw message;
1215
+ throw dumpObj(message);
1185
1216
  }
1186
1217
  else {
1187
- var logFunc = severity === exports.LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
1218
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
1188
1219
  if (!isUndefined(message.message)) {
1189
1220
  var logLevel = _self.consoleLoggingLevel();
1190
1221
  if (isUserAct) {
@@ -1202,7 +1233,7 @@
1202
1233
  _self.logInternalMessage(severity, message);
1203
1234
  }
1204
1235
  else {
1205
- _debugExtMsg("throw" + (severity === exports.LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
1236
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
1206
1237
  }
1207
1238
  }
1208
1239
  };
@@ -1234,13 +1265,13 @@
1234
1265
  if (severity <= _self.telemetryLoggingLevel()) {
1235
1266
  _self.queue.push(message);
1236
1267
  _messageCount++;
1237
- _debugExtMsg((severity === exports.LoggingSeverity.CRITICAL ? "error" : "warn"), message);
1268
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
1238
1269
  }
1239
1270
  if (_messageCount === _self.maxInternalMessageLimit()) {
1240
1271
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
1241
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
1272
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
1242
1273
  _self.queue.push(throttleMessage);
1243
- if (severity === exports.LoggingSeverity.CRITICAL) {
1274
+ if (severity === 1 ) {
1244
1275
  _self.errorToConsole(throttleLimitMessage);
1245
1276
  }
1246
1277
  else {
@@ -1269,6 +1300,16 @@
1269
1300
  }
1270
1301
  return DiagnosticLogger;
1271
1302
  }());
1303
+ function _getLogger(logger) {
1304
+ return (logger || new DiagnosticLogger());
1305
+ }
1306
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1307
+ if (isUserAct === void 0) { isUserAct = false; }
1308
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1309
+ }
1310
+ function _warnToConsole(logger, message) {
1311
+ _getLogger(logger).warnToConsole(message);
1312
+ }
1272
1313
 
1273
1314
  var strExecutionContextKey = "ctx";
1274
1315
  var _defaultPerfManager = null;
@@ -1408,277 +1449,192 @@
1408
1449
  }
1409
1450
  }
1410
1451
  }
1411
- return func();
1452
+ return func();
1453
+ }
1454
+ function getGblPerfMgr() {
1455
+ return _defaultPerfManager;
1456
+ }
1457
+
1458
+ var UInt32Mask = 0x100000000;
1459
+ var MaxUInt32 = 0xffffffff;
1460
+ var _mwcSeeded = false;
1461
+ var _mwcW = 123456789;
1462
+ var _mwcZ = 987654321;
1463
+ function _mwcSeed(seedValue) {
1464
+ if (seedValue < 0) {
1465
+ seedValue >>>= 0;
1466
+ }
1467
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1468
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1469
+ _mwcSeeded = true;
1470
+ }
1471
+ function _autoSeedMwc() {
1472
+ try {
1473
+ var now = dateNow() & 0x7fffffff;
1474
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1475
+ }
1476
+ catch (e) {
1477
+ }
1412
1478
  }
1413
- function getGblPerfMgr() {
1414
- return _defaultPerfManager;
1479
+ function randomValue(maxValue) {
1480
+ if (maxValue > 0) {
1481
+ return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
1482
+ }
1483
+ return 0;
1415
1484
  }
1416
-
1417
- var TelemetryPluginChain = /** @class */ (function () {
1418
- function TelemetryPluginChain(plugin, defItemCtx) {
1419
- var _self = this;
1420
- var _nextProxy = null;
1421
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1422
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1423
- _self._hasRun = false;
1424
- _self.getPlugin = function () {
1425
- return plugin;
1426
- };
1427
- _self.getNext = function () {
1428
- return _nextProxy;
1429
- };
1430
- _self.setNext = function (nextPlugin) {
1431
- _nextProxy = nextPlugin;
1432
- };
1433
- _self.processTelemetry = function (env, itemCtx) {
1434
- if (!itemCtx) {
1435
- itemCtx = defItemCtx;
1436
- }
1437
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1438
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1439
- if (plugin && _hasProcessTelemetry) {
1440
- _self._hasRun = true;
1441
- try {
1442
- itemCtx.setNext(_nextProxy);
1443
- if (_hasSetNext) {
1444
- plugin.setNextPlugin(_nextProxy);
1445
- }
1446
- _nextProxy && (_nextProxy._hasRun = false);
1447
- plugin.processTelemetry(env, itemCtx);
1448
- }
1449
- catch (error) {
1450
- var hasRun = _nextProxy && _nextProxy._hasRun;
1451
- if (!_nextProxy || !hasRun) {
1452
- itemCtx.diagLog().throwInternal(exports.LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1453
- }
1454
- if (_nextProxy && !hasRun) {
1455
- _nextProxy.processTelemetry(env, itemCtx);
1456
- }
1457
- }
1458
- }
1459
- else if (_nextProxy) {
1460
- _self._hasRun = true;
1461
- _nextProxy.processTelemetry(env, itemCtx);
1462
- }
1463
- }, function () { return ({ item: env }); }, !(env.sync));
1464
- };
1485
+ function random32(signed) {
1486
+ var value = 0;
1487
+ var c = getCrypto() || getMsCrypto();
1488
+ if (c && c.getRandomValues) {
1489
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1465
1490
  }
1466
- return TelemetryPluginChain;
1467
- }());
1468
-
1469
- function _createProxyChain(plugins, itemCtx) {
1470
- var proxies = [];
1471
- if (plugins && plugins.length > 0) {
1472
- var lastProxy = null;
1473
- for (var idx = 0; idx < plugins.length; idx++) {
1474
- var thePlugin = plugins[idx];
1475
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1476
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1477
- proxies.push(newProxy);
1478
- if (lastProxy) {
1479
- lastProxy.setNext(newProxy);
1480
- }
1481
- lastProxy = newProxy;
1482
- }
1491
+ if (value === 0 && isIE()) {
1492
+ if (!_mwcSeeded) {
1493
+ _autoSeedMwc();
1483
1494
  }
1495
+ value = mwcRandom32() & MaxUInt32;
1496
+ }
1497
+ if (value === 0) {
1498
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1499
+ }
1500
+ if (!signed) {
1501
+ value >>>= 0;
1484
1502
  }
1485
- return proxies.length > 0 ? proxies[0] : null;
1503
+ return value;
1486
1504
  }
1487
- function _copyProxyChain(proxy, itemCtx, startAt) {
1488
- var plugins = [];
1489
- var add = startAt ? false : true;
1490
- if (proxy) {
1491
- while (proxy) {
1492
- var thePlugin = proxy.getPlugin();
1493
- if (add || thePlugin === startAt) {
1494
- add = true;
1495
- plugins.push(thePlugin);
1496
- }
1497
- proxy = proxy.getNext();
1498
- }
1505
+ function mwcRandomSeed(value) {
1506
+ if (!value) {
1507
+ _autoSeedMwc();
1499
1508
  }
1500
- if (!add) {
1501
- plugins.push(startAt);
1509
+ else {
1510
+ _mwcSeed(value);
1502
1511
  }
1503
- return _createProxyChain(plugins, itemCtx);
1504
1512
  }
1505
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1506
- var plugins = srcPlugins;
1507
- var add = false;
1508
- if (startAt && srcPlugins) {
1509
- plugins = [];
1510
- arrForEach(srcPlugins, function (thePlugin) {
1511
- if (add || thePlugin === startAt) {
1512
- add = true;
1513
- plugins.push(thePlugin);
1514
- }
1515
- });
1513
+ function mwcRandom32(signed) {
1514
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1515
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1516
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1517
+ if (!signed) {
1518
+ value >>>= 0;
1519
+ }
1520
+ return value;
1521
+ }
1522
+ function newId(maxLength) {
1523
+ if (maxLength === void 0) { maxLength = 22; }
1524
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1525
+ var number = random32() >>> 0;
1526
+ var chars = 0;
1527
+ var result = strEmpty;
1528
+ while (result.length < maxLength) {
1529
+ chars++;
1530
+ result += base64chars.charAt(number & 0x3F);
1531
+ number >>>= 6;
1532
+ if (chars === 5) {
1533
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1534
+ chars = 0;
1535
+ }
1516
1536
  }
1517
- if (startAt && !add) {
1518
- if (!plugins) {
1519
- plugins = [];
1537
+ return result;
1538
+ }
1539
+
1540
+ var _objDefineProperty = ObjDefineProperty;
1541
+ var version = "2.8.3";
1542
+ var instanceName = "." + newId(6);
1543
+ var _dataUid = 0;
1544
+ function _createAccessor(target, prop, value) {
1545
+ if (_objDefineProperty) {
1546
+ try {
1547
+ _objDefineProperty(target, prop, {
1548
+ value: value,
1549
+ enumerable: false,
1550
+ configurable: true
1551
+ });
1552
+ return true;
1553
+ }
1554
+ catch (e) {
1520
1555
  }
1521
- plugins.push(startAt);
1522
1556
  }
1523
- return _createProxyChain(plugins, itemCtx);
1557
+ return false;
1524
1558
  }
1525
- var ProcessTelemetryContext = /** @class */ (function () {
1526
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1527
- var _self = this;
1528
- var _nextProxy = null;
1529
- if (startAt !== null) {
1530
- if (plugins && isFunction(plugins.getPlugin)) {
1531
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1532
- }
1533
- else {
1534
- if (startAt) {
1535
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1536
- }
1537
- else if (isUndefined(startAt)) {
1538
- _nextProxy = _createProxyChain(plugins, _self);
1559
+ function _canAcceptData(target) {
1560
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1561
+ }
1562
+ function _getCache(data, target) {
1563
+ var theCache = target[data.id];
1564
+ if (!theCache) {
1565
+ theCache = {};
1566
+ try {
1567
+ if (_canAcceptData(target)) {
1568
+ if (!_createAccessor(target, data.id, theCache)) {
1569
+ target[data.id] = theCache;
1539
1570
  }
1540
1571
  }
1541
1572
  }
1542
- _self.core = function () {
1543
- return core;
1544
- };
1545
- _self.diagLog = function () {
1546
- return safeGetLogger(core, config);
1547
- };
1548
- _self.getCfg = function () {
1549
- return config;
1550
- };
1551
- _self.getExtCfg = function (identifier, defaultValue) {
1552
- if (defaultValue === void 0) { defaultValue = {}; }
1553
- var theConfig;
1554
- if (config) {
1555
- var extConfig = config.extensionConfig;
1556
- if (extConfig && identifier) {
1557
- theConfig = extConfig[identifier];
1558
- }
1559
- }
1560
- return (theConfig ? theConfig : defaultValue);
1561
- };
1562
- _self.getConfig = function (identifier, field, defaultValue) {
1563
- if (defaultValue === void 0) { defaultValue = false; }
1564
- var theValue;
1565
- var extConfig = _self.getExtCfg(identifier, null);
1566
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1567
- theValue = extConfig[field];
1568
- }
1569
- else if (config && !isNullOrUndefined(config[field])) {
1570
- theValue = config[field];
1571
- }
1572
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1573
- };
1574
- _self.hasNext = function () {
1575
- return _nextProxy != null;
1576
- };
1577
- _self.getNext = function () {
1578
- return _nextProxy;
1579
- };
1580
- _self.setNext = function (nextPlugin) {
1581
- _nextProxy = nextPlugin;
1582
- };
1583
- _self.processNext = function (env) {
1584
- var nextPlugin = _nextProxy;
1585
- if (nextPlugin) {
1586
- _nextProxy = nextPlugin.getNext();
1587
- nextPlugin.processTelemetry(env, _self);
1588
- }
1589
- };
1590
- _self.createNew = function (plugins, startAt) {
1591
- if (plugins === void 0) { plugins = null; }
1592
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1593
- };
1573
+ catch (e) {
1574
+ }
1594
1575
  }
1595
- return ProcessTelemetryContext;
1596
- }());
1597
-
1598
- var strIKey = "iKey";
1599
- var strExtensionConfig = "extensionConfig";
1600
-
1601
- var strGetPlugin = "getPlugin";
1602
- var BaseTelemetryPlugin = /** @class */ (function () {
1603
- function BaseTelemetryPlugin() {
1604
- var _self = this;
1605
- var _isinitialized = false;
1606
- var _rootCtx = null;
1607
- var _nextPlugin = null;
1608
- _self.core = null;
1609
- _self.diagLog = function (itemCtx) {
1610
- return _self._getTelCtx(itemCtx).diagLog();
1611
- };
1612
- _self.isInitialized = function () {
1613
- return _isinitialized;
1614
- };
1615
- _self.setInitialized = function (isInitialized) {
1616
- _isinitialized = isInitialized;
1617
- };
1618
- _self.setNextPlugin = function (next) {
1619
- _nextPlugin = next;
1620
- };
1621
- _self.processNext = function (env, itemCtx) {
1622
- if (itemCtx) {
1623
- itemCtx.processNext(env);
1624
- }
1625
- else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
1626
- _nextPlugin.processTelemetry(env, null);
1576
+ return theCache;
1577
+ }
1578
+ function createUniqueNamespace(name, includeVersion) {
1579
+ if (includeVersion === void 0) { includeVersion = false; }
1580
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1581
+ }
1582
+ function createElmNodeData(name) {
1583
+ var data = {
1584
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1585
+ accept: function (target) {
1586
+ return _canAcceptData(target);
1587
+ },
1588
+ get: function (target, name, defValue, addDefault) {
1589
+ var theCache = target[data.id];
1590
+ if (!theCache) {
1591
+ if (addDefault) {
1592
+ theCache = _getCache(data, target);
1593
+ theCache[normalizeJsName(name)] = defValue;
1594
+ }
1595
+ return defValue;
1627
1596
  }
1628
- };
1629
- _self._getTelCtx = function (currentCtx) {
1630
- if (currentCtx === void 0) { currentCtx = null; }
1631
- var itemCtx = currentCtx;
1632
- if (!itemCtx) {
1633
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1634
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1635
- itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1597
+ return theCache[normalizeJsName(name)];
1598
+ },
1599
+ kill: function (target, name) {
1600
+ if (target && target[name]) {
1601
+ try {
1602
+ delete target[name];
1636
1603
  }
1637
- else {
1638
- itemCtx = rootCtx.createNew(null, _nextPlugin);
1604
+ catch (e) {
1639
1605
  }
1640
1606
  }
1641
- return itemCtx;
1642
- };
1643
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1644
- if (config) {
1645
- setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1646
- }
1647
- if (!pluginChain && core) {
1648
- pluginChain = core.getProcessTelContext().getNext();
1649
- }
1650
- var nextPlugin = _nextPlugin;
1651
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1652
- nextPlugin = _nextPlugin[strGetPlugin]();
1653
- }
1654
- _self.core = core;
1655
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1656
- _isinitialized = true;
1657
- };
1658
- }
1659
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1660
- this._baseTelInit(config, core, extensions, pluginChain);
1607
+ }
1661
1608
  };
1662
- return BaseTelemetryPlugin;
1663
- }());
1609
+ return data;
1610
+ }
1664
1611
 
1665
- var processTelemetry = "processTelemetry";
1666
- var priority = "priority";
1667
- var setNextPlugin = "setNextPlugin";
1668
- var isInitialized = "isInitialized";
1612
+ var pluginStateData = createElmNodeData("plugin");
1613
+ function _getPluginState(plugin) {
1614
+ return pluginStateData.get(plugin, "state", {}, true);
1615
+ }
1669
1616
  function initializePlugins(processContext, extensions) {
1670
1617
  var initPlugins = [];
1671
1618
  var lastPlugin = null;
1672
1619
  var proxy = processContext.getNext();
1620
+ var pluginState;
1673
1621
  while (proxy) {
1674
1622
  var thePlugin = proxy.getPlugin();
1675
1623
  if (thePlugin) {
1676
1624
  if (lastPlugin &&
1677
- isFunction(lastPlugin[setNextPlugin]) &&
1678
- isFunction(thePlugin[processTelemetry])) {
1679
- lastPlugin[setNextPlugin](thePlugin);
1625
+ isFunction(lastPlugin[strSetNextPlugin]) &&
1626
+ isFunction(thePlugin[strProcessTelemetry])) {
1627
+ lastPlugin[strSetNextPlugin](thePlugin);
1680
1628
  }
1681
- if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {
1629
+ var isInitialized = false;
1630
+ if (isFunction(thePlugin[strIsInitialized])) {
1631
+ isInitialized = thePlugin[strIsInitialized]();
1632
+ }
1633
+ else {
1634
+ pluginState = _getPluginState(thePlugin);
1635
+ isInitialized = pluginState[strIsInitialized];
1636
+ }
1637
+ if (!isInitialized) {
1682
1638
  initPlugins.push(thePlugin);
1683
1639
  }
1684
1640
  lastPlugin = thePlugin;
@@ -1686,15 +1642,22 @@
1686
1642
  }
1687
1643
  }
1688
1644
  arrForEach(initPlugins, function (thePlugin) {
1689
- thePlugin.initialize(processContext.getCfg(), processContext.core(), extensions, processContext.getNext());
1645
+ var core = processContext.core();
1646
+ thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
1647
+ pluginState = _getPluginState(thePlugin);
1648
+ if (!thePlugin[strCore] && !pluginState[strCore]) {
1649
+ pluginState[strCore] = core;
1650
+ }
1651
+ pluginState[strIsInitialized] = true;
1652
+ delete pluginState[strTeardown];
1690
1653
  });
1691
1654
  }
1692
1655
  function sortPlugins(plugins) {
1693
1656
  return plugins.sort(function (extA, extB) {
1694
1657
  var result = 0;
1695
- var bHasProcess = isFunction(extB[processTelemetry]);
1696
- if (isFunction(extA[processTelemetry])) {
1697
- result = bHasProcess ? extA[priority] - extB[priority] : 1;
1658
+ var bHasProcess = isFunction(extB[strProcessTelemetry]);
1659
+ if (isFunction(extA[strProcessTelemetry])) {
1660
+ result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1698
1661
  }
1699
1662
  else if (bHasProcess) {
1700
1663
  result = -1;
@@ -1703,80 +1666,361 @@
1703
1666
  });
1704
1667
  }
1705
1668
 
1706
- var ChannelControllerPriority = 500;
1707
- var ChannelValidationMessage = "Channel has invalid priority";
1708
- var ChannelController = /** @class */ (function (_super) {
1709
- __extendsFn(ChannelController, _super);
1710
- function ChannelController() {
1711
- var _this = _super.call(this) || this;
1712
- _this.identifier = "ChannelControllerPlugin";
1713
- _this.priority = ChannelControllerPriority;
1714
- var _channelQueue;
1715
- dynamicProto(ChannelController, _this, function (_self, _base) {
1716
- _self.setNextPlugin = function (next) {
1717
- };
1718
- _self.processTelemetry = function (item, itemCtx) {
1719
- if (_channelQueue) {
1720
- arrForEach(_channelQueue, function (queues) {
1721
- if (queues.length > 0) {
1722
- var chainCtx = _this._getTelCtx(itemCtx).createNew(queues);
1723
- chainCtx.processNext(item);
1669
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1670
+ var strHasRunFlags = "_hasRun";
1671
+ var strGetTelCtx = "_getTelCtx";
1672
+ var _chainId = 0;
1673
+ function _getNextProxyStart(proxy, core, startAt) {
1674
+ while (proxy) {
1675
+ if (proxy.getPlugin() === startAt) {
1676
+ return proxy;
1677
+ }
1678
+ proxy = proxy.getNext();
1679
+ }
1680
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
1681
+ }
1682
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1683
+ var _nextProxy = null;
1684
+ var _onComplete = [];
1685
+ if (startAt !== null) {
1686
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1687
+ }
1688
+ var context = {
1689
+ _next: _moveNext,
1690
+ ctx: {
1691
+ core: function () {
1692
+ return core;
1693
+ },
1694
+ diagLog: function () {
1695
+ return safeGetLogger(core, config);
1696
+ },
1697
+ getCfg: function () {
1698
+ return config;
1699
+ },
1700
+ getExtCfg: _getExtCfg,
1701
+ getConfig: _getConfig,
1702
+ hasNext: function () {
1703
+ return !!_nextProxy;
1704
+ },
1705
+ getNext: function () {
1706
+ return _nextProxy;
1707
+ },
1708
+ setNext: function (nextPlugin) {
1709
+ _nextProxy = nextPlugin;
1710
+ },
1711
+ iterate: _iterateChain,
1712
+ onComplete: _addOnComplete
1713
+ }
1714
+ };
1715
+ function _addOnComplete(onComplete, that) {
1716
+ var args = [];
1717
+ for (var _i = 2; _i < arguments.length; _i++) {
1718
+ args[_i - 2] = arguments[_i];
1719
+ }
1720
+ if (onComplete) {
1721
+ _onComplete.push({
1722
+ func: onComplete,
1723
+ self: !isUndefined(that) ? that : context.ctx,
1724
+ args: args
1725
+ });
1726
+ }
1727
+ }
1728
+ function _moveNext() {
1729
+ var nextProxy = _nextProxy;
1730
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1731
+ if (!nextProxy) {
1732
+ var onComplete = _onComplete;
1733
+ if (onComplete && onComplete.length > 0) {
1734
+ arrForEach(onComplete, function (completeDetails) {
1735
+ try {
1736
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1737
+ }
1738
+ catch (e) {
1739
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1740
+ }
1741
+ });
1742
+ _onComplete = [];
1743
+ }
1744
+ }
1745
+ return nextProxy;
1746
+ }
1747
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1748
+ if (defaultValue === void 0) { defaultValue = {}; }
1749
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1750
+ var theConfig;
1751
+ if (config) {
1752
+ var extConfig = config.extensionConfig;
1753
+ if (extConfig && identifier) {
1754
+ theConfig = extConfig[identifier];
1755
+ }
1756
+ }
1757
+ if (!theConfig) {
1758
+ theConfig = defaultValue;
1759
+ }
1760
+ else if (isObject(defaultValue)) {
1761
+ if (mergeDefault !== 0 ) {
1762
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1763
+ if (config && mergeDefault === 2 ) {
1764
+ objForEachKey(defaultValue, function (field) {
1765
+ if (isNullOrUndefined(newConfig_1[field])) {
1766
+ var cfgValue = config[field];
1767
+ if (!isNullOrUndefined(cfgValue)) {
1768
+ newConfig_1[field] = cfgValue;
1769
+ }
1724
1770
  }
1725
1771
  });
1726
1772
  }
1727
- };
1728
- _self.getChannelControls = function () {
1729
- return _channelQueue;
1730
- };
1731
- _self.initialize = function (config, core, extensions) {
1732
- if (_self.isInitialized()) {
1733
- return;
1773
+ theConfig = newConfig_1;
1774
+ }
1775
+ }
1776
+ return theConfig;
1777
+ }
1778
+ function _getConfig(identifier, field, defaultValue) {
1779
+ if (defaultValue === void 0) { defaultValue = false; }
1780
+ var theValue;
1781
+ var extConfig = _getExtCfg(identifier, null);
1782
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1783
+ theValue = extConfig[field];
1784
+ }
1785
+ else if (config && !isNullOrUndefined(config[field])) {
1786
+ theValue = config[field];
1787
+ }
1788
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1789
+ }
1790
+ function _iterateChain(cb) {
1791
+ var nextPlugin;
1792
+ while (!!(nextPlugin = context._next())) {
1793
+ var plugin = nextPlugin.getPlugin();
1794
+ if (plugin) {
1795
+ cb(plugin);
1796
+ }
1797
+ }
1798
+ }
1799
+ return context;
1800
+ }
1801
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1802
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1803
+ var context = internalContext.ctx;
1804
+ function _processNext(env) {
1805
+ var nextPlugin = internalContext._next();
1806
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1807
+ return !nextPlugin;
1808
+ }
1809
+ function _createNew(plugins, startAt) {
1810
+ if (plugins === void 0) { plugins = null; }
1811
+ if (isArray(plugins)) {
1812
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1813
+ }
1814
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1815
+ }
1816
+ context.processNext = _processNext;
1817
+ context.createNew = _createNew;
1818
+ return context;
1819
+ }
1820
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1821
+ var config = core.config || {};
1822
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1823
+ var context = internalContext.ctx;
1824
+ function _processNext(unloadState) {
1825
+ var nextPlugin = internalContext._next();
1826
+ nextPlugin && nextPlugin.unload(context, unloadState);
1827
+ return !nextPlugin;
1828
+ }
1829
+ function _createNew(plugins, startAt) {
1830
+ if (plugins === void 0) { plugins = null; }
1831
+ if (isArray(plugins)) {
1832
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1833
+ }
1834
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1835
+ }
1836
+ context.processNext = _processNext;
1837
+ context.createNew = _createNew;
1838
+ return context;
1839
+ }
1840
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1841
+ var config = core.config || {};
1842
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1843
+ var context = internalContext.ctx;
1844
+ function _processNext(updateState) {
1845
+ return context.iterate(function (plugin) {
1846
+ if (isFunction(plugin.update)) {
1847
+ plugin.update(context, updateState);
1848
+ }
1849
+ });
1850
+ }
1851
+ function _createNew(plugins, startAt) {
1852
+ if (plugins === void 0) { plugins = null; }
1853
+ if (isArray(plugins)) {
1854
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1855
+ }
1856
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1857
+ }
1858
+ context.processNext = _processNext;
1859
+ context.createNew = _createNew;
1860
+ return context;
1861
+ }
1862
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1863
+ var firstProxy = null;
1864
+ var add = startAt ? false : true;
1865
+ if (isArray(plugins) && plugins.length > 0) {
1866
+ var lastProxy_1 = null;
1867
+ arrForEach(plugins, function (thePlugin) {
1868
+ if (!add && startAt === thePlugin) {
1869
+ add = true;
1870
+ }
1871
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1872
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1873
+ if (!firstProxy) {
1874
+ firstProxy = newProxy;
1734
1875
  }
1735
- _base.initialize(config, core, extensions);
1736
- _createChannelQueues((config || {}).channels, extensions);
1737
- arrForEach(_channelQueue, function (queue) { return initializePlugins(new ProcessTelemetryContext(queue, config, core), extensions); });
1738
- };
1876
+ if (lastProxy_1) {
1877
+ lastProxy_1._setNext(newProxy);
1878
+ }
1879
+ lastProxy_1 = newProxy;
1880
+ }
1739
1881
  });
1740
- function _checkQueuePriority(queue) {
1741
- arrForEach(queue, function (queueItem) {
1742
- if (queueItem.priority < ChannelControllerPriority) {
1743
- throwError(ChannelValidationMessage + queueItem.identifier);
1882
+ }
1883
+ if (startAt && !firstProxy) {
1884
+ return createTelemetryProxyChain([startAt], config, core);
1885
+ }
1886
+ return firstProxy;
1887
+ }
1888
+ function createTelemetryPluginProxy(plugin, config, core) {
1889
+ var nextProxy = null;
1890
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1891
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1892
+ var chainId;
1893
+ if (plugin) {
1894
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1895
+ }
1896
+ else {
1897
+ chainId = "Unknown-0-" + _chainId++;
1898
+ }
1899
+ var proxyChain = {
1900
+ getPlugin: function () {
1901
+ return plugin;
1902
+ },
1903
+ getNext: function () {
1904
+ return nextProxy;
1905
+ },
1906
+ processTelemetry: _processTelemetry,
1907
+ unload: _unloadPlugin,
1908
+ update: _updatePlugin,
1909
+ _id: chainId,
1910
+ _setNext: function (nextPlugin) {
1911
+ nextProxy = nextPlugin;
1912
+ }
1913
+ };
1914
+ function _getTelCtx() {
1915
+ var itemCtx;
1916
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1917
+ itemCtx = plugin[strGetTelCtx]();
1918
+ }
1919
+ if (!itemCtx) {
1920
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1921
+ }
1922
+ return itemCtx;
1923
+ }
1924
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1925
+ var hasRun = false;
1926
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1927
+ var hasRunContext = itemCtx[strHasRunFlags];
1928
+ if (!hasRunContext) {
1929
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1930
+ }
1931
+ itemCtx.setNext(nextProxy);
1932
+ if (plugin) {
1933
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1934
+ hasRunContext[chainId] = true;
1935
+ try {
1936
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1937
+ if (nextId) {
1938
+ hasRunContext[nextId] = false;
1939
+ }
1940
+ hasRun = processPluginFn(itemCtx);
1744
1941
  }
1745
- });
1942
+ catch (error) {
1943
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1944
+ if (hasNextRun) {
1945
+ hasRun = true;
1946
+ }
1947
+ if (!nextProxy || !hasNextRun) {
1948
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1949
+ }
1950
+ }
1951
+ }, details, isAsync);
1746
1952
  }
1747
- function _addChannelQueue(queue) {
1748
- if (queue && queue.length > 0) {
1749
- queue = queue.sort(function (a, b) {
1750
- return a.priority - b.priority;
1751
- });
1752
- _checkQueuePriority(queue);
1753
- _channelQueue.push(queue);
1953
+ return hasRun;
1954
+ }
1955
+ function _processTelemetry(env, itemCtx) {
1956
+ itemCtx = itemCtx || _getTelCtx();
1957
+ function _callProcessTelemetry(itemCtx) {
1958
+ if (!plugin || !hasProcessTelemetry) {
1959
+ return false;
1754
1960
  }
1961
+ var pluginState = _getPluginState(plugin);
1962
+ if (pluginState.teardown || pluginState[strDisabled]) {
1963
+ return false;
1964
+ }
1965
+ if (hasSetNext) {
1966
+ plugin.setNextPlugin(nextProxy);
1967
+ }
1968
+ plugin.processTelemetry(env, itemCtx);
1969
+ return true;
1755
1970
  }
1756
- function _createChannelQueues(channels, extensions) {
1757
- _channelQueue = [];
1758
- if (channels) {
1759
- arrForEach(channels, function (queue) { return _addChannelQueue(queue); });
1971
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1972
+ itemCtx.processNext(env);
1973
+ }
1974
+ }
1975
+ function _unloadPlugin(unloadCtx, unloadState) {
1976
+ function _callTeardown() {
1977
+ var hasRun = false;
1978
+ if (plugin) {
1979
+ var pluginState = _getPluginState(plugin);
1980
+ var pluginCore = plugin[strCore] || pluginState.core;
1981
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1982
+ pluginState[strCore] = null;
1983
+ pluginState[strTeardown] = true;
1984
+ pluginState[strIsInitialized] = false;
1985
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1986
+ hasRun = true;
1987
+ }
1988
+ }
1760
1989
  }
1761
- if (extensions) {
1762
- var extensionQueue_1 = [];
1763
- arrForEach(extensions, function (plugin) {
1764
- if (plugin.priority > ChannelControllerPriority) {
1765
- extensionQueue_1.push(plugin);
1990
+ return hasRun;
1991
+ }
1992
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1993
+ unloadCtx.processNext(unloadState);
1994
+ }
1995
+ }
1996
+ function _updatePlugin(updateCtx, updateState) {
1997
+ function _callUpdate() {
1998
+ var hasRun = false;
1999
+ if (plugin) {
2000
+ var pluginState = _getPluginState(plugin);
2001
+ var pluginCore = plugin[strCore] || pluginState.core;
2002
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
2003
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
2004
+ hasRun = true;
1766
2005
  }
1767
- });
1768
- _addChannelQueue(extensionQueue_1);
2006
+ }
1769
2007
  }
2008
+ return hasRun;
2009
+ }
2010
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
2011
+ updateCtx.processNext(updateState);
1770
2012
  }
1771
- return _this;
1772
2013
  }
1773
- ChannelController._staticInit = (function () {
1774
- var proto = ChannelController.prototype;
1775
- objDefineAccessors(proto, "ChannelControls", proto.getChannelControls);
1776
- objDefineAccessors(proto, "channelQueue", proto.getChannelControls);
1777
- })();
1778
- return ChannelController;
1779
- }(BaseTelemetryPlugin));
2014
+ return objFreeze(proxyChain);
2015
+ }
2016
+ var ProcessTelemetryContext = /** @class */ (function () {
2017
+ function ProcessTelemetryContext(pluginChain, config, core, startAt) {
2018
+ var _self = this;
2019
+ var context = createProcessTelemetryContext(pluginChain, config, core, startAt);
2020
+ proxyFunctions(_self, context, objKeys(context));
2021
+ }
2022
+ return ProcessTelemetryContext;
2023
+ }());
1780
2024
 
1781
2025
  var strToGMTString = "toGMTString";
1782
2026
  var strToUTCString = "toUTCString";
@@ -1786,7 +2030,6 @@
1786
2030
  var strIsCookieUseDisabled = "isCookieUseDisabled";
1787
2031
  var strDisableCookiesUsage = "disableCookiesUsage";
1788
2032
  var strConfigCookieMgr = "_ckMgr";
1789
- var strEmpty = "";
1790
2033
  var _supportsCookies = null;
1791
2034
  var _allowUaSameSite = null;
1792
2035
  var _parsedCookieValue = null;
@@ -1931,119 +2174,617 @@
1931
2174
  delCookie(name, _formatCookieValue(strEmpty, values));
1932
2175
  result = true;
1933
2176
  }
1934
- return result;
1935
- }
1936
- };
1937
- cookieMgr[strConfigCookieMgr] = cookieMgr;
1938
- return cookieMgr;
1939
- }
1940
- function areCookiesSupported(logger) {
1941
- if (_supportsCookies === null) {
1942
- _supportsCookies = false;
1943
- try {
1944
- var doc = _doc || {};
1945
- _supportsCookies = doc[strCookie] !== undefined;
2177
+ return result;
2178
+ }
2179
+ };
2180
+ cookieMgr[strConfigCookieMgr] = cookieMgr;
2181
+ return cookieMgr;
2182
+ }
2183
+ function areCookiesSupported(logger) {
2184
+ if (_supportsCookies === null) {
2185
+ _supportsCookies = false;
2186
+ try {
2187
+ var doc = _doc || {};
2188
+ _supportsCookies = doc[strCookie] !== undefined;
2189
+ }
2190
+ catch (e) {
2191
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2192
+ }
2193
+ }
2194
+ return _supportsCookies;
2195
+ }
2196
+ function _extractParts(theValue) {
2197
+ var values = {};
2198
+ if (theValue && theValue.length) {
2199
+ var parts = strTrim(theValue).split(";");
2200
+ arrForEach(parts, function (thePart) {
2201
+ thePart = strTrim(thePart || strEmpty);
2202
+ if (thePart) {
2203
+ var idx = thePart.indexOf("=");
2204
+ if (idx === -1) {
2205
+ values[thePart] = null;
2206
+ }
2207
+ else {
2208
+ values[strTrim(thePart.substring(0, idx))] = strTrim(thePart.substring(idx + 1));
2209
+ }
2210
+ }
2211
+ });
2212
+ }
2213
+ return values;
2214
+ }
2215
+ function _formatDate(theDate, func) {
2216
+ if (isFunction(theDate[func])) {
2217
+ return theDate[func]();
2218
+ }
2219
+ return null;
2220
+ }
2221
+ function _formatCookieValue(value, values) {
2222
+ var cookieValue = value || strEmpty;
2223
+ objForEachKey(values, function (name, theValue) {
2224
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
2225
+ });
2226
+ return cookieValue;
2227
+ }
2228
+ function _getCookieValue(name) {
2229
+ var cookieValue = strEmpty;
2230
+ if (_doc) {
2231
+ var theCookie = _doc[strCookie] || strEmpty;
2232
+ if (_parsedCookieValue !== theCookie) {
2233
+ _cookieCache = _extractParts(theCookie);
2234
+ _parsedCookieValue = theCookie;
2235
+ }
2236
+ cookieValue = strTrim(_cookieCache[name] || strEmpty);
2237
+ }
2238
+ return cookieValue;
2239
+ }
2240
+ function _setCookieValue(name, cookieValue) {
2241
+ if (_doc) {
2242
+ _doc[strCookie] = name + "=" + cookieValue;
2243
+ }
2244
+ }
2245
+ function uaDisallowsSameSiteNone(userAgent) {
2246
+ if (!isString(userAgent)) {
2247
+ return false;
2248
+ }
2249
+ if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
2250
+ return true;
2251
+ }
2252
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
2253
+ return true;
2254
+ }
2255
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
2256
+ return true;
2257
+ }
2258
+ if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
2259
+ return true;
2260
+ }
2261
+ if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
2262
+ return true;
2263
+ }
2264
+ if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
2265
+ return true;
2266
+ }
2267
+ return false;
2268
+ }
2269
+
2270
+ var strIKey = "iKey";
2271
+ var strExtensionConfig = "extensionConfig";
2272
+
2273
+ var ChannelControllerPriority = 500;
2274
+ var ChannelValidationMessage = "Channel has invalid priority - ";
2275
+ function _addChannelQueue(channelQueue, queue, config, core) {
2276
+ if (queue && isArray(queue) && queue.length > 0) {
2277
+ queue = queue.sort(function (a, b) {
2278
+ return a.priority - b.priority;
2279
+ });
2280
+ arrForEach(queue, function (queueItem) {
2281
+ if (queueItem.priority < ChannelControllerPriority) {
2282
+ throwError(ChannelValidationMessage + queueItem.identifier);
2283
+ }
2284
+ });
2285
+ channelQueue.push({
2286
+ queue: objFreeze(queue),
2287
+ chain: createTelemetryProxyChain(queue, config, core)
2288
+ });
2289
+ }
2290
+ }
2291
+ function createChannelControllerPlugin(channelQueue, core) {
2292
+ var _a;
2293
+ function _getTelCtx() {
2294
+ return createProcessTelemetryContext(null, core.config, core, null);
2295
+ }
2296
+ function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2297
+ var waiting = theChannels ? (theChannels.length + 1) : 1;
2298
+ function _runChainOnComplete() {
2299
+ waiting--;
2300
+ if (waiting === 0) {
2301
+ onComplete && onComplete();
2302
+ onComplete = null;
2303
+ }
2304
+ }
2305
+ if (waiting > 0) {
2306
+ arrForEach(theChannels, function (channels) {
2307
+ if (channels && channels.queue.length > 0) {
2308
+ var channelChain = channels.chain;
2309
+ var chainCtx = itemCtx.createNew(channelChain);
2310
+ chainCtx.onComplete(_runChainOnComplete);
2311
+ processFn(chainCtx);
2312
+ }
2313
+ else {
2314
+ waiting--;
2315
+ }
2316
+ });
2317
+ }
2318
+ _runChainOnComplete();
2319
+ }
2320
+ function _doUpdate(updateCtx, updateState) {
2321
+ var theUpdateState = updateState || {
2322
+ reason: 0
2323
+ };
2324
+ _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2325
+ chainCtx[strProcessNext](theUpdateState);
2326
+ }, function () {
2327
+ updateCtx[strProcessNext](theUpdateState);
2328
+ });
2329
+ return true;
2330
+ }
2331
+ function _doTeardown(unloadCtx, unloadState) {
2332
+ var theUnloadState = unloadState || {
2333
+ reason: 0 ,
2334
+ isAsync: false
2335
+ };
2336
+ _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2337
+ chainCtx[strProcessNext](theUnloadState);
2338
+ }, function () {
2339
+ unloadCtx[strProcessNext](theUnloadState);
2340
+ isInitialized = false;
2341
+ });
2342
+ return true;
2343
+ }
2344
+ function _getChannel(pluginIdentifier) {
2345
+ var thePlugin = null;
2346
+ if (channelQueue && channelQueue.length > 0) {
2347
+ arrForEach(channelQueue, function (channels) {
2348
+ if (channels && channels.queue.length > 0) {
2349
+ arrForEach(channels.queue, function (ext) {
2350
+ if (ext.identifier === pluginIdentifier) {
2351
+ thePlugin = ext;
2352
+ return -1;
2353
+ }
2354
+ });
2355
+ if (thePlugin) {
2356
+ return -1;
2357
+ }
2358
+ }
2359
+ });
2360
+ }
2361
+ return thePlugin;
2362
+ }
2363
+ var isInitialized = false;
2364
+ var channelController = (_a = {
2365
+ identifier: "ChannelControllerPlugin",
2366
+ priority: ChannelControllerPriority,
2367
+ initialize: function (config, core, extensions, pluginChain) {
2368
+ isInitialized = true;
2369
+ arrForEach(channelQueue, function (channels) {
2370
+ if (channels && channels.queue.length > 0) {
2371
+ initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2372
+ }
2373
+ });
2374
+ },
2375
+ isInitialized: function () {
2376
+ return isInitialized;
2377
+ },
2378
+ processTelemetry: function (item, itemCtx) {
2379
+ _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2380
+ chainCtx[strProcessNext](item);
2381
+ }, function () {
2382
+ itemCtx[strProcessNext](item);
2383
+ });
2384
+ },
2385
+ update: _doUpdate
2386
+ },
2387
+ _a[strPause] = function () {
2388
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2389
+ chainCtx.iterate(function (plugin) {
2390
+ plugin[strPause] && plugin[strPause]();
2391
+ });
2392
+ }, null);
2393
+ },
2394
+ _a[strResume] = function () {
2395
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2396
+ chainCtx.iterate(function (plugin) {
2397
+ plugin[strResume] && plugin[strResume]();
2398
+ });
2399
+ }, null);
2400
+ },
2401
+ _a[strTeardown] = _doTeardown,
2402
+ _a.getChannel = _getChannel,
2403
+ _a.flush = function (isAsync, callBack, sendReason, cbTimeout) {
2404
+ var waiting = 1;
2405
+ var doneIterating = false;
2406
+ var cbTimer = null;
2407
+ cbTimeout = cbTimeout || 5000;
2408
+ function doCallback() {
2409
+ waiting--;
2410
+ if (doneIterating && waiting === 0) {
2411
+ if (cbTimer) {
2412
+ clearTimeout(cbTimer);
2413
+ cbTimer = null;
2414
+ }
2415
+ callBack && callBack(doneIterating);
2416
+ callBack = null;
2417
+ }
2418
+ }
2419
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2420
+ chainCtx.iterate(function (plugin) {
2421
+ if (plugin.flush) {
2422
+ waiting++;
2423
+ var handled_1 = false;
2424
+ if (!plugin.flush(isAsync, function () {
2425
+ handled_1 = true;
2426
+ doCallback();
2427
+ }, sendReason)) {
2428
+ if (!handled_1) {
2429
+ if (isAsync && cbTimer == null) {
2430
+ cbTimer = setTimeout(function () {
2431
+ cbTimer = null;
2432
+ doCallback();
2433
+ }, cbTimeout);
2434
+ }
2435
+ else {
2436
+ doCallback();
2437
+ }
2438
+ }
2439
+ }
2440
+ }
2441
+ });
2442
+ }, function () {
2443
+ doneIterating = true;
2444
+ doCallback();
2445
+ });
2446
+ return true;
2447
+ },
2448
+ _a._setQueue = function (queue) {
2449
+ channelQueue = queue;
2450
+ },
2451
+ _a);
2452
+ return channelController;
2453
+ }
2454
+ function createChannelQueues(channels, extensions, config, core) {
2455
+ var channelQueue = [];
2456
+ if (channels) {
2457
+ arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, config, core); });
2458
+ }
2459
+ if (extensions) {
2460
+ var extensionQueue_1 = [];
2461
+ arrForEach(extensions, function (plugin) {
2462
+ if (plugin.priority > ChannelControllerPriority) {
2463
+ extensionQueue_1.push(plugin);
2464
+ }
2465
+ });
2466
+ _addChannelQueue(channelQueue, extensionQueue_1, config, core);
2467
+ }
2468
+ return channelQueue;
2469
+ }
2470
+
2471
+ function createUnloadHandlerContainer() {
2472
+ var handlers = [];
2473
+ function _addHandler(handler) {
2474
+ if (handler) {
2475
+ handlers.push(handler);
2476
+ }
2477
+ }
2478
+ function _runHandlers(unloadCtx, unloadState) {
2479
+ arrForEach(handlers, function (handler) {
2480
+ try {
2481
+ handler(unloadCtx, unloadState);
2482
+ }
2483
+ catch (e) {
2484
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2485
+ }
2486
+ });
2487
+ handlers = [];
2488
+ }
2489
+ return {
2490
+ add: _addHandler,
2491
+ run: _runHandlers
2492
+ };
2493
+ }
2494
+
2495
+ var strGetPlugin = "getPlugin";
2496
+ var BaseTelemetryPlugin = /** @class */ (function () {
2497
+ function BaseTelemetryPlugin() {
2498
+ var _self = this;
2499
+ var _isinitialized;
2500
+ var _rootCtx;
2501
+ var _nextPlugin;
2502
+ var _unloadHandlerContainer;
2503
+ var _hooks;
2504
+ _initDefaults();
2505
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
2506
+ _self.initialize = function (config, core, extensions, pluginChain) {
2507
+ _setDefaults(config, core, pluginChain);
2508
+ _isinitialized = true;
2509
+ };
2510
+ _self.teardown = function (unloadCtx, unloadState) {
2511
+ var core = _self.core;
2512
+ if (!core || (unloadCtx && core !== unloadCtx.core())) {
2513
+ return;
2514
+ }
2515
+ var result;
2516
+ var unloadDone = false;
2517
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2518
+ var theUnloadState = unloadState || {
2519
+ reason: 0 ,
2520
+ isAsync: false
2521
+ };
2522
+ function _unloadCallback() {
2523
+ if (!unloadDone) {
2524
+ unloadDone = true;
2525
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
2526
+ arrForEach(_hooks, function (fn) {
2527
+ fn.rm();
2528
+ });
2529
+ _hooks = [];
2530
+ if (result === true) {
2531
+ theUnloadCtx.processNext(theUnloadState);
2532
+ }
2533
+ _initDefaults();
2534
+ }
2535
+ }
2536
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
2537
+ _unloadCallback();
2538
+ }
2539
+ else {
2540
+ result = true;
2541
+ }
2542
+ return result;
2543
+ };
2544
+ _self.update = function (updateCtx, updateState) {
2545
+ var core = _self.core;
2546
+ if (!core || (updateCtx && core !== updateCtx.core())) {
2547
+ return;
2548
+ }
2549
+ var result;
2550
+ var updateDone = false;
2551
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2552
+ var theUpdateState = updateState || {
2553
+ reason: 0
2554
+ };
2555
+ function _updateCallback() {
2556
+ if (!updateDone) {
2557
+ updateDone = true;
2558
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
2559
+ }
2560
+ }
2561
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
2562
+ _updateCallback();
2563
+ }
2564
+ else {
2565
+ result = true;
2566
+ }
2567
+ return result;
2568
+ };
2569
+ _self._addHook = function (hooks) {
2570
+ if (hooks) {
2571
+ if (isArray(hooks)) {
2572
+ _hooks = _hooks.concat(hooks);
2573
+ }
2574
+ else {
2575
+ _hooks.push(hooks);
2576
+ }
2577
+ }
2578
+ };
2579
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
2580
+ });
2581
+ _self.diagLog = function (itemCtx) {
2582
+ return _getTelCtx(itemCtx).diagLog();
2583
+ };
2584
+ _self[strIsInitialized] = function () {
2585
+ return _isinitialized;
2586
+ };
2587
+ _self.setInitialized = function (isInitialized) {
2588
+ _isinitialized = isInitialized;
2589
+ };
2590
+ _self[strSetNextPlugin] = function (next) {
2591
+ _nextPlugin = next;
2592
+ };
2593
+ _self.processNext = function (env, itemCtx) {
2594
+ if (itemCtx) {
2595
+ itemCtx.processNext(env);
2596
+ }
2597
+ else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
2598
+ _nextPlugin.processTelemetry(env, null);
2599
+ }
2600
+ };
2601
+ _self._getTelCtx = _getTelCtx;
2602
+ function _getTelCtx(currentCtx) {
2603
+ if (currentCtx === void 0) { currentCtx = null; }
2604
+ var itemCtx = currentCtx;
2605
+ if (!itemCtx) {
2606
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
2607
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2608
+ itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
2609
+ }
2610
+ else {
2611
+ itemCtx = rootCtx.createNew(null, _nextPlugin);
2612
+ }
2613
+ }
2614
+ return itemCtx;
2615
+ }
2616
+ function _setDefaults(config, core, pluginChain) {
2617
+ if (config) {
2618
+ setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
2619
+ }
2620
+ if (!pluginChain && core) {
2621
+ pluginChain = core.getProcessTelContext().getNext();
2622
+ }
2623
+ var nextPlugin = _nextPlugin;
2624
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2625
+ nextPlugin = _nextPlugin[strGetPlugin]();
2626
+ }
2627
+ _self.core = core;
2628
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1946
2629
  }
1947
- catch (e) {
1948
- logger && logger.throwInternal(exports.LoggingSeverity.WARNING, _InternalMessageId.CannotAccessCookie, "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2630
+ function _initDefaults() {
2631
+ _isinitialized = false;
2632
+ _self.core = null;
2633
+ _rootCtx = null;
2634
+ _nextPlugin = null;
2635
+ _hooks = [];
2636
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1949
2637
  }
1950
2638
  }
1951
- return _supportsCookies;
1952
- }
1953
- function _extractParts(theValue) {
1954
- var values = {};
1955
- if (theValue && theValue.length) {
1956
- var parts = strTrim(theValue).split(";");
1957
- arrForEach(parts, function (thePart) {
1958
- thePart = strTrim(thePart || strEmpty);
1959
- if (thePart) {
1960
- var idx = thePart.indexOf("=");
1961
- if (idx === -1) {
1962
- values[thePart] = null;
2639
+ return BaseTelemetryPlugin;
2640
+ }());
2641
+
2642
+ var TelemetryInitializerPlugin = /** @class */ (function (_super) {
2643
+ __extendsFn(TelemetryInitializerPlugin, _super);
2644
+ function TelemetryInitializerPlugin() {
2645
+ var _this = _super.call(this) || this;
2646
+ _this.identifier = "TelemetryInitializerPlugin";
2647
+ _this.priority = 199;
2648
+ var _id;
2649
+ var _initializers;
2650
+ _initDefaults();
2651
+ dynamicProto(TelemetryInitializerPlugin, _this, function (_self, _base) {
2652
+ _self.addTelemetryInitializer = function (telemetryInitializer) {
2653
+ var theInitializer = {
2654
+ id: _id++,
2655
+ fn: telemetryInitializer
2656
+ };
2657
+ _initializers.push(theInitializer);
2658
+ var handler = {
2659
+ remove: function () {
2660
+ arrForEach(_initializers, function (initializer, idx) {
2661
+ if (initializer.id === theInitializer.id) {
2662
+ _initializers.splice(idx, 1);
2663
+ return -1;
2664
+ }
2665
+ });
2666
+ }
2667
+ };
2668
+ return handler;
2669
+ };
2670
+ _self.processTelemetry = function (item, itemCtx) {
2671
+ var doNotSendItem = false;
2672
+ var telemetryInitializersCount = _initializers.length;
2673
+ for (var i = 0; i < telemetryInitializersCount; ++i) {
2674
+ var telemetryInitializer = _initializers[i];
2675
+ if (telemetryInitializer) {
2676
+ try {
2677
+ if (telemetryInitializer.fn.apply(null, [item]) === false) {
2678
+ doNotSendItem = true;
2679
+ break;
2680
+ }
2681
+ }
2682
+ catch (e) {
2683
+ _throwInternal(itemCtx.diagLog(), 1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2684
+ }
2685
+ }
1963
2686
  }
1964
- else {
1965
- values[strTrim(thePart.substring(0, idx))] = strTrim(thePart.substring(idx + 1));
2687
+ if (!doNotSendItem) {
2688
+ _self.processNext(item, itemCtx);
1966
2689
  }
1967
- }
2690
+ };
2691
+ _self[strDoTeardown] = function () {
2692
+ _initDefaults();
2693
+ };
1968
2694
  });
1969
- }
1970
- return values;
1971
- }
1972
- function _formatDate(theDate, func) {
1973
- if (isFunction(theDate[func])) {
1974
- return theDate[func]();
1975
- }
1976
- return null;
1977
- }
1978
- function _formatCookieValue(value, values) {
1979
- var cookieValue = value || strEmpty;
1980
- objForEachKey(values, function (name, theValue) {
1981
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
1982
- });
1983
- return cookieValue;
1984
- }
1985
- function _getCookieValue(name) {
1986
- var cookieValue = strEmpty;
1987
- if (_doc) {
1988
- var theCookie = _doc[strCookie] || strEmpty;
1989
- if (_parsedCookieValue !== theCookie) {
1990
- _cookieCache = _extractParts(theCookie);
1991
- _parsedCookieValue = theCookie;
2695
+ function _initDefaults() {
2696
+ _id = 0;
2697
+ _initializers = [];
1992
2698
  }
1993
- cookieValue = strTrim(_cookieCache[name] || strEmpty);
1994
- }
1995
- return cookieValue;
1996
- }
1997
- function _setCookieValue(name, cookieValue) {
1998
- if (_doc) {
1999
- _doc[strCookie] = name + "=" + cookieValue;
2000
- }
2001
- }
2002
- function uaDisallowsSameSiteNone(userAgent) {
2003
- if (!isString(userAgent)) {
2004
- return false;
2005
- }
2006
- if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
2007
- return true;
2008
- }
2009
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
2010
- return true;
2011
- }
2012
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
2013
- return true;
2014
- }
2015
- if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
2016
- return true;
2017
- }
2018
- if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
2019
- return true;
2020
- }
2021
- if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
2022
- return true;
2699
+ return _this;
2023
2700
  }
2024
- return false;
2025
- }
2701
+ return TelemetryInitializerPlugin;
2702
+ }(BaseTelemetryPlugin));
2026
2703
 
2027
- var validationError = "Extensions must provide callback to initialize";
2704
+ var strValidationError = "Plugins must provide initialize method";
2028
2705
  var strNotificationManager = "_notificationManager";
2706
+ var strSdkUnloadingError = "SDK is still unloading...";
2707
+ var strSdkNotInitialized = "SDK is not initialized";
2708
+ var defaultInitConfig = {
2709
+ loggingLevelConsole: 1
2710
+ };
2029
2711
  function _createPerfManager(core, notificationMgr) {
2030
2712
  return new PerfManager(notificationMgr);
2031
2713
  }
2714
+ function _validateExtensions(logger, channelPriority, allExtensions) {
2715
+ var coreExtensions = [];
2716
+ var extPriorities = {};
2717
+ arrForEach(allExtensions, function (ext) {
2718
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
2719
+ throwError(strValidationError);
2720
+ }
2721
+ var extPriority = ext.priority;
2722
+ var identifier = ext.identifier;
2723
+ if (ext && extPriority) {
2724
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
2725
+ _warnToConsole(logger, "Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
2726
+ }
2727
+ else {
2728
+ extPriorities[extPriority] = identifier;
2729
+ }
2730
+ }
2731
+ if (!extPriority || extPriority < channelPriority) {
2732
+ coreExtensions.push(ext);
2733
+ }
2734
+ });
2735
+ return {
2736
+ all: allExtensions,
2737
+ core: coreExtensions
2738
+ };
2739
+ }
2740
+ function _isPluginPresent(thePlugin, plugins) {
2741
+ var exists = false;
2742
+ arrForEach(plugins, function (plugin) {
2743
+ if (plugin === thePlugin) {
2744
+ exists = true;
2745
+ return -1;
2746
+ }
2747
+ });
2748
+ return exists;
2749
+ }
2750
+ function _createDummyNotificationManager() {
2751
+ var _a;
2752
+ return objCreateFn((_a = {},
2753
+ _a[strAddNotificationListener] = function (listener) { },
2754
+ _a[strRemoveNotificationListener] = function (listener) { },
2755
+ _a[strEventsSent] = function (events) { },
2756
+ _a[strEventsDiscarded] = function (events, reason) { },
2757
+ _a[strEventsSendRequest] = function (sendReason, isAsync) { },
2758
+ _a));
2759
+ }
2032
2760
  var BaseCore$2 = /** @class */ (function () {
2033
2761
  function BaseCore() {
2034
- var _isInitialized = false;
2762
+ var _isInitialized;
2035
2763
  var _eventQueue;
2036
- var _channelController;
2037
2764
  var _notificationManager;
2038
2765
  var _perfManager;
2766
+ var _cfgPerfManager;
2039
2767
  var _cookieManager;
2768
+ var _pluginChain;
2769
+ var _configExtensions;
2770
+ var _coreExtensions;
2771
+ var _channelControl;
2772
+ var _channelConfig;
2773
+ var _channelQueue;
2774
+ var _isUnloading;
2775
+ var _telemetryInitializerPlugin;
2776
+ var _internalLogsEventName;
2777
+ var _evtNamespace;
2778
+ var _unloadHandlers;
2779
+ var _debugListener;
2780
+ var _internalLogPoller = 0;
2040
2781
  dynamicProto(BaseCore, this, function (_self) {
2041
- _self._extensions = new Array();
2042
- _channelController = new ChannelController();
2043
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: exports.LoggingSeverity.CRITICAL });
2044
- _eventQueue = [];
2782
+ _initDefaults();
2045
2783
  _self.isInitialized = function () { return _isInitialized; };
2046
2784
  _self.initialize = function (config, extensions, logger, notificationManager) {
2785
+ if (_isUnloading) {
2786
+ throwError(strSdkUnloadingError);
2787
+ }
2047
2788
  if (_self.isInitialized()) {
2048
2789
  throwError("Core should not be initialized more than once");
2049
2790
  }
@@ -2053,185 +2794,460 @@
2053
2794
  _notificationManager = notificationManager;
2054
2795
  _self[strNotificationManager] = notificationManager;
2055
2796
  _self.config = config || {};
2056
- if (notificationManager && _self.config.disableDbgExt !== true) {
2057
- notificationManager.addNotificationListener(getDebugListener(config));
2058
- }
2059
- if (_self.config.enablePerfMgr) {
2060
- setValue(_self.config, "createPerfMgr", _createPerfManager);
2061
- }
2797
+ _initDebugListener(config);
2798
+ _initPerfManager(config);
2062
2799
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
2063
- var extConfig = getSetValue(config, strExtensionConfig);
2064
- extConfig.NotificationManager = notificationManager;
2800
+ _initExtConfig(config);
2065
2801
  if (logger) {
2066
2802
  _self.logger = logger;
2067
2803
  }
2068
- var allExtensions = [];
2069
- allExtensions.push.apply(allExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2070
- allExtensions = sortPlugins(allExtensions);
2071
- var coreExtensions = [];
2072
- var extPriorities = {};
2073
- arrForEach(allExtensions, function (ext) {
2074
- if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
2075
- throwError(validationError);
2076
- }
2077
- var extPriority = ext.priority;
2078
- var identifier = ext.identifier;
2079
- if (ext && extPriority) {
2080
- if (!isNullOrUndefined(extPriorities[extPriority])) {
2081
- logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
2082
- }
2083
- else {
2084
- extPriorities[extPriority] = identifier;
2085
- }
2086
- }
2087
- if (!extPriority || extPriority < _channelController.priority) {
2088
- coreExtensions.push(ext);
2089
- }
2090
- });
2091
- allExtensions.push(_channelController);
2092
- coreExtensions.push(_channelController);
2093
- allExtensions = sortPlugins(allExtensions);
2094
- _self._extensions = allExtensions;
2095
- initializePlugins(new ProcessTelemetryContext([_channelController], config, _self), allExtensions);
2096
- initializePlugins(new ProcessTelemetryContext(coreExtensions, config, _self), allExtensions);
2097
- _self._extensions = coreExtensions;
2098
- if (_self.getTransmissionControls().length === 0) {
2804
+ _configExtensions = [];
2805
+ _configExtensions.push.apply(_configExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2806
+ _channelConfig = (config || {}).channels;
2807
+ _initPluginChain(config, null);
2808
+ if (!_channelQueue || _channelQueue.length === 0) {
2099
2809
  throwError("No channels available");
2100
2810
  }
2101
2811
  _isInitialized = true;
2102
2812
  _self.releaseQueue();
2103
2813
  };
2104
2814
  _self.getTransmissionControls = function () {
2105
- return _channelController.getChannelControls();
2815
+ var controls = [];
2816
+ if (_channelQueue) {
2817
+ arrForEach(_channelQueue, function (channels) {
2818
+ controls.push(channels.queue);
2819
+ });
2820
+ }
2821
+ return objFreeze(controls);
2106
2822
  };
2107
2823
  _self.track = function (telemetryItem) {
2108
2824
  setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
2109
2825
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
2110
2826
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
2111
- if (_self.isInitialized()) {
2112
- _self.getProcessTelContext().processNext(telemetryItem);
2827
+ if (!_isUnloading && _self.isInitialized()) {
2828
+ _createTelCtx().processNext(telemetryItem);
2113
2829
  }
2114
2830
  else {
2115
2831
  _eventQueue.push(telemetryItem);
2116
2832
  }
2117
2833
  };
2118
- _self.getProcessTelContext = function () {
2119
- var extensions = _self._extensions;
2120
- var thePlugins = extensions;
2121
- if (!extensions || extensions.length === 0) {
2122
- thePlugins = [_channelController];
2123
- }
2124
- return new ProcessTelemetryContext(thePlugins, _self.config, _self);
2125
- };
2834
+ _self.getProcessTelContext = _createTelCtx;
2126
2835
  _self.getNotifyMgr = function () {
2127
2836
  if (!_notificationManager) {
2128
- _notificationManager = objCreateFn({
2129
- addNotificationListener: function (listener) { },
2130
- removeNotificationListener: function (listener) { },
2131
- eventsSent: function (events) { },
2132
- eventsDiscarded: function (events, reason) { },
2133
- eventsSendRequest: function (sendReason, isAsync) { }
2134
- });
2837
+ _notificationManager = _createDummyNotificationManager();
2135
2838
  _self[strNotificationManager] = _notificationManager;
2136
2839
  }
2137
2840
  return _notificationManager;
2138
2841
  };
2842
+ _self[strAddNotificationListener] = function (listener) {
2843
+ if (_notificationManager) {
2844
+ _notificationManager[strAddNotificationListener](listener);
2845
+ }
2846
+ };
2847
+ _self[strRemoveNotificationListener] = function (listener) {
2848
+ if (_notificationManager) {
2849
+ _notificationManager[strRemoveNotificationListener](listener);
2850
+ }
2851
+ };
2139
2852
  _self.getCookieMgr = function () {
2140
2853
  if (!_cookieManager) {
2141
2854
  _cookieManager = createCookieMgr(_self.config, _self.logger);
2142
2855
  }
2143
- return _cookieManager;
2144
- };
2145
- _self.setCookieMgr = function (cookieMgr) {
2146
- _cookieManager = cookieMgr;
2147
- };
2148
- _self.getPerfMgr = function () {
2149
- if (!_perfManager) {
2150
- if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
2151
- _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
2152
- }
2856
+ return _cookieManager;
2857
+ };
2858
+ _self.setCookieMgr = function (cookieMgr) {
2859
+ _cookieManager = cookieMgr;
2860
+ };
2861
+ _self.getPerfMgr = function () {
2862
+ if (!_perfManager && !_cfgPerfManager) {
2863
+ if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
2864
+ _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
2865
+ }
2866
+ }
2867
+ return _perfManager || _cfgPerfManager || getGblPerfMgr();
2868
+ };
2869
+ _self.setPerfMgr = function (perfMgr) {
2870
+ _perfManager = perfMgr;
2871
+ };
2872
+ _self.eventCnt = function () {
2873
+ return _eventQueue.length;
2874
+ };
2875
+ _self.releaseQueue = function () {
2876
+ if (_isInitialized && _eventQueue.length > 0) {
2877
+ var eventQueue = _eventQueue;
2878
+ _eventQueue = [];
2879
+ arrForEach(eventQueue, function (event) {
2880
+ _createTelCtx().processNext(event);
2881
+ });
2882
+ }
2883
+ };
2884
+ _self.pollInternalLogs = function (eventName) {
2885
+ _internalLogsEventName = eventName || null;
2886
+ var interval = _self.config.diagnosticLogInterval;
2887
+ if (!interval || !(interval > 0)) {
2888
+ interval = 10000;
2889
+ }
2890
+ if (_internalLogPoller) {
2891
+ clearInterval(_internalLogPoller);
2892
+ }
2893
+ _internalLogPoller = setInterval(function () {
2894
+ _flushInternalLogs();
2895
+ }, interval);
2896
+ return _internalLogPoller;
2897
+ };
2898
+ _self.stopPollingInternalLogs = function () {
2899
+ if (_internalLogPoller) {
2900
+ clearInterval(_internalLogPoller);
2901
+ _internalLogPoller = 0;
2902
+ _flushInternalLogs();
2903
+ }
2904
+ };
2905
+ proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
2906
+ _self.unload = function (isAsync, unloadComplete, cbTimeout) {
2907
+ if (isAsync === void 0) { isAsync = true; }
2908
+ if (!_isInitialized) {
2909
+ throwError(strSdkNotInitialized);
2910
+ }
2911
+ if (_isUnloading) {
2912
+ throwError(strSdkUnloadingError);
2913
+ }
2914
+ var unloadState = {
2915
+ reason: 50 ,
2916
+ isAsync: isAsync,
2917
+ flushComplete: false
2918
+ };
2919
+ var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self);
2920
+ processUnloadCtx.onComplete(function () {
2921
+ _initDefaults();
2922
+ unloadComplete && unloadComplete(unloadState);
2923
+ }, _self);
2924
+ function _doUnload(flushComplete) {
2925
+ unloadState.flushComplete = flushComplete;
2926
+ _isUnloading = true;
2927
+ _unloadHandlers.run(processUnloadCtx, unloadState);
2928
+ _self.stopPollingInternalLogs();
2929
+ processUnloadCtx.processNext(unloadState);
2930
+ }
2931
+ if (!_flushChannels(isAsync, _doUnload, 6 , cbTimeout)) {
2932
+ _doUnload(false);
2933
+ }
2934
+ };
2935
+ _self.getPlugin = _getPlugin;
2936
+ _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
2937
+ if (!plugin) {
2938
+ addCb && addCb(false);
2939
+ _logOrThrowError(strValidationError);
2940
+ return;
2941
+ }
2942
+ var existingPlugin = _getPlugin(plugin.identifier);
2943
+ if (existingPlugin && !replaceExisting) {
2944
+ addCb && addCb(false);
2945
+ _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2946
+ return;
2947
+ }
2948
+ var updateState = {
2949
+ reason: 16
2950
+ };
2951
+ function _addPlugin(removed) {
2952
+ _configExtensions.push(plugin);
2953
+ updateState.added = [plugin];
2954
+ _initPluginChain(_self.config, updateState);
2955
+ addCb && addCb(true);
2956
+ }
2957
+ if (existingPlugin) {
2958
+ var removedPlugins_1 = [existingPlugin.plugin];
2959
+ var unloadState = {
2960
+ reason: 2 ,
2961
+ isAsync: !!isAsync
2962
+ };
2963
+ _removePlugins(removedPlugins_1, unloadState, function (removed) {
2964
+ if (!removed) {
2965
+ addCb && addCb(false);
2966
+ }
2967
+ else {
2968
+ updateState.removed = removedPlugins_1;
2969
+ updateState.reason |= 32 ;
2970
+ _addPlugin();
2971
+ }
2972
+ });
2973
+ }
2974
+ else {
2975
+ _addPlugin();
2976
+ }
2977
+ };
2978
+ _self.evtNamespace = function () {
2979
+ return _evtNamespace;
2980
+ };
2981
+ _self.flush = _flushChannels;
2982
+ proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2983
+ function _initDefaults() {
2984
+ _isInitialized = false;
2985
+ _self.config = objExtend(true, {}, defaultInitConfig);
2986
+ _self.logger = new DiagnosticLogger(_self.config);
2987
+ _self._extensions = [];
2988
+ _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
2989
+ _eventQueue = [];
2990
+ _notificationManager = null;
2991
+ _perfManager = null;
2992
+ _cfgPerfManager = null;
2993
+ _cookieManager = null;
2994
+ _pluginChain = null;
2995
+ _coreExtensions = null;
2996
+ _configExtensions = [];
2997
+ _channelControl = null;
2998
+ _channelConfig = null;
2999
+ _channelQueue = null;
3000
+ _isUnloading = false;
3001
+ _internalLogsEventName = null;
3002
+ _evtNamespace = createUniqueNamespace("AIBaseCore", true);
3003
+ _unloadHandlers = createUnloadHandlerContainer();
3004
+ }
3005
+ function _createTelCtx() {
3006
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
3007
+ }
3008
+ function _initPluginChain(config, updateState) {
3009
+ var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
3010
+ _coreExtensions = theExtensions.core;
3011
+ _pluginChain = null;
3012
+ var allExtensions = theExtensions.all;
3013
+ _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
3014
+ if (_channelControl) {
3015
+ var idx = arrIndexOf(allExtensions, _channelControl);
3016
+ if (idx !== -1) {
3017
+ allExtensions.splice(idx, 1);
3018
+ }
3019
+ idx = arrIndexOf(_coreExtensions, _channelControl);
3020
+ if (idx !== -1) {
3021
+ _coreExtensions.splice(idx, 1);
3022
+ }
3023
+ _channelControl._setQueue(_channelQueue);
3024
+ }
3025
+ else {
3026
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
3027
+ }
3028
+ allExtensions.push(_channelControl);
3029
+ _coreExtensions.push(_channelControl);
3030
+ _self._extensions = sortPlugins(allExtensions);
3031
+ _channelControl.initialize(config, _self, allExtensions);
3032
+ initializePlugins(_createTelCtx(), allExtensions);
3033
+ _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
3034
+ if (updateState) {
3035
+ _doUpdate(updateState);
3036
+ }
3037
+ }
3038
+ function _getPlugin(pluginIdentifier) {
3039
+ var theExt = null;
3040
+ var thePlugin = null;
3041
+ arrForEach(_self._extensions, function (ext) {
3042
+ if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
3043
+ thePlugin = ext;
3044
+ return -1;
3045
+ }
3046
+ });
3047
+ if (!thePlugin && _channelControl) {
3048
+ thePlugin = _channelControl.getChannel(pluginIdentifier);
3049
+ }
3050
+ if (thePlugin) {
3051
+ theExt = {
3052
+ plugin: thePlugin,
3053
+ setEnabled: function (enabled) {
3054
+ _getPluginState(thePlugin)[strDisabled] = !enabled;
3055
+ },
3056
+ isEnabled: function () {
3057
+ var pluginState = _getPluginState(thePlugin);
3058
+ return !pluginState[strTeardown] && !pluginState[strDisabled];
3059
+ },
3060
+ remove: function (isAsync, removeCb) {
3061
+ if (isAsync === void 0) { isAsync = true; }
3062
+ var pluginsToRemove = [thePlugin];
3063
+ var unloadState = {
3064
+ reason: 1 ,
3065
+ isAsync: isAsync
3066
+ };
3067
+ _removePlugins(pluginsToRemove, unloadState, function (removed) {
3068
+ if (removed) {
3069
+ _initPluginChain(_self.config, {
3070
+ reason: 32 ,
3071
+ removed: pluginsToRemove
3072
+ });
3073
+ }
3074
+ removeCb && removeCb(removed);
3075
+ });
3076
+ }
3077
+ };
3078
+ }
3079
+ return theExt;
3080
+ }
3081
+ function _getPluginChain() {
3082
+ if (!_pluginChain) {
3083
+ var extensions = (_coreExtensions || []).slice();
3084
+ if (arrIndexOf(extensions, _telemetryInitializerPlugin) === -1) {
3085
+ extensions.push(_telemetryInitializerPlugin);
3086
+ }
3087
+ _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
3088
+ }
3089
+ return _pluginChain;
3090
+ }
3091
+ function _removePlugins(thePlugins, unloadState, removeComplete) {
3092
+ if (thePlugins && thePlugins.length > 0) {
3093
+ var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
3094
+ var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self);
3095
+ unloadCtx.onComplete(function () {
3096
+ var removed = false;
3097
+ var newConfigExtensions = [];
3098
+ arrForEach(_configExtensions, function (plugin, idx) {
3099
+ if (!_isPluginPresent(plugin, thePlugins)) {
3100
+ newConfigExtensions.push(plugin);
3101
+ }
3102
+ else {
3103
+ removed = true;
3104
+ }
3105
+ });
3106
+ _configExtensions = newConfigExtensions;
3107
+ var newChannelConfig = [];
3108
+ if (_channelConfig) {
3109
+ arrForEach(_channelConfig, function (queue, idx) {
3110
+ var newQueue = [];
3111
+ arrForEach(queue, function (channel) {
3112
+ if (!_isPluginPresent(channel, thePlugins)) {
3113
+ newQueue.push(channel);
3114
+ }
3115
+ else {
3116
+ removed = true;
3117
+ }
3118
+ });
3119
+ newChannelConfig.push(newQueue);
3120
+ });
3121
+ _channelConfig = newChannelConfig;
3122
+ }
3123
+ removeComplete && removeComplete(removed);
3124
+ });
3125
+ unloadCtx.processNext(unloadState);
3126
+ }
3127
+ else {
3128
+ removeComplete(false);
3129
+ }
3130
+ }
3131
+ function _flushInternalLogs() {
3132
+ var queue = _self.logger ? _self.logger.queue : [];
3133
+ if (queue) {
3134
+ arrForEach(queue, function (logMessage) {
3135
+ var item = {
3136
+ name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
3137
+ iKey: _self.config.instrumentationKey,
3138
+ time: toISOString(new Date()),
3139
+ baseType: _InternalLogMessage.dataType,
3140
+ baseData: { message: logMessage.message }
3141
+ };
3142
+ _self.track(item);
3143
+ });
3144
+ queue.length = 0;
3145
+ }
3146
+ }
3147
+ function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
3148
+ if (_channelControl) {
3149
+ return _channelControl.flush(isAsync, callBack, sendReason || 6 , cbTimeout);
3150
+ }
3151
+ callBack && callBack(false);
3152
+ return true;
3153
+ }
3154
+ function _initDebugListener(config) {
3155
+ if (config.disableDbgExt === true && _debugListener) {
3156
+ _notificationManager[strRemoveNotificationListener](_debugListener);
3157
+ _debugListener = null;
3158
+ }
3159
+ if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
3160
+ _debugListener = getDebugListener(config);
3161
+ _notificationManager[strAddNotificationListener](_debugListener);
3162
+ }
3163
+ }
3164
+ function _initPerfManager(config) {
3165
+ if (!config.enablePerfMgr && _cfgPerfManager) {
3166
+ _cfgPerfManager = null;
3167
+ }
3168
+ if (config.enablePerfMgr) {
3169
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
2153
3170
  }
2154
- return _perfManager || getGblPerfMgr();
2155
- };
2156
- _self.setPerfMgr = function (perfMgr) {
2157
- _perfManager = perfMgr;
2158
- };
2159
- _self.eventCnt = function () {
2160
- return _eventQueue.length;
2161
- };
2162
- _self.releaseQueue = function () {
2163
- if (_eventQueue.length > 0) {
2164
- arrForEach(_eventQueue, function (event) {
2165
- _self.getProcessTelContext().processNext(event);
2166
- });
2167
- _eventQueue = [];
3171
+ }
3172
+ function _initExtConfig(config) {
3173
+ var extConfig = getSetValue(config, strExtensionConfig);
3174
+ extConfig.NotificationManager = _notificationManager;
3175
+ }
3176
+ function _doUpdate(updateState) {
3177
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self);
3178
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3179
+ updateCtx.processNext(updateState);
2168
3180
  }
2169
- };
3181
+ }
3182
+ function _logOrThrowError(message) {
3183
+ var logger = _self.logger;
3184
+ if (logger) {
3185
+ _throwInternal(logger, 2 , 73 , message);
3186
+ }
3187
+ else {
3188
+ throwError(message);
3189
+ }
3190
+ }
2170
3191
  });
2171
3192
  }
2172
3193
  return BaseCore;
2173
3194
  }());
2174
3195
 
3196
+ function _runListeners(listeners, name, isAsync, callback) {
3197
+ arrForEach(listeners, function (listener) {
3198
+ if (listener && listener[name]) {
3199
+ if (isAsync) {
3200
+ setTimeout(function () { return callback(listener); }, 0);
3201
+ }
3202
+ else {
3203
+ try {
3204
+ callback(listener);
3205
+ }
3206
+ catch (e) {
3207
+ }
3208
+ }
3209
+ }
3210
+ });
3211
+ }
2175
3212
  var NotificationManager = /** @class */ (function () {
2176
3213
  function NotificationManager(config) {
2177
3214
  this.listeners = [];
2178
3215
  var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
2179
3216
  dynamicProto(NotificationManager, this, function (_self) {
2180
- _self.addNotificationListener = function (listener) {
3217
+ _self[strAddNotificationListener] = function (listener) {
2181
3218
  _self.listeners.push(listener);
2182
3219
  };
2183
- _self.removeNotificationListener = function (listener) {
3220
+ _self[strRemoveNotificationListener] = function (listener) {
2184
3221
  var index = arrIndexOf(_self.listeners, listener);
2185
3222
  while (index > -1) {
2186
3223
  _self.listeners.splice(index, 1);
2187
3224
  index = arrIndexOf(_self.listeners, listener);
2188
3225
  }
2189
3226
  };
2190
- _self.eventsSent = function (events) {
2191
- arrForEach(_self.listeners, function (listener) {
2192
- if (listener && listener.eventsSent) {
2193
- setTimeout(function () { return listener.eventsSent(events); }, 0);
2194
- }
3227
+ _self[strEventsSent] = function (events) {
3228
+ _runListeners(_self.listeners, strEventsSent, true, function (listener) {
3229
+ listener[strEventsSent](events);
2195
3230
  });
2196
3231
  };
2197
- _self.eventsDiscarded = function (events, reason) {
2198
- arrForEach(_self.listeners, function (listener) {
2199
- if (listener && listener.eventsDiscarded) {
2200
- setTimeout(function () { return listener.eventsDiscarded(events, reason); }, 0);
2201
- }
3232
+ _self[strEventsDiscarded] = function (events, reason) {
3233
+ _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
3234
+ listener[strEventsDiscarded](events, reason);
2202
3235
  });
2203
3236
  };
2204
- _self.eventsSendRequest = function (sendReason, isAsync) {
2205
- arrForEach(_self.listeners, function (listener) {
2206
- if (listener && listener.eventsSendRequest) {
2207
- if (isAsync) {
2208
- setTimeout(function () { return listener.eventsSendRequest(sendReason, isAsync); }, 0);
2209
- }
2210
- else {
2211
- try {
2212
- listener.eventsSendRequest(sendReason, isAsync);
2213
- }
2214
- catch (e) {
2215
- }
2216
- }
2217
- }
3237
+ _self[strEventsSendRequest] = function (sendReason, isAsync) {
3238
+ _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
3239
+ listener[strEventsSendRequest](sendReason, isAsync);
2218
3240
  });
2219
3241
  };
2220
- _self.perfEvent = function (perfEvent) {
3242
+ _self[strPerfEvent] = function (perfEvent) {
2221
3243
  if (perfEvent) {
2222
3244
  if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
2223
- arrForEach(_self.listeners, function (listener) {
2224
- if (listener && listener.perfEvent) {
2225
- if (perfEvent.isAsync) {
2226
- setTimeout(function () { return listener.perfEvent(perfEvent); }, 0);
2227
- }
2228
- else {
2229
- try {
2230
- listener.perfEvent(perfEvent);
2231
- }
2232
- catch (e) {
2233
- }
2234
- }
3245
+ _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
3246
+ if (perfEvent.isAsync) {
3247
+ setTimeout(function () { return listener[strPerfEvent](perfEvent); }, 0);
3248
+ }
3249
+ else {
3250
+ listener[strPerfEvent](perfEvent);
2235
3251
  }
2236
3252
  });
2237
3253
  }
@@ -2246,7 +3262,6 @@
2246
3262
  __extendsFn(AppInsightsCore, _super);
2247
3263
  function AppInsightsCore() {
2248
3264
  var _this = _super.call(this) || this;
2249
- var _internalLogPoller = 0;
2250
3265
  dynamicProto(AppInsightsCore, _this, function (_self, _base) {
2251
3266
  _self.initialize = function (config, extensions, logger, notificationManager) {
2252
3267
  _base.initialize(config, extensions, logger || new DiagnosticLogger(config), notificationManager || new NotificationManager(config));
@@ -2261,58 +3276,16 @@
2261
3276
  _base.track(telemetryItem);
2262
3277
  }, function () { return ({ item: telemetryItem }); }, !(telemetryItem.sync));
2263
3278
  };
2264
- _self.addNotificationListener = function (listener) {
2265
- var manager = _self.getNotifyMgr();
2266
- if (manager) {
2267
- manager.addNotificationListener(listener);
2268
- }
2269
- };
2270
- _self.removeNotificationListener = function (listener) {
2271
- var manager = _self.getNotifyMgr();
2272
- if (manager) {
2273
- manager.removeNotificationListener(listener);
2274
- }
2275
- };
2276
- _self.pollInternalLogs = function (eventName) {
2277
- var interval = _self.config.diagnosticLogInterval;
2278
- if (!interval || !(interval > 0)) {
2279
- interval = 10000;
2280
- }
2281
- if (_internalLogPoller) {
2282
- _self.stopPollingInternalLogs();
2283
- }
2284
- _internalLogPoller = setInterval(function () {
2285
- var queue = _self.logger ? _self.logger.queue : [];
2286
- arrForEach(queue, function (logMessage) {
2287
- var item = {
2288
- name: eventName ? eventName : "InternalMessageId: " + logMessage.messageId,
2289
- iKey: _self.config.instrumentationKey,
2290
- time: toISOString(new Date()),
2291
- baseType: _InternalLogMessage.dataType,
2292
- baseData: { message: logMessage.message }
2293
- };
2294
- _self.track(item);
2295
- });
2296
- queue.length = 0;
2297
- }, interval);
2298
- return _internalLogPoller;
2299
- };
2300
- _self.stopPollingInternalLogs = function () {
2301
- if (!_internalLogPoller)
2302
- return;
2303
- clearInterval(_internalLogPoller);
2304
- _internalLogPoller = 0;
2305
- };
2306
3279
  function _validateTelemetryItem(telemetryItem) {
2307
3280
  if (isNullOrUndefined(telemetryItem.name)) {
2308
3281
  _notifyInvalidEvent(telemetryItem);
2309
- throw Error("telemetry name required");
3282
+ throwError("telemetry name required");
2310
3283
  }
2311
3284
  }
2312
3285
  function _notifyInvalidEvent(telemetryItem) {
2313
3286
  var manager = _self.getNotifyMgr();
2314
3287
  if (manager) {
2315
- manager.eventsDiscarded([telemetryItem], EventsDiscardedReason.InvalidEvent);
3288
+ manager.eventsDiscarded([telemetryItem], 2 );
2316
3289
  }
2317
3290
  }
2318
3291
  });
@@ -2321,148 +3294,312 @@
2321
3294
  return AppInsightsCore;
2322
3295
  }(BaseCore$2));
2323
3296
 
2324
- var UInt32Mask = 0x100000000;
2325
- var MaxUInt32 = 0xffffffff;
2326
- var _mwcSeeded = false;
2327
- var _mwcW = 123456789;
2328
- var _mwcZ = 987654321;
2329
- function _mwcSeed(seedValue) {
2330
- if (seedValue < 0) {
2331
- seedValue >>>= 0;
3297
+ var strOnPrefix = "on";
3298
+ var strAttachEvent = "attachEvent";
3299
+ var strAddEventHelper = "addEventListener";
3300
+ var strDetachEvent = "detachEvent";
3301
+ var strRemoveEventListener = "removeEventListener";
3302
+ var strEvents = "events";
3303
+ var strVisibilityChangeEvt = "visibilitychange";
3304
+ var strPageHide = "pagehide";
3305
+ var strPageShow = "pageshow";
3306
+ var strUnload = "unload";
3307
+ var strBeforeUnload = "beforeunload";
3308
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
3309
+ var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
3310
+ var rRemoveEmptyNs = /\.[\.]+/g;
3311
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
3312
+ var _guid = 1;
3313
+ var elmNodeData = createElmNodeData("events");
3314
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
3315
+ function _normalizeNamespace(name) {
3316
+ if (name && name.replace) {
3317
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
3318
+ }
3319
+ return name;
3320
+ }
3321
+ function _getEvtNamespace(eventName, evtNamespace) {
3322
+ if (evtNamespace) {
3323
+ var theNamespace_1 = "";
3324
+ if (isArray(evtNamespace)) {
3325
+ theNamespace_1 = "";
3326
+ arrForEach(evtNamespace, function (name) {
3327
+ name = _normalizeNamespace(name);
3328
+ if (name) {
3329
+ if (name[0] !== ".") {
3330
+ name = "." + name;
3331
+ }
3332
+ theNamespace_1 += name;
3333
+ }
3334
+ });
3335
+ }
3336
+ else {
3337
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
3338
+ }
3339
+ if (theNamespace_1) {
3340
+ if (theNamespace_1[0] !== ".") {
3341
+ theNamespace_1 = "." + theNamespace_1;
3342
+ }
3343
+ eventName = (eventName || "") + theNamespace_1;
3344
+ }
2332
3345
  }
2333
- _mwcW = (123456789 + seedValue) & MaxUInt32;
2334
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
2335
- _mwcSeeded = true;
3346
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
3347
+ return {
3348
+ type: parsedEvent[1],
3349
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
3350
+ };
2336
3351
  }
2337
- function _autoSeedMwc() {
2338
- try {
2339
- var now = dateNow() & 0x7fffffff;
2340
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
2341
- }
2342
- catch (e) {
3352
+ function __getRegisteredEvents(target, eventName, evtNamespace) {
3353
+ var theEvents = [];
3354
+ var eventCache = elmNodeData.get(target, strEvents, {}, false);
3355
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
3356
+ objForEachKey(eventCache, function (evtType, registeredEvents) {
3357
+ arrForEach(registeredEvents, function (value) {
3358
+ if (!evtName.type || evtName.type === value.evtName.type) {
3359
+ if (!evtName.ns || evtName.ns === evtName.ns) {
3360
+ theEvents.push({
3361
+ name: value.evtName.type + (value.evtName.ns ? "." + value.evtName.ns : ""),
3362
+ handler: value.handler
3363
+ });
3364
+ }
3365
+ }
3366
+ });
3367
+ });
3368
+ return theEvents;
3369
+ }
3370
+ function _getRegisteredEvents(target, evtName, addDefault) {
3371
+ if (addDefault === void 0) { addDefault = true; }
3372
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
3373
+ var registeredEvents = aiEvts[evtName];
3374
+ if (!registeredEvents) {
3375
+ registeredEvents = aiEvts[evtName] = [];
2343
3376
  }
3377
+ return registeredEvents;
2344
3378
  }
2345
- function randomValue(maxValue) {
2346
- if (maxValue > 0) {
2347
- return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
3379
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
3380
+ if (obj && evtName && evtName.type) {
3381
+ if (obj[strRemoveEventListener]) {
3382
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3383
+ }
3384
+ else if (obj[strDetachEvent]) {
3385
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3386
+ }
2348
3387
  }
2349
- return 0;
2350
3388
  }
2351
- function random32(signed) {
2352
- var value;
2353
- var c = getCrypto() || getMsCrypto();
2354
- if (c && c.getRandomValues) {
2355
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
3389
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
3390
+ var result = false;
3391
+ if (obj && evtName && evtName.type && handlerRef) {
3392
+ if (obj[strAddEventHelper]) {
3393
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
3394
+ result = true;
3395
+ }
3396
+ else if (obj[strAttachEvent]) {
3397
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
3398
+ result = true;
3399
+ }
2356
3400
  }
2357
- else if (isIE()) {
2358
- if (!_mwcSeeded) {
2359
- _autoSeedMwc();
3401
+ return result;
3402
+ }
3403
+ function _doUnregister(target, events, evtName, unRegFn) {
3404
+ var idx = events.length;
3405
+ while (idx--) {
3406
+ var theEvent = events[idx];
3407
+ if (theEvent) {
3408
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3409
+ if (!unRegFn || unRegFn(theEvent)) {
3410
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3411
+ events.splice(idx, 1);
3412
+ }
3413
+ }
2360
3414
  }
2361
- value = mwcRandom32() & MaxUInt32;
2362
3415
  }
2363
- else {
2364
- value = Math.floor((UInt32Mask * Math.random()) | 0);
3416
+ }
3417
+ function _unregisterEvents(target, evtName, unRegFn) {
3418
+ if (evtName.type) {
3419
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
2365
3420
  }
2366
- if (!signed) {
2367
- value >>>= 0;
3421
+ else {
3422
+ var eventCache = elmNodeData.get(target, strEvents, {});
3423
+ objForEachKey(eventCache, function (evtType, events) {
3424
+ _doUnregister(target, events, evtName, unRegFn);
3425
+ });
3426
+ if (objKeys(eventCache).length === 0) {
3427
+ elmNodeData.kill(target, strEvents);
3428
+ }
2368
3429
  }
2369
- return value;
2370
3430
  }
2371
- function mwcRandomSeed(value) {
2372
- if (!value) {
2373
- _autoSeedMwc();
3431
+ function mergeEvtNamespace(theNamespace, namespaces) {
3432
+ var newNamespaces;
3433
+ if (namespaces) {
3434
+ if (isArray(namespaces)) {
3435
+ newNamespaces = [theNamespace].concat(namespaces);
3436
+ }
3437
+ else {
3438
+ newNamespaces = [theNamespace, namespaces];
3439
+ }
3440
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
2374
3441
  }
2375
3442
  else {
2376
- _mwcSeed(value);
3443
+ newNamespaces = theNamespace;
2377
3444
  }
3445
+ return newNamespaces;
2378
3446
  }
2379
- function mwcRandom32(signed) {
2380
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
2381
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
2382
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
2383
- if (!signed) {
2384
- value >>>= 0;
3447
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3448
+ if (useCapture === void 0) { useCapture = false; }
3449
+ var result = false;
3450
+ if (target) {
3451
+ try {
3452
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
3453
+ result = _doAttach(target, evtName, handlerRef, useCapture);
3454
+ if (result && elmNodeData.accept(target)) {
3455
+ var registeredEvent = {
3456
+ guid: _guid++,
3457
+ evtName: evtName,
3458
+ handler: handlerRef,
3459
+ capture: useCapture
3460
+ };
3461
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
3462
+ }
3463
+ }
3464
+ catch (e) {
3465
+ }
2385
3466
  }
2386
- return value;
3467
+ return result;
2387
3468
  }
2388
-
2389
- var strVisibilityChangeEvt = "visibilitychange";
2390
- var strPageHide = "pagehide";
2391
- var strPageShow = "pageshow";
2392
- function addEventHandler(eventName, callback) {
3469
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3470
+ if (useCapture === void 0) { useCapture = false; }
3471
+ if (target) {
3472
+ try {
3473
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3474
+ var found_1 = false;
3475
+ _unregisterEvents(target, evtName_1, function (regEvent) {
3476
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3477
+ found_1 = true;
3478
+ return true;
3479
+ }
3480
+ return false;
3481
+ });
3482
+ if (!found_1) {
3483
+ _doDetach(target, evtName_1, handlerRef, useCapture);
3484
+ }
3485
+ }
3486
+ catch (e) {
3487
+ }
3488
+ }
3489
+ }
3490
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3491
+ if (useCapture === void 0) { useCapture = false; }
3492
+ return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3493
+ }
3494
+ function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3495
+ if (useCapture === void 0) { useCapture = false; }
3496
+ eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3497
+ }
3498
+ function addEventHandler(eventName, callback, evtNamespace) {
2393
3499
  var result = false;
2394
3500
  var w = getWindow();
2395
3501
  if (w) {
2396
- result = attachEvent(w, eventName, callback);
2397
- result = attachEvent(w["body"], eventName, callback) || result;
3502
+ result = eventOn(w, eventName, callback, evtNamespace);
3503
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
2398
3504
  }
2399
3505
  var doc = getDocument();
2400
3506
  if (doc) {
2401
- result = attachEvent(doc, eventName, callback) || result;
3507
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
2402
3508
  }
2403
3509
  return result;
2404
3510
  }
2405
- function addEventListeners(events, listener, excludeEvents) {
3511
+ function removeEventHandler(eventName, callback, evtNamespace) {
3512
+ var w = getWindow();
3513
+ if (w) {
3514
+ eventOff(w, eventName, callback, evtNamespace);
3515
+ eventOff(w["body"], eventName, callback, evtNamespace);
3516
+ }
3517
+ var doc = getDocument();
3518
+ if (doc) {
3519
+ eventOff(doc, eventName, callback, evtNamespace);
3520
+ }
3521
+ }
3522
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
2406
3523
  var added = false;
2407
- if (listener && events && isArray(events)) {
2408
- var excluded_1 = [];
3524
+ if (listener && events && events.length > 0) {
2409
3525
  arrForEach(events, function (name) {
2410
- if (isString(name)) {
3526
+ if (name) {
2411
3527
  if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
2412
- added = addEventHandler(name, listener) || added;
2413
- }
2414
- else {
2415
- excluded_1.push(name);
3528
+ added = addEventHandler(name, listener, evtNamespace) || added;
2416
3529
  }
2417
3530
  }
2418
3531
  });
2419
- if (!added && excluded_1.length > 0) {
2420
- added = addEventListeners(excluded_1, listener);
3532
+ }
3533
+ return added;
3534
+ }
3535
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
3536
+ var added = false;
3537
+ if (listener && events && isArray(events)) {
3538
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
3539
+ if (!added && excludeEvents && excludeEvents.length > 0) {
3540
+ added = _addEventListeners(events, listener, null, evtNamespace);
2421
3541
  }
2422
3542
  }
2423
3543
  return added;
2424
3544
  }
2425
- function addPageUnloadEventListener(listener, excludeEvents) {
2426
- return addEventListeners(["beforeunload", "unload", "pagehide"], listener, excludeEvents);
3545
+ function removeEventListeners(events, listener, evtNamespace) {
3546
+ if (events && isArray(events)) {
3547
+ arrForEach(events, function (name) {
3548
+ if (name) {
3549
+ removeEventHandler(name, listener, evtNamespace);
3550
+ }
3551
+ });
3552
+ }
3553
+ }
3554
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
3555
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
3556
+ }
3557
+ function removePageUnloadEventListener(listener, evtNamespace) {
3558
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
2427
3559
  }
2428
- function addPageHideEventListener(listener, excludeEvents) {
3560
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
2429
3561
  function _handlePageVisibility(evt) {
2430
3562
  var doc = getDocument();
2431
3563
  if (listener && doc && doc.visibilityState === "hidden") {
2432
3564
  listener(evt);
2433
3565
  }
2434
3566
  }
2435
- var pageUnloadAdded = false;
2436
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
2437
- pageUnloadAdded = addEventHandler(strPageHide, listener);
2438
- }
3567
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3568
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
2439
3569
  if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
2440
- pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
3570
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
2441
3571
  }
2442
3572
  if (!pageUnloadAdded && excludeEvents) {
2443
- pageUnloadAdded = addPageHideEventListener(listener);
3573
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
2444
3574
  }
2445
3575
  return pageUnloadAdded;
2446
3576
  }
2447
- function addPageShowEventListener(listener, excludeEvents) {
3577
+ function removePageHideEventListener(listener, evtNamespace) {
3578
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3579
+ removeEventListeners([strPageHide], listener, newNamespaces);
3580
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
3581
+ }
3582
+ function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
2448
3583
  function _handlePageVisibility(evt) {
2449
3584
  var doc = getDocument();
2450
3585
  if (listener && doc && doc.visibilityState === "visible") {
2451
3586
  listener(evt);
2452
3587
  }
2453
3588
  }
2454
- var pageShowAdded = false;
2455
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageShow) === -1) {
2456
- pageShowAdded = addEventHandler(strPageShow, listener);
2457
- }
2458
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
2459
- pageShowAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageShowAdded;
2460
- }
3589
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
3590
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
3591
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
2461
3592
  if (!pageShowAdded && excludeEvents) {
2462
- pageShowAdded = addPageShowEventListener(listener);
3593
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
2463
3594
  }
2464
3595
  return pageShowAdded;
2465
3596
  }
3597
+ function removePageShowEventListener(listener, evtNamespace) {
3598
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
3599
+ removeEventListeners([strPageShow], listener, newNamespaces);
3600
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
3601
+ }
3602
+
2466
3603
  function newGuid() {
2467
3604
  function randomHexDigit() {
2468
3605
  return randomValue(15);
@@ -2479,26 +3616,9 @@
2479
3616
  }
2480
3617
  return dateNow();
2481
3618
  }
2482
- function newId(maxLength) {
2483
- if (maxLength === void 0) { maxLength = 22; }
2484
- var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2485
- var number = random32() >>> 0;
2486
- var chars = 0;
2487
- var result = "";
2488
- while (result.length < maxLength) {
2489
- chars++;
2490
- result += base64chars.charAt(number & 0x3F);
2491
- number >>>= 6;
2492
- if (chars === 5) {
2493
- number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
2494
- chars = 0;
2495
- }
2496
- }
2497
- return result;
2498
- }
2499
3619
  function generateW3CId() {
2500
3620
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
2501
- var oct = "", tmp;
3621
+ var oct = strEmpty, tmp;
2502
3622
  for (var a = 0; a < 4; a++) {
2503
3623
  tmp = random32();
2504
3624
  oct +=
@@ -2522,67 +3642,177 @@
2522
3642
  DetachEvent: detachEvent
2523
3643
  };
2524
3644
 
2525
- var ValueKind = {
2526
- NotSet: 0,
2527
- Pii_DistinguishedName: 1,
2528
- Pii_GenericData: 2,
2529
- Pii_IPV4Address: 3,
2530
- Pii_IPv6Address: 4,
2531
- Pii_MailSubject: 5,
2532
- Pii_PhoneNumber: 6,
2533
- Pii_QueryString: 7,
2534
- Pii_SipAddress: 8,
2535
- Pii_SmtpAddress: 9,
2536
- Pii_Identity: 10,
2537
- Pii_Uri: 11,
2538
- Pii_Fqdn: 12,
2539
- Pii_IPV4AddressLegacy: 13,
3645
+ var LoggingSeverity = createEnumStyle({
3646
+ CRITICAL: 1 ,
3647
+ WARNING: 2
3648
+ });
3649
+ var _InternalMessageId = createEnumStyle({
3650
+ BrowserDoesNotSupportLocalStorage: 0 ,
3651
+ BrowserCannotReadLocalStorage: 1 ,
3652
+ BrowserCannotReadSessionStorage: 2 ,
3653
+ BrowserCannotWriteLocalStorage: 3 ,
3654
+ BrowserCannotWriteSessionStorage: 4 ,
3655
+ BrowserFailedRemovalFromLocalStorage: 5 ,
3656
+ BrowserFailedRemovalFromSessionStorage: 6 ,
3657
+ CannotSendEmptyTelemetry: 7 ,
3658
+ ClientPerformanceMathError: 8 ,
3659
+ ErrorParsingAISessionCookie: 9 ,
3660
+ ErrorPVCalc: 10 ,
3661
+ ExceptionWhileLoggingError: 11 ,
3662
+ FailedAddingTelemetryToBuffer: 12 ,
3663
+ FailedMonitorAjaxAbort: 13 ,
3664
+ FailedMonitorAjaxDur: 14 ,
3665
+ FailedMonitorAjaxOpen: 15 ,
3666
+ FailedMonitorAjaxRSC: 16 ,
3667
+ FailedMonitorAjaxSend: 17 ,
3668
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
3669
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
3670
+ FailedToSendQueuedTelemetry: 20 ,
3671
+ FailedToReportDataLoss: 21 ,
3672
+ FlushFailed: 22 ,
3673
+ MessageLimitPerPVExceeded: 23 ,
3674
+ MissingRequiredFieldSpecification: 24 ,
3675
+ NavigationTimingNotSupported: 25 ,
3676
+ OnError: 26 ,
3677
+ SessionRenewalDateIsZero: 27 ,
3678
+ SenderNotInitialized: 28 ,
3679
+ StartTrackEventFailed: 29 ,
3680
+ StopTrackEventFailed: 30 ,
3681
+ StartTrackFailed: 31 ,
3682
+ StopTrackFailed: 32 ,
3683
+ TelemetrySampledAndNotSent: 33 ,
3684
+ TrackEventFailed: 34 ,
3685
+ TrackExceptionFailed: 35 ,
3686
+ TrackMetricFailed: 36 ,
3687
+ TrackPVFailed: 37 ,
3688
+ TrackPVFailedCalc: 38 ,
3689
+ TrackTraceFailed: 39 ,
3690
+ TransmissionFailed: 40 ,
3691
+ FailedToSetStorageBuffer: 41 ,
3692
+ FailedToRestoreStorageBuffer: 42 ,
3693
+ InvalidBackendResponse: 43 ,
3694
+ FailedToFixDepricatedValues: 44 ,
3695
+ InvalidDurationValue: 45 ,
3696
+ TelemetryEnvelopeInvalid: 46 ,
3697
+ CreateEnvelopeError: 47 ,
3698
+ CannotSerializeObject: 48 ,
3699
+ CannotSerializeObjectNonSerializable: 49 ,
3700
+ CircularReferenceDetected: 50 ,
3701
+ ClearAuthContextFailed: 51 ,
3702
+ ExceptionTruncated: 52 ,
3703
+ IllegalCharsInName: 53 ,
3704
+ ItemNotInArray: 54 ,
3705
+ MaxAjaxPerPVExceeded: 55 ,
3706
+ MessageTruncated: 56 ,
3707
+ NameTooLong: 57 ,
3708
+ SampleRateOutOfRange: 58 ,
3709
+ SetAuthContextFailed: 59 ,
3710
+ SetAuthContextFailedAccountName: 60 ,
3711
+ StringValueTooLong: 61 ,
3712
+ StartCalledMoreThanOnce: 62 ,
3713
+ StopCalledWithoutStart: 63 ,
3714
+ TelemetryInitializerFailed: 64 ,
3715
+ TrackArgumentsNotSpecified: 65 ,
3716
+ UrlTooLong: 66 ,
3717
+ SessionStorageBufferFull: 67 ,
3718
+ CannotAccessCookie: 68 ,
3719
+ IdTooLong: 69 ,
3720
+ InvalidEvent: 70 ,
3721
+ FailedMonitorAjaxSetRequestHeader: 71 ,
3722
+ SendBrowserInfoOnUserInit: 72 ,
3723
+ PluginException: 73 ,
3724
+ NotificationException: 74 ,
3725
+ SnippetScriptLoadFailure: 99 ,
3726
+ InvalidInstrumentationKey: 100 ,
3727
+ CannotParseAiBlobValue: 101 ,
3728
+ InvalidContentBlob: 102 ,
3729
+ TrackPageActionEventFailed: 103 ,
3730
+ FailedAddingCustomDefinedRequestContext: 104 ,
3731
+ InMemoryStorageBufferFull: 105
3732
+ });
3733
+
3734
+ var ValueKind = createEnumStyle({
3735
+ NotSet: 0 ,
3736
+ Pii_DistinguishedName: 1 ,
3737
+ Pii_GenericData: 2 ,
3738
+ Pii_IPV4Address: 3 ,
3739
+ Pii_IPv6Address: 4 ,
3740
+ Pii_MailSubject: 5 ,
3741
+ Pii_PhoneNumber: 6 ,
3742
+ Pii_QueryString: 7 ,
3743
+ Pii_SipAddress: 8 ,
3744
+ Pii_SmtpAddress: 9 ,
3745
+ Pii_Identity: 10 ,
3746
+ Pii_Uri: 11 ,
3747
+ Pii_Fqdn: 12 ,
3748
+ Pii_IPV4AddressLegacy: 13 ,
2540
3749
  CustomerContent_GenericContent: 32
2541
- };
2542
- var EventLatency = {
3750
+ });
3751
+ var EventLatency = createEnumStyle({
2543
3752
  Normal: 1 ,
2544
3753
  CostDeferred: 2 ,
2545
3754
  RealTime: 3 ,
2546
3755
  Immediate: 4
2547
- };
2548
- var EventPropertyType = {
2549
- Unspecified: 0,
2550
- String: 1,
2551
- Int32: 2,
2552
- UInt32: 3,
2553
- Int64: 4,
2554
- UInt64: 5,
2555
- Double: 6,
2556
- Bool: 7,
2557
- Guid: 8,
3756
+ });
3757
+ var EventPropertyType = createEnumStyle({
3758
+ Unspecified: 0 ,
3759
+ String: 1 ,
3760
+ Int32: 2 ,
3761
+ UInt32: 3 ,
3762
+ Int64: 4 ,
3763
+ UInt64: 5 ,
3764
+ Double: 6 ,
3765
+ Bool: 7 ,
3766
+ Guid: 8 ,
2558
3767
  DateTime: 9
2559
- };
2560
- var EventPersistence = {
3768
+ });
3769
+ var EventPersistence = createEnumStyle({
2561
3770
  Normal: 1 ,
2562
3771
  Critical: 2
2563
- };
2564
- var TraceLevel = {
2565
- NONE: 0,
2566
- ERROR: 1,
2567
- WARNING: 2,
3772
+ });
3773
+ var TraceLevel = createEnumStyle({
3774
+ NONE: 0 ,
3775
+ ERROR: 1 ,
3776
+ WARNING: 2 ,
2568
3777
  INFORMATION: 3
2569
- };
2570
- var _ExtendedInternalMessageId = __assignFn(__assignFn({}, _InternalMessageId), { AuthHandShakeError: 501, AuthRedirectFail: 502, BrowserCannotReadLocalStorage: 503, BrowserCannotWriteLocalStorage: 504, BrowserDoesNotSupportLocalStorage: 505, CannotParseBiBlobValue: 506, CannotParseDataAttribute: 507, CVPluginNotAvailable: 508, DroppedEvent: 509, ErrorParsingAISessionCookie: 510, ErrorProvidedChannels: 511, FailedToGetCookies: 512, FailedToInitializeCorrelationVector: 513, FailedToInitializeSDK: 514, InvalidContentBlob: 515, InvalidCorrelationValue: 516, SessionRenewalDateIsZero: 517, SendPostOnCompleteFailure: 518, PostResponseHandler: 519, SDKNotInitialized: 520 });
3778
+ });
3779
+ var _ExtendedInternalMessageId = objFreeze(__assignFn(__assignFn({}, _InternalMessageId), createEnumStyle({
3780
+ AuthHandShakeError: 501 ,
3781
+ AuthRedirectFail: 502 ,
3782
+ BrowserCannotReadLocalStorage: 503 ,
3783
+ BrowserCannotWriteLocalStorage: 504 ,
3784
+ BrowserDoesNotSupportLocalStorage: 505 ,
3785
+ CannotParseBiBlobValue: 506 ,
3786
+ CannotParseDataAttribute: 507 ,
3787
+ CVPluginNotAvailable: 508 ,
3788
+ DroppedEvent: 509 ,
3789
+ ErrorParsingAISessionCookie: 510 ,
3790
+ ErrorProvidedChannels: 511 ,
3791
+ FailedToGetCookies: 512 ,
3792
+ FailedToInitializeCorrelationVector: 513 ,
3793
+ FailedToInitializeSDK: 514 ,
3794
+ InvalidContentBlob: 515 ,
3795
+ InvalidCorrelationValue: 516 ,
3796
+ SessionRenewalDateIsZero: 517 ,
3797
+ SendPostOnCompleteFailure: 518 ,
3798
+ PostResponseHandler: 519 ,
3799
+ SDKNotInitialized: 520
3800
+ })));
2571
3801
 
2572
3802
  var _a;
2573
- var Version = '3.1.11';
3803
+ var Version = '3.2.2';
2574
3804
  var FullVersionString = "1DS-Web-JS-" + Version;
2575
3805
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2576
3806
  var strWithCredentials = "withCredentials";
2577
3807
  var strTimeout = "timeout";
2578
3808
  var _fieldTypeEventPropMap = (_a = {},
2579
- _a[0 ] = EventPropertyType.Unspecified,
2580
- _a[2 ] = EventPropertyType.Double,
2581
- _a[1 ] = EventPropertyType.String,
2582
- _a[3 ] = EventPropertyType.Bool,
2583
- _a[4096 | 2 ] = EventPropertyType.Double,
2584
- _a[4096 | 1 ] = EventPropertyType.String,
2585
- _a[4096 | 3 ] = EventPropertyType.Bool,
3809
+ _a[0 ] = 0 ,
3810
+ _a[2 ] = 6 ,
3811
+ _a[1 ] = 1 ,
3812
+ _a[3 ] = 7 ,
3813
+ _a[4096 | 2 ] = 6 ,
3814
+ _a[4096 | 1 ] = 1 ,
3815
+ _a[4096 | 3 ] = 7 ,
2586
3816
  _a);
2587
3817
  var uInt8ArraySupported = null;
2588
3818
  var isDocumentObjectAvailable = Boolean(getDocument());
@@ -2606,7 +3836,7 @@
2606
3836
  return uInt8ArraySupported;
2607
3837
  }
2608
3838
  function isLatency(value) {
2609
- if (value && isNumber(value) && value >= EventLatency.Normal && value <= EventLatency.Immediate) {
3839
+ if (value && isNumber(value) && value >= 1 && value <= 4 ) {
2610
3840
  return true;
2611
3841
  }
2612
3842
  return false;
@@ -2662,7 +3892,7 @@
2662
3892
  if (encodedTypeValue !== -1 && propType !== -1) {
2663
3893
  encodedTypeValue |= propType;
2664
3894
  }
2665
- else if (propType === EventPropertyType.Double) {
3895
+ else if (propType === 6 ) {
2666
3896
  encodedTypeValue = propType;
2667
3897
  }
2668
3898
  }
@@ -2752,7 +3982,7 @@
2752
3982
  }
2753
3983
  var getTime = perfNow;
2754
3984
  function isValueKind(value) {
2755
- if (value === ValueKind.NotSet || ((value > ValueKind.NotSet && value <= ValueKind.Pii_IPV4AddressLegacy) || value === ValueKind.CustomerContent_GenericContent)) {
3985
+ if (value === 0 || ((value > 0 && value <= 13 ) || value === 32 )) {
2756
3986
  return true;
2757
3987
  }
2758
3988
  return false;
@@ -2935,7 +4165,7 @@
2935
4165
  _this.pluginVersionString = "";
2936
4166
  dynamicProto(AppInsightsCore, _this, function (_self, _base) {
2937
4167
  if (!_self.logger || !_self.logger.queue) {
2938
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: exports.LoggingSeverity.CRITICAL });
4168
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 });
2939
4169
  }
2940
4170
  _self.initialize = function (config, extensions, logger, notificationManager) {
2941
4171
  doPerf(_self, function () { return "AppInsightsCore.initialize"; }, function () {
@@ -2982,7 +4212,7 @@
2982
4212
  if (message.indexOf("channels") !== -1) {
2983
4213
  message += "\n - Channels must be provided through config.channels only!";
2984
4214
  }
2985
- logger_1.throwInternal(exports.LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.FailedToInitializeSDK, "SDK Initialization Failed - no telemetry will be sent: " + message);
4215
+ logger_1.throwInternal(1 , 514 , "SDK Initialization Failed - no telemetry will be sent: " + message);
2986
4216
  }
2987
4217
  }, function () { return ({ config: config, extensions: extensions, logger: logger, notificationManager: notificationManager }); });
2988
4218
  };
@@ -2993,7 +4223,7 @@
2993
4223
  telemetryItem.timings = telemetryItem.timings || {};
2994
4224
  telemetryItem.timings.trackStart = getTime();
2995
4225
  if (!isLatency(telemetryItem.latency)) {
2996
- telemetryItem.latency = EventLatency.Normal;
4226
+ telemetryItem.latency = 1 ;
2997
4227
  }
2998
4228
  var itemExt = telemetryItem.ext = telemetryItem.ext || {};
2999
4229
  itemExt.sdk = itemExt.sdk || {};
@@ -3036,7 +4266,7 @@
3036
4266
  _base.initialize(config, extensions, logger, notificationManager);
3037
4267
  }
3038
4268
  catch (e) {
3039
- _self.logger.throwInternal(exports.LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.FailedToInitializeSDK, "Initialization Failed: " + dumpObj(e) + "\n - Note: Channels must be provided through config.channels only");
4269
+ _throwInternal(_self.logger, 1 , 514 , "Initialization Failed: " + dumpObj(e) + "\n - Note: Channels must be provided through config.channels only");
3040
4270
  }
3041
4271
  };
3042
4272
  _self.track = function (item) {
@@ -3640,6 +4870,7 @@
3640
4870
  exports.FullVersionString = FullVersionString;
3641
4871
  exports.InternalAppInsightsCore = AppInsightsCore$2;
3642
4872
  exports.InternalBaseCore = BaseCore$2;
4873
+ exports.LoggingSeverity = LoggingSeverity;
3643
4874
  exports.MinChannelPriorty = MinChannelPriorty;
3644
4875
  exports.NotificationManager = NotificationManager;
3645
4876
  exports.PerfEvent = PerfEvent;
@@ -3654,6 +4885,8 @@
3654
4885
  exports._ExtendedInternalMessageId = _ExtendedInternalMessageId;
3655
4886
  exports._InternalLogMessage = _InternalLogMessage;
3656
4887
  exports._InternalMessageId = _InternalMessageId;
4888
+ exports.__getRegisteredEvents = __getRegisteredEvents;
4889
+ exports._throwInternal = _throwInternal;
3657
4890
  exports.addEventHandler = addEventHandler;
3658
4891
  exports.addEventListeners = addEventListeners;
3659
4892
  exports.addPageHideEventListener = addPageHideEventListener;
@@ -3667,7 +4900,11 @@
3667
4900
  exports.attachEvent = attachEvent;
3668
4901
  exports.cookieAvailable = areCookiesSupported;
3669
4902
  exports.createCookieMgr = createCookieMgr;
4903
+ exports.createEnumStyle = createEnumStyle;
3670
4904
  exports.createGuid = createGuid;
4905
+ exports.createProcessTelemetryContext = createProcessTelemetryContext;
4906
+ exports.createUniqueNamespace = createUniqueNamespace;
4907
+ exports.createUnloadHandlerContainer = createUnloadHandlerContainer;
3671
4908
  exports.dateNow = dateNow;
3672
4909
  exports.deleteCookie = deleteCookie;
3673
4910
  exports.detachEvent = detachEvent;
@@ -3675,6 +4912,8 @@
3675
4912
  exports.disallowsSameSiteNone = uaDisallowsSameSiteNone;
3676
4913
  exports.doPerf = doPerf;
3677
4914
  exports.dumpObj = dumpObj;
4915
+ exports.eventOff = eventOff;
4916
+ exports.eventOn = eventOn;
3678
4917
  exports.extend = extend;
3679
4918
  exports.generateW3CId = generateW3CId;
3680
4919
  exports.getCommonSchemaMetaData = getCommonSchemaMetaData;
@@ -3731,19 +4970,29 @@
3731
4970
  exports.isValueKind = isValueKind;
3732
4971
  exports.isWindowObjectAvailable = isWindowObjectAvailable;
3733
4972
  exports.isXhrSupported = isXhrSupported;
4973
+ exports.mergeEvtNamespace = mergeEvtNamespace;
3734
4974
  exports.newGuid = newGuid;
3735
4975
  exports.newId = newId;
3736
4976
  exports.normalizeJsName = normalizeJsName;
3737
4977
  exports.objCreate = objCreateFn;
3738
4978
  exports.objDefineAccessors = objDefineAccessors;
3739
4979
  exports.objForEachKey = objForEachKey;
4980
+ exports.objFreeze = objFreeze;
3740
4981
  exports.objKeys = objKeys;
4982
+ exports.objSeal = objSeal;
3741
4983
  exports.openXhr = openXhr;
3742
4984
  exports.optimizeObject = optimizeObject;
3743
4985
  exports.perfNow = perfNow;
3744
4986
  exports.proxyAssign = proxyAssign;
4987
+ exports.proxyFunctionAs = proxyFunctionAs;
4988
+ exports.proxyFunctions = proxyFunctions;
3745
4989
  exports.random32 = random32;
3746
4990
  exports.randomValue = randomValue;
4991
+ exports.removeEventHandler = removeEventHandler;
4992
+ exports.removeEventListeners = removeEventListeners;
4993
+ exports.removePageHideEventListener = removePageHideEventListener;
4994
+ exports.removePageShowEventListener = removePageShowEventListener;
4995
+ exports.removePageUnloadEventListener = removePageUnloadEventListener;
3747
4996
  exports.safeGetCookieMgr = safeGetCookieMgr;
3748
4997
  exports.safeGetLogger = safeGetLogger;
3749
4998
  exports.sanitizeProperty = sanitizeProperty;
@@ -3753,9 +5002,7 @@
3753
5002
  exports.setValue = setValue;
3754
5003
  exports.strContains = strContains;
3755
5004
  exports.strEndsWith = strEndsWith;
3756
- exports.strExtensionConfig = strExtensionConfig;
3757
5005
  exports.strFunction = strShimFunction;
3758
- exports.strIKey = strIKey;
3759
5006
  exports.strObject = strShimObject;
3760
5007
  exports.strPrototype = strShimPrototype;
3761
5008
  exports.strStartsWith = strStartsWith;