Skip to content

Goal: Amazon Import — Free-Text Search BFF Route

Lifecycle: Completed

Extend the Next.js BFF route surface in arda-frontend-app so that the Amazon import flow accepts free-text keyword queries via the Amazon Creators SearchItems endpoint, in addition to the URL and bare-ASIN inputs the existing /api/amazon/import route already handles. The deliverable is purely the server-side API. The frontend “Add from Amazon” UI is not in scope for this project — UI integration of the new route is tracked separately under PDEV-477, which is blocked by PDEV-457.

The detailed request/response contract, input processing, error codes, Amazon Creators API surface, and zero-result augmentation strategy are documented in spec-analysis.md. Background analysis for the augmentation strategy lives in query-relaxation-exploration.md.

RepositoryRolePlanned Changes
arda-frontend-appBFF route + supporting server-side client wrapper + MSW mocks + testsNew BFF route exposing keyword product search; a wrapper on the existing Creators API client; MSW handlers for all server-exercised paths; route and client tests.
documentationProject docsgoal.md, spec-analysis.md, query-relaxation-exploration.md.

UI consumption of the new route is out of scope; no changes to React components, pages, hooks, or the ux-prototype design system.

  1. The BFF can accept a flexible free-text product search and return a list of matching Amazon products using the same per-item DTO shape as the existing import route. The contract has no pagination. On a zero-result primary call, the server performs a bounded, deterministic Amazon-side relaxation (always on, no caller opt-in) before returning an empty list. Richer zero-result strategies (LLM-generated suggestions, external web-search fallbacks) are explicitly out of scope and tracked separately under PDEV-569.
  2. POST /api/amazon/import accepts a broader set of URL/ASIN input shapes via the new shared normalisation layer (schemeless URLs, path-only inputs, lowercase ASINs, extended US sub-hosts, old-form product paths, and plain text containing exactly one ASIN) — but its response contract is preserved verbatim: same DTO shape, same error codes, same HTTP statuses, and free text without an unambiguous ASIN still returns UNRECOGNIZED_AMAZON_URL. No silent re-routing of free text to keyword search.
  3. Invalid request input is rejected with a clear error. Amazon-side failures (network, throttling, 5xx) surface as a distinct error. Zero matching items is a successful empty response, not an error.
  4. No new external dependencies, server secrets, environment variables, or operations-backend changes. Existing Amazon Creators API credentials, marketplace, and rate-limit pool are reused.
  5. All server-exercised paths are covered by MSW mocks and by route and client tests. No live Amazon calls run in CI.
  6. Standard PR gates (npm run build, lint, typecheck, tests) pass locally before PR; PR-body ## CHANGELOG entry filed in the arda-frontend-app PR.

The Amazon import flow currently accepts only Amazon product URLs and bare ASINs via POST /api/amazon/import (introduced under PDEV-446). This project extends the BFF surface so it can also accept free-text product queries against the Amazon Creators API, using the existing OAuth2 credentials and rate-limit pool.

  • A BFF route exposing keyword product search.
  • A supporting wrapper on the existing Amazon Creators API client.
  • A shared URL/ASIN input normalisation layer (extractAsin strict + extractAsinLenient permissive) that broadens the set of accepted URL/ASIN shapes for both routes. /api/amazon/import switches to the lenient extractor (accepting schemeless URLs, path-only inputs, lowercase ASINs, extended US sub-hosts, old-form product paths, and plain text containing exactly one ASIN). /api/amazon/search’s ASIN-shortcut dispatcher uses the strict extractor so keyword queries that happen to contain an ASIN are still treated as searches.
  • MSW handlers covering every server-exercised path.
  • Route and client tests for the new surface.
  • Observability parity with recent Sentry conventions (user spans, external-call timing for Amazon API calls, error capture). The implementation plan audits the workspace’s current Sentry integration patterns and applies them to the new search route. If the audit shows that /api/amazon/import falls short of the same conventions, this project also retrofits the necessary observability probes onto the import route so the two routes match.
  • PR-body ## CHANGELOG entry in arda-frontend-app.
  • Any UI/UX change — React components, pages, hooks, ux-prototype consumers, frontend input parsing, Storybook stories beyond what is needed to keep existing stories green.
  • Multiple-result picker UI / result list rendering.
  • Search suggestions, autocomplete, or debounce semantics in any input.
  • Operations-backend changes; no API contract negotiated with operations.
  • Affiliate-link rewriting strategy changes beyond reusing the existing helper.
  1. API-only deliverable. Frontend integration of any new route is explicitly deferred. This project may not modify React components, pages, or Storybook stories beyond keeping existing tests green.
  2. Existing URL and bare-ASIN happy paths through /api/amazon/import continue to return the current response shape and status codes for their existing inputs.
  3. Short-link and non-US-locale URLs continue to surface their existing, specific error codes — never silently re-routed to search.
  4. Reuse the existing Amazon Creators API client and OAuth2 credentials; do not introduce a separate client or new server env vars.

Copyright: (c) Arda Systems 2025-2026, All rights reserved