Quick fix for automation JS scripting, make sure context is passed through correctly.
This commit is contained in:
parent
f77acc1f1b
commit
6cad0e758f
|
@ -1,12 +1,12 @@
|
||||||
import ScriptRunner from "../../utilities/scriptRunner"
|
import ScriptRunner from "../../utilities/scriptRunner"
|
||||||
import { BBContext } from "@budibase/types"
|
import { Ctx } from "@budibase/types"
|
||||||
|
|
||||||
export async function execute(ctx: BBContext) {
|
export async function execute(ctx: Ctx) {
|
||||||
const { script, context } = ctx.request.body
|
const { script, context } = ctx.request.body
|
||||||
const runner = new ScriptRunner(script, context)
|
const runner = new ScriptRunner(script, context)
|
||||||
ctx.body = runner.execute()
|
ctx.body = runner.execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function save(ctx: BBContext) {
|
export async function save(ctx: Ctx) {
|
||||||
ctx.throw(501, "Not currently implemented")
|
ctx.throw(501, "Not currently implemented")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import ivm, { Context, Script } from "isolated-vm"
|
import ivm from "isolated-vm"
|
||||||
|
|
||||||
const JS_TIMEOUT_MS = 1000
|
const JS_TIMEOUT_MS = 1000
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ class ScriptRunner {
|
||||||
const code = `let fn = () => {\n${script}\n}; results.out = fn();`
|
const code = `let fn = () => {\n${script}\n}; results.out = fn();`
|
||||||
this.vm = new IsolatedVM({ memoryLimit: 8 })
|
this.vm = new IsolatedVM({ memoryLimit: 8 })
|
||||||
this.vm.context = {
|
this.vm.context = {
|
||||||
data: context.data,
|
...context,
|
||||||
params: context.params,
|
|
||||||
results: { out: "" },
|
results: { out: "" },
|
||||||
}
|
}
|
||||||
this.vm.code = code
|
this.vm.code = code
|
||||||
|
|
Loading…
Reference in New Issue