@lorenzopant/tmdb 0.0.2
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/.env +1 -0
- package/.prettierrc +5 -0
- package/.release-it.json +8 -0
- package/README.md +153 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +42 -0
- package/dist/endpoints/movie_lists.d.ts +56 -0
- package/dist/endpoints/movie_lists.js +73 -0
- package/dist/endpoints/movies.d.ts +202 -0
- package/dist/endpoints/movies.js +256 -0
- package/dist/endpoints/search.d.ts +25 -0
- package/dist/endpoints/search.js +36 -0
- package/dist/errors/messages.d.ts +15 -0
- package/dist/errors/messages.js +53 -0
- package/dist/errors/tmdb.d.ts +45 -0
- package/dist/errors/tmdb.js +39 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/tmdb.d.ts +10 -0
- package/dist/tmdb.js +21 -0
- package/dist/types/common.d.ts +113 -0
- package/dist/types/common.js +2 -0
- package/dist/types/enums.d.ts +8 -0
- package/dist/types/enums.js +9 -0
- package/dist/types/movies.d.ts +132 -0
- package/dist/types/movies.js +2 -0
- package/dist/types/params.d.ts +6 -0
- package/dist/types/params.js +1 -0
- package/dist/types/utility.d.ts +97 -0
- package/dist/types/utility.js +98 -0
- package/package.json +37 -0
- package/tsconfig.json +114 -0
- package/vitest.config.mts +16 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
export const MOVIE_ENDPOINTS = {
|
|
2
|
+
MOVIE: "/movie",
|
|
3
|
+
ALTERNATIVE_TITLES: "/alternative_titles",
|
|
4
|
+
CREDITS: "/credits",
|
|
5
|
+
EXTERNAL_IDS: "/external_ids",
|
|
6
|
+
KEYWORDS: "/keywords",
|
|
7
|
+
CHANGES: "/changes",
|
|
8
|
+
IMAGES: "/images",
|
|
9
|
+
LATEST: "/latest",
|
|
10
|
+
RECOMMENDATIONS: "/recommendations",
|
|
11
|
+
RELEASE_DATES: "/release_dates",
|
|
12
|
+
SIMILAR: "/similar",
|
|
13
|
+
TRANSLATIONS: "/translations",
|
|
14
|
+
VIDEOS: "/videos",
|
|
15
|
+
WATCH_PROVIDERS: "/watch/providers",
|
|
16
|
+
// Missing:
|
|
17
|
+
// ACCOUNT_STATES
|
|
18
|
+
// LISTS
|
|
19
|
+
// REVIEWS
|
|
20
|
+
// ADD RATING
|
|
21
|
+
// DELETE RATING
|
|
22
|
+
};
|
|
23
|
+
export class MoviesAPI {
|
|
24
|
+
client;
|
|
25
|
+
constructor(client) {
|
|
26
|
+
this.client = client;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Details
|
|
30
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}
|
|
31
|
+
*
|
|
32
|
+
* Get the top level details of a movie by ID.
|
|
33
|
+
* @param movie_id The ID of the movie.
|
|
34
|
+
* @param append_to_response A comma-separated list of the fields to include in the response.
|
|
35
|
+
* @param language The language to use for the response.
|
|
36
|
+
* @returns A promise that resolves to the movie details.
|
|
37
|
+
* @reference https://developer.themoviedb.org/reference/movie-details
|
|
38
|
+
*/
|
|
39
|
+
async details(movie_id, append_to_response, language) {
|
|
40
|
+
const params = { append_to_response, language };
|
|
41
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}`;
|
|
42
|
+
return this.client.request(endpoint, params);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Alternative Titles
|
|
46
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/alternative_titles
|
|
47
|
+
*
|
|
48
|
+
* Get the alternative titles for a movie (ex. Russian name, Indian names etc..).
|
|
49
|
+
* @param movie_id The ID of the movie.
|
|
50
|
+
* @param country The ISO 3166-1 code of the country to get alternative titles for.
|
|
51
|
+
* @returns A promise that resolves to the movie alternative titles.
|
|
52
|
+
* @reference https://developer.themoviedb.org/reference/movie-alternative-titles
|
|
53
|
+
*/
|
|
54
|
+
async alternative_titles(movie_id, country) {
|
|
55
|
+
const params = { country: country || "" };
|
|
56
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.ALTERNATIVE_TITLES}`;
|
|
57
|
+
return this.client.request(endpoint, params);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Credits
|
|
61
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/credits
|
|
62
|
+
*
|
|
63
|
+
* Get the cast and crew members details for a movie.
|
|
64
|
+
* @param movie_id The ID of the movie.
|
|
65
|
+
* @param language The ISO 639-1 code of the language to use for the response. Default is "en-US".
|
|
66
|
+
* @returns A promise that resolves to the movie credits.
|
|
67
|
+
* @reference https://developer.themoviedb.org/reference/movie-credits
|
|
68
|
+
*/
|
|
69
|
+
async credits(movie_id, language = "en-US") {
|
|
70
|
+
const params = { language };
|
|
71
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.CREDITS}`;
|
|
72
|
+
return this.client.request(endpoint, params);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* External IDs
|
|
76
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/external_ids
|
|
77
|
+
*
|
|
78
|
+
* Get the external IDs for a movie (ex. IMDB, Facebook, Instagram etc..).
|
|
79
|
+
* Supported external IDs are: IMDB, Facebook, Instagram, Twitter, and Wikidata.
|
|
80
|
+
*
|
|
81
|
+
* @param movie_id The ID of the movie.
|
|
82
|
+
* @returns A promise that resolves to the movie external IDs.
|
|
83
|
+
* @reference https://developer.themoviedb.org/reference/movie-external-ids
|
|
84
|
+
*/
|
|
85
|
+
async external_ids(movie_id) {
|
|
86
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.EXTERNAL_IDS}`;
|
|
87
|
+
return this.client.request(endpoint);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Keywords
|
|
91
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/keywords
|
|
92
|
+
*
|
|
93
|
+
* Get the keywords that have been added to a movie.
|
|
94
|
+
* This is a list of keywords that have been added to the movie.
|
|
95
|
+
* @param movie_id The ID of the movie.
|
|
96
|
+
* @returns A promise that resolves to the movie keywords.
|
|
97
|
+
* @reference https://developer.themoviedb.org/reference/movie-keywords
|
|
98
|
+
*/
|
|
99
|
+
async keywords(movie_id) {
|
|
100
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.KEYWORDS}`;
|
|
101
|
+
return this.client.request(endpoint);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Changes
|
|
105
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/changes
|
|
106
|
+
*
|
|
107
|
+
* Get the changes for a movie. This is a list of all the changes that have been made to a movie.
|
|
108
|
+
* By default, only the last 24 hours are returned.
|
|
109
|
+
* You can query up to 14 days in a single query by using the start_date and end_date query parameters.
|
|
110
|
+
* @param movie_id The ID of the movie.
|
|
111
|
+
* @param page Page number of the results to return. Defaults to 1.
|
|
112
|
+
* @param start_date Optional start date for the changes. Format: YYYY-MM-DD.
|
|
113
|
+
* @param end_date Optional end date for the changes. Format: YYYY-MM-DD.
|
|
114
|
+
* @returns A promise that resolves to the changes made to the movie.
|
|
115
|
+
* @reference https://developer.themoviedb.org/reference/movie-changes
|
|
116
|
+
*/
|
|
117
|
+
async changes(movie_id, page, start_date, end_date) {
|
|
118
|
+
const params = { page, start_date, end_date };
|
|
119
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.CHANGES}`;
|
|
120
|
+
return this.client.request(endpoint, params);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Images
|
|
124
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/images
|
|
125
|
+
*
|
|
126
|
+
* Fetches images related to a specific movie, such as posters and backdrops.
|
|
127
|
+
* The images are returned in various sizes and formats.
|
|
128
|
+
* @param movie_id - The unique identifier of the movie.
|
|
129
|
+
* @param language - (Optional) The language code to filter the images by language.
|
|
130
|
+
* @param include_image_language - (Optional) A comma-separated list of language codes to include images for.
|
|
131
|
+
* @returns A promise that resolves to a `MovieImages` object containing the movie's images.
|
|
132
|
+
* @reference https://developer.themoviedb.org/reference/movie-images
|
|
133
|
+
*/
|
|
134
|
+
async images(movie_id, language, include_image_language) {
|
|
135
|
+
const params = { language, include_image_language };
|
|
136
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.IMAGES}`;
|
|
137
|
+
return this.client.request(endpoint, params);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Latest
|
|
141
|
+
* GET - https://api.themoviedb.org/3/movie/latest
|
|
142
|
+
*
|
|
143
|
+
* Get the newest movie ID.
|
|
144
|
+
* This is the most recent movie that has been added to TMDB. This is a live response will continuously change as new movies are added.
|
|
145
|
+
* @returns A promise that resolves to the latest movie details.
|
|
146
|
+
* @reference https://developer.themoviedb.org/reference/movie-latest-id
|
|
147
|
+
*/
|
|
148
|
+
async latest() {
|
|
149
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}${MOVIE_ENDPOINTS.LATEST}`;
|
|
150
|
+
return this.client.request(endpoint);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Recommendations
|
|
154
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/recommendations
|
|
155
|
+
*
|
|
156
|
+
* Get a list of recommended movies for a specific movie.
|
|
157
|
+
* This is based on the movie's popularity and user ratings.
|
|
158
|
+
* @param movie_id The ID of the movie.
|
|
159
|
+
* @param page Page number of the results to return. Defaults to 1.
|
|
160
|
+
* @param language Language code to filter the results. Default is "en-US".
|
|
161
|
+
* @returns A promise that resolves to a paginated response of similar movies.
|
|
162
|
+
* @reference https://developer.themoviedb.org/reference/movie-recommendations
|
|
163
|
+
*/
|
|
164
|
+
async recommendations(movie_id, page, language) {
|
|
165
|
+
const params = { page, language };
|
|
166
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.RECOMMENDATIONS}`;
|
|
167
|
+
return this.client.request(endpoint, params);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Release Dates
|
|
171
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/release_dates
|
|
172
|
+
*
|
|
173
|
+
* Get the release dates and certifications for a movie. For different countries and release types.
|
|
174
|
+
* The release types and statuses used on TMDB are the following:
|
|
175
|
+
* - 1: Premiere
|
|
176
|
+
* - 2: Theatrical (Limited)
|
|
177
|
+
* - 3: Theatrical
|
|
178
|
+
* - 4: Digital
|
|
179
|
+
* - 5: Physical
|
|
180
|
+
* - 6: TV
|
|
181
|
+
* @param movie_id The ID of the movie.
|
|
182
|
+
* @returns A promise that resolves to the release dates for the movie.
|
|
183
|
+
* @reference https://developer.themoviedb.org/reference/movie-release-dates
|
|
184
|
+
*/
|
|
185
|
+
async release_dates(movie_id) {
|
|
186
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.RELEASE_DATES}`;
|
|
187
|
+
return this.client.request(endpoint);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Similar
|
|
191
|
+
* GET -https://api.themoviedb.org/3/movie/{movie_id}/similar
|
|
192
|
+
*
|
|
193
|
+
* Get the similar movies based on genres and keywords.
|
|
194
|
+
* This method only looks for other items based on genres and plot keywords.
|
|
195
|
+
* As such, the results found here are not always going to be 💯. Use it with that in mind.
|
|
196
|
+
* @param movie_id The ID of the movie
|
|
197
|
+
* @param page Page number of the results to return. Defaults to 1.
|
|
198
|
+
* @param language Language code to filter the results. Default is "en-US".
|
|
199
|
+
* @returns A promise that resolves to a paginated response of similar movies.
|
|
200
|
+
* @reference https://developer.themoviedb.org/reference/movie-similar
|
|
201
|
+
*/
|
|
202
|
+
async similar(movie_id, language, page) {
|
|
203
|
+
const params = { page, language };
|
|
204
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.SIMILAR}`;
|
|
205
|
+
return this.client.request(endpoint, params);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Translations
|
|
209
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/translations
|
|
210
|
+
*
|
|
211
|
+
* Get the translations for a movie.
|
|
212
|
+
* Take a read through our language documentation for more information about languages on TMDB.
|
|
213
|
+
* https://developer.themoviedb.org/docs/languages
|
|
214
|
+
* @param movie_id The ID of the movie
|
|
215
|
+
* @returns A promise that resolves to the translations of the movie.
|
|
216
|
+
* @reference https://developer.themoviedb.org/reference/movie-translations
|
|
217
|
+
*/
|
|
218
|
+
async translations(movie_id) {
|
|
219
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.TRANSLATIONS}`;
|
|
220
|
+
return this.client.request(endpoint);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Videos
|
|
224
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/videos
|
|
225
|
+
*
|
|
226
|
+
* Get the available videos for a movie.
|
|
227
|
+
* @param movie_id The ID of the movie
|
|
228
|
+
* @returns A promise that resolves to a list of videos for the movie.
|
|
229
|
+
* @reference https://developer.themoviedb.org/reference/movie-videos
|
|
230
|
+
*/
|
|
231
|
+
async videos(movie_id, language) {
|
|
232
|
+
const params = { language };
|
|
233
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.VIDEOS}`;
|
|
234
|
+
return this.client.request(endpoint, params);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Watch Providers
|
|
238
|
+
* GET - https://api.themoviedb.org/3/movie/{movie_id}/watch/providers
|
|
239
|
+
*
|
|
240
|
+
* Get the list of streaming providers we have for a movie.
|
|
241
|
+
* Powered by our partnership with JustWatch, you can query this method to get a list of the streaming/rental/purchase availabilities per country by provider.
|
|
242
|
+
* This is not going to return full deep links, but rather, it's just enough information to display what's available where.
|
|
243
|
+
* You can link to the provided TMDB URL to help support TMDB and provide the actual deep links to the content.
|
|
244
|
+
*
|
|
245
|
+
* JustWatch ATTRIBUTION REQUIRED
|
|
246
|
+
* In order to use this data you must attribute the source of the data as JustWatch.
|
|
247
|
+
* If we find any usage not complying with these terms we will revoke access to the API.
|
|
248
|
+
* @param movie_id The ID of the movie
|
|
249
|
+
* @returns A promise that resolves to a list of videos for the movie.
|
|
250
|
+
* @reference https://developer.themoviedb.org/reference/movie-videos
|
|
251
|
+
*/
|
|
252
|
+
async watch_providers(movie_id) {
|
|
253
|
+
const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.WATCH_PROVIDERS}`;
|
|
254
|
+
return this.client.request(endpoint);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ApiClient } from "../client";
|
|
2
|
+
import { MovieResultItem } from "../types/movies";
|
|
3
|
+
import { PaginatedResponse } from "../types/params";
|
|
4
|
+
export declare const SEARCH_ENDPOINTS: {
|
|
5
|
+
MOVIE: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class SearchAPI {
|
|
8
|
+
private client;
|
|
9
|
+
constructor(client: ApiClient);
|
|
10
|
+
/**
|
|
11
|
+
* Search
|
|
12
|
+
* GET - https://api.themoviedb.org/3/search/movie
|
|
13
|
+
*
|
|
14
|
+
* Search for movies by their original, translated and alternative titles.
|
|
15
|
+
* @param query Search query (required)
|
|
16
|
+
* @param include_adult Include Adult (Defaults to false)
|
|
17
|
+
* @param language Language (Defaults to en-US)
|
|
18
|
+
* @param primary_release_year: string
|
|
19
|
+
* @param page Page (Defaults to 1)
|
|
20
|
+
* @param region Region
|
|
21
|
+
* @param year Year
|
|
22
|
+
* @reference https://developer.themoviedb.org/reference/search-movie
|
|
23
|
+
*/
|
|
24
|
+
movies(query: string, include_adult?: boolean, language?: string, page?: number, primary_release_year?: string, region?: string, year?: string): Promise<PaginatedResponse<MovieResultItem>>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const SEARCH_ENDPOINTS = {
|
|
2
|
+
MOVIE: "/search/movie",
|
|
3
|
+
};
|
|
4
|
+
export class SearchAPI {
|
|
5
|
+
client;
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Search
|
|
11
|
+
* GET - https://api.themoviedb.org/3/search/movie
|
|
12
|
+
*
|
|
13
|
+
* Search for movies by their original, translated and alternative titles.
|
|
14
|
+
* @param query Search query (required)
|
|
15
|
+
* @param include_adult Include Adult (Defaults to false)
|
|
16
|
+
* @param language Language (Defaults to en-US)
|
|
17
|
+
* @param primary_release_year: string
|
|
18
|
+
* @param page Page (Defaults to 1)
|
|
19
|
+
* @param region Region
|
|
20
|
+
* @param year Year
|
|
21
|
+
* @reference https://developer.themoviedb.org/reference/search-movie
|
|
22
|
+
*/
|
|
23
|
+
async movies(query, include_adult = false, language = "en-US", page = 1, primary_release_year, region, year) {
|
|
24
|
+
const params = {
|
|
25
|
+
query,
|
|
26
|
+
include_adult,
|
|
27
|
+
language,
|
|
28
|
+
page,
|
|
29
|
+
primary_release_year,
|
|
30
|
+
year,
|
|
31
|
+
region,
|
|
32
|
+
};
|
|
33
|
+
const endpoint = `${SEARCH_ENDPOINTS.MOVIE}`;
|
|
34
|
+
return this.client.request(endpoint, params);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A collection of error messages used throughout the application.
|
|
3
|
+
* For library-specific errors (-1 status code) only.
|
|
4
|
+
*/
|
|
5
|
+
export declare const Errors: {
|
|
6
|
+
NO_ACCESS_TOKEN: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* TMDB Error Codes and messages.
|
|
10
|
+
* @reference https://developer.themoviedb.org/docs/errors
|
|
11
|
+
*/
|
|
12
|
+
export declare const TMDB_ERRORS: Map<number, {
|
|
13
|
+
message: string;
|
|
14
|
+
http_status: number;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A collection of error messages used throughout the application.
|
|
3
|
+
* For library-specific errors (-1 status code) only.
|
|
4
|
+
*/
|
|
5
|
+
export const Errors = {
|
|
6
|
+
NO_ACCESS_TOKEN: "TMDB requires a valid access token, please provide one.",
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* TMDB Error Codes and messages.
|
|
10
|
+
* @reference https://developer.themoviedb.org/docs/errors
|
|
11
|
+
*/
|
|
12
|
+
export const TMDB_ERRORS = new Map([
|
|
13
|
+
[1, { message: "Success", http_status: 200 }],
|
|
14
|
+
[2, { message: "Invalid service: this service does not exist.", http_status: 501 }],
|
|
15
|
+
[3, { message: "Authentication failed: You do not have permissions to access the service.", http_status: 401 }],
|
|
16
|
+
[4, { message: "Invalid format: This service doesn't exist in that format.", http_status: 405 }],
|
|
17
|
+
[5, { message: "Invalid parameters: Your request parameters are incorrect.", http_status: 422 }],
|
|
18
|
+
[6, { message: "Invalid id: The pre-requisite id is invalid or not found.", http_status: 404 }],
|
|
19
|
+
[7, { message: "Invalid API key: You must be granted a valid key.", http_status: 401 }],
|
|
20
|
+
[8, { message: "Duplicate entry: The data you tried to submit already exists.", http_status: 403 }],
|
|
21
|
+
[9, { message: "Service offline: This service is temporarily offline, try again later.", http_status: 503 }],
|
|
22
|
+
[10, { message: "Suspended API key: Access to your account has been suspended, contact TMDB.", http_status: 401 }],
|
|
23
|
+
[11, { message: "Internal error: Something went wrong, contact TMDB.", http_status: 500 }],
|
|
24
|
+
[12, { message: "The item/record was updated successfully.", http_status: 201 }],
|
|
25
|
+
[13, { message: "The item/record was deleted successfully.", http_status: 200 }],
|
|
26
|
+
[14, { message: "Authentication failed.", http_status: 401 }],
|
|
27
|
+
[15, { message: "Failed", http_status: 500 }],
|
|
28
|
+
[16, { message: "Device denied.", http_status: 401 }],
|
|
29
|
+
[17, { message: "Session denied.", http_status: 401 }],
|
|
30
|
+
[18, { message: "Validation failed.", http_status: 400 }],
|
|
31
|
+
[19, { message: "Invalid accept header.", http_status: 406 }],
|
|
32
|
+
[20, { message: "Invalid date range: Should be a range no longer than 14 days.", http_status: 422 }],
|
|
33
|
+
[21, { message: "Entry not found: The item you are trying to edit cannot be found.", http_status: 200 }],
|
|
34
|
+
[
|
|
35
|
+
22,
|
|
36
|
+
{
|
|
37
|
+
message: "Invalid page: Pages start at 1 and max at 500. They are expected to be an integer.",
|
|
38
|
+
http_status: 400,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
[23, { message: "Invalid date: Format needs to be YYYY-MM-DD.", http_status: 400 }],
|
|
42
|
+
[24, { message: "Your request to the backend server timed out. Try again.", http_status: 504 }],
|
|
43
|
+
[25, { message: "Your request count (#) is over the allowed limit of (40).", http_status: 429 }],
|
|
44
|
+
[26, { message: "You must provide a username and password.", http_status: 400 }],
|
|
45
|
+
[27, { message: "Too many append to response objects: The maximum number of remote calls is 20.", http_status: 400 }],
|
|
46
|
+
[28, { message: "Invalid timezone: Please consult the documentation for a valid timezone.", http_status: 400 }],
|
|
47
|
+
[29, { message: "Invalid date range: Should be a range no longer than 14 days.", http_status: 422 }],
|
|
48
|
+
[30, { message: "Invalid date range: Should be a range no longer than 14 days.", http_status: 422 }],
|
|
49
|
+
[31, { message: "Invalid date range: Should be a range no longer than 14 days.", http_status: 422 }],
|
|
50
|
+
[32, { message: "Invalid date range: Should be a range no longer than 14 days.", http_status: 422 }],
|
|
51
|
+
[33, { message: "Invalid date range: Should be a range no longer than 14 days.", http_status: 422 }],
|
|
52
|
+
[34, { message: "The resource you requested could not be found.", http_status: 404 }],
|
|
53
|
+
]);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the structure of an error response returned by the TMDB API.
|
|
3
|
+
*
|
|
4
|
+
* @property success - Indicates whether the API request was successful. This will typically be `false` for error responses.
|
|
5
|
+
* @property status_code - The numeric code representing the type of error encountered.
|
|
6
|
+
* @property status_message - A descriptive message providing details about the error.
|
|
7
|
+
*/
|
|
8
|
+
export type TMDBAPIErrorResponse = {
|
|
9
|
+
success: boolean;
|
|
10
|
+
status_code: number;
|
|
11
|
+
status_message: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents a generic error or an error specific to the TMDB (The Movie Database) API.
|
|
15
|
+
* This error class extends the built-in `Error` class and includes additional
|
|
16
|
+
* properties to provide more context about the error.
|
|
17
|
+
*/
|
|
18
|
+
export declare class TMDBError extends Error {
|
|
19
|
+
/**
|
|
20
|
+
* The status code returned by the TMDB API.
|
|
21
|
+
* If the value is `-1`, it indicates a library-specific error rather than a TMDB API error.
|
|
22
|
+
* @reference https://developer.themoviedb.org/docs/errors - code
|
|
23
|
+
*/
|
|
24
|
+
tmdb_status_code: number;
|
|
25
|
+
/**
|
|
26
|
+
* A descriptive message providing details about the error.
|
|
27
|
+
* If the error is specific to the TMDB API, this message will be derived from the API response
|
|
28
|
+
* @reference https://developer.themoviedb.org/docs/errors - message
|
|
29
|
+
*/
|
|
30
|
+
message: string;
|
|
31
|
+
/**
|
|
32
|
+
* The HTTP status code associated with the error.
|
|
33
|
+
* If the error is specific to the TMDB API, this code will be derived from the API response.
|
|
34
|
+
* @reference https://developer.themoviedb.org/docs/errors - HTTP Status
|
|
35
|
+
*/
|
|
36
|
+
http_status_code: number;
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of `TMDBError`.
|
|
39
|
+
*
|
|
40
|
+
* @param message - A descriptive message providing details about the error.
|
|
41
|
+
* @param http_status - The HTTP status code associated with the error.
|
|
42
|
+
* @param tmdb_status_code - (Optional) The status code returned by the TMDB API. Defaults to `-1` for library-specific errors.
|
|
43
|
+
*/
|
|
44
|
+
constructor(message: string, http_status: number, tmdb_status_code?: number);
|
|
45
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a generic error or an error specific to the TMDB (The Movie Database) API.
|
|
3
|
+
* This error class extends the built-in `Error` class and includes additional
|
|
4
|
+
* properties to provide more context about the error.
|
|
5
|
+
*/
|
|
6
|
+
export class TMDBError extends Error {
|
|
7
|
+
/**
|
|
8
|
+
* The status code returned by the TMDB API.
|
|
9
|
+
* If the value is `-1`, it indicates a library-specific error rather than a TMDB API error.
|
|
10
|
+
* @reference https://developer.themoviedb.org/docs/errors - code
|
|
11
|
+
*/
|
|
12
|
+
tmdb_status_code;
|
|
13
|
+
/**
|
|
14
|
+
* A descriptive message providing details about the error.
|
|
15
|
+
* If the error is specific to the TMDB API, this message will be derived from the API response
|
|
16
|
+
* @reference https://developer.themoviedb.org/docs/errors - message
|
|
17
|
+
*/
|
|
18
|
+
message;
|
|
19
|
+
/**
|
|
20
|
+
* The HTTP status code associated with the error.
|
|
21
|
+
* If the error is specific to the TMDB API, this code will be derived from the API response.
|
|
22
|
+
* @reference https://developer.themoviedb.org/docs/errors - HTTP Status
|
|
23
|
+
*/
|
|
24
|
+
http_status_code;
|
|
25
|
+
/**
|
|
26
|
+
* Creates an instance of `TMDBError`.
|
|
27
|
+
*
|
|
28
|
+
* @param message - A descriptive message providing details about the error.
|
|
29
|
+
* @param http_status - The HTTP status code associated with the error.
|
|
30
|
+
* @param tmdb_status_code - (Optional) The status code returned by the TMDB API. Defaults to `-1` for library-specific errors.
|
|
31
|
+
*/
|
|
32
|
+
constructor(message, http_status, tmdb_status_code) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "TMDBError";
|
|
35
|
+
this.tmdb_status_code = tmdb_status_code || -1;
|
|
36
|
+
this.message = message;
|
|
37
|
+
this.http_status_code = http_status;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { TMDB } from "./tmdb";
|
|
2
|
+
export { TMDBError } from "./errors/tmdb";
|
|
3
|
+
export type { MovieDetails, MovieAlternativeTitle, MovieAlternativeTitles, MovieCredits, MovieExternalIDs, MovieImages, MovieKeywords, MovieReleaseDates, MovieTranslations, MovieVideos, } from "./types/movies";
|
|
4
|
+
export type { Changes, Collection, Genre, ImageItem, Keyword, ProductionCompany, ProductionCountry, SpokenLanguage, VideoItem, Cast, Crew, } from "./types/common";
|
package/dist/index.js
ADDED
package/dist/tmdb.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MovieListsAPI } from "./endpoints/movie_lists";
|
|
2
|
+
import { MoviesAPI } from "./endpoints/movies";
|
|
3
|
+
import { SearchAPI } from "./endpoints/search";
|
|
4
|
+
export declare class TMDB {
|
|
5
|
+
private client;
|
|
6
|
+
movies: MoviesAPI;
|
|
7
|
+
movie_lists: MovieListsAPI;
|
|
8
|
+
search: SearchAPI;
|
|
9
|
+
constructor(accessToken: string);
|
|
10
|
+
}
|
package/dist/tmdb.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src.tmdb.ts
|
|
2
|
+
import { ApiClient } from "./client";
|
|
3
|
+
import { MovieListsAPI } from "./endpoints/movie_lists";
|
|
4
|
+
import { MoviesAPI } from "./endpoints/movies";
|
|
5
|
+
import { SearchAPI } from "./endpoints/search";
|
|
6
|
+
import { Errors } from "./errors/messages";
|
|
7
|
+
export class TMDB {
|
|
8
|
+
client;
|
|
9
|
+
movies;
|
|
10
|
+
movie_lists;
|
|
11
|
+
search;
|
|
12
|
+
// etc...
|
|
13
|
+
constructor(accessToken) {
|
|
14
|
+
if (!accessToken)
|
|
15
|
+
throw new Error(Errors.NO_ACCESS_TOKEN);
|
|
16
|
+
this.client = new ApiClient(accessToken);
|
|
17
|
+
this.movies = new MoviesAPI(this.client);
|
|
18
|
+
this.movie_lists = new MovieListsAPI(this.client);
|
|
19
|
+
this.search = new SearchAPI(this.client);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a genre of a movie or TV show.
|
|
3
|
+
*/
|
|
4
|
+
export type Genre = {
|
|
5
|
+
id: number;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Represents a production company involved in creating a movie or TV show.
|
|
10
|
+
*/
|
|
11
|
+
export type ProductionCompany = {
|
|
12
|
+
id: number;
|
|
13
|
+
logo_path: string | null;
|
|
14
|
+
name: string;
|
|
15
|
+
origin_country: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Represents a country where a movie or TV show was produced.
|
|
19
|
+
*/
|
|
20
|
+
export type ProductionCountry = {
|
|
21
|
+
iso_3166_1: string;
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Represents a spoken language in a movie or TV show.
|
|
26
|
+
*/
|
|
27
|
+
export type SpokenLanguage = {
|
|
28
|
+
english_name: string;
|
|
29
|
+
iso_639_1: string;
|
|
30
|
+
name: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Represents a collection of movies.
|
|
34
|
+
*/
|
|
35
|
+
export type Collection = {
|
|
36
|
+
id: number;
|
|
37
|
+
name: string;
|
|
38
|
+
poster_path: string | null;
|
|
39
|
+
backdrop_path: string | null;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Represents a cast member in a movie or TV show.
|
|
43
|
+
*/
|
|
44
|
+
export type Cast = {
|
|
45
|
+
adult: boolean;
|
|
46
|
+
gender: number | null;
|
|
47
|
+
id: number;
|
|
48
|
+
known_for_department: string;
|
|
49
|
+
name: string;
|
|
50
|
+
original_name: string;
|
|
51
|
+
popularity: number;
|
|
52
|
+
profile_path?: string | null;
|
|
53
|
+
cast_id: number;
|
|
54
|
+
character: string;
|
|
55
|
+
credit_id: string;
|
|
56
|
+
order: number;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Represents a crew member in a movie or TV show.
|
|
60
|
+
*/
|
|
61
|
+
export type Crew = {
|
|
62
|
+
adult: boolean;
|
|
63
|
+
gender: number | null;
|
|
64
|
+
id: number;
|
|
65
|
+
known_for_department: string;
|
|
66
|
+
name: string;
|
|
67
|
+
original_name: string;
|
|
68
|
+
popularity: number;
|
|
69
|
+
profile_path?: string | null;
|
|
70
|
+
credit_id: string;
|
|
71
|
+
department: string;
|
|
72
|
+
job: string;
|
|
73
|
+
};
|
|
74
|
+
export type Keyword = {
|
|
75
|
+
id: number;
|
|
76
|
+
name: string;
|
|
77
|
+
};
|
|
78
|
+
export type Changes = {
|
|
79
|
+
changes: Change[];
|
|
80
|
+
};
|
|
81
|
+
export type Change = {
|
|
82
|
+
key: string;
|
|
83
|
+
items: ChangeItem[];
|
|
84
|
+
};
|
|
85
|
+
export type ChangeItem = {
|
|
86
|
+
id: number;
|
|
87
|
+
action: string;
|
|
88
|
+
time: string;
|
|
89
|
+
iso_639_1: string;
|
|
90
|
+
iso_3166_1: string;
|
|
91
|
+
value: any;
|
|
92
|
+
};
|
|
93
|
+
export type ImageItem = {
|
|
94
|
+
aspect_ratio: number;
|
|
95
|
+
height: number;
|
|
96
|
+
iso_639_1: string | null;
|
|
97
|
+
file_path: string;
|
|
98
|
+
vote_average: number;
|
|
99
|
+
vote_count: number;
|
|
100
|
+
width: number;
|
|
101
|
+
};
|
|
102
|
+
export type VideoItem = {
|
|
103
|
+
iso_649_1: string;
|
|
104
|
+
iso_3166_1: string;
|
|
105
|
+
name: string;
|
|
106
|
+
key: string;
|
|
107
|
+
site: string;
|
|
108
|
+
size: number;
|
|
109
|
+
type: string;
|
|
110
|
+
official: boolean;
|
|
111
|
+
published_at: string;
|
|
112
|
+
id: string;
|
|
113
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var ReleaseType;
|
|
2
|
+
(function (ReleaseType) {
|
|
3
|
+
ReleaseType[ReleaseType["Premiere"] = 1] = "Premiere";
|
|
4
|
+
ReleaseType[ReleaseType["TheatricalLimited"] = 2] = "TheatricalLimited";
|
|
5
|
+
ReleaseType[ReleaseType["Theatrical"] = 3] = "Theatrical";
|
|
6
|
+
ReleaseType[ReleaseType["Digital"] = 4] = "Digital";
|
|
7
|
+
ReleaseType[ReleaseType["Physical"] = 5] = "Physical";
|
|
8
|
+
ReleaseType[ReleaseType["TV"] = 6] = "TV";
|
|
9
|
+
})(ReleaseType || (ReleaseType = {}));
|