tmdb-kit 1.0.0 → 1.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/README.md +455 -196
- package/dist/cli.js +3823 -0
- package/dist/client.d.cts +71 -0
- package/dist/client.d.ts +71 -0
- package/dist/errors.d.cts +86 -0
- package/dist/errors.d.ts +86 -0
- package/dist/helpers/cache.d.cts +28 -0
- package/dist/helpers/cache.d.ts +28 -0
- package/dist/helpers/pagination.d.cts +35 -0
- package/dist/helpers/pagination.d.ts +35 -0
- package/dist/helpers/retry.d.cts +47 -0
- package/dist/helpers/retry.d.ts +47 -0
- package/dist/helpers/timeout.d.cts +20 -0
- package/dist/helpers/timeout.d.ts +20 -0
- package/dist/http.d.cts +80 -0
- package/dist/http.d.ts +80 -0
- package/dist/index.cjs +1115 -768
- package/dist/index.cjs.map +27 -1
- package/dist/index.d.cts +13 -783
- package/dist/index.d.ts +13 -783
- package/dist/index.js +1074 -744
- package/dist/index.js.map +27 -1
- package/dist/query.d.cts +91 -0
- package/dist/query.d.ts +91 -0
- package/dist/resources/configuration.d.cts +17 -0
- package/dist/resources/configuration.d.ts +17 -0
- package/dist/resources/genres.d.cts +13 -0
- package/dist/resources/genres.d.ts +13 -0
- package/dist/resources/images.d.cts +17 -0
- package/dist/resources/images.d.ts +17 -0
- package/dist/resources/movies.d.cts +21 -0
- package/dist/resources/movies.d.ts +21 -0
- package/dist/resources/people.d.cts +14 -0
- package/dist/resources/people.d.ts +14 -0
- package/dist/resources/search.d.cts +15 -0
- package/dist/resources/search.d.ts +15 -0
- package/dist/resources/trending.d.cts +23 -0
- package/dist/resources/trending.d.ts +23 -0
- package/dist/resources/tv.d.cts +30 -0
- package/dist/resources/tv.d.ts +30 -0
- package/dist/search-guards.d.cts +32 -0
- package/dist/search-guards.d.ts +32 -0
- package/dist/types.d.cts +550 -0
- package/dist/types.d.ts +550 -0
- package/package.json +26 -19
package/dist/index.js
CHANGED
|
@@ -1,798 +1,1128 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.retryAfter = options.retryAfter;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Create the appropriate error instance for a non-2xx TMDB response.
|
|
77
|
-
*
|
|
78
|
-
* Returns a {@link TMDBRateLimitError} when the status is 429, otherwise
|
|
79
|
-
* a generic {@link TMDBResponseError}. The error message is extracted from
|
|
80
|
-
* the TMDB `status_message` field when available.
|
|
81
|
-
*/
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
class TMDBError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = "TMDBError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class TMDBRequestError extends TMDBError {
|
|
10
|
+
constructor(message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
this.name = "TMDBRequestError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class TMDBTimeoutError extends TMDBError {
|
|
17
|
+
timeoutMs;
|
|
18
|
+
constructor(timeoutMs, message = `TMDB request timed out after ${timeoutMs}ms`) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "TMDBTimeoutError";
|
|
21
|
+
this.timeoutMs = timeoutMs;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class TMDBResponseError extends TMDBError {
|
|
26
|
+
body;
|
|
27
|
+
headers;
|
|
28
|
+
requestId;
|
|
29
|
+
status;
|
|
30
|
+
statusCode;
|
|
31
|
+
statusMessage;
|
|
32
|
+
statusText;
|
|
33
|
+
url;
|
|
34
|
+
constructor(message, options) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "TMDBResponseError";
|
|
37
|
+
this.body = options.body;
|
|
38
|
+
this.headers = options.headers;
|
|
39
|
+
this.requestId = options.headers.get("x-request-id");
|
|
40
|
+
this.status = options.status;
|
|
41
|
+
this.statusText = options.statusText;
|
|
42
|
+
this.url = options.url;
|
|
43
|
+
const body = isErrorResponseBody(options.body) ? options.body : undefined;
|
|
44
|
+
this.statusCode = body?.status_code;
|
|
45
|
+
this.statusMessage = body?.status_message;
|
|
46
|
+
}
|
|
47
|
+
get isRateLimit() {
|
|
48
|
+
return this.status === 429;
|
|
49
|
+
}
|
|
50
|
+
get isNotFound() {
|
|
51
|
+
return this.status === 404;
|
|
52
|
+
}
|
|
53
|
+
get isUnauthorized() {
|
|
54
|
+
return this.status === 401;
|
|
55
|
+
}
|
|
56
|
+
get isForbidden() {
|
|
57
|
+
return this.status === 403;
|
|
58
|
+
}
|
|
59
|
+
get isServerError() {
|
|
60
|
+
return this.status >= 500 && this.status < 600;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
class TMDBRateLimitError extends TMDBResponseError {
|
|
65
|
+
retryAfter;
|
|
66
|
+
constructor(message, options) {
|
|
67
|
+
super(message, options);
|
|
68
|
+
this.name = "TMDBRateLimitError";
|
|
69
|
+
this.retryAfter = options.retryAfter;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
82
72
|
function createResponseError(options) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* Falls back to 1 second when the header is missing or unparseable.
|
|
94
|
-
*/
|
|
73
|
+
const body = isErrorResponseBody(options.body) ? options.body : undefined;
|
|
74
|
+
const message = body?.status_message ?? `${options.status} ${options.statusText}`.trim();
|
|
75
|
+
if (options.status === 429) {
|
|
76
|
+
return new TMDBRateLimitError(message, {
|
|
77
|
+
...options,
|
|
78
|
+
retryAfter: parseRetryAfter(options.headers.get("retry-after"))
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return new TMDBResponseError(message, options);
|
|
82
|
+
}
|
|
95
83
|
function parseRetryAfter(value) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
84
|
+
if (value === null || value === undefined) {
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
const trimmed = value.trim();
|
|
88
|
+
if (trimmed === "") {
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
const seconds = Number(trimmed);
|
|
92
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
93
|
+
return seconds;
|
|
94
|
+
}
|
|
95
|
+
const date = Date.parse(trimmed);
|
|
96
|
+
if (Number.isFinite(date)) {
|
|
97
|
+
const deltaMs = date - Date.now();
|
|
98
|
+
return Math.max(1, Math.ceil(deltaMs / 1000));
|
|
99
|
+
}
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
109
102
|
function isErrorResponseBody(value) {
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
* - Arrays are joined with commas (TMDB convention).
|
|
117
|
-
* - All values are converted to strings.
|
|
118
|
-
*/
|
|
103
|
+
return typeof value === "object" && value !== null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/query.ts
|
|
107
|
+
var DEFAULT_API_BASE_URL = "https://api.themoviedb.org/3";
|
|
108
|
+
var DEFAULT_IMAGE_BASE_URL = "https://image.tmdb.org/t/p";
|
|
119
109
|
function appendQuery(url, query) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
* If `query.language` is set it takes precedence; otherwise the client's
|
|
133
|
-
* default language is used.
|
|
134
|
-
*/
|
|
110
|
+
for (const [key, value] of Object.entries(query)) {
|
|
111
|
+
if (value === undefined || value === null) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
url.searchParams.set(key, value.map(String).join(","));
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
url.searchParams.set(key, String(value));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
135
121
|
function withLanguage(defaults, query) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Merge language and region defaults for list endpoints.
|
|
144
|
-
*
|
|
145
|
-
* Combines {@link withLanguage} with region fallback from client defaults.
|
|
146
|
-
*/
|
|
122
|
+
const language = typeof query.language === "string" ? query.language : defaults.language;
|
|
123
|
+
return {
|
|
124
|
+
...query,
|
|
125
|
+
language
|
|
126
|
+
};
|
|
127
|
+
}
|
|
147
128
|
function withListDefaults(defaults, query) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Convert a string or string array to a comma-separated list.
|
|
156
|
-
*
|
|
157
|
-
* Returns `undefined` if the input is `undefined` (skips the parameter).
|
|
158
|
-
* TMDB uses comma-separated values for multi-value query parameters.
|
|
159
|
-
*/
|
|
129
|
+
const region = typeof query.region === "string" ? query.region : defaults.region;
|
|
130
|
+
return {
|
|
131
|
+
...withLanguage(defaults, query),
|
|
132
|
+
region
|
|
133
|
+
};
|
|
134
|
+
}
|
|
160
135
|
function toCommaList(value) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
*
|
|
167
|
-
* @throws {TMDBRequestError} If `value` is not a positive integer.
|
|
168
|
-
*/
|
|
136
|
+
if (value === undefined) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
return typeof value === "string" ? value : value.join(",");
|
|
140
|
+
}
|
|
169
141
|
function toId(value, name) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
142
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
143
|
+
throw new TMDBRequestError(`${name} must be a positive integer`);
|
|
144
|
+
}
|
|
145
|
+
return String(value);
|
|
146
|
+
}
|
|
147
|
+
function toSeasonNumber(value) {
|
|
148
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
149
|
+
throw new TMDBRequestError("seasonNumber must be a non-negative integer");
|
|
150
|
+
}
|
|
151
|
+
return String(value);
|
|
152
|
+
}
|
|
153
|
+
function toGroupId(value) {
|
|
154
|
+
const groupId = value.trim();
|
|
155
|
+
if (!/^[A-Za-z0-9_-]+$/.test(groupId)) {
|
|
156
|
+
throw new TMDBRequestError("groupId must be a non-empty identifier");
|
|
157
|
+
}
|
|
158
|
+
return groupId;
|
|
159
|
+
}
|
|
178
160
|
function toSearchQuery(value) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
*
|
|
186
|
-
* @throws {TMDBRequestError} If `value` is not `"day"` or `"week"`.
|
|
187
|
-
*/
|
|
161
|
+
const query = value.trim();
|
|
162
|
+
if (query.length === 0) {
|
|
163
|
+
throw new TMDBRequestError("search query must not be empty");
|
|
164
|
+
}
|
|
165
|
+
return query;
|
|
166
|
+
}
|
|
188
167
|
function toTimeWindow(value) {
|
|
189
|
-
|
|
190
|
-
|
|
168
|
+
if (value !== "day" && value !== "week") {
|
|
169
|
+
throw new TMDBRequestError('timeWindow must be either "day" or "week"');
|
|
170
|
+
}
|
|
171
|
+
return value;
|
|
191
172
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Build a full TMDB image URL from the path returned by API payloads.
|
|
194
|
-
* Returns null for nullish image paths so UI code can branch naturally.
|
|
195
|
-
*/
|
|
196
173
|
function buildImageUrl(path, size = "original", options = {}) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
174
|
+
if (path === undefined || path === null || path.trim() === "") {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_IMAGE_BASE_URL);
|
|
178
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
179
|
+
const url = `${baseUrl}/${size}${normalizedPath}`;
|
|
180
|
+
return options.transform ? options.transform(url) : url;
|
|
200
181
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Strip trailing slashes from a base URL to ensure consistent path joining.
|
|
203
|
-
*/
|
|
204
182
|
function normalizeBaseUrl(baseUrl) {
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
* text for certain error conditions).
|
|
294
|
-
*/
|
|
183
|
+
return baseUrl.replace(/\/+$/, "");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/http.ts
|
|
187
|
+
class TMDBHttpClient {
|
|
188
|
+
defaults;
|
|
189
|
+
imageTransform;
|
|
190
|
+
#apiKey;
|
|
191
|
+
#accessToken;
|
|
192
|
+
#baseUrl;
|
|
193
|
+
#fetch;
|
|
194
|
+
#headers;
|
|
195
|
+
constructor(options) {
|
|
196
|
+
const accessToken = normalizeSecret("accessToken" in options ? options.accessToken : undefined);
|
|
197
|
+
const apiKey = normalizeSecret("apiKey" in options ? options.apiKey : undefined);
|
|
198
|
+
if (Boolean(accessToken) === Boolean(apiKey)) {
|
|
199
|
+
throw new TMDBRequestError("Provide exactly one of accessToken or apiKey");
|
|
200
|
+
}
|
|
201
|
+
this.#accessToken = accessToken;
|
|
202
|
+
this.#apiKey = apiKey;
|
|
203
|
+
this.#baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_API_BASE_URL);
|
|
204
|
+
this.#fetch = options.fetch;
|
|
205
|
+
this.#headers = options.headers;
|
|
206
|
+
this.defaults = {
|
|
207
|
+
imageBaseUrl: normalizeBaseUrl(options.imageBaseUrl ?? DEFAULT_IMAGE_BASE_URL),
|
|
208
|
+
language: options.defaultLanguage,
|
|
209
|
+
region: options.defaultRegion
|
|
210
|
+
};
|
|
211
|
+
this.imageTransform = options.images?.transform;
|
|
212
|
+
}
|
|
213
|
+
async get(path, options = {}) {
|
|
214
|
+
const url = this.#createUrl(path, options.query ?? {});
|
|
215
|
+
const headers = this.#createHeaders(options.headers);
|
|
216
|
+
const fetchImpl = this.#resolveFetch();
|
|
217
|
+
let response;
|
|
218
|
+
try {
|
|
219
|
+
response = await fetchImpl(url, {
|
|
220
|
+
headers,
|
|
221
|
+
method: "GET",
|
|
222
|
+
signal: options.signal
|
|
223
|
+
});
|
|
224
|
+
} catch (error) {
|
|
225
|
+
throw new TMDBRequestError(`TMDB request failed: ${String(error)}`, { cause: error });
|
|
226
|
+
}
|
|
227
|
+
const body = await readJson(response);
|
|
228
|
+
if (!response.ok) {
|
|
229
|
+
throw createResponseError({
|
|
230
|
+
body,
|
|
231
|
+
headers: response.headers,
|
|
232
|
+
status: response.status,
|
|
233
|
+
statusText: response.statusText,
|
|
234
|
+
url
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return body;
|
|
238
|
+
}
|
|
239
|
+
#resolveFetch() {
|
|
240
|
+
if (this.#fetch !== undefined) {
|
|
241
|
+
return this.#fetch;
|
|
242
|
+
}
|
|
243
|
+
const globalFetch = globalThis.fetch;
|
|
244
|
+
if (typeof globalFetch !== "function") {
|
|
245
|
+
throw new TMDBRequestError("No fetch implementation found. Pass options.fetch in this runtime.");
|
|
246
|
+
}
|
|
247
|
+
return globalFetch.bind(globalThis);
|
|
248
|
+
}
|
|
249
|
+
#createHeaders(headersInit) {
|
|
250
|
+
const headers = new Headers(this.#headers);
|
|
251
|
+
const requestHeaders = new Headers(headersInit);
|
|
252
|
+
headers.set("Accept", "application/json");
|
|
253
|
+
for (const [key, value] of requestHeaders) {
|
|
254
|
+
headers.set(key, value);
|
|
255
|
+
}
|
|
256
|
+
if (this.#accessToken !== undefined) {
|
|
257
|
+
headers.set("Authorization", `Bearer ${this.#accessToken}`);
|
|
258
|
+
}
|
|
259
|
+
return headers;
|
|
260
|
+
}
|
|
261
|
+
#createUrl(path, query) {
|
|
262
|
+
const relativePath = path.replace(/^\/+/, "");
|
|
263
|
+
const url = new URL(relativePath, `${this.#baseUrl}/`);
|
|
264
|
+
appendQuery(url, {
|
|
265
|
+
...query,
|
|
266
|
+
api_key: this.#apiKey
|
|
267
|
+
});
|
|
268
|
+
return url.toString();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
295
271
|
async function readJson(response) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
* strings as undefined (not provided).
|
|
307
|
-
*/
|
|
272
|
+
const text = await response.text();
|
|
273
|
+
if (text.length === 0) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
return JSON.parse(text);
|
|
278
|
+
} catch {
|
|
279
|
+
return text;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
308
282
|
function normalizeSecret(value) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
283
|
+
const secret = value?.trim();
|
|
284
|
+
return secret === "" ? undefined : secret;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/resources/configuration.ts
|
|
288
|
+
class ConfigurationResource {
|
|
289
|
+
#transport;
|
|
290
|
+
constructor(transport) {
|
|
291
|
+
this.#transport = transport;
|
|
292
|
+
}
|
|
293
|
+
details(options = {}) {
|
|
294
|
+
return this.#transport.get("/configuration", { signal: options.signal });
|
|
295
|
+
}
|
|
296
|
+
countries(options = {}) {
|
|
297
|
+
return this.#transport.get("/configuration/countries", { signal: options.signal });
|
|
298
|
+
}
|
|
299
|
+
jobs(options = {}) {
|
|
300
|
+
return this.#transport.get("/configuration/jobs", { signal: options.signal });
|
|
301
|
+
}
|
|
302
|
+
languages(options = {}) {
|
|
303
|
+
return this.#transport.get("/configuration/languages", { signal: options.signal });
|
|
304
|
+
}
|
|
305
|
+
primaryTranslations(options = {}) {
|
|
306
|
+
return this.#transport.get("/configuration/primary_translations", {
|
|
307
|
+
signal: options.signal
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
timezones(options = {}) {
|
|
311
|
+
return this.#transport.get("/configuration/timezones", { signal: options.signal });
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// src/resources/genres.ts
|
|
316
|
+
class GenresResource {
|
|
317
|
+
#transport;
|
|
318
|
+
constructor(transport) {
|
|
319
|
+
this.#transport = transport;
|
|
320
|
+
}
|
|
321
|
+
movies(options = {}) {
|
|
322
|
+
return this.#transport.get("/genre/movie/list", {
|
|
323
|
+
query: withLanguage(this.#transport.defaults, {
|
|
324
|
+
language: options.language
|
|
325
|
+
}),
|
|
326
|
+
signal: options.signal
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
tv(options = {}) {
|
|
330
|
+
return this.#transport.get("/genre/tv/list", {
|
|
331
|
+
query: withLanguage(this.#transport.defaults, {
|
|
332
|
+
language: options.language
|
|
333
|
+
}),
|
|
334
|
+
signal: options.signal
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/resources/images.ts
|
|
340
|
+
class ImagesHelper {
|
|
341
|
+
#transport;
|
|
342
|
+
#transform;
|
|
343
|
+
constructor(transport, transform) {
|
|
344
|
+
this.#transport = transport;
|
|
345
|
+
this.#transform = transform;
|
|
346
|
+
}
|
|
347
|
+
url(path, size = "original", options = {}) {
|
|
348
|
+
return buildImageUrl(path, size, {
|
|
349
|
+
baseUrl: this.#transport.defaults.imageBaseUrl,
|
|
350
|
+
transform: options.transform ?? this.#transform
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/resources/movies.ts
|
|
356
|
+
class MoviesResource {
|
|
357
|
+
#transport;
|
|
358
|
+
constructor(transport) {
|
|
359
|
+
this.#transport = transport;
|
|
360
|
+
}
|
|
361
|
+
popular(options = {}) {
|
|
362
|
+
return this.#transport.get("/movie/popular", {
|
|
363
|
+
query: movieListQuery(this.#transport, options),
|
|
364
|
+
signal: options.signal
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
topRated(options = {}) {
|
|
368
|
+
return this.#transport.get("/movie/top_rated", {
|
|
369
|
+
query: movieListQuery(this.#transport, options),
|
|
370
|
+
signal: options.signal
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
nowPlaying(options = {}) {
|
|
374
|
+
return this.#transport.get("/movie/now_playing", {
|
|
375
|
+
query: movieListQuery(this.#transport, options),
|
|
376
|
+
signal: options.signal
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
upcoming(options = {}) {
|
|
380
|
+
return this.#transport.get("/movie/upcoming", {
|
|
381
|
+
query: movieListQuery(this.#transport, options),
|
|
382
|
+
signal: options.signal
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
details(movieId, options = {}) {
|
|
386
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}`, {
|
|
387
|
+
query: withLanguage(this.#transport.defaults, {
|
|
388
|
+
append_to_response: toCommaList(options.appendToResponse),
|
|
389
|
+
language: options.language
|
|
390
|
+
}),
|
|
391
|
+
signal: options.signal
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
credits(movieId, options = {}) {
|
|
395
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/credits`, {
|
|
396
|
+
query: withLanguage(this.#transport.defaults, {
|
|
397
|
+
language: options.language
|
|
398
|
+
}),
|
|
399
|
+
signal: options.signal
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
images(movieId, options = {}) {
|
|
403
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/images`, {
|
|
404
|
+
query: withLanguage(this.#transport.defaults, {
|
|
405
|
+
include_image_language: toCommaList(options.includeImageLanguage),
|
|
406
|
+
language: options.language
|
|
407
|
+
}),
|
|
408
|
+
signal: options.signal
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
recommendations(movieId, options = {}) {
|
|
412
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/recommendations`, {
|
|
413
|
+
query: movieListQuery(this.#transport, options),
|
|
414
|
+
signal: options.signal
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
similar(movieId, options = {}) {
|
|
418
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/similar`, {
|
|
419
|
+
query: movieListQuery(this.#transport, options),
|
|
420
|
+
signal: options.signal
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
videos(movieId, options = {}) {
|
|
424
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/videos`, {
|
|
425
|
+
query: withLanguage(this.#transport.defaults, {
|
|
426
|
+
language: options.language
|
|
427
|
+
}),
|
|
428
|
+
signal: options.signal
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
434
432
|
function movieListQuery(transport, options) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
433
|
+
return withListDefaults(transport.defaults, {
|
|
434
|
+
language: options.language,
|
|
435
|
+
page: options.page,
|
|
436
|
+
region: options.region
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// src/resources/people.ts
|
|
441
|
+
class PeopleResource {
|
|
442
|
+
#transport;
|
|
443
|
+
constructor(transport) {
|
|
444
|
+
this.#transport = transport;
|
|
445
|
+
}
|
|
446
|
+
popular(options = {}) {
|
|
447
|
+
return this.#transport.get("/person/popular", {
|
|
448
|
+
query: peopleListQuery(this.#transport, options),
|
|
449
|
+
signal: options.signal
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
details(personId, options = {}) {
|
|
453
|
+
return this.#transport.get(`/person/${toId(personId, "personId")}`, {
|
|
454
|
+
query: withLanguage(this.#transport.defaults, {
|
|
455
|
+
language: options.language
|
|
456
|
+
}),
|
|
457
|
+
signal: options.signal
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
combinedCredits(personId, options = {}) {
|
|
461
|
+
return this.#transport.get(`/person/${toId(personId, "personId")}/combined_credits`, {
|
|
462
|
+
query: withLanguage(this.#transport.defaults, {
|
|
463
|
+
language: options.language
|
|
464
|
+
}),
|
|
465
|
+
signal: options.signal
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
461
469
|
function peopleListQuery(transport, options) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
470
|
+
return withLanguage(transport.defaults, {
|
|
471
|
+
language: options.language,
|
|
472
|
+
page: options.page
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// src/resources/search.ts
|
|
477
|
+
class SearchResource {
|
|
478
|
+
#transport;
|
|
479
|
+
constructor(transport) {
|
|
480
|
+
this.#transport = transport;
|
|
481
|
+
}
|
|
482
|
+
movies(query, options = {}) {
|
|
483
|
+
return this.#transport.get("/search/movie", {
|
|
484
|
+
query: movieSearchQuery(this.#transport, query, options),
|
|
485
|
+
signal: options.signal
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
tv(query, options = {}) {
|
|
489
|
+
return this.#transport.get("/search/tv", {
|
|
490
|
+
query: tvSearchQuery(this.#transport, query, options),
|
|
491
|
+
signal: options.signal
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
people(query, options = {}) {
|
|
495
|
+
return this.#transport.get("/search/person", {
|
|
496
|
+
query: commonSearchQuery(this.#transport, query, options),
|
|
497
|
+
signal: options.signal
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
async multi(query, options = {}) {
|
|
501
|
+
const response = await this.#transport.get("/search/multi", {
|
|
502
|
+
query: commonSearchQuery(this.#transport, query, options),
|
|
503
|
+
signal: options.signal
|
|
504
|
+
});
|
|
505
|
+
const excluded = options.exclude;
|
|
506
|
+
if (excluded === undefined || excluded.length === 0) {
|
|
507
|
+
return response;
|
|
508
|
+
}
|
|
509
|
+
const excludedSet = new Set(excluded);
|
|
510
|
+
return {
|
|
511
|
+
...response,
|
|
512
|
+
results: response.results.filter((result) => !excludedSet.has(result.media_type))
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
}
|
|
500
516
|
function movieSearchQuery(transport, query, options) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
/** Build query parameters for TV search. */
|
|
517
|
+
return withListDefaults(transport.defaults, {
|
|
518
|
+
include_adult: options.includeAdult,
|
|
519
|
+
language: options.language,
|
|
520
|
+
page: options.page,
|
|
521
|
+
primary_release_year: options.primaryReleaseYear,
|
|
522
|
+
query: toSearchQuery(query),
|
|
523
|
+
region: options.region,
|
|
524
|
+
year: options.year
|
|
525
|
+
});
|
|
526
|
+
}
|
|
512
527
|
function tvSearchQuery(transport, query, options) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
522
|
-
/** Build query parameters for person and multi-search. */
|
|
528
|
+
return withLanguage(transport.defaults, {
|
|
529
|
+
first_air_date_year: options.firstAirDateYear,
|
|
530
|
+
include_adult: options.includeAdult,
|
|
531
|
+
language: options.language,
|
|
532
|
+
page: options.page,
|
|
533
|
+
query: toSearchQuery(query),
|
|
534
|
+
year: options.year
|
|
535
|
+
});
|
|
536
|
+
}
|
|
523
537
|
function commonSearchQuery(transport, query, options) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
538
|
+
return withLanguage(transport.defaults, {
|
|
539
|
+
include_adult: options.includeAdult,
|
|
540
|
+
language: options.language,
|
|
541
|
+
page: options.page,
|
|
542
|
+
query: toSearchQuery(query)
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/resources/trending.ts
|
|
547
|
+
class TrendingResource {
|
|
548
|
+
#transport;
|
|
549
|
+
constructor(transport) {
|
|
550
|
+
this.#transport = transport;
|
|
551
|
+
}
|
|
552
|
+
all(timeWindow = "day", options = {}) {
|
|
553
|
+
return this.#transport.get(`/trending/all/${toTimeWindow(timeWindow)}`, {
|
|
554
|
+
query: withLanguage(this.#transport.defaults, {
|
|
555
|
+
language: options.language,
|
|
556
|
+
page: options.page
|
|
557
|
+
}),
|
|
558
|
+
signal: options.signal
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
movies(timeWindow = "day", options = {}) {
|
|
562
|
+
return this.#transport.get(`/trending/movie/${toTimeWindow(timeWindow)}`, {
|
|
563
|
+
query: withLanguage(this.#transport.defaults, {
|
|
564
|
+
language: options.language,
|
|
565
|
+
page: options.page
|
|
566
|
+
}),
|
|
567
|
+
signal: options.signal
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
tv(timeWindow = "day", options = {}) {
|
|
571
|
+
return this.#transport.get(`/trending/tv/${toTimeWindow(timeWindow)}`, {
|
|
572
|
+
query: withLanguage(this.#transport.defaults, {
|
|
573
|
+
language: options.language,
|
|
574
|
+
page: options.page
|
|
575
|
+
}),
|
|
576
|
+
signal: options.signal
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
people(timeWindow = "day", options = {}) {
|
|
580
|
+
return this.#transport.get(`/trending/person/${toTimeWindow(timeWindow)}`, {
|
|
581
|
+
query: withLanguage(this.#transport.defaults, {
|
|
582
|
+
language: options.language,
|
|
583
|
+
page: options.page
|
|
584
|
+
}),
|
|
585
|
+
signal: options.signal
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// src/resources/tv.ts
|
|
591
|
+
class TVResource {
|
|
592
|
+
#transport;
|
|
593
|
+
constructor(transport) {
|
|
594
|
+
this.#transport = transport;
|
|
595
|
+
}
|
|
596
|
+
popular(options = {}) {
|
|
597
|
+
return this.#transport.get("/tv/popular", {
|
|
598
|
+
query: tvListQuery(this.#transport, options),
|
|
599
|
+
signal: options.signal
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
topRated(options = {}) {
|
|
603
|
+
return this.#transport.get("/tv/top_rated", {
|
|
604
|
+
query: tvListQuery(this.#transport, options),
|
|
605
|
+
signal: options.signal
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
airingToday(options = {}) {
|
|
609
|
+
return this.#transport.get("/tv/airing_today", {
|
|
610
|
+
query: tvListQuery(this.#transport, options),
|
|
611
|
+
signal: options.signal
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
onTheAir(options = {}) {
|
|
615
|
+
return this.#transport.get("/tv/on_the_air", {
|
|
616
|
+
query: tvListQuery(this.#transport, options),
|
|
617
|
+
signal: options.signal
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
details(seriesId, options = {}) {
|
|
621
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}`, {
|
|
622
|
+
query: withLanguage(this.#transport.defaults, {
|
|
623
|
+
append_to_response: toCommaList(options.appendToResponse),
|
|
624
|
+
language: options.language
|
|
625
|
+
}),
|
|
626
|
+
signal: options.signal
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
credits(seriesId, options = {}) {
|
|
630
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/credits`, {
|
|
631
|
+
query: withLanguage(this.#transport.defaults, {
|
|
632
|
+
language: options.language
|
|
633
|
+
}),
|
|
634
|
+
signal: options.signal
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
images(seriesId, options = {}) {
|
|
638
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/images`, {
|
|
639
|
+
query: withLanguage(this.#transport.defaults, {
|
|
640
|
+
include_image_language: toCommaList(options.includeImageLanguage),
|
|
641
|
+
language: options.language
|
|
642
|
+
}),
|
|
643
|
+
signal: options.signal
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
recommendations(seriesId, options = {}) {
|
|
647
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/recommendations`, {
|
|
648
|
+
query: tvListQuery(this.#transport, options),
|
|
649
|
+
signal: options.signal
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
similar(seriesId, options = {}) {
|
|
653
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/similar`, {
|
|
654
|
+
query: tvListQuery(this.#transport, options),
|
|
655
|
+
signal: options.signal
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
videos(seriesId, options = {}) {
|
|
659
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/videos`, {
|
|
660
|
+
query: withLanguage(this.#transport.defaults, {
|
|
661
|
+
language: options.language
|
|
662
|
+
}),
|
|
663
|
+
signal: options.signal
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
seasonDetails(seriesId, seasonNumber, options = {}) {
|
|
667
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/season/${toSeasonNumber(seasonNumber)}`, {
|
|
668
|
+
query: withLanguage(this.#transport.defaults, {
|
|
669
|
+
append_to_response: toCommaList(options.appendToResponse),
|
|
670
|
+
language: options.language
|
|
671
|
+
}),
|
|
672
|
+
signal: options.signal
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
seasonCredits(seriesId, seasonNumber, options = {}) {
|
|
676
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/season/${toSeasonNumber(seasonNumber)}/credits`, {
|
|
677
|
+
query: withLanguage(this.#transport.defaults, {
|
|
678
|
+
language: options.language
|
|
679
|
+
}),
|
|
680
|
+
signal: options.signal
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
seasonAggregateCredits(seriesId, seasonNumber, options = {}) {
|
|
684
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/season/${toSeasonNumber(seasonNumber)}/aggregate_credits`, {
|
|
685
|
+
query: withLanguage(this.#transport.defaults, {
|
|
686
|
+
language: options.language
|
|
687
|
+
}),
|
|
688
|
+
signal: options.signal
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
seasonImages(seriesId, seasonNumber, options = {}) {
|
|
692
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/season/${toSeasonNumber(seasonNumber)}/images`, {
|
|
693
|
+
query: withLanguage(this.#transport.defaults, {
|
|
694
|
+
include_image_language: toCommaList(options.includeImageLanguage),
|
|
695
|
+
language: options.language
|
|
696
|
+
}),
|
|
697
|
+
signal: options.signal
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
seasonVideos(seriesId, seasonNumber, options = {}) {
|
|
701
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/season/${toSeasonNumber(seasonNumber)}/videos`, {
|
|
702
|
+
query: withLanguage(this.#transport.defaults, {
|
|
703
|
+
language: options.language
|
|
704
|
+
}),
|
|
705
|
+
signal: options.signal
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
episodeDetails(seriesId, seasonNumber, episodeNumber, options = {}) {
|
|
709
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/season/${toSeasonNumber(seasonNumber)}/episode/${toId(episodeNumber, "episodeNumber")}`, {
|
|
710
|
+
query: withLanguage(this.#transport.defaults, {
|
|
711
|
+
append_to_response: toCommaList(options.appendToResponse),
|
|
712
|
+
language: options.language
|
|
713
|
+
}),
|
|
714
|
+
signal: options.signal
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
aggregateCredits(seriesId, options = {}) {
|
|
718
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/aggregate_credits`, {
|
|
719
|
+
query: withLanguage(this.#transport.defaults, {
|
|
720
|
+
language: options.language
|
|
721
|
+
}),
|
|
722
|
+
signal: options.signal
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
episodeGroups(seriesId, options = {}) {
|
|
726
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/episode_groups`, {
|
|
727
|
+
query: withLanguage(this.#transport.defaults, {
|
|
728
|
+
language: options.language
|
|
729
|
+
}),
|
|
730
|
+
signal: options.signal
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
episodeGroup(groupId, options = {}) {
|
|
734
|
+
return this.#transport.get(`/tv/episode_group/${toGroupId(groupId)}`, {
|
|
735
|
+
query: withLanguage(this.#transport.defaults, {
|
|
736
|
+
language: options.language
|
|
737
|
+
}),
|
|
738
|
+
signal: options.signal
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
}
|
|
612
742
|
function tvListQuery(transport, options) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
this.tv = new TVResource(this.#transport);
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Make a raw GET request to any TMDB endpoint.
|
|
656
|
-
*
|
|
657
|
-
* This is an escape hatch for endpoints not covered by the typed resource
|
|
658
|
-
* helpers. The `path` should be relative to the API base URL (e.g.
|
|
659
|
-
* `/movie/{id}/credits`). Response is parsed as JSON and cast to `T`.
|
|
660
|
-
*
|
|
661
|
-
* @param path - API path relative to the base URL (e.g. `/movie/123`)
|
|
662
|
-
* @param options - Optional request-level overrides (headers, query, signal)
|
|
663
|
-
* @returns Parsed JSON response typed as `T`
|
|
664
|
-
*/
|
|
665
|
-
request(path, options) {
|
|
666
|
-
return this.#transport.get(path, options);
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
/**
|
|
670
|
-
* Create a new {@link TMDBClient} instance.
|
|
671
|
-
*
|
|
672
|
-
* @example
|
|
673
|
-
* ```ts
|
|
674
|
-
* const tmdb = createTMDB({ accessToken: 'YOUR_TOKEN' })
|
|
675
|
-
* const { results } = await tmdb.search.movies('Inception')
|
|
676
|
-
* ```
|
|
677
|
-
*
|
|
678
|
-
* @param options - Authentication and configuration options
|
|
679
|
-
* @returns A configured TMDBClient ready to make API calls
|
|
680
|
-
*/
|
|
743
|
+
return withLanguage(transport.defaults, {
|
|
744
|
+
language: options.language,
|
|
745
|
+
page: options.page
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// src/client.ts
|
|
750
|
+
class TMDBClient {
|
|
751
|
+
configuration;
|
|
752
|
+
genres;
|
|
753
|
+
images;
|
|
754
|
+
movies;
|
|
755
|
+
people;
|
|
756
|
+
search;
|
|
757
|
+
trending;
|
|
758
|
+
tv;
|
|
759
|
+
#transport;
|
|
760
|
+
constructor(options) {
|
|
761
|
+
let imageTransform = options.images?.transform;
|
|
762
|
+
if (options.transport === undefined) {
|
|
763
|
+
const builtInClient = new TMDBHttpClient(options);
|
|
764
|
+
this.#transport = builtInClient;
|
|
765
|
+
imageTransform = builtInClient.imageTransform;
|
|
766
|
+
} else {
|
|
767
|
+
this.#transport = options.transport;
|
|
768
|
+
}
|
|
769
|
+
this.configuration = new ConfigurationResource(this.#transport);
|
|
770
|
+
this.genres = new GenresResource(this.#transport);
|
|
771
|
+
this.images = new ImagesHelper(this.#transport, imageTransform);
|
|
772
|
+
this.movies = new MoviesResource(this.#transport);
|
|
773
|
+
this.people = new PeopleResource(this.#transport);
|
|
774
|
+
this.search = new SearchResource(this.#transport);
|
|
775
|
+
this.trending = new TrendingResource(this.#transport);
|
|
776
|
+
this.tv = new TVResource(this.#transport);
|
|
777
|
+
}
|
|
778
|
+
request(path, options) {
|
|
779
|
+
return this.#transport.get(path, options);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
681
782
|
function createTMDB(options) {
|
|
682
|
-
|
|
783
|
+
return new TMDBClient(options);
|
|
683
784
|
}
|
|
684
|
-
|
|
685
|
-
|
|
785
|
+
// src/helpers/cache.ts
|
|
786
|
+
function withMemoryCache(transport, options = {}) {
|
|
787
|
+
const ttlMs = options.ttlMs ?? 5 * 60000;
|
|
788
|
+
const maxEntries = options.maxEntries ?? 100;
|
|
789
|
+
if (!Number.isFinite(ttlMs) || ttlMs <= 0) {
|
|
790
|
+
throw new RangeError("ttlMs must be a positive number");
|
|
791
|
+
}
|
|
792
|
+
if (!Number.isInteger(maxEntries) || maxEntries < 1) {
|
|
793
|
+
throw new RangeError("maxEntries must be a positive integer");
|
|
794
|
+
}
|
|
795
|
+
const entries = new Map;
|
|
796
|
+
return {
|
|
797
|
+
...transport,
|
|
798
|
+
async get(path, requestOptions = {}) {
|
|
799
|
+
const key = cacheKey(path, requestOptions);
|
|
800
|
+
const cached = entries.get(key);
|
|
801
|
+
if (cached !== undefined) {
|
|
802
|
+
if (cached.expiresAt > Date.now()) {
|
|
803
|
+
entries.delete(key);
|
|
804
|
+
entries.set(key, cached);
|
|
805
|
+
return cached.value;
|
|
806
|
+
}
|
|
807
|
+
entries.delete(key);
|
|
808
|
+
}
|
|
809
|
+
const value = await transport.get(path, requestOptions);
|
|
810
|
+
entries.set(key, { expiresAt: Date.now() + ttlMs, value });
|
|
811
|
+
evictOverflow(entries, maxEntries);
|
|
812
|
+
return value;
|
|
813
|
+
},
|
|
814
|
+
clear() {
|
|
815
|
+
entries.clear();
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
function cacheKey(path, options) {
|
|
820
|
+
return `${path}?${serializeQuery(options.query)}|${serializeHeaders(options.headers)}`;
|
|
821
|
+
}
|
|
822
|
+
function serializeQuery(query) {
|
|
823
|
+
if (query === undefined) {
|
|
824
|
+
return "";
|
|
825
|
+
}
|
|
826
|
+
return Object.entries(query).filter(([, value]) => value !== undefined && value !== null).sort(([left], [right]) => left.localeCompare(right)).map(([key, value]) => `${key}=${Array.isArray(value) ? value.map(String).join(",") : String(value)}`).join("&");
|
|
827
|
+
}
|
|
828
|
+
function serializeHeaders(headers) {
|
|
829
|
+
if (headers === undefined) {
|
|
830
|
+
return "";
|
|
831
|
+
}
|
|
832
|
+
return [...new Headers(headers)].sort(([left], [right]) => left.localeCompare(right)).map(([key, value]) => `${key}:${value}`).join("|");
|
|
833
|
+
}
|
|
834
|
+
function evictOverflow(entries, maxEntries) {
|
|
835
|
+
while (entries.size > maxEntries) {
|
|
836
|
+
entries.delete(entries.keys().next().value);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
// src/helpers/pagination.ts
|
|
840
|
+
async function* paginate(fetchPage, options = {}) {
|
|
841
|
+
const startPage = options.startPage ?? 1;
|
|
842
|
+
const endPage = options.endPage ?? 500;
|
|
843
|
+
assertPositiveInteger(startPage, "startPage");
|
|
844
|
+
assertPositiveInteger(endPage, "endPage");
|
|
845
|
+
for (let page = startPage;page <= endPage; page += 1) {
|
|
846
|
+
options.signal?.throwIfAborted();
|
|
847
|
+
const response = await fetchPage(page);
|
|
848
|
+
yield response;
|
|
849
|
+
if (response.results.length === 0 || page >= response.total_pages) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
async function* paginateItems(fetchPage, options = {}) {
|
|
855
|
+
for await (const page of paginate(fetchPage, options)) {
|
|
856
|
+
yield* page.results;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function assertPositiveInteger(value, name) {
|
|
860
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
861
|
+
throw new RangeError(`${name} must be a positive integer`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
// src/helpers/retry.ts
|
|
865
|
+
var MAX_RETRY_AFTER_MS = 60000;
|
|
866
|
+
async function retry(task, options = {}) {
|
|
867
|
+
const retries = options.retries ?? 2;
|
|
868
|
+
if (!Number.isInteger(retries) || retries < 0) {
|
|
869
|
+
throw new RangeError("retries must be a non-negative integer");
|
|
870
|
+
}
|
|
871
|
+
const retryOn = options.retryOn ?? shouldRetry;
|
|
872
|
+
const signal = options.signal;
|
|
873
|
+
if (signal?.aborted) {
|
|
874
|
+
throw signal.reason;
|
|
875
|
+
}
|
|
876
|
+
for (let attempt = 0;; attempt += 1) {
|
|
877
|
+
try {
|
|
878
|
+
return await task();
|
|
879
|
+
} catch (error) {
|
|
880
|
+
if (signal?.aborted) {
|
|
881
|
+
throw signal.reason;
|
|
882
|
+
}
|
|
883
|
+
if (attempt >= retries || !retryOn(error, attempt)) {
|
|
884
|
+
throw error;
|
|
885
|
+
}
|
|
886
|
+
const delayMs = retryDelay(error, attempt, options);
|
|
887
|
+
options.onRetry?.({ attempt, delayMs, error });
|
|
888
|
+
await sleep(delayMs, signal);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
function withRetry(transport, options = {}) {
|
|
893
|
+
return {
|
|
894
|
+
...transport,
|
|
895
|
+
get(path, requestOptions) {
|
|
896
|
+
const { cleanup, signal } = combineSignals(options.signal, requestOptions?.signal);
|
|
897
|
+
const effectiveOptions = signal === undefined ? requestOptions : { ...requestOptions, signal };
|
|
898
|
+
return retry(() => transport.get(path, effectiveOptions), {
|
|
899
|
+
...options,
|
|
900
|
+
signal
|
|
901
|
+
}).finally(cleanup);
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
function shouldRetry(error) {
|
|
906
|
+
if (error instanceof TMDBRateLimitError) {
|
|
907
|
+
return true;
|
|
908
|
+
}
|
|
909
|
+
if (error instanceof TMDBResponseError) {
|
|
910
|
+
return error.isServerError || error.status === 408;
|
|
911
|
+
}
|
|
912
|
+
if (error instanceof TMDBTimeoutError) {
|
|
913
|
+
return false;
|
|
914
|
+
}
|
|
915
|
+
if (error instanceof TMDBRequestError) {
|
|
916
|
+
if (error.cause === undefined || error.cause instanceof TMDBTimeoutError) {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
return !isAbortError(error.cause);
|
|
920
|
+
}
|
|
921
|
+
return false;
|
|
922
|
+
}
|
|
923
|
+
function retryDelay(error, attempt, options) {
|
|
924
|
+
const retryAfter = retryAfterMs(error);
|
|
925
|
+
if (retryAfter !== undefined) {
|
|
926
|
+
return Math.min(Math.max(retryAfter, 0), MAX_RETRY_AFTER_MS);
|
|
927
|
+
}
|
|
928
|
+
if (error instanceof TMDBRateLimitError) {
|
|
929
|
+
return Math.min(Math.max(error.retryAfter * 1000, 0), MAX_RETRY_AFTER_MS);
|
|
930
|
+
}
|
|
931
|
+
const baseDelayMs = options.baseDelayMs ?? 250;
|
|
932
|
+
const maxDelayMs = options.maxDelayMs ?? 1e4;
|
|
933
|
+
const factor = options.factor ?? 2;
|
|
934
|
+
const delay = Math.min(maxDelayMs, baseDelayMs * factor ** attempt);
|
|
935
|
+
return options.jitter === false ? delay : Math.random() * delay;
|
|
936
|
+
}
|
|
937
|
+
function retryAfterMs(error) {
|
|
938
|
+
if (!(error instanceof TMDBResponseError)) {
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
const header = error.headers.get("retry-after");
|
|
942
|
+
if (header === null || header.trim() === "") {
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
return parseRetryAfter(header) * 1000;
|
|
946
|
+
}
|
|
947
|
+
function combineSignals(first, second) {
|
|
948
|
+
if (first === undefined || second === undefined || first === second) {
|
|
949
|
+
return { cleanup: noop, signal: first ?? second };
|
|
950
|
+
}
|
|
951
|
+
const controller = new AbortController;
|
|
952
|
+
const onAbort = () => controller.abort((first.aborted ? first : second).reason);
|
|
953
|
+
first.addEventListener("abort", onAbort, { once: true });
|
|
954
|
+
second.addEventListener("abort", onAbort, { once: true });
|
|
955
|
+
if (first.aborted || second.aborted) {
|
|
956
|
+
onAbort();
|
|
957
|
+
}
|
|
958
|
+
return {
|
|
959
|
+
cleanup() {
|
|
960
|
+
first.removeEventListener("abort", onAbort);
|
|
961
|
+
second.removeEventListener("abort", onAbort);
|
|
962
|
+
},
|
|
963
|
+
signal: controller.signal
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
function noop() {}
|
|
967
|
+
function isAbortError(error) {
|
|
968
|
+
return typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
|
|
969
|
+
}
|
|
970
|
+
function sleep(ms, signal) {
|
|
971
|
+
return new Promise((resolve, reject) => {
|
|
972
|
+
const onAbort = () => {
|
|
973
|
+
clearTimeout(timer);
|
|
974
|
+
signal?.removeEventListener("abort", onAbort);
|
|
975
|
+
reject(signal.reason);
|
|
976
|
+
};
|
|
977
|
+
const timer = setTimeout(() => {
|
|
978
|
+
signal?.removeEventListener("abort", onAbort);
|
|
979
|
+
resolve();
|
|
980
|
+
}, ms);
|
|
981
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
982
|
+
if (signal?.aborted) {
|
|
983
|
+
onAbort();
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
// src/helpers/timeout.ts
|
|
988
|
+
async function withTimeout(timeoutMs, task, options = {}) {
|
|
989
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
990
|
+
throw new RangeError("timeoutMs must be a positive number");
|
|
991
|
+
}
|
|
992
|
+
const parent = options.signal;
|
|
993
|
+
const controller = new AbortController;
|
|
994
|
+
const timeoutError = new TMDBTimeoutError(timeoutMs, options.message);
|
|
995
|
+
const onAbort = () => controller.abort(parent.reason);
|
|
996
|
+
parent?.addEventListener("abort", onAbort, { once: true });
|
|
997
|
+
if (parent?.aborted) {
|
|
998
|
+
parent.removeEventListener("abort", onAbort);
|
|
999
|
+
throw parent.reason;
|
|
1000
|
+
}
|
|
1001
|
+
const timer = setTimeout(() => controller.abort(timeoutError), timeoutMs);
|
|
1002
|
+
try {
|
|
1003
|
+
return await task(controller.signal);
|
|
1004
|
+
} catch (error) {
|
|
1005
|
+
if (controller.signal.reason === timeoutError) {
|
|
1006
|
+
throw timeoutError;
|
|
1007
|
+
}
|
|
1008
|
+
if (parent?.aborted) {
|
|
1009
|
+
throw parent.reason;
|
|
1010
|
+
}
|
|
1011
|
+
throw error;
|
|
1012
|
+
} finally {
|
|
1013
|
+
clearTimeout(timer);
|
|
1014
|
+
parent?.removeEventListener("abort", onAbort);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
// src/search-guards.ts
|
|
686
1018
|
function isMovieSearchResult(result) {
|
|
687
|
-
|
|
1019
|
+
return isObjectWithMediaType(result, "movie");
|
|
688
1020
|
}
|
|
689
1021
|
function isTVSearchResult(result) {
|
|
690
|
-
|
|
1022
|
+
return isObjectWithMediaType(result, "tv");
|
|
691
1023
|
}
|
|
692
1024
|
function isPersonSearchResult(result) {
|
|
693
|
-
|
|
1025
|
+
return isObjectWithMediaType(result, "person");
|
|
694
1026
|
}
|
|
695
1027
|
function isMovie(result) {
|
|
696
|
-
|
|
1028
|
+
return isObjectWithMediaType(result, "movie");
|
|
697
1029
|
}
|
|
698
1030
|
function isTV(result) {
|
|
699
|
-
|
|
1031
|
+
return isObjectWithMediaType(result, "tv");
|
|
700
1032
|
}
|
|
701
1033
|
function isPerson(result) {
|
|
702
|
-
|
|
1034
|
+
return isObjectWithMediaType(result, "person");
|
|
703
1035
|
}
|
|
704
|
-
/** Internal helper: check if a value is an object with a matching `media_type` field. */
|
|
705
1036
|
function isObjectWithMediaType(value, mediaType) {
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
* canonical list lets callers:
|
|
715
|
-
*
|
|
716
|
-
* - iterate over the set to build a size picker
|
|
717
|
-
* - validate user-supplied sizes with `isKnownBackdropSize(...)` etc.
|
|
718
|
-
* - type a variable as a "known" size without giving up the
|
|
719
|
-
* `(string & {})` escape hatch for forward-compatibility
|
|
720
|
-
*
|
|
721
|
-
* If TMDB publishes a new size, the SDK will still accept it at runtime
|
|
722
|
-
* (every helper is `(string & {})` permissive), but you will need to
|
|
723
|
-
* add the literal to these constants to get autocomplete on it.
|
|
724
|
-
*/
|
|
725
|
-
const KNOWN_BACKDROP_SIZES = Object.freeze([
|
|
726
|
-
"w300",
|
|
727
|
-
"w780",
|
|
728
|
-
"w1280",
|
|
729
|
-
"original"
|
|
730
|
-
]);
|
|
731
|
-
const KNOWN_LOGO_SIZES = Object.freeze([
|
|
732
|
-
"w45",
|
|
733
|
-
"w92",
|
|
734
|
-
"w154",
|
|
735
|
-
"w185",
|
|
736
|
-
"w300",
|
|
737
|
-
"w500",
|
|
738
|
-
"original"
|
|
739
|
-
]);
|
|
740
|
-
const KNOWN_POSTER_SIZES = Object.freeze([
|
|
741
|
-
"w92",
|
|
742
|
-
"w154",
|
|
743
|
-
"w185",
|
|
744
|
-
"w342",
|
|
745
|
-
"w500",
|
|
746
|
-
"w780",
|
|
747
|
-
"original"
|
|
1037
|
+
return typeof value === "object" && value !== null && "media_type" in value && value.media_type === mediaType;
|
|
1038
|
+
}
|
|
1039
|
+
// src/types.ts
|
|
1040
|
+
var KNOWN_BACKDROP_SIZES = Object.freeze([
|
|
1041
|
+
"w300",
|
|
1042
|
+
"w780",
|
|
1043
|
+
"w1280",
|
|
1044
|
+
"original"
|
|
748
1045
|
]);
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
1046
|
+
var KNOWN_LOGO_SIZES = Object.freeze(["w45", "w92", "w154", "w185", "w300", "w500", "original"]);
|
|
1047
|
+
var KNOWN_POSTER_SIZES = Object.freeze(["w92", "w154", "w185", "w342", "w500", "w780", "original"]);
|
|
1048
|
+
var KNOWN_PROFILE_SIZES = Object.freeze([
|
|
1049
|
+
"w45",
|
|
1050
|
+
"w185",
|
|
1051
|
+
"h632",
|
|
1052
|
+
"original"
|
|
754
1053
|
]);
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
1054
|
+
var KNOWN_STILL_SIZES = Object.freeze([
|
|
1055
|
+
"w92",
|
|
1056
|
+
"w185",
|
|
1057
|
+
"w300",
|
|
1058
|
+
"original"
|
|
760
1059
|
]);
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
...KNOWN_STILL_SIZES
|
|
1060
|
+
var KNOWN_IMAGE_SIZES = Object.freeze([
|
|
1061
|
+
...KNOWN_BACKDROP_SIZES,
|
|
1062
|
+
...KNOWN_LOGO_SIZES,
|
|
1063
|
+
...KNOWN_POSTER_SIZES,
|
|
1064
|
+
...KNOWN_PROFILE_SIZES,
|
|
1065
|
+
...KNOWN_STILL_SIZES
|
|
768
1066
|
]);
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
const KNOWN_IMAGE_SET = new Set(KNOWN_IMAGE_SIZES);
|
|
1067
|
+
var KNOWN_BACKDROP_SET = new Set(KNOWN_BACKDROP_SIZES);
|
|
1068
|
+
var KNOWN_LOGO_SET = new Set(KNOWN_LOGO_SIZES);
|
|
1069
|
+
var KNOWN_POSTER_SET = new Set(KNOWN_POSTER_SIZES);
|
|
1070
|
+
var KNOWN_PROFILE_SET = new Set(KNOWN_PROFILE_SIZES);
|
|
1071
|
+
var KNOWN_STILL_SET = new Set(KNOWN_STILL_SIZES);
|
|
1072
|
+
var KNOWN_IMAGE_SET = new Set(KNOWN_IMAGE_SIZES);
|
|
776
1073
|
function isKnownBackdropSize(value) {
|
|
777
|
-
|
|
1074
|
+
return KNOWN_BACKDROP_SET.has(value);
|
|
778
1075
|
}
|
|
779
1076
|
function isKnownLogoSize(value) {
|
|
780
|
-
|
|
1077
|
+
return KNOWN_LOGO_SET.has(value);
|
|
781
1078
|
}
|
|
782
1079
|
function isKnownPosterSize(value) {
|
|
783
|
-
|
|
1080
|
+
return KNOWN_POSTER_SET.has(value);
|
|
784
1081
|
}
|
|
785
1082
|
function isKnownProfileSize(value) {
|
|
786
|
-
|
|
1083
|
+
return KNOWN_PROFILE_SET.has(value);
|
|
787
1084
|
}
|
|
788
1085
|
function isKnownStillSize(value) {
|
|
789
|
-
|
|
1086
|
+
return KNOWN_STILL_SET.has(value);
|
|
790
1087
|
}
|
|
791
|
-
/** True if `value` is in any documented size set. */
|
|
792
1088
|
function isKnownImageSize(value) {
|
|
793
|
-
|
|
1089
|
+
return KNOWN_IMAGE_SET.has(value);
|
|
794
1090
|
}
|
|
795
|
-
|
|
796
|
-
|
|
1091
|
+
export {
|
|
1092
|
+
KNOWN_BACKDROP_SIZES,
|
|
1093
|
+
KNOWN_IMAGE_SIZES,
|
|
1094
|
+
KNOWN_LOGO_SIZES,
|
|
1095
|
+
KNOWN_POSTER_SIZES,
|
|
1096
|
+
KNOWN_PROFILE_SIZES,
|
|
1097
|
+
KNOWN_STILL_SIZES,
|
|
1098
|
+
TMDBClient,
|
|
1099
|
+
TMDBError,
|
|
1100
|
+
TMDBHttpClient,
|
|
1101
|
+
TMDBRateLimitError,
|
|
1102
|
+
TMDBRequestError,
|
|
1103
|
+
TMDBResponseError,
|
|
1104
|
+
TMDBTimeoutError,
|
|
1105
|
+
buildImageUrl,
|
|
1106
|
+
createTMDB,
|
|
1107
|
+
isKnownBackdropSize,
|
|
1108
|
+
isKnownImageSize,
|
|
1109
|
+
isKnownLogoSize,
|
|
1110
|
+
isKnownPosterSize,
|
|
1111
|
+
isKnownProfileSize,
|
|
1112
|
+
isKnownStillSize,
|
|
1113
|
+
isMovie,
|
|
1114
|
+
isMovieSearchResult,
|
|
1115
|
+
isPerson,
|
|
1116
|
+
isPersonSearchResult,
|
|
1117
|
+
isTV,
|
|
1118
|
+
isTVSearchResult,
|
|
1119
|
+
paginate,
|
|
1120
|
+
paginateItems,
|
|
1121
|
+
retry,
|
|
1122
|
+
withMemoryCache,
|
|
1123
|
+
withRetry,
|
|
1124
|
+
withTimeout
|
|
1125
|
+
};
|
|
797
1126
|
|
|
798
|
-
//#
|
|
1127
|
+
//# debugId=24603BBDC4DA497C64756E2164756E21
|
|
1128
|
+
//# sourceMappingURL=index.js.map
|