@testsmith/api-spector-agent 0.8.9 → 0.9.1
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 +37 -22
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -73627,20 +73627,21 @@ function readFileTrim(path) {
|
|
|
73627
73627
|
}
|
|
73628
73628
|
function resolveConn() {
|
|
73629
73629
|
const cfg = getSecretsConfig()?.vault ?? {};
|
|
73630
|
-
const address = env("VAULT_ADDR", "API_SPECTOR_VAULT_ADDR") ?? cfg.address;
|
|
73630
|
+
const address = env("VAULT_ADDR", "BAO_ADDR", "API_SPECTOR_VAULT_ADDR") ?? cfg.address;
|
|
73631
73631
|
if (!address) {
|
|
73632
|
-
throw new Error("Vault is not configured: set VAULT_ADDR (or settings.secrets.vault.address)");
|
|
73633
|
-
}
|
|
73634
|
-
const token = env("VAULT_TOKEN", "API_SPECTOR_VAULT_TOKEN") ?? readFileTrim((0, import_node_path.join)((0, import_node_os.homedir)(), ".vault-token"));
|
|
73635
|
-
const roleId = env("VAULT_ROLE_ID", "API_SPECTOR_VAULT_ROLE_ID") ?? cfg.roleId;
|
|
73636
|
-
const secretId = env("VAULT_SECRET_ID", "API_SPECTOR_VAULT_SECRET_ID");
|
|
73637
|
-
const
|
|
73638
|
-
const
|
|
73639
|
-
const
|
|
73632
|
+
throw new Error("Vault/OpenBao is not configured: set VAULT_ADDR or BAO_ADDR (or settings.secrets.vault.address)");
|
|
73633
|
+
}
|
|
73634
|
+
const token = env("VAULT_TOKEN", "BAO_TOKEN", "API_SPECTOR_VAULT_TOKEN") ?? readFileTrim((0, import_node_path.join)((0, import_node_os.homedir)(), ".vault-token")) ?? readFileTrim((0, import_node_path.join)((0, import_node_os.homedir)(), ".bao-token"));
|
|
73635
|
+
const roleId = env("VAULT_ROLE_ID", "BAO_ROLE_ID", "API_SPECTOR_VAULT_ROLE_ID") ?? cfg.roleId;
|
|
73636
|
+
const secretId = env("VAULT_SECRET_ID", "BAO_SECRET_ID", "API_SPECTOR_VAULT_SECRET_ID");
|
|
73637
|
+
const jwtPath = env("VAULT_JWT_PATH", "BAO_JWT_PATH", "API_SPECTOR_VAULT_JWT_PATH");
|
|
73638
|
+
const jwt = env("VAULT_JWT", "BAO_JWT", "API_SPECTOR_VAULT_JWT") ?? (jwtPath ? readFileTrim(jwtPath) : void 0);
|
|
73639
|
+
const jwtRole = env("VAULT_JWT_ROLE", "BAO_JWT_ROLE", "API_SPECTOR_VAULT_JWT_ROLE") ?? cfg.jwtRole;
|
|
73640
|
+
const explicit = env("VAULT_AUTH_METHOD", "BAO_AUTH_METHOD", "API_SPECTOR_VAULT_AUTH_METHOD") ?? cfg.authMethod;
|
|
73640
73641
|
const authMethod = explicit ?? (token ? "token" : roleId ? "approle" : jwt ? "jwt" : "token");
|
|
73641
73642
|
return {
|
|
73642
73643
|
address: address.replace(/\/+$/, ""),
|
|
73643
|
-
namespace: env("VAULT_NAMESPACE", "API_SPECTOR_VAULT_NAMESPACE") ?? cfg.namespace,
|
|
73644
|
+
namespace: env("VAULT_NAMESPACE", "BAO_NAMESPACE", "API_SPECTOR_VAULT_NAMESPACE") ?? cfg.namespace,
|
|
73644
73645
|
authMethod,
|
|
73645
73646
|
token,
|
|
73646
73647
|
roleId,
|
|
@@ -73648,9 +73649,9 @@ function resolveConn() {
|
|
|
73648
73649
|
jwt,
|
|
73649
73650
|
jwtRole,
|
|
73650
73651
|
loginMount: cfg.loginMount,
|
|
73651
|
-
kvVersion: env("VAULT_KV_VERSION", "API_SPECTOR_VAULT_KV_VERSION") ?? cfg.kvVersion ?? "auto",
|
|
73652
|
-
skipVerify: (env("VAULT_SKIP_VERIFY", "API_SPECTOR_VAULT_SKIP_VERIFY") ?? "").toLowerCase() === "true" || cfg.skipVerify === true,
|
|
73653
|
-
caPath: env("VAULT_CACERT", "API_SPECTOR_VAULT_CACERT")
|
|
73652
|
+
kvVersion: env("VAULT_KV_VERSION", "BAO_KV_VERSION", "API_SPECTOR_VAULT_KV_VERSION") ?? cfg.kvVersion ?? "auto",
|
|
73653
|
+
skipVerify: (env("VAULT_SKIP_VERIFY", "BAO_SKIP_VERIFY", "API_SPECTOR_VAULT_SKIP_VERIFY") ?? "").toLowerCase() === "true" || cfg.skipVerify === true,
|
|
73654
|
+
caPath: env("VAULT_CACERT", "BAO_CACERT", "API_SPECTOR_VAULT_CACERT")
|
|
73654
73655
|
};
|
|
73655
73656
|
}
|
|
73656
73657
|
var cachedToken = null;
|
|
@@ -73724,15 +73725,15 @@ async function clientToken(conn) {
|
|
|
73724
73725
|
cachedToken = { value: token, expiresAt: ttl > 0 ? now + ttl * 1e3 : now + 5 * 6e4 };
|
|
73725
73726
|
return token;
|
|
73726
73727
|
}
|
|
73727
|
-
async function readSecret(refBody) {
|
|
73728
|
+
async function readSecret(refBody, scheme) {
|
|
73728
73729
|
const hash = refBody.lastIndexOf("#");
|
|
73729
73730
|
if (hash < 0) {
|
|
73730
|
-
throw new Error(
|
|
73731
|
+
throw new Error(`${scheme} reference must be '${scheme}:<path>#<key>' (got '${scheme}:${refBody}')`);
|
|
73731
73732
|
}
|
|
73732
73733
|
const path = refBody.slice(0, hash).replace(/^\/+/, "");
|
|
73733
73734
|
const key = refBody.slice(hash + 1);
|
|
73734
73735
|
if (!path || !key) {
|
|
73735
|
-
throw new Error(
|
|
73736
|
+
throw new Error(`${scheme} reference must be '${scheme}:<path>#<key>' (got '${scheme}:${refBody}')`);
|
|
73736
73737
|
}
|
|
73737
73738
|
const conn = resolveConn();
|
|
73738
73739
|
const cacheKey = `${conn.address}|${conn.namespace ?? ""}|${path}`;
|
|
@@ -73757,7 +73758,11 @@ async function readSecret(refBody) {
|
|
|
73757
73758
|
}
|
|
73758
73759
|
var vaultProvider = {
|
|
73759
73760
|
scheme: "vault",
|
|
73760
|
-
resolve: (refBody) => readSecret(refBody)
|
|
73761
|
+
resolve: (refBody) => readSecret(refBody, "vault")
|
|
73762
|
+
};
|
|
73763
|
+
var openBaoProvider = {
|
|
73764
|
+
scheme: "bao",
|
|
73765
|
+
resolve: (refBody) => readSecret(refBody, "bao")
|
|
73761
73766
|
};
|
|
73762
73767
|
|
|
73763
73768
|
// src/main/secrets/providers/sigv4.ts
|
|
@@ -74195,6 +74200,7 @@ var gcpSecretManagerProvider = {
|
|
|
74195
74200
|
|
|
74196
74201
|
// src/main/secrets/index.ts
|
|
74197
74202
|
registerSecretProvider(vaultProvider);
|
|
74203
|
+
registerSecretProvider(openBaoProvider);
|
|
74198
74204
|
registerSecretProvider(awsSecretsProvider);
|
|
74199
74205
|
registerSecretProvider(azureKeyVaultProvider);
|
|
74200
74206
|
registerSecretProvider(onePasswordProvider);
|
|
@@ -74267,7 +74273,7 @@ async function buildDynamicVars() {
|
|
|
74267
74273
|
};
|
|
74268
74274
|
}
|
|
74269
74275
|
function interpolate(str, vars) {
|
|
74270
|
-
return str.replaceAll(/\{\{([^}]
|
|
74276
|
+
return str.replaceAll(/\{\{\s*((?:[^{}]|\{[^{}]*\})+?)\s*\}\}/g, (match, key) => {
|
|
74271
74277
|
const trimmed = key.trim();
|
|
74272
74278
|
if (trimmed in vars) return vars[trimmed];
|
|
74273
74279
|
if (_exprContext && (trimmed.includes(".") || trimmed.includes("("))) {
|
|
@@ -74287,7 +74293,7 @@ function resolveDataRow(row, scope) {
|
|
|
74287
74293
|
}
|
|
74288
74294
|
function buildUrl(baseUrl, params, vars) {
|
|
74289
74295
|
const templateTokens = /* @__PURE__ */ new Set();
|
|
74290
|
-
baseUrl.replaceAll(/\{\{([^}]
|
|
74296
|
+
baseUrl.replaceAll(/\{\{\s*((?:[^{}]|\{[^{}]*\})+?)\s*\}\}/g, (_m, name) => {
|
|
74291
74297
|
templateTokens.add(String(name).trim());
|
|
74292
74298
|
return "";
|
|
74293
74299
|
});
|
|
@@ -76318,10 +76324,11 @@ function buildAt(ctx, testResults, consoleOutput) {
|
|
|
76318
76324
|
fn2();
|
|
76319
76325
|
testResults.push({ name, passed: true });
|
|
76320
76326
|
} catch (err) {
|
|
76327
|
+
const line = scriptLineOf(err);
|
|
76321
76328
|
testResults.push({
|
|
76322
76329
|
name,
|
|
76323
76330
|
passed: false,
|
|
76324
|
-
error: err instanceof Error ? err.message : String(err)
|
|
76331
|
+
error: (err instanceof Error ? err.message : String(err)) + (line ? ` (line ${line})` : "")
|
|
76325
76332
|
});
|
|
76326
76333
|
}
|
|
76327
76334
|
},
|
|
@@ -76442,6 +76449,13 @@ function buildSandbox(scriptCtx, testResults, consoleOutput, faker) {
|
|
|
76442
76449
|
setInterval: void 0
|
|
76443
76450
|
};
|
|
76444
76451
|
}
|
|
76452
|
+
function scriptLineOf(err) {
|
|
76453
|
+
if (err instanceof Error && err.stack) {
|
|
76454
|
+
const m6 = err.stack.match(/script\.js:(\d+):\d+/);
|
|
76455
|
+
if (m6) return Number(m6[1]);
|
|
76456
|
+
}
|
|
76457
|
+
return void 0;
|
|
76458
|
+
}
|
|
76445
76459
|
async function runScript(code, ctx, timeoutMs = 5e3) {
|
|
76446
76460
|
const faker = await getFaker2();
|
|
76447
76461
|
const testResults = [];
|
|
@@ -76467,6 +76481,7 @@ async function runScript(code, ctx, timeoutMs = 5e3) {
|
|
|
76467
76481
|
try {
|
|
76468
76482
|
vm3.runInNewContext(code, sandbox, { timeout: timeoutMs, filename: "script.js" });
|
|
76469
76483
|
} catch (err) {
|
|
76484
|
+
const line = scriptLineOf(err);
|
|
76470
76485
|
const message = err instanceof Error ? err.message : String(err);
|
|
76471
76486
|
return {
|
|
76472
76487
|
testResults,
|
|
@@ -76476,7 +76491,7 @@ async function runScript(code, ctx, timeoutMs = 5e3) {
|
|
|
76476
76491
|
updatedGlobals: globalsCopy,
|
|
76477
76492
|
updatedLocalVars: localVarsCopy,
|
|
76478
76493
|
updatedFolderVars: folderCopy,
|
|
76479
|
-
error: message
|
|
76494
|
+
error: (line ? `Line ${line}: ` : "") + message
|
|
76480
76495
|
};
|
|
76481
76496
|
}
|
|
76482
76497
|
return {
|
|
@@ -81418,7 +81433,7 @@ var APP_URL = (process.env.APP_URL || "").replace(/\/+$/, "");
|
|
|
81418
81433
|
var AGENT_TOKEN = process.env.AGENT_TOKEN || "";
|
|
81419
81434
|
var RUNTIME_TOKEN = process.env.RUNTIME_TOKEN || "";
|
|
81420
81435
|
var POLL_MS = Number(process.env.POLL_INTERVAL_MS || 5e3);
|
|
81421
|
-
var VERSION = true ? "0.
|
|
81436
|
+
var VERSION = true ? "0.9.1" : "";
|
|
81422
81437
|
var authHeaders = AGENT_TOKEN ? { Authorization: `Bearer ${AGENT_TOKEN}` } : RUNTIME_TOKEN ? { "X-Runtime-Token": RUNTIME_TOKEN } : {};
|
|
81423
81438
|
async function postResult(m6, fields) {
|
|
81424
81439
|
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.
|
|
3
|
+
"version": "0.9.1",
|
|
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",
|