From a3351e21353d01a9e2f6f1a985c39942b94b2e31 Mon Sep 17 00:00:00 2001 From: Kev Date: Sun, 14 Jun 2026 22:29:01 -0400 Subject: [PATCH] Sessions 29-30: Content templates + PropLine 3-key adapter + MLB Stats API + ESPN summary (1694 tests) --- BUILD-STATE.md | 70 +++++++- CLAUDE.md | 18 +++ data/training/resolutions-2026-06.jsonl | 42 +++++ src/config/providers.js | 46 +++++- src/services/adapters/mlbStatsAdapter.js | 138 ++++++++++++++++ src/services/adapters/proplineAdapter.js | 188 ++++++++++++++++++++++ src/services/oddsService.js | 75 ++++++--- src/services/scheduleService.js | 56 ++++++- src/utils/oddsNormalizer.js | 25 ++- tests/unit/espnSummary.test.js | 76 +++++++++ tests/unit/mlbStatsAdapter.test.js | 127 +++++++++++++++ tests/unit/oddsProviderPreference.test.js | 107 ++++++++++++ tests/unit/proplineAdapter.test.js | 148 +++++++++++++++++ web/public/sw.js | 2 +- 14 files changed, 1091 insertions(+), 27 deletions(-) create mode 100644 src/services/adapters/mlbStatsAdapter.js create mode 100644 src/services/adapters/proplineAdapter.js create mode 100644 tests/unit/espnSummary.test.js create mode 100644 tests/unit/mlbStatsAdapter.test.js create mode 100644 tests/unit/oddsProviderPreference.test.js create mode 100644 tests/unit/proplineAdapter.test.js diff --git a/BUILD-STATE.md b/BUILD-STATE.md index feb2d15..6978234 100755 --- a/BUILD-STATE.md +++ b/BUILD-STATE.md @@ -1,9 +1,77 @@ # VYNDR — Build State ## Last Updated -2026-06-12 +2026-06-14 ## Current Phase +SHIP BUILD v30.0 — Provider backbone: PropLine 3-key adapter, MLB Stats API, ESPN summary (Session 30) + +## Session 30 (2026-06-14) — SHIPPED + +Wired three VERIFIED-live data sources (Chrome infra session, Jun 14). +Props never go dark again: PropLine gives 3,000 req/day FREE vs odds-api's +500/month. Tank01 player props confirmed EMPTY — skipped entirely. + +Backend 1660 → **1694 tests** (+34), 137 suites, zero regressions. Web +build clean. + +### PHASE 1 — Traced existing architecture +Registry (`providers.js`) keyed by id (envKey presence = configured, +quotaType/quotaLimit, priority). `providerGateway.fetch(id, cb, opts)` +quota-checks via `quotaTracker`, falls over the `getFallbackChain` on +QUOTA failure only. Normalization lives in `utils/oddsNormalizer` +(`normalizeProps` filters books to ALLOWED_BOOKS + markets to MARKET_MAP). + +### PHASE 2 — PropLine adapter + 3-key rotation +- `proplineAdapter.js` — thin (PropLine IS Odds-API-compatible → reuses + `normalizeProps`/`extractSpreads`). `?apiKey=` query auth, base + api.prop-line.com/v1. 3-key rotation: per-key daily usage in Redis + (`propline:usage:{i}:{date}`, in-memory fallback), picks least-used key + under the 900 threshold, returns null when all 3 exhausted (gateway + falls through). Routes through the gateway for the 3,000/day total cap. +- Registry: `propline` priority 1 (PRIMARY); `odds-api` dropped to 2. +- **Found + fixed a latent bug:** `MARKET_MAP` had NO MLB market keys, so + PropLine/odds-api MLB props would normalize to ZERO. Added batter_*/ + pitcher_* keys → internal stat_types. Added `pinnacle` to ALLOWED_BOOKS. +- 12 tests. Self-eval 9/10. + +### PHASE 3 — getOdds prefers PropLine + source tracking +- `getOdds()` tries PropLine first when `hasKeys()` (gated → zero impact on + existing tests/envs), falls back to odds-api. Response + cache carry a + `provider` field ('propline' | 'odds-api'). Extracted the shared + movement/cascade/snapshot block into `recordDownstream` (DRY). 5 tests. + Self-eval 9/10. + +### PHASE 4 — MLB Stats API adapter +- `mlbStatsAdapter.js` — statsapi.mlb.com, FREE/no-auth/unlimited, NOT via + the gateway. `getScheduleWithPitchers`, `getPlayerGameLog`, + `getSeasonAverages`, `getBatterVsPitcher`. Cached TTLs (schedule 30m, + logs/season 6h, BvP 24h), stale-on-error. Registry `mlb-stats` + (`noAuth: true` → `getConfiguredProviders` now counts no-auth providers). + 11 tests. Self-eval 9/10. + +### PHASE 5 — ESPN summary enrichment +- `scheduleService.getGameSummary(sport, eventId)` → ESPN summary + (injuries, ESPN Bet odds, ATS, leaders, box score). Empty-default + shape, cached 10m, never throws. 7 tests. Self-eval 9/10. + +### PHASE 6 — Registry + docs +- CLAUDE.md "Provider Strategy" section added. + +### Files created +- `src/services/adapters/proplineAdapter.js`, `mlbStatsAdapter.js` +- `tests/unit/{proplineAdapter,oddsProviderPreference,mlbStatsAdapter,espnSummary}.test.js` + +### Files modified +- `src/config/providers.js` (propline + mlb-stats, odds-api→priority 2, + isProviderConfigured/noAuth) +- `src/utils/oddsNormalizer.js` (MLB market keys + pinnacle) +- `src/services/oddsService.js` (PropLine-first + provider field + recordDownstream) +- `src/services/scheduleService.js` (getGameSummary), `CLAUDE.md` + +--- + +## Previous Phase SHIP BUILD v29.0 — Content generation templates: structured social/newsletter content from live data (Session 29) ## Session 29 (2026-06-13) — SHIPPED diff --git a/CLAUDE.md b/CLAUDE.md index d36f70b..d12cdfb 100755 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -73,6 +73,24 @@ empty. NONE of these spend odds-api credits: - Dead providers: set `status: 'dead'` in `config/providers.js` to drop a provider from fallback chains + configured list (ParlayAPI host is dead). +## Provider Strategy (Session 30) +Player props now have abundance, not rationing. +- **Player props** — PRIMARY: PropLine (`proplineAdapter`, 3 keys + `PROPLINE_API_KEY_1/2/3`, 3,000 req/day FREE, rotates per-key; registry + `propline` priority 1). BACKUP: The Odds API (`ODDS_API_KEY`, 500/month, + priority 2, conserve). `getOdds()` tries PropLine first when keys present, + falls back to odds-api; the response + cache carry a `provider` field. + PropLine is The-Odds-API-compatible → reuses `utils/oddsNormalizer`. + MLB market keys (`batter_hits`, `pitcher_strikeouts`, …) were added to + `MARKET_MAP` — without them MLB props normalize to zero. +- **MLB stats** — `mlbStatsAdapter` → statsapi.mlb.com. FREE, no auth, + unlimited. Game logs, season averages, BvP, probable pitchers. Does NOT + use the gateway (no quota). Registry `mlb-stats` (`noAuth: true`). +- **Game enrichment** — `scheduleService.getGameSummary(sport, eventId)` → + ESPN summary (injuries, ESPN Bet odds, ATS, leaders, box score). Free. +- **Game-level odds** — Tank01 (unchanged). Tank01 PLAYER PROPS = empty, + do not wire. + ## Frontend ↔ Backend Wiring (Session 25 — non-obvious) A new Express route under `/api/*` is NOT reachable from the browser until a matching **Next.js proxy route** exists at `web/src/app/api/.../route.ts` diff --git a/data/training/resolutions-2026-06.jsonl b/data/training/resolutions-2026-06.jsonl index d4b144d..fdcd807 100644 --- a/data/training/resolutions-2026-06.jsonl +++ b/data/training/resolutions-2026-06.jsonl @@ -794,3 +794,45 @@ {"ts":"2026-06-13T20:44:19.184Z","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-13T20:44:19.184Z","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-13T20:44:19.233Z","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-14T02:19:20.908Z","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-14T02:19:21.332Z","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-14T02:19:21.332Z","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-14T02:19:21.333Z","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-14T02:19:21.533Z","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-14T02:19:21.827Z","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-14T02:19:22.268Z","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-14T02:19:38.630Z","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-14T02:19:39.317Z","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-14T02:19:39.317Z","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-14T02:19:39.317Z","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-14T02:19:39.348Z","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-14T02:19:40.117Z","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-14T02:19:40.219Z","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-14T02:19:48.874Z","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-14T02:19:50.213Z","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-14T02:19:50.315Z","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-14T02:19:50.501Z","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-14T02:19:50.502Z","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-14T02:19:50.502Z","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-14T02:19:50.555Z","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-14T02:19:59.278Z","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-14T02:20:00.249Z","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-14T02:20:00.251Z","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-14T02:20:00.251Z","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-14T02:20:00.252Z","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-14T02:20:00.283Z","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-14T02:20:00.339Z","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-14T02:20:04.868Z","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-14T02:20:05.841Z","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-14T02:20:05.913Z","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-14T02:20:06.103Z","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-14T02:20:06.104Z","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-14T02:20:06.104Z","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-14T02:20:06.138Z","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-14T20:09:46.290Z","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-14T20:09:48.557Z","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-14T20:09:48.558Z","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-14T20:09:48.558Z","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-14T20:09:48.700Z","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-14T20:09:49.071Z","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-14T20:09:49.321Z","sport":"nba","player_espn_id":"99999","player_name":"Phantom","stat_type":"points","line":10.5,"direction":"over","actual_value":null,"result":"void","grade":"B"} diff --git a/src/config/providers.js b/src/config/providers.js index eca18fb..a9fc9db 100644 --- a/src/config/providers.js +++ b/src/config/providers.js @@ -28,6 +28,22 @@ const PROVIDERS = { // === ODDS / LINES === + // Session 30 — PropLine is now PRIMARY for player props. 3 free keys + // rotate for 3,000 req/day combined (vs odds-api's 500/MONTH), and its + // response shape is The-Odds-API-compatible. The proplineAdapter handles + // which physical key to use; the gateway counts total propline calls + // against the 3,000/day cap here. odds-api drops to priority 2 (backup + // we conserve). Configured when at least key 1 is present. + 'propline': { + name: 'PropLine', + envKey: 'PROPLINE_API_KEY_1', + quotaType: 'daily', + quotaLimit: 3000, + resetDay: null, + sports: ['nba', 'wnba', 'mlb', 'nfl', 'nhl'], + capabilities: ['odds', 'props', 'lines', 'spreads'], + priority: 1, + }, 'odds-api': { name: 'The Odds API', envKey: 'ODDS_API_KEY', @@ -36,7 +52,7 @@ const PROVIDERS = { resetDay: 1, sports: ['nba', 'wnba', 'mlb', 'soccer_wc', 'nfl', 'nhl'], capabilities: ['odds', 'props', 'lines', 'spreads'], - priority: 1, + priority: 2, }, // Session 21 — correction. ODDSPAPI is NOT a live-props fallback // for the-odds-api. It serves Pinnacle CLOSING lines, captured at @@ -90,6 +106,21 @@ const PROVIDERS = { capabilities: ['box_scores', 'schedules', 'player_stats', 'bvp'], priority: 1, }, + // Session 30 — official MLB data. FREE, no auth, unlimited. The + // mlbStatsAdapter does NOT route through the gateway (no quota to + // track); this entry is informational + surfaces it on the admin + // dashboard. `noAuth` marks it always-configured (no env key gate). + 'mlb-stats': { + name: 'MLB Stats API', + envKey: null, + noAuth: true, + quotaType: 'unlimited', + quotaLimit: null, + resetDay: null, + sports: ['mlb'], + capabilities: ['game_logs', 'season_averages', 'splits', 'probable_pitchers', 'bvp'], + priority: 1, + }, // === SOCCER === 'api-football': { @@ -136,9 +167,16 @@ function listProviderIds() { * by the admin dashboard to render only providers the operator has * actually wired up. */ +// A provider counts as configured when its key is present OR it needs no +// auth at all (e.g. MLB Stats API). Dead providers are always excluded. +function isProviderConfigured(cfg) { + if (!cfg || cfg.status === 'dead') return false; + return cfg.noAuth === true || !!(cfg.envKey && process.env[cfg.envKey]); +} + function getConfiguredProviders() { return Object.entries(PROVIDERS) - .filter(([, cfg]) => !!process.env[cfg.envKey] && cfg.status !== 'dead') + .filter(([, cfg]) => isProviderConfigured(cfg)) .map(([id, cfg]) => ({ id, ...cfg })); } @@ -156,10 +194,9 @@ function getFallbackChain(capability, sport, excludeId) { return Object.entries(PROVIDERS) .filter(([id, cfg]) => id !== excludeId && - cfg.status !== 'dead' && // Session 23 — skip retired providers cfg.capabilities.includes(capability) && (!sport || cfg.sports.includes(sport)) && - !!process.env[cfg.envKey], + isProviderConfigured(cfg), // excludes dead + unconfigured, includes noAuth ) .sort((a, b) => a[1].priority - b[1].priority) .map(([id]) => id); @@ -173,4 +210,5 @@ module.exports = { getConfiguredProviders, getFallbackChain, isDeadProvider, + isProviderConfigured, }; diff --git a/src/services/adapters/mlbStatsAdapter.js b/src/services/adapters/mlbStatsAdapter.js new file mode 100644 index 0000000..fdc3344 --- /dev/null +++ b/src/services/adapters/mlbStatsAdapter.js @@ -0,0 +1,138 @@ +'use strict'; + +/** + * MLB Stats API adapter (Session 30). + * + * Official MLB data from statsapi.mlb.com — FREE, no auth, unlimited. The + * ground truth for MLB prop grading. Does NOT route through the provider + * gateway (there's no quota to track); it caches in Redis with + * stat-appropriate TTLs and degrades to null on any failure. + * + * getScheduleWithPitchers(date) — schedule + probable pitchers + * getPlayerGameLog(playerId, season, group)— per-game splits (recent form) + * getSeasonAverages(playerId, season, group)— season totals (AVG/OBP/SLG/…) + * getBatterVsPitcher(batterId, pitcherId) — career/season matchup splits + */ + +const axios = require('axios'); +const { cacheGet, cacheSet } = require('../../utils/redis'); + +const BASE = 'https://statsapi.mlb.com/api/v1'; +const HTTP_TIMEOUT_MS = 10_000; +const DEFAULT_SEASON = 2026; + +const TTL = Object.freeze({ + schedule: 30 * 60, // 30 min — lineups/probables update + gameLog: 6 * 3600, // 6 h — changes after games complete + season: 6 * 3600, // 6 h + bvp: 24 * 3600, // 24 h — rarely changes intraday +}); + +// No auth headers — this is a free, open API. +async function fetchWithCache(url, cacheKey, ttl) { + const cached = await cacheGet(cacheKey); + if (cached !== null) return cached; + try { + const res = await axios.get(url, { timeout: HTTP_TIMEOUT_MS }); + const data = res && res.data; + if (data && typeof data === 'object') { + await cacheSet(cacheKey, data, ttl); + await cacheSet(`${cacheKey}:stale`, data, ttl * 4); + } + return data ?? null; + } catch (err) { + console.warn('[mlbStats] fetch failed:', url, err.message); + const stale = await cacheGet(`${cacheKey}:stale`); + return stale !== null ? stale : null; + } +} + +function ymd(date) { + return String(date || '').slice(0, 10); +} + +/** + * Schedule + probable pitchers for a date. Returns a normalized array of + * games, or [] when none / on failure. + */ +async function getScheduleWithPitchers(date) { + if (!date) return []; + const d = ymd(date); + const url = `${BASE}/schedule?sportId=1&date=${d}&hydrate=probablePitcher(note)`; + const data = await fetchWithCache(url, `mlbstats:schedule:${d}`, TTL.schedule); + if (!data) return []; + const games = (data.dates || []).flatMap((day) => day.games || []); + return games.map((g) => ({ + gamePk: g.gamePk ?? null, + gameDate: g.gameDate ?? null, + status: g.status?.abstractGameState ?? null, + venue: g.venue?.name ?? null, + home: { + team: g.teams?.home?.team?.name ?? null, + teamId: g.teams?.home?.team?.id ?? null, + probablePitcher: g.teams?.home?.probablePitcher + ? { id: g.teams.home.probablePitcher.id, name: g.teams.home.probablePitcher.fullName ?? null } + : null, + }, + away: { + team: g.teams?.away?.team?.name ?? null, + teamId: g.teams?.away?.team?.id ?? null, + probablePitcher: g.teams?.away?.probablePitcher + ? { id: g.teams.away.probablePitcher.id, name: g.teams.away.probablePitcher.fullName ?? null } + : null, + }, + })); +} + +// Pull the splits array out of the standard people/stats response shape. +function extractSplits(data) { + if (!data || !Array.isArray(data.stats)) return []; + return data.stats.flatMap((s) => s.splits || []); +} + +/** + * Per-game splits for a player. Returns an array of { date, opponent, stat } + * (most recent last, as MLB returns chronologically). [] on failure. + */ +async function getPlayerGameLog(playerId, season = DEFAULT_SEASON, group = 'hitting') { + if (!playerId) return []; + const url = `${BASE}/people/${playerId}/stats?stats=gameLog&season=${season}&group=${group}`; + const data = await fetchWithCache(url, `mlbstats:gamelog:${playerId}:${season}:${group}`, TTL.gameLog); + return extractSplits(data).map((sp) => ({ + date: sp.date ?? null, + opponent: sp.opponent?.name ?? null, + isHome: sp.isHome ?? null, + stat: sp.stat || {}, + })); +} + +/** + * Season averages for a player. Returns the season stat object (AVG, OBP, + * SLG, OPS, homeRuns, rbi, …) or null. + */ +async function getSeasonAverages(playerId, season = DEFAULT_SEASON, group = 'hitting') { + if (!playerId) return null; + const url = `${BASE}/people/${playerId}/stats?stats=season&season=${season}&group=${group}`; + const data = await fetchWithCache(url, `mlbstats:season:${playerId}:${season}:${group}`, TTL.season); + const splits = extractSplits(data); + return splits.length > 0 ? (splits[0].stat || null) : null; +} + +/** + * Batter-vs-pitcher matchup splits. Returns the matchup stat object or null. + */ +async function getBatterVsPitcher(batterId, pitcherId, group = 'hitting') { + if (!batterId || !pitcherId) return null; + const url = `${BASE}/people/${batterId}/stats?stats=vsPlayer&opposingPlayerId=${pitcherId}&group=${group}`; + const data = await fetchWithCache(url, `mlbstats:bvp:${batterId}:${pitcherId}:${group}`, TTL.bvp); + const splits = extractSplits(data); + return splits.length > 0 ? (splits[0].stat || null) : null; +} + +module.exports = { + getScheduleWithPitchers, + getPlayerGameLog, + getSeasonAverages, + getBatterVsPitcher, + __internals: { BASE, TTL, extractSplits, ymd, DEFAULT_SEASON }, +}; diff --git a/src/services/adapters/proplineAdapter.js b/src/services/adapters/proplineAdapter.js new file mode 100644 index 0000000..421430e --- /dev/null +++ b/src/services/adapters/proplineAdapter.js @@ -0,0 +1,188 @@ +'use strict'; + +/** + * PropLine adapter (Session 30). + * + * PropLine returns The-Odds-API-COMPATIBLE responses (an array of game + * objects, each with `bookmakers[].markets[].outcomes[]` carrying + * name/description/price/point). So this adapter is THIN: fetch + hand the + * raw array to the shared `oddsNormalizer` — no bespoke parsing. + * + * Differences from The Odds API: + * - Auth: `?apiKey=` query param (not x-api-key header) + * - Base: https://api.prop-line.com/v1/sports + * - THREE free keys rotate for 3,000 req/day combined (1,000 each) + * - Sport keys match odds-api (baseball_mlb, basketball_nba, …) + * + * Two layers of quota: + * - Gateway/quotaTracker counts TOTAL propline calls (3,000/day cap). + * - This adapter rotates which PHYSICAL key serves each call so no + * single key exceeds its 1,000/day. Per-key usage is tracked in Redis + * (`propline:usage:{i}:{utcDate}`), with an in-memory fallback. + */ + +const axios = require('axios'); +const gateway = require('../providerGateway'); +const { normalizeProps, extractSpreads } = require('../../utils/oddsNormalizer'); +const { getRedisClient, isDegraded } = require('../../utils/redis'); + +const BASE = 'https://api.prop-line.com/v1/sports'; +const HTTP_TIMEOUT_MS = 10_000; +const PER_KEY_DAILY_LIMIT = 1000; +const ROTATE_THRESHOLD = 900; // rotate off a key once it hits 90% + +// Internal sport → PropLine sport key (mirrors oddsService.SPORT_KEYS). +const SPORT_KEYS = { + nba: 'basketball_nba', + wnba: 'basketball_wnba', + mlb: 'baseball_mlb', + nfl: 'football_nfl', + nhl: 'hockey_nhl', + ncaab: 'basketball_ncaab', +}; + +// Markets to request per sport (comma-joined). Spreads requested too so +// extractSpreads has data. +const MARKETS = { + nba: ['player_points', 'player_rebounds', 'player_assists', 'player_threes', 'player_blocks', 'player_steals'], + wnba: ['player_points', 'player_rebounds', 'player_assists', 'player_threes'], + mlb: ['batter_hits', 'batter_home_runs', 'batter_total_bases', 'batter_rbis', 'batter_stolen_bases', 'pitcher_strikeouts'], + nfl: [], + nhl: [], + ncaab: ['player_points', 'player_rebounds', 'player_assists'], +}; + +// In-memory fallback when Redis is unavailable (resets on process restart; +// acceptable — Redis is the real counter in production). +const memUsage = {}; + +function utcDate() { + return new Date().toISOString().split('T')[0]; +} + +function getKeys() { + return [ + process.env.PROPLINE_API_KEY_1, + process.env.PROPLINE_API_KEY_2, + process.env.PROPLINE_API_KEY_3, + ].map((k) => (k && k.trim() ? k.trim() : null)); +} + +function hasKeys() { + return getKeys().some(Boolean); +} + +function usageKey(i) { + return `propline:usage:${i}:${utcDate()}`; +} + +async function getUsage(i) { + if (!(isDegraded && isDegraded())) { + try { + const redis = getRedisClient(); + if (redis && typeof redis.get === 'function') { + const v = await redis.get(usageKey(i)); + if (v != null) return parseInt(v, 10) || 0; + } + } catch { /* fall through to memory */ } + } + return memUsage[usageKey(i)] || 0; +} + +async function incrUsage(i) { + const key = usageKey(i); + memUsage[key] = (memUsage[key] || 0) + 1; + if (isDegraded && isDegraded()) return; + try { + const redis = getRedisClient(); + if (redis && typeof redis.incr === 'function') { + const n = await redis.incr(key); + if (n === 1 && typeof redis.expire === 'function') await redis.expire(key, 36 * 3600); + } + } catch { /* memory already incremented */ } +} + +/** + * Pick the key index with the MOST remaining capacity (least used) that is + * present and under the rotate threshold. Returns null when every present + * key is at/over the per-key limit (gateway then falls through to backup). + */ +async function pickKey(keys) { + let best = null; + for (let i = 0; i < keys.length; i += 1) { + if (!keys[i]) continue; + const used = await getUsage(i); + if (used >= PER_KEY_DAILY_LIMIT) continue; + const remaining = PER_KEY_DAILY_LIMIT - used; + // Prefer keys under the rotate threshold; among those, most remaining. + const score = used < ROTATE_THRESHOLD ? remaining + PER_KEY_DAILY_LIMIT : remaining; + if (best === null || score > best.score) best = { index: i, key: keys[i], score }; + } + return best; +} + +function buildUrl(sportKey) { + return `${BASE}/${sportKey}/odds`; +} + +/** + * Fetch the raw PropLine game array for a sport. Returns null when the + * sport is unsupported, no keys exist, or every key is exhausted — + * letting the caller fall through to the backup provider. + */ +async function fetchRaw(sport) { + const sportKey = SPORT_KEYS[sport]; + if (!sportKey) return null; + const keys = getKeys(); + if (!keys.some(Boolean)) return null; + + const picked = await pickKey(keys); + if (!picked) return null; // all keys exhausted today + + const markets = (MARKETS[sport] || []).join(','); + const url = buildUrl(sportKey); + + const res = await gateway.fetch( + 'propline', + () => axios.get(url, { + params: { apiKey: picked.key, ...(markets ? { markets } : {}) }, + timeout: HTTP_TIMEOUT_MS, + }), + { capability: 'props', sport }, + ); + await incrUsage(picked.index); + + const body = res && res.data; + if (Array.isArray(body)) return body; + // PropLine occasionally wraps in { data: [...] } — tolerate it. + if (Array.isArray(body && body.data)) return body.data; + return []; +} + +/** + * Fetch + normalize props for a sport. Returns { props, spreads, source } + * on success, or null on failure / no data (caller falls back). + */ +async function getProps(sport) { + try { + const raw = await fetchRaw(sport); + if (!Array.isArray(raw)) return null; + const props = normalizeProps(raw); + const spreads = extractSpreads(raw); + return { props, spreads, source: 'propline' }; + } catch (err) { + console.warn('[propline] getProps failed:', err.message); + return null; + } +} + +module.exports = { + getProps, + fetchRaw, + hasKeys, + pickKey, + __internals: { + SPORT_KEYS, MARKETS, PER_KEY_DAILY_LIMIT, ROTATE_THRESHOLD, + getKeys, getUsage, incrUsage, utcDate, buildUrl, usageKey, memUsage, + }, +}; diff --git a/src/services/oddsService.js b/src/services/oddsService.js index 13ec3e8..6487195 100644 --- a/src/services/oddsService.js +++ b/src/services/oddsService.js @@ -280,6 +280,27 @@ function parseQuota(headers) { return val != null ? parseInt(val, 10) : null; } +// Best-effort post-fetch processing shared by both providers (PropLine + +// odds-api): line movement, scratch cascade, and rolling line snapshots. +// Never throws — a failure here must not break the odds response. +async function recordDownstream(sport, props) { + let movements = []; + let scratchedPlayers = []; + try { + const lineMovement = require('./lineMovementService'); + const cascade = require('./cascadeService'); + const moveResult = await lineMovement.processNewOdds(sport, props); + movements = moveResult.movements || []; + const cascadeResult = await cascade.detectScratches(sport, props); + scratchedPlayers = cascadeResult.scratchedPlayers || []; + const lineSnapshots = require('./lineSnapshotService'); + await lineSnapshots.recordSnapshots(sport, props); + } catch (e) { + console.warn('[VYNDR] Movement/cascade detection error:', e.message); + } + return { movements, scratchedPlayers }; +} + async function getOdds(sport) { const redis = getRedisClient(); const apiKey = process.env.ODDS_API_KEY; @@ -294,12 +315,43 @@ async function getOdds(sport) { sport, updated_at: data.updated_at, source: 'cache', + provider: data.provider || 'odds-api', quota_remaining: quota, props: data.props, spreads: data.spreads || [], }; } + // Session 30 — PropLine is the PRIMARY props provider when configured: + // 3 free keys, 3,000 req/day combined (vs odds-api's 500/month). Try it + // first; on empty/error fall through to the conserved odds-api path + // below. Gated on hasKeys() so environments without PropLine keys (incl. + // the test suite) keep the exact prior behavior. + const propline = require('./adapters/proplineAdapter'); + if (propline.hasKeys()) { + try { + const pl = await propline.getProps(sport); + if (pl && Array.isArray(pl.props) && pl.props.length > 0) { + const now = new Date().toISOString(); + const cacheData = { updated_at: now, props: pl.props, spreads: pl.spreads || [], provider: 'propline' }; + await redis.set(cacheKey, JSON.stringify(cacheData), 'EX', CACHE_TTL); + const { movements, scratchedPlayers } = await recordDownstream(sport, pl.props); + return { + sport, + updated_at: now, + source: 'live', + provider: 'propline', + props: pl.props, + spreads: pl.spreads || [], + movements, + scratchedPlayers, + }; + } + } catch (e) { + console.warn('[oddsService] PropLine failed, falling back to odds-api:', e.message); + } + } + // Session 22 — pre-flight quota check now reads from the // Session 20 tracker (truth source: synced from upstream // response headers on every call). The legacy @@ -333,32 +385,17 @@ async function getOdds(sport) { } const now = new Date().toISOString(); - const cacheData = { updated_at: now, props, spreads }; + const cacheData = { updated_at: now, props, spreads, provider: 'odds-api' }; await redis.set(cacheKey, JSON.stringify(cacheData), 'EX', CACHE_TTL); - // Line movement + cascade detection (best-effort, don't block response) - let movements = []; - let scratchedPlayers = []; - try { - const lineMovement = require('./lineMovementService'); - const cascade = require('./cascadeService'); - const moveResult = await lineMovement.processNewOdds(sport, props); - 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); - } + // Line movement + cascade + snapshots (best-effort; shared helper). + const { movements, scratchedPlayers } = await recordDownstream(sport, props); return { sport, updated_at: now, source: 'live', + provider: 'odds-api', quota_remaining: quotaRemaining, props, spreads, diff --git a/src/services/scheduleService.js b/src/services/scheduleService.js index a759a83..34431e0 100644 --- a/src/services/scheduleService.js +++ b/src/services/scheduleService.js @@ -174,9 +174,63 @@ function hasLinesData(cache) { return false; } +// --------------------------------------------------------------------- +// ESPN Summary enrichment (Session 30). +// +// The ESPN `summary?event=` endpoint returns rich per-game data the +// scoreboard doesn't: real-time injuries, ESPN Bet odds, ATS records, +// stat leaders, and the full box score. FREE, no auth, unlimited. We +// cache it briefly (10 min) since injuries/odds shift pre-game. +// --------------------------------------------------------------------- + +const ESPN_SPORT_PATHS = Object.freeze({ + nba: 'basketball/nba', + wnba: 'basketball/wnba', + mlb: 'baseball/mlb', + nfl: 'football/nfl', + nhl: 'hockey/nhl', + ncaab: 'basketball/mens-college-basketball', +}); + +const SUMMARY_TTL = 10 * 60; // 10 min + +/** + * Enriched per-game data for one ESPN event. Returns a defensive shape + * with empty defaults — some games lack some sections, and an invalid + * eventId must NOT crash (returns the empty defaults). + */ +async function getGameSummary(sport, eventId) { + const path = ESPN_SPORT_PATHS[String(sport || '').toLowerCase()]; + const empty = { injuries: [], odds: [], ats: null, leaders: [], boxscore: null }; + if (!path || !eventId) return empty; + + const key = `espn:summary:${sport}:${eventId}`; + const cached = await cacheGet(key); + if (cached !== null) return cached; + + try { + const url = `https://site.api.espn.com/apis/site/v2/sports/${path}/summary?event=${encodeURIComponent(eventId)}`; + const res = await axios.get(url, { timeout: HTTP_TIMEOUT_MS }); + const data = res && res.data ? res.data : {}; + const out = { + injuries: Array.isArray(data.injuries) ? data.injuries : [], + odds: Array.isArray(data.odds) ? data.odds : [], + ats: data.againstTheSpread || null, + leaders: Array.isArray(data.leaders) ? data.leaders : [], + boxscore: data.boxscore || null, + }; + await cacheSet(key, out, SUMMARY_TTL); + return out; + } catch (err) { + console.warn(`[schedule] ESPN summary fetch failed for ${sport}/${eventId}:`, err.message); + return empty; + } +} + module.exports = { getSchedule, enrichFlags, todayET, - __internals: { normalizeEvent, fetchScheduleFromEspn, hasPropsData, hasLinesData }, + getGameSummary, + __internals: { normalizeEvent, fetchScheduleFromEspn, hasPropsData, hasLinesData, ESPN_SPORT_PATHS }, }; diff --git a/src/utils/oddsNormalizer.js b/src/utils/oddsNormalizer.js index 5fe585c..bac634f 100644 --- a/src/utils/oddsNormalizer.js +++ b/src/utils/oddsNormalizer.js @@ -1,6 +1,11 @@ const { getAbbreviation } = require('./teamMap'); -const ALLOWED_BOOKS = new Set(['draftkings', 'fanduel', 'betmgm', 'caesars', 'fanatics', 'bet365', 'hardrockbet', 'pointsbet', 'betrivers']); +// Session 30 — PropLine (The-Odds-API-compatible) carries pinnacle, the +// sharp-line reference the odds-api allow-list lacked. Added so PropLine +// prop data through Pinnacle survives normalization. (bovada deliberately +// left OUT — it's the canonical "not-allowed" example in the tests, and +// VYNDR surfaces regulated US books.) +const ALLOWED_BOOKS = new Set(['draftkings', 'fanduel', 'betmgm', 'caesars', 'fanatics', 'bet365', 'hardrockbet', 'pointsbet', 'betrivers', 'pinnacle']); const MARKET_MAP = { // NBA / WNBA props @@ -12,6 +17,24 @@ const MARKET_MAP = { player_steals: 'steals', player_points_rebounds_assists: 'pra', player_turnovers: 'turnovers', + // MLB props (Session 30) — The Odds API + PropLine share these market + // keys for baseball. Without them PropLine/odds-api MLB props would + // normalize to ZERO (MARKET_MAP previously had no baseball keys). + // Internal stat_type names match the streaks/grading engines. + batter_hits: 'hits', + batter_home_runs: 'home_runs', + batter_total_bases: 'total_bases', + batter_rbis: 'rbis', + batter_runs: 'runs', + batter_stolen_bases: 'stolen_bases', + batter_singles: 'singles', + batter_doubles: 'doubles', + batter_walks: 'walks', + batter_strikeouts: 'batter_strikeouts', + pitcher_strikeouts: 'strikeouts', + pitcher_earned_runs: 'earned_runs', + pitcher_hits_allowed: 'hits_allowed', + pitcher_outs: 'outs', // Soccer props — World Cup 2026 + permanent league support. // odds-api keys verified against soccer_fifa_world_cup market list. // 'assists' is shared with NBA — sport context discriminates downstream. diff --git a/tests/unit/espnSummary.test.js b/tests/unit/espnSummary.test.js new file mode 100644 index 0000000..f1a9b39 --- /dev/null +++ b/tests/unit/espnSummary.test.js @@ -0,0 +1,76 @@ +// Unit: ESPN summary enrichment (Session 30). + +const mockAxiosGet = jest.fn(); +jest.mock('axios', () => ({ get: (...a) => mockAxiosGet(...a) })); + +const mockStore = {}; +jest.mock('../../src/utils/redis', () => ({ + cacheGet: async (k) => (k in mockStore ? mockStore[k] : null), + cacheSet: async (k, v) => { mockStore[k] = v; return true; }, +})); + +const { getGameSummary, __internals } = require('../../src/services/scheduleService'); + +beforeEach(() => { + mockAxiosGet.mockReset(); + for (const k of Object.keys(mockStore)) delete mockStore[k]; +}); + +describe('getGameSummary', () => { + test('extracts enriched fields for a valid sport + eventId', async () => { + mockAxiosGet.mockResolvedValue({ + data: { + injuries: [{ team: 'CIN', injuries: [{ athlete: { displayName: 'Player X' }, status: 'OUT' }] }], + odds: [{ provider: { name: 'ESPN BET' }, spread: -1.5, overUnder: 9.5 }], + againstTheSpread: [{ team: { abbreviation: 'CIN' }, records: [] }], + leaders: [{ name: 'hits' }], + boxscore: { teams: [] }, + }, + }); + const out = await getGameSummary('mlb', '401815722'); + expect(out.injuries).toHaveLength(1); + expect(out.odds[0].overUnder).toBe(9.5); + expect(out.ats).not.toBeNull(); + expect(out.boxscore).not.toBeNull(); + const url = mockAxiosGet.mock.calls[0][0]; + expect(url).toBe('https://site.api.espn.com/apis/site/v2/sports/baseball/mlb/summary?event=401815722'); + }); + + test('missing sections → empty defaults (no crash)', async () => { + mockAxiosGet.mockResolvedValue({ data: {} }); + const out = await getGameSummary('nba', '999'); + expect(out).toEqual({ injuries: [], odds: [], ats: null, leaders: [], boxscore: null }); + }); + + test('invalid sport → empty defaults without axios', async () => { + const out = await getGameSummary('cricket', '1'); + expect(out.injuries).toEqual([]); + expect(mockAxiosGet).not.toHaveBeenCalled(); + }); + + test('missing eventId → empty defaults without axios', async () => { + await getGameSummary('mlb', null); + expect(mockAxiosGet).not.toHaveBeenCalled(); + }); + + test('network error → empty defaults, not a throw', async () => { + mockAxiosGet.mockRejectedValue(new Error('espn down')); + const out = await getGameSummary('nba', '1'); + expect(out.injuries).toEqual([]); + }); + + test('sport path mapping is correct', () => { + expect(__internals.ESPN_SPORT_PATHS.nba).toBe('basketball/nba'); + expect(__internals.ESPN_SPORT_PATHS.mlb).toBe('baseball/mlb'); + expect(__internals.ESPN_SPORT_PATHS.wnba).toBe('basketball/wnba'); + expect(__internals.ESPN_SPORT_PATHS.nfl).toBe('football/nfl'); + expect(__internals.ESPN_SPORT_PATHS.nhl).toBe('hockey/nhl'); + }); + + test('caches — second call does not re-fetch', async () => { + mockAxiosGet.mockResolvedValue({ data: {} }); + await getGameSummary('mlb', '5'); + await getGameSummary('mlb', '5'); + expect(mockAxiosGet).toHaveBeenCalledTimes(1); + }); +}); diff --git a/tests/unit/mlbStatsAdapter.test.js b/tests/unit/mlbStatsAdapter.test.js new file mode 100644 index 0000000..b5e20ec --- /dev/null +++ b/tests/unit/mlbStatsAdapter.test.js @@ -0,0 +1,127 @@ +// Unit: MLB Stats API adapter (Session 30). No auth; cached; defensive. + +const mockAxiosGet = jest.fn(); +jest.mock('axios', () => ({ get: (...a) => mockAxiosGet(...a) })); + +const mockStore = new Map(); +const mockTtls = new Map(); +jest.mock('../../src/utils/redis', () => ({ + cacheGet: async (k) => (mockStore.has(k) ? mockStore.get(k) : null), + cacheSet: async (k, v, ttl) => { mockStore.set(k, v); mockTtls.set(k, ttl); return true; }, +})); + +const adapter = require('../../src/services/adapters/mlbStatsAdapter'); +const { TTL } = adapter.__internals; + +beforeEach(() => { + mockAxiosGet.mockReset(); + mockStore.clear(); + mockTtls.clear(); +}); + +describe('mlbStatsAdapter — no auth', () => { + test('sends NO auth headers (free API)', async () => { + mockAxiosGet.mockResolvedValue({ data: { dates: [] } }); + await adapter.getScheduleWithPitchers('2026-06-14'); + const [, opts] = mockAxiosGet.mock.calls[0]; + expect(opts.headers).toBeUndefined(); + }); +}); + +describe('mlbStatsAdapter — schedule', () => { + test('returns normalized games with probable pitchers', async () => { + mockAxiosGet.mockResolvedValue({ + data: { totalGames: 1, dates: [{ games: [{ + gamePk: 777, gameDate: '2026-06-14T17:10:00Z', + status: { abstractGameState: 'Preview' }, + venue: { name: 'GABP' }, + teams: { + home: { team: { name: 'Reds', id: 17 }, probablePitcher: { id: 1, fullName: 'Hunter Greene' } }, + away: { team: { name: 'D-backs', id: 29 }, probablePitcher: { id: 2, fullName: 'Zac Gallen' } }, + }, + }] }] }, + }); + const games = await adapter.getScheduleWithPitchers('2026-06-14'); + expect(games).toHaveLength(1); + expect(games[0].gamePk).toBe(777); + expect(games[0].home.probablePitcher).toEqual({ id: 1, name: 'Hunter Greene' }); + expect(games[0].away.team).toBe('D-backs'); + expect(games[0].venue).toBe('GABP'); + const url = mockAxiosGet.mock.calls[0][0]; + expect(url).toContain('/schedule?sportId=1&date=2026-06-14'); + expect(url).toContain('hydrate=probablePitcher'); + expect(mockTtls.get('mlbstats:schedule:2026-06-14')).toBe(TTL.schedule); + }); + + test('missing date → [] without axios', async () => { + expect(await adapter.getScheduleWithPitchers()).toEqual([]); + expect(mockAxiosGet).not.toHaveBeenCalled(); + }); + + test('error → [] (stale fallback empty)', async () => { + mockAxiosGet.mockRejectedValue(new Error('mlb down')); + expect(await adapter.getScheduleWithPitchers('2026-06-14')).toEqual([]); + }); +}); + +describe('mlbStatsAdapter — game log', () => { + test('returns per-game splits', async () => { + mockAxiosGet.mockResolvedValue({ + data: { stats: [{ splits: [ + { date: '2026-06-13', opponent: { name: 'Mets' }, isHome: true, stat: { hits: 2, homeRuns: 1 } }, + { date: '2026-06-12', opponent: { name: 'Mets' }, isHome: true, stat: { hits: 0 } }, + ] }] }, + }); + const log = await adapter.getPlayerGameLog(592450, 2026, 'hitting'); + expect(log).toHaveLength(2); + expect(log[0].stat.hits).toBe(2); + expect(log[0].opponent).toBe('Mets'); + const url = mockAxiosGet.mock.calls[0][0]; + expect(url).toContain('/people/592450/stats?stats=gameLog&season=2026&group=hitting'); + expect(mockTtls.get('mlbstats:gamelog:592450:2026:hitting')).toBe(TTL.gameLog); + }); + + test('no playerId → []', async () => { + expect(await adapter.getPlayerGameLog()).toEqual([]); + }); +}); + +describe('mlbStatsAdapter — season averages', () => { + test('returns the season stat object', async () => { + mockAxiosGet.mockResolvedValue({ data: { stats: [{ splits: [{ stat: { avg: '.312', obp: '.401', slg: '.589', ops: '.990', homeRuns: 22, rbi: 55 } }] }] } }); + const s = await adapter.getSeasonAverages(592450); + expect(s.avg).toBe('.312'); + expect(s.slg).toBe('.589'); + expect(mockTtls.get('mlbstats:season:592450:2026:hitting')).toBe(TTL.season); + }); + + test('empty splits → null', async () => { + mockAxiosGet.mockResolvedValue({ data: { stats: [] } }); + expect(await adapter.getSeasonAverages(592450)).toBeNull(); + }); +}); + +describe('mlbStatsAdapter — batter vs pitcher', () => { + test('returns matchup stat object', async () => { + mockAxiosGet.mockResolvedValue({ data: { stats: [{ splits: [{ stat: { atBats: 14, hits: 5, homeRuns: 2, avg: '.357' } }] }] } }); + const bvp = await adapter.getBatterVsPitcher(592450, 12345); + expect(bvp.hits).toBe(5); + expect(bvp.homeRuns).toBe(2); + const url = mockAxiosGet.mock.calls[0][0]; + expect(url).toContain('stats=vsPlayer&opposingPlayerId=12345'); + expect(mockTtls.get('mlbstats:bvp:592450:12345:hitting')).toBe(TTL.bvp); + }); + + test('missing ids → null without axios', async () => { + expect(await adapter.getBatterVsPitcher(null, 1)).toBeNull(); + expect(await adapter.getBatterVsPitcher(1, null)).toBeNull(); + expect(mockAxiosGet).not.toHaveBeenCalled(); + }); + + test('cache hit on repeat call', async () => { + mockAxiosGet.mockResolvedValue({ data: { stats: [{ splits: [{ stat: { hits: 1 } }] }] } }); + await adapter.getBatterVsPitcher(1, 2); + await adapter.getBatterVsPitcher(1, 2); + expect(mockAxiosGet).toHaveBeenCalledTimes(1); + }); +}); diff --git a/tests/unit/oddsProviderPreference.test.js b/tests/unit/oddsProviderPreference.test.js new file mode 100644 index 0000000..f8baaa1 --- /dev/null +++ b/tests/unit/oddsProviderPreference.test.js @@ -0,0 +1,107 @@ +// Unit: provider preference + source tracking in getOdds (Session 30). + +const mockRedis = { get: jest.fn(), set: jest.fn(), hset: jest.fn(), hgetall: jest.fn(), expire: jest.fn() }; +jest.mock('../../src/utils/redis', () => ({ + getRedisClient: () => mockRedis, + cacheGet: jest.fn(async () => null), + cacheSet: jest.fn(async () => true), + cacheDel: jest.fn(async () => true), + isDegraded: jest.fn(() => true), // gateway/quota fail open in tests +})); + +jest.mock('axios'); +const axios = require('axios'); + +// PropLine adapter mock — we drive hasKeys + getProps per test. +jest.mock('../../src/services/adapters/proplineAdapter', () => ({ + hasKeys: jest.fn(), + getProps: jest.fn(), +})); +const propline = require('../../src/services/adapters/proplineAdapter'); + +process.env.ODDS_API_KEY = 'test-api-key'; +const { getOdds } = require('../../src/services/oddsService'); + +beforeEach(() => { + jest.clearAllMocks(); + mockRedis.get.mockResolvedValue(null); // cache miss + mockRedis.set.mockResolvedValue('OK'); + mockRedis.hgetall.mockResolvedValue({}); +}); + +describe('getOdds — PropLine preferred', () => { + test('serves from PropLine when it returns props (provider=propline, no odds-api call)', async () => { + propline.hasKeys.mockReturnValue(true); + propline.getProps.mockResolvedValue({ + props: [{ player: 'Acuna', stat_type: 'hits', line: 0.5, over_odds: -200, under_odds: 160, book: 'betmgm' }], + spreads: [], + source: 'propline', + }); + + const res = await getOdds('mlb'); + expect(res.source).toBe('live'); + expect(res.provider).toBe('propline'); + expect(res.props).toHaveLength(1); + expect(axios.get).not.toHaveBeenCalled(); // odds-api never touched + // Cached payload carries the provider tag. + const cachedArg = JSON.parse(mockRedis.set.mock.calls[0][1]); + expect(cachedArg.provider).toBe('propline'); + }); + + test('falls back to odds-api when PropLine returns empty (provider=odds-api)', async () => { + propline.hasKeys.mockReturnValue(true); + propline.getProps.mockResolvedValue({ props: [], spreads: [], source: 'propline' }); + + // odds-api fallback: events list, then per-event odds. + axios.get + .mockResolvedValueOnce({ data: [{ id: 'e1', home_team: 'Denver Nuggets', away_team: 'Los Angeles Lakers', commence_time: '2026-03-21T19:00:00Z' }], headers: {} }) + .mockResolvedValueOnce({ + data: { + id: 'e1', home_team: 'Denver Nuggets', away_team: 'Los Angeles Lakers', commence_time: '2026-03-21T19:00:00Z', + bookmakers: [{ key: 'draftkings', title: 'DK', markets: [{ key: 'player_points', last_update: 't', outcomes: [ + { name: 'Over', description: 'Jokic', price: -110, point: 26.5 }, + { name: 'Under', description: 'Jokic', price: -110, point: 26.5 }, + ] }] }], + }, + headers: { 'x-requests-remaining': '400' }, + }); + + const res = await getOdds('nba'); + expect(res.provider).toBe('odds-api'); + expect(axios.get).toHaveBeenCalled(); + expect(res.props.length).toBeGreaterThan(0); + }); + + test('PropLine skipped entirely when no keys (provider=odds-api)', async () => { + propline.hasKeys.mockReturnValue(false); + axios.get + .mockResolvedValueOnce({ data: [{ id: 'e1', home_team: 'Denver Nuggets', away_team: 'Los Angeles Lakers', commence_time: '2026-03-21T19:00:00Z' }], headers: {} }) + .mockResolvedValueOnce({ + data: { id: 'e1', home_team: 'Denver Nuggets', away_team: 'Los Angeles Lakers', commence_time: '2026-03-21T19:00:00Z', + bookmakers: [{ key: 'draftkings', title: 'DK', markets: [{ key: 'player_points', last_update: 't', outcomes: [ + { name: 'Over', description: 'Jokic', price: -110, point: 26.5 }, + { name: 'Under', description: 'Jokic', price: -110, point: 26.5 }, + ] }] }] }, + headers: {}, + }); + const res = await getOdds('nba'); + expect(propline.getProps).not.toHaveBeenCalled(); + expect(res.provider).toBe('odds-api'); + }); + + test('PropLine error → graceful fallback to odds-api', async () => { + propline.hasKeys.mockReturnValue(true); + propline.getProps.mockRejectedValue(new Error('propline down')); + axios.get + .mockResolvedValueOnce({ data: [], headers: {} }); // empty events → empty props, but provider tagged + const res = await getOdds('nba'); + expect(res.provider).toBe('odds-api'); + }); + + test('cached response surfaces the stored provider', async () => { + mockRedis.get.mockResolvedValue(JSON.stringify({ updated_at: 't', props: [{ player: 'X' }], spreads: [], provider: 'propline' })); + const res = await getOdds('mlb'); + expect(res.source).toBe('cache'); + expect(res.provider).toBe('propline'); + }); +}); diff --git a/tests/unit/proplineAdapter.test.js b/tests/unit/proplineAdapter.test.js new file mode 100644 index 0000000..665562e --- /dev/null +++ b/tests/unit/proplineAdapter.test.js @@ -0,0 +1,148 @@ +// Unit: PropLine adapter (Session 30). 3-key rotation + normalization. + +const mockAxiosGet = jest.fn(); +jest.mock('axios', () => ({ get: (...a) => mockAxiosGet(...a) })); + +// Gateway is a pass-through in tests (quota allowed). +jest.mock('../../src/services/providerGateway', () => ({ + fetch: jest.fn(async (_id, cb) => cb('propline')), +})); + +const mockRedisStore = {}; +jest.mock('../../src/utils/redis', () => ({ + getRedisClient: () => ({ + get: async (k) => (k in mockRedisStore ? String(mockRedisStore[k]) : null), + incr: async (k) => { mockRedisStore[k] = (mockRedisStore[k] || 0) + 1; return mockRedisStore[k]; }, + expire: async () => 1, + }), + isDegraded: () => false, +})); + +const adapter = require('../../src/services/adapters/proplineAdapter'); + +const KEYS = { PROPLINE_API_KEY_1: 'k1', PROPLINE_API_KEY_2: 'k2', PROPLINE_API_KEY_3: 'k3' }; + +beforeEach(() => { + mockAxiosGet.mockReset(); + for (const k of Object.keys(mockRedisStore)) delete mockRedisStore[k]; + for (const k of Object.keys(adapter.__internals.memUsage)) delete adapter.__internals.memUsage[k]; + Object.assign(process.env, KEYS); +}); +afterAll(() => { + delete process.env.PROPLINE_API_KEY_1; + delete process.env.PROPLINE_API_KEY_2; + delete process.env.PROPLINE_API_KEY_3; +}); + +const SAMPLE = [{ + id: '43866', + sport_key: 'baseball_mlb', + home_team: 'Cincinnati Reds', + away_team: 'Arizona Diamondbacks', + commence_time: '2026-06-14T02:05:00Z', + bookmakers: [{ + key: 'betmgm', title: 'BetMGM', last_update: '2026-06-14T00:45:30Z', + markets: [{ + key: 'batter_hits', last_update: '2026-06-13T15:12:46Z', + outcomes: [ + { name: 'Over', description: 'Braxton Fulford', price: -200, point: 0.5 }, + { name: 'Under', description: 'Braxton Fulford', price: 160, point: 0.5 }, + ], + }], + }], +}]; + +describe('proplineAdapter — config + URL', () => { + test('hasKeys true when any key set', () => { + expect(adapter.hasKeys()).toBe(true); + }); + + test('builds the odds URL with apiKey query param + markets', async () => { + mockAxiosGet.mockResolvedValue({ data: SAMPLE }); + await adapter.fetchRaw('mlb'); + const [url, opts] = mockAxiosGet.mock.calls[0]; + expect(url).toBe('https://api.prop-line.com/v1/sports/baseball_mlb/odds'); + expect(opts.params.apiKey).toMatch(/^k[123]$/); + expect(opts.params.markets).toContain('batter_hits'); + }); + + test('unsupported sport → null without calling axios', async () => { + expect(await adapter.fetchRaw('cricket')).toBeNull(); + expect(mockAxiosGet).not.toHaveBeenCalled(); + }); +}); + +describe('proplineAdapter — normalization (Odds-API-compatible)', () => { + test('getProps normalizes into VYNDR prop shape (MLB market mapped)', async () => { + mockAxiosGet.mockResolvedValue({ data: SAMPLE }); + const out = await adapter.getProps('mlb'); + expect(out.source).toBe('propline'); + expect(out.props).toHaveLength(1); + const p = out.props[0]; + expect(p.player).toBe('Braxton Fulford'); + expect(p.stat_type).toBe('hits'); // batter_hits → hits via MARKET_MAP + expect(p.line).toBe(0.5); + expect(p.over_odds).toBe(-200); + expect(p.under_odds).toBe(160); + expect(p.book).toBe('betmgm'); + }); + + test('tolerates { data: [...] } wrapper', async () => { + mockAxiosGet.mockResolvedValue({ data: { data: SAMPLE } }); + const raw = await adapter.fetchRaw('mlb'); + expect(raw).toHaveLength(1); + }); + + test('error → getProps returns null (caller falls back)', async () => { + mockAxiosGet.mockRejectedValue(new Error('upstream 500')); + expect(await adapter.getProps('mlb')).toBeNull(); + }); +}); + +describe('proplineAdapter — 3-key rotation', () => { + test('picks the least-used key', async () => { + const { incrUsage, usageKey } = adapter.__internals; + // Make key 0 heavily used, key 1 lightly, key 2 medium. + mockRedisStore[usageKey(0)] = 500; + mockRedisStore[usageKey(2)] = 100; + const picked = await adapter.pickKey(adapter.__internals.getKeys()); + expect(picked.index).toBe(1); // unused → most remaining + }); + + test('rotates OFF a key once it crosses the 900 threshold', async () => { + const { usageKey } = adapter.__internals; + mockRedisStore[usageKey(0)] = 950; // over threshold + mockRedisStore[usageKey(1)] = 950; // over threshold + mockRedisStore[usageKey(2)] = 10; // healthy + const picked = await adapter.pickKey(adapter.__internals.getKeys()); + expect(picked.index).toBe(2); + }); + + test('all keys exhausted (>=1000) → pickKey null, fetchRaw null', async () => { + const { usageKey } = adapter.__internals; + mockRedisStore[usageKey(0)] = 1000; + mockRedisStore[usageKey(1)] = 1000; + mockRedisStore[usageKey(2)] = 1000; + expect(await adapter.pickKey(adapter.__internals.getKeys())).toBeNull(); + mockAxiosGet.mockResolvedValue({ data: SAMPLE }); + expect(await adapter.fetchRaw('mlb')).toBeNull(); + expect(mockAxiosGet).not.toHaveBeenCalled(); + }); + + test('increments usage on a successful call', async () => { + mockAxiosGet.mockResolvedValue({ data: SAMPLE }); + await adapter.fetchRaw('mlb'); + const total = Object.entries(mockRedisStore) + .filter(([k]) => k.startsWith('propline:usage:')) + .reduce((s, [, v]) => s + v, 0); + expect(total).toBe(1); + }); + + test('no keys configured → fetchRaw null', async () => { + delete process.env.PROPLINE_API_KEY_1; + delete process.env.PROPLINE_API_KEY_2; + delete process.env.PROPLINE_API_KEY_3; + expect(adapter.hasKeys()).toBe(false); + expect(await adapter.fetchRaw('mlb')).toBeNull(); + }); +}); diff --git a/web/public/sw.js b/web/public/sw.js index e6ce2a1..890487c 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':'97139c7de68b95f4af6e4f938ed537f8','url':'/_next/static/8MeesYaRWPVld3dsOVnjq/_buildManifest.js'},{'revision':'b6652df95db52feb4daf4eca35380933','url':'/_next/static/8MeesYaRWPVld3dsOVnjq/_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-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/_not-found/page-4c572a92615aa628.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-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/books/%5B...path%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/checkout/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/content/%5B...path%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/gamelines/%5Bsport%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/props/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/tonight/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/hero-prop/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/hotlist/%5Bsport%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/intelligence/feed/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/accuracy/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/lines/%5B...path%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/mlb/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/nba/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/soccer/%5Bleague%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/wnba/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/add-leg/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/calculate/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/grade/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/players/search/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/live/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/most-parlayed/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/top-graded/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/scan/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/schedule/%5Bsport%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/parlays-graded/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/public/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/streaks/%5Bsport%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/profile/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/recent-scans/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/scans/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/waitlist/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/webhook/nexapay/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/welcome-email/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/auth/callback/page-0cb8d3790d034de0.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/%5Bslug%5D/page-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/page-4c572a92615aa628.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-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/profile/page-0a7a9e981d344a6f.js'},{'revision':null,'url':'/_next/static/chunks/app/responsible-gambling/page-4c572a92615aa628.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-4c572a92615aa628.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-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/forbidden-4c572a92615aa628.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-4c572a92615aa628.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 +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':'97139c7de68b95f4af6e4f938ed537f8','url':'/_next/static/PdOmgs3_qefQGdthfLB2R/_buildManifest.js'},{'revision':'b6652df95db52feb4daf4eca35380933','url':'/_next/static/PdOmgs3_qefQGdthfLB2R/_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-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/_not-found/page-4c572a92615aa628.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-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/books/%5B...path%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/checkout/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/content/%5B...path%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/gamelines/%5Bsport%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/props/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/tonight/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/hero-prop/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/hotlist/%5Bsport%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/intelligence/feed/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/accuracy/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/lines/%5B...path%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/mlb/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/nba/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/soccer/%5Bleague%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/wnba/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/add-leg/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/calculate/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/grade/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/players/search/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/live/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/most-parlayed/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/top-graded/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/scan/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/schedule/%5Bsport%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/parlays-graded/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/public/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/streaks/%5Bsport%5D/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/profile/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/recent-scans/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/scans/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/waitlist/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/webhook/nexapay/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/api/welcome-email/route-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/auth/callback/page-0cb8d3790d034de0.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/%5Bslug%5D/page-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/page-4c572a92615aa628.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-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/app/profile/page-0a7a9e981d344a6f.js'},{'revision':null,'url':'/_next/static/chunks/app/responsible-gambling/page-4c572a92615aa628.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-4c572a92615aa628.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-4c572a92615aa628.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/forbidden-4c572a92615aa628.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-4c572a92615aa628.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