feat: add script dry-run functionality and enhance script management

- Introduced a new dry-run endpoint for executing scripts without saving changes.
- Implemented a dedicated ScriptDryRunPage for user interaction with dry-run functionality.
- Enhanced ScriptsPage to support navigation to the dry-run feature.
- Added LogViewer component for displaying logs during script execution.
- Created ScriptEditPage for editing scripts with integrated dry-run capabilities.
- Updated workflows to include new scripts for fetching and notifying data.
- Improved overall user experience with better navigation and error handling.
This commit is contained in:
2026-08-14 15:37:30 +07:00
parent 389f94f950
commit 8519c92ed1
17 changed files with 810 additions and 176 deletions
+20 -3
View File
@@ -291,6 +291,10 @@ function createScriptSandbox({ log, script, workflowName }) {
return sandbox;
}
function compileScriptSource(source, filename) {
return new vm.Script(wrapScriptSource(source, filename), { filename });
}
function loadCompiledScript(script) {
const filePath = path.join(SCRIPTS_DIR, script);
const { mtimeMs } = fs.statSync(filePath);
@@ -300,9 +304,7 @@ function loadCompiledScript(script) {
}
const source = fs.readFileSync(filePath, "utf8");
const compiled = new vm.Script(wrapScriptSource(source, script), {
filename: filePath,
});
const compiled = compileScriptSource(source, filePath);
scriptCache.set(script, { compiled, mtimeMs });
return compiled;
}
@@ -320,3 +322,18 @@ export async function runScript(script, ctx, { log, workflowName }) {
const fn = compiled.runInContext(sandbox);
return await fn(ctx);
}
/**
* Evaluate script source in memory (dry-run). Does not read from disk or use the disk cache.
*
* @param {string} script
* @param {string} source
* @param {unknown} ctx
* @param {{ log: import("pino").Logger, workflowName: string }} opts
*/
export async function runScriptSource(script, source, ctx, { log, workflowName }) {
const compiled = compileScriptSource(source, script);
const sandbox = createScriptSandbox({ log, script, workflowName });
const fn = compiled.runInContext(sandbox);
return await fn(ctx);
}