Skip to content

Add deterministic EZID DOI naming - #112

Merged
neuromechanist merged 4 commits into
devfrom
111-deterministic-ezid-doi-naming-dataset-based-identifiers
Feb 11, 2026
Merged

neuromechanist merged 4 commits into
devfrom
111-deterministic-ezid-doi-naming-dataset-based-identifiers

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

  • Add createIdentifier() to EZID service using PUT /id/{identifier} for exact DOI names
  • Add buildConceptIdentifier() and buildVersionIdentifier() helpers for deterministic DOI naming
  • Refactor createEzidConceptDoi and createEzidVersionDoi to eliminate placeholder-then-update pattern

Naming convention:

  • Concept: doi:10.82901/NEMAR.NM000104
  • Version: doi:10.82901/NEMAR.NM000104.V1.0.0
  • Sandbox: doi:10.5072/FK2NM099999

Test plan

  • Unit tests for buildConceptIdentifier (production + sandbox)
  • Unit tests for buildVersionIdentifier (production + sandbox + pre-release)
  • Existing credential-rejection tests still pass
  • Sandbox integration tests for createIdentifier (deterministic naming, collision detection, version DOI)
  • All 313 tests pass (bun test)
  • Run sandbox tests: RUN_EZID_TESTS=true bun test test/ezid-sandbox.test.ts

Closes #111

Use createIdentifier (PUT /id/) instead of mintIdentifier (POST
/shoulder/) for predictable DOI names based on dataset IDs.

Concept: doi:10.82901/NEMAR.NM000104
Version: doi:10.82901/NEMAR.NM000104.V1.0.0

Eliminates the placeholder-then-update two-step pattern.

Closes #111
- Add idempotency handling to createEzidConceptDoi (catch
  "already exists" and fallback to getIdentifier)
- Capture createIdentifier return value in createEzidVersionDoi
- Extract resolveShoulder helper, simplify ezidRequest body param
- resolveEzidAuth now throws when sandbox=true but sandbox
  credentials are missing, instead of silently using production
- Log unknown doi_provider values before falling back to default
- Wrap webhook JSON parse in try-catch (return 400 on malformed)
- Separate DB writes from DOI publication (non-fatal after public)
- Surface BIDS metadata, DB, and concept DOI update failures in
  webhook response instead of swallowing silently
- Add response.text() error context in ezidRequest
- Log warnings for unknown EZID status values and percent-decode
  fallbacks
- Add warnings field to DoiResult for partial failure visibility
@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review Summary

Ran comprehensive review with 6 specialized agents (code-reviewer, silent-failure-hunter, test-coverage-analyzer, type-design-analyzer, code-simplifier, comment-analyzer). All findings addressed.

Critical Issues Fixed (3)

  1. Sandbox-to-production credential fallthrough (silent-failure-hunter): resolveEzidAuth silently fell through to production credentials when sandbox credentials were missing. Now throws explicitly when sandbox=true but sandbox creds are absent. Prevents accidental permanent production DOI minting during testing.

  2. Unguarded JSON parse in webhook (silent-failure-hunter): c.req.json() was not wrapped in try-catch. Malformed requests caused cryptic 500 errors. Now returns 400 with clear message.

  3. DB writes after permanent DOI publication (silent-failure-hunter): Database updates happened inside the same try-catch as DOI minting. If DB failed after DOI was already public (permanent), the response said "Failed to publish DOI" -- misleading since the DOI WAS published. Now DB failures are caught separately and surfaced as db_error in the response.

Important Issues Fixed (5)

  1. Idempotency handling (code-reviewer): createEzidConceptDoi now catches "already exists" errors and falls back to getIdentifier. Safe to retry after network timeouts.

  2. Discarded return value (code-reviewer): createEzidVersionDoi now captures createIdentifier return value and uses the normalized identifier from EZID for makePublic.

  3. BIDS metadata fallback invisible (silent-failure-hunter): When BIDS metadata read fails, the DOI gets minimal metadata. Now surfaces bids_metadata_warning in the webhook response.

  4. Concept DOI update failure swallowed (silent-failure-hunter): Version DOI createEzidVersionDoi catches concept DOI update errors but only logged to console. Now propagates via warnings field on DoiResult, surfaced as doi_warnings in webhook response.

  5. Unknown provider silent fallback (silent-failure-hunter): parseDoiProvider now logs console.error when encountering unexpected doi_provider values before falling back.

Medium Issues Fixed (3)

  1. response.text() outside try-catch in ezidRequest: Now wrapped with EZID-contextualized error message.
  2. percentDecode silent fallback: Now logs console.warn when decodeURIComponent fails.
  3. Unknown EZID status cast: parseEzidStatus now warns when encountering unrecognized status values.

Simplifications Applied (code-simplifier)

  • Extracted resolveShoulder() helper (DRY for concept/version identifier builders)
  • Removed redundant body !== undefined ? body : undefined ternary in ezidRequest

Test Coverage

313 tests pass, 0 failures. Test coverage analyzer confirmed no critical gaps; pure functions (buildConceptIdentifier, buildVersionIdentifier) and sandbox integration tests (createIdentifier) are well-covered.

@neuromechanist
neuromechanist merged commit ab48b0e into dev Feb 11, 2026
7 checks passed
@neuromechanist
neuromechanist deleted the 111-deterministic-ezid-doi-naming-dataset-based-identifiers branch February 11, 2026 08:19
@neuromechanist neuromechanist mentioned this pull request Feb 11, 2026
2 of 5 tasks
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.

1 participant