26 Commits

Author SHA1 Message Date
Blake
2fed644950 Update README.md 2023-04-25 22:56:07 -04:00
Blake
e5ce15d58d Merge pull request #28 from blakejoy/v1
feat: remove default export
2023-04-21 09:15:52 -04:00
Blake Joynes
7f98a557dc remove commented tsconfig 2023-04-20 06:27:35 -04:00
Blake Joynes
9e54e26e87 run prettier 2023-04-20 06:26:53 -04:00
Blake Joynes
69a883e845 remove default exports
major version 1.x
2023-04-16 15:39:45 -04:00
Blake Joynes
de2f76d257 add nvmrc \n update packages 2023-04-16 11:27:36 -04:00
Blake
af7dc02a07 Merge pull request #26 from blakejoy/feat/publish-npm
Create npm-publish.yml
2023-04-15 14:52:19 -04:00
Blake
6e111921b5 Create npm-publish.yml 2023-04-15 14:51:27 -04:00
Blake
c95a66baae Merge pull request #23 from Der-Penz/refactor/parsing-options-superclass
Refactor/ moved parsing of parameters into superclass
2023-04-15 14:47:56 -04:00
DerPenz
f3f4868ef8 version: 0.2.0 2023-04-15 20:22:45 +02:00
DerPenz
6bcddc62f1 Merge branch 'master' into refactor/parsing-options-superclass 2023-04-15 18:38:17 +02:00
DerPenz
2b26b7b848 run npm format 2023-04-15 18:32:53 +02:00
DerPenz
6c361002bf Squashed commit of the following:
commit 5d38a76997
Merge: 7cccdb9 f160e23
Author: Blake <blakejoy@users.noreply.github.com>
Date:   Sat Apr 15 11:44:39 2023 -0400

    Merge pull request #22 from blakejoy/feat/add_linting

    feat - add linting and prettier

commit f160e2362c
Author: Blake Joynes <blakejoynes@gmail.com>
Date:   Sat Apr 15 11:44:00 2023 -0400

    add pre commit hook

commit 0fd8317884
Merge: bc91674 d1e87ba
Author: Blake Joynes <blakejoynes@gmail.com>
Date:   Sat Apr 15 11:41:28 2023 -0400

    add husky

commit bc91674c4b
Author: Blake Joynes <blakejoynes@gmail.com>
Date:   Sat Apr 15 11:39:24 2023 -0400

    add husky

commit d1e87ba7be
Author: Blake <blakejoy@users.noreply.github.com>
Date:   Fri Apr 14 08:48:33 2023 -0400

    Update .prettierrc

commit d064d4d86f
Author: Blake Joynes <blakejoynes@gmail.com>
Date:   Fri Apr 14 03:09:39 2023 -0400

    turn off linebreak rules

commit 06155bd323
Author: Blake Joynes <blakejoynes@gmail.com>
Date:   Thu Apr 13 21:58:41 2023 -0400

    add linting and prettier
2023-04-15 18:32:06 +02:00
Blake
6fd471b921 Merge pull request #24 from blakejoy/update_any_types
fix warnings for any type
2023-04-15 12:20:25 -04:00
Blake Joynes
60a2f8e00e update version 2023-04-15 12:17:50 -04:00
Blake Joynes
933ebf25a3 fix warnings for any type 2023-04-15 12:16:57 -04:00
Blake
5d38a76997 Merge pull request #22 from blakejoy/feat/add_linting
feat - add linting and prettier
2023-04-15 11:44:39 -04:00
Blake Joynes
f160e2362c add pre commit hook 2023-04-15 11:44:00 -04:00
Blake Joynes
0fd8317884 add husky 2023-04-15 11:41:28 -04:00
Blake Joynes
bc91674c4b add husky 2023-04-15 11:39:24 -04:00
DerPenz
562864a70f removed unused parameter parsing 2023-04-14 16:01:35 +02:00
DerPenz
1200064194 moved option parsing in superclass 'get' method 2023-04-14 15:54:27 +02:00
Blake
d1e87ba7be Update .prettierrc 2023-04-14 08:48:33 -04:00
Blake Joynes
d064d4d86f turn off linebreak rules 2023-04-14 03:09:39 -04:00
Blake Joynes
06155bd323 add linting and prettier 2023-04-13 21:58:41 -04:00
Blake
7cccdb9929 Merge pull request #20 from blakejoy/blakejoy-patch_v0.1.8
Update package.json
2023-04-13 06:56:05 -04:00
47 changed files with 2834 additions and 2310 deletions

View File

@@ -2,42 +2,21 @@ module.exports = {
env: {
browser: false,
es2021: true,
node: true,
},
extends: [
'plugin:@typescript-eslint/recommended',
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
parser: '@typescript-eslint/parser',
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
sourceType: "module",
},
plugins: [
'@typescript-eslint',
],
rules:{
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }],
indent: 'off',
'@typescript-eslint/indent': ['error', 2],
'no-trailing-spaces': 'error',
quotes: ['error', 'single', { allowTemplateLiterals: true }],
semi: ['error', 'always'],
'spaced-comment': ['error', 'always'],
'no-irregular-whitespace': ['error', { 'skipComments': true }],
'space-infix-ops': 'error',
'array-bracket-spacing': 'error',
'object-curly-spacing': ['error', 'always'],
'space-before-function-paren': ['error', {
named: 'never',
anonymous: 'never',
asyncArrow: 'always',
}],
'comma-dangle': ['warn', 'always-multiline'],
'no-multiple-empty-lines': 'error',
'linebreak-style': ['off', 'unix'],
},
plugins: ["@typescript-eslint"],
};

33
.github/workflows/npm-publish.yml vendored Normal file
View File

@@ -0,0 +1,33 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Node.js Package
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

4
.husky/pre-commit Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm run lint

1
.nvmrc Normal file
View File

@@ -0,0 +1 @@
v18.16.0

3
.prettierignore Normal file
View File

@@ -0,0 +1,3 @@
dist
node_modules
.github

12
.prettierrc Normal file
View File

@@ -0,0 +1,12 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always",
"proseWrap": "never",
"htmlWhitespaceSensitivity": "strict"
}

View File

@@ -14,8 +14,10 @@ Installation:
npm install --save tmdb-ts
``
Version 1.0 removed the default import so make sure you update accordingly!
```js
import TMDB from 'tmdb-ts';
import { TMDB } from 'tmdb-ts';
const tmdb = new TMDB('accessToken');

4158
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "tmdb-ts",
"version": "0.1.8",
"version": "1.0.0",
"description": "TMDB v3 library wrapper",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -8,7 +8,8 @@
"compile": "rm -rf dist && tsc -d && npm run copy-types",
"lint": "eslint --ext .ts src/",
"lint:fix": "eslint --ext .ts src/ --fix",
"prepublish": "tsc",
"format": "npx prettier --write src",
"pre-commit": "npm run lint",
"copy-types": "mkdir dist/types && cp src/types/*.d.ts dist/types"
},
"bugs": {
@@ -29,24 +30,32 @@
"author": "Blake Joynes",
"license": "MIT",
"devDependencies": {
"@types/node": "^15.3.0",
"@types/node": "^18.15.11",
"@types/node-fetch": "^2.5.10",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"dotenv": "^9.0.2",
"eslint": "^7.26.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.23.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
"eslint": "^8.38.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"prettier": "^2.8.7",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"dependencies": {
"cross-fetch": "^3.1.4"
},
"volta": {
"node": "15.13.0",
"yarn": "1.19.2",
"npm": "7.12.1"
"node": "18.16.0",
"yarn": "1.22.4",
"npm": "9.5.1"
},
"husky": {
"hooks": {
"pre-commit": "npm run pre-commit"
}
},
"files": [
"dist"

View File

@@ -1,20 +1,22 @@
import fetch from 'cross-fetch';
import { parseOptions } from './utils';
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
export default class Api {
export class Api {
constructor(private accessToken: string) {
this.accessToken = accessToken;
}
async get<T>(path: string): Promise<T> {
const response = await fetch(`${BASE_URL_V3}${path}`, {
async get<T>(path: string, options?: Record<string, any>): Promise<T> {
const params = parseOptions(options);
const response = await fetch(`${BASE_URL_V3}${path}?${params}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${this.accessToken}`,
'Content-Type': 'application/json;charset=utf-8',
},
});
return await response.json() as T;
return (await response.json()) as T;
}
}

View File

@@ -1,11 +1,12 @@
import { BaseEndpoint } from './base';
import { AccountDetails } from '../types/account';
export class AccountEndpoint extends BaseEndpoint {
constructor(accessToken: string) {
super(accessToken);
}
async details(): Promise<any> {
async details(): Promise<AccountDetails> {
return await this.api.get('/account');
}
}

View File

@@ -1,4 +1,4 @@
import Api from '../api';
import { Api } from '../api';
export class BaseEndpoint {
protected api: Api;

View File

@@ -1,7 +1,5 @@
import { BaseEndpoint } from './base';
import { ChangeOptions, Changes } from '../types/changes';
import { parseOptions } from '../utils';
export class ChangeEndpoint extends BaseEndpoint {
constructor(protected readonly accessToken: string) {
@@ -9,17 +7,14 @@ export class ChangeEndpoint extends BaseEndpoint {
}
async movies(options?: ChangeOptions): Promise<Changes> {
const params = parseOptions(options);
return await this.api.get<Changes>(`/movie/changes?${params}`);
return await this.api.get<Changes>(`/movie/changes`, options);
}
async tvShows(options?: ChangeOptions): Promise<Changes> {
const params = parseOptions(options);
return await this.api.get<Changes>(`/tv/changes?${params}`);
return await this.api.get<Changes>(`/tv/changes`, options);
}
async person(options?: ChangeOptions): Promise<Changes> {
const params = parseOptions(options);
return await this.api.get<Changes>(`/person/changes${params}`);
return await this.api.get<Changes>(`/person/change`, options);
}
}

View File

@@ -1,5 +1,9 @@
import { DetailedCollection, ImageCollection, LanguageOption, Translations } from '../types';
import { parseOptions } from '../utils';
import {
DetailedCollection,
ImageCollection,
LanguageOption,
Translations,
} from '../types';
import { BaseEndpoint } from './base';
const BASE_COLLECTION = '/collection';
@@ -9,18 +13,30 @@ export class CollectionsEndpoint extends BaseEndpoint {
super(accessToken);
}
async details(id: number, options? : LanguageOption): Promise<DetailedCollection> {
const params = parseOptions(options);
return await this.api.get<DetailedCollection>(`${BASE_COLLECTION}/${id}?${params}`);
async details(
id: number,
options?: LanguageOption
): Promise<DetailedCollection> {
return await this.api.get<DetailedCollection>(
`${BASE_COLLECTION}/${id}`,
options
);
}
async images(id: number, options?: LanguageOption): Promise<ImageCollection> {
const params = parseOptions(options);
return await this.api.get<ImageCollection>(`${BASE_COLLECTION}/${id}/images?${params}`);
return await this.api.get<ImageCollection>(
`${BASE_COLLECTION}/${id}/images`,
options
);
}
async translations(id: number, options? : LanguageOption): Promise<Translations> {
const params = parseOptions(options);
return await this.api.get<Translations>(`${BASE_COLLECTION}/${id}/translations?${params}`);
async translations(
id: number,
options?: LanguageOption
): Promise<Translations> {
return await this.api.get<Translations>(
`${BASE_COLLECTION}/${id}/translations`,
options
);
}
}

View File

@@ -9,5 +9,4 @@ export class ConfigurationEndpoint extends BaseEndpoint {
async getCurrent(): Promise<Configuration> {
return await this.api.get<Configuration>(`/configuration`);
}
}

View File

@@ -1,7 +1,6 @@
import { BaseEndpoint } from './base';
import { CreditResponse } from '../types/credits';
export class CreditsEndpoint extends BaseEndpoint {
constructor(protected readonly accessToken: string) {
super(accessToken);
@@ -10,5 +9,4 @@ export class CreditsEndpoint extends BaseEndpoint {
async getById(id: string): Promise<CreditResponse> {
return await this.api.get<CreditResponse>(`/credit/${id}`);
}
}

View File

@@ -1,5 +1,8 @@
import { MovieDiscoverResult, SortOption, TvShowDiscoverResult } from '../types';
import { parseOptions } from '../utils';
import {
MovieDiscoverResult,
SortOption,
TvShowDiscoverResult,
} from '../types';
import { BaseEndpoint } from './base';
const BASE_DISCOVER = '/discover';
@@ -66,12 +69,16 @@ export class DiscoverEndpoint extends BaseEndpoint {
}
async movie(options?: MovieQueryOptions): Promise<MovieDiscoverResult> {
const params = parseOptions(options);
return await this.api.get<MovieDiscoverResult>(`${BASE_DISCOVER}/movie?${params}`);
return await this.api.get<MovieDiscoverResult>(
`${BASE_DISCOVER}/movie`,
options
);
}
async tvShow(options?: TvShowQueryOptions): Promise<TvShowDiscoverResult> {
const params = parseOptions(options);
return await this.api.get<TvShowDiscoverResult>(`${BASE_DISCOVER}/tv?${params}`);
return await this.api.get<TvShowDiscoverResult>(
`${BASE_DISCOVER}/tv`,
options
);
}
}

View File

@@ -1,14 +1,15 @@
import { BaseEndpoint } from './base';
import { ExternalIdOptions, FindResult } from '../types';
import { parseOptions } from '../utils';
export class FindEndpoint extends BaseEndpoint {
constructor(accessToken: string) {
super(accessToken);
}
async byId(externalId: string, options: ExternalIdOptions): Promise<FindResult> {
const params = parseOptions(options);
return await this.api.get<FindResult>(`/find/${externalId}?${params}`);
async byId(
externalId: string,
options: ExternalIdOptions
): Promise<FindResult> {
return await this.api.get<FindResult>(`/find/${externalId}`, options);
}
}

View File

@@ -1,7 +1,7 @@
import { BaseEndpoint } from './base';
export interface Genres {
genres: Array<{id: number, name: string}>
genres: Array<{ id: number; name: string }>;
}
export class GenreEndpoint extends BaseEndpoint {

View File

@@ -1,5 +1,3 @@
export * from './account';
export * from './certification';
export * from './changes';
@@ -16,4 +14,3 @@ export * from './trending';
export * from './find';
export * from './keywords';
export * from './collections';

View File

@@ -1,6 +1,5 @@
import { BaseEndpoint } from './base';
import { BelongingMovies, Keyword, KeywordsOptions } from '../types';
import { parseOptions } from '../utils';
const BASE_Keyword = '/keyword';
@@ -13,8 +12,13 @@ export class KeywordsEndpoint extends BaseEndpoint {
return await this.api.get<Keyword>(`${BASE_Keyword}/${keywordId}`);
}
async belongingMovies(keywordId : number, options?: KeywordsOptions): Promise<BelongingMovies> {
const params = parseOptions(options);
return await this.api.get<BelongingMovies>(`${BASE_Keyword}/${keywordId}/movies?${params}`);
async belongingMovies(
keywordId: number,
options?: KeywordsOptions
): Promise<BelongingMovies> {
return await this.api.get<BelongingMovies>(
`${BASE_Keyword}/${keywordId}/movies`,
options
);
}
}

View File

@@ -19,12 +19,12 @@ import {
ReleaseDates,
Reviews,
SimilarMovies,
TopRatedMovies, Translations,
TopRatedMovies,
Translations,
UpcomingMovies,
Videos,
WatchProviders,
} from '../types';
import { parseOptions } from '../utils';
const BASE_MOVIE = '/movie';
@@ -38,12 +38,16 @@ export class MoviesEndpoint extends BaseEndpoint{
}
async alternativeTitles(id: number): Promise<AlternativeTitles> {
return await this.api.get<AlternativeTitles>(`${BASE_MOVIE}/${id}/alternative_titles`);
return await this.api.get<AlternativeTitles>(
`${BASE_MOVIE}/${id}/alternative_titles`
);
}
async changes(id: number, options?: ChangeOptions): Promise<MovieChanges> {
const params = parseOptions(options);
return await this.api.get<MovieChanges>(`${BASE_MOVIE}/${id}/changes?${params}`);
return await this.api.get<MovieChanges>(
`${BASE_MOVIE}/${id}/changes`,
options
);
}
async credits(id: number): Promise<Credits> {
@@ -62,28 +66,38 @@ export class MoviesEndpoint extends BaseEndpoint{
return await this.api.get<Keywords>(`${BASE_MOVIE}/${id}/keywords`);
}
async lists(id: number, options?: LanguageOption | PageOption): Promise<MovieLists>{
const params = parseOptions(options);
return await this.api.get<MovieLists>(`${BASE_MOVIE}/${id}/lists?${params}`);
async lists(
id: number,
options?: LanguageOption | PageOption
): Promise<MovieLists> {
return await this.api.get<MovieLists>(`${BASE_MOVIE}/${id}/lists`, options);
}
async recommendations(id: number, options?: PageOption): Promise<Recommendations>{
const params = parseOptions(options);
return await this.api.get<Recommendations>(`${BASE_MOVIE}/${id}/recommendations?${params}`);
async recommendations(
id: number,
options?: PageOption
): Promise<Recommendations> {
return await this.api.get<Recommendations>(
`${BASE_MOVIE}/${id}/recommendations`,
options
);
}
async releaseDates(id: number): Promise<ReleaseDates> {
return await this.api.get<ReleaseDates>(`${BASE_MOVIE}/${id}/release_dates`);
return await this.api.get<ReleaseDates>(
`${BASE_MOVIE}/${id}/release_dates`
);
}
async reviews(id: number, options?: PageOption): Promise<Reviews> {
const params = parseOptions(options);
return await this.api.get<Reviews>(`${BASE_MOVIE}/${id}/reviews?${params}`);
return await this.api.get<Reviews>(`${BASE_MOVIE}/${id}/reviews`, options);
}
async similar(id: number, options?: PageOption): Promise<SimilarMovies> {
const params = parseOptions(options);
return await this.api.get<SimilarMovies>(`${BASE_MOVIE}/${id}/similar?${params}`);
return await this.api.get<SimilarMovies>(
`${BASE_MOVIE}/${id}/similar`,
options
);
}
async translations(id: number): Promise<Translations> {
@@ -99,32 +113,43 @@ export class MoviesEndpoint extends BaseEndpoint{
* @param id
*/
async watchProviders(id: number): Promise<WatchProviders> {
return await this.api.get<WatchProviders>(`${BASE_MOVIE}/${id}/watch/providers`);
return await this.api.get<WatchProviders>(
`${BASE_MOVIE}/${id}/watch/providers`
);
}
async latest(): Promise<LatestMovie> {
return await this.api.get<LatestMovie>(`${BASE_MOVIE}/latest`);
}
async nowPlaying(options?: PageOption & LanguageOption & RegionOption): Promise<MoviesPlayingNow>{
const params = parseOptions(options);
return await this.api.get<MoviesPlayingNow>(`${BASE_MOVIE}/now_playing?${params}`);
async nowPlaying(
options?: PageOption & LanguageOption & RegionOption
): Promise<MoviesPlayingNow> {
return await this.api.get<MoviesPlayingNow>(
`${BASE_MOVIE}/now_playing`,
options
);
}
async popular(options?: PageOption): Promise<PopularMovies> {
const params = parseOptions(options);
return await this.api.get<PopularMovies>(`${BASE_MOVIE}/popular?${params}`);
return await this.api.get<PopularMovies>(`${BASE_MOVIE}/popular`, options);
}
async topRated(options?: PageOption & LanguageOption & RegionOption): Promise<TopRatedMovies>{
const params = parseOptions(options);
return await this.api.get<TopRatedMovies>(`${BASE_MOVIE}/top_rated?${params}`);
async topRated(
options?: PageOption & LanguageOption & RegionOption
): Promise<TopRatedMovies> {
return await this.api.get<TopRatedMovies>(
`${BASE_MOVIE}/top_rated`,
options
);
}
async upcoming(options?: PageOption & LanguageOption & RegionOption): Promise<UpcomingMovies>{
const params = parseOptions(options);
return await this.api.get<UpcomingMovies>(`${BASE_MOVIE}/upcoming?${params}`);
async upcoming(
options?: PageOption & LanguageOption & RegionOption
): Promise<UpcomingMovies> {
return await this.api.get<UpcomingMovies>(
`${BASE_MOVIE}/upcoming`,
options
);
}
}

View File

@@ -12,7 +12,6 @@ import {
PopularPersons,
TaggedImages,
} from '../types';
import { parseOptions } from '../utils';
import { BaseEndpoint } from './base';
const BASE_PERSON = '/person';
@@ -27,37 +26,51 @@ export class PeopleEndpoint extends BaseEndpoint {
}
async changes(id: number, options?: ChangeOptions): Promise<PersonChanges> {
const params = parseOptions(options);
return await this.api.get<PersonChanges>(`${BASE_PERSON}/${id}/changes?${params}`);
return await this.api.get<PersonChanges>(
`${BASE_PERSON}/${id}/changes`,
options
);
}
async movieCredits(id: number): Promise<PersonMovieCredit> {
return await this.api.get<PersonMovieCredit>(`${BASE_PERSON}/${id}/movie_credits`);
return await this.api.get<PersonMovieCredit>(
`${BASE_PERSON}/${id}/movie_credits`
);
}
async tvShowCredits(id: number): Promise<PersonTvShowCredit> {
return await this.api.get<PersonTvShowCredit>(`${BASE_PERSON}/${id}/tv_credits`);
return await this.api.get<PersonTvShowCredit>(
`${BASE_PERSON}/${id}/tv_credits`
);
}
async combinedCredits(id: number): Promise<PersonCombinedCredits> {
return await this.api.get<PersonCombinedCredits>(`${BASE_PERSON}/${id}/combined_credits`);
return await this.api.get<PersonCombinedCredits>(
`${BASE_PERSON}/${id}/combined_credits`
);
}
async externalId(id: number): Promise<ExternalIds> {
return await this.api.get<ExternalIds>(`${BASE_PERSON}/${id}/external_ids`);
}
async images(id: number): Promise<{id: number, profiles: Image[]}>{
return await this.api.get<{id: number, profiles: Image[]}>(`${BASE_PERSON}/${id}/images`);
async images(id: number): Promise<{ id: number; profiles: Image[] }> {
return await this.api.get<{ id: number; profiles: Image[] }>(
`${BASE_PERSON}/${id}/images`
);
}
async taggedImages(id: number, options?: PageOption): Promise<TaggedImages> {
const params = parseOptions(options);
return await this.api.get<TaggedImages>(`${BASE_PERSON}/${id}/tagged_images?${params}`);
return await this.api.get<TaggedImages>(
`${BASE_PERSON}/${id}/tagged_images`,
options
);
}
async translation(id: number): Promise<PeopleTranslations> {
return await this.api.get<PeopleTranslations>(`${BASE_PERSON}/${id}/translations`);
return await this.api.get<PeopleTranslations>(
`${BASE_PERSON}/${id}/translations`
);
}
async latest(): Promise<PersonDetail> {
@@ -65,7 +78,9 @@ export class PeopleEndpoint extends BaseEndpoint {
}
async popular(options?: PageOption): Promise<PopularPersons> {
const params = parseOptions(options);
return await this.api.get<PopularPersons>(`${BASE_PERSON}/popular?${params}`);
return await this.api.get<PopularPersons>(
`${BASE_PERSON}/popular`,
options
);
}
}

View File

@@ -1,7 +1,6 @@
import { BaseEndpoint } from './base';
import { Search } from '../types/search';
import { Collection, Company, Movie, Person, TV } from '../types';
import { parseOptions } from '../utils';
const BASE_SEARCH = '/search';
@@ -31,34 +30,39 @@ export class SearchEndpoint extends BaseEndpoint {
}
async companies(options: SearchOptions): Promise<Search<Company>> {
const params = parseOptions(options);
return await this.api.get<Search<Company>>(`${BASE_SEARCH}/company?${params}`);
return await this.api.get<Search<Company>>(
`${BASE_SEARCH}/company`,
options
);
}
async collections(options: SearchOptions): Promise<Search<Collection>> {
const params = parseOptions(options);
return await this.api.get<Search<Collection>>(`${BASE_SEARCH}/collection?${params}`);
return await this.api.get<Search<Collection>>(
`${BASE_SEARCH}/collection`,
options
);
}
async keywords(options: SearchOptions): Promise<Search<{ id: string, name: string }>>{
const params = parseOptions(options);
return await this.api.get<Search<{ id: string, name: string }>>(`${BASE_SEARCH}/keyword?${params}`);
async keywords(
options: SearchOptions
): Promise<Search<{ id: string; name: string }>> {
return await this.api.get<Search<{ id: string; name: string }>>(
`${BASE_SEARCH}/keyword`,
options
);
}
async movies(options: MovieSearchOptions): Promise<Search<Movie>> {
const params = parseOptions(options);
return await this.api.get<Search<Movie>>(`${BASE_SEARCH}/movie?${params}`);
return await this.api.get<Search<Movie>>(`${BASE_SEARCH}/movie`, options);
}
async people(options: PeopleSearchOptions): Promise<Search<Person>> {
const params = parseOptions(options);
return await this.api.get<Search<Person>>(`${BASE_SEARCH}/person?${params}`);
return await this.api.get<Search<Person>>(`${BASE_SEARCH}/person`, options);
}
// TODO: Multi search
async tvShows(options: TvSearchOptions): Promise<Search<TV>> {
const params = parseOptions(options);
return await this.api.get<Search<TV>>(`${BASE_SEARCH}/tv?${params}`);
return await this.api.get<Search<TV>>(`${BASE_SEARCH}/tv`, options);
}
}

View File

@@ -6,9 +6,12 @@ export class TrendingEndpoint extends BaseEndpoint {
super(accessToken);
}
async trending<T extends MediaType>(mediaType : T, timeWindow: TimeWindow): Promise<TrendingResults<T>> {
return await this.api.get<TrendingResults<T>>(`/trending/${mediaType}/${timeWindow}`);
async trending<T extends MediaType>(
mediaType: T,
timeWindow: TimeWindow
): Promise<TrendingResults<T>> {
return await this.api.get<TrendingResults<T>>(
`/trending/${mediaType}/${timeWindow}`
);
}
}

View File

@@ -27,7 +27,6 @@ import {
Videos,
WatchProviders,
} from '../types';
import { parseOptions } from '../utils';
const BASE_TV = '/tv';
@@ -41,16 +40,22 @@ export class TvShowsEndpoint extends BaseEndpoint{
}
async alternativeTitles(id: number): Promise<AlternativeTitles> {
return await this.api.get<AlternativeTitles>(`${BASE_TV}/${id}/alternative_titles`);
return await this.api.get<AlternativeTitles>(
`${BASE_TV}/${id}/alternative_titles`
);
}
async changes(id: number, options?: ChangeOptions): Promise<TvShowChanges> {
const params = parseOptions(options);
return await this.api.get<TvShowChanges>(`${BASE_TV}/${id}/changes?${params}`);
return await this.api.get<TvShowChanges>(
`${BASE_TV}/${id}/changes`,
options
);
}
async contentRatings(id: number): Promise<ContentRatings> {
return await this.api.get<ContentRatings>(`${BASE_TV}/${id}/content_ratings`);
return await this.api.get<ContentRatings>(
`${BASE_TV}/${id}/content_ratings`
);
}
async credits(id: number): Promise<Credits> {
@@ -58,7 +63,9 @@ export class TvShowsEndpoint extends BaseEndpoint{
}
async season(tvId: number, seasonNumber: number): Promise<SeasonDetails> {
return await this.api.get<SeasonDetails>(`${BASE_TV}/${tvId}/season/${seasonNumber}`);
return await this.api.get<SeasonDetails>(
`${BASE_TV}/${tvId}/season/${seasonNumber}`
);
}
async episodeGroups(id: number): Promise<EpisodeGroups> {
@@ -77,23 +84,31 @@ export class TvShowsEndpoint extends BaseEndpoint{
return await this.api.get<Keywords>(`${BASE_TV}/${id}/keywords`);
}
async recommendations(id: number, options?: PageOption): Promise<Recommendations>{
const params = parseOptions(options);
return await this.api.get<Recommendations>(`${BASE_TV}/${id}/recommendations?${params}`);
async recommendations(
id: number,
options?: PageOption
): Promise<Recommendations> {
return await this.api.get<Recommendations>(
`${BASE_TV}/${id}/recommendations`,
options
);
}
async reviews(id: number, options?: PageOption): Promise<Reviews> {
const params = parseOptions(options);
return await this.api.get<Reviews>(`${BASE_TV}/${id}/reviews?${params}`);
return await this.api.get<Reviews>(`${BASE_TV}/${id}/reviews`, options);
}
async screenedTheatrically(id: number): Promise<ScreenedTheatrically> {
return await this.api.get<ScreenedTheatrically>(`${BASE_TV}/${id}/screened_theatrically`);
return await this.api.get<ScreenedTheatrically>(
`${BASE_TV}/${id}/screened_theatrically`
);
}
async similar(id: number, options?: PageOption): Promise<SimilarTvShows> {
const params = parseOptions(options);
return await this.api.get<SimilarTvShows>(`${BASE_TV}/${id}/similar?${params}`);
return await this.api.get<SimilarTvShows>(
`${BASE_TV}/${id}/similar`,
options
);
}
async translations(id: number): Promise<Translations> {
@@ -109,7 +124,9 @@ export class TvShowsEndpoint extends BaseEndpoint{
* @param id
*/
async watchProviders(id: number): Promise<WatchProviders> {
return await this.api.get<WatchProviders>(`${BASE_TV}/${id}/watch/providers`);
return await this.api.get<WatchProviders>(
`${BASE_TV}/${id}/watch/providers`
);
}
async latest(): Promise<LatestTvShows> {
@@ -120,18 +137,24 @@ export class TvShowsEndpoint extends BaseEndpoint{
return await this.api.get<OnTheAir>(`${BASE_TV}/on_the_air`);
}
async airingToday(options?: PageOption & LanguageOption & RegionOption): Promise<TvShowsAiringToday>{
const params = parseOptions(options);
return await this.api.get<TvShowsAiringToday>(`${BASE_TV}/airing_today?${params}`);
async airingToday(
options?: PageOption & LanguageOption & RegionOption
): Promise<TvShowsAiringToday> {
return await this.api.get<TvShowsAiringToday>(
`${BASE_TV}/airing_today`,
options
);
}
async popular(options?: PageOption & LanguageOption & RegionOption): Promise<PopularTvShows>{
const params = parseOptions(options);
return await this.api.get<PopularTvShows>(`${BASE_TV}/popular?${params}`);
async popular(
options?: PageOption & LanguageOption & RegionOption
): Promise<PopularTvShows> {
return await this.api.get<PopularTvShows>(`${BASE_TV}/popular`, options);
}
async topRated(options?: PageOption & LanguageOption & RegionOption): Promise<TopRatedTvShows>{
const params = parseOptions(options);
return await this.api.get<TopRatedTvShows>(`${BASE_TV}/top_rated?${params}`);
async topRated(
options?: PageOption & LanguageOption & RegionOption
): Promise<TopRatedTvShows> {
return await this.api.get<TopRatedTvShows>(`${BASE_TV}/top_rated`, options);
}
}

View File

@@ -1,6 +1,6 @@
import TMDB from './tmdb';
import { TMDB } from './tmdb';
export * from './types';
export * from './utils';
export default TMDB;
export { TMDB };

View File

@@ -17,7 +17,7 @@ import {
CollectionsEndpoint,
} from './endpoints';
export default class TMDB {
export class TMDB {
private readonly accessToken: string;
constructor(accessToken: string) {

17
src/types/account.ts Normal file
View File

@@ -0,0 +1,17 @@
export interface Gravatar {
hash: string;
}
export interface Avatar {
gravatar: Gravatar;
}
export interface AccountDetails {
avatar: Avatar;
id: number;
include_adult: boolean;
iso_3166_1: string;
iso_639_1: string;
name: string;
username: string;
}

View File

@@ -6,14 +6,14 @@ export interface Certification {
export interface Certifications {
certifications: {
US: Certification[],
CA: Certification[],
DE: Certification[],
GB: Certification[],
AU: Certification[],
BR: Certification[],
FR: Certification[],
NZ: Certification[],
IN: Certification[],
}
US: Certification[];
CA: Certification[];
DE: Certification[];
GB: Certification[];
AU: Certification[];
BR: Certification[];
FR: Certification[];
NZ: Certification[];
IN: Certification[];
};
}

View File

@@ -12,5 +12,5 @@ export interface Collection {
}
export interface DetailedCollection extends Collection {
parts: Movie[]
parts: Movie[];
}

View File

@@ -1,4 +1,3 @@
export interface Images {
base_url: string;
secure_base_url: string;
@@ -14,12 +13,11 @@ export interface Configuration {
change_keys: ChangeKeys[];
}
export const enum BackdropSizes {
W300 = 'w300',
W780 = 'w780',
W1280 = 'w1280',
ORIGINAL = 'original'
ORIGINAL = 'original',
}
export const enum LogoSizes {
@@ -29,7 +27,7 @@ export const enum LogoSizes {
W185 = 'w185',
W300 = 'w300',
W500 = 'w500',
ORIGINAL = 'original'
ORIGINAL = 'original',
}
export const enum PosterSizes {
@@ -39,22 +37,21 @@ export const enum PosterSizes {
W300 = 'w300',
W500 = 'w500',
W780 = 'w780',
ORIGINAL = 'original'
ORIGINAL = 'original',
}
export const enum ProfileSizes {
W45 = 'w45',
W185 = 'w185',
W632 = 'w632',
ORIGINAL = 'original'
ORIGINAL = 'original',
}
export const enum StillSizes {
W92 = 'w92',
W185 = 'w185',
W300 = 'w300',
ORIGINAL = 'original'
ORIGINAL = 'original',
}
export const enum ChangeKeys {
@@ -110,5 +107,5 @@ export const enum ChangeKeys {
TVRAGE_ID = 'tvrage_id',
TYPE = 'type',
VIDEO = 'video',
VIDEOS = 'videos'
VIDEOS = 'videos',
}

View File

@@ -6,7 +6,6 @@ export interface CreditSeason {
season_number?: number;
}
export interface Media {
i?: number;
name?: string;
@@ -87,8 +86,6 @@ export interface ImageCollection {
backdrops: Image[];
posters: Image[];
}
export interface Video {
id: string;
iso_639_1: string;

View File

@@ -132,17 +132,16 @@ export interface ContentRatingsResult {
rating: string;
}
export interface Recommendation {
adult: boolean;
backdrop_path?: any;
backdrop_path?: string;
genre_ids: number[];
id: number;
original_language: string;
original_title: string;
overview: string;
release_date: string;
poster_path?: any;
poster_path?: string;
popularity: number;
title: string;
video: boolean;
@@ -150,7 +149,6 @@ export interface Recommendation {
vote_count: number;
}
export interface Recommendations {
page: number;
results: Recommendation[];
@@ -176,7 +174,6 @@ export interface Reviews {
total_results: number;
}
export interface TranslationData {
title: string;
overview: string;

View File

@@ -1,9 +1,22 @@
import { Genre, Movie, ProductionCompany, ProductionCountry, SpokenLanguage } from './';
import {
Genre,
Movie,
ProductionCompany,
ProductionCountry,
SpokenLanguage,
} from './';
export interface BelongsToCollection {
id: number;
name: string;
poster_path: string;
backdrop_path: string;
}
export interface MovieDetails {
adult: boolean;
backdrop_path: string;
belongs_to_collection?: any;
belongs_to_collection?: BelongsToCollection;
budget: number;
genres: Genre[];
homepage: string;
@@ -13,7 +26,7 @@ export interface MovieDetails {
original_title: string;
overview: string;
popularity: number;
poster_path?: any;
poster_path?: string;
production_companies: ProductionCompany[];
production_countries: ProductionCountry[];
release_date: string;
@@ -34,7 +47,7 @@ export enum ReleaseDateType {
'Theatrical',
'Digital',
'Physical',
'TV'
'TV',
}
export interface ReleaseDate {
@@ -55,7 +68,6 @@ export interface ReleaseDates {
results: ReleaseDateResult[];
}
export interface SimilarMovies {
page: number;
results: Movie[];
@@ -82,7 +94,6 @@ export interface MovieLists {
total_results: number;
}
export interface MovieChangeItem {
id: string;
action: string;
@@ -103,8 +114,8 @@ export interface MovieChanges {
export interface LatestMovie {
adult: boolean;
backdrop_path?: any;
belongs_to_collection?: any;
backdrop_path?: string;
belongs_to_collection?: BelongsToCollection;
budget: number;
genres: Genre[];
homepage: string;
@@ -115,12 +126,12 @@ export interface LatestMovie {
overview: string;
popularity: number;
poster_path: string;
production_companies: any[];
production_countries: any[];
production_companies: ProductionCompany[];
production_countries: ProductionCountry[];
release_date: string;
revenue: number;
runtime: number;
spoken_languages: any[];
spoken_languages: SpokenLanguage[];
status: string;
tagline: string;
title: string;
@@ -129,7 +140,6 @@ export interface LatestMovie {
vote_count: number;
}
export interface Dates {
maximum: string;
minimum: string;

View File

@@ -4,5 +4,3 @@ export interface Search<T> {
total_pages: number;
total_results: number;
}

View File

@@ -1,4 +1,10 @@
import { Genre, ProductionCompany, ProductionCountry, SpokenLanguage, Crew } from './';
import {
Genre,
ProductionCompany,
ProductionCountry,
SpokenLanguage,
Crew,
} from './';
export interface CreatedBy {
id: number;
@@ -8,6 +14,21 @@ export interface CreatedBy {
profile_path: string;
}
export interface NextEpisodeToAir {
id: number;
name: string;
overview: string;
vote_average: number;
vote_count: number;
air_date: string;
episode_number: number;
production_code: string;
runtime: number;
season_number: number;
show_id: number;
still_path: string;
}
export interface LastEpisodeToAir {
air_date: string;
episode_number: number;
@@ -51,7 +72,7 @@ export interface TvShowDetails {
last_air_date: string;
last_episode_to_air: LastEpisodeToAir;
name: string;
next_episode_to_air?: any;
next_episode_to_air?: NextEpisodeToAir;
networks: Network[];
number_of_episodes: number;
number_of_seasons: number;
@@ -73,54 +94,53 @@ export interface TvShowDetails {
}
export interface GuestStar {
credit_id: string
order: number
character: string
adult: boolean
gender: number | null
id: number
known_for_department: string
name: string
original_name: string
popularity: number
profile_path: string | null
credit_id: string;
order: number;
character: string;
adult: boolean;
gender: number | null;
id: number;
known_for_department: string;
name: string;
original_name: string;
popularity: number;
profile_path: string | null;
}
export interface Episode {
air_date: string
episode_number: number
crew: Crew[]
guest_stars: GuestStar[]
id: number
name: string
overview: string
production_code: string
season_number: number
still_path: string
vote_average: number
vote_count: number
air_date: string;
episode_number: number;
crew: Crew[];
guest_stars: GuestStar[];
id: number;
name: string;
overview: string;
production_code: string;
season_number: number;
still_path: string;
vote_average: number;
vote_count: number;
show_id: number;
runtime: number;
}
export interface SeasonDetails {
air_date: string
episodes: Episode[]
name: string
overview: string
id: number
poster_path: string | null
season_number: number
air_date: string;
episodes: Episode[];
name: string;
overview: string;
id: number;
poster_path: string | null;
season_number: number;
}
export interface TvShowItem {
id: string;
action: string;
time: string;
value: any;
value: Array<number>;
iso_639_1: string;
original_value: any;
original_value: Array<number>;
}
export interface TvShowChange {
@@ -165,7 +185,6 @@ export interface ScreenedTheatrically {
results: ScreenedTheatricallyResult[];
}
export interface SimilarTvShow {
backdrop_path: string;
first_air_date: string;
@@ -190,8 +209,8 @@ export interface SimilarTvShows {
}
export interface LatestTvShows {
backdrop_path?: any;
created_by: any[];
backdrop_path?: string;
created_by: CreatedBy[];
episode_run_time: number[];
first_air_date: string;
genres: Genre[];
@@ -207,10 +226,10 @@ export interface LatestTvShows {
origin_country: string[];
original_language: string;
original_name: string;
overview?: any;
overview?: string;
popularity: number;
poster_path?: any;
production_companies: any[];
poster_path?: string;
production_companies: ProductionCompany[];
seasons: Season[];
status: string;
type: string;
@@ -218,7 +237,6 @@ export interface LatestTvShows {
vote_count: number;
}
export interface OnTheAirResult {
poster_path: string;
popularity: number;
@@ -242,7 +260,6 @@ export interface OnTheAir {
total_pages: number;
}
export interface AiringTodayResult {
poster_path: string;
popularity: number;
@@ -266,7 +283,6 @@ export interface TvShowsAiringToday {
total_pages: number;
}
export interface PopularTvShowResult {
poster_path: string;
popularity: number;
@@ -290,7 +306,6 @@ export interface PopularTvShows {
total_pages: number;
}
export interface TopRatedTvShowResult {
poster_path: string;
popularity: number;
@@ -313,5 +328,3 @@ export interface TopRatedTvShows {
total_results: number;
total_pages: number;
}

View File

@@ -1,4 +1,3 @@
export interface Flatrate {
display_priority: number;
logo_path: string;
@@ -20,7 +19,6 @@ export interface Buy {
provider_name: string;
}
export interface WatchLocale {
AR: {
link: string;
@@ -298,5 +296,3 @@ export interface WatchProviders {
id: number;
results: WatchLocale;
}

View File

@@ -8,7 +8,12 @@
* @param {string} imagePath raw image path
* @param {boolean} svg get svg version if true
*/
export const getFullImagePath = (baseUrl: string, fileSize: string, imagePath: string, svg = false): string => {
export const getFullImagePath = (
baseUrl: string,
fileSize: string,
imagePath: string,
svg = false
): string => {
const imagePathArr = imagePath.split('.');
const imageFormat = svg ? 'svg' : imagePathArr[1];

View File

@@ -1,7 +1,4 @@
export function parseOptions(
options?: { [s: string]: any },
): string {
return options
? new URLSearchParams(Object.entries(options)).toString()
: '';
export function parseOptions(options?: Record<string, any>): string {
/* eslint-disable @typescript-eslint/no-explicit-any */
return options ? new URLSearchParams(Object.entries(options)).toString() : '';
}

View File

@@ -1,28 +1,18 @@
{
"compilerOptions": {
"target": "es2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"target": "ES2022" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "CommonJS" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"moduleResolution": "node16",
"sourceMap": true /* Generates corresponding '.map' file. */,
"outDir": "dist" /* Redirect output structure to the directory. */,
"strict": true /* Enable all strict type-checking options. */,
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"types": ["node"],
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
"typeRoots": [
"./src/types"
]
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
"typeRoots": ["./src/types"]
},
"types": ["node"],
"include": [
"src"
],
"exclude": [
"node_modules",
"dist",
"./src/types/*.ts"
]
"include": ["src"],
"exclude": ["node_modules", "dist", "./src/types/*.ts"]
}