From bb4d7e0b3270a908327f72b3d6f3488c4d2cdc71 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 2 Dec 2024 16:48:34 +0000 Subject: [PATCH] Integration API. --- .../server/src/api/controllers/integration.ts | 17 +++++++++++++---- packages/types/src/api/web/app/index.ts | 1 + packages/types/src/api/web/app/integration.ts | 8 ++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 packages/types/src/api/web/app/integration.ts diff --git a/packages/server/src/api/controllers/integration.ts b/packages/server/src/api/controllers/integration.ts index 57038f8401..9f770ad049 100644 --- a/packages/server/src/api/controllers/integration.ts +++ b/packages/server/src/api/controllers/integration.ts @@ -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) { 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) { 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 } diff --git a/packages/types/src/api/web/app/index.ts b/packages/types/src/api/web/app/index.ts index 9cc0bf36b6..614446a1b7 100644 --- a/packages/types/src/api/web/app/index.ts +++ b/packages/types/src/api/web/app/index.ts @@ -10,3 +10,4 @@ export * from "./user" export * from "./rowAction" export * from "./automation" export * from "./component" +export * from "./integration" diff --git a/packages/types/src/api/web/app/integration.ts b/packages/types/src/api/web/app/integration.ts new file mode 100644 index 0000000000..8e52a32ba9 --- /dev/null +++ b/packages/types/src/api/web/app/integration.ts @@ -0,0 +1,8 @@ +import { Integration, SourceName } from "../../../sdk" + +export type FetchIntegrationsResponse = Record< + SourceName, + Integration | undefined +> + +export type FindIntegrationResponse = Integration