diff --git a/connectors/src/connectors/confluence/lib/cli.ts b/connectors/src/connectors/confluence/lib/cli.ts index e3e7818bfc5c..4adf4e9ff670 100644 --- a/connectors/src/connectors/confluence/lib/cli.ts +++ b/connectors/src/connectors/confluence/lib/cli.ts @@ -1,11 +1,16 @@ import type { AdminSuccessResponseType, ConfluenceCommandType, + ConfluenceMeResponseType, ConfluenceUpsertPageResponseType, } from "@dust-tt/types"; import assert from "assert"; import fs from "fs/promises"; +import { + fetchConfluenceConfigurationActivity, + getConfluenceClient, +} from "@connectors/connectors/confluence/temporal/activities"; import { QUEUE_NAME } from "@connectors/connectors/confluence/temporal/config"; import { confluenceUpsertPagesWithFullParentsWorkflow, @@ -13,15 +18,38 @@ import { } from "@connectors/connectors/confluence/temporal/workflows"; import { getTemporalClient } from "@connectors/lib/temporal"; import { default as topLogger } from "@connectors/logger/logger"; +import { ConnectorResource } from "@connectors/resources/connector_resource"; export const confluence = async ({ command, args, }: ConfluenceCommandType): Promise< - AdminSuccessResponseType | ConfluenceUpsertPageResponseType + | AdminSuccessResponseType + | ConfluenceUpsertPageResponseType + | ConfluenceMeResponseType > => { const logger = topLogger.child({ majorCommand: "confluence", command, args }); switch (command) { + case "me": { + if (!args.connectorId) { + throw new Error("Missing --connectorId argument"); + } + const { connectorId } = args; + const connector = await ConnectorResource.fetchById(connectorId); + if (!connector) { + throw new Error("Connector not found."); + } + if (connector.type !== "confluence") { + throw new Error("Connector is not a Confluence connector."); + } + const confluenceConfig = + await fetchConfluenceConfigurationActivity(connectorId); + const client = await getConfluenceClient( + { cloudId: confluenceConfig?.cloudId }, + connector + ); + return { me: await client.getUserAccount() }; + } case "upsert-page": { if (!args.connectorId) { throw new Error("Missing --connectorId argument"); diff --git a/types/src/connectors/admin/cli.ts b/types/src/connectors/admin/cli.ts index 2d2ff0b74507..6fe34bb56b8a 100644 --- a/types/src/connectors/admin/cli.ts +++ b/types/src/connectors/admin/cli.ts @@ -28,7 +28,11 @@ export type ConnectorsCommandType = t.TypeOf; */ export const ConfluenceCommandSchema = t.type({ majorCommand: t.literal("confluence"), - command: t.union([t.literal("upsert-page"), t.literal("upsert-pages")]), + command: t.union([ + t.literal("me"), + t.literal("upsert-page"), + t.literal("upsert-pages"), + ]), args: t.type({ connectorId: t.union([t.number, t.undefined]), pageId: t.union([t.string, t.undefined]), @@ -38,6 +42,14 @@ export const ConfluenceCommandSchema = t.type({ }); export type ConfluenceCommandType = t.TypeOf; +export const ConfluenceMeResponseSchema = t.type({ + me: t.UnknownRecord, +}); + +export type ConfluenceMeResponseType = t.TypeOf< + typeof ConfluenceMeResponseSchema +>; + export const ConfluenceUpsertPageResponseSchema = t.type({ workflowId: t.string, workflowUrl: t.union([t.string, t.undefined]),