From 0da9ad02a7d854b6e6421e2b0713e3cd6f0ff00f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 5 Dec 2024 12:34:59 +0000 Subject: [PATCH] Update automation endpoints with new types --- packages/frontend-core/src/api/automations.ts | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/packages/frontend-core/src/api/automations.ts b/packages/frontend-core/src/api/automations.ts index a348dc52a7..e87999e55b 100644 --- a/packages/frontend-core/src/api/automations.ts +++ b/packages/frontend-core/src/api/automations.ts @@ -1,19 +1,30 @@ import { - Automation, - AutomationLogPage, + ClearAutomationLogRequest, + ClearAutomationLogResponse, + CreateAutomationRequest, + CreateAutomationResponse, DeleteAutomationResponse, FetchAutomationResponse, + GetAutomationStepDefinitionsResponse, + SearchAutomationLogsRequest, + SearchAutomationLogsResponse, + TestAutomationRequest, + TestAutomationResponse, + TriggerAutomationRequest, + TriggerAutomationResponse, + UpdateAutomationRequest, + UpdateAutomationResponse, } from "@budibase/types" import { BaseAPIClient } from "./types" export interface AutomationEndpoints { getAutomations: () => Promise createAutomation: ( - automation: Automation - ) => Promise<{ message: string; automation: Automation }> + automation: CreateAutomationRequest + ) => Promise updateAutomation: ( - automation: Automation - ) => Promise<{ message: string; automation: Automation }> + automation: UpdateAutomationRequest + ) => Promise deleteAutomation: ( automationId: string, automationRev: string @@ -21,20 +32,20 @@ export interface AutomationEndpoints { clearAutomationLogErrors: ( automationId: string, appId: string - ) => Promise<{ message: string }> - - // Missing request or response types + ) => Promise triggerAutomation: ( automationId: string, fields: Record, - timeout?: number - ) => Promise + timeout: number + ) => Promise testAutomation: ( automationdId: string, - testData: Record - ) => Promise - getAutomationDefinitions: () => Promise - getAutomationLogs: (options: any) => Promise + data: TestAutomationRequest + ) => Promise + getAutomationDefinitions: () => Promise + getAutomationLogs: ( + options: SearchAutomationLogsRequest + ) => Promise } export const buildAutomationEndpoints = ( @@ -44,10 +55,10 @@ export const buildAutomationEndpoints = ( * 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 + * @param timeout a timeout override */ triggerAutomation: async (automationId, fields, timeout) => { - return await API.post({ + return await API.post({ url: `/api/automations/${automationId}/trigger`, body: { fields, timeout }, }) @@ -56,12 +67,12 @@ export const buildAutomationEndpoints = ( /** * Tests an automation with data. * @param automationId the ID of the automation to test - * @param testData the test data to run against the automation + * @param data the test data to run against the automation */ - testAutomation: async (automationId, testData) => { + testAutomation: async (automationId, data) => { return await API.post({ url: `/api/automations/${automationId}/test`, - body: testData, + body: data, }) }, @@ -118,20 +129,11 @@ export const buildAutomationEndpoints = ( /** * Get the logs for the app, or by automation ID. - * @param automationId The ID of the automation to get logs for. - * @param startDate An ISO date string to state the start of the date range. - * @param status The status, error or success. - * @param page The page to retrieve. */ - getAutomationLogs: async ({ automationId, startDate, status, page }) => { + getAutomationLogs: async data => { return await API.post({ url: "/api/automations/logs/search", - body: { - automationId, - startDate, - status, - page, - }, + body: data, }) }, @@ -142,7 +144,10 @@ export const buildAutomationEndpoints = ( * @param appId The app ID to clear errors for. */ clearAutomationLogErrors: async (automationId, appId) => { - return await API.delete({ + return await API.delete< + ClearAutomationLogRequest, + ClearAutomationLogResponse + >({ url: "/api/automations/logs", body: { appId,