Home

boring / v2

publicBoring-Software-Inc/v2
Overview Code History Branches Pull requestsIssuesInsights Campfire Docs
main
HomeOverview Code PRsIssues

TRP-83 feat(economics): billed-vs-actual sparkline thumbnail on the digest

3 months ago

6ba3a58
Authored
grim7/26/2026, 3:10:53 AM
Adds a generated spend-trend chart to the digest embed's thumbnail: the last
14 days of billed (blurple) vs actual (yellow) as overlaid sparklines, so a
reader sees at a glance whether today's drift is a blip or a trend.

Built without any image dependency and without our spend figures leaving our
infra:
- sparkline-png.ts (@tripwire/utils): a dependency-free PNG encoder (hand-
  assembled chunks + CRC32, IDAT via node:zlib) and a pixel-plotted sparkline
  renderer. Pure, unit-tested by parsing the PNG back (signature, IHDR dims,
  chunk order).
- guardedPostMultipart (@tripwire/utils): posts multipart/form-data through
  the SAME SSRF guard as guardedPost. Extracted guardedResolve so the guard is
  single-sourced; the existing guard test suite still passes unchanged.
- getRecentDailyCosts (@tripwire/db): the 14-day billed/actual range query.
- economicsDigest attaches the PNG as files[0] and points the embed thumbnail
  at attachment://econ.png; a day with no invoice yet falls back to its billed
  figure so the actual line stays continuous. Under two points, no chart and
  the embed posts as plain JSON. dry-run prints the payload and the attachment.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Parentd22742f

9 files changed
  • apps/worker/src/economics-trigger.ts+22−0
  • apps/worker/src/jobs/economics-digest.test.ts+31−1
  • apps/worker/src/jobs/economics-digest.ts+71−3
  • packages/db/src/index.ts+1−0
  • packages/db/src/services/economics.ts+40−0
  • packages/utils/src/guarded-fetch.ts+116−37
  • packages/utils/src/index.ts+8−0
  • packages/utils/src/sparkline-png.test.ts
+73
−0
  • packages/utils/src/sparkline-png.ts+198−0