Skip to content

BB-888: feat: add built-in identifier validation with admin dropdown#1273

Open
atharvsp02 wants to merge 1 commit into
metabrainz:masterfrom
atharvsp02:BB-888
Open

BB-888: feat: add built-in identifier validation with admin dropdown#1273
atharvsp02 wants to merge 1 commit into
metabrainz:masterfrom
atharvsp02:BB-888

Conversation

@atharvsp02
Copy link
Copy Markdown
Contributor

@atharvsp02 atharvsp02 commented Mar 23, 2026

Problem

Ticket: BB-888
BookBrainz validates identifiers using only regex, which cannot catch mathematical errors like invalid ISBN checksums. A typo like 9780306406150 (wrong check digit) passes regex validation and gets saved to the database.

Solution

Added support for built-in JavaScript validation functions that run alongside regex:

  • New validation_function column in identifier_type table maps to named JS functions
  • ISBN-10 and ISBN-13 checksum validators implemented as first built-in validators
  • Admin UI gets a dropdown to assign validation functions to identifier types

Adding support for new identifier checksums (like ISSN etc.) just requires writing a validation function in identifier-validators.ts and registering it. Once deployed, admins can assign it to any identifier type through the UI without further code changes.

Areas of Impact

  • identifier-validators.ts - ISBN checksum logic and validator registry
  • common.ts - Calls built-in validator before falling back to regex
  • identifier-type.tsx - Admin dropdown for validation function
  • typeUtils.tsx, types.ts` - Added validationFunction property
  • typeRouteUtils.ts - Server side save/load of new field
  • identifier-types-tree.tsx - Display validation function in type listing
  • bookbrainz.sql - Added column to base schema
  • sql/migrations/2026-03-23/ - Migration for new column
  • I have run the code and manually tested the changes

Screenshots

Before

  • Invalid checksum passes with regex only
image

After

  • Added validation function dropdown to Identifier type editor
image
  • Invalid checksum now correctly rejected
image

AI usage

  • I did not use any AI
  • I have used AI in this PR (add more details below)

If you did use AI:

  • I used AI tools for communication
  • I used AI tools for coding
  • I understand all the changes made in this PR

Action

Run SQL migration

  1. Run SQL migration sql/migrations/2026-03-23/up.sql
  2. Admins can assign validators to ISBN types via the admin UI after deployment

@atharvsp02 atharvsp02 marked this pull request as draft March 23, 2026 18:05
@atharvsp02 atharvsp02 marked this pull request as ready for review March 23, 2026 18:40
@atharvsp02 atharvsp02 marked this pull request as draft March 24, 2026 17:19
@atharvsp02 atharvsp02 marked this pull request as ready for review March 25, 2026 19:52
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