@testsmith/api-spector-agent 0.9.10 → 0.9.12
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/dist/index.cjs +94 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -58924,7 +58924,7 @@ var require_websocket2 = __commonJS({
|
|
|
58924
58924
|
var http = require("http");
|
|
58925
58925
|
var net = require("net");
|
|
58926
58926
|
var tls = require("tls");
|
|
58927
|
-
var { randomBytes, createHash: createHash2 } = require("crypto");
|
|
58927
|
+
var { randomBytes: randomBytes2, createHash: createHash2 } = require("crypto");
|
|
58928
58928
|
var { Duplex, Readable } = require("stream");
|
|
58929
58929
|
var { URL: URL2 } = require("url");
|
|
58930
58930
|
var PerMessageDeflate2 = require_permessage_deflate2();
|
|
@@ -59462,7 +59462,7 @@ var require_websocket2 = __commonJS({
|
|
|
59462
59462
|
}
|
|
59463
59463
|
}
|
|
59464
59464
|
const defaultPort = isSecure ? 443 : 80;
|
|
59465
|
-
const key =
|
|
59465
|
+
const key = randomBytes2(16).toString("base64");
|
|
59466
59466
|
const request = isSecure ? https.request : http.request;
|
|
59467
59467
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
59468
59468
|
let perMessageDeflate;
|
|
@@ -73401,6 +73401,8 @@ var import_xmldom = __toESM(require_lib());
|
|
|
73401
73401
|
// src/main/request-exec.ts
|
|
73402
73402
|
var import_undici = __toESM(require_undici());
|
|
73403
73403
|
var import_promises2 = require("fs/promises");
|
|
73404
|
+
var import_path = require("path");
|
|
73405
|
+
var import_crypto = require("crypto");
|
|
73404
73406
|
var nodeTls = __toESM(require("tls"));
|
|
73405
73407
|
|
|
73406
73408
|
// src/main/stream/parse.ts
|
|
@@ -80951,6 +80953,81 @@ async function buildDispatcher(proxy, tls) {
|
|
|
80951
80953
|
_dispatcherCache.set(key, dispatcher);
|
|
80952
80954
|
return dispatcher;
|
|
80953
80955
|
}
|
|
80956
|
+
var MIME_BY_EXT = {
|
|
80957
|
+
".json": "application/json",
|
|
80958
|
+
".xml": "application/xml",
|
|
80959
|
+
".txt": "text/plain",
|
|
80960
|
+
".csv": "text/csv",
|
|
80961
|
+
".html": "text/html",
|
|
80962
|
+
".pdf": "application/pdf",
|
|
80963
|
+
".png": "image/png",
|
|
80964
|
+
".jpg": "image/jpeg",
|
|
80965
|
+
".jpeg": "image/jpeg",
|
|
80966
|
+
".gif": "image/gif",
|
|
80967
|
+
".webp": "image/webp",
|
|
80968
|
+
".svg": "image/svg+xml",
|
|
80969
|
+
".zip": "application/zip",
|
|
80970
|
+
".gz": "application/gzip",
|
|
80971
|
+
".mp4": "video/mp4",
|
|
80972
|
+
".mp3": "audio/mpeg",
|
|
80973
|
+
".wav": "audio/wav",
|
|
80974
|
+
".doc": "application/msword",
|
|
80975
|
+
".xls": "application/vnd.ms-excel",
|
|
80976
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
80977
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
80978
|
+
".bin": "application/octet-stream"
|
|
80979
|
+
};
|
|
80980
|
+
function guessMultipartContentType(name) {
|
|
80981
|
+
return MIME_BY_EXT[(0, import_path.extname)(name).toLowerCase()] ?? "application/octet-stream";
|
|
80982
|
+
}
|
|
80983
|
+
function sanitizeFormName(s8) {
|
|
80984
|
+
return s8.replace(/"/g, "%22").replace(/[\r\n]/g, "");
|
|
80985
|
+
}
|
|
80986
|
+
async function buildMultipartBody(parts2, vars) {
|
|
80987
|
+
const boundary = `----APISpectorFormBoundary${(0, import_crypto.randomBytes)(16).toString("hex")}`;
|
|
80988
|
+
const chunks = [];
|
|
80989
|
+
const previewLines = [];
|
|
80990
|
+
for (const p6 of parts2) {
|
|
80991
|
+
if (!p6.enabled || !p6.key.trim()) continue;
|
|
80992
|
+
const name = sanitizeFormName(interpolate(p6.key, vars));
|
|
80993
|
+
chunks.push(Buffer.from(`--${boundary}\r
|
|
80994
|
+
`));
|
|
80995
|
+
if (p6.type === "file") {
|
|
80996
|
+
const path = interpolate(p6.filePath ?? "", vars).trim();
|
|
80997
|
+
let bytes;
|
|
80998
|
+
try {
|
|
80999
|
+
bytes = await (0, import_promises2.readFile)(path);
|
|
81000
|
+
} catch {
|
|
81001
|
+
throw new Error(`Multipart file not found or unreadable: ${path || "(no path set)"}`);
|
|
81002
|
+
}
|
|
81003
|
+
const filename = sanitizeFormName(interpolate(p6.fileName?.trim() || (0, import_path.basename)(path), vars));
|
|
81004
|
+
const ct2 = p6.contentType?.trim() || guessMultipartContentType(filename);
|
|
81005
|
+
chunks.push(Buffer.from(
|
|
81006
|
+
`Content-Disposition: form-data; name="${name}"; filename="${filename}"\r
|
|
81007
|
+
Content-Type: ${ct2}\r
|
|
81008
|
+
\r
|
|
81009
|
+
`
|
|
81010
|
+
));
|
|
81011
|
+
chunks.push(bytes);
|
|
81012
|
+
chunks.push(Buffer.from("\r\n"));
|
|
81013
|
+
previewLines.push(`${name}: <file ${path} (${ct2}, ${bytes.length} bytes)>`);
|
|
81014
|
+
} else {
|
|
81015
|
+
const value2 = interpolate(p6.value ?? "", vars);
|
|
81016
|
+
chunks.push(Buffer.from(`Content-Disposition: form-data; name="${name}"\r
|
|
81017
|
+
\r
|
|
81018
|
+
${value2}\r
|
|
81019
|
+
`));
|
|
81020
|
+
previewLines.push(`${name}: ${value2}`);
|
|
81021
|
+
}
|
|
81022
|
+
}
|
|
81023
|
+
chunks.push(Buffer.from(`--${boundary}--\r
|
|
81024
|
+
`));
|
|
81025
|
+
return {
|
|
81026
|
+
body: Buffer.concat(chunks),
|
|
81027
|
+
contentType: `multipart/form-data; boundary=${boundary}`,
|
|
81028
|
+
preview: previewLines.join("\n")
|
|
81029
|
+
};
|
|
81030
|
+
}
|
|
80954
81031
|
function buildBodyAndApplyHeaders(req, vars, headers) {
|
|
80955
81032
|
let body;
|
|
80956
81033
|
if (req.body.mode === "json" && req.body.json) {
|
|
@@ -81012,15 +81089,25 @@ async function performHttpExchange(opts) {
|
|
|
81012
81089
|
if (h6.enabled && h6.key) headers.set(interpolate(h6.key, vars), interpolate(h6.value, vars));
|
|
81013
81090
|
}
|
|
81014
81091
|
for (const [k2, v3] of Object.entries(authHeaders2)) headers.set(k2, v3);
|
|
81015
|
-
const body = buildBodyAndApplyHeaders(req, vars, headers);
|
|
81016
81092
|
const methodHasBody = !["GET", "HEAD"].includes(req.method);
|
|
81017
|
-
|
|
81093
|
+
let effectiveBody;
|
|
81094
|
+
let previewBody;
|
|
81095
|
+
if (methodHasBody && req.body.mode === "multipart" && req.body.multipart?.length) {
|
|
81096
|
+
const mp = await buildMultipartBody(req.body.multipart, vars);
|
|
81097
|
+
effectiveBody = mp.body;
|
|
81098
|
+
previewBody = mp.preview;
|
|
81099
|
+
if (!headers.has("content-type")) headers.set("Content-Type", mp.contentType);
|
|
81100
|
+
} else {
|
|
81101
|
+
const body = buildBodyAndApplyHeaders(req, vars, headers);
|
|
81102
|
+
effectiveBody = methodHasBody ? body : void 0;
|
|
81103
|
+
previewBody = typeof effectiveBody === "string" ? effectiveBody : void 0;
|
|
81104
|
+
}
|
|
81018
81105
|
const captureSent = (h6) => {
|
|
81019
81106
|
const captured = {};
|
|
81020
81107
|
h6.forEach((value2, key) => {
|
|
81021
81108
|
captured[key] = value2;
|
|
81022
81109
|
});
|
|
81023
|
-
onSent?.({ method: req.method, url: finalUrl, headers: captured, body:
|
|
81110
|
+
onSent?.({ method: req.method, url: finalUrl, headers: captured, body: previewBody });
|
|
81024
81111
|
return captured;
|
|
81025
81112
|
};
|
|
81026
81113
|
const doFetch = (h6) => (0, import_undici.fetch)(finalUrl, {
|
|
@@ -81084,7 +81171,7 @@ async function performHttpExchange(opts) {
|
|
|
81084
81171
|
responseBody,
|
|
81085
81172
|
durationMs: Date.now() - start,
|
|
81086
81173
|
sentHeaders,
|
|
81087
|
-
sentBody:
|
|
81174
|
+
sentBody: previewBody,
|
|
81088
81175
|
finalUrl,
|
|
81089
81176
|
...streamFields
|
|
81090
81177
|
};
|
|
@@ -81535,7 +81622,7 @@ var APP_URL = (process.env.APP_URL || "").replace(/\/+$/, "");
|
|
|
81535
81622
|
var AGENT_TOKEN = process.env.AGENT_TOKEN || "";
|
|
81536
81623
|
var RUNTIME_TOKEN = process.env.RUNTIME_TOKEN || "";
|
|
81537
81624
|
var POLL_MS = Number(process.env.POLL_INTERVAL_MS || 5e3);
|
|
81538
|
-
var VERSION = true ? "0.9.
|
|
81625
|
+
var VERSION = true ? "0.9.12" : "";
|
|
81539
81626
|
var authHeaders = AGENT_TOKEN ? { Authorization: `Bearer ${AGENT_TOKEN}` } : RUNTIME_TOKEN ? { "X-Runtime-Token": RUNTIME_TOKEN } : {};
|
|
81540
81627
|
async function postResult(m6, fields) {
|
|
81541
81628
|
await fetch(`${APP_URL}/api/monitor-runtime/${m6.id}/result`, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testsmith/api-spector-agent",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.12",
|
|
4
4
|
"description": "API Spector private runner: monitor internal/local APIs the cloud cannot reach, with no inbound connections.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://api-spector.dev",
|