@microsoft/1ds-core-js 3.1.6 → 3.1.10

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 (57) hide show
  1. package/README.md +4 -0
  2. package/bundle/ms.core-3.1.10.gbl.js +3722 -0
  3. package/bundle/ms.core-3.1.10.gbl.js.map +1 -0
  4. package/bundle/ms.core-3.1.10.gbl.min.js +7 -0
  5. package/bundle/ms.core-3.1.10.gbl.min.js.map +1 -0
  6. package/bundle/ms.core-3.1.10.integrity.json +46 -0
  7. package/bundle/{ms.core-test.js → ms.core-3.1.10.js} +273 -110
  8. package/bundle/ms.core-3.1.10.js.map +1 -0
  9. package/bundle/ms.core-3.1.10.min.js +7 -0
  10. package/bundle/ms.core-3.1.10.min.js.map +1 -0
  11. package/bundle/{ms.core-3.1.6.gbl.js → ms.core.gbl.js} +272 -109
  12. package/bundle/ms.core.gbl.js.map +1 -0
  13. package/bundle/ms.core.gbl.min.js +7 -0
  14. package/bundle/ms.core.gbl.min.js.map +1 -0
  15. package/bundle/ms.core.integrity.json +46 -0
  16. package/bundle/{ms.core-3.1.6.js → ms.core.js} +273 -110
  17. package/bundle/ms.core.js.map +1 -0
  18. package/bundle/ms.core.min.js +7 -0
  19. package/bundle/ms.core.min.js.map +1 -0
  20. package/dist/ms.core.js +53 -41
  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 +15 -4
  25. package/dist-esm/src/AppInsightsCore.js.map +1 -1
  26. package/dist-esm/src/BaseCore.js +5 -7
  27. package/dist-esm/src/BaseCore.js.map +1 -1
  28. package/dist-esm/src/DataModels.d.ts +17 -2
  29. package/dist-esm/src/DataModels.js +1 -1
  30. package/dist-esm/src/ESPromise.js +1 -1
  31. package/dist-esm/src/ESPromiseScheduler.js +1 -1
  32. package/dist-esm/src/Enums.d.ts +1 -0
  33. package/dist-esm/src/Enums.js +1 -1
  34. package/dist-esm/src/Index.d.ts +4 -3
  35. package/dist-esm/src/Index.js +5 -5
  36. package/dist-esm/src/Index.js.map +1 -1
  37. package/dist-esm/src/Utils.d.ts +12 -24
  38. package/dist-esm/src/Utils.js +46 -49
  39. package/dist-esm/src/Utils.js.map +1 -1
  40. package/dist-esm/src/ValueSanitizer.js +1 -1
  41. package/package.json +3 -3
  42. package/src/AppInsightsCore.ts +16 -5
  43. package/src/BaseCore.ts +4 -6
  44. package/src/DataModels.ts +24 -3
  45. package/src/Index.ts +7 -5
  46. package/src/Utils.ts +51 -56
  47. package/bundle/ms.core-3.1.6.gbl.js.map +0 -1
  48. package/bundle/ms.core-3.1.6.gbl.min.js +0 -7
  49. package/bundle/ms.core-3.1.6.gbl.min.js.map +0 -1
  50. package/bundle/ms.core-3.1.6.integrity.json +0 -46
  51. package/bundle/ms.core-3.1.6.js.map +0 -1
  52. package/bundle/ms.core-3.1.6.min.js +0 -7
  53. package/bundle/ms.core-3.1.6.min.js.map +0 -1
  54. package/bundle/ms.core-test.integrity.json +0 -26
  55. package/bundle/ms.core-test.js.map +0 -1
  56. package/bundle/ms.core-test.min.js +0 -7
  57. package/bundle/ms.core-test.min.js.map +0 -1
@@ -3,7 +3,7 @@
3
3
  * @author Abhilash Panwar (abpanwar) Hector Hernandez (hectorh)
4
4
  * @copyright Microsoft 2018
5
5
  */
