From 4b1fb01eb49f9f061cf7bd1f5b26aa84cf0856b3 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Sat, 11 Dec 2021 10:40:57 +0000 Subject: [PATCH] Add _id field --- .../rest/auth/RestAuthenticationBuilder.svelte | 11 +++++------ .../rest/auth/RestAuthenticationModal.svelte | 1 - .../TableIntegrationMenu/rest/auth/authTypes.js | 10 +++++----- packages/server/src/integrations/rest.ts | 11 ++++++----- packages/server/src/integrations/tests/rest.spec.js | 6 ++++-- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte index 4b32d53fb9..3f23b03a3d 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte @@ -2,6 +2,7 @@ import { Table, Modal, Layout, ActionButton } from "@budibase/bbui" import AuthTypeRenderer from "./AuthTypeRenderer.svelte" import RestAuthenticationModal from "./RestAuthenticationModal.svelte" + import { uuid } from "builderStore/uuid" export let configs = [] @@ -20,24 +21,22 @@ const onConfirm = config => { if (currentConfig) { - // TODO: Update with _id configs = configs.map(c => { // replace the current config with the new one - if (c.name === currentConfig.name) { + if (c._id === currentConfig._id) { return config } return c }) } else { - configs.push(config) - configs = [...configs] + config._id = uuid() + configs = [...configs, config] } } const onDelete = () => { - // TODO: Update with _id configs = configs.filter(c => { - return c.name !== currentConfig.name + return c._id !== currentConfig._id }) } diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte index 79dc19f439..611e752a32 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte @@ -156,7 +156,6 @@ confirmText={currentConfig ? "Update" : "Add"} disabled={hasErrors || !hasChanged} cancelText={"Cancel"} - warning={true} size="M" showSecondaryButton={!!currentConfig} secondaryButtonText={"Delete"} diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js index 854391d6ce..1e2b65dad9 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js @@ -1,15 +1,15 @@ export const AUTH_TYPES = { - BEARER: "bearer", BASIC: "basic", + BEARER: "bearer", } export const AUTH_TYPE_LABELS = [ - { - label: "Bearer Token", - value: AUTH_TYPES.BEARER, - }, { label: "Basic Auth", value: AUTH_TYPES.BASIC, }, + { + label: "Bearer Token", + value: AUTH_TYPES.BEARER, + }, ] diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index dd3a14c3d3..51310eef3b 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -19,6 +19,7 @@ enum AuthType { } interface AuthConfig { + _id: string name: string type: AuthType config: BasicAuthConfig | BearerAuthConfig @@ -170,12 +171,12 @@ module RestModule { } } - processAuth(authConfigName: string) { - if (!this.config.authConfigs || !authConfigName) { + processAuth(authConfigId: string) { + if (!this.config.authConfigs || !authConfigId) { return } const authConfig = this.config.authConfigs.filter( - authConfig => authConfig.name === authConfigName + c => c._id === authConfigId )[0] let config switch (authConfig.type) { @@ -198,14 +199,14 @@ module RestModule { headers = {}, json = {}, method = "GET", - authConfigName = "", + authConfigId = "", }) { this.headers = { ...this.config.defaultHeaders, ...headers, } - this.processAuth(authConfigName) + this.processAuth(authConfigId) const input: any = { method, headers: this.headers } if (json && typeof json === "object" && Object.keys(json).length > 0) { diff --git a/packages/server/src/integrations/tests/rest.spec.js b/packages/server/src/integrations/tests/rest.spec.js index 85b5ac473b..0523115ad8 100644 --- a/packages/server/src/integrations/tests/rest.spec.js +++ b/packages/server/src/integrations/tests/rest.spec.js @@ -107,6 +107,7 @@ describe("REST Integration", () => { describe("authentication", () => { const basicAuth = { + _id: "c59c14bd1898a43baa08da68959b24686", name: "basic-1", type : AuthType.BASIC, config : { @@ -116,6 +117,7 @@ describe("REST Integration", () => { } const bearerAuth = { + _id: "0d91d732f34e4befabeff50b392a8ff3", name: "bearer-1", type : AuthType.BEARER, config : { @@ -132,7 +134,7 @@ describe("REST Integration", () => { it("adds basic auth", async () => { const query = { - authConfigName: "basic-1" + authConfigId: "c59c14bd1898a43baa08da68959b24686" } await config.integration.read(query) expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, { @@ -145,7 +147,7 @@ describe("REST Integration", () => { it("adds bearer auth", async () => { const query = { - authConfigName: "bearer-1" + authConfigId: "0d91d732f34e4befabeff50b392a8ff3" } await config.integration.read(query) expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {