nhl-api-ts 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +315 -2
- package/dist/api/edge.d.mts +180 -0
- package/dist/api/edge.mjs +184 -0
- package/dist/api/game-center.d.mts +84 -0
- package/dist/api/game-center.mjs +74 -0
- package/dist/api/helpers.d.mts +47 -0
- package/dist/api/helpers.mjs +106 -0
- package/dist/api/misc.d.mts +40 -0
- package/dist/api/misc.mjs +43 -0
- package/dist/api/players.d.mts +28 -0
- package/dist/api/players.mjs +18 -0
- package/dist/api/query/builder.d.mts +22 -0
- package/dist/api/query/builder.mjs +30 -0
- package/dist/api/query/filters.d.mts +93 -0
- package/dist/api/query/filters.mjs +118 -0
- package/dist/api/query/index.d.mts +4 -0
- package/dist/api/query/index.mjs +4 -0
- package/dist/api/query/sorting/goalie-sorts.d.mts +61 -0
- package/dist/api/query/sorting/goalie-sorts.mjs +54 -0
- package/dist/api/query/sorting/sorting-options.d.mts +136 -0
- package/dist/api/query/sorting/sorting-options.mjs +94 -0
- package/dist/api/schedule.d.mts +117 -0
- package/dist/api/schedule.mjs +131 -0
- package/dist/api/standings.d.mts +29 -0
- package/dist/api/standings.mjs +38 -0
- package/dist/api/stats.d.mts +153 -0
- package/dist/api/stats.mjs +166 -0
- package/dist/api/teams.d.mts +59 -0
- package/dist/api/teams.mjs +91 -0
- package/dist/cli/colors.d.mts +14 -0
- package/dist/cli/colors.mjs +13 -0
- package/dist/cli/commands.d.mts +27 -0
- package/dist/cli/commands.mjs +695 -0
- package/dist/cli/run.d.mts +9 -0
- package/dist/cli/run.mjs +313 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.mjs +13 -0
- package/dist/config.d.mts +20 -0
- package/dist/config.mjs +4 -0
- package/dist/context.d.mts +6 -0
- package/dist/context.mjs +1 -0
- package/dist/errors.d.mts +35 -0
- package/dist/errors.mjs +49 -0
- package/dist/http-client.d.mts +27 -0
- package/dist/http-client.mjs +95 -0
- package/dist/index.d.mts +22 -0
- package/dist/index.mjs +15 -0
- package/dist/nhl-client.d.mts +101 -0
- package/dist/nhl-client.mjs +40 -0
- package/dist/types/common.d.mts +81 -0
- package/dist/types/common.mjs +2 -0
- package/dist/types/edge.d.mts +1024 -0
- package/dist/types/edge.mjs +1 -0
- package/dist/types/game-center.d.mts +1194 -0
- package/dist/types/game-center.mjs +1 -0
- package/dist/types/helpers.d.mts +17 -0
- package/dist/types/helpers.mjs +1 -0
- package/dist/types/index.d.mts +10 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/misc.d.mts +68 -0
- package/dist/types/misc.mjs +2 -0
- package/dist/types/players.d.mts +42 -0
- package/dist/types/players.mjs +1 -0
- package/dist/types/schedule.d.mts +456 -0
- package/dist/types/schedule.mjs +1 -0
- package/dist/types/standings.d.mts +104 -0
- package/dist/types/standings.mjs +1 -0
- package/dist/types/stats.d.mts +1086 -0
- package/dist/types/stats.mjs +1 -0
- package/dist/types/teams.d.mts +29 -0
- package/dist/types/teams.mjs +1 -0
- package/dist/utils.d.mts +4 -0
- package/dist/utils.mjs +3 -0
- package/package.json +85 -3
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type GoalieStatsSummaryParams, type SkaterStatsWithQueryContextParams, statsApi } from '#src/api/stats.mjs';
|
|
2
|
+
import { type ClientOptions } from '#src/config.mjs';
|
|
3
|
+
import type { Context } from '#src/context.mjs';
|
|
4
|
+
import type { GoalieReportRows, SkaterReportRows, StatsApiPage } from '#src/types/index.mjs';
|
|
5
|
+
type Bound<Module> = {
|
|
6
|
+
[Method in keyof Module]: Module[Method] extends (ctx: Context, ...args: infer Args) => infer MethodResponse ? (...args: Args) => MethodResponse : never;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* `Bound` erases generic parameters, so the report-typed stats methods are
|
|
10
|
+
* spelled out here (without `ctx`) to keep `reportType` / `statsType`
|
|
11
|
+
* flowing into the row type.
|
|
12
|
+
*/
|
|
13
|
+
interface StatsGenericMethods {
|
|
14
|
+
skaterStatsWithQueryContext<Report extends keyof SkaterReportRows>(params: SkaterStatsWithQueryContextParams<Report>): Promise<StatsApiPage<SkaterReportRows[Report]>>;
|
|
15
|
+
goalieStatsSummary<Report extends keyof GoalieReportRows = 'summary'>(params: GoalieStatsSummaryParams<Report>): Promise<GoalieReportRows[Report][]>;
|
|
16
|
+
}
|
|
17
|
+
type StatsClient = Omit<Bound<typeof statsApi>, 'skaterStatsWithQueryContext' | 'goalieStatsSummary'> & StatsGenericMethods;
|
|
18
|
+
/**
|
|
19
|
+
* Builds the main client used to access the NHL API.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const client = createNHLClient();
|
|
23
|
+
* const client = createNHLClient({ debug: true }); // for a lil extra logging
|
|
24
|
+
* const teams = await client.teams.teams();
|
|
25
|
+
*/
|
|
26
|
+
export declare const createNHLClient: (options?: ClientOptions) => {
|
|
27
|
+
readonly config: Readonly<import("#src/config.mjs").Config>;
|
|
28
|
+
readonly teams: Bound<{
|
|
29
|
+
readonly teams: typeof import("#src/api/teams.mjs").teams;
|
|
30
|
+
readonly teamRoster: typeof import("#src/api/teams.mjs").teamRoster;
|
|
31
|
+
readonly franchises: typeof import("#src/api/teams.mjs").franchises;
|
|
32
|
+
}>;
|
|
33
|
+
readonly standings: Bound<{
|
|
34
|
+
readonly leagueStandings: typeof import("#src/api/standings.mjs").leagueStandings;
|
|
35
|
+
readonly seasonStandingManifest: typeof import("#src/api/standings.mjs").seasonStandingManifest;
|
|
36
|
+
}>;
|
|
37
|
+
readonly schedule: Bound<{
|
|
38
|
+
readonly dailySchedule: typeof import("#src/api/schedule.mjs").dailySchedule;
|
|
39
|
+
readonly weeklySchedule: typeof import("#src/api/schedule.mjs").weeklySchedule;
|
|
40
|
+
readonly teamMonthlySchedule: typeof import("#src/api/schedule.mjs").teamMonthlySchedule;
|
|
41
|
+
readonly teamWeeklySchedule: typeof import("#src/api/schedule.mjs").teamWeeklySchedule;
|
|
42
|
+
readonly teamSeasonSchedule: typeof import("#src/api/schedule.mjs").teamSeasonSchedule;
|
|
43
|
+
readonly calendarSchedule: typeof import("#src/api/schedule.mjs").calendarSchedule;
|
|
44
|
+
readonly playoffCarousel: typeof import("#src/api/schedule.mjs").playoffCarousel;
|
|
45
|
+
readonly playoffSeriesSchedule: typeof import("#src/api/schedule.mjs").playoffSeriesSchedule;
|
|
46
|
+
readonly playoffBracket: typeof import("#src/api/schedule.mjs").playoffBracket;
|
|
47
|
+
}>;
|
|
48
|
+
readonly gameCenter: Bound<{
|
|
49
|
+
readonly boxscore: typeof import("#src/api/game-center.mjs").boxscore;
|
|
50
|
+
readonly playByPlay: typeof import("#src/api/game-center.mjs").playByPlay;
|
|
51
|
+
readonly matchUp: typeof import("#src/api/game-center.mjs").matchUp;
|
|
52
|
+
readonly dailyScores: typeof import("#src/api/game-center.mjs").dailyScores;
|
|
53
|
+
readonly shiftChartData: typeof import("#src/api/game-center.mjs").shiftChartData;
|
|
54
|
+
readonly seasonSeriesMatchup: typeof import("#src/api/game-center.mjs").seasonSeriesMatchup;
|
|
55
|
+
readonly gameStory: typeof import("#src/api/game-center.mjs").gameStory;
|
|
56
|
+
}>;
|
|
57
|
+
readonly stats: StatsClient;
|
|
58
|
+
readonly misc: Bound<{
|
|
59
|
+
readonly glossary: typeof import("#src/api/misc.mjs").glossary;
|
|
60
|
+
readonly config: typeof import("#src/api/misc.mjs").config;
|
|
61
|
+
readonly countries: typeof import("#src/api/misc.mjs").countries;
|
|
62
|
+
readonly seasonSpecificRulesAndInfo: typeof import("#src/api/misc.mjs").seasonSpecificRulesAndInfo;
|
|
63
|
+
readonly draftYearAndRounds: typeof import("#src/api/misc.mjs").draftYearAndRounds;
|
|
64
|
+
}>;
|
|
65
|
+
readonly helpers: Bound<{
|
|
66
|
+
readonly gameIdsBySeason: typeof import("#src/api/helpers.mjs").gameIdsBySeason;
|
|
67
|
+
readonly allPlayers: typeof import("#src/api/helpers.mjs").allPlayers;
|
|
68
|
+
readonly allPlayersSummaryStatistics: typeof import("#src/api/helpers.mjs").allPlayersSummaryStatistics;
|
|
69
|
+
}>;
|
|
70
|
+
readonly players: Bound<{
|
|
71
|
+
readonly prospectsByTeam: typeof import("#src/api/players.mjs").prospectsByTeam;
|
|
72
|
+
readonly playersByTeam: typeof import("#src/api/players.mjs").playersByTeam;
|
|
73
|
+
}>;
|
|
74
|
+
readonly edge: Bound<{
|
|
75
|
+
readonly skaterDetail: typeof import("#src/api/edge.mjs").skaterDetail;
|
|
76
|
+
readonly skaterShotSpeedDetail: typeof import("#src/api/edge.mjs").skaterShotSpeedDetail;
|
|
77
|
+
readonly skaterSkatingSpeedDetail: typeof import("#src/api/edge.mjs").skaterSkatingSpeedDetail;
|
|
78
|
+
readonly skaterShotLocationDetail: typeof import("#src/api/edge.mjs").skaterShotLocationDetail;
|
|
79
|
+
readonly skaterSkatingDistanceDetail: typeof import("#src/api/edge.mjs").skaterSkatingDistanceDetail;
|
|
80
|
+
readonly skaterComparison: typeof import("#src/api/edge.mjs").skaterComparison;
|
|
81
|
+
readonly skaterZoneTime: typeof import("#src/api/edge.mjs").skaterZoneTime;
|
|
82
|
+
readonly skaterLanding: typeof import("#src/api/edge.mjs").skaterLanding;
|
|
83
|
+
readonly catSkaterDetail: typeof import("#src/api/edge.mjs").catSkaterDetail;
|
|
84
|
+
readonly goalieDetail: typeof import("#src/api/edge.mjs").goalieDetail;
|
|
85
|
+
readonly goalieShotLocationDetail: typeof import("#src/api/edge.mjs").goalieShotLocationDetail;
|
|
86
|
+
readonly goalie5v5Detail: typeof import("#src/api/edge.mjs").goalie5v5Detail;
|
|
87
|
+
readonly goalieComparison: typeof import("#src/api/edge.mjs").goalieComparison;
|
|
88
|
+
readonly goalieSavePercentageDetail: typeof import("#src/api/edge.mjs").goalieSavePercentageDetail;
|
|
89
|
+
readonly goalieLanding: typeof import("#src/api/edge.mjs").goalieLanding;
|
|
90
|
+
readonly catGoalieDetail: typeof import("#src/api/edge.mjs").catGoalieDetail;
|
|
91
|
+
readonly teamDetail: typeof import("#src/api/edge.mjs").teamDetail;
|
|
92
|
+
readonly teamSkatingDistanceDetail: typeof import("#src/api/edge.mjs").teamSkatingDistanceDetail;
|
|
93
|
+
readonly teamZoneTimeDetails: typeof import("#src/api/edge.mjs").teamZoneTimeDetails;
|
|
94
|
+
readonly teamShotLocationDetail: typeof import("#src/api/edge.mjs").teamShotLocationDetail;
|
|
95
|
+
readonly teamLanding: typeof import("#src/api/edge.mjs").teamLanding;
|
|
96
|
+
readonly teamShotSpeedDetail: typeof import("#src/api/edge.mjs").teamShotSpeedDetail;
|
|
97
|
+
readonly teamSkatingSpeedDetail: typeof import("#src/api/edge.mjs").teamSkatingSpeedDetail;
|
|
98
|
+
}>;
|
|
99
|
+
};
|
|
100
|
+
export type NHLClient = ReturnType<typeof createNHLClient>;
|
|
101
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { edgeApi } from '#src/api/edge.mjs';
|
|
2
|
+
import { gameCenterApi } from '#src/api/game-center.mjs';
|
|
3
|
+
import { helpersApi } from '#src/api/helpers.mjs';
|
|
4
|
+
import { miscApi } from '#src/api/misc.mjs';
|
|
5
|
+
import { playersApi } from '#src/api/players.mjs';
|
|
6
|
+
import { scheduleApi } from '#src/api/schedule.mjs';
|
|
7
|
+
import { standingsApi } from '#src/api/standings.mjs';
|
|
8
|
+
import { statsApi, } from '#src/api/stats.mjs';
|
|
9
|
+
import { teamsApi } from '#src/api/teams.mjs';
|
|
10
|
+
import { resolveConfig } from '#src/config.mjs';
|
|
11
|
+
import { createGet } from '#src/http-client.mjs';
|
|
12
|
+
import { sleep } from '#src/utils.mjs';
|
|
13
|
+
const bind = (ctx, api) => Object.fromEntries(Object.entries(api).map(([key, fn]) => [
|
|
14
|
+
key,
|
|
15
|
+
(...args) => fn(ctx, ...args),
|
|
16
|
+
]));
|
|
17
|
+
/**
|
|
18
|
+
* Builds the main client used to access the NHL API.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const client = createNHLClient();
|
|
22
|
+
* const client = createNHLClient({ debug: true }); // for a lil extra logging
|
|
23
|
+
* const teams = await client.teams.teams();
|
|
24
|
+
*/
|
|
25
|
+
export const createNHLClient = (options = {}) => {
|
|
26
|
+
const config = resolveConfig(options);
|
|
27
|
+
const ctx = { get: createGet(config), sleep };
|
|
28
|
+
return {
|
|
29
|
+
config,
|
|
30
|
+
teams: bind(ctx, teamsApi),
|
|
31
|
+
standings: bind(ctx, standingsApi),
|
|
32
|
+
schedule: bind(ctx, scheduleApi),
|
|
33
|
+
gameCenter: bind(ctx, gameCenterApi),
|
|
34
|
+
stats: bind(ctx, statsApi),
|
|
35
|
+
misc: bind(ctx, miscApi),
|
|
36
|
+
helpers: bind(ctx, helpersApi),
|
|
37
|
+
players: bind(ctx, playersApi),
|
|
38
|
+
edge: bind(ctx, edgeApi),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A string union that still accepts values the SDK doesn't know about yet.
|
|
3
|
+
* Autocomplete lists `Known`, but a new value from the NHL doesn't break
|
|
4
|
+
* consumers.
|
|
5
|
+
*/
|
|
6
|
+
export type OpenUnion<Known extends string> = Known | (string & {});
|
|
7
|
+
/** A name or label with optional translations; `default` is always present. */
|
|
8
|
+
export interface LocalizedString {
|
|
9
|
+
default: string;
|
|
10
|
+
cs?: string;
|
|
11
|
+
de?: string;
|
|
12
|
+
es?: string;
|
|
13
|
+
fi?: string;
|
|
14
|
+
fr?: string;
|
|
15
|
+
sk?: string;
|
|
16
|
+
sv?: string;
|
|
17
|
+
}
|
|
18
|
+
/** 1 = preseason, 2 = regular season, 3 = playoffs. Other codes (4 = all-star) exist. */
|
|
19
|
+
export type GameType = 1 | 2 | 3 | (number & {});
|
|
20
|
+
/** Season in YYYYYYYY form, e.g. 20232024. */
|
|
21
|
+
export type SeasonId = number;
|
|
22
|
+
export type GameState = OpenUnion<'FUT' | 'PRE' | 'LIVE' | 'CRIT' | 'FINAL' | 'OFF'>;
|
|
23
|
+
export type GameScheduleState = OpenUnion<'OK' | 'PPD' | 'SUSP' | 'CNCL' | 'TBD'>;
|
|
24
|
+
export type PeriodType = OpenUnion<'REG' | 'OT' | 'SO'>;
|
|
25
|
+
export type PositionCode = OpenUnion<'C' | 'L' | 'R' | 'D' | 'G'>;
|
|
26
|
+
export type ShootsCatches = OpenUnion<'L' | 'R'>;
|
|
27
|
+
export type ZoneCode = OpenUnion<'O' | 'N' | 'D'>;
|
|
28
|
+
export type ShotType = OpenUnion<'wrist' | 'snap' | 'slap' | 'backhand' | 'tip-in' | 'deflected' | 'wrap-around' | 'bat'>;
|
|
29
|
+
/** Envelope of the stats API (`api.nhle.com/stats/rest`) for paged reports. */
|
|
30
|
+
export interface StatsApiPage<Row> {
|
|
31
|
+
data: Row[];
|
|
32
|
+
total: number;
|
|
33
|
+
}
|
|
34
|
+
export interface GameOutcome {
|
|
35
|
+
lastPeriodType: PeriodType;
|
|
36
|
+
/** Low sample count */
|
|
37
|
+
otPeriods?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface PeriodDescriptor {
|
|
40
|
+
number: number;
|
|
41
|
+
periodType: PeriodType;
|
|
42
|
+
maxRegulationPeriods: number;
|
|
43
|
+
}
|
|
44
|
+
export interface SeriesStatus {
|
|
45
|
+
round: number;
|
|
46
|
+
seriesAbbrev: string;
|
|
47
|
+
seriesTitle: string;
|
|
48
|
+
seriesLetter: string;
|
|
49
|
+
neededToWin: number;
|
|
50
|
+
topSeedTeamAbbrev: string;
|
|
51
|
+
topSeedWins: number;
|
|
52
|
+
bottomSeedTeamAbbrev: string;
|
|
53
|
+
bottomSeedWins: number;
|
|
54
|
+
gameNumberOfSeries: number;
|
|
55
|
+
}
|
|
56
|
+
export interface TeamLogo {
|
|
57
|
+
light: string;
|
|
58
|
+
dark: string;
|
|
59
|
+
}
|
|
60
|
+
export interface TvBroadcast {
|
|
61
|
+
id: number;
|
|
62
|
+
market: string;
|
|
63
|
+
countryCode: string;
|
|
64
|
+
network: string;
|
|
65
|
+
sequenceNumber: number;
|
|
66
|
+
}
|
|
67
|
+
export interface OddsPartner {
|
|
68
|
+
partnerId: number;
|
|
69
|
+
country: string;
|
|
70
|
+
name: string;
|
|
71
|
+
imageUrl: string;
|
|
72
|
+
siteUrl: string;
|
|
73
|
+
bgColor: string;
|
|
74
|
+
textColor: string;
|
|
75
|
+
accentColor: string;
|
|
76
|
+
}
|
|
77
|
+
/** A betting provider's price for one side of a game. */
|
|
78
|
+
export interface TeamOdd {
|
|
79
|
+
providerId: number;
|
|
80
|
+
value: string;
|
|
81
|
+
}
|