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: new integration create and initaite connection + reinitiate and update API schema #1189

Merged
merged 17 commits into from
Jan 16, 2025

Conversation

himanshu-dixit
Copy link
Collaborator

@himanshu-dixit himanshu-dixit commented Jan 14, 2025

Important

This pull request enhances the SDK with new DTOs for error handling, introduces methods for managing integrations and connections, and updates models to support new API endpoints.

  • Behavior:
    • Add new DTOs for error handling in types.gen.ts.
    • Introduce new methods for managing integrations and connections in integrations.ts and connectedAccounts.ts.
    • Update existing models to support new API endpoints in index.ts and Entity.spec.ts.
  • Models:
    • Add ZReinitiateConnectionPayloadDto to connectedAccount.ts for reinitiating connections.
    • Add ZAuthMode to integration.ts for defining authentication modes.
  • Tests:
    • Add tests for new integration methods in integrations.spec.ts.
    • Add tests for connection handling in Entity.spec.ts.
  • Misc:
    • Update checkForLatestVersionFromNPM() in index.ts to log info instead of warning.

This description was created by Ellipsis for 3cd6021. It will automatically update as commits are pushed.

Copy link

vercel bot commented Jan 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 6:58am

Copy link

github-actions bot commented Jan 14, 2025

This comment was generated by github-actions[bot]!

JS SDK Coverage Report

📊 Coverage report for JS SDK can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-12803696833/coverage/index.html

📁 Test report folder can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-12803696833/html-report/report.html

@@ -14,7 +14,7 @@
"test:watch": "jest --testMatch=\"**/*.spec.ts\" --watch",
"test:coverage": "jest --coverage --testMatch=\"**/*.spec.ts\"",
"type-docs": "typedoc",
"openapispec:generate": "npx @hey-api/openapi-ts",
"openapispec:generate": "npx @hey-api/openapi-ts ",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The openapispec:generate script in package.json has a trailing space, which might cause issues with some tools or scripts.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
"openapispec:generate": "npx @hey-api/openapi-ts ",
"openapispec:generate": "npx @hey-api/openapi-ts"

