diff --git a/packages/builder/src/builderStore/api.js b/packages/builder/src/api.js similarity index 90% rename from packages/builder/src/builderStore/api.js rename to packages/builder/src/api.js index 3dd6c28031..4a1f5e94f2 100644 --- a/packages/builder/src/builderStore/api.js +++ b/packages/builder/src/api.js @@ -3,7 +3,7 @@ import { CookieUtils, Constants, } from "@budibase/frontend-core" -import { store } from "./index" +import { store } from "./builderStore" import { get } from "svelte/store" export const API = createAPIClient({ @@ -25,7 +25,7 @@ export const API = createAPIClient({ } // Log all errors to console - console.error(`HTTP ${status} on ${method}:${url}:\n\t${message}`) + console.error(`HTTP ${status} on ${method}:${url}\n\t${message}`) // Logout on 403's if (status === 403) { diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 97e0fd5715..c81a62d42c 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -50,7 +50,7 @@ "Another app with the same name already exists", value => { return !existingAppNames.some( - appName => appName.toLowerCase() === value.toLowerCase() + appName => appName?.toLowerCase() === value.toLowerCase() ) } ) @@ -67,7 +67,7 @@ try { await obj.validate(values, { abortEarly: false }) } catch (validationErrors) { - validationErrors.inner.forEach(error => { + validationErrors.inner?.forEach(error => { $errors[error.path] = capitalise(error.message) }) } diff --git a/packages/builder/vite.config.js b/packages/builder/vite.config.js index dbaf1ffb2b..b68d265bc5 100644 --- a/packages/builder/vite.config.js +++ b/packages/builder/vite.config.js @@ -58,7 +58,7 @@ export default ({ mode }) => { }, { find: "api", - replacement: path.resolve("./src/builderStore/api.js"), + replacement: path.resolve("./src/api.js"), }, { find: "constants", diff --git a/packages/frontend-core/src/api/app.js b/packages/frontend-core/src/api/app.js index 1b0735be05..32fe8908ad 100644 --- a/packages/frontend-core/src/api/app.js +++ b/packages/frontend-core/src/api/app.js @@ -139,4 +139,15 @@ export const buildAppEndpoints = API => ({ url: "/api/applications?status=all", }) }, + + /** + * Fetches the definitions for component library components. This includes + * their props and other metadata from components.json. + * @param {string} appId - ID of the currently running app + */ + fetchComponentLibDefinitions: async appId => { + return await API.get({ + url: `/api/${appId}/components/definitions`, + }) + }, }) diff --git a/packages/frontend-core/src/api/builder.js b/packages/frontend-core/src/api/builder.js deleted file mode 100644 index 1b873fe09e..0000000000 --- a/packages/frontend-core/src/api/builder.js +++ /dev/null @@ -1,39 +0,0 @@ -export const buildBuilderEndpoints = API => ({ - /** - * Fetches the definitions for component library components. This includes - * their props and other metadata from components.json. - * @param {string} appId - ID of the currently running app - */ - fetchComponentLibDefinitions: async appId => { - return await API.get({ - url: `/api/${appId}/components/definitions`, - }) - }, - - /** - * Gets the list of available integrations. - */ - getIntegrations: async () => { - return await API.get({ - url: "/api/integrations", - }) - }, - - /** - * Gets the version of the installed Budibase environment. - */ - getBudibaseVersion: async () => { - return await API.get({ - url: "/api/dev/version", - }) - }, - - /** - * Gets the base permissions for roles. - */ - getBasePermissions: async () => { - return await API.get({ - url: "/api/permission/builtin", - }) - }, -}) diff --git a/packages/frontend-core/src/api/index.js b/packages/frontend-core/src/api/index.js index 973a1fbc2f..99ce9a1f69 100644 --- a/packages/frontend-core/src/api/index.js +++ b/packages/frontend-core/src/api/index.js @@ -66,13 +66,13 @@ export const createAPIClient = config => { } // Generates an error object from a string - const makeError = message => { + const makeError = (message, request) => { return { message, json: null, status: 400, - url: "", - method: "", + url: request?.url, + method: request?.method, handled: true, } } @@ -106,7 +106,7 @@ export const createAPIClient = config => { try { requestBody = JSON.stringify(body) } catch (error) { - throw makeError("Invalid JSON body") + throw makeError("Invalid JSON body", { url, method }) } } @@ -120,7 +120,7 @@ export const createAPIClient = config => { credentials: "same-origin", }) } catch (error) { - throw makeError("Failed to send request") + throw makeError("Failed to send request", { url, method }) } // Handle response diff --git a/packages/frontend-core/src/api/other.js b/packages/frontend-core/src/api/other.js index b3481f1e27..b2a5ccf441 100644 --- a/packages/frontend-core/src/api/other.js +++ b/packages/frontend-core/src/api/other.js @@ -16,4 +16,31 @@ export const buildOtherEndpoints = API => ({ url: "/api/system/environment", }) }, + + /** + * Gets the list of available integrations. + */ + getIntegrations: async () => { + return await API.get({ + url: "/api/integrations", + }) + }, + + /** + * Gets the version of the installed Budibase environment. + */ + getBudibaseVersion: async () => { + return await API.get({ + url: "/api/dev/version", + }) + }, + + /** + * Gets the base permissions for roles. + */ + getBasePermissions: async () => { + return await API.get({ + url: "/api/permission/builtin", + }) + }, })