Skip to content

Commit

Permalink
feat: utkarsh review I
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-dixit committed Dec 27, 2024
1 parent 8af7610 commit d21fd9f
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 43 deletions.
4 changes: 2 additions & 2 deletions js/src/cli/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class TriggerDisable {
async handleAction(triggerId: string): Promise<void> {
const composioClient = new Composio({});
try {
await composioClient.triggers.disable(triggerId);
await composioClient.triggers.disable({ triggerId });
console.log(chalk.green(`Trigger ${triggerId} disabled`));
} catch (error) {
console.log(chalk.red(`Error disabling trigger ${triggerId}: ${error}`));
Expand All @@ -201,7 +201,7 @@ export class TriggerEnable {
async handleAction(triggerId: string): Promise<void> {
const composioClient = new Composio({});
try {
await composioClient.triggers.enable(triggerId);
await composioClient.triggers.enable({ triggerId });
console.log(chalk.green(`Trigger ${triggerId} enabled`));
} catch (error) {
console.log(chalk.red(`Error enabling trigger ${triggerId}: ${error}`));
Expand Down
2 changes: 0 additions & 2 deletions js/src/sdk/base.toolset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,9 @@ describe("ComposioToolSet class tests", () => {

const postProcessor = ({
actionName: _actionName,
appName: _appName,
toolResponse,
}: {
actionName: string;
appName: string;
toolResponse: ActionExecutionResDto;
}) => {
return {
Expand Down
1 change: 0 additions & 1 deletion js/src/sdk/base.toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ export class ComposioToolSet {
for (const processor of allOutputProcessor) {
dataToReturn = processor({
actionName: meta.action,
appName: "",
toolResponse: dataToReturn,
});
}
Expand Down
2 changes: 1 addition & 1 deletion js/src/sdk/models/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Actions {
* The response includes the action's name, display name, description, input parameters, expected response, associated app information, and enabled status.
*
* @param {GetActionData} data The data for the request.
* @returns {CancelablePromise<GetActionResponse[0]>} A promise that resolves to the details of the action.
* @returns {Promise<GetActionResponse[0]>} A promise that resolves to the details of the action.
* @throws {ComposioError} If the request fails.
*/
async get(data: GetActionItemParam): Promise<ActionDetails> {
Expand Down
8 changes: 4 additions & 4 deletions js/src/sdk/models/activeTriggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ActiveTriggers {
* The response includes the trigger's name, description, input parameters, expected response, associated app information, and enabled status.
*
* @param {TriggerItemParam} data The data for the request.
* @returns {CancelablePromise<TriggerItem>} A promise that resolves to the details of the active trigger.
* @returns {Promise<TriggerItem>} A promise that resolves to the details of the active trigger.
* @throws {ComposioError} If the request fails.
*/
async get({ triggerId }: TriggerItemParam) {
Expand Down Expand Up @@ -58,7 +58,7 @@ export class ActiveTriggers {
* This method allows you to fetch a list of all the available active triggers. It supports pagination to handle large numbers of triggers. The response includes an array of trigger objects, each containing information such as the trigger's name, description, input parameters, expected response, associated app information, and enabled status.
*
* @param {GetActiveTriggersData} data The data for the request.
* @returns {CancelablePromise<ZActiveTriggerItemRes[]>} A promise that resolves to the list of all active triggers.
* @returns {Promise<ZActiveTriggerItemRes[]>} A promise that resolves to the list of all active triggers.
* @throws {ComposioError} If the request fails.
*/
async list(data: GetActiveTriggersData = {}): Promise<TriggerItem[]> {
Expand All @@ -83,7 +83,7 @@ export class ActiveTriggers {
* Enables the previously disabled trigger.
*
* @param {TriggerItemParam} data The data for the request.
* @returns {CancelablePromise<TriggerChangeResponse>} A promise that resolves to the response of the enable request.
* @returns {Promise<{status: string}>} A promise that resolves to the response of the enable request.
* @throws {ComposioError} If the request fails.
*/
async enable(data: TriggerItemParam): Promise<{ status: string }> {
Expand Down Expand Up @@ -112,7 +112,7 @@ export class ActiveTriggers {
* Disables the previously enabled trigger.
*
* @param {TriggerItemParam} data The data for the request.
* @returns {CancelablePromise<TriggerChangeResponse>} A promise that resolves to the response of the disable request.
* @returns {Promise<{status: string}>} A promise that resolves to the response of the disable request.
*/
async disable(data: TriggerItemParam): Promise<TriggerChangeResponse> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
Expand Down
2 changes: 1 addition & 1 deletion js/src/sdk/models/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Apps {
* This method allows clients to fetch detailed information about a specific app by providing its unique key. The response includes the app's name, key, status, description, logo, categories, authentication schemes, and other metadata.
*
* @param {GetAppDataParams} data The data for the request, including the app's unique key.
* @returns {CancelablePromise<AppItemResponse>} A promise that resolves to the details of the app.
* @returns {Promise<AppItemResponse>} A promise that resolves to the details of the app.
* @throws {ComposioError} If the request fails.
*/
async get(data: GetAppDataParams): Promise<AppItemResponse> {
Expand Down
22 changes: 5 additions & 17 deletions js/src/sdk/models/connectedAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import {
ZInitiateConnectionPayloadDto,
ZListConnectionsData,
ZSaveUserAccessDataParam,
ZSingleCOnnectionParam,
ZSingleConnectionParams,
} from "../types/connectedAccount";
import { ZAuthMode } from "../types/integration";
import { CEG } from "../utils/error";
import { COMPOSIO_SDK_ERROR_CODES } from "../utils/errors/src/constants";
import { TELEMETRY_LOGGER } from "../utils/telemetry";
import { TELEMETRY_EVENTS } from "../utils/telemetry/events";
import { Apps } from "./apps";
Expand All @@ -26,7 +25,7 @@ import { Integrations } from "./integrations";
// Schema type from conectedAccount.ts
type ConnectedAccountsListData = z.infer<typeof ZListConnectionsData>;
type InitiateConnectionDataReq = z.infer<typeof ZInitiateConnectionDataReq>;
type SingleConnectionParam = z.infer<typeof ZSingleCOnnectionParam>;
type SingleConnectionParam = z.infer<typeof ZSingleConnectionParams>;
type SaveUserAccessDataParam = z.infer<typeof ZSaveUserAccessDataParam>;
type InitiateConnectionPayloadDto = z.infer<
typeof ZInitiateConnectionPayloadDto
Expand Down Expand Up @@ -96,7 +95,7 @@ export class ConnectedAccounts {
params: { data },
});
try {
ZSingleCOnnectionParam.parse(data);
ZSingleConnectionParams.parse(data);
const res = await apiClient.connections.getConnection({
path: data,
throwOnError: true,
Expand All @@ -114,7 +113,7 @@ export class ConnectedAccounts {
params: { data },
});
try {
ZSingleCOnnectionParam.parse(data);
ZSingleConnectionParams.parse(data);
const res = await apiClient.connections.deleteConnection({
path: data,
throwOnError: true,
Expand Down Expand Up @@ -173,17 +172,6 @@ export class ConnectedAccounts {
});

integrationId = integration?.id!;

if (!integrationId) {
throw CEG.getCustomError(
COMPOSIO_SDK_ERROR_CODES.BACKEND.BAD_REQUEST,
{
message: `Can't create integration for ${appName} with authMode ${authMode}`,
possibleFix:
"Check if the authMode is supported by the app and validate the authConfig",
}
);
}
}

const res = await client.connections
Expand Down Expand Up @@ -255,7 +243,7 @@ export class ConnectionRequest {
data: SingleConnectionParam
): Promise<GetConnectionInfoResponse> {
try {
ZSingleCOnnectionParam.parse(data);
ZSingleConnectionParams.parse(data);
const res = await client.connections.getConnectionInfo({ path: data });
return res.data!;
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions js/src/sdk/models/triggers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ describe("Apps class tests subscribe", () => {
});

it("should disable, enable, and then disable the created trigger", async () => {
let trigger = await triggers.disable(triggerId);
let trigger = await triggers.disable({ triggerId });
expect(trigger.status).toBe("success");

trigger = await triggers.enable(triggerId);
trigger = await triggers.enable({ triggerId });
expect(trigger.status).toBe("success");

trigger = await triggers.disable(triggerId);
trigger = await triggers.disable({ triggerId });
expect(trigger.status).toBe("success");
});

Expand Down
16 changes: 8 additions & 8 deletions js/src/sdk/models/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Triggers {
* This method allows you to fetch a list of all the available triggers. It supports pagination to handle large numbers of triggers. The response includes an array of trigger objects, each containing information such as the trigger's name, description, input parameters, expected response, associated app information, and enabled status.
*
* @param {ListTriggersData} data The data for the request.
* @returns {CancelablePromise<ListTriggersResponse>} A promise that resolves to the list of all triggers.
* @returns {Promise<ListTriggersResponse>} A promise that resolves to the list of all triggers.
* @throws {ComposioError} If the request fails.
*/
async list(data: TTriggerListParam = {}): Promise<TriggerListResponse> {
Expand Down Expand Up @@ -83,7 +83,7 @@ export class Triggers {
* Setup a trigger for a connected account.
*
* @param {SetupTriggerData} data The data for the request.
* @returns {CancelablePromise<SetupTriggerResponse>} A promise that resolves to the setup trigger response.
* @returns {Promise<SetupTriggerResponse>} A promise that resolves to the setup trigger response.
* @throws {ComposioError} If the request fails.
*/
async setup(params: TTriggerSetupParam): Promise<TriggerSetupResponse> {
Expand Down Expand Up @@ -122,16 +122,16 @@ export class Triggers {
* @returns {Promise<boolean>} A promise that resolves to the response of the enable request.
* @throws {ComposioError} If the request fails.
*/
async enable(triggerInstanceId: string) {
async enable({ triggerId }: { triggerId: string }) {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "enable",
file: this.fileName,
params: { triggerInstanceId },
params: { triggerId },
});
try {
await apiClient.triggers.switchTriggerInstanceStatus({
path: {
triggerId: triggerInstanceId,
triggerId: triggerId,
},
body: {
enabled: true,
Expand All @@ -152,16 +152,16 @@ export class Triggers {
* @returns {Promise<boolean>} A promise that resolves to the response of the disable request.
* @throws {ComposioError} If the request fails.
*/
async disable(triggerInstanceId: string) {
async disable({ triggerId }: { triggerId: string }) {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "disable",
file: this.fileName,
params: { triggerInstanceId },
params: { triggerId },
});
try {
await apiClient.triggers.switchTriggerInstanceStatus({
path: {
triggerId: triggerInstanceId,
triggerId: triggerId,
},
body: {
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion js/src/sdk/types/connectedAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const ZSaveUserAccessDataParam = z.object({
entityId: z.string().optional(),
});

export const ZSingleCOnnectionParam = z.object({
export const ZSingleConnectionParams = z.object({
connectedAccountId: z.string(),
});

Expand Down
1 change: 0 additions & 1 deletion js/src/sdk/utils/processor/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { saveFile } from "../fileUtils";

export const fileResponseProcessor: TPostProcessor = ({
actionName,
appName: _appName,
toolResponse,
}) => {
const responseData =
Expand Down
2 changes: 0 additions & 2 deletions js/src/types/base_toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ export type TPreProcessor = ({

export type TPostProcessor = ({
actionName,
appName,
toolResponse,
}: {
actionName: string;
appName: string;
toolResponse: ActionExecutionResDto;
}) => ActionExecutionResDto;

Expand Down

0 comments on commit d21fd9f

Please sign in to comment.