From c986fb164e19822515cdd11c1daf343917ac4e30 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 4 Oct 2022 15:01:18 +0100 Subject: [PATCH 01/10] Use raw server jsUrl when rendering plugins --- packages/client/src/components/ClientApp.svelte | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index ab19e91038..537e963ff3 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -16,7 +16,6 @@ themeStore, appStore, devToolsStore, - environmentStore, } from "stores" import NotificationDisplay from "components/overlay/NotificationDisplay.svelte" import ConfirmationDisplay from "components/overlay/ConfirmationDisplay.svelte" @@ -48,8 +47,6 @@ !$builderStore.inBuilder && $devToolsStore.enabled && !$routeStore.queryParams?.peek - $: objectStoreUrl = $environmentStore.cloud ? "https://cdn.budi.live" : "" - $: pluginsUrl = `${objectStoreUrl}/plugins` // Handle no matching route $: { @@ -95,8 +92,7 @@ {#if $builderStore.usedPlugins?.length} {#each $builderStore.usedPlugins as plugin (plugin.hash)} - + {/each} {/if} From de9b2c44cb27e5890ddfaf2d42bcd372a7d81473 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 4 Oct 2022 16:27:04 +0100 Subject: [PATCH 02/10] Add utility for generating plugin JS URLs --- packages/server/src/utilities/plugins.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/server/src/utilities/plugins.js diff --git a/packages/server/src/utilities/plugins.js b/packages/server/src/utilities/plugins.js new file mode 100644 index 0000000000..e69de29bb2 From 69988aabc38bddd7d7d2f4b6b87d4ecd2b97448c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 4 Oct 2022 16:27:15 +0100 Subject: [PATCH 03/10] Always use the raw server plugin JS URL --- packages/client/src/components/ClientApp.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index 537e963ff3..47f6cc2e3e 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -87,6 +87,8 @@ builderStore.actions.analyticsPing({ source: "app" }) } }) + + $: console.log($builderStore.usedPlugins) From b148b7d004a1bc14f40b1416e970e18cbe11258e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 4 Oct 2022 16:27:42 +0100 Subject: [PATCH 04/10] Enrich plugin JS URLs when fetching appPackage --- packages/server/src/api/controllers/application.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/application.ts b/packages/server/src/api/controllers/application.ts index 6771f7e4e0..b6377a61a2 100644 --- a/packages/server/src/api/controllers/application.ts +++ b/packages/server/src/api/controllers/application.ts @@ -50,6 +50,7 @@ import { errors, events, migrations } from "@budibase/backend-core" import { App, Layout, Screen, MigrationType } from "@budibase/types" import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts" import { groups } from "@budibase/pro" +import { enrichPluginURLs } from "../../utilities/plugins" const URL_REGEX_SLASH = /\/|\\/g @@ -208,10 +209,13 @@ export const fetchAppDefinition = async (ctx: any) => { export const fetchAppPackage = async (ctx: any) => { const db = context.getAppDB() - const application = await db.get(DocumentType.APP_METADATA) + let application = await db.get(DocumentType.APP_METADATA) const layouts = await getLayouts() let screens = await getScreens() + // Enrich plugin URLs + application.usedPlugins = enrichPluginURLs(application.usedPlugins) + // Only filter screens if the user is not a builder if (!(ctx.user.builder && ctx.user.builder.global)) { const userRoleId = getUserRoleId(ctx) From d5cde049a7bf089a866dfd1aaf2dcdc67b8b92bf Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 4 Oct 2022 16:28:01 +0100 Subject: [PATCH 05/10] Enrich plugin JS URLs when SSR'ing apps --- packages/server/src/api/controllers/static/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 80116a21f5..83f2b6fdc4 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -1,3 +1,6 @@ +import { Plugin } from "@budibase/types" +import { enrichPluginURLs } from "../../../utilities/plugins" + require("svelte/register") const send = require("koa-send") @@ -22,6 +25,7 @@ const fs = require("fs") const { downloadTarballDirect, } = require("../../../utilities/fileSystem/utilities") +const { isMultiTenant } = require("@budibase/backend-core/tenancy") async function prepareUpload({ s3Key, bucket, metadata, file }: any) { const response = await upload({ @@ -107,12 +111,13 @@ export const serveApp = async function (ctx: any) { if (!env.isJest()) { const App = require("./templates/BudibaseApp.svelte").default + const plugins = enrichPluginURLs(appInfo.usedPlugins) const { head, html, css } = App.render({ title: appInfo.name, production: env.isProd(), appId, clientLibPath: clientLibraryPath(appId, appInfo.version, ctx), - usedPlugins: appInfo.usedPlugins, + usedPlugins: plugins, }) const appHbs = loadHandlebarsFile(`${__dirname}/templates/app.hbs`) From b487855348153811e7101d7ff469db5f053bc592 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 4 Oct 2022 16:28:21 +0100 Subject: [PATCH 06/10] Update plugin JS URL handling --- .../static/templates/BudibaseApp.svelte | 4 +--- packages/server/src/utilities/plugins.js | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte index 4bf54f2c91..227f980896 100644 --- a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte +++ b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte @@ -88,9 +88,7 @@ {#if usedPlugins?.length} {#each usedPlugins as plugin} - + {/each} {/if} From 021316c73f6939bb50493073948d55c80be1a13e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 4 Oct 2022 16:43:20 +0100 Subject: [PATCH 08/10] Lint --- packages/server/src/api/controllers/static/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 83f2b6fdc4..08213c2cf8 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -1,4 +1,3 @@ -import { Plugin } from "@budibase/types" import { enrichPluginURLs } from "../../../utilities/plugins" require("svelte/register") @@ -25,7 +24,6 @@ const fs = require("fs") const { downloadTarballDirect, } = require("../../../utilities/fileSystem/utilities") -const { isMultiTenant } = require("@budibase/backend-core/tenancy") async function prepareUpload({ s3Key, bucket, metadata, file }: any) { const response = await upload({ From 788dac0f8dc09264a4e70813398a48aa6a9395bf Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 5 Oct 2022 08:25:50 +0100 Subject: [PATCH 09/10] Use CJS style imports in plugin URL helper to work in jest, and respect plugin bucket env var --- packages/server/src/utilities/plugins.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/server/src/utilities/plugins.js b/packages/server/src/utilities/plugins.js index fae15fb184..96e496ed4e 100644 --- a/packages/server/src/utilities/plugins.js +++ b/packages/server/src/utilities/plugins.js @@ -1,5 +1,6 @@ -import env from "../environment" -import { plugins as ProPlugins } from "@budibase/pro" +const env = require("../environment") +const { plugins: ProPlugins } = require("@budibase/pro") +const { objectStore } = require("@budibase/backend-core") export const enrichPluginURLs = plugins => { if (!plugins || !plugins.length) { @@ -7,14 +8,14 @@ export const enrichPluginURLs = plugins => { } return plugins.map(plugin => { const cloud = !env.SELF_HOSTED - // In self host we need to prefix the path, as "plugins" is not part of the - // bucket path. In cloud, "plugins" is already part of the bucket path. - let jsUrl = cloud ? "https://cdn.budi.live/" : "/plugins/" + const bucket = objectStore.ObjectStoreBuckets.PLUGINS + const jsFileName = "plugin.min.js" + + // In self host we need to prefix the path, as the bucket name is not part + // of the bucket path. In cloud, it's already part of the bucket path. + let jsUrl = cloud ? "https://cdn.budi.live/" : `/${bucket}/` jsUrl += ProPlugins.getBucketPath(plugin.name) - jsUrl += "plugin.min.js" - return { - ...plugin, - jsUrl, - } + jsUrl += jsFileName + return { ...plugin, jsUrl } }) } From f2f842444a1d6786200190b170a4903e10cc1c8a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 5 Oct 2022 08:57:26 +0100 Subject: [PATCH 10/10] Update plugin URL utility export to use CJS syntax --- packages/server/src/utilities/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/utilities/plugins.js b/packages/server/src/utilities/plugins.js index 96e496ed4e..202a349b16 100644 --- a/packages/server/src/utilities/plugins.js +++ b/packages/server/src/utilities/plugins.js @@ -2,7 +2,7 @@ const env = require("../environment") const { plugins: ProPlugins } = require("@budibase/pro") const { objectStore } = require("@budibase/backend-core") -export const enrichPluginURLs = plugins => { +exports.enrichPluginURLs = plugins => { if (!plugins || !plugins.length) { return [] }