Skip to content

Commit

Permalink
fix: Actions parity in TS SDK (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
plxity authored Dec 12, 2024
1 parent 3f02820 commit 051bfa0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ on:
push:
branches:
- master
paths:
- 'python/**'
pull_request:
paths:
- 'python/**'

jobs:
lock_check:
Expand Down
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"openapispec:generate": "npx @hey-api/openapi-ts",
"run:cli": "ts-node src/cli/index.ts",
"run:sample": "ts-node sample.ts",
"eslint": "eslint 'src/**/*.{ts,js}' --max-warnings=281",
"eslint": "eslint 'src/**/*.{ts,js}' --max-warnings=261",
"prettier": "prettier --write 'src/**/*.{ts,js,cjs}'",
"prettier:check": "prettier --check 'src/**/*.{ts,js,mjs,cjs}'",
"build": "rollup -c rollup.config.mjs && ./setup_cli.sh",
Expand Down
74 changes: 74 additions & 0 deletions js/src/cli/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import chalk from "chalk";
import { Command } from "commander";
import client from "../sdk/client/client";
import { getOpenAPIClient } from "../sdk/utils/config";
import { ListActionsV2Data } from "../sdk/client";

export default class ActionCommand {
private program: Command;

constructor(program: Command) {
this.program = program;
this.program
.command("actions")
.description("Composio Actions")
.option(
"-a, --apps <appName>",
"List all actions for the given apps",
(value, previous: string[]) => previous.concat([value]),
[]
)
.option(
"--tags <tagName>",
"List all actions for the given tags",
(value, previous: string[]) => previous.concat([value]),
[]
)
.option(
"--use-case <useCase>",
"Search for actions based on the given use case"
)
.option("--limit <limit>", "Limit the number of actions to display")
.option("--enabled", "Only show enabled actions")
.action(this.handleAction.bind(this));
}

private async handleAction(options: {
apps?: string[];
tags?: string[];
useCase?: string;
limit?: number;
enabled?: boolean;
}): Promise<void> {
getOpenAPIClient();
const { apps = [], tags = [], useCase, limit, enabled } = options;
if (apps.length === 0) {
console.log(chalk.red("Please provide at least one app name"));

Check warning on line 46 in js/src/cli/actions.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

Unexpected console statement
return;
}
const data: ListActionsV2Data = {
query: {
apps: apps.join(","),
...(tags.length && { tags: tags.join(",") }),
...(limit && { limit }),
...(enabled && { showEnabledOnly: enabled }),
...(useCase && { useCase }),
},
};
try {
const response = await client.actionsV2.listActionsV2(data);
if (response.data?.items.length === 0) {
console.log(chalk.yellow("No actions found"));

Check warning on line 61 in js/src/cli/actions.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

Unexpected console statement
return;
}
console.log(chalk.green("Here are the actions for the app:"));

Check warning on line 64 in js/src/cli/actions.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

Unexpected console statement
console.log("");

Check warning on line 65 in js/src/cli/actions.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

Unexpected console statement
// render list
const actions = response.data?.items || [];
actions.forEach((action) => console.log(action.name));

Check warning on line 68 in js/src/cli/actions.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

Unexpected console statement
} catch (error) {
console.log(chalk.red((error as Error)?.message));

Check warning on line 70 in js/src/cli/actions.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

Unexpected console statement
return;
}
}
}
2 changes: 2 additions & 0 deletions js/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import login from "./login";
import logout from "./logout";
import triggers from "./triggers";
import whoami from "./whoami";
import actions from "./actions";

// SDK Imports
import { TELEMETRY_EVENTS } from "../sdk/utils/telemetry/events";
Expand All @@ -28,6 +29,7 @@ new connections(program);
new integrations(program);
new triggers(program);
new add(program);
new actions(program);

function formatLine(content: string): string {
return `${content}`;
Expand Down

0 comments on commit 051bfa0

Please sign in to comment.