Merge branch 'master' into remove-automation-survey

This commit is contained in:
Andrew Kingston 2024-12-17 12:03:59 +00:00 committed by GitHub
commit 4f2de37c27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 233 additions and 108 deletions

View File

@ -15,6 +15,7 @@ import {
BuildWebhookSchemaResponse, BuildWebhookSchemaResponse,
TriggerWebhookRequest, TriggerWebhookRequest,
TriggerWebhookResponse, TriggerWebhookResponse,
AutomationIOType,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../sdk" import sdk from "../../sdk"
import * as pro from "@budibase/pro" import * as pro from "@budibase/pro"
@ -60,14 +61,21 @@ export async function buildSchema(
if (webhook.action.type === WebhookActionType.AUTOMATION) { if (webhook.action.type === WebhookActionType.AUTOMATION) {
let automation = await db.get<Automation>(webhook.action.target) let automation = await db.get<Automation>(webhook.action.target)
const autoOutputs = automation.definition.trigger.schema.outputs const autoOutputs = automation.definition.trigger.schema.outputs
let properties = webhook.bodySchema.properties let properties = webhook.bodySchema?.properties
// reset webhook outputs // reset webhook outputs
autoOutputs.properties = { autoOutputs.properties = {
body: autoOutputs.properties.body, body: autoOutputs.properties.body,
} }
for (let prop of Object.keys(properties)) { for (let prop of Object.keys(properties || {})) {
if (properties?.[prop] == null) {
continue
}
const def = properties[prop]
if (typeof def === "boolean") {
continue
}
autoOutputs.properties[prop] = { autoOutputs.properties[prop] = {
type: properties[prop].type, type: def.type as AutomationIOType,
description: AUTOMATION_DESCRIPTION, description: AUTOMATION_DESCRIPTION,
} }
} }

View File

@ -0,0 +1,65 @@
import * as automation from "../../index"
import * as setup from "../utilities"
import { Table, Webhook, WebhookActionType } from "@budibase/types"
import { createAutomationBuilder } from "../utilities/AutomationTestBuilder"
import { mocks } from "@budibase/backend-core/tests"
mocks.licenses.useSyncAutomations()
describe("Branching automations", () => {
let config = setup.getConfig(),
table: Table,
webhook: Webhook
async function createWebhookAutomation(testName: string) {
const builder = createAutomationBuilder({
name: testName,
})
const automation = await builder
.webhook({ fields: { parameter: "string" } })
.createRow({
row: { tableId: table._id!, name: "{{ trigger.parameter }}" },
})
.collect({ collection: `{{ trigger.parameter }}` })
.save()
webhook = await config.api.webhook.save({
name: "hook",
live: true,
action: {
type: WebhookActionType.AUTOMATION,
target: automation._id!,
},
bodySchema: {},
})
await config.api.webhook.buildSchema(config.getAppId(), webhook._id!, {
parameter: "string",
})
await config.publish()
return { webhook, automation }
}
beforeEach(async () => {
await automation.init()
await config.init()
table = await config.createTable()
})
afterAll(setup.afterAll)
it("should run the webhook automation - checking for parameters", async () => {
const { webhook } = await createWebhookAutomation(
"Check a basic webhook works as expected"
)
const res = await config.api.webhook.trigger(
config.getProdAppId(),
webhook._id!,
{
parameter: "testing",
}
)
expect(typeof res).toBe("object")
const collectedInfo = res as Record<string, any>
expect(collectedInfo.value).toEqual("testing")
})
})

View File

@ -1,42 +1,44 @@
import { v4 as uuidv4 } from "uuid" import { v4 as uuidv4 } from "uuid"
import { testAutomation } from "../../../api/routes/tests/utilities/TestFunctions" import { testAutomation } from "../../../api/routes/tests/utilities/TestFunctions"
import {} from "../../steps/createRow"
import { BUILTIN_ACTION_DEFINITIONS } from "../../actions" import { BUILTIN_ACTION_DEFINITIONS } from "../../actions"
import { TRIGGER_DEFINITIONS } from "../../triggers" import { TRIGGER_DEFINITIONS } from "../../triggers"
import { import {
LoopStepInputs, AppActionTriggerInputs,
DeleteRowStepInputs, AppActionTriggerOutputs,
UpdateRowStepInputs,
CreateRowStepInputs,
Automation, Automation,
AutomationTrigger,
AutomationResults,
SmtpEmailStepInputs,
ExecuteQueryStepInputs,
QueryRowsStepInputs,
AutomationActionStepId, AutomationActionStepId,
AutomationTriggerStepId, AutomationResults,
AutomationStep, AutomationStep,
AutomationStepInputs,
AutomationTrigger,
AutomationTriggerDefinition, AutomationTriggerDefinition,
RowDeletedTriggerInputs, AutomationTriggerInputs,
RowDeletedTriggerOutputs, AutomationTriggerStepId,
RowUpdatedTriggerOutputs, BashStepInputs,
RowUpdatedTriggerInputs, Branch,
BranchStepInputs,
CollectStepInputs,
CreateRowStepInputs,
CronTriggerOutputs,
DeleteRowStepInputs,
ExecuteQueryStepInputs,
ExecuteScriptStepInputs,
FilterStepInputs,
LoopStepInputs,
OpenAIStepInputs,
QueryRowsStepInputs,
RowCreatedTriggerInputs, RowCreatedTriggerInputs,
RowCreatedTriggerOutputs, RowCreatedTriggerOutputs,
AppActionTriggerOutputs, RowDeletedTriggerInputs,
CronTriggerOutputs, RowDeletedTriggerOutputs,
AppActionTriggerInputs, RowUpdatedTriggerInputs,
AutomationStepInputs, RowUpdatedTriggerOutputs,
AutomationTriggerInputs,
ServerLogStepInputs,
BranchStepInputs,
SearchFilters, SearchFilters,
Branch, ServerLogStepInputs,
FilterStepInputs, SmtpEmailStepInputs,
ExecuteScriptStepInputs, UpdateRowStepInputs,
OpenAIStepInputs, WebhookTriggerInputs,
BashStepInputs, WebhookTriggerOutputs,
} from "@budibase/types" } from "@budibase/types"
import TestConfiguration from "../../../tests/utilities/TestConfiguration" import TestConfiguration from "../../../tests/utilities/TestConfiguration"
import * as setup from "../utilities" import * as setup from "../utilities"
@ -47,6 +49,7 @@ type TriggerOutputs =
| RowUpdatedTriggerOutputs | RowUpdatedTriggerOutputs
| RowDeletedTriggerOutputs | RowDeletedTriggerOutputs
| AppActionTriggerOutputs | AppActionTriggerOutputs
| WebhookTriggerOutputs
| CronTriggerOutputs | CronTriggerOutputs
| undefined | undefined
@ -180,6 +183,7 @@ class BaseStepBuilder {
opts opts
) )
} }
loop( loop(
inputs: LoopStepInputs, inputs: LoopStepInputs,
opts?: { stepName?: string; stepId?: string } opts?: { stepName?: string; stepId?: string }
@ -247,7 +251,20 @@ class BaseStepBuilder {
opts opts
) )
} }
collect(
input: CollectStepInputs,
opts?: { stepName?: string; stepId?: string }
): this {
return this.step(
AutomationActionStepId.COLLECT,
BUILTIN_ACTION_DEFINITIONS.COLLECT,
input,
opts
)
} }
}
class StepBuilder extends BaseStepBuilder { class StepBuilder extends BaseStepBuilder {
build(): AutomationStep[] { build(): AutomationStep[] {
return this.steps return this.steps
@ -329,6 +346,16 @@ class AutomationBuilder extends BaseStepBuilder {
) )
} }
webhook(outputs: WebhookTriggerOutputs, inputs?: WebhookTriggerInputs) {
this.triggerOutputs = outputs
return this.trigger(
TRIGGER_DEFINITIONS.WEBHOOK,
AutomationTriggerStepId.WEBHOOK,
inputs,
outputs
)
}
private trigger<TStep extends AutomationTriggerStepId>( private trigger<TStep extends AutomationTriggerStepId>(
triggerSchema: AutomationTriggerDefinition, triggerSchema: AutomationTriggerDefinition,
stepId: TStep, stepId: TStep,
@ -361,12 +388,16 @@ class AutomationBuilder extends BaseStepBuilder {
return this.automationConfig return this.automationConfig
} }
async run() { async save() {
if (!Object.keys(this.automationConfig.definition.trigger).length) { if (!Object.keys(this.automationConfig.definition.trigger).length) {
throw new Error("Please add a trigger to this automation test") throw new Error("Please add a trigger to this automation test")
} }
this.automationConfig.definition.steps = this.steps this.automationConfig.definition.steps = this.steps
const automation = await this.config.createAutomation(this.build()) return await this.config.createAutomation(this.build())
}
async run() {
const automation = await this.save()
const results = await testAutomation( const results = await testAutomation(
this.config, this.config,
automation, automation,

View File

@ -181,10 +181,14 @@ export async function externalTrigger(
coercedFields[key] = coerce(params.fields[key], fields[key]) coercedFields[key] = coerce(params.fields[key], fields[key])
} }
params.fields = coercedFields params.fields = coercedFields
} else if (sdk.automations.isRowAction(automation)) { }
// row actions and webhooks flatten the fields down
else if (
sdk.automations.isRowAction(automation) ||
sdk.automations.isWebhookAction(automation)
) {
params = { params = {
...params, ...params,
// Until we don't refactor all the types, we want to flatten the nested "fields" object
...params.fields, ...params.fields,
fields: {}, fields: {},
} }

View File

@ -16,6 +16,7 @@ import { TemplateAPI } from "./template"
import { RowActionAPI } from "./rowAction" import { RowActionAPI } from "./rowAction"
import { AutomationAPI } from "./automation" import { AutomationAPI } from "./automation"
import { PluginAPI } from "./plugin" import { PluginAPI } from "./plugin"
import { WebhookAPI } from "./webhook"
export default class API { export default class API {
table: TableAPI table: TableAPI
@ -35,6 +36,7 @@ export default class API {
rowAction: RowActionAPI rowAction: RowActionAPI
automation: AutomationAPI automation: AutomationAPI
plugin: PluginAPI plugin: PluginAPI
webhook: WebhookAPI
constructor(config: TestConfiguration) { constructor(config: TestConfiguration) {
this.table = new TableAPI(config) this.table = new TableAPI(config)
@ -54,5 +56,6 @@ export default class API {
this.rowAction = new RowActionAPI(config) this.rowAction = new RowActionAPI(config)
this.automation = new AutomationAPI(config) this.automation = new AutomationAPI(config)
this.plugin = new PluginAPI(config) this.plugin = new PluginAPI(config)
this.webhook = new WebhookAPI(config)
} }
} }

View File

@ -0,0 +1,58 @@
import { Expectations, TestAPI } from "./base"
import {
BuildWebhookSchemaResponse,
SaveWebhookResponse,
TriggerWebhookResponse,
Webhook,
} from "@budibase/types"
export class WebhookAPI extends TestAPI {
save = async (webhook: Webhook, expectations?: Expectations) => {
const resp = await this._put<SaveWebhookResponse>("/api/webhooks", {
body: webhook,
expectations: {
status: 200,
...expectations,
},
})
return resp.webhook
}
buildSchema = async (
appId: string,
webhookId: string,
fields: Record<string, any>,
expectations?: Expectations
) => {
const resp = await this._post<BuildWebhookSchemaResponse>(
`/api/webhooks/schema/${appId}/${webhookId}`,
{
body: fields,
expectations: {
status: 200,
...expectations,
},
}
)
return resp.id
}
trigger = async (
appId: string,
webhookId: string,
fields: Record<string, any>,
expectations?: Expectations
) => {
const resp = await this._post<TriggerWebhookResponse>(
`/api/webhooks/trigger/${appId}/${webhookId}`,
{
body: fields,
expectations: {
status: 200,
...expectations,
},
}
)
return resp
}
}

View File

@ -1,13 +1,17 @@
import { Automation, AutomationTriggerStepId } from "@budibase/types" import { Automation, AutomationTriggerStepId } from "@budibase/types"
export function isRowAction(automation: Automation) { export function isRowAction(automation: Automation) {
const result = return (
automation.definition.trigger?.stepId === AutomationTriggerStepId.ROW_ACTION automation.definition.trigger?.stepId === AutomationTriggerStepId.ROW_ACTION
return result )
}
export function isWebhookAction(automation: Automation) {
return (
automation.definition.trigger?.stepId === AutomationTriggerStepId.WEBHOOK
)
} }
export function isAppAction(automation: Automation) { export function isAppAction(automation: Automation) {
const result = return automation.definition.trigger?.stepId === AutomationTriggerStepId.APP
automation.definition.trigger?.stepId === AutomationTriggerStepId.APP
return result
} }

View File

@ -15,11 +15,12 @@
"jest": {}, "jest": {},
"devDependencies": { "devDependencies": {
"@budibase/nano": "10.1.5", "@budibase/nano": "10.1.5",
"@types/json-schema": "^7.0.15",
"@types/koa": "2.13.4", "@types/koa": "2.13.4",
"@types/redlock": "4.0.7", "@types/redlock": "4.0.7",
"koa-useragent": "^4.1.0",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"typescript": "5.7.2", "typescript": "5.7.2",
"koa-useragent": "^4.1.0",
"zod": "^3.23.8" "zod": "^3.23.8"
}, },
"dependencies": { "dependencies": {

View File

@ -150,6 +150,7 @@ export type OpenAIStepInputs = {
prompt: string prompt: string
model: Model model: Model
} }
export enum Model { export enum Model {
GPT_35_TURBO = "gpt-3.5-turbo", GPT_35_TURBO = "gpt-3.5-turbo",
// will only work with api keys that have access to the GPT4 API // will only work with api keys that have access to the GPT4 API
@ -296,3 +297,12 @@ export type RowUpdatedTriggerOutputs = {
id: string id: string
revision?: string revision?: string
} }
export type WebhookTriggerInputs = {
schemaUrl: string
triggerUrl: string
}
export type WebhookTriggerOutputs = {
fields: Record<string, any>
}

View File

@ -1,4 +1,5 @@
import { Document } from "../document" import { Document } from "../document"
import { JSONSchema7 } from "json-schema"
export enum WebhookActionType { export enum WebhookActionType {
AUTOMATION = "automation", AUTOMATION = "automation",
@ -11,5 +12,5 @@ export interface Webhook extends Document {
type: WebhookActionType type: WebhookActionType
target: string target: string
} }
bodySchema?: any bodySchema?: JSONSchema7
} }

View File

@ -2088,47 +2088,6 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@3.2.26":
version "0.0.0"
dependencies:
"@budibase/nano" "10.1.5"
"@budibase/pouchdb-replication-stream" "1.2.11"
"@budibase/shared-core" "*"
"@budibase/types" "*"
"@techpass/passport-openidconnect" "0.3.3"
aws-cloudfront-sign "3.0.2"
aws-sdk "2.1692.0"
bcrypt "5.1.0"
bcryptjs "2.4.3"
bull "4.10.1"
correlation-id "4.0.0"
dd-trace "5.26.0"
dotenv "16.0.1"
google-auth-library "^8.0.1"
google-spreadsheet "npm:@budibase/google-spreadsheet@4.1.5"
ioredis "5.3.2"
joi "17.6.0"
jsonwebtoken "9.0.2"
knex "2.4.2"
koa-passport "^6.0.0"
koa-pino-logger "4.0.0"
lodash "4.17.21"
node-fetch "2.6.7"
passport-google-oauth "2.0.0"
passport-local "1.0.0"
passport-oauth2-refresh "^2.1.0"
pino "8.11.0"
pino-http "8.3.3"
posthog-node "4.0.1"
pouchdb "9.0.0"
pouchdb-find "9.0.0"
redlock "4.2.0"
rotating-file-stream "3.1.0"
sanitize-s3-objectkey "0.0.1"
semver "^7.5.4"
tar-fs "2.1.1"
uuid "^8.3.2"
"@budibase/handlebars-helpers@^0.13.2": "@budibase/handlebars-helpers@^0.13.2":
version "0.13.2" version "0.13.2"
resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.13.2.tgz#73ab51c464e91fd955b429017648e0257060db77" resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.13.2.tgz#73ab51c464e91fd955b429017648e0257060db77"
@ -2172,15 +2131,15 @@
through2 "^2.0.0" through2 "^2.0.0"
"@budibase/pro@npm:@budibase/pro@latest": "@budibase/pro@npm:@budibase/pro@latest":
version "3.2.26" version "3.2.28"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.2.26.tgz#3525535e07827ff820eefeeb94ad9e0e818ac698" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.2.28.tgz#59b5b37225715bb8fbf5b1c5c989140b10b58710"
integrity sha512-+V04NbKSBN3Up6vcyBFFpecQ3MrJvVuXN74JE9yLj+KVxQXJ1kwCrMgea/XyJomSc72PWb9sQzXADWTe5i5STA== integrity sha512-eDPeZpYFRZYQhCulcQAUwFoPk68c8+K9mIsB6QD3oMHmHTDA1P2ZcXvLNqDTIqHB94DqnWinqDf4hTuGYApgPA==
dependencies: dependencies:
"@anthropic-ai/sdk" "^0.27.3" "@anthropic-ai/sdk" "^0.27.3"
"@budibase/backend-core" "3.2.26" "@budibase/backend-core" "*"
"@budibase/shared-core" "3.2.26" "@budibase/shared-core" "*"
"@budibase/string-templates" "3.2.26" "@budibase/string-templates" "*"
"@budibase/types" "3.2.26" "@budibase/types" "*"
"@koa/router" "13.1.0" "@koa/router" "13.1.0"
bull "4.10.1" bull "4.10.1"
dd-trace "5.26.0" dd-trace "5.26.0"
@ -2193,25 +2152,6 @@
scim-patch "^0.8.1" scim-patch "^0.8.1"
scim2-parse-filter "^0.2.8" scim2-parse-filter "^0.2.8"
"@budibase/shared-core@3.2.26":
version "0.0.0"
dependencies:
"@budibase/types" "*"
cron-validate "1.4.5"
"@budibase/string-templates@3.2.26":
version "0.0.0"
dependencies:
"@budibase/handlebars-helpers" "^0.13.2"
dayjs "^1.10.8"
handlebars "^4.7.8"
lodash.clonedeep "^4.5.0"
"@budibase/types@3.2.26":
version "0.0.0"
dependencies:
scim-patch "^0.8.1"
"@bull-board/api@5.10.2": "@bull-board/api@5.10.2":
version "5.10.2" version "5.10.2"
resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-5.10.2.tgz#ae8ff6918b23897bf879a6ead3683f964374c4b3" resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-5.10.2.tgz#ae8ff6918b23897bf879a6ead3683f964374c4b3"