@microsoft/1ds-core-js 3.1.3 → 3.1.7

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 (84) hide show
  1. package/README.md +1 -1
  2. package/bundle/ms.core-3.1.7.gbl.js +3589 -0
  3. package/bundle/ms.core-3.1.7.gbl.js.map +1 -0
  4. package/bundle/ms.core-3.1.7.gbl.min.js +7 -0
  5. package/bundle/ms.core-3.1.7.gbl.min.js.map +1 -0
  6. package/bundle/ms.core-3.1.7.integrity.json +46 -0
  7. package/bundle/{ms.core-test.js → ms.core-3.1.7.js} +203 -100
  8. package/bundle/ms.core-3.1.7.js.map +1 -0
  9. package/bundle/ms.core-3.1.7.min.js +7 -0
  10. package/bundle/ms.core-3.1.7.min.js.map +1 -0
  11. package/bundle/{ms.core-3.1.3.gbl.js → ms.core.gbl.js} +201 -98
  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.3.js → ms.core.js} +202 -99
  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 +64 -68
  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 +1 -1
  25. package/dist-esm/src/BaseCore.js +1 -1
  26. package/dist-esm/src/DataModels.d.ts +5 -2
  27. package/dist-esm/src/DataModels.js +2 -1
  28. package/dist-esm/src/DataModels.js.map +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 +1 -0
  32. package/dist-esm/src/Enums.js +1 -1
  33. package/dist-esm/src/Index.d.ts +4 -3
  34. package/dist-esm/src/Index.js +6 -5
  35. package/dist-esm/src/Index.js.map +1 -1
  36. package/dist-esm/src/Utils.d.ts +33 -19
  37. package/dist-esm/src/Utils.js +86 -75
  38. package/dist-esm/src/Utils.js.map +1 -1
  39. package/dist-esm/src/ValueSanitizer.js +1 -1
  40. package/package.json +6 -6
  41. package/src/DataModels.ts +5 -2
  42. package/src/Index.ts +10 -10
  43. package/src/Utils.ts +100 -84
  44. package/tsconfig.json +2 -4
  45. package/bundle/ms.core-3.1.3.gbl.js.map +0 -1
  46. package/bundle/ms.core-3.1.3.gbl.min.js +0 -7
  47. package/bundle/ms.core-3.1.3.gbl.min.js.map +0 -1
  48. package/bundle/ms.core-3.1.3.js.map +0 -1
  49. package/bundle/ms.core-3.1.3.min.js +0 -7
  50. package/bundle/ms.core-3.1.3.min.js.map +0 -1
  51. package/bundle/ms.core-test.js.map +0 -1
  52. package/bundle/ms.core-test.min.js +0 -7
  53. package/bundle/ms.core-test.min.js.map +0 -1
  54. package/dist-esm/test/CoreTest.d.ts +0 -6
  55. package/dist-esm/test/CoreTest.js +0 -105
  56. package/dist-esm/test/CoreTest.js.map +0 -1
  57. package/dist-esm/test/DynamicProtoTests.d.ts +0 -7
  58. package/dist-esm/test/DynamicProtoTests.js +0 -541
  59. package/dist-esm/test/DynamicProtoTests.js.map +0 -1
  60. package/dist-esm/test/ESPromiseSchedulerTests.d.ts +0 -6
  61. package/dist-esm/test/ESPromiseSchedulerTests.js +0 -190
  62. package/dist-esm/test/ESPromiseSchedulerTests.js.map +0 -1
  63. package/dist-esm/test/ESPromiseTests.d.ts +0 -5
  64. package/dist-esm/test/ESPromiseTests.js +0 -422
  65. package/dist-esm/test/ESPromiseTests.js.map +0 -1
  66. package/dist-esm/test/FileSizeCheckTest.d.ts +0 -5
  67. package/dist-esm/test/FileSizeCheckTest.js +0 -42
  68. package/dist-esm/test/FileSizeCheckTest.js.map +0 -1
  69. package/dist-esm/test/Index.d.ts +0 -1
  70. package/dist-esm/test/Index.js +0 -23
  71. package/dist-esm/test/Index.js.map +0 -1
  72. package/dist-esm/test/TestClass.d.ts +0 -103
  73. package/dist-esm/test/TestClass.js +0 -396
  74. package/dist-esm/test/TestClass.js.map +0 -1
  75. package/dist-esm/test/TestHelper.d.ts +0 -7
  76. package/dist-esm/test/TestHelper.js +0 -98
  77. package/dist-esm/test/TestHelper.js.map +0 -1
  78. package/dist-esm/test/UtilsTest.d.ts +0 -4
  79. package/dist-esm/test/UtilsTest.js +0 -224
  80. package/dist-esm/test/UtilsTest.js.map +0 -1
  81. package/dist-esm/test/ValueSanitizerTests.d.ts +0 -6
  82. package/dist-esm/test/ValueSanitizerTests.js +0 -331
  83. package/dist-esm/test/ValueSanitizerTests.js.map +0 -1
  84. package/src/typings/XDomainRequest.d.ts +0 -23
