-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Create new integration if integrationId not provided #890
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Changes requested. Reviewed everything up to c2ceb80 in 43 seconds
More details
- Looked at
117
lines of code in1
files - Skipped
0
files when reviewing. - Skipped posting
1
drafted comments based on config settings.
1. js/src/sdk/models/connectedAccounts.ts:4
- Draft comment:
Duplicate import ofclient
. Consider removing one of the import statements to avoid confusion. - Reason this comment was not posted:
Comment was on unchanged code.
Workflow ID: wflow_jArZWVgx8Gg80fTT
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.
|
||
if (!integrationId && authMode) { | ||
const timestamp = new Date().toISOString().replace(/[-:.]/g, ""); | ||
const app = await this.apps.get({ appKey: appName! }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using appName!
assumes appName
is always defined, which might not be the case. Consider adding a check to ensure appName
is not undefined
before using it.
const app = await this.apps.get({ appKey: appName! }); | |
const app = appName ? await this.apps.get({ appKey: appName }) : null; |
authConfig: authConfig, | ||
useComposioAuth: false, | ||
}); | ||
integrationId = integration!.id!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using integration!.id!
assumes integration
and integration.id
are always defined, which might not be the case. Consider adding a check to ensure integration
and integration.id
are not undefined
before using them.
integrationId = integration!.id!; | |
integrationId = integration?.id; |
redirectUri?: string; | ||
authMode?: string; | ||
authConfig?: { [key: string]: any }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The authConfig
type is using any
which could lead to runtime errors. Consider defining a proper interface for better type safety:
interface AuthConfig {
clientId?: string;
clientSecret?: string;
[key: string]: string | undefined;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not required here.
const timestamp = new Date().toISOString().replace(/[-:.]/g, ""); | ||
const app = await this.apps.get({ appKey: appName! }); | ||
const integration = await this.integrations.create({ | ||
appId: app.appId!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using non-null assertions (!
) on app.appId
and integration.id
could lead to runtime errors if these values are undefined. Consider adding proper validation:
if (!app?.appId) {
throw new Error(`App not found or invalid app ID for ${appName}`);
}
if (!integration?.id) {
throw new Error('Failed to create integration');
}
integrationId = integration.id;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added it in the next commit
data, | ||
} }).then(res => res.data); | ||
|
||
let { integrationId, entityId = 'default', labels, data = {}, redirectUri, authMode = '', authConfig = {}, appName } = payload; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initiate method should validate required parameters before proceeding. Consider adding input validation:
if (!integrationId && !appName) {
throw new Error('Either integrationId or appName must be provided');
}
if (!integrationId && !authMode) {
throw new Error('authMode is required when creating new integration');
}
|
||
let { integrationId, entityId = 'default', labels, data = {}, redirectUri, authMode = '', authConfig = {}, appName } = payload; | ||
|
||
if (!integrationId && authMode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the integration creation logic into a separate private method for better code organization and reusability:
private async createNewIntegration(
appName: string,
authMode: string,
authConfig: AuthConfig
): Promise<string> {
const timestamp = new Date().toISOString().replace(/[-:.]/g, "");
const app = await this.apps.get({ appKey: appName });
if (!app?.appId) {
throw new Error(`Invalid app: ${appName}`);
}
const integration = await this.integrations.create({
appId: app.appId,
name: `integration_${timestamp}`,
authScheme: authMode,
authConfig,
useComposioAuth: false,
});
return integration?.id ?? throw new Error('Failed to create integration');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required.
…com/ComposioHQ/composio into update-initiate-connection-function
Code Review SummaryOverall AssessmentThe changes introduce good functionality for dynamic integration creation, but there are several areas that need attention for better reliability and maintainability. Strengths✅ Good separation of concerns with proper class dependencies Areas for Improvement
Testing Requirements
The changes are generally good but implementing the suggested improvements would make the code more robust and maintainable. Rating: 7/10 - Good functionality but needs improvements in type safety and validation. |
This comment was generated by github-actions[bot]! JS SDK Coverage Report📊 Coverage report for JS SDK can be found at the following URL: 📁 Test report folder can be found at the following URL: |
Create new integration if integration ID is not provided is the
connectedAccounts.initiate
method.Important
Add logic to create a new integration in
ConnectedAccounts.initiate
ifintegrationId
is not provided.ConnectedAccounts.initiate
, create a new integration ifintegrationId
is not provided andauthMode
is specified.Apps.get
to retrieve app details andIntegrations.create
to create a new integration with a timestamped name.integrationId
inInitiateConnectionDataReq
is now optional.connectedAccounts.ts
.This description was created by for c2ceb80. It will automatically update as commits are pushed.