react-native-nitro-fetch 1.3.1 → 1.3.2
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/android/build.gradle +12 -0
- package/android/src/main/java/com/margelo/nitro/nitrofetch/AutoPrefetcher.kt +148 -55
- package/ios/NitroAutoPrefetcher.swift +149 -53
- package/lib/module/CurlGenerator.js.map +2 -1
- package/lib/module/HermesProfiler.js.map +1 -2
- package/lib/module/NetworkInspector.js +4 -0
- package/lib/module/NetworkInspector.js.map +1 -1
- package/lib/module/NitroFetch.nitro.js.map +1 -2
- package/lib/module/NitroInstances.js.map +1 -1
- package/lib/module/Request.js.map +2 -1
- package/lib/module/Response.js +3 -1
- package/lib/module/Response.js.map +2 -2
- package/lib/module/fetch.js +8 -10
- package/lib/module/fetch.js.map +1 -1
- package/lib/module/index.js.map +1 -2
- package/lib/module/index.web.js +1 -1
- package/lib/module/index.web.js.map +2 -1
- package/lib/module/tokenRefresh.js +1 -4
- package/lib/module/tokenRefresh.js.map +2 -1
- package/lib/module/utf8.js.map +2 -2
- package/lib/typescript/src/fetch.d.ts.map +1 -1
- package/lib/typescript/src/tokenRefresh.d.ts +14 -0
- package/lib/typescript/src/tokenRefresh.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/CurlGenerator.js +23 -26
- package/src/Headers.js +108 -116
- package/src/HermesProfiler.js +16 -18
- package/src/NetworkInspector.js +171 -179
- package/src/NitroInstances.js +2 -1
- package/src/Request.js +167 -164
- package/src/Response.js +244 -242
- package/src/fetch.js +708 -693
- package/src/fetch.ts +15 -16
- package/src/index.js +17 -2
- package/src/index.web.js +69 -67
- package/src/tokenRefresh.js +75 -77
- package/src/tokenRefresh.ts +16 -0
- package/src/utf8.js +28 -27
package/src/NetworkInspector.js
CHANGED
|
@@ -1,183 +1,175 @@
|
|
|
1
1
|
import { generateCurl } from './CurlGenerator';
|
|
2
2
|
class NetworkInspectorImpl {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (!this._enabled)
|
|
175
|
-
return;
|
|
176
|
-
const entry = this._entries.find((e) => e.id === id && e.type === 'websocket');
|
|
177
|
-
if (!entry)
|
|
178
|
-
return;
|
|
179
|
-
entry.error = error;
|
|
180
|
-
this._notify(entry);
|
|
181
|
-
}
|
|
3
|
+
_enabled = false;
|
|
4
|
+
_entries = [];
|
|
5
|
+
_maxEntries = 500;
|
|
6
|
+
_maxBodyCapture = 4096;
|
|
7
|
+
_listeners = new Set();
|
|
8
|
+
enable(options) {
|
|
9
|
+
this._enabled = true;
|
|
10
|
+
if (options?.maxEntries != null) this._maxEntries = options.maxEntries;
|
|
11
|
+
if (options?.maxBodyCapture != null)
|
|
12
|
+
this._maxBodyCapture = options.maxBodyCapture;
|
|
13
|
+
}
|
|
14
|
+
disable() {
|
|
15
|
+
this._enabled = false;
|
|
16
|
+
}
|
|
17
|
+
isEnabled() {
|
|
18
|
+
return this._enabled;
|
|
19
|
+
}
|
|
20
|
+
getEntries() {
|
|
21
|
+
return this._entries;
|
|
22
|
+
}
|
|
23
|
+
getHttpEntries() {
|
|
24
|
+
return this._entries.filter((e) => e.type === 'http');
|
|
25
|
+
}
|
|
26
|
+
getWebSocketEntries() {
|
|
27
|
+
return this._entries.filter((e) => e.type === 'websocket');
|
|
28
|
+
}
|
|
29
|
+
getEntry(id) {
|
|
30
|
+
return this._entries.find((e) => e.id === id);
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
this._entries = [];
|
|
34
|
+
}
|
|
35
|
+
onEntry(callback) {
|
|
36
|
+
this._listeners.add(callback);
|
|
37
|
+
return () => {
|
|
38
|
+
this._listeners.delete(callback);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
_notify(entry) {
|
|
42
|
+
for (const cb of this._listeners) {
|
|
43
|
+
try {
|
|
44
|
+
cb(entry);
|
|
45
|
+
} catch {
|
|
46
|
+
// swallow listener errors
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
_trimEntries() {
|
|
51
|
+
if (this._entries.length > this._maxEntries) {
|
|
52
|
+
this._entries.shift();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// --- HTTP recording ---
|
|
56
|
+
_recordStart(id, url, method, headers, body) {
|
|
57
|
+
if (!this._enabled) return;
|
|
58
|
+
const bodySize = body ? body.length : 0;
|
|
59
|
+
const entry = {
|
|
60
|
+
id,
|
|
61
|
+
type: 'http',
|
|
62
|
+
url,
|
|
63
|
+
method,
|
|
64
|
+
requestHeaders: headers.map((h) => ({ key: h.key, value: h.value })),
|
|
65
|
+
requestBody: body ? body.slice(0, this._maxBodyCapture) : undefined,
|
|
66
|
+
requestBodySize: bodySize,
|
|
67
|
+
status: 0,
|
|
68
|
+
statusText: '',
|
|
69
|
+
responseHeaders: [],
|
|
70
|
+
responseBodySize: 0,
|
|
71
|
+
startTime: performance.now(),
|
|
72
|
+
endTime: 0,
|
|
73
|
+
duration: 0,
|
|
74
|
+
curl: generateCurl({ url, method, headers, body }),
|
|
75
|
+
};
|
|
76
|
+
this._entries.push(entry);
|
|
77
|
+
this._trimEntries();
|
|
78
|
+
}
|
|
79
|
+
_recordEnd(id, status, statusText, headers, bodySize, error, responseBody) {
|
|
80
|
+
if (!this._enabled) return;
|
|
81
|
+
const entry = this._entries.find((e) => e.id === id && e.type === 'http');
|
|
82
|
+
if (!entry) return;
|
|
83
|
+
entry.status = status;
|
|
84
|
+
entry.statusText = statusText;
|
|
85
|
+
entry.responseHeaders = headers.map((h) => ({
|
|
86
|
+
key: h.key,
|
|
87
|
+
value: h.value,
|
|
88
|
+
}));
|
|
89
|
+
entry.responseBodySize = bodySize;
|
|
90
|
+
entry.endTime = performance.now();
|
|
91
|
+
entry.duration = entry.endTime - entry.startTime;
|
|
92
|
+
if (error) entry.error = error;
|
|
93
|
+
if (responseBody != null) {
|
|
94
|
+
entry.responseBody = responseBody.slice(0, this._maxBodyCapture);
|
|
95
|
+
}
|
|
96
|
+
this._notify(entry);
|
|
97
|
+
}
|
|
98
|
+
// --- WebSocket recording ---
|
|
99
|
+
_recordWsOpen(id, url, protocols, headers) {
|
|
100
|
+
if (!this._enabled) return;
|
|
101
|
+
const entry = {
|
|
102
|
+
id,
|
|
103
|
+
type: 'websocket',
|
|
104
|
+
url,
|
|
105
|
+
protocols,
|
|
106
|
+
requestHeaders: headers.map((h) => ({ key: h.key, value: h.value })),
|
|
107
|
+
startTime: performance.now(),
|
|
108
|
+
endTime: 0,
|
|
109
|
+
duration: 0,
|
|
110
|
+
readyState: 'CONNECTING',
|
|
111
|
+
messages: [],
|
|
112
|
+
messagesSent: 0,
|
|
113
|
+
messagesReceived: 0,
|
|
114
|
+
bytesSent: 0,
|
|
115
|
+
bytesReceived: 0,
|
|
116
|
+
};
|
|
117
|
+
this._entries.push(entry);
|
|
118
|
+
this._trimEntries();
|
|
119
|
+
this._notify(entry);
|
|
120
|
+
}
|
|
121
|
+
_recordWsConnected(id) {
|
|
122
|
+
if (!this._enabled) return;
|
|
123
|
+
const entry = this._entries.find(
|
|
124
|
+
(e) => e.id === id && e.type === 'websocket'
|
|
125
|
+
);
|
|
126
|
+
if (!entry) return;
|
|
127
|
+
entry.readyState = 'OPEN';
|
|
128
|
+
this._notify(entry);
|
|
129
|
+
}
|
|
130
|
+
_recordWsMessage(id, direction, data, size, isBinary) {
|
|
131
|
+
if (!this._enabled) return;
|
|
132
|
+
const entry = this._entries.find(
|
|
133
|
+
(e) => e.id === id && e.type === 'websocket'
|
|
134
|
+
);
|
|
135
|
+
if (!entry) return;
|
|
136
|
+
entry.messages.push({
|
|
137
|
+
direction,
|
|
138
|
+
data: data.slice(0, this._maxBodyCapture),
|
|
139
|
+
size,
|
|
140
|
+
isBinary,
|
|
141
|
+
timestamp: performance.now(),
|
|
142
|
+
});
|
|
143
|
+
if (direction === 'sent') {
|
|
144
|
+
entry.messagesSent++;
|
|
145
|
+
entry.bytesSent += size;
|
|
146
|
+
} else {
|
|
147
|
+
entry.messagesReceived++;
|
|
148
|
+
entry.bytesReceived += size;
|
|
149
|
+
}
|
|
150
|
+
this._notify(entry);
|
|
151
|
+
}
|
|
152
|
+
_recordWsClose(id, code, reason) {
|
|
153
|
+
if (!this._enabled) return;
|
|
154
|
+
const entry = this._entries.find(
|
|
155
|
+
(e) => e.id === id && e.type === 'websocket'
|
|
156
|
+
);
|
|
157
|
+
if (!entry) return;
|
|
158
|
+
entry.readyState = 'CLOSED';
|
|
159
|
+
entry.closeCode = code;
|
|
160
|
+
entry.closeReason = reason;
|
|
161
|
+
entry.endTime = performance.now();
|
|
162
|
+
entry.duration = entry.endTime - entry.startTime;
|
|
163
|
+
this._notify(entry);
|
|
164
|
+
}
|
|
165
|
+
_recordWsError(id, error) {
|
|
166
|
+
if (!this._enabled) return;
|
|
167
|
+
const entry = this._entries.find(
|
|
168
|
+
(e) => e.id === id && e.type === 'websocket'
|
|
169
|
+
);
|
|
170
|
+
if (!entry) return;
|
|
171
|
+
entry.error = error;
|
|
172
|
+
this._notify(entry);
|
|
173
|
+
}
|
|
182
174
|
}
|
|
183
175
|
export const NetworkInspector = new NetworkInspectorImpl();
|
package/src/NitroInstances.js
CHANGED
|
@@ -3,4 +3,5 @@ import { NitroModules } from 'react-native-nitro-modules';
|
|
|
3
3
|
export const NitroFetch = NitroModules.createHybridObject('NitroFetch');
|
|
4
4
|
export const NativeStorage = NitroModules.createHybridObject('NativeStorage');
|
|
5
5
|
export const boxedNitroFetch = NitroModules.box(NitroFetch);
|
|
6
|
-
export const NitroCronetSingleton =
|
|
6
|
+
export const NitroCronetSingleton =
|
|
7
|
+
NitroModules.createHybridObject('NitroCronet');
|