Skip to content

feat(api): implement the two missing vanity-URL slug endpoints - #441

Merged
thinkclay merged 1 commit into
mainfrom
claude/dazzling-swanson-b4f634
Jul 30, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/dazzling-swanson-b4f634

Conversation

@thinkclay

@thinkclay thinkclay commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The SDK's checkSlugAvailability and updateSlug both called routes that were never ported out of the legacy tRPC vanity router, so every request 404'd. The Vanity URL panel could list slug history (GET /slug/history exists) and nothing else.

What this adds

Two handlers in packages/supabase/functions/api/routes/profiles.ts, both requireAuth, both in the static-route block ahead of every param route:

Route Response
GET /v1/profiles/slug/check?slug=… { available, suggestions }
PATCH /v1/profiles/slug { success, slug, nextChangeAllowed }

Responses are deliberately unenveloped. The SDK's http client returns await response.json() with no unwrapping, so a { data } wrapper would deserialize into the wrong shape without failing loudly.

checkSlugAvailability excludes the caller's own slug from the taken check — re-saving your current slug is a no-op, not a conflict.

updateSlug enforces the same 30-day cooldown that GET /slug/history reports (400 carrying nextChangeAllowed/daysRemaining), answers 409 with alternatives when another user holds the slug, and records the change in core.slug_change_history. The history insert is best-effort: a failed insert is logged rather than surfaced, since it cannot undo a slug change that already committed.

Slug normalization matches migration 018's users_slug_format_check — lowercased and trimmed, 3–50 chars, ^[a-z0-9-]+$. generateSlugSuggestions is ported from the tRPC vanity router unchanged.

Follow-up

GET /v1/profiles/slug/{slug} (SDK getProfileBySlug) was still missing after this PR — see the follow-up PR for it.

Tests

11 new cases in profiles.test.ts using assertStatus (not assertSuccessResponse, which requires a data key): availability, own-slug-is-available, suggestions, 400/401, a successful change verified down to the slug_change_history row, case/whitespace normalization, cooldown, and 409.

Test slugs carry a per-run token. core.users.slug is globally unique and outlives a crashed run, so fixed literals collide with leftovers and fail on the second run. The fixture helper also throws if the admin slug seed fails instead of silently proceeding.

Verified green locally, 11/11, stable across consecutive runs.

🤖 Generated with Claude Code

The SDK's `checkSlugAvailability` and `updateSlug` both called routes that
were never ported out of the legacy tRPC vanity router, so every request
404'd. The Vanity URL panel could list slug history and nothing else.

Adds, in the static-route block ahead of every param route:

  GET   /v1/profiles/slug/check?slug=...  -> { available, suggestions }
  PATCH /v1/profiles/slug                 -> { success, slug, nextChangeAllowed }

Both responses are unenveloped: the SDK's http client returns the body
verbatim, so a `{ data }` wrapper would deserialize into the wrong shape
without failing loudly.

updateSlug enforces the same 30-day cooldown that GET /slug/history
reports (400 carrying nextChangeAllowed/daysRemaining), answers 409 with
alternatives when another user holds the slug, and records the change in
core.slug_change_history. The history insert is best-effort — a failed
insert is logged rather than surfaced, since it cannot undo a slug change
that already committed.

Slug normalization matches migration 018's users_slug_format_check:
lowercased and trimmed, 3-50 chars, ^[a-z0-9-]+$.

Test slugs carry a per-run token. core.users.slug is globally unique and
outlives a crashed run, so fixed literals collide with leftovers and fail
on the second run.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit 4cf5fbb into main Jul 30, 2026
3 of 16 checks passed
@thinkclay
thinkclay deleted the claude/dazzling-swanson-b4f634 branch July 30, 2026 11:02
@thinkclay thinkclay changed the title feat(api): implement the two missing vanity-URL slug endpoints feat(api): implement the missing vanity-URL slug endpoints Jul 30, 2026
@thinkclay thinkclay changed the title feat(api): implement the missing vanity-URL slug endpoints feat(api): implement the two missing vanity-URL slug endpoints Jul 30, 2026
thinkclay added a commit that referenced this pull request Jul 30, 2026
main is currently red on the contract test. #439 landed the test with an
85-entry baseline captured before #441 merged; #441 implemented two of
those entries, so the stale-entry assertion now fires on every run:

  GET /v1/profiles/slug/check
  PATCH /v1/profiles/slug

That is the assertion doing its job — it exists so a baseline cannot
quietly drift out of date — but it needs the two lines removed. Baseline
drops 85 -> 83.

Verified red before and green after: checked out origin/main in a
scratch worktree and reproduced the failure naming both entries, then
confirmed 3/3 pass with this change.

Co-authored-by: Claude Opus 5 <[email protected]>
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