@rozenite/network-activity-plugin 1.0.0-alpha.8 → 1.0.0

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.
Files changed (160) hide show
  1. package/README.md +2 -0
  2. package/dist/App.html +2 -2
  3. package/dist/assets/{App-R2ZMH9wJ.css → App-BrSkOkws.css} +269 -2
  4. package/dist/assets/{App-lNMijPJ4.js → App-C6wCDVkW.js} +17485 -10814
  5. package/dist/event-source.cjs +22 -0
  6. package/dist/event-source.js +23 -0
  7. package/dist/react-native.cjs +4 -1
  8. package/dist/react-native.js +4 -1
  9. package/dist/rozenite.json +1 -1
  10. package/dist/src/react-native/config.d.ts +20 -0
  11. package/dist/src/react-native/{network-inspector.d.ts → http/network-inspector.d.ts} +1 -1
  12. package/dist/src/react-native/http/overrides-registry.d.ts +6 -0
  13. package/dist/src/react-native/{xhr-interceptor.d.ts → http/xhr-interceptor.d.ts} +7 -1
  14. package/dist/src/react-native/sse/event-source.d.ts +2 -0
  15. package/dist/src/react-native/sse/sse-inspector.d.ts +9 -0
  16. package/dist/src/react-native/sse/sse-interceptor.d.ts +36 -0
  17. package/dist/src/react-native/sse/types.d.ts +6 -0
  18. package/dist/src/react-native/useNetworkActivityDevTools.d.ts +2 -1
  19. package/dist/src/react-native/utils/getBlobName.d.ts +35 -0
  20. package/dist/src/react-native/utils/getFormDataEntries.d.ts +18 -0
  21. package/dist/src/react-native/utils.d.ts +6 -0
  22. package/dist/src/react-native/websocket/websocket-inspector.d.ts +9 -0
  23. package/dist/src/react-native/websocket/websocket-interceptor.d.ts +74 -0
  24. package/dist/src/shared/client.d.ts +53 -6
  25. package/dist/src/shared/sse-events.d.ts +38 -0
  26. package/dist/src/shared/websocket-events.d.ts +60 -0
  27. package/dist/src/ui/components/Badge.d.ts +1 -1
  28. package/dist/src/ui/components/Button.d.ts +2 -2
  29. package/dist/src/ui/components/CodeBlock.d.ts +3 -0
  30. package/dist/src/ui/components/CodeEditor.d.ts +5 -0
  31. package/dist/src/ui/components/CookieCard.d.ts +7 -0
  32. package/dist/src/ui/components/CopyRequestDropdown.d.ts +7 -0
  33. package/dist/src/ui/components/DropdownMenu.d.ts +27 -0
  34. package/dist/src/ui/components/FilterBar.d.ts +10 -0
  35. package/dist/src/ui/components/JsonTreeCopyableItem.d.ts +7 -0
  36. package/dist/src/ui/components/KeyValueGrid.d.ts +13 -0
  37. package/dist/src/ui/components/OverrideResponse.d.ts +8 -0
  38. package/dist/src/ui/components/RequestBody.d.ts +6 -0
  39. package/dist/src/ui/components/RequestList.d.ts +13 -28
  40. package/dist/src/ui/components/ScrollArea.d.ts +3 -2
  41. package/dist/src/ui/components/Section.d.ts +8 -0
  42. package/dist/src/ui/components/Separator.d.ts +2 -1
  43. package/dist/src/ui/components/SidePanel.d.ts +1 -0
  44. package/dist/src/ui/components/Tabs.d.ts +7 -0
  45. package/dist/src/ui/components/Toolbar.d.ts +1 -0
  46. package/dist/src/ui/hooks/useCopyToClipboard.d.ts +4 -0
  47. package/dist/src/ui/state/derived.d.ts +5 -0
  48. package/dist/src/ui/state/hooks.d.ts +21 -0
  49. package/dist/src/ui/state/model.d.ts +103 -0
  50. package/dist/src/ui/state/store.d.ts +48 -0
  51. package/dist/src/ui/tabs/CookiesTab.d.ts +3 -6
  52. package/dist/src/ui/tabs/HeadersTab.d.ts +3 -15
  53. package/dist/src/ui/tabs/MessagesTab.d.ts +5 -0
  54. package/dist/src/ui/tabs/RequestTab.d.ts +2 -7
  55. package/dist/src/ui/tabs/ResponseTab.d.ts +2 -8
  56. package/dist/src/ui/tabs/SSEMessagesTab.d.ts +5 -0
  57. package/dist/src/ui/tabs/TimingTab.d.ts +3 -5
  58. package/dist/src/ui/types.d.ts +4 -1
  59. package/dist/src/ui/utils/assert.d.ts +1 -0
  60. package/dist/src/ui/utils/checkRequestBodyBinary.d.ts +2 -0
  61. package/dist/src/ui/utils/copyToClipboard.d.ts +1 -0
  62. package/dist/src/ui/utils/escapeShellArg.d.ts +1 -0
  63. package/dist/src/ui/utils/generateCurlCommand.d.ts +2 -0
  64. package/dist/src/ui/utils/generateFetchCall.d.ts +2 -0
  65. package/dist/src/ui/utils/generateMultipartBody.d.ts +4 -0
  66. package/dist/src/ui/utils/getId.d.ts +1 -0
  67. package/dist/src/ui/utils/getStatusColor.d.ts +1 -0
  68. package/dist/src/utils/applyReactNativeRequestHeadersLogic.d.ts +7 -0
  69. package/dist/src/utils/applyReactNativeResponseHeadersLogic.d.ts +9 -0
  70. package/dist/src/utils/cookieParser.d.ts +6 -0
  71. package/dist/src/utils/getContentTypeMimeType.d.ts +2 -0
  72. package/dist/src/utils/getHttpHeader.d.ts +5 -0
  73. package/dist/src/utils/getHttpHeaderValueAsString.d.ts +11 -0
  74. package/dist/src/utils/getStringSizeInBytes.d.ts +1 -0
  75. package/dist/src/utils/inferContentTypeFromPostData.d.ts +2 -0
  76. package/dist/src/utils/safeStringify.d.ts +1 -0
  77. package/dist/src/utils/typeChecks.d.ts +9 -0
  78. package/dist/useNetworkActivityDevTools.cjs +724 -40
  79. package/dist/useNetworkActivityDevTools.js +723 -41
  80. package/package.json +22 -8
  81. package/react-native.ts +6 -1
  82. package/src/react-native/config.ts +43 -0
  83. package/src/react-native/http/network-inspector.ts +388 -0
  84. package/src/react-native/http/overrides-registry.ts +32 -0
  85. package/src/react-native/{xhr-interceptor.ts → http/xhr-interceptor.ts} +19 -2
  86. package/src/react-native/{xml-request.d.ts → http/xml-request.d.ts} +1 -0
  87. package/src/react-native/sse/event-source.ts +25 -0
  88. package/src/react-native/sse/sse-inspector.ts +139 -0
  89. package/src/react-native/sse/sse-interceptor.ts +180 -0
  90. package/src/react-native/sse/types.ts +9 -0
  91. package/src/react-native/useNetworkActivityDevTools.ts +156 -4
  92. package/src/react-native/utils/getBlobName.ts +45 -0
  93. package/src/react-native/utils/getFormDataEntries.ts +32 -0
  94. package/src/react-native/utils.ts +43 -0
  95. package/src/react-native/websocket/websocket-inspector.ts +180 -0
  96. package/src/react-native/websocket/websocket-interceptor.d.ts +4 -0
  97. package/src/react-native/websocket/websocket-interceptor.ts +166 -0
  98. package/src/shared/client.ts +79 -6
  99. package/src/shared/sse-events.ts +47 -0
  100. package/src/shared/websocket-events.ts +79 -0
  101. package/src/ui/components/Button.tsx +1 -0
  102. package/src/ui/components/CodeBlock.tsx +19 -0
  103. package/src/ui/components/CodeEditor.tsx +26 -0
  104. package/src/ui/components/CookieCard.tsx +64 -0
  105. package/src/ui/components/CopyRequestDropdown.tsx +95 -0
  106. package/src/ui/components/DropdownMenu.tsx +206 -0
  107. package/src/ui/components/FilterBar.tsx +117 -0
  108. package/src/ui/components/Input.tsx +1 -1
  109. package/src/ui/components/JsonTree.tsx +20 -0
  110. package/src/ui/components/JsonTreeCopyableItem.tsx +37 -0
  111. package/src/ui/components/KeyValueGrid.tsx +51 -0
  112. package/src/ui/components/OverrideResponse.tsx +132 -0
  113. package/src/ui/components/RequestBody.tsx +86 -0
  114. package/src/ui/components/RequestList.tsx +101 -131
  115. package/src/ui/components/ScrollArea.tsx +1 -0
  116. package/src/ui/components/Section.tsx +46 -0
  117. package/src/ui/components/SidePanel.tsx +333 -0
  118. package/src/ui/components/Tabs.tsx +1 -1
  119. package/src/ui/components/Toolbar.tsx +45 -0
  120. package/src/ui/globals.css +4 -0
  121. package/src/ui/hooks/useCopyToClipboard.ts +28 -0
  122. package/src/ui/state/derived.ts +112 -0
  123. package/src/ui/state/hooks.ts +52 -0
  124. package/src/ui/state/model.ts +140 -0
  125. package/src/ui/state/store.ts +669 -0
  126. package/src/ui/tabs/CookiesTab.tsx +61 -278
  127. package/src/ui/tabs/HeadersTab.tsx +85 -103
  128. package/src/ui/tabs/MessagesTab.tsx +276 -0
  129. package/src/ui/tabs/RequestTab.tsx +58 -51
  130. package/src/ui/tabs/ResponseTab.tsx +101 -74
  131. package/src/ui/tabs/SSEMessagesTab.tsx +224 -0
  132. package/src/ui/tabs/TimingTab.tsx +30 -43
  133. package/src/ui/types.ts +4 -1
  134. package/src/ui/utils/assert.ts +5 -0
  135. package/src/ui/utils/checkRequestBodyBinary.ts +7 -0
  136. package/src/ui/utils/copyToClipboard.ts +3 -0
  137. package/src/ui/utils/escapeShellArg.ts +12 -0
  138. package/src/ui/utils/generateCurlCommand.ts +83 -0
  139. package/src/ui/utils/generateFetchCall.ts +64 -0
  140. package/src/ui/utils/generateMultipartBody.ts +19 -0
  141. package/src/ui/utils/getId.ts +10 -0
  142. package/src/ui/utils/getStatusColor.ts +15 -0
  143. package/src/ui/views/InspectorView.tsx +35 -319
  144. package/src/utils/applyReactNativeRequestHeadersLogic.ts +30 -0
  145. package/src/utils/applyReactNativeResponseHeadersLogic.ts +28 -0
  146. package/src/utils/cookieParser.ts +126 -0
  147. package/src/utils/getContentTypeMimeType.ts +17 -0
  148. package/src/utils/getHttpHeader.ts +17 -0
  149. package/src/utils/getHttpHeaderValueAsString.ts +13 -0
  150. package/src/utils/getStringSizeInBytes.ts +3 -0
  151. package/src/utils/inferContentTypeFromPostData.ts +9 -0
  152. package/src/utils/safeStringify.ts +7 -0
  153. package/src/utils/typeChecks.ts +27 -0
  154. package/tailwind.config.ts +3 -0
  155. package/vite.config.ts +12 -0
  156. package/dist/src/ui/utils/getHttpHeaderValue.d.ts +0 -2
  157. package/src/react-native/network-inspector.ts +0 -247
  158. package/src/ui/utils/getHttpHeaderValue.ts +0 -14
  159. /package/dist/src/react-native/{network-requests-registry.d.ts → http/network-requests-registry.d.ts} +0 -0
  160. /package/src/react-native/{network-requests-registry.ts → http/network-requests-registry.ts} +0 -0
