Skip to content

feat(types): fix DriverAnalytics shape + add TireHealthSnapshot/WinProb/LTOE types + simulate pause/resume - #1

Closed
jlazar wants to merge 6 commits into
mainfrom
feature/types-analytics-simulate-pause-resume
Closed

feat(types): fix DriverAnalytics shape + add TireHealthSnapshot/WinProb/LTOE types + simulate pause/resume#1
jlazar wants to merge 6 commits into
mainfrom
feature/types-analytics-simulate-pause-resume

Conversation

@jlazar

@jlazar jlazar commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix DriverAnalytics type to match live Analytics-tier API output

    • tireHealth was number; the API sends a full TireHealthSnapshot object (12 fields)
    • degRateSecPerLap, cliffLapPredicted, cliffRisk were top-level; they live inside tireHealth
    • fuelCorrectedTimeSec typed but absent from the API
    • Missing fields added: overtakeProbability, winProbability (full snapshot), undercutThreat, ltoe, ltoeConfidenceFlag, regulationsEra
  • New exported types matching backend analytics types:

    • TireHealthSnapshot, WinProbabilitySnapshot, LTOESnapshot, UndercutThreatSnapshot
    • CliffRisk, DegMode, HealthLabel string literal unions
  • Add simulate.pause() and simulate.resume() — maps to POST /simulate/:id/pause and POST /simulate/:id/resume

Test plan

  • npm run typecheck — clean
  • npm test — 66 tests pass (19 new in types.test.ts, 8 new in simulate.test.ts, 44 existing webhook tests unchanged)
  • npm run build — clean (ESM + CJS + DTS)

🤖 Generated with Claude Code

jlazar and others added 6 commits June 7, 2026 15:09
- verifySignature now throws typed errors (WebhookSignatureError / WebhookTimestampError) instead of returning bool
- Add verifySignatureBoolean for backward-compatible non-throwing usage
- Add signPayload, SIGNATURE_HEADER, TIMESTAMP_HEADER constants
- Add constructEvent(), safeConstructEvent() helpers
- Add webhookHandler() Express/Fastify/plain-http middleware
- Extend RaceHooksConfig with secret and toleranceSeconds options
- RaceHooks class gains constructEvent, safeConstructEvent, webhookHandler methods
- 44 Jest tests covering all new paths
- CI workflow updated to run tests before build

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- http.ts: only send Content-Type: application/json when a body is present (fixes RFC 9110
  violation on GET/DELETE — sending Content-Type with no body breaks strict servers)
- verify.ts: export headerValue so webhook-middleware.ts can import it instead of
  re-declaring an identical copy (DRY)
- webhook-middleware.ts: remove duplicate headerValue, import from verify.ts
- webhook-middleware.ts: resolveRawBody now skips empty rawBody (length 0) rather than
  passing "" to verifySignature, which would produce a confusing signature-mismatch
  error instead of falling through to the stream-read path
- verify.ts: secureCompare runs timingSafeEqual even when buffer lengths differ, so
  signature comparisons are constant-time regardless of the submitted signature length

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- WebhookPayload.type renamed to .feed across types, middleware, client, and tests
- SubscriptionTier updated to "free" | "live" | "analytics" (starter→live, pro dropped)
- Add DriverRef, DriverAnalytics, and drivers[] to WebhookPayload; data becomes optional
- Add driverIds to WebhookFilters

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…re usage, and domain

- README JSON example: `type` → `feed` (field was renamed)
- Signature example: `verifySignature` → `verifySignatureBoolean` — the throwing
  variant doesn't return a boolean, so the `if (!...)` guard was always wrong
- Analytics section: replace old `payload.analytics?.[driverNumber]` map access
  with current inline `payload.drivers[].analytics` shape
- package.json homepage: `racehooks-ai.com` → `racehooks.io`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…te pause/resume

DriverAnalytics was typed incorrectly — tireHealth was number but the API
sends a full TireHealthSnapshot object; degRateSecPerLap/cliffLapPredicted/
cliffRisk were top-level but live inside tireHealth; fuelCorrectedTimeSec
was present but absent from the API. Adds missing fields: overtakeProbability,
winProbability (WinProbabilitySnapshot), undercutThreat, ltoe (LTOESnapshot),
ltoeConfidenceFlag, regulationsEra.

Also adds TireHealthSnapshot, WinProbabilitySnapshot, LTOESnapshot,
UndercutThreatSnapshot, CliffRisk, DegMode, HealthLabel as exported types.

Adds simulate.pause() and simulate.resume() matching the API's
POST /simulate/:id/pause and POST /simulate/:id/resume endpoints.

Tests: types.test.ts (19 new tests) and simulate.test.ts (8 new tests).
All 66 tests pass, typecheck clean, build clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Exposes the SC/VSC split fields added in the API Analytics tier payload.
safetyCarProbability is kept for backward compatibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jlazar jlazar closed this Jun 23, 2026
@jlazar
jlazar deleted the feature/types-analytics-simulate-pause-resume branch June 23, 2026 02:50
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