react-native-in-app-debugger 1.0.6 → 1.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.jsx CHANGED
@@ -13,15 +13,21 @@ let Clipboard;
13
13
  try {
14
14
  Clipboard = require("@react-native-clipboard/clipboard")?.default;
15
15
  } catch (error) {
16
- console.error("Error importing Clipboard:", error);
16
+ // console.error("Error importing Clipboard:", error);
17
17
  }
18
18
 
19
19
  const MAX_URL_LENGTH = 100;
20
20
 
21
21
  const Row = ({ item }) => {
22
- const [tab, setTab] = useState("response-body");
22
+ const tabs = [
23
+ { value: "Response Body" },
24
+ { value: "Request Body", hide: !item.request.data },
25
+ { value: "Request Body" },
26
+ ];
27
+ const [tab, setTab] = useState(tabs[0].value);
23
28
  const hasResponse = item.response;
24
- const Tab = ({ value, label }) => {
29
+ const Tab = ({ value, hide }) => {
30
+ if (hide) return null;
25
31
  const isSelected = value === tab;
26
32
  return (
27
33
  <TouchableOpacity
@@ -33,13 +39,17 @@ const Row = ({ item }) => {
33
39
  ]}
34
40
  >
35
41
  <Text
36
- style={{ color: isSelected ? "#000" : "#fff", textAlign: "center" }}
42
+ style={{
43
+ color: isSelected ? "#000" : "#ffffff88",
44
+ textAlign: "center",
45
+ }}
37
46
  >
38
- {label}
47
+ {value}
39
48
  </Text>
40
49
  </TouchableOpacity>
41
50
  );
42
51
  };
52
+
43
53
  return (
44
54
  <View style={styles.details}>
45
55
  {item.request.url.length > MAX_URL_LENGTH && (
@@ -49,24 +59,22 @@ const Row = ({ item }) => {
49
59
  )}
50
60
  <View>
51
61
  <View style={{ flexDirection: "row" }}>
52
- <Tab value="response-body" label="Response Body" />
53
- {!!item.request.data && (
54
- <Tab value="request-body" label="Request Body" />
55
- )}
56
- <Tab value="request-header" label="Request Header" />
62
+ {tabs.map((t) => (
63
+ <Tab key={t.value} {...t} />
64
+ ))}
57
65
  </View>
58
66
 
59
- {tab === "response-body" && hasResponse && (
67
+ {tab === tabs[0].value && hasResponse && (
60
68
  <Text style={{ color: "white" }}>
61
69
  {JSON.stringify(item.response.data, undefined, 4)}
62
70
  </Text>
63
71
  )}
64
- {tab === "request-body" && (
72
+ {tab === tabs[1].value && (
65
73
  <Text style={{ color: "white" }}>
66
74
  {JSON.stringify(item.request.data, undefined, 4)}
67
75
  </Text>
68
76
  )}
69
- {tab === "request-header" && (
77
+ {tab === tabs[2].value && (
70
78
  <Text style={{ color: "white" }}>
71
79
  {JSON.stringify(item.request.headers, undefined, 4)}
72
80
  </Text>
@@ -148,6 +156,13 @@ export default (props) => {
148
156
  </TouchableOpacity>
149
157
  )}
150
158
  </View>
159
+ {!filter &&
160
+ !!props.maxNumOfApiToStore &&
161
+ apis.length === props.maxNumOfApiToStore && (
162
+ <Text style={{ color: "#ffffff88", padding: 10 }}>
163
+ Capped to only latest {props.maxNumOfApiToStore} APIs
164
+ </Text>
165
+ )}
151
166
  <SectionList
152
167
  contentContainerStyle={{ padding: 5 }}
153
168
  keyExtractor={(i) => i.id}
@@ -166,19 +181,19 @@ export default (props) => {
166
181
  const item = data[0];
167
182
  const hasResponse = !!item.response;
168
183
 
169
- let duration = 0;
170
- if (item.response?.datetime) {
171
- let [hr, min, sec] = item.request.datetime.split(" ")[0].split(":");
172
- const start = new Date();
173
- start.setHours(hr);
174
- start.setMinutes(min);
175
- start.setSeconds(sec);
176
- [hr, min, sec] = item.response.datetime.split(" ")[0].split(":");
177
- const end = new Date();
178
- end.setHours(hr);
179
- end.setMinutes(min);
180
- end.setSeconds(sec);
181
- duration = (end.getTime() - start.getTime()) / 1000;
184
+ const duration = item.response?.timestamp
185
+ ? ~~(item.response?.timestamp - item.request.timestamp) / 1000
186
+ : 0;
187
+ const date = new Date(item.request.datetime);
188
+ let hour = date.getHours();
189
+ const minute = date.getMinutes();
190
+
191
+ const amPm = hour >= 12 ? "PM" : "AM";
192
+
193
+ if (hour > 12) {
194
+ hour -= 12;
195
+ } else if (hour === 0) {
196
+ hour = 12;
182
197
  }
183
198
  const isExpand = expands[item.id];
184
199
  return (
@@ -199,7 +214,7 @@ export default (props) => {
199
214
  {item.request.method +
200
215
  ` (${item.response?.status ?? "no response"})` +
201
216
  " - " +
202
- item.request.datetime +
217
+ item.request.time +
203
218
  (hasResponse ? " - " + duration + " second(s)" : "") +
204
219
  "\n"}
205
220
  </Text>
package/Variables.jsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { useState } from 'react';
2
2
  import { Text, FlatList, TextInput } from 'react-native';
3
3
 
4
- export default ({ envs }) => {
4
+ export default ({ variables }) => {
5
5
  const [filter, setFilter] = useState('');
6
6
 
7
7
  return (
@@ -15,13 +15,13 @@ export default ({ envs }) => {
15
15
  />
16
16
  <FlatList
17
17
  contentContainerStyle={{ padding: 5, paddingBottom: 20 }}
18
- data={Object.keys(envs).filter(
19
- (k) => !filter || envs[k].toLowerCase().includes(filter) || k.toLowerCase().includes(filter),
18
+ data={Object.keys(variables).filter(
19
+ (k) => !filter || variables[k].toLowerCase().includes(filter) || k.toLowerCase().includes(filter),
20
20
  )}
21
21
  keyExtractor={(i) => i}
22
22
  renderItem={({ item }) => (
23
23
  <Text selectable style={{ color: 'white', marginVertical: 10 }}>
24
- {item + ' : ' + envs[item]}
24
+ {item + ' : ' + variables[item]}
25
25
  </Text>
26
26
  )}
27
27
  />
package/index.jsx CHANGED
@@ -19,7 +19,7 @@ let DeviceInfo;
19
19
  try {
20
20
  DeviceInfo = require("react-native-device-info");
21
21
  } catch (error) {
22
- console.error("Error importing DeviceInfo:", error);
22
+ // console.error("Error importing DeviceInfo:", error);
23
23
  }
24
24
 
25
25
  import useAnimation from "./useAnimation";
@@ -31,6 +31,13 @@ const dimension = Dimensions.get("window");
31
31
 
32
32
  const v = DeviceInfo?.getReadableVersion() || "";
33
33
 
34
+ let modelOs;
35
+ if (DeviceInfo) {
36
+ let model = DeviceInfo.getDeviceId();
37
+ if (model === "unknown") model = DeviceInfo.getModel();
38
+ modelOs = model + " - " + DeviceInfo.getSystemVersion();
39
+ }
40
+
34
41
  const Label = (props) => (
35
42
  <Text
36
43
  {...props}
@@ -40,8 +47,8 @@ const Label = (props) => (
40
47
  />
41
48
  );
42
49
 
43
- export default ({ variables, env, version = v }) => {
44
- const { apis, clear } = useApiInterceptor();
50
+ export default ({ variables, env, version = v, maxNumOfApiToStore = 0 }) => {
51
+ const { apis, clear } = useApiInterceptor(maxNumOfApiToStore);
45
52
 
46
53
  const [tab, setTab] = useState("api");
47
54
 
@@ -74,6 +81,7 @@ export default ({ variables, env, version = v }) => {
74
81
  backgroundColor: "#000000" + (isOpen ? "dd" : "bb"),
75
82
  height,
76
83
  width,
84
+ borderTopRightRadius: numPendingApiCalls || errors ? 0 : undefined,
77
85
  }}
78
86
  {...(isOpen ? {} : panResponder.panHandlers)}
79
87
  >
@@ -96,19 +104,11 @@ export default ({ variables, env, version = v }) => {
96
104
  {(!!env || !!version) && (
97
105
  <Label>{(env || "") + (env ? " " : "") + version}</Label>
98
106
  )}
99
- {!!DeviceInfo && (
100
- <Label style={{ fontSize: 6 }}>
101
- {DeviceInfo.getDeviceId() + " " + DeviceInfo.getSystemVersion()}
102
- </Label>
103
- )}
104
- <Label style={{ fontSize: 6 }}>
105
- {dimension.width + "x" + dimension.height}
106
- </Label>
107
- {variables?.GIT_BRANCH && (
108
- <Label style={{ fontSize: 6 }}>{variables.GIT_BRANCH}</Label>
109
- )}
107
+ {!!modelOs && <Label>{modelOs}</Label>}
108
+ <Label>{dimension.width + " x " + dimension.height}</Label>
109
+ {variables?.GIT_BRANCH && <Label>{variables.GIT_BRANCH}</Label>}
110
110
  {variables?.BUILD_DATE_TIME && (
111
- <Label style={{ fontSize: 6 }}>{variables.BUILD_DATE_TIME}</Label>
111
+ <Label>{variables.BUILD_DATE_TIME}</Label>
112
112
  )}
113
113
  </TouchableOpacity>
114
114
  ) : (
@@ -129,7 +129,13 @@ export default ({ variables, env, version = v }) => {
129
129
  borderColor: "white",
130
130
  }}
131
131
  >
132
- <Text style={{ color: "white", textAlign: "center" }}>
132
+ <Text
133
+ style={{
134
+ color: "white",
135
+ opacity: isSelected ? 1 : 0.5,
136
+ textAlign: "center",
137
+ }}
138
+ >
133
139
  {t.toUpperCase()}
134
140
  </Text>
135
141
  </TouchableOpacity>
@@ -143,7 +149,13 @@ export default ({ variables, env, version = v }) => {
143
149
  {tab === "variables" && !!variables && (
144
150
  <Variables variables={variables} />
145
151
  )}
146
- {tab === "api" && <Api apis={apis} clear={clear} />}
152
+ {tab === "api" && (
153
+ <Api
154
+ apis={apis}
155
+ clear={clear}
156
+ maxNumOfApiToStore={maxNumOfApiToStore}
157
+ />
158
+ )}
147
159
  </SafeAreaView>
148
160
  )}
149
161
  </Animated.View>
@@ -156,12 +168,12 @@ const styles = StyleSheet.create({
156
168
  width: "100%",
157
169
  height: "100%",
158
170
  },
159
- label: { color: "white", textAlign: "center", fontSize: 8 },
171
+ label: { color: "white", textAlign: "center", fontSize: 6 },
160
172
  badgeContainer: {
161
173
  gap: 3,
162
174
  flexDirection: "row",
163
- top: -8,
164
- right: -3,
175
+ top: -12,
176
+ right: -6,
165
177
  position: "absolute",
166
178
  zIndex: 999,
167
179
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-in-app-debugger",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "main": "index.jsx",
6
6
  "scripts": {
@@ -1,17 +1,7 @@
1
- // @ts-nocheck
2
1
  import { useEffect, useState } from "react";
3
- import { Platform } from "react-native";
4
2
  import XHRInterceptor from "react-native/Libraries/Network/XHRInterceptor.js";
5
3
 
6
4
  const filterNonBusinessRelatedAPI = true;
7
- const MAX_NUM_OF_API = 50;
8
-
9
- const now = () =>
10
- new Date().toLocaleTimeString("en-US", {
11
- hour: "numeric",
12
- minute: "numeric",
13
- second: "numeric",
14
- });
15
5
 
16
6
  const shouldExclude = (url, method) =>
17
7
  ["HEAD"].includes(method) ||
@@ -27,20 +17,34 @@ const parse = (data) => {
27
17
  }
28
18
  };
29
19
 
30
- export default () => {
20
+ export default (maxNumOfApiToStore) => {
31
21
  const [apis, setApis] = useState([]);
32
22
 
33
23
  const makeRequest = (data) => {
24
+ const date = new Date();
25
+ let hour = date.getHours();
26
+ const minute = (date.getMinutes() + "").padStart(2, "0");
27
+
28
+ const amPm = hour >= 12 ? "PM" : "AM";
29
+
30
+ if (hour > 12) {
31
+ hour -= 12;
32
+ } else if (hour === 0) {
33
+ hour = 12;
34
+ }
34
35
  const request = {
35
36
  ...data,
36
- datetime: now(),
37
+ timestamp: performance.now(),
38
+ time: `${hour}:${minute} ${amPm}`,
37
39
  };
38
- setApis((v) =>
39
- [
40
+ setApis((v) => {
41
+ const newData = [
40
42
  { request, id: Date.now().toString(36) + Math.random().toString(36) },
41
43
  ...v,
42
- ].slice(0, MAX_NUM_OF_API)
43
- );
44
+ ];
45
+ if (maxNumOfApiToStore) newData.slice(0, maxNumOfApiToStore);
46
+ return newData;
47
+ });
44
48
  };
45
49
 
46
50
  const receiveResponse = (data) => {
@@ -59,7 +63,7 @@ export default () => {
59
63
 
60
64
  oldData[i].response = {
61
65
  ...data,
62
- datetime: now(),
66
+ timestamp: performance.now(),
63
67
  error,
64
68
  };
65
69
  break;