Skip to content

refactor(auth): consolidate attacher context types onto a shared base#48

Merged
scottlovegrove merged 2 commits into
mainfrom
refactor/auth-attacher-context-base
May 23, 2026
Merged

refactor(auth): consolidate attacher context types onto a shared base#48
scottlovegrove merged 2 commits into
mainfrom
refactor/auth-attacher-context-base

Conversation

@scottlovegrove
Copy link
Copy Markdown
Collaborator

@scottlovegrove scottlovegrove commented May 23, 2026

Summary

Several auth attacher context types re-typed the same view: Required<ViewOptions> + flags: Record<string, unknown> pair, copy-pasting the identical view JSDoc ~11 times. The account attachers shipped in #45/#46 each added another bespoke ctx repeating it.

  • Add internal AttachContextBase (the view + flags pair, with the previously copy-pasted view JSDoc in one place) and WithAccount<TAccount> to src/auth/types.ts. Not re-exported from src/auth/index.ts — they have no consumer-facing use, so the named ctx types stay the only public API.
  • Derive the 7 named ctx types (AttachLoginContext, AttachLogoutContext, AttachLogoutRevokeContext, AttachStatusContext, AttachAccountList/Current/RemoveContext) and the 4 inline callback ctxs that carry view+flags (status fetchLive/onNotAuthenticated, account onDefaultSet/current onNotAuthenticated) from the base. Flags-only ctxs (renderJson, login resolveScopes) left as-is.

Pure type-alias refactor: structural shapes are byte-for-byte identical, so the public API surface, README, and runtime behaviour are unchanged (net −20 LOC).

Test plan

  • npm run type-check — clean (the real proof shapes are preserved: attach-fn bodies + re-export chain still typecheck)
  • npm test — 498 passed
  • npm run check — oxlint + oxfmt clean on src/

The seven exported auth attacher context types plus several inline
callback ctxs each re-typed the same `view: Required<ViewOptions>` +
`flags: Record<string, unknown>` pair, copy-pasting the identical `view`
JSDoc ~11 times. Introduce internal `AttachContextBase` and
`WithAccount<TAccount>` aliases in `types.ts` (not re-exported) and
derive the named + view-bearing inline ctxs from them.

Pure type-alias refactor: structural shapes are byte-for-byte identical,
so the public API surface, README, and runtime behaviour are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@doistbot doistbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR nicely addresses the roadmap item by consolidating the auth attacher context types onto a shared base, reducing duplication across the module. The structural refactor effectively streamlines the codebase while preserving the public API surface and runtime behavior. A few minor details could be smoothed out, specifically restoring some context-specific JSDoc comments that were dropped during the consolidation, applying the newly added WithAccount helper more consistently, and removing a comment that merely restates the code.

Share FeedbackReview Logs

Comment thread src/auth/types.ts Outdated
Comment thread src/auth/account.ts Outdated
Comment thread src/auth/login.ts
Comment thread src/auth/status.ts Outdated
Restore the login flags-stripping invariant and the remove-ctx account
doc that the base-type rebase had dropped, reuse WithAccount in the
status fetchLive ctx, and drop the WithAccount alias comment that
restated the code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove merged commit 2400072 into main May 23, 2026
4 checks passed
@scottlovegrove scottlovegrove deleted the refactor/auth-attacher-context-base branch May 23, 2026 19:05
@doist-release-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.24.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants