Skip to content

fix(core): emdash types reads un-enveloped /schema response#1143

Open
nesmachny wants to merge 2 commits into
emdash-cms:mainfrom
nesmachny:fix/emdash-types-schema-export
Open

fix(core): emdash types reads un-enveloped /schema response#1143
nesmachny wants to merge 2 commits into
emdash-cms:mainfrom
nesmachny:fix/emdash-types-schema-export

Conversation

@nesmachny
Copy link
Copy Markdown

What does this PR do?

emdash types crashes with TypeError: Cannot read properties of undefined (reading 'collections').

The CLI's types command calls client.schemaExport(), which routed through the private request() helper. request() unwraps the standard { data } API envelope and returns json.data. But GET /_emdash/api/schema returns a bare { collections, version } object — there is no data wrapper — so schemaExport() returned undefined, and the CLI then threw on schema.collections.

schemaExport() now reads the raw response directly (requestRaw() + assertOk()), mirroring its sibling schemaTypes(). The /schema endpoint and its other consumers are unchanged — this is a non-breaking, client-side fix.

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 (0 errors)
  • pnpm test passes (or targeted tests for my change) — packages/core/tests/unit/client/client.test.ts, 18/18
  • 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) — N/A, no admin UI changes
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion — N/A, bug fix

AI-generated code disclosure

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

Screenshots / test output

The new test reproduces the bug: against the un-enveloped /schema response it failed with the exact production error before the fix, and passes after it.

 Test Files  1 passed (1)
      Tests  18 passed (18)

`emdash types` crashed with "Cannot read properties of undefined
(reading 'collections')". The client's schemaExport() routed through the
enveloped request() helper, but the /schema endpoint returns a bare
{ collections, version } object — it now reads the raw response directly.

Adds a failing-then-passing unit test and a changeset.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

🦋 Changeset detected

Latest commit: d2cbda4

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

This PR includes changesets to release 14 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@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/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@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
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@nesmachny
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 22, 2026
@ascorbic ascorbic requested a review from Copilot May 23, 2026 05:56
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 23, 2026

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

emdash

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

create-emdash

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

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

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: d2cbda4

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes a crash in emdash types by updating schemaExport() to correctly handle the /schema endpoint’s non-enveloped JSON response, instead of assuming the standard { data } wrapper.

Changes:

  • Updated EmDashClient.schemaExport() to use requestRaw() + assertOk() and parse the response body directly.
  • Added a unit test covering the un-enveloped /schema response shape.
  • Added a patch changeset documenting the CLI crash fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/client/index.ts Reads /schema as a raw JSON body (no { data } envelope), preventing schemaExport() from returning undefined.
packages/core/tests/unit/client/client.test.ts Adds regression coverage for /schema returning { collections, version } directly.
.changeset/fix-emdash-types-schema-export.md Publishes a patch note for the fixed emdash types crash.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +390 to +394
// The /schema endpoint returns a bare { collections, version } object,
// not the standard { data } envelope — parse the raw response directly.
const response = await this.requestRaw("GET", "/schema");
await this.assertOk(response);
return (await response.json()) as SchemaExport;
});

describe("schemaExport()", () => {
it("returns the un-enveloped /schema response body", async () => {
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.

3 participants