@lorenzopant/tmdb 0.0.5 → 0.0.7

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.
@@ -12,6 +12,7 @@ export declare class MovieListsAPI {
12
12
  private client;
13
13
  private defaultOptions;
14
14
  constructor(client: ApiClient, defaultOptions?: TMDBOptions);
15
+ private withDefaults;
15
16
  /**
16
17
  * Fetch Movie List Wrapper
17
18
  * @param endpoint Endpoint to call
@@ -13,6 +13,10 @@ export class MovieListsAPI {
13
13
  this.client = client;
14
14
  this.defaultOptions = defaultOptions;
15
15
  }
16
+ withDefaults(params) {
17
+ const { language = this.defaultOptions.language, region = this.defaultOptions.region, ...rest } = params;
18
+ return { language, region, ...rest };
19
+ }
16
20
  /**
17
21
  * Fetch Movie List Wrapper
18
22
  * @param endpoint Endpoint to call
@@ -20,8 +24,7 @@ export class MovieListsAPI {
20
24
  * @returns Specific to endpoint (MovieListResult)
21
25
  */
22
26
  fetch_movie_list(endpoint, params = {}) {
23
- const mergedParams = { ...this.defaultOptions, ...params };
24
- return this.client.request(MOVIE_ENDPOINTS.MOVIE + endpoint, mergedParams);
27
+ return this.client.request(MOVIE_ENDPOINTS.MOVIE + endpoint, this.withDefaults(params));
25
28
  }
26
29
  /**
27
30
  * Now Playing
@@ -1,8 +1,8 @@
1
1
  import { ApiClient } from "../client";
2
2
  import { TMDBOptions } from "../tmdb";
3
3
  import { Changes } from "../types/common";
4
- import { MovieAlternativeTitles, MovieCredits, MovieDetails, MovieExternalIDs, MovieImages, MovieKeywords, MovieReleaseDates, MovieResultItem, MovieTranslations, MovieVideos, MovieWatchProvider } from "../types/movies";
5
- import { MovieAlternativeTitlesParams, MovieDetailsParams, PaginatedResponse } from "../types/params";
4
+ import { MovieAlternativeTitles, MovieAppendToResponseNamespace, MovieCredits, MovieDetails, MovieDetailsWithAppends, MovieExternalIDs, MovieImages, MovieKeywords, MovieRecommendations, MovieReleaseDates, MovieReviews, MovieSimilar, MovieTranslations, MovieVideos, MovieWatchProvider } from "../types/movies";
5
+ import { MovieAlternativeTitlesParams, MovieChangesParams, MovieCreditsParams, MovieDetailsParams, MovieExternalIDsParams, MovieImagesParams, MovieKeywordsParams, MovieRecommendationsParams, MovieReleaseDatesParams, MovieReviewsParams, MovieSimilarParams, MovieTranslationsParams, MovieVideosParams, MovieWathProvidersParams } from "../types/params";
6
6
  export declare const MOVIE_ENDPOINTS: {
7
7
  MOVIE: string;
8
8
  ALTERNATIVE_TITLES: string;
@@ -18,6 +18,7 @@ export declare const MOVIE_ENDPOINTS: {
18
18
  TRANSLATIONS: string;
19
19
  VIDEOS: string;
20
20
  WATCH_PROVIDERS: string;
21
+ REVIEWS: string;
21
22
  };
22
23
  export declare class MoviesAPI {
23
24
  private client;
@@ -34,7 +35,9 @@ export declare class MoviesAPI {
34
35
  * @returns A promise that resolves to the movie details.
35
36
  * @reference https://developer.themoviedb.org/reference/movie-details
36
37
  */
37
- details(params: MovieDetailsParams): Promise<MovieDetails>;
38
+ details<T extends readonly MovieAppendToResponseNamespace[] = []>(params: MovieDetailsParams & {
39
+ append_to_response?: T[number] | T;
40
+ }): Promise<T extends [] ? MovieDetails : MovieDetailsWithAppends<T>>;
38
41
  /**
39
42
  * Alternative Titles
40
43
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/alternative_titles
@@ -56,7 +59,7 @@ export declare class MoviesAPI {
56
59
  * @returns A promise that resolves to the movie credits.
57
60
  * @reference https://developer.themoviedb.org/reference/movie-credits
58
61
  */
59
- credits(movie_id: number, language?: string): Promise<MovieCredits>;
62
+ credits(params: MovieCreditsParams): Promise<MovieCredits>;
60
63
  /**
61
64
  * External IDs
62
65
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/external_ids
@@ -68,7 +71,7 @@ export declare class MoviesAPI {
68
71
  * @returns A promise that resolves to the movie external IDs.
69
72
  * @reference https://developer.themoviedb.org/reference/movie-external-ids
70
73
  */
71
- external_ids(movie_id: number): Promise<MovieExternalIDs>;
74
+ external_ids(params: MovieExternalIDsParams): Promise<MovieExternalIDs>;
72
75
  /**
73
76
  * Keywords
74
77
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/keywords
@@ -79,7 +82,7 @@ export declare class MoviesAPI {
79
82
  * @returns A promise that resolves to the movie keywords.
80
83
  * @reference https://developer.themoviedb.org/reference/movie-keywords
81
84
  */
82
- keywords(movie_id: number): Promise<MovieKeywords>;
85
+ keywords(params: MovieKeywordsParams): Promise<MovieKeywords>;
83
86
  /**
84
87
  * Changes
85
88
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/changes
@@ -94,20 +97,23 @@ export declare class MoviesAPI {
94
97
  * @returns A promise that resolves to the changes made to the movie.
95
98
  * @reference https://developer.themoviedb.org/reference/movie-changes
96
99
  */
97
- changes(movie_id: number, page?: number, start_date?: string, end_date?: string): Promise<Changes>;
100
+ changes(params: MovieChangesParams): Promise<Changes>;
98
101
  /**
99
102
  * Images
100
103
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/images
101
104
  *
102
105
  * Fetches images related to a specific movie, such as posters and backdrops.
103
106
  * The images are returned in various sizes and formats.
107
+ *
108
+ * If you have a language specified, it will act as a filter on the returned items. You can use the include_image_language param to query additional languages.
109
+ *
104
110
  * @param movie_id - The unique identifier of the movie.
105
111
  * @param language - (Optional) The language code to filter the images by language.
106
112
  * @param include_image_language - (Optional) A comma-separated list of language codes to include images for.
107
113
  * @returns A promise that resolves to a `MovieImages` object containing the movie's images.
108
114
  * @reference https://developer.themoviedb.org/reference/movie-images
109
115
  */
110
- images(movie_id: number, language?: string, include_image_language?: string): Promise<MovieImages>;
116
+ images(params: MovieImagesParams): Promise<MovieImages>;
111
117
  /**
112
118
  * Latest
113
119
  * GET - https://api.themoviedb.org/3/movie/latest
@@ -130,7 +136,7 @@ export declare class MoviesAPI {
130
136
  * @returns A promise that resolves to a paginated response of similar movies.
131
137
  * @reference https://developer.themoviedb.org/reference/movie-recommendations
132
138
  */
133
- recommendations(movie_id: number, page?: number, language?: string): Promise<PaginatedResponse<MovieResultItem>>;
139
+ recommendations(params: MovieRecommendationsParams): Promise<MovieRecommendations>;
134
140
  /**
135
141
  * Release Dates
136
142
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/release_dates
@@ -147,7 +153,19 @@ export declare class MoviesAPI {
147
153
  * @returns A promise that resolves to the release dates for the movie.
148
154
  * @reference https://developer.themoviedb.org/reference/movie-release-dates
149
155
  */
150
- release_dates(movie_id: number): Promise<MovieReleaseDates>;
156
+ release_dates(params: MovieReleaseDatesParams): Promise<MovieReleaseDates>;
157
+ /**
158
+ * Reviews
159
+ * GET - https://api.themoviedb.org/3/movie/{movie_id}/reviews
160
+ *
161
+ * Get the user reviews for a movie.
162
+ * @param movie_id The ID of the movie.
163
+ * @param page Page number of the results to return. Defaults to 1.
164
+ * @param language Language code to filter the results. Default is "en-US".
165
+ * @returns A promise that resolves to a paginated response of movies reviews.
166
+ * @reference https://developer.themoviedb.org/reference/movie-reviews
167
+ */
168
+ reviews(params: MovieReviewsParams): Promise<MovieReviews>;
151
169
  /**
152
170
  * Similar
153
171
  * GET -https://api.themoviedb.org/3/movie/{movie_id}/similar
@@ -161,7 +179,7 @@ export declare class MoviesAPI {
161
179
  * @returns A promise that resolves to a paginated response of similar movies.
162
180
  * @reference https://developer.themoviedb.org/reference/movie-similar
163
181
  */
164
- similar(movie_id: number, language?: string, page?: number): Promise<PaginatedResponse<MovieResultItem>>;
182
+ similar(params: MovieSimilarParams): Promise<MovieSimilar>;
165
183
  /**
166
184
  * Translations
167
185
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/translations
@@ -173,7 +191,7 @@ export declare class MoviesAPI {
173
191
  * @returns A promise that resolves to the translations of the movie.
174
192
  * @reference https://developer.themoviedb.org/reference/movie-translations
175
193
  */
176
- translations(movie_id: number): Promise<MovieTranslations>;
194
+ translations(params: MovieTranslationsParams): Promise<MovieTranslations>;
177
195
  /**
178
196
  * Videos
179
197
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/videos
@@ -183,7 +201,7 @@ export declare class MoviesAPI {
183
201
  * @returns A promise that resolves to a list of videos for the movie.
184
202
  * @reference https://developer.themoviedb.org/reference/movie-videos
185
203
  */
186
- videos(movie_id: number, language?: string): Promise<MovieVideos>;
204
+ videos(params: MovieVideosParams): Promise<MovieVideos>;
187
205
  /**
188
206
  * Watch Providers
189
207
  * GET - https://api.themoviedb.org/3/movie/{movie_id}/watch/providers
@@ -200,5 +218,5 @@ export declare class MoviesAPI {
200
218
  * @returns A promise that resolves to a list of videos for the movie.
201
219
  * @reference https://developer.themoviedb.org/reference/movie-videos
202
220
  */
203
- watch_providers(movie_id: number): Promise<MovieWatchProvider>;
221
+ watch_providers(params: MovieWathProvidersParams): Promise<MovieWatchProvider>;
204
222
  }
