feat(core): entitlement state machine + public-render resolver (spec §6) - #17
Merged
Conversation
New packages/core. Pure domain logic - no database, no clock, no I/O.
- transition(status, trigger) encodes the §6.3 table: returns
{ from, to, emits } or throws IllegalTransitionError. Illegal
(status, trigger) pairs are rejected, never silently ignored. Triggers
carry only what the table branches on (trial configured? payment
succeeded? override target). The deliberate emit asymmetries are
preserved: refund -> expired emits only listing.tier_changed;
grace -> expired emits only entitlement.expired (listing already
downgraded); term/cancel -> expired emit both.
- resolvePublicRender(status) encodes the §6.5 table: badge, featured
placement, perk level, owner notice. past_due keeps badge + featured +
full perks; grace/expired drop to rank-0. `none` follows §6.2.
- Emitted-event names are sourced from @osds/adapter-kit
(EntitlementEventType minus renewal_due, plus listing.tier_changed).
Tests (vitest, 157): one per §6.3 row in table order, admin override
from every state, ~12 explicit illegal cases asserting
IllegalTransitionError with from/trigger, a full 8x14 (status x trigger)
matrix asserting every cell is either the expected accept or a reject,
and one per §6.5 row plus `none`.
Removes passWithNoTests from vitest.config.ts now that tests exist, and
excludes **/dist/** so the tsc-emitted *.test.js copies don't double-run.
Closes #9.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Puf9jhj137U3iswf4GWZkG
Signed-off-by: Matthew Wren <info@origindev.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9
New
packages/core— pure domain logic, no database, no clock, no I/O.transition(status, trigger)— §6.3(EntitlementStatus, EntitlementTrigger) → { from, to, emits }, or throwsIllegalTransitionError. Every illegal(status, trigger)pair is rejected, never silently ignored. Triggers carry only what the table branches on — trial configured?, payment succeeded?, override target.The deliberate emit asymmetries in the table are preserved:
active--refund-->expiredlisting.tier_changedonlyentitlement.expiredper §6.3grace--30d-->expiredentitlement.expiredonlygraceactive--term end--> /canceled--period end-->expiredentitlement.expired+listing.tier_changedEmitted-event names are sourced from
@osds/adapter-kit(EntitlementEventTypeminusrenewal_due— a scheduled notice, not a transition — pluslisting.tier_changed).resolvePublicRender(status)— §6.5EntitlementStatus → { badge, featuredPlacement, perks, ownerNotice }.past_duekeeps badge + featured slot + full perks (most failed payments are involuntary);grace/expireddrop to rank-0.nonefollows §6.2 (rank-0, nothing to show).Tests — vitest, 157
IllegalTransitionErrorcarryingfrom/triggernoneConfig
passWithNoTestsremoved fromvitest.config.ts(chore: remove passWithNoTests once real tests exist #9).**/dist/**excluded so thetsc --build*.test.jscopies don't double-run (they did — 4 files / 314 tests before the exclude).tsconfig.jsonreferencespackages/core.pnpm typecheck/lint/testall pass.Note
§6.3 has 16 data rows; the task said 17. I couldn't find a 17th in v0.4 — every row is covered, and I read it as approximate. Flagging in case a row was expected that isn't in the spec.
🤖 Generated with Claude Code