Repository navigation
Generalize receipt storage and let a draft be discarded - #29
Conversation
The web read EXT_BY_MEDIA_TYPE and SUPPORTED_IMAGE_MIME_TYPES through `@repo/api/constants`, coupling the frontend to the backend just to know which MIME types the receipt upload accepts. Move them to `@repo/shared-types`, which both apps already depend on, and drop the api's `./constants` entry point along with its barrel file.
fake-gcs-server creates buckets from the layout under /data on startup, so mounting `.dev/gcs` gives the dev stack the `snapsplit-receipts` bucket without the app having to create it on first use.
`ReceiptStorage` mixed three concerns: talking to GCS, minting the file id from the media type, and creating the bucket on demand when running against the emulator. That made the interface untestable in isolation and tied every caller to receipts. Split them apart: - `ObjectStorage` now takes the key explicitly, so it knows nothing about receipts. `GcsObjectStorage` receives its prefix, bucket and endpoint through the constructor instead of reading `Bun.env` on the spot. - `createReceiptStorage(env)` in `storage/index.ts` wires the receipts bucket and is the only place that touches the environment. - The receipt-specific rules — how a file id is minted and how it maps to the public `/receipts/:fileId` path — move to `modules/receipt/service.ts` and are now covered by unit tests. - `ensureBucket()` is gone: the dev bucket is seeded from `.dev/gcs`, and in production the bucket is provisioned by infra. `createReceiptModule(storage)` mirrors `createSessionModule` so the route can be exercised with a fake storage.
`DELETE /sessions/:sessionId` lets the payer discard a session — a draft they no longer want, or a settled bill. Only the owner may call it, so the route reuses the `owner: true` guard from the auth plugin and answers 204 with an empty body. The stored image is dropped alongside the document, mapping the session's `receiptImageUrl` back to a storage key with `receiptFileId`. A failing storage delete does not fail the request: the document is already gone and a leftover object is cheaper than a session the owner cannot remove.
"Retake photo" was a plain link back to home, which left the draft session and its receipt image behind on the server. It now deletes the session first, drops its device token and cached query, and navigates home once the request settles. Also drop the header back link: leaving the review screen without resolving the draft is exactly what that route no longer allows.
There was a problem hiding this comment.
Important
The storage refactor is clean and behaviour-preserving, but the new DELETE /sessions/:sessionId accepts sessions in any status — including open and closed, where it destroys every participant's embedded line items and claims. Worth settling the intended scope before merge.
Reviewed changes — full diff of all 26 files at fd4e085, plus local verification of the lint, sync and unit-test gates.
ObjectStoragegeneralization —save()now takes a caller-supplied key and returnsvoid;GcsObjectStorageis constructed with{ prefix, bucketName, apiEndpoint }rather than reaching intoBun.envitself.- Key/URL logic relocated —
newReceiptFileId,receiptUrl,receiptFileIdandRECEIPT_BASE_PATHmove tomodules/receipt/service.ts;createReceiptStorage()instorage/index.tsbecomes the single composition point. ensureBucket()deleted — emulator bucket auto-creation is replaced by seeding fake-gcs-server from a new./.dev/gcs:/datacompose mount.- New
DELETE /sessions/:sessionId—owner: true, returns 204, hard-deletes the document then best-effort deletes the receipt image. - Web discard flow — new
useDeleteSessionhook; "Retake photo" becomes a button that discards before navigating, and the header back-link is removed. - Media types moved to
@repo/shared-types— the@repo/api/constantssubpath export is dropped.
I confirmed the stored object layout is receipts/<uuid>.<ext> both before and after, so existing images and existing receiptImageUrl values keep resolving — no migration needed. doc.deleteOne() is a valid Mongoose document method in the installed version, and receiptImageUrl defaults to '' with receiptFileId('') returning null, so the no-image path is safe. Locally: bun nx test api 121 pass, bunx nx lint web exit 0, bunx nx sync:check up to date.
⚠️ Nothing proves the session document is actually deleted
The PR body states the change ships "integration coverage for the delete route's auth and 204 path", but apps/api/test/ gains no new spec — the only change there is fixtures.ts type renames. Every test of the delete path mocks Session.prototype.deleteOne, so the suite would stay green if the call never reached Mongo at all.
Technical details
# Delete path has no real-database coverage
## Affected sites
- `apps/api/src/modules/session/__test__/service.spec.ts:251` — `spyOn(Session.prototype, 'deleteOne').mockImplementation(...)`; asserts the spy was called, not that a document was removed.
- `apps/api/src/modules/session/__test__/index.spec.ts:383` — same mock at the route level.
- `apps/api/test/` — contains only `auth-flow.spec.ts`, `session-participants.spec.ts`, `fixtures.ts`, `setup.ts`. No delete spec was added.
## Required outcome
- Either add a `test:integration` spec that issues `DELETE /sessions/:sessionId` against the real Mongo testcontainer and asserts the document is gone afterward, or correct the PR description so it does not claim coverage that is not present.
## Open questions for the human
- Docker is unavailable in this review sandbox, so the integration suite could not be executed here — this finding comes from reading the file list, not from a failing run.ℹ️ Nitpicks
apps/web/src/features/session/components/session-draft.tsx:7—ChevronLeftis now unused; removing the header<Link>removed its only consumer.bunx biome lintflags it aslint/correctness/noUnusedImports. It does not failnx lint web(warnings are non-fatal in this repo) but it is new noise introduced by this PR.apps/api/src/storage/gcs.ts:22—objectName()guards withthis.prefix ? ... : key, butprefixis a required non-optional field ofGcsObjectStorageOptionsand the sole construction site passes the literal'receipts'. The empty-prefix branch is unreachable.
Claude Opus | 𝕏
Follow-up to my review — one correction, one firmer findingSome verification finished after I submitted my review above. Where this comment and that review disagree, this one is right. Correction: failed deletes are not silentIn my inline comment on The narrower concern that survives:
For what it's worth, Firmer: the missing draft guard breaks an existing conventionI raised the missing status guard as a design question. It is more concrete than that —
The response type already exists — Two things that should inform which way you go:
Cleared: dev bucket seedingI flagged the
|
`app.ts` re-exported `EXT_BY_MEDIA_TYPE`, `SUPPORTED_IMAGE_MIME_TYPES` and
`SupportedImageMimeType` next to the `App` type, but nothing consumed them:
`apps/web/src/lib/api-client.ts` is the only importer of `@repo/api` and it
takes `import type { App }` alone. The `./constants` subpath they used to be
reachable through is gone too.
They are value exports on a module that transitively pulls in `mongoose` and
`@google-cloud/storage`, so importing them from here would drag the server
into the browser bundle — the coupling that moving the media types to
`@repo/shared-types` set out to remove. Consumers already take them from
`@repo/shared-types` or from `storage/object-storage`.
`clearToken` and `removeQueries` ran in the mutation's `onSuccess` while the button navigated home on `onSettled`, so a failed `DELETE` left for home with the device token still stored and the session still cached. Pressing back returned the user to the draft they had just discarded, alive and editable. Discarding is local-first: "Retake photo" is both a delete and an intent to move on, and the intent does not hang on the server answering. The device now forgets the session either way, and a document left behind expires with its TTL. Clearing the token before leaving is safe because `expireSession` treats a session it holds no token for as already handled, so a late refetch neither toasts nor redirects.
Removing the header back link took away the icon's only consumer. Biome reports it as `lint/correctness/noUnusedImports`, but only as a warning, so `nx lint web` stayed green with it in place.
`src/model.ts` held a single Elysia schema and sat next to `index.ts` and `app.ts`, where the rest of the tree is folders by responsibility. It also collided by name with the per-module `modules/session/model.ts` and `modules/auth/model.ts`, so `'../model'` and `'../../model'` read as if they pointed at a module's own schemas when they pointed at a global one. It now lives in `src/common/model.ts`, alongside `plugins/`, `schemas/` and `storage/`, which leaves an obvious home for the next validation schema shared across modules. The two importers, `plugins/auth.ts` and `modules/session/model.ts`, are the only ones in the repo. `OBJECT_ID_PATTERN` stays in `@repo/shared-types`. The binding to `t.String` does not follow it there: that lib is framework-agnostic and `apps/web` consumes it through a `export *` barrel, so an Elysia schema would pull typebox into the browser bundle's type graph.
There was a problem hiding this comment.
ℹ️ No new issues in the four commits since the last review. Not an approval only because the earlier
DELETE /sessions/:sessionIdscope thread is still open.
Reviewed changes — the four commits added since the prior pullfrog review at fd4e085, plus a re-run of the repo's CI gates.
- Dropped the dead media-type re-export —
app.tsno longer re-exportsEXT_BY_MEDIA_TYPE/SUPPORTED_IMAGE_MIME_TYPES;@repo/shared-typesis now the single source and nothing pulls those constants through a module that transitively importsmongooseand@google-cloud/storage. - Moved the discard cleanup to
onSettled—useDeleteSessionnow runsclearTokenandremoveQueriesregardless of outcome, so the hook and the button's navigation finally agree on what "discarded" means. React Query invokes hook-level callbacks beforemutate-level ones, so cleanup still precedes the navigation. - Removed the orphaned
ChevronLeftimport — clears thenoUnusedImportswarning the removed header link left behind. - Relocated the shared
objectIdschema —src/model.ts→src/common/model.ts, withplugins/auth.tsandmodules/session/model.tsupdated. Verified no../modelimports still point at the old root path.
Locally: bunx nx sync:check up to date, nx run-many -t tsc:typecheck format:check green for all six projects, bun nx test api 121 pass, bun nx lint web exit 0 with only pre-existing noExplicitAny warnings. On the failure path introduced by b8c10f9: a failed DELETE does leave a server-side orphan the user can no longer reach, but sessionSchema carries a 90-day TTL on createdAt and the global Eden onResponse hook toasts the error, so it degrades to the pre-PR status quo rather than to something worse.
Claude Opus | 𝕏

What
Turns the receipt-specific GCS wrapper into a generic keyed object storage, adds
DELETE /sessions/:sessionId, and wires the web app's "Retake photo" button to it so abandoning a draft no longer leaks a session document and an orphaned image.Changes
Storage (
apps/api/src/storage)ObjectStorageis now a plain keyed interface —save(key, bytes, mediaType),get(key),delete(key)— with no knowledge of receipts.GcsObjectStoragetakes aprefixso other kinds of objects can share the same bucket later.<uuid>.<ext>) and the/receipts/<id>URL mapping move toapps/api/src/modules/receipt/service.ts, where they belong.createReceiptStorage()instorage/index.tsis the single composition point.Session deletion
DELETE /sessions/:sessionId, owner-only, removes the session document and then best-effort deletes its receipt image. A storage failure does not fail the request — the document is already gone, and a stray object is cheaper than a dangling session.204;401/403come from the existing auth plugin.Web
useDeleteSessionhook: deletes the session, clears its device token from the browser, and drops the cached session query.Shared types / dev setup
SUPPORTED_IMAGE_MIME_TYPESandEXT_BY_MEDIA_TYPEmove from the API to@repo/shared-types, so the web upload validation and the API agree on one list.compose.yamlmounts.dev/gcsinto fake-gcs-server, so the dev bucket exists on boot. The app never creates buckets itself; in production the bucket is provisioned by infra.Testing
bun nx test apiandbun nx test:integration api— unit specs for the new storage composition, receipt key helpers, and session deletion; integration coverage for the delete route's auth and 204 path.bun nx lint web/bun nx typecheck web.Note:
typecheckneedsbun nx build shared-typesto have emitted intodist/out-tscfirst — a stale or missing build there surfaces as "no exported member" errors from@repo/shared-types.