gametime-api-client 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # Gametime API Client
2
+
3
+ A typed JavaScript client for the [Gametime API](https://gametimeapi.onrender.com) – live sports data, player analysis, and predictions for NBA & Soccer.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install gametime-api-client
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Quick start
14
+
15
+ ```js
16
+ import { gametime } from 'gametime-api-client';
17
+
18
+ // Live soccer games
19
+ const games = await gametime.live.games('soccer');
20
+ console.log(games[0]); // { sportEventId, homeTeam, awayTeam, score, ... }
21
+
22
+ // One-line soccer analysis (auto-picks game + focus player)
23
+ const analysis = await gametime.live.soccerAnalysis({
24
+ sportEventId: games[0].sportEventId,
25
+ });
26
+ console.log(analysis.prediction.projectedFinal); // { goals, assists, shots, touches }
27
+ ```
28
+
29
+ ### Custom base URL
30
+
31
+ ```js
32
+ import { createClient } from 'gametime-api-client';
33
+
34
+ const api = createClient({ baseUrl: 'https://gametimeapi.onrender.com' });
35
+
36
+ const nbaGames = await api.live.games('nba');
37
+ const nbaAnalysis = await api.live.nbaAnalysis({
38
+ sportEventId: nbaGames[0].sportEventId,
39
+ focusPlayerId: 'some-player-id',
40
+ });
41
+ ```
42
+
43
+ ### Full flow (soccer)
44
+
45
+ ```js
46
+ import { createClient } from 'gametime-api-client';
47
+
48
+ const api = createClient();
49
+
50
+ // 1. Get live games
51
+ const games = await api.live.games('soccer');
52
+
53
+ // 2. Optional: list players for a game
54
+ const players = await api.live.players(games[0].sportEventId, 'soccer');
55
+
56
+ // 3. Get prediction analysis (focus player optional; API can auto-pick)
57
+ const analysis = await api.live.soccerAnalysis({
58
+ sportEventId: games[0].sportEventId,
59
+ focusPlayerId: players[0]?.playerId, // optional
60
+ });
61
+
62
+ console.log(analysis.live.currentTotals); // goals, assists, shots, touches
63
+ console.log(analysis.prediction.projectedFinal);
64
+ ```
65
+
66
+ ### Error handling
67
+
68
+ ```js
69
+ import { gametime, ApiError } from 'gametime-api-client';
70
+
71
+ try {
72
+ const games = await gametime.live.games('soccer');
73
+ } catch (err) {
74
+ if (err instanceof ApiError) {
75
+ console.error(err.message, err.status, err.code);
76
+ }
77
+ throw err;
78
+ }
79
+ ```
80
+
81
+ ## API reference
82
+
83
+ | Method | Description |
84
+ |--------|-------------|
85
+ | `live.games(sport)` | `'soccer' \| 'nba'` – list in-progress live games |
86
+ | `live.players(sportEventId, sport)` | List players for a game |
87
+ | `live.soccerAnalysis({ sportEventId, focusPlayerId? })` | Soccer prediction analysis |
88
+ | `live.nbaAnalysis({ sportEventId, focusPlayerId?, verbosity? })` | NBA prediction analysis |
89
+ | `live.createSession({ sport, sportEventId, focusPlayerId? })` | Create live WebSocket session |
90
+
91
+ ## Types
92
+
93
+ The client is written in TypeScript and ships with `.d.ts` definitions. Import types for better IDE support:
94
+
95
+ ```ts
96
+ import type { LiveGame, SoccerAnalysis, NbaAnalysis } from 'gametime-api-client';
97
+ ```
98
+
99
+ ## Links
100
+
101
+ - **Hosted API**: https://gametimeapi.onrender.com
102
+ - **API docs**: See main project README
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Gametime API JavaScript Client
3
+ * Live sports data, player analysis, and predictions for NBA & Soccer.
4
+ *
5
+ * @example
6
+ * ```js
7
+ * import { createClient } from 'gametime-api-client';
8
+ * const api = createClient({ baseUrl: 'https://gametimeapi.onrender.com' });
9
+ * const games = await api.live.games('soccer');
10
+ * const analysis = await api.live.soccerAnalysis({ sportEventId: games[0].sportEventId });
11
+ * ```
12
+ */
13
+ export interface ClientOptions {
14
+ /** API base URL. Default: https://gametimeapi.onrender.com */
15
+ baseUrl?: string;
16
+ }
17
+ declare class ApiError extends Error {
18
+ code?: string | undefined;
19
+ status?: number | undefined;
20
+ details?: unknown | undefined;
21
+ constructor(message: string, code?: string | undefined, status?: number | undefined, details?: unknown | undefined);
22
+ }
23
+ /** Live games and analysis */
24
+ export interface LiveApi {
25
+ /** Fetch in-progress live games for a sport */
26
+ games(sport: "soccer" | "nba"): Promise<LiveGame[]>;
27
+ /** Fetch players for a specific game */
28
+ players(sportEventId: string, sport: "soccer" | "nba"): Promise<LivePlayer[]>;
29
+ /** Soccer player prediction analysis (auto-picks focus player if not provided) */
30
+ soccerAnalysis(params: {
31
+ sportEventId: string;
32
+ focusPlayerId?: string;
33
+ focusPlayerName?: string;
34
+ }): Promise<SoccerAnalysis>;
35
+ /** NBA player prediction analysis */
36
+ nbaAnalysis(params: {
37
+ sportEventId: string;
38
+ focusPlayerId?: string;
39
+ focusPlayerName?: string;
40
+ verbosity?: "short" | "medium" | "high";
41
+ }): Promise<NbaAnalysis>;
42
+ /** Create a live session for WebSocket streaming */
43
+ createSession(params: {
44
+ sport: "soccer" | "nba";
45
+ sportEventId: string;
46
+ focusPlayerId?: string;
47
+ focusPlayerName?: string;
48
+ }): Promise<{
49
+ id: string;
50
+ }>;
51
+ }
52
+ export interface LiveGame {
53
+ sportEventId: string;
54
+ scheduled?: string;
55
+ status?: string;
56
+ homeTeam?: string;
57
+ awayTeam?: string;
58
+ score?: string | null;
59
+ competition?: string | null;
60
+ analysis?: Record<string, unknown>;
61
+ }
62
+ export interface LivePlayer {
63
+ playerId: string;
64
+ name?: string | null;
65
+ teamId?: string | null;
66
+ teamName?: string | null;
67
+ touches?: number;
68
+ isActive?: boolean;
69
+ }
70
+ export interface SoccerAnalysis {
71
+ sport: "soccer";
72
+ sportEventId: string;
73
+ player: {
74
+ playerId: string;
75
+ name: string;
76
+ teamId?: string | null;
77
+ };
78
+ live: {
79
+ elapsedMinutes: number;
80
+ currentTotals: {
81
+ goals: number;
82
+ assists: number;
83
+ shots: number;
84
+ touches: number;
85
+ };
86
+ };
87
+ historical: {
88
+ averages: Record<string, number>;
89
+ };
90
+ prediction: {
91
+ projectedFinal: Record<string, number>;
92
+ blendedPrediction: Record<string, number>;
93
+ confidence: string;
94
+ };
95
+ matchEnded: boolean;
96
+ narration?: Record<string, unknown>;
97
+ }
98
+ export interface NbaAnalysis {
99
+ sport: "nba";
100
+ sportEventId: string;
101
+ player: {
102
+ playerId: string;
103
+ name: string;
104
+ teamId?: string | null;
105
+ };
106
+ live: {
107
+ elapsedSeconds: number;
108
+ currentTotals: {
109
+ pts: number;
110
+ ast: number;
111
+ reb: number;
112
+ threePm: number;
113
+ };
114
+ };
115
+ historical: {
116
+ averages: Record<string, number>;
117
+ };
118
+ prediction: {
119
+ projectedFinal: Record<string, number>;
120
+ blendedPrediction: Record<string, number>;
121
+ confidence: string;
122
+ };
123
+ narration?: Record<string, unknown>;
124
+ }
125
+ /** Create a Gametime API client */
126
+ export declare function createClient(options?: ClientOptions): {
127
+ live: LiveApi;
128
+ };
129
+ /** Pre-built client using default hosted API URL */
130
+ export declare const gametime: {
131
+ live: LiveApi;
132
+ };
133
+ export { ApiError };
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Gametime API JavaScript Client
3
+ * Live sports data, player analysis, and predictions for NBA & Soccer.
4
+ *
5
+ * @example
6
+ * ```js
7
+ * import { createClient } from 'gametime-api-client';
8
+ * const api = createClient({ baseUrl: 'https://gametimeapi.onrender.com' });
9
+ * const games = await api.live.games('soccer');
10
+ * const analysis = await api.live.soccerAnalysis({ sportEventId: games[0].sportEventId });
11
+ * ```
12
+ */
13
+ const DEFAULT_BASE = "https://gametimeapi.onrender.com";
14
+ class ApiError extends Error {
15
+ constructor(message, code, status, details) {
16
+ super(message);
17
+ this.code = code;
18
+ this.status = status;
19
+ this.details = details;
20
+ this.name = "GametimeApiError";
21
+ }
22
+ }
23
+ async function request(baseUrl, path, init) {
24
+ const url = `${baseUrl.replace(/\/$/, "")}${path}`;
25
+ const res = await fetch(url, {
26
+ ...init,
27
+ headers: { "Content-Type": "application/json", ...init?.headers },
28
+ });
29
+ const body = await res.json().catch(() => ({}));
30
+ if (!res.ok) {
31
+ const err = body?.error ?? body;
32
+ throw new ApiError(err?.message ?? body?.message ?? res.statusText, err?.code, res.status, err?.details);
33
+ }
34
+ return body;
35
+ }
36
+ function get(baseUrl, path) {
37
+ return request(baseUrl, path, { method: "GET" });
38
+ }
39
+ function post(baseUrl, path, body) {
40
+ return request(baseUrl, path, {
41
+ method: "POST",
42
+ body: JSON.stringify(body),
43
+ });
44
+ }
45
+ /** Create a Gametime API client */
46
+ export function createClient(options = {}) {
47
+ const baseUrl = options.baseUrl ?? DEFAULT_BASE;
48
+ const live = {
49
+ games(sport) {
50
+ return get(baseUrl, `/v1/live/games?sport=${sport}`);
51
+ },
52
+ players(sportEventId, sport) {
53
+ const path = `/v1/live/games/${encodeURIComponent(sportEventId)}/players?sport=${sport}`;
54
+ return get(baseUrl, path);
55
+ },
56
+ async soccerAnalysis(params) {
57
+ return post(baseUrl, "/v1/live/soccer/analysis", params);
58
+ },
59
+ async nbaAnalysis(params) {
60
+ return post(baseUrl, "/v1/live/nba/analysis", params);
61
+ },
62
+ async createSession(params) {
63
+ return post(baseUrl, "/v1/live/sessions", params);
64
+ },
65
+ };
66
+ return { live };
67
+ }
68
+ /** Pre-built client using default hosted API URL */
69
+ export const gametime = createClient();
70
+ export { ApiError };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "gametime-api-client",
3
+ "version": "1.0.0",
4
+ "description": "JavaScript client for Gametime API - live sports data, player analysis, and predictions",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": ["dist"],
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "prepublishOnly": "npm run build"
19
+ },
20
+ "keywords": ["gametime", "sports", "api", "nba", "soccer", "live", "prediction"],
21
+ "author": "",
22
+ "license": "MIT",
23
+ "devDependencies": {
24
+ "typescript": "^5.9.2"
25
+ }
26
+ }