feat(providers): add provider token expiry watchdog - #532
Merged
Pidoko257 merged 1 commit intoAug 27, 2026
Conversation
Provider authentication could silently break before service interruption: the uptime watchdog counts any HTTP <500 (including 401/403) as healthy, and a dead Xero/QuickBooks refresh token only surfaced when the scheduled refresh permanently failed. Add a scheduled provider-token-watchdog job that: - probes MTN/Airtel/Orange auth endpoints with real credentials and pages a CRITICAL PagerDuty incident when they are rejected (401/403), auto-resolving once credentials are accepted again; - detects expired accounting access tokens, attempts one auto-heal refresh, and pages for manual re-authorization when the refresh token has been revoked or expired; - warns via webhook when accounting refresh tokens approach the provider inactivity window (Xero 60d / QuickBooks 100d) before they die. New providers get a public checkAuth() used by the watchdog; env vars (PROVIDER_TOKEN_WATCHDOG_CRON, PROVIDER_TOKEN_ALERT_WEBHOOK_URL, PROVIDER_TOKEN_STALE_REALERT_HOURS) and the provider-down runbook are updated. Includes unit tests for the watchdog and checkAuth, plus fixes stale MTN requestPayment assertions (providerResponseTimeMs). Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@Prasiejames Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #434
Closes #435
Closes #438
Closes #441
Description
Provider authentication was effectively refreshed manually — the uptime watchdog counts any HTTP <500 (including 401/403) as "up", so expired/revoked credentials only surfaced once real transactions started failing. Accounting OAuth refresh tokens (Xero 60-day / QuickBooks 100-day inactivity expiry) could also die silently, leaving connections dead until a human re-authorized.
This PR adds a scheduled provider token watchdog (
provider-token-watchdogcron job, every 5 minutes) that detects these conditions before service interruption:Mobile money (MTN / Airtel / Orange)
checkAuth()on each provider.Accounting (Xero / QuickBooks)
PROVIDER_TOKEN_ALERT_WEBHOOK_URL/SLACK_ALERTS_WEBHOOK_URL), re-alerted at most once perPROVIDER_TOKEN_STALE_REALERT_HOURS.New environment variables
PROVIDER_TOKEN_WATCHDOG_CRON*/5 * * * *PROVIDER_TOKEN_ALERT_WEBHOOK_URLPROVIDER_TOKEN_STALE_REALERT_HOURS24Type of Change
How Has This Been Tested?
tests/jobs/providerTokenWatchdog.test.ts(13 tests) — credential probes, PagerDuty trigger/resolve/dedup, accounting auto-heal, re-authorization paging, and stale-token webhook warnings.checkAuth()unit tests for MTN, Airtel, and Orange providers (success, 401/403 classification, network errors not flagged).requestPaymentassertions (missingproviderResponseTimeMs) — these were already failing onmain.npx tsc --noEmit: clean for all changed files (the repo has a pre-existing broken filesrc/stellar/sep02.ts).npx eslinton changed files: 0 errors (only pre-existing warnings).Checklist
.env.example,docs/runbooks/01-provider-down.md)