Skip to content

feat: make initTokenRefreshLoop expiration-aware - #68

Draft
nicomiguelino wants to merge 2 commits into
mainfrom
feat/expiration-aware-refresh-loop
Draft

feat: make initTokenRefreshLoop expiration-aware#68
nicomiguelino wants to merge 2 commits into
mainfrom
feat/expiration-aware-refresh-loop

Conversation

@nicomiguelino

@nicomiguelino nicomiguelino commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • initTokenRefreshLoop's onRefresh callback can now optionally resolve an { expiresAt } hint, letting the loop schedule the next refresh as a clamped fraction of the token's remaining lifetime instead of a fixed interval.
  • A new options object (maxIntervalSec, minDelaySec, lifetimeFraction) tunes that behavior.
  • Backward compatibility: a callback typed () => Promise<void> (as used unchanged by google-calendar-app, outlook-calendar-app, and airtable-app) still type-checks and behaves byte-for-byte the same — fixed 30-minute interval with the existing exponential back-off — since returning nothing falls back to the old fixed-interval path.
  • Follow-up (not in this PR): migrate the Power BI app's bespoke reimplementation onto this shared function.
  • README updated with an OAuth & Token Refresh section documenting the new options/hint. Version bumped to 1.4.0 (aligned with sibling PR feat: return expiration from getCredentials #67, since we don't know which merges first).

- Let onRefresh optionally resolve an { expiresAt } hint so the loop
  can schedule the next run from the token's remaining lifetime
  instead of a fixed interval
- Add an options object (maxIntervalSec, minDelaySec, lifetimeFraction)
  for tuning the new scheduling behavior
- Fall back to the original fixed 30-minute interval and back-off
  behavior when no hint is returned, keeping existing zero-arg
  callers (Google Calendar, Outlook, Airtable) unchanged
- Add tests covering the fixed-interval path, expiration-aware
  scheduling, hint fallback, and delay clamping
@nicomiguelino nicomiguelino self-assigned this Jul 30, 2026
- Add an OAuth & Token Refresh section to README.md covering
  getCredentials and the new initTokenRefreshLoop options/expiresAt
  hint, with a fixed-interval and an expiration-aware example
- Bump package version to 1.4.0 (minor, additive/backward-compatible
  change), aligned with a sibling PR bumping to the same version
nicomiguelino added a commit that referenced this pull request Jul 30, 2026
- Bump package.json/package-lock.json version from 1.3.0 to 1.4.0
- Shared with sibling PR #68 since it is unclear which of the two additive, backward-compatible changes will merge first
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.

1 participant