More typing fixes.

This commit is contained in:
mike12345567 2024-12-02 15:26:12 +00:00
parent bc3658e2cb
commit fe9e4d1c5a
4 changed files with 27 additions and 11 deletions

View File

@ -10,6 +10,7 @@ import {
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../sdk" import sdk from "../../sdk"
import * as pro from "@budibase/pro" import * as pro from "@budibase/pro"
import { isAutomationResults } from "../../automations/triggers"
const toJsonSchema = require("to-json-schema") const toJsonSchema = require("to-json-schema")
const validate = require("jsonschema").validate const validate = require("jsonschema").validate
@ -94,12 +95,16 @@ export async function trigger(ctx: BBContext) {
{ getResponses: true } { getResponses: true }
) )
if (triggers.isAutomationResults(response)) {
let collectedValue = response.steps.find( let collectedValue = response.steps.find(
(step: any) => step.stepId === AutomationActionStepId.COLLECT (step: any) => step.stepId === AutomationActionStepId.COLLECT
) )
ctx.status = 200 ctx.status = 200
ctx.body = collectedValue.outputs ctx.body = collectedValue?.outputs
} else {
ctx.throw(400, "Automation did not have a collect block.")
}
} else { } else {
await triggers.externalTrigger(target, { await triggers.externalTrigger(target, {
body: ctx.request.body, body: ctx.request.body,

View File

@ -3,7 +3,6 @@ import {
AutomationStepDefinition, AutomationStepDefinition,
AutomationStepType, AutomationStepType,
AutomationIOType, AutomationIOType,
AutomationResults,
Automation, Automation,
AutomationCustomIOType, AutomationCustomIOType,
TriggerAutomationStepInputs, TriggerAutomationStepInputs,
@ -78,7 +77,7 @@ export async function run({
const db = context.getAppDB() const db = context.getAppDB()
let automation = await db.get<Automation>(inputs.automation.automationId) let automation = await db.get<Automation>(inputs.automation.automationId)
const response: AutomationResults = await triggers.externalTrigger( const response = await triggers.externalTrigger(
automation, automation,
{ {
fields: { ...fieldParams }, fields: { ...fieldParams },
@ -88,10 +87,14 @@ export async function run({
{ getResponses: true } { getResponses: true }
) )
if (triggers.isAutomationResults(response)) {
return { return {
success: true, success: true,
value: response.steps, value: response.steps,
} }
} else {
throw new Error("Automation did not have a collect block")
}
} }
} else { } else {
return { return {

View File

@ -148,6 +148,14 @@ function rowPassesFilters(row: Row, filters: SearchFilters) {
return filteredRows.length > 0 return filteredRows.length > 0
} }
export function isAutomationResults(
response: AutomationResults | DidNotTriggerResponse | AutomationJob
): response is AutomationResults {
return (
response !== null && "steps" in response && Array.isArray(response.steps)
)
}
export async function externalTrigger( export async function externalTrigger(
automation: Automation, automation: Automation,
params: { params: {

View File

@ -621,7 +621,7 @@ export default class TestConfiguration {
} }
async unpublish() { async unpublish() {
const response = await this._req(appController.unpublish, { const response = await this._req(appController.unpublish, undefined, {
appId: this.appId, appId: this.appId,
}) })
this.prodAppId = undefined this.prodAppId = undefined