Move API client in builder to top level under src and fix some endpoints not being imported

This commit is contained in:
Andrew Kingston 2022-01-24 16:38:36 +00:00
parent bbc3c18fcd
commit c7877055a5
7 changed files with 48 additions and 49 deletions

View File

@ -3,7 +3,7 @@ import {
CookieUtils, CookieUtils,
Constants, Constants,
} from "@budibase/frontend-core" } from "@budibase/frontend-core"
import { store } from "./index" import { store } from "./builderStore"
import { get } from "svelte/store" import { get } from "svelte/store"
export const API = createAPIClient({ export const API = createAPIClient({
@ -25,7 +25,7 @@ export const API = createAPIClient({
} }
// Log all errors to console // 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 // Logout on 403's
if (status === 403) { if (status === 403) {

View File

@ -50,7 +50,7 @@
"Another app with the same name already exists", "Another app with the same name already exists",
value => { value => {
return !existingAppNames.some( return !existingAppNames.some(
appName => appName.toLowerCase() === value.toLowerCase() appName => appName?.toLowerCase() === value.toLowerCase()
) )
} }
) )
@ -67,7 +67,7 @@
try { try {
await obj.validate(values, { abortEarly: false }) await obj.validate(values, { abortEarly: false })
} catch (validationErrors) { } catch (validationErrors) {
validationErrors.inner.forEach(error => { validationErrors.inner?.forEach(error => {
$errors[error.path] = capitalise(error.message) $errors[error.path] = capitalise(error.message)
}) })
} }

View File

@ -58,7 +58,7 @@ export default ({ mode }) => {
}, },
{ {
find: "api", find: "api",
replacement: path.resolve("./src/builderStore/api.js"), replacement: path.resolve("./src/api.js"),
}, },
{ {
find: "constants", find: "constants",

View File

@ -139,4 +139,15 @@ export const buildAppEndpoints = API => ({
url: "/api/applications?status=all", 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`,
})
},
}) })

View File

@ -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",
})
},
})

View File

@ -66,13 +66,13 @@ export const createAPIClient = config => {
} }
// Generates an error object from a string // Generates an error object from a string
const makeError = message => { const makeError = (message, request) => {
return { return {
message, message,
json: null, json: null,
status: 400, status: 400,
url: "", url: request?.url,
method: "", method: request?.method,
handled: true, handled: true,
} }
} }
@ -106,7 +106,7 @@ export const createAPIClient = config => {
try { try {
requestBody = JSON.stringify(body) requestBody = JSON.stringify(body)
} catch (error) { } 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", credentials: "same-origin",
}) })
} catch (error) { } catch (error) {
throw makeError("Failed to send request") throw makeError("Failed to send request", { url, method })
} }
// Handle response // Handle response

View File

@ -16,4 +16,31 @@ export const buildOtherEndpoints = API => ({
url: "/api/system/environment", 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",
})
},
}) })