Every account in Munchable can download everything we hold about it. The endpoint is one route handler, it runs five queries, and the field in its output I spent the longest on is a string of prose.

The whole handler

Authorisation first. An anonymous session is not an account and gets nothing:

const user = await getUser(request); if (!user || user.isAnonymous) { return NextResponse.json({ error: 'unauthorized' }, { status: 401 }); } 

Then five reads, in parallel, each scoped to the caller's own id:

const [ent, consent, rewards, contributions, feedback] = await Promise.all([ db.select().from(entitlements).where(eq(entitlements.userId, uid)).limit(1), db.select().from(userConsent).where(eq(userConsent.userId, uid)).limit(1), db.select().from(contributionRewards).where(eq(contributionRewards.userId, uid)), db .select({ barcode: catalogProductRevisions.barcode, ingredientsText: catalogProductRevisions.ingredientsText, createdAt: catalogProductRevisions.createdAt, }) .from(catalogProductRevisions) .where(eq(catalogProductRevisions.contributorId, uid)), db.select().from(catalogProductFeedback).where(eq(catalogProductFeedback.userId, uid)), ]); 

Billing state, the consent record, rewards earned, labels contributed, and product corrections sent in. That is the complete list of things an account can accumulate on our servers.

Four of those five are select() with no column list, because every column in those rows is the user's own data and leaving one out would be a smaller export than the regulation asks for. The fifth names three columns on purpose. A contributed label row has our own processing columns on it as well as the contribution, and those are our operational record rather than something the contributor is entitled to receive. Naming the three keeps a column added next year out of the payload by default, which is the direction I want the mistake to go for a row that is only half the user's.

The field that took the longest

note: 'Your conditions, sensitivities, and scan history are stored only on your device and are never sent to our servers, so they are not part of this export.', 

Here is the problem that sentence solves. A thin export looks like a broken export. Someone who manages three conditions, has scanned forty products and keeps a food log asks for their data and receives a billing row, a consent row and, if they have never contributed a label, three empty arrays. The most likely reading of that file is that we are holding things back.

We are not. The health data is not filtered out of the export, which is the version of this I want to be clear about, because it is a different claim. It was never there to filter. It is written to device storage and no endpoint uploads it, so the export is thin because the architecture is thin, and the only way to say so inside a JSON file is to put a sentence in it.

That sentence has to agree with our privacy notice, which is the copy a reader can hold us to, and with the deletion flow, which is where the asymmetry shows up: account deletion has to reach both the server and the handset, because the two halves of your data are in two places. Export only has to reach one.

The filename nobody reads

The response is deliberately not NextResponse.json. It is built by hand so it can carry a disposition:

return new NextResponse(JSON.stringify(payload, null, 2), { status: 200, headers: { 'content-type': 'application/json; charset=utf-8', 'content-disposition': `attachment; filename="munchable-data-${uid}.json"`, }, }); 

Two things in the repository call that endpoint, and neither of them lets a browser see that header.

The website fetches it and builds its own download:

const res = await fetch('/api/export-account', { credentials: 'same-origin' }); const blob = await res.blob(); const a = document.createElement('a'); a.href = url; a.download = 'munchable-data.json'; 

The app parses the JSON, re-serialises it, and on native hands the text to the share sheet rather than writing a file at all:

await Share.share({ message: json, title: 'My Munchable data' }); 

So there are three download designs in play and the header is not one of them. a.download overrides the server's filename on the web, and the native path never involves a browser. The account id in that filename has never appeared on anybody's disk.

I am keeping the header, for one reason: the endpoint is also a URL a signed-in person can open directly, and in that path the header is the only thing standing between them and a page of raw JSON in a tab. It is dead weight for the two callers we wrote and the correct behaviour for the caller we did not.

The JSON.stringify(payload, null, 2) is a related choice. Pretty printing a machine-readable export is wasted bytes right up until somebody opens it to read it, which for a right-of-access export is most of the time.

What this is worth copying for

The thing I did not expect going in was how much of a data export is writing rather than querying. The queries took an afternoon. Deciding that the export needed to explain its own emptiness, and that the explanation had to be true in the same words as the privacy notice, took longer.

If you want to see the two public claims this endpoint has to keep agreeing with, they are our privacy notice and the licences and attribution page, which is where the contributed-label half of the export is described in plain English. The terms carry the version number that the consent row in the export points at.