Merge remote-tracking branch 'origin/master' into feedback

This commit is contained in:
Michael Shanks 2020-10-26 11:46:07 +00:00
commit aa5d3d5af2
17 changed files with 627 additions and 288 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "0.2.5", "version": "0.2.6",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*" "packages/*"

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/builder", "name": "@budibase/builder",
"version": "0.2.5", "version": "0.2.6",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"private": true, "private": true,
"scripts": { "scripts": {
@ -64,7 +64,7 @@
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.44.1", "@budibase/bbui": "^1.44.1",
"@budibase/client": "^0.2.5", "@budibase/client": "^0.2.6",
"@budibase/colorpicker": "^1.0.1", "@budibase/colorpicker": "^1.0.1",
"@fortawesome/fontawesome-free": "^5.14.0", "@fortawesome/fontawesome-free": "^5.14.0",
"@sentry/browser": "5.19.1", "@sentry/browser": "5.19.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "budibase", "name": "budibase",
"version": "0.2.5", "version": "0.2.6",
"description": "Budibase CLI", "description": "Budibase CLI",
"repository": "https://github.com/Budibase/Budibase", "repository": "https://github.com/Budibase/Budibase",
"homepage": "https://www.budibase.com", "homepage": "https://www.budibase.com",
@ -17,7 +17,7 @@
"author": "Budibase", "author": "Budibase",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"@budibase/server": "^0.2.5", "@budibase/server": "^0.2.6",
"@inquirer/password": "^0.0.6-alpha.0", "@inquirer/password": "^0.0.6-alpha.0",
"chalk": "^2.4.2", "chalk": "^2.4.2",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/client", "name": "@budibase/client",
"version": "0.2.5", "version": "0.2.6",
"license": "MPL-2.0", "license": "MPL-2.0",
"main": "dist/budibase-client.js", "main": "dist/budibase-client.js",
"module": "dist/budibase-client.esm.mjs", "module": "dist/budibase-client.esm.mjs",

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/server", "name": "@budibase/server",
"version": "0.2.5", "version": "0.2.6",
"description": "Budibase Web Server", "description": "Budibase Web Server",
"main": "src/electron.js", "main": "src/electron.js",
"repository": { "repository": {
@ -42,7 +42,7 @@
"author": "Michael Shanks", "author": "Michael Shanks",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"@budibase/client": "^0.2.5", "@budibase/client": "^0.2.6",
"@koa/router": "^8.0.0", "@koa/router": "^8.0.0",
"@sendgrid/mail": "^7.1.1", "@sendgrid/mail": "^7.1.1",
"@sentry/node": "^5.19.2", "@sentry/node": "^5.19.2",
@ -57,6 +57,7 @@
"electron-updater": "^4.3.1", "electron-updater": "^4.3.1",
"fix-path": "^3.0.0", "fix-path": "^3.0.0",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"jimp": "^0.16.1",
"joi": "^17.2.1", "joi": "^17.2.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"koa": "^2.7.0", "koa": "^2.7.0",
@ -74,7 +75,6 @@
"pouchdb-all-dbs": "^1.0.2", "pouchdb-all-dbs": "^1.0.2",
"pouchdb-replication-stream": "^1.2.9", "pouchdb-replication-stream": "^1.2.9",
"sanitize-s3-objectkey": "^0.0.1", "sanitize-s3-objectkey": "^0.0.1",
"sharp": "^0.26.0",
"squirrelly": "^7.5.0", "squirrelly": "^7.5.0",
"tar-fs": "^2.1.0", "tar-fs": "^2.1.0",
"uuid": "^3.3.2", "uuid": "^3.3.2",

View File

@ -12,6 +12,7 @@ const { join, resolve } = require("../../utilities/centralPath")
const { promisify } = require("util") const { promisify } = require("util")
const chmodr = require("chmodr") const chmodr = require("chmodr")
const { generateAppID, getAppParams } = require("../../db/utils") const { generateAppID, getAppParams } = require("../../db/utils")
const packageJson = require("../../../package.json")
const { const {
downloadExtractComponentLibraries, downloadExtractComponentLibraries,
} = require("../../utilities/createAppPackage") } = require("../../utilities/createAppPackage")
@ -38,7 +39,12 @@ exports.fetchAppPackage = async function(ctx) {
const devInstance = application.instances.find( const devInstance = application.instances.find(
i => i.name === `dev-${clientId}` i => i.name === `dev-${clientId}`
) )
setBuilderToken(ctx, ctx.params.applicationId, devInstance._id) setBuilderToken(
ctx,
ctx.params.applicationId,
devInstance._id,
application.version
)
} }
exports.create = async function(ctx) { exports.create = async function(ctx) {
@ -64,6 +70,7 @@ exports.create = async function(ctx) {
type: "app", type: "app",
instances: [], instances: [],
userInstanceMap: {}, userInstanceMap: {},
version: packageJson.version,
componentLibraries: ["@budibase/standard-components"], componentLibraries: ["@budibase/standard-components"],
name: ctx.request.body.name, name: ctx.request.body.name,
template: ctx.request.body.template, template: ctx.request.body.template,

View File

@ -51,6 +51,7 @@ exports.authenticate = async ctx => {
userId: dbUser._id, userId: dbUser._id,
accessLevelId: dbUser.accessLevelId, accessLevelId: dbUser.accessLevelId,
appId: ctx.user.appId, appId: ctx.user.appId,
version: app.version,
instanceId, instanceId,
} }
// if in cloud add the user api key // if in cloud add the user api key

View File

@ -5,7 +5,6 @@ const fs = require("fs-extra")
const uuid = require("uuid") const uuid = require("uuid")
const AWS = require("aws-sdk") const AWS = require("aws-sdk")
const { prepareUploadForS3 } = require("./deploy/aws") const { prepareUploadForS3 } = require("./deploy/aws")
const { const {
budibaseAppsDir, budibaseAppsDir,
budibaseTempDir, budibaseTempDir,
@ -15,6 +14,9 @@ const setBuilderToken = require("../../utilities/builder/setBuilderToken")
const fileProcessor = require("../../utilities/fileProcessor") const fileProcessor = require("../../utilities/fileProcessor")
const { AuthTypes } = require("../../constants") const { AuthTypes } = require("../../constants")
// this was the version before we started versioning the component library
const COMP_LIB_BASE_APP_VERSION = "0.2.5"
exports.serveBuilder = async function(ctx) { exports.serveBuilder = async function(ctx) {
let builderPath = resolve(__dirname, "../../../builder") let builderPath = resolve(__dirname, "../../../builder")
if (ctx.file === "index.html") { if (ctx.file === "index.html") {
@ -163,15 +165,14 @@ exports.serveApp = async function(ctx) {
exports.serveAttachment = async function(ctx) { exports.serveAttachment = async function(ctx) {
const appId = ctx.user.appId const appId = ctx.user.appId
const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments") const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments")
// Serve from CloudFront // Serve from CloudFront
if (process.env.CLOUD) { if (process.env.CLOUD) {
const S3_URL = `https://cdn.app.budi.live/assets/${appId}/attachments/${ctx.file}` const S3_URL = `https://cdn.app.budi.live/assets/${appId}/attachments/${ctx.file}`
const response = await fetch(S3_URL) const response = await fetch(S3_URL)
const body = await response.text() const body = await response.text()
ctx.set("Content-Type", response.headers.get("Content-Type"))
ctx.body = body ctx.body = body
return return
} }
@ -213,11 +214,16 @@ exports.serveComponentLibrary = async function(ctx) {
) )
} }
// TODO: component libs should be versioned based on app version
if (process.env.CLOUD) { if (process.env.CLOUD) {
let componentLib = "componentlibrary"
if (ctx.user.version) {
componentLib += `-${ctx.user.version}`
} else {
componentLib += `-${COMP_LIB_BASE_APP_VERSION}`
}
const appId = ctx.query.appId const appId = ctx.query.appId
const S3_URL = encodeURI( const S3_URL = encodeURI(
`https://${appId}.app.budi.live/assets/componentlibrary/${ctx.query.library}/dist/index.js` `https://${appId}.app.budi.live/assets/${componentLib}/${ctx.query.library}/dist/index.js`
) )
const response = await fetch(S3_URL) const response = await fetch(S3_URL)
const body = await response.text() const body = await response.text()

View File

@ -1,5 +1,7 @@
const Router = require("@koa/router") const Router = require("@koa/router")
const StatusCodes = require("../../utilities/statusCodes") const StatusCodes = require("../../utilities/statusCodes")
const joiValidator = require("../../middleware/joi-validator")
const Joi = require("joi")
const { const {
listScreens, listScreens,
saveScreen, saveScreen,
@ -12,6 +14,33 @@ const { BUILDER } = require("../../utilities/accessLevels")
const router = Router() const router = Router()
function generateSaveValidation() {
// prettier-ignore
return joiValidator.body(Joi.object({
_css: Joi.string().allow(""),
name: Joi.string().required(),
route: Joi.string().required(),
props: Joi.object({
_id: Joi.string().required(),
_component: Joi.string().required(),
_children: Joi.array().required(),
_instanceName: Joi.string().required(),
_styles: Joi.object().required(),
type: Joi.string().optional(),
table: Joi.string().optional(),
}).required().unknown(true),
}).unknown(true))
}
function generatePatchValidation() {
return joiValidator.body(
Joi.object({
oldname: Joi.string().required(),
newname: Joi.string().required(),
}).unknown(true)
)
}
router.post( router.post(
"/_builder/api/:appId/pages/:pageName", "/_builder/api/:appId/pages/:pageName",
authorized(BUILDER), authorized(BUILDER),
@ -42,6 +71,7 @@ router.get(
router.post( router.post(
"/_builder/api/:appId/pages/:pagename/screen", "/_builder/api/:appId/pages/:pagename/screen",
authorized(BUILDER), authorized(BUILDER),
generateSaveValidation(),
async ctx => { async ctx => {
ctx.body = await saveScreen( ctx.body = await saveScreen(
ctx.config, ctx.config,
@ -56,6 +86,7 @@ router.post(
router.patch( router.patch(
"/_builder/api/:appname/pages/:pagename/screen", "/_builder/api/:appname/pages/:pagename/screen",
authorized(BUILDER), authorized(BUILDER),
generatePatchValidation(),
async ctx => { async ctx => {
await renameScreen( await renameScreen(
ctx.config, ctx.config,

View File

@ -7,6 +7,7 @@ const {
BUILDER_LEVEL_ID, BUILDER_LEVEL_ID,
generateAdminPermissions, generateAdminPermissions,
} = require("../../../utilities/accessLevels") } = require("../../../utilities/accessLevels")
const packageJson = require("../../../../package")
const jwt = require("jsonwebtoken") const jwt = require("jsonwebtoken")
const env = require("../../../environment") const env = require("../../../environment")
@ -214,6 +215,7 @@ const createUserWithPermissions = async (
userId: "ANON", userId: "ANON",
accessLevelId: ANON_LEVEL_ID, accessLevelId: ANON_LEVEL_ID,
appId: appId, appId: appId,
version: packageJson.version,
} }
const anonToken = jwt.sign(anonUser, env.JWT_SECRET) const anonToken = jwt.sign(anonUser, env.JWT_SECRET)

View File

@ -15,4 +15,5 @@ module.exports = {
DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT, DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT,
AWS_REGION: process.env.AWS_REGION, AWS_REGION: process.env.AWS_REGION,
DEPLOYMENT_CREDENTIALS_URL: process.env.DEPLOYMENT_CREDENTIALS_URL, DEPLOYMENT_CREDENTIALS_URL: process.env.DEPLOYMENT_CREDENTIALS_URL,
BUDIBASE_API_KEY: process.env.BUDIBASE_API_KEY,
} }

View File

@ -1,15 +1,17 @@
const { BUILDER_LEVEL_ID } = require("../accessLevels") const { BUILDER_LEVEL_ID } = require("../accessLevels")
const environment = require("../../environment")
const jwt = require("jsonwebtoken") const jwt = require("jsonwebtoken")
module.exports = (ctx, appId, instanceId) => { module.exports = (ctx, appId, instanceId, version) => {
const builderUser = { const builderUser = {
userId: "BUILDER", userId: "BUILDER",
accessLevelId: BUILDER_LEVEL_ID, accessLevelId: BUILDER_LEVEL_ID,
instanceId, instanceId,
appId, appId,
version,
} }
if (process.env.BUDIBASE_API_KEY) { if (environment.BUDIBASE_API_KEY) {
builderUser.apiKey = process.env.BUDIBASE_API_KEY builderUser.apiKey = environment.BUDIBASE_API_KEY
} }
const token = jwt.sign(builderUser, ctx.config.jwtSecret, { const token = jwt.sign(builderUser, ctx.config.jwtSecret, {
expiresIn: "30 days", expiresIn: "30 days",

View File

@ -1,24 +1,21 @@
const fs = require("fs") const fs = require("fs")
const sharp = require("sharp") const jimp = require("jimp")
const fsPromises = fs.promises const fsPromises = fs.promises
const FORMATS = { const FORMATS = {
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"], IMAGES: ["png", "jpg", "jpeg", "gif", "bmp", "tiff"],
} }
async function processImage(file) { function processImage(file) {
const imgMeta = await sharp(file.path) return jimp.read(file.path).then(img => {
.resize(300) return img.resize(300, jimp.AUTO).write(file.outputPath)
.toFile(file.outputPath) })
return {
...file,
...imgMeta,
}
} }
async function process(file) { async function process(file) {
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) { if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
return await processImage(file) await processImage(file)
return file
} }
// No processing required // No processing required

File diff suppressed because it is too large Load Diff

View File

@ -6,14 +6,14 @@
"scripts": { "scripts": {
"build": "rollup -c", "build": "rollup -c",
"prepublishOnly": "npm run build", "prepublishOnly": "npm run build",
"postpublish": "scripts/deploy.sh", "postpublish": "node scripts/deploy.js",
"testbuild": "rollup -w -c rollup.testconfig.js", "testbuild": "rollup -w -c rollup.testconfig.js",
"dev": "run-p start:dev testbuild", "dev": "run-p start:dev testbuild",
"start:dev": "sirv public --single --dev", "start:dev": "sirv public --single --dev",
"dev:builder": "rollup -cw" "dev:builder": "rollup -cw"
}, },
"devDependencies": { "devDependencies": {
"@budibase/client": "^0.2.5", "@budibase/client": "^0.2.6",
"@rollup/plugin-commonjs": "^11.1.0", "@rollup/plugin-commonjs": "^11.1.0",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"rollup": "^2.11.2", "rollup": "^2.11.2",
@ -31,7 +31,7 @@
"keywords": [ "keywords": [
"svelte" "svelte"
], ],
"version": "0.2.5", "version": "0.2.6",
"license": "MIT", "license": "MIT",
"gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691", "gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691",
"dependencies": { "dependencies": {

View File

@ -0,0 +1,41 @@
const packageJson = require("../package.json")
const { execSync } = require("child_process")
const fs = require("fs")
const TO_SYNC = "dist/"
const BUCKET_LOCATION = "s3://prod-budi-app-assets/assets"
const BASE_PROFILE = "budibase"
const S3_COMP_DIR = "@budibase/standard-components/dist"
const MANIFEST = "componentlibrary-latest.json"
function buildS3Path() {
return `${BUCKET_LOCATION}/componentlibrary-${packageJson.version}/${S3_COMP_DIR}`
}
async function run() {
let profile = process.env.AWS_PROFILE
if (profile == null) {
profile = BASE_PROFILE
}
// basic manifest file describing the latest
fs.writeFileSync(
MANIFEST,
JSON.stringify({
version: packageJson.version,
dir: S3_COMP_DIR,
})
)
execSync(`aws s3 sync ${TO_SYNC} ${buildS3Path()} --profile ${profile}`)
execSync(
`aws s3 cp ${MANIFEST} ${BUCKET_LOCATION}/${MANIFEST} --profile ${profile}`
)
fs.unlinkSync(MANIFEST)
}
run()
.then(() => {
console.log(`Deployment complete, version ${packageJson.version}`)
})
.catch(err => {
console.error(err)
})

View File

@ -1,3 +0,0 @@
#!/usr/bin/env bash
aws s3 sync dist s3://prod-budi-app-assets/assets/componentlibrary/@budibase/standard-components/dist --profile budibase