Skip to content

Commit

Permalink
feaT: SP
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-dixit committed Nov 2, 2024
1 parent 9af3781 commit 632ddba
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 32 deletions.
8 changes: 4 additions & 4 deletions js/src/cli/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from "commander";
import { Composio } from "../sdk";
import inquirer from "inquirer";
import open from "open";
import { GetConnectorListResDTO } from "../sdk/client";
import { GetConnectionInfoData, GetConnectionInfoResponse, GetConnectorInfoResDTO, GetConnectorListResDTO } from "../sdk/client";

export default class AddCommand {
private program: Command;
Expand All @@ -30,14 +30,14 @@ export default class AddCommand {
appName: appName.toLowerCase(),
});

let firstIntegration: GetConnectorListResDTO | undefined;
let firstIntegration: GetConnectorInfoResDTO | undefined;
if (integration?.items?.length === 0 || options.force || options.skipDefaultConnector) {
firstIntegration = (await this.createIntegration(
appName,
options.skipDefaultConnector,
)) as GetConnectorListResDTO;
)) as GetConnectorInfoResDTO;
}else{
firstIntegration = (integration as GetConnectorListResDTO)?.items[0] as GetConnectorListResDTO;
firstIntegration = (integration as GetConnectorListResDTO)?.items[0] as GetConnectorInfoResDTO;
}
if (!firstIntegration) {
console.log(chalk.red("No integration found or created"));
Expand Down
4 changes: 2 additions & 2 deletions js/src/sdk/actionRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ describe("ActionRegistry", () => {

await actionRegistry.createAction(options);

const actions = await actionRegistry.getTools({actions: ["testAction"]});
const actions = await actionRegistry.getActions({actions: ["testAction"]});
expect(actions.length).toBe(1);
expect(actions[0].parameters.properties).toHaveProperty("param1");
});

it("should return an empty array if no actions match the names", async () => {
const actions = await actionRegistry.getTools({actions: ["nonExistentAction"]});
const actions = await actionRegistry.getActions({actions: ["nonExistentAction"]});

expect(actions.length).toBe(0);
});
Expand Down
4 changes: 2 additions & 2 deletions js/src/sdk/base.toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ComposioToolSet {
});
const uniqueLocalActions = Array.from(localActionsMap.values());
const _newActions = filters.actions?.map((action: string) => action.toLowerCase());
const toolsWithCustomActions = (await this.customActionRegistry.getTools({ actions: _newActions!})).filter((action: any) => {
const toolsWithCustomActions = (await this.customActionRegistry.getActions({ actions: _newActions!})).filter((action: any) => {
if (_newActions && !_newActions.includes(action.parameters.title.toLowerCase()!)) {
return false;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ export class ComposioToolSet {
}

private isCustomAction(action: string) {
return this.customActionRegistry.getTools({ actions: [action] }).then((actions: any) => actions.length > 0);
return this.customActionRegistry.getActions({ actions: [action] }).then((actions: any) => actions.length > 0);
}

async executeAction(
Expand Down
2 changes: 1 addition & 1 deletion js/src/sdk/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ export type ActionsControllerV1GetActionResponse = ActionDetails;
export type ActionsControllerV1GetActionError = unknown;

export type ConnectionsControllerGetConnectionsData = {
query?: {
query: {
appNames?: unknown;
connectionId?: string;
integrationId?: string;
Expand Down
15 changes: 6 additions & 9 deletions js/src/sdk/models/activeTriggers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ import { describe, it, expect, beforeAll } from "@jest/globals";
import { getBackendClient } from "../testUtils/getBackendClient";
import { ActiveTriggers } from "./activeTriggers";

describe("Apps class tests", () => {
describe("Active Triggers class tests", () => {
let backendClient;
let activeTriggers: ActiveTriggers;

beforeAll(() => {
backendClient = getBackendClient();
activeTriggers = new ActiveTriggers(backendClient);

});

it("should get a specific action", async () => {
it("should retrieve a list of active triggers", async () => {
const activeTriggersList = await activeTriggers.list();
expect(activeTriggersList).toBeInstanceOf(Array);
expect(activeTriggersList).not.toHaveLength(0);
});

it("should get a list of actions", async () => {
it("should retrieve details of a specific active trigger", async () => {
const activeTriggersList = await activeTriggers.list();
const firstTrigger= activeTriggersList[0];
const activeTrigger = await activeTriggers.get({ path:{
triggerId: firstTrigger.id
}
});
const firstTrigger = activeTriggersList[0];

const activeTrigger = await activeTriggers.get({ path: { triggerId: firstTrigger.id } });
expect(activeTrigger).toBeDefined();
});

Expand Down
33 changes: 28 additions & 5 deletions js/src/sdk/models/activeTriggers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
import { TriggersControllerListTriggersData } from "../client";
import { TriggersControllerGetActiveTriggersData, TriggersControllerGetTriggerData } from "../client/types.gen";
import { TriggersControllerGetActiveTriggersData, TriggersControllerGetActiveTriggersResponse, TriggersControllerGetTriggerData } from "../client/types.gen";
import apiClient from "../client/client"
import { BackendClient } from "./backendClient";
import { CEG } from "../utils/error";

type TActiveTrigger = {
id: string;
connectionId: string;
triggerName: string;
triggerData: string;
triggerConfig: Record<string, any>;
state: Record<string, any>;
createdAt: string;
updatedAt: string;
disabledAt: string | null;
disabledReason: string | null;
}
type TActiveTriggersListResponse = {
triggers: Array<TActiveTrigger>;
pageInfo: {
currentPage: number;
perPage: number;
totalPages: number;
};
status: "success";
}
export class ActiveTriggers {

backendClient: BackendClient;
Expand All @@ -22,8 +43,8 @@ export class ActiveTriggers {
*/
async get(data: TriggersControllerGetTriggerData) {
try {
const response = await apiClient.triggers.getTrigger(data);
return response.data;
const response = await apiClient.triggers.getTrigger(data)
return response.data as TActiveTrigger;
} catch (error) {
throw CEG.handleError(error);
}
Expand All @@ -40,8 +61,10 @@ export class ActiveTriggers {
*/
async list(data: TriggersControllerGetActiveTriggersData = {}) {
try {
const response = await apiClient.triggers.getActiveTriggers({ query: data });
return (response.data as Record<string, string>).triggers;
const {data: response} = await apiClient.triggers.getActiveTriggers({ query: data })

const newResponse = response as TActiveTriggersListResponse;
return newResponse.triggers;
} catch (error) {
throw CEG.handleError(error);
}
Expand Down
11 changes: 6 additions & 5 deletions js/src/sdk/models/connectedAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@ import apiClient from "../client/client"
import { BackendClient } from "./backendClient";
import { CEG } from "../utils/error";

type ConnectedAccountsListData = ConnectionsControllerGetConnectionsData['query'] & {appNames?: string};
export class ConnectedAccounts {
backendClient: BackendClient;

constructor(backendClient: BackendClient) {
this.backendClient = backendClient;
}

async list(data: Pick<ConnectionsControllerGetConnectionsData,'query'>): Promise<GetConnectionsResponseDto> {
async list(data: ConnectedAccountsListData): Promise<GetConnectionsResponseDto> {
try {

const res = await apiClient.connections.getConnections({ query: data });
return res.data!;
} catch (error) {
throw CEG.handleError(error);
}
}

async create(data: InitiateConnectionPayloadDto = { integrationId: "" }) {
async create(data: InitiateConnectionPayloadDto) {
try {
const res = await apiClient.connections.initiateConnection({ body: data });
return res.data;
const {data: res} = await apiClient.connections.initiateConnection({ body: data });
//@ts-ignore
return new ConnectionRequest(res.connectionStatus, res.connectedAccountId, res.redirectUrl);
} catch (error) {
throw CEG.handleError(error);
}
Expand Down
5 changes: 4 additions & 1 deletion js/src/sdk/models/triggers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ describe("Apps class tests subscribe", () => {


it("should create a new trigger for gmail", async () => {
const connectedAccount = await connectedAccounts.list({ query: { user_uuid: 'default' } });
const connectedAccount = await connectedAccounts.list({ user_uuid: 'default' });

const connectedAccountId = connectedAccount.items.find(item => item.appName === 'gmail')?.id;
if(!connectedAccountId) {
throw new Error("No connected account found");
}
const trigger = await triggers.setup(connectedAccountId, 'gmail_new_gmail_message', {
"userId": connectedAccount.items[0].id,
"interval": 60,
Expand Down
12 changes: 9 additions & 3 deletions js/src/sdk/models/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export class Triggers {
enabled: true
}
});
return response.data;
return {
status: "success"
}
} catch (error) {
throw CEG.handleError(error);
}
Expand All @@ -85,7 +87,9 @@ export class Triggers {
enabled: false
}
});
return response.data;
return {
status: "success"
}
} catch (error) {
throw CEG.handleError(error);
}
Expand All @@ -96,7 +100,9 @@ export class Triggers {
const response = await apiClient.triggers.deleteTrigger({
path: data
});
return response.data;
return {
status: "success"
}
} catch (error) {
throw CEG.handleError(error);
}
Expand Down

0 comments on commit 632ddba

Please sign in to comment.