From 32c71bd00604beef0613eabdfb5c18d570bdcf03 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 7 Jan 2021 14:53:18 +0000 Subject: [PATCH] Bundle client as IIFE rather than ESM --- packages/client/rollup.config.js | 2 +- packages/client/src/utils/getAppId.js | 47 --------------------------- 2 files changed, 1 insertion(+), 48 deletions(-) delete mode 100644 packages/client/src/utils/getAppId.js diff --git a/packages/client/rollup.config.js b/packages/client/rollup.config.js index 30064bde26..6a4144caf5 100644 --- a/packages/client/rollup.config.js +++ b/packages/client/rollup.config.js @@ -10,7 +10,7 @@ export default { output: [ { sourcemap: true, - format: "esm", + format: "iife", file: `./dist/budibase-client.js`, }, ], diff --git a/packages/client/src/utils/getAppId.js b/packages/client/src/utils/getAppId.js deleted file mode 100644 index 355dd55d6b..0000000000 --- a/packages/client/src/utils/getAppId.js +++ /dev/null @@ -1,47 +0,0 @@ -const COOKIE_SEPARATOR = ";" -const APP_PREFIX = "app_" -const KEY_VALUE_SPLIT = "=" - -function confirmAppId(possibleAppId) { - return possibleAppId && possibleAppId.startsWith(APP_PREFIX) - ? possibleAppId - : undefined -} - -function tryGetFromCookie({ cookies }) { - if (!cookies) { - return undefined - } - const cookie = cookies - .split(COOKIE_SEPARATOR) - .find(cookie => cookie.trim().startsWith("budibase:currentapp")) - let appId - if (cookie && cookie.split(KEY_VALUE_SPLIT).length === 2) { - appId = cookie.split("=")[1] - } - return confirmAppId(appId) -} - -function tryGetFromPath() { - const appId = location.pathname.split("/")[1] - return confirmAppId(appId) -} - -function tryGetFromSubdomain() { - const parts = window.location.host.split(".") - const appId = parts[1] ? parts[0] : undefined - return confirmAppId(appId) -} - -export const getAppId = (cookies = window.document.cookie) => { - const functions = [tryGetFromSubdomain, tryGetFromPath, tryGetFromCookie] - // try getting the app Id in order - let appId - for (let func of functions) { - appId = func({ cookies }) - if (appId) { - break - } - } - return appId -}