@kush_hemant/react-api-monitor 1.0.3 → 1.0.4

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 +16 -9
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  // src/core/sender.js
2
- var endpoint = "";
2
+ var LOG_ENDPOINT = "";
3
3
  function configureSender(url) {
4
- endpoint = url;
4
+ LOG_ENDPOINT = url;
5
5
  }
6
6
  function sendLog(data) {
7
7
  var _a;
8
- if (!endpoint) return;
8
+ if (!LOG_ENDPOINT) return;
9
9
  ((_a = navigator.sendBeacon) == null ? void 0 : _a.call(
10
10
  navigator,
11
- endpoint,
11
+ LOG_ENDPOINT,
12
12
  JSON.stringify(data)
13
- )) || fetch(endpoint, {
13
+ )) || fetch(LOG_ENDPOINT, {
14
14
  method: "POST",
15
15
  headers: { "Content-Type": "application/json" },
16
16
  body: JSON.stringify(data),
@@ -32,9 +32,13 @@ function getMetadata() {
32
32
  function monitorFetch() {
33
33
  const originalFetch = window.fetch;
34
34
  window.fetch = async (input, init = {}) => {
35
+ const url = typeof input === "string" ? input : (input == null ? void 0 : input.url) || "";
36
+ if (url.includes("/api/logs")) {
37
+ return originalFetch(input, init);
38
+ }
35
39
  const start = Date.now();
36
- let requestBody = init.body || null;
37
- let method = init.method || "GET";
40
+ const method = init.method || "GET";
41
+ const requestBody = init.body || null;
38
42
  try {
39
43
  const response = await originalFetch(input, init);
40
44
  const clone = response.clone();
@@ -46,7 +50,7 @@ function monitorFetch() {
46
50
  sendLog({
47
51
  type: "api_call",
48
52
  transport: "fetch",
49
- url: typeof input === "string" ? input : input.url,
53
+ url,
50
54
  method,
51
55
  statusCode: response.status,
52
56
  requestHeaders: init.headers,
@@ -63,7 +67,7 @@ function monitorFetch() {
63
67
  sendLog({
64
68
  type: "api_error",
65
69
  transport: "fetch",
66
- url: input,
70
+ url,
67
71
  method,
68
72
  error: err.message,
69
73
  ...getMetadata()
@@ -90,6 +94,9 @@ function monitorXHR() {
90
94
  };
91
95
  XMLHttpRequest.prototype.send = function(body) {
92
96
  const start = Date.now();
97
+ if (this._url && LOG_ENDPOINT && this._url.includes(LOG_ENDPOINT)) {
98
+ return originalSend.call(this, body);
99
+ }
93
100
  this.addEventListener("loadend", () => {
94
101
  sendLog({
95
102
  type: "api_call",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kush_hemant/react-api-monitor",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Automatic API monitoring SDK for React apps",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -21,6 +21,6 @@
21
21
  "typescript": "^5.9.3"
22
22
  },
23
23
  "scripts": {
24
- "build": "tsup src/index.js --format esm --dts false"
24
+ "build": "tsup src/index.js --format esm"
25
25
  }
26
26
  }