Integration API.

This commit is contained in:
mike12345567 2024-12-02 16:48:34 +00:00
parent 98de7e69d1
commit bb4d7e0b32
3 changed files with 22 additions and 4 deletions

View File

@ -1,12 +1,17 @@
import { getDefinition, getDefinitions } from "../../integrations"
import { SourceName, UserCtx } from "@budibase/types"
import {
SourceName,
UserCtx,
FetchIntegrationsResponse,
FindIntegrationResponse,
} from "@budibase/types"
const DISABLED_EXTERNAL_INTEGRATIONS = [
SourceName.AIRTABLE,
SourceName.BUDIBASE,
]
export async function fetch(ctx: UserCtx) {
export async function fetch(ctx: UserCtx<void, FetchIntegrationsResponse>) {
const definitions = await getDefinitions()
for (let disabledIntegration of DISABLED_EXTERNAL_INTEGRATIONS) {
delete definitions[disabledIntegration]
@ -14,10 +19,14 @@ export async function fetch(ctx: UserCtx) {
ctx.body = definitions
}
export async function find(ctx: UserCtx) {
export async function find(ctx: UserCtx<void, FindIntegrationResponse>) {
const sourceType = ctx.params?.type
if (DISABLED_EXTERNAL_INTEGRATIONS.indexOf(sourceType) !== -1) {
ctx.throw(400, `Invalid source type - ${sourceType} is not supported.`)
}
ctx.body = await getDefinition(ctx.params.type)
const integration = await getDefinition(ctx.params.type)
if (!integration) {
ctx.throw(400, "Integration not found")
}
ctx.body = integration
}

View File

@ -10,3 +10,4 @@ export * from "./user"
export * from "./rowAction"
export * from "./automation"
export * from "./component"
export * from "./integration"

View File

@ -0,0 +1,8 @@
import { Integration, SourceName } from "../../../sdk"
export type FetchIntegrationsResponse = Record<
SourceName,
Integration | undefined
>
export type FindIntegrationResponse = Integration