diff --git a/packages/backend-core/src/events/publishers/automation.ts b/packages/backend-core/src/events/publishers/automation.ts index 5f4ce5a120..8b2574b739 100644 --- a/packages/backend-core/src/events/publishers/automation.ts +++ b/packages/backend-core/src/events/publishers/automation.ts @@ -19,7 +19,7 @@ export async function created( const properties: AutomationCreatedEvent = { appId: automation.appId, automationId: automation._id as string, - triggerId: automation.definition?.trigger?.id!, + triggerId: automation.definition?.trigger?.id, triggerType: automation.definition?.trigger?.stepId, } await publishEvent(Event.AUTOMATION_CREATED, properties, timestamp) @@ -29,7 +29,7 @@ export async function triggerUpdated(automation: Automation) { const properties: AutomationTriggerUpdatedEvent = { appId: automation.appId, automationId: automation._id as string, - triggerId: automation.definition?.trigger?.id!, + triggerId: automation.definition?.trigger?.id, triggerType: automation.definition?.trigger?.stepId, } await publishEvent(Event.AUTOMATION_TRIGGER_UPDATED, properties) @@ -39,7 +39,7 @@ export async function deleted(automation: Automation) { const properties: AutomationDeletedEvent = { appId: automation.appId, automationId: automation._id as string, - triggerId: automation.definition?.trigger?.id!, + triggerId: automation.definition?.trigger?.id, triggerType: automation.definition?.trigger?.stepId, } await publishEvent(Event.AUTOMATION_DELETED, properties) @@ -49,7 +49,7 @@ export async function tested(automation: Automation) { const properties: AutomationTestedEvent = { appId: automation.appId, automationId: automation._id as string, - triggerId: automation.definition?.trigger?.id!, + triggerId: automation.definition?.trigger?.id, triggerType: automation.definition?.trigger?.stepId, } await publishEvent(Event.AUTOMATION_TESTED, properties) @@ -70,7 +70,7 @@ export async function stepCreated( const properties: AutomationStepCreatedEvent = { appId: automation.appId, automationId: automation._id as string, - triggerId: automation.definition?.trigger?.id!, + triggerId: automation.definition?.trigger?.id, triggerType: automation.definition?.trigger?.stepId, stepId: step.id!, stepType: step.stepId, @@ -85,7 +85,7 @@ export async function stepDeleted( const properties: AutomationStepDeletedEvent = { appId: automation.appId, automationId: automation._id as string, - triggerId: automation.definition?.trigger?.id!, + triggerId: automation.definition?.trigger?.id, triggerType: automation.definition?.trigger?.stepId, stepId: step.id!, stepType: step.stepId, diff --git a/packages/server/src/api/controllers/integration.js b/packages/server/src/api/controllers/integration.js deleted file mode 100644 index 2f11ec19ed..0000000000 --- a/packages/server/src/api/controllers/integration.js +++ /dev/null @@ -1,14 +0,0 @@ -const { getDefinitions } = require("../../integrations") - -exports.fetch = async function (ctx) { - ctx.status = 200 - const defs = await getDefinitions() - - ctx.body = defs -} - -exports.find = async function (ctx) { - const defs = await getDefinitions() - ctx.status = 200 - ctx.body = defs[ctx.params.type] -} diff --git a/packages/server/src/api/controllers/integration.ts b/packages/server/src/api/controllers/integration.ts new file mode 100644 index 0000000000..743d216da7 --- /dev/null +++ b/packages/server/src/api/controllers/integration.ts @@ -0,0 +1,13 @@ +import { getDefinitions } from "../../integrations" +import { BBContext } from "@budibase/types" + +export async function fetch(ctx: BBContext) { + ctx.status = 200 + ctx.body = await getDefinitions() +} + +export async function find(ctx: BBContext) { + const defs = await getDefinitions() + ctx.status = 200 + ctx.body = defs[ctx.params.type] +} diff --git a/packages/server/src/api/controllers/migrations.js b/packages/server/src/api/controllers/migrations.js deleted file mode 100644 index 6a890349c3..0000000000 --- a/packages/server/src/api/controllers/migrations.js +++ /dev/null @@ -1,13 +0,0 @@ -const { migrate, MIGRATIONS } = require("../../migrations") - -exports.migrate = async ctx => { - const options = ctx.request.body - // don't await as can take a while, just return - migrate(options) - ctx.status = 200 -} - -exports.fetchDefinitions = async ctx => { - ctx.body = MIGRATIONS - ctx.status = 200 -} diff --git a/packages/server/src/api/controllers/migrations.ts b/packages/server/src/api/controllers/migrations.ts new file mode 100644 index 0000000000..8f1bfa22db --- /dev/null +++ b/packages/server/src/api/controllers/migrations.ts @@ -0,0 +1,14 @@ +import { migrate as migrationImpl, MIGRATIONS } from "../../migrations" +import { BBContext } from "@budibase/types" + +export async function migrate(ctx: BBContext) { + const options = ctx.request.body + // don't await as can take a while, just return + migrationImpl(options) + ctx.status = 200 +} + +export async function fetchDefinitions(ctx: BBContext) { + ctx.body = MIGRATIONS + ctx.status = 200 +} diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 2ef7953437..bd012d61b5 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -209,12 +209,16 @@ module External { } class ExternalRequest { - private operation: Operation + private operation: DataSourceOperation private tableId: string private datasource: Datasource private tables: { [key: string]: Table } = {} - constructor(operation: Operation, tableId: string, datasource: Datasource) { + constructor( + operation: DataSourceOperation, + tableId: string, + datasource: Datasource + ) { this.operation = operation this.tableId = tableId this.datasource = datasource diff --git a/packages/server/src/api/controllers/row/staticFormula.ts b/packages/server/src/api/controllers/row/staticFormula.ts index ee09264af1..7d97d7e466 100644 --- a/packages/server/src/api/controllers/row/staticFormula.ts +++ b/packages/server/src/api/controllers/row/staticFormula.ts @@ -122,9 +122,9 @@ export async function finaliseRow( const db = context.getAppDB() row.type = "row" // process the row before return, to include relationships - let enrichedRow = await outputProcessing(table, cloneDeep(row), { + let enrichedRow = (await outputProcessing(table, cloneDeep(row), { squash: false, - }) + })) as Row // use enriched row to generate formulas for saving, specifically only use as context row = processFormulas(table, row, { dynamic: false, diff --git a/packages/server/src/api/controllers/table/external.ts b/packages/server/src/api/controllers/table/external.ts index 8fd227e633..b79ab45660 100644 --- a/packages/server/src/api/controllers/table/external.ts +++ b/packages/server/src/api/controllers/table/external.ts @@ -14,7 +14,7 @@ import { RelationshipTypes, } from "../../../constants" import { makeExternalQuery } from "../../../integrations/base/query" -import csvParser from "../../../utilities/csvParser" +import * as csvParser from "../../../utilities/csvParser" import { handleRequest } from "../row/external" import { events, context } from "@budibase/backend-core" import { diff --git a/packages/server/src/api/controllers/table/index.ts b/packages/server/src/api/controllers/table/index.ts index 5d8ab5be3e..0df974adc4 100644 --- a/packages/server/src/api/controllers/table/index.ts +++ b/packages/server/src/api/controllers/table/index.ts @@ -1,6 +1,6 @@ import * as internal from "./internal" import * as external from "./external" -import csvParser from "../../../utilities/csvParser" +import * as csvParser from "../../../utilities/csvParser" import { isExternalTable, isSQL } from "../../../integrations/utils" import { getDatasourceParams } from "../../../db/utils" import { context, events } from "@budibase/backend-core" @@ -103,7 +103,10 @@ export async function validateCSVSchema(ctx: BBContext) { if (tableId) { existingTable = await sdk.tables.getTable(tableId) } - let result = await csvParser.parse(csvString, schema) + let result: Record | undefined = await csvParser.parse( + csvString, + schema + ) if (existingTable) { result = csvParser.updateSchema({ schema: result, existingTable }) } diff --git a/packages/server/src/api/controllers/webhook.ts b/packages/server/src/api/controllers/webhook.ts index 26bf16bd4c..f877110646 100644 --- a/packages/server/src/api/controllers/webhook.ts +++ b/packages/server/src/api/controllers/webhook.ts @@ -1,5 +1,5 @@ import { getWebhookParams } from "../../db/utils" -import triggers from "../../automations/triggers" +import * as triggers from "../../automations/triggers" import { db as dbCore, context } from "@budibase/backend-core" import { Webhook, diff --git a/packages/server/src/api/index.ts b/packages/server/src/api/index.ts index a77fc62b9b..3375161dd8 100644 --- a/packages/server/src/api/index.ts +++ b/packages/server/src/api/index.ts @@ -37,7 +37,7 @@ router // re-direct before any middlewares occur .redirect("/", "/builder") .use( - auth.buildAuthMiddleware(null, { + auth.buildAuthMiddleware([], { publicAllowed: true, }) ) @@ -45,7 +45,7 @@ router // the server can be public anywhere, so nowhere should throw errors // if the tenancy has not been set, it'll have to be discovered at application layer .use( - auth.buildTenancyMiddleware(null, null, { + auth.buildTenancyMiddleware([], [], { noTenancyRequired: true, }) ) diff --git a/packages/server/src/api/routes/integration.ts b/packages/server/src/api/routes/integration.ts index 835cc5a896..b21915a6d1 100644 --- a/packages/server/src/api/routes/integration.ts +++ b/packages/server/src/api/routes/integration.ts @@ -1,5 +1,5 @@ import Router from "@koa/router" -import controller from "../controllers/integration" +import * as controller from "../controllers/integration" import authorized from "../../middleware/authorized" import { permissions } from "@budibase/backend-core" diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index 8a9c1d5b24..9010bf87f3 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -10,7 +10,7 @@ if (process.env.ELASTIC_APM_ENABLED) { } import { ExtendableContext } from "koa" -import db from "./db" +import * as db from "./db" db.init() const Koa = require("koa") const destroyable = require("server-destroy") diff --git a/packages/server/src/automations/actions.ts b/packages/server/src/automations/actions.ts index 7c1ef719f7..456399bc68 100644 --- a/packages/server/src/automations/actions.ts +++ b/packages/server/src/automations/actions.ts @@ -15,7 +15,7 @@ import * as delay from "./steps/delay" import * as queryRow from "./steps/queryRows" import * as loop from "./steps/loop" import env from "../environment" -import { AutomationStep, AutomationStepInput } from "@budibase/types" +import { AutomationStepSchema, AutomationStepInput } from "@budibase/types" const ACTION_IMPLS: Record< string, @@ -38,7 +38,7 @@ const ACTION_IMPLS: Record< zapier: zapier.run, integromat: integromat.run, } -export const ACTION_DEFINITIONS: Record = { +export const ACTION_DEFINITIONS: Record = { SEND_EMAIL_SMTP: sendSmtpEmail.definition, CREATE_ROW: createRow.definition, UPDATE_ROW: updateRow.definition, diff --git a/packages/server/src/automations/steps/bash.ts b/packages/server/src/automations/steps/bash.ts index 5bdf482e70..e6deb8c38f 100644 --- a/packages/server/src/automations/steps/bash.ts +++ b/packages/server/src/automations/steps/bash.ts @@ -1,14 +1,14 @@ import { execSync } from "child_process" import { processStringSync } from "@budibase/string-templates" -import automationUtils from "../automationUtils" +import * as automationUtils from "../automationUtils" import environment from "../../environment" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Bash Scripting", tagline: "Execute a bash command", icon: "JourneyEvent", diff --git a/packages/server/src/automations/steps/createRow.ts b/packages/server/src/automations/steps/createRow.ts index a8a139e11c..d529127360 100644 --- a/packages/server/src/automations/steps/createRow.ts +++ b/packages/server/src/automations/steps/createRow.ts @@ -3,11 +3,11 @@ import { cleanUpRow, getError } from "../automationUtils" import { buildCtx } from "./utils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Create Row", tagline: "Create a {{inputs.enriched.table.name}} row", icon: "TableRowAddBottom", diff --git a/packages/server/src/automations/steps/delay.ts b/packages/server/src/automations/steps/delay.ts index 17a07d5699..58ca383ac1 100644 --- a/packages/server/src/automations/steps/delay.ts +++ b/packages/server/src/automations/steps/delay.ts @@ -1,11 +1,11 @@ import { wait } from "../../utilities" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Delay", icon: "Clock", tagline: "Delay for {{inputs.time}} milliseconds", diff --git a/packages/server/src/automations/steps/deleteRow.ts b/packages/server/src/automations/steps/deleteRow.ts index 92978987b2..540d95b94d 100644 --- a/packages/server/src/automations/steps/deleteRow.ts +++ b/packages/server/src/automations/steps/deleteRow.ts @@ -3,11 +3,11 @@ import { buildCtx } from "./utils" import { getError } from "../automationUtils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { description: "Delete a row from your database", icon: "TableRowRemoveCenter", name: "Delete Row", diff --git a/packages/server/src/automations/steps/discord.ts b/packages/server/src/automations/steps/discord.ts index 75899961a6..ae484fa42e 100644 --- a/packages/server/src/automations/steps/discord.ts +++ b/packages/server/src/automations/steps/discord.ts @@ -2,14 +2,14 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" const DEFAULT_USERNAME = "Budibase Automate" const DEFAULT_AVATAR_URL = "https://i.imgur.com/a1cmTKM.png" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Discord Message", tagline: "Send a message to a Discord server", description: "Send a message to a Discord server", diff --git a/packages/server/src/automations/steps/executeQuery.ts b/packages/server/src/automations/steps/executeQuery.ts index d4408441dd..72fb69b96c 100644 --- a/packages/server/src/automations/steps/executeQuery.ts +++ b/packages/server/src/automations/steps/executeQuery.ts @@ -1,13 +1,13 @@ import * as queryController from "../../api/controllers/query" import { buildCtx } from "./utils" -import automationUtils from "../automationUtils" +import * as automationUtils from "../automationUtils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "External Data Connector", tagline: "Execute Data Connector", icon: "Data", diff --git a/packages/server/src/automations/steps/executeScript.ts b/packages/server/src/automations/steps/executeScript.ts index 05e4c9a196..84bdb0e2d5 100644 --- a/packages/server/src/automations/steps/executeScript.ts +++ b/packages/server/src/automations/steps/executeScript.ts @@ -1,13 +1,13 @@ import * as scriptController from "../../api/controllers/script" import { buildCtx } from "./utils" -import automationUtils from "../automationUtils" +import * as automationUtils from "../automationUtils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "JS Scripting", tagline: "Execute JavaScript Code", icon: "Code", diff --git a/packages/server/src/automations/steps/filter.ts b/packages/server/src/automations/steps/filter.ts index 9eeaefd69d..18914ddca6 100644 --- a/packages/server/src/automations/steps/filter.ts +++ b/packages/server/src/automations/steps/filter.ts @@ -1,6 +1,6 @@ import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" @@ -18,7 +18,7 @@ export const PrettyFilterConditions = { [FilterConditions.LESS_THAN]: "Less than", } -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Condition", tagline: "{{inputs.field}} {{inputs.condition}} {{inputs.value}}", icon: "Branch2", diff --git a/packages/server/src/automations/steps/integromat.ts b/packages/server/src/automations/steps/integromat.ts index 9677d3e06a..dd897b5429 100644 --- a/packages/server/src/automations/steps/integromat.ts +++ b/packages/server/src/automations/steps/integromat.ts @@ -2,11 +2,11 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Integromat Integration", tagline: "Trigger an Integromat scenario", description: diff --git a/packages/server/src/automations/steps/loop.ts b/packages/server/src/automations/steps/loop.ts index 552d6df6e7..72087ae357 100644 --- a/packages/server/src/automations/steps/loop.ts +++ b/packages/server/src/automations/steps/loop.ts @@ -1,6 +1,6 @@ -import { AutomationActionStepId, AutomationStep } from "@budibase/types" +import { AutomationActionStepId, AutomationStepSchema } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Looping", icon: "Reuse", tagline: "Loop the block", diff --git a/packages/server/src/automations/steps/outgoingWebhook.ts b/packages/server/src/automations/steps/outgoingWebhook.ts index 42eb0342b0..ea1ffeb339 100644 --- a/packages/server/src/automations/steps/outgoingWebhook.ts +++ b/packages/server/src/automations/steps/outgoingWebhook.ts @@ -1,9 +1,9 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" -import automationUtils from "../automationUtils" +import * as automationUtils from "../automationUtils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" @@ -21,7 +21,7 @@ const BODY_REQUESTS = [RequestType.POST, RequestType.PUT, RequestType.PATCH] * NOTE: this functionality is deprecated - it no longer should be used. */ -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { deprecated: true, name: "Outgoing webhook", tagline: "Send a {{inputs.requestMethod}} request", diff --git a/packages/server/src/automations/steps/queryRows.ts b/packages/server/src/automations/steps/queryRows.ts index 1c9d1f54e0..6de518e931 100644 --- a/packages/server/src/automations/steps/queryRows.ts +++ b/packages/server/src/automations/steps/queryRows.ts @@ -2,10 +2,10 @@ import * as rowController from "../../api/controllers/row" import * as tableController from "../../api/controllers/table" import { FieldTypes } from "../../constants" import { buildCtx } from "./utils" -import automationUtils from "../automationUtils" +import * as automationUtils from "../automationUtils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, SearchFilters, Table, @@ -31,7 +31,7 @@ const EmptyFilterOptionPretty = { [EmptyFilterOption.RETURN_NONE]: "Return no rows", } -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { description: "Query rows from the database", icon: "Search", name: "Query rows", diff --git a/packages/server/src/automations/steps/sendSmtpEmail.ts b/packages/server/src/automations/steps/sendSmtpEmail.ts index a2680a05cb..67516c803d 100644 --- a/packages/server/src/automations/steps/sendSmtpEmail.ts +++ b/packages/server/src/automations/steps/sendSmtpEmail.ts @@ -1,12 +1,12 @@ import { sendSmtpEmail } from "../../utilities/workerRequests" -import automationUtils from "../automationUtils" +import * as automationUtils from "../automationUtils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { description: "Send an email using SMTP", tagline: "Send SMTP email to {{inputs.to}}", icon: "Email", diff --git a/packages/server/src/automations/steps/serverLog.ts b/packages/server/src/automations/steps/serverLog.ts index 04eba3e6d4..bb2f49ede8 100644 --- a/packages/server/src/automations/steps/serverLog.ts +++ b/packages/server/src/automations/steps/serverLog.ts @@ -1,6 +1,6 @@ import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" @@ -10,7 +10,7 @@ import { * GET/DELETE requests cannot handle body elements so they will not be sent if configured. */ -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Backend log", tagline: "Console log a value in the backend", icon: "Monitoring", diff --git a/packages/server/src/automations/steps/slack.ts b/packages/server/src/automations/steps/slack.ts index ddd26c98e2..47c66bebf3 100644 --- a/packages/server/src/automations/steps/slack.ts +++ b/packages/server/src/automations/steps/slack.ts @@ -2,11 +2,11 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Slack Message", tagline: "Send a message to Slack", description: "Send a message to Slack", diff --git a/packages/server/src/automations/steps/updateRow.ts b/packages/server/src/automations/steps/updateRow.ts index ed8e8a02ee..953313986e 100644 --- a/packages/server/src/automations/steps/updateRow.ts +++ b/packages/server/src/automations/steps/updateRow.ts @@ -1,13 +1,13 @@ import * as rowController from "../../api/controllers/row" -import automationUtils from "../automationUtils" +import * as automationUtils from "../automationUtils" import { buildCtx } from "./utils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Update Row", tagline: "Update a {{inputs.enriched.table.name}} row", icon: "Refresh", diff --git a/packages/server/src/automations/steps/zapier.ts b/packages/server/src/automations/steps/zapier.ts index 96bc90c4d0..1a48c1ec92 100644 --- a/packages/server/src/automations/steps/zapier.ts +++ b/packages/server/src/automations/steps/zapier.ts @@ -2,11 +2,11 @@ import fetch from "node-fetch" import { getFetchResponse } from "./utils" import { AutomationActionStepId, - AutomationStep, + AutomationStepSchema, AutomationStepInput, } from "@budibase/types" -export const definition: AutomationStep = { +export const definition: AutomationStepSchema = { name: "Zapier Webhook", stepId: AutomationActionStepId.zapier, type: "ACTION", diff --git a/packages/server/src/automations/triggerInfo/app.ts b/packages/server/src/automations/triggerInfo/app.ts index fe1413e88e..fca9acaef8 100644 --- a/packages/server/src/automations/triggerInfo/app.ts +++ b/packages/server/src/automations/triggerInfo/app.ts @@ -1,6 +1,9 @@ -import { AutomationTrigger, AutomationTriggerStepId } from "@budibase/types" +import { + AutomationTriggerSchema, + AutomationTriggerStepId, +} from "@budibase/types" -export const definition: AutomationTrigger = { +export const definition: AutomationTriggerSchema = { name: "App Action", event: "app:trigger", icon: "Apps", diff --git a/packages/server/src/automations/triggerInfo/cron.ts b/packages/server/src/automations/triggerInfo/cron.ts index fc40d33683..91b41f7243 100644 --- a/packages/server/src/automations/triggerInfo/cron.ts +++ b/packages/server/src/automations/triggerInfo/cron.ts @@ -1,6 +1,9 @@ -import { AutomationTrigger, AutomationTriggerStepId } from "@budibase/types" +import { + AutomationTriggerSchema, + AutomationTriggerStepId, +} from "@budibase/types" -export const definition: AutomationTrigger = { +export const definition: AutomationTriggerSchema = { name: "Cron Trigger", event: "cron:trigger", icon: "Clock", diff --git a/packages/server/src/automations/triggerInfo/index.ts b/packages/server/src/automations/triggerInfo/index.ts index 50089c98e9..b35d915ea8 100644 --- a/packages/server/src/automations/triggerInfo/index.ts +++ b/packages/server/src/automations/triggerInfo/index.ts @@ -1,9 +1,9 @@ -import app from "./app" -import cron from "./cron" -import rowDeleted from "./rowDeleted" -import rowSaved from "./rowSaved" -import rowUpdated from "./rowUpdated" -import webhook from "./webhook" +import * as app from "./app" +import * as cron from "./cron" +import * as rowDeleted from "./rowDeleted" +import * as rowSaved from "./rowSaved" +import * as rowUpdated from "./rowUpdated" +import * as webhook from "./webhook" export const definitions = { ROW_SAVED: rowSaved.definition, diff --git a/packages/server/src/automations/triggerInfo/rowDeleted.ts b/packages/server/src/automations/triggerInfo/rowDeleted.ts index ab238800ea..de4a1b0412 100644 --- a/packages/server/src/automations/triggerInfo/rowDeleted.ts +++ b/packages/server/src/automations/triggerInfo/rowDeleted.ts @@ -1,6 +1,9 @@ -import { AutomationTrigger, AutomationTriggerStepId } from "@budibase/types" +import { + AutomationTriggerSchema, + AutomationTriggerStepId, +} from "@budibase/types" -export const definition: AutomationTrigger = { +export const definition: AutomationTriggerSchema = { name: "Row Deleted", event: "row:delete", icon: "TableRowRemoveCenter", diff --git a/packages/server/src/automations/triggerInfo/rowSaved.ts b/packages/server/src/automations/triggerInfo/rowSaved.ts index 55cf60c594..c1dde25eef 100644 --- a/packages/server/src/automations/triggerInfo/rowSaved.ts +++ b/packages/server/src/automations/triggerInfo/rowSaved.ts @@ -1,6 +1,9 @@ -import { AutomationTrigger, AutomationTriggerStepId } from "@budibase/types" +import { + AutomationTriggerSchema, + AutomationTriggerStepId, +} from "@budibase/types" -export const definition: AutomationTrigger = { +export const definition: AutomationTriggerSchema = { name: "Row Created", event: "row:save", icon: "TableRowAddBottom", diff --git a/packages/server/src/automations/triggerInfo/rowUpdated.ts b/packages/server/src/automations/triggerInfo/rowUpdated.ts index 6cc6d303c9..1bc8811d54 100644 --- a/packages/server/src/automations/triggerInfo/rowUpdated.ts +++ b/packages/server/src/automations/triggerInfo/rowUpdated.ts @@ -1,6 +1,9 @@ -import { AutomationTrigger, AutomationTriggerStepId } from "@budibase/types" +import { + AutomationTriggerSchema, + AutomationTriggerStepId, +} from "@budibase/types" -export const definition: AutomationTrigger = { +export const definition: AutomationTriggerSchema = { name: "Row Updated", event: "row:update", icon: "Refresh", diff --git a/packages/server/src/automations/triggerInfo/webhook.ts b/packages/server/src/automations/triggerInfo/webhook.ts index 762b871193..906967a02a 100644 --- a/packages/server/src/automations/triggerInfo/webhook.ts +++ b/packages/server/src/automations/triggerInfo/webhook.ts @@ -1,6 +1,9 @@ -import { AutomationTrigger, AutomationTriggerStepId } from "@budibase/types" +import { + AutomationTriggerSchema, + AutomationTriggerStepId, +} from "@budibase/types" -export const definition: AutomationTrigger = { +export const definition: AutomationTriggerSchema = { name: "Webhook", event: "web:trigger", icon: "Send", diff --git a/packages/server/src/db/linkedRows/LinkController.ts b/packages/server/src/db/linkedRows/LinkController.ts index fc28137f58..690abc1feb 100644 --- a/packages/server/src/db/linkedRows/LinkController.ts +++ b/packages/server/src/db/linkedRows/LinkController.ts @@ -13,7 +13,7 @@ import { } from "@budibase/types" type LinkControllerOpts = { - tableId: string + tableId?: string row?: Row table?: Table oldTable?: Table @@ -21,7 +21,7 @@ type LinkControllerOpts = { class LinkController { _db: Database - _tableId: string + _tableId?: string _row?: Row _table?: Table _oldTable?: Table diff --git a/packages/server/src/db/linkedRows/index.ts b/packages/server/src/db/linkedRows/index.ts index 1559e644af..a6ed7de161 100644 --- a/packages/server/src/db/linkedRows/index.ts +++ b/packages/server/src/db/linkedRows/index.ts @@ -100,7 +100,7 @@ async function getFullLinkedDocs(links: LinkDocumentValue[]) { * row operations and the table for table operations. */ export async function updateLinks(args: { - tableId: string + tableId?: string eventType: string row?: Row table?: Table diff --git a/packages/server/src/events/BudibaseEmitter.ts b/packages/server/src/events/BudibaseEmitter.ts index b31fa36df7..8eb7bffd96 100644 --- a/packages/server/src/events/BudibaseEmitter.ts +++ b/packages/server/src/events/BudibaseEmitter.ts @@ -21,7 +21,7 @@ class BudibaseEmitter extends EventEmitter { tableEmission({ emitter: this, eventName, appId, table }) } - emitPort(portNumber: number) { + emitPort(portNumber?: number | string) { this.emit("internal:port", portNumber) } } diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index 3e17df4076..84c2deaa57 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -266,6 +266,7 @@ class GoogleSheetsIntegration implements DatasourcePlus { this.deleteTable(json?.table?.name), } + // @ts-ignore const internalQueryMethod = handlers[json.endpoint.operation] return await internalQueryMethod() diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index 287783eec6..1861cc9662 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -230,7 +230,7 @@ function shouldCopySpecialColumn( const fetchedIsNumber = !fetchedColumn || fetchedColumn.type === FieldTypes.NUMBER return ( - specialTypes.indexOf(column.type) !== -1 || + specialTypes.indexOf(column.type as FieldTypes) !== -1 || (fetchedIsNumber && column.type === FieldTypes.BOOLEAN) ) } @@ -292,7 +292,11 @@ export function finaliseExternalTables( if (table.primary == null || table.primary.length === 0) { errors[name] = BuildSchemaErrors.NO_KEY continue - } else if (schemaFields.find(field => invalidColumns.includes(field))) { + } else if ( + schemaFields.find(field => + invalidColumns.includes(field as InvalidColumns) + ) + ) { errors[name] = BuildSchemaErrors.INVALID_COLUMN continue } diff --git a/packages/server/src/startup.ts b/packages/server/src/startup.ts index 53fcf3ebef..50c1122cef 100644 --- a/packages/server/src/startup.ts +++ b/packages/server/src/startup.ts @@ -13,11 +13,11 @@ import { } from "@budibase/backend-core" import fs from "fs" import { watch } from "./watch" -import automations from "./automations" -import fileSystem from "./utilities/fileSystem" +import * as automations from "./automations" +import * as fileSystem from "./utilities/fileSystem" import eventEmitter from "./events" import * as migrations from "./migrations" -import bullboard from "./automations/bullboard" +import * as bullboard from "./automations/bullboard" import * as pro from "@budibase/pro" import * as api from "./api" import sdk from "./sdk" diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 5e2817ed06..8b343cdf8e 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -6,8 +6,8 @@ import { disableCronById, isErrorInOutput, } from "../automations/utils" -import { default as actions } from "../automations/actions" -import { default as automationUtils } from "../automations/automationUtils" +import * as actions from "../automations/actions" +import * as automationUtils from "../automations/automationUtils" import { default as AutomationEmitter } from "../events/AutomationEmitter" import { generateAutomationMetadataID, isProdAppID } from "../db/utils" import { definitions as triggerDefs } from "../automations/triggerInfo" @@ -335,7 +335,7 @@ class Orchestrator { )) { originalStepInput[key][innerKey][innerObject] = automationUtils.substituteLoopStep( - innerValue, + innerValue as string, `steps.${loopStepNumber}` ) } diff --git a/packages/server/src/threads/utils.ts b/packages/server/src/threads/utils.ts index 53120160a8..5caaeb83d7 100644 --- a/packages/server/src/threads/utils.ts +++ b/packages/server/src/threads/utils.ts @@ -1,6 +1,6 @@ import { QueryVariable } from "./definitions" import env from "../environment" -import db from "../db" +import * as db from "../db" import { redis, db as dbCore } from "@budibase/backend-core" const VARIABLE_TTL_SECONDS = 3600 diff --git a/packages/server/src/utilities/csvParser.ts b/packages/server/src/utilities/csvParser.ts index 85e4b1e8e5..0c138abc3e 100644 --- a/packages/server/src/utilities/csvParser.ts +++ b/packages/server/src/utilities/csvParser.ts @@ -8,7 +8,7 @@ type CsvParseOpts = { csvString?: string } -const VALIDATORS = { +const VALIDATORS: any = { [FieldTypes.STRING]: () => true, [FieldTypes.OPTIONS]: () => true, [FieldTypes.BARCODEQR]: () => true, @@ -28,7 +28,7 @@ const VALIDATORS = { }, } -const PARSERS = { +const PARSERS: any = { [FieldTypes.NUMBER]: (attribute?: string) => { if (!attribute) { return attribute @@ -43,7 +43,7 @@ const PARSERS = { }, } -export function parse(csvString: string, parsers: any) { +export function parse(csvString: string, parsers: any): Record { const result = csv().fromString(csvString) const schema: Record = {} @@ -89,7 +89,7 @@ export function updateSchema({ existingTable, }: { schema?: Record - existingTable: Table + existingTable?: Table }) { if (!schema) { return schema @@ -97,7 +97,7 @@ export function updateSchema({ const finalSchema: Record = {} const schemaKeyMap: Record = {} Object.keys(schema).forEach(key => (schemaKeyMap[key.toLowerCase()] = key)) - for (let [key, field] of Object.entries(existingTable.schema)) { + for (let [key, field] of Object.entries(existingTable?.schema || {})) { const lcKey = key.toLowerCase() const foundKey: string = schemaKeyMap[lcKey] if (foundKey) { diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index 9807fc7d61..d1aa93b4fe 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -1,4 +1,4 @@ -import linkRows from "../../db/linkedRows" +import * as linkRows from "../../db/linkedRows" import { FieldTypes, AutoFieldSubTypes } from "../../constants" import { attachmentsRelativeURL } from "../index" import { processFormulas, fixAutoColumnSubType } from "./utils" @@ -189,10 +189,10 @@ export async function outputProcessing( wasArray = false } // attach any linked row information - let enriched = await linkRows.attachFullLinkedDocs(table, rows) + let enriched = await linkRows.attachFullLinkedDocs(table, rows as Row[]) // process formulas - enriched = processFormulas(table, enriched, { dynamic: true }) + enriched = processFormulas(table, enriched, { dynamic: true }) as Row[] // update the attachments URL depending on hosting for (let [property, column] of Object.entries(table.schema)) { diff --git a/packages/server/src/utilities/rowProcessor/map.ts b/packages/server/src/utilities/rowProcessor/map.ts index 5b57d2d33f..8911d62133 100644 --- a/packages/server/src/utilities/rowProcessor/map.ts +++ b/packages/server/src/utilities/rowProcessor/map.ts @@ -4,7 +4,7 @@ import { FieldTypes } from "../../constants" /** * A map of how we convert various properties in rows to each other based on the row type. */ -exports.TYPE_TRANSFORM_MAP = { +export const TYPE_TRANSFORM_MAP: any = { [FieldTypes.LINK]: { "": [], [null]: [], diff --git a/packages/types/src/documents/app/automation.ts b/packages/types/src/documents/app/automation.ts index ba718aa8d5..f267aa339f 100644 --- a/packages/types/src/documents/app/automation.ts +++ b/packages/types/src/documents/app/automation.ts @@ -41,8 +41,7 @@ export interface Automation extends Document { name: string } -export interface AutomationStep { - id?: string +export interface AutomationStepSchema { name: string tagline: string icon: string @@ -65,11 +64,19 @@ export interface AutomationStep { } } -export interface AutomationTrigger extends AutomationStep { +export interface AutomationStep extends AutomationStepSchema { + id: string +} + +export interface AutomationTriggerSchema extends AutomationStepSchema { event?: string cronJobId?: string } +export interface AutomationTrigger extends AutomationTriggerSchema { + id: string +} + export enum AutomationStatus { SUCCESS = "success", ERROR = "error",