Repository navigation
fix: accept numeric-string OAuth lifetime fields so refresh stops running every poll (#178) - #182
Merged
Merged
Conversation
…ning every poll (#178) BLUETTI's OAuth responses deliver the numeric fields (notably expires_in) as strings. normalizeToken() only accepted `typeof === "number"`, so the string was dropped (and leaked unnormalized through the object spread), no created_at was stamped, no expiry could be derived and isNearExpiry() stayed true -- forcing a token refresh on every poll and defeating the #46 fix. Coerce numeric strings for expires_at/expires_in/created_at via a setFiniteNumber() helper that also clears non-finite values so the raw string cannot survive serialization. No fallback lifetime is introduced. Adds regression tests for a string-typed expires_in (no refresh across several polls) and for a non-numeric expires_in being dropped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Percy2Live
force-pushed
the
fix/178-string-expires-in
branch
from
September 28, 2026 22:06
5d222d3 to
24e1295
Compare
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.
Problem (issue #178, point 1)
The reporter confirmed on 1.0.1 that
auth.tokenJsonafter a successful poll containsexpires_inas a string ("3600"), with nocreated_at/expires_at.normalizeToken()inbluetti-stored-token-provider.jsonly accepted the numeric OAuth fields whentypeof value.<field> === "number". A stringexpires_inwas therefore:...valuespread unnormalized, andcreated_at(the Token expiry not parsed from BLUETTI response → refresh runs on every poll #46 receipt-time stamp also requirestypeof token.expires_in === "number").Result: no expiry is computable →
isNearExpiry()defaults totrue→ a token refresh runs on every poll, defeating the #46 fix.Fix
setFiniteNumber()helper coerces numeric strings forexpires_at/expires_in/created_at, and deletes the key when the value is non-finite so the raw string can't leak through the spread into serialization.created_atstamp now fires for the real BLUETTI shape.Tests
expires_inas a numeric string → token reused across several polls, zero refreshes.expires_in→ dropped, not serialized, no boguscreated_at.npm run checkgreen, full token-provider suite passing.Closes #178.