Comment on lines +1484 to +1490
sortBy: {
enum: ["alphabet", "usage", "no_sort"],
type: "string",
description: "Sort the apps by usage or alphabetically",
example: "usage",
default: "alphabetically",
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for the "sortBy" property in AppQueryDTO is described as "alphabetically" but the example value is "usage". It would be better to align the default value with the example or vice versa.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
sortBy: {
enum: ["alphabet", "usage", "no_sort"],
type: "string",
description: "Sort the apps by usage or alphabetically",
example: "usage",
default: "alphabetically",
},
sortBy: {
enum: ["alphabet", "usage", "no_sort"],
type: "string",
description: "Sort the apps by usage or alphabetically",
example: "alphabet",
default: "alphabet",
},

Comment on lines 1052 to +1058
* Filter to include locally developed/testing apps in the response. Must be 'true' or 'false'
*/
includeLocal?: "true" | "false";
/**
* Sort the apps by usage or alphabetically
*/
sortBy?: "alphabet" | "usage" | "no_sort";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The includeLocal property in AppQueryDTO is defined as a string enum, but it should be a boolean to be consistent with its usage and description.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
* Filter to include locally developed/testing apps in the response. Must be 'true' or 'false'
*/
includeLocal?: "true" | "false";
/**
* Sort the apps by usage or alphabetically
*/
sortBy?: "alphabet" | "usage" | "no_sort";
/**
* Filter to include locally developed/testing apps in the response. Must be 'true' or 'false'
*/
includeLocal?: boolean;
/**
* Sort the apps by usage or alphabetically
*/
sortBy?: "alphabet" | "usage" | "no_sort";

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to c3fc6de in 1 minute and 42 seconds

More details
  • Looked at 5282 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. js/src/sdk/client/schemas.gen.ts:1970
  • Draft comment:
    The $GetConnectorListResDTO schema has an incorrect $ref for items. It should be an array of ConnectorListItemDTO.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
2. js/src/sdk/client/types.gen.ts:1706
  • Draft comment:
   status?: string;
  • Reason this comment was not posted:
    Marked as duplicate.
3. js/src/sdk/client/schemas.gen.ts:2385
  • Draft comment:
    Ensure the status field in $ConnectedAccountResponseDTO includes 'EXPIRED' as an option.
  • Reason this comment was not posted:
    Comment did not seem useful.
4. js/src/sdk/client/schemas.gen.ts:2543
  • Draft comment:
    Ensure the status field in $GetConnectionsQueryDto is a string to match the description of being a comma-separated list.
  • Reason this comment was not posted:
    Comment did not seem useful.

Workflow ID: wflow_lzBSaUSYj6aDtcLp


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

type: "string",
description: "Sort the apps by usage or alphabetically",
example: "usage",
default: "alphabetically",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an inconsistency in the sortBy field default value. The default is set to "alphabetically" but this value is not included in the enum which only allows ["alphabet", "usage", "no_sort"]. This could cause validation errors. Consider changing the default to "alphabet" to match the enum values.

},
logo: {
triggerType: {
enum: ["poll", "webhook"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The triggerType enum in TriggerLogItemDTO is missing documentation for its values. Consider adding descriptions for what "poll" and "webhook" trigger types mean and when they are used. This will help with API documentation and client understanding.

},
triggerClientResponse: {
type: "object",
description: "Payload sent by the client when the trigger was activated.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The triggerClientResponse and triggerClientPayload in TriggerLogItemDTO have the same description: "Payload sent by the client when the trigger was activated". This seems incorrect as they represent different things - one is the request payload and the other is the response. Please update the descriptions to accurately reflect their purposes.

type: "object",
},
type: "array",
description: "List of availavle versions of the action.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The available_versions field in ActionDetails has a typo in its description: "List of availavle versions of the action". Should be "available" instead of "availavle".

},
integration_id: {
type: "string",
description: "List of app unique keys to filter by",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integration_id field in AppFilterDTO has an incorrect description. It's currently using the same description as unique_key: "List of app unique keys to filter by". This should be updated to accurately describe what the integration_id field is used for.

@shreysingla11
Copy link
Collaborator

Code Review Summary

Overall Assessment

The code changes look generally good with some minor issues that need attention. The changes primarily focus on:

  • Adding new error types and improving error handling
  • Enhancing trigger and connection management
  • Adding sorting capabilities
  • Improving type definitions and documentation

Issues Found

  1. Validation Inconsistency: The sortBy field default value doesn't match its enum values (default: "alphabetically" vs enum: ["alphabet", "usage", "no_sort"])
  2. Documentation Issues:
    • Missing documentation for trigger types (poll/webhook)
    • Duplicate descriptions for triggerClientResponse and triggerClientPayload
    • Typo in available_versions description ("availavle")
    • Incorrect description for integration_id field in AppFilterDTO

Positive Aspects

  1. Strong typing throughout the codebase
  2. Comprehensive error handling with detailed error types
  3. Good API versioning support
  4. Clear parameter documentation for most fields

Suggestions for Improvement

  1. Fix the identified documentation issues
  2. Align enum values with default values
  3. Consider adding more descriptive error messages
  4. Add examples in documentation where appropriate

Code Quality Rating: 8/10

Good overall quality with attention to type safety and error handling, but needs minor documentation improvements and validation fixes.

Comment on lines 148 to 169
const connection = await apiClient.connectionsV2.initiateConnectionV2({
body: {
app: {
uniqueKey: payload.appName!,
integrationId: payload.integrationId,
},
config: {
name: payload.appName!,
useComposioAuth: !!payload.authMode && !!payload.authConfig,
authScheme: payload.authMode as z.infer<typeof ZAuthMode>,
integrationSecrets: payload.authConfig,
},
connection: {
entityId: payload.entityId,
initiateData: payload.connectionParams as Record<string, unknown>,
extra: {
redirectURL: payload.redirectUri,
labels: payload.labels || [],
},
},
},
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing validation for appName or integrationId can lead to runtime errors if both are absent. Add checks before API call. Non-null assertion on appName is unsafe; validate or provide a default to prevent runtime errors.

Comment on lines 161 to 162
entityId: payload.entityId,
initiateData: payload.connectionParams as Record<string, unknown>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct type casting of connectionParams may allow invalid data types, causing downstream issues. Validate before casting.

Comment on lines +163 to +171
extra: {
redirectURL: payload.redirectUri,
labels: payload.labels || [],
},
},
},
});

