network-terminal 1.0.1 → 1.0.3
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/bin/cli.js +40 -0
- package/dist/index.js +48 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -21
- package/dist/index.mjs.map +1 -1
- package/dist/vite-plugin.js +48 -21
- package/dist/vite-plugin.js.map +1 -1
- package/dist/vite-plugin.mjs +48 -21
- package/dist/vite-plugin.mjs.map +1 -1
- package/package.json +19 -6
- package/src/components/LogEntry.tsx +121 -0
- package/src/components/NetworkTerminal.tsx +219 -0
- package/src/components/Terminal.tsx +86 -0
- package/src/components/TerminalHeader.tsx +93 -0
- package/src/hooks/useNetworkInterceptor.ts +190 -0
- package/src/index.ts +17 -0
- package/src/types.ts +50 -0
- package/src/utils/colors.ts +18 -0
- package/src/utils/formatters.ts +26 -0
- package/src/vite-plugin.ts +88 -0
- package/standalone/index.html +25 -0
- package/standalone/main.tsx +216 -0
- package/standalone/vite.config.js +12 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom/client';
|
|
3
|
+
import { NetworkTerminal } from '../src';
|
|
4
|
+
|
|
5
|
+
const styles = {
|
|
6
|
+
container: {
|
|
7
|
+
padding: '40px',
|
|
8
|
+
maxWidth: '800px',
|
|
9
|
+
margin: '0 auto',
|
|
10
|
+
},
|
|
11
|
+
header: {
|
|
12
|
+
marginBottom: '40px',
|
|
13
|
+
},
|
|
14
|
+
title: {
|
|
15
|
+
fontSize: '32px',
|
|
16
|
+
fontWeight: 'bold',
|
|
17
|
+
color: '#4ade80',
|
|
18
|
+
fontFamily: 'monospace',
|
|
19
|
+
marginBottom: '8px',
|
|
20
|
+
},
|
|
21
|
+
subtitle: {
|
|
22
|
+
color: '#94a3b8',
|
|
23
|
+
fontSize: '16px',
|
|
24
|
+
},
|
|
25
|
+
section: {
|
|
26
|
+
background: '#1e293b',
|
|
27
|
+
borderRadius: '12px',
|
|
28
|
+
padding: '24px',
|
|
29
|
+
marginBottom: '24px',
|
|
30
|
+
},
|
|
31
|
+
sectionTitle: {
|
|
32
|
+
fontSize: '18px',
|
|
33
|
+
fontWeight: '600',
|
|
34
|
+
marginBottom: '16px',
|
|
35
|
+
color: '#f1f5f9',
|
|
36
|
+
},
|
|
37
|
+
buttonGroup: {
|
|
38
|
+
display: 'flex',
|
|
39
|
+
gap: '12px',
|
|
40
|
+
flexWrap: 'wrap' as const,
|
|
41
|
+
},
|
|
42
|
+
button: {
|
|
43
|
+
padding: '10px 20px',
|
|
44
|
+
borderRadius: '8px',
|
|
45
|
+
border: 'none',
|
|
46
|
+
cursor: 'pointer',
|
|
47
|
+
fontWeight: '500',
|
|
48
|
+
fontSize: '14px',
|
|
49
|
+
transition: 'all 0.2s',
|
|
50
|
+
},
|
|
51
|
+
getButton: {
|
|
52
|
+
background: '#22c55e',
|
|
53
|
+
color: '#000',
|
|
54
|
+
},
|
|
55
|
+
postButton: {
|
|
56
|
+
background: '#3b82f6',
|
|
57
|
+
color: '#fff',
|
|
58
|
+
},
|
|
59
|
+
putButton: {
|
|
60
|
+
background: '#f59e0b',
|
|
61
|
+
color: '#000',
|
|
62
|
+
},
|
|
63
|
+
deleteButton: {
|
|
64
|
+
background: '#ef4444',
|
|
65
|
+
color: '#fff',
|
|
66
|
+
},
|
|
67
|
+
errorButton: {
|
|
68
|
+
background: '#6b7280',
|
|
69
|
+
color: '#fff',
|
|
70
|
+
},
|
|
71
|
+
inputGroup: {
|
|
72
|
+
display: 'flex',
|
|
73
|
+
gap: '12px',
|
|
74
|
+
marginBottom: '16px',
|
|
75
|
+
},
|
|
76
|
+
input: {
|
|
77
|
+
flex: 1,
|
|
78
|
+
padding: '10px 16px',
|
|
79
|
+
borderRadius: '8px',
|
|
80
|
+
border: '1px solid #374151',
|
|
81
|
+
background: '#0f172a',
|
|
82
|
+
color: '#e2e8f0',
|
|
83
|
+
fontSize: '14px',
|
|
84
|
+
},
|
|
85
|
+
hint: {
|
|
86
|
+
marginTop: '24px',
|
|
87
|
+
padding: '16px',
|
|
88
|
+
background: '#0f172a',
|
|
89
|
+
borderRadius: '8px',
|
|
90
|
+
borderLeft: '4px solid #4ade80',
|
|
91
|
+
},
|
|
92
|
+
hintText: {
|
|
93
|
+
color: '#94a3b8',
|
|
94
|
+
fontSize: '14px',
|
|
95
|
+
fontFamily: 'monospace',
|
|
96
|
+
},
|
|
97
|
+
kbd: {
|
|
98
|
+
background: '#374151',
|
|
99
|
+
padding: '2px 8px',
|
|
100
|
+
borderRadius: '4px',
|
|
101
|
+
fontSize: '12px',
|
|
102
|
+
color: '#4ade80',
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
function App() {
|
|
107
|
+
const [customUrl, setCustomUrl] = useState('https://jsonplaceholder.typicode.com/posts/1');
|
|
108
|
+
|
|
109
|
+
const makeRequest = async (method: string, url: string, body?: object) => {
|
|
110
|
+
try {
|
|
111
|
+
const options: RequestInit = {
|
|
112
|
+
method,
|
|
113
|
+
headers: {
|
|
114
|
+
'Content-Type': 'application/json',
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
if (body) {
|
|
118
|
+
options.body = JSON.stringify(body);
|
|
119
|
+
}
|
|
120
|
+
await fetch(url, options);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error('Request failed:', error);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<div style={styles.container}>
|
|
128
|
+
<div style={styles.header}>
|
|
129
|
+
<h1 style={styles.title}>>_ Network Terminal</h1>
|
|
130
|
+
<p style={styles.subtitle}>Monitor your Fetch/XHR requests in real-time</p>
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
<div style={styles.section}>
|
|
134
|
+
<h2 style={styles.sectionTitle}>Quick Actions</h2>
|
|
135
|
+
<div style={styles.buttonGroup}>
|
|
136
|
+
<button
|
|
137
|
+
style={{ ...styles.button, ...styles.getButton }}
|
|
138
|
+
onClick={() => makeRequest('GET', 'https://jsonplaceholder.typicode.com/posts/1')}
|
|
139
|
+
>
|
|
140
|
+
GET Request
|
|
141
|
+
</button>
|
|
142
|
+
<button
|
|
143
|
+
style={{ ...styles.button, ...styles.postButton }}
|
|
144
|
+
onClick={() =>
|
|
145
|
+
makeRequest('POST', 'https://jsonplaceholder.typicode.com/posts', {
|
|
146
|
+
title: 'Test Post',
|
|
147
|
+
body: 'This is a test post body',
|
|
148
|
+
userId: 1,
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
>
|
|
152
|
+
POST Request
|
|
153
|
+
</button>
|
|
154
|
+
<button
|
|
155
|
+
style={{ ...styles.button, ...styles.putButton }}
|
|
156
|
+
onClick={() =>
|
|
157
|
+
makeRequest('PUT', 'https://jsonplaceholder.typicode.com/posts/1', {
|
|
158
|
+
id: 1,
|
|
159
|
+
title: 'Updated Title',
|
|
160
|
+
body: 'Updated body content',
|
|
161
|
+
userId: 1,
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
>
|
|
165
|
+
PUT Request
|
|
166
|
+
</button>
|
|
167
|
+
<button
|
|
168
|
+
style={{ ...styles.button, ...styles.deleteButton }}
|
|
169
|
+
onClick={() => makeRequest('DELETE', 'https://jsonplaceholder.typicode.com/posts/1')}
|
|
170
|
+
>
|
|
171
|
+
DELETE Request
|
|
172
|
+
</button>
|
|
173
|
+
<button
|
|
174
|
+
style={{ ...styles.button, ...styles.errorButton }}
|
|
175
|
+
onClick={() => makeRequest('GET', 'https://jsonplaceholder.typicode.com/invalid-endpoint')}
|
|
176
|
+
>
|
|
177
|
+
404 Error
|
|
178
|
+
</button>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<div style={styles.section}>
|
|
183
|
+
<h2 style={styles.sectionTitle}>Custom Request</h2>
|
|
184
|
+
<div style={styles.inputGroup}>
|
|
185
|
+
<input
|
|
186
|
+
type="text"
|
|
187
|
+
value={customUrl}
|
|
188
|
+
onChange={(e) => setCustomUrl(e.target.value)}
|
|
189
|
+
placeholder="Enter URL..."
|
|
190
|
+
style={styles.input}
|
|
191
|
+
/>
|
|
192
|
+
<button
|
|
193
|
+
style={{ ...styles.button, ...styles.getButton }}
|
|
194
|
+
onClick={() => makeRequest('GET', customUrl)}
|
|
195
|
+
>
|
|
196
|
+
Send GET
|
|
197
|
+
</button>
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<div style={styles.hint}>
|
|
202
|
+
<p style={styles.hintText}>
|
|
203
|
+
Press <span style={styles.kbd}>Ctrl+Shift+N</span> to toggle the Network Terminal
|
|
204
|
+
</p>
|
|
205
|
+
</div>
|
|
206
|
+
|
|
207
|
+
<NetworkTerminal defaultVisible={true} position="bottom" maxLogs={50} />
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
213
|
+
<React.StrictMode>
|
|
214
|
+
<App />
|
|
215
|
+
</React.StrictMode>
|
|
216
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
plugins: [react()],
|
|
7
|
+
resolve: {
|
|
8
|
+
alias: {
|
|
9
|
+
'network-terminal': path.resolve(__dirname, '../src'),
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
});
|