feat: enrich connectors response with social profile data#406
feat: enrich connectors response with social profile data#406recoup-coding-agent wants to merge 1 commit intotestfrom
Conversation
GET /api/connectors now returns avatar and username for connected Instagram/TikTok connectors by looking up matching social profiles from the artist's account_socials in Supabase. - Add avatar/username to ConnectorInfo interface - New enrichConnectorsWithSocials function with hostname-based matching - Handler calls enrichment after fetching Composio connectors - Tests for enrichment logic Co-Authored-By: Paperclip <noreply@paperclip.ing>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
3 issues found across 4 files
Confidence score: 2/5
- There is a high-confidence functional risk in
lib/composio/connectors/enrichConnectorsWithSocials.ts:new URL(profileUrl)can throw for protocol-less normalized URLs, which can cause valid Instagram/TikTok matches to be missed. lib/composio/connectors/getConnectorsHandler.tscurrently risks turning/api/connectorsinto a 500 when enrichment fails, even if connector retrieval succeeded, which is user-facing reliability impact.- The typing issue in
lib/composio/connectors/enrichConnectorsWithSocials.ts(anyin social mapping) increases maintenance and correctness risk, especially alongside the parsing bug in the same flow. - Pay close attention to
lib/composio/connectors/enrichConnectorsWithSocials.tsandlib/composio/connectors/getConnectorsHandler.ts- URL parsing and error-handling paths can cause missed social enrichment and endpoint failures.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/composio/connectors/enrichConnectorsWithSocials.ts">
<violation number="1" location="lib/composio/connectors/enrichConnectorsWithSocials.ts:23">
P1: `new URL(profileUrl)` fails for normalized profile URLs stored without protocol, causing social matching to miss valid Instagram/TikTok records.</violation>
<violation number="2" location="lib/composio/connectors/enrichConnectorsWithSocials.ts:48">
P1: Custom agent: **Enforce Clear Code Style and Maintainability Practices**
Rule 1 (strict TypeScript typing) is violated by using `any` in the social mapping; use the typed `social` field directly instead of bypassing type checks.</violation>
</file>
<file name="lib/composio/connectors/getConnectorsHandler.ts">
<violation number="1" location="lib/composio/connectors/getConnectorsHandler.ts:49">
P2: Handle enrichment failures gracefully so social-profile lookup errors don’t turn `/api/connectors` into a 500 when connector data was fetched successfully.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Client
participant Handler as getConnectorsHandler
participant Composio as getConnectors
participant Enricher as enrichConnectorsWithSocials
participant DB as Supabase (account_socials)
Client->>Handler: GET /api/connectors?account_id={id}
Handler->>Handler: validateGetConnectorsRequest()
Handler->>Composio: getConnectors({ accountId })
Note right of Composio: Fetch connection status for<br/>Google, TikTok, Instagram
Composio-->>Handler: ConnectorInfo[] (slug, name, isConnected)
rect rgb(240, 248, 255)
Note over Handler,DB: NEW: Enrichment Flow
Handler->>Enricher: enrichConnectorsWithSocials(connectors, accountId)
Enricher->>DB: selectAccountSocials(accountId)
DB-->>Enricher: Social profile data (url, username, avatar)
loop For each Connector
alt connector.isConnected AND slug in [instagram, tiktok]
Enricher->>Enricher: Match social.profile_url hostname to slug
opt Hostname matches
Enricher->>Enricher: CHANGED: Attach avatar and username
end
else connector is not connected OR slug is Google/Other
Enricher->>Enricher: Skip enrichment
end
end
Enricher-->>Handler: Enriched ConnectorInfo[]
end
Handler-->>Client: 200 OK (JSON with avatar/username fields)
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| ): Promise<ConnectorInfo[]> { | ||
| const accountSocials = await selectAccountSocials(accountId); | ||
| const socials: SocialRow[] = (accountSocials || []) | ||
| .map((item) => (item as any).social as SocialRow | null) |
There was a problem hiding this comment.
P1: Custom agent: Enforce Clear Code Style and Maintainability Practices
Rule 1 (strict TypeScript typing) is violated by using any in the social mapping; use the typed social field directly instead of bypassing type checks.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/composio/connectors/enrichConnectorsWithSocials.ts, line 48:
<comment>Rule 1 (strict TypeScript typing) is violated by using `any` in the social mapping; use the typed `social` field directly instead of bypassing type checks.</comment>
<file context>
@@ -0,0 +1,69 @@
+): Promise<ConnectorInfo[]> {
+ const accountSocials = await selectAccountSocials(accountId);
+ const socials: SocialRow[] = (accountSocials || [])
+ .map((item) => (item as any).social as SocialRow | null)
+ .filter((s): s is SocialRow => s !== null);
+
</file context>
| expectedHostname: string, | ||
| ): boolean { | ||
| try { | ||
| const hostname = new URL(profileUrl).hostname.toLowerCase(); |
There was a problem hiding this comment.
P1: new URL(profileUrl) fails for normalized profile URLs stored without protocol, causing social matching to miss valid Instagram/TikTok records.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/composio/connectors/enrichConnectorsWithSocials.ts, line 23:
<comment>`new URL(profileUrl)` fails for normalized profile URLs stored without protocol, causing social matching to miss valid Instagram/TikTok records.</comment>
<file context>
@@ -0,0 +1,69 @@
+ expectedHostname: string,
+): boolean {
+ try {
+ const hostname = new URL(profileUrl).hostname.toLowerCase();
+ return (
+ hostname === expectedHostname || hostname.endsWith(`.${expectedHostname}`)
</file context>
| }); | ||
|
|
||
| // Enrich with social profile data (avatar, username) | ||
| const enriched = await enrichConnectorsWithSocials(connectors, accountId); |
There was a problem hiding this comment.
P2: Handle enrichment failures gracefully so social-profile lookup errors don’t turn /api/connectors into a 500 when connector data was fetched successfully.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/composio/connectors/getConnectorsHandler.ts, line 49:
<comment>Handle enrichment failures gracefully so social-profile lookup errors don’t turn `/api/connectors` into a 500 when connector data was fetched successfully.</comment>
<file context>
@@ -40,15 +45,19 @@ export async function getConnectorsHandler(request: NextRequest): Promise<NextRe
});
+ // Enrich with social profile data (avatar, username)
+ const enriched = await enrichConnectorsWithSocials(connectors, accountId);
+
return NextResponse.json(
</file context>
| const enriched = await enrichConnectorsWithSocials(connectors, accountId); | |
| const enriched = await enrichConnectorsWithSocials(connectors, accountId).catch( | |
| () => connectors, | |
| ); |
Summary
Changes
Test plan
Generated with Claude Code
Summary by cubic
GET
/api/connectorsnow includes avatar and username for connected Instagram and TikTok connectors whenaccount_idis provided, using Supabase social profiles. Other connectors and unconnected items are unchanged.account_socialsand matched by hostname (instagram.com,tiktok.com).avatarandusernametoConnectorInfo; newenrichConnectorsWithSocials; handler enriches after Composio fetch.Written for commit ae33d59. Summary will update on new commits.