diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index b7d55ee2d4..1d1a758c13 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -733,10 +733,7 @@ const automationActions = store => ({ automation.definition.trigger.inputs.rowActionId ) } else { - await API.deleteAutomation({ - automationId: automation?._id, - automationRev: automation?._rev, - }) + await API.deleteAutomation(automation?._id, automation?._rev) } store.update(state => { @@ -818,10 +815,7 @@ const automationActions = store => ({ test: async (automation, testData) => { let result try { - result = await API.testAutomation({ - automationId: automation?._id, - testData, - }) + result = await API.testAutomation(automation?._id, testData) } catch (err) { const message = err.message || err.status || JSON.stringify(err) throw `Automation test failed - ${message}` @@ -875,10 +869,7 @@ const automationActions = store => ({ }) }, clearLogErrors: async ({ automationId, appId } = {}) => { - return await API.clearAutomationLogErrors({ - automationId, - appId, - }) + return await API.clearAutomationLogErrors(automationId, appId) }, addTestDataToAutomation: async data => { let newAutomation = cloneDeep(get(selectedAutomation).data) diff --git a/packages/frontend-core/src/api/automations.js b/packages/frontend-core/src/api/automations.ts similarity index 64% rename from packages/frontend-core/src/api/automations.js rename to packages/frontend-core/src/api/automations.ts index 37a834cf04..a348dc52a7 100644 --- a/packages/frontend-core/src/api/automations.js +++ b/packages/frontend-core/src/api/automations.ts @@ -1,10 +1,52 @@ -export const buildAutomationEndpoints = API => ({ +import { + Automation, + AutomationLogPage, + DeleteAutomationResponse, + FetchAutomationResponse, +} from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface AutomationEndpoints { + getAutomations: () => Promise + createAutomation: ( + automation: Automation + ) => Promise<{ message: string; automation: Automation }> + updateAutomation: ( + automation: Automation + ) => Promise<{ message: string; automation: Automation }> + deleteAutomation: ( + automationId: string, + automationRev: string + ) => Promise + clearAutomationLogErrors: ( + automationId: string, + appId: string + ) => Promise<{ message: string }> + + // Missing request or response types + triggerAutomation: ( + automationId: string, + fields: Record, + timeout?: number + ) => Promise + testAutomation: ( + automationdId: string, + testData: Record + ) => Promise + getAutomationDefinitions: () => Promise + getAutomationLogs: (options: any) => Promise +} + +export const buildAutomationEndpoints = ( + API: BaseAPIClient +): AutomationEndpoints => ({ /** * Executes an automation. Must have "App Action" trigger. * @param automationId the ID of the automation to trigger * @param fields the fields to trigger the automation with + * @param timeout an optional timeout override */ - triggerAutomation: async ({ automationId, fields, timeout }) => { + triggerAutomation: async (automationId, fields, timeout) => { return await API.post({ url: `/api/automations/${automationId}/trigger`, body: { fields, timeout }, @@ -16,7 +58,7 @@ export const buildAutomationEndpoints = API => ({ * @param automationId the ID of the automation to test * @param testData the test data to run against the automation */ - testAutomation: async ({ automationId, testData }) => { + testAutomation: async (automationId, testData) => { return await API.post({ url: `/api/automations/${automationId}/test`, body: testData, @@ -68,7 +110,7 @@ export const buildAutomationEndpoints = API => ({ * @param automationId the ID of the automation to delete * @param automationRev the rev of the automation to delete */ - deleteAutomation: async ({ automationId, automationRev }) => { + deleteAutomation: async (automationId, automationRev) => { return await API.delete({ url: `/api/automations/${automationId}/${automationRev}`, }) @@ -99,7 +141,7 @@ export const buildAutomationEndpoints = API => ({ * @param automationId optional - the ID of the automation to clear errors for. * @param appId The app ID to clear errors for. */ - clearAutomationLogErrors: async ({ automationId, appId }) => { + clearAutomationLogErrors: async (automationId, appId) => { return await API.delete({ url: "/api/automations/logs", body: { diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 5df7f777c0..1e027b9157 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -4,6 +4,7 @@ import { AppEndpoints } from "./app" import { AttachmentEndpoints } from "./attachments" import { AuditLogsEndpoints } from "./auditLogs" import { AuthEndpoints } from "./auth" +import { AutomationEndpoints } from "./automations" export enum HTTPMethod { POST = "POST", @@ -52,4 +53,5 @@ export type APIClient = BaseAPIClient & AppEndpoints & AttachmentEndpoints & AuditLogsEndpoints & - AuthEndpoints & { [key: string]: any } + AuthEndpoints & + AutomationEndpoints & { [key: string]: any } diff --git a/packages/frontend-core/tsconfig.json b/packages/frontend-core/tsconfig.json new file mode 100644 index 0000000000..6e0cb00434 --- /dev/null +++ b/packages/frontend-core/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "paths": { + "@budibase/types": ["../types/src"], + "@budibase/shared-core": ["../shared-core/src"] + } + } +}