mirror of https://github.com/Budibase/budibase.git
406 changed files with 29095 additions and 3450 deletions
@ -0,0 +1,9 @@ |
|||
packages/server/node_modules |
|||
packages/builder |
|||
packages/frontend-core |
|||
packages/backend-core |
|||
packages/worker/node_modules |
|||
packages/cli |
|||
packages/client |
|||
packages/bbui |
|||
packages/string-templates |
|||
@ -1,11 +1,11 @@ |
|||
node_modules |
|||
public |
|||
dist |
|||
*.spec.js |
|||
packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte |
|||
packages/server/builder |
|||
packages/server/coverage |
|||
packages/server/client |
|||
packages/server/src/definitions/openapi.ts |
|||
packages/builder/.routify |
|||
packages/builder/cypress/support/queryLevelTransformerFunction.js |
|||
packages/builder/cypress/support/queryLevelTransformerFunctionWithData.js |
|||
packages/builder/cypress/support/queryLevelTransformerFunctionWithData.js |
|||
|
|||
@ -0,0 +1,3 @@ |
|||
{ |
|||
"extends": "next/core-web-vitals" |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. |
|||
|
|||
# dependencies |
|||
/node_modules |
|||
/.pnp |
|||
.pnp.js |
|||
|
|||
# testing |
|||
/coverage |
|||
|
|||
# next.js |
|||
/.next/ |
|||
/out/ |
|||
|
|||
# production |
|||
/build |
|||
|
|||
# misc |
|||
.DS_Store |
|||
*.pem |
|||
|
|||
# debug |
|||
npm-debug.log* |
|||
yarn-debug.log* |
|||
yarn-error.log* |
|||
.pnpm-debug.log* |
|||
|
|||
# local env files |
|||
.env.local |
|||
.env.development.local |
|||
.env.test.local |
|||
.env.production.local |
|||
|
|||
# vercel |
|||
.vercel |
|||
|
|||
# typescript |
|||
*.tsbuildinfo |
|||
@ -0,0 +1,41 @@ |
|||
# Budibase API + Next.js example |
|||
|
|||
This is an example of how Budibase can be used as a backend for a Postgres database for a Next.js sales app. You will |
|||
need to follow the walk-through that has been published in the Budibase docs to set up your Budibase app for this example. |
|||
|
|||
## Pre-requisites |
|||
|
|||
To use this example you will need: |
|||
1. [Docker](https://www.docker.com/) |
|||
2. [Docker Compose](https://docs.docker.com/compose/) |
|||
3. [Node.js](https://nodejs.org/en/) |
|||
4. A self-hosted Budibase installation |
|||
|
|||
## Getting Started |
|||
|
|||
The first step is to set up the database - you can do this by going to the `db/` directory and running the command: |
|||
|
|||
```bash |
|||
docker-compose up |
|||
``` |
|||
|
|||
The next step is to follow the example walk-through and set up a Budibase app as it describes. Once you've done |
|||
this you can configure the settings in `next.config.js`, specifically the `apiKey`, `host` and `appName`. |
|||
|
|||
Finally, you can start the dev server with the following command: |
|||
|
|||
```bash |
|||
npm run dev |
|||
# or |
|||
yarn dev |
|||
``` |
|||
|
|||
## Accessing the app |
|||
|
|||
Open [http://localhost:3001](http://localhost:3001) with your browser to see the sales app. |
|||
|
|||
Look in the API routes (`pages/api/sales.ts` and `pages/api/salespeople.ts`) to see how this is integrated with Budibase. |
|||
There is also a utility file where some core functions and types have been defined, in `utilities/index.ts`. |
|||
|
|||
## Attribution |
|||
This example was set up using [Next.js](https://nextjs.org/) and bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). |
|||
@ -0,0 +1,42 @@ |
|||
import Link from "next/link" |
|||
import Image from "next/image" |
|||
import { ReactNotifications } from "react-notifications-component" |
|||
|
|||
function layout(props: any) { |
|||
return ( |
|||
<> |
|||
<nav className="navbar" role="navigation" aria-label="main navigation"> |
|||
<div id="navbar" className="navbar-menu"> |
|||
<div className="logo"> |
|||
<Image alt="logo" src="/bb-emblem.svg" width="50" height="50" /> |
|||
</div> |
|||
<div className="navbar-start"> |
|||
<Link href="/"> |
|||
<a className="navbar-item"> |
|||
List |
|||
</a> |
|||
</Link> |
|||
<Link href="/save"> |
|||
<a className="navbar-item"> |
|||
New sale |
|||
</a> |
|||
</Link> |
|||
</div> |
|||
<div className="navbar-end"> |
|||
<div className="navbar-item"> |
|||
<div className="buttons"> |
|||
<a className="button is-primary" href="https://budibase.readme.io/reference"> |
|||
<strong>API Documentation</strong> |
|||
</a> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</nav> |
|||
<ReactNotifications /> |
|||
{props.children} |
|||
</> |
|||
) |
|||
} |
|||
|
|||
export default layout |
|||
@ -0,0 +1,28 @@ |
|||
import { Store } from "react-notifications-component" |
|||
|
|||
const notifications = { |
|||
error: (error: string, title: string) => { |
|||
Store.addNotification({ |
|||
container: "top-right", |
|||
type: "danger", |
|||
message: error, |
|||
title: title, |
|||
dismiss: { |
|||
duration: 10000, |
|||
}, |
|||
}) |
|||
}, |
|||
success: (message: string, title: string) => { |
|||
Store.addNotification({ |
|||
container: "top-right", |
|||
type: "success", |
|||
message: message, |
|||
title: title, |
|||
dismiss: { |
|||
duration: 3000, |
|||
}, |
|||
}) |
|||
}, |
|||
} |
|||
|
|||
export default notifications |
|||
@ -0,0 +1,17 @@ |
|||
version: "3.8" |
|||
services: |
|||
db: |
|||
container_name: postgres |
|||
image: postgres |
|||
restart: always |
|||
environment: |
|||
POSTGRES_USER: root |
|||
POSTGRES_PASSWORD: root |
|||
POSTGRES_DB: postgres |
|||
ports: |
|||
- "5432:5432" |
|||
volumes: |
|||
- pg_data:/var/lib/postgresql/data/ |
|||
- ./init.sql:/docker-entrypoint-initdb.d/init.sql |
|||
volumes: |
|||
pg_data: |
|||
@ -0,0 +1,21 @@ |
|||
CREATE TABLE IF NOT EXISTS sales_people ( |
|||
person_id SERIAL PRIMARY KEY, |
|||
name varchar(200) NOT NULL |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS sales ( |
|||
sale_id SERIAL PRIMARY KEY, |
|||
sale_name varchar(200) NOT NULL, |
|||
sold_by INT, |
|||
CONSTRAINT sold_by_fk |
|||
FOREIGN KEY(sold_by) |
|||
REFERENCES sales_people(person_id) |
|||
); |
|||
|
|||
INSERT INTO sales_people (name) |
|||
select 'Salesperson ' || id |
|||
FROM GENERATE_SERIES(1, 50) as id; |
|||
|
|||
INSERT INTO sales (sale_name, sold_by) |
|||
select 'Sale ' || id, floor(random() * 50 + 1)::int |
|||
FROM GENERATE_SERIES(1, 200) as id; |
|||
@ -0,0 +1,7 @@ |
|||
import { components } from "./openapi" |
|||
|
|||
export type App = components["schemas"]["applicationOutput"]["data"] |
|||
export type Table = components["schemas"]["tableOutput"]["data"] |
|||
export type TableSearch = components["schemas"]["tableSearch"] |
|||
export type AppSearch = components["schemas"]["applicationSearch"] |
|||
export type RowSearch = components["schemas"]["searchOutput"] |
|||
File diff suppressed because it is too large
@ -0,0 +1,5 @@ |
|||
/// <reference types="next" />
|
|||
/// <reference types="next/image-types/global" />
|
|||
|
|||
// NOTE: This file should not be edited
|
|||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
|||
@ -0,0 +1,16 @@ |
|||
const { join } = require("path") |
|||
/** @type {import('next').NextConfig} */ |
|||
const nextConfig = { |
|||
reactStrictMode: true, |
|||
sassOptions: { |
|||
includePaths: [join(__dirname, "styles")], |
|||
}, |
|||
serverRuntimeConfig: { |
|||
apiKey: |
|||
"bf4d86af933b5ac0af0fdbe4bf7d89ff-f929752a1eeaafb00f4b5e3325097d51a44fe4b39f22ed857923409cc75414b379323a25ebfb4916", |
|||
appName: "sales", |
|||
host: "http://localhost:10000", |
|||
}, |
|||
} |
|||
|
|||
module.exports = nextConfig |
|||
@ -0,0 +1,27 @@ |
|||
{ |
|||
"name": "nextjs-api-sales", |
|||
"version": "0.1.0", |
|||
"private": true, |
|||
"scripts": { |
|||
"dev": "next dev -p 3001", |
|||
"build": "next build", |
|||
"start": "next start", |
|||
"lint": "next lint" |
|||
}, |
|||
"dependencies": { |
|||
"bulma": "^0.9.3", |
|||
"next": "12.1.0", |
|||
"node-fetch": "^3.2.2", |
|||
"node-sass": "^7.0.1", |
|||
"react": "17.0.2", |
|||
"react-dom": "17.0.2", |
|||
"react-notifications-component": "^3.4.1" |
|||
}, |
|||
"devDependencies": { |
|||
"@types/node": "17.0.21", |
|||
"@types/react": "17.0.39", |
|||
"eslint": "8.10.0", |
|||
"eslint-config-next": "12.1.0", |
|||
"typescript": "4.6.2" |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
import "../styles/global.sass" |
|||
import type { AppProps } from "next/app" |
|||
import Head from "next/head" |
|||
import Layout from "../components/layout" |
|||
|
|||
function MyApp({ Component, pageProps }: AppProps) { |
|||
return ( |
|||
<Layout> |
|||
<Head> |
|||
<title>BB NextJS Sales Example</title> |
|||
</Head> |
|||
<Component {...pageProps} /> |
|||
</Layout> |
|||
) |
|||
} |
|||
|
|||
export default MyApp |
|||
@ -0,0 +1,46 @@ |
|||
import { getApp, findTable, makeCall } from "../../utilities" |
|||
|
|||
async function getSales(req: any) { |
|||
const { page } = req.query |
|||
const { _id: appId } = await getApp() |
|||
const table = await findTable(appId, "sales") |
|||
return await makeCall("post", `tables/${table._id}/rows/search`, { |
|||
appId, |
|||
body: { |
|||
limit: 10, |
|||
sort: { |
|||
type: "string", |
|||
order: "descending", |
|||
column: "sale_id", |
|||
}, |
|||
paginate: true, |
|||
bookmark: parseInt(page), |
|||
}, |
|||
}) |
|||
} |
|||
|
|||
async function saveSale(req: any) { |
|||
const { _id: appId } = await getApp() |
|||
const table = await findTable(appId, "sales") |
|||
return await makeCall("post", `tables/${table._id}/rows`, { |
|||
body: req.body, |
|||
appId, |
|||
}) |
|||
} |
|||
|
|||
export default async function handler(req: any, res: any) { |
|||
let response: any = {} |
|||
try { |
|||
if (req.method === "POST") { |
|||
response = await saveSale(req) |
|||
} else if (req.method === "GET") { |
|||
response = await getSales(req) |
|||
} else { |
|||
res.status(404) |
|||
return |
|||
} |
|||
res.status(200).json(response) |
|||
} catch (err: any) { |
|||
res.status(400).send(err) |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
import { getApp, findTable, makeCall } from "../../utilities" |
|||
|
|||
async function getSalespeople() { |
|||
const { _id: appId } = await getApp() |
|||
const table = await findTable(appId, "sales_people") |
|||
return await makeCall("post", `tables/${table._id}/rows/search`, { |
|||
appId, |
|||
body: { |
|||
sort: { |
|||
type: "string", |
|||
order: "ascending", |
|||
column: "person_id", |
|||
}, |
|||
}, |
|||
}) |
|||
} |
|||
|
|||
export default async function handler(req: any, res: any) { |
|||
let response: any = {} |
|||
try { |
|||
if (req.method === "GET") { |
|||
response = await getSalespeople() |
|||
} else { |
|||
res.status(404) |
|||
return |
|||
} |
|||
res.status(200).json(response) |
|||
} catch (err: any) { |
|||
res.status(400).send(err) |
|||
} |
|||
} |
|||
@ -0,0 +1,83 @@ |
|||
import type { NextPage } from "next" |
|||
import styles from "../styles/home.module.css" |
|||
import { useState, useEffect, useCallback } from "react" |
|||
import Notifications from "../components/notifications" |
|||
|
|||
const Home: NextPage = () => { |
|||
const [sales, setSales] = useState([]) |
|||
const [currentPage, setCurrentPage] = useState(1) |
|||
const [loaded, setLoaded] = useState(false) |
|||
|
|||
const getSales = useCallback(async (page: Number = 1) => { |
|||
let url = "/api/sales" |
|||
if (page) { |
|||
url += `?page=${page}` |
|||
} |
|||
const response = await fetch(url) |
|||
if (!response.ok) { |
|||
const error = await response.text() |
|||
Notifications.error(error, "Failed to get sales") |
|||
return |
|||
} |
|||
const sales = await response.json() |
|||
// @ts-ignore
|
|||
setCurrentPage(page) |
|||
return setSales(sales.data) |
|||
}, []) |
|||
|
|||
const goToNextPage = useCallback(async () => { |
|||
await getSales(currentPage + 1) |
|||
}, [currentPage, getSales]) |
|||
|
|||
const goToPrevPage = useCallback(async () => { |
|||
if (currentPage > 1) { |
|||
await getSales(currentPage - 1) |
|||
} |
|||
}, [currentPage, getSales]) |
|||
|
|||
useEffect(() => { |
|||
getSales().then(() => { |
|||
setLoaded(true) |
|||
}).catch(() => { |
|||
setSales([]) |
|||
}) |
|||
}, []) |
|||
|
|||
if (!loaded) { |
|||
return null |
|||
} |
|||
|
|||
return ( |
|||
<div className={styles.container}> |
|||
<div className={styles.tableSection}> |
|||
<h1 className="subtitle">Sales</h1> |
|||
<div className={styles.table}> |
|||
<table className="table"> |
|||
<thead> |
|||
<tr> |
|||
<th>Sale ID</th> |
|||
<th>name</th> |
|||
<th>Sold by</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{sales.map((sale: any) => |
|||
<tr key={sale.sale_id}> |
|||
<th>{sale.sale_id}</th> |
|||
<th>{sale.sale_name}</th> |
|||
<th>{sale.sales_person?.map((person: any) => person.primaryDisplay)[0]}</th> |
|||
</tr> |
|||
)} |
|||
</tbody> |
|||
</table> |
|||
<div className={styles.buttons}> |
|||
<button className="button" onClick={goToPrevPage}>Prev Page</button> |
|||
<button className="button" onClick={goToNextPage}>Next Page</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
) |
|||
} |
|||
|
|||
export default Home |
|||
@ -0,0 +1,81 @@ |
|||
import type { NextPage } from "next" |
|||
import { useCallback, useEffect, useState } from "react" |
|||
import styles from "../styles/save.module.css" |
|||
import Notifications from "../components/notifications" |
|||
|
|||
const Save: NextPage = () => { |
|||
const [salespeople, setSalespeople] = useState([]) |
|||
const [loaded, setLoaded] = useState(false) |
|||
|
|||
const saveSale = useCallback(async (event: any) => { |
|||
event.preventDefault() |
|||
const sale = { |
|||
sale_name: event.target.name.value, |
|||
sales_person: [event.target.soldBy.value], |
|||
} |
|||
const response = await fetch("/api/sales", { |
|||
method: "POST", |
|||
headers: { |
|||
"Content-Type": "application/json", |
|||
}, |
|||
body: JSON.stringify(sale), |
|||
}) |
|||
if (!response.ok) { |
|||
const error = await response.text() |
|||
Notifications.error(error, "Failed to save sale") |
|||
return |
|||
} |
|||
Notifications.success("Sale saved successfully!", "Sale saved") |
|||
}, []) |
|||
|
|||
const getSalespeople = useCallback(async () => { |
|||
const response: any = await fetch("/api/salespeople") |
|||
if (!response.ok) { |
|||
throw new Error(await response.text()) |
|||
} |
|||
const json = await response.json() |
|||
setSalespeople(json.data) |
|||
}, []) |
|||
|
|||
useEffect(() => { |
|||
getSalespeople().then(() => { |
|||
setLoaded(true) |
|||
}).catch(() => { |
|||
setSalespeople([]) |
|||
}) |
|||
}, []) |
|||
|
|||
if (!loaded) { |
|||
return null |
|||
} |
|||
return ( |
|||
<div className={styles.container}> |
|||
<div className={styles.formSection}> |
|||
<h1 className="subtitle">New sale</h1> |
|||
<form onSubmit={saveSale}> |
|||
<div className="field"> |
|||
<label className="label">Name</label> |
|||
<div className="control"> |
|||
<input id="name" className="input" type="text" placeholder="Text input" /> |
|||
</div> |
|||
</div> |
|||
<div className="field"> |
|||
<label className="label">Sold by</label> |
|||
<div className="control"> |
|||
<div className="select"> |
|||
<select id="soldBy"> |
|||
{salespeople.map((person: any) => <option key={person._id} value={person._id}>{person.name}</option>)} |
|||
</select> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
<div className="control"> |
|||
<button className="button is-link">Submit</button> |
|||
</div> |
|||
</form> |
|||
</div> |
|||
</div> |
|||
) |
|||
} |
|||
|
|||
export default Save |
|||
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 25 KiB |
@ -0,0 +1,26 @@ |
|||
@charset "utf-8" |
|||
|
|||
@import url('https://fonts.googleapis.com/css?family=Roboto:400,700') |
|||
$family-sans-serif: "Roboto", sans-serif |
|||
|
|||
#__next |
|||
display: flex |
|||
flex-direction: column |
|||
justify-content: flex-start |
|||
align-items: stretch |
|||
height: 100vh |
|||
--bg-color: #f5f5f5 |
|||
|
|||
.logo |
|||
padding: 0.75rem |
|||
|
|||
@import "../node_modules/bulma/bulma.sass" |
|||
@import "../node_modules/react-notifications-component/dist/theme.css" |
|||
|
|||
// applied after bulma styles are enabled |
|||
html |
|||
overflow-y: auto |
|||
|
|||
.navbar |
|||
background-color: var(--bg-color) |
|||
color: white |
|||
@ -0,0 +1,30 @@ |
|||
.container { |
|||
width: 100vw; |
|||
display: flex; |
|||
flex-direction: column; |
|||
padding: 5rem 2rem 0; |
|||
align-items: center; |
|||
flex: 1 1 auto; |
|||
} |
|||
|
|||
.buttons { |
|||
display: flex; |
|||
flex-direction: row; |
|||
justify-content: space-between; |
|||
} |
|||
|
|||
.tableSection { |
|||
padding: 2rem; |
|||
background: var(--bg-color); |
|||
width: 800px; |
|||
border-radius: 10px; |
|||
} |
|||
|
|||
.table table { |
|||
width: 100%; |
|||
} |
|||
|
|||
.tableSection h1 { |
|||
text-align: center; |
|||
color: black; |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
.container { |
|||
width: 100vw; |
|||
display: flex; |
|||
flex-direction: column; |
|||
padding: 5rem 2rem 0; |
|||
align-items: center; |
|||
flex: 1 1 auto; |
|||
} |
|||
|
|||
.formSection { |
|||
padding: 2rem; |
|||
background: var(--bg-color); |
|||
width: 400px; |
|||
border-radius: 10px; |
|||
} |
|||
|
|||
.formSection h1 { |
|||
text-align: center; |
|||
color: black; |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
{ |
|||
"compilerOptions": { |
|||
"target": "es5", |
|||
"lib": ["dom", "dom.iterable", "esnext"], |
|||
"allowJs": true, |
|||
"skipLibCheck": true, |
|||
"strict": true, |
|||
"forceConsistentCasingInFileNames": true, |
|||
"noEmit": true, |
|||
"esModuleInterop": true, |
|||
"module": "esnext", |
|||
"moduleResolution": "node", |
|||
"resolveJsonModule": true, |
|||
"isolatedModules": true, |
|||
"jsx": "preserve", |
|||
"incremental": true |
|||
}, |
|||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], |
|||
"exclude": ["node_modules"] |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
import { App, AppSearch, Table, TableSearch } from "../definitions" |
|||
import getConfig from "next/config" |
|||
|
|||
const { serverRuntimeConfig } = getConfig() |
|||
const apiKey = serverRuntimeConfig["apiKey"] |
|||
const appName = serverRuntimeConfig["appName"] |
|||
const host = serverRuntimeConfig["host"] |
|||
|
|||
let APP: App | null = null |
|||
let TABLES: { [key: string]: Table } = {} |
|||
|
|||
export async function makeCall( |
|||
method: string, |
|||
url: string, |
|||
opts?: { body?: any; appId?: string } |
|||
): Promise<any> { |
|||
const fetchOpts: any = { |
|||
method, |
|||
headers: { |
|||
"x-budibase-api-key": apiKey, |
|||
}, |
|||
} |
|||
if (opts?.appId) { |
|||
fetchOpts.headers["x-budibase-app-id"] = opts.appId |
|||
} |
|||
if (opts?.body) { |
|||
fetchOpts.body = |
|||
typeof opts.body !== "string" ? JSON.stringify(opts.body) : opts.body |
|||
fetchOpts.headers["Content-Type"] = "application/json" |
|||
} |
|||
const finalUrl = `${host}/api/public/v1/${url}` |
|||
const response = await fetch(finalUrl, fetchOpts) |
|||
if (response.ok) { |
|||
return response.json() |
|||
} else { |
|||
const error = await response.text() |
|||
console.error("Budibase server error - ", error) |
|||
throw new Error(error) |
|||
} |
|||
} |
|||
|
|||
export async function getApp(): Promise<App> { |
|||
if (APP) { |
|||
return APP |
|||
} |
|||
const apps: AppSearch = await makeCall("post", "applications/search", { |
|||
body: { |
|||
name: appName, |
|||
}, |
|||
}) |
|||
const app = apps.data.find((app: App) => app.name === appName) |
|||
if (!app) { |
|||
throw new Error( |
|||
"Could not find app, please make sure app name in config is correct." |
|||
) |
|||
} |
|||
APP = app |
|||
return app |
|||
} |
|||
|
|||
export async function findTable( |
|||
appId: string, |
|||
tableName: string |
|||
): Promise<Table> { |
|||
if (TABLES[tableName]) { |
|||
return TABLES[tableName] |
|||
} |
|||
const tables: TableSearch = await makeCall("post", "tables/search", { |
|||
body: { |
|||
name: tableName, |
|||
}, |
|||
appId, |
|||
}) |
|||
const table = tables.data.find((table: Table) => table.name === tableName) |
|||
if (!table) { |
|||
throw new Error( |
|||
"Could not find table, please make sure your app is configured with the Postgres datasource correctly." |
|||
) |
|||
} |
|||
TABLES[tableName] = table |
|||
return table |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,94 @@ |
|||
{ |
|||
"version": "2", |
|||
"templates": [ |
|||
{ |
|||
"type": 3, |
|||
"title": "Budibase", |
|||
"categories": ["Tools"], |
|||
"description": "Build modern business apps in minutes", |
|||
"logo": "https://budibase.com/favicon.ico", |
|||
"platform": "linux", |
|||
"repository": { |
|||
"url": "https://github.com/Budibase/budibase", |
|||
"stackfile": "hosting/docker-compose.yaml" |
|||
}, |
|||
"env": [ |
|||
{ |
|||
"name": "MAIN_PORT", |
|||
"label": "Main port", |
|||
"default": "10000" |
|||
}, |
|||
{ |
|||
"name": "JWT_SECRET", |
|||
"label": "JWT secret", |
|||
"default": "change-me" |
|||
}, |
|||
{ |
|||
"name": "MINIO_ACCESS_KEY", |
|||
"label": "MinIO access key", |
|||
"default": "change-me" |
|||
}, |
|||
{ |
|||
"name": "MINIO_SECRET_KEY", |
|||
"label": "MinIO secret key", |
|||
"default": "change-me" |
|||
}, |
|||
{ |
|||
"name": "COUCH_DB_USER", |
|||
"default": "budibase", |
|||
"preset": true |
|||
}, |
|||
{ |
|||
"name": "COUCH_DB_PASSWORD", |
|||
"label": "Couch DB password", |
|||
"default": "change-me" |
|||
}, |
|||
{ |
|||
"name": "REDIS_PASSWORD", |
|||
"label": "Redis password", |
|||
"default": "change-me" |
|||
}, |
|||
{ |
|||
"name": "INTERNAL_API_KEY", |
|||
"label": "Internal API key", |
|||
"default": "change-me" |
|||
}, |
|||
{ |
|||
"name": "APP_PORT", |
|||
"default": "4002", |
|||
"preset": true |
|||
}, |
|||
{ |
|||
"name": "WORKER_PORT", |
|||
"default": "4003", |
|||
"preset": true |
|||
}, |
|||
{ |
|||
"name": "MINIO_PORT", |
|||
"default": "4004", |
|||
"preset": true |
|||
}, |
|||
{ |
|||
"name": "COUCH_DB_PORT", |
|||
"default": "4005", |
|||
"preset": true |
|||
}, |
|||
{ |
|||
"name": "REDIS_PORT", |
|||
"default": "6379", |
|||
"preset": true |
|||
}, |
|||
{ |
|||
"name": "WATCHTOWER_PORT", |
|||
"default": "6161", |
|||
"preset": true |
|||
}, |
|||
{ |
|||
"name": "BUDIBASE_ENVIRONMENT", |
|||
"default": "PRODUCTION", |
|||
"preset": true |
|||
} |
|||
] |
|||
} |
|||
] |
|||
} |
|||
@ -1,145 +0,0 @@ |
|||
user nginx; |
|||
error_log /var/log/nginx/error.log debug; |
|||
pid /var/run/nginx.pid; |
|||
worker_processes auto; |
|||
worker_rlimit_nofile 33282; |
|||
|
|||
events { |
|||
worker_connections 1024; |
|||
} |
|||
|
|||
http { |
|||
limit_req_zone $binary_remote_addr zone=ratelimit:10m rate=20r/s; |
|||
include /etc/nginx/mime.types; |
|||
default_type application/octet-stream; |
|||
charset utf-8; |
|||
sendfile on; |
|||
tcp_nopush on; |
|||
tcp_nodelay on; |
|||
server_tokens off; |
|||
types_hash_max_size 2048; |
|||
|
|||
# buffering |
|||
client_body_buffer_size 1K; |
|||
client_header_buffer_size 1k; |
|||
client_max_body_size 1k; |
|||
ignore_invalid_headers off; |
|||
|
|||
|
|||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
|||
'$status $body_bytes_sent "$http_referer" ' |
|||
'"$http_user_agent" "$http_x_forwarded_for"'; |
|||
|
|||
map $http_upgrade $connection_upgrade { |
|||
default "upgrade"; |
|||
} |
|||
|
|||
server { |
|||
listen 10000 default_server; |
|||
listen [::]:10000 default_server; |
|||
server_name _; |
|||
client_max_body_size 1000m; |
|||
ignore_invalid_headers off; |
|||
proxy_buffering off; |
|||
port_in_redirect off; |
|||
|
|||
# Security Headers |
|||
add_header X-Frame-Options SAMEORIGIN always; |
|||
add_header X-Content-Type-Options nosniff always; |
|||
add_header X-XSS-Protection "1; mode=block" always; |
|||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.budi.live https://js.intercomcdn.com https://widget.intercom.io; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://fonts.googleapis.com https://rsms.me; object-src 'none'; base-uri 'self'; connect-src 'self' https://api-iam.intercom.io https://app.posthog.com wss://nexus-websocket-a.intercom.io; font-src 'self' data: https://cdn.jsdelivr.net https://fonts.gstatic.com https://rsms.me; frame-src 'self'; img-src http: https: data:; manifest-src 'self'; media-src 'self'; worker-src 'none';" always; |
|||
|
|||
location /app { |
|||
proxy_pass http://app-service:4002; |
|||
rewrite ^/app/(.*)$ /$1 break; |
|||
} |
|||
|
|||
location = / { |
|||
port_in_redirect off; |
|||
proxy_pass http://app-service:4002; |
|||
} |
|||
|
|||
location = /v1/update { |
|||
proxy_pass http://watchtower-service:8080; |
|||
} |
|||
|
|||
location /builder/ { |
|||
port_in_redirect off; |
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection $connection_upgrade; |
|||
proxy_set_header Upgrade $http_upgrade; |
|||
proxy_set_header Host $host; |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_pass http://app-service:4002; |
|||
} |
|||
|
|||
location ~ ^/(builder|app_) { |
|||
port_in_redirect off; |
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection $connection_upgrade; |
|||
proxy_set_header Upgrade $http_upgrade; |
|||
proxy_set_header Host $host; |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
proxy_pass http://app-service:4002; |
|||
} |
|||
|
|||
location ~ ^/api/(system|admin|global)/ { |
|||
proxy_pass http://worker-service:4003; |
|||
} |
|||
|
|||
location /worker/ { |
|||
proxy_pass http://worker-service:4003; |
|||
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 Host $host; |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
|||
|
|||
proxy_pass http://app-service:4002; |
|||
} |
|||
|
|||
location /db/ { |
|||
proxy_pass http://couchdb-service: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_set_header Host $http_host; |
|||
|
|||
proxy_connect_timeout 300; |
|||
proxy_http_version 1.1; |
|||
proxy_set_header Connection ""; |
|||
chunked_transfer_encoding off; |
|||
proxy_pass http://minio-service: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,97 @@ |
|||
FROM couchdb |
|||
|
|||
ENV COUCHDB_PASSWORD=budibase |
|||
ENV COUCHDB_USER=budibase |
|||
ENV COUCH_DB_URL=http://budibase:budibase@localhost:5984 |
|||
ENV BUDIBASE_ENVIRONMENT=PRODUCTION |
|||
ENV MINIO_URL=http://localhost:9000 |
|||
ENV REDIS_URL=localhost:6379 |
|||
ENV WORKER_URL=http://localhost:4002 |
|||
ENV INTERNAL_API_KEY=budibase |
|||
ENV JWT_SECRET=testsecret |
|||
ENV MINIO_ACCESS_KEY=budibase |
|||
ENV MINIO_SECRET_KEY=budibase |
|||
ENV SELF_HOSTED=1 |
|||
ENV CLUSTER_PORT=10000 |
|||
ENV REDIS_PASSWORD=budibase |
|||
ENV ARCHITECTURE=amd |
|||
ENV APP_PORT=4001 |
|||
ENV WORKER_PORT=4002 |
|||
|
|||
RUN apt-get update |
|||
RUN apt-get install software-properties-common wget nginx -y |
|||
RUN apt-add-repository 'deb http://security.debian.org/debian-security stretch/updates main' |
|||
RUN apt-get update |
|||
|
|||
# setup nginx |
|||
ADD hosting/single/nginx.conf /etc/nginx |
|||
RUN mkdir /etc/nginx/logs |
|||
RUN useradd www |
|||
RUN touch /etc/nginx/logs/error.log |
|||
RUN touch /etc/nginx/logs/nginx.pid |
|||
|
|||
# install java |
|||
RUN apt-get install openjdk-8-jdk -y |
|||
|
|||
# setup nodejs |
|||
WORKDIR /nodejs |
|||
RUN curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh |
|||
RUN bash /tmp/nodesource_setup.sh |
|||
RUN apt-get install nodejs |
|||
RUN npm install --global yarn |
|||
RUN npm install --global pm2 |
|||
|
|||
# setup redis |
|||
RUN apt install redis-server -y |
|||
|
|||
# setup server |
|||
WORKDIR /app |
|||
ADD packages/server . |
|||
RUN ls -al |
|||
RUN yarn |
|||
RUN yarn build |
|||
# Install client for oracle datasource |
|||
RUN apt-get install unzip libaio1 |
|||
RUN /bin/bash -e scripts/integrations/oracle/instantclient/linux/x86-64/install.sh |
|||
|
|||
# setup worker |
|||
WORKDIR /worker |
|||
ADD packages/worker . |
|||
RUN yarn |
|||
RUN yarn build |
|||
|
|||
# setup clouseau |
|||
WORKDIR / |
|||
RUN wget https://github.com/cloudant-labs/clouseau/releases/download/2.21.0/clouseau-2.21.0-dist.zip |
|||
RUN unzip clouseau-2.21.0-dist.zip |
|||
RUN mv clouseau-2.21.0 /opt/clouseau |
|||
RUN rm clouseau-2.21.0-dist.zip |
|||
|
|||
WORKDIR /opt/clouseau |
|||
RUN mkdir ./bin |
|||
ADD hosting/single/clouseau ./bin/ |
|||
ADD hosting/single/log4j.properties . |
|||
ADD hosting/single/clouseau.ini . |
|||
RUN chmod +x ./bin/clouseau |
|||
|
|||
# setup CouchDB |
|||
WORKDIR /opt/couchdb |
|||
ADD hosting/single/vm.args ./etc/ |
|||
|
|||
# setup minio |
|||
WORKDIR /minio |
|||
RUN wget https://dl.min.io/server/minio/release/linux-${ARCHITECTURE}64/minio |
|||
RUN chmod +x minio |
|||
|
|||
# setup runner file |
|||
WORKDIR / |
|||
ADD hosting/single/runner.sh . |
|||
RUN chmod +x ./runner.sh |
|||
|
|||
EXPOSE 10000 |
|||
VOLUME /opt/couchdb/data |
|||
VOLUME /minio |
|||
|
|||
# must set this just before running |
|||
ENV NODE_ENV=production |
|||
CMD ["./runner.sh"] |
|||
@ -0,0 +1,12 @@ |
|||
#!/bin/sh |
|||
/usr/bin/java -server \ |
|||
-Xmx2G \ |
|||
-Dsun.net.inetaddr.ttl=30 \ |
|||
-Dsun.net.inetaddr.negative.ttl=30 \ |
|||
-Dlog4j.configuration=file:/opt/clouseau/log4j.properties \ |
|||
-XX:OnOutOfMemoryError="kill -9 %p" \ |
|||
-XX:+UseConcMarkSweepGC \ |
|||
-XX:+CMSParallelRemarkEnabled \ |
|||
-classpath '/opt/clouseau/*' \ |
|||
com.cloudant.clouseau.Main \ |
|||
/opt/clouseau/clouseau.ini |
|||
@ -0,0 +1,13 @@ |
|||
[clouseau] |
|||
|
|||
; the name of the Erlang node created by the service, leave this unchanged |
|||
name=clouseau@127.0.0.1 |
|||
|
|||
; set this to the same distributed Erlang cookie used by the CouchDB nodes |
|||
cookie=monster |
|||
|
|||
; the path where you would like to store the search index files |
|||
dir=/opt/couchdb/data/search |
|||
|
|||
; the number of search indexes that can be open simultaneously |
|||
max_indexes_open=500 |
|||
@ -0,0 +1,4 @@ |
|||
log4j.rootLogger=debug, CONSOLE |
|||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
|||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
|||
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %c [%p] %m%n |
|||
@ -0,0 +1,116 @@ |
|||
user www www; |
|||
error_log /etc/nginx/logs/error.log; |
|||
pid /etc/nginx/logs/nginx.pid; |
|||
worker_processes auto; |
|||
worker_rlimit_nofile 8192; |
|||
|
|||
events { |
|||
worker_connections 1024; |
|||
} |
|||
|
|||
http { |
|||
limit_req_zone $binary_remote_addr zone=ratelimit:10m rate=20r/s; |
|||
proxy_set_header Host $host; |
|||
charset utf-8; |
|||
sendfile on; |
|||
tcp_nopush on; |
|||
tcp_nodelay on; |
|||
server_tokens off; |
|||
types_hash_max_size 2048; |
|||
|
|||
# buffering |
|||
client_header_buffer_size 1k; |
|||
client_max_body_size 20M; |
|||
ignore_invalid_headers off; |
|||
proxy_buffering off; |
|||
|
|||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
|||
'$status $body_bytes_sent "$http_referer" ' |
|||
'"$http_user_agent" "$http_x_forwarded_for"'; |
|||
|
|||
map $http_upgrade $connection_upgrade { |
|||
default "upgrade"; |
|||
} |
|||
|
|||
server { |
|||
listen 10000 default_server; |
|||
listen [::]:10000 default_server; |
|||
server_name _; |
|||
client_max_body_size 1000m; |
|||
ignore_invalid_headers off; |
|||
proxy_buffering off; |
|||
# port_in_redirect off; |
|||
|
|||
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,16 @@ |
|||
redis-server --requirepass $REDIS_PASSWORD & |
|||
/opt/clouseau/bin/clouseau & |
|||
/minio/minio server /minio & |
|||
/docker-entrypoint.sh /opt/couchdb/bin/couchdb & |
|||
/etc/init.d/nginx restart |
|||
pushd app |
|||
pm2 start --name app "yarn run:docker" |
|||
popd |
|||
pushd worker |
|||
pm2 start --name worker "yarn run:docker" |
|||
popd |
|||
sleep 10 |
|||
URL=http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@localhost:5984 |
|||
curl -X PUT ${URL}/_users |
|||
curl -X PUT ${URL}/_replicator |
|||
sleep infinity |
|||
@ -0,0 +1,32 @@ |
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|||
# use this file except in compliance with the License. You may obtain a copy of |
|||
# the License at |
|||
# |
|||
# http://www.apache.org/licenses/LICENSE-2.0 |
|||
# |
|||
# Unless required by applicable law or agreed to in writing, software |
|||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|||
# License for the specific language governing permissions and limitations under |
|||
# the License. |
|||
|
|||
# erlang cookie for clouseau security |
|||
-name couchdb@127.0.0.1 |
|||
-setcookie monster |
|||
|
|||
# Ensure that the Erlang VM listens on a known port |
|||
-kernel inet_dist_listen_min 9100 |
|||
-kernel inet_dist_listen_max 9100 |
|||
|
|||
# Tell kernel and SASL not to log anything |
|||
-kernel error_logger silent |
|||
-sasl sasl_error_logger false |
|||
|
|||
# Use kernel poll functionality if supported by emulator |
|||
+K true |
|||
|
|||
# Start a pool of asynchronous IO threads |
|||
+A 16 |
|||
|
|||
# Comment this line out to enable the interactive Erlang shell on startup |
|||
+Bd -noinput |
|||
@ -0,0 +1 @@ |
|||
module.exports = require("./src/security/encryption") |
|||
@ -1,27 +0,0 @@ |
|||
const { |
|||
isMultiTenant, |
|||
updateTenantId, |
|||
isTenantIdSet, |
|||
DEFAULT_TENANT_ID, |
|||
updateAppId, |
|||
} = require("../tenancy") |
|||
const ContextFactory = require("../context/FunctionContext") |
|||
const { getTenantIDFromAppID } = require("../db/utils") |
|||
|
|||
module.exports = () => { |
|||
return ContextFactory.getMiddleware(ctx => { |
|||
// if not in multi-tenancy mode make sure its default and exit
|
|||
if (!isMultiTenant()) { |
|||
updateTenantId(DEFAULT_TENANT_ID) |
|||
return |
|||
} |
|||
// if tenant ID already set no need to continue
|
|||
if (isTenantIdSet()) { |
|||
return |
|||
} |
|||
const appId = ctx.appId ? ctx.appId : ctx.user ? ctx.user.appId : null |
|||
const tenantId = getTenantIDFromAppID(appId) || DEFAULT_TENANT_ID |
|||
updateTenantId(tenantId) |
|||
updateAppId(appId) |
|||
}) |
|||
} |
|||
@ -0,0 +1 @@ |
|||
exports.lookupApiKey = async () => {} |
|||
@ -0,0 +1,33 @@ |
|||
const crypto = require("crypto") |
|||
const env = require("../environment") |
|||
|
|||
const ALGO = "aes-256-ctr" |
|||
const SECRET = env.JWT_SECRET |
|||
const SEPARATOR = "-" |
|||
const ITERATIONS = 10000 |
|||
const RANDOM_BYTES = 16 |
|||
const STRETCH_LENGTH = 32 |
|||
|
|||
function stretchString(string, salt) { |
|||
return crypto.pbkdf2Sync(string, salt, ITERATIONS, STRETCH_LENGTH, "sha512") |
|||
} |
|||
|
|||
exports.encrypt = input => { |
|||
const salt = crypto.randomBytes(RANDOM_BYTES) |
|||
const stretched = stretchString(SECRET, salt) |
|||
const cipher = crypto.createCipheriv(ALGO, stretched, salt) |
|||
const base = cipher.update(input) |
|||
const final = cipher.final() |
|||
const encrypted = Buffer.concat([base, final]).toString("hex") |
|||
return `${salt.toString("hex")}${SEPARATOR}${encrypted}` |
|||
} |
|||
|
|||
exports.decrypt = input => { |
|||
const [salt, encrypted] = input.split(SEPARATOR) |
|||
const saltBuffer = Buffer.from(salt, "hex") |
|||
const stretched = stretchString(SECRET, saltBuffer) |
|||
const decipher = crypto.createDecipheriv(ALGO, stretched, saltBuffer) |
|||
const base = decipher.update(Buffer.from(encrypted, "hex")) |
|||
const final = decipher.final() |
|||
return Buffer.concat([base, final]).toString() |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
<script> |
|||
import "@spectrum-css/toast/dist/index-vars.css" |
|||
import Portal from "svelte-portal" |
|||
import { banner } from "../Stores/banner" |
|||
import Banner from "./Banner.svelte" |
|||
import { fly } from "svelte/transition" |
|||
</script> |
|||
|
|||
<Portal target=".banner-container"> |
|||
<div class="banner"> |
|||
{#if $banner.message} |
|||
<div transition:fly={{ y: -30 }}> |
|||
<Banner |
|||
type={$banner.type} |
|||
extraButtonText={$banner.extraButtonText} |
|||
extraButtonAction={$banner.extraButtonAction} |
|||
on:change={$banner.onChange} |
|||
> |
|||
{$banner.message} |
|||
</Banner> |
|||
</div> |
|||
{/if} |
|||
</div> |
|||
</Portal> |
|||
|
|||
<style> |
|||
.banner { |
|||
pointer-events: none; |
|||
width: 100%; |
|||
} |
|||
</style> |
|||
@ -0,0 +1,37 @@ |
|||
import { writable } from "svelte/store" |
|||
|
|||
export function createBannerStore() { |
|||
const DEFAULT_CONFIG = {} |
|||
|
|||
const banner = writable(DEFAULT_CONFIG) |
|||
|
|||
const show = async ( |
|||
// eslint-disable-next-line
|
|||
config = { message, type, extraButtonText, extraButtonAction, onChange } |
|||
) => { |
|||
banner.update(store => { |
|||
return { |
|||
...store, |
|||
...config, |
|||
} |
|||
}) |
|||
} |
|||
|
|||
const showStatus = async () => { |
|||
const config = { |
|||
message: "Some systems are experiencing issues", |
|||
type: "negative", |
|||
extraButtonText: "View Status", |
|||
extraButtonAction: () => window.open("https://status.budibase.com/"), |
|||
} |
|||
|
|||
await show(config) |
|||
} |
|||
|
|||
return { |
|||
subscribe: banner.subscribe, |
|||
showStatus, |
|||
} |
|||
} |
|||
|
|||
export const banner = createBannerStore() |
|||
@ -1,43 +1,47 @@ |
|||
import filterTests from "../../support/filterTests" |
|||
|
|||
filterTests(['smoke', 'all'], () => { |
|||
context("REST Datasource Testing", () => { |
|||
before(() => { |
|||
cy.login() |
|||
cy.createTestApp() |
|||
}) |
|||
|
|||
const datasource = "REST" |
|||
const restUrl = "https://api.openbrewerydb.org/breweries" |
|||
|
|||
it("Should add REST data source with incorrect API", () => { |
|||
// Select REST data source
|
|||
cy.selectExternalDatasource(datasource) |
|||
// Enter incorrect api & attempt to send query
|
|||
cy.wait(500) |
|||
cy.get(".spectrum-Button").contains("Add query").click({ force: true }) |
|||
cy.intercept('**/preview').as('queryError') |
|||
cy.get("input").clear().type("random text") |
|||
cy.get(".spectrum-Button").contains("Send").click({ force: true }) |
|||
// Intercept Request after button click & apply assertions
|
|||
cy.wait("@queryError") |
|||
cy.get("@queryError").its('response.body') |
|||
.should('have.property', 'message', 'Invalid URL: http://random text?') |
|||
cy.get("@queryError").its('response.body') |
|||
.should('have.property', 'status', 400) |
|||
}) |
|||
|
|||
it("should add and configure a REST datasource", () => { |
|||
// Select REST datasource and create query
|
|||
cy.selectExternalDatasource(datasource) |
|||
cy.wait(500) |
|||
// createRestQuery confirms query creation
|
|||
cy.createRestQuery("GET", restUrl) |
|||
// Confirm status code response within REST datasource
|
|||
cy.get(".spectrum-FieldLabel") |
|||
.contains("Status") |
|||
.children() |
|||
.should('contain', 200) |
|||
}) |
|||
filterTests(["smoke", "all"], () => { |
|||
context("REST Datasource Testing", () => { |
|||
before(() => { |
|||
cy.login() |
|||
cy.createTestApp() |
|||
}) |
|||
|
|||
const datasource = "REST" |
|||
const restUrl = "https://api.openbrewerydb.org/breweries" |
|||
|
|||
it("Should add REST data source with incorrect API", () => { |
|||
// Select REST data source
|
|||
cy.selectExternalDatasource(datasource) |
|||
// Enter incorrect api & attempt to send query
|
|||
cy.wait(500) |
|||
cy.get(".spectrum-Button").contains("Add query").click({ force: true }) |
|||
cy.intercept("**/preview").as("queryError") |
|||
cy.get("input").clear().type("random text") |
|||
cy.get(".spectrum-Button").contains("Send").click({ force: true }) |
|||
// Intercept Request after button click & apply assertions
|
|||
cy.wait("@queryError") |
|||
cy.get("@queryError") |
|||
.its("response.body") |
|||
.should("have.property", "message", "Invalid URL: http://random text?") |
|||
cy.get("@queryError") |
|||
.its("response.body") |
|||
.should("have.property", "status", 400) |
|||
}) |
|||
|
|||
it("should add and configure a REST datasource", () => { |
|||
// Select REST datasource and create query
|
|||
cy.selectExternalDatasource(datasource) |
|||
cy.wait(500) |
|||
// createRestQuery confirms query creation
|
|||
cy.createRestQuery("GET", restUrl, "/breweries") |
|||
// Confirm status code response within REST datasource
|
|||
cy.wait(1000) |
|||
cy.get(".stats").within(() => { |
|||
cy.get(".spectrum-FieldLabel") |
|||
.eq(0) |
|||
.should("contain", 200) |
|||
}) |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue