Repository navigation
feat(reviews): ReviewLinks resource for shareable review tokens (SC-38) - #3
Merged
Merged
Conversation
Adds a new ReviewLinks resource + mounts it on the Scaffald client.
Drives the SC-38 "shareable, no-account-required review request"
feature in scaffald-app.
Methods:
- create({ label?, expires_at?, max_uses? }) — auth, returns ReviewLink with share_url
- list() — auth, lists current user's links
- revoke(id) — auth
- getByToken(token) — anon, returns subject info for the public form
- submitByToken(token, { reviewer_name, reviewer_email?, reviewer_relationship, rating, body, headline? }) — anon
Types: ReviewLink, ReviewLinkLookup, ReviewLinkSubject, ReviewerRelationship, CreateReviewLinkParams, SubmitReviewByTokenParams, SubmitReviewByTokenResponse.
API endpoints expected at /v1/reviews/links — see the matching
scaffald-app PR for the Edge Function implementation.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
6 of 20 tasks
thinkclay
added a commit
to Scaffald/SaaS
that referenced
this pull request
May 22, 2026
#280) * feat(reviews): shareable review links + anon review submission (SC-38) The "Reviews & Credentials" trust layer described in https://linear.app/scaffald/issue/SC-38. A worker generates a unique link and shares it with a former employer, instructor, foreman, CTE director, co-op supervisor, project lead, client, etc. The recipient opens the link in any browser and submits a review WITHOUT creating a Scaffald account. Reviews flow into the same core.reviews table existing UI already reads from, so they show up on the public profile immediately. What's new Migration: `326_review_links_and_anon_reviews.sql` - New `core.review_links` table: id, subject_user_id, token, label, expires_at, max_uses, used_count, is_revoked, timestamps. - RLS: workers manage their own rows; anon SELECT is granted so the public submit Edge Function can look up by token. The token itself (32 hex chars of v4 UUID entropy) is the secret. - `core.reviews.author_user_id` is now nullable. The existing UNIQUE (kind, subject_type, subject_id, author_user_id) constraint is replaced by a partial unique index that only applies when author_user_id IS NOT NULL — anon dedup is handled at the API layer. - Anon writes to core.reviews are NOT allowed via RLS — the Edge Function uses the service role after validating the token. This forces all anon submissions through the API where future rate limiting / anti-bot can live. API: `packages/supabase/functions/api/routes/review-links.ts` - POST /v1/reviews/links (auth) create - GET /v1/reviews/links (auth) list mine - DELETE /v1/reviews/links/:id (auth) revoke - GET /v1/reviews/links/by-token/:token (anon) validate + return subject info (name, headline, slug, avatar_path) - POST /v1/reviews/links/by-token/:token/submit (anon) submit a review. Validates token (not revoked, not expired, under max_uses), optionally dedupes by reviewer email, inserts the review with author_user_id = NULL + metadata.via_review_link = link_id, then increments used_count. Best-effort — increment errors don't block the review. SDK (submodule): `packages/sdk` bumped to include the new ReviewLinks resource. See Scaffald/sdk#3. scf-core hooks: `utils/review-links-sdk-hooks.ts` - useMyReviewLinks (worker) - useCreateReviewLinkMutation, useRevokeReviewLinkMutation (worker) - useReviewLinkByToken (anon, used by the public form) - useSubmitReviewByTokenMutation (anon) Worker UI: `features/profile/components/RequestReviewModal.tsx` - New "Request review" button on /profile next to "Share profile". - Optional label input ("Foreman at Acme") for tracking which link was given to whom. - "Generate" → mutation → modal shows QR + URL + Copy + Share. - Below: list of other active links with per-row Copy + Revoke. - Web Share API on web with clipboard fallback; native Share.share on iOS/Android. Public form: `apps/scaffald/app/(public)/reviews/[token].tsx` - Validates token via the SDK hook on mount. Invalid/expired/revoked → friendly error screen with a CTA back to scaffald.com. - Renders the worker's display name + headline at the top so the reviewer knows who they're vouching for. - Form: reviewer name (required), email (optional), relationship (instructor / manager / coworker / client / foreman / supervisor / other), 1-5 star rating, optional headline, body (max 2000 chars). - Submit → service-role insert into core.reviews via the Edge Function → success screen with a deep-link to the public profile. Deployment note This PR ships a migration. To apply locally: cd packages/supabase && pnpm supa db reset The migration is additive (relaxes constraints, adds new table) and reversible. Existing review data is unaffected. Out of scope (v1.4.0) - Anti-bot / CAPTCHA on the public form (see SC-32 — Cloudflare Turnstile). - Per-IP rate limiting on submitByToken. - Email notification to the worker when a review arrives. - "Reviews I've requested" dashboard with per-link stats. Co-Authored-By: Claude Opus 4.7 <[email protected]> * fix(reviews): address Codex review on SC-38 + sync SDK submodule Three Codex findings from PR #280, all reasonable: P1 — Atomic max_uses enforcement (review-links.ts submit endpoint) The previous flow validated `used_count < max_uses` then later wrote `used_count + 1` from the read value. Two concurrent submits on the same token could both pass validation and both insert reviews, breaking the advertised cap and clobbering the counter via lost update. Now uses a compare-and-swap UPDATE that claims the slot atomically before the review insert. PostgREST's chained `.eq()` filters compose into a `WHERE used_count = ? AND is_revoked = false` predicate; if a concurrent caller has incremented in the meantime, the update affects 0 rows and we return 409. The earlier read-and-validate block still runs because it produces friendlier error messages for known-invalid states (revoked, expired, max-reached at read time) — but it's no longer load-bearing for correctness. If the review insert fails after the claim, we issue a CAS refund (used_count = used_count - 1, gated by `eq("used_count", claimed)`) so a failed write doesn't burn a slot. Best-effort: if the refund also fails, the worst case is one wasted slot. P1 — Remove anon SELECT policy on core.review_links (migration 326) The previous policy granted anon `USING (TRUE)`, which would let any unauthenticated client enumerate review tokens via the Supabase REST API. The Edge Function already uses the service role for token lookup (which bypasses RLS), so the policy was dead code on top of being a vector for token enumeration. Dropped entirely. P2 — Filter unusable links from the Request Review modal The modal's `activeLinks` was `!is_revoked`, but the submit API also rejects expired and maxed-out tokens. Surfacing them in the "most recent link" QR/Copy/Share UI just produced silent failures for recipients. Filter now also excludes expired (`expires_at` in the past) and maxed (`used_count >= max_uses`) rows. Also bumps the @scaffald/sdk submodule from the feature-branch commit (now deleted) to the squash-merge of #3 on main (`0518e70 feat(reviews): ReviewLinks resource for shareable review tokens (SC-38)`). Co-Authored-By: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
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
Adds a new
ReviewLinksresource for the SC-38 shareable review link feature in scaffald-app. Workers generate a unique token they share with a former employer / instructor / foreman / client; the recipient submits a review without creating a Scaffald account.What's new
src/resources/review-links.ts— new `ReviewLinks` class extending ResourceAPI contract
Endpoints land in scaffald-app at `packages/supabase/functions/api/routes/review-links.ts`. Mounted at `/v1/reviews/links` (separate from the existing `/reviews` router which stays auth-only).
The anon endpoints validate the token + use the service role to insert reviews with `author_user_id = NULL`. Reviewer identity lives in `metadata.reviewer_*`. See the consumer PR for the Edge Function + the matching migration.
Out of scope
Linear
🤖 Generated with Claude Code