2021-05-11 13:02:29 +02:00
|
|
|
const sendEmail = require("./steps/sendgridEmail")
|
2020-10-09 20:10:28 +02:00
|
|
|
const createRow = require("./steps/createRow")
|
|
|
|
const updateRow = require("./steps/updateRow")
|
|
|
|
const deleteRow = require("./steps/deleteRow")
|
2020-09-16 15:00:04 +02:00
|
|
|
const createUser = require("./steps/createUser")
|
2021-03-26 15:56:34 +01:00
|
|
|
const executeScript = require("./steps/executeScript")
|
|
|
|
const executeQuery = require("./steps/executeQuery")
|
2020-10-27 13:33:25 +01:00
|
|
|
const outgoingWebhook = require("./steps/outgoingWebhook")
|
2020-10-28 21:35:06 +01:00
|
|
|
const env = require("../environment")
|
2020-09-18 17:50:52 +02:00
|
|
|
const Sentry = require("@sentry/node")
|
2021-03-23 18:54:02 +01:00
|
|
|
const {
|
|
|
|
automationInit,
|
|
|
|
getExternalAutomationStep,
|
|
|
|
} = require("../utilities/fileSystem")
|
2020-09-10 16:00:21 +02:00
|
|
|
|
2020-09-16 15:00:04 +02:00
|
|
|
const BUILTIN_ACTIONS = {
|
|
|
|
SEND_EMAIL: sendEmail.run,
|
2020-10-09 20:10:28 +02:00
|
|
|
CREATE_ROW: createRow.run,
|
|
|
|
UPDATE_ROW: updateRow.run,
|
|
|
|
DELETE_ROW: deleteRow.run,
|
2020-09-16 15:00:04 +02:00
|
|
|
CREATE_USER: createUser.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,
|
2020-09-16 15:00:04 +02:00
|
|
|
}
|
|
|
|
const BUILTIN_DEFINITIONS = {
|
|
|
|
SEND_EMAIL: sendEmail.definition,
|
2020-10-09 20:10:28 +02:00
|
|
|
CREATE_ROW: createRow.definition,
|
|
|
|
UPDATE_ROW: updateRow.definition,
|
|
|
|
DELETE_ROW: deleteRow.definition,
|
2020-09-16 15:00:04 +02:00
|
|
|
CREATE_USER: createUser.definition,
|
2020-10-27 13:33:25 +01:00
|
|
|
OUTGOING_WEBHOOK: outgoingWebhook.definition,
|
2021-03-26 15:56:34 +01:00
|
|
|
EXECUTE_SCRIPT: executeScript.definition,
|
|
|
|
EXECUTE_QUERY: executeQuery.definition,
|
2020-09-10 16:00:21 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 17:50:52 +02:00
|
|
|
let MANIFEST = null
|
|
|
|
|
2021-03-15 15:11:13 +01:00
|
|
|
/* istanbul ignore next */
|
2020-09-22 15:07:22 +02:00
|
|
|
function buildBundleName(pkgName, version) {
|
|
|
|
return `${pkgName}@${version}.min.js`
|
|
|
|
}
|
|
|
|
|
2021-03-15 15:11:13 +01:00
|
|
|
/* istanbul ignore next */
|
2021-05-03 09:31:09 +02:00
|
|
|
module.exports.getAction = async function (actionName) {
|
2020-09-10 16:00:21 +02:00
|
|
|
if (BUILTIN_ACTIONS[actionName] != null) {
|
|
|
|
return BUILTIN_ACTIONS[actionName]
|
|
|
|
}
|
2021-02-17 14:40:14 +01:00
|
|
|
// worker pools means that a worker may not have manifest
|
2021-03-24 19:21:23 +01:00
|
|
|
if (env.isProd() && MANIFEST == null) {
|
2021-02-17 14:40:14 +01:00
|
|
|
MANIFEST = await module.exports.init()
|
|
|
|
}
|
2020-09-18 17:50:52 +02:00
|
|
|
// env setup to get async packages
|
|
|
|
if (!MANIFEST || !MANIFEST.packages || !MANIFEST.packages[actionName]) {
|
|
|
|
return null
|
|
|
|
}
|
2020-09-22 15:07:22 +02:00
|
|
|
const pkg = MANIFEST.packages[actionName]
|
|
|
|
const bundleName = buildBundleName(pkg.stepId, pkg.version)
|
2021-03-23 18:54:02 +01:00
|
|
|
return getExternalAutomationStep(pkg.stepId, pkg.version, bundleName)
|
2020-09-18 17:50:52 +02:00
|
|
|
}
|
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
module.exports.init = async function () {
|
2020-09-18 17:50:52 +02:00
|
|
|
try {
|
2021-03-23 18:54:02 +01:00
|
|
|
MANIFEST = await automationInit()
|
2020-09-22 15:37:09 +02:00
|
|
|
module.exports.DEFINITIONS =
|
|
|
|
MANIFEST && MANIFEST.packages
|
|
|
|
? Object.assign(MANIFEST.packages, BUILTIN_DEFINITIONS)
|
|
|
|
: BUILTIN_DEFINITIONS
|
2020-09-18 17:50:52 +02:00
|
|
|
} catch (err) {
|
2021-02-17 14:40:14 +01:00
|
|
|
console.error(err)
|
2020-09-18 17:50:52 +02:00
|
|
|
Sentry.captureException(err)
|
|
|
|
}
|
2021-02-17 14:40:14 +01:00
|
|
|
return MANIFEST
|
2020-09-10 16:00:21 +02:00
|
|
|
}
|
2020-09-16 15:00:04 +02:00
|
|
|
|
2021-03-11 19:29:48 +01:00
|
|
|
// definitions will have downloaded ones added to it, while builtin won't
|
2020-09-18 17:50:52 +02:00
|
|
|
module.exports.DEFINITIONS = BUILTIN_DEFINITIONS
|
2020-09-16 15:00:04 +02:00
|
|
|
module.exports.BUILTIN_DEFINITIONS = BUILTIN_DEFINITIONS
|