package/src/Utils.ts CHANGED
@@ -4,22 +4,25 @@
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 {
11
- ITelemetryItem, getDocument, hasNavigator, getNavigator, getWindow, getGlobalInst,
11
+ ITelemetryItem, getDocument, getNavigator, getWindow, getGlobalInst,
12
12
  objForEachKey, isUndefined, isNullOrUndefined, isNumber, isReactNative, isString, isBoolean, isArray,
13
13
  newGuid, isObject, perfNow, hasOwnProperty, addEventHandler, uaDisallowsSameSiteNone, strPrototype, objDefineAccessors,
14
14
  toISOString, strTrim, isFunction, objKeys, arrReduce, arrMap, arrIndexOf, arrForEach, strUndefined, strObject,
15
- areCookiesSupported, IDiagnosticLogger, ICookieMgr, safeGetCookieMgr, IConfiguration, IAppInsightsCore, generateW3CId,
16
- mwcRandom32, mwcRandomSeed, random32, randomValue, newId, isIE, dateNow, isError, isDate, isTypeof, ICoreUtils, strEndsWith,
17
- objFreeze,
15
+ areCookiesSupported, ICookieMgr, safeGetCookieMgr, generateW3CId,
16
+ mwcRandom32, mwcRandomSeed, random32, randomValue, newId, isIE, dateNow, isError, isDate, isTypeof, ICoreUtils, strEndsWith, useXDomainRequest, isBeaconsSupported,
18
17
  } from "@microsoft/applicationinsights-core-js";
19
18
 
20
19
  export const Version = "#version#";
21
20
  export const FullVersionString = "1DS-Web-JS-" + Version;
22
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
+
23
26
  // If value is array just get the type for the first element
24
27
  const _fieldTypeEventPropMap = {
25
28
  [FieldValueSanitizerType.NotSet]: EventPropertyType.Unspecified,
@@ -36,35 +39,9 @@ const _fieldTypeEventPropMap = {
36
39
  */
37
40
  // let _uaDisallowsSameSiteNone = null;
38
41
 
39
- let _useXDomainRequest: boolean | null = null;
40
- var beaconsSupported: boolean | null = null;
41
42
  var uInt8ArraySupported: boolean | null = null;
42
43
  // var _areCookiesAvailable: boolean | undefined;
43
44
 
44
- function _hasProperty(theClass: any, property: string) {
45
- let supported = false;
46
- if (theClass) {
47
- supported = property in theClass;
48
- if (!supported) {
49
- let proto = theClass.prototype;
50
- if (proto) {
51
- supported = property in proto;
52
- }
53
- }
54
-
55
- if (!supported) {
56
- try {
57
- let tmp = new theClass();
58
- supported = !isUndefined(tmp[property]);
59
- } catch (e) {
60
- // Do Nothing
61
- }
62
- }
63
- }
64
-
65
- return supported;
66
- }
67
-
68
45
  /**
69
46
  * Checks if document object is available
70
47
  */
@@ -102,46 +79,6 @@ export function getTenantId(apiKey: string | undefined): string {
102
79
  return "";
103
80
  }
104
81
 
105
- /**
106
- * Checks if HTML5 Beacons are supported in the current environment.
107
- * @returns True if supported, false otherwise.
108
- */
109
- export function isBeaconsSupported(): boolean {
110
- if (beaconsSupported === null) {
111
- beaconsSupported = hasNavigator() && Boolean(getNavigator().sendBeacon);
112
- }
113
- return beaconsSupported;
114
- }
115
-
116
- /**
117
- * Checks if the Fetch API is supported in the current environment.
118
- * @param withKeepAlive - [Optional] If True, check if fetch is available and it supports the keepalive feature, otherwise only check if fetch is supported
119
- * @returns True if supported, otherwise false
120
- */
121
- export function isFetchSupported(withKeepAlive?: boolean): boolean {
122
- let isSupported = false;
123
- try {
124
- const fetchApi = getGlobalInst("fetch");
125
- isSupported = !!fetchApi;
126
- const request = getGlobalInst("Request");
127
- if (isSupported && withKeepAlive && request) {
128
- isSupported = _hasProperty(request, "keepalive");
129
- }
130
- } catch (e) {
131
- // Just Swallow any failure during availability checks
132
- }
133
-
134
- return isSupported;
135
- }
136
-
137
- /**
138
- * Checks if XMLHttpRequest is supported
139
- * @returns True if supported, otherwise false
140
- */
141
- export function isXhrSupported(): boolean {
142
- return typeof XMLHttpRequest !== undefined;
143
- }
144
-
145
82
  /**
146
83
  * Checks if Uint8Array are available in the current environment. Safari and Firefox along with
147
84
  * ReactNative are known to not support Uint8Array properly.
@@ -218,17 +155,6 @@ export function sanitizeProperty(name: string,
218
155
  return (property as IEventProperty);
219
156
  }
220
157
 
221
- export function useXDomainRequest(): boolean | undefined {
222
- if (_useXDomainRequest === null) {
223
- _useXDomainRequest = (typeof XDomainRequest !== undefined);
224
- if (_useXDomainRequest && isXhrSupported()) {
225
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(XMLHttpRequest, "withCredentials");
226
- }
227
- }
228
-
229
- return _useXDomainRequest;
230
- }
231
-
232
158
  export function getCommonSchemaMetaData(value: string | boolean | number | string[] | number[] | boolean[] | undefined, kind: number | undefined, type?: number | undefined): number {
233
159
  let encodedTypeValue = -1;
234
160
 
@@ -443,13 +369,58 @@ export function isArrayValid(value: any[]): boolean {
443
369
  return value.length > 0;
444
370
  }
445
371
 
372
+ /**
373
+ * Listen to the pagehide and visibility changing to 'hidden' events
374
+ * @param listener The event callback to call when a page hide event is triggered
375
+ * @returns true - when at least one of the events was registered otherwise false
376
+ */
377
+ export function addPageHideEventListener(listener: any): boolean {
378
+
379
+ function _handlePageVisibility(evt) {
380
+ let doc = getDocument();
381
+ if (listener && doc && doc.visibilityState === 'hidden') {
382
+ listener(evt);
383
+ }
384
+ }
385
+
386
+ let pageUnloadAdded = addEventHandler("pagehide", listener);
387
+ return addEventHandler("visibilitychange", _handlePageVisibility) || pageUnloadAdded;
388
+ }
389
+
390
+ /**
391
+ * Listen to the pageshow and visibility changing to 'visible' events
392
+ * @param listener The event callback to call when a page is show event is triggered
393
+ * @returns true - when at least one of the events was registered otherwise false
394
+ */
395
+ export function addPageShowEventListener(listener: any): boolean {
396
+
397
+ function _handlePageVisibility(evt) {
398
+ let doc = getDocument();
399
+ if (listener && doc && doc.visibilityState === 'visible') {
400
+ listener(evt);
401
+ }
402
+ }
403
+
404
+ let pageUnloadAdded = addEventHandler("pageshow", listener);
405
+ return addEventHandler("visibilitychange", _handlePageVisibility) || pageUnloadAdded;
406
+ }
407
+
408
+ /**
409
+ * Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
410
+ * this does NOT listen to the 'visibilitychange' event as while it does indicate that the page is being hidden
411
+ * it does not *necessarily* mean that the page is being completely unloaded, it can mean that the user is
412
+ * just navigating to a different Tab and may come back (without unloading the page). As such you may also
413
+ * need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
414
+ * @param listener The event callback to call when a page unload event is triggered
415
+ * @returns true - when at least one of the events was registered otherwise false
416
+ */
446
417
  export function addPageUnloadEventListener(listener: any): boolean {
418
+
447
419
  // Hook the unload event for the document, window and body to ensure that the client events are flushed to the server
448
420
  // As just hooking the window does not always fire (on chrome) for page navigations.
449
421
  let pageUnloadAdded = addEventHandler("beforeunload", listener);
450
422
  pageUnloadAdded = addEventHandler("unload", listener) || pageUnloadAdded;
451
- pageUnloadAdded = addEventHandler("pagehide", listener) || pageUnloadAdded;
452
- return pageUnloadAdded;
423
+ return addEventHandler("pagehide", listener) || pageUnloadAdded;
453
424
  }
454
425
 
455
426
  export function setProcessTelemetryTimings(event: ITelemetryItem, identifier: string): void {
@@ -592,3 +563,48 @@ export const CoreUtils: ICoreUtils = {
592
563
  export function isChromium() {
593
564
  return !!getGlobalInst("chrome");
594
565
  }
566
+
567
+ /**
568
+ * Create and open an XMLHttpRequest object
569
+ * @param method - The request method
570
+ * @param urlString - The url
571
+ * @param withCredentials - Option flag indicating that credentials should be sent
572
+ * @param disabled - Optional flag indicating that the XHR object should be marked as disabled and not tracked (default is false)
573
+ * @param isSync - Optional flag indicating if the instance should be a synchronous request (defaults to false)
574
+ * @returns A new opened XHR request
575
+ */
576
+ export function openXhr(method: string, urlString: string, withCredentials?: boolean, disabled: boolean = false, isSync: boolean = false) {
577
+
578
+ function _wrapSetXhrProp(xhr: XMLHttpRequest, prop: string, value: boolean) {
579
+ try {
580
+ xhr[prop] = value;
581
+ } catch (e) {
582
+ // - Wrapping as depending on the environment setting the property may fail (non-terminally)
583
+ }
584
+ }
585
+
586
+ let xhr = new XMLHttpRequest();
587
+
588
+ if (disabled) {
589
+ // Tag the instance so it's not tracked (trackDependency)
590
+ // If the environment has locked down the XMLHttpRequest (preventExtensions and/or freeze), this would
591
+ // cause the request to fail and we no telemetry would be sent
592
+ _wrapSetXhrProp(xhr, strDisabledPropertyName, disabled);
593
+ }
594
+
595
+ if (withCredentials) {
596
+ // Some libraries require that the withCredentials flag is set "before" open and
597
+ // - Wrapping as IE 10 has started throwing when setting before open
598
+ _wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
599
+ }
600
+
601
+ xhr.open(method, urlString, !isSync);
602
+
603
+ if (withCredentials) {
604
+ // withCredentials should be set AFTER open (https://xhr.spec.whatwg.org/#the-withcredentials-attribute)
605
+ // And older firefox instances from 11+ will throw for sync events (current versions don't) which happens during unload processing
606
+ _wrapSetXhrProp(xhr, strWithCredentials, withCredentials);
607
+ }
608
+
609
+ return xhr;
610
+ }
package/tsconfig.json CHANGED
@@ -13,12 +13,10 @@
13
13
  "noEmitHelpers": true,
14
14
  "forceConsistentCasingInFileNames": true,
15
15
  "declaration": true,
16
- "rootDir": "shared/core",
17
- "outDir": "dist-esm/"
16
+ "outDir": "dist-esm/src/"
18
17
  },
19
18
  "include": [
20
- "./src/**/*.ts",
21
- "./test/**/*.ts"
19
+ "./src/**/*.ts"
22
20
  ],
23
21
  "exclude": [
24
22
  "node_modules/"