Update automation endpoints to use TS
This commit is contained in:
parent
679f08dcc4
commit
7ab6a1bbec
|
@ -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)
|
||||
|
|
|
@ -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<FetchAutomationResponse>
|
||||
createAutomation: (
|
||||
automation: Automation
|
||||
) => Promise<{ message: string; automation: Automation }>
|
||||
updateAutomation: (
|
||||
automation: Automation
|
||||
) => Promise<{ message: string; automation: Automation }>
|
||||
deleteAutomation: (
|
||||
automationId: string,
|
||||
automationRev: string
|
||||
) => Promise<DeleteAutomationResponse>
|
||||
clearAutomationLogErrors: (
|
||||
automationId: string,
|
||||
appId: string
|
||||
) => Promise<{ message: string }>
|
||||
|
||||
// Missing request or response types
|
||||
triggerAutomation: (
|
||||
automationId: string,
|
||||
fields: Record<string, any>,
|
||||
timeout?: number
|
||||
) => Promise<any>
|
||||
testAutomation: (
|
||||
automationdId: string,
|
||||
testData: Record<string, any>
|
||||
) => Promise<any>
|
||||
getAutomationDefinitions: () => Promise<any>
|
||||
getAutomationLogs: (options: any) => Promise<AutomationLogPage>
|
||||
}
|
||||
|
||||
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: {
|
|
@ -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 }
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@budibase/types": ["../types/src"],
|
||||
"@budibase/shared-core": ["../shared-core/src"]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue