@kush_hemant/react-api-monitor 1.0.26 → 1.0.28
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.
- package/dist/index.js +26 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// src/core/sender.js
|
|
2
|
-
var
|
|
2
|
+
var LOG_ENDPOINT = "";
|
|
3
3
|
function configureSender(url) {
|
|
4
|
-
|
|
4
|
+
LOG_ENDPOINT = url;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function sendLog(data) {
|
|
7
7
|
var _a;
|
|
8
|
-
if (!
|
|
8
|
+
if (!LOG_ENDPOINT) return;
|
|
9
9
|
((_a = navigator.sendBeacon) == null ? void 0 : _a.call(
|
|
10
10
|
navigator,
|
|
11
|
-
|
|
11
|
+
LOG_ENDPOINT,
|
|
12
12
|
JSON.stringify(data)
|
|
13
|
-
)) || fetch(
|
|
13
|
+
)) || fetch(LOG_ENDPOINT, {
|
|
14
14
|
method: "POST",
|
|
15
15
|
headers: { "Content-Type": "application/json" },
|
|
16
16
|
body: JSON.stringify(data),
|
|
@@ -19,6 +19,18 @@ function sendLog2(data) {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// src/utils/metadata.js
|
|
23
|
+
function getMetadata() {
|
|
24
|
+
return {
|
|
25
|
+
pageUrl: location.href,
|
|
26
|
+
userAgent: navigator.userAgent,
|
|
27
|
+
language: navigator.language,
|
|
28
|
+
platform: navigator.platform,
|
|
29
|
+
screen: `${screen.width}x${screen.height}`,
|
|
30
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
// src/network/fetchMonitor.js
|
|
23
35
|
function monitorFetch() {
|
|
24
36
|
const originalFetch = globalThis.fetch || window.fetch;
|
|
@@ -66,18 +78,6 @@ function monitorFetch() {
|
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
|
|
69
|
-
// src/utils/metadata.js
|
|
70
|
-
function getMetadata2() {
|
|
71
|
-
return {
|
|
72
|
-
pageUrl: location.href,
|
|
73
|
-
userAgent: navigator.userAgent,
|
|
74
|
-
language: navigator.language,
|
|
75
|
-
platform: navigator.platform,
|
|
76
|
-
screen: `${screen.width}x${screen.height}`,
|
|
77
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
81
|
// src/network/xhrMonitor.js
|
|
82
82
|
function monitorXHR() {
|
|
83
83
|
const originalOpen = XMLHttpRequest.prototype.open;
|
|
@@ -95,11 +95,11 @@ function monitorXHR() {
|
|
|
95
95
|
};
|
|
96
96
|
XMLHttpRequest.prototype.send = function(body) {
|
|
97
97
|
const start = Date.now();
|
|
98
|
-
if (this._url &&
|
|
98
|
+
if (this._url && LOG_ENDPOINT && this._url.includes(LOG_ENDPOINT)) {
|
|
99
99
|
return originalSend.call(this, body);
|
|
100
100
|
}
|
|
101
101
|
this.addEventListener("loadend", () => {
|
|
102
|
-
|
|
102
|
+
sendLog({
|
|
103
103
|
type: "api_call",
|
|
104
104
|
transport: "xhr",
|
|
105
105
|
url: this._url,
|
|
@@ -110,7 +110,7 @@ function monitorXHR() {
|
|
|
110
110
|
responseHeaders: this.getAllResponseHeaders(),
|
|
111
111
|
responseBody: this.responseText,
|
|
112
112
|
duration: Date.now() - start,
|
|
113
|
-
...
|
|
113
|
+
...getMetadata()
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
return originalSend.call(this, body);
|
|
@@ -127,14 +127,14 @@ function monitorAxios() {
|
|
|
127
127
|
window.axios.interceptors.response.use(
|
|
128
128
|
(response) => {
|
|
129
129
|
var _a;
|
|
130
|
-
|
|
130
|
+
sendLog({
|
|
131
131
|
type: "api_call",
|
|
132
132
|
transport: "axios",
|
|
133
133
|
url: response.config.url,
|
|
134
134
|
method: (_a = response.config.method) == null ? void 0 : _a.toUpperCase(),
|
|
135
135
|
statusCode: response.status,
|
|
136
136
|
duration: Date.now() - response.config.__startTime,
|
|
137
|
-
...
|
|
137
|
+
...getMetadata()
|
|
138
138
|
});
|
|
139
139
|
return response;
|
|
140
140
|
},
|
|
@@ -146,16 +146,16 @@ function monitorAxios() {
|
|
|
146
146
|
function monitorBeacon() {
|
|
147
147
|
const originalBeacon = navigator.sendBeacon;
|
|
148
148
|
navigator.sendBeacon = function(url, data) {
|
|
149
|
-
if (
|
|
149
|
+
if (LOG_ENDPOINT && url.includes(LOG_ENDPOINT)) {
|
|
150
150
|
return originalBeacon.call(this, url, data);
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
sendLog({
|
|
153
153
|
type: "api_call",
|
|
154
154
|
transport: "beacon",
|
|
155
155
|
url,
|
|
156
156
|
method: "POST",
|
|
157
157
|
requestBody: data,
|
|
158
|
-
...
|
|
158
|
+
...getMetadata()
|
|
159
159
|
});
|
|
160
160
|
return originalBeacon.call(this, url, data);
|
|
161
161
|
};
|