@lorenzopant/tmdb 0.0.18 → 1.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/dist/images/images.d.ts +13 -0
- package/dist/images/images.d.ts.map +1 -0
- package/dist/images/images.js +26 -0
- package/dist/tests/images/images.test.d.ts +2 -0
- package/dist/tests/images/images.test.d.ts.map +1 -0
- package/dist/tests/images/images.test.js +43 -0
- package/dist/tmdb.d.ts +2 -0
- package/dist/tmdb.d.ts.map +1 -1
- package/dist/tmdb.js +3 -0
- package/dist/types/images.d.ts +14 -0
- package/dist/types/images.d.ts.map +1 -0
- package/dist/types/images.js +13 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/utility.d.ts +24 -0
- package/dist/types/utility.d.ts.map +1 -1
- package/package.json +1 -1
- package/vitest.config.mts +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ImagesConfig } from "../types";
|
|
2
|
+
import { BackdropSize, LogoSize, PosterSize, ProfileSize, StillSize } from "../types/images";
|
|
3
|
+
export declare class ImageAPI {
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options?: ImagesConfig);
|
|
6
|
+
private buildUrl;
|
|
7
|
+
backdrop(path: string, size?: BackdropSize): string;
|
|
8
|
+
logo(path: string, size?: LogoSize): string;
|
|
9
|
+
poster(path: string, size?: PosterSize): string;
|
|
10
|
+
profile(path: string, size?: ProfileSize): string;
|
|
11
|
+
still(path: string, size?: StillSize): string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../src/images/images.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,YAAY,EAAyC,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEpI,qBAAa,QAAQ;IACpB,OAAO,CAAC,OAAO,CAAe;gBAElB,OAAO,GAAE,YAAiB;IAItC,OAAO,CAAC,QAAQ;IAKT,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAoE,GAAG,MAAM;IAI1G,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,QAA4D,GAAG,MAAM;IAI9F,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,UAAgE,GAAG,MAAM;IAIpG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAkE,GAAG,MAAM;IAIvG,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,SAA6D,GAAG,MAAM;CAGvG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IMAGE_BASE_URL, IMAGE_SECURE_BASE_URL } from "../types/images";
|
|
2
|
+
export class ImageAPI {
|
|
3
|
+
options;
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.options = { secure_images_url: true, ...options };
|
|
6
|
+
}
|
|
7
|
+
buildUrl(path, size) {
|
|
8
|
+
const baseUrl = this.options.secure_images_url ? IMAGE_SECURE_BASE_URL : IMAGE_BASE_URL;
|
|
9
|
+
return `${baseUrl}${size}${path}`;
|
|
10
|
+
}
|
|
11
|
+
backdrop(path, size = this.options.default_image_sizes?.backdrops || "w780") {
|
|
12
|
+
return this.buildUrl(path, size);
|
|
13
|
+
}
|
|
14
|
+
logo(path, size = this.options.default_image_sizes?.logos || "w185") {
|
|
15
|
+
return this.buildUrl(path, size);
|
|
16
|
+
}
|
|
17
|
+
poster(path, size = this.options.default_image_sizes?.posters || "w500") {
|
|
18
|
+
return this.buildUrl(path, size);
|
|
19
|
+
}
|
|
20
|
+
profile(path, size = this.options.default_image_sizes?.profiles || "w185") {
|
|
21
|
+
return this.buildUrl(path, size);
|
|
22
|
+
}
|
|
23
|
+
still(path, size = this.options.default_image_sizes?.still || "w300") {
|
|
24
|
+
return this.buildUrl(path, size);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"images.test.d.ts","sourceRoot":"","sources":["../../../src/tests/images/images.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { IMAGE_SECURE_BASE_URL, IMAGE_BASE_URL } from "../../types/images";
|
|
3
|
+
import { ImageAPI } from "../../images/images";
|
|
4
|
+
describe("ImageAPI", () => {
|
|
5
|
+
const path = "/sample.jpg";
|
|
6
|
+
test("should generate secure poster URL by default", () => {
|
|
7
|
+
const imageAPI = new ImageAPI();
|
|
8
|
+
const poster_path = "/1E5baAaEse26fej7uHcjOgEE2t2.jpg"; // Fast X
|
|
9
|
+
const url = imageAPI.poster(poster_path);
|
|
10
|
+
expect(url).toBe(`${IMAGE_SECURE_BASE_URL}w500${poster_path}`);
|
|
11
|
+
});
|
|
12
|
+
test("should generate non-secure poster URL when configured", () => {
|
|
13
|
+
const poster_path = "/1E5baAaEse26fej7uHcjOgEE2t2.jpg"; // Fast X
|
|
14
|
+
const imageAPI = new ImageAPI({ secure_images_url: false });
|
|
15
|
+
const url = imageAPI.poster(poster_path);
|
|
16
|
+
expect(url).toBe(`${IMAGE_BASE_URL}w500${poster_path}`);
|
|
17
|
+
});
|
|
18
|
+
test("should use default image sizes if defined", () => {
|
|
19
|
+
const imageAPI = new ImageAPI({ default_image_sizes: { posters: "original" } });
|
|
20
|
+
const url = imageAPI.poster(path);
|
|
21
|
+
expect(url).toBe(`${IMAGE_SECURE_BASE_URL}original${path}`);
|
|
22
|
+
});
|
|
23
|
+
test("should generate backdrop URL", () => {
|
|
24
|
+
const imageAPI = new ImageAPI();
|
|
25
|
+
const url = imageAPI.backdrop(path, "w1280");
|
|
26
|
+
expect(url).toBe(`${IMAGE_SECURE_BASE_URL}w1280${path}`);
|
|
27
|
+
});
|
|
28
|
+
test("should generate logo URL", () => {
|
|
29
|
+
const imageAPI = new ImageAPI();
|
|
30
|
+
const url = imageAPI.logo(path, "w300");
|
|
31
|
+
expect(url).toBe(`${IMAGE_SECURE_BASE_URL}w300${path}`);
|
|
32
|
+
});
|
|
33
|
+
test("should generate profile URL", () => {
|
|
34
|
+
const imageAPI = new ImageAPI();
|
|
35
|
+
const url = imageAPI.profile(path, "h632");
|
|
36
|
+
expect(url).toBe(`${IMAGE_SECURE_BASE_URL}h632${path}`);
|
|
37
|
+
});
|
|
38
|
+
test("should generate still URL", () => {
|
|
39
|
+
const imageAPI = new ImageAPI();
|
|
40
|
+
const url = imageAPI.still(path, "w300");
|
|
41
|
+
expect(url).toBe(`${IMAGE_SECURE_BASE_URL}w300${path}`);
|
|
42
|
+
});
|
|
43
|
+
});
|
package/dist/tmdb.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MovieListsAPI } from "./endpoints/movie_lists";
|
|
2
2
|
import { MoviesAPI } from "./endpoints/movies";
|
|
3
3
|
import { SearchAPI } from "./endpoints/search";
|
|
4
|
+
import { ImageAPI } from "./images/images";
|
|
4
5
|
import { TMDBOptions } from "./types";
|
|
5
6
|
export declare class TMDB {
|
|
6
7
|
private client;
|
|
@@ -8,6 +9,7 @@ export declare class TMDB {
|
|
|
8
9
|
movies: MoviesAPI;
|
|
9
10
|
movie_lists: MovieListsAPI;
|
|
10
11
|
search: SearchAPI;
|
|
12
|
+
images: ImageAPI;
|
|
11
13
|
/**
|
|
12
14
|
* Creates a new TMDB instance.
|
|
13
15
|
* @param accessToken The TMDB API access token.
|
package/dist/tmdb.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tmdb.d.ts","sourceRoot":"","sources":["../src/tmdb.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,IAAI;IAChB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,OAAO,CAAc;IACtB,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,EAAE,aAAa,CAAC;IAC3B,MAAM,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"tmdb.d.ts","sourceRoot":"","sources":["../src/tmdb.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,IAAI;IAChB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,OAAO,CAAc;IACtB,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,EAAE,aAAa,CAAC;IAC3B,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,QAAQ,CAAC;IAGxB;;;;OAIG;gBACS,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB;CAS1D"}
|
package/dist/tmdb.js
CHANGED
|
@@ -4,12 +4,14 @@ import { MovieListsAPI } from "./endpoints/movie_lists";
|
|
|
4
4
|
import { MoviesAPI } from "./endpoints/movies";
|
|
5
5
|
import { SearchAPI } from "./endpoints/search";
|
|
6
6
|
import { Errors } from "./errors/messages";
|
|
7
|
+
import { ImageAPI } from "./images/images";
|
|
7
8
|
export class TMDB {
|
|
8
9
|
client;
|
|
9
10
|
options; // ** Default options for all requests
|
|
10
11
|
movies;
|
|
11
12
|
movie_lists;
|
|
12
13
|
search;
|
|
14
|
+
images;
|
|
13
15
|
// etc...
|
|
14
16
|
/**
|
|
15
17
|
* Creates a new TMDB instance.
|
|
@@ -24,5 +26,6 @@ export class TMDB {
|
|
|
24
26
|
this.movies = new MoviesAPI(this.client, this.options);
|
|
25
27
|
this.movie_lists = new MovieListsAPI(this.client, this.options);
|
|
26
28
|
this.search = new SearchAPI(this.client, this.options);
|
|
29
|
+
this.images = new ImageAPI(this.options.images);
|
|
27
30
|
}
|
|
28
31
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const IMAGE_BASE_URL = "http://image.tmdb.org/t/p/";
|
|
2
|
+
export declare const IMAGE_SECURE_BASE_URL = "https://image.tmdb.org/t/p/";
|
|
3
|
+
export declare const BACKDROP_SIZES: readonly ["w300", "w780", "w1280", "original"];
|
|
4
|
+
export type BackdropSize = (typeof BACKDROP_SIZES)[number];
|
|
5
|
+
export declare const LOGO_SIZES: readonly ["w45", "w92", "w154", "w185", "w300", "w500", "original"];
|
|
6
|
+
export type LogoSize = (typeof LOGO_SIZES)[number];
|
|
7
|
+
export declare const POSTER_SIZES: readonly ["w92", "w154", "w185", "w342", "w500", "w780", "original"];
|
|
8
|
+
export type PosterSize = (typeof POSTER_SIZES)[number];
|
|
9
|
+
export declare const PROFILE_SIZES: readonly ["w45", "w185", "h632", "original"];
|
|
10
|
+
export type ProfileSize = (typeof PROFILE_SIZES)[number];
|
|
11
|
+
export declare const STILL_SIZES: readonly ["w92", "w185", "w300", "original"];
|
|
12
|
+
export type StillSize = (typeof STILL_SIZES)[number];
|
|
13
|
+
export type ImageSize = BackdropSize | LogoSize | PosterSize | ProfileSize | StillSize;
|
|
14
|
+
//# sourceMappingURL=images.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"images.d.ts","sourceRoot":"","sources":["../../src/types/images.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,+BAA+B,CAAC;AAC3D,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AAGnE,eAAO,MAAM,cAAc,gDAAiD,CAAC;AAC7E,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAG3D,eAAO,MAAM,UAAU,qEAAsE,CAAC;AAC9F,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAGnD,eAAO,MAAM,YAAY,sEAAuE,CAAC;AACjG,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAGvD,eAAO,MAAM,aAAa,8CAA+C,CAAC;AAC1E,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAGzD,eAAO,MAAM,WAAW,8CAA+C,CAAC;AACxE,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAGrD,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Image base URLs
|
|
2
|
+
export const IMAGE_BASE_URL = "http://image.tmdb.org/t/p/";
|
|
3
|
+
export const IMAGE_SECURE_BASE_URL = "https://image.tmdb.org/t/p/";
|
|
4
|
+
// Backdrop sizes
|
|
5
|
+
export const BACKDROP_SIZES = ["w300", "w780", "w1280", "original"];
|
|
6
|
+
// Logo sizes
|
|
7
|
+
export const LOGO_SIZES = ["w45", "w92", "w154", "w185", "w300", "w500", "original"];
|
|
8
|
+
// Poster sizes
|
|
9
|
+
export const POSTER_SIZES = ["w92", "w154", "w185", "w342", "w500", "w780", "original"];
|
|
10
|
+
// Profile sizes
|
|
11
|
+
export const PROFILE_SIZES = ["w45", "w185", "h632", "original"];
|
|
12
|
+
// Still sizes
|
|
13
|
+
export const STILL_SIZES = ["w92", "w185", "w300", "original"];
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
package/dist/types/index.js
CHANGED
package/dist/types/utility.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CountryISO3166_1 } from "./countries";
|
|
2
|
+
import { BackdropSize, LogoSize, PosterSize, ProfileSize, StillSize } from "./images";
|
|
2
3
|
import { LanguageISO6391 } from "./lang";
|
|
3
4
|
export type TMDBOptions = {
|
|
4
5
|
/**
|
|
@@ -13,5 +14,28 @@ export type TMDBOptions = {
|
|
|
13
14
|
* If not set, TMDB may fall back to a default or global data.
|
|
14
15
|
*/
|
|
15
16
|
region?: CountryISO3166_1;
|
|
17
|
+
/**
|
|
18
|
+
* Provide images default configuration
|
|
19
|
+
*/
|
|
20
|
+
images?: ImagesConfig;
|
|
21
|
+
};
|
|
22
|
+
export type ImagesConfig = {
|
|
23
|
+
/**
|
|
24
|
+
* Whether to use the secure (HTTPS) image base URL.
|
|
25
|
+
* Defaults to true. Set to false only if working in an environment where HTTPS is not supported
|
|
26
|
+
* or where you explicitly need non-secure image URLs.
|
|
27
|
+
*/
|
|
28
|
+
secure_images_url?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Provide default image size configuration for each type of images.
|
|
31
|
+
*/
|
|
32
|
+
default_image_sizes?: Partial<DefaultImageSizesConfig>;
|
|
33
|
+
};
|
|
34
|
+
export type DefaultImageSizesConfig = {
|
|
35
|
+
posters?: PosterSize;
|
|
36
|
+
backdrops?: BackdropSize;
|
|
37
|
+
logos?: LogoSize;
|
|
38
|
+
profiles?: ProfileSize;
|
|
39
|
+
still?: StillSize;
|
|
16
40
|
};
|
|
17
41
|
//# sourceMappingURL=utility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../src/types/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../src/types/utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAC1B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACrC,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC"}
|
package/package.json
CHANGED
package/vitest.config.mts
CHANGED
|
@@ -8,6 +8,7 @@ export default defineConfig({
|
|
|
8
8
|
coverage: {
|
|
9
9
|
enabled: true,
|
|
10
10
|
reporter: ["text", "json", "html", "clover"],
|
|
11
|
+
exclude: ["src/types/**", "dist/**", "vitest.config.mts", "eslint.config.mjs", ".eslintrc.js", "src/index.ts"],
|
|
11
12
|
},
|
|
12
13
|
setupFiles: ["dotenv/config"],
|
|
13
14
|
env: loadEnv(process.cwd(), ""),
|