react-native-in-app-debugger 2.0.7 → 2.0.9
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/index.jsx +22 -6
- package/Api/useApiInterceptor.js +18 -4
- package/Mock/MockDetails.jsx +81 -44
- package/package.json +1 -1
package/Api/index.jsx
CHANGED
|
@@ -285,16 +285,32 @@ export default (props) => {
|
|
|
285
285
|
<BlacklistIcon />
|
|
286
286
|
</TouchableOpacity>
|
|
287
287
|
)}
|
|
288
|
+
{isExpand && item.interface === "axios" && !!item.mockid && (
|
|
289
|
+
<TouchableOpacity
|
|
290
|
+
onPress={() => props.goToMock({ ...item, id: item.mockid })}
|
|
291
|
+
style={styles.actionButton}
|
|
292
|
+
>
|
|
293
|
+
<Text style={{ color: "black", fontSize: 10 }}>
|
|
294
|
+
Edit Mock
|
|
295
|
+
</Text>
|
|
296
|
+
</TouchableOpacity>
|
|
297
|
+
)}
|
|
288
298
|
{isExpand && item.interface === "axios" && (
|
|
289
299
|
<TouchableOpacity
|
|
290
|
-
onPress={() =>
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
300
|
+
onPress={() => props.goToMock(item)}
|
|
301
|
+
style={styles.actionButton}
|
|
302
|
+
>
|
|
303
|
+
<Text style={{ color: "black", fontSize: 10 }}>
|
|
304
|
+
{item.mockid ? "New " : ""}Mock
|
|
305
|
+
</Text>
|
|
306
|
+
</TouchableOpacity>
|
|
307
|
+
)}
|
|
308
|
+
{isExpand && (
|
|
309
|
+
<TouchableOpacity
|
|
310
|
+
onPress={() => props.deleteApi(item.id)}
|
|
295
311
|
style={styles.actionButton}
|
|
296
312
|
>
|
|
297
|
-
<Text style={{ color: "black", fontSize: 10 }}>
|
|
313
|
+
<Text style={{ color: "black", fontSize: 10 }}>Delete</Text>
|
|
298
314
|
</TouchableOpacity>
|
|
299
315
|
)}
|
|
300
316
|
</View>
|
package/Api/useApiInterceptor.js
CHANGED
|
@@ -50,11 +50,16 @@ export default ({ maxNumOfApiToStore, blacklists, blacklistRef, mocks }) => {
|
|
|
50
50
|
datetime: new Date().toLocaleString(),
|
|
51
51
|
time: `${hour}:${minute}:${second}`,
|
|
52
52
|
mockid: undefined,
|
|
53
|
-
interface: undefined
|
|
53
|
+
interface: undefined,
|
|
54
54
|
};
|
|
55
55
|
setApis((v) => {
|
|
56
56
|
const newData = [
|
|
57
|
-
{
|
|
57
|
+
{
|
|
58
|
+
request,
|
|
59
|
+
id: Date.now().toString(36) + Math.random().toString(36),
|
|
60
|
+
mockid: data.mockid,
|
|
61
|
+
interface: data.interface,
|
|
62
|
+
},
|
|
58
63
|
...(maxNumOfApiToStore ? v.slice(0, maxNumOfApiToStore - 1) : v),
|
|
59
64
|
];
|
|
60
65
|
return newData;
|
|
@@ -194,7 +199,7 @@ export default ({ maxNumOfApiToStore, blacklists, blacklistRef, mocks }) => {
|
|
|
194
199
|
if (!shouldExclude(url, method)) {
|
|
195
200
|
const data = config.data ? parse(config.data) : undefined;
|
|
196
201
|
|
|
197
|
-
|
|
202
|
+
const mock = mocked(url, method);
|
|
198
203
|
|
|
199
204
|
makeRequest({
|
|
200
205
|
url,
|
|
@@ -255,5 +260,14 @@ export default ({ maxNumOfApiToStore, blacklists, blacklistRef, mocks }) => {
|
|
|
255
260
|
);
|
|
256
261
|
}, [mocks]);
|
|
257
262
|
|
|
258
|
-
|
|
263
|
+
const deleteApi = (id) => {
|
|
264
|
+
setApis((v) => v.filter((a) => a.id !== id));
|
|
265
|
+
setBookmarks((v) => {
|
|
266
|
+
const newV = { ...v };
|
|
267
|
+
delete newV[id];
|
|
268
|
+
return newV;
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return { apis, deleteApi, clear: () => setApis([]), bookmarks, setBookmarks };
|
|
259
273
|
};
|
package/Mock/MockDetails.jsx
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import { useEffect, useState } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
Alert,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
TextInput,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
View,
|
|
8
|
+
} from "react-native";
|
|
9
|
+
import Text from "../Text";
|
|
10
|
+
import X from "../X";
|
|
5
11
|
|
|
6
|
-
const removeId = (key, value) => (key ===
|
|
12
|
+
const removeId = (key, value) => (key === "id" ? undefined : value);
|
|
7
13
|
export default (p) => {
|
|
8
|
-
const [tab, setTab] = useState(
|
|
9
|
-
const [tmpResBody, setTmpResBody] = useState(
|
|
10
|
-
const [tmpResStatus, setTmpResStatus] = useState(
|
|
14
|
+
const [tab, setTab] = useState("response");
|
|
15
|
+
const [tmpResBody, setTmpResBody] = useState("");
|
|
16
|
+
const [tmpResStatus, setTmpResStatus] = useState("");
|
|
11
17
|
const [tmpMockDetails, setTmpMockDetails] = useState({});
|
|
12
18
|
|
|
13
19
|
const save = (cb) => {
|
|
14
|
-
if (tab ===
|
|
20
|
+
if (tab === "response") {
|
|
15
21
|
try {
|
|
16
22
|
if (!tmpResStatus) {
|
|
17
|
-
return Alert.alert(
|
|
23
|
+
return Alert.alert("Sorry", "Status code is required");
|
|
18
24
|
}
|
|
19
25
|
const tmp = JSON.parse(tmpMockDetails);
|
|
20
26
|
tmp.response.data = JSON.parse(tmpResBody);
|
|
@@ -46,25 +52,25 @@ export default (p) => {
|
|
|
46
52
|
// })
|
|
47
53
|
cb?.();
|
|
48
54
|
} catch (e) {
|
|
49
|
-
return Alert.alert(
|
|
55
|
+
return Alert.alert("Sorry", "Please fix the response body JSON");
|
|
50
56
|
}
|
|
51
|
-
} else if (tab ===
|
|
57
|
+
} else if (tab === "json") {
|
|
52
58
|
cb?.();
|
|
53
|
-
} else if (tab ===
|
|
59
|
+
} else if (tab === "request") {
|
|
54
60
|
cb?.();
|
|
55
61
|
}
|
|
56
62
|
};
|
|
57
|
-
const hasResponse = !!p.mockDetails?.response
|
|
63
|
+
const hasResponse = !!p.mockDetails?.response;
|
|
58
64
|
|
|
59
65
|
const reset = () => {
|
|
60
66
|
if (!p.mockDetails) return;
|
|
61
67
|
setTmpMockDetails(JSON.stringify(p.mockDetails, removeId, 4));
|
|
62
68
|
if (hasResponse) {
|
|
63
69
|
setTmpResBody(JSON.stringify(p.mockDetails.response.data, removeId, 4));
|
|
64
|
-
setTmpResStatus(p.mockDetails.response.status +
|
|
70
|
+
setTmpResStatus(p.mockDetails.response.status + "" || "");
|
|
65
71
|
} else {
|
|
66
|
-
setTmpResBody(
|
|
67
|
-
setTmpResStatus(
|
|
72
|
+
setTmpResBody("");
|
|
73
|
+
setTmpResStatus("");
|
|
68
74
|
}
|
|
69
75
|
};
|
|
70
76
|
useEffect(reset, [p.mockDetails]);
|
|
@@ -91,9 +97,11 @@ export default (p) => {
|
|
|
91
97
|
// }, [p.mockDetails, tmpMockDetails]);
|
|
92
98
|
if (!p.mockDetails) return null;
|
|
93
99
|
// const canReset = JSON.stringify(p.mockDetails, removeId)?.replace(/\s+/g, '') !== tmpMockDetails?.replace?.(/\s+/g, '');
|
|
94
|
-
const canReset =
|
|
100
|
+
const canReset =
|
|
101
|
+
!hasResponse ||
|
|
95
102
|
tmpResStatus != p.mockDetails.response.status ||
|
|
96
|
-
JSON.stringify(p.mockDetails.response.data)?.replace(/\s+/g,
|
|
103
|
+
JSON.stringify(p.mockDetails.response.data)?.replace(/\s+/g, "") !==
|
|
104
|
+
tmpResBody?.replace?.(/\s+/g, "");
|
|
97
105
|
const isnew = !p.mocks.some((m) => m.id === p.mockDetails.id);
|
|
98
106
|
|
|
99
107
|
// console.log('xxxxx response', JSON.stringify(p.mockDetails.response.data)?.replace(/\s+/g, ''));
|
|
@@ -106,17 +114,19 @@ export default (p) => {
|
|
|
106
114
|
bottom: 0,
|
|
107
115
|
left: 0,
|
|
108
116
|
right: 0,
|
|
109
|
-
position:
|
|
117
|
+
position: "absolute",
|
|
110
118
|
zIndex: 1000,
|
|
111
|
-
backgroundColor:
|
|
112
|
-
width:
|
|
113
|
-
height:
|
|
119
|
+
backgroundColor: "grey",
|
|
120
|
+
width: "100%",
|
|
121
|
+
height: "100%",
|
|
114
122
|
paddingTop: 50,
|
|
115
123
|
}}
|
|
116
124
|
>
|
|
117
125
|
{!isnew && <Text style={{ opacity: 0.3 }}>{p.mockDetails.id}</Text>}
|
|
118
|
-
<View style={{ flexDirection:
|
|
119
|
-
<Text
|
|
126
|
+
<View style={{ flexDirection: "row" }}>
|
|
127
|
+
<Text
|
|
128
|
+
style={{ flex: 1 }}
|
|
129
|
+
>{`(${p.mockDetails.request.method}) ${p.mockDetails.request.url}`}</Text>
|
|
120
130
|
<TouchableOpacity onPress={() => p.setMockDetails(null)}>
|
|
121
131
|
<X size={25} />
|
|
122
132
|
</TouchableOpacity>
|
|
@@ -124,34 +134,46 @@ export default (p) => {
|
|
|
124
134
|
<View
|
|
125
135
|
style={{
|
|
126
136
|
marginVertical: 10,
|
|
127
|
-
flexDirection:
|
|
128
|
-
justifyContent:
|
|
129
|
-
backgroundColor:
|
|
137
|
+
flexDirection: "row",
|
|
138
|
+
justifyContent: "space-around",
|
|
139
|
+
backgroundColor: "black",
|
|
130
140
|
borderRadius: 5,
|
|
131
141
|
padding: 5,
|
|
132
142
|
}}
|
|
133
143
|
>
|
|
134
|
-
{[
|
|
144
|
+
{["request", "response", "json"].map((item) => {
|
|
135
145
|
const isSelected = item === tab;
|
|
136
146
|
return (
|
|
137
147
|
<TouchableOpacity
|
|
138
|
-
style={{
|
|
148
|
+
style={{
|
|
149
|
+
backgroundColor: isSelected ? "white" : "black",
|
|
150
|
+
padding: 3,
|
|
151
|
+
borderRadius: 5,
|
|
152
|
+
}}
|
|
139
153
|
onPress={() => {
|
|
140
|
-
save(() => setTab(item));
|
|
154
|
+
// save(() => setTab(item));
|
|
155
|
+
setTab(item);
|
|
141
156
|
}}
|
|
142
157
|
>
|
|
143
|
-
<Text
|
|
158
|
+
<Text
|
|
159
|
+
style={{
|
|
160
|
+
textTransform: "uppercase",
|
|
161
|
+
color: isSelected ? "black" : "white",
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{item}
|
|
165
|
+
</Text>
|
|
144
166
|
</TouchableOpacity>
|
|
145
167
|
);
|
|
146
168
|
})}
|
|
147
169
|
</View>
|
|
148
|
-
{tab ===
|
|
170
|
+
{tab === "response" && (
|
|
149
171
|
<View style={{ gap: 3 }}>
|
|
150
|
-
<View style={{ flexDirection:
|
|
172
|
+
<View style={{ flexDirection: "row", gap: 5 }}>
|
|
151
173
|
<Text>Status</Text>
|
|
152
174
|
<TextInput
|
|
153
|
-
style={{ backgroundColor:
|
|
154
|
-
inputMode=
|
|
175
|
+
style={{ backgroundColor: "#ccc", width: 50, padding: 2 }}
|
|
176
|
+
inputMode="numeric"
|
|
155
177
|
onChangeText={(t) => {
|
|
156
178
|
setTmpResStatus(t);
|
|
157
179
|
// try {
|
|
@@ -166,10 +188,15 @@ export default (p) => {
|
|
|
166
188
|
/>
|
|
167
189
|
</View>
|
|
168
190
|
|
|
169
|
-
<View style={{ flexDirection:
|
|
191
|
+
<View style={{ flexDirection: "row", gap: 5 }}>
|
|
170
192
|
<Text>Body</Text>
|
|
171
193
|
<TextInput
|
|
172
|
-
style={{
|
|
194
|
+
style={{
|
|
195
|
+
backgroundColor: "#ccc",
|
|
196
|
+
height: 250,
|
|
197
|
+
flex: 1,
|
|
198
|
+
padding: 2,
|
|
199
|
+
}}
|
|
173
200
|
multiline
|
|
174
201
|
onChangeText={setTmpResBody}
|
|
175
202
|
value={tmpResBody}
|
|
@@ -177,12 +204,22 @@ export default (p) => {
|
|
|
177
204
|
</View>
|
|
178
205
|
</View>
|
|
179
206
|
)}
|
|
180
|
-
{tab !==
|
|
207
|
+
{tab !== "response" && (
|
|
208
|
+
<Text style={{ marginTop: 30, textAlign: "center" }}>
|
|
209
|
+
To be developed later
|
|
210
|
+
</Text>
|
|
211
|
+
)}
|
|
181
212
|
{/* {tab === 'json' && (
|
|
182
213
|
<TextInput onChangeText={setTmpMockDetails} value={tmpMockDetails} style={{ height: '40%' }} multiline />
|
|
183
214
|
)} */}
|
|
184
|
-
{tab ===
|
|
185
|
-
<View
|
|
215
|
+
{tab === "response" && (
|
|
216
|
+
<View
|
|
217
|
+
style={{
|
|
218
|
+
flexDirection: "row",
|
|
219
|
+
justifyContent: "space-between",
|
|
220
|
+
padding: 10,
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
186
223
|
{!isnew && (
|
|
187
224
|
<TouchableOpacity
|
|
188
225
|
style={styles.actionButton}
|
|
@@ -233,10 +270,10 @@ export default (p) => {
|
|
|
233
270
|
|
|
234
271
|
const styles = StyleSheet.create({
|
|
235
272
|
actionButton: {
|
|
236
|
-
backgroundColor:
|
|
273
|
+
backgroundColor: "white",
|
|
237
274
|
borderRadius: 5,
|
|
238
275
|
padding: 4,
|
|
239
|
-
alignItems:
|
|
240
|
-
justifyContent:
|
|
276
|
+
alignItems: "center",
|
|
277
|
+
justifyContent: "center",
|
|
241
278
|
},
|
|
242
279
|
});
|
package/package.json
CHANGED