tmdb-kit 1.0.0 → 1.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/README.md +293 -198
- package/dist/cli.js +3132 -0
- package/dist/client.d.cts +63 -0
- package/dist/client.d.ts +63 -0
- package/dist/errors.d.cts +74 -0
- package/dist/errors.d.ts +74 -0
- package/dist/http.d.cts +80 -0
- package/dist/http.d.ts +80 -0
- package/dist/index.cjs +747 -768
- package/dist/index.cjs.map +23 -1
- package/dist/index.d.cts +8 -783
- package/dist/index.d.ts +8 -783
- package/dist/index.js +707 -745
- package/dist/index.js.map +23 -1
- package/dist/query.d.cts +77 -0
- package/dist/query.d.ts +77 -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 +22 -0
- package/dist/resources/tv.d.ts +22 -0
- package/dist/search-guards.d.cts +32 -0
- package/dist/search-guards.d.ts +32 -0
- package/dist/types.d.cts +452 -0
- package/dist/types.d.ts +452 -0
- package/package.json +26 -19
package/dist/index.cjs
CHANGED
|
@@ -1,823 +1,802 @@
|
|
|
1
|
-
Object.defineProperty
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
9
23
|
};
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
16
37
|
};
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
38
|
+
|
|
39
|
+
// src/index.ts
|
|
40
|
+
var exports_src = {};
|
|
41
|
+
__export(exports_src, {
|
|
42
|
+
KNOWN_BACKDROP_SIZES: () => KNOWN_BACKDROP_SIZES,
|
|
43
|
+
KNOWN_IMAGE_SIZES: () => KNOWN_IMAGE_SIZES,
|
|
44
|
+
KNOWN_LOGO_SIZES: () => KNOWN_LOGO_SIZES,
|
|
45
|
+
KNOWN_POSTER_SIZES: () => KNOWN_POSTER_SIZES,
|
|
46
|
+
KNOWN_PROFILE_SIZES: () => KNOWN_PROFILE_SIZES,
|
|
47
|
+
KNOWN_STILL_SIZES: () => KNOWN_STILL_SIZES,
|
|
48
|
+
TMDBClient: () => TMDBClient,
|
|
49
|
+
TMDBError: () => TMDBError,
|
|
50
|
+
TMDBRateLimitError: () => TMDBRateLimitError,
|
|
51
|
+
TMDBRequestError: () => TMDBRequestError,
|
|
52
|
+
TMDBResponseError: () => TMDBResponseError,
|
|
53
|
+
buildImageUrl: () => buildImageUrl,
|
|
54
|
+
createTMDB: () => createTMDB,
|
|
55
|
+
isKnownBackdropSize: () => isKnownBackdropSize,
|
|
56
|
+
isKnownImageSize: () => isKnownImageSize,
|
|
57
|
+
isKnownLogoSize: () => isKnownLogoSize,
|
|
58
|
+
isKnownPosterSize: () => isKnownPosterSize,
|
|
59
|
+
isKnownProfileSize: () => isKnownProfileSize,
|
|
60
|
+
isKnownStillSize: () => isKnownStillSize,
|
|
61
|
+
isMovie: () => isMovie,
|
|
62
|
+
isMovieSearchResult: () => isMovieSearchResult,
|
|
63
|
+
isPerson: () => isPerson,
|
|
64
|
+
isPersonSearchResult: () => isPersonSearchResult,
|
|
65
|
+
isTV: () => isTV,
|
|
66
|
+
isTVSearchResult: () => isTVSearchResult
|
|
67
|
+
});
|
|
68
|
+
module.exports = __toCommonJS(exports_src);
|
|
69
|
+
|
|
70
|
+
// src/errors.ts
|
|
71
|
+
class TMDBError extends Error {
|
|
72
|
+
constructor(message, options) {
|
|
73
|
+
super(message, options);
|
|
74
|
+
this.name = "TMDBError";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
class TMDBRequestError extends TMDBError {
|
|
79
|
+
constructor(message, options) {
|
|
80
|
+
super(message, options);
|
|
81
|
+
this.name = "TMDBRequestError";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
class TMDBResponseError extends TMDBError {
|
|
86
|
+
body;
|
|
87
|
+
headers;
|
|
88
|
+
requestId;
|
|
89
|
+
status;
|
|
90
|
+
statusCode;
|
|
91
|
+
statusMessage;
|
|
92
|
+
statusText;
|
|
93
|
+
url;
|
|
94
|
+
constructor(message, options) {
|
|
95
|
+
super(message);
|
|
96
|
+
this.name = "TMDBResponseError";
|
|
97
|
+
this.body = options.body;
|
|
98
|
+
this.headers = options.headers;
|
|
99
|
+
this.requestId = options.headers.get("x-request-id");
|
|
100
|
+
this.status = options.status;
|
|
101
|
+
this.statusText = options.statusText;
|
|
102
|
+
this.url = options.url;
|
|
103
|
+
const body = isErrorResponseBody(options.body) ? options.body : undefined;
|
|
104
|
+
this.statusCode = body?.status_code;
|
|
105
|
+
this.statusMessage = body?.status_message;
|
|
106
|
+
}
|
|
107
|
+
get isRateLimit() {
|
|
108
|
+
return this.status === 429;
|
|
109
|
+
}
|
|
110
|
+
get isNotFound() {
|
|
111
|
+
return this.status === 404;
|
|
112
|
+
}
|
|
113
|
+
get isUnauthorized() {
|
|
114
|
+
return this.status === 401;
|
|
115
|
+
}
|
|
116
|
+
get isForbidden() {
|
|
117
|
+
return this.status === 403;
|
|
118
|
+
}
|
|
119
|
+
get isServerError() {
|
|
120
|
+
return this.status >= 500 && this.status < 600;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
class TMDBRateLimitError extends TMDBResponseError {
|
|
125
|
+
retryAfter;
|
|
126
|
+
constructor(message, options) {
|
|
127
|
+
super(message, options);
|
|
128
|
+
this.name = "TMDBRateLimitError";
|
|
129
|
+
this.retryAfter = options.retryAfter;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
83
132
|
function createResponseError(options) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
* Falls back to 1 second when the header is missing or unparseable.
|
|
95
|
-
*/
|
|
133
|
+
const body = isErrorResponseBody(options.body) ? options.body : undefined;
|
|
134
|
+
const message = body?.status_message ?? `${options.status} ${options.statusText}`.trim();
|
|
135
|
+
if (options.status === 429) {
|
|
136
|
+
return new TMDBRateLimitError(message, {
|
|
137
|
+
...options,
|
|
138
|
+
retryAfter: parseRetryAfter(options.headers.get("retry-after"))
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return new TMDBResponseError(message, options);
|
|
142
|
+
}
|
|
96
143
|
function parseRetryAfter(value) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
144
|
+
if (value === null || value === undefined) {
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
const trimmed = value.trim();
|
|
148
|
+
if (trimmed === "") {
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
const seconds = Number(trimmed);
|
|
152
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
153
|
+
return seconds;
|
|
154
|
+
}
|
|
155
|
+
const date = Date.parse(trimmed);
|
|
156
|
+
if (Number.isFinite(date)) {
|
|
157
|
+
const deltaMs = date - Date.now();
|
|
158
|
+
return Math.max(1, Math.ceil(deltaMs / 1000));
|
|
159
|
+
}
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
110
162
|
function isErrorResponseBody(value) {
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* - Arrays are joined with commas (TMDB convention).
|
|
118
|
-
* - All values are converted to strings.
|
|
119
|
-
*/
|
|
163
|
+
return typeof value === "object" && value !== null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/query.ts
|
|
167
|
+
var DEFAULT_API_BASE_URL = "https://api.themoviedb.org/3";
|
|
168
|
+
var DEFAULT_IMAGE_BASE_URL = "https://image.tmdb.org/t/p";
|
|
120
169
|
function appendQuery(url, query) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
*
|
|
133
|
-
* If `query.language` is set it takes precedence; otherwise the client's
|
|
134
|
-
* default language is used.
|
|
135
|
-
*/
|
|
170
|
+
for (const [key, value] of Object.entries(query)) {
|
|
171
|
+
if (value === undefined || value === null) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (Array.isArray(value)) {
|
|
175
|
+
url.searchParams.set(key, value.map(String).join(","));
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
url.searchParams.set(key, String(value));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
136
181
|
function withLanguage(defaults, query) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Merge language and region defaults for list endpoints.
|
|
145
|
-
*
|
|
146
|
-
* Combines {@link withLanguage} with region fallback from client defaults.
|
|
147
|
-
*/
|
|
182
|
+
const language = typeof query.language === "string" ? query.language : defaults.language;
|
|
183
|
+
return {
|
|
184
|
+
...query,
|
|
185
|
+
language
|
|
186
|
+
};
|
|
187
|
+
}
|
|
148
188
|
function withListDefaults(defaults, query) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Convert a string or string array to a comma-separated list.
|
|
157
|
-
*
|
|
158
|
-
* Returns `undefined` if the input is `undefined` (skips the parameter).
|
|
159
|
-
* TMDB uses comma-separated values for multi-value query parameters.
|
|
160
|
-
*/
|
|
189
|
+
const region = typeof query.region === "string" ? query.region : defaults.region;
|
|
190
|
+
return {
|
|
191
|
+
...withLanguage(defaults, query),
|
|
192
|
+
region
|
|
193
|
+
};
|
|
194
|
+
}
|
|
161
195
|
function toCommaList(value) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
*
|
|
168
|
-
* @throws {TMDBRequestError} If `value` is not a positive integer.
|
|
169
|
-
*/
|
|
196
|
+
if (value === undefined) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
return typeof value === "string" ? value : value.join(",");
|
|
200
|
+
}
|
|
170
201
|
function toId(value, name) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*
|
|
177
|
-
* @throws {TMDBRequestError} If the query is empty after trimming.
|
|
178
|
-
*/
|
|
202
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
203
|
+
throw new TMDBRequestError(`${name} must be a positive integer`);
|
|
204
|
+
}
|
|
205
|
+
return String(value);
|
|
206
|
+
}
|
|
179
207
|
function toSearchQuery(value) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
*
|
|
187
|
-
* @throws {TMDBRequestError} If `value` is not `"day"` or `"week"`.
|
|
188
|
-
*/
|
|
208
|
+
const query = value.trim();
|
|
209
|
+
if (query.length === 0) {
|
|
210
|
+
throw new TMDBRequestError("search query must not be empty");
|
|
211
|
+
}
|
|
212
|
+
return query;
|
|
213
|
+
}
|
|
189
214
|
function toTimeWindow(value) {
|
|
190
|
-
|
|
191
|
-
|
|
215
|
+
if (value !== "day" && value !== "week") {
|
|
216
|
+
throw new TMDBRequestError('timeWindow must be either "day" or "week"');
|
|
217
|
+
}
|
|
218
|
+
return value;
|
|
192
219
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Build a full TMDB image URL from the path returned by API payloads.
|
|
195
|
-
* Returns null for nullish image paths so UI code can branch naturally.
|
|
196
|
-
*/
|
|
197
220
|
function buildImageUrl(path, size = "original", options = {}) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
221
|
+
if (path === undefined || path === null || path.trim() === "") {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
const baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_IMAGE_BASE_URL);
|
|
225
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
226
|
+
const url = `${baseUrl}/${size}${normalizedPath}`;
|
|
227
|
+
return options.transform ? options.transform(url) : url;
|
|
201
228
|
}
|
|
202
|
-
/**
|
|
203
|
-
* Strip trailing slashes from a base URL to ensure consistent path joining.
|
|
204
|
-
*/
|
|
205
229
|
function normalizeBaseUrl(baseUrl) {
|
|
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
|
-
|
|
294
|
-
* text for certain error conditions).
|
|
295
|
-
*/
|
|
230
|
+
return baseUrl.replace(/\/+$/, "");
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/http.ts
|
|
234
|
+
class TMDBHttpClient {
|
|
235
|
+
defaults;
|
|
236
|
+
imageTransform;
|
|
237
|
+
#apiKey;
|
|
238
|
+
#accessToken;
|
|
239
|
+
#baseUrl;
|
|
240
|
+
#fetch;
|
|
241
|
+
#headers;
|
|
242
|
+
constructor(options) {
|
|
243
|
+
const accessToken = normalizeSecret("accessToken" in options ? options.accessToken : undefined);
|
|
244
|
+
const apiKey = normalizeSecret("apiKey" in options ? options.apiKey : undefined);
|
|
245
|
+
if (Boolean(accessToken) === Boolean(apiKey)) {
|
|
246
|
+
throw new TMDBRequestError("Provide exactly one of accessToken or apiKey");
|
|
247
|
+
}
|
|
248
|
+
this.#accessToken = accessToken;
|
|
249
|
+
this.#apiKey = apiKey;
|
|
250
|
+
this.#baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_API_BASE_URL);
|
|
251
|
+
this.#fetch = options.fetch;
|
|
252
|
+
this.#headers = options.headers;
|
|
253
|
+
this.defaults = {
|
|
254
|
+
imageBaseUrl: normalizeBaseUrl(options.imageBaseUrl ?? DEFAULT_IMAGE_BASE_URL),
|
|
255
|
+
language: options.defaultLanguage,
|
|
256
|
+
region: options.defaultRegion
|
|
257
|
+
};
|
|
258
|
+
this.imageTransform = options.images?.transform;
|
|
259
|
+
}
|
|
260
|
+
async get(path, options = {}) {
|
|
261
|
+
const url = this.#createUrl(path, options.query ?? {});
|
|
262
|
+
const headers = this.#createHeaders(options.headers);
|
|
263
|
+
const fetchImpl = this.#resolveFetch();
|
|
264
|
+
let response;
|
|
265
|
+
try {
|
|
266
|
+
response = await fetchImpl(url, {
|
|
267
|
+
headers,
|
|
268
|
+
method: "GET",
|
|
269
|
+
signal: options.signal
|
|
270
|
+
});
|
|
271
|
+
} catch (error) {
|
|
272
|
+
throw new TMDBRequestError(`TMDB request failed: ${String(error)}`, { cause: error });
|
|
273
|
+
}
|
|
274
|
+
const body = await readJson(response);
|
|
275
|
+
if (!response.ok) {
|
|
276
|
+
throw createResponseError({
|
|
277
|
+
body,
|
|
278
|
+
headers: response.headers,
|
|
279
|
+
status: response.status,
|
|
280
|
+
statusText: response.statusText,
|
|
281
|
+
url
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return body;
|
|
285
|
+
}
|
|
286
|
+
#resolveFetch() {
|
|
287
|
+
if (this.#fetch !== undefined) {
|
|
288
|
+
return this.#fetch;
|
|
289
|
+
}
|
|
290
|
+
const globalFetch = globalThis.fetch;
|
|
291
|
+
if (typeof globalFetch !== "function") {
|
|
292
|
+
throw new TMDBRequestError("No fetch implementation found. Pass options.fetch in this runtime.");
|
|
293
|
+
}
|
|
294
|
+
return globalFetch.bind(globalThis);
|
|
295
|
+
}
|
|
296
|
+
#createHeaders(headersInit) {
|
|
297
|
+
const headers = new Headers(this.#headers);
|
|
298
|
+
const requestHeaders = new Headers(headersInit);
|
|
299
|
+
headers.set("Accept", "application/json");
|
|
300
|
+
for (const [key, value] of requestHeaders) {
|
|
301
|
+
headers.set(key, value);
|
|
302
|
+
}
|
|
303
|
+
if (this.#accessToken !== undefined) {
|
|
304
|
+
headers.set("Authorization", `Bearer ${this.#accessToken}`);
|
|
305
|
+
}
|
|
306
|
+
return headers;
|
|
307
|
+
}
|
|
308
|
+
#createUrl(path, query) {
|
|
309
|
+
const relativePath = path.replace(/^\/+/, "");
|
|
310
|
+
const url = new URL(relativePath, `${this.#baseUrl}/`);
|
|
311
|
+
appendQuery(url, {
|
|
312
|
+
...query,
|
|
313
|
+
api_key: this.#apiKey
|
|
314
|
+
});
|
|
315
|
+
return url.toString();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
296
318
|
async function readJson(response) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
* strings as undefined (not provided).
|
|
308
|
-
*/
|
|
319
|
+
const text = await response.text();
|
|
320
|
+
if (text.length === 0) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
return JSON.parse(text);
|
|
325
|
+
} catch {
|
|
326
|
+
return text;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
309
329
|
function normalizeSecret(value) {
|
|
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
|
-
}
|
|
434
|
-
|
|
330
|
+
const secret = value?.trim();
|
|
331
|
+
return secret === "" ? undefined : secret;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/resources/configuration.ts
|
|
335
|
+
class ConfigurationResource {
|
|
336
|
+
#transport;
|
|
337
|
+
constructor(transport) {
|
|
338
|
+
this.#transport = transport;
|
|
339
|
+
}
|
|
340
|
+
details() {
|
|
341
|
+
return this.#transport.get("/configuration");
|
|
342
|
+
}
|
|
343
|
+
countries() {
|
|
344
|
+
return this.#transport.get("/configuration/countries");
|
|
345
|
+
}
|
|
346
|
+
jobs() {
|
|
347
|
+
return this.#transport.get("/configuration/jobs");
|
|
348
|
+
}
|
|
349
|
+
languages() {
|
|
350
|
+
return this.#transport.get("/configuration/languages");
|
|
351
|
+
}
|
|
352
|
+
primaryTranslations() {
|
|
353
|
+
return this.#transport.get("/configuration/primary_translations");
|
|
354
|
+
}
|
|
355
|
+
timezones() {
|
|
356
|
+
return this.#transport.get("/configuration/timezones");
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/resources/genres.ts
|
|
361
|
+
class GenresResource {
|
|
362
|
+
#transport;
|
|
363
|
+
constructor(transport) {
|
|
364
|
+
this.#transport = transport;
|
|
365
|
+
}
|
|
366
|
+
movies(options = {}) {
|
|
367
|
+
return this.#transport.get("/genre/movie/list", {
|
|
368
|
+
query: withLanguage(this.#transport.defaults, {
|
|
369
|
+
language: options.language
|
|
370
|
+
})
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
tv(options = {}) {
|
|
374
|
+
return this.#transport.get("/genre/tv/list", {
|
|
375
|
+
query: withLanguage(this.#transport.defaults, {
|
|
376
|
+
language: options.language
|
|
377
|
+
})
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/resources/images.ts
|
|
383
|
+
class ImagesHelper {
|
|
384
|
+
#transport;
|
|
385
|
+
#transform;
|
|
386
|
+
constructor(transport, transform) {
|
|
387
|
+
this.#transport = transport;
|
|
388
|
+
this.#transform = transform;
|
|
389
|
+
}
|
|
390
|
+
url(path, size = "original", options = {}) {
|
|
391
|
+
return buildImageUrl(path, size, {
|
|
392
|
+
baseUrl: this.#transport.defaults.imageBaseUrl,
|
|
393
|
+
transform: options.transform ?? this.#transform
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/resources/movies.ts
|
|
399
|
+
class MoviesResource {
|
|
400
|
+
#transport;
|
|
401
|
+
constructor(transport) {
|
|
402
|
+
this.#transport = transport;
|
|
403
|
+
}
|
|
404
|
+
popular(options = {}) {
|
|
405
|
+
return this.#transport.get("/movie/popular", {
|
|
406
|
+
query: movieListQuery(this.#transport, options)
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
topRated(options = {}) {
|
|
410
|
+
return this.#transport.get("/movie/top_rated", {
|
|
411
|
+
query: movieListQuery(this.#transport, options)
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
nowPlaying(options = {}) {
|
|
415
|
+
return this.#transport.get("/movie/now_playing", {
|
|
416
|
+
query: movieListQuery(this.#transport, options)
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
upcoming(options = {}) {
|
|
420
|
+
return this.#transport.get("/movie/upcoming", {
|
|
421
|
+
query: movieListQuery(this.#transport, options)
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
details(movieId, options = {}) {
|
|
425
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}`, {
|
|
426
|
+
query: withLanguage(this.#transport.defaults, {
|
|
427
|
+
append_to_response: toCommaList(options.appendToResponse),
|
|
428
|
+
language: options.language
|
|
429
|
+
})
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
credits(movieId, options = {}) {
|
|
433
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/credits`, {
|
|
434
|
+
query: withLanguage(this.#transport.defaults, {
|
|
435
|
+
language: options.language
|
|
436
|
+
})
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
images(movieId, options = {}) {
|
|
440
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/images`, {
|
|
441
|
+
query: withLanguage(this.#transport.defaults, {
|
|
442
|
+
include_image_language: toCommaList(options.includeImageLanguage),
|
|
443
|
+
language: options.language
|
|
444
|
+
})
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
recommendations(movieId, options = {}) {
|
|
448
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/recommendations`, {
|
|
449
|
+
query: movieListQuery(this.#transport, options)
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
similar(movieId, options = {}) {
|
|
453
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/similar`, {
|
|
454
|
+
query: movieListQuery(this.#transport, options)
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
videos(movieId, options = {}) {
|
|
458
|
+
return this.#transport.get(`/movie/${toId(movieId, "movieId")}/videos`, {
|
|
459
|
+
query: withLanguage(this.#transport.defaults, {
|
|
460
|
+
language: options.language
|
|
461
|
+
})
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
}
|
|
435
465
|
function movieListQuery(transport, options) {
|
|
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
|
-
}
|
|
461
|
-
|
|
466
|
+
return withListDefaults(transport.defaults, {
|
|
467
|
+
language: options.language,
|
|
468
|
+
page: options.page,
|
|
469
|
+
region: options.region
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// src/resources/people.ts
|
|
474
|
+
class PeopleResource {
|
|
475
|
+
#transport;
|
|
476
|
+
constructor(transport) {
|
|
477
|
+
this.#transport = transport;
|
|
478
|
+
}
|
|
479
|
+
popular(options = {}) {
|
|
480
|
+
return this.#transport.get("/person/popular", {
|
|
481
|
+
query: peopleListQuery(this.#transport, options)
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
details(personId, options = {}) {
|
|
485
|
+
return this.#transport.get(`/person/${toId(personId, "personId")}`, {
|
|
486
|
+
query: withLanguage(this.#transport.defaults, {
|
|
487
|
+
language: options.language
|
|
488
|
+
})
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
combinedCredits(personId, options = {}) {
|
|
492
|
+
return this.#transport.get(`/person/${toId(personId, "personId")}/combined_credits`, {
|
|
493
|
+
query: withLanguage(this.#transport.defaults, {
|
|
494
|
+
language: options.language
|
|
495
|
+
})
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
462
499
|
function peopleListQuery(transport, options) {
|
|
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
|
-
|
|
500
|
-
|
|
500
|
+
return withLanguage(transport.defaults, {
|
|
501
|
+
language: options.language,
|
|
502
|
+
page: options.page
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// src/resources/search.ts
|
|
507
|
+
class SearchResource {
|
|
508
|
+
#transport;
|
|
509
|
+
constructor(transport) {
|
|
510
|
+
this.#transport = transport;
|
|
511
|
+
}
|
|
512
|
+
movies(query, options = {}) {
|
|
513
|
+
return this.#transport.get("/search/movie", {
|
|
514
|
+
query: movieSearchQuery(this.#transport, query, options)
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
tv(query, options = {}) {
|
|
518
|
+
return this.#transport.get("/search/tv", {
|
|
519
|
+
query: tvSearchQuery(this.#transport, query, options)
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
people(query, options = {}) {
|
|
523
|
+
return this.#transport.get("/search/person", {
|
|
524
|
+
query: commonSearchQuery(this.#transport, query, options)
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
async multi(query, options = {}) {
|
|
528
|
+
const response = await this.#transport.get("/search/multi", {
|
|
529
|
+
query: commonSearchQuery(this.#transport, query, options)
|
|
530
|
+
});
|
|
531
|
+
const excluded = options.exclude;
|
|
532
|
+
if (excluded === undefined || excluded.length === 0) {
|
|
533
|
+
return response;
|
|
534
|
+
}
|
|
535
|
+
const excludedSet = new Set(excluded);
|
|
536
|
+
return {
|
|
537
|
+
...response,
|
|
538
|
+
results: response.results.filter((result) => !excludedSet.has(result.media_type))
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
}
|
|
501
542
|
function movieSearchQuery(transport, query, options) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
/** Build query parameters for TV search. */
|
|
543
|
+
return withListDefaults(transport.defaults, {
|
|
544
|
+
include_adult: options.includeAdult,
|
|
545
|
+
language: options.language,
|
|
546
|
+
page: options.page,
|
|
547
|
+
primary_release_year: options.primaryReleaseYear,
|
|
548
|
+
query: toSearchQuery(query),
|
|
549
|
+
region: options.region,
|
|
550
|
+
year: options.year
|
|
551
|
+
});
|
|
552
|
+
}
|
|
513
553
|
function tvSearchQuery(transport, query, options) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
/** Build query parameters for person and multi-search. */
|
|
554
|
+
return withLanguage(transport.defaults, {
|
|
555
|
+
first_air_date_year: options.firstAirDateYear,
|
|
556
|
+
include_adult: options.includeAdult,
|
|
557
|
+
language: options.language,
|
|
558
|
+
page: options.page,
|
|
559
|
+
query: toSearchQuery(query),
|
|
560
|
+
year: options.year
|
|
561
|
+
});
|
|
562
|
+
}
|
|
524
563
|
function commonSearchQuery(transport, query, options) {
|
|
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
|
-
}
|
|
612
|
-
|
|
564
|
+
return withLanguage(transport.defaults, {
|
|
565
|
+
include_adult: options.includeAdult,
|
|
566
|
+
language: options.language,
|
|
567
|
+
page: options.page,
|
|
568
|
+
query: toSearchQuery(query)
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// src/resources/trending.ts
|
|
573
|
+
class TrendingResource {
|
|
574
|
+
#transport;
|
|
575
|
+
constructor(transport) {
|
|
576
|
+
this.#transport = transport;
|
|
577
|
+
}
|
|
578
|
+
all(timeWindow = "day", options = {}) {
|
|
579
|
+
return this.#transport.get(`/trending/all/${toTimeWindow(timeWindow)}`, {
|
|
580
|
+
query: withLanguage(this.#transport.defaults, {
|
|
581
|
+
language: options.language,
|
|
582
|
+
page: options.page
|
|
583
|
+
})
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
movies(timeWindow = "day", options = {}) {
|
|
587
|
+
return this.#transport.get(`/trending/movie/${toTimeWindow(timeWindow)}`, {
|
|
588
|
+
query: withLanguage(this.#transport.defaults, {
|
|
589
|
+
language: options.language,
|
|
590
|
+
page: options.page
|
|
591
|
+
})
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
tv(timeWindow = "day", options = {}) {
|
|
595
|
+
return this.#transport.get(`/trending/tv/${toTimeWindow(timeWindow)}`, {
|
|
596
|
+
query: withLanguage(this.#transport.defaults, {
|
|
597
|
+
language: options.language,
|
|
598
|
+
page: options.page
|
|
599
|
+
})
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
people(timeWindow = "day", options = {}) {
|
|
603
|
+
return this.#transport.get(`/trending/person/${toTimeWindow(timeWindow)}`, {
|
|
604
|
+
query: withLanguage(this.#transport.defaults, {
|
|
605
|
+
language: options.language,
|
|
606
|
+
page: options.page
|
|
607
|
+
})
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// src/resources/tv.ts
|
|
613
|
+
class TVResource {
|
|
614
|
+
#transport;
|
|
615
|
+
constructor(transport) {
|
|
616
|
+
this.#transport = transport;
|
|
617
|
+
}
|
|
618
|
+
popular(options = {}) {
|
|
619
|
+
return this.#transport.get("/tv/popular", {
|
|
620
|
+
query: tvListQuery(this.#transport, options)
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
topRated(options = {}) {
|
|
624
|
+
return this.#transport.get("/tv/top_rated", {
|
|
625
|
+
query: tvListQuery(this.#transport, options)
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
airingToday(options = {}) {
|
|
629
|
+
return this.#transport.get("/tv/airing_today", {
|
|
630
|
+
query: tvListQuery(this.#transport, options)
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
onTheAir(options = {}) {
|
|
634
|
+
return this.#transport.get("/tv/on_the_air", {
|
|
635
|
+
query: tvListQuery(this.#transport, options)
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
details(seriesId, options = {}) {
|
|
639
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}`, {
|
|
640
|
+
query: withLanguage(this.#transport.defaults, {
|
|
641
|
+
append_to_response: toCommaList(options.appendToResponse),
|
|
642
|
+
language: options.language
|
|
643
|
+
})
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
credits(seriesId, options = {}) {
|
|
647
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/credits`, {
|
|
648
|
+
query: withLanguage(this.#transport.defaults, {
|
|
649
|
+
language: options.language
|
|
650
|
+
})
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
images(seriesId, options = {}) {
|
|
654
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/images`, {
|
|
655
|
+
query: withLanguage(this.#transport.defaults, {
|
|
656
|
+
include_image_language: toCommaList(options.includeImageLanguage),
|
|
657
|
+
language: options.language
|
|
658
|
+
})
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
recommendations(seriesId, options = {}) {
|
|
662
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/recommendations`, {
|
|
663
|
+
query: tvListQuery(this.#transport, options)
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
similar(seriesId, options = {}) {
|
|
667
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/similar`, {
|
|
668
|
+
query: tvListQuery(this.#transport, options)
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
videos(seriesId, options = {}) {
|
|
672
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/videos`, {
|
|
673
|
+
query: withLanguage(this.#transport.defaults, {
|
|
674
|
+
language: options.language
|
|
675
|
+
})
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
seasonDetails(seriesId, seasonNumber, options = {}) {
|
|
679
|
+
return this.#transport.get(`/tv/${toId(seriesId, "seriesId")}/season/${toId(seasonNumber, "seasonNumber")}`, {
|
|
680
|
+
query: withLanguage(this.#transport.defaults, {
|
|
681
|
+
append_to_response: toCommaList(options.appendToResponse),
|
|
682
|
+
language: options.language
|
|
683
|
+
})
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
}
|
|
613
687
|
function tvListQuery(transport, options) {
|
|
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
|
-
this.movies = new MoviesResource(this.#transport);
|
|
650
|
-
this.people = new PeopleResource(this.#transport);
|
|
651
|
-
this.search = new SearchResource(this.#transport);
|
|
652
|
-
this.trending = new TrendingResource(this.#transport);
|
|
653
|
-
this.tv = new TVResource(this.#transport);
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Make a raw GET request to any TMDB endpoint.
|
|
657
|
-
*
|
|
658
|
-
* This is an escape hatch for endpoints not covered by the typed resource
|
|
659
|
-
* helpers. The `path` should be relative to the API base URL (e.g.
|
|
660
|
-
* `/movie/{id}/credits`). Response is parsed as JSON and cast to `T`.
|
|
661
|
-
*
|
|
662
|
-
* @param path - API path relative to the base URL (e.g. `/movie/123`)
|
|
663
|
-
* @param options - Optional request-level overrides (headers, query, signal)
|
|
664
|
-
* @returns Parsed JSON response typed as `T`
|
|
665
|
-
*/
|
|
666
|
-
request(path, options) {
|
|
667
|
-
return this.#transport.get(path, options);
|
|
668
|
-
}
|
|
669
|
-
};
|
|
670
|
-
/**
|
|
671
|
-
* Create a new {@link TMDBClient} instance.
|
|
672
|
-
*
|
|
673
|
-
* @example
|
|
674
|
-
* ```ts
|
|
675
|
-
* const tmdb = createTMDB({ accessToken: 'YOUR_TOKEN' })
|
|
676
|
-
* const { results } = await tmdb.search.movies('Inception')
|
|
677
|
-
* ```
|
|
678
|
-
*
|
|
679
|
-
* @param options - Authentication and configuration options
|
|
680
|
-
* @returns A configured TMDBClient ready to make API calls
|
|
681
|
-
*/
|
|
688
|
+
return withLanguage(transport.defaults, {
|
|
689
|
+
language: options.language,
|
|
690
|
+
page: options.page
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// src/client.ts
|
|
695
|
+
class TMDBClient {
|
|
696
|
+
configuration;
|
|
697
|
+
genres;
|
|
698
|
+
images;
|
|
699
|
+
movies;
|
|
700
|
+
people;
|
|
701
|
+
search;
|
|
702
|
+
trending;
|
|
703
|
+
tv;
|
|
704
|
+
#transport;
|
|
705
|
+
constructor(options) {
|
|
706
|
+
const { transport, images, ...httpOptions } = options;
|
|
707
|
+
const fallbackTransform = images?.transform;
|
|
708
|
+
const builtInClient = transport === undefined ? new TMDBHttpClient({ ...httpOptions, images }) : undefined;
|
|
709
|
+
this.#transport = builtInClient ?? transport;
|
|
710
|
+
this.configuration = new ConfigurationResource(this.#transport);
|
|
711
|
+
this.genres = new GenresResource(this.#transport);
|
|
712
|
+
this.images = new ImagesHelper(this.#transport, builtInClient ? builtInClient.imageTransform : fallbackTransform);
|
|
713
|
+
this.movies = new MoviesResource(this.#transport);
|
|
714
|
+
this.people = new PeopleResource(this.#transport);
|
|
715
|
+
this.search = new SearchResource(this.#transport);
|
|
716
|
+
this.trending = new TrendingResource(this.#transport);
|
|
717
|
+
this.tv = new TVResource(this.#transport);
|
|
718
|
+
}
|
|
719
|
+
request(path, options) {
|
|
720
|
+
return this.#transport.get(path, options);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
682
723
|
function createTMDB(options) {
|
|
683
|
-
|
|
724
|
+
return new TMDBClient(options);
|
|
684
725
|
}
|
|
685
|
-
|
|
686
|
-
//#region src/search-guards.ts
|
|
726
|
+
// src/search-guards.ts
|
|
687
727
|
function isMovieSearchResult(result) {
|
|
688
|
-
|
|
728
|
+
return isObjectWithMediaType(result, "movie");
|
|
689
729
|
}
|
|
690
730
|
function isTVSearchResult(result) {
|
|
691
|
-
|
|
731
|
+
return isObjectWithMediaType(result, "tv");
|
|
692
732
|
}
|
|
693
733
|
function isPersonSearchResult(result) {
|
|
694
|
-
|
|
734
|
+
return isObjectWithMediaType(result, "person");
|
|
695
735
|
}
|
|
696
736
|
function isMovie(result) {
|
|
697
|
-
|
|
737
|
+
return isObjectWithMediaType(result, "movie");
|
|
698
738
|
}
|
|
699
739
|
function isTV(result) {
|
|
700
|
-
|
|
740
|
+
return isObjectWithMediaType(result, "tv");
|
|
701
741
|
}
|
|
702
742
|
function isPerson(result) {
|
|
703
|
-
|
|
743
|
+
return isObjectWithMediaType(result, "person");
|
|
704
744
|
}
|
|
705
|
-
/** Internal helper: check if a value is an object with a matching `media_type` field. */
|
|
706
745
|
function isObjectWithMediaType(value, mediaType) {
|
|
707
|
-
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
* canonical list lets callers:
|
|
716
|
-
*
|
|
717
|
-
* - iterate over the set to build a size picker
|
|
718
|
-
* - validate user-supplied sizes with `isKnownBackdropSize(...)` etc.
|
|
719
|
-
* - type a variable as a "known" size without giving up the
|
|
720
|
-
* `(string & {})` escape hatch for forward-compatibility
|
|
721
|
-
*
|
|
722
|
-
* If TMDB publishes a new size, the SDK will still accept it at runtime
|
|
723
|
-
* (every helper is `(string & {})` permissive), but you will need to
|
|
724
|
-
* add the literal to these constants to get autocomplete on it.
|
|
725
|
-
*/
|
|
726
|
-
const KNOWN_BACKDROP_SIZES = Object.freeze([
|
|
727
|
-
"w300",
|
|
728
|
-
"w780",
|
|
729
|
-
"w1280",
|
|
730
|
-
"original"
|
|
746
|
+
return typeof value === "object" && value !== null && "media_type" in value && value.media_type === mediaType;
|
|
747
|
+
}
|
|
748
|
+
// src/types.ts
|
|
749
|
+
var KNOWN_BACKDROP_SIZES = Object.freeze([
|
|
750
|
+
"w300",
|
|
751
|
+
"w780",
|
|
752
|
+
"w1280",
|
|
753
|
+
"original"
|
|
731
754
|
]);
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
"original"
|
|
755
|
+
var KNOWN_LOGO_SIZES = Object.freeze(["w45", "w92", "w154", "w185", "w300", "w500", "original"]);
|
|
756
|
+
var KNOWN_POSTER_SIZES = Object.freeze(["w92", "w154", "w185", "w342", "w500", "w780", "original"]);
|
|
757
|
+
var KNOWN_PROFILE_SIZES = Object.freeze([
|
|
758
|
+
"w45",
|
|
759
|
+
"w185",
|
|
760
|
+
"h632",
|
|
761
|
+
"original"
|
|
740
762
|
]);
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
"w500",
|
|
747
|
-
"w780",
|
|
748
|
-
"original"
|
|
763
|
+
var KNOWN_STILL_SIZES = Object.freeze([
|
|
764
|
+
"w92",
|
|
765
|
+
"w185",
|
|
766
|
+
"w300",
|
|
767
|
+
"original"
|
|
749
768
|
]);
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
769
|
+
var KNOWN_IMAGE_SIZES = Object.freeze([
|
|
770
|
+
...KNOWN_BACKDROP_SIZES,
|
|
771
|
+
...KNOWN_LOGO_SIZES,
|
|
772
|
+
...KNOWN_POSTER_SIZES,
|
|
773
|
+
...KNOWN_PROFILE_SIZES,
|
|
774
|
+
...KNOWN_STILL_SIZES
|
|
755
775
|
]);
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
/** Union of every documented image size. */
|
|
763
|
-
const KNOWN_IMAGE_SIZES = Object.freeze([
|
|
764
|
-
...KNOWN_BACKDROP_SIZES,
|
|
765
|
-
...KNOWN_LOGO_SIZES,
|
|
766
|
-
...KNOWN_POSTER_SIZES,
|
|
767
|
-
...KNOWN_PROFILE_SIZES,
|
|
768
|
-
...KNOWN_STILL_SIZES
|
|
769
|
-
]);
|
|
770
|
-
/** O(1) membership check backed by a Set. */
|
|
771
|
-
const KNOWN_BACKDROP_SET = new Set(KNOWN_BACKDROP_SIZES);
|
|
772
|
-
const KNOWN_LOGO_SET = new Set(KNOWN_LOGO_SIZES);
|
|
773
|
-
const KNOWN_POSTER_SET = new Set(KNOWN_POSTER_SIZES);
|
|
774
|
-
const KNOWN_PROFILE_SET = new Set(KNOWN_PROFILE_SIZES);
|
|
775
|
-
const KNOWN_STILL_SET = new Set(KNOWN_STILL_SIZES);
|
|
776
|
-
const KNOWN_IMAGE_SET = new Set(KNOWN_IMAGE_SIZES);
|
|
776
|
+
var KNOWN_BACKDROP_SET = new Set(KNOWN_BACKDROP_SIZES);
|
|
777
|
+
var KNOWN_LOGO_SET = new Set(KNOWN_LOGO_SIZES);
|
|
778
|
+
var KNOWN_POSTER_SET = new Set(KNOWN_POSTER_SIZES);
|
|
779
|
+
var KNOWN_PROFILE_SET = new Set(KNOWN_PROFILE_SIZES);
|
|
780
|
+
var KNOWN_STILL_SET = new Set(KNOWN_STILL_SIZES);
|
|
781
|
+
var KNOWN_IMAGE_SET = new Set(KNOWN_IMAGE_SIZES);
|
|
777
782
|
function isKnownBackdropSize(value) {
|
|
778
|
-
|
|
783
|
+
return KNOWN_BACKDROP_SET.has(value);
|
|
779
784
|
}
|
|
780
785
|
function isKnownLogoSize(value) {
|
|
781
|
-
|
|
786
|
+
return KNOWN_LOGO_SET.has(value);
|
|
782
787
|
}
|
|
783
788
|
function isKnownPosterSize(value) {
|
|
784
|
-
|
|
789
|
+
return KNOWN_POSTER_SET.has(value);
|
|
785
790
|
}
|
|
786
791
|
function isKnownProfileSize(value) {
|
|
787
|
-
|
|
792
|
+
return KNOWN_PROFILE_SET.has(value);
|
|
788
793
|
}
|
|
789
794
|
function isKnownStillSize(value) {
|
|
790
|
-
|
|
795
|
+
return KNOWN_STILL_SET.has(value);
|
|
791
796
|
}
|
|
792
|
-
/** True if `value` is in any documented size set. */
|
|
793
797
|
function isKnownImageSize(value) {
|
|
794
|
-
|
|
795
|
-
}
|
|
796
|
-
//#endregion
|
|
797
|
-
exports.KNOWN_BACKDROP_SIZES = KNOWN_BACKDROP_SIZES;
|
|
798
|
-
exports.KNOWN_IMAGE_SIZES = KNOWN_IMAGE_SIZES;
|
|
799
|
-
exports.KNOWN_LOGO_SIZES = KNOWN_LOGO_SIZES;
|
|
800
|
-
exports.KNOWN_POSTER_SIZES = KNOWN_POSTER_SIZES;
|
|
801
|
-
exports.KNOWN_PROFILE_SIZES = KNOWN_PROFILE_SIZES;
|
|
802
|
-
exports.KNOWN_STILL_SIZES = KNOWN_STILL_SIZES;
|
|
803
|
-
exports.TMDBClient = TMDBClient;
|
|
804
|
-
exports.TMDBError = TMDBError;
|
|
805
|
-
exports.TMDBRateLimitError = TMDBRateLimitError;
|
|
806
|
-
exports.TMDBRequestError = TMDBRequestError;
|
|
807
|
-
exports.TMDBResponseError = TMDBResponseError;
|
|
808
|
-
exports.buildImageUrl = buildImageUrl;
|
|
809
|
-
exports.createTMDB = createTMDB;
|
|
810
|
-
exports.isKnownBackdropSize = isKnownBackdropSize;
|
|
811
|
-
exports.isKnownImageSize = isKnownImageSize;
|
|
812
|
-
exports.isKnownLogoSize = isKnownLogoSize;
|
|
813
|
-
exports.isKnownPosterSize = isKnownPosterSize;
|
|
814
|
-
exports.isKnownProfileSize = isKnownProfileSize;
|
|
815
|
-
exports.isKnownStillSize = isKnownStillSize;
|
|
816
|
-
exports.isMovie = isMovie;
|
|
817
|
-
exports.isMovieSearchResult = isMovieSearchResult;
|
|
818
|
-
exports.isPerson = isPerson;
|
|
819
|
-
exports.isPersonSearchResult = isPersonSearchResult;
|
|
820
|
-
exports.isTV = isTV;
|
|
821
|
-
exports.isTVSearchResult = isTVSearchResult;
|
|
798
|
+
return KNOWN_IMAGE_SET.has(value);
|
|
799
|
+
}
|
|
822
800
|
|
|
823
|
-
//#
|
|
801
|
+
//# debugId=CD39AE1F6030D61F64756E2164756E21
|
|
802
|
+
//# sourceMappingURL=index.cjs.map
|