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

View File

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

View File

@ -26,6 +26,7 @@
"svelte": "^4.2.10",
"svelte-eslint-parser": "^0.33.1",
"typescript": "5.2.2",
"typescript-eslint": "^7.3.1",
"yargs": "^17.7.2"
},
"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()
try {
await client.delete(generateTenantKey(key))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ export const buildMatcherRegex = (
}
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 methodMatch =
method === "ALL"

View File

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

View File

@ -5,7 +5,6 @@ import * as context from "../../../context"
import fetch from "node-fetch"
import {
SaveSSOUserFunction,
SaveUserOpts,
SSOAuthDetails,
SSOUser,
User,
@ -14,10 +13,8 @@ import {
// no-op function for user save
// - 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
export const ssoSaveUserNoOp: SaveSSOUserFunction = (
user: SSOUser,
opts: SaveUserOpts
) => Promise.resolve(user)
export const ssoSaveUserNoOp: SaveSSOUserFunction = (user: SSOUser) =>
Promise.resolve(user)
/**
* Common authentication logic for third parties. e.g. OAuth, OIDC.

View File

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

View File

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

View File

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

View File

@ -166,7 +166,7 @@ class InMemoryQueue implements Partial<Queue> {
return []
}
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async removeJobs(pattern: string) {
// 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.
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.
await doInJobContext(job, () => {
console.info(...getLogParams(eventType, BullEvent.ACTIVE, { job }))

View File

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

View File

@ -120,7 +120,7 @@ describe("redis", () => {
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)
}

View File

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

View File

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

View File

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

View File

@ -291,7 +291,10 @@
<div
id="side-panel-container"
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}
>
<div class="side-panel-header">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,7 +33,6 @@ export { default as staticRoutes } from "./static"
export { default as publicRoutes } from "./public"
const appBackupRoutes = pro.appBackups
const scheduleRoutes = pro.schedules
const environmentVariableRoutes = pro.environmentVariables
export const mainRoutes: Router[] = [
@ -65,7 +64,6 @@ export const mainRoutes: Router[] = [
pluginRoutes,
opsRoutes,
debugRoutes,
scheduleRoutes,
environmentVariableRoutes,
// these need to be handled last as they still use /api/:tableId
// 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 () => {
const appId = config.getAppId()
const res = await request
await request
.post(`/api/applications/${appId}/import`)
.field("encryptionPassword", PASSWORD)
.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"
describe("/api/applications/:appId/sync", () => {
let request = setup.getRequest()
let config = setup.getConfig()
let app

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ import {
} from "@budibase/string-templates"
import sdk from "../sdk"
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.

View File

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

View File

@ -10,8 +10,6 @@ import {
AutomationStepSchema,
AutomationStepType,
} from "@budibase/types"
import { utils } from "@budibase/backend-core"
import env from "../../environment"
export const definition: AutomationStepSchema = {
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) {
return {
success: false,

View File

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

View File

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

View File

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

View File

@ -6,6 +6,10 @@ import {
TableSourceType,
} from "@budibase/types"
import env from "../environment"
export const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
export enum FilterTypes {
STRING = "string",
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,
LinkDocumentValue,
FieldType,
LinkDocument,
ContextUser,
} from "@budibase/types"
import sdk from "../../sdk"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,11 +8,10 @@ import {
import { context, logging } from "@budibase/backend-core"
import tracer from "dd-trace"
import { IsolatedVM } from "./vm"
import type { VM } from "@budibase/types"
export function init() {
setJSRunner((js: string, ctx: Record<string, any>) => {
return tracer.trace("runJS", {}, span => {
return tracer.trace("runJS", {}, () => {
try {
// Reuse an existing isolate from context, or make a new one
const bbCtx = context.getCurrentContext()
@ -36,6 +35,7 @@ export function init() {
// 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
// back in.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { helpers, snippets, ...rest } = ctx
return vm.withContext(rest, () => vm.execute(js))
} catch (error: any) {

View File

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

View File

@ -11,7 +11,6 @@ import {
import authorizedMiddleware from "../authorized"
import env from "../../environment"
import { generateTableID, generateViewID } from "../../db/utils"
import { generator, mocks } from "@budibase/backend-core/tests"
import { initProMocks } from "../../tests/utilities/mocks/pro"
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
export async function trimViewFields<T extends Row>(
body: Row,
viewId: string
): Promise<void> {
export async function trimViewFields(body: Row, viewId: string): Promise<void> {
const view = await sdk.views.get(viewId)
const allowedKeys = sdk.views.allowedFields(view)
// have to mutate the context, can't update reference

View File

@ -43,7 +43,7 @@ export const backfill = async (
}
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)
}
}

View File

@ -11,7 +11,6 @@ import env from "../environment"
// migration functions
import * as userEmailViewCasing from "./functions/userEmailViewCasing"
import * as syncQuotas from "./functions/syncQuotas"
import * as syncUsers from "./functions/usageQuotas/syncUsers"
import * as appUrls from "./functions/appUrls"
import * as tableSettings from "./functions/tableSettings"
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 { sdk as proSdk } from "@budibase/pro"
import sdk from "../../"
import {
getGlobalUsers,
getRawGlobalUsers,
processUser,
} from "../../../utilities/global"
import { getRawGlobalUsers, processUser } from "../../../utilities/global"
import { generateUserMetadataID, InternalTables } from "../../../db/utils"
type DeletedUser = { _id: string; deleted: boolean }

View File

@ -6,7 +6,7 @@ import EventEmitter from "events"
import { UserGroup, UserMetadata, UserRoles, User } from "@budibase/types"
const config = new TestConfiguration()
let app, group: UserGroup, groupUser: User
let group: UserGroup, groupUser: User
const ROLE_ID = roles.BUILTIN_ROLE_IDS.BASIC
const emitter = new EventEmitter()
@ -36,7 +36,7 @@ function waitForUpdate(opts: { group?: boolean }) {
}
beforeAll(async () => {
app = await config.init("syncApp")
await config.init("syncApp")
})
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 {
DocumentType,
@ -133,7 +133,7 @@ export async function getDependantResources(
}
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) {
dependants[VirtualDocumentType.VIEW] ??= new Set()
dependants[VirtualDocumentType.VIEW].add(view.id)

View File

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

View File

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

View File

@ -6,7 +6,6 @@ import {
PaginatedSearchRowResponse,
} from "@budibase/types"
import { Expectations, TestAPI } from "./base"
import { generator } from "@budibase/backend-core/tests"
import sdk from "../../../sdk"
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
const result = await csv({ ignoreEmpty: false }).fromString(csvString)
result.forEach((r, i) => {
for (const [key] of Object.entries(r).filter(
([key, value]) => value === ""
)) {
for (const [key] of Object.entries(r).filter(([, value]) => value === "")) {
if (castedWithEmptyValues[i][key] === undefined) {
r[key] = null
}

View File

@ -34,21 +34,6 @@ interface ValidationResults {
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 {
return (
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 {
Response,
default as fetch,
type RequestInit,
Headers,
HeadersInit,
} from "node-fetch"
import { Response, default as fetch, type RequestInit } from "node-fetch"
import env from "../environment"
import { checkSlashesInUrl } from "./index"
import {
@ -13,7 +7,6 @@ import {
tenancy,
logging,
env as coreEnv,
utils,
} from "@budibase/backend-core"
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) {
// Override
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async onDisconnect(socket: Socket) {
// Override
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@ import { platform } from "@budibase/backend-core"
* Description:
* 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 promises = []
for (let user of users) {

View File

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

View File

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

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