Merge branch 'master' into remove-mocks-1
This commit is contained in:
commit
83640e9d22
|
@ -63,6 +63,11 @@ http {
|
||||||
proxy_send_timeout 120s;
|
proxy_send_timeout 120s;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
|
|
||||||
|
# Enable buffering for potentially large OIDC configs
|
||||||
|
proxy_buffering on;
|
||||||
|
proxy_buffer_size 16k;
|
||||||
|
proxy_buffers 4 32k;
|
||||||
|
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header Connection "";
|
proxy_set_header Connection "";
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||||
"version": "3.4.11",
|
"version": "3.4.13",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"concurrency": 20,
|
"concurrency": 20,
|
||||||
"command": {
|
"command": {
|
||||||
|
|
|
@ -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)]
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { Input, Label } from "@budibase/bbui"
|
import { Input, Label } from "@budibase/bbui"
|
||||||
import { previewStore, selectedScreen } from "@/stores/builder"
|
import { previewStore, selectedScreen } from "@/stores/builder"
|
||||||
import type { ComponentContext } from "@budibase/types"
|
import type { AppContext } from "@budibase/types"
|
||||||
|
|
||||||
export let baseRoute = ""
|
export let baseRoute = ""
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
// This function is needed to repopulate the test value from componentContext
|
// This function is needed to repopulate the test value from componentContext
|
||||||
// when a user navigates to another component and then back again
|
// when a user navigates to another component and then back again
|
||||||
const updateTestValueFromContext = (context: ComponentContext | null) => {
|
const updateTestValueFromContext = (context: AppContext | null) => {
|
||||||
if (context?.url && !testValue) {
|
if (context?.url && !testValue) {
|
||||||
const { wild, ...urlParams } = context.url
|
const { wild, ...urlParams } = context.url
|
||||||
const queryParams = context.query
|
const queryParams = context.query
|
||||||
|
|
|
@ -8,27 +8,32 @@ import {
|
||||||
} from "@budibase/string-templates"
|
} from "@budibase/string-templates"
|
||||||
import { capitalise } from "@/helpers"
|
import { capitalise } from "@/helpers"
|
||||||
import { Constants } from "@budibase/frontend-core"
|
import { Constants } from "@budibase/frontend-core"
|
||||||
|
import { Component, ComponentContext } from "@budibase/types"
|
||||||
|
|
||||||
const { ContextScopes } = Constants
|
const { ContextScopes } = Constants
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively searches for a specific component ID
|
* Recursively searches for a specific component ID
|
||||||
*/
|
*/
|
||||||
export const findComponent = (rootComponent, id) => {
|
export const findComponent = (rootComponent: Component, id: string) => {
|
||||||
return searchComponentTree(rootComponent, comp => comp._id === id)
|
return searchComponentTree(rootComponent, comp => comp._id === id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively searches for a specific component type
|
* Recursively searches for a specific component type
|
||||||
*/
|
*/
|
||||||
export const findComponentType = (rootComponent, type) => {
|
export const findComponentType = (rootComponent: Component, type: string) => {
|
||||||
return searchComponentTree(rootComponent, comp => comp._component === type)
|
return searchComponentTree(rootComponent, comp => comp._component === type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively searches for the parent component of a specific component ID
|
* Recursively searches for the parent component of a specific component ID
|
||||||
*/
|
*/
|
||||||
export const findComponentParent = (rootComponent, id, parentComponent) => {
|
export const findComponentParent = (
|
||||||
|
rootComponent: Component | undefined,
|
||||||
|
id: string | undefined,
|
||||||
|
parentComponent: Component | null = null
|
||||||
|
): Component | null => {
|
||||||
if (!rootComponent || !id) {
|
if (!rootComponent || !id) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -51,7 +56,11 @@ export const findComponentParent = (rootComponent, id, parentComponent) => {
|
||||||
* Recursively searches for a specific component ID and records the component
|
* Recursively searches for a specific component ID and records the component
|
||||||
* path to this component
|
* path to this component
|
||||||
*/
|
*/
|
||||||
export const findComponentPath = (rootComponent, id, path = []) => {
|
export const findComponentPath = (
|
||||||
|
rootComponent: Component,
|
||||||
|
id: string | undefined,
|
||||||
|
path: Component[] = []
|
||||||
|
): Component[] => {
|
||||||
if (!rootComponent || !id) {
|
if (!rootComponent || !id) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -75,11 +84,14 @@ export const findComponentPath = (rootComponent, id, path = []) => {
|
||||||
* Recurses through the component tree and finds all components which match
|
* Recurses through the component tree and finds all components which match
|
||||||
* a certain selector
|
* a certain selector
|
||||||
*/
|
*/
|
||||||
export const findAllMatchingComponents = (rootComponent, selector) => {
|
export const findAllMatchingComponents = (
|
||||||
|
rootComponent: Component | null,
|
||||||
|
selector: (component: Component) => boolean
|
||||||
|
) => {
|
||||||
if (!rootComponent || !selector) {
|
if (!rootComponent || !selector) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let components = []
|
let components: Component[] = []
|
||||||
if (rootComponent._children) {
|
if (rootComponent._children) {
|
||||||
rootComponent._children.forEach(child => {
|
rootComponent._children.forEach(child => {
|
||||||
components = [
|
components = [
|
||||||
|
@ -97,7 +109,7 @@ export const findAllMatchingComponents = (rootComponent, selector) => {
|
||||||
/**
|
/**
|
||||||
* Recurses through the component tree and finds all components.
|
* Recurses through the component tree and finds all components.
|
||||||
*/
|
*/
|
||||||
export const findAllComponents = rootComponent => {
|
export const findAllComponents = (rootComponent: Component) => {
|
||||||
return findAllMatchingComponents(rootComponent, () => true)
|
return findAllMatchingComponents(rootComponent, () => true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,9 +117,9 @@ export const findAllComponents = rootComponent => {
|
||||||
* Finds the closest parent component which matches certain criteria
|
* Finds the closest parent component which matches certain criteria
|
||||||
*/
|
*/
|
||||||
export const findClosestMatchingComponent = (
|
export const findClosestMatchingComponent = (
|
||||||
rootComponent,
|
rootComponent: Component,
|
||||||
componentId,
|
componentId: string | undefined,
|
||||||
selector
|
selector: (component: Component) => boolean
|
||||||
) => {
|
) => {
|
||||||
if (!selector) {
|
if (!selector) {
|
||||||
return null
|
return null
|
||||||
|
@ -125,7 +137,10 @@ export const findClosestMatchingComponent = (
|
||||||
* Recurses through a component tree evaluating a matching function against
|
* Recurses through a component tree evaluating a matching function against
|
||||||
* components until a match is found
|
* components until a match is found
|
||||||
*/
|
*/
|
||||||
const searchComponentTree = (rootComponent, matchComponent) => {
|
const searchComponentTree = (
|
||||||
|
rootComponent: Component,
|
||||||
|
matchComponent: (component: Component) => boolean
|
||||||
|
): Component | null => {
|
||||||
if (!rootComponent || !matchComponent) {
|
if (!rootComponent || !matchComponent) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -150,15 +165,18 @@ const searchComponentTree = (rootComponent, matchComponent) => {
|
||||||
* This mutates the object in place.
|
* This mutates the object in place.
|
||||||
* @param component the component to randomise
|
* @param component the component to randomise
|
||||||
*/
|
*/
|
||||||
export const makeComponentUnique = component => {
|
export const makeComponentUnique = (component: Component) => {
|
||||||
if (!component) {
|
if (!component) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a full set of component ID replacements in this tree
|
// Generate a full set of component ID replacements in this tree
|
||||||
const idReplacements = []
|
const idReplacements: [string, string][] = []
|
||||||
const generateIdReplacements = (component, replacements) => {
|
const generateIdReplacements = (
|
||||||
const oldId = component._id
|
component: Component,
|
||||||
|
replacements: [string, string][]
|
||||||
|
) => {
|
||||||
|
const oldId = component._id!
|
||||||
const newId = Helpers.uuid()
|
const newId = Helpers.uuid()
|
||||||
replacements.push([oldId, newId])
|
replacements.push([oldId, newId])
|
||||||
component._children?.forEach(x => generateIdReplacements(x, replacements))
|
component._children?.forEach(x => generateIdReplacements(x, replacements))
|
||||||
|
@ -182,9 +200,9 @@ export const makeComponentUnique = component => {
|
||||||
let js = decodeJSBinding(sanitizedBinding)
|
let js = decodeJSBinding(sanitizedBinding)
|
||||||
if (js != null) {
|
if (js != null) {
|
||||||
// Replace ID inside JS binding
|
// Replace ID inside JS binding
|
||||||
idReplacements.forEach(([oldId, newId]) => {
|
for (const [oldId, newId] of idReplacements) {
|
||||||
js = js.replace(new RegExp(oldId, "g"), newId)
|
js = js.replace(new RegExp(oldId, "g"), newId)
|
||||||
})
|
}
|
||||||
|
|
||||||
// Create new valid JS binding
|
// Create new valid JS binding
|
||||||
let newBinding = encodeJSBinding(js)
|
let newBinding = encodeJSBinding(js)
|
||||||
|
@ -204,7 +222,7 @@ export const makeComponentUnique = component => {
|
||||||
return JSON.parse(definition)
|
return JSON.parse(definition)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getComponentText = component => {
|
export const getComponentText = (component: Component) => {
|
||||||
if (component == null) {
|
if (component == null) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -218,7 +236,7 @@ export const getComponentText = component => {
|
||||||
return capitalise(type)
|
return capitalise(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getComponentName = component => {
|
export const getComponentName = (component: Component) => {
|
||||||
if (component == null) {
|
if (component == null) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -229,9 +247,9 @@ export const getComponentName = component => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets all contexts exposed by a certain component type, including actions
|
// Gets all contexts exposed by a certain component type, including actions
|
||||||
export const getComponentContexts = component => {
|
export const getComponentContexts = (component: string) => {
|
||||||
const def = componentStore.getDefinition(component)
|
const def = componentStore.getDefinition(component)
|
||||||
let contexts = []
|
let contexts: ComponentContext[] = []
|
||||||
if (def?.context) {
|
if (def?.context) {
|
||||||
contexts = Array.isArray(def.context) ? [...def.context] : [def.context]
|
contexts = Array.isArray(def.context) ? [...def.context] : [def.context]
|
||||||
}
|
}
|
||||||
|
@ -251,9 +269,9 @@ export const getComponentContexts = component => {
|
||||||
* Recurses through the component tree and builds a tree of contexts provided
|
* Recurses through the component tree and builds a tree of contexts provided
|
||||||
* by components.
|
* by components.
|
||||||
*/
|
*/
|
||||||
export const buildContextTree = (
|
const buildContextTree = (
|
||||||
rootComponent,
|
rootComponent: Component,
|
||||||
tree = { root: [] },
|
tree: Record<string, string[]> = { root: [] },
|
||||||
currentBranch = "root"
|
currentBranch = "root"
|
||||||
) => {
|
) => {
|
||||||
// Sanity check
|
// Sanity check
|
||||||
|
@ -264,12 +282,12 @@ export const buildContextTree = (
|
||||||
// Process this component's contexts
|
// Process this component's contexts
|
||||||
const contexts = getComponentContexts(rootComponent._component)
|
const contexts = getComponentContexts(rootComponent._component)
|
||||||
if (contexts.length) {
|
if (contexts.length) {
|
||||||
tree[currentBranch].push(rootComponent._id)
|
tree[currentBranch].push(rootComponent._id!)
|
||||||
|
|
||||||
// If we provide local context, start a new branch for our children
|
// If we provide local context, start a new branch for our children
|
||||||
if (contexts.some(context => context.scope === ContextScopes.Local)) {
|
if (contexts.some(context => context.scope === ContextScopes.Local)) {
|
||||||
currentBranch = rootComponent._id
|
currentBranch = rootComponent._id!
|
||||||
tree[rootComponent._id] = []
|
tree[rootComponent._id!] = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,9 +305,9 @@ export const buildContextTree = (
|
||||||
* Generates a lookup map of which context branch all components in a component
|
* Generates a lookup map of which context branch all components in a component
|
||||||
* tree are inside.
|
* tree are inside.
|
||||||
*/
|
*/
|
||||||
export const buildContextTreeLookupMap = rootComponent => {
|
export const buildContextTreeLookupMap = (rootComponent: Component) => {
|
||||||
const tree = buildContextTree(rootComponent)
|
const tree = buildContextTree(rootComponent)
|
||||||
let map = {}
|
const map: Record<string, string> = {}
|
||||||
Object.entries(tree).forEach(([branch, ids]) => {
|
Object.entries(tree).forEach(([branch, ids]) => {
|
||||||
ids.forEach(id => {
|
ids.forEach(id => {
|
||||||
map[id] = branch
|
map[id] = branch
|
||||||
|
@ -299,9 +317,9 @@ export const buildContextTreeLookupMap = rootComponent => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a flat list of ids for all descendants of a component
|
// Get a flat list of ids for all descendants of a component
|
||||||
export const getChildIdsForComponent = component => {
|
export const getChildIdsForComponent = (component: Component): string[] => {
|
||||||
return [
|
return [
|
||||||
component._id,
|
component._id!,
|
||||||
...(component?._children ?? []).map(getChildIdsForComponent).flat(1),
|
...(component?._children ?? []).map(getChildIdsForComponent).flat(1),
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -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
|
||||||
|
|
|
@ -58,7 +58,7 @@ export class ComponentTreeNodesStore extends BudiStore<OpenNodesState> {
|
||||||
|
|
||||||
const path = findComponentPath(selectedScreen.props, componentId)
|
const path = findComponentPath(selectedScreen.props, componentId)
|
||||||
|
|
||||||
const componentIds = path.map((component: Component) => component._id)
|
const componentIds = path.map((component: Component) => component._id!)
|
||||||
|
|
||||||
this.update((openNodes: OpenNodesState) => {
|
this.update((openNodes: OpenNodesState) => {
|
||||||
const newNodes = Object.fromEntries(
|
const newNodes = Object.fromEntries(
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// TODO: analise and fix all the undefined ! and ?
|
||||||
|
|
||||||
import { get, derived } from "svelte/store"
|
import { get, derived } from "svelte/store"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { API } from "@/api"
|
import { API } from "@/api"
|
||||||
|
@ -36,7 +38,7 @@ import { Utils } from "@budibase/frontend-core"
|
||||||
import {
|
import {
|
||||||
ComponentDefinition,
|
ComponentDefinition,
|
||||||
ComponentSetting,
|
ComponentSetting,
|
||||||
Component as ComponentType,
|
Component,
|
||||||
ComponentCondition,
|
ComponentCondition,
|
||||||
FieldType,
|
FieldType,
|
||||||
Screen,
|
Screen,
|
||||||
|
@ -45,10 +47,6 @@ import {
|
||||||
import { utils } from "@budibase/shared-core"
|
import { utils } from "@budibase/shared-core"
|
||||||
import { getSequentialName } from "@/helpers/duplicate"
|
import { getSequentialName } from "@/helpers/duplicate"
|
||||||
|
|
||||||
interface Component extends ComponentType {
|
|
||||||
_id: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ComponentState {
|
export interface ComponentState {
|
||||||
components: Record<string, ComponentDefinition>
|
components: Record<string, ComponentDefinition>
|
||||||
customComponents: string[]
|
customComponents: string[]
|
||||||
|
@ -182,7 +180,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
* Takes an enriched component instance and applies any required migration
|
* Takes an enriched component instance and applies any required migration
|
||||||
* logic
|
* logic
|
||||||
*/
|
*/
|
||||||
migrateSettings(enrichedComponent: Component) {
|
migrateSettings(enrichedComponent: Component | null) {
|
||||||
const componentPrefix = "@budibase/standard-components"
|
const componentPrefix = "@budibase/standard-components"
|
||||||
let migrated = false
|
let migrated = false
|
||||||
|
|
||||||
|
@ -232,7 +230,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
|
|
||||||
enrichEmptySettings(
|
enrichEmptySettings(
|
||||||
component: Component,
|
component: Component,
|
||||||
opts: { screen?: Screen; parent?: Component; useDefaultValues?: boolean }
|
opts: { screen?: Screen; parent?: string; useDefaultValues?: boolean }
|
||||||
) {
|
) {
|
||||||
if (!component?._component) {
|
if (!component?._component) {
|
||||||
return
|
return
|
||||||
|
@ -240,7 +238,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
const defaultDS = this.getDefaultDatasource()
|
const defaultDS = this.getDefaultDatasource()
|
||||||
const settings = this.getComponentSettings(component._component)
|
const settings = this.getComponentSettings(component._component)
|
||||||
const { parent, screen, useDefaultValues } = opts || {}
|
const { parent, screen, useDefaultValues } = opts || {}
|
||||||
const treeId = parent?._id || component._id
|
const treeId = parent || component._id
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -425,7 +423,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
createInstance(
|
createInstance(
|
||||||
componentType: string,
|
componentType: string,
|
||||||
presetProps?: Record<string, any>,
|
presetProps?: Record<string, any>,
|
||||||
parent?: Component
|
parent?: string
|
||||||
): Component | null {
|
): Component | null {
|
||||||
const screen = get(selectedScreen)
|
const screen = get(selectedScreen)
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
|
@ -503,7 +501,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
async create(
|
async create(
|
||||||
componentType: string,
|
componentType: string,
|
||||||
presetProps?: Record<string, any>,
|
presetProps?: Record<string, any>,
|
||||||
parent?: Component,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) {
|
) {
|
||||||
const state = get(this.store)
|
const state = get(this.store)
|
||||||
|
@ -519,7 +517,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
// Insert in position if specified
|
// Insert in position if specified
|
||||||
if (parent && index != null) {
|
if (parent && index != null) {
|
||||||
await screenStore.patch((screen: Screen) => {
|
await screenStore.patch((screen: Screen) => {
|
||||||
let parentComponent = findComponent(screen.props, parent)
|
let parentComponent = findComponent(screen.props, parent)!
|
||||||
if (!parentComponent._children?.length) {
|
if (!parentComponent._children?.length) {
|
||||||
parentComponent._children = [componentInstance]
|
parentComponent._children = [componentInstance]
|
||||||
} else {
|
} else {
|
||||||
|
@ -538,7 +536,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
}
|
}
|
||||||
const currentComponent = findComponent(
|
const currentComponent = findComponent(
|
||||||
screen.props,
|
screen.props,
|
||||||
selectedComponentId
|
selectedComponentId!
|
||||||
)
|
)
|
||||||
if (!currentComponent) {
|
if (!currentComponent) {
|
||||||
return false
|
return false
|
||||||
|
@ -581,7 +579,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
|
|
||||||
componentTreeNodesStore.makeNodeVisible(componentInstance._id)
|
componentTreeNodesStore.makeNodeVisible(componentInstance._id!)
|
||||||
|
|
||||||
// Log event
|
// Log event
|
||||||
analytics.captureEvent(Events.COMPONENT_CREATED, {
|
analytics.captureEvent(Events.COMPONENT_CREATED, {
|
||||||
|
@ -633,7 +631,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
// Determine the next component to select, and select it before deletion
|
// Determine the next component to select, and select it before deletion
|
||||||
// to avoid an intermediate state of no component selection
|
// to avoid an intermediate state of no component selection
|
||||||
const state = get(this.store)
|
const state = get(this.store)
|
||||||
let nextId = ""
|
let nextId: string | null = ""
|
||||||
if (state.selectedComponentId === component._id) {
|
if (state.selectedComponentId === component._id) {
|
||||||
nextId = this.getNext()
|
nextId = this.getNext()
|
||||||
if (!nextId) {
|
if (!nextId) {
|
||||||
|
@ -646,7 +644,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
nextId = nextId.replace("-navigation", "-screen")
|
nextId = nextId.replace("-navigation", "-screen")
|
||||||
}
|
}
|
||||||
this.update(state => {
|
this.update(state => {
|
||||||
state.selectedComponentId = nextId
|
state.selectedComponentId = nextId ?? undefined
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -654,18 +652,18 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
// Patch screen
|
// Patch screen
|
||||||
await screenStore.patch((screen: Screen) => {
|
await screenStore.patch((screen: Screen) => {
|
||||||
// Check component exists
|
// Check component exists
|
||||||
component = findComponent(screen.props, component._id)
|
const updatedComponent = findComponent(screen.props, component._id!)
|
||||||
if (!component) {
|
if (!updatedComponent) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check component has a valid parent
|
// Check component has a valid parent
|
||||||
const parent = findComponentParent(screen.props, component._id)
|
const parent = findComponentParent(screen.props, updatedComponent._id)
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
parent._children = parent._children.filter(
|
parent._children = parent._children!.filter(
|
||||||
(child: Component) => child._id !== component._id
|
(child: Component) => child._id !== updatedComponent._id
|
||||||
)
|
)
|
||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
|
@ -729,7 +727,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
// Patch screen
|
// Patch screen
|
||||||
const patch = (screen: Screen) => {
|
const patch = (screen: Screen) => {
|
||||||
// Get up to date ref to target
|
// Get up to date ref to target
|
||||||
targetComponent = findComponent(screen.props, targetComponent._id)
|
targetComponent = findComponent(screen.props, targetComponent!._id!)!
|
||||||
if (!targetComponent) {
|
if (!targetComponent) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -743,7 +741,7 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
if (!cut) {
|
if (!cut) {
|
||||||
componentToPaste = makeComponentUnique(componentToPaste)
|
componentToPaste = makeComponentUnique(componentToPaste)
|
||||||
}
|
}
|
||||||
newComponentId = componentToPaste._id
|
newComponentId = componentToPaste._id!
|
||||||
|
|
||||||
// Strip grid position metadata if pasting into a new screen, but keep
|
// Strip grid position metadata if pasting into a new screen, but keep
|
||||||
// alignment metadata
|
// alignment metadata
|
||||||
|
@ -820,8 +818,8 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
throw "A valid screen must be selected"
|
throw "A valid screen must be selected"
|
||||||
}
|
}
|
||||||
const parent = findComponentParent(screen.props, componentId)
|
const parent = findComponentParent(screen.props, componentId)!
|
||||||
const index = parent?._children.findIndex(
|
const index = parent?._children?.findIndex(
|
||||||
(x: Component) => x._id === componentId
|
(x: Component) => x._id === componentId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -839,29 +837,29 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have siblings above us, choose the sibling or a descendant
|
// If we have siblings above us, choose the sibling or a descendant
|
||||||
if (index > 0) {
|
if (index !== undefined && index > 0) {
|
||||||
// If sibling before us accepts children, and is not collapsed, select a descendant
|
// If sibling before us accepts children, and is not collapsed, select a descendant
|
||||||
const previousSibling = parent._children[index - 1]
|
const previousSibling = parent._children![index - 1]
|
||||||
if (
|
if (
|
||||||
previousSibling._children?.length &&
|
previousSibling._children?.length &&
|
||||||
componentTreeNodesStore.isNodeExpanded(previousSibling._id)
|
componentTreeNodesStore.isNodeExpanded(previousSibling._id!)
|
||||||
) {
|
) {
|
||||||
let target = previousSibling
|
let target = previousSibling
|
||||||
while (
|
while (
|
||||||
target._children?.length &&
|
target._children?.length &&
|
||||||
componentTreeNodesStore.isNodeExpanded(target._id)
|
componentTreeNodesStore.isNodeExpanded(target._id!)
|
||||||
) {
|
) {
|
||||||
target = target._children[target._children.length - 1]
|
target = target._children[target._children.length - 1]
|
||||||
}
|
}
|
||||||
return target._id
|
return target._id!
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise just select sibling
|
// Otherwise just select sibling
|
||||||
return previousSibling._id
|
return previousSibling._id!
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no siblings above us, select the parent
|
// If no siblings above us, select the parent
|
||||||
return parent._id
|
return parent._id!
|
||||||
}
|
}
|
||||||
|
|
||||||
getNext() {
|
getNext() {
|
||||||
|
@ -873,9 +871,9 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
throw "A valid screen must be selected"
|
throw "A valid screen must be selected"
|
||||||
}
|
}
|
||||||
const parent = findComponentParent(screen.props, componentId)
|
const parent = findComponentParent(screen.props, componentId)
|
||||||
const index = parent?._children.findIndex(
|
const index = parent?._children?.findIndex(
|
||||||
(x: Component) => x._id === componentId
|
(x: Component) => x._id === componentId
|
||||||
)
|
)!
|
||||||
|
|
||||||
// Check for screen and navigation component edge cases
|
// Check for screen and navigation component edge cases
|
||||||
const screenComponentId = `${screen._id}-screen`
|
const screenComponentId = `${screen._id}-screen`
|
||||||
|
@ -888,37 +886,38 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
if (
|
if (
|
||||||
component?._children?.length &&
|
component?._children?.length &&
|
||||||
(state.selectedComponentId === navComponentId ||
|
(state.selectedComponentId === navComponentId ||
|
||||||
componentTreeNodesStore.isNodeExpanded(component._id))
|
componentTreeNodesStore.isNodeExpanded(component._id!))
|
||||||
) {
|
) {
|
||||||
return component._children[0]._id
|
return component._children[0]._id!
|
||||||
} else if (!parent) {
|
} else if (!parent) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise select the next sibling if we have one
|
// Otherwise select the next sibling if we have one
|
||||||
if (index < parent._children.length - 1) {
|
if (index < parent._children!.length - 1) {
|
||||||
const nextSibling = parent._children[index + 1]
|
const nextSibling = parent._children![index + 1]
|
||||||
return nextSibling._id
|
return nextSibling._id!
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last child, select our parents next sibling
|
// Last child, select our parents next sibling
|
||||||
let target = parent
|
let target = parent
|
||||||
let targetParent = findComponentParent(screen.props, target._id)
|
let targetParent = findComponentParent(screen.props, target._id)
|
||||||
let targetIndex = targetParent?._children.findIndex(
|
let targetIndex = targetParent?._children?.findIndex(
|
||||||
(child: Component) => child._id === target._id
|
(child: Component) => child._id === target._id
|
||||||
)
|
)!
|
||||||
while (
|
while (
|
||||||
targetParent != null &&
|
targetParent != null &&
|
||||||
targetIndex === targetParent._children?.length - 1
|
targetParent._children &&
|
||||||
|
targetIndex === targetParent._children.length - 1
|
||||||
) {
|
) {
|
||||||
target = targetParent
|
target = targetParent
|
||||||
targetParent = findComponentParent(screen.props, target._id)
|
targetParent = findComponentParent(screen.props, target._id)
|
||||||
targetIndex = targetParent?._children.findIndex(
|
targetIndex = targetParent?._children!.findIndex(
|
||||||
(child: Component) => child._id === target._id
|
(child: Component) => child._id === target._id
|
||||||
)
|
)!
|
||||||
}
|
}
|
||||||
if (targetParent) {
|
if (targetParent) {
|
||||||
return targetParent._children[targetIndex + 1]._id
|
return targetParent._children![targetIndex + 1]._id!
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -950,16 +949,16 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
const parent = findComponentParent(screen.props, componentId)
|
const parent = findComponentParent(screen.props, componentId)
|
||||||
|
|
||||||
// Check we aren't right at the top of the tree
|
// Check we aren't right at the top of the tree
|
||||||
const index = parent?._children.findIndex(
|
const index = parent?._children?.findIndex(
|
||||||
(x: Component) => x._id === componentId
|
(x: Component) => x._id === componentId
|
||||||
)
|
)!
|
||||||
if (!parent || (index === 0 && parent._id === screen.props._id)) {
|
if (!parent || (index === 0 && parent._id === screen.props._id)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy original component and remove it from the parent
|
// Copy original component and remove it from the parent
|
||||||
const originalComponent = cloneDeep(parent._children[index])
|
const originalComponent = cloneDeep(parent._children![index])
|
||||||
parent._children = parent._children.filter(
|
parent._children = parent._children!.filter(
|
||||||
(component: Component) => component._id !== componentId
|
(component: Component) => component._id !== componentId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -971,9 +970,9 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
const definition = this.getDefinition(previousSibling._component)
|
const definition = this.getDefinition(previousSibling._component)
|
||||||
if (
|
if (
|
||||||
definition?.hasChildren &&
|
definition?.hasChildren &&
|
||||||
componentTreeNodesStore.isNodeExpanded(previousSibling._id)
|
componentTreeNodesStore.isNodeExpanded(previousSibling._id!)
|
||||||
) {
|
) {
|
||||||
previousSibling._children.push(originalComponent)
|
previousSibling._children!.push(originalComponent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise just move component above sibling
|
// Otherwise just move component above sibling
|
||||||
|
@ -985,11 +984,11 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
// If no siblings above us, go above the parent as long as it isn't
|
// If no siblings above us, go above the parent as long as it isn't
|
||||||
// the screen
|
// the screen
|
||||||
else if (parent._id !== screen.props._id) {
|
else if (parent._id !== screen.props._id) {
|
||||||
const grandParent = findComponentParent(screen.props, parent._id)
|
const grandParent = findComponentParent(screen.props, parent._id)!
|
||||||
const parentIndex = grandParent._children.findIndex(
|
const parentIndex = grandParent._children!.findIndex(
|
||||||
(child: Component) => child._id === parent._id
|
(child: Component) => child._id === parent._id
|
||||||
)
|
)
|
||||||
grandParent._children.splice(parentIndex, 0, originalComponent)
|
grandParent._children!.splice(parentIndex, 0, originalComponent)
|
||||||
}
|
}
|
||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
|
@ -1028,9 +1027,9 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
const definition = this.getDefinition(nextSibling._component)
|
const definition = this.getDefinition(nextSibling._component)
|
||||||
if (
|
if (
|
||||||
definition?.hasChildren &&
|
definition?.hasChildren &&
|
||||||
componentTreeNodesStore.isNodeExpanded(nextSibling._id)
|
componentTreeNodesStore.isNodeExpanded(nextSibling._id!)
|
||||||
) {
|
) {
|
||||||
nextSibling._children.splice(0, 0, originalComponent)
|
nextSibling._children!.splice(0, 0, originalComponent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise move below next sibling
|
// Otherwise move below next sibling
|
||||||
|
@ -1041,11 +1040,11 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
|
|
||||||
// Last child, so move below our parent
|
// Last child, so move below our parent
|
||||||
else {
|
else {
|
||||||
const grandParent = findComponentParent(screen.props, parent._id)
|
const grandParent = findComponentParent(screen.props, parent._id)!
|
||||||
const parentIndex = grandParent._children.findIndex(
|
const parentIndex = grandParent._children!.findIndex(
|
||||||
(child: Component) => child._id === parent._id
|
(child: Component) => child._id === parent._id
|
||||||
)
|
)
|
||||||
grandParent._children.splice(parentIndex + 1, 0, originalComponent)
|
grandParent._children!.splice(parentIndex + 1, 0, originalComponent)
|
||||||
}
|
}
|
||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
|
@ -1208,13 +1207,13 @@ export class ComponentStore extends BudiStore<ComponentState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace component with parent
|
// Replace component with parent
|
||||||
const index = oldParentDefinition._children.findIndex(
|
const index = oldParentDefinition._children!.findIndex(
|
||||||
(component: Component) => component._id === componentId
|
(component: Component) => component._id === componentId
|
||||||
)
|
)
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
oldParentDefinition._children[index] = {
|
oldParentDefinition._children![index] = {
|
||||||
...newParentDefinition,
|
...newParentDefinition,
|
||||||
_children: [definition],
|
_children: [definition],
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import { BudiStore } from "../BudiStore"
|
import { BudiStore } from "../BudiStore"
|
||||||
import { PreviewDevice, ComponentContext } from "@budibase/types"
|
import { PreviewDevice, ComponentContext, AppContext } from "@budibase/types"
|
||||||
|
|
||||||
type PreviewEventHandler = (name: string, payload?: any) => void
|
type PreviewEventHandler = (name: string, payload?: any) => void
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ interface PreviewState {
|
||||||
previewDevice: PreviewDevice
|
previewDevice: PreviewDevice
|
||||||
previewEventHandler: PreviewEventHandler | null
|
previewEventHandler: PreviewEventHandler | null
|
||||||
showPreview: boolean
|
showPreview: boolean
|
||||||
selectedComponentContext: ComponentContext | null
|
selectedComponentContext: AppContext | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const INITIAL_PREVIEW_STATE: PreviewState = {
|
const INITIAL_PREVIEW_STATE: PreviewState = {
|
||||||
|
|
|
@ -490,7 +490,7 @@ export class ScreenStore extends BudiStore<ScreenState> {
|
||||||
// Flatten the recursive component tree
|
// Flatten the recursive component tree
|
||||||
const components = findAllMatchingComponents(
|
const components = findAllMatchingComponents(
|
||||||
screen.props,
|
screen.props,
|
||||||
(x: Component) => x
|
(x: Component) => !!x
|
||||||
)
|
)
|
||||||
|
|
||||||
// Iterate over all components and run checks
|
// Iterate over all components and run checks
|
||||||
|
|
|
@ -112,10 +112,7 @@ export const EventPublishType = {
|
||||||
ENV_VAR_UPGRADE_PANEL_OPENED: "environment_variable_upgrade_panel_opened",
|
ENV_VAR_UPGRADE_PANEL_OPENED: "environment_variable_upgrade_panel_opened",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ContextScopes = {
|
export { ComponentContextScopes as ContextScopes } from "@budibase/types"
|
||||||
Local: "local",
|
|
||||||
Global: "global",
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TypeIconMap = {
|
export const TypeIconMap = {
|
||||||
[FieldType.STRING]: "Text",
|
[FieldType.STRING]: "Text",
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -28,6 +28,8 @@ export interface ComponentDefinition {
|
||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
}
|
}
|
||||||
|
context?: ComponentContext | ComponentContext[]
|
||||||
|
actions?: (string | any)[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DependsOnComponentSetting =
|
export type DependsOnComponentSetting =
|
||||||
|
@ -56,3 +58,28 @@ export interface ComponentSetting {
|
||||||
self: boolean
|
self: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
interface ComponentAction {
|
||||||
|
type: string
|
||||||
|
suffix?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ComponentStaticContextValue {
|
||||||
|
label: string
|
||||||
|
key: string
|
||||||
|
type: string // technically this is a long list of options but there are too many to enumerate
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ComponentContext {
|
||||||
|
type: ComponentContextType
|
||||||
|
scope?: ComponentContextScopes
|
||||||
|
actions?: ComponentAction[]
|
||||||
|
suffix?: string
|
||||||
|
values?: ComponentStaticContextValue[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ComponentContextType = "action" | "static" | "schema" | "form"
|
||||||
|
|
||||||
|
export const enum ComponentContextScopes {
|
||||||
|
Local = "local",
|
||||||
|
Global = "global",
|
||||||
|
}
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
export type PreviewDevice = "desktop" | "tablet" | "mobile"
|
export type PreviewDevice = "desktop" | "tablet" | "mobile"
|
||||||
export type ComponentContext = Record<string, any>
|
|
||||||
|
export type AppContext = Record<string, any>
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
"koa-body": "4.2.0",
|
"koa-body": "4.2.0",
|
||||||
"koa-compress": "4.0.1",
|
"koa-compress": "4.0.1",
|
||||||
"koa-passport": "4.1.4",
|
"koa-passport": "4.1.4",
|
||||||
|
"koa-redis": "^4.0.1",
|
||||||
"koa-send": "5.0.1",
|
"koa-send": "5.0.1",
|
||||||
"koa-session": "5.13.1",
|
"koa-session": "5.13.1",
|
||||||
"koa-static": "5.0.0",
|
"koa-static": "5.0.0",
|
||||||
|
@ -82,7 +83,6 @@
|
||||||
"@swc/jest": "0.2.27",
|
"@swc/jest": "0.2.27",
|
||||||
"@types/jest": "29.5.5",
|
"@types/jest": "29.5.5",
|
||||||
"@types/jsonwebtoken": "9.0.3",
|
"@types/jsonwebtoken": "9.0.3",
|
||||||
"@types/koa": "2.13.4",
|
|
||||||
"@types/koa__router": "12.0.4",
|
"@types/koa__router": "12.0.4",
|
||||||
"@types/lodash": "4.14.200",
|
"@types/lodash": "4.14.200",
|
||||||
"@types/node-fetch": "2.6.4",
|
"@types/node-fetch": "2.6.4",
|
||||||
|
|
|
@ -311,7 +311,7 @@ describe("/api/global/auth", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("GET /api/global/auth/:tenantId/oidc/callback", () => {
|
describe.skip("GET /api/global/auth/:tenantId/oidc/callback", () => {
|
||||||
it("logs in", async () => {
|
it("logs in", async () => {
|
||||||
const email = `${generator.guid()}@example.com`
|
const email = `${generator.guid()}@example.com`
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -4,7 +4,7 @@ if (process.env.DD_APM_ENABLED) {
|
||||||
|
|
||||||
// need to load environment first
|
// need to load environment first
|
||||||
import env from "./environment"
|
import env from "./environment"
|
||||||
import Application from "koa"
|
import Application, { Middleware } from "koa"
|
||||||
import { bootstrap } from "global-agent"
|
import { bootstrap } from "global-agent"
|
||||||
import * as db from "./db"
|
import * as db from "./db"
|
||||||
import { sdk as proSdk } from "@budibase/pro"
|
import { sdk as proSdk } from "@budibase/pro"
|
||||||
|
@ -20,6 +20,7 @@ import {
|
||||||
cache,
|
cache,
|
||||||
features,
|
features,
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
|
import RedisStore from "koa-redis"
|
||||||
|
|
||||||
db.init()
|
db.init()
|
||||||
import koaBody from "koa-body"
|
import koaBody from "koa-body"
|
||||||
|
@ -52,7 +53,28 @@ app.proxy = true
|
||||||
app.use(handleScimBody)
|
app.use(handleScimBody)
|
||||||
app.use(koaBody({ multipart: true }))
|
app.use(koaBody({ multipart: true }))
|
||||||
|
|
||||||
app.use(koaSession(app))
|
const sessionMiddleware: Middleware = async (ctx: any, next: any) => {
|
||||||
|
const redisClient = await new redis.Client(
|
||||||
|
redis.utils.Databases.SESSIONS
|
||||||
|
).init()
|
||||||
|
return koaSession(
|
||||||
|
{
|
||||||
|
// @ts-ignore
|
||||||
|
store: new RedisStore({ client: redisClient.getClient() }),
|
||||||
|
key: "koa:sess",
|
||||||
|
maxAge: 86400000, // one day
|
||||||
|
httpOnly: true,
|
||||||
|
secure: process.env.NODE_ENV === "production",
|
||||||
|
sameSite: "strict",
|
||||||
|
rolling: true,
|
||||||
|
renew: true,
|
||||||
|
},
|
||||||
|
app
|
||||||
|
)(ctx, next)
|
||||||
|
}
|
||||||
|
|
||||||
|
app.use(sessionMiddleware)
|
||||||
|
|
||||||
app.use(middleware.correlation)
|
app.use(middleware.correlation)
|
||||||
app.use(middleware.pino)
|
app.use(middleware.pino)
|
||||||
app.use(middleware.ip)
|
app.use(middleware.ip)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
declare module "koa-redis" {}
|
34
yarn.lock
34
yarn.lock
|
@ -2695,6 +2695,13 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
regenerator-runtime "^0.14.0"
|
regenerator-runtime "^0.14.0"
|
||||||
|
|
||||||
|
"@babel/runtime@^7.8.3":
|
||||||
|
version "7.26.9"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.26.9.tgz#aa4c6facc65b9cb3f87d75125ffd47781b475433"
|
||||||
|
integrity sha512-aA63XwOkcl4xxQa3HjPMqOP6LiK0ZDv3mUPYEFXkpHbaFjtGggE1A61FjFzJnB+p7/oy2gA8E+rcBNl/zC1tMg==
|
||||||
|
dependencies:
|
||||||
|
regenerator-runtime "^0.14.0"
|
||||||
|
|
||||||
"@babel/template@^7.22.15", "@babel/template@^7.22.5", "@babel/template@^7.25.9", "@babel/template@^7.3.3":
|
"@babel/template@^7.22.15", "@babel/template@^7.22.5", "@babel/template@^7.25.9", "@babel/template@^7.3.3":
|
||||||
version "7.25.9"
|
version "7.25.9"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.25.9.tgz#ecb62d81a8a6f5dc5fe8abfc3901fc52ddf15016"
|
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.25.9.tgz#ecb62d81a8a6f5dc5fe8abfc3901fc52ddf15016"
|
||||||
|
@ -2778,9 +2785,9 @@
|
||||||
through2 "^2.0.0"
|
through2 "^2.0.0"
|
||||||
|
|
||||||
"@budibase/pro@npm:@budibase/pro@latest":
|
"@budibase/pro@npm:@budibase/pro@latest":
|
||||||
version "3.4.6"
|
version "3.4.12"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.4.6.tgz#62b6ee13a015b98d4768dc7821f468f8177da3e9"
|
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.4.12.tgz#60e630944de4e2de970a04179d8f0f57d48ce75e"
|
||||||
integrity sha512-MC3P5SMokmqbjejZMlNM6z7NB9o5H6hZ++yVvbyThniBPYfuDc2ssa1HNwwcuNE3uRLhcxcKe8CY/0SbFgn51g==
|
integrity sha512-msUBmcWxRDg+ugjZvd27XudERQqtQRdiARsO8MaDVTcp5ejIXgshEIVVshHOCj3hcbRblw9pXvBIMI53iTMUsA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@anthropic-ai/sdk" "^0.27.3"
|
"@anthropic-ai/sdk" "^0.27.3"
|
||||||
"@budibase/backend-core" "*"
|
"@budibase/backend-core" "*"
|
||||||
|
@ -9041,7 +9048,14 @@ co-body@^5.1.1:
|
||||||
raw-body "^2.2.0"
|
raw-body "^2.2.0"
|
||||||
type-is "^1.6.14"
|
type-is "^1.6.14"
|
||||||
|
|
||||||
co@^4.6.0:
|
co-wrap-all@^1.0.0:
|
||||||
|
version "1.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/co-wrap-all/-/co-wrap-all-1.0.0.tgz#370ae3e8333510a53f6b2f7fdfbe4568a11b7ecf"
|
||||||
|
integrity sha512-aru6gLi2vTUazr+MxVm3Rv6ST7/EKtFj9BrfkcOrbCO2Qv6LqJdE71m88HhHiBEviKw/ucVrwoGLrq2xHpOsJA==
|
||||||
|
dependencies:
|
||||||
|
co "^4.0.0"
|
||||||
|
|
||||||
|
co@^4.0.0, co@^4.6.0:
|
||||||
version "4.6.0"
|
version "4.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
|
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
|
||||||
integrity sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==
|
integrity sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==
|
||||||
|
@ -13177,7 +13191,7 @@ ioredis@5.3.2:
|
||||||
redis-parser "^3.0.0"
|
redis-parser "^3.0.0"
|
||||||
standard-as-callback "^2.1.0"
|
standard-as-callback "^2.1.0"
|
||||||
|
|
||||||
ioredis@^4.28.5:
|
ioredis@^4.14.1, ioredis@^4.28.5:
|
||||||
version "4.28.5"
|
version "4.28.5"
|
||||||
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.28.5.tgz#5c149e6a8d76a7f8fa8a504ffc85b7d5b6797f9f"
|
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-4.28.5.tgz#5c149e6a8d76a7f8fa8a504ffc85b7d5b6797f9f"
|
||||||
integrity sha512-3GYo0GJtLqgNXj4YhrisLaNNvWSNwSS2wS4OELGfGxH8I69+XfNdnmV1AyN+ZqMh0i7eX+SWjrwFKDBDgfBC1A==
|
integrity sha512-3GYo0GJtLqgNXj4YhrisLaNNvWSNwSS2wS4OELGfGxH8I69+XfNdnmV1AyN+ZqMh0i7eX+SWjrwFKDBDgfBC1A==
|
||||||
|
@ -14677,6 +14691,16 @@ koa-pino-logger@4.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
pino-http "^6.5.0"
|
pino-http "^6.5.0"
|
||||||
|
|
||||||
|
koa-redis@^4.0.1:
|
||||||
|
version "4.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/koa-redis/-/koa-redis-4.0.1.tgz#57ac1b46d9ab851221a9f4952c1e8d4bf289db40"
|
||||||
|
integrity sha512-o2eTVNo1NBnloeUGhHed5Q2ZvJSLpUEj/+E1/7oH5EmH8WuQ+QLdl/VawkshxdFQ47W1p6V09lM3hCTu7D0YnQ==
|
||||||
|
dependencies:
|
||||||
|
"@babel/runtime" "^7.8.3"
|
||||||
|
co-wrap-all "^1.0.0"
|
||||||
|
debug "^4.1.1"
|
||||||
|
ioredis "^4.14.1"
|
||||||
|
|
||||||
koa-router@^10.0.0:
|
koa-router@^10.0.0:
|
||||||
version "10.1.1"
|
version "10.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/koa-router/-/koa-router-10.1.1.tgz#20809f82648518b84726cd445037813cd99f17ff"
|
resolved "https://registry.yarnpkg.com/koa-router/-/koa-router-10.1.1.tgz#20809f82648518b84726cd445037813cd99f17ff"
|
||||||
|
|
Loading…
Reference in New Issue