Skip to content

fix: accept numeric-string OAuth lifetime fields so refresh stops running every poll (#178) - #182

Merged
Percy2Live merged 1 commit into
mainfrom
fix/178-string-expires-in
Sep 28, 2026
Merged

Percy2Live merged 1 commit into
mainfrom
fix/178-string-expires-in

Conversation

@Percy2Live

Copy link
Copy Markdown
Owner

Problem (issue #178, point 1)

The reporter confirmed on 1.0.1 that auth.tokenJson after a successful poll contains expires_in as a string ("3600"), with no created_at/expires_at.

normalizeToken() in bluetti-stored-token-provider.js only accepted the numeric OAuth fields when typeof value.<field> === "number". A string expires_in was therefore:

Result: no expiry is computable → isNearExpiry() defaults to true → a token refresh runs on every poll, defeating the #46 fix.

Fix

  • New setFiniteNumber() helper coerces numeric strings for expires_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.
  • No fallback lifetime — matches the reporter's recommendation; the receipt-time created_at stamp now fires for the real BLUETTI shape.

Tests

  • expires_in as a numeric string → token reused across several polls, zero refreshes.
  • non-numeric expires_in → dropped, not serialized, no bogus created_at.

npm run check green, full token-provider suite passing.

Closes #178.

…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
Percy2Live force-pushed the fix/178-string-expires-in branch from 5d222d3 to 24e1295 Compare September 28, 2026 22:06
@Percy2Live
Percy2Live merged commit 77e1557 into main Sep 28, 2026
12 checks passed
@Percy2Live
Percy2Live deleted the fix/178-string-expires-in branch September 28, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Access token is refreshed on every poll again (cf. #46); a failed refresh stops telemetry for 75 minutes

1 participant