@databallr/sdk 0.2.0 → 0.3.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 +10 -2
- package/dist/client.js +5 -3
- package/dist/errors.d.ts +14 -3
- package/dist/errors.js +9 -2
- package/dist/generated/methods.d.ts +47 -1
- package/dist/generated/methods.js +28 -1
- package/dist/generated/schema.d.ts +971 -94
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,8 +32,16 @@ const standings = await dbr.get("/v1/nba/standings", { query: { season: 2026 } }
|
|
|
32
32
|
network error is retried with backoff. `maxRetries` (default 2) and
|
|
33
33
|
`timeoutMs` (default 30 s, per attempt) can be set on the client or per
|
|
34
34
|
call, along with `signal` and `headers`.
|
|
35
|
-
- Non-2xx responses throw `DataballrError` (`status`, `code`, `
|
|
36
|
-
`requestId`, `requiredScope`, `retryAfter`).
|
|
35
|
+
- Non-2xx responses throw `DataballrError` (`status`, `code`, `type`,
|
|
36
|
+
`retryable`, `message`, `requestId`, `requiredScope`, `retryAfter`).
|
|
37
|
+
`code` is UPPER_SNAKE for errors any call can hit: `INVALID_TOKEN` (401),
|
|
38
|
+
`INSUFFICIENT_SCOPE` (403), `RATE_LIMITED` (429), `UPSTREAM_ERROR` (502),
|
|
39
|
+
or `HTTP_ERROR` when the body is not the API's error envelope. An
|
|
40
|
+
operation's own errors (bad input, nothing found) may still carry a
|
|
41
|
+
sentence as `code` until the API moves them to codes, so branch on
|
|
42
|
+
`status` for those. The API does not send `type` yet, so it is
|
|
43
|
+
`undefined` and `retryable` is `false`; the client's own retries do not
|
|
44
|
+
depend on them. Network failures throw
|
|
37
45
|
`DataballrConnectionError`, and timeouts its subclass
|
|
38
46
|
`DataballrTimeoutError`.
|
|
39
47
|
- Responses are returned exactly as the API sends them.
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DataballrConnectionError, DataballrTimeoutError, errorFromResponse } from "./errors.js";
|
|
2
2
|
import { methods } from "./generated/methods.js";
|
|
3
|
+
const PLACEHOLDER_RE = /\{([^}]+)\}/g;
|
|
4
|
+
const TRAILING_SLASHES_RE = /\/+$/;
|
|
3
5
|
export const PRODUCTION_BASE_URL = "https://api.databallr.com";
|
|
4
6
|
export const PRODUCTION_API_KEY_PREFIX = "dbrk_";
|
|
5
7
|
const RETRY_STATUSES = new Set([429, 502, 503, 504]);
|
|
@@ -48,7 +50,7 @@ export class Databallr {
|
|
|
48
50
|
(body, options) => this.#request("POST", path, { ...options, body }),
|
|
49
51
|
];
|
|
50
52
|
}
|
|
51
|
-
const placeholders = new Set(Array.from(target.matchAll(
|
|
53
|
+
const placeholders = new Set(Array.from(target.matchAll(PLACEHOLDER_RE), (m) => m[1]));
|
|
52
54
|
return [
|
|
53
55
|
name,
|
|
54
56
|
(params = {}, options) => {
|
|
@@ -162,7 +164,7 @@ function isJson(response) {
|
|
|
162
164
|
return (response.headers.get("content-type") ?? "").includes("json");
|
|
163
165
|
}
|
|
164
166
|
function fillPath(template, params) {
|
|
165
|
-
return template.replace(
|
|
167
|
+
return template.replace(PLACEHOLDER_RE, (_, name) => {
|
|
166
168
|
const value = params?.[name];
|
|
167
169
|
if (value === undefined || value === null) {
|
|
168
170
|
throw new Error(`Databallr: missing path parameter "${name}" for ${template}`);
|
|
@@ -195,5 +197,5 @@ function isBrowser() {
|
|
|
195
197
|
return typeof g.window !== "undefined" && typeof g.document !== "undefined";
|
|
196
198
|
}
|
|
197
199
|
function trimSlash(url) {
|
|
198
|
-
return url.replace(
|
|
200
|
+
return url.replace(TRAILING_SLASHES_RE, "");
|
|
199
201
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
interface DataballrErrorFields {
|
|
2
2
|
readonly status: number;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The shared envelope's `error` in UPPER_SNAKE (`INVALID_TOKEN`,
|
|
5
|
+
* `INSUFFICIENT_SCOPE`, `RATE_LIMITED`, ...), or `HTTP_ERROR` when the body
|
|
6
|
+
* is not that envelope. An older lowercase spelling from the API reads the
|
|
7
|
+
* same.
|
|
8
|
+
*/
|
|
4
9
|
readonly code: string;
|
|
10
|
+
/** The envelope's `type` (`validation`, `rate_limited`, `unavailable`, ...), when the API sends one. */
|
|
11
|
+
readonly type: string | undefined;
|
|
12
|
+
/** The envelope's `retryable`: true when retrying the same request can help. */
|
|
13
|
+
readonly retryable: boolean;
|
|
5
14
|
readonly requestId: string | undefined;
|
|
6
15
|
/** The scope a 403 says would allow the call, from `WWW-Authenticate`. */
|
|
7
16
|
readonly requiredScope: string | undefined;
|
|
@@ -11,13 +20,15 @@ interface DataballrErrorFields {
|
|
|
11
20
|
readonly body: unknown;
|
|
12
21
|
}
|
|
13
22
|
/**
|
|
14
|
-
* Thrown for every non-2xx response. `code` is `
|
|
15
|
-
* `
|
|
23
|
+
* Thrown for every non-2xx response. `code` is `INVALID_TOKEN`,
|
|
24
|
+
* `INSUFFICIENT_SCOPE`, `RATE_LIMITED`, ... or `HTTP_ERROR`.
|
|
16
25
|
*/
|
|
17
26
|
export declare class DataballrError extends Error implements DataballrErrorFields {
|
|
18
27
|
readonly name = "DataballrError";
|
|
19
28
|
readonly status: number;
|
|
20
29
|
readonly code: string;
|
|
30
|
+
readonly type: string | undefined;
|
|
31
|
+
readonly retryable: boolean;
|
|
21
32
|
readonly requestId: string | undefined;
|
|
22
33
|
readonly requiredScope: string | undefined;
|
|
23
34
|
readonly retryAfter: number | undefined;
|
package/dist/errors.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const WWW_AUTHENTICATE_SCOPE_RE = /\bscope="([^"]*)"/;
|
|
1
2
|
export class DataballrError extends Error {
|
|
2
3
|
name = "DataballrError";
|
|
3
4
|
constructor(message, fields) {
|
|
@@ -18,17 +19,23 @@ export function errorFromResponse(response, text) {
|
|
|
18
19
|
}
|
|
19
20
|
catch { }
|
|
20
21
|
const envelope = isEnvelope(body) ? body : undefined;
|
|
21
|
-
const code = envelope
|
|
22
|
+
const code = envelope ? wireCode(envelope.error) : "HTTP_ERROR";
|
|
22
23
|
return new DataballrError(stringOrUndefined(envelope?.message) ??
|
|
23
24
|
(envelope ? code : `Request failed with status ${response.status}`), {
|
|
24
25
|
status: response.status,
|
|
25
26
|
code,
|
|
27
|
+
type: stringOrUndefined(envelope?.type),
|
|
28
|
+
retryable: envelope?.retryable === true,
|
|
26
29
|
requestId: stringOrUndefined(envelope?.request_id),
|
|
27
|
-
requiredScope: response.headers.get("www-authenticate")?.match(
|
|
30
|
+
requiredScope: response.headers.get("www-authenticate")?.match(WWW_AUTHENTICATE_SCOPE_RE)?.[1],
|
|
28
31
|
retryAfter: secondsFromRetryAfter(response.headers.get("retry-after")),
|
|
29
32
|
body,
|
|
30
33
|
});
|
|
31
34
|
}
|
|
35
|
+
const LOWER_SNAKE_RE = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
|
|
36
|
+
function wireCode(error) {
|
|
37
|
+
return LOWER_SNAKE_RE.test(error) ? error.toUpperCase() : error;
|
|
38
|
+
}
|
|
32
39
|
function secondsFromRetryAfter(header) {
|
|
33
40
|
if (header === null)
|
|
34
41
|
return undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** First 12 hex characters of the SHA-256 of the key-callable spec these files came from. */
|
|
2
|
-
export declare const SPEC_HASH = "
|
|
2
|
+
export declare const SPEC_HASH = "bfc137c567e9";
|
|
3
3
|
/**
|
|
4
4
|
* Every generated method: GET operations by path, POST queries as
|
|
5
5
|
* `POST <path>`. `Databallr` turns this table into `dbr.nba.players.search(...)`.
|
|
@@ -49,6 +49,8 @@ export declare const methods: {
|
|
|
49
49
|
readonly youtube: "/v1/nba/draft/youtube";
|
|
50
50
|
};
|
|
51
51
|
readonly games: {
|
|
52
|
+
/** Get a game's box score from the NBA live-data feed. `GET /v1/nba/games/{game_id}/gamelog` · `stats:read` */
|
|
53
|
+
readonly byGameIdGamelog: "/v1/nba/games/{game_id}/gamelog";
|
|
52
54
|
/** Get an NBA game's play-by-play. `GET /v1/nba/games/{game_id}/pbp` · `stats:read` */
|
|
53
55
|
readonly byGameIdPbp: "/v1/nba/games/{game_id}/pbp";
|
|
54
56
|
/** List play-by-play events for an NBA game. `GET /v1/nba/games/{game_id}/plays` · `stats:read` */
|
|
@@ -103,6 +105,8 @@ export declare const methods: {
|
|
|
103
105
|
readonly playerWowy: "POST /v1/nba/pbp/player-wowy";
|
|
104
106
|
/** Get NBA players appearing in a PBP season. `GET /v1/nba/pbp/players-by-season` · `stats:read` */
|
|
105
107
|
readonly playersBySeason: "/v1/nba/pbp/players-by-season";
|
|
108
|
+
/** Get every NBA player's or team's season totals from the play-by-play engine. `GET /v1/nba/pbp/season-totals` · `stats:read` */
|
|
109
|
+
readonly seasonTotals: "/v1/nba/pbp/season-totals";
|
|
106
110
|
/** Get one NBA team's game log for a season. `GET /v1/nba/pbp/team-log` · `stats:read` */
|
|
107
111
|
readonly teamLog: "/v1/nba/pbp/team-log";
|
|
108
112
|
/** Get NBA player on/off combinations. `POST /v1/nba/pbp/wowy-combos-stats` · `stats:read` */
|
|
@@ -163,6 +167,8 @@ export declare const methods: {
|
|
|
163
167
|
readonly byDocKey: "/v1/nba/roster-shapes/{doc_key}";
|
|
164
168
|
};
|
|
165
169
|
readonly shotChart: {
|
|
170
|
+
/** Get NBA league shot averages by zone, overall and by phase and NBA label. `GET /v1/nba/shot-chart/league` · `stats:read` */
|
|
171
|
+
readonly league: "/v1/nba/shot-chart/league";
|
|
166
172
|
/** Get one NBA player's shot chart coordinates. `GET /v1/nba/shot-chart/player` · `stats:read` */
|
|
167
173
|
readonly player: "/v1/nba/shot-chart/player";
|
|
168
174
|
/** Get one NBA team's shot chart coordinates (its own shots, or the shots taken against it). `GET /v1/nba/shot-chart/team` · `stats:read` */
|
|
@@ -248,6 +254,10 @@ export declare const methods: {
|
|
|
248
254
|
readonly tabOrder: "/v1/users/me/tab-order";
|
|
249
255
|
};
|
|
250
256
|
readonly wnba: {
|
|
257
|
+
readonly leagueBaselines: {
|
|
258
|
+
/** WNBA league-wide rates per season (the comparison base for any stat), from the engine's own totals. `GET /v1/wnba/league-baselines` · `stats:read` */
|
|
259
|
+
readonly get: "/v1/wnba/league-baselines";
|
|
260
|
+
};
|
|
251
261
|
readonly live: {
|
|
252
262
|
/** Get a WNBA live game center. `GET /v1/wnba/live/game-center/{event_id}` · `stats:read` */
|
|
253
263
|
readonly gameCenterByEventId: "/v1/wnba/live/game-center/{event_id}";
|
|
@@ -258,6 +268,34 @@ export declare const methods: {
|
|
|
258
268
|
/** List WNBA live plays for a game. `GET /v1/wnba/live/plays/{event_id}` · `stats:read` */
|
|
259
269
|
readonly playsByEventId: "/v1/wnba/live/plays/{event_id}";
|
|
260
270
|
};
|
|
271
|
+
readonly opponentQuality: {
|
|
272
|
+
/** WNBA teams ranking in a rating range (top, middle or bottom of the league by ORtg, DRtg or NetRtg), from the engine's own totals. `GET /v1/wnba/opponent-quality` · `stats:read` */
|
|
273
|
+
readonly get: "/v1/wnba/opponent-quality";
|
|
274
|
+
};
|
|
275
|
+
readonly pbp: {
|
|
276
|
+
/** Get combined WNBA PBP analytics. `POST /v1/wnba/pbp/enhanced-stats` · `stats:read` */
|
|
277
|
+
readonly enhancedStats: "POST /v1/wnba/pbp/enhanced-stats";
|
|
278
|
+
/** Get WNBA five-player lineup combinations. `POST /v1/wnba/pbp/lineup/combos` · `stats:read` */
|
|
279
|
+
readonly lineupCombos: "POST /v1/wnba/pbp/lineup/combos";
|
|
280
|
+
/** Get WNBA lineup player statistics. `POST /v1/wnba/pbp/lineup/players` · `stats:read` */
|
|
281
|
+
readonly lineupPlayers: "POST /v1/wnba/pbp/lineup/players";
|
|
282
|
+
/** Get WNBA lineup possession totals. `POST /v1/wnba/pbp/lineup/summary` · `stats:read` */
|
|
283
|
+
readonly lineupSummary: "POST /v1/wnba/pbp/lineup/summary";
|
|
284
|
+
/** Discover WNBA PBP analytics endpoints. `GET /v1/wnba/pbp/manifest` · `stats:read` */
|
|
285
|
+
readonly manifest: "/v1/wnba/pbp/manifest";
|
|
286
|
+
/** Get one WNBA player's game log for a season. `GET /v1/wnba/pbp/player-log` · `stats:read` */
|
|
287
|
+
readonly playerLog: "/v1/wnba/pbp/player-log";
|
|
288
|
+
/** Get one WNBA player's production across teammate on/off combinations. `POST /v1/wnba/pbp/player-wowy` · `stats:read` */
|
|
289
|
+
readonly playerWowy: "POST /v1/wnba/pbp/player-wowy";
|
|
290
|
+
/** Get WNBA players appearing in a PBP season. `GET /v1/wnba/pbp/players-by-season` · `stats:read` */
|
|
291
|
+
readonly playersBySeason: "/v1/wnba/pbp/players-by-season";
|
|
292
|
+
/** Get every WNBA player's or team's season totals from the play-by-play engine. `GET /v1/wnba/pbp/season-totals` · `stats:read` */
|
|
293
|
+
readonly seasonTotals: "/v1/wnba/pbp/season-totals";
|
|
294
|
+
/** Get one WNBA team's game log for a season. `GET /v1/wnba/pbp/team-log` · `stats:read` */
|
|
295
|
+
readonly teamLog: "/v1/wnba/pbp/team-log";
|
|
296
|
+
/** Get WNBA player on/off combinations. `POST /v1/wnba/pbp/wowy-combos-stats` · `stats:read` */
|
|
297
|
+
readonly wowyCombosStats: "POST /v1/wnba/pbp/wowy-combos-stats";
|
|
298
|
+
};
|
|
261
299
|
readonly players: {
|
|
262
300
|
/** List WNBA player stats. `GET /v1/wnba/players/stats` · `stats:read` */
|
|
263
301
|
readonly stats: "/v1/wnba/players/stats";
|
|
@@ -266,6 +304,14 @@ export declare const methods: {
|
|
|
266
304
|
/** Get the WNBA playoff bracket, series and games. `GET /v1/wnba/playoffs` · `stats:read` */
|
|
267
305
|
readonly get: "/v1/wnba/playoffs";
|
|
268
306
|
};
|
|
307
|
+
readonly shotChart: {
|
|
308
|
+
/** Get WNBA league shot averages by zone, overall and by phase and label. `GET /v1/wnba/shot-chart/league` · `stats:read` */
|
|
309
|
+
readonly league: "/v1/wnba/shot-chart/league";
|
|
310
|
+
/** Get one WNBA player's shot chart coordinates. `GET /v1/wnba/shot-chart/player` · `stats:read` */
|
|
311
|
+
readonly player: "/v1/wnba/shot-chart/player";
|
|
312
|
+
/** Get one WNBA team's shot chart coordinates (its own shots, or the shots taken against it). `GET /v1/wnba/shot-chart/team` · `stats:read` */
|
|
313
|
+
readonly team: "/v1/wnba/shot-chart/team";
|
|
314
|
+
};
|
|
269
315
|
readonly stats: {
|
|
270
316
|
/** List WNBA advanced stats. `GET /v1/wnba/stats/advanced-stats` · `stats:read` */
|
|
271
317
|
readonly advancedStats: "/v1/wnba/stats/advanced-stats";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const SPEC_HASH = "
|
|
1
|
+
export const SPEC_HASH = "bfc137c567e9";
|
|
2
2
|
export const methods = {
|
|
3
3
|
apps: {
|
|
4
4
|
sixrings: {
|
|
@@ -27,6 +27,7 @@ export const methods = {
|
|
|
27
27
|
youtube: "/v1/nba/draft/youtube",
|
|
28
28
|
},
|
|
29
29
|
games: {
|
|
30
|
+
byGameIdGamelog: "/v1/nba/games/{game_id}/gamelog",
|
|
30
31
|
byGameIdPbp: "/v1/nba/games/{game_id}/pbp",
|
|
31
32
|
byGameIdPlays: "/v1/nba/games/{game_id}/plays",
|
|
32
33
|
},
|
|
@@ -61,6 +62,7 @@ export const methods = {
|
|
|
61
62
|
playerLog: "/v1/nba/pbp/player-log",
|
|
62
63
|
playerWowy: "POST /v1/nba/pbp/player-wowy",
|
|
63
64
|
playersBySeason: "/v1/nba/pbp/players-by-season",
|
|
65
|
+
seasonTotals: "/v1/nba/pbp/season-totals",
|
|
64
66
|
teamLog: "/v1/nba/pbp/team-log",
|
|
65
67
|
wowyCombosStats: "POST /v1/nba/pbp/wowy-combos-stats",
|
|
66
68
|
},
|
|
@@ -96,6 +98,7 @@ export const methods = {
|
|
|
96
98
|
byDocKey: "/v1/nba/roster-shapes/{doc_key}",
|
|
97
99
|
},
|
|
98
100
|
shotChart: {
|
|
101
|
+
league: "/v1/nba/shot-chart/league",
|
|
99
102
|
player: "/v1/nba/shot-chart/player",
|
|
100
103
|
team: "/v1/nba/shot-chart/team",
|
|
101
104
|
},
|
|
@@ -147,18 +150,42 @@ export const methods = {
|
|
|
147
150
|
tabOrder: "/v1/users/me/tab-order",
|
|
148
151
|
},
|
|
149
152
|
wnba: {
|
|
153
|
+
leagueBaselines: {
|
|
154
|
+
get: "/v1/wnba/league-baselines",
|
|
155
|
+
},
|
|
150
156
|
live: {
|
|
151
157
|
gameCenterByEventId: "/v1/wnba/live/game-center/{event_id}",
|
|
152
158
|
games: "/v1/wnba/live/games",
|
|
153
159
|
gamesByGameDate: "/v1/wnba/live/games/{game_date}",
|
|
154
160
|
playsByEventId: "/v1/wnba/live/plays/{event_id}",
|
|
155
161
|
},
|
|
162
|
+
opponentQuality: {
|
|
163
|
+
get: "/v1/wnba/opponent-quality",
|
|
164
|
+
},
|
|
165
|
+
pbp: {
|
|
166
|
+
enhancedStats: "POST /v1/wnba/pbp/enhanced-stats",
|
|
167
|
+
lineupCombos: "POST /v1/wnba/pbp/lineup/combos",
|
|
168
|
+
lineupPlayers: "POST /v1/wnba/pbp/lineup/players",
|
|
169
|
+
lineupSummary: "POST /v1/wnba/pbp/lineup/summary",
|
|
170
|
+
manifest: "/v1/wnba/pbp/manifest",
|
|
171
|
+
playerLog: "/v1/wnba/pbp/player-log",
|
|
172
|
+
playerWowy: "POST /v1/wnba/pbp/player-wowy",
|
|
173
|
+
playersBySeason: "/v1/wnba/pbp/players-by-season",
|
|
174
|
+
seasonTotals: "/v1/wnba/pbp/season-totals",
|
|
175
|
+
teamLog: "/v1/wnba/pbp/team-log",
|
|
176
|
+
wowyCombosStats: "POST /v1/wnba/pbp/wowy-combos-stats",
|
|
177
|
+
},
|
|
156
178
|
players: {
|
|
157
179
|
stats: "/v1/wnba/players/stats",
|
|
158
180
|
},
|
|
159
181
|
playoffs: {
|
|
160
182
|
get: "/v1/wnba/playoffs",
|
|
161
183
|
},
|
|
184
|
+
shotChart: {
|
|
185
|
+
league: "/v1/wnba/shot-chart/league",
|
|
186
|
+
player: "/v1/wnba/shot-chart/player",
|
|
187
|
+
team: "/v1/wnba/shot-chart/team",
|
|
188
|
+
},
|
|
162
189
|
stats: {
|
|
163
190
|
advancedStats: "/v1/wnba/stats/advanced-stats",
|
|
164
191
|
onOff: "/v1/wnba/stats/on-off",
|