@testsmith/api-spector-agent 0.9.12 → 0.9.14

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.
Files changed (2) hide show
  1. package/dist/index.cjs +22 -12
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -73671,6 +73671,10 @@ function getSecretsConfig() {
73671
73671
  }
73672
73672
 
73673
73673
  // src/main/secrets/providers/vault.ts
73674
+ function applyVars(str, vars) {
73675
+ if (!vars || !str.includes("{{")) return str;
73676
+ return str.replace(/\{\{\s*([\w.$-]+)\s*\}\}/g, (m6, name) => name in vars ? vars[name] : m6);
73677
+ }
73674
73678
  function env(...names) {
73675
73679
  for (const n5 of names) {
73676
73680
  const v3 = process.env[n5];
@@ -73702,6 +73706,7 @@ function resolveConn() {
73702
73706
  return {
73703
73707
  address: address.replace(/\/+$/, ""),
73704
73708
  namespace: env("VAULT_NAMESPACE", "BAO_NAMESPACE", "API_SPECTOR_VAULT_NAMESPACE") ?? cfg.namespace,
73709
+ pathPrefix: env("VAULT_PATH_PREFIX", "BAO_PATH_PREFIX", "API_SPECTOR_VAULT_PATH_PREFIX") ?? cfg.pathPrefix,
73705
73710
  authMethod,
73706
73711
  token,
73707
73712
  roleId,
@@ -73785,17 +73790,22 @@ async function clientToken(conn) {
73785
73790
  cachedToken = { value: token, expiresAt: ttl > 0 ? now + ttl * 1e3 : now + 5 * 6e4 };
73786
73791
  return token;
73787
73792
  }
73788
- async function readSecret(refBody, scheme) {
73793
+ async function readSecret(refBody, scheme, ctx = {}) {
73789
73794
  const hash = refBody.lastIndexOf("#");
73790
73795
  if (hash < 0) {
73791
73796
  throw new Error(`${scheme} reference must be '${scheme}:<path>#<key>' (got '${scheme}:${refBody}')`);
73792
73797
  }
73793
- const path = refBody.slice(0, hash).replace(/^\/+/, "");
73798
+ const rawPath = refBody.slice(0, hash);
73794
73799
  const key = refBody.slice(hash + 1);
73795
- if (!path || !key) {
73800
+ const absolute = /^\//.test(rawPath);
73801
+ const relPath = rawPath.replace(/^\/+/, "");
73802
+ if (!relPath || !key) {
73796
73803
  throw new Error(`${scheme} reference must be '${scheme}:<path>#<key>' (got '${scheme}:${refBody}')`);
73797
73804
  }
73798
73805
  const conn = resolveConn();
73806
+ const relResolved = applyVars(relPath, ctx.vars);
73807
+ const prefix = applyVars(conn.pathPrefix ?? "", ctx.vars).replace(/^\/+|\/+$/g, "");
73808
+ const path = !absolute && prefix ? `${prefix}/${relResolved}` : relResolved;
73799
73809
  const cacheKey = `${conn.address}|${conn.namespace ?? ""}|${path}`;
73800
73810
  const now = Date.now();
73801
73811
  let bag;
@@ -73818,11 +73828,11 @@ async function readSecret(refBody, scheme) {
73818
73828
  }
73819
73829
  var vaultProvider = {
73820
73830
  scheme: "vault",
73821
- resolve: (refBody) => readSecret(refBody, "vault")
73831
+ resolve: (refBody, ctx) => readSecret(refBody, "vault", ctx)
73822
73832
  };
73823
73833
  var openBaoProvider = {
73824
73834
  scheme: "bao",
73825
- resolve: (refBody) => readSecret(refBody, "bao")
73835
+ resolve: (refBody, ctx) => readSecret(refBody, "bao", ctx)
73826
73836
  };
73827
73837
 
73828
73838
  // src/main/secrets/providers/sigv4.ts
@@ -74383,7 +74393,7 @@ function buildUrl(baseUrl, params, vars) {
74383
74393
  const qs = queryRows.map((p6) => `${encodeURIComponent(interpolate(p6.key, vars))}=${encodeURIComponent(interpolate(p6.value, vars))}`).join("&");
74384
74394
  return url2 + sep + qs;
74385
74395
  }
74386
- async function resolveInlineSecretRefs(text) {
74396
+ async function resolveInlineSecretRefs(text, vars) {
74387
74397
  const refs = /* @__PURE__ */ new Set();
74388
74398
  for (const m6 of text.matchAll(/\{\{\s*([^}]+?)\s*\}\}/g)) {
74389
74399
  const inner = m6[1].trim();
@@ -74392,7 +74402,7 @@ async function resolveInlineSecretRefs(text) {
74392
74402
  if (refs.size === 0) return {};
74393
74403
  const out = {};
74394
74404
  await Promise.all([...refs].map(async (ref) => {
74395
- const value2 = await resolveExternalSecret(ref);
74405
+ const value2 = await resolveExternalSecret(ref, { vars });
74396
74406
  if (value2 !== null) out[ref] = value2;
74397
74407
  }));
74398
74408
  return out;
@@ -81064,7 +81074,7 @@ function buildBodyAndApplyHeaders(req, vars, headers) {
81064
81074
  async function performHttpExchange(opts) {
81065
81075
  const { req, resolvedUrl, dispatcher, proxy, tls, onSent } = opts;
81066
81076
  let vars = opts.vars;
81067
- const inlineSecrets = await resolveInlineSecrets(req);
81077
+ const inlineSecrets = await resolveInlineSecrets(req, vars);
81068
81078
  if (Object.keys(inlineSecrets).length) vars = { ...vars, ...inlineSecrets };
81069
81079
  const start = Date.now();
81070
81080
  if (req.auth.type === "oauth2") {
@@ -81189,7 +81199,7 @@ function syntheticHttpFailure(status, statusText) {
81189
81199
  error: `Request returned ${status} - no assertion was defined to verify the status code.`
81190
81200
  };
81191
81201
  }
81192
- async function resolveInlineSecrets(req) {
81202
+ async function resolveInlineSecrets(req, vars) {
81193
81203
  const haystack = [
81194
81204
  req.url ?? "",
81195
81205
  JSON.stringify(req.params ?? []),
@@ -81199,7 +81209,7 @@ async function resolveInlineSecrets(req) {
81199
81209
  req.preRequestScript ?? "",
81200
81210
  req.postRequestScript ?? ""
81201
81211
  ].join("\n");
81202
- return resolveInlineSecretRefs(haystack);
81212
+ return resolveInlineSecretRefs(haystack, vars);
81203
81213
  }
81204
81214
  async function executeRunnerRequest(opts) {
81205
81215
  const { req, collectionVars, envVars, globals, dispatcher, piiMaskPatterns, proxy, tls, onScriptOutput } = opts;
@@ -81313,7 +81323,7 @@ async function executeRunnerRequest(opts) {
81313
81323
  }
81314
81324
  let inlineSecrets = {};
81315
81325
  try {
81316
- inlineSecrets = await resolveInlineSecrets(req);
81326
+ inlineSecrets = await resolveInlineSecrets(req, vars);
81317
81327
  } catch (err) {
81318
81328
  return {
81319
81329
  result: {
@@ -81622,7 +81632,7 @@ var APP_URL = (process.env.APP_URL || "").replace(/\/+$/, "");
81622
81632
  var AGENT_TOKEN = process.env.AGENT_TOKEN || "";
81623
81633
  var RUNTIME_TOKEN = process.env.RUNTIME_TOKEN || "";
81624
81634
  var POLL_MS = Number(process.env.POLL_INTERVAL_MS || 5e3);
81625
- var VERSION = true ? "0.9.12" : "";
81635
+ var VERSION = true ? "0.9.14" : "";
81626
81636
  var authHeaders = AGENT_TOKEN ? { Authorization: `Bearer ${AGENT_TOKEN}` } : RUNTIME_TOKEN ? { "X-Runtime-Token": RUNTIME_TOKEN } : {};
81627
81637
  async function postResult(m6, fields) {
81628
81638
  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.12",
3
+ "version": "0.9.14",
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",