1
0
Fork 0
mirror of synced 2024-08-15 10:01:34 +12:00

Merge branch 'develop' of github.com:Budibase/budibase into feature/map-component

This commit is contained in:
Andrew Kingston 2022-03-16 15:31:10 +00:00
commit de318ec9e2
33 changed files with 5708 additions and 119 deletions

View file

@ -63,6 +63,7 @@ jobs:
run: |
git config user.name "Budibase Helm Bot"
git config user.email "<>"
git reset --hard
git pull
helm package charts/budibase
git checkout gh-pages

View file

@ -1,5 +1,5 @@
{
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"npmClient": "yarn",
"packages": [
"packages/*"

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/backend-core",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"description": "Budibase backend core libraries used in server and worker",
"main": "src/index.js",
"author": "Budibase",

View file

@ -5,7 +5,7 @@ const { getSession, updateSessionTTL } = require("../security/sessions")
const { buildMatcherRegex, matches } = require("./matchers")
const env = require("../environment")
const { SEPARATOR, ViewNames, queryGlobalView } = require("../../db")
const { getGlobalDB } = require("../tenancy")
const { getGlobalDB, doInTenant } = require("../tenancy")
const { decrypt } = require("../security/encryption")
function finalise(
@ -25,20 +25,25 @@ async function checkApiKey(apiKey, populateUser) {
}
const decrypted = decrypt(apiKey)
const tenantId = decrypted.split(SEPARATOR)[0]
const db = getGlobalDB(tenantId)
// api key is encrypted in the database
const userId = await queryGlobalView(
ViewNames.BY_API_KEY,
{
key: apiKey,
},
db
)
if (userId) {
return { valid: true, user: await getUser(userId, tenantId, populateUser) }
} else {
throw "Invalid API key"
}
return doInTenant(tenantId, async () => {
const db = getGlobalDB()
// api key is encrypted in the database
const userId = await queryGlobalView(
ViewNames.BY_API_KEY,
{
key: apiKey,
},
db
)
if (userId) {
return {
valid: true,
user: await getUser(userId, tenantId, populateUser),
}
} else {
throw "Invalid API key"
}
})
}
/**

View file

@ -40,7 +40,7 @@ exports.getRedisOptions = (clustered = false) => {
let redisProtocolUrl
// fully qualified redis URL
if (/rediss?/.test(REDIS_URL)) {
if (/rediss?:\/\//.test(REDIS_URL)) {
redisProtocolUrl = REDIS_URL
}

View file

@ -1,7 +1,7 @@
{
"name": "@budibase/bbui",
"description": "A UI solution used in the different Budibase projects.",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"license": "MPL-2.0",
"svelte": "src/index.js",
"module": "dist/bbui.es.js",
@ -38,7 +38,7 @@
],
"dependencies": {
"@adobe/spectrum-css-workflow-icons": "^1.2.1",
"@budibase/string-templates": "^1.0.84-alpha.0",
"@budibase/string-templates": "^1.0.91-alpha.0",
"@spectrum-css/actionbutton": "^1.0.1",
"@spectrum-css/actiongroup": "^1.0.1",
"@spectrum-css/avatar": "^3.0.2",

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/builder",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"license": "GPL-3.0",
"private": true,
"scripts": {
@ -65,10 +65,10 @@
}
},
"dependencies": {
"@budibase/bbui": "^1.0.84-alpha.0",
"@budibase/client": "^1.0.84-alpha.0",
"@budibase/frontend-core": "^1.0.84-alpha.0",
"@budibase/string-templates": "^1.0.84-alpha.0",
"@budibase/bbui": "^1.0.91-alpha.0",
"@budibase/client": "^1.0.91-alpha.0",
"@budibase/frontend-core": "^1.0.91-alpha.0",
"@budibase/string-templates": "^1.0.91-alpha.0",
"@sentry/browser": "5.19.1",
"@spectrum-css/page": "^3.0.1",
"@spectrum-css/vars": "^3.0.1",

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/cli",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"description": "Budibase CLI, for developers, self hosting and migrations.",
"main": "src/index.js",
"bin": {

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/client",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"license": "MPL-2.0",
"module": "dist/budibase-client.js",
"main": "dist/budibase-client.js",
@ -19,9 +19,9 @@
"dev:builder": "rollup -cw"
},
"dependencies": {
"@budibase/bbui": "^1.0.84-alpha.0",
"@budibase/frontend-core": "^1.0.84-alpha.0",
"@budibase/string-templates": "^1.0.84-alpha.0",
"@budibase/bbui": "^1.0.91-alpha.0",
"@budibase/frontend-core": "^1.0.91-alpha.0",
"@budibase/string-templates": "^1.0.91-alpha.0",
"@spectrum-css/button": "^3.0.3",
"@spectrum-css/card": "^3.0.3",
"@spectrum-css/divider": "^1.0.3",

View file

@ -250,9 +250,9 @@ const exportDataHandler = async action => {
const data = await API.exportRows({
tableId: selection.tableId,
rows: selection.selectedRows,
format: action.parameters.type,
})
download(JSON.stringify(data), `export.${action.parameters.type}`)
download(data, `${selection.tableId}.${action.parameters.type}`)
} catch (error) {
notificationStore.actions.error("There was an error exporting the data")
}

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,12 @@
{
"name": "@budibase/frontend-core",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"description": "Budibase frontend core libraries used in builder and client",
"author": "Budibase",
"license": "MPL-2.0",
"svelte": "src/index.js",
"dependencies": {
"@budibase/bbui": "^1.0.84-alpha.0",
"@budibase/bbui": "^1.0.91-alpha.0",
"lodash": "^4.17.21",
"svelte": "^3.46.2"
}

View file

@ -66,12 +66,15 @@ export const buildRowEndpoints = API => ({
* @param tableId the table ID to export the rows from
* @param rows the array of rows to export
*/
exportRows: async ({ tableId, rows }) => {
exportRows: async ({ tableId, rows, format }) => {
return await API.post({
url: `/api/${tableId}/rows/exportRows`,
url: `/api/${tableId}/rows/exportRows?format=${format}`,
body: {
rows,
},
parseResponse: async response => {
return await response.text()
},
})
},
})

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
{
"name": "@budibase/server",
"email": "hi@budibase.com",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"description": "Budibase Web Server",
"main": "src/index.ts",
"repository": {
@ -71,9 +71,9 @@
"license": "GPL-3.0",
"dependencies": {
"@apidevtools/swagger-parser": "^10.0.3",
"@budibase/backend-core": "^1.0.84-alpha.0",
"@budibase/client": "^1.0.84-alpha.0",
"@budibase/string-templates": "^1.0.84-alpha.0",
"@budibase/backend-core": "^1.0.91-alpha.0",
"@budibase/client": "^1.0.91-alpha.0",
"@budibase/string-templates": "^1.0.91-alpha.0",
"@bull-board/api": "^3.7.0",
"@bull-board/koa": "^3.7.0",
"@elastic/elasticsearch": "7.10.0",

View file

@ -10,6 +10,8 @@ const {
} = require("../../../integrations/utils")
const ExternalRequest = require("./ExternalRequest")
const { getAppDB } = require("@budibase/backend-core/context")
const exporters = require("../view/exporters")
const { apiFileReturn } = require("../../../utilities/fileSystem")
async function handleRequest(operation, tableId, opts = {}) {
// make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
@ -155,6 +157,7 @@ exports.validate = async () => {
exports.exportRows = async ctx => {
const { datasourceId, tableName } = breakExternalTableId(ctx.params.tableId)
const db = getAppDB()
let format = ctx.query.format
const datasource = await db.get(datasourceId)
if (!datasource || !datasource.entities) {
ctx.throw(400, "Datasource has not been configured for plus API.")
@ -164,13 +167,22 @@ exports.exportRows = async ctx => {
ctx.request.body = {
query: {
oneOf: {
[table.primaryDisplay]: ctx.request.body.map(
[table.primaryDisplay]: ctx.request.body.rows.map(
id => breakRowIdField(id)[0]
),
},
},
}
return exports.search(ctx)
let result = await exports.search(ctx)
let headers = Object.keys(result.rows[0])
const exporter = exporters[format]
const filename = `export.${format}`
// send down the file
ctx.attachment(filename)
return apiFileReturn(exporter(headers, result.rows))
}
exports.fetchEnrichedRow = async ctx => {

View file

@ -27,6 +27,8 @@ const {
const { cloneDeep } = require("lodash/fp")
const { getAppDB } = require("@budibase/backend-core/context")
const { finaliseRow, updateRelatedFormula } = require("./staticFormula")
const exporters = require("../view/exporters")
const { apiFileReturn } = require("../../../utilities/fileSystem")
const CALCULATION_TYPES = {
SUM: "sum",
@ -366,6 +368,7 @@ exports.exportRows = async ctx => {
const db = getAppDB()
const table = await db.get(ctx.params.tableId)
const rowIds = ctx.request.body.rows
let format = ctx.query.format
let response = (
await db.allDocs({
include_docs: true,
@ -375,7 +378,13 @@ exports.exportRows = async ctx => {
let rows = await outputProcessing(table, response)
return rows
let headers = Object.keys(rows[0])
const exporter = exporters[format]
const filename = `export.${format}`
// send down the file
ctx.attachment(filename)
return apiFileReturn(exporter(headers, rows))
}
exports.fetchEnrichedRow = async ctx => {

View file

@ -5,6 +5,7 @@ import rowEndpoints from "./rows"
import userEndpoints from "./users"
import usage from "../../../middleware/usageQuota"
import authorized from "../../../middleware/authorized"
import publicApi from "../../../middleware/publicApi"
import { paramResource, paramSubResource } from "../../../middleware/resourceId"
import { CtxFn } from "./utils/Endpoint"
import mapperMiddleware from "./middleware/mapper"
@ -31,16 +32,24 @@ function getApiLimitPerSecond(): number {
if (!env.isTest()) {
const REDIS_OPTS = getRedisOptions()
RateLimit.defaultOptions({
store: new Stores.Redis({
// @ts-ignore
let options
if (REDIS_OPTS.redisProtocolUrl) {
// fully qualified redis URL
options = {
url: REDIS_OPTS.redisProtocolUrl,
}
} else {
options = {
socket: {
host: REDIS_OPTS.host,
port: REDIS_OPTS.port,
},
password: REDIS_OPTS.opts.password,
database: 1,
}),
}
}
RateLimit.defaultOptions({
store: new Stores.Redis(options),
})
}
// rate limiting, allows for 2 requests per second
@ -93,6 +102,12 @@ function applyRoutes(
const paramMiddleware = subResource
? paramSubResource(resource, subResource)
: paramResource(resource)
const publicApiMiddleware = publicApi({
requiresAppId:
permType !== PermissionTypes.APP && permType !== PermissionTypes.USER,
})
addMiddleware(endpoints.read, publicApiMiddleware)
addMiddleware(endpoints.write, publicApiMiddleware)
// add the parameter capture middleware
addMiddleware(endpoints.read, paramMiddleware)
addMiddleware(endpoints.write, paramMiddleware)

View file

@ -8,5 +8,6 @@ export interface DatasourcePlus extends IntegrationBase {
// if the datasource supports the use of bindings directly (to protect against SQL injection)
// this returns the format of the identifier
getBindingIdentifier(): string
getStringConcat(parts: string[]): string
buildSchema(datasourceId: string, entities: Record<string, Table>): any
}

View file

@ -115,6 +115,10 @@ module GoogleSheetsModule {
return ""
}
getStringConcat(parts: string[]) {
return ""
}
/**
* Pull the spreadsheet ID out from a valid google sheets URL
* @param spreadsheetId - the URL or standard spreadsheetId of the google sheet

View file

@ -126,7 +126,11 @@ module MSSQLModule {
}
getBindingIdentifier(): string {
return `(@p${this.index++})`
return `@p${this.index++}`
}
getStringConcat(parts: string[]): string {
return `concat(${parts.join(", ")})`
}
async connect() {

View file

@ -99,6 +99,10 @@ module MySQLModule {
return "?"
}
getStringConcat(parts: string[]): string {
return `concat(${parts.join(", ")})`
}
async connect() {
this.client = await mysql.createConnection(this.config)
}

View file

@ -179,6 +179,10 @@ module OracleModule {
return `:${this.index++}`
}
getStringConcat(parts: string[]): string {
return parts.join(" || ")
}
/**
* Map the flat tabular columns and constraints data into a nested object
*/

View file

@ -148,6 +148,10 @@ module PostgresModule {
return `$${this.index++}`
}
getStringConcat(parts: string[]): string {
return parts.join(" || ")
}
async internalQuery(query: SqlQuery) {
const client = this.client
this.index = 1

View file

@ -0,0 +1,21 @@
const { Headers } = require("@budibase/backend-core/constants")
const { getAppId } = require("@budibase/backend-core/utils")
module.exports = function ({ requiresAppId } = {}) {
return async (ctx, next) => {
const appId = getAppId(ctx)
if (requiresAppId && !appId) {
ctx.throw(
400,
`Invalid app ID provided, please check the ${Headers.APP_ID} header.`
)
}
if (!ctx.headers[Headers.API_KEY]) {
ctx.throw(
400,
`Invalid API key provided, please check the ${Headers.API_KEY} header.`
)
}
return next()
}
}

View file

@ -37,7 +37,20 @@ class QueryRunner {
for (let binding of bindings) {
let variable = integration.getBindingIdentifier()
variables.push(binding)
sql = sql.replace(binding, variable)
// check if the variable was used as part of a string concat e.g. 'Hello {{binding}}'
const charConstRegex = new RegExp(`'[^']*${binding}[^']*'`)
const charConstMatch = sql.match(charConstRegex)
if (charConstMatch) {
let [part1, part2] = charConstMatch[0].split(binding)
part1 = `'${part1.substring(1)}'`
part2 = `'${part2.substring(0, part2.length - 1)}'`
sql = sql.replace(
charConstMatch[0],
integration.getStringConcat([part1, variable, part2])
)
} else {
sql = sql.replace(binding, variable)
}
}
// replicate the knex structure
fields.sql = sql

View file

@ -995,10 +995,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@^1.0.82":
version "1.0.82"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.82.tgz#9197da1dd0252c32957f6ec9a60bde489b4e87eb"
integrity sha512-ObQ9Ik8rEQ6bWP1JZI+6GGD3T+JqyQEPIWBvLTOdYWefHaPkjrvi6CK6+UUQuZtMXQHDv2hyu+FolV/+EbzK9w==
"@budibase/backend-core@^1.0.84":
version "1.0.84"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.84.tgz#9fb01669129838419c57f1723e9274cb4bb9dfd5"
integrity sha512-8hqRxSHO8A46f/hyzcqCdlku05yXBVEea1/FJdkoEDoCPhbuv04VHQ/f/dwkWctQ/oL8fm8MHpCA4ApyO7bnJA==
dependencies:
"@techpass/passport-openidconnect" "^0.3.0"
aws-sdk "^2.901.0"
@ -1068,13 +1068,13 @@
svelte-flatpickr "^3.2.3"
svelte-portal "^1.0.0"
"@budibase/bbui@^1.0.82":
version "1.0.82"
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.0.82.tgz#d84796d08dcaac6051a7306d24feb774882d2599"
integrity sha512-i566tYEp3dTWMq/KON3HP3q1QwWfCK010j1Gb8Od2MPZDC7Yqv9KogS5CEhJnCkmaytI2tn2R0rIg8f9nK2FSw==
"@budibase/bbui@^1.0.84":
version "1.0.84"
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.0.84.tgz#8bf2f3d93aaf71ae353f93b10cb34e06c99d8176"
integrity sha512-GO2qXq5wJ00YCdgl93fP1y9eLwAbX0fpt9WVqNYWcgUzAMkeQAOPr7S0ud05GwLZPo736exxqh6RzSwo5H73sg==
dependencies:
"@adobe/spectrum-css-workflow-icons" "^1.2.1"
"@budibase/string-templates" "^1.0.82"
"@budibase/string-templates" "^1.0.84"
"@spectrum-css/actionbutton" "^1.0.1"
"@spectrum-css/actiongroup" "^1.0.1"
"@spectrum-css/avatar" "^3.0.2"
@ -1120,14 +1120,14 @@
svelte-flatpickr "^3.2.3"
svelte-portal "^1.0.0"
"@budibase/client@^1.0.82":
version "1.0.82"
resolved "https://registry.yarnpkg.com/@budibase/client/-/client-1.0.82.tgz#0f74753686ace1b41c33cde87a395f0e9560d569"
integrity sha512-WTiQSpPKcjvrZvJjVrW5qGYzx3D6/n5PUyuLzZHKrMWDd2Z1mfSQLED+tuiv7BOgVy27YUfqwLLCve/SMXL1tw==
"@budibase/client@^1.0.84":
version "1.0.84"
resolved "https://registry.yarnpkg.com/@budibase/client/-/client-1.0.84.tgz#7d29cd03a3611fb580ced1bb911b45e73a8c7832"
integrity sha512-sZC3/7KQXPHS/jDyeTiPKK8Ri81JgtgInIfEvpd45V5jeg5kNo0L1m37xZgQEzQCqSqr47veM6WN7Kl3WYZr0g==
dependencies:
"@budibase/bbui" "^1.0.82"
"@budibase/frontend-core" "^1.0.82"
"@budibase/string-templates" "^1.0.82"
"@budibase/bbui" "^1.0.84"
"@budibase/frontend-core" "^1.0.84"
"@budibase/string-templates" "^1.0.84"
"@spectrum-css/button" "^3.0.3"
"@spectrum-css/card" "^3.0.3"
"@spectrum-css/divider" "^1.0.3"
@ -1147,12 +1147,12 @@
svelte-flatpickr "^3.1.0"
svelte-spa-router "^3.0.5"
"@budibase/frontend-core@^1.0.82":
version "1.0.82"
resolved "https://registry.yarnpkg.com/@budibase/frontend-core/-/frontend-core-1.0.82.tgz#118953d7a6b9d4f4e9954fb0f20a51b2fc2fccd7"
integrity sha512-WwUuKl47sz5use36d/qoj7zTuBwb6OlYLla7FRpCoALOoQiU9SVUVu/tFTsC9K0v9v7Gwb86qXoamzovIMzG7A==
"@budibase/frontend-core@^1.0.84":
version "1.0.84"
resolved "https://registry.yarnpkg.com/@budibase/frontend-core/-/frontend-core-1.0.84.tgz#d21594ddb521b79e2ac1b5322903887268f8a9aa"
integrity sha512-v6vTIVq8p+1ytnCWckYUqzzJ4Ylo6DF4C/pi2x5UrZxZuU7tQPMYGktHGQOouosHoGoZXsnPXJooeFHy43j0OQ==
dependencies:
"@budibase/bbui" "^1.0.82"
"@budibase/bbui" "^1.0.84"
lodash "^4.17.21"
svelte "^3.46.2"
@ -1199,10 +1199,10 @@
svelte-apexcharts "^1.0.2"
svelte-flatpickr "^3.1.0"
"@budibase/string-templates@^1.0.82":
version "1.0.82"
resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-1.0.82.tgz#562e862d0eac279b72135cb34996ee347edabafd"
integrity sha512-6/zPqAJhQ4ZVMatzi3Fu4ht0KLDnEEoPFdjOqHjZEK2B3OoIHy0ZkRPf6g5dSYvv2QujATEYAJvzhemVSLMd6g==
"@budibase/string-templates@^1.0.84":
version "1.0.84"
resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-1.0.84.tgz#66669e9898ed20c6be2c46a5eb19d55003eb6bcb"
integrity sha512-6Tv/TfGkmr3uBwNdZ3eKAPKwdsRTZbuQ+02puH+EcJK2leCerINo1SpAHf1BOmjQJynKeslKpSkUiisRVerMEg==
dependencies:
"@budibase/handlebars-helpers" "^0.11.8"
dayjs "^1.10.4"

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/string-templates",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"description": "Handlebars wrapper for Budibase templating.",
"main": "src/index.cjs",
"module": "dist/bundle.mjs",

View file

@ -1,7 +1,7 @@
{
"name": "@budibase/worker",
"email": "hi@budibase.com",
"version": "1.0.84-alpha.0",
"version": "1.0.91-alpha.0",
"description": "Budibase background service",
"main": "src/index.ts",
"repository": {
@ -34,8 +34,8 @@
"author": "Budibase",
"license": "GPL-3.0",
"dependencies": {
"@budibase/backend-core": "^1.0.84-alpha.0",
"@budibase/string-templates": "^1.0.84-alpha.0",
"@budibase/backend-core": "^1.0.91-alpha.0",
"@budibase/string-templates": "^1.0.91-alpha.0",
"@koa/router": "^8.0.0",
"@sentry/node": "^6.0.0",
"@techpass/passport-openidconnect": "^0.3.0",

View file

@ -85,7 +85,12 @@ exports.setInitInfo = ctx => {
}
exports.getInitInfo = ctx => {
ctx.body = getCookie(ctx, Cookies.Init) || {}
try {
ctx.body = getCookie(ctx, Cookies.Init) || {}
} catch (err) {
clearCookie(ctx, Cookies.Init)
ctx.body = {}
}
}
/**

File diff suppressed because it is too large Load diff