@getlimelight/sdk 0.7.4 → 0.7.8
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 +9 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +405 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +406 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,6 +128,15 @@ export default Limelight.withLimelight((req, res) => {
|
|
|
128
128
|
|
|
129
129
|
Both methods automatically capture request/response headers, bodies, status codes, and timing — and propagate a trace ID (`x-limelight-trace-id`) for full-stack tracing.
|
|
130
130
|
|
|
131
|
+
**Outbound HTTP interception** is automatic in Node.js environments. When `enableNetworkInspector` is `true` (the default), the SDK patches `http.request` and `https.request` to capture all outgoing calls your server makes — API calls to other services, auth servers, databases over HTTP, etc. Combined with the incoming middleware, this gives you full end-to-end tracing:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
Client (fetch) → Your Server (middleware) → Downstream Service (http interceptor)
|
|
135
|
+
↑ same trace ID propagated across all three ↑
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
No additional setup is required — just connect the SDK and add the middleware.
|
|
139
|
+
|
|
131
140
|
## Learn More
|
|
132
141
|
|
|
133
142
|
- [Quick Start Guide](https://docs.getlimelight.io/quickstart)
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,8 @@ declare enum NetworkType {
|
|
|
5
5
|
FETCH = "fetch",
|
|
6
6
|
XHR = "xhr",
|
|
7
7
|
GRAPHQL = "graphql",
|
|
8
|
-
INCOMING = "incoming"
|
|
8
|
+
INCOMING = "incoming",
|
|
9
|
+
HTTP = "http"
|
|
9
10
|
}
|
|
10
11
|
declare enum NetworkPhase {
|
|
11
12
|
CONNECT = "CONNECT",
|
|
@@ -572,6 +573,7 @@ declare class LimelightClient {
|
|
|
572
573
|
private maxQueueSize;
|
|
573
574
|
private networkInterceptor;
|
|
574
575
|
private xhrInterceptor;
|
|
576
|
+
private httpInterceptor;
|
|
575
577
|
private consoleInterceptor;
|
|
576
578
|
private renderInterceptor;
|
|
577
579
|
private stateInterceptor;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ declare enum NetworkType {
|
|
|
5
5
|
FETCH = "fetch",
|
|
6
6
|
XHR = "xhr",
|
|
7
7
|
GRAPHQL = "graphql",
|
|
8
|
-
INCOMING = "incoming"
|
|
8
|
+
INCOMING = "incoming",
|
|
9
|
+
HTTP = "http"
|
|
9
10
|
}
|
|
10
11
|
declare enum NetworkPhase {
|
|
11
12
|
CONNECT = "CONNECT",
|
|
@@ -572,6 +573,7 @@ declare class LimelightClient {
|
|
|
572
573
|
private maxQueueSize;
|
|
573
574
|
private networkInterceptor;
|
|
574
575
|
private xhrInterceptor;
|
|
576
|
+
private httpInterceptor;
|
|
575
577
|
private consoleInterceptor;
|
|
576
578
|
private renderInterceptor;
|
|
577
579
|
private stateInterceptor;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Bridge Node CJS require to globalThis so runtime dynamic requires work
|
|
2
|
+
// in environments like ts-node where require is module-scoped only.
|
|
3
|
+
// In ESM or browser contexts typeof require is 'undefined', so this is a no-op.
|
|
4
|
+
if (typeof require === "function" && typeof globalThis !== "undefined" && typeof globalThis.require === "undefined" && typeof process !== "undefined" && process.versions && process.versions.node) { Object.defineProperty(globalThis, "require", { value: require, configurable: true, writable: true, enumerable: false }); }
|
|
1
5
|
"use strict";
|
|
2
6
|
var __defProp = Object.defineProperty;
|
|
3
7
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -67,6 +71,7 @@ var NetworkType = /* @__PURE__ */ ((NetworkType2) => {
|
|
|
67
71
|
NetworkType2["XHR"] = "xhr";
|
|
68
72
|
NetworkType2["GRAPHQL"] = "graphql";
|
|
69
73
|
NetworkType2["INCOMING"] = "incoming";
|
|
74
|
+
NetworkType2["HTTP"] = "http";
|
|
70
75
|
return NetworkType2;
|
|
71
76
|
})(NetworkType || {});
|
|
72
77
|
var NetworkPhase = /* @__PURE__ */ ((NetworkPhase2) => {
|
|
@@ -87,17 +92,17 @@ var BodyFormat = /* @__PURE__ */ ((BodyFormat2) => {
|
|
|
87
92
|
BodyFormat2["UNSERIALIZABLE"] = "UNSERIALIZABLE";
|
|
88
93
|
return BodyFormat2;
|
|
89
94
|
})(BodyFormat || {});
|
|
90
|
-
var HttpMethod = /* @__PURE__ */ ((
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
95
|
+
var HttpMethod = /* @__PURE__ */ ((HttpMethod7) => {
|
|
96
|
+
HttpMethod7["GET"] = "GET";
|
|
97
|
+
HttpMethod7["POST"] = "POST";
|
|
98
|
+
HttpMethod7["PUT"] = "PUT";
|
|
99
|
+
HttpMethod7["PATCH"] = "PATCH";
|
|
100
|
+
HttpMethod7["DELETE"] = "DELETE";
|
|
101
|
+
HttpMethod7["HEAD"] = "HEAD";
|
|
102
|
+
HttpMethod7["OPTIONS"] = "OPTIONS";
|
|
103
|
+
HttpMethod7["TRACE"] = "TRACE";
|
|
104
|
+
HttpMethod7["CONNECT"] = "CONNECT";
|
|
105
|
+
return HttpMethod7;
|
|
101
106
|
})(HttpMethod || {});
|
|
102
107
|
var HttpStatusClass = /* @__PURE__ */ ((HttpStatusClass2) => {
|
|
103
108
|
HttpStatusClass2[HttpStatusClass2["INFORMATIONAL"] = 100] = "INFORMATIONAL";
|
|
@@ -287,7 +292,7 @@ var LIMELIGHT_WEB_WSS_URL = "wss://api.getlimelight.io";
|
|
|
287
292
|
var LIMELIGHT_DESKTOP_WSS_URL = "ws://localhost:8484";
|
|
288
293
|
var LIMELIGHT_MCP_WS_URL = "ws://localhost:9229";
|
|
289
294
|
var WS_PATH = "/limelight";
|
|
290
|
-
var SDK_VERSION = true ? "0.7.
|
|
295
|
+
var SDK_VERSION = true ? "0.7.8" : "test-version";
|
|
291
296
|
var RENDER_THRESHOLDS = {
|
|
292
297
|
HOT_VELOCITY: 5,
|
|
293
298
|
HIGH_RENDER_COUNT: 50,
|
|
@@ -301,6 +306,16 @@ var RENDER_THRESHOLDS = {
|
|
|
301
306
|
TOP_PROPS_TO_REPORT: 5
|
|
302
307
|
// Only report top N changed props
|
|
303
308
|
};
|
|
309
|
+
var BINARY_CONTENT_TYPES = [
|
|
310
|
+
"image/",
|
|
311
|
+
"audio/",
|
|
312
|
+
"video/",
|
|
313
|
+
"application/octet-stream",
|
|
314
|
+
"application/pdf",
|
|
315
|
+
"application/zip",
|
|
316
|
+
"application/gzip"
|
|
317
|
+
];
|
|
318
|
+
var MAX_BODY_SIZE = 1024 * 1024;
|
|
304
319
|
|
|
305
320
|
// src/helpers/safety/redactSensitiveHeaders.ts
|
|
306
321
|
var redactSensitiveHeaders = (headers) => {
|
|
@@ -580,6 +595,21 @@ var getCurrentTransactionId = () => {
|
|
|
580
595
|
return globalGetTransactionId?.() ?? null;
|
|
581
596
|
};
|
|
582
597
|
|
|
598
|
+
// src/helpers/http/resolveUrl.ts
|
|
599
|
+
var resolveUrl = (protocol, options) => {
|
|
600
|
+
const host = options.hostname || options.host || "localhost";
|
|
601
|
+
const port = options.port ? `:${options.port}` : "";
|
|
602
|
+
const path = options.path || "/";
|
|
603
|
+
return `${protocol}//${host}${port}${path}`;
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
// src/helpers/http/isBinaryContentType.ts
|
|
607
|
+
var isBinaryContentType = (contentType) => {
|
|
608
|
+
return BINARY_CONTENT_TYPES.some(
|
|
609
|
+
(type) => contentType.toLowerCase().includes(type)
|
|
610
|
+
);
|
|
611
|
+
};
|
|
612
|
+
|
|
583
613
|
// src/limelight/interceptors/ConsoleInterceptor.ts
|
|
584
614
|
var ConsoleInterceptor = class {
|
|
585
615
|
constructor(sendMessage, getSessionId) {
|
|
@@ -1205,6 +1235,360 @@ var XHRInterceptor = class {
|
|
|
1205
1235
|
}
|
|
1206
1236
|
};
|
|
1207
1237
|
|
|
1238
|
+
// src/limelight/interceptors/HttpInterceptor.ts
|
|
1239
|
+
var HttpInterceptor = class {
|
|
1240
|
+
constructor(sendMessage, getSessionId) {
|
|
1241
|
+
this.sendMessage = sendMessage;
|
|
1242
|
+
this.getSessionId = getSessionId;
|
|
1243
|
+
try {
|
|
1244
|
+
const _require = globalThis["require"];
|
|
1245
|
+
this.httpModule = _require("http");
|
|
1246
|
+
this.httpsModule = _require("https");
|
|
1247
|
+
this.originalHttpRequest = this.httpModule.request;
|
|
1248
|
+
this.originalHttpGet = this.httpModule.get;
|
|
1249
|
+
this.originalHttpsRequest = this.httpsModule.request;
|
|
1250
|
+
this.originalHttpsGet = this.httpsModule.get;
|
|
1251
|
+
} catch {
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
originalHttpRequest = null;
|
|
1255
|
+
originalHttpGet = null;
|
|
1256
|
+
originalHttpsRequest = null;
|
|
1257
|
+
originalHttpsGet = null;
|
|
1258
|
+
httpModule = null;
|
|
1259
|
+
httpsModule = null;
|
|
1260
|
+
config = null;
|
|
1261
|
+
isSetup = false;
|
|
1262
|
+
setup(config) {
|
|
1263
|
+
if (this.isSetup) {
|
|
1264
|
+
if (this.config?.enableInternalLogging) {
|
|
1265
|
+
console.warn("[Limelight] HTTP interceptor already set up");
|
|
1266
|
+
}
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
if (!this.httpModule || !this.httpsModule) {
|
|
1270
|
+
if (config?.enableInternalLogging) {
|
|
1271
|
+
console.warn(
|
|
1272
|
+
"[Limelight] Node http module not available, skipping HTTP interception"
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
this.isSetup = true;
|
|
1278
|
+
this.config = config;
|
|
1279
|
+
const self2 = this;
|
|
1280
|
+
const httpMod = this.httpModule;
|
|
1281
|
+
const httpsMod = this.httpsModule;
|
|
1282
|
+
httpMod.request = (...args) => {
|
|
1283
|
+
return self2.interceptRequest(
|
|
1284
|
+
"http:",
|
|
1285
|
+
self2.originalHttpRequest,
|
|
1286
|
+
httpMod,
|
|
1287
|
+
args
|
|
1288
|
+
);
|
|
1289
|
+
};
|
|
1290
|
+
httpMod.get = (...args) => {
|
|
1291
|
+
const req = self2.interceptRequest(
|
|
1292
|
+
"http:",
|
|
1293
|
+
self2.originalHttpRequest,
|
|
1294
|
+
httpMod,
|
|
1295
|
+
args
|
|
1296
|
+
);
|
|
1297
|
+
req.end();
|
|
1298
|
+
return req;
|
|
1299
|
+
};
|
|
1300
|
+
httpsMod.request = (...args) => {
|
|
1301
|
+
return self2.interceptRequest(
|
|
1302
|
+
"https:",
|
|
1303
|
+
self2.originalHttpsRequest,
|
|
1304
|
+
httpsMod,
|
|
1305
|
+
args
|
|
1306
|
+
);
|
|
1307
|
+
};
|
|
1308
|
+
httpsMod.get = (...args) => {
|
|
1309
|
+
const req = self2.interceptRequest(
|
|
1310
|
+
"https:",
|
|
1311
|
+
self2.originalHttpsRequest,
|
|
1312
|
+
httpsMod,
|
|
1313
|
+
args
|
|
1314
|
+
);
|
|
1315
|
+
req.end();
|
|
1316
|
+
return req;
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
interceptRequest(protocol, originalMethod, module2, args) {
|
|
1320
|
+
let url;
|
|
1321
|
+
let options;
|
|
1322
|
+
let callback;
|
|
1323
|
+
if (typeof args[0] === "string" || args[0] instanceof URL) {
|
|
1324
|
+
url = args[0];
|
|
1325
|
+
if (typeof args[1] === "function") {
|
|
1326
|
+
options = {};
|
|
1327
|
+
callback = args[1];
|
|
1328
|
+
} else {
|
|
1329
|
+
options = args[1] || {};
|
|
1330
|
+
callback = args[2];
|
|
1331
|
+
}
|
|
1332
|
+
} else {
|
|
1333
|
+
options = args[0] || {};
|
|
1334
|
+
callback = args[1];
|
|
1335
|
+
}
|
|
1336
|
+
let resolvedUrl;
|
|
1337
|
+
if (url) {
|
|
1338
|
+
resolvedUrl = url.toString();
|
|
1339
|
+
} else {
|
|
1340
|
+
resolvedUrl = resolveUrl(protocol, options);
|
|
1341
|
+
}
|
|
1342
|
+
const limelightServerUrl = this.config?.serverUrl || "";
|
|
1343
|
+
if (limelightServerUrl && resolvedUrl.includes(limelightServerUrl)) {
|
|
1344
|
+
return originalMethod.apply(module2, args);
|
|
1345
|
+
}
|
|
1346
|
+
const self2 = this;
|
|
1347
|
+
const requestId = generateRequestId();
|
|
1348
|
+
const startTime = Date.now();
|
|
1349
|
+
const initiator = getInitiator();
|
|
1350
|
+
const traceHeaderName = this.config?.traceHeaderName ?? "x-limelight-trace-id";
|
|
1351
|
+
const existingTraceId = getTraceContext()?.getStore()?.traceId;
|
|
1352
|
+
const traceId = existingTraceId || generateRequestId();
|
|
1353
|
+
if (!options.headers) {
|
|
1354
|
+
options.headers = {};
|
|
1355
|
+
}
|
|
1356
|
+
options.headers[traceHeaderName] = traceId;
|
|
1357
|
+
const method = (options.method || "GET").toUpperCase();
|
|
1358
|
+
let patchedArgs;
|
|
1359
|
+
if (url) {
|
|
1360
|
+
patchedArgs = callback ? [url, options, callback] : [url, options];
|
|
1361
|
+
} else {
|
|
1362
|
+
patchedArgs = callback ? [options, callback] : [options];
|
|
1363
|
+
}
|
|
1364
|
+
const req = originalMethod.apply(
|
|
1365
|
+
module2,
|
|
1366
|
+
patchedArgs
|
|
1367
|
+
);
|
|
1368
|
+
const bodyChunks = [];
|
|
1369
|
+
let totalBodySize = 0;
|
|
1370
|
+
let requestEventSent = false;
|
|
1371
|
+
const originalWrite = req.write.bind(req);
|
|
1372
|
+
const originalEnd = req.end.bind(req);
|
|
1373
|
+
req.write = (chunk, encodingOrCallback, callback2) => {
|
|
1374
|
+
if (chunk && totalBodySize < MAX_BODY_SIZE) {
|
|
1375
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1376
|
+
bodyChunks.push(buf);
|
|
1377
|
+
totalBodySize += buf.length;
|
|
1378
|
+
}
|
|
1379
|
+
return originalWrite(chunk, encodingOrCallback, callback2);
|
|
1380
|
+
};
|
|
1381
|
+
req.end = (chunk, encodingOrCallback, callback2) => {
|
|
1382
|
+
if (chunk && typeof chunk !== "function" && totalBodySize < MAX_BODY_SIZE) {
|
|
1383
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1384
|
+
bodyChunks.push(buf);
|
|
1385
|
+
totalBodySize += buf.length;
|
|
1386
|
+
}
|
|
1387
|
+
if (!requestEventSent) {
|
|
1388
|
+
requestEventSent = true;
|
|
1389
|
+
const fullBody = bodyChunks.length > 0 ? Buffer.concat(bodyChunks).toString("utf-8") : void 0;
|
|
1390
|
+
const headers = {};
|
|
1391
|
+
const rawHeaders = req.getHeaders();
|
|
1392
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
1393
|
+
if (value !== void 0) {
|
|
1394
|
+
headers[key.toLowerCase()] = Array.isArray(value) ? value.join(", ") : String(value);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
const requestBody = serializeBody(
|
|
1398
|
+
fullBody,
|
|
1399
|
+
self2.config?.disableBodyCapture
|
|
1400
|
+
);
|
|
1401
|
+
let requestEvent = {
|
|
1402
|
+
id: requestId,
|
|
1403
|
+
traceId,
|
|
1404
|
+
sessionId: self2.getSessionId(),
|
|
1405
|
+
timestamp: startTime,
|
|
1406
|
+
phase: "REQUEST" /* REQUEST */,
|
|
1407
|
+
networkType: "http" /* HTTP */,
|
|
1408
|
+
url: resolvedUrl,
|
|
1409
|
+
method,
|
|
1410
|
+
headers: redactSensitiveHeaders(headers),
|
|
1411
|
+
body: requestBody,
|
|
1412
|
+
name: formatRequestName(resolvedUrl),
|
|
1413
|
+
initiator,
|
|
1414
|
+
requestSize: requestBody?.size ?? 0
|
|
1415
|
+
};
|
|
1416
|
+
if (self2.config?.beforeSend) {
|
|
1417
|
+
const modifiedEvent = self2.config.beforeSend(requestEvent);
|
|
1418
|
+
if (!modifiedEvent) {
|
|
1419
|
+
return originalEnd(
|
|
1420
|
+
chunk,
|
|
1421
|
+
encodingOrCallback,
|
|
1422
|
+
callback2
|
|
1423
|
+
);
|
|
1424
|
+
}
|
|
1425
|
+
if (modifiedEvent.phase !== "REQUEST" /* REQUEST */) {
|
|
1426
|
+
console.error("[Limelight] beforeSend must return same event type");
|
|
1427
|
+
return originalEnd(
|
|
1428
|
+
chunk,
|
|
1429
|
+
encodingOrCallback,
|
|
1430
|
+
callback2
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
requestEvent = modifiedEvent;
|
|
1434
|
+
}
|
|
1435
|
+
self2.sendMessage(requestEvent);
|
|
1436
|
+
}
|
|
1437
|
+
return originalEnd(chunk, encodingOrCallback, callback2);
|
|
1438
|
+
};
|
|
1439
|
+
let responseSent = false;
|
|
1440
|
+
req.on("response", (res) => {
|
|
1441
|
+
const responseChunks = [];
|
|
1442
|
+
let responseSize = 0;
|
|
1443
|
+
res.on("data", (chunk) => {
|
|
1444
|
+
if (responseSize < MAX_BODY_SIZE) {
|
|
1445
|
+
responseChunks.push(chunk);
|
|
1446
|
+
responseSize += chunk.length;
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
res.on("end", () => {
|
|
1450
|
+
if (responseSent) return;
|
|
1451
|
+
responseSent = true;
|
|
1452
|
+
const endTime = Date.now();
|
|
1453
|
+
const duration = endTime - startTime;
|
|
1454
|
+
const responseHeaders = {};
|
|
1455
|
+
if (res.headers) {
|
|
1456
|
+
for (const [key, value] of Object.entries(res.headers)) {
|
|
1457
|
+
if (value) {
|
|
1458
|
+
responseHeaders[key.toLowerCase()] = Array.isArray(value) ? value.join(", ") : value;
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const contentType = responseHeaders["content-type"] || "";
|
|
1463
|
+
let responseBodyStr;
|
|
1464
|
+
if (responseChunks.length > 0) {
|
|
1465
|
+
if (isBinaryContentType(contentType)) {
|
|
1466
|
+
responseBodyStr = `[Binary Data: ${contentType}]`;
|
|
1467
|
+
} else {
|
|
1468
|
+
const full = Buffer.concat(responseChunks);
|
|
1469
|
+
responseBodyStr = full.length > MAX_BODY_SIZE ? full.toString("utf-8", 0, MAX_BODY_SIZE) + "...[truncated]" : full.toString("utf-8");
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
const responseBody = serializeBody(
|
|
1473
|
+
responseBodyStr,
|
|
1474
|
+
self2.config?.disableBodyCapture
|
|
1475
|
+
);
|
|
1476
|
+
const statusCode = res.statusCode ?? 0;
|
|
1477
|
+
let responseEvent = {
|
|
1478
|
+
id: requestId,
|
|
1479
|
+
traceId,
|
|
1480
|
+
sessionId: self2.getSessionId(),
|
|
1481
|
+
timestamp: endTime,
|
|
1482
|
+
phase: "RESPONSE" /* RESPONSE */,
|
|
1483
|
+
networkType: "http" /* HTTP */,
|
|
1484
|
+
status: statusCode,
|
|
1485
|
+
statusText: res.statusMessage || "",
|
|
1486
|
+
headers: redactSensitiveHeaders(responseHeaders),
|
|
1487
|
+
body: responseBody,
|
|
1488
|
+
duration,
|
|
1489
|
+
responseSize: responseBody?.size ?? 0,
|
|
1490
|
+
redirected: false,
|
|
1491
|
+
ok: statusCode >= 200 && statusCode < 300
|
|
1492
|
+
};
|
|
1493
|
+
if (self2.config?.beforeSend) {
|
|
1494
|
+
const modifiedEvent = self2.config.beforeSend(responseEvent);
|
|
1495
|
+
if (!modifiedEvent) return;
|
|
1496
|
+
if (modifiedEvent.phase !== "RESPONSE" /* RESPONSE */) {
|
|
1497
|
+
console.error("[Limelight] beforeSend must return same event type");
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
responseEvent = modifiedEvent;
|
|
1501
|
+
}
|
|
1502
|
+
self2.sendMessage(responseEvent);
|
|
1503
|
+
});
|
|
1504
|
+
});
|
|
1505
|
+
req.on("error", (err) => {
|
|
1506
|
+
if (responseSent) return;
|
|
1507
|
+
responseSent = true;
|
|
1508
|
+
let errorEvent = {
|
|
1509
|
+
id: requestId,
|
|
1510
|
+
traceId,
|
|
1511
|
+
sessionId: self2.getSessionId(),
|
|
1512
|
+
timestamp: Date.now(),
|
|
1513
|
+
phase: "ERROR" /* ERROR */,
|
|
1514
|
+
networkType: "http" /* HTTP */,
|
|
1515
|
+
errorMessage: err.message || "Network request failed",
|
|
1516
|
+
stack: err.stack
|
|
1517
|
+
};
|
|
1518
|
+
if (self2.config?.beforeSend) {
|
|
1519
|
+
const modifiedEvent = self2.config.beforeSend(errorEvent);
|
|
1520
|
+
if (modifiedEvent && (modifiedEvent.phase === "ERROR" /* ERROR */ || modifiedEvent.phase === "ABORT" /* ABORT */)) {
|
|
1521
|
+
errorEvent = modifiedEvent;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
self2.sendMessage(errorEvent);
|
|
1525
|
+
});
|
|
1526
|
+
req.on("timeout", () => {
|
|
1527
|
+
if (responseSent) return;
|
|
1528
|
+
responseSent = true;
|
|
1529
|
+
let errorEvent = {
|
|
1530
|
+
id: requestId,
|
|
1531
|
+
traceId,
|
|
1532
|
+
sessionId: self2.getSessionId(),
|
|
1533
|
+
timestamp: Date.now(),
|
|
1534
|
+
phase: "ERROR" /* ERROR */,
|
|
1535
|
+
networkType: "http" /* HTTP */,
|
|
1536
|
+
errorMessage: "Request timeout"
|
|
1537
|
+
};
|
|
1538
|
+
if (self2.config?.beforeSend) {
|
|
1539
|
+
const modifiedEvent = self2.config.beforeSend(errorEvent);
|
|
1540
|
+
if (modifiedEvent && (modifiedEvent.phase === "ERROR" /* ERROR */ || modifiedEvent.phase === "ABORT" /* ABORT */)) {
|
|
1541
|
+
errorEvent = modifiedEvent;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
self2.sendMessage(errorEvent);
|
|
1545
|
+
});
|
|
1546
|
+
req.on("close", () => {
|
|
1547
|
+
if (responseSent) return;
|
|
1548
|
+
if (!req.destroyed) return;
|
|
1549
|
+
responseSent = true;
|
|
1550
|
+
let errorEvent = {
|
|
1551
|
+
id: requestId,
|
|
1552
|
+
traceId,
|
|
1553
|
+
sessionId: self2.getSessionId(),
|
|
1554
|
+
timestamp: Date.now(),
|
|
1555
|
+
phase: "ABORT" /* ABORT */,
|
|
1556
|
+
networkType: "http" /* HTTP */,
|
|
1557
|
+
errorMessage: "Request aborted"
|
|
1558
|
+
};
|
|
1559
|
+
if (self2.config?.beforeSend) {
|
|
1560
|
+
const modifiedEvent = self2.config.beforeSend(errorEvent);
|
|
1561
|
+
if (modifiedEvent && (modifiedEvent.phase === "ERROR" /* ERROR */ || modifiedEvent.phase === "ABORT" /* ABORT */)) {
|
|
1562
|
+
errorEvent = modifiedEvent;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
self2.sendMessage(errorEvent);
|
|
1566
|
+
});
|
|
1567
|
+
return req;
|
|
1568
|
+
}
|
|
1569
|
+
cleanup() {
|
|
1570
|
+
if (!this.isSetup) {
|
|
1571
|
+
if (this.config?.enableInternalLogging) {
|
|
1572
|
+
console.warn("[Limelight] HTTP interceptor not set up");
|
|
1573
|
+
}
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
this.isSetup = false;
|
|
1577
|
+
if (this.httpModule && this.originalHttpRequest) {
|
|
1578
|
+
this.httpModule.request = this.originalHttpRequest;
|
|
1579
|
+
}
|
|
1580
|
+
if (this.httpModule && this.originalHttpGet) {
|
|
1581
|
+
this.httpModule.get = this.originalHttpGet;
|
|
1582
|
+
}
|
|
1583
|
+
if (this.httpsModule && this.originalHttpsRequest) {
|
|
1584
|
+
this.httpsModule.request = this.originalHttpsRequest;
|
|
1585
|
+
}
|
|
1586
|
+
if (this.httpsModule && this.originalHttpsGet) {
|
|
1587
|
+
this.httpsModule.get = this.originalHttpsGet;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1208
1592
|
// src/limelight/interceptors/RenderInterceptor.ts
|
|
1209
1593
|
var RenderInterceptor = class {
|
|
1210
1594
|
sendMessage;
|
|
@@ -2574,6 +2958,7 @@ var LimelightClient = class {
|
|
|
2574
2958
|
maxQueueSize = 100;
|
|
2575
2959
|
networkInterceptor;
|
|
2576
2960
|
xhrInterceptor;
|
|
2961
|
+
httpInterceptor;
|
|
2577
2962
|
consoleInterceptor;
|
|
2578
2963
|
renderInterceptor;
|
|
2579
2964
|
stateInterceptor;
|
|
@@ -2589,6 +2974,10 @@ var LimelightClient = class {
|
|
|
2589
2974
|
this.sendMessage.bind(this),
|
|
2590
2975
|
() => this.sessionId
|
|
2591
2976
|
);
|
|
2977
|
+
this.httpInterceptor = new HttpInterceptor(
|
|
2978
|
+
this.sendMessage.bind(this),
|
|
2979
|
+
() => this.sessionId
|
|
2980
|
+
);
|
|
2592
2981
|
this.consoleInterceptor = new ConsoleInterceptor(
|
|
2593
2982
|
this.sendMessage.bind(this),
|
|
2594
2983
|
() => this.sessionId
|
|
@@ -2649,6 +3038,9 @@ var LimelightClient = class {
|
|
|
2649
3038
|
if (typeof XMLHttpRequest !== "undefined") {
|
|
2650
3039
|
this.xhrInterceptor.setup(this.config);
|
|
2651
3040
|
}
|
|
3041
|
+
if (!hasDOM()) {
|
|
3042
|
+
this.httpInterceptor.setup(this.config);
|
|
3043
|
+
}
|
|
2652
3044
|
}
|
|
2653
3045
|
if (this.config.enableConsole) {
|
|
2654
3046
|
this.consoleInterceptor.setup(this.config);
|
|
@@ -2874,6 +3266,7 @@ var LimelightClient = class {
|
|
|
2874
3266
|
}
|
|
2875
3267
|
this.networkInterceptor.cleanup();
|
|
2876
3268
|
this.xhrInterceptor.cleanup();
|
|
3269
|
+
this.httpInterceptor.cleanup();
|
|
2877
3270
|
this.consoleInterceptor.cleanup();
|
|
2878
3271
|
this.errorInterceptor.cleanup();
|
|
2879
3272
|
this.renderInterceptor.cleanup();
|