Skip to content

Commit

Permalink
[connectors] add a CLI command confluence me (#9382)
Browse files Browse the repository at this point in the history
* add a command "me" to Confluence CLI

* lint

* add missing types
  • Loading branch information
aubin-tchoi authored Dec 13, 2024
1 parent 2cf24b7 commit 7c27592
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
30 changes: 29 additions & 1 deletion connectors/src/connectors/confluence/lib/cli.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
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,
confluenceUpsertPageWithFullParentsWorkflow,
} 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");
Expand Down
15 changes: 14 additions & 1 deletion types/src/connectors/admin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export type ConnectorsCommandType = t.TypeOf<typeof ConnectorsCommandSchema>;
*/
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]),
Expand All @@ -38,6 +42,13 @@ export const ConfluenceCommandSchema = t.type({
});
export type ConfluenceCommandType = t.TypeOf<typeof ConfluenceCommandSchema>;

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]),
Expand Down Expand Up @@ -425,6 +436,8 @@ export const AdminResponseSchema = t.union([
AdminSuccessResponseSchema,
BatchAllResponseSchema,
CheckFileGenericResponseSchema,
ConfluenceMeResponseSchema,
ConfluenceUpsertPageResponseSchema,
GetParentsResponseSchema,
IntercomCheckConversationResponseSchema,
IntercomCheckMissingConversationsResponseSchema,
Expand Down

0 comments on commit 7c27592

Please sign in to comment.