@@ -1,4 +1,3 @@
1
- import { mergeParams } from "../utils/params";
2
1
  export const MOVIE_ENDPOINTS = {
3
2
  MOVIE: "/movie",
4
3
  ALTERNATIVE_TITLES: "/alternative_titles",
@@ -14,10 +13,10 @@ export const MOVIE_ENDPOINTS = {
14
13
  TRANSLATIONS: "/translations",
15
14
  VIDEOS: "/videos",
16
15
  WATCH_PROVIDERS: "/watch/providers",
16
+ REVIEWS: "/reviews",
17
17
  // Missing:
18
18
  // ACCOUNT_STATES
19
19
  // LISTS
20
- // REVIEWS
21
20
  // ADD RATING
22
21
  // DELETE RATING
23
22
  };
@@ -40,9 +39,9 @@ export class MoviesAPI {
40
39
  * @reference https://developer.themoviedb.org/reference/movie-details
41
40
  */
42
41
  async details(params) {
43
- const mergedParams = { ...this.defaultOptions, ...params };
44
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${mergedParams.movie_id}`;
45
- return this.client.request(endpoint, mergedParams);
42
+ const { language = this.defaultOptions.language, ...rest } = params;
43
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}`;
44
+ return this.client.request(endpoint, { language, ...rest });
46
45
  }
47
46
  /**
48
47
  * Alternative Titles
@@ -55,9 +54,8 @@ export class MoviesAPI {
55
54
  * @reference https://developer.themoviedb.org/reference/movie-alternative-titles
56
55
  */
57
56
  async alternative_titles(params) {
58
- const mergedParams = mergeParams(this.defaultOptions, params);
59
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${mergedParams.movie_id}${MOVIE_ENDPOINTS.ALTERNATIVE_TITLES}`;
60
- return this.client.request(endpoint, mergedParams);
57
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.ALTERNATIVE_TITLES}`;
58
+ return this.client.request(endpoint, params);
61
59
  }
62
60
  /**
63
61
  * Credits
@@ -69,10 +67,10 @@ export class MoviesAPI {
69
67
  * @returns A promise that resolves to the movie credits.
70
68
  * @reference https://developer.themoviedb.org/reference/movie-credits
71
69
  */
72
- async credits(movie_id, language = "en-US") {
73
- const params = { language };
74
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.CREDITS}`;
75
- return this.client.request(endpoint, params);
70
+ async credits(params) {
71
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.CREDITS}`;
72
+ const { language = this.defaultOptions.language, ...rest } = params;
73
+ return this.client.request(endpoint, { language, ...rest });
76
74
  }
77
75
  /**
78
76
  * External IDs
@@ -85,8 +83,8 @@ export class MoviesAPI {
85
83
  * @returns A promise that resolves to the movie external IDs.
86
84
  * @reference https://developer.themoviedb.org/reference/movie-external-ids
87
85
  */
88
- async external_ids(movie_id) {
89
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.EXTERNAL_IDS}`;
86
+ async external_ids(params) {
87
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.EXTERNAL_IDS}`;
90
88
  return this.client.request(endpoint);
91
89
  }
