Merge branch 'develop' of github.com:Budibase/budibase into feature/app-backups

This commit is contained in:
mike12345567 2022-10-12 11:59:00 +01:00
commit 7439ade518
36 changed files with 380 additions and 125 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "2.0.24-alpha.3", "version": "2.0.30-alpha.0",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*" "packages/*"

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/backend-core", "name": "@budibase/backend-core",
"version": "2.0.24-alpha.3", "version": "2.0.30-alpha.0",
"description": "Budibase backend core libraries used in server and worker", "description": "Budibase backend core libraries used in server and worker",
"main": "dist/src/index.js", "main": "dist/src/index.js",
"types": "dist/src/index.d.ts", "types": "dist/src/index.d.ts",
@ -20,7 +20,7 @@
"test:watch": "jest --watchAll" "test:watch": "jest --watchAll"
}, },
"dependencies": { "dependencies": {
"@budibase/types": "2.0.24-alpha.3", "@budibase/types": "2.0.30-alpha.0",
"@shopify/jest-koa-mocks": "5.0.1", "@shopify/jest-koa-mocks": "5.0.1",
"@techpass/passport-openidconnect": "0.3.2", "@techpass/passport-openidconnect": "0.3.2",
"aws-sdk": "2.1030.0", "aws-sdk": "2.1030.0",

View File

@ -216,6 +216,9 @@ export = class RedisWrapper {
async bulkGet(keys: string[]) { async bulkGet(keys: string[]) {
const db = this._db const db = this._db
if (keys.length === 0) {
return {}
}
const prefixedKeys = keys.map(key => addDbPrefix(db, key)) const prefixedKeys = keys.map(key => addDbPrefix(db, key))
let response = await this.getClient().mget(prefixedKeys) let response = await this.getClient().mget(prefixedKeys)
if (Array.isArray(response)) { if (Array.isArray(response)) {

View File

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

View File

@ -2,7 +2,7 @@ import filterTests from "../support/filterTests"
const interact = require('../support/interact') const interact = require('../support/interact')
filterTests(['smoke', 'all'], () => { filterTests(['smoke', 'all'], () => {
context("Auto Screens UI", () => { xcontext("Auto Screens UI", () => {
before(() => { before(() => {
cy.login() cy.login()
cy.deleteAllApps() cy.deleteAllApps()

View File

@ -1,7 +1,7 @@
import filterTests from "../../support/filterTests" import filterTests from "../../support/filterTests"
filterTests(["all"], () => { filterTests(["all"], () => {
context("PostgreSQL Datasource Testing", () => { xcontext("PostgreSQL Datasource Testing", () => {
if (Cypress.env("TEST_ENV")) { if (Cypress.env("TEST_ENV")) {
before(() => { before(() => {
cy.login() cy.login()

View File

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

View File

@ -17,12 +17,21 @@
$: selectedRoleId = selectedRole._id $: selectedRoleId = selectedRole._id
$: otherRoles = editableRoles.filter(role => role._id !== selectedRoleId) $: otherRoles = editableRoles.filter(role => role._id !== selectedRoleId)
$: isCreating = selectedRoleId == null || selectedRoleId === "" $: isCreating = selectedRoleId == null || selectedRoleId === ""
$: hasUniqueRoleName = !otherRoles
?.map(role => role.name)
?.includes(selectedRole.name)
$: valid = $: valid =
selectedRole.name && selectedRole.name &&
selectedRole.inherits && selectedRole.inherits &&
selectedRole.permissionId && selectedRole.permissionId &&
!builtInRoles.includes(selectedRole.name) !builtInRoles.includes(selectedRole.name)
$: shouldDisableRoleInput =
builtInRoles.includes(selectedRole.name) &&
selectedRole.name?.toLowerCase() === selectedRoleId?.toLowerCase()
const fetchBasePermissions = async () => { const fetchBasePermissions = async () => {
try { try {
basePermissions = await API.getBasePermissions() basePermissions = await API.getBasePermissions()
@ -99,7 +108,7 @@
title="Edit Roles" title="Edit Roles"
confirmText={isCreating ? "Create" : "Save"} confirmText={isCreating ? "Create" : "Save"}
onConfirm={saveRole} onConfirm={saveRole}
disabled={!valid} disabled={!valid || !hasUniqueRoleName}
> >
{#if errors.length} {#if errors.length}
<ErrorsBox {errors} /> <ErrorsBox {errors} />
@ -119,15 +128,16 @@
<Input <Input
label="Name" label="Name"
bind:value={selectedRole.name} bind:value={selectedRole.name}
disabled={builtInRoles.includes(selectedRole.name)} disabled={shouldDisableRoleInput}
error={!hasUniqueRoleName ? "Select a unique role name." : null}
/> />
<Select <Select
label="Inherits Role" label="Inherits Role"
bind:value={selectedRole.inherits} bind:value={selectedRole.inherits}
options={otherRoles} options={selectedRole._id === "BASIC" ? $roles : otherRoles}
getOptionValue={role => role._id} getOptionValue={role => role._id}
getOptionLabel={role => role.name} getOptionLabel={role => role.name}
disabled={builtInRoles.includes(selectedRole.name)} disabled={shouldDisableRoleInput}
/> />
<Select <Select
label="Base Permissions" label="Base Permissions"
@ -135,11 +145,11 @@
options={basePermissions} options={basePermissions}
getOptionValue={x => x._id} getOptionValue={x => x._id}
getOptionLabel={x => x.name} getOptionLabel={x => x.name}
disabled={builtInRoles.includes(selectedRole.name)} disabled={shouldDisableRoleInput}
/> />
{/if} {/if}
<div slot="footer"> <div slot="footer">
{#if !isCreating} {#if !isCreating && !builtInRoles.includes(selectedRole.name)}
<Button warning on:click={deleteRole}>Delete</Button> <Button warning on:click={deleteRole}>Delete</Button>
{/if} {/if}
</div> </div>

View File

@ -209,27 +209,29 @@
{:else} {:else}
<Body size="S"><i>No tables found.</i></Body> <Body size="S"><i>No tables found.</i></Body>
{/if} {/if}
<Divider /> {#if integration.relationships !== false}
<div class="query-header"> <Divider />
<Heading size="S">Relationships</Heading> <div class="query-header">
<Button primary on:click={() => openRelationshipModal()}> <Heading size="S">Relationships</Heading>
Define relationship <Button primary on:click={() => openRelationshipModal()}>
</Button> Define relationship
</div> </Button>
<Body> </div>
Tell budibase how your tables are related to get even more smart features. <Body>
</Body> Tell budibase how your tables are related to get even more smart features.
{#if relationshipInfo && relationshipInfo.length > 0} </Body>
<Table {#if relationshipInfo && relationshipInfo.length > 0}
on:click={({ detail }) => openRelationshipModal(detail.from, detail.to)} <Table
schema={relationshipSchema} on:click={({ detail }) => openRelationshipModal(detail.from, detail.to)}
data={relationshipInfo} schema={relationshipSchema}
allowEditColumns={false} data={relationshipInfo}
allowEditRows={false} allowEditColumns={false}
allowSelectRows={false} allowEditRows={false}
/> allowSelectRows={false}
{:else} />
<Body size="S"><i>No relationships configured.</i></Body> {:else}
<Body size="S"><i>No relationships configured.</i></Body>
{/if}
{/if} {/if}
<style> <style>

View File

@ -156,8 +156,8 @@
page={$usersFetch.pageNumber + 1} page={$usersFetch.pageNumber + 1}
hasPrevPage={$usersFetch.hasPrevPage} hasPrevPage={$usersFetch.hasPrevPage}
hasNextPage={$usersFetch.hasNextPage} hasNextPage={$usersFetch.hasNextPage}
goToPrevPage={$usersFetch.loading ? null : fetch.prevPage} goToPrevPage={$usersFetch.loading ? null : usersFetch.prevPage}
goToNextPage={$usersFetch.loading ? null : fetch.nextPage} goToNextPage={$usersFetch.loading ? null : usersFetch.nextPage}
/> />
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/cli", "name": "@budibase/cli",
"version": "2.0.24-alpha.3", "version": "2.0.30-alpha.0",
"description": "Budibase CLI, for developers, self hosting and migrations.", "description": "Budibase CLI, for developers, self hosting and migrations.",
"main": "src/index.js", "main": "src/index.js",
"bin": { "bin": {
@ -26,9 +26,9 @@
"outputPath": "build" "outputPath": "build"
}, },
"dependencies": { "dependencies": {
"@budibase/backend-core": "2.0.24-alpha.3", "@budibase/backend-core": "2.0.30-alpha.0",
"@budibase/string-templates": "2.0.24-alpha.3", "@budibase/string-templates": "2.0.30-alpha.0",
"@budibase/types": "2.0.24-alpha.3", "@budibase/types": "2.0.30-alpha.0",
"axios": "0.21.2", "axios": "0.21.2",
"chalk": "4.1.0", "chalk": "4.1.0",
"cli-progress": "3.11.2", "cli-progress": "3.11.2",

View File

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

View File

@ -47,6 +47,9 @@ const createBuilderStore = () => {
duplicateComponent: id => { duplicateComponent: id => {
dispatchEvent("duplicate-component", { id }) dispatchEvent("duplicate-component", { id })
}, },
deleteComponent: id => {
dispatchEvent("delete-component", { id })
},
notifyLoaded: () => { notifyLoaded: () => {
dispatchEvent("preview-loaded") dispatchEvent("preview-loaded")
}, },

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/sdk", "name": "@budibase/sdk",
"version": "2.0.24-alpha.3", "version": "2.0.30-alpha.0",
"description": "Budibase Public API SDK", "description": "Budibase Public API SDK",
"author": "Budibase", "author": "Budibase",
"license": "MPL-2.0", "license": "MPL-2.0",

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/server", "name": "@budibase/server",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "2.0.24-alpha.3", "version": "2.0.30-alpha.0",
"description": "Budibase Web Server", "description": "Budibase Web Server",
"main": "src/index.ts", "main": "src/index.ts",
"repository": { "repository": {
@ -77,11 +77,11 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@apidevtools/swagger-parser": "10.0.3", "@apidevtools/swagger-parser": "10.0.3",
"@budibase/backend-core": "2.0.24-alpha.3", "@budibase/backend-core": "2.0.30-alpha.0",
"@budibase/client": "2.0.24-alpha.3", "@budibase/client": "2.0.30-alpha.0",
"@budibase/pro": "2.0.24-alpha.3", "@budibase/pro": "2.0.30-alpha.0",
"@budibase/string-templates": "2.0.24-alpha.3", "@budibase/string-templates": "2.0.30-alpha.0",
"@budibase/types": "2.0.24-alpha.3", "@budibase/types": "2.0.30-alpha.0",
"@bull-board/api": "3.7.0", "@bull-board/api": "3.7.0",
"@bull-board/koa": "3.9.4", "@bull-board/koa": "3.9.4",
"@elastic/elasticsearch": "7.10.0", "@elastic/elasticsearch": "7.10.0",

View File

@ -103,7 +103,7 @@ exports.revert = async ctx => {
target: appId, target: appId,
}) })
try { try {
if (!env.isCypress()) { if (env.COUCH_DB_URL) {
// in-memory db stalls on rollback // in-memory db stalls on rollback
await replication.rollback() await replication.rollback()
} }

View File

@ -1,17 +1,9 @@
const { getDefinitions } = require("../../integrations") const { getDefinitions } = require("../../integrations")
const { SourceName } = require("@budibase/types")
const googlesheets = require("../../integrations/googlesheets")
const { featureFlags } = require("@budibase/backend-core")
exports.fetch = async function (ctx) { exports.fetch = async function (ctx) {
ctx.status = 200 ctx.status = 200
const defs = await getDefinitions() const defs = await getDefinitions()
// for google sheets integration google verification
if (featureFlags.isEnabled(featureFlags.TenantFeatureFlag.GOOGLE_SHEETS)) {
defs[SourceName.GOOGLE_SHEETS] = googlesheets.schema
}
ctx.body = defs ctx.body = defs
} }

View File

@ -18,6 +18,7 @@ import { Table } from "@budibase/types"
import { quotas } from "@budibase/pro" import { quotas } from "@budibase/pro"
import { isEqual } from "lodash" import { isEqual } from "lodash"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import env from "../../../environment"
function checkAutoColumns(table: Table, oldTable: Table) { function checkAutoColumns(table: Table, oldTable: Table) {
if (!table.schema) { if (!table.schema) {
@ -167,7 +168,7 @@ export async function destroy(ctx: any) {
await db.remove(tableToDelete) await db.remove(tableToDelete)
// remove table search index // remove table search index
if (!isTest()) { if (!isTest() || env.COUCH_DB_URL) {
const currentIndexes = await db.getIndexes() const currentIndexes = await db.getIndexes()
const existingIndex = currentIndexes.indexes.find( const existingIndex = currentIndexes.indexes.find(
(existing: any) => existing.name === `search:${ctx.params.tableId}` (existing: any) => existing.name === `search:${ctx.params.tableId}`

View File

@ -31,6 +31,7 @@ export interface BearerAuthConfig {
export interface RestConfig { export interface RestConfig {
url: string url: string
rejectUnauthorized: boolean
defaultHeaders: { defaultHeaders: {
[key: string]: any [key: string]: any
} }

View File

@ -8,6 +8,7 @@ function runServer() {
checkDevelopmentEnvironment() checkDevelopmentEnvironment()
fixPath() fixPath()
// this will setup http and https proxies form env variables // this will setup http and https proxies form env variables
process.env.GLOBAL_AGENT_FORCE_GLOBAL_AGENT = "false"
bootstrap() bootstrap()
require("./app") require("./app")
} }

View File

@ -33,6 +33,7 @@ const DEFINITIONS: { [key: string]: Integration } = {
[SourceName.ARANGODB]: arangodb.schema, [SourceName.ARANGODB]: arangodb.schema,
[SourceName.REST]: rest.schema, [SourceName.REST]: rest.schema,
[SourceName.FIRESTORE]: firebase.schema, [SourceName.FIRESTORE]: firebase.schema,
[SourceName.GOOGLE_SHEETS]: googlesheets.schema,
[SourceName.REDIS]: redis.schema, [SourceName.REDIS]: redis.schema,
[SourceName.SNOWFLAKE]: snowflake.schema, [SourceName.SNOWFLAKE]: snowflake.schema,
} }
@ -66,10 +67,6 @@ if (
INTEGRATIONS[SourceName.ORACLE] = oracle.integration INTEGRATIONS[SourceName.ORACLE] = oracle.integration
} }
if (environment.SELF_HOSTED) {
DEFINITIONS[SourceName.GOOGLE_SHEETS] = googlesheets.schema
}
module.exports = { module.exports = {
getDefinitions: async () => { getDefinitions: async () => {
const pluginSchemas: { [key: string]: Integration } = {} const pluginSchemas: { [key: string]: Integration } = {}

View File

@ -14,6 +14,7 @@ import {
BearerAuthConfig, BearerAuthConfig,
} from "../definitions/datasource" } from "../definitions/datasource"
import { get } from "lodash" import { get } from "lodash"
import * as https from "https"
import qs from "querystring" import qs from "querystring"
const fetch = require("node-fetch") const fetch = require("node-fetch")
const { formatBytes } = require("../utilities") const { formatBytes } = require("../utilities")
@ -76,6 +77,11 @@ const SCHEMA: Integration = {
required: false, required: false,
default: {}, default: {},
}, },
rejectUnauthorized: {
type: DatasourceFieldType.BOOLEAN,
default: true,
required: false,
},
legacyHttpParser: { legacyHttpParser: {
display: "Legacy HTTP Support", display: "Legacy HTTP Support",
type: DatasourceFieldType.BOOLEAN, type: DatasourceFieldType.BOOLEAN,
@ -218,8 +224,12 @@ class RestIntegration implements IntegrationBase {
} }
} }
// make sure the query string is fully encoded if (queryString) {
const main = `${path}?${qs.encode(qs.decode(queryString))}` // make sure the query string is fully encoded
queryString = "?" + qs.encode(qs.decode(queryString))
}
const main = `${path}${queryString}`
let complete = main let complete = main
if (this.config.url && !main.startsWith("http")) { if (this.config.url && !main.startsWith("http")) {
complete = !this.config.url ? main : `${this.config.url}/${main}` complete = !this.config.url ? main : `${this.config.url}/${main}`
@ -381,6 +391,12 @@ class RestIntegration implements IntegrationBase {
paginationValues paginationValues
) )
if (this.config.rejectUnauthorized == false) {
input.agent = new https.Agent({
rejectUnauthorized: false,
})
}
if (this.config.legacyHttpParser) { if (this.config.legacyHttpParser) {
// https://github.com/nodejs/node/issues/43798 // https://github.com/nodejs/node/issues/43798
input.extraHttpOptions = { insecureHTTPParser: true } input.extraHttpOptions = { insecureHTTPParser: true }

View File

@ -256,7 +256,7 @@ describe("REST Integration", () => {
authConfigId: "c59c14bd1898a43baa08da68959b24686", authConfigId: "c59c14bd1898a43baa08da68959b24686",
} }
await config.integration.read(query) await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/`, {
method: "GET", method: "GET",
headers: { headers: {
Authorization: "Basic dXNlcjpwYXNzd29yZA==", Authorization: "Basic dXNlcjpwYXNzd29yZA==",
@ -269,7 +269,7 @@ describe("REST Integration", () => {
authConfigId: "0d91d732f34e4befabeff50b392a8ff3", authConfigId: "0d91d732f34e4befabeff50b392a8ff3",
} }
await config.integration.read(query) await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/`, {
method: "GET", method: "GET",
headers: { headers: {
Authorization: "Bearer mytoken", Authorization: "Bearer mytoken",
@ -327,7 +327,7 @@ describe("REST Integration", () => {
}, },
} }
await config.integration.create(query) await config.integration.create(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
body: JSON.stringify({ body: JSON.stringify({
[pageParam]: pageValue, [pageParam]: pageValue,
[sizeParam]: sizeValue, [sizeParam]: sizeValue,
@ -359,7 +359,7 @@ describe("REST Integration", () => {
}, },
} }
await config.integration.create(query) await config.integration.create(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
body: expect.any(FormData), body: expect.any(FormData),
headers: {}, headers: {},
method: "POST", method: "POST",
@ -390,7 +390,7 @@ describe("REST Integration", () => {
}, },
} }
await config.integration.create(query) await config.integration.create(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
body: expect.any(URLSearchParams), body: expect.any(URLSearchParams),
headers: {}, headers: {},
method: "POST", method: "POST",
@ -456,7 +456,7 @@ describe("REST Integration", () => {
}, },
} }
const res = await config.integration.create(query) const res = await config.integration.create(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
body: JSON.stringify({ body: JSON.stringify({
[pageParam]: pageValue, [pageParam]: pageValue,
[sizeParam]: sizeValue, [sizeParam]: sizeValue,
@ -490,7 +490,7 @@ describe("REST Integration", () => {
}, },
} }
const res = await config.integration.create(query) const res = await config.integration.create(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
body: expect.any(FormData), body: expect.any(FormData),
headers: {}, headers: {},
method: "POST", method: "POST",
@ -523,7 +523,7 @@ describe("REST Integration", () => {
}, },
} }
const res = await config.integration.create(query) const res = await config.integration.create(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api`, {
body: expect.any(URLSearchParams), body: expect.any(URLSearchParams),
headers: {}, headers: {},
method: "POST", method: "POST",
@ -563,7 +563,7 @@ describe("REST Integration", () => {
legacyHttpParser: true, legacyHttpParser: true,
}) })
await config.integration.read({}) await config.integration.read({})
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/`, {
method: "GET", method: "GET",
headers: {}, headers: {},
extraHttpOptions: { extraHttpOptions: {

View File

@ -7,14 +7,17 @@ const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
exports.getFullUser = async (ctx, userId) => { exports.getFullUser = async (ctx, userId) => {
const global = await getGlobalUser(userId) const global = await getGlobalUser(userId)
let metadata = {} let metadata = {}
// always prefer the user metadata _id and _rev
delete global._id
delete global._rev
try { try {
// this will throw an error if the db doesn't exist, or there is no appId // this will throw an error if the db doesn't exist, or there is no appId
const db = getAppDB() const db = getAppDB()
metadata = await db.get(userId) metadata = await db.get(userId)
} catch (err) { } catch (err) {
// it is fine if there is no user metadata, just remove global db info // it is fine if there is no user metadata yet
delete global._id
delete global._rev
} }
delete metadata.csrfToken delete metadata.csrfToken
return { return {

View File

@ -1094,12 +1094,12 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.0.24-alpha.3": "@budibase/backend-core@2.0.30-alpha.0":
version "2.0.24-alpha.3" version "2.0.30-alpha.0"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.0.24-alpha.3.tgz#49a92082d1ca6bed0eb82519a6c02d7d14ead751" resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.0.30-alpha.0.tgz#aa9277ec26da51f8396fe047ebab39a0dff69c93"
integrity sha512-Zm/ddRDMzMuXCoEXZa0CzA/B1SnpQ+yjZCNAPH7Y4yYTIKfeE/DQ6COLlUixQxVMAUN1L5+GXML+px6fRigA5w== integrity sha512-6+KHAceEZv1SC0qSA4GTNQBAlF1wnr9jfl85D5Tq1O2caD4J7drkIz8D6e0/DVv8zccHT+aUA7hy7YhKxbHAUA==
dependencies: dependencies:
"@budibase/types" "2.0.24-alpha.3" "@budibase/types" "2.0.30-alpha.0"
"@shopify/jest-koa-mocks" "5.0.1" "@shopify/jest-koa-mocks" "5.0.1"
"@techpass/passport-openidconnect" "0.3.2" "@techpass/passport-openidconnect" "0.3.2"
aws-sdk "2.1030.0" aws-sdk "2.1030.0"
@ -1180,13 +1180,13 @@
svelte-flatpickr "^3.2.3" svelte-flatpickr "^3.2.3"
svelte-portal "^1.0.0" svelte-portal "^1.0.0"
"@budibase/pro@2.0.24-alpha.3": "@budibase/pro@2.0.30-alpha.0":
version "2.0.24-alpha.3" version "2.0.30-alpha.0"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.0.24-alpha.3.tgz#16605029663b07d0e3bcf0c08893878b542b6752" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.0.30-alpha.0.tgz#6f0d9e45bc458e0e423280355c1a339f3143da47"
integrity sha512-gBdqJzvtEAMJkhB2YTAyVYKoCANA25F1wT/K7kQtTOy5LrjDmcXah7CZoetfZQGbsKxUYEAZwJzxLSXmIxvWmQ== integrity sha512-8PFdiIHT7wUusa1Gi+KvcpLaJdBAtnAK6bfYGayasnrS9OIasfIBAMgzXRONMAGMvY7PZz84psZVimXSkW7EEA==
dependencies: dependencies:
"@budibase/backend-core" "2.0.24-alpha.3" "@budibase/backend-core" "2.0.30-alpha.0"
"@budibase/types" "2.0.24-alpha.3" "@budibase/types" "2.0.30-alpha.0"
"@koa/router" "8.0.8" "@koa/router" "8.0.8"
joi "17.6.0" joi "17.6.0"
node-fetch "^2.6.1" node-fetch "^2.6.1"
@ -1209,10 +1209,10 @@
svelte-apexcharts "^1.0.2" svelte-apexcharts "^1.0.2"
svelte-flatpickr "^3.1.0" svelte-flatpickr "^3.1.0"
"@budibase/types@2.0.24-alpha.3": "@budibase/types@2.0.30-alpha.0":
version "2.0.24-alpha.3" version "2.0.30-alpha.0"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.24-alpha.3.tgz#84eec5f991a2cfaf48d968b07a075b343f847289" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.30-alpha.0.tgz#fb5e80870b00850601785f1102f64bd22339f4e9"
integrity sha512-f9PhtqzmqPI76ITXttuvxsvqMUJtkrDYf/4MHlI2v5ssNL9r0C/hbQEXllff3L3JqViEHWxkKFmfvfnDTV8rRQ== integrity sha512-i9c02crPzZPRzn+RXwn2f4H4WCLWhC7HlsiXH2w4Ngk7PJvtcR9Jn7mKBKVcXM/9PAK6d0vWIQidA8XuU0CpZA==
"@bull-board/api@3.7.0": "@bull-board/api@3.7.0":
version "3.7.0" version "3.7.0"

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/types", "name": "@budibase/types",
"version": "2.0.24-alpha.3", "version": "2.0.30-alpha.0",
"description": "Budibase types", "description": "Budibase types",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/worker", "name": "@budibase/worker",
"email": "hi@budibase.com", "email": "hi@budibase.com",
"version": "2.0.24-alpha.3", "version": "2.0.30-alpha.0",
"description": "Budibase background service", "description": "Budibase background service",
"main": "src/index.ts", "main": "src/index.ts",
"repository": { "repository": {
@ -36,10 +36,10 @@
"author": "Budibase", "author": "Budibase",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@budibase/backend-core": "2.0.24-alpha.3", "@budibase/backend-core": "2.0.30-alpha.0",
"@budibase/pro": "2.0.24-alpha.3", "@budibase/pro": "2.0.30-alpha.0",
"@budibase/string-templates": "2.0.24-alpha.3", "@budibase/string-templates": "2.0.30-alpha.0",
"@budibase/types": "2.0.24-alpha.3", "@budibase/types": "2.0.30-alpha.0",
"@koa/router": "8.0.8", "@koa/router": "8.0.8",
"@sentry/node": "6.17.7", "@sentry/node": "6.17.7",
"@techpass/passport-openidconnect": "0.3.2", "@techpass/passport-openidconnect": "0.3.2",

View File

@ -291,12 +291,12 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.0.24-alpha.3": "@budibase/backend-core@2.0.30-alpha.0":
version "2.0.24-alpha.3" version "2.0.30-alpha.0"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.0.24-alpha.3.tgz#49a92082d1ca6bed0eb82519a6c02d7d14ead751" resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.0.30-alpha.0.tgz#aa9277ec26da51f8396fe047ebab39a0dff69c93"
integrity sha512-Zm/ddRDMzMuXCoEXZa0CzA/B1SnpQ+yjZCNAPH7Y4yYTIKfeE/DQ6COLlUixQxVMAUN1L5+GXML+px6fRigA5w== integrity sha512-6+KHAceEZv1SC0qSA4GTNQBAlF1wnr9jfl85D5Tq1O2caD4J7drkIz8D6e0/DVv8zccHT+aUA7hy7YhKxbHAUA==
dependencies: dependencies:
"@budibase/types" "2.0.24-alpha.3" "@budibase/types" "2.0.30-alpha.0"
"@shopify/jest-koa-mocks" "5.0.1" "@shopify/jest-koa-mocks" "5.0.1"
"@techpass/passport-openidconnect" "0.3.2" "@techpass/passport-openidconnect" "0.3.2"
aws-sdk "2.1030.0" aws-sdk "2.1030.0"
@ -327,21 +327,21 @@
uuid "8.3.2" uuid "8.3.2"
zlib "1.0.5" zlib "1.0.5"
"@budibase/pro@2.0.24-alpha.3": "@budibase/pro@2.0.30-alpha.0":
version "2.0.24-alpha.3" version "2.0.30-alpha.0"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.0.24-alpha.3.tgz#16605029663b07d0e3bcf0c08893878b542b6752" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.0.30-alpha.0.tgz#6f0d9e45bc458e0e423280355c1a339f3143da47"
integrity sha512-gBdqJzvtEAMJkhB2YTAyVYKoCANA25F1wT/K7kQtTOy5LrjDmcXah7CZoetfZQGbsKxUYEAZwJzxLSXmIxvWmQ== integrity sha512-8PFdiIHT7wUusa1Gi+KvcpLaJdBAtnAK6bfYGayasnrS9OIasfIBAMgzXRONMAGMvY7PZz84psZVimXSkW7EEA==
dependencies: dependencies:
"@budibase/backend-core" "2.0.24-alpha.3" "@budibase/backend-core" "2.0.30-alpha.0"
"@budibase/types" "2.0.24-alpha.3" "@budibase/types" "2.0.30-alpha.0"
"@koa/router" "8.0.8" "@koa/router" "8.0.8"
joi "17.6.0" joi "17.6.0"
node-fetch "^2.6.1" node-fetch "^2.6.1"
"@budibase/types@2.0.24-alpha.3": "@budibase/types@2.0.30-alpha.0":
version "2.0.24-alpha.3" version "2.0.30-alpha.0"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.24-alpha.3.tgz#84eec5f991a2cfaf48d968b07a075b343f847289" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.0.30-alpha.0.tgz#fb5e80870b00850601785f1102f64bd22339f4e9"
integrity sha512-f9PhtqzmqPI76ITXttuvxsvqMUJtkrDYf/4MHlI2v5ssNL9r0C/hbQEXllff3L3JqViEHWxkKFmfvfnDTV8rRQ== integrity sha512-i9c02crPzZPRzn+RXwn2f4H4WCLWhC7HlsiXH2w4Ngk7PJvtcR9Jn7mKBKVcXM/9PAK6d0vWIQidA8XuU0CpZA==
"@cspotcode/source-map-consumer@0.8.0": "@cspotcode/source-map-consumer@0.8.0":
version "0.8.0" version "0.8.0"

View File

@ -3,6 +3,11 @@ import { App } from "@budibase/types"
import { Response } from "node-fetch" import { Response } from "node-fetch"
import InternalAPIClient from "./InternalAPIClient" import InternalAPIClient from "./InternalAPIClient"
import FormData from "form-data" import FormData from "form-data"
import { RouteConfig } from "../fixtures/types/routing"
import { AppPackageResponse } from "../fixtures/types/appPackage"
import { DeployConfig } from "../fixtures/types/deploy"
type messageResponse = { message: string }
export default class AppApi { export default class AppApi {
api: InternalAPIClient api: InternalAPIClient
@ -23,13 +28,13 @@ export default class AppApi {
return [response, Object.keys(json.routes).length > 0] return [response, Object.keys(json.routes).length > 0]
} }
async getAppPackage(appId: string): Promise<[Response, any]> { async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> {
const response = await this.api.get(`/applications/${appId}/appPackage`) const response = await this.api.get(`/applications/${appId}/appPackage`)
const json = await response.json() const json = await response.json()
return [response, json] return [response, json]
} }
async publish(): Promise<[Response, string]> { async publish(): Promise<[Response, DeployConfig]> {
const response = await this.api.post("/deploy") const response = await this.api.post("/deploy")
const json = await response.json() const json = await response.json()
return [response, json] return [response, json]
@ -46,4 +51,52 @@ export default class AppApi {
const json = await response.json() const json = await response.json()
return [response, json.data] return [response, json.data]
} }
async sync(appId: string): Promise<[Response, messageResponse]> {
const response = await this.api.post(`/applications/${appId}/sync`)
const json = await response.json()
return [response, json]
}
async updateClient(
appId: string,
body: any
): Promise<[Response, Application]> {
const response = await this.api.put(
`/applications/${appId}/client/update`,
{ body }
)
const json = await response.json()
return [response, json]
}
async revert(appId: string): Promise<[Response, messageResponse]> {
const response = await this.api.post(`/dev/${appId}/revert`)
const json = await response.json()
return [response, json]
}
async delete(appId: string): Promise<[Response, any]> {
const response = await this.api.del(`/applications/${appId}`)
const json = await response.json()
return [response, json]
}
async update(appId: string, body: any): Promise<[Response, Application]> {
const response = await this.api.put(`/applications/${appId}`, { body })
const json = await response.json()
return [response, json]
}
async addScreentoApp(body: any): Promise<[Response, Application]> {
const response = await this.api.post(`/screens`, { body })
const json = await response.json()
return [response, json]
}
async getRoutes(): Promise<[Response, RouteConfig]> {
const response = await this.api.get(`/routing`)
const json = await response.json()
return [response, json]
}
} }

View File

@ -0,0 +1,34 @@
import generator from "../../generator"
const randomId = generator.guid()
const generateScreen = (): any => ({
showNavigation: true,
width: "Large",
props: {
_id: randomId,
_component: "@budibase/standard-components/container",
_styles: {
normal: {},
hover: {},
active: {},
selected: {},
},
_children: [],
_instanceName: "New Screen",
direction: "column",
hAlign: "stretch",
vAlign: "top",
size: "grow",
gap: "M",
},
routing: {
route: "/test",
roleId: "BASIC",
homeScreen: false,
},
name: randomId,
template: "createFromScratch",
})
export default generateScreen

View File

@ -0,0 +1,9 @@
import { Application } from "@budibase/server/api/controllers/public/mapping/types"
import { Layout } from "@budibase/types"
import { Screen } from "@budibase/types"
// Create type for getAppPackage response
export interface AppPackageResponse {
application: Partial<Application>
layout: Layout
screens: Screen[]
}

View File

@ -0,0 +1,5 @@
export interface DeployConfig {
appUrl: string
status: string
_id: string
}

View File

@ -0,0 +1,17 @@
export interface RouteConfig {
routes: Record<string, Route>
}
export interface Route {
subpaths: Record<string, Subpath>
}
export interface Subpath {
screens: ScreenRouteConfig
}
export interface ScreenRouteConfig {
BASIC?: string
POWER?: string
ADMIN?: string
}

View File

@ -4,6 +4,7 @@ import { db } from "@budibase/backend-core"
import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient"
import generateApp from "../../../config/internal-api/fixtures/applications" import generateApp from "../../../config/internal-api/fixtures/applications"
import generator from "../../../config/generator" import generator from "../../../config/generator"
import generateScreen from "../../../config/internal-api/fixtures/screens"
describe("Internal API - /applications endpoints", () => { describe("Internal API - /applications endpoints", () => {
const api = new InternalAPIClient() const api = new InternalAPIClient()
@ -84,4 +85,111 @@ describe("Internal API - /applications endpoints", () => {
await config.applications.canRender() await config.applications.canRender()
expect(publishedAppRenders).toBe(true) expect(publishedAppRenders).toBe(true)
}) })
it("POST - Sync application before deployment", async () => {
const [response, app] = await config.applications.create(generateApp())
expect(response).toHaveStatusCode(200)
expect(app.appId).toBeDefined()
config.applications.api.appId = app.appId
const [syncResponse, sync] = await config.applications.sync(
<string>app.appId
)
expect(syncResponse).toHaveStatusCode(200)
expect(sync).toEqual({
message: "App sync not required, app not deployed.",
})
})
it("POST - Sync application after deployment", async () => {
const [response, app] = await config.applications.create(generateApp())
expect(response).toHaveStatusCode(200)
expect(app.appId).toBeDefined()
config.applications.api.appId = app.appId
// publish app
await config.applications.publish()
const [syncResponse, sync] = await config.applications.sync(
<string>app.appId
)
expect(syncResponse).toHaveStatusCode(200)
expect(sync).toEqual({
message: "App sync completed successfully.",
})
})
it("PUT - Update an application", async () => {
const [response, app] = await config.applications.create(generateApp())
expect(response).toHaveStatusCode(200)
expect(app.appId).toBeDefined()
config.applications.api.appId = app.appId
const [updateResponse, updatedApp] = await config.applications.update(
<string>app.appId,
{
name: generator.word(),
}
)
expect(updateResponse).toHaveStatusCode(200)
expect(updatedApp.name).not.toEqual(app.name)
})
it("POST - Revert Changes without changes", async () => {
const [response, app] = await config.applications.create(generateApp())
expect(response).toHaveStatusCode(200)
expect(app.appId).toBeDefined()
config.applications.api.appId = app.appId
const [revertResponse, revert] = await config.applications.revert(
<string>app.appId
)
expect(revertResponse).toHaveStatusCode(400)
expect(revert).toEqual({
message: "App has not yet been deployed",
status: 400,
})
})
it("POST - Revert Changes", async () => {
const [response, app] = await config.applications.create(generateApp())
expect(response).toHaveStatusCode(200)
expect(app.appId).toBeDefined()
config.applications.api.appId = app.appId
// publish app
const [publishResponse, publish] = await config.applications.publish()
expect(publishResponse).toHaveStatusCode(200)
expect(publish.status).toEqual("SUCCESS")
// Change/add component to the app
const [screenResponse, screen] = await config.applications.addScreentoApp(
generateScreen()
)
expect(screenResponse).toHaveStatusCode(200)
expect(screen._id).toBeDefined()
// // Revert the app to published state
const [revertResponse, revert] = await config.applications.revert(
<string>app.appId
)
expect(revertResponse).toHaveStatusCode(200)
expect(revert).toEqual({
message: "Reverted changes successfully.",
})
// Check screen is removed
const [routesResponse, routes] = await config.applications.getRoutes()
expect(routesResponse).toHaveStatusCode(200)
expect(routes.routes["/test"]).toBeUndefined()
})
it("DELETE - Delete an application", async () => {
const [response, app] = await config.applications.create(generateApp())
expect(response).toHaveStatusCode(200)
expect(app.appId).toBeDefined()
const [deleteResponse] = await config.applications.delete(<string>app.appId)
expect(deleteResponse).toHaveStatusCode(200)
})
}) })