2022-11-25 20:57:07 +01:00
|
|
|
import * as sendSmtpEmail from "./steps/sendSmtpEmail"
|
|
|
|
import * as createRow from "./steps/createRow"
|
|
|
|
import * as updateRow from "./steps/updateRow"
|
|
|
|
import * as deleteRow from "./steps/deleteRow"
|
|
|
|
import * as executeScript from "./steps/executeScript"
|
|
|
|
import * as executeQuery from "./steps/executeQuery"
|
|
|
|
import * as outgoingWebhook from "./steps/outgoingWebhook"
|
|
|
|
import * as serverLog from "./steps/serverLog"
|
|
|
|
import * as discord from "./steps/discord"
|
|
|
|
import * as slack from "./steps/slack"
|
|
|
|
import * as zapier from "./steps/zapier"
|
2024-02-15 14:05:03 +01:00
|
|
|
import * as n8n from "./steps/n8n"
|
2023-05-05 13:41:24 +02:00
|
|
|
import * as make from "./steps/make"
|
2022-11-25 20:57:07 +01:00
|
|
|
import * as filter from "./steps/filter"
|
|
|
|
import * as delay from "./steps/delay"
|
|
|
|
import * as queryRow from "./steps/queryRows"
|
|
|
|
import * as loop from "./steps/loop"
|
2023-05-09 13:10:20 +02:00
|
|
|
import * as collect from "./steps/collect"
|
2024-01-15 11:11:16 +01:00
|
|
|
import * as triggerAutomationRun from "./steps/triggerAutomationRun"
|
2022-11-25 20:57:07 +01:00
|
|
|
import env from "../environment"
|
2023-04-11 17:37:26 +02:00
|
|
|
import {
|
|
|
|
PluginType,
|
2024-07-31 23:18:00 +02:00
|
|
|
AutomationActionStepId,
|
|
|
|
ActionImplementations,
|
|
|
|
Hosting,
|
|
|
|
ActionImplementation,
|
2024-08-14 22:39:39 +02:00
|
|
|
AutomationStepDefinition,
|
2023-04-11 17:37:26 +02:00
|
|
|
} from "@budibase/types"
|
|
|
|
import sdk from "../sdk"
|
|
|
|
import { getAutomationPlugin } from "../utilities/fileSystem"
|
2020-09-10 16:00:21 +02:00
|
|
|
|
2024-07-31 23:18:00 +02:00
|
|
|
type ActionImplType = ActionImplementations<
|
|
|
|
typeof env.SELF_HOSTED extends "true" ? Hosting.SELF : Hosting.CLOUD
|
|
|
|
>
|
|
|
|
|
|
|
|
const ACTION_IMPLS: ActionImplType = {
|
2021-05-11 16:08:59 +02:00
|
|
|
SEND_EMAIL_SMTP: sendSmtpEmail.run,
|
2020-10-09 20:10:28 +02:00
|
|
|
CREATE_ROW: createRow.run,
|
|
|
|
UPDATE_ROW: updateRow.run,
|
|
|
|
DELETE_ROW: deleteRow.run,
|
2020-10-27 13:33:25 +01:00
|
|
|
OUTGOING_WEBHOOK: outgoingWebhook.run,
|
2021-03-26 15:56:34 +01:00
|
|
|
EXECUTE_SCRIPT: executeScript.run,
|
|
|
|
EXECUTE_QUERY: executeQuery.run,
|
2021-06-18 19:07:51 +02:00
|
|
|
SERVER_LOG: serverLog.run,
|
2021-09-14 12:28:39 +02:00
|
|
|
DELAY: delay.run,
|
|
|
|
FILTER: filter.run,
|
2021-09-15 20:02:44 +02:00
|
|
|
QUERY_ROWS: queryRow.run,
|
2023-05-09 13:10:20 +02:00
|
|
|
COLLECT: collect.run,
|
2024-01-16 17:22:11 +01:00
|
|
|
TRIGGER_AUTOMATION_RUN: triggerAutomationRun.run,
|
2021-09-03 18:36:00 +02:00
|
|
|
// these used to be lowercase step IDs, maintain for backwards compat
|
|
|
|
discord: discord.run,
|
2021-09-07 14:58:53 +02:00
|
|
|
slack: slack.run,
|
2021-09-03 18:36:00 +02:00
|
|
|
zapier: zapier.run,
|
2023-05-05 13:41:24 +02:00
|
|
|
integromat: make.run,
|
2024-02-15 14:05:03 +01:00
|
|
|
n8n: n8n.run,
|
2020-09-16 15:00:04 +02:00
|
|
|
}
|
2024-07-31 23:18:00 +02:00
|
|
|
|
2024-08-14 22:39:39 +02:00
|
|
|
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,
|
|
|
|
// 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,
|
|
|
|
}
|
2020-09-22 15:07:22 +02:00
|
|
|
|
2021-10-13 18:03:19 +02:00
|
|
|
// 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")
|
2023-05-24 18:17:23 +02:00
|
|
|
const openai = require("./steps/openai")
|
|
|
|
|
2022-11-25 20:57:07 +01:00
|
|
|
// @ts-ignore
|
2021-10-13 18:03:19 +02:00
|
|
|
ACTION_IMPLS["EXECUTE_BASH"] = bash.run
|
2022-11-25 20:57:07 +01:00
|
|
|
// @ts-ignore
|
2023-04-11 00:48:54 +02:00
|
|
|
BUILTIN_ACTION_DEFINITIONS["EXECUTE_BASH"] = bash.definition
|
2024-07-31 23:18:00 +02:00
|
|
|
// @ts-ignore
|
2023-05-24 18:17:23 +02:00
|
|
|
ACTION_IMPLS.OPENAI = openai.run
|
|
|
|
BUILTIN_ACTION_DEFINITIONS.OPENAI = openai.definition
|
2023-04-11 00:48:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getActionDefinitions() {
|
|
|
|
const actionDefinitions = BUILTIN_ACTION_DEFINITIONS
|
|
|
|
if (env.SELF_HOSTED) {
|
2023-04-11 17:37:26 +02:00
|
|
|
const plugins = await sdk.plugins.fetch(PluginType.AUTOMATION)
|
2023-04-11 00:48:54 +02:00
|
|
|
for (let plugin of plugins) {
|
2024-08-14 22:39:39 +02:00
|
|
|
const schema = plugin.schema.schema as AutomationStepDefinition
|
2023-04-11 00:48:54 +02:00
|
|
|
actionDefinitions[schema.stepId] = {
|
|
|
|
...schema,
|
|
|
|
custom: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return actionDefinitions
|
2021-10-13 18:03:19 +02:00
|
|
|
}
|
|
|
|
|
2021-03-15 15:11:13 +01:00
|
|
|
/* istanbul ignore next */
|
2024-07-31 23:18:00 +02:00
|
|
|
export async function getAction(
|
|
|
|
stepId: AutomationActionStepId
|
|
|
|
): Promise<ActionImplementation<any, any> | undefined> {
|
|
|
|
if (ACTION_IMPLS[stepId as keyof ActionImplType] != null) {
|
|
|
|
return ACTION_IMPLS[stepId as keyof ActionImplType]
|
2023-04-11 17:37:26 +02:00
|
|
|
}
|
2024-07-31 23:18:00 +02:00
|
|
|
|
2023-04-11 17:37:26 +02:00
|
|
|
// must be a plugin
|
|
|
|
if (env.SELF_HOSTED) {
|
|
|
|
const plugins = await sdk.plugins.fetch(PluginType.AUTOMATION)
|
|
|
|
const found = plugins.find(plugin => plugin.schema.schema.stepId === stepId)
|
|
|
|
if (!found) {
|
|
|
|
throw new Error(`Unable to find action implementation for "${stepId}"`)
|
|
|
|
}
|
|
|
|
return (await getAutomationPlugin(found)).action
|
2020-09-10 16:00:21 +02:00
|
|
|
}
|
|
|
|
}
|