From f450cf6912596373e1b93b3a79ac811e6c1a9b2d Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 3 Feb 2025 10:46:03 +0000 Subject: [PATCH 1/3] Move trigger definitions to shared-core. --- packages/server/src/automations/triggers.ts | 2 +- packages/server/src/automations/utils.ts | 2 +- packages/server/src/sdk/app/automations/crud.ts | 2 +- packages/server/src/sdk/app/rowActions/crud.ts | 2 +- packages/server/src/threads/automation.ts | 2 +- packages/server/tsconfig.json | 14 +++++++++++++- packages/shared-core/src/automations/index.ts | 1 + .../src/automations/triggers}/app.ts | 0 .../src/automations/triggers}/cron.ts | 0 .../src/automations/triggers}/index.ts | 0 .../src/automations/triggers}/rowAction.ts | 0 .../src/automations/triggers}/rowDeleted.ts | 0 .../src/automations/triggers}/rowSaved.ts | 0 .../src/automations/triggers}/rowUpdated.ts | 0 .../src/automations/triggers}/webhook.ts | 0 15 files changed, 19 insertions(+), 6 deletions(-) rename packages/{server/src/automations/triggerInfo => shared-core/src/automations/triggers}/app.ts (100%) rename packages/{server/src/automations/triggerInfo => shared-core/src/automations/triggers}/cron.ts (100%) rename packages/{server/src/automations/triggerInfo => shared-core/src/automations/triggers}/index.ts (100%) rename packages/{server/src/automations/triggerInfo => shared-core/src/automations/triggers}/rowAction.ts (100%) rename packages/{server/src/automations/triggerInfo => shared-core/src/automations/triggers}/rowDeleted.ts (100%) rename packages/{server/src/automations/triggerInfo => shared-core/src/automations/triggers}/rowSaved.ts (100%) rename packages/{server/src/automations/triggerInfo => shared-core/src/automations/triggers}/rowUpdated.ts (100%) rename packages/{server/src/automations/triggerInfo => shared-core/src/automations/triggers}/webhook.ts (100%) diff --git a/packages/server/src/automations/triggers.ts b/packages/server/src/automations/triggers.ts index a9317772d9..bfd1b5c47f 100644 --- a/packages/server/src/automations/triggers.ts +++ b/packages/server/src/automations/triggers.ts @@ -1,7 +1,7 @@ import emitter from "../events/index" import { getAutomationParams, isDevAppID } from "../db/utils" import { coerce } from "../utilities/rowProcessor" -import { definitions } from "./triggerInfo" +import { definitions } from "../../../shared-core/src/automations/triggers" // need this to call directly, so we can get a response import { automationQueue } from "./bullboard" import { checkTestFlag } from "../utilities/redis" diff --git a/packages/server/src/automations/utils.ts b/packages/server/src/automations/utils.ts index 292b288a70..74cc64a95e 100644 --- a/packages/server/src/automations/utils.ts +++ b/packages/server/src/automations/utils.ts @@ -1,5 +1,5 @@ import { Thread, ThreadType } from "../threads" -import { definitions } from "./triggerInfo" +import { definitions } from "../../../shared-core/src/automations/triggers" import { automationQueue } from "./bullboard" import { updateEntityMetadata } from "../utilities" import { context, db as dbCore, utils } from "@budibase/backend-core" diff --git a/packages/server/src/sdk/app/automations/crud.ts b/packages/server/src/sdk/app/automations/crud.ts index d16ae2d042..487f93cfa6 100644 --- a/packages/server/src/sdk/app/automations/crud.ts +++ b/packages/server/src/sdk/app/automations/crud.ts @@ -13,7 +13,7 @@ import { HTTPError, db as dbCore, } from "@budibase/backend-core" -import { definitions } from "../../../automations/triggerInfo" +import { definitions } from "../../../../../shared-core/src/automations/triggers" import automations from "." export interface PersistedAutomation extends Automation { diff --git a/packages/server/src/sdk/app/rowActions/crud.ts b/packages/server/src/sdk/app/rowActions/crud.ts index 1153677685..ca6f7b8f1a 100644 --- a/packages/server/src/sdk/app/rowActions/crud.ts +++ b/packages/server/src/sdk/app/rowActions/crud.ts @@ -9,7 +9,7 @@ import { } from "@budibase/types" import { generateRowActionsID } from "../../../db/utils" import automations from "../automations" -import { definitions as TRIGGER_DEFINITIONS } from "../../../automations/triggerInfo" +import { definitions as TRIGGER_DEFINITIONS } from "../../../../../shared-core/src/automations/triggers" import * as triggers from "../../../automations/triggers" import sdk from "../.." diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 2790d8fda6..1a56139e52 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -11,7 +11,7 @@ import { replaceFakeBindings } from "../automations/loopUtils" import { dataFilters, helpers, utils } from "@budibase/shared-core" import { default as AutomationEmitter } from "../events/AutomationEmitter" import { generateAutomationMetadataID, isProdAppID } from "../db/utils" -import { definitions as triggerDefs } from "../automations/triggerInfo" +import { definitions as triggerDefs } from "../../../shared-core/src/automations/triggers" import { AutomationErrors, MAX_AUTOMATION_RECURRING_ERRORS } from "../constants" import { storeLog } from "../automations/logging" import { diff --git a/packages/server/tsconfig.json b/packages/server/tsconfig.json index c962785810..475f0b3e2d 100644 --- a/packages/server/tsconfig.json +++ b/packages/server/tsconfig.json @@ -4,6 +4,18 @@ "require": ["tsconfig-paths/register"], "swc": true }, - "include": ["src/**/*", "specs", "__mocks__"], + "include": [ + "src/**/*", + "specs", + "__mocks__", + "../shared-core/src/automations/triggers/app.ts", + "../shared-core/src/automations/triggers/cron.ts", + "../shared-core/src/automations/triggers/index.ts", + "../shared-core/src/automations/triggers/rowAction.ts", + "../shared-core/src/automations/triggers/rowDeleted.ts", + "../shared-core/src/automations/triggers/rowSaved.ts", + "../shared-core/src/automations/triggers/rowUpdated.ts", + "../shared-core/src/automations/triggers/webhook.ts" + ], "exclude": ["node_modules", "dist"] } diff --git a/packages/shared-core/src/automations/index.ts b/packages/shared-core/src/automations/index.ts index 064796845e..db38233494 100644 --- a/packages/shared-core/src/automations/index.ts +++ b/packages/shared-core/src/automations/index.ts @@ -1 +1,2 @@ export * as steps from "./steps/index" +export * as triggers from "./triggers/index" diff --git a/packages/server/src/automations/triggerInfo/app.ts b/packages/shared-core/src/automations/triggers/app.ts similarity index 100% rename from packages/server/src/automations/triggerInfo/app.ts rename to packages/shared-core/src/automations/triggers/app.ts diff --git a/packages/server/src/automations/triggerInfo/cron.ts b/packages/shared-core/src/automations/triggers/cron.ts similarity index 100% rename from packages/server/src/automations/triggerInfo/cron.ts rename to packages/shared-core/src/automations/triggers/cron.ts diff --git a/packages/server/src/automations/triggerInfo/index.ts b/packages/shared-core/src/automations/triggers/index.ts similarity index 100% rename from packages/server/src/automations/triggerInfo/index.ts rename to packages/shared-core/src/automations/triggers/index.ts diff --git a/packages/server/src/automations/triggerInfo/rowAction.ts b/packages/shared-core/src/automations/triggers/rowAction.ts similarity index 100% rename from packages/server/src/automations/triggerInfo/rowAction.ts rename to packages/shared-core/src/automations/triggers/rowAction.ts diff --git a/packages/server/src/automations/triggerInfo/rowDeleted.ts b/packages/shared-core/src/automations/triggers/rowDeleted.ts similarity index 100% rename from packages/server/src/automations/triggerInfo/rowDeleted.ts rename to packages/shared-core/src/automations/triggers/rowDeleted.ts diff --git a/packages/server/src/automations/triggerInfo/rowSaved.ts b/packages/shared-core/src/automations/triggers/rowSaved.ts similarity index 100% rename from packages/server/src/automations/triggerInfo/rowSaved.ts rename to packages/shared-core/src/automations/triggers/rowSaved.ts diff --git a/packages/server/src/automations/triggerInfo/rowUpdated.ts b/packages/shared-core/src/automations/triggers/rowUpdated.ts similarity index 100% rename from packages/server/src/automations/triggerInfo/rowUpdated.ts rename to packages/shared-core/src/automations/triggers/rowUpdated.ts diff --git a/packages/server/src/automations/triggerInfo/webhook.ts b/packages/shared-core/src/automations/triggers/webhook.ts similarity index 100% rename from packages/server/src/automations/triggerInfo/webhook.ts rename to packages/shared-core/src/automations/triggers/webhook.ts From 32b0e34b663e3001c9d9497eba1e2820b9744ce4 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 4 Feb 2025 10:56:08 +0000 Subject: [PATCH 2/3] respond to pr feedback --- packages/server/src/automations/triggers.ts | 8 ++++---- packages/server/src/automations/utils.ts | 9 ++++++--- packages/server/src/sdk/app/automations/crud.ts | 4 ++-- packages/server/src/sdk/app/rowActions/crud.ts | 4 ++-- packages/server/tsconfig.json | 14 +------------- 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/packages/server/src/automations/triggers.ts b/packages/server/src/automations/triggers.ts index bfd1b5c47f..2ac90f3f9c 100644 --- a/packages/server/src/automations/triggers.ts +++ b/packages/server/src/automations/triggers.ts @@ -1,7 +1,7 @@ import emitter from "../events/index" import { getAutomationParams, isDevAppID } from "../db/utils" import { coerce } from "../utilities/rowProcessor" -import { definitions } from "../../../shared-core/src/automations/triggers" +import { automations } from "@budibase/shared-core" // need this to call directly, so we can get a response import { automationQueue } from "./bullboard" import { checkTestFlag } from "../utilities/redis" @@ -26,7 +26,7 @@ import { import { executeInThread } from "../threads/automation" import { dataFilters, sdk } from "@budibase/shared-core" -export const TRIGGER_DEFINITIONS = definitions +export const TRIGGER_DEFINITIONS = automations.triggers.definitions const JOB_OPTS = { removeOnComplete: true, removeOnFail: true, @@ -273,8 +273,8 @@ async function checkTriggerFilters( } if ( - trigger.stepId === definitions.ROW_UPDATED.stepId || - trigger.stepId === definitions.ROW_SAVED.stepId + trigger.stepId === automations.triggers.definitions.ROW_UPDATED.stepId || + trigger.stepId === automations.triggers.definitions.ROW_SAVED.stepId ) { const newRow = await automationUtils.cleanUpRow(tableId, event.row) return rowPassesFilters(newRow, filters) diff --git a/packages/server/src/automations/utils.ts b/packages/server/src/automations/utils.ts index 74cc64a95e..9bfcc6cf8a 100644 --- a/packages/server/src/automations/utils.ts +++ b/packages/server/src/automations/utils.ts @@ -1,5 +1,5 @@ import { Thread, ThreadType } from "../threads" -import { definitions } from "../../../shared-core/src/automations/triggers" +import { automations } from "@budibase/shared-core" import { automationQueue } from "./bullboard" import { updateEntityMetadata } from "../utilities" import { context, db as dbCore, utils } from "@budibase/backend-core" @@ -19,7 +19,7 @@ import { automationsEnabled } from "../features" import { helpers, REBOOT_CRON } from "@budibase/shared-core" import tracer from "dd-trace" -const CRON_STEP_ID = definitions.CRON.stepId +const CRON_STEP_ID = automations.triggers.definitions.CRON.stepId let Runner: Thread if (automationsEnabled()) { Runner = new Thread(ThreadType.AUTOMATION) @@ -255,7 +255,10 @@ export async function cleanupAutomations(appId: any) { * @return if it is recurring (cron). */ export function isRecurring(automation: Automation) { - return automation.definition.trigger.stepId === definitions.CRON.stepId + return ( + automation.definition.trigger.stepId === + automations.triggers.definitions.CRON.stepId + ) } export function isErrorInOutput(output: { diff --git a/packages/server/src/sdk/app/automations/crud.ts b/packages/server/src/sdk/app/automations/crud.ts index 487f93cfa6..cd8af1e548 100644 --- a/packages/server/src/sdk/app/automations/crud.ts +++ b/packages/server/src/sdk/app/automations/crud.ts @@ -13,7 +13,7 @@ import { HTTPError, db as dbCore, } from "@budibase/backend-core" -import { definitions } from "../../../../../shared-core/src/automations/triggers" +import { automations as sharedAutomations } from "@budibase/shared-core" import automations from "." export interface PersistedAutomation extends Automation { @@ -202,7 +202,7 @@ export async function remove(automationId: string, rev: string) { * written to DB (this does not write to DB as it would be wasteful to repeat). */ async function checkForWebhooks({ oldAuto, newAuto }: any) { - const WH_STEP_ID = definitions.WEBHOOK.stepId + const WH_STEP_ID = sharedAutomations.triggers.definitions.WEBHOOK.stepId const appId = context.getAppId() if (!appId) { diff --git a/packages/server/src/sdk/app/rowActions/crud.ts b/packages/server/src/sdk/app/rowActions/crud.ts index ca6f7b8f1a..64bb4729ce 100644 --- a/packages/server/src/sdk/app/rowActions/crud.ts +++ b/packages/server/src/sdk/app/rowActions/crud.ts @@ -9,7 +9,7 @@ import { } from "@budibase/types" import { generateRowActionsID } from "../../../db/utils" import automations from "../automations" -import { definitions as TRIGGER_DEFINITIONS } from "../../../../../shared-core/src/automations/triggers" +import { automations as sharedAutomations } from "@budibase/shared-core" import * as triggers from "../../../automations/triggers" import sdk from "../.." @@ -59,7 +59,7 @@ export async function create(tableId: string, rowAction: { name: string }) { definition: { trigger: { id: "trigger", - ...TRIGGER_DEFINITIONS.ROW_ACTION, + ...sharedAutomations.triggers.definitions.ROW_ACTION, stepId: AutomationTriggerStepId.ROW_ACTION, inputs: { tableId, diff --git a/packages/server/tsconfig.json b/packages/server/tsconfig.json index 475f0b3e2d..c962785810 100644 --- a/packages/server/tsconfig.json +++ b/packages/server/tsconfig.json @@ -4,18 +4,6 @@ "require": ["tsconfig-paths/register"], "swc": true }, - "include": [ - "src/**/*", - "specs", - "__mocks__", - "../shared-core/src/automations/triggers/app.ts", - "../shared-core/src/automations/triggers/cron.ts", - "../shared-core/src/automations/triggers/index.ts", - "../shared-core/src/automations/triggers/rowAction.ts", - "../shared-core/src/automations/triggers/rowDeleted.ts", - "../shared-core/src/automations/triggers/rowSaved.ts", - "../shared-core/src/automations/triggers/rowUpdated.ts", - "../shared-core/src/automations/triggers/webhook.ts" - ], + "include": ["src/**/*", "specs", "__mocks__"], "exclude": ["node_modules", "dist"] } From 0a27087f5c1c23d8d755217a3521388132906a69 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 4 Feb 2025 10:58:22 +0000 Subject: [PATCH 3/3] missed a bit --- packages/server/src/threads/automation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 1a56139e52..174efa0fe0 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -11,7 +11,7 @@ import { replaceFakeBindings } from "../automations/loopUtils" import { dataFilters, helpers, utils } from "@budibase/shared-core" import { default as AutomationEmitter } from "../events/AutomationEmitter" import { generateAutomationMetadataID, isProdAppID } from "../db/utils" -import { definitions as triggerDefs } from "../../../shared-core/src/automations/triggers" +import { automations } from "@budibase/shared-core" import { AutomationErrors, MAX_AUTOMATION_RECURRING_ERRORS } from "../constants" import { storeLog } from "../automations/logging" import { @@ -50,7 +50,7 @@ import env from "../environment" import tracer from "dd-trace" threadUtils.threadSetup() -const CRON_STEP_ID = triggerDefs.CRON.stepId +const CRON_STEP_ID = automations.triggers.definitions.CRON.stepId const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED } function getLoopIterations(loopStep: LoopStep) {