@rozenite/network-activity-plugin 1.0.0-alpha.15 → 1.0.0-alpha.16
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/dist/App.html +2 -2
- package/dist/assets/{App-CfJuBHc_.css → App-BrSkOkws.css} +21 -0
- package/dist/assets/{App-CZPlDq_M.js → App-CM3Ub2ZA.js} +911 -479
- package/dist/rozenite.json +1 -1
- package/dist/src/react-native/http/overrides-registry.d.ts +6 -0
- package/dist/src/react-native/http/xhr-interceptor.d.ts +5 -0
- package/dist/src/shared/client.d.ts +7 -0
- package/dist/src/ui/components/CodeEditor.d.ts +5 -0
- package/dist/src/ui/components/OverrideResponse.d.ts +8 -0
- package/dist/src/ui/components/RequestList.d.ts +3 -2
- package/dist/src/ui/components/Section.d.ts +2 -1
- package/dist/src/ui/state/hooks.d.ts +3 -0
- package/dist/src/ui/state/store.d.ts +26 -3
- package/dist/useNetworkActivityDevTools.cjs +72 -0
- package/dist/useNetworkActivityDevTools.js +72 -0
- package/package.json +4 -4
- package/src/react-native/http/network-inspector.ts +50 -0
- package/src/react-native/http/overrides-registry.ts +32 -0
- package/src/react-native/http/xhr-interceptor.ts +14 -0
- package/src/react-native/useNetworkActivityDevTools.ts +6 -0
- package/src/shared/client.ts +9 -0
- package/src/ui/components/CodeEditor.tsx +26 -0
- package/src/ui/components/OverrideResponse.tsx +132 -0
- package/src/ui/components/RequestList.tsx +15 -8
- package/src/ui/components/Section.tsx +5 -1
- package/src/ui/components/SidePanel.tsx +8 -0
- package/src/ui/state/hooks.ts +4 -0
- package/src/ui/state/store.ts +585 -502
- package/src/ui/tabs/ResponseTab.tsx +60 -12
- package/src/ui/views/InspectorView.tsx +7 -1
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { ScrollArea } from '../components/ScrollArea';
|
|
3
3
|
import { JsonTree } from '../components/JsonTree';
|
|
4
4
|
import { HttpNetworkEntry } from '../state/model';
|
|
5
5
|
import { Section } from '../components/Section';
|
|
6
6
|
import { KeyValueGrid } from '../components/KeyValueGrid';
|
|
7
7
|
import { CodeBlock } from '../components/CodeBlock';
|
|
8
|
+
import { useOverrides } from '../state/hooks';
|
|
9
|
+
import { RequestOverride } from '../../shared/client';
|
|
10
|
+
import { OverrideResponse } from '../components/OverrideResponse';
|
|
11
|
+
import { Button } from '../components/Button';
|
|
12
|
+
import { Pencil } from 'lucide-react';
|
|
8
13
|
|
|
9
14
|
export type ResponseTabProps = {
|
|
10
15
|
selectedRequest: HttpNetworkEntry;
|
|
11
16
|
onRequestResponseBody: (requestId: string) => void;
|
|
12
17
|
};
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
type ResponseBodySectionProps = {
|
|
20
|
+
action?: React.ReactNode;
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const RenderResponseBodySection = ({
|
|
25
|
+
children,
|
|
26
|
+
action,
|
|
27
|
+
}: ResponseBodySectionProps) => {
|
|
15
28
|
return (
|
|
16
|
-
<Section title="Response Body" collapsible={false}>
|
|
29
|
+
<Section title="Response Body" collapsible={false} action={action}>
|
|
17
30
|
<div className="space-y-4">{children}</div>
|
|
18
31
|
</Section>
|
|
19
32
|
);
|
|
@@ -24,6 +37,13 @@ export const ResponseTab = ({
|
|
|
24
37
|
onRequestResponseBody,
|
|
25
38
|
}: ResponseTabProps) => {
|
|
26
39
|
const onRequestResponseBodyRef = useRef(onRequestResponseBody);
|
|
40
|
+
const overrides = useOverrides();
|
|
41
|
+
const [initialOverride, setInitialOverride] = useState<
|
|
42
|
+
RequestOverride | undefined
|
|
43
|
+
>(() => {
|
|
44
|
+
const override = overrides.get(selectedRequest.request.url);
|
|
45
|
+
return override;
|
|
46
|
+
});
|
|
27
47
|
|
|
28
48
|
useEffect(() => {
|
|
29
49
|
onRequestResponseBodyRef.current = onRequestResponseBody;
|
|
@@ -47,6 +67,7 @@ export const ResponseTab = ({
|
|
|
47
67
|
}
|
|
48
68
|
|
|
49
69
|
const { type, data } = responseBody;
|
|
70
|
+
const statusCode = selectedRequest.response?.status;
|
|
50
71
|
|
|
51
72
|
const contentTypeGrid = (
|
|
52
73
|
<KeyValueGrid
|
|
@@ -60,6 +81,33 @@ export const ResponseTab = ({
|
|
|
60
81
|
/>
|
|
61
82
|
);
|
|
62
83
|
|
|
84
|
+
const overrideAction = (
|
|
85
|
+
<Button
|
|
86
|
+
variant="ghost"
|
|
87
|
+
size="xs"
|
|
88
|
+
className="text-violet-300 hover:text-violet-300"
|
|
89
|
+
onClick={() =>
|
|
90
|
+
setInitialOverride({
|
|
91
|
+
body: data,
|
|
92
|
+
status: statusCode,
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
>
|
|
96
|
+
<Pencil className="h-2 w-2" />
|
|
97
|
+
Override
|
|
98
|
+
</Button>
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
if (initialOverride !== undefined) {
|
|
102
|
+
return (
|
|
103
|
+
<OverrideResponse
|
|
104
|
+
selectedRequest={selectedRequest}
|
|
105
|
+
initialOverride={initialOverride}
|
|
106
|
+
onClear={() => setInitialOverride(undefined)}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
63
111
|
if (type.startsWith('application/json')) {
|
|
64
112
|
let bodyContent;
|
|
65
113
|
|
|
@@ -82,11 +130,11 @@ export const ResponseTab = ({
|
|
|
82
130
|
);
|
|
83
131
|
}
|
|
84
132
|
|
|
85
|
-
return
|
|
86
|
-
|
|
133
|
+
return (
|
|
134
|
+
<RenderResponseBodySection action={overrideAction}>
|
|
87
135
|
{contentTypeGrid}
|
|
88
136
|
{bodyContent}
|
|
89
|
-
|
|
137
|
+
</RenderResponseBodySection>
|
|
90
138
|
);
|
|
91
139
|
}
|
|
92
140
|
|
|
@@ -95,21 +143,21 @@ export const ResponseTab = ({
|
|
|
95
143
|
type.startsWith('application/xml') ||
|
|
96
144
|
type.startsWith('application/javascript')
|
|
97
145
|
) {
|
|
98
|
-
return
|
|
99
|
-
|
|
146
|
+
return (
|
|
147
|
+
<RenderResponseBodySection action={overrideAction}>
|
|
100
148
|
{contentTypeGrid}
|
|
101
149
|
<CodeBlock>{data}</CodeBlock>
|
|
102
|
-
|
|
150
|
+
</RenderResponseBodySection>
|
|
103
151
|
);
|
|
104
152
|
}
|
|
105
153
|
|
|
106
|
-
return
|
|
107
|
-
|
|
154
|
+
return (
|
|
155
|
+
<RenderResponseBodySection>
|
|
108
156
|
{contentTypeGrid}
|
|
109
157
|
<div className="text-sm text-gray-400">
|
|
110
158
|
Binary content not shown - {data.length} bytes
|
|
111
159
|
</div>
|
|
112
|
-
|
|
160
|
+
</RenderResponseBodySection>
|
|
113
161
|
);
|
|
114
162
|
};
|
|
115
163
|
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
useNetworkActivityClientManagement,
|
|
9
9
|
useHasSelectedRequest,
|
|
10
10
|
useNetworkActivityActions,
|
|
11
|
+
useOverrides,
|
|
11
12
|
} from '../state/hooks';
|
|
12
13
|
|
|
13
14
|
export type InspectorViewProps = {
|
|
@@ -18,6 +19,7 @@ export const InspectorView = ({ client }: InspectorViewProps) => {
|
|
|
18
19
|
const actions = useNetworkActivityActions();
|
|
19
20
|
const clientManagement = useNetworkActivityClientManagement();
|
|
20
21
|
const hasSelectedRequest = useHasSelectedRequest();
|
|
22
|
+
const overrides = useOverrides();
|
|
21
23
|
const [filter, setFilter] = useState<FilterState>({
|
|
22
24
|
text: '',
|
|
23
25
|
types: new Set(['http', 'websocket', 'sse']),
|
|
@@ -31,11 +33,15 @@ export const InspectorView = ({ client }: InspectorViewProps) => {
|
|
|
31
33
|
clientManagement.setupClient(client);
|
|
32
34
|
actions.setRecording(true);
|
|
33
35
|
|
|
36
|
+
client.send('set-overrides', {
|
|
37
|
+
overrides: Array.from(overrides.entries()),
|
|
38
|
+
});
|
|
39
|
+
|
|
34
40
|
return () => {
|
|
35
41
|
actions.setRecording(false);
|
|
36
42
|
clientManagement.cleanupClient();
|
|
37
43
|
};
|
|
38
|
-
}, [client, clientManagement, actions]);
|
|
44
|
+
}, [client, clientManagement, actions, overrides]);
|
|
39
45
|
|
|
40
46
|
return (
|
|
41
47
|
<div className="h-screen bg-gray-900 text-gray-100 flex flex-col">
|