diff --git a/lerna.json b/lerna.json index 591565b377..e492e58a75 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.0.27-alpha.5", + "version": "1.0.27-alpha.13", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/auth/.gitignore b/packages/backend-core/.gitignore similarity index 100% rename from packages/auth/.gitignore rename to packages/backend-core/.gitignore diff --git a/packages/auth/LICENSE b/packages/backend-core/LICENSE similarity index 100% rename from packages/auth/LICENSE rename to packages/backend-core/LICENSE diff --git a/packages/auth/README.md b/packages/backend-core/README.md similarity index 78% rename from packages/auth/README.md rename to packages/backend-core/README.md index 4c6a474b5b..f36f80f84d 100644 --- a/packages/auth/README.md +++ b/packages/backend-core/README.md @@ -4,7 +4,7 @@ This library contains core functionality, like auth and security features which are shared between backend services. #### Note about top level JS files -For the purposes of being able to do say `require("@budibase/auth/permissions")` we need to +For the purposes of being able to do say `require("@budibase/backend-core/permissions")` we need to specify the exports at the top-level of the module. For these files they should be limited to a single `require` of the file that should diff --git a/packages/auth/accounts.js b/packages/backend-core/accounts.js similarity index 100% rename from packages/auth/accounts.js rename to packages/backend-core/accounts.js diff --git a/packages/backend-core/auth.js b/packages/backend-core/auth.js new file mode 100644 index 0000000000..bbfe3d41dd --- /dev/null +++ b/packages/backend-core/auth.js @@ -0,0 +1 @@ +module.exports = require("./src/auth") diff --git a/packages/auth/cache.js b/packages/backend-core/cache.js similarity index 100% rename from packages/auth/cache.js rename to packages/backend-core/cache.js diff --git a/packages/auth/constants.js b/packages/backend-core/constants.js similarity index 100% rename from packages/auth/constants.js rename to packages/backend-core/constants.js diff --git a/packages/auth/db.js b/packages/backend-core/db.js similarity index 100% rename from packages/auth/db.js rename to packages/backend-core/db.js diff --git a/packages/auth/deprovision.js b/packages/backend-core/deprovision.js similarity index 100% rename from packages/auth/deprovision.js rename to packages/backend-core/deprovision.js diff --git a/packages/backend-core/middleware.js b/packages/backend-core/middleware.js new file mode 100644 index 0000000000..30fec96239 --- /dev/null +++ b/packages/backend-core/middleware.js @@ -0,0 +1 @@ +module.exports = require("./src/middleware") diff --git a/packages/backend-core/objectStore.js b/packages/backend-core/objectStore.js new file mode 100644 index 0000000000..3ee433f224 --- /dev/null +++ b/packages/backend-core/objectStore.js @@ -0,0 +1,4 @@ +module.exports = { + ...require("./src/objectStore"), + ...require("./src/objectStore/utils"), +} diff --git a/packages/auth/package.json b/packages/backend-core/package.json similarity index 87% rename from packages/auth/package.json rename to packages/backend-core/package.json index 058d5fe43d..c358c7f9d4 100644 --- a/packages/auth/package.json +++ b/packages/backend-core/package.json @@ -1,7 +1,7 @@ { - "name": "@budibase/auth", - "version": "1.0.27-alpha.5", - "description": "Authentication middlewares for budibase builder and apps", + "name": "@budibase/backend-core", + "version": "1.0.27-alpha.13", + "description": "Budibase backend core libraries used in server and worker", "main": "src/index.js", "author": "Budibase", "license": "GPL-3.0", diff --git a/packages/auth/permissions.js b/packages/backend-core/permissions.js similarity index 100% rename from packages/auth/permissions.js rename to packages/backend-core/permissions.js diff --git a/packages/auth/redis.js b/packages/backend-core/redis.js similarity index 100% rename from packages/auth/redis.js rename to packages/backend-core/redis.js diff --git a/packages/auth/roles.js b/packages/backend-core/roles.js similarity index 100% rename from packages/auth/roles.js rename to packages/backend-core/roles.js diff --git a/packages/auth/scripts/jestSetup.js b/packages/backend-core/scripts/jestSetup.js similarity index 100% rename from packages/auth/scripts/jestSetup.js rename to packages/backend-core/scripts/jestSetup.js diff --git a/packages/auth/sessions.js b/packages/backend-core/sessions.js similarity index 100% rename from packages/auth/sessions.js rename to packages/backend-core/sessions.js diff --git a/packages/auth/src/index.js b/packages/backend-core/src/auth.js similarity index 52% rename from packages/auth/src/index.js rename to packages/backend-core/src/auth.js index 4aa2c8ab96..7f66d887ae 100644 --- a/packages/auth/src/index.js +++ b/packages/backend-core/src/auth.js @@ -1,7 +1,6 @@ const passport = require("koa-passport") const LocalStrategy = require("passport-local").Strategy const JwtStrategy = require("passport-jwt").Strategy -const { StaticDatabases } = require("./db/utils") const { getGlobalDB } = require("./tenancy") const { jwt, @@ -14,8 +13,6 @@ const { appTenancy, authError, } = require("./middleware") -const { setDB } = require("./db") -const userCache = require("./cache/user") // Strategies passport.use(new LocalStrategy(local.options, local.authenticate)) @@ -36,36 +33,13 @@ passport.deserializeUser(async (user, done) => { }) module.exports = { - init(pouch) { - setDB(pouch) - }, - db: require("./db/utils"), - redis: { - Client: require("./redis"), - utils: require("./redis/utils"), - }, - objectStore: { - ...require("./objectStore"), - ...require("./objectStore/utils"), - }, - utils: { - ...require("./utils"), - ...require("./hashing"), - }, - auth: { - buildAuthMiddleware: authenticated, - passport, - google, - oidc, - jwt: require("jsonwebtoken"), - buildTenancyMiddleware: tenancy, - buildAppTenancyMiddleware: appTenancy, - auditLog, - authError, - }, - cache: { - user: userCache, - }, - StaticDatabases, - constants: require("./constants"), + buildAuthMiddleware: authenticated, + passport, + google, + oidc, + jwt: require("jsonwebtoken"), + buildTenancyMiddleware: tenancy, + buildAppTenancyMiddleware: appTenancy, + auditLog, + authError, } diff --git a/packages/auth/src/cache/appMetadata.js b/packages/backend-core/src/cache/appMetadata.js similarity index 100% rename from packages/auth/src/cache/appMetadata.js rename to packages/backend-core/src/cache/appMetadata.js diff --git a/packages/auth/src/cache/user.js b/packages/backend-core/src/cache/user.js similarity index 100% rename from packages/auth/src/cache/user.js rename to packages/backend-core/src/cache/user.js diff --git a/packages/auth/src/cloud/accounts.js b/packages/backend-core/src/cloud/accounts.js similarity index 100% rename from packages/auth/src/cloud/accounts.js rename to packages/backend-core/src/cloud/accounts.js diff --git a/packages/auth/src/cloud/api.js b/packages/backend-core/src/cloud/api.js similarity index 100% rename from packages/auth/src/cloud/api.js rename to packages/backend-core/src/cloud/api.js diff --git a/packages/auth/src/constants.js b/packages/backend-core/src/constants.js similarity index 100% rename from packages/auth/src/constants.js rename to packages/backend-core/src/constants.js diff --git a/packages/auth/src/db/Replication.js b/packages/backend-core/src/db/Replication.js similarity index 100% rename from packages/auth/src/db/Replication.js rename to packages/backend-core/src/db/Replication.js diff --git a/packages/auth/src/db/constants.js b/packages/backend-core/src/db/constants.js similarity index 100% rename from packages/auth/src/db/constants.js rename to packages/backend-core/src/db/constants.js diff --git a/packages/auth/src/db/index.js b/packages/backend-core/src/db/index.js similarity index 100% rename from packages/auth/src/db/index.js rename to packages/backend-core/src/db/index.js diff --git a/packages/auth/src/db/utils.js b/packages/backend-core/src/db/utils.js similarity index 97% rename from packages/auth/src/db/utils.js rename to packages/backend-core/src/db/utils.js index 2bad09c306..5830de4721 100644 --- a/packages/auth/src/db/utils.js +++ b/packages/backend-core/src/db/utils.js @@ -224,8 +224,15 @@ exports.getAllDbs = async () => { } } let couchUrl = `${exports.getCouchUrl()}/_all_dbs` - if (env.MULTI_TENANCY) { - let tenantId = getTenantId() + let tenantId = getTenantId() + if (!env.MULTI_TENANCY || tenantId == DEFAULT_TENANT_ID) { + // just get all DBs when: + // - single tenancy + // - default tenant + // - apps dbs don't contain tenant id + // - non-default tenant dbs are filtered out application side in getAllApps + await addDbs(couchUrl) + } else { // get prod apps await addDbs( exports.getStartEndKeyURL(couchUrl, DocumentTypes.APP, tenantId) @@ -236,9 +243,6 @@ exports.getAllDbs = async () => { ) // add global db name dbs.push(getGlobalDBName(tenantId)) - } else { - // just get all DBs in self host - await addDbs(couchUrl) } return dbs } diff --git a/packages/auth/src/db/views.js b/packages/backend-core/src/db/views.js similarity index 100% rename from packages/auth/src/db/views.js rename to packages/backend-core/src/db/views.js diff --git a/packages/auth/src/environment.js b/packages/backend-core/src/environment.js similarity index 100% rename from packages/auth/src/environment.js rename to packages/backend-core/src/environment.js diff --git a/packages/auth/src/hashing.js b/packages/backend-core/src/hashing.js similarity index 100% rename from packages/auth/src/hashing.js rename to packages/backend-core/src/hashing.js diff --git a/packages/auth/src/helpers.js b/packages/backend-core/src/helpers.js similarity index 100% rename from packages/auth/src/helpers.js rename to packages/backend-core/src/helpers.js diff --git a/packages/backend-core/src/index.js b/packages/backend-core/src/index.js new file mode 100644 index 0000000000..cd3a3f5c97 --- /dev/null +++ b/packages/backend-core/src/index.js @@ -0,0 +1,17 @@ +const { setDB } = require("./db") + +module.exports = { + init(pouch) { + setDB(pouch) + }, + // some default exports from the library, however these ideally shouldn't + // be used, instead the syntax require("@budibase/backend-core/db") should be used + StaticDatabases: require("./db/utils").StaticDatabases, + db: require("../db"), + redis: require("../redis"), + objectStore: require("../objectStore"), + utils: require("../utils"), + cache: require("../cache"), + auth: require("../auth"), + constants: require("../constants"), +} diff --git a/packages/auth/src/middleware/appTenancy.js b/packages/backend-core/src/middleware/appTenancy.js similarity index 100% rename from packages/auth/src/middleware/appTenancy.js rename to packages/backend-core/src/middleware/appTenancy.js diff --git a/packages/auth/src/middleware/auditLog.js b/packages/backend-core/src/middleware/auditLog.js similarity index 100% rename from packages/auth/src/middleware/auditLog.js rename to packages/backend-core/src/middleware/auditLog.js diff --git a/packages/auth/src/middleware/authenticated.js b/packages/backend-core/src/middleware/authenticated.js similarity index 100% rename from packages/auth/src/middleware/authenticated.js rename to packages/backend-core/src/middleware/authenticated.js diff --git a/packages/auth/src/middleware/index.js b/packages/backend-core/src/middleware/index.js similarity index 100% rename from packages/auth/src/middleware/index.js rename to packages/backend-core/src/middleware/index.js diff --git a/packages/auth/src/middleware/matchers.js b/packages/backend-core/src/middleware/matchers.js similarity index 100% rename from packages/auth/src/middleware/matchers.js rename to packages/backend-core/src/middleware/matchers.js diff --git a/packages/auth/src/middleware/passport/google.js b/packages/backend-core/src/middleware/passport/google.js similarity index 100% rename from packages/auth/src/middleware/passport/google.js rename to packages/backend-core/src/middleware/passport/google.js diff --git a/packages/auth/src/middleware/passport/jwt.js b/packages/backend-core/src/middleware/passport/jwt.js similarity index 100% rename from packages/auth/src/middleware/passport/jwt.js rename to packages/backend-core/src/middleware/passport/jwt.js diff --git a/packages/auth/src/middleware/passport/local.js b/packages/backend-core/src/middleware/passport/local.js similarity index 100% rename from packages/auth/src/middleware/passport/local.js rename to packages/backend-core/src/middleware/passport/local.js diff --git a/packages/auth/src/middleware/passport/oidc.js b/packages/backend-core/src/middleware/passport/oidc.js similarity index 100% rename from packages/auth/src/middleware/passport/oidc.js rename to packages/backend-core/src/middleware/passport/oidc.js diff --git a/packages/auth/src/middleware/passport/tests/google.spec.js b/packages/backend-core/src/middleware/passport/tests/google.spec.js similarity index 100% rename from packages/auth/src/middleware/passport/tests/google.spec.js rename to packages/backend-core/src/middleware/passport/tests/google.spec.js diff --git a/packages/auth/src/middleware/passport/tests/oidc.spec.js b/packages/backend-core/src/middleware/passport/tests/oidc.spec.js similarity index 100% rename from packages/auth/src/middleware/passport/tests/oidc.spec.js rename to packages/backend-core/src/middleware/passport/tests/oidc.spec.js diff --git a/packages/auth/src/middleware/passport/tests/third-party-common.spec.js b/packages/backend-core/src/middleware/passport/tests/third-party-common.spec.js similarity index 100% rename from packages/auth/src/middleware/passport/tests/third-party-common.spec.js rename to packages/backend-core/src/middleware/passport/tests/third-party-common.spec.js diff --git a/packages/auth/src/middleware/passport/tests/utilities/mock-data.js b/packages/backend-core/src/middleware/passport/tests/utilities/mock-data.js similarity index 100% rename from packages/auth/src/middleware/passport/tests/utilities/mock-data.js rename to packages/backend-core/src/middleware/passport/tests/utilities/mock-data.js diff --git a/packages/auth/src/middleware/passport/third-party-common.js b/packages/backend-core/src/middleware/passport/third-party-common.js similarity index 100% rename from packages/auth/src/middleware/passport/third-party-common.js rename to packages/backend-core/src/middleware/passport/third-party-common.js diff --git a/packages/auth/src/middleware/passport/utils.js b/packages/backend-core/src/middleware/passport/utils.js similarity index 100% rename from packages/auth/src/middleware/passport/utils.js rename to packages/backend-core/src/middleware/passport/utils.js diff --git a/packages/auth/src/middleware/tenancy.js b/packages/backend-core/src/middleware/tenancy.js similarity index 100% rename from packages/auth/src/middleware/tenancy.js rename to packages/backend-core/src/middleware/tenancy.js diff --git a/packages/auth/src/migrations/index.js b/packages/backend-core/src/migrations/index.js similarity index 100% rename from packages/auth/src/migrations/index.js rename to packages/backend-core/src/migrations/index.js diff --git a/packages/auth/src/migrations/tests/__snapshots__/index.spec.js.snap b/packages/backend-core/src/migrations/tests/__snapshots__/index.spec.js.snap similarity index 100% rename from packages/auth/src/migrations/tests/__snapshots__/index.spec.js.snap rename to packages/backend-core/src/migrations/tests/__snapshots__/index.spec.js.snap diff --git a/packages/auth/src/migrations/tests/index.spec.js b/packages/backend-core/src/migrations/tests/index.spec.js similarity index 100% rename from packages/auth/src/migrations/tests/index.spec.js rename to packages/backend-core/src/migrations/tests/index.spec.js diff --git a/packages/auth/src/objectStore/index.js b/packages/backend-core/src/objectStore/index.js similarity index 91% rename from packages/auth/src/objectStore/index.js rename to packages/backend-core/src/objectStore/index.js index 87b67d464e..b5d8475cee 100644 --- a/packages/auth/src/objectStore/index.js +++ b/packages/backend-core/src/objectStore/index.js @@ -206,6 +206,34 @@ exports.retrieveToTmp = async (bucketName, filepath) => { return outputPath } +/** + * Delete a single file. + */ +exports.deleteFile = async (bucketName, filepath) => { + const objectStore = exports.ObjectStore(bucketName) + await exports.makeSureBucketExists(objectStore, bucketName) + const params = { + Bucket: bucketName, + Key: filepath, + } + return objectStore.deleteObject(params) +} + +exports.deleteFiles = async (bucketName, filepaths) => { + const objectStore = exports.ObjectStore(bucketName) + await exports.makeSureBucketExists(objectStore, bucketName) + const params = { + Bucket: bucketName, + Delete: { + Objects: filepaths.map(path => ({ Key: path })), + }, + } + return objectStore.deleteObjects(params).promise() +} + +/** + * Delete a path, including everything within. + */ exports.deleteFolder = async (bucketName, folder) => { bucketName = sanitizeBucket(bucketName) folder = sanitizeKey(folder) diff --git a/packages/auth/src/objectStore/utils.js b/packages/backend-core/src/objectStore/utils.js similarity index 100% rename from packages/auth/src/objectStore/utils.js rename to packages/backend-core/src/objectStore/utils.js diff --git a/packages/auth/src/redis/authRedis.js b/packages/backend-core/src/redis/authRedis.js similarity index 100% rename from packages/auth/src/redis/authRedis.js rename to packages/backend-core/src/redis/authRedis.js diff --git a/packages/auth/src/redis/index.js b/packages/backend-core/src/redis/index.js similarity index 100% rename from packages/auth/src/redis/index.js rename to packages/backend-core/src/redis/index.js diff --git a/packages/auth/src/redis/utils.js b/packages/backend-core/src/redis/utils.js similarity index 100% rename from packages/auth/src/redis/utils.js rename to packages/backend-core/src/redis/utils.js diff --git a/packages/auth/src/security/permissions.js b/packages/backend-core/src/security/permissions.js similarity index 100% rename from packages/auth/src/security/permissions.js rename to packages/backend-core/src/security/permissions.js diff --git a/packages/auth/src/security/roles.js b/packages/backend-core/src/security/roles.js similarity index 100% rename from packages/auth/src/security/roles.js rename to packages/backend-core/src/security/roles.js diff --git a/packages/auth/src/security/sessions.js b/packages/backend-core/src/security/sessions.js similarity index 100% rename from packages/auth/src/security/sessions.js rename to packages/backend-core/src/security/sessions.js diff --git a/packages/auth/src/tenancy/FunctionContext.js b/packages/backend-core/src/tenancy/FunctionContext.js similarity index 100% rename from packages/auth/src/tenancy/FunctionContext.js rename to packages/backend-core/src/tenancy/FunctionContext.js diff --git a/packages/auth/src/tenancy/context.js b/packages/backend-core/src/tenancy/context.js similarity index 100% rename from packages/auth/src/tenancy/context.js rename to packages/backend-core/src/tenancy/context.js diff --git a/packages/auth/src/tenancy/deprovision.js b/packages/backend-core/src/tenancy/deprovision.js similarity index 100% rename from packages/auth/src/tenancy/deprovision.js rename to packages/backend-core/src/tenancy/deprovision.js diff --git a/packages/auth/src/tenancy/index.js b/packages/backend-core/src/tenancy/index.js similarity index 100% rename from packages/auth/src/tenancy/index.js rename to packages/backend-core/src/tenancy/index.js diff --git a/packages/auth/src/tenancy/tenancy.js b/packages/backend-core/src/tenancy/tenancy.js similarity index 100% rename from packages/auth/src/tenancy/tenancy.js rename to packages/backend-core/src/tenancy/tenancy.js diff --git a/packages/auth/src/tests/utilities/db.js b/packages/backend-core/src/tests/utilities/db.js similarity index 100% rename from packages/auth/src/tests/utilities/db.js rename to packages/backend-core/src/tests/utilities/db.js diff --git a/packages/auth/src/tests/utilities/dbConfig.js b/packages/backend-core/src/tests/utilities/dbConfig.js similarity index 100% rename from packages/auth/src/tests/utilities/dbConfig.js rename to packages/backend-core/src/tests/utilities/dbConfig.js diff --git a/packages/auth/src/utils.js b/packages/backend-core/src/utils.js similarity index 100% rename from packages/auth/src/utils.js rename to packages/backend-core/src/utils.js diff --git a/packages/auth/tenancy.js b/packages/backend-core/tenancy.js similarity index 100% rename from packages/auth/tenancy.js rename to packages/backend-core/tenancy.js diff --git a/packages/backend-core/utils.js b/packages/backend-core/utils.js new file mode 100644 index 0000000000..2ef920e103 --- /dev/null +++ b/packages/backend-core/utils.js @@ -0,0 +1,4 @@ +module.exports = { + ...require("./src/utils"), + ...require("./src/hashing"), +} diff --git a/packages/auth/yarn.lock b/packages/backend-core/yarn.lock similarity index 100% rename from packages/auth/yarn.lock rename to packages/backend-core/yarn.lock diff --git a/packages/bbui/package.json b/packages/bbui/package.json index f53c314eaa..941127eb92 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/bbui", "description": "A UI solution used in the different Budibase projects.", - "version": "1.0.27-alpha.5", + "version": "1.0.27-alpha.13", "license": "MPL-2.0", "svelte": "src/index.js", "module": "dist/bbui.es.js", diff --git a/packages/bbui/src/Tabs/Tabs.svelte b/packages/bbui/src/Tabs/Tabs.svelte index c68f715de0..40e02058c1 100644 --- a/packages/bbui/src/Tabs/Tabs.svelte +++ b/packages/bbui/src/Tabs/Tabs.svelte @@ -10,6 +10,8 @@ export let noHorizPadding = false export let quiet = false export let emphasized = false + // overlay content from the tab bar onto tabs e.g. for a dropdown + export let onTop = false let thisSelected = undefined @@ -78,6 +80,7 @@ 'spectrum-Tabs--quiet'} spectrum-Tabs--{vertical ? 'vertical' : 'horizontal'}" + class:onTop > {#if $tab.info} @@ -98,7 +101,9 @@ .quiet { border-bottom: none !important; } - + .onTop { + z-index: 20; + } .spectrum-Tabs { padding-left: var(--spacing-xl); padding-right: var(--spacing-xl); diff --git a/packages/bbui/yarn.lock b/packages/bbui/yarn.lock index a102e6c148..42c88af5a4 100644 --- a/packages/bbui/yarn.lock +++ b/packages/bbui/yarn.lock @@ -2076,9 +2076,9 @@ postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.27: supports-color "^6.1.0" postcss@^8.2.9: - version "8.2.10" - resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.10.tgz#ca7a042aa8aff494b334d0ff3e9e77079f6f702b" - integrity sha512-b/h7CPV7QEdrqIxtAf2j31U5ef05uBDuvoXv6L51Q4rcS1jdlXAVKJv+atCFdUXYl9dyTHGyoMzIepwowRJjFw== + version "8.2.13" + resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.13.tgz#dbe043e26e3c068e45113b1ed6375d2d37e2129f" + integrity sha512-FCE5xLH+hjbzRdpbRb1IMCvPv9yZx2QnDarBEYSN0N0HYk+TcXsEhwdFcFb+SRWOKzKGErhIEbBK2ogyLdTtfQ== dependencies: colorette "^1.2.2" nanoid "^3.1.22" diff --git a/packages/builder/package.json b/packages/builder/package.json index 6aa67e307e..8b03c66b74 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "1.0.27-alpha.5", + "version": "1.0.27-alpha.13", "license": "GPL-3.0", "private": true, "scripts": { @@ -65,10 +65,10 @@ } }, "dependencies": { - "@budibase/bbui": "^1.0.27-alpha.5", - "@budibase/client": "^1.0.27-alpha.5", + "@budibase/bbui": "^1.0.27-alpha.13", + "@budibase/client": "^1.0.27-alpha.13", "@budibase/colorpicker": "1.1.2", - "@budibase/string-templates": "^1.0.27-alpha.5", + "@budibase/string-templates": "^1.0.27-alpha.13", "@sentry/browser": "5.19.1", "@spectrum-css/page": "^3.0.1", "@spectrum-css/vars": "^3.0.1", diff --git a/packages/builder/src/builderStore/datasource.js b/packages/builder/src/builderStore/datasource.js index 61cead2e16..cfdeeac23e 100644 --- a/packages/builder/src/builderStore/datasource.js +++ b/packages/builder/src/builderStore/datasource.js @@ -23,10 +23,10 @@ function prepareData(config) { return datasource } -export async function saveDatasource(config) { +export async function saveDatasource(config, skipFetch = false) { const datasource = prepareData(config) // Create datasource - const resp = await datasources.save(datasource, datasource.plus) + const resp = await datasources.save(datasource, !skipFetch && datasource.plus) // update the tables incase data source plus await tables.fetch() diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte index 7f379ba138..fe94b7e63f 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte @@ -9,6 +9,7 @@ Modal, Button, StatusLight, + ActionButton, } from "@budibase/bbui" import AutomationBlockSetup from "../../SetupPanel/AutomationBlockSetup.svelte" import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte" @@ -27,7 +28,7 @@ let blockComplete $: testResult = $automationStore.selectedAutomation.testResults?.steps.filter( - step => step.stepId === block.stepId + step => (block.id ? step.id === block.id : step.stepId === block.stepId) ) $: isTrigger = block.type === "TRIGGER" @@ -119,19 +120,13 @@
-
{ - setupToggled = !setupToggled - }} - class="center-items" + (setupToggled = !setupToggled)} + quiet + icon={setupToggled ? "ChevronDown" : "ChevronRight"} > - {#if setupToggled} - - {:else} - - {/if} Setup -
+ {#if !isTrigger}
deleteStep()}> @@ -187,6 +182,7 @@ .splitHeader { display: flex; justify-content: space-between; + align-items: center; } .iconAlign { padding: 0 0 0 var(--spacing-m); diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index d648b3f989..928897d6f5 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -10,6 +10,7 @@ ActionButton, Drawer, Modal, + Detail, } from "@budibase/bbui" import CreateWebhookModal from "components/automation/Shared/CreateWebhookModal.svelte" @@ -37,6 +38,7 @@ let drawer let tempFilters = lookForFilters(schemaProperties) || [] let fillWidth = true + let codeBindingOpen = false $: stepId = block.stepId $: bindings = getAvailableBindings( @@ -233,7 +235,16 @@ onChange(e, key)} value={inputData[key]} /> {:else if value.customType === "code"} -
{JSON.stringify(bindings, null, 2)}
+ (codeBindingOpen = !codeBindingOpen)} + quiet + icon={codeBindingOpen ? "ChevronDown" : "ChevronRight"} + > + Bindings + + {#if codeBindingOpen} +
{JSON.stringify(bindings, null, 2)}
+ {/if} { diff --git a/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte b/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte index 18143c2071..af345ddcdf 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte @@ -137,7 +137,7 @@ selected={$queries.selected === query._id} on:click={() => onClickQuery(query)} > - + {/each} {/if} diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte index b97f23d7a3..819fb32e45 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte @@ -199,18 +199,18 @@ Tell budibase how your tables are related to get even more smart features. -{/if} -{#if relationshipInfo && relationshipInfo.length > 0} - openRelationshipModal(detail.from, detail.to)} - schema={relationshipSchema} - data={relationshipInfo} - allowEditColumns={false} - allowEditRows={false} - allowSelectRows={false} - /> -{:else} - No relationships configured. + {#if relationshipInfo && relationshipInfo.length > 0} +
openRelationshipModal(detail.from, detail.to)} + schema={relationshipSchema} + data={relationshipInfo} + allowEditColumns={false} + allowEditRows={false} + allowSelectRows={false} + /> + {:else} + No relationships configured. + {/if} {/if} diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte index 33bf5d604a..808c3a49ec 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte @@ -234,8 +234,12 @@ const datasourceUrl = datasource?.config.url const qs = query?.fields.queryString breakQs = restUtils.breakQueryString(qs) - if (datasourceUrl && !query.fields.path?.startsWith(datasourceUrl)) { - const path = query.fields.path + const path = query.fields.path + if ( + datasourceUrl && + !path?.startsWith("http") && + !path?.startsWith("{{") // don't substitute the datasource url when query starts with a variable e.g. the upgrade path + ) { query.fields.path = `${datasource.config.url}/${path ? path : ""}` } url = buildUrl(query.fields.path, breakQs) @@ -311,7 +315,7 @@ - + Create dynamic variables based on response body or headers - from other queries. + from this query. app.status === AppStatus.DEPLOYED $: publishedApps = $apps.filter(publishedAppsOnly) - + $: isCloud = $admin.cloud $: userApps = $auth.user?.builder?.global ? publishedApps : publishedApps.filter(app => Object.keys($auth.user?.roles).includes(app.prodId) ) + + function getUrl(app) { + return !isCloud ? `/app/${encodeURIComponent(app.name)}` : `/${app.prodId}` + } {#if $auth.user && loaded} @@ -93,7 +97,7 @@
{#each userApps as app, idx (app.appId)} - +
{app.name} diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index 336489be8d..c85ad79d45 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -47,6 +47,7 @@ $: filteredApps = enrichedApps.filter(app => app?.name?.toLowerCase().includes(searchTerm.toLowerCase()) ) + $: isCloud = $admin.cloud const enrichApps = (apps, user, sortBy) => { const enrichedApps = apps.map(app => ({ @@ -158,8 +159,13 @@ } const viewApp = app => { - const id = app.deployed ? app.prodId : app.devId - window.open(`/${id}`, "_blank") + if (!isCloud && app.deployed) { + // special case to use the short form name if self hosted + window.open(`/app/${encodeURIComponent(app.name)}`) + } else { + const id = app.deployed ? app.prodId : app.devId + window.open(`/${id}`, "_blank") + } } const editApp = app => { diff --git a/packages/builder/src/stores/backend/queries.js b/packages/builder/src/stores/backend/queries.js index 0e767fa5c0..2018933ffc 100644 --- a/packages/builder/src/stores/backend/queries.js +++ b/packages/builder/src/stores/backend/queries.js @@ -134,7 +134,7 @@ export function createQueriesStore() { list.map(q => q.name) ) - actions.save(datasourceId, newQuery) + return actions.save(datasourceId, newQuery) }, } diff --git a/packages/cli/package.json b/packages/cli/package.json index b61d914501..f485df8acb 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/cli", - "version": "1.0.27-alpha.5", + "version": "1.0.27-alpha.13", "description": "Budibase CLI, for developers, self hosting and migrations.", "main": "src/index.js", "bin": { diff --git a/packages/client/package.json b/packages/client/package.json index 1163410f09..c0047da8ef 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "1.0.27-alpha.5", + "version": "1.0.27-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": "^1.0.27-alpha.5", + "@budibase/bbui": "^1.0.27-alpha.13", "@budibase/standard-components": "^0.9.139", - "@budibase/string-templates": "^1.0.27-alpha.5", + "@budibase/string-templates": "^1.0.27-alpha.13", "regexparam": "^1.3.0", "shortid": "^2.2.15", "svelte-spa-router": "^3.0.5" diff --git a/packages/server/package.json b/packages/server/package.json index 35e81561f1..a958e175a6 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/server", "email": "hi@budibase.com", - "version": "1.0.27-alpha.5", + "version": "1.0.27-alpha.13", "description": "Budibase Web Server", "main": "src/index.ts", "repository": { @@ -70,9 +70,9 @@ "license": "GPL-3.0", "dependencies": { "@apidevtools/swagger-parser": "^10.0.3", - "@budibase/auth": "^1.0.27-alpha.5", - "@budibase/client": "^1.0.27-alpha.5", - "@budibase/string-templates": "^1.0.27-alpha.5", + "@budibase/backend-core": "^1.0.27-alpha.13", + "@budibase/client": "^1.0.27-alpha.13", + "@budibase/string-templates": "^1.0.27-alpha.13", "@bull-board/api": "^3.7.0", "@bull-board/koa": "^3.7.0", "@elastic/elasticsearch": "7.10.0", diff --git a/packages/server/scripts/replicateApp.js b/packages/server/scripts/replicateApp.js index 8b363309ab..6730fe42d3 100644 --- a/packages/server/scripts/replicateApp.js +++ b/packages/server/scripts/replicateApp.js @@ -7,7 +7,7 @@ const CouchDB = require("../src/db") const { DocumentTypes } = require("../src/db/utils") -const { getAllDbs } = require("@budibase/auth/db") +const { getAllDbs } = require("@budibase/backend-core/db") const appName = process.argv[2].toLowerCase() const remoteUrl = process.argv[3] diff --git a/packages/server/src/api/controllers/apikeys.js b/packages/server/src/api/controllers/apikeys.js index 9b1ddee4c4..f5e36e7435 100644 --- a/packages/server/src/api/controllers/apikeys.js +++ b/packages/server/src/api/controllers/apikeys.js @@ -1,5 +1,5 @@ -const { StaticDatabases } = require("@budibase/auth/db") -const { getGlobalDB } = require("@budibase/auth/tenancy") +const { StaticDatabases } = require("@budibase/backend-core/db") +const { getGlobalDB } = require("@budibase/backend-core/tenancy") const KEYS_DOC = StaticDatabases.GLOBAL.docs.apiKeys diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 6f55834a49..48e2b19a9d 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -19,7 +19,10 @@ const { DocumentTypes, AppStatus, } = require("../../db/utils") -const { BUILTIN_ROLE_IDS, AccessController } = require("@budibase/auth/roles") +const { + BUILTIN_ROLE_IDS, + AccessController, +} = require("@budibase/backend-core/roles") const { BASE_LAYOUTS } = require("../../constants/layouts") const { cloneDeep } = require("lodash/fp") const { processObject } = require("@budibase/string-templates") @@ -28,7 +31,7 @@ const { isDevAppID, getDeployedAppID, Replication, -} = require("@budibase/auth/db") +} = require("@budibase/backend-core/db") const { USERS_TABLE_SCHEMA } = require("../../constants") const { getDeployedApps, @@ -41,9 +44,9 @@ const { backupClientLibrary, revertClientLibrary, } = require("../../utilities/fileSystem/clientLibrary") -const { getTenantId, isMultiTenant } = require("@budibase/auth/tenancy") +const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy") const { syncGlobalUsers } = require("./user") -const { app: appCache } = require("@budibase/auth/cache") +const { app: appCache } = require("@budibase/backend-core/cache") const { cleanupAutomations } = require("../../automations/utils") const URL_REGEX_SLASH = /\/|\\/g diff --git a/packages/server/src/api/controllers/auth.js b/packages/server/src/api/controllers/auth.js index 53d8ecbacb..3f680225af 100644 --- a/packages/server/src/api/controllers/auth.js +++ b/packages/server/src/api/controllers/auth.js @@ -2,7 +2,7 @@ const CouchDB = require("../../db") const { outputProcessing } = require("../../utilities/rowProcessor") const { InternalTables } = require("../../db/utils") const { getFullUser } = require("../../utilities/users") -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") exports.fetchSelf = async ctx => { const appId = ctx.appId diff --git a/packages/server/src/api/controllers/cloud.js b/packages/server/src/api/controllers/cloud.js index a0057d68e4..ea6cc9b71e 100644 --- a/packages/server/src/api/controllers/cloud.js +++ b/packages/server/src/api/controllers/cloud.js @@ -1,5 +1,5 @@ const env = require("../../environment") -const { getAllApps } = require("@budibase/auth/db") +const { getAllApps } = require("@budibase/backend-core/db") const CouchDB = require("../../db") const { exportDB, @@ -7,7 +7,10 @@ const { readFileSync, } = require("../../utilities/fileSystem") const { stringToReadStream } = require("../../utilities") -const { getGlobalDBName, getGlobalDB } = require("@budibase/auth/tenancy") +const { + getGlobalDBName, + getGlobalDB, +} = require("@budibase/backend-core/tenancy") const { create } = require("./application") const { getDocParams, DocumentTypes, isDevAppID } = require("../../db/utils") diff --git a/packages/server/src/api/controllers/datasource.js b/packages/server/src/api/controllers/datasource.js index b99b1a5048..f08b622c3e 100644 --- a/packages/server/src/api/controllers/datasource.js +++ b/packages/server/src/api/controllers/datasource.js @@ -10,6 +10,7 @@ const { const { BuildSchemaErrors, InvalidColumns } = require("../../constants") const { integrations } = require("../../integrations") const { getDatasourceAndQuery } = require("./row/utils") +const { invalidateDynamicVariables } = require("../../threads/utils") exports.fetch = async function (ctx) { const database = new CouchDB(ctx.appId) @@ -57,10 +58,43 @@ exports.buildSchemaFromDb = async function (ctx) { ctx.body = response } +/** + * Check for variables that have been updated or removed and invalidate them. + */ +const invalidateVariables = async (existingDatasource, updatedDatasource) => { + const existingVariables = existingDatasource.config.dynamicVariables + const updatedVariables = updatedDatasource.config.dynamicVariables + const toInvalidate = [] + + if (!existingVariables) { + return + } + + if (!updatedVariables) { + // invalidate all + toInvalidate.push(...existingVariables) + } else { + // invaldate changed / removed + existingVariables.forEach(existing => { + const unchanged = updatedVariables.find( + updated => + existing.name === updated.name && + existing.queryId === updated.queryId && + existing.value === updated.value + ) + if (!unchanged) { + toInvalidate.push(existing) + } + }) + } + await invalidateDynamicVariables(toInvalidate) +} + exports.update = async function (ctx) { const db = new CouchDB(ctx.appId) const datasourceId = ctx.params.datasourceId let datasource = await db.get(datasourceId) + await invalidateVariables(datasource, ctx.request.body) datasource = { ...datasource, ...ctx.request.body } const response = await db.put(datasource) diff --git a/packages/server/src/api/controllers/deploy/index.js b/packages/server/src/api/controllers/deploy/index.js index c1138f4b03..76d7b75912 100644 --- a/packages/server/src/api/controllers/deploy/index.js +++ b/packages/server/src/api/controllers/deploy/index.js @@ -1,12 +1,12 @@ const CouchDB = require("../../../db") const Deployment = require("./Deployment") -const { Replication, getDeployedAppID } = require("@budibase/auth/db") +const { Replication, getDeployedAppID } = require("@budibase/backend-core/db") const { DocumentTypes, getAutomationParams } = require("../../../db/utils") const { disableAllCrons, enableCronTrigger, } = require("../../../automations/utils") -const { app: appCache } = require("@budibase/auth/cache") +const { app: appCache } = require("@budibase/backend-core/cache") // the max time we can wait for an invalidation to complete before considering it failed const MAX_PENDING_TIME_MS = 30 * 60000 diff --git a/packages/server/src/api/controllers/dev.js b/packages/server/src/api/controllers/dev.js index 559ffcbcfd..3126454a6b 100644 --- a/packages/server/src/api/controllers/dev.js +++ b/packages/server/src/api/controllers/dev.js @@ -4,9 +4,9 @@ const env = require("../../environment") const { checkSlashesInUrl } = require("../../utilities") const { request } = require("../../utilities/workerRequests") const { clearLock } = require("../../utilities/redis") -const { Replication } = require("@budibase/auth").db +const { Replication } = require("@budibase/backend-core/db") const { DocumentTypes } = require("../../db/utils") -const { app: appCache } = require("@budibase/auth/cache") +const { app: appCache } = require("@budibase/backend-core/cache") async function redirect(ctx, method, path = "global") { const { devPath } = ctx.params diff --git a/packages/server/src/api/controllers/hosting.js b/packages/server/src/api/controllers/hosting.js index 6b47dc8634..0360643942 100644 --- a/packages/server/src/api/controllers/hosting.js +++ b/packages/server/src/api/controllers/hosting.js @@ -1,7 +1,7 @@ const CouchDB = require("../../db") const { getDeployedApps } = require("../../utilities/workerRequests") -const { getScopedConfig } = require("@budibase/auth/db") -const { Configs } = require("@budibase/auth").constants +const { getScopedConfig } = require("@budibase/backend-core/db") +const { Configs } = require("@budibase/backend-core/constants") const { checkSlashesInUrl } = require("../../utilities") exports.fetchUrls = async ctx => { diff --git a/packages/server/src/api/controllers/permission.js b/packages/server/src/api/controllers/permission.js index c38740cb01..5c42fe77ef 100644 --- a/packages/server/src/api/controllers/permission.js +++ b/packages/server/src/api/controllers/permission.js @@ -1,10 +1,10 @@ -const { getBuiltinPermissions } = require("@budibase/auth/permissions") +const { getBuiltinPermissions } = require("@budibase/backend-core/permissions") const { isBuiltin, getDBRoleID, getExternalRoleID, getBuiltinRoles, -} = require("@budibase/auth/roles") +} = require("@budibase/backend-core/roles") const { getRoleParams } = require("../../db/utils") const CouchDB = require("../../db") const { diff --git a/packages/server/src/api/controllers/query/import/sources/base/index.ts b/packages/server/src/api/controllers/query/import/sources/base/index.ts index 06e8dcfeff..e666fdc193 100644 --- a/packages/server/src/api/controllers/query/import/sources/base/index.ts +++ b/packages/server/src/api/controllers/query/import/sources/base/index.ts @@ -1,7 +1,7 @@ import { Query, QueryParameter } from "../../../../../../definitions/datasource" +import { URL } from "url" export interface ImportInfo { - url: string name: string } @@ -23,6 +23,7 @@ export abstract class ImportSource { name: string, method: string, path: string, + url: URL, queryString: string, headers: object = {}, parameters: QueryParameter[] = [], @@ -33,6 +34,7 @@ export abstract class ImportSource { const transformer = "return data" const schema = {} path = this.processPath(path) + path = `${url.origin}/${path}` queryString = this.processQuery(queryString) const requestBody = JSON.stringify(body, null, 2) diff --git a/packages/server/src/api/controllers/query/import/sources/curl.ts b/packages/server/src/api/controllers/query/import/sources/curl.ts index b55d24403b..d72441ab12 100644 --- a/packages/server/src/api/controllers/query/import/sources/curl.ts +++ b/packages/server/src/api/controllers/query/import/sources/curl.ts @@ -60,16 +60,19 @@ export class Curl extends ImportSource { return true } + getUrl = (): URL => { + return new URL(this.curl.raw_url) + } + getInfo = async (): Promise => { - const url = new URL(this.curl.url) + const url = this.getUrl() return { - url: url.origin, name: url.hostname, } } getQueries = async (datasourceId: string): Promise => { - const url = new URL(this.curl.raw_url) + const url = this.getUrl() const name = url.pathname const path = url.pathname const method = this.curl.method @@ -87,6 +90,7 @@ export class Curl extends ImportSource { name, method, path, + url, queryString, headers, [], diff --git a/packages/server/src/api/controllers/query/import/sources/openapi2.ts b/packages/server/src/api/controllers/query/import/sources/openapi2.ts index 35dab163f6..c193654909 100644 --- a/packages/server/src/api/controllers/query/import/sources/openapi2.ts +++ b/packages/server/src/api/controllers/query/import/sources/openapi2.ts @@ -2,6 +2,7 @@ import { ImportInfo } from "./base" import { Query, QueryParameter } from "../../../../../definitions/datasource" import { OpenAPIV2 } from "openapi-types" import { OpenAPISource } from "./base/openapi" +import { URL } from "url" const parameterNotRef = ( param: OpenAPIV2.Parameter | OpenAPIV2.ReferenceObject @@ -55,20 +56,22 @@ export class OpenAPI2 extends OpenAPISource { } } - getInfo = async (): Promise => { + getUrl = (): URL => { const scheme = this.document.schemes?.includes("https") ? "https" : "http" const basePath = this.document.basePath || "" const host = this.document.host || "" - const url = `${scheme}://${host}${basePath}` - const name = this.document.info.title || "Swagger Import" + return new URL(`${scheme}://${host}${basePath}`) + } + getInfo = async (): Promise => { + const name = this.document.info.title || "Swagger Import" return { - url: url, - name: name, + name, } } getQueries = async (datasourceId: string): Promise => { + const url = this.getUrl() const queries = [] for (let [path, pathItem] of Object.entries(this.document.paths)) { @@ -145,6 +148,7 @@ export class OpenAPI2 extends OpenAPISource { name, methodName, path, + url, queryString, headers, parameters, diff --git a/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js b/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js index 11869862f7..2b17685f24 100644 --- a/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +++ b/packages/server/src/api/controllers/query/import/sources/tests/curl/curl.spec.js @@ -35,7 +35,6 @@ describe("Curl Import", () => { it("returns import info", async () => { await init("get") const info = await curl.getInfo() - expect(info.url).toBe("http://example.com") expect(info.name).toBe("example.com") }) @@ -67,8 +66,8 @@ describe("Curl Import", () => { } it("populates path", async () => { - await testPath("get", "") - await testPath("path", "paths/abc") + await testPath("get", "http://example.com/") + await testPath("path", "http://example.com/paths/abc") }) const testHeaders = async (file, headers) => { diff --git a/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js b/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js index 845c4f38f6..3c5aa89e3c 100644 --- a/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +++ b/packages/server/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js @@ -41,7 +41,6 @@ describe("OpenAPI2 Import", () => { const testImportInfo = async (file, extension) => { await init(file, extension) const info = await openapi2.getInfo() - expect(info.url).toBe("https://petstore.swagger.io/v2") expect(info.name).toBe("Swagger Petstore") } @@ -92,12 +91,12 @@ describe("OpenAPI2 Import", () => { it("populates path", async () => { const assertions = { - "createEntity" : "entities", - "getEntities" : "entities", - "getEntity" : "entities/{{entityId}}", - "updateEntity" : "entities/{{entityId}}", - "patchEntity" : "entities/{{entityId}}", - "deleteEntity" : "entities/{{entityId}}" + "createEntity" : "http://example.com/entities", + "getEntities" : "http://example.com/entities", + "getEntity" : "http://example.com/entities/{{entityId}}", + "updateEntity" : "http://example.com/entities/{{entityId}}", + "patchEntity" : "http://example.com/entities/{{entityId}}", + "deleteEntity" : "http://example.com/entities/{{entityId}}" } await runTests("crud", testPath, assertions) }) diff --git a/packages/server/src/api/controllers/query/import/tests/index.spec.js b/packages/server/src/api/controllers/query/import/tests/index.spec.js index 32f3b43b44..5a509d2258 100644 --- a/packages/server/src/api/controllers/query/import/tests/index.spec.js +++ b/packages/server/src/api/controllers/query/import/tests/index.spec.js @@ -51,30 +51,24 @@ describe("Rest Importer", () => { await init(data) const info = await restImporter.getInfo() expect(info.name).toBe(assertions[key].name) - expect(info.url).toBe(assertions[key].url) } it("gets info", async () => { const assertions = { "oapi2CrudJson" : { name: "CRUD", - url: "http://example.com" }, "oapi2CrudYaml" : { name: "CRUD", - url: "http://example.com" }, "oapi2PetstoreJson" : { name: "Swagger Petstore", - url: "https://petstore.swagger.io/v2" }, "oapi2PetstoreYaml" :{ name: "Swagger Petstore", - url: "https://petstore.swagger.io/v2" }, "curl": { name: "example.com", - url: "http://example.com" } } await runTest(testGetInfo, assertions) diff --git a/packages/server/src/api/controllers/query/index.js b/packages/server/src/api/controllers/query/index.js index 2cc87628ba..4096dd433f 100644 --- a/packages/server/src/api/controllers/query/index.js +++ b/packages/server/src/api/controllers/query/index.js @@ -8,6 +8,7 @@ const { BaseQueryVerbs } = require("../../../constants") const { Thread, ThreadType } = require("../../../threads") const { save: saveDatasource } = require("../datasource") const { RestImporter } = require("./import") +const { invalidateDynamicVariables } = require("../../../threads/utils") const Runner = new Thread(ThreadType.QUERY, { timeoutMs: 10000 }) @@ -167,8 +168,28 @@ exports.executeV2 = async function (ctx) { return execute(ctx, { rowsOnly: false }) } +const removeDynamicVariables = async (db, queryId) => { + const query = await db.get(queryId) + const datasource = await db.get(query.datasourceId) + const dynamicVariables = datasource.config.dynamicVariables + + if (dynamicVariables) { + // delete dynamic variables from the datasource + const newVariables = dynamicVariables.filter(dv => dv.queryId !== queryId) + datasource.config.dynamicVariables = newVariables + await db.put(datasource) + + // invalidate the deleted variables + const variablesToDelete = dynamicVariables.filter( + dv => dv.queryId === queryId + ) + await invalidateDynamicVariables(variablesToDelete) + } +} + exports.destroy = async function (ctx) { const db = new CouchDB(ctx.appId) + await removeDynamicVariables(db, ctx.params.queryId) await db.remove(ctx.params.queryId, ctx.params.revId) ctx.message = `Query deleted.` ctx.status = 200 diff --git a/packages/server/src/api/controllers/role.js b/packages/server/src/api/controllers/role.js index 7b127fb2d0..b79907031d 100644 --- a/packages/server/src/api/controllers/role.js +++ b/packages/server/src/api/controllers/role.js @@ -4,7 +4,7 @@ const { getRole, isBuiltin, getAllRoles, -} = require("@budibase/auth/roles") +} = require("@budibase/backend-core/roles") const { generateRoleID, getUserMetadataParams, diff --git a/packages/server/src/api/controllers/routing.js b/packages/server/src/api/controllers/routing.js index d281b92fe2..d45d33ed07 100644 --- a/packages/server/src/api/controllers/routing.js +++ b/packages/server/src/api/controllers/routing.js @@ -2,7 +2,7 @@ const { getRoutingInfo } = require("../../utilities/routing") const { getUserRoleHierarchy, BUILTIN_ROLE_IDS, -} = require("@budibase/auth/roles") +} = require("@budibase/backend-core/roles") const URL_SEPARATOR = "/" diff --git a/packages/server/src/api/controllers/row/internal.js b/packages/server/src/api/controllers/row/internal.js index ffee1dcec3..75caaf2fda 100644 --- a/packages/server/src/api/controllers/row/internal.js +++ b/packages/server/src/api/controllers/row/internal.js @@ -11,6 +11,7 @@ const { inputProcessing, outputProcessing, processAutoColumn, + cleanupAttachments, } = require("../../../utilities/rowProcessor") const { FieldTypes } = require("../../../constants") const { isEqual } = require("lodash") @@ -25,6 +26,7 @@ const { getFromDesignDoc, getFromMemoryDoc, } = require("../view/utils") +const { cloneDeep } = require("lodash/fp") const CALCULATION_TYPES = { SUM: "sum", @@ -109,14 +111,14 @@ exports.patch = async ctx => { const inputs = ctx.request.body const tableId = inputs.tableId const isUserTable = tableId === InternalTables.USER_METADATA - let dbRow + let oldRow try { - dbRow = await db.get(inputs._id) + oldRow = await db.get(inputs._id) } catch (err) { if (isUserTable) { // don't include the rev, it'll be the global rev // this time - dbRow = { + oldRow = { _id: inputs._id, } } else { @@ -125,13 +127,14 @@ exports.patch = async ctx => { } let dbTable = await db.get(tableId) // need to build up full patch fields before coerce + let combinedRow = cloneDeep(oldRow) for (let key of Object.keys(inputs)) { if (!dbTable.schema[key]) continue - dbRow[key] = inputs[key] + combinedRow[key] = inputs[key] } // this returns the table and row incase they have been updated - let { table, row } = inputProcessing(ctx.user, dbTable, dbRow) + let { table, row } = inputProcessing(ctx.user, dbTable, combinedRow) const validateResult = await validate({ row, table, @@ -149,6 +152,8 @@ exports.patch = async ctx => { tableId: row.tableId, table, }) + // check if any attachments removed + await cleanupAttachments(appId, table, { oldRow, row }) if (isUserTable) { // the row has been updated, need to put it into the ctx @@ -295,6 +300,8 @@ exports.destroy = async function (ctx) { row, tableId: row.tableId, }) + // remove any attachments that were on the row from object storage + await cleanupAttachments(appId, table, { row }) let response if (ctx.params.tableId === InternalTables.USER_METADATA) { @@ -341,6 +348,8 @@ exports.bulkDestroy = async ctx => { } else { await db.bulkDocs(rows.map(row => ({ ...row, _deleted: true }))) } + // remove any attachments that were on the rows from object storage + await cleanupAttachments(appId, table, { rows }) await Promise.all(updates) return { response: { ok: true }, rows } } diff --git a/packages/server/src/api/controllers/row/internalSearch.js b/packages/server/src/api/controllers/row/internalSearch.js index d8ae77156a..3a2586331a 100644 --- a/packages/server/src/api/controllers/row/internalSearch.js +++ b/packages/server/src/api/controllers/row/internalSearch.js @@ -1,6 +1,6 @@ const { SearchIndexes } = require("../../../db/utils") const fetch = require("node-fetch") -const { getCouchUrl } = require("@budibase/auth/db") +const { getCouchUrl } = require("@budibase/backend-core/db") /** * Class to build lucene query URLs. diff --git a/packages/server/src/api/controllers/screen.js b/packages/server/src/api/controllers/screen.js index 7898476227..5e0eeb5176 100644 --- a/packages/server/src/api/controllers/screen.js +++ b/packages/server/src/api/controllers/screen.js @@ -1,6 +1,6 @@ const CouchDB = require("../../db") const { getScreenParams, generateScreenID } = require("../../db/utils") -const { AccessController } = require("@budibase/auth/roles") +const { AccessController } = require("@budibase/backend-core/roles") exports.fetch = async ctx => { const appId = ctx.appId diff --git a/packages/server/src/api/controllers/user.js b/packages/server/src/api/controllers/user.js index 902f6ce7e5..d87afc4309 100644 --- a/packages/server/src/api/controllers/user.js +++ b/packages/server/src/api/controllers/user.js @@ -8,10 +8,13 @@ const { InternalTables } = require("../../db/utils") const { getGlobalUsers, getRawGlobalUser } = require("../../utilities/global") const { getFullUser } = require("../../utilities/users") const { isEqual } = require("lodash") -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") -const { getDevelopmentAppID, getDeployedAppIDs } = require("@budibase/auth/db") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") +const { + getDevelopmentAppID, + getDeployedAppIDs, +} = require("@budibase/backend-core/db") const { doesDatabaseExist } = require("../../utilities") -const { UserStatus } = require("@budibase/auth/constants") +const { UserStatus } = require("@budibase/backend-core/constants") async function rawMetadata(db) { return ( diff --git a/packages/server/src/api/controllers/webhook.js b/packages/server/src/api/controllers/webhook.js index 2d687955e3..0230fb481b 100644 --- a/packages/server/src/api/controllers/webhook.js +++ b/packages/server/src/api/controllers/webhook.js @@ -3,7 +3,7 @@ const { generateWebhookID, getWebhookParams } = require("../../db/utils") const toJsonSchema = require("to-json-schema") const validate = require("jsonschema").validate const triggers = require("../../automations/triggers") -const { getDeployedAppID } = require("@budibase/auth/db") +const { getDeployedAppID } = require("@budibase/backend-core/db") const AUTOMATION_DESCRIPTION = "Generated from Webhook Schema" diff --git a/packages/server/src/api/index.js b/packages/server/src/api/index.js index dfe1f83fb4..4a94063e31 100644 --- a/packages/server/src/api/index.js +++ b/packages/server/src/api/index.js @@ -4,7 +4,7 @@ const { auditLog, buildTenancyMiddleware, buildAppTenancyMiddleware, -} = require("@budibase/auth").auth +} = require("@budibase/backend-core/auth") const currentApp = require("../middleware/currentapp") const compress = require("koa-compress") const zlib = require("zlib") diff --git a/packages/server/src/api/routes/apikeys.js b/packages/server/src/api/routes/apikeys.js index d1174eb475..315cffb41a 100644 --- a/packages/server/src/api/routes/apikeys.js +++ b/packages/server/src/api/routes/apikeys.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/apikeys") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/application.js b/packages/server/src/api/routes/application.js index 1a21cc8216..4a7949a2bb 100644 --- a/packages/server/src/api/routes/application.js +++ b/packages/server/src/api/routes/application.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/application") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const usage = require("../../middleware/usageQuota") const router = Router() diff --git a/packages/server/src/api/routes/automation.js b/packages/server/src/api/routes/automation.js index 599b16b583..2bec83d75e 100644 --- a/packages/server/src/api/routes/automation.js +++ b/packages/server/src/api/routes/automation.js @@ -6,7 +6,7 @@ const { BUILDER, PermissionLevels, PermissionTypes, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const Joi = require("joi") const { bodyResource, paramResource } = require("../../middleware/resourceId") const { diff --git a/packages/server/src/api/routes/backup.js b/packages/server/src/api/routes/backup.js index 51c53e37b6..83387ea75a 100644 --- a/packages/server/src/api/routes/backup.js +++ b/packages/server/src/api/routes/backup.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/backup") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/cloud.js b/packages/server/src/api/routes/cloud.js index 02b501c399..3cee889abf 100644 --- a/packages/server/src/api/routes/cloud.js +++ b/packages/server/src/api/routes/cloud.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/cloud") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/component.js b/packages/server/src/api/routes/component.js index 7b14b2b440..0f122169aa 100644 --- a/packages/server/src/api/routes/component.js +++ b/packages/server/src/api/routes/component.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/component") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/datasource.js b/packages/server/src/api/routes/datasource.js index ab5289176a..270e4e286e 100644 --- a/packages/server/src/api/routes/datasource.js +++ b/packages/server/src/api/routes/datasource.js @@ -6,7 +6,7 @@ const { BUILDER, PermissionLevels, PermissionTypes, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const Joi = require("joi") const { DataSourceOperation } = require("../../constants") diff --git a/packages/server/src/api/routes/deploy.js b/packages/server/src/api/routes/deploy.js index 261a440c2e..762646435a 100644 --- a/packages/server/src/api/routes/deploy.js +++ b/packages/server/src/api/routes/deploy.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/deploy") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/dev.js b/packages/server/src/api/routes/dev.js index 0d9bd118aa..165149ca8b 100644 --- a/packages/server/src/api/routes/dev.js +++ b/packages/server/src/api/routes/dev.js @@ -2,7 +2,7 @@ const Router = require("@koa/router") const controller = require("../controllers/dev") const env = require("../../environment") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/hosting.js b/packages/server/src/api/routes/hosting.js index 29e229f843..5af2d3c622 100644 --- a/packages/server/src/api/routes/hosting.js +++ b/packages/server/src/api/routes/hosting.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/hosting") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/integration.js b/packages/server/src/api/routes/integration.js index 6b523867c3..ebe79d978e 100644 --- a/packages/server/src/api/routes/integration.js +++ b/packages/server/src/api/routes/integration.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/integration") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/layout.js b/packages/server/src/api/routes/layout.js index ad3ac0aa9e..fa04b63402 100644 --- a/packages/server/src/api/routes/layout.js +++ b/packages/server/src/api/routes/layout.js @@ -1,6 +1,6 @@ const Router = require("@koa/router") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const controller = require("../controllers/layout") const router = Router() diff --git a/packages/server/src/api/routes/metadata.js b/packages/server/src/api/routes/metadata.js index f4eba64358..129e72b5e7 100644 --- a/packages/server/src/api/routes/metadata.js +++ b/packages/server/src/api/routes/metadata.js @@ -5,7 +5,7 @@ const { AppType, } = require("../../middleware/appInfo") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/permission.js b/packages/server/src/api/routes/permission.js index f395b13577..a868219e83 100644 --- a/packages/server/src/api/routes/permission.js +++ b/packages/server/src/api/routes/permission.js @@ -1,7 +1,10 @@ const Router = require("@koa/router") const controller = require("../controllers/permission") const authorized = require("../../middleware/authorized") -const { BUILDER, PermissionLevels } = require("@budibase/auth/permissions") +const { + BUILDER, + PermissionLevels, +} = require("@budibase/backend-core/permissions") const Joi = require("joi") const joiValidator = require("../../middleware/joi-validator") diff --git a/packages/server/src/api/routes/query.js b/packages/server/src/api/routes/query.js index 466fb1efaf..37a26f6808 100644 --- a/packages/server/src/api/routes/query.js +++ b/packages/server/src/api/routes/query.js @@ -5,7 +5,7 @@ const { PermissionLevels, PermissionTypes, BUILDER, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const { bodyResource, bodySubResource, diff --git a/packages/server/src/api/routes/role.js b/packages/server/src/api/routes/role.js index 8736bb93c6..bf20b01221 100644 --- a/packages/server/src/api/routes/role.js +++ b/packages/server/src/api/routes/role.js @@ -7,7 +7,7 @@ const { BUILTIN_PERMISSION_IDS, BUILDER, PermissionLevels, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/routing.js b/packages/server/src/api/routes/routing.js index 4d75705f14..45ccb7bb64 100644 --- a/packages/server/src/api/routes/routing.js +++ b/packages/server/src/api/routes/routing.js @@ -1,6 +1,6 @@ const Router = require("@koa/router") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const controller = require("../controllers/routing") const router = Router() diff --git a/packages/server/src/api/routes/row.js b/packages/server/src/api/routes/row.js index 8251328df3..aa300108f1 100644 --- a/packages/server/src/api/routes/row.js +++ b/packages/server/src/api/routes/row.js @@ -9,7 +9,7 @@ const { const { PermissionLevels, PermissionTypes, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/screen.js b/packages/server/src/api/routes/screen.js index 3a9baa25fc..cfce67a5dc 100644 --- a/packages/server/src/api/routes/screen.js +++ b/packages/server/src/api/routes/screen.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/screen") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const joiValidator = require("../../middleware/joi-validator") const Joi = require("joi") diff --git a/packages/server/src/api/routes/script.js b/packages/server/src/api/routes/script.js index cda8fa8df9..d0d3214db3 100644 --- a/packages/server/src/api/routes/script.js +++ b/packages/server/src/api/routes/script.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/script") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/static.js b/packages/server/src/api/routes/static.js index 6b695e5ddf..b40d5fe4e9 100644 --- a/packages/server/src/api/routes/static.js +++ b/packages/server/src/api/routes/static.js @@ -6,7 +6,7 @@ const { BUILDER, PermissionTypes, PermissionLevels, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const env = require("../../environment") const { paramResource } = require("../../middleware/resourceId") diff --git a/packages/server/src/api/routes/table.js b/packages/server/src/api/routes/table.js index d8ddbe8133..7b12b9e911 100644 --- a/packages/server/src/api/routes/table.js +++ b/packages/server/src/api/routes/table.js @@ -6,7 +6,7 @@ const { BUILDER, PermissionLevels, PermissionTypes, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const joiValidator = require("../../middleware/joi-validator") const Joi = require("joi") diff --git a/packages/server/src/api/routes/templates.js b/packages/server/src/api/routes/templates.js index ee29730406..710475db84 100644 --- a/packages/server/src/api/routes/templates.js +++ b/packages/server/src/api/routes/templates.js @@ -1,7 +1,7 @@ const Router = require("@koa/router") const controller = require("../controllers/templates") const authorized = require("../../middleware/authorized") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/tests/datasource.spec.js b/packages/server/src/api/routes/tests/datasource.spec.js index 04f4dd77b8..880cc338a2 100644 --- a/packages/server/src/api/routes/tests/datasource.spec.js +++ b/packages/server/src/api/routes/tests/datasource.spec.js @@ -4,6 +4,7 @@ let setup = require("./utilities") let { basicDatasource } = setup.structures let { checkBuilderEndpoint } = require("./utilities/TestFunctions") const pg = require("pg") +const { checkCacheForDynamicVariable } = require("../../../threads/utils") describe("/datasources", () => { let request = setup.getRequest() @@ -31,6 +32,50 @@ describe("/datasources", () => { }) }) + describe("update", () => { + it("should update an existing datasource", async () => { + datasource.name = "Updated Test" + const res = await request + .put(`/api/datasources/${datasource._id}`) + .send(datasource) + .set(config.defaultHeaders()) + .expect('Content-Type', /json/) + .expect(200) + + expect(res.body.datasource.name).toEqual("Updated Test") + expect(res.body.errors).toBeUndefined() + }) + + describe("dynamic variables", () => { + async function preview(datasource, fields) { + return config.previewQuery(request, config, datasource, fields) + } + + it("should invalidate changed or removed variables", async () => { + const { datasource, query } = await config.dynamicVariableDatasource() + // preview once to cache variables + await preview(datasource, { path: "www.test.com", queryString: "test={{ variable3 }}" }) + // check variables in cache + let contents = await checkCacheForDynamicVariable(query._id, "variable3") + expect(contents.rows.length).toEqual(1) + + // update the datasource to remove the variables + datasource.config.dynamicVariables = [] + const res = await request + .put(`/api/datasources/${datasource._id}`) + .send(datasource) + .set(config.defaultHeaders()) + .expect('Content-Type', /json/) + .expect(200) + expect(res.body.errors).toBeUndefined() + + // check variables no longer in cache + contents = await checkCacheForDynamicVariable(query._id, "variable3") + expect(contents).toBe(null) + }) + }) + }) + describe("fetch", () => { it("returns all the datasources from the server", async () => { const res = await request diff --git a/packages/server/src/api/routes/tests/permissions.spec.js b/packages/server/src/api/routes/tests/permissions.spec.js index 0304e551cc..2b231dbe64 100644 --- a/packages/server/src/api/routes/tests/permissions.spec.js +++ b/packages/server/src/api/routes/tests/permissions.spec.js @@ -1,4 +1,4 @@ -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const setup = require("./utilities") const { basicRow } = setup.structures diff --git a/packages/server/src/api/routes/tests/query.spec.js b/packages/server/src/api/routes/tests/query.spec.js index c8f842e584..9357d53cde 100644 --- a/packages/server/src/api/routes/tests/query.spec.js +++ b/packages/server/src/api/routes/tests/query.spec.js @@ -4,7 +4,7 @@ jest.mock("node-fetch") // Mock isProdAppID to we can later mock the implementation and pretend we are // using prod app IDs -const authDb = require("@budibase/auth/db") +const authDb = require("@budibase/backend-core/db") const { isProdAppID } = authDb const mockIsProdAppID = jest.fn(isProdAppID) authDb.isProdAppID = mockIsProdAppID @@ -229,52 +229,14 @@ describe("/queries", () => { }) }) - describe("test variables", () => { - async function restDatasource(cfg) { - return await config.createDatasource({ - datasource: { - ...basicDatasource().datasource, - source: "REST", - config: cfg || {}, - }, - }) - } - - async function dynamicVariableDatasource() { - const datasource = await restDatasource() - const basedOnQuery = await config.createQuery({ - ...basicQuery(datasource._id), - fields: { - path: "www.google.com", - }, - }) - await config.updateDatasource({ - ...datasource, - config: { - dynamicVariables: [ - { queryId: basedOnQuery._id, name: "variable3", value: "{{ data.0.[value] }}" } - ] - } - }) - return { datasource, query: basedOnQuery } - } + describe("variables", () => { async function preview(datasource, fields) { - return await request - .post(`/api/queries/preview`) - .send({ - datasourceId: datasource._id, - parameters: {}, - fields, - queryVerb: "read", - }) - .set(config.defaultHeaders()) - .expect("Content-Type", /json/) - .expect(200) + return config.previewQuery(request, config, datasource, fields) } it("should work with static variables", async () => { - const datasource = await restDatasource({ + const datasource = await config.restDatasource({ staticVariables: { variable: "google", variable2: "1", @@ -290,7 +252,7 @@ describe("/queries", () => { }) it("should work with dynamic variables", async () => { - const { datasource } = await dynamicVariableDatasource() + const { datasource } = await config.dynamicVariableDatasource() const res = await preview(datasource, { path: "www.google.com", queryString: "test={{ variable3 }}", @@ -300,7 +262,7 @@ describe("/queries", () => { }) it("check that it automatically retries on fail with cached dynamics", async () => { - const { datasource, query: base } = await dynamicVariableDatasource() + const { datasource, query: base } = await config.dynamicVariableDatasource() // preview once to cache await preview(datasource, { path: "www.google.com", queryString: "test={{ variable3 }}" }) // check its in cache @@ -313,5 +275,24 @@ describe("/queries", () => { expect(res.body.schemaFields).toEqual(["fails", "url", "opts"]) expect(res.body.rows[0].fails).toEqual(1) }) + + it("deletes variables when linked query is deleted", async () => { + const { datasource, query: base } = await config.dynamicVariableDatasource() + // preview once to cache + await preview(datasource, { path: "www.google.com", queryString: "test={{ variable3 }}" }) + // check its in cache + let contents = await checkCacheForDynamicVariable(base._id, "variable3") + expect(contents.rows.length).toEqual(1) + + // delete the query + await request + .delete(`/api/queries/${base._id}/${base._rev}`) + .set(config.defaultHeaders()) + .expect(200) + + // check variables no longer in cache + contents = await checkCacheForDynamicVariable(base._id, "variable3") + expect(contents).toBe(null) + }) }) }) diff --git a/packages/server/src/api/routes/tests/role.spec.js b/packages/server/src/api/routes/tests/role.spec.js index d74a84b2b2..31fd9997d8 100644 --- a/packages/server/src/api/routes/tests/role.spec.js +++ b/packages/server/src/api/routes/tests/role.spec.js @@ -1,7 +1,7 @@ -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const { BUILTIN_PERMISSION_IDS, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const setup = require("./utilities") const { basicRole } = setup.structures diff --git a/packages/server/src/api/routes/tests/routing.spec.js b/packages/server/src/api/routes/tests/routing.spec.js index 079fe0dedc..fdc414448c 100644 --- a/packages/server/src/api/routes/tests/routing.spec.js +++ b/packages/server/src/api/routes/tests/routing.spec.js @@ -1,7 +1,7 @@ const setup = require("./utilities") const { basicScreen } = setup.structures const { checkBuilderEndpoint } = require("./utilities/TestFunctions") -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const route = "/test" diff --git a/packages/server/src/api/routes/tests/user.spec.js b/packages/server/src/api/routes/tests/user.spec.js index a9e98f2555..29c33b3899 100644 --- a/packages/server/src/api/routes/tests/user.spec.js +++ b/packages/server/src/api/routes/tests/user.spec.js @@ -1,4 +1,4 @@ -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const { checkPermissionsEndpoint } = require("./utilities/TestFunctions") const setup = require("./utilities") diff --git a/packages/server/src/api/routes/tests/utilities/TestFunctions.js b/packages/server/src/api/routes/tests/utilities/TestFunctions.js index 857e902b66..9bd54f0d75 100644 --- a/packages/server/src/api/routes/tests/utilities/TestFunctions.js +++ b/packages/server/src/api/routes/tests/utilities/TestFunctions.js @@ -2,7 +2,7 @@ const rowController = require("../../../controllers/row") const appController = require("../../../controllers/application") const CouchDB = require("../../../../db") const { AppStatus } = require("../../../../db/utils") -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const { TENANT_ID } = require("../../../../tests/utilities/structures") function Request(appId, params) { diff --git a/packages/server/src/api/routes/user.js b/packages/server/src/api/routes/user.js index 9acd599b71..5ac446d54e 100644 --- a/packages/server/src/api/routes/user.js +++ b/packages/server/src/api/routes/user.js @@ -4,7 +4,7 @@ const authorized = require("../../middleware/authorized") const { PermissionLevels, PermissionTypes, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/view.js b/packages/server/src/api/routes/view.js index b72fe1ac26..9d57d722e1 100644 --- a/packages/server/src/api/routes/view.js +++ b/packages/server/src/api/routes/view.js @@ -7,7 +7,7 @@ const { BUILDER, PermissionTypes, PermissionLevels, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const router = Router() diff --git a/packages/server/src/api/routes/webhook.js b/packages/server/src/api/routes/webhook.js index 73790acd64..561eb8c1ee 100644 --- a/packages/server/src/api/routes/webhook.js +++ b/packages/server/src/api/routes/webhook.js @@ -2,7 +2,7 @@ const Router = require("@koa/router") const controller = require("../controllers/webhook") const authorized = require("../../middleware/authorized") const joiValidator = require("../../middleware/joi-validator") -const { BUILDER } = require("@budibase/auth/permissions") +const { BUILDER } = require("@budibase/backend-core/permissions") const Joi = require("joi") const router = Router() diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index c44b6123aa..060169a777 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -3,7 +3,7 @@ import { ExtendableContext } from "koa" const env = require("./environment") const CouchDB = require("./db") -require("@budibase/auth").init(CouchDB) +require("@budibase/backend-core").init(CouchDB) const Koa = require("koa") const destroyable = require("server-destroy") const koaBody = require("koa-body") diff --git a/packages/server/src/automations/bullboard.js b/packages/server/src/automations/bullboard.js index 67f3f4ce56..32336c4714 100644 --- a/packages/server/src/automations/bullboard.js +++ b/packages/server/src/automations/bullboard.js @@ -6,7 +6,7 @@ const Queue = env.isTest() ? require("../utilities/queue/inMemoryQueue") : require("bull") const { JobQueues } = require("../constants") -const { utils } = require("@budibase/auth/redis") +const { utils } = require("@budibase/backend-core/redis") const { opts, redisProtocolUrl } = utils.getRedisOptions() const CLEANUP_PERIOD_MS = 60 * 1000 diff --git a/packages/server/src/automations/steps/executeQuery.js b/packages/server/src/automations/steps/executeQuery.js index 0fa8661561..99c2c40783 100644 --- a/packages/server/src/automations/steps/executeQuery.js +++ b/packages/server/src/automations/steps/executeQuery.js @@ -72,7 +72,7 @@ exports.run = async function ({ inputs, appId, emitter }) { }) try { - await queryController.execute(ctx) + await queryController.executeV1(ctx) const { data, ...rest } = ctx.body return { response: data, diff --git a/packages/server/src/automations/utils.js b/packages/server/src/automations/utils.js index d9c96963ab..4a554793f8 100644 --- a/packages/server/src/automations/utils.js +++ b/packages/server/src/automations/utils.js @@ -6,7 +6,7 @@ const { queue } = require("./bullboard") const newid = require("../db/newid") const { updateEntityMetadata } = require("../utilities") const { MetadataTypes } = require("../constants") -const { getDeployedAppID } = require("@budibase/auth/db") +const { getDeployedAppID } = require("@budibase/backend-core/db") const { cloneDeep } = require("lodash/fp") const WH_STEP_ID = definitions.WEBHOOK.stepId diff --git a/packages/server/src/constants/index.js b/packages/server/src/constants/index.js index c3cb9b7a58..b63b71d2c2 100644 --- a/packages/server/src/constants/index.js +++ b/packages/server/src/constants/index.js @@ -1,6 +1,6 @@ -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") -const { UserStatus } = require("@budibase/auth").constants -const { ObjectStoreBuckets } = require("@budibase/auth").objectStore +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") +const { UserStatus } = require("@budibase/backend-core/constants") +const { ObjectStoreBuckets } = require("@budibase/backend-core/objectStore") exports.JobQueues = { AUTOMATIONS: "automationQueue", diff --git a/packages/server/src/constants/screens.js b/packages/server/src/constants/screens.js index 49c21367cd..23f8bc88df 100644 --- a/packages/server/src/constants/screens.js +++ b/packages/server/src/constants/screens.js @@ -1,4 +1,4 @@ -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const { BASE_LAYOUT_PROP_IDS } = require("./layouts") exports.createHomeScreen = () => ({ diff --git a/packages/server/src/db/client.js b/packages/server/src/db/client.js index a453ad8561..5d0df7ef05 100644 --- a/packages/server/src/db/client.js +++ b/packages/server/src/db/client.js @@ -1,5 +1,5 @@ const PouchDB = require("pouchdb") -const { getCouchUrl } = require("@budibase/auth/db") +const { getCouchUrl } = require("@budibase/backend-core/db") const replicationStream = require("pouchdb-replication-stream") const allDbs = require("pouchdb-all-dbs") const find = require("pouchdb-find") diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js index 2d9ef87c87..e19fed0201 100644 --- a/packages/server/src/db/utils.js +++ b/packages/server/src/db/utils.js @@ -9,7 +9,7 @@ const { StaticDatabases, isDevAppID, isProdAppID, -} = require("@budibase/auth/db") +} = require("@budibase/backend-core/db") const UNICODE_MAX = "\ufff0" diff --git a/packages/server/src/integrations/base/sqlTable.ts b/packages/server/src/integrations/base/sqlTable.ts index 53d123e38b..47566bdcd5 100644 --- a/packages/server/src/integrations/base/sqlTable.ts +++ b/packages/server/src/integrations/base/sqlTable.ts @@ -36,7 +36,7 @@ function generateSchema( case FieldTypes.STRING: case FieldTypes.OPTIONS: case FieldTypes.LONGFORM: - schema.string(key) + schema.text(key) break case FieldTypes.NUMBER: // if meta is specified then this is a junction table entry diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index 5c5c506704..3199ce3bde 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -208,7 +208,7 @@ module RestModule { const main = `${path}?${queryString}` let complete = main - if (this.config.url && !main.startsWith(this.config.url)) { + if (this.config.url && !main.startsWith("http")) { complete = !this.config.url ? main : `${this.config.url}/${main}` } if (!complete.startsWith("http")) { diff --git a/packages/server/src/middleware/authorized.js b/packages/server/src/middleware/authorized.js index 5f21c2d026..b463895a80 100644 --- a/packages/server/src/middleware/authorized.js +++ b/packages/server/src/middleware/authorized.js @@ -2,11 +2,11 @@ const { getUserRoleHierarchy, getRequiredResourceRole, BUILTIN_ROLE_IDS, -} = require("@budibase/auth/roles") +} = require("@budibase/backend-core/roles") const { PermissionTypes, doesHaveBasePermission, -} = require("@budibase/auth/permissions") +} = require("@budibase/backend-core/permissions") const builderMiddleware = require("./builder") const { isWebhookEndpoint } = require("./utils") diff --git a/packages/server/src/middleware/builder.js b/packages/server/src/middleware/builder.js index f8a84c4c25..d2a8ee80f0 100644 --- a/packages/server/src/middleware/builder.js +++ b/packages/server/src/middleware/builder.js @@ -7,8 +7,8 @@ const { } = require("../utilities/redis") const CouchDB = require("../db") const { DocumentTypes } = require("../db/utils") -const { PermissionTypes } = require("@budibase/auth/permissions") -const { app: appCache } = require("@budibase/auth/cache") +const { PermissionTypes } = require("@budibase/backend-core/permissions") +const { app: appCache } = require("@budibase/backend-core/cache") const DEBOUNCE_TIME_SEC = 30 diff --git a/packages/server/src/middleware/currentapp.js b/packages/server/src/middleware/currentapp.js index 5682a860b9..69f80c895b 100644 --- a/packages/server/src/middleware/currentapp.js +++ b/packages/server/src/middleware/currentapp.js @@ -1,11 +1,15 @@ -const { getAppId, setCookie, getCookie, clearCookie } = - require("@budibase/auth").utils -const { Cookies } = require("@budibase/auth").constants -const { getRole } = require("@budibase/auth/roles") -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { + getAppId, + setCookie, + getCookie, + clearCookie, +} = require("@budibase/backend-core/utils") +const { Cookies } = require("@budibase/backend-core/constants") +const { getRole } = require("@budibase/backend-core/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const { generateUserMetadataID, isDevAppID } = require("../db/utils") -const { dbExists } = require("@budibase/auth/db") -const { isUserInAppTenant } = require("@budibase/auth/tenancy") +const { dbExists } = require("@budibase/backend-core/db") +const { isUserInAppTenant } = require("@budibase/backend-core/tenancy") const { getCachedSelf } = require("../utilities/global") const CouchDB = require("../db") const env = require("../environment") diff --git a/packages/server/src/middleware/tests/authorized.spec.js b/packages/server/src/middleware/tests/authorized.spec.js index d7052b323b..9775965b5a 100644 --- a/packages/server/src/middleware/tests/authorized.spec.js +++ b/packages/server/src/middleware/tests/authorized.spec.js @@ -9,8 +9,8 @@ jest.mock("../../environment", () => ({ ) const authorizedMiddleware = require("../authorized") const env = require("../../environment") -const { PermissionTypes, PermissionLevels } = require("@budibase/auth/permissions") -require("@budibase/auth").init(require("../../db")) +const { PermissionTypes, PermissionLevels } = require("@budibase/backend-core/permissions") +require("@budibase/backend-core").init(require("../../db")) class TestConfiguration { constructor(role) { diff --git a/packages/server/src/middleware/tests/currentapp.spec.js b/packages/server/src/middleware/tests/currentapp.spec.js index d288320aea..27c88f3b48 100644 --- a/packages/server/src/middleware/tests/currentapp.spec.js +++ b/packages/server/src/middleware/tests/currentapp.spec.js @@ -23,7 +23,7 @@ function mockReset() { function mockAuthWithNoCookie() { jest.resetModules() mockWorker() - jest.mock("@budibase/auth/cache", () => ({ + jest.mock("@budibase/backend-core/cache", () => ({ user: { getUser: () => { return { @@ -32,34 +32,30 @@ function mockAuthWithNoCookie() { }, }, })) - jest.mock("@budibase/auth", () => ({ - utils: { - getAppId: jest.fn(), - setCookie: jest.fn(), - getCookie: jest.fn(), - }, - constants: { - Cookies: {}, - }, + jest.mock("@budibase/backend-core/utils", () => ({ + getAppId: jest.fn(), + setCookie: jest.fn(), + getCookie: jest.fn(), + })) + jest.mock("@budibase/backend-core/constants", () => ({ + Cookies: {}, })) } function mockAuthWithCookie() { jest.resetModules() mockWorker() - jest.mock("@budibase/auth", () => ({ - utils: { - getAppId: () => { - return "app_test" - }, - setCookie: jest.fn(), - getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}), + jest.mock("@budibase/backend-core/utils", () => ({ + getAppId: () => { + return "app_test" }, - constants: { - Cookies: { - Auth: "auth", - CurrentApp: "currentapp", - }, + setCookie: jest.fn(), + getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}), + })) + jest.mock("@budibase/backend-core/constants", () => ({ + Cookies: { + Auth: "auth", + CurrentApp: "currentapp", }, })) } @@ -121,7 +117,7 @@ describe("Current app middleware", () => { async function checkExpected(setCookie) { config.setUser() await config.executeMiddleware() - const cookieFn = require("@budibase/auth").utils.setCookie + let { setCookie: cookieFn } = require("@budibase/backend-core/utils") if (setCookie) { expect(cookieFn).toHaveBeenCalled() } else { @@ -140,32 +136,30 @@ describe("Current app middleware", () => { it("should perform correct when no cookie exists", async () => { mockReset() - jest.mock("@budibase/auth", () => ({ - utils: { - getAppId: () => { - return "app_test" - }, - setCookie: jest.fn(), - getCookie: jest.fn(), - }, - constants: { - Cookies: {}, + jest.mock("@budibase/backend-core/utils", () => ({ + getAppId: () => { + return "app_test" }, + setCookie: jest.fn(), + getCookie: jest.fn(), + })) + jest.mock("@budibase/backend-core/constants", () => ({ + Cookies: {}, })) await checkExpected(true) }) it("lastly check what occurs when cookie doesn't need updated", async () => { mockReset() - jest.mock("@budibase/auth", () => ({ - utils: { - getAppId: () => { - return "app_test" - }, - setCookie: jest.fn(), - getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}), + jest.mock("@budibase/backend-core/utils", () => ({ + getAppId: () => { + return "app_test" }, - constants: { Cookies: {} }, + setCookie: jest.fn(), + getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}), + })) + jest.mock("@budibase/backend-core/constants", () => ({ + Cookies: {}, })) await checkExpected(false) }) diff --git a/packages/server/src/middleware/tests/usageQuota.spec.js b/packages/server/src/middleware/tests/usageQuota.spec.js index 7a64b1a039..ae47d19207 100644 --- a/packages/server/src/middleware/tests/usageQuota.spec.js +++ b/packages/server/src/middleware/tests/usageQuota.spec.js @@ -6,7 +6,7 @@ jest.mock("../../environment", () => ({ isDev: () => true, _set: () => {}, })) -jest.mock("@budibase/auth/tenancy", () => ({ +jest.mock("@budibase/backend-core/tenancy", () => ({ getTenantId: () => "testing123" })) diff --git a/packages/server/src/middleware/usageQuota.js b/packages/server/src/middleware/usageQuota.js index 2b189b8660..bb5fa4de3f 100644 --- a/packages/server/src/middleware/usageQuota.js +++ b/packages/server/src/middleware/usageQuota.js @@ -1,7 +1,7 @@ const CouchDB = require("../db") const usageQuota = require("../utilities/usageQuota") const env = require("../environment") -const { getTenantId } = require("@budibase/auth/tenancy") +const { getTenantId } = require("@budibase/backend-core/tenancy") const { isExternalTable, isRowId: isExternalRowId, diff --git a/packages/server/src/tests/utilities/TestConfiguration.js b/packages/server/src/tests/utilities/TestConfiguration.js index f003a8a78d..06d81593a1 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.js +++ b/packages/server/src/tests/utilities/TestConfiguration.js @@ -1,4 +1,4 @@ -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const env = require("../../environment") const { basicTable, @@ -15,14 +15,14 @@ const { const controllers = require("./controllers") const supertest = require("supertest") const { cleanup } = require("../../utilities/fileSystem") -const { Cookies, Headers } = require("@budibase/auth").constants -const { jwt } = require("@budibase/auth").auth -const auth = require("@budibase/auth") -const { getGlobalDB } = require("@budibase/auth/tenancy") -const { createASession } = require("@budibase/auth/sessions") -const { user: userCache } = require("@budibase/auth/cache") +const { Cookies, Headers } = require("@budibase/backend-core/constants") +const { jwt } = require("@budibase/backend-core/auth") +const core = require("@budibase/backend-core") +const { getGlobalDB } = require("@budibase/backend-core/tenancy") +const { createASession } = require("@budibase/backend-core/sessions") +const { user: userCache } = require("@budibase/backend-core/cache") const CouchDB = require("../../db") -auth.init(CouchDB) +core.init(CouchDB) const GLOBAL_USER_ID = "us_uuid1" const EMAIL = "babs@babs.com" @@ -326,6 +326,53 @@ class TestConfiguration { return this.datasource } + async restDatasource(cfg) { + return this.createDatasource({ + datasource: { + ...basicDatasource().datasource, + source: "REST", + config: cfg || {}, + }, + }) + } + + async dynamicVariableDatasource() { + let datasource = await this.restDatasource() + const basedOnQuery = await this.createQuery({ + ...basicQuery(datasource._id), + fields: { + path: "www.google.com", + }, + }) + datasource = await this.updateDatasource({ + ...datasource, + config: { + dynamicVariables: [ + { + queryId: basedOnQuery._id, + name: "variable3", + value: "{{ data.0.[value] }}", + }, + ], + }, + }) + return { datasource, query: basedOnQuery } + } + + async previewQuery(request, config, datasource, fields) { + return request + .post(`/api/queries/preview`) + .send({ + datasourceId: datasource._id, + parameters: {}, + fields, + queryVerb: "read", + }) + .set(config.defaultHeaders()) + .expect("Content-Type", /json/) + .expect(200) + } + async createQuery(config = null) { if (!this.datasource && !config) { throw "No data source created for query." diff --git a/packages/server/src/tests/utilities/structures.js b/packages/server/src/tests/utilities/structures.js index 9c900fec09..45a8f2dece 100644 --- a/packages/server/src/tests/utilities/structures.js +++ b/packages/server/src/tests/utilities/structures.js @@ -1,5 +1,5 @@ -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") -const { BUILTIN_PERMISSION_IDS } = require("@budibase/auth/permissions") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") +const { BUILTIN_PERMISSION_IDS } = require("@budibase/backend-core/permissions") const { createHomeScreen } = require("../../constants/screens") const { EMPTY_LAYOUT } = require("../../constants/layouts") const { cloneDeep } = require("lodash/fp") diff --git a/packages/server/src/threads/automation.js b/packages/server/src/threads/automation.js index fc9e2a21fc..2a39773520 100644 --- a/packages/server/src/threads/automation.js +++ b/packages/server/src/threads/automation.js @@ -4,10 +4,10 @@ const actions = require("../automations/actions") const automationUtils = require("../automations/automationUtils") const AutomationEmitter = require("../events/AutomationEmitter") const { processObject } = require("@budibase/string-templates") -const { DEFAULT_TENANT_ID } = require("@budibase/auth").constants +const { DEFAULT_TENANT_ID } = require("@budibase/backend-core/constants") const CouchDB = require("../db") const { DocumentTypes, isDevAppID } = require("../db/utils") -const { doInTenant } = require("@budibase/auth/tenancy") +const { doInTenant } = require("@budibase/backend-core/tenancy") const usage = require("../utilities/usageQuota") const { definitions: triggerDefs } = require("../automations/triggerInfo") diff --git a/packages/server/src/threads/query.js b/packages/server/src/threads/query.js index ad461008df..35164ac642 100644 --- a/packages/server/src/threads/query.js +++ b/packages/server/src/threads/query.js @@ -58,7 +58,10 @@ class QueryRunner { // transform as required if (transformer) { - const runner = new ScriptRunner(transformer, { data: rows }) + const runner = new ScriptRunner(transformer, { + data: rows, + params: parameters, + }) rows = runner.execute() } diff --git a/packages/server/src/threads/utils.js b/packages/server/src/threads/utils.js index 71edd54843..bf89791874 100644 --- a/packages/server/src/threads/utils.js +++ b/packages/server/src/threads/utils.js @@ -1,8 +1,8 @@ const env = require("../environment") const CouchDB = require("../db") -const { init } = require("@budibase/auth") -const redis = require("@budibase/auth/redis") -const { SEPARATOR } = require("@budibase/auth/db") +const { init } = require("@budibase/backend-core") +const redis = require("@budibase/backend-core/redis") +const { SEPARATOR } = require("@budibase/backend-core/db") const VARIABLE_TTL_SECONDS = 3600 let client @@ -38,10 +38,11 @@ exports.checkCacheForDynamicVariable = async (queryId, variable) => { } exports.invalidateDynamicVariables = async cachedVars => { + const cache = await getClient() let promises = [] for (let variable of cachedVars) { promises.push( - client.delete(makeVariableKey(variable.queryId, variable.name)) + cache.delete(makeVariableKey(variable.queryId, variable.name)) ) } await Promise.all(promises) diff --git a/packages/server/src/utilities/budibaseDir.js b/packages/server/src/utilities/budibaseDir.js index b61a807306..48ae7eb0e7 100644 --- a/packages/server/src/utilities/budibaseDir.js +++ b/packages/server/src/utilities/budibaseDir.js @@ -1,7 +1,7 @@ const { join } = require("./centralPath") const { homedir } = require("os") const env = require("../environment") -const { budibaseTempDir } = require("@budibase/auth").objectStore +const { budibaseTempDir } = require("@budibase/backend-core/objectStore") module.exports.budibaseAppsDir = function () { return env.BUDIBASE_DIR || join(homedir(), ".budibase") diff --git a/packages/server/src/utilities/fileSystem/utilities.js b/packages/server/src/utilities/fileSystem/utilities.js index c33ce083c1..e85f4f9c79 100644 --- a/packages/server/src/utilities/fileSystem/utilities.js +++ b/packages/server/src/utilities/fileSystem/utilities.js @@ -2,13 +2,14 @@ const { ObjectStore, makeSureBucketExists, upload, + deleteFiles, streamUpload, retrieve, retrieveToTmp, deleteFolder, uploadDirectory, downloadTarball, -} = require("@budibase/auth").objectStore +} = require("@budibase/backend-core/objectStore") /*********************************** * NOTE * @@ -28,3 +29,4 @@ exports.retrieveToTmp = retrieveToTmp exports.deleteFolder = deleteFolder exports.uploadDirectory = uploadDirectory exports.downloadTarball = downloadTarball +exports.deleteFiles = deleteFiles diff --git a/packages/server/src/utilities/global.js b/packages/server/src/utilities/global.js index 6527aa0601..7ef1c09405 100644 --- a/packages/server/src/utilities/global.js +++ b/packages/server/src/utilities/global.js @@ -2,11 +2,14 @@ const { getMultiIDParams, getGlobalIDFromUserMetadataID, } = require("../db/utils") -const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") -const { getDeployedAppID } = require("@budibase/auth/db") -const { getGlobalUserParams } = require("@budibase/auth/db") -const { user: userCache } = require("@budibase/auth/cache") -const { getGlobalDB, isUserInAppTenant } = require("@budibase/auth/tenancy") +const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") +const { getDeployedAppID } = require("@budibase/backend-core/db") +const { getGlobalUserParams } = require("@budibase/backend-core/db") +const { user: userCache } = require("@budibase/backend-core/cache") +const { + getGlobalDB, + isUserInAppTenant, +} = require("@budibase/backend-core/tenancy") const env = require("../environment") exports.updateAppRole = (appId, user) => { diff --git a/packages/server/src/utilities/index.js b/packages/server/src/utilities/index.js index 389514cc4b..77d3d46282 100644 --- a/packages/server/src/utilities/index.js +++ b/packages/server/src/utilities/index.js @@ -1,6 +1,6 @@ const env = require("../environment") const { OBJ_STORE_DIRECTORY } = require("../constants") -const { sanitizeKey } = require("@budibase/auth/src/objectStore") +const { sanitizeKey } = require("@budibase/backend-core/objectStore") const CouchDB = require("../db") const { generateMetadataID } = require("../db/utils") const Readable = require("stream").Readable diff --git a/packages/server/src/utilities/redis.js b/packages/server/src/utilities/redis.js index 151feabdbb..ca2fa3254d 100644 --- a/packages/server/src/utilities/redis.js +++ b/packages/server/src/utilities/redis.js @@ -1,4 +1,4 @@ -const { Client, utils } = require("@budibase/auth/redis") +const { Client, utils } = require("@budibase/backend-core/redis") const { getGlobalIDFromUserMetadataID } = require("../db/utils") const APP_DEV_LOCK_SECONDS = 600 diff --git a/packages/server/src/utilities/rowProcessor/index.js b/packages/server/src/utilities/rowProcessor/index.js index 860063f173..4f5d72c179 100644 --- a/packages/server/src/utilities/rowProcessor/index.js +++ b/packages/server/src/utilities/rowProcessor/index.js @@ -3,6 +3,14 @@ const { cloneDeep } = require("lodash/fp") const { FieldTypes, AutoFieldSubTypes } = require("../../constants") const { attachmentsRelativeURL } = require("../index") const { processFormulas } = require("./utils") +const { deleteFiles } = require("../../utilities/fileSystem/utilities") +const { ObjectStoreBuckets } = require("../../constants") +const { + isProdAppID, + getDeployedAppID, + dbExists, +} = require("@budibase/backend-core/db") +const CouchDB = require("../../db") const BASE_AUTO_ID = 1 @@ -95,6 +103,23 @@ const TYPE_TRANSFORM_MAP = { }, } +/** + * Given the old state of the row and the new one after an update, this will + * find the keys that have been removed in the updated row. + */ +function getRemovedAttachmentKeys(oldRow, row, attachmentKey) { + if (!oldRow[attachmentKey]) { + return [] + } + const oldKeys = oldRow[attachmentKey].map(attachment => attachment.key) + // no attachments in new row, all removed + if (!row[attachmentKey]) { + return oldKeys + } + const newKeys = row[attachmentKey].map(attachment => attachment.key) + return oldKeys.filter(key => newKeys.indexOf(key) === -1) +} + /** * This will update any auto columns that are found on the row/table with the correct information based on * time now and the current logged in user making the request. @@ -272,3 +297,45 @@ exports.outputProcessing = async ( } return wasArray ? enriched : enriched[0] } + +/** + * Clean up any attachments that were attached to a row. + * @param {string} appId The ID of the app from which a row is being deleted. + * @param {object} table The table from which a row is being removed. + * @param {any} row optional - the row being removed. + * @param {any} rows optional - if multiple rows being deleted can do this in bulk. + * @param {any} oldRow optional - if updating a row this will determine the difference. + * @return {Promise} When all attachments have been removed this will return. + */ +exports.cleanupAttachments = async (appId, table, { row, rows, oldRow }) => { + if (!isProdAppID(appId)) { + const prodAppId = getDeployedAppID(appId) + // if prod exists, then don't allow deleting + const exists = await dbExists(CouchDB, prodAppId) + if (exists) { + return + } + } + let files = [] + function addFiles(row, key) { + if (row[key]) { + files = files.concat(row[key].map(attachment => attachment.key)) + } + } + for (let [key, schema] of Object.entries(table.schema)) { + if (schema.type !== FieldTypes.ATTACHMENT) { + continue + } + // if updating, need to manage the differences + if (oldRow && row) { + files = files.concat(getRemovedAttachmentKeys(oldRow, row, key)) + } else if (row) { + addFiles(row, key) + } else if (rows) { + rows.forEach(row => addFiles(row, key)) + } + } + if (files.length > 0) { + return deleteFiles(ObjectStoreBuckets.APPS, files) + } +} diff --git a/packages/server/src/utilities/security.js b/packages/server/src/utilities/security.js index 78b2f5b713..de5b696553 100644 --- a/packages/server/src/utilities/security.js +++ b/packages/server/src/utilities/security.js @@ -3,8 +3,11 @@ const { PermissionTypes, getBuiltinPermissionByID, isPermissionLevelHigherThanRead, -} = require("@budibase/auth/permissions") -const { lowerBuiltinRoleID, getBuiltinRoles } = require("@budibase/auth/roles") +} = require("@budibase/backend-core/permissions") +const { + lowerBuiltinRoleID, + getBuiltinRoles, +} = require("@budibase/backend-core/roles") const { DocumentTypes } = require("../db/utils") const CURRENTLY_SUPPORTED_LEVELS = [ diff --git a/packages/server/src/utilities/usageQuota.js b/packages/server/src/utilities/usageQuota.js index 1980b13ef0..73fe83a170 100644 --- a/packages/server/src/utilities/usageQuota.js +++ b/packages/server/src/utilities/usageQuota.js @@ -1,9 +1,9 @@ const env = require("../environment") -const { getGlobalDB } = require("@budibase/auth/tenancy") +const { getGlobalDB } = require("@budibase/backend-core/tenancy") const { StaticDatabases, generateNewUsageQuotaDoc, -} = require("@budibase/auth/db") +} = require("@budibase/backend-core/db") function getNewQuotaReset() { return Date.now() + 2592000000 diff --git a/packages/server/src/utilities/workerRequests.js b/packages/server/src/utilities/workerRequests.js index 6a15e1b243..92dffc8d3f 100644 --- a/packages/server/src/utilities/workerRequests.js +++ b/packages/server/src/utilities/workerRequests.js @@ -1,10 +1,10 @@ const fetch = require("node-fetch") const env = require("../environment") const { checkSlashesInUrl } = require("./index") -const { getDeployedAppID } = require("@budibase/auth/db") +const { getDeployedAppID } = require("@budibase/backend-core/db") const { updateAppRole } = require("./global") -const { Headers } = require("@budibase/auth/constants") -const { getTenantId, isTenantIdSet } = require("@budibase/auth/tenancy") +const { Headers } = require("@budibase/backend-core/constants") +const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy") function request(ctx, request) { if (!request.headers) { diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index e235d9f1a7..2f64782a81 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -983,10 +983,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/auth@^1.0.27-alpha.2": - version "1.0.34" - resolved "https://registry.yarnpkg.com/@budibase/auth/-/auth-1.0.34.tgz#f1daad174d494c5baae29ebfb2d0cf7a26d487bb" - integrity sha512-RN5xZVqk4D4GIFoTrm6kv6vxIcAyDgoopsGMYj8dQRCYWb6pvWzCKyDw4o1THXiK8BBD8ctFUE/FhtLXRj8F4w== +"@budibase/backend-core@^1.0.27-alpha.13": + version "1.0.27-alpha.13" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.27-alpha.13.tgz#89f46e081eb7b342f483fd0eccd72c42b2b2fa6c" + integrity sha512-NiasBvZ5wTpvANG9AjuO34DHMTqWQWSpabLcgwBY0tNG4ekh+wvSCPjCcUvN/bBpOzrVMQ8C4hmS4pvv342BhQ== dependencies: "@techpass/passport-openidconnect" "^0.3.0" aws-sdk "^2.901.0" @@ -1056,10 +1056,10 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/bbui@^1.0.34": - version "1.0.34" - resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.0.34.tgz#3eba93984cd0075aecbf4ca8451b301e623c7afa" - integrity sha512-9mVzIWx4dQ8LIy4ncJaJBVwuTx2LEMqZl1XRr/NAI3rsTv+HIULe+zCUJSCYM2MGoR3qKSU7geIzIuwnRa8k4Q== +"@budibase/bbui@^1.0.35": + version "1.0.35" + resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.0.35.tgz#a51886886772257d31e2c6346dbec46fe0c9fd85" + integrity sha512-8qeAzTujtO7uvhj+dMiyW4BTkQ7dC4xF1CNIwyuTnDwIeFDlXYgNb09VVRs3+nWcX2e2eC53EUs1RnLUoSlTsw== dependencies: "@adobe/spectrum-css-workflow-icons" "^1.2.1" "@spectrum-css/actionbutton" "^1.0.1" @@ -1106,14 +1106,14 @@ svelte-flatpickr "^3.2.3" svelte-portal "^1.0.0" -"@budibase/client@^1.0.27-alpha.2": - version "1.0.34" - resolved "https://registry.yarnpkg.com/@budibase/client/-/client-1.0.34.tgz#2bdac2030eabf780659481fa751cd7fecf1b609f" - integrity sha512-WGEVjwmKYv+B+J6crbia62BNFCzgKHEggsNAlCN3+IB+w9jxS2oiOJYPpYQnsSM2l4j4/Zbu9W30OhenSiB8kQ== +"@budibase/client@^1.0.27-alpha.13": + version "1.0.35" + resolved "https://registry.yarnpkg.com/@budibase/client/-/client-1.0.35.tgz#b832e7e7e35032fb35fe5492fbb721db1da15394" + integrity sha512-maL3V29PQb9VjgnPZq44GSDZCuamAGp01bheUeJxEeskjQqZUdf8QC7Frf1mT+ZjgKJf3gU6qtFOxmWRbVzVbw== dependencies: - "@budibase/bbui" "^1.0.34" + "@budibase/bbui" "^1.0.35" "@budibase/standard-components" "^0.9.139" - "@budibase/string-templates" "^1.0.34" + "@budibase/string-templates" "^1.0.35" regexparam "^1.3.0" shortid "^2.2.15" svelte-spa-router "^3.0.5" @@ -1163,10 +1163,10 @@ svelte-apexcharts "^1.0.2" svelte-flatpickr "^3.1.0" -"@budibase/string-templates@^1.0.27-alpha.2", "@budibase/string-templates@^1.0.34": - version "1.0.34" - resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-1.0.34.tgz#7e5f80a26db5d04063c0e78cdf37af88cff772c6" - integrity sha512-HWqXxQBXqVwBgCh3ptczVFxWOLHVUhuTShXCafRDgKAVY3d+LJzKGwiD40/oR/nUqeNtBbHgYWu8Z4gMQQYZhA== +"@budibase/string-templates@^1.0.27-alpha.13", "@budibase/string-templates@^1.0.35": + version "1.0.35" + resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-1.0.35.tgz#a888f1e9327bb36416336a91a95a43cb34e6a42d" + integrity sha512-8HxSv0ru+cgSmphqtOm1pmBM8rc0TRC/6RQGzQefmFFQFfm/SBLAVLLWRmZxAOYTxt4mittGWeL4y05FqEuocg== dependencies: "@budibase/handlebars-helpers" "^0.11.7" dayjs "^1.10.4" diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json index eb8102a0bb..da61e06da9 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/string-templates", - "version": "1.0.27-alpha.5", + "version": "1.0.27-alpha.13", "description": "Handlebars wrapper for Budibase templating.", "main": "src/index.cjs", "module": "dist/bundle.mjs", diff --git a/packages/worker/package.json b/packages/worker/package.json index a22f7cedbc..aff597b925 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/worker", "email": "hi@budibase.com", - "version": "1.0.27-alpha.5", + "version": "1.0.27-alpha.13", "description": "Budibase background service", "main": "src/index.js", "repository": { @@ -29,8 +29,8 @@ "author": "Budibase", "license": "GPL-3.0", "dependencies": { - "@budibase/auth": "^1.0.27-alpha.5", - "@budibase/string-templates": "^1.0.27-alpha.5", + "@budibase/backend-core": "^1.0.27-alpha.13", + "@budibase/string-templates": "^1.0.27-alpha.13", "@koa/router": "^8.0.0", "@sentry/node": "^6.0.0", "@techpass/passport-openidconnect": "^0.3.0", diff --git a/packages/worker/src/api/controllers/app.js b/packages/worker/src/api/controllers/app.js index 8f0d4f402f..c08603e57e 100644 --- a/packages/worker/src/api/controllers/app.js +++ b/packages/worker/src/api/controllers/app.js @@ -1,18 +1,29 @@ -const { getAllApps } = require("@budibase/auth/db") +const { + getAllApps, + getDeployedAppID, + isProdAppID, +} = require("@budibase/backend-core/db") const CouchDB = require("../../db") const URL_REGEX_SLASH = /\/|\\/g exports.getApps = async ctx => { - const apps = await getAllApps(CouchDB, { dev: true }) + const apps = await getAllApps(CouchDB, { all: true }) const body = {} for (let app of apps) { let url = app.url || encodeURI(`${app.name}`) url = `/${url.replace(URL_REGEX_SLASH, "")}` - body[url] = { - appId: app.appId, - name: app.name, - url, + const appId = app.appId, + isProd = isProdAppID(app.appId) + if (!body[url]) { + body[url] = { + appId: getDeployedAppID(appId), + name: app.name, + url, + deployed: isProd, + } + } else { + body[url].deployed = isProd || body[url].deployed } } ctx.body = body diff --git a/packages/worker/src/api/controllers/global/auth.js b/packages/worker/src/api/controllers/global/auth.js index 93a15a6514..2ba12194ca 100644 --- a/packages/worker/src/api/controllers/global/auth.js +++ b/packages/worker/src/api/controllers/global/auth.js @@ -1,7 +1,7 @@ -const authPkg = require("@budibase/auth") -const { getScopedConfig } = require("@budibase/auth/db") -const { google } = require("@budibase/auth/src/middleware") -const { oidc } = require("@budibase/auth/src/middleware") +const core = require("@budibase/backend-core") +const { getScopedConfig } = require("@budibase/backend-core/db") +const { google } = require("@budibase/backend-core/middleware") +const { oidc } = require("@budibase/backend-core/middleware") const { Configs, EmailTemplatePurpose } = require("../../../constants") const { sendEmail, isEmailConfigured } = require("../../../utilities/email") const { @@ -11,15 +11,15 @@ const { getGlobalUserByEmail, hash, platformLogout, -} = authPkg.utils -const { Cookies, Headers } = authPkg.constants -const { passport } = authPkg.auth +} = core.utils +const { Cookies, Headers } = core.constants +const { passport } = core.auth const { checkResetPasswordCode } = require("../../../utilities/redis") const { getGlobalDB, getTenantId, isMultiTenant, -} = require("@budibase/auth/tenancy") +} = require("@budibase/backend-core/tenancy") const env = require("../../../environment") const ssoCallbackUrl = async (config, type) => { @@ -152,7 +152,7 @@ exports.logout = async ctx => { exports.googlePreAuth = async (ctx, next) => { const db = getGlobalDB() - const config = await authPkg.db.getScopedConfig(db, { + const config = await core.db.getScopedConfig(db, { type: Configs.GOOGLE, workspace: ctx.query.workspace, }) @@ -167,7 +167,7 @@ exports.googlePreAuth = async (ctx, next) => { exports.googleAuth = async (ctx, next) => { const db = getGlobalDB() - const config = await authPkg.db.getScopedConfig(db, { + const config = await core.db.getScopedConfig(db, { type: Configs.GOOGLE, workspace: ctx.query.workspace, }) @@ -187,7 +187,7 @@ exports.googleAuth = async (ctx, next) => { async function oidcStrategyFactory(ctx, configId) { const db = getGlobalDB() - const config = await authPkg.db.getScopedConfig(db, { + const config = await core.db.getScopedConfig(db, { type: Configs.OIDC, group: ctx.query.group, }) diff --git a/packages/worker/src/api/controllers/global/configs.js b/packages/worker/src/api/controllers/global/configs.js index b6fcb9ee7d..fc0aa868a3 100644 --- a/packages/worker/src/api/controllers/global/configs.js +++ b/packages/worker/src/api/controllers/global/configs.js @@ -4,12 +4,15 @@ const { getGlobalUserParams, getScopedFullConfig, getAllApps, -} = require("@budibase/auth/db") +} = require("@budibase/backend-core/db") const { Configs } = require("../../../constants") const email = require("../../../utilities/email") -const { upload, ObjectStoreBuckets } = require("@budibase/auth").objectStore +const { + upload, + ObjectStoreBuckets, +} = require("@budibase/backend-core/objectStore") const CouchDB = require("../../../db") -const { getGlobalDB, getTenantId } = require("@budibase/auth/tenancy") +const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy") const env = require("../../../environment") const { googleCallbackUrl, oidcCallbackUrl } = require("./auth") diff --git a/packages/worker/src/api/controllers/global/email.js b/packages/worker/src/api/controllers/global/email.js index e194a30862..125376cdc2 100644 --- a/packages/worker/src/api/controllers/global/email.js +++ b/packages/worker/src/api/controllers/global/email.js @@ -1,5 +1,5 @@ const { sendEmail } = require("../../../utilities/email") -const { getGlobalDB } = require("@budibase/auth/tenancy") +const { getGlobalDB } = require("@budibase/backend-core/tenancy") exports.sendEmail = async ctx => { let { diff --git a/packages/worker/src/api/controllers/global/roles.js b/packages/worker/src/api/controllers/global/roles.js index 1aae07241e..3c977a6290 100644 --- a/packages/worker/src/api/controllers/global/roles.js +++ b/packages/worker/src/api/controllers/global/roles.js @@ -1,9 +1,9 @@ -const { getAllRoles } = require("@budibase/auth/roles") +const { getAllRoles } = require("@budibase/backend-core/roles") const { getAllApps, getDeployedAppID, DocumentTypes, -} = require("@budibase/auth/db") +} = require("@budibase/backend-core/db") const CouchDB = require("../../../db") exports.fetch = async ctx => { diff --git a/packages/worker/src/api/controllers/global/sessions.js b/packages/worker/src/api/controllers/global/sessions.js index 170e97d690..4a334037d4 100644 --- a/packages/worker/src/api/controllers/global/sessions.js +++ b/packages/worker/src/api/controllers/global/sessions.js @@ -2,7 +2,7 @@ const { getAllSessions, getUserSessions, invalidateSessions, -} = require("@budibase/auth/sessions") +} = require("@budibase/backend-core/sessions") exports.fetch = async ctx => { ctx.body = await getAllSessions() diff --git a/packages/worker/src/api/controllers/global/templates.js b/packages/worker/src/api/controllers/global/templates.js index 0dc2b8abab..b16e9423ec 100644 --- a/packages/worker/src/api/controllers/global/templates.js +++ b/packages/worker/src/api/controllers/global/templates.js @@ -1,11 +1,11 @@ -const { generateTemplateID } = require("@budibase/auth/db") +const { generateTemplateID } = require("@budibase/backend-core/db") const { TemplateMetadata, TemplateBindings, GLOBAL_OWNER, } = require("../../../constants") const { getTemplates } = require("../../../constants/templates") -const { getGlobalDB } = require("@budibase/auth/tenancy") +const { getGlobalDB } = require("@budibase/backend-core/tenancy") exports.save = async ctx => { const db = getGlobalDB() diff --git a/packages/worker/src/api/controllers/global/users.js b/packages/worker/src/api/controllers/global/users.js index 87194a7ceb..152bc9f5ae 100644 --- a/packages/worker/src/api/controllers/global/users.js +++ b/packages/worker/src/api/controllers/global/users.js @@ -2,22 +2,26 @@ const { getGlobalUserParams, StaticDatabases, generateNewUsageQuotaDoc, -} = require("@budibase/auth/db") -const { hash, getGlobalUserByEmail, saveUser, platformLogout } = - require("@budibase/auth").utils +} = require("@budibase/backend-core/db") +const { + hash, + getGlobalUserByEmail, + saveUser, + platformLogout, +} = require("@budibase/backend-core/utils") const { EmailTemplatePurpose } = require("../../../constants") const { checkInviteCode } = require("../../../utilities/redis") const { sendEmail } = require("../../../utilities/email") -const { user: userCache } = require("@budibase/auth/cache") -const { invalidateSessions } = require("@budibase/auth/sessions") -const accounts = require("@budibase/auth/accounts") +const { user: userCache } = require("@budibase/backend-core/cache") +const { invalidateSessions } = require("@budibase/backend-core/sessions") +const accounts = require("@budibase/backend-core/accounts") const { getGlobalDB, getTenantId, getTenantUser, doesTenantExist, -} = require("@budibase/auth/tenancy") -const { removeUserFromInfoDB } = require("@budibase/auth/deprovision") +} = require("@budibase/backend-core/tenancy") +const { removeUserFromInfoDB } = require("@budibase/backend-core/deprovision") const env = require("../../../environment") const { syncUserInApps } = require("../../../utilities/appService") diff --git a/packages/worker/src/api/controllers/global/workspaces.js b/packages/worker/src/api/controllers/global/workspaces.js index 48a710c92d..d5d1037d9e 100644 --- a/packages/worker/src/api/controllers/global/workspaces.js +++ b/packages/worker/src/api/controllers/global/workspaces.js @@ -1,5 +1,8 @@ -const { getWorkspaceParams, generateWorkspaceID } = require("@budibase/auth/db") -const { getGlobalDB } = require("@budibase/auth/tenancy") +const { + getWorkspaceParams, + generateWorkspaceID, +} = require("@budibase/backend-core/db") +const { getGlobalDB } = require("@budibase/backend-core/tenancy") exports.save = async function (ctx) { const db = getGlobalDB() diff --git a/packages/worker/src/api/controllers/system/tenants.js b/packages/worker/src/api/controllers/system/tenants.js index a96c5e5f9f..4d41ce894c 100644 --- a/packages/worker/src/api/controllers/system/tenants.js +++ b/packages/worker/src/api/controllers/system/tenants.js @@ -1,7 +1,7 @@ const CouchDB = require("../../../db") -const { StaticDatabases } = require("@budibase/auth/db") -const { getTenantId } = require("@budibase/auth/tenancy") -const { deleteTenant } = require("@budibase/auth/deprovision") +const { StaticDatabases } = require("@budibase/backend-core/db") +const { getTenantId } = require("@budibase/backend-core/tenancy") +const { deleteTenant } = require("@budibase/backend-core/deprovision") exports.exists = async ctx => { const tenantId = ctx.request.params diff --git a/packages/worker/src/api/index.js b/packages/worker/src/api/index.js index 3ed6a96ac1..a83b39e6cf 100644 --- a/packages/worker/src/api/index.js +++ b/packages/worker/src/api/index.js @@ -2,8 +2,11 @@ const Router = require("@koa/router") const compress = require("koa-compress") const zlib = require("zlib") const { routes } = require("./routes") -const { buildAuthMiddleware, auditLog, buildTenancyMiddleware } = - require("@budibase/auth").auth +const { + buildAuthMiddleware, + auditLog, + buildTenancyMiddleware, +} = require("@budibase/backend-core/auth") const PUBLIC_ENDPOINTS = [ // old deprecated endpoints kept for backwards compat diff --git a/packages/worker/src/api/routes/global/auth.js b/packages/worker/src/api/routes/global/auth.js index 7baad60ecd..20c615b85a 100644 --- a/packages/worker/src/api/routes/global/auth.js +++ b/packages/worker/src/api/routes/global/auth.js @@ -2,7 +2,7 @@ const Router = require("@koa/router") const authController = require("../../controllers/global/auth") const joiValidator = require("../../../middleware/joi-validator") const Joi = require("joi") -const { updateTenantId } = require("@budibase/auth/tenancy") +const { updateTenantId } = require("@budibase/backend-core/tenancy") const router = Router() diff --git a/packages/worker/src/api/routes/tests/auth.spec.js b/packages/worker/src/api/routes/tests/auth.spec.js index 13a93f9cfb..e26af12e01 100644 --- a/packages/worker/src/api/routes/tests/auth.spec.js +++ b/packages/worker/src/api/routes/tests/auth.spec.js @@ -54,7 +54,7 @@ describe("/api/global/auth", () => { }) describe("oidc", () => { - const auth = require("@budibase/auth").auth + const auth = require("@budibase/backend-core/auth") // mock the oidc strategy implementation and return value strategyFactory = jest.fn() @@ -104,4 +104,4 @@ describe("/api/global/auth", () => { }) }) -}) \ No newline at end of file +}) diff --git a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js index c40b6d8dec..34ce01263d 100644 --- a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js +++ b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js @@ -1,17 +1,17 @@ const env = require("../../../../environment") const controllers = require("./controllers") const supertest = require("supertest") -const { jwt } = require("@budibase/auth").auth -const { Cookies } = require("@budibase/auth").constants +const { jwt } = require("@budibase/backend-core/auth") +const { Cookies } = require("@budibase/backend-core/constants") const { Configs, LOGO_URL } = require("../../../../constants") -const { getGlobalUserByEmail } = require("@budibase/auth").utils -const { createASession } = require("@budibase/auth/sessions") -const { newid } = require("../../../../../../auth/src/hashing") +const { getGlobalUserByEmail } = require("@budibase/backend-core/utils") +const { createASession } = require("@budibase/backend-core/sessions") +const { newid } = require("@budibase/backend-core/src/hashing") const { TENANT_ID } = require("./structures") -const auth = require("@budibase/auth") +const core = require("@budibase/backend-core") const CouchDB = require("../../../../db") -const { doInTenant } = require("@budibase/auth/tenancy") -auth.init(CouchDB) +const { doInTenant } = require("@budibase/backend-core/tenancy") +core.init(CouchDB) class TestConfiguration { constructor(openServer = true) { diff --git a/packages/worker/src/constants/index.js b/packages/worker/src/constants/index.js index a2bc818674..5affaaccb3 100644 --- a/packages/worker/src/constants/index.js +++ b/packages/worker/src/constants/index.js @@ -1,4 +1,4 @@ -const { Configs } = require("@budibase/auth").constants +const { Configs } = require("@budibase/backend-core/constants") exports.LOGO_URL = "https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg" diff --git a/packages/worker/src/constants/templates/index.js b/packages/worker/src/constants/templates/index.js index ac5427ba1f..cfca00f471 100644 --- a/packages/worker/src/constants/templates/index.js +++ b/packages/worker/src/constants/templates/index.js @@ -6,8 +6,8 @@ const { GLOBAL_OWNER, } = require("../index") const { join } = require("path") -const { getTemplateParams } = require("@budibase/auth/db") -const { getGlobalDB } = require("@budibase/auth/tenancy") +const { getTemplateParams } = require("@budibase/backend-core/db") +const { getGlobalDB } = require("@budibase/backend-core/tenancy") exports.EmailTemplates = { [EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile( diff --git a/packages/worker/src/db/index.js b/packages/worker/src/db/index.js index 632e19280d..d7e7f5ff4f 100644 --- a/packages/worker/src/db/index.js +++ b/packages/worker/src/db/index.js @@ -1,7 +1,7 @@ const PouchDB = require("pouchdb") const allDbs = require("pouchdb-all-dbs") const env = require("../environment") -const { getCouchUrl } = require("@budibase/auth/db") +const { getCouchUrl } = require("@budibase/backend-core/db") // level option is purely for testing (development) const COUCH_DB_URL = getCouchUrl() || "http://localhost:10000/db/" diff --git a/packages/worker/src/index.js b/packages/worker/src/index.js index 77430268cd..7568784f09 100644 --- a/packages/worker/src/index.js +++ b/packages/worker/src/index.js @@ -1,12 +1,12 @@ // need to load environment first const env = require("./environment") const CouchDB = require("./db") -require("@budibase/auth").init(CouchDB) +require("@budibase/backend-core").init(CouchDB) const Koa = require("koa") const destroyable = require("server-destroy") const koaBody = require("koa-body") const koaSession = require("koa-session") -const { passport } = require("@budibase/auth").auth +const { passport } = require("@budibase/backend-core/auth") const logger = require("koa-pino-logger") const http = require("http") const api = require("./api") diff --git a/packages/worker/src/middleware/cloudRestricted.js b/packages/worker/src/middleware/cloudRestricted.js index b29093f77e..b42ce4f3a4 100644 --- a/packages/worker/src/middleware/cloudRestricted.js +++ b/packages/worker/src/middleware/cloudRestricted.js @@ -1,5 +1,5 @@ const env = require("../environment") -const { Headers } = require("@budibase/auth").constants +const { Headers } = require("@budibase/backend-core/constants") /** * This is a restricted endpoint in the cloud. diff --git a/packages/worker/src/utilities/appService.js b/packages/worker/src/utilities/appService.js index 23c5581510..36785198d7 100644 --- a/packages/worker/src/utilities/appService.js +++ b/packages/worker/src/utilities/appService.js @@ -1,6 +1,6 @@ const fetch = require("node-fetch") -const { Headers } = require("@budibase/auth/constants") -const { getTenantId, isTenantIdSet } = require("@budibase/auth/tenancy") +const { Headers } = require("@budibase/backend-core/constants") +const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy") const { checkSlashesInUrl } = require("../utilities") const env = require("../environment") diff --git a/packages/worker/src/utilities/email.js b/packages/worker/src/utilities/email.js index f11ec90a27..ae3910ed1e 100644 --- a/packages/worker/src/utilities/email.js +++ b/packages/worker/src/utilities/email.js @@ -1,12 +1,12 @@ const nodemailer = require("nodemailer") const env = require("../environment") -const { getScopedConfig } = require("@budibase/auth/db") +const { getScopedConfig } = require("@budibase/backend-core/db") const { EmailTemplatePurpose, TemplateTypes, Configs } = require("../constants") const { getTemplateByPurpose } = require("../constants/templates") const { getSettingsTemplateContext } = require("./templates") const { processString } = require("@budibase/string-templates") const { getResetPasswordCode, getInviteCode } = require("../utilities/redis") -const { getGlobalDB } = require("@budibase/auth/tenancy") +const { getGlobalDB } = require("@budibase/backend-core/tenancy") const TEST_MODE = false const TYPE = TemplateTypes.EMAIL diff --git a/packages/worker/src/utilities/redis.js b/packages/worker/src/utilities/redis.js index b644d1bc57..cfed97cd18 100644 --- a/packages/worker/src/utilities/redis.js +++ b/packages/worker/src/utilities/redis.js @@ -1,5 +1,5 @@ -const { Client, utils } = require("@budibase/auth/redis") -const { newid } = require("@budibase/auth").utils +const { Client, utils } = require("@budibase/backend-core/redis") +const { newid } = require("@budibase/backend-core/utils") function getExpirySecondsForDB(db) { switch (db) { diff --git a/packages/worker/src/utilities/templates.js b/packages/worker/src/utilities/templates.js index f261d9ca33..6e559dec65 100644 --- a/packages/worker/src/utilities/templates.js +++ b/packages/worker/src/utilities/templates.js @@ -1,4 +1,4 @@ -const { getScopedConfig } = require("@budibase/auth/db") +const { getScopedConfig } = require("@budibase/backend-core/db") const { Configs, InternalTemplateBindings, @@ -6,7 +6,10 @@ const { EmailTemplatePurpose, } = require("../constants") const { checkSlashesInUrl } = require("./index") -const { getGlobalDB, addTenantToUrl } = require("@budibase/auth/tenancy") +const { + getGlobalDB, + addTenantToUrl, +} = require("@budibase/backend-core/tenancy") const BASE_COMPANY = "Budibase" exports.getSettingsTemplateContext = async (purpose, code = null) => {