Wave 2A: offseason data feeds — news wire + quota-disciplined futures

FREE ESPN news wire + championship-winner futures for the never-dark
offseason hub. Both graceful/empty, never fabricate a market value.

- newsService (mirrors injuryService): per-sport ESPN /news FEEDS, pure
  parseNews → { sport, items:[{id,headline,description,published,type,
  athlete?{name,key},team?,href}] }; athlete/team from categories[] only
  (absent when not present). Cache 15m, injectable, offline-tested.
- oddsNormalizer.normalizeOutrights: NEW branch — outrights outcomes are
  {name,price} with no point, so normalizeProps drops them; keeps them with
  best-price-across-allowed-books per selection. + americanToDecimal.
- oddsService.FUTURES_KEYS: separate map (mlb/nba/wnba championship winner),
  OUT of the daily SPORT_KEYS/snapshot budget.
- futuresService: getFutures(sport,deps) → { sport, updated_at, markets:
  [{key,title,selections:[{name,price,prevPrice?,move?}]}] }. One outrights
  call per 12h TTL (quota-disciplined), FUTURES_ENABLED gate. Price-move
  (shortening/drifting/flat) mirrors computeLineDeltas SHAPE on odds not
  line; prev prices persisted inside the futures:{sport} value (no new key).
  linkNewsToMoves pure causal-tie helper.
- Routes /api/news/:sport + /api/futures/:sport (registered) + Next proxies.
- Tests: newsService, futuresService, oddsNormalizerOutrights (fail→pass,
  no network). Full suite green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kev
2026-07-13 23:33:26 -04:00
parent a4b6255bed
commit f0752b804b
12 changed files with 920 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
/**
* /api/futures/:sport (Wave 2A, D1) — championship/outright futures.
*
* Response contract:
* { sport, updated_at, markets: [{ key, title, selections:
* [{ name, price, prevPrice?, move? }] }] }
* No data / gated-off (FUTURES_ENABLED=0) / quota-skip → { sport, updated_at,
* markets: [] }. Never errors, never fabricates a price.
*
* QUOTA-DISCIPLINED: futuresService fetches at most one odds-api outrights call
* per sport per 12h (default), isolated from the daily player-prop budget.
*/
const express = require('express');
const { createRateLimit } = require('../middleware/rateLimit');
const router = express.Router();
// Public throttle (30/min — futures are cheap to serve from cache).
router.use(createRateLimit({ windowMs: 60_000, max: 30 }));
const MISSION_HEADER = { 'X-VYNDR-Mission': 'The slate is never empty' };
router.get('/:sport', async (req, res) => {
const sport = String(req.params.sport || '').toLowerCase();
try {
const { getFutures } = require('../services/futuresService');
const payload = await getFutures(sport);
res.set('Cache-Control', 'public, max-age=600');
return res.set(MISSION_HEADER).json(payload);
} catch (err) {
console.error('[futures]', err.message);
return res.set(MISSION_HEADER).json({ sport, updated_at: new Date().toISOString(), markets: [] });
}
});
module.exports = router;
+33
View File
@@ -0,0 +1,33 @@
/**
* /api/news/:sport (Wave 2A) — the FREE ESPN news wire. NO odds-api credits.
*
* Response contract:
* { sport, items: [{ id, headline, description, published (ISO), type,
* athlete?: { name, key }, team?: string, href }] }
* Newest first, cap ~25. Empty feed / unknown sport → { sport, items: [] }.
* Never errors.
*/
const express = require('express');
const { createRateLimit } = require('../middleware/rateLimit');
const router = express.Router();
// Public throttle (60/min; ESPN is free but be respectful).
router.use(createRateLimit({ windowMs: 60_000, max: 60 }));
const MISSION_HEADER = { 'X-VYNDR-Mission': 'The slate is never empty' };
router.get('/:sport', async (req, res) => {
const sport = String(req.params.sport || '').toLowerCase();
try {
const { getNews } = require('../services/newsService');
const payload = await getNews(sport);
res.set('Cache-Control', 'public, max-age=600');
return res.set(MISSION_HEADER).json(payload);
} catch (err) {
console.error('[news]', err.message);
return res.set(MISSION_HEADER).json({ sport, items: [] });
}
});
module.exports = router;