@kush_hemant/react-api-monitor 1.0.33 → 1.0.35

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 +15 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,19 +1,21 @@
1
1
  // src/core/sender.js
2
2
  var LOG_ENDPOINT = "";
3
- function configureSender(url) {
3
+ var API_KEY = "";
4
+ function configureSender(url, apiKey) {
4
5
  LOG_ENDPOINT = url;
6
+ API_KEY = apiKey;
5
7
  }
6
8
  function sendLog(data) {
7
- var _a;
8
9
  if (!LOG_ENDPOINT) return;
9
- ((_a = navigator.sendBeacon) == null ? void 0 : _a.call(
10
- navigator,
11
- LOG_ENDPOINT,
12
- JSON.stringify(data)
13
- )) || fetch(LOG_ENDPOINT, {
10
+ const payload = JSON.stringify(data);
11
+ fetch(LOG_ENDPOINT, {
14
12
  method: "POST",
15
- headers: { "Content-Type": "application/json" },
16
- body: JSON.stringify(data),
13
+ headers: {
14
+ "Content-Type": "application/json",
15
+ /* 🔥 REQUIRED FOR SAAS */
16
+ "x-api-key": API_KEY
17
+ },
18
+ body: payload,
17
19
  keepalive: true
18
20
  }).catch(() => {
19
21
  });
@@ -168,7 +170,10 @@ function startNetworkMonitoring() {
168
170
 
169
171
  // src/index.js
170
172
  function initMonitoring(options) {
171
- configureSender(options.endpoint);
173
+ configureSender({
174
+ endpoint: options.endpoint,
175
+ apiKey: options.apiKey
176
+ });
172
177
  startNetworkMonitoring();
173
178
  }
174
179
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kush_hemant/react-api-monitor",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "Automatic API monitoring SDK for React apps",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",