mirror of https://github.com/Budibase/budibase.git
539 changed files with 20240 additions and 8778 deletions
@ -1,76 +0,0 @@ |
|||
# Contributor Covenant Code of Conduct |
|||
|
|||
## Our Pledge |
|||
|
|||
In the interest of fostering an open and welcoming environment, we as |
|||
contributors and maintainers pledge to making participation in our project and |
|||
our community a harassment-free experience for everyone, regardless of age, body |
|||
size, disability, ethnicity, sex characteristics, gender identity and expression, |
|||
level of experience, education, socio-economic status, nationality, personal |
|||
appearance, race, religion, or sexual identity and orientation. |
|||
|
|||
## Our Standards |
|||
|
|||
Examples of behavior that contributes to creating a positive environment |
|||
include: |
|||
|
|||
* Using welcoming and inclusive language |
|||
* Being respectful of differing viewpoints and experiences |
|||
* Gracefully accepting constructive criticism |
|||
* Focusing on what is best for the community |
|||
* Showing empathy towards other community members |
|||
|
|||
Examples of unacceptable behavior by participants include: |
|||
|
|||
* The use of sexualized language or imagery and unwelcome sexual attention or |
|||
advances |
|||
* Trolling, insulting/derogatory comments, and personal or political attacks |
|||
* Public or private harassment |
|||
* Publishing others' private information, such as a physical or electronic |
|||
address, without explicit permission |
|||
* Other conduct which could reasonably be considered inappropriate in a |
|||
professional setting |
|||
|
|||
## Our Responsibilities |
|||
|
|||
Project maintainers are responsible for clarifying the standards of acceptable |
|||
behavior and are expected to take appropriate and fair corrective action in |
|||
response to any instances of unacceptable behavior. |
|||
|
|||
Project maintainers have the right and responsibility to remove, edit, or |
|||
reject comments, commits, code, wiki edits, issues, and other contributions |
|||
that are not aligned to this Code of Conduct, or to ban temporarily or |
|||
permanently any contributor for other behaviors that they deem inappropriate, |
|||
threatening, offensive, or harmful. |
|||
|
|||
## Scope |
|||
|
|||
This Code of Conduct applies both within project spaces and in public spaces |
|||
when an individual is representing the project or its community. Examples of |
|||
representing a project or community include using an official project e-mail |
|||
address, posting via an official social media account, or acting as an appointed |
|||
representative at an online or offline event. Representation of a project may be |
|||
further defined and clarified by project maintainers. |
|||
|
|||
## Enforcement |
|||
|
|||
Instances of abusive, harassing, or otherwise unacceptable behavior may be |
|||
reported by contacting the project team at community@budibase.com. All |
|||
complaints will be reviewed and investigated and will result in a response that |
|||
is deemed necessary and appropriate to the circumstances. The project team is |
|||
obligated to maintain confidentiality with regard to the reporter of an incident. |
|||
Further details of specific enforcement policies may be posted separately. |
|||
|
|||
Project maintainers who do not follow or enforce the Code of Conduct in good |
|||
faith may face temporary or permanent repercussions as determined by other |
|||
members of the project's leadership. |
|||
|
|||
## Attribution |
|||
|
|||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, |
|||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html |
|||
|
|||
[homepage]: https://www.contributor-covenant.org |
|||
|
|||
For answers to common questions about this code of conduct, see |
|||
https://www.contributor-covenant.org/faq |
|||
@ -0,0 +1 @@ |
|||
../docs/CODE_OF_CONDUCT.md |
|||
@ -1,208 +0,0 @@ |
|||
# Contributing |
|||
|
|||
From opening a bug report to creating a pull request: every contribution is appreciated and welcome. If you're planning to implement a new feature or change the api please create an issue first. This way we can ensure that your precious work is not in vain. |
|||
|
|||
## Not Sure Where to Start? |
|||
|
|||
Budibase is a low-code web application builder that creates svelte based web applications. |
|||
|
|||
Budibase is a monorepo managed by [lerna](https://github.com/lerna/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** - contains code for the budibase builder client side svelte application. |
|||
|
|||
- **packages/client** - A module that runs in the browser responsible for reading JSON definition and creating living, breathing web apps from it. |
|||
|
|||
- **packages/server** - The budibase server. This [Koa](https://koajs.com/) app is responsible for serving the JS for the builder and budibase apps, as well as providing the API for interaction with the database and file system. |
|||
|
|||
- **packages/worker** - This [Koa](https://koajs.com/) app is responsible for providing global apis for managing your budibase installation. Authentication, Users, Email, Org and Auth configs are all provided by the worker. |
|||
|
|||
## Contributor License Agreement (CLA) |
|||
|
|||
In order to accept your pull request, we need you to submit a CLA. You only need to do this once. If you are submitting a pull request for the first time, just submit a Pull Request and our CLA Bot will give you instructions on how to sign the CLA before merging your Pull Request. |
|||
|
|||
All contributors must sign an [Individual Contributor License Agreement](https://github.com/budibase/budibase/blob/next/.github/cla/individual-cla.md). |
|||
|
|||
If contributing on behalf of your company, your company must sign a [Corporate Contributor License Agreement](https://github.com/budibase/budibase/blob/next/.github/cla/corporate-cla.md). If so, please contact us via community@budibase.com. |
|||
|
|||
## Glossary of Terms |
|||
|
|||
To understand the budibase API, it can be helpful to understand the top level entities that make up Budibase. |
|||
|
|||
### Client |
|||
|
|||
A client represents a single budibase customer. Each budibase client will have 1 or more budibase servers. Every client is assigned a unique ID. |
|||
|
|||
### App |
|||
|
|||
A client can have one or more budibase applications. Budibase applications would be things like "Developer Inventory Management" or "Goat Herder CRM". Think of a budibase application as a tree. |
|||
|
|||
### Database |
|||
|
|||
An App can have one or more databases. Keeping with our [dendrology](https://en.wikipedia.org/wiki/Dendrology) analogy - think of an database as a branch on the tree. Databases are used to keep data separate for different instances of your app. For example, if you had a CRM app, you may create a database for your US office, and a database for your Australian office. Databases allow us to support [multitenancy](https://www.gartner.com/en/information-technology/glossary/multitenancy) in budibase applications. |
|||
|
|||
### Table |
|||
|
|||
Tables in budibase are almost akin to tables in relational databases. A table may be a "Car" or an "Employee". They are the main building blocks for the creation and management of backend data in budibase. |
|||
|
|||
### View |
|||
|
|||
A View is an advanced feature in budibase that allows you to write a custom query using [MapReduce](https://pouchdb.com/guides/queries.html) queries. Views enable powerful query functionality and calculations, allowing you to do more with your data. |
|||
|
|||
### Page |
|||
|
|||
A page in budibase is actually a single, self contained svelte web app. There are only 2 pages in budibase. The **login** page and the **main** page. |
|||
|
|||
### Screen |
|||
|
|||
A screen is a component within a single page. Generally, screens represent client side routes, and can be switched without refreshing the page. |
|||
|
|||
### Component |
|||
|
|||
A component is the basic frontend building block of a budibase app. |
|||
|
|||
### Component Library |
|||
|
|||
Component libraries are collections of components as well as the definition of their props contained in a file called `components.json`. |
|||
|
|||
## Contributing to Budibase |
|||
|
|||
* Please maintain the existing code style. |
|||
|
|||
* Please try to keep your commits small and focused. |
|||
|
|||
* Please write tests. |
|||
|
|||
* If the project diverges from your branch, please rebase instead of merging. This makes the commit graph easier to read. |
|||
|
|||
* Once your work is completed, please raise a PR against the `develop` branch with some information about what has changed and why. |
|||
|
|||
### Getting Started For Contributors |
|||
#### 1. Prerequisites |
|||
|
|||
NodeJS Version `14.x.x` |
|||
|
|||
*yarn -* `npm install -g yarn` |
|||
|
|||
*jest* - `npm install -g jest` |
|||
|
|||
#### 2. Clone this repository |
|||
|
|||
`git clone https://github.com/Budibase/budibase.git` |
|||
|
|||
then `cd ` into your local copy. |
|||
|
|||
#### 3. Install and Build |
|||
|
|||
| **NOTE**: On Windows, all yarn commands must be executed on a bash shell (e.g. git bash) |
|||
|
|||
To develop the Budibase platform you'll need [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) installed. |
|||
|
|||
##### Quick method |
|||
|
|||
`yarn setup` will check that all necessary components are installed and setup the repo for usage. |
|||
|
|||
##### Manual method |
|||
|
|||
The following commands can be executed to manually get Budibase up and running (assuming Docker/Docker Compose has been installed). |
|||
|
|||
`yarn` to install project dependencies |
|||
|
|||
`yarn bootstrap` will install all budibase modules and symlink them together using lerna. |
|||
|
|||
`yarn build` will build all budibase packages. |
|||
|
|||
#### 4. Running |
|||
|
|||
To run the budibase server and builder in dev mode (i.e. with live reloading): |
|||
|
|||
1. Open a new console |
|||
2. `yarn dev` (from root) |
|||
3. Access the builder on http://localhost:10000/builder |
|||
|
|||
This will enable watch mode for both the builder app, server, client library and any component libraries. |
|||
|
|||
#### 5. Debugging using VS Code |
|||
|
|||
To debug the budibase server and worker a VS Code launch configuration has been provided. |
|||
|
|||
Visit the debug window and select `Budibase Server` or `Budibase Worker` to debug the respective component. |
|||
Alternatively to start both components simultaneously select `Start Budibase`. |
|||
|
|||
In addition to the above, the remaining budibase components may be ran in dev mode using: `yarn dev:noserver`. |
|||
|
|||
#### 6. Cleanup |
|||
|
|||
If you wish to delete all the apps created in development and reset the environment then run the following: |
|||
|
|||
1. `yarn nuke:docker` will wipe all the Budibase services |
|||
2. `yarn dev` will restart all the services |
|||
|
|||
### Backend |
|||
|
|||
For the backend we run [Redis](https://redis.io/), [CouchDB](https://couchdb.apache.org/), [MinIO](https://min.io/) and [NGINX](https://www.nginx.com/) in Docker compose. This means that to develop Budibase you will need Docker and Docker compose installed. The backend services are then ran separately as Node services with nodemon so that they can be debugged outside of Docker. |
|||
|
|||
### Data Storage |
|||
|
|||
When you are running locally, budibase stores data on disk using docker volumes. The volumes and the types of data associated with each are: |
|||
|
|||
- `redis_data` |
|||
- Sessions, email tokens |
|||
- `couchdb3_data` |
|||
- Global and app databases |
|||
- `minio_data` |
|||
- App manifest, budibase client, static assets |
|||
|
|||
### Devlopment Modes |
|||
|
|||
A combination of environment variables controls the mode that budibase runs in. |
|||
Yarn commands can be used to mimic the different modes that budibase can be ran in |
|||
|
|||
#### Self Hosted |
|||
The default mode. A single tenant installation with no usage restrictions. |
|||
|
|||
To enable this mode, use: |
|||
``` |
|||
yarn mode:self |
|||
``` |
|||
|
|||
#### Cloud |
|||
The cloud mode, with account portal turned off. |
|||
|
|||
To enable this mode, use: |
|||
``` |
|||
yarn mode:cloud |
|||
``` |
|||
#### Cloud & Account |
|||
The cloud mode, with account portal turned on. This is a replica of the mode that runs at https://budibase.app |
|||
|
|||
|
|||
To enable this mode, use: |
|||
``` |
|||
yarn mode:account |
|||
``` |
|||
### CI |
|||
An overview of the CI pipelines can be found [here](./workflows/README.md) |
|||
### Troubleshooting |
|||
|
|||
Sometimes, things go wrong. This can be due to incompatible updates on the budibase platform. To clear down your development environment and start again follow **Step 6. Cleanup**, then proceed from **Step 3. Install and Build** in the setup guide above. You should have a fresh Budibase installation. |
|||
### Running tests |
|||
|
|||
#### End-to-end Tests |
|||
|
|||
Budibase uses Cypress to run a number of E2E tests. To run the tests execute the following command in the root folder: |
|||
|
|||
``` |
|||
yarn test:e2e |
|||
``` |
|||
|
|||
Or if you are in the builder you can run `yarn cy:test`. |
|||
|
|||
|
|||
### Other Useful Information |
|||
|
|||
* The contributors are listed in [AUTHORS.md](https://github.com/Budibase/budibase/blob/master/.github/AUTHORS.md) (add yourself). |
|||
|
|||
* This project uses a modified version of the MPLv2 license, see [LICENSE](https://github.com/budibase/server/blob/master/LICENSE). |
|||
|
|||
* We use the [C4 (Collective Code Construction Contract)](https://rfc.zeromq.org/spec:42/C4/) process for contributions. |
|||
Please read this if you are unfamiliar with it. |
|||
@ -0,0 +1 @@ |
|||
../docs/CONTRIBUTING.md |
|||
@ -0,0 +1,77 @@ |
|||
name: Budibase Deploy Release |
|||
|
|||
on: |
|||
workflow_dispatch: |
|||
|
|||
jobs: |
|||
release: |
|||
runs-on: ubuntu-latest |
|||
|
|||
steps: |
|||
- uses: actions/checkout@v2 |
|||
|
|||
- name: Configure AWS Credentials |
|||
uses: aws-actions/configure-aws-credentials@v1 |
|||
with: |
|||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
|||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
|||
aws-region: eu-west-1 |
|||
|
|||
- name: Fail if branch is not develop |
|||
if: github.ref != 'refs/heads/develop' |
|||
run: | |
|||
echo "Ref is not develop, you must run this job from develop." |
|||
exit 1 |
|||
|
|||
- name: Get the latest budibase release version |
|||
id: version |
|||
run: | |
|||
release_version=$(cat lerna.json | jq -r '.version') |
|||
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV |
|||
|
|||
- name: Tag and release Proxy service docker image |
|||
run: | |
|||
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD |
|||
yarn build:docker:proxy:release |
|||
docker tag proxy-service budibase/proxy:$RELEASE_TAG |
|||
docker push budibase/proxy:$RELEASE_TAG |
|||
env: |
|||
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }} |
|||
DOCKER_PASSWORD: ${{ secrets.DOCKER_API_KEY }} |
|||
RELEASE_TAG: k8s-release |
|||
|
|||
- name: Pull values.yaml from budibase-infra |
|||
run: | |
|||
curl -H "Authorization: token ${{ secrets.GH_PERSONAL_TOKEN }}" \ |
|||
-H 'Accept: application/vnd.github.v3.raw' \ |
|||
-o values.release.yaml \ |
|||
-L https://api.github.com/repos/budibase/budibase-infra/contents/kubernetes/budibase-release/values.yaml |
|||
wc -l values.release.yaml |
|||
|
|||
- name: Deploy to Release Environment |
|||
uses: glopezep/helm@v1.7.1 |
|||
with: |
|||
release: budibase-release |
|||
namespace: budibase |
|||
chart: charts/budibase |
|||
token: ${{ github.token }} |
|||
helm: helm3 |
|||
values: | |
|||
globals: |
|||
appVersion: develop |
|||
ingress: |
|||
enabled: true |
|||
nginx: true |
|||
value-files: >- |
|||
[ |
|||
"values.release.yaml" |
|||
] |
|||
env: |
|||
KUBECONFIG_FILE: '${{ secrets.RELEASE_KUBECONFIG }}' |
|||
|
|||
- name: Discord Webhook Action |
|||
uses: tsickert/discord-webhook@v4.0.0 |
|||
with: |
|||
webhook-url: ${{ secrets.PROD_DEPLOY_WEBHOOK_URL }} |
|||
content: "Release Env Deployment Complete: ${{ env.RELEASE_VERSION }} deployed to Budibase Release Env." |
|||
embed-title: ${{ env.RELEASE_VERSION }} |
|||
@ -0,0 +1,76 @@ |
|||
# Contributor Covenant Code of Conduct |
|||
|
|||
## Our Pledge |
|||
|
|||
In the interest of fostering an open and welcoming environment, we as |
|||
contributors and maintainers pledge to making participation in our project and |
|||
our community a harassment-free experience for everyone, regardless of age, body |
|||
size, disability, ethnicity, sex characteristics, gender identity and expression, |
|||
level of experience, education, socio-economic status, nationality, personal |
|||
appearance, race, religion, or sexual identity and orientation. |
|||
|
|||
## Our Standards |
|||
|
|||
Examples of behavior that contributes to creating a positive environment |
|||
include: |
|||
|
|||
* Using welcoming and inclusive language |
|||
* Being respectful of differing viewpoints and experiences |
|||
* Gracefully accepting constructive criticism |
|||
* Focusing on what is best for the community |
|||
* Showing empathy towards other community members |
|||
|
|||
Examples of unacceptable behavior by participants include: |
|||
|
|||
* The use of sexualized language or imagery and unwelcome sexual attention or |
|||
advances |
|||
* Trolling, insulting/derogatory comments, and personal or political attacks |
|||
* Public or private harassment |
|||
* Publishing others' private information, such as a physical or electronic |
|||
address, without explicit permission |
|||
* Other conduct which could reasonably be considered inappropriate in a |
|||
professional setting |
|||
|
|||
## Our Responsibilities |
|||
|
|||
Project maintainers are responsible for clarifying the standards of acceptable |
|||
behavior and are expected to take appropriate and fair corrective action in |
|||
response to any instances of unacceptable behavior. |
|||
|
|||
Project maintainers have the right and responsibility to remove, edit, or |
|||
reject comments, commits, code, wiki edits, issues, and other contributions |
|||
that are not aligned to this Code of Conduct, or to ban temporarily or |
|||
permanently any contributor for other behaviors that they deem inappropriate, |
|||
threatening, offensive, or harmful. |
|||
|
|||
## Scope |
|||
|
|||
This Code of Conduct applies both within project spaces and in public spaces |
|||
when an individual is representing the project or its community. Examples of |
|||
representing a project or community include using an official project e-mail |
|||
address, posting via an official social media account, or acting as an appointed |
|||
representative at an online or offline event. Representation of a project may be |
|||
further defined and clarified by project maintainers. |
|||
|
|||
## Enforcement |
|||
|
|||
Instances of abusive, harassing, or otherwise unacceptable behavior may be |
|||
reported by contacting the project team at community@budibase.com. All |
|||
complaints will be reviewed and investigated and will result in a response that |
|||
is deemed necessary and appropriate to the circumstances. The project team is |
|||
obligated to maintain confidentiality with regard to the reporter of an incident. |
|||
Further details of specific enforcement policies may be posted separately. |
|||
|
|||
Project maintainers who do not follow or enforce the Code of Conduct in good |
|||
faith may face temporary or permanent repercussions as determined by other |
|||
members of the project's leadership. |
|||
|
|||
## Attribution |
|||
|
|||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, |
|||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html |
|||
|
|||
[homepage]: https://www.contributor-covenant.org |
|||
|
|||
For answers to common questions about this code of conduct, see |
|||
https://www.contributor-covenant.org/faq |
|||
@ -0,0 +1,231 @@ |
|||
# Contributing |
|||
|
|||
From opening a bug report to creating a pull request: every contribution is appreciated and welcome. If you're planning to implement a new feature or change the api please [create an issue](https://github.com/Budibase/budibase/issues/new/choose) first. This way we can ensure that your precious work is not in vain. |
|||
|
|||
## Table of contents |
|||
|
|||
- [Quick start](#quick-start) |
|||
- [Status](#status) |
|||
- [What's included](#whats-included) |
|||
- [Bugs and feature requests](#bugs-and-feature-requests) |
|||
|
|||
|
|||
## Not Sure Where to Start? |
|||
|
|||
Budibase is a low-code web application builder that creates svelte-based web applications. |
|||
|
|||
Budibase is a monorepo managed by [lerna](https://github.com/lerna/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** - contains code for the budibase builder client side svelte application. |
|||
|
|||
- **packages/client** - A module that runs in the browser responsible for reading JSON definition and creating living, breathing web apps from it. |
|||
|
|||
- **packages/server** - The budibase server. This [Koa](https://koajs.com/) app is responsible for serving the JS for the builder and budibase apps, as well as providing the API for interaction with the database and file system. |
|||
|
|||
- **packages/worker** - This [Koa](https://koajs.com/) app is responsible for providing global apis for managing your budibase installation. Authentication, Users, Email, Org and Auth configs are all provided by the worker. |
|||
|
|||
## Contributor License Agreement (CLA) |
|||
|
|||
In order to accept your pull request, we need you to submit a CLA. You only need to do this once. If you are submitting a pull request for the first time, just submit a Pull Request and our CLA Bot will give you instructions on how to sign the CLA before merging your Pull Request. |
|||
|
|||
All contributors must sign an [Individual Contributor License Agreement](https://github.com/budibase/budibase/blob/next/.github/cla/individual-cla.md). |
|||
|
|||
If contributing on behalf of your company, your company must sign a [Corporate Contributor License Agreement](https://github.com/budibase/budibase/blob/next/.github/cla/corporate-cla.md). If so, please contact us via community@budibase.com. |
|||
|
|||
## Glossary of Terms |
|||
|
|||
To understand the budibase API, it can be helpful to understand the top level entities that make up Budibase. |
|||
|
|||
### Client |
|||
|
|||
A client represents a single budibase customer. Each budibase client will have 1 or more budibase servers. Every client is assigned a unique ID. |
|||
|
|||
### App |
|||
|
|||
A client can have one or more budibase applications. Budibase applications would be things like "Developer Inventory Management" or "Goat Herder CRM". Think of a budibase application as a tree. |
|||
|
|||
### Database |
|||
|
|||
An App can have one or more databases. Keeping with our [dendrology](https://en.wikipedia.org/wiki/Dendrology) analogy - think of an database as a branch on the tree. Databases are used to keep data separate for different instances of your app. For example, if you had a CRM app, you may create a database for your US office, and a database for your Australian office. Databases allow us to support [multitenancy](https://www.gartner.com/en/information-technology/glossary/multitenancy) in budibase applications. |
|||
|
|||
### Table |
|||
|
|||
Tables in budibase are almost akin to tables in relational databases. A table may be a "Car" or an "Employee". They are the main building blocks for the creation and management of backend data in budibase. |
|||
|
|||
### View |
|||
|
|||
A View is an advanced feature in budibase that allows you to write a custom query using [MapReduce](https://pouchdb.com/guides/queries.html) queries. Views enable powerful query functionality and calculations, allowing you to do more with your data. |
|||
|
|||
### Page |
|||
|
|||
A page in budibase is actually a single, self contained svelte web app. There are only 2 pages in budibase. The **login** page and the **main** page. |
|||
|
|||
### Screen |
|||
|
|||
A screen is a component within a single page. Generally, screens represent client side routes, and can be switched without refreshing the page. |
|||
|
|||
### Component |
|||
|
|||
A component is the basic frontend building block of a budibase app. |
|||
|
|||
### Component Library |
|||
|
|||
Component libraries are collections of components as well as the definition of their props contained in a file called `components.json`. |
|||
|
|||
## Contributing to Budibase |
|||
|
|||
* Please maintain the existing code style. |
|||
|
|||
* Please try to keep your commits small and focused. |
|||
|
|||
* Please write tests. |
|||
|
|||
* If the project diverges from your branch, please rebase instead of merging. This makes the commit graph easier to read. |
|||
|
|||
* Once your work is completed, please raise a PR against the `develop` branch with some information about what has changed and why. |
|||
|
|||
### Getting Started For Contributors |
|||
#### 1. Prerequisites |
|||
|
|||
NodeJS Version `14.x.x` |
|||
|
|||
*yarn -* `npm install -g yarn` |
|||
|
|||
*jest* - `npm install -g jest` |
|||
|
|||
#### 2. Clone this repository |
|||
|
|||
`git clone https://github.com/Budibase/budibase.git` |
|||
|
|||
then `cd ` into your local copy. |
|||
|
|||
#### 3. Install and Build |
|||
|
|||
| **NOTE**: On Windows, all yarn commands must be executed on a bash shell (e.g. git bash) |
|||
|
|||
To develop the Budibase platform you'll need [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) installed. |
|||
|
|||
##### Quick method |
|||
|
|||
`yarn setup` will check that all necessary components are installed and setup the repo for usage. |
|||
|
|||
##### Manual method |
|||
|
|||
The following commands can be executed to manually get Budibase up and running (assuming Docker/Docker Compose has been installed). |
|||
|
|||
`yarn` to install project dependencies |
|||
|
|||
`yarn bootstrap` will install all budibase modules and symlink them together using lerna. |
|||
|
|||
`yarn build` will build all budibase packages. |
|||
|
|||
#### 4. Running |
|||
|
|||
To run the budibase server and builder in dev mode (i.e. with live reloading): |
|||
|
|||
1. Open a new console |
|||
2. `yarn dev` (from root) |
|||
3. Access the builder on http://localhost:10000/builder |
|||
|
|||
This will enable watch mode for both the builder app, server, client library and any component libraries. |
|||
|
|||
#### 5. Debugging using VS Code |
|||
|
|||
To debug the budibase server and worker a VS Code launch configuration has been provided. |
|||
|
|||
Visit the debug window and select `Budibase Server` or `Budibase Worker` to debug the respective component. |
|||
Alternatively to start both components simultaneously select `Start Budibase`. |
|||
|
|||
In addition to the above, the remaining budibase components may be run in dev mode using: `yarn dev:noserver`. |
|||
|
|||
#### 6. Cleanup |
|||
|
|||
If you wish to delete all the apps created in development and reset the environment then run the following: |
|||
|
|||
1. `yarn nuke:docker` will wipe all the Budibase services |
|||
2. `yarn dev` will restart all the services |
|||
|
|||
### Backend |
|||
|
|||
For the backend we run [Redis](https://redis.io/), [CouchDB](https://couchdb.apache.org/), [MinIO](https://min.io/) and [NGINX](https://www.nginx.com/) in Docker compose. This means that to develop Budibase you will need Docker and Docker compose installed. The backend services are then run separately as Node services with nodemon so that they can be debugged outside of Docker. |
|||
|
|||
### Data Storage |
|||
|
|||
When you are running locally, budibase stores data on disk using docker volumes. The volumes and the types of data associated with each are: |
|||
|
|||
- `redis_data` |
|||
- Sessions, email tokens |
|||
- `couchdb3_data` |
|||
- Global and app databases |
|||
- `minio_data` |
|||
- App manifest, budibase client, static assets |
|||
|
|||
### Development Modes |
|||
|
|||
A combination of environment variables controls the mode budibase runs in. |
|||
Yarn commands can be used to mimic the different modes as described in the sections below: |
|||
|
|||
#### Self Hosted |
|||
The default mode. A single tenant installation with no usage restrictions. |
|||
|
|||
To enable this mode, use: |
|||
``` |
|||
yarn mode:self |
|||
``` |
|||
|
|||
#### Cloud |
|||
The cloud mode, with account portal turned off. |
|||
|
|||
To enable this mode, use: |
|||
``` |
|||
yarn mode:cloud |
|||
``` |
|||
#### Cloud & Account |
|||
The cloud mode, with account portal turned on. This is a replica of the mode that runs at https://budibase.app |
|||
|
|||
|
|||
To enable this mode, use: |
|||
``` |
|||
yarn mode:account |
|||
``` |
|||
### CI |
|||
An overview of the CI pipelines can be found [here](./workflows/README.md) |
|||
|
|||
### Pro |
|||
|
|||
@budibase/pro is the closed source package that supports licensed features in budibase. By default the package will be pulled from NPM and will not normally need to be touched in local development. If you require to update code inside the pro package it can be cloned to the same root level as budibase, e.g. |
|||
|
|||
``` |
|||
. |
|||
|_ budibase |
|||
|_ budibase-pro |
|||
``` |
|||
|
|||
Note that only budibase maintainers will be able to access the pro repo. |
|||
|
|||
The `yarn bootstrap` command can be used to replace the NPM supplied dependency with the local source aware version. This is achieved using the `yarn link` command. To see specifically how dependencies are linked see [scripts/link-dependencies.sh](../scripts/link-dependencies.sh). The same link script is used to link dependencies to account-portal in local dev. |
|||
|
|||
### Troubleshooting |
|||
|
|||
Sometimes, things go wrong. This can be due to incompatible updates on the budibase platform. To clear down your development environment and start again follow **Step 6. Cleanup**, then proceed from **Step 3. Install and Build** in the setup guide above to create a fresh Budibase installation. |
|||
### Running tests |
|||
|
|||
#### End-to-end Tests |
|||
|
|||
Budibase uses Cypress to run a number of E2E tests. To run the tests execute the following command in the root folder: |
|||
|
|||
``` |
|||
yarn test:e2e |
|||
``` |
|||
|
|||
Or if you are in the builder you can run `yarn cy:test`. |
|||
|
|||
|
|||
### Other Useful Information |
|||
|
|||
* The contributors are listed in [AUTHORS.md](https://github.com/Budibase/budibase/blob/master/.github/AUTHORS.md) (add yourself). |
|||
|
|||
* This project uses a modified version of the MPLv2 license, see [LICENSE](https://github.com/budibase/server/blob/master/LICENSE). |
|||
|
|||
* We use the [C4 (Collective Code Construction Contract)](https://rfc.zeromq.org/spec:42/C4/) process for contributions. |
|||
Please read this if you are unfamiliar with it. |
|||
@ -0,0 +1,52 @@ |
|||
## Dev Environment on Debian 11 |
|||
|
|||
### Install Node |
|||
|
|||
Budibase requires a recent version of node (14+): |
|||
``` |
|||
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash - |
|||
apt -y install nodejs |
|||
node -v |
|||
``` |
|||
|
|||
### 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: v16.15.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 bootstrap && 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 |
|||
@ -0,0 +1,54 @@ |
|||
## Dev Environment on MAC OSX 12 (Monterey) |
|||
|
|||
### Install Homebrew |
|||
|
|||
Install instructions [here](https://brew.sh/) |
|||
|
|||
### 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: 18.3.0 |
|||
- 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 bootstrap && 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 |
|||
@ -0,0 +1,13 @@ |
|||
#!/bin/bash |
|||
CUSTOM_DOMAIN="$1" |
|||
|
|||
if [[ ! -z "${CUSTOM_DOMAIN}" ]]; then |
|||
certbot certonly --webroot --webroot-path="/var/www/html" \ |
|||
--register-unsafely-without-email \ |
|||
--domains $CUSTOM_DOMAIN \ |
|||
--rsa-key-size 4096 \ |
|||
--agree-tos \ |
|||
--force-renewal |
|||
|
|||
nginx -s reload |
|||
fi |
|||
@ -0,0 +1,23 @@ |
|||
#!/bin/bash |
|||
CUSTOM_DOMAIN="$1" |
|||
# Request from Lets Encrypt |
|||
certbot certonly --webroot --webroot-path="/var/www/html" \ |
|||
--register-unsafely-without-email \ |
|||
--domains $CUSTOM_DOMAIN \ |
|||
--rsa-key-size 4096 \ |
|||
--agree-tos \ |
|||
--force-renewal |
|||
|
|||
if (($? != 0)); then |
|||
echo "ERROR: certbot request failed for $CUSTOM_DOMAIN use http on port 80 - exiting" |
|||
exit 1 |
|||
else |
|||
cp /app/letsencrypt/options-ssl-nginx.conf /etc/letsencrypt/options-ssl-nginx.conf |
|||
cp /app/letsencrypt/ssl-dhparams.pem /etc/letsencrypt/ssl-dhparams.pem |
|||
cp /app/letsencrypt/nginx-ssl.conf /etc/nginx/sites-available/nginx-ssl.conf |
|||
sed -i "s/CUSTOM_DOMAIN/$CUSTOM_DOMAIN/g" /etc/nginx/sites-available/nginx-ssl.conf |
|||
ln -s /etc/nginx/sites-available/nginx-ssl.conf /etc/nginx/sites-enabled/nginx-ssl.conf |
|||
|
|||
echo "INFO: restart nginx after certbot request" |
|||
/etc/init.d/nginx restart |
|||
fi |
|||
@ -0,0 +1,96 @@ |
|||
server { |
|||
listen 443 ssl default_server; |
|||
listen [::]:443 ssl default_server; |
|||
server_name _; |
|||
ssl_certificate /etc/letsencrypt/live/CUSTOM_DOMAIN/fullchain.pem; |
|||
ssl_certificate_key /etc/letsencrypt/live/CUSTOM_DOMAIN/privkey.pem; |
|||
include /etc/letsencrypt/options-ssl-nginx.conf; |
|||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; |
|||
|
|||
client_max_body_size 1000m; |
|||
ignore_invalid_headers off; |
|||
proxy_buffering off; |
|||
# port_in_redirect off; |
|||
|
|||
location ^~ /.well-known/acme-challenge/ { |
|||
default_type "text/plain"; |
|||
root /var/www/html; |
|||
break; |
|||
} |
|||
location = /.well-known/acme-challenge/ { |
|||
return 404; |
|||
} |
|||
|
|||
location /app { |
|||
proxy_pass http://127.0.0.1:4001; |
|||
} |
|||
|
|||
location = / { |
|||
proxy_pass http://127.0.0.1:4001; |
|||
} |
|||
|
|||
location ~ ^/(builder|app_) { |
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection $connection_upgrade; |
|||
proxy_set_header Upgrade $http_upgrade; |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_pass http://127.0.0.1:4001; |
|||
} |
|||
|
|||
location ~ ^/api/(system|admin|global)/ { |
|||
proxy_pass http://127.0.0.1:4002; |
|||
} |
|||
|
|||
location /worker/ { |
|||
proxy_pass http://127.0.0.1:4002; |
|||
rewrite ^/worker/(.*)$ /$1 break; |
|||
} |
|||
|
|||
location /api/ { |
|||
# calls to the API are rate limited with bursting |
|||
limit_req zone=ratelimit burst=20 nodelay; |
|||
|
|||
# 120s timeout on API requests |
|||
proxy_read_timeout 120s; |
|||
proxy_connect_timeout 120s; |
|||
proxy_send_timeout 120s; |
|||
|
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection $connection_upgrade; |
|||
proxy_set_header Upgrade $http_upgrade; |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
|
|||
proxy_pass http://127.0.0.1:4001; |
|||
} |
|||
|
|||
location /db/ { |
|||
proxy_pass http://127.0.0.1:5984; |
|||
rewrite ^/db/(.*)$ /$1 break; |
|||
} |
|||
|
|||
location / { |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_set_header X-Forwarded-Proto $scheme; |
|||
|
|||
proxy_connect_timeout 300; |
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection ""; |
|||
chunked_transfer_encoding off; |
|||
proxy_pass http://127.0.0.1:9000; |
|||
} |
|||
|
|||
client_header_timeout 60; |
|||
client_body_timeout 60; |
|||
keepalive_timeout 60; |
|||
|
|||
# gzip |
|||
gzip on; |
|||
gzip_vary on; |
|||
gzip_proxied any; |
|||
gzip_comp_level 6; |
|||
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml; |
|||
|
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
# This file contains important security parameters. If you modify this file |
|||
# manually, Certbot will be unable to automatically provide future security |
|||
# updates. Instead, Certbot will print and log an error message with a path to |
|||
# the up-to-date file that you will need to refer to when manually updating |
|||
# this file. |
|||
|
|||
ssl_session_cache shared:le_nginx_SSL:10m; |
|||
ssl_session_timeout 1440m; |
|||
|
|||
ssl_protocols TLSv1.2 TLSv1.3; |
|||
ssl_prefer_server_ciphers off; |
|||
|
|||
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"; |
|||
@ -0,0 +1,8 @@ |
|||
-----BEGIN DH PARAMETERS----- |
|||
MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz |
|||
+8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a |
|||
87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 |
|||
YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi |
|||
7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD |
|||
ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg== |
|||
-----END DH PARAMETERS----- |
|||
@ -0,0 +1,17 @@ |
|||
#!/bin/bash |
|||
|
|||
echo ${TARGETBUILD} > /buildtarget.txt |
|||
if [[ "${TARGETBUILD}" = "aas" ]]; then |
|||
# Azure AppService uses /home for persisent data & SSH on port 2222 |
|||
mkdir -p /home/budibase/{minio,couchdb} |
|||
mkdir -p /home/budibase/couchdb/data |
|||
chown -R couchdb:couchdb /home/budibase/couchdb/ |
|||
apt update |
|||
apt-get install -y openssh-server |
|||
sed -i 's#dir=/opt/couchdb/data/search#dir=/home/budibase/couchdb/data/search#' /opt/clouseau/clouseau.ini |
|||
sed -i 's#/minio/minio server /minio &#/minio/minio server /home/budibase/minio &#' /runner.sh |
|||
sed -i 's#database_dir = ./data#database_dir = /home/budibase/couchdb/data#' /opt/couchdb/etc/default.ini |
|||
sed -i 's#view_index_dir = ./data#view_index_dir = /home/budibase/couchdb/data#' /opt/couchdb/etc/default.ini |
|||
sed -i "s/#Port 22/Port 2222/" /etc/ssh/sshd_config |
|||
/etc/init.d/ssh restart |
|||
fi |
|||
@ -0,0 +1,40 @@ |
|||
#!/usr/bin/env bash |
|||
healthy=true |
|||
|
|||
if [[ $(curl -Lfk -s -w "%{http_code}\n" http://localhost/ -o /dev/null) -ne 200 ]]; then |
|||
echo 'ERROR: Budibase is not running'; |
|||
healthy=false |
|||
fi |
|||
|
|||
if [[ $(curl -s -w "%{http_code}\n" http://localhost:4001/health -o /dev/null) -ne 200 ]]; then |
|||
echo 'ERROR: Budibase backend is not running'; |
|||
healthy=false |
|||
fi |
|||
|
|||
if [[ $(curl -s -w "%{http_code}\n" http://localhost:4002/health -o /dev/null) -ne 200 ]]; then |
|||
echo 'ERROR: Budibase worker is not running'; |
|||
healthy=false |
|||
fi |
|||
|
|||
if [[ $(curl -s -w "%{http_code}\n" http://localhost:5984/ -o /dev/null) -ne 200 ]]; then |
|||
echo 'ERROR: CouchDB is not running'; |
|||
healthy=false |
|||
fi |
|||
if [[ $(redis-cli -a $REDIS_PASSWORD --no-auth-warning ping) != 'PONG' ]]; then |
|||
echo 'ERROR: Redis is down'; |
|||
healthy=false |
|||
fi |
|||
# mino, clouseau, |
|||
nginx -t -q |
|||
NGINX_STATUS=$? |
|||
|
|||
if [[ $NGINX_STATUS -gt 0 ]]; then |
|||
echo 'ERROR: Nginx config problem'; |
|||
healthy=false |
|||
fi |
|||
|
|||
if [ $healthy == true ]; then |
|||
exit 0 |
|||
else |
|||
exit 1 |
|||
fi |
|||
@ -0,0 +1,112 @@ |
|||
# Docker Single Image for Budibase |
|||
|
|||
## Overview |
|||
As an alternative to running several docker containers via docker-compose, the files under ./hosting/single can be used to build a docker image containing all of the Budibase components (minio, couch, clouseau etc). |
|||
We call this the 'single image' container as the Dockerfile adds all the components to a single docker image. |
|||
|
|||
## Usage |
|||
|
|||
- Amend Environment Variables |
|||
- Build Requirements |
|||
- Build the Image |
|||
- Run the Container |
|||
|
|||
### Amend Environment Variables |
|||
|
|||
Edit the Dockerfile in this directory amending the environment variables to suit your usage. Pay particular attention to changing passwords. |
|||
The CUSTOM_DOMAIN variable will be used to request a certificate from LetsEncrypt and if successful you can point traffic to port 443. If you choose to use the CUSTOM_DOMAIN variable ensure that the DNS for your custom domain points to the public IP address where you are running Budibase - otherwise the certificate issuance will fail. |
|||
If you have other arrangements for a proxy in front of the single image container you can omit the CUSTOM_DOMAIN environment variable and the request to LetsEncrypt will be skipped. You can then point traffic to port 80. |
|||
|
|||
### Build Requirements |
|||
We would suggest building the image with 6GB of RAM and 20GB of free disk space for build artifacts. The resulting image size will use approx 2GB of disk space. |
|||
|
|||
### Build the Image |
|||
The guidance below is based on building the Budibase single image on Debian 11 and AlmaLinux 8. If you use another distro or OS you will need to amend the commands to suit. |
|||
#### Install Node |
|||
Budibase requires a more recent version of node (14+) than is available in the base Debian repos so: |
|||
|
|||
``` |
|||
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash - |
|||
apt install -y nodejs |
|||
node -v |
|||
``` |
|||
Install yarn and lerna: |
|||
``` |
|||
npm install -g yarn jest lerna |
|||
``` |
|||
#### Install Docker |
|||
|
|||
``` |
|||
apt install -y docker.io |
|||
``` |
|||
|
|||
Check the versions of each installed version. This process was tested with the version numbers below so YMMV using anything else: |
|||
|
|||
- Docker: 20.10.5 |
|||
- node: 16.15.1 |
|||
- yarn: 1.22.19 |
|||
- lerna: 5.1.4 |
|||
|
|||
#### Get the Code |
|||
Clone the Budibase repo |
|||
``` |
|||
git clone https://github.com/Budibase/budibase.git |
|||
cd budibase |
|||
``` |
|||
#### Setup Node |
|||
Node setup: |
|||
``` |
|||
node ./hosting/scripts/setup.js |
|||
yarn |
|||
yarn bootstrap |
|||
yarn build |
|||
``` |
|||
#### Build Image |
|||
The following yarn command does some prep and then runs the docker build command: |
|||
``` |
|||
yarn build:docker:single |
|||
``` |
|||
If the docker build step fails try running that step again manually with: |
|||
``` |
|||
docker build --build-arg TARGETARCH=amd --no-cache -t budibase:latest -f ./hosting/single/Dockerfile . |
|||
``` |
|||
|
|||
#### Azure App Services |
|||
Azure have some specific requirements for running a container in their App Service. Specifically, installation of SSH to port 2222 and data storage under /home. If you would like to build a budibase container for Azure App Service add the build argument shown below setting it to 'aas'. You can remove the CUSTOM_DOMAIN env variable from the Dockerfile too as Azure terminate SSL before requests reach the container. |
|||
``` |
|||
docker build --build-arg TARGETARCH=amd --build-arg TARGETBUILD=aas -t budibase:latest -f ./hosting/single/Dockerfile . |
|||
``` |
|||
|
|||
### Run the Container |
|||
``` |
|||
docker run -d -p 80:80 -p 443:443 --name budibase budibase:latest |
|||
``` |
|||
Where: |
|||
- -d runs the container in detached mode |
|||
- -p forwards ports from your host to the ports inside the container. If you are already using port 80 on your host for something else you can try running with an alternative port e.g. `-p 8080:80` |
|||
- --name is the name for the container as shown in `docker ps` and can be used with other docker commands e.g. `docker restart budibase` |
|||
|
|||
When the container runs you should be able to access the container over http at your host address e.g. http://1.2.3.4/ or using your custom domain e.g. https://my.custom.domain/ |
|||
|
|||
When the Budibase UI appears you will be prompted to create an account to get started. |
|||
|
|||
### Podman |
|||
The single image container builds fine when using podman in place of docker. You may be prompted for the registry to use for the CouchDB image and the HEALTHCHECK parameter is not OCI compliant so is ignored. |
|||
|
|||
### Check |
|||
There are many things that could go wrong so if your container is not building or running as expected please check the following before opening a support issue. |
|||
Verify the healthcheck status of the container: |
|||
``` |
|||
docker ps |
|||
``` |
|||
Check the container logs: |
|||
``` |
|||
docker logs budibase |
|||
``` |
|||
|
|||
### Support |
|||
This single image build is still a work-in-progress so if you open an issue please provide the following information: |
|||
- The OS and OS version you are building on |
|||
- The versions you are using of docker, docker-compose, yarn, node, lerna |
|||
- For build errors please provide zipped output |
|||
- For container errors please provide zipped container logs |
|||
@ -0,0 +1,94 @@ |
|||
server { |
|||
listen 80 default_server; |
|||
listen [::]:80 default_server; |
|||
server_name _; |
|||
|
|||
client_max_body_size 1000m; |
|||
ignore_invalid_headers off; |
|||
proxy_buffering off; |
|||
# port_in_redirect off; |
|||
|
|||
location ^~ /.well-known/acme-challenge/ { |
|||
default_type "text/plain"; |
|||
root /var/www/html; |
|||
break; |
|||
} |
|||
location = /.well-known/acme-challenge/ { |
|||
return 404; |
|||
} |
|||
|
|||
location /app { |
|||
proxy_pass http://127.0.0.1:4001; |
|||
} |
|||
|
|||
location = / { |
|||
proxy_pass http://127.0.0.1:4001; |
|||
} |
|||
|
|||
location ~ ^/(builder|app_) { |
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection $connection_upgrade; |
|||
proxy_set_header Upgrade $http_upgrade; |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_pass http://127.0.0.1:4001; |
|||
} |
|||
|
|||
location ~ ^/api/(system|admin|global)/ { |
|||
proxy_pass http://127.0.0.1:4002; |
|||
} |
|||
|
|||
location /worker/ { |
|||
proxy_pass http://127.0.0.1:4002; |
|||
rewrite ^/worker/(.*)$ /$1 break; |
|||
} |
|||
|
|||
location /api/ { |
|||
# calls to the API are rate limited with bursting |
|||
limit_req zone=ratelimit burst=20 nodelay; |
|||
|
|||
# 120s timeout on API requests |
|||
proxy_read_timeout 120s; |
|||
proxy_connect_timeout 120s; |
|||
proxy_send_timeout 120s; |
|||
|
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection $connection_upgrade; |
|||
proxy_set_header Upgrade $http_upgrade; |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
|
|||
proxy_pass http://127.0.0.1:4001; |
|||
} |
|||
|
|||
location /db/ { |
|||
proxy_pass http://127.0.0.1:5984; |
|||
rewrite ^/db/(.*)$ /$1 break; |
|||
} |
|||
|
|||
location / { |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_set_header X-Forwarded-Proto $scheme; |
|||
|
|||
proxy_connect_timeout 300; |
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection ""; |
|||
chunked_transfer_encoding off; |
|||
proxy_pass http://127.0.0.1:9000; |
|||
} |
|||
|
|||
client_header_timeout 60; |
|||
client_body_timeout 60; |
|||
keepalive_timeout 60; |
|||
|
|||
# gzip |
|||
gzip on; |
|||
gzip_vary on; |
|||
gzip_proxied any; |
|||
gzip_comp_level 6; |
|||
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml; |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
#!/bin/bash |
|||
id=$(docker run -t -d -p 80:80 budibase:latest) |
|||
docker exec -it $id bash |
|||
docker kill $id |
|||
@ -1,48 +1,82 @@ |
|||
{ |
|||
"name": "@budibase/backend-core", |
|||
"version": "1.0.192-alpha.5", |
|||
"version": "1.0.212-alpha.15", |
|||
"description": "Budibase backend core libraries used in server and worker", |
|||
"main": "src/index.js", |
|||
"main": "dist/src/index.js", |
|||
"types": "dist/src/index.d.ts", |
|||
"exports": { |
|||
".": "./dist/src/index.js", |
|||
"./tests": "./dist/tests/index.js", |
|||
"./*": "./dist/*.js" |
|||
}, |
|||
"author": "Budibase", |
|||
"license": "GPL-3.0", |
|||
"scripts": { |
|||
"prebuild": "rimraf dist/", |
|||
"prepack": "cp package.json dist", |
|||
"build": "tsc -p tsconfig.build.json", |
|||
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput", |
|||
"test": "jest", |
|||
"test:watch": "jest --watchAll" |
|||
}, |
|||
"dependencies": { |
|||
"@techpass/passport-openidconnect": "^0.3.0", |
|||
"aws-sdk": "^2.901.0", |
|||
"bcrypt": "^5.0.1", |
|||
"dotenv": "^16.0.1", |
|||
"emitter-listener": "^1.1.2", |
|||
"ioredis": "^4.27.1", |
|||
"jsonwebtoken": "^8.5.1", |
|||
"koa-passport": "^4.1.4", |
|||
"lodash": "^4.17.21", |
|||
"lodash.isarguments": "^3.1.0", |
|||
"node-fetch": "^2.6.1", |
|||
"passport-google-auth": "^1.0.2", |
|||
"passport-google-oauth": "^2.0.0", |
|||
"passport-jwt": "^4.0.0", |
|||
"passport-local": "^1.0.0", |
|||
"posthog-node": "^1.3.0", |
|||
"@budibase/types": "^1.0.212-alpha.15", |
|||
"@techpass/passport-openidconnect": "0.3.2", |
|||
"aws-sdk": "2.1030.0", |
|||
"bcrypt": "5.0.1", |
|||
"dotenv": "16.0.1", |
|||
"emitter-listener": "1.1.2", |
|||
"ioredis": "4.28.0", |
|||
"jsonwebtoken": "8.5.1", |
|||
"koa-passport": "4.1.4", |
|||
"lodash": "4.17.21", |
|||
"lodash.isarguments": "3.1.0", |
|||
"node-fetch": "2.6.7", |
|||
"passport-google-auth": "1.0.2", |
|||
"passport-google-oauth": "2.0.0", |
|||
"passport-jwt": "4.0.0", |
|||
"passport-local": "1.0.0", |
|||
"passport-oauth2-refresh": "^2.1.0", |
|||
"posthog-node": "1.3.0", |
|||
"pouchdb": "7.3.0", |
|||
"pouchdb-find": "^7.2.2", |
|||
"pouchdb-replication-stream": "^1.2.9", |
|||
"sanitize-s3-objectkey": "^0.0.1", |
|||
"tar-fs": "^2.1.1", |
|||
"uuid": "^8.3.2", |
|||
"zlib": "^1.0.5" |
|||
"pouchdb-find": "7.2.2", |
|||
"pouchdb-replication-stream": "1.2.9", |
|||
"redlock": "4.2.0", |
|||
"sanitize-s3-objectkey": "0.0.1", |
|||
"semver": "7.3.7", |
|||
"tar-fs": "2.1.1", |
|||
"uuid": "8.3.2", |
|||
"zlib": "1.0.5" |
|||
}, |
|||
"jest": { |
|||
"preset": "ts-jest", |
|||
"testEnvironment": "node", |
|||
"moduleNameMapper": { |
|||
"@budibase/types": "<rootDir>/../types/src" |
|||
}, |
|||
"setupFiles": [ |
|||
"./scripts/jestSetup.js" |
|||
"./scripts/jestSetup.ts" |
|||
] |
|||
}, |
|||
"devDependencies": { |
|||
"ioredis-mock": "^5.5.5", |
|||
"jest": "^26.6.3", |
|||
"pouchdb-adapter-memory": "^7.2.2" |
|||
"@shopify/jest-koa-mocks": "3.1.5", |
|||
"@types/jest": "27.5.1", |
|||
"@types/koa": "2.0.52", |
|||
"@types/node": "14.18.20", |
|||
"@types/node-fetch": "2.6.1", |
|||
"@types/pouchdb": "6.4.0", |
|||
"@types/redlock": "4.0.3", |
|||
"@types/semver": "7.3.7", |
|||
"@types/tar-fs": "2.0.1", |
|||
"@types/uuid": "8.3.4", |
|||
"ioredis-mock": "5.8.0", |
|||
"jest": "27.5.1", |
|||
"koa": "2.7.0", |
|||
"nodemon": "2.0.16", |
|||
"pouchdb-adapter-memory": "7.2.2", |
|||
"timekeeper": "2.2.0", |
|||
"ts-jest": "27.1.5", |
|||
"typescript": "4.7.3" |
|||
}, |
|||
"gitHead": "d1836a898cab3f8ab80ee6d8f42be1a9eed7dcdc" |
|||
} |
|||
|
|||
@ -1,4 +1,5 @@ |
|||
module.exports = { |
|||
Client: require("./src/redis"), |
|||
utils: require("./src/redis/utils"), |
|||
clients: require("./src/redis/init"), |
|||
} |
|||
|
|||
@ -1,6 +0,0 @@ |
|||
const env = require("../src/environment") |
|||
|
|||
env._set("SELF_HOSTED", "1") |
|||
env._set("NODE_ENV", "jest") |
|||
env._set("JWT_SECRET", "test-jwtsecret") |
|||
env._set("LOG_LEVEL", "silent") |
|||
@ -0,0 +1,12 @@ |
|||
import env from "../src/environment" |
|||
import { mocks } from "../tests/utilities" |
|||
|
|||
// mock all dates to 2020-01-01T00:00:00.000Z
|
|||
// use tk.reset() to use real dates in individual tests
|
|||
import tk from "timekeeper" |
|||
tk.freeze(mocks.date.MOCK_DATE) |
|||
|
|||
env._set("SELF_HOSTED", "1") |
|||
env._set("NODE_ENV", "jest") |
|||
env._set("JWT_SECRET", "test-jwtsecret") |
|||
env._set("LOG_LEVEL", "silent") |
|||
@ -0,0 +1,92 @@ |
|||
import { getTenantId } from "../../context" |
|||
import redis from "../../redis/init" |
|||
import RedisWrapper from "../../redis" |
|||
|
|||
function generateTenantKey(key: string) { |
|||
const tenantId = getTenantId() |
|||
return `${key}:${tenantId}` |
|||
} |
|||
|
|||
export = class BaseCache { |
|||
client: RedisWrapper | undefined |
|||
|
|||
constructor(client: RedisWrapper | undefined = undefined) { |
|||
this.client = client |
|||
} |
|||
|
|||
async getClient() { |
|||
return !this.client ? await redis.getCacheClient() : this.client |
|||
} |
|||
|
|||
async keys(pattern: string) { |
|||
const client = await this.getClient() |
|||
return client.keys(pattern) |
|||
} |
|||
|
|||
/** |
|||
* Read only from the cache. |
|||
*/ |
|||
async get(key: string, opts = { useTenancy: true }) { |
|||
key = opts.useTenancy ? generateTenantKey(key) : key |
|||
const client = await this.getClient() |
|||
return client.get(key) |
|||
} |
|||
|
|||
/** |
|||
* Write to the cache. |
|||
*/ |
|||
async store( |
|||
key: string, |
|||
value: any, |
|||
ttl: number | null = null, |
|||
opts = { useTenancy: true } |
|||
) { |
|||
key = opts.useTenancy ? generateTenantKey(key) : key |
|||
const client = await this.getClient() |
|||
await client.store(key, value, ttl) |
|||
} |
|||
|
|||
/** |
|||
* Remove from cache. |
|||
*/ |
|||
async delete(key: string, opts = { useTenancy: true }) { |
|||
key = opts.useTenancy ? generateTenantKey(key) : key |
|||
const client = await this.getClient() |
|||
return client.delete(key) |
|||
} |
|||
|
|||
/** |
|||
* Read from the cache. Write to the cache if not exists. |
|||
*/ |
|||
async withCache( |
|||
key: string, |
|||
ttl: number, |
|||
fetchFn: any, |
|||
opts = { useTenancy: true } |
|||
) { |
|||
const cachedValue = await this.get(key, opts) |
|||
if (cachedValue) { |
|||
return cachedValue |
|||
} |
|||
|
|||
try { |
|||
const fetchedValue = await fetchFn() |
|||
|
|||
await this.store(key, fetchedValue, ttl, opts) |
|||
return fetchedValue |
|||
} catch (err) { |
|||
console.error("Error fetching before cache - ", err) |
|||
throw err |
|||
} |
|||
} |
|||
|
|||
async bustCache(key: string, opts = { client: null }) { |
|||
const client = await this.getClient() |
|||
try { |
|||
await client.delete(generateTenantKey(key)) |
|||
} catch (err) { |
|||
console.error("Error busting cache - ", err) |
|||
throw err |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
require("../../../tests/utilities/TestConfiguration") |
|||
const { Writethrough } = require("../writethrough") |
|||
const { dangerousGetDB } = require("../../db") |
|||
const tk = require("timekeeper") |
|||
|
|||
const START_DATE = Date.now() |
|||
tk.freeze(START_DATE) |
|||
|
|||
const DELAY = 5000 |
|||
|
|||
const db = dangerousGetDB("test") |
|||
const db2 = dangerousGetDB("test2") |
|||
const writethrough = new Writethrough(db, DELAY), writethrough2 = new Writethrough(db2, DELAY) |
|||
|
|||
describe("writethrough", () => { |
|||
describe("put", () => { |
|||
let first |
|||
it("should be able to store, will go to DB", async () => { |
|||
const response = await writethrough.put({ _id: "test", value: 1 }) |
|||
const output = await db.get(response.id) |
|||
first = output |
|||
expect(output.value).toBe(1) |
|||
}) |
|||
|
|||
it("second put shouldn't update DB", async () => { |
|||
const response = await writethrough.put({ ...first, value: 2 }) |
|||
const output = await db.get(response.id) |
|||
expect(first._rev).toBe(output._rev) |
|||
expect(output.value).toBe(1) |
|||
}) |
|||
|
|||
it("should put it again after delay period", async () => { |
|||
tk.freeze(START_DATE + DELAY + 1) |
|||
const response = await writethrough.put({ ...first, value: 3 }) |
|||
const output = await db.get(response.id) |
|||
expect(response.rev).not.toBe(first._rev) |
|||
expect(output.value).toBe(3) |
|||
}) |
|||
}) |
|||
|
|||
describe("get", () => { |
|||
it("should be able to retrieve", async () => { |
|||
const response = await writethrough.get("test") |
|||
expect(response.value).toBe(3) |
|||
}) |
|||
}) |
|||
|
|||
describe("same doc, different databases (tenancy)", () => { |
|||
it("should be able to two different databases", async () => { |
|||
const resp1 = await writethrough.put({ _id: "db1", value: "first" }) |
|||
const resp2 = await writethrough2.put({ _id: "db1", value: "second" }) |
|||
expect(resp1.rev).toBeDefined() |
|||
expect(resp2.rev).toBeDefined() |
|||
expect((await db.get("db1")).value).toBe("first") |
|||
expect((await db2.get("db1")).value).toBe("second") |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
@ -0,0 +1,120 @@ |
|||
import BaseCache from "./base" |
|||
import { getWritethroughClient } from "../redis/init" |
|||
|
|||
const DEFAULT_WRITE_RATE_MS = 10000 |
|||
let CACHE: BaseCache | null = null |
|||
|
|||
interface CacheItem { |
|||
doc: any |
|||
lastWrite: number |
|||
} |
|||
|
|||
async function getCache() { |
|||
if (!CACHE) { |
|||
const client = await getWritethroughClient() |
|||
CACHE = new BaseCache(client) |
|||
} |
|||
return CACHE |
|||
} |
|||
|
|||
function makeCacheKey(db: PouchDB.Database, key: string) { |
|||
return db.name + key |
|||
} |
|||
|
|||
function makeCacheItem(doc: any, lastWrite: number | null = null): CacheItem { |
|||
return { doc, lastWrite: lastWrite || Date.now() } |
|||
} |
|||
|
|||
export async function put( |
|||
db: PouchDB.Database, |
|||
doc: any, |
|||
writeRateMs: number = DEFAULT_WRITE_RATE_MS |
|||
) { |
|||
const cache = await getCache() |
|||
const key = doc._id |
|||
let cacheItem: CacheItem | undefined = await cache.get(makeCacheKey(db, key)) |
|||
const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs |
|||
let output = doc |
|||
if (updateDb) { |
|||
const writeDb = async (toWrite: any) => { |
|||
// doc should contain the _id and _rev
|
|||
const response = await db.put(toWrite) |
|||
output = { |
|||
...doc, |
|||
_id: response.id, |
|||
_rev: response.rev, |
|||
} |
|||
} |
|||
try { |
|||
await writeDb(doc) |
|||
} catch (err: any) { |
|||
if (err.status !== 409) { |
|||
throw err |
|||
} else { |
|||
// get the rev, update over it - this is risky, may change in future
|
|||
const readDoc = await db.get(doc._id) |
|||
doc._rev = readDoc._rev |
|||
await writeDb(doc) |
|||
} |
|||
} |
|||
} |
|||
// if we are updating the DB then need to set the lastWrite to now
|
|||
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem?.lastWrite) |
|||
await cache.store(makeCacheKey(db, key), cacheItem) |
|||
return { ok: true, id: output._id, rev: output._rev } |
|||
} |
|||
|
|||
export async function get(db: PouchDB.Database, id: string): Promise<any> { |
|||
const cache = await getCache() |
|||
const cacheKey = makeCacheKey(db, id) |
|||
let cacheItem: CacheItem = await cache.get(cacheKey) |
|||
if (!cacheItem) { |
|||
const doc = await db.get(id) |
|||
cacheItem = makeCacheItem(doc) |
|||
await cache.store(cacheKey, cacheItem) |
|||
} |
|||
return cacheItem.doc |
|||
} |
|||
|
|||
export async function remove( |
|||
db: PouchDB.Database, |
|||
docOrId: any, |
|||
rev?: any |
|||
): Promise<void> { |
|||
const cache = await getCache() |
|||
if (!docOrId) { |
|||
throw new Error("No ID/Rev provided.") |
|||
} |
|||
const id = typeof docOrId === "string" ? docOrId : docOrId._id |
|||
rev = typeof docOrId === "string" ? rev : docOrId._rev |
|||
try { |
|||
await cache.delete(makeCacheKey(db, id)) |
|||
} finally { |
|||
await db.remove(id, rev) |
|||
} |
|||
} |
|||
|
|||
export class Writethrough { |
|||
db: PouchDB.Database |
|||
writeRateMs: number |
|||
|
|||
constructor( |
|||
db: PouchDB.Database, |
|||
writeRateMs: number = DEFAULT_WRITE_RATE_MS |
|||
) { |
|||
this.db = db |
|||
this.writeRateMs = writeRateMs |
|||
} |
|||
|
|||
async put(doc: any) { |
|||
return put(this.db, doc, this.writeRateMs) |
|||
} |
|||
|
|||
async get(id: string) { |
|||
return get(this.db, id) |
|||
} |
|||
|
|||
async remove(docOrId: any, rev?: any) { |
|||
return remove(this.db, docOrId, rev) |
|||
} |
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
const API = require("./api") |
|||
const env = require("../environment") |
|||
const { Headers } = require("../constants") |
|||
|
|||
const api = new API(env.ACCOUNT_PORTAL_URL) |
|||
|
|||
exports.getAccount = async email => { |
|||
const payload = { |
|||
email, |
|||
} |
|||
const response = await api.post(`/api/accounts/search`, { |
|||
body: payload, |
|||
headers: { |
|||
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
|||
}, |
|||
}) |
|||
const json = await response.json() |
|||
|
|||
if (response.status !== 200) { |
|||
throw new Error(`Error getting account by email ${email}`, json) |
|||
} |
|||
|
|||
return json[0] |
|||
} |
|||
|
|||
exports.getStatus = async () => { |
|||
const response = await api.get(`/api/status`, { |
|||
headers: { |
|||
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
|||
}, |
|||
}) |
|||
const json = await response.json() |
|||
|
|||
if (response.status !== 200) { |
|||
throw new Error(`Error getting status`) |
|||
} |
|||
|
|||
return json |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
import API from "./api" |
|||
import env from "../environment" |
|||
import { Headers } from "../constants" |
|||
import { CloudAccount } from "@budibase/types" |
|||
|
|||
const api = new API(env.ACCOUNT_PORTAL_URL) |
|||
|
|||
export const getAccount = async ( |
|||
email: string |
|||
): Promise<CloudAccount | undefined> => { |
|||
const payload = { |
|||
email, |
|||
} |
|||
const response = await api.post(`/api/accounts/search`, { |
|||
body: payload, |
|||
headers: { |
|||
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
|||
}, |
|||
}) |
|||
|
|||
if (response.status !== 200) { |
|||
throw new Error(`Error getting account by email ${email}`) |
|||
} |
|||
|
|||
const json: CloudAccount[] = await response.json() |
|||
return json[0] |
|||
} |
|||
|
|||
export const getAccountByTenantId = async ( |
|||
tenantId: string |
|||
): Promise<CloudAccount | undefined> => { |
|||
const payload = { |
|||
tenantId, |
|||
} |
|||
const response = await api.post(`/api/accounts/search`, { |
|||
body: payload, |
|||
headers: { |
|||
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
|||
}, |
|||
}) |
|||
|
|||
if (response.status !== 200) { |
|||
throw new Error(`Error getting account by tenantId ${tenantId}`) |
|||
} |
|||
|
|||
const json: CloudAccount[] = await response.json() |
|||
return json[0] |
|||
} |
|||
|
|||
export const getStatus = async () => { |
|||
const response = await api.get(`/api/status`, { |
|||
headers: { |
|||
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
|||
}, |
|||
}) |
|||
const json = await response.json() |
|||
|
|||
if (response.status !== 200) { |
|||
throw new Error(`Error getting status`) |
|||
} |
|||
|
|||
return json |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
import { |
|||
IdentityContext, |
|||
IdentityType, |
|||
User, |
|||
UserContext, |
|||
isCloudAccount, |
|||
Account, |
|||
AccountUserContext, |
|||
} from "@budibase/types" |
|||
import * as context from "." |
|||
|
|||
export const getIdentity = (): IdentityContext | undefined => { |
|||
return context.getIdentity() |
|||
} |
|||
|
|||
export const doInIdentityContext = (identity: IdentityContext, task: any) => { |
|||
return context.doInIdentityContext(identity, task) |
|||
} |
|||
|
|||
export const doInUserContext = (user: User, task: any) => { |
|||
const userContext: UserContext = { |
|||
...user, |
|||
_id: user._id as string, |
|||
type: IdentityType.USER, |
|||
} |
|||
return doInIdentityContext(userContext, task) |
|||
} |
|||
|
|||
export const doInAccountContext = (account: Account, task: any) => { |
|||
const _id = getAccountUserId(account) |
|||
const tenantId = account.tenantId |
|||
const accountContext: AccountUserContext = { |
|||
_id, |
|||
type: IdentityType.USER, |
|||
tenantId, |
|||
account, |
|||
} |
|||
return doInIdentityContext(accountContext, task) |
|||
} |
|||
|
|||
export const getAccountUserId = (account: Account) => { |
|||
let userId: string |
|||
if (isCloudAccount(account)) { |
|||
userId = account.budibaseUserId |
|||
} else { |
|||
// use account id as user id for self hosting
|
|||
userId = account.accountId |
|||
} |
|||
return userId |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
export const SEPARATOR = "_" |
|||
export const UNICODE_MAX = "\ufff0" |
|||
|
|||
/** |
|||
* Can be used to create a few different forms of querying a view. |
|||
*/ |
|||
export enum AutomationViewModes { |
|||
ALL = "all", |
|||
AUTOMATION = "automation", |
|||
STATUS = "status", |
|||
} |
|||
|
|||
export enum ViewNames { |
|||
USER_BY_EMAIL = "by_email", |
|||
BY_API_KEY = "by_api_key", |
|||
USER_BY_BUILDERS = "by_builders", |
|||
LINK = "by_link", |
|||
ROUTING = "screen_routes", |
|||
AUTOMATION_LOGS = "automation_logs", |
|||
} |
|||
|
|||
export enum DocumentTypes { |
|||
USER = "us", |
|||
WORKSPACE = "workspace", |
|||
CONFIG = "config", |
|||
TEMPLATE = "template", |
|||
APP = "app", |
|||
DEV = "dev", |
|||
APP_DEV = "app_dev", |
|||
APP_METADATA = "app_metadata", |
|||
ROLE = "role", |
|||
MIGRATIONS = "migrations", |
|||
DEV_INFO = "devinfo", |
|||
AUTOMATION_LOG = "log_au", |
|||
} |
|||
|
|||
export const StaticDatabases = { |
|||
GLOBAL: { |
|||
name: "global-db", |
|||
docs: { |
|||
apiKeys: "apikeys", |
|||
usageQuota: "usage_quota", |
|||
licenseInfo: "license_info", |
|||
}, |
|||
}, |
|||
// contains information about tenancy and so on
|
|||
PLATFORM_INFO: { |
|||
name: "global-info", |
|||
docs: { |
|||
tenants: "tenants", |
|||
install: "install", |
|||
}, |
|||
}, |
|||
} |
|||
|
|||
export const APP_PREFIX = exports.DocumentTypes.APP + exports.SEPARATOR |
|||
export const APP_DEV = exports.DocumentTypes.APP_DEV + exports.SEPARATOR |
|||
export const APP_DEV_PREFIX = APP_DEV |
|||
@ -0,0 +1,26 @@ |
|||
require("../../../tests/utilities/TestConfiguration") |
|||
const { dangerousGetDB } = require("../") |
|||
|
|||
describe("db", () => { |
|||
|
|||
describe("getDB", () => { |
|||
it("returns a db", async () => { |
|||
const db = dangerousGetDB("test") |
|||
expect(db).toBeDefined() |
|||
expect(db._adapter).toBe("memory") |
|||
expect(db.prefix).toBe("_pouch_") |
|||
expect(db.name).toBe("test") |
|||
}) |
|||
|
|||
it("uses the custom put function", async () => { |
|||
const db = dangerousGetDB("test") |
|||
let doc = { _id: "test" } |
|||
await db.put(doc) |
|||
doc = await db.get(doc._id) |
|||
expect(doc.createdAt).toBe(new Date().toISOString()) |
|||
expect(doc.updatedAt).toBe(new Date().toISOString()) |
|||
await db.destroy() |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
@ -0,0 +1,62 @@ |
|||
require("../../../tests/utilities/TestConfiguration") |
|||
const getUrlInfo = require("../pouch").getUrlInfo |
|||
|
|||
describe("pouch", () => { |
|||
describe("Couch DB URL parsing", () => { |
|||
it("should handle a null Couch DB URL", () => { |
|||
const info = getUrlInfo(null) |
|||
expect(info.url).toBeUndefined() |
|||
expect(info.auth.username).toBeUndefined() |
|||
}) |
|||
it("should be able to parse a basic Couch DB URL", () => { |
|||
const info = getUrlInfo("http://host.com") |
|||
expect(info.url).toBe("http://host.com") |
|||
expect(info.auth.username).toBeUndefined() |
|||
}) |
|||
it("should be able to parse a Couch DB basic URL with HTTPS", () => { |
|||
const info = getUrlInfo("https://host.com") |
|||
expect(info.url).toBe("https://host.com") |
|||
expect(info.auth.username).toBeUndefined() |
|||
}) |
|||
it("should be able to parse a basic Couch DB URL with a custom port", () => { |
|||
const info = getUrlInfo("https://host.com:1234") |
|||
expect(info.url).toBe("https://host.com:1234") |
|||
expect(info.auth.username).toBeUndefined() |
|||
}) |
|||
it("should be able to parse a Couch DB URL with auth", () => { |
|||
const info = getUrlInfo("https://user:pass@host.com:1234") |
|||
expect(info.url).toBe("https://host.com:1234") |
|||
expect(info.auth.username).toBe("user") |
|||
expect(info.auth.password).toBe("pass") |
|||
}) |
|||
it("should be able to parse a Couch DB URL with auth and special chars", () => { |
|||
const info = getUrlInfo("https://user:s:p@s://@://:d@;][~s@host.com:1234") |
|||
expect(info.url).toBe("https://host.com:1234") |
|||
expect(info.auth.username).toBe("user") |
|||
expect(info.auth.password).toBe("s:p@s://@://:d@;][~s") |
|||
}) |
|||
it("should be able to parse a Couch DB URL without a protocol", () => { |
|||
const info = getUrlInfo("host.com:1234") |
|||
expect(info.url).toBe("http://host.com:1234") |
|||
expect(info.auth.username).toBeUndefined() |
|||
}) |
|||
it("should be able to parse a Couch DB URL with auth and without a protocol", () => { |
|||
const info = getUrlInfo("user:s:p@s://@://:d@;][~s@host.com:1234") |
|||
expect(info.url).toBe("http://host.com:1234") |
|||
expect(info.auth.username).toBe("user") |
|||
expect(info.auth.password).toBe("s:p@s://@://:d@;][~s") |
|||
}) |
|||
it("should be able to parse a Couch DB URL with only username auth", () => { |
|||
const info = getUrlInfo("https://user@host.com:1234") |
|||
expect(info.url).toBe("https://host.com:1234") |
|||
expect(info.auth.username).toBe("user") |
|||
expect(info.auth.password).toBeUndefined() |
|||
}) |
|||
it("should be able to parse a Couch DB URL with only username auth and without a protocol", () => { |
|||
const info = getUrlInfo("user@host.com:1234") |
|||
expect(info.url).toBe("http://host.com:1234") |
|||
expect(info.auth.username).toBe("user") |
|||
expect(info.auth.password).toBeUndefined() |
|||
}) |
|||
}) |
|||
}) |
|||
@ -0,0 +1,11 @@ |
|||
const { BudibaseError } = require("./base") |
|||
|
|||
class GenericError extends BudibaseError { |
|||
constructor(message, code, type) { |
|||
super(message, code, type ? type : "generic") |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
GenericError, |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
const { GenericError } = require("./generic") |
|||
|
|||
class HTTPError extends GenericError { |
|||
constructor(message, httpStatus, code = "http", type = "generic") { |
|||
super(message, code, type) |
|||
this.status = httpStatus |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
HTTPError, |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
import env from "../environment" |
|||
import tenancy from "../tenancy" |
|||
import * as dbUtils from "../db/utils" |
|||
import { Configs } from "../constants" |
|||
import { withCache, TTL, CacheKeys } from "../cache/generic" |
|||
|
|||
export const enabled = async () => { |
|||
// cloud - always use the environment variable
|
|||
if (!env.SELF_HOSTED) { |
|||
return !!env.ENABLE_ANALYTICS |
|||
} |
|||
|
|||
// self host - prefer the settings doc
|
|||
// use cache as events have high throughput
|
|||
const enabledInDB = await withCache( |
|||
CacheKeys.ANALYTICS_ENABLED, |
|||
TTL.ONE_DAY, |
|||
async () => { |
|||
const settings = await getSettingsDoc() |
|||
|
|||
// need to do explicit checks in case the field is not set
|
|||
if (settings?.config?.analyticsEnabled === false) { |
|||
return false |
|||
} else if (settings?.config?.analyticsEnabled === true) { |
|||
return true |
|||
} |
|||
} |
|||
) |
|||
|
|||
if (enabledInDB !== undefined) { |
|||
return enabledInDB |
|||
} |
|||
|
|||
// fallback to the environment variable
|
|||
// explicitly check for 0 or false here, undefined or otherwise is treated as true
|
|||
const envEnabled: any = env.ENABLE_ANALYTICS |
|||
if (envEnabled === 0 || envEnabled === false) { |
|||
return false |
|||
} else { |
|||
return true |
|||
} |
|||
} |
|||
|
|||
const getSettingsDoc = async () => { |
|||
const db = tenancy.getGlobalDB() |
|||
let settings |
|||
try { |
|||
settings = await db.get( |
|||
dbUtils.generateConfigID({ type: Configs.SETTINGS }) |
|||
) |
|||
} catch (e: any) { |
|||
if (e.status !== 404) { |
|||
throw e |
|||
} |
|||
} |
|||
return settings |
|||
} |
|||
@ -0,0 +1,183 @@ |
|||
import { |
|||
Event, |
|||
BackfillMetadata, |
|||
CachedEvent, |
|||
SSOCreatedEvent, |
|||
AutomationCreatedEvent, |
|||
AutomationStepCreatedEvent, |
|||
DatasourceCreatedEvent, |
|||
LayoutCreatedEvent, |
|||
QueryCreatedEvent, |
|||
RoleCreatedEvent, |
|||
ScreenCreatedEvent, |
|||
TableCreatedEvent, |
|||
ViewCreatedEvent, |
|||
ViewCalculationCreatedEvent, |
|||
ViewFilterCreatedEvent, |
|||
AppPublishedEvent, |
|||
UserCreatedEvent, |
|||
RoleAssignedEvent, |
|||
UserPermissionAssignedEvent, |
|||
AppCreatedEvent, |
|||
} from "@budibase/types" |
|||
import * as context from "../context" |
|||
import { CacheKeys } from "../cache/generic" |
|||
import * as cache from "../cache/generic" |
|||
|
|||
// LIFECYCLE
|
|||
|
|||
export const start = async (events: Event[]) => { |
|||
const metadata: BackfillMetadata = { |
|||
eventWhitelist: events, |
|||
} |
|||
return saveBackfillMetadata(metadata) |
|||
} |
|||
|
|||
export const recordEvent = async (event: Event, properties: any) => { |
|||
const eventKey = getEventKey(event, properties) |
|||
// don't use a ttl - cleaned up by migration
|
|||
// don't use tenancy - already in the key
|
|||
await cache.store(eventKey, properties, undefined, { useTenancy: false }) |
|||
} |
|||
|
|||
export const end = async () => { |
|||
await deleteBackfillMetadata() |
|||
await clearEvents() |
|||
} |
|||
|
|||
// CRUD
|
|||
|
|||
const getBackfillMetadata = async (): Promise<BackfillMetadata | null> => { |
|||
return cache.get(CacheKeys.BACKFILL_METADATA) |
|||
} |
|||
|
|||
const saveBackfillMetadata = async ( |
|||
backfill: BackfillMetadata |
|||
): Promise<void> => { |
|||
// no TTL - deleted by backfill
|
|||
return cache.store(CacheKeys.BACKFILL_METADATA, backfill) |
|||
} |
|||
|
|||
const deleteBackfillMetadata = async (): Promise<void> => { |
|||
await cache.delete(CacheKeys.BACKFILL_METADATA) |
|||
} |
|||
|
|||
const clearEvents = async () => { |
|||
// wildcard
|
|||
const pattern = getEventKey() |
|||
const keys = await cache.keys(pattern) |
|||
|
|||
for (const key of keys) { |
|||
// delete each key
|
|||
// don't use tenancy, already in the key
|
|||
await cache.delete(key, { useTenancy: false }) |
|||
} |
|||
} |
|||
|
|||
// HELPERS
|
|||
|
|||
export const isBackfillingEvent = async (event: Event) => { |
|||
const backfill = await getBackfillMetadata() |
|||
const events = backfill?.eventWhitelist |
|||
if (events && events.includes(event)) { |
|||
return true |
|||
} else { |
|||
return false |
|||
} |
|||
} |
|||
|
|||
export const isAlreadySent = async (event: Event, properties: any) => { |
|||
const eventKey = getEventKey(event, properties) |
|||
const cachedEvent: CachedEvent = await cache.get(eventKey, { |
|||
useTenancy: false, |
|||
}) |
|||
return !!cachedEvent |
|||
} |
|||
|
|||
const CUSTOM_PROPERTY_SUFFIX: any = { |
|||
// APP EVENTS
|
|||
[Event.AUTOMATION_CREATED]: (properties: AutomationCreatedEvent) => { |
|||
return properties.automationId |
|||
}, |
|||
[Event.AUTOMATION_STEP_CREATED]: (properties: AutomationStepCreatedEvent) => { |
|||
return properties.stepId |
|||
}, |
|||
[Event.DATASOURCE_CREATED]: (properties: DatasourceCreatedEvent) => { |
|||
return properties.datasourceId |
|||
}, |
|||
[Event.LAYOUT_CREATED]: (properties: LayoutCreatedEvent) => { |
|||
return properties.layoutId |
|||
}, |
|||
[Event.QUERY_CREATED]: (properties: QueryCreatedEvent) => { |
|||
return properties.queryId |
|||
}, |
|||
[Event.ROLE_CREATED]: (properties: RoleCreatedEvent) => { |
|||
return properties.roleId |
|||
}, |
|||
[Event.SCREEN_CREATED]: (properties: ScreenCreatedEvent) => { |
|||
return properties.screenId |
|||
}, |
|||
[Event.TABLE_CREATED]: (properties: TableCreatedEvent) => { |
|||
return properties.tableId |
|||
}, |
|||
[Event.VIEW_CREATED]: (properties: ViewCreatedEvent) => { |
|||
return properties.tableId // best uniqueness
|
|||
}, |
|||
[Event.VIEW_CALCULATION_CREATED]: ( |
|||
properties: ViewCalculationCreatedEvent |
|||
) => { |
|||
return properties.tableId // best uniqueness
|
|||
}, |
|||
[Event.VIEW_FILTER_CREATED]: (properties: ViewFilterCreatedEvent) => { |
|||
return properties.tableId // best uniqueness
|
|||
}, |
|||
[Event.APP_CREATED]: (properties: AppCreatedEvent) => { |
|||
return properties.appId // best uniqueness
|
|||
}, |
|||
[Event.APP_PUBLISHED]: (properties: AppPublishedEvent) => { |
|||
return properties.appId // best uniqueness
|
|||
}, |
|||
// GLOBAL EVENTS
|
|||
[Event.AUTH_SSO_CREATED]: (properties: SSOCreatedEvent) => { |
|||
return properties.type |
|||
}, |
|||
[Event.AUTH_SSO_ACTIVATED]: (properties: SSOCreatedEvent) => { |
|||
return properties.type |
|||
}, |
|||
[Event.USER_CREATED]: (properties: UserCreatedEvent) => { |
|||
return properties.userId |
|||
}, |
|||
[Event.USER_PERMISSION_ADMIN_ASSIGNED]: ( |
|||
properties: UserPermissionAssignedEvent |
|||
) => { |
|||
return properties.userId |
|||
}, |
|||
[Event.USER_PERMISSION_BUILDER_ASSIGNED]: ( |
|||
properties: UserPermissionAssignedEvent |
|||
) => { |
|||
return properties.userId |
|||
}, |
|||
[Event.ROLE_ASSIGNED]: (properties: RoleAssignedEvent) => { |
|||
return `${properties.roleId}-${properties.userId}` |
|||
}, |
|||
} |
|||
|
|||
const getEventKey = (event?: Event, properties?: any) => { |
|||
let eventKey: string |
|||
|
|||
const tenantId = context.getTenantId() |
|||
if (event) { |
|||
eventKey = `${CacheKeys.EVENTS}:${tenantId}:${event}` |
|||
|
|||
// use some properties to make the key more unique
|
|||
const custom = CUSTOM_PROPERTY_SUFFIX[event] |
|||
const suffix = custom ? custom(properties) : undefined |
|||
if (suffix) { |
|||
eventKey = `${eventKey}:${suffix}` |
|||
} |
|||
} else { |
|||
eventKey = `${CacheKeys.EVENTS}:${tenantId}:*` |
|||
} |
|||
|
|||
return eventKey |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
import { Event } from "@budibase/types" |
|||
import { processors } from "./processors" |
|||
import * as identification from "./identification" |
|||
import * as backfill from "./backfill" |
|||
|
|||
export const publishEvent = async ( |
|||
event: Event, |
|||
properties: any, |
|||
timestamp?: string | number |
|||
) => { |
|||
// in future this should use async events via a distributed queue.
|
|||
const identity = await identification.getCurrentIdentity() |
|||
|
|||
const backfilling = await backfill.isBackfillingEvent(event) |
|||
// no backfill - send the event and exit
|
|||
if (!backfilling) { |
|||
await processors.processEvent(event, identity, properties, timestamp) |
|||
return |
|||
} |
|||
|
|||
// backfill active - check if the event has been sent already
|
|||
const alreadySent = await backfill.isAlreadySent(event, properties) |
|||
if (alreadySent) { |
|||
// do nothing
|
|||
return |
|||
} else { |
|||
// send and record the event
|
|||
await processors.processEvent(event, identity, properties, timestamp) |
|||
await backfill.recordEvent(event, properties) |
|||
} |
|||
} |
|||
@ -0,0 +1,302 @@ |
|||
import * as context from "../context" |
|||
import * as identityCtx from "../context/identity" |
|||
import env from "../environment" |
|||
import { |
|||
Hosting, |
|||
User, |
|||
Identity, |
|||
IdentityType, |
|||
Account, |
|||
isCloudAccount, |
|||
isSSOAccount, |
|||
TenantGroup, |
|||
SettingsConfig, |
|||
CloudAccount, |
|||
UserIdentity, |
|||
InstallationGroup, |
|||
UserContext, |
|||
Group, |
|||
} from "@budibase/types" |
|||
import { processors } from "./processors" |
|||
import * as dbUtils from "../db/utils" |
|||
import { Configs } from "../constants" |
|||
import * as hashing from "../hashing" |
|||
import * as installation from "../installation" |
|||
import { withCache, TTL, CacheKeys } from "../cache/generic" |
|||
|
|||
const pkg = require("../../package.json") |
|||
|
|||
/** |
|||
* An identity can be: |
|||
* - account user (Self host) |
|||
* - budibase user |
|||
* - tenant |
|||
* - installation |
|||
*/ |
|||
export const getCurrentIdentity = async (): Promise<Identity> => { |
|||
let identityContext = identityCtx.getIdentity() |
|||
const environment = getDeploymentEnvironment() |
|||
|
|||
let identityType |
|||
|
|||
if (!identityContext) { |
|||
identityType = IdentityType.TENANT |
|||
} else { |
|||
identityType = identityContext.type |
|||
} |
|||
|
|||
if (identityType === IdentityType.INSTALLATION) { |
|||
const installationId = await getInstallationId() |
|||
const hosting = getHostingFromEnv() |
|||
return { |
|||
id: formatDistinctId(installationId, identityType), |
|||
hosting, |
|||
type: identityType, |
|||
installationId, |
|||
environment, |
|||
} |
|||
} else if (identityType === IdentityType.TENANT) { |
|||
const installationId = await getInstallationId() |
|||
const tenantId = await getEventTenantId(context.getTenantId()) |
|||
const hosting = getHostingFromEnv() |
|||
|
|||
return { |
|||
id: formatDistinctId(tenantId, identityType), |
|||
type: identityType, |
|||
hosting, |
|||
installationId, |
|||
tenantId, |
|||
environment, |
|||
} |
|||
} else if (identityType === IdentityType.USER) { |
|||
const userContext = identityContext as UserContext |
|||
const tenantId = await getEventTenantId(context.getTenantId()) |
|||
const installationId = await getInstallationId() |
|||
|
|||
const account = userContext.account |
|||
let hosting |
|||
if (account) { |
|||
hosting = account.hosting |
|||
} else { |
|||
hosting = getHostingFromEnv() |
|||
} |
|||
|
|||
return { |
|||
id: userContext._id, |
|||
type: identityType, |
|||
hosting, |
|||
installationId, |
|||
tenantId, |
|||
environment, |
|||
} |
|||
} else { |
|||
throw new Error("Unknown identity type") |
|||
} |
|||
} |
|||
|
|||
export const identifyInstallationGroup = async ( |
|||
installId: string, |
|||
timestamp?: string | number |
|||
): Promise<void> => { |
|||
const id = installId |
|||
const type = IdentityType.INSTALLATION |
|||
const hosting = getHostingFromEnv() |
|||
const version = pkg.version |
|||
const environment = getDeploymentEnvironment() |
|||
|
|||
const group: InstallationGroup = { |
|||
id, |
|||
type, |
|||
hosting, |
|||
version, |
|||
environment, |
|||
} |
|||
|
|||
await identifyGroup(group, timestamp) |
|||
// need to create a normal identity for the group to be able to query it globally
|
|||
// match the posthog syntax to link this identity to the empty auto generated one
|
|||
await identify({ ...group, id: `$${type}_${id}` }, timestamp) |
|||
} |
|||
|
|||
export const identifyTenantGroup = async ( |
|||
tenantId: string, |
|||
account: Account | undefined, |
|||
timestamp?: string | number |
|||
): Promise<void> => { |
|||
const id = await getEventTenantId(tenantId) |
|||
const type = IdentityType.TENANT |
|||
const installationId = await getInstallationId() |
|||
const environment = getDeploymentEnvironment() |
|||
|
|||
let hosting: Hosting |
|||
let profession: string | undefined |
|||
let companySize: string | undefined |
|||
|
|||
if (account) { |
|||
profession = account.profession |
|||
companySize = account.size |
|||
hosting = account.hosting |
|||
} else { |
|||
hosting = getHostingFromEnv() |
|||
} |
|||
|
|||
const group: TenantGroup = { |
|||
id, |
|||
type, |
|||
hosting, |
|||
environment, |
|||
installationId, |
|||
profession, |
|||
companySize, |
|||
} |
|||
|
|||
await identifyGroup(group, timestamp) |
|||
// need to create a normal identity for the group to be able to query it globally
|
|||
// match the posthog syntax to link this identity to the auto generated one
|
|||
await identify({ ...group, id: `$${type}_${id}` }, timestamp) |
|||
} |
|||
|
|||
export const identifyUser = async ( |
|||
user: User, |
|||
account: CloudAccount | undefined, |
|||
timestamp?: string | number |
|||
) => { |
|||
const id = user._id as string |
|||
const tenantId = await getEventTenantId(user.tenantId) |
|||
const type = IdentityType.USER |
|||
let builder = user.builder?.global || false |
|||
let admin = user.admin?.global || false |
|||
let providerType = user.providerType |
|||
const accountHolder = account?.budibaseUserId === user._id || false |
|||
const verified = |
|||
account && account?.budibaseUserId === user._id ? account.verified : false |
|||
const installationId = await getInstallationId() |
|||
const hosting = account ? account.hosting : getHostingFromEnv() |
|||
const environment = getDeploymentEnvironment() |
|||
|
|||
const identity: UserIdentity = { |
|||
id, |
|||
type, |
|||
hosting, |
|||
installationId, |
|||
tenantId, |
|||
verified, |
|||
accountHolder, |
|||
providerType, |
|||
builder, |
|||
admin, |
|||
environment, |
|||
} |
|||
|
|||
await identify(identity, timestamp) |
|||
} |
|||
|
|||
export const identifyAccount = async (account: Account) => { |
|||
let id = account.accountId |
|||
const tenantId = account.tenantId |
|||
let type = IdentityType.USER |
|||
let providerType = isSSOAccount(account) ? account.providerType : undefined |
|||
const verified = account.verified |
|||
const accountHolder = true |
|||
const hosting = account.hosting |
|||
const installationId = await getInstallationId() |
|||
const environment = getDeploymentEnvironment() |
|||
|
|||
if (isCloudAccount(account)) { |
|||
if (account.budibaseUserId) { |
|||
// use the budibase user as the id if set
|
|||
id = account.budibaseUserId |
|||
} |
|||
} |
|||
|
|||
const identity: UserIdentity = { |
|||
id, |
|||
type, |
|||
hosting, |
|||
installationId, |
|||
tenantId, |
|||
providerType, |
|||
verified, |
|||
accountHolder, |
|||
environment, |
|||
} |
|||
|
|||
await identify(identity) |
|||
} |
|||
|
|||
export const identify = async ( |
|||
identity: Identity, |
|||
timestamp?: string | number |
|||
) => { |
|||
await processors.identify(identity, timestamp) |
|||
} |
|||
|
|||
export const identifyGroup = async ( |
|||
group: Group, |
|||
timestamp?: string | number |
|||
) => { |
|||
await processors.identifyGroup(group, timestamp) |
|||
} |
|||
|
|||
const getDeploymentEnvironment = () => { |
|||
if (env.isDev()) { |
|||
return "development" |
|||
} else { |
|||
return env.DEPLOYMENT_ENVIRONMENT |
|||
} |
|||
} |
|||
|
|||
const getHostingFromEnv = () => { |
|||
return env.SELF_HOSTED ? Hosting.SELF : Hosting.CLOUD |
|||
} |
|||
|
|||
export const getInstallationId = async () => { |
|||
if (isAccountPortal()) { |
|||
return "account-portal" |
|||
} |
|||
const install = await installation.getInstall() |
|||
return install.installId |
|||
} |
|||
|
|||
const getEventTenantId = async (tenantId: string): Promise<string> => { |
|||
if (env.SELF_HOSTED) { |
|||
return getUniqueTenantId(tenantId) |
|||
} else { |
|||
// tenant id's in the cloud are already unique
|
|||
return tenantId |
|||
} |
|||
} |
|||
|
|||
const getUniqueTenantId = async (tenantId: string): Promise<string> => { |
|||
// make sure this tenantId always matches the tenantId in context
|
|||
return context.doInTenant(tenantId, () => { |
|||
return withCache(CacheKeys.UNIQUE_TENANT_ID, TTL.ONE_DAY, async () => { |
|||
const db = context.getGlobalDB() |
|||
const config: SettingsConfig = await dbUtils.getScopedFullConfig(db, { |
|||
type: Configs.SETTINGS, |
|||
}) |
|||
|
|||
let uniqueTenantId: string |
|||
if (config.config.uniqueTenantId) { |
|||
return config.config.uniqueTenantId |
|||
} else { |
|||
uniqueTenantId = `${hashing.newid()}_${tenantId}` |
|||
config.config.uniqueTenantId = uniqueTenantId |
|||
await db.put(config) |
|||
return uniqueTenantId |
|||
} |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
const isAccountPortal = () => { |
|||
return env.SERVICE === "account-portal" |
|||
} |
|||
|
|||
const formatDistinctId = (id: string, type: IdentityType) => { |
|||
if (type === IdentityType.INSTALLATION || type === IdentityType.TENANT) { |
|||
return `$${type}_${id}` |
|||
} else { |
|||
return id |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
export * from "./publishers" |
|||
export * as processors from "./processors" |
|||
export * as analytics from "./analytics" |
|||
export * as identification from "./identification" |
|||
export * as backfillCache from "./backfill" |
|||
|
|||
import { processors } from "./processors" |
|||
|
|||
export const shutdown = () => { |
|||
processors.shutdown() |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
import { Event, Identity, Group, IdentityType } from "@budibase/types" |
|||
import { EventProcessor } from "./types" |
|||
import env from "../../environment" |
|||
import * as analytics from "../analytics" |
|||
import PosthogProcessor from "./PosthogProcessor" |
|||
|
|||
/** |
|||
* Events that are always captured. |
|||
*/ |
|||
const EVENT_WHITELIST = [ |
|||
Event.INSTALLATION_VERSION_UPGRADED, |
|||
Event.INSTALLATION_VERSION_DOWNGRADED, |
|||
] |
|||
const IDENTITY_WHITELIST = [IdentityType.INSTALLATION, IdentityType.TENANT] |
|||
|
|||
export default class AnalyticsProcessor implements EventProcessor { |
|||
posthog: PosthogProcessor | undefined |
|||
|
|||
constructor() { |
|||
if (env.POSTHOG_TOKEN && !env.isTest()) { |
|||
this.posthog = new PosthogProcessor(env.POSTHOG_TOKEN) |
|||
} |
|||
} |
|||
|
|||
async processEvent( |
|||
event: Event, |
|||
identity: Identity, |
|||
properties: any, |
|||
timestamp?: string | number |
|||
): Promise<void> { |
|||
if (!EVENT_WHITELIST.includes(event) && !(await analytics.enabled())) { |
|||
return |
|||
} |
|||
if (this.posthog) { |
|||
this.posthog.processEvent(event, identity, properties, timestamp) |
|||
} |
|||
} |
|||
|
|||
async identify(identity: Identity, timestamp?: string | number) { |
|||
// Group indentifications (tenant and installation) always on
|
|||
if ( |
|||
!IDENTITY_WHITELIST.includes(identity.type) && |
|||
!(await analytics.enabled()) |
|||
) { |
|||
return |
|||
} |
|||
if (this.posthog) { |
|||
this.posthog.identify(identity, timestamp) |
|||
} |
|||
} |
|||
|
|||
async identifyGroup(group: Group, timestamp?: string | number) { |
|||
// Group indentifications (tenant and installation) always on
|
|||
if (this.posthog) { |
|||
this.posthog.identifyGroup(group, timestamp) |
|||
} |
|||
} |
|||
|
|||
shutdown() { |
|||
if (this.posthog) { |
|||
this.posthog.shutdown() |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
import { Event, Identity, Group } from "@budibase/types" |
|||
import { EventProcessor } from "./types" |
|||
import env from "../../environment" |
|||
|
|||
const getTimestampString = (timestamp?: string | number) => { |
|||
let timestampString = "" |
|||
if (timestamp) { |
|||
timestampString = `[timestamp=${new Date(timestamp).toISOString()}]` |
|||
} |
|||
return timestampString |
|||
} |
|||
|
|||
const skipLogging = env.SELF_HOSTED && !env.isDev() |
|||
|
|||
export default class LoggingProcessor implements EventProcessor { |
|||
async processEvent( |
|||
event: Event, |
|||
identity: Identity, |
|||
properties: any, |
|||
timestamp?: string |
|||
): Promise<void> { |
|||
if (skipLogging) { |
|||
return |
|||
} |
|||
let timestampString = getTimestampString(timestamp) |
|||
console.log( |
|||
`[audit] [tenant=${identity.tenantId}] [identityType=${identity.type}] [identity=${identity.id}] ${timestampString} ${event} ` |
|||
) |
|||
} |
|||
|
|||
async identify(identity: Identity, timestamp?: string | number) { |
|||
if (skipLogging) { |
|||
return |
|||
} |
|||
let timestampString = getTimestampString(timestamp) |
|||
console.log( |
|||
`[audit] [${JSON.stringify(identity)}] ${timestampString} identified` |
|||
) |
|||
} |
|||
|
|||
async identifyGroup(group: Group, timestamp?: string | number) { |
|||
if (skipLogging) { |
|||
return |
|||
} |
|||
let timestampString = getTimestampString(timestamp) |
|||
console.log( |
|||
`[audit] [${JSON.stringify(group)}] ${timestampString} group identified` |
|||
) |
|||
} |
|||
|
|||
shutdown(): void { |
|||
// no-op
|
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
import PostHog from "posthog-node" |
|||
import { Event, Identity, Group, BaseEvent } from "@budibase/types" |
|||
import { EventProcessor } from "./types" |
|||
import env from "../../environment" |
|||
import context from "../../context" |
|||
const pkg = require("../../../package.json") |
|||
|
|||
export default class PosthogProcessor implements EventProcessor { |
|||
posthog: PostHog |
|||
|
|||
constructor(token: string | undefined) { |
|||
if (!token) { |
|||
throw new Error("Posthog token is not defined") |
|||
} |
|||
this.posthog = new PostHog(token) |
|||
} |
|||
|
|||
async processEvent( |
|||
event: Event, |
|||
identity: Identity, |
|||
properties: BaseEvent, |
|||
timestamp?: string | number |
|||
): Promise<void> { |
|||
properties.version = pkg.version |
|||
properties.service = env.SERVICE |
|||
properties.environment = identity.environment |
|||
properties.hosting = identity.hosting |
|||
|
|||
const appId = context.getAppId() |
|||
if (appId) { |
|||
properties.appId = appId |
|||
} |
|||
|
|||
const payload: any = { distinctId: identity.id, event, properties } |
|||
|
|||
if (timestamp) { |
|||
payload.timestamp = new Date(timestamp) |
|||
} |
|||
|
|||
// add groups to the event
|
|||
if (identity.installationId || identity.tenantId) { |
|||
payload.groups = {} |
|||
if (identity.installationId) { |
|||
payload.groups.installation = identity.installationId |
|||
payload.properties.installationId = identity.installationId |
|||
} |
|||
if (identity.tenantId) { |
|||
payload.groups.tenant = identity.tenantId |
|||
payload.properties.tenantId = identity.tenantId |
|||
} |
|||
} |
|||
|
|||
this.posthog.capture(payload) |
|||
} |
|||
|
|||
async identify(identity: Identity, timestamp?: string | number) { |
|||
const payload: any = { distinctId: identity.id, properties: identity } |
|||
if (timestamp) { |
|||
payload.timestamp = new Date(timestamp) |
|||
} |
|||
this.posthog.identify(payload) |
|||
} |
|||
|
|||
async identifyGroup(group: Group, timestamp?: string | number) { |
|||
const payload: any = { |
|||
distinctId: group.id, |
|||
groupType: group.type, |
|||
groupKey: group.id, |
|||
properties: group, |
|||
} |
|||
|
|||
if (timestamp) { |
|||
payload.timestamp = new Date(timestamp) |
|||
} |
|||
this.posthog.groupIdentify(payload) |
|||
} |
|||
|
|||
shutdown() { |
|||
this.posthog.shutdown() |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
import { Event, Identity, Group } from "@budibase/types" |
|||
import { EventProcessor } from "./types" |
|||
|
|||
export default class Processor implements EventProcessor { |
|||
initialised: boolean = false |
|||
processors: EventProcessor[] = [] |
|||
|
|||
constructor(processors: EventProcessor[]) { |
|||
this.processors = processors |
|||
} |
|||
|
|||
async processEvent( |
|||
event: Event, |
|||
identity: Identity, |
|||
properties: any, |
|||
timestamp?: string | number |
|||
): Promise<void> { |
|||
for (const eventProcessor of this.processors) { |
|||
await eventProcessor.processEvent(event, identity, properties, timestamp) |
|||
} |
|||
} |
|||
|
|||
async identify( |
|||
identity: Identity, |
|||
timestamp?: string | number |
|||
): Promise<void> { |
|||
for (const eventProcessor of this.processors) { |
|||
await eventProcessor.identify(identity, timestamp) |
|||
} |
|||
} |
|||
|
|||
async identifyGroup( |
|||
identity: Group, |
|||
timestamp?: string | number |
|||
): Promise<void> { |
|||
for (const eventProcessor of this.processors) { |
|||
await eventProcessor.identifyGroup(identity, timestamp) |
|||
} |
|||
} |
|||
|
|||
shutdown() { |
|||
for (const eventProcessor of this.processors) { |
|||
eventProcessor.shutdown() |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
import AnalyticsProcessor from "./AnalyticsProcessor" |
|||
import LoggingProcessor from "./LoggingProcessor" |
|||
import Processors from "./Processors" |
|||
|
|||
export const analyticsProcessor = new AnalyticsProcessor() |
|||
const loggingProcessor = new LoggingProcessor() |
|||
|
|||
export const processors = new Processors([analyticsProcessor, loggingProcessor]) |
|||
@ -0,0 +1,18 @@ |
|||
import { Event, Identity, Group } from "@budibase/types" |
|||
|
|||
export enum EventProcessorType { |
|||
POSTHOG = "posthog", |
|||
LOGGING = "logging", |
|||
} |
|||
|
|||
export interface EventProcessor { |
|||
processEvent( |
|||
event: Event, |
|||
identity: Identity, |
|||
properties: any, |
|||
timestamp?: string | number |
|||
): Promise<void> |
|||
identify(identity: Identity, timestamp?: string | number): Promise<void> |
|||
identifyGroup(group: Group, timestamp?: string | number): Promise<void> |
|||
shutdown(): void |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
Account, |
|||
AccountCreatedEvent, |
|||
AccountDeletedEvent, |
|||
AccountVerifiedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export async function created(account: Account) { |
|||
const properties: AccountCreatedEvent = { |
|||
tenantId: account.tenantId, |
|||
} |
|||
await publishEvent(Event.ACCOUNT_CREATED, properties) |
|||
} |
|||
|
|||
export async function deleted(account: Account) { |
|||
const properties: AccountDeletedEvent = { |
|||
tenantId: account.tenantId, |
|||
} |
|||
await publishEvent(Event.ACCOUNT_DELETED, properties) |
|||
} |
|||
|
|||
export async function verified(account: Account) { |
|||
const properties: AccountVerifiedEvent = { |
|||
tenantId: account.tenantId, |
|||
} |
|||
await publishEvent(Event.ACCOUNT_VERIFIED, properties) |
|||
} |
|||
@ -0,0 +1,108 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
App, |
|||
AppCreatedEvent, |
|||
AppUpdatedEvent, |
|||
AppDeletedEvent, |
|||
AppPublishedEvent, |
|||
AppUnpublishedEvent, |
|||
AppFileImportedEvent, |
|||
AppTemplateImportedEvent, |
|||
AppVersionUpdatedEvent, |
|||
AppVersionRevertedEvent, |
|||
AppRevertedEvent, |
|||
AppExportedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export const created = async (app: App, timestamp?: string | number) => { |
|||
const properties: AppCreatedEvent = { |
|||
appId: app.appId, |
|||
version: app.version, |
|||
} |
|||
await publishEvent(Event.APP_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function updated(app: App) { |
|||
const properties: AppUpdatedEvent = { |
|||
appId: app.appId, |
|||
version: app.version, |
|||
} |
|||
await publishEvent(Event.APP_UPDATED, properties) |
|||
} |
|||
|
|||
export async function deleted(app: App) { |
|||
const properties: AppDeletedEvent = { |
|||
appId: app.appId, |
|||
} |
|||
await publishEvent(Event.APP_DELETED, properties) |
|||
} |
|||
|
|||
export async function published(app: App, timestamp?: string | number) { |
|||
const properties: AppPublishedEvent = { |
|||
appId: app.appId, |
|||
} |
|||
await publishEvent(Event.APP_PUBLISHED, properties, timestamp) |
|||
} |
|||
|
|||
export async function unpublished(app: App) { |
|||
const properties: AppUnpublishedEvent = { |
|||
appId: app.appId, |
|||
} |
|||
await publishEvent(Event.APP_UNPUBLISHED, properties) |
|||
} |
|||
|
|||
export async function fileImported(app: App) { |
|||
const properties: AppFileImportedEvent = { |
|||
appId: app.appId, |
|||
} |
|||
await publishEvent(Event.APP_FILE_IMPORTED, properties) |
|||
} |
|||
|
|||
export async function templateImported(app: App, templateKey: string) { |
|||
const properties: AppTemplateImportedEvent = { |
|||
appId: app.appId, |
|||
templateKey, |
|||
} |
|||
await publishEvent(Event.APP_TEMPLATE_IMPORTED, properties) |
|||
} |
|||
|
|||
export async function versionUpdated( |
|||
app: App, |
|||
currentVersion: string, |
|||
updatedToVersion: string |
|||
) { |
|||
const properties: AppVersionUpdatedEvent = { |
|||
appId: app.appId, |
|||
currentVersion, |
|||
updatedToVersion, |
|||
} |
|||
await publishEvent(Event.APP_VERSION_UPDATED, properties) |
|||
} |
|||
|
|||
export async function versionReverted( |
|||
app: App, |
|||
currentVersion: string, |
|||
revertedToVersion: string |
|||
) { |
|||
const properties: AppVersionRevertedEvent = { |
|||
appId: app.appId, |
|||
currentVersion, |
|||
revertedToVersion, |
|||
} |
|||
await publishEvent(Event.APP_VERSION_REVERTED, properties) |
|||
} |
|||
|
|||
export async function reverted(app: App) { |
|||
const properties: AppRevertedEvent = { |
|||
appId: app.appId, |
|||
} |
|||
await publishEvent(Event.APP_REVERTED, properties) |
|||
} |
|||
|
|||
export async function exported(app: App) { |
|||
const properties: AppExportedEvent = { |
|||
appId: app.appId, |
|||
} |
|||
await publishEvent(Event.APP_EXPORTED, properties) |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
LoginEvent, |
|||
LoginSource, |
|||
LogoutEvent, |
|||
SSOActivatedEvent, |
|||
SSOCreatedEvent, |
|||
SSODeactivatedEvent, |
|||
SSOType, |
|||
SSOUpdatedEvent, |
|||
} from "@budibase/types" |
|||
import { identification } from ".." |
|||
|
|||
export async function login(source: LoginSource) { |
|||
const identity = await identification.getCurrentIdentity() |
|||
const properties: LoginEvent = { |
|||
userId: identity.id, |
|||
source, |
|||
} |
|||
await publishEvent(Event.AUTH_LOGIN, properties) |
|||
} |
|||
|
|||
export async function logout() { |
|||
const identity = await identification.getCurrentIdentity() |
|||
const properties: LogoutEvent = { |
|||
userId: identity.id, |
|||
} |
|||
await publishEvent(Event.AUTH_LOGOUT, properties) |
|||
} |
|||
|
|||
export async function SSOCreated(type: SSOType, timestamp?: string | number) { |
|||
const properties: SSOCreatedEvent = { |
|||
type, |
|||
} |
|||
await publishEvent(Event.AUTH_SSO_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function SSOUpdated(type: SSOType) { |
|||
const properties: SSOUpdatedEvent = { |
|||
type, |
|||
} |
|||
await publishEvent(Event.AUTH_SSO_UPDATED, properties) |
|||
} |
|||
|
|||
export async function SSOActivated(type: SSOType, timestamp?: string | number) { |
|||
const properties: SSOActivatedEvent = { |
|||
type, |
|||
} |
|||
await publishEvent(Event.AUTH_SSO_ACTIVATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function SSODeactivated(type: SSOType) { |
|||
const properties: SSODeactivatedEvent = { |
|||
type, |
|||
} |
|||
await publishEvent(Event.AUTH_SSO_DEACTIVATED, properties) |
|||
} |
|||
@ -0,0 +1,94 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Automation, |
|||
Event, |
|||
AutomationStep, |
|||
AutomationCreatedEvent, |
|||
AutomationDeletedEvent, |
|||
AutomationTestedEvent, |
|||
AutomationStepCreatedEvent, |
|||
AutomationStepDeletedEvent, |
|||
AutomationTriggerUpdatedEvent, |
|||
AutomationsRunEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export async function created( |
|||
automation: Automation, |
|||
timestamp?: string | number |
|||
) { |
|||
const properties: AutomationCreatedEvent = { |
|||
appId: automation.appId, |
|||
automationId: automation._id as string, |
|||
triggerId: automation.definition?.trigger?.id, |
|||
triggerType: automation.definition?.trigger?.stepId, |
|||
} |
|||
await publishEvent(Event.AUTOMATION_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function triggerUpdated(automation: Automation) { |
|||
const properties: AutomationTriggerUpdatedEvent = { |
|||
appId: automation.appId, |
|||
automationId: automation._id as string, |
|||
triggerId: automation.definition?.trigger?.id, |
|||
triggerType: automation.definition?.trigger?.stepId, |
|||
} |
|||
await publishEvent(Event.AUTOMATION_TRIGGER_UPDATED, properties) |
|||
} |
|||
|
|||
export async function deleted(automation: Automation) { |
|||
const properties: AutomationDeletedEvent = { |
|||
appId: automation.appId, |
|||
automationId: automation._id as string, |
|||
triggerId: automation.definition?.trigger?.id, |
|||
triggerType: automation.definition?.trigger?.stepId, |
|||
} |
|||
await publishEvent(Event.AUTOMATION_DELETED, properties) |
|||
} |
|||
|
|||
export async function tested(automation: Automation) { |
|||
const properties: AutomationTestedEvent = { |
|||
appId: automation.appId, |
|||
automationId: automation._id as string, |
|||
triggerId: automation.definition?.trigger?.id, |
|||
triggerType: automation.definition?.trigger?.stepId, |
|||
} |
|||
await publishEvent(Event.AUTOMATION_TESTED, properties) |
|||
} |
|||
|
|||
export const run = async (count: number, timestamp?: string | number) => { |
|||
const properties: AutomationsRunEvent = { |
|||
count, |
|||
} |
|||
await publishEvent(Event.AUTOMATIONS_RUN, properties, timestamp) |
|||
} |
|||
|
|||
export async function stepCreated( |
|||
automation: Automation, |
|||
step: AutomationStep, |
|||
timestamp?: string | number |
|||
) { |
|||
const properties: AutomationStepCreatedEvent = { |
|||
appId: automation.appId, |
|||
automationId: automation._id as string, |
|||
triggerId: automation.definition?.trigger?.id, |
|||
triggerType: automation.definition?.trigger?.stepId, |
|||
stepId: step.id, |
|||
stepType: step.stepId, |
|||
} |
|||
await publishEvent(Event.AUTOMATION_STEP_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function stepDeleted( |
|||
automation: Automation, |
|||
step: AutomationStep |
|||
) { |
|||
const properties: AutomationStepDeletedEvent = { |
|||
appId: automation.appId, |
|||
automationId: automation._id as string, |
|||
triggerId: automation.definition?.trigger?.id, |
|||
triggerType: automation.definition?.trigger?.stepId, |
|||
stepId: step.id, |
|||
stepType: step.stepId, |
|||
} |
|||
await publishEvent(Event.AUTOMATION_STEP_DELETED, properties) |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
AppBackfillSucceededEvent, |
|||
AppBackfillFailedEvent, |
|||
TenantBackfillSucceededEvent, |
|||
TenantBackfillFailedEvent, |
|||
InstallationBackfillSucceededEvent, |
|||
InstallationBackfillFailedEvent, |
|||
} from "@budibase/types" |
|||
const env = require("../../environment") |
|||
|
|||
const shouldSkip = !env.SELF_HOSTED && !env.isDev() |
|||
|
|||
export async function appSucceeded(properties: AppBackfillSucceededEvent) { |
|||
if (shouldSkip) { |
|||
return |
|||
} |
|||
await publishEvent(Event.APP_BACKFILL_SUCCEEDED, properties) |
|||
} |
|||
|
|||
export async function appFailed(error: any) { |
|||
if (shouldSkip) { |
|||
return |
|||
} |
|||
const properties: AppBackfillFailedEvent = { |
|||
error: JSON.stringify(error, Object.getOwnPropertyNames(error)), |
|||
} |
|||
await publishEvent(Event.APP_BACKFILL_FAILED, properties) |
|||
} |
|||
|
|||
export async function tenantSucceeded( |
|||
properties: TenantBackfillSucceededEvent |
|||
) { |
|||
if (shouldSkip) { |
|||
return |
|||
} |
|||
await publishEvent(Event.TENANT_BACKFILL_SUCCEEDED, properties) |
|||
} |
|||
|
|||
export async function tenantFailed(error: any) { |
|||
if (shouldSkip) { |
|||
return |
|||
} |
|||
const properties: TenantBackfillFailedEvent = { |
|||
error: JSON.stringify(error, Object.getOwnPropertyNames(error)), |
|||
} |
|||
await publishEvent(Event.TENANT_BACKFILL_FAILED, properties) |
|||
} |
|||
|
|||
export async function installationSucceeded() { |
|||
if (shouldSkip) { |
|||
return |
|||
} |
|||
const properties: InstallationBackfillSucceededEvent = {} |
|||
await publishEvent(Event.INSTALLATION_BACKFILL_SUCCEEDED, properties) |
|||
} |
|||
|
|||
export async function installationFailed(error: any) { |
|||
if (shouldSkip) { |
|||
return |
|||
} |
|||
const properties: InstallationBackfillFailedEvent = { |
|||
error: JSON.stringify(error, Object.getOwnPropertyNames(error)), |
|||
} |
|||
await publishEvent(Event.INSTALLATION_BACKFILL_FAILED, properties) |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
Datasource, |
|||
DatasourceCreatedEvent, |
|||
DatasourceUpdatedEvent, |
|||
DatasourceDeletedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export async function created( |
|||
datasource: Datasource, |
|||
timestamp?: string | number |
|||
) { |
|||
const properties: DatasourceCreatedEvent = { |
|||
datasourceId: datasource._id as string, |
|||
source: datasource.source, |
|||
} |
|||
await publishEvent(Event.DATASOURCE_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function updated(datasource: Datasource) { |
|||
const properties: DatasourceUpdatedEvent = { |
|||
datasourceId: datasource._id as string, |
|||
source: datasource.source, |
|||
} |
|||
await publishEvent(Event.DATASOURCE_UPDATED, properties) |
|||
} |
|||
|
|||
export async function deleted(datasource: Datasource) { |
|||
const properties: DatasourceDeletedEvent = { |
|||
datasourceId: datasource._id as string, |
|||
source: datasource.source, |
|||
} |
|||
await publishEvent(Event.DATASOURCE_DELETED, properties) |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
import { publishEvent } from "../events" |
|||
import { Event, SMTPCreatedEvent, SMTPUpdatedEvent } from "@budibase/types" |
|||
|
|||
export async function SMTPCreated(timestamp?: string | number) { |
|||
const properties: SMTPCreatedEvent = {} |
|||
await publishEvent(Event.EMAIL_SMTP_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function SMTPUpdated() { |
|||
const properties: SMTPUpdatedEvent = {} |
|||
await publishEvent(Event.EMAIL_SMTP_UPDATED, properties) |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
export * as account from "./account" |
|||
export * as app from "./app" |
|||
export * as auth from "./auth" |
|||
export * as automation from "./automation" |
|||
export * as datasource from "./datasource" |
|||
export * as email from "./email" |
|||
export * as license from "./license" |
|||
export * as layout from "./layout" |
|||
export * as org from "./org" |
|||
export * as query from "./query" |
|||
export * as role from "./role" |
|||
export * as screen from "./screen" |
|||
export * as rows from "./rows" |
|||
export * as table from "./table" |
|||
export * as serve from "./serve" |
|||
export * as user from "./user" |
|||
export * as view from "./view" |
|||
export * as installation from "./installation" |
|||
export * as backfill from "./backfill" |
|||
@ -0,0 +1,31 @@ |
|||
import { publishEvent } from "../events" |
|||
import { Event, VersionCheckedEvent, VersionChangeEvent } from "@budibase/types" |
|||
|
|||
export async function versionChecked(version: string) { |
|||
const properties: VersionCheckedEvent = { |
|||
currentVersion: version, |
|||
} |
|||
await publishEvent(Event.INSTALLATION_VERSION_CHECKED, properties) |
|||
} |
|||
|
|||
export async function upgraded(from: string, to: string) { |
|||
const properties: VersionChangeEvent = { |
|||
from, |
|||
to, |
|||
} |
|||
|
|||
await publishEvent(Event.INSTALLATION_VERSION_UPGRADED, properties) |
|||
} |
|||
|
|||
export async function downgraded(from: string, to: string) { |
|||
const properties: VersionChangeEvent = { |
|||
from, |
|||
to, |
|||
} |
|||
await publishEvent(Event.INSTALLATION_VERSION_DOWNGRADED, properties) |
|||
} |
|||
|
|||
export async function firstStartup() { |
|||
const properties = {} |
|||
await publishEvent(Event.INSTALLATION_FIRST_STARTUP, properties) |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
Layout, |
|||
LayoutCreatedEvent, |
|||
LayoutDeletedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export async function created(layout: Layout, timestamp?: string | number) { |
|||
const properties: LayoutCreatedEvent = { |
|||
layoutId: layout._id as string, |
|||
} |
|||
await publishEvent(Event.LAYOUT_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function deleted(layoutId: string) { |
|||
const properties: LayoutDeletedEvent = { |
|||
layoutId, |
|||
} |
|||
await publishEvent(Event.LAYOUT_DELETED, properties) |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
License, |
|||
LicenseActivatedEvent, |
|||
LicenseDowngradedEvent, |
|||
LicenseUpdatedEvent, |
|||
LicenseUpgradedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
// TODO
|
|||
export async function updgraded(license: License) { |
|||
const properties: LicenseUpgradedEvent = {} |
|||
await publishEvent(Event.LICENSE_UPGRADED, properties) |
|||
} |
|||
|
|||
// TODO
|
|||
export async function downgraded(license: License) { |
|||
const properties: LicenseDowngradedEvent = {} |
|||
await publishEvent(Event.LICENSE_DOWNGRADED, properties) |
|||
} |
|||
|
|||
// TODO
|
|||
export async function updated(license: License) { |
|||
const properties: LicenseUpdatedEvent = {} |
|||
await publishEvent(Event.LICENSE_UPDATED, properties) |
|||
} |
|||
|
|||
// TODO
|
|||
export async function activated(license: License) { |
|||
const properties: LicenseActivatedEvent = {} |
|||
await publishEvent(Event.LICENSE_ACTIVATED, properties) |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
import { publishEvent } from "../events" |
|||
import { Event } from "@budibase/types" |
|||
|
|||
export async function nameUpdated(timestamp?: string | number) { |
|||
const properties = {} |
|||
await publishEvent(Event.ORG_NAME_UPDATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function logoUpdated(timestamp?: string | number) { |
|||
const properties = {} |
|||
await publishEvent(Event.ORG_LOGO_UPDATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function platformURLUpdated(timestamp?: string | number) { |
|||
const properties = {} |
|||
await publishEvent(Event.ORG_PLATFORM_URL_UPDATED, properties, timestamp) |
|||
} |
|||
|
|||
// TODO
|
|||
|
|||
export async function analyticsOptOut() { |
|||
const properties = {} |
|||
await publishEvent(Event.ANALYTICS_OPT_OUT, properties) |
|||
} |
|||
|
|||
export async function analyticsOptIn() { |
|||
const properties = {} |
|||
await publishEvent(Event.ANALYTICS_OPT_OUT, properties) |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
Datasource, |
|||
Query, |
|||
QueryCreatedEvent, |
|||
QueryUpdatedEvent, |
|||
QueryDeletedEvent, |
|||
QueryImportedEvent, |
|||
QueryPreviewedEvent, |
|||
QueriesRunEvent, |
|||
} from "@budibase/types" |
|||
|
|||
/* eslint-disable */ |
|||
|
|||
export const created = async ( |
|||
datasource: Datasource, |
|||
query: Query, |
|||
timestamp?: string | number |
|||
) => { |
|||
const properties: QueryCreatedEvent = { |
|||
queryId: query._id as string, |
|||
datasourceId: datasource._id as string, |
|||
source: datasource.source, |
|||
queryVerb: query.queryVerb, |
|||
} |
|||
await publishEvent(Event.QUERY_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export const updated = async (datasource: Datasource, query: Query) => { |
|||
const properties: QueryUpdatedEvent = { |
|||
queryId: query._id as string, |
|||
datasourceId: datasource._id as string, |
|||
source: datasource.source, |
|||
queryVerb: query.queryVerb, |
|||
} |
|||
await publishEvent(Event.QUERY_UPDATED, properties) |
|||
} |
|||
|
|||
export const deleted = async (datasource: Datasource, query: Query) => { |
|||
const properties: QueryDeletedEvent = { |
|||
queryId: query._id as string, |
|||
datasourceId: datasource._id as string, |
|||
source: datasource.source, |
|||
queryVerb: query.queryVerb, |
|||
} |
|||
await publishEvent(Event.QUERY_DELETED, properties) |
|||
} |
|||
|
|||
export const imported = async ( |
|||
datasource: Datasource, |
|||
importSource: any, |
|||
count: any |
|||
) => { |
|||
const properties: QueryImportedEvent = { |
|||
datasourceId: datasource._id as string, |
|||
source: datasource.source, |
|||
count, |
|||
importSource, |
|||
} |
|||
await publishEvent(Event.QUERY_IMPORT, properties) |
|||
} |
|||
|
|||
export const run = async (count: number, timestamp?: string | number) => { |
|||
const properties: QueriesRunEvent = { |
|||
count, |
|||
} |
|||
await publishEvent(Event.QUERIES_RUN, properties, timestamp) |
|||
} |
|||
|
|||
export const previewed = async (datasource: Datasource, query: Query) => { |
|||
const properties: QueryPreviewedEvent = { |
|||
queryId: query._id, |
|||
datasourceId: datasource._id as string, |
|||
source: datasource.source, |
|||
queryVerb: query.queryVerb, |
|||
} |
|||
await publishEvent(Event.QUERY_PREVIEWED, properties) |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
Role, |
|||
RoleAssignedEvent, |
|||
RoleCreatedEvent, |
|||
RoleDeletedEvent, |
|||
RoleUnassignedEvent, |
|||
RoleUpdatedEvent, |
|||
User, |
|||
} from "@budibase/types" |
|||
|
|||
export async function created(role: Role, timestamp?: string | number) { |
|||
const properties: RoleCreatedEvent = { |
|||
roleId: role._id as string, |
|||
permissionId: role.permissionId, |
|||
inherits: role.inherits, |
|||
} |
|||
await publishEvent(Event.ROLE_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function updated(role: Role) { |
|||
const properties: RoleUpdatedEvent = { |
|||
roleId: role._id as string, |
|||
permissionId: role.permissionId, |
|||
inherits: role.inherits, |
|||
} |
|||
await publishEvent(Event.ROLE_UPDATED, properties) |
|||
} |
|||
|
|||
export async function deleted(role: Role) { |
|||
const properties: RoleDeletedEvent = { |
|||
roleId: role._id as string, |
|||
permissionId: role.permissionId, |
|||
inherits: role.inherits, |
|||
} |
|||
await publishEvent(Event.ROLE_DELETED, properties) |
|||
} |
|||
|
|||
export async function assigned(user: User, roleId: string, timestamp?: number) { |
|||
const properties: RoleAssignedEvent = { |
|||
userId: user._id as string, |
|||
roleId, |
|||
} |
|||
await publishEvent(Event.ROLE_ASSIGNED, properties, timestamp) |
|||
} |
|||
|
|||
export async function unassigned(user: User, roleId: string) { |
|||
const properties: RoleUnassignedEvent = { |
|||
userId: user._id as string, |
|||
roleId, |
|||
} |
|||
await publishEvent(Event.ROLE_UNASSIGNED, properties) |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
RowsImportedEvent, |
|||
RowsCreatedEvent, |
|||
RowImportFormat, |
|||
Table, |
|||
} from "@budibase/types" |
|||
|
|||
/* eslint-disable */ |
|||
|
|||
export const created = async (count: number, timestamp?: string | number) => { |
|||
const properties: RowsCreatedEvent = { |
|||
count, |
|||
} |
|||
await publishEvent(Event.ROWS_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export const imported = async ( |
|||
table: Table, |
|||
format: RowImportFormat, |
|||
count: number |
|||
) => { |
|||
const properties: RowsImportedEvent = { |
|||
tableId: table._id as string, |
|||
format, |
|||
count, |
|||
} |
|||
await publishEvent(Event.ROWS_IMPORTED, properties) |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
Screen, |
|||
ScreenCreatedEvent, |
|||
ScreenDeletedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export async function created(screen: Screen, timestamp?: string | number) { |
|||
const properties: ScreenCreatedEvent = { |
|||
layoutId: screen.layoutId, |
|||
screenId: screen._id as string, |
|||
roleId: screen.routing.roleId, |
|||
} |
|||
await publishEvent(Event.SCREEN_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function deleted(screen: Screen) { |
|||
const properties: ScreenDeletedEvent = { |
|||
layoutId: screen.layoutId, |
|||
screenId: screen._id as string, |
|||
roleId: screen.routing.roleId, |
|||
} |
|||
await publishEvent(Event.SCREEN_DELETED, properties) |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
App, |
|||
BuilderServedEvent, |
|||
Event, |
|||
AppPreviewServedEvent, |
|||
AppServedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export async function servedBuilder() { |
|||
const properties: BuilderServedEvent = {} |
|||
await publishEvent(Event.SERVED_BUILDER, properties) |
|||
} |
|||
|
|||
export async function servedApp(app: App) { |
|||
const properties: AppServedEvent = { |
|||
appVersion: app.version, |
|||
} |
|||
await publishEvent(Event.SERVED_APP, properties) |
|||
} |
|||
|
|||
export async function servedAppPreview(app: App) { |
|||
const properties: AppPreviewServedEvent = { |
|||
appId: app.appId, |
|||
appVersion: app.version, |
|||
} |
|||
await publishEvent(Event.SERVED_APP_PREVIEW, properties) |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
TableExportFormat, |
|||
TableImportFormat, |
|||
Table, |
|||
TableCreatedEvent, |
|||
TableUpdatedEvent, |
|||
TableDeletedEvent, |
|||
TableExportedEvent, |
|||
TableImportedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export async function created(table: Table, timestamp?: string | number) { |
|||
const properties: TableCreatedEvent = { |
|||
tableId: table._id as string, |
|||
} |
|||
await publishEvent(Event.TABLE_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function updated(table: Table) { |
|||
const properties: TableUpdatedEvent = { |
|||
tableId: table._id as string, |
|||
} |
|||
await publishEvent(Event.TABLE_UPDATED, properties) |
|||
} |
|||
|
|||
export async function deleted(table: Table) { |
|||
const properties: TableDeletedEvent = { |
|||
tableId: table._id as string, |
|||
} |
|||
await publishEvent(Event.TABLE_DELETED, properties) |
|||
} |
|||
|
|||
export async function exported(table: Table, format: TableExportFormat) { |
|||
const properties: TableExportedEvent = { |
|||
tableId: table._id as string, |
|||
format, |
|||
} |
|||
await publishEvent(Event.TABLE_EXPORTED, properties) |
|||
} |
|||
|
|||
export async function imported(table: Table, format: TableImportFormat) { |
|||
const properties: TableImportedEvent = { |
|||
tableId: table._id as string, |
|||
format, |
|||
} |
|||
await publishEvent(Event.TABLE_IMPORTED, properties) |
|||
} |
|||
@ -0,0 +1,122 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
User, |
|||
UserCreatedEvent, |
|||
UserDeletedEvent, |
|||
UserInviteAcceptedEvent, |
|||
UserInvitedEvent, |
|||
UserPasswordForceResetEvent, |
|||
UserPasswordResetEvent, |
|||
UserPasswordResetRequestedEvent, |
|||
UserPasswordUpdatedEvent, |
|||
UserPermissionAssignedEvent, |
|||
UserPermissionRemovedEvent, |
|||
UserUpdatedEvent, |
|||
} from "@budibase/types" |
|||
|
|||
export async function created(user: User, timestamp?: number) { |
|||
const properties: UserCreatedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function updated(user: User) { |
|||
const properties: UserUpdatedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_UPDATED, properties) |
|||
} |
|||
|
|||
export async function deleted(user: User) { |
|||
const properties: UserDeletedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_DELETED, properties) |
|||
} |
|||
|
|||
// PERMISSIONS
|
|||
|
|||
export async function permissionAdminAssigned(user: User, timestamp?: number) { |
|||
const properties: UserPermissionAssignedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent( |
|||
Event.USER_PERMISSION_ADMIN_ASSIGNED, |
|||
properties, |
|||
timestamp |
|||
) |
|||
} |
|||
|
|||
export async function permissionAdminRemoved(user: User) { |
|||
const properties: UserPermissionRemovedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_PERMISSION_ADMIN_REMOVED, properties) |
|||
} |
|||
|
|||
export async function permissionBuilderAssigned( |
|||
user: User, |
|||
timestamp?: number |
|||
) { |
|||
const properties: UserPermissionAssignedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent( |
|||
Event.USER_PERMISSION_BUILDER_ASSIGNED, |
|||
properties, |
|||
timestamp |
|||
) |
|||
} |
|||
|
|||
export async function permissionBuilderRemoved(user: User) { |
|||
const properties: UserPermissionRemovedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_PERMISSION_BUILDER_REMOVED, properties) |
|||
} |
|||
|
|||
// INVITE
|
|||
|
|||
export async function invited() { |
|||
const properties: UserInvitedEvent = {} |
|||
await publishEvent(Event.USER_INVITED, properties) |
|||
} |
|||
|
|||
export async function inviteAccepted(user: User) { |
|||
const properties: UserInviteAcceptedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_INVITED_ACCEPTED, properties) |
|||
} |
|||
|
|||
// PASSWORD
|
|||
|
|||
export async function passwordForceReset(user: User) { |
|||
const properties: UserPasswordForceResetEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_PASSWORD_FORCE_RESET, properties) |
|||
} |
|||
|
|||
export async function passwordUpdated(user: User) { |
|||
const properties: UserPasswordUpdatedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_PASSWORD_UPDATED, properties) |
|||
} |
|||
|
|||
export async function passwordResetRequested(user: User) { |
|||
const properties: UserPasswordResetRequestedEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_PASSWORD_RESET_REQUESTED, properties) |
|||
} |
|||
|
|||
export async function passwordReset(user: User) { |
|||
const properties: UserPasswordResetEvent = { |
|||
userId: user._id as string, |
|||
} |
|||
await publishEvent(Event.USER_PASSWORD_RESET, properties) |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
import { publishEvent } from "../events" |
|||
import { |
|||
Event, |
|||
ViewCalculationCreatedEvent, |
|||
ViewCalculationDeletedEvent, |
|||
ViewCalculationUpdatedEvent, |
|||
ViewCreatedEvent, |
|||
ViewDeletedEvent, |
|||
ViewExportedEvent, |
|||
ViewFilterCreatedEvent, |
|||
ViewFilterDeletedEvent, |
|||
ViewFilterUpdatedEvent, |
|||
ViewUpdatedEvent, |
|||
View, |
|||
ViewCalculation, |
|||
Table, |
|||
TableExportFormat, |
|||
} from "@budibase/types" |
|||
|
|||
/* eslint-disable */ |
|||
|
|||
export async function created(view: View, timestamp?: string | number) { |
|||
const properties: ViewCreatedEvent = { |
|||
tableId: view.tableId, |
|||
} |
|||
await publishEvent(Event.VIEW_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function updated(view: View) { |
|||
const properties: ViewUpdatedEvent = { |
|||
tableId: view.tableId, |
|||
} |
|||
await publishEvent(Event.VIEW_UPDATED, properties) |
|||
} |
|||
|
|||
export async function deleted(view: View) { |
|||
const properties: ViewDeletedEvent = { |
|||
tableId: view.tableId, |
|||
} |
|||
await publishEvent(Event.VIEW_DELETED, properties) |
|||
} |
|||
|
|||
export async function exported(table: Table, format: TableExportFormat) { |
|||
const properties: ViewExportedEvent = { |
|||
tableId: table._id as string, |
|||
format, |
|||
} |
|||
await publishEvent(Event.VIEW_EXPORTED, properties) |
|||
} |
|||
|
|||
export async function filterCreated(view: View, timestamp?: string | number) { |
|||
const properties: ViewFilterCreatedEvent = { |
|||
tableId: view.tableId, |
|||
} |
|||
await publishEvent(Event.VIEW_FILTER_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function filterUpdated(view: View) { |
|||
const properties: ViewFilterUpdatedEvent = { |
|||
tableId: view.tableId, |
|||
} |
|||
await publishEvent(Event.VIEW_FILTER_UPDATED, properties) |
|||
} |
|||
|
|||
export async function filterDeleted(view: View) { |
|||
const properties: ViewFilterDeletedEvent = { |
|||
tableId: view.tableId, |
|||
} |
|||
await publishEvent(Event.VIEW_FILTER_DELETED, properties) |
|||
} |
|||
|
|||
export async function calculationCreated( |
|||
view: View, |
|||
timestamp?: string | number |
|||
) { |
|||
const properties: ViewCalculationCreatedEvent = { |
|||
tableId: view.tableId, |
|||
calculation: view.calculation as ViewCalculation, |
|||
} |
|||
await publishEvent(Event.VIEW_CALCULATION_CREATED, properties, timestamp) |
|||
} |
|||
|
|||
export async function calculationUpdated(view: View) { |
|||
const properties: ViewCalculationUpdatedEvent = { |
|||
tableId: view.tableId, |
|||
calculation: view.calculation as ViewCalculation, |
|||
} |
|||
await publishEvent(Event.VIEW_CALCULATION_UPDATED, properties) |
|||
} |
|||
|
|||
export async function calculationDeleted(existingView: View) { |
|||
const properties: ViewCalculationDeletedEvent = { |
|||
tableId: existingView.tableId, |
|||
calculation: existingView.calculation as ViewCalculation, |
|||
} |
|||
await publishEvent(Event.VIEW_CALCULATION_DELETED, properties) |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue