diff --git a/packages/server/src/api/controllers/automation.ts b/packages/server/src/api/controllers/automation.ts index 3e68dcb0cb..f7e664964c 100644 --- a/packages/server/src/api/controllers/automation.ts +++ b/packages/server/src/api/controllers/automation.ts @@ -23,6 +23,7 @@ import { BBContext, } from "@budibase/types" import { getActionDefinitions as actionDefs } from "../../automations/actions" +import sdk from "src/sdk" async function getActionDefinitions() { return removeDeprecated(await actionDefs()) @@ -264,10 +265,9 @@ export async function trigger(ctx: BBContext) { const db = context.getAppDB() let automation = await db.get(ctx.params.id) - let hasCollectBlock = automation.definition.steps.some( - (step: any) => step.stepId === AutomationActionStepId.COLLECT - ) - if (hasCollectBlock) { + let hasCollectStep = sdk.automations.utils.checkForCollectStep(automation) + + if (hasCollectStep) { const response: AutomationResults = await triggers.externalTrigger( automation, { diff --git a/packages/server/src/api/controllers/webhook.ts b/packages/server/src/api/controllers/webhook.ts index 066b1e534d..01bb43046b 100644 --- a/packages/server/src/api/controllers/webhook.ts +++ b/packages/server/src/api/controllers/webhook.ts @@ -81,12 +81,9 @@ export async function trigger(ctx: BBContext) { if (webhook.action.type === WebhookActionType.AUTOMATION) { // trigger with both the pure request and then expand it // incase the user has produced a schema to bind to + let hasCollectStep = sdk.automations.utils.checkForCollectStep(target) - let hasCollectBlock = target.definition.steps.some( - (step: any) => step.stepId === AutomationActionStepId.COLLECT - ) - - if (hasCollectBlock && (await pro.features.isSyncWebhookEnabled())) { + if (hasCollectStep && (await pro.features.isSyncWebhookEnabled())) { const response = await triggers.externalTrigger( target, { diff --git a/packages/server/src/sdk/app/automations/index.ts b/packages/server/src/sdk/app/automations/index.ts index 1c9ce13455..16530cf085 100644 --- a/packages/server/src/sdk/app/automations/index.ts +++ b/packages/server/src/sdk/app/automations/index.ts @@ -1,5 +1,7 @@ import * as webhook from "./webhook" +import * as utils from "./utils" export default { webhook, + utils, } diff --git a/packages/server/src/sdk/app/automations/utils.ts b/packages/server/src/sdk/app/automations/utils.ts new file mode 100644 index 0000000000..79e70923f1 --- /dev/null +++ b/packages/server/src/sdk/app/automations/utils.ts @@ -0,0 +1,7 @@ +import { Automation, AutomationActionStepId } from "@budibase/types" + +export function checkForCollectStep(automation: Automation) { + return automation.definition.steps.some( + (step: any) => step.stepId === AutomationActionStepId.COLLECT + ) +}