Merge branch 'master' of github.com:budibase/budibase into remove-mocks-2
This commit is contained in:
commit
57fd9e8d3a
|
@ -266,9 +266,9 @@ export const getProdAppId = () => {
|
||||||
return conversions.getProdAppID(appId)
|
return conversions.getProdAppID(appId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doInEnvironmentContext(
|
export function doInEnvironmentContext<T>(
|
||||||
values: Record<string, string>,
|
values: Record<string, string>,
|
||||||
task: any
|
task: () => T
|
||||||
) {
|
) {
|
||||||
if (!values) {
|
if (!values) {
|
||||||
throw new Error("Must supply environment variables.")
|
throw new Error("Must supply environment variables.")
|
||||||
|
|
|
@ -15,23 +15,27 @@ const conversion: Record<DurationType, number> = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Duration {
|
export class Duration {
|
||||||
|
constructor(public ms: number) {}
|
||||||
|
|
||||||
|
to(type: DurationType) {
|
||||||
|
return this.ms / conversion[type]
|
||||||
|
}
|
||||||
|
|
||||||
|
toMs() {
|
||||||
|
return this.ms
|
||||||
|
}
|
||||||
|
|
||||||
|
toSeconds() {
|
||||||
|
return this.to(DurationType.SECONDS)
|
||||||
|
}
|
||||||
|
|
||||||
static convert(from: DurationType, to: DurationType, duration: number) {
|
static convert(from: DurationType, to: DurationType, duration: number) {
|
||||||
const milliseconds = duration * conversion[from]
|
const milliseconds = duration * conversion[from]
|
||||||
return milliseconds / conversion[to]
|
return milliseconds / conversion[to]
|
||||||
}
|
}
|
||||||
|
|
||||||
static from(from: DurationType, duration: number) {
|
static from(from: DurationType, duration: number) {
|
||||||
return {
|
return new Duration(duration * conversion[from])
|
||||||
to: (to: DurationType) => {
|
|
||||||
return Duration.convert(from, to, duration)
|
|
||||||
},
|
|
||||||
toMs: () => {
|
|
||||||
return Duration.convert(from, DurationType.MILLISECONDS, duration)
|
|
||||||
},
|
|
||||||
toSeconds: () => {
|
|
||||||
return Duration.convert(from, DurationType.SECONDS, duration)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromSeconds(duration: number) {
|
static fromSeconds(duration: number) {
|
||||||
|
|
|
@ -2,3 +2,4 @@ export * from "./hashing"
|
||||||
export * from "./utils"
|
export * from "./utils"
|
||||||
export * from "./stringUtils"
|
export * from "./stringUtils"
|
||||||
export * from "./Duration"
|
export * from "./Duration"
|
||||||
|
export * from "./time"
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { Duration } from "./Duration"
|
||||||
|
|
||||||
|
export async function time<T>(f: () => Promise<T>): Promise<[T, Duration]> {
|
||||||
|
const start = performance.now()
|
||||||
|
const result = await f()
|
||||||
|
return [result, Duration.fromMilliseconds(performance.now() - start)]
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import {
|
||||||
import {
|
import {
|
||||||
AutomationTriggerStepId,
|
AutomationTriggerStepId,
|
||||||
AutomationEventType,
|
AutomationEventType,
|
||||||
AutomationStepType,
|
|
||||||
AutomationActionStepId,
|
AutomationActionStepId,
|
||||||
Automation,
|
Automation,
|
||||||
AutomationStep,
|
AutomationStep,
|
||||||
|
@ -26,10 +25,14 @@ import {
|
||||||
UILogicalOperator,
|
UILogicalOperator,
|
||||||
EmptyFilterOption,
|
EmptyFilterOption,
|
||||||
AutomationIOType,
|
AutomationIOType,
|
||||||
AutomationStepSchema,
|
|
||||||
AutomationTriggerSchema,
|
|
||||||
BranchPath,
|
BranchPath,
|
||||||
BlockDefinitions,
|
BlockDefinitions,
|
||||||
|
isBranchStep,
|
||||||
|
isTrigger,
|
||||||
|
isRowUpdateTrigger,
|
||||||
|
isRowSaveTrigger,
|
||||||
|
isAppTrigger,
|
||||||
|
BranchStep,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { ActionStepID } from "@/constants/backend/automations"
|
import { ActionStepID } from "@/constants/backend/automations"
|
||||||
import { FIELDS } from "@/constants/backend"
|
import { FIELDS } from "@/constants/backend"
|
||||||
|
@ -291,16 +294,16 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
let result: (AutomationStep | AutomationTrigger)[] = []
|
let result: (AutomationStep | AutomationTrigger)[] = []
|
||||||
pathWay.forEach(path => {
|
pathWay.forEach(path => {
|
||||||
const { stepIdx, branchIdx } = path
|
const { stepIdx, branchIdx } = path
|
||||||
let last = result.length ? result[result.length - 1] : []
|
|
||||||
if (!result.length) {
|
if (!result.length) {
|
||||||
// Preceeding steps.
|
// Preceeding steps.
|
||||||
result = steps.slice(0, stepIdx + 1)
|
result = steps.slice(0, stepIdx + 1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (last && "inputs" in last) {
|
let last = result[result.length - 1]
|
||||||
|
if (isBranchStep(last)) {
|
||||||
if (Number.isInteger(branchIdx)) {
|
if (Number.isInteger(branchIdx)) {
|
||||||
const branchId = last.inputs.branches[branchIdx].id
|
const branchId = last.inputs.branches[branchIdx].id
|
||||||
const children = last.inputs.children[branchId]
|
const children = last.inputs.children?.[branchId] || []
|
||||||
const stepChildren = children.slice(0, stepIdx + 1)
|
const stepChildren = children.slice(0, stepIdx + 1)
|
||||||
// Preceeding steps.
|
// Preceeding steps.
|
||||||
result = result.concat(stepChildren)
|
result = result.concat(stepChildren)
|
||||||
|
@ -473,23 +476,28 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
id: block.id,
|
id: block.id,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
const branches: Branch[] = block.inputs?.branches || []
|
|
||||||
|
|
||||||
branches.forEach((branch, bIdx) => {
|
if (isBranchStep(block)) {
|
||||||
block.inputs?.children[branch.id].forEach(
|
const branches = block.inputs?.branches || []
|
||||||
(bBlock: AutomationStep, sIdx: number, array: AutomationStep[]) => {
|
const children = block.inputs?.children || {}
|
||||||
const ended =
|
|
||||||
array.length - 1 === sIdx && !bBlock.inputs?.branches?.length
|
branches.forEach((branch, bIdx) => {
|
||||||
treeTraverse(bBlock, pathToCurrentNode, sIdx, bIdx, ended)
|
children[branch.id].forEach(
|
||||||
}
|
(bBlock: AutomationStep, sIdx: number, array: AutomationStep[]) => {
|
||||||
)
|
const ended = array.length - 1 === sIdx && !branches.length
|
||||||
})
|
treeTraverse(bBlock, pathToCurrentNode, sIdx, bIdx, ended)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
terminating = terminating && !branches.length
|
||||||
|
}
|
||||||
|
|
||||||
store.actions.registerBlock(
|
store.actions.registerBlock(
|
||||||
blockRefs,
|
blockRefs,
|
||||||
block,
|
block,
|
||||||
pathToCurrentNode,
|
pathToCurrentNode,
|
||||||
terminating && !branches.length
|
terminating
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,7 +583,6 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
pathBlock.stepId === ActionStepID.LOOP &&
|
pathBlock.stepId === ActionStepID.LOOP &&
|
||||||
pathBlock.blockToLoop in blocks
|
pathBlock.blockToLoop in blocks
|
||||||
}
|
}
|
||||||
const isTrigger = pathBlock.type === AutomationStepType.TRIGGER
|
|
||||||
|
|
||||||
if (isLoopBlock && loopBlockCount == 0) {
|
if (isLoopBlock && loopBlockCount == 0) {
|
||||||
schema = {
|
schema = {
|
||||||
|
@ -586,17 +593,14 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const icon = isTrigger
|
const icon = isTrigger(pathBlock)
|
||||||
? pathBlock.icon
|
? pathBlock.icon
|
||||||
: isLoopBlock
|
: isLoopBlock
|
||||||
? "Reuse"
|
? "Reuse"
|
||||||
: pathBlock.icon
|
: pathBlock.icon
|
||||||
|
|
||||||
if (blockIdx === 0 && isTrigger) {
|
if (blockIdx === 0 && isTrigger(pathBlock)) {
|
||||||
if (
|
if (isRowUpdateTrigger(pathBlock) || isRowSaveTrigger(pathBlock)) {
|
||||||
pathBlock.event === AutomationEventType.ROW_UPDATE ||
|
|
||||||
pathBlock.event === AutomationEventType.ROW_SAVE
|
|
||||||
) {
|
|
||||||
let table: any = get(tables).list.find(
|
let table: any = get(tables).list.find(
|
||||||
(table: Table) => table._id === pathBlock.inputs.tableId
|
(table: Table) => table._id === pathBlock.inputs.tableId
|
||||||
)
|
)
|
||||||
|
@ -608,7 +612,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete schema.row
|
delete schema.row
|
||||||
} else if (pathBlock.event === AutomationEventType.APP_TRIGGER) {
|
} else if (isAppTrigger(pathBlock)) {
|
||||||
schema = Object.fromEntries(
|
schema = Object.fromEntries(
|
||||||
Object.keys(pathBlock.inputs.fields || []).map(key => [
|
Object.keys(pathBlock.inputs.fields || []).map(key => [
|
||||||
key,
|
key,
|
||||||
|
@ -915,8 +919,10 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
]
|
]
|
||||||
|
|
||||||
let cache:
|
let cache:
|
||||||
| AutomationStepSchema<AutomationActionStepId>
|
| AutomationStep
|
||||||
| AutomationTriggerSchema<AutomationTriggerStepId>
|
| AutomationTrigger
|
||||||
|
| AutomationStep[]
|
||||||
|
| undefined = undefined
|
||||||
|
|
||||||
pathWay.forEach((path, pathIdx, array) => {
|
pathWay.forEach((path, pathIdx, array) => {
|
||||||
const { stepIdx, branchIdx } = path
|
const { stepIdx, branchIdx } = path
|
||||||
|
@ -938,9 +944,13 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (Number.isInteger(branchIdx)) {
|
if (
|
||||||
|
Number.isInteger(branchIdx) &&
|
||||||
|
!Array.isArray(cache) &&
|
||||||
|
isBranchStep(cache)
|
||||||
|
) {
|
||||||
const branchId = cache.inputs.branches[branchIdx].id
|
const branchId = cache.inputs.branches[branchIdx].id
|
||||||
const children = cache.inputs.children[branchId]
|
const children = cache.inputs.children?.[branchId] || []
|
||||||
|
|
||||||
if (final) {
|
if (final) {
|
||||||
insertBlock(children, stepIdx)
|
insertBlock(children, stepIdx)
|
||||||
|
@ -1090,7 +1100,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
branchLeft: async (
|
branchLeft: async (
|
||||||
pathTo: Array<any>,
|
pathTo: Array<any>,
|
||||||
automation: Automation,
|
automation: Automation,
|
||||||
block: AutomationStep
|
block: BranchStep
|
||||||
) => {
|
) => {
|
||||||
const update = store.actions.shiftBranch(pathTo, block)
|
const update = store.actions.shiftBranch(pathTo, block)
|
||||||
if (update) {
|
if (update) {
|
||||||
|
@ -1113,7 +1123,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
branchRight: async (
|
branchRight: async (
|
||||||
pathTo: Array<BranchPath>,
|
pathTo: Array<BranchPath>,
|
||||||
automation: Automation,
|
automation: Automation,
|
||||||
block: AutomationStep
|
block: BranchStep
|
||||||
) => {
|
) => {
|
||||||
const update = store.actions.shiftBranch(pathTo, block, 1)
|
const update = store.actions.shiftBranch(pathTo, block, 1)
|
||||||
if (update) {
|
if (update) {
|
||||||
|
@ -1133,7 +1143,7 @@ const automationActions = (store: AutomationStore) => ({
|
||||||
* @param {Number} direction - the direction of the swap. Defaults to -1 for left, add 1 for right
|
* @param {Number} direction - the direction of the swap. Defaults to -1 for left, add 1 for right
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
shiftBranch: (pathTo: Array<any>, block: AutomationStep, direction = -1) => {
|
shiftBranch: (pathTo: Array<any>, block: BranchStep, direction = -1) => {
|
||||||
let newBlock = cloneDeep(block)
|
let newBlock = cloneDeep(block)
|
||||||
const branchPath = pathTo.at(-1)
|
const branchPath = pathTo.at(-1)
|
||||||
const targetIdx = branchPath.branchIdx
|
const targetIdx = branchPath.branchIdx
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
UIComponentError,
|
UIComponentError,
|
||||||
ComponentDefinition,
|
ComponentDefinition,
|
||||||
DependsOnComponentSetting,
|
DependsOnComponentSetting,
|
||||||
|
Screen,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { queries } from "./queries"
|
import { queries } from "./queries"
|
||||||
import { views } from "./views"
|
import { views } from "./views"
|
||||||
|
@ -66,6 +67,7 @@ export const screenComponentErrorList = derived(
|
||||||
if (!$selectedScreen) {
|
if (!$selectedScreen) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
const screen = $selectedScreen
|
||||||
|
|
||||||
const datasources = {
|
const datasources = {
|
||||||
...reduceBy("_id", $tables.list),
|
...reduceBy("_id", $tables.list),
|
||||||
|
@ -79,7 +81,9 @@ export const screenComponentErrorList = derived(
|
||||||
const errors: UIComponentError[] = []
|
const errors: UIComponentError[] = []
|
||||||
|
|
||||||
function checkComponentErrors(component: Component, ancestors: string[]) {
|
function checkComponentErrors(component: Component, ancestors: string[]) {
|
||||||
errors.push(...getInvalidDatasources(component, datasources, definitions))
|
errors.push(
|
||||||
|
...getInvalidDatasources(screen, component, datasources, definitions)
|
||||||
|
)
|
||||||
errors.push(...getMissingRequiredSettings(component, definitions))
|
errors.push(...getMissingRequiredSettings(component, definitions))
|
||||||
errors.push(...getMissingAncestors(component, definitions, ancestors))
|
errors.push(...getMissingAncestors(component, definitions, ancestors))
|
||||||
|
|
||||||
|
@ -95,6 +99,7 @@ export const screenComponentErrorList = derived(
|
||||||
)
|
)
|
||||||
|
|
||||||
function getInvalidDatasources(
|
function getInvalidDatasources(
|
||||||
|
screen: Screen,
|
||||||
component: Component,
|
component: Component,
|
||||||
datasources: Record<string, any>,
|
datasources: Record<string, any>,
|
||||||
definitions: Record<string, ComponentDefinition>
|
definitions: Record<string, ComponentDefinition>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit eb96d8b2f2029033b0f758078ed30c888e8fb249
|
Subproject commit 45f5673d5e5ab3c22deb6663cea2e31a628aa133
|
|
@ -13,6 +13,7 @@ import sdk from "../../../sdk"
|
||||||
import {
|
import {
|
||||||
ConfigType,
|
ConfigType,
|
||||||
FieldType,
|
FieldType,
|
||||||
|
FilterCondition,
|
||||||
isDidNotTriggerResponse,
|
isDidNotTriggerResponse,
|
||||||
SettingsConfig,
|
SettingsConfig,
|
||||||
Table,
|
Table,
|
||||||
|
@ -20,12 +21,9 @@ import {
|
||||||
import { mocks } from "@budibase/backend-core/tests"
|
import { mocks } from "@budibase/backend-core/tests"
|
||||||
import { removeDeprecated } from "../../../automations/utils"
|
import { removeDeprecated } from "../../../automations/utils"
|
||||||
import { createAutomationBuilder } from "../../../automations/tests/utilities/AutomationTestBuilder"
|
import { createAutomationBuilder } from "../../../automations/tests/utilities/AutomationTestBuilder"
|
||||||
import { automations } from "@budibase/shared-core"
|
|
||||||
import { basicTable } from "../../../tests/utilities/structures"
|
import { basicTable } from "../../../tests/utilities/structures"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
|
||||||
const FilterConditions = automations.steps.filter.FilterConditions
|
|
||||||
|
|
||||||
const MAX_RETRIES = 4
|
const MAX_RETRIES = 4
|
||||||
const {
|
const {
|
||||||
basicAutomation,
|
basicAutomation,
|
||||||
|
@ -487,15 +485,40 @@ describe("/automations", () => {
|
||||||
expect(events.automation.created).not.toHaveBeenCalled()
|
expect(events.automation.created).not.toHaveBeenCalled()
|
||||||
expect(events.automation.triggerUpdated).not.toHaveBeenCalled()
|
expect(events.automation.triggerUpdated).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can update an input field", async () => {
|
||||||
|
const { automation } = await createAutomationBuilder(config)
|
||||||
|
.onRowDeleted({ tableId: "tableId" })
|
||||||
|
.serverLog({ text: "test" })
|
||||||
|
.save()
|
||||||
|
|
||||||
|
automation.definition.trigger.inputs.tableId = "newTableId"
|
||||||
|
const { automation: updatedAutomation } =
|
||||||
|
await config.api.automation.update(automation)
|
||||||
|
|
||||||
|
expect(updatedAutomation.definition.trigger.inputs.tableId).toEqual(
|
||||||
|
"newTableId"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("cannot update a readonly field", async () => {
|
||||||
|
const { automation } = await createAutomationBuilder(config)
|
||||||
|
.onRowAction({ tableId: "tableId" })
|
||||||
|
.serverLog({ text: "test" })
|
||||||
|
.save()
|
||||||
|
|
||||||
|
automation.definition.trigger.inputs.tableId = "newTableId"
|
||||||
|
await config.api.automation.update(automation, {
|
||||||
|
status: 400,
|
||||||
|
body: {
|
||||||
|
message: "Field tableId is readonly and it cannot be modified",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
it("return all the automations for an instance", async () => {
|
it("return all the automations for an instance", async () => {
|
||||||
const fetchResponse = await config.api.automation.fetch()
|
|
||||||
for (const auto of fetchResponse.automations) {
|
|
||||||
await config.api.automation.delete(auto)
|
|
||||||
}
|
|
||||||
|
|
||||||
const { automation: automation1 } = await config.api.automation.post(
|
const { automation: automation1 } = await config.api.automation.post(
|
||||||
newAutomation()
|
newAutomation()
|
||||||
)
|
)
|
||||||
|
@ -594,7 +617,7 @@ describe("/automations", () => {
|
||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
inputs: {
|
inputs: {
|
||||||
condition: FilterConditions.EQUAL,
|
condition: FilterCondition.EQUAL,
|
||||||
field: "{{ trigger.row.City }}",
|
field: "{{ trigger.row.City }}",
|
||||||
value: "{{ trigger.oldRow.City }}",
|
value: "{{ trigger.oldRow.City }}",
|
||||||
},
|
},
|
||||||
|
|
|
@ -27,6 +27,8 @@ import {
|
||||||
Hosting,
|
Hosting,
|
||||||
ActionImplementation,
|
ActionImplementation,
|
||||||
AutomationStepDefinition,
|
AutomationStepDefinition,
|
||||||
|
AutomationStepInputs,
|
||||||
|
AutomationStepOutputs,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import sdk from "../sdk"
|
import sdk from "../sdk"
|
||||||
import { getAutomationPlugin } from "../utilities/fileSystem"
|
import { getAutomationPlugin } from "../utilities/fileSystem"
|
||||||
|
@ -120,11 +122,15 @@ export async function getActionDefinitions(): Promise<
|
||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
export async function getAction(
|
export async function getAction<
|
||||||
stepId: AutomationActionStepId
|
TStep extends AutomationActionStepId,
|
||||||
): Promise<ActionImplementation<any, any> | undefined> {
|
TInputs = AutomationStepInputs<TStep>,
|
||||||
|
TOutputs = AutomationStepOutputs<TStep>
|
||||||
|
>(stepId: TStep): Promise<ActionImplementation<TInputs, TOutputs> | undefined> {
|
||||||
if (ACTION_IMPLS[stepId as keyof ActionImplType] != null) {
|
if (ACTION_IMPLS[stepId as keyof ActionImplType] != null) {
|
||||||
return ACTION_IMPLS[stepId as keyof ActionImplType]
|
return ACTION_IMPLS[
|
||||||
|
stepId as keyof ActionImplType
|
||||||
|
] as unknown as ActionImplementation<TInputs, TOutputs>
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be a plugin
|
// must be a plugin
|
||||||
|
|
|
@ -6,10 +6,10 @@ import {
|
||||||
import sdk from "../sdk"
|
import sdk from "../sdk"
|
||||||
import {
|
import {
|
||||||
AutomationAttachment,
|
AutomationAttachment,
|
||||||
|
BaseIOStructure,
|
||||||
|
FieldSchema,
|
||||||
FieldType,
|
FieldType,
|
||||||
Row,
|
Row,
|
||||||
LoopStepType,
|
|
||||||
LoopStepInputs,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { objectStore, context } from "@budibase/backend-core"
|
import { objectStore, context } from "@budibase/backend-core"
|
||||||
import * as uuid from "uuid"
|
import * as uuid from "uuid"
|
||||||
|
@ -32,33 +32,34 @@ import path from "path"
|
||||||
* primitive types.
|
* primitive types.
|
||||||
*/
|
*/
|
||||||
export function cleanInputValues<T extends Record<string, any>>(
|
export function cleanInputValues<T extends Record<string, any>>(
|
||||||
inputs: any,
|
inputs: T,
|
||||||
schema?: any
|
schema?: Partial<Record<keyof T, FieldSchema | BaseIOStructure>>
|
||||||
): T {
|
): T {
|
||||||
if (schema == null) {
|
const keys = Object.keys(inputs) as (keyof T)[]
|
||||||
return inputs
|
for (let inputKey of keys) {
|
||||||
}
|
|
||||||
for (let inputKey of Object.keys(inputs)) {
|
|
||||||
let input = inputs[inputKey]
|
let input = inputs[inputKey]
|
||||||
if (typeof input !== "string") {
|
if (typeof input !== "string") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let propSchema = schema.properties[inputKey]
|
let propSchema = schema?.[inputKey]
|
||||||
if (!propSchema) {
|
if (!propSchema) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (propSchema.type === "boolean") {
|
if (propSchema.type === "boolean") {
|
||||||
let lcInput = input.toLowerCase()
|
let lcInput = input.toLowerCase()
|
||||||
if (lcInput === "true") {
|
if (lcInput === "true") {
|
||||||
|
// @ts-expect-error - indexing a generic on purpose
|
||||||
inputs[inputKey] = true
|
inputs[inputKey] = true
|
||||||
}
|
}
|
||||||
if (lcInput === "false") {
|
if (lcInput === "false") {
|
||||||
|
// @ts-expect-error - indexing a generic on purpose
|
||||||
inputs[inputKey] = false
|
inputs[inputKey] = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (propSchema.type === "number") {
|
if (propSchema.type === "number") {
|
||||||
let floatInput = parseFloat(input)
|
let floatInput = parseFloat(input)
|
||||||
if (!isNaN(floatInput)) {
|
if (!isNaN(floatInput)) {
|
||||||
|
// @ts-expect-error - indexing a generic on purpose
|
||||||
inputs[inputKey] = floatInput
|
inputs[inputKey] = floatInput
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +94,7 @@ export function cleanInputValues<T extends Record<string, any>>(
|
||||||
*/
|
*/
|
||||||
export async function cleanUpRow(tableId: string, row: Row) {
|
export async function cleanUpRow(tableId: string, row: Row) {
|
||||||
let table = await sdk.tables.getTable(tableId)
|
let table = await sdk.tables.getTable(tableId)
|
||||||
return cleanInputValues(row, { properties: table.schema })
|
return cleanInputValues(row, table.schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getError(err: any) {
|
export function getError(err: any) {
|
||||||
|
@ -271,36 +272,3 @@ export function stringSplit(value: string | string[]) {
|
||||||
}
|
}
|
||||||
return value.split(",")
|
return value.split(",")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function typecastForLooping(input: LoopStepInputs) {
|
|
||||||
if (!input || !input.binding) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
switch (input.option) {
|
|
||||||
case LoopStepType.ARRAY:
|
|
||||||
if (typeof input.binding === "string") {
|
|
||||||
return JSON.parse(input.binding)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case LoopStepType.STRING:
|
|
||||||
if (Array.isArray(input.binding)) {
|
|
||||||
return input.binding.join(",")
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error("Unable to cast to correct type")
|
|
||||||
}
|
|
||||||
return input.binding
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ensureMaxIterationsAsNumber(
|
|
||||||
value: number | string | undefined
|
|
||||||
): number | undefined {
|
|
||||||
if (typeof value === "number") return value
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return parseInt(value)
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
import * as automationUtils from "./automationUtils"
|
|
||||||
import { isPlainObject } from "lodash"
|
|
||||||
|
|
||||||
type ObjValue = {
|
|
||||||
[key: string]: string | ObjValue
|
|
||||||
}
|
|
||||||
|
|
||||||
export function replaceFakeBindings<T extends Record<string, any>>(
|
|
||||||
originalStepInput: T,
|
|
||||||
loopStepNumber: number
|
|
||||||
): T {
|
|
||||||
const result: Record<string, any> = {}
|
|
||||||
for (const [key, value] of Object.entries(originalStepInput)) {
|
|
||||||
result[key] = replaceBindingsRecursive(value, loopStepNumber)
|
|
||||||
}
|
|
||||||
return result as T
|
|
||||||
}
|
|
||||||
|
|
||||||
function replaceBindingsRecursive(
|
|
||||||
value: string | ObjValue,
|
|
||||||
loopStepNumber: number
|
|
||||||
) {
|
|
||||||
if (value === null || value === undefined) {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value === "object") {
|
|
||||||
for (const [innerKey, innerValue] of Object.entries(value)) {
|
|
||||||
if (typeof innerValue === "string") {
|
|
||||||
value[innerKey] = automationUtils.substituteLoopStep(
|
|
||||||
innerValue,
|
|
||||||
`steps.${loopStepNumber}`
|
|
||||||
)
|
|
||||||
} else if (
|
|
||||||
innerValue &&
|
|
||||||
isPlainObject(innerValue) &&
|
|
||||||
Object.keys(innerValue).length > 0
|
|
||||||
) {
|
|
||||||
value[innerKey] = replaceBindingsRecursive(innerValue, loopStepNumber)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (typeof value === "string") {
|
|
||||||
value = automationUtils.substituteLoopStep(value, `steps.${loopStepNumber}`)
|
|
||||||
}
|
|
||||||
return value
|
|
||||||
}
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { FilterStepInputs, FilterStepOutputs } from "@budibase/types"
|
import {
|
||||||
import { automations } from "@budibase/shared-core"
|
FilterCondition,
|
||||||
|
FilterStepInputs,
|
||||||
const FilterConditions = automations.steps.filter.FilterConditions
|
FilterStepOutputs,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
export async function run({
|
export async function run({
|
||||||
inputs,
|
inputs,
|
||||||
|
@ -26,16 +27,16 @@ export async function run({
|
||||||
let result = false
|
let result = false
|
||||||
if (typeof field !== "object" && typeof value !== "object") {
|
if (typeof field !== "object" && typeof value !== "object") {
|
||||||
switch (condition) {
|
switch (condition) {
|
||||||
case FilterConditions.EQUAL:
|
case FilterCondition.EQUAL:
|
||||||
result = field === value
|
result = field === value
|
||||||
break
|
break
|
||||||
case FilterConditions.NOT_EQUAL:
|
case FilterCondition.NOT_EQUAL:
|
||||||
result = field !== value
|
result = field !== value
|
||||||
break
|
break
|
||||||
case FilterConditions.GREATER_THAN:
|
case FilterCondition.GREATER_THAN:
|
||||||
result = field > value
|
result = field > value
|
||||||
break
|
break
|
||||||
case FilterConditions.LESS_THAN:
|
case FilterCondition.LESS_THAN:
|
||||||
result = field < value
|
result = field < value
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import {
|
import { AutomationIOType } from "@budibase/types"
|
||||||
typecastForLooping,
|
import { cleanInputValues, substituteLoopStep } from "../automationUtils"
|
||||||
cleanInputValues,
|
|
||||||
substituteLoopStep,
|
|
||||||
} from "../automationUtils"
|
|
||||||
import { LoopStepType } from "@budibase/types"
|
|
||||||
|
|
||||||
describe("automationUtils", () => {
|
describe("automationUtils", () => {
|
||||||
describe("substituteLoopStep", () => {
|
describe("substituteLoopStep", () => {
|
||||||
|
@ -30,29 +26,6 @@ describe("automationUtils", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("typeCastForLooping", () => {
|
|
||||||
it("should parse to correct type", () => {
|
|
||||||
expect(
|
|
||||||
typecastForLooping({ option: LoopStepType.ARRAY, binding: [1, 2, 3] })
|
|
||||||
).toEqual([1, 2, 3])
|
|
||||||
expect(
|
|
||||||
typecastForLooping({ option: LoopStepType.ARRAY, binding: "[1,2,3]" })
|
|
||||||
).toEqual([1, 2, 3])
|
|
||||||
expect(
|
|
||||||
typecastForLooping({ option: LoopStepType.STRING, binding: [1, 2, 3] })
|
|
||||||
).toEqual("1,2,3")
|
|
||||||
})
|
|
||||||
it("should handle null values", () => {
|
|
||||||
// expect it to handle where the binding is null
|
|
||||||
expect(
|
|
||||||
typecastForLooping({ option: LoopStepType.ARRAY, binding: null })
|
|
||||||
).toEqual(null)
|
|
||||||
expect(() =>
|
|
||||||
typecastForLooping({ option: LoopStepType.ARRAY, binding: "test" })
|
|
||||||
).toThrow()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("cleanInputValues", () => {
|
describe("cleanInputValues", () => {
|
||||||
it("should handle array relationship fields from read binding", () => {
|
it("should handle array relationship fields from read binding", () => {
|
||||||
const schema = {
|
const schema = {
|
||||||
|
@ -70,15 +43,12 @@ describe("automationUtils", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expect(
|
expect(
|
||||||
cleanInputValues(
|
cleanInputValues({
|
||||||
{
|
row: {
|
||||||
row: {
|
relationship: `[{"_id": "ro_ta_users_us_3"}]`,
|
||||||
relationship: `[{"_id": "ro_ta_users_us_3"}]`,
|
|
||||||
},
|
|
||||||
schema,
|
|
||||||
},
|
},
|
||||||
schema
|
schema,
|
||||||
)
|
})
|
||||||
).toEqual({
|
).toEqual({
|
||||||
row: {
|
row: {
|
||||||
relationship: [{ _id: "ro_ta_users_us_3" }],
|
relationship: [{ _id: "ro_ta_users_us_3" }],
|
||||||
|
@ -103,15 +73,12 @@ describe("automationUtils", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expect(
|
expect(
|
||||||
cleanInputValues(
|
cleanInputValues({
|
||||||
{
|
row: {
|
||||||
row: {
|
relationship: `ro_ta_users_us_3`,
|
||||||
relationship: `ro_ta_users_us_3`,
|
|
||||||
},
|
|
||||||
schema,
|
|
||||||
},
|
},
|
||||||
schema
|
schema,
|
||||||
)
|
})
|
||||||
).toEqual({
|
).toEqual({
|
||||||
row: {
|
row: {
|
||||||
relationship: "ro_ta_users_us_3",
|
relationship: "ro_ta_users_us_3",
|
||||||
|
@ -122,28 +89,27 @@ describe("automationUtils", () => {
|
||||||
|
|
||||||
it("should be able to clean inputs with the utilities", () => {
|
it("should be able to clean inputs with the utilities", () => {
|
||||||
// can't clean without a schema
|
// can't clean without a schema
|
||||||
let output = cleanInputValues({ a: "1" })
|
const one = cleanInputValues({ a: "1" })
|
||||||
expect(output.a).toBe("1")
|
expect(one.a).toBe("1")
|
||||||
output = cleanInputValues(
|
|
||||||
|
const two = cleanInputValues(
|
||||||
{ a: "1", b: "true", c: "false", d: 1, e: "help" },
|
{ a: "1", b: "true", c: "false", d: 1, e: "help" },
|
||||||
{
|
{
|
||||||
properties: {
|
a: {
|
||||||
a: {
|
type: AutomationIOType.NUMBER,
|
||||||
type: "number",
|
},
|
||||||
},
|
b: {
|
||||||
b: {
|
type: AutomationIOType.BOOLEAN,
|
||||||
type: "boolean",
|
},
|
||||||
},
|
c: {
|
||||||
c: {
|
type: AutomationIOType.BOOLEAN,
|
||||||
type: "boolean",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
expect(output.a).toBe(1)
|
expect(two.a).toBe(1)
|
||||||
expect(output.b).toBe(true)
|
expect(two.b).toBe(true)
|
||||||
expect(output.c).toBe(false)
|
expect(two.c).toBe(false)
|
||||||
expect(output.d).toBe(1)
|
expect(two.d).toBe(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
import * as automation from "../index"
|
import * as automation from "../index"
|
||||||
import { LoopStepType, FieldType, Table, Datasource } from "@budibase/types"
|
import {
|
||||||
|
LoopStepType,
|
||||||
|
FieldType,
|
||||||
|
Table,
|
||||||
|
Datasource,
|
||||||
|
FilterCondition,
|
||||||
|
} from "@budibase/types"
|
||||||
import { createAutomationBuilder } from "./utilities/AutomationTestBuilder"
|
import { createAutomationBuilder } from "./utilities/AutomationTestBuilder"
|
||||||
import {
|
import {
|
||||||
DatabaseName,
|
DatabaseName,
|
||||||
|
@ -7,12 +13,9 @@ import {
|
||||||
} from "../../integrations/tests/utils"
|
} from "../../integrations/tests/utils"
|
||||||
import { Knex } from "knex"
|
import { Knex } from "knex"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { automations } from "@budibase/shared-core"
|
|
||||||
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../tests/utilities/TestConfiguration"
|
||||||
import { basicTable } from "../../tests/utilities/structures"
|
import { basicTable } from "../../tests/utilities/structures"
|
||||||
|
|
||||||
const FilterConditions = automations.steps.filter.FilterConditions
|
|
||||||
|
|
||||||
describe("Automation Scenarios", () => {
|
describe("Automation Scenarios", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
|
||||||
|
@ -256,7 +259,7 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
.filter({
|
.filter({
|
||||||
field: "{{ steps.2.rows.0.value }}",
|
field: "{{ steps.2.rows.0.value }}",
|
||||||
condition: FilterConditions.EQUAL,
|
condition: FilterCondition.EQUAL,
|
||||||
value: 20,
|
value: 20,
|
||||||
})
|
})
|
||||||
.serverLog({ text: "Equal condition met" })
|
.serverLog({ text: "Equal condition met" })
|
||||||
|
@ -282,7 +285,7 @@ describe("Automation Scenarios", () => {
|
||||||
})
|
})
|
||||||
.filter({
|
.filter({
|
||||||
field: "{{ steps.2.rows.0.value }}",
|
field: "{{ steps.2.rows.0.value }}",
|
||||||
condition: FilterConditions.NOT_EQUAL,
|
condition: FilterCondition.NOT_EQUAL,
|
||||||
value: 20,
|
value: 20,
|
||||||
})
|
})
|
||||||
.serverLog({ text: "Not Equal condition met" })
|
.serverLog({ text: "Not Equal condition met" })
|
||||||
|
@ -295,37 +298,37 @@ describe("Automation Scenarios", () => {
|
||||||
|
|
||||||
const testCases = [
|
const testCases = [
|
||||||
{
|
{
|
||||||
condition: FilterConditions.EQUAL,
|
condition: FilterCondition.EQUAL,
|
||||||
value: 10,
|
value: 10,
|
||||||
rowValue: 10,
|
rowValue: 10,
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
condition: FilterConditions.NOT_EQUAL,
|
condition: FilterCondition.NOT_EQUAL,
|
||||||
value: 10,
|
value: 10,
|
||||||
rowValue: 20,
|
rowValue: 20,
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
condition: FilterConditions.GREATER_THAN,
|
condition: FilterCondition.GREATER_THAN,
|
||||||
value: 10,
|
value: 10,
|
||||||
rowValue: 15,
|
rowValue: 15,
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
condition: FilterConditions.LESS_THAN,
|
condition: FilterCondition.LESS_THAN,
|
||||||
value: 10,
|
value: 10,
|
||||||
rowValue: 5,
|
rowValue: 5,
|
||||||
expectPass: true,
|
expectPass: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
condition: FilterConditions.GREATER_THAN,
|
condition: FilterCondition.GREATER_THAN,
|
||||||
value: 10,
|
value: 10,
|
||||||
rowValue: 5,
|
rowValue: 5,
|
||||||
expectPass: false,
|
expectPass: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
condition: FilterConditions.LESS_THAN,
|
condition: FilterCondition.LESS_THAN,
|
||||||
value: 10,
|
value: 10,
|
||||||
rowValue: 15,
|
rowValue: 15,
|
||||||
expectPass: false,
|
expectPass: false,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
} from "../../../tests/utilities/structures"
|
} from "../../../tests/utilities/structures"
|
||||||
import { objectStore } from "@budibase/backend-core"
|
import { objectStore } from "@budibase/backend-core"
|
||||||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||||
import { Row, Table } from "@budibase/types"
|
import { FilterCondition, Row, Table } from "@budibase/types"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
|
||||||
async function uploadTestFile(filename: string) {
|
async function uploadTestFile(filename: string) {
|
||||||
|
@ -90,7 +90,7 @@ describe("test the create row action", () => {
|
||||||
.createRow({ row: {} }, { stepName: "CreateRow" })
|
.createRow({ row: {} }, { stepName: "CreateRow" })
|
||||||
.filter({
|
.filter({
|
||||||
field: "{{ stepsByName.CreateRow.success }}",
|
field: "{{ stepsByName.CreateRow.success }}",
|
||||||
condition: "equal",
|
condition: FilterCondition.EQUAL,
|
||||||
value: true,
|
value: true,
|
||||||
})
|
})
|
||||||
.serverLog(
|
.serverLog(
|
||||||
|
@ -131,7 +131,7 @@ describe("test the create row action", () => {
|
||||||
.createRow({ row: attachmentRow }, { stepName: "CreateRow" })
|
.createRow({ row: attachmentRow }, { stepName: "CreateRow" })
|
||||||
.filter({
|
.filter({
|
||||||
field: "{{ stepsByName.CreateRow.success }}",
|
field: "{{ stepsByName.CreateRow.success }}",
|
||||||
condition: "equal",
|
condition: FilterCondition.EQUAL,
|
||||||
value: true,
|
value: true,
|
||||||
})
|
})
|
||||||
.serverLog(
|
.serverLog(
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
import { automations } from "@budibase/shared-core"
|
|
||||||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
import { FilterCondition } from "@budibase/types"
|
||||||
|
|
||||||
const FilterConditions = automations.steps.filter.FilterConditions
|
function stringToFilterCondition(
|
||||||
|
condition: "==" | "!=" | ">" | "<"
|
||||||
function stringToFilterCondition(condition: "==" | "!=" | ">" | "<"): string {
|
): FilterCondition {
|
||||||
switch (condition) {
|
switch (condition) {
|
||||||
case "==":
|
case "==":
|
||||||
return FilterConditions.EQUAL
|
return FilterCondition.EQUAL
|
||||||
case "!=":
|
case "!=":
|
||||||
return FilterConditions.NOT_EQUAL
|
return FilterCondition.NOT_EQUAL
|
||||||
case ">":
|
case ">":
|
||||||
return FilterConditions.GREATER_THAN
|
return FilterCondition.GREATER_THAN
|
||||||
case "<":
|
case "<":
|
||||||
return FilterConditions.LESS_THAN
|
return FilterCondition.LESS_THAN
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported condition: ${condition}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ import {
|
||||||
ServerLogStepOutputs,
|
ServerLogStepOutputs,
|
||||||
CreateRowStepOutputs,
|
CreateRowStepOutputs,
|
||||||
FieldType,
|
FieldType,
|
||||||
|
FilterCondition,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import * as loopUtils from "../../loopUtils"
|
|
||||||
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ describe("Attempt to run a basic loop automation", () => {
|
||||||
await config.api.row.save(table._id!, {})
|
await config.api.row.save(table._id!, {})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(async () => {
|
||||||
automation.shutdown()
|
await automation.shutdown()
|
||||||
config.end()
|
config.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -535,97 +535,30 @@ describe("Attempt to run a basic loop automation", () => {
|
||||||
expect(results.steps[2].outputs.rows).toHaveLength(0)
|
expect(results.steps[2].outputs.rows).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("replaceFakeBindings", () => {
|
describe("loop output", () => {
|
||||||
it("should replace loop bindings in nested objects", () => {
|
it("should not output anything if a filter stops the automation", async () => {
|
||||||
const originalStepInput = {
|
const results = await createAutomationBuilder(config)
|
||||||
schema: {
|
.onAppAction()
|
||||||
name: {
|
.filter({
|
||||||
type: "string",
|
condition: FilterCondition.EQUAL,
|
||||||
constraints: {
|
field: "1",
|
||||||
type: "string",
|
value: "2",
|
||||||
length: { maximum: null },
|
})
|
||||||
presence: false,
|
.loop({
|
||||||
},
|
option: LoopStepType.ARRAY,
|
||||||
name: "name",
|
binding: [1, 2, 3],
|
||||||
display: { type: "Text" },
|
})
|
||||||
},
|
.serverLog({ text: "Message {{loop.currentItem}}" })
|
||||||
},
|
.test({ fields: {} })
|
||||||
row: {
|
|
||||||
tableId: "ta_aaad4296e9f74b12b1b90ef7a84afcad",
|
|
||||||
name: "{{ loop.currentItem.pokemon }}",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const loopStepNumber = 3
|
expect(results.steps.length).toBe(1)
|
||||||
|
expect(results.steps[0].outputs).toEqual({
|
||||||
const result = loopUtils.replaceFakeBindings(
|
comparisonValue: 2,
|
||||||
originalStepInput,
|
refValue: 1,
|
||||||
loopStepNumber
|
result: false,
|
||||||
)
|
success: true,
|
||||||
|
status: "stopped",
|
||||||
expect(result).toEqual({
|
|
||||||
schema: {
|
|
||||||
name: {
|
|
||||||
type: "string",
|
|
||||||
constraints: {
|
|
||||||
type: "string",
|
|
||||||
length: { maximum: null },
|
|
||||||
presence: false,
|
|
||||||
},
|
|
||||||
name: "name",
|
|
||||||
display: { type: "Text" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
row: {
|
|
||||||
tableId: "ta_aaad4296e9f74b12b1b90ef7a84afcad",
|
|
||||||
name: "{{ steps.3.currentItem.pokemon }}",
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle null values in nested objects", () => {
|
|
||||||
const originalStepInput = {
|
|
||||||
nullValue: null,
|
|
||||||
nestedNull: {
|
|
||||||
someKey: null,
|
|
||||||
},
|
|
||||||
validValue: "{{ loop.someValue }}",
|
|
||||||
}
|
|
||||||
|
|
||||||
const loopStepNumber = 2
|
|
||||||
|
|
||||||
const result = loopUtils.replaceFakeBindings(
|
|
||||||
originalStepInput,
|
|
||||||
loopStepNumber
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
nullValue: null,
|
|
||||||
nestedNull: {
|
|
||||||
someKey: null,
|
|
||||||
},
|
|
||||||
validValue: "{{ steps.2.someValue }}",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should handle empty objects and arrays", () => {
|
|
||||||
const originalStepInput = {
|
|
||||||
emptyObject: {},
|
|
||||||
emptyArray: [],
|
|
||||||
nestedEmpty: {
|
|
||||||
emptyObj: {},
|
|
||||||
emptyArr: [],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const loopStepNumber = 1
|
|
||||||
|
|
||||||
const result = loopUtils.replaceFakeBindings(
|
|
||||||
originalStepInput,
|
|
||||||
loopStepNumber
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(result).toEqual(originalStepInput)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -66,7 +66,7 @@ describe("cron trigger", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should stop if the job fails more than 3 times", async () => {
|
it("should stop if the job fails more than N times", async () => {
|
||||||
const { automation } = await createAutomationBuilder(config)
|
const { automation } = await createAutomationBuilder(config)
|
||||||
.onCron({ cron: "* * * * *" })
|
.onCron({ cron: "* * * * *" })
|
||||||
.queryRows({
|
.queryRows({
|
||||||
|
|
|
@ -5,7 +5,7 @@ import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
|
|
||||||
mocks.licenses.useSyncAutomations()
|
mocks.licenses.useSyncAutomations()
|
||||||
|
|
||||||
describe("Branching automations", () => {
|
describe("Webhook trigger test", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
let table: Table
|
let table: Table
|
||||||
let webhook: Webhook
|
let webhook: Webhook
|
||||||
|
|
|
@ -63,6 +63,7 @@ class TriggerBuilder {
|
||||||
onRowDeleted = this.trigger(AutomationTriggerStepId.ROW_DELETED)
|
onRowDeleted = this.trigger(AutomationTriggerStepId.ROW_DELETED)
|
||||||
onWebhook = this.trigger(AutomationTriggerStepId.WEBHOOK)
|
onWebhook = this.trigger(AutomationTriggerStepId.WEBHOOK)
|
||||||
onCron = this.trigger(AutomationTriggerStepId.CRON)
|
onCron = this.trigger(AutomationTriggerStepId.CRON)
|
||||||
|
onRowAction = this.trigger(AutomationTriggerStepId.ROW_ACTION)
|
||||||
}
|
}
|
||||||
|
|
||||||
class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
|
class BranchStepBuilder<TStep extends AutomationTriggerStepId> {
|
||||||
|
|
|
@ -182,11 +182,12 @@ export async function externalTrigger(
|
||||||
// values are likely to be submitted as strings, so we shall convert to correct type
|
// values are likely to be submitted as strings, so we shall convert to correct type
|
||||||
const coercedFields: any = {}
|
const coercedFields: any = {}
|
||||||
const fields = automation.definition.trigger.inputs.fields
|
const fields = automation.definition.trigger.inputs.fields
|
||||||
for (let key of Object.keys(fields || {})) {
|
for (const key of Object.keys(fields || {})) {
|
||||||
coercedFields[key] = coerce(params.fields[key], fields[key])
|
coercedFields[key] = coerce(params.fields[key], fields[key])
|
||||||
}
|
}
|
||||||
params.fields = coercedFields
|
params.fields = coercedFields
|
||||||
}
|
}
|
||||||
|
|
||||||
// row actions and webhooks flatten the fields down
|
// row actions and webhooks flatten the fields down
|
||||||
else if (
|
else if (
|
||||||
sdk.automations.isRowAction(automation) ||
|
sdk.automations.isRowAction(automation) ||
|
||||||
|
@ -198,6 +199,7 @@ export async function externalTrigger(
|
||||||
fields: {},
|
fields: {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const data: AutomationData = { automation, event: params }
|
const data: AutomationData = { automation, event: params }
|
||||||
|
|
||||||
const shouldTrigger = await checkTriggerFilters(automation, {
|
const shouldTrigger = await checkTriggerFilters(automation, {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
import { automationsEnabled } from "../features"
|
import { automationsEnabled } from "../features"
|
||||||
import { helpers, REBOOT_CRON } from "@budibase/shared-core"
|
import { helpers, REBOOT_CRON } from "@budibase/shared-core"
|
||||||
import tracer from "dd-trace"
|
import tracer from "dd-trace"
|
||||||
|
import { JobId } from "bull"
|
||||||
|
|
||||||
const CRON_STEP_ID = automations.triggers.definitions.CRON.stepId
|
const CRON_STEP_ID = automations.triggers.definitions.CRON.stepId
|
||||||
let Runner: Thread
|
let Runner: Thread
|
||||||
|
@ -155,11 +156,11 @@ export async function disableAllCrons(appId: any) {
|
||||||
return { count: results.length / 2 }
|
return { count: results.length / 2 }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function disableCronById(jobId: number | string) {
|
export async function disableCronById(jobId: JobId) {
|
||||||
const repeatJobs = await automationQueue.getRepeatableJobs()
|
const jobs = await automationQueue.getRepeatableJobs()
|
||||||
for (let repeatJob of repeatJobs) {
|
for (const job of jobs) {
|
||||||
if (repeatJob.id === jobId) {
|
if (job.id === jobId) {
|
||||||
await automationQueue.removeRepeatableByKey(repeatJob.key)
|
await automationQueue.removeRepeatableByKey(job.key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(`jobId=${jobId} disabled`)
|
console.log(`jobId=${jobId} disabled`)
|
||||||
|
@ -248,33 +249,3 @@ export async function enableCronTrigger(appId: any, automation: Automation) {
|
||||||
export async function cleanupAutomations(appId: any) {
|
export async function cleanupAutomations(appId: any) {
|
||||||
await disableAllCrons(appId)
|
await disableAllCrons(appId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the supplied automation is of a recurring type.
|
|
||||||
* @param automation The automation to check.
|
|
||||||
* @return if it is recurring (cron).
|
|
||||||
*/
|
|
||||||
export function isRecurring(automation: Automation) {
|
|
||||||
return (
|
|
||||||
automation.definition.trigger.stepId ===
|
|
||||||
automations.triggers.definitions.CRON.stepId
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isErrorInOutput(output: {
|
|
||||||
steps: { outputs?: { success: boolean } }[]
|
|
||||||
}) {
|
|
||||||
let first = true,
|
|
||||||
error = false
|
|
||||||
for (let step of output.steps) {
|
|
||||||
// skip the trigger, its always successful if automation ran
|
|
||||||
if (first) {
|
|
||||||
first = false
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (!step.outputs?.success) {
|
|
||||||
error = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return error
|
|
||||||
}
|
|
||||||
|
|
|
@ -130,11 +130,6 @@ export enum InvalidColumns {
|
||||||
TABLE_ID = "tableId",
|
TABLE_ID = "tableId",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AutomationErrors {
|
|
||||||
INCORRECT_TYPE = "INCORRECT_TYPE",
|
|
||||||
FAILURE_CONDITION = "FAILURE_CONDITION_MET",
|
|
||||||
}
|
|
||||||
|
|
||||||
// pass through the list from the auth/core lib
|
// pass through the list from the auth/core lib
|
||||||
export const ObjectStoreBuckets = objectStore.ObjectStoreBuckets
|
export const ObjectStoreBuckets = objectStore.ObjectStoreBuckets
|
||||||
export const MAX_AUTOMATION_RECURRING_ERRORS = 5
|
export const MAX_AUTOMATION_RECURRING_ERRORS = 5
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
import { AutomationResults, LoopStepType, UserBindings } from "@budibase/types"
|
import {
|
||||||
|
AutomationStepResultOutputs,
|
||||||
|
AutomationTriggerResultOutputs,
|
||||||
|
LoopStepType,
|
||||||
|
UserBindings,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
export interface LoopInput {
|
export interface LoopInput {
|
||||||
option: LoopStepType
|
option: LoopStepType
|
||||||
|
@ -13,19 +18,17 @@ export interface TriggerOutput {
|
||||||
timestamp?: number
|
timestamp?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AutomationContext extends AutomationResults {
|
export interface AutomationContext {
|
||||||
steps: any[]
|
trigger: AutomationTriggerResultOutputs
|
||||||
stepsById: Record<string, any>
|
steps: [AutomationTriggerResultOutputs, ...AutomationStepResultOutputs[]]
|
||||||
stepsByName: Record<string, any>
|
stepsById: Record<string, AutomationStepResultOutputs>
|
||||||
|
stepsByName: Record<string, AutomationStepResultOutputs>
|
||||||
env?: Record<string, string>
|
env?: Record<string, string>
|
||||||
user?: UserBindings
|
user?: UserBindings
|
||||||
trigger: any
|
|
||||||
settings?: {
|
settings?: {
|
||||||
url?: string
|
url?: string
|
||||||
logo?: string
|
logo?: string
|
||||||
company?: string
|
company?: string
|
||||||
}
|
}
|
||||||
|
loop?: { currentItem: any }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AutomationResponse
|
|
||||||
extends Omit<AutomationContext, "stepsByName" | "stepsById"> {}
|
|
||||||
|
|
|
@ -40,7 +40,8 @@ function cleanAutomationInputs(automation: Automation) {
|
||||||
if (step == null) {
|
if (step == null) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for (let inputName of Object.keys(step.inputs)) {
|
for (const key of Object.keys(step.inputs)) {
|
||||||
|
const inputName = key as keyof typeof step.inputs
|
||||||
if (!step.inputs[inputName] || step.inputs[inputName] === "") {
|
if (!step.inputs[inputName] || step.inputs[inputName] === "") {
|
||||||
delete step.inputs[inputName]
|
delete step.inputs[inputName]
|
||||||
}
|
}
|
||||||
|
@ -281,7 +282,8 @@ function guardInvalidUpdatesAndThrow(
|
||||||
const readonlyFields = Object.keys(
|
const readonlyFields = Object.keys(
|
||||||
step.schema.inputs.properties || {}
|
step.schema.inputs.properties || {}
|
||||||
).filter(k => step.schema.inputs.properties[k].readonly)
|
).filter(k => step.schema.inputs.properties[k].readonly)
|
||||||
readonlyFields.forEach(readonlyField => {
|
readonlyFields.forEach(key => {
|
||||||
|
const readonlyField = key as keyof typeof step.inputs
|
||||||
const oldStep = oldStepDefinitions.find(i => i.id === step.id)
|
const oldStep = oldStepDefinitions.find(i => i.id === step.id)
|
||||||
if (step.inputs[readonlyField] !== oldStep?.inputs[readonlyField]) {
|
if (step.inputs[readonlyField] !== oldStep?.inputs[readonlyField]) {
|
||||||
throw new HTTPError(
|
throw new HTTPError(
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
import { sample } from "lodash/fp"
|
|
||||||
import { Automation } from "@budibase/types"
|
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
|
||||||
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
|
||||||
import automationSdk from "../"
|
|
||||||
import { structures } from "../../../../api/routes/tests/utilities"
|
|
||||||
|
|
||||||
describe("automation sdk", () => {
|
|
||||||
const config = new TestConfiguration()
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
await config.init()
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("update", () => {
|
|
||||||
it("can rename existing automations", async () => {
|
|
||||||
await config.doInContext(config.getAppId(), async () => {
|
|
||||||
const automation = structures.newAutomation()
|
|
||||||
|
|
||||||
const response = await automationSdk.create(automation)
|
|
||||||
|
|
||||||
const newName = generator.guid()
|
|
||||||
const update = { ...response, name: newName }
|
|
||||||
const result = await automationSdk.update(update)
|
|
||||||
expect(result.name).toEqual(newName)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
["trigger", (a: Automation) => a.definition.trigger],
|
|
||||||
["step", (a: Automation) => a.definition.steps[0]],
|
|
||||||
])("can update input fields (for a %s)", async (_, getStep) => {
|
|
||||||
await config.doInContext(config.getAppId(), async () => {
|
|
||||||
const automation = structures.newAutomation()
|
|
||||||
|
|
||||||
const keyToUse = sample(Object.keys(getStep(automation).inputs))!
|
|
||||||
getStep(automation).inputs[keyToUse] = "anyValue"
|
|
||||||
|
|
||||||
const response = await automationSdk.create(automation)
|
|
||||||
|
|
||||||
const update = { ...response }
|
|
||||||
getStep(update).inputs[keyToUse] = "anyUpdatedValue"
|
|
||||||
const result = await automationSdk.update(update)
|
|
||||||
expect(getStep(result).inputs[keyToUse]).toEqual("anyUpdatedValue")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it.each([
|
|
||||||
["trigger", (a: Automation) => a.definition.trigger],
|
|
||||||
["step", (a: Automation) => a.definition.steps[0]],
|
|
||||||
])("cannot update readonly fields (for a %s)", async (_, getStep) => {
|
|
||||||
await config.doInContext(config.getAppId(), async () => {
|
|
||||||
const automation = structures.newAutomation()
|
|
||||||
getStep(automation).schema.inputs.properties["readonlyProperty"] = {
|
|
||||||
readonly: true,
|
|
||||||
}
|
|
||||||
getStep(automation).inputs["readonlyProperty"] = "anyValue"
|
|
||||||
|
|
||||||
const response = await automationSdk.create(automation)
|
|
||||||
|
|
||||||
const update = { ...response }
|
|
||||||
getStep(update).inputs["readonlyProperty"] = "anyUpdatedValue"
|
|
||||||
await expect(automationSdk.update(update)).rejects.toThrow(
|
|
||||||
"Field readonlyProperty is readonly and it cannot be modified"
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -35,6 +35,8 @@ import {
|
||||||
WebhookActionType,
|
WebhookActionType,
|
||||||
BuiltinPermissionID,
|
BuiltinPermissionID,
|
||||||
DeepPartial,
|
DeepPartial,
|
||||||
|
FilterCondition,
|
||||||
|
AutomationTriggerResult,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { LoopInput } from "../../definitions/automations"
|
import { LoopInput } from "../../definitions/automations"
|
||||||
import { merge } from "lodash"
|
import { merge } from "lodash"
|
||||||
|
@ -372,7 +374,11 @@ export function filterAutomation(opts?: DeepPartial<Automation>): Automation {
|
||||||
type: AutomationStepType.ACTION,
|
type: AutomationStepType.ACTION,
|
||||||
internal: true,
|
internal: true,
|
||||||
stepId: AutomationActionStepId.FILTER,
|
stepId: AutomationActionStepId.FILTER,
|
||||||
inputs: { field: "name", value: "test", condition: "EQ" },
|
inputs: {
|
||||||
|
field: "name",
|
||||||
|
value: "test",
|
||||||
|
condition: FilterCondition.EQUAL,
|
||||||
|
},
|
||||||
schema: BUILTIN_ACTION_DEFINITIONS.EXECUTE_SCRIPT.schema,
|
schema: BUILTIN_ACTION_DEFINITIONS.EXECUTE_SCRIPT.schema,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -437,15 +443,24 @@ export function updateRowAutomationWithFilters(
|
||||||
export function basicAutomationResults(
|
export function basicAutomationResults(
|
||||||
automationId: string
|
automationId: string
|
||||||
): AutomationResults {
|
): AutomationResults {
|
||||||
|
const trigger: AutomationTriggerResult = {
|
||||||
|
id: "trigger",
|
||||||
|
stepId: AutomationTriggerStepId.APP,
|
||||||
|
outputs: {},
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
automationId,
|
automationId,
|
||||||
status: AutomationStatus.SUCCESS,
|
status: AutomationStatus.SUCCESS,
|
||||||
trigger: "trigger" as any,
|
trigger,
|
||||||
steps: [
|
steps: [
|
||||||
|
trigger,
|
||||||
{
|
{
|
||||||
|
id: "step1",
|
||||||
stepId: AutomationActionStepId.SERVER_LOG,
|
stepId: AutomationActionStepId.SERVER_LOG,
|
||||||
inputs: {},
|
inputs: {},
|
||||||
outputs: {},
|
outputs: {
|
||||||
|
success: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,20 +3,14 @@ import {
|
||||||
AutomationStepDefinition,
|
AutomationStepDefinition,
|
||||||
AutomationStepType,
|
AutomationStepType,
|
||||||
AutomationIOType,
|
AutomationIOType,
|
||||||
|
FilterCondition,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
export const FilterConditions = {
|
|
||||||
EQUAL: "EQUAL",
|
|
||||||
NOT_EQUAL: "NOT_EQUAL",
|
|
||||||
GREATER_THAN: "GREATER_THAN",
|
|
||||||
LESS_THAN: "LESS_THAN",
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PrettyFilterConditions = {
|
export const PrettyFilterConditions = {
|
||||||
[FilterConditions.EQUAL]: "Equals",
|
[FilterCondition.EQUAL]: "Equals",
|
||||||
[FilterConditions.NOT_EQUAL]: "Not equals",
|
[FilterCondition.NOT_EQUAL]: "Not equals",
|
||||||
[FilterConditions.GREATER_THAN]: "Greater than",
|
[FilterCondition.GREATER_THAN]: "Greater than",
|
||||||
[FilterConditions.LESS_THAN]: "Less than",
|
[FilterCondition.LESS_THAN]: "Less than",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const definition: AutomationStepDefinition = {
|
export const definition: AutomationStepDefinition = {
|
||||||
|
@ -30,7 +24,7 @@ export const definition: AutomationStepDefinition = {
|
||||||
features: {},
|
features: {},
|
||||||
stepId: AutomationActionStepId.FILTER,
|
stepId: AutomationActionStepId.FILTER,
|
||||||
inputs: {
|
inputs: {
|
||||||
condition: FilterConditions.EQUAL,
|
condition: FilterCondition.EQUAL,
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
inputs: {
|
inputs: {
|
||||||
|
@ -42,7 +36,7 @@ export const definition: AutomationStepDefinition = {
|
||||||
condition: {
|
condition: {
|
||||||
type: AutomationIOType.STRING,
|
type: AutomationIOType.STRING,
|
||||||
title: "Condition",
|
title: "Condition",
|
||||||
enum: Object.values(FilterConditions),
|
enum: Object.values(FilterCondition),
|
||||||
pretty: Object.values(PrettyFilterConditions),
|
pretty: Object.values(PrettyFilterConditions),
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
|
|
|
@ -105,10 +105,10 @@ export function cancelableTimeout(
|
||||||
|
|
||||||
export async function withTimeout<T>(
|
export async function withTimeout<T>(
|
||||||
timeout: number,
|
timeout: number,
|
||||||
promise: Promise<T>
|
promise: () => Promise<T>
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const [timeoutPromise, cancel] = cancelableTimeout(timeout)
|
const [timeoutPromise, cancel] = cancelableTimeout(timeout)
|
||||||
const result = (await Promise.race([promise, timeoutPromise])) as T
|
const result = (await Promise.race([promise(), timeoutPromise])) as T
|
||||||
cancel()
|
cancel()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,20 @@ import {
|
||||||
} from "../../../sdk"
|
} from "../../../sdk"
|
||||||
import { HttpMethod } from "../query"
|
import { HttpMethod } from "../query"
|
||||||
import { Row } from "../row"
|
import { Row } from "../row"
|
||||||
import { LoopStepType, EmailAttachment, AutomationResults } from "./automation"
|
import {
|
||||||
import { AutomationStep, AutomationStepOutputs } from "./schema"
|
LoopStepType,
|
||||||
|
EmailAttachment,
|
||||||
|
AutomationResults,
|
||||||
|
AutomationStepResult,
|
||||||
|
} from "./automation"
|
||||||
|
import { AutomationStep } from "./schema"
|
||||||
|
|
||||||
|
export enum FilterCondition {
|
||||||
|
EQUAL = "EQUAL",
|
||||||
|
NOT_EQUAL = "NOT_EQUAL",
|
||||||
|
GREATER_THAN = "GREATER_THAN",
|
||||||
|
LESS_THAN = "LESS_THAN",
|
||||||
|
}
|
||||||
|
|
||||||
export type BaseAutomationOutputs = {
|
export type BaseAutomationOutputs = {
|
||||||
success?: boolean
|
success?: boolean
|
||||||
|
@ -92,7 +104,7 @@ export type ExecuteScriptStepOutputs = BaseAutomationOutputs & {
|
||||||
|
|
||||||
export type FilterStepInputs = {
|
export type FilterStepInputs = {
|
||||||
field: any
|
field: any
|
||||||
condition: string
|
condition: FilterCondition
|
||||||
value: any
|
value: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +122,7 @@ export type LoopStepInputs = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LoopStepOutputs = {
|
export type LoopStepOutputs = {
|
||||||
items: AutomationStepOutputs[]
|
items: AutomationStepResult[]
|
||||||
success: boolean
|
success: boolean
|
||||||
iterations: number
|
iterations: number
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ export interface Automation extends Document {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BaseIOStructure {
|
export interface BaseIOStructure {
|
||||||
type?: AutomationIOType
|
type?: AutomationIOType
|
||||||
subtype?: AutomationIOType
|
subtype?: AutomationIOType
|
||||||
customType?: AutomationCustomIOType
|
customType?: AutomationCustomIOType
|
||||||
|
@ -176,6 +176,8 @@ export enum AutomationFeature {
|
||||||
export enum AutomationStepStatus {
|
export enum AutomationStepStatus {
|
||||||
NO_ITERATIONS = "no_iterations",
|
NO_ITERATIONS = "no_iterations",
|
||||||
MAX_ITERATIONS = "max_iterations_reached",
|
MAX_ITERATIONS = "max_iterations_reached",
|
||||||
|
FAILURE_CONDITION = "FAILURE_CONDITION_MET",
|
||||||
|
INCORRECT_TYPE = "INCORRECT_TYPE",
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AutomationStatus {
|
export enum AutomationStatus {
|
||||||
|
@ -190,19 +192,37 @@ export enum AutomationStoppedReason {
|
||||||
TRIGGER_FILTER_NOT_MET = "Automation did not run. Filter conditions in trigger were not met.",
|
TRIGGER_FILTER_NOT_MET = "Automation did not run. Filter conditions in trigger were not met.",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AutomationStepResultOutputs {
|
||||||
|
success: boolean
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AutomationStepResultInputs {
|
||||||
|
[key: string]: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AutomationStepResult {
|
||||||
|
id: string
|
||||||
|
stepId: AutomationActionStepId
|
||||||
|
inputs: AutomationStepResultInputs
|
||||||
|
outputs: AutomationStepResultOutputs
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AutomationTriggerResultInputs = Record<string, any>
|
||||||
|
export type AutomationTriggerResultOutputs = Record<string, any>
|
||||||
|
|
||||||
|
export interface AutomationTriggerResult {
|
||||||
|
id: string
|
||||||
|
stepId: AutomationTriggerStepId
|
||||||
|
inputs?: AutomationTriggerResultInputs | null
|
||||||
|
outputs: AutomationTriggerResultOutputs
|
||||||
|
}
|
||||||
|
|
||||||
export interface AutomationResults {
|
export interface AutomationResults {
|
||||||
automationId?: string
|
automationId?: string
|
||||||
status?: AutomationStatus
|
status?: AutomationStatus
|
||||||
trigger?: AutomationTrigger
|
trigger: AutomationTriggerResult
|
||||||
steps: {
|
steps: [AutomationTriggerResult, ...AutomationStepResult[]]
|
||||||
stepId: AutomationTriggerStepId | AutomationActionStepId
|
|
||||||
inputs: {
|
|
||||||
[key: string]: any
|
|
||||||
}
|
|
||||||
outputs: {
|
|
||||||
[key: string]: any
|
|
||||||
}
|
|
||||||
}[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DidNotTriggerResponse {
|
export interface DidNotTriggerResponse {
|
||||||
|
@ -236,6 +256,7 @@ export type ActionImplementation<TInputs, TOutputs> = (
|
||||||
inputs: TInputs
|
inputs: TInputs
|
||||||
} & AutomationStepInputBase
|
} & AutomationStepInputBase
|
||||||
) => Promise<TOutputs>
|
) => Promise<TOutputs>
|
||||||
|
|
||||||
export interface AutomationMetadata extends Document {
|
export interface AutomationMetadata extends Document {
|
||||||
errorCount?: number
|
errorCount?: number
|
||||||
automationChainCount?: number
|
automationChainCount?: number
|
||||||
|
|
|
@ -164,24 +164,6 @@ export interface AutomationStepSchemaBase {
|
||||||
features?: Partial<Record<AutomationFeature, boolean>>
|
features?: Partial<Record<AutomationFeature, boolean>>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AutomationStepOutputs =
|
|
||||||
| CollectStepOutputs
|
|
||||||
| CreateRowStepOutputs
|
|
||||||
| DelayStepOutputs
|
|
||||||
| DeleteRowStepOutputs
|
|
||||||
| ExecuteQueryStepOutputs
|
|
||||||
| ExecuteScriptStepOutputs
|
|
||||||
| FilterStepOutputs
|
|
||||||
| QueryRowsStepOutputs
|
|
||||||
| BaseAutomationOutputs
|
|
||||||
| BashStepOutputs
|
|
||||||
| ExternalAppStepOutputs
|
|
||||||
| OpenAIStepOutputs
|
|
||||||
| ServerLogStepOutputs
|
|
||||||
| TriggerAutomationStepOutputs
|
|
||||||
| UpdateRowStepOutputs
|
|
||||||
| ZapierStepOutputs
|
|
||||||
|
|
||||||
export type AutomationStepInputs<T extends AutomationActionStepId> =
|
export type AutomationStepInputs<T extends AutomationActionStepId> =
|
||||||
T extends AutomationActionStepId.COLLECT
|
T extends AutomationActionStepId.COLLECT
|
||||||
? CollectStepInputs
|
? CollectStepInputs
|
||||||
|
@ -229,11 +211,56 @@ export type AutomationStepInputs<T extends AutomationActionStepId> =
|
||||||
? BranchStepInputs
|
? BranchStepInputs
|
||||||
: never
|
: never
|
||||||
|
|
||||||
|
export type AutomationStepOutputs<T extends AutomationActionStepId> =
|
||||||
|
T extends AutomationActionStepId.COLLECT
|
||||||
|
? CollectStepOutputs
|
||||||
|
: T extends AutomationActionStepId.CREATE_ROW
|
||||||
|
? CreateRowStepOutputs
|
||||||
|
: T extends AutomationActionStepId.DELAY
|
||||||
|
? DelayStepOutputs
|
||||||
|
: T extends AutomationActionStepId.DELETE_ROW
|
||||||
|
? DeleteRowStepOutputs
|
||||||
|
: T extends AutomationActionStepId.EXECUTE_QUERY
|
||||||
|
? ExecuteQueryStepOutputs
|
||||||
|
: T extends AutomationActionStepId.EXECUTE_SCRIPT
|
||||||
|
? ExecuteScriptStepOutputs
|
||||||
|
: T extends AutomationActionStepId.FILTER
|
||||||
|
? FilterStepOutputs
|
||||||
|
: T extends AutomationActionStepId.QUERY_ROWS
|
||||||
|
? QueryRowsStepOutputs
|
||||||
|
: T extends AutomationActionStepId.SEND_EMAIL_SMTP
|
||||||
|
? BaseAutomationOutputs
|
||||||
|
: T extends AutomationActionStepId.SERVER_LOG
|
||||||
|
? ServerLogStepOutputs
|
||||||
|
: T extends AutomationActionStepId.TRIGGER_AUTOMATION_RUN
|
||||||
|
? TriggerAutomationStepOutputs
|
||||||
|
: T extends AutomationActionStepId.UPDATE_ROW
|
||||||
|
? UpdateRowStepOutputs
|
||||||
|
: T extends AutomationActionStepId.OUTGOING_WEBHOOK
|
||||||
|
? ExternalAppStepOutputs
|
||||||
|
: T extends AutomationActionStepId.discord
|
||||||
|
? ExternalAppStepOutputs
|
||||||
|
: T extends AutomationActionStepId.slack
|
||||||
|
? ExternalAppStepOutputs
|
||||||
|
: T extends AutomationActionStepId.zapier
|
||||||
|
? ZapierStepOutputs
|
||||||
|
: T extends AutomationActionStepId.integromat
|
||||||
|
? ExternalAppStepOutputs
|
||||||
|
: T extends AutomationActionStepId.n8n
|
||||||
|
? ExternalAppStepOutputs
|
||||||
|
: T extends AutomationActionStepId.EXECUTE_BASH
|
||||||
|
? BashStepOutputs
|
||||||
|
: T extends AutomationActionStepId.OPENAI
|
||||||
|
? OpenAIStepOutputs
|
||||||
|
: T extends AutomationActionStepId.LOOP
|
||||||
|
? BaseAutomationOutputs
|
||||||
|
: never
|
||||||
|
|
||||||
export interface AutomationStepSchema<TStep extends AutomationActionStepId>
|
export interface AutomationStepSchema<TStep extends AutomationActionStepId>
|
||||||
extends AutomationStepSchemaBase {
|
extends AutomationStepSchemaBase {
|
||||||
id: string
|
id: string
|
||||||
stepId: TStep
|
stepId: TStep
|
||||||
inputs: AutomationStepInputs<TStep> & Record<string, any> // The record union to be removed once the types are fixed
|
inputs: AutomationStepInputs<TStep>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CollectStep = AutomationStepSchema<AutomationActionStepId.COLLECT>
|
export type CollectStep = AutomationStepSchema<AutomationActionStepId.COLLECT>
|
||||||
|
@ -315,6 +342,36 @@ export type AutomationStep =
|
||||||
| OpenAIStep
|
| OpenAIStep
|
||||||
| BranchStep
|
| BranchStep
|
||||||
|
|
||||||
|
export function isBranchStep(
|
||||||
|
step: AutomationStep | AutomationTrigger
|
||||||
|
): step is BranchStep {
|
||||||
|
return step.stepId === AutomationActionStepId.BRANCH
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isTrigger(
|
||||||
|
step: AutomationStep | AutomationTrigger
|
||||||
|
): step is AutomationTrigger {
|
||||||
|
return step.type === AutomationStepType.TRIGGER
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isRowUpdateTrigger(
|
||||||
|
step: AutomationStep | AutomationTrigger
|
||||||
|
): step is RowUpdatedTrigger {
|
||||||
|
return step.stepId === AutomationTriggerStepId.ROW_UPDATED
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isRowSaveTrigger(
|
||||||
|
step: AutomationStep | AutomationTrigger
|
||||||
|
): step is RowSavedTrigger {
|
||||||
|
return step.stepId === AutomationTriggerStepId.ROW_SAVED
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAppTrigger(
|
||||||
|
step: AutomationStep | AutomationTrigger
|
||||||
|
): step is AppActionTrigger {
|
||||||
|
return step.stepId === AutomationTriggerStepId.APP
|
||||||
|
}
|
||||||
|
|
||||||
type EmptyInputs = {}
|
type EmptyInputs = {}
|
||||||
export type AutomationStepDefinition = Omit<AutomationStep, "id" | "inputs"> & {
|
export type AutomationStepDefinition = Omit<AutomationStep, "id" | "inputs"> & {
|
||||||
inputs: EmptyInputs
|
inputs: EmptyInputs
|
||||||
|
|
|
@ -82,6 +82,10 @@ type RangeFilter = Record<
|
||||||
|
|
||||||
type LogicalFilter = { conditions: SearchFilters[] }
|
type LogicalFilter = { conditions: SearchFilters[] }
|
||||||
|
|
||||||
|
export function isLogicalFilter(filter: any): filter is LogicalFilter {
|
||||||
|
return "conditions" in filter
|
||||||
|
}
|
||||||
|
|
||||||
export type AnySearchFilter = BasicFilter | ArrayFilter | RangeFilter
|
export type AnySearchFilter = BasicFilter | ArrayFilter | RangeFilter
|
||||||
|
|
||||||
export interface SearchFilters {
|
export interface SearchFilters {
|
||||||
|
|
|
@ -31,8 +31,8 @@ describe("/api/global/email", () => {
|
||||||
) {
|
) {
|
||||||
let response, text
|
let response, text
|
||||||
try {
|
try {
|
||||||
await helpers.withTimeout(20000, config.saveEtherealSmtpConfig())
|
await helpers.withTimeout(20000, () => config.saveEtherealSmtpConfig())
|
||||||
await helpers.withTimeout(20000, config.saveSettingsConfig())
|
await helpers.withTimeout(20000, () => config.saveSettingsConfig())
|
||||||
let res
|
let res
|
||||||
if (attachments) {
|
if (attachments) {
|
||||||
res = await config.api.emails
|
res = await config.api.emails
|
||||||
|
|
Loading…
Reference in New Issue