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 CHANGED
@@ -68,7 +68,7 @@ export default ({ item, filter, wrap, setWrap }) => {
68
68
  </Text>
69
69
  </TouchableOpacity>
70
70
  </View>
71
- <Comp horizontal>
71
+ <Comp horizontal style={{flex:1}}>
72
72
  {tab === tabs[0].value && hasResponse && (
73
73
  <Text style={{ color: "white" }}>
74
74
  <Highlight
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-in-app-debugger",
3
- "version": "1.0.83",
3
+ "version": "1.0.84",
4
4
  "description": "This library's main usage is to be used by Non-Technical testers during UAT, SIT or any testing phase.",
5
5
  "main": "index.jsx",
6
6
  "scripts": {
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
- 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
- }
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
+ // }
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useState } from 'react';
2
- import XHRInterceptor from 'react-native/src/private/inspector/XHRInterceptor.js';
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
- XHRInterceptor.enableInterception();
85
- // console.log('API interceptor status', XHRInterceptor.isInterceptorEnabled());
86
- XHRInterceptor.setSendCallback((...obj) => {
87
- obj[1].responseType = 'text';
88
- const data = parse(obj[0]);
89
-
90
- const { _method: method, _url: url, _headers: headers } = obj[1];
91
- if (filterNonBusinessRelatedAPI) {
92
- if (shouldExclude(url, method)) return;
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
- makeRequest({
96
- url,
97
- headers,
98
- method,
99
- data,
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
- XHRInterceptor.setResponseCallback((...obj) => {
104
- interceptResponse?.(...obj);
105
- const { _method: method, _url: url, _response, status } = obj[5];
106
- if (filterNonBusinessRelatedAPI) {
107
- if (shouldExclude(url, method)) return;
108
- }
109
- const data = parse(_response);
110
-
111
- receiveResponse({
112
- config: {
113
- url,
114
- method,
115
- },
116
- data,
117
- status,
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 };