Merge branch 'master' into execute-script-v2

This commit is contained in:
deanhannigan 2025-02-25 15:03:06 +00:00 committed by GitHub
commit f55d8c5ed9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 150 additions and 160 deletions

View File

@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "3.4.16",
"version": "3.4.17",
"npmClient": "yarn",
"concurrency": 20,
"command": {

View File

@ -3553,6 +3553,31 @@ if (descriptions.length) {
limit: 1,
}).toContainExactly([row])
})
isInternal &&
describe("search by _id for relations", () => {
it("can filter by the related _id", async () => {
await expectSearch({
query: {
equal: { "rel._id": row.rel[0]._id },
},
}).toContainExactly([row])
await expectSearch({
query: {
equal: { "rel._id": row.rel[1]._id },
},
}).toContainExactly([row])
})
it("can filter by the related _id and find nothing", async () => {
await expectSearch({
query: {
equal: { "rel._id": "rel_none" },
},
}).toFindNothing()
})
})
})
!isInternal &&

View File

@ -1,5 +1,5 @@
import * as automation from "../index"
import { Table, AutomationStatus } from "@budibase/types"
import { Table, AutomationStatus, EmptyFilterOption } from "@budibase/types"
import { createAutomationBuilder } from "./utilities/AutomationTestBuilder"
import TestConfiguration from "../../tests/utilities/TestConfiguration"
@ -280,4 +280,23 @@ describe("Branching automations", () => {
expect(results.steps[2].outputs.message).toContain("Special user")
})
it("should not fail with empty conditions", async () => {
const results = await createAutomationBuilder(config)
.onAppAction()
.branch({
specialBranch: {
steps: stepBuilder => stepBuilder.serverLog({ text: "Hello!" }),
condition: {
onEmptyFilter: EmptyFilterOption.RETURN_NONE,
},
},
})
.test({ fields: { test_trigger: true } })
expect(results.steps[0].outputs.success).toEqual(false)
expect(results.steps[0].outputs.status).toEqual(
AutomationStatus.NO_CONDITION_MET
)
})
})

View File

