nhl-api-ts 0.0.0-stage → 0.1.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.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -2
  3. package/dist/api/edge.d.mts +179 -0
  4. package/dist/api/edge.mjs +184 -0
  5. package/dist/api/game-center.d.mts +83 -0
  6. package/dist/api/game-center.mjs +74 -0
  7. package/dist/api/helpers.d.mts +46 -0
  8. package/dist/api/helpers.mjs +106 -0
  9. package/dist/api/misc.d.mts +40 -0
  10. package/dist/api/misc.mjs +43 -0
  11. package/dist/api/players.d.mts +27 -0
  12. package/dist/api/players.mjs +18 -0
  13. package/dist/api/query/builder.d.mts +20 -0
  14. package/dist/api/query/builder.mjs +28 -0
  15. package/dist/api/query/errors.d.mts +3 -0
  16. package/dist/api/query/errors.mjs +6 -0
  17. package/dist/api/query/filters/base.d.mts +4 -0
  18. package/dist/api/query/filters/base.mjs +2 -0
  19. package/dist/api/query/filters/decision.d.mts +13 -0
  20. package/dist/api/query/filters/decision.mjs +26 -0
  21. package/dist/api/query/filters/draft.d.mts +15 -0
  22. package/dist/api/query/filters/draft.mjs +27 -0
  23. package/dist/api/query/filters/experience.d.mts +9 -0
  24. package/dist/api/query/filters/experience.mjs +17 -0
  25. package/dist/api/query/filters/franchise.d.mts +9 -0
  26. package/dist/api/query/filters/franchise.mjs +15 -0
  27. package/dist/api/query/filters/game-type.d.mts +10 -0
  28. package/dist/api/query/filters/game-type.mjs +16 -0
  29. package/dist/api/query/filters/goalie-sorts.d.mts +3 -0
  30. package/dist/api/query/filters/goalie-sorts.mjs +55 -0
  31. package/dist/api/query/filters/home-road.d.mts +9 -0
  32. package/dist/api/query/filters/home-road.mjs +16 -0
  33. package/dist/api/query/filters/index.d.mts +14 -0
  34. package/dist/api/query/filters/index.mjs +14 -0
  35. package/dist/api/query/filters/nationality.d.mts +12 -0
  36. package/dist/api/query/filters/nationality.mjs +19 -0
  37. package/dist/api/query/filters/opponent.d.mts +10 -0
  38. package/dist/api/query/filters/opponent.mjs +16 -0
  39. package/dist/api/query/filters/position.d.mts +16 -0
  40. package/dist/api/query/filters/position.mjs +28 -0
  41. package/dist/api/query/filters/season.d.mts +14 -0
  42. package/dist/api/query/filters/season.mjs +24 -0
  43. package/dist/api/query/filters/shoot-catch.d.mts +9 -0
  44. package/dist/api/query/filters/shoot-catch.mjs +16 -0
  45. package/dist/api/query/filters/status.d.mts +20 -0
  46. package/dist/api/query/filters/status.mjs +28 -0
  47. package/dist/api/query/filters.d.mts +93 -0
  48. package/dist/api/query/filters.mjs +118 -0
  49. package/dist/api/query/index.d.mts +4 -0
  50. package/dist/api/query/index.mjs +4 -0
  51. package/dist/api/query/sorting/goalie-sorts.d.mts +6 -0
  52. package/dist/api/query/sorting/goalie-sorts.mjs +59 -0
  53. package/dist/api/query/sorting/sorting-options.d.mts +11 -0
  54. package/dist/api/query/sorting/sorting-options.mjs +93 -0
  55. package/dist/api/schedule.d.mts +116 -0
  56. package/dist/api/schedule.mjs +131 -0
  57. package/dist/api/standings.d.mts +28 -0
  58. package/dist/api/standings.mjs +38 -0
  59. package/dist/api/stats.d.mts +148 -0
  60. package/dist/api/stats.mjs +148 -0
  61. package/dist/api/teams.d.mts +58 -0
  62. package/dist/api/teams.mjs +91 -0
  63. package/dist/cli/colors.d.mts +14 -0
  64. package/dist/cli/colors.mjs +13 -0
  65. package/dist/cli/commands.d.mts +27 -0
  66. package/dist/cli/commands.mjs +695 -0
  67. package/dist/cli/run.d.mts +9 -0
  68. package/dist/cli/run.mjs +313 -0
  69. package/dist/cli.d.mts +2 -0
  70. package/dist/cli.mjs +13 -0
  71. package/dist/config.d.mts +20 -0
  72. package/dist/config.mjs +4 -0
  73. package/dist/context.d.mts +6 -0
  74. package/dist/context.mjs +1 -0
  75. package/dist/errors.d.mts +35 -0
  76. package/dist/errors.mjs +49 -0
  77. package/dist/http-client.d.mts +27 -0
  78. package/dist/http-client.mjs +95 -0
  79. package/dist/index.d.mts +21 -0
  80. package/dist/index.mjs +15 -0
  81. package/dist/logging.d.mts +14 -0
  82. package/dist/logging.mjs +13 -0
  83. package/dist/nhl-client.d.mts +97 -0
  84. package/dist/nhl-client.mjs +40 -0
  85. package/dist/utils.d.mts +5 -0
  86. package/dist/utils.mjs +3 -0
  87. package/package.json +77 -3
