Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: throwOnError and error message more descriptive #838

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "composio-core",
"version": "0.2.8-4",
"version": "0.2.9-3",
"description": "",
"main": "lib/src/index.js",
"scripts": {
Expand Down
7 changes: 2 additions & 5 deletions js/src/sdk/base.toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ export class ComposioToolSet {
entityId: string = "default",
workspaceConfig: WorkspaceConfig = Workspace.Host()
) {
const clientApiKey: string | undefined = apiKey || getEnvVariable("COMPOSIO_API_KEY") || getUserDataJson().api_key;
if (!clientApiKey) {
throw new Error("API key is required, please pass it either by using `COMPOSIO_API_KEY` environment variable or during initialization");
}
const clientApiKey: string | undefined = apiKey || getEnvVariable("COMPOSIO_API_KEY") || getUserDataJson().api_key as string;
this.apiKey = clientApiKey;
this.client = new Composio(this.apiKey, baseUrl || undefined, runtime as string );
this.customActionRegistry = new ActionRegistry(this.client);
Expand Down Expand Up @@ -172,7 +169,7 @@ export class ComposioToolSet {
return action.schema;
});

const toolsActions = [...apps.items!, ...uniqueLocalActions, ...toolsWithCustomActions];
const toolsActions = [...apps?.items!, ...uniqueLocalActions, ...toolsWithCustomActions];

return toolsActions.map((action: any) => {
return this.modifyActionForLocalExecution(action);
Expand Down
43 changes: 41 additions & 2 deletions js/src/sdk/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,15 +933,19 @@ export const $CreateConnectorPayloadDTO = {
},
appId: {
type: 'string',
description: 'Application ID'
description: 'Composio App UUID to be used for authentication. Either specify this or appName'
},
appName: {
type: 'string',
description: 'Name of the app to be used for authentication. Either specify this or appId'
},
forceNewIntegration: {
type: 'boolean',
description: 'Flag to force new integration'
}
},
type: 'object',
required: ['name', 'appId']
required: ['name']
} as const;

export const $PatchConnectorReqDTO = {
Expand Down Expand Up @@ -1556,6 +1560,12 @@ export const $GetConnectionsQueryDto = {
},
showDisabled: {
type: 'boolean'
},
labels: {
items: {
type: 'string'
},
type: 'array'
}
},
type: 'object'
Expand All @@ -1578,12 +1588,31 @@ export const $InitiateConnectionPayloadDto = {
},
entityId: {
type: 'string'
},
labels: {
items: {
type: 'string'
},
type: 'array'
}
},
type: 'object',
required: ['data', 'integrationId']
} as const;

export const $UpdateConnectionLabelsPayloadDto = {
properties: {
labels: {
items: {
type: 'string'
},
type: 'array'
}
},
type: 'object',
required: ['labels']
} as const;

