@nflmeta/sdk 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.
- package/LICENSE +21 -0
- package/README.md +141 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +156 -0
- package/dist/errors.d.ts +30 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +82 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/resources.d.ts +189 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +460 -0
- package/dist/types.d.ts +155 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Philippe Bourdon / ClearOak Studio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# `@nflmeta/sdk`
|
|
2
|
+
|
|
3
|
+
Official TypeScript SDK for the NFLMeta API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nflmeta/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { NFLMetaClient } from "@nflmeta/sdk";
|
|
15
|
+
|
|
16
|
+
const client = new NFLMetaClient({
|
|
17
|
+
apiKey: process.env.NFLMETA_API_KEY,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const team = await client.teams.get("PIT", { season: 2025 });
|
|
21
|
+
const player = await client.players.identity("josh-allen-1996");
|
|
22
|
+
const usage = await client.usage.get();
|
|
23
|
+
|
|
24
|
+
console.log(team.data.displayName);
|
|
25
|
+
console.log(player.data.display_name);
|
|
26
|
+
console.log(usage.data.quota_remaining);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## What The SDK Does
|
|
30
|
+
|
|
31
|
+
- sends `X-NFLMeta-Key` automatically when you provide `apiKey`
|
|
32
|
+
- preserves the API envelope shape: `data`, optional `meta`, plus parsed rate-limit headers
|
|
33
|
+
- throws typed HTTP errors for common failure cases
|
|
34
|
+
- exposes the main API surfaces as resource clients instead of forcing raw URL construction
|
|
35
|
+
- still gives you a low-level `client.get(path, { query })` escape hatch for any route not wrapped yet
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const client = new NFLMetaClient({
|
|
41
|
+
apiKey: process.env.NFLMETA_API_KEY,
|
|
42
|
+
baseUrl: "https://nflmeta.org",
|
|
43
|
+
timeoutMs: 10_000,
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Options:
|
|
48
|
+
|
|
49
|
+
- `apiKey`: optional API key for authenticated routes
|
|
50
|
+
- `baseUrl`: defaults to `https://nflmeta.org`
|
|
51
|
+
- `timeoutMs`: request timeout in milliseconds
|
|
52
|
+
- `fetch`: optional custom `fetch` implementation
|
|
53
|
+
- `headers`: optional default headers merged into each request
|
|
54
|
+
|
|
55
|
+
## Returned Shape
|
|
56
|
+
|
|
57
|
+
Every SDK method returns the API envelope plus request metadata:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
const response = await client.games.list({ season: 2025, week: 1 });
|
|
61
|
+
|
|
62
|
+
response.data;
|
|
63
|
+
response.meta;
|
|
64
|
+
response.status;
|
|
65
|
+
response.rateLimit.limit;
|
|
66
|
+
response.rateLimit.remaining;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Resource Coverage
|
|
70
|
+
|
|
71
|
+
The SDK wraps the main public surfaces:
|
|
72
|
+
|
|
73
|
+
- `health`
|
|
74
|
+
- `usage`
|
|
75
|
+
- `metadata`
|
|
76
|
+
- `seasons`
|
|
77
|
+
- `teams`
|
|
78
|
+
- `players`
|
|
79
|
+
- `games`
|
|
80
|
+
- `playoffGames`
|
|
81
|
+
- `standings`
|
|
82
|
+
- `playoffs`
|
|
83
|
+
- `superBowls`
|
|
84
|
+
- `history`
|
|
85
|
+
- `hallOfFame`
|
|
86
|
+
- `contributors`
|
|
87
|
+
- `executives`
|
|
88
|
+
- `staff`
|
|
89
|
+
- `coaches`
|
|
90
|
+
- `assets`
|
|
91
|
+
- `allStarGames`
|
|
92
|
+
- `stats.players`
|
|
93
|
+
- `reference`
|
|
94
|
+
|
|
95
|
+
Examples:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
await client.seasons.list({ year_from: 2000, year_to: 2025 });
|
|
99
|
+
await client.teams.profile("PIT", { season: 2025 });
|
|
100
|
+
await client.players.bio("josh-allen-1996");
|
|
101
|
+
await client.players.careerField("josh-allen-1996", "pass_passer_rating");
|
|
102
|
+
await client.games.extras(12001);
|
|
103
|
+
await client.superBowls.byTeam("PIT");
|
|
104
|
+
await client.reference.venue("m-t-bank-stadium");
|
|
105
|
+
await client.stats.players.search({ search: "Mahomes" });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Errors
|
|
109
|
+
|
|
110
|
+
The SDK throws typed errors:
|
|
111
|
+
|
|
112
|
+
- `NFLMetaBadRequestError`
|
|
113
|
+
- `NFLMetaUnauthorizedError`
|
|
114
|
+
- `NFLMetaNotFoundError`
|
|
115
|
+
- `NFLMetaRateLimitError`
|
|
116
|
+
- `NFLMetaTimeoutError`
|
|
117
|
+
- `NFLMetaError`
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { NFLMetaNotFoundError } from "@nflmeta/sdk";
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
await client.teams.get("BAD");
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error instanceof NFLMetaNotFoundError) {
|
|
126
|
+
console.error(error.message);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Escape Hatch
|
|
132
|
+
|
|
133
|
+
You can call any route directly:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const raw = await client.get("/api/v1/reference/team-colors", {
|
|
137
|
+
query: { limit: 10 },
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
That makes the SDK usable immediately even when a new endpoint lands before a wrapper method is added.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NFLMetaClientOptions, NFLMetaEnvelope, RequestOptions, UnknownRecord } from "./types.js";
|
|
2
|
+
export declare class NFLMetaClientCore {
|
|
3
|
+
readonly apiKey?: string;
|
|
4
|
+
readonly baseUrl: string;
|
|
5
|
+
readonly timeoutMs?: number;
|
|
6
|
+
readonly fetchImpl: typeof fetch;
|
|
7
|
+
readonly defaultHeaders?: HeadersInit;
|
|
8
|
+
constructor(options?: NFLMetaClientOptions);
|
|
9
|
+
get<TData = UnknownRecord, TMeta = unknown>(path: string, options?: RequestOptions): Promise<NFLMetaEnvelope<TData, TMeta>>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EAGf,cAAc,EACd,aAAa,EACd,MAAM,YAAY,CAAC;AA0GpB,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,KAAK,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,WAAW,CAAC;gBAE1B,OAAO,GAAE,oBAAyB;IAQxC,GAAG,CAAC,KAAK,GAAG,aAAa,EAAE,KAAK,GAAG,OAAO,EAC9C,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;CA8C1C"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { NFLMetaTimeoutError, createHttpError } from "./errors.js";
|
|
2
|
+
function isAbsoluteUrl(value) {
|
|
3
|
+
return /^https?:\/\//i.test(value);
|
|
4
|
+
}
|
|
5
|
+
function normalizeBaseUrl(baseUrl) {
|
|
6
|
+
const base = (baseUrl || "https://nflmeta.org").trim();
|
|
7
|
+
return base.replace(/\/+$/, "");
|
|
8
|
+
}
|
|
9
|
+
function encodeQueryValue(value) {
|
|
10
|
+
if (value instanceof Date)
|
|
11
|
+
return value.toISOString();
|
|
12
|
+
return String(value);
|
|
13
|
+
}
|
|
14
|
+
function appendQuery(url, query) {
|
|
15
|
+
if (!query)
|
|
16
|
+
return;
|
|
17
|
+
for (const [key, rawValue] of Object.entries(query)) {
|
|
18
|
+
if (rawValue == null)
|
|
19
|
+
continue;
|
|
20
|
+
const values = Array.isArray(rawValue) ? rawValue : [rawValue];
|
|
21
|
+
for (const value of values) {
|
|
22
|
+
if (value == null)
|
|
23
|
+
continue;
|
|
24
|
+
if (value instanceof Date || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
25
|
+
url.searchParams.append(key, encodeQueryValue(value));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function parseNumberHeader(headers, name) {
|
|
31
|
+
const value = headers.get(name);
|
|
32
|
+
if (!value)
|
|
33
|
+
return undefined;
|
|
34
|
+
const parsed = Number.parseInt(value, 10);
|
|
35
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
36
|
+
}
|
|
37
|
+
function parseRateLimit(headers) {
|
|
38
|
+
return {
|
|
39
|
+
limit: parseNumberHeader(headers, "X-RateLimit-Limit"),
|
|
40
|
+
remaining: parseNumberHeader(headers, "X-RateLimit-Remaining"),
|
|
41
|
+
reset: headers.get("X-RateLimit-Reset") || undefined,
|
|
42
|
+
policy: headers.get("X-RateLimit-Policy") || undefined,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function mergeHeaders(base, extra) {
|
|
46
|
+
const headers = new Headers(base);
|
|
47
|
+
if (extra) {
|
|
48
|
+
const additions = new Headers(extra);
|
|
49
|
+
additions.forEach((value, key) => {
|
|
50
|
+
headers.set(key, value);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return headers;
|
|
54
|
+
}
|
|
55
|
+
async function parsePayload(response) {
|
|
56
|
+
const contentType = response.headers.get("content-type") || "";
|
|
57
|
+
if (contentType.includes("application/json")) {
|
|
58
|
+
return response.json();
|
|
59
|
+
}
|
|
60
|
+
const text = await response.text();
|
|
61
|
+
return text ? { message: text } : undefined;
|
|
62
|
+
}
|
|
63
|
+
function createAbortContext(signal, timeoutMs) {
|
|
64
|
+
if (!signal && (!timeoutMs || timeoutMs <= 0)) {
|
|
65
|
+
return {
|
|
66
|
+
signal: undefined,
|
|
67
|
+
cleanup: () => undefined,
|
|
68
|
+
didTimeout: () => false,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
let timedOut = false;
|
|
73
|
+
let timeoutId;
|
|
74
|
+
let onAbort;
|
|
75
|
+
if (signal) {
|
|
76
|
+
if (signal.aborted) {
|
|
77
|
+
controller.abort(signal.reason);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
onAbort = () => controller.abort(signal.reason);
|
|
81
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (timeoutMs && timeoutMs > 0) {
|
|
85
|
+
timeoutId = setTimeout(() => {
|
|
86
|
+
timedOut = true;
|
|
87
|
+
controller.abort();
|
|
88
|
+
}, timeoutMs);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
signal: controller.signal,
|
|
92
|
+
cleanup: () => {
|
|
93
|
+
if (timeoutId)
|
|
94
|
+
clearTimeout(timeoutId);
|
|
95
|
+
if (signal && onAbort)
|
|
96
|
+
signal.removeEventListener("abort", onAbort);
|
|
97
|
+
},
|
|
98
|
+
didTimeout: () => timedOut,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export class NFLMetaClientCore {
|
|
102
|
+
apiKey;
|
|
103
|
+
baseUrl;
|
|
104
|
+
timeoutMs;
|
|
105
|
+
fetchImpl;
|
|
106
|
+
defaultHeaders;
|
|
107
|
+
constructor(options = {}) {
|
|
108
|
+
this.apiKey = options.apiKey?.trim() || undefined;
|
|
109
|
+
this.baseUrl = normalizeBaseUrl(options.baseUrl);
|
|
110
|
+
this.timeoutMs = options.timeoutMs;
|
|
111
|
+
this.fetchImpl = options.fetch || fetch;
|
|
112
|
+
this.defaultHeaders = options.headers;
|
|
113
|
+
}
|
|
114
|
+
async get(path, options = {}) {
|
|
115
|
+
const url = isAbsoluteUrl(path) ? new URL(path) : new URL(path, `${this.baseUrl}/`);
|
|
116
|
+
appendQuery(url, options.query);
|
|
117
|
+
const headers = mergeHeaders(this.defaultHeaders, options.headers);
|
|
118
|
+
headers.set("Accept", "application/json");
|
|
119
|
+
if (this.apiKey && !headers.has("X-NFLMeta-Key")) {
|
|
120
|
+
headers.set("X-NFLMeta-Key", this.apiKey);
|
|
121
|
+
}
|
|
122
|
+
const abort = createAbortContext(options.signal, this.timeoutMs);
|
|
123
|
+
try {
|
|
124
|
+
const response = await this.fetchImpl(url, {
|
|
125
|
+
method: "GET",
|
|
126
|
+
headers,
|
|
127
|
+
signal: abort.signal,
|
|
128
|
+
});
|
|
129
|
+
const rateLimit = parseRateLimit(response.headers);
|
|
130
|
+
const payload = await parsePayload(response);
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
throw createHttpError(response.status, payload, rateLimit);
|
|
133
|
+
}
|
|
134
|
+
if (typeof payload !== "object" || payload === null || !("data" in payload)) {
|
|
135
|
+
throw createHttpError(response.status, payload, rateLimit);
|
|
136
|
+
}
|
|
137
|
+
const body = payload;
|
|
138
|
+
return {
|
|
139
|
+
data: body.data,
|
|
140
|
+
meta: body.meta,
|
|
141
|
+
status: response.status,
|
|
142
|
+
rateLimit,
|
|
143
|
+
headers: response.headers,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (abort.didTimeout()) {
|
|
148
|
+
throw new NFLMetaTimeoutError(this.timeoutMs || 0);
|
|
149
|
+
}
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
abort.cleanup();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RateLimitInfo } from "./types.js";
|
|
2
|
+
export interface NFLMetaErrorDetails {
|
|
3
|
+
code?: string;
|
|
4
|
+
payload?: unknown;
|
|
5
|
+
rateLimit?: RateLimitInfo;
|
|
6
|
+
}
|
|
7
|
+
export declare class NFLMetaError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly code?: string;
|
|
10
|
+
readonly payload?: unknown;
|
|
11
|
+
readonly rateLimit?: RateLimitInfo;
|
|
12
|
+
constructor(message: string, status: number, details?: NFLMetaErrorDetails);
|
|
13
|
+
}
|
|
14
|
+
export declare class NFLMetaBadRequestError extends NFLMetaError {
|
|
15
|
+
constructor(message: string, details?: NFLMetaErrorDetails);
|
|
16
|
+
}
|
|
17
|
+
export declare class NFLMetaUnauthorizedError extends NFLMetaError {
|
|
18
|
+
constructor(message: string, details?: NFLMetaErrorDetails);
|
|
19
|
+
}
|
|
20
|
+
export declare class NFLMetaNotFoundError extends NFLMetaError {
|
|
21
|
+
constructor(message: string, details?: NFLMetaErrorDetails);
|
|
22
|
+
}
|
|
23
|
+
export declare class NFLMetaRateLimitError extends NFLMetaError {
|
|
24
|
+
constructor(message: string, details?: NFLMetaErrorDetails);
|
|
25
|
+
}
|
|
26
|
+
export declare class NFLMetaTimeoutError extends Error {
|
|
27
|
+
constructor(timeoutMs: number);
|
|
28
|
+
}
|
|
29
|
+
export declare function createHttpError(status: number, payload: unknown, rateLimit?: RateLimitInfo): NFLMetaError;
|
|
30
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAC;AAE/D,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAQ/E;AAED,qBAAa,sBAAuB,SAAQ,YAAY;gBAC1C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAI/D;AAED,qBAAa,wBAAyB,SAAQ,YAAY;gBAC5C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAI/D;AAED,qBAAa,oBAAqB,SAAQ,YAAY;gBACxC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAI/D;AAED,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;CAI/D;AAED,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,SAAS,EAAE,MAAM;CAI9B;AAqBD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,YAAY,CAczG"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export class NFLMetaError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
code;
|
|
4
|
+
payload;
|
|
5
|
+
rateLimit;
|
|
6
|
+
constructor(message, status, details = {}) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "NFLMetaError";
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.code = details.code;
|
|
11
|
+
this.payload = details.payload;
|
|
12
|
+
this.rateLimit = details.rateLimit;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class NFLMetaBadRequestError extends NFLMetaError {
|
|
16
|
+
constructor(message, details = {}) {
|
|
17
|
+
super(message, 400, details);
|
|
18
|
+
this.name = "NFLMetaBadRequestError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class NFLMetaUnauthorizedError extends NFLMetaError {
|
|
22
|
+
constructor(message, details = {}) {
|
|
23
|
+
super(message, 401, details);
|
|
24
|
+
this.name = "NFLMetaUnauthorizedError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class NFLMetaNotFoundError extends NFLMetaError {
|
|
28
|
+
constructor(message, details = {}) {
|
|
29
|
+
super(message, 404, details);
|
|
30
|
+
this.name = "NFLMetaNotFoundError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class NFLMetaRateLimitError extends NFLMetaError {
|
|
34
|
+
constructor(message, details = {}) {
|
|
35
|
+
super(message, 429, details);
|
|
36
|
+
this.name = "NFLMetaRateLimitError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class NFLMetaTimeoutError extends Error {
|
|
40
|
+
constructor(timeoutMs) {
|
|
41
|
+
super(`NFLMeta request timed out after ${timeoutMs}ms`);
|
|
42
|
+
this.name = "NFLMetaTimeoutError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isRecord(value) {
|
|
46
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
function messageFromPayload(payload, fallback) {
|
|
49
|
+
if (!isRecord(payload))
|
|
50
|
+
return fallback;
|
|
51
|
+
const error = payload.error;
|
|
52
|
+
if (!isRecord(error))
|
|
53
|
+
return fallback;
|
|
54
|
+
const message = error.message;
|
|
55
|
+
return typeof message === "string" && message.trim() ? message : fallback;
|
|
56
|
+
}
|
|
57
|
+
function codeFromPayload(payload) {
|
|
58
|
+
if (!isRecord(payload))
|
|
59
|
+
return undefined;
|
|
60
|
+
const error = payload.error;
|
|
61
|
+
if (!isRecord(error))
|
|
62
|
+
return undefined;
|
|
63
|
+
return typeof error.code === "string" && error.code.trim() ? error.code : undefined;
|
|
64
|
+
}
|
|
65
|
+
export function createHttpError(status, payload, rateLimit) {
|
|
66
|
+
const fallback = `NFLMeta request failed with status ${status}`;
|
|
67
|
+
const message = messageFromPayload(payload, fallback);
|
|
68
|
+
const details = {
|
|
69
|
+
code: codeFromPayload(payload),
|
|
70
|
+
payload,
|
|
71
|
+
rateLimit,
|
|
72
|
+
};
|
|
73
|
+
if (status === 400)
|
|
74
|
+
return new NFLMetaBadRequestError(message, details);
|
|
75
|
+
if (status === 401)
|
|
76
|
+
return new NFLMetaUnauthorizedError(message, details);
|
|
77
|
+
if (status === 404)
|
|
78
|
+
return new NFLMetaNotFoundError(message, details);
|
|
79
|
+
if (status === 429)
|
|
80
|
+
return new NFLMetaRateLimitError(message, details);
|
|
81
|
+
return new NFLMetaError(message, status, details);
|
|
82
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NFLMetaClientCore } from "./client.js";
|
|
2
|
+
import { AllStarGamesResource, AssetsResource, CoachesResource, ContributorsResource, ExecutivesResource, GamesResource, HallOfFameResource, HealthResource, HistoryResource, MetadataResource, PlayoffGamesResource, PlayoffsResource, PlayersResource, ReferenceResource, SeasonsResource, StaffResource, StandingsResource, StatsResource, SuperBowlsResource, TeamsResource, UsageResource } from "./resources.js";
|
|
3
|
+
import { NFLMetaError, NFLMetaBadRequestError, NFLMetaNotFoundError, NFLMetaRateLimitError, NFLMetaTimeoutError, NFLMetaUnauthorizedError } from "./errors.js";
|
|
4
|
+
export * from "./errors.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export declare class NFLMetaClient extends NFLMetaClientCore {
|
|
7
|
+
readonly health: HealthResource;
|
|
8
|
+
readonly usage: UsageResource;
|
|
9
|
+
readonly metadata: MetadataResource;
|
|
10
|
+
readonly seasons: SeasonsResource;
|
|
11
|
+
readonly teams: TeamsResource;
|
|
12
|
+
readonly players: PlayersResource;
|
|
13
|
+
readonly games: GamesResource;
|
|
14
|
+
readonly playoffGames: PlayoffGamesResource;
|
|
15
|
+
readonly standings: StandingsResource;
|
|
16
|
+
readonly playoffs: PlayoffsResource;
|
|
17
|
+
readonly superBowls: SuperBowlsResource;
|
|
18
|
+
readonly history: HistoryResource;
|
|
19
|
+
readonly hallOfFame: HallOfFameResource;
|
|
20
|
+
readonly contributors: ContributorsResource;
|
|
21
|
+
readonly executives: ExecutivesResource;
|
|
22
|
+
readonly staff: StaffResource;
|
|
23
|
+
readonly coaches: CoachesResource;
|
|
24
|
+
readonly assets: AssetsResource;
|
|
25
|
+
readonly allStarGames: AllStarGamesResource;
|
|
26
|
+
readonly stats: StatsResource;
|
|
27
|
+
readonly reference: ReferenceResource;
|
|
28
|
+
constructor(options?: ConstructorParameters<typeof NFLMetaClientCore>[0]);
|
|
29
|
+
}
|
|
30
|
+
export declare function createNFLMetaClient(options?: ConstructorParameters<typeof NFLMetaClient>[0]): NFLMetaClient;
|
|
31
|
+
export { NFLMetaBadRequestError, NFLMetaError, NFLMetaNotFoundError, NFLMetaRateLimitError, NFLMetaTimeoutError, NFLMetaUnauthorizedError, };
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,aAAa,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE/J,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAE3B,qBAAa,aAAc,SAAQ,iBAAiB;IAClD,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;gBAE1B,OAAO,GAAE,qBAAqB,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAM;CAwB7E;AAED,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,qBAAqB,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAM,GAAG,aAAa,CAE/G;AAED,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,wBAAwB,GACzB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { NFLMetaClientCore } from "./client.js";
|
|
2
|
+
import { AllStarGamesResource, AssetsResource, CoachesResource, ContributorsResource, ExecutivesResource, GamesResource, HallOfFameResource, HealthResource, HistoryResource, MetadataResource, PlayoffGamesResource, PlayoffsResource, PlayersResource, ReferenceResource, SeasonsResource, StaffResource, StandingsResource, StatsResource, SuperBowlsResource, TeamsResource, UsageResource, } from "./resources.js";
|
|
3
|
+
import { NFLMetaError, NFLMetaBadRequestError, NFLMetaNotFoundError, NFLMetaRateLimitError, NFLMetaTimeoutError, NFLMetaUnauthorizedError } from "./errors.js";
|
|
4
|
+
export * from "./errors.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export class NFLMetaClient extends NFLMetaClientCore {
|
|
7
|
+
health;
|
|
8
|
+
usage;
|
|
9
|
+
metadata;
|
|
10
|
+
seasons;
|
|
11
|
+
teams;
|
|
12
|
+
players;
|
|
13
|
+
games;
|
|
14
|
+
playoffGames;
|
|
15
|
+
standings;
|
|
16
|
+
playoffs;
|
|
17
|
+
superBowls;
|
|
18
|
+
history;
|
|
19
|
+
hallOfFame;
|
|
20
|
+
contributors;
|
|
21
|
+
executives;
|
|
22
|
+
staff;
|
|
23
|
+
coaches;
|
|
24
|
+
assets;
|
|
25
|
+
allStarGames;
|
|
26
|
+
stats;
|
|
27
|
+
reference;
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
super(options);
|
|
30
|
+
this.health = new HealthResource(this);
|
|
31
|
+
this.usage = new UsageResource(this);
|
|
32
|
+
this.metadata = new MetadataResource(this);
|
|
33
|
+
this.seasons = new SeasonsResource(this);
|
|
34
|
+
this.teams = new TeamsResource(this);
|
|
35
|
+
this.players = new PlayersResource(this);
|
|
36
|
+
this.games = new GamesResource(this);
|
|
37
|
+
this.playoffGames = new PlayoffGamesResource(this);
|
|
38
|
+
this.standings = new StandingsResource(this);
|
|
39
|
+
this.playoffs = new PlayoffsResource(this);
|
|
40
|
+
this.superBowls = new SuperBowlsResource(this);
|
|
41
|
+
this.history = new HistoryResource(this);
|
|
42
|
+
this.hallOfFame = new HallOfFameResource(this);
|
|
43
|
+
this.contributors = new ContributorsResource(this, ["contributors"]);
|
|
44
|
+
this.executives = new ExecutivesResource(this, ["executives"]);
|
|
45
|
+
this.staff = new StaffResource(this, ["staff"]);
|
|
46
|
+
this.coaches = new CoachesResource(this, ["coaches"]);
|
|
47
|
+
this.assets = new AssetsResource(this);
|
|
48
|
+
this.allStarGames = new AllStarGamesResource(this);
|
|
49
|
+
this.stats = new StatsResource(this);
|
|
50
|
+
this.reference = new ReferenceResource(this);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function createNFLMetaClient(options = {}) {
|
|
54
|
+
return new NFLMetaClient(options);
|
|
55
|
+
}
|
|
56
|
+
export { NFLMetaBadRequestError, NFLMetaError, NFLMetaNotFoundError, NFLMetaRateLimitError, NFLMetaTimeoutError, NFLMetaUnauthorizedError, };
|