Merge branch 'master' of github.com:Budibase/budibase into update-aliasing
This commit is contained in:
commit
e2a81836a2
|
@ -26,6 +26,7 @@
|
|||
const values = writable({ name: "", url: null })
|
||||
const validation = createValidationStore()
|
||||
const encryptionValidation = createValidationStore()
|
||||
const isEncryptedRegex = /^.*\.enc.*\.tar\.gz$/gm
|
||||
|
||||
$: {
|
||||
const { url } = $values
|
||||
|
@ -37,7 +38,9 @@
|
|||
encryptionValidation.check({ ...$values })
|
||||
}
|
||||
|
||||
$: encryptedFile = $values.file?.name?.endsWith(".enc.tar.gz")
|
||||
// filename should be separated to avoid updates everytime any other form element changes
|
||||
$: filename = $values.file?.name
|
||||
$: encryptedFile = isEncryptedRegex.test(filename)
|
||||
|
||||
onMount(async () => {
|
||||
const lastChar = $auth.user?.firstName
|
||||
|
@ -171,7 +174,7 @@
|
|||
try {
|
||||
await createNewApp()
|
||||
} catch (error) {
|
||||
notifications.error("Error creating app")
|
||||
notifications.error(`Error creating app - ${error.message}`)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
import { Heading, Body, Layout, Button, Modal, Icon } from "@budibase/bbui"
|
||||
import { Heading, Body, Layout, Button, Modal } from "@budibase/bbui"
|
||||
import AutomationPanel from "@/components/automation/AutomationPanel/AutomationPanel.svelte"
|
||||
import CreateAutomationModal from "@/components/automation/AutomationPanel/CreateAutomationModal.svelte"
|
||||
import CreateWebhookModal from "@/components/automation/Shared/CreateWebhookModal.svelte"
|
||||
|
@ -12,17 +12,10 @@
|
|||
automationStore,
|
||||
selectedAutomation,
|
||||
} from "@/stores/builder"
|
||||
import { createLocalStorageStore } from "@budibase/frontend-core"
|
||||
import { fly } from "svelte/transition"
|
||||
|
||||
$: automationId = $selectedAutomation?.data?._id
|
||||
$: builderStore.selectResource(automationId)
|
||||
|
||||
const surveyDismissed = createLocalStorageStore("automation-survey", false)
|
||||
const stopSyncing = syncURLToState({
|
||||
urlParam: "automationId",
|
||||
stateKey: "selectedAutomationId",
|
||||
validate: id => $automationStore.automations.some(x => x._id === id),
|
||||
fallbackUrl: "./index",
|
||||
store: automationStore,
|
||||
update: automationStore.actions.select,
|
||||
|
@ -31,11 +24,9 @@
|
|||
|
||||
let modal
|
||||
let webhookModal
|
||||
let mounted = false
|
||||
|
||||
onMount(() => {
|
||||
$automationStore.showTestPanel = false
|
||||
mounted = true
|
||||
})
|
||||
|
||||
onDestroy(stopSyncing)
|
||||
|
@ -83,43 +74,6 @@
|
|||
</Modal>
|
||||
</div>
|
||||
|
||||
{#if !$surveyDismissed && mounted}
|
||||
<div
|
||||
class="survey"
|
||||
in:fly={{ x: 600, duration: 260, delay: 1000 }}
|
||||
out:fly={{ x: 600, duration: 260 }}
|
||||
>
|
||||
<div class="survey__body">
|
||||
<div class="survey__title">We value your feedback!</div>
|
||||
<div class="survey__text">
|
||||
<a
|
||||
href="https://t.maze.co/310149185"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
on:click={() => surveyDismissed.set(true)}
|
||||
>
|
||||
Complete our survey on Automations</a
|
||||
>
|
||||
and receive a $20 thank-you gift.
|
||||
<a
|
||||
href="https://drive.google.com/file/d/12-qk_2F9g5PdbM6wuKoz2KkIyLI-feMX/view?usp=sharing"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Terms apply.
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<Icon
|
||||
name="Close"
|
||||
hoverable
|
||||
color="var(--spectrum-global-color-static-gray-300)"
|
||||
hoverColor="var(--spectrum-global-color-static-gray-100)"
|
||||
on:click={() => surveyDismissed.set(true)}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.root {
|
||||
flex: 1 1 auto;
|
||||
|
@ -164,39 +118,4 @@
|
|||
grid-column: 3;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
/* Survey */
|
||||
.survey {
|
||||
position: absolute;
|
||||
bottom: 32px;
|
||||
right: 32px;
|
||||
background: var(--spectrum-semantic-positive-color-background);
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
padding: var(--spacing-l) var(--spacing-xl);
|
||||
border-radius: 4px;
|
||||
gap: var(--spacing-xl);
|
||||
}
|
||||
.survey * {
|
||||
color: var(--spectrum-global-color-static-gray-300);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.survey a {
|
||||
text-decoration: underline;
|
||||
transition: color 130ms ease-out;
|
||||
}
|
||||
.survey a:hover {
|
||||
color: var(--spectrum-global-color-static-gray-100);
|
||||
cursor: pointer;
|
||||
}
|
||||
.survey__body {
|
||||
flex: 1 1 auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.survey__title {
|
||||
font-weight: 600;
|
||||
font-size: 15px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
await auth.setInitInfo({})
|
||||
$goto(`/builder/app/${createdApp.instance._id}`)
|
||||
} catch (error) {
|
||||
notifications.error("Error creating app")
|
||||
notifications.error(`Error creating app - ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,25 @@ import {
|
|||
import { tables } from "./tables"
|
||||
import { queries } from "./queries"
|
||||
import { API } from "@/api"
|
||||
import { DatasourceFeature } from "@budibase/types"
|
||||
import {
|
||||
DatasourceFeature,
|
||||
Datasource,
|
||||
Table,
|
||||
Integration,
|
||||
UIIntegration,
|
||||
SourceName,
|
||||
} from "@budibase/types"
|
||||
import { TableNames } from "@/constants"
|
||||
|
||||
// when building the internal DS - seems to represent it slightly differently to the backend typing of a DS
|
||||
interface InternalDatasource extends Omit<Datasource, "entities"> {
|
||||
entities: Table[]
|
||||
}
|
||||
|
||||
class TableImportError extends Error {
|
||||
constructor(errors) {
|
||||
errors: Record<string, string>
|
||||
|
||||
constructor(errors: Record<string, string>) {
|
||||
super()
|
||||
this.name = "TableImportError"
|
||||
this.errors = errors
|
||||
|
@ -26,8 +40,13 @@ class TableImportError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
interface DatasourceStore {
|
||||
list: Datasource[]
|
||||
selectedDatasourceId: null | string
|
||||
}
|
||||
|
||||
export function createDatasourcesStore() {
|
||||
const store = writable({
|
||||
const store = writable<DatasourceStore>({
|
||||
list: [],
|
||||
selectedDatasourceId: null,
|
||||
})
|
||||
|
@ -36,23 +55,25 @@ export function createDatasourcesStore() {
|
|||
// Set the internal datasource entities from the table list, which we're
|
||||
// able to keep updated unlike the egress generated definition of the
|
||||
// internal datasource
|
||||
let internalDS = $store.list?.find(ds => ds._id === BUDIBASE_INTERNAL_DB_ID)
|
||||
let internalDS: Datasource | InternalDatasource | undefined =
|
||||
$store.list?.find(ds => ds._id === BUDIBASE_INTERNAL_DB_ID)
|
||||
let otherDS = $store.list?.filter(ds => ds._id !== BUDIBASE_INTERNAL_DB_ID)
|
||||
if (internalDS) {
|
||||
const tables: Table[] = $tables.list?.filter((table: Table) => {
|
||||
return (
|
||||
table.sourceId === BUDIBASE_INTERNAL_DB_ID &&
|
||||
table._id !== TableNames.USERS
|
||||
)
|
||||
})
|
||||
internalDS = {
|
||||
...internalDS,
|
||||
entities: $tables.list?.filter(table => {
|
||||
return (
|
||||
table.sourceId === BUDIBASE_INTERNAL_DB_ID &&
|
||||
table._id !== TableNames.USERS
|
||||
)
|
||||
}),
|
||||
entities: tables,
|
||||
}
|
||||
}
|
||||
|
||||
// Build up enriched DS list
|
||||
// Only add the internal DS if we have at least one non-users table
|
||||
let list = []
|
||||
let list: (InternalDatasource | Datasource)[] = []
|
||||
if (internalDS?.entities?.length) {
|
||||
list.push(internalDS)
|
||||
}
|
||||
|
@ -75,62 +96,82 @@ export function createDatasourcesStore() {
|
|||
}))
|
||||
}
|
||||
|
||||
const select = id => {
|
||||
const select = (id: string) => {
|
||||
store.update(state => ({
|
||||
...state,
|
||||
selectedDatasourceId: id,
|
||||
}))
|
||||
}
|
||||
|
||||
const updateDatasource = (response, { ignoreErrors } = {}) => {
|
||||
const updateDatasource = (
|
||||
response: { datasource: Datasource; errors?: Record<string, string> },
|
||||
{ ignoreErrors }: { ignoreErrors?: boolean } = {}
|
||||
) => {
|
||||
const { datasource, errors } = response
|
||||
if (!ignoreErrors && errors && Object.keys(errors).length > 0) {
|
||||
throw new TableImportError(errors)
|
||||
}
|
||||
replaceDatasource(datasource._id, datasource)
|
||||
select(datasource._id)
|
||||
replaceDatasource(datasource._id!, datasource)
|
||||
select(datasource._id!)
|
||||
return datasource
|
||||
}
|
||||
|
||||
const updateSchema = async (datasource, tablesFilter) => {
|
||||
const response = await API.buildDatasourceSchema({
|
||||
datasourceId: datasource?._id,
|
||||
tablesFilter,
|
||||
})
|
||||
const updateSchema = async (
|
||||
datasource: Datasource,
|
||||
tablesFilter: string[]
|
||||
) => {
|
||||
const response = await API.buildDatasourceSchema(
|
||||
datasource?._id!,
|
||||
tablesFilter
|
||||
)
|
||||
updateDatasource(response)
|
||||
}
|
||||
|
||||
const sourceCount = source => {
|
||||
const sourceCount = (source: string) => {
|
||||
return get(store).list.filter(datasource => datasource.source === source)
|
||||
.length
|
||||
}
|
||||
|
||||
const checkDatasourceValidity = async (integration, datasource) => {
|
||||
const checkDatasourceValidity = async (
|
||||
integration: Integration,
|
||||
datasource: Datasource
|
||||
): Promise<{ valid: boolean; error?: string }> => {
|
||||
if (integration.features?.[DatasourceFeature.CONNECTION_CHECKING]) {
|
||||
const { connected, error } = await API.validateDatasource(datasource)
|
||||
if (connected) {
|
||||
return
|
||||
return { valid: true }
|
||||
} else {
|
||||
return { valid: false, error }
|
||||
}
|
||||
|
||||
throw new Error(`Unable to connect: ${error}`)
|
||||
}
|
||||
return { valid: true }
|
||||
}
|
||||
|
||||
const create = async ({ integration, config }) => {
|
||||
const create = async ({
|
||||
integration,
|
||||
config,
|
||||
}: {
|
||||
integration: UIIntegration
|
||||
config: Record<string, any>
|
||||
}) => {
|
||||
const count = sourceCount(integration.name)
|
||||
const nameModifier = count === 0 ? "" : ` ${count + 1}`
|
||||
|
||||
const datasource = {
|
||||
const datasource: Datasource = {
|
||||
type: "datasource",
|
||||
source: integration.name,
|
||||
source: integration.name as SourceName,
|
||||
config,
|
||||
name: `${integration.friendlyName}${nameModifier}`,
|
||||
plus: integration.plus && integration.name !== IntegrationTypes.REST,
|
||||
isSQL: integration.isSQL,
|
||||
}
|
||||
|
||||
if (await checkDatasourceValidity(integration, datasource)) {
|
||||
throw new Error("Unable to connect")
|
||||
const { valid, error } = await checkDatasourceValidity(
|
||||
integration,
|
||||
datasource
|
||||
)
|
||||
if (!valid) {
|
||||
throw new Error(`Unable to connect - ${error}`)
|
||||
}
|
||||
|
||||
const response = await API.createDatasource({
|
||||
|
@ -141,7 +182,13 @@ export function createDatasourcesStore() {
|
|||
return updateDatasource(response, { ignoreErrors: true })
|
||||
}
|
||||
|
||||
const update = async ({ integration, datasource }) => {
|
||||
const update = async ({
|
||||
integration,
|
||||
datasource,
|
||||
}: {
|
||||
integration: Integration
|
||||
datasource: Datasource
|
||||
}) => {
|
||||
if (await checkDatasourceValidity(integration, datasource)) {
|
||||
throw new Error("Unable to connect")
|
||||
}
|
||||
|
@ -151,18 +198,15 @@ export function createDatasourcesStore() {
|
|||
return updateDatasource(response)
|
||||
}
|
||||
|
||||
const deleteDatasource = async datasource => {
|
||||
const deleteDatasource = async (datasource: Datasource) => {
|
||||
if (!datasource?._id || !datasource?._rev) {
|
||||
return
|
||||
}
|
||||
await API.deleteDatasource({
|
||||
datasourceId: datasource._id,
|
||||
datasourceRev: datasource._rev,
|
||||
})
|
||||
replaceDatasource(datasource._id, null)
|
||||
await API.deleteDatasource(datasource._id, datasource._rev)
|
||||
replaceDatasource(datasource._id)
|
||||
}
|
||||
|
||||
const replaceDatasource = (datasourceId, datasource) => {
|
||||
const replaceDatasource = (datasourceId: string, datasource?: Datasource) => {
|
||||
if (!datasourceId) {
|
||||
return
|
||||
}
|
||||
|
@ -200,7 +244,7 @@ export function createDatasourcesStore() {
|
|||
}
|
||||
}
|
||||
|
||||
const getTableNames = async datasource => {
|
||||
const getTableNames = async (datasource: Datasource) => {
|
||||
const info = await API.fetchInfoForDatasource(datasource)
|
||||
return info.tableNames || []
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
import { integrations } from "./integrations"
|
||||
import { derived } from "svelte/store"
|
||||
|
||||
import { DatasourceTypes } from "@/constants/backend"
|
||||
|
||||
const getIntegrationOrder = type => {
|
||||
if (type === DatasourceTypes.API) return 1
|
||||
if (type === DatasourceTypes.RELATIONAL) return 2
|
||||
if (type === DatasourceTypes.NON_RELATIONAL) return 3
|
||||
|
||||
// Sort all others arbitrarily by the first character of their name.
|
||||
// Character codes can technically be as low as 0, so make sure the number is at least 4
|
||||
return type.charCodeAt(0) + 4
|
||||
}
|
||||
|
||||
export const createSortedIntegrationsStore = () => {
|
||||
return derived(integrations, $integrations => {
|
||||
const integrationsAsArray = Object.entries($integrations).map(
|
||||
([name, integration]) => ({
|
||||
name,
|
||||
...integration,
|
||||
})
|
||||
)
|
||||
|
||||
return integrationsAsArray.sort((integrationA, integrationB) => {
|
||||
const integrationASortOrder = getIntegrationOrder(integrationA.type)
|
||||
const integrationBSortOrder = getIntegrationOrder(integrationB.type)
|
||||
if (integrationASortOrder === integrationBSortOrder) {
|
||||
return integrationA.friendlyName.localeCompare(
|
||||
integrationB.friendlyName
|
||||
)
|
||||
}
|
||||
|
||||
return integrationASortOrder < integrationBSortOrder ? -1 : 1
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const sortedIntegrations = createSortedIntegrationsStore()
|
|
@ -0,0 +1,45 @@
|
|||
import { integrations } from "./integrations"
|
||||
import { derived } from "svelte/store"
|
||||
import { DatasourceTypes } from "@/constants/backend"
|
||||
import { UIIntegration, Integration } from "@budibase/types"
|
||||
|
||||
const getIntegrationOrder = (type: string | undefined) => {
|
||||
// if type is not known, sort to end
|
||||
if (!type) {
|
||||
return Number.MAX_SAFE_INTEGER
|
||||
}
|
||||
if (type === DatasourceTypes.API) return 1
|
||||
if (type === DatasourceTypes.RELATIONAL) return 2
|
||||
if (type === DatasourceTypes.NON_RELATIONAL) return 3
|
||||
|
||||
// Sort all others arbitrarily by the first character of their name.
|
||||
// Character codes can technically be as low as 0, so make sure the number is at least 4
|
||||
return type.charCodeAt(0) + 4
|
||||
}
|
||||
|
||||
export const createSortedIntegrationsStore = () => {
|
||||
return derived<typeof integrations, UIIntegration[]>(
|
||||
integrations,
|
||||
$integrations => {
|
||||
const entries: [string, Integration][] = Object.entries($integrations)
|
||||
const integrationsAsArray = entries.map(([name, integration]) => ({
|
||||
name,
|
||||
...integration,
|
||||
}))
|
||||
|
||||
return integrationsAsArray.sort((integrationA, integrationB) => {
|
||||
const integrationASortOrder = getIntegrationOrder(integrationA.type)
|
||||
const integrationBSortOrder = getIntegrationOrder(integrationB.type)
|
||||
if (integrationASortOrder === integrationBSortOrder) {
|
||||
return integrationA.friendlyName.localeCompare(
|
||||
integrationB.friendlyName
|
||||
)
|
||||
}
|
||||
|
||||
return integrationASortOrder < integrationBSortOrder ? -1 : 1
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export const sortedIntegrations = createSortedIntegrationsStore()
|
|
@ -30,6 +30,10 @@ CREATE TABLE Products (
|
|||
name text,
|
||||
updated time
|
||||
);
|
||||
CREATE TABLE `table with space` (
|
||||
id serial primary key,
|
||||
name text
|
||||
);
|
||||
INSERT INTO Persons (FirstName, LastName, Age, Address, City, CreatedAt) VALUES ('Mike', 'Hughes', 28.2, '123 Fake Street', 'Belfast', '2021-01-19 03:14:07');
|
||||
INSERT INTO Persons (FirstName, LastName, Age, Address, City, CreatedAt) VALUES ('Dave', 'Johnson', 29, '124 Fake Street', 'Belfast', '2022-04-01 00:11:11');
|
||||
INSERT INTO Person (Name) VALUES ('Elf');
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
BuildWebhookSchemaResponse,
|
||||
TriggerWebhookRequest,
|
||||
TriggerWebhookResponse,
|
||||
AutomationIOType,
|
||||
} from "@budibase/types"
|
||||
import sdk from "../../sdk"
|
||||
import * as pro from "@budibase/pro"
|
||||
|
@ -60,14 +61,21 @@ export async function buildSchema(
|
|||
if (webhook.action.type === WebhookActionType.AUTOMATION) {
|
||||
let automation = await db.get<Automation>(webhook.action.target)
|
||||
const autoOutputs = automation.definition.trigger.schema.outputs
|
||||
let properties = webhook.bodySchema.properties
|
||||
let properties = webhook.bodySchema?.properties
|
||||
// reset webhook outputs
|
||||
autoOutputs.properties = {
|
||||
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] = {
|
||||
type: properties[prop].type,
|
||||
type: def.type as AutomationIOType,
|
||||
description: AUTOMATION_DESCRIPTION,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
})
|
||||
})
|
|
@ -1,42 +1,44 @@
|
|||
import { v4 as uuidv4 } from "uuid"
|
||||
import { testAutomation } from "../../../api/routes/tests/utilities/TestFunctions"
|
||||
import {} from "../../steps/createRow"
|
||||
import { BUILTIN_ACTION_DEFINITIONS } from "../../actions"
|
||||
import { TRIGGER_DEFINITIONS } from "../../triggers"
|
||||
import {
|
||||
LoopStepInputs,
|
||||
DeleteRowStepInputs,
|
||||
UpdateRowStepInputs,
|
||||
CreateRowStepInputs,
|
||||
AppActionTriggerInputs,
|
||||
AppActionTriggerOutputs,
|
||||
Automation,
|
||||
AutomationTrigger,
|
||||
AutomationResults,
|
||||
SmtpEmailStepInputs,
|
||||
ExecuteQueryStepInputs,
|
||||
QueryRowsStepInputs,
|
||||
AutomationActionStepId,
|
||||
AutomationTriggerStepId,
|
||||
AutomationResults,
|
||||
AutomationStep,
|
||||
AutomationStepInputs,
|
||||
AutomationTrigger,
|
||||
AutomationTriggerDefinition,
|
||||
RowDeletedTriggerInputs,
|
||||
RowDeletedTriggerOutputs,
|
||||
RowUpdatedTriggerOutputs,
|
||||
RowUpdatedTriggerInputs,
|
||||
AutomationTriggerInputs,
|
||||
AutomationTriggerStepId,
|
||||
BashStepInputs,
|
||||
Branch,
|
||||
BranchStepInputs,
|
||||
CollectStepInputs,
|
||||
CreateRowStepInputs,
|
||||
CronTriggerOutputs,
|
||||
DeleteRowStepInputs,
|
||||
ExecuteQueryStepInputs,
|
||||
ExecuteScriptStepInputs,
|
||||
FilterStepInputs,
|
||||
LoopStepInputs,
|
||||
OpenAIStepInputs,
|
||||
QueryRowsStepInputs,
|
||||
RowCreatedTriggerInputs,
|
||||
RowCreatedTriggerOutputs,
|
||||
AppActionTriggerOutputs,
|
||||
CronTriggerOutputs,
|
||||
AppActionTriggerInputs,
|
||||
AutomationStepInputs,
|
||||
AutomationTriggerInputs,
|
||||
ServerLogStepInputs,
|
||||
BranchStepInputs,
|
||||
RowDeletedTriggerInputs,
|
||||
RowDeletedTriggerOutputs,
|
||||
RowUpdatedTriggerInputs,
|
||||
RowUpdatedTriggerOutputs,
|
||||
SearchFilters,
|
||||
Branch,
|
||||
FilterStepInputs,
|
||||
ExecuteScriptStepInputs,
|
||||
OpenAIStepInputs,
|
||||
BashStepInputs,
|
||||
ServerLogStepInputs,
|
||||
SmtpEmailStepInputs,
|
||||
UpdateRowStepInputs,
|
||||
WebhookTriggerInputs,
|
||||
WebhookTriggerOutputs,
|
||||
} from "@budibase/types"
|
||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||
import * as setup from "../utilities"
|
||||
|
@ -47,6 +49,7 @@ type TriggerOutputs =
|
|||
| RowUpdatedTriggerOutputs
|
||||
| RowDeletedTriggerOutputs
|
||||
| AppActionTriggerOutputs
|
||||
| WebhookTriggerOutputs
|
||||
| CronTriggerOutputs
|
||||
| undefined
|
||||
|
||||
|
@ -180,6 +183,7 @@ class BaseStepBuilder {
|
|||
opts
|
||||
)
|
||||
}
|
||||
|
||||
loop(
|
||||
inputs: LoopStepInputs,
|
||||
opts?: { stepName?: string; stepId?: string }
|
||||
|
@ -247,7 +251,20 @@ class BaseStepBuilder {
|
|||
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 {
|
||||
build(): AutomationStep[] {
|
||||
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>(
|
||||
triggerSchema: AutomationTriggerDefinition,
|
||||
stepId: TStep,
|
||||
|
@ -361,12 +388,16 @@ class AutomationBuilder extends BaseStepBuilder {
|
|||
return this.automationConfig
|
||||
}
|
||||
|
||||
async run() {
|
||||
async save() {
|
||||
if (!Object.keys(this.automationConfig.definition.trigger).length) {
|
||||
throw new Error("Please add a trigger to this automation test")
|
||||
}
|
||||
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(
|
||||
this.config,
|
||||
automation,
|
||||
|
|
|
@ -181,10 +181,14 @@ export async function externalTrigger(
|
|||
coercedFields[key] = coerce(params.fields[key], fields[key])
|
||||
}
|
||||
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,
|
||||
// Until we don't refactor all the types, we want to flatten the nested "fields" object
|
||||
...params.fields,
|
||||
fields: {},
|
||||
}
|
||||
|
|
|
@ -187,6 +187,20 @@ export async function importApp(
|
|||
await decryptFiles(tmpPath, template.file.password)
|
||||
}
|
||||
const contents = await fsp.readdir(tmpPath)
|
||||
const stillEncrypted = !!contents.find(name => name.endsWith(".enc"))
|
||||
if (stillEncrypted) {
|
||||
throw new Error("Files are encrypted but no password has been supplied.")
|
||||
}
|
||||
const isPlugin = !!contents.find(name => name === "plugin.min.js")
|
||||
if (isPlugin) {
|
||||
throw new Error("Supplied file is a plugin - cannot import as app.")
|
||||
}
|
||||
const isInvalid = !contents.find(name => name === DB_EXPORT_FILE)
|
||||
if (isInvalid) {
|
||||
throw new Error(
|
||||
"App export does not appear to be valid - no DB file found."
|
||||
)
|
||||
}
|
||||
// have to handle object import
|
||||
if (contents.length && opts.importObjStoreContents) {
|
||||
let promises = []
|
||||
|
|
|
@ -16,6 +16,7 @@ import { TemplateAPI } from "./template"
|
|||
import { RowActionAPI } from "./rowAction"
|
||||
import { AutomationAPI } from "./automation"
|
||||
import { PluginAPI } from "./plugin"
|
||||
import { WebhookAPI } from "./webhook"
|
||||
|
||||
export default class API {
|
||||
table: TableAPI
|
||||
|
@ -35,6 +36,7 @@ export default class API {
|
|||
rowAction: RowActionAPI
|
||||
automation: AutomationAPI
|
||||
plugin: PluginAPI
|
||||
webhook: WebhookAPI
|
||||
|
||||
constructor(config: TestConfiguration) {
|
||||
this.table = new TableAPI(config)
|
||||
|
@ -54,5 +56,6 @@ export default class API {
|
|||
this.rowAction = new RowActionAPI(config)
|
||||
this.automation = new AutomationAPI(config)
|
||||
this.plugin = new PluginAPI(config)
|
||||
this.webhook = new WebhookAPI(config)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -1,13 +1,17 @@
|
|||
import { Automation, AutomationTriggerStepId } from "@budibase/types"
|
||||
|
||||
export function isRowAction(automation: Automation) {
|
||||
const result =
|
||||
return (
|
||||
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) {
|
||||
const result =
|
||||
automation.definition.trigger?.stepId === AutomationTriggerStepId.APP
|
||||
return result
|
||||
return automation.definition.trigger?.stepId === AutomationTriggerStepId.APP
|
||||
}
|
||||
|
|
|
@ -15,11 +15,12 @@
|
|||
"jest": {},
|
||||
"devDependencies": {
|
||||
"@budibase/nano": "10.1.5",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"@types/koa": "2.13.4",
|
||||
"@types/redlock": "4.0.7",
|
||||
"koa-useragent": "^4.1.0",
|
||||
"rimraf": "3.0.2",
|
||||
"typescript": "5.7.2",
|
||||
"koa-useragent": "^4.1.0",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
@ -12,7 +12,7 @@ export interface UpdateDatasourceResponse {
|
|||
export interface CreateDatasourceRequest {
|
||||
datasource: Datasource
|
||||
fetchSchema?: boolean
|
||||
tablesFilter: string[]
|
||||
tablesFilter?: string[]
|
||||
}
|
||||
|
||||
export interface VerifyDatasourceRequest {
|
||||
|
|
|
@ -150,6 +150,7 @@ export type OpenAIStepInputs = {
|
|||
prompt: string
|
||||
model: Model
|
||||
}
|
||||
|
||||
export enum Model {
|
||||
GPT_35_TURBO = "gpt-3.5-turbo",
|
||||
// will only work with api keys that have access to the GPT4 API
|
||||
|
@ -296,3 +297,12 @@ export type RowUpdatedTriggerOutputs = {
|
|||
id: string
|
||||
revision?: string
|
||||
}
|
||||
|
||||
export type WebhookTriggerInputs = {
|
||||
schemaUrl: string
|
||||
triggerUrl: string
|
||||
}
|
||||
|
||||
export type WebhookTriggerOutputs = {
|
||||
fields: Record<string, any>
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Document } from "../document"
|
||||
import { JSONSchema7 } from "json-schema"
|
||||
|
||||
export enum WebhookActionType {
|
||||
AUTOMATION = "automation",
|
||||
|
@ -11,5 +12,5 @@ export interface Webhook extends Document {
|
|||
type: WebhookActionType
|
||||
target: string
|
||||
}
|
||||
bodySchema?: any
|
||||
bodySchema?: JSONSchema7
|
||||
}
|
||||
|
|
|
@ -3,3 +3,4 @@ export * from "./sdk"
|
|||
export * from "./api"
|
||||
export * from "./core"
|
||||
export * from "./shared"
|
||||
export * from "./ui"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export * from "./stores"
|
|
@ -0,0 +1 @@
|
|||
export * from "./integration"
|
|
@ -0,0 +1,5 @@
|
|||
import { Integration } from "@budibase/types"
|
||||
|
||||
export interface UIIntegration extends Integration {
|
||||
name: string
|
||||
}
|
74
yarn.lock
74
yarn.lock
|
@ -2088,47 +2088,6 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
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":
|
||||
version "0.13.2"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.13.2.tgz#73ab51c464e91fd955b429017648e0257060db77"
|
||||
|
@ -2172,15 +2131,15 @@
|
|||
through2 "^2.0.0"
|
||||
|
||||
"@budibase/pro@npm:@budibase/pro@latest":
|
||||
version "3.2.26"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.2.26.tgz#3525535e07827ff820eefeeb94ad9e0e818ac698"
|
||||
integrity sha512-+V04NbKSBN3Up6vcyBFFpecQ3MrJvVuXN74JE9yLj+KVxQXJ1kwCrMgea/XyJomSc72PWb9sQzXADWTe5i5STA==
|
||||
version "3.2.28"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.2.28.tgz#59b5b37225715bb8fbf5b1c5c989140b10b58710"
|
||||
integrity sha512-eDPeZpYFRZYQhCulcQAUwFoPk68c8+K9mIsB6QD3oMHmHTDA1P2ZcXvLNqDTIqHB94DqnWinqDf4hTuGYApgPA==
|
||||
dependencies:
|
||||
"@anthropic-ai/sdk" "^0.27.3"
|
||||
"@budibase/backend-core" "3.2.26"
|
||||
"@budibase/shared-core" "3.2.26"
|
||||
"@budibase/string-templates" "3.2.26"
|
||||
"@budibase/types" "3.2.26"
|
||||
"@budibase/backend-core" "*"
|
||||
"@budibase/shared-core" "*"
|
||||
"@budibase/string-templates" "*"
|
||||
"@budibase/types" "*"
|
||||
"@koa/router" "13.1.0"
|
||||
bull "4.10.1"
|
||||
dd-trace "5.26.0"
|
||||
|
@ -2193,25 +2152,6 @@
|
|||
scim-patch "^0.8.1"
|
||||
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":
|
||||
version "5.10.2"
|
||||
resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-5.10.2.tgz#ae8ff6918b23897bf879a6ead3683f964374c4b3"
|
||||
|
|
Loading…
Reference in New Issue