mirror of https://github.com/Budibase/budibase.git
183 changed files with 11375 additions and 1203 deletions
@ -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 @@ |
|||||
|
module.exports = require("./src/security/encryption") |
||||
@ -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() |
||||
|
} |
||||
@ -1,43 +1,45 @@ |
|||||
import filterTests from "../../support/filterTests" |
import filterTests from "../../support/filterTests" |
||||
|
|
||||
filterTests(['smoke', 'all'], () => { |
filterTests(["smoke", "all"], () => { |
||||
context("REST Datasource Testing", () => { |
context("REST Datasource Testing", () => { |
||||
before(() => { |
before(() => { |
||||
cy.login() |
cy.login() |
||||
cy.createTestApp() |
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) |
|
||||
}) |
|
||||
}) |
}) |
||||
|
|
||||
|
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.get(".spectrum-FieldLabel") |
||||
|
.contains("Status") |
||||
|
.children() |
||||
|
.should("contain", 200) |
||||
|
}) |
||||
|
}) |
||||
}) |
}) |
||||
|
|||||
@ -0,0 +1,64 @@ |
|||||
|
<script> |
||||
|
import { |
||||
|
Select, |
||||
|
Toggle, |
||||
|
DatePicker, |
||||
|
Multiselect, |
||||
|
TextArea, |
||||
|
} from "@budibase/bbui" |
||||
|
import LinkedRowSelector from "components/common/LinkedRowSelector.svelte" |
||||
|
import DrawerBindableInput from "../../common/bindings/DrawerBindableInput.svelte" |
||||
|
import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte" |
||||
|
|
||||
|
export let onChange |
||||
|
export let field |
||||
|
export let schema |
||||
|
export let value |
||||
|
export let bindings |
||||
|
|
||||
|
function schemaHasOptions(schema) { |
||||
|
return !!schema.constraints?.inclusion?.length |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
{#if schemaHasOptions(schema) && schema.type !== "array"} |
||||
|
<Select |
||||
|
on:change={e => onChange(e, field)} |
||||
|
label={field} |
||||
|
value={value[field]} |
||||
|
options={schema.constraints.inclusion} |
||||
|
/> |
||||
|
{:else if schema.type === "datetime"} |
||||
|
<DatePicker |
||||
|
label={field} |
||||
|
value={value[field]} |
||||
|
on:change={e => onChange(e, field)} |
||||
|
/> |
||||
|
{:else if schema.type === "boolean"} |
||||
|
<Toggle |
||||
|
text={field} |
||||
|
value={value[field]} |
||||
|
on:change={e => onChange(e, field)} |
||||
|
/> |
||||
|
{:else if schema.type === "array"} |
||||
|
<Multiselect |
||||
|
bind:value={value[field]} |
||||
|
label={field} |
||||
|
options={schema.constraints.inclusion} |
||||
|
/> |
||||
|
{:else if schema.type === "longform"} |
||||
|
<TextArea label={field} bind:value={value[field]} /> |
||||
|
{:else if schema.type === "link"} |
||||
|
<LinkedRowSelector bind:linkedRows={value[field]} {schema} /> |
||||
|
{:else if schema.type === "string" || schema.type === "number"} |
||||
|
<DrawerBindableInput |
||||
|
panel={AutomationBindingPanel} |
||||
|
value={value[field]} |
||||
|
on:change={e => onChange(e, field)} |
||||
|
label={field} |
||||
|
type="string" |
||||
|
{bindings} |
||||
|
fillWidth={true} |
||||
|
allowJS={true} |
||||
|
/> |
||||
|
{/if} |
||||
@ -0,0 +1,58 @@ |
|||||
|
<script> |
||||
|
import { Input, Icon, notifications } from "@budibase/bbui" |
||||
|
|
||||
|
export let label = null |
||||
|
export let value |
||||
|
export let copyValue |
||||
|
|
||||
|
const copyToClipboard = val => { |
||||
|
const dummy = document.createElement("textarea") |
||||
|
document.body.appendChild(dummy) |
||||
|
dummy.value = val |
||||
|
dummy.select() |
||||
|
document.execCommand("copy") |
||||
|
document.body.removeChild(dummy) |
||||
|
notifications.success(`URL copied to clipboard`) |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<div> |
||||
|
<Input readonly {value} {label} /> |
||||
|
<div class="icon" on:click={() => copyToClipboard(value || copyValue)}> |
||||
|
<Icon size="S" name="Copy" /> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<style> |
||||
|
div { |
||||
|
position: relative; |
||||
|
} |
||||
|
|
||||
|
.icon { |
||||
|
right: 1px; |
||||
|
bottom: 1px; |
||||
|
position: absolute; |
||||
|
justify-content: center; |
||||
|
align-items: center; |
||||
|
display: flex; |
||||
|
flex-direction: row; |
||||
|
box-sizing: border-box; |
||||
|
border-left: 1px solid var(--spectrum-alias-border-color); |
||||
|
border-top-right-radius: var(--spectrum-alias-border-radius-regular); |
||||
|
border-bottom-right-radius: var(--spectrum-alias-border-radius-regular); |
||||
|
width: 31px; |
||||
|
color: var(--spectrum-alias-text-color); |
||||
|
background-color: var(--spectrum-global-color-gray-75); |
||||
|
transition: background-color |
||||
|
var(--spectrum-global-animation-duration-100, 130ms), |
||||
|
box-shadow var(--spectrum-global-animation-duration-100, 130ms), |
||||
|
border-color var(--spectrum-global-animation-duration-100, 130ms); |
||||
|
height: calc(var(--spectrum-alias-item-height-m) - 2px); |
||||
|
} |
||||
|
.icon:hover { |
||||
|
cursor: pointer; |
||||
|
color: var(--spectrum-alias-text-color-hover); |
||||
|
background-color: var(--spectrum-global-color-gray-50); |
||||
|
border-color: var(--spectrum-alias-border-color-hover); |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,71 @@ |
|||||
|
<script> |
||||
|
import { Label, Select, Body } from "@budibase/bbui" |
||||
|
import { tables } from "stores/backend" |
||||
|
import { onMount } from "svelte" |
||||
|
|
||||
|
export let parameters |
||||
|
$: tableOptions = $tables.list || [] |
||||
|
|
||||
|
const FORMATS = [ |
||||
|
{ |
||||
|
label: "CSV", |
||||
|
value: "csv", |
||||
|
}, |
||||
|
{ |
||||
|
label: "JSON", |
||||
|
value: "json", |
||||
|
}, |
||||
|
] |
||||
|
|
||||
|
onMount(() => { |
||||
|
if (!parameters.type) { |
||||
|
parameters.type = "csv" |
||||
|
} |
||||
|
}) |
||||
|
</script> |
||||
|
|
||||
|
<div class="root"> |
||||
|
<Body size="S"> |
||||
|
Choose the table that you would like to export your row selection from. |
||||
|
<br /> |
||||
|
Please ensure you have enabled row selection in the table settings |
||||
|
</Body> |
||||
|
|
||||
|
<div class="params"> |
||||
|
<Label small>Table</Label> |
||||
|
<Select |
||||
|
bind:value={parameters.tableId} |
||||
|
options={tableOptions} |
||||
|
getOptionLabel={option => option.name} |
||||
|
getOptionValue={option => option._id} |
||||
|
/> |
||||
|
|
||||
|
<Label small>Type</Label> |
||||
|
<Select bind:value={parameters.type} options={FORMATS} /> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<style> |
||||
|
.root { |
||||
|
width: 100%; |
||||
|
max-width: 800px; |
||||
|
margin: 0 auto; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
justify-content: flex-start; |
||||
|
align-items: stretch; |
||||
|
gap: var(--spacing-xl); |
||||
|
} |
||||
|
|
||||
|
.root :global(p) { |
||||
|
line-height: 1.5; |
||||
|
} |
||||
|
|
||||
|
.params { |
||||
|
display: grid; |
||||
|
column-gap: var(--spacing-l); |
||||
|
row-gap: var(--spacing-s); |
||||
|
grid-template-columns: 100px 1fr; |
||||
|
align-items: center; |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,41 @@ |
|||||
|
<script> |
||||
|
import { ModalContent, Body, notifications } from "@budibase/bbui" |
||||
|
import { auth } from "stores/portal" |
||||
|
import { onMount } from "svelte" |
||||
|
import CopyInput from "components/common/inputs/CopyInput.svelte" |
||||
|
|
||||
|
let apiKey = null |
||||
|
|
||||
|
async function generateAPIKey() { |
||||
|
try { |
||||
|
apiKey = await auth.generateAPIKey() |
||||
|
notifications.success("New API key generated") |
||||
|
} catch (err) { |
||||
|
notifications.error("Unable to generate new API key") |
||||
|
} |
||||
|
// need to return false to keep modal open |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
onMount(async () => { |
||||
|
try { |
||||
|
apiKey = await auth.fetchAPIKey() |
||||
|
} catch (err) { |
||||
|
notifications.error("Unable to fetch API key") |
||||
|
} |
||||
|
}) |
||||
|
</script> |
||||
|
|
||||
|
<ModalContent |
||||
|
title="Developer information" |
||||
|
showConfirmButton={false} |
||||
|
showSecondaryButton={true} |
||||
|
secondaryButtonText="Re-generate key" |
||||
|
secondaryAction={generateAPIKey} |
||||
|
> |
||||
|
<Body size="S"> |
||||
|
You can find information about your developer account here, such as the API |
||||
|
key used to access the Budibase API. |
||||
|
</Body> |
||||
|
<CopyInput bind:value={apiKey} label="API key" /> |
||||
|
</ModalContent> |
||||
@ -0,0 +1,8 @@ |
|||||
|
<script> |
||||
|
import Provider from "./Provider.svelte" |
||||
|
import { rowSelectionStore } from "stores" |
||||
|
</script> |
||||
|
|
||||
|
<Provider key="rowSelection" data={$rowSelectionStore}> |
||||
|
<slot /> |
||||
|
</Provider> |
||||
@ -0,0 +1,31 @@ |
|||||
|
import { get, writable } from "svelte/store" |
||||
|
|
||||
|
const createRowSelectionStore = () => { |
||||
|
const store = writable({}) |
||||
|
|
||||
|
function updateSelection(componentId, tableId, selectedRows) { |
||||
|
store.update(state => { |
||||
|
state[componentId] = { tableId: tableId, selectedRows: selectedRows } |
||||
|
return state |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
function getSelection(tableId) { |
||||
|
const selection = get(store) |
||||
|
const componentId = Object.keys(selection).find( |
||||
|
componentId => selection[componentId].tableId === tableId |
||||
|
) |
||||
|
return componentId ? selection[componentId] : {} |
||||
|
} |
||||
|
|
||||
|
return { |
||||
|
subscribe: store.subscribe, |
||||
|
set: store.set, |
||||
|
actions: { |
||||
|
updateSelection, |
||||
|
getSelection, |
||||
|
}, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export const rowSelectionStore = createRowSelectionStore() |
||||
@ -0,0 +1,54 @@ |
|||||
|
export const buildSelfEndpoints = API => ({ |
||||
|
/** |
||||
|
* Using the logged in user, this will generate a new API key, |
||||
|
* assuming the user is a builder. |
||||
|
* @return {Promise<object>} returns the API response, including an API key. |
||||
|
*/ |
||||
|
generateAPIKey: async () => { |
||||
|
const response = await API.post({ |
||||
|
url: "/api/global/self/api_key", |
||||
|
}) |
||||
|
return response?.apiKey |
||||
|
}, |
||||
|
|
||||
|
/** |
||||
|
* retrieves the API key for the logged in user. |
||||
|
* @return {Promise<object>} An object containing the user developer information. |
||||
|
*/ |
||||
|
fetchDeveloperInfo: async () => { |
||||
|
return API.get({ |
||||
|
url: "/api/global/self/api_key", |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
/** |
||||
|
* Fetches the currently logged-in user object. |
||||
|
* Used in client apps. |
||||
|
*/ |
||||
|
fetchSelf: async () => { |
||||
|
return await API.get({ |
||||
|
url: "/api/self", |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
/** |
||||
|
* Fetches the currently logged-in user object. |
||||
|
* Used in the builder. |
||||
|
*/ |
||||
|
fetchBuilderSelf: async () => { |
||||
|
return await API.get({ |
||||
|
url: "/api/global/self", |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
/** |
||||
|
* Updates the current logged-in user. |
||||
|
* @param user the new user object to save |
||||
|
*/ |
||||
|
updateSelf: async user => { |
||||
|
return await API.post({ |
||||
|
url: "/api/global/self", |
||||
|
body: user, |
||||
|
}) |
||||
|
}, |
||||
|
}) |
||||
@ -1,7 +1,5 @@ |
|||||
export { createAPIClient } from "./api" |
export { createAPIClient } from "./api" |
||||
export { createLocalStorageStore } from "./stores/localStorage" |
|
||||
export { fetchData } from "./fetch/fetchData" |
export { fetchData } from "./fetch/fetchData" |
||||
export * as Constants from "./constants" |
export * as Constants from "./constants" |
||||
export * as LuceneUtils from "./utils/lucene" |
export * from "./stores" |
||||
export * as JSONUtils from "./utils/json" |
export * from "./utils" |
||||
export * as CookieUtils from "./utils/cookies" |
|
||||
|
|||||
@ -0,0 +1 @@ |
|||||
|
export { createLocalStorageStore } from "./localStorage" |
||||
@ -0,0 +1,4 @@ |
|||||
|
export * as LuceneUtils from "./lucene" |
||||
|
export * as JSONUtils from "./json" |
||||
|
export * as CookieUtils from "./cookies" |
||||
|
export * as Utils from "./utils" |
||||
@ -0,0 +1,17 @@ |
|||||
|
/** |
||||
|
* Utility to wrap an async function and ensure all invocations happen |
||||
|
* sequentially. |
||||
|
* @param fn the async function to run |
||||
|
* @return {Promise} a sequential version of the function |
||||
|
*/ |
||||
|
export const sequential = fn => { |
||||
|
let promise |
||||
|
return async (...params) => { |
||||
|
if (promise) { |
||||
|
await promise |
||||
|
} |
||||
|
promise = fn(...params) |
||||
|
await promise |
||||
|
promise = null |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,94 @@ |
|||||
|
const swaggerJsdoc = require("swagger-jsdoc") |
||||
|
const { join } = require("path") |
||||
|
const { writeFileSync } = require("fs") |
||||
|
const { examples, schemas } = require("./resources") |
||||
|
const parameters = require("./parameters") |
||||
|
const security = require("./security") |
||||
|
|
||||
|
const VARIABLES = {} |
||||
|
|
||||
|
const options = { |
||||
|
definition: { |
||||
|
openapi: "3.0.0", |
||||
|
info: { |
||||
|
title: "Budibase API", |
||||
|
description: "The public API for Budibase apps and its services.", |
||||
|
version: "1.0.0", |
||||
|
}, |
||||
|
servers: [ |
||||
|
{ |
||||
|
url: "https://budibase.app/api/public/v1", |
||||
|
description: "Budibase Cloud API", |
||||
|
}, |
||||
|
{ |
||||
|
url: "{protocol}://{hostname}/api/public/v1", |
||||
|
description: "Budibase self hosted API", |
||||
|
variables: { |
||||
|
protocol: { |
||||
|
default: "http", |
||||
|
description: |
||||
|
"Whether HTTP or HTTPS should be used to communicate with your Budibase instance.", |
||||
|
}, |
||||
|
hostname: { |
||||
|
default: "localhost:10000", |
||||
|
description: "The URL of your Budibase instance.", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
], |
||||
|
components: { |
||||
|
parameters: { |
||||
|
...parameters, |
||||
|
}, |
||||
|
examples: { |
||||
|
...examples, |
||||
|
}, |
||||
|
securitySchemes: { |
||||
|
...security, |
||||
|
}, |
||||
|
schemas: { |
||||
|
...schemas, |
||||
|
}, |
||||
|
}, |
||||
|
security: [ |
||||
|
{ |
||||
|
ApiKeyAuth: [], |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
format: ".json", |
||||
|
apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.ts")], |
||||
|
} |
||||
|
|
||||
|
function writeFile(output, filename) { |
||||
|
try { |
||||
|
const path = join(__dirname, filename) |
||||
|
let spec = output |
||||
|
if (filename.endsWith("json")) { |
||||
|
spec = JSON.stringify(output, null, 2) |
||||
|
} |
||||
|
// input the static variables
|
||||
|
for (let [key, replacement] of Object.entries(VARIABLES)) { |
||||
|
spec = spec.replace(new RegExp(`{${key}}`, "g"), replacement) |
||||
|
} |
||||
|
writeFileSync(path, spec) |
||||
|
console.log(`Wrote spec to ${path}`) |
||||
|
return path |
||||
|
} catch (err) { |
||||
|
console.error(err) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function run() { |
||||
|
const outputJSON = swaggerJsdoc(options) |
||||
|
options.format = ".yaml" |
||||
|
const outputYAML = swaggerJsdoc(options) |
||||
|
writeFile(outputJSON, "openapi.json") |
||||
|
return writeFile(outputYAML, "openapi.yaml") |
||||
|
} |
||||
|
|
||||
|
if (require.main === module) { |
||||
|
run() |
||||
|
} |
||||
|
|
||||
|
module.exports = run |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,59 @@ |
|||||
|
exports.tableId = { |
||||
|
in: "path", |
||||
|
name: "tableId", |
||||
|
required: true, |
||||
|
description: "The ID of the table which this request is targeting.", |
||||
|
schema: { |
||||
|
type: "string", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
exports.rowId = { |
||||
|
in: "path", |
||||
|
name: "rowId", |
||||
|
required: true, |
||||
|
description: "The ID of the row which this request is targeting.", |
||||
|
schema: { |
||||
|
type: "string", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
exports.appId = { |
||||
|
in: "header", |
||||
|
name: "x-budibase-app-id", |
||||
|
required: true, |
||||
|
description: "The ID of the app which this request is targeting.", |
||||
|
schema: { |
||||
|
type: "string", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
exports.appIdUrl = { |
||||
|
in: "path", |
||||
|
name: "appId", |
||||
|
required: true, |
||||
|
description: "The ID of the app which this request is targeting.", |
||||
|
schema: { |
||||
|
type: "string", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
exports.queryId = { |
||||
|
in: "path", |
||||
|
name: "queryId", |
||||
|
required: true, |
||||
|
description: "The ID of the query which this request is targeting.", |
||||
|
schema: { |
||||
|
type: "string", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
exports.userId = { |
||||
|
in: "path", |
||||
|
name: "userId", |
||||
|
required: true, |
||||
|
description: "The ID of the user which this request is targeting.", |
||||
|
schema: { |
||||
|
type: "string", |
||||
|
}, |
||||
|
} |
||||
@ -0,0 +1,101 @@ |
|||||
|
const userResource = require("./user") |
||||
|
const { object } = require("./utils") |
||||
|
const Resource = require("./utils/Resource") |
||||
|
|
||||
|
const application = { |
||||
|
_id: "app_metadata", |
||||
|
appId: "app_dev_957b12f943d348faa61db7e18e088d0f", |
||||
|
version: "1.0.58-alpha.0", |
||||
|
name: "App name", |
||||
|
url: "/app-url", |
||||
|
tenantId: "default", |
||||
|
updatedAt: "2022-02-22T13:00:54.035Z", |
||||
|
createdAt: "2022-02-11T18:02:26.961Z", |
||||
|
status: "development", |
||||
|
lockedBy: userResource.getExamples().user.value.user, |
||||
|
} |
||||
|
|
||||
|
const base = { |
||||
|
name: { |
||||
|
description: "The name of the app.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
url: { |
||||
|
description: |
||||
|
"The URL by which the app is accessed, this must be URL encoded.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const applicationSchema = object(base, { required: ["name", "url"] }) |
||||
|
|
||||
|
const applicationOutputSchema = object( |
||||
|
{ |
||||
|
...base, |
||||
|
_id: { |
||||
|
description: "The ID of the app.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
status: { |
||||
|
description: |
||||
|
"The status of the app, stating it if is the development or published version.", |
||||
|
type: "string", |
||||
|
enum: ["development", "published"], |
||||
|
}, |
||||
|
createdAt: { |
||||
|
description: |
||||
|
"States when the app was created, will be constant. Stored in ISO format.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
updatedAt: { |
||||
|
description: |
||||
|
"States the last time the app was updated - stored in ISO format.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
version: { |
||||
|
description: |
||||
|
"States the version of the Budibase client this app is currently based on.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
tenantId: { |
||||
|
description: |
||||
|
"In a multi-tenant environment this will state the tenant this app is within.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
lockedBy: { |
||||
|
description: "The user this app is currently being built by.", |
||||
|
type: "object", |
||||
|
}, |
||||
|
}, |
||||
|
{ |
||||
|
required: [ |
||||
|
"_id", |
||||
|
"name", |
||||
|
"url", |
||||
|
"status", |
||||
|
"createdAt", |
||||
|
"updatedAt", |
||||
|
"version", |
||||
|
], |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
module.exports = new Resource() |
||||
|
.setExamples({ |
||||
|
application: { |
||||
|
value: { |
||||
|
data: application, |
||||
|
}, |
||||
|
}, |
||||
|
applications: { |
||||
|
value: { |
||||
|
data: [application], |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
.setSchemas({ |
||||
|
application: applicationSchema, |
||||
|
applicationOutput: object({ |
||||
|
data: applicationOutputSchema, |
||||
|
}), |
||||
|
}) |
||||
@ -0,0 +1,24 @@ |
|||||
|
const application = require("./application") |
||||
|
const row = require("./row") |
||||
|
const table = require("./table") |
||||
|
const query = require("./query") |
||||
|
const user = require("./user") |
||||
|
const misc = require("./misc") |
||||
|
|
||||
|
exports.examples = { |
||||
|
...application.getExamples(), |
||||
|
...row.getExamples(), |
||||
|
...table.getExamples(), |
||||
|
...query.getExamples(), |
||||
|
...user.getExamples(), |
||||
|
...misc.getExamples(), |
||||
|
} |
||||
|
|
||||
|
exports.schemas = { |
||||
|
...application.getSchemas(), |
||||
|
...row.getSchemas(), |
||||
|
...table.getSchemas(), |
||||
|
...query.getSchemas(), |
||||
|
...user.getSchemas(), |
||||
|
...misc.getSchemas(), |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
const { object } = require("./utils") |
||||
|
const Resource = require("./utils/Resource") |
||||
|
|
||||
|
module.exports = new Resource().setSchemas({ |
||||
|
nameSearch: object({ |
||||
|
name: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"The name to be used when searching - this will be used in a case insensitive starts with match.", |
||||
|
}, |
||||
|
}), |
||||
|
}) |
||||
@ -0,0 +1,189 @@ |
|||||
|
const Resource = require("./utils/Resource") |
||||
|
const { object } = require("./utils") |
||||
|
const { BaseQueryVerbs } = require("../../src/constants") |
||||
|
|
||||
|
const query = { |
||||
|
_id: "query_datasource_plus_4d8be0c506b9465daf4bf84d890fdab6_454854487c574d45bc4029b1e153219e", |
||||
|
datasourceId: "datasource_plus_4d8be0c506b9465daf4bf84d890fdab6", |
||||
|
parameters: [], |
||||
|
fields: { |
||||
|
sql: "select * from persons", |
||||
|
}, |
||||
|
queryVerb: "read", |
||||
|
name: "Help", |
||||
|
schema: { |
||||
|
personid: { |
||||
|
name: "personid", |
||||
|
type: "string", |
||||
|
}, |
||||
|
lastname: { |
||||
|
name: "lastname", |
||||
|
type: "string", |
||||
|
}, |
||||
|
firstname: { |
||||
|
name: "firstname", |
||||
|
type: "string", |
||||
|
}, |
||||
|
address: { |
||||
|
name: "address", |
||||
|
type: "string", |
||||
|
}, |
||||
|
city: { |
||||
|
name: "city", |
||||
|
type: "string", |
||||
|
}, |
||||
|
}, |
||||
|
transformer: "return data", |
||||
|
readable: true, |
||||
|
} |
||||
|
|
||||
|
const restResponse = { |
||||
|
value: { |
||||
|
data: [ |
||||
|
{ |
||||
|
value: "<html lang='en-GB'></html>", |
||||
|
}, |
||||
|
], |
||||
|
pagination: { |
||||
|
cursor: "2", |
||||
|
}, |
||||
|
raw: "<html lang='en-GB'></html>", |
||||
|
headers: { |
||||
|
"content-type": "text/html; charset=ISO-8859-1", |
||||
|
}, |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const sqlResponse = { |
||||
|
value: { |
||||
|
data: [ |
||||
|
{ |
||||
|
personid: 1, |
||||
|
lastname: "Hughes", |
||||
|
firstname: "Mike", |
||||
|
address: "123 Fake Street", |
||||
|
city: "Belfast", |
||||
|
}, |
||||
|
{ |
||||
|
personid: 2, |
||||
|
lastname: "Smith", |
||||
|
firstname: "John", |
||||
|
address: "64 Updown Road", |
||||
|
city: "Dublin", |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const querySchema = object( |
||||
|
{ |
||||
|
_id: { |
||||
|
description: "The ID of the query.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
datasourceId: { |
||||
|
description: "The ID of the data source the query belongs to.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
parameters: { |
||||
|
description: "The bindings which are required to perform this query.", |
||||
|
type: "array", |
||||
|
items: { |
||||
|
type: "string", |
||||
|
}, |
||||
|
}, |
||||
|
fields: { |
||||
|
description: |
||||
|
"The fields that are used to perform this query, e.g. the sql statement", |
||||
|
type: "object", |
||||
|
}, |
||||
|
queryVerb: { |
||||
|
description: "The verb that describes this query.", |
||||
|
enum: Object.values(BaseQueryVerbs), |
||||
|
}, |
||||
|
name: { |
||||
|
description: "The name of the query.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
schema: { |
||||
|
description: |
||||
|
"The schema of the data returned when the query is executed.", |
||||
|
type: "object", |
||||
|
}, |
||||
|
transformer: { |
||||
|
description: |
||||
|
"The JavaScript transformer function, applied after the query responds with data.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
readable: { |
||||
|
description: "Whether the query has readable data.", |
||||
|
type: "boolean", |
||||
|
}, |
||||
|
}, |
||||
|
{ required: ["name", "schema", "_id"] } |
||||
|
) |
||||
|
|
||||
|
const executeQuerySchema = { |
||||
|
description: |
||||
|
"The query body must contain the required parameters for the query, this depends on query type, setup and bindings.", |
||||
|
type: "object", |
||||
|
additionalProperties: { |
||||
|
description: |
||||
|
"Key value properties of any type, depending on the query output schema.", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const executeQueryOutputSchema = object( |
||||
|
{ |
||||
|
data: { |
||||
|
description: "The data response from the query.", |
||||
|
type: "array", |
||||
|
items: { |
||||
|
type: "object", |
||||
|
}, |
||||
|
}, |
||||
|
extra: { |
||||
|
description: |
||||
|
"Extra information that is not part of the main data, e.g. headers.", |
||||
|
type: "object", |
||||
|
properties: { |
||||
|
headers: { |
||||
|
description: |
||||
|
"If carrying out a REST request, this will contain the response headers.", |
||||
|
type: "object", |
||||
|
}, |
||||
|
raw: { |
||||
|
description: "The raw query response, as a string.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
pagination: { |
||||
|
description: |
||||
|
"If pagination is supported, this will contain the bookmark/anchor information for it.", |
||||
|
type: "object", |
||||
|
}, |
||||
|
}, |
||||
|
{ required: ["data"] } |
||||
|
) |
||||
|
|
||||
|
module.exports = new Resource() |
||||
|
.setExamples({ |
||||
|
query: { |
||||
|
value: { |
||||
|
data: query, |
||||
|
}, |
||||
|
}, |
||||
|
queries: { |
||||
|
value: { |
||||
|
data: [query], |
||||
|
}, |
||||
|
}, |
||||
|
restResponse, |
||||
|
sqlResponse, |
||||
|
}) |
||||
|
.setSchemas({ |
||||
|
executeQuery: executeQuerySchema, |
||||
|
executeQueryOutput: executeQueryOutputSchema, |
||||
|
query: querySchema, |
||||
|
}) |
||||
@ -0,0 +1,125 @@ |
|||||
|
const { object } = require("./utils") |
||||
|
const Resource = require("./utils/Resource") |
||||
|
|
||||
|
const baseRow = { |
||||
|
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4", |
||||
|
type: "row", |
||||
|
tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70", |
||||
|
name: "Mike", |
||||
|
age: 30, |
||||
|
} |
||||
|
|
||||
|
const inputRow = { |
||||
|
...baseRow, |
||||
|
relationship: ["ro_ta_..."], |
||||
|
} |
||||
|
|
||||
|
const row = { |
||||
|
...baseRow, |
||||
|
relationship: [ |
||||
|
{ |
||||
|
primaryDisplay: "Joe", |
||||
|
_id: "ro_ta_...", |
||||
|
}, |
||||
|
], |
||||
|
} |
||||
|
|
||||
|
const enrichedRow = { |
||||
|
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4", |
||||
|
name: "eg", |
||||
|
tableId: "ta_5b1649e42a5b41dea4ef7742a36a7a70", |
||||
|
type: "row", |
||||
|
relationship: [ |
||||
|
{ |
||||
|
_id: "ro_ta_users_us_8f3d717147d74d759d8cef5b6712062f", |
||||
|
name: "Joe", |
||||
|
tableId: "ta_users", |
||||
|
internal: [ |
||||
|
{ |
||||
|
_id: "ro_ta_5b1649e42a5b41dea4ef7742a36a7a70_e6dc7e38cf1343b2b56760265201cda4", |
||||
|
primaryDisplay: "eg", |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
], |
||||
|
} |
||||
|
|
||||
|
const rowSchema = { |
||||
|
description: "The row to be created/updated, based on the table schema.", |
||||
|
type: "object", |
||||
|
additionalProperties: { |
||||
|
description: |
||||
|
"Key value properties of any type, depending on the table schema.", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const rowOutputSchema = { |
||||
|
...rowSchema, |
||||
|
properties: { |
||||
|
...rowSchema.properties, |
||||
|
_id: { |
||||
|
description: "The ID of the row.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
tableId: { |
||||
|
description: "The ID of the table this row comes from.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
}, |
||||
|
required: ["tableId", "_id"], |
||||
|
} |
||||
|
|
||||
|
const searchOutputSchema = { |
||||
|
type: "object", |
||||
|
required: ["data"], |
||||
|
properties: { |
||||
|
data: { |
||||
|
description: |
||||
|
"An array of rows, these will each contain an _id field which can be used to update or delete them.", |
||||
|
type: "array", |
||||
|
items: { |
||||
|
type: "object", |
||||
|
}, |
||||
|
}, |
||||
|
bookmark: { |
||||
|
description: "If pagination in use, this should be provided.", |
||||
|
oneOf: [{ type: "string" }, { type: "integer" }], |
||||
|
}, |
||||
|
hasNextPage: { |
||||
|
description: |
||||
|
"If pagination in use, this will determine if there is another page to fetch.", |
||||
|
type: "boolean", |
||||
|
}, |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
module.exports = new Resource() |
||||
|
.setExamples({ |
||||
|
inputRow: { |
||||
|
value: inputRow, |
||||
|
}, |
||||
|
row: { |
||||
|
value: { |
||||
|
data: row, |
||||
|
}, |
||||
|
}, |
||||
|
enrichedRow: { |
||||
|
value: { |
||||
|
data: enrichedRow, |
||||
|
}, |
||||
|
}, |
||||
|
rows: { |
||||
|
value: { |
||||
|
data: [row], |
||||
|
hasNextPage: true, |
||||
|
bookmark: 10, |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
.setSchemas({ |
||||
|
row: rowSchema, |
||||
|
searchOutput: searchOutputSchema, |
||||
|
rowOutput: object({ |
||||
|
data: rowOutputSchema, |
||||
|
}), |
||||
|
}) |
||||
@ -0,0 +1,191 @@ |
|||||
|
const { |
||||
|
FieldTypes, |
||||
|
RelationshipTypes, |
||||
|
FormulaTypes, |
||||
|
} = require("../../src/constants") |
||||
|
const { object } = require("./utils") |
||||
|
const Resource = require("./utils/Resource") |
||||
|
|
||||
|
const table = { |
||||
|
_id: "ta_5b1649e42a5b41dea4ef7742a36a7a70", |
||||
|
name: "People", |
||||
|
schema: { |
||||
|
name: { |
||||
|
type: "string", |
||||
|
name: "name", |
||||
|
}, |
||||
|
age: { |
||||
|
type: "number", |
||||
|
name: "age", |
||||
|
}, |
||||
|
relationship: { |
||||
|
type: "link", |
||||
|
name: "relationship", |
||||
|
tableId: "ta_...", |
||||
|
fieldName: "relatedColumn", |
||||
|
relationshipType: "many-to-many", |
||||
|
}, |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const baseColumnDef = { |
||||
|
type: { |
||||
|
type: "string", |
||||
|
enum: Object.values(FieldTypes), |
||||
|
description: |
||||
|
"Defines the type of the column, most explain themselves, a link column is a relationship.", |
||||
|
}, |
||||
|
constraints: { |
||||
|
type: "object", |
||||
|
description: |
||||
|
"A constraint can be applied to the column which will be validated against when a row is saved.", |
||||
|
properties: { |
||||
|
type: { |
||||
|
type: "string", |
||||
|
enum: ["string", "number", "object", "boolean"], |
||||
|
}, |
||||
|
presence: { |
||||
|
type: "boolean", |
||||
|
description: "Defines whether the column is required or not.", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
name: { |
||||
|
type: "string", |
||||
|
description: "The name of the column.", |
||||
|
}, |
||||
|
autocolumn: { |
||||
|
type: "boolean", |
||||
|
description: "Defines whether the column is automatically generated.", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const tableSchema = { |
||||
|
description: "The table to be created/updated.", |
||||
|
type: "object", |
||||
|
required: ["name", "schema"], |
||||
|
properties: { |
||||
|
name: { |
||||
|
description: "The name of the table.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
primaryDisplay: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"The name of the column which should be used in relationship tags when relating to this table.", |
||||
|
}, |
||||
|
schema: { |
||||
|
type: "object", |
||||
|
additionalProperties: { |
||||
|
oneOf: [ |
||||
|
// relationship
|
||||
|
{ |
||||
|
type: "object", |
||||
|
properties: { |
||||
|
...baseColumnDef, |
||||
|
type: { |
||||
|
type: "string", |
||||
|
enum: [FieldTypes.LINK], |
||||
|
description: "A relationship column.", |
||||
|
}, |
||||
|
fieldName: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"The name of the column which a relationship column is related to in another table.", |
||||
|
}, |
||||
|
tableId: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"The ID of the table which a relationship column is related to.", |
||||
|
}, |
||||
|
relationshipType: { |
||||
|
type: "string", |
||||
|
enum: Object.values(RelationshipTypes), |
||||
|
description: |
||||
|
"Defines the type of relationship that this column will be used for.", |
||||
|
}, |
||||
|
through: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"When using a SQL table that contains many to many relationships this defines the table the relationships are linked through.", |
||||
|
}, |
||||
|
foreignKey: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"When using a SQL table that contains a one to many relationship this defines the foreign key.", |
||||
|
}, |
||||
|
throughFrom: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"When using a SQL table that utilises a through table, this defines the primary key in the through table for this table.", |
||||
|
}, |
||||
|
throughTo: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"When using a SQL table that utilises a through table, this defines the primary key in the through table for the related table.", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
{ |
||||
|
type: "object", |
||||
|
properties: { |
||||
|
...baseColumnDef, |
||||
|
type: { |
||||
|
type: "string", |
||||
|
enum: [FieldTypes.FORMULA], |
||||
|
description: "A formula column.", |
||||
|
}, |
||||
|
formula: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"Defines a Handlebars or JavaScript formula to use, note that Javascript formulas are expected to be provided in the base64 format.", |
||||
|
}, |
||||
|
formulaType: { |
||||
|
type: "string", |
||||
|
enum: Object.values(FormulaTypes), |
||||
|
description: |
||||
|
"Defines whether this is a static or dynamic formula.", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
{ |
||||
|
type: "object", |
||||
|
properties: baseColumnDef, |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const tableOutputSchema = { |
||||
|
...tableSchema, |
||||
|
properties: { |
||||
|
...tableSchema.properties, |
||||
|
_id: { |
||||
|
description: "The ID of the table.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
}, |
||||
|
required: [...tableSchema.required, "_id"], |
||||
|
} |
||||
|
|
||||
|
module.exports = new Resource() |
||||
|
.setExamples({ |
||||
|
table: { |
||||
|
value: { |
||||
|
data: table, |
||||
|
}, |
||||
|
}, |
||||
|
tables: { |
||||
|
value: { |
||||
|
data: [table], |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
.setSchemas({ |
||||
|
table: tableSchema, |
||||
|
tableOutput: object({ |
||||
|
data: tableOutputSchema, |
||||
|
}), |
||||
|
}) |
||||
@ -0,0 +1,126 @@ |
|||||
|
const { object } = require("./utils") |
||||
|
const Resource = require("./utils/Resource") |
||||
|
|
||||
|
const user = { |
||||
|
_id: "us_693a73206518477283a8d5ae31103252", |
||||
|
email: "test@test.com", |
||||
|
roles: { |
||||
|
app_957b12f943d348faa61db7e18e088d0f: "BASIC", |
||||
|
}, |
||||
|
builder: { |
||||
|
global: false, |
||||
|
}, |
||||
|
admin: { |
||||
|
global: true, |
||||
|
}, |
||||
|
tenantId: "default", |
||||
|
status: "active", |
||||
|
budibaseAccess: true, |
||||
|
csrfToken: "9c70291d-7137-48f9-9166-99ab5473a3d4", |
||||
|
userId: "us_693a73206518477283a8d5ae31103252", |
||||
|
roleId: "ADMIN", |
||||
|
role: { |
||||
|
_id: "ADMIN", |
||||
|
name: "Admin", |
||||
|
permissionId: "admin", |
||||
|
inherits: "POWER", |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
const userSchema = object( |
||||
|
{ |
||||
|
email: { |
||||
|
description: "The email address of the user, this must be unique.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
password: { |
||||
|
description: |
||||
|
"The password of the user if using password based login - this will never be returned. This can be" + |
||||
|
" left out of subsequent requests (updates) and will be enriched back into the user structure.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
status: { |
||||
|
description: "The status of the user, if they are active.", |
||||
|
type: "string", |
||||
|
enum: ["active"], |
||||
|
}, |
||||
|
firstName: { |
||||
|
description: "The first name of the user", |
||||
|
type: "string", |
||||
|
}, |
||||
|
lastName: { |
||||
|
description: "The last name of the user", |
||||
|
type: "string", |
||||
|
}, |
||||
|
forceResetPassword: { |
||||
|
description: |
||||
|
"If set to true forces the user to reset their password on first login.", |
||||
|
type: "boolean", |
||||
|
}, |
||||
|
builder: { |
||||
|
description: "Describes if the user is a builder user or not.", |
||||
|
type: "object", |
||||
|
properties: { |
||||
|
global: { |
||||
|
description: |
||||
|
"If set to true the user will be able to build any app in the system.", |
||||
|
type: "boolean", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
admin: { |
||||
|
description: "Describes if the user is an admin user or not.", |
||||
|
type: "object", |
||||
|
properties: { |
||||
|
global: { |
||||
|
description: |
||||
|
"If set to true the user will be able to administrate the system.", |
||||
|
type: "boolean", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
roles: { |
||||
|
description: |
||||
|
"Contains the roles of the user per app (assuming they are not a builder user).", |
||||
|
type: "object", |
||||
|
additionalProperties: { |
||||
|
type: "string", |
||||
|
description: |
||||
|
"A map of app ID (production app ID, minus the _dev component) to a role ID, e.g. ADMIN.", |
||||
|
}, |
||||
|
}, |
||||
|
}, |
||||
|
{ required: ["email", "roles"] } |
||||
|
) |
||||
|
|
||||
|
const userOutputSchema = { |
||||
|
...userSchema, |
||||
|
properties: { |
||||
|
...userSchema.properties, |
||||
|
_id: { |
||||
|
description: "The ID of the user.", |
||||
|
type: "string", |
||||
|
}, |
||||
|
}, |
||||
|
required: [...userSchema.required, "_id"], |
||||
|
} |
||||
|
|
||||
|
module.exports = new Resource() |
||||
|
.setExamples({ |
||||
|
user: { |
||||
|
value: { |
||||
|
data: user, |
||||
|
}, |
||||
|
}, |
||||
|
users: { |
||||
|
value: { |
||||
|
data: [user], |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
.setSchemas({ |
||||
|
user: userSchema, |
||||
|
userOutput: object({ |
||||
|
data: userOutputSchema, |
||||
|
}), |
||||
|
}) |
||||
@ -0,0 +1,26 @@ |
|||||
|
class Resource { |
||||
|
constructor() { |
||||
|
this.examples = {} |
||||
|
this.schemas = {} |
||||
|
} |
||||
|
|
||||
|
setExamples(examples) { |
||||
|
this.examples = examples |
||||
|
return this |
||||
|
} |
||||
|
|
||||
|
setSchemas(schemas) { |
||||
|
this.schemas = schemas |
||||
|
return this |
||||
|
} |
||||
|
|
||||
|
getExamples() { |
||||
|
return this.examples |
||||
|
} |
||||
|
|
||||
|
getSchemas() { |
||||
|
return this.schemas |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = Resource |
||||
@ -0,0 +1,11 @@ |
|||||
|
exports.object = (props, opts) => { |
||||
|
const base = { |
||||
|
type: "object", |
||||
|
properties: props, |
||||
|
...opts, |
||||
|
} |
||||
|
if (Object.keys(props).length > 0 && (!opts || !opts.required)) { |
||||
|
base.required = Object.keys(props) |
||||
|
} |
||||
|
return base |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
exports.ApiKeyAuth = { |
||||
|
type: "apiKey", |
||||
|
in: "header", |
||||
|
name: "x-budibase-api-key", |
||||
|
description: |
||||
|
"Your individual API key, this will provide access based on the configured RBAC settings of your user.", |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue