@maestro_io/maestro-web-sdk 3.3.1 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/dist/f8820fca3a2a7957f753167da0884f9d.png +0 -0
  2. package/dist/maestro-web-sdk.esm.js +12 -12
  3. package/dist/maestro-web-sdk.esm.js.map +1 -1
  4. package/dist/maestro-web-sdk.umd.js +12 -12
  5. package/dist/maestro-web-sdk.umd.js.map +1 -1
  6. package/dist/package.json +87 -0
  7. package/dist/src/__mocks__/sentry.d.ts +4 -0
  8. package/dist/src/components/atoms/BaseButton/BaseButton.js +11 -0
  9. package/dist/src/components/atoms/BaseButton/index.js +2 -0
  10. package/dist/src/components/atoms/Image/index.js +34 -0
  11. package/dist/src/components/atoms/Rive/index.js +53 -0
  12. package/dist/src/components/atoms/SvgIcon/BetGeneralIcon.js +9 -0
  13. package/dist/src/components/atoms/SvgIcon/BetsIcon.js +11 -0
  14. package/dist/src/components/atoms/SvgIcon/BetsWarningIcon.js +11 -0
  15. package/dist/src/components/atoms/SvgIcon/CheckmarkIcon.js +6 -0
  16. package/dist/src/components/atoms/SvgIcon/CollapseIcon.js +6 -0
  17. package/dist/src/components/atoms/SvgIcon/ExpandIcon.js +6 -0
  18. package/dist/src/components/atoms/SvgIcon/FantasyIcon.js +15 -0
  19. package/dist/src/components/atoms/SvgIcon/FlameIcon.js +11 -0
  20. package/dist/src/components/atoms/SvgIcon/Icon.js +44 -0
  21. package/dist/src/components/atoms/SvgIcon/KeyPlaysIcon.js +10 -0
  22. package/dist/src/components/atoms/SvgIcon/MobilePhoneIcon.js +11 -0
  23. package/dist/src/components/atoms/SvgIcon/PlayIcon.js +8 -0
  24. package/dist/src/components/atoms/SvgIcon/ShopIcon.js +7 -0
  25. package/dist/src/components/atoms/SvgIcon/StatsIcon.js +12 -0
  26. package/dist/src/components/atoms/SvgIcon/TimesIcon.js +6 -0
  27. package/dist/src/components/atoms/SvgIcon/WarningIcon.js +8 -0
  28. package/dist/src/components/atoms/SvgIcon/index.js +2 -0
  29. package/dist/src/components/core/App/App.js +35 -0
  30. package/dist/src/components/core/App/index.js +2 -0
  31. package/dist/src/components/core/OverlayContainer.js +58 -0
  32. package/dist/src/components/core/PanelManager/PanelManager.js +86 -0
  33. package/dist/src/components/core/PanelManager/index.js +2 -0
  34. package/dist/src/components/core/ScrollableContainer/FocusableItem.js +38 -0
  35. package/dist/src/components/core/ScrollableContainer/ScrollableContainer.js +168 -0
  36. package/dist/src/components/core/ScrollableContainer/index.js +2 -0
  37. package/dist/src/components/molecules/ActionButton/ActionButton.js +10 -0
  38. package/dist/src/components/molecules/ActionButton/index.js +2 -0
  39. package/dist/src/components/molecules/HeadshotImage/HeadshotImage.js +50 -0
  40. package/dist/src/components/molecules/HeadshotImage/index.js +2 -0
  41. package/dist/src/components/molecules/Overlay/Overlay.js +139 -0
  42. package/dist/src/components/molecules/Overlay/index.js +2 -0
  43. package/dist/src/components/molecules/PanelNavButton/PanelNavButton.js +27 -0
  44. package/dist/src/components/molecules/PanelNavButton/index.js +2 -0
  45. package/dist/src/components/molecules/SegmentButton/SegmentButton.js +10 -0
  46. package/dist/src/components/molecules/SegmentButton/index.js +2 -0
  47. package/dist/src/components/molecules/TabLoadError/TabLoadError.js +14 -0
  48. package/dist/src/components/molecules/TabLoadError/index.js +2 -0
  49. package/dist/src/components/molecules/WatchButton/WatchButton.js +15 -0
  50. package/dist/src/components/molecules/WatchButton/index.js +2 -0
  51. package/dist/src/components/organisms/PanelNavigation/PanelNavigation.js +60 -0
  52. package/dist/src/components/organisms/PanelNavigation/index.js +2 -0
  53. package/dist/src/components/organisms/SegmentController/SegmentController.js +76 -0
  54. package/dist/src/components/organisms/SegmentController/index.js +2 -0
  55. package/dist/src/development/MaestroEventDelegate.js +109 -0
  56. package/dist/src/development/TimeSeek.js +218 -0
  57. package/dist/src/development/development.js +33 -0
  58. package/dist/src/external/AxiosNetworkClient.js +110 -0
  59. package/dist/src/external/LocalStorageCacheManager.js +213 -0
  60. package/dist/src/external/ReactRenderer.js +53 -0
  61. package/dist/src/external/mocks/MockExternalNetworkClient.js +187 -0
  62. package/dist/src/external/ports/cacheManager.js +1 -0
  63. package/dist/src/external/ports/networkClient.js +1 -0
  64. package/dist/src/external/ports/renderer.d.ts +1 -2
  65. package/dist/src/external/ports/renderer.js +1 -0
  66. package/dist/src/external/spatial-navigation/__mocks__/withFocusable.d.ts +8 -0
  67. package/dist/src/external/spatial-navigation/__mocks__/withFocusable.js +7 -0
  68. package/dist/src/external/spatial-navigation/index.js +3 -0
  69. package/dist/src/external/spatial-navigation/measureLayout.js +30 -0
  70. package/dist/src/external/spatial-navigation/spatialNavigation.js +876 -0
  71. package/dist/src/external/spatial-navigation/utils.js +6 -0
  72. package/dist/src/external/spatial-navigation/visualDebugger.js +76 -0
  73. package/dist/src/external/spatial-navigation/withFocusable.js +245 -0
  74. package/dist/src/helpers/Observable.js +37 -0
  75. package/dist/src/helpers/strings.js +14 -0
  76. package/dist/src/helpers/url.js +12 -0
  77. package/dist/src/index.d.ts +5 -5
  78. package/dist/src/index.js +165 -0
  79. package/dist/src/interfaces/IMaestroEvent.d.ts +12 -0
  80. package/dist/src/interfaces/IMaestroEvent.js +18 -0
  81. package/dist/src/interfaces/IMaestroEventDelegate.js +1 -0
  82. package/dist/src/interfaces/IMaestroManager.js +1 -0
  83. package/dist/src/interfaces/IUserSettings.js +20 -0
  84. package/dist/src/models/IModel.js +1 -0
  85. package/dist/src/models/IPanel.js +40 -0
  86. package/dist/src/models/ITheme.js +20 -0
  87. package/dist/src/models/IWinningBet.js +1 -0
  88. package/dist/src/modules/bets/interfaces/IBets.js +1 -0
  89. package/dist/src/modules/bets/mocks.js +573 -0
  90. package/dist/src/modules/bets/types/BetsAnalyticsTypes.js +1 -0
  91. package/dist/src/modules/bets/view/BetsView.js +143 -0
  92. package/dist/src/modules/bets/view/HotProps/HotPropsView.js +150 -0
  93. package/dist/src/modules/bets/view/SixPack/SixPackView.js +110 -0
  94. package/dist/src/modules/bets/view/UserBets/BetResult/BetResult.js +6 -0
  95. package/dist/src/modules/bets/view/UserBets/BetsCard/BetsCard.js +149 -0
  96. package/dist/src/modules/bets/view/UserBets/BetsCard/BetsCardEvent.js +34 -0
  97. package/dist/src/modules/bets/view/UserBets/BetsCard/BetsCardFooter.js +18 -0
  98. package/dist/src/modules/bets/view/UserBets/Boost/Boost.js +6 -0
  99. package/dist/src/modules/bets/view/UserBets/OutcomeBadge/OutcomeBadge.js +9 -0
  100. package/dist/src/modules/bets/view/UserBets/Parlay/Parlay.js +13 -0
  101. package/dist/src/modules/bets/view/UserBets/Straight/Straight.js +6 -0
  102. package/dist/src/modules/bets/view/UserBets/Teaser/Teaser.js +13 -0
  103. package/dist/src/modules/bets/view/UserBets/UserBetsView.js +107 -0
  104. package/dist/src/modules/bets/view/components/Bet/Bet.js +32 -0
  105. package/dist/src/modules/bets/view/components/BetPill/BetPill.js +6 -0
  106. package/dist/src/modules/bets/view/components/BetsCard/BetsCard.js +15 -0
  107. package/dist/src/modules/bets/view/components/BetsCard/BetsCardHeader.js +20 -0
  108. package/dist/src/modules/bets/view/components/GamblingDisclaimer/GamblingDisclaimer.js +14 -0
  109. package/dist/src/modules/bets/view/components/LocationWarning/LocationWarning.js +16 -0
  110. package/dist/src/modules/bets/view/components/PromoCodeBanner/PromoCodeBanner.js +78 -0
  111. package/dist/src/modules/bets/view/components/PromoCodeBanner/index.js +1 -0
  112. package/dist/src/modules/bets/view-model/BetsViewModel.js +974 -0
  113. package/dist/src/modules/fantasy/components/ExpandedAthleteList/ExpandedAthletesList.js +107 -0
  114. package/dist/src/modules/fantasy/components/ExpandedAthleteList/index.js +1 -0
  115. package/dist/src/modules/fantasy/components/LeagueCard/LeagueCard.js +20 -0
  116. package/dist/src/modules/fantasy/components/LeagueCard/index.js +2 -0
  117. package/dist/src/modules/fantasy/components/TopPlayerCard/TopPlayerCard.js +29 -0
  118. package/dist/src/modules/fantasy/components/TopPlayerCard/index.js +2 -0
  119. package/dist/src/modules/fantasy/mocks.js +3682 -0
  120. package/dist/src/modules/fantasy/types.js +6 -0
  121. package/dist/src/modules/fantasy/view/ActiveAthletesMarquee/ActiveAthletesMarquee.js +74 -0
  122. package/dist/src/modules/fantasy/view/ActiveAthletesMarquee/index.js +2 -0
  123. package/dist/src/modules/fantasy/view/ErrorBoundary.d.ts +13 -0
  124. package/dist/src/modules/fantasy/view/FantasyItemView.js +74 -0
  125. package/dist/src/modules/fantasy/view/FantasyView.js +133 -0
  126. package/dist/src/modules/fantasy/view/InactiveLeague/DraftDateCountdown.js +95 -0
  127. package/dist/src/modules/fantasy/view/InactiveLeague/InactiveLeague.js +13 -0
  128. package/dist/src/modules/fantasy/view/InactiveLeague/index.js +2 -0
  129. package/dist/src/modules/fantasy/view/LoginView/LoginView.js +27 -0
  130. package/dist/src/modules/fantasy/view/LoginView/index.js +2 -0
  131. package/dist/src/modules/fantasy/view/MatchupPair/DoubleAthleteCard/DoubleAthleteCard.js +25 -0
  132. package/dist/src/modules/fantasy/view/MatchupPair/DoubleAthleteCard/index.js +2 -0
  133. package/dist/src/modules/fantasy/view/MatchupPair/ExpandedDoubleAthleteCards.js +9 -0
  134. package/dist/src/modules/fantasy/view/MatchupPair/MatchupPair.js +118 -0
  135. package/dist/src/modules/fantasy/view/MatchupPair/index.js +2 -0
  136. package/dist/src/modules/fantasy/view/MatchupSingle/ExpandedSingleAthleteCards.js +9 -0
  137. package/dist/src/modules/fantasy/view/MatchupSingle/MatchupSingle.js +108 -0
  138. package/dist/src/modules/fantasy/view/MatchupSingle/SingleAthleteCard/SingleAthleteCard.js +18 -0
  139. package/dist/src/modules/fantasy/view/MatchupSingle/SingleAthleteCard/index.js +2 -0
  140. package/dist/src/modules/fantasy/view/MatchupSingle/index.js +2 -0
  141. package/dist/src/modules/fantasy/view/PromoView/PromoView.js +12 -0
  142. package/dist/src/modules/fantasy/view/PromoView/index.js +2 -0
  143. package/dist/src/modules/fantasy/view/index.js +2 -0
  144. package/dist/src/modules/fantasy/view-model/FantasyViewModel.FantasyPolling.js +132 -0
  145. package/dist/src/modules/fantasy/view-model/FantasyViewModel.LeagueManagerPolling.js +141 -0
  146. package/dist/src/modules/fantasy/view-model/FantasyViewModel.js +534 -0
  147. package/dist/src/modules/key-plays/constants.js +292 -0
  148. package/dist/src/modules/key-plays/interfaces/IKeyPlays.js +14 -0
  149. package/dist/src/modules/key-plays/interfaces/IKeyPlaysResponse.js +1 -0
  150. package/dist/src/modules/key-plays/view/KeyPlayCardScoreTagView.js +16 -0
  151. package/dist/src/modules/key-plays/view/KeyPlayCardView.js +144 -0
  152. package/dist/src/modules/key-plays/view/KeyPlayErrorStateView.js +65 -0
  153. package/dist/src/modules/key-plays/view/KeyPlaysView.js +151 -0
  154. package/dist/src/modules/key-plays/view-model/KeyPlaysViewModel.js +246 -0
  155. package/dist/src/modules/shop/mocks.js +390 -0
  156. package/dist/src/modules/shop/types.js +7 -0
  157. package/dist/src/modules/shop/view/ProductDetailView/ProductDetailView.js +56 -0
  158. package/dist/src/modules/shop/view/ProductDetailView/index.js +2 -0
  159. package/dist/src/modules/shop/view/ShopView.js +182 -0
  160. package/dist/src/modules/shop/view/components/BrowseCard/BrowseCard.js +23 -0
  161. package/dist/src/modules/shop/view/components/BrowseCard/index.js +2 -0
  162. package/dist/src/modules/shop/view/components/ProductSummaryCard/ProductSummaryCard.js +26 -0
  163. package/dist/src/modules/shop/view/components/ProductSummaryCard/index.js +1 -0
  164. package/dist/src/modules/shop/view/components/ShopPromoView/ShopPromoView.js +19 -0
  165. package/dist/src/modules/shop/view/components/ShopPromoView/index.js +1 -0
  166. package/dist/src/modules/shop/view/components/ShopSection/ShopSection.d.ts +1 -0
  167. package/dist/src/modules/shop/view/components/ShopSection/ShopSection.js +61 -0
  168. package/dist/src/modules/shop/view/components/ShopSection/ShopSectionItem.d.ts +18 -0
  169. package/dist/src/modules/shop/view/components/ShopSection/ShopSectionItem.js +22 -0
  170. package/dist/src/modules/shop/view/components/ShopSection/index.js +1 -0
  171. package/dist/src/modules/shop/view/index.js +2 -0
  172. package/dist/src/modules/shop/view-model/ShopViewModel.ShopPolling.js +111 -0
  173. package/dist/src/modules/shop/view-model/ShopViewModel.js +353 -0
  174. package/dist/src/modules/stats/interfaces/IStats.js +1 -0
  175. package/dist/src/modules/stats/mocks.js +746 -0
  176. package/dist/src/modules/stats/utils/driveSummaryUtils.js +48 -0
  177. package/dist/src/modules/stats/utils/renderTeamStatistic.js +16 -0
  178. package/dist/src/modules/stats/utils.js +62 -0
  179. package/dist/src/modules/stats/view/ActiveAthletes/ActiveAthletes.js +98 -0
  180. package/dist/src/modules/stats/view/ActiveAthletes/CollapsedAthletes/CollapsedAthletes.js +27 -0
  181. package/dist/src/modules/stats/view/ActiveAthletes/ExpandedAthletes/ExpandedAthletes.js +89 -0
  182. package/dist/src/modules/stats/view/ActiveAthletes/index.js +2 -0
  183. package/dist/src/modules/stats/view/DriveSummary/DrivePlayCard.js +70 -0
  184. package/dist/src/modules/stats/view/DriveSummary/DriveSummary.js +87 -0
  185. package/dist/src/modules/stats/view/DriveSummary/ExpandedItems/DriveSummaryExpanded.js +129 -0
  186. package/dist/src/modules/stats/view/DriveSummary/Header/DriveSummaryHeader.js +26 -0
  187. package/dist/src/modules/stats/view/DriveSummary/MainStat/MainStat.js +24 -0
  188. package/dist/src/modules/stats/view/DriveSummary/index.js +2 -0
  189. package/dist/src/modules/stats/view/GameLeaders/GameLeaders.js +48 -0
  190. package/dist/src/modules/stats/view/GameLeaders/index.js +2 -0
  191. package/dist/src/modules/stats/view/MatchPredictor/DonutChart/DonutChart.js +55 -0
  192. package/dist/src/modules/stats/view/MatchPredictor/DonutChart/index.js +1 -0
  193. package/dist/src/modules/stats/view/MatchPredictor/MatchPredictorView.js +60 -0
  194. package/dist/src/modules/stats/view/MatchPredictor/index.js +2 -0
  195. package/dist/src/modules/stats/view/Penalties/Penalties.js +6 -0
  196. package/dist/src/modules/stats/view/Penalties/index.js +2 -0
  197. package/dist/src/modules/stats/view/RecentGames/RecentGames.js +23 -0
  198. package/dist/src/modules/stats/view/RecentGames/index.js +2 -0
  199. package/dist/src/modules/stats/view/ScoringSummary/ExpandedScores/ExpandedScores.js +121 -0
  200. package/dist/src/modules/stats/view/ScoringSummary/ExpandedScores/index.js +2 -0
  201. package/dist/src/modules/stats/view/ScoringSummary/ScoreItem/ScoreItem.js +62 -0
  202. package/dist/src/modules/stats/view/ScoringSummary/ScoreItem/index.js +2 -0
  203. package/dist/src/modules/stats/view/ScoringSummary/ScoresSection/ScoresSection.js +23 -0
  204. package/dist/src/modules/stats/view/ScoringSummary/ScoresSection/index.js +2 -0
  205. package/dist/src/modules/stats/view/ScoringSummary/ScoringSummary.js +106 -0
  206. package/dist/src/modules/stats/view/ScoringSummary/index.js +2 -0
  207. package/dist/src/modules/stats/view/StatsItemView.js +92 -0
  208. package/dist/src/modules/stats/view/StatsQRCode/StatsQRCodeView.js +36 -0
  209. package/dist/src/modules/stats/view/StatsQRCode/index.js +1 -0
  210. package/dist/src/modules/stats/view/StatsView.js +137 -0
  211. package/dist/src/modules/stats/view/TeamStats/TeamStatsView.js +43 -0
  212. package/dist/src/modules/stats/view/TeamStats/index.js +1 -0
  213. package/dist/src/modules/stats/view/Teams/StatsCarousel.js +83 -0
  214. package/dist/src/modules/stats/view/Teams/StatsProgressBar.js +19 -0
  215. package/dist/src/modules/stats/view/Teams/Teams.js +27 -0
  216. package/dist/src/modules/stats/view/Teams/index.js +2 -0
  217. package/dist/src/modules/stats/view/WinProbability/WinProbability.js +28 -0
  218. package/dist/src/modules/stats/view/WinProbability/index.js +2 -0
  219. package/dist/src/modules/stats/view/components/AthletesStatistics/AthletesStatistics.js +89 -0
  220. package/dist/src/modules/stats/view/components/AthletesStatistics/StatisticTable.js +12 -0
  221. package/dist/src/modules/stats/view/components/AthletesStatistics/index.js +2 -0
  222. package/dist/src/modules/stats/view/index.js +2 -0
  223. package/dist/src/modules/stats/view-model/StatsViewModel.d.ts +5 -0
  224. package/dist/src/modules/stats/view-model/StatsViewModel.js +989 -0
  225. package/dist/src/sentry.js +31 -0
  226. package/dist/src/services/AnalyticsService/AnalyticsService.d.ts +12 -7
  227. package/dist/src/services/AnalyticsService/AnalyticsService.js +402 -0
  228. package/dist/src/services/AnalyticsService/types.js +1 -0
  229. package/dist/src/services/BetsService.js +122 -0
  230. package/dist/src/services/FantasyService.js +92 -0
  231. package/dist/src/services/GlobalService/GlobalService.d.ts +9 -0
  232. package/dist/src/services/GlobalService/PageService.d.ts +9 -0
  233. package/dist/src/services/GlobalService/index.d.ts +2 -0
  234. package/dist/src/services/GlobalService/mocks.d.ts +2 -0
  235. package/dist/src/services/GlobalService/types.d.ts +11 -0
  236. package/dist/src/services/InsightsService/InsightsPayloadBuilder.d.ts +1 -2
  237. package/dist/src/services/InsightsService/InsightsPayloadBuilder.js +386 -0
  238. package/dist/src/services/InsightsService/InsightsService.js +74 -0
  239. package/dist/src/services/NetworkManager/NetworkManager.js +457 -0
  240. package/dist/src/services/NetworkManager/NetworkManagerFactory.js +101 -0
  241. package/dist/src/services/NetworkManager/errors.js +45 -0
  242. package/dist/src/services/NetworkManager/types.js +10 -0
  243. package/dist/src/services/PageService/PageService.d.ts +9 -0
  244. package/dist/src/services/PageService/PageService.js +39 -0
  245. package/dist/src/services/PageService/index.d.ts +2 -0
  246. package/dist/src/services/PageService/index.js +2 -0
  247. package/dist/src/services/PageService/mocks.d.ts +2 -0
  248. package/dist/src/services/PageService/mocks.js +104 -0
  249. package/dist/src/services/PageService/types.d.ts +76 -0
  250. package/dist/src/services/PageService/types.js +1 -0
  251. package/dist/src/services/ShopService.js +46 -0
  252. package/dist/src/services/StaticService/PageService.d.ts +9 -0
  253. package/dist/src/services/StaticService/StaticService.d.ts +3 -1
  254. package/dist/src/services/StaticService/StaticService.js +59 -0
  255. package/dist/src/services/StaticService/index.js +2 -0
  256. package/dist/src/services/StaticService/mocks.js +104 -0
  257. package/dist/src/services/StaticService/types.js +1 -0
  258. package/dist/src/services/StatsService.d.ts +1 -0
  259. package/dist/src/services/StatsService.js +147 -0
  260. package/dist/src/services/ThemeManager/constants.js +47 -0
  261. package/dist/src/services/UserSettingsManager.js +155 -0
  262. package/dist/src/test-polyfills.js +15 -0
  263. package/dist/src/types/OverlayTypes.js +4 -0
  264. package/dist/src/view-models/MaestroEventViewModel.d.ts +1 -2
  265. package/dist/src/view-models/MaestroEventViewModel.js +307 -0
  266. package/dist/src/view-models/OverlayViewModel.js +222 -0
  267. package/dist/src/view-models/PanelManagerViewModel.js +212 -0
  268. package/dist/src/view-models/ViewModel.js +32 -0
  269. package/package.json +1 -1
@@ -0,0 +1,534 @@
1
+ import { Observable } from '@/helpers/Observable';
2
+ import AnalyticsService from '@/services/AnalyticsService/AnalyticsService';
3
+ import { captureException } from '@/sentry';
4
+ import FantasyService from '@/services/FantasyService';
5
+ import { isLeagueManagerHeadToHeadResponse, isLeagueManagerRotoResponse, } from '../types';
6
+ import FantasyPolling from './FantasyViewModel.FantasyPolling';
7
+ import LeagueManagerPolling from './FantasyViewModel.LeagueManagerPolling';
8
+ import { slugify, stringHashCode } from '@/helpers/strings';
9
+ import { MOCK_FANTASY_RESPONSE } from '../mocks';
10
+ const FANTASY_ERROR_STATE = {
11
+ NONE: 'none',
12
+ TAB_LOAD_FAILURE: 'tabLoadFailure',
13
+ };
14
+ export class FantasyViewModel {
15
+ constructor(eventId, delegate, options = {}) {
16
+ // Observable properties
17
+ Object.defineProperty(this, "fantasyItems", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: new Observable([])
22
+ });
23
+ Object.defineProperty(this, "isDataLoading", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: new Observable(false)
28
+ });
29
+ Object.defineProperty(this, "hasEverSuccessfullyLoaded", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: new Observable(false)
34
+ });
35
+ // Properties
36
+ Object.defineProperty(this, "eventId", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "delegate", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ Object.defineProperty(this, "analyticsService", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "fantasyService", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "fantasyPolling", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ Object.defineProperty(this, "leagueManagerPolling", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ Object.defineProperty(this, "errorState", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: new Observable('none')
77
+ });
78
+ Object.defineProperty(this, "leagueSortOrder", {
79
+ enumerable: true,
80
+ configurable: true,
81
+ writable: true,
82
+ value: new Map()
83
+ });
84
+ Object.defineProperty(this, "itemToLeagueKey", {
85
+ enumerable: true,
86
+ configurable: true,
87
+ writable: true,
88
+ value: new Map()
89
+ });
90
+ Object.defineProperty(this, "useMockData", {
91
+ enumerable: true,
92
+ configurable: true,
93
+ writable: true,
94
+ value: false
95
+ });
96
+ this.useMockData = options.useMockData || false;
97
+ this.eventId = eventId;
98
+ this.delegate = delegate;
99
+ this.analyticsService = new AnalyticsService();
100
+ this.fantasyService = new FantasyService();
101
+ this.fantasyPolling = new FantasyPolling(this.fantasyService);
102
+ this.leagueManagerPolling = new LeagueManagerPolling(this.fantasyService);
103
+ }
104
+ /**
105
+ * Initialize the ViewModel and start data fetching
106
+ */
107
+ async init() {
108
+ // Track panel view on initialization
109
+ this.trackPanelView();
110
+ await this.fetchData();
111
+ }
112
+ async fetchData() {
113
+ const isAuthenticated = await this.delegate.userIsAuthenticated();
114
+ if (!isAuthenticated) {
115
+ this.append({
116
+ id: 'not-logged-in',
117
+ type: 'notLoggedIn',
118
+ });
119
+ return;
120
+ }
121
+ else if (this.fantasyItems.value.find((i) => i.type === 'notLoggedIn')) {
122
+ this.fantasyItems.value = [];
123
+ }
124
+ const swid = (await this.delegate.getUserSWID()) || '';
125
+ const jwt = (await this.delegate.getUserToken()) || '';
126
+ if (this.useMockData) {
127
+ await this.fetchMockData();
128
+ return;
129
+ }
130
+ else {
131
+ await this.fantasyPolling.refresh({
132
+ eventId: this.eventId,
133
+ swid,
134
+ jwt,
135
+ }, this.processFantasy.bind(this));
136
+ }
137
+ }
138
+ onEngage(type) {
139
+ this.analyticsService.panelClick({
140
+ type: 'espnFantasy',
141
+ name: 'fantasy_item_clicked',
142
+ metadata: {
143
+ card: type,
144
+ },
145
+ });
146
+ }
147
+ onAskLogin() {
148
+ this.fantasyItems.value = [];
149
+ this.delegate.onPanelEvent({
150
+ type: 'fantasy:request:login',
151
+ payload: {
152
+ onLoginSuccess: async () => {
153
+ await this.fetchData();
154
+ },
155
+ },
156
+ });
157
+ }
158
+ /**
159
+ * Clean up resources when the ViewModel is no longer needed
160
+ */
161
+ cleanup() {
162
+ this.fantasyPolling.stop();
163
+ this.fantasyPolling.removeLastResponseHash();
164
+ this.leagueManagerPolling.stopAll();
165
+ this.leagueSortOrder.clear();
166
+ this.itemToLeagueKey.clear();
167
+ }
168
+ /**
169
+ * Track panel view event
170
+ */
171
+ async trackPanelView() {
172
+ try {
173
+ await this.analyticsService.panelView('espnFantasy');
174
+ }
175
+ catch (error) {
176
+ captureException(error, {
177
+ context: 'FantasyViewModel.trackPanelView',
178
+ });
179
+ console.error('[FANTASY] Error tracking panel view:', error);
180
+ }
181
+ }
182
+ async processFantasy(data) {
183
+ try {
184
+ const token = (await this.delegate.getUserToken()) || '';
185
+ this.leagueManagerPolling.stopAll();
186
+ const noData = (data.fantasyData?.totalChallengeEntries || 0) +
187
+ (data.fantasyData?.totalFantasyLeagues || 0) ===
188
+ 0;
189
+ if (noData || (data.preferences || []).length === 0) {
190
+ const promo = await this.fantasyService.getPromo();
191
+ this.append({
192
+ id: 'promo',
193
+ type: 'promo',
194
+ background: promo.fantasy.promotion.background,
195
+ description: promo.fantasy.promotion.description,
196
+ logo: promo.fantasy.promotion.logo,
197
+ qrCode: promo.fantasy.promotion.qrCode,
198
+ title: promo.fantasy.promotion.title,
199
+ });
200
+ return;
201
+ }
202
+ else if (this.fantasyItems.value.find((i) => i.type === 'promo')) {
203
+ this.fantasyItems.value = [];
204
+ }
205
+ // Clear and rebuild the sort order map based on preferences array order
206
+ this.leagueSortOrder.clear();
207
+ this.itemToLeagueKey.clear();
208
+ for (let i = 0; i < (data.preferences || []).length; i++) {
209
+ const pref = data.preferences[i];
210
+ const entry = pref.metaData?.entry || {};
211
+ const game = entry.abbrev;
212
+ const seasonId = entry.seasonId;
213
+ const leagueId = entry.groups?.[0]?.groupId;
214
+ const draftDate = entry.groups?.[0]?.draftDate;
215
+ if (!game || !seasonId || !leagueId || !entry.entryId) {
216
+ continue;
217
+ }
218
+ const key = `${game}-${leagueId}-${seasonId}-${token}`;
219
+ // Store the array index as the sort order for this league
220
+ this.leagueSortOrder.set(key, i);
221
+ this.leagueManagerPolling.refresh(key, {
222
+ game,
223
+ leagueId,
224
+ seasonId,
225
+ token,
226
+ proGameId: this.eventId,
227
+ teamId: entry.entryId,
228
+ }, (data) => {
229
+ if (entry.entryMetadata?.draftComplete === false) {
230
+ this.append(this.parseInactiveLeague(data, draftDate), key);
231
+ }
232
+ else if (isLeagueManagerHeadToHeadResponse(data)) {
233
+ const items = this.parseHeadToHead(data, pref);
234
+ if (items) {
235
+ for (const item of items) {
236
+ this.append(item, key);
237
+ }
238
+ }
239
+ }
240
+ else if (isLeagueManagerRotoResponse(data)) {
241
+ const items = this.parseRoto(data, pref);
242
+ if (items) {
243
+ for (const item of items) {
244
+ this.append(item, key);
245
+ }
246
+ }
247
+ }
248
+ });
249
+ }
250
+ // Mark successful load
251
+ this.hasEverSuccessfullyLoaded.value = true;
252
+ this.errorState.value = 'none';
253
+ }
254
+ catch (error) {
255
+ captureException(error, {
256
+ context: 'FantasyViewModel.processFantasy',
257
+ });
258
+ console.error('[FANTASY] Error processing fantasy data:', error);
259
+ if (!this.hasEverSuccessfullyLoaded.value) {
260
+ this.errorState.value = 'tabLoadFailure';
261
+ }
262
+ }
263
+ }
264
+ parseRoto(data, preference) {
265
+ if (!data.matchups?.length ||
266
+ !data.leagueName ||
267
+ !data.scoringType ||
268
+ !data.gameId) {
269
+ return null;
270
+ }
271
+ const items = [];
272
+ for (const matchup of data.matchups) {
273
+ if (!matchup.teams?.length) {
274
+ continue;
275
+ }
276
+ const team = matchup.teams[0];
277
+ if (!team.logo ||
278
+ !data.sportLogo ||
279
+ !data.sportColor ||
280
+ team.points === undefined) {
281
+ continue;
282
+ }
283
+ const roster = team.roster || [];
284
+ const matchupRoster = [];
285
+ const activeAthletes = [];
286
+ for (const r of roster) {
287
+ if (!r.player) {
288
+ continue;
289
+ }
290
+ if (!r.player.abbrevName ||
291
+ !r.player.headshot ||
292
+ !r.player.proTeam?.triCode ||
293
+ !r.slot) {
294
+ continue;
295
+ }
296
+ matchupRoster.push({
297
+ athleteHeadshot: r.player.headshot,
298
+ athleteAbbrevName: r.player.abbrevName,
299
+ athletesSlot: r.slot,
300
+ teamTriCode: r.player.proTeam.triCode,
301
+ proGameStatusLines: r.player.proGameStatusLines || [],
302
+ });
303
+ if (r.player.currentlyWatching && r.player.points !== undefined) {
304
+ activeAthletes.push({
305
+ abbrevName: r.player.abbrevName,
306
+ points: `${r.player.points} FPTS`,
307
+ });
308
+ }
309
+ }
310
+ items.push({
311
+ id: stringHashCode(JSON.stringify(preference)).toString(),
312
+ type: 'matchup-single',
313
+ topPlayers: this.parseTopPlayers(data.topPlayers || []),
314
+ league: {
315
+ color: data.sportColor,
316
+ logo: data.sportLogo,
317
+ subtitle: data.name,
318
+ title: data.leagueName,
319
+ },
320
+ team: {
321
+ logo: team.logo,
322
+ scoringType: data.scoringType.includes('SEASON')
323
+ ? 'SEASON'
324
+ : data.scoringType,
325
+ points: team.points,
326
+ },
327
+ roster: matchupRoster,
328
+ activeAthletes,
329
+ });
330
+ }
331
+ return items;
332
+ }
333
+ append(item, leagueKey) {
334
+ if (!item) {
335
+ return;
336
+ }
337
+ if (item.type === 'notLoggedIn' || item.type === 'promo') {
338
+ this.fantasyItems.value = [item];
339
+ return;
340
+ }
341
+ // Store the league key for this item
342
+ if (leagueKey) {
343
+ this.itemToLeagueKey.set(item.id, leagueKey);
344
+ }
345
+ const current = this.fantasyItems.value.find((i) => {
346
+ return i.id === item.id;
347
+ });
348
+ let updatedItems;
349
+ if (current) {
350
+ const index = this.fantasyItems.value.indexOf(current);
351
+ updatedItems = [...this.fantasyItems.value];
352
+ updatedItems[index] = item;
353
+ }
354
+ else {
355
+ updatedItems = [...this.fantasyItems.value, item];
356
+ }
357
+ // Sort items based on their league's position in preferences array
358
+ updatedItems.sort((a, b) => {
359
+ const keyA = this.itemToLeagueKey.get(a.id);
360
+ const keyB = this.itemToLeagueKey.get(b.id);
361
+ const orderA = keyA !== undefined
362
+ ? this.leagueSortOrder.get(keyA) ?? Number.MAX_SAFE_INTEGER
363
+ : Number.MAX_SAFE_INTEGER;
364
+ const orderB = keyB !== undefined
365
+ ? this.leagueSortOrder.get(keyB) ?? Number.MAX_SAFE_INTEGER
366
+ : Number.MAX_SAFE_INTEGER;
367
+ return orderA - orderB;
368
+ });
369
+ this.fantasyItems.value = updatedItems;
370
+ }
371
+ parseHeadToHead(data, preference) {
372
+ if (!data.matchups?.length ||
373
+ !data.leagueName ||
374
+ !data.sportColor ||
375
+ !data.sportLogo ||
376
+ !data.gameId) {
377
+ return null;
378
+ }
379
+ const items = [];
380
+ for (const matchup of data.matchups) {
381
+ if (!matchup.home || !matchup.away) {
382
+ continue;
383
+ }
384
+ const roster = [];
385
+ const activeAthletes = [];
386
+ const homeRoster = matchup.home.roster || [];
387
+ const awayRoster = matchup.away.roster || [];
388
+ for (let i = 0; i < awayRoster.length; i++) {
389
+ const singleAwayRoster = awayRoster[i];
390
+ const singleHomeRoster = homeRoster[i];
391
+ if (!singleAwayRoster.player || !singleHomeRoster.player)
392
+ continue;
393
+ if (!singleAwayRoster.player.abbrevName ||
394
+ !singleAwayRoster.player.headshot ||
395
+ !singleAwayRoster.slot ||
396
+ !singleAwayRoster.player.proTeam?.triCode ||
397
+ !matchup.away?.record) {
398
+ continue;
399
+ }
400
+ if (!singleHomeRoster.player.abbrevName ||
401
+ !singleHomeRoster.player.headshot ||
402
+ !singleHomeRoster.slot ||
403
+ !singleHomeRoster.player.proTeam?.triCode ||
404
+ !matchup.home?.record) {
405
+ continue;
406
+ }
407
+ roster.push({
408
+ away: {
409
+ abbrevName: singleAwayRoster.player.abbrevName,
410
+ headshot: singleAwayRoster.player.headshot,
411
+ points: singleAwayRoster.player.points,
412
+ slot: singleAwayRoster.slot,
413
+ stats: singleAwayRoster.player.proGameStatusLines || [],
414
+ triCode: singleAwayRoster.player.proTeam.triCode,
415
+ projectedPoints: singleAwayRoster.player.projectedPoints,
416
+ },
417
+ home: {
418
+ abbrevName: singleHomeRoster.player.abbrevName,
419
+ headshot: singleHomeRoster.player.headshot,
420
+ points: singleHomeRoster.player.points,
421
+ slot: singleHomeRoster.slot,
422
+ stats: singleHomeRoster.player.proGameStatusLines || [],
423
+ triCode: singleHomeRoster.player.proTeam?.triCode,
424
+ projectedPoints: singleHomeRoster.player.projectedPoints,
425
+ },
426
+ });
427
+ if (singleHomeRoster.player.currentlyWatching &&
428
+ singleHomeRoster.player.points !== undefined) {
429
+ activeAthletes.push({
430
+ abbrevName: singleHomeRoster.player.abbrevName,
431
+ points: `${singleHomeRoster.player.points} FPTS`,
432
+ });
433
+ }
434
+ }
435
+ items.push({
436
+ id: stringHashCode(JSON.stringify(preference)).toString(),
437
+ type: 'matchup-pair',
438
+ awayTeam: {
439
+ logo: matchup.away.logo,
440
+ name: matchup.away.name,
441
+ points: data.scoringType === 'H2H_POINTS'
442
+ ? String(matchup.away.points)
443
+ : matchup.away.score,
444
+ projectedPoints: matchup.away.projectedPoints,
445
+ record: matchup.away.record,
446
+ winProbability: matchup.away.winProbability,
447
+ },
448
+ homeTeam: {
449
+ logo: matchup.home.logo,
450
+ name: matchup.home.name,
451
+ points: data.scoringType === 'H2H_POINTS'
452
+ ? String(matchup.home.points)
453
+ : matchup.home.score,
454
+ projectedPoints: matchup.home.projectedPoints,
455
+ record: matchup.home.record,
456
+ winProbability: matchup.home.winProbability,
457
+ },
458
+ league: {
459
+ color: data.sportColor,
460
+ logo: data.sportLogo,
461
+ subtitle: matchup.name,
462
+ title: data.leagueName,
463
+ },
464
+ roster,
465
+ activeAthletes,
466
+ topPlayers: this.parseTopPlayers(data.topPlayers || []),
467
+ });
468
+ }
469
+ return items;
470
+ }
471
+ parseTopPlayers(players) {
472
+ const topPlayers = [];
473
+ for (const p of players) {
474
+ if (!p.abbrevName ||
475
+ !p.headshot ||
476
+ !p.proTeam?.triCode ||
477
+ p.points === undefined) {
478
+ continue;
479
+ }
480
+ let rosteredBy = '';
481
+ if (p.percentRostered !== undefined &&
482
+ p.percentRostered > 0 &&
483
+ p.playerStatus?.startsWith('Rostered')) {
484
+ rosteredBy = p.playerStatus;
485
+ }
486
+ topPlayers.push({
487
+ abbrevName: p.abbrevName,
488
+ headshot: p.headshot,
489
+ position: p.positions?.split(',')[0] || '',
490
+ teamTriCode: p.proTeam.triCode,
491
+ points: p.points,
492
+ rosteredBy,
493
+ });
494
+ }
495
+ return topPlayers;
496
+ }
497
+ parseInactiveLeague(data, draftDate) {
498
+ if (!data.sportColor || !data.sportLogo || !data.leagueName) {
499
+ return null;
500
+ }
501
+ let draftDateNum = undefined;
502
+ if (draftDate) {
503
+ const parsedDate = new Date(Number(draftDate));
504
+ if (!isNaN(parsedDate.getTime())) {
505
+ draftDateNum = parsedDate.getTime();
506
+ }
507
+ }
508
+ return {
509
+ id: slugify(`${data.gameId}-inactive-${data.leagueName}`),
510
+ leagueColor: data.sportColor,
511
+ leagueLogo: data.sportLogo,
512
+ leagueName: data.leagueName,
513
+ type: 'inactiveLeague',
514
+ draftDate: draftDateNum,
515
+ };
516
+ }
517
+ /**
518
+ * Fetch mock data for testing
519
+ */
520
+ async fetchMockData() {
521
+ this.hasEverSuccessfullyLoaded.value = true;
522
+ await this.processFantasy(MOCK_FANTASY_RESPONSE);
523
+ this.errorState.value = 'none';
524
+ this.isDataLoading.value = false;
525
+ }
526
+ clearTabLoadFailure() {
527
+ this.errorState.value = 'none';
528
+ // Small delay to allow UI to update before refetching
529
+ setTimeout(() => {
530
+ this.fetchData();
531
+ }, 100);
532
+ }
533
+ }
534
+ export default FantasyViewModel;