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
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>
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.
There was a problem hiding this comment.
Astro didn't create a proper route for this (or at least I didn't find one), but let's still move this out of pages/?
| }); | ||
|
|
||
| const mutationListVariantSchema = z.object({ | ||
| type: z.literal('mutationList'), |
There was a problem hiding this comment.
| type: z.literal('mutationList'), | |
| type: z.literal('filterObject'), |
... etc. :)
| if (session?.user?.id === undefined) { | ||
| return getUnauthorizedResponse(request.url); | ||
| } |
There was a problem hiding this comment.
This makes the login required for every route, but the collections have public routes. We probably need to exclude some from this check?
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
The implemented feature is covered by an appropriate test.(We're not testing these functions)