@microsoft/applicationinsights-react-js 3.2.2-nightly.2111-08 → 3.2.2-nightly.2111-09

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 (36) hide show
  1. package/api-extractor.json +361 -0
  2. package/applicationinsights-react-js.build.error.log +40 -0
  3. package/applicationinsights-react-js.build.log +93 -0
  4. package/browser/applicationinsights-react-js.js +10 -3
  5. package/browser/applicationinsights-react-js.js.map +1 -1
  6. package/browser/applicationinsights-react-js.min.js +2 -2
  7. package/browser/applicationinsights-react-js.min.js.map +1 -1
  8. package/dist/applicationinsights-react-js.api.json +2 -2
  9. package/dist/applicationinsights-react-js.d.ts +1 -1
  10. package/dist/applicationinsights-react-js.js +10 -3
  11. package/dist/applicationinsights-react-js.js.map +1 -1
  12. package/dist/applicationinsights-react-js.min.js +2 -2
  13. package/dist/applicationinsights-react-js.min.js.map +1 -1
  14. package/dist/applicationinsights-react-js.rollup.d.ts +1 -1
  15. package/dist-esm/AppInsightsContext.js +1 -1
  16. package/dist-esm/AppInsightsErrorBoundary.js +1 -1
  17. package/dist-esm/Interfaces/IReactExtensionConfig.js +1 -1
  18. package/dist-esm/ReactPlugin.js +12 -3
  19. package/dist-esm/ReactPlugin.js.map +1 -1
  20. package/dist-esm/applicationinsights-react-js.js +1 -1
  21. package/dist-esm/useTrackEvent.js +1 -1
  22. package/dist-esm/useTrackMetric.js +1 -1
  23. package/dist-esm/withAITracking.js +1 -1
  24. package/microsoft-applicationinsights-react-js-3.2.2-nightly.2111-09.tgz +0 -0
  25. package/package.json +14 -13
  26. package/rollup.config.js +148 -0
  27. package/src/ReactPlugin.ts +12 -3
  28. package/temp/applicationinsights-react-js.api.md +98 -0
  29. package/test/AppInsightsErrorBoundary.test.tsx +88 -0
  30. package/test/ReactAI.test.ts +158 -0
  31. package/test/TestComponent.tsx +31 -0
  32. package/test/jestconfig.json +21 -0
  33. package/test/tsconfig.json +16 -0
  34. package/test/withAITracking.test.tsx +72 -0
  35. package/tslint.json +5 -0
  36. package/types/tsdoc-metadata.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights react plugin, 3.2.2-nightly.2111-08
