Compose StackTokenStore explicitly instead of sniffing token methods off the adapter - #62
Merged
Merged
Conversation
…off the adapter Auth middleware and the /tokens routes now go through ctx.tokens, a NativeTokenStore opened at stack.db.tokens and typed against core's StackTokenStore interface, rather than calling LocalAdapter's createToken/lookupToken/listTokens/revokeToken convenience methods directly. TokenInfo now imports from @haverstack/core/wire. This was already the last unaddressed item under #43 now that the adapter swap and tokens-out-of-stack-file goals arrived for free with the native SQLite adapter — deployment docs get a note on backing up stack.db.tokens separately from "export your data" flows.
5 tasks
6 tasks
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.
Summary
Closes out the last open item under #43: the adapter swap and "tokens out of the portable stack file" goals already landed for free with the native SQLite adapter (
adapter-local@0.7.0composesrecord-adapter-sqlite'sNativeTokenStorein a sibling<path>.tokensfile), but the server was still going throughLocalAdapter's token convenience methods rather than typing against@haverstack/core'sStackTokenStoreinterface directly.src/stack.ts—StackContextnow composes{ adapter, stack, tokens }explicitly.tokensis aNativeTokenStoreopened atstack.db.tokens, typed asStackTokenStore & { close(): Promise<void> }(the interface everywhere except the one lifecycle hook every implementation needs but the interface doesn't declare).src/middleware/auth.ts— looks up sessions viactx.tokens.lookupToken()instead ofctx.adapter.lookupToken().src/routes/tokens.ts— issues/lists/revokes viactx.tokens;TokenInfonow imports from@haverstack/core/wireinstead of@haverstack/adapter-local.src/index.ts/tests/setup.ts— close the token store on shutdown/cleanup alongside the stack.docs/deployment.md— notes thatstack.db.tokensbelongs in operational backups but must be excluded from any "export your data" / stack-sharing flow, since restoring one should never resurrect a revoked token.Other #43 items, verified rather than changed
node:sqlite, FTS5, WAL sidecars and double-open protection are all in place and documented.PRAGMA foreign_keys/deleteAttachmentrace-test follow-up: turns out to already be resolved upstream.Stack.deleteAttachment()only takes the non-atomic fallback path (racing a concurrentassociate()) when the adapter lacksdeleteUnreferencedAttachmentRecords().LocalAdapterimplements it (backed byNativeSQLiteRecordAdapter), so the atomic path is what actually runs — no server-side test or code change needed, same "arrives free" pattern as Upgrade to the coordinated core release: one copy of core, delete superseded route guards, rewrite the tests that assert old behaviour #51's guard removals.Test plan
pnpm typecheckpnpm lintpnpm format:checkpnpm buildpnpm test— 115 tests passingCloses #43.
https://claude.ai/code/session_018wnXZRudrMTCfubDJkkHSA
Generated by Claude Code