@hakam-aldeen-kh/blix 0.4.2 → 0.6.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.
- package/README.md +298 -37
- package/dist/{DevToolsPanel-TXMT43YN.js → DevToolsPanel-QTVFBNU5.js} +3651 -2178
- package/dist/capture/index.d.ts +168 -18
- package/dist/capture/index.js +4 -2
- package/dist/chunk-4JZEVUOR.js +735 -0
- package/dist/{chunk-MRTSIXR7.js → chunk-FIYP47QZ.js} +202 -118
- package/dist/index.d.ts +4 -4
- package/dist/index.js +13 -4
- package/package.json +2 -1
- package/dist/chunk-OQHKPRNI.js +0 -287
package/dist/chunk-OQHKPRNI.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MONITOR_ENABLED,
|
|
3
|
-
PERSIST_MAX_ENTRY_BYTES,
|
|
4
|
-
configureDbName,
|
|
5
|
-
estimateBytes,
|
|
6
|
-
getOwner,
|
|
7
|
-
networkMonitor,
|
|
8
|
-
now,
|
|
9
|
-
serializeBody,
|
|
10
|
-
serializeHeaders,
|
|
11
|
-
truncateForPersist
|
|
12
|
-
} from "./chunk-MRTSIXR7.js";
|
|
13
|
-
|
|
14
|
-
// src/capture/monitorStamp.ts
|
|
15
|
-
var MONITOR_ID = /* @__PURE__ */ Symbol.for("blix.monitorId");
|
|
16
|
-
var stampFallback = /* @__PURE__ */ new WeakMap();
|
|
17
|
-
function stampMonitorId(config, id) {
|
|
18
|
-
try {
|
|
19
|
-
Object.defineProperty(config, MONITOR_ID, {
|
|
20
|
-
value: id,
|
|
21
|
-
enumerable: false,
|
|
22
|
-
writable: true,
|
|
23
|
-
configurable: true
|
|
24
|
-
});
|
|
25
|
-
} catch (e) {
|
|
26
|
-
stampFallback.set(config, id);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function readMonitorId(config) {
|
|
30
|
-
if (config === null || typeof config !== "object") return void 0;
|
|
31
|
-
const stamped = config;
|
|
32
|
-
const direct = stamped[MONITOR_ID];
|
|
33
|
-
if (typeof direct === "string") return direct;
|
|
34
|
-
if (typeof stamped.__monitorId === "string") return stamped.__monitorId;
|
|
35
|
-
return stampFallback.get(config);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// src/capture/attachHttp.ts
|
|
39
|
-
function attachHttpMonitor(instance, options) {
|
|
40
|
-
if (!MONITOR_ENABLED) return;
|
|
41
|
-
if (options == null ? void 0 : options.dbName) configureDbName(options.dbName);
|
|
42
|
-
instance.interceptors.request.use((config) => {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
if (networkMonitor.isPaused) return config;
|
|
45
|
-
try {
|
|
46
|
-
const id = networkMonitor.nextId();
|
|
47
|
-
const monitored = config;
|
|
48
|
-
monitored.__monitorId = id;
|
|
49
|
-
stampMonitorId(config, id);
|
|
50
|
-
const hadFormData = typeof FormData !== "undefined" && config.data instanceof FormData;
|
|
51
|
-
const requestPayload = serializeBody(config.data);
|
|
52
|
-
const owner = getOwner();
|
|
53
|
-
networkMonitor.start({
|
|
54
|
-
id,
|
|
55
|
-
method: ((_a = config.method) != null ? _a : "post").toUpperCase(),
|
|
56
|
-
url: (_b = config.url) != null ? _b : "",
|
|
57
|
-
baseURL: config.baseURL,
|
|
58
|
-
at: Date.now(),
|
|
59
|
-
startTime: now(),
|
|
60
|
-
requestPayload,
|
|
61
|
-
requestHeaders: serializeHeaders(config.headers),
|
|
62
|
-
sizeBytes: estimateBytes(requestPayload),
|
|
63
|
-
skipEncryption: monitored.skipEncryption === true,
|
|
64
|
-
hadFormData,
|
|
65
|
-
replayOf: monitored.__monitorReplayOf,
|
|
66
|
-
initiator: monitored.__monitorInitiator,
|
|
67
|
-
ownerId: owner == null ? void 0 : owner.id,
|
|
68
|
-
initiatorKind: owner == null ? void 0 : owner.kind
|
|
69
|
-
});
|
|
70
|
-
if (owner) networkMonitor.linkChild(owner.id, id);
|
|
71
|
-
} catch (e) {
|
|
72
|
-
}
|
|
73
|
-
return config;
|
|
74
|
-
});
|
|
75
|
-
instance.interceptors.response.use(
|
|
76
|
-
(response) => {
|
|
77
|
-
const id = response.config.__monitorId;
|
|
78
|
-
if (!id) return response;
|
|
79
|
-
try {
|
|
80
|
-
const payload = response.data;
|
|
81
|
-
networkMonitor.update(id, {
|
|
82
|
-
state: "success",
|
|
83
|
-
status: response.status,
|
|
84
|
-
endTime: now(),
|
|
85
|
-
responsePayload: payload,
|
|
86
|
-
responseHeaders: serializeHeaders(response.headers),
|
|
87
|
-
sizeBytes: estimateBytes(payload)
|
|
88
|
-
});
|
|
89
|
-
} catch (e) {
|
|
90
|
-
}
|
|
91
|
-
return response;
|
|
92
|
-
},
|
|
93
|
-
(error) => {
|
|
94
|
-
var _a, _b, _c, _d, _e;
|
|
95
|
-
const id = (_a = error.config) == null ? void 0 : _a.__monitorId;
|
|
96
|
-
if (id) {
|
|
97
|
-
try {
|
|
98
|
-
const payload = (_c = (_b = error.response) == null ? void 0 : _b.data) != null ? _c : error.message;
|
|
99
|
-
networkMonitor.update(id, {
|
|
100
|
-
state: "error",
|
|
101
|
-
status: (_d = error.response) == null ? void 0 : _d.status,
|
|
102
|
-
endTime: now(),
|
|
103
|
-
error: payload,
|
|
104
|
-
responseHeaders: serializeHeaders((_e = error.response) == null ? void 0 : _e.headers),
|
|
105
|
-
sizeBytes: estimateBytes(payload)
|
|
106
|
-
});
|
|
107
|
-
} catch (e) {
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return Promise.reject(error);
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/capture/captureEncrypted.ts
|
|
116
|
-
var MAX_ENCRYPTED_BYTES = PERSIST_MAX_ENTRY_BYTES;
|
|
117
|
-
var BINARY_PREVIEW_BYTES = 512;
|
|
118
|
-
var HEX = "0123456789abcdef";
|
|
119
|
-
function toBytes(value) {
|
|
120
|
-
if (typeof ArrayBuffer === "undefined") return null;
|
|
121
|
-
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
122
|
-
if (ArrayBuffer.isView(value)) {
|
|
123
|
-
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
function labelOf(value) {
|
|
128
|
-
var _a;
|
|
129
|
-
const name = (_a = value.constructor) == null ? void 0 : _a.name;
|
|
130
|
-
return typeof name === "string" && name.length > 0 ? name : "BufferSource";
|
|
131
|
-
}
|
|
132
|
-
function binaryPreview(bytes, label) {
|
|
133
|
-
const limit = Math.min(bytes.length, BINARY_PREVIEW_BYTES);
|
|
134
|
-
let head = "";
|
|
135
|
-
for (let i = 0; i < limit; i += 1) {
|
|
136
|
-
const byte = bytes[i];
|
|
137
|
-
head += HEX[byte >> 4] + HEX[byte & 15];
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
__blixBinary: label,
|
|
141
|
-
byteLength: bytes.length,
|
|
142
|
-
head,
|
|
143
|
-
truncated: bytes.length > limit
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function normalize(value) {
|
|
147
|
-
const bytes = toBytes(value);
|
|
148
|
-
if (bytes) return binaryPreview(bytes, labelOf(value));
|
|
149
|
-
return truncateForPersist(serializeBody(value), MAX_ENCRYPTED_BYTES).value;
|
|
150
|
-
}
|
|
151
|
-
function captureEncrypted(config, payload) {
|
|
152
|
-
if (!MONITOR_ENABLED) return;
|
|
153
|
-
try {
|
|
154
|
-
const id = readMonitorId(config);
|
|
155
|
-
if (!id) return;
|
|
156
|
-
if (!payload) return;
|
|
157
|
-
const patch = {};
|
|
158
|
-
if (payload.request != null) patch.encryptedRequest = normalize(payload.request);
|
|
159
|
-
if (payload.response != null) patch.encryptedResponse = normalize(payload.response);
|
|
160
|
-
if (patch.encryptedRequest === void 0 && patch.encryptedResponse === void 0) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
networkMonitor.update(id, patch);
|
|
164
|
-
} catch (e) {
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// src/capture/realtimeCapture.ts
|
|
169
|
-
var frameCounter = 0;
|
|
170
|
-
function makeFrame(direction, event, data) {
|
|
171
|
-
frameCounter += 1;
|
|
172
|
-
return {
|
|
173
|
-
id: `f${frameCounter}`,
|
|
174
|
-
at: Date.now(),
|
|
175
|
-
direction,
|
|
176
|
-
event,
|
|
177
|
-
data,
|
|
178
|
-
sizeBytes: estimateBytes(data)
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
function tapRealtimeAdapter(adapter, transport) {
|
|
182
|
-
if (!MONITOR_ENABLED) return adapter;
|
|
183
|
-
let connectionId = null;
|
|
184
|
-
const frame = (direction, event, data) => {
|
|
185
|
-
if (!connectionId) return;
|
|
186
|
-
try {
|
|
187
|
-
networkMonitor.appendFrame(connectionId, makeFrame(direction, event, data));
|
|
188
|
-
} catch (e) {
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
const openConnection = (url) => {
|
|
192
|
-
try {
|
|
193
|
-
const id = networkMonitor.nextId();
|
|
194
|
-
connectionId = id;
|
|
195
|
-
const startTime = now();
|
|
196
|
-
networkMonitor.start({
|
|
197
|
-
id,
|
|
198
|
-
kind: "ws",
|
|
199
|
-
transport,
|
|
200
|
-
method: "WS",
|
|
201
|
-
// Strip the token from the query string — it is a credential, and the
|
|
202
|
-
// panel already masks the equivalent HTTP header.
|
|
203
|
-
url: redactUrl(url),
|
|
204
|
-
at: Date.now(),
|
|
205
|
-
startTime,
|
|
206
|
-
// A connection has no response body; size accrues from its frames.
|
|
207
|
-
sizeBytes: 0,
|
|
208
|
-
frames: []
|
|
209
|
-
});
|
|
210
|
-
return id;
|
|
211
|
-
} catch (e) {
|
|
212
|
-
connectionId = null;
|
|
213
|
-
return null;
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
const closeConnection = (state, reason) => {
|
|
217
|
-
if (!connectionId) return;
|
|
218
|
-
try {
|
|
219
|
-
networkMonitor.update(connectionId, {
|
|
220
|
-
state,
|
|
221
|
-
endTime: now(),
|
|
222
|
-
responsePayload: { closed: reason != null ? reason : "disconnected" }
|
|
223
|
-
});
|
|
224
|
-
} catch (e) {
|
|
225
|
-
}
|
|
226
|
-
connectionId = null;
|
|
227
|
-
};
|
|
228
|
-
return new Proxy(adapter, {
|
|
229
|
-
get(target, prop, receiver) {
|
|
230
|
-
const value = Reflect.get(target, prop, receiver);
|
|
231
|
-
if (typeof value !== "function") return value;
|
|
232
|
-
if (prop === "connect") {
|
|
233
|
-
return (token, url) => {
|
|
234
|
-
openConnection(url);
|
|
235
|
-
frame("system", "connect", { url: redactUrl(url), transport });
|
|
236
|
-
return value.call(target, token, url);
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
if (prop === "disconnect") {
|
|
240
|
-
return () => {
|
|
241
|
-
frame("system", "disconnect", null);
|
|
242
|
-
const result = value.call(target);
|
|
243
|
-
closeConnection("success", "client disconnect");
|
|
244
|
-
return result;
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
if (prop === "subscribe") {
|
|
248
|
-
return (channelName) => {
|
|
249
|
-
frame("out", `subscribe:${channelName}`, { channel: channelName });
|
|
250
|
-
return value.call(target, channelName);
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
if (prop === "onMessage") {
|
|
254
|
-
return (cb) => value.call(target, (payload) => {
|
|
255
|
-
var _a;
|
|
256
|
-
frame("in", (_a = payload == null ? void 0 : payload.event) != null ? _a : "message", payload == null ? void 0 : payload.data);
|
|
257
|
-
cb(payload);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
if (prop === "onPresenceUpdate") {
|
|
261
|
-
return (cb) => value.call(target, (status) => {
|
|
262
|
-
frame("system", `presence:${status}`, { status });
|
|
263
|
-
if (status === "offline") closeConnection("error", "transport offline");
|
|
264
|
-
cb(status);
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
return value.bind(target);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
function redactUrl(url) {
|
|
272
|
-
try {
|
|
273
|
-
const parsed = new URL(url, "http://local");
|
|
274
|
-
for (const key of ["token", "access_token", "accessToken", "auth"]) {
|
|
275
|
-
if (parsed.searchParams.has(key)) parsed.searchParams.set(key, "\u2022\u2022\u2022");
|
|
276
|
-
}
|
|
277
|
-
return url.startsWith("/") ? parsed.pathname + parsed.search : parsed.toString();
|
|
278
|
-
} catch (e) {
|
|
279
|
-
return url.replace(/([?&](?:token|access_token|accessToken|auth)=)[^&]*/gi, "$1\u2022\u2022\u2022");
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export {
|
|
284
|
-
attachHttpMonitor,
|
|
285
|
-
captureEncrypted,
|
|
286
|
-
tapRealtimeAdapter
|
|
287
|
-
};
|