tmdb-kit 1.0.0 → 1.2.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.
Files changed (45) hide show
  1. package/README.md +455 -196
  2. package/dist/cli.js +3823 -0
  3. package/dist/client.d.cts +71 -0
  4. package/dist/client.d.ts +71 -0
  5. package/dist/errors.d.cts +86 -0
  6. package/dist/errors.d.ts +86 -0
  7. package/dist/helpers/cache.d.cts +28 -0
  8. package/dist/helpers/cache.d.ts +28 -0
  9. package/dist/helpers/pagination.d.cts +35 -0
  10. package/dist/helpers/pagination.d.ts +35 -0
  11. package/dist/helpers/retry.d.cts +47 -0
  12. package/dist/helpers/retry.d.ts +47 -0
  13. package/dist/helpers/timeout.d.cts +20 -0
  14. package/dist/helpers/timeout.d.ts +20 -0
  15. package/dist/http.d.cts +80 -0
  16. package/dist/http.d.ts +80 -0
  17. package/dist/index.cjs +1115 -768
  18. package/dist/index.cjs.map +27 -1
  19. package/dist/index.d.cts +13 -783
  20. package/dist/index.d.ts +13 -783
  21. package/dist/index.js +1074 -744
  22. package/dist/index.js.map +27 -1
  23. package/dist/query.d.cts +91 -0
  24. package/dist/query.d.ts +91 -0
  25. package/dist/resources/configuration.d.cts +17 -0
  26. package/dist/resources/configuration.d.ts +17 -0
  27. package/dist/resources/genres.d.cts +13 -0
  28. package/dist/resources/genres.d.ts +13 -0
  29. package/dist/resources/images.d.cts +17 -0
  30. package/dist/resources/images.d.ts +17 -0
  31. package/dist/resources/movies.d.cts +21 -0
  32. package/dist/resources/movies.d.ts +21 -0
  33. package/dist/resources/people.d.cts +14 -0
  34. package/dist/resources/people.d.ts +14 -0
  35. package/dist/resources/search.d.cts +15 -0
  36. package/dist/resources/search.d.ts +15 -0
  37. package/dist/resources/trending.d.cts +23 -0
  38. package/dist/resources/trending.d.ts +23 -0
  39. package/dist/resources/tv.d.cts +30 -0
  40. package/dist/resources/tv.d.ts +30 -0
  41. package/dist/search-guards.d.cts +32 -0
  42. package/dist/search-guards.d.ts +32 -0
  43. package/dist/types.d.cts +550 -0
  44. package/dist/types.d.ts +550 -0
  45. package/package.json +26 -19
