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