@lorenzopant/tmdb 1.18.0 → 1.18.1

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 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
@@ -3367,9 +3375,11 @@ declare class ApiClient {
3367
3375
  private requestInterceptors;
3368
3376
  private onSuccessInterceptor?;
3369
3377
  private onErrorInterceptor?;
3378
+ private imageApi?;
3370
3379
  constructor(accessToken: string, options?: {
3371
3380
  logger?: boolean | TMDBLoggerFn;
3372
3381
  deduplication?: boolean;
3382
+ images?: ImagesConfig;
3373
3383
  interceptors?: {
3374
3384
  request?: RequestInterceptor | RequestInterceptor[];
3375
3385
  response?: {
@@ -4459,6 +4469,26 @@ declare class ImageAPI {
4459
4469
  poster(path: string, size?: PosterSize): string;
4460
4470
  profile(path: string, size?: ProfileSize): string;
4461
4471
  still(path: string, size?: StillSize): string;
4472
+ /**
4473
+ * Recursively processes an object or array to autocomplete image paths by transforming string values
4474
+ * and tracking the current image collection context.
4475
+ *
4476
+ * @template T - The type of the value being processed
4477
+ * @param value - The value to process (can be an object, array, string, or primitive)
4478
+ * @param collectionKey - Optional image collection key to maintain context during recursion
4479
+ * @returns The processed value with autocompleted image paths, maintaining the original type
4480
+ *
4481
+ * @remarks
4482
+ * - Arrays are recursively mapped over each entry
4483
+ * - String values are transformed using {@link transformPathValue}
4484
+ * - Object keys that match image collection keys update the collection context
4485
+ * - Non-plain objects (e.g. Date/class instances) are returned unchanged
4486
+ */
4487
+ autocompleteImagePaths<T>(value: T, collectionKey?: ImageCollectionKey): T;
4488
+ private isImageCollectionKey;
4489
+ private isFullUrl;
4490
+ private buildImageUrl;
4491
+ private transformPathValue;
4462
4492
  }
4463
4493
  //#endregion
4464
4494
  //#region src/endpoints/networks.d.ts
@@ -5121,7 +5151,18 @@ declare class TMDB {
5121
5151
  //#region src/utils/jwt.d.ts
5122
5152
  declare function isJwt(token: string): boolean;
5123
5153
  //#endregion
5124
- //#region src/utils/index.d.ts
5154
+ //#region src/utils/types.d.ts
5155
+ /**
5156
+ * Typeguard that checks if a value is a record object.
5157
+ * @param value - The value to check
5158
+ * @returns `true` if the value is a non-null object that is not an array, `false` otherwise
5159
+ */
5160
+ declare function isRecord(value: unknown): value is Record<string, unknown>;
5161
+ /**
5162
+ * Typeguard that checks whether a value is a plain object.
5163
+ * Plain objects are objects whose prototype is `Object.prototype` or `null`.
5164
+ */
5165
+ declare function isPlainObject(value: unknown): value is Record<string, unknown>;
5125
5166
  /** Utility type guard to check if an object has a poster_path property */
5126
5167
  declare function hasPosterPath(data: unknown): data is {
5127
5168
  poster_path: string;
@@ -5143,4 +5184,4 @@ declare function hasLogoPath(data: unknown): data is {
5143
5184
  logo_path: string;
5144
5185
  };
5145
5186
  //#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 };
5187
+ 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, 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/index.ts
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,6 +203,99 @@ 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;
@@ -162,6 +312,7 @@ var ApiClient = class {
162
312
  requestInterceptors;
163
313
  onSuccessInterceptor;
164
314
  onErrorInterceptor;
315
+ imageApi;
165
316
  constructor(accessToken, options = {}) {
166
317
  this.accessToken = accessToken;
167
318
  this.logger = TMDBLogger.from(options.logger);
@@ -170,6 +321,7 @@ var ApiClient = class {
170
321
  this.requestInterceptors = raw == null ? [] : Array.isArray(raw) ? raw : [raw];
171
322
  this.onSuccessInterceptor = options.interceptors?.response?.onSuccess;
172
323
  this.onErrorInterceptor = options.interceptors?.response?.onError;
324
+ this.imageApi = options.images?.autocomplete_paths ? new ImageAPI(options.images) : void 0;
173
325
  }
174
326
  /**
175
327
  * Builds a stable, order-independent cache key for a request.
@@ -330,11 +482,12 @@ var ApiClient = class {
330
482
  });
331
483
  const data = await res.json();
332
484
  const sanitized = this.sanitizeNulls(data);
485
+ const transformed = this.imageApi ? this.imageApi.autocompleteImagePaths(sanitized) : sanitized;
333
486
  if (this.onSuccessInterceptor) {
334
- const result = await this.onSuccessInterceptor(sanitized);
335
- return result !== void 0 ? result : sanitized;
487
+ const result = await this.onSuccessInterceptor(transformed);
488
+ return result !== void 0 ? result : transformed;
336
489
  }
337
- return sanitized;
490
+ return transformed;
338
491
  }
339
492
  };
340
493
  //#endregion
@@ -1894,75 +2047,6 @@ var WatchProvidersAPI = class extends TMDBAPIBase {
1894
2047
  }
1895
2048
  };
1896
2049
  //#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
2050
  //#region src/endpoints/networks.ts
1967
2051
  var NetworksAPI = class extends TMDBAPIBase {
1968
2052
  networkPath(network_id) {
@@ -2840,6 +2924,7 @@ var TMDB = class {
2840
2924
  this.client = new ApiClient(accessToken, {
2841
2925
  logger: options.logger,
2842
2926
  deduplication: options.deduplication,
2927
+ images: options.images,
2843
2928
  interceptors: options.interceptors
2844
2929
  });
2845
2930
  this.movies = new MoviesAPI(this.client, this.options);
@@ -4187,4 +4272,4 @@ let TVEpisodeGroupType = /* @__PURE__ */ function(TVEpisodeGroupType) {
4187
4272
  return TVEpisodeGroupType;
4188
4273
  }({});
4189
4274
  //#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 };
4275
+ 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, isPlainObject, isRecord };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lorenzopant/tmdb",
3
- "version": "1.18.0",
3
+ "version": "1.18.1",
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": "^22.19.11",
55
- "@vitest/coverage-v8": "^4.0.9",
56
- "@vitest/ui": "^4.0.10",
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": "^7.0.0",
65
- "vitest": "^4.0.9"
62
+ "vite": "^8.0.3",
63
+ "vitest": "^4.1.2"
66
64
  }
67
65
  }