Skip to content

fix(fmodata/better-auth): resolve OData metadata key lookup + upgrade better-auth to 1.5.x#124

Merged
eluce2 merged 4 commits intoproofgeist:mainfrom
chriscors:feat/better-auth-1.5-metadata-fix
Mar 6, 2026
Merged

fix(fmodata/better-auth): resolve OData metadata key lookup + upgrade better-auth to 1.5.x#124
eluce2 merged 4 commits intoproofgeist:mainfrom
chriscors:feat/better-auth-1.5-metadata-fix

Conversation

@chriscors
Copy link
Contributor

Summary

This PR ships two related fixes surfaced while investigating a bug in the @proofkit/better-auth migration CLI:

  1. @proofkit/fmodata — metadata key lookup bug (fix): Database.getMetadata() was throwing when connecting to FileMaker Server because the OData $metadata endpoint returns the database name without the .fmp12 extension as the response key (e.g. "GMT_Web"), but the Database instance is constructed with the full filename ("GMT_Web.fmp12"). The key lookup data[this.databaseName] always missed, crashing the migration CLI with a confusing error.

  2. @proofkit/better-auth — upgrade to Better Auth 1.5.x (feat): Better Auth 1.5 renamed createAdaptercreateAdapterFactory in better-auth/adapters and removed the getAdapter export from better-auth/db. Updated the adapter and CLI to use the new APIs.


Root Cause

The migration CLI calls db.getMetadata() to compare existing FileMaker tables against the Better Auth schema. getMetadata() fetches /{db}/$metadata and then extracts data["GMT_Web.fmp12"]. FileMaker's OData engine returns { "GMT_Web": { ... } } — without the .fmp12 extension — so the lookup returned undefined, and the code threw before any migration logic ran. Regular queries were unaffected because they never call getMetadata().


Changes

packages/fmodata/src/client/database.ts

  • Primary bug fix: getMetadata() now falls back to the .fmp12-stripped database name when the full name is not found as a key in the OData response:
    const metadata = data[this.databaseName] ?? data[this.databaseName.replace(FMP12_EXT_REGEX, "")];
    The full name still takes priority for any server that returns the key with the extension.
  • Secondary fix: the default (no-arg / format: 'json') code path previously gated on args?.format === "json", which silently returned the raw wrapper object when format was omitted. Logic inverted to format === "xml" as the early-return so all JSON paths flow through the same extraction branch.

packages/fmodata/tests/metadata.test.ts (new file)

Five unit tests covering the metadata key resolution:

  • Server returns key without .fmp12 — the primary bug scenario
  • Server returns key with .fmp12 — backward-compat
  • Both keys present — full name wins
  • Neither key present — throws a descriptive error
  • Works with explicit format: 'json' argument

packages/better-auth/package.json

  • Bumped better-auth dependency from ^1.4.11^1.5.4

packages/better-auth/src/adapter.ts

  • Replaced removed createAdapter import with createAdapterFactory from better-auth/adapters

packages/better-auth/src/cli/index.ts

  • Removed call to getAdapter (removed in Better Auth 1.5); replaced with direct factory invocation of config.database (the adapter factory function stored on the config object)
  • Added guard for missing/invalid database factory with a clear error message

packages/better-auth/tests/e2e/adapter.test.ts

  • Updated test utilities to reflect the createAdapterFactory API

Test Plan

  • pnpm --filter @proofkit/fmodata run test — 799 tests pass (5 new)
  • pnpm --filter @proofkit/better-auth run test — 39 tests pass
  • pnpm --filter @proofkit/fmodata run typecheck — no errors
  • pnpm --filter @proofkit/better-auth run typecheck — no errors

Diff Summary

 packages/better-auth/package.json              |   2 +-
 packages/better-auth/src/adapter.ts            |   4 +-
 packages/better-auth/src/cli/index.ts          |  19 +-
 packages/better-auth/tests/e2e/adapter.test.ts |  13 +-
 packages/fmodata/src/client/database.ts        |  19 +-
 packages/fmodata/tests/metadata.test.ts        | 122 +++++++
 pnpm-lock.yaml                                 | 453 ++++++++++++++++++-------
 7 files changed, 485 insertions(+), 147 deletions(-)

Made with Cursor

- Upgrade better-auth from 1.4.11 to 1.5.4
- Replace createAdapter with createAdapterFactory (1.5 breaking change)
- Replace getAdapter with direct adapter resolution in CLI (removed in 1.5)
- Remove runAdapterTest from e2e (better-auth/adapters/test removed in 1.5)
- Restore FMServerConnection import in e2e adapter test

Made-with: Cursor
…tension

FileMaker Server's OData $metadata endpoint returns the database name as
the key without the .fmp12 file extension (e.g. "GMT_Web" instead of
"GMT_Web.fmp12"). The Database.getMetadata() method was looking up
data[this.databaseName] which always failed for databases constructed
with the full filename, causing the migration CLI to throw:

  "Metadata for database "GMT_Web.fmp12" not found in response"

Fix: fall back to the extension-stripped name when the full name is not
found in the response. Full name still takes priority for servers that
may return the key with the extension.

Also corrects a secondary issue where calling getMetadata() without an
explicit format argument (the default JSON path) would skip the JSON
extraction branch entirely, returning the raw wrapper object instead of
the database-scoped metadata.

Adds unit tests covering:
- Server returns key without .fmp12 (the primary bug scenario)
- Server returns key with .fmp12 (backward compat)
- Both keys present - full name wins
- Neither key present - throws descriptive error
- Works with explicit format: 'json' argument

Made-with: Cursor
@vercel
Copy link

vercel bot commented Mar 6, 2026

@chriscors is attempting to deploy a commit to the Proof Geist Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

Open in StackBlitz

@proofkit/better-auth

pnpm add https://pkg.pr.new/proofgeist/proofkit/@proofkit/better-auth@124

@proofkit/cli

pnpm add https://pkg.pr.new/proofgeist/proofkit/@proofkit/cli@124

create-proofkit

pnpm add https://pkg.pr.new/proofgeist/proofkit/create-proofkit@124

@proofkit/fmdapi

pnpm add https://pkg.pr.new/proofgeist/proofkit/@proofkit/fmdapi@124

@proofkit/fmodata

pnpm add https://pkg.pr.new/proofgeist/proofkit/@proofkit/fmodata@124

@proofkit/typegen

pnpm add https://pkg.pr.new/proofgeist/proofkit/@proofkit/typegen@124

@proofkit/webviewer

pnpm add https://pkg.pr.new/proofgeist/proofkit/@proofkit/webviewer@124

commit: dc29d50

eluce2 added 2 commits March 6, 2026 10:14
…es without .fmp12 extension. Upgrade better-auth to 1.5.x, replacing createAdapter with createAdapterFactory and removing getAdapter.
…r result assertions

Updated test assertions in FileMakerAdapter tests to use a more descriptive variable name for the user result, enhancing code readability and maintainability.
@eluce2 eluce2 merged commit a5c9e11 into proofgeist:main Mar 6, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants