From 1c4ff2828190ff4ec8342c5fa071a847058e43da Mon Sep 17 00:00:00 2001 From: Aubin Date: Fri, 13 Dec 2024 08:50:06 +0100 Subject: [PATCH] feat: add page upsertion to the CLI command --- .../src/connectors/confluence/lib/cli.ts | 52 +++++++++++++++++++ types/src/connectors/admin/cli.ts | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/connectors/src/connectors/confluence/lib/cli.ts b/connectors/src/connectors/confluence/lib/cli.ts index 48b4ab1f8e64..fb93e9a85858 100644 --- a/connectors/src/connectors/confluence/lib/cli.ts +++ b/connectors/src/connectors/confluence/lib/cli.ts @@ -4,7 +4,14 @@ import type { ConfluenceUpsertPageResponseType, } from "@dust-tt/types"; +import { + fetchConfluenceConfigurationActivity, + getConfluenceClient, + upsertConfluencePageToDataSource, +} from "@connectors/connectors/confluence/temporal/activities"; +import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config"; import { default as topLogger } from "@connectors/logger/logger"; +import { ConnectorResource } from "@connectors/resources/connector_resource"; export const confluence = async ({ command, @@ -21,6 +28,51 @@ export const confluence = async ({ if (!args.pageId) { throw new Error("Missing --pageId argument"); } + const connectorId = args.connectorId; + const pageId = args.pageId; + + const connector = await ConnectorResource.fetchById(connectorId); + if (!connector) { + throw new Error("Connector not found."); + } + const dataSourceConfig = dataSourceConfigFromConnector(connector); + const confluenceConfig = + await fetchConfluenceConfigurationActivity(connectorId); + + const loggerArgs = { + connectorId, + dataSourceId: dataSourceConfig.dataSourceId, + pageId, + workspaceId: dataSourceConfig.workspaceId, + }; + const localLogger = logger.child(loggerArgs); + + const client = await getConfluenceClient( + { cloudId: confluenceConfig?.cloudId }, + connector + ); + + const page = await client.getPageById(pageId); + if (!page) { + localLogger.info("Confluence page not found."); + return false; + } + const space = await client.getSpaceById(page.spaceId); + if (!space) { + localLogger.info("Confluence space not found."); + return false; + } + + localLogger.info("Upserting Confluence page."); + await upsertConfluencePageToDataSource( + page, + space.name, + confluenceConfig, + "batch", + dataSourceConfig, + loggerArgs + ); + break; } diff --git a/types/src/connectors/admin/cli.ts b/types/src/connectors/admin/cli.ts index 2cac6ea2e6d2..136aaeb222aa 100644 --- a/types/src/connectors/admin/cli.ts +++ b/types/src/connectors/admin/cli.ts @@ -31,7 +31,7 @@ export const ConfluenceCommandSchema = t.type({ command: t.literal("upsert-page"), args: t.type({ connectorId: t.union([t.number, t.undefined]), - pageId: t.union([t.number, t.undefined]), + pageId: t.union([t.string, t.undefined]), }), }); export type ConfluenceCommandType = t.TypeOf;