@ -1,3 +1,4 @@
import { SendEmailResponse } from "@budibase/types"
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
import * as workerRequests from "../../../utilities/workerRequests"
@ -5,17 +6,18 @@ jest.mock("../../../utilities/workerRequests", () => ({
sendSmtpEmail: jest.fn(),
}))
function generateResponse(to: string, from: string) {
function generateResponse(to: string, from: string): SendEmailResponse {
return {
success: true,
response: {
message: `Email sent to ${to}.`,
accepted: [to],
envelope: {
from: from,
to: [to],
},
message: `Email sent to ${to}.`,
},
messageId: "messageId",
pending: [],
rejected: [],
response: "response",
}
}

View File

@ -7,6 +7,7 @@ import {
} from "@budibase/types"
import { cloneDeep } from "lodash/fp"
import sdk from "../../../sdk"
import { isInternal } from "../tables/utils"
export const removeInvalidFilters = (
filters: SearchFilters,
@ -70,6 +71,10 @@ export const getQueryableFields = async (
opts?: { noRelationships?: boolean }
): Promise<string[]> => {
const result = []
if (isInternal({ table })) {
result.push("_id")
}
for (const field of Object.keys(table.schema).filter(
f => allowedFields.includes(f) && table.schema[f].visible !== false
)) {
@ -113,14 +118,13 @@ export const getQueryableFields = async (
return result
}
const result = [
"_id", // Querying by _id is always allowed, even if it's never part of the schema
]
// Querying by _id is always allowed, even if it's never part of the schema
const result = ["_id"]
if (fields == null) {
fields = Object.keys(table.schema)
}
result.push(...(await extractTableFields(table, fields, [table._id!])))
return result
return Array.from(new Set(result))
}

View File

@ -250,6 +250,8 @@ describe("query utils", () => {
expect(result).toEqual([
"_id",
"name",
"aux._id",
"auxTable._id",
"aux.title",
"auxTable.title",
"aux.name",
@ -284,7 +286,14 @@ describe("query utils", () => {
const result = await config.doInContext(config.appId, () => {
return getQueryableFields(table)
})
expect(result).toEqual(["_id", "name", "aux.name", "auxTable.name"])
expect(result).toEqual([
"_id",
"name",
"aux._id",
"auxTable._id",
"aux.name",
"auxTable.name",
])
})
it("excludes all relationship fields if hidden", async () => {
@ -387,10 +396,14 @@ describe("query utils", () => {
"_id",
"name",
// aux1 primitive props
"aux1._id",
"aux1Table._id",
"aux1.name",
"aux1Table.name",
// aux2 primitive props
"aux2._id",
"aux2Table._id",
"aux2.title",
"aux2Table.title",
])
@ -405,14 +418,18 @@ describe("query utils", () => {
"name",
// aux2_1 primitive props
"aux2_1._id",
"aux2Table._id",
"aux2_1.title",
"aux2Table.title",
// aux2_2 primitive props
"aux2_2._id",
"aux2_2.title",
"aux2Table.title",
// table primitive props
"table._id",
"TestTable._id",
"table.name",
"TestTable.name",
])
@ -427,14 +444,18 @@ describe("query utils", () => {
"title",
// aux1_1 primitive props
"aux1_1._id",
"aux1Table._id",
"aux1_1.name",
"aux1Table.name",
// aux1_2 primitive props
"aux1_2._id",
"aux1_2.name",
"aux1Table.name",
// table primitive props
"table._id",
"TestTable._id",
"table.name",
"TestTable.name",
])
@ -481,6 +502,8 @@ describe("query utils", () => {
"name",
// deep 1 aux primitive props
"aux._id",
"auxTable._id",
"aux.title",
"auxTable.title",
])
@ -495,6 +518,8 @@ describe("query utils", () => {
"title",
// deep 1 dependency primitive props
"table._id",
"TestTable._id",
"table.name",
"TestTable.name",
])

View File

@ -1,108 +0,0 @@
import {
FieldType,
INTERNAL_TABLE_SOURCE_ID,
Table,
TableSourceType,
ViewV2,
} from "@budibase/types"
import { generator } from "@budibase/backend-core/tests"
import sdk from "../../.."
jest.mock("../../views", () => ({
...jest.requireActual("../../views"),
enrichSchema: jest.fn().mockImplementation(v => ({ ...v, mocked: true })),
}))
describe("table sdk", () => {
describe("enrichViewSchemas", () => {
const basicTable: Table = {
_id: generator.guid(),
name: "TestTable",
type: "table",
sourceId: INTERNAL_TABLE_SOURCE_ID,
sourceType: TableSourceType.INTERNAL,
schema: {
name: {
type: FieldType.STRING,
name: "name",
visible: true,
width: 80,
order: 2,
constraints: {
type: "string",
},
},
description: {
type: FieldType.STRING,
name: "description",
visible: true,
width: 200,
constraints: {
type: "string",
},
},
id: {
type: FieldType.NUMBER,
name: "id",
visible: true,
order: 1,
constraints: {
type: "number",
},
},
hiddenField: {
type: FieldType.STRING,
name: "hiddenField",
visible: false,
constraints: {
type: "string",
},
},
},
}
it("should fetch the default schema if not overriden", async () => {
const tableId = basicTable._id!
function getTable() {
const view: ViewV2 = {
version: 2,
id: generator.guid(),
name: generator.guid(),
tableId,
}
return view
}
const view1 = getTable()
const view2 = getTable()
const view3 = getTable()
const res = await sdk.tables.enrichViewSchemas({
...basicTable,
views: {
[view1.name]: view1,
[view2.name]: view2,
[view3.name]: view3,
},
})
expect(sdk.views.enrichSchema).toHaveBeenCalledTimes(3)
expect(res).toEqual({
...basicTable,
views: {
[view1.name]: {
...view1,
mocked: true,
},
[view2.name]: {
...view2,
mocked: true,
},
[view3.name]: {
...view3,
mocked: true,
},
},
})
})
})
})

View File

@ -367,6 +367,8 @@ class Orchestrator {
if (e.errno === "ETIME") {
span?.addTags({ timedOut: true })
console.warn(`Automation execution timed out after ${timeout}ms`)
} else {
throw e
}
}

View File

@ -8,7 +8,15 @@ import {
logging,
env as coreEnv,
} from "@budibase/backend-core"
import { Ctx, User, EmailInvite, EmailAttachment } from "@budibase/types"
import {
Ctx,
User,
EmailInvite,
EmailAttachment,
SendEmailResponse,
SendEmailRequest,
EmailTemplatePurpose,
} from "@budibase/types"
interface Request {
ctx?: Ctx
@ -110,25 +118,23 @@ export async function sendSmtpEmail({
invite?: EmailInvite
}) {
// tenant ID will be set in header
const response = await fetch(
checkSlashesInUrl(env.WORKER_URL + `/api/global/email/send`),
createRequest({
method: "POST",
body: {
const request: SendEmailRequest = {
email: to,
from,
contents,
subject,
cc,
bcc,
purpose: "custom",
purpose: EmailTemplatePurpose.CUSTOM,
automation,
invite,
attachments,
},
})
}
const response = await fetch(
checkSlashesInUrl(env.WORKER_URL + `/api/global/email/send`),
createRequest({ method: "POST", body: request })
)
return checkResponse(response, "send email")
return (await checkResponse(response, "send email")) as SendEmailResponse
}
export async function removeAppFromUserRoles(ctx: Ctx, appId: string) {

View File

@ -17,6 +17,7 @@
"@budibase/nano": "10.1.5",
"@types/json-schema": "^7.0.15",
"@types/koa": "2.13.4",
"@types/nodemailer": "^6.4.17",
"@types/redlock": "4.0.7",
"koa-useragent": "^4.1.0",
"rimraf": "3.0.2",

View File

@ -1,4 +1,5 @@
import { EmailAttachment, EmailInvite } from "../../../documents"
import SMTPTransport from "nodemailer/lib/smtp-transport"
export enum EmailTemplatePurpose {
CORE = "core",
@ -12,17 +13,17 @@ export enum EmailTemplatePurpose {
export interface SendEmailRequest {
workspaceId?: string
email: string
userId: string
userId?: string
purpose: EmailTemplatePurpose
contents?: string
from?: string
subject: string
cc?: boolean
bcc?: boolean
cc?: string
bcc?: string
automation?: boolean
invite?: EmailInvite
attachments?: EmailAttachment[]
}
export interface SendEmailResponse extends Record<string, any> {
export interface SendEmailResponse extends SMTPTransport.SentMessageInfo {
message: string
}

View File

@ -1,10 +1,10 @@
import { Document } from "../../document"
import { User } from "../../global"
import { ReadStream } from "fs"
import { Row } from "../row"
import { Table } from "../table"
import { AutomationStep, AutomationTrigger } from "./schema"
import { ContextEmitter } from "../../../sdk"
import { Readable } from "stream"
export enum AutomationIOType {
OBJECT = "object",
@ -109,8 +109,8 @@ export interface SendEmailOpts {
subject: string
// info Pass in a structure of information to be stored alongside the invitation.
info?: any
cc?: boolean
bcc?: boolean
cc?: string
bcc?: string
automation?: boolean
invite?: EmailInvite
attachments?: EmailAttachment[]
@ -270,7 +270,7 @@ export type AutomationAttachment = {
export type AutomationAttachmentContent = {
filename: string
content: ReadStream | NodeJS.ReadableStream
content: Readable
}
export type BucketedContent = AutomationAttachmentContent & {

View File

@ -3,6 +3,7 @@ import { Row, DocumentType, Table, Datasource } from "../documents"
import { SortOrder, SortType } from "../api"
import { Knex } from "knex"
import { Aggregation } from "./row"
import _ from "lodash"
export enum BasicOperator {
EQUAL = "equal",
@ -83,7 +84,7 @@ type RangeFilter = Record<
type LogicalFilter = { conditions: SearchFilters[] }
export function isLogicalFilter(filter: any): filter is LogicalFilter {
return "conditions" in filter
return _.isPlainObject(filter) && "conditions" in filter
}
export type AnySearchFilter = BasicFilter | ArrayFilter | RangeFilter

View File

@ -86,6 +86,7 @@
"@types/koa__router": "12.0.4",
"@types/lodash": "4.14.200",
"@types/node-fetch": "2.6.4",
"@types/nodemailer": "^6.4.17",
"@types/server-destroy": "1.0.1",
"@types/supertest": "2.0.14",
"@types/uuid": "8.3.4",

View File

@ -24,10 +24,13 @@ export async function sendEmail(
invite,
attachments,
} = ctx.request.body
let user: any
let user: User | undefined = undefined
if (userId) {
const db = tenancy.getGlobalDB()
user = await db.get<User>(userId)
user = await db.tryGet<User>(userId)
}
if (!user) {
ctx.throw(404, "User not found.")
}
const response = await sendEmailFn(email, purpose, {
workspaceId,

View File

@ -13,7 +13,8 @@ import { configs, cache, objectStore } from "@budibase/backend-core"
import ical from "ical-generator"
import _ from "lodash"
const nodemailer = require("nodemailer")
import nodemailer from "nodemailer"
import SMTPTransport from "nodemailer/lib/smtp-transport"
const TEST_MODE = env.ENABLE_EMAIL_TEST_MODE && env.isDev()
const TYPE = TemplateType.EMAIL
@ -26,7 +27,7 @@ const FULL_EMAIL_PURPOSES = [
]
function createSMTPTransport(config?: SMTPInnerConfig) {
let options: any
let options: SMTPTransport.Options
let secure = config?.secure
// default it if not specified
if (secure == null) {
@ -161,7 +162,7 @@ export async function sendEmail(
const code = await getLinkCode(purpose, email, opts.user, opts?.info)
let context = await getSettingsTemplateContext(purpose, code)
let message: any = {
let message: Parameters<typeof transport.sendMail>[0] = {
from: opts?.from || config?.from,
html: await buildEmail(purpose, email, context, {
user: opts?.user,

View File

@ -2785,9 +2785,9 @@
through2 "^2.0.0"
"@budibase/pro@npm:@budibase/pro@latest":
version "3.4.12"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.4.12.tgz#60e630944de4e2de970a04179d8f0f57d48ce75e"
integrity sha512-msUBmcWxRDg+ugjZvd27XudERQqtQRdiARsO8MaDVTcp5ejIXgshEIVVshHOCj3hcbRblw9pXvBIMI53iTMUsA==
version "3.4.16"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-3.4.16.tgz#c482a400e27b7e89ca73092c4c81bdeac1d24581"
integrity sha512-8ECnqOh9jQ10KlQEwmKPFcoVGE+2gGgSybj+vbshwDp1zAW76doyMR2DMNjEatNpWVnpoMnTkDWtE9aqQ5v0vQ==
dependencies:
"@anthropic-ai/sdk" "^0.27.3"
"@budibase/backend-core" "*"
@ -6775,6 +6775,13 @@
dependencies:
undici-types "~6.19.2"
"@types/nodemailer@^6.4.17":
version "6.4.17"
resolved "https://registry.yarnpkg.com/@types/nodemailer/-/nodemailer-6.4.17.tgz#5c82a42aee16a3dd6ea31446a1bd6a447f1ac1a4"
integrity sha512-I9CCaIp6DTldEg7vyUTZi8+9Vo0hi1/T8gv3C89yk1rSAAzoKQ8H8ki/jBYJSFoH/BisgLP8tkZMlQ91CIquww==
dependencies:
"@types/node" "*"
"@types/normalize-package-data@^2.4.0":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"