@testsmith/api-spector-agent 0.8.3 → 0.8.5
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 +76 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -74228,9 +74228,14 @@ async function getSecret(ref) {
|
|
|
74228
74228
|
return process.env[ref] ?? null;
|
|
74229
74229
|
}
|
|
74230
74230
|
|
|
74231
|
+
// src/shared/url-params.ts
|
|
74232
|
+
var PATH_PARAM_PATTERN = String.raw`\[([A-Za-z_]\w*)\]|(?<!\{)\{([A-Za-z_]\w*)\}(?!\})`;
|
|
74233
|
+
var PATH_PARAM_RE = new RegExp(PATH_PARAM_PATTERN, "g");
|
|
74234
|
+
|
|
74231
74235
|
// src/main/interpolation.ts
|
|
74232
74236
|
var import_dayjs2 = __toESM(require_dayjs_min());
|
|
74233
74237
|
var vm = __toESM(require("node:vm"));
|
|
74238
|
+
var PATH_PARAM_RE2 = new RegExp(PATH_PARAM_PATTERN, "g");
|
|
74234
74239
|
var _fakerCache = null;
|
|
74235
74240
|
async function getFaker() {
|
|
74236
74241
|
_fakerCache ??= await Promise.resolve().then(() => (init_dist(), dist_exports));
|
|
@@ -74286,8 +74291,8 @@ function buildUrl(baseUrl, params, vars) {
|
|
|
74286
74291
|
templateTokens.add(String(name).trim());
|
|
74287
74292
|
return "";
|
|
74288
74293
|
});
|
|
74289
|
-
baseUrl.replaceAll(
|
|
74290
|
-
templateTokens.add(
|
|
74294
|
+
baseUrl.replaceAll(PATH_PARAM_RE2, (_m, g1, g22) => {
|
|
74295
|
+
templateTokens.add(g1 ?? g22);
|
|
74291
74296
|
return "";
|
|
74292
74297
|
});
|
|
74293
74298
|
const enabled = (params ?? []).filter((p6) => p6.enabled && p6.key);
|
|
@@ -74303,7 +74308,10 @@ function buildUrl(baseUrl, params, vars) {
|
|
|
74303
74308
|
...Object.fromEntries(pathRows.map((p6) => [p6.key, interpolate(p6.value, vars)]))
|
|
74304
74309
|
} : vars;
|
|
74305
74310
|
let url2 = interpolate(baseUrl, mergedVars);
|
|
74306
|
-
url2 = url2.replaceAll(
|
|
74311
|
+
url2 = url2.replaceAll(PATH_PARAM_RE2, (m6, g1, g22) => {
|
|
74312
|
+
const name = g1 ?? g22;
|
|
74313
|
+
return name in mergedVars ? mergedVars[name] : m6;
|
|
74314
|
+
});
|
|
74307
74315
|
if (!queryRows.length) return url2;
|
|
74308
74316
|
const sep = url2.includes("?") ? "&" : "?";
|
|
74309
74317
|
const qs = queryRows.map((p6) => `${encodeURIComponent(interpolate(p6.key, vars))}=${encodeURIComponent(interpolate(p6.value, vars))}`).join("&");
|
|
@@ -74334,6 +74342,65 @@ function mergeVars(envVars, collectionVars, globals2, localVars = {}, dynamicVar
|
|
|
74334
74342
|
return out;
|
|
74335
74343
|
}
|
|
74336
74344
|
|
|
74345
|
+
// src/shared/strip-json-comments.ts
|
|
74346
|
+
function jsonCommentRanges(input) {
|
|
74347
|
+
const ranges = [];
|
|
74348
|
+
const n5 = input.length;
|
|
74349
|
+
let i79 = 0;
|
|
74350
|
+
let inString = false;
|
|
74351
|
+
while (i79 < n5) {
|
|
74352
|
+
const c8 = input[i79];
|
|
74353
|
+
if (inString) {
|
|
74354
|
+
if (c8 === "\\") {
|
|
74355
|
+
i79 += 2;
|
|
74356
|
+
continue;
|
|
74357
|
+
}
|
|
74358
|
+
if (c8 === '"') inString = false;
|
|
74359
|
+
i79++;
|
|
74360
|
+
continue;
|
|
74361
|
+
}
|
|
74362
|
+
if (c8 === '"') {
|
|
74363
|
+
inString = true;
|
|
74364
|
+
i79++;
|
|
74365
|
+
continue;
|
|
74366
|
+
}
|
|
74367
|
+
const next = input[i79 + 1];
|
|
74368
|
+
if (c8 === "/" && next === "/") {
|
|
74369
|
+
const from = i79;
|
|
74370
|
+
i79 += 2;
|
|
74371
|
+
while (i79 < n5 && input[i79] !== "\n") i79++;
|
|
74372
|
+
ranges.push({ from, to: i79, type: "line" });
|
|
74373
|
+
continue;
|
|
74374
|
+
}
|
|
74375
|
+
if (c8 === "/" && next === "*") {
|
|
74376
|
+
const from = i79;
|
|
74377
|
+
i79 += 2;
|
|
74378
|
+
while (i79 < n5 && !(input[i79] === "*" && input[i79 + 1] === "/")) i79++;
|
|
74379
|
+
i79 = Math.min(i79 + 2, n5);
|
|
74380
|
+
ranges.push({ from, to: i79, type: "block" });
|
|
74381
|
+
continue;
|
|
74382
|
+
}
|
|
74383
|
+
i79++;
|
|
74384
|
+
}
|
|
74385
|
+
return ranges;
|
|
74386
|
+
}
|
|
74387
|
+
function stripJsonComments(input) {
|
|
74388
|
+
const ranges = jsonCommentRanges(input);
|
|
74389
|
+
if (!ranges.length) return input;
|
|
74390
|
+
let out = "";
|
|
74391
|
+
let pos = 0;
|
|
74392
|
+
for (const r63 of ranges) {
|
|
74393
|
+
out += input.slice(pos, r63.from);
|
|
74394
|
+
if (r63.type === "block") {
|
|
74395
|
+
const seg = input.slice(r63.from, r63.to);
|
|
74396
|
+
for (let k2 = 0; k2 < seg.length; k2++) if (seg[k2] === "\n") out += "\n";
|
|
74397
|
+
}
|
|
74398
|
+
pos = r63.to;
|
|
74399
|
+
}
|
|
74400
|
+
out += input.slice(pos);
|
|
74401
|
+
return out;
|
|
74402
|
+
}
|
|
74403
|
+
|
|
74337
74404
|
// src/main/script-runner.ts
|
|
74338
74405
|
var vm3 = __toESM(require("node:vm"));
|
|
74339
74406
|
var crypto = __toESM(require("node:crypto"));
|
|
@@ -80782,7 +80849,7 @@ async function buildDispatcher(proxy, tls) {
|
|
|
80782
80849
|
function buildBodyAndApplyHeaders(req, vars, headers) {
|
|
80783
80850
|
let body;
|
|
80784
80851
|
if (req.body.mode === "json" && req.body.json) {
|
|
80785
|
-
body = interpolate(req.body.json, vars);
|
|
80852
|
+
body = interpolate(stripJsonComments(req.body.json), vars);
|
|
80786
80853
|
if (!headers.has("content-type")) headers.set("Content-Type", "application/json");
|
|
80787
80854
|
} else if (req.body.mode === "form" && req.body.form) {
|
|
80788
80855
|
body = req.body.form.filter((p6) => p6.enabled && p6.key).map((p6) => `${encodeURIComponent(interpolate(p6.key, vars))}=${encodeURIComponent(interpolate(p6.value, vars))}`).join("&");
|
|
@@ -80796,7 +80863,7 @@ function buildBodyAndApplyHeaders(req, vars, headers) {
|
|
|
80796
80863
|
const rawVars = gql.variables?.trim();
|
|
80797
80864
|
if (rawVars) {
|
|
80798
80865
|
try {
|
|
80799
|
-
gqlBody.variables = JSON.parse(interpolate(rawVars, vars));
|
|
80866
|
+
gqlBody.variables = JSON.parse(interpolate(stripJsonComments(rawVars), vars));
|
|
80800
80867
|
} catch {
|
|
80801
80868
|
}
|
|
80802
80869
|
}
|
|
@@ -80955,6 +81022,9 @@ async function executeRunnerRequest(opts) {
|
|
|
80955
81022
|
status: "running"
|
|
80956
81023
|
};
|
|
80957
81024
|
const dynamicVars = await buildDynamicVars();
|
|
81025
|
+
if (req.variables && Object.keys(req.variables).length > 0) {
|
|
81026
|
+
localVars = { ...req.variables, ...localVars };
|
|
81027
|
+
}
|
|
80958
81028
|
if (localVars && Object.keys(localVars).length > 0) {
|
|
80959
81029
|
localVars = resolveDataRow(localVars, mergeVars(envVars, collectionVars, globals2, {}, dynamicVars, folderVars));
|
|
80960
81030
|
}
|
|
@@ -81364,7 +81434,7 @@ var APP_URL = (process.env.APP_URL || "").replace(/\/+$/, "");
|
|
|
81364
81434
|
var AGENT_TOKEN = process.env.AGENT_TOKEN || "";
|
|
81365
81435
|
var RUNTIME_TOKEN = process.env.RUNTIME_TOKEN || "";
|
|
81366
81436
|
var POLL_MS = Number(process.env.POLL_INTERVAL_MS || 5e3);
|
|
81367
|
-
var VERSION = true ? "0.8.
|
|
81437
|
+
var VERSION = true ? "0.8.5" : "";
|
|
81368
81438
|
var authHeaders = AGENT_TOKEN ? { Authorization: `Bearer ${AGENT_TOKEN}` } : RUNTIME_TOKEN ? { "X-Runtime-Token": RUNTIME_TOKEN } : {};
|
|
81369
81439
|
async function postResult(m6, fields) {
|
|
81370
81440
|
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.8.
|
|
3
|
+
"version": "0.8.5",
|
|
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",
|