react-native-in-app-debugger 1.0.83 → 1.0.84
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/Api/Row.jsx +1 -1
- package/package.json +1 -1
- package/postinstall.js +11 -11
- package/useApiInterceptor.js +100 -35
package/Api/Row.jsx
CHANGED
package/package.json
CHANGED
package/postinstall.js
CHANGED
|
@@ -10,15 +10,15 @@ for (const d in read('../../package.json').dependencies) {
|
|
|
10
10
|
fs.writeSync(parentDependencies, '}');
|
|
11
11
|
fs.closeSync(parentDependencies);
|
|
12
12
|
|
|
13
|
-
const isRNVersionGTE0780 = (v) => v.split('.').map(Number)[1] < 78;
|
|
13
|
+
// const isRNVersionGTE0780 = (v) => v.split('.').map(Number)[1] < 78;
|
|
14
14
|
|
|
15
|
-
if (isRNVersionGTE0780(read('../react-native/package.json').version)) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
15
|
+
// if (isRNVersionGTE0780(read('../react-native/package.json').version)) {
|
|
16
|
+
// try {
|
|
17
|
+
// const filePath = './useApiInterceptor.js';
|
|
18
|
+
// const regex = new RegExp('react-native/src/private/inspector/XHRInterceptor.js', 'g');
|
|
19
|
+
// const fileContent = fs.readFileSync(filePath, 'utf8').replace(regex, 'react-native/Libraries/Network/XHRInterceptor.js');
|
|
20
|
+
// fs.writeFileSync(filePath, fileContent, 'utf8');
|
|
21
|
+
// } catch (err) {
|
|
22
|
+
// console.error('Error while replacing strings in file:', err);
|
|
23
|
+
// }
|
|
24
|
+
// }
|
package/useApiInterceptor.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import XHRInterceptor from 'react-native/
|
|
3
|
-
|
|
2
|
+
// import XHRInterceptor from 'react-native/Libraries/Network/XHRInterceptor.js';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
const overrideResponse = false; // Set to true to override the response with a random value
|
|
4
5
|
const filterNonBusinessRelatedAPI = true;
|
|
5
6
|
|
|
6
7
|
const shouldExclude = (url, method) =>
|
|
@@ -81,42 +82,106 @@ export default (maxNumOfApiToStore, blacklists, interceptResponse, blacklistRef)
|
|
|
81
82
|
};
|
|
82
83
|
|
|
83
84
|
useEffect(() => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
const originalFetch = global.fetch;
|
|
86
|
+
global.fetch = async function (...args) {
|
|
87
|
+
console.log('[Fetch Request]', args);
|
|
88
|
+
const [url, { headers, method, body }] = args;
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
if (!shouldExclude(url, method)) {
|
|
92
|
+
const data = body ? parse(body): undefined;
|
|
93
|
+
makeRequest({
|
|
94
|
+
url,
|
|
95
|
+
headers,
|
|
96
|
+
method,
|
|
97
|
+
data,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const response = await originalFetch(...args);
|
|
101
|
+
|
|
102
|
+
receiveResponse({
|
|
103
|
+
config: response,
|
|
104
|
+
status: response.status,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// console.log('[Fetch Response]', args);
|
|
108
|
+
|
|
109
|
+
// if (overrideResponse) {
|
|
110
|
+
// // Mock a random response value
|
|
111
|
+
// const randomValue = { message: 'Random overridden fetch response' };
|
|
112
|
+
|
|
113
|
+
// // Create a new Response object with JSON stringified randomValue
|
|
114
|
+
// return new Response(JSON.stringify(randomValue), {
|
|
115
|
+
// status: 200,
|
|
116
|
+
// headers: { 'Content-Type': 'application/json' },
|
|
117
|
+
// });
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
return response;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
// console.log(error);
|
|
123
|
+
// console.error('[Fetch Error]', error);
|
|
124
|
+
throw error;
|
|
93
125
|
}
|
|
126
|
+
};
|
|
94
127
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
128
|
+
// --- Intercept Axios globally ---
|
|
129
|
+
axios.interceptors.request.use(
|
|
130
|
+
(config) => {
|
|
131
|
+
// console.log('[Axios Request]', config);
|
|
132
|
+
|
|
133
|
+
const { method, url, headers } = config;
|
|
134
|
+
if (!shouldExclude(url, method)) {
|
|
135
|
+
const data = config.data ? parse(config.data) : undefined;
|
|
136
|
+
makeRequest({
|
|
137
|
+
url,
|
|
138
|
+
headers,
|
|
139
|
+
method,
|
|
140
|
+
data,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
102
143
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
144
|
+
return config;
|
|
145
|
+
},
|
|
146
|
+
(error) => {
|
|
147
|
+
// alert(JSON.stringify(error));
|
|
148
|
+
console.error('[Axios Request Error]', error);
|
|
149
|
+
// receiveResponse({
|
|
150
|
+
// config: error.config,
|
|
151
|
+
// status: error.response?.status,
|
|
152
|
+
// });
|
|
153
|
+
receiveResponse({
|
|
154
|
+
config: error.config,
|
|
155
|
+
status: error.response?.status,
|
|
156
|
+
});
|
|
157
|
+
return Promise.reject(error);
|
|
158
|
+
},
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
axios.interceptors.response.use(
|
|
162
|
+
(response) => {
|
|
163
|
+
// console.log('[Axios Response]', response);
|
|
164
|
+
|
|
165
|
+
// if (overrideResponse) {
|
|
166
|
+
// // Replace response.data with random value
|
|
167
|
+
// response.data = { message: 'Random overridden Axios response' };
|
|
168
|
+
// }
|
|
169
|
+
receiveResponse({
|
|
170
|
+
config: response.config,
|
|
171
|
+
data: response.data,
|
|
172
|
+
status: response.status,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return response;
|
|
176
|
+
},
|
|
177
|
+
(error) => {
|
|
178
|
+
receiveResponse({
|
|
179
|
+
config: error.config,
|
|
180
|
+
status: error.response?.status,
|
|
181
|
+
});
|
|
182
|
+
return Promise.reject(error);
|
|
183
|
+
},
|
|
184
|
+
);
|
|
120
185
|
}, []);
|
|
121
186
|
|
|
122
187
|
return { apis, clear: () => setApis([]), bookmarks, setBookmarks };
|