Skip to content

fix(search): normalize bare-array response from POST /search#650

Open
kevinheneveld wants to merge 1 commit into
Listenarrs:canaryfrom
kevinheneveld:fix/search-bare-array-normalize
Open

fix(search): normalize bare-array response from POST /search#650
kevinheneveld wants to merge 1 commit into
Listenarrs:canaryfrom
kevinheneveld:fix/search-bare-array-normalize

Conversation

@kevinheneveld

Copy link
Copy Markdown
Contributor

Summary

searchAudibleByTitleAndAuthor silently dropped every result when the search endpoint returned a bare array. The unified POST /search endpoint returns a flat array of Audible-shaped result objects (SearchController does return Ok(flatMapped)), but the FE service method typed the response as the wrapped { totalResults, results } envelope and read .results off it. When the array shape arrived it had no .results, so the method returned zero hits and callers saw "no matches" even though IntelligentSearch had actually found one. The method now normalizes both response shapes.

Why this matters

Any feature that searches Audible by title + author is affected — the call can find a match server-side and the UI still reports nothing. It's shape-dependent, so it surfaces inconsistently and is easy to misread as "Audible just didn't have it."

Implementation notes

  • Surface: fe/src/services/api.tssearchAudibleByTitleAndAuthor only.
  • Normalization:
    • bare array → { totalResults: resp.length, results: resp }
    • wrapped { totalResults, results } envelope → returned as-is
    • null / undefined → empty envelope ({ totalResults: 0, results: [] })
  • No change to the endpoint or to callers; purely makes the client tolerant of both shapes the API can return.

Test plan

  • npx vitest run src/__tests__/api.advancedSearch.spec.ts — 5/5 passing (new; covers array, wrapped, and null cases).
  • npm run type-check — clean.
  • Full FE unit suite — 367 passing / 1 skipped, no regressions.

The unified search endpoint returns a flat array of Audible-shaped results
(see SearchController.cs: `return Ok(flatMapped)`), but the FE service method
`searchAudibleByTitleAndAuthor` typed the response as the wrapped
`{ totalResults, results }` envelope. When the array shape arrived the
method treated it as an object without `.results` and silently dropped
every hit — callers saw "no matches" even when IntelligentSearch had
actually found one.

Normalize both shapes:

  - Bare array → `{ totalResults: resp.length, results: resp }`
  - Wrapped envelope → returned as-is
  - null / undefined → empty envelope

Three tests cover the array, wrapped, and null cases.

This is the latent bug the metadata-backfill modal in the next commit
exposes most aggressively (every search is title+author), but the issue
affects any current or future caller of `searchAudibleByTitleAndAuthor`.
@kevinheneveld kevinheneveld marked this pull request as ready for review June 4, 2026 21:38
@kevinheneveld kevinheneveld requested a review from a team June 4, 2026 21:38
@therobbiedavis therobbiedavis self-assigned this Jun 8, 2026
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.

2 participants