92
90
  /**
@@ -99,8 +97,8 @@ export class MoviesAPI {
99
97
  * @returns A promise that resolves to the movie keywords.
100
98
  * @reference https://developer.themoviedb.org/reference/movie-keywords
101
99
  */
102
- async keywords(movie_id) {
103
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.KEYWORDS}`;
100
+ async keywords(params) {
101
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.KEYWORDS}`;
104
102
  return this.client.request(endpoint);
105
103
  }
106
104
  /**
@@ -117,9 +115,8 @@ export class MoviesAPI {
117
115
  * @returns A promise that resolves to the changes made to the movie.
118
116
  * @reference https://developer.themoviedb.org/reference/movie-changes
119
117
  */
120
- async changes(movie_id, page, start_date, end_date) {
121
- const params = { page, start_date, end_date };
122
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.CHANGES}`;
118
+ async changes(params) {
119
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.CHANGES}`;
123
120
  return this.client.request(endpoint, params);
124
121
  }
125
122
  /**
@@ -128,16 +125,19 @@ export class MoviesAPI {
128
125
  *
129
126
  * Fetches images related to a specific movie, such as posters and backdrops.
130
127
  * The images are returned in various sizes and formats.
128
+ *
129
+ * If you have a language specified, it will act as a filter on the returned items. You can use the include_image_language param to query additional languages.
130
+ *
131
131
  * @param movie_id - The unique identifier of the movie.
132
132
  * @param language - (Optional) The language code to filter the images by language.
133
133
  * @param include_image_language - (Optional) A comma-separated list of language codes to include images for.
134
134
  * @returns A promise that resolves to a `MovieImages` object containing the movie's images.
135
135
  * @reference https://developer.themoviedb.org/reference/movie-images
136
136
  */
137
- async images(movie_id, language, include_image_language) {
138
- const params = { language, include_image_language };
139
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.IMAGES}`;
140
- return this.client.request(endpoint, params);
137
+ async images(params) {
138
+ const { language = this.defaultOptions.language, ...rest } = params;
139
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.IMAGES}`;
140
+ return this.client.request(endpoint, { language, ...rest });
141
141
  }
142
142
  /**
143
143
  * Latest
@@ -164,10 +164,10 @@ export class MoviesAPI {
164
164
  * @returns A promise that resolves to a paginated response of similar movies.
165
165
  * @reference https://developer.themoviedb.org/reference/movie-recommendations
166
166
  */
167
- async recommendations(movie_id, page, language) {
168
- const params = { page, language };
169
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.RECOMMENDATIONS}`;
170
- return this.client.request(endpoint, params);
167
+ async recommendations(params) {
168
+ const { language = this.defaultOptions.language, ...rest } = params;
169
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.RECOMMENDATIONS}`;
170
+ return this.client.request(endpoint, { language, ...rest });
171
171
  }
172
172
  /**
173
173
  * Release Dates
@@ -185,10 +185,26 @@ export class MoviesAPI {
185
185
  * @returns A promise that resolves to the release dates for the movie.
186
186
  * @reference https://developer.themoviedb.org/reference/movie-release-dates
187
187
  */
188
- async release_dates(movie_id) {
189
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.RELEASE_DATES}`;
188
+ async release_dates(params) {
189
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.RELEASE_DATES}`;
190
190
  return this.client.request(endpoint);
191
191
  }
192
+ /**
193
+ * Reviews
194
+ * GET - https://api.themoviedb.org/3/movie/{movie_id}/reviews
195
+ *
196
+ * Get the user reviews for a movie.
197
+ * @param movie_id The ID of the movie.
198
+ * @param page Page number of the results to return. Defaults to 1.
199
+ * @param language Language code to filter the results. Default is "en-US".
200
+ * @returns A promise that resolves to a paginated response of movies reviews.
201
+ * @reference https://developer.themoviedb.org/reference/movie-reviews
202
+ */
203
+ async reviews(params) {
204
+ const { language = this.defaultOptions.language, ...rest } = params;
205
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.REVIEWS}`;
206
+ return this.client.request(endpoint, { language, ...rest });
207
+ }
192
208
  /**
193
209
  * Similar
194
210
  * GET -https://api.themoviedb.org/3/movie/{movie_id}/similar
@@ -202,10 +218,10 @@ export class MoviesAPI {
202
218
  * @returns A promise that resolves to a paginated response of similar movies.
203
219
  * @reference https://developer.themoviedb.org/reference/movie-similar
204
220
  */
205
- async similar(movie_id, language, page) {
206
- const params = { page, language };
207
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.SIMILAR}`;
208
- return this.client.request(endpoint, params);
221
+ async similar(params) {
222
+ const { language = this.defaultOptions.language, ...rest } = params;
223
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.SIMILAR}`;
224
+ return this.client.request(endpoint, { language, ...rest });
209
225
  }
210
226
  /**
211
227
  * Translations
@@ -218,8 +234,8 @@ export class MoviesAPI {
218
234
  * @returns A promise that resolves to the translations of the movie.
219
235
  * @reference https://developer.themoviedb.org/reference/movie-translations
220
236
  */
221
- async translations(movie_id) {
222
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.TRANSLATIONS}`;
237
+ async translations(params) {
238
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.TRANSLATIONS}`;
223
239
  return this.client.request(endpoint);
224
240
  }
225
241
  /**
@@ -231,10 +247,10 @@ export class MoviesAPI {
231
247
  * @returns A promise that resolves to a list of videos for the movie.
232
248
  * @reference https://developer.themoviedb.org/reference/movie-videos
233
249
  */
234
- async videos(movie_id, language) {
235
- const params = { language };
236
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.VIDEOS}`;
237
- return this.client.request(endpoint, params);
250
+ async videos(params) {
251
+ const { language = this.defaultOptions.language, ...rest } = params;
252
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.VIDEOS}`;
253
+ return this.client.request(endpoint, { language, ...rest });
238
254
  }
239
255
  /**
240
256
  * Watch Providers
@@ -252,8 +268,8 @@ export class MoviesAPI {
252
268
  * @returns A promise that resolves to a list of videos for the movie.
253
269
  * @reference https://developer.themoviedb.org/reference/movie-videos
254
270
  */
255
- async watch_providers(movie_id) {
256
- const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${movie_id}${MOVIE_ENDPOINTS.WATCH_PROVIDERS}`;
271
+ async watch_providers(params) {
272
+ const endpoint = `${MOVIE_ENDPOINTS.MOVIE}/${params.movie_id}${MOVIE_ENDPOINTS.WATCH_PROVIDERS}`;
257
273
  return this.client.request(endpoint);
258
274
  }
259
275
  }
@@ -9,6 +9,7 @@ export declare class SearchAPI {
9
9
  private client;
10
10
  private defaultOptions;
11
11
  constructor(client: ApiClient, defaultOptions?: TMDBOptions);
12
+ withDefaults(params: SearchMoviesParams): SearchMoviesParams;
12
13
  /**
13
14
  * Search
14
15
  * GET - https://api.themoviedb.org/3/search/movie
@@ -8,6 +8,10 @@ export class SearchAPI {
8
8
  this.client = client;
9
9
  this.defaultOptions = defaultOptions;
10
10
  }
11
+ withDefaults(params) {
12
+ const { language = this.defaultOptions.language, region = this.defaultOptions.region, ...rest } = params;
13
+ return { language, region, ...rest };
14
+ }
11
15
  /**
12
16
  * Search
13
17
  * GET - https://api.themoviedb.org/3/search/movie
@@ -24,8 +28,6 @@ export class SearchAPI {
24
28
  */
25
29
  async movies(params) {
26
30
  const endpoint = `${SEARCH_ENDPOINTS.MOVIE}`;
27
- // Merge defaultOptions with params, giving precedence to params
28
- const mergedParams = { ...this.defaultOptions, ...params };
29
- return this.client.request(endpoint, mergedParams);
31
+ return this.client.request(endpoint, this.withDefaults(params));
30
32
  }
31
33
  }
@@ -3,7 +3,7 @@ import { TMDB } from "../../tmdb";
3
3
  const token = process.env.TMDB_ACCESS_TOKEN;
4
4
  if (!token)
5
5
  throw new Error("TMDB_ACCESS_TOKEN is not set, plaase set it in your enviroment variables.");
