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
|
automation.definition.trigger.inputs.rowActionId
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
await API.deleteAutomation({
|
await API.deleteAutomation(automation?._id, automation?._rev)
|
||||||
automationId: automation?._id,
|
|
||||||
automationRev: automation?._rev,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
|
@ -818,10 +815,7 @@ const automationActions = store => ({
|
||||||
test: async (automation, testData) => {
|
test: async (automation, testData) => {
|
||||||
let result
|
let result
|
||||||
try {
|
try {
|
||||||
result = await API.testAutomation({
|
result = await API.testAutomation(automation?._id, testData)
|
||||||
automationId: automation?._id,
|
|
||||||
testData,
|
|
||||||
})
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = err.message || err.status || JSON.stringify(err)
|
const message = err.message || err.status || JSON.stringify(err)
|
||||||
throw `Automation test failed - ${message}`
|
throw `Automation test failed - ${message}`
|
||||||
|
@ -875,10 +869,7 @@ const automationActions = store => ({
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
clearLogErrors: async ({ automationId, appId } = {}) => {
|
clearLogErrors: async ({ automationId, appId } = {}) => {
|
||||||
return await API.clearAutomationLogErrors({
|
return await API.clearAutomationLogErrors(automationId, appId)
|
||||||
automationId,
|
|
||||||
appId,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
addTestDataToAutomation: async data => {
|
addTestDataToAutomation: async data => {
|
||||||
let newAutomation = cloneDeep(get(selectedAutomation).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.
|
* Executes an automation. Must have "App Action" trigger.
|
||||||
* @param automationId the ID of the automation to trigger
|
* @param automationId the ID of the automation to trigger
|
||||||
* @param fields the fields to trigger the automation with
|
* @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({
|
return await API.post({
|
||||||
url: `/api/automations/${automationId}/trigger`,
|
url: `/api/automations/${automationId}/trigger`,
|
||||||
body: { fields, timeout },
|
body: { fields, timeout },
|
||||||
|
@ -16,7 +58,7 @@ export const buildAutomationEndpoints = API => ({
|
||||||
* @param automationId the ID of the automation to test
|
* @param automationId the ID of the automation to test
|
||||||
* @param testData the test data to run against the automation
|
* @param testData the test data to run against the automation
|
||||||
*/
|
*/
|
||||||
testAutomation: async ({ automationId, testData }) => {
|
testAutomation: async (automationId, testData) => {
|
||||||
return await API.post({
|
return await API.post({
|
||||||
url: `/api/automations/${automationId}/test`,
|
url: `/api/automations/${automationId}/test`,
|
||||||
body: testData,
|
body: testData,
|
||||||
|
@ -68,7 +110,7 @@ export const buildAutomationEndpoints = API => ({
|
||||||
* @param automationId the ID of the automation to delete
|
* @param automationId the ID of the automation to delete
|
||||||
* @param automationRev the rev 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({
|
return await API.delete({
|
||||||
url: `/api/automations/${automationId}/${automationRev}`,
|
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 automationId optional - the ID of the automation to clear errors for.
|
||||||
* @param appId The app ID 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({
|
return await API.delete({
|
||||||
url: "/api/automations/logs",
|
url: "/api/automations/logs",
|
||||||
body: {
|
body: {
|
|
@ -4,6 +4,7 @@ import { AppEndpoints } from "./app"
|
||||||
import { AttachmentEndpoints } from "./attachments"
|
import { AttachmentEndpoints } from "./attachments"
|
||||||
import { AuditLogsEndpoints } from "./auditLogs"
|
import { AuditLogsEndpoints } from "./auditLogs"
|
||||||
import { AuthEndpoints } from "./auth"
|
import { AuthEndpoints } from "./auth"
|
||||||
|
import { AutomationEndpoints } from "./automations"
|
||||||
|
|
||||||
export enum HTTPMethod {
|
export enum HTTPMethod {
|
||||||
POST = "POST",
|
POST = "POST",
|
||||||
|
@ -52,4 +53,5 @@ export type APIClient = BaseAPIClient &
|
||||||
AppEndpoints &
|
AppEndpoints &
|
||||||
AttachmentEndpoints &
|
AttachmentEndpoints &
|
||||||
AuditLogsEndpoints &
|
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