feat(search-artist-links): implement Spotify adapter - #339
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…rmalization Adds a complete Spotify artist search implementation for the search-artist-links edge function. Includes Spotify Client Credentials auth, API search integration, and normalization to the shared Candidate type. Implements per-artist error handling to keep partial results when one artist search fails. Added files: - supabase/functions/_shared/spotify-api/auth.ts: Token caching and auth - supabase/functions/_shared/spotify-api/schemas.ts: Spotify API response types Modified files: - spotify-adapter.ts: Real implementation replacing stub - normalize.ts: normalizeSpotifySearchResult function - normalize.test.ts: Unit tests for normalization with 0-followers preservation Closes #336
38c015e to
10122d4
Compare
|
Deploy →
|
There was a problem hiding this comment.
Pull request overview
Implements the Spotify provider for the search-artist-links Supabase Edge Function by adding Spotify Client Credentials auth, Spotify search response validation, and normalization into the shared Candidate shape used by the link wizard flow.
Changes:
- Add a Spotify Client Credentials token helper with in-memory caching.
- Implement
searchSpotifyto query Spotify’s artist search API and return up to 3 normalized candidates per artist (per-artist failures are isolated). - Add Spotify Zod schemas plus unit tests for
normalizeSpotifySearchResult.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| supabase/functions/search-artist-links/spotify-adapter.ts | Implements the Spotify provider search flow (token fetch + per-artist search + normalization). |
| supabase/functions/search-artist-links/normalize.ts | Adds normalizeSpotifySearchResult to map Spotify artists into the shared Candidate shape. |
| supabase/functions/search-artist-links/normalize.test.ts | Adds unit tests covering Spotify normalization edge cases (missing images/genres/followers, followers=0). |
| supabase/functions/_shared/spotify-api/schemas.ts | Introduces Zod schemas/types for Spotify artists and search responses. |
| supabase/functions/_shared/spotify-api/auth.ts | Adds Spotify Client Credentials token acquisition with caching. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Playwright test resultsDetails
|
…g leak Moves credential lookup into getSpotifyAccessToken so missing config throws (matching SoundCloud) instead of silently returning empty candidates. Fixes expires_in falsy-zero bug and redacts access_token from error logs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
supabase/functions/_shared/spotify-api/schemas.ts:30
- This schema accepts
{}or{ artists: {} }as a valid Spotify response, so an incomplete/malformed 200 response is silently reported as a legitimate zero-result search instead of the per-artist error handled by the adapter. Spotify search responses require bothartistsanditems; keep those containers required while leaving genuinely nullable artist fields optional.
export const SpotifySearchResponseSchema = z.object({
artists: z
.object({
items: z.array(SpotifyArtistSchema).optional(),
})
.optional(),
Adds a complete Spotify artist search implementation with Client Credentials auth, API search, and normalization.
Search failures for individual artists don't affect results for other artists.
Verification
Preconditions: Set Supabase secrets
SPOTIFY_CLIENT_IDandSPOTIFY_CLIENT_SECRETin the edge function environment./search-artist-linkswithprovider: "spotify"and multiple artist names; verify all artists return up to 3 candidates each.{ name, url, imageUrl, followers, genres }.imageUrl: null.Stacked on #337.
Closes #336
Generated by Claude Code