@fubar-it-co/tmdb-client 0.0.5

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/src/index.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @fileoverview TMDB HTTP Client package entry point.
3
+ *
4
+ * This package provides a type-safe HTTP client for the TMDB API,
5
+ * generated from the official OpenAPI specification using heyAPI.
6
+ *
7
+ * **Note**: The `./client` folder is generated by heyAPI.
8
+ * Run `pnpm generate` to create it.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Import SDK functions
13
+ * import { moviePopularList, movieDetails } from '@fubar-it-co/tmdb-client'
14
+ *
15
+ * // Use with TanStack Query
16
+ * import { moviePopularListOptions } from '@fubar-it-co/tmdb-client'
17
+ * const { data } = useQuery(moviePopularListOptions())
18
+ * ```
19
+ *
20
+ * @see https://developer.themoviedb.org/docs - TMDB API Documentation
21
+ * @see https://heyapi.dev - heyAPI Documentation
22
+ */
23
+
24
+ // Re-export generated client
25
+ export * from './client'
26
+
27
+ // Re-export custom types
28
+ export type { TMDBError } from './types/errors'
@@ -0,0 +1,47 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ /**
4
+ * @fileoverview TMDB API client runtime configuration.
5
+ *
6
+ * This file is referenced by heyAPI during client generation via the
7
+ * `runtimeConfigPath` option in `openapi-ts.config.ts`.
8
+ *
9
+ * It provides the base URL and authentication headers for all TMDB API requests.
10
+ * The API token is read from the environment variable `VITE_TMDB_API_TOKEN`.
11
+ *
12
+ * @see https://heyapi.dev/openapi-ts/clients/fetch#runtime-api
13
+ */
14
+ import type { Config } from './client/client/types.gen'
15
+
16
+ /**
17
+ * TMDB API Bearer token from environment variables.
18
+ * Must be set in `.env.local` at the monorepo root.
19
+ */
20
+ const TMDB_API_TOKEN = import.meta.env.VITE_TMDB_API_TOKEN
21
+
22
+ /**
23
+ * Creates the client configuration for TMDB API requests.
24
+ *
25
+ * This function is called by the generated `client.gen.ts` before
26
+ * initializing the client instance. It sets:
27
+ * - `baseUrl`: The TMDB API base URL
28
+ * - `Authorization`: Bearer token for authentication
29
+ *
30
+ * @param config - The default configuration from heyAPI
31
+ * @returns The merged configuration with TMDB-specific settings
32
+ */
33
+ export const createClientConfig = <T extends Config>(config: T): T => {
34
+ const existingHeaders =
35
+ config.headers && !Array.isArray(config.headers)
36
+ ? (config.headers as Record<string, string>)
37
+ : {}
38
+
39
+ return {
40
+ ...config,
41
+ baseUrl: 'https://api.themoviedb.org',
42
+ headers: {
43
+ ...existingHeaders,
44
+ Authorization: `Bearer ${TMDB_API_TOKEN}`,
45
+ },
46
+ }
47
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * TMDB API Error Response
3
+ *
4
+ * This is the error format returned by the TMDB API when a request fails.
5
+ * The API returns this JSON structure with an HTTP error status code (401, 404, 500, etc.).
6
+ *
7
+ * @see https://developer.themoviedb.org/docs/errors
8
+ *
9
+ * @example
10
+ * // 401 Unauthorized (Invalid API key)
11
+ * {
12
+ * success: false,
13
+ * status_code: 7,
14
+ * status_message: "Invalid API key: You must be granted a valid key."
15
+ * }
16
+ *
17
+ * @example
18
+ * // 404 Not Found (Resource not found)
19
+ * {
20
+ * success: false,
21
+ * status_code: 34,
22
+ * status_message: "The resource you requested could not be found."
23
+ * }
24
+ */
25
+ export interface TMDBError {
26
+ /** Always false for error responses */
27
+ success: false
28
+ /** TMDB internal status code (e.g., 7 for invalid API key, 34 for not found) */
29
+ status_code: number
30
+ /** Human-readable error message */
31
+ status_message: string
32
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ interface ImportMetaEnv {
4
+ readonly VITE_TMDB_API_TOKEN: string
5
+ }
6
+
7
+ interface ImportMeta {
8
+ readonly env: ImportMetaEnv
9
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": false,
5
+ "outDir": "dist",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "module": "ESNext",
10
+ "moduleResolution": "bundler"
11
+ },
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "skipLibCheck": true,
10
+ "esModuleInterop": true,
11
+ "isolatedModules": true,
12
+ "resolveJsonModule": true,
13
+ "types": ["vite/client"]
14
+ },
15
+ "include": ["src/index.ts", "src/tmdb-config.ts", "src/vite-env.d.ts"],
16
+ "exclude": ["node_modules"]
17
+ }