From e44a68d356488ff0bff381b691a33f4e460a66fd Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 26 Nov 2024 11:04:37 +0100 Subject: [PATCH] Delete js files (moved to ts) --- packages/builder/src/api.js | 59 -------------- .../builder/src/stores/portal/navigation.js | 31 -------- packages/builder/src/stores/portal/plugins.js | 76 ------------------- 3 files changed, 166 deletions(-) delete mode 100644 packages/builder/src/api.js delete mode 100644 packages/builder/src/stores/portal/navigation.js delete mode 100644 packages/builder/src/stores/portal/plugins.js diff --git a/packages/builder/src/api.js b/packages/builder/src/api.js deleted file mode 100644 index 6441b4ff48..0000000000 --- a/packages/builder/src/api.js +++ /dev/null @@ -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)}` - ) - }, -}) diff --git a/packages/builder/src/stores/portal/navigation.js b/packages/builder/src/stores/portal/navigation.js deleted file mode 100644 index 67a06eff53..0000000000 --- a/packages/builder/src/stores/portal/navigation.js +++ /dev/null @@ -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() diff --git a/packages/builder/src/stores/portal/plugins.js b/packages/builder/src/stores/portal/plugins.js deleted file mode 100644 index e259f9aa6d..0000000000 --- a/packages/builder/src/stores/portal/plugins.js +++ /dev/null @@ -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()