export const $InitiateConnectionResponse = {
properties: {
connectionStatus: {
Expand Down Expand Up @@ -1861,6 +1890,12 @@ export const $ActionsQueryDTO = {
},
showAll: {
type: 'boolean'
},
page: {
type: 'number'
},
offset: {
type: 'number'
}
},
type: 'object'
Expand Down Expand Up @@ -2368,6 +2403,10 @@ export const $TriggerResponseDTO = {
triggerId: {
type: 'string',
description: 'Optional trigger ID'
},
isNew: {
type: 'boolean',
description: 'Is new trigger. If true, the trigger was created just now or else it was already existing'
}
},
type: 'object',
Expand Down
13 changes: 12 additions & 1 deletion js/src/sdk/client/services.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import { createClient, createConfig, type Options } from '@hey-api/client-axios';
import type { IdentifyClientData, IdentifyClientError, IdentifyClientResponse, GetUserInfoError, GetUserInfoResponse, GenerateApiKeyData, GenerateApiKeyError, GenerateApiKeyResponse, ListApiKeysError, ListApiKeysResponse, DeleteApiKeyData, DeleteApiKeyError, DeleteApiKeyResponse, GetAppsData, GetAppsError, GetAppsResponse, GetOpenApiSpecsError, GetOpenApiSpecsResponse, DeleteOpenApiSpecToolData, DeleteOpenApiSpecToolError, DeleteOpenApiSpecToolResponse, AppControllerSendEmailToClientData, AppControllerSendEmailToClientError, AppControllerSendEmailToClientResponse, GetOpenApiSpecStatusData, GetOpenApiSpecStatusError, GetOpenApiSpecStatusResponse, GetAppData, GetAppError, GetAppResponse, CreateConnectorData, CreateConnectorError, CreateConnectorResponse, ListAllConnectorsError, ListAllConnectorsResponse, GetConnectorInfoData, GetConnectorInfoError, GetConnectorInfoResponse, ModifyConnectorData, ModifyConnectorError, ModifyConnectorResponse, DeleteConnectorData, DeleteConnectorError, DeleteConnectorResponse, GetConnectionsData, GetConnectionsError, GetConnectionsResponse, InitiateConnectionData, InitiateConnectionError, InitiateConnectionResponse2, GetConnectionData, GetConnectionError, GetConnectionResponse, DeleteConnectionData, DeleteConnectionError, DeleteConnectionResponse, GetConnectionInfoData, GetConnectionInfoError, GetConnectionInfoResponse, DisableConnectionData, DisableConnectionError, DisableConnectionResponse, EnableConnectionData, EnableConnectionError, EnableConnectionResponse, ListTriggersData, ListTriggersError, ListTriggersResponse, EnableTriggerData, EnableTriggerError, EnableTriggerResponse, GetActiveTriggersData, GetActiveTriggersError, GetActiveTriggersResponse, SwitchTriggerInstanceStatusData, SwitchTriggerInstanceStatusError, SwitchTriggerInstanceStatusResponse, DisableTriggerData, DisableTriggerError, DisableTriggerResponse, DeleteTriggerData, DeleteTriggerError, DeleteTriggerResponse, SetCallbackUrlData, SetCallbackUrlError, SetCallbackUrlResponse, GetWebhookUrlError, GetWebhookUrlResponse, GetTriggerLogsData, GetTriggerLogsError, GetTriggerLogsResponse, GetTriggerInfoV2Data, GetTriggerInfoV2Error, GetTriggerInfoV2Response, GetSentryDnsError, GetSentryDnsResponse, ClearCacheData, ClearCacheError, ClearCacheResponse, GenerateCliSessionError, GenerateCliSessionResponse, GetCliCodeData, GetCliCodeError, GetCliCodeResponse, VerifyCliCodeData, VerifyCliCodeError, VerifyCliCodeResponse, GetLogsData, GetLogsError, GetLogsResponse, PostLogsData, PostLogsError, PostLogsResponse, ListActionsV2Data, ListActionsV2Error, ListActionsV2Response, ListActionsMinimalV2Data, ListActionsMinimalV2Error, ListActionsMinimalV2Response, ExecuteActionV2Data, ExecuteActionV2Error, ExecuteActionV2Response, GetActionInputsV2Data, GetActionInputsV2Error, GetActionInputsV2Response, GetActionV2Data, GetActionV2Error, GetActionV2Response, ExecuteActionProxyV2Data, ExecuteActionProxyV2Error, ExecuteActionProxyV2Response, GetAnalyticsData, GetAnalyticsError, GetAnalyticsResponse, GetTopEntitiesData, GetTopEntitiesError, GetTopEntitiesResponse, UpdateWebhookData, UpdateWebhookError, UpdateWebhookResponse } from './types.gen';
import type { IdentifyClientData, IdentifyClientError, IdentifyClientResponse, GetUserInfoError, GetUserInfoResponse, GenerateApiKeyData, GenerateApiKeyError, GenerateApiKeyResponse, ListApiKeysError, ListApiKeysResponse, DeleteApiKeyData, DeleteApiKeyError, DeleteApiKeyResponse, GetAppsData, GetAppsError, GetAppsResponse, GetOpenApiSpecsError, GetOpenApiSpecsResponse, DeleteOpenApiSpecToolData, DeleteOpenApiSpecToolError, DeleteOpenApiSpecToolResponse, AppControllerSendEmailToClientData, AppControllerSendEmailToClientError, AppControllerSendEmailToClientResponse, GetOpenApiSpecStatusData, GetOpenApiSpecStatusError, GetOpenApiSpecStatusResponse, GetAppData, GetAppError, GetAppResponse, CreateConnectorData, CreateConnectorError, CreateConnectorResponse, ListAllConnectorsError, ListAllConnectorsResponse, GetConnectorInfoData, GetConnectorInfoError, GetConnectorInfoResponse, ModifyConnectorData, ModifyConnectorError, ModifyConnectorResponse, DeleteConnectorData, DeleteConnectorError, DeleteConnectorResponse, GetConnectionsData, GetConnectionsError, GetConnectionsResponse, InitiateConnectionData, InitiateConnectionError, InitiateConnectionResponse2, UpdateConnectionDataData, UpdateConnectionDataError, UpdateConnectionDataResponse, GetConnectionData, GetConnectionError, GetConnectionResponse, DeleteConnectionData, DeleteConnectionError, DeleteConnectionResponse, GetConnectionInfoData, GetConnectionInfoError, GetConnectionInfoResponse, DisableConnectionData, DisableConnectionError, DisableConnectionResponse, EnableConnectionData, EnableConnectionError, EnableConnectionResponse, ListTriggersData, ListTriggersError, ListTriggersResponse, EnableTriggerData, EnableTriggerError, EnableTriggerResponse, GetActiveTriggersData, GetActiveTriggersError, GetActiveTriggersResponse, SwitchTriggerInstanceStatusData, SwitchTriggerInstanceStatusError, SwitchTriggerInstanceStatusResponse, DisableTriggerData, DisableTriggerError, DisableTriggerResponse, DeleteTriggerData, DeleteTriggerError, DeleteTriggerResponse, SetCallbackUrlData, SetCallbackUrlError, SetCallbackUrlResponse, GetWebhookUrlError, GetWebhookUrlResponse, GetTriggerLogsData, GetTriggerLogsError, GetTriggerLogsResponse, GetTriggerInfoV2Data, GetTriggerInfoV2Error, GetTriggerInfoV2Response, GetSentryDnsError, GetSentryDnsResponse, ClearCacheData, ClearCacheError, ClearCacheResponse, GenerateCliSessionError, GenerateCliSessionResponse, GetCliCodeData, GetCliCodeError, GetCliCodeResponse, VerifyCliCodeData, VerifyCliCodeError, VerifyCliCodeResponse, GetLogsData, GetLogsError, GetLogsResponse, PostLogsData, PostLogsError, PostLogsResponse, ListActionsV2Data, ListActionsV2Error, ListActionsV2Response, ListActionsMinimalV2Data, ListActionsMinimalV2Error, ListActionsMinimalV2Response, ExecuteActionV2Data, ExecuteActionV2Error, ExecuteActionV2Response, GetActionInputsV2Data, GetActionInputsV2Error, GetActionInputsV2Response, GetActionV2Data, GetActionV2Error, GetActionV2Response, ExecuteActionProxyV2Data, ExecuteActionProxyV2Error, ExecuteActionProxyV2Response, GetAnalyticsData, GetAnalyticsError, GetAnalyticsResponse, GetTopEntitiesData, GetTopEntitiesError, GetTopEntitiesResponse, UpdateWebhookData, UpdateWebhookError, UpdateWebhookResponse } from './types.gen';

export const client = createClient(createConfig());

Expand Down Expand Up @@ -209,6 +209,17 @@ export class ConnectionsService {
});
}

