@kush_hemant/react-api-monitor 1.0.18 → 1.0.19
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 +28 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -169,44 +169,46 @@ function monitorXHR() {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
// src/network/monitorAxios.js
|
|
172
|
-
function monitorAxios() {
|
|
173
|
-
if (!
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
);
|
|
180
|
-
window.axios.interceptors.response.use(
|
|
172
|
+
function monitorAxios(axiosInstance) {
|
|
173
|
+
if (!(axiosInstance == null ? void 0 : axiosInstance.interceptors)) return;
|
|
174
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
175
|
+
config.__monitorStart = Date.now();
|
|
176
|
+
return config;
|
|
177
|
+
});
|
|
178
|
+
axiosInstance.interceptors.response.use(
|
|
181
179
|
(response) => {
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
var _a, _b, _c, _d, _e;
|
|
181
|
+
const url = ((_a = response.config) == null ? void 0 : _a.url) || "";
|
|
182
|
+
if (LOG_ENDPOINT && url.includes(LOG_ENDPOINT)) {
|
|
184
183
|
return response;
|
|
185
184
|
}
|
|
186
185
|
sendLog({
|
|
187
186
|
type: "api_call",
|
|
188
187
|
transport: "axios",
|
|
189
188
|
url,
|
|
190
|
-
method: response.config.method,
|
|
189
|
+
method: (_c = (_b = response.config) == null ? void 0 : _b.method) == null ? void 0 : _c.toUpperCase(),
|
|
191
190
|
statusCode: response.status,
|
|
192
|
-
requestHeaders: response.config.headers,
|
|
193
|
-
requestBody: response.config.data,
|
|
191
|
+
requestHeaders: (_d = response.config) == null ? void 0 : _d.headers,
|
|
192
|
+
requestBody: (_e = response.config) == null ? void 0 : _e.data,
|
|
194
193
|
responseHeaders: response.headers,
|
|
195
|
-
responseBody: response.data,
|
|
196
|
-
duration: Date.now() - response.config.
|
|
194
|
+
responseBody: typeof response.data === "string" ? response.data : JSON.stringify(response.data),
|
|
195
|
+
duration: Date.now() - (response.config.__monitorStart || Date.now()),
|
|
197
196
|
...getMetadata()
|
|
198
197
|
});
|
|
199
198
|
return response;
|
|
200
199
|
},
|
|
201
200
|
(error) => {
|
|
201
|
+
var _a, _b;
|
|
202
202
|
const config = error.config || {};
|
|
203
|
+
const url = (config == null ? void 0 : config.url) || "";
|
|
203
204
|
sendLog({
|
|
204
205
|
type: "api_error",
|
|
205
206
|
transport: "axios",
|
|
206
|
-
url
|
|
207
|
-
method: config.method,
|
|
207
|
+
url,
|
|
208
|
+
method: (_a = config == null ? void 0 : config.method) == null ? void 0 : _a.toUpperCase(),
|
|
209
|
+
statusCode: ((_b = error.response) == null ? void 0 : _b.status) || 0,
|
|
210
|
+
duration: Date.now() - (config.__monitorStart || Date.now()),
|
|
208
211
|
error: error.message,
|
|
209
|
-
duration: Date.now() - (config.__startTime || 0),
|
|
210
212
|
...getMetadata()
|
|
211
213
|
});
|
|
212
214
|
return Promise.reject(error);
|
|
@@ -237,17 +239,21 @@ function monitorResources() {
|
|
|
237
239
|
}
|
|
238
240
|
|
|
239
241
|
// src/network/auto.js
|
|
240
|
-
function startNetworkMonitoring() {
|
|
242
|
+
function startNetworkMonitoring(options = {}) {
|
|
241
243
|
monitorFetch();
|
|
242
244
|
monitorXHR();
|
|
243
|
-
|
|
245
|
+
if (options.axios) {
|
|
246
|
+
monitorAxios(options.axios);
|
|
247
|
+
}
|
|
244
248
|
monitorResources();
|
|
245
249
|
}
|
|
246
250
|
|
|
247
251
|
// src/index.js
|
|
248
252
|
function initMonitoring(options) {
|
|
249
253
|
configureSender(options.endpoint);
|
|
250
|
-
startNetworkMonitoring(
|
|
254
|
+
startNetworkMonitoring({
|
|
255
|
+
axios: options.axios
|
|
256
|
+
});
|
|
251
257
|
}
|
|
252
258
|
export {
|
|
253
259
|
initMonitoring
|