Merge master.

This commit is contained in:
Sam Rose 2024-03-20 18:05:17 +00:00
commit da2dfcfad0
No known key found for this signature in database
102 changed files with 234 additions and 355 deletions

View File

@ -36,12 +36,14 @@
"files": ["**/*.ts"], "files": ["**/*.ts"],
"excludedFiles": ["qa-core/**"], "excludedFiles": ["qa-core/**"],
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended"], "extends": ["eslint:recommended"],
"globals": { "globals": {
"NodeJS": true "NodeJS": true
}, },
"rules": { "rules": {
"no-unused-vars": "off", "no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"local-rules/no-budibase-imports": "error" "local-rules/no-budibase-imports": "error"
} }
}, },
@ -49,7 +51,7 @@
"files": ["**/*.spec.ts"], "files": ["**/*.spec.ts"],
"excludedFiles": ["qa-core/**"], "excludedFiles": ["qa-core/**"],
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"plugins": ["jest"], "plugins": ["jest", "@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:jest/recommended"], "extends": ["eslint:recommended", "plugin:jest/recommended"],
"env": { "env": {
"jest/globals": true "jest/globals": true
@ -59,6 +61,7 @@
}, },
"rules": { "rules": {
"no-unused-vars": "off", "no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"local-rules/no-test-com": "error", "local-rules/no-test-com": "error",
"local-rules/email-domain-example-com": "error", "local-rules/email-domain-example-com": "error",
"no-console": "warn", "no-console": "warn",

View File

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

View File

@ -26,6 +26,7 @@
"svelte": "^4.2.10", "svelte": "^4.2.10",
"svelte-eslint-parser": "^0.33.1", "svelte-eslint-parser": "^0.33.1",
"typescript": "5.2.2", "typescript": "5.2.2",
"typescript-eslint": "^7.3.1",
"yargs": "^17.7.2" "yargs": "^17.7.2"
}, },
"scripts": { "scripts": {

View File

@ -129,7 +129,7 @@ export default class BaseCache {
} }
} }
async bustCache(key: string, opts = { client: null }) { async bustCache(key: string) {
const client = await this.getClient() const client = await this.getClient()
try { try {
await client.delete(generateTenantKey(key)) await client.delete(generateTenantKey(key))

View File

@ -1,5 +1,5 @@
import * as utils from "../utils" import * as utils from "../utils"
import { Duration, DurationType } from "../utils" import { Duration } from "../utils"
import env from "../environment" import env from "../environment"
import { getTenantId } from "../context" import { getTenantId } from "../context"
import * as redis from "../redis/init" import * as redis from "../redis/init"

View File

@ -8,7 +8,7 @@ const DEFAULT_WRITE_RATE_MS = 10000
let CACHE: BaseCache | null = null let CACHE: BaseCache | null = null
interface CacheItem<T extends Document> { interface CacheItem<T extends Document> {
doc: any doc: T
lastWrite: number lastWrite: number
} }

View File

@ -10,10 +10,6 @@ interface SearchResponse<T> {
totalRows: number totalRows: number
} }
interface PaginatedSearchResponse<T> extends SearchResponse<T> {
hasNextPage: boolean
}
export type SearchParams<T> = { export type SearchParams<T> = {
tableId?: string tableId?: string
sort?: string sort?: string

View File

@ -17,13 +17,8 @@ export function init(processors: ProcessorMap) {
// if not processing in this instance, kick it off // if not processing in this instance, kick it off
if (!processingPromise) { if (!processingPromise) {
processingPromise = asyncEventQueue.process(async job => { processingPromise = asyncEventQueue.process(async job => {
const { event, identity, properties, timestamp } = job.data const { event, identity, properties } = job.data
await documentProcessor.processEvent( await documentProcessor.processEvent(event, identity, properties)
event,
identity,
properties,
timestamp
)
}) })
} }
} }

View File

@ -1,7 +1,6 @@
import { import {
Event, Event,
Identity, Identity,
Group,
IdentityType, IdentityType,
AuditLogQueueEvent, AuditLogQueueEvent,
AuditLogFn, AuditLogFn,
@ -79,11 +78,11 @@ export default class AuditLogsProcessor implements EventProcessor {
} }
} }
async identify(identity: Identity, timestamp?: string | number) { async identify() {
// no-op // no-op
} }
async identifyGroup(group: Group, timestamp?: string | number) { async identifyGroup() {
// no-op // no-op
} }

View File

@ -8,8 +8,7 @@ export default class LoggingProcessor implements EventProcessor {
async processEvent( async processEvent(
event: Event, event: Event,
identity: Identity, identity: Identity,
properties: any, properties: any
timestamp?: string
): Promise<void> { ): Promise<void> {
if (skipLogging) { if (skipLogging) {
return return
@ -17,14 +16,14 @@ export default class LoggingProcessor implements EventProcessor {
console.log(`[audit] [identityType=${identity.type}] ${event}`, properties) console.log(`[audit] [identityType=${identity.type}] ${event}`, properties)
} }
async identify(identity: Identity, timestamp?: string | number) { async identify(identity: Identity) {
if (skipLogging) { if (skipLogging) {
return return
} }
console.log(`[audit] identified`, identity) console.log(`[audit] identified`, identity)
} }
async identifyGroup(group: Group, timestamp?: string | number) { async identifyGroup(group: Group) {
if (skipLogging) { if (skipLogging) {
return return
} }

View File

@ -14,12 +14,7 @@ export default class DocumentUpdateProcessor implements EventProcessor {
this.processors = processors this.processors = processors
} }
async processEvent( async processEvent(event: Event, identity: Identity, properties: any) {
event: Event,
identity: Identity,
properties: any,
timestamp?: string | number
) {
const tenantId = identity.realTenantId const tenantId = identity.realTenantId
const docId = getDocumentId(event, properties) const docId = getDocumentId(event, properties)
if (!tenantId || !docId) { if (!tenantId || !docId) {

View File

@ -28,7 +28,7 @@ export const buildMatcherRegex = (
} }
export const matches = (ctx: BBContext, options: RegexMatcher[]) => { export const matches = (ctx: BBContext, options: RegexMatcher[]) => {
return options.find(({ regex, method, route }) => { return options.find(({ regex, method }) => {
const urlMatch = regex.test(ctx.request.url) const urlMatch = regex.test(ctx.request.url)
const methodMatch = const methodMatch =
method === "ALL" method === "ALL"

View File

@ -3,7 +3,7 @@ import { Cookie } from "../../../constants"
import * as configs from "../../../configs" import * as configs from "../../../configs"
import * as cache from "../../../cache" import * as cache from "../../../cache"
import * as utils from "../../../utils" import * as utils from "../../../utils"
import { UserCtx, SSOProfile, DatasourceAuthCookie } from "@budibase/types" import { UserCtx, SSOProfile } from "@budibase/types"
import { ssoSaveUserNoOp } from "../sso/sso" import { ssoSaveUserNoOp } from "../sso/sso"
const GoogleStrategy = require("passport-google-oauth").OAuth2Strategy const GoogleStrategy = require("passport-google-oauth").OAuth2Strategy

View File

@ -5,7 +5,6 @@ import * as context from "../../../context"
import fetch from "node-fetch" import fetch from "node-fetch"
import { import {
SaveSSOUserFunction, SaveSSOUserFunction,
SaveUserOpts,
SSOAuthDetails, SSOAuthDetails,
SSOUser, SSOUser,
User, User,
@ -14,10 +13,8 @@ import {
// no-op function for user save // no-op function for user save
// - this allows datasource auth and access token refresh to work correctly // - this allows datasource auth and access token refresh to work correctly
// - prefer no-op over an optional argument to ensure function is provided to login flows // - prefer no-op over an optional argument to ensure function is provided to login flows
export const ssoSaveUserNoOp: SaveSSOUserFunction = ( export const ssoSaveUserNoOp: SaveSSOUserFunction = (user: SSOUser) =>
user: SSOUser, Promise.resolve(user)
opts: SaveUserOpts
) => Promise.resolve(user)
/** /**
* Common authentication logic for third parties. e.g. OAuth, OIDC. * Common authentication logic for third parties. e.g. OAuth, OIDC.

View File

@ -45,10 +45,6 @@ export const runMigration = async (
options: MigrationOptions = {} options: MigrationOptions = {}
) => { ) => {
const migrationType = migration.type const migrationType = migration.type
let tenantId: string | undefined
if (migrationType !== MigrationType.INSTALLATION) {
tenantId = context.getTenantId()
}
const migrationName = migration.name const migrationName = migration.name
const silent = migration.silent const silent = migration.silent

View File

@ -126,7 +126,7 @@ describe("app", () => {
it("gets url with embedded minio", async () => { it("gets url with embedded minio", async () => {
testEnv.withMinio() testEnv.withMinio()
await testEnv.withTenant(tenantId => { await testEnv.withTenant(() => {
const url = getAppFileUrl() const url = getAppFileUrl()
expect(url).toBe( expect(url).toBe(
"/files/signed/prod-budi-app-assets/app_123/attachments/image.jpeg" "/files/signed/prod-budi-app-assets/app_123/attachments/image.jpeg"
@ -136,7 +136,7 @@ describe("app", () => {
it("gets url with custom S3", async () => { it("gets url with custom S3", async () => {
testEnv.withS3() testEnv.withS3()
await testEnv.withTenant(tenantId => { await testEnv.withTenant(() => {
const url = getAppFileUrl() const url = getAppFileUrl()
expect(url).toBe( expect(url).toBe(
"http://s3.example.com/prod-budi-app-assets/app_123/attachments/image.jpeg" "http://s3.example.com/prod-budi-app-assets/app_123/attachments/image.jpeg"
@ -146,7 +146,7 @@ describe("app", () => {
it("gets url with cloudfront + s3", async () => { it("gets url with cloudfront + s3", async () => {
testEnv.withCloudfront() testEnv.withCloudfront()
await testEnv.withTenant(tenantId => { await testEnv.withTenant(() => {
const url = getAppFileUrl() const url = getAppFileUrl()
// omit rest of signed params // omit rest of signed params
expect( expect(

View File

@ -3,7 +3,7 @@ import { DBTestConfiguration } from "../../../tests/extra"
import * as tenants from "../tenants" import * as tenants from "../tenants"
describe("tenants", () => { describe("tenants", () => {
const config = new DBTestConfiguration() new DBTestConfiguration()
describe("addTenant", () => { describe("addTenant", () => {
it("concurrently adds multiple tenants safely", async () => { it("concurrently adds multiple tenants safely", async () => {

View File

@ -166,7 +166,7 @@ class InMemoryQueue implements Partial<Queue> {
return [] return []
} }
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
async removeJobs(pattern: string) { async removeJobs(pattern: string) {
// no-op // no-op
} }

View File

@ -132,7 +132,7 @@ function logging(queue: Queue, jobQueue: JobQueue) {
// A Job is waiting to be processed as soon as a worker is idling. // A Job is waiting to be processed as soon as a worker is idling.
console.info(...getLogParams(eventType, BullEvent.WAITING, { jobId })) console.info(...getLogParams(eventType, BullEvent.WAITING, { jobId }))
}) })
.on(BullEvent.ACTIVE, async (job: Job, jobPromise: any) => { .on(BullEvent.ACTIVE, async (job: Job) => {
// A job has started. You can use `jobPromise.cancel()`` to abort it. // A job has started. You can use `jobPromise.cancel()`` to abort it.
await doInJobContext(job, () => { await doInJobContext(job, () => {
console.info(...getLogParams(eventType, BullEvent.ACTIVE, { job })) console.info(...getLogParams(eventType, BullEvent.ACTIVE, { job }))

View File

@ -40,6 +40,7 @@ export async function shutdown() {
if (inviteClient) await inviteClient.finish() if (inviteClient) await inviteClient.finish()
if (passwordResetClient) await passwordResetClient.finish() if (passwordResetClient) await passwordResetClient.finish()
if (socketClient) await socketClient.finish() if (socketClient) await socketClient.finish()
if (docWritethroughClient) await docWritethroughClient.finish()
} }
process.on("exit", async () => { process.on("exit", async () => {

View File

@ -120,7 +120,7 @@ describe("redis", () => {
await redis.bulkStore(data, ttl) await redis.bulkStore(data, ttl)
for (const [key, value] of Object.entries(data)) { for (const key of Object.keys(data)) {
expect(await redis.get(key)).toBe(null) expect(await redis.get(key)).toBe(null)
} }

View File

@ -45,7 +45,7 @@ describe("Users", () => {
...{ _id: groupId, roles: { app1: "ADMIN" } }, ...{ _id: groupId, roles: { app1: "ADMIN" } },
} }
const users: User[] = [] const users: User[] = []
for (const _ of Array.from({ length: usersInGroup })) { for (let i = 0; i < usersInGroup; i++) {
const userId = `us_${generator.guid()}` const userId = `us_${generator.guid()}`
const user: User = structures.users.user({ const user: User = structures.users.user({
_id: userId, _id: userId,

View File

@ -39,19 +39,23 @@ const handleClick = event => {
return return
} }
if (handler.allowedType && event.type !== handler.allowedType) {
return
}
handler.callback?.(event) handler.callback?.(event)
}) })
} }
document.documentElement.addEventListener("click", handleClick, true) document.documentElement.addEventListener("click", handleClick, true)
document.documentElement.addEventListener("contextmenu", handleClick, true) document.documentElement.addEventListener("mousedown", handleClick, true)
/** /**
* Adds or updates a click handler * Adds or updates a click handler
*/ */
const updateHandler = (id, element, anchor, callback) => { const updateHandler = (id, element, anchor, callback, allowedType) => {
let existingHandler = clickHandlers.find(x => x.id === id) let existingHandler = clickHandlers.find(x => x.id === id)
if (!existingHandler) { if (!existingHandler) {
clickHandlers.push({ id, element, anchor, callback }) clickHandlers.push({ id, element, anchor, callback, allowedType })
} else { } else {
existingHandler.callback = callback existingHandler.callback = callback
} }
@ -77,7 +81,8 @@ export default (element, opts) => {
const update = newOpts => { const update = newOpts => {
const callback = newOpts?.callback || newOpts const callback = newOpts?.callback || newOpts
const anchor = newOpts?.anchor || element const anchor = newOpts?.anchor || element
updateHandler(id, element, anchor, callback) const allowedType = newOpts?.allowedType || "click"
updateHandler(id, element, anchor, callback, allowedType)
} }
update(opts) update(opts)
return { return {

View File

@ -129,10 +129,7 @@
filteredUsers = $usersFetch.rows filteredUsers = $usersFetch.rows
.filter(user => user.email !== $auth.user.email) .filter(user => user.email !== $auth.user.email)
.map(user => { .map(user => {
const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder( const isAdminOrGlobalBuilder = sdk.users.isAdminOrGlobalBuilder(user)
user,
prodAppId
)
const isAppBuilder = user.builder?.apps?.includes(prodAppId) const isAppBuilder = user.builder?.apps?.includes(prodAppId)
let role let role
if (isAdminOrGlobalBuilder) { if (isAdminOrGlobalBuilder) {

View File

@ -291,7 +291,10 @@
<div <div
id="side-panel-container" id="side-panel-container"
class:open={$sidePanelStore.open} class:open={$sidePanelStore.open}
use:clickOutside={autoCloseSidePanel ? sidePanelStore.actions.close : null} use:clickOutside={{
callback: autoCloseSidePanel ? sidePanelStore.actions.close : null,
allowedType: "mousedown",
}}
class:builder={$builderStore.inBuilder} class:builder={$builderStore.inBuilder}
> >
<div class="side-panel-header"> <div class="side-panel-header">

View File

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module FirebaseMock { module FirebaseMock {
const firebase: any = {} const firebase: any = {}

View File

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module SendgridMock { module SendgridMock {
class Email { class Email {
constructor() { constructor() {

View File

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module ArangoMock { module ArangoMock {
const arangodb: any = {} const arangodb: any = {}

View File

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module MongoMock { module MongoMock {
const mongodb: any = {} const mongodb: any = {}

View File

@ -1,3 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module MySQLMock { module MySQLMock {
const mysql: any = {} const mysql: any = {}

View File

@ -1,6 +1,7 @@
// @ts-ignore // @ts-ignore
import fs from "fs" import fs from "fs"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
module FetchMock { module FetchMock {
// @ts-ignore // @ts-ignore
const fetch = jest.requireActual("node-fetch") const fetch = jest.requireActual("node-fetch")

View File

@ -26,7 +26,6 @@ import {
env as envCore, env as envCore,
ErrorCode, ErrorCode,
events, events,
HTTPError,
migrations, migrations,
objectStore, objectStore,
roles, roles,

View File

@ -116,7 +116,7 @@ export async function save(ctx: UserCtx<SaveRoleRequest, SaveRoleResponse>) {
target: prodDb.name, target: prodDb.name,
}) })
await replication.replicate({ await replication.replicate({
filter: (doc: any, params: any) => { filter: (doc: any) => {
return doc._id && doc._id.startsWith("role_") return doc._id && doc._id.startsWith("role_")
}, },
}) })

View File

@ -7,13 +7,11 @@ import {
FilterType, FilterType,
IncludeRelationship, IncludeRelationship,
ManyToManyRelationshipFieldMetadata, ManyToManyRelationshipFieldMetadata,
ManyToOneRelationshipFieldMetadata,
OneToManyRelationshipFieldMetadata, OneToManyRelationshipFieldMetadata,
Operation, Operation,
PaginationJson, PaginationJson,
RelationshipFieldMetadata, RelationshipFieldMetadata,
RelationshipsJson, RelationshipsJson,
RelationshipType,
Row, Row,
SearchFilters, SearchFilters,
SortJson, SortJson,

View File

@ -1,4 +1,3 @@
import { quotas } from "@budibase/pro"
import { import {
UserCtx, UserCtx,
ViewV2, ViewV2,

View File

@ -1,6 +1,6 @@
import { generateUserFlagID, InternalTables } from "../../db/utils" import { generateUserFlagID, InternalTables } from "../../db/utils"
import { getFullUser } from "../../utilities/users" import { getFullUser } from "../../utilities/users"
import { cache, context } from "@budibase/backend-core" import { context } from "@budibase/backend-core"
import { import {
ContextUserMetadata, ContextUserMetadata,
Ctx, Ctx,

View File

@ -24,7 +24,7 @@ async function parseSchema(view: CreateViewRequest) {
icon: schemaValue.icon, icon: schemaValue.icon,
} }
Object.entries(fieldSchema) Object.entries(fieldSchema)
.filter(([_, val]) => val === undefined) .filter(([, val]) => val === undefined)
.forEach(([key]) => { .forEach(([key]) => {
delete fieldSchema[key as keyof UIFieldMetadata] delete fieldSchema[key as keyof UIFieldMetadata]
}) })

View File

@ -33,7 +33,6 @@ export { default as staticRoutes } from "./static"
export { default as publicRoutes } from "./public" export { default as publicRoutes } from "./public"
const appBackupRoutes = pro.appBackups const appBackupRoutes = pro.appBackups
const scheduleRoutes = pro.schedules
const environmentVariableRoutes = pro.environmentVariables const environmentVariableRoutes = pro.environmentVariables
export const mainRoutes: Router[] = [ export const mainRoutes: Router[] = [
@ -65,7 +64,6 @@ export const mainRoutes: Router[] = [
pluginRoutes, pluginRoutes,
opsRoutes, opsRoutes,
debugRoutes, debugRoutes,
scheduleRoutes,
environmentVariableRoutes, environmentVariableRoutes,
// these need to be handled last as they still use /api/:tableId // these need to be handled last as they still use /api/:tableId
// this could be breaking as koa may recognise other routes as this // this could be breaking as koa may recognise other routes as this

View File

@ -16,7 +16,7 @@ describe("/applications/:appId/import", () => {
it("should be able to perform import", async () => { it("should be able to perform import", async () => {
const appId = config.getAppId() const appId = config.getAppId()
const res = await request await request
.post(`/api/applications/${appId}/import`) .post(`/api/applications/${appId}/import`)
.field("encryptionPassword", PASSWORD) .field("encryptionPassword", PASSWORD)
.attach("appExport", path.join(__dirname, "assets", "export.tar.gz")) .attach("appExport", path.join(__dirname, "assets", "export.tar.gz"))

View File

@ -2,7 +2,6 @@ import * as setup from "./utilities"
import { roles, db as dbCore } from "@budibase/backend-core" import { roles, db as dbCore } from "@budibase/backend-core"
describe("/api/applications/:appId/sync", () => { describe("/api/applications/:appId/sync", () => {
let request = setup.getRequest()
let config = setup.getConfig() let config = setup.getConfig()
let app let app

View File

@ -369,7 +369,7 @@ describe("/applications", () => {
}) })
it("should reject with a known name", async () => { it("should reject with a known name", async () => {
const resp = await config.api.application.duplicateApp( await config.api.application.duplicateApp(
app.appId, app.appId,
{ {
name: app.name, name: app.name,
@ -381,7 +381,7 @@ describe("/applications", () => {
}) })
it("should reject with a known url", async () => { it("should reject with a known url", async () => {
const resp = await config.api.application.duplicateApp( await config.api.application.duplicateApp(
app.appId, app.appId,
{ {
name: "this is fine", name: "this is fine",

View File

@ -156,7 +156,7 @@ describe("/permission", () => {
level: PermissionLevel.READ, level: PermissionLevel.READ,
}) })
const response = await config.api.permission.revoke( await config.api.permission.revoke(
{ {
roleId: STD_ROLE_ID, roleId: STD_ROLE_ID,
resourceId: table._id, resourceId: table._id,

View File

@ -65,7 +65,7 @@ describe("/queries", () => {
beforeEach(async () => { beforeEach(async () => {
await withConnection(async connection => { await withConnection(async connection => {
const resp = await connection.query(createTableSQL) await connection.query(createTableSQL)
await connection.query(insertSQL) await connection.query(insertSQL)
}) })
}) })

View File

@ -74,7 +74,7 @@ describe("/views", () => {
describe("create", () => { describe("create", () => {
it("returns a success message when the view is successfully created", async () => { it("returns a success message when the view is successfully created", async () => {
const res = await saveView() await saveView()
expect(events.view.created).toHaveBeenCalledTimes(1) expect(events.view.created).toHaveBeenCalledTimes(1)
}) })

View File

@ -5,7 +5,7 @@ import {
} from "@budibase/string-templates" } from "@budibase/string-templates"
import sdk from "../sdk" import sdk from "../sdk"
import { Row } from "@budibase/types" import { Row } from "@budibase/types"
import { LoopInput, LoopStep, LoopStepType } from "../definitions/automations" import { LoopInput, LoopStepType } from "../definitions/automations"
/** /**
* When values are input to the system generally they will be of type string as this is required for template strings. * When values are input to the system generally they will be of type string as this is required for template strings.

View File

@ -4,7 +4,6 @@ import {
AutomationStepInput, AutomationStepInput,
AutomationStepType, AutomationStepType,
AutomationIOType, AutomationIOType,
AutomationFeature,
} from "@budibase/types" } from "@budibase/types"
export const definition: AutomationStepSchema = { export const definition: AutomationStepSchema = {

View File

@ -10,8 +10,6 @@ import {
AutomationStepSchema, AutomationStepSchema,
AutomationStepType, AutomationStepType,
} from "@budibase/types" } from "@budibase/types"
import { utils } from "@budibase/backend-core"
import env from "../../environment"
export const definition: AutomationStepSchema = { export const definition: AutomationStepSchema = {
name: "External Data Connector", name: "External Data Connector",

View File

@ -58,7 +58,7 @@ export const definition: AutomationStepSchema = {
}, },
} }
export async function run({ inputs, context }: AutomationStepInput) { export async function run({ inputs }: AutomationStepInput) {
if (!environment.OPENAI_API_KEY) { if (!environment.OPENAI_API_KEY) {
return { return {
success: false, success: false,

View File

@ -62,6 +62,7 @@ export const definition: AutomationStepSchema = {
} }
export async function run({ inputs }: AutomationStepInput) { export async function run({ inputs }: AutomationStepInput) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { automationId, ...fieldParams } = inputs.automation const { automationId, ...fieldParams } = inputs.automation
if (await features.isTriggerAutomationRunEnabled()) { if (await features.isTriggerAutomationRunEnabled()) {

View File

@ -3,19 +3,18 @@ import * as triggers from "../triggers"
import { loopAutomation } from "../../tests/utilities/structures" import { loopAutomation } from "../../tests/utilities/structures"
import { context } from "@budibase/backend-core" import { context } from "@budibase/backend-core"
import * as setup from "./utilities" import * as setup from "./utilities"
import { Row, Table } from "@budibase/types" import { Table } from "@budibase/types"
import { LoopInput, LoopStepType } from "../../definitions/automations" import { LoopInput, LoopStepType } from "../../definitions/automations"
describe("Attempt to run a basic loop automation", () => { describe("Attempt to run a basic loop automation", () => {
let config = setup.getConfig(), let config = setup.getConfig(),
table: Table, table: Table
row: Row
beforeEach(async () => { beforeEach(async () => {
await automation.init() await automation.init()
await config.init() await config.init()
table = await config.createTable() table = await config.createTable()
row = await config.createRow() await config.createRow()
}) })
afterAll(setup.afterAll) afterAll(setup.afterAll)

View File

@ -1,4 +1,4 @@
import { LoopStep, LoopStepType } from "../../definitions/automations" import { LoopStepType } from "../../definitions/automations"
import { import {
typecastForLooping, typecastForLooping,
cleanInputValues, cleanInputValues,

View File

@ -6,6 +6,10 @@ import {
TableSourceType, TableSourceType,
} from "@budibase/types" } from "@budibase/types"
import env from "../environment"
export const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
export enum FilterTypes { export enum FilterTypes {
STRING = "string", STRING = "string",
FUZZY = "fuzzy", FUZZY = "fuzzy",

View File

@ -1,147 +0,0 @@
import merge from "lodash/merge"
import env from "../environment"
export const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
const TableInfo = {
API_KEYS: {
name: "beta-api-key-table",
primary: "pk",
},
USERS: {
name: "prod-budi-table",
primary: "pk",
sort: "sk",
},
}
let docClient: any = null
type GetOpts = {
primary: string
sort?: string
otherProps?: any
}
type UpdateOpts = {
primary: string
sort?: string
expression?: string
condition?: string
names?: string[]
values?: any[]
exists?: boolean
otherProps?: any
}
type PutOpts = {
item: any
otherProps?: any
}
class Table {
_name: string
_primary: string
_sort?: string
constructor(tableInfo: { name: string; primary: string; sort?: string }) {
if (!tableInfo.name || !tableInfo.primary) {
throw "Table info must specify a name and a primary key"
}
this._name = tableInfo.name
this._primary = tableInfo.primary
this._sort = tableInfo.sort
}
async get({ primary, sort, otherProps }: GetOpts) {
let params = {
TableName: this._name,
Key: {
[this._primary]: primary,
},
}
if (this._sort && sort) {
params.Key[this._sort] = sort
}
if (otherProps) {
params = merge(params, otherProps)
}
let response = await docClient.get(params).promise()
return response.Item
}
async update({
primary,
sort,
expression,
condition,
names,
values,
exists,
otherProps,
}: UpdateOpts) {
let params: any = {
TableName: this._name,
Key: {
[this._primary]: primary,
},
ExpressionAttributeNames: names,
ExpressionAttributeValues: values,
UpdateExpression: expression,
}
if (condition) {
params.ConditionExpression = condition
}
if (this._sort && sort) {
params.Key[this._sort] = sort
}
if (exists) {
params.ExpressionAttributeNames["#PRIMARY"] = this._primary
if (params.ConditionExpression) {
params.ConditionExpression += " AND "
}
params.ConditionExpression += "attribute_exists(#PRIMARY)"
}
if (otherProps) {
params = merge(params, otherProps)
}
return docClient.update(params).promise()
}
async put({ item, otherProps }: PutOpts) {
if (
item[this._primary] == null ||
(this._sort && item[this._sort] == null)
) {
throw "Cannot put item without primary and sort key (if required)"
}
let params = {
TableName: this._name,
Item: item,
}
if (otherProps) {
params = merge(params, otherProps)
}
return docClient.put(params).promise()
}
}
export function init(endpoint: string) {
let AWS = require("aws-sdk")
let docClientParams: any = {
correctClockSkew: true,
region: AWS_REGION,
}
if (endpoint) {
docClientParams.endpoint = endpoint
} else if (env.DYNAMO_ENDPOINT) {
docClientParams.endpoint = env.DYNAMO_ENDPOINT
}
docClient = new AWS.DynamoDB.DocumentClient(docClientParams)
}
if (!env.isProd() && !env.isJest()) {
env._set("AWS_ACCESS_KEY_ID", "KEY_ID")
env._set("AWS_SECRET_ACCESS_KEY", "SECRET_KEY")
init("http://localhost:8333")
}

View File

@ -18,7 +18,6 @@ import {
Row, Row,
LinkDocumentValue, LinkDocumentValue,
FieldType, FieldType,
LinkDocument,
ContextUser, ContextUser,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../sdk" import sdk from "../../sdk"

View File

@ -1,8 +1,11 @@
import { features } from "@budibase/backend-core" import { features } from "@budibase/backend-core"
import env from "./environment" import env from "./environment"
// eslint-disable-next-line no-unused-vars
enum AppFeature { enum AppFeature {
// eslint-disable-next-line no-unused-vars
API = "api", API = "api",
// eslint-disable-next-line no-unused-vars
AUTOMATIONS = "automations", AUTOMATIONS = "automations",
} }

View File

@ -12,7 +12,6 @@ import {
TableRequest, TableRequest,
TableSourceType, TableSourceType,
} from "@budibase/types" } from "@budibase/types"
import _ from "lodash"
import { databaseTestProviders } from "../integrations/tests/utils" import { databaseTestProviders } from "../integrations/tests/utils"
import mysql from "mysql2/promise" import mysql from "mysql2/promise"
import { builderSocket } from "../websockets" import { builderSocket } from "../websockets"

View File

@ -8,7 +8,7 @@ import {
} from "@budibase/types" } from "@budibase/types"
import AWS from "aws-sdk" import AWS from "aws-sdk"
import { AWS_REGION } from "../db/dynamoClient" import { AWS_REGION } from "../constants"
import { DocumentClient } from "aws-sdk/clients/dynamodb" import { DocumentClient } from "aws-sdk/clients/dynamodb"
interface DynamoDBConfig { interface DynamoDBConfig {

View File

@ -168,6 +168,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
return "" return ""
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getStringConcat(parts: string[]) { getStringConcat(parts: string[]) {
return "" return ""
} }

View File

@ -14,8 +14,6 @@ import {
Schema, Schema,
TableSourceType, TableSourceType,
DatasourcePlusQueryResponse, DatasourcePlusQueryResponse,
FieldType,
FieldSubtype,
} from "@budibase/types" } from "@budibase/types"
import { import {
getSqlQuery, getSqlQuery,

View File

@ -13,8 +13,6 @@ import {
Schema, Schema,
TableSourceType, TableSourceType,
DatasourcePlusQueryResponse, DatasourcePlusQueryResponse,
FieldType,
FieldSubtype,
} from "@budibase/types" } from "@budibase/types"
import { import {
getSqlQuery, getSqlQuery,

View File

@ -28,7 +28,7 @@ describe("Airtable Integration", () => {
}) })
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const response = await config.integration.create({ await config.integration.create({
table: "test", table: "test",
json: {}, json: {},
}) })
@ -40,7 +40,7 @@ describe("Airtable Integration", () => {
}) })
it("calls the read method with the correct params", async () => { it("calls the read method with the correct params", async () => {
const response = await config.integration.read({ await config.integration.read({
table: "test", table: "test",
view: "Grid view", view: "Grid view",
}) })
@ -51,7 +51,7 @@ describe("Airtable Integration", () => {
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const response = await config.integration.update({ await config.integration.update({
table: "table", table: "table",
id: "123", id: "123",
json: { json: {
@ -68,7 +68,7 @@ describe("Airtable Integration", () => {
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const ids = [1, 2, 3, 4] const ids = [1, 2, 3, 4]
const response = await config.integration.delete({ await config.integration.delete({
ids, ids,
}) })
expect(config.client.destroy).toHaveBeenCalledWith(ids) expect(config.client.destroy).toHaveBeenCalledWith(ids)

View File

@ -12,7 +12,6 @@ class TestConfiguration {
describe("ArangoDB Integration", () => { describe("ArangoDB Integration", () => {
let config: any let config: any
let indexName = "Users"
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration() config = new TestConfiguration()
@ -23,7 +22,7 @@ describe("ArangoDB Integration", () => {
json: "Hello", json: "Hello",
} }
const response = await config.integration.create(body) await config.integration.create(body)
expect(config.integration.client.query).toHaveBeenCalledWith( expect(config.integration.client.query).toHaveBeenCalledWith(
`INSERT Hello INTO collection RETURN NEW` `INSERT Hello INTO collection RETURN NEW`
) )
@ -33,7 +32,7 @@ describe("ArangoDB Integration", () => {
const query = { const query = {
sql: `test`, sql: `test`,
} }
const response = await config.integration.read(query) await config.integration.read(query)
expect(config.integration.client.query).toHaveBeenCalledWith(query.sql) expect(config.integration.client.query).toHaveBeenCalledWith(query.sql)
}) })
}) })

View File

@ -79,7 +79,7 @@ describe("CouchDB Integration", () => {
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const id = "1234" const id = "1234"
const response = await config.integration.delete({ id }) await config.integration.delete({ id })
expect(config.integration.client.get).toHaveBeenCalledWith(id) expect(config.integration.client.get).toHaveBeenCalledWith(id)
expect(config.integration.client.remove).toHaveBeenCalled() expect(config.integration.client.remove).toHaveBeenCalled()
}) })

View File

@ -19,7 +19,7 @@ describe("DynamoDB Integration", () => {
}) })
it("calls the create method with the correct params", async () => { it("calls the create method with the correct params", async () => {
const response = await config.integration.create({ await config.integration.create({
table: tableName, table: tableName,
json: { json: {
Name: "John", Name: "John",
@ -66,7 +66,7 @@ describe("DynamoDB Integration", () => {
}) })
it("calls the get method with the correct params", async () => { it("calls the get method with the correct params", async () => {
const response = await config.integration.get({ await config.integration.get({
table: tableName, table: tableName,
json: { json: {
Id: 123, Id: 123,
@ -80,7 +80,7 @@ describe("DynamoDB Integration", () => {
}) })
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const response = await config.integration.update({ await config.integration.update({
table: tableName, table: tableName,
json: { json: {
Name: "John", Name: "John",
@ -93,7 +93,7 @@ describe("DynamoDB Integration", () => {
}) })
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const response = await config.integration.delete({ await config.integration.delete({
table: tableName, table: tableName,
json: { json: {
Name: "John", Name: "John",

View File

@ -22,7 +22,7 @@ describe("Elasticsearch Integration", () => {
const body = { const body = {
name: "Hello", name: "Hello",
} }
const response = await config.integration.create({ await config.integration.create({
index: indexName, index: indexName,
json: body, json: body,
}) })

View File

@ -81,7 +81,7 @@ describe("Firebase Integration", () => {
}) })
it("calls the delete method with the correct params", async () => { it("calls the delete method with the correct params", async () => {
const response = await config.integration.delete({ await config.integration.delete({
table: tableName, table: tableName,
json: { json: {
id: "test", id: "test",

View File

@ -44,7 +44,7 @@ describe("Oracle Integration", () => {
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const sql = "update table users set name = 'test';" const sql = "update table users set name = 'test';"
const response = await config.integration.update({ await config.integration.update({
sql, sql,
}) })
expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options) expect(oracledb.executeMock).toHaveBeenCalledWith(sql, [], options)

View File

@ -37,7 +37,7 @@ describe("Postgres Integration", () => {
it("calls the update method with the correct params", async () => { it("calls the update method with the correct params", async () => {
const sql = "update table users set name = 'test';" const sql = "update table users set name = 'test';"
const response = await config.integration.update({ await config.integration.update({
sql, sql,
}) })
expect(pg.queryMock).toHaveBeenCalledWith(sql, []) expect(pg.queryMock).toHaveBeenCalledWith(sql, [])

View File

@ -70,7 +70,7 @@ describe("REST Integration", () => {
Accept: "text/html", Accept: "text/html",
}, },
} }
const response = await config.integration.read(query) await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
headers: { headers: {
Accept: "text/html", Accept: "text/html",
@ -91,7 +91,7 @@ describe("REST Integration", () => {
name: "test", name: "test",
}), }),
} }
const response = await config.integration.update(query) await config.integration.update(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
method: "PUT", method: "PUT",
body: '{"name":"test"}', body: '{"name":"test"}',
@ -111,7 +111,7 @@ describe("REST Integration", () => {
name: "test", name: "test",
}), }),
} }
const response = await config.integration.delete(query) await config.integration.delete(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
method: "DELETE", method: "DELETE",
headers: HEADERS, headers: HEADERS,

View File

@ -1,5 +1,3 @@
const AWS = require("aws-sdk")
import { default as S3Integration } from "../s3" import { default as S3Integration } from "../s3"
jest.mock("aws-sdk") jest.mock("aws-sdk")

View File

@ -1,5 +1,3 @@
import { utils } from "@budibase/shared-core"
import environment from "../../environment"
import fs from "fs" import fs from "fs"
export const enum BundleType { export const enum BundleType {

View File

@ -8,11 +8,10 @@ import {
import { context, logging } from "@budibase/backend-core" import { context, logging } from "@budibase/backend-core"
import tracer from "dd-trace" import tracer from "dd-trace"
import { IsolatedVM } from "./vm" import { IsolatedVM } from "./vm"
import type { VM } from "@budibase/types"
export function init() { export function init() {
setJSRunner((js: string, ctx: Record<string, any>) => { setJSRunner((js: string, ctx: Record<string, any>) => {
return tracer.trace("runJS", {}, span => { return tracer.trace("runJS", {}, () => {
try { try {
// Reuse an existing isolate from context, or make a new one // Reuse an existing isolate from context, or make a new one
const bbCtx = context.getCurrentContext() const bbCtx = context.getCurrentContext()
@ -36,6 +35,7 @@ export function init() {
// Because we can't pass functions into an Isolate, we remove them from // Because we can't pass functions into an Isolate, we remove them from
// the passed context and rely on the withHelpers() method to add them // the passed context and rely on the withHelpers() method to add them
// back in. // back in.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { helpers, snippets, ...rest } = ctx const { helpers, snippets, ...rest } = ctx
return vm.withContext(rest, () => vm.execute(js)) return vm.withContext(rest, () => vm.execute(js))
} catch (error: any) { } catch (error: any) {

View File

@ -13,7 +13,7 @@ export default async (ctx: Ctx, next: any) => {
let errors = [] let errors = []
for (let fn of current.cleanup) { for (let fn of current.cleanup) {
try { try {
await tracer.trace("cleanup", async span => { await tracer.trace("cleanup", async () => {
await fn() await fn()
}) })
} catch (e) { } catch (e) {

View File

@ -11,7 +11,6 @@ import {
import authorizedMiddleware from "../authorized" import authorizedMiddleware from "../authorized"
import env from "../../environment" import env from "../../environment"
import { generateTableID, generateViewID } from "../../db/utils"
import { generator, mocks } from "@budibase/backend-core/tests" import { generator, mocks } from "@budibase/backend-core/tests"
import { initProMocks } from "../../tests/utilities/mocks/pro" import { initProMocks } from "../../tests/utilities/mocks/pro"
import { getResourcePerms } from "../../sdk/app/permissions" import { getResourcePerms } from "../../sdk/app/permissions"

View File

@ -32,10 +32,7 @@ export default async (ctx: Ctx<Row>, next: Next) => {
} }
// have to mutate the koa context, can't return // have to mutate the koa context, can't return
export async function trimViewFields<T extends Row>( export async function trimViewFields(body: Row, viewId: string): Promise<void> {
body: Row,
viewId: string
): Promise<void> {
const view = await sdk.views.get(viewId) const view = await sdk.views.get(viewId)
const allowedKeys = sdk.views.allowedFields(view) const allowedKeys = sdk.views.allowedFields(view)
// have to mutate the context, can't update reference // have to mutate the context, can't update reference

View File

@ -43,7 +43,7 @@ export const backfill = async (
} }
if (user.roles) { if (user.roles) {
for (const [appId, role] of Object.entries(user.roles)) { for (const [, role] of Object.entries(user.roles)) {
await events.role.assigned(user, role, timestamp) await events.role.assigned(user, role, timestamp)
} }
} }

View File

@ -11,7 +11,6 @@ import env from "../environment"
// migration functions // migration functions
import * as userEmailViewCasing from "./functions/userEmailViewCasing" import * as userEmailViewCasing from "./functions/userEmailViewCasing"
import * as syncQuotas from "./functions/syncQuotas" import * as syncQuotas from "./functions/syncQuotas"
import * as syncUsers from "./functions/usageQuotas/syncUsers"
import * as appUrls from "./functions/appUrls" import * as appUrls from "./functions/appUrls"
import * as tableSettings from "./functions/tableSettings" import * as tableSettings from "./functions/tableSettings"
import * as backfill from "./functions/backfill" import * as backfill from "./functions/backfill"

View File

@ -3,11 +3,7 @@ import { db as dbCore, context, logging, roles } from "@budibase/backend-core"
import { User, ContextUser, UserGroup } from "@budibase/types" import { User, ContextUser, UserGroup } from "@budibase/types"
import { sdk as proSdk } from "@budibase/pro" import { sdk as proSdk } from "@budibase/pro"
import sdk from "../../" import sdk from "../../"
import { import { getRawGlobalUsers, processUser } from "../../../utilities/global"
getGlobalUsers,
getRawGlobalUsers,
processUser,
} from "../../../utilities/global"
import { generateUserMetadataID, InternalTables } from "../../../db/utils" import { generateUserMetadataID, InternalTables } from "../../../db/utils"
type DeletedUser = { _id: string; deleted: boolean } type DeletedUser = { _id: string; deleted: boolean }

View File

@ -6,7 +6,7 @@ import EventEmitter from "events"
import { UserGroup, UserMetadata, UserRoles, User } from "@budibase/types" import { UserGroup, UserMetadata, UserRoles, User } from "@budibase/types"
const config = new TestConfiguration() const config = new TestConfiguration()
let app, group: UserGroup, groupUser: User let group: UserGroup, groupUser: User
const ROLE_ID = roles.BUILTIN_ROLE_IDS.BASIC const ROLE_ID = roles.BUILTIN_ROLE_IDS.BASIC
const emitter = new EventEmitter() const emitter = new EventEmitter()
@ -36,7 +36,7 @@ function waitForUpdate(opts: { group?: boolean }) {
} }
beforeAll(async () => { beforeAll(async () => {
app = await config.init("syncApp") await config.init("syncApp")
}) })
async function createUser(email: string, roles: UserRoles, builder?: boolean) { async function createUser(email: string, roles: UserRoles, builder?: boolean) {

View File

@ -1,4 +1,4 @@
import { db, env, roles } from "@budibase/backend-core" import { db, roles } from "@budibase/backend-core"
import { features } from "@budibase/pro" import { features } from "@budibase/pro"
import { import {
DocumentType, DocumentType,
@ -133,7 +133,7 @@ export async function getDependantResources(
} }
const permissions = await getResourcePerms(view.id) const permissions = await getResourcePerms(view.id)
for (const [level, roleInfo] of Object.entries(permissions)) { for (const [, roleInfo] of Object.entries(permissions)) {
if (roleInfo.type === PermissionSource.INHERITED) { if (roleInfo.type === PermissionSource.INHERITED) {
dependants[VirtualDocumentType.VIEW] ??= new Set() dependants[VirtualDocumentType.VIEW] ??= new Set()
dependants[VirtualDocumentType.VIEW].add(view.id) dependants[VirtualDocumentType.VIEW].add(view.id)

View File

@ -351,6 +351,7 @@ describe("table sdk", () => {
const view: ViewV2 = { const view: ViewV2 = {
...basicView, ...basicView,
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { name, description, ...newTableSchema } = basicTable.schema const { name, description, ...newTableSchema } = basicTable.schema
const result = syncSchema(_.cloneDeep(view), newTableSchema, undefined) const result = syncSchema(_.cloneDeep(view), newTableSchema, undefined)
@ -364,6 +365,7 @@ describe("table sdk", () => {
const view: ViewV2 = { const view: ViewV2 = {
...basicView, ...basicView,
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { description, ...newTableSchema } = { const { description, ...newTableSchema } = {
...basicTable.schema, ...basicTable.schema,
updatedDescription: { updatedDescription: {
@ -448,6 +450,7 @@ describe("table sdk", () => {
hiddenField: { visible: false }, hiddenField: { visible: false },
}, },
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { name, description, ...newTableSchema } = basicTable.schema const { name, description, ...newTableSchema } = basicTable.schema
const result = syncSchema(_.cloneDeep(view), newTableSchema, undefined) const result = syncSchema(_.cloneDeep(view), newTableSchema, undefined)
@ -471,6 +474,7 @@ describe("table sdk", () => {
hiddenField: { visible: false }, hiddenField: { visible: false },
}, },
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { name, description, ...newTableSchema } = { const { name, description, ...newTableSchema } = {
...basicTable.schema, ...basicTable.schema,
newField1: { newField1: {
@ -502,6 +506,7 @@ describe("table sdk", () => {
hiddenField: { visible: false }, hiddenField: { visible: false },
}, },
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { description, ...newTableSchema } = { const { description, ...newTableSchema } = {
...basicTable.schema, ...basicTable.schema,
updatedDescription: { updatedDescription: {

View File

@ -49,7 +49,6 @@ import {
AuthToken, AuthToken,
Automation, Automation,
CreateViewRequest, CreateViewRequest,
Ctx,
Datasource, Datasource,
FieldType, FieldType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,

View File

@ -6,7 +6,6 @@ import {
PaginatedSearchRowResponse, PaginatedSearchRowResponse,
} from "@budibase/types" } from "@budibase/types"
import { Expectations, TestAPI } from "./base" import { Expectations, TestAPI } from "./base"
import { generator } from "@budibase/backend-core/tests"
import sdk from "../../../sdk" import sdk from "../../../sdk"
export class ViewV2API extends TestAPI { export class ViewV2API extends TestAPI {

View File

@ -9,9 +9,7 @@ export async function jsonFromCsvString(csvString: string) {
// ignoreEmpty will remove the key completly if empty, so creating this empty object will ensure we return the values with the keys but empty values // ignoreEmpty will remove the key completly if empty, so creating this empty object will ensure we return the values with the keys but empty values
const result = await csv({ ignoreEmpty: false }).fromString(csvString) const result = await csv({ ignoreEmpty: false }).fromString(csvString)
result.forEach((r, i) => { result.forEach((r, i) => {
for (const [key] of Object.entries(r).filter( for (const [key] of Object.entries(r).filter(([, value]) => value === "")) {
([key, value]) => value === ""
)) {
if (castedWithEmptyValues[i][key] === undefined) { if (castedWithEmptyValues[i][key] === undefined) {
r[key] = null r[key] = null
} }

View File

@ -34,21 +34,6 @@ interface ValidationResults {
errors: Record<string, string> errors: Record<string, string>
} }
const PARSERS: any = {
[FieldType.NUMBER]: (attribute?: string) => {
if (!attribute) {
return attribute
}
return Number(attribute)
},
[FieldType.DATETIME]: (attribute?: string) => {
if (!attribute) {
return attribute
}
return new Date(attribute).toISOString()
},
}
export function isSchema(schema: any): schema is Schema { export function isSchema(schema: any): schema is Schema {
return ( return (
typeof schema === "object" && typeof schema === "object" &&

View File

@ -1,18 +0,0 @@
// UNUSED CODE
// Preserved for future use
/* eslint-disable no-unused-vars */
function getNewQuotaReset() {
return Date.now() + 2592000000
}
function resetQuotasIfRequired(quota: { quotaReset: number; usageQuota: any }) {
// Check if the quota needs reset
if (Date.now() >= quota.quotaReset) {
quota.quotaReset = getNewQuotaReset()
for (let prop of Object.keys(quota.usageQuota)) {
quota.usageQuota[prop] = 0
}
}
}

View File

@ -1,10 +1,4 @@
import { import { Response, default as fetch, type RequestInit } from "node-fetch"
Response,
default as fetch,
type RequestInit,
Headers,
HeadersInit,
} from "node-fetch"
import env from "../environment" import env from "../environment"
import { checkSlashesInUrl } from "./index" import { checkSlashesInUrl } from "./index"
import { import {
@ -13,7 +7,6 @@ import {
tenancy, tenancy,
logging, logging,
env as coreEnv, env as coreEnv,
utils,
} from "@budibase/backend-core" } from "@budibase/backend-core"
import { Ctx, User, EmailInvite } from "@budibase/types" import { Ctx, User, EmailInvite } from "@budibase/types"

View File

@ -262,10 +262,12 @@ export class BaseSocket {
} }
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async onConnect(socket: Socket) { async onConnect(socket: Socket) {
// Override // Override
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async onDisconnect(socket: Socket) { async onDisconnect(socket: Socket) {
// Override // Override
} }

View File

@ -46,10 +46,7 @@ export function isAdminOrBuilder(
return isBuilder(user, appId) || isAdmin(user) return isBuilder(user, appId) || isAdmin(user)
} }
export function isAdminOrGlobalBuilder( export function isAdminOrGlobalBuilder(user: User | ContextUser): boolean {
user: User | ContextUser,
appId?: string
): boolean {
return isGlobalBuilder(user) || isAdmin(user) return isGlobalBuilder(user) || isAdmin(user)
} }

View File

@ -1,6 +1,8 @@
{ {
"extends": "./tsconfig.build.json", "extends": "./tsconfig.build.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": "..",
"rootDir": "src",
"composite": true, "composite": true,
"types": ["node", "jest"] "types": ["node", "jest"]
}, },

View File

@ -34,7 +34,7 @@ export const getParsedManifest = () => {
requiresBlock: boolean requiresBlock: boolean
}>(manifest[collection]) }>(manifest[collection])
.filter( .filter(
([_, details]) => ([, details]) =>
details.example?.split("->").map(x => x.trim()).length > 1 details.example?.split("->").map(x => x.trim()).length > 1
) )
.map(([name, details]): ExampleType => { .map(([name, details]): ExampleType => {
@ -93,7 +93,7 @@ export const runJsHelpersTests = ({
describe.each(Object.keys(jsExamples))("%s", collection => { describe.each(Object.keys(jsExamples))("%s", collection => {
const examplesToRun = jsExamples[collection] const examplesToRun = jsExamples[collection]
.filter(([_, { requiresHbsBody }]) => !requiresHbsBody) .filter(([, { requiresHbsBody }]) => !requiresHbsBody)
.filter(([key]) => !testsToSkip?.includes(key)) .filter(([key]) => !testsToSkip?.includes(key))
examplesToRun.length && examplesToRun.length &&

View File

@ -1,9 +1,5 @@
import { Event, AuditedEventFriendlyName } from "../../../sdk" import { Event } from "../../../sdk"
import { import { PaginationResponse, BasicPaginationRequest } from "../"
PaginationResponse,
PaginationRequest,
BasicPaginationRequest,
} from "../"
import { User, App } from "../../../" import { User, App } from "../../../"
export interface AuditLogSearchParams { export interface AuditLogSearchParams {

View File

@ -1,5 +1,4 @@
import { Document } from "../document" import { Document } from "../document"
import type { Row } from "./row"
export interface QuerySchema { export interface QuerySchema {
name?: string name?: string

View File

@ -225,7 +225,7 @@ export async function oidcCallbackUrl() {
return ssoCallbackUrl(ConfigType.OIDC) return ssoCallbackUrl(ConfigType.OIDC)
} }
export const oidcStrategyFactory = async (ctx: any, configId: any) => { export const oidcStrategyFactory = async (ctx: any) => {
const config = await configs.getOIDCConfig() const config = await configs.getOIDCConfig()
if (!config) { if (!config) {
return ctx.throw(400, "OIDC config not found") return ctx.throw(400, "OIDC config not found")
@ -247,7 +247,7 @@ export const oidcPreAuth = async (ctx: Ctx, next: any) => {
if (!configId) { if (!configId) {
ctx.throw(400, "OIDC config id is required") ctx.throw(400, "OIDC config id is required")
} }
const strategy = await oidcStrategyFactory(ctx, configId) const strategy = await oidcStrategyFactory(ctx)
setCookie(ctx, configId, Cookie.OIDC_CONFIG) setCookie(ctx, configId, Cookie.OIDC_CONFIG)
@ -268,8 +268,7 @@ export const oidcPreAuth = async (ctx: Ctx, next: any) => {
} }
export const oidcCallback = async (ctx: any, next: any) => { export const oidcCallback = async (ctx: any, next: any) => {
const configId = getCookie(ctx, Cookie.OIDC_CONFIG) const strategy = await oidcStrategyFactory(ctx)
const strategy = await oidcStrategyFactory(ctx, configId)
return passport.authenticate( return passport.authenticate(
strategy, strategy,

View File

@ -170,10 +170,7 @@ describe("/api/global/auth", () => {
let user: User let user: User
async function testSSOUser() { async function testSSOUser() {
const { res } = await config.api.auth.requestPasswordReset( await config.api.auth.requestPasswordReset(sendMailMock, user.email)
sendMailMock,
user.email
)
expect(sendMailMock).not.toHaveBeenCalled() expect(sendMailMock).not.toHaveBeenCalled()
} }

View File

@ -704,6 +704,7 @@ describe("scim", () => {
expect(response).toEqual({ expect(response).toEqual({
Resources: expect.arrayContaining( Resources: expect.arrayContaining(
groups.map(g => { groups.map(g => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { members, ...groupData } = g const { members, ...groupData } = g
return groupData return groupData
}) })
@ -723,6 +724,7 @@ describe("scim", () => {
expect(response).toEqual({ expect(response).toEqual({
Resources: expect.arrayContaining( Resources: expect.arrayContaining(
groups.map(g => { groups.map(g => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { members, displayName, ...groupData } = g const { members, displayName, ...groupData } = g
return groupData return groupData
}) })
@ -872,6 +874,7 @@ describe("scim", () => {
qs: "excludedAttributes=members", qs: "excludedAttributes=members",
}) })
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { members, ...expectedResponse } = group const { members, ...expectedResponse } = group
expect(response).toEqual(expectedResponse) expect(response).toEqual(expectedResponse)

View File

@ -1,6 +1,7 @@
import { features } from "@budibase/backend-core" import { features } from "@budibase/backend-core"
import env from "./environment" import env from "./environment"
// eslint-disable-next-line no-unused-vars
enum WorkerFeature {} enum WorkerFeature {}
const featureList: WorkerFeature[] = features.processFeatureEnvVar( const featureList: WorkerFeature[] = features.processFeatureEnvVar(

View File

@ -9,7 +9,7 @@ import { platform } from "@budibase/backend-core"
* Description: * Description:
* Re-sync the global-db users to the global-info db users * Re-sync the global-db users to the global-info db users
*/ */
export const run = async (globalDb: any) => { export const run = async () => {
const users = (await usersSdk.db.allUsers()) as User[] const users = (await usersSdk.db.allUsers()) as User[]
const promises = [] const promises = []
for (let user of users) { for (let user of users) {

View File

@ -19,7 +19,6 @@ import {
users, users,
context, context,
sessions, sessions,
auth,
constants, constants,
env as coreEnv, env as coreEnv,
db as dbCore, db as dbCore,

View File

@ -5,7 +5,7 @@ import { UserGroup as UserGroupType, UserGroupRoles } from "@budibase/types"
export function UserGroup(): UserGroupType { export function UserGroup(): UserGroupType {
const appsCount = generator.integer({ min: 0, max: 3 }) const appsCount = generator.integer({ min: 0, max: 3 })
const roles = Array.from({ length: appsCount }).reduce( const roles = Array.from({ length: appsCount }).reduce(
(p: UserGroupRoles, v) => { (p: UserGroupRoles) => {
return { return {
...p, ...p,
[db.generateAppID()]: generator.pickone(["ADMIN", "POWER", "BASIC"]), [db.generateAppID()]: generator.pickone(["ADMIN", "POWER", "BASIC"]),

Some files were not shown because too many files have changed in this diff Show More