@lorenzopant/tmdb 1.18.0 → 1.19.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/dist/index.d.mts +171 -2
- package/dist/index.mjs +297 -76
- package/package.json +6 -8
package/dist/index.d.mts
CHANGED
|
@@ -477,6 +477,14 @@ type ImagesConfig = {
|
|
|
477
477
|
* Provide default image size configuration for each type of images.
|
|
478
478
|
*/
|
|
479
479
|
default_image_sizes?: Partial<DefaultImageSizesConfig>;
|
|
480
|
+
/**
|
|
481
|
+
* Automatically expand TMDB image paths found in API responses into full URLs
|
|
482
|
+
* using the configured default image sizes.
|
|
483
|
+
*
|
|
484
|
+
* This is disabled by default to preserve the existing response shape semantics,
|
|
485
|
+
* where fields like `poster_path` contain the original relative TMDB path.
|
|
486
|
+
*/
|
|
487
|
+
autocomplete_paths?: boolean;
|
|
480
488
|
};
|
|
481
489
|
//#endregion
|
|
482
490
|
//#region src/errors/tmdb.d.ts
|
|
@@ -3351,6 +3359,47 @@ type PersonImagesParams = PersonBaseParam;
|
|
|
3351
3359
|
type PersonTranslationsParams = PersonBaseParam;
|
|
3352
3360
|
type PersonTaggedImagesParams = Prettify<PersonBaseParam & WithPage>;
|
|
3353
3361
|
//#endregion
|
|
3362
|
+
//#region src/types/v4/auth.d.ts
|
|
3363
|
+
/** Optional request body for POST /4/auth/request_token. */
|
|
3364
|
+
type V4AuthCreateRequestTokenBody = {
|
|
3365
|
+
/** URL to redirect the user back to after they approve the request token on TMDB. */redirect_to?: string;
|
|
3366
|
+
};
|
|
3367
|
+
/**
|
|
3368
|
+
* Response from POST /4/auth/request_token.
|
|
3369
|
+
* Contains a short-lived request token the user must approve at the TMDB website.
|
|
3370
|
+
*/
|
|
3371
|
+
type V4AuthRequestTokenResponse = {
|
|
3372
|
+
/** Always `true` on success. */success: boolean;
|
|
3373
|
+
/** The generated request token. Redirect the user to:
|
|
3374
|
+
* `https://www.themoviedb.org/auth/access?request_token={request_token}` to approve it. */
|
|
3375
|
+
request_token: string;
|
|
3376
|
+
};
|
|
3377
|
+
/** Request body for POST /4/auth/access_token. */
|
|
3378
|
+
type V4AuthCreateAccessTokenBody = {
|
|
3379
|
+
/** The request token that the user has approved at the TMDB website. */request_token: string;
|
|
3380
|
+
};
|
|
3381
|
+
/**
|
|
3382
|
+
* Response from POST /4/auth/access_token.
|
|
3383
|
+
* Contains the permanent user access token and the TMDB account ID.
|
|
3384
|
+
*/
|
|
3385
|
+
type V4AuthAccessTokenResponse = {
|
|
3386
|
+
/** Always `true` on success. */success: boolean; /** The permanent user access token (Bearer token). Store this securely — treat it like a password. */
|
|
3387
|
+
access_token: string; /** The TMDB account ID associated with this access token. Used by v4 account endpoints. */
|
|
3388
|
+
account_id: string;
|
|
3389
|
+
};
|
|
3390
|
+
/** Request body for DELETE /4/auth/access_token. */
|
|
3391
|
+
type V4AuthDeleteAccessTokenBody = {
|
|
3392
|
+
/** The access token to invalidate. */access_token: string;
|
|
3393
|
+
};
|
|
3394
|
+
/**
|
|
3395
|
+
* Response from DELETE /4/auth/access_token.
|
|
3396
|
+
*/
|
|
3397
|
+
type V4AuthDeleteAccessTokenResponse = {
|
|
3398
|
+
/** `true` if the access token was successfully deleted. */success: boolean; /** TMDB internal status code. */
|
|
3399
|
+
status_code: number; /** Human-readable status message. */
|
|
3400
|
+
status_message: string;
|
|
3401
|
+
};
|
|
3402
|
+
//#endregion
|
|
3354
3403
|
//#region src/client.d.ts
|
|
3355
3404
|
declare class ApiClient {
|
|
3356
3405
|
private accessToken;
|
|
@@ -3367,9 +3416,12 @@ declare class ApiClient {
|
|
|
3367
3416
|
private requestInterceptors;
|
|
3368
3417
|
private onSuccessInterceptor?;
|
|
3369
3418
|
private onErrorInterceptor?;
|
|
3419
|
+
private imageApi?;
|
|
3370
3420
|
constructor(accessToken: string, options?: {
|
|
3421
|
+
/** @internal API version to target. Used by TMDBv4 — not exposed in TMDBOptions. */version?: 3 | 4;
|
|
3371
3422
|
logger?: boolean | TMDBLoggerFn;
|
|
3372
3423
|
deduplication?: boolean;
|
|
3424
|
+
images?: ImagesConfig;
|
|
3373
3425
|
interceptors?: {
|
|
3374
3426
|
request?: RequestInterceptor | RequestInterceptor[];
|
|
3375
3427
|
response?: {
|
|
@@ -4459,6 +4511,26 @@ declare class ImageAPI {
|
|
|
4459
4511
|
poster(path: string, size?: PosterSize): string;
|
|
4460
4512
|
profile(path: string, size?: ProfileSize): string;
|
|
4461
4513
|
still(path: string, size?: StillSize): string;
|
|
4514
|
+
/**
|
|
4515
|
+
* Recursively processes an object or array to autocomplete image paths by transforming string values
|
|
4516
|
+
* and tracking the current image collection context.
|
|
4517
|
+
*
|
|
4518
|
+
* @template T - The type of the value being processed
|
|
4519
|
+
* @param value - The value to process (can be an object, array, string, or primitive)
|
|
4520
|
+
* @param collectionKey - Optional image collection key to maintain context during recursion
|
|
4521
|
+
* @returns The processed value with autocompleted image paths, maintaining the original type
|
|
4522
|
+
*
|
|
4523
|
+
* @remarks
|
|
4524
|
+
* - Arrays are recursively mapped over each entry
|
|
4525
|
+
* - String values are transformed using {@link transformPathValue}
|
|
4526
|
+
* - Object keys that match image collection keys update the collection context
|
|
4527
|
+
* - Non-plain objects (e.g. Date/class instances) are returned unchanged
|
|
4528
|
+
*/
|
|
4529
|
+
autocompleteImagePaths<T>(value: T, collectionKey?: ImageCollectionKey): T;
|
|
4530
|
+
private isImageCollectionKey;
|
|
4531
|
+
private isFullUrl;
|
|
4532
|
+
private buildImageUrl;
|
|
4533
|
+
private transformPathValue;
|
|
4462
4534
|
}
|
|
4463
4535
|
//#endregion
|
|
4464
4536
|
//#region src/endpoints/networks.d.ts
|
|
@@ -5079,9 +5151,89 @@ declare class AuthenticationAPI extends TMDBAPIBase {
|
|
|
5079
5151
|
delete_session(body: AuthDeleteSessionBody): Promise<AuthDeleteSessionResponse>;
|
|
5080
5152
|
}
|
|
5081
5153
|
//#endregion
|
|
5154
|
+
//#region src/endpoints/v4/auth.d.ts
|
|
5155
|
+
declare class V4AuthAPI extends TMDBAPIBase {
|
|
5156
|
+
/**
|
|
5157
|
+
* Create Request Token
|
|
5158
|
+
* POST - https://api.themoviedb.org/4/auth/request_token
|
|
5159
|
+
*
|
|
5160
|
+
* Generate a request token that the user must approve at the TMDB website to begin
|
|
5161
|
+
* the v4 OAuth-style flow. Redirect the user to:
|
|
5162
|
+
* `https://www.themoviedb.org/auth/access?request_token={request_token}`
|
|
5163
|
+
*
|
|
5164
|
+
* Once approved, exchange the token for an access token using `create_access_token`.
|
|
5165
|
+
* @param body Optional body with a `redirect_to` URL for post-approval redirect.
|
|
5166
|
+
* @reference https://developer.themoviedb.org/reference/create-request-token
|
|
5167
|
+
*/
|
|
5168
|
+
create_request_token(body?: V4AuthCreateRequestTokenBody): Promise<V4AuthRequestTokenResponse>;
|
|
5169
|
+
/**
|
|
5170
|
+
* Create Access Token
|
|
5171
|
+
* POST - https://api.themoviedb.org/4/auth/access_token
|
|
5172
|
+
*
|
|
5173
|
+
* Exchange a user-approved request token for a permanent user access token and
|
|
5174
|
+
* TMDB account ID. Store the returned `access_token` securely — it is valid
|
|
5175
|
+
* indefinitely until explicitly deleted with `delete_access_token`.
|
|
5176
|
+
* @param body An object containing the approved `request_token`.
|
|
5177
|
+
* @reference https://developer.themoviedb.org/reference/create-access-token
|
|
5178
|
+
*/
|
|
5179
|
+
create_access_token(body: V4AuthCreateAccessTokenBody): Promise<V4AuthAccessTokenResponse>;
|
|
5180
|
+
/**
|
|
5181
|
+
* Delete Access Token (Logout)
|
|
5182
|
+
* DELETE - https://api.themoviedb.org/4/auth/access_token
|
|
5183
|
+
*
|
|
5184
|
+
* Invalidate a user access token. Use this to log a user out of your application.
|
|
5185
|
+
* @param body An object containing the `access_token` to delete.
|
|
5186
|
+
* @reference https://developer.themoviedb.org/reference/delete-access-token
|
|
5187
|
+
*/
|
|
5188
|
+
delete_access_token(body: V4AuthDeleteAccessTokenBody): Promise<V4AuthDeleteAccessTokenResponse>;
|
|
5189
|
+
}
|
|
5190
|
+
//#endregion
|
|
5191
|
+
//#region src/endpoints/v4/account.d.ts
|
|
5192
|
+
declare class V4AccountAPI extends TMDBAPIBase {}
|
|
5193
|
+
//#endregion
|
|
5194
|
+
//#region src/endpoints/v4/lists.d.ts
|
|
5195
|
+
declare class V4ListsAPI extends TMDBAPIBase {}
|
|
5196
|
+
//#endregion
|
|
5197
|
+
//#region src/tmdb.v4.d.ts
|
|
5198
|
+
/**
|
|
5199
|
+
* Aggregator for all TMDB API v4 namespaces.
|
|
5200
|
+
*
|
|
5201
|
+
* Access via `tmdb.v4` — the v4 client is backed by `https://api.themoviedb.org/4`
|
|
5202
|
+
* and inherits the same access token and options as the parent TMDB instance.
|
|
5203
|
+
*
|
|
5204
|
+
* @example
|
|
5205
|
+
* ```ts
|
|
5206
|
+
* const tmdb = new TMDB(accessToken);
|
|
5207
|
+
*
|
|
5208
|
+
* // v4 auth flow
|
|
5209
|
+
* const { request_token } = await tmdb.v4.auth.create_request_token();
|
|
5210
|
+
* // ... user approves at https://www.themoviedb.org/auth/access?request_token=...
|
|
5211
|
+
* const { access_token, account_id } = await tmdb.v4.auth.create_access_token({ request_token });
|
|
5212
|
+
*
|
|
5213
|
+
* // v4 account (account_id is a string from the access token response)
|
|
5214
|
+
* const profile = await tmdb.v4.account.details(account_id);
|
|
5215
|
+
* const favorites = await tmdb.v4.account.favorite_movies({ account_id, page: 1 });
|
|
5216
|
+
*
|
|
5217
|
+
* // v4 lists (full CRUD)
|
|
5218
|
+
* const list = await tmdb.v4.lists.create({ name: "My list", iso_639_1: "en" });
|
|
5219
|
+
* await tmdb.v4.lists.add_items(list.id, { items: [{ media_type: "movie", media_id: 550 }] });
|
|
5220
|
+
* ```
|
|
5221
|
+
*/
|
|
5222
|
+
declare class TMDBv4 {
|
|
5223
|
+
private client;
|
|
5224
|
+
/** v4 authentication — request token → access token → logout. */
|
|
5225
|
+
auth: V4AuthAPI;
|
|
5226
|
+
/** v4 account — details, lists, favorites, watchlist, rated. */
|
|
5227
|
+
account: V4AccountAPI;
|
|
5228
|
+
/** v4 lists — full CRUD for user-created lists. */
|
|
5229
|
+
lists: V4ListsAPI;
|
|
5230
|
+
constructor(accessToken: string, options?: TMDBOptions);
|
|
5231
|
+
}
|
|
5232
|
+
//#endregion
|
|
5082
5233
|
//#region src/tmdb.d.ts
|
|
5083
5234
|
declare class TMDB {
|
|
5084
5235
|
private client;
|
|
5236
|
+
private accessToken;
|
|
5085
5237
|
private options;
|
|
5086
5238
|
movies: MoviesAPI;
|
|
5087
5239
|
movie_lists: MovieListsAPI;
|
|
@@ -5110,6 +5262,12 @@ declare class TMDB {
|
|
|
5110
5262
|
people: PeopleAPI;
|
|
5111
5263
|
account: AccountAPI;
|
|
5112
5264
|
authentication: AuthenticationAPI;
|
|
5265
|
+
/**
|
|
5266
|
+
* TMDB API v4 namespaces. Access via `tmdb.v4.auth`, `tmdb.v4.account`, `tmdb.v4.lists`.
|
|
5267
|
+
* Requires a Bearer (JWT) access token — throws if the instance was created with an API key.
|
|
5268
|
+
*/
|
|
5269
|
+
get v4(): TMDBv4;
|
|
5270
|
+
private _v4;
|
|
5113
5271
|
/**
|
|
5114
5272
|
* Creates a new TMDB instance.
|
|
5115
5273
|
* @param accessToken The TMDB API access token.
|
|
@@ -5121,7 +5279,18 @@ declare class TMDB {
|
|
|
5121
5279
|
//#region src/utils/jwt.d.ts
|
|
5122
5280
|
declare function isJwt(token: string): boolean;
|
|
5123
5281
|
//#endregion
|
|
5124
|
-
//#region src/utils/
|
|
5282
|
+
//#region src/utils/types.d.ts
|
|
5283
|
+
/**
|
|
5284
|
+
* Typeguard that checks if a value is a record object.
|
|
5285
|
+
* @param value - The value to check
|
|
5286
|
+
* @returns `true` if the value is a non-null object that is not an array, `false` otherwise
|
|
5287
|
+
*/
|
|
5288
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
5289
|
+
/**
|
|
5290
|
+
* Typeguard that checks whether a value is a plain object.
|
|
5291
|
+
* Plain objects are objects whose prototype is `Object.prototype` or `null`.
|
|
5292
|
+
*/
|
|
5293
|
+
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
5125
5294
|
/** Utility type guard to check if an object has a poster_path property */
|
|
5126
5295
|
declare function hasPosterPath(data: unknown): data is {
|
|
5127
5296
|
poster_path: string;
|
|
@@ -5143,4 +5312,4 @@ declare function hasLogoPath(data: unknown): data is {
|
|
|
5143
5312
|
logo_path: string;
|
|
5144
5313
|
};
|
|
5145
5314
|
//#endregion
|
|
5146
|
-
export { AccountAPI, AccountAddFavoriteBody, AccountAddToWatchlistBody, AccountAvatar, AccountDetails, AccountDetailsParams, AccountListItem, AccountListsParams, AccountListsResponse, AccountMediaListParams, AccountMovieItem, AccountMovieListResponse, AccountMutationParams, AccountMutationResponse, AccountRatedEpisodeItem, AccountRatedEpisodesResponse, AccountRatedMovieItem, AccountRatedMoviesResponse, AccountRatedTVItem, AccountRatedTVResponse, AccountSortBy, AccountTVItem, AccountTVListResponse, AlternativeName, AlternativeNamesResult, AlternativeTitle, AuthCreateSessionBody, AuthCreateSessionResponse, AuthCreateSessionWithLoginBody, AuthDeleteSessionBody, AuthDeleteSessionResponse, AuthGuestSessionResponse, AuthRequestTokenResponse, AuthValidateKeyResponse, AuthenticationAPI, BACKDROP_SIZES, BackdropSize, Cast, CertificationItem, Certifications, CertificationsAPI, Change, ChangeItem, ChangeResultItem, Changes, ChangesAPI, Collection, CollectionBaseParam, CollectionDetailsParams, CollectionImages, CollectionImagesParams, CollectionItem, CollectionResultItem, CollectionTranslationData, CollectionTranslations, CollectionsAPI, CompaniesAPI, Company, CompanyAlternativeName, CompanyAlternativeNames, CompanyAlternativeNamesParams, CompanyBaseParam, CompanyDetailsParams, CompanyImages, CompanyImagesParams, CompanyResultItem, CompanySummary, ConfigurationAPI, ConfigurationCountriesParams, ConfigurationCountry, ConfigurationJob, ConfigurationLanguage, ConfigurationResponse, ConfigurationTimezone, ContentRating, CountryISO3166_1, Credit, CreditBaseParam, CreditDetails, CreditDetailsMedia, CreditDetailsMovieMedia, CreditDetailsParams, CreditDetailsPerson, CreditDetailsTVEpisode, CreditDetailsTVMedia, CreditDetailsTVSeason, CreditsAPI, Crew, DateRange, DefaultImageSizesConfig, DiscoverAPI, DiscoverFilterExpression, DiscoverMovieParams, DiscoverMovieSortBy, DiscoverTVParams, DiscoverTVResultItem, DiscoverTVSortBy, DiscoverTVStatus, DiscoverTVType, FileType, FindAPI, FindByIDParams, FindExternalSource, FindMovieResultItem, FindPersonResultItem, FindResults, FindTVEpisodeResultItem, FindTVResultItem, FindTVSeasonResultItem, Genre, GenresAPI, GenresResponse, IMAGE_BASE_URL, IMAGE_SECURE_BASE_URL, ImageCollectionKey, ImageConfiguration, ImageItem, ImageSize, ImageSizeTypes, ImagesConfig, ImagesResult, Keyword, KeywordBaseParam, KeywordDetailsParams, KeywordMoviesParams, KeywordResultItem, KeywordsAPI, KnownForItem, KnownForMovie, KnownForTV, LOGO_SIZES, Language, LanguageISO6391, LiteralUnion, LogoSize, MediaType, MediaWatchProviders, MovieAlternativeTitles, MovieAlternativeTitlesParams, MovieAppendToResponseNamespace, MovieAppendableMap, MovieChanges, MovieChangesParams, MovieCollection, MovieCredits, MovieCreditsParams, MovieDetails, MovieDetailsParams, MovieDetailsWithAppends, MovieExternalIDs, MovieExternalIDsParams, MovieImages, MovieImagesParams, MovieKeywords, MovieKeywordsParams, MovieListParams, MovieListsAPI, MovieRecommendations, MovieRecommendationsParams, MovieReleaseDate, MovieReleaseDateResult, MovieReleaseDates, MovieReleaseDatesParams, MovieResultItem, MovieReviews, MovieReviewsParams, MovieSimilar, MovieSimilarParams, MovieTranslationData, MovieTranslations, MovieTranslationsParams, MovieVideos, MovieVideosParams, MovieWatchProvidersParams, MoviesAPI, MultiSearchResultItem, Network, NetworkBaseParams, NetworkImages, NetworkItem, NetworksAPI, OrganizationImage, POSTER_SIZES, PROFILE_SIZES, PaginatedResponse, PeopleAPI, PeopleListParams, PeopleListsAPI, PersonAppendToResponseNamespace, PersonAppendableMap, PersonBaseParam, PersonChanges, PersonChangesParams, PersonCombinedCastCredit, PersonCombinedCredits, PersonCombinedCrewCredit, PersonCreditsParams, PersonDetails, PersonDetailsParams, PersonDetailsWithAppends, PersonExternalIDs, PersonExternalIDsParams, PersonImages, PersonImagesParams, PersonMovieCastCredit, PersonMovieCredits, PersonMovieCrewCredit, PersonResultItem, PersonTVCastCredit, PersonTVCredits, PersonTVCrewCredit, PersonTaggedImage, PersonTaggedImageMedia, PersonTaggedImages, PersonTaggedImagesParams, PersonTranslationData, PersonTranslations, PersonTranslationsParams, PosterSize, Prettify, PrimaryTranslations, ProductionCompany, ProductionCountry, ProfileSize, RequestInterceptor, RequestInterceptorContext, ResponseErrorInterceptor, ResponseSuccessInterceptor, Review, ReviewAuthorDetails, ReviewDetails, ReviewDetailsParams, ReviewsAPI, STILL_SIZES, SearchAPI, SearchCollectionsParams, SearchCompanyParams, SearchKeywordsParams, SearchMoviesParams, SearchMultiParams, SearchPersonParams, SearchTVSeriesParams, SpokenLanguage, StillSize, TMDB, TMDBCountries, TMDBError, TMDBLogger, TMDBLoggerEntry, TMDBLoggerFn, TMDBOptions, TMDBQueryParams, TVAggregateCredits, TVAggregateCreditsCastItem, TVAggregateCreditsCrewItem, TVAggregateCreditsParams, TVAlternativeTitles, TVAppendToResponseNamespace, TVAppendableMap, TVBaseParam, TVChangeParams, TVContentRatings, TVCreditJob, TVCreditRole, TVCredits, TVCreditsParams, TVDetailsParams, TVDetailsWithAppends, TVEpisode, TVEpisodeAppendToResponseNamespace, TVEpisodeAppendableMap, TVEpisodeBaseParams, TVEpisodeCredits, TVEpisodeCreditsParams, TVEpisodeDetailsParams, TVEpisodeDetailsWithAppends, TVEpisodeExternalIDs, TVEpisodeGroupDetails, TVEpisodeGroupDetailsItem, TVEpisodeGroupEpisode, TVEpisodeGroupItem, TVEpisodeGroupParams, TVEpisodeGroupType, TVEpisodeGroups, TVEpisodeGroupsAPI, TVEpisodeId, TVEpisodeImages, TVEpisodeImagesParams, TVEpisodeItem, TVEpisodeTranslationData, TVEpisodeTranslations, TVEpisodeVideos, TVEpisodesAPI, TVExternalIDs, TVImageItem, TVImages, TVImagesParams, TVKeywords, TVRecommendations, TVRecommendationsParams, TVReviews, TVReviewsParams, TVScreenedTheatrically, TVScreeningItem, TVSeason, TVSeasonAggregateCredits, TVSeasonAggregateCreditsParams, TVSeasonAppendToResponseNamespace, TVSeasonAppendableMap, TVSeasonBaseParams, TVSeasonChanges, TVSeasonChangesParams, TVSeasonCredits, TVSeasonCreditsParams, TVSeasonDetailsParams, TVSeasonDetailsWithAppends, TVSeasonEpisode, TVSeasonExternalIDs, TVSeasonId, TVSeasonImages, TVSeasonImagesParams, TVSeasonItem, TVSeasonTranslationData, TVSeasonTranslations, TVSeasonVideos, TVSeasonVideosParams, TVSeasonWatchProvidersParams, TVSeasonsAPI, TVSeriesAPI, TVSeriesChanges, TVSeriesDetails, TVSeriesListItem, TVSeriesListParams, TVSeriesLists, TVSeriesListsAPI, TVSeriesListsParams, TVSeriesResultItem, TVSimilar, TVSimilarParams, TVTranslationData, TVTranslations, TVVideos, Timezone, Translation, TranslationResults, TrendingAPI, TrendingAllResult, TrendingMovieResult, TrendingParams, TrendingPersonResult, TrendingTVResult, TrendingTimeWindow, VideoItem, VideoResults, WatchMonetizationType, WatchProvider, WatchProviderDisplayPriorities, WatchProviderItem, WatchProviderListItem, WatchProviderListParams, WatchProviderListResponse, WatchProviderRegionsParams, WatchProviderRegionsResponse, WatchProvidersAPI, WithLanguage, WithLanguagePage, WithPage, WithPageAndDateRange, WithParams, WithRegion, hasBackdropPath, hasLogoPath, hasPosterPath, hasProfilePath, hasStillPath, isJwt, isKnownForMovie, isKnownForTV };
|
|
5315
|
+
export { AccountAPI, AccountAddFavoriteBody, AccountAddToWatchlistBody, AccountAvatar, AccountDetails, AccountDetailsParams, AccountListItem, AccountListsParams, AccountListsResponse, AccountMediaListParams, AccountMovieItem, AccountMovieListResponse, AccountMutationParams, AccountMutationResponse, AccountRatedEpisodeItem, AccountRatedEpisodesResponse, AccountRatedMovieItem, AccountRatedMoviesResponse, AccountRatedTVItem, AccountRatedTVResponse, AccountSortBy, AccountTVItem, AccountTVListResponse, AlternativeName, AlternativeNamesResult, AlternativeTitle, AuthCreateSessionBody, AuthCreateSessionResponse, AuthCreateSessionWithLoginBody, AuthDeleteSessionBody, AuthDeleteSessionResponse, AuthGuestSessionResponse, AuthRequestTokenResponse, AuthValidateKeyResponse, AuthenticationAPI, BACKDROP_SIZES, BackdropSize, Cast, CertificationItem, Certifications, CertificationsAPI, Change, ChangeItem, ChangeResultItem, Changes, ChangesAPI, Collection, CollectionBaseParam, CollectionDetailsParams, CollectionImages, CollectionImagesParams, CollectionItem, CollectionResultItem, CollectionTranslationData, CollectionTranslations, CollectionsAPI, CompaniesAPI, Company, CompanyAlternativeName, CompanyAlternativeNames, CompanyAlternativeNamesParams, CompanyBaseParam, CompanyDetailsParams, CompanyImages, CompanyImagesParams, CompanyResultItem, CompanySummary, ConfigurationAPI, ConfigurationCountriesParams, ConfigurationCountry, ConfigurationJob, ConfigurationLanguage, ConfigurationResponse, ConfigurationTimezone, ContentRating, CountryISO3166_1, Credit, CreditBaseParam, CreditDetails, CreditDetailsMedia, CreditDetailsMovieMedia, CreditDetailsParams, CreditDetailsPerson, CreditDetailsTVEpisode, CreditDetailsTVMedia, CreditDetailsTVSeason, CreditsAPI, Crew, DateRange, DefaultImageSizesConfig, DiscoverAPI, DiscoverFilterExpression, DiscoverMovieParams, DiscoverMovieSortBy, DiscoverTVParams, DiscoverTVResultItem, DiscoverTVSortBy, DiscoverTVStatus, DiscoverTVType, FileType, FindAPI, FindByIDParams, FindExternalSource, FindMovieResultItem, FindPersonResultItem, FindResults, FindTVEpisodeResultItem, FindTVResultItem, FindTVSeasonResultItem, Genre, GenresAPI, GenresResponse, IMAGE_BASE_URL, IMAGE_SECURE_BASE_URL, ImageCollectionKey, ImageConfiguration, ImageItem, ImageSize, ImageSizeTypes, ImagesConfig, ImagesResult, Keyword, KeywordBaseParam, KeywordDetailsParams, KeywordMoviesParams, KeywordResultItem, KeywordsAPI, KnownForItem, KnownForMovie, KnownForTV, LOGO_SIZES, Language, LanguageISO6391, LiteralUnion, LogoSize, MediaType, MediaWatchProviders, MovieAlternativeTitles, MovieAlternativeTitlesParams, MovieAppendToResponseNamespace, MovieAppendableMap, MovieChanges, MovieChangesParams, MovieCollection, MovieCredits, MovieCreditsParams, MovieDetails, MovieDetailsParams, MovieDetailsWithAppends, MovieExternalIDs, MovieExternalIDsParams, MovieImages, MovieImagesParams, MovieKeywords, MovieKeywordsParams, MovieListParams, MovieListsAPI, MovieRecommendations, MovieRecommendationsParams, MovieReleaseDate, MovieReleaseDateResult, MovieReleaseDates, MovieReleaseDatesParams, MovieResultItem, MovieReviews, MovieReviewsParams, MovieSimilar, MovieSimilarParams, MovieTranslationData, MovieTranslations, MovieTranslationsParams, MovieVideos, MovieVideosParams, MovieWatchProvidersParams, MoviesAPI, MultiSearchResultItem, Network, NetworkBaseParams, NetworkImages, NetworkItem, NetworksAPI, OrganizationImage, POSTER_SIZES, PROFILE_SIZES, PaginatedResponse, PeopleAPI, PeopleListParams, PeopleListsAPI, PersonAppendToResponseNamespace, PersonAppendableMap, PersonBaseParam, PersonChanges, PersonChangesParams, PersonCombinedCastCredit, PersonCombinedCredits, PersonCombinedCrewCredit, PersonCreditsParams, PersonDetails, PersonDetailsParams, PersonDetailsWithAppends, PersonExternalIDs, PersonExternalIDsParams, PersonImages, PersonImagesParams, PersonMovieCastCredit, PersonMovieCredits, PersonMovieCrewCredit, PersonResultItem, PersonTVCastCredit, PersonTVCredits, PersonTVCrewCredit, PersonTaggedImage, PersonTaggedImageMedia, PersonTaggedImages, PersonTaggedImagesParams, PersonTranslationData, PersonTranslations, PersonTranslationsParams, PosterSize, Prettify, PrimaryTranslations, ProductionCompany, ProductionCountry, ProfileSize, RequestInterceptor, RequestInterceptorContext, ResponseErrorInterceptor, ResponseSuccessInterceptor, Review, ReviewAuthorDetails, ReviewDetails, ReviewDetailsParams, ReviewsAPI, STILL_SIZES, SearchAPI, SearchCollectionsParams, SearchCompanyParams, SearchKeywordsParams, SearchMoviesParams, SearchMultiParams, SearchPersonParams, SearchTVSeriesParams, SpokenLanguage, StillSize, TMDB, TMDBCountries, TMDBError, TMDBLogger, TMDBLoggerEntry, TMDBLoggerFn, TMDBOptions, TMDBQueryParams, TMDBv4, TVAggregateCredits, TVAggregateCreditsCastItem, TVAggregateCreditsCrewItem, TVAggregateCreditsParams, TVAlternativeTitles, TVAppendToResponseNamespace, TVAppendableMap, TVBaseParam, TVChangeParams, TVContentRatings, TVCreditJob, TVCreditRole, TVCredits, TVCreditsParams, TVDetailsParams, TVDetailsWithAppends, TVEpisode, TVEpisodeAppendToResponseNamespace, TVEpisodeAppendableMap, TVEpisodeBaseParams, TVEpisodeCredits, TVEpisodeCreditsParams, TVEpisodeDetailsParams, TVEpisodeDetailsWithAppends, TVEpisodeExternalIDs, TVEpisodeGroupDetails, TVEpisodeGroupDetailsItem, TVEpisodeGroupEpisode, TVEpisodeGroupItem, TVEpisodeGroupParams, TVEpisodeGroupType, TVEpisodeGroups, TVEpisodeGroupsAPI, TVEpisodeId, TVEpisodeImages, TVEpisodeImagesParams, TVEpisodeItem, TVEpisodeTranslationData, TVEpisodeTranslations, TVEpisodeVideos, TVEpisodesAPI, TVExternalIDs, TVImageItem, TVImages, TVImagesParams, TVKeywords, TVRecommendations, TVRecommendationsParams, TVReviews, TVReviewsParams, TVScreenedTheatrically, TVScreeningItem, TVSeason, TVSeasonAggregateCredits, TVSeasonAggregateCreditsParams, TVSeasonAppendToResponseNamespace, TVSeasonAppendableMap, TVSeasonBaseParams, TVSeasonChanges, TVSeasonChangesParams, TVSeasonCredits, TVSeasonCreditsParams, TVSeasonDetailsParams, TVSeasonDetailsWithAppends, TVSeasonEpisode, TVSeasonExternalIDs, TVSeasonId, TVSeasonImages, TVSeasonImagesParams, TVSeasonItem, TVSeasonTranslationData, TVSeasonTranslations, TVSeasonVideos, TVSeasonVideosParams, TVSeasonWatchProvidersParams, TVSeasonsAPI, TVSeriesAPI, TVSeriesChanges, TVSeriesDetails, TVSeriesListItem, TVSeriesListParams, TVSeriesLists, TVSeriesListsAPI, TVSeriesListsParams, TVSeriesResultItem, TVSimilar, TVSimilarParams, TVTranslationData, TVTranslations, TVVideos, Timezone, Translation, TranslationResults, TrendingAPI, TrendingAllResult, TrendingMovieResult, TrendingParams, TrendingPersonResult, TrendingTVResult, TrendingTimeWindow, V4AccountAPI, V4AuthAPI, V4AuthAccessTokenResponse, V4AuthCreateAccessTokenBody, V4AuthCreateRequestTokenBody, V4AuthDeleteAccessTokenBody, V4AuthDeleteAccessTokenResponse, V4AuthRequestTokenResponse, V4ListsAPI, VideoItem, VideoResults, WatchMonetizationType, WatchProvider, WatchProviderDisplayPriorities, WatchProviderItem, WatchProviderListItem, WatchProviderListParams, WatchProviderListResponse, WatchProviderRegionsParams, WatchProviderRegionsResponse, WatchProvidersAPI, WithLanguage, WithLanguagePage, WithPage, WithPageAndDateRange, WithParams, WithRegion, hasBackdropPath, hasLogoPath, hasPosterPath, hasProfilePath, hasStillPath, isJwt, isKnownForMovie, isKnownForTV, isPlainObject, isRecord };
|
package/dist/index.mjs
CHANGED
|
@@ -39,6 +39,46 @@ var TMDBError = class extends Error {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
//#endregion
|
|
42
|
+
//#region src/types/config/images.ts
|
|
43
|
+
const IMAGE_BASE_URL = "http://image.tmdb.org/t/p/";
|
|
44
|
+
const IMAGE_SECURE_BASE_URL = "https://image.tmdb.org/t/p/";
|
|
45
|
+
const BACKDROP_SIZES = [
|
|
46
|
+
"w300",
|
|
47
|
+
"w780",
|
|
48
|
+
"w1280",
|
|
49
|
+
"original"
|
|
50
|
+
];
|
|
51
|
+
const LOGO_SIZES = [
|
|
52
|
+
"w45",
|
|
53
|
+
"w92",
|
|
54
|
+
"w154",
|
|
55
|
+
"w185",
|
|
56
|
+
"w300",
|
|
57
|
+
"w500",
|
|
58
|
+
"original"
|
|
59
|
+
];
|
|
60
|
+
const POSTER_SIZES = [
|
|
61
|
+
"w92",
|
|
62
|
+
"w154",
|
|
63
|
+
"w185",
|
|
64
|
+
"w342",
|
|
65
|
+
"w500",
|
|
66
|
+
"w780",
|
|
67
|
+
"original"
|
|
68
|
+
];
|
|
69
|
+
const PROFILE_SIZES = [
|
|
70
|
+
"w45",
|
|
71
|
+
"w185",
|
|
72
|
+
"h632",
|
|
73
|
+
"original"
|
|
74
|
+
];
|
|
75
|
+
const STILL_SIZES = [
|
|
76
|
+
"w92",
|
|
77
|
+
"w185",
|
|
78
|
+
"w300",
|
|
79
|
+
"original"
|
|
80
|
+
];
|
|
81
|
+
//#endregion
|
|
42
82
|
//#region src/utils/logger.ts
|
|
43
83
|
var TMDBLogger = class TMDBLogger {
|
|
44
84
|
logger;
|
|
@@ -124,7 +164,24 @@ function isJwt(token) {
|
|
|
124
164
|
return true;
|
|
125
165
|
}
|
|
126
166
|
//#endregion
|
|
127
|
-
//#region src/utils/
|
|
167
|
+
//#region src/utils/types.ts
|
|
168
|
+
/**
|
|
169
|
+
* Typeguard that checks if a value is a record object.
|
|
170
|
+
* @param value - The value to check
|
|
171
|
+
* @returns `true` if the value is a non-null object that is not an array, `false` otherwise
|
|
172
|
+
*/
|
|
173
|
+
function isRecord(value) {
|
|
174
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Typeguard that checks whether a value is a plain object.
|
|
178
|
+
* Plain objects are objects whose prototype is `Object.prototype` or `null`.
|
|
179
|
+
*/
|
|
180
|
+
function isPlainObject(value) {
|
|
181
|
+
if (!isRecord(value)) return false;
|
|
182
|
+
const prototype = Object.getPrototypeOf(value);
|
|
183
|
+
return prototype === Object.prototype || prototype === null;
|
|
184
|
+
}
|
|
128
185
|
/** Utility type guard to check if an object has a poster_path property */
|
|
129
186
|
function hasPosterPath(data) {
|
|
130
187
|
return typeof data === "object" && data !== null && "poster_path" in data && typeof data.poster_path === "string";
|
|
@@ -146,10 +203,103 @@ function hasLogoPath(data) {
|
|
|
146
203
|
return typeof data === "object" && data !== null && "logo_path" in data && typeof data.logo_path === "string";
|
|
147
204
|
}
|
|
148
205
|
//#endregion
|
|
206
|
+
//#region src/images/images.ts
|
|
207
|
+
const IMAGE_PATH_BUILDERS = {
|
|
208
|
+
backdrop_path: "backdrop",
|
|
209
|
+
logo_path: "logo",
|
|
210
|
+
poster_path: "poster",
|
|
211
|
+
profile_path: "profile",
|
|
212
|
+
still_path: "still"
|
|
213
|
+
};
|
|
214
|
+
const IMAGE_COLLECTION_BUILDERS = {
|
|
215
|
+
backdrops: "backdrop_path",
|
|
216
|
+
logos: "logo_path",
|
|
217
|
+
posters: "poster_path",
|
|
218
|
+
profiles: "profile_path",
|
|
219
|
+
stills: "still_path"
|
|
220
|
+
};
|
|
221
|
+
var ImageAPI = class {
|
|
222
|
+
options;
|
|
223
|
+
constructor(options = {}) {
|
|
224
|
+
this.options = {
|
|
225
|
+
secure_images_url: true,
|
|
226
|
+
...options
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
buildUrl(path, size) {
|
|
230
|
+
return `${this.options.secure_images_url ? IMAGE_SECURE_BASE_URL : IMAGE_BASE_URL}${size}${path}`;
|
|
231
|
+
}
|
|
232
|
+
backdrop(path, size = this.options.default_image_sizes?.backdrops || "w780") {
|
|
233
|
+
return this.buildUrl(path, size);
|
|
234
|
+
}
|
|
235
|
+
logo(path, size = this.options.default_image_sizes?.logos || "w185") {
|
|
236
|
+
return this.buildUrl(path, size);
|
|
237
|
+
}
|
|
238
|
+
poster(path, size = this.options.default_image_sizes?.posters || "w500") {
|
|
239
|
+
return this.buildUrl(path, size);
|
|
240
|
+
}
|
|
241
|
+
profile(path, size = this.options.default_image_sizes?.profiles || "w185") {
|
|
242
|
+
return this.buildUrl(path, size);
|
|
243
|
+
}
|
|
244
|
+
still(path, size = this.options.default_image_sizes?.still || "w300") {
|
|
245
|
+
return this.buildUrl(path, size);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Recursively processes an object or array to autocomplete image paths by transforming string values
|
|
249
|
+
* and tracking the current image collection context.
|
|
250
|
+
*
|
|
251
|
+
* @template T - The type of the value being processed
|
|
252
|
+
* @param value - The value to process (can be an object, array, string, or primitive)
|
|
253
|
+
* @param collectionKey - Optional image collection key to maintain context during recursion
|
|
254
|
+
* @returns The processed value with autocompleted image paths, maintaining the original type
|
|
255
|
+
*
|
|
256
|
+
* @remarks
|
|
257
|
+
* - Arrays are recursively mapped over each entry
|
|
258
|
+
* - String values are transformed using {@link transformPathValue}
|
|
259
|
+
* - Object keys that match image collection keys update the collection context
|
|
260
|
+
* - Non-plain objects (e.g. Date/class instances) are returned unchanged
|
|
261
|
+
*/
|
|
262
|
+
autocompleteImagePaths(value, collectionKey) {
|
|
263
|
+
if (Array.isArray(value)) return value.map((entry) => this.autocompleteImagePaths(entry, collectionKey));
|
|
264
|
+
if (!isPlainObject(value)) return value;
|
|
265
|
+
const transformed = Object.create(null);
|
|
266
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
267
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
268
|
+
transformed[key] = entry;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (typeof entry === "string") {
|
|
272
|
+
transformed[key] = this.transformPathValue(key, entry, collectionKey);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const nextCollectionKey = this.isImageCollectionKey(key) ? key : collectionKey;
|
|
276
|
+
transformed[key] = this.autocompleteImagePaths(entry, nextCollectionKey);
|
|
277
|
+
}
|
|
278
|
+
return transformed;
|
|
279
|
+
}
|
|
280
|
+
isImageCollectionKey(value) {
|
|
281
|
+
return Object.hasOwn(IMAGE_COLLECTION_BUILDERS, value);
|
|
282
|
+
}
|
|
283
|
+
isFullUrl(path) {
|
|
284
|
+
return /^https?:\/\//.test(path);
|
|
285
|
+
}
|
|
286
|
+
buildImageUrl(key, path) {
|
|
287
|
+
const method = IMAGE_PATH_BUILDERS[key];
|
|
288
|
+
if (Object.hasOwn(this, method) || typeof this[method] !== "function") {}
|
|
289
|
+
return this[method](path);
|
|
290
|
+
}
|
|
291
|
+
transformPathValue(key, value, collectionKey) {
|
|
292
|
+
if (!value.startsWith("/") || this.isFullUrl(value)) return value;
|
|
293
|
+
if (Object.hasOwn(IMAGE_PATH_BUILDERS, key)) return this.buildImageUrl(key, value);
|
|
294
|
+
if (key === "file_path" && collectionKey) return this.buildImageUrl(IMAGE_COLLECTION_BUILDERS[collectionKey], value);
|
|
295
|
+
return value;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
//#endregion
|
|
149
299
|
//#region src/client.ts
|
|
150
300
|
var ApiClient = class {
|
|
151
301
|
accessToken;
|
|
152
|
-
baseUrl
|
|
302
|
+
baseUrl;
|
|
153
303
|
logger;
|
|
154
304
|
/**
|
|
155
305
|
* Tracks in-flight requests keyed by a deterministic string derived from the endpoint
|
|
@@ -162,14 +312,17 @@ var ApiClient = class {
|
|
|
162
312
|
requestInterceptors;
|
|
163
313
|
onSuccessInterceptor;
|
|
164
314
|
onErrorInterceptor;
|
|
315
|
+
imageApi;
|
|
165
316
|
constructor(accessToken, options = {}) {
|
|
166
317
|
this.accessToken = accessToken;
|
|
318
|
+
this.baseUrl = `https://api.themoviedb.org/${options.version ?? 3}`;
|
|
167
319
|
this.logger = TMDBLogger.from(options.logger);
|
|
168
320
|
this.deduplication = options.deduplication !== false;
|
|
169
321
|
const raw = options.interceptors?.request;
|
|
170
322
|
this.requestInterceptors = raw == null ? [] : Array.isArray(raw) ? raw : [raw];
|
|
171
323
|
this.onSuccessInterceptor = options.interceptors?.response?.onSuccess;
|
|
172
324
|
this.onErrorInterceptor = options.interceptors?.response?.onError;
|
|
325
|
+
this.imageApi = options.images?.autocomplete_paths ? new ImageAPI(options.images) : void 0;
|
|
173
326
|
}
|
|
174
327
|
/**
|
|
175
328
|
* Builds a stable, order-independent cache key for a request.
|
|
@@ -330,11 +483,12 @@ var ApiClient = class {
|
|
|
330
483
|
});
|
|
331
484
|
const data = await res.json();
|
|
332
485
|
const sanitized = this.sanitizeNulls(data);
|
|
486
|
+
const transformed = this.imageApi ? this.imageApi.autocompleteImagePaths(sanitized) : sanitized;
|
|
333
487
|
if (this.onSuccessInterceptor) {
|
|
334
|
-
const result = await this.onSuccessInterceptor(
|
|
335
|
-
return result !== void 0 ? result :
|
|
488
|
+
const result = await this.onSuccessInterceptor(transformed);
|
|
489
|
+
return result !== void 0 ? result : transformed;
|
|
336
490
|
}
|
|
337
|
-
return
|
|
491
|
+
return transformed;
|
|
338
492
|
}
|
|
339
493
|
};
|
|
340
494
|
//#endregion
|
|
@@ -509,6 +663,31 @@ const ENDPOINTS = {
|
|
|
509
663
|
REVIEWS: { DETAILS: "/review" },
|
|
510
664
|
PEOPLE_LISTS: { POPULAR: "/person/popular" }
|
|
511
665
|
};
|
|
666
|
+
/**
|
|
667
|
+
* TMDB API v4 endpoint fragments.
|
|
668
|
+
* These are combined with `https://api.themoviedb.org/4` by the v4 ApiClient.
|
|
669
|
+
*/
|
|
670
|
+
const ENDPOINTS_V4 = {
|
|
671
|
+
AUTH: {
|
|
672
|
+
REQUEST_TOKEN: "/auth/request_token",
|
|
673
|
+
ACCESS_TOKEN: "/auth/access_token"
|
|
674
|
+
},
|
|
675
|
+
ACCOUNT: {
|
|
676
|
+
DETAILS: "/account",
|
|
677
|
+
LISTS: "/lists",
|
|
678
|
+
FAVORITE_MOVIES: "/favorite/movies",
|
|
679
|
+
FAVORITE_TV: "/favorite/tv",
|
|
680
|
+
WATCHLIST_MOVIES: "/watchlist/movies",
|
|
681
|
+
WATCHLIST_TV: "/watchlist/tv",
|
|
682
|
+
RATED_MOVIES: "/rated/movies",
|
|
683
|
+
RATED_TV: "/rated/tv"
|
|
684
|
+
},
|
|
685
|
+
LISTS: {
|
|
686
|
+
DETAILS: "/list",
|
|
687
|
+
ITEMS: "/items",
|
|
688
|
+
ITEM_STATUS: "/item_status"
|
|
689
|
+
}
|
|
690
|
+
};
|
|
512
691
|
//#endregion
|
|
513
692
|
//#region src/errors/messages.ts
|
|
514
693
|
/**
|
|
@@ -517,7 +696,8 @@ const ENDPOINTS = {
|
|
|
517
696
|
*/
|
|
518
697
|
const Errors = {
|
|
519
698
|
NO_ACCESS_TOKEN: "TMDB requires a valid access token, please provide one.",
|
|
520
|
-
INVALID_CLIENT: "TMDB received an invalid ApiClient instance. Pass a valid ApiClient or an access token string."
|
|
699
|
+
INVALID_CLIENT: "TMDB received an invalid ApiClient instance. Pass a valid ApiClient or an access token string.",
|
|
700
|
+
V4_REQUIRES_JWT: "TMDB v4 requires a Bearer (JWT) access token. API key strings are not supported for v4 endpoints."
|
|
521
701
|
};
|
|
522
702
|
//#endregion
|
|
523
703
|
//#region src/endpoints/base.ts
|
|
@@ -1894,75 +2074,6 @@ var WatchProvidersAPI = class extends TMDBAPIBase {
|
|
|
1894
2074
|
}
|
|
1895
2075
|
};
|
|
1896
2076
|
//#endregion
|
|
1897
|
-
//#region src/types/config/images.ts
|
|
1898
|
-
const IMAGE_BASE_URL = "http://image.tmdb.org/t/p/";
|
|
1899
|
-
const IMAGE_SECURE_BASE_URL = "https://image.tmdb.org/t/p/";
|
|
1900
|
-
const BACKDROP_SIZES = [
|
|
1901
|
-
"w300",
|
|
1902
|
-
"w780",
|
|
1903
|
-
"w1280",
|
|
1904
|
-
"original"
|
|
1905
|
-
];
|
|
1906
|
-
const LOGO_SIZES = [
|
|
1907
|
-
"w45",
|
|
1908
|
-
"w92",
|
|
1909
|
-
"w154",
|
|
1910
|
-
"w185",
|
|
1911
|
-
"w300",
|
|
1912
|
-
"w500",
|
|
1913
|
-
"original"
|
|
1914
|
-
];
|
|
1915
|
-
const POSTER_SIZES = [
|
|
1916
|
-
"w92",
|
|
1917
|
-
"w154",
|
|
1918
|
-
"w185",
|
|
1919
|
-
"w342",
|
|
1920
|
-
"w500",
|
|
1921
|
-
"w780",
|
|
1922
|
-
"original"
|
|
1923
|
-
];
|
|
1924
|
-
const PROFILE_SIZES = [
|
|
1925
|
-
"w45",
|
|
1926
|
-
"w185",
|
|
1927
|
-
"h632",
|
|
1928
|
-
"original"
|
|
1929
|
-
];
|
|
1930
|
-
const STILL_SIZES = [
|
|
1931
|
-
"w92",
|
|
1932
|
-
"w185",
|
|
1933
|
-
"w300",
|
|
1934
|
-
"original"
|
|
1935
|
-
];
|
|
1936
|
-
//#endregion
|
|
1937
|
-
//#region src/images/images.ts
|
|
1938
|
-
var ImageAPI = class {
|
|
1939
|
-
options;
|
|
1940
|
-
constructor(options = {}) {
|
|
1941
|
-
this.options = {
|
|
1942
|
-
secure_images_url: true,
|
|
1943
|
-
...options
|
|
1944
|
-
};
|
|
1945
|
-
}
|
|
1946
|
-
buildUrl(path, size) {
|
|
1947
|
-
return `${this.options.secure_images_url ? IMAGE_SECURE_BASE_URL : IMAGE_BASE_URL}${size}${path}`;
|
|
1948
|
-
}
|
|
1949
|
-
backdrop(path, size = this.options.default_image_sizes?.backdrops || "w780") {
|
|
1950
|
-
return this.buildUrl(path, size);
|
|
1951
|
-
}
|
|
1952
|
-
logo(path, size = this.options.default_image_sizes?.logos || "w185") {
|
|
1953
|
-
return this.buildUrl(path, size);
|
|
1954
|
-
}
|
|
1955
|
-
poster(path, size = this.options.default_image_sizes?.posters || "w500") {
|
|
1956
|
-
return this.buildUrl(path, size);
|
|
1957
|
-
}
|
|
1958
|
-
profile(path, size = this.options.default_image_sizes?.profiles || "w185") {
|
|
1959
|
-
return this.buildUrl(path, size);
|
|
1960
|
-
}
|
|
1961
|
-
still(path, size = this.options.default_image_sizes?.still || "w300") {
|
|
1962
|
-
return this.buildUrl(path, size);
|
|
1963
|
-
}
|
|
1964
|
-
};
|
|
1965
|
-
//#endregion
|
|
1966
2077
|
//#region src/endpoints/networks.ts
|
|
1967
2078
|
var NetworksAPI = class extends TMDBAPIBase {
|
|
1968
2079
|
networkPath(network_id) {
|
|
@@ -2798,9 +2909,107 @@ var AuthenticationAPI = class extends TMDBAPIBase {
|
|
|
2798
2909
|
}
|
|
2799
2910
|
};
|
|
2800
2911
|
//#endregion
|
|
2912
|
+
//#region src/endpoints/v4/auth.ts
|
|
2913
|
+
var V4AuthAPI = class extends TMDBAPIBase {
|
|
2914
|
+
/**
|
|
2915
|
+
* Create Request Token
|
|
2916
|
+
* POST - https://api.themoviedb.org/4/auth/request_token
|
|
2917
|
+
*
|
|
2918
|
+
* Generate a request token that the user must approve at the TMDB website to begin
|
|
2919
|
+
* the v4 OAuth-style flow. Redirect the user to:
|
|
2920
|
+
* `https://www.themoviedb.org/auth/access?request_token={request_token}`
|
|
2921
|
+
*
|
|
2922
|
+
* Once approved, exchange the token for an access token using `create_access_token`.
|
|
2923
|
+
* @param body Optional body with a `redirect_to` URL for post-approval redirect.
|
|
2924
|
+
* @reference https://developer.themoviedb.org/reference/create-request-token
|
|
2925
|
+
*/
|
|
2926
|
+
async create_request_token(body) {
|
|
2927
|
+
return this.client.mutate("POST", ENDPOINTS_V4.AUTH.REQUEST_TOKEN, body ?? {});
|
|
2928
|
+
}
|
|
2929
|
+
/**
|
|
2930
|
+
* Create Access Token
|
|
2931
|
+
* POST - https://api.themoviedb.org/4/auth/access_token
|
|
2932
|
+
*
|
|
2933
|
+
* Exchange a user-approved request token for a permanent user access token and
|
|
2934
|
+
* TMDB account ID. Store the returned `access_token` securely — it is valid
|
|
2935
|
+
* indefinitely until explicitly deleted with `delete_access_token`.
|
|
2936
|
+
* @param body An object containing the approved `request_token`.
|
|
2937
|
+
* @reference https://developer.themoviedb.org/reference/create-access-token
|
|
2938
|
+
*/
|
|
2939
|
+
async create_access_token(body) {
|
|
2940
|
+
return this.client.mutate("POST", ENDPOINTS_V4.AUTH.ACCESS_TOKEN, body);
|
|
2941
|
+
}
|
|
2942
|
+
/**
|
|
2943
|
+
* Delete Access Token (Logout)
|
|
2944
|
+
* DELETE - https://api.themoviedb.org/4/auth/access_token
|
|
2945
|
+
*
|
|
2946
|
+
* Invalidate a user access token. Use this to log a user out of your application.
|
|
2947
|
+
* @param body An object containing the `access_token` to delete.
|
|
2948
|
+
* @reference https://developer.themoviedb.org/reference/delete-access-token
|
|
2949
|
+
*/
|
|
2950
|
+
async delete_access_token(body) {
|
|
2951
|
+
return this.client.mutate("DELETE", ENDPOINTS_V4.AUTH.ACCESS_TOKEN, body);
|
|
2952
|
+
}
|
|
2953
|
+
};
|
|
2954
|
+
//#endregion
|
|
2955
|
+
//#region src/endpoints/v4/account.ts
|
|
2956
|
+
var V4AccountAPI = class extends TMDBAPIBase {};
|
|
2957
|
+
//#endregion
|
|
2958
|
+
//#region src/endpoints/v4/lists.ts
|
|
2959
|
+
var V4ListsAPI = class extends TMDBAPIBase {};
|
|
2960
|
+
//#endregion
|
|
2961
|
+
//#region src/tmdb.v4.ts
|
|
2962
|
+
/**
|
|
2963
|
+
* Aggregator for all TMDB API v4 namespaces.
|
|
2964
|
+
*
|
|
2965
|
+
* Access via `tmdb.v4` — the v4 client is backed by `https://api.themoviedb.org/4`
|
|
2966
|
+
* and inherits the same access token and options as the parent TMDB instance.
|
|
2967
|
+
*
|
|
2968
|
+
* @example
|
|
2969
|
+
* ```ts
|
|
2970
|
+
* const tmdb = new TMDB(accessToken);
|
|
2971
|
+
*
|
|
2972
|
+
* // v4 auth flow
|
|
2973
|
+
* const { request_token } = await tmdb.v4.auth.create_request_token();
|
|
2974
|
+
* // ... user approves at https://www.themoviedb.org/auth/access?request_token=...
|
|
2975
|
+
* const { access_token, account_id } = await tmdb.v4.auth.create_access_token({ request_token });
|
|
2976
|
+
*
|
|
2977
|
+
* // v4 account (account_id is a string from the access token response)
|
|
2978
|
+
* const profile = await tmdb.v4.account.details(account_id);
|
|
2979
|
+
* const favorites = await tmdb.v4.account.favorite_movies({ account_id, page: 1 });
|
|
2980
|
+
*
|
|
2981
|
+
* // v4 lists (full CRUD)
|
|
2982
|
+
* const list = await tmdb.v4.lists.create({ name: "My list", iso_639_1: "en" });
|
|
2983
|
+
* await tmdb.v4.lists.add_items(list.id, { items: [{ media_type: "movie", media_id: 550 }] });
|
|
2984
|
+
* ```
|
|
2985
|
+
*/
|
|
2986
|
+
var TMDBv4 = class {
|
|
2987
|
+
client;
|
|
2988
|
+
/** v4 authentication — request token → access token → logout. */
|
|
2989
|
+
auth;
|
|
2990
|
+
/** v4 account — details, lists, favorites, watchlist, rated. */
|
|
2991
|
+
account;
|
|
2992
|
+
/** v4 lists — full CRUD for user-created lists. */
|
|
2993
|
+
lists;
|
|
2994
|
+
constructor(accessToken, options = {}) {
|
|
2995
|
+
if (!accessToken) throw new Error(Errors.NO_ACCESS_TOKEN);
|
|
2996
|
+
this.client = new ApiClient(accessToken, {
|
|
2997
|
+
version: 4,
|
|
2998
|
+
logger: options.logger,
|
|
2999
|
+
deduplication: options.deduplication,
|
|
3000
|
+
images: options.images,
|
|
3001
|
+
interceptors: options.interceptors
|
|
3002
|
+
});
|
|
3003
|
+
this.auth = new V4AuthAPI(this.client, options);
|
|
3004
|
+
this.account = new V4AccountAPI(this.client, options);
|
|
3005
|
+
this.lists = new V4ListsAPI(this.client, options);
|
|
3006
|
+
}
|
|
3007
|
+
};
|
|
3008
|
+
//#endregion
|
|
2801
3009
|
//#region src/tmdb.ts
|
|
2802
3010
|
var TMDB = class {
|
|
2803
3011
|
client;
|
|
3012
|
+
accessToken;
|
|
2804
3013
|
options;
|
|
2805
3014
|
movies;
|
|
2806
3015
|
movie_lists;
|
|
@@ -2830,16 +3039,28 @@ var TMDB = class {
|
|
|
2830
3039
|
account;
|
|
2831
3040
|
authentication;
|
|
2832
3041
|
/**
|
|
3042
|
+
* TMDB API v4 namespaces. Access via `tmdb.v4.auth`, `tmdb.v4.account`, `tmdb.v4.lists`.
|
|
3043
|
+
* Requires a Bearer (JWT) access token — throws if the instance was created with an API key.
|
|
3044
|
+
*/
|
|
3045
|
+
get v4() {
|
|
3046
|
+
if (!isJwt(this.accessToken)) throw new Error(Errors.V4_REQUIRES_JWT);
|
|
3047
|
+
if (!this._v4) this._v4 = new TMDBv4(this.accessToken, this.options);
|
|
3048
|
+
return this._v4;
|
|
3049
|
+
}
|
|
3050
|
+
_v4;
|
|
3051
|
+
/**
|
|
2833
3052
|
* Creates a new TMDB instance.
|
|
2834
3053
|
* @param accessToken The TMDB API access token.
|
|
2835
3054
|
* @param options Optional default options (e.g., language) for all requests.
|
|
2836
3055
|
*/
|
|
2837
3056
|
constructor(accessToken, options = {}) {
|
|
2838
3057
|
if (!accessToken) throw new Error(Errors.NO_ACCESS_TOKEN);
|
|
3058
|
+
this.accessToken = accessToken;
|
|
2839
3059
|
this.options = options;
|
|
2840
3060
|
this.client = new ApiClient(accessToken, {
|
|
2841
3061
|
logger: options.logger,
|
|
2842
3062
|
deduplication: options.deduplication,
|
|
3063
|
+
images: options.images,
|
|
2843
3064
|
interceptors: options.interceptors
|
|
2844
3065
|
});
|
|
2845
3066
|
this.movies = new MoviesAPI(this.client, this.options);
|
|
@@ -4187,4 +4408,4 @@ let TVEpisodeGroupType = /* @__PURE__ */ function(TVEpisodeGroupType) {
|
|
|
4187
4408
|
return TVEpisodeGroupType;
|
|
4188
4409
|
}({});
|
|
4189
4410
|
//#endregion
|
|
4190
|
-
export { AccountAPI, AuthenticationAPI, BACKDROP_SIZES, CertificationsAPI, ChangesAPI, CollectionsAPI, CompaniesAPI, ConfigurationAPI, CreditsAPI, DiscoverAPI, DiscoverTVStatus, DiscoverTVType, FindAPI, GenresAPI, IMAGE_BASE_URL, IMAGE_SECURE_BASE_URL, KeywordsAPI, LOGO_SIZES, MovieListsAPI, MoviesAPI, NetworksAPI, POSTER_SIZES, PROFILE_SIZES, PeopleAPI, PeopleListsAPI, ReviewsAPI, STILL_SIZES, SearchAPI, TMDB, TMDBCountries, TMDBError, TMDBLogger, TVEpisodeGroupType, TVEpisodeGroupsAPI, TVEpisodesAPI, TVSeasonsAPI, TVSeriesAPI, TVSeriesListsAPI, TrendingAPI, WatchProvidersAPI, hasBackdropPath, hasLogoPath, hasPosterPath, hasProfilePath, hasStillPath, isJwt, isKnownForMovie, isKnownForTV };
|
|
4411
|
+
export { AccountAPI, AuthenticationAPI, BACKDROP_SIZES, CertificationsAPI, ChangesAPI, CollectionsAPI, CompaniesAPI, ConfigurationAPI, CreditsAPI, DiscoverAPI, DiscoverTVStatus, DiscoverTVType, FindAPI, GenresAPI, IMAGE_BASE_URL, IMAGE_SECURE_BASE_URL, KeywordsAPI, LOGO_SIZES, MovieListsAPI, MoviesAPI, NetworksAPI, POSTER_SIZES, PROFILE_SIZES, PeopleAPI, PeopleListsAPI, ReviewsAPI, STILL_SIZES, SearchAPI, TMDB, TMDBCountries, TMDBError, TMDBLogger, TMDBv4, TVEpisodeGroupType, TVEpisodeGroupsAPI, TVEpisodesAPI, TVSeasonsAPI, TVSeriesAPI, TVSeriesListsAPI, TrendingAPI, V4AccountAPI, V4AuthAPI, V4ListsAPI, WatchProvidersAPI, hasBackdropPath, hasLogoPath, hasPosterPath, hasProfilePath, hasStillPath, isJwt, isKnownForMovie, isKnownForTV, isPlainObject, isRecord };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lorenzopant/tmdb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "A completely type-safe The Movie Database (TMDB) API wrapper for typescript applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -51,17 +51,15 @@
|
|
|
51
51
|
"typecheck": "tsc --noEmit"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/node": "^
|
|
55
|
-
"@vitest/coverage-v8": "^4.
|
|
56
|
-
"@vitest/ui": "^4.
|
|
54
|
+
"@types/node": "^25.5.0",
|
|
55
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
56
|
+
"@vitest/ui": "^4.1.2",
|
|
57
57
|
"dotenv": "^16.5.0",
|
|
58
|
-
"release-it": "^19.0.3",
|
|
59
|
-
"release-it-pnpm": "^4.6.6",
|
|
60
58
|
"ts-morph": "^27.0.2",
|
|
61
59
|
"tsdown": "^0.21.7",
|
|
62
60
|
"tsx": "^4.21.0",
|
|
63
61
|
"typescript": "^5.8.3",
|
|
64
|
-
"vite": "^
|
|
65
|
-
"vitest": "^4.
|
|
62
|
+
"vite": "^8.0.3",
|
|
63
|
+
"vitest": "^4.1.2"
|
|
66
64
|
}
|
|
67
65
|
}
|