diff --git a/packages/server/src/api/routes/tests/automation.spec.ts b/packages/server/src/api/routes/tests/automation.spec.ts index a517346c82..5c0b86d9a0 100644 --- a/packages/server/src/api/routes/tests/automation.spec.ts +++ b/packages/server/src/api/routes/tests/automation.spec.ts @@ -19,9 +19,11 @@ import { Table, } from "@budibase/types" import { mocks } from "@budibase/backend-core/tests" -import { FilterConditions } from "../../../automations/steps/filter" import { removeDeprecated } from "../../../automations/utils" import { createAutomationBuilder } from "../../../automations/tests/utilities/AutomationTestBuilder" +import { automations } from "@budibase/shared-core" + +const FilterConditions = automations.steps.filter.FilterConditions const MAX_RETRIES = 4 let { diff --git a/packages/server/src/automations/actions.ts b/packages/server/src/automations/actions.ts index 537b6befc3..65a57c2586 100644 --- a/packages/server/src/automations/actions.ts +++ b/packages/server/src/automations/actions.ts @@ -1,3 +1,4 @@ +import { automations } from "@budibase/shared-core" import * as sendSmtpEmail from "./steps/sendSmtpEmail" import * as createRow from "./steps/createRow" import * as updateRow from "./steps/updateRow" @@ -14,11 +15,10 @@ import * as make from "./steps/make" import * as filter from "./steps/filter" import * as delay from "./steps/delay" import * as queryRow from "./steps/queryRows" -import * as loop from "./steps/loop" import * as collect from "./steps/collect" -import * as branch from "./steps/branch" import * as triggerAutomationRun from "./steps/triggerAutomationRun" import * as openai from "./steps/openai" +import * as bash from "./steps/bash" import env from "../environment" import { PluginType, @@ -62,42 +62,39 @@ export const BUILTIN_ACTION_DEFINITIONS: Record< string, AutomationStepDefinition > = { - SEND_EMAIL_SMTP: sendSmtpEmail.definition, - CREATE_ROW: createRow.definition, - UPDATE_ROW: updateRow.definition, - DELETE_ROW: deleteRow.definition, - OUTGOING_WEBHOOK: outgoingWebhook.definition, - EXECUTE_SCRIPT: executeScript.definition, - EXECUTE_QUERY: executeQuery.definition, - SERVER_LOG: serverLog.definition, - DELAY: delay.definition, - FILTER: filter.definition, - QUERY_ROWS: queryRow.definition, - LOOP: loop.definition, - COLLECT: collect.definition, - TRIGGER_AUTOMATION_RUN: triggerAutomationRun.definition, - BRANCH: branch.definition, + SEND_EMAIL_SMTP: automations.steps.sendSmtpEmail.definition, + CREATE_ROW: automations.steps.createRow.definition, + UPDATE_ROW: automations.steps.updateRow.definition, + DELETE_ROW: automations.steps.deleteRow.definition, + OUTGOING_WEBHOOK: automations.steps.outgoingWebhook.definition, + EXECUTE_SCRIPT: automations.steps.executeScript.definition, + EXECUTE_QUERY: automations.steps.executeQuery.definition, + SERVER_LOG: automations.steps.serverLog.definition, + DELAY: automations.steps.delay.definition, + FILTER: automations.steps.filter.definition, + QUERY_ROWS: automations.steps.queryRows.definition, + LOOP: automations.steps.loop.definition, + COLLECT: automations.steps.collect.definition, + TRIGGER_AUTOMATION_RUN: automations.steps.triggerAutomationRun.definition, + BRANCH: automations.steps.branch.definition, // these used to be lowercase step IDs, maintain for backwards compat - discord: discord.definition, - slack: slack.definition, - zapier: zapier.definition, - integromat: make.definition, - n8n: n8n.definition, + discord: automations.steps.discord.definition, + slack: automations.steps.slack.definition, + zapier: automations.steps.zapier.definition, + integromat: automations.steps.make.definition, + n8n: automations.steps.n8n.definition, } // don't add the bash script/definitions unless in self host // the fact this isn't included in any definitions means it cannot be // ran at all if (env.SELF_HOSTED) { - const bash = require("./steps/bash") - - // @ts-ignore + // @ts-expect-error ACTION_IMPLS["EXECUTE_BASH"] = bash.run - // @ts-ignore - BUILTIN_ACTION_DEFINITIONS["EXECUTE_BASH"] = bash.definition + BUILTIN_ACTION_DEFINITIONS["EXECUTE_BASH"] = automations.steps.bash.definition if (env.isTest()) { - BUILTIN_ACTION_DEFINITIONS["OPENAI"] = openai.definition + BUILTIN_ACTION_DEFINITIONS["OPENAI"] = automations.steps.openai.definition } } @@ -105,7 +102,7 @@ export async function getActionDefinitions(): Promise< Record > { if (env.SELF_HOSTED) { - BUILTIN_ACTION_DEFINITIONS["OPENAI"] = openai.definition + BUILTIN_ACTION_DEFINITIONS["OPENAI"] = automations.steps.openai.definition } const actionDefinitions = BUILTIN_ACTION_DEFINITIONS diff --git a/packages/server/src/automations/steps/bash.ts b/packages/server/src/automations/steps/bash.ts index 636e659ffe..f6d2feecf6 100644 --- a/packages/server/src/automations/steps/bash.ts +++ b/packages/server/src/automations/steps/bash.ts @@ -2,55 +2,7 @@ import { execSync } from "child_process" import { processStringSync } from "@budibase/string-templates" import * as automationUtils from "../automationUtils" import environment from "../../environment" -import { - AutomationActionStepId, - AutomationCustomIOType, - AutomationFeature, - AutomationIOType, - AutomationStepDefinition, - AutomationStepType, - BashStepInputs, - BashStepOutputs, -} from "@budibase/types" - -export const definition: AutomationStepDefinition = { - name: "Bash Scripting", - tagline: "Execute a bash command", - icon: "JourneyEvent", - description: "Run a bash script", - type: AutomationStepType.ACTION, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - stepId: AutomationActionStepId.EXECUTE_BASH, - inputs: {}, - schema: { - inputs: { - properties: { - code: { - type: AutomationIOType.STRING, - customType: AutomationCustomIOType.CODE, - title: "Code", - }, - }, - required: ["code"], - }, - outputs: { - properties: { - stdout: { - type: AutomationIOType.STRING, - description: "Standard output of your bash command or script", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the command was successful", - }, - }, - required: ["stdout"], - }, - }, -} +import { BashStepInputs, BashStepOutputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/steps/collect.ts b/packages/server/src/automations/steps/collect.ts index 3b2ca7d21f..689c3d347f 100644 --- a/packages/server/src/automations/steps/collect.ts +++ b/packages/server/src/automations/steps/collect.ts @@ -1,48 +1,4 @@ -import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - CollectStepInputs, - CollectStepOutputs, -} from "@budibase/types" - -export const definition: AutomationStepDefinition = { - name: "Collect Data", - tagline: "Collect data to be sent to design", - icon: "Collection", - description: - "Collects specified data so it can be provided to the design section", - type: AutomationStepType.ACTION, - internal: true, - features: {}, - stepId: AutomationActionStepId.COLLECT, - inputs: {}, - schema: { - inputs: { - properties: { - collection: { - type: AutomationIOType.STRING, - title: "What to Collect", - }, - }, - required: ["collection"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the action was successful", - }, - value: { - type: AutomationIOType.STRING, - description: "Collected data", - }, - }, - required: ["success", "value"], - }, - }, -} +import { CollectStepInputs, CollectStepOutputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/steps/createRow.ts b/packages/server/src/automations/steps/createRow.ts index cd16be2cf3..24dada422d 100644 --- a/packages/server/src/automations/steps/createRow.ts +++ b/packages/server/src/automations/steps/createRow.ts @@ -5,77 +5,9 @@ import { sendAutomationAttachmentsToStorage, } from "../automationUtils" import { buildCtx } from "./utils" -import { - AutomationActionStepId, - AutomationCustomIOType, - AutomationFeature, - AutomationIOType, - AutomationStepDefinition, - AutomationStepType, - CreateRowStepInputs, - CreateRowStepOutputs, -} from "@budibase/types" +import { CreateRowStepInputs, CreateRowStepOutputs } from "@budibase/types" import { EventEmitter } from "events" -export const definition: AutomationStepDefinition = { - name: "Create Row", - tagline: "Create a {{inputs.enriched.table.name}} row", - icon: "TableRowAddBottom", - description: "Add a row to your database", - type: AutomationStepType.ACTION, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - stepId: AutomationActionStepId.CREATE_ROW, - inputs: {}, - schema: { - inputs: { - properties: { - row: { - type: AutomationIOType.OBJECT, - properties: { - tableId: { - type: AutomationIOType.STRING, - customType: AutomationCustomIOType.TABLE, - }, - }, - customType: AutomationCustomIOType.ROW, - title: "Table", - required: ["tableId"], - }, - }, - required: ["row"], - }, - outputs: { - properties: { - row: { - type: AutomationIOType.OBJECT, - customType: AutomationCustomIOType.ROW, - description: "The new row", - }, - response: { - type: AutomationIOType.OBJECT, - description: "The response from the table", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the row creation was successful", - }, - id: { - type: AutomationIOType.STRING, - description: "The identifier of the new row", - }, - revision: { - type: AutomationIOType.STRING, - description: "The revision of the new row", - }, - }, - required: ["success", "id", "revision"], - }, - }, -} - export async function run({ inputs, appId, diff --git a/packages/server/src/automations/steps/delay.ts b/packages/server/src/automations/steps/delay.ts index c623693488..4ca5a16942 100644 --- a/packages/server/src/automations/steps/delay.ts +++ b/packages/server/src/automations/steps/delay.ts @@ -1,44 +1,5 @@ import { wait } from "../../utilities" -import { - AutomationActionStepId, - AutomationIOType, - AutomationStepDefinition, - AutomationStepType, - DelayStepInputs, - DelayStepOutputs, -} from "@budibase/types" - -export const definition: AutomationStepDefinition = { - name: "Delay", - icon: "Clock", - tagline: "Delay for {{inputs.time}} milliseconds", - description: "Delay the automation until an amount of time has passed", - stepId: AutomationActionStepId.DELAY, - internal: true, - features: {}, - inputs: {}, - schema: { - inputs: { - properties: { - time: { - type: AutomationIOType.NUMBER, - title: "Delay in milliseconds", - }, - }, - required: ["time"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the delay was successful", - }, - }, - required: ["success"], - }, - }, - type: AutomationStepType.LOGIC, -} +import { DelayStepInputs, DelayStepOutputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/steps/deleteRow.ts b/packages/server/src/automations/steps/deleteRow.ts index 6b8a68eeb8..7c50fe4dcb 100644 --- a/packages/server/src/automations/steps/deleteRow.ts +++ b/packages/server/src/automations/steps/deleteRow.ts @@ -2,64 +2,7 @@ import { EventEmitter } from "events" import { destroy } from "../../api/controllers/row" import { buildCtx } from "./utils" import { getError } from "../automationUtils" -import { - AutomationActionStepId, - AutomationStepType, - AutomationIOType, - AutomationCustomIOType, - AutomationFeature, - DeleteRowStepInputs, - DeleteRowStepOutputs, - AutomationStepDefinition, -} from "@budibase/types" - -export const definition: AutomationStepDefinition = { - description: "Delete a row from your database", - icon: "TableRowRemoveCenter", - name: "Delete Row", - tagline: "Delete a {{inputs.enriched.table.name}} row", - type: AutomationStepType.ACTION, - stepId: AutomationActionStepId.DELETE_ROW, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - inputs: {}, - schema: { - inputs: { - properties: { - tableId: { - type: AutomationIOType.STRING, - customType: AutomationCustomIOType.TABLE, - title: "Table", - }, - id: { - type: AutomationIOType.STRING, - title: "Row ID", - }, - }, - required: ["tableId", "id"], - }, - outputs: { - properties: { - row: { - type: AutomationIOType.OBJECT, - customType: AutomationCustomIOType.ROW, - description: "The deleted row", - }, - response: { - type: AutomationIOType.OBJECT, - description: "The response from the table", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the deletion was successful", - }, - }, - required: ["row", "success"], - }, - }, -} +import { DeleteRowStepInputs, DeleteRowStepOutputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/steps/discord.ts b/packages/server/src/automations/steps/discord.ts index 1ce21fc89e..30d3e8137b 100644 --- a/packages/server/src/automations/steps/discord.ts +++ b/packages/server/src/automations/steps/discord.ts @@ -1,71 +1,10 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" -import { - AutomationActionStepId, - AutomationStepType, - AutomationIOType, - AutomationFeature, - ExternalAppStepOutputs, - DiscordStepInputs, - AutomationStepDefinition, -} from "@budibase/types" +import { ExternalAppStepOutputs, DiscordStepInputs } from "@budibase/types" const DEFAULT_USERNAME = "Budibase Automate" const DEFAULT_AVATAR_URL = "https://i.imgur.com/a1cmTKM.png" -export const definition: AutomationStepDefinition = { - name: "Discord Message", - tagline: "Send a message to a Discord server", - description: "Send a message to a Discord server", - icon: "ri-discord-line", - stepId: AutomationActionStepId.discord, - type: AutomationStepType.ACTION, - internal: false, - features: { - [AutomationFeature.LOOPING]: true, - }, - inputs: {}, - schema: { - inputs: { - properties: { - url: { - type: AutomationIOType.STRING, - title: "Discord Webhook URL", - }, - username: { - type: AutomationIOType.STRING, - title: "Bot Name", - }, - avatar_url: { - type: AutomationIOType.STRING, - title: "Bot Avatar URL", - }, - content: { - type: AutomationIOType.STRING, - title: "Message", - }, - }, - required: ["url", "content"], - }, - outputs: { - properties: { - httpStatus: { - type: AutomationIOType.NUMBER, - description: "The HTTP status code of the request", - }, - response: { - type: AutomationIOType.STRING, - description: "The response from the Discord Webhook", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the message sent successfully", - }, - }, - }, - }, -} - export async function run({ inputs, }: { diff --git a/packages/server/src/automations/steps/executeQuery.ts b/packages/server/src/automations/steps/executeQuery.ts index 7af540093f..9816e31b1e 100644 --- a/packages/server/src/automations/steps/executeQuery.ts +++ b/packages/server/src/automations/steps/executeQuery.ts @@ -3,67 +3,10 @@ import * as queryController from "../../api/controllers/query" import { buildCtx } from "./utils" import * as automationUtils from "../automationUtils" import { - AutomationActionStepId, - AutomationCustomIOType, - AutomationFeature, - AutomationIOType, - AutomationStepDefinition, - AutomationStepType, ExecuteQueryStepInputs, ExecuteQueryStepOutputs, } from "@budibase/types" -export const definition: AutomationStepDefinition = { - name: "External Data Connector", - tagline: "Execute Data Connector", - icon: "Data", - description: "Execute a query in an external data connector", - type: AutomationStepType.ACTION, - stepId: AutomationActionStepId.EXECUTE_QUERY, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - inputs: {}, - schema: { - inputs: { - properties: { - query: { - type: AutomationIOType.OBJECT, - properties: { - queryId: { - type: AutomationIOType.STRING, - customType: AutomationCustomIOType.QUERY, - }, - }, - customType: AutomationCustomIOType.QUERY_PARAMS, - title: "Parameters", - required: ["queryId"], - }, - }, - required: ["query"], - }, - outputs: { - properties: { - response: { - type: AutomationIOType.OBJECT, - description: "The response from the datasource execution", - }, - info: { - type: AutomationIOType.OBJECT, - description: - "Some query types may return extra data, like headers from a REST query", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the action was successful", - }, - }, - required: ["response", "success"], - }, - }, -} - export async function run({ inputs, appId, diff --git a/packages/server/src/automations/steps/executeScript.ts b/packages/server/src/automations/steps/executeScript.ts index 97145f3e14..105543d34c 100644 --- a/packages/server/src/automations/steps/executeScript.ts +++ b/packages/server/src/automations/steps/executeScript.ts @@ -2,56 +2,11 @@ import * as scriptController from "../../api/controllers/script" import { buildCtx } from "./utils" import * as automationUtils from "../automationUtils" import { - AutomationActionStepId, - AutomationCustomIOType, - AutomationFeature, - AutomationIOType, - AutomationStepDefinition, - AutomationStepType, ExecuteScriptStepInputs, ExecuteScriptStepOutputs, } from "@budibase/types" import { EventEmitter } from "events" -export const definition: AutomationStepDefinition = { - name: "JS Scripting", - tagline: "Execute JavaScript Code", - icon: "Code", - description: "Run a piece of JavaScript code in your automation", - type: AutomationStepType.ACTION, - internal: true, - stepId: AutomationActionStepId.EXECUTE_SCRIPT, - inputs: {}, - features: { - [AutomationFeature.LOOPING]: true, - }, - schema: { - inputs: { - properties: { - code: { - type: AutomationIOType.STRING, - customType: AutomationCustomIOType.CODE, - title: "Code", - }, - }, - required: ["code"], - }, - outputs: { - properties: { - value: { - type: AutomationIOType.STRING, - description: "The result of the return statement", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the action was successful", - }, - }, - required: ["success"], - }, - }, -} - export async function run({ inputs, appId, diff --git a/packages/server/src/automations/steps/filter.ts b/packages/server/src/automations/steps/filter.ts index 84cea00b93..9b7e347034 100644 --- a/packages/server/src/automations/steps/filter.ts +++ b/packages/server/src/automations/steps/filter.ts @@ -1,74 +1,7 @@ -import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - FilterStepInputs, - FilterStepOutputs, -} from "@budibase/types" +import { FilterStepInputs, FilterStepOutputs } from "@budibase/types" +import { automations } from "@budibase/shared-core" -export const FilterConditions = { - EQUAL: "EQUAL", - NOT_EQUAL: "NOT_EQUAL", - GREATER_THAN: "GREATER_THAN", - LESS_THAN: "LESS_THAN", -} - -export const PrettyFilterConditions = { - [FilterConditions.EQUAL]: "Equals", - [FilterConditions.NOT_EQUAL]: "Not equals", - [FilterConditions.GREATER_THAN]: "Greater than", - [FilterConditions.LESS_THAN]: "Less than", -} - -export const definition: AutomationStepDefinition = { - name: "Condition", - tagline: "{{inputs.field}} {{inputs.condition}} {{inputs.value}}", - icon: "Branch2", - description: - "Conditionally halt automations which do not meet certain conditions", - type: AutomationStepType.LOGIC, - internal: true, - features: {}, - stepId: AutomationActionStepId.FILTER, - inputs: { - condition: FilterConditions.EQUAL, - }, - schema: { - inputs: { - properties: { - field: { - type: AutomationIOType.STRING, - title: "Reference Value", - }, - condition: { - type: AutomationIOType.STRING, - title: "Condition", - enum: Object.values(FilterConditions), - pretty: Object.values(PrettyFilterConditions), - }, - value: { - type: AutomationIOType.STRING, - title: "Comparison Value", - }, - }, - required: ["field", "condition", "value"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the action was successful", - }, - result: { - type: AutomationIOType.BOOLEAN, - description: "Whether the logic block passed", - }, - }, - required: ["success", "result"], - }, - }, -} +const FilterConditions = automations.steps.filter.FilterConditions export async function run({ inputs, diff --git a/packages/server/src/automations/steps/make.ts b/packages/server/src/automations/steps/make.ts index 62cfd66302..241cccce9e 100644 --- a/packages/server/src/automations/steps/make.ts +++ b/packages/server/src/automations/steps/make.ts @@ -1,62 +1,6 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" -import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - AutomationFeature, - ExternalAppStepOutputs, - MakeIntegrationInputs, -} from "@budibase/types" - -export const definition: AutomationStepDefinition = { - name: "Make Integration", - stepTitle: "Make", - tagline: "Trigger a Make scenario", - description: - "Performs a webhook call to Make and gets the response (if configured)", - icon: "ri-shut-down-line", - stepId: AutomationActionStepId.integromat, - type: AutomationStepType.ACTION, - internal: false, - features: { - [AutomationFeature.LOOPING]: true, - }, - inputs: {}, - schema: { - inputs: { - properties: { - url: { - type: AutomationIOType.STRING, - title: "Webhook URL", - }, - body: { - type: AutomationIOType.JSON, - title: "Payload", - }, - }, - required: ["url", "body"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether call was successful", - }, - httpStatus: { - type: AutomationIOType.NUMBER, - description: "The HTTP status code returned", - }, - response: { - type: AutomationIOType.OBJECT, - description: "The webhook response - this can have properties", - }, - }, - required: ["success", "response"], - }, - }, -} +import { ExternalAppStepOutputs, MakeIntegrationInputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/steps/n8n.ts b/packages/server/src/automations/steps/n8n.ts index 8e55d2535b..29883dd327 100644 --- a/packages/server/src/automations/steps/n8n.ts +++ b/packages/server/src/automations/steps/n8n.ts @@ -1,73 +1,11 @@ import fetch, { HeadersInit } from "node-fetch" import { getFetchResponse } from "./utils" import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - AutomationFeature, HttpMethod, ExternalAppStepOutputs, n8nStepInputs, } from "@budibase/types" -export const definition: AutomationStepDefinition = { - name: "n8n Integration", - stepTitle: "n8n", - tagline: "Trigger an n8n workflow", - description: - "Performs a webhook call to n8n and gets the response (if configured)", - icon: "ri-shut-down-line", - stepId: AutomationActionStepId.n8n, - type: AutomationStepType.ACTION, - internal: false, - features: { - [AutomationFeature.LOOPING]: true, - }, - inputs: {}, - schema: { - inputs: { - properties: { - url: { - type: AutomationIOType.STRING, - title: "Webhook URL", - }, - method: { - type: AutomationIOType.STRING, - title: "Method", - enum: Object.values(HttpMethod), - }, - authorization: { - type: AutomationIOType.STRING, - title: "Authorization", - }, - body: { - type: AutomationIOType.JSON, - title: "Payload", - }, - }, - required: ["url", "method"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether call was successful", - }, - httpStatus: { - type: AutomationIOType.NUMBER, - description: "The HTTP status code returned", - }, - response: { - type: AutomationIOType.OBJECT, - description: "The webhook response - this can have properties", - }, - }, - required: ["success", "response"], - }, - }, -} - export async function run({ inputs, }: { diff --git a/packages/server/src/automations/steps/openai.ts b/packages/server/src/automations/steps/openai.ts index 53e41ceb09..55f57aff7c 100644 --- a/packages/server/src/automations/steps/openai.ts +++ b/packages/server/src/automations/steps/openai.ts @@ -1,67 +1,10 @@ import { OpenAI } from "openai" -import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - OpenAIStepInputs, - OpenAIStepOutputs, -} from "@budibase/types" +import { OpenAIStepInputs, OpenAIStepOutputs } from "@budibase/types" import { env } from "@budibase/backend-core" import * as automationUtils from "../automationUtils" import * as pro from "@budibase/pro" -enum Model { - GPT_4O_MINI = "gpt-4o-mini", - GPT_4O = "gpt-4o", - GPT_4 = "gpt-4", - GPT_35_TURBO = "gpt-3.5-turbo", -} - -export const definition: AutomationStepDefinition = { - name: "OpenAI", - tagline: "Send prompts to ChatGPT", - icon: "Algorithm", - description: "Interact with the OpenAI ChatGPT API.", - type: AutomationStepType.ACTION, - internal: true, - features: {}, - stepId: AutomationActionStepId.OPENAI, - inputs: { - prompt: "", - }, - schema: { - inputs: { - properties: { - prompt: { - type: AutomationIOType.STRING, - title: "Prompt", - }, - model: { - type: AutomationIOType.STRING, - title: "Model", - enum: Object.values(Model), - }, - }, - required: ["prompt", "model"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the action was successful", - }, - response: { - type: AutomationIOType.STRING, - description: "What was output", - }, - }, - required: ["success", "response"], - }, - }, -} - /** * Maintains backward compatibility with automation steps created before the introduction * of custom configurations and Budibase AI diff --git a/packages/server/src/automations/steps/outgoingWebhook.ts b/packages/server/src/automations/steps/outgoingWebhook.ts index 70b8b1f476..a1211ea281 100644 --- a/packages/server/src/automations/steps/outgoingWebhook.ts +++ b/packages/server/src/automations/steps/outgoingWebhook.ts @@ -2,12 +2,6 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" import * as automationUtils from "../automationUtils" import { - AutomationActionStepId, - AutomationCustomIOType, - AutomationFeature, - AutomationIOType, - AutomationStepDefinition, - AutomationStepType, ExternalAppStepOutputs, OutgoingWebhookStepInputs, } from "@budibase/types" @@ -26,69 +20,6 @@ const BODY_REQUESTS = [RequestType.POST, RequestType.PUT, RequestType.PATCH] * NOTE: this functionality is deprecated - it no longer should be used. */ -export const definition: AutomationStepDefinition = { - deprecated: true, - name: "Outgoing webhook", - tagline: "Send a {{inputs.requestMethod}} request", - icon: "Send", - description: "Send a request of specified method to a URL", - type: AutomationStepType.ACTION, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - stepId: AutomationActionStepId.OUTGOING_WEBHOOK, - inputs: { - requestMethod: "POST", - url: "http://", - requestBody: "{}", - headers: "{}", - }, - schema: { - inputs: { - properties: { - requestMethod: { - type: AutomationIOType.STRING, - enum: Object.values(RequestType), - title: "Request method", - }, - url: { - type: AutomationIOType.STRING, - title: "URL", - }, - requestBody: { - type: AutomationIOType.STRING, - title: "JSON Body", - customType: AutomationCustomIOType.WIDE, - }, - headers: { - type: AutomationIOType.STRING, - title: "Headers", - customType: AutomationCustomIOType.WIDE, - }, - }, - required: ["requestMethod", "url"], - }, - outputs: { - properties: { - response: { - type: AutomationIOType.OBJECT, - description: "The response from the webhook", - }, - httpStatus: { - type: AutomationIOType.NUMBER, - description: "The HTTP status code returned", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the action was successful", - }, - }, - required: ["response", "success"], - }, - }, -} - export async function run({ inputs, }: { diff --git a/packages/server/src/automations/steps/queryRows.ts b/packages/server/src/automations/steps/queryRows.ts index 4a02e80686..9c60a63dac 100644 --- a/packages/server/src/automations/steps/queryRows.ts +++ b/packages/server/src/automations/steps/queryRows.ts @@ -4,84 +4,12 @@ import { buildCtx } from "./utils" import * as automationUtils from "../automationUtils" import { FieldType, - AutomationActionStepId, - AutomationCustomIOType, - AutomationFeature, - AutomationIOType, - AutomationStepDefinition, - AutomationStepType, EmptyFilterOption, SortOrder, QueryRowsStepInputs, QueryRowsStepOutputs, } from "@budibase/types" -const SortOrderPretty = { - [SortOrder.ASCENDING]: "Ascending", - [SortOrder.DESCENDING]: "Descending", -} - -export const definition: AutomationStepDefinition = { - description: "Query rows from the database", - icon: "Search", - name: "Query rows", - tagline: "Query rows from {{inputs.enriched.table.name}} table", - type: AutomationStepType.ACTION, - stepId: AutomationActionStepId.QUERY_ROWS, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - inputs: {}, - schema: { - inputs: { - properties: { - tableId: { - type: AutomationIOType.STRING, - customType: AutomationCustomIOType.TABLE, - title: "Table", - }, - filters: { - type: AutomationIOType.OBJECT, - customType: AutomationCustomIOType.FILTERS, - title: "Filtering", - }, - sortColumn: { - type: AutomationIOType.STRING, - title: "Sort Column", - customType: AutomationCustomIOType.COLUMN, - }, - sortOrder: { - type: AutomationIOType.STRING, - title: "Sort Order", - enum: Object.values(SortOrder), - pretty: Object.values(SortOrderPretty), - }, - limit: { - type: AutomationIOType.NUMBER, - title: "Limit", - customType: AutomationCustomIOType.QUERY_LIMIT, - }, - }, - required: ["tableId"], - }, - outputs: { - properties: { - rows: { - type: AutomationIOType.ARRAY, - customType: AutomationCustomIOType.ROWS, - description: "The rows that were found", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the query was successful", - }, - }, - required: ["rows", "success"], - }, - }, -} - async function getTable(appId: string, tableId: string) { const ctx: any = buildCtx(appId, null, { params: { diff --git a/packages/server/src/automations/steps/sendSmtpEmail.ts b/packages/server/src/automations/steps/sendSmtpEmail.ts index 72ca410528..bfa2fa31ad 100644 --- a/packages/server/src/automations/steps/sendSmtpEmail.ts +++ b/packages/server/src/automations/steps/sendSmtpEmail.ts @@ -1,102 +1,6 @@ import { sendSmtpEmail } from "../../utilities/workerRequests" import * as automationUtils from "../automationUtils" -import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - AutomationFeature, - AutomationCustomIOType, - SmtpEmailStepInputs, - BaseAutomationOutputs, -} from "@budibase/types" - -export const definition: AutomationStepDefinition = { - description: "Send an email using SMTP", - tagline: "Send SMTP email to {{inputs.to}}", - icon: "Email", - name: "Send Email (SMTP)", - type: AutomationStepType.ACTION, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - stepId: AutomationActionStepId.SEND_EMAIL_SMTP, - inputs: {}, - schema: { - inputs: { - properties: { - to: { - type: AutomationIOType.STRING, - title: "Send To", - }, - from: { - type: AutomationIOType.STRING, - title: "Send From", - }, - cc: { - type: AutomationIOType.STRING, - title: "CC", - }, - bcc: { - type: AutomationIOType.STRING, - title: "BCC", - }, - subject: { - type: AutomationIOType.STRING, - title: "Email Subject", - }, - contents: { - type: AutomationIOType.STRING, - title: "HTML Contents", - }, - addInvite: { - type: AutomationIOType.BOOLEAN, - title: "Add calendar invite", - }, - startTime: { - type: AutomationIOType.DATE, - title: "Start Time", - dependsOn: "addInvite", - }, - endTime: { - type: AutomationIOType.DATE, - title: "End Time", - dependsOn: "addInvite", - }, - summary: { - type: AutomationIOType.STRING, - title: "Meeting Summary", - dependsOn: "addInvite", - }, - location: { - type: AutomationIOType.STRING, - title: "Location", - dependsOn: "addInvite", - }, - attachments: { - type: AutomationIOType.ATTACHMENT, - customType: AutomationCustomIOType.MULTI_ATTACHMENTS, - title: "Attachments", - }, - }, - required: ["to", "from", "subject", "contents"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the email was sent", - }, - response: { - type: AutomationIOType.OBJECT, - description: "A response from the email client, this may be an error", - }, - }, - required: ["success"], - }, - }, -} +import { SmtpEmailStepInputs, BaseAutomationOutputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/steps/serverLog.ts b/packages/server/src/automations/steps/serverLog.ts index d0702ab3eb..b3588b7378 100644 --- a/packages/server/src/automations/steps/serverLog.ts +++ b/packages/server/src/automations/steps/serverLog.ts @@ -1,58 +1,4 @@ -import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - AutomationFeature, - ServerLogStepInputs, - ServerLogStepOutputs, -} from "@budibase/types" - -/** - * 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. - */ - -export const definition: AutomationStepDefinition = { - name: "Backend log", - tagline: "Console log a value in the backend", - icon: "Monitoring", - description: "Logs the given text to the server (using console.log)", - type: AutomationStepType.ACTION, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - stepId: AutomationActionStepId.SERVER_LOG, - inputs: { - text: "", - }, - schema: { - inputs: { - properties: { - text: { - type: AutomationIOType.STRING, - title: "Log", - }, - }, - required: ["text"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the action was successful", - }, - message: { - type: AutomationIOType.STRING, - description: "What was output", - }, - }, - required: ["success", "message"], - }, - }, -} +import { ServerLogStepInputs, ServerLogStepOutputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/steps/slack.ts b/packages/server/src/automations/steps/slack.ts index 353611260c..12dcea74c7 100644 --- a/packages/server/src/automations/steps/slack.ts +++ b/packages/server/src/automations/steps/slack.ts @@ -1,59 +1,6 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" -import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - AutomationFeature, - ExternalAppStepOutputs, - SlackStepInputs, -} from "@budibase/types" - -export const definition: AutomationStepDefinition = { - name: "Slack Message", - tagline: "Send a message to Slack", - description: "Send a message to Slack", - icon: "ri-slack-line", - stepId: AutomationActionStepId.slack, - type: AutomationStepType.ACTION, - internal: false, - features: { - [AutomationFeature.LOOPING]: true, - }, - inputs: {}, - schema: { - inputs: { - properties: { - url: { - type: AutomationIOType.STRING, - title: "Incoming Webhook URL", - }, - text: { - type: AutomationIOType.STRING, - title: "Message", - }, - }, - required: ["url", "text"], - }, - outputs: { - properties: { - httpStatus: { - type: AutomationIOType.NUMBER, - description: "The HTTP status code of the request", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the message sent successfully", - }, - response: { - type: AutomationIOType.STRING, - description: "The response from the Slack Webhook", - }, - }, - }, - }, -} +import { ExternalAppStepOutputs, SlackStepInputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/steps/triggerAutomationRun.ts b/packages/server/src/automations/steps/triggerAutomationRun.ts index f1cf65b182..5c7959648d 100644 --- a/packages/server/src/automations/steps/triggerAutomationRun.ts +++ b/packages/server/src/automations/steps/triggerAutomationRun.ts @@ -1,10 +1,5 @@ import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, Automation, - AutomationCustomIOType, TriggerAutomationStepInputs, TriggerAutomationStepOutputs, } from "@budibase/types" @@ -13,54 +8,6 @@ import { context } from "@budibase/backend-core" import { features } from "@budibase/pro" import env from "../../environment" -export const definition: AutomationStepDefinition = { - name: "Trigger an automation", - tagline: "Triggers an automation synchronously", - icon: "Sync", - description: "Triggers an automation synchronously", - type: AutomationStepType.ACTION, - internal: true, - features: {}, - stepId: AutomationActionStepId.TRIGGER_AUTOMATION_RUN, - inputs: {}, - schema: { - inputs: { - properties: { - automation: { - type: AutomationIOType.OBJECT, - properties: { - automationId: { - type: AutomationIOType.STRING, - customType: AutomationCustomIOType.AUTOMATION, - }, - }, - customType: AutomationCustomIOType.AUTOMATION_FIELDS, - title: "automatioFields", - required: ["automationId"], - }, - timeout: { - type: AutomationIOType.NUMBER, - title: "Timeout (ms)", - }, - }, - required: ["automationId"], - }, - outputs: { - properties: { - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the automation was successful", - }, - value: { - type: AutomationIOType.OBJECT, - description: "Automation Result", - }, - }, - required: ["success", "value"], - }, - }, -} - export async function run({ inputs, }: { diff --git a/packages/server/src/automations/steps/updateRow.ts b/packages/server/src/automations/steps/updateRow.ts index 552d846f18..46ae2a5c74 100644 --- a/packages/server/src/automations/steps/updateRow.ts +++ b/packages/server/src/automations/steps/updateRow.ts @@ -2,76 +2,8 @@ import { EventEmitter } from "events" import * as rowController from "../../api/controllers/row" import * as automationUtils from "../automationUtils" import { buildCtx } from "./utils" -import { - AutomationActionStepId, - AutomationCustomIOType, - AutomationFeature, - AutomationIOType, - AutomationStepDefinition, - AutomationStepType, - UpdateRowStepInputs, - UpdateRowStepOutputs, -} from "@budibase/types" +import { UpdateRowStepInputs, UpdateRowStepOutputs } from "@budibase/types" -export const definition: AutomationStepDefinition = { - name: "Update Row", - tagline: "Update a {{inputs.enriched.table.name}} row", - icon: "Refresh", - description: "Update a row in your database", - type: AutomationStepType.ACTION, - internal: true, - features: { - [AutomationFeature.LOOPING]: true, - }, - stepId: AutomationActionStepId.UPDATE_ROW, - inputs: {}, - schema: { - inputs: { - properties: { - meta: { - type: AutomationIOType.OBJECT, - title: "Field settings", - }, - row: { - type: AutomationIOType.OBJECT, - customType: AutomationCustomIOType.ROW, - title: "Table", - }, - rowId: { - type: AutomationIOType.STRING, - title: "Row ID", - }, - }, - required: ["row", "rowId"], - }, - outputs: { - properties: { - row: { - type: AutomationIOType.OBJECT, - customType: AutomationCustomIOType.ROW, - description: "The updated row", - }, - response: { - type: AutomationIOType.OBJECT, - description: "The response from the table", - }, - success: { - type: AutomationIOType.BOOLEAN, - description: "Whether the action was successful", - }, - id: { - type: AutomationIOType.STRING, - description: "The identifier of the updated row", - }, - revision: { - type: AutomationIOType.STRING, - description: "The revision of the updated row", - }, - }, - required: ["success", "id", "revision"], - }, - }, -} export async function run({ inputs, appId, diff --git a/packages/server/src/automations/steps/zapier.ts b/packages/server/src/automations/steps/zapier.ts index 888dae1e68..d17323cf0d 100644 --- a/packages/server/src/automations/steps/zapier.ts +++ b/packages/server/src/automations/steps/zapier.ts @@ -1,55 +1,6 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" -import { - AutomationActionStepId, - AutomationStepDefinition, - AutomationStepType, - AutomationIOType, - AutomationFeature, - ZapierStepInputs, - ZapierStepOutputs, -} from "@budibase/types" - -export const definition: AutomationStepDefinition = { - name: "Zapier Webhook", - stepId: AutomationActionStepId.zapier, - type: AutomationStepType.ACTION, - internal: false, - features: { - [AutomationFeature.LOOPING]: true, - }, - description: "Trigger a Zapier Zap via webhooks", - tagline: "Trigger a Zapier Zap", - icon: "ri-flashlight-line", - inputs: {}, - schema: { - inputs: { - properties: { - url: { - type: AutomationIOType.STRING, - title: "Webhook URL", - }, - body: { - type: AutomationIOType.JSON, - title: "Payload", - }, - }, - required: ["url"], - }, - outputs: { - properties: { - httpStatus: { - type: AutomationIOType.NUMBER, - description: "The HTTP status code of the request", - }, - response: { - type: AutomationIOType.STRING, - description: "The response from Zapier", - }, - }, - }, - }, -} +import { ZapierStepInputs, ZapierStepOutputs } from "@budibase/types" export async function run({ inputs, diff --git a/packages/server/src/automations/tests/filter.spec.ts b/packages/server/src/automations/tests/filter.spec.ts index a1ed72dd74..674516517a 100644 --- a/packages/server/src/automations/tests/filter.spec.ts +++ b/packages/server/src/automations/tests/filter.spec.ts @@ -1,5 +1,7 @@ import * as setup from "./utilities" -import { FilterConditions } from "../steps/filter" +import { automations } from "@budibase/shared-core" + +const FilterConditions = automations.steps.filter.FilterConditions describe("test the filter logic", () => { const config = setup.getConfig() diff --git a/packages/server/src/automations/tests/scenarios/scenarios.spec.ts b/packages/server/src/automations/tests/scenarios/scenarios.spec.ts index 45b251f4c1..3e203b7959 100644 --- a/packages/server/src/automations/tests/scenarios/scenarios.spec.ts +++ b/packages/server/src/automations/tests/scenarios/scenarios.spec.ts @@ -6,9 +6,11 @@ import { DatabaseName, datasourceDescribe, } from "../../../integrations/tests/utils" -import { FilterConditions } from "../../../automations/steps/filter" import { Knex } from "knex" import { generator } from "@budibase/backend-core/tests" +import { automations } from "@budibase/shared-core" + +const FilterConditions = automations.steps.filter.FilterConditions describe("Automation Scenarios", () => { let config = setup.getConfig() diff --git a/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts b/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts index acc35a0eeb..830d2ee5ca 100644 --- a/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts +++ b/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts @@ -42,7 +42,7 @@ import { } from "@budibase/types" import TestConfiguration from "../../../tests/utilities/TestConfiguration" import * as setup from "../utilities" -import { definition } from "../../../automations/steps/branch" +import { automations } from "@budibase/shared-core" type TriggerOutputs = | RowCreatedTriggerOutputs @@ -103,7 +103,7 @@ class BaseStepBuilder { branchStepInputs.children![branchId] = stepBuilder.build() }) const branchStep: AutomationStep = { - ...definition, + ...automations.steps.branch.definition, id: uuidv4(), stepId: AutomationActionStepId.BRANCH, inputs: branchStepInputs, diff --git a/packages/shared-core/src/automations/index.ts b/packages/shared-core/src/automations/index.ts new file mode 100644 index 0000000000..064796845e --- /dev/null +++ b/packages/shared-core/src/automations/index.ts @@ -0,0 +1 @@ +export * as steps from "./steps/index" diff --git a/packages/shared-core/src/automations/steps/bash.ts b/packages/shared-core/src/automations/steps/bash.ts new file mode 100644 index 0000000000..2980e18f0e --- /dev/null +++ b/packages/shared-core/src/automations/steps/bash.ts @@ -0,0 +1,47 @@ +import { + AutomationActionStepId, + AutomationCustomIOType, + AutomationFeature, + AutomationIOType, + AutomationStepDefinition, + AutomationStepType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Bash Scripting", + tagline: "Execute a bash command", + icon: "JourneyEvent", + description: "Run a bash script", + type: AutomationStepType.ACTION, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + stepId: AutomationActionStepId.EXECUTE_BASH, + inputs: {}, + schema: { + inputs: { + properties: { + code: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.CODE, + title: "Code", + }, + }, + required: ["code"], + }, + outputs: { + properties: { + stdout: { + type: AutomationIOType.STRING, + description: "Standard output of your bash command or script", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the command was successful", + }, + }, + required: ["stdout"], + }, + }, +} diff --git a/packages/server/src/automations/steps/branch.ts b/packages/shared-core/src/automations/steps/branch.ts similarity index 100% rename from packages/server/src/automations/steps/branch.ts rename to packages/shared-core/src/automations/steps/branch.ts diff --git a/packages/shared-core/src/automations/steps/collect.ts b/packages/shared-core/src/automations/steps/collect.ts new file mode 100644 index 0000000000..d4a6f6ec98 --- /dev/null +++ b/packages/shared-core/src/automations/steps/collect.ts @@ -0,0 +1,43 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Collect Data", + tagline: "Collect data to be sent to design", + icon: "Collection", + description: + "Collects specified data so it can be provided to the design section", + type: AutomationStepType.ACTION, + internal: true, + features: {}, + stepId: AutomationActionStepId.COLLECT, + inputs: {}, + schema: { + inputs: { + properties: { + collection: { + type: AutomationIOType.STRING, + title: "What to Collect", + }, + }, + required: ["collection"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the action was successful", + }, + value: { + type: AutomationIOType.STRING, + description: "Collected data", + }, + }, + required: ["success", "value"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/createRow.ts b/packages/shared-core/src/automations/steps/createRow.ts new file mode 100644 index 0000000000..f51fdabb67 --- /dev/null +++ b/packages/shared-core/src/automations/steps/createRow.ts @@ -0,0 +1,67 @@ +import { + AutomationActionStepId, + AutomationCustomIOType, + AutomationFeature, + AutomationIOType, + AutomationStepDefinition, + AutomationStepType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Create Row", + tagline: "Create a {{inputs.enriched.table.name}} row", + icon: "TableRowAddBottom", + description: "Add a row to your database", + type: AutomationStepType.ACTION, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + stepId: AutomationActionStepId.CREATE_ROW, + inputs: {}, + schema: { + inputs: { + properties: { + row: { + type: AutomationIOType.OBJECT, + properties: { + tableId: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.TABLE, + }, + }, + customType: AutomationCustomIOType.ROW, + title: "Table", + required: ["tableId"], + }, + }, + required: ["row"], + }, + outputs: { + properties: { + row: { + type: AutomationIOType.OBJECT, + customType: AutomationCustomIOType.ROW, + description: "The new row", + }, + response: { + type: AutomationIOType.OBJECT, + description: "The response from the table", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the row creation was successful", + }, + id: { + type: AutomationIOType.STRING, + description: "The identifier of the new row", + }, + revision: { + type: AutomationIOType.STRING, + description: "The revision of the new row", + }, + }, + required: ["success", "id", "revision"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/delay.ts b/packages/shared-core/src/automations/steps/delay.ts new file mode 100644 index 0000000000..627bc9ed2f --- /dev/null +++ b/packages/shared-core/src/automations/steps/delay.ts @@ -0,0 +1,38 @@ +import { + AutomationActionStepId, + AutomationIOType, + AutomationStepDefinition, + AutomationStepType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Delay", + icon: "Clock", + tagline: "Delay for {{inputs.time}} milliseconds", + description: "Delay the automation until an amount of time has passed", + stepId: AutomationActionStepId.DELAY, + internal: true, + features: {}, + inputs: {}, + schema: { + inputs: { + properties: { + time: { + type: AutomationIOType.NUMBER, + title: "Delay in milliseconds", + }, + }, + required: ["time"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the delay was successful", + }, + }, + required: ["success"], + }, + }, + type: AutomationStepType.LOGIC, +} diff --git a/packages/shared-core/src/automations/steps/deleteRow.ts b/packages/shared-core/src/automations/steps/deleteRow.ts new file mode 100644 index 0000000000..5a9de74392 --- /dev/null +++ b/packages/shared-core/src/automations/steps/deleteRow.ts @@ -0,0 +1,56 @@ +import { + AutomationActionStepId, + AutomationStepType, + AutomationIOType, + AutomationCustomIOType, + AutomationFeature, + AutomationStepDefinition, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + description: "Delete a row from your database", + icon: "TableRowRemoveCenter", + name: "Delete Row", + tagline: "Delete a {{inputs.enriched.table.name}} row", + type: AutomationStepType.ACTION, + stepId: AutomationActionStepId.DELETE_ROW, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + inputs: {}, + schema: { + inputs: { + properties: { + tableId: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.TABLE, + title: "Table", + }, + id: { + type: AutomationIOType.STRING, + title: "Row ID", + }, + }, + required: ["tableId", "id"], + }, + outputs: { + properties: { + row: { + type: AutomationIOType.OBJECT, + customType: AutomationCustomIOType.ROW, + description: "The deleted row", + }, + response: { + type: AutomationIOType.OBJECT, + description: "The response from the table", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the deletion was successful", + }, + }, + required: ["row", "success"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/discord.ts b/packages/shared-core/src/automations/steps/discord.ts new file mode 100644 index 0000000000..906b970e1d --- /dev/null +++ b/packages/shared-core/src/automations/steps/discord.ts @@ -0,0 +1,60 @@ +import { + AutomationActionStepId, + AutomationStepType, + AutomationIOType, + AutomationFeature, + AutomationStepDefinition, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Discord Message", + tagline: "Send a message to a Discord server", + description: "Send a message to a Discord server", + icon: "ri-discord-line", + stepId: AutomationActionStepId.discord, + type: AutomationStepType.ACTION, + internal: false, + features: { + [AutomationFeature.LOOPING]: true, + }, + inputs: {}, + schema: { + inputs: { + properties: { + url: { + type: AutomationIOType.STRING, + title: "Discord Webhook URL", + }, + username: { + type: AutomationIOType.STRING, + title: "Bot Name", + }, + avatar_url: { + type: AutomationIOType.STRING, + title: "Bot Avatar URL", + }, + content: { + type: AutomationIOType.STRING, + title: "Message", + }, + }, + required: ["url", "content"], + }, + outputs: { + properties: { + httpStatus: { + type: AutomationIOType.NUMBER, + description: "The HTTP status code of the request", + }, + response: { + type: AutomationIOType.STRING, + description: "The response from the Discord Webhook", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the message sent successfully", + }, + }, + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/executeQuery.ts b/packages/shared-core/src/automations/steps/executeQuery.ts new file mode 100644 index 0000000000..bbb8b93d6b --- /dev/null +++ b/packages/shared-core/src/automations/steps/executeQuery.ts @@ -0,0 +1,59 @@ +import { + AutomationActionStepId, + AutomationCustomIOType, + AutomationFeature, + AutomationIOType, + AutomationStepDefinition, + AutomationStepType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "External Data Connector", + tagline: "Execute Data Connector", + icon: "Data", + description: "Execute a query in an external data connector", + type: AutomationStepType.ACTION, + stepId: AutomationActionStepId.EXECUTE_QUERY, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + inputs: {}, + schema: { + inputs: { + properties: { + query: { + type: AutomationIOType.OBJECT, + properties: { + queryId: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.QUERY, + }, + }, + customType: AutomationCustomIOType.QUERY_PARAMS, + title: "Parameters", + required: ["queryId"], + }, + }, + required: ["query"], + }, + outputs: { + properties: { + response: { + type: AutomationIOType.OBJECT, + description: "The response from the datasource execution", + }, + info: { + type: AutomationIOType.OBJECT, + description: + "Some query types may return extra data, like headers from a REST query", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the action was successful", + }, + }, + required: ["response", "success"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/executeScript.ts b/packages/shared-core/src/automations/steps/executeScript.ts new file mode 100644 index 0000000000..dcc52f2905 --- /dev/null +++ b/packages/shared-core/src/automations/steps/executeScript.ts @@ -0,0 +1,47 @@ +import { + AutomationActionStepId, + AutomationCustomIOType, + AutomationFeature, + AutomationIOType, + AutomationStepDefinition, + AutomationStepType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "JS Scripting", + tagline: "Execute JavaScript Code", + icon: "Code", + description: "Run a piece of JavaScript code in your automation", + type: AutomationStepType.ACTION, + internal: true, + stepId: AutomationActionStepId.EXECUTE_SCRIPT, + inputs: {}, + features: { + [AutomationFeature.LOOPING]: true, + }, + schema: { + inputs: { + properties: { + code: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.CODE, + title: "Code", + }, + }, + required: ["code"], + }, + outputs: { + properties: { + value: { + type: AutomationIOType.STRING, + description: "The result of the return statement", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the action was successful", + }, + }, + required: ["success"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/filter.ts b/packages/shared-core/src/automations/steps/filter.ts new file mode 100644 index 0000000000..70dcb6f66e --- /dev/null +++ b/packages/shared-core/src/automations/steps/filter.ts @@ -0,0 +1,69 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, +} from "@budibase/types" + +export const FilterConditions = { + EQUAL: "EQUAL", + NOT_EQUAL: "NOT_EQUAL", + GREATER_THAN: "GREATER_THAN", + LESS_THAN: "LESS_THAN", +} + +export const PrettyFilterConditions = { + [FilterConditions.EQUAL]: "Equals", + [FilterConditions.NOT_EQUAL]: "Not equals", + [FilterConditions.GREATER_THAN]: "Greater than", + [FilterConditions.LESS_THAN]: "Less than", +} + +export const definition: AutomationStepDefinition = { + name: "Condition", + tagline: "{{inputs.field}} {{inputs.condition}} {{inputs.value}}", + icon: "Branch2", + description: + "Conditionally halt automations which do not meet certain conditions", + type: AutomationStepType.LOGIC, + internal: true, + features: {}, + stepId: AutomationActionStepId.FILTER, + inputs: { + condition: FilterConditions.EQUAL, + }, + schema: { + inputs: { + properties: { + field: { + type: AutomationIOType.STRING, + title: "Reference Value", + }, + condition: { + type: AutomationIOType.STRING, + title: "Condition", + enum: Object.values(FilterConditions), + pretty: Object.values(PrettyFilterConditions), + }, + value: { + type: AutomationIOType.STRING, + title: "Comparison Value", + }, + }, + required: ["field", "condition", "value"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the action was successful", + }, + result: { + type: AutomationIOType.BOOLEAN, + description: "Whether the logic block passed", + }, + }, + required: ["success", "result"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/index.ts b/packages/shared-core/src/automations/steps/index.ts new file mode 100644 index 0000000000..d23c5622b8 --- /dev/null +++ b/packages/shared-core/src/automations/steps/index.ts @@ -0,0 +1,22 @@ +export * as bash from "./bash" +export * as branch from "./branch" +export * as collect from "./collect" +export * as createRow from "./createRow" +export * as delay from "./delay" +export * as deleteRow from "./deleteRow" +export * as discord from "./discord" +export * as executeQuery from "./executeQuery" +export * as executeScript from "./executeScript" +export * as filter from "./filter" +export * as loop from "./loop" +export * as make from "./make" +export * as n8n from "./n8n" +export * as openai from "./openai" +export * as outgoingWebhook from "./outgoingWebhook" +export * as queryRows from "./queryRows" +export * as sendSmtpEmail from "./sendSmtpEmail" +export * as serverLog from "./serverLog" +export * as slack from "./slack" +export * as triggerAutomationRun from "./triggerAutomationRun" +export * as updateRow from "./updateRow" +export * as zapier from "./zapier" diff --git a/packages/server/src/automations/steps/loop.ts b/packages/shared-core/src/automations/steps/loop.ts similarity index 100% rename from packages/server/src/automations/steps/loop.ts rename to packages/shared-core/src/automations/steps/loop.ts diff --git a/packages/shared-core/src/automations/steps/make.ts b/packages/shared-core/src/automations/steps/make.ts new file mode 100644 index 0000000000..4f9e6c40ad --- /dev/null +++ b/packages/shared-core/src/automations/steps/make.ts @@ -0,0 +1,55 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, + AutomationFeature, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Make Integration", + stepTitle: "Make", + tagline: "Trigger a Make scenario", + description: + "Performs a webhook call to Make and gets the response (if configured)", + icon: "ri-shut-down-line", + stepId: AutomationActionStepId.integromat, + type: AutomationStepType.ACTION, + internal: false, + features: { + [AutomationFeature.LOOPING]: true, + }, + inputs: {}, + schema: { + inputs: { + properties: { + url: { + type: AutomationIOType.STRING, + title: "Webhook URL", + }, + body: { + type: AutomationIOType.JSON, + title: "Payload", + }, + }, + required: ["url", "body"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether call was successful", + }, + httpStatus: { + type: AutomationIOType.NUMBER, + description: "The HTTP status code returned", + }, + response: { + type: AutomationIOType.OBJECT, + description: "The webhook response - this can have properties", + }, + }, + required: ["success", "response"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/n8n.ts b/packages/shared-core/src/automations/steps/n8n.ts new file mode 100644 index 0000000000..fcb407bcbf --- /dev/null +++ b/packages/shared-core/src/automations/steps/n8n.ts @@ -0,0 +1,65 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, + AutomationFeature, + HttpMethod, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "n8n Integration", + stepTitle: "n8n", + tagline: "Trigger an n8n workflow", + description: + "Performs a webhook call to n8n and gets the response (if configured)", + icon: "ri-shut-down-line", + stepId: AutomationActionStepId.n8n, + type: AutomationStepType.ACTION, + internal: false, + features: { + [AutomationFeature.LOOPING]: true, + }, + inputs: {}, + schema: { + inputs: { + properties: { + url: { + type: AutomationIOType.STRING, + title: "Webhook URL", + }, + method: { + type: AutomationIOType.STRING, + title: "Method", + enum: Object.values(HttpMethod), + }, + authorization: { + type: AutomationIOType.STRING, + title: "Authorization", + }, + body: { + type: AutomationIOType.JSON, + title: "Payload", + }, + }, + required: ["url", "method"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether call was successful", + }, + httpStatus: { + type: AutomationIOType.NUMBER, + description: "The HTTP status code returned", + }, + response: { + type: AutomationIOType.OBJECT, + description: "The webhook response - this can have properties", + }, + }, + required: ["success", "response"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/openai.ts b/packages/shared-core/src/automations/steps/openai.ts new file mode 100644 index 0000000000..dc25e62f96 --- /dev/null +++ b/packages/shared-core/src/automations/steps/openai.ts @@ -0,0 +1,56 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, +} from "@budibase/types" + +enum Model { + GPT_4O_MINI = "gpt-4o-mini", + GPT_4O = "gpt-4o", + GPT_4 = "gpt-4", + GPT_35_TURBO = "gpt-3.5-turbo", +} + +export const definition: AutomationStepDefinition = { + name: "OpenAI", + tagline: "Send prompts to ChatGPT", + icon: "Algorithm", + description: "Interact with the OpenAI ChatGPT API.", + type: AutomationStepType.ACTION, + internal: true, + features: {}, + stepId: AutomationActionStepId.OPENAI, + inputs: { + prompt: "", + }, + schema: { + inputs: { + properties: { + prompt: { + type: AutomationIOType.STRING, + title: "Prompt", + }, + model: { + type: AutomationIOType.STRING, + title: "Model", + enum: Object.values(Model), + }, + }, + required: ["prompt", "model"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the action was successful", + }, + response: { + type: AutomationIOType.STRING, + description: "What was output", + }, + }, + required: ["success", "response"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/outgoingWebhook.ts b/packages/shared-core/src/automations/steps/outgoingWebhook.ts new file mode 100644 index 0000000000..9e0b1b375b --- /dev/null +++ b/packages/shared-core/src/automations/steps/outgoingWebhook.ts @@ -0,0 +1,79 @@ +import { + AutomationActionStepId, + AutomationCustomIOType, + AutomationFeature, + AutomationIOType, + AutomationStepDefinition, + AutomationStepType, +} from "@budibase/types" + +enum RequestType { + POST = "POST", + GET = "GET", + PUT = "PUT", + DELETE = "DELETE", + PATCH = "PATCH", +} + +export const definition: AutomationStepDefinition = { + deprecated: true, + name: "Outgoing webhook", + tagline: "Send a {{inputs.requestMethod}} request", + icon: "Send", + description: "Send a request of specified method to a URL", + type: AutomationStepType.ACTION, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + stepId: AutomationActionStepId.OUTGOING_WEBHOOK, + inputs: { + requestMethod: "POST", + url: "http://", + requestBody: "{}", + headers: "{}", + }, + schema: { + inputs: { + properties: { + requestMethod: { + type: AutomationIOType.STRING, + enum: Object.values(RequestType), + title: "Request method", + }, + url: { + type: AutomationIOType.STRING, + title: "URL", + }, + requestBody: { + type: AutomationIOType.STRING, + title: "JSON Body", + customType: AutomationCustomIOType.WIDE, + }, + headers: { + type: AutomationIOType.STRING, + title: "Headers", + customType: AutomationCustomIOType.WIDE, + }, + }, + required: ["requestMethod", "url"], + }, + outputs: { + properties: { + response: { + type: AutomationIOType.OBJECT, + description: "The response from the webhook", + }, + httpStatus: { + type: AutomationIOType.NUMBER, + description: "The HTTP status code returned", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the action was successful", + }, + }, + required: ["response", "success"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/queryRows.ts b/packages/shared-core/src/automations/steps/queryRows.ts new file mode 100644 index 0000000000..31fec1e112 --- /dev/null +++ b/packages/shared-core/src/automations/steps/queryRows.ts @@ -0,0 +1,75 @@ +import { + AutomationActionStepId, + AutomationCustomIOType, + AutomationFeature, + AutomationIOType, + AutomationStepDefinition, + AutomationStepType, + SortOrder, +} from "@budibase/types" + +const SortOrderPretty = { + [SortOrder.ASCENDING]: "Ascending", + [SortOrder.DESCENDING]: "Descending", +} + +export const definition: AutomationStepDefinition = { + description: "Query rows from the database", + icon: "Search", + name: "Query rows", + tagline: "Query rows from {{inputs.enriched.table.name}} table", + type: AutomationStepType.ACTION, + stepId: AutomationActionStepId.QUERY_ROWS, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + inputs: {}, + schema: { + inputs: { + properties: { + tableId: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.TABLE, + title: "Table", + }, + filters: { + type: AutomationIOType.OBJECT, + customType: AutomationCustomIOType.FILTERS, + title: "Filtering", + }, + sortColumn: { + type: AutomationIOType.STRING, + title: "Sort Column", + customType: AutomationCustomIOType.COLUMN, + }, + sortOrder: { + type: AutomationIOType.STRING, + title: "Sort Order", + enum: Object.values(SortOrder), + pretty: Object.values(SortOrderPretty), + }, + limit: { + type: AutomationIOType.NUMBER, + title: "Limit", + customType: AutomationCustomIOType.QUERY_LIMIT, + }, + }, + required: ["tableId"], + }, + outputs: { + properties: { + rows: { + type: AutomationIOType.ARRAY, + customType: AutomationCustomIOType.ROWS, + description: "The rows that were found", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the query was successful", + }, + }, + required: ["rows", "success"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/sendSmtpEmail.ts b/packages/shared-core/src/automations/steps/sendSmtpEmail.ts new file mode 100644 index 0000000000..99ded7fdb3 --- /dev/null +++ b/packages/shared-core/src/automations/steps/sendSmtpEmail.ts @@ -0,0 +1,95 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, + AutomationFeature, + AutomationCustomIOType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + description: "Send an email using SMTP", + tagline: "Send SMTP email to {{inputs.to}}", + icon: "Email", + name: "Send Email (SMTP)", + type: AutomationStepType.ACTION, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + stepId: AutomationActionStepId.SEND_EMAIL_SMTP, + inputs: {}, + schema: { + inputs: { + properties: { + to: { + type: AutomationIOType.STRING, + title: "Send To", + }, + from: { + type: AutomationIOType.STRING, + title: "Send From", + }, + cc: { + type: AutomationIOType.STRING, + title: "CC", + }, + bcc: { + type: AutomationIOType.STRING, + title: "BCC", + }, + subject: { + type: AutomationIOType.STRING, + title: "Email Subject", + }, + contents: { + type: AutomationIOType.STRING, + title: "HTML Contents", + }, + addInvite: { + type: AutomationIOType.BOOLEAN, + title: "Add calendar invite", + }, + startTime: { + type: AutomationIOType.DATE, + title: "Start Time", + dependsOn: "addInvite", + }, + endTime: { + type: AutomationIOType.DATE, + title: "End Time", + dependsOn: "addInvite", + }, + summary: { + type: AutomationIOType.STRING, + title: "Meeting Summary", + dependsOn: "addInvite", + }, + location: { + type: AutomationIOType.STRING, + title: "Location", + dependsOn: "addInvite", + }, + attachments: { + type: AutomationIOType.ATTACHMENT, + customType: AutomationCustomIOType.MULTI_ATTACHMENTS, + title: "Attachments", + }, + }, + required: ["to", "from", "subject", "contents"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the email was sent", + }, + response: { + type: AutomationIOType.OBJECT, + description: "A response from the email client, this may be an error", + }, + }, + required: ["success"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/serverLog.ts b/packages/shared-core/src/automations/steps/serverLog.ts new file mode 100644 index 0000000000..44ffb84049 --- /dev/null +++ b/packages/shared-core/src/automations/steps/serverLog.ts @@ -0,0 +1,47 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, + AutomationFeature, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Backend log", + tagline: "Console log a value in the backend", + icon: "Monitoring", + description: "Logs the given text to the server (using console.log)", + type: AutomationStepType.ACTION, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + stepId: AutomationActionStepId.SERVER_LOG, + inputs: { + text: "", + }, + schema: { + inputs: { + properties: { + text: { + type: AutomationIOType.STRING, + title: "Log", + }, + }, + required: ["text"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the action was successful", + }, + message: { + type: AutomationIOType.STRING, + description: "What was output", + }, + }, + required: ["success", "message"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/slack.ts b/packages/shared-core/src/automations/steps/slack.ts new file mode 100644 index 0000000000..185e00a8ed --- /dev/null +++ b/packages/shared-core/src/automations/steps/slack.ts @@ -0,0 +1,52 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, + AutomationFeature, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Slack Message", + tagline: "Send a message to Slack", + description: "Send a message to Slack", + icon: "ri-slack-line", + stepId: AutomationActionStepId.slack, + type: AutomationStepType.ACTION, + internal: false, + features: { + [AutomationFeature.LOOPING]: true, + }, + inputs: {}, + schema: { + inputs: { + properties: { + url: { + type: AutomationIOType.STRING, + title: "Incoming Webhook URL", + }, + text: { + type: AutomationIOType.STRING, + title: "Message", + }, + }, + required: ["url", "text"], + }, + outputs: { + properties: { + httpStatus: { + type: AutomationIOType.NUMBER, + description: "The HTTP status code of the request", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the message sent successfully", + }, + response: { + type: AutomationIOType.STRING, + description: "The response from the Slack Webhook", + }, + }, + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/triggerAutomationRun.ts b/packages/shared-core/src/automations/steps/triggerAutomationRun.ts new file mode 100644 index 0000000000..3aa78b6015 --- /dev/null +++ b/packages/shared-core/src/automations/steps/triggerAutomationRun.ts @@ -0,0 +1,55 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, + AutomationCustomIOType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Trigger an automation", + tagline: "Triggers an automation synchronously", + icon: "Sync", + description: "Triggers an automation synchronously", + type: AutomationStepType.ACTION, + internal: true, + features: {}, + stepId: AutomationActionStepId.TRIGGER_AUTOMATION_RUN, + inputs: {}, + schema: { + inputs: { + properties: { + automation: { + type: AutomationIOType.OBJECT, + properties: { + automationId: { + type: AutomationIOType.STRING, + customType: AutomationCustomIOType.AUTOMATION, + }, + }, + customType: AutomationCustomIOType.AUTOMATION_FIELDS, + title: "automatioFields", + required: ["automationId"], + }, + timeout: { + type: AutomationIOType.NUMBER, + title: "Timeout (ms)", + }, + }, + required: ["automationId"], + }, + outputs: { + properties: { + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the automation was successful", + }, + value: { + type: AutomationIOType.OBJECT, + description: "Automation Result", + }, + }, + required: ["success", "value"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/updateRow.ts b/packages/shared-core/src/automations/steps/updateRow.ts new file mode 100644 index 0000000000..30f86214bb --- /dev/null +++ b/packages/shared-core/src/automations/steps/updateRow.ts @@ -0,0 +1,68 @@ +import { + AutomationActionStepId, + AutomationCustomIOType, + AutomationFeature, + AutomationIOType, + AutomationStepDefinition, + AutomationStepType, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Update Row", + tagline: "Update a {{inputs.enriched.table.name}} row", + icon: "Refresh", + description: "Update a row in your database", + type: AutomationStepType.ACTION, + internal: true, + features: { + [AutomationFeature.LOOPING]: true, + }, + stepId: AutomationActionStepId.UPDATE_ROW, + inputs: {}, + schema: { + inputs: { + properties: { + meta: { + type: AutomationIOType.OBJECT, + title: "Field settings", + }, + row: { + type: AutomationIOType.OBJECT, + customType: AutomationCustomIOType.ROW, + title: "Table", + }, + rowId: { + type: AutomationIOType.STRING, + title: "Row ID", + }, + }, + required: ["row", "rowId"], + }, + outputs: { + properties: { + row: { + type: AutomationIOType.OBJECT, + customType: AutomationCustomIOType.ROW, + description: "The updated row", + }, + response: { + type: AutomationIOType.OBJECT, + description: "The response from the table", + }, + success: { + type: AutomationIOType.BOOLEAN, + description: "Whether the action was successful", + }, + id: { + type: AutomationIOType.STRING, + description: "The identifier of the updated row", + }, + revision: { + type: AutomationIOType.STRING, + description: "The revision of the updated row", + }, + }, + required: ["success", "id", "revision"], + }, + }, +} diff --git a/packages/shared-core/src/automations/steps/zapier.ts b/packages/shared-core/src/automations/steps/zapier.ts new file mode 100644 index 0000000000..b1afd31def --- /dev/null +++ b/packages/shared-core/src/automations/steps/zapier.ts @@ -0,0 +1,48 @@ +import { + AutomationActionStepId, + AutomationStepDefinition, + AutomationStepType, + AutomationIOType, + AutomationFeature, +} from "@budibase/types" + +export const definition: AutomationStepDefinition = { + name: "Zapier Webhook", + stepId: AutomationActionStepId.zapier, + type: AutomationStepType.ACTION, + internal: false, + features: { + [AutomationFeature.LOOPING]: true, + }, + description: "Trigger a Zapier Zap via webhooks", + tagline: "Trigger a Zapier Zap", + icon: "ri-flashlight-line", + inputs: {}, + schema: { + inputs: { + properties: { + url: { + type: AutomationIOType.STRING, + title: "Webhook URL", + }, + body: { + type: AutomationIOType.JSON, + title: "Payload", + }, + }, + required: ["url"], + }, + outputs: { + properties: { + httpStatus: { + type: AutomationIOType.NUMBER, + description: "The HTTP status code of the request", + }, + response: { + type: AutomationIOType.STRING, + description: "The response from Zapier", + }, + }, + }, + }, +} diff --git a/packages/shared-core/src/index.ts b/packages/shared-core/src/index.ts index 0833f999ee..a4f4208f4a 100644 --- a/packages/shared-core/src/index.ts +++ b/packages/shared-core/src/index.ts @@ -5,3 +5,4 @@ export * as utils from "./utils" export * as sdk from "./sdk" export * from "./table" export * from "./themes" +export * as automations from "./automations"