Merge branch 'feature/app-backups' of github.com:Budibase/budibase into feature/backups-ui
This commit is contained in:
commit
0a6f86197d
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
"packages/*"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/backend-core",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"description": "Budibase backend core libraries used in server and worker",
|
||||
"main": "dist/src/index.js",
|
||||
"types": "dist/src/index.d.ts",
|
||||
|
@ -20,7 +20,7 @@
|
|||
"test:watch": "jest --watchAll"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/types": "2.0.30-alpha.12",
|
||||
"@budibase/types": "2.0.30-alpha.13",
|
||||
"@shopify/jest-koa-mocks": "5.0.1",
|
||||
"@techpass/passport-openidconnect": "0.3.2",
|
||||
"aws-sdk": "2.1030.0",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/bbui",
|
||||
"description": "A UI solution used in the different Budibase projects.",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"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": "2.0.30-alpha.12",
|
||||
"@budibase/string-templates": "2.0.30-alpha.13",
|
||||
"@spectrum-css/actionbutton": "^1.0.1",
|
||||
"@spectrum-css/actiongroup": "^1.0.1",
|
||||
"@spectrum-css/avatar": "^3.0.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/builder",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"license": "GPL-3.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
@ -71,10 +71,10 @@
|
|||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "2.0.30-alpha.12",
|
||||
"@budibase/client": "2.0.30-alpha.12",
|
||||
"@budibase/frontend-core": "2.0.30-alpha.12",
|
||||
"@budibase/string-templates": "2.0.30-alpha.12",
|
||||
"@budibase/bbui": "2.0.30-alpha.13",
|
||||
"@budibase/client": "2.0.30-alpha.13",
|
||||
"@budibase/frontend-core": "2.0.30-alpha.13",
|
||||
"@budibase/string-templates": "2.0.30-alpha.13",
|
||||
"@sentry/browser": "5.19.1",
|
||||
"@spectrum-css/page": "^3.0.1",
|
||||
"@spectrum-css/vars": "^3.0.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/cli",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"description": "Budibase CLI, for developers, self hosting and migrations.",
|
||||
"main": "src/index.js",
|
||||
"bin": {
|
||||
|
@ -26,9 +26,9 @@
|
|||
"outputPath": "build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/backend-core": "2.0.30-alpha.12",
|
||||
"@budibase/string-templates": "2.0.30-alpha.12",
|
||||
"@budibase/types": "2.0.30-alpha.12",
|
||||
"@budibase/backend-core": "2.0.30-alpha.13",
|
||||
"@budibase/string-templates": "2.0.30-alpha.13",
|
||||
"@budibase/types": "2.0.30-alpha.13",
|
||||
"axios": "0.21.2",
|
||||
"chalk": "4.1.0",
|
||||
"cli-progress": "3.11.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/client",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"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": "2.0.30-alpha.12",
|
||||
"@budibase/frontend-core": "2.0.30-alpha.12",
|
||||
"@budibase/string-templates": "2.0.30-alpha.12",
|
||||
"@budibase/bbui": "2.0.30-alpha.13",
|
||||
"@budibase/frontend-core": "2.0.30-alpha.13",
|
||||
"@budibase/string-templates": "2.0.30-alpha.13",
|
||||
"@spectrum-css/button": "^3.0.3",
|
||||
"@spectrum-css/card": "^3.0.3",
|
||||
"@spectrum-css/divider": "^1.0.3",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@budibase/frontend-core",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"description": "Budibase frontend core libraries used in builder and client",
|
||||
"author": "Budibase",
|
||||
"license": "MPL-2.0",
|
||||
"svelte": "src/index.js",
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "2.0.30-alpha.12",
|
||||
"@budibase/bbui": "2.0.30-alpha.13",
|
||||
"lodash": "^4.17.21",
|
||||
"svelte": "^3.46.2"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/sdk",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"description": "Budibase Public API SDK",
|
||||
"author": "Budibase",
|
||||
"license": "MPL-2.0",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/server",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"description": "Budibase Web Server",
|
||||
"main": "src/index.ts",
|
||||
"repository": {
|
||||
|
@ -77,11 +77,11 @@
|
|||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@apidevtools/swagger-parser": "10.0.3",
|
||||
"@budibase/backend-core": "2.0.30-alpha.12",
|
||||
"@budibase/client": "2.0.30-alpha.12",
|
||||
"@budibase/pro": "2.0.30-alpha.12",
|
||||
"@budibase/string-templates": "2.0.30-alpha.12",
|
||||
"@budibase/types": "2.0.30-alpha.12",
|
||||
"@budibase/backend-core": "2.0.30-alpha.13",
|
||||
"@budibase/client": "2.0.30-alpha.13",
|
||||
"@budibase/pro": "2.0.30-alpha.13",
|
||||
"@budibase/string-templates": "2.0.30-alpha.13",
|
||||
"@budibase/types": "2.0.30-alpha.13",
|
||||
"@bull-board/api": "3.7.0",
|
||||
"@bull-board/koa": "3.9.4",
|
||||
"@elastic/elasticsearch": "7.10.0",
|
||||
|
|
|
@ -38,6 +38,7 @@ import {
|
|||
import { watch } from "./watch"
|
||||
import { initialise as initialiseWebsockets } from "./websocket"
|
||||
import sdk from "./sdk"
|
||||
import * as pro from "@budibase/pro"
|
||||
|
||||
const app = new Koa()
|
||||
|
||||
|
@ -103,13 +104,25 @@ server.on("close", async () => {
|
|||
}
|
||||
})
|
||||
|
||||
const initPro = async () => {
|
||||
await pro.init({
|
||||
backups: {
|
||||
processing: {
|
||||
exportAppFn: sdk.backups.exportApp,
|
||||
importAppFn: sdk.backups.importApp,
|
||||
statsFn: sdk.backups.calculateBackupStats,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = server.listen(env.PORT || 0, async () => {
|
||||
console.log(`Budibase running on ${JSON.stringify(server.address())}`)
|
||||
env._set("PORT", server.address().port)
|
||||
eventEmitter.emitPort(env.PORT)
|
||||
fileSystem.init()
|
||||
await redis.init()
|
||||
await sdk.backups.init()
|
||||
await initPro()
|
||||
|
||||
// run migrations on startup if not done via http
|
||||
// not recommended in a clustered environment
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
import { backups } from "@budibase/pro"
|
||||
import { db as dbCore, objectStore, tenancy } from "@budibase/backend-core"
|
||||
import {
|
||||
AppBackupQueueData,
|
||||
AppBackupStatus,
|
||||
AppBackupTrigger,
|
||||
AppBackupType,
|
||||
} from "@budibase/types"
|
||||
import { exportApp } from "./exports"
|
||||
import { importApp } from "./imports"
|
||||
import { calculateBackupStats } from "./statistics"
|
||||
import { Job } from "bull"
|
||||
import fs from "fs"
|
||||
import env from "../../../environment"
|
||||
|
||||
type BackupOpts = {
|
||||
doc?: { id: string; rev: string }
|
||||
createdBy?: string
|
||||
}
|
||||
|
||||
async function removeExistingApp(devId: string) {
|
||||
const devDb = dbCore.dangerousGetDB(devId, { skip_setup: true })
|
||||
await devDb.destroy()
|
||||
}
|
||||
|
||||
async function runBackup(
|
||||
name: string,
|
||||
trigger: AppBackupTrigger,
|
||||
tenantId: string,
|
||||
appId: string,
|
||||
opts?: BackupOpts
|
||||
) {
|
||||
const devAppId = dbCore.getDevAppID(appId),
|
||||
prodAppId = dbCore.getProdAppID(appId)
|
||||
const timestamp = new Date().toISOString()
|
||||
const tarPath = await exportApp(devAppId, { tar: true })
|
||||
const contents = await calculateBackupStats(devAppId)
|
||||
let filename = `${prodAppId}/backup-${timestamp}.tar.gz`
|
||||
// add the tenant to the bucket path if backing up within a multi-tenant environment
|
||||
if (env.MULTI_TENANCY) {
|
||||
filename = `${tenantId}/${filename}`
|
||||
}
|
||||
const bucket = objectStore.ObjectStoreBuckets.BACKUPS
|
||||
await objectStore.upload({
|
||||
path: tarPath,
|
||||
type: "application/gzip",
|
||||
bucket,
|
||||
filename,
|
||||
metadata: {
|
||||
name,
|
||||
trigger,
|
||||
timestamp,
|
||||
appId: prodAppId,
|
||||
},
|
||||
})
|
||||
if (opts?.doc) {
|
||||
await backups.updateBackupStatus(
|
||||
opts.doc.id,
|
||||
opts.doc.rev,
|
||||
AppBackupStatus.COMPLETE,
|
||||
contents,
|
||||
filename
|
||||
)
|
||||
} else {
|
||||
await backups.storeAppBackupMetadata(
|
||||
{
|
||||
appId: prodAppId,
|
||||
timestamp,
|
||||
name,
|
||||
trigger,
|
||||
type: AppBackupType.BACKUP,
|
||||
status: AppBackupStatus.COMPLETE,
|
||||
contents,
|
||||
createdBy: opts?.createdBy,
|
||||
},
|
||||
{ filename }
|
||||
)
|
||||
}
|
||||
// clear up the tarball after uploading it
|
||||
fs.rmSync(tarPath)
|
||||
}
|
||||
|
||||
async function importProcessor(job: Job) {
|
||||
const data: AppBackupQueueData = job.data
|
||||
const appId = data.appId,
|
||||
backupId = data.import!.backupId,
|
||||
nameForBackup = data.import!.nameForBackup,
|
||||
createdBy = data.import!.createdBy
|
||||
const tenantId = tenancy.getTenantIDFromAppID(appId) as string
|
||||
tenancy.doInTenant(tenantId, async () => {
|
||||
const devAppId = dbCore.getDevAppID(appId)
|
||||
const { rev } = await backups.updateRestoreStatus(
|
||||
data.docId,
|
||||
data.docRev,
|
||||
AppBackupStatus.PENDING
|
||||
)
|
||||
// initially export the current state to disk - incase something goes wrong
|
||||
await runBackup(
|
||||
nameForBackup,
|
||||
AppBackupTrigger.RESTORING,
|
||||
tenantId,
|
||||
appId,
|
||||
{ createdBy }
|
||||
)
|
||||
// get the backup ready on disk
|
||||
const { path } = await backups.downloadAppBackup(backupId)
|
||||
// start by removing app database and contents of bucket - which will be updated
|
||||
await removeExistingApp(devAppId)
|
||||
let status = AppBackupStatus.COMPLETE
|
||||
try {
|
||||
await importApp(devAppId, dbCore.dangerousGetDB(devAppId), {
|
||||
file: {
|
||||
type: "application/gzip",
|
||||
path,
|
||||
},
|
||||
key: path,
|
||||
})
|
||||
} catch (err) {
|
||||
status = AppBackupStatus.FAILED
|
||||
}
|
||||
await backups.updateRestoreStatus(data.docId, rev, status)
|
||||
})
|
||||
}
|
||||
|
||||
async function exportProcessor(job: Job) {
|
||||
const data: AppBackupQueueData = job.data
|
||||
const appId = data.appId,
|
||||
trigger = data.export!.trigger,
|
||||
name = data.export!.name || `${trigger} - backup`
|
||||
const tenantId = tenancy.getTenantIDFromAppID(appId) as string
|
||||
await tenancy.doInTenant(tenantId, async () => {
|
||||
const { rev } = await backups.updateBackupStatus(
|
||||
data.docId,
|
||||
data.docRev,
|
||||
AppBackupStatus.PENDING
|
||||
)
|
||||
return runBackup(name, trigger, tenantId, appId, {
|
||||
doc: { id: data.docId, rev },
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function init() {
|
||||
await backups.addAppBackupProcessors(importProcessor, exportProcessor)
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
import * as exportApps from "./exports"
|
||||
import * as importApps from "./imports"
|
||||
import * as backup from "./backup"
|
||||
import * as statistics from "./statistics"
|
||||
|
||||
export default {
|
||||
...exportApps,
|
||||
...importApps,
|
||||
...backup,
|
||||
...statistics,
|
||||
}
|
||||
|
|
|
@ -1094,12 +1094,12 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@budibase/backend-core@2.0.30-alpha.12":
|
||||
version "2.0.30-alpha.12"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.0.30-alpha.12.tgz#adeb3e3f043c7b85a1a4aab3d3e33832d1ab8dfd"
|
||||
integrity sha512-e/+tvvn1rcLTw/D/OlL9HYV1hw87x2mgofCV5Y1th6r1Tvum7Nr7revcU8CQIpVOc+iz6Eg1vAbMjqDsGr5YUw==
|
||||
"@budibase/backend-core@2.0.30-alpha.13":
|
||||
version "2.0.30-alpha.13"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.0.30-alpha.13.tgz#d32384e136bb458b3ae66435dcb1b73ea1dd371c"
|
||||
integrity sha512-Jp5H84L68ru+8kSLFe/ysYncgW0LpJsSY1HBpXD/QJ9a/3/weDvOFfDUddq547B18ZclOGdEDt7USdqshiwxJA==
|
||||
dependencies:
|
||||
"@budibase/types" "2.0.30-alpha.12"
|
||||
"@budibase/types" "2.0.30-alpha.13"
|
||||
"@shopify/jest-koa-mocks" "5.0.1"
|
||||
"@techpass/passport-openidconnect" "0.3.2"
|
||||
aws-sdk "2.1030.0"
|
||||
|
@ -1180,13 +1180,13 @@
|
|||
svelte-flatpickr "^3.2.3"
|
||||
svelte-portal "^1.0.0"
|
||||
|
||||
"@budibase/pro@2.0.30-alpha.12":
|
||||
version "2.0.30-alpha.12"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.0.30-alpha.12.tgz#52a26671aad4248fa2a6482a262f07c3f8154b7b"
|
||||
integrity sha512-qp/plMQCpCabfDGeKZlOL74epNFzH1leZX7K/cqGwos0kYSElg6zPv/BayMRgID0oxllvuDq5M/fllXtF1QMig==
|
||||
"@budibase/pro@2.0.30-alpha.13":
|
||||
version "2.0.30-alpha.13"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.0.30-alpha.13.tgz#64d2536a098c5c46ae20ff2dff4740a7e88e2051"
|
||||
integrity sha512-uxK5Zo6ZBxw82ZZrz1E2xXm7CBz/TB3VPnBHy5b2dQgEgshEbAxnxwzO1LiFmyb/dc62W1emO/lFIfhmp7tqtA==
|
||||
dependencies:
|
||||
"@budibase/backend-core" "2.0.30-alpha.12"
|
||||
"@budibase/types" "2.0.30-alpha.12"
|
||||
"@budibase/backend-core" "2.0.30-alpha.13"
|
||||
"@budibase/types" "2.0.30-alpha.13"
|
||||
"@koa/router" "8.0.8"
|
||||
joi "17.6.0"
|
||||
node-fetch "^2.6.1"
|
||||
|
@ -1209,10 +1209,10 @@
|
|||
svelte-apexcharts "^1.0.2"
|
||||
svelte-flatpickr "^3.1.0"
|
||||
|
||||
"@budibase/types@2.0.30-alpha.12":
|
||||
version "2.0.30-alpha.12"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.30-alpha.12.tgz#90912b6f6731d67f135787bc5cdeec562b30e336"
|
||||
integrity sha512-PFO8BgScyaesA060ickUhiJTlKvOVIn6mUtc2rr3jrWZ5OTGGi31+eq+QhVcUS45BWuoEoPc0AhQPn7WtrvRQw==
|
||||
"@budibase/types@2.0.30-alpha.13":
|
||||
version "2.0.30-alpha.13"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.30-alpha.13.tgz#820e1c0e908ead50e76dfdf233f1b64931818ef5"
|
||||
integrity sha512-tiyRl5Y2JFYSM/mJRszGsrp52+FL6O71tZasytn9H9Zenrcdr33eRWSC+RvoUGIXUub3uCoPht8aAC7YXNm/7g==
|
||||
|
||||
"@bull-board/api@3.7.0":
|
||||
version "3.7.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/string-templates",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"description": "Handlebars wrapper for Budibase templating.",
|
||||
"main": "src/index.cjs",
|
||||
"module": "dist/bundle.mjs",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/types",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"description": "Budibase types",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
@ -50,4 +50,6 @@ export interface Table extends Document {
|
|||
relatedFormula?: string[]
|
||||
constrained?: string[]
|
||||
sql?: boolean
|
||||
indexes?: { [key: string]: any }
|
||||
dataImport?: { [key: string]: any }
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/worker",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "2.0.30-alpha.12",
|
||||
"version": "2.0.30-alpha.13",
|
||||
"description": "Budibase background service",
|
||||
"main": "src/index.ts",
|
||||
"repository": {
|
||||
|
@ -36,10 +36,10 @@
|
|||
"author": "Budibase",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"@budibase/backend-core": "2.0.30-alpha.12",
|
||||
"@budibase/pro": "2.0.30-alpha.12",
|
||||
"@budibase/string-templates": "2.0.30-alpha.12",
|
||||
"@budibase/types": "2.0.30-alpha.12",
|
||||
"@budibase/backend-core": "2.0.30-alpha.13",
|
||||
"@budibase/pro": "2.0.30-alpha.13",
|
||||
"@budibase/string-templates": "2.0.30-alpha.13",
|
||||
"@budibase/types": "2.0.30-alpha.13",
|
||||
"@koa/router": "8.0.8",
|
||||
"@sentry/node": "6.17.7",
|
||||
"@techpass/passport-openidconnect": "0.3.2",
|
||||
|
|
|
@ -291,12 +291,12 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@budibase/backend-core@2.0.30-alpha.12":
|
||||
version "2.0.30-alpha.12"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.0.30-alpha.12.tgz#adeb3e3f043c7b85a1a4aab3d3e33832d1ab8dfd"
|
||||
integrity sha512-e/+tvvn1rcLTw/D/OlL9HYV1hw87x2mgofCV5Y1th6r1Tvum7Nr7revcU8CQIpVOc+iz6Eg1vAbMjqDsGr5YUw==
|
||||
"@budibase/backend-core@2.0.30-alpha.13":
|
||||
version "2.0.30-alpha.13"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.0.30-alpha.13.tgz#d32384e136bb458b3ae66435dcb1b73ea1dd371c"
|
||||
integrity sha512-Jp5H84L68ru+8kSLFe/ysYncgW0LpJsSY1HBpXD/QJ9a/3/weDvOFfDUddq547B18ZclOGdEDt7USdqshiwxJA==
|
||||
dependencies:
|
||||
"@budibase/types" "2.0.30-alpha.12"
|
||||
"@budibase/types" "2.0.30-alpha.13"
|
||||
"@shopify/jest-koa-mocks" "5.0.1"
|
||||
"@techpass/passport-openidconnect" "0.3.2"
|
||||
aws-sdk "2.1030.0"
|
||||
|
@ -327,21 +327,21 @@
|
|||
uuid "8.3.2"
|
||||
zlib "1.0.5"
|
||||
|
||||
"@budibase/pro@2.0.30-alpha.12":
|
||||
version "2.0.30-alpha.12"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.0.30-alpha.12.tgz#52a26671aad4248fa2a6482a262f07c3f8154b7b"
|
||||
integrity sha512-qp/plMQCpCabfDGeKZlOL74epNFzH1leZX7K/cqGwos0kYSElg6zPv/BayMRgID0oxllvuDq5M/fllXtF1QMig==
|
||||
"@budibase/pro@2.0.30-alpha.13":
|
||||
version "2.0.30-alpha.13"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.0.30-alpha.13.tgz#64d2536a098c5c46ae20ff2dff4740a7e88e2051"
|
||||
integrity sha512-uxK5Zo6ZBxw82ZZrz1E2xXm7CBz/TB3VPnBHy5b2dQgEgshEbAxnxwzO1LiFmyb/dc62W1emO/lFIfhmp7tqtA==
|
||||
dependencies:
|
||||
"@budibase/backend-core" "2.0.30-alpha.12"
|
||||
"@budibase/types" "2.0.30-alpha.12"
|
||||
"@budibase/backend-core" "2.0.30-alpha.13"
|
||||
"@budibase/types" "2.0.30-alpha.13"
|
||||
"@koa/router" "8.0.8"
|
||||
joi "17.6.0"
|
||||
node-fetch "^2.6.1"
|
||||
|
||||
"@budibase/types@2.0.30-alpha.12":
|
||||
version "2.0.30-alpha.12"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.30-alpha.12.tgz#90912b6f6731d67f135787bc5cdeec562b30e336"
|
||||
integrity sha512-PFO8BgScyaesA060ickUhiJTlKvOVIn6mUtc2rr3jrWZ5OTGGi31+eq+QhVcUS45BWuoEoPc0AhQPn7WtrvRQw==
|
||||
"@budibase/types@2.0.30-alpha.13":
|
||||
version "2.0.30-alpha.13"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.30-alpha.13.tgz#820e1c0e908ead50e76dfdf233f1b64931818ef5"
|
||||
integrity sha512-tiyRl5Y2JFYSM/mJRszGsrp52+FL6O71tZasytn9H9Zenrcdr33eRWSC+RvoUGIXUub3uCoPht8aAC7YXNm/7g==
|
||||
|
||||
"@cspotcode/source-map-consumer@0.8.0":
|
||||
version "0.8.0"
|
||||
|
|
|
@ -6,8 +6,9 @@ import FormData from "form-data"
|
|||
import { RouteConfig } from "../fixtures/types/routing"
|
||||
import { AppPackageResponse } from "../fixtures/types/appPackage"
|
||||
import { DeployConfig } from "../fixtures/types/deploy"
|
||||
import { responseMessage } from "../fixtures/types/responseMessage"
|
||||
|
||||
|
||||
type messageResponse = { message: string }
|
||||
|
||||
export default class AppApi {
|
||||
api: InternalAPIClient
|
||||
|
@ -40,10 +41,12 @@ export default class AppApi {
|
|||
return [response, json]
|
||||
}
|
||||
|
||||
async create(body: any): Promise<[Response, Partial<App>]> {
|
||||
async create(body: any): Promise<Partial<App>> {
|
||||
const response = await this.api.post(`/applications`, { body })
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json._id).toBeDefined()
|
||||
return json
|
||||
}
|
||||
|
||||
async read(id: string): Promise<[Response, Application]> {
|
||||
|
@ -52,7 +55,7 @@ export default class AppApi {
|
|||
return [response, json.data]
|
||||
}
|
||||
|
||||
async sync(appId: string): Promise<[Response, messageResponse]> {
|
||||
async sync(appId: string): Promise<[Response, responseMessage]> {
|
||||
const response = await this.api.post(`/applications/${appId}/sync`)
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
|
@ -70,7 +73,7 @@ export default class AppApi {
|
|||
return [response, json]
|
||||
}
|
||||
|
||||
async revert(appId: string): Promise<[Response, messageResponse]> {
|
||||
async revert(appId: string): Promise<[Response, responseMessage]> {
|
||||
const response = await this.api.post(`/dev/${appId}/revert`)
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import ApplicationApi from "./applications"
|
||||
import AuthApi from "./auth"
|
||||
import InternalAPIClient from "./InternalAPIClient"
|
||||
import TablesApi from "./tables"
|
||||
import RowApi from "./rows"
|
||||
import ScreenApi from "./screens"
|
||||
|
||||
export default class TestConfiguration<T> {
|
||||
|
@ -8,9 +10,13 @@ export default class TestConfiguration<T> {
|
|||
auth: AuthApi
|
||||
screen: ScreenApi
|
||||
context: T
|
||||
tables: TablesApi
|
||||
rows: RowApi
|
||||
|
||||
constructor(apiClient: InternalAPIClient) {
|
||||
this.applications = new ApplicationApi(apiClient)
|
||||
this.tables = new TablesApi(apiClient)
|
||||
this.rows = new RowApi(apiClient)
|
||||
this.auth = new AuthApi(apiClient)
|
||||
this.screen = new ScreenApi(apiClient)
|
||||
this.context = <T>{}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import { Response } from "node-fetch"
|
||||
import { Row } from "@budibase/types"
|
||||
import InternalAPIClient from "./InternalAPIClient"
|
||||
|
||||
export default class RowsApi {
|
||||
api: InternalAPIClient
|
||||
|
||||
constructor(apiClient: InternalAPIClient) {
|
||||
this.api = apiClient
|
||||
}
|
||||
|
||||
async getAll(tableId: string): Promise<[Response, Row[]]> {
|
||||
const response = await this.api.get(`/${tableId}/rows`)
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
async add(tableId: string, body: any): Promise<[Response, Row]> {
|
||||
const response = await this.api.post(`/${tableId}/rows`, { body })
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async delete(tableId: string, body: any): Promise<[Response, Row[]]> {
|
||||
const response = await this.api.del(`/${tableId}/rows/`, { body })
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
import { Response } from "node-fetch"
|
||||
import { Table } from "@budibase/types"
|
||||
import InternalAPIClient from "./InternalAPIClient"
|
||||
import { responseMessage } from "../fixtures/types/responseMessage"
|
||||
|
||||
|
||||
export default class TablesApi {
|
||||
api: InternalAPIClient
|
||||
|
||||
constructor(apiClient: InternalAPIClient) {
|
||||
this.api = apiClient
|
||||
}
|
||||
|
||||
async getAll(expectedNumber: Number): Promise<[Response, Table[]]> {
|
||||
const response = await this.api.get(`/tables`)
|
||||
const json = await response.json()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(json.length).toBe(expectedNumber)
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async getTableById(id: string): Promise<[Response, Table]> {
|
||||
const response = await this.api.get(`/tables/${id}`)
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async save(body: any): Promise<[Response, Table]> {
|
||||
const response = await this.api.post(`/tables`, { body })
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
async delete(id: string, revId: string): Promise<[Response, responseMessage]> {
|
||||
const response = await this.api.del(`/tables/${id}/${revId}`)
|
||||
const json = await response.json()
|
||||
return [response, json]
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
import { Row } from "@budibase/types"
|
||||
|
||||
export const generateNewRowForTable = (tableId: string): Row => {
|
||||
return {
|
||||
TestColumn: "TestRow",
|
||||
tableId: tableId
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
import { Table } from "@budibase/types"
|
||||
|
||||
export const generateTable = (): Table => {
|
||||
return {
|
||||
name: "Test Table",
|
||||
schema: {},
|
||||
sourceId: "bb_internal",
|
||||
type: "internal",
|
||||
dataImport: {
|
||||
valid: true,
|
||||
schema: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const generateNewColumnForTable = (tableData: any): Table => {
|
||||
const newColumn = tableData
|
||||
newColumn.schema = {
|
||||
TestColumn: {
|
||||
type: "string",
|
||||
name: "TestColumn",
|
||||
constraints: {
|
||||
presence: { allowEmpty: false },
|
||||
length: { maximum: null },
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
newColumn.indexes = {
|
||||
0: "TestColumn"
|
||||
}
|
||||
newColumn.updatedAt = new Date().toISOString()
|
||||
return newColumn
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
export interface responseMessage { message: string }
|
|
@ -5,6 +5,8 @@ import InternalAPIClient from "../../../config/internal-api/TestConfiguration/In
|
|||
import generateApp from "../../../config/internal-api/fixtures/applications"
|
||||
import generator from "../../../config/generator"
|
||||
import generateScreen from "../../../config/internal-api/fixtures/screens"
|
||||
import { generateTable, generateNewColumnForTable } from "../../../config/internal-api/fixtures/table"
|
||||
import { generateNewRowForTable } from "../../../config/internal-api/fixtures/rows"
|
||||
|
||||
describe("Internal API - /applications endpoints", () => {
|
||||
const api = new InternalAPIClient()
|
||||
|
@ -40,16 +42,12 @@ describe("Internal API - /applications endpoints", () => {
|
|||
})
|
||||
|
||||
it("POST - Create an application", async () => {
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app._id).toBeDefined()
|
||||
config.applications.create(generateApp())
|
||||
})
|
||||
|
||||
it("POST - Publish application", async () => {
|
||||
// create app
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
const app = await config.applications.create(generateApp())
|
||||
|
||||
// publish app
|
||||
config.applications.api.appId = app.appId
|
||||
|
@ -65,9 +63,7 @@ describe("Internal API - /applications endpoints", () => {
|
|||
it("POST - Create an application from a template, publish and check it renders", async () => {
|
||||
// create the app
|
||||
const appName = generator.word()
|
||||
const [response, app] = await createAppFromTemplate()
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
const app = await createAppFromTemplate()
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// check preview renders
|
||||
|
@ -87,9 +83,7 @@ describe("Internal API - /applications endpoints", () => {
|
|||
})
|
||||
|
||||
it("POST - Sync application before deployment", async () => {
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
const [syncResponse, sync] = await config.applications.sync(
|
||||
|
@ -102,9 +96,7 @@ describe("Internal API - /applications endpoints", () => {
|
|||
})
|
||||
|
||||
it("POST - Sync application after deployment", async () => {
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// publish app
|
||||
|
@ -120,15 +112,14 @@ describe("Internal API - /applications endpoints", () => {
|
|||
})
|
||||
|
||||
it("PUT - Update an application", async () => {
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
const app = await config.applications.create(generateApp())
|
||||
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
const [updateResponse, updatedApp] = await config.applications.update(
|
||||
<string>app.appId,
|
||||
{
|
||||
name: generator.word(),
|
||||
name: generator.word()
|
||||
}
|
||||
)
|
||||
expect(updateResponse).toHaveStatusCode(200)
|
||||
|
@ -136,9 +127,7 @@ describe("Internal API - /applications endpoints", () => {
|
|||
})
|
||||
|
||||
it("POST - Revert Changes without changes", async () => {
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
const [revertResponse, revert] = await config.applications.revert(
|
||||
|
@ -152,9 +141,7 @@ describe("Internal API - /applications endpoints", () => {
|
|||
})
|
||||
|
||||
it("POST - Revert Changes", async () => {
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
const app = await config.applications.create(generateApp())
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// publish app
|
||||
|
@ -185,11 +172,72 @@ describe("Internal API - /applications endpoints", () => {
|
|||
})
|
||||
|
||||
it("DELETE - Delete an application", async () => {
|
||||
const [response, app] = await config.applications.create(generateApp())
|
||||
expect(response).toHaveStatusCode(200)
|
||||
expect(app.appId).toBeDefined()
|
||||
const app = await config.applications.create(generateApp())
|
||||
|
||||
const [deleteResponse] = await config.applications.delete(<string>app.appId)
|
||||
expect(deleteResponse).toHaveStatusCode(200)
|
||||
})
|
||||
|
||||
it("Operations on Tables", async () => {
|
||||
// create the app
|
||||
const appName = generator.word()
|
||||
const app = await createAppFromTemplate()
|
||||
config.applications.api.appId = app.appId
|
||||
|
||||
// Get current tables: expect 2 in this template
|
||||
await config.tables.getAll(2)
|
||||
|
||||
// Add new table
|
||||
const [createdTableResponse, createdTableData] = await config.tables.save(generateTable())
|
||||
expect(createdTableResponse).toHaveStatusCode(200)
|
||||
expect(createdTableData._id).toBeDefined()
|
||||
expect(createdTableData._rev).toBeDefined()
|
||||
|
||||
//Table was added
|
||||
await config.tables.getAll(3)
|
||||
|
||||
//Get information about the table
|
||||
const [tableInfoResponse, tableInfo] = await config.tables.getTableById(<string>createdTableData._id)
|
||||
expect(tableInfoResponse).toHaveStatusCode(200)
|
||||
expect(tableInfo._id).toEqual(createdTableData._id)
|
||||
|
||||
//Add Column to table
|
||||
const newColumn = generateNewColumnForTable(createdTableData)
|
||||
const [addColumnResponse, addColumnData] = await config.tables.save(newColumn)
|
||||
expect(addColumnResponse).toHaveStatusCode(200)
|
||||
expect(addColumnData._id).toEqual(createdTableData._id)
|
||||
expect(addColumnData.schema.TestColumn).toBeDefined()
|
||||
|
||||
//Add Row to table
|
||||
const newRow = generateNewRowForTable(<string>addColumnData._id)
|
||||
const [addRowResponse, addRowData] = await config.rows.add(<string>addColumnData._id, newRow)
|
||||
console.log(addRowData)
|
||||
expect(addRowResponse).toHaveStatusCode(200)
|
||||
expect(addRowData._id).toBeDefined()
|
||||
expect(addRowData._rev).toBeDefined()
|
||||
expect(addRowData.tableId).toEqual(addColumnData._id)
|
||||
|
||||
//Get Row from table
|
||||
const [getRowResponse, getRowData] = await config.rows.getAll(<string>addColumnData._id)
|
||||
expect(getRowResponse).toHaveStatusCode(200)
|
||||
expect(getRowData.length).toEqual(1)
|
||||
|
||||
//Delete Row from table
|
||||
const rowToDelete = {
|
||||
rows: [
|
||||
getRowData[0]
|
||||
]
|
||||
}
|
||||
const [deleteRowResponse, deleteRowData] = await config.rows.delete(<string>addColumnData._id, rowToDelete)
|
||||
expect(deleteRowResponse).toHaveStatusCode(200)
|
||||
expect(deleteRowData[0]._id).toEqual(getRowData[0]._id)
|
||||
|
||||
//Delete the table
|
||||
const [deleteTableResponse, deleteTable] = await config.tables.delete(<string>addColumnData._id, <string>addColumnData._rev)
|
||||
expect(deleteTableResponse).toHaveStatusCode(200)
|
||||
expect(deleteTable.message).toEqual(`Table ${createdTableData._id} deleted.`)
|
||||
|
||||
//Table was deleted
|
||||
await config.tables.getAll(2)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -20,9 +20,7 @@ describe("Internal API - /screens endpoints", () => {
|
|||
|
||||
it("POST - Create a screen with each role type", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(
|
||||
generateApp()
|
||||
)
|
||||
const app = await appConfig.applications.create(generateApp())
|
||||
|
||||
// Create Screen
|
||||
const roleArray = ["BASIC", "POWER", "ADMIN", "PUBLIC"]
|
||||
|
@ -38,9 +36,7 @@ describe("Internal API - /screens endpoints", () => {
|
|||
|
||||
it("GET - Fetch screens", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(
|
||||
generateApp()
|
||||
)
|
||||
const app = await appConfig.applications.create(generateApp())
|
||||
|
||||
// Create Screen
|
||||
appConfig.applications.api.appId = app.appId
|
||||
|
@ -56,9 +52,7 @@ describe("Internal API - /screens endpoints", () => {
|
|||
|
||||
it("DELETE - Delete a screen", async () => {
|
||||
// Create app
|
||||
const [appResponse, app] = await appConfig.applications.create(
|
||||
generateApp()
|
||||
)
|
||||
const app = await appConfig.applications.create(generateApp())
|
||||
|
||||
// Create Screen
|
||||
appConfig.applications.api.appId = app.appId
|
||||
|
|
Loading…
Reference in New Issue