fix: menu-template UUID ids (self-serve menu import) + refund input/authz status codes - #15
Merged
Merged
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 }returned500 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 asuuid, so a self-serve tenant could be created but stay menu-less.Fix:
src/lib/saas/menu-template.tstid()now returnscrypto.randomUUID()for every generated id — categories, items, sizes, modifier groups, and modifiers.item_modifier_groupsjoin rows have no id column (composite keyitem_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/refundwith a malformedpaymentIdreturned 500 instead of a clean 422 (and unauth callers risked a 500 from auuid-typed lookup).Fix: added an
isUuidguard tosrc/lib/security/validate.ts; the refund route now rejects a non-UUIDpaymentIdwith 422 before touching the DB, and wrapsgetPaymentso a lookup error can never surface as a 500 to an unauthenticated caller. Unauthenticated/non-member callers still get 401/403 viarequireTenantMember, 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 →getMenuinsert/read path end-to-end.src/lib/security/validate.test.ts: addedisUuidunit coverage (incl. rejecting the oldcat-mq1zyqas-1shape).Verification (zero env vars, mock driver)
npm run build,npm run typecheck,npm run lint,npm run test:runall green (160 tests pass).🤖 Generated with Claude Code