Skip to content

feat(plugins): add bylines:read capability, ctx.bylines API, and byline hooks - #3394

Merged
ascorbic merged 4 commits into
emdash-cms:mainfrom
ttmx:feat/plugin-bylines-api
Sep 27, 2026
Merged

ascorbic merged 4 commits into
emdash-cms:mainfrom
ttmx:feat/plugin-bylines-api

Conversation

@ttmx

@ttmx ttmx commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Lets plugins read the bylines credited on content. Plugins that index or publish content, such as search indexers and feed generators, need author names, but today they can only get the raw authorId from ctx.content or read user accounts through users:read, which misses byline credits.

The new bylines:read capability gives plugins ctx.bylines for public byline profiles and entry credits, resolved the same way the site renders them. Two new hooks, byline:afterSave and byline:afterDelete, let those plugins keep their copy current when a profile changes. The PR has two commits, one for the read API and one for the hooks, so they can be reviewed separately.

Credit changes on an entry are already reported by content:afterSave, which includes content.bylines. Relinking a byline to another user can change inferred credits without a per-entry event; this is documented rather than solved here.

Type of change

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

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: (Add a public `getBylines()` so site code can list bylines without going through content #2333) Remaining discussed internally
  • I have included screenshots below if this PR changes the UI

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 5.5 (OpenCode)

Screenshots / test output

The only UI change is a new permission label in the install and update consent dialog: "Read public byline profiles and content credits".
image

Tests:

  • New: packages/core/tests/integration/plugins/byline-access.test.ts (API behavior), packages/core/tests/integration/api/byline-hooks.test.ts (REST and MCP hooks, capability gating, error isolation), and a capability-gating case in tests/unit/plugins/hooks.test.ts.
  • Sandbox: denial and validation cases in the Cloudflare and workerd bridge tests, and the real workerd integration test calls ctx.bylines.getEntriesBylines().
  • Full suites pass for core, cloudflare, workerd, plugin-test, plugin-types, plugin-cli, and marketplace, plus the admin marketplace test. Both commits pass build, lint, and typecheck on their own. The docs site builds.
  • Manually verified on a Node dev site with a trusted plugin, a workerd-sandboxed plugin, and a plugin without bylines:read: create, update, translation, and delete through REST and MCP fired the expected events with public fields only; failed deletes fired nothing; the plugin without the capability was refused at registration.
  • Not run: PostgreSQL parity tests.

Plugins with bylines:read can read public byline profiles with
ctx.bylines.get() and list(), and resolve the bylines credited on up to
100 entries of one collection with getEntriesBylines(). Credits match
what the site renders, including author-inferred credits, and resolve at
each entry's locale. Profiles omit the linked user, guest flag, and
custom field values.

The credit resolver moves to bylines/credits.ts so the sandbox bridges
can use it without importing the site loader; the site path keeps its
query count. The capability is wired through plugin-types, the manifest
schemas, plugin-cli, the registry lexicon, admin consent labels, and the
Cloudflare and workerd sandbox bridges.
Plugins with bylines:read can react to byline profile changes, for
example to keep a search index's author data current. Both hooks receive
the public byline profile; afterSave also reports isNew, and afterDelete
carries the byline as it was before deletion.

The hooks fire after the admin REST routes (create, update, translation,
delete) and the MCP byline tools succeed, deferred with after(). Errors
are logged and never propagate. Delete reads the row first only when a
plugin registered byline:afterDelete, so sites without such plugins keep
the same query count. Seeds and imports do not fire the hooks.
@changeset-bot

changeset-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 433fc17

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

This PR includes changesets to release 18 packages
Name Type
emdash Minor
@emdash-cms/plugin-types Minor
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Minor
@emdash-cms/plugin-cli Minor
@emdash-cms/registry-lexicons Minor
@emdash-cms/admin Minor
@emdash-cms/plugin-test Patch
@emdash-cms/registry-verification Patch
@emdash-cms/registry-client Patch
@emdash-cms/registry-loader Patch
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
create-emdash Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 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

@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Sep 24, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

npm i https://pkg.pr.new/emdash@3394

create-emdash

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

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

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

@emdash-cms/plugin-cli

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

@emdash-cms/plugin-test

npm i https://pkg.pr.new/@emdash-cms/plugin-test@3394

@emdash-cms/plugin-types

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

@emdash-cms/registry-client

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

@emdash-cms/registry-lexicons

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

@emdash-cms/registry-loader

npm i https://pkg.pr.new/@emdash-cms/registry-loader@3394

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@3394

@emdash-cms/registry-verification

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

@emdash-cms/sandbox-workerd

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 433fc17

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 1,448 lines across 54 files. Large PRs are harder to review and more likely to be closed without review.
This PR spans 5 different areas (area/core, area/admin, area/plugins, area/docs, area/cloudflare). Consider breaking it into smaller, focused PRs.

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.

@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.

I reviewed the full diff and the relevant source files. The change is architecturally sound: introducing a dedicated bylines:read capability, a read-only ctx.bylines API, and after-save/after-delete hooks fits how EmDash already gates content, taxonomies, and media. The implementation correctly strips private byline fields (userId, isGuest, customFields) before exposing them to plugins, enforces the 100-entry credit lookup limit, validates collection identifiers before any SQL is built, and gates hook registration on the new capability.

I traced:

  • packages/core/src/plugins/byline-access.ts and packages/core/src/bylines/credits.ts for SQL safety, data leakage, and pagination.
  • packages/core/src/plugins/hooks.ts and the admin/MCP routes for hook firing, error isolation, and capability checks.
  • packages/cloudflare/src/sandbox/bridge.ts, packages/workerd/src/sandbox/bridge-handler.ts, and the generated wrappers for parity in sandboxed runtimes.
  • All changesets and documentation prose against the implementation.

The code is clean, tests cover behavior rather than tautologies, and the docs and capability labels stay consistent with the implementation. I could not verify the maintainer-approved Discussion that AGENTS.md requires for features (the PR checklist item is unchecked with only “Discussed internally”), so maintainers should confirm that exists before merging. I did not run checks.

@emdashbot emdashbot Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Sep 24, 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.

@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Sep 27, 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.

The approach remains solid: adding a dedicated bylines:read capability, a read-only ctx.bylines API, and after-save/after-delete hooks fits EmDash’s existing plugin gating model and solves the stated problem for search-indexer/feed-generator plugins. The implementation correctly strips private byline fields before exposing them, enforces the 100-entry credit lookup limit, validates collection identifiers before building SQL, gates hook registration on the new capability, and defers hook execution so mutations aren’t blocked.

I re-checked the one issue from my prior review (packages/core/src/plugins/byline-access.ts:81): loadEntryRefs intentionally lets an unknown/missing ec_<collection> table fail rather than returning empty credits, and the contributor’s pushback is consistent with how ctx.content.get/list and ctx.taxonomies.getEntryTerms behave — I verified taxonomy.ts performs the same kind of raw content-table lookup without an isMissingTableError guard. I’m satisfied leaving that as intentional.

Otherwise I traced the new code across core (byline-access.ts, bylines/credits.ts, plugins/hooks.ts, plugins/context.ts), admin/MCP routes, Cloudflare bridge/runtime, workerd bridge-handler/wrapper, plugin-types, manifest schemas, docs, and changesets. I found no new logic bugs, security issues, AGENTS.md convention violations, or inconsistencies. Tests cover API behavior, capability gating, error isolation, sandbox parity, and workerd integration. No logged-out query-count impact was introduced.

Approve as-is.

@emdashbot emdashbot Bot added review/approved Approved; no new commits since and removed bot:review Trigger an emdashbot code review on this PR review/awaiting-author Reviewed; waiting on the author to respond labels Sep 27, 2026
@ascorbic
ascorbic merged commit 38d200d into emdash-cms:main Sep 27, 2026
47 checks passed
@ttmx

ttmx commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

:D ty Matt

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