@api-wrappers/tmdb-wrapper 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tommy Danks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,395 @@
1
+ <h1 align="center">
2
+ TMDB Api Wrapper
3
+ </h1>
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@api-wrappers/tmdb-wrapper"><img alt="npm version" src="https://img.shields.io/npm/v/@api-wrappers/tmdb-wrapper"></a>
7
+ <a href="https://github.com/api-wrappers/tmdb-wrapper/blob/master/LICENSE"><img alt="license" src="https://img.shields.io/npm/l/@api-wrappers/tmdb-wrapper"></a>
8
+ <a href="https://github.com/api-wrappers/tmdb-wrapper"><img alt="GitHub stars" src="https://img.shields.io/github/stars/api-wrappers/tmdb-wrapper?style=social"></a>
9
+ </p>
10
+
11
+ <br />
12
+
13
+ <p align="center">
14
+ <b>A powerful and easy-to-use TypeScript wrapper for The Movie Database (TMDb) API</b>
15
+ </p>
16
+
17
+ The TMDB Api Wrapper simplifies the process of making API requests to The Movie Database (TMDb), a comprehensive database for movies and TV shows. It encapsulates functionality related to various API endpoints, such as account, certifications, changes, collections, configuration, credits, discover, find, genres, keywords, movies, people, reviews, search, trending, TV episodes, TV seasons, TV shows, companies, networks, and watch providers. With this wrapper, developers can quickly integrate TMDB functionality into their TypeScript projects.
18
+
19
+ ## Table of Contents
20
+
21
+ - [Installation](#installation)
22
+ - [Usage](#usage)
23
+ - [Authentication](#authentication)
24
+ - [Functionality](#functionality)
25
+ - [Movies](#movies)
26
+ - [TV Shows](#tv-shows)
27
+ - [People](#people)
28
+ - [Companies](#companies)
29
+ - [Networks](#networks)
30
+ - [Watch Providers](#watch-providers)
31
+ - [Other Endpoints](#other-endpoints)
32
+ - [Image Handling](#image-handling)
33
+ - [Examples](#examples)
34
+ - [Troubleshooting](#troubleshooting)
35
+ - [API Reference](#api-reference)
36
+ - [Contributing](#contributing)
37
+ - [License](#license)
38
+
39
+ ## Installation
40
+
41
+ To install the TMDB TypeScript Wrapper, follow these steps:
42
+
43
+ 1. Run the following command in your project directory:
44
+
45
+ ```typescript
46
+ // npm
47
+ npm install @api-wrappers/tmdb-wrapper
48
+ // yarn
49
+ yarn add @api-wrappers/tmdb-wrapper
50
+ // pnpm
51
+ pnpm i @api-wrappers/tmdb-wrapper
52
+ // bun
53
+ bun add @api-wrappers/tmdb-wrapper
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ To use the TMDB TypeScript API Wrapper in your TypeScript project, import the necessary classes and functions:
59
+
60
+ ```typescript
61
+ import { TMDB } from '@api-wrappers/tmdb-wrapper';
62
+ ```
63
+
64
+ Then, create an instance of the TMDB class, optionally providing an access token. Access tokens can be obtained from [TMDb API Settings](https://www.themoviedb.org/settings/api) under read access token.
65
+
66
+ ```typescript
67
+ const tmdb = new TMDB('YOUR_ACCESS_TOKEN');
68
+ ```
69
+
70
+ You can now use the `tmdb` object to access various functionalities of the TMDB API. The wrapper provides access to all major TMDB API endpoints including Movies, TV Shows, People, Companies, Networks, and Watch Providers.
71
+
72
+ ## Authentication
73
+
74
+ To use the TMDB API, you need to obtain an API key from [TMDb API Settings](https://www.themoviedb.org/settings/api). The wrapper supports both API key authentication and read access token authentication.
75
+
76
+ ```typescript
77
+ // Using API key
78
+ const tmdb = new TMDB({ apiKey: 'YOUR_API_KEY' });
79
+
80
+ // Using read access token (recommended)
81
+ const tmdb = new TMDB('YOUR_ACCESS_TOKEN');
82
+ ```
83
+
84
+ ## Functionality
85
+
86
+ The TMDB Api Wrapper provides access to the following endpoints:
87
+
88
+ ### Movies
89
+
90
+ Access comprehensive information about movies, including details, credits, reviews, and more.
91
+
92
+ ```typescript
93
+ // Get popular movies
94
+ const popularMovies = await tmdb.movies.getPopular();
95
+
96
+ // Get movie details
97
+ const movieDetails = await tmdb.movies.getDetails(550); // Fight Club
98
+
99
+ // Get movie credits
100
+ const movieCredits = await tmdb.movies.getCredits(550);
101
+ ```
102
+
103
+ ### TV Shows
104
+
105
+ Retrieve information about TV shows, seasons, and episodes.
106
+
107
+ ```typescript
108
+ // Get popular TV shows
109
+ const popularShows = await tmdb.tvShows.getPopular();
110
+
111
+ // Get TV show details
112
+ const showDetails = await tmdb.tvShows.getDetails(1396); // Breaking Bad
113
+
114
+ // Get season details
115
+ const seasonDetails = await tmdb.tvSeasons.getDetails(1396, 1);
116
+
117
+ // Get episode details
118
+ const episodeDetails = await tmdb.tvEpisodes.getDetails(1396, 1, 1);
119
+ ```
120
+
121
+ ### People
122
+
123
+ Access information about actors, directors, and other people involved in movies and TV shows.
124
+
125
+ ```typescript
126
+ // Get popular people
127
+ const popularPeople = await tmdb.people.getPopular();
128
+
129
+ // Get person details
130
+ const personDetails = await tmdb.people.getDetails(287); // Brad Pitt
131
+
132
+ // Get person movie credits
133
+ const personMovieCredits = await tmdb.people.getMovieCredits(287);
134
+ ```
135
+
136
+ ### Companies
137
+
138
+ Retrieve information about production companies.
139
+
140
+ ```typescript
141
+ // Get company details
142
+ const companyDetails = await tmdb.companies.getDetails(1); // Lucasfilm
143
+
144
+ // Get company movies
145
+ const companyMovies = await tmdb.companies.getMovies(1);
146
+ ```
147
+
148
+ ### Networks
149
+
150
+ Access information about TV networks.
151
+
152
+ ```typescript
153
+ // Get network details
154
+ const networkDetails = await tmdb.networks.getDetails(213); // Netflix
155
+
156
+ // Get alternative names
157
+ const alternativeNames = await tmdb.networks.getAlternativeNames(213);
158
+ ```
159
+
160
+ ### Watch Providers
161
+
162
+ Retrieve information about streaming platforms and availability.
163
+
164
+ ```typescript
165
+ // Get available regions
166
+ const regions = await tmdb.watchProviders.getAvailableRegions();
167
+
168
+ // Get movie providers
169
+ const movieProviders = await tmdb.watchProviders.getMovieProviders();
170
+
171
+ // Get TV providers
172
+ const tvProviders = await tmdb.watchProviders.getTvProviders();
173
+ ```
174
+
175
+ ### Other Endpoints
176
+
177
+ The wrapper also provides access to these additional endpoints:
178
+
179
+ - **Account**: Manage account details and settings
180
+ - **Certifications**: Retrieve certification information for movies and TV shows
181
+ - **Changes**: Get information about changes to the database
182
+ - **Collections**: Access information about movie collections
183
+ - **Configuration**: Retrieve configuration information for the API
184
+ - **Credits**: Get credits information for movies and TV shows
185
+ - **Discover**: Discover movies and TV shows based on various criteria
186
+ - **Find**: Find movies and TV shows by external IDs
187
+ - **Genres**: Retrieve information about movie and TV show genres
188
+ - **Keywords**: Access information about movie keywords
189
+ - **Reviews**: Get reviews for movies and TV shows
190
+ - **Search**: Search for movies, TV shows, and people
191
+ - **Trending**: Get trending movies and TV shows
192
+
193
+ ## Image Handling
194
+
195
+ ## Image Handling
196
+
197
+ The wrapper includes utilities to reliably construct TMDB image URLs, plus a convenience helper for TMDB `Image` objects.
198
+
199
+ ```typescript
200
+ import {
201
+ formImage,
202
+ getFullImagePath,
203
+ ImageSizes,
204
+ ImageFormats,
205
+ } from "@api-wrappers/tmdb-wrapper";
206
+ ```
207
+
208
+ ### `getFullImagePath(...)`
209
+
210
+ ```typescript
211
+ getFullImagePath(
212
+ baseUrl: string, // e.g. "https://image.tmdb.org/t/p/"
213
+ fileSize: string, // e.g. ImageSizes.W500 or "w780"
214
+ imagePath: string, // e.g. "/abc123" or "/abc123.jpg"
215
+ format?: string // optional: ImageFormats.JPG / PNG / SVG
216
+ ): string
217
+ ```
218
+
219
+ Notes:
220
+ - `imagePath` can be with or without a leading `/` (both work).
221
+ - If `imagePath` is already an absolute URL (`https://...`), it’s returned unchanged.
222
+ - If you provide `format`, the extension is appended/replaced safely.
223
+ - If you omit `format`, the original path is preserved (no forced default extension).
224
+
225
+ ### `formImage(image, fileSize, format?)`
226
+
227
+ `formImage` is a small helper that reads `file_path` from a TMDB `Image` object and returns a ready-to-use URL. If the image object doesn’t include a `file_path`, it returns `undefined`.
228
+
229
+ ```typescript
230
+ formImage(
231
+ image: Image,
232
+ fileSize: ImageSizes,
233
+ format?: ImageFormats
234
+ ): string | undefined
235
+ ```
236
+
237
+ ### Examples
238
+
239
+ Poster path without extension (add one via `format`):
240
+
241
+ ```typescript
242
+ const posterUrl = getFullImagePath(
243
+ "https://image.tmdb.org/t/p/",
244
+ ImageSizes.W500,
245
+ "/wwemzKWzjKYJFfCeiB57q3r4Bcm",
246
+ ImageFormats.JPG,
247
+ );
248
+ // https://image.tmdb.org/t/p/w500/wwemzKWzjKYJFfCeiB57q3r4Bcm.jpg
249
+ ```
250
+
251
+ Profile path that already includes an extension (no need to pass `format`):
252
+
253
+ ```typescript
254
+ const profileUrl = getFullImagePath(
255
+ "https://image.tmdb.org/t/p/",
256
+ ImageSizes.W185,
257
+ "/5XBzD5WuTyVQZeS4VI25z2moMeY.jpg",
258
+ );
259
+ // https://image.tmdb.org/t/p/w185/5XBzD5WuTyVQZeS4VI25z2moMeY.jpg
260
+ ```
261
+
262
+ Using `formImage` with a TMDB response image object:
263
+
264
+ ```typescript
265
+ const images = await tmdb.movies.getImages(550);
266
+ const poster = images.posters[0];
267
+
268
+ const posterUrl = formImage(poster, ImageSizes.W500);
269
+ // e.g. https://image.tmdb.org/t/p/w500/xxxxx.jpg
270
+ ```
271
+
272
+ Override the output extension (append/replace) with `format`:
273
+
274
+ ```typescript
275
+ const posterPngUrl = formImage(poster, ImageSizes.W500, ImageFormats.PNG);
276
+ ```
277
+
278
+ ### Sizes & formats
279
+
280
+ This package exports common presets:
281
+
282
+ - **Sizes**: `ImageSizes.ORIGINAL`, `W500`, `W300`, `W185`, `W92`, `H632`
283
+ - **Formats**: `ImageFormats.JPG`, `PNG`, `SVG`
284
+
285
+ TMDB can support additional sizes depending on their configuration; you can also pass any valid TMDB size string directly (e.g. `"w780"`, `"w1280"`).
286
+
287
+ ### Searching for Content
288
+
289
+ ```typescript
290
+ // Search for movies
291
+ const movieResults = await tmdb.search.searchMovies('Inception');
292
+
293
+ // Search for TV shows
294
+ const tvResults = await tmdb.search.searchTvShows('Breaking Bad');
295
+
296
+ // Search for people
297
+ const peopleResults = await tmdb.search.searchPeople('Brad Pitt');
298
+
299
+ // Multi-search (movies, TV shows, and people)
300
+ const multiResults = await tmdb.search.searchMulti('Marvel');
301
+ ```
302
+
303
+ ### Getting Trending Content
304
+
305
+ ```typescript
306
+ // Get trending movies (day)
307
+ const trendingMoviesDay = await tmdb.trending.getTrendingMovies('day');
308
+
309
+ // Get trending TV shows (week)
310
+ const trendingTvWeek = await tmdb.trending.getTrendingTvShows('week');
311
+
312
+ // Get trending people (day)
313
+ const trendingPeopleDay = await tmdb.trending.getTrendingPeople('day');
314
+
315
+ // Get all trending content (week)
316
+ const trendingAllWeek = await tmdb.trending.getTrendingAll('week');
317
+ ```
318
+
319
+ ### Using Discover
320
+
321
+ ```typescript
322
+ // Discover movies by genre
323
+ const actionMovies = await tmdb.discover.discoverMovies({
324
+ with_genres: '28', // Action genre ID
325
+ sort_by: 'popularity.desc'
326
+ });
327
+
328
+ // Discover TV shows by network
329
+ const netflixShows = await tmdb.discover.discoverTvShows({
330
+ with_networks: '213', // Netflix network ID
331
+ sort_by: 'vote_average.desc'
332
+ });
333
+ ```
334
+
335
+ ## Troubleshooting
336
+
337
+ ### Rate Limiting
338
+
339
+ TMDb API has rate limiting in place. If you encounter rate limiting issues, consider implementing a delay between requests or using a caching mechanism.
340
+
341
+ ```typescript
342
+ // Example of implementing a delay between requests
343
+ const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
344
+
345
+ async function fetchWithDelay() {
346
+ const result1 = await tmdb.movies.getPopular();
347
+ await delay(250); // Wait 250ms between requests
348
+ const result2 = await tmdb.tvShows.getPopular();
349
+ return { movies: result1, tvShows: result2 };
350
+ }
351
+ ```
352
+
353
+ ### Authentication Issues
354
+
355
+ If you're experiencing authentication issues, ensure your API key or access token is valid and correctly formatted.
356
+
357
+ ```typescript
358
+ // Check if your token is valid
359
+ try {
360
+ const accountDetails = await tmdb.account.getDetails();
361
+ console.log('Authentication successful:', accountDetails);
362
+ } catch (error) {
363
+ console.error('Authentication failed:', error);
364
+ }
365
+ ```
366
+
367
+ ## API Reference
368
+
369
+ For a complete list of available methods and parameters, please refer to the [TMDB API Documentation](https://developers.themoviedb.org/3/getting-started/introduction).
370
+
371
+ This wrapper aims to provide a 1:1 mapping to the official TMDB API, with TypeScript types for improved developer experience.
372
+
373
+ ## Contributing
374
+
375
+ Contributions are welcome! For bug reports, feature requests, or any other questions, please open an issue on the [GitHub repository](https://github.com/api-wrappers/tmdb-wrapper).
376
+
377
+ 1. Fork the repository
378
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
379
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
380
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
381
+ 5. Open a Pull Request
382
+
383
+ ## License
384
+
385
+ This project is licensed under the MIT License - see the [LICENSE](https://github.com/api-wrappers/tmdb-wrapper/blob/main/LICENSE) file for details.
386
+
387
+ <br/>
388
+
389
+ # ❤️
390
+
391
+ <p align="center">
392
+ <a target="_blank" href="https://tdanks.com/mental-health/quote">
393
+ ❤️ Reminder that <strong><i>you are great, you are enough, and your presence is valued.</i></strong> If you are struggling with your mental health, please reach out to someone you love and consult a professional. You are not alone. ❤️
394
+ </a>
395
+ </p>