if (!isTestConnectorAvailable && app.no_auth === false) {
logger.debug(
"Auth schemes not provided, available auth schemes and authConfig"
);
// @ts-ignore
for (const authScheme of app.auth_schemes) {
logger.debug(
"authScheme:",
authScheme.name,
"\n",
"fields:",
authScheme.fields
);
}
const connectionResponse = connection?.data?.connectionResponse;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing error handling for missing 'integrationId' or 'appName' may cause issues if these are required.

Comment on lines 41 to 42

constructor(backendClient: BackendClient) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing 'integrations' and 'apps' properties may cause issues if they are used elsewhere in the code.

},
},
type: "object",
required: ["authScheme"],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing 'name' from required fields may cause issues if 'name' is expected elsewhere in the code.

},
labels: {
items: {
type: "string",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing 'labels' type from object to string may break functionality if the code expects an object.

"Details about the integration associated with this connection.",
},
connectionResponse: {
$ref: "#/components/schemas/ConnectionResponseV2",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing 'connectionResponse' from object to reference may cause issues if the reference is not defined correctly.

/**
* Name of the integration
*/
name?: string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing 'name' to optional may cause issues if 'name' is required elsewhere in the code.

/**
* Array of labels to associate with the connection for organization and filtering.
*/
labels?: Array<string>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing 'labels' from object to string array may break functionality if the code expects an object.

/**
* Response data containing connection details and status.
*/
connectionResponse: ConnectionResponseV2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing 'connectionResponse' from object to reference may cause issues if the reference is not defined correctly.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Incremental review on 2b99c9d in 1 minute and 48 seconds

More details
  • Looked at 354 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. js/src/sdk/models/connectedAccounts.ts:185
  • Draft comment:
    Typo in function name 'reiniateConnection'. It should be 'reinitiateConnection'.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_yS6wMhMsu7aJwzre


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

js/src/sdk/models/connectedAccounts.ts Outdated Show resolved Hide resolved
Comment on lines +13 to +14
sed -i '' '/export type in = '\''query'\'' | '\''header'\'';/d' src/sdk/client/types.gen.ts
sed -i '' 's/successfull: boolean/successfull?: boolean/g' src/sdk/client/types.gen.ts

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sed command lacks error handling, potentially failing silently on some platforms.

Comment on lines +2444 to +2447
* Whether the action execution was successfully executed or not. If this is false, error field will be populated with the error message.
* @deprecated
*/
appId: string;
successfull?: boolean;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from 'successfull: boolean' to 'successfull?: boolean' introduces a potential issue where the 'successfull' property might be undefined, leading to runtime errors if not handled properly.

Comment on lines 1363 to +1366
/**
* Array of connector items matching the query parameters. Each item contains detailed information about a connector and its associated connections.
*/
items: Array<{
[key: string]: unknown;
}>;
items: Array<ConnectorListItemDTO>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from 'items: ConnectorListItemDTO' to 'items: Array' may cause issues if the consuming code expects a single object instead of an array.

@@ -1,4 +1,4 @@
export const env = process.env.TEST_ENV || "prod"
export const env = process.env.TEST_ENV || "staging"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default environment changed from 'prod' to 'staging' which could affect production deployments if TEST_ENV is not explicitly set. This is a potentially risky change.

Comment on lines +28 to 31
const connection = await entity2.initiateConnection({
appName: "github",
});
expect(connection.connectionStatus).toBe("INITIATED");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent auth state due to mismatched requirements for authMode and authScheme. Align their requirements to prevent issues.

Comment on lines +130 to 132
logger.info(
`🚀 Upgrade available! Your composio-core version (${currentVersionFromPackageJson}) is behind. Latest version: ${latestVersion}.`
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching from console.warn() to logger.info() reduces visibility of upgrade notifications. Warning level is more appropriate for version upgrade messages to ensure they are noticed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on 3cd6021 in 24 seconds

More details
  • Looked at 16 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_sXd6i4UsXUUSuIWv


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 7fd7f3f in 1 minute and 36 seconds

More details
  • Looked at 5745 lines of code in 14 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. js/src/sdk/index.ts:129
  • Draft comment:
    The comment above this line mentions console.warn, but the code uses logger.info. Consider updating the comment for consistency.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The change in the checkForLatestVersionFromNPM method to use logger.info instead of console.warn is a good practice for consistent logging. However, the comment above the logger.info call still mentions console.warn, which can be misleading. It should be updated to reflect the actual logging method used.
2. js/src/sdk/models/connectedAccounts.ts:184
  • Draft comment:
    The reinitiateConnection method should return the ConnectionRequest object after creating it.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. js/src/sdk/models/integrations.ts:174
  • Draft comment:
    The getOrCreateIntegration method correctly uses apiClient.appConnectorV2.getOrCreateConnector, consistent with the introduction of V2 services.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The getOrCreateIntegration method in the Integrations class uses apiClient.appConnectorV2.getOrCreateConnector, which aligns with the new V2 service introduced in the PR. This method is consistent with the changes and correctly retrieves the app using apiClient.apps.getApps(). It also handles errors using CEG.handleAllError, which is consistent with the error handling strategy in the codebase.

Workflow ID: wflow_DQu2L2203QZq9aST


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@himanshu-dixit himanshu-dixit changed the title feat: integration list, reinitiate and update schema feat: new integration create and initaite connection + reinitiate and update API schema Jan 16, 2025
@himanshu-dixit himanshu-dixit merged commit 7791eaa into master Jan 16, 2025
16 of 17 checks passed
@himanshu-dixit himanshu-dixit deleted the ft-update-schema branch January 16, 2025 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants