Skip to content

feat(website): add API wrapper for collections backend API#1081

Open
fhennig wants to merge 9 commits intomainfrom
generalized-collections-frontend-api
Open

feat(website): add API wrapper for collections backend API#1081
fhennig wants to merge 9 commits intomainfrom
generalized-collections-frontend-api

Conversation

@fhennig
Copy link
Contributor

@fhennig fhennig commented Mar 17, 2026

This is part of #938

Summary

  • move existing backendApi dir out of the subscriptions, into the top level where the other API stuff is also located (lapis, covspectrum).
  • Add new types and functions for the backend API
  • Use a common proxyToBackend function for subscriptions and collections API
  • drop userId everywhere, because it's already added later on in the backend proxy

PR Checklist

  • All necessary documentation has been adapted.
  • The implemented feature is covered by an appropriate test. (We're not testing these functions)

@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboards Ready Ready Preview, Comment Mar 19, 2026 3:29pm

Request Review

@fhennig fhennig self-assigned this Mar 17, 2026
@fhennig fhennig changed the title Generalized collections frontend api feat(website): add API wrapper for collections backend API Mar 17, 2026
@fhennig fhennig force-pushed the generalized-collections-frontend-api branch from 1d68c9d to 6ff08e9 Compare March 17, 2026 14:55
@fhennig fhennig marked this pull request as ready for review March 17, 2026 14:55
@fhennig fhennig force-pushed the generalized-collections-frontend-api branch from 6ff08e9 to 8ca09af Compare March 17, 2026 15:04
@fhennig fhennig force-pushed the generalized-collections-pt1 branch from ae8ba83 to 9629cdd Compare March 18, 2026 10:58
@fhennig fhennig force-pushed the generalized-collections-frontend-api branch from 8ca09af to 5a45f69 Compare March 18, 2026 10:59
@fhennig fhennig force-pushed the generalized-collections-frontend-api branch from 9e5ed16 to db7b941 Compare March 18, 2026 14:11
Base automatically changed from generalized-collections-pt1 to main March 19, 2026 14:50
fhennig and others added 9 commits March 19, 2026 16:28
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>
@fhennig fhennig force-pushed the generalized-collections-frontend-api branch from db7b941 to 9870dc4 Compare March 19, 2026 15:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BackendService collections endpoints + Collection zod schemas.
  • Replaces the subscriptions-specific proxy with a shared proxyToBackend used by both subscriptions and collections routes.
  • Removes explicit userId plumbing 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 deleteSubscription response schema uses z.literal('').refine((input): input is never => true), which makes the parsed return type never even though the method resolves with an empty string at runtime. This is misleading for callers and can break type-driven control flow. Prefer returning void (transform the schema to undefined) or keep the output type as string without narrowing to never.
    website/src/backendApi/backendService.ts:198
  • Same issue as deleteSubscription: the schema z.literal('').refine((input): input is never => true) narrows the return type to never while the request resolves normally. Consider returning void (schema transform) or keep the schema output type as string to avoid misleading typing for deleteCollection.
    website/src/backendApi/backendService.ts:199
  • BackendService adds new collections endpoints (getCollections, getCollection, postCollection, putCollection, deleteCollection) but there are no corresponding tests in backendService.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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type: z.literal('mutationList'),
type: z.literal('filterObject'),

... etc. :)

Comment on lines +20 to +22
if (session?.user?.id === undefined) {
return getUnauthorizedResponse(request.url);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the login required for every route, but the collections have public routes. We probably need to exclude some from this check?

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.

3 participants