react-native-inapp-inspector 1.0.13 → 1.0.15
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/README.md +203 -44
- package/dist/commonjs/customHooks/analyticsLogger.d.ts +1 -0
- package/dist/commonjs/customHooks/analyticsLogger.js +57 -17
- package/dist/commonjs/customHooks/networkLogger.d.ts +1 -1
- package/dist/commonjs/customHooks/networkLogger.js +66 -54
- package/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.js +1501 -793
- package/dist/esm/customHooks/analyticsLogger.d.ts +1 -0
- package/dist/esm/customHooks/analyticsLogger.js +55 -16
- package/dist/esm/customHooks/networkLogger.d.ts +1 -1
- package/dist/esm/customHooks/networkLogger.js +64 -55
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1501 -794
- package/example/App.tsx +5 -3
- package/package.json +3 -1
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.addAxiosInterceptors = exports.setupNetworkLogger = exports.getNetworkLogs = exports.clearNetworkLogs = exports.subscribeNetworkLogs = void 0;
|
|
4
7
|
require("./webViewLogger");
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
5
9
|
let logs = [];
|
|
6
10
|
let listeners = [];
|
|
7
11
|
let counter = 0;
|
|
8
|
-
const ALLOWED_METHODS = [
|
|
12
|
+
const ALLOWED_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
13
|
+
const IGNORED_URL_PATTERNS = [/\/symbolicate(?:[/?#]|$)/];
|
|
14
|
+
function shouldIgnoreUrl(url) {
|
|
15
|
+
if (!url)
|
|
16
|
+
return false;
|
|
17
|
+
return IGNORED_URL_PATTERNS.some((re) => re.test(url));
|
|
18
|
+
}
|
|
9
19
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
10
20
|
function normaliseHeaders(raw) {
|
|
11
21
|
if (!raw)
|
|
12
22
|
return undefined;
|
|
13
|
-
if (typeof raw.forEach ===
|
|
23
|
+
if (typeof raw.forEach === "function") {
|
|
14
24
|
const result = {};
|
|
15
25
|
raw.forEach((value, key) => {
|
|
16
26
|
result[key] = value;
|
|
@@ -42,11 +52,11 @@ function parseRequestData(data) {
|
|
|
42
52
|
data._parts.forEach((part) => {
|
|
43
53
|
const key = part[0];
|
|
44
54
|
const value = part[1];
|
|
45
|
-
if (value && typeof value ===
|
|
55
|
+
if (value && typeof value === "object" && value.uri) {
|
|
46
56
|
parsedFormData[key] = {
|
|
47
57
|
_isFile: true,
|
|
48
|
-
name: value.name ||
|
|
49
|
-
type: value.type ||
|
|
58
|
+
name: value.name || "unknown",
|
|
59
|
+
type: value.type || "unknown",
|
|
50
60
|
uri: value.uri,
|
|
51
61
|
};
|
|
52
62
|
}
|
|
@@ -63,29 +73,29 @@ function getCallerFromStack() {
|
|
|
63
73
|
try {
|
|
64
74
|
const stack = new Error().stack;
|
|
65
75
|
if (!stack)
|
|
66
|
-
return
|
|
67
|
-
const lines = stack.split(
|
|
76
|
+
return "Unknown";
|
|
77
|
+
const lines = stack.split("\n");
|
|
68
78
|
for (let i = 0; i < lines.length; i++) {
|
|
69
79
|
const line = lines[i];
|
|
70
80
|
// Skip internal react-native network modules and the logger itself
|
|
71
|
-
if (line.includes(
|
|
72
|
-
line.includes(
|
|
73
|
-
line.includes(
|
|
74
|
-
line.includes(
|
|
81
|
+
if (line.includes("networkLogger") ||
|
|
82
|
+
line.includes("node_modules") ||
|
|
83
|
+
line.includes("Error") ||
|
|
84
|
+
line.includes("regeneratorRuntime")) {
|
|
75
85
|
continue;
|
|
76
86
|
}
|
|
77
|
-
return line.trim().replace(/^at /,
|
|
87
|
+
return line.trim().replace(/^at /, "");
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
catch (e) { }
|
|
81
|
-
return
|
|
91
|
+
return "Unknown";
|
|
82
92
|
}
|
|
83
93
|
// ─── Subscribe ────────────────────────────────────────────────────────────────
|
|
84
94
|
const subscribeNetworkLogs = (callback) => {
|
|
85
95
|
listeners.push(callback);
|
|
86
96
|
callback([...logs]);
|
|
87
97
|
return () => {
|
|
88
|
-
listeners = listeners.filter(l => l !== callback);
|
|
98
|
+
listeners = listeners.filter((l) => l !== callback);
|
|
89
99
|
};
|
|
90
100
|
};
|
|
91
101
|
exports.subscribeNetworkLogs = subscribeNetworkLogs;
|
|
@@ -99,13 +109,15 @@ exports.getNetworkLogs = getNetworkLogs;
|
|
|
99
109
|
// ─── Internal ─────────────────────────────────────────────────────────────────
|
|
100
110
|
const notify = () => {
|
|
101
111
|
const snapshot = [...logs];
|
|
102
|
-
listeners.forEach(cb => cb(snapshot));
|
|
112
|
+
listeners.forEach((cb) => cb(snapshot));
|
|
103
113
|
};
|
|
104
114
|
const addOrUpdateLog = (log) => {
|
|
105
115
|
const method = log.method?.toUpperCase();
|
|
106
116
|
if (!ALLOWED_METHODS.includes(method))
|
|
107
117
|
return;
|
|
108
|
-
|
|
118
|
+
if (shouldIgnoreUrl(log.url))
|
|
119
|
+
return;
|
|
120
|
+
const index = logs.findIndex((l) => l.id === log.id);
|
|
109
121
|
if (index >= 0) {
|
|
110
122
|
logs[index] = { ...logs[index], ...log };
|
|
111
123
|
}
|
|
@@ -123,12 +135,14 @@ const setupNetworkLogger = () => {
|
|
|
123
135
|
const originalFetch = globalThis.fetch;
|
|
124
136
|
if (originalFetch) {
|
|
125
137
|
globalThis.fetch = async (url, options = {}) => {
|
|
126
|
-
const method = (options?.method ||
|
|
138
|
+
const method = (options?.method || "GET").toUpperCase();
|
|
127
139
|
if (!ALLOWED_METHODS.includes(method))
|
|
128
140
|
return originalFetch(url, options);
|
|
129
141
|
const id = counter++;
|
|
130
142
|
const start = Date.now();
|
|
131
|
-
const finalUrl = typeof url ===
|
|
143
|
+
const finalUrl = typeof url === "string" ? url : url?.url;
|
|
144
|
+
if (shouldIgnoreUrl(finalUrl))
|
|
145
|
+
return originalFetch(url, options);
|
|
132
146
|
const requestHeaders = normaliseHeaders(options?.headers);
|
|
133
147
|
const caller = getCallerFromStack(); // ✅ Capture call line
|
|
134
148
|
addOrUpdateLog({
|
|
@@ -137,7 +151,7 @@ const setupNetworkLogger = () => {
|
|
|
137
151
|
method,
|
|
138
152
|
startTime: start,
|
|
139
153
|
caller,
|
|
140
|
-
request: method ===
|
|
154
|
+
request: method === "GET" ? undefined : parseRequestData(options?.body),
|
|
141
155
|
requestHeaders,
|
|
142
156
|
});
|
|
143
157
|
try {
|
|
@@ -145,11 +159,11 @@ const setupNetworkLogger = () => {
|
|
|
145
159
|
const duration = Date.now() - start;
|
|
146
160
|
const responseHeaders = normaliseHeaders(response.headers);
|
|
147
161
|
let data = null;
|
|
148
|
-
const contentType = responseHeaders?.[
|
|
149
|
-
responseHeaders?.[
|
|
150
|
-
|
|
151
|
-
if (contentType.includes(
|
|
152
|
-
data =
|
|
162
|
+
const contentType = responseHeaders?.["content-type"] ||
|
|
163
|
+
responseHeaders?.["Content-Type"] ||
|
|
164
|
+
"";
|
|
165
|
+
if (contentType.includes("image/")) {
|
|
166
|
+
data = "[Image Data]";
|
|
153
167
|
}
|
|
154
168
|
else {
|
|
155
169
|
try {
|
|
@@ -192,27 +206,22 @@ const setupNetworkLogger = () => {
|
|
|
192
206
|
}
|
|
193
207
|
};
|
|
194
208
|
}
|
|
195
|
-
//
|
|
209
|
+
// Hook Axios — patches both the default instance and any future axios.create() instances
|
|
196
210
|
try {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const instance = originalCreate.apply(this, args);
|
|
207
|
-
(0, exports.addAxiosInterceptors)(instance);
|
|
208
|
-
return instance;
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
+
if (axios_1.default) {
|
|
212
|
+
(0, exports.addAxiosInterceptors)(axios_1.default);
|
|
213
|
+
const originalCreate = axios_1.default.create;
|
|
214
|
+
if (typeof originalCreate === "function") {
|
|
215
|
+
axios_1.default.create = function (...args) {
|
|
216
|
+
const instance = originalCreate.apply(this, args);
|
|
217
|
+
(0, exports.addAxiosInterceptors)(instance);
|
|
218
|
+
return instance;
|
|
219
|
+
};
|
|
211
220
|
}
|
|
212
221
|
}
|
|
213
222
|
}
|
|
214
|
-
catch (
|
|
215
|
-
//
|
|
223
|
+
catch (_e) {
|
|
224
|
+
// Axios not available — fetch-only mode
|
|
216
225
|
}
|
|
217
226
|
globalThis.__NETWORK_LOGGER_INITIALIZED__ = true;
|
|
218
227
|
};
|
|
@@ -220,25 +229,28 @@ exports.setupNetworkLogger = setupNetworkLogger;
|
|
|
220
229
|
// ─── Axios interceptor helper ─────────────────────────────────────────────────
|
|
221
230
|
const addAxiosInterceptors = (axiosInstance) => {
|
|
222
231
|
axiosInstance.interceptors.request.use(async (config) => {
|
|
223
|
-
const method = (config.method ||
|
|
232
|
+
const method = (config.method || "GET").toUpperCase();
|
|
224
233
|
if (!ALLOWED_METHODS.includes(method))
|
|
225
234
|
return config;
|
|
226
235
|
const id = counter++;
|
|
227
236
|
const start = Date.now();
|
|
228
237
|
const caller = getCallerFromStack(); // ✅ Capture call line
|
|
238
|
+
let url = config.url ?? "";
|
|
239
|
+
if (!url.startsWith("http"))
|
|
240
|
+
url = `${config.baseURL ?? ""}${url}`;
|
|
241
|
+
// ✅ Leave config untagged so the response interceptor skips it too.
|
|
242
|
+
if (shouldIgnoreUrl(url))
|
|
243
|
+
return config;
|
|
229
244
|
config.__logId = id;
|
|
230
245
|
config.__logStart = start;
|
|
231
246
|
config.__logCaller = caller;
|
|
232
|
-
let url = config.url ?? '';
|
|
233
|
-
if (!url.startsWith('http'))
|
|
234
|
-
url = `${config.baseURL ?? ''}${url}`;
|
|
235
247
|
addOrUpdateLog({
|
|
236
248
|
id,
|
|
237
249
|
url,
|
|
238
250
|
method,
|
|
239
251
|
startTime: start,
|
|
240
252
|
caller,
|
|
241
|
-
request: method ===
|
|
253
|
+
request: method === "GET" ? undefined : parseRequestData(config.data),
|
|
242
254
|
requestHeaders: normaliseHeaders(config.headers),
|
|
243
255
|
});
|
|
244
256
|
return config;
|
|
@@ -248,12 +260,12 @@ const addAxiosInterceptors = (axiosInstance) => {
|
|
|
248
260
|
const id = config.__logId;
|
|
249
261
|
const start = config.__logStart;
|
|
250
262
|
const caller = config.__logCaller;
|
|
251
|
-
const method = (config.method ||
|
|
263
|
+
const method = (config.method || "GET").toUpperCase();
|
|
252
264
|
if (id == null || !ALLOWED_METHODS.includes(method))
|
|
253
265
|
return response;
|
|
254
|
-
let url = config.url ??
|
|
255
|
-
if (!url.startsWith(
|
|
256
|
-
url = `${config.baseURL ??
|
|
266
|
+
let url = config.url ?? "";
|
|
267
|
+
if (!url.startsWith("http"))
|
|
268
|
+
url = `${config.baseURL ?? ""}${url}`;
|
|
257
269
|
addOrUpdateLog({
|
|
258
270
|
id,
|
|
259
271
|
url,
|
|
@@ -271,11 +283,11 @@ const addAxiosInterceptors = (axiosInstance) => {
|
|
|
271
283
|
const id = config.__logId;
|
|
272
284
|
const start = config.__logStart;
|
|
273
285
|
const caller = config.__logCaller;
|
|
274
|
-
const method = (config.method ||
|
|
286
|
+
const method = (config.method || "GET").toUpperCase();
|
|
275
287
|
if (id != null && ALLOWED_METHODS.includes(method)) {
|
|
276
|
-
let url = config.url ??
|
|
277
|
-
if (!url.startsWith(
|
|
278
|
-
url = `${config.baseURL ??
|
|
288
|
+
let url = config.url ?? "";
|
|
289
|
+
if (!url.startsWith("http"))
|
|
290
|
+
url = `${config.baseURL ?? ""}${url}`;
|
|
279
291
|
addOrUpdateLog({
|
|
280
292
|
id,
|
|
281
293
|
url,
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
declare const NetworkInspectorWrapper: (props: any) => React.JSX.Element;
|
|
3
3
|
export default NetworkInspectorWrapper;
|
|
4
|
-
export { setupNetworkLogger, clearNetworkLogs, subscribeNetworkLogs, } from './customHooks/networkLogger';
|
|
4
|
+
export { setupNetworkLogger, clearNetworkLogs, subscribeNetworkLogs, addAxiosInterceptors, } from './customHooks/networkLogger';
|
|
5
5
|
export { setupConsoleLogger, clearConsoleLogs, subscribeConsoleLogs, } from './customHooks/consoleLogger';
|
|
6
6
|
export { setupAnalyticsLogger, logAnalyticsEvent, subscribeAnalyticsEvents, clearAnalyticsEvents, } from './customHooks/analyticsLogger';
|
|
7
7
|
export { WebView, getWebViewLogs, getWebViewNavHistory, getWebViewHtml, getWebViewCss, getWebViewJs, getWebViewHtmlUrl, clearWebViewData, subscribeWebView, } from './customHooks/webViewLogger';
|