diff --git a/BUILD-STATE.md b/BUILD-STATE.md index 7279f86..2519792 100755 --- a/BUILD-STATE.md +++ b/BUILD-STATE.md @@ -4,7 +4,111 @@ 2026-06-10 ## Current Phase -SHIP BUILD v7.2 — Soccer Intelligence + World Cup 2026 (Session 7j) +SHIP BUILD v8.0 — Frontend Stripe Cutover + Soccer Pages (Session 8) + +## Session 8 (2026-06-10) — SHIPPED + +Frontend layer that connects users to the Session 7h–7j backend. +NexaPay → Stripe cutover on the pricing flow + a `/soccer` page that +exposes the soccer intelligence pipeline. + +### Files created (frontend) +- `web/src/app/api/odds/soccer/[league]/route.ts` — Next.js proxy → + Express `GET /api/odds/soccer/:league`. Validates league against the + 9 accepted codes upstream so a typo bounces at the Next boundary. +- `web/src/app/soccer/page.tsx` — live soccer odds feed. Hosts + `SportSelector`, fetches `/api/odds/soccer/:league`, groups props by + match → stat type. "Grade" button triggers inline scan via + `/api/scan` (sport: Soccer) and renders the result through + `SoccerGradeResult`. Soccer-only page; switching the selector to + another sport bounces to `/scan`. +- `web/src/app/upgrade/success/page.tsx` — Stripe success landing. + Reads `session_id`, refreshes AuthContext so the new tier flips + immediately. Does NOT verify against Stripe from the client (no + secret key on the browser) — the webhook is the source of truth. +- `web/src/app/upgrade/cancel/page.tsx` — Stripe cancel landing. +- `web/src/components/SportSelector.tsx` — pill tabs (NBA/WNBA/MLB/ + Soccer); Soccer reveals a sub-row of the 9 league codes matching + Express's `SOCCER_SPORT_KEYS`. Emits `{ sport, league? }` via + `onChange` — pure UI, no fetches. +- `web/src/components/SoccerGradeResult.tsx` — soccer-themed result + card. Parses the engine's reasoning summary into visual chips + (⚽ goals/90, 📊 xG, 🎯 penalty taker, 🏹 free-kick taker, ⛳ corner + taker, 🏔️ altitude, 🟨 referee, ⏱️ minutes discount, 🛡️ opponent + defense, 🏆 tournament pedigree). Color-coded by tone + (positive / caution / warning / neutral). Free-tier responses + (carrying `tier_gated: true`) render the chip row blurred under an + upgrade CTA; the structured grade + confidence + edge stay visible. + Kept separate from `GradeCard` so the NBA/MLB/WNBA path is + untouched. + +### Files modified (frontend) +- `web/src/app/api/checkout/route.ts` — full rewrite. Was a NexaPay + payment-link creator; is now a thin proxy that forwards `{ tier, + founder_code? }` + bearer to Express `/api/stripe/checkout`. + Response remap: `checkout_url` → `url` for callsite compat; both + fields shipped so either reads cleanly. +- `web/src/app/api/scan/route.ts` — accepts `Soccer` sport in addition + to NBA/MLB/WNBA. Soccer stat-type allowlist mirrors the backend + `VALID_STAT_TYPES` (goals, shots_on_target, shots, tackles, cards, + corners, saves, goals_conceded, passes, clean_sheet, assists). +- `web/src/components/Pricing.tsx` — CTAs converted from `` to + onClick handlers. Uses `useAuth()` for the bearer token, POSTs to + `/api/checkout`, `window.location.assign` to the returned Stripe URL. + Loading state on the active tier, inline error banner. Anonymous + visitors bounce to `/signup?return=/%23pricing`. Footnote rewritten + from "NexaPay" to "Stripe (test mode while we onboard founders)". +- `web/src/components/Nav.tsx` — small BETA tag next to the wordmark. + Glitch-styled, monospace, low-opacity green border. Renders on every + page that mounts Nav. + +### Files modified (backend — ONE allowed change) +- `src/services/stripeService.js` — `success_url` / `cancel_url` + point at the frontend (`NEXT_PUBLIC_SITE_URL` with `BASE_URL` + fallback, default `http://localhost:3000`). Previously the routes + pointed at the Express origin which would have 404'd the redirect. + New URLs: + - `${frontendUrl}/upgrade/success?session_id={CHECKOUT_SESSION_ID}` + - `${frontendUrl}/upgrade/cancel` + All 23 Stripe tests still pass (none asserted on the URL strings). + +### Files modified (docs) +- `docs/SYSTEM-MANIFEST.md` — `/api/odds/soccer/[league]` row in + Next.js routes, new section listing the three new Next.js pages, + the Session 7h "dual-provider divergence" callout flipped from + open-work to ✅ complete. +- `BUILD-STATE.md` — Session 8 entry. + +### Honest verification status + +Build-verified (passed `web/npm run build` after every component): +- All TypeScript types resolve +- All routes prerender / build correctly (24 pages, 30+ API routes) +- No ESLint errors + +NOT runtime-verified in this session (I have no browser to click +through): +- Actual Stripe checkout redirect end-to-end (test mode card flow) +- Soccer odds rendering with live data (depends on + `FOOTBALL_DATA_API_KEY` being set in prod and the daily prefetch + having run) +- SoccerGradeResult signal parsing against a real engine response + (signal-chip regex tested against the exact phrasing + `buildSoccerReasoningLines` emits in `analyzeViaEngine1.js`, but + not against live engine output) +- AuthContext.refresh() actually triggering a profile re-read after + the Stripe redirect + +These are the expected next-session sanity checks once Coolify +deploys this build. + +### Quality gates +- `npm test` (backend): **1173 / 1173 passing**, 91 suites, 0 regressions + from Session 7j baseline +- `web/npm run build`: clean — all new routes prerendered, no type errors +- License audit: only permissive licenses + +--- ## Session 7j (2026-06-10) — SHIPPED diff --git a/data/training/resolutions-2026-06.jsonl b/data/training/resolutions-2026-06.jsonl index 5c54ced..fe3e753 100644 --- a/data/training/resolutions-2026-06.jsonl +++ b/data/training/resolutions-2026-06.jsonl @@ -439,3 +439,17 @@ {"ts":"2026-06-10T18:29:14.213Z","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-10T18:29:14.229Z","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-10T18:29:14.240Z","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-10T19:00:15.858Z","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-10T19:00:16.029Z","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-10T19:00:16.037Z","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-10T19:00:16.037Z","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-10T19:00:16.264Z","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-10T19:00:16.380Z","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-10T19:00:16.686Z","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-10T19:18:38.940Z","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-10T19:18:39.104Z","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-10T19:18:39.109Z","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-10T19:18:39.109Z","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-10T19:18:39.153Z","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-10T19:18:39.210Z","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-10T19:18:39.431Z","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"} diff --git a/docs/SYSTEM-MANIFEST.md b/docs/SYSTEM-MANIFEST.md index d0920c2..36b1d6c 100644 --- a/docs/SYSTEM-MANIFEST.md +++ b/docs/SYSTEM-MANIFEST.md @@ -99,19 +99,26 @@ Mounted in `src/app.js`. Auth column meanings: These are proxies or thin wrappers; they hit Express via `BACKEND_URL` or the Python service via `NEXT_PUBLIC_NBA_SERVICE_URL`. -- `/api/checkout` (POST/GET) — NexaPay checkout +- `/api/checkout` (POST/GET) — Stripe checkout proxy (Session 8 cutover — was NexaPay) - `/api/games/[id]` and `/api/games/tonight` — list / detail - `/api/games/[id]/props` — props for a game - `/api/intelligence/feed` — homepage live signals - `/api/ledger`, `/api/ledger/accuracy` — Ledger feed +- `/api/odds/soccer/[league]` — soccer odds proxy → Express `/api/odds/soccer/:league` (Session 8) - `/api/parlay/add-leg`, `/api/parlay/grade` — proxy to `/api/scan/parlay` - `/api/players/search` — proxy to Python `/players/search` - `/api/props/live`, `/api/props/most-parlayed`, `/api/props/top-graded` -- `/api/scan` — bare scan endpoint +- `/api/scan` — bare scan endpoint (Session 8 — accepts `Soccer` sport in addition to NBA/MLB/WNBA) - `/api/stats/parlays-graded`, `/api/stats/public` — proxy - `/api/user/profile`, `/api/user/scans`, `/api/user/recent-scans` - `/api/waitlist` — proxy -- `/api/webhook/nexapay` — NexaPay webhook +- `/api/webhook/nexapay` — NexaPay webhook (legacy — Stripe cutover Session 8; webhook still listening for any in-flight NexaPay events) + +### Next.js pages (Session 8 additions) + +- `/soccer` — live soccer odds feed + inline prop grading. Hosts `SportSelector` + per-league match cards, scans selected props through `/api/scan` → Express `/api/analyze/prop` with `sport: 'Soccer'`. Results render in `SoccerGradeResult` (parses the engine's reasoning summary into visual signal chips: ⚽ goals/90, 📊 xG, 🏔️ altitude, 🟨 referee, 🎯 penalty taker, 🏆 WC pedigree). Free tier gets a blurred preview + upgrade CTA. +- `/upgrade/success` — Stripe checkout success landing. Reads `session_id` query param, refreshes the AuthContext so the new tier flips immediately. Stripe webhook is the source of truth; this page does not verify the session against Stripe (no secret key on the client). +- `/upgrade/cancel` — Stripe checkout cancel landing. No judgment, links back to `/#pricing` and `/scan`. --- @@ -615,28 +622,26 @@ All frontend API paths discovered are either: handler. Spot-checked: `/api/players/search` (Next → Python), `/api/scan` (Next → Express), `/api/intelligence/feed` (Next direct DB). -#### Payments: dual-provider divergence (Session 7h) +#### Payments: Stripe cutover (Session 8 — COMPLETE) -The frontend `/api/checkout` (Next.js) creates **NexaPay** payment -links and is what `web/src/components/Pricing.tsx` CTAs currently hit. -The Express `POST /api/stripe/checkout` (Stripe Checkout Sessions) is -fully wired, tested in test mode against real Stripe resources -(products + prices + webhook all created), and ready for traffic — -but no frontend caller invokes it yet. Cutover work for a follow-up -session: +The dual-provider divergence flagged in 7h is closed: -1. Replace `web/src/app/api/checkout/route.ts` body to fetch - `${BACKEND_URL}/api/stripe/checkout` with the user's bearer token - instead of calling NexaPay's `createPaymentLink`. -2. Wire `Pricing.tsx` CTAs through that same Next.js route (response - shape is already `{ url, ... }`-compatible; Express returns - `{ checkout_url, session_id }`, so the proxy needs to remap - `checkout_url → url`). -3. Add `/upgrade/success?session_id=...` and `/upgrade/cancel` pages. - Current Stripe `success_url` points at `/scan?upgraded=true` and - `cancel_url` at `/#pricing` — those work but a confirmation page - reads better. -4. Decide on NexaPay: keep as fallback, remove, or feature-flag. +1. ✅ `web/src/app/api/checkout/route.ts` now forwards to + `${BACKEND_URL}/api/stripe/checkout` with the user's bearer token. + The route remaps `{ checkout_url, session_id }` → `{ url, … }` so + the existing client field shape still works. +2. ✅ `Pricing.tsx` CTAs were converted from `` to onClick + handlers that POST to `/api/checkout` and `window.location.assign` + the returned Stripe URL. Loading state during redirect; error + surfaced inline. +3. ✅ `/upgrade/success?session_id=…` and `/upgrade/cancel` pages + shipped. Express `stripeService.js` updated to point `success_url` + and `cancel_url` at the new frontend pages via `NEXT_PUBLIC_SITE_URL` + (the only backend file touched in Session 8). +4. NexaPay is still wired but no UI calls it. Disposition (remove vs + keep as fallback) is a follow-up call — leaving it in place doesn't + cost anything and gives the team a fallback if Stripe goes down + during the World Cup window. --- diff --git a/src/services/stripeService.js b/src/services/stripeService.js index 9a84ad7..6a14563 100644 --- a/src/services/stripeService.js +++ b/src/services/stripeService.js @@ -57,13 +57,21 @@ async function createCheckoutSession(userId, email, tier, founderCode) { .eq('id', userId); } - const baseUrl = process.env.BASE_URL || 'http://localhost:3001'; + // Stripe sends the user to a FRONTEND URL after checkout — not the + // Express API. NEXT_PUBLIC_SITE_URL is the canonical frontend origin + // (defaults to https://vyndr.app per the email templates), with + // BASE_URL as a fallback for legacy deploys that only set the API + // origin. localhost:3000 is the Next dev server default; Express + // dev runs on 3001 so we never want to send users there. + const frontendUrl = process.env.NEXT_PUBLIC_SITE_URL + || process.env.BASE_URL + || 'http://localhost:3000'; const session = await getStripe().checkout.sessions.create({ customer: customerId, line_items: [{ price: priceId, quantity: 1 }], mode: 'subscription', - success_url: `${baseUrl}/scan?upgraded=true`, - cancel_url: `${baseUrl}/#pricing`, + success_url: `${frontendUrl}/upgrade/success?session_id={CHECKOUT_SESSION_ID}`, + cancel_url: `${frontendUrl}/upgrade/cancel`, metadata: { user_id: userId, tier, is_founder: String(isFounder) }, }); diff --git a/web/public/sw.js b/web/public/sw.js index 079afe3..ade5825 100644 --- a/web/public/sw.js +++ b/web/public/sw.js @@ -1,2 +1,2 @@ (()=>{"use strict";let e,t,a,s,r,n={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"serwist",runtime:"runtime",suffix:"u">typeof registration?registration.scope:""},i=e=>[n.prefix,e,n.suffix].filter(e=>e&&e.length>0).join("-"),c=e=>e||i(n.precache),o=e=>e||i(n.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 m(e,t,a,s){let r=d(t.url,a);if(t.url===r)return e.match(t,s);let n={...s,ignoreSearch:!0};for(let i of(await e.keys(t,n)))if(r===d(i.url,a))return e.match(i,s)}var f=class{promise;resolve;reject;constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}};let g=async()=>{for(let e of u)await e()},w="-precache-",p=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),x=new WeakMap,b=new WeakMap,v=new WeakMap,E={get(e,t,a){if(e instanceof IDBTransaction){if("done"===t)return x.get(e);if("store"===t)return a.objectStoreNames[1]?void 0:a.objectStore(a.objectStoreNames[0])}return R(e[t])},set:(e,t,a)=>(e[t]=a,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function R(e){if(e instanceof IDBRequest){let t;return t=new Promise((t,a)=>{let s=()=>{e.removeEventListener("success",r),e.removeEventListener("error",n)},r=()=>{t(R(e.result)),s()},n=()=>{a(e.error),s()};e.addEventListener("success",r),e.addEventListener("error",n)}),v.set(t,e),t}if(b.has(e))return b.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(q(this),t),R(this.request)}:function(...t){return R(e.apply(q(this),t))};return(e instanceof IDBTransaction&&function(e){if(x.has(e))return;let t=new Promise((t,a)=>{let s=()=>{e.removeEventListener("complete",r),e.removeEventListener("error",n),e.removeEventListener("abort",n)},r=()=>{t(),s()},n=()=>{a(e.error||new DOMException("AbortError","AbortError")),s()};e.addEventListener("complete",r),e.addEventListener("error",n),e.addEventListener("abort",n)});x.set(e,t)}(e),_(e,s||(s=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])))?new Proxy(e,E):e}(e);return t!==e&&(b.set(e,t),v.set(t,e)),t}let q=e=>v.get(e);function S(e,t,{blocked:a,upgrade:s,blocking:r,terminated:n}={}){let i=indexedDB.open(e,t),c=R(i);return s&&i.addEventListener("upgradeneeded",e=>{s(R(i.result),e.oldVersion,e.newVersion,R(i.transaction),e)}),a&&i.addEventListener("blocked",e=>a(e.oldVersion,e.newVersion,e)),c.then(e=>{n&&e.addEventListener("close",()=>n()),r&&e.addEventListener("versionchange",e=>r(e.oldVersion,e.newVersion,e))}).catch(()=>{}),c}let D=["get","getKey","getAll","getAllKeys","count"],N=["put","add","delete","clear"],C=new Map;function T(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&"string"==typeof t))return;if(C.get(t))return C.get(t);let a=t.replace(/FromIndex$/,""),s=t!==a,r=N.includes(a);if(!(a in(s?IDBIndex:IDBObjectStore).prototype)||!(r||D.includes(a)))return;let n=async function(e,...t){let n=this.transaction(e,r?"readwrite":"readonly"),i=n.store;return s&&(i=i.index(t.shift())),(await Promise.all([i[a](...t),r&&n.done]))[0]};return C.set(t,n),n}E={...e=E,get:(t,a,s)=>T(t,a)||e.get(t,a,s),has:(t,a)=>!!T(t,a)||e.has(t,a)};let P=["continue","continuePrimaryKey","advance"],k={},A=new WeakMap,I=new WeakMap,U={get(e,t){if(!P.includes(t))return e[t];let a=k[t];return a||(a=k[t]=function(...e){A.set(this,I.get(this)[t](...e))}),a}};async function*L(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;let a=new Proxy(t,U);for(I.set(a,t),v.set(a,q(t));t;)yield a,t=await (A.get(a)||t.continue()),A.delete(a)}function F(e,t){return t===Symbol.asyncIterator&&_(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&_(e,[IDBIndex,IDBObjectStore])}E={...t=E,get:(e,a,s)=>F(e,a)?L:t.get(e,a,s),has:(e,a)=>F(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(),n={headers:new Headers(r.headers),status:r.status,statusText:r.statusText},i=t?t(n):n,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,i)},O="requests",B="queueName";var K=class{_db=null;async addEntry(e){let t=(await this.getDb()).transaction(O,"readwrite",{durability:"relaxed"});await t.store.add(e),await t.done}async getFirstEntryId(){return(await (await this.getDb()).transaction(O).store.openCursor())?.value.id}async getAllEntriesByQueueName(e){return await (await this.getDb()).getAllFromIndex(O,B,IDBKeyRange.only(e))||[]}async getEntryCountByQueueName(e){return(await this.getDb()).countFromIndex(O,B,IDBKeyRange.only(e))}async deleteEntry(e){await (await this.getDb()).delete(O,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(O).store.index(B).openCursor(e,t))?.value}async getDb(){return this._db||(this._db=await S("serwist-background-sync",3,{upgrade:this._upgradeDb})),this._db}_upgradeDb(e,t){t>0&&t<3&&e.objectStoreNames.contains(O)&&e.deleteObjectStore(O),e.createObjectStore(O,{autoIncrement:!0,keyPath:"id"}).createIndex(B,B,{unique:!1})}},W=class{_queueName;_queueDb;constructor(e){this._queueName=e,this._queueDb=new K}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 $=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 H="serwist-background-sync",V=new Set,G=e=>{let t={request:new $(e.requestData).toRequest(),timestamp:e.timestamp};return e.metadata&&(t.metadata=e.metadata),t};var Q=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(G(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 $.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):G(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(`${H}:${this._name}`)}catch(e){}}_addSyncListener(){"sync"in self.registration&&!this._forceSyncFallback?self.addEventListener("sync",e=>{if(e.tag===`${H}:${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 Q(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 f,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 n=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:n,response:e});return e}catch(e){throw r&&await this.runCallbacks("fetchDidFail",{error:e,event:t,originalRequest:r.clone(),request:n.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,n=await this.getCacheKey(a,"read"),i={...r,cacheName:s};for(let e of(t=await caches.match(n,i),this.iterateCallbacks("cachedResponseWillBeUsed")))t=await e({cacheName:s,matchOptions:r,cachedResponse:t,request:n,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:n,matchOptions:i}=this._strategy,c=await self.caches.open(n),o=this.hasCallback("cacheDidUpdate"),u=o?await m(c,s.clone(),["__WB_REVISION__"],i):null;try{await c.put(s,o?r.clone():r)}catch(e){if(e instanceof Error)throw"QuotaExceededError"===e.name&&await g(),e}for(let e of this.iterateCallbacks("cacheDidUpdate"))await e({cacheName:n,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 n of e.iterateCallbacks("handlerDidError"))if(void 0!==(s=await n({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,n;try{r=await e}catch{}try{await t.runCallbacks("handlerDidRespond",{event:s,request:a,response:r}),await t.doneWaiting()}catch(e){e instanceof Error&&(n=e)}if(await t.runCallbacks("handlerDidComplete",{event:s,request:a,response:r,error:n}),t.destroy(),n)throw n}},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:n,promise:i}=this._getTimeoutPromise({request:e,logs:s,handler:t});a=n,r.push(i)}let n=this._getNetworkPromise({timeoutId:a,request:e,logs:s,handler:t});r.push(n);let i=await t.waitUntil((async()=>await t.waitUntil(Promise.race(r))||await n)());if(!i)throw new l("no-response",{url:e.url});return i}_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,n;try{n=await s.fetchAndCachePut(t)}catch(e){e instanceof Error&&(r=e)}return e&&clearTimeout(e),(r||!n)&&(n=await s.cacheMatch(t)),n}},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,n=e.integrity,i=!n||n===r;a=await t.fetch(new Request(e,{integrity:"no-cors"!==e.mode?n||r:void 0})),r&&i&&"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)}},en=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))}},ei=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 n=await a(r.item);t.push({result:n,index:r.index})}},n=Array.from({length:e},()=>new Promise(r));return(await Promise.all(n)).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)),R(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 n=a.value;n.cacheName===this._cacheName&&(e&&n.timestamp=t?(a.delete(),s.push(n.url)):r++),a=await a.continue()}return s}async getDb(){return this._db||(this._db=await S("serwist-expiration",1,{upgrade:this._upgradeDbAndDeleteOldDbs.bind(this)})),this._db}},em=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 em(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),n=this._getCacheExpiration(t),i="last-used"===this._config.maxAgeFrom,c=(async()=>{i&&await n.updateTimestamp(a.url),await n.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 eg=/^\/(\w+\/)?collect/,ew=({serwist:e,cacheName:t,...a})=>{let s,r,c=t||i(n.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,n=new URL(s.url);try{let e="POST"===s.method?new URLSearchParams(await s.clone().text()):n.searchParams,t=r-(Number(e.get("qt"))||0),i=Date.now()-t;if(e.set("qt",String(i)),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(n.origin+n.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&&eg.test(e.pathname),r=new et({plugins:[o]}),"GET"),new es(s,r,"POST")])e.registerRoute(t)};var ep=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}}};let ey=async(e,t)=>{try{if(206===t.status)return t;let a=e.headers.get("range");if(!a)throw new l("no-range-header");let s=(e=>{let t=e.trim().toLowerCase();if(!t.startsWith("bytes="))throw new l("unit-must-be-bytes",{normalizedRangeHeader:t});if(t.includes(","))throw new l("single-range-only",{normalizedRangeHeader:t});let a=/(\d*)-(\d*)/.exec(t);if(!a||!(a[1]||a[2]))throw new l("invalid-range-values",{normalizedRangeHeader:t});return{start:""===a[1]?void 0:Number(a[1]),end:""===a[2]?void 0:Number(a[2])}})(a),r=await t.blob(),n=((e,t,a)=>{let s,r,n=e.size;if(a&&a>n||t&&t<0)throw new l("range-not-satisfiable",{size:n,end:a,start:t});return void 0!==t&&void 0!==a?(s=t,r=a+1):void 0!==t&&void 0===a?(s=t,r=n):void 0!==a&&void 0===t&&(s=n-a,r=n),{start:s,end:r}})(r,s.start,s.end),i=r.slice(n.start,n.end),c=i.size,o=new Response(i,{status:206,statusText:"Partial Content",headers:t.headers});return o.headers.set("Content-Length",String(c)),o.headers.set("Content-Range",`bytes ${n.start}-${n.end-1}/${r.size}`),o}catch(e){return new Response("",{status:416,statusText:"Range Not Satisfiable"})}};var e_=class{cachedResponseWillBeUsed=async({request:e,cachedResponse:t})=>t&&e.headers.has("range")?await ey(e,t):t},ex=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}},eb=class extends Z{constructor(e={}){super(e),this.plugins.some(e=>"cacheWillUpdate"in e)||this.plugins.unshift(Y)}async _handle(e,t){let a,s=t.fetchAndCachePut(e).catch(()=>{});t.waitUntil(s);let r=await t.cacheMatch(e);if(r);else try{r=await s}catch(e){e instanceof Error&&(a=e)}if(!r)throw new l("no-response",{url:e.url,error:a});return r}},ev=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 n=new URL(e,location.href);n.hash="",yield n.href;let i=((e,t=[])=>{for(let a of[...e.searchParams.keys()])t.some(e=>e.test(a))&&e.searchParams.delete(a);return e})(n,a);if(yield i.href,t&&i.pathname.endsWith("/")){let e=new URL(i.href);e.pathname+=t,yield e.href}if(s){let e=new URL(i.href);e.pathname+=".html",yield e.href}if(r)for(let e of r({url:n}))yield e.href}(a.url,t)){let t=s.get(r);if(t)return{cacheKey:t,integrity:e.getIntegrityForPrecacheKey(t)}}},e.precacheStrategy)}},eE=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}},eR=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:i,clientsClaim:o=!1,runtimeCaching:l,offlineAnalyticsConfig:h,disableDevLogs:u=!1,fallbacks:d,requestRules:m}={}){const{precacheStrategyOptions:f,precacheRouteOptions:g,precacheMiscOptions:w}=((e,t={})=>{let{cacheName:a,plugins:s=[],fetchOptions:r,matchOptions:n,fallbackToNetwork:i,directoryIndex:o,ignoreURLParametersMatching:l,cleanURLs:h,urlManipulation:u,cleanupOutdatedCaches:d,concurrency:m=10,navigateFallback:f,navigateFallbackAllowlist:g,navigateFallbackDenylist:w}=t??{};return{precacheStrategyOptions:{cacheName:c(a),plugins:[...s,new eE({precacheController:e})],fetchOptions:r,matchOptions:n,fallbackToNetwork:i},precacheRouteOptions:{directoryIndex:o,ignoreURLParametersMatching:l,cleanURLs:h,urlManipulation:u},precacheMiscOptions:{cleanupOutdatedCaches:d,concurrency:m,navigateFallback:f,navigateFallbackAllowlist:g,navigateFallbackDenylist:w}}})(this,t);if(this._concurrentPrecaching=w.concurrency,this._precacheStrategy=new er(f),this._routes=new Map,this._defaultHandlerMap=new Map,this._requestRules=m,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!==i&&(e=>{var t=e;for(let e of Object.keys(n))(e=>{let a=t[e];"string"==typeof a&&(n[e]=a)})(e)})({prefix:i}),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(p(c(e)).then(e=>{}))})})(f.cacheName),this.registerRoute(new ev(this,g)),w.navigateFallback&&this.registerRoute(new en(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 ep({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),n=new Request(t,{integrity:s,cache:r,credentials:"same-origin"});await Promise.all(this.precacheStrategy.handleAll({event:e,request:n,url:new URL(n.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 ei(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:n,route:i}=this.findMatchingRoute({event:t,request:e,sameOrigin:r,url:s}),c=i?.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:n})}catch(e){a=Promise.reject(e)}let l=i?.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:n})}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 n,i=r.match({url:e,sameOrigin:t,request:a,event:s});if(i)return Array.isArray(n=i)&&0===n.length||i.constructor===Object&&0===Object.keys(i).length?n=void 0:"boolean"==typeof i&&(n=void 0),{route:r,params:n}}return{}}};let eq=[{matcher:/^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,handler:new ex({cacheName:"google-fonts-webfonts",plugins:[new ef({maxEntries:4,maxAgeSeconds:31536e3,maxAgeFrom:"last-used"})]})},{matcher:/^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,handler:new eb({cacheName:"google-fonts-stylesheets",plugins:[new ef({maxEntries:4,maxAgeSeconds:604800,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,handler:new eb({cacheName:"static-font-assets",plugins:[new ef({maxEntries:4,maxAgeSeconds:604800,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,handler:new eb({cacheName:"static-image-assets",plugins:[new ef({maxEntries:64,maxAgeSeconds:2592e3,maxAgeFrom:"last-used"})]})},{matcher:/\/_next\/static.+\.js$/i,handler:new ex({cacheName:"next-static-js-assets",plugins:[new ef({maxEntries:64,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\/_next\/image\?url=.+$/i,handler:new eb({cacheName:"next-image",plugins:[new ef({maxEntries:64,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:mp3|wav|ogg)$/i,handler:new ex({cacheName:"static-audio-assets",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"}),new e_]})},{matcher:/\.(?:mp4|webm)$/i,handler:new ex({cacheName:"static-video-assets",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"}),new e_]})},{matcher:/\.(?:js)$/i,handler:new eb({cacheName:"static-js-assets",plugins:[new ef({maxEntries:48,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:css|less)$/i,handler:new eb({cacheName:"static-style-assets",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\/_next\/data\/.+\/.+\.json$/i,handler:new ee({cacheName:"next-data",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:json|xml|csv)$/i,handler:new ee({cacheName:"static-data-assets",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\/api\/auth\/.*/,handler:new et({networkTimeoutSeconds:10})},{matcher:({sameOrigin:e,url:{pathname:t}})=>e&&t.startsWith("/api/"),method:"GET",handler:new ee({cacheName:"apis",plugins:[new ef({maxEntries:16,maxAgeSeconds:86400,maxAgeFrom:"last-used"})],networkTimeoutSeconds:10})},{matcher:({request:e,url:{pathname:t},sameOrigin:a})=>"1"===e.headers.get("RSC")&&"1"===e.headers.get("Next-Router-Prefetch")&&a&&!t.startsWith("/api/"),handler:new ee({cacheName:"pages-rsc-prefetch",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400})]})},{matcher:({request:e,url:{pathname:t},sameOrigin:a})=>"1"===e.headers.get("RSC")&&a&&!t.startsWith("/api/"),handler:new ee({cacheName:"pages-rsc",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400})]})},{matcher:({request:e,url:{pathname:t},sameOrigin:a})=>e.headers.get("Content-Type")?.includes("text/html")&&a&&!t.startsWith("/api/"),handler:new ee({cacheName:"pages",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400})]})},{matcher:({url:{pathname:e},sameOrigin:t})=>t&&!e.startsWith("/api/"),handler:new ee({cacheName:"others",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400})]})},{matcher:({sameOrigin:e})=>!e,handler:new ee({cacheName:"cross-origin",plugins:[new ef({maxEntries:32,maxAgeSeconds:3600})],networkTimeoutSeconds:10})},{matcher:/.*/i,method:"GET",handler:new et}];new eR({precacheEntries:[{'revision':'eb0695a824207ab91c8394dca5ba308f','url':'/_next/static/ZXFYgrDffjC5_DVyoLfcp/_buildManifest.js'},{'revision':'b6652df95db52feb4daf4eca35380933','url':'/_next/static/ZXFYgrDffjC5_DVyoLfcp/_ssgManifest.js'},{'revision':null,'url':'/_next/static/chunks/1958-a1cd681eb2c1a83e.js'},{'revision':null,'url':'/_next/static/chunks/4bd1b696-c2f6e0877b6c10aa.js'},{'revision':null,'url':'/_next/static/chunks/5838-7ac6ecc648315323.js'},{'revision':null,'url':'/_next/static/chunks/6810-8b074082a0b51859.js'},{'revision':null,'url':'/_next/static/chunks/7938-3aca95fbb5e36779.js'},{'revision':null,'url':'/_next/static/chunks/8500-3953cc33eeceb44e.js'},{'revision':null,'url':'/_next/static/chunks/9da6db1e-54d62c4d2564a0ac.js'},{'revision':null,'url':'/_next/static/chunks/app/_global-error/page-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/_not-found/page-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/checkout/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/props/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/tonight/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/intelligence/feed/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/accuracy/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/add-leg/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/grade/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/players/search/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/live/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/most-parlayed/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/top-graded/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/scan/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/parlays-graded/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/public/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/profile/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/recent-scans/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/scans/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/waitlist/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/api/webhook/nexapay/route-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/auth/callback/page-f6253334ccab6a26.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/%5Bslug%5D/page-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/page-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/dashboard/page-107967f64e4a489c.js'},{'revision':null,'url':'/_next/static/chunks/app/forgot-password/page-012a02e7c1c1bf4c.js'},{'revision':null,'url':'/_next/static/chunks/app/game/%5Bid%5D/page-2c1eb07021c4e596.js'},{'revision':null,'url':'/_next/static/chunks/app/intelligence/page-67a1ff5cb5db4b20.js'},{'revision':null,'url':'/_next/static/chunks/app/layout-3a96900bea5fa4a8.js'},{'revision':null,'url':'/_next/static/chunks/app/ledger/page-b2f371ae0e2dc445.js'},{'revision':null,'url':'/_next/static/chunks/app/login/page-e0e44e4f9dfb8d77.js'},{'revision':null,'url':'/_next/static/chunks/app/marketplace/page-ce0df41afd789a48.js'},{'revision':null,'url':'/_next/static/chunks/app/not-found-386ba9205922d4c3.js'},{'revision':null,'url':'/_next/static/chunks/app/page-f47792ee8cedc53b.js'},{'revision':null,'url':'/_next/static/chunks/app/privacy/page-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/profile/page-589cb3a364727c3b.js'},{'revision':null,'url':'/_next/static/chunks/app/responsible-gambling/page-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/scan/page-ee1e7545074ffd2a.js'},{'revision':null,'url':'/_next/static/chunks/app/settings/security/page-6728e10517c834af.js'},{'revision':null,'url':'/_next/static/chunks/app/signup/page-06c72711414c663d.js'},{'revision':null,'url':'/_next/static/chunks/app/terms/page-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/app/tracker/page-c75c1f66c42eac58.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/desk/page-416ebb86e698df18.js'},{'revision':null,'url':'/_next/static/chunks/app/verify/page-b5ca90220207b0ae.js'},{'revision':null,'url':'/_next/static/chunks/app/welcome/page-ff77b94f609b0d52.js'},{'revision':null,'url':'/_next/static/chunks/framework-29591c88a1db84ab.js'},{'revision':null,'url':'/_next/static/chunks/main-ad5ed0494576592d.js'},{'revision':null,'url':'/_next/static/chunks/main-app-f54c179578b140aa.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/app-error-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/forbidden-115bee36cba427f1.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/global-error-d5beecc31181c673.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/unauthorized-115bee36cba427f1.js'},{'revision':'846118c33b2c0e922d7b3a7676f81f6f','url':'/_next/static/chunks/polyfills-42372ed130431b0a.js'},{'revision':null,'url':'/_next/static/chunks/webpack-9660626b6ab2c75c.js'},{'revision':null,'url':'/_next/static/css/64fdd512527e72f3.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':'27007d181514e7fe4213035736a8300e','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("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:n="/"}=t;e.waitUntil(self.registration.showNotification(a,{body:s,icon:r,badge:"/icons/icon-192.png",data:{url:n}}))}),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),n=new Request(t,{integrity:s,cache:r,credentials:"same-origin"});await Promise.all(this.precacheStrategy.handleAll({event:e,request:n,url:new URL(n.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 ei(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:n,route:i}=this.findMatchingRoute({event:t,request:e,sameOrigin:r,url:s}),c=i?.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:n})}catch(e){a=Promise.reject(e)}let l=i?.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:n})}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 n,i=r.match({url:e,sameOrigin:t,request:a,event:s});if(i)return Array.isArray(n=i)&&0===n.length||i.constructor===Object&&0===Object.keys(i).length?n=void 0:"boolean"==typeof i&&(n=void 0),{route:r,params:n}}return{}}};let eq=[{matcher:/^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,handler:new ex({cacheName:"google-fonts-webfonts",plugins:[new ef({maxEntries:4,maxAgeSeconds:31536e3,maxAgeFrom:"last-used"})]})},{matcher:/^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,handler:new eb({cacheName:"google-fonts-stylesheets",plugins:[new ef({maxEntries:4,maxAgeSeconds:604800,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,handler:new eb({cacheName:"static-font-assets",plugins:[new ef({maxEntries:4,maxAgeSeconds:604800,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,handler:new eb({cacheName:"static-image-assets",plugins:[new ef({maxEntries:64,maxAgeSeconds:2592e3,maxAgeFrom:"last-used"})]})},{matcher:/\/_next\/static.+\.js$/i,handler:new ex({cacheName:"next-static-js-assets",plugins:[new ef({maxEntries:64,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\/_next\/image\?url=.+$/i,handler:new eb({cacheName:"next-image",plugins:[new ef({maxEntries:64,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:mp3|wav|ogg)$/i,handler:new ex({cacheName:"static-audio-assets",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"}),new e_]})},{matcher:/\.(?:mp4|webm)$/i,handler:new ex({cacheName:"static-video-assets",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"}),new e_]})},{matcher:/\.(?:js)$/i,handler:new eb({cacheName:"static-js-assets",plugins:[new ef({maxEntries:48,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:css|less)$/i,handler:new eb({cacheName:"static-style-assets",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\/_next\/data\/.+\/.+\.json$/i,handler:new ee({cacheName:"next-data",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\.(?:json|xml|csv)$/i,handler:new ee({cacheName:"static-data-assets",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400,maxAgeFrom:"last-used"})]})},{matcher:/\/api\/auth\/.*/,handler:new et({networkTimeoutSeconds:10})},{matcher:({sameOrigin:e,url:{pathname:t}})=>e&&t.startsWith("/api/"),method:"GET",handler:new ee({cacheName:"apis",plugins:[new ef({maxEntries:16,maxAgeSeconds:86400,maxAgeFrom:"last-used"})],networkTimeoutSeconds:10})},{matcher:({request:e,url:{pathname:t},sameOrigin:a})=>"1"===e.headers.get("RSC")&&"1"===e.headers.get("Next-Router-Prefetch")&&a&&!t.startsWith("/api/"),handler:new ee({cacheName:"pages-rsc-prefetch",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400})]})},{matcher:({request:e,url:{pathname:t},sameOrigin:a})=>"1"===e.headers.get("RSC")&&a&&!t.startsWith("/api/"),handler:new ee({cacheName:"pages-rsc",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400})]})},{matcher:({request:e,url:{pathname:t},sameOrigin:a})=>e.headers.get("Content-Type")?.includes("text/html")&&a&&!t.startsWith("/api/"),handler:new ee({cacheName:"pages",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400})]})},{matcher:({url:{pathname:e},sameOrigin:t})=>t&&!e.startsWith("/api/"),handler:new ee({cacheName:"others",plugins:[new ef({maxEntries:32,maxAgeSeconds:86400})]})},{matcher:({sameOrigin:e})=>!e,handler:new ee({cacheName:"cross-origin",plugins:[new ef({maxEntries:32,maxAgeSeconds:3600})],networkTimeoutSeconds:10})},{matcher:/.*/i,method:"GET",handler:new et}];new eR({precacheEntries:[{'revision':'5df28436444beef2d99fc7f9b548f465','url':'/_next/static/H_uIQ1fOevaOJbnuN1cyz/_buildManifest.js'},{'revision':'b6652df95db52feb4daf4eca35380933','url':'/_next/static/H_uIQ1fOevaOJbnuN1cyz/_ssgManifest.js'},{'revision':null,'url':'/_next/static/chunks/1958-a1cd681eb2c1a83e.js'},{'revision':null,'url':'/_next/static/chunks/4bd1b696-c2f6e0877b6c10aa.js'},{'revision':null,'url':'/_next/static/chunks/5838-7ac6ecc648315323.js'},{'revision':null,'url':'/_next/static/chunks/6810-8b074082a0b51859.js'},{'revision':null,'url':'/_next/static/chunks/7938-3aca95fbb5e36779.js'},{'revision':null,'url':'/_next/static/chunks/8500-3953cc33eeceb44e.js'},{'revision':null,'url':'/_next/static/chunks/9da6db1e-54d62c4d2564a0ac.js'},{'revision':null,'url':'/_next/static/chunks/app/_global-error/page-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/_not-found/page-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/checkout/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/props/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/%5Bid%5D/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/games/tonight/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/intelligence/feed/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/accuracy/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/ledger/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/odds/soccer/%5Bleague%5D/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/add-leg/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/parlay/grade/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/players/search/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/live/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/most-parlayed/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/props/top-graded/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/scan/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/parlays-graded/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/stats/public/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/profile/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/recent-scans/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/user/scans/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/waitlist/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/api/webhook/nexapay/route-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/auth/callback/page-f6253334ccab6a26.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/%5Bslug%5D/page-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/blog/page-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/dashboard/page-107967f64e4a489c.js'},{'revision':null,'url':'/_next/static/chunks/app/forgot-password/page-012a02e7c1c1bf4c.js'},{'revision':null,'url':'/_next/static/chunks/app/game/%5Bid%5D/page-2c1eb07021c4e596.js'},{'revision':null,'url':'/_next/static/chunks/app/intelligence/page-67a1ff5cb5db4b20.js'},{'revision':null,'url':'/_next/static/chunks/app/layout-3b07af6d04b4581b.js'},{'revision':null,'url':'/_next/static/chunks/app/ledger/page-b2f371ae0e2dc445.js'},{'revision':null,'url':'/_next/static/chunks/app/login/page-e0e44e4f9dfb8d77.js'},{'revision':null,'url':'/_next/static/chunks/app/marketplace/page-ce0df41afd789a48.js'},{'revision':null,'url':'/_next/static/chunks/app/not-found-3d8359a06d3506dc.js'},{'revision':null,'url':'/_next/static/chunks/app/page-38a2bfff1f1f1e74.js'},{'revision':null,'url':'/_next/static/chunks/app/privacy/page-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/profile/page-589cb3a364727c3b.js'},{'revision':null,'url':'/_next/static/chunks/app/responsible-gambling/page-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/scan/page-ee1e7545074ffd2a.js'},{'revision':null,'url':'/_next/static/chunks/app/settings/security/page-6728e10517c834af.js'},{'revision':null,'url':'/_next/static/chunks/app/signup/page-06c72711414c663d.js'},{'revision':null,'url':'/_next/static/chunks/app/soccer/page-17f39664cea5f0ca.js'},{'revision':null,'url':'/_next/static/chunks/app/terms/page-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/app/tracker/page-c75c1f66c42eac58.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/cancel/page-3d8359a06d3506dc.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/desk/page-416ebb86e698df18.js'},{'revision':null,'url':'/_next/static/chunks/app/upgrade/success/page-3057bec4679f1ad3.js'},{'revision':null,'url':'/_next/static/chunks/app/verify/page-b5ca90220207b0ae.js'},{'revision':null,'url':'/_next/static/chunks/app/welcome/page-ff77b94f609b0d52.js'},{'revision':null,'url':'/_next/static/chunks/framework-29591c88a1db84ab.js'},{'revision':null,'url':'/_next/static/chunks/main-ad5ed0494576592d.js'},{'revision':null,'url':'/_next/static/chunks/main-app-f54c179578b140aa.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/app-error-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/forbidden-17ca8364c0815cb4.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/global-error-d5beecc31181c673.js'},{'revision':null,'url':'/_next/static/chunks/next/dist/client/components/builtin/unauthorized-17ca8364c0815cb4.js'},{'revision':'846118c33b2c0e922d7b3a7676f81f6f','url':'/_next/static/chunks/polyfills-42372ed130431b0a.js'},{'revision':null,'url':'/_next/static/chunks/webpack-9660626b6ab2c75c.js'},{'revision':null,'url':'/_next/static/css/9a23f77e58f3bd56.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':'27007d181514e7fe4213035736a8300e','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("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:n="/"}=t;e.waitUntil(self.registration.showNotification(a,{body:s,icon:r,badge:"/icons/icon-192.png",data:{url:n}}))}),self.addEventListener("notificationclick",e=>{e.notification.close();let t=e.notification.data?.url??"/";e.waitUntil(self.clients.matchAll({type:"window",includeUncontrolled:!0}).then(e=>{let a=e.find(e=>e.url.endsWith(t));return a?a.focus():self.clients.openWindow(t)}))})})(); \ No newline at end of file diff --git a/web/src/app/api/checkout/route.ts b/web/src/app/api/checkout/route.ts index d239069..622b057 100644 --- a/web/src/app/api/checkout/route.ts +++ b/web/src/app/api/checkout/route.ts @@ -1,73 +1,100 @@ import { NextRequest, NextResponse } from 'next/server'; import { getUserFromRequest, jsonError } from '@/lib/auth-helpers'; -import { createPaymentLink, TIER_PRICING, type NexaPayTier } from '@/services/nexapay'; -import { getServiceRoleSupabase } from '@/lib/supabase'; export const dynamic = 'force-dynamic'; -const VALID_TIERS = new Set(['analyst', 'desk']); - -async function resolveTier(req: NextRequest): Promise { - const url = new URL(req.url); - const queryTier = url.searchParams.get('tier'); - if (queryTier && VALID_TIERS.has(queryTier as NexaPayTier)) return queryTier as NexaPayTier; - if (req.method === 'POST') { - try { - const body = (await req.json().catch(() => ({}))) as { tier?: string }; - if (body.tier && VALID_TIERS.has(body.tier as NexaPayTier)) return body.tier as NexaPayTier; - } catch { - /* fall through */ - } - } - return null; -} - -export async function GET(req: NextRequest) { - return handle(req); -} - -export async function POST(req: NextRequest) { - return handle(req); -} +const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000'; +const VALID_TIERS = new Set(['analyst', 'desk']); +/** + * Checkout proxy — Next.js → Express → Stripe. + * + * Session 8 cutover: previously this route created NexaPay payment + * links; now it forwards to the Express `/api/stripe/checkout` route + * (Session 3.4 + 7i) which creates a Stripe Checkout Session + * server-side. The browser never sees `sk_test_*` / `sk_live_*` — + * only the resulting `https://checkout.stripe.com/...` redirect URL. + * + * Response shape — preserves the existing `{ url }` field so older + * Pricing CTA code that read `.url` keeps working. Express returns + * `{ checkout_url, session_id }`; we rename and forward both so + * either field name resolves on the client. + */ async function handle(req: NextRequest) { const user = await getUserFromRequest(req); if (!user) return jsonError(401, 'Log in to upgrade.'); - const tier = await resolveTier(req); - if (!tier) return jsonError(400, 'Pick a valid tier (analyst or desk).'); - - // Founder pricing eligibility — first 100 paid users overall - let founderEligible = false; - const sb = getServiceRoleSupabase(); - if (sb) { - const { count } = await sb - .from('user_profiles') - .select('id', { count: 'exact', head: true }) - .eq('founder_pricing', true); - founderEligible = (count ?? 0) < 100; + // Tier resolution — query string for GET (button hrefs), body for POST. + let tier: string | null = null; + let founderCode: string | undefined; + const url = new URL(req.url); + const queryTier = url.searchParams.get('tier'); + if (queryTier) tier = queryTier; + if (req.method === 'POST') { + try { + const body = (await req.json().catch(() => ({}))) as { tier?: string; founder_code?: string }; + if (body.tier) tier = body.tier; + if (body.founder_code) founderCode = body.founder_code; + } catch { + /* tier may still be on the query string */ + } + } + if (!tier || !VALID_TIERS.has(tier)) { + return jsonError(400, 'Pick a valid tier (analyst or desk).'); } - const pricing = TIER_PRICING[tier]; - const amount = founderEligible ? pricing.founder : pricing.regular; + // Forward to Express. The bearer token from the browser is the same + // one Express's requireAuth verifies — no token rewriting on this hop. + const authHeader = req.headers.get('authorization'); + if (!authHeader) return jsonError(401, 'Log in to upgrade.'); try { - const link = await createPaymentLink({ - userId: user.id, - tier, - amount, - description: `${pricing.label}${founderEligible ? ' (Founder)' : ''}`, - founderPricing: founderEligible, + const upstream = await fetch(`${BACKEND_URL}/api/stripe/checkout`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: authHeader, + }, + body: JSON.stringify({ tier, ...(founderCode ? { founder_code: founderCode } : {}) }), }); - // For GET (used by Pricing CTA links), redirect directly. - if (req.method === 'GET') { - return NextResponse.redirect(link.url, { status: 303 }); + const data = (await upstream.json().catch(() => ({}))) as { + checkout_url?: string; + session_id?: string; + error?: string; + }; + + if (!upstream.ok) { + return NextResponse.json( + { error: data.error || 'Checkout creation failed. Try again in a moment.' }, + { status: upstream.status }, + ); } - return NextResponse.json({ url: link.url, expires_at: link.expires_at, founder_pricing: founderEligible }); - } catch (err) { - console.error('[checkout] NexaPay link failed', err); + const checkoutUrl = data.checkout_url; + if (!checkoutUrl) { + // Defensive: Express returned 200 with no URL — should never happen, + // but if it does we don't want to silently redirect to undefined. + return jsonError(502, 'Checkout creation incomplete. Try again.'); + } + + // GET requests (used by legacy hrefs) redirect directly so a + // plain link click flows to Stripe without JS. + if (req.method === 'GET') { + return NextResponse.redirect(checkoutUrl, { status: 303 }); + } + + // POST returns JSON so the new Pricing onClick handler can navigate + // explicitly (gives us a place to show loading state first). + return NextResponse.json({ + url: checkoutUrl, + checkout_url: checkoutUrl, + session_id: data.session_id, + }); + } catch { return jsonError(502, 'Payment processor is unreachable. Try again in a moment.'); } } + +export async function GET(req: NextRequest) { return handle(req); } +export async function POST(req: NextRequest) { return handle(req); } diff --git a/web/src/app/api/odds/soccer/[league]/route.ts b/web/src/app/api/odds/soccer/[league]/route.ts new file mode 100644 index 0000000..0cbf386 --- /dev/null +++ b/web/src/app/api/odds/soccer/[league]/route.ts @@ -0,0 +1,44 @@ +import { NextRequest, NextResponse } from 'next/server'; + +export const dynamic = 'force-dynamic'; + +const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000'; + +// Frozen at the same set Express validates against +// (`src/services/oddsService.js SOCCER_SPORT_KEYS`). Duplicated here so +// a typo'd league bounces at the Next layer without burning a backend +// round-trip. +const VALID_LEAGUES = new Set([ + 'wc', 'epl', 'laliga', 'bundesliga', 'seriea', + 'ligue1', 'ucl', 'mls', 'ligamx', +]); + +export async function GET(req: NextRequest, { params }: { params: Promise<{ league: string }> }) { + const { league } = await params; + const leagueLc = String(league || '').toLowerCase(); + if (!VALID_LEAGUES.has(leagueLc)) { + return NextResponse.json( + { error: `Unknown soccer league. Valid: ${[...VALID_LEAGUES].join(', ')}.` }, + { status: 400 }, + ); + } + + // Pass the original query string through (filters: book, stat_type). + const qs = req.nextUrl.search; + try { + const upstream = await fetch(`${BACKEND_URL}/api/odds/soccer/${leagueLc}${qs}`, { + method: 'GET', + headers: { Accept: 'application/json' }, + }); + const data = await upstream.json().catch(() => ({})); + if (!upstream.ok) { + return NextResponse.json(data, { status: upstream.status }); + } + return NextResponse.json(data); + } catch { + return NextResponse.json( + { error: 'Odds service is unreachable. Try again in a moment.' }, + { status: 502 }, + ); + } +} diff --git a/web/src/app/api/scan/route.ts b/web/src/app/api/scan/route.ts index 4545282..27f5626 100644 --- a/web/src/app/api/scan/route.ts +++ b/web/src/app/api/scan/route.ts @@ -9,18 +9,22 @@ const monthKey = () => new Date().toISOString().slice(0, 7) + '-01'; const isSameMonth = (date: string | null | undefined) => !!date && date.slice(0, 7) === new Date().toISOString().slice(0, 7); -const VALID_SPORTS = new Set(['NBA', 'MLB', 'WNBA']); +const VALID_SPORTS = new Set(['NBA', 'MLB', 'WNBA', 'Soccer']); const VALID_DIRECTIONS = new Set(['over', 'under']); const VALID_NBA_STATS = new Set(['points', 'rebounds', 'assists', 'threes', 'blocks', 'steals', 'pra', 'turnovers']); const VALID_MLB_STATS = new Set([ 'strikeouts', 'hits_allowed', 'earned_runs', 'innings_pitched', 'walks_allowed', 'hits', 'total_bases', 'rbi', 'runs', 'stolen_bases', 'home_runs', 'walks', 'singles', 'doubles', ]); +const VALID_SOCCER_STATS = new Set([ + 'goals', 'assists', 'shots_on_target', 'shots', 'tackles', + 'cards', 'corners', 'saves', 'goals_conceded', 'passes', 'clean_sheet', +]); export const dynamic = 'force-dynamic'; interface ScanBody { - sport: 'NBA' | 'MLB' | 'WNBA'; + sport: 'NBA' | 'MLB' | 'WNBA' | 'Soccer'; player: string; stat: string; line: number; @@ -45,7 +49,10 @@ export async function POST(req: NextRequest) { return jsonError(400, 'Line must be a number between 0 and 500.'); } - const validStats = body.sport === 'MLB' ? VALID_MLB_STATS : VALID_NBA_STATS; + const validStats = + body.sport === 'MLB' ? VALID_MLB_STATS : + body.sport === 'Soccer' ? VALID_SOCCER_STATS : + VALID_NBA_STATS; if (!validStats.has(body.stat)) { return jsonError(400, `Stat "${body.stat}" not supported for ${body.sport}.`); } diff --git a/web/src/app/soccer/page.tsx b/web/src/app/soccer/page.tsx new file mode 100644 index 0000000..81a4b48 --- /dev/null +++ b/web/src/app/soccer/page.tsx @@ -0,0 +1,414 @@ +'use client'; + +import { useCallback, useEffect, useState } from 'react'; +import { useRouter } from 'next/navigation'; +import SportSelector, { SoccerLeague, SportSelection } from '@/components/SportSelector'; +import SoccerGradeResult, { SoccerGradeResultProps } from '@/components/SoccerGradeResult'; +import { useAuth } from '@/contexts/AuthContext'; + +/** + * /soccer — live soccer odds feed. + * + * Shows match cards for the selected league (defaults to World Cup + * 2026). Each match expands to reveal player props grouped by stat + * type. Clicking a prop hands it off to /scan for grading. + * + * Data path: this page → /api/odds/soccer/:league → Express + * /api/odds/soccer/:league → odds-api. The Express route falls back + * to cache when the API quota is low; the response carries `source: + * 'cache' | 'live'` so we can tag the freshness. + */ + +interface NormalizedProp { + player: string; + stat_type: string; + line: number; + direction: 'over' | 'under'; + book: string; + odds: number; + game_time?: string; + home_team?: string; + away_team?: string; + fetched_at?: string; +} + +interface GroupedProp { + player: string; + stat_type: string; + line: number; + game_time?: string; + home_team?: string; + away_team?: string; + // best line per direction across books + over?: { book: string; odds: number }; + under?: { book: string; odds: number }; +} + +interface OddsResponse { + sport: string; + updated_at?: string; + source?: string; + quota_remaining?: number; + props: GroupedProp[]; + message?: string; + error?: string; +} + +// Group a flat props array by (player, stat_type, line) so each row +// represents a SINGLE prop with both directions next to each other. +// The Express response already does some grouping but ships per-direction +// rows — collapse them. +function groupProps(props: GroupedProp[]): GroupedProp[] { + return props || []; +} + +// Group props under their match for the card layout. +function groupByMatch(props: GroupedProp[]) { + const matches = new Map }>(); + for (const p of props) { + const home = p.home_team || '?'; + const away = p.away_team || '?'; + const key = `${home}__${away}__${p.game_time || ''}`; + if (!matches.has(key)) { + matches.set(key, { home, away, time: p.game_time, propsByStatType: new Map() }); + } + const m = matches.get(key)!; + const list = m.propsByStatType.get(p.stat_type) || []; + list.push(p); + m.propsByStatType.set(p.stat_type, list); + } + return Array.from(matches.values()); +} + +const STAT_LABELS: Record = { + goals: 'Anytime / Total Goals', + shots_on_target: 'Shots on Target', + shots: 'Total Shots', + tackles: 'Tackles', + cards: 'Cards', + corners: 'Corners', + saves: 'Saves', + goals_conceded: 'Goals Conceded', + passes: 'Passes', + clean_sheet: 'Clean Sheet', + assists: 'Assists', +}; + +function formatTime(iso?: string) { + if (!iso) return ''; + try { + const d = new Date(iso); + return d.toLocaleString(undefined, { + weekday: 'short', hour: 'numeric', minute: '2-digit', + }); + } catch { + return iso; + } +} + +export default function SoccerOddsPage() { + const router = useRouter(); + const { session } = useAuth(); + const [selection, setSelection] = useState({ sport: 'Soccer', league: 'wc' }); + const [data, setData] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [expanded, setExpanded] = useState>(new Set()); + + const [scanning, setScanning] = useState(false); + const [scanResult, setScanResult] = useState(null); + const [scanError, setScanError] = useState(null); + + const league: SoccerLeague = selection.league || 'wc'; + + // Redirect non-Soccer sport selections back to /scan — that page + // owns NBA/MLB/WNBA. Soccer is the only one this page serves. + useEffect(() => { + if (selection.sport !== 'Soccer') { + router.push('/scan'); + } + }, [selection.sport, router]); + + async function gradeProp(player: string, stat_type: string, lineVal: number) { + setScanError(null); + setScanResult(null); + setScanning(true); + try { + const res = await fetch('/api/scan', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + ...(session?.access_token ? { Authorization: `Bearer ${session.access_token}` } : {}), + }, + body: JSON.stringify({ + sport: 'Soccer', + player, + stat: stat_type, + line: lineVal, + direction: 'over', + book: 'draftkings', + }), + }); + const body = (await res.json().catch(() => ({}))) as Record & { error?: string }; + if (!res.ok) { + setScanError(body.error || 'The engine hit a wall. Try that read again.'); + setScanning(false); + return; + } + const result: SoccerGradeResultProps = { + player, + stat_type, + line: lineVal, + direction: 'over', + league, + grade: String(body.grade || 'C'), + confidence: typeof body.confidence === 'number' ? body.confidence : undefined, + edge_pct: typeof body.edge_pct === 'number' ? body.edge_pct : undefined, + reasoning: (body.reasoning as SoccerGradeResultProps['reasoning']) || undefined, + kill_conditions_triggered: (body.kill_conditions_triggered as SoccerGradeResultProps['kill_conditions_triggered']) || [], + tier_gated: !!body.tier_gated, + upgrade_hint: typeof body.upgrade_hint === 'string' ? body.upgrade_hint : undefined, + onUpgradeClick: () => router.push('/#pricing'), + onClose: () => setScanResult(null), + }; + setScanResult(result); + } catch { + setScanError('Network error. Try again.'); + } finally { + setScanning(false); + } + } + + const fetchOdds = useCallback(async () => { + setLoading(true); + setError(null); + try { + const res = await fetch(`/api/odds/soccer/${league}`, { cache: 'no-store' }); + const body = (await res.json().catch(() => ({}))) as OddsResponse; + if (!res.ok) { + setError(body.error || 'Couldn’t load odds. Try again.'); + setData(null); + } else { + setData(body); + } + } catch { + setError('Network error. Try again.'); + setData(null); + } finally { + setLoading(false); + } + }, [league]); + + useEffect(() => { + fetchOdds(); + }, [fetchOdds]); + + const matches = data ? groupByMatch(groupProps(data.props)) : []; + + return ( +
+
+
+

+ Soccer odds +

+

+ Live odds across our launch leagues. Click any prop to grade it through the VYNDR engine. +

+
+ +
+ setSelection(sel)} + /> +
+ + {data?.source && ( +

+ {data.updated_at ? `Updated ${formatTime(data.updated_at)} · ` : ''} + source: {data.source} + {typeof data.quota_remaining === 'number' ? ` · quota: ${data.quota_remaining}` : ''} +

+ )} + + {loading && ( +
Loading odds…
+ )} + + {error && ( +
+ {error} +
+ )} + + {scanError && ( +
+ {scanError} +
+ )} + + {scanResult && ( + + )} + + {!loading && !error && matches.length === 0 && ( +
+ No live matches with props in this league right now. + {league !== 'wc' && ( +

+ Off-season or between matchdays — World Cup props are running through July 19, 2026. +

+ )} +
+ )} + +
+ {matches.map((m, idx) => { + const matchKey = `${m.home}-${m.away}-${idx}`; + const isOpen = expanded.has(matchKey); + return ( +
+ + + {isOpen && ( +
+ {Array.from(m.propsByStatType.entries()).map(([statType, list]) => ( +
+

+ {STAT_LABELS[statType] || statType} +

+
    + {list.slice(0, 8).map((p, j) => ( +
  • + {p.player} + + {p.line.toFixed(1)} + + +
  • + ))} +
+
+ ))} +
+ )} +
+ ); + })} +
+
+
+ ); +} diff --git a/web/src/app/upgrade/cancel/page.tsx b/web/src/app/upgrade/cancel/page.tsx new file mode 100644 index 0000000..5c5536c --- /dev/null +++ b/web/src/app/upgrade/cancel/page.tsx @@ -0,0 +1,39 @@ +import Link from 'next/link'; + +/** + * Stripe cancel landing — Stripe sends users here when they bail out + * of checkout. We don't gate, judge, or guilt; just acknowledge and + * point them back to pricing. + */ +export default function UpgradeCancelPage() { + return ( +
+
+

+ Checkout cancelled. +

+

+ Your account is unchanged. No card was charged. +

+
+ + Back to pricing + + + Keep using the free tier + +
+
+
+ ); +} diff --git a/web/src/app/upgrade/success/page.tsx b/web/src/app/upgrade/success/page.tsx new file mode 100644 index 0000000..fea07db --- /dev/null +++ b/web/src/app/upgrade/success/page.tsx @@ -0,0 +1,106 @@ +'use client'; + +import { Suspense, useEffect } from 'react'; +import Link from 'next/link'; +import { useSearchParams } from 'next/navigation'; +import { useAuth } from '@/contexts/AuthContext'; + +/** + * Stripe checkout success landing. + * + * Stripe redirects to /upgrade/success?session_id={CHECKOUT_SESSION_ID} + * after a completed checkout. Webhook events (handled server-side in + * `src/services/stripeService.handleWebhookEvent`) write the user's + * new tier into Supabase — there's nothing for the client to do here + * besides confirm the redirect and refresh the auth context so the + * new tier shows up on subsequent reads. + * + * We deliberately do NOT verify the session against Stripe from the + * client (no secret key on the browser). The webhook is the source of + * truth; this page just acknowledges the user landed. + */ +function SuccessInner() { + const search = useSearchParams(); + const sessionId = search.get('session_id'); + const { refresh, profile } = useAuth(); + + useEffect(() => { + // Force a profile re-read so the new tier flips in the UI without + // requiring a manual sign-out/in. + refresh(); + }, [refresh]); + + const tierLabel = profile?.tier === 'desk' ? 'Desk' : profile?.tier === 'analyst' ? 'Analyst' : ''; + + return ( +
+
+
+ Founder Pricing Locked +
+ +

+ Welcome to VYNDR{tierLabel ? ` ${tierLabel}` : ''}. +

+ +

+ Your beta pricing is locked for as long as you stay subscribed. +

+

+ Cancel anytime in your profile. +

+ + {sessionId && ( +

+ Session: {sessionId} +

+ )} + +
+ + Start scanning + + + View account + +
+
+
+ ); +} + +export default function UpgradeSuccessPage() { + return ( + Loading…}> + + + ); +} diff --git a/web/src/components/Nav.tsx b/web/src/components/Nav.tsx index 8ed5fc1..3681c70 100644 --- a/web/src/components/Nav.tsx +++ b/web/src/components/Nav.tsx @@ -47,10 +47,33 @@ export default function Nav() { >
+ {/* Session 8 — beta tag. Tiny, glitch-styled, sits next to + the wordmark so it reads as part of the brand rather than + a banner. Renders on every page that mounts Nav. */} + + BETA +
diff --git a/web/src/components/Pricing.tsx b/web/src/components/Pricing.tsx index 1331f13..37a82d8 100644 --- a/web/src/components/Pricing.tsx +++ b/web/src/components/Pricing.tsx @@ -1,6 +1,26 @@ 'use client'; -const TIERS = [ +import { useState } from 'react'; +import { useRouter } from 'next/navigation'; +import { useAuth } from '@/contexts/AuthContext'; + +type TierId = 'free' | 'analyst' | 'desk'; + +interface TierConfig { + id: TierId; + name: string; + price: string; + originalPrice?: string; + cadence: string; + badge?: string; + headline: string; + cta: string; + features: string[]; + locked: string[]; + highlight: boolean; +} + +const TIERS: TierConfig[] = [ { id: 'free', name: 'Free', @@ -8,7 +28,6 @@ const TIERS = [ cadence: '/mo', headline: 'Try the model. No card required.', cta: 'Start Free', - ctaHref: '/signup', features: [ '5 reads per month', 'Grade letter + projection', @@ -31,7 +50,6 @@ const TIERS = [ badge: 'Founder Access', headline: 'The full intelligence layer.', cta: 'Lock Founder Price', - ctaHref: '/api/checkout?tier=analyst', features: [ 'Unlimited reads', 'Full factor analysis (40+ signals)', @@ -54,7 +72,6 @@ const TIERS = [ cadence: '/mo', headline: 'Everything. The professional setup.', cta: 'Go Desk', - ctaHref: '/api/checkout?tier=desk', features: [ 'Everything in Analyst', 'Alt line ladder + edge ranking', @@ -62,7 +79,6 @@ const TIERS = [ 'Real-time intelligence feed', 'Parlay correlation analysis (phi)', 'Consensus vs model comparison', - 'API access (coming Q3)', ], locked: [], highlight: false, @@ -70,6 +86,51 @@ const TIERS = [ ]; export default function Pricing() { + const router = useRouter(); + const { session, loading: authLoading } = useAuth(); + const [pending, setPending] = useState(null); + const [error, setError] = useState(null); + + async function startCheckout(tier: TierId) { + setError(null); + + // Free tier short-circuits — no checkout, just signup. + if (tier === 'free') { + router.push('/signup'); + return; + } + + // Anonymous → bounce to signup with a returnTo back to /#pricing. + if (!session) { + router.push('/signup?return=/%23pricing'); + return; + } + + setPending(tier); + try { + const res = await fetch('/api/checkout', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${session.access_token}`, + }, + body: JSON.stringify({ tier }), + }); + const data = (await res.json().catch(() => ({}))) as { url?: string; error?: string }; + if (!res.ok || !data.url) { + setError(data.error || 'Checkout creation failed. Try again in a moment.'); + setPending(null); + return; + } + // Hand off to Stripe. The success_url returns the user to + // /upgrade/success?session_id=… — no further client work needed. + window.location.assign(data.url); + } catch { + setError('Network error. Try again.'); + setPending(null); + } + } + return (

- First 100 users lock $14.99/mo for life. This price dies at user 101. + First 100 users lock $14.99/mo for life. Beta pricing — this price dies at user 101.

+ {error && ( +
+ {error} +
+ )} +
- {TIERS.map((tier, i) => ( -
- {tier.badge && ( -
{ + const isPending = pending === tier.id; + const isDisabled = authLoading || (pending !== null && !isPending); + return ( +
+ {tier.badge && ( +
+ {tier.badge} +
+ )} +

+ {tier.name} +

+
+ + {tier.price} + + {tier.cadence} + {tier.originalPrice && ( + + {tier.originalPrice} + + )} +
+

+ {tier.headline} +

+ +
- )} -

- {tier.name} -

-
- - {tier.price} - - {tier.cadence} - {tier.originalPrice && ( - - {tier.originalPrice} - - )} -
-

- {tier.headline} -

+ {isPending ? 'Redirecting to Stripe…' : tier.cta} + - - {tier.cta} - - -
    - {tier.features.map((f) => ( -
  • - + - {f} -
  • - ))} - {tier.locked.map((f) => ( -
  • - - {f} -
  • - ))} -
-
- ))} +
    + {tier.features.map((f) => ( +
  • + + + {f} +
  • + ))} + {tier.locked.map((f) => ( +
  • + + {f} +
  • + ))} +
+ + ); + })}

- Cancel anytime. No contracts. Card or Apple Pay or Google Pay — payments processed by NexaPay. + Cancel anytime. No contracts. Card / Apple Pay / Google Pay — payments processed by Stripe (test mode while we onboard founders).

diff --git a/web/src/components/SoccerGradeResult.tsx b/web/src/components/SoccerGradeResult.tsx new file mode 100644 index 0000000..68156ee --- /dev/null +++ b/web/src/components/SoccerGradeResult.tsx @@ -0,0 +1,350 @@ +'use client'; + +import { useMemo } from 'react'; + +/** + * Soccer result card — renders an analyze/prop response with + * soccer-specific visual treatment. We can't surface raw feature + * values (the backend response carries only `reasoning.summary` + + * `kill_conditions_triggered` per the engine1 → legacy adapter), so + * we parse the summary for known soccer-signal phrases and surface + * each as a colored chip above the prose. + * + * Free-tier responses already arrive gated (the Session 7h + * `applyTierGating` redacts `reasoning` and `kill_conditions`); we + * just need to detect the `tier_gated` / `locked` markers and show + * an upgrade CTA over the blurred content. + */ + +interface KillCondition { + code: string; + reason: string; + locked?: boolean; +} + +interface Reasoning { + summary?: string; + steps?: unknown; + locked?: boolean; +} + +export interface SoccerGradeResultProps { + player: string; + stat_type: string; + line: number; + direction: 'over' | 'under'; + league: string; + grade: string; + confidence?: number; + edge_pct?: number; + reasoning?: Reasoning; + kill_conditions_triggered?: KillCondition[]; + tier_gated?: boolean; + upgrade_hint?: string; + onUpgradeClick?: () => void; + onClose?: () => void; +} + +type SignalTone = 'positive' | 'caution' | 'warning' | 'neutral'; + +interface ParsedSignal { + icon: string; + label: string; + detail: string; + tone: SignalTone; +} + +const SIGNAL_TONE_STYLE: Record = { + positive: { color: 'var(--grade-a)', bg: 'rgba(0,200,150,0.08)', border: 'rgba(0,200,150,0.40)' }, + caution: { color: 'var(--grade-c, #FFB347)', bg: 'rgba(255,179,71,0.08)', border: 'rgba(255,179,71,0.40)' }, + warning: { color: 'var(--grade-d, #ff5a5a)', bg: 'rgba(255,90,90,0.08)', border: 'rgba(255,90,90,0.40)' }, + neutral: { color: 'var(--text-secondary)', bg: 'transparent', border: 'var(--border)' }, +}; + +// Pattern-match the concrete sentences `buildSoccerReasoningLines` +// emits in src/services/intelligence/analyzeViaEngine1.js. Order +// matters — earlier patterns win when multiple match the same line. +const SIGNAL_PATTERNS: Array<(line: string) => ParsedSignal | null> = [ + (line) => { + const m = line.match(/scores ([\d.]+) goals per 90 minutes/i); + if (m) return { icon: '⚽', label: 'Goals / 90', detail: `${m[1]}`, tone: 'positive' }; + return null; + }, + (line) => { + const m = line.match(/Expected goals \(xG\): ([\d.]+) per 90 — (.+)/i); + if (m) { + const trend = m[2].toLowerCase(); + const tone: SignalTone = trend.includes('regression') ? 'caution' + : trend.includes('breakout') ? 'positive' : 'neutral'; + return { icon: '📊', label: 'xG / 90', detail: `${m[1]} — ${m[2]}`, tone }; + } + return null; + }, + (line) => { + if (/Designated penalty taker/i.test(line)) { + return { icon: '🎯', label: 'Penalty Taker', detail: '+0.15 goals/90 boost', tone: 'positive' }; + } + return null; + }, + (line) => { + if (/Direct free-kick specialist/i.test(line)) { + return { icon: '🏹', label: 'Free-Kick Taker', detail: 'shot/goal probability boost', tone: 'positive' }; + } + return null; + }, + (line) => { + if (/corner taker/i.test(line)) { + return { icon: '⛳', label: 'Corner Taker', detail: 'assist probability boost', tone: 'positive' }; + } + return null; + }, + (line) => { + const m = line.match(/Match at ([\d,]+)ft altitude\.\s*(.+)/i); + if (m) { + const isAcclimated = /acclimated host/i.test(m[2]); + return { + icon: '🏔️', + label: 'Altitude', + detail: `${m[1]}ft — ${isAcclimated ? 'host acclimated' : 'visitor risk'}`, + tone: isAcclimated ? 'neutral' : 'warning', + }; + } + return null; + }, + (line) => { + const m = line.match(/(.+?) averages ([\d.]+) cards per match/i); + if (m) { + const cardsPerGame = parseFloat(m[2]); + const tone: SignalTone = cardsPerGame >= 5 ? 'caution' : 'neutral'; + return { icon: '🟨', label: `Referee: ${m[1].trim()}`, detail: `${m[2]} cards/match`, tone }; + } + return null; + }, + (line) => { + const m = line.match(/Averaging only ([\d.]+) minutes per match/i); + if (m) return { icon: '⏱️', label: 'Minutes', detail: `${m[1]}/90 — under-line discount`, tone: 'caution' }; + return null; + }, + (line) => { + const m = line.match(/(.+?) concedes ([\d.]+) goals per game/i); + if (m) { + const conceded = parseFloat(m[2]); + const tone: SignalTone = conceded <= 0.8 ? 'warning' : conceded >= 1.6 ? 'positive' : 'neutral'; + return { icon: '🛡️', label: `Defense: ${m[1].trim()}`, detail: `${m[2]} GA/match`, tone }; + } + return null; + }, + (line) => { + const m = line.match(/Tournament pedigree: (\d+) career World Cup goals/i); + if (m) return { icon: '🏆', label: 'WC Pedigree', detail: `${m[1]} career goals`, tone: 'positive' }; + return null; + }, +]; + +function parseSignals(summary: string | undefined): ParsedSignal[] { + if (!summary) return []; + const out: ParsedSignal[] = []; + // The buildSoccerReasoningLines output is a single `lines.join(' ')`, + // so split on period+space and trim. Some sentences contain periods + // (e.g. "0.67 goals per 90"), so re-match conservatively. + const fragments = summary.split(/(?<=\.)\s+(?=[A-Z⚽📊🎯🏹⛳🏔️🟨⏱️🛡️🏆])/); + for (const frag of fragments) { + for (const fn of SIGNAL_PATTERNS) { + const sig = fn(frag); + if (sig) { + out.push(sig); + break; + } + } + } + return out; +} + +function gradeColor(grade: string): string { + const g = (grade || '').trim().toUpperCase().charAt(0); + if (g === 'A') return 'var(--grade-a)'; + if (g === 'B') return 'var(--grade-b, #4A9EFF)'; + if (g === 'C') return 'var(--grade-c, #FFB347)'; + return 'var(--grade-d, #ff5a5a)'; +} + +export default function SoccerGradeResult(props: SoccerGradeResultProps) { + const { + player, stat_type, line, direction, league, grade, confidence, edge_pct, + reasoning, kill_conditions_triggered, tier_gated, upgrade_hint, + onUpgradeClick, onClose, + } = props; + + const signals = useMemo(() => parseSignals(reasoning?.summary), [reasoning?.summary]); + const color = gradeColor(grade); + const locked = !!tier_gated || !!reasoning?.locked; + const kills = Array.isArray(kill_conditions_triggered) ? kill_conditions_triggered : []; + + return ( +
+ {onClose && ( + + )} + +
+
+
{player}
+
+ {direction.toUpperCase()} {line.toFixed(1)} {stat_type.replace(/_/g, ' ')} · {league.toUpperCase()} +
+
+
+
+ {grade} +
+ {typeof confidence === 'number' && ( +
+ {confidence.toFixed(0)}% conf + {typeof edge_pct === 'number' && ( + <> · {edge_pct >= 0 ? '+' : ''}{edge_pct.toFixed(1)}% edge + )} +
+ )} +
+
+ + {signals.length > 0 && !locked && ( +
+ {signals.map((sig, idx) => { + const style = SIGNAL_TONE_STYLE[sig.tone]; + return ( +
+ {sig.icon} + + {sig.label} + + {sig.detail} +
+ ); + })} +
+ )} + + {!locked && reasoning?.summary && ( +

+ {reasoning.summary} +

+ )} + + {locked && ( +
+
+ ⚽ Goals/90: 0.67 · 📊 xG: 0.52 — overperforming · 🏔️ altitude 7,349ft · 🟨 ref 4.7 cards/match · 🎯 penalty taker +
+

+ {upgrade_hint || 'Unlock full intelligence — xG regression, altitude, referee, set-piece role.'} +

+ +
+ )} + + {kills.length > 0 && ( +
+

+ Kill conditions ({kills.length}) +

+
    + {kills.map((k, idx) => ( +
  • + + {k.code} + + {k.reason} +
  • + ))} +
+
+ )} +
+ ); +} diff --git a/web/src/components/SportSelector.tsx b/web/src/components/SportSelector.tsx new file mode 100644 index 0000000..42ee4d2 --- /dev/null +++ b/web/src/components/SportSelector.tsx @@ -0,0 +1,190 @@ +'use client'; + +import { useState, useEffect } from 'react'; + +/** + * SportSelector — pill tabs for the four launch verticals. + * + * Soccer reveals a secondary league pill row (WC default for the + * tournament launch; EPL/La Liga/etc available year-round). The + * selected `{ sport, league }` is emitted via `onChange` so the + * parent owns the actual scan/odds state and can refetch on switch. + * + * The component is intentionally pure-UI — no fetches, no auth, no + * persistence. A parent that wants the selection to stick should + * pass `initialSport` / `initialLeague` from URL params or + * localStorage. + */ + +export type Sport = 'NBA' | 'WNBA' | 'MLB' | 'Soccer'; + +// Soccer league codes match the GET /api/odds/soccer/:league path +// segment AND the `SOCCER_LEAGUES` env on the backend. Source of truth +// is `src/services/oddsService.js SOCCER_SPORT_KEYS`. +export type SoccerLeague = + | 'wc' + | 'epl' + | 'laliga' + | 'bundesliga' + | 'seriea' + | 'ligue1' + | 'ucl' + | 'mls' + | 'ligamx'; + +export interface SportSelection { + sport: Sport; + league?: SoccerLeague; +} + +const SPORTS: Array<{ id: Sport; label: string; status?: 'live' | 'beta' }> = [ + { id: 'NBA', label: 'NBA', status: 'live' }, + { id: 'WNBA', label: 'WNBA', status: 'live' }, + { id: 'MLB', label: 'MLB', status: 'live' }, + { id: 'Soccer', label: 'Soccer', status: 'beta' }, +]; + +const SOCCER_LEAGUES: Array<{ id: SoccerLeague; label: string; sub?: string }> = [ + { id: 'wc', label: 'World Cup', sub: '2026' }, + { id: 'epl', label: 'EPL' }, + { id: 'laliga', label: 'La Liga' }, + { id: 'bundesliga', label: 'Bundesliga' }, + { id: 'seriea', label: 'Serie A' }, + { id: 'ligue1', label: 'Ligue 1' }, + { id: 'ucl', label: 'UCL' }, + { id: 'mls', label: 'MLS' }, + { id: 'ligamx', label: 'Liga MX' }, +]; + +interface Props { + initialSport?: Sport; + initialLeague?: SoccerLeague; + onChange?: (selection: SportSelection) => void; +} + +export default function SportSelector({ + initialSport = 'NBA', + initialLeague = 'wc', + onChange, +}: Props) { + const [sport, setSport] = useState(initialSport); + const [league, setLeague] = useState(initialLeague); + + // Emit on every change so parents stay in sync. Effect (not inline + // in setSport) so React batches both pieces of state correctly. + useEffect(() => { + if (onChange) { + onChange(sport === 'Soccer' ? { sport, league } : { sport }); + } + }, [sport, league, onChange]); + + function selectSport(next: Sport) { + setSport(next); + } + + return ( +
+
+ {SPORTS.map((s) => { + const active = sport === s.id; + return ( + + ); + })} +
+ + {sport === 'Soccer' && ( +
+ {SOCCER_LEAGUES.map((l) => { + const active = league === l.id; + return ( + + ); + })} +
+ )} +
+ ); +}