6
- const tmdb = new TMDB(token, { language: "it-IT", region: "IT", country: "IT" });
6
+ const tmdb = new TMDB(token, { language: "it", region: "IT" });
7
7
  describe("Movie List (integration)", () => {
8
8
  it("(NOW PLAYING) should get now playing movies", async () => {
9
9
  const now_playing = await tmdb.movie_lists.now_playing();
@@ -25,6 +25,15 @@ describe("Movies (integration)", () => {
25
25
  expect(error).toBeInstanceOf(TMDBError);
26
26
  }
27
27
  });
28
+ it("(MOVIE DETAILS) should get movie details with appended response", async () => {
29
+ const movie_id = 550; // Fight Club
30
+ const movie = await tmdb.movies.details({ movie_id, append_to_response: ["reviews"] });
31
+ expect(movie).toBeDefined();
32
+ expect(movie.id).toBe(movie_id);
33
+ expect(movie.title).toBe("Fight Club");
34
+ expect(movie.reviews.results).toBeDefined();
35
+ expect(movie.reviews.results.length).toBeGreaterThanOrEqual(0);
36
+ });
28
37
  it("(MOVIE ALTERNATIVE TITLES) should get movie alternative titles", async () => {
29
38
  const movie_id = 550; // Fight Club
30
39
  const movie_titles = await tmdb.movies.alternative_titles({ movie_id });
@@ -34,7 +43,7 @@ describe("Movies (integration)", () => {
34
43
  });
35
44
  it("(MOVIE CREDITS) should get movie credits", async () => {
36
45
  const movie_id = 550; // Fight Club
37
- const credits = await tmdb.movies.credits(movie_id);
46
+ const credits = await tmdb.movies.credits({ movie_id });
38
47
  expect(credits).toBeDefined();
39
48
  expect(credits.id).toBe(movie_id);
40
49
  expect(credits.cast.length).toBeGreaterThan(0);
@@ -43,14 +52,14 @@ describe("Movies (integration)", () => {
43
52
  });
44
53
  it("(MOVIE EXTERNAL IDS) should get movie external IDs", async () => {
45
54
  const movie_id = 550; // Fight Club
46
- const external_ids = await tmdb.movies.external_ids(movie_id);
55
+ const external_ids = await tmdb.movies.external_ids({ movie_id });
47
56
  expect(external_ids).toBeDefined();
48
57
  expect(external_ids.id).toBe(movie_id);
49
58
  expect(external_ids.imdb_id).toBe("tt0137523");
50
59
  });
51
60
  it("(MOVIE KEYWORDS) should get movie keywords", async () => {
52
61
  const movie_id = 550; // Fight Club
53
- const keywords = await tmdb.movies.keywords(movie_id);
62
+ const keywords = await tmdb.movies.keywords({ movie_id });
54
63
  expect(keywords).toBeDefined();
55
64
  expect(keywords.id).toBe(movie_id);
56
65
  expect(keywords.keywords.length).toBeGreaterThan(0);
@@ -59,7 +68,7 @@ describe("Movies (integration)", () => {
59
68
  const movie_id = 550; // Fight Club
60
69
  const start_date = "2024-12-20";
61
70
  const end_date = "2024-12-24";
62
- const changes = await tmdb.movies.changes(movie_id, 1, start_date, end_date);
71
+ const changes = await tmdb.movies.changes({ movie_id, start_date, end_date });
63
72
  expect(changes).toBeDefined();
64
73
  expect(changes.changes).toBeDefined();
65
74
  expect(changes.changes[0].key).toBe("images");
@@ -67,7 +76,7 @@ describe("Movies (integration)", () => {
67
76
  });
68
77
  it("(MOVIE IMAGES) should get movie images", async () => {
69
78
  const movie_id = 550; // Fight Club
70
- const images = await tmdb.movies.images(movie_id);
79
+ const images = await tmdb.movies.images({ movie_id });
71
80
  expect(images).toBeDefined();
72
81
  expect(images.id).toBe(movie_id);
73
82
  expect(images.backdrops.length).toBeGreaterThan(0);
@@ -75,10 +84,10 @@ describe("Movies (integration)", () => {
75
84
  });
76
85
  it("(MOVIE IMAGES) should get movie images for a specific language", async () => {
77
86
  const movie_id = 550; // Fight Club
78
- const images = await tmdb.movies.images(movie_id, "en");
87
+ const images = await tmdb.movies.images({ movie_id, language: "de" });
79
88
  expect(images).toBeDefined();
80
89
  expect(images.id).toBe(movie_id);
81
- expect(images.backdrops.length).toBeGreaterThan(0);
90
+ expect(images.backdrops.length).toBeGreaterThanOrEqual(0);
82
91
  expect(images.posters.length).toBeGreaterThan(0);
83
92
  });
84
93
  it("(MOVIE LATEST) should get the latest movie details", async () => {
@@ -89,7 +98,7 @@ describe("Movies (integration)", () => {
89
98
  });
90
99
  it("(MOVIE RECOMMENDATIONS) should get movie recommendations", async () => {
91
100
  const movie_id = 550; // Fight Club
92
- const recommendations = await tmdb.movies.recommendations(movie_id);
101
+ const recommendations = await tmdb.movies.recommendations({ movie_id });
93
102
  expect(recommendations).toBeDefined();
94
103
  expect(recommendations.results.length).toBeGreaterThan(0);
95
104
  expect(recommendations.results[0].id).toBeDefined();
@@ -99,16 +108,26 @@ describe("Movies (integration)", () => {
99
108
  });
100
109
  it("(MOVIE RELEASE DATES) should get movie release dates", async () => {
101
110
  const movie_id = 550; // Fight Club
102
- const release_dates = await tmdb.movies.release_dates(movie_id);
111
+ const release_dates = await tmdb.movies.release_dates({ movie_id });
103
112
  expect(release_dates).toBeDefined();
104
113
  expect(release_dates.id).toBe(movie_id);
105
114
  expect(release_dates.results.length).toBeGreaterThan(0);
106
115
  expect(release_dates.results[0].iso_3166_1).toBeDefined();
107
116
  expect(release_dates.results[0].release_dates.length).toBeGreaterThan(0);
108
117
  });
118
+ it("(MOVIE REVIEWS) should get movie reviews", async () => {
119
+ const movie_id = 550; // Fight Club
120
+ const reviews = await tmdb.movies.reviews({ movie_id });
121
+ expect(reviews).toBeDefined();
122
+ expect(reviews.results.length).toBeGreaterThan(0);
123
+ expect(reviews.results[0].id).toBeDefined();
124
+ expect(reviews.page).toBe(1);
125
+ expect(reviews.total_results).toBeGreaterThan(0);
126
+ expect(reviews.total_pages).toBeGreaterThan(0);
127
+ });
109
128
  it("(MOVIE SIMILAR) should get similar movies", async () => {
110
129
  const movie_id = 550;
111
- const similar = await tmdb.movies.similar(movie_id);
130
+ const similar = await tmdb.movies.similar({ movie_id });
112
131
  expect(similar).toBeDefined();
113
132
  expect(similar.results.length).toBeGreaterThan(0);
114
133
  expect(similar.results[0].id).toBeDefined();
@@ -118,7 +137,7 @@ describe("Movies (integration)", () => {
118
137
  });
119
138
  it("(MOVIE TRANSLATIONS) should get translations for a movie", async () => {
120
139
  const movie_id = 550;
121
- const translations = await tmdb.movies.translations(movie_id);
140
+ const translations = await tmdb.movies.translations({ movie_id });
122
141
  expect(translations).toBeDefined();
123
142
  expect(translations.id).toBe(movie_id);
124
143
  expect(translations.translations).toBeDefined();
@@ -127,7 +146,7 @@ describe("Movies (integration)", () => {
127
146
  });
128
147
  it("(MOVIE VIDEOS) should get videos for a movie", async () => {
129
148
  const movie_id = 550;
130
- const videos = await tmdb.movies.videos(movie_id);
149
+ const videos = await tmdb.movies.videos({ movie_id });
131
150
  expect(videos).toBeDefined();
132
151
  expect(videos.id).toBe(movie_id);
133
152
  expect(videos.results).toBeDefined();
@@ -136,7 +155,7 @@ describe("Movies (integration)", () => {
136
155
  });
137
156
  it("(MOVIE WATCH PROVIDERS) should get watch providers for a movie", async () => {
138
157
  const movie_id = 550;
139
- const watch_providers = await tmdb.movies.watch_providers(movie_id);
158
+ const watch_providers = await tmdb.movies.watch_providers({ movie_id });
140
159
  expect(watch_providers).toBeDefined();
141
160
  expect(watch_providers.id).toBe(movie_id);
142
161
  expect(watch_providers.results).toBeDefined();
@@ -13,9 +13,9 @@ describe("MoviesAPI", () => {
13
13
  });
14
14
  it("should call client.request with the correct parameters", async () => {
15
15
  const movie_id = 550;
16
- const append_to_response = ["credits", "images"];
17
16
  const language = "en";
18
- await moviesAPI.details({ movie_id, append_to_response, language });
17
+ const append_to_response = ["credits", "images"];
18
+ await moviesAPI.details({ movie_id, language, append_to_response });
19
19
  expect(clientMock.request).toHaveBeenCalledOnce();
20
20
  expect(clientMock.request).toHaveBeenCalledWith("/movie/550", {
21
21
  movie_id,
@@ -13,7 +13,7 @@ describe("Search (integration)", () => {
13
13
  expect(movies.results[0].title).toBe("Fight Club");
14
14
  });
15
15
  it("(SEARCH MOVIE) should search for a movie with default options", async () => {
16
- const tmdb = new TMDB(token, { language: "it-IT", region: "IT" });
16
+ const tmdb = new TMDB(token, { language: "it", region: "IT" });
17
17
  const movies = await tmdb.search.movies({ query: "Fight Club" });
18
18
  expect(movies.page).toBe(1);
19
19
  expect(movies.total_results).toBeGreaterThan(0);
package/dist/tmdb.d.ts CHANGED
@@ -1,10 +1,21 @@
1
1
  import { MovieListsAPI } from "./endpoints/movie_lists";
2
2
  import { MoviesAPI } from "./endpoints/movies";
3
3
  import { SearchAPI } from "./endpoints/search";
4
+ import { CountryISO3166_1 } from "./types/countries";
5
+ import { LanguageISO6391 } from "./types/lang";
4
6
  export type TMDBOptions = {
5
- language?: string;
6
- region?: string;
7
- country?: string;
7
+ /**
8
+ * The language to use for requests (ISO 639-1 code)
9
+ * This provides localization and translated data.
10
+ */
11
+ language?: LanguageISO6391;
12
+ /**
13
+ * Region codes follow ISO 3166-1 (e.g. 'US', 'IT', 'JP') and are used to localize results.
14
+ * They affect release dates, age certifications, watch providers, and filtered movie lists.
15
+ * Example: 'region=IT' returns Italian-specific results for now playing, watch providers, etc.
16
+ * If not set, TMDB may fall back to a default or global data.
17
+ */
18
+ region?: CountryISO3166_1;
8
19
  };
9
20
  export declare class TMDB {
10
21
  private client;
@@ -18,9 +29,4 @@ export declare class TMDB {
18
29
  * @param options Optional default options (e.g., language) for all requests.
19
30
  */
20
31
  constructor(accessToken: string, options?: TMDBOptions);
21
- /**
22
- * Helper to merge default options with method-specific params.
23
- * Method-level params override defaults.
24
- */
25
- withDefaults<T extends object>(params?: T): T & TMDBOptions;
26
32
  }
package/dist/tmdb.js CHANGED
@@ -21,15 +21,8 @@ export class TMDB {
21
21
  throw new Error(Errors.NO_ACCESS_TOKEN);
22
22
  this.options = options;
23
23
  this.client = new ApiClient(accessToken);
24
- this.movies = new MoviesAPI(this.client, options);
25
- this.movie_lists = new MovieListsAPI(this.client, options);
26
- this.search = new SearchAPI(this.client, options);
27
- }
28
- /**
29
- * Helper to merge default options with method-specific params.
30
- * Method-level params override defaults.
31
- */
32
- withDefaults(params) {
33
- return { ...this.options, ...params };
24
+ this.movies = new MoviesAPI(this.client, this.options);
25
+ this.movie_lists = new MovieListsAPI(this.client, this.options);
26
+ this.search = new SearchAPI(this.client, this.options);
34
27
  }
35
28
  }
@@ -1,5 +1,6 @@
1
- import { Cast, Collection, Crew, Genre, ImageItem, Keyword, ProductionCompany, ProductionCountry, SpokenLanguage, VideoItem } from "./common";
1
+ import { Cast, Changes, Collection, Crew, Genre, ImageItem, Keyword, ProductionCompany, ProductionCountry, SpokenLanguage, VideoItem } from "./common";
2
2
  import { ReleaseType } from "./enums";
3
+ import { PaginatedResponse } from "./params";
3
4
  import { ISO3166Country } from "./utility";
4
5
  export type MovieDetails = {
5
6
  adult: boolean;
@@ -55,6 +56,7 @@ export type MovieAlternativeTitle = {
55
56
  iso_3166_1: string;
56
57
  type: string;
57
58
  };
59
+ export type MovieChanges = Changes;
58
60
  export type MovieCredits = {
59
61
  id: number;
60
62
  cast: Cast[];
@@ -77,6 +79,8 @@ export type MovieImages = {
77
79
  logos: ImageItem[];
78
80
  posters: ImageItem[];
79
81
  };
82
+ export type MovieRecommendations = PaginatedResponse<MovieResultItem>;
83
+ export type MovieSimilar = PaginatedResponse<MovieResultItem>;
80
84
  export type MovieReleaseDates = {
81
85
  id: number;
82
86
  results: MovieReleaseDateResult[];
@@ -93,6 +97,22 @@ export type MovieReleaseDate = {
93
97
  note: string;
94
98
  descriptors: any[];
95
99
  };
100
+ export type MovieReviews = PaginatedResponse<MovieReview>;
101
+ export type MovieReview = {
102
+ author: string;
103
+ author_details: MovieReviewAuthorDetails;
104
+ content: string;
105
+ created_at: string;
106
+ id: string;
107
+ updated_at: string;
108
+ url: string;
109
+ };
110
+ export type MovieReviewAuthorDetails = {
111
+ name: string;
112
+ username: string;
113
+ avatar_path?: string;
114
+ rating?: number;
115
+ };
96
116
  export type MovieTranslations = {
97
117
  id: number;
98
118
  translations: MovieTranslationResults[];
@@ -130,3 +150,22 @@ export type WatchProviderItem = {
130
150
  provider_name: string;
131
151
  display_priority: number;
132
152
  };
153
+ /** Append To Response */
154
+ export type MovieAppendToResponseNamespace = "alternative_titles" | "changes" | "credits" | "external_ids" | "images" | "keywords" | "recommendations" | "release_dates" | "reviews" | "similar" | "translations" | "videos";
155
+ export type MovieAppendableMap = {
156
+ alternative_titles: MovieAlternativeTitles;
157
+ changes: MovieChanges;
158
+ credits: MovieCredits;
159
+ external_ids: MovieExternalIDs;
160
+ images: MovieImages;
161
+ keywords: MovieKeywords;
162
+ recommendations: MovieRecommendations;
163
+ release_dates: MovieReleaseDates;
164
+ reviews: MovieReviews;
165
+ similar: MovieSimilar;
166
+ translations: MovieTranslations;
167
+ videos: MovieVideos;
168
+ };
169
+ export type MovieDetailsWithAppends<T extends readonly MovieAppendToResponseNamespace[]> = MovieDetails & {
170
+ [K in T[number]]: MovieAppendableMap[K];
171
+ };
@@ -1,5 +1,6 @@
1
1
  import { CountryISO3166_1 } from "./countries";
2
2
  import { LanguageISO6391 } from "./lang";
3
+ import { MovieAppendToResponseNamespace } from "./movies";
3
4
  export type PaginatedResponse<T> = {
4
5
  page: number;
5
6
  total_pages: number;
@@ -22,10 +23,40 @@ export type MovieListParams = {
22
23
  };
23
24
  export type MovieDetailsParams = {
24
25
  movie_id: number;
25
- append_to_response?: string[];
26
+ append_to_response?: MovieAppendToResponseNamespace[];
26
27
  language?: LanguageISO6391;
27
28
  };
28
29
  export type MovieAlternativeTitlesParams = {
29
30
  movie_id: number;
30
31
  country?: CountryISO3166_1;
31
32
  };
33
+ export type MovieCreditsParams = {
34
+ movie_id: number;
35
+ language?: LanguageISO6391;
36
+ };
37
+ export type MovieKeywordsParams = {
38
+ movie_id: number;
39
+ };
40
+ export type MovieExternalIDsParams = MovieKeywordsParams;
41
+ export type MovieReleaseDatesParams = MovieKeywordsParams;
42
+ export type MovieTranslationsParams = MovieKeywordsParams;
43
+ export type MovieWathProvidersParams = MovieKeywordsParams;
44
+ export type MovieChangesParams = {
45
+ movie_id: number;
46
+ page?: number;
47
+ start_date?: string;
48
+ end_date?: string;
49
+ };
50
+ export type MovieImagesParams = {
51
+ movie_id: number;
52
+ language?: LanguageISO6391;
53
+ include_image_language?: LanguageISO6391;
54
+ };
55
+ export type MovieRecommendationsParams = {
56
+ movie_id: number;
57
+ page?: number;
58
+ language?: LanguageISO6391;
59
+ };
60
+ export type MovieSimilarParams = MovieRecommendationsParams;
61
+ export type MovieVideosParams = MovieCreditsParams;
62
+ export type MovieReviewsParams = MovieRecommendationsParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lorenzopant/tmdb",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "A completely type-safe The Movie Database (TMDB) API wrapper for typescript applications.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",