@kush_hemant/react-api-monitor 1.0.30 → 1.0.32

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 (2) hide show
  1. package/dist/index.js +7 -40
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -32,19 +32,16 @@ function getMetadata() {
32
32
  }
33
33
 
34
34
  // src/network/fetchMonitor.js
35
- var alreadyPatched = false;
36
35
  function monitorFetch() {
37
- if (alreadyPatched) return;
38
- alreadyPatched = true;
39
- const originalFetch = globalThis.fetch || window.fetch;
40
- const patchedFetch = async (input, init = {}) => {
36
+ const originalFetch = window.fetch;
37
+ window.fetch = async function(input, init = {}) {
38
+ const start = Date.now();
41
39
  const request = input instanceof Request ? input : new Request(input, init);
42
40
  const url = request.url;
43
41
  const method = request.method || "GET";
44
42
  if (LOG_ENDPOINT && url.startsWith(LOG_ENDPOINT)) {
45
- return originalFetch(input, init);
43
+ return originalFetch.apply(this, arguments);
46
44
  }
47
- const start = Date.now();
48
45
  let requestBody = null;
49
46
  try {
50
47
  requestBody = await request.clone().text();
@@ -55,9 +52,7 @@ function monitorFetch() {
55
52
  requestHeaders[k] = v;
56
53
  });
57
54
  try {
58
- const response = await originalFetch(
59
- request
60
- );
55
+ const response = await originalFetch.apply(this, arguments);
61
56
  let responseBody = null;
62
57
  try {
63
58
  responseBody = await response.clone().text();
@@ -87,6 +82,8 @@ function monitorFetch() {
87
82
  transport: "fetch",
88
83
  url,
89
84
  method,
85
+ requestHeaders,
86
+ requestBody,
90
87
  error: err.message,
91
88
  duration: Date.now() - start,
92
89
  ...getMetadata()
@@ -94,10 +91,6 @@ function monitorFetch() {
94
91
  throw err;
95
92
  }
96
93
  };
97
- globalThis.fetch = patchedFetch;
98
- if (typeof window !== "undefined") {
99
- window.fetch = patchedFetch;
100
- }
101
94
  }
102
95
 
103
96
  // src/network/xhrMonitor.js
@@ -139,31 +132,6 @@ function monitorXHR() {
139
132
  };
140
133
  }
141
134
 
142
- // src/network/resourceMonitor.js
143
- function monitorResources() {
144
- if (!window.PerformanceObserver) return;
145
- const observer = new PerformanceObserver((list) => {
146
- list.getEntries().forEach((entry) => {
147
- if (entry.initiatorType === "fetch" || entry.initiatorType === "xmlhttprequest" || entry.initiatorType === "beacon") {
148
- return;
149
- }
150
- if (LOG_ENDPOINT && entry.name.includes(LOG_ENDPOINT)) {
151
- return;
152
- }
153
- sendLog({
154
- type: "resource",
155
- transport: "resource",
156
- url: entry.name,
157
- method: "GET",
158
- duration: Math.round(entry.duration),
159
- statusCode: 0,
160
- ...getMetadata()
161
- });
162
- });
163
- });
164
- observer.observe({ entryTypes: ["resource"] });
165
- }
166
-
167
135
  // src/network/monitorAxios.js
168
136
  function monitorAxios() {
169
137
  if (!window.axios) return;
@@ -214,7 +182,6 @@ function startNetworkMonitoring() {
214
182
  monitorXHR();
215
183
  monitorAxios();
216
184
  monitorBeacon();
217
- monitorResources();
218
185
  }
219
186
 
220
187
  // src/index.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kush_hemant/react-api-monitor",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Automatic API monitoring SDK for React apps",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",