Repository navigation
feat(plugins): add bylines:read capability, ctx.bylines API, and byline hooks - #3394
Conversation
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 detectedLatest commit: 433fc17 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 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 |
@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-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@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: |
Scope checkThis PR changes 1,448 lines across 54 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. |
There was a problem hiding this comment.
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.tsandpackages/core/src/bylines/credits.tsfor SQL safety, data leakage, and pagination.packages/core/src/plugins/hooks.tsand 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.
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. |
There was a problem hiding this comment.
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.
|
:D ty Matt |
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
authorIdfromctx.contentor read user accounts throughusers:read, which misses byline credits.The new
bylines:readcapability gives pluginsctx.bylinesfor public byline profiles and entry credits, resolved the same way the site renders them. Two new hooks,byline:afterSaveandbyline: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 includescontent.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
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.AI-generated code disclosure
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".

Tests:
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 intests/unit/plugins/hooks.test.ts.ctx.bylines.getEntriesBylines().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.