feat(website): add API wrapper for collections backend API#1081
feat(website): add API wrapper for collections backend API#1081
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
1d68c9d to
6ff08e9
Compare
6ff08e9 to
8ca09af
Compare
ae8ba83 to
9629cdd
Compare
8ca09af to
5a45f69
Compare
9e5ed16 to
db7b941
Compare
db7b941 to
9870dc4
Compare
There was a problem hiding this comment.
Pull request overview
Adds a generalized website-side API wrapper to support the new “collections” backend endpoints while consolidating existing subscriptions backend API plumbing at website/src/backendApi and introducing a shared /api/* proxy that injects userId from the authenticated session.
Changes:
- Introduces
BackendServicecollections endpoints +Collectionzod schemas. - Replaces the subscriptions-specific proxy with a shared
proxyToBackendused by both subscriptions and collections routes. - Removes explicit
userIdplumbing in subscriptions UI and client API calls (now derived in the proxy).
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| website/src/util/getErrorLogMessage.ts | Updates import path after backend API relocation. |
| website/src/types/Collection.ts | Adds zod schemas/types for collections + request/update payloads. |
| website/src/pages/subscriptions/index.astro | Drops userId prop wiring into client component. |
| website/src/pages/subscriptions/create.astro | Drops userId prop wiring into client component. |
| website/src/pages/api/subscriptions/[...path].ts | Switches to shared proxyToBackend. |
| website/src/pages/api/collections/[...path].ts | Adds collections API route using shared proxyToBackend. |
| website/src/pages/api/backendProxy.ts | New shared backend proxy that appends userId from session. |
| website/src/layouts/OrganismPage/DataPageLayout.tsx | Updates withQueryProvider import location. |
| website/src/components/views/wasap/WasapPage.tsx | Updates withQueryProvider import location. |
| website/src/components/views/sequencingEfforts/CountStatistics.tsx | Updates withQueryProvider import location. |
| website/src/components/subscriptions/overview/Subscriptions.tsx | Removes userId prop usage; updates query/service calls to new API location. |
| website/src/components/subscriptions/overview/SubscriptionEntry.tsx | Removes userId usage for delete; updates API import location. |
| website/src/components/subscriptions/create/SubscriptionsCreate.tsx | Removes userId usage for create; updates API import location. |
| website/src/components/pageStateSelectors/DynamicDateFilter.browser.spec.tsx | Updates withQueryProvider import location for tests. |
| website/src/backendApi/withQueryProvider.tsx | New shared React Query provider HOC. |
| website/src/backendApi/querySubscriptions.ts | Drops userId parameter; uses session-proxied backend API. |
| website/src/backendApi/backendService.ts | Moves/extends backend API client; adds collections endpoints; removes userId params. |
| website/src/backendApi/backendService.spec.ts | Updates tests to align with removal of userId in client calls. |
| website/routeMocker.ts | Updates backend route mock helpers to match new request shapes (no userId). |
Comments suppressed due to low confidence (3)
website/src/backendApi/backendService.ts:166
- The
deleteSubscriptionresponse schema usesz.literal('').refine((input): input is never => true), which makes the parsed return typenevereven though the method resolves with an empty string at runtime. This is misleading for callers and can break type-driven control flow. Prefer returningvoid(transform the schema toundefined) or keep the output type asstringwithout narrowing tonever.
website/src/backendApi/backendService.ts:198 - Same issue as
deleteSubscription: the schemaz.literal('').refine((input): input is never => true)narrows the return type toneverwhile the request resolves normally. Consider returningvoid(schema transform) or keep the schema output type asstringto avoid misleading typing fordeleteCollection.
website/src/backendApi/backendService.ts:199 BackendServiceadds new collections endpoints (getCollections,getCollection,postCollection,putCollection,deleteCollection) but there are no corresponding tests inbackendService.spec.ts. Since this file already has request/response contract tests for subscriptions, adding similar tests for the collections methods would help catch regressions (URL, params, and schema parsing).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
userId is injected by the backend proxy from the session, so there is no need to pass it from the client. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The userId is added by the backend proxy, so callers don't need to supply it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- MutationListDefinition -> FilterObject - mutationList discriminator -> filterObject - mutationList field -> filterObject on variant objects - aaMutations/nucMutations/aaInsertions/nucInsertions -> spelled-out names - filters sub-object removed; arbitrary filter props now top-level via catchall Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces [...path].ts with index.ts (GET+POST) and [id].ts (GET+PUT+DELETE), making auth requirements per endpoint explicit. Also adds proxyToBackendOptionalAuth to backendProxy.ts to support endpoints where auth is optional. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests cover fetching all collections and filtering by organism query param. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3e567d5 to
e951f78
Compare
…ection GETs Forwarding userId on read requests caused the backend to filter collections by owner. Collection reads are always public, so no auth context is needed. Removes proxyToBackendOptionalAuth entirely. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 20 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (3)
website/src/backendApi/backendService.spec.ts:188
- Collections support adds additional
BackendServicemethods (getCollection,postCollection,putCollection,deleteCollection), but the tests added here only covergetCollections. Adding unit tests for the remaining new methods would help catch request/response-shape regressions as the API evolves.
website/src/backendApi/backendService.ts:165 - This delete endpoint uses
z.literal('').refine((input): input is never => true). The type predicate forces the Zod output type tonever, sodeleteSubscriptionis typed as returningPromise<never>even though at runtime it returns the empty string. Use a schema whose output type matches the intended return (e.g.,z.literal('')), or transform tovoid/undefinedif the API returns 204/empty bodies.
website/src/backendApi/backendService.ts:198 - Same issue as
deleteSubscription:z.literal('').refine((input): input is never => true)makes the Zod output typeneverwhile runtime returns''. Preferz.literal('')(returning'') or a transform tovoid/undefinedfor empty-body deletes, so the method return type is usable.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This is part of #938
Summary
backendApidir out of thesubscriptions, into the top level where the other API stuff is also located (lapis,covspectrum).proxyToBackendfunction for subscriptions and collections APIuserIdeverywhere, because it's already added later on in the backend proxyPR Checklist