@@ -0,0 +1,11 @@
1
+ export interface SortExpr {
2
+ property: string;
3
+ direction: 'ASC' | 'DESC' | 'ASC_CI' | 'DESC_CI' | (string & {});
4
+ }
5
+ /** Skater report types that have a default sort configured. */
6
+ export declare const SKATER_REPORT_TYPES: string[];
7
+ /**
8
+ * Default sort criteria for a skater stats report. Falls back to the skater
9
+ * summary sort for unknown report types.
10
+ */
11
+ export declare function defaultSortForReport(report: string): SortExpr[];
@@ -0,0 +1,93 @@
1
+ const skaterSummaryDefaultSorting = [
2
+ { property: 'points', direction: 'DESC' },
3
+ { property: 'gamesPlayed', direction: 'ASC' },
4
+ { property: 'playerId', direction: 'ASC' },
5
+ ];
6
+ const defaultSortingByReport = {
7
+ summary: skaterSummaryDefaultSorting,
8
+ bios: [
9
+ { property: 'lastName', direction: 'ASC_CI' },
10
+ { property: 'skaterFullName', direction: 'ASC_CI' },
11
+ { property: 'playerId', direction: 'ASC' },
12
+ ],
13
+ faceoffpercentages: [
14
+ { property: 'totalFaceoffs', direction: 'DESC' },
15
+ { property: 'playerId', direction: 'ASC' },
16
+ ],
17
+ faceoffwins: [
18
+ { property: 'totalFaceoffWins', direction: 'DESC' },
19
+ { property: 'faceoffWinPct', direction: 'DESC' },
20
+ { property: 'playerId', direction: 'ASC' },
21
+ ],
22
+ goalsForAgainst: [
23
+ { property: 'evenStrengthGoalDifference', direction: 'DESC' },
24
+ { property: 'playerId', direction: 'ASC' },
25
+ ],
26
+ realtime: [
27
+ { property: 'hits', direction: 'DESC' },
28
+ { property: 'playerId', direction: 'ASC' },
29
+ ],
30
+ penalties: [
31
+ { property: 'penaltyMinutes', direction: 'DESC' },
32
+ { property: 'playerId', direction: 'ASC' },
33
+ ],
34
+ penaltykill: [
35
+ { property: 'shTimeOnIce', direction: 'DESC' },
36
+ { property: 'playerId', direction: 'ASC' },
37
+ ],
38
+ penaltyShots: [
39
+ { property: 'penaltyShotsGoals', direction: 'DESC' },
40
+ { property: 'playerId', direction: 'ASC' },
41
+ ],
42
+ powerplay: [
43
+ { property: 'ppTimeOnIce', direction: 'DESC' },
44
+ { property: 'playerId', direction: 'ASC' },
45
+ ],
46
+ puckPossessions: [
47
+ { property: 'satPct', direction: 'DESC' },
48
+ { property: 'playerId', direction: 'ASC' },
49
+ ],
50
+ summaryshooting: [
51
+ { property: 'satTotal', direction: 'DESC' },
52
+ { property: 'usatTotal', direction: 'DESC' },
53
+ { property: 'playerId', direction: 'ASC' },
54
+ ],
55
+ percentages: [
56
+ { property: 'satPercentage', direction: 'DESC' },
57
+ { property: 'playerId', direction: 'ASC' },
58
+ ],
59
+ scoringRates: [
60
+ { property: 'pointsPer605v5', direction: 'DESC' },
61
+ { property: 'goalsPer605v5', direction: 'DESC' },
62
+ { property: 'playerId', direction: 'ASC' },
63
+ ],
64
+ scoringpergame: [
65
+ { property: 'pointsPerGame', direction: 'DESC' },
66
+ { property: 'goalsPerGame', direction: 'DESC' },
67
+ { property: 'playerId', direction: 'ASC' },
68
+ ],
69
+ shootout: [
70
+ { property: 'shootoutGoals', direction: 'DESC' },
71
+ { property: 'playerId', direction: 'ASC' },
72
+ ],
73
+ shottype: [
74
+ { property: 'shootingPct', direction: 'DESC' },
75
+ { property: 'shootingPctBat', direction: 'DESC' },
76
+ { property: 'playerId', direction: 'ASC' },
77
+ ],
78
+ timeonice: [
79
+ { property: 'timeOnIce', direction: 'DESC' },
80
+ { property: 'playerId', direction: 'ASC' },
81
+ ],
82
+ };
83
+ /** Skater report types that have a default sort configured. */
84
+ export const SKATER_REPORT_TYPES = Object.keys(defaultSortingByReport);
85
+ /**
86
+ * Default sort criteria for a skater stats report. Falls back to the skater
87
+ * summary sort for unknown report types.
88
+ */
89
+ export function defaultSortForReport(report) {
90
+ return ((Object.hasOwn(defaultSortingByReport, report)
91
+ ? defaultSortingByReport[report]
92
+ : undefined) ?? skaterSummaryDefaultSorting);
93
+ }
@@ -0,0 +1,116 @@
1
+ import type { Context } from '#src/context.mjs';
2
+ import type { Id, JsonObject } from '#src/utils.mjs';
3
+ /**
4
+ * Parses and normalizes a YYYY-MM-DD date: single-digit months/days are
5
+ * accepted ("2024-10-9" -> "2024-10-09") and impossible dates are rejected.
6
+ */
7
+ export declare function normalizeDate(date: string): string;
8
+ export interface DailySchedule {
9
+ nextStartDate: string | null;
10
+ previousStartDate: string | null;
11
+ date: string;
12
+ oddsPartners: JsonObject[] | null;
13
+ games?: JsonObject[];
14
+ numberOfGames?: number;
15
+ }
16
+ /**
17
+ * Gets NHL schedule for a specific date.
18
+ *
19
+ * @param params.date Date in YYYY-MM-DD format. Defaults to today.
20
+ * @throws RangeError If the date is not a valid YYYY-MM-DD date
21
+ * @example await client.schedule.dailySchedule({ date: '2024-10-09' })
22
+ */
23
+ export declare const dailySchedule: (ctx: Context, { date }?: {
24
+ date?: string;
25
+ }) => Promise<DailySchedule>;
26
+ /**
27
+ * Gets NHL schedule for a week starting from the specified date.
28
+ *
29
+ * @param params.date Date in YYYY-MM-DD format. Defaults to "now".
30
+ * @example https://api-web.nhle.com/v1/schedule/2024-10-09
31
+ */
32
+ export declare const weeklySchedule: (ctx: Context, { date }?: {
33
+ date?: string;
34
+ }) => Promise<JsonObject>;
35
+ /**
36
+ * Gets monthly schedule for a specified team.
37
+ *
38
+ * @param params.teamAbbr Team abbreviation, e.g. BUF, TOR
39
+ * @param params.month Month in YYYY-MM format. Defaults to "now".
40
+ * @example https://api-web.nhle.com/v1/club-schedule/BUF/month/2023-11
41
+ */
42
+ export declare const teamMonthlySchedule: (ctx: Context, { teamAbbr, month }: {
43
+ teamAbbr: string;
44
+ month?: string;
45
+ }) => Promise<JsonObject[]>;
46
+ /**
47
+ * Gets weekly schedule for a specified team.
48
+ *
49
+ * @param params.teamAbbr Team abbreviation, e.g. BUF, TOR
50
+ * @param params.date Date in YYYY-MM-DD format. Defaults to "now".
51
+ * @example https://api-web.nhle.com/v1/club-schedule/BUF/week/2024-02-10
52
+ */
53
+ export declare const teamWeeklySchedule: (ctx: Context, { teamAbbr, date }: {
54
+ teamAbbr: string;
55
+ date?: string;
56
+ }) => Promise<JsonObject[]>;
57
+ /**
58
+ * Gets the full season schedule for a specified team.
59
+ *
60
+ * @param params.teamAbbr Team abbreviation, e.g. BUF, TOR
61
+ * @param params.season Season in YYYYYYYY format, e.g. 20232024
62
+ * @example https://api-web.nhle.com/v1/club-schedule-season/BUF/20232024
63
+ */
64
+ export declare const teamSeasonSchedule: (ctx: Context, { teamAbbr, season }: {
65
+ teamAbbr: string;
66
+ season: Id;
67
+ }) => Promise<JsonObject>;
68
+ /**
69
+ * Gets the schedule in calendar format for a specified date.
70
+ *
71
+ * @param params.date Date in YYYY-MM-DD format
72
+ * @example https://api-web.nhle.com/v1/schedule-calendar/2023-11-08
73
+ */
74
+ export declare const calendarSchedule: (ctx: Context, { date }: {
75
+ date: string;
76
+ }) => Promise<JsonObject>;
77
+ /**
78
+ * Gets all playoff series information up to the current round.
79
+ *
80
+ * @param params.season Season in YYYYYYYY format, e.g. 20232024
81
+ * @example https://api-web.nhle.com/v1/playoff-series/carousel/20232024
82
+ */
83
+ export declare const playoffCarousel: (ctx: Context, { season }: {
84
+ season: Id;
85
+ }) => Promise<JsonObject>;
86
+ /**
87
+ * Returns the schedule and results for a specified playoff series matchup.
88
+ *
89
+ * @param params.season Season in YYYYYYYY format, e.g. 20232024
90
+ * @param params.series Series letter, e.g. "a" (first round) through "o" (final)
91
+ * @example https://api-web.nhle.com/v1/schedule/playoff-series/20232024/a
92
+ */
93
+ export declare const playoffSeriesSchedule: (ctx: Context, { season, series }: {
94
+ season: Id;
95
+ series: string;
96
+ }) => Promise<JsonObject>;
97
+ /**
98
+ * Returns the full playoff bracket for a given year.
99
+ *
100
+ * @param params.year Year the playoffs took place, e.g. 2024
101
+ * @example https://api-web.nhle.com/v1/playoff-bracket/2024
102
+ */
103
+ export declare const playoffBracket: (ctx: Context, { year }: {
104
+ year: Id;
105
+ }) => Promise<JsonObject>;
106
+ export declare const scheduleApi: {
107
+ readonly dailySchedule: typeof dailySchedule;
108
+ readonly weeklySchedule: typeof weeklySchedule;
109
+ readonly teamMonthlySchedule: typeof teamMonthlySchedule;
110
+ readonly teamWeeklySchedule: typeof teamWeeklySchedule;
111
+ readonly teamSeasonSchedule: typeof teamSeasonSchedule;
112
+ readonly calendarSchedule: typeof calendarSchedule;
113
+ readonly playoffCarousel: typeof playoffCarousel;
114
+ readonly playoffSeriesSchedule: typeof playoffSeriesSchedule;
115
+ readonly playoffBracket: typeof playoffBracket;
116
+ };
@@ -0,0 +1,131 @@
1
+ import { Endpoint } from '#src/http-client.mjs';
2
+ const pad = (value, width = 2) => String(value).padStart(width, '0');
3
+ /** Today's date (local time) as YYYY-MM-DD. */
4
+ function today() {
5
+ const now = new Date();
6
+ return `${pad(now.getFullYear(), 4)}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
7
+ }
8
+ /**
9
+ * Parses and normalizes a YYYY-MM-DD date: single-digit months/days are
10
+ * accepted ("2024-10-9" -> "2024-10-09") and impossible dates are rejected.
11
+ */
12
+ export function normalizeDate(date) {
13
+ const match = /^(\d{4})-(1[0-2]|0[1-9]|[1-9])-(3[01]|[12]\d|0[1-9]|[1-9]| [1-9])$/.exec(date);
14
+ if (!match) {
15
+ throw new RangeError('Invalid date format. Please use YYYY-MM-DD.');
16
+ }
17
+ const [year, month, day] = match.slice(1).map((part) => Number(part.trim()));
18
+ const parsed = new Date(0);
19
+ parsed.setUTCFullYear(year, month - 1, day);
20
+ if (parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day) {
21
+ throw new RangeError('Invalid date format. Please use YYYY-MM-DD.');
22
+ }
23
+ return `${pad(year, 4)}-${pad(month)}-${pad(day)}`;
24
+ }
25
+ /**
26
+ * Gets NHL schedule for a specific date.
27
+ *
28
+ * @param params.date Date in YYYY-MM-DD format. Defaults to today.
29
+ * @throws RangeError If the date is not a valid YYYY-MM-DD date
30
+ * @example await client.schedule.dailySchedule({ date: '2024-10-09' })
31
+ */
32
+ export const dailySchedule = async (ctx, { date } = {}) => {
33
+ const resolvedDate = date ? normalizeDate(date) : today();
34
+ const scheduleData = await (await ctx.get(Endpoint.API_WEB_V1, `schedule/${resolvedDate}`)).json();
35
+ const responsePayload = {
36
+ nextStartDate: scheduleData.nextStartDate ?? null,
37
+ previousStartDate: scheduleData.previousStartDate ?? null,
38
+ date: resolvedDate,
39
+ oddsPartners: scheduleData.oddsPartners ?? null,
40
+ };
41
+ const gameWeek = scheduleData.gameWeek ?? [];
42
+ const matchingDay = gameWeek.find((day) => day.date === resolvedDate);
43
+ if (matchingDay) {
44
+ const games = matchingDay.games ?? [];
45
+ responsePayload.games = games;
46
+ responsePayload.numberOfGames = games.length;
47
+ }
48
+ return responsePayload;
49
+ };
50
+ /**
51
+ * Gets NHL schedule for a week starting from the specified date.
52
+ *
53
+ * @param params.date Date in YYYY-MM-DD format. Defaults to "now".
54
+ * @example https://api-web.nhle.com/v1/schedule/2024-10-09
55
+ */
56
+ export const weeklySchedule = async (ctx, { date } = {}) => {
57
+ const res = date ? date : 'now';
58
+ return (await ctx.get(Endpoint.API_WEB_V1, `schedule/${res}`)).json();
59
+ };
60
+ /**
61
+ * Gets monthly schedule for a specified team.
62
+ *
63
+ * @param params.teamAbbr Team abbreviation, e.g. BUF, TOR
64
+ * @param params.month Month in YYYY-MM format. Defaults to "now".
65
+ * @example https://api-web.nhle.com/v1/club-schedule/BUF/month/2023-11
66
+ */
67
+ export const teamMonthlySchedule = async (ctx, { teamAbbr, month }) => {
68
+ const resource = `club-schedule/${teamAbbr}/month/${month ? month : 'now'}`;
69
+ const response = await (await ctx.get(Endpoint.API_WEB_V1, resource)).json();
70
+ return response.games ?? [];
71
+ };
72
+ /**
73
+ * Gets weekly schedule for a specified team.
74
+ *
75
+ * @param params.teamAbbr Team abbreviation, e.g. BUF, TOR
76
+ * @param params.date Date in YYYY-MM-DD format. Defaults to "now".
77
+ * @example https://api-web.nhle.com/v1/club-schedule/BUF/week/2024-02-10
78
+ */
79
+ export const teamWeeklySchedule = async (ctx, { teamAbbr, date }) => {
80
+ const resource = `club-schedule/${teamAbbr}/week/${date ? date : 'now'}`;
81
+ const response = await (await ctx.get(Endpoint.API_WEB_V1, resource)).json();
82
+ return response.games ?? [];
83
+ };
84
+ /**
85
+ * Gets the full season schedule for a specified team.
86
+ *
87
+ * @param params.teamAbbr Team abbreviation, e.g. BUF, TOR
88
+ * @param params.season Season in YYYYYYYY format, e.g. 20232024
89
+ * @example https://api-web.nhle.com/v1/club-schedule-season/BUF/20232024
90
+ */
91
+ export const teamSeasonSchedule = async (ctx, { teamAbbr, season }) => (await ctx.get(Endpoint.API_WEB_V1, `club-schedule-season/${teamAbbr}/${season}`)).json();
92
+ /**
93
+ * Gets the schedule in calendar format for a specified date.
94
+ *
95
+ * @param params.date Date in YYYY-MM-DD format
96
+ * @example https://api-web.nhle.com/v1/schedule-calendar/2023-11-08
97
+ */
98
+ export const calendarSchedule = async (ctx, { date }) => (await ctx.get(Endpoint.API_WEB_V1, `schedule-calendar/${date}`)).json();
99
+ /**
100
+ * Gets all playoff series information up to the current round.
101
+ *
102
+ * @param params.season Season in YYYYYYYY format, e.g. 20232024
103
+ * @example https://api-web.nhle.com/v1/playoff-series/carousel/20232024
104
+ */
105
+ export const playoffCarousel = async (ctx, { season }) => (await ctx.get(Endpoint.API_WEB_V1, `playoff-series/carousel/${season}`)).json();
106
+ /**
107
+ * Returns the schedule and results for a specified playoff series matchup.
108
+ *
109
+ * @param params.season Season in YYYYYYYY format, e.g. 20232024
110
+ * @param params.series Series letter, e.g. "a" (first round) through "o" (final)
111
+ * @example https://api-web.nhle.com/v1/schedule/playoff-series/20232024/a
112
+ */
113
+ export const playoffSeriesSchedule = async (ctx, { season, series }) => (await ctx.get(Endpoint.API_WEB_V1, `schedule/playoff-series/${season}/${series}`)).json();
114
+ /**
115
+ * Returns the full playoff bracket for a given year.
116
+ *
117
+ * @param params.year Year the playoffs took place, e.g. 2024
118
+ * @example https://api-web.nhle.com/v1/playoff-bracket/2024
119
+ */
120
+ export const playoffBracket = async (ctx, { year }) => (await ctx.get(Endpoint.API_WEB_V1, `playoff-bracket/${year}`)).json();
121
+ export const scheduleApi = {
122
+ dailySchedule,
123
+ weeklySchedule,
124
+ teamMonthlySchedule,
125
+ teamWeeklySchedule,
126
+ teamSeasonSchedule,
127
+ calendarSchedule,
128
+ playoffCarousel,
129
+ playoffSeriesSchedule,
130
+ playoffBracket,
131
+ };
@@ -0,0 +1,28 @@
1
+ import type { Context } from '#src/context.mjs';
2
+ import type { Id, JsonObject } from '#src/utils.mjs';
3
+ /**
4
+ * Gets NHL league standings for a specific date or season.
5
+ *
6
+ * If `season` is given, the standings from the end of that season are
7
+ * returned (overrides `date`). Otherwise standings for `date` or today.
8
+ *
9
+ * @param params.date Date in YYYY-MM-DD format
10
+ * @param params.season Season in YYYYYYYY format, e.g. 20222023
11
+ * @throws RangeError If the season id is not found in the standings manifest
12
+ * @example await client.standings.leagueStandings({ season: '20222023' })
13
+ */
14
+ export declare const leagueStandings: (ctx: Context, { date, season }?: {
15
+ date?: string;
16
+ season?: Id;
17
+ }) => Promise<JsonObject>;
18
+ /**
19
+ * Gets metadata for every historical NHL season: start/end dates and which
20
+ * standings rules (conferences, divisions, wildcard, ties...) were in use.
21
+ *
22
+ * @example https://api-web.nhle.com/v1/standings-season
23
+ */
24
+ export declare const seasonStandingManifest: (ctx: Context) => Promise<JsonObject[]>;
25
+ export declare const standingsApi: {
26
+ readonly leagueStandings: typeof leagueStandings;
27
+ readonly seasonStandingManifest: typeof seasonStandingManifest;
28
+ };
@@ -0,0 +1,38 @@
1
+ import { Endpoint } from '#src/http-client.mjs';
2
+ /**
3
+ * Gets NHL league standings for a specific date or season.
4
+ *
5
+ * If `season` is given, the standings from the end of that season are
6
+ * returned (overrides `date`). Otherwise standings for `date` or today.
7
+ *
8
+ * @param params.date Date in YYYY-MM-DD format
9
+ * @param params.season Season in YYYYYYYY format, e.g. 20222023
10
+ * @throws RangeError If the season id is not found in the standings manifest
11
+ * @example await client.standings.leagueStandings({ season: '20222023' })
12
+ */
13
+ export const leagueStandings = async (ctx, { date, season } = {}) => {
14
+ if (season) {
15
+ const seasons = await seasonStandingManifest(ctx);
16
+ const seasonData = seasons.find((seasonEntry) => seasonEntry.id === Number(season));
17
+ if (!seasonData) {
18
+ throw new RangeError(`Invalid Season Id ${season}`);
19
+ }
20
+ date = seasonData.standingsEnd;
21
+ }
22
+ const res = date ? date : 'now';
23
+ return (await ctx.get(Endpoint.API_WEB_V1, `standings/${res}`)).json();
24
+ };
25
+ /**
26
+ * Gets metadata for every historical NHL season: start/end dates and which
27
+ * standings rules (conferences, divisions, wildcard, ties...) were in use.
28
+ *
29
+ * @example https://api-web.nhle.com/v1/standings-season
30
+ */
31
+ export const seasonStandingManifest = async (ctx) => {
32
+ const response = await (await ctx.get(Endpoint.API_WEB_V1, 'standings-season')).json();
33
+ return response.seasons ?? [];
34
+ };
35
+ export const standingsApi = {
36
+ leagueStandings,
37
+ seasonStandingManifest,
38
+ };
@@ -0,0 +1,148 @@
1
+ import type { QueryContext } from '#src/api/query/builder.mjs';
2
+ import { type SortExpr } from '#src/api/query/sorting/sorting-options.mjs';
3
+ import type { Context } from '#src/context.mjs';
4
+ import type { Id, JsonObject } from '#src/utils.mjs';
5
+ export interface TeamSummaryParams {
6
+ /** Start season in YYYYYYYY format, e.g. 20202021 */
7
+ startSeason: Id;
8
+ /** End season in YYYYYYYY format, e.g. 20232024 */
9
+ endSeason: Id;
10
+ /** 1=Preseason, 2=Regular season (default), 3=Playoffs */
11
+ gameTypeId?: number;
12
+ /** Game-level stats rather than season-level. Defaults to false. */
13
+ isGame?: boolean;
14
+ /** Aggregate stats across the selected seasons. Defaults to false. */
15
+ isAggregate?: boolean;
16
+ /** Custom sort. Defaults to points DESC, wins DESC, teamId ASC. */
17
+ sortExpr?: SortExpr[];
18
+ /** Pagination offset. Defaults to 0. */
19
+ start?: number;
20
+ /** Max results. Defaults to 50. */
21
+ limit?: number;
22
+ /** Base fact filter. Defaults to "gamesPlayed>1". */
23
+ factCayenneExp?: string;
24
+ /** Overrides the generated cayenneExp filter entirely. */
25
+ defaultCayenneExp?: string;
26
+ }
27
+ export interface SkaterStatsSummaryParams {
28
+ startSeason: Id;
29
+ endSeason: Id;
30
+ /** Limit results to a franchise. */
31
+ franchiseId?: Id;
32
+ gameTypeId?: number;
33
+ aggregate?: boolean;
34
+ /** Custom sort. Defaults to points DESC, gamesPlayed ASC, playerId ASC. */
35
+ sortExpr?: SortExpr[];
36
+ start?: number;
37
+ /** Max results. Defaults to 25. */
38
+ limit?: number;
39
+ /** Base fact filter. Defaults to "gamesPlayed>=1". */
40
+ factCayenneExp?: string;
41
+ defaultCayenneExp?: string;
42
+ }
43
+ export interface SkaterStatsWithQueryContextParams {
44
+ /** Built with `buildQuery(filters)`. */
45
+ queryContext: QueryContext;
46
+ /**
47
+ * Report type, e.g. summary, bios, faceoffpercentages, faceoffwins,
48
+ * goalsForAgainst, realtime, penalties, penaltykill, penaltyShots,
49
+ * powerplay, puckPossessions, summaryshooting, percentages, scoringRates,
50
+ * scoringpergame, shootout, shottype, timeonice
51
+ */
52
+ reportType: string;
53
+ /** Custom sort. Defaults to the report type's default sort. */
54
+ sortExpr?: SortExpr[];
55
+ aggregate?: boolean;
56
+ start?: number;
57
+ limit?: number;
58
+ }
59
+ export interface GoalieStatsSummaryParams {
60
+ startSeason: Id;
61
+ /** Defaults to `startSeason`. */
62
+ endSeason?: Id;
63
+ /**
64
+ * Report type: summary (default), advanced, bios, daysrest, penaltyShots,
65
+ * savesByStrength, shootout, startedVsRelieved
66
+ */
67
+ statsType?: string;
68
+ gameTypeId?: number;
69
+ franchiseId?: Id;
70
+ aggregate?: boolean;
71
+ sortExpr?: SortExpr[];
72
+ start?: number;
73
+ limit?: number;
74
+ factCayenneExp?: string;
75
+ defaultCayenneExp?: string;
76
+ }
77
+ /**
78
+ * Gets all game types played by a team throughout their history.
79
+ *
80
+ * @param params.teamAbbr Team abbreviation, e.g. BUF, TOR
81
+ * @example https://api-web.nhle.com/v1/club-stats-season/TOR
82
+ */
83
+ export declare const gametypesPerSeasonDirectoryByTeam: (ctx: Context, { teamAbbr }: {
84
+ teamAbbr: string;
85
+ }) => Promise<JsonObject[]>;
86
+ /**
87
+ * Gets a player's career statistics and biographical information.
88
+ *
89
+ * @param params.playerId NHL player id, e.g. 8481528
90
+ * @example https://api-web.nhle.com/v1/player/8481528/landing
91
+ */
92
+ export declare const playerCareerStats: (ctx: Context, { playerId }: {
93
+ playerId: Id;
94
+ }) => Promise<JsonObject>;
95
+ /**
96
+ * Gets a player's game log for a specific season and game type.
97
+ *
98
+ * @param params.playerId NHL player id, e.g. 8481528
99
+ * @param params.seasonId Season in YYYYYYYY format, e.g. 20232024
100
+ * @param params.gameType 1=Preseason, 2=Regular season, 3=Playoffs
101
+ * @example https://api-web.nhle.com/v1/player/8481528/game-log/20232024/2
102
+ */
103
+ export declare const playerGameLog: (ctx: Context, { playerId, seasonId, gameType, }: {
104
+ playerId: Id;
105
+ seasonId: Id;
106
+ gameType: number;
107
+ }) => Promise<JsonObject[]>;
108
+ /**
109
+ * Retrieves team summary statistics across one or more seasons.
110
+ *
111
+ * @example await client.stats.teamSummary({ startSeason: '20232024', endSeason: '20232024' })
112
+ */
113
+ export declare const teamSummary: (ctx: Context, { startSeason, endSeason, gameTypeId, isGame, isAggregate, sortExpr, start, limit, factCayenneExp, defaultCayenneExp, }: TeamSummaryParams) => Promise<JsonObject[]>;
114
+ /**
115
+ * Gets simplified skater statistics summary for specified seasons and
116
+ * franchises.
117
+ *
118
+ * @example await client.stats.skaterStatsSummary({ startSeason: '20232024', endSeason: '20232024', franchiseId: 10 })
119
+ */
120
+ export declare const skaterStatsSummary: (ctx: Context, { startSeason, endSeason, franchiseId, gameTypeId, aggregate, sortExpr, start, limit, factCayenneExp, defaultCayenneExp, }: SkaterStatsSummaryParams) => Promise<JsonObject[]>;
121
+ /**
122
+ * Retrieves skater statistics using a query context and specified report
123
+ * type. Returns the full response (`{ data, total }`).
124
+ *
125
+ * @example
126
+ * const context = buildQuery([
127
+ * filter.season('20232024', '20232024'),
128
+ * filter.position(PositionTypes.CENTER),
129
+ * ]);
130
+ * await client.stats.skaterStatsWithQueryContext({ queryContext: context, reportType: 'summary' });
131
+ */
132
+ export declare const skaterStatsWithQueryContext: (ctx: Context, { queryContext, reportType, sortExpr, aggregate, start, limit, }: SkaterStatsWithQueryContextParams) => Promise<JsonObject>;
133
+ /**
134
+ * Retrieves goalie statistics with various filtering and aggregation
135
+ * options.
136
+ *
137
+ * @example await client.stats.goalieStatsSummary({ startSeason: '20232024', statsType: 'advanced' })
138
+ */
139
+ export declare const goalieStatsSummary: (ctx: Context, { startSeason, endSeason, statsType, gameTypeId, franchiseId, aggregate, sortExpr, start, limit, factCayenneExp, defaultCayenneExp, }: GoalieStatsSummaryParams) => Promise<JsonObject[]>;
140
+ export declare const statsApi: {
141
+ readonly gametypesPerSeasonDirectoryByTeam: typeof gametypesPerSeasonDirectoryByTeam;
142
+ readonly playerCareerStats: typeof playerCareerStats;
143
+ readonly playerGameLog: typeof playerGameLog;
144
+ readonly teamSummary: typeof teamSummary;
145
+ readonly skaterStatsSummary: typeof skaterStatsSummary;
146
+ readonly skaterStatsWithQueryContext: typeof skaterStatsWithQueryContext;
147
+ readonly goalieStatsSummary: typeof goalieStatsSummary;
148
+ };