1
0
Fork 0
mirror of synced 2024-09-29 08:41:16 +13:00

Bundle client as IIFE rather than ESM

This commit is contained in:
Andrew Kingston 2021-01-07 14:53:18 +00:00
parent 2583e70498
commit 5fb6503298
2 changed files with 1 additions and 48 deletions

View file

@ -10,7 +10,7 @@ export default {
output: [
{
sourcemap: true,
format: "esm",
format: "iife",
file: `./dist/budibase-client.js`,
},
],

View file

@ -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
}