Skip to content

fix: menu-template UUID ids (self-serve menu import) + refund input/authz status codes - #15

Merged
snackman merged 1 commit into
mainfrom
fix-menu-template-uuid
Jun 6, 2026
Merged

fix: menu-template UUID ids (self-serve menu import) + refund input/authz status codes#15
snackman merged 1 commit into
mainfrom
fix-menu-template-uuid

Conversation

@snackman

@snackman snackman commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two real bugs in the multi-tenant POS.

Bug 1 (primary) — self-serve menu import fails on Supabase

POST /api/signup { action: import_menu } returned 500 invalid input syntax for type uuid: "cat-mq1zyqas-1". The starter-menu template generated synthetic string ids (cat-…, item-…, etc.). The mock driver accepts any string id, but the production Supabase schema types every id column as uuid, so a self-serve tenant could be created but stay menu-less.

Fix: src/lib/saas/menu-template.ts tid() now returns crypto.randomUUID() for every generated id — categories, items, sizes, modifier groups, and modifiers. item_modifier_groups join rows have no id column (composite key item_id+group_id), so they reference the new uuids only. Both drivers (mock.ts, supabase.ts) already pass the template rows (tpl.*) straight into their inserts, so the uuids flow through template → driver → insert unchanged. Referential integrity (item→category, size→item, modifier→group, item↔group links) is preserved.

Bug 2 (secondary) — refund returns 500 on bad/unauth input

POST /api/payments/refund with a malformed paymentId returned 500 instead of a clean 422 (and unauth callers risked a 500 from a uuid-typed lookup).

Fix: added an isUuid guard to src/lib/security/validate.ts; the refund route now rejects a non-UUID paymentId with 422 before touching the DB, and wraps getPayment so a lookup error can never surface as a 500 to an unauthenticated caller. Unauthenticated/non-member callers still get 401/403 via requireTenantMember, and the no-unauthorized-refund behavior is unchanged.

Tests

  • src/lib/saas/menu-template.test.ts (new): asserts every template id is a valid UUID, ids are unique, referential integrity holds, and exercises the template → mock driver → getMenu insert/read path end-to-end.
  • src/lib/security/validate.test.ts: added isUuid unit coverage (incl. rejecting the old cat-mq1zyqas-1 shape).

Verification (zero env vars, mock driver)

npm run build, npm run typecheck, npm run lint, npm run test:run all green (160 tests pass).

🤖 Generated with Claude Code

…uthz status codes

Bug 1 (primary): the starter-menu template emitted synthetic string ids like
`cat-<rand>-1`, which the mock driver accepts but the production Supabase schema
(uuid columns) rejects with `invalid input syntax for type uuid`, leaving a
self-serve tenant menu-less after a 500. `tid()` now returns `crypto.randomUUID()`
for every generated id (categories, items, sizes, modifier groups, modifiers).
Both drivers already carry `tpl.*` ids straight into their inserts, so the new
uuids flow through template -> driver -> insert unchanged. Referential integrity
(item->category, size->item, modifier->group, item<->group joins) is preserved.

Bug 2 (secondary): POST /api/payments/refund returned 500 on a malformed/
unauthenticated paymentId. Now validates paymentId is a UUID up front (422 on
malformed) via a new `isUuid` guard in security/validate.ts, and wraps the
payment lookup so a driver error can never surface as a 500 to an unauth caller
-- unauthenticated/non-member callers still get 401/403 and the no-unauthorized-
refund behavior is unchanged.

Tests: new menu-template regression test asserts every template id is a valid
UUID, the graph keeps referential integrity, and exercises the template->mock
driver->getMenu insert/read path; isUuid unit tests added to validate.test.ts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
pos Ready Ready Preview, Comment Jun 6, 2026 7:54am

Request Review

@snackman
snackman marked this pull request as ready for review June 6, 2026 07:58
@snackman
snackman merged commit 5f2339b into main Jun 6, 2026
6 checks passed
@snackman
snackman deleted the fix-menu-template-uuid branch June 6, 2026 07:58
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.

1 participant