@@ -0,0 +1,71 @@
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 when the caller supplies a custom transport.
12
+ *
13
+ * The transport owns authentication, so credentials are not required.
14
+ */
15
+ export type TMDBTransportOptions = Omit<TMDBClientOptions, 'accessToken' | 'apiKey'> & {
16
+ transport: TMDBTransport;
17
+ };
18
+ /**
19
+ * Options accepted by {@link createTMDB} and the {@link TMDBClient} constructor.
20
+ *
21
+ * Either provide credentials for the built-in transport, or pass a custom
22
+ * {@link TMDBTransport} (typically for tests, caching, or instrumentation)
23
+ * without credentials.
24
+ */
25
+ export type TMDBFactoryOptions = (TMDBClientOptions & {
26
+ transport?: TMDBTransport;
27
+ }) | TMDBTransportOptions;
28
+ /**
29
+ * Main SDK entry point.
30
+ *
31
+ * Resource properties are intentionally small and explicit. The SDK focuses on
32
+ * common TMDB workflows first, while request<T>() keeps uncommon endpoints easy
33
+ * to call without waiting for a generated surface area.
34
+ */
35
+ export declare class TMDBClient {
36
+ #private;
37
+ readonly configuration: ConfigurationResource;
38
+ readonly genres: GenresResource;
39
+ readonly images: ImagesHelper;
40
+ readonly movies: MoviesResource;
41
+ readonly people: PeopleResource;
42
+ readonly search: SearchResource;
43
+ readonly trending: TrendingResource;
44
+ readonly tv: TVResource;
45
+ constructor(options: TMDBFactoryOptions);
46
+ /**
47
+ * Make a raw GET request to any TMDB endpoint.
48
+ *
49
+ * This is an escape hatch for endpoints not covered by the typed resource
50
+ * helpers. The `path` should be relative to the API base URL (e.g.
51
+ * `/movie/{id}/credits`). Response is parsed as JSON and cast to `T`.
52
+ *
53
+ * @param path - API path relative to the base URL (e.g. `/movie/123`)
54
+ * @param options - Optional request-level overrides (headers, query, signal)
55
+ * @returns Parsed JSON response typed as `T`
56
+ */
57
+ request<T>(path: string, options?: TMDBRequestOptions): Promise<T>;
58
+ }
59
+ /**
60
+ * Create a new {@link TMDBClient} instance.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const tmdb = createTMDB({ accessToken: 'YOUR_TOKEN' })
65
+ * const { results } = await tmdb.search.movies('Inception')
66
+ * ```
67
+ *
68
+ * @param options - Authentication and configuration options
69
+ * @returns A configured TMDBClient ready to make API calls
70
+ */
71
+ export declare function createTMDB(options: TMDBFactoryOptions): TMDBClient;
@@ -0,0 +1,71 @@
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 when the caller supplies a custom transport.
12
+ *
13
+ * The transport owns authentication, so credentials are not required.
14
+ */
15
+ export type TMDBTransportOptions = Omit<TMDBClientOptions, 'accessToken' | 'apiKey'> & {
16
+ transport: TMDBTransport;
17
+ };
18
+ /**
19
+ * Options accepted by {@link createTMDB} and the {@link TMDBClient} constructor.
20
+ *
21
+ * Either provide credentials for the built-in transport, or pass a custom
22
+ * {@link TMDBTransport} (typically for tests, caching, or instrumentation)
23
+ * without credentials.
24
+ */
25
+ export type TMDBFactoryOptions = (TMDBClientOptions & {
26
+ transport?: TMDBTransport;
27
+ }) | TMDBTransportOptions;
28
+ /**
29
+ * Main SDK entry point.
30
+ *
31
+ * Resource properties are intentionally small and explicit. The SDK focuses on
32
+ * common TMDB workflows first, while request<T>() keeps uncommon endpoints easy
33
+ * to call without waiting for a generated surface area.
34
+ */
35
+ export declare class TMDBClient {
36
+ #private;
37
+ readonly configuration: ConfigurationResource;
38
+ readonly genres: GenresResource;
39
+ readonly images: ImagesHelper;
40
+ readonly movies: MoviesResource;
41
+ readonly people: PeopleResource;
42
+ readonly search: SearchResource;
43
+ readonly trending: TrendingResource;
44
+ readonly tv: TVResource;
45
+ constructor(options: TMDBFactoryOptions);
46
+ /**
47
+ * Make a raw GET request to any TMDB endpoint.
48
+ *
49
+ * This is an escape hatch for endpoints not covered by the typed resource
50
+ * helpers. The `path` should be relative to the API base URL (e.g.
51
+ * `/movie/{id}/credits`). Response is parsed as JSON and cast to `T`.
52
+ *
53
+ * @param path - API path relative to the base URL (e.g. `/movie/123`)
54
+ * @param options - Optional request-level overrides (headers, query, signal)
55
+ * @returns Parsed JSON response typed as `T`
56
+ */
57
+ request<T>(path: string, options?: TMDBRequestOptions): Promise<T>;
58
+ }
59
+ /**
60
+ * Create a new {@link TMDBClient} instance.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const tmdb = createTMDB({ accessToken: 'YOUR_TOKEN' })
65
+ * const { results } = await tmdb.search.movies('Inception')
66
+ * ```
67
+ *
68
+ * @param options - Authentication and configuration options
69
+ * @returns A configured TMDBClient ready to make API calls
70
+ */
71
+ export declare function createTMDB(options: TMDBFactoryOptions): TMDBClient;
@@ -0,0 +1,86 @@
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
+ /**
25
+ * Thrown when a request exceeds the timeout supplied to `withTimeout()`.
26
+ *
27
+ * The timeout helper aborts the request's AbortSignal and converts the
28
+ * resulting abort into this error so timeouts are distinguishable from
29
+ * caller-initiated cancellation.
30
+ */
31
+ export declare class TMDBTimeoutError extends TMDBError {
32
+ readonly timeoutMs: number;
33
+ constructor(timeoutMs: number, message?: string);
34
+ }
35
+ /** Thrown when TMDB returns a non-2xx response. */
36
+ export declare class TMDBResponseError extends TMDBError {
37
+ readonly body: JsonValue | undefined;
38
+ readonly headers: Headers;
39
+ readonly requestId: string | null;
40
+ readonly status: number;
41
+ readonly statusCode: number | undefined;
42
+ readonly statusMessage: string | undefined;
43
+ readonly statusText: string;
44
+ readonly url: string;
45
+ constructor(message: string, options: TMDBResponseErrorOptions);
46
+ /** True when TMDB has asked the caller to back off (HTTP 429). */
47
+ get isRateLimit(): boolean;
48
+ /** True when the resource was not found (HTTP 404). */
49
+ get isNotFound(): boolean;
50
+ /** True when the request was rejected as unauthenticated (HTTP 401). */
51
+ get isUnauthorized(): boolean;
52
+ /** True when the request was rejected as forbidden (HTTP 403). */
53
+ get isForbidden(): boolean;
54
+ /** True when the upstream returned a 5xx server error. */
55
+ get isServerError(): boolean;
56
+ }
57
+ export interface TMDBRateLimitErrorOptions extends TMDBResponseErrorOptions {
58
+ /** Seconds to wait before retrying. Parsed from the `Retry-After` header. */
59
+ retryAfter: number;
60
+ }
61
+ /**
62
+ * Thrown when TMDB returns HTTP 429.
63
+ *
64
+ * The SDK does NOT retry automatically — that decision is left to the
65
+ * caller, since retry policies vary widely. Inspect `retryAfter` to
66
+ * implement your own backoff, or use the optional `retry()` / `withRetry()`
67
+ * helpers for a TMDB-aware default.
68
+ */
69
+ export declare class TMDBRateLimitError extends TMDBResponseError {
70
+ readonly retryAfter: number;
71
+ constructor(message: string, options: TMDBRateLimitErrorOptions);
72
+ }
73
+ /**
74
+ * Create the appropriate error instance for a non-2xx TMDB response.
75
+ *
76
+ * Returns a {@link TMDBRateLimitError} when the status is 429, otherwise
77
+ * a generic {@link TMDBResponseError}. The error message is extracted from
78
+ * the TMDB `status_message` field when available.
79
+ */
80
+ export declare function createResponseError(options: TMDBResponseErrorOptions): TMDBResponseError;
81
+ /**
82
+ * Parse the `Retry-After` header into seconds. Accepts both delta-seconds
83
+ * (e.g. "5") and HTTP-date forms (e.g. "Wed, 21 Oct 2026 07:28:00 GMT").
84
+ * Falls back to 1 second when the header is missing or unparseable.
85
+ */
86
+ export declare function parseRetryAfter(value: string | null | undefined): number;
@@ -0,0 +1,86 @@
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
+ /**
25
+ * Thrown when a request exceeds the timeout supplied to `withTimeout()`.
26
+ *
27
+ * The timeout helper aborts the request's AbortSignal and converts the
28
+ * resulting abort into this error so timeouts are distinguishable from
29
+ * caller-initiated cancellation.
30
+ */
31
+ export declare class TMDBTimeoutError extends TMDBError {
32
+ readonly timeoutMs: number;
33
+ constructor(timeoutMs: number, message?: string);
34
+ }
35
+ /** Thrown when TMDB returns a non-2xx response. */
36
+ export declare class TMDBResponseError extends TMDBError {
37
+ readonly body: JsonValue | undefined;
38
+ readonly headers: Headers;
39
+ readonly requestId: string | null;
40
+ readonly status: number;
41
+ readonly statusCode: number | undefined;
42
+ readonly statusMessage: string | undefined;
43
+ readonly statusText: string;
44
+ readonly url: string;
45
+ constructor(message: string, options: TMDBResponseErrorOptions);
46
+ /** True when TMDB has asked the caller to back off (HTTP 429). */
47
+ get isRateLimit(): boolean;
48
+ /** True when the resource was not found (HTTP 404). */
49
+ get isNotFound(): boolean;
50
+ /** True when the request was rejected as unauthenticated (HTTP 401). */
51
+ get isUnauthorized(): boolean;
52
+ /** True when the request was rejected as forbidden (HTTP 403). */
53
+ get isForbidden(): boolean;
54
+ /** True when the upstream returned a 5xx server error. */
55
+ get isServerError(): boolean;
56
+ }
57
+ export interface TMDBRateLimitErrorOptions extends TMDBResponseErrorOptions {
58
+ /** Seconds to wait before retrying. Parsed from the `Retry-After` header. */
59
+ retryAfter: number;
60
+ }
61
+ /**
62
+ * Thrown when TMDB returns HTTP 429.
63
+ *
64
+ * The SDK does NOT retry automatically — that decision is left to the
65
+ * caller, since retry policies vary widely. Inspect `retryAfter` to
66
+ * implement your own backoff, or use the optional `retry()` / `withRetry()`
67
+ * helpers for a TMDB-aware default.
68
+ */
69
+ export declare class TMDBRateLimitError extends TMDBResponseError {
70
+ readonly retryAfter: number;
71
+ constructor(message: string, options: TMDBRateLimitErrorOptions);
72
+ }
73
+ /**
74
+ * Create the appropriate error instance for a non-2xx TMDB response.
75
+ *
76
+ * Returns a {@link TMDBRateLimitError} when the status is 429, otherwise
77
+ * a generic {@link TMDBResponseError}. The error message is extracted from
78
+ * the TMDB `status_message` field when available.
79
+ */
80
+ export declare function createResponseError(options: TMDBResponseErrorOptions): TMDBResponseError;
81
+ /**
82
+ * Parse the `Retry-After` header into seconds. Accepts both delta-seconds
83
+ * (e.g. "5") and HTTP-date forms (e.g. "Wed, 21 Oct 2026 07:28:00 GMT").
84
+ * Falls back to 1 second when the header is missing or unparseable.
85
+ */
86
+ export declare function parseRetryAfter(value: string | null | undefined): number;
@@ -0,0 +1,28 @@
1
+ import type { TMDBTransport } from '../http.cjs';
2
+ export interface MemoryCacheOptions {
3
+ /** Entry lifetime in milliseconds. Defaults to 300000 (5 minutes). */
4
+ ttlMs?: number;
5
+ /** Maximum number of cached responses. Defaults to 100. */
6
+ maxEntries?: number;
7
+ }
8
+ export type MemoryCacheTransport<T extends TMDBTransport = TMDBTransport> = T & {
9
+ /** Remove every cached response. */
10
+ clear(): void;
11
+ };
12
+ /**
13
+ * Wrap a transport with a small in-memory LRU cache.
14
+ *
15
+ * Only successful responses are cached. The key includes the path, sorted
16
+ * query parameters, and sorted headers, so language, region, and header
17
+ * variants never collide. Signals are intentionally excluded from the key.
18
+ * Use one cache per client or credential: authentication is not part of the
19
+ * key.
20
+ *
21
+ * ```ts
22
+ * const http = new TMDBHttpClient({ accessToken })
23
+ * const tmdb = createTMDB({
24
+ * transport: withMemoryCache(http, { ttlMs: 60_000, maxEntries: 200 }),
25
+ * })
26
+ * ```
27
+ */
28
+ export declare function withMemoryCache<T extends TMDBTransport>(transport: T, options?: MemoryCacheOptions): MemoryCacheTransport<T>;
@@ -0,0 +1,28 @@
1
+ import type { TMDBTransport } from '../http.js';
2
+ export interface MemoryCacheOptions {
3
+ /** Entry lifetime in milliseconds. Defaults to 300000 (5 minutes). */
4
+ ttlMs?: number;
5
+ /** Maximum number of cached responses. Defaults to 100. */
6
+ maxEntries?: number;
7
+ }
8
+ export type MemoryCacheTransport<T extends TMDBTransport = TMDBTransport> = T & {
9
+ /** Remove every cached response. */
10
+ clear(): void;
11
+ };
12
+ /**
13
+ * Wrap a transport with a small in-memory LRU cache.
14
+ *
15
+ * Only successful responses are cached. The key includes the path, sorted
16
+ * query parameters, and sorted headers, so language, region, and header
17
+ * variants never collide. Signals are intentionally excluded from the key.
18
+ * Use one cache per client or credential: authentication is not part of the
19
+ * key.
20
+ *
21
+ * ```ts
22
+ * const http = new TMDBHttpClient({ accessToken })
23
+ * const tmdb = createTMDB({
24
+ * transport: withMemoryCache(http, { ttlMs: 60_000, maxEntries: 200 }),
25
+ * })
26
+ * ```
27
+ */
28
+ export declare function withMemoryCache<T extends TMDBTransport>(transport: T, options?: MemoryCacheOptions): MemoryCacheTransport<T>;
@@ -0,0 +1,35 @@
1
+ import type { PagedResponse } from '../types.cjs';
2
+ /** Fetches a single page. The caller closes over its own query options. */
3
+ export interface PageFetcher<T> {
4
+ (page: number): Promise<PagedResponse<T>>;
5
+ }
6
+ export interface PaginateOptions {
7
+ /** First page to request. Defaults to 1. */
8
+ startPage?: number;
9
+ /** Last page to request, inclusive. Defaults to 500, TMDB's documented cap. */
10
+ endPage?: number;
11
+ /** Cancels the iteration before the next request. */
12
+ signal?: AbortSignal;
13
+ }
14
+ /**
15
+ * Iterate a paged TMDB endpoint page by page.
16
+ *
17
+ * Stops when the API reports the last page, when a page has no results,
18
+ * when `endPage` is reached, or when the signal is aborted. Yields nothing
19
+ * when `endPage` is lower than `startPage`. The fetcher
20
+ * receives the page number and should forward the signal to the SDK:
21
+ *
22
+ * ```ts
23
+ * for await (const page of paginate((page) => tmdb.movies.popular({ page, signal }))) {
24
+ * console.log(page.page, page.results.length)
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function paginate<T>(fetchPage: PageFetcher<T>, options?: PaginateOptions): AsyncGenerator<PagedResponse<T>, void, undefined>;
29
+ /**
30
+ * Iterate a paged TMDB endpoint item by item.
31
+ *
32
+ * Built on {@link paginate}; use `paginate` directly when you need page
33
+ * metadata such as `total_pages`.
34
+ */
35
+ export declare function paginateItems<T>(fetchPage: PageFetcher<T>, options?: PaginateOptions): AsyncGenerator<T, void, undefined>;
@@ -0,0 +1,35 @@
1
+ import type { PagedResponse } from '../types.js';
2
+ /** Fetches a single page. The caller closes over its own query options. */
3
+ export interface PageFetcher<T> {
4
+ (page: number): Promise<PagedResponse<T>>;
5
+ }
6
+ export interface PaginateOptions {
7
+ /** First page to request. Defaults to 1. */
8
+ startPage?: number;
9
+ /** Last page to request, inclusive. Defaults to 500, TMDB's documented cap. */
10
+ endPage?: number;
11
+ /** Cancels the iteration before the next request. */
12
+ signal?: AbortSignal;
13
+ }
14
+ /**
15
+ * Iterate a paged TMDB endpoint page by page.
16
+ *
17
+ * Stops when the API reports the last page, when a page has no results,
18
+ * when `endPage` is reached, or when the signal is aborted. Yields nothing
19
+ * when `endPage` is lower than `startPage`. The fetcher
20
+ * receives the page number and should forward the signal to the SDK:
21
+ *
22
+ * ```ts
23
+ * for await (const page of paginate((page) => tmdb.movies.popular({ page, signal }))) {
24
+ * console.log(page.page, page.results.length)
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function paginate<T>(fetchPage: PageFetcher<T>, options?: PaginateOptions): AsyncGenerator<PagedResponse<T>, void, undefined>;
29
+ /**
30
+ * Iterate a paged TMDB endpoint item by item.
31
+ *
32
+ * Built on {@link paginate}; use `paginate` directly when you need page
33
+ * metadata such as `total_pages`.
34
+ */
35
+ export declare function paginateItems<T>(fetchPage: PageFetcher<T>, options?: PaginateOptions): AsyncGenerator<T, void, undefined>;
@@ -0,0 +1,47 @@
1
+ import type { TMDBTransport } from '../http.cjs';
2
+ export interface RetryInfo {
3
+ /** Zero-based attempt number that failed. */
4
+ attempt: number;
5
+ /** Delay before the next attempt, in milliseconds. */
6
+ delayMs: number;
7
+ error: unknown;
8
+ }
9
+ export interface RetryOptions {
10
+ /** Retries after the first attempt. Defaults to 2. */
11
+ retries?: number;
12
+ /** Base delay for exponential backoff in milliseconds. Defaults to 250. */
13
+ baseDelayMs?: number;
14
+ /** Maximum exponential backoff delay in milliseconds. Defaults to 10000. */
15
+ maxDelayMs?: number;
16
+ /** Exponential backoff factor. Defaults to 2. */
17
+ factor?: number;
18
+ /** Apply full jitter to exponential delays. Defaults to true. */
19
+ jitter?: boolean;
20
+ /** Cancels the delay and any further attempts. */
21
+ signal?: AbortSignal;
22
+ /** Replaces the default retry predicate. */
23
+ retryOn?: (error: unknown, attempt: number) => boolean;
24
+ /** Observes each retry decision without changing it. */
25
+ onRetry?: (info: RetryInfo) => void;
26
+ }
27
+ /**
28
+ * Retry an async task using TMDB-aware defaults.
29
+ *
30
+ * Retries 429 and any response that carries `Retry-After`, retries 408 and
31
+ * 5xx responses plus network failures with exponential backoff, and never
32
+ * retries other 4xx responses, validation errors, aborts, or timeouts. All
33
+ * TMDB requests are GETs, so the helper is safe for every resource method.
34
+ */
35
+ export declare function retry<T>(task: () => Promise<T>, options?: RetryOptions): Promise<T>;
36
+ /**
37
+ * Wrap a transport so every request uses {@link retry}.
38
+ *
39
+ * ```ts
40
+ * const http = new TMDBHttpClient({ accessToken })
41
+ * const tmdb = createTMDB({ transport: withRetry(http, { retries: 3 }) })
42
+ * ```
43
+ *
44
+ * A wrapper-level `signal` and a per-request `signal` are combined, so
45
+ * aborting either cancels the call. Extra transport members are preserved.
46
+ */
47
+ export declare function withRetry<T extends TMDBTransport>(transport: T, options?: RetryOptions): T;
@@ -0,0 +1,47 @@
1
+ import type { TMDBTransport } from '../http.js';
2
+ export interface RetryInfo {
3
+ /** Zero-based attempt number that failed. */
4
+ attempt: number;
5
+ /** Delay before the next attempt, in milliseconds. */
6
+ delayMs: number;
7
+ error: unknown;
8
+ }
9
+ export interface RetryOptions {
10
+ /** Retries after the first attempt. Defaults to 2. */
11
+ retries?: number;
12
+ /** Base delay for exponential backoff in milliseconds. Defaults to 250. */
13
+ baseDelayMs?: number;
14
+ /** Maximum exponential backoff delay in milliseconds. Defaults to 10000. */
15
+ maxDelayMs?: number;
16
+ /** Exponential backoff factor. Defaults to 2. */
17
+ factor?: number;
18
+ /** Apply full jitter to exponential delays. Defaults to true. */
19
+ jitter?: boolean;
20
+ /** Cancels the delay and any further attempts. */
21
+ signal?: AbortSignal;
22
+ /** Replaces the default retry predicate. */
23
+ retryOn?: (error: unknown, attempt: number) => boolean;
24
+ /** Observes each retry decision without changing it. */
25
+ onRetry?: (info: RetryInfo) => void;
26
+ }
27
+ /**
28
+ * Retry an async task using TMDB-aware defaults.
29
+ *
30
+ * Retries 429 and any response that carries `Retry-After`, retries 408 and
31
+ * 5xx responses plus network failures with exponential backoff, and never
32
+ * retries other 4xx responses, validation errors, aborts, or timeouts. All
33
+ * TMDB requests are GETs, so the helper is safe for every resource method.
34
+ */
35
+ export declare function retry<T>(task: () => Promise<T>, options?: RetryOptions): Promise<T>;
36
+ /**
37
+ * Wrap a transport so every request uses {@link retry}.
38
+ *
39
+ * ```ts
40
+ * const http = new TMDBHttpClient({ accessToken })
41
+ * const tmdb = createTMDB({ transport: withRetry(http, { retries: 3 }) })
42
+ * ```
43
+ *
44
+ * A wrapper-level `signal` and a per-request `signal` are combined, so
45
+ * aborting either cancels the call. Extra transport members are preserved.
46
+ */
47
+ export declare function withRetry<T extends TMDBTransport>(transport: T, options?: RetryOptions): T;
@@ -0,0 +1,20 @@
1
+ export interface TimeoutOptions {
2
+ /** Parent signal. Aborting it cancels the task with the same reason. */
3
+ signal?: AbortSignal;
4
+ /** Custom message for the TMDBTimeoutError. */
5
+ message?: string;
6
+ }
7
+ /**
8
+ * Run a task with an AbortSignal-backed timeout.
9
+ *
10
+ * The task must forward the provided signal to the SDK for cancellation to
11
+ * take effect. Timeouts are reported as {@link TMDBTimeoutError}; aborts from
12
+ * the parent signal keep the parent's reason.
13
+ *
14
+ * ```ts
15
+ * const movie = await withTimeout(5_000, (signal) =>
16
+ * tmdb.movies.details(550, { signal }),
17
+ * )
18
+ * ```
19
+ */
20
+ export declare function withTimeout<T>(timeoutMs: number, task: (signal: AbortSignal) => Promise<T>, options?: TimeoutOptions): Promise<T>;
@@ -0,0 +1,20 @@
1
+ export interface TimeoutOptions {
2
+ /** Parent signal. Aborting it cancels the task with the same reason. */
3
+ signal?: AbortSignal;
4
+ /** Custom message for the TMDBTimeoutError. */
5
+ message?: string;
6
+ }
7
+ /**
8
+ * Run a task with an AbortSignal-backed timeout.
9
+ *
10
+ * The task must forward the provided signal to the SDK for cancellation to
11
+ * take effect. Timeouts are reported as {@link TMDBTimeoutError}; aborts from
12
+ * the parent signal keep the parent's reason.
13
+ *
14
+ * ```ts
15
+ * const movie = await withTimeout(5_000, (signal) =>
16
+ * tmdb.movies.details(550, { signal }),
17
+ * )
18
+ * ```
19
+ */
20
+ export declare function withTimeout<T>(timeoutMs: number, task: (signal: AbortSignal) => Promise<T>, options?: TimeoutOptions): Promise<T>;
@@ -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
+ }