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 { Table, Modal, Layout, ActionButton } from "@budibase/bbui"
|
||||||
import AuthTypeRenderer from "./AuthTypeRenderer.svelte"
|
import AuthTypeRenderer from "./AuthTypeRenderer.svelte"
|
||||||
import RestAuthenticationModal from "./RestAuthenticationModal.svelte"
|
import RestAuthenticationModal from "./RestAuthenticationModal.svelte"
|
||||||
|
import { uuid } from "builderStore/uuid"
|
||||||
|
|
||||||
export let configs = []
|
export let configs = []
|
||||||
|
|
||||||
|
@ -20,24 +21,22 @@
|
||||||
|
|
||||||
const onConfirm = config => {
|
const onConfirm = config => {
|
||||||
if (currentConfig) {
|
if (currentConfig) {
|
||||||
// TODO: Update with _id
|
|
||||||
configs = configs.map(c => {
|
configs = configs.map(c => {
|
||||||
// replace the current config with the new one
|
// replace the current config with the new one
|
||||||
if (c.name === currentConfig.name) {
|
if (c._id === currentConfig._id) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
configs.push(config)
|
config._id = uuid()
|
||||||
configs = [...configs]
|
configs = [...configs, config]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDelete = () => {
|
const onDelete = () => {
|
||||||
// TODO: Update with _id
|
|
||||||
configs = configs.filter(c => {
|
configs = configs.filter(c => {
|
||||||
return c.name !== currentConfig.name
|
return c._id !== currentConfig._id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -156,7 +156,6 @@
|
||||||
confirmText={currentConfig ? "Update" : "Add"}
|
confirmText={currentConfig ? "Update" : "Add"}
|
||||||
disabled={hasErrors || !hasChanged}
|
disabled={hasErrors || !hasChanged}
|
||||||
cancelText={"Cancel"}
|
cancelText={"Cancel"}
|
||||||
warning={true}
|
|
||||||
size="M"
|
size="M"
|
||||||
showSecondaryButton={!!currentConfig}
|
showSecondaryButton={!!currentConfig}
|
||||||
secondaryButtonText={"Delete"}
|
secondaryButtonText={"Delete"}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
export const AUTH_TYPES = {
|
export const AUTH_TYPES = {
|
||||||
BEARER: "bearer",
|
|
||||||
BASIC: "basic",
|
BASIC: "basic",
|
||||||
|
BEARER: "bearer",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AUTH_TYPE_LABELS = [
|
export const AUTH_TYPE_LABELS = [
|
||||||
{
|
|
||||||
label: "Bearer Token",
|
|
||||||
value: AUTH_TYPES.BEARER,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: "Basic Auth",
|
label: "Basic Auth",
|
||||||
value: AUTH_TYPES.BASIC,
|
value: AUTH_TYPES.BASIC,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Bearer Token",
|
||||||
|
value: AUTH_TYPES.BEARER,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
|
@ -19,6 +19,7 @@ enum AuthType {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AuthConfig {
|
interface AuthConfig {
|
||||||
|
_id: string
|
||||||
name: string
|
name: string
|
||||||
type: AuthType
|
type: AuthType
|
||||||
config: BasicAuthConfig | BearerAuthConfig
|
config: BasicAuthConfig | BearerAuthConfig
|
||||||
|
@ -170,12 +171,12 @@ module RestModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processAuth(authConfigName: string) {
|
processAuth(authConfigId: string) {
|
||||||
if (!this.config.authConfigs || !authConfigName) {
|
if (!this.config.authConfigs || !authConfigId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const authConfig = this.config.authConfigs.filter(
|
const authConfig = this.config.authConfigs.filter(
|
||||||
authConfig => authConfig.name === authConfigName
|
c => c._id === authConfigId
|
||||||
)[0]
|
)[0]
|
||||||
let config
|
let config
|
||||||
switch (authConfig.type) {
|
switch (authConfig.type) {
|
||||||
|
@ -198,14 +199,14 @@ module RestModule {
|
||||||
headers = {},
|
headers = {},
|
||||||
json = {},
|
json = {},
|
||||||
method = "GET",
|
method = "GET",
|
||||||
authConfigName = "",
|
authConfigId = "",
|
||||||
}) {
|
}) {
|
||||||
this.headers = {
|
this.headers = {
|
||||||
...this.config.defaultHeaders,
|
...this.config.defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.processAuth(authConfigName)
|
this.processAuth(authConfigId)
|
||||||
|
|
||||||
const input: any = { method, headers: this.headers }
|
const input: any = { method, headers: this.headers }
|
||||||
if (json && typeof json === "object" && Object.keys(json).length > 0) {
|
if (json && typeof json === "object" && Object.keys(json).length > 0) {
|
||||||
|
|
|
@ -107,6 +107,7 @@ describe("REST Integration", () => {
|
||||||
|
|
||||||
describe("authentication", () => {
|
describe("authentication", () => {
|
||||||
const basicAuth = {
|
const basicAuth = {
|
||||||
|
_id: "c59c14bd1898a43baa08da68959b24686",
|
||||||
name: "basic-1",
|
name: "basic-1",
|
||||||
type : AuthType.BASIC,
|
type : AuthType.BASIC,
|
||||||
config : {
|
config : {
|
||||||
|
@ -116,6 +117,7 @@ describe("REST Integration", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const bearerAuth = {
|
const bearerAuth = {
|
||||||
|
_id: "0d91d732f34e4befabeff50b392a8ff3",
|
||||||
name: "bearer-1",
|
name: "bearer-1",
|
||||||
type : AuthType.BEARER,
|
type : AuthType.BEARER,
|
||||||
config : {
|
config : {
|
||||||
|
@ -132,7 +134,7 @@ describe("REST Integration", () => {
|
||||||
|
|
||||||
it("adds basic auth", async () => {
|
it("adds basic auth", async () => {
|
||||||
const query = {
|
const query = {
|
||||||
authConfigName: "basic-1"
|
authConfigId: "c59c14bd1898a43baa08da68959b24686"
|
||||||
}
|
}
|
||||||
await config.integration.read(query)
|
await config.integration.read(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
||||||
|
@ -145,7 +147,7 @@ describe("REST Integration", () => {
|
||||||
|
|
||||||
it("adds bearer auth", async () => {
|
it("adds bearer auth", async () => {
|
||||||
const query = {
|
const query = {
|
||||||
authConfigName: "bearer-1"
|
authConfigId: "0d91d732f34e4befabeff50b392a8ff3"
|
||||||
}
|
}
|
||||||
await config.integration.read(query)
|
await config.integration.read(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
||||||
|
|
Loading…
Reference in New Issue