Delete js files (moved to ts)
This commit is contained in:
parent
90833d1889
commit
e44a68d356
|
@ -1,59 +0,0 @@
|
||||||
import {
|
|
||||||
createAPIClient,
|
|
||||||
CookieUtils,
|
|
||||||
Constants,
|
|
||||||
} from "@budibase/frontend-core"
|
|
||||||
import { appStore } from "stores/builder"
|
|
||||||
import { get } from "svelte/store"
|
|
||||||
import { auth, navigation } from "./stores/portal"
|
|
||||||
|
|
||||||
export const API = createAPIClient({
|
|
||||||
attachHeaders: headers => {
|
|
||||||
// Attach app ID header from store
|
|
||||||
let appId = get(appStore).appId
|
|
||||||
if (appId) {
|
|
||||||
headers["x-budibase-app-id"] = appId
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add csrf token if authenticated
|
|
||||||
const user = get(auth).user
|
|
||||||
if (user?.csrfToken) {
|
|
||||||
headers["x-csrf-token"] = user.csrfToken
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
onError: error => {
|
|
||||||
const { url, message, status, method, handled } = error || {}
|
|
||||||
|
|
||||||
// Log any errors that we haven't manually handled
|
|
||||||
if (!handled) {
|
|
||||||
console.error("Unhandled error from API client", error)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log all errors to console
|
|
||||||
console.warn(`[Builder] HTTP ${status} on ${method}:${url}\n\t${message}`)
|
|
||||||
|
|
||||||
// Logout on 403's
|
|
||||||
if (status === 403) {
|
|
||||||
// Remove cookies
|
|
||||||
CookieUtils.removeCookie(Constants.Cookies.Auth)
|
|
||||||
|
|
||||||
// Reload after removing cookie, go to login
|
|
||||||
if (!url.includes("self") && !url.includes("login")) {
|
|
||||||
location.reload()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onMigrationDetected: appId => {
|
|
||||||
const updatingUrl = `/builder/app/updating/${appId}`
|
|
||||||
|
|
||||||
if (window.location.pathname === updatingUrl) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
get(navigation).goto(
|
|
||||||
`${updatingUrl}?returnUrl=${encodeURIComponent(window.location.pathname)}`
|
|
||||||
)
|
|
||||||
},
|
|
||||||
})
|
|
|
@ -1,31 +0,0 @@
|
||||||
import { writable } from "svelte/store"
|
|
||||||
|
|
||||||
export function createNavigationStore() {
|
|
||||||
const store = writable({
|
|
||||||
initialisated: false,
|
|
||||||
goto: undefined,
|
|
||||||
})
|
|
||||||
const { set, subscribe } = store
|
|
||||||
|
|
||||||
const init = gotoFunc => {
|
|
||||||
if (typeof gotoFunc !== "function") {
|
|
||||||
throw new Error(
|
|
||||||
`gotoFunc must be a function, found a "${typeof gotoFunc}" instead`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
set({
|
|
||||||
initialisated: true,
|
|
||||||
goto: gotoFunc,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
subscribe,
|
|
||||||
actions: {
|
|
||||||
init,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const navigation = createNavigationStore()
|
|
|
@ -1,76 +0,0 @@
|
||||||
import { writable } from "svelte/store"
|
|
||||||
import { API } from "api"
|
|
||||||
import { PluginSource } from "constants"
|
|
||||||
|
|
||||||
export function createPluginsStore() {
|
|
||||||
const { subscribe, set, update } = writable([])
|
|
||||||
|
|
||||||
async function load() {
|
|
||||||
const plugins = await API.getPlugins()
|
|
||||||
set(plugins)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deletePlugin(pluginId) {
|
|
||||||
await API.deletePlugin(pluginId)
|
|
||||||
update(state => {
|
|
||||||
state = state.filter(existing => existing._id !== pluginId)
|
|
||||||
return state
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createPlugin(source, url, auth = null) {
|
|
||||||
let pluginData = {
|
|
||||||
source,
|
|
||||||
url,
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (source) {
|
|
||||||
case PluginSource.URL:
|
|
||||||
pluginData.headers = auth
|
|
||||||
break
|
|
||||||
case PluginSource.GITHUB:
|
|
||||||
pluginData.githubToken = auth
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = await API.createPlugin(pluginData)
|
|
||||||
let newPlugin = res.plugin
|
|
||||||
update(state => {
|
|
||||||
const currentIdx = state.findIndex(plugin => plugin._id === newPlugin._id)
|
|
||||||
if (currentIdx >= 0) {
|
|
||||||
state.splice(currentIdx, 1, newPlugin)
|
|
||||||
} else {
|
|
||||||
state.push(newPlugin)
|
|
||||||
}
|
|
||||||
return state
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function uploadPlugin(file) {
|
|
||||||
if (!file) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let data = new FormData()
|
|
||||||
data.append("file", file)
|
|
||||||
let resp = await API.uploadPlugin(data)
|
|
||||||
let newPlugin = resp.plugins[0]
|
|
||||||
update(state => {
|
|
||||||
const currentIdx = state.findIndex(plugin => plugin._id === newPlugin._id)
|
|
||||||
if (currentIdx >= 0) {
|
|
||||||
state.splice(currentIdx, 1, newPlugin)
|
|
||||||
} else {
|
|
||||||
state.push(newPlugin)
|
|
||||||
}
|
|
||||||
return state
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
subscribe,
|
|
||||||
load,
|
|
||||||
createPlugin,
|
|
||||||
deletePlugin,
|
|
||||||
uploadPlugin,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const plugins = createPluginsStore()
|
|
Loading…
Reference in New Issue