package/vite.config.ts CHANGED
@@ -12,6 +12,18 @@ export default defineConfig({
12
12
  reportCompressedSize: false,
13
13
  minify: false,
14
14
  sourcemap: false,
15
+ rollupOptions: {
16
+ output: {
17
+ manualChunks: (id) => {
18
+ // Mitigate https://github.com/facebook/metro/issues/836
19
+ if (id.includes('event-source.ts')) {
20
+ return 'event-source';
21
+ }
22
+
23
+ return undefined;
24
+ },
25
+ },
26
+ },
15
27
  },
16
28
  server: {
17
29
  port: 3000,
@@ -1,2 +0,0 @@
1
- import { HttpHeaders } from '../../shared/client';
2
- export declare function getHttpHeaderValue(headers: HttpHeaders, name: string): string | undefined;
@@ -1,247 +0,0 @@
1
- import { NetworkActivityDevToolsClient } from '../shared/client';
2
- import { getHttpHeaderValue } from '../ui/utils/getHttpHeaderValue';
3
- import { getNetworkRequestsRegistry } from './network-requests-registry';
4
- import { XHRInterceptor } from './xhr-interceptor';
5
-
6
- const networkRequestsRegistry = getNetworkRequestsRegistry();
7
-
8
- const getContentType = (request: XMLHttpRequest): string => {
9
- const responseHeaders = request.responseHeaders;
10
- const responseType = request.responseType;
11
-
12
- const contentType = getHttpHeaderValue(responseHeaders || {}, 'content-type');
13
-
14
- if (contentType) {
15
- return contentType.split(';')[0].trim();
16
- }
17
-
18
- switch (responseType) {
19
- case 'arraybuffer':
20
- case 'blob':
21
- return 'application/octet-stream';
22
- case 'text':
23
- case '':
24
- return 'text/plain';
25
- case 'json':
26
- return 'application/json';
27
- case 'document':
28
- return 'text/html';
29
- }
30
- };
31
-
32
- const getResponseSize = (request: XMLHttpRequest): number => {
33
- if (typeof request.response === 'object') {
34
- return request.response.size;
35
- }
36
-
37
- return request.response.length || 0;
38
- };
39
-
40
- const getResponseBody = async (
41
- request: XMLHttpRequest
42
- ): Promise<string | null> => {
43
- const responseType = request.responseType;
44
-
45
- if (responseType === 'text') {
46
- return request.responseText as string;
47
- }
48
-
49
- if (responseType === 'blob') {
50
- // This may be a text blob.
51
- const contentType = request.getResponseHeader('Content-Type') || '';
52
-
53
- if (
54
- contentType.startsWith('text/') ||
55
- contentType.startsWith('application/json')
56
- ) {
57
- // It looks like a text blob, let's read it and forward it to the client.
58
- return new Promise((resolve) => {
59
- const reader = new FileReader();
60
- reader.onload = () => {
61
- resolve(reader.result as string);
62
- };
63
- reader.readAsText(request.response);
64
- });
65
- }
66
- }
67
-
68
- return null;
69
- };
70
-
71
- const getInitiatorFromStack = (): {
72
- type: string;
73
- url?: string;
74
- lineNumber?: number;
75
- columnNumber?: number;
76
- } => {
77
- try {
78
- const stack = new Error().stack;
79
- if (!stack) {
80
- return { type: 'other' };
81
- }
82
-
83
- const line = stack.split('\n')[9];
84
- const match = line.match(/at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
85
- if (match) {
86
- return {
87
- type: 'script',
88
- url: match[2],
89
- lineNumber: parseInt(match[3]),
90
- columnNumber: parseInt(match[4]),
91
- };
92
- }
93
- } catch {
94
- // Ignore stack parsing errors
95
- }
96
-
97
- return { type: 'other' };
98
- };
99
-
100
- export type NetworkInspector = {
101
- enable: () => void;
102
- disable: () => void;
103
- isEnabled: () => boolean;
104
- dispose: () => void;
105
- };
106
-
107
- const READY_STATE_HEADERS_RECEIVED = 2;
108
-
109
- export const getNetworkInspector = (
110
- pluginClient: NetworkActivityDevToolsClient
111
- ): NetworkInspector => {
112
- const generateRequestId = (): string => {
113
- return `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
114
- };
115
-
116
- const handleRequestSend = (data: string, request: XMLHttpRequest): void => {
117
- const sendTime = Date.now();
118
-
119
- const requestId = generateRequestId();
120
- const initiator = getInitiatorFromStack();
121
-
122
- networkRequestsRegistry.addEntry(requestId, request);
123
-
124
- let ttfb = 0;
125
-
126
- pluginClient.send('request-sent', {
127
- requestId: requestId,
128
- timestamp: sendTime / 1000,
129
- request: {
130
- url: request._url as string,
131
- method: request._method as string,
132
- headers: request._headers,
133
- postData: data,
134
- },
135
- type: 'XHR',
136
- initiator,
137
- });
138
-
139
- request.addEventListener('readystatechange', () => {
140
- if (request.readyState === READY_STATE_HEADERS_RECEIVED) {
141
- ttfb = Date.now() - sendTime;
142
- }
143
- });
144
-
145
- request.addEventListener('load', () => {
146
- pluginClient.send('response-received', {
147
- requestId: requestId,
148
- timestamp: Date.now() / 1000,
149
- type: 'XHR',
150
- response: {
151
- url: request._url as string,
152
- status: request.status,
153
- statusText: request.statusText,
154
- headers: request.responseHeaders || {},
155
- contentType: getContentType(request),
156
- size: getResponseSize(request),
157
- responseTime: Date.now() / 1000,
158
- },
159
- });
160
- });
161
-
162
- request.addEventListener('loadend', () => {
163
- pluginClient.send('request-completed', {
164
- requestId: requestId,
165
- timestamp: Date.now() / 1000,
166
- duration: Date.now() - sendTime,
167
- size: getResponseSize(request),
168
- ttfb,
169
- });
170
- });
171
-
172
- request.addEventListener('error', () => {
173
- pluginClient.send('request-failed', {
174
- requestId: requestId,
175
- timestamp: Date.now() / 1000,
176
- type: 'XHR',
177
- error: 'Failed',
178
- canceled: false,
179
- });
180
- });
181
-
182
- request.addEventListener('abort', () => {
183
- pluginClient.send('request-failed', {
184
- requestId: requestId,
185
- timestamp: Date.now() / 1000,
186
- type: 'XHR',
187
- error: 'Aborted',
188
- canceled: true,
189
- });
190
- });
191
- };
192
-
193
- const enable = () => {
194
- XHRInterceptor.disableInterception();
195
- XHRInterceptor.setSendCallback(handleRequestSend);
196
- XHRInterceptor.enableInterception();
197
- };
198
-
199
- const disable = () => {
200
- XHRInterceptor.disableInterception();
201
- networkRequestsRegistry.clear();
202
- };
203
-
204
- const isEnabled = () => {
205
- return XHRInterceptor.isInterceptorEnabled();
206
- };
207
-
208
- const enableSubscription = pluginClient.onMessage('network-enable', () => {
209
- enable();
210
- });
211
-
212
- const disableSubscription = pluginClient.onMessage('network-disable', () => {
213
- disable();
214
- });
215
-
216
- const handleBodySubscription = pluginClient.onMessage(
217
- 'get-response-body',
218
- async ({ requestId }) => {
219
- const request = networkRequestsRegistry.getEntry(requestId);
220
-
221
- if (!request) {
222
- return;
223
- }
224
-
225
- const body = await getResponseBody(request);
226
-
227
- pluginClient.send('response-body', {
228
- requestId,
229
- body,
230
- });
231
- }
232
- );
233
-
234
- const dispose = () => {
235
- disable();
236
- enableSubscription.remove();
237
- disableSubscription.remove();
238
- handleBodySubscription.remove();
239
- };
240
-
241
- return {
242
- enable,
243
- disable,
244
- isEnabled,
245
- dispose,
246
- };
247
- };
@@ -1,14 +0,0 @@
1
- import { HttpHeaders } from "../../shared/client";
2
-
3
- // Utility to get header value case-insensitively
4
- export function getHttpHeaderValue(headers: HttpHeaders, name: string) {
5
- const lowerName = name.toLowerCase();
6
-
7
- for (const key in headers) {
8
- if (key.toLowerCase() === lowerName) {
9
- return headers[key];
10
- }
11
- }
12
-
13
- return undefined;
14
- }