Skip to content

Add media usage read APIs#2092

Open
khoinguyenpham04 wants to merge 10 commits into
mainfrom
media-usage-read-api
Open

Add media usage read APIs#2092
khoinguyenpham04 wants to merge 10 commits into
mainfrom
media-usage-read-api

Conversation

@khoinguyenpham04

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds coverage-aware media usage reads so authorized clients can show where local assets are referenced.

  • Adds opt-in usage summaries to media list and get responses without changing default query cost.
  • Adds paginated "Used in" details grouped by content entry.
  • Protects draft and trash metadata with permission and token-scope checks.
  • Adds client methods, OpenAPI and REST documentation, and regression coverage.

Discussion: #1503

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenCode (GPT-5.6 Sol), Claude Opus 4.8

Screenshots / test output

No visual changes.

  • pnpm format
  • pnpm lint
  • pnpm typecheck
  • Focused media usage suite: 157 tests passed
  • SQLite query-count snapshots matched

Copilot AI review requested due to automatic review settings July 17, 2026 13:13
@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 976ed70

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Minor
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
create-emdash Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond area/core area/docs size/XL labels Jul 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 2,213 lines across 22 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.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 976ed70 Jul 17 2026, 01:14 PM

@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/admin@2092

@emdash-cms/auth

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth@2092

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/auth-atproto@2092

@emdash-cms/blocks

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/blocks@2092

@emdash-cms/cloudflare

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/cloudflare@2092

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/contentful-to-portable-text@2092

emdash

npm i https://pkg.pr.new/emdash-cms/emdash@2092

create-emdash

npm i https://pkg.pr.new/emdash-cms/emdash/create-emdash@2092

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/gutenberg-to-portable-text@2092

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-cli@2092

@emdash-cms/plugin-types

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-types@2092

@emdash-cms/registry-client

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-client@2092

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-lexicons@2092

@emdash-cms/registry-verification

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/registry-verification@2092

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/sandbox-workerd@2092

@emdash-cms/x402

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/x402@2092

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-ai-moderation@2092

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-atproto@2092

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-audit-log@2092

@emdash-cms/plugin-color

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-color@2092

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-embeds@2092

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-field-kit@2092

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-forms@2092

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/emdash-cms/emdash/@emdash-cms/plugin-webhook-notifier@2092

commit: 976ed70

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 976ed70 Jul 17 2026, 01:15 PM

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do 976ed70 Jul 17 2026, 01:15 PM

@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right change for the approved Discussion: additive, read-only media usage APIs with the advertised scope/permission gating. The implementation keeps default query cost intact (usage is opt-in via includeUsage=1), groups details by content entry, and reuses the existing projection tables and repair pipeline. It also wires up routes, OpenAPI, client methods, docs, and regression tests.

I reviewed the diff and related source statically and found no blocking correctness, security, authorization, or AGENTS.md violations. The repository-level pagination SQL is parameterized, draft/trash metadata is guarded by content:read_drafts plus an admin token scope, the response envelope stays consistent, and the changeset is user-facing.

Only two small client-type completeness gaps are worth noting so the TypeScript contract matches what the server now returns.

Comment thread packages/core/src/client/index.ts
Comment thread packages/core/src/client/index.ts
@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 17, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right change for the approved Discussion: it adds read-only, coverage-aware media usage APIs without changing default query cost. The implementation reuses the existing media-usage projection tables and repair pipeline, and the authorization/scope gating matches the PR description.

I re-checked the diff statically after the previous review. The two client-type completeness gaps from the prior pass are resolved: EmDashClient now accepts includeUsage on mediaList / mediaGet and exposes mediaGetUsage with matching MediaUsageDetailsResponse / MediaUsageSummary types.

No blocking issues remain. The repository SQL is parameterized Kysely (no interpolation), draft/trash metadata is guarded by content:read_drafts plus admin token scope, the response envelope shape stays consistent, the changeset is user-facing, and the new tests cover schema validation, route auth/success/error paths, query-count budgets, and client serialization. Locale filtering does not come into play here because usage details are read from the projection tables and grouped by content row ID, which is already per-locale.

Approved.

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants