forked from tsai/budibase
115 changed files with 10833 additions and 575 deletions
@ -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() |
|||
} |
|||
@ -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,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,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, |
|||
}) |
|||
}, |
|||
}) |
|||
@ -0,0 +1,83 @@ |
|||
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: "http://budibase.app/api/public/v1", |
|||
description: "Budibase Cloud API", |
|||
}, |
|||
{ |
|||
url: "{protocol}://{hostname}:10000/api/public/v1", |
|||
description: "Budibase self hosted API", |
|||
}, |
|||
], |
|||
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.", |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
const { getAllApps } = require("@budibase/backend-core/db") |
|||
const { updateAppId } = require("@budibase/backend-core/context") |
|||
import { search as stringSearch } from "./utils" |
|||
import { default as controller } from "../application" |
|||
import { Application } from "../../../definitions/common" |
|||
|
|||
function fixAppID(app: Application, params: any) { |
|||
if (!params) { |
|||
return app |
|||
} |
|||
if (!app._id && params.appId) { |
|||
app._id = params.appId |
|||
} |
|||
return app |
|||
} |
|||
|
|||
async function setResponseApp(ctx: any) { |
|||
if (ctx.body && ctx.body.appId && (!ctx.params || !ctx.params.appId)) { |
|||
ctx.params = { appId: ctx.body.appId } |
|||
} |
|||
await controller.fetchAppPackage(ctx) |
|||
} |
|||
|
|||
export async function search(ctx: any, next: any) { |
|||
const { name } = ctx.request.body |
|||
const apps = await getAllApps({ all: true }) |
|||
ctx.body = stringSearch(apps, name) |
|||
await next() |
|||
} |
|||
|
|||
export async function create(ctx: any, next: any) { |
|||
if (!ctx.request.body || !ctx.request.body.useTemplate) { |
|||
ctx.request.body = { |
|||
useTemplate: false, |
|||
...ctx.request.body, |
|||
} |
|||
} |
|||
await controller.create(ctx) |
|||
await setResponseApp(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function read(ctx: any, next: any) { |
|||
updateAppId(ctx.params.appId) |
|||
await setResponseApp(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function update(ctx: any, next: any) { |
|||
ctx.request.body = fixAppID(ctx.request.body, ctx.params) |
|||
updateAppId(ctx.params.appId) |
|||
await controller.update(ctx) |
|||
await setResponseApp(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function destroy(ctx: any, next: any) { |
|||
updateAppId(ctx.params.appId) |
|||
// get the app before deleting it
|
|||
await setResponseApp(ctx) |
|||
const body = ctx.body |
|||
await controller.delete(ctx) |
|||
// overwrite the body again
|
|||
ctx.body = body |
|||
await next() |
|||
} |
|||
|
|||
export default { |
|||
create, |
|||
update, |
|||
read, |
|||
destroy, |
|||
search, |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
import { Application } from "./types" |
|||
|
|||
function application(body: any): Application { |
|||
let app = body?.application ? body.application : body |
|||
return { |
|||
_id: app.appId, |
|||
name: app.name, |
|||
url: app.url, |
|||
status: app.status, |
|||
createdAt: app.createdAt, |
|||
updatedAt: app.updatedAt, |
|||
version: app.version, |
|||
tenantId: app.tenantId, |
|||
lockedBy: app.lockedBy, |
|||
} |
|||
} |
|||
|
|||
function mapApplication(ctx: any): { data: Application } { |
|||
return { |
|||
data: application(ctx.body), |
|||
} |
|||
} |
|||
|
|||
function mapApplications(ctx: any): { data: Application[] } { |
|||
const apps = ctx.body.map((body: any) => application(body)) |
|||
return { data: apps } |
|||
} |
|||
|
|||
export default { |
|||
mapApplication, |
|||
mapApplications, |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
import tables from "./tables" |
|||
import applications from "./applications" |
|||
import users from "./users" |
|||
import rows from "./rows" |
|||
import queries from "./queries" |
|||
|
|||
export default { |
|||
...tables, |
|||
...applications, |
|||
...users, |
|||
...rows, |
|||
...queries, |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
import { Query, ExecuteQuery } from "./types" |
|||
|
|||
function query(body: any): Query { |
|||
return { |
|||
_id: body._id, |
|||
datasourceId: body.datasourceId, |
|||
parameters: body.parameters, |
|||
fields: body.fields, |
|||
queryVerb: body.queryVerb, |
|||
name: body.name, |
|||
schema: body.schema, |
|||
transformer: body.transformer, |
|||
readable: body.readable, |
|||
} |
|||
} |
|||
|
|||
function mapQueries(ctx: any): { data: Query[] } { |
|||
const queries = ctx.body.map((body: any) => query(body)) |
|||
return { |
|||
data: queries, |
|||
} |
|||
} |
|||
|
|||
function mapQueryExecution(ctx: any): ExecuteQuery { |
|||
// very little we can map here, structure mostly unknown
|
|||
return { |
|||
data: ctx.body.data, |
|||
pagination: ctx.body.pagination, |
|||
extra: { |
|||
raw: ctx.body.raw, |
|||
headers: ctx.body.headers, |
|||
}, |
|||
} |
|||
} |
|||
|
|||
export default { |
|||
mapQueries, |
|||
mapQueryExecution, |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
import { Row, RowSearch } from "./types" |
|||
|
|||
function row(body: any): Row { |
|||
delete body._rev |
|||
// have to input everything, since structure unknown
|
|||
return { |
|||
...body, |
|||
_id: body._id, |
|||
tableId: body.tableId, |
|||
} |
|||
} |
|||
|
|||
function mapRowSearch(ctx: any): RowSearch { |
|||
const rows = ctx.body.rows.map((body: any) => row(body)) |
|||
return { |
|||
data: rows, |
|||
hasNextPage: ctx.body.hasNextPage, |
|||
bookmark: ctx.body.bookmark, |
|||
} |
|||
} |
|||
|
|||
function mapRow(ctx: any): { data: Row } { |
|||
return { |
|||
data: row(ctx.body), |
|||
} |
|||
} |
|||
|
|||
export default { |
|||
mapRowSearch, |
|||
mapRow, |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
import { Table } from "./types" |
|||
|
|||
function table(body: any): Table { |
|||
return { |
|||
_id: body._id, |
|||
name: body.name, |
|||
schema: body.schema, |
|||
primaryDisplay: body.primaryDisplay, |
|||
} |
|||
} |
|||
|
|||
function mapTable(ctx: any): { data: Table } { |
|||
return { |
|||
data: table(ctx.body), |
|||
} |
|||
} |
|||
|
|||
function mapTables(ctx: any): { data: Table[] } { |
|||
const tables = ctx.body.map((body: any) => table(body)) |
|||
return { data: tables } |
|||
} |
|||
|
|||
export default { |
|||
mapTable, |
|||
mapTables, |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
import { components } from "../../../../definitions/openapi" |
|||
|
|||
export type Query = components["schemas"]["query"] |
|||
export type ExecuteQuery = components["schemas"]["executeQueryOutput"] |
|||
|
|||
export type Application = components["schemas"]["applicationOutput"]["data"] |
|||
|
|||
export type Table = components["schemas"]["tableOutput"]["data"] |
|||
|
|||
export type Row = components["schemas"]["rowOutput"]["data"] |
|||
export type RowSearch = components["schemas"]["searchOutput"] |
|||
|
|||
export type User = components["schemas"]["userOutput"]["data"] |
|||
@ -0,0 +1,32 @@ |
|||
import { User } from "./types" |
|||
|
|||
function user(body: any): User { |
|||
return { |
|||
_id: body._id, |
|||
email: body.email, |
|||
password: body.password, |
|||
status: body.status, |
|||
firstName: body.firstName, |
|||
lastName: body.lastName, |
|||
forceResetPassword: body.forceResetPassword, |
|||
builder: body.builder, |
|||
admin: body.admin, |
|||
roles: body.roles, |
|||
} |
|||
} |
|||
|
|||
function mapUser(ctx: any): { data: User } { |
|||
return { |
|||
data: user(ctx.body), |
|||
} |
|||
} |
|||
|
|||
function mapUsers(ctx: any): { data: User[] } { |
|||
const users = ctx.body.map((body: any) => user(body)) |
|||
return { data: users } |
|||
} |
|||
|
|||
export default { |
|||
mapUser, |
|||
mapUsers, |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
import { search as stringSearch } from "./utils" |
|||
import { default as queryController } from "../query" |
|||
|
|||
export async function search(ctx: any, next: any) { |
|||
await queryController.fetch(ctx) |
|||
const { name } = ctx.request.body |
|||
ctx.body = stringSearch(ctx.body, name) |
|||
await next() |
|||
} |
|||
|
|||
export async function execute(ctx: any, next: any) { |
|||
// don't wrap this, already returns "data"
|
|||
await queryController.executeV2(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export default { |
|||
search, |
|||
execute, |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
import { default as rowController } from "../row" |
|||
import { addRev } from "./utils" |
|||
import { Row } from "../../../definitions/common" |
|||
|
|||
// makes sure that the user doesn't need to pass in the type, tableId or _id params for
|
|||
// the call to be correct
|
|||
function fixRow(row: Row, params: any) { |
|||
if (!params || !row) { |
|||
return row |
|||
} |
|||
if (params.rowId) { |
|||
row._id = params.rowId |
|||
} |
|||
if (params.tableId) { |
|||
row.tableId = params.tableId |
|||
} |
|||
if (!row.type) { |
|||
row.type = "row" |
|||
} |
|||
return row |
|||
} |
|||
|
|||
export async function search(ctx: any, next: any) { |
|||
let { sort, paginate, bookmark, limit, query } = ctx.request.body |
|||
// update the body to the correct format of the internal search
|
|||
if (!sort) { |
|||
sort = {} |
|||
} |
|||
ctx.request.body = { |
|||
sort: sort.column, |
|||
sortType: sort.type, |
|||
sortOrder: sort.order, |
|||
bookmark, |
|||
paginate, |
|||
limit, |
|||
query, |
|||
} |
|||
await rowController.search(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function create(ctx: any, next: any) { |
|||
ctx.request.body = fixRow(ctx.request.body, ctx.params) |
|||
await rowController.save(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function read(ctx: any, next: any) { |
|||
await rowController.fetchEnrichedRow(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function update(ctx: any, next: any) { |
|||
ctx.request.body = await addRev(fixRow(ctx.request.body, ctx.params.tableId)) |
|||
await rowController.save(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function destroy(ctx: any, next: any) { |
|||
// set the body as expected, with the _id and _rev fields
|
|||
ctx.request.body = await addRev( |
|||
fixRow({ _id: ctx.params.rowId }, ctx.params.tableId) |
|||
) |
|||
await rowController.destroy(ctx) |
|||
// destroy controller doesn't currently return the row as the body, need to adjust this
|
|||
// in the public API to be correct
|
|||
ctx.body = ctx.row |
|||
await next() |
|||
} |
|||
|
|||
export default { |
|||
create, |
|||
read, |
|||
update, |
|||
destroy, |
|||
search, |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
import { search as stringSearch, addRev } from "./utils" |
|||
import { default as controller } from "../table" |
|||
import { Table } from "../../../definitions/common" |
|||
|
|||
function fixTable(table: Table, params: any) { |
|||
if (!params || !table) { |
|||
return table |
|||
} |
|||
if (params.tableId) { |
|||
table._id = params.tableId |
|||
} |
|||
if (!table.type) { |
|||
table.type = "table" |
|||
} |
|||
return table |
|||
} |
|||
|
|||
export async function search(ctx: any, next: any) { |
|||
const { name } = ctx.request.body |
|||
await controller.fetch(ctx) |
|||
ctx.body = stringSearch(ctx.body, name) |
|||
await next() |
|||
} |
|||
|
|||
export async function create(ctx: any, next: any) { |
|||
await controller.save(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function read(ctx: any, next: any) { |
|||
await controller.find(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function update(ctx: any, next: any) { |
|||
ctx.request.body = await addRev( |
|||
fixTable(ctx.request.body, ctx.params), |
|||
ctx.params.tableId |
|||
) |
|||
await controller.save(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function destroy(ctx: any, next: any) { |
|||
await controller.destroy(ctx) |
|||
ctx.body = ctx.table |
|||
await next() |
|||
} |
|||
|
|||
export default { |
|||
create, |
|||
read, |
|||
update, |
|||
destroy, |
|||
search, |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
import { |
|||
allGlobalUsers, |
|||
deleteGlobalUser, |
|||
readGlobalUser, |
|||
saveGlobalUser, |
|||
} from "../../../utilities/workerRequests" |
|||
import { search as stringSearch } from "./utils" |
|||
|
|||
const { getProdAppID } = require("@budibase/backend-core/db") |
|||
|
|||
function fixUser(ctx: any) { |
|||
if (!ctx.request.body) { |
|||
return ctx |
|||
} |
|||
if (!ctx.request.body._id && ctx.params.userId) { |
|||
ctx.request.body._id = ctx.params.userId |
|||
} |
|||
if (!ctx.request.body.roles) { |
|||
ctx.request.body.roles = {} |
|||
} else { |
|||
const newRoles: { [key: string]: string } = {} |
|||
for (let [appId, role] of Object.entries(ctx.request.body.roles)) { |
|||
// @ts-ignore
|
|||
newRoles[getProdAppID(appId)] = role |
|||
} |
|||
ctx.request.body.roles = newRoles |
|||
} |
|||
return ctx |
|||
} |
|||
|
|||
function getUser(ctx: any, userId?: string) { |
|||
if (userId) { |
|||
ctx.params = { userId } |
|||
} else if (!ctx.params?.userId) { |
|||
throw "No user ID provided for getting" |
|||
} |
|||
return readGlobalUser(ctx) |
|||
} |
|||
|
|||
export async function search(ctx: any, next: any) { |
|||
const { name } = ctx.request.body |
|||
const users = await allGlobalUsers(ctx) |
|||
ctx.body = stringSearch(users, name, "email") |
|||
await next() |
|||
} |
|||
|
|||
export async function create(ctx: any, next: any) { |
|||
const response = await saveGlobalUser(fixUser(ctx)) |
|||
ctx.body = await getUser(ctx, response._id) |
|||
await next() |
|||
} |
|||
|
|||
export async function read(ctx: any, next: any) { |
|||
ctx.body = await readGlobalUser(ctx) |
|||
await next() |
|||
} |
|||
|
|||
export async function update(ctx: any, next: any) { |
|||
const user = await readGlobalUser(ctx) |
|||
ctx.request.body = { |
|||
...ctx.request.body, |
|||
_rev: user._rev, |
|||
} |
|||
const response = await saveGlobalUser(fixUser(ctx)) |
|||
ctx.body = await getUser(ctx, response._id) |
|||
await next() |
|||
} |
|||
|
|||
export async function destroy(ctx: any, next: any) { |
|||
const user = await getUser(ctx) |
|||
await deleteGlobalUser(ctx) |
|||
ctx.body = user |
|||
await next() |
|||
} |
|||
|
|||
export default { |
|||
create, |
|||
read, |
|||
update, |
|||
destroy, |
|||
search, |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
const { getAppDB } = require("@budibase/backend-core/context") |
|||
import { isExternalTable } from "../../../integrations/utils" |
|||
|
|||
export async function addRev( |
|||
body: { _id?: string; _rev?: string }, |
|||
tableId?: string |
|||
) { |
|||
if (!body._id || (tableId && isExternalTable(tableId))) { |
|||
return body |
|||
} |
|||
const db = getAppDB() |
|||
const dbDoc = await db.get(body._id) |
|||
body._rev = dbDoc._rev |
|||
return body |
|||
} |
|||
|
|||
/** |
|||
* Performs a case insensitive search on the provided documents, using the |
|||
* provided key and value. This will be a string based search, using the |
|||
* startsWith function. |
|||
*/ |
|||
export function search(docs: any[], value: any, key = "name") { |
|||
if (!value || typeof value !== "string") { |
|||
return docs |
|||
} |
|||
value = value.toLowerCase() |
|||
const filtered = [] |
|||
for (let doc of docs) { |
|||
if (typeof doc[key] !== "string") { |
|||
continue |
|||
} |
|||
const toTest = doc[key].toLowerCase() |
|||
if (toTest.startsWith(value)) { |
|||
filtered.push(doc) |
|||
} |
|||
} |
|||
return filtered |
|||
} |
|||
@ -0,0 +1,156 @@ |
|||
import controller from "../../controllers/public/applications" |
|||
import Endpoint from "./utils/Endpoint" |
|||
const { nameValidator, applicationValidator } = require("../utils/validators") |
|||
|
|||
const read = [], |
|||
write = [] |
|||
|
|||
/** |
|||
* @openapi |
|||
* /applications: |
|||
* post: |
|||
* summary: Create an application |
|||
* tags: |
|||
* - applications |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/application' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the created application. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/applicationOutput' |
|||
* examples: |
|||
* application: |
|||
* $ref: '#/components/examples/application' |
|||
*/ |
|||
write.push( |
|||
new Endpoint("post", "/applications", controller.create).addMiddleware( |
|||
applicationValidator() |
|||
) |
|||
) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /applications/{appId}: |
|||
* put: |
|||
* summary: Update an application |
|||
* tags: |
|||
* - applications |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/appIdUrl' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/application' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the updated application. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/applicationOutput' |
|||
* examples: |
|||
* application: |
|||
* $ref: '#/components/examples/application' |
|||
*/ |
|||
write.push( |
|||
new Endpoint("put", "/applications/:appId", controller.update).addMiddleware( |
|||
applicationValidator() |
|||
) |
|||
) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /applications/{appId}: |
|||
* delete: |
|||
* summary: Delete an application |
|||
* tags: |
|||
* - applications |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/appIdUrl' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the deleted application. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/applicationOutput' |
|||
* examples: |
|||
* application: |
|||
* $ref: '#/components/examples/application' |
|||
*/ |
|||
write.push(new Endpoint("delete", "/applications/:appId", controller.destroy)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /applications/{appId}: |
|||
* get: |
|||
* summary: Retrieve an application |
|||
* tags: |
|||
* - applications |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/appIdUrl' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the retrieved application. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/applicationOutput' |
|||
* examples: |
|||
* application: |
|||
* $ref: '#/components/examples/application' |
|||
*/ |
|||
read.push(new Endpoint("get", "/applications/:appId", controller.read)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /applications/search: |
|||
* post: |
|||
* summary: Search for applications |
|||
* description: Based on application properties (currently only name) search for applications. |
|||
* tags: |
|||
* - applications |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/nameSearch' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the applications that were found based on the search parameters. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* type: object |
|||
* required: |
|||
* - data |
|||
* properties: |
|||
* data: |
|||
* type: array |
|||
* items: |
|||
* $ref: '#/components/schemas/application' |
|||
* examples: |
|||
* applications: |
|||
* $ref: '#/components/examples/applications' |
|||
*/ |
|||
read.push( |
|||
new Endpoint("post", "/applications/search", controller.search).addMiddleware( |
|||
nameValidator() |
|||
) |
|||
) |
|||
|
|||
export default { read, write } |
|||
@ -0,0 +1,82 @@ |
|||
import appEndpoints from "./applications" |
|||
import queryEndpoints from "./queries" |
|||
import tableEndpoints from "./tables" |
|||
import rowEndpoints from "./rows" |
|||
import userEndpoints from "./users" |
|||
import usage from "../../../middleware/usageQuota" |
|||
import authorized from "../../../middleware/authorized" |
|||
import { paramResource, paramSubResource } from "../../../middleware/resourceId" |
|||
import { CtxFn } from "./utils/Endpoint" |
|||
import mapperMiddleware from "./middleware/mapper" |
|||
const Router = require("@koa/router") |
|||
const { |
|||
PermissionLevels, |
|||
PermissionTypes, |
|||
} = require("@budibase/backend-core/permissions") |
|||
|
|||
const PREFIX = "/api/public/v1" |
|||
|
|||
const publicRouter = new Router({ |
|||
prefix: PREFIX, |
|||
}) |
|||
|
|||
function addMiddleware( |
|||
endpoints: any, |
|||
middleware: CtxFn, |
|||
opts: { output: boolean } = { output: false } |
|||
) { |
|||
if (!endpoints) { |
|||
return |
|||
} |
|||
if (!Array.isArray(endpoints)) { |
|||
endpoints = [endpoints] |
|||
} |
|||
for (let endpoint of endpoints) { |
|||
if (opts?.output) { |
|||
endpoint.addOutputMiddleware(middleware) |
|||
} else { |
|||
endpoint.addMiddleware(middleware) |
|||
} |
|||
} |
|||
} |
|||
|
|||
function addToRouter(endpoints: any) { |
|||
if (endpoints) { |
|||
for (let endpoint of endpoints) { |
|||
endpoint.apply(publicRouter) |
|||
} |
|||
} |
|||
} |
|||
|
|||
function applyRoutes( |
|||
endpoints: any, |
|||
permType: string, |
|||
resource: string, |
|||
subResource?: string |
|||
) { |
|||
const paramMiddleware = subResource |
|||
? paramSubResource(resource, subResource) |
|||
: paramResource(resource) |
|||
// add the parameter capture middleware
|
|||
addMiddleware(endpoints.read, paramMiddleware) |
|||
addMiddleware(endpoints.write, paramMiddleware) |
|||
// add the authorization middleware, using the correct perm type
|
|||
addMiddleware(endpoints.read, authorized(permType, PermissionLevels.READ)) |
|||
addMiddleware(endpoints.write, authorized(permType, PermissionLevels.WRITE)) |
|||
// add the usage quota middleware
|
|||
addMiddleware(endpoints.write, usage) |
|||
// add the output mapper middleware
|
|||
addMiddleware(endpoints.read, mapperMiddleware, { output: true }) |
|||
addMiddleware(endpoints.write, mapperMiddleware, { output: true }) |
|||
addToRouter(endpoints.read) |
|||
addToRouter(endpoints.write) |
|||
} |
|||
|
|||
applyRoutes(appEndpoints, PermissionTypes.APP, "appId") |
|||
applyRoutes(tableEndpoints, PermissionTypes.TABLE, "tableId") |
|||
applyRoutes(userEndpoints, PermissionTypes.USER, "userId") |
|||
applyRoutes(queryEndpoints, PermissionTypes.QUERY, "queryId") |
|||
// needs to be applied last for routing purposes, don't override other endpoints
|
|||
applyRoutes(rowEndpoints, PermissionTypes.TABLE, "tableId", "rowId") |
|||
|
|||
module.exports = publicRouter |
|||
@ -0,0 +1,81 @@ |
|||
import mapping from "../../../controllers/public/mapping" |
|||
|
|||
enum Resources { |
|||
APPLICATION = "applications", |
|||
TABLES = "tables", |
|||
ROWS = "rows", |
|||
USERS = "users", |
|||
QUERIES = "queries", |
|||
SEARCH = "search", |
|||
} |
|||
|
|||
function isArrayResponse(ctx: any) { |
|||
return ctx.url.endsWith(Resources.SEARCH) || Array.isArray(ctx.body) |
|||
} |
|||
|
|||
function processApplications(ctx: any) { |
|||
if (isArrayResponse(ctx)) { |
|||
return mapping.mapApplications(ctx) |
|||
} else { |
|||
return mapping.mapApplication(ctx) |
|||
} |
|||
} |
|||
|
|||
function processTables(ctx: any) { |
|||
if (isArrayResponse(ctx)) { |
|||
return mapping.mapTables(ctx) |
|||
} else { |
|||
return mapping.mapTable(ctx) |
|||
} |
|||
} |
|||
|
|||
function processRows(ctx: any) { |
|||
if (isArrayResponse(ctx)) { |
|||
return mapping.mapRowSearch(ctx) |
|||
} else { |
|||
return mapping.mapRow(ctx) |
|||
} |
|||
} |
|||
|
|||
function processUsers(ctx: any) { |
|||
if (isArrayResponse(ctx)) { |
|||
return mapping.mapUsers(ctx) |
|||
} else { |
|||
return mapping.mapUser(ctx) |
|||
} |
|||
} |
|||
|
|||
function processQueries(ctx: any) { |
|||
if (isArrayResponse(ctx)) { |
|||
return mapping.mapQueries(ctx) |
|||
} else { |
|||
return mapping.mapQueryExecution(ctx) |
|||
} |
|||
} |
|||
|
|||
export default async (ctx: any, next: any) => { |
|||
let urlParts = ctx.url.split("/") |
|||
urlParts = urlParts.slice(4, urlParts.length) |
|||
let body = {} |
|||
switch (urlParts[0]) { |
|||
case Resources.APPLICATION: |
|||
body = processApplications(ctx) |
|||
break |
|||
case Resources.TABLES: |
|||
if (urlParts[2] === Resources.ROWS) { |
|||
body = processRows(ctx) |
|||
} else { |
|||
body = processTables(ctx) |
|||
} |
|||
break |
|||
case Resources.USERS: |
|||
body = processUsers(ctx) |
|||
break |
|||
case Resources.QUERIES: |
|||
body = processQueries(ctx) |
|||
break |
|||
} |
|||
// update the body based on what has occurred in the mapper
|
|||
ctx.body = body |
|||
await next() |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
import controller from "../../controllers/public/queries" |
|||
import Endpoint from "./utils/Endpoint" |
|||
import { nameValidator } from "../utils/validators" |
|||
|
|||
const read = [], |
|||
write = [] |
|||
|
|||
/** |
|||
* @openapi |
|||
* /queries/{queryId}: |
|||
* post: |
|||
* summary: Execute a query |
|||
* description: Queries which have been created within a Budibase app can be executed using this, |
|||
* tags: |
|||
* - queries |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/queryId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/executeQuery' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the result of the query execution. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/executeQueryOutput' |
|||
* examples: |
|||
* REST: |
|||
* $ref: '#/components/examples/restResponse' |
|||
* SQL: |
|||
* $ref: '#/components/examples/sqlResponse' |
|||
* |
|||
*/ |
|||
write.push(new Endpoint("post", "/queries/:queryId", controller.execute)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /queries/search: |
|||
* post: |
|||
* summary: Search for queries |
|||
* description: Based on query properties (currently only name) search for queries. |
|||
* tags: |
|||
* - queries |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/nameSearch' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the queries found based on the search parameters. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* type: object |
|||
* required: |
|||
* - data |
|||
* properties: |
|||
* data: |
|||
* type: array |
|||
* items: |
|||
* $ref: '#/components/schemas/query' |
|||
* examples: |
|||
* queries: |
|||
* $ref: '#/components/examples/queries' |
|||
*/ |
|||
read.push( |
|||
new Endpoint("post", "/queries/search", controller.search).addMiddleware( |
|||
nameValidator() |
|||
) |
|||
) |
|||
|
|||
export default { read, write } |
|||
@ -0,0 +1,242 @@ |
|||
import controller from "../../controllers/public/rows" |
|||
import Endpoint from "./utils/Endpoint" |
|||
import { externalSearchValidator } from "../utils/validators" |
|||
|
|||
const read = [], |
|||
write = [] |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/{tableId}/rows: |
|||
* post: |
|||
* summary: Create a row |
|||
* description: Creates a row within the specified table. |
|||
* tags: |
|||
* - rows |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/tableId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/row' |
|||
* examples: |
|||
* row: |
|||
* $ref: '#/components/examples/inputRow' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the created row, including the ID which has been generated for it. |
|||
* This can be found in the Budibase portal, viewed under the developer information. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/rowOutput' |
|||
* examples: |
|||
* row: |
|||
* $ref: '#/components/examples/row' |
|||
*/ |
|||
write.push(new Endpoint("post", "/tables/:tableId/rows", controller.create)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/{tableId}/rows/{rowId}: |
|||
* put: |
|||
* summary: Update a row |
|||
* description: Updates a row within the specified table. |
|||
* tags: |
|||
* - rows |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/tableId' |
|||
* - $ref: '#/components/parameters/rowId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/row' |
|||
* examples: |
|||
* row: |
|||
* $ref: '#/components/examples/inputRow' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the created row, including the ID which has been generated for it. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/rowOutput' |
|||
* examples: |
|||
* row: |
|||
* $ref: '#/components/examples/row' |
|||
*/ |
|||
write.push( |
|||
new Endpoint("put", "/tables/:tableId/rows/:rowId", controller.update) |
|||
) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/{tableId}/rows/{rowId}: |
|||
* delete: |
|||
* summary: Delete a row |
|||
* description: Deletes a row within the specified table. |
|||
* tags: |
|||
* - rows |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/tableId' |
|||
* - $ref: '#/components/parameters/rowId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the deleted row, including the ID which has been generated for it. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/rowOutput' |
|||
* examples: |
|||
* row: |
|||
* $ref: '#/components/examples/row' |
|||
*/ |
|||
write.push( |
|||
new Endpoint("delete", "/tables/:tableId/rows/:rowId", controller.destroy) |
|||
) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/{tableId}/rows/{rowId}: |
|||
* get: |
|||
* summary: Retrieve a row |
|||
* description: This gets a single row, it will be enriched with the full related rows, rather than |
|||
* the squashed "primaryDisplay" format returned by the search endpoint. |
|||
* tags: |
|||
* - rows |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/tableId' |
|||
* - $ref: '#/components/parameters/rowId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the retrieved row. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/rowOutput' |
|||
* examples: |
|||
* enrichedRow: |
|||
* $ref: '#/components/examples/enrichedRow' |
|||
*/ |
|||
read.push(new Endpoint("get", "/tables/:tableId/rows/:rowId", controller.read)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/{tableId}/rows/search: |
|||
* post: |
|||
* summary: Search for rows |
|||
* tags: |
|||
* - rows |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/tableId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* type: object |
|||
* required: |
|||
* - query |
|||
* properties: |
|||
* query: |
|||
* type: object |
|||
* properties: |
|||
* string: |
|||
* type: object |
|||
* example: |
|||
* columnName1: value |
|||
* columnName2: value |
|||
* description: A map of field name to the string to search for, |
|||
* this will look for rows that have a value starting with the |
|||
* string value. |
|||
* additionalProperties: |
|||
* type: string |
|||
* description: The value to search for in the column. |
|||
* fuzzy: |
|||
* type: object |
|||
* description: A fuzzy search, only supported by internal tables. |
|||
* range: |
|||
* type: object |
|||
* description: Searches within a range, the format of this must be |
|||
* columnName -> [low, high]. |
|||
* example: |
|||
* columnName1: [10, 20] |
|||
* equal: |
|||
* type: object |
|||
* description: Searches for rows that have a column value that is |
|||
* exactly the value set. |
|||
* notEqual: |
|||
* type: object |
|||
* description: Searches for any row which does not contain the specified |
|||
* column value. |
|||
* empty: |
|||
* type: object |
|||
* description: Searches for rows which do not contain the specified column. |
|||
* The object should simply contain keys of the column names, these |
|||
* can map to any value. |
|||
* example: |
|||
* columnName1: "" |
|||
* notEmpty: |
|||
* type: object |
|||
* description: Searches for rows which have the specified column. |
|||
* oneOf: |
|||
* type: object |
|||
* description: Searches for rows which have a column value that is any |
|||
* of the specified values. The format of this must be columnName -> [value1, value2]. |
|||
* paginate: |
|||
* type: boolean |
|||
* description: Enables pagination, by default this is disabled. |
|||
* bookmark: |
|||
* oneOf: |
|||
* - type: string |
|||
* - type: integer |
|||
* description: If retrieving another page, the bookmark from the previous request must be supplied. |
|||
* limit: |
|||
* type: integer |
|||
* description: The maximum number of rows to return, useful when paginating, for internal tables this |
|||
* will be limited to 1000, for SQL tables it will be 5000. |
|||
* sort: |
|||
* type: object |
|||
* description: A set of parameters describing the sort behaviour of the search. |
|||
* properties: |
|||
* order: |
|||
* type: string |
|||
* enum: [ascending, descending] |
|||
* description: The order of the sort, by default this is ascending. |
|||
* column: |
|||
* type: string |
|||
* description: The name of the column by which the rows will be sorted. |
|||
* type: |
|||
* type: string |
|||
* enum: [string, number] |
|||
* description: Defines whether the column should be treated as a string |
|||
* or as numbers when sorting. |
|||
* responses: |
|||
* 200: |
|||
* description: The response will contain an array of rows that match the search parameters. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/searchOutput' |
|||
* examples: |
|||
* search: |
|||
* $ref: '#/components/examples/rows' |
|||
*/ |
|||
read.push( |
|||
new Endpoint( |
|||
"post", |
|||
"/tables/:tableId/rows/search", |
|||
controller.search |
|||
).addMiddleware(externalSearchValidator()) |
|||
) |
|||
|
|||
export default { read, write } |
|||
@ -0,0 +1,169 @@ |
|||
import controller from "../../controllers/public/tables" |
|||
import Endpoint from "./utils/Endpoint" |
|||
import { tableValidator, nameValidator } from "../utils/validators" |
|||
|
|||
const read = [], |
|||
write = [] |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables: |
|||
* post: |
|||
* summary: Create a table |
|||
* description: Create a table, this could be internal or external. |
|||
* tags: |
|||
* - tables |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/table' |
|||
* examples: |
|||
* table: |
|||
* $ref: '#/components/examples/table' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the created table, including the ID which has been generated for it. This can be |
|||
* internal or external data sources. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/tableOutput' |
|||
* examples: |
|||
* table: |
|||
* $ref: '#/components/examples/table' |
|||
*/ |
|||
write.push( |
|||
new Endpoint("post", "/tables", controller.create).addMiddleware( |
|||
tableValidator() |
|||
) |
|||
) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/{tableId}: |
|||
* put: |
|||
* summary: Update a table |
|||
* description: Update a table, this could be internal or external. |
|||
* tags: |
|||
* - tables |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/tableId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/table' |
|||
* examples: |
|||
* table: |
|||
* $ref: '#/components/examples/table' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the updated table. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/tableOutput' |
|||
* examples: |
|||
* table: |
|||
* $ref: '#/components/examples/table' |
|||
*/ |
|||
write.push( |
|||
new Endpoint("put", "/tables/:tableId", controller.update).addMiddleware( |
|||
tableValidator() |
|||
) |
|||
) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/{tableId}: |
|||
* delete: |
|||
* summary: Delete a table |
|||
* description: Delete a table, this could be internal or external. |
|||
* tags: |
|||
* - tables |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/tableId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the deleted table. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/tableOutput' |
|||
* examples: |
|||
* table: |
|||
* $ref: '#/components/examples/table' |
|||
*/ |
|||
write.push(new Endpoint("delete", "/tables/:tableId", controller.destroy)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/{tableId}: |
|||
* get: |
|||
* summary: Retrieve a table |
|||
* description: Lookup a table, this could be internal or external. |
|||
* tags: |
|||
* - tables |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/tableId' |
|||
* - $ref: '#/components/parameters/appId' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the retrieved table. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/tableOutput' |
|||
* examples: |
|||
* table: |
|||
* $ref: '#/components/examples/table' |
|||
*/ |
|||
read.push(new Endpoint("get", "/tables/:tableId", controller.read)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /tables/search: |
|||
* post: |
|||
* summary: Search for tables |
|||
* description: Based on table properties (currently only name) search for tables. This could be |
|||
* an internal or an external table. |
|||
* tags: |
|||
* - tables |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/appId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/nameSearch' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the found tables, based on the search parameters. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* type: object |
|||
* required: |
|||
* - data |
|||
* properties: |
|||
* data: |
|||
* type: array |
|||
* items: |
|||
* $ref: '#/components/schemas/table' |
|||
* examples: |
|||
* tables: |
|||
* $ref: '#/components/examples/tables' |
|||
*/ |
|||
read.push( |
|||
new Endpoint("post", "/tables/search", controller.search).addMiddleware( |
|||
nameValidator() |
|||
) |
|||
) |
|||
|
|||
export default { read, write } |
|||
@ -0,0 +1,184 @@ |
|||
const jestOpenAPI = require("jest-openapi").default |
|||
const generateSchema = require("../../../../../specs/generate") |
|||
const setup = require("../../tests/utilities") |
|||
const { checkSlashesInUrl } = require("../../../../utilities") |
|||
|
|||
const yamlPath = generateSchema() |
|||
jestOpenAPI(yamlPath) |
|||
|
|||
let request = setup.getRequest() |
|||
let config = setup.getConfig() |
|||
let apiKey, table, app |
|||
|
|||
beforeAll(async () => { |
|||
app = await config.init() |
|||
table = await config.updateTable() |
|||
apiKey = await config.generateApiKey() |
|||
}) |
|||
|
|||
afterAll(setup.afterAll) |
|||
|
|||
async function makeRequest(method, endpoint, body, appId = config.getAppId()) { |
|||
const extraHeaders = { |
|||
"x-budibase-api-key": apiKey, |
|||
} |
|||
if (appId) { |
|||
extraHeaders["x-budibase-app-id"] = appId |
|||
} |
|||
const req = request |
|||
[method](checkSlashesInUrl(`/api/public/v1/${endpoint}`)) |
|||
.set(config.defaultHeaders(extraHeaders)) |
|||
if (body) { |
|||
req.send(body) |
|||
} |
|||
const res = await req.expect("Content-Type", /json/).expect(200) |
|||
expect(res.body).toBeDefined() |
|||
return res |
|||
} |
|||
|
|||
describe("check the applications endpoints", () => { |
|||
it("should allow retrieving applications through search", async () => { |
|||
const res = await makeRequest("post", "/applications/search") |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow creating an application", async () => { |
|||
const res = await makeRequest("post", "/applications", { |
|||
name: "new App" |
|||
}, null) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow updating an application", async () => { |
|||
const app = config.getApp() |
|||
const appId = config.getAppId() |
|||
const res = await makeRequest("put", `/applications/${appId}`, { |
|||
...app, |
|||
name: "updated app name", |
|||
}, appId) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow retrieving an application", async () => { |
|||
const res = await makeRequest("get", `/applications/${config.getAppId()}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow deleting an application", async () => { |
|||
const res = await makeRequest("delete", `/applications/${config.getAppId()}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
}) |
|||
|
|||
describe("check the tables endpoints", () => { |
|||
it("should allow retrieving tables through search", async () => { |
|||
await config.createApp("new app 1") |
|||
table = await config.updateTable() |
|||
const res = await makeRequest("post", "/tables/search") |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow creating a table", async () => { |
|||
const res = await makeRequest("post", "/tables", { |
|||
name: "table name", |
|||
primaryDisplay: "column1", |
|||
schema: { |
|||
column1: { |
|||
type: "string", |
|||
constraints: {}, |
|||
} |
|||
} |
|||
}) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow updating a table", async () => { |
|||
const updated = { ...table, _rev: undefined, name: "new name" } |
|||
const res = await makeRequest("put", `/tables/${table._id}`, updated) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow retrieving a table", async () => { |
|||
const res = await makeRequest("get", `/tables/${table._id}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow deleting a table", async () => { |
|||
const res = await makeRequest("delete", `/tables/${table._id}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
}) |
|||
|
|||
describe("check the rows endpoints", () => { |
|||
let row |
|||
it("should allow retrieving rows through search", async () => { |
|||
table = await config.updateTable() |
|||
const res = await makeRequest("post", `/tables/${table._id}/rows/search`, { |
|||
query: { |
|||
}, |
|||
}) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow creating a row", async () => { |
|||
const res = await makeRequest("post", `/tables/${table._id}/rows`, { |
|||
name: "test row", |
|||
}) |
|||
expect(res).toSatisfyApiSpec() |
|||
row = res.body.data |
|||
}) |
|||
|
|||
it("should allow updating a row", async () => { |
|||
const res = await makeRequest("put", `/tables/${table._id}/rows/${row._id}`, { |
|||
name: "test row updated", |
|||
}) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow retrieving a row", async () => { |
|||
const res = await makeRequest("get", `/tables/${table._id}/rows/${row._id}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow deleting a row", async () => { |
|||
const res = await makeRequest("delete", `/tables/${table._id}/rows/${row._id}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
}) |
|||
|
|||
describe("check the users endpoints", () => { |
|||
let user |
|||
it("should allow retrieving users through search", async () => { |
|||
user = await config.createUser() |
|||
const res = await makeRequest("post", "/users/search") |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow creating a user", async () => { |
|||
const res = await makeRequest("post", "/users") |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow updating a user", async () => { |
|||
const res = await makeRequest("put", `/users/${user._id}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow retrieving a user", async () => { |
|||
const res = await makeRequest("get", `/users/${user._id}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
|
|||
it("should allow deleting a user", async () => { |
|||
const res = await makeRequest("delete", `/users/${user._id}`) |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
}) |
|||
|
|||
describe("check the queries endpoints", () => { |
|||
it("should allow retrieving queries through search", async () => { |
|||
const res = await makeRequest("post", "/queries/search") |
|||
expect(res).toSatisfyApiSpec() |
|||
}) |
|||
}) |
|||
|
|||
@ -0,0 +1,144 @@ |
|||
import controller from "../../controllers/public/users" |
|||
import Endpoint from "./utils/Endpoint" |
|||
import { nameValidator } from "../utils/validators" |
|||
|
|||
const read = [], |
|||
write = [] |
|||
|
|||
/** |
|||
* @openapi |
|||
* /users: |
|||
* post: |
|||
* summary: Create a user |
|||
* tags: |
|||
* - users |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/user' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the created user. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/userOutput' |
|||
* examples: |
|||
* user: |
|||
* $ref: '#/components/examples/user' |
|||
*/ |
|||
write.push(new Endpoint("post", "/users", controller.create)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /users/{userId}: |
|||
* put: |
|||
* summary: Update a user |
|||
* tags: |
|||
* - users |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/userId' |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/user' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the updated user. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/userOutput' |
|||
* examples: |
|||
* user: |
|||
* $ref: '#/components/examples/user' |
|||
*/ |
|||
write.push(new Endpoint("put", "/users/:userId", controller.update)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /users/{userId}: |
|||
* delete: |
|||
* summary: Delete a user |
|||
* tags: |
|||
* - users |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/userId' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the deleted user. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/userOutput' |
|||
* examples: |
|||
* user: |
|||
* $ref: '#/components/examples/user' |
|||
*/ |
|||
write.push(new Endpoint("delete", "/users/:userId", controller.destroy)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /users/{userId}: |
|||
* get: |
|||
* summary: Retrieve a user |
|||
* tags: |
|||
* - users |
|||
* parameters: |
|||
* - $ref: '#/components/parameters/userId' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the retrieved user. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/userOutput' |
|||
* examples: |
|||
* user: |
|||
* $ref: '#/components/examples/user' |
|||
*/ |
|||
read.push(new Endpoint("get", "/users/:userId", controller.read)) |
|||
|
|||
/** |
|||
* @openapi |
|||
* /users/search: |
|||
* post: |
|||
* summary: Search for users |
|||
* description: Based on user properties (currently only name) search for users. |
|||
* tags: |
|||
* - users |
|||
* requestBody: |
|||
* required: true |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* $ref: '#/components/schemas/nameSearch' |
|||
* responses: |
|||
* 200: |
|||
* description: Returns the found users based on search parameters. |
|||
* content: |
|||
* application/json: |
|||
* schema: |
|||
* type: object |
|||
* required: |
|||
* - data |
|||
* properties: |
|||
* data: |
|||
* type: array |
|||
* items: |
|||
* $ref: '#/components/schemas/user' |
|||
* examples: |
|||
* users: |
|||
* $ref: '#/components/examples/users' |
|||
*/ |
|||
read.push( |
|||
new Endpoint("post", "/users/search", controller.search).addMiddleware( |
|||
nameValidator() |
|||
) |
|||
) |
|||
|
|||
export default { read, write } |
|||
@ -0,0 +1,51 @@ |
|||
import Router from "koa-router" |
|||
|
|||
export type CtxFn = (ctx: any, next?: any) => void | Promise<any> |
|||
|
|||
class Endpoint { |
|||
method: string |
|||
url: string |
|||
controller: CtxFn |
|||
middlewares: CtxFn[] |
|||
outputMiddlewares: CtxFn[] |
|||
|
|||
constructor(method: string, url: string, controller: CtxFn) { |
|||
this.method = method |
|||
this.url = url |
|||
this.controller = controller |
|||
this.middlewares = [] |
|||
this.outputMiddlewares = [] |
|||
} |
|||
|
|||
addMiddleware(middleware: CtxFn) { |
|||
this.middlewares.push(middleware) |
|||
return this |
|||
} |
|||
|
|||
addOutputMiddleware(middleware: CtxFn) { |
|||
this.outputMiddlewares.push(middleware) |
|||
return this |
|||
} |
|||
|
|||
apply(router: Router) { |
|||
const method = this.method, |
|||
url = this.url |
|||
const middlewares = this.middlewares, |
|||
controller = this.controller, |
|||
outputMiddlewares = this.outputMiddlewares |
|||
// need a function to do nothing to stop the execution at the end
|
|||
// middlewares are circular so if they always keep calling next, it'll just keep looping
|
|||
const complete = () => {} |
|||
const params = [ |
|||
url, |
|||
...middlewares, |
|||
controller, |
|||
...outputMiddlewares, |
|||
complete, |
|||
] |
|||
// @ts-ignore
|
|||
router[method](...params) |
|||
} |
|||
} |
|||
|
|||
export default Endpoint |
|||
@ -0,0 +1,219 @@ |
|||
const joiValidator = require("../../../middleware/joi-validator") |
|||
const { DataSourceOperation } = require("../../../constants") |
|||
const { WebhookType } = require("../../../constants") |
|||
const { |
|||
BUILTIN_PERMISSION_IDS, |
|||
PermissionLevels, |
|||
} = require("@budibase/backend-core/permissions") |
|||
const Joi = require("joi") |
|||
|
|||
const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("") |
|||
const OPTIONAL_NUMBER = Joi.number().optional().allow(null) |
|||
|
|||
exports.tableValidator = () => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
_id: OPTIONAL_STRING, |
|||
_rev: OPTIONAL_STRING, |
|||
type: OPTIONAL_STRING.valid("table", "internal", "external"), |
|||
primaryDisplay: OPTIONAL_STRING, |
|||
schema: Joi.object().required(), |
|||
name: Joi.string().required(), |
|||
views: Joi.object(), |
|||
dataImport: Joi.object(), |
|||
}).unknown(true)) |
|||
} |
|||
|
|||
exports.nameValidator = () => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
name: OPTIONAL_STRING, |
|||
})) |
|||
} |
|||
|
|||
exports.datasourceValidator = () => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
_id: Joi.string(), |
|||
_rev: Joi.string(), |
|||
type: OPTIONAL_STRING.allow("datasource_plus"), |
|||
relationships: Joi.array().items(Joi.object({ |
|||
from: Joi.string().required(), |
|||
to: Joi.string().required(), |
|||
cardinality: Joi.valid("1:N", "1:1", "N:N").required() |
|||
})), |
|||
}).unknown(true)) |
|||
} |
|||
|
|||
function filterObject() { |
|||
// prettier-ignore
|
|||
return Joi.object({ |
|||
string: Joi.object().optional(), |
|||
fuzzy: Joi.object().optional(), |
|||
range: Joi.object().optional(), |
|||
equal: Joi.object().optional(), |
|||
notEqual: Joi.object().optional(), |
|||
empty: Joi.object().optional(), |
|||
notEmpty: Joi.object().optional(), |
|||
oneOf: Joi.object().optional(), |
|||
contains: Joi.object().optional(), |
|||
notContains: Joi.object().optional(), |
|||
}).unknown(true) |
|||
} |
|||
|
|||
exports.internalSearchValidator = () => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
tableId: OPTIONAL_STRING, |
|||
query: filterObject(), |
|||
limit: OPTIONAL_NUMBER, |
|||
sort: OPTIONAL_STRING, |
|||
sortOrder: OPTIONAL_STRING, |
|||
sortType: OPTIONAL_STRING, |
|||
paginate: Joi.boolean(), |
|||
bookmark: Joi.alternatives().try(OPTIONAL_STRING, OPTIONAL_NUMBER).optional(), |
|||
})) |
|||
} |
|||
|
|||
exports.externalSearchValidator = () => { |
|||
return joiValidator.body( |
|||
Joi.object({ |
|||
query: filterObject(), |
|||
paginate: Joi.boolean().optional(), |
|||
bookmark: Joi.alternatives() |
|||
.try(OPTIONAL_STRING, OPTIONAL_NUMBER) |
|||
.optional(), |
|||
limit: OPTIONAL_NUMBER, |
|||
sort: Joi.object({ |
|||
column: Joi.string(), |
|||
order: OPTIONAL_STRING.valid("ascending", "descending"), |
|||
type: OPTIONAL_STRING.valid("string", "number"), |
|||
}).optional(), |
|||
}) |
|||
) |
|||
} |
|||
|
|||
exports.datasourceQueryValidator = () => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
endpoint: Joi.object({ |
|||
datasourceId: Joi.string().required(), |
|||
operation: Joi.string().required().valid(...Object.values(DataSourceOperation)), |
|||
entityId: Joi.string().required(), |
|||
}).required(), |
|||
resource: Joi.object({ |
|||
fields: Joi.array().items(Joi.string()).optional(), |
|||
}).optional(), |
|||
body: Joi.object().optional(), |
|||
sort: Joi.object().optional(), |
|||
filters: filterObject().optional(), |
|||
paginate: Joi.object({ |
|||
page: Joi.string().alphanum().optional(), |
|||
limit: Joi.number().optional(), |
|||
}).optional(), |
|||
})) |
|||
} |
|||
|
|||
exports.webhookValidator = () => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
live: Joi.bool(), |
|||
_id: OPTIONAL_STRING, |
|||
_rev: OPTIONAL_STRING, |
|||
name: Joi.string().required(), |
|||
bodySchema: Joi.object().optional(), |
|||
action: Joi.object({ |
|||
type: Joi.string().required().valid(WebhookType.AUTOMATION), |
|||
target: Joi.string().required(), |
|||
}).required(), |
|||
}).unknown(true)) |
|||
} |
|||
|
|||
exports.roleValidator = () => { |
|||
const permLevelArray = Object.values(PermissionLevels) |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
_id: OPTIONAL_STRING, |
|||
_rev: OPTIONAL_STRING, |
|||
name: Joi.string().required(), |
|||
// this is the base permission ID (for now a built in)
|
|||
permissionId: Joi.string().valid(...Object.values(BUILTIN_PERMISSION_IDS)).required(), |
|||
permissions: Joi.object() |
|||
.pattern(/.*/, [Joi.string().valid(...permLevelArray)]) |
|||
.optional(), |
|||
inherits: OPTIONAL_STRING, |
|||
}).unknown(true)) |
|||
} |
|||
|
|||
exports.permissionValidator = () => { |
|||
const permLevelArray = Object.values(PermissionLevels) |
|||
// prettier-ignore
|
|||
return joiValidator.params(Joi.object({ |
|||
level: Joi.string().valid(...permLevelArray).required(), |
|||
resourceId: Joi.string(), |
|||
roleId: Joi.string(), |
|||
}).unknown(true)) |
|||
} |
|||
|
|||
exports.screenValidator = () => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
name: Joi.string().required(), |
|||
routing: Joi.object({ |
|||
route: Joi.string().required(), |
|||
roleId: Joi.string().required().allow(""), |
|||
}).required().unknown(true), |
|||
props: Joi.object({ |
|||
_id: Joi.string().required(), |
|||
_component: Joi.string().required(), |
|||
_children: Joi.array().required(), |
|||
_instanceName: Joi.string().required(), |
|||
_styles: Joi.object().required(), |
|||
type: OPTIONAL_STRING, |
|||
table: OPTIONAL_STRING, |
|||
layoutId: OPTIONAL_STRING, |
|||
}).required().unknown(true), |
|||
}).unknown(true)) |
|||
} |
|||
|
|||
function generateStepSchema(allowStepTypes) { |
|||
// prettier-ignore
|
|||
return Joi.object({ |
|||
stepId: Joi.string().required(), |
|||
id: Joi.string().required(), |
|||
description: Joi.string().required(), |
|||
name: Joi.string().required(), |
|||
tagline: Joi.string().required(), |
|||
icon: Joi.string().required(), |
|||
params: Joi.object(), |
|||
args: Joi.object(), |
|||
type: Joi.string().required().valid(...allowStepTypes), |
|||
}).unknown(true) |
|||
} |
|||
|
|||
exports.automationValidator = (existing = false) => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
_id: existing ? Joi.string().required() : OPTIONAL_STRING, |
|||
_rev: existing ? Joi.string().required() : OPTIONAL_STRING, |
|||
name: Joi.string().required(), |
|||
type: Joi.string().valid("automation").required(), |
|||
definition: Joi.object({ |
|||
steps: Joi.array().required().items(generateStepSchema(["ACTION", "LOGIC"])), |
|||
trigger: generateStepSchema(["TRIGGER"]).allow(null), |
|||
}).required().unknown(true), |
|||
}).unknown(true)) |
|||
} |
|||
|
|||
exports.applicationValidator = () => { |
|||
// prettier-ignore
|
|||
return joiValidator.body(Joi.object({ |
|||
_id: OPTIONAL_STRING, |
|||
_rev: OPTIONAL_STRING, |
|||
name: Joi.string().required(), |
|||
url: OPTIONAL_STRING, |
|||
template: Joi.object({ |
|||
templateString: OPTIONAL_STRING, |
|||
}).unknown(true), |
|||
}).unknown(true)) |
|||
} |
|||
@ -0,0 +1,943 @@ |
|||
/** |
|||
* This file was auto-generated by openapi-typescript. |
|||
* Do not make direct changes to the file. |
|||
*/ |
|||
|
|||
export interface paths { |
|||
"/applications": { |
|||
post: { |
|||
parameters: { |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the created application. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["applicationOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["application"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/applications/{appId}": { |
|||
get: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
appId: components["parameters"]["appIdUrl"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the retrieved application. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["applicationOutput"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
put: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
appId: components["parameters"]["appIdUrl"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the updated application. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["applicationOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["application"] |
|||
} |
|||
} |
|||
} |
|||
delete: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
appId: components["parameters"]["appIdUrl"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the deleted application. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["applicationOutput"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/applications/search": { |
|||
/** Based on application properties (currently only name) search for applications. */ |
|||
post: { |
|||
parameters: { |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the applications that were found based on the search parameters. */ |
|||
200: { |
|||
content: { |
|||
"application/json": { |
|||
data: components["schemas"]["application"][] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["nameSearch"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/queries/{queryId}": { |
|||
/** Queries which have been created within a Budibase app can be executed using this, */ |
|||
post: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the query which this request is targeting. */ |
|||
queryId: components["parameters"]["queryId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the result of the query execution. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["executeQueryOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["executeQuery"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/queries/search": { |
|||
/** Based on query properties (currently only name) search for queries. */ |
|||
post: { |
|||
parameters: { |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the queries found based on the search parameters. */ |
|||
200: { |
|||
content: { |
|||
"application/json": { |
|||
data: components["schemas"]["query"][] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["nameSearch"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/tables/{tableId}/rows": { |
|||
/** Creates a row within the specified table. */ |
|||
post: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the table which this request is targeting. */ |
|||
tableId: components["parameters"]["tableId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the created row, including the ID which has been generated for it. This can be found in the Budibase portal, viewed under the developer information. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["rowOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["row"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/tables/{tableId}/rows/{rowId}": { |
|||
/** This gets a single row, it will be enriched with the full related rows, rather than the squashed "primaryDisplay" format returned by the search endpoint. */ |
|||
get: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the table which this request is targeting. */ |
|||
tableId: components["parameters"]["tableId"] |
|||
/** The ID of the row which this request is targeting. */ |
|||
rowId: components["parameters"]["rowId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the retrieved row. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["rowOutput"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
/** Updates a row within the specified table. */ |
|||
put: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the table which this request is targeting. */ |
|||
tableId: components["parameters"]["tableId"] |
|||
/** The ID of the row which this request is targeting. */ |
|||
rowId: components["parameters"]["rowId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the created row, including the ID which has been generated for it. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["rowOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["row"] |
|||
} |
|||
} |
|||
} |
|||
/** Deletes a row within the specified table. */ |
|||
delete: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the table which this request is targeting. */ |
|||
tableId: components["parameters"]["tableId"] |
|||
/** The ID of the row which this request is targeting. */ |
|||
rowId: components["parameters"]["rowId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the deleted row, including the ID which has been generated for it. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["rowOutput"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/tables/{tableId}/rows/search": { |
|||
post: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the table which this request is targeting. */ |
|||
tableId: components["parameters"]["tableId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** The response will contain an array of rows that match the search parameters. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["searchOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": { |
|||
query: { |
|||
/** |
|||
* @description A map of field name to the string to search for, this will look for rows that have a value starting with the string value. |
|||
* @example [object Object] |
|||
*/ |
|||
string?: { [key: string]: string } |
|||
/** @description A fuzzy search, only supported by internal tables. */ |
|||
fuzzy?: { [key: string]: unknown } |
|||
/** |
|||
* @description Searches within a range, the format of this must be columnName -> [low, high]. |
|||
* @example [object Object] |
|||
*/ |
|||
range?: { [key: string]: unknown } |
|||
/** @description Searches for rows that have a column value that is exactly the value set. */ |
|||
equal?: { [key: string]: unknown } |
|||
/** @description Searches for any row which does not contain the specified column value. */ |
|||
notEqual?: { [key: string]: unknown } |
|||
/** |
|||
* @description Searches for rows which do not contain the specified column. The object should simply contain keys of the column names, these can map to any value. |
|||
* @example [object Object] |
|||
*/ |
|||
empty?: { [key: string]: unknown } |
|||
/** @description Searches for rows which have the specified column. */ |
|||
notEmpty?: { [key: string]: unknown } |
|||
/** @description Searches for rows which have a column value that is any of the specified values. The format of this must be columnName -> [value1, value2]. */ |
|||
oneOf?: { [key: string]: unknown } |
|||
} |
|||
/** @description Enables pagination, by default this is disabled. */ |
|||
paginate?: boolean |
|||
/** @description If retrieving another page, the bookmark from the previous request must be supplied. */ |
|||
bookmark?: string | number |
|||
/** @description The maximum number of rows to return, useful when paginating, for internal tables this will be limited to 1000, for SQL tables it will be 5000. */ |
|||
limit?: number |
|||
/** @description A set of parameters describing the sort behaviour of the search. */ |
|||
sort?: { |
|||
/** |
|||
* @description The order of the sort, by default this is ascending. |
|||
* @enum {string} |
|||
*/ |
|||
order?: "ascending" | "descending" |
|||
/** @description The name of the column by which the rows will be sorted. */ |
|||
column?: string |
|||
/** |
|||
* @description Defines whether the column should be treated as a string or as numbers when sorting. |
|||
* @enum {string} |
|||
*/ |
|||
type?: "string" | "number" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/tables": { |
|||
/** Create a table, this could be internal or external. */ |
|||
post: { |
|||
parameters: { |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the created table, including the ID which has been generated for it. This can be internal or external data sources. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["tableOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["table"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/tables/{tableId}": { |
|||
/** Lookup a table, this could be internal or external. */ |
|||
get: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the table which this request is targeting. */ |
|||
tableId: components["parameters"]["tableId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the retrieved table. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["tableOutput"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
/** Update a table, this could be internal or external. */ |
|||
put: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the table which this request is targeting. */ |
|||
tableId: components["parameters"]["tableId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the updated table. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["tableOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["table"] |
|||
} |
|||
} |
|||
} |
|||
/** Delete a table, this could be internal or external. */ |
|||
delete: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the table which this request is targeting. */ |
|||
tableId: components["parameters"]["tableId"] |
|||
} |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the deleted table. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["tableOutput"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/tables/search": { |
|||
/** Based on table properties (currently only name) search for tables. This could be an internal or an external table. */ |
|||
post: { |
|||
parameters: { |
|||
header: { |
|||
/** The ID of the app which this request is targeting. */ |
|||
"x-budibase-app-id": components["parameters"]["appId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the found tables, based on the search parameters. */ |
|||
200: { |
|||
content: { |
|||
"application/json": { |
|||
data: components["schemas"]["table"][] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["nameSearch"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/users": { |
|||
post: { |
|||
responses: { |
|||
/** Returns the created user. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["userOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["user"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/users/{userId}": { |
|||
get: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the user which this request is targeting. */ |
|||
userId: components["parameters"]["userId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the retrieved user. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["userOutput"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
put: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the user which this request is targeting. */ |
|||
userId: components["parameters"]["userId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the updated user. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["userOutput"] |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["user"] |
|||
} |
|||
} |
|||
} |
|||
delete: { |
|||
parameters: { |
|||
path: { |
|||
/** The ID of the user which this request is targeting. */ |
|||
userId: components["parameters"]["userId"] |
|||
} |
|||
} |
|||
responses: { |
|||
/** Returns the deleted user. */ |
|||
200: { |
|||
content: { |
|||
"application/json": components["schemas"]["userOutput"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
"/users/search": { |
|||
/** Based on user properties (currently only name) search for users. */ |
|||
post: { |
|||
responses: { |
|||
/** Returns the found users based on search parameters. */ |
|||
200: { |
|||
content: { |
|||
"application/json": { |
|||
data: components["schemas"]["user"][] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
requestBody: { |
|||
content: { |
|||
"application/json": components["schemas"]["nameSearch"] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
export interface components { |
|||
schemas: { |
|||
application: { |
|||
/** @description The name of the app. */ |
|||
name: string |
|||
/** @description The URL by which the app is accessed, this must be URL encoded. */ |
|||
url: string |
|||
} |
|||
applicationOutput: { |
|||
data: { |
|||
/** @description The name of the app. */ |
|||
name: string |
|||
/** @description The URL by which the app is accessed, this must be URL encoded. */ |
|||
url: string |
|||
/** @description The ID of the app. */ |
|||
_id: string |
|||
/** |
|||
* @description The status of the app, stating it if is the development or published version. |
|||
* @enum {string} |
|||
*/ |
|||
status: "development" | "published" |
|||
/** @description States when the app was created, will be constant. Stored in ISO format. */ |
|||
createdAt: string |
|||
/** @description States the last time the app was updated - stored in ISO format. */ |
|||
updatedAt: string |
|||
/** @description States the version of the Budibase client this app is currently based on. */ |
|||
version: string |
|||
/** @description In a multi-tenant environment this will state the tenant this app is within. */ |
|||
tenantId?: string |
|||
/** @description The user this app is currently being built by. */ |
|||
lockedBy?: { [key: string]: unknown } |
|||
} |
|||
} |
|||
/** @description The row to be created/updated, based on the table schema. */ |
|||
row: { [key: string]: unknown } |
|||
searchOutput: { |
|||
/** @description An array of rows, these will each contain an _id field which can be used to update or delete them. */ |
|||
data: { [key: string]: unknown }[] |
|||
/** @description If pagination in use, this should be provided. */ |
|||
bookmark?: string | number |
|||
/** @description If pagination in use, this will determine if there is another page to fetch. */ |
|||
hasNextPage?: boolean |
|||
} |
|||
rowOutput: { |
|||
/** @description The row to be created/updated, based on the table schema. */ |
|||
data: { |
|||
/** @description The ID of the row. */ |
|||
_id: string |
|||
/** @description The ID of the table this row comes from. */ |
|||
tableId: string |
|||
} & { [key: string]: unknown } |
|||
} |
|||
/** @description The table to be created/updated. */ |
|||
table: { |
|||
/** @description The name of the table. */ |
|||
name: string |
|||
/** @description The name of the column which should be used in relationship tags when relating to this table. */ |
|||
primaryDisplay?: string |
|||
schema: { |
|||
[key: string]: |
|||
| { |
|||
/** |
|||
* @description A relationship column. |
|||
* @enum {string} |
|||
*/ |
|||
type?: "link" |
|||
/** @description A constraint can be applied to the column which will be validated against when a row is saved. */ |
|||
constraints?: { |
|||
/** @enum {string} */ |
|||
type?: "string" | "number" | "object" | "boolean" |
|||
/** @description Defines whether the column is required or not. */ |
|||
presence?: boolean |
|||
} |
|||
/** @description The name of the column. */ |
|||
name?: string |
|||
/** @description Defines whether the column is automatically generated. */ |
|||
autocolumn?: boolean |
|||
/** @description The name of the column which a relationship column is related to in another table. */ |
|||
fieldName?: string |
|||
/** @description The ID of the table which a relationship column is related to. */ |
|||
tableId?: string |
|||
/** |
|||
* @description Defines the type of relationship that this column will be used for. |
|||
* @enum {string} |
|||
*/ |
|||
relationshipType?: "one-to-many" | "many-to-one" | "many-to-many" |
|||
/** @description When using a SQL table that contains many to many relationships this defines the table the relationships are linked through. */ |
|||
through?: string |
|||
/** @description When using a SQL table that contains a one to many relationship this defines the foreign key. */ |
|||
foreignKey?: string |
|||
/** @description When using a SQL table that utilises a through table, this defines the primary key in the through table for this table. */ |
|||
throughFrom?: 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. */ |
|||
throughTo?: string |
|||
} |
|||
| { |
|||
/** |
|||
* @description A formula column. |
|||
* @enum {string} |
|||
*/ |
|||
type?: "formula" |
|||
/** @description A constraint can be applied to the column which will be validated against when a row is saved. */ |
|||
constraints?: { |
|||
/** @enum {string} */ |
|||
type?: "string" | "number" | "object" | "boolean" |
|||
/** @description Defines whether the column is required or not. */ |
|||
presence?: boolean |
|||
} |
|||
/** @description The name of the column. */ |
|||
name?: string |
|||
/** @description Defines whether the column is automatically generated. */ |
|||
autocolumn?: boolean |
|||
/** @description Defines a Handlebars or JavaScript formula to use, note that Javascript formulas are expected to be provided in the base64 format. */ |
|||
formula?: string |
|||
/** |
|||
* @description Defines whether this is a static or dynamic formula. |
|||
* @enum {string} |
|||
*/ |
|||
formulaType?: "static" | "dynamic" |
|||
} |
|||
| { |
|||
/** |
|||
* @description Defines the type of the column, most explain themselves, a link column is a relationship. |
|||
* @enum {string} |
|||
*/ |
|||
type?: |
|||
| "string" |
|||
| "longform" |
|||
| "options" |
|||
| "number" |
|||
| "boolean" |
|||
| "array" |
|||
| "datetime" |
|||
| "attachment" |
|||
| "link" |
|||
| "formula" |
|||
| "auto" |
|||
| "json" |
|||
| "internal" |
|||
/** @description A constraint can be applied to the column which will be validated against when a row is saved. */ |
|||
constraints?: { |
|||
/** @enum {string} */ |
|||
type?: "string" | "number" | "object" | "boolean" |
|||
/** @description Defines whether the column is required or not. */ |
|||
presence?: boolean |
|||
} |
|||
/** @description The name of the column. */ |
|||
name?: string |
|||
/** @description Defines whether the column is automatically generated. */ |
|||
autocolumn?: boolean |
|||
} |
|||
} |
|||
} |
|||
tableOutput: { |
|||
/** @description The table to be created/updated. */ |
|||
data: { |
|||
/** @description The name of the table. */ |
|||
name: string |
|||
/** @description The name of the column which should be used in relationship tags when relating to this table. */ |
|||
primaryDisplay?: string |
|||
schema: { |
|||
[key: string]: |
|||
| { |
|||
/** |
|||
* @description A relationship column. |
|||
* @enum {string} |
|||
*/ |
|||
type?: "link" |
|||
/** @description A constraint can be applied to the column which will be validated against when a row is saved. */ |
|||
constraints?: { |
|||
/** @enum {string} */ |
|||
type?: "string" | "number" | "object" | "boolean" |
|||
/** @description Defines whether the column is required or not. */ |
|||
presence?: boolean |
|||
} |
|||
/** @description The name of the column. */ |
|||
name?: string |
|||
/** @description Defines whether the column is automatically generated. */ |
|||
autocolumn?: boolean |
|||
/** @description The name of the column which a relationship column is related to in another table. */ |
|||
fieldName?: string |
|||
/** @description The ID of the table which a relationship column is related to. */ |
|||
tableId?: string |
|||
/** |
|||
* @description Defines the type of relationship that this column will be used for. |
|||
* @enum {string} |
|||
*/ |
|||
relationshipType?: |
|||
| "one-to-many" |
|||
| "many-to-one" |
|||
| "many-to-many" |
|||
/** @description When using a SQL table that contains many to many relationships this defines the table the relationships are linked through. */ |
|||
through?: string |
|||
/** @description When using a SQL table that contains a one to many relationship this defines the foreign key. */ |
|||
foreignKey?: string |
|||
/** @description When using a SQL table that utilises a through table, this defines the primary key in the through table for this table. */ |
|||
throughFrom?: 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. */ |
|||
throughTo?: string |
|||
} |
|||
| { |
|||
/** |
|||
* @description A formula column. |
|||
* @enum {string} |
|||
*/ |
|||
type?: "formula" |
|||
/** @description A constraint can be applied to the column which will be validated against when a row is saved. */ |
|||
constraints?: { |
|||
/** @enum {string} */ |
|||
type?: "string" | "number" | "object" | "boolean" |
|||
/** @description Defines whether the column is required or not. */ |
|||
presence?: boolean |
|||
} |
|||
/** @description The name of the column. */ |
|||
name?: string |
|||
/** @description Defines whether the column is automatically generated. */ |
|||
autocolumn?: boolean |
|||
/** @description Defines a Handlebars or JavaScript formula to use, note that Javascript formulas are expected to be provided in the base64 format. */ |
|||
formula?: string |
|||
/** |
|||
* @description Defines whether this is a static or dynamic formula. |
|||
* @enum {string} |
|||
*/ |
|||
formulaType?: "static" | "dynamic" |
|||
} |
|||
| { |
|||
/** |
|||
* @description Defines the type of the column, most explain themselves, a link column is a relationship. |
|||
* @enum {string} |
|||
*/ |
|||
type?: |
|||
| "string" |
|||
| "longform" |
|||
| "options" |
|||
| "number" |
|||
| "boolean" |
|||
| "array" |
|||
| "datetime" |
|||
| "attachment" |
|||
| "link" |
|||
| "formula" |
|||
| "auto" |
|||
| "json" |
|||
| "internal" |
|||
/** @description A constraint can be applied to the column which will be validated against when a row is saved. */ |
|||
constraints?: { |
|||
/** @enum {string} */ |
|||
type?: "string" | "number" | "object" | "boolean" |
|||
/** @description Defines whether the column is required or not. */ |
|||
presence?: boolean |
|||
} |
|||
/** @description The name of the column. */ |
|||
name?: string |
|||
/** @description Defines whether the column is automatically generated. */ |
|||
autocolumn?: boolean |
|||
} |
|||
} |
|||
/** @description The ID of the table. */ |
|||
_id: string |
|||
} |
|||
} |
|||
/** @description The query body must contain the required parameters for the query, this depends on query type, setup and bindings. */ |
|||
executeQuery: { [key: string]: unknown } |
|||
executeQueryOutput: { |
|||
/** @description The data response from the query. */ |
|||
data: { [key: string]: unknown }[] |
|||
/** @description Extra information that is not part of the main data, e.g. headers. */ |
|||
extra?: { |
|||
/** @description If carrying out a REST request, this will contain the response headers. */ |
|||
headers?: { [key: string]: unknown } |
|||
/** @description The raw query response, as a string. */ |
|||
raw?: string |
|||
} |
|||
/** @description If pagination is supported, this will contain the bookmark/anchor information for it. */ |
|||
pagination?: { [key: string]: unknown } |
|||
} |
|||
query: { |
|||
/** @description The ID of the query. */ |
|||
_id: string |
|||
/** @description The ID of the data source the query belongs to. */ |
|||
datasourceId?: string |
|||
/** @description The bindings which are required to perform this query. */ |
|||
parameters?: string[] |
|||
/** @description The fields that are used to perform this query, e.g. the sql statement */ |
|||
fields?: { [key: string]: unknown } |
|||
/** |
|||
* @description The verb that describes this query. |
|||
* @enum {undefined} |
|||
*/ |
|||
queryVerb?: "create" | "read" | "update" | "delete" |
|||
/** @description The name of the query. */ |
|||
name: string |
|||
/** @description The schema of the data returned when the query is executed. */ |
|||
schema: { [key: string]: unknown } |
|||
/** @description The JavaScript transformer function, applied after the query responds with data. */ |
|||
transformer?: string |
|||
/** @description Whether the query has readable data. */ |
|||
readable?: boolean |
|||
} |
|||
user: { |
|||
/** @description The email address of the user, this must be unique. */ |
|||
email: string |
|||
/** @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. */ |
|||
password?: string |
|||
/** |
|||
* @description The status of the user, if they are active. |
|||
* @enum {string} |
|||
*/ |
|||
status?: "active" |
|||
/** @description The first name of the user */ |
|||
firstName?: string |
|||
/** @description The last name of the user */ |
|||
lastName?: string |
|||
/** @description If set to true forces the user to reset their password on first login. */ |
|||
forceResetPassword?: boolean |
|||
/** @description Describes if the user is a builder user or not. */ |
|||
builder?: { |
|||
/** @description If set to true the user will be able to build any app in the system. */ |
|||
global?: boolean |
|||
} |
|||
/** @description Describes if the user is an admin user or not. */ |
|||
admin?: { |
|||
/** @description If set to true the user will be able to administrate the system. */ |
|||
global?: boolean |
|||
} |
|||
/** @description Contains the roles of the user per app (assuming they are not a builder user). */ |
|||
roles: { [key: string]: string } |
|||
} |
|||
userOutput: { |
|||
data: { |
|||
/** @description The email address of the user, this must be unique. */ |
|||
email: string |
|||
/** @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. */ |
|||
password?: string |
|||
/** |
|||
* @description The status of the user, if they are active. |
|||
* @enum {string} |
|||
*/ |
|||
status?: "active" |
|||
/** @description The first name of the user */ |
|||
firstName?: string |
|||
/** @description The last name of the user */ |
|||
lastName?: string |
|||
/** @description If set to true forces the user to reset their password on first login. */ |
|||
forceResetPassword?: boolean |
|||
/** @description Describes if the user is a builder user or not. */ |
|||
builder?: { |
|||
/** @description If set to true the user will be able to build any app in the system. */ |
|||
global?: boolean |
|||
} |
|||
/** @description Describes if the user is an admin user or not. */ |
|||
admin?: { |
|||
/** @description If set to true the user will be able to administrate the system. */ |
|||
global?: boolean |
|||
} |
|||
/** @description Contains the roles of the user per app (assuming they are not a builder user). */ |
|||
roles: { [key: string]: string } |
|||
/** @description The ID of the user. */ |
|||
_id: string |
|||
} |
|||
} |
|||
nameSearch: { |
|||
/** @description The name to be used when searching - this will be used in a case insensitive starts with match. */ |
|||
name: string |
|||
} |
|||
} |
|||
parameters: { |
|||
/** @description The ID of the table which this request is targeting. */ |
|||
tableId: string |
|||
/** @description The ID of the row which this request is targeting. */ |
|||
rowId: string |
|||
/** @description The ID of the app which this request is targeting. */ |
|||
appId: string |
|||
/** @description The ID of the app which this request is targeting. */ |
|||
appIdUrl: string |
|||
/** @description The ID of the query which this request is targeting. */ |
|||
queryId: string |
|||
/** @description The ID of the user which this request is targeting. */ |
|||
userId: string |
|||
} |
|||
} |
|||
|
|||
export interface operations {} |
|||
|
|||
export interface external {} |
|||
File diff suppressed because it is too large
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue