diff --git a/BUILD-STATE.md b/BUILD-STATE.md index 9c94709..5212d7b 100755 --- a/BUILD-STATE.md +++ b/BUILD-STATE.md @@ -4,6 +4,71 @@ 2026-06-12 ## Current Phase +SHIP BUILD v28.0 — Parlay builder, line-movement tracking, book comparison (Session 28) + +## Session 28 (2026-06-13) — SHIPPED + +The three features every competitor has: parlay building, line movement, +book comparison. All zero-credit (pure math / Redis snapshots / cached +odds). Reused existing primitives heavily (payoutCalculator, the existing +ParlayTray/ParlayContext frontend). + +Backend 1584 → **1623 tests** (+39), 130 suites, zero regressions. Web +build clean. + +### PHASE 1-2 — Parlay builder +- `parlayService.js` — combined American/decimal odds (reuses + payoutCalculator), confidence-weighted combined grade, correlation + detection via an interaction matrix (same-game teammates = positive, + opposing rebounds = negative, cross-game = independent), kill-condition + aggregation, and `suggestParlays` (greedy, conflict-avoiding). +- `POST /api/parlay/calculate` + `/suggestions`. Frontend parlay builder + already existed (ParlayTray + ParlayContext → /api/scan/parlay grading); + left intact. Added the calculate proxy for the lightweight path. +- 15 unit + 3 route tests. + +### PHASE 3-4 — Line movement +- `lineSnapshotService.js` — Redis-only rolling history + (`linehistory:{sport}:{gameId}:{player}:{stat}`, cap 100, 48h TTL), + `classifyMovement` (stable/rising/dropping + sharp signal ≥1.5 pts), + `getBiggestMovers` (scan + classify + sort by |delta|). Complements the + existing Supabase-backed lineMovementService rather than replacing it. +- Wired `recordSnapshots` into oddsService's existing best-effort block. +- `GET /api/lines/:sport/movers` + per-prop history. +- Frontend: `LineMovementChart` (dependency-free SVG sparkline) + + `MoversPanel` (mounted in the Slate, self-hiding, tier-gated). +- 9 unit + 2 route tests. + +### PHASE 5-6 — Book comparison +- `bookComparisonService.js` — best line per side (highest decimal + payout), savings vs field average per $100, over the grouped odds + `lines[]`. `GET /api/books/:sport` (best lines) + per-prop grid, reading + CACHED odds props (zero credits). +- Frontend: `BookComparison` (book grid, BEST badge) + `BestLinesPanel` + (mounted in the Slate, self-hiding, tier-gated). +- 7 unit + 3 route tests. + +### PHASE 7 — Wiring +- Mounted /api/parlay, /api/lines, /api/books in app.js. +- Next proxies: `parlay/calculate/route.ts` (explicit, avoids catch-all + conflict with existing grade/add-leg), `lines/[...path]`, `books/[...path]`. +- MoversPanel + BestLinesPanel added to the Slate below streaks/hot lists. + +### Files created +- `src/services/parlayService.js`, `src/routes/parlay.js` +- `src/services/lineSnapshotService.js`, `src/routes/lineMovement.js` +- `src/services/bookComparisonService.js`, `src/routes/bookComparison.js` +- `web/src/components/{LineMovementChart,MoversPanel,BestLinesPanel,BookComparison}.tsx` +- `web/src/app/api/parlay/calculate/route.ts`, `api/lines/[...path]/route.ts`, `api/books/[...path]/route.ts` +- 4 new test files (parlayService, lineSnapshotService, bookComparisonService, session28Routes) + +### Files modified +- `src/app.js` (3 mounts), `src/services/oddsService.js` (snapshot recording) +- `web/src/components/Slate.tsx` (2 panels) + +--- + +## Previous Phase SHIP BUILD v27.0 — PWA autopilot: deployment-aware service worker, push foundation, offline fallback, install + cookie + tier polish (Session 27) ## Session 27 (2026-06-13) — SHIPPED diff --git a/data/training/resolutions-2026-06.jsonl b/data/training/resolutions-2026-06.jsonl index 30ed234..07a5be9 100644 --- a/data/training/resolutions-2026-06.jsonl +++ b/data/training/resolutions-2026-06.jsonl @@ -759,3 +759,24 @@ {"ts":"2026-06-13T14:45:08.483Z","sport":"nba","player_espn_id":"3136195","player_name":"Karl-Anthony Towns","stat_type":"rebounds","line":13.5,"direction":"under","actual_value":13,"result":"hit","margin":-0.5,"grade":"B+"} {"ts":"2026-06-13T14:45:08.484Z","sport":"nba","player_espn_id":"3062679","player_name":"Josh Hart","stat_type":"pts_reb_ast","line":10.5,"direction":"over","actual_value":10,"result":"miss","margin":-0.5,"grade":"C"} {"ts":"2026-06-13T14:45:08.569Z","sport":"nba","player_espn_id":"999999999","player_name":"Phantom Player","stat_type":"points","line":10.5,"direction":"over","actual_value":null,"result":"void","grade":"C"} +{"ts":"2026-06-13T15:25:31.069Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A"} +{"ts":"2026-06-13T15:25:31.143Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A"} +{"ts":"2026-06-13T15:25:31.238Z","sport":"nba","player_espn_id":"99999","player_name":"Phantom","stat_type":"points","line":10.5,"direction":"over","actual_value":null,"result":"void","grade":"B"} +{"ts":"2026-06-13T15:25:31.651Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A-"} +{"ts":"2026-06-13T15:25:31.651Z","sport":"nba","player_espn_id":"3136195","player_name":"Karl-Anthony Towns","stat_type":"rebounds","line":13.5,"direction":"under","actual_value":13,"result":"hit","margin":-0.5,"grade":"B+"} +{"ts":"2026-06-13T15:25:31.651Z","sport":"nba","player_espn_id":"3062679","player_name":"Josh Hart","stat_type":"pts_reb_ast","line":10.5,"direction":"over","actual_value":10,"result":"miss","margin":-0.5,"grade":"C"} +{"ts":"2026-06-13T15:25:31.899Z","sport":"nba","player_espn_id":"999999999","player_name":"Phantom Player","stat_type":"points","line":10.5,"direction":"over","actual_value":null,"result":"void","grade":"C"} +{"ts":"2026-06-13T15:53:25.341Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A-"} +{"ts":"2026-06-13T15:53:25.343Z","sport":"nba","player_espn_id":"3136195","player_name":"Karl-Anthony Towns","stat_type":"rebounds","line":13.5,"direction":"under","actual_value":13,"result":"hit","margin":-0.5,"grade":"B+"} +{"ts":"2026-06-13T15:53:25.343Z","sport":"nba","player_espn_id":"3062679","player_name":"Josh Hart","stat_type":"pts_reb_ast","line":10.5,"direction":"over","actual_value":10,"result":"miss","margin":-0.5,"grade":"C"} +{"ts":"2026-06-13T15:53:25.423Z","sport":"nba","player_espn_id":"999999999","player_name":"Phantom Player","stat_type":"points","line":10.5,"direction":"over","actual_value":null,"result":"void","grade":"C"} +{"ts":"2026-06-13T15:53:26.214Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A"} +{"ts":"2026-06-13T15:53:26.372Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A"} +{"ts":"2026-06-13T15:53:26.404Z","sport":"nba","player_espn_id":"99999","player_name":"Phantom","stat_type":"points","line":10.5,"direction":"over","actual_value":null,"result":"void","grade":"B"} +{"ts":"2026-06-13T15:56:53.174Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A"} +{"ts":"2026-06-13T15:56:53.299Z","sport":"nba","player_espn_id":"99999","player_name":"Phantom","stat_type":"points","line":10.5,"direction":"over","actual_value":null,"result":"void","grade":"B"} +{"ts":"2026-06-13T15:56:53.752Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A"} +{"ts":"2026-06-13T15:56:53.880Z","sport":"nba","player_espn_id":"3934719","player_name":"OG Anunoby","stat_type":"points","line":16.5,"direction":"over","actual_value":17,"result":"hit","margin":0.5,"grade":"A-"} +{"ts":"2026-06-13T15:56:53.881Z","sport":"nba","player_espn_id":"3136195","player_name":"Karl-Anthony Towns","stat_type":"rebounds","line":13.5,"direction":"under","actual_value":13,"result":"hit","margin":-0.5,"grade":"B+"} +{"ts":"2026-06-13T15:56:53.881Z","sport":"nba","player_espn_id":"3062679","player_name":"Josh Hart","stat_type":"pts_reb_ast","line":10.5,"direction":"over","actual_value":10,"result":"miss","margin":-0.5,"grade":"C"} +{"ts":"2026-06-13T15:56:53.940Z","sport":"nba","player_espn_id":"999999999","player_name":"Phantom Player","stat_type":"points","line":10.5,"direction":"over","actual_value":null,"result":"void","grade":"C"} diff --git a/src/app.js b/src/app.js index 58b5e05..e9613ff 100644 --- a/src/app.js +++ b/src/app.js @@ -150,6 +150,15 @@ const streaksRoutes = require('./routes/streaks'); app.use('/api/streaks', streaksRoutes); const hotListRoutes = require('./routes/hotlist'); app.use('/api/hotlist', hotListRoutes); +// Session 28 — parlay builder, line-movement views, book comparison. +// All three are zero-credit: parlay math is pure, lines read a Redis +// snapshot history, books read the cached odds props. +const parlayRoutes = require('./routes/parlay'); +app.use('/api/parlay', parlayRoutes); +const lineMovementRoutes = require('./routes/lineMovement'); +app.use('/api/lines', lineMovementRoutes); +const bookComparisonRoutes = require('./routes/bookComparison'); +app.use('/api/books', bookComparisonRoutes); // Session 18 — internal ops endpoints (admin dashboard triggers, // shared-key auth via `VYNDR_INTERNAL_KEY`). Never reachable from // the public surface; the Next.js admin route proxies through with diff --git a/src/routes/bookComparison.js b/src/routes/bookComparison.js new file mode 100644 index 0000000..4604c77 --- /dev/null +++ b/src/routes/bookComparison.js @@ -0,0 +1,78 @@ +'use strict'; + +/** + * /api/books (Session 28) + * + * Book comparison views over the CACHED odds props — zero odds-api + * credits (it never triggers a fetch; it reads what's already cached). + * + * GET /api/books/:sport → best lines tonight (sorted by savings) + * GET /api/books/:sport/:player/:stat → book-by-book for one prop + * + * `?side=over|under` selects which side to optimize (default over). + */ + +const express = require('express'); +const bookComparison = require('../services/bookComparisonService'); +const { cacheGet } = require('../utils/redis'); + +const router = express.Router(); + +const MISSION_HEADER = { 'X-VYNDR-Mission': 'Never leave money on the table' }; + +const SUPPORTED = new Set(['nba', 'wnba', 'mlb', 'soccer', 'nfl', 'nhl']); + +// Read cached grouped props for a sport without triggering a fetch. +// oddsService caches `odds:{sport}:{utcDate}` = { updated_at, props, spreads }. +async function readCachedProps(sport) { + const utcDate = new Date().toISOString().split('T')[0]; + const cache = + (await cacheGet(`odds:${sport}:${utcDate}`)) ?? + (await cacheGet(`odds:${sport}`)); + if (!cache) return []; + return Array.isArray(cache.props) ? cache.props : []; +} + +router.get('/:sport', async (req, res) => { + const sport = String(req.params.sport || '').toLowerCase(); + if (!SUPPORTED.has(sport)) { + return res.status(404).set(MISSION_HEADER).json({ error: `No book comparison for sport: ${sport}` }); + } + const side = req.query.side === 'under' ? 'under' : 'over'; + const limit = req.query.limit ? Math.max(0, parseInt(req.query.limit, 10) || 0) : 20; + try { + const props = await readCachedProps(sport); + const lines = bookComparison.bestLines(props, { side, limit }); + return res.set(MISSION_HEADER).json({ sport, side, bestLines: lines, source: 'odds-cache' }); + } catch (err) { + console.error(`[books/${sport}]`, err.message); + return res.set(MISSION_HEADER).json({ sport, side, bestLines: [], source: 'odds-cache' }); + } +}); + +router.get('/:sport/:player/:stat', async (req, res) => { + const sport = String(req.params.sport || '').toLowerCase(); + const player = decodeURIComponent(req.params.player); + const stat = req.params.stat; + const side = req.query.side === 'under' ? 'under' : 'over'; + try { + const props = await readCachedProps(sport); + const prop = props.find( + (p) => (p.player || '').toLowerCase() === player.toLowerCase() && + (p.stat_type || p.stat || '').toLowerCase() === stat.toLowerCase(), + ); + if (!prop) { + return res.status(404).set(MISSION_HEADER).json({ error: 'Prop not found in current slate.' }); + } + const comparison = bookComparison.compareProp(prop, side); + if (!comparison) { + return res.set(MISSION_HEADER).json({ sport, player, stat, side, books: [], bestBook: null }); + } + return res.set(MISSION_HEADER).json({ sport, ...comparison }); + } catch (err) { + console.error(`[books/${sport}/prop]`, err.message); + return res.status(500).set(MISSION_HEADER).json({ error: 'Comparison failed' }); + } +}); + +module.exports = router; diff --git a/src/routes/lineMovement.js b/src/routes/lineMovement.js new file mode 100644 index 0000000..0c922e6 --- /dev/null +++ b/src/routes/lineMovement.js @@ -0,0 +1,49 @@ +'use strict'; + +/** + * /api/lines (Session 28) + * + * Read-only views over the line-snapshot history (Redis). Zero credits. + * + * GET /api/lines/:sport/movers → biggest movers today + * GET /api/lines/:sport/:gameId/:player/:stat → one prop's history + classification + */ + +const express = require('express'); +const lineSnapshots = require('../services/lineSnapshotService'); + +const router = express.Router(); + +const MISSION_HEADER = { 'X-VYNDR-Mission': 'The market confirms the grade' }; + +const SUPPORTED = new Set(['nba', 'wnba', 'mlb', 'soccer', 'nfl', 'nhl']); + +router.get('/:sport/movers', async (req, res) => { + const sport = String(req.params.sport || '').toLowerCase(); + if (!SUPPORTED.has(sport)) { + return res.status(404).set(MISSION_HEADER).json({ error: `No line tracking for sport: ${sport}` }); + } + const limit = req.query.limit ? Math.max(0, parseInt(req.query.limit, 10) || 0) : 20; + try { + const movers = await lineSnapshots.getBiggestMovers(sport, { limit }); + return res.set(MISSION_HEADER).json({ sport, movers, source: 'snapshots' }); + } catch (err) { + console.error(`[lines/${sport}/movers]`, err.message); + return res.set(MISSION_HEADER).json({ sport, movers: [], source: 'snapshots' }); + } +}); + +router.get('/:sport/:gameId/:player/:stat', async (req, res) => { + const sport = String(req.params.sport || '').toLowerCase(); + const { gameId, player, stat } = req.params; + try { + const history = await lineSnapshots.getLineHistory(sport, gameId, decodeURIComponent(player), stat); + const classification = lineSnapshots.classifyMovement(history); + return res.set(MISSION_HEADER).json({ sport, gameId, player, stat, ...classification }); + } catch (err) { + console.error(`[lines/${sport}/prop]`, err.message); + return res.set(MISSION_HEADER).json({ sport, gameId, player, stat, movement: 'stable', delta: 0, snapshots: [] }); + } +}); + +module.exports = router; diff --git a/src/routes/parlay.js b/src/routes/parlay.js new file mode 100644 index 0000000..4a4358f --- /dev/null +++ b/src/routes/parlay.js @@ -0,0 +1,46 @@ +'use strict'; + +/** + * /api/parlay (Session 28) + * + * Builder-side parlay math — combined odds, grade, and correlation flags + * for a set of user-selected legs. Distinct from the existing parlay + * GRADING path (parlayGrader); this is the lightweight, zero-credit + * combination used by the live parlay builder. + * + * POST /api/parlay/calculate { legs: [...] } → combined analysis + * POST /api/parlay/suggestions { props, legs?, max? } → suggested combos + */ + +const express = require('express'); +const parlayService = require('../services/parlayService'); + +const router = express.Router(); + +const MISSION_HEADER = { 'X-VYNDR-Mission': 'Catch the legs that fight each other' }; + +router.post('/calculate', (req, res) => { + try { + const legs = req.body?.legs; + const result = parlayService.calculateParlay(legs); + return res.set(MISSION_HEADER).json(result); + } catch (err) { + const status = err.statusCode || 400; + return res.status(status).set(MISSION_HEADER).json({ error: err.message }); + } +}); + +router.post('/suggestions', (req, res) => { + try { + const { props, legs, max } = req.body || {}; + const suggestions = parlayService.suggestParlays(props || [], { + legs: Number(legs) || 3, + max: Number(max) || 3, + }); + return res.set(MISSION_HEADER).json({ suggestions }); + } catch (err) { + return res.status(400).set(MISSION_HEADER).json({ error: err.message }); + } +}); + +module.exports = router; diff --git a/src/services/bookComparisonService.js b/src/services/bookComparisonService.js new file mode 100644 index 0000000..c6d5fdb --- /dev/null +++ b/src/services/bookComparisonService.js @@ -0,0 +1,90 @@ +'use strict'; + +/** + * Book comparison (Session 28). + * + * Surfaces the same prop across every available sportsbook with the best + * line highlighted. Data source is the grouped odds-api prop shape, which + * already carries book-by-book lines: + * { player, stat_type, lines: [{ book, line, over_odds, under_odds }] } + * + * "Best line" = highest decimal payout for the selected side. Savings is + * the per-$100 payout edge of the best book over the field average — the + * concrete dollars a user leaves on the table by not line-shopping. + * + * Zero credits: it only reads odds already fetched/cached. + */ + +const { __internals } = require('./parlayService'); +const { americanToDecimal } = __internals; + +function average(nums) { + const valid = nums.filter((n) => Number.isFinite(n)); + if (valid.length === 0) return 0; + return valid.reduce((a, b) => a + b, 0) / valid.length; +} + +function oddsForSide(line, side) { + if (!line) return null; + const raw = side === 'under' ? line.under_odds : line.over_odds; + return raw == null ? null : Number(raw); +} + +/** + * Compare one grouped prop across its books for a given side. + * Returns null when there are no usable book lines. + */ +function compareProp(prop, side = 'over') { + const books = (prop?.lines || prop?.books || []).filter((b) => b && b.book); + const priced = books.filter((b) => Number.isFinite(oddsForSide(b, side))); + if (priced.length === 0) return null; + + let best = priced[0]; + for (const b of priced) { + if (americanToDecimal(oddsForSide(b, side)) > americanToDecimal(oddsForSide(best, side))) best = b; + } + + const bestDecimal = americanToDecimal(oddsForSide(best, side)); + const avgDecimal = average(priced.map((b) => americanToDecimal(oddsForSide(b, side)))); + const savings = Math.round((bestDecimal - avgDecimal) * 100 * 100) / 100; // per $100, 2dp + + return { + player: prop.player, + stat: prop.stat_type || prop.stat, + line: best.line ?? prop.line ?? null, + side, + books: priced.map((b) => ({ + book: b.book, + line: b.line ?? null, + over_odds: b.over_odds ?? null, + under_odds: b.under_odds ?? null, + isBest: b.book === best.book, + })), + bestBook: best.book, + bestOdds: oddsForSide(best, side), + bookCount: priced.length, + savings, + }; +} + +/** + * Best lines across a list of props, sorted by savings desc (where line- + * shopping matters most). Drops props with a single book (nothing to + * compare). `limit` caps the result. + */ +function bestLines(props, { side = 'over', limit = 20 } = {}) { + if (!Array.isArray(props)) return []; + const out = []; + for (const prop of props) { + const cmp = compareProp(prop, side); + if (cmp && cmp.bookCount >= 2) out.push(cmp); + } + out.sort((a, b) => b.savings - a.savings); + return limit > 0 ? out.slice(0, limit) : out; +} + +module.exports = { + compareProp, + bestLines, + __internals: { average, oddsForSide }, +}; diff --git a/src/services/lineSnapshotService.js b/src/services/lineSnapshotService.js new file mode 100644 index 0000000..a30db62 --- /dev/null +++ b/src/services/lineSnapshotService.js @@ -0,0 +1,174 @@ +'use strict'; + +/** + * Line-snapshot service (Session 28). + * + * Lightweight, Redis-only line-movement tracking that complements the + * Supabase-backed `lineMovementService` (which captures opening baselines + * + sharp indicators for grading). This layer records a rolling history + * of a prop's line through the day so the UI can draw a sparkline and a + * "biggest movers" board — with ZERO odds-api credits (it only stores + * what an odds fetch already returned). + * + * Key shape: + * linehistory:{sport}:{gameId}:{player}:{stat} → Redis list of + * JSON { time, line, book } snapshots (cap 100, 48h TTL). + * + * Everything is defensive: Redis down → no-op / empty, never a throw. + */ + +const { getRedisClient, isDegraded } = require('../utils/redis'); + +const MAX_SNAPSHOTS = 100; +const TTL_SECONDS = 48 * 3600; +const SCAN_COUNT = 200; +const MAX_KEYS = 1000; +const SHARP_THRESHOLD = 1.5; // points of movement that flags sharp money +const STABLE_THRESHOLD = 0.5; // < this = "stable" + +function snapshotKey(sport, gameId, player, stat) { + return `linehistory:${sport}:${gameId}:${player}:${stat}`; +} + +function safeNum(v) { + const n = Number(v); + return Number.isFinite(n) ? n : null; +} + +/** + * Append a line snapshot for each prop. `now` is injectable for tests. + * Props need { gameId|game_id, player, stat|stat_type, line, book }. + */ +async function recordSnapshots(sport, props, now = Date.now()) { + if (isDegraded && isDegraded()) return 0; + if (!Array.isArray(props) || props.length === 0) return 0; + const redis = getRedisClient(); + if (!redis || typeof redis.rpush !== 'function') return 0; + + let written = 0; + for (const p of props) { + const gameId = p.gameId || p.game_id; + const player = p.player; + const stat = p.stat || p.stat_type; + const line = safeNum(p.line); + if (!gameId || !player || !stat || line === null) continue; + const key = snapshotKey(sport, gameId, player, stat); + const snap = JSON.stringify({ time: now, line, book: p.book || null }); + try { + await redis.rpush(key, snap); + await redis.ltrim(key, -MAX_SNAPSHOTS, -1); + await redis.expire(key, TTL_SECONDS); + written += 1; + } catch { + /* swallow — snapshot recording must never break an odds fetch */ + } + } + return written; +} + +async function getLineHistory(sport, gameId, player, stat) { + if (isDegraded && isDegraded()) return []; + const redis = getRedisClient(); + if (!redis || typeof redis.lrange !== 'function') return []; + try { + const raw = await redis.lrange(snapshotKey(sport, gameId, player, stat), 0, -1); + return (raw || []) + .map((s) => { try { return JSON.parse(s); } catch { return null; } }) + .filter(Boolean); + } catch { + return []; + } +} + +/** + * Classify a list of snapshots (oldest → newest) into a movement summary. + * Empty / single-snapshot → stable, never an error. + */ +function classifyMovement(snapshots) { + if (!Array.isArray(snapshots) || snapshots.length < 2) { + const only = snapshots && snapshots[0] ? safeNum(snapshots[0].line) : null; + return { opening: only, current: only, delta: 0, movement: 'stable', sharpSignal: false, snapshots: snapshots || [] }; + } + const opening = safeNum(snapshots[0].line) ?? 0; + const current = safeNum(snapshots[snapshots.length - 1].line) ?? 0; + const delta = Math.round((current - opening) * 100) / 100; + const abs = Math.abs(delta); + return { + opening, + current, + delta, + movement: abs < STABLE_THRESHOLD ? 'stable' : delta > 0 ? 'rising' : 'dropping', + sharpSignal: abs >= SHARP_THRESHOLD, + snapshots, + }; +} + +function parseKey(key) { + // linehistory:{sport}:{gameId}:{player}:{stat} + const parts = String(key).split(':'); + if (parts.length < 5 || parts[0] !== 'linehistory') return null; + // player names may contain no colons in practice; stat is the last part. + const [, sport, gameId] = parts; + const stat = parts[parts.length - 1]; + const player = parts.slice(3, parts.length - 1).join(':'); + return { sport, gameId, player, stat }; +} + +async function scanKeys(match) { + if (isDegraded && isDegraded()) return []; + const redis = getRedisClient(); + if (!redis || typeof redis.scan !== 'function') return []; + const keys = []; + let cursor = '0'; + try { + do { + const [next, batch] = await redis.scan(cursor, 'MATCH', match, 'COUNT', SCAN_COUNT); + cursor = next; + for (const k of batch) { + if (!keys.includes(k)) keys.push(k); + if (keys.length >= MAX_KEYS) return keys; + } + } while (cursor !== '0'); + } catch { + return keys; + } + return keys; +} + +/** + * Biggest movers for a sport — every tracked prop classified, filtered to + * meaningful moves, sorted by absolute delta desc. `limit` caps the list. + */ +async function getBiggestMovers(sport, { limit = 20, minDelta = STABLE_THRESHOLD } = {}) { + const keys = await scanKeys(`linehistory:${sport}:*`); + const movers = []; + for (const key of keys) { + const meta = parseKey(key); + if (!meta) continue; + const history = await getLineHistory(sport, meta.gameId, meta.player, meta.stat); + const cls = classifyMovement(history); + if (Math.abs(cls.delta) < minDelta) continue; + movers.push({ + sport, + gameId: meta.gameId, + player: meta.player, + stat: meta.stat, + opening: cls.opening, + current: cls.current, + delta: cls.delta, + movement: cls.movement, + sharpSignal: cls.sharpSignal, + snapshots: cls.snapshots, + }); + } + movers.sort((a, b) => Math.abs(b.delta) - Math.abs(a.delta)); + return limit > 0 ? movers.slice(0, limit) : movers; +} + +module.exports = { + recordSnapshots, + getLineHistory, + classifyMovement, + getBiggestMovers, + __internals: { snapshotKey, parseKey, scanKeys, SHARP_THRESHOLD, STABLE_THRESHOLD }, +}; diff --git a/src/services/oddsService.js b/src/services/oddsService.js index e869d94..13ec3e8 100644 --- a/src/services/oddsService.js +++ b/src/services/oddsService.js @@ -346,6 +346,10 @@ async function getOdds(sport) { movements = moveResult.movements || []; const cascadeResult = await cascade.detectScratches(sport, props); scratchedPlayers = cascadeResult.scratchedPlayers || []; + // Session 28 — append a rolling line-history snapshot per prop so the + // sparkline / biggest-movers views have data. Redis-only, free. + const lineSnapshots = require('./lineSnapshotService'); + await lineSnapshots.recordSnapshots(sport, props); } catch (e) { // Non-fatal — log and continue console.warn('[VYNDR] Movement/cascade detection error:', e.message); diff --git a/src/services/parlayService.js b/src/services/parlayService.js new file mode 100644 index 0000000..f39d33a --- /dev/null +++ b/src/services/parlayService.js @@ -0,0 +1,193 @@ +'use strict'; + +/** + * Parlay service (Session 28). + * + * Combines user-selected props (from the parlay builder) into a parlay: + * - combined American/decimal odds (multiply decimal odds) + * - combined grade (confidence-weighted average of leg grades) + * - correlation detection (interaction matrix for same-game legs) + * - kill-condition aggregation (any leg flagged → surface it) + * + * This is the lightweight BUILDER path — it operates on the simple leg + * shape the frontend sends ({ player, team, gameId, stat, side, line, + * odds, grade, confidence, killConditions }). It is distinct from the + * full grading pipeline (`parlayGrader` / `correlationEngine`), which + * consumes already-analyzed legs with full reasoning trees. + * + * Odds math reuses `payoutCalculator` where it can; the decimal/American + * conversions live here because the builder needs both directions. + */ + +const { calculateParlayPayout } = require('./payoutCalculator'); + +// ---- odds conversions ------------------------------------------------- +function americanToDecimal(odds) { + const n = Number(odds); + if (!Number.isFinite(n) || n === 0) return 1; + return n > 0 ? 1 + n / 100 : 1 + 100 / Math.abs(n); +} + +function decimalToAmerican(decimal) { + const d = Number(decimal); + if (!Number.isFinite(d) || d <= 1) return 0; + return d >= 2 + ? Math.round((d - 1) * 100) + : Math.round(-100 / (d - 1)); +} + +// ---- grade <-> numeric (A+ = 12 … F = 0) ------------------------------ +const GRADE_ORDER = ['F', 'D-', 'D', 'D+', 'C-', 'C', 'C+', 'B-', 'B', 'B+', 'A-', 'A', 'A+']; + +function gradeToNumeric(grade) { + const idx = GRADE_ORDER.indexOf(String(grade || 'C').toUpperCase()); + return idx === -1 ? GRADE_ORDER.indexOf('C') : idx; +} + +function numericToGrade(value) { + const idx = Math.max(0, Math.min(GRADE_ORDER.length - 1, Math.round(value))); + return GRADE_ORDER[idx]; +} + +// ---- correlation interaction matrix ----------------------------------- +// Keyed by the two stat types sorted + joined. `sameTeam` / `crossTeam` +// give the correlation sign. Stat names are normalized to lowercase. +const INTERACTIONS = { + 'assists_points': { sameTeam: 'positive', crossTeam: 'neutral' }, + 'assists_rebounds': { sameTeam: 'positive', crossTeam: 'neutral' }, + 'points_points': { sameTeam: 'neutral', crossTeam: 'negative' }, + 'rebounds_rebounds': { sameTeam: 'negative', crossTeam: 'negative' }, + 'points_rebounds': { sameTeam: 'positive', crossTeam: 'neutral' }, + 'assists_assists': { sameTeam: 'negative', crossTeam: 'neutral' }, + 'pra_points': { sameTeam: 'positive', crossTeam: 'neutral' }, + // MLB + 'hits_strikeouts': { sameTeam: 'neutral', crossTeam: 'negative' }, + 'hits_hits': { sameTeam: 'positive', crossTeam: 'neutral' }, + 'strikeouts_strikeouts':{ sameTeam: 'neutral', crossTeam: 'positive' }, + 'home_runs_strikeouts': { sameTeam: 'neutral', crossTeam: 'negative' }, +}; + +function normStat(s) { + return String(s || '').toLowerCase().replace(/\s+/g, '_'); +} + +function describeCorrelation(legA, legB, sign) { + const a = `${legA.player} ${normStat(legA.stat).replace(/_/g, ' ')}`; + const b = `${legB.player} ${normStat(legB.stat).replace(/_/g, ' ')}`; + if (sign === 'negative') return `${a} and ${b} compete — these legs fight each other`; + if (sign === 'positive') return `${a} and ${b} feed each other — correlated outcome`; + return `${a} and ${b} are weakly related`; +} + +/** + * Correlation between two builder legs. Independent across different + * games; otherwise looked up in the interaction matrix. + */ +function detectCorrelation(legA, legB) { + if (!legA || !legB) return { correlated: false, type: 'independent' }; + + // Same player, opposite directions on the same stat → direct conflict. + if (legA.player && legB.player && legA.player.toLowerCase() === legB.player.toLowerCase()) { + if (normStat(legA.stat) === normStat(legB.stat) && legA.side && legB.side && legA.side !== legB.side) { + return { correlated: true, type: 'negative', description: `${legA.player}: ${legA.side} vs ${legB.side} on the same prop — direct conflict` }; + } + } + + if (!legA.gameId || !legB.gameId || legA.gameId !== legB.gameId) { + return { correlated: false, type: 'independent' }; + } + + const key = [normStat(legA.stat), normStat(legB.stat)].sort().join('_'); + const interaction = INTERACTIONS[key]; + if (!interaction) return { correlated: false, type: 'unknown' }; + + const sameTeam = legA.team != null && legA.team === legB.team; + const sign = sameTeam ? interaction.sameTeam : interaction.crossTeam; + if (sign === 'neutral') return { correlated: false, type: 'neutral' }; + + return { correlated: true, type: sign, description: describeCorrelation(legA, legB, sign) }; +} + +/** + * Combine legs into a parlay analysis. Throws on empty/invalid input so + * the route can 400 cleanly. + */ +function calculateParlay(legs) { + if (!Array.isArray(legs) || legs.length === 0) { + const err = new Error('A parlay needs at least one leg.'); + err.statusCode = 400; + throw err; + } + + const decimalOdds = legs.map((l) => americanToDecimal(l.odds)); + const combinedDecimal = decimalOdds.reduce((a, b) => a * b, 1); + const combinedAmerican = decimalToAmerican(combinedDecimal); + + // Confidence-weighted grade. + const totalConfidence = legs.reduce((sum, l) => sum + (Number(l.confidence) || 50), 0); + const weightedGrade = legs.reduce((sum, l) => { + const weight = (Number(l.confidence) || 50) / totalConfidence; + return sum + gradeToNumeric(l.grade) * weight; + }, 0); + + // All pairwise correlations. + const correlations = []; + for (let i = 0; i < legs.length; i += 1) { + for (let j = i + 1; j < legs.length; j += 1) { + const c = detectCorrelation(legs[i], legs[j]); + if (c.correlated) correlations.push({ legA: i, legB: j, type: c.type, description: c.description }); + } + } + + const killConditions = legs + .map((l, i) => ({ leg: i, player: l.player, conditions: l.killConditions || [] })) + .filter((k) => Array.isArray(k.conditions) && k.conditions.length > 0); + + return { + legCount: legs.length, + combinedOdds: combinedAmerican, + combinedDecimal: Math.round(combinedDecimal * 10000) / 10000, + combinedGrade: numericToGrade(weightedGrade), + payoutPer10: Math.round(calculateParlayPayout(10, legs.map((l) => Number(l.odds) || 0)) * 100) / 100, + correlations, + hasNegativeCorrelation: correlations.some((c) => c.type === 'negative'), + hasPositiveCorrelation: correlations.some((c) => c.type === 'positive'), + killConditions, + hasKillCondition: killConditions.length > 0, + }; +} + +/** + * Suggest up to `max` parlays from a pool of graded props. Greedy: take + * the best-graded props, avoid negative correlations within a suggestion. + * Pure — the route supplies the prop pool (no API calls here). + */ +function suggestParlays(props, { legs = 3, max = 3 } = {}) { + if (!Array.isArray(props) || props.length < legs) return []; + const sorted = [...props].sort((a, b) => gradeToNumeric(b.grade) - gradeToNumeric(a.grade)); + + const suggestions = []; + const used = new Set(); + for (let start = 0; start < sorted.length && suggestions.length < max; start += 1) { + if (used.has(start)) continue; + const combo = [start]; + for (let k = 0; k < sorted.length && combo.length < legs; k += 1) { + if (k === start || used.has(k) || combo.includes(k)) continue; + const conflicts = combo.some((idx) => detectCorrelation(sorted[idx], sorted[k]).type === 'negative'); + if (!conflicts) combo.push(k); + } + if (combo.length === legs) { + combo.forEach((idx) => used.add(idx)); + const legObjs = combo.map((idx) => sorted[idx]); + suggestions.push({ legs: legObjs, ...calculateParlay(legObjs) }); + } + } + return suggestions; +} + +module.exports = { + calculateParlay, + detectCorrelation, + suggestParlays, + __internals: { americanToDecimal, decimalToAmerican, gradeToNumeric, numericToGrade, INTERACTIONS }, +}; diff --git a/tests/integration/session28Routes.test.js b/tests/integration/session28Routes.test.js new file mode 100644 index 0000000..f35cc15 --- /dev/null +++ b/tests/integration/session28Routes.test.js @@ -0,0 +1,106 @@ +// Integration: parlay / lines / books routes (Session 28). + +const express = require('express'); +const request = require('supertest'); + +// Redis-backed services are mocked at the redis layer. +const mockStore = {}; +const mockScan = jest.fn(async () => ['0', []]); +jest.mock('../../src/utils/redis', () => ({ + cacheGet: jest.fn(async (k) => (k in mockStore ? mockStore[k] : null)), + getRedisClient: () => ({ scan: mockScan, lrange: async () => [], rpush: async () => 1, ltrim: async () => 'OK', expire: async () => 1 }), + isDegraded: () => false, +})); + +function mount(routePath, file) { + delete require.cache[require.resolve(file)]; + const app = express(); + app.use(express.json()); + app.use(routePath, require(file)); + return app; +} + +beforeEach(() => { + for (const k of Object.keys(mockStore)) delete mockStore[k]; + jest.clearAllMocks(); +}); + +describe('POST /api/parlay/calculate', () => { + const app = () => mount('/api/parlay', '../../src/routes/parlay'); + + test('returns combined odds + grade for valid legs', async () => { + const res = await request(app()).post('/api/parlay/calculate').send({ + legs: [ + { player: 'A', stat: 'points', odds: 100, grade: 'A', gameId: 'g1' }, + { player: 'B', stat: 'hits', odds: 100, grade: 'A', gameId: 'g2' }, + ], + }); + expect(res.status).toBe(200); + expect(res.body.combinedOdds).toBe(300); // 2×2 = 4.0 → +300 + expect(res.body.combinedGrade).toBeDefined(); + }); + + test('empty legs → 400', async () => { + const res = await request(app()).post('/api/parlay/calculate').send({ legs: [] }); + expect(res.status).toBe(400); + }); + + test('suggestions endpoint returns combos', async () => { + const props = [ + { player: 'A', stat: 'points', odds: -110, grade: 'A', gameId: 'g1' }, + { player: 'B', stat: 'hits', odds: -110, grade: 'A', gameId: 'g2' }, + { player: 'C', stat: 'goals', odds: -110, grade: 'B', gameId: 'g3' }, + ]; + const res = await request(app()).post('/api/parlay/suggestions').send({ props, legs: 3, max: 1 }); + expect(res.status).toBe(200); + expect(res.body.suggestions).toHaveLength(1); + }); +}); + +describe('GET /api/lines/:sport/movers', () => { + const app = () => mount('/api/lines', '../../src/routes/lineMovement'); + + test('empty when no snapshots cached', async () => { + const res = await request(app()).get('/api/lines/mlb/movers'); + expect(res.status).toBe(200); + expect(res.body.movers).toEqual([]); + }); + + test('unsupported sport → 404', async () => { + const res = await request(app()).get('/api/lines/cricket/movers'); + expect(res.status).toBe(404); + }); +}); + +describe('GET /api/books/:sport', () => { + const app = () => mount('/api/books', '../../src/routes/bookComparison'); + + test('returns best lines from cached props', async () => { + mockStore[`odds:nba:${new Date().toISOString().split('T')[0]}`] = { + props: [ + { + player: 'Wemby', stat_type: 'points', + lines: [ + { book: 'dk', over_odds: -110 }, + { book: 'fd', over_odds: -105 }, + ], + }, + ], + }; + const res = await request(app()).get('/api/books/nba'); + expect(res.status).toBe(200); + expect(res.body.bestLines).toHaveLength(1); + expect(res.body.bestLines[0].bestBook).toBe('fd'); + }); + + test('empty when no cached props', async () => { + const res = await request(app()).get('/api/books/nba'); + expect(res.status).toBe(200); + expect(res.body.bestLines).toEqual([]); + }); + + test('unsupported sport → 404', async () => { + const res = await request(app()).get('/api/books/cricket'); + expect(res.status).toBe(404); + }); +}); diff --git a/tests/unit/bookComparisonService.test.js b/tests/unit/bookComparisonService.test.js new file mode 100644 index 0000000..fab7cb1 --- /dev/null +++ b/tests/unit/bookComparisonService.test.js @@ -0,0 +1,68 @@ +// Unit: book comparison service (Session 28). Pure functions. + +const { compareProp, bestLines } = require('../../src/services/bookComparisonService'); + +const prop = { + player: 'Wembanyama', + stat_type: 'points', + lines: [ + { book: 'draftkings', line: 28.5, over_odds: -110, under_odds: -110 }, + { book: 'fanduel', line: 28.5, over_odds: -105, under_odds: -115 }, // best over + { book: 'betmgm', line: 28.5, over_odds: -120, under_odds: -102 }, // best under + ], +}; + +describe('bookComparisonService — compareProp', () => { + test('identifies the best OVER line (highest payout)', () => { + const c = compareProp(prop, 'over'); + expect(c.bestBook).toBe('fanduel'); // -105 pays more than -110/-120 + expect(c.bestOdds).toBe(-105); + expect(c.books.find((b) => b.book === 'fanduel').isBest).toBe(true); + expect(c.bookCount).toBe(3); + }); + + test('identifies the best UNDER line', () => { + const c = compareProp(prop, 'under'); + expect(c.bestBook).toBe('betmgm'); // -102 pays more than -110/-115 + expect(c.bestOdds).toBe(-102); + }); + + test('savings is positive (best beats the field average)', () => { + const c = compareProp(prop, 'over'); + expect(c.savings).toBeGreaterThan(0); + }); + + test('single-book prop still compares (bookCount 1)', () => { + const c = compareProp({ player: 'X', stat_type: 'hits', lines: [{ book: 'dk', over_odds: -110 }] }, 'over'); + expect(c.bookCount).toBe(1); + expect(c.bestBook).toBe('dk'); + }); + + test('no usable lines → null, not crash', () => { + expect(compareProp({ player: 'X', stat_type: 'hits', lines: [] }, 'over')).toBeNull(); + expect(compareProp({ player: 'X', stat_type: 'hits' }, 'over')).toBeNull(); + }); +}); + +describe('bookComparisonService — bestLines', () => { + test('drops single-book props and sorts by savings desc', () => { + const props = [ + prop, + { player: 'Solo', stat_type: 'reb', lines: [{ book: 'dk', over_odds: -110 }] }, // 1 book → dropped + { + player: 'BigEdge', stat_type: 'ast', + lines: [ + { book: 'dk', over_odds: -200 }, + { book: 'fd', over_odds: +120 }, // huge spread → big savings + ], + }, + ]; + const lines = bestLines(props, { side: 'over' }); + expect(lines.map((l) => l.player)).not.toContain('Solo'); + expect(lines[0].player).toBe('BigEdge'); // biggest savings first + }); + + test('non-array input → empty', () => { + expect(bestLines(null)).toEqual([]); + }); +}); diff --git a/tests/unit/lineSnapshotService.test.js b/tests/unit/lineSnapshotService.test.js new file mode 100644 index 0000000..42f0ecd --- /dev/null +++ b/tests/unit/lineSnapshotService.test.js @@ -0,0 +1,104 @@ +// Unit: line-snapshot service (Session 28). Redis-only; mocked. + +const mockStore = {}; // key -> array of JSON strings (list) +const mockScan = jest.fn(); +const mockRedis = { + rpush: jest.fn(async (k, v) => { (mockStore[k] = mockStore[k] || []).push(v); return mockStore[k].length; }), + ltrim: jest.fn(async (k, start, end) => { + if (mockStore[k]) mockStore[k] = mockStore[k].slice(start, end === -1 ? undefined : end + 1); + return 'OK'; + }), + expire: jest.fn(async () => 1), + lrange: jest.fn(async (k) => mockStore[k] || []), + scan: mockScan, +}; + +jest.mock('../../src/utils/redis', () => ({ + getRedisClient: () => mockRedis, + isDegraded: () => false, +})); + +const svc = require('../../src/services/lineSnapshotService'); + +beforeEach(() => { + for (const k of Object.keys(mockStore)) delete mockStore[k]; + jest.clearAllMocks(); +}); + +describe('lineSnapshotService — recording', () => { + test('records a snapshot per prop into the right key', async () => { + const n = await svc.recordSnapshots('nba', [ + { gameId: 'g1', player: 'Wemby', stat: 'points', line: 28.5, book: 'dk' }, + ], 1000); + expect(n).toBe(1); + const hist = await svc.getLineHistory('nba', 'g1', 'Wemby', 'points'); + expect(hist).toEqual([{ time: 1000, line: 28.5, book: 'dk' }]); + }); + + test('skips props missing required fields', async () => { + const n = await svc.recordSnapshots('nba', [{ player: 'X' }, { gameId: 'g', player: 'Y', stat: 's', line: 'NaN' }], 1); + expect(n).toBe(0); + }); +}); + +describe('lineSnapshotService — classifyMovement', () => { + test('empty / single → stable, no error', () => { + expect(svc.classifyMovement([]).movement).toBe('stable'); + expect(svc.classifyMovement([{ line: 5 }]).movement).toBe('stable'); + expect(svc.classifyMovement([{ line: 5 }]).delta).toBe(0); + }); + + test('rising vs dropping', () => { + expect(svc.classifyMovement([{ line: 26.5 }, { line: 28.5 }]).movement).toBe('rising'); + expect(svc.classifyMovement([{ line: 28.5 }, { line: 26.5 }]).movement).toBe('dropping'); + }); + + test('sharp signal at >= 1.5 point move', () => { + expect(svc.classifyMovement([{ line: 28.5 }, { line: 26.5 }]).sharpSignal).toBe(true); // 2.0 + expect(svc.classifyMovement([{ line: 28.5 }, { line: 27.5 }]).sharpSignal).toBe(false); // 1.0 + }); + + test('< 0.5 move is stable', () => { + expect(svc.classifyMovement([{ line: 28.5 }, { line: 28.5 }]).movement).toBe('stable'); + expect(svc.classifyMovement([{ line: 28.5 }, { line: 28.2 }]).movement).toBe('stable'); + }); +}); + +describe('lineSnapshotService — biggest movers', () => { + test('classifies + sorts by absolute delta desc', async () => { + mockScan.mockResolvedValueOnce(['0', [ + 'linehistory:mlb:g1:Acuna:hits', + 'linehistory:mlb:g2:Soto:total_bases', + ]]); + mockStore['linehistory:mlb:g1:Acuna:hits'] = [ + JSON.stringify({ time: 1, line: 1.5 }), + JSON.stringify({ time: 2, line: 2.5 }), // +1.0 + ]; + mockStore['linehistory:mlb:g2:Soto:total_bases'] = [ + JSON.stringify({ time: 1, line: 3.5 }), + JSON.stringify({ time: 2, line: 1.0 }), // -2.5 (bigger, sharp) + ]; + const movers = await svc.getBiggestMovers('mlb'); + expect(movers).toHaveLength(2); + expect(movers[0].player).toBe('Soto'); // bigger |delta| first + expect(movers[0].delta).toBe(-2.5); + expect(movers[0].sharpSignal).toBe(true); + expect(movers[1].player).toBe('Acuna'); + }); + + test('filters out sub-threshold (stable) props', async () => { + mockScan.mockResolvedValueOnce(['0', ['linehistory:mlb:g1:Flat:hits']]); + mockStore['linehistory:mlb:g1:Flat:hits'] = [ + JSON.stringify({ time: 1, line: 1.5 }), + JSON.stringify({ time: 2, line: 1.5 }), + ]; + const movers = await svc.getBiggestMovers('mlb'); + expect(movers).toEqual([]); + }); + + test('parseKey extracts sport/game/player/stat', () => { + expect(svc.__internals.parseKey('linehistory:nba:g1:LeBron James:points')).toEqual({ + sport: 'nba', gameId: 'g1', player: 'LeBron James', stat: 'points', + }); + }); +}); diff --git a/tests/unit/parlayService.test.js b/tests/unit/parlayService.test.js new file mode 100644 index 0000000..1ca4205 --- /dev/null +++ b/tests/unit/parlayService.test.js @@ -0,0 +1,132 @@ +// Unit: parlay builder service (Session 28). Pure functions. + +const { calculateParlay, detectCorrelation, suggestParlays, __internals } = require('../../src/services/parlayService'); + +describe('parlayService — odds conversions', () => { + const { americanToDecimal, decimalToAmerican } = __internals; + test('americanToDecimal: +100 → 2.0, -110 → ~1.909', () => { + expect(americanToDecimal(100)).toBeCloseTo(2.0, 5); + expect(americanToDecimal(-110)).toBeCloseTo(1.9091, 3); + }); + test('decimalToAmerican round-trips', () => { + expect(decimalToAmerican(2.0)).toBe(100); + expect(decimalToAmerican(1.5)).toBe(-200); + }); +}); + +describe('parlayService — calculateParlay', () => { + test('2-leg combined odds multiply correctly', () => { + // -110 (1.909) × -110 (1.909) = 3.645 → +264 American + const r = calculateParlay([ + { player: 'A', stat: 'points', side: 'over', line: 20, odds: -110, grade: 'B', confidence: 60 }, + { player: 'B', stat: 'hits', side: 'over', line: 1, odds: -110, grade: 'B', confidence: 60, gameId: 'g2' }, + ]); + expect(r.combinedDecimal).toBeCloseTo(3.645, 2); + expect(r.combinedOdds).toBe(264); + expect(r.legCount).toBe(2); + }); + + test('3-leg combined odds', () => { + const r = calculateParlay([ + { player: 'A', stat: 'points', odds: 100, grade: 'A', confidence: 70 }, + { player: 'B', stat: 'hits', odds: 100, grade: 'A', confidence: 70, gameId: 'g2' }, + { player: 'C', stat: 'goals', odds: 100, grade: 'A', confidence: 70, gameId: 'g3' }, + ]); + expect(r.combinedDecimal).toBeCloseTo(8.0, 5); // 2×2×2 + expect(r.combinedOdds).toBe(700); + }); + + test('combined grade is confidence-weighted', () => { + const r = calculateParlay([ + { player: 'A', stat: 'points', odds: -110, grade: 'A', confidence: 90 }, + { player: 'B', stat: 'hits', odds: -110, grade: 'C', confidence: 10, gameId: 'g2' }, + ]); + // Heavily weighted toward the A leg. + expect(['A-', 'A', 'B+']).toContain(r.combinedGrade); + }); + + test('payoutPer10 computed', () => { + const r = calculateParlay([{ player: 'A', stat: 'points', odds: 100, grade: 'B' }]); + expect(r.payoutPer10).toBe(20); // $10 at +100 → $20 total + }); + + test('empty legs → 400 error, not crash', () => { + expect(() => calculateParlay([])).toThrow(); + try { calculateParlay([]); } catch (e) { expect(e.statusCode).toBe(400); } + }); + + test('kill conditions aggregated', () => { + const r = calculateParlay([ + { player: 'A', stat: 'points', odds: -110, grade: 'B', killConditions: ['blowout risk'] }, + { player: 'B', stat: 'hits', odds: -110, grade: 'B', gameId: 'g2' }, + ]); + expect(r.hasKillCondition).toBe(true); + expect(r.killConditions[0].player).toBe('A'); + }); +}); + +describe('parlayService — correlation detection', () => { + test('different games → independent', () => { + const c = detectCorrelation( + { player: 'A', stat: 'points', gameId: 'g1', team: 'X' }, + { player: 'B', stat: 'assists', gameId: 'g2', team: 'Y' }, + ); + expect(c.correlated).toBe(false); + expect(c.type).toBe('independent'); + }); + + test('same-game teammates assists+points → positive', () => { + const c = detectCorrelation( + { player: 'A', stat: 'assists', gameId: 'g1', team: 'X' }, + { player: 'B', stat: 'points', gameId: 'g1', team: 'X' }, + ); + expect(c.correlated).toBe(true); + expect(c.type).toBe('positive'); + }); + + test('same-game opposing rebounds → negative (they fight)', () => { + const c = detectCorrelation( + { player: 'A', stat: 'rebounds', gameId: 'g1', team: 'X' }, + { player: 'B', stat: 'rebounds', gameId: 'g1', team: 'Y' }, + ); + expect(c.correlated).toBe(true); + expect(c.type).toBe('negative'); + }); + + test('same player opposite sides on same prop → negative conflict', () => { + const c = detectCorrelation( + { player: 'A', stat: 'points', side: 'over', gameId: 'g1' }, + { player: 'A', stat: 'points', side: 'under', gameId: 'g1' }, + ); + expect(c.type).toBe('negative'); + }); + + test('negative correlation surfaced on the parlay', () => { + const r = calculateParlay([ + { player: 'A', stat: 'rebounds', side: 'over', odds: -110, grade: 'B', gameId: 'g1', team: 'X' }, + { player: 'B', stat: 'rebounds', side: 'over', odds: -110, grade: 'B', gameId: 'g1', team: 'Y' }, + ]); + expect(r.hasNegativeCorrelation).toBe(true); + expect(r.correlations).toHaveLength(1); + }); +}); + +describe('parlayService — suggestParlays', () => { + const pool = [ + { player: 'A', stat: 'points', odds: -110, grade: 'A', gameId: 'g1', team: 'X' }, + { player: 'B', stat: 'hits', odds: -110, grade: 'A-', gameId: 'g2', team: 'Y' }, + { player: 'C', stat: 'goals', odds: -110, grade: 'B+', gameId: 'g3', team: 'Z' }, + { player: 'D', stat: 'assists', odds: -110, grade: 'B', gameId: 'g4', team: 'W' }, + ]; + + test('returns a suggestion of the requested leg count', () => { + const s = suggestParlays(pool, { legs: 3, max: 1 }); + expect(s).toHaveLength(1); + expect(s[0].legs).toHaveLength(3); + expect(s[0].combinedGrade).toBeDefined(); + }); + + test('too few props → empty', () => { + expect(suggestParlays([pool[0]], { legs: 3 })).toEqual([]); + }); +}); diff --git a/web/public/sw.js b/web/public/sw.js index 6916d30..9a52ddc 100644 --- a/web/public/sw.js +++ b/web/public/sw.js @@ -1,2 +1,2 @@ (()=>{"use strict";let e,t,a,s,r,i={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"serwist",runtime:"runtime",suffix:"u">typeof registration?registration.scope:""},n=e=>[i.prefix,e,i.suffix].filter(e=>e&&e.length>0).join("-"),c=e=>e||n(i.precache),o=e=>e||n(i.runtime);var l=class extends Error{details;constructor(e,t){super(((e,...t)=>{let a=e;return t.length>0&&(a+=` :: ${JSON.stringify(t)}`),a})(e,t)),this.name=e,this.details=t}};function h(e){return new Promise(t=>setTimeout(t,e))}let u=new Set;function d(e,t){let a=new URL(e);for(let e of t)a.searchParams.delete(e);return a.href}async function f(e,t,a,s){let r=d(t.url,a);if(t.url===r)return e.match(t,s);let i={...s,ignoreSearch:!0};for(let n of(await e.keys(t,i)))if(r===d(n.url,a))return e.match(n,s)}var p=class{promise;resolve;reject;constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}};let m=async()=>{for(let e of u)await e()},w="-precache-",g=async(e,t=w)=>{let a=(await self.caches.keys()).filter(a=>a.includes(t)&&a.includes(self.registration.scope)&&a!==e);return await Promise.all(a.map(e=>self.caches.delete(e))),a},y=(e,t)=>{let a=t();return e.waitUntil(a),a},_=(e,t)=>t.some(t=>e instanceof t),b=new WeakMap,v=new WeakMap,R=new WeakMap,E={get(e,t,a){if(e instanceof IDBTransaction){if("done"===t)return b.get(e);if("store"===t)return a.objectStoreNames[1]?void 0:a.objectStore(a.objectStoreNames[0])}return q(e[t])},set:(e,t,a)=>(e[t]=a,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function q(e){if(e instanceof IDBRequest){let t;return t=new Promise((t,a)=>{let s=()=>{e.removeEventListener("success",r),e.removeEventListener("error",i)},r=()=>{t(q(e.result)),s()},i=()=>{a(e.error),s()};e.addEventListener("success",r),e.addEventListener("error",i)}),R.set(t,e),t}if(v.has(e))return v.get(e);let t=function(e){if("function"==typeof e)return(r||(r=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(x(this),t),q(this.request)}:function(...t){return q(e.apply(x(this),t))};return(e instanceof IDBTransaction&&function(e){if(b.has(e))return;let t=new Promise((t,a)=>{let s=()=>{e.removeEventListener("complete",r),e.removeEventListener("error",i),e.removeEventListener("abort",i)},r=()=>{t(),s()},i=()=>{a(e.error||new DOMException("AbortError","AbortError")),s()};e.addEventListener("complete",r),e.addEventListener("error",i),e.addEventListener("abort",i)});b.set(e,t)}(e),_(e,s||(s=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])))?new Proxy(e,E):e}(e);return t!==e&&(v.set(e,t),R.set(t,e)),t}let x=e=>R.get(e);function D(e,t,{blocked:a,upgrade:s,blocking:r,terminated:i}={}){let n=indexedDB.open(e,t),c=q(n);return s&&n.addEventListener("upgradeneeded",e=>{s(q(n.result),e.oldVersion,e.newVersion,q(n.transaction),e)}),a&&n.addEventListener("blocked",e=>a(e.oldVersion,e.newVersion,e)),c.then(e=>{i&&e.addEventListener("close",()=>i()),r&&e.addEventListener("versionchange",e=>r(e.oldVersion,e.newVersion,e))}).catch(()=>{}),c}let S=["get","getKey","getAll","getAllKeys","count"],k=["put","add","delete","clear"],T=new Map;function P(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&"string"==typeof t))return;if(T.get(t))return T.get(t);let a=t.replace(/FromIndex$/,""),s=t!==a,r=k.includes(a);if(!(a in(s?IDBIndex:IDBObjectStore).prototype)||!(r||S.includes(a)))return;let i=async function(e,...t){let i=this.transaction(e,r?"readwrite":"readonly"),n=i.store;return s&&(n=n.index(t.shift())),(await Promise.all([n[a](...t),r&&i.done]))[0]};return T.set(t,i),i}E={...e=E,get:(t,a,s)=>P(t,a)||e.get(t,a,s),has:(t,a)=>!!P(t,a)||e.has(t,a)};let C=["continue","continuePrimaryKey","advance"],N={},I=new WeakMap,U=new WeakMap,L={get(e,t){if(!C.includes(t))return e[t];let a=N[t];return a||(a=N[t]=function(...e){I.set(this,U.get(this)[t](...e))}),a}};async function*A(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;let a=new Proxy(t,L);for(U.set(a,t),R.set(a,x(t));t;)yield a,t=await (I.get(a)||t.continue()),I.delete(a)}function O(e,t){return t===Symbol.asyncIterator&&_(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&_(e,[IDBIndex,IDBObjectStore])}E={...t=E,get:(e,a,s)=>O(e,a)?A:t.get(e,a,s),has:(e,a)=>O(e,a)||t.has(e,a)};let M=async(e,t)=>{let s=null;if(e.url&&(s=new URL(e.url).origin),s!==self.location.origin)throw new l("cross-origin-copy-response",{origin:s});let r=e.clone(),i={headers:new Headers(r.headers),status:r.status,statusText:r.statusText},n=t?t(i):i,c=!function(){if(void 0===a){let e=new Response("");if("body"in e)try{new Response(e.body),a=!0}catch{a=!1}a=!1}return a}()?await r.blob():r.body;return new Response(c,n)},B="requests",K="queueName";var F=class{_db=null;async addEntry(e){let t=(await this.getDb()).transaction(B,"readwrite",{durability:"relaxed"});await t.store.add(e),await t.done}async getFirstEntryId(){return(await (await this.getDb()).transaction(B).store.openCursor())?.value.id}async getAllEntriesByQueueName(e){return await (await this.getDb()).getAllFromIndex(B,K,IDBKeyRange.only(e))||[]}async getEntryCountByQueueName(e){return(await this.getDb()).countFromIndex(B,K,IDBKeyRange.only(e))}async deleteEntry(e){await (await this.getDb()).delete(B,e)}async getFirstEntryByQueueName(e){return await this.getEndEntryFromIndex(IDBKeyRange.only(e),"next")}async getLastEntryByQueueName(e){return await this.getEndEntryFromIndex(IDBKeyRange.only(e),"prev")}async getEndEntryFromIndex(e,t){return(await (await this.getDb()).transaction(B).store.index(K).openCursor(e,t))?.value}async getDb(){return this._db||(this._db=await D("serwist-background-sync",3,{upgrade:this._upgradeDb})),this._db}_upgradeDb(e,t){t>0&&t<3&&e.objectStoreNames.contains(B)&&e.deleteObjectStore(B),e.createObjectStore(B,{autoIncrement:!0,keyPath:"id"}).createIndex(K,K,{unique:!1})}},W=class{_queueName;_queueDb;constructor(e){this._queueName=e,this._queueDb=new F}async pushEntry(e){delete e.id,e.queueName=this._queueName,await this._queueDb.addEntry(e)}async unshiftEntry(e){let t=await this._queueDb.getFirstEntryId();t?e.id=t-1:delete e.id,e.queueName=this._queueName,await this._queueDb.addEntry(e)}async popEntry(){return this._removeEntry(await this._queueDb.getLastEntryByQueueName(this._queueName))}async shiftEntry(){return this._removeEntry(await this._queueDb.getFirstEntryByQueueName(this._queueName))}async getAll(){return await this._queueDb.getAllEntriesByQueueName(this._queueName)}async size(){return await this._queueDb.getEntryCountByQueueName(this._queueName)}async deleteEntry(e){await this._queueDb.deleteEntry(e)}async _removeEntry(e){return e&&await this.deleteEntry(e.id),e}};let j=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];var H=class e{_requestData;static async fromRequest(t){let a={url:t.url,headers:{}};for(let e of("GET"!==t.method&&(a.body=await t.clone().arrayBuffer()),t.headers.forEach((e,t)=>{a.headers[t]=e}),j))void 0!==t[e]&&(a[e]=t[e]);return new e(a)}constructor(e){"navigate"===e.mode&&(e.mode="same-origin"),this._requestData=e}toObject(){let e=Object.assign({},this._requestData);return e.headers=Object.assign({},this._requestData.headers),e.body&&(e.body=e.body.slice(0)),e}toRequest(){return new Request(this._requestData.url,this._requestData)}clone(){return new e(this.toObject())}};let $="serwist-background-sync",V=new Set,Q=e=>{let t={request:new H(e.requestData).toRequest(),timestamp:e.timestamp};return e.metadata&&(t.metadata=e.metadata),t};var G=class{_name;_onSync;_maxRetentionTime;_queueStore;_forceSyncFallback;_syncInProgress=!1;_requestsAddedDuringSync=!1;constructor(e,{forceSyncFallback:t,onSync:a,maxRetentionTime:s}={}){if(V.has(e))throw new l("duplicate-queue-name",{name:e});V.add(e),this._name=e,this._onSync=a||this.replayRequests,this._maxRetentionTime=s||10080,this._forceSyncFallback=!!t,this._queueStore=new W(this._name),this._addSyncListener()}get name(){return this._name}async pushRequest(e){await this._addRequest(e,"push")}async unshiftRequest(e){await this._addRequest(e,"unshift")}async popRequest(){return this._removeRequest("pop")}async shiftRequest(){return this._removeRequest("shift")}async getAll(){let e=await this._queueStore.getAll(),t=Date.now(),a=[];for(let s of e){let e=60*this._maxRetentionTime*1e3;t-s.timestamp>e?await this._queueStore.deleteEntry(s.id):a.push(Q(s))}return a}async size(){return await this._queueStore.size()}async _addRequest({request:e,metadata:t,timestamp:a=Date.now()},s){let r={requestData:(await H.fromRequest(e.clone())).toObject(),timestamp:a};switch(t&&(r.metadata=t),s){case"push":await this._queueStore.pushEntry(r);break;case"unshift":await this._queueStore.unshiftEntry(r)}this._syncInProgress?this._requestsAddedDuringSync=!0:await this.registerSync()}async _removeRequest(e){let t,a=Date.now();switch(e){case"pop":t=await this._queueStore.popEntry();break;case"shift":t=await this._queueStore.shiftEntry()}if(t){let s=60*this._maxRetentionTime*1e3;return a-t.timestamp>s?this._removeRequest(e):Q(t)}}async replayRequests(){let e;for(;e=await this.shiftRequest();)try{await fetch(e.request.clone())}catch{throw await this.unshiftRequest(e),new l("queue-replay-failed",{name:this._name})}}async registerSync(){if("sync"in self.registration&&!this._forceSyncFallback)try{await self.registration.sync.register(`${$}:${this._name}`)}catch(e){}}_addSyncListener(){"sync"in self.registration&&!this._forceSyncFallback?self.addEventListener("sync",e=>{if(e.tag===`${$}:${this._name}`){let t=async()=>{let t;this._syncInProgress=!0;try{await this._onSync({queue:this})}catch(e){if(e instanceof Error)throw e}finally{this._requestsAddedDuringSync&&!(t&&!e.lastChance)&&await this.registerSync(),this._syncInProgress=!1,this._requestsAddedDuringSync=!1}};e.waitUntil(t())}}):this._onSync({queue:this})}static get _queueNames(){return V}},z=class{_queue;constructor(e,t){this._queue=new G(e,t)}async fetchDidFail({request:e}){await this._queue.pushRequest({request:e})}};let Y={cacheWillUpdate:async({response:e})=>200===e.status||0===e.status?e:null};function J(e){return"string"==typeof e?new Request(e):e}var X=class{event;request;url;params;_cacheKeys={};_strategy;_handlerDeferred;_extendLifetimePromises;_plugins;_pluginStateMap;constructor(e,t){for(const a of(this.event=t.event,this.request=t.request,t.url&&(this.url=t.url,this.params=t.params),this._strategy=e,this._handlerDeferred=new p,this._extendLifetimePromises=[],this._plugins=[...e.plugins],this._pluginStateMap=new Map,this._plugins))this._pluginStateMap.set(a,{});this.event.waitUntil(this._handlerDeferred.promise)}async fetch(e){let{event:t}=this,a=J(e),s=await this.getPreloadResponse();if(s)return s;let r=this.hasCallback("fetchDidFail")?a.clone():null;try{for(let e of this.iterateCallbacks("requestWillFetch"))a=await e({request:a.clone(),event:t})}catch(e){if(e instanceof Error)throw new l("plugin-error-request-will-fetch",{thrownErrorMessage:e.message})}let i=a.clone();try{let e;for(let s of(e=await fetch(a,"navigate"===a.mode?void 0:this._strategy.fetchOptions),this.iterateCallbacks("fetchDidSucceed")))e=await s({event:t,request:i,response:e});return e}catch(e){throw r&&await this.runCallbacks("fetchDidFail",{error:e,event:t,originalRequest:r.clone(),request:i.clone()}),e}}async fetchAndCachePut(e){let t=await this.fetch(e),a=t.clone();return this.waitUntil(this.cachePut(e,a)),t}async cacheMatch(e){let t,a=J(e),{cacheName:s,matchOptions:r}=this._strategy,i=await this.getCacheKey(a,"read"),n={...r,cacheName:s};for(let e of(t=await caches.match(i,n),this.iterateCallbacks("cachedResponseWillBeUsed")))t=await e({cacheName:s,matchOptions:r,cachedResponse:t,request:i,event:this.event})||void 0;return t}async cachePut(e,t){let a=J(e);await h(0);let s=await this.getCacheKey(a,"write");if(!t)throw new l("cache-put-with-no-response",{url:new URL(String(s.url),location.href).href.replace(RegExp(`^${location.origin}`),"")});let r=await this._ensureResponseSafeToCache(t);if(!r)return!1;let{cacheName:i,matchOptions:n}=this._strategy,c=await self.caches.open(i),o=this.hasCallback("cacheDidUpdate"),u=o?await f(c,s.clone(),["__WB_REVISION__"],n):null;try{await c.put(s,o?r.clone():r)}catch(e){if(e instanceof Error)throw"QuotaExceededError"===e.name&&await m(),e}for(let e of this.iterateCallbacks("cacheDidUpdate"))await e({cacheName:i,oldResponse:u,newResponse:r.clone(),request:s,event:this.event});return!0}async getCacheKey(e,t){let a=`${e.url} | ${t}`;if(!this._cacheKeys[a]){let s=e;for(let e of this.iterateCallbacks("cacheKeyWillBeUsed"))s=J(await e({mode:t,request:s,event:this.event,params:this.params}));this._cacheKeys[a]=s}return this._cacheKeys[a]}hasCallback(e){for(let t of this._strategy.plugins)if(e in t)return!0;return!1}async runCallbacks(e,t){for(let a of this.iterateCallbacks(e))await a(t)}*iterateCallbacks(e){for(let t of this._strategy.plugins)if("function"==typeof t[e]){let a=this._pluginStateMap.get(t),s=s=>{let r={...s,state:a};return t[e](r)};yield s}}waitUntil(e){return this._extendLifetimePromises.push(e),e}async doneWaiting(){let e;for(;e=this._extendLifetimePromises.shift();)await e}destroy(){this._handlerDeferred.resolve(null)}async getPreloadResponse(){if(this.event instanceof FetchEvent&&"navigate"===this.event.request.mode&&"preloadResponse"in this.event)try{let e=await this.event.preloadResponse;if(e)return e}catch(e){return}}async _ensureResponseSafeToCache(e){let t=e,a=!1;for(let e of this.iterateCallbacks("cacheWillUpdate"))if(t=await e({request:this.request,response:t,event:this.event})||void 0,a=!0,!t)break;return!a&&t&&200!==t.status&&(t=void 0),t}},Z=class{cacheName;plugins;fetchOptions;matchOptions;constructor(e={}){this.cacheName=o(e.cacheName),this.plugins=e.plugins||[],this.fetchOptions=e.fetchOptions,this.matchOptions=e.matchOptions}handle(e){let[t]=this.handleAll(e);return t}handleAll(e){e instanceof FetchEvent&&(e={event:e,request:e.request});let t=e.event,a="string"==typeof e.request?new Request(e.request):e.request,s=new X(this,e.url?{event:t,request:a,url:e.url,params:e.params}:{event:t,request:a}),r=this._getResponse(s,a,t);return[r,this._awaitComplete(r,s,a,t)]}async _getResponse(e,t,a){let s;await e.runCallbacks("handlerWillStart",{event:a,request:t});try{if(s=await this._handle(t,e),void 0===s||"error"===s.type)throw new l("no-response",{url:t.url})}catch(r){if(r instanceof Error){for(let i of e.iterateCallbacks("handlerDidError"))if(void 0!==(s=await i({error:r,event:a,request:t})))break}if(!s)throw r}for(let r of e.iterateCallbacks("handlerWillRespond"))s=await r({event:a,request:t,response:s});return s}async _awaitComplete(e,t,a,s){let r,i;try{r=await e}catch{}try{await t.runCallbacks("handlerDidRespond",{event:s,request:a,response:r}),await t.doneWaiting()}catch(e){e instanceof Error&&(i=e)}if(await t.runCallbacks("handlerDidComplete",{event:s,request:a,response:r,error:i}),t.destroy(),i)throw i}},ee=class extends Z{_networkTimeoutSeconds;constructor(e={}){super(e),this.plugins.some(e=>"cacheWillUpdate"in e)||this.plugins.unshift(Y),this._networkTimeoutSeconds=e.networkTimeoutSeconds||0}async _handle(e,t){let a,s=[],r=[];if(this._networkTimeoutSeconds){let{id:i,promise:n}=this._getTimeoutPromise({request:e,logs:s,handler:t});a=i,r.push(n)}let i=this._getNetworkPromise({timeoutId:a,request:e,logs:s,handler:t});r.push(i);let n=await t.waitUntil((async()=>await t.waitUntil(Promise.race(r))||await i)());if(!n)throw new l("no-response",{url:e.url});return n}_getTimeoutPromise({request:e,logs:t,handler:a}){let s;return{promise:new Promise(t=>{s=setTimeout(async()=>{t(await a.cacheMatch(e))},1e3*this._networkTimeoutSeconds)}),id:s}}async _getNetworkPromise({timeoutId:e,request:t,logs:a,handler:s}){let r,i;try{i=await s.fetchAndCachePut(t)}catch(e){e instanceof Error&&(r=e)}return e&&clearTimeout(e),(r||!i)&&(i=await s.cacheMatch(t)),i}},et=class extends Z{_networkTimeoutSeconds;constructor(e={}){super(e),this._networkTimeoutSeconds=e.networkTimeoutSeconds||0}async _handle(e,t){let a,s;try{let a=[t.fetch(e)];if(this._networkTimeoutSeconds){let e=h(1e3*this._networkTimeoutSeconds);a.push(e)}if(!(s=await Promise.race(a)))throw Error(`Timed out the network response after ${this._networkTimeoutSeconds} seconds.`)}catch(e){e instanceof Error&&(a=e)}if(!s)throw new l("no-response",{url:e.url,error:a});return s}};let ea=e=>e&&"object"==typeof e?e:{handle:e};var es=class{handler;match;method;catchHandler;constructor(e,t,a="GET"){this.handler=ea(t),this.match=e,this.method=a}setCatchHandler(e){this.catchHandler=ea(e)}},er=class e extends Z{_fallbackToNetwork;static defaultPrecacheCacheabilityPlugin={cacheWillUpdate:async({response:e})=>!e||e.status>=400?null:e};static copyRedirectedCacheableResponsesPlugin={cacheWillUpdate:async({response:e})=>e.redirected?await M(e):e};constructor(t={}){t.cacheName=c(t.cacheName),super(t),this._fallbackToNetwork=!1!==t.fallbackToNetwork,this.plugins.push(e.copyRedirectedCacheableResponsesPlugin)}async _handle(e,t){let a=await t.getPreloadResponse();if(a)return a;let s=await t.cacheMatch(e);return s||(t.event&&"install"===t.event.type?await this._handleInstall(e,t):await this._handleFetch(e,t))}async _handleFetch(e,t){let a,s=t.params||{};if(this._fallbackToNetwork){let r=s.integrity,i=e.integrity,n=!i||i===r;a=await t.fetch(new Request(e,{integrity:"no-cors"!==e.mode?i||r:void 0})),r&&n&&"no-cors"!==e.mode&&(this._useDefaultCacheabilityPluginIfNeeded(),await t.cachePut(e,a.clone()))}else throw new l("missing-precache-entry",{cacheName:this.cacheName,url:e.url});return a}async _handleInstall(e,t){this._useDefaultCacheabilityPluginIfNeeded();let a=await t.fetch(e);if(!await t.cachePut(e,a.clone()))throw new l("bad-precaching-response",{url:e.url,status:a.status});return a}_useDefaultCacheabilityPluginIfNeeded(){let t=null,a=0;for(let[s,r]of this.plugins.entries())r!==e.copyRedirectedCacheableResponsesPlugin&&(r===e.defaultPrecacheCacheabilityPlugin&&(t=s),r.cacheWillUpdate&&a++);0===a?this.plugins.push(e.defaultPrecacheCacheabilityPlugin):a>1&&null!==t&&this.plugins.splice(t,1)}},ei=class extends es{_allowlist;_denylist;constructor(e,{allowlist:t=[/./],denylist:a=[]}={}){super(e=>this._match(e),e),this._allowlist=t,this._denylist=a}_match({url:e,request:t}){if(t&&"navigate"!==t.mode)return!1;let a=e.pathname+e.search;for(let e of this._denylist)if(e.test(a))return!1;return!!this._allowlist.some(e=>e.test(a))}},en=class extends es{constructor(e,t,a){super(({url:t})=>{let a=e.exec(t.href);if(a)return t.origin!==location.origin&&0!==a.index?void 0:a.slice(1)},t,a)}};let ec=e=>{if(!e)throw new l("add-to-cache-list-unexpected-type",{entry:e});if("string"==typeof e){let t=new URL(e,location.href);return{cacheKey:t.href,url:t.href}}let{revision:t,url:a}=e;if(!a)throw new l("add-to-cache-list-unexpected-type",{entry:e});if(!t){let e=new URL(a,location.href);return{cacheKey:e.href,url:e.href}}let s=new URL(a,location.href),r=new URL(a,location.href);return s.searchParams.set("__WB_REVISION__",t),{cacheKey:s.href,url:r.href}};var eo=class{updatedURLs=[];notUpdatedURLs=[];handlerWillStart=async({request:e,state:t})=>{t&&(t.originalRequest=e)};cachedResponseWillBeUsed=async({event:e,state:t,cachedResponse:a})=>{if("install"===e.type&&t?.originalRequest&&t.originalRequest instanceof Request){let e=t.originalRequest.url;a?this.notUpdatedURLs.push(e):this.updatedURLs.push(e)}return a}};let el=async(e,t,a)=>{let s=t.map((e,t)=>({index:t,item:e})),r=async e=>{let t=[];for(;;){let r=s.pop();if(!r)return e(t);let i=await a(r.item);t.push({result:i,index:r.index})}},i=Array.from({length:e},()=>new Promise(r));return(await Promise.all(i)).flat().sort((e,t)=>e.indexe.result)};"u">typeof navigator&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent);let eh="cache-entries",eu=e=>{let t=new URL(e,location.href);return t.hash="",t.href};var ed=class{_cacheName;_db=null;constructor(e){this._cacheName=e}_getId(e){return`${this._cacheName}|${eu(e)}`}_upgradeDb(e){let t=e.createObjectStore(eh,{keyPath:"id"});t.createIndex("cacheName","cacheName",{unique:!1}),t.createIndex("timestamp","timestamp",{unique:!1})}_upgradeDbAndDeleteOldDbs(e){this._upgradeDb(e),this._cacheName&&function(e,{blocked:t}={}){let a=indexedDB.deleteDatabase(e);t&&a.addEventListener("blocked",e=>t(e.oldVersion,e)),q(a).then(()=>void 0)}(this._cacheName)}async setTimestamp(e,t){e=eu(e);let a={id:this._getId(e),cacheName:this._cacheName,url:e,timestamp:t},s=(await this.getDb()).transaction(eh,"readwrite",{durability:"relaxed"});await s.store.put(a),await s.done}async getTimestamp(e){return(await (await this.getDb()).get(eh,this._getId(e)))?.timestamp}async expireEntries(e,t){let a=await (await this.getDb()).transaction(eh,"readwrite").store.index("timestamp").openCursor(null,"prev"),s=[],r=0;for(;a;){let i=a.value;i.cacheName===this._cacheName&&(e&&i.timestamp=t?(a.delete(),s.push(i.url)):r++),a=await a.continue()}return s}async getDb(){return this._db||(this._db=await D("serwist-expiration",1,{upgrade:this._upgradeDbAndDeleteOldDbs.bind(this)})),this._db}},ef=class{_isRunning=!1;_rerunRequested=!1;_maxEntries;_maxAgeSeconds;_matchOptions;_cacheName;_timestampModel;constructor(e,t={}){this._maxEntries=t.maxEntries,this._maxAgeSeconds=t.maxAgeSeconds,this._matchOptions=t.matchOptions,this._cacheName=e,this._timestampModel=new ed(e)}async expireEntries(){if(this._isRunning){this._rerunRequested=!0;return}this._isRunning=!0;let e=this._maxAgeSeconds?Date.now()-1e3*this._maxAgeSeconds:0,t=await this._timestampModel.expireEntries(e,this._maxEntries),a=await self.caches.open(this._cacheName);for(let e of t)await a.delete(e,this._matchOptions);this._isRunning=!1,this._rerunRequested&&(this._rerunRequested=!1,this.expireEntries())}async updateTimestamp(e){await this._timestampModel.setTimestamp(e,Date.now())}async isURLExpired(e){if(!this._maxAgeSeconds)return!1;let t=await this._timestampModel.getTimestamp(e),a=Date.now()-1e3*this._maxAgeSeconds;return void 0===t||t{u.add(e)})(()=>this.deleteCacheAndMetadata())}_getCacheExpiration(e){if(e===o())throw new l("expire-custom-caches-only");let t=this._cacheExpirations.get(e);return t||(t=new ef(e,this._config),this._cacheExpirations.set(e,t)),t}cachedResponseWillBeUsed({event:e,cacheName:t,request:a,cachedResponse:s}){if(!s)return null;let r=this._isResponseDateFresh(s),i=this._getCacheExpiration(t),n="last-used"===this._config.maxAgeFrom,c=(async()=>{n&&await i.updateTimestamp(a.url),await i.expireEntries()})();try{e.waitUntil(c)}catch{}return r?s:null}_isResponseDateFresh(e){if("last-used"===this._config.maxAgeFrom)return!0;let t=Date.now();if(!this._config.maxAgeSeconds)return!0;let a=this._getDateHeaderTimestamp(e);return null===a||a>=t-1e3*this._config.maxAgeSeconds}_getDateHeaderTimestamp(e){if(!e.headers.has("date"))return null;let t=new Date(e.headers.get("date")).getTime();return Number.isNaN(t)?null:t}async cacheDidUpdate({cacheName:e,request:t}){let a=this._getCacheExpiration(e);await a.updateTimestamp(t.url),await a.expireEntries()}async deleteCacheAndMetadata(){for(let[e,t]of this._cacheExpirations)await self.caches.delete(e),await t.delete();this._cacheExpirations=new Map}};let em=/^\/(\w+\/)?collect/,ew=({serwist:e,cacheName:t,...a})=>{let s,r,c=t||n(i.googleAnalytics),o=new z("serwist-google-analytics",{maxRetentionTime:2880,onSync:async({queue:e})=>{let t;for(;t=await e.shiftRequest();){let{request:s,timestamp:r}=t,i=new URL(s.url);try{let e="POST"===s.method?new URLSearchParams(await s.clone().text()):i.searchParams,t=r-(Number(e.get("qt"))||0),n=Date.now()-t;if(e.set("qt",String(n)),a.parameterOverrides)for(let t of Object.keys(a.parameterOverrides)){let s=a.parameterOverrides[t];e.set(t,s)}"function"==typeof a.hitFilter&&a.hitFilter.call(null,e),await fetch(new Request(i.origin+i.pathname,{body:e.toString(),method:"POST",mode:"cors",credentials:"omit",headers:{"Content-Type":"text/plain"}}))}catch(a){throw await e.unshiftRequest(t),a}}}});for(let t of[new es(({url:e})=>"www.googletagmanager.com"===e.hostname&&"/gtm.js"===e.pathname,new ee({cacheName:c}),"GET"),new es(({url:e})=>"www.google-analytics.com"===e.hostname&&"/analytics.js"===e.pathname,new ee({cacheName:c}),"GET"),new es(({url:e})=>"www.googletagmanager.com"===e.hostname&&"/gtag/js"===e.pathname,new ee({cacheName:c}),"GET"),new es(s=({url:e})=>"www.google-analytics.com"===e.hostname&&em.test(e.pathname),r=new et({plugins:[o]}),"GET"),new es(s,r,"POST")])e.registerRoute(t)};var eg=class{_fallbackUrls;_serwist;constructor({fallbackUrls:e,serwist:t}){this._fallbackUrls=e,this._serwist=t}async handlerDidError(e){for(let t of this._fallbackUrls)if("string"==typeof t){let e=await this._serwist.matchPrecache(t);if(void 0!==e)return e}else if(t.matcher(e)){let e=await this._serwist.matchPrecache(t.url);if(void 0!==e)return e}}},ey=class extends Z{async _handle(e,t){let a,s=await t.cacheMatch(e);if(s);else try{s=await t.fetchAndCachePut(e)}catch(e){e instanceof Error&&(a=e)}if(!s)throw new l("no-response",{url:e.url,error:a});return s}},e_=class extends es{constructor(e,t){super(({request:a})=>{let s=e.getUrlsToPrecacheKeys();for(let r of function*(e,{directoryIndex:t="index.html",ignoreURLParametersMatching:a=[/^utm_/,/^fbclid$/],cleanURLs:s=!0,urlManipulation:r}={}){let i=new URL(e,location.href);i.hash="",yield i.href;let n=((e,t=[])=>{for(let a of[...e.searchParams.keys()])t.some(e=>e.test(a))&&e.searchParams.delete(a);return e})(i,a);if(yield n.href,t&&n.pathname.endsWith("/")){let e=new URL(n.href);e.pathname+=t,yield e.href}if(s){let e=new URL(n.href);e.pathname+=".html",yield e.href}if(r)for(let e of r({url:i}))yield e.href}(a.url,t)){let t=s.get(r);if(t)return{cacheKey:t,integrity:e.getIntegrityForPrecacheKey(t)}}},e.precacheStrategy)}},eb=class{_precacheController;constructor({precacheController:e}){this._precacheController=e}cacheKeyWillBeUsed=async({request:e,params:t})=>{let a=t?.cacheKey||this._precacheController.getPrecacheKeyForUrl(e.url);return a?new Request(a,{headers:e.headers}):e}},ev=class{_urlsToCacheKeys=new Map;_urlsToCacheModes=new Map;_cacheKeysToIntegrities=new Map;_concurrentPrecaching;_precacheStrategy;_routes;_defaultHandlerMap;_catchHandler;_requestRules;constructor({precacheEntries:e,precacheOptions:t,skipWaiting:a=!1,importScripts:s,navigationPreload:r=!1,cacheId:n,clientsClaim:o=!1,runtimeCaching:l,offlineAnalyticsConfig:h,disableDevLogs:u=!1,fallbacks:d,requestRules:f}={}){const{precacheStrategyOptions:p,precacheRouteOptions:m,precacheMiscOptions:w}=((e,t={})=>{let{cacheName:a,plugins:s=[],fetchOptions:r,matchOptions:i,fallbackToNetwork:n,directoryIndex:o,ignoreURLParametersMatching:l,cleanURLs:h,urlManipulation:u,cleanupOutdatedCaches:d,concurrency:f=10,navigateFallback:p,navigateFallbackAllowlist:m,navigateFallbackDenylist:w}=t??{};return{precacheStrategyOptions:{cacheName:c(a),plugins:[...s,new eb({precacheController:e})],fetchOptions:r,matchOptions:i,fallbackToNetwork:n},precacheRouteOptions:{directoryIndex:o,ignoreURLParametersMatching:l,cleanURLs:h,urlManipulation:u},precacheMiscOptions:{cleanupOutdatedCaches:d,concurrency:f,navigateFallback:p,navigateFallbackAllowlist:m,navigateFallbackDenylist:w}}})(this,t);if(this._concurrentPrecaching=w.concurrency,this._precacheStrategy=new er(p),this._routes=new Map,this._defaultHandlerMap=new Map,this._requestRules=f,this.handleInstall=this.handleInstall.bind(this),this.handleActivate=this.handleActivate.bind(this),this.handleFetch=this.handleFetch.bind(this),this.handleCache=this.handleCache.bind(this),s&&s.length>0&&self.importScripts(...s),r&&self.registration?.navigationPreload&&self.addEventListener("activate",e=>{e.waitUntil(self.registration.navigationPreload.enable().then(()=>{}))}),void 0!==n&&(e=>{var t=e;for(let e of Object.keys(i))(e=>{let a=t[e];"string"==typeof a&&(i[e]=a)})(e)})({prefix:n}),a?self.skipWaiting():self.addEventListener("message",e=>{e.data&&"SKIP_WAITING"===e.data.type&&self.skipWaiting()}),o&&self.addEventListener("activate",()=>self.clients.claim()),e&&e.length>0&&this.addToPrecacheList(e),w.cleanupOutdatedCaches&&(e=>{self.addEventListener("activate",t=>{t.waitUntil(g(c(e)).then(e=>{}))})})(p.cacheName),this.registerRoute(new e_(this,m)),w.navigateFallback&&this.registerRoute(new ei(this.createHandlerBoundToUrl(w.navigateFallback),{allowlist:w.navigateFallbackAllowlist,denylist:w.navigateFallbackDenylist})),void 0!==h&&("boolean"==typeof h?h&&ew({serwist:this}):ew({...h,serwist:this})),void 0!==l){if(void 0!==d){const e=new eg({fallbackUrls:d.entries,serwist:this});l.forEach(t=>{t.handler instanceof Z&&!t.handler.plugins.some(e=>"handlerDidError"in e)&&t.handler.plugins.push(e)})}for(const e of l)this.registerCapture(e.matcher,e.handler,e.method)}u&&(self.__WB_DISABLE_DEV_LOGS=!0)}get precacheStrategy(){return this._precacheStrategy}get routes(){return this._routes}addEventListeners(){self.addEventListener("install",this.handleInstall),self.addEventListener("activate",this.handleActivate),self.addEventListener("fetch",this.handleFetch),self.addEventListener("message",this.handleCache)}addToPrecacheList(e){let t=[];for(let a of e){"string"==typeof a?t.push(a):a&&!a.integrity&&void 0===a.revision&&t.push(a.url);let{cacheKey:e,url:s}=ec(a),r="string"!=typeof a&&a.revision?"reload":"default";if(this._urlsToCacheKeys.has(s)&&this._urlsToCacheKeys.get(s)!==e)throw new l("add-to-cache-list-conflicting-entries",{firstEntry:this._urlsToCacheKeys.get(s),secondEntry:e});if("string"!=typeof a&&a.integrity){if(this._cacheKeysToIntegrities.has(e)&&this._cacheKeysToIntegrities.get(e)!==a.integrity)throw new l("add-to-cache-list-conflicting-integrities",{url:s});this._cacheKeysToIntegrities.set(e,a.integrity)}this._urlsToCacheKeys.set(s,e),this._urlsToCacheModes.set(s,r)}t.length>0&&console.warn(`Serwist is precaching URLs without revision info: ${t.join(", ")} -This is generally NOT safe. Learn more at https://bit.ly/wb-precache`)}handleInstall(e){return this.registerRequestRules(e),y(e,async()=>{let t=new eo;this.precacheStrategy.plugins.push(t),await el(this._concurrentPrecaching,Array.from(this._urlsToCacheKeys.entries()),async([t,a])=>{let s=this._cacheKeysToIntegrities.get(a),r=this._urlsToCacheModes.get(t),i=new Request(t,{integrity:s,cache:r,credentials:"same-origin"});await Promise.all(this.precacheStrategy.handleAll({event:e,request:i,url:new URL(i.url),params:{cacheKey:a}}))});let{updatedURLs:a,notUpdatedURLs:s}=t;return{updatedURLs:a,notUpdatedURLs:s}})}async registerRequestRules(e){if(this._requestRules&&e?.addRoutes)try{await e.addRoutes(this._requestRules),this._requestRules=void 0}catch(e){throw e}}handleActivate(e){return y(e,async()=>{let e=await self.caches.open(this.precacheStrategy.cacheName),t=await e.keys(),a=new Set(this._urlsToCacheKeys.values()),s=[];for(let r of t)a.has(r.url)||(await e.delete(r),s.push(r.url));return{deletedCacheRequests:s}})}handleFetch(e){let{request:t}=e,a=this.handleRequest({request:t,event:e});a&&e.respondWith(a)}handleCache(e){if(e.data&&"CACHE_URLS"===e.data.type){let{payload:t}=e.data,a=Promise.all(t.urlsToCache.map(t=>{let a;return a="string"==typeof t?new Request(t):new Request(...t),this.handleRequest({request:a,event:e})}));e.waitUntil(a),e.ports?.[0]&&a.then(()=>e.ports[0].postMessage(!0))}}setDefaultHandler(e,t="GET"){this._defaultHandlerMap.set(t,ea(e))}setCatchHandler(e){this._catchHandler=ea(e)}registerCapture(e,t,a){let s=((e,t,a)=>{if("string"==typeof e){let s=new URL(e,location.href);return new es(({url:e})=>e.href===s.href,t,a)}if(e instanceof RegExp)return new en(e,t,a);if("function"==typeof e)return new es(e,t,a);if(e instanceof es)return e;throw new l("unsupported-route-type",{moduleName:"serwist",funcName:"parseRoute",paramName:"capture"})})(e,t,a);return this.registerRoute(s),s}registerRoute(e){this._routes.has(e.method)||this._routes.set(e.method,[]),this._routes.get(e.method).push(e)}unregisterRoute(e){if(!this._routes.has(e.method))throw new l("unregister-route-but-not-found-with-method",{method:e.method});let t=this._routes.get(e.method).indexOf(e);if(t>-1)this._routes.get(e.method).splice(t,1);else throw new l("unregister-route-route-not-registered")}getUrlsToPrecacheKeys(){return this._urlsToCacheKeys}getPrecachedUrls(){return[...this._urlsToCacheKeys.keys()]}getPrecacheKeyForUrl(e){let t=new URL(e,location.href);return this._urlsToCacheKeys.get(t.href)}getIntegrityForPrecacheKey(e){return this._cacheKeysToIntegrities.get(e)}async matchPrecache(e){let t=e instanceof Request?e.url:e,a=this.getPrecacheKeyForUrl(t);if(a)return(await self.caches.open(this.precacheStrategy.cacheName)).match(a)}createHandlerBoundToUrl(e){let t=this.getPrecacheKeyForUrl(e);if(!t)throw new l("non-precached-url",{url:e});return a=>(a.request=new Request(e),a.params={cacheKey:t,...a.params},this.precacheStrategy.handle(a))}handleRequest({request:e,event:t}){let a,s=new URL(e.url,location.href);if(!s.protocol.startsWith("http"))return;let r=s.origin===location.origin,{params:i,route:n}=this.findMatchingRoute({event:t,request:e,sameOrigin:r,url:s}),c=n?.handler,o=e.method;if(!c&&this._defaultHandlerMap.has(o)&&(c=this._defaultHandlerMap.get(o)),!c)return;try{a=c.handle({url:s,request:e,event:t,params:i})}catch(e){a=Promise.reject(e)}let l=n?.catchHandler;return a instanceof Promise&&(this._catchHandler||l)&&(a=a.catch(async a=>{if(l)try{return await l.handle({url:s,request:e,event:t,params:i})}catch(e){e instanceof Error&&(a=e)}if(this._catchHandler)return this._catchHandler.handle({url:s,request:e,event:t});throw a})),a}findMatchingRoute({url:e,sameOrigin:t,request:a,event:s}){for(let r of this._routes.get(a.method)||[]){let i,n=r.match({url:e,sameOrigin:t,request:a,event:s});if(n)return Array.isArray(i=n)&&0===i.length||n.constructor===Object&&0===Object.keys(n).length?i=void 0:"boolean"==typeof n&&(i=void 0),{route:r,params:i}}return{}}};let eR="/offline",eE=["pages","api-responses","next-static","static-media","fallback","offline-fallback"],eq=[{matcher:({url:e,sameOrigin:t})=>t&&e.pathname.startsWith("/api/"),handler:new ee({cacheName:"api-responses",networkTimeoutSeconds:5,plugins:[new ep({maxEntries:100,maxAgeSeconds:3600})]})},{matcher:({request:e})=>"navigate"===e.mode,handler:new ee({cacheName:"pages",networkTimeoutSeconds:5,plugins:[new ep({maxEntries:50,maxAgeSeconds:86400}),{handlerDidError:async()=>await caches.match(eR)||Response.error()}]})},{matcher:({url:e,sameOrigin:t})=>t&&e.pathname.startsWith("/_next/static/"),handler:new ey({cacheName:"next-static",plugins:[new ep({maxEntries:200,maxAgeSeconds:2592e3})]})},{matcher:({url:e})=>e.pathname.startsWith("/images/")||e.pathname.startsWith("/icons/")||/\.(?:png|jpe?g|gif|svg|webp|ico|woff2?)$/.test(e.pathname),handler:new ey({cacheName:"static-media",plugins:[new ep({maxEntries:100,maxAgeSeconds:2592e3})]})},{matcher:()=>!0,handler:new ee({cacheName:"fallback",networkTimeoutSeconds:5,plugins:[new ep({maxEntries:50,maxAgeSeconds:86400})]})}];new ev({precacheEntries:[{'revision':null,'url':'/_next/static/chunks/1896-359ed2e68a8c4f1d.js'},{'revision':null,'url':'/_next/static/chunks/1958-56cbbb8dba15fd2f.js'},{'revision':null,'url':'/_next/static/chunks/2346-d63ba3de1d09a41e.js'},{'revision':null,'url':'/_next/static/chunks/4bd1b696-e356ca5ba0218e27.js'},{'revision':null,'url':'/_next/static/chunks/52774a7f.f2ab7a9b4b8ba576.js'},{'revision':null,'url':'/_next/static/chunks/5838-7e0aa455e9f24259.js'},{'revision':null,'url':'/_next/static/chunks/6810-65ea0987ee90a78b.js'},{'revision':null,'url':'/_next/static/chunks/7602.2868ff821d53ee09.js'},{'revision':null,'url':'/_next/static/chunks/7918-9cfe56e3ee27ed27.js'},{'revision':null,'url':'/_next/static/chunks/8500-f62a38ff68ab7f42.js'},{'revision':null,'url':'/_next/static/chunks/9da6db1e-9623f3245f088d02.js'},{'revision':null,'url':'/_next/static/chunks/app/_global-error/page-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/_not-found/page-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/account/page-f5e2a6d5e729cc87.js'},{'revision':null,'url':'/_next/static/chunks/app/admin/page-7653c5a94021e122.js'},{'revision':null,'url':'/_next/static/chunks/app/api/admin/stats/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/checkout/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/gamelines/%5Bsport%5D/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/props/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/tonight/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/hero-prop/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/hotlist/%5Bsport%5D/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/intelligence/feed/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/accuracy/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/mlb/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/nba/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/soccer/%5Bleague%5D/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/wnba/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/add-leg/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/grade/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/players/search/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/live/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/most-parlayed/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/top-graded/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/scan/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/schedule/%5Bsport%5D/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/parlays-graded/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/public/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/streaks/%5Bsport%5D/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/profile/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/recent-scans/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/scans/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/waitlist/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/webhook/nexapay/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/api/welcome-email/route-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/auth/callback/page-0cb8d3790d034de0.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/%5Bslug%5D/page-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/page-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/dashboard/page-e6a8c076ce48fe3c.js'},{'revision':null,'url':'/_next/static/chunks/app/forgot-password/page-a251f52b4206e8d1.js'},{'revision':null,'url':'/_next/static/chunks/app/game/%5Bid%5D/page-56eb3dff903c944e.js'},{'revision':null,'url':'/_next/static/chunks/app/intelligence/page-5f6c106fd6c53851.js'},{'revision':null,'url':'/_next/static/chunks/app/layout-c72e0130bc50baac.js'},{'revision':null,'url':'/_next/static/chunks/app/ledger/page-3bfc2406ebeb6d2e.js'},{'revision':null,'url':'/_next/static/chunks/app/login/page-69c1ebd6ff5c12d8.js'},{'revision':null,'url':'/_next/static/chunks/app/marketplace/page-cbada49ae96a7527.js'},{'revision':null,'url':'/_next/static/chunks/app/not-found-1fd99a98dab3c771.js'},{'revision':null,'url':'/_next/static/chunks/app/offline/page-a7a57ff039afc1af.js'},{'revision':null,'url':'/_next/static/chunks/app/page-70c10ec17b5cf43c.js'},{'revision':null,'url':'/_next/static/chunks/app/pricing/page-3f26af475b3f8452.js'},{'revision':null,'url':'/_next/static/chunks/app/privacy/page-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/profile/page-0a7a9e981d344a6f.js'},{'revision':null,'url':'/_next/static/chunks/app/responsible-gambling/page-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/scan/page-8f1c2629fa6951f2.js'},{'revision':null,'url':'/_next/static/chunks/app/settings/security/page-59df87aff0c62ec8.js'},{'revision':null,'url':'/_next/static/chunks/app/signup/page-33e502bb04569f60.js'},{'revision':null,'url':'/_next/static/chunks/app/soccer/page-9ba3b46b0b1dfa59.js'},{'revision':null,'url':'/_next/static/chunks/app/terms/page-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/app/tracker/page-d6937e1faa494c49.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/cancel/page-1fd99a98dab3c771.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/desk/page-0ed948b44f9c64d7.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/success/page-b6baded9f44ae951.js'},{'revision':null,'url':'/_next/static/chunks/app/verify/page-cdeec62ab3a5d8ff.js'},{'revision':null,'url':'/_next/static/chunks/app/welcome/page-e3ab6d5822dee6dc.js'},{'revision':null,'url':'/_next/static/chunks/framework-95da69ac6843d788.js'},{'revision':null,'url':'/_next/static/chunks/main-a354262253293123.js'},{'revision':null,'url':'/_next/static/chunks/main-app-4231d5f500f33972.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/app-error-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/forbidden-c81f75b48fa88863.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/global-error-756d787dba63aa4d.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/unauthorized-c81f75b48fa88863.js'},{'revision':'846118c33b2c0e922d7b3a7676f81f6f','url':'/_next/static/chunks/polyfills-42372ed130431b0a.js'},{'revision':null,'url':'/_next/static/chunks/webpack-a41d593db6ea66d4.js'},{'revision':null,'url':'/_next/static/css/f795112d016cc138.css'},{'revision':'61181631d622c1e4c405db474783d65f','url':'/_next/static/xlUV0_7v5otS6i3gs6Eg5/_buildManifest.js'},{'revision':'b6652df95db52feb4daf4eca35380933','url':'/_next/static/xlUV0_7v5otS6i3gs6Eg5/_ssgManifest.js'},{'revision':'d7bc0f63f9618b8b700d028d7d242de8','url':'/apple-touch-icon.png'},{'revision':'5616f81ec5f8a9f726a17fb7ac66a54a','url':'/favicon-16.png'},{'revision':'1fc285cfb0116a0523eb34c779a7d282','url':'/favicon-32.png'},{'revision':'583b034f36839a8af92841771eef38b6','url':'/favicon.ico'},{'revision':'b15795128b3691e5703d0ce14ce10827','url':'/favicon.png'},{'revision':'44e9d71551be13574ac2e10063d03aa9','url':'/favicon.svg'},{'revision':'252b8f8c4d0f64c7cd120f182a6c74ab','url':'/icon-192.png'},{'revision':'3e3b53bbd210bd772b36b70165657e7c','url':'/icon-512.png'},{'revision':'252b8f8c4d0f64c7cd120f182a6c74ab','url':'/icons/icon-192.png'},{'revision':'3e3b53bbd210bd772b36b70165657e7c','url':'/icons/icon-512.png'},{'revision':'3e3b53bbd210bd772b36b70165657e7c','url':'/icons/icon-maskable-512.png'},{'revision':'bf670b1fafa1b3127bd50abe86d723b9','url':'/images/player-silhouette.svg'},{'revision':'d31c450ad857fff6798872411d72f42b','url':'/manifest.json'},{'revision':'9f61cf51298661d5c57a782534216240','url':'/og-image.png'},{'revision':'7c759c20b35840eacf9344692cb51061','url':'/og-image.svg'},{'revision':'9327802333275f11e68c3f19f20c160d','url':'/widget.js'}],skipWaiting:!0,clientsClaim:!0,navigationPreload:!0,runtimeCaching:eq}).addEventListeners(),self.addEventListener("install",e=>{e.waitUntil(caches.open("offline-fallback").then(e=>e.add(eR)).catch(()=>{}))}),self.addEventListener("activate",e=>{e.waitUntil(caches.keys().then(e=>Promise.all(e.filter(e=>!eE.includes(e)&&!e.startsWith("serwist")).map(e=>(console.log("[SW] deleting stale cache:",e),caches.delete(e))))))}),self.addEventListener("push",e=>{let t;if(!e.data)return;try{t=e.data.json()}catch{t={title:"VYNDR",body:e.data.text()}}let{title:a="VYNDR",body:s="",icon:r="/icons/icon-192.png",url:i="/",tag:n="vyndr-notification"}=t;e.waitUntil(self.registration.showNotification(a,{body:s,icon:r,badge:"/icons/icon-192.png",tag:n,data:{url:i}}))}),self.addEventListener("notificationclick",e=>{e.notification.close();let t=e.notification.data?.url??"/";e.waitUntil(self.clients.matchAll({type:"window",includeUncontrolled:!0}).then(e=>{let a=e.find(e=>e.url.endsWith(t));return a?a.focus():self.clients.openWindow(t)}))})})(); \ No newline at end of file +This is generally NOT safe. Learn more at https://bit.ly/wb-precache`)}handleInstall(e){return this.registerRequestRules(e),y(e,async()=>{let t=new eo;this.precacheStrategy.plugins.push(t),await el(this._concurrentPrecaching,Array.from(this._urlsToCacheKeys.entries()),async([t,a])=>{let s=this._cacheKeysToIntegrities.get(a),r=this._urlsToCacheModes.get(t),i=new Request(t,{integrity:s,cache:r,credentials:"same-origin"});await Promise.all(this.precacheStrategy.handleAll({event:e,request:i,url:new URL(i.url),params:{cacheKey:a}}))});let{updatedURLs:a,notUpdatedURLs:s}=t;return{updatedURLs:a,notUpdatedURLs:s}})}async registerRequestRules(e){if(this._requestRules&&e?.addRoutes)try{await e.addRoutes(this._requestRules),this._requestRules=void 0}catch(e){throw e}}handleActivate(e){return y(e,async()=>{let e=await self.caches.open(this.precacheStrategy.cacheName),t=await e.keys(),a=new Set(this._urlsToCacheKeys.values()),s=[];for(let r of t)a.has(r.url)||(await e.delete(r),s.push(r.url));return{deletedCacheRequests:s}})}handleFetch(e){let{request:t}=e,a=this.handleRequest({request:t,event:e});a&&e.respondWith(a)}handleCache(e){if(e.data&&"CACHE_URLS"===e.data.type){let{payload:t}=e.data,a=Promise.all(t.urlsToCache.map(t=>{let a;return a="string"==typeof t?new Request(t):new Request(...t),this.handleRequest({request:a,event:e})}));e.waitUntil(a),e.ports?.[0]&&a.then(()=>e.ports[0].postMessage(!0))}}setDefaultHandler(e,t="GET"){this._defaultHandlerMap.set(t,ea(e))}setCatchHandler(e){this._catchHandler=ea(e)}registerCapture(e,t,a){let s=((e,t,a)=>{if("string"==typeof e){let s=new URL(e,location.href);return new es(({url:e})=>e.href===s.href,t,a)}if(e instanceof RegExp)return new en(e,t,a);if("function"==typeof e)return new es(e,t,a);if(e instanceof es)return e;throw new l("unsupported-route-type",{moduleName:"serwist",funcName:"parseRoute",paramName:"capture"})})(e,t,a);return this.registerRoute(s),s}registerRoute(e){this._routes.has(e.method)||this._routes.set(e.method,[]),this._routes.get(e.method).push(e)}unregisterRoute(e){if(!this._routes.has(e.method))throw new l("unregister-route-but-not-found-with-method",{method:e.method});let t=this._routes.get(e.method).indexOf(e);if(t>-1)this._routes.get(e.method).splice(t,1);else throw new l("unregister-route-route-not-registered")}getUrlsToPrecacheKeys(){return this._urlsToCacheKeys}getPrecachedUrls(){return[...this._urlsToCacheKeys.keys()]}getPrecacheKeyForUrl(e){let t=new URL(e,location.href);return this._urlsToCacheKeys.get(t.href)}getIntegrityForPrecacheKey(e){return this._cacheKeysToIntegrities.get(e)}async matchPrecache(e){let t=e instanceof Request?e.url:e,a=this.getPrecacheKeyForUrl(t);if(a)return(await self.caches.open(this.precacheStrategy.cacheName)).match(a)}createHandlerBoundToUrl(e){let t=this.getPrecacheKeyForUrl(e);if(!t)throw new l("non-precached-url",{url:e});return a=>(a.request=new Request(e),a.params={cacheKey:t,...a.params},this.precacheStrategy.handle(a))}handleRequest({request:e,event:t}){let a,s=new URL(e.url,location.href);if(!s.protocol.startsWith("http"))return;let r=s.origin===location.origin,{params:i,route:n}=this.findMatchingRoute({event:t,request:e,sameOrigin:r,url:s}),c=n?.handler,o=e.method;if(!c&&this._defaultHandlerMap.has(o)&&(c=this._defaultHandlerMap.get(o)),!c)return;try{a=c.handle({url:s,request:e,event:t,params:i})}catch(e){a=Promise.reject(e)}let l=n?.catchHandler;return a instanceof Promise&&(this._catchHandler||l)&&(a=a.catch(async a=>{if(l)try{return await l.handle({url:s,request:e,event:t,params:i})}catch(e){e instanceof Error&&(a=e)}if(this._catchHandler)return this._catchHandler.handle({url:s,request:e,event:t});throw a})),a}findMatchingRoute({url:e,sameOrigin:t,request:a,event:s}){for(let r of this._routes.get(a.method)||[]){let i,n=r.match({url:e,sameOrigin:t,request:a,event:s});if(n)return Array.isArray(i=n)&&0===i.length||n.constructor===Object&&0===Object.keys(n).length?i=void 0:"boolean"==typeof n&&(i=void 0),{route:r,params:i}}return{}}};let eR="/offline",eE=["pages","api-responses","next-static","static-media","fallback","offline-fallback"],eq=[{matcher:({url:e,sameOrigin:t})=>t&&e.pathname.startsWith("/api/"),handler:new ee({cacheName:"api-responses",networkTimeoutSeconds:5,plugins:[new ep({maxEntries:100,maxAgeSeconds:3600})]})},{matcher:({request:e})=>"navigate"===e.mode,handler:new ee({cacheName:"pages",networkTimeoutSeconds:5,plugins:[new ep({maxEntries:50,maxAgeSeconds:86400}),{handlerDidError:async()=>await caches.match(eR)||Response.error()}]})},{matcher:({url:e,sameOrigin:t})=>t&&e.pathname.startsWith("/_next/static/"),handler:new ey({cacheName:"next-static",plugins:[new ep({maxEntries:200,maxAgeSeconds:2592e3})]})},{matcher:({url:e})=>e.pathname.startsWith("/images/")||e.pathname.startsWith("/icons/")||/\.(?:png|jpe?g|gif|svg|webp|ico|woff2?)$/.test(e.pathname),handler:new ey({cacheName:"static-media",plugins:[new ep({maxEntries:100,maxAgeSeconds:2592e3})]})},{matcher:()=>!0,handler:new ee({cacheName:"fallback",networkTimeoutSeconds:5,plugins:[new ep({maxEntries:50,maxAgeSeconds:86400})]})}];new ev({precacheEntries:[{'revision':'f2636d328ec971216a28fd25d0ad5283','url':'/_next/static/GrOWVkWbsVYxDVGVsTB2n/_buildManifest.js'},{'revision':'b6652df95db52feb4daf4eca35380933','url':'/_next/static/GrOWVkWbsVYxDVGVsTB2n/_ssgManifest.js'},{'revision':null,'url':'/_next/static/chunks/1896-359ed2e68a8c4f1d.js'},{'revision':null,'url':'/_next/static/chunks/1958-56cbbb8dba15fd2f.js'},{'revision':null,'url':'/_next/static/chunks/2346-d63ba3de1d09a41e.js'},{'revision':null,'url':'/_next/static/chunks/4bd1b696-e356ca5ba0218e27.js'},{'revision':null,'url':'/_next/static/chunks/52774a7f.f2ab7a9b4b8ba576.js'},{'revision':null,'url':'/_next/static/chunks/5838-7e0aa455e9f24259.js'},{'revision':null,'url':'/_next/static/chunks/6810-65ea0987ee90a78b.js'},{'revision':null,'url':'/_next/static/chunks/7602.2868ff821d53ee09.js'},{'revision':null,'url':'/_next/static/chunks/7918-9cfe56e3ee27ed27.js'},{'revision':null,'url':'/_next/static/chunks/8500-f62a38ff68ab7f42.js'},{'revision':null,'url':'/_next/static/chunks/9da6db1e-9623f3245f088d02.js'},{'revision':null,'url':'/_next/static/chunks/app/_global-error/page-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/_not-found/page-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/account/page-f5e2a6d5e729cc87.js'},{'revision':null,'url':'/_next/static/chunks/app/admin/page-7653c5a94021e122.js'},{'revision':null,'url':'/_next/static/chunks/app/api/admin/stats/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/books/%5B...path%5D/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/checkout/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/gamelines/%5Bsport%5D/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/props/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/tonight/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/hero-prop/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/hotlist/%5Bsport%5D/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/intelligence/feed/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/accuracy/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/lines/%5B...path%5D/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/mlb/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/nba/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/soccer/%5Bleague%5D/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/wnba/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/add-leg/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/calculate/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/grade/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/players/search/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/live/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/most-parlayed/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/top-graded/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/scan/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/schedule/%5Bsport%5D/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/parlays-graded/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/public/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/streaks/%5Bsport%5D/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/profile/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/recent-scans/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/scans/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/waitlist/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/webhook/nexapay/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/welcome-email/route-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/auth/callback/page-0cb8d3790d034de0.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/%5Bslug%5D/page-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/page-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/dashboard/page-79c033d3218c9272.js'},{'revision':null,'url':'/_next/static/chunks/app/forgot-password/page-a251f52b4206e8d1.js'},{'revision':null,'url':'/_next/static/chunks/app/game/%5Bid%5D/page-56eb3dff903c944e.js'},{'revision':null,'url':'/_next/static/chunks/app/intelligence/page-5f6c106fd6c53851.js'},{'revision':null,'url':'/_next/static/chunks/app/layout-c72e0130bc50baac.js'},{'revision':null,'url':'/_next/static/chunks/app/ledger/page-3bfc2406ebeb6d2e.js'},{'revision':null,'url':'/_next/static/chunks/app/login/page-69c1ebd6ff5c12d8.js'},{'revision':null,'url':'/_next/static/chunks/app/marketplace/page-cbada49ae96a7527.js'},{'revision':null,'url':'/_next/static/chunks/app/not-found-1fd99a98dab3c771.js'},{'revision':null,'url':'/_next/static/chunks/app/offline/page-a7a57ff039afc1af.js'},{'revision':null,'url':'/_next/static/chunks/app/page-70c10ec17b5cf43c.js'},{'revision':null,'url':'/_next/static/chunks/app/pricing/page-3f26af475b3f8452.js'},{'revision':null,'url':'/_next/static/chunks/app/privacy/page-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/profile/page-0a7a9e981d344a6f.js'},{'revision':null,'url':'/_next/static/chunks/app/responsible-gambling/page-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/scan/page-8f1c2629fa6951f2.js'},{'revision':null,'url':'/_next/static/chunks/app/settings/security/page-59df87aff0c62ec8.js'},{'revision':null,'url':'/_next/static/chunks/app/signup/page-33e502bb04569f60.js'},{'revision':null,'url':'/_next/static/chunks/app/soccer/page-9ba3b46b0b1dfa59.js'},{'revision':null,'url':'/_next/static/chunks/app/terms/page-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/app/tracker/page-d6937e1faa494c49.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/cancel/page-1fd99a98dab3c771.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/desk/page-0ed948b44f9c64d7.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/success/page-b6baded9f44ae951.js'},{'revision':null,'url':'/_next/static/chunks/app/verify/page-cdeec62ab3a5d8ff.js'},{'revision':null,'url':'/_next/static/chunks/app/welcome/page-e3ab6d5822dee6dc.js'},{'revision':null,'url':'/_next/static/chunks/framework-95da69ac6843d788.js'},{'revision':null,'url':'/_next/static/chunks/main-a354262253293123.js'},{'revision':null,'url':'/_next/static/chunks/main-app-4231d5f500f33972.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/app-error-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/forbidden-30c428a14fcfa3f4.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/global-error-756d787dba63aa4d.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/unauthorized-30c428a14fcfa3f4.js'},{'revision':'846118c33b2c0e922d7b3a7676f81f6f','url':'/_next/static/chunks/polyfills-42372ed130431b0a.js'},{'revision':null,'url':'/_next/static/chunks/webpack-a41d593db6ea66d4.js'},{'revision':null,'url':'/_next/static/css/0e3cdd5e3f69836f.css'},{'revision':'d7bc0f63f9618b8b700d028d7d242de8','url':'/apple-touch-icon.png'},{'revision':'5616f81ec5f8a9f726a17fb7ac66a54a','url':'/favicon-16.png'},{'revision':'1fc285cfb0116a0523eb34c779a7d282','url':'/favicon-32.png'},{'revision':'583b034f36839a8af92841771eef38b6','url':'/favicon.ico'},{'revision':'b15795128b3691e5703d0ce14ce10827','url':'/favicon.png'},{'revision':'44e9d71551be13574ac2e10063d03aa9','url':'/favicon.svg'},{'revision':'252b8f8c4d0f64c7cd120f182a6c74ab','url':'/icon-192.png'},{'revision':'3e3b53bbd210bd772b36b70165657e7c','url':'/icon-512.png'},{'revision':'252b8f8c4d0f64c7cd120f182a6c74ab','url':'/icons/icon-192.png'},{'revision':'3e3b53bbd210bd772b36b70165657e7c','url':'/icons/icon-512.png'},{'revision':'3e3b53bbd210bd772b36b70165657e7c','url':'/icons/icon-maskable-512.png'},{'revision':'bf670b1fafa1b3127bd50abe86d723b9','url':'/images/player-silhouette.svg'},{'revision':'d31c450ad857fff6798872411d72f42b','url':'/manifest.json'},{'revision':'9f61cf51298661d5c57a782534216240','url':'/og-image.png'},{'revision':'7c759c20b35840eacf9344692cb51061','url':'/og-image.svg'},{'revision':'9327802333275f11e68c3f19f20c160d','url':'/widget.js'}],skipWaiting:!0,clientsClaim:!0,navigationPreload:!0,runtimeCaching:eq}).addEventListeners(),self.addEventListener("install",e=>{e.waitUntil(caches.open("offline-fallback").then(e=>e.add(eR)).catch(()=>{}))}),self.addEventListener("activate",e=>{e.waitUntil(caches.keys().then(e=>Promise.all(e.filter(e=>!eE.includes(e)&&!e.startsWith("serwist")).map(e=>(console.log("[SW] deleting stale cache:",e),caches.delete(e))))))}),self.addEventListener("push",e=>{let t;if(!e.data)return;try{t=e.data.json()}catch{t={title:"VYNDR",body:e.data.text()}}let{title:a="VYNDR",body:s="",icon:r="/icons/icon-192.png",url:i="/",tag:n="vyndr-notification"}=t;e.waitUntil(self.registration.showNotification(a,{body:s,icon:r,badge:"/icons/icon-192.png",tag:n,data:{url:i}}))}),self.addEventListener("notificationclick",e=>{e.notification.close();let t=e.notification.data?.url??"/";e.waitUntil(self.clients.matchAll({type:"window",includeUncontrolled:!0}).then(e=>{let a=e.find(e=>e.url.endsWith(t));return a?a.focus():self.clients.openWindow(t)}))})})(); \ No newline at end of file diff --git a/web/src/app/api/books/[...path]/route.ts b/web/src/app/api/books/[...path]/route.ts new file mode 100644 index 0000000..827fec0 --- /dev/null +++ b/web/src/app/api/books/[...path]/route.ts @@ -0,0 +1,25 @@ +import { NextRequest, NextResponse } from 'next/server'; + +export const dynamic = 'force-dynamic'; + +const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000'; + +/** + * Book-comparison proxy (Session 28). Forwards /api/books/* to Express + * (best lines + per-prop book grid). Read-only, zero-credit. + */ +export async function GET(req: NextRequest, { params }: { params: Promise<{ path: string[] }> }) { + const { path } = await params; + const segments = (path || []).map(encodeURIComponent).join('/'); + const qs = req.nextUrl.search; + try { + const upstream = await fetch(`${BACKEND_URL}/api/books/${segments}${qs}`, { + method: 'GET', + headers: { Accept: 'application/json' }, + }); + const data = await upstream.json().catch(() => ({})); + return NextResponse.json(data, { status: upstream.status }); + } catch { + return NextResponse.json({ bestLines: [], books: [] }, { status: 200 }); + } +} diff --git a/web/src/app/api/lines/[...path]/route.ts b/web/src/app/api/lines/[...path]/route.ts new file mode 100644 index 0000000..906cbab --- /dev/null +++ b/web/src/app/api/lines/[...path]/route.ts @@ -0,0 +1,25 @@ +import { NextRequest, NextResponse } from 'next/server'; + +export const dynamic = 'force-dynamic'; + +const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000'; + +/** + * Line-movement proxy (Session 28). Forwards /api/lines/* to Express + * (movers + per-prop history). Read-only, zero-credit. + */ +export async function GET(req: NextRequest, { params }: { params: Promise<{ path: string[] }> }) { + const { path } = await params; + const segments = (path || []).map(encodeURIComponent).join('/'); + const qs = req.nextUrl.search; + try { + const upstream = await fetch(`${BACKEND_URL}/api/lines/${segments}${qs}`, { + method: 'GET', + headers: { Accept: 'application/json' }, + }); + const data = await upstream.json().catch(() => ({})); + return NextResponse.json(data, { status: upstream.status }); + } catch { + return NextResponse.json({ movers: [], snapshots: [] }, { status: 200 }); + } +} diff --git a/web/src/app/api/parlay/calculate/route.ts b/web/src/app/api/parlay/calculate/route.ts new file mode 100644 index 0000000..1e92a57 --- /dev/null +++ b/web/src/app/api/parlay/calculate/route.ts @@ -0,0 +1,30 @@ +import { NextRequest, NextResponse } from 'next/server'; + +export const dynamic = 'force-dynamic'; + +const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000'; + +/** + * Parlay calculate proxy (Session 28). Forwards builder legs to Express + * `/api/parlay/calculate` for combined odds, grade, and correlation flags. + * Zero-credit pure math — no auth gate (the math reveals nothing private). + */ +export async function POST(req: NextRequest) { + let body: unknown; + try { + body = await req.json(); + } catch { + return NextResponse.json({ error: 'Invalid JSON.' }, { status: 400 }); + } + try { + const upstream = await fetch(`${BACKEND_URL}/api/parlay/calculate`, { + method: 'POST', + headers: { 'Content-Type': 'application/json', Accept: 'application/json' }, + body: JSON.stringify(body), + }); + const data = await upstream.json().catch(() => ({})); + return NextResponse.json(data, { status: upstream.status }); + } catch { + return NextResponse.json({ error: 'Parlay service unreachable.' }, { status: 502 }); + } +} diff --git a/web/src/components/BestLinesPanel.tsx b/web/src/components/BestLinesPanel.tsx new file mode 100644 index 0000000..bbc5a4d --- /dev/null +++ b/web/src/components/BestLinesPanel.tsx @@ -0,0 +1,105 @@ +'use client'; + +import { useEffect, useState } from 'react'; +import { getVisibleCount, getHiddenCount, type Tier } from '@/lib/tierGate'; + +/** + * BestLinesPanel (Session 28). + * + * "Best lines tonight" — the prop + sportsbook offering the highest payout, + * with the dollars-per-$100 a user saves by line-shopping. Reads + * /api/books/:sport (cached odds, zero credits). Self-hides when empty. + */ + +interface BestLine { + player: string; + stat: string; + line: number | null; + bestBook: string; + bestOdds: number; + savings: number; +} + +export interface BestLinesPanelProps { + sport: string; + tier?: Tier; + limit?: number; +} + +export default function BestLinesPanel({ sport, tier = 'free', limit }: BestLinesPanelProps) { + const [lines, setLines] = useState(null); + + useEffect(() => { + let cancelled = false; + async function load() { + try { + const res = await fetch(`/api/books/${sport}`); + if (!res.ok) { if (!cancelled) setLines([]); return; } + const data = await res.json(); + if (!cancelled) setLines(Array.isArray(data?.bestLines) ? data.bestLines : []); + } catch { + if (!cancelled) setLines([]); + } + } + load(); + return () => { cancelled = true; }; + }, [sport]); + + if (!lines || lines.length === 0) return null; + + const tierCount = getVisibleCount(tier, lines.length); + const cap = limit && limit > 0 ? Math.min(limit, tierCount) : tierCount; + const visible = lines.slice(0, cap); + const hidden = limit ? lines.length - visible.length : getHiddenCount(tier, lines.length); + + const fmtOdds = (o: number) => (o > 0 ? `+${o}` : `${o}`); + + return ( +
+

💰 BEST LINES TONIGHT

+
+ {visible.map((bl) => ( +
+
+
{bl.player}
+
+ {bl.stat.replace(/_/g, ' ')}{bl.line != null ? ` ${bl.line}` : ''} +
+
+ + {bl.bestBook} {fmtOdds(bl.bestOdds)} + + {bl.savings > 0 && save ${bl.savings.toFixed(2)}} +
+ ))} +
+ {hidden > 0 && ( + {hidden} more — upgrade to compare every book → + )} +
+ ); +} + +const heading: React.CSSProperties = { + fontSize: 12, letterSpacing: '0.12em', textTransform: 'uppercase', + color: 'var(--text-tertiary, #6B6B7B)', margin: '0 0 10px', +}; +const row: React.CSSProperties = { + display: 'flex', alignItems: 'center', gap: 12, + padding: '8px 10px', borderRadius: 10, + background: 'var(--bg-2, #12121A)', border: '1px solid var(--border, #1A1A24)', +}; +const playerName: React.CSSProperties = { + fontSize: 14, fontWeight: 700, color: 'var(--text-0, #F0F0F5)', + whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', +}; +const propLine: React.CSSProperties = { fontSize: 12, color: 'var(--text-secondary, #8A8A9A)', textTransform: 'capitalize' }; +const book: React.CSSProperties = { flex: '0 0 auto', fontSize: 12, fontWeight: 700, color: 'var(--text-0, #F0F0F5)', textTransform: 'capitalize' }; +const savings: React.CSSProperties = { + flex: '0 0 auto', fontSize: 11, fontWeight: 700, padding: '2px 7px', borderRadius: 6, + background: 'rgba(0,212,160,0.12)', color: 'var(--grade-a, #00D4A0)', whiteSpace: 'nowrap', +}; +const upsell: React.CSSProperties = { + display: 'inline-block', marginTop: 10, fontSize: 12, fontWeight: 600, + color: 'var(--grade-a, #00D4A0)', textDecoration: 'none', +}; diff --git a/web/src/components/BookComparison.tsx b/web/src/components/BookComparison.tsx new file mode 100644 index 0000000..ebd0c88 --- /dev/null +++ b/web/src/components/BookComparison.tsx @@ -0,0 +1,73 @@ +'use client'; + +/** + * BookComparison (Session 28). + * + * Presentational book-by-book grid for a single prop with the best line + * highlighted. Fed by /api/books/:sport/:player/:stat (or the prop grid + * from a parent). Pure render — no fetching here, so it drops cleanly into + * a modal or an expanded prop row. + */ + +export interface BookRow { + book: string; + line?: number | null; + over_odds?: number | null; + under_odds?: number | null; + isBest?: boolean; +} + +export interface BookComparisonProps { + player: string; + stat: string; + line?: number | null; + side?: 'over' | 'under'; + books: BookRow[]; + savings?: number; +} + +function fmt(o?: number | null) { + if (o == null) return '—'; + return o > 0 ? `+${o}` : `${o}`; +} + +export default function BookComparison({ player, stat, line, side = 'over', books, savings }: BookComparisonProps) { + if (!books || books.length === 0) return null; + return ( +
+
+ {player} · {stat.replace(/_/g, ' ')}{line != null ? ` ${line}` : ''} · {side} +
+
+ {books.map((b) => ( +
+ {b.book} + + {fmt(b.over_odds)} / {fmt(b.under_odds)} + + {b.isBest ? ( + BEST + ) : } +
+ ))} +
+ {savings != null && savings > 0 && ( +
+ Betting the best line saves ~${savings.toFixed(2)} per $100. +
+ )} +
+ ); +} diff --git a/web/src/components/LineMovementChart.tsx b/web/src/components/LineMovementChart.tsx new file mode 100644 index 0000000..0e427fb --- /dev/null +++ b/web/src/components/LineMovementChart.tsx @@ -0,0 +1,57 @@ +'use client'; + +/** + * LineMovementChart (Session 28). + * + * Dependency-free SVG sparkline of a prop's line through the day. Green + * when the line rose, red when it dropped. Renders open + current labels. + * Degrades to a flat midline for <2 points. + */ + +export interface Snapshot { + time?: number; + line: number; +} + +export interface LineMovementChartProps { + snapshots: Snapshot[]; + width?: number; + height?: number; +} + +export default function LineMovementChart({ snapshots, width = 120, height = 32 }: LineMovementChartProps) { + const pts = (snapshots || []).map((s) => Number(s.line)).filter((n) => Number.isFinite(n)); + if (pts.length === 0) return null; + + const opening = pts[0]; + const current = pts[pts.length - 1]; + const delta = current - opening; + const stroke = Math.abs(delta) < 0.5 ? 'var(--text-tertiary, #6B6B7B)' : delta > 0 ? '#00D4A0' : '#FF4D4D'; + + const min = Math.min(...pts); + const max = Math.max(...pts); + const range = max - min || 1; + const pad = 4; + const innerH = height - pad * 2; + const stepX = pts.length > 1 ? width / (pts.length - 1) : 0; + const yScale = (v: number) => pad + innerH - ((v - min) / range) * innerH; + + const polyline = + pts.length > 1 + ? pts.map((v, i) => `${(i * stepX).toFixed(1)},${yScale(v).toFixed(1)}`).join(' ') + : `0,${(height / 2).toFixed(1)} ${width},${(height / 2).toFixed(1)}`; + + return ( + + + {pts.length > 1 && } + + ); +} diff --git a/web/src/components/MoversPanel.tsx b/web/src/components/MoversPanel.tsx new file mode 100644 index 0000000..fbcde53 --- /dev/null +++ b/web/src/components/MoversPanel.tsx @@ -0,0 +1,103 @@ +'use client'; + +import { useEffect, useState } from 'react'; +import LineMovementChart, { Snapshot } from '@/components/LineMovementChart'; +import { getVisibleCount, getHiddenCount, type Tier } from '@/lib/tierGate'; + +/** + * MoversPanel (Session 28). + * + * Biggest line moves for a sport — the market confirming (or contradicting) + * a grade. Reads /api/lines/:sport/movers (Redis snapshot history, zero + * credits). Self-hides when there's nothing moving. Free users see the top + * 3; paid see the full board. + */ + +interface Mover { + player: string; + stat: string; + opening: number; + current: number; + delta: number; + movement: 'stable' | 'rising' | 'dropping'; + sharpSignal: boolean; + snapshots: Snapshot[]; +} + +export interface MoversPanelProps { + sport: string; + tier?: Tier; + limit?: number; +} + +export default function MoversPanel({ sport, tier = 'free', limit }: MoversPanelProps) { + const [movers, setMovers] = useState(null); + + useEffect(() => { + let cancelled = false; + async function load() { + try { + const res = await fetch(`/api/lines/${sport}/movers`); + if (!res.ok) { if (!cancelled) setMovers([]); return; } + const data = await res.json(); + if (!cancelled) setMovers(Array.isArray(data?.movers) ? data.movers : []); + } catch { + if (!cancelled) setMovers([]); + } + } + load(); + return () => { cancelled = true; }; + }, [sport]); + + if (!movers || movers.length === 0) return null; + + const tierCount = getVisibleCount(tier, movers.length); + const cap = limit && limit > 0 ? Math.min(limit, tierCount) : tierCount; + const visible = movers.slice(0, cap); + const hidden = limit ? movers.length - visible.length : getHiddenCount(tier, movers.length); + + return ( +
+

📈 BIGGEST MOVERS

+
+ {visible.map((m) => ( +
+
+
{m.player}
+
{m.stat.replace(/_/g, ' ')} · open {m.opening} → {m.current}
+
+ + 0 ? '#00D4A0' : '#FF4D4D' }}> + {m.delta > 0 ? '+' : ''}{m.delta} + {m.sharpSignal ? SHARP : null} + +
+ ))} +
+ {hidden > 0 && ( + {hidden} more — upgrade for the full board → + )} +
+ ); +} + +const heading: React.CSSProperties = { + fontSize: 12, letterSpacing: '0.12em', textTransform: 'uppercase', + color: 'var(--text-tertiary, #6B6B7B)', margin: '0 0 10px', +}; +const row: React.CSSProperties = { + display: 'flex', alignItems: 'center', gap: 12, + padding: '8px 10px', borderRadius: 10, + background: 'var(--bg-2, #12121A)', border: '1px solid var(--border, #1A1A24)', +}; +const playerName: React.CSSProperties = { + fontSize: 14, fontWeight: 700, color: 'var(--text-0, #F0F0F5)', + whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', +}; +const propLine: React.CSSProperties = { fontSize: 12, color: 'var(--text-secondary, #8A8A9A)', textTransform: 'capitalize' }; +const delta: React.CSSProperties = { flex: '0 0 auto', fontSize: 13, fontWeight: 800, whiteSpace: 'nowrap' }; +const sharp: React.CSSProperties = { fontSize: 9, color: '#FFB347', letterSpacing: '0.06em' }; +const upsell: React.CSSProperties = { + display: 'inline-block', marginTop: 10, fontSize: 12, fontWeight: 600, + color: 'var(--grade-a, #00D4A0)', textDecoration: 'none', +}; diff --git a/web/src/components/Slate.tsx b/web/src/components/Slate.tsx index 40bd361..1ab83ff 100644 --- a/web/src/components/Slate.tsx +++ b/web/src/components/Slate.tsx @@ -11,6 +11,10 @@ import { useAuth } from '@/contexts/AuthContext'; import StatFilterPills from '@/components/StatFilterPills'; import StreaksPanel from '@/components/StreaksPanel'; import HotListPanel from '@/components/HotListPanel'; +// Session 28 — line-movement + book-comparison read-only panels. Both +// self-hide when empty; free users see a top-3 teaser. +import MoversPanel from '@/components/MoversPanel'; +import BestLinesPanel from '@/components/BestLinesPanel'; /** * The Slate (Session 13). @@ -762,6 +766,11 @@ export default function Slate({ initialTab = 'all', tier = 'free' }: SlateProps) an off-hours slate with no warm logs simply shows the games. */} + {/* Session 28 — market layers: how lines are MOVING and where the + BEST price sits. Both read cached data (zero credits) and + self-hide until there's something to show. */} + + {/* Session 24 — removed the developer-facing "odds endpoint not configured yet" footer note. A sport with no data simply doesn't