tmdb-kit 0.1.0-beta.4 → 1.1.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/README.md +293 -198
- package/dist/cli.js +3132 -0
- package/dist/client.d.cts +63 -0
- package/dist/client.d.ts +63 -0
- package/dist/errors.d.cts +74 -0
- package/dist/errors.d.ts +74 -0
- package/dist/http.d.cts +80 -0
- package/dist/http.d.ts +80 -0
- package/dist/index.cjs +747 -768
- package/dist/index.cjs.map +23 -1
- package/dist/index.d.cts +8 -783
- package/dist/index.d.ts +8 -783
- package/dist/index.js +707 -745
- package/dist/index.js.map +23 -1
- package/dist/query.d.cts +77 -0
- package/dist/query.d.ts +77 -0
- package/dist/resources/configuration.d.cts +17 -0
- package/dist/resources/configuration.d.ts +17 -0
- package/dist/resources/genres.d.cts +13 -0
- package/dist/resources/genres.d.ts +13 -0
- package/dist/resources/images.d.cts +17 -0
- package/dist/resources/images.d.ts +17 -0
- package/dist/resources/movies.d.cts +21 -0
- package/dist/resources/movies.d.ts +21 -0
- package/dist/resources/people.d.cts +14 -0
- package/dist/resources/people.d.ts +14 -0
- package/dist/resources/search.d.cts +15 -0
- package/dist/resources/search.d.ts +15 -0
- package/dist/resources/trending.d.cts +23 -0
- package/dist/resources/trending.d.ts +23 -0
- package/dist/resources/tv.d.cts +22 -0
- package/dist/resources/tv.d.ts +22 -0
- package/dist/search-guards.d.cts +32 -0
- package/dist/search-guards.d.ts +32 -0
- package/dist/types.d.cts +452 -0
- package/dist/types.d.ts +452 -0
- package/package.json +26 -19
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type TMDBClientOptions, type TMDBRequestOptions, type TMDBTransport } from './http.cjs';
|
|
2
|
+
import { ConfigurationResource } from './resources/configuration.cjs';
|
|
3
|
+
import { GenresResource } from './resources/genres.cjs';
|
|
4
|
+
import { ImagesHelper } from './resources/images.cjs';
|
|
5
|
+
import { MoviesResource } from './resources/movies.cjs';
|
|
6
|
+
import { PeopleResource } from './resources/people.cjs';
|
|
7
|
+
import { SearchResource } from './resources/search.cjs';
|
|
8
|
+
import { TrendingResource } from './resources/trending.cjs';
|
|
9
|
+
import { TVResource } from './resources/tv.cjs';
|
|
10
|
+
/**
|
|
11
|
+
* Options accepted by {@link createTMDB} and the {@link TMDBClient} constructor.
|
|
12
|
+
*
|
|
13
|
+
* Extends {@link TMDBClientOptions} with an optional {@link TMDBTransport} so
|
|
14
|
+
* callers can plug in a custom transport (typically for tests, caching, or
|
|
15
|
+
* instrumentation) without having to mock `fetch` or the factory itself.
|
|
16
|
+
*/
|
|
17
|
+
export type TMDBFactoryOptions = TMDBClientOptions & {
|
|
18
|
+
transport?: TMDBTransport;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Main SDK entry point.
|
|
22
|
+
*
|
|
23
|
+
* Resource properties are intentionally small and explicit. The SDK focuses on
|
|
24
|
+
* common TMDB workflows first, while request<T>() keeps uncommon endpoints easy
|
|
25
|
+
* to call without waiting for a generated surface area.
|
|
26
|
+
*/
|
|
27
|
+
export declare class TMDBClient {
|
|
28
|
+
#private;
|
|
29
|
+
readonly configuration: ConfigurationResource;
|
|
30
|
+
readonly genres: GenresResource;
|
|
31
|
+
readonly images: ImagesHelper;
|
|
32
|
+
readonly movies: MoviesResource;
|
|
33
|
+
readonly people: PeopleResource;
|
|
34
|
+
readonly search: SearchResource;
|
|
35
|
+
readonly trending: TrendingResource;
|
|
36
|
+
readonly tv: TVResource;
|
|
37
|
+
constructor(options: TMDBFactoryOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Make a raw GET request to any TMDB endpoint.
|
|
40
|
+
*
|
|
41
|
+
* This is an escape hatch for endpoints not covered by the typed resource
|
|
42
|
+
* helpers. The `path` should be relative to the API base URL (e.g.
|
|
43
|
+
* `/movie/{id}/credits`). Response is parsed as JSON and cast to `T`.
|
|
44
|
+
*
|
|
45
|
+
* @param path - API path relative to the base URL (e.g. `/movie/123`)
|
|
46
|
+
* @param options - Optional request-level overrides (headers, query, signal)
|
|
47
|
+
* @returns Parsed JSON response typed as `T`
|
|
48
|
+
*/
|
|
49
|
+
request<T>(path: string, options?: TMDBRequestOptions): Promise<T>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a new {@link TMDBClient} instance.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const tmdb = createTMDB({ accessToken: 'YOUR_TOKEN' })
|
|
57
|
+
* const { results } = await tmdb.search.movies('Inception')
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param options - Authentication and configuration options
|
|
61
|
+
* @returns A configured TMDBClient ready to make API calls
|
|
62
|
+
*/
|
|
63
|
+
export declare function createTMDB(options: TMDBFactoryOptions): TMDBClient;
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type TMDBClientOptions, type TMDBRequestOptions, type TMDBTransport } from './http.js';
|
|
2
|
+
import { ConfigurationResource } from './resources/configuration.js';
|
|
3
|
+
import { GenresResource } from './resources/genres.js';
|
|
4
|
+
import { ImagesHelper } from './resources/images.js';
|
|
5
|
+
import { MoviesResource } from './resources/movies.js';
|
|
6
|
+
import { PeopleResource } from './resources/people.js';
|
|
7
|
+
import { SearchResource } from './resources/search.js';
|
|
8
|
+
import { TrendingResource } from './resources/trending.js';
|
|
9
|
+
import { TVResource } from './resources/tv.js';
|
|
10
|
+
/**
|
|
11
|
+
* Options accepted by {@link createTMDB} and the {@link TMDBClient} constructor.
|
|
12
|
+
*
|
|
13
|
+
* Extends {@link TMDBClientOptions} with an optional {@link TMDBTransport} so
|
|
14
|
+
* callers can plug in a custom transport (typically for tests, caching, or
|
|
15
|
+
* instrumentation) without having to mock `fetch` or the factory itself.
|
|
16
|
+
*/
|
|
17
|
+
export type TMDBFactoryOptions = TMDBClientOptions & {
|
|
18
|
+
transport?: TMDBTransport;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Main SDK entry point.
|
|
22
|
+
*
|
|
23
|
+
* Resource properties are intentionally small and explicit. The SDK focuses on
|
|
24
|
+
* common TMDB workflows first, while request<T>() keeps uncommon endpoints easy
|
|
25
|
+
* to call without waiting for a generated surface area.
|
|
26
|
+
*/
|
|
27
|
+
export declare class TMDBClient {
|
|
28
|
+
#private;
|
|
29
|
+
readonly configuration: ConfigurationResource;
|
|
30
|
+
readonly genres: GenresResource;
|
|
31
|
+
readonly images: ImagesHelper;
|
|
32
|
+
readonly movies: MoviesResource;
|
|
33
|
+
readonly people: PeopleResource;
|
|
34
|
+
readonly search: SearchResource;
|
|
35
|
+
readonly trending: TrendingResource;
|
|
36
|
+
readonly tv: TVResource;
|
|
37
|
+
constructor(options: TMDBFactoryOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Make a raw GET request to any TMDB endpoint.
|
|
40
|
+
*
|
|
41
|
+
* This is an escape hatch for endpoints not covered by the typed resource
|
|
42
|
+
* helpers. The `path` should be relative to the API base URL (e.g.
|
|
43
|
+
* `/movie/{id}/credits`). Response is parsed as JSON and cast to `T`.
|
|
44
|
+
*
|
|
45
|
+
* @param path - API path relative to the base URL (e.g. `/movie/123`)
|
|
46
|
+
* @param options - Optional request-level overrides (headers, query, signal)
|
|
47
|
+
* @returns Parsed JSON response typed as `T`
|
|
48
|
+
*/
|
|
49
|
+
request<T>(path: string, options?: TMDBRequestOptions): Promise<T>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a new {@link TMDBClient} instance.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const tmdb = createTMDB({ accessToken: 'YOUR_TOKEN' })
|
|
57
|
+
* const { results } = await tmdb.search.movies('Inception')
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param options - Authentication and configuration options
|
|
61
|
+
* @returns A configured TMDBClient ready to make API calls
|
|
62
|
+
*/
|
|
63
|
+
export declare function createTMDB(options: TMDBFactoryOptions): TMDBClient;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { JsonValue } from './types.cjs';
|
|
2
|
+
/** Raw TMDB error response body structure. */
|
|
3
|
+
export interface TMDBErrorResponseBody {
|
|
4
|
+
success?: boolean;
|
|
5
|
+
status_code?: number;
|
|
6
|
+
status_message?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Options for constructing a {@link TMDBResponseError} or its subclasses. */
|
|
9
|
+
export interface TMDBResponseErrorOptions {
|
|
10
|
+
body: JsonValue | undefined;
|
|
11
|
+
headers: Headers;
|
|
12
|
+
status: number;
|
|
13
|
+
statusText: string;
|
|
14
|
+
url: string;
|
|
15
|
+
}
|
|
16
|
+
/** Base class for all SDK-originated errors. */
|
|
17
|
+
export declare class TMDBError extends Error {
|
|
18
|
+
constructor(message: string, options?: ErrorOptions);
|
|
19
|
+
}
|
|
20
|
+
/** Thrown before a request is sent or when fetch itself rejects. */
|
|
21
|
+
export declare class TMDBRequestError extends TMDBError {
|
|
22
|
+
constructor(message: string, options?: ErrorOptions);
|
|
23
|
+
}
|
|
24
|
+
/** Thrown when TMDB returns a non-2xx response. */
|
|
25
|
+
export declare class TMDBResponseError extends TMDBError {
|
|
26
|
+
readonly body: JsonValue | undefined;
|
|
27
|
+
readonly headers: Headers;
|
|
28
|
+
readonly requestId: string | null;
|
|
29
|
+
readonly status: number;
|
|
30
|
+
readonly statusCode: number | undefined;
|
|
31
|
+
readonly statusMessage: string | undefined;
|
|
32
|
+
readonly statusText: string;
|
|
33
|
+
readonly url: string;
|
|
34
|
+
constructor(message: string, options: TMDBResponseErrorOptions);
|
|
35
|
+
/** True when TMDB has asked the caller to back off (HTTP 429). */
|
|
36
|
+
get isRateLimit(): boolean;
|
|
37
|
+
/** True when the resource was not found (HTTP 404). */
|
|
38
|
+
get isNotFound(): boolean;
|
|
39
|
+
/** True when the request was rejected as unauthenticated (HTTP 401). */
|
|
40
|
+
get isUnauthorized(): boolean;
|
|
41
|
+
/** True when the request was rejected as forbidden (HTTP 403). */
|
|
42
|
+
get isForbidden(): boolean;
|
|
43
|
+
/** True when the upstream returned a 5xx server error. */
|
|
44
|
+
get isServerError(): boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface TMDBRateLimitErrorOptions extends TMDBResponseErrorOptions {
|
|
47
|
+
/** Seconds to wait before retrying. Parsed from the `Retry-After` header. */
|
|
48
|
+
retryAfter: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Thrown when TMDB returns HTTP 429.
|
|
52
|
+
*
|
|
53
|
+
* The SDK does NOT retry automatically — that decision is left to the
|
|
54
|
+
* caller, since retry policies vary widely. Inspect `retryAfter` to
|
|
55
|
+
* implement your own backoff.
|
|
56
|
+
*/
|
|
57
|
+
export declare class TMDBRateLimitError extends TMDBResponseError {
|
|
58
|
+
readonly retryAfter: number;
|
|
59
|
+
constructor(message: string, options: TMDBRateLimitErrorOptions);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create the appropriate error instance for a non-2xx TMDB response.
|
|
63
|
+
*
|
|
64
|
+
* Returns a {@link TMDBRateLimitError} when the status is 429, otherwise
|
|
65
|
+
* a generic {@link TMDBResponseError}. The error message is extracted from
|
|
66
|
+
* the TMDB `status_message` field when available.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createResponseError(options: TMDBResponseErrorOptions): TMDBResponseError;
|
|
69
|
+
/**
|
|
70
|
+
* Parse the `Retry-After` header into seconds. Accepts both delta-seconds
|
|
71
|
+
* (e.g. "5") and HTTP-date forms (e.g. "Wed, 21 Oct 2026 07:28:00 GMT").
|
|
72
|
+
* Falls back to 1 second when the header is missing or unparseable.
|
|
73
|
+
*/
|
|
74
|
+
export declare function parseRetryAfter(value: string | null | undefined): number;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { JsonValue } from './types.js';
|
|
2
|
+
/** Raw TMDB error response body structure. */
|
|
3
|
+
export interface TMDBErrorResponseBody {
|
|
4
|
+
success?: boolean;
|
|
5
|
+
status_code?: number;
|
|
6
|
+
status_message?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Options for constructing a {@link TMDBResponseError} or its subclasses. */
|
|
9
|
+
export interface TMDBResponseErrorOptions {
|
|
10
|
+
body: JsonValue | undefined;
|
|
11
|
+
headers: Headers;
|
|
12
|
+
status: number;
|
|
13
|
+
statusText: string;
|
|
14
|
+
url: string;
|
|
15
|
+
}
|
|
16
|
+
/** Base class for all SDK-originated errors. */
|
|
17
|
+
export declare class TMDBError extends Error {
|
|
18
|
+
constructor(message: string, options?: ErrorOptions);
|
|
19
|
+
}
|
|
20
|
+
/** Thrown before a request is sent or when fetch itself rejects. */
|
|
21
|
+
export declare class TMDBRequestError extends TMDBError {
|
|
22
|
+
constructor(message: string, options?: ErrorOptions);
|
|
23
|
+
}
|
|
24
|
+
/** Thrown when TMDB returns a non-2xx response. */
|
|
25
|
+
export declare class TMDBResponseError extends TMDBError {
|
|
26
|
+
readonly body: JsonValue | undefined;
|
|
27
|
+
readonly headers: Headers;
|
|
28
|
+
readonly requestId: string | null;
|
|
29
|
+
readonly status: number;
|
|
30
|
+
readonly statusCode: number | undefined;
|
|
31
|
+
readonly statusMessage: string | undefined;
|
|
32
|
+
readonly statusText: string;
|
|
33
|
+
readonly url: string;
|
|
34
|
+
constructor(message: string, options: TMDBResponseErrorOptions);
|
|
35
|
+
/** True when TMDB has asked the caller to back off (HTTP 429). */
|
|
36
|
+
get isRateLimit(): boolean;
|
|
37
|
+
/** True when the resource was not found (HTTP 404). */
|
|
38
|
+
get isNotFound(): boolean;
|
|
39
|
+
/** True when the request was rejected as unauthenticated (HTTP 401). */
|
|
40
|
+
get isUnauthorized(): boolean;
|
|
41
|
+
/** True when the request was rejected as forbidden (HTTP 403). */
|
|
42
|
+
get isForbidden(): boolean;
|
|
43
|
+
/** True when the upstream returned a 5xx server error. */
|
|
44
|
+
get isServerError(): boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface TMDBRateLimitErrorOptions extends TMDBResponseErrorOptions {
|
|
47
|
+
/** Seconds to wait before retrying. Parsed from the `Retry-After` header. */
|
|
48
|
+
retryAfter: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Thrown when TMDB returns HTTP 429.
|
|
52
|
+
*
|
|
53
|
+
* The SDK does NOT retry automatically — that decision is left to the
|
|
54
|
+
* caller, since retry policies vary widely. Inspect `retryAfter` to
|
|
55
|
+
* implement your own backoff.
|
|
56
|
+
*/
|
|
57
|
+
export declare class TMDBRateLimitError extends TMDBResponseError {
|
|
58
|
+
readonly retryAfter: number;
|
|
59
|
+
constructor(message: string, options: TMDBRateLimitErrorOptions);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create the appropriate error instance for a non-2xx TMDB response.
|
|
63
|
+
*
|
|
64
|
+
* Returns a {@link TMDBRateLimitError} when the status is 429, otherwise
|
|
65
|
+
* a generic {@link TMDBResponseError}. The error message is extracted from
|
|
66
|
+
* the TMDB `status_message` field when available.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createResponseError(options: TMDBResponseErrorOptions): TMDBResponseError;
|
|
69
|
+
/**
|
|
70
|
+
* Parse the `Retry-After` header into seconds. Accepts both delta-seconds
|
|
71
|
+
* (e.g. "5") and HTTP-date forms (e.g. "Wed, 21 Oct 2026 07:28:00 GMT").
|
|
72
|
+
* Falls back to 1 second when the header is missing or unparseable.
|
|
73
|
+
*/
|
|
74
|
+
export declare function parseRetryAfter(value: string | null | undefined): number;
|
package/dist/http.d.cts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type QueryDefaults, type QueryParams } from './query.cjs';
|
|
2
|
+
import type { ImageUrlTransform } from './resources/images.cjs';
|
|
3
|
+
import type { LanguageCode, RegionCode } from './types.cjs';
|
|
4
|
+
export type { ImageUrlTransform };
|
|
5
|
+
/**
|
|
6
|
+
* A minimal fetch-like function signature. Any runtime's native `fetch`
|
|
7
|
+
* or a test double conforming to this shape can be used.
|
|
8
|
+
*/
|
|
9
|
+
export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
10
|
+
export interface TMDBAccessTokenAuth {
|
|
11
|
+
/** TMDB API Read Access Token. Sent as an Authorization Bearer header. */
|
|
12
|
+
accessToken: string;
|
|
13
|
+
apiKey?: never;
|
|
14
|
+
}
|
|
15
|
+
export interface TMDBApiKeyAuth {
|
|
16
|
+
/** Legacy v3 API key. Sent as api_key query parameter. */
|
|
17
|
+
apiKey: string;
|
|
18
|
+
accessToken?: never;
|
|
19
|
+
}
|
|
20
|
+
export type TMDBAuth = TMDBAccessTokenAuth | TMDBApiKeyAuth;
|
|
21
|
+
/** Internal defaults resolved during client construction. */
|
|
22
|
+
export interface TMDBClientDefaults extends QueryDefaults {
|
|
23
|
+
imageBaseUrl: string;
|
|
24
|
+
}
|
|
25
|
+
export interface TMDBImagesOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Default transform applied to every URL produced by the ImagesHelper.
|
|
28
|
+
* Use this to route TMDB image requests through a CDN, image proxy, or
|
|
29
|
+
* to add signed query parameters. Individual calls can still override it
|
|
30
|
+
* via ImagesHelper.url(path, size, { transform }).
|
|
31
|
+
*/
|
|
32
|
+
transform?: ImageUrlTransform;
|
|
33
|
+
}
|
|
34
|
+
export type TMDBClientOptions = TMDBAuth & {
|
|
35
|
+
/** Defaults to https://api.themoviedb.org/3. Useful for tests or proxies. */
|
|
36
|
+
baseUrl?: string;
|
|
37
|
+
/** Inject a fetch implementation for tests, custom runtimes, or instrumentation. */
|
|
38
|
+
fetch?: FetchLike;
|
|
39
|
+
/** Default language for endpoints that accept a language query parameter. */
|
|
40
|
+
defaultLanguage?: LanguageCode;
|
|
41
|
+
/** Default region for movie list/search endpoints that accept a region query parameter. */
|
|
42
|
+
defaultRegion?: RegionCode;
|
|
43
|
+
/** Custom image host. Defaults to https://image.tmdb.org/t/p. */
|
|
44
|
+
imageBaseUrl?: string;
|
|
45
|
+
/** Image-helper configuration: host overrides and URL transforms. */
|
|
46
|
+
images?: TMDBImagesOptions;
|
|
47
|
+
/** Additional headers merged into every request before authentication is applied. */
|
|
48
|
+
headers?: HeadersInit;
|
|
49
|
+
};
|
|
50
|
+
/** Per-request overrides applied when making a single API call. */
|
|
51
|
+
export interface TMDBRequestOptions {
|
|
52
|
+
headers?: HeadersInit;
|
|
53
|
+
query?: QueryParams;
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Transport abstraction for making HTTP requests to the TMDB API.
|
|
58
|
+
*
|
|
59
|
+
* The built-in {@link TMDBHttpClient} implements this interface. You can
|
|
60
|
+
* provide a custom implementation via {@link TMDBFactoryOptions.transport}
|
|
61
|
+
* for testing, caching, or instrumentation.
|
|
62
|
+
*/
|
|
63
|
+
export interface TMDBTransport {
|
|
64
|
+
readonly defaults: TMDBClientDefaults;
|
|
65
|
+
get<T>(path: string, options?: TMDBRequestOptions): Promise<T>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Built-in HTTP transport that uses the Fetch API.
|
|
69
|
+
*
|
|
70
|
+
* Handles authentication (API key or access token), URL construction,
|
|
71
|
+
* request headers, and response parsing. Use the factory function
|
|
72
|
+
* {@link createTMDB} instead of instantiating this directly.
|
|
73
|
+
*/
|
|
74
|
+
export declare class TMDBHttpClient implements TMDBTransport {
|
|
75
|
+
#private;
|
|
76
|
+
readonly defaults: TMDBClientDefaults;
|
|
77
|
+
readonly imageTransform: ImageUrlTransform | undefined;
|
|
78
|
+
constructor(options: TMDBClientOptions);
|
|
79
|
+
get<T>(path: string, options?: TMDBRequestOptions): Promise<T>;
|
|
80
|
+
}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type QueryDefaults, type QueryParams } from './query.js';
|
|
2
|
+
import type { ImageUrlTransform } from './resources/images.js';
|
|
3
|
+
import type { LanguageCode, RegionCode } from './types.js';
|
|
4
|
+
export type { ImageUrlTransform };
|
|
5
|
+
/**
|
|
6
|
+
* A minimal fetch-like function signature. Any runtime's native `fetch`
|
|
7
|
+
* or a test double conforming to this shape can be used.
|
|
8
|
+
*/
|
|
9
|
+
export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
10
|
+
export interface TMDBAccessTokenAuth {
|
|
11
|
+
/** TMDB API Read Access Token. Sent as an Authorization Bearer header. */
|
|
12
|
+
accessToken: string;
|
|
13
|
+
apiKey?: never;
|
|
14
|
+
}
|
|
15
|
+
export interface TMDBApiKeyAuth {
|
|
16
|
+
/** Legacy v3 API key. Sent as api_key query parameter. */
|
|
17
|
+
apiKey: string;
|
|
18
|
+
accessToken?: never;
|
|
19
|
+
}
|
|
20
|
+
export type TMDBAuth = TMDBAccessTokenAuth | TMDBApiKeyAuth;
|
|
21
|
+
/** Internal defaults resolved during client construction. */
|
|
22
|
+
export interface TMDBClientDefaults extends QueryDefaults {
|
|
23
|
+
imageBaseUrl: string;
|
|
24
|
+
}
|
|
25
|
+
export interface TMDBImagesOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Default transform applied to every URL produced by the ImagesHelper.
|
|
28
|
+
* Use this to route TMDB image requests through a CDN, image proxy, or
|
|
29
|
+
* to add signed query parameters. Individual calls can still override it
|
|
30
|
+
* via ImagesHelper.url(path, size, { transform }).
|
|
31
|
+
*/
|
|
32
|
+
transform?: ImageUrlTransform;
|
|
33
|
+
}
|
|
34
|
+
export type TMDBClientOptions = TMDBAuth & {
|
|
35
|
+
/** Defaults to https://api.themoviedb.org/3. Useful for tests or proxies. */
|
|
36
|
+
baseUrl?: string;
|
|
37
|
+
/** Inject a fetch implementation for tests, custom runtimes, or instrumentation. */
|
|
38
|
+
fetch?: FetchLike;
|
|
39
|
+
/** Default language for endpoints that accept a language query parameter. */
|
|
40
|
+
defaultLanguage?: LanguageCode;
|
|
41
|
+
/** Default region for movie list/search endpoints that accept a region query parameter. */
|
|
42
|
+
defaultRegion?: RegionCode;
|
|
43
|
+
/** Custom image host. Defaults to https://image.tmdb.org/t/p. */
|
|
44
|
+
imageBaseUrl?: string;
|
|
45
|
+
/** Image-helper configuration: host overrides and URL transforms. */
|
|
46
|
+
images?: TMDBImagesOptions;
|
|
47
|
+
/** Additional headers merged into every request before authentication is applied. */
|
|
48
|
+
headers?: HeadersInit;
|
|
49
|
+
};
|
|
50
|
+
/** Per-request overrides applied when making a single API call. */
|
|
51
|
+
export interface TMDBRequestOptions {
|
|
52
|
+
headers?: HeadersInit;
|
|
53
|
+
query?: QueryParams;
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Transport abstraction for making HTTP requests to the TMDB API.
|
|
58
|
+
*
|
|
59
|
+
* The built-in {@link TMDBHttpClient} implements this interface. You can
|
|
60
|
+
* provide a custom implementation via {@link TMDBFactoryOptions.transport}
|
|
61
|
+
* for testing, caching, or instrumentation.
|
|
62
|
+
*/
|
|
63
|
+
export interface TMDBTransport {
|
|
64
|
+
readonly defaults: TMDBClientDefaults;
|
|
65
|
+
get<T>(path: string, options?: TMDBRequestOptions): Promise<T>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Built-in HTTP transport that uses the Fetch API.
|
|
69
|
+
*
|
|
70
|
+
* Handles authentication (API key or access token), URL construction,
|
|
71
|
+
* request headers, and response parsing. Use the factory function
|
|
72
|
+
* {@link createTMDB} instead of instantiating this directly.
|
|
73
|
+
*/
|
|
74
|
+
export declare class TMDBHttpClient implements TMDBTransport {
|
|
75
|
+
#private;
|
|
76
|
+
readonly defaults: TMDBClientDefaults;
|
|
77
|
+
readonly imageTransform: ImageUrlTransform | undefined;
|
|
78
|
+
constructor(options: TMDBClientOptions);
|
|
79
|
+
get<T>(path: string, options?: TMDBRequestOptions): Promise<T>;
|
|
80
|
+
}
|