flybrain/services/bridge/src
acamilo d06e1cf809 bridge: refresh stored tokens on load before giving up, persist both roles
A stored access token that has expired (obtainmentTimestamp + expiresIn) or
that validate rejects with 401 is now refreshed once through its role's
RefreshingAuthProvider before startup fails, for the bot and broadcaster
roles alike. Refreshes are persisted under the role whose provider made
them (no more scope-set guessing), through one serialized writer, so both
roles reach tokens.json even when they are one account; writes stay
tmp + rename, 0600.

Only a refresh Twitch refuses (4xx, e.g. 400 Invalid refresh token) is
fatal, with one line naming the role and the runbook's re-authorize step.
Twitch errors are logged by status and message only: twurple's
HttpStatusCodeError message carries the refresh grant URL, client secret
and refresh token included, so the entrypoint and EventSub log lines now
redact it.

Tests mock Twitch's validate and token endpoints. Runbook and B1 updated.
2026-09-28 23:47:48 +00:00
..
atomic-file.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
auth.ts bridge: refresh stored tokens on load before giving up, persist both roles 2026-09-28 23:47:48 +00:00
chat.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
commands.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
config.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
duration.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
eventsub.ts bridge: refresh stored tokens on load before giving up, persist both roles 2026-09-28 23:47:48 +00:00
explainer.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
health.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
index.ts bridge: refresh stored tokens on load before giving up, persist both roles 2026-09-28 23:47:48 +00:00
names.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
notice.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
onscreen-chat.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
predictions.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
ratelimit.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
redact.ts bridge: refresh stored tokens on load before giving up, persist both roles 2026-09-28 23:47:48 +00:00
redemptions.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
scopes.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
sim.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
subscription-health.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00
templates.ts flybrain v0.4.0: public tree (history retained privately) 2026-09-21 15:09:46 +00:00