mirror of https://github.com/Budibase/budibase.git
nocodelowcodelow-codedockerdocker-composeinternal-projectinternal-toolinternal-toolslow-code-developmentlow-code-development-platformopensourceselfhostedweb-devweb-developmentweb-development-toolswebdevwebdevelopmentworkflow-automationautomationdeveloper-tools
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.4 KiB
70 lines
1.4 KiB
const scriptController = require("../../api/controllers/script")
|
|
const { buildCtx } = require("./utils")
|
|
const automationUtils = require("../automationUtils")
|
|
|
|
exports.definition = {
|
|
name: "JS Scripting",
|
|
tagline: "Execute JavaScript Code",
|
|
icon: "Code",
|
|
description: "Run a piece of JavaScript code in your automation",
|
|
type: "ACTION",
|
|
internal: true,
|
|
stepId: "EXECUTE_SCRIPT",
|
|
inputs: {},
|
|
schema: {
|
|
inputs: {
|
|
properties: {
|
|
code: {
|
|
type: "string",
|
|
customType: "code",
|
|
title: "Code",
|
|
},
|
|
},
|
|
required: ["code"],
|
|
},
|
|
outputs: {
|
|
properties: {
|
|
value: {
|
|
type: "string",
|
|
description: "The result of the return statement",
|
|
},
|
|
success: {
|
|
type: "boolean",
|
|
description: "Whether the action was successful",
|
|
},
|
|
},
|
|
},
|
|
required: ["success"],
|
|
},
|
|
}
|
|
|
|
exports.run = async function ({ inputs, appId, context, emitter }) {
|
|
if (inputs.code == null) {
|
|
return {
|
|
success: false,
|
|
response: {
|
|
message: "Invalid inputs",
|
|
},
|
|
}
|
|
}
|
|
|
|
const ctx = buildCtx(appId, emitter, {
|
|
body: {
|
|
script: inputs.code,
|
|
context,
|
|
},
|
|
})
|
|
|
|
try {
|
|
await scriptController.execute(ctx)
|
|
return {
|
|
success: true,
|
|
value: ctx.body,
|
|
}
|
|
} catch (err) {
|
|
return {
|
|
success: false,
|
|
response: automationUtils.getError(err),
|
|
}
|
|
}
|
|
}
|
|
|