better integration API, parse JSON by default

This commit is contained in:
Martin McKeaveney 2021-01-15 13:11:51 +00:00
commit a7f9e2fb8f
32 changed files with 638 additions and 161 deletions

View File

@ -68,5 +68,6 @@ jobs:
env: env:
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }} DOCKER_USER: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_API_KEY }} DOCKER_PASSWORD: ${{ secrets.DOCKER_API_KEY }}
run: docker login -u $DOCKER_USER -p $DOCKER_PASSWORD run: |
run: yarn build:docker docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
yarn build:docker

View File

@ -9,7 +9,6 @@ services:
SELF_HOSTED: 1 SELF_HOSTED: 1
COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984 COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984
BUDIBASE_ENVIRONMENT: ${BUDIBASE_ENVIRONMENT} BUDIBASE_ENVIRONMENT: ${BUDIBASE_ENVIRONMENT}
LOGO_URL: ${LOGO_URL}
PORT: 4002 PORT: 4002
JWT_SECRET: ${JWT_SECRET} JWT_SECRET: ${JWT_SECRET}
depends_on: depends_on:
@ -43,6 +42,7 @@ services:
environment: environment:
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY} MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY} MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
MINIO_BROWSER: "off"
command: server /data command: server /data
healthcheck: healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]

View File

@ -5,9 +5,6 @@ MAIN_PORT=10000
# This should be updated # This should be updated
HOSTING_KEY=budibase HOSTING_KEY=budibase
# This section contains customisation options
LOGO_URL=https://logoipsum.com/logo/logo-15.svg
# This section contains all secrets pertaining to the system # This section contains all secrets pertaining to the system
# These should be updated # These should be updated
JWT_SECRET=testsecret JWT_SECRET=testsecret

View File