6
- import { AppInsightsCore as InternalCore, IPlugin, LoggingSeverity, ITelemetryItem, IDiagnosticLogger, INotificationManager, doPerf, arrForEach } from "@microsoft/applicationinsights-core-js";
6
+ import { AppInsightsCore as InternalCore, IPlugin, LoggingSeverity, ITelemetryItem, IDiagnosticLogger, INotificationManager, doPerf, arrForEach, dumpObj, DiagnosticLogger } from "@microsoft/applicationinsights-core-js";
7
7
  import { IExtendedConfiguration, IExtendedTelemetryItem, IExtendedAppInsightsCore } from "./DataModels";
8
8
  import { EventLatency, _ExtendedInternalMessageId } from "./Enums";
9
9
  import { isLatency, FullVersionString, getTime } from "./Utils";
@@ -23,6 +23,11 @@ export default class AppInsightsCore extends InternalCore implements IExtendedAp
23
23
  super();
24
24
 
25
25
  dynamicProto(AppInsightsCore, this, (_self, _base) => {
26
+ if (!_self.logger || !_self.logger.queue) {
27
+ // The AI Base can inject a No-Op logger so if not defined or the No-Op, change to use a default logger so initialization errors
28
+ // are not dropped on the floor if one is not already defined
29
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
30
+ }
26
31
 
27
32
  _self.initialize = (config: IExtendedConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager) => {
28
33
  doPerf(_self, () => "AppInsightsCore.initialize", () => {
@@ -66,14 +71,20 @@ export default class AppInsightsCore extends InternalCore implements IExtendedAp
66
71
  _self.pluginVersionString = _self.pluginVersionStringArr.join(";");
67
72
  try {
68
73
  _base.initialize(config, extensions, logger, notificationManager);
74
+
75
+ _self.pollInternalLogs("InternalLog");
69
76
  } catch (e) {
70
- _self.logger.throwInternal(
77
+ let logger = _self.logger;
78
+ let message = dumpObj(e);
79
+ if (message.indexOf("channels") !== -1) {
80
+ // Add some additional context to the underlying reported error
81
+ message += "\n - Channels must be provided through config.channels only!";
82
+ }
83
+ logger.throwInternal(
71
84
  LoggingSeverity.CRITICAL,
72
- _ExtendedInternalMessageId.ErrorProvidedChannels, "Channels must be provided through config.channels only"
85
+ _ExtendedInternalMessageId.FailedToInitializeSDK, "SDK Initialization Failed - no telemetry will be sent: " + message
73
86
  );
74
87
  }
75
-
76
- _self.pollInternalLogs("InternalLog");
77
88
  }, () => ({ config, extensions, logger, notificationManager }));
78
89
  };
79
90
 
package/src/BaseCore.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * @author Abhilash Panwar (abpanwar) Hector Hernandez (hectorh)
7
7
  * @copyright Microsoft 2018
8
8
  */
9
- import { BaseCore as InternalCore, IPlugin, LoggingSeverity, ITelemetryItem, IDiagnosticLogger, INotificationManager } from "@microsoft/applicationinsights-core-js";
9
+ import { BaseCore as InternalCore, IPlugin, LoggingSeverity, ITelemetryItem, IDiagnosticLogger, INotificationManager, dumpObj } from "@microsoft/applicationinsights-core-js";
10
10
  import { IExtendedConfiguration, IExtendedTelemetryItem, IExtendedAppInsightsCore } from "./DataModels";
11
11
  import { _ExtendedInternalMessageId } from "./Enums";
12
12
  import { FullVersionString, isDocumentObjectAvailable } from "./Utils";
@@ -23,10 +23,8 @@ export default class BaseCore extends InternalCore implements IExtendedAppInsigh
23
23
  dynamicProto(BaseCore, this, (_self, _base) => {
24
24
 
25
25
  _self.initialize = (config: IExtendedConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager) => {
26
- if (config) {
27
- if (!config.endpointUrl) {
28
- config.endpointUrl = "https://browser.events.data.microsoft.com/OneCollector/1.0/";
29
- }
26
+ if (config && !config.endpointUrl) {
27
+ config.endpointUrl = "https://browser.events.data.microsoft.com/OneCollector/1.0/";
30
28
  }
31
29
 
32
30
  _self.getWParam = () => {
@@ -38,7 +36,7 @@ export default class BaseCore extends InternalCore implements IExtendedAppInsigh
38
36
  } catch (e) {
39
37
  _self.logger.throwInternal(
40
38
  LoggingSeverity.CRITICAL,
41
- _ExtendedInternalMessageId.ErrorProvidedChannels, "Channels must be provided through config.channels only"
39
+ _ExtendedInternalMessageId.FailedToInitializeSDK, "Initialization Failed: " + dumpObj(e) + "\n - Note: Channels must be provided through config.channels only"
42
40
  );
43
41
  }
44
42
  };
package/src/DataModels.ts CHANGED
@@ -99,11 +99,32 @@ export interface IExtendedConfiguration extends IConfiguration {
99
99
  disableEventTimings?: boolean;
100
100
 
101
101
  /**
102
- * [Optional] Enables support for objects with compound keys which indirectly represent an object eg. event: { "somedata.embeddedvalue": 123 }
103
- * where the "key" of the object contains a "." as part of it's name.
102
+ * [Optional] Enables support for objects with compound keys which indirectly represent an object where the "key" of the object contains a "." as part of it's name.
103
+ * @example
104
+ * ```typescript
105
+ * event: { "somedata.embeddedvalue": 123 }
106
+ * ```
104
107
  */
105
108
  enableCompoundKey?: boolean;
106
- }
109
+
110
+ // Internal note: remove these after consuming the ApplicationInsights Core version that defines these on IConfiguration
111
+
112
+ /**
113
+ * [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload
114
+ * event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
115
+ * Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide"
116
+ */
117
+ disablePageUnloadEvents?: string[];
118
+
119
+ /**
120
+ * [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event
121
+ * hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
122
+ * Page Show events include "pageshow" and "visibilitychange" (with 'visible' state)
123
+ */
124
+ disablePageShowEvents?: string[];
125
+
126
+ // End of Internal note: remove these after consuming the ApplicationInsights Core version that defines these on IConfiguration
127
+ }
107
128
 
108
129
  /**
109
130
  * An interface used for telemetry event timings.
package/src/Index.ts CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  IExtendedConfiguration, IPropertyStorageOverride,
13
13
  IEventProperty, IExtendedTelemetryItem, IExtendedAppInsightsCore, IEventTiming,
14
14
  IValueSanitizer, FieldValueSanitizerFunc, IFieldSanitizerDetails, IFieldValueSanitizerProvider,
15
- FieldValueSanitizerTypes,
15
+ FieldValueSanitizerTypes
16
16
  } from "./DataModels";
17
17
  import AppInsightsCore from "./AppInsightsCore";
18
18
  import BaseCore from "./BaseCore";
@@ -35,8 +35,8 @@ export {
35
35
  IAppInsightsCore, IChannelControls, IPlugin, INotificationManager, NotificationManager, INotificationListener,
36
36
  IConfiguration, ITelemetryItem, ITelemetryPlugin, BaseTelemetryPlugin, IProcessTelemetryContext, ProcessTelemetryContext, ITelemetryPluginChain,
37
37
  MinChannelPriorty, EventsDiscardedReason, ICoreUtils, IDiagnosticLogger, DiagnosticLogger, LoggingSeverity, SendRequestReason,
38
- IPerfEvent, IPerfManager, IPerfManagerProvider, PerfEvent, PerfManager, doPerf,
39
- EventHelper,
38
+ IPerfEvent, IPerfManager, IPerfManagerProvider, PerfEvent, PerfManager, doPerf, ICustomProperties, Tags,
39
+ EventHelper, AppInsightsCore as InternalAppInsightsCore, BaseCore as InternalBaseCore, _InternalLogMessage, _InternalMessageId,
40
40
  // The HelperFuncs functions
41
41
  isTypeof, isUndefined, isNullOrUndefined, hasOwnProperty, isObject, isFunction, attachEvent, detachEvent, normalizeJsName,
42
42
  objForEachKey, strStartsWith, strEndsWith, strContains, strTrim, isDate, isArray, isError, isString, isNumber, isBoolean,
@@ -57,16 +57,18 @@ export {
57
57
  strIKey, strExtensionConfig,
58
58
  // Aliases
59
59
  toISOString as getISOString,
60
- isBeaconsSupported, isFetchSupported, isXhrSupported, useXDomainRequest
60
+ isBeaconsSupported, isFetchSupported, isXhrSupported, useXDomainRequest,
61
+ addPageHideEventListener, addPageShowEventListener, addEventListeners, addPageUnloadEventListener
61
62
  } from "@microsoft/applicationinsights-core-js";
62
63
 
63
64
  export {
64
65
  isValueAssigned, isLatency, isUint8ArrayAvailable, getTenantId, sanitizeProperty,
65
66
  Version, FullVersionString, getCommonSchemaMetaData, getCookie, setCookie, deleteCookie, getCookieValue,
66
67
  extend, createGuid, isDocumentObjectAvailable, isWindowObjectAvailable,
67
- addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, setProcessTelemetryTimings, getTime,
68
+ setProcessTelemetryTimings, getTime,
68
69
  isArrayValid, isValueKind, getFieldValueType,
69
70
  CoreUtils, disableCookies, // exporting the overridden version for tree-shaking
70
71
  Utils, // Replacement for import * as Utils from "./Utils";
71
72
  isChromium, // Replace with ai-core version once published in ai-core
73
+ openXhr
72
74
  } from "./Utils";
package/src/Utils.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * @copyright Microsoft 2018
5
5
  * File containing utility functions.
6
6
  */
7
- import { getGlobal, objCreateFn, ObjHasOwnProperty, strShimObject } from "@microsoft/applicationinsights-shims";
7
+ import { objCreateFn, strShimObject } from "@microsoft/applicationinsights-shims";
8
8
  import { IEventProperty, IExtendedTelemetryItem } from "./DataModels";
9
9
  import { EventPropertyType, _ExtendedInternalMessageId, GuidStyle, ValueKind, FieldValueSanitizerType, EventLatency } from "./Enums";
10
10
  import {
@@ -13,12 +13,16 @@ import {
13
13
  newGuid, isObject, perfNow, hasOwnProperty, addEventHandler, uaDisallowsSameSiteNone, strPrototype, objDefineAccessors,
14
14
  toISOString, strTrim, isFunction, objKeys, arrReduce, arrMap, arrIndexOf, arrForEach, strUndefined, strObject,
15
15
  areCookiesSupported, ICookieMgr, safeGetCookieMgr, generateW3CId,
16
- mwcRandom32, mwcRandomSeed, random32, randomValue, newId, isIE, dateNow, isError, isDate, isTypeof, ICoreUtils, strEndsWith, useXDomainRequest, isBeaconsSupported,
16
+ mwcRandom32, mwcRandomSeed, random32, randomValue, newId, isIE, dateNow, isError, isDate, isTypeof, ICoreUtils, strEndsWith, useXDomainRequest, isBeaconsSupported, addPageUnloadEventListener,
17
17
  } from "@microsoft/applicationinsights-core-js";
18
18
 
19
19
  export const Version = "#version#";
20
20
  export const FullVersionString = "1DS-Web-JS-" + Version;
21
21
 
22
+ // Defining here so we don't need to take (import) the ApplicationInsights Common module
23
+ const strDisabledPropertyName: string = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
24
+ const strWithCredentials: string = "withCredentials";
25
+
22
26
  // If value is array just get the type for the first element
23
27
  const _fieldTypeEventPropMap = {
24
28
  [FieldValueSanitizerType.NotSet]: EventPropertyType.Unspecified,
@@ -365,60 +369,6 @@ export function isArrayValid(value: any[]): boolean {
365
369
  return value.length > 0;
366
370
  }
367
371
 
368
- /**
369
- * Listen to the pagehide and visibility changing to 'hidden' events
370
- * @param listener The event callback to call when a page hide event is triggered
371
- * @returns true - when at least one of the events was registered otherwise false
372
- */
373
- export function addPageHideEventListener(listener: any): boolean {
374
-
375
- function _handlePageVisibility(evt) {
376
- let doc = getDocument();
377
- if (listener && doc && doc.visibilityState === 'hidden') {
378
- listener(evt);
379
- }
380
- }
381
-
382
- let pageUnloadAdded = addEventHandler("pagehide", listener);
383
- return addEventHandler("visibilitychange", _handlePageVisibility) || pageUnloadAdded;
384
- }
385
-
386
- /**
387
- * Listen to the pageshow and visibility changing to 'visible' events
388
- * @param listener The event callback to call when a page is show event is triggered
389
- * @returns true - when at least one of the events was registered otherwise false
390
- */
391
- export function addPageShowEventListener(listener: any): boolean {
392
-
393
- function _handlePageVisibility(evt) {
394
- let doc = getDocument();
395
- if (listener && doc && doc.visibilityState === 'visible') {
396
- listener(evt);
397
- }
398
- }
399
-
400
- let pageUnloadAdded = addEventHandler("pageshow", listener);
401
- return addEventHandler("visibilitychange", _handlePageVisibility) || pageUnloadAdded;
402
- }
403
-
404
- /**
405
- * Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
406
- * this does NOT listen to the 'visibilitychange' event as while it does indicate that the page is being hidden
407
- * it does not *necessarily* mean that the page is being completely unloaded, it can mean that the user is
408
- * just navigating to a different Tab and may come back (without unloading the page). As such you may also
409
- * need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
410
- * @param listener The event callback to call when a page unload event is triggered
411
- * @returns true - when at least one of the events was registered otherwise false
412
- */
413
- export function addPageUnloadEventListener(listener: any): boolean {
414
-
415
- // Hook the unload event for the document, window and body to ensure that the client events are flushed to the server
416
- // As just hooking the window does not always fire (on chrome) for page navigations.
417
- let pageUnloadAdded = addEventHandler("beforeunload", listener);
418
- pageUnloadAdded = addEventHandler("unload", listener) || pageUnloadAdded;
419
- return addEventHandler("pagehide", listener) || pageUnloadAdded;
420
- }
421
-
422
372
  export function setProcessTelemetryTimings(event: ITelemetryItem, identifier: string): void {
423
373
  var evt = event as IExtendedTelemetryItem;
424
374
  evt.timings = evt.timings || {};
@@ -559,3 +509,48 @@ export const CoreUtils: ICoreUtils = {
559
509
  export function isChromium() {
560
510
  return !!getGlobalInst("chrome");
561
511
  }
512
+
513
+ /**
514
+ * Create and open an XMLHttpRequest object
515
+ * @param method - The request method
516
+ * @param urlString - The url
517
+ * @param withCredentials - Option flag indicating that credentials should be sent
518
+ * @param disabled - Optional flag indicating that the XHR object should be marked as disabled and not tracked (default is false)
519
+ * @param isSync - Optional flag indicating if the instance should be a synchronous request (defaults to false)
520
+ * @returns A new opened XHR request
521
+ */
522
+ export function openXhr(method: string, urlString: string, withCredentials?: boolean, disabled: boolean = false, isSync: boolean = false) {
523
+
524
+ function _wrapSetXhrProp(xhr: XMLHttpRequest, prop: string, value: boolean) {
525
+ try {
526
+ xhr[prop] = value;
527
+ } catch (e) {
528
+ // - Wrapping as depending on the environment setting the property may fail (non-terminally)
529
+ }
530
+ }
531
+
532
+ let xhr = new XMLHttpRequest();
533
+
534
+ if (disabled) {
535
+ // Tag the instance so it's not tracked (trackDependency)
536
+ // If the environment has locked down the XMLHttpRequest (preventExtensions and/or freeze), this would
537
+ // cause the request to fail and we no telemetry would be sent
538
+ _wrapSetXhrProp(xhr, strDisabledPropertyName, disabled);
539
+ }
540
+
541
+ if (withCredentials) {
542
+ // Some libraries require that the withCredentials flag is set "before" open and
543
+ // - Wrapping as IE 10 has started throwing when setting before open
544
+ _wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
545
+ }
546
+
547
+ xhr.open(method, urlString, !isSync);
548
+
549
+ if (withCredentials) {
550
+ // withCredentials should be set AFTER open (https://xhr.spec.whatwg.org/#the-withcredentials-attribute)
551
+ // And older firefox instances from 11+ will throw for sync events (current versions don't) which happens during unload processing
552
+ _wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
553
+ }
554
+
555
+ return xhr;
556
+ }