Repository navigation
Add media usage repair admin API - #1867
Conversation
🦋 Changeset detectedLatest commit: ae2e421 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Scope checkThis PR changes 1,025 lines across 15 files. Large PRs are harder to review and more likely to be closed without review. If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs. See CONTRIBUTING.md for contribution guidelines. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | ae2e421 | Jul 08 2026, 09:27 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | ae2e421 | Jul 08 2026, 09:27 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-do | ae2e421 | Jul 08 2026, 09:27 AM |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
This PR adds the admin/operator REST surface for the existing content media-usage repair machinery: a new POST /_emdash/api/admin/media-usage/repair route, handler, strict Zod schemas, client method, OpenAPI docs, REST reference docs, tests, and a changeset.
Approach assessment
Assuming the maintainer-directed “Patch 4C” framing is accurate, the change is a sensible, additive API surface. It does not introduce new DB queries or repair logic; it exposes the already-existing repairContentMediaUsageCollection / repairContentMediaUsageAll functions with proper auth, CSRF, request validation, and a shaped response envelope. The permission choice (schema:manage) and the token-scope requirement (admin, because the path is under /_emdash/api/admin) match the stated operator-only intent.
I cannot verify the maintainer direction or an approved Discussion from the diff alone, so I’m treating that as a process note rather than a code blocker.
What I checked
- Auth / CSRF: The route lives under
/_emdash/api/admin, so the middleware enforces theadmintoken scope; the route itself checksschema:manageviarequirePerm. Non-ADMIN users and missing/bad tokens are rejected with the expected 401/403. Session-authenticated POSTs still requireX-EmDash-Request: 1(verified in tests and middleware). - Request/response shape: The
mediaUsageRepairBodyis a strict discriminated union with explicitscope: "collection"andscope: "all"shapes; there is no silent default to all-content repair. Unknown collections return a structured200withstatus: "failed"andlastErrorCode: "COLLECTION_NOT_FOUND", consistent with the docs. - API conventions: The route uses
requireDb,requirePerm,parseBody,unwrapResult, and the standardApiResultenvelope. The newMEDIA_USAGE_REPAIR_ERRORmaps to 500 via the existingmapErrorStatusfallback. - Client:
EmDashClient.mediaRepairUsage()POSTs to the correct prefixed path and accepts the same explicit input union. - OpenAPI: The new path is registered in
buildMediaPaths, uses the Zod schemas as source of truth, and documents the expected 200/400/401/403/413/500 responses. - AGENTS.md: No new admin UI strings (Lingui/RTL n/a), no dynamic SQL added, no new permission string invented, collection slug validation aligns with existing schemas, and a minor changeset is present.
Headline conclusion
The diff is clean and well-tested. I found no blocking issues, regressions, or convention violations.
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
It will be used by the next patch:
The overall plan here is repair service exists already. This patch exposes it safely over REST and EmDashClient. The next PR will add CLI/MCP commands for operators. |
What does this PR do?
Adds Patch 4C's admin/operator API surface for repairing content media usage indexes.
POST /_emdash/api/admin/media-usage/repairwith explicit{ "scope": "collection" }and{ "scope": "all" }request shapes.EmDashClient.mediaRepairUsage()and exported client-side request/response types.emdashpackage.No linked issue. Implements the maintainer-directed Patch 4C media usage repair plan.
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain. N/a: no admin UI strings were added.AI-generated code disclosure
Screenshots / test output
No screenshots: API/client/docs change only.
Verified:
Focused Vitest result: 77 tests passed.
Additional review:
second-opinionadversarial review converged with no remaining code/spec findings.Try this PR
Open a fresh playground →
A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.
Tracks
media-usage-repair-admin-api. Updated automatically when the playground redeploys.