2
+ * Microsoft Application Insights react plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-08
2
+ * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  import { createContext, useContext } from "react";
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-08
2
+ * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-08
2
+ * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-08
2
+ * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  /**
@@ -98,10 +98,19 @@ var ReactPlugin = /** @class */ (function (_super) {
98
98
  };
99
99
  ReactPlugin.prototype.addHistoryListener = function (history) {
100
100
  var _this = this;
101
- var locationListener = function (location, action) {
101
+ var locationListener = function (arg) {
102
+ // v4 of the history API passes "location" as the first argument, while v5 passes an object that contains location and action
103
+ var locn = null;
104
+ if ("location" in arg) {
105
+ // Looks like v5
106
+ locn = arg["location"];
107
+ }
108
+ else {
109
+ locn = arg;
110
+ }
102
111
  // Timeout to ensure any changes to the DOM made by route changes get included in pageView telemetry
103
112
  setTimeout(function () {
104
- var pageViewTelemetry = { uri: location.pathname };
113
+ var pageViewTelemetry = { uri: locn.pathname };
105
114
  _this.trackPageView(pageViewTelemetry);
106
115
  }, 500);
107
116
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ReactPlugin.js.map","sources":["ReactPlugin.js"],"sourcesContent":["/**\r\n * ReactPlugin.ts\r\n * @copyright Microsoft 2019\r\n */\r\nimport { __extends } from \"tslib\";\r\nimport { BaseTelemetryPlugin, _InternalMessageId, LoggingSeverity, safeGetCookieMgr, arrForEach } from \"@microsoft/applicationinsights-core-js\";\r\nvar ReactPlugin = /** @class */ (function (_super) {\r\n __extends(ReactPlugin, _super);\r\n function ReactPlugin() {\r\n var _this = _super !== null && _super.apply(this, arguments) || this;\r\n _this.priority = 185;\r\n _this.identifier = 'ReactPlugin';\r\n return _this;\r\n }\r\n ReactPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {\r\n var _this = this;\r\n _super.prototype.initialize.call(this, config, core, extensions, pluginChain);\r\n this._extensionConfig =\r\n config.extensionConfig && config.extensionConfig[this.identifier]\r\n ? config.extensionConfig[this.identifier]\r\n : { history: null };\r\n arrForEach(extensions, function (ext) {\r\n var identifier = ext.identifier;\r\n if (identifier === 'ApplicationInsightsAnalytics') {\r\n _this._analyticsPlugin = ext;\r\n }\r\n });\r\n if (this._extensionConfig.history) {\r\n this.addHistoryListener(this._extensionConfig.history);\r\n var pageViewTelemetry = {\r\n uri: this._extensionConfig.history.location.pathname\r\n };\r\n this.trackPageView(pageViewTelemetry);\r\n }\r\n };\r\n /**\r\n * Get the current cookie manager for this instance\r\n */\r\n ReactPlugin.prototype.getCookieMgr = function () {\r\n return safeGetCookieMgr(this.core);\r\n };\r\n /**\r\n * Get application insights instance.\r\n */\r\n ReactPlugin.prototype.getAppInsights = function () {\r\n return this._analyticsPlugin;\r\n };\r\n /**\r\n * Add Part A fields to the event\r\n * @param event The event that needs to be processed\r\n */\r\n ReactPlugin.prototype.processTelemetry = function (event, itemCtx) {\r\n this.processNext(event, itemCtx);\r\n };\r\n ReactPlugin.prototype.trackMetric = function (metric, customProperties) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackMetric(metric, customProperties);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.trackPageView = function (pageView) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackPageView(pageView);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.trackEvent = function (event, customProperties) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackEvent(event, customProperties);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.trackException = function (exception, customProperties) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackException(exception, customProperties);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.trackTrace = function (trace, customProperties) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackTrace(trace, customProperties);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.addHistoryListener = function (history) {\r\n var _this = this;\r\n var locationListener = function (location, action) {\r\n // Timeout to ensure any changes to the DOM made by route changes get included in pageView telemetry\r\n setTimeout(function () {\r\n var pageViewTelemetry = { uri: location.pathname };\r\n _this.trackPageView(pageViewTelemetry);\r\n }, 500);\r\n };\r\n history.listen(locationListener);\r\n };\r\n return ReactPlugin;\r\n}(BaseTelemetryPlugin));\r\nexport default ReactPlugin;\r\n//# sourceMappingURL=ReactPlugin.js.map"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA,gFAAkC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"file":"ReactPlugin.js.map","sources":["ReactPlugin.js"],"sourcesContent":["/**\r\n * ReactPlugin.ts\r\n * @copyright Microsoft 2019\r\n */\r\nimport { __extends } from \"tslib\";\r\nimport { BaseTelemetryPlugin, _InternalMessageId, LoggingSeverity, safeGetCookieMgr, arrForEach } from \"@microsoft/applicationinsights-core-js\";\r\nvar ReactPlugin = /** @class */ (function (_super) {\r\n __extends(ReactPlugin, _super);\r\n function ReactPlugin() {\r\n var _this = _super !== null && _super.apply(this, arguments) || this;\r\n _this.priority = 185;\r\n _this.identifier = 'ReactPlugin';\r\n return _this;\r\n }\r\n ReactPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {\r\n var _this = this;\r\n _super.prototype.initialize.call(this, config, core, extensions, pluginChain);\r\n this._extensionConfig =\r\n config.extensionConfig && config.extensionConfig[this.identifier]\r\n ? config.extensionConfig[this.identifier]\r\n : { history: null };\r\n arrForEach(extensions, function (ext) {\r\n var identifier = ext.identifier;\r\n if (identifier === 'ApplicationInsightsAnalytics') {\r\n _this._analyticsPlugin = ext;\r\n }\r\n });\r\n if (this._extensionConfig.history) {\r\n this.addHistoryListener(this._extensionConfig.history);\r\n var pageViewTelemetry = {\r\n uri: this._extensionConfig.history.location.pathname\r\n };\r\n this.trackPageView(pageViewTelemetry);\r\n }\r\n };\r\n /**\r\n * Get the current cookie manager for this instance\r\n */\r\n ReactPlugin.prototype.getCookieMgr = function () {\r\n return safeGetCookieMgr(this.core);\r\n };\r\n /**\r\n * Get application insights instance.\r\n */\r\n ReactPlugin.prototype.getAppInsights = function () {\r\n return this._analyticsPlugin;\r\n };\r\n /**\r\n * Add Part A fields to the event\r\n * @param event The event that needs to be processed\r\n */\r\n ReactPlugin.prototype.processTelemetry = function (event, itemCtx) {\r\n this.processNext(event, itemCtx);\r\n };\r\n ReactPlugin.prototype.trackMetric = function (metric, customProperties) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackMetric(metric, customProperties);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.trackPageView = function (pageView) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackPageView(pageView);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.trackEvent = function (event, customProperties) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackEvent(event, customProperties);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.trackException = function (exception, customProperties) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackException(exception, customProperties);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.trackTrace = function (trace, customProperties) {\r\n if (this._analyticsPlugin) {\r\n this._analyticsPlugin.trackTrace(trace, customProperties);\r\n }\r\n else {\r\n this.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, \"Analytics plugin is not available, React plugin telemetry will not be sent: \");\r\n }\r\n };\r\n ReactPlugin.prototype.addHistoryListener = function (history) {\r\n var _this = this;\r\n var locationListener = function (arg) {\r\n // v4 of the history API passes \"location\" as the first argument, while v5 passes an object that contains location and action \r\n var locn = null;\r\n if (\"location\" in arg) {\r\n // Looks like v5\r\n locn = arg[\"location\"];\r\n }\r\n else {\r\n locn = arg;\r\n }\r\n // Timeout to ensure any changes to the DOM made by route changes get included in pageView telemetry\r\n setTimeout(function () {\r\n var pageViewTelemetry = { uri: locn.pathname };\r\n _this.trackPageView(pageViewTelemetry);\r\n }, 500);\r\n };\r\n history.listen(locationListener);\r\n };\r\n return ReactPlugin;\r\n}(BaseTelemetryPlugin));\r\nexport default ReactPlugin;\r\n//# sourceMappingURL=ReactPlugin.js.map"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA,gFAAkC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-08
2
+ * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-08
2
+ * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-08
2
+ * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  import { useEffect, useRef } from "react";
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-08
2
+ * Application Insights JavaScript SDK - React Plugin, 3.2.2-nightly.2111-09
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/applicationinsights-react-js",
3
- "version": "3.2.2-nightly.2111-08",
3
+ "version": "3.2.2-nightly.2111-09",
4
4
  "description": "Microsoft Application Insights React plugin",
5
5
  "main": "dist/applicationinsights-react-js.js",
6
6
  "module": "dist-esm/applicationinsights-react-js.js",
@@ -30,8 +30,8 @@
30
30
  "@testing-library/react": "^11.2.5",
31
31
  "@testing-library/user-event": "^12.8.1",
32
32
  "@types/cheerio": "0.22.13",
33
- "@types/history": "4.7.2",
34
- "@types/jest": "^24.0.11",
33
+ "@types/history": "^4.7.9",
34
+ "@types/jest": "^27.0.2",
35
35
  "@types/node": "11.13.2",
36
36
  "@types/prop-types": "^15.7.3",
37
37
  "@types/react": "^16.9.11",
@@ -39,9 +39,9 @@
39
39
  "csstype": "~2.6.7",
40
40
  "grunt": "^1.4.1",
41
41
  "grunt-cli": "^1.4.3",
42
- "jest": "^24.7.1",
43
- "react": "^17.0.1",
44
- "react-dom": "^17.0.1",
42
+ "jest": "^27.3.1",
43
+ "react": "^17.0.2",
44
+ "react-dom": "^17.0.2",
45
45
  "globby": "^11.0.0",
46
46
  "magic-string": "^0.25.7",
47
47
  "@rollup/plugin-commonjs": "^18.0.0",
@@ -50,21 +50,22 @@
50
50
  "rollup-plugin-cleanup": "3.2.1",
51
51
  "rollup-plugin-peer-deps-external": "^2.2.4",
52
52
  "rollup": "^2.32.0",
53
- "ts-jest": "^24.0.2",
53
+ "ts-jest": "^27.0.7",
54
54
  "typescript": "^4.3.4",
55
55
  "tslib": "^2.0.0",
56
- "uglify-js": "^3.11.0"
56
+ "uglify-js": "^3.11.0",
57
+ "history": "^5.1.0"
57
58
  },
58
59
  "dependencies": {
59
60
  "@microsoft/applicationinsights-shims": "2.0.0",
60
- "@microsoft/applicationinsights-core-js": "2.7.2-nightly.2111-08",
61
- "@microsoft/applicationinsights-common": "2.7.2-nightly.2111-08",
62
- "@microsoft/dynamicproto-js": "^1.1.4",
63
- "history": "^4.10.1"
61
+ "@microsoft/applicationinsights-core-js": "2.7.2-nightly.2111-09",
62
+ "@microsoft/applicationinsights-common": "2.7.2-nightly.2111-09",
63
+ "@microsoft/dynamicproto-js": "^1.1.4"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "tslib": "*",
67
- "react": "^17.0.1"
67
+ "react": "^17.0.1",
68
+ "history": ">= 4.10.1"
68
69
  },
69
70
  "license": "MIT",
70
71
  "publishConfig": {
@@ -0,0 +1,148 @@
1
+ import nodeResolve from "@rollup/plugin-node-resolve";
2
+ import commonjs from "@rollup/plugin-commonjs";
3
+ import replace from "@rollup/plugin-replace";
4
+ import cleanup from "rollup-plugin-cleanup";
5
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external';
6
+ import { uglify } from "../../tools/rollup-plugin-uglify3-js/dist/esm/rollup-plugin-uglify3-js";
7
+ import { es3Poly, importCheck } from "@microsoft/applicationinsights-rollup-es3";
8
+ import dynamicRemove from "@microsoft/dynamicproto-js/tools/rollup/node/removedynamic";
9
+ import { updateDistEsmFiles } from "../../tools/updateDistEsm/updateDistEsm";
10
+
11
+ const version = require("./package.json").version;
12
+ const outputName = "applicationinsights-react-js";
13
+ const banner = [
14
+ "/*!",
15
+ ` * Application Insights JavaScript SDK - React Plugin, ${version}`,
16
+ " * Copyright (c) Microsoft and contributors. All rights reserved.",
17
+ " */"
18
+ ].join("\n");
19
+
20
+ const replaceValues = {
21
+ "// Copyright (c) Microsoft Corporation. All rights reserved.": "",
22
+ "// Licensed under the MIT License.": ""
23
+ };
24
+
25
+ function doCleanup() {
26
+ return cleanup({
27
+ comments: [
28
+ 'some',
29
+ /^.\s*@DynamicProtoStub/i,
30
+ /^\*\*\s*@class\s*$/
31
+ ]
32
+ })
33
+ }
34
+
35
+ const browserRollupConfigFactory = isProduction => {
36
+ const browserRollupConfig = {
37
+ input: `dist-esm/${outputName}.js`,
38
+ output: {
39
+ file: `browser/${outputName}.js`,
40
+ banner: banner,
41
+ format: "umd",
42
+ name: "Microsoft.ApplicationInsights",
43
+ extend: true,
44
+ freeze: false,
45
+ sourcemap: true
46
+ },
47
+ plugins: [
48
+ dynamicRemove(),
49
+ replace({
50
+ preventAssignment: true,
51
+ delimiters: ["", ""],
52
+ values: replaceValues
53
+ }),
54
+ importCheck({ exclude: [ "applicationinsights-react-js" ] }),
55
+ peerDepsExternal(),
56
+ nodeResolve({
57
+ browser: true,
58
+ preferBuiltins: true,
59
+ dedupe: [ "react", "react-dom" ]
60
+ }),
61
+ commonjs(),
62
+ doCleanup(),
63
+ es3Poly()
64
+ ]
65
+ };
66
+
67
+ if (isProduction) {
68
+ browserRollupConfig.output.file = `browser/${outputName}.min.js`;
69
+ browserRollupConfig.plugins.push(
70
+ uglify({
71
+ ie8: true,
72
+ toplevel: true,
73
+ compress: {
74
+ passes:3,
75
+ unsafe: true
76
+ },
77
+ output: {
78
+ preamble: banner,
79
+ webkit:true
80
+ }
81
+ })
82
+ );
83
+ }
84
+
85
+ return browserRollupConfig;
86
+ };
87
+
88
+ const nodeUmdRollupConfigFactory = (isProduction) => {
89
+ const nodeRollupConfig = {
90
+ input: `dist-esm/${outputName}.js`,
91
+ output: {
92
+ file: `dist/${outputName}.js`,
93
+ banner: banner,
94
+ format: "umd",
95
+ name: "Microsoft.ApplicationInsights",
96
+ extend: true,
97
+ freeze: false,
98
+ sourcemap: true
99
+ },
100
+ plugins: [
101
+ dynamicRemove(),
102
+ replace({
103
+ preventAssignment: true,
104
+ delimiters: ["", ""],
105
+ values: replaceValues
106
+ }),
107
+ importCheck({ exclude: [ "applicationinsights-react-js" ] }),
108
+ peerDepsExternal(),
109
+ nodeResolve({
110
+ browser: true,
111
+ preferBuiltins: true,
112
+ dedupe: [ "react", "react-dom" ]
113
+ }),
114
+ commonjs(),
115
+ doCleanup(),
116
+ es3Poly()
117
+ ]
118
+ };
119
+
120
+ if (isProduction) {
121
+ nodeRollupConfig.output.file = `dist/${outputName}.min.js`;
122
+ nodeRollupConfig.plugins.push(
123
+ uglify({
124
+ ie8: true,
125
+ toplevel: true,
126
+ compress: {
127
+ passes:3,
128
+ unsafe: true
129
+ },
130
+ output: {
131
+ preamble: banner,
132
+ webkit:true
133
+ }
134
+ })
135
+ );
136
+ }
137
+
138
+ return nodeRollupConfig;
139
+ };
140
+
141
+ updateDistEsmFiles(replaceValues, banner);
142
+
143
+ export default [
144
+ browserRollupConfigFactory(true),
145
+ browserRollupConfigFactory(false),
146
+ nodeUmdRollupConfigFactory(true),
147
+ nodeUmdRollupConfigFactory(false)
148
+ ];
@@ -12,7 +12,7 @@ import {
12
12
  ITelemetryPluginChain, _InternalMessageId, LoggingSeverity, ICustomProperties, safeGetCookieMgr, ICookieMgr, arrForEach
13
13
  } from "@microsoft/applicationinsights-core-js";
14
14
  import { IReactExtensionConfig } from './Interfaces/IReactExtensionConfig';
15
- import { History, LocationListener, Location, Action } from "history";
15
+ import { History, Location, Action, Update } from "history";
16
16
 
17
17
  export default class ReactPlugin extends BaseTelemetryPlugin {
18
18
  public priority = 185;
@@ -116,10 +116,19 @@ export default class ReactPlugin extends BaseTelemetryPlugin {
116
116
 
117
117
 
118
118
  private addHistoryListener(history: History): void {
119
- const locationListener: LocationListener = (location: Location, action: Action): void => {
119
+ const locationListener = (arg: Location | Update): void => {
120
+ // v4 of the history API passes "location" as the first argument, while v5 passes an object that contains location and action
121
+ let locn: Location = null;
122
+ if ("location" in arg) {
123
+ // Looks like v5
124
+ locn = arg["location"];
125
+ } else {
126
+ locn = arg as Location;
127
+ }
128
+
120
129
  // Timeout to ensure any changes to the DOM made by route changes get included in pageView telemetry
121
130
  setTimeout(() => {
122
- const pageViewTelemetry: IPageViewTelemetry = { uri: location.pathname };
131
+ const pageViewTelemetry: IPageViewTelemetry = { uri: locn.pathname };
123
132
  this.trackPageView(pageViewTelemetry);
124
133
  }, 500);
125
134
  };
@@ -0,0 +1,98 @@
1
+ ## API Report File for "@microsoft/applicationinsights-react-js"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ import { BaseTelemetryPlugin } from '@microsoft/applicationinsights-core-js';
8
+ import { Context } from 'react';
9
+ import { Dispatch } from 'react';
10
+ import { History as History_2 } from 'history';
11
+ import { IAppInsights } from '@microsoft/applicationinsights-common';
12
+ import { IAppInsightsCore } from '@microsoft/applicationinsights-core-js';
13
+ import { IConfig } from '@microsoft/applicationinsights-common';
14
+ import { IConfiguration } from '@microsoft/applicationinsights-core-js';
15
+ import { ICookieMgr } from '@microsoft/applicationinsights-core-js';
16
+ import { ICustomProperties } from '@microsoft/applicationinsights-core-js';
17
+ import { IEventTelemetry } from '@microsoft/applicationinsights-common';
18
+ import { IExceptionTelemetry } from '@microsoft/applicationinsights-common';
19
+ import { IMetricTelemetry } from '@microsoft/applicationinsights-common';
20
+ import { IPageViewTelemetry } from '@microsoft/applicationinsights-common';
21
+ import { IPlugin } from '@microsoft/applicationinsights-core-js';
22
+ import { IProcessTelemetryContext } from '@microsoft/applicationinsights-core-js';
23
+ import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
24
+ import { ITelemetryPluginChain } from '@microsoft/applicationinsights-core-js';
25
+ import { ITraceTelemetry } from '@microsoft/applicationinsights-common';
26
+ import * as React_2 from 'react';
27
+ import { default as React_3 } from 'react';
28
+ import { SetStateAction } from 'react';
29
+
30
+ // Warning: (ae-forgotten-export) The symbol "AppInsightsReactContext" needs to be exported by the entry point applicationinsights-react-js.d.ts
31
+ //
32
+ // @public (undocumented)
33
+ export const AppInsightsContext: AppInsightsReactContext;
34
+
35
+ // Warning: (ae-forgotten-export) The symbol "IAppInsightsErrorBoundaryProps" needs to be exported by the entry point applicationinsights-react-js.d.ts
36
+ // Warning: (ae-forgotten-export) The symbol "IAppInsightsErrorBoundaryState" needs to be exported by the entry point applicationinsights-react-js.d.ts
37
+ //
38
+ // @public (undocumented)
39
+ export class AppInsightsErrorBoundary extends React_3.Component<IAppInsightsErrorBoundaryProps, IAppInsightsErrorBoundaryState> {
40
+ // (undocumented)
41
+ componentDidCatch(error: Error, errorInfo: React_3.ErrorInfo): void;
42
+ // (undocumented)
43
+ render(): React_3.ReactNode;
44
+ // (undocumented)
45
+ state: {
46
+ hasError: boolean;
47
+ };
48
+ }
49
+
50
+ // @public
51
+ export interface IReactExtensionConfig {
52
+ readonly history?: History_2;
53
+ }
54
+
55
+ // @public (undocumented)
56
+ export class ReactPlugin extends BaseTelemetryPlugin {
57
+ getAppInsights(): IAppInsights;
58
+ getCookieMgr(): ICookieMgr;
59
+ // (undocumented)
60
+ identifier: string;
61
+ // (undocumented)
62
+ initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
63
+ // (undocumented)
64
+ priority: number;
65
+ processTelemetry(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
66
+ // (undocumented)
67
+ trackEvent(event: IEventTelemetry, customProperties?: ICustomProperties): void;
68
+ // (undocumented)
69
+ trackException(exception: IExceptionTelemetry, customProperties?: {
70
+ [key: string]: any;
71
+ }): void;
72
+ // (undocumented)
73
+ trackMetric(metric: IMetricTelemetry, customProperties: ICustomProperties): void;
74
+ // (undocumented)
75
+ trackPageView(pageView: IPageViewTelemetry): void;
76
+ // (undocumented)
77
+ trackTrace(trace: ITraceTelemetry, customProperties?: {
78
+ [key: string]: any;
79
+ }): void;
80
+ }
81
+
82
+ // @public (undocumented)
83
+ export const useAppInsightsContext: () => ReactPlugin;
84
+
85
+ // Warning: (ae-forgotten-export) The symbol "AIReactCustomEvent" needs to be exported by the entry point applicationinsights-react-js.d.ts
86
+ //
87
+ // @public (undocumented)
88
+ export function useTrackEvent<T>(reactPlugin: ReactPlugin, eventName: string, eventData: T, skipFirstRun?: boolean): AIReactCustomEvent<T>;
89
+
90
+ // @public (undocumented)
91
+ export const useTrackMetric: (reactPlugin: ReactPlugin, componentName: string) => () => void;
92
+
93
+ // @public
94
+ export function withAITracking<P>(reactPlugin: ReactPlugin, Component: React_2.ComponentType<P>, componentName?: string, className?: string): React_2.ComponentClass<P>;
95
+
96
+ // (No @packageDocumentation comment for this package)
97
+
98
+ ```
@@ -0,0 +1,88 @@
1
+ import React from "react";
2
+ import ReactPlugin from "../src/ReactPlugin";
3
+ import AppInsightsErrorBoundary from "../src/AppInsightsErrorBoundary";
4
+ import { TestComponent, ErrorTestComponent } from "./TestComponent";
5
+ import { render} from '@testing-library/react';
6
+ import '@testing-library/jest-dom/extend-expect';
7
+
8
+ let reactPlugin: ReactPlugin;
9
+ let trackExceptionSpy;
10
+ let orgWarn = console && console.warn;
11
+
12
+ describe("<AppInsightsErrorBoundary />", () => {
13
+ beforeEach(() => {
14
+ if (orgWarn) {
15
+ console.warn = (msg) => { /* Swallow */ }
16
+ }
17
+ reactPlugin = new ReactPlugin();
18
+ trackExceptionSpy = reactPlugin.trackException = jest.fn();
19
+ });
20
+
21
+ afterEach(() => {
22
+ if (orgWarn) {
23
+ console.warn = orgWarn;
24
+ }
25
+ });
26
+
27
+ it("should render a non-erroring component", () => {
28
+ const aiErrorBoundry = render(
29
+ <AppInsightsErrorBoundary
30
+ appInsights={reactPlugin}
31
+ onError={() => <div></div>}
32
+ >
33
+ <TestComponent />
34
+ </AppInsightsErrorBoundary>
35
+ );
36
+ const testComponent = render(<TestComponent />);
37
+ expect(aiErrorBoundry.container).toEqual(testComponent.container);
38
+ });
39
+
40
+ it("should catch the error and render the alternative component", async () => {
41
+ const orgError = console && console.error;
42
+ if (orgError) {
43
+ console.error = msg => { /* Do Nothing */ };
44
+ }
45
+
46
+ try {
47
+ const ErrorDisplay = () => <div>Error</div>;
48
+ const aiErrorBoundry = render(
49
+ <AppInsightsErrorBoundary
50
+ appInsights={reactPlugin}
51
+ onError={ErrorDisplay}
52
+ >
53
+ <ErrorTestComponent />
54
+ </AppInsightsErrorBoundary>
55
+ );
56
+ const errorDisplay = render(<ErrorDisplay />);
57
+ expect(aiErrorBoundry.container).toEqual(errorDisplay.container);
58
+ } finally {
59
+ if (orgError) {
60
+ console.error = orgError;
61
+ }
62
+ }
63
+ });
64
+
65
+ it("should catch the error and track exception", async () => {
66
+ const orgError = console && console.error;
67
+ if (orgError) {
68
+ console.error = msg => { /* Do Nothing */ };
69
+ }
70
+
71
+ try {
72
+ const ErrorDisplay = () => <div>Error</div>;
73
+ const aiErrorBoundry = render(
74
+ <AppInsightsErrorBoundary
75
+ appInsights={reactPlugin}
76
+ onError={ErrorDisplay}
77
+ >
78
+ <ErrorTestComponent />
79
+ </AppInsightsErrorBoundary>
80
+ );
81
+ expect(trackExceptionSpy).toHaveBeenCalledTimes(1);
82
+ } finally {
83
+ if (orgError) {
84
+ console.error = orgError;
85
+ }
86
+ }
87
+ });
88
+ });