feat: add createAccess, error classes, and override layer#3
Merged
Conversation
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.
What
Implements the full runtime access API: error classes, override application, and
createAccess.New files:
src/errors.ts—AccessDeniedError(carriesfeature,plan,requiredPlans: string[]) andInvalidOverrideError(carriesreason: 'unknown_feature' | 'grant_revoke_conflict',feature). Both extendError, set prototype correctly for cross-moduleinstanceof, and implementtoJSON()returning JSON-serializable plain objects.src/overrides.ts—applyOverrides(config, resolved, overrides)validates all features ingrant/revokeare declared, throws ongrant ∩ revokeconflicts, then returns a new effectiveResolvedPlan.src/access.ts—createAccess(config, { plan, overrides? })returning{ can, cannot, guard, diff }.guardthrowsAccessDeniedErrorwithrequiredPlanscomputed as all plans whose resolved feature set includes the featurediff(targetPlan)returns{ gains: string[], limitUpgrades: Record<string, { from, to }> }against the effective (post-override) setrequiredPlansUpdated:
src/index.ts— exports all public symbols:createAccess,defineConfig,AccessDeniedError,InvalidOverrideError, and all typessrc/index.test.ts— verifies the full export surfaceTests (74 total, 100% coverage):
src/errors.test.ts— 10 tests: instanceof, metadata fields, message content, toJSON shape, JSON round-tripsrc/overrides.test.ts— 11 tests: grant adds feature, grant idempotent, unknown grant throws, revoke removes feature, revoke beats inheritance, unknown revoke throws, grant∩revoke conflict throws with correct reason, empty overrides, limits preservedsrc/access.test.ts— 28 tests: can/cannot, guard happy/sad path, requiredPlans enumeration, multi-plan requiredPlans, JSON serialization, grant/revoke overrides, conflict, diff gains/exclusions, limitUpgrades including asymmetric keys and null-quota, broken plan graceful handlingWhy
Implements v1 scope items 2, 3, and 4: the
createAccessfeature gate API, the override layer, and the structured error classes with their specified field shapes and JSON serializability guarantee.How to verify
Out of scope
overrides.limitsruntime API — deferred to v1.1createUsage/ usage tracking — explicitly out of v1 scope