feat: cut getArtistSocials tasks helper over to /api/artists/{id}/socials with x-api-key#143
Conversation
…ials with x-api-key - Build URL from NEW_API_BASE_URL + nested path id (drop artist_account_id query param) - Send x-api-key: RECOUP_API_KEY header per mono/api auth retrofit - Guard on missing RECOUP_API_KEY same as createAccountSandbox template - Zod schema, error handling, exported types unchanged
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/recoup/getArtistSocials.ts (1)
49-49: EncodeartistAccountIdas a URL path segment.
artistAccountIdis interpolated directly into the path. Any unexpected character (e.g.,/,?,#, whitespace) would alter routing or silently break the request. The sibling helpergetAccountSandboxesalready wraps its id withencodeURIComponent; apply the same here for consistency and defense-in-depth.🛡️ Proposed fix
- const url = `${NEW_API_BASE_URL}/api/artists/${artistAccountId}/socials`; + const url = `${NEW_API_BASE_URL}/api/artists/${encodeURIComponent( + artistAccountId + )}/socials`;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/recoup/getArtistSocials.ts` at line 49, The URL path is built by interpolating artistAccountId directly into NEW_API_BASE_URL in getArtistSocials, which can break routing for characters like /, ?, # or spaces; update the construction of url in getArtistSocials to wrap artistAccountId with encodeURIComponent (same approach as getAccountSandboxes) so the artistAccountId is safely encoded as a path segment before concatenation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/recoup/getArtistSocials.ts`:
- Line 49: The URL path is built by interpolating artistAccountId directly into
NEW_API_BASE_URL in getArtistSocials, which can break routing for characters
like /, ?, # or spaces; update the construction of url in getArtistSocials to
wrap artistAccountId with encodeURIComponent (same approach as
getAccountSandboxes) so the artistAccountId is safely encoded as a path segment
before concatenation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 44883bb5-d8ff-444b-880c-2b925f0cbb42
📒 Files selected for processing (1)
src/recoup/getArtistSocials.ts
There was a problem hiding this comment.
1 issue found across 1 file
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="src/recoup/getArtistSocials.ts">
<violation number="1" location="src/recoup/getArtistSocials.ts:49">
P2: Wrap `artistAccountId` in `encodeURIComponent()` to safely embed it as a path segment. The previous query-param approach auto-encoded the value; the new template literal does not, so any ID containing `/`, `?`, or `#` would break the URL.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| try { | ||
| const url = new URL(ARTIST_SOCIALS_API_URL); | ||
| url.searchParams.set("artist_account_id", artistAccountId); | ||
| const url = `${NEW_API_BASE_URL}/api/artists/${artistAccountId}/socials`; |
There was a problem hiding this comment.
P2: Wrap artistAccountId in encodeURIComponent() to safely embed it as a path segment. The previous query-param approach auto-encoded the value; the new template literal does not, so any ID containing /, ?, or # would break the URL.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/recoup/getArtistSocials.ts, line 49:
<comment>Wrap `artistAccountId` in `encodeURIComponent()` to safely embed it as a path segment. The previous query-param approach auto-encoded the value; the new template literal does not, so any ID containing `/`, `?`, or `#` would break the URL.</comment>
<file context>
@@ -41,14 +40,19 @@ export async function getArtistSocials(
try {
- const url = new URL(ARTIST_SOCIALS_API_URL);
- url.searchParams.set("artist_account_id", artistAccountId);
+ const url = `${NEW_API_BASE_URL}/api/artists/${artistAccountId}/socials`;
- const response = await fetch(url.toString(), {
</file context>
| const url = `${NEW_API_BASE_URL}/api/artists/${artistAccountId}/socials`; | |
| const url = `${NEW_API_BASE_URL}/api/artists/${encodeURIComponent(artistAccountId)}/socials`; |
Summary
Migrate the
getArtistSocialstasks helper to the new RESTful nested pathGET /api/artists/{id}/socialsonrecoup-api.vercel.app, and add the requiredx-api-keyauth header.NEW_API_BASE_URL(already exported insrc/consts.ts) withidas path segment; drop theartist_account_idquery param.x-api-key: RECOUP_API_KEYheader (template:src/recoup/createAccountSandbox.ts). Guard missing key by logging + returningundefined(same failure mode as siblings).ARTIST_SOCIALS_API_URLconstant — URL now built inline likecreateAccountSandbox.ArtistSocialProfile/getArtistSocialstypes unchanged. Downstream consumers (getBatchArtistSocials,filterScrapableSocials,isScrapableSocial) require no edits.Draft until the api-side PR adding
app/api/artists/[id]/socials/route.tswith auth lands and deploys to production.Test plan
npx tsc --noEmitclean onsrc/recoup/getArtistSocials.tspnpm test165/165 passapi.recoupable.com/api/artist/socialsstatus: "success"with populatedsocials[]Summary by cubic
Switch
getArtistSocialsto the nested endpointGET /api/artists/{id}/socialsand addx-api-keyauth to align with the new API.NEW_API_BASE_URLwithidin the path; remove theartist_account_idquery param.x-api-keyfromRECOUP_API_KEY; if missing, log and returnundefined.ARTIST_SOCIALS_API_URLconstant; Zod schema, types, and downstream consumers remain unchanged.Written for commit e6e7daa. Summary will update on new commits.
Summary by CodeRabbit