@ -1,5 +1,5 @@
{ {
"version": "0.4.3", "version": "0.5.3",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*" "packages/*"

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/builder", "name": "@budibase/builder",
"version": "0.4.3", "version": "0.5.3",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"private": true, "private": true,
"scripts": { "scripts": {
@ -64,7 +64,7 @@
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.52.4", "@budibase/bbui": "^1.52.4",
"@budibase/client": "^0.4.3", "@budibase/client": "^0.5.3",
"@budibase/colorpicker": "^1.0.1", "@budibase/colorpicker": "^1.0.1",
"@budibase/svelte-ag-grid": "^0.0.16", "@budibase/svelte-ag-grid": "^0.0.16",
"@fortawesome/fontawesome-free": "^5.14.0", "@fortawesome/fontawesome-free": "^5.14.0",

View File

@ -56,4 +56,13 @@ export default class Automation {
steps.splice(stepIdx, 1) steps.splice(stepIdx, 1)
this.automation.definition.steps = steps this.automation.definition.steps = steps
} }
constructBlock(type, stepId, blockDefinition) {
return {
...blockDefinition,
inputs: blockDefinition.inputs || {},
stepId,
type,
}
}
} }

View File

@ -2,6 +2,7 @@ import { writable } from "svelte/store"
import api from "../../api" import api from "../../api"
import Automation from "./Automation" import Automation from "./Automation"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import analytics from "analytics"
const automationActions = store => ({ const automationActions = store => ({
fetch: async () => { fetch: async () => {
@ -93,6 +94,9 @@ const automationActions = store => ({
state.selectedBlock = newBlock state.selectedBlock = newBlock
return state return state
}) })
analytics.captureEvent("Added Automation Block", {
name: block.name,
})
}, },
deleteAutomationBlock: block => { deleteAutomationBlock: block => {
store.update(state => { store.update(state => {

View File

@ -49,16 +49,9 @@
} }
function addBlockToAutomation(stepId, blockDefinition) { function addBlockToAutomation(stepId, blockDefinition) {
const newBlock = { const newBlock = $automationStore.selectedAutomation.constructBlock(
...blockDefinition, selectedTab, stepId, blockDefinition)
inputs: blockDefinition.inputs || {},
stepId,
type: selectedTab,
}
automationStore.actions.addBlockToAutomation(newBlock) automationStore.actions.addBlockToAutomation(newBlock)
analytics.captureEvent("Added Automation Block", {
name: blockDefinition.name,
})
closePopover() closePopover()
if (stepId === "WEBHOOK") { if (stepId === "WEBHOOK") {
webhookModal.show() webhookModal.show()

View File

@ -1,6 +1,7 @@
<script> <script>
import TableSelector from "./TableSelector.svelte" import TableSelector from "./TableSelector.svelte"
import RowSelector from "./RowSelector.svelte" import RowSelector from "./RowSelector.svelte"
import SchemaSetup from "./SchemaSetup.svelte"
import { Button, Input, Select, Label } from "@budibase/bbui" import { Button, Input, Select, Label } from "@budibase/bbui"
import { automationStore } from "builderStore" import { automationStore } from "builderStore"
import WebhookDisplay from "../Shared/WebhookDisplay.svelte" import WebhookDisplay from "../Shared/WebhookDisplay.svelte"
@ -70,6 +71,8 @@
<RowSelector bind:value={block.inputs[key]} {bindings} /> <RowSelector bind:value={block.inputs[key]} {bindings} />
{:else if value.customType === 'webhookUrl'} {:else if value.customType === 'webhookUrl'}
<WebhookDisplay value={block.inputs[key]} /> <WebhookDisplay value={block.inputs[key]} />
{:else if value.customType === 'triggerSchema'}
<SchemaSetup bind:value={block.inputs[key]} />
{:else if value.type === 'string' || value.type === 'number'} {:else if value.type === 'string' || value.type === 'number'}
<BindableInput <BindableInput
type="string" type="string"

View File

@ -0,0 +1,133 @@
<script>
import { Input, Select } from "@budibase/bbui"
export let value = {}
$: fieldsArray = Object.entries(value).map(([name, type]) => ({
name,
type,
}))
function addField() {
const newValue = { ...value }
newValue[""] = "string"
value = newValue
}
function removeField(name) {
const newValues = { ...value }
delete newValues[name]
value = newValues
}
const fieldNameChanged = originalName => e => {
// reconstruct using fieldsArray, so field order is preserved
let entries = [...fieldsArray]
const newName = e.target.value
if (newName) {
entries.find(f => f.name === originalName).name = newName
} else {
entries = entries.filter(f => f.name !== originalName)
}
value = entries.reduce((newVals, current) => {
newVals[current.name] = current.type
return newVals
}, {})
}
</script>
<div class="root">
<div class="add-field">
<i class="ri-add-line" on:click={addField} />
</div>
<div class="spacer" />
{#each fieldsArray as field}
<div class="field">
<Input
value={field.name}
secondary
on:change={fieldNameChanged(field.name)} />
<Select
secondary
extraThin
value={field.type}
on:blur={e => (value[field.name] = e.target.value)}>
<option>string</option>
<option>number</option>
<option>boolean</option>
<option>datetime</option>
</Select>
<i class="remove-field ri-delete-bin-line"
on:click={() => removeField(field.name)} />
</div>
{/each}
</div>
<style>
.root {
position: relative;
max-width: 100%;
overflow-x: auto;
/* so we can show the "+" button beside the "fields" label*/
top: -26px;
}
.spacer {
height: var(--spacing-s);
}
.field {
max-width: 100%;
background-color: var(--grey-2);
margin-bottom: var(--spacing-m);
border-style: solid;
border-width: 1px;
border-color: var(--grey-4);
display: grid;
/*grid-template-rows: auto auto;
grid-template-columns: auto;*/
position: relative;
overflow: hidden;
}
.field :global(select) {
padding: var(--spacing-xs) 2rem var(--spacing-m) var(--spacing-s) !important;
font-size: var(--font-size-xs);
color: var(--grey-7);
}
.field :global(.pointer) {
padding-bottom: var(--spacing-m) !important;
color: var(--grey-2);
}
.field :global(input) {
padding: var(--spacing-m) var(--spacing-xl) var(--spacing-xs) var(--spacing-m);
font-size: var(--font-size-s);
font-weight: bold;
}
.remove-field {
cursor: pointer;
color: var(--grey-6);
position: absolute;
top: var(--spacing-m);
right: 3px;
}
.remove-field:hover {
color: var(--black);
}
.add-field {
text-align: right;
}
.add-field > i {
cursor: pointer;
}
</style>

View File

@ -7,6 +7,7 @@
Heading, Heading,
Select Select
} from "@budibase/bbui" } from "@budibase/bbui"
import Editor from "./QueryEditor.svelte"
export let fields = {} export let fields = {}
export let schema export let schema
@ -17,23 +18,8 @@
$: fieldKeys = Object.keys(fields) $: fieldKeys = Object.keys(fields)
$: schemaKeys = Object.keys(schema.fields) $: schemaKeys = Object.keys(schema.fields)
$: console.log({ fields, schema }) function updateCustomFields({ detail }) {
fields.customData = detail.value
function addField() {
// Add the new field to custom fields for the query
schema.fields[draftField.name] = {
type: draftField.type
}
// reset the draft field
draftField = {}
}
function removeField(field) {
delete fields[field]
fields = fields
delete schema.fields[field]
schema = schema
} }
</script> </script>
@ -46,38 +32,21 @@
type={schema.fields[field]?.type} type={schema.fields[field]?.type}
required={schema.fields[field]?.required} required={schema.fields[field]?.required}
bind:value={fields[field]} /> bind:value={fields[field]} />
{#if !schema.fields[field]?.required}
<i class="ri-close-circle-line" on:click={() => removeField(field)} />
{/if}
</div> </div>
{/each} {/each}
</form> </form>
{#if schema.customisable && editable} <Label extraSmall grey>Data</Label>
<div> {#if schema.customisable}
<Label>Add Custom Field</Label> <Editor
<div class="new-field"> label="Query"
<Label extraSmall grey>Name</Label> mode="json"
<Label extraSmall grey>Type</Label> on:change={updateCustomFields}
<Input thin bind:value={draftField.name} /> readOnly={!editable}
<Select thin secondary bind:value={draftField.type}> value={fields.customData} />
<option value={"text"}>String</option>
<option value={"number"}>Number</option>
</Select>
</div>
<Button small thin secondary on:click={addField}>Add Field</Button>
</div>
{/if} {/if}
<style> <style>
.new-field {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: var(--spacing-m);
margin-top: var(--spacing-m);
margin-bottom: var(--spacing-m);
}
.field { .field {
margin-bottom: var(--spacing-m); margin-bottom: var(--spacing-m);
display: grid; display: grid;
@ -85,15 +54,4 @@
grid-gap: var(--spacing-m); grid-gap: var(--spacing-m);
align-items: center; align-items: center;
} }
i {
transition: all 0.2s;
}
i:hover {
transform: scale(1.1);
font-weight: 500;
cursor: pointer;
}
</style> </style>

View File

@ -47,5 +47,5 @@
value={query.fields.json} /> value={query.fields.json} />
{:else if schema.type === QueryTypes.FIELDS} {:else if schema.type === QueryTypes.FIELDS}
<FieldsBuilder bind:fields={query.fields} {schema} {editable} /> <FieldsBuilder bind:fields={query.fields} {schema} {editable} />
{:else if schema.type === QueryTypes.LIST}LIST STUFF{/if} {/if}
{/if} {/if}

View File

@ -8,8 +8,10 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { AddIcon, ArrowDownIcon } from "components/common/Icons/" import { AddIcon, ArrowDownIcon } from "components/common/Icons/"
import actionTypes from "./actions" import actionTypes from "./actions"
import { createEventDispatcher } from "svelte"
import { automationStore } from "builderStore"
const eventTypeKey = "##eventHandlerType" const EVENT_TYPE_KEY = "##eventHandlerType"
export let event export let event
@ -17,16 +19,10 @@
let addActionDropdown let addActionDropdown
let selectedAction let selectedAction
let draftEventHandler = { parameters: [] }
$: actions = event || [] $: actions = event || []
$: selectedActionComponent = $: selectedActionComponent =
selectedAction && selectedAction &&
actionTypes.find(t => t.name === selectedAction[eventTypeKey]).component actionTypes.find(t => t.name === selectedAction[EVENT_TYPE_KEY]).component
const updateEventHandler = (updatedHandler, index) => {
actions[index] = updatedHandler
}
const deleteAction = index => { const deleteAction = index => {
actions.splice(index, 1) actions.splice(index, 1)
@ -36,7 +32,7 @@
const addAction = actionType => () => { const addAction = actionType => () => {
const newAction = { const newAction = {
parameters: {}, parameters: {},
[eventTypeKey]: actionType.name, [EVENT_TYPE_KEY]: actionType.name,
} }
actions.push(newAction) actions.push(newAction)
selectedAction = newAction selectedAction = newAction
@ -79,7 +75,7 @@
<div class="action-container"> <div class="action-container">
<div class="action-header" on:click={selectAction(action)}> <div class="action-header" on:click={selectAction(action)}>
<span class:selected={action === selectedAction}> <span class:selected={action === selectedAction}>
{index + 1}. {action[eventTypeKey]} {index + 1}. {action[EVENT_TYPE_KEY]}
</span> </span>
</div> </div>
<i <i

View File

@ -5,6 +5,7 @@
import { notifier } from "builderStore/store/notifications" import { notifier } from "builderStore/store/notifications"
import EventEditor from "./EventEditor.svelte" import EventEditor from "./EventEditor.svelte"
import BottomDrawer from "components/common/BottomDrawer.svelte" import BottomDrawer from "components/common/BottomDrawer.svelte"
import { automationStore } from "builderStore"
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -17,10 +18,48 @@
drawerVisible = true drawerVisible = true
} }
const saveEventData = () => { const saveEventData = async () => {
// any automations that need created from event triggers
const automationsToCreate = value.filter(
action => action["##eventHandlerType"] === "Trigger Automation"
)
automationsToCreate.forEach(action => createAutomation(action.parameters))
dispatch("change", value) dispatch("change", value)
notifier.success("Component actions saved.") notifier.success("Component actions saved.")
} }
// called by the parent modal when actions are saved
const createAutomation = async parameters => {
if (parameters.automationId || !parameters.newAutomationName) return
await automationStore.actions.create({ name: parameters.newAutomationName })
const appActionDefinition = $automationStore.blockDefinitions.TRIGGER.APP
const newBlock = $automationStore.selectedAutomation.constructBlock(
"TRIGGER",
"APP",
appActionDefinition
)
newBlock.inputs = {
fields: Object.entries(parameters.fields).reduce(
(fields, [key, value]) => {
fields[key] = value.type
return fields
},
{}
),
}
automationStore.actions.addBlockToAutomation(newBlock)
await automationStore.actions.save($automationStore.selectedAutomation)
parameters.automationId = $automationStore.selectedAutomation.automation._id
delete parameters.newAutomationName
}
</script> </script>
<Button secondary small on:click={showDrawer}>Define Actions</Button> <Button secondary small on:click={showDrawer}>Define Actions</Button>

View File

@ -1,6 +1,6 @@
<script> <script>
// accepts an array of field names, and outputs an object of { FieldName: value } // accepts an array of field names, and outputs an object of { FieldName: value }
import { DataList, Label, TextButton, Spacer, Select } from "@budibase/bbui" import { DataList, Label, TextButton, Spacer, Select, Input } from "@budibase/bbui"
import { store, backendUiStore, currentAsset } from "builderStore" import { store, backendUiStore, currentAsset } from "builderStore"
import fetchBindableProperties from "builderStore/fetchBindableProperties" import fetchBindableProperties from "builderStore/fetchBindableProperties"
import { CloseCircleIcon, AddIcon } from "components/common/Icons" import { CloseCircleIcon, AddIcon } from "components/common/Icons"
@ -14,6 +14,7 @@
export let parameterFields export let parameterFields
export let schemaFields export let schemaFields
export let fieldLabel="Column"
const emptyField = () => ({ name: "", value: "" }) const emptyField = () => ({ name: "", value: "" })
@ -59,7 +60,7 @@
// value and type is needed by the client, so it can parse // value and type is needed by the client, so it can parse
// a string into a correct type // a string into a correct type
newParameterFields[field.name] = { newParameterFields[field.name] = {
type: schemaFields.find(f => f.name === field.name).type, type: schemaFields ? schemaFields.find(f => f.name === field.name).type : "string",
value: readableToRuntimeBinding(bindableProperties, field.value), value: readableToRuntimeBinding(bindableProperties, field.value),
} }
} }
@ -73,13 +74,17 @@
{#if fields} {#if fields}
{#each fields as field} {#each fields as field}
<Label size="m" color="dark">Column</Label> <Label size="m" color="dark">{fieldLabel}</Label>
<Select secondary bind:value={field.name} on:blur={rebuildParameters}> {#if schemaFields}
<option value="" /> <Select secondary bind:value={field.name} on:blur={rebuildParameters}>
{#each schemaFields as schemaField} <option value="" />
<option value={schemaField.name}>{schemaField.name}</option> {#each schemaFields as schemaField}
{/each} <option value={schemaField.name}>{schemaField.name}</option>
</Select> {/each}
</Select>
{:else}
<Input secondary bind:value={field.name} on:blur={rebuildParameters}/>
{/if}
<Label size="m" color="dark">Value</Label> <Label size="m" color="dark">Value</Label>
<DataList secondary bind:value={field.value} on:blur={rebuildParameters}> <DataList secondary bind:value={field.value} on:blur={rebuildParameters}>
<option value="" /> <option value="" />
@ -100,7 +105,7 @@
<Spacer small /> <Spacer small />
<TextButton text small blue on:click={addField}> <TextButton text small blue on:click={addField}>
Add Field Add {fieldLabel}
<div style="height: 20px; width: 20px;"> <div style="height: 20px; width: 20px;">
<AddIcon /> <AddIcon />
</div> </div>

View File

@ -0,0 +1,136 @@
<script>
import { Select, Label, Input } from "@budibase/bbui"
import { automationStore } from "builderStore"
import SaveFields from "./SaveFields.svelte"
const AUTOMATION_STATUS = {
NEW: "new",
EXISTING: "existing"
}
export let parameters = {}
let automationStatus = parameters.automationId ? AUTOMATION_STATUS.EXISTING : AUTOMATION_STATUS.NEW
$: automations = $automationStore.automations
.filter(a => a.definition.trigger?.stepId === "APP")
.map(automation => {
const schema = Object.entries(
automation.definition.trigger.inputs.fields
).map(([name, type]) => ({ name, type }))
return {
name: automation.name,
_id: automation._id,
schema,
}
})
$: hasAutomations = automations && automations.length > 0
$: selectedAutomation =
parameters &&
parameters.automationId &&
automations.find(a => a._id === parameters.automationId)
const onFieldsChanged = e => {
parameters.fields = e.detail
}
const setNew = () => {
automationStatus = AUTOMATION_STATUS.NEW
parameters.automationId = undefined
}
const setExisting = () => {
automationStatus = AUTOMATION_STATUS.EXISTING
parameters.newAutomationName = ""
}
</script>
<div class="root">
<div class="radio-container" on:click={setNew}>
<input
type="radio"
value={AUTOMATION_STATUS.NEW}
bind:group={automationStatus}
disabled={!hasAutomations}>
<Label disabled={!hasAutomations}>Create a new automation </Label>
</div>
<div class="radio-container" on:click={setExisting}>
<input
type="radio"
value={AUTOMATION_STATUS.EXISTING}
bind:group={automationStatus}
disabled={!hasAutomations}>
<Label disabled={!hasAutomations}>Use an existing automation </Label>
</div>
<Label size="m" color="dark">Automation</Label>
{#if automationStatus === AUTOMATION_STATUS.EXISTING}
<Select secondary bind:value={parameters.automationId} placeholder="Choose automation">
<option value="" />
{#each automations as automation}
<option value={automation._id}>{automation.name}</option>
{/each}
</Select>
{:else}
<Input secondary bind:value={parameters.newAutomationName} placeholder="Enter automation name" />
{/if}
<SaveFields
parameterFields={parameters.fields}
schemaFields={automationStatus === AUTOMATION_STATUS.EXISTING && selectedAutomation && selectedAutomation.schema}
fieldLabel="Field"
on:fieldschanged={onFieldsChanged} />
</div>
<style>
.root {
display: grid;
column-gap: var(--spacing-s);
row-gap: var(--spacing-s);
grid-template-columns: auto 1fr auto 1fr auto;
align-items: baseline;
}
.root :global(> div:nth-child(4)) {
grid-column: 2 / span 4;
}
.radio-container {
display: grid;
grid-template-columns: auto 1fr;
}
.radio-container:nth-child(1) {
grid-column: 1 / span 2;
}
.radio-container:nth-child(2) {
grid-column: 3 / span 3;
}
.radio-container :global(> label) {
margin-left: var(--spacing-m);
}
.radio-container > input {
margin-bottom: var(--spacing-s);
}
.radio-container > input:focus {
outline: none;
}
</style>

View File

@ -2,6 +2,7 @@ import NavigateTo from "./NavigateTo.svelte"
import SaveRow from "./SaveRow.svelte" import SaveRow from "./SaveRow.svelte"
import DeleteRow from "./DeleteRow.svelte" import DeleteRow from "./DeleteRow.svelte"
import ExecuteQuery from "./ExecuteQuery.svelte" import ExecuteQuery from "./ExecuteQuery.svelte"
import TriggerAutomation from "./TriggerAutomation.svelte"
// defines what actions are available, when adding a new one // defines what actions are available, when adding a new one
// the component is the setup panel for the action // the component is the setup panel for the action
@ -25,4 +26,8 @@ export default [
name: "Execute Query", name: "Execute Query",
component: ExecuteQuery, component: ExecuteQuery,
}, },
{
name: "Trigger Automation",
component: TriggerAutomation,
},
] ]

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/client", "name": "@budibase/client",
"version": "0.4.3", "version": "0.5.3",
"license": "MPL-2.0", "license": "MPL-2.0",
"main": "dist/budibase-client.js", "main": "dist/budibase-client.js",
"module": "dist/budibase-client.js", "module": "dist/budibase-client.js",
@ -15,7 +15,7 @@
"svelte-spa-router": "^3.0.5" "svelte-spa-router": "^3.0.5"
}, },
"devDependencies": { "devDependencies": {
"@budibase/standard-components": "^0.4.3", "@budibase/standard-components": "^0.5.3",
"@rollup/plugin-commonjs": "^16.0.0", "@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0", "@rollup/plugin-node-resolve": "^10.0.0",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
@ -29,5 +29,5 @@
"svelte": "^3.30.0", "svelte": "^3.30.0",
"svelte-jester": "^1.0.6" "svelte-jester": "^1.0.6"
}, },
"gitHead": "e4e053cb6ff9a0ddc7115b44ccaa24b8ec41fb9a" "gitHead": "62ebf3cedcd7e9b2494b4f8cbcfb90927609b491"
} }

View File

@ -0,0 +1,10 @@
import API from "./api"
/**
* Executes an automation. Must have "App Action" trigger.
*/
export const triggerAutomation = async (automationId, fields) => {
return await API.post({
url: `/api/automations/${automationId}/trigger`,
body: { fields },
})
}

View File

@ -8,3 +8,4 @@ export * from "./relationships"
export * from "./routes" export * from "./routes"
export * from "./queries" export * from "./queries"
export * from "./app" export * from "./app"
export * from "./automations"

View File

@ -1,6 +1,6 @@
import { enrichDataBinding, enrichDataBindings } from "./enrichDataBinding" import { enrichDataBinding, enrichDataBindings } from "./enrichDataBinding"
import { routeStore } from "../store" import { routeStore } from "../store"
import { saveRow, deleteRow, executeQuery } from "../api" import { saveRow, deleteRow, executeQuery, triggerAutomation } from "../api"
const saveRowHandler = async (action, context) => { const saveRowHandler = async (action, context) => {
let draft = context[`${action.parameters.contextPath}_draft`] let draft = context[`${action.parameters.contextPath}_draft`]
@ -21,6 +21,17 @@ const deleteRowHandler = async (action, context) => {
}) })
} }
const triggerAutomationHandler = async (action, context) => {
const params = {}
for (let field in action.parameters.fields) {
params[field] = enrichDataBinding(
action.parameters.fields[field].value,
context
)
}
await triggerAutomation(action.parameters.automationId, params)
}
const navigationHandler = action => { const navigationHandler = action => {
routeStore.actions.navigate(action.parameters.url) routeStore.actions.navigate(action.parameters.url)
} }
@ -42,6 +53,7 @@ const handlerMap = {
["Delete Row"]: deleteRowHandler, ["Delete Row"]: deleteRowHandler,
["Navigate To"]: navigationHandler, ["Navigate To"]: navigationHandler,
["Execute Query"]: queryExecutionHandler, ["Execute Query"]: queryExecutionHandler,
["Trigger Automation"]: triggerAutomationHandler,
} }
/** /**

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/server", "name": "@budibase/server",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "0.4.3", "version": "0.5.3",
"description": "Budibase Web Server", "description": "Budibase Web Server",
"main": "src/electron.js", "main": "src/electron.js",
"repository": { "repository": {
@ -49,8 +49,8 @@
"author": "Budibase", "author": "Budibase",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"@budibase/client": "^0.4.3",
"@elastic/elasticsearch": "^7.10.0", "@elastic/elasticsearch": "^7.10.0",
"@budibase/client": "^0.5.3",
"@koa/router": "^8.0.0", "@koa/router": "^8.0.0",
"@sendgrid/mail": "^7.1.1", "@sendgrid/mail": "^7.1.1",
"@sentry/node": "^5.19.2", "@sentry/node": "^5.19.2",
@ -118,5 +118,5 @@
"./scripts/jestSetup.js" "./scripts/jestSetup.js"
] ]
}, },
"gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691" "gitHead": "62ebf3cedcd7e9b2494b4f8cbcfb90927609b491"
} }

View File

@ -31,11 +31,18 @@ exports.save = async function(ctx) {
function enrichQueryFields(fields, parameters) { function enrichQueryFields(fields, parameters) {
const enrichedQuery = {} const enrichedQuery = {}
// enrich the fields with dynamic parameters // enrich the fields with dynamic parameters
for (let key in fields) { for (let key in fields) {
const template = handlebars.compile(fields[key]) const template = handlebars.compile(fields[key])
enrichedQuery[key] = template(parameters) enrichedQuery[key] = template(parameters)
} }
if (fields.json || fields.customData) {
enrichedQuery.json = JSON.parse(fields.json || fields.customData)
delete enrichedQuery.customData
}
return enrichedQuery return enrichedQuery
} }

View File

@ -2,6 +2,7 @@ const CouchDB = require("../db")
const emitter = require("../events/index") const emitter = require("../events/index")
const InMemoryQueue = require("../utilities/queue/inMemoryQueue") const InMemoryQueue = require("../utilities/queue/inMemoryQueue")
const { getAutomationParams } = require("../db/utils") const { getAutomationParams } = require("../db/utils")
const { coerceValue } = require("../utilities")
let automationQueue = new InMemoryQueue("automationQueue") let automationQueue = new InMemoryQueue("automationQueue")
@ -119,6 +120,37 @@ const BUILTIN_DEFINITIONS = {
}, },
type: "TRIGGER", type: "TRIGGER",
}, },
APP: {
name: "App Action",
event: "app:trigger",
icon: "ri-window-fill",
tagline: "Automation fired from the frontend",
description: "Trigger an automation from an action inside your app",
stepId: "APP",
inputs: {},
schema: {
inputs: {
properties: {
fields: {
type: "object",
customType: "triggerSchema",
title: "Fields",
},
},
required: [],
},
outputs: {
properties: {
fields: {
type: "object",
description: "Fields submitted from the app frontend",
},
},
required: ["fields"],
},
},
type: "TRIGGER",
},
} }
async function queueRelevantRowAutomations(event, eventType) { async function queueRelevantRowAutomations(event, eventType) {
@ -200,12 +232,19 @@ async function fillRowOutput(automation, params) {
module.exports.externalTrigger = async function(automation, params) { module.exports.externalTrigger = async function(automation, params) {
// TODO: replace this with allowing user in builder to input values in future // TODO: replace this with allowing user in builder to input values in future
if ( if (automation.definition != null && automation.definition.trigger != null) {
automation.definition != null && if (automation.definition.trigger.inputs.tableId != null) {
automation.definition.trigger != null && params = await fillRowOutput(automation, params)
automation.definition.trigger.inputs.tableId != null }
) { if (automation.definition.trigger.stepId === "APP") {
params = await fillRowOutput(automation, params) // values are likely to be submitted as strings, so we shall convert to correct type
const coercedFields = {}
const fields = automation.definition.trigger.inputs.fields
for (let key in fields) {
coercedFields[key] = coerceValue(params.fields[key], fields[key])
}
params.fields = coercedFields
}
} }
automationQueue.add({ automation, event: params }) automationQueue.add({ automation, event: params })

View File

@ -36,8 +36,6 @@ module.exports = {
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
DEPLOYMENT_DB_URL: process.env.DEPLOYMENT_DB_URL, DEPLOYMENT_DB_URL: process.env.DEPLOYMENT_DB_URL,
LOCAL_TEMPLATES: process.env.LOCAL_TEMPLATES, LOCAL_TEMPLATES: process.env.LOCAL_TEMPLATES,
// self hosting features
LOGO_URL: process.env.LOGO_URL,
_set(key, value) { _set(key, value) {
process.env[key] = value process.env[key] = value
module.exports[key] = value module.exports[key] = value

View File

@ -56,7 +56,7 @@ const SCHEMA = {
}, },
delete: { delete: {
"Airtable Ids": { "Airtable Ids": {
type: FIELD_TYPES.LIST, type: FIELD_TYPES.JSON,
}, },
}, },
}, },
@ -69,12 +69,12 @@ class AirtableIntegration {
} }
async create(query) { async create(query) {
const { table, ...rest } = query const { table, json } = query
try { try {
const records = await this.client(table).create([ const records = await this.client(table).create([
{ {
fields: rest, fields: json,
}, },
]) ])
return records return records
@ -87,7 +87,7 @@ class AirtableIntegration {
async read(query) { async read(query) {
try { try {
const records = await this.client(query.table) const records = await this.client(query.table)
.select({ maxRecords: 10, view: query.view }) .select({ maxRecords: query.numRecords || 10, view: query.view })
.firstPage() .firstPage()
return records.map(({ fields }) => fields) return records.map(({ fields }) => fields)
} catch (err) { } catch (err) {
@ -97,13 +97,13 @@ class AirtableIntegration {
} }
async update(query) { async update(query) {
const { table, id, ...rest } = query const { table, id, json } = query
try { try {
const records = await this.client(table).update([ const records = await this.client(table).update([
{ {
id, id,
fields: rest, fields: json,
}, },
]) ])
return records return records

View File

@ -6,21 +6,39 @@ const SCHEMA = {
url: { url: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
required: true, required: true,
default: "localhost", default: "http://localhost:5984",
}, },
database: { database: {
type: FIELD_TYPES.STRING, type: FIELD_TYPES.STRING,
required: true, required: true,
}, },
view: {
type: FIELD_TYPES.STRING,
required: true,
},
}, },
query: { query: {
json: { create: {
type: QUERY_TYPES.JSON, "CouchDB DSL": {
required: true, type: QUERY_TYPES.JSON,
},
},
read: {
"CouchDB DSL": {
type: QUERY_TYPES.JSON,
},
},
update: {
"CouchDB Document": {
type: QUERY_TYPES.JSON,
},
},
delete: {
"Document ID": {
type: QUERY_TYPES.FIELDS,
fields: {
id: {
type: FIELD_TYPES.STRING,
required: true,
},
},
},
}, },
}, },
} }
@ -31,10 +49,21 @@ class CouchDBIntegration {
this.client = new PouchDB(`${config.url}/${config.database}`) this.client = new PouchDB(`${config.url}/${config.database}`)
} }
async read() { async create(query) {
try {
const result = await this.client.post(query.json)
return result
} catch (err) {
console.error("Error writing to couchDB", err)
throw err
}
}
async read(query) {
try { try {
const result = await this.client.allDocs({ const result = await this.client.allDocs({
include_docs: true, include_docs: true,
...query.json,
}) })
return result.rows.map(row => row.doc) return result.rows.map(row => row.doc)
} catch (err) { } catch (err) {
@ -42,6 +71,26 @@ class CouchDBIntegration {
throw err throw err
} }
} }
async update(query) {
try {
const result = await this.client.put(query.json)
return result
} catch (err) {
console.error("Error updating couchDB document", err)
throw err
}
}
async delete(query) {
try {
const result = await this.client.remove(query.id)
return result
} catch (err) {
console.error("Error deleting couchDB document", err)
throw err
}
}
} }
module.exports = { module.exports = {

View File

@ -1,21 +1,69 @@
const { Client } = require("@elastic/elasticsearch") const { Client } = require("@elastic/elasticsearch")
const { QUERY_TYPES, FIELD_TYPES } = require("./Integration")
const SCHEMA = { const SCHEMA = {
datasource: { datasource: {
url: { url: {
type: "string", type: "string",
required: true, required: true,
default: "localhost", default: "http://localhost:9200",
},
index: {
type: "string",
required: true,
}, },
}, },
query: { query: {
json: { create: {
type: "json", "ES Query DSL": {
required: true, type: QUERY_TYPES.FIELDS,
customisable: true,
fields: {
index: {
type: FIELD_TYPES.STRING,
required: true,
},
},
},
},
read: {
"ES Query DSL": {
type: QUERY_TYPES.FIELDS,
customisable: true,
fields: {
index: {
type: FIELD_TYPES.STRING,
required: true,
},
},
},
},
update: {
"ES Query DSL": {
type: QUERY_TYPES.FIELDS,
customisable: true,
fields: {
id: {
type: FIELD_TYPES.STRING,
required: true,
},
index: {
type: FIELD_TYPES.STRING,
required: true,
},
},
},
},
delete: {
"Document ID": {
type: QUERY_TYPES.FIELDS,
fields: {
index: {
type: FIELD_TYPES.STRING,
required: true,
},
id: {
type: FIELD_TYPES.STRING,
required: true,
},
},
},
}, },
}, },
} }
@ -27,12 +75,14 @@ class ElasticSearchIntegration {
} }
async create(query) { async create(query) {
const { index, json } = query
try { try {
const result = await this.client.index({ const result = await this.client.index({
index: this.config.index, index,
body: JSON.parse(query.json), body: json,
}) })
return [result] return result.body
} catch (err) { } catch (err) {
console.error("Error writing to elasticsearch", err) console.error("Error writing to elasticsearch", err)
throw err throw err
@ -42,10 +92,11 @@ class ElasticSearchIntegration {
} }
async read(query) { async read(query) {
const { index, json } = query
try { try {
const result = await this.client.search({ const result = await this.client.search({
index: this.config.index, index: index,
body: JSON.parse(query.json), body: json,
}) })
return result.body.hits.hits.map(({ _source }) => _source) return result.body.hits.hits.map(({ _source }) => _source)
} catch (err) { } catch (err) {
@ -55,6 +106,35 @@ class ElasticSearchIntegration {
await this.client.close() await this.client.close()
} }
} }
async update(query) {
const { id, index, json } = query
try {
const result = await this.client.update({
id,
index,
body: json,
})
return result.body
} catch (err) {
console.error("Error querying elasticsearch", err)
throw err
} finally {
await this.client.close()
}
}
async delete(query) {
try {
const result = await this.client.delete(query)
return result.body
} catch (err) {
console.error("Error deleting from elasticsearch", err)
throw err
} finally {
await this.client.close()
}
}
} }
module.exports = { module.exports = {

View File

@ -43,14 +43,13 @@ class MongoIntegration {
async create(query) { async create(query) {
try { try {
const mongoQuery = query.json ? JSON.parse(query.json) : {}
await this.connect() await this.connect()
const db = this.client.db(this.config.db) const db = this.client.db(this.config.db)
const collection = db.collection(this.config.collection) const collection = db.collection(this.config.collection)
const result = await collection.insertOne(mongoQuery) const result = await collection.insertOne(query.json)
return result return result
} catch (err) { } catch (err) {
console.error("Error querying mongodb", err) console.error("Error writing to mongodb", err)
throw err throw err
} finally { } finally {
await this.client.close() await this.client.close()
@ -59,11 +58,10 @@ class MongoIntegration {
async read(query) { async read(query) {
try { try {
const mongoQuery = query.json ? JSON.parse(query.json) : {}
await this.connect() await this.connect()
const db = this.client.db(this.config.db) const db = this.client.db(this.config.db)
const collection = db.collection(this.config.collection) const collection = db.collection(this.config.collection)
const result = await collection.find(mongoQuery).toArray() const result = await collection.find(query.json).toArray()
return result return result
} catch (err) { } catch (err) {
console.error("Error querying mongodb", err) console.error("Error querying mongodb", err)

View File

@ -144,6 +144,23 @@ exports.walkDir = (dirPath, callback) => {
} }
} }
/**
* This will coerce a value to the correct types based on the type transform map
* @param {object} row The value to coerce
* @param {object} type The type fo coerce to
* @returns {object} The coerced value
*/
exports.coerceValue = (value, type) => {
// eslint-disable-next-line no-prototype-builtins
if (TYPE_TRANSFORM_MAP[type].hasOwnProperty(value)) {
return TYPE_TRANSFORM_MAP[type][value]
} else if (TYPE_TRANSFORM_MAP[type].parse) {
return TYPE_TRANSFORM_MAP[type].parse(value)
}
return value
}
/** /**
* This will coerce the values in a row to the correct types based on the type transform map and the * This will coerce the values in a row to the correct types based on the type transform map and the
* table schema. * table schema.
@ -159,25 +176,11 @@ exports.coerceRowValues = (row, table) => {
const field = table.schema[key] const field = table.schema[key]
if (!field) continue if (!field) continue
// eslint-disable-next-line no-prototype-builtins clonedRow[key] = exports.coerceValue(value, field.type)
if (TYPE_TRANSFORM_MAP[field.type].hasOwnProperty(value)) {
clonedRow[key] = TYPE_TRANSFORM_MAP[field.type][value]
} else if (TYPE_TRANSFORM_MAP[field.type].parse) {
clonedRow[key] = TYPE_TRANSFORM_MAP[field.type].parse(value)
}
} }
return clonedRow return clonedRow
} }
/**
* Gets the correct link to the logo URL depending on if running in Cloud or if running in self hosting.
* @returns {string} A URL which links to the correct default logo for new apps.
*/
exports.getLogoUrl = () => { exports.getLogoUrl = () => {
const BB_LOGO_URL = return "https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
if (env.SELF_HOSTED) {
return env.LOGO_URL || BB_LOGO_URL
}
return BB_LOGO_URL
} }

View File

@ -29,9 +29,9 @@
"keywords": [ "keywords": [
"svelte" "svelte"
], ],
"version": "0.4.3", "version": "0.5.3",
"license": "MIT", "license": "MIT",
"gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691", "gitHead": "62ebf3cedcd7e9b2494b4f8cbcfb90927609b491",
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.52.4", "@budibase/bbui": "^1.52.4",
"@budibase/svelte-ag-grid": "^0.0.16", "@budibase/svelte-ag-grid": "^0.0.16",

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/deployment", "name": "@budibase/deployment",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "0.3.8", "version": "0.5.3",
"description": "Budibase Deployment Server", "description": "Budibase Deployment Server",
"main": "src/index.js", "main": "src/index.js",
"repository": { "repository": {
@ -30,5 +30,6 @@
"koa-static": "^5.0.0", "koa-static": "^5.0.0",
"pino-pretty": "^4.0.0", "pino-pretty": "^4.0.0",
"server-destroy": "^1.0.1" "server-destroy": "^1.0.1"
} },
"gitHead": "62ebf3cedcd7e9b2494b4f8cbcfb90927609b491"
} }