diff --git a/packages/auth/src/constants.js b/packages/auth/src/constants.js index 363274eda5..28b9ced49b 100644 --- a/packages/auth/src/constants.js +++ b/packages/auth/src/constants.js @@ -16,6 +16,7 @@ exports.Headers = { APP_ID: "x-budibase-app-id", TYPE: "x-budibase-type", TENANT_ID: "x-budibase-tenant-id", + TOKEN: "x-budibase-token", } exports.GlobalRoles = { diff --git a/packages/auth/src/middleware/authenticated.js b/packages/auth/src/middleware/authenticated.js index f0fb6e21c5..87bd4d35ce 100644 --- a/packages/auth/src/middleware/authenticated.js +++ b/packages/auth/src/middleware/authenticated.js @@ -1,5 +1,5 @@ const { Cookies, Headers } = require("../constants") -const { getCookie, clearCookie } = require("../utils") +const { getCookie, clearCookie, openJwt } = require("../utils") const { getUser } = require("../cache/user") const { getSession, updateSessionTTL } = require("../security/sessions") const { buildMatcherRegex, matches } = require("./matchers") @@ -35,8 +35,9 @@ module.exports = ( publicEndpoint = true } try { - // check the actual user is authenticated first - const authCookie = getCookie(ctx, Cookies.Auth) + // check the actual user is authenticated first, try header or cookie + const headerToken = ctx.request.headers[Headers.TOKEN] + const authCookie = getCookie(ctx, Cookies.Auth) || openJwt(headerToken) let authenticated = false, user = null, internal = false diff --git a/packages/auth/src/redis/utils.js b/packages/auth/src/redis/utils.js index 466b117e96..3461d2a511 100644 --- a/packages/auth/src/redis/utils.js +++ b/packages/auth/src/redis/utils.js @@ -16,6 +16,7 @@ exports.Databases = { USER_CACHE: "users", FLAGS: "flags", APP_METADATA: "appMetadata", + QUERY_VARS: "queryVars", } exports.SEPARATOR = SEPARATOR diff --git a/packages/auth/src/utils.js b/packages/auth/src/utils.js index b8fa7b9588..8c00f2a8b8 100644 --- a/packages/auth/src/utils.js +++ b/packages/auth/src/utils.js @@ -63,6 +63,17 @@ exports.getAppId = ctx => { return appId } +/** + * opens the contents of the specified encrypted JWT. + * @return {object} the contents of the token. + */ +exports.openJwt = token => { + if (!token) { + return token + } + return jwt.verify(token, options.secretOrKey) +} + /** * Get a cookie from context, and decrypt if necessary. * @param {object} ctx The request which is to be manipulated. @@ -75,7 +86,7 @@ exports.getCookie = (ctx, name) => { return cookie } - return jwt.verify(cookie, options.secretOrKey) + return exports.openJwt(cookie) } /** diff --git a/packages/bbui/src/Table/BoldRenderer.svelte b/packages/bbui/src/Table/BoldRenderer.svelte new file mode 100644 index 0000000000..ea882d538e --- /dev/null +++ b/packages/bbui/src/Table/BoldRenderer.svelte @@ -0,0 +1,11 @@ + + +
{value}
+ + diff --git a/packages/bbui/src/Table/CodeRenderer.svelte b/packages/bbui/src/Table/CodeRenderer.svelte new file mode 100644 index 0000000000..a75bec663c --- /dev/null +++ b/packages/bbui/src/Table/CodeRenderer.svelte @@ -0,0 +1,5 @@ + + +{value} diff --git a/packages/bbui/src/index.js b/packages/bbui/src/index.js index 13fb7f1770..16f069f4e7 100644 --- a/packages/bbui/src/index.js +++ b/packages/bbui/src/index.js @@ -61,6 +61,10 @@ export { default as ColorPicker } from "./ColorPicker/ColorPicker.svelte" export { default as InlineAlert } from "./InlineAlert/InlineAlert.svelte" export { default as Banner } from "./Banner/Banner.svelte" +// Renderers +export { default as BoldRenderer } from "./Table/BoldRenderer.svelte" +export { default as CodeRenderer } from "./Table/CodeRenderer.svelte" + // Typography export { default as Body } from "./Typography/Body.svelte" export { default as Heading } from "./Typography/Heading.svelte" diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte index f736d29bee..b97f23d7a3 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte @@ -175,15 +175,19 @@ onConfirm={datasources.removeSchemaError} /> {/if} - onClickTable(detail)} - schema={tableSchema} - data={Object.values(plusTables)} - allowEditColumns={false} - allowEditRows={false} - allowSelectRows={false} - customRenderers={[{ column: "primary", component: ArrayRenderer }]} -/> +{#if plusTables && Object.values(plusTables).length > 0} +
onClickTable(detail)} + schema={tableSchema} + data={Object.values(plusTables)} + allowEditColumns={false} + allowEditRows={false} + allowSelectRows={false} + customRenderers={[{ column: "primary", component: ArrayRenderer }]} + /> +{:else} + No tables found. +{/if} {#if plusTables?.length !== 0}
@@ -196,14 +200,18 @@ Tell budibase how your tables are related to get even more smart features. {/if} -
openRelationshipModal(detail.from, detail.to)} - schema={relationshipSchema} - data={relationshipInfo} - allowEditColumns={false} - allowEditRows={false} - allowSelectRows={false} -/> +{#if relationshipInfo && relationshipInfo.length > 0} +
openRelationshipModal(detail.from, detail.to)} + schema={relationshipSchema} + data={relationshipInfo} + allowEditColumns={false} + allowEditRows={false} + allowSelectRows={false} + /> +{:else} + No relationships configured. +{/if} diff --git a/packages/builder/src/helpers/data/utils.js b/packages/builder/src/helpers/data/utils.js index 613f533043..b6478680ec 100644 --- a/packages/builder/src/helpers/data/utils.js +++ b/packages/builder/src/helpers/data/utils.js @@ -119,3 +119,13 @@ export function flipHeaderState(headersActivity) { }) return enabled } + +export default { + breakQueryString, + buildQueryString, + fieldsToSchema, + flipHeaderState, + keyValueToQueryParameters, + queryParametersToKeyValue, + schemaToFields, +} diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte new file mode 100644 index 0000000000..61d0a1993c --- /dev/null +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte @@ -0,0 +1,54 @@ + + + + + Specify a name for your new dynamic variable, this must be unique across + your datasource. + + + diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/RestBodyInput.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/RestBodyInput.svelte index c387f0b492..4e3b645373 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/RestBodyInput.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/RestBodyInput.svelte @@ -16,17 +16,33 @@ export let query export let bodyType + let text = "" + let json = "" + $: checkRequestBody(bodyType) + $: updateRequestBody(bodyType, text, json) function checkRequestBody(type) { if (!bodyType || !query) { return } const currentType = typeof query?.fields.requestBody - if (objectTypes.includes(type) && currentType !== "object") { - query.fields.requestBody = {} - } else if (textTypes.includes(type) && currentType !== "string") { - query.fields.requestBody = "" + const isObject = objectTypes.includes(type) + const isText = textTypes.includes(type) + if (isText && currentType === "string") { + text = query.fields.requestBody + } else if (isObject && currentType === "object") { + json = query.fields.requestBody + } + } + + function updateRequestBody(type, text, json) { + if (type === RawRestBodyTypes.NONE) { + query.fields.requestBody = null + } else if (objectTypes.includes(type)) { + query.fields.requestBody = json + } else { + query.fields.requestBody = text } } @@ -49,16 +65,12 @@ THE REQUEST DOES NOT HAVE A BODY {:else if objectTypes.includes(bodyType)} - + {:else if textTypes.includes(bodyType)} (query.fields.requestBody = e.detail)} /> diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte index 94cf2d8604..98b7859305 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte @@ -21,11 +21,11 @@ import { cloneDeep } from "lodash/fp" import ImportRestQueriesModal from "components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte" - import { onMount } from "svelte" let importQueriesModal let changed - let datasource + let integration, baseDatasource, datasource + let queryList const querySchema = { name: {}, queryVerb: { displayName: "Method" }, @@ -34,11 +34,12 @@ $: baseDatasource = $datasources.list.find( ds => ds._id === $datasources.selected ) - $: integration = datasource && $integrations[datasource.source] + $: queryList = $queries.list.filter( query => query.datasourceId === datasource?._id ) $: hasChanged(baseDatasource, datasource) + $: updateDatasource(baseDatasource) function hasChanged(base, ds) { if (base && ds) { @@ -66,9 +67,12 @@ $goto(`./${query._id}`) } - onMount(() => { - datasource = cloneDeep(baseDatasource) - }) + function updateDatasource(base) { + if (base) { + datasource = cloneDeep(base) + integration = $integrations[datasource.source] + } + } @@ -142,7 +146,11 @@ {/if} {#if datasource?.source === IntegrationTypes.REST} - + {/if} diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte index 39d02d5dd8..43037242f3 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte @@ -1,22 +1,22 @@ + {#if query && queryConfig}
@@ -275,7 +344,10 @@ {#if !$flags.queryTransformerBanner} + window.open( + "https://docs.budibase.com/building-apps/data/transformers" + )} on:change={() => flags.updateFlag("queryTransformerBanner", true)} > @@ -341,6 +413,9 @@ name="schema" headings options={SchemaTypeOptions} + menuItems={schemaMenuItems} + showMenu={!schemaReadOnly} + readOnly={schemaReadOnly} /> {/if} @@ -349,7 +424,12 @@