Skip to content

feat: package model in the commons API - #151

Closed
jzongker wants to merge 1 commit into
mainfrom
feat/commons-package-model
Closed

feat: package model in the commons API#151
jzongker wants to merge 1 commit into
mainfrom
feat/commons-package-model

Conversation

@jzongker

@jzongker jzongker commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Package model for commons songs: migration 2026-09-07_package_model adds confidence, firstLine, tune, hasChords, rights, form, recommendedKey, recommendedKeyReason, publishedKeys, singTimeSeconds, scoreSource, listenedKeys, sundayReadyBy, sundayReadyAt to songs.
  • Seed (tools/commons-seed/catalog.ts) now resolves each row's package dir (from its paths, or by id when every path points at a work), reads masters/song.json for rights/form/meter and derivatives/duration.json for sing time, marks scoreSource: "abc" when a score.musicxml is served (own or inherited from the work, the way abcUrl already resolves), and copies score.musicxml, slides.json, chart.chordpro, chart.pdf, attribution.txt, duration.json, cover-thumb.webp flat into assets/song/{id}/. tools/manual/commons-sync-catalog.ts (previously untracked) is committed with the new columns in its --update set.
  • GET /commons/songs rows add confidence, sundayReady, featured, firstLine, tune, hasChords, hasScore, hasSlides, hasTiming, hasAccompaniment (false), recommendedKey, singTimeSeconds; query params sundayReady=true, confidence=, language=, q= (title / first line / writer). rank ordering and every existing key kept; reviewer-only fields still never leave.
  • GET /commons/songs/:id adds rights, rightsMatrix, ccliReport, attribution, form, publishedKeys, recommendedKeyReason, scoreSource, contributors, sundayReadyAt, sundayReadyBy, listenedKeys and the fileUrls roles score, slides, chart, chartPdf, attribution, thumb, duration. fileRole() lives in @churchapps/helpers, so the new names are mapped in ContentLibraryHelper.role() (the manifest hook uses it too); lyrics.chordpro still maps to chart and wins over chart.chordpro when both are served.
  • New GET /commons/songs/:id/page{ song, rating: { average, count, mine }, history, family, similar }; mine only with a user JWT. Similar: same language, not family, +2 meter, +2 scripture book, +1 per shared theme, top 6 with a one-sentence reason.
  • helpers/RightsHelper.ts: matrixForLicense, composeMatrix, ccliReport per the contract table (mirrors the site's src/rights.ts).
  • Publish hook computes confidence / firstLine / hasChords / rights / form / publishedKeys on approve, keeps sunday-ready unless lyrics or score files changed (then clears the listen record). song.json.status is written from the asset status, never the literal.
  • POST /commons/admin/songs/:id/listen { keys } records the listen gate; sunday-ready when the keys cover publishedKeys and the package serves score + chords + slides; { keys: [] } clears. Reviewer check lives in one place: helpers/ReviewAccess.ts canReview(au).
  • src/modules/commons/README.md documents the model, the /page endpoint and the query params.

Test plan

  • yarn jest src/modules/commons — 20 suites, 190 tests pass (new: RightsHelper, SeedCatalog against __tests__/fixtures/package-repo, SongPackageHelper, SongPage, ListenGate, SongPublishHook; ContentLibraryHelper gained fileUrls-role and song.json-status cases)
  • yarn tsc --noEmit clean; yarn eslint --fix src/modules/commons clean
  • e2e runs in the batch integration pass (site + B1Admin consume this contract); yarn reset-commons against a local MySQL to exercise the migration + seed

Cross-repo

Depends on / pairs with: WorshipCommons feat/site-package-contract (consumer); B1Admin package-model job (consumer). The submission-types branch adds songs.contributorscontributors reads [] until that column exists.
Migration: required on staging/prod (2026-09-07_package_model), then commons-sync-catalog.ts --update to fill the new columns for existing rows.

Left out

  • Public-API versioning (/v1) — deliberately skipped; routes stay /commons/....
  • recommendedKey / recommendedKeyReason are stored and served but never computed (contract marks it optional; no MIDI melody-range fit here) — null today.
  • Music-editor reviewers (COMMONS_MUSIC_EDITORS) — canReview() is the single swap point for the branch that adds them.
  • tune is reserved and always null.

Adds the package-model columns to songs (confidence tier, first line, rights
and form maps, sing time, score source, listen-gate record), seeds them from
the content repo packages (masters/song.json, derivatives/*, work inheritance),
and recomputes them in the song publish hook. GET /commons/songs rows gain
confidence/sundayReady/featured/has* flags and the sundayReady/confidence/
language/q filters; the detail adds rights, rightsMatrix, ccliReport,
attribution, form, publishedKeys, contributors and the new fileUrls roles.
New GET /commons/songs/:id/page bundles song + rating + history + family +
similar, and POST /commons/admin/songs/:id/listen records the listen gate.

Tests: RightsHelper table, seed reader against a fixture package repo,
package shaping, /page shape, listen-gate transitions, publish hook fields.
@jzongker

jzongker commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #153 (squash-merged integration of #149 #150 #151 #152, tested together).

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