Merge pull request #1739 from Budibase/fix/automation-scripts

Fixing automation JS scripts
This commit is contained in:
Michael Drury 2021-06-20 11:07:15 +01:00 committed by GitHub
commit 141cb1ac38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 5 deletions

View File

@ -3,13 +3,15 @@ const vm = require("vm")
class ScriptExecutor { class ScriptExecutor {
constructor(body) { constructor(body) {
this.script = new vm.Script(body.script) const code = `let fn = () => {\n${body.script}\n}; out = fn();`
this.script = new vm.Script(code)
this.context = vm.createContext(body.context) this.context = vm.createContext(body.context)
this.context.fetch = fetch this.context.fetch = fetch
} }
execute() { execute() {
return this.script.runInContext(this.context) this.script.runInContext(this.context)
return this.context.out
} }
} }

View File

@ -7,6 +7,7 @@ const executeScript = require("./steps/executeScript")
const bash = require("./steps/bash") const bash = require("./steps/bash")
const executeQuery = require("./steps/executeQuery") const executeQuery = require("./steps/executeQuery")
const outgoingWebhook = require("./steps/outgoingWebhook") const outgoingWebhook = require("./steps/outgoingWebhook")
const serverLog = require("./steps/serverLog")
const env = require("../environment") const env = require("../environment")
const Sentry = require("@sentry/node") const Sentry = require("@sentry/node")
const { const {
@ -24,6 +25,7 @@ const BUILTIN_ACTIONS = {
EXECUTE_SCRIPT: executeScript.run, EXECUTE_SCRIPT: executeScript.run,
EXECUTE_BASH: bash.run, EXECUTE_BASH: bash.run,
EXECUTE_QUERY: executeQuery.run, EXECUTE_QUERY: executeQuery.run,
SERVER_LOG: serverLog.run,
} }
const BUILTIN_DEFINITIONS = { const BUILTIN_DEFINITIONS = {
SEND_EMAIL: sendgridEmail.definition, SEND_EMAIL: sendgridEmail.definition,
@ -35,6 +37,7 @@ const BUILTIN_DEFINITIONS = {
EXECUTE_SCRIPT: executeScript.definition, EXECUTE_SCRIPT: executeScript.definition,
EXECUTE_QUERY: executeQuery.definition, EXECUTE_QUERY: executeQuery.definition,
EXECUTE_BASH: bash.definition, EXECUTE_BASH: bash.definition,
SERVER_LOG: serverLog.definition,
} }
let MANIFEST = null let MANIFEST = null

View File

@ -0,0 +1,41 @@
/**
* Note, there is some functionality in this that is not currently exposed as it
* is complex and maybe better to be opinionated here.
* GET/DELETE requests cannot handle body elements so they will not be sent if configured.
*/
module.exports.definition = {
name: "Backend log",
tagline: "Console log a value in the backend",
icon: "ri-server-line",
description: "Logs the given text to the server (using console.log)",
type: "ACTION",
stepId: "SERVER_LOG",
inputs: {
text: "",
},
schema: {
inputs: {
properties: {
text: {
type: "string",
title: "URL",
},
},
required: ["text"],
},
outputs: {
properties: {
success: {
type: "boolean",
description: "Whether the action was successful",
},
},
required: ["success"],
},
},
}
module.exports.run = async function ({ inputs, appId }) {
console.log(`App ${appId} - ${inputs.text}`)
}

View File

@ -211,14 +211,17 @@ class LinkController {
// iterate through the link IDs in the row field, see if any don't exist already // iterate through the link IDs in the row field, see if any don't exist already
for (let linkId of rowField) { for (let linkId of rowField) {
if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) { if (linkedSchema.relationshipType === RelationshipTypes.ONE_TO_MANY) {
const links = ( let links = (
await getLinkDocuments({ await getLinkDocuments({
appId: this._appId, appId: this._appId,
tableId: field.tableId, tableId: field.tableId,
rowId: linkId, rowId: linkId,
includeDocs: IncludeDocs.EXCLUDE, includeDocs: IncludeDocs.EXCLUDE,
}) })
).filter(link => link.id !== row._id) ).filter(
link =>
link.id !== row._id && link.fieldName === linkedSchema.name
)
// The 1 side of 1:N is already related to something else // The 1 side of 1:N is already related to something else
// You must remove the existing relationship // You must remove the existing relationship

View File

@ -53,7 +53,6 @@ describe("/api/admin/email", () => {
it("should be able to send a welcome email", async () => { it("should be able to send a welcome email", async () => {
await sendRealEmail(EmailTemplatePurpose.WELCOME) await sendRealEmail(EmailTemplatePurpose.WELCOME)
}) })
it("should be able to send a invitation email", async () => { it("should be able to send a invitation email", async () => {