@testsmith/api-spector-agent 0.7.2 → 0.7.3
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 +186 -18
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46913,22 +46913,7 @@ function buildAt(ctx, testResults, consoleOutput) {
|
|
|
46913
46913
|
}
|
|
46914
46914
|
return sp;
|
|
46915
46915
|
}
|
|
46916
|
-
|
|
46917
|
-
const faker = await getFaker2();
|
|
46918
|
-
const testResults = [];
|
|
46919
|
-
const consoleOutput = [];
|
|
46920
|
-
const envVarsCopy = { ...ctx.envVars };
|
|
46921
|
-
const collectionCopy = { ...ctx.collectionVars };
|
|
46922
|
-
const globalsCopy = { ...ctx.globals };
|
|
46923
|
-
const localVarsCopy = { ...ctx.localVars };
|
|
46924
|
-
const scriptCtx = {
|
|
46925
|
-
envVars: envVarsCopy,
|
|
46926
|
-
collectionVars: collectionCopy,
|
|
46927
|
-
globals: globalsCopy,
|
|
46928
|
-
localVars: localVarsCopy,
|
|
46929
|
-
response: ctx.response,
|
|
46930
|
-
piiMaskPatterns: ctx.piiMaskPatterns
|
|
46931
|
-
};
|
|
46916
|
+
function buildSandbox(scriptCtx, testResults, consoleOutput, faker) {
|
|
46932
46917
|
const sp = buildAt(scriptCtx, testResults, consoleOutput);
|
|
46933
46918
|
const captureConsole = {
|
|
46934
46919
|
log: (...args) => consoleOutput.push(args.map(String).join(" ")),
|
|
@@ -46936,8 +46921,9 @@ async function runScript(code, ctx, timeoutMs = 5e3) {
|
|
|
46936
46921
|
error: (...args) => consoleOutput.push("[error] " + args.map(String).join(" ")),
|
|
46937
46922
|
info: (...args) => consoleOutput.push("[info] " + args.map(String).join(" "))
|
|
46938
46923
|
};
|
|
46939
|
-
|
|
46924
|
+
return {
|
|
46940
46925
|
sp,
|
|
46926
|
+
data: scriptCtx.data ?? {},
|
|
46941
46927
|
DOMParser: makeSandboxDOMParser,
|
|
46942
46928
|
dayjs: import_dayjs3.default,
|
|
46943
46929
|
faker,
|
|
@@ -46959,6 +46945,24 @@ async function runScript(code, ctx, timeoutMs = 5e3) {
|
|
|
46959
46945
|
// not available in sync vm context
|
|
46960
46946
|
setInterval: void 0
|
|
46961
46947
|
};
|
|
46948
|
+
}
|
|
46949
|
+
async function runScript(code, ctx, timeoutMs = 5e3) {
|
|
46950
|
+
const faker = await getFaker2();
|
|
46951
|
+
const testResults = [];
|
|
46952
|
+
const consoleOutput = [];
|
|
46953
|
+
const envVarsCopy = { ...ctx.envVars };
|
|
46954
|
+
const collectionCopy = { ...ctx.collectionVars };
|
|
46955
|
+
const globalsCopy = { ...ctx.globals };
|
|
46956
|
+
const localVarsCopy = { ...ctx.localVars };
|
|
46957
|
+
const scriptCtx = {
|
|
46958
|
+
envVars: envVarsCopy,
|
|
46959
|
+
collectionVars: collectionCopy,
|
|
46960
|
+
globals: globalsCopy,
|
|
46961
|
+
localVars: localVarsCopy,
|
|
46962
|
+
response: ctx.response,
|
|
46963
|
+
piiMaskPatterns: ctx.piiMaskPatterns
|
|
46964
|
+
};
|
|
46965
|
+
const sandbox = buildSandbox(scriptCtx, testResults, consoleOutput, faker);
|
|
46962
46966
|
try {
|
|
46963
46967
|
vm3.runInNewContext(code, sandbox, { timeout: timeoutMs, filename: "script.js" });
|
|
46964
46968
|
} catch (err) {
|
|
@@ -47957,12 +47961,176 @@ async function executeRunnerRequest(opts) {
|
|
|
47957
47961
|
}
|
|
47958
47962
|
}
|
|
47959
47963
|
|
|
47964
|
+
// src/shared/flow-blocks.ts
|
|
47965
|
+
var IN = [{ id: "in" }];
|
|
47966
|
+
var OUT = () => [{ id: "out" }];
|
|
47967
|
+
var BLOCK_SPECS = {
|
|
47968
|
+
start: {
|
|
47969
|
+
type: "start",
|
|
47970
|
+
category: "terminal",
|
|
47971
|
+
label: "Start",
|
|
47972
|
+
description: "Where the flow begins.",
|
|
47973
|
+
inputs: [],
|
|
47974
|
+
outputs: OUT
|
|
47975
|
+
},
|
|
47976
|
+
end: {
|
|
47977
|
+
type: "end",
|
|
47978
|
+
category: "terminal",
|
|
47979
|
+
label: "End",
|
|
47980
|
+
description: "Ends this path of the flow.",
|
|
47981
|
+
inputs: IN,
|
|
47982
|
+
outputs: () => []
|
|
47983
|
+
},
|
|
47984
|
+
// ── Action ──────────────────────────────────────────────────────────────
|
|
47985
|
+
request: {
|
|
47986
|
+
type: "request",
|
|
47987
|
+
category: "action",
|
|
47988
|
+
label: "Send Request",
|
|
47989
|
+
description: "Send a saved request; routes success or fail on its response.",
|
|
47990
|
+
inputs: IN,
|
|
47991
|
+
outputs: () => [{ id: "success", label: "success" }, { id: "fail", label: "fail" }]
|
|
47992
|
+
},
|
|
47993
|
+
subflow: {
|
|
47994
|
+
type: "subflow",
|
|
47995
|
+
category: "action",
|
|
47996
|
+
label: "Run Flow",
|
|
47997
|
+
description: "Run another flow from this workspace.",
|
|
47998
|
+
inputs: IN,
|
|
47999
|
+
outputs: OUT
|
|
48000
|
+
},
|
|
48001
|
+
// ── Logic ───────────────────────────────────────────────────────────────
|
|
48002
|
+
if: {
|
|
48003
|
+
type: "if",
|
|
48004
|
+
category: "logic",
|
|
48005
|
+
label: "If",
|
|
48006
|
+
description: "Route to true or false based on a JS condition.",
|
|
48007
|
+
inputs: IN,
|
|
48008
|
+
outputs: () => [{ id: "true", label: "true" }, { id: "false", label: "false" }],
|
|
48009
|
+
defaultConfig: { expression: "sp.response.code === 200" }
|
|
48010
|
+
},
|
|
48011
|
+
condition: {
|
|
48012
|
+
type: "condition",
|
|
48013
|
+
category: "logic",
|
|
48014
|
+
label: "Condition",
|
|
48015
|
+
description: "Multi-way switch: the first matching case wins, else `else`.",
|
|
48016
|
+
inputs: IN,
|
|
48017
|
+
outputs: (config) => [
|
|
48018
|
+
...(config?.cases ?? []).map((c70) => ({ id: c70.id, label: c70.label })),
|
|
48019
|
+
{ id: "else", label: "else" }
|
|
48020
|
+
],
|
|
48021
|
+
defaultConfig: {
|
|
48022
|
+
cases: [
|
|
48023
|
+
{ id: "case1", label: "ok", expression: "sp.response.code < 400" }
|
|
48024
|
+
]
|
|
48025
|
+
}
|
|
48026
|
+
},
|
|
48027
|
+
validate: {
|
|
48028
|
+
type: "validate",
|
|
48029
|
+
category: "logic",
|
|
48030
|
+
label: "Validate",
|
|
48031
|
+
description: "Assert with sp.test(...); routes pass or fail.",
|
|
48032
|
+
inputs: IN,
|
|
48033
|
+
outputs: () => [{ id: "pass", label: "pass" }, { id: "fail", label: "fail" }],
|
|
48034
|
+
defaultConfig: {
|
|
48035
|
+
script: "sp.test('status is 2xx', () => {\n sp.expect(sp.response.code).to.be.below(300);\n});"
|
|
48036
|
+
}
|
|
48037
|
+
},
|
|
48038
|
+
evaluate: {
|
|
48039
|
+
type: "evaluate",
|
|
48040
|
+
category: "logic",
|
|
48041
|
+
label: "Evaluate",
|
|
48042
|
+
description: "Run JS to compute values and set variables.",
|
|
48043
|
+
inputs: IN,
|
|
48044
|
+
outputs: OUT,
|
|
48045
|
+
defaultConfig: { script: "// sp.variables.set('id', sp.response.json().id)" }
|
|
48046
|
+
},
|
|
48047
|
+
setVar: {
|
|
48048
|
+
type: "setVar",
|
|
48049
|
+
category: "logic",
|
|
48050
|
+
label: "Set Variable",
|
|
48051
|
+
description: "Set a variable from an expression, in a chosen scope.",
|
|
48052
|
+
inputs: IN,
|
|
48053
|
+
outputs: OUT,
|
|
48054
|
+
defaultConfig: { varName: "myVar", valueExpression: "sp.response.json()", scope: "local" }
|
|
48055
|
+
},
|
|
48056
|
+
delay: {
|
|
48057
|
+
type: "delay",
|
|
48058
|
+
category: "logic",
|
|
48059
|
+
label: "Delay",
|
|
48060
|
+
description: "Wait before continuing.",
|
|
48061
|
+
inputs: IN,
|
|
48062
|
+
outputs: OUT,
|
|
48063
|
+
defaultConfig: { delayMs: 1e3 }
|
|
48064
|
+
},
|
|
48065
|
+
merge: {
|
|
48066
|
+
type: "merge",
|
|
48067
|
+
category: "logic",
|
|
48068
|
+
label: "Or / Merge",
|
|
48069
|
+
description: "Continue as soon as any one incoming branch arrives.",
|
|
48070
|
+
inputs: IN,
|
|
48071
|
+
outputs: OUT
|
|
48072
|
+
},
|
|
48073
|
+
// ── Looping ─────────────────────────────────────────────────────────────
|
|
48074
|
+
forEach: {
|
|
48075
|
+
type: "forEach",
|
|
48076
|
+
category: "looping",
|
|
48077
|
+
label: "For Each",
|
|
48078
|
+
description: "Run the body once per item of a list; then continue on done.",
|
|
48079
|
+
inputs: IN,
|
|
48080
|
+
outputs: () => [{ id: "body", label: "body" }, { id: "done", label: "done" }],
|
|
48081
|
+
defaultConfig: { expression: "sp.response.json()", itemVar: "item", indexVar: "index" }
|
|
48082
|
+
},
|
|
48083
|
+
repeat: {
|
|
48084
|
+
type: "repeat",
|
|
48085
|
+
category: "looping",
|
|
48086
|
+
label: "Repeat",
|
|
48087
|
+
description: "Run the body a fixed number of times, then continue on done.",
|
|
48088
|
+
inputs: IN,
|
|
48089
|
+
outputs: () => [{ id: "body", label: "body" }, { id: "done", label: "done" }],
|
|
48090
|
+
defaultConfig: { count: 3, indexVar: "index" }
|
|
48091
|
+
},
|
|
48092
|
+
collect: {
|
|
48093
|
+
type: "collect",
|
|
48094
|
+
category: "looping",
|
|
48095
|
+
label: "Collect",
|
|
48096
|
+
description: "Append each iteration's value into a list variable.",
|
|
48097
|
+
inputs: IN,
|
|
48098
|
+
outputs: OUT,
|
|
48099
|
+
defaultConfig: { intoVar: "results" }
|
|
48100
|
+
},
|
|
48101
|
+
// ── Visualize ───────────────────────────────────────────────────────────
|
|
48102
|
+
display: {
|
|
48103
|
+
type: "display",
|
|
48104
|
+
category: "visualize",
|
|
48105
|
+
label: "Display",
|
|
48106
|
+
description: "Show a value in the run results (text, JSON or table).",
|
|
48107
|
+
inputs: IN,
|
|
48108
|
+
outputs: OUT,
|
|
48109
|
+
defaultConfig: { message: "sp.response.json()", as: "json" }
|
|
48110
|
+
},
|
|
48111
|
+
log: {
|
|
48112
|
+
type: "log",
|
|
48113
|
+
category: "visualize",
|
|
48114
|
+
label: "Log",
|
|
48115
|
+
description: "Append a message to the run log.",
|
|
48116
|
+
inputs: IN,
|
|
48117
|
+
outputs: OUT,
|
|
48118
|
+
defaultConfig: { message: "Reached this point" }
|
|
48119
|
+
}
|
|
48120
|
+
};
|
|
48121
|
+
var BLOCKS_BY_CATEGORY = [
|
|
48122
|
+
{ category: "action", blocks: [BLOCK_SPECS.request, BLOCK_SPECS.subflow] },
|
|
48123
|
+
{ category: "logic", blocks: [BLOCK_SPECS.if, BLOCK_SPECS.condition, BLOCK_SPECS.validate, BLOCK_SPECS.evaluate, BLOCK_SPECS.setVar, BLOCK_SPECS.delay, BLOCK_SPECS.merge] },
|
|
48124
|
+
{ category: "looping", blocks: [BLOCK_SPECS.forEach, BLOCK_SPECS.repeat, BLOCK_SPECS.collect] },
|
|
48125
|
+
{ category: "visualize", blocks: [BLOCK_SPECS.display, BLOCK_SPECS.log] }
|
|
48126
|
+
];
|
|
48127
|
+
|
|
47960
48128
|
// src/agent/index.ts
|
|
47961
48129
|
var APP_URL = (process.env.APP_URL || "").replace(/\/+$/, "");
|
|
47962
48130
|
var AGENT_TOKEN = process.env.AGENT_TOKEN || "";
|
|
47963
48131
|
var RUNTIME_TOKEN = process.env.RUNTIME_TOKEN || "";
|
|
47964
48132
|
var POLL_MS = Number(process.env.POLL_INTERVAL_MS || 5e3);
|
|
47965
|
-
var VERSION = true ? "0.7.
|
|
48133
|
+
var VERSION = true ? "0.7.3" : "";
|
|
47966
48134
|
var authHeaders = AGENT_TOKEN ? { Authorization: `Bearer ${AGENT_TOKEN}` } : RUNTIME_TOKEN ? { "X-Runtime-Token": RUNTIME_TOKEN } : {};
|
|
47967
48135
|
async function postResult(m75, fields) {
|
|
47968
48136
|
await fetch(`${APP_URL}/api/monitor-runtime/${m75.id}/result`, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testsmith/api-spector-agent",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
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",
|