- Budibase is an open source low-code platform, and the easiest way to build internal apps that improve productivity.
+ Budibase is an open-source low-code platform that saves engineers 100s of hours building forms, portals, and approval apps, securely.
@@ -20,7 +20,7 @@
-
+
@@ -57,7 +57,7 @@
## ✨ Features
### Build and ship real software
-Unlike other platforms, with Budibase you build and ship single page applications. Budibase applications have performance baked in and can be designed responsively, providing your users with a great experience.
+Unlike other platforms, with Budibase you build and ship single page applications. Budibase applications have performance baked in and can be designed responsively, providing users with a great experience.
### Open source and extensible
@@ -65,40 +65,36 @@ Budibase is open-source - licensed as GPL v3. This should fill you with confiden
### Load data or start from scratch
-Budibase pulls in data from multiple sources, including MongoDB, CouchDB, PostgreSQL, MySQL, Airtable, S3, DynamoDB, or a REST API. And unlike other platforms, with Budibase you can start from scratch and create business apps with no datasources. [Request new datasources](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).
+Budibase pulls data from multiple sources, including MongoDB, CouchDB, PostgreSQL, MySQL, Airtable, S3, DynamoDB, or a REST API. And unlike other platforms, with Budibase you can start from scratch and create business apps with no data sources. [Request new datasources](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).
-
+
### Design and build apps with powerful pre-made components
-Budibase comes out of the box with beautifully designed, powerful components which you can use like building blocks to build your UI. We also expose a lot of your favourite CSS styling options so you can go that extra creative mile. [Request new component](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).
+Budibase comes out of the box with beautifully designed, powerful components which you can use like building blocks to build your UI. We also expose many of your favourite CSS styling options so you can go that extra creative mile. [Request new component](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).
-
+
-### Automate processes, integrate with other tools, and connect to webhooks
-Save time by automating manual processes and workflows. From connecting to webhooks, to automating emails, simply tell Budibase what to do and let it work for you. You can easily [create new automations for Budibase here](https://github.com/Budibase/automations) or [Request new automation](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).
-
-
-
-
+### Automate processes, integrate with other tools and connect to webhooks
+Save time by automating manual processes and workflows. From connecting to webhooks to automating emails, simply tell Budibase what to do and let it work for you. You can easily [create new automations for Budibase here](https://github.com/Budibase/automations) or [Request new automation](https://github.com/Budibase/budibase/discussions?discussions_q=category%3AIdeas).
### Integrate with your favorite tools
Budibase integrates with a number of popular tools allowing you to build apps that perfectly fit your stack.
-
+
-### Admin paradise
-Budibase is made to scale. With Budibase, you can self-host on your own infrastructure and globally manage users, onboarding, SMTP, apps, groups, theming and more. You can also provide users/groups with an app portal and disseminate user-management to the group manager.
+### Deploy with confidence and security
+Budibase is made to scale. With Budibase, you can self-host on your own infrastructure and globally manage users, onboarding, SMTP, apps, groups, theming and more. You can also provide users/groups with an app portal and disseminate user management to the group manager.
- Checkout the promo video: https://youtu.be/xoljVpty_Kw
@@ -119,17 +115,14 @@ As with anything that we build in Budibase, our new public API is simple to use,
#### Docs
You can learn more about the Budibase API at the following places:
-- [General documentation](https://docs.budibase.com/docs/public-api) : Learn how to get your API key, how to use spec, and how to use with Postman
+- [General documentation](https://docs.budibase.com/docs/public-api): Learn how to get your API key, how to use spec, and how to use Postman
- [Interactive API documentation](https://docs.budibase.com/reference/post_applications) : Learn how to interact with the API
-#### Guides
-
-- [Build an app with Budibase and Next.js](https://budibase.com/blog/building-a-crud-app-with-budibase-and-next.js/)
+
## 🏁 Get started
-Deploy Budibase self-hosted in your existing infrastructure, using Docker, Kubernetes, and Digital Ocean.
-Or use Budibase Cloud if you don't need to self-host, and would like to get started quickly.
+Deploy Budibase using Docker, Kubernetes, and Digital Ocean on your existing infrastructure. Or use Budibase Cloud if you don't need to self-host and would like to get started quickly.
### [Get started with self-hosting Budibase](https://docs.budibase.com/docs/hosting-methods)
@@ -162,7 +155,7 @@ If you have a question or would like to talk with other Budibase users and join
## ❗ Code of conduct
-Budibase is dedicated to providing a welcoming, diverse, and harrassment-free experience for everyone. We expect everyone in the Budibase community to abide by our [**Code of Conduct**](https://github.com/Budibase/budibase/blob/HEAD/docs/CODE_OF_CONDUCT.md). Please read it.
+Budibase is dedicated to providing everyone a welcoming, diverse, and harassment-free experience. We expect everyone in the Budibase community to abide by our [**Code of Conduct**](https://github.com/Budibase/budibase/blob/HEAD/docs/CODE_OF_CONDUCT.md). Please read it.
@@ -171,16 +164,16 @@ Budibase is dedicated to providing a welcoming, diverse, and harrassment-free ex
## 🙌 Contributing to Budibase
-From opening a bug report to creating a pull request: every contribution is appreciated and welcomed. If you're planning to implement a new feature or change the API please create an issue first. This way we can ensure your work is not in vain.
-Environment setup instructions are available for [Debian](https://github.com/Budibase/budibase/tree/HEAD/docs/DEV-SETUP-DEBIAN.md) and [MacOSX](https://github.com/Budibase/budibase/tree/HEAD/docs/DEV-SETUP-MACOSX.md)
+From opening a bug report to creating a pull request: every contribution is appreciated and welcomed. If you're planning to implement a new feature or change the API, please create an issue first. This way, we can ensure your work is not in vain.
+Environment setup instructions are available [here](https://github.com/Budibase/budibase/tree/HEAD/docs/CONTRIBUTING.md).
### Not Sure Where to Start?
-A good place to start contributing, is the [First time issues project](https://github.com/Budibase/budibase/projects/22).
+A good place to start contributing is the [First time issues project](https://github.com/Budibase/budibase/projects/22).
### How the repository is organized
Budibase is a monorepo managed by lerna. Lerna manages the building and publishing of the budibase packages. At a high level, here are the packages that make up Budibase.
-- [packages/builder](https://github.com/Budibase/budibase/tree/HEAD/packages/builder) - contains code for the budibase builder client side svelte application.
+- [packages/builder](https://github.com/Budibase/budibase/tree/HEAD/packages/builder) - contains code for the budibase builder client-side svelte application.
- [packages/client](https://github.com/Budibase/budibase/tree/HEAD/packages/client) - A module that runs in the browser responsible for reading JSON definition and creating living, breathing web apps from it.
@@ -193,7 +186,7 @@ For more information, see [CONTRIBUTING.md](https://github.com/Budibase/budibase
## 📝 License
-Budibase is open-source, licensed as [GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html). The client and component libraries are licensed as [MPL](https://directory.fsf.org/wiki/License:MPL-2.0) - so the apps that you build can be licensed however you like.
+Budibase is open-source, licensed as [GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html). The client and component libraries are licensed as [MPL](https://directory.fsf.org/wiki/License:MPL-2.0) - so the apps you build can be licensed however you like.
diff --git a/docs/DEV-SETUP-DEBIAN.md b/docs/DEV-SETUP-DEBIAN.md
deleted file mode 100644
index e098862c64..0000000000
--- a/docs/DEV-SETUP-DEBIAN.md
+++ /dev/null
@@ -1,76 +0,0 @@
-## Dev Environment on Debian 11
-
-### Install NVM & Node 14
-
-NVM documentation: https://github.com/nvm-sh/nvm#installing-and-updating
-
-Install NVM
-
-```
-curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
-```
-
-Install Node 14
-
-```
-nvm install 14
-```
-
-### Install npm requirements
-
-```
-npm install -g yarn jest lerna
-```
-
-### Install Docker and Docker Compose
-
-```
-apt install docker.io
-pip3 install docker-compose
-```
-
-### Clone the repo
-
-```
-git clone https://github.com/Budibase/budibase.git
-```
-
-### Check Versions
-
-This setup process was tested on Debian 11 (bullseye) with version numbers show below. Your mileage may vary using anything else.
-
-- Docker: 20.10.5
-- Docker-Compose: 1.29.2
-- Node: v14.20.1
-- Yarn: 1.22.19
-- Lerna: 5.1.4
-
-### Build
-
-```
-cd budibase
-yarn setup
-```
-
-The yarn setup command runs several build steps i.e.
-
-```
-node ./hosting/scripts/setup.js && yarn && yarn build && yarn dev
-```
-
-So this command will actually run the application in dev mode. It creates .env files under `./packages/server` and `./packages/worker` and runs docker containers for each service via docker-compose.
-
-The dev version will be available on port 10000 i.e.
-
-http://127.0.0.1:10000/builder/admin
-
-### File descriptor issues with Vite and Chrome in Linux
-
-If your dev environment stalls forever, with some network requests stuck in flight, it's likely that Chrome is trying to open more file descriptors than your system allows.
-To fix this, apply the following tweaks.
-
-Debian based distros:
-Add `* - nofile 65536` to `/etc/security/limits.conf`.
-
-Arch:
-Add `DefaultLimitNOFILE=65536` to `/etc/systemd/system.conf`.
diff --git a/docs/DEV-SETUP-MACOSX.md b/docs/DEV-SETUP-MACOSX.md
deleted file mode 100644
index 0e13d540b3..0000000000
--- a/docs/DEV-SETUP-MACOSX.md
+++ /dev/null
@@ -1,84 +0,0 @@
-## Dev Environment on MAC OSX 12 (Monterey)
-
-### Install Homebrew
-
-Install instructions [here](https://brew.sh/)
-
-| **NOTE**: If you are working on a M1 Apple Silicon which is running Z shell, you could need to add
-`eval $(/opt/homebrew/bin/brew shellenv)` line to your `.zshrc`. This will make your zsh to find the apps you install
-through brew.
-
-### Install Node
-
-Budibase requires a recent version of node 14:
-
-```
-brew install node npm
-node -v
-```
-
-### Install npm requirements
-
-```
-npm install -g yarn jest lerna
-```
-
-### Install Docker and Docker Compose
-
-```
-brew install docker docker-compose
-```
-
-### Clone the repo
-
-```
-git clone https://github.com/Budibase/budibase.git
-```
-
-### Check Versions
-
-This setup process was tested on Mac OSX 12 (Monterey) with version numbers shown below. Your mileage may vary using anything else.
-
-- Docker: 20.10.14
-- Docker-Compose: 2.6.0
-- Node: 14.20.1
-- Yarn: 1.22.19
-- Lerna: 5.1.4
-
-### Build
-
-```
-cd budibase
-yarn setup
-```
-
-The yarn setup command runs several build steps i.e.
-
-```
-node ./hosting/scripts/setup.js && yarn && yarn build && yarn dev
-```
-
-So this command will actually run the application in dev mode. It creates .env files under `./packages/server` and `./packages/worker` and runs docker containers for each service via docker-compose.
-
-The dev version will be available on port 10000 i.e.
-
-http://127.0.0.1:10000/builder/admin
-
-| **NOTE**: If you are working on a M1 Apple Silicon, you will need to uncomment `# platform: linux/amd64` line in
-[hosting/docker-compose-dev.yaml](../hosting/docker-compose.dev.yaml)
-
-### Troubleshootings
-
-#### Yarn setup errors
-
-If there are errors with the `yarn setup` command, you can try installing nvm and node 14. This is the same as the instructions for Debian 11.
-
-#### Node 14.20.1 not supported for arm64
-
-If you are working with M1 or M2 Mac and trying the Node installation via `nvm`, probably you will find the error `curl: (22) The requested URL returned error: 404`.
-
-Version `v14.20.1` is not supported for arm64; in order to use it, you can switch the CPU architecture for this by the following command:
-
-```shell
-arch -x86_64 zsh #Run this before nvm install
-```
diff --git a/docs/DEV-SETUP-WINDOWS.md b/docs/DEV-SETUP-WINDOWS.md
deleted file mode 100644
index f26a5a0882..0000000000
--- a/docs/DEV-SETUP-WINDOWS.md
+++ /dev/null
@@ -1,92 +0,0 @@
-## Dev Environment on Windows 10/11 (WSL2)
-
-### Install WSL with Ubuntu LTS
-
-Enable WSL 2 on Windows 10/11 for docker support.
-
-```
-wsl --set-default-version 2
-```
-
-Install Ubuntu LTS.
-
-```
-wsl --install Ubuntu
-```
-
-Or follow the instruction here:
-https://learn.microsoft.com/en-us/windows/wsl/install
-
-### Install Docker in windows
-
-Download the installer from docker and install it.
-
-Check this url for more detailed instructions:
-https://docs.docker.com/desktop/install/windows-install/
-
-You should follow the next steps from within the Ubuntu terminal.
-
-### Install NVM & Node 14
-
-NVM documentation: https://github.com/nvm-sh/nvm#installing-and-updating
-
-Install NVM
-
-```
-curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
-```
-
-Install Node 14
-
-```
-nvm install 14
-```
-
-### Install npm requirements
-
-```
-npm install -g yarn jest lerna
-```
-
-### Clone the repo
-
-```
-git clone https://github.com/Budibase/budibase.git
-```
-
-### Check Versions
-
-This setup process was tested on Windows 11 with version numbers show below. Your mileage may vary using anything else.
-
-- Docker: 20.10.7
-- Docker-Compose: 2.10.2
-- Node: v14.20.1
-- Yarn: 1.22.19
-- Lerna: 5.5.4
-
-### Build
-
-```
-cd budibase
-yarn setup
-```
-
-The yarn setup command runs several build steps i.e.
-
-```
-node ./hosting/scripts/setup.js && yarn && yarn build && yarn dev
-```
-
-So this command will actually run the application in dev mode. It creates .env files under `./packages/server` and `./packages/worker` and runs docker containers for each service via docker-compose.
-
-The dev version will be available on port 10000 i.e.
-
-http://127.0.0.1:10000/builder/admin
-
-### Working with the code
-
-Here are the instructions to work on the application from within Visual Studio Code (in Windows) through the WSL. All the commands and files are within the Ubuntu system and it should run as if you were working on a Linux machine.
-
-https://code.visualstudio.com/docs/remote/wsl
-
-Note you will be able to run the application from within the WSL terminal and you will be able to access the application from the a browser in Windows.
diff --git a/hosting/single/Dockerfile b/hosting/single/Dockerfile
index 67ac677984..f9044cd124 100644
--- a/hosting/single/Dockerfile
+++ b/hosting/single/Dockerfile
@@ -124,6 +124,8 @@ HEALTHCHECK --interval=15s --timeout=15s --start-period=45s CMD "/healthcheck.sh
# must set this just before running
ENV NODE_ENV=production
+# this is required for isolated-vm to work on Node 20+
+ENV NODE_OPTIONS="--no-node-snapshot"
WORKDIR /
CMD ["./runner.sh"]
diff --git a/i18n/README.es.md b/i18n/README.es.md
index 227d5d5d5f..a7d1112914 100644
--- a/i18n/README.es.md
+++ b/i18n/README.es.md
@@ -207,8 +207,7 @@ Desde comunicar un bug a solventar un error en el codigo, toda contribucion es a
implementar una nueva funcionalidad o un realizar un cambio en la API, por favor crea un [nuevo mensaje aqui](https://github.com/Budibase/budibase/issues),
de esta manera nos encargaremos que tu trabajo no sea en vano.
-Aqui tienes instrucciones de como configurar tu entorno Budibase para [Debian](https://github.com/Budibase/budibase/tree/HEAD/docs/DEV-SETUP-DEBIAN.md)
-y [MacOSX](https://github.com/Budibase/budibase/tree/HEAD/docs/DEV-SETUP-MACOSX.md)
+Aqui tienes instrucciones de como configurar tu entorno Budibase para [aquí](https://github.com/Budibase/budibase/tree/HEAD/docs/CONTRIBUTING.md).
### No estas seguro por donde empezar?
Un buen lugar para empezar a contribuir con nosotros es [aqui](https://github.com/Budibase/budibase/projects/22).
diff --git a/lerna.json b/lerna.json
index 386fbe425a..8938ed4c5f 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
{
- "version": "2.14.4",
+ "version": "2.17.2",
"npmClient": "yarn",
"packages": [
"packages/*",
diff --git a/package.json b/package.json
index 4422f2bd23..4f81d216ad 100644
--- a/package.json
+++ b/package.json
@@ -46,7 +46,7 @@
"kill-accountportal": "kill-port 3001 4003",
"kill-all": "yarn run kill-builder && yarn run kill-server && yarn kill-accountportal",
"dev": "yarn run kill-all && lerna run --parallel prebuild && lerna run --stream dev --ignore=@budibase/account-portal-ui --ignore @budibase/account-portal-server",
- "dev:noserver": "yarn run kill-builder && lerna run --stream dev:stack:up && lerna run --stream dev --ignore @budibase/backend-core --ignore @budibase/server --ignore @budibase/worker --ignore=@budibase/account-portal-ui --ignore @budibase/account-portal-server",
+ "dev:noserver": "yarn run kill-builder && lerna run --stream dev:stack:up --ignore @budibase/account-portal-server && lerna run --stream dev --ignore @budibase/backend-core --ignore @budibase/server --ignore @budibase/worker --ignore=@budibase/account-portal-ui --ignore @budibase/account-portal-server",
"dev:server": "yarn run kill-server && lerna run --stream dev --scope @budibase/worker --scope @budibase/server",
"dev:accountportal": "yarn kill-accountportal && lerna run dev --stream --scope @budibase/account-portal-ui --scope @budibase/account-portal-server",
"dev:all": "yarn run kill-all && lerna run --stream dev",
diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json
index fde478f973..642e7ec8b6 100644
--- a/packages/backend-core/package.json
+++ b/packages/backend-core/package.json
@@ -21,7 +21,7 @@
"test:watch": "jest --watchAll"
},
"dependencies": {
- "@budibase/nano": "10.1.4",
+ "@budibase/nano": "10.1.5",
"@budibase/pouchdb-replication-stream": "1.2.10",
"@budibase/shared-core": "0.0.0",
"@budibase/types": "0.0.0",
@@ -32,7 +32,7 @@
"bcryptjs": "2.4.3",
"bull": "4.10.1",
"correlation-id": "4.0.0",
- "dd-trace": "3.13.2",
+ "dd-trace": "5.0.0",
"dotenv": "16.0.1",
"ioredis": "5.3.2",
"joi": "17.6.0",
@@ -54,7 +54,7 @@
"sanitize-s3-objectkey": "0.0.1",
"semver": "^7.5.4",
"tar-fs": "2.1.1",
- "uuid": "8.3.2"
+ "uuid": "^8.3.2"
},
"devDependencies": {
"@shopify/jest-koa-mocks": "5.1.1",
diff --git a/packages/backend-core/src/context/types.ts b/packages/backend-core/src/context/types.ts
index f73dc9f5c7..cc052ca505 100644
--- a/packages/backend-core/src/context/types.ts
+++ b/packages/backend-core/src/context/types.ts
@@ -1,5 +1,5 @@
import { IdentityContext } from "@budibase/types"
-import { ExecutionTimeTracker } from "../timers"
+import { Isolate, Context, Module } from "isolated-vm"
// keep this out of Budibase types, don't want to expose context info
export type ContextMap = {
@@ -10,5 +10,9 @@ export type ContextMap = {
isScim?: boolean
automationId?: string
isMigrating?: boolean
- jsExecutionTracker?: ExecutionTimeTracker
+ isolateRefs?: {
+ jsIsolate: Isolate
+ jsContext: Context
+ helpersModule: Module
+ }
}
diff --git a/packages/backend-core/src/db/couch/DatabaseImpl.ts b/packages/backend-core/src/db/couch/DatabaseImpl.ts
index 3fec573bb9..0e2b4173b0 100644
--- a/packages/backend-core/src/db/couch/DatabaseImpl.ts
+++ b/packages/backend-core/src/db/couch/DatabaseImpl.ts
@@ -19,6 +19,8 @@ import { WriteStream, ReadStream } from "fs"
import { newid } from "../../docIds/newid"
import { DDInstrumentedDatabase } from "../instrumentation"
+const DATABASE_NOT_FOUND = "Database does not exist."
+
function buildNano(couchInfo: { url: string; cookie: string }) {
return Nano({
url: couchInfo.url,
@@ -31,6 +33,8 @@ function buildNano(couchInfo: { url: string; cookie: string }) {
})
}
+type DBCall = () => Promise
+
export function DatabaseWithConnection(
dbName: string,
connection: string,
@@ -78,7 +82,11 @@ export class DatabaseImpl implements Database {
return this.instanceNano || DatabaseImpl.nano
}
- async checkSetup() {
+ private getDb() {
+ return this.nano().db.use(this.name)
+ }
+
+ private async checkAndCreateDb() {
let shouldCreate = !this.pouchOpts?.skip_setup
// check exists in a lightweight fashion
let exists = await this.exists()
@@ -95,14 +103,22 @@ export class DatabaseImpl implements Database {
}
}
}
- return this.nano().db.use(this.name)
+ return this.getDb()
}
- private async updateOutput(fnc: any) {
+ // this function fetches the DB and handles if DB creation is needed
+ private async performCall(
+ call: (db: Nano.DocumentScope) => Promise> | DBCall
+ ): Promise {
+ const db = this.getDb()
+ const fnc = await call(db)
try {
return await fnc()
} catch (err: any) {
- if (err.statusCode) {
+ if (err.statusCode === 404 && err.reason === DATABASE_NOT_FOUND) {
+ await this.checkAndCreateDb()
+ return await this.performCall(call)
+ } else if (err.statusCode) {
err.status = err.statusCode
}
throw err
@@ -110,11 +126,12 @@ export class DatabaseImpl implements Database {
}
async get(id?: string): Promise {
- const db = await this.checkSetup()
- if (!id) {
- throw new Error("Unable to get doc without a valid _id.")
- }
- return this.updateOutput(() => db.get(id))
+ return this.performCall(db => {
+ if (!id) {
+ throw new Error("Unable to get doc without a valid _id.")
+ }
+ return () => db.get(id)
+ })
}
async getMultiple(
@@ -147,22 +164,23 @@ export class DatabaseImpl implements Database {
}
async remove(idOrDoc: string | Document, rev?: string) {
- const db = await this.checkSetup()
- let _id: string
- let _rev: string
+ return this.performCall(db => {
+ let _id: string
+ let _rev: string
- if (isDocument(idOrDoc)) {
- _id = idOrDoc._id!
- _rev = idOrDoc._rev!
- } else {
- _id = idOrDoc
- _rev = rev!
- }
+ if (isDocument(idOrDoc)) {
+ _id = idOrDoc._id!
+ _rev = idOrDoc._rev!
+ } else {
+ _id = idOrDoc
+ _rev = rev!
+ }
- if (!_id || !_rev) {
- throw new Error("Unable to remove doc without a valid _id and _rev.")
- }
- return this.updateOutput(() => db.destroy(_id, _rev))
+ if (!_id || !_rev) {
+ throw new Error("Unable to remove doc without a valid _id and _rev.")
+ }
+ return () => db.destroy(_id, _rev)
+ })
}
async post(document: AnyDocument, opts?: DatabasePutOpts) {
@@ -176,45 +194,49 @@ export class DatabaseImpl implements Database {
if (!document._id) {
throw new Error("Cannot store document without _id field.")
}
- const db = await this.checkSetup()
- if (!document.createdAt) {
- document.createdAt = new Date().toISOString()
- }
- document.updatedAt = new Date().toISOString()
- if (opts?.force && document._id) {
- try {
- const existing = await this.get(document._id)
- if (existing) {
- document._rev = existing._rev
- }
- } catch (err: any) {
- if (err.status !== 404) {
- throw err
+ return this.performCall(async db => {
+ if (!document.createdAt) {
+ document.createdAt = new Date().toISOString()
+ }
+ document.updatedAt = new Date().toISOString()
+ if (opts?.force && document._id) {
+ try {
+ const existing = await this.get(document._id)
+ if (existing) {
+ document._rev = existing._rev
+ }
+ } catch (err: any) {
+ if (err.status !== 404) {
+ throw err
+ }
}
}
- }
- return this.updateOutput(() => db.insert(document))
+ return () => db.insert(document)
+ })
}
async bulkDocs(documents: AnyDocument[]) {
- const db = await this.checkSetup()
- return this.updateOutput(() => db.bulk({ docs: documents }))
+ return this.performCall(db => {
+ return () => db.bulk({ docs: documents })
+ })
}
async allDocs(
params: DatabaseQueryOpts
): Promise> {
- const db = await this.checkSetup()
- return this.updateOutput(() => db.list(params))
+ return this.performCall(db => {
+ return () => db.list(params)
+ })
}
async query(
viewName: string,
params: DatabaseQueryOpts
): Promise> {
- const db = await this.checkSetup()
- const [database, view] = viewName.split("/")
- return this.updateOutput(() => db.view(database, view, params))
+ return this.performCall(db => {
+ const [database, view] = viewName.split("/")
+ return () => db.view(database, view, params)
+ })
}
async destroy() {
@@ -231,8 +253,9 @@ export class DatabaseImpl implements Database {
}
async compact() {
- const db = await this.checkSetup()
- return this.updateOutput(() => db.compact())
+ return this.performCall(db => {
+ return () => db.compact()
+ })
}
// All below functions are in-frequently called, just utilise PouchDB
diff --git a/packages/backend-core/src/db/instrumentation.ts b/packages/backend-core/src/db/instrumentation.ts
index ba5febcba6..aa2ac424ae 100644
--- a/packages/backend-core/src/db/instrumentation.ts
+++ b/packages/backend-core/src/db/instrumentation.ts
@@ -31,13 +31,6 @@ export class DDInstrumentedDatabase implements Database {
})
}
- checkSetup(): Promise> {
- return tracer.trace("db.checkSetup", span => {
- span?.addTags({ db_name: this.name })
- return this.db.checkSetup()
- })
- }
-
get(id?: string | undefined): Promise {
return tracer.trace("db.get", span => {
span?.addTags({ db_name: this.name, doc_id: id })
diff --git a/packages/backend-core/src/environment.ts b/packages/backend-core/src/environment.ts
index 0fec786c31..b3179cbeea 100644
--- a/packages/backend-core/src/environment.ts
+++ b/packages/backend-core/src/environment.ts
@@ -179,6 +179,7 @@ const environment = {
...getPackageJsonFields(),
DISABLE_PINO_LOGGER: process.env.DISABLE_PINO_LOGGER,
OFFLINE_MODE: process.env.OFFLINE_MODE,
+ SESSION_EXPIRY_SECONDS: process.env.SESSION_EXPIRY_SECONDS,
_set(key: any, value: any) {
process.env[key] = value
// @ts-ignore
diff --git a/packages/backend-core/src/index.ts b/packages/backend-core/src/index.ts
index 7bf26f3688..8001017092 100644
--- a/packages/backend-core/src/index.ts
+++ b/packages/backend-core/src/index.ts
@@ -2,6 +2,7 @@ export * as configs from "./configs"
export * as events from "./events"
export * as migrations from "./migrations"
export * as users from "./users"
+export * as userUtils from "./users/utils"
export * as roles from "./security/roles"
export * as permissions from "./security/permissions"
export * as accounts from "./accounts"
diff --git a/packages/backend-core/src/objectStore/cloudfront.ts b/packages/backend-core/src/objectStore/cloudfront.ts
index 866fe9e880..3bca97d11e 100644
--- a/packages/backend-core/src/objectStore/cloudfront.ts
+++ b/packages/backend-core/src/objectStore/cloudfront.ts
@@ -23,7 +23,7 @@ const getCloudfrontSignParams = () => {
return {
keypairId: env.CLOUDFRONT_PUBLIC_KEY_ID!,
privateKeyString: getPrivateKey(),
- expireTime: new Date().getTime() + 1000 * 60 * 60, // 1 hour
+ expireTime: new Date().getTime() + 1000 * 60 * 60 * 24, // 1 day
}
}
diff --git a/packages/backend-core/src/objectStore/objectStore.ts b/packages/backend-core/src/objectStore/objectStore.ts
index 57ead0e809..3a3b9cdaab 100644
--- a/packages/backend-core/src/objectStore/objectStore.ts
+++ b/packages/backend-core/src/objectStore/objectStore.ts
@@ -7,7 +7,7 @@ import tar from "tar-fs"
import zlib from "zlib"
import { promisify } from "util"
import { join } from "path"
-import fs from "fs"
+import fs, { ReadStream } from "fs"
import env from "../environment"
import { budibaseTempDir } from "./utils"
import { v4 } from "uuid"
@@ -184,7 +184,7 @@ export async function upload({
export async function streamUpload(
bucketName: string,
filename: string,
- stream: any,
+ stream: ReadStream | ReadableStream,
extra = {}
) {
const objectStore = ObjectStore(bucketName)
diff --git a/packages/backend-core/src/security/sessions.ts b/packages/backend-core/src/security/sessions.ts
index a86a829b17..8d7b43d5b6 100644
--- a/packages/backend-core/src/security/sessions.ts
+++ b/packages/backend-core/src/security/sessions.ts
@@ -1,8 +1,8 @@
-const redis = require("../redis/init")
-const { v4: uuidv4 } = require("uuid")
-const { logWarn } = require("../logging")
-
+import * as redis from "../redis/init"
+import { v4 as uuidv4 } from "uuid"
+import { logWarn } from "../logging"
import env from "../environment"
+import { Duration } from "../utils"
import {
Session,
ScannedSession,
@@ -10,8 +10,10 @@ import {
CreateSession,
} from "@budibase/types"
-// a week in seconds
-const EXPIRY_SECONDS = 86400 * 7
+// a week expiry is the default
+const EXPIRY_SECONDS = env.SESSION_EXPIRY_SECONDS
+ ? parseInt(env.SESSION_EXPIRY_SECONDS)
+ : Duration.fromDays(7).toSeconds()
function makeSessionID(userId: string, sessionId: string) {
return `${userId}/${sessionId}`
diff --git a/packages/backend-core/src/timers/timers.ts b/packages/backend-core/src/timers/timers.ts
index 9121c576cd..000be74821 100644
--- a/packages/backend-core/src/timers/timers.ts
+++ b/packages/backend-core/src/timers/timers.ts
@@ -20,41 +20,3 @@ export function cleanup() {
}
intervals = []
}
-
-export class ExecutionTimeoutError extends Error {
- public readonly name = "ExecutionTimeoutError"
-}
-
-export class ExecutionTimeTracker {
- static withLimit(limitMs: number) {
- return new ExecutionTimeTracker(limitMs)
- }
-
- constructor(readonly limitMs: number) {}
-
- private totalTimeMs = 0
-
- track(f: () => T): T {
- this.checkLimit()
- const start = process.hrtime.bigint()
- try {
- return f()
- } finally {
- const end = process.hrtime.bigint()
- this.totalTimeMs += Number(end - start) / 1e6
- this.checkLimit()
- }
- }
-
- get elapsedMS() {
- return this.totalTimeMs
- }
-
- checkLimit() {
- if (this.totalTimeMs > this.limitMs) {
- throw new ExecutionTimeoutError(
- `Execution time limit of ${this.limitMs}ms exceeded: ${this.totalTimeMs}ms`
- )
- }
- }
-}
diff --git a/packages/backend-core/src/users/db.ts b/packages/backend-core/src/users/db.ts
index 4d0d216603..136cb4b8ad 100644
--- a/packages/backend-core/src/users/db.ts
+++ b/packages/backend-core/src/users/db.ts
@@ -251,7 +251,8 @@ export class UserDB {
}
const change = dbUser ? 0 : 1 // no change if there is existing user
- const creatorsChange = isCreator(dbUser) !== isCreator(user) ? 1 : 0
+ const creatorsChange =
+ (await isCreator(dbUser)) !== (await isCreator(user)) ? 1 : 0
return UserDB.quotas.addUsers(change, creatorsChange, async () => {
await validateUniqueUser(email, tenantId)
@@ -335,7 +336,7 @@ export class UserDB {
}
newUser.userGroups = groups || []
newUsers.push(newUser)
- if (isCreator(newUser)) {
+ if (await isCreator(newUser)) {
newCreators.push(newUser)
}
}
@@ -432,12 +433,16 @@ export class UserDB {
_deleted: true,
}))
const dbResponse = await usersCore.bulkUpdateGlobalUsers(toDelete)
- const creatorsToDelete = usersToDelete.filter(isCreator)
+
+ const creatorsEval = await Promise.all(usersToDelete.map(isCreator))
+ const creatorsToDeleteCount = creatorsEval.filter(
+ creator => !!creator
+ ).length
for (let user of usersToDelete) {
await bulkDeleteProcessing(user)
}
- await UserDB.quotas.removeUsers(toDelete.length, creatorsToDelete.length)
+ await UserDB.quotas.removeUsers(toDelete.length, creatorsToDeleteCount)
// Build Response
// index users by id
@@ -486,7 +491,7 @@ export class UserDB {
await db.remove(userId, dbUser._rev)
- const creatorsToDelete = isCreator(dbUser) ? 1 : 0
+ const creatorsToDelete = (await isCreator(dbUser)) ? 1 : 0
await UserDB.quotas.removeUsers(1, creatorsToDelete)
await eventHelpers.handleDeleteEvents(dbUser)
await cache.user.invalidateUser(userId)
diff --git a/packages/backend-core/src/users/test/utils.spec.ts b/packages/backend-core/src/users/test/utils.spec.ts
new file mode 100644
index 0000000000..0fe27f57a6
--- /dev/null
+++ b/packages/backend-core/src/users/test/utils.spec.ts
@@ -0,0 +1,67 @@
+import { User, UserGroup } from "@budibase/types"
+import { generator, structures } from "../../../tests"
+import { DBTestConfiguration } from "../../../tests/extra"
+import { getGlobalDB } from "../../context"
+import { isCreator } from "../utils"
+
+const config = new DBTestConfiguration()
+
+describe("Users", () => {
+ it("User is a creator if it is configured as a global builder", async () => {
+ const user: User = structures.users.user({ builder: { global: true } })
+ expect(await isCreator(user)).toBe(true)
+ })
+
+ it("User is a creator if it is configured as a global admin", async () => {
+ const user: User = structures.users.user({ admin: { global: true } })
+ expect(await isCreator(user)).toBe(true)
+ })
+
+ it("User is a creator if it is configured with creator permission", async () => {
+ const user: User = structures.users.user({ builder: { creator: true } })
+ expect(await isCreator(user)).toBe(true)
+ })
+
+ it("User is a creator if it is a builder in some application", async () => {
+ const user: User = structures.users.user({ builder: { apps: ["app1"] } })
+ expect(await isCreator(user)).toBe(true)
+ })
+
+ it("User is a creator if it has CREATOR permission in some application", async () => {
+ const user: User = structures.users.user({ roles: { app1: "CREATOR" } })
+ expect(await isCreator(user)).toBe(true)
+ })
+
+ it("User is a creator if it has ADMIN permission in some application", async () => {
+ const user: User = structures.users.user({ roles: { app1: "ADMIN" } })
+ expect(await isCreator(user)).toBe(true)
+ })
+
+ it("User is a creator if it remains to a group with ADMIN permissions", async () => {
+ const usersInGroup = 10
+ const groupId = "gr_17abffe89e0b40268e755b952f101a59"
+ const group: UserGroup = {
+ ...structures.userGroups.userGroup(),
+ ...{ _id: groupId, roles: { app1: "ADMIN" } },
+ }
+ const users: User[] = []
+ for (const _ of Array.from({ length: usersInGroup })) {
+ const userId = `us_${generator.guid()}`
+ const user: User = structures.users.user({
+ _id: userId,
+ userGroups: [groupId],
+ })
+ users.push(user)
+ }
+
+ await config.doInTenant(async () => {
+ const db = getGlobalDB()
+ await db.put(group)
+ for (let user of users) {
+ await db.put(user)
+ const creator = await isCreator(user)
+ expect(creator).toBe(true)
+ }
+ })
+ })
+})
diff --git a/packages/backend-core/src/users/users.ts b/packages/backend-core/src/users/users.ts
index cc2b4fc27f..638da4a5b1 100644
--- a/packages/backend-core/src/users/users.ts
+++ b/packages/backend-core/src/users/users.ts
@@ -309,7 +309,8 @@ export async function getCreatorCount() {
let creators = 0
async function iterate(startPage?: string) {
const page = await paginatedUsers({ bookmark: startPage })
- creators += page.data.filter(isCreator).length
+ const creatorsEval = await Promise.all(page.data.map(isCreator))
+ creators += creatorsEval.filter(creator => !!creator).length
if (page.hasNextPage) {
await iterate(page.nextPage)
}
diff --git a/packages/backend-core/src/users/utils.ts b/packages/backend-core/src/users/utils.ts
index 0ef4b77998..348ad1532f 100644
--- a/packages/backend-core/src/users/utils.ts
+++ b/packages/backend-core/src/users/utils.ts
@@ -1,4 +1,4 @@
-import { CloudAccount } from "@budibase/types"
+import { CloudAccount, ContextUser, User, UserGroup } from "@budibase/types"
import * as accountSdk from "../accounts"
import env from "../environment"
import { getPlatformUser } from "./lookup"
@@ -6,17 +6,48 @@ import { EmailUnavailableError } from "../errors"
import { getTenantId } from "../context"
import { sdk } from "@budibase/shared-core"
import { getAccountByTenantId } from "../accounts"
+import { BUILTIN_ROLE_IDS } from "../security/roles"
+import * as context from "../context"
// extract from shared-core to make easily accessible from backend-core
export const isBuilder = sdk.users.isBuilder
export const isAdmin = sdk.users.isAdmin
-export const isCreator = sdk.users.isCreator
export const isGlobalBuilder = sdk.users.isGlobalBuilder
export const isAdminOrBuilder = sdk.users.isAdminOrBuilder
export const hasAdminPermissions = sdk.users.hasAdminPermissions
export const hasBuilderPermissions = sdk.users.hasBuilderPermissions
export const hasAppBuilderPermissions = sdk.users.hasAppBuilderPermissions
+export async function isCreator(user?: User | ContextUser) {
+ const isCreatorByUserDefinition = sdk.users.isCreator(user)
+ if (!isCreatorByUserDefinition && user) {
+ return await isCreatorByGroupMembership(user)
+ }
+ return isCreatorByUserDefinition
+}
+
+async function isCreatorByGroupMembership(user?: User | ContextUser) {
+ const userGroups = user?.userGroups || []
+ if (userGroups.length > 0) {
+ const db = context.getGlobalDB()
+ const groups: UserGroup[] = []
+ for (let groupId of userGroups) {
+ try {
+ const group = await db.get(groupId)
+ groups.push(group)
+ } catch (e: any) {
+ if (e.error !== "not_found") {
+ throw e
+ }
+ }
+ }
+ return groups.some(group =>
+ Object.values(group.roles || {}).includes(BUILTIN_ROLE_IDS.ADMIN)
+ )
+ }
+ return false
+}
+
export async function validateUniqueUser(email: string, tenantId: string) {
// check budibase users in other tenants
if (env.MULTI_TENANCY) {
diff --git a/packages/bbui/src/Actions/position_dropdown.js b/packages/bbui/src/Actions/position_dropdown.js
index f2018272f6..cc169eac09 100644
--- a/packages/bbui/src/Actions/position_dropdown.js
+++ b/packages/bbui/src/Actions/position_dropdown.js
@@ -18,7 +18,6 @@ export default function positionDropdown(element, opts) {
useAnchorWidth,
offset = 5,
customUpdate,
- offsetBelow,
} = opts
if (!anchor) {
return
@@ -48,7 +47,7 @@ export default function positionDropdown(element, opts) {
styles.top = anchorBounds.top - elementBounds.height - offset
styles.maxHeight = maxHeight || 240
} else {
- styles.top = anchorBounds.bottom + (offsetBelow || offset)
+ styles.top = anchorBounds.bottom + offset
styles.maxHeight =
maxHeight || window.innerHeight - anchorBounds.bottom - 20
}
diff --git a/packages/bbui/src/Form/Core/EnvDropdown.svelte b/packages/bbui/src/Form/Core/EnvDropdown.svelte
index 2edf8a5f9d..c690ffbc6b 100644
--- a/packages/bbui/src/Form/Core/EnvDropdown.svelte
+++ b/packages/bbui/src/Form/Core/EnvDropdown.svelte
@@ -184,7 +184,7 @@
{#if environmentVariablesEnabled}