Add _id field
This commit is contained in:
parent
e8755b6854
commit
4b1fb01eb4
|
@ -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
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -156,7 +156,6 @@
|
|||
confirmText={currentConfig ? "Update" : "Add"}
|
||||
disabled={hasErrors || !hasChanged}
|
||||
cancelText={"Cancel"}
|
||||
warning={true}
|
||||
size="M"
|
||||
showSecondaryButton={!!currentConfig}
|
||||
secondaryButtonText={"Delete"}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
]
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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}/?`, {
|
||||
|
|
Loading…
Reference in New Issue