mirror of https://github.com/Budibase/budibase.git
201 changed files with 14305 additions and 1413 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() |
||||
File diff suppressed because one or more lines are too long
@ -1,61 +1,66 @@ |
|||||
export const buildAttachmentEndpoints = API => ({ |
export const buildAttachmentEndpoints = API => { |
||||
/** |
|
||||
* Uploads an attachment to the server. |
|
||||
* @param data the attachment to upload |
|
||||
* @param tableId the table ID to upload to |
|
||||
*/ |
|
||||
uploadAttachment: async ({ data, tableId }) => { |
|
||||
return await API.post({ |
|
||||
url: `/api/attachments/${tableId}/upload`, |
|
||||
body: data, |
|
||||
json: false, |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
/** |
|
||||
* Uploads an attachment to the server as a builder user from the builder. |
|
||||
* @param data the data to upload |
|
||||
*/ |
|
||||
uploadBuilderAttachment: async data => { |
|
||||
return await API.post({ |
|
||||
url: "/api/attachments/process", |
|
||||
body: data, |
|
||||
json: false, |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
/** |
/** |
||||
* Generates a signed URL to upload a file to an external datasource. |
* Generates a signed URL to upload a file to an external datasource. |
||||
* @param datasourceId the ID of the datasource to upload to |
* @param datasourceId the ID of the datasource to upload to |
||||
* @param bucket the name of the bucket to upload to |
* @param bucket the name of the bucket to upload to |
||||
* @param key the name of the file to upload to |
* @param key the name of the file to upload to |
||||
*/ |
*/ |
||||
getSignedDatasourceURL: async ({ datasourceId, bucket, key }) => { |
const getSignedDatasourceURL = async ({ datasourceId, bucket, key }) => { |
||||
return await API.post({ |
return await API.post({ |
||||
url: `/api/attachments/${datasourceId}/url`, |
url: `/api/attachments/${datasourceId}/url`, |
||||
body: { bucket, key }, |
body: { bucket, key }, |
||||
}) |
}) |
||||
}, |
} |
||||
|
|
||||
/** |
return { |
||||
* Uploads a file to an external datasource. |
getSignedDatasourceURL, |
||||
* @param datasourceId the ID of the datasource to upload to |
|
||||
* @param bucket the name of the bucket to upload to |
/** |
||||
* @param key the name of the file to upload to |
* Uploads an attachment to the server. |
||||
* @param data the file to upload |
* @param data the attachment to upload |
||||
*/ |
* @param tableId the table ID to upload to |
||||
externalUpload: async ({ datasourceId, bucket, key, data }) => { |
*/ |
||||
const { signedUrl, publicUrl } = await API.getSignedDatasourceURL({ |
uploadAttachment: async ({ data, tableId }) => { |
||||
datasourceId, |
return await API.post({ |
||||
bucket, |
url: `/api/attachments/${tableId}/upload`, |
||||
key, |
body: data, |
||||
}) |
json: false, |
||||
await API.put({ |
}) |
||||
url: signedUrl, |
}, |
||||
body: data, |
|
||||
json: false, |
/** |
||||
external: true, |
* Uploads an attachment to the server as a builder user from the builder. |
||||
}) |
* @param data the data to upload |
||||
return { publicUrl } |
*/ |
||||
}, |
uploadBuilderAttachment: async data => { |
||||
}) |
return await API.post({ |
||||
|
url: "/api/attachments/process", |
||||
|
body: data, |
||||
|
json: false, |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
/** |
||||
|
* Uploads a file to an external datasource. |
||||
|
* @param datasourceId the ID of the datasource to upload to |
||||
|
* @param bucket the name of the bucket to upload to |
||||
|
* @param key the name of the file to upload to |
||||
|
* @param data the file to upload |
||||
|
*/ |
||||
|
externalUpload: async ({ datasourceId, bucket, key, data }) => { |
||||
|
console.log(API) |
||||
|
const { signedUrl, publicUrl } = await getSignedDatasourceURL({ |
||||
|
datasourceId, |
||||
|
bucket, |
||||
|
key, |
||||
|
}) |
||||
|
await API.put({ |
||||
|
url: signedUrl, |
||||
|
body: data, |
||||
|
json: false, |
||||
|
external: true, |
||||
|
}) |
||||
|
return { publicUrl } |
||||
|
}, |
||||
|
} |
||||
|
} |
||||
|
|||||
@ -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,17 @@ |
|||||
|
module MySQLMock { |
||||
|
const mysql: any = {} |
||||
|
|
||||
|
const client = { |
||||
|
connect: jest.fn(), |
||||
|
end: jest.fn(), |
||||
|
query: jest.fn(async () => { |
||||
|
return [[]] |
||||
|
}), |
||||
|
} |
||||
|
|
||||
|
mysql.createConnection = jest.fn(async () => { |
||||
|
return client |
||||
|
}) |
||||
|
|
||||
|
module.exports = mysql |
||||
|
} |
||||
@ -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 |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue