@gotza02/sequential-thinking 2026.2.40 → 2026.2.42
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/SYSTEM_INSTRUCTION.md +253 -37
- package/dist/http-server.js +45 -2
- package/dist/tools/filesystem.js +4 -3
- package/dist/tools/sports/core/base.d.ts +169 -0
- package/dist/tools/sports/core/base.js +289 -0
- package/dist/tools/sports/core/cache.d.ts +106 -0
- package/dist/tools/sports/core/cache.js +306 -0
- package/dist/tools/sports/core/constants.d.ts +179 -0
- package/dist/tools/sports/core/constants.js +149 -0
- package/dist/tools/sports/core/types.d.ts +379 -0
- package/dist/tools/sports/core/types.js +5 -0
- package/dist/tools/sports/index.d.ts +34 -0
- package/dist/tools/sports/index.js +50 -0
- package/dist/tools/sports/providers/api.d.ts +73 -0
- package/dist/tools/sports/providers/api.js +517 -0
- package/dist/tools/sports/providers/scraper.d.ts +66 -0
- package/dist/tools/sports/providers/scraper.js +186 -0
- package/dist/tools/sports/providers/search.d.ts +54 -0
- package/dist/tools/sports/providers/search.js +224 -0
- package/dist/tools/sports/tools/betting.d.ts +6 -0
- package/dist/tools/sports/tools/betting.js +251 -0
- package/dist/tools/sports/tools/league.d.ts +11 -0
- package/dist/tools/sports/tools/league.js +12 -0
- package/dist/tools/sports/tools/live.d.ts +9 -0
- package/dist/tools/sports/tools/live.js +235 -0
- package/dist/tools/sports/tools/match.d.ts +6 -0
- package/dist/tools/sports/tools/match.js +323 -0
- package/dist/tools/sports/tools/player.d.ts +6 -0
- package/dist/tools/sports/tools/player.js +152 -0
- package/dist/tools/sports/tools/team.d.ts +6 -0
- package/dist/tools/sports/tools/team.js +370 -0
- package/dist/tools/sports/utils/calculator.d.ts +69 -0
- package/dist/tools/sports/utils/calculator.js +156 -0
- package/dist/tools/sports/utils/formatter.d.ts +57 -0
- package/dist/tools/sports/utils/formatter.js +206 -0
- package/dist/tools/sports.d.ts +7 -0
- package/dist/tools/sports.js +27 -6
- package/dist/utils.d.ts +22 -0
- package/dist/utils.js +234 -6
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPORTS MODULE INDEX
|
|
3
|
+
* Main entry point - Exports all sports functionality
|
|
4
|
+
*/
|
|
5
|
+
export * from './core/constants.js';
|
|
6
|
+
export * from './core/types.js';
|
|
7
|
+
export * from './core/cache.js';
|
|
8
|
+
export * from './core/base.js';
|
|
9
|
+
export * from './providers/api.js';
|
|
10
|
+
export * from './providers/scraper.js';
|
|
11
|
+
export * from './providers/search.js';
|
|
12
|
+
export { getGlobalCache, resetGlobalCache, CacheService, } from './core/cache.js';
|
|
13
|
+
export { createAPIProvider, } from './providers/api.js';
|
|
14
|
+
export { getSearchProvider, resetSearchProvider, SearchProvider, } from './providers/search.js';
|
|
15
|
+
export { scrapeMatchContent, findBestMatchUrl, } from './providers/scraper.js';
|
|
16
|
+
export * from './utils/calculator.js';
|
|
17
|
+
export * from './utils/formatter.js';
|
|
18
|
+
export { formatMatchesTable, formatComparisonResult, formatPlayerStats, formatMatchRow, formatScore, formatMatchStatus, formatHeadToHead, } from './utils/formatter.js';
|
|
19
|
+
/**
|
|
20
|
+
* Initialize the sports module with custom configuration
|
|
21
|
+
*/
|
|
22
|
+
export declare function initializeSportsModule(config?: {
|
|
23
|
+
cachePath?: string;
|
|
24
|
+
cacheTTL?: number;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get sports module status
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSportsModuleStatus(): {
|
|
30
|
+
version: string;
|
|
31
|
+
providers: string[];
|
|
32
|
+
searchProviders: string[];
|
|
33
|
+
cacheEnabled: boolean;
|
|
34
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPORTS MODULE INDEX
|
|
3
|
+
* Main entry point - Exports all sports functionality
|
|
4
|
+
*/
|
|
5
|
+
// ============= Core Exports =============
|
|
6
|
+
export * from './core/constants.js';
|
|
7
|
+
export * from './core/types.js';
|
|
8
|
+
export * from './core/cache.js';
|
|
9
|
+
export * from './core/base.js';
|
|
10
|
+
// ============= Provider Exports =============
|
|
11
|
+
export * from './providers/api.js';
|
|
12
|
+
export * from './providers/scraper.js';
|
|
13
|
+
export * from './providers/search.js';
|
|
14
|
+
// Re-exports for convenience
|
|
15
|
+
export { getGlobalCache, resetGlobalCache, CacheService, } from './core/cache.js';
|
|
16
|
+
export { createAPIProvider, } from './providers/api.js';
|
|
17
|
+
export { getSearchProvider, resetSearchProvider, SearchProvider, } from './providers/search.js';
|
|
18
|
+
export { scrapeMatchContent, findBestMatchUrl, } from './providers/scraper.js';
|
|
19
|
+
// ============= Utility Exports =============
|
|
20
|
+
export * from './utils/calculator.js';
|
|
21
|
+
export * from './utils/formatter.js';
|
|
22
|
+
// Re-export specific utility functions for convenience
|
|
23
|
+
export { formatMatchesTable, formatComparisonResult, formatPlayerStats, formatMatchRow, formatScore, formatMatchStatus, formatHeadToHead, } from './utils/formatter.js';
|
|
24
|
+
// ============= Utility Functions =============
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the sports module with custom configuration
|
|
27
|
+
*/
|
|
28
|
+
export async function initializeSportsModule(config) {
|
|
29
|
+
const { getGlobalCache } = await import('./core/cache.js');
|
|
30
|
+
// Initialize cache with config if provided
|
|
31
|
+
if (config?.cachePath || config?.cacheTTL) {
|
|
32
|
+
// Cache is already initialized, but we could add reconfiguration here
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get sports module status
|
|
37
|
+
*/
|
|
38
|
+
export function getSportsModuleStatus() {
|
|
39
|
+
const { MODULE_INFO } = require('./core/constants.js');
|
|
40
|
+
const apiProvider = require('./providers/api.js').createAPIProvider();
|
|
41
|
+
const searchProvider = require('./providers/search.js').getSearchProvider();
|
|
42
|
+
return {
|
|
43
|
+
version: MODULE_INFO.VERSION,
|
|
44
|
+
providers: apiProvider.getStatus().available
|
|
45
|
+
? ['api-football', 'football-data', 'sports-db'].filter((p) => process.env[`${p.replace('-', '_').toUpperCase()}_KEY`])
|
|
46
|
+
: [],
|
|
47
|
+
searchProviders: searchProvider.getAvailableProviders(),
|
|
48
|
+
cacheEnabled: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPORTS MODULE API PROVIDERS
|
|
3
|
+
* Concrete implementations of football API providers
|
|
4
|
+
*/
|
|
5
|
+
import { Match, Team, Player, TableEntry, APIResponse } from '../core/types.js';
|
|
6
|
+
import { APIProviderBase, FallbackProvider } from '../core/base.js';
|
|
7
|
+
/**
|
|
8
|
+
* API-Football Provider (via RapidAPI)
|
|
9
|
+
* Documentation: https://rapidapi.com/api-sports/api/api-football
|
|
10
|
+
*/
|
|
11
|
+
export declare class APIFootballProvider extends APIProviderBase {
|
|
12
|
+
constructor();
|
|
13
|
+
protected getAuthHeaders(): Record<string, string>;
|
|
14
|
+
protected transformResponse<T>(data: any): T;
|
|
15
|
+
getMatch(matchId: string): Promise<APIResponse<Match>>;
|
|
16
|
+
getLiveMatches(leagueId?: string): Promise<APIResponse<Match[]>>;
|
|
17
|
+
getStandings(leagueId: string, season?: string): Promise<APIResponse<TableEntry[]>>;
|
|
18
|
+
getTeam(teamId: string): Promise<APIResponse<Team>>;
|
|
19
|
+
getPlayer(playerId: string): Promise<APIResponse<Player>>;
|
|
20
|
+
searchTeams(query: string): Promise<APIResponse<Team[]>>;
|
|
21
|
+
searchPlayers(query: string): Promise<APIResponse<Player[]>>;
|
|
22
|
+
private transformMatch;
|
|
23
|
+
private transformTeam;
|
|
24
|
+
private transformPlayer;
|
|
25
|
+
private transformTableEntry;
|
|
26
|
+
private mapStatus;
|
|
27
|
+
private mapPosition;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Football-Data.org Provider
|
|
31
|
+
* Documentation: https://www.football-data.org/
|
|
32
|
+
*/
|
|
33
|
+
export declare class FootballDataProvider extends APIProviderBase {
|
|
34
|
+
constructor();
|
|
35
|
+
protected getAuthHeaders(): Record<string, string>;
|
|
36
|
+
protected transformResponse<T>(data: any): T;
|
|
37
|
+
getMatch(matchId: string): Promise<APIResponse<Match>>;
|
|
38
|
+
getLiveMatches(leagueId?: string): Promise<APIResponse<Match[]>>;
|
|
39
|
+
getStandings(leagueId: string, season?: string): Promise<APIResponse<TableEntry[]>>;
|
|
40
|
+
getTeam(teamId: string): Promise<APIResponse<Team>>;
|
|
41
|
+
getPlayer(playerId: string): Promise<APIResponse<Player>>;
|
|
42
|
+
searchTeams(query: string): Promise<APIResponse<Team[]>>;
|
|
43
|
+
searchPlayers(query: string): Promise<APIResponse<Player[]>>;
|
|
44
|
+
private transformMatchFD;
|
|
45
|
+
private transformTeamFD;
|
|
46
|
+
private transformTableEntryFD;
|
|
47
|
+
private mapStatusFD;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* TheSportsDB Provider
|
|
51
|
+
* Documentation: https://www.thesportsdb.com/api.php
|
|
52
|
+
*/
|
|
53
|
+
export declare class SportsDBProvider extends APIProviderBase {
|
|
54
|
+
constructor();
|
|
55
|
+
protected getAuthHeaders(): Record<string, string>;
|
|
56
|
+
protected transformResponse<T>(data: any): T;
|
|
57
|
+
getMatch(matchId: string): Promise<APIResponse<Match>>;
|
|
58
|
+
getLiveMatches(): Promise<APIResponse<Match[]>>;
|
|
59
|
+
getStandings(leagueId: string): Promise<APIResponse<TableEntry[]>>;
|
|
60
|
+
getTeam(teamId: string): Promise<APIResponse<Team>>;
|
|
61
|
+
getPlayer(playerId: string): Promise<APIResponse<Player>>;
|
|
62
|
+
searchTeams(query: string): Promise<APIResponse<Team[]>>;
|
|
63
|
+
searchPlayers(query: string): Promise<APIResponse<Player[]>>;
|
|
64
|
+
private transformMatchDB;
|
|
65
|
+
private transformTeamDB;
|
|
66
|
+
private transformPlayerDB;
|
|
67
|
+
private transformTableEntryDB;
|
|
68
|
+
private mapPositionDB;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a fallback provider with all available API providers
|
|
72
|
+
*/
|
|
73
|
+
export declare function createAPIProvider(): FallbackProvider;
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPORTS MODULE API PROVIDERS
|
|
3
|
+
* Concrete implementations of football API providers
|
|
4
|
+
*/
|
|
5
|
+
import { APIProviderBase, FallbackProvider } from '../core/base.js';
|
|
6
|
+
import { API_CONFIG } from '../core/constants.js';
|
|
7
|
+
import { logger } from '../../../utils.js';
|
|
8
|
+
/**
|
|
9
|
+
* API-Football Provider (via RapidAPI)
|
|
10
|
+
* Documentation: https://rapidapi.com/api-sports/api/api-football
|
|
11
|
+
*/
|
|
12
|
+
export class APIFootballProvider extends APIProviderBase {
|
|
13
|
+
constructor() {
|
|
14
|
+
super('api-football', API_CONFIG.API_FOOTBALL_KEY, API_CONFIG.API_FOOTBALL_BASE, API_CONFIG.RATE_LIMITS.API_FOOTBALL);
|
|
15
|
+
}
|
|
16
|
+
getAuthHeaders() {
|
|
17
|
+
return {
|
|
18
|
+
'x-rapidapi-key': this.apiKey,
|
|
19
|
+
'x-rapidapi-host': API_CONFIG.API_FOOTBALL_HOST,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
transformResponse(data) {
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
async getMatch(matchId) {
|
|
26
|
+
const cacheKey = `match:api-football:${matchId}`;
|
|
27
|
+
const cached = this.cache.get(cacheKey);
|
|
28
|
+
if (cached)
|
|
29
|
+
return { success: true, data: cached, cached: true };
|
|
30
|
+
const response = await this.callAPI(`/fixtures?id=${matchId}`);
|
|
31
|
+
if (response.success && response.data?.response?.[0]) {
|
|
32
|
+
const match = this.transformMatch(response.data.response[0]);
|
|
33
|
+
this.cache.set(cacheKey, match);
|
|
34
|
+
return { success: true, data: match, provider: 'api-football' };
|
|
35
|
+
}
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
async getLiveMatches(leagueId) {
|
|
39
|
+
const endpoint = leagueId
|
|
40
|
+
? `/fixtures?live=all&league=${leagueId}`
|
|
41
|
+
: '/fixtures?live=all';
|
|
42
|
+
const response = await this.callAPI(endpoint);
|
|
43
|
+
if (response.success && response.data?.response) {
|
|
44
|
+
const matches = response.data.response.map((m) => this.transformMatch(m));
|
|
45
|
+
return { success: true, data: matches, provider: 'api-football' };
|
|
46
|
+
}
|
|
47
|
+
return response;
|
|
48
|
+
}
|
|
49
|
+
async getStandings(leagueId, season) {
|
|
50
|
+
const currentYear = new Date().getFullYear();
|
|
51
|
+
const seasonYear = season || currentYear;
|
|
52
|
+
const response = await this.callAPI(`/standings?league=${leagueId}&season=${seasonYear}`);
|
|
53
|
+
if (response.success && response.data?.response?.[0]?.league?.standings?.[0]) {
|
|
54
|
+
const standings = response.data.response[0].league.standings[0].map((s) => this.transformTableEntry(s));
|
|
55
|
+
return { success: true, data: standings, provider: 'api-football' };
|
|
56
|
+
}
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
async getTeam(teamId) {
|
|
60
|
+
const response = await this.callAPI(`/teams?id=${teamId}`);
|
|
61
|
+
if (response.success && response.data?.response?.[0]) {
|
|
62
|
+
const team = this.transformTeam(response.data.response[0]);
|
|
63
|
+
return { success: true, data: team, provider: 'api-football' };
|
|
64
|
+
}
|
|
65
|
+
return response;
|
|
66
|
+
}
|
|
67
|
+
async getPlayer(playerId) {
|
|
68
|
+
const response = await this.callAPI(`/players?id=${playerId}&season=2024`);
|
|
69
|
+
if (response.success && response.data?.response?.[0]) {
|
|
70
|
+
const player = this.transformPlayer(response.data.response[0]);
|
|
71
|
+
return { success: true, data: player, provider: 'api-football' };
|
|
72
|
+
}
|
|
73
|
+
return response;
|
|
74
|
+
}
|
|
75
|
+
async searchTeams(query) {
|
|
76
|
+
const response = await this.callAPI(`/teams?search=${encodeURIComponent(query)}`);
|
|
77
|
+
if (response.success && response.data?.response) {
|
|
78
|
+
const teams = response.data.response.map((t) => this.transformTeam(t));
|
|
79
|
+
return { success: true, data: teams, provider: 'api-football' };
|
|
80
|
+
}
|
|
81
|
+
return response;
|
|
82
|
+
}
|
|
83
|
+
async searchPlayers(query) {
|
|
84
|
+
const response = await this.callAPI(`/players?search=${encodeURIComponent(query)}&season=2024`);
|
|
85
|
+
if (response.success && response.data?.response) {
|
|
86
|
+
const players = response.data.response.map((p) => this.transformPlayer(p));
|
|
87
|
+
return { success: true, data: players, provider: 'api-football' };
|
|
88
|
+
}
|
|
89
|
+
return response;
|
|
90
|
+
}
|
|
91
|
+
// ============= Transformation Helpers =============
|
|
92
|
+
transformMatch(data) {
|
|
93
|
+
return {
|
|
94
|
+
id: data.fixture.id.toString(),
|
|
95
|
+
homeTeam: this.transformTeam(data.teams.home),
|
|
96
|
+
awayTeam: this.transformTeam(data.teams.away),
|
|
97
|
+
league: {
|
|
98
|
+
id: data.league.id.toString(),
|
|
99
|
+
name: data.league.name,
|
|
100
|
+
country: data.league.country,
|
|
101
|
+
season: data.league.season.toString(),
|
|
102
|
+
},
|
|
103
|
+
date: new Date(data.fixture.date),
|
|
104
|
+
status: this.mapStatus(data.fixture.status.long),
|
|
105
|
+
venue: data.fixture.venue?.name,
|
|
106
|
+
score: data.goals ? {
|
|
107
|
+
home: data.goals.home,
|
|
108
|
+
away: data.goals.away,
|
|
109
|
+
halfTime: data.score.halftime ? {
|
|
110
|
+
home: data.score.halftime.home,
|
|
111
|
+
away: data.score.halftime.away,
|
|
112
|
+
} : undefined,
|
|
113
|
+
} : undefined,
|
|
114
|
+
minute: data.fixture.status?.elapsed,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
transformTeam(data) {
|
|
118
|
+
return {
|
|
119
|
+
id: data.team?.id?.toString() || data.id?.toString() || '',
|
|
120
|
+
name: data.team?.name || data.name || '',
|
|
121
|
+
code: data.team?.code || data.code,
|
|
122
|
+
country: data.team?.country || data.country || '',
|
|
123
|
+
logo: data.team?.logo || data.logo,
|
|
124
|
+
founded: data.team?.founded || data.founded,
|
|
125
|
+
venue: data.venue?.name,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
transformPlayer(data) {
|
|
129
|
+
return {
|
|
130
|
+
id: data.player?.id?.toString() || data.id?.toString() || '',
|
|
131
|
+
name: data.player?.name || data.name || '',
|
|
132
|
+
age: data.player?.age || data.age,
|
|
133
|
+
nationality: data.player?.nationality || data.nationality || '',
|
|
134
|
+
position: this.mapPosition(data.player?.position || data.statistics?.[0]?.games?.position),
|
|
135
|
+
number: data.player?.number || data.statistics?.[0]?.games?.number,
|
|
136
|
+
photo: data.player?.photo,
|
|
137
|
+
team: data.statistics?.[0]?.team ? this.transformTeam({ team: data.statistics[0].team }) : undefined,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
transformTableEntry(data) {
|
|
141
|
+
return {
|
|
142
|
+
position: data.rank,
|
|
143
|
+
team: this.transformTeam(data.team),
|
|
144
|
+
played: data.all.played,
|
|
145
|
+
won: data.all.win,
|
|
146
|
+
drawn: data.all.draw,
|
|
147
|
+
lost: data.all.lose,
|
|
148
|
+
goalsFor: data.all.goals.for,
|
|
149
|
+
goalsAgainst: data.all.goals.against,
|
|
150
|
+
goalDifference: data.goalsDiff,
|
|
151
|
+
points: data.points,
|
|
152
|
+
form: data.form ? (data.form.split('').map((c) => c)) : undefined,
|
|
153
|
+
homeRecord: data.home ? {
|
|
154
|
+
played: data.home.played,
|
|
155
|
+
won: data.home.win,
|
|
156
|
+
drawn: data.home.draw,
|
|
157
|
+
lost: data.home.lose,
|
|
158
|
+
goalsFor: data.home.goals.for,
|
|
159
|
+
against: data.home.goals.against,
|
|
160
|
+
} : undefined,
|
|
161
|
+
awayRecord: data.away ? {
|
|
162
|
+
played: data.away.played,
|
|
163
|
+
won: data.away.win,
|
|
164
|
+
drawn: data.away.draw,
|
|
165
|
+
lost: data.away.lose,
|
|
166
|
+
goalsFor: data.away.goals.for,
|
|
167
|
+
against: data.away.goals.against,
|
|
168
|
+
} : undefined,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
mapStatus(status) {
|
|
172
|
+
const s = status.toLowerCase();
|
|
173
|
+
if (s.includes('live') || s.includes('half'))
|
|
174
|
+
return 'live';
|
|
175
|
+
if (s.includes('finished') || s.includes('complete'))
|
|
176
|
+
return 'finished';
|
|
177
|
+
if (s.includes('postponed'))
|
|
178
|
+
return 'postponed';
|
|
179
|
+
if (s.includes('cancelled'))
|
|
180
|
+
return 'cancelled';
|
|
181
|
+
return 'scheduled';
|
|
182
|
+
}
|
|
183
|
+
mapPosition(pos) {
|
|
184
|
+
if (!pos)
|
|
185
|
+
return 'SUB';
|
|
186
|
+
const p = pos.toLowerCase();
|
|
187
|
+
if (p.includes('goalkeeper') || p === 'gk')
|
|
188
|
+
return 'GK';
|
|
189
|
+
if (p.includes('defender') || p === 'df')
|
|
190
|
+
return 'DF';
|
|
191
|
+
if (p.includes('midfielder') || p === 'mf')
|
|
192
|
+
return 'MF';
|
|
193
|
+
if (p.includes('forward') || p === 'fw')
|
|
194
|
+
return 'FW';
|
|
195
|
+
return 'SUB';
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Football-Data.org Provider
|
|
200
|
+
* Documentation: https://www.football-data.org/
|
|
201
|
+
*/
|
|
202
|
+
export class FootballDataProvider extends APIProviderBase {
|
|
203
|
+
constructor() {
|
|
204
|
+
super('football-data', API_CONFIG.FOOTBALL_DATA_KEY, API_CONFIG.FOOTBALL_DATA_BASE, API_CONFIG.RATE_LIMITS.FOOTBALL_DATA);
|
|
205
|
+
}
|
|
206
|
+
getAuthHeaders() {
|
|
207
|
+
return {
|
|
208
|
+
'X-Auth-Token': this.apiKey,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
transformResponse(data) {
|
|
212
|
+
return data;
|
|
213
|
+
}
|
|
214
|
+
async getMatch(matchId) {
|
|
215
|
+
const response = await this.callAPI(`/matches/${matchId}`);
|
|
216
|
+
if (response.success && response.data?.match) {
|
|
217
|
+
const match = this.transformMatchFD(response.data.match);
|
|
218
|
+
return { success: true, data: match, provider: 'football-data' };
|
|
219
|
+
}
|
|
220
|
+
return response;
|
|
221
|
+
}
|
|
222
|
+
async getLiveMatches(leagueId) {
|
|
223
|
+
const response = await this.callAPI('/matches?status=IN_PLAY');
|
|
224
|
+
if (response.success && response.data?.matches) {
|
|
225
|
+
const matches = response.data.matches.map((m) => this.transformMatchFD(m));
|
|
226
|
+
return { success: true, data: matches, provider: 'football-data' };
|
|
227
|
+
}
|
|
228
|
+
return response;
|
|
229
|
+
}
|
|
230
|
+
async getStandings(leagueId, season) {
|
|
231
|
+
const response = await this.callAPI(`/competitions/${leagueId}/standings`);
|
|
232
|
+
if (response.success && response.data?.standings?.[0]?.table) {
|
|
233
|
+
const standings = response.data.standings[0].table.map((t) => this.transformTableEntryFD(t));
|
|
234
|
+
return { success: true, data: standings, provider: 'football-data' };
|
|
235
|
+
}
|
|
236
|
+
return response;
|
|
237
|
+
}
|
|
238
|
+
async getTeam(teamId) {
|
|
239
|
+
const response = await this.callAPI(`/teams/${teamId}`);
|
|
240
|
+
if (response.success && response.data) {
|
|
241
|
+
const team = this.transformTeamFD(response.data);
|
|
242
|
+
return { success: true, data: team, provider: 'football-data' };
|
|
243
|
+
}
|
|
244
|
+
return response;
|
|
245
|
+
}
|
|
246
|
+
async getPlayer(playerId) {
|
|
247
|
+
// Football-Data.org has limited player data
|
|
248
|
+
return {
|
|
249
|
+
success: false,
|
|
250
|
+
error: 'Player data not available via Football-Data.org',
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async searchTeams(query) {
|
|
254
|
+
// Football-Data.org doesn't have search endpoint
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
error: 'Search not available via Football-Data.org',
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
async searchPlayers(query) {
|
|
261
|
+
return {
|
|
262
|
+
success: false,
|
|
263
|
+
error: 'Search not available via Football-Data.org',
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
// ============= Transformation Helpers (Football-Data.org format) =============
|
|
267
|
+
transformMatchFD(data) {
|
|
268
|
+
return {
|
|
269
|
+
id: data.id.toString(),
|
|
270
|
+
homeTeam: this.transformTeamFD(data.homeTeam),
|
|
271
|
+
awayTeam: this.transformTeamFD(data.awayTeam),
|
|
272
|
+
league: {
|
|
273
|
+
id: data.competition.id.toString(),
|
|
274
|
+
name: data.competition.name,
|
|
275
|
+
country: data.competition.area?.name || 'Europe',
|
|
276
|
+
},
|
|
277
|
+
date: new Date(data.utcDate),
|
|
278
|
+
status: this.mapStatusFD(data.status),
|
|
279
|
+
score: data.score ? {
|
|
280
|
+
home: data.score.fullTime.homeTeam || 0,
|
|
281
|
+
away: data.score.fullTime.awayTeam || 0,
|
|
282
|
+
halfTime: data.score.halfTime.homeTeam !== null ? {
|
|
283
|
+
home: data.score.halfTime.homeTeam,
|
|
284
|
+
away: data.score.halfTime.awayTeam,
|
|
285
|
+
} : undefined,
|
|
286
|
+
} : undefined,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
transformTeamFD(data) {
|
|
290
|
+
return {
|
|
291
|
+
id: data.id.toString(),
|
|
292
|
+
name: data.name || data.shortName,
|
|
293
|
+
code: data.tla,
|
|
294
|
+
country: data.area?.name || '',
|
|
295
|
+
logo: data.crest,
|
|
296
|
+
founded: data.founded,
|
|
297
|
+
venue: data.venue,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
transformTableEntryFD(data) {
|
|
301
|
+
return {
|
|
302
|
+
position: data.position,
|
|
303
|
+
team: this.transformTeamFD(data.team),
|
|
304
|
+
played: data.playedGames,
|
|
305
|
+
won: data.won,
|
|
306
|
+
drawn: data.draw,
|
|
307
|
+
lost: data.lost,
|
|
308
|
+
goalsFor: data.goalsFor,
|
|
309
|
+
goalsAgainst: data.goalsAgainst,
|
|
310
|
+
goalDifference: data.goalDifference,
|
|
311
|
+
points: data.points,
|
|
312
|
+
homeRecord: data.homeGames ? {
|
|
313
|
+
played: data.homeGames.playedGames,
|
|
314
|
+
won: data.homeGames.won,
|
|
315
|
+
drawn: data.homeGames.draw,
|
|
316
|
+
lost: data.homeGames.lost,
|
|
317
|
+
goalsFor: data.homeGames.goalsFor,
|
|
318
|
+
against: data.homeGames.goalsAgainst,
|
|
319
|
+
} : undefined,
|
|
320
|
+
awayRecord: data.awayGames ? {
|
|
321
|
+
played: data.awayGames.playedGames,
|
|
322
|
+
won: data.awayGames.won,
|
|
323
|
+
drawn: data.awayGames.draw,
|
|
324
|
+
lost: data.awayGames.lost,
|
|
325
|
+
goalsFor: data.awayGames.goalsFor,
|
|
326
|
+
against: data.awayGames.goalsAgainst,
|
|
327
|
+
} : undefined,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
mapStatusFD(status) {
|
|
331
|
+
const s = status.toUpperCase();
|
|
332
|
+
if (s === 'IN_PLAY' || s === 'PAUSED')
|
|
333
|
+
return 'live';
|
|
334
|
+
if (s === 'FINISHED')
|
|
335
|
+
return 'finished';
|
|
336
|
+
if (s === 'POSTPONED')
|
|
337
|
+
return 'postponed';
|
|
338
|
+
if (s === 'CANCELLED')
|
|
339
|
+
return 'cancelled';
|
|
340
|
+
return 'scheduled';
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* TheSportsDB Provider
|
|
345
|
+
* Documentation: https://www.thesportsdb.com/api.php
|
|
346
|
+
*/
|
|
347
|
+
export class SportsDBProvider extends APIProviderBase {
|
|
348
|
+
constructor() {
|
|
349
|
+
super('sports-db', API_CONFIG.SPORTS_DB_KEY, API_CONFIG.SPORTS_DB_BASE, API_CONFIG.RATE_LIMITS.SPORTS_DB);
|
|
350
|
+
}
|
|
351
|
+
getAuthHeaders() {
|
|
352
|
+
// TheSportsDB uses API key in URL, not headers
|
|
353
|
+
return {};
|
|
354
|
+
}
|
|
355
|
+
transformResponse(data) {
|
|
356
|
+
return data;
|
|
357
|
+
}
|
|
358
|
+
async getMatch(matchId) {
|
|
359
|
+
const url = `/lookupfixture.php?id=${matchId}`;
|
|
360
|
+
const response = await this.callAPI(url);
|
|
361
|
+
if (response.success && response.data?.[0]) {
|
|
362
|
+
const match = this.transformMatchDB(response.data[0]);
|
|
363
|
+
return { success: true, data: match, provider: 'sports-db' };
|
|
364
|
+
}
|
|
365
|
+
return response;
|
|
366
|
+
}
|
|
367
|
+
async getLiveMatches() {
|
|
368
|
+
// TheSportsDB doesn't have a good live scores endpoint
|
|
369
|
+
return {
|
|
370
|
+
success: false,
|
|
371
|
+
error: 'Live scores not available via TheSportsDB',
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
async getStandings(leagueId) {
|
|
375
|
+
const url = `/lookuptable.php?l=${leagueId}`;
|
|
376
|
+
const response = await this.callAPI(url);
|
|
377
|
+
if (response.success && response.data) {
|
|
378
|
+
const standings = response.data.map((t) => this.transformTableEntryDB(t));
|
|
379
|
+
return { success: true, data: standings, provider: 'sports-db' };
|
|
380
|
+
}
|
|
381
|
+
return response;
|
|
382
|
+
}
|
|
383
|
+
async getTeam(teamId) {
|
|
384
|
+
const url = `/lookupteam.php?id=${teamId}`;
|
|
385
|
+
const response = await this.callAPI(url);
|
|
386
|
+
if (response.success && response.data?.[0]) {
|
|
387
|
+
const team = this.transformTeamDB(response.data[0]);
|
|
388
|
+
return { success: true, data: team, provider: 'sports-db' };
|
|
389
|
+
}
|
|
390
|
+
return response;
|
|
391
|
+
}
|
|
392
|
+
async getPlayer(playerId) {
|
|
393
|
+
const url = `/lookupplayer.php?id=${playerId}`;
|
|
394
|
+
const response = await this.callAPI(url);
|
|
395
|
+
if (response.success && response.data?.[0]) {
|
|
396
|
+
const player = this.transformPlayerDB(response.data[0]);
|
|
397
|
+
return { success: true, data: player, provider: 'sports-db' };
|
|
398
|
+
}
|
|
399
|
+
return response;
|
|
400
|
+
}
|
|
401
|
+
async searchTeams(query) {
|
|
402
|
+
const url = `/searchteams.php?t=${encodeURIComponent(query)}`;
|
|
403
|
+
const response = await this.callAPI(url);
|
|
404
|
+
if (response.success && response.data) {
|
|
405
|
+
const teams = response.data.map((t) => this.transformTeamDB(t));
|
|
406
|
+
return { success: true, data: teams, provider: 'sports-db' };
|
|
407
|
+
}
|
|
408
|
+
return response;
|
|
409
|
+
}
|
|
410
|
+
async searchPlayers(query) {
|
|
411
|
+
const url = `/searchplayers.php?p=${encodeURIComponent(query)}`;
|
|
412
|
+
const response = await this.callAPI(url);
|
|
413
|
+
if (response.success && response.data) {
|
|
414
|
+
const players = response.data.map((p) => this.transformPlayerDB(p));
|
|
415
|
+
return { success: true, data: players, provider: 'sports-db' };
|
|
416
|
+
}
|
|
417
|
+
return response;
|
|
418
|
+
}
|
|
419
|
+
// ============= Transformation Helpers (TheSportsDB format) =============
|
|
420
|
+
transformMatchDB(data) {
|
|
421
|
+
return {
|
|
422
|
+
id: data.idEvent,
|
|
423
|
+
homeTeam: this.transformTeamDB({ idTeam: data.idHomeTeam, strTeam: data.strHomeTeam }),
|
|
424
|
+
awayTeam: this.transformTeamDB({ idTeam: data.idAwayTeam, strTeam: data.strAwayTeam }),
|
|
425
|
+
league: {
|
|
426
|
+
id: data.idLeague,
|
|
427
|
+
name: data.strLeague,
|
|
428
|
+
country: data.strCountry || '',
|
|
429
|
+
},
|
|
430
|
+
date: new Date(data.dateEvent + 'T' + data.strTime),
|
|
431
|
+
status: data.strStatus === 'Match Finished' ? 'finished' : 'scheduled',
|
|
432
|
+
score: {
|
|
433
|
+
home: parseInt(data.intHomeScore) || 0,
|
|
434
|
+
away: parseInt(data.intAwayScore) || 0,
|
|
435
|
+
},
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
transformTeamDB(data) {
|
|
439
|
+
return {
|
|
440
|
+
id: data.idTeam?.toString() || '',
|
|
441
|
+
name: data.strTeam || '',
|
|
442
|
+
code: data.strTeamShort,
|
|
443
|
+
country: data.strCountry || '',
|
|
444
|
+
logo: data.strTeamBadge,
|
|
445
|
+
founded: data.intFormedYear ? parseInt(data.intFormedYear) : undefined,
|
|
446
|
+
venue: data.strStadium,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
transformPlayerDB(data) {
|
|
450
|
+
return {
|
|
451
|
+
id: data.idPlayer?.toString() || '',
|
|
452
|
+
name: data.strPlayer || '',
|
|
453
|
+
age: data.dateBorn
|
|
454
|
+
? new Date().getFullYear() - new Date(data.dateBorn).getFullYear()
|
|
455
|
+
: undefined,
|
|
456
|
+
nationality: data.strNationality || '',
|
|
457
|
+
position: this.mapPositionDB(data.strPosition),
|
|
458
|
+
photo: data.strCutout,
|
|
459
|
+
team: data.strTeam
|
|
460
|
+
? this.transformTeamDB({ strTeam: data.strTeam })
|
|
461
|
+
: undefined,
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
transformTableEntryDB(data) {
|
|
465
|
+
return {
|
|
466
|
+
position: parseInt(data.intRank),
|
|
467
|
+
team: this.transformTeamDB(data),
|
|
468
|
+
played: parseInt(data.intPlayed),
|
|
469
|
+
won: parseInt(data.intWin),
|
|
470
|
+
drawn: parseInt(data.intDraw),
|
|
471
|
+
lost: parseInt(data.intLoss),
|
|
472
|
+
goalsFor: parseInt(data.intGoalsFor),
|
|
473
|
+
goalsAgainst: parseInt(data.intGoalsAgainst),
|
|
474
|
+
goalDifference: parseInt(data.intGoalDifference),
|
|
475
|
+
points: parseInt(data.intPoints),
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
mapPositionDB(pos) {
|
|
479
|
+
if (!pos)
|
|
480
|
+
return 'SUB';
|
|
481
|
+
const p = pos.toLowerCase();
|
|
482
|
+
if (p.includes('goalkeeper') || p === 'gk')
|
|
483
|
+
return 'GK';
|
|
484
|
+
if (p.includes('defender') || p === 'df')
|
|
485
|
+
return 'DF';
|
|
486
|
+
if (p.includes('midfielder') || p === 'mf')
|
|
487
|
+
return 'MF';
|
|
488
|
+
if (p.includes('forward') || p === 'fw')
|
|
489
|
+
return 'FW';
|
|
490
|
+
return 'SUB';
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Create a fallback provider with all available API providers
|
|
495
|
+
*/
|
|
496
|
+
export function createAPIProvider() {
|
|
497
|
+
const providers = [];
|
|
498
|
+
// Add API-Football if key is available
|
|
499
|
+
if (API_CONFIG.API_FOOTBALL_KEY) {
|
|
500
|
+
providers.push(new APIFootballProvider());
|
|
501
|
+
logger.info('API-Football provider initialized');
|
|
502
|
+
}
|
|
503
|
+
// Add Football-Data.org if key is available
|
|
504
|
+
if (API_CONFIG.FOOTBALL_DATA_KEY) {
|
|
505
|
+
providers.push(new FootballDataProvider());
|
|
506
|
+
logger.info('Football-Data.org provider initialized');
|
|
507
|
+
}
|
|
508
|
+
// Add TheSportsDB if key is available
|
|
509
|
+
if (API_CONFIG.SPORTS_DB_KEY) {
|
|
510
|
+
providers.push(new SportsDBProvider());
|
|
511
|
+
logger.info('TheSportsDB provider initialized');
|
|
512
|
+
}
|
|
513
|
+
if (providers.length === 0) {
|
|
514
|
+
logger.warn('No API providers configured. Set API_FOOTBALL_KEY, FOOTBALL_DATA_KEY, or SPORTS_DB_KEY environment variables.');
|
|
515
|
+
}
|
|
516
|
+
return new FallbackProvider(providers);
|
|
517
|
+
}
|