/**
* Update connection data
* Update connection data
*/
public static updateConnectionData<ThrowOnError extends boolean = false>(options: Options<UpdateConnectionDataData, ThrowOnError>) {
return (options?.client ?? client).patch<UpdateConnectionDataResponse, UpdateConnectionDataError, ThrowOnError>({
...options,
url: '/api/v1/connectedAccounts/{connectedAccountId}/data'
});
}

/**
* Get connection
*/
Expand Down
39 changes: 37 additions & 2 deletions js/src/sdk/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,13 @@ export type CreateConnectorPayloadDTO = {
*/
useComposioAuth?: boolean;
/**
* Application ID
* Composio App UUID to be used for authentication. Either specify this or appName
*/
appId: string;
appId?: string;
/**
* Name of the app to be used for authentication. Either specify this or appId
*/
appName?: string;
/**
* Flag to force new integration
*/
Expand Down Expand Up @@ -969,6 +973,7 @@ export type GetConnectionsQueryDto = {
showActiveOnly?: boolean;
status?: string;
showDisabled?: boolean;
labels?: Array<(string)>;
};

export type InitiateConnectionPayloadDto = {
Expand All @@ -979,6 +984,11 @@ export type InitiateConnectionPayloadDto = {
redirectUri?: string;
userUuid?: string;
entityId?: string;
labels?: Array<(string)>;
};

export type UpdateConnectionLabelsPayloadDto = {
labels: Array<(string)>;
};

export type InitiateConnectionResponse = {
Expand Down Expand Up @@ -1104,6 +1114,8 @@ export type ActionsQueryDTO = {
usecaseLimit?: number;
filterImportantActions?: boolean;
showAll?: boolean;
page?: number;
offset?: number;
};

export type ActionsControllerV1 = {
Expand Down Expand Up @@ -1494,6 +1506,10 @@ export type TriggerResponseDTO = {
* Optional trigger ID
*/
triggerId?: string;
/**
* Is new trigger. If true, the trigger was created just now or else it was already existing
*/
isNew?: boolean;
};

export type WebhookURLResponseDTO = {
Expand Down Expand Up @@ -2292,6 +2308,7 @@ export type GetConnectionsData = {
appNames?: string;
connectionId?: string;
integrationId?: string;
labels?: Array<(string)>;
page?: number;
pageSize?: number;
showActiveOnly?: boolean;
Expand All @@ -2316,6 +2333,20 @@ export type InitiateConnectionResponse2 = InitiateConnectionResponse;

export type InitiateConnectionError = unknown;

export type UpdateConnectionDataData = {
/**
* UpdateConnectionLabelsPayloadDto
*/
body?: UpdateConnectionLabelsPayloadDto;
path: {
connectedAccountId: string;
};
};

export type UpdateConnectionDataResponse = unknown;

export type UpdateConnectionDataError = unknown;

export type GetConnectionData = {
path: {
connectedAccountId: string;
Expand Down Expand Up @@ -2560,6 +2591,8 @@ export type ListActionsV2Data = {
apps?: string;
filterImportantActions?: boolean;
limit?: number;
offset?: number;
page?: number;
showAll?: boolean;
showEnabledOnly?: boolean;
tags?: string;
Expand All @@ -2579,6 +2612,8 @@ export type ListActionsMinimalV2Data = {
apps?: string;
filterImportantActions?: boolean;
limit?: number;
offset?: number;
page?: number;
showAll?: boolean;
showEnabledOnly?: boolean;
tags?: string;
Expand Down
2 changes: 2 additions & 0 deletions js/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class Composio {
// // Parse the base URL and API key, falling back to environment variables or defaults if not provided.
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getClientBaseConfig(baseUrl, apiKey);

console.log("Using API Key: ", apiKeyParsed , "and baseURL: ", baseURLParsed);
if(!apiKeyParsed){

CEG.throwCustomError(ERROR.COMMON.API_KEY_UNAVAILABLE,{});
}

Expand Down
4 changes: 3 additions & 1 deletion js/src/sdk/models/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export class Entity {
redirectUrl?: string,
integrationId?: string,
connectionData?: Record<string, any>,
labels: string[] = []
): Promise<ConnectionRequest> {
try{
// Get the app details from the client
Expand Down Expand Up @@ -237,7 +238,8 @@ export class Entity {
userUuid: this.id,
redirectUri: redirectUrl,
//@ts-ignore
data: connectionData
data: connectionData,
labels: labels
});
}catch(error){
throw CEG.handleError(error);
Expand Down
3 changes: 2 additions & 1 deletion js/src/sdk/models/backendClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class BackendClient {
'X-API-KEY': `${this.apiKey}`,
'X-SOURCE': 'js_sdk',
'X-RUNTIME': this.runtime
}
},
throwOnError: true
});

}
Expand Down
25 changes: 19 additions & 6 deletions js/src/sdk/models/connectedAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import { BackendClient } from "./backendClient";
import { CEG } from "../utils/error";

type ConnectedAccountsListData = GetConnectionsData['query'] & {appNames?: string};

type InitiateConnectionDataReq = InitiateConnectionPayloadDto & {
data?: Record<string, unknown> | unknown;
userUuid?: string;
entityId?: string;
labels?: string[];
integrationId: string;
}

export class ConnectedAccounts {
backendClient: BackendClient;

Expand Down Expand Up @@ -59,13 +68,17 @@ export class ConnectedAccounts {
}
}

async initiate(data: InitiateConnectionData["body"] & { userUuid?: string; entityId?: string }): Promise<ConnectionRequest> {
async initiate(payload: InitiateConnectionDataReq): Promise<ConnectionRequest> {
try {
if (data.userUuid) {
data.entityId = data.userUuid;
}
const res = await client.connections.initiateConnection({ body: data }).then(res => res.data);
//@ts-ignore
const {integrationId, entityId = 'default', labels,data={}} = payload;

const res = await client.connections.initiateConnection({ body: {
integrationId,
entityId,
labels,
data,
} }).then(res => res.data);

return new ConnectionRequest(res?.connectionStatus!, res?.connectedAccountId!, res?.redirectUrl!)
} catch (error) {
throw CEG.handleError(error);
Expand Down
12 changes: 8 additions & 4 deletions js/src/sdk/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ERROR = {
UNKNOWN: "BACKEND::UNKNOWN"
},
COMMON: {
API_KEY_UNAVAILABLE: "COMMON::API_KEY_UNAVAILABLE",
API_KEY_UNAVAILABLE: "COMMON::API_KEY_INVALID",
UNKNOWN: "SDK::UNKNOWN"
}
}
Expand Down Expand Up @@ -65,6 +65,8 @@ class ComposioError extends Error {
this.possibleFix = possibleFix;

let detailedMessage = `Error Code: ${errCode}\nMessage: ${message}\n`;
let detailedDescription = description;

if (description) detailedMessage += `Description: ${description}\n`;
if (possibleFix) detailedMessage += `Suggested Fix: ${possibleFix}\n`;

Expand All @@ -73,6 +75,7 @@ class ComposioError extends Error {
Object.defineProperty(this, 'description', { enumerable: false });
Object.defineProperty(this, 'possibleFix', { enumerable: false });


this.stack = `${this.name}: ${detailedMessage}Stack Trace:\n${(new Error()).stack}`;
}
}
Expand Down Expand Up @@ -114,9 +117,10 @@ export class CEG {
}


const axiosDataMessage = axiosError.response?.data?.message || axiosError.message;


let axiosDataMessage = axiosError.response?.data?.message || axiosError.message;
const status = axiosError.response?.status || axiosError.status || axiosError.code || 'unknown';
const urlAndStatus = axiosError.config?.url ? `in (URL: ${axiosError.config.url}, Status: ${status})` : '';
axiosDataMessage = `${axiosDataMessage || errorDetails.description || "No additional information available."} ${urlAndStatus}`;
throw new ComposioError(
errorKey as string,
errorDetails.message,
Expand Down
Loading
Loading