@tutkli/jikan-ts 0.5.41 → 0.5.42

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 (42) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/clients/anime.client.js +227 -0
  3. package/dist/clients/base.client.js +31 -0
  4. package/dist/clients/index.js +7 -0
  5. package/dist/clients/jikan.client.js +26 -0
  6. package/dist/clients/manga.client.js +141 -0
  7. package/dist/clients/top.client.js +54 -0
  8. package/dist/config/cache.config.js +10 -0
  9. package/dist/config/index.js +5 -0
  10. package/dist/config/logger.config.js +28 -0
  11. package/dist/constants/base.constant.js +7 -0
  12. package/dist/constants/endpoints.constant.js +33 -0
  13. package/dist/constants/index.js +5 -0
  14. package/dist/index.d.ts +664 -670
  15. package/dist/index.js +7 -647
  16. package/dist/models/Anime/anime-character.model.js +2 -0
  17. package/dist/models/Anime/anime-episode.model.js +2 -0
  18. package/dist/models/Anime/anime-picture.model.js +2 -0
  19. package/dist/models/Anime/anime-staff.model.js +2 -0
  20. package/dist/models/Anime/anime-statistics.model.js +2 -0
  21. package/dist/models/Anime/anime-video.model.js +2 -0
  22. package/dist/models/Anime/anime.model.js +34 -0
  23. package/dist/models/Anime/index.js +10 -0
  24. package/dist/models/Common/character.model.js +8 -0
  25. package/dist/models/Common/image.model.js +2 -0
  26. package/dist/models/Common/index.js +9 -0
  27. package/dist/models/Common/person.model.js +2 -0
  28. package/dist/models/Common/recommendation.model.js +2 -0
  29. package/dist/models/Common/resource.model.js +2 -0
  30. package/dist/models/Common/statistics.model.js +2 -0
  31. package/dist/models/Manga/index.js +5 -0
  32. package/dist/models/Manga/manga-statistics.model.js +2 -0
  33. package/dist/models/Manga/manga.model.js +21 -0
  34. package/dist/models/Params/index.js +5 -0
  35. package/dist/models/Params/search-params.model.js +32 -0
  36. package/dist/models/Params/top-params.model.js +17 -0
  37. package/dist/models/Response/index.js +4 -0
  38. package/dist/models/Response/response.model.js +2 -0
  39. package/dist/models/index.js +8 -0
  40. package/package.json +1 -1
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v0.5.42 (13/11/2022)
2
+
3
+ ### Models
4
+
5
+ - Fix typo in anime model
6
+
7
+ <!-- CHANGELOG SPLIT MARKER -->
8
+
1
9
  # v0.5.4 (13/11/2022)
2
10
 
3
11
  ### Build
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnimeClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const base_client_1 = require("./base.client");
6
+ const constants_1 = require("../constants");
7
+ /**
8
+ * **Anime Client**
9
+ *
10
+ * Client used to access the Anime Endpoints:
11
+ * - [AnimeSearch](https://docs.api.jikan.moe/#tag/anime)
12
+ * - [AnimeFullById](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeFullById)
13
+ * - [AnimeById](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeById)
14
+ * - [AnimeCharacters](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeCharacters)
15
+ * - [AnimeStaff](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeStaff)
16
+ * - [AnimeEpisodes](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeEpisodes)
17
+ * - [AnimeEpisodeById](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeEpisodeById)
18
+ * - [AnimeVideos](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeVideos)
19
+ * - [AnimeVideosEpisodes](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeVideosEpisodes)
20
+ * - [AnimePictures](https://docs.api.jikan.moe/#tag/anime/operation/getAnimePictures)
21
+ * - [AnimeStatistics](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeStatistics)
22
+ * - [AnimeRecommendations](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeRecommendations)
23
+ *
24
+ * See also: [JikanAPI](https://docs.api.jikan.moe/)
25
+ */
26
+ class AnimeClient extends base_client_1.BaseClient {
27
+ /**
28
+ * @argument clientOptions Options for the client.
29
+ */
30
+ constructor(clientOptions) {
31
+ super(clientOptions);
32
+ }
33
+ /**
34
+ * Get all the filtered Animes. Returns all the Animes if no filters are given.
35
+ * @param searchParams Filter parameters
36
+ * @returns A JikanResponse with Anime data
37
+ */
38
+ getAnimeSearch(searchParams) {
39
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
40
+ return new Promise((resolve, reject) => {
41
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeSearch}`;
42
+ this.api
43
+ .get(endpoint, { params: searchParams })
44
+ .then((response) => resolve(response.data))
45
+ .catch((error) => reject(error));
46
+ });
47
+ });
48
+ }
49
+ /**
50
+ * Get a complete Anime resource data
51
+ * @param mal_id The Anime ID
52
+ * @returns A JikanUniqueResponse with Anime data
53
+ */
54
+ getAnimeFullById(mal_id) {
55
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
56
+ return new Promise((resolve, reject) => {
57
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeFullById.replace('{id}', String(mal_id))}`;
58
+ this.api
59
+ .get(endpoint)
60
+ .then((response) => resolve(response.data))
61
+ .catch((error) => reject(error));
62
+ });
63
+ });
64
+ }
65
+ /**
66
+ * Get Anime resource data
67
+ * @param mal_id The Anime ID
68
+ * @returns A JikanUniqueResponse with Anime data
69
+ */
70
+ getAnimeById(mal_id) {
71
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
72
+ return new Promise((resolve, reject) => {
73
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeById.replace('{id}', String(mal_id))}`;
74
+ this.api
75
+ .get(endpoint)
76
+ .then((response) => resolve(response.data))
77
+ .catch((error) => reject(error));
78
+ });
79
+ });
80
+ }
81
+ /**
82
+ * Get Characters of a specific Anime
83
+ * @param mal_id The Anime ID
84
+ * @returns A JikanResponse with AnimeCharacter data
85
+ */
86
+ getAnimeCharacters(mal_id) {
87
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
+ return new Promise((resolve, reject) => {
89
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeCharacters.replace('{id}', String(mal_id))}`;
90
+ this.api
91
+ .get(endpoint)
92
+ .then((response) => resolve(response.data))
93
+ .catch((error) => reject(error));
94
+ });
95
+ });
96
+ }
97
+ /**
98
+ * Get Staff of a specific Anime
99
+ * @param mal_id The Anime ID
100
+ * @returns A JikanResponse with AnimeStaff data
101
+ */
102
+ getAnimeStaff(mal_id) {
103
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
104
+ return new Promise((resolve, reject) => {
105
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeStaff.replace('{id}', String(mal_id))}`;
106
+ this.api
107
+ .get(endpoint)
108
+ .then((response) => resolve(response.data))
109
+ .catch((error) => reject(error));
110
+ });
111
+ });
112
+ }
113
+ /**
114
+ * Get a list of all the episodes of a specific Anime
115
+ * @param mal_id The Anime ID
116
+ * @returns A JikanResponse with AnimeEpisode data
117
+ */
118
+ getAnimeEpisodes(mal_id) {
119
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
120
+ return new Promise((resolve, reject) => {
121
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeEpisodes.replace('{id}', String(mal_id))}`;
122
+ this.api
123
+ .get(endpoint)
124
+ .then((response) => resolve(response.data))
125
+ .catch((error) => reject(error));
126
+ });
127
+ });
128
+ }
129
+ /**
130
+ * Get a single Episode of a specific Anime by its ID
131
+ * @param anime_mal_id The Anime ID
132
+ * @param episode_mal_id The Episode ID
133
+ * @returns A JikanUniqueResponse with AnimeEpisode data
134
+ */
135
+ getAnimeEpisodeById(anime_mal_id, episode_mal_id) {
136
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
137
+ return new Promise((resolve, reject) => {
138
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeEpisodeById.replace('{id}', String(anime_mal_id)).replace('{episode}', String(episode_mal_id))}`;
139
+ this.api
140
+ .get(endpoint)
141
+ .then((response) => resolve(response.data))
142
+ .catch((error) => reject(error));
143
+ });
144
+ });
145
+ }
146
+ /**
147
+ * Get Videos related to a specific Anime
148
+ * @param mal_id The Anime ID
149
+ * @returns A JikanUniqueResponse with AnimeVideo data
150
+ */
151
+ getAnimeVideos(mal_id) {
152
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
153
+ return new Promise((resolve, reject) => {
154
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeVideos.replace('{id}', String(mal_id))}`;
155
+ this.api
156
+ .get(endpoint)
157
+ .then((response) => resolve(response.data))
158
+ .catch((error) => reject(error));
159
+ });
160
+ });
161
+ }
162
+ /**
163
+ * Get Episode Videos related to a specific Anime
164
+ * @param mal_id The Anime ID
165
+ * @returns A JikanResponse with AnimeVideoEpisode data
166
+ */
167
+ getAnimeVideosEpisode(mal_id) {
168
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
169
+ return new Promise((resolve, reject) => {
170
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeVideosEpisodes.replace('{id}', String(mal_id))}`;
171
+ this.api
172
+ .get(endpoint)
173
+ .then((response) => resolve(response.data))
174
+ .catch((error) => reject(error));
175
+ });
176
+ });
177
+ }
178
+ /**
179
+ * Get Pictures related to a specific Anime
180
+ * @param mal_id The Anime ID
181
+ * @returns A JikanResponse with AnimePicture data
182
+ */
183
+ getAnimePictures(mal_id) {
184
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
185
+ return new Promise((resolve, reject) => {
186
+ const endpoint = `${constants_1.AnimeEndpoints.AnimePictures.replace('{id}', String(mal_id))}`;
187
+ this.api
188
+ .get(endpoint)
189
+ .then((response) => resolve(response.data))
190
+ .catch((error) => reject(error));
191
+ });
192
+ });
193
+ }
194
+ /**
195
+ * Get Statistics related to a specific Anime
196
+ * @param mal_id The Anime ID
197
+ * @returns A JikanUniqueResponse with AnimeStatistics data
198
+ */
199
+ getAnimeStatistics(mal_id) {
200
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
201
+ return new Promise((resolve, reject) => {
202
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeStatistics.replace('{id}', String(mal_id))}`;
203
+ this.api
204
+ .get(endpoint)
205
+ .then((response) => resolve(response.data))
206
+ .catch((error) => reject(error));
207
+ });
208
+ });
209
+ }
210
+ /**
211
+ * Get Recommendations related to a specific Anime
212
+ * @param mal_id The Anime ID
213
+ * @returns A JikanResponse with Recommendation data
214
+ */
215
+ getAnimeRecommendation(mal_id) {
216
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
217
+ return new Promise((resolve, reject) => {
218
+ const endpoint = `${constants_1.AnimeEndpoints.AnimeRecommendations.replace('{id}', String(mal_id))}`;
219
+ this.api
220
+ .get(endpoint)
221
+ .then((response) => resolve(response.data))
222
+ .catch((error) => reject(error));
223
+ });
224
+ });
225
+ }
226
+ }
227
+ exports.AnimeClient = AnimeClient;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const axios_cache_interceptor_1 = require("axios-cache-interceptor");
6
+ const axios_1 = tslib_1.__importDefault(require("axios"));
7
+ const constants_1 = require("../constants");
8
+ const config_1 = require("../config");
9
+ /**
10
+ * **Base Client** This client is responsible for creating an Axios Instance and the cache and logging configurations
11
+ */
12
+ class BaseClient {
13
+ constructor(clientOptions) {
14
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
15
+ this.api = (0, axios_cache_interceptor_1.setupCache)(axios_1.default.create({
16
+ baseURL: (_a = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.baseURL) !== null && _a !== void 0 ? _a : constants_1.BaseURL.REST,
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ },
20
+ }), {
21
+ storage: (_c = (_b = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.cacheOptions) === null || _b === void 0 ? void 0 : _b.storage) !== null && _c !== void 0 ? _c : config_1.DEFAULT_CACHE_OPTIONS.storage,
22
+ generateKey: (_e = (_d = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.cacheOptions) === null || _d === void 0 ? void 0 : _d.generateKey) !== null && _e !== void 0 ? _e : config_1.DEFAULT_CACHE_OPTIONS.generateKey,
23
+ headerInterpreter: (_g = (_f = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.cacheOptions) === null || _f === void 0 ? void 0 : _f.headerInterpreter) !== null && _g !== void 0 ? _g : config_1.DEFAULT_CACHE_OPTIONS.headerInterpreter,
24
+ debug: (_j = (_h = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.cacheOptions) === null || _h === void 0 ? void 0 : _h.debug) !== null && _j !== void 0 ? _j : config_1.DEFAULT_CACHE_OPTIONS.debug,
25
+ });
26
+ this.logger = (0, config_1.createLogger)(Object.assign({ enabled: !(((_k = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.logOptions) === null || _k === void 0 ? void 0 : _k.enabled) === undefined || (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.logOptions.enabled) === false) }, clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.logOptions));
27
+ this.api.interceptors.request.use((config) => (0, config_1.handleRequest)(config, this.logger), (error) => (0, config_1.handleRequestError)(error, this.logger));
28
+ this.api.interceptors.response.use((response) => (0, config_1.handleResponse)(response, this.logger), (error) => (0, config_1.handleResponseError)(error, this.logger));
29
+ }
30
+ }
31
+ exports.BaseClient = BaseClient;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./base.client"), exports);
5
+ tslib_1.__exportStar(require("./anime.client"), exports);
6
+ tslib_1.__exportStar(require("./manga.client"), exports);
7
+ tslib_1.__exportStar(require("./jikan.client"), exports);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JikanClient = void 0;
4
+ const base_client_1 = require("./base.client");
5
+ const anime_client_1 = require("./anime.client");
6
+ const manga_client_1 = require("./manga.client");
7
+ const top_client_1 = require("./top.client");
8
+ /**
9
+ * **Jikan Client**
10
+ *
11
+ * The main client used to access all the JikanAPI Endpoints:
12
+ * - [Anime](https://docs.api.jikan.moe/#tag/anime)
13
+ * - [Manga](https://docs.api.jikan.moe/#tag/manga)
14
+ * - [Top](https://docs.api.jikan.moe/#tag/top)
15
+ *
16
+ * See also: [JikanAPI Documentation](https://docs.api.jikan.moe/)
17
+ */
18
+ class JikanClient extends base_client_1.BaseClient {
19
+ constructor(clientOptions) {
20
+ super(clientOptions);
21
+ this.anime = new anime_client_1.AnimeClient(clientOptions);
22
+ this.manga = new manga_client_1.MangaClient(clientOptions);
23
+ this.top = new top_client_1.TopClient(clientOptions);
24
+ }
25
+ }
26
+ exports.JikanClient = JikanClient;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MangaClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const base_client_1 = require("./base.client");
6
+ const constants_1 = require("../constants");
7
+ /**
8
+ * **Manga Client**
9
+ *
10
+ * Client used to access the Manga Endpoints:
11
+ * - [MangaSearch](https://docs.api.jikan.moe/#tag/manga)
12
+ * - [MangaFullById](https://docs.api.jikan.moe/#tag/manga/operation/getMangaFullById)
13
+ * - [MangaById](https://docs.api.jikan.moe/#tag/manga/operation/getMangaById)
14
+ * - [MangaCharacters](https://docs.api.jikan.moe/#tag/manga/operation/getMangaCharacters)
15
+ * - [MangaPictures](https://docs.api.jikan.moe/#tag/manga/operation/getMangaPictures)
16
+ * - [MangaStatistics](https://docs.api.jikan.moe/#tag/manga/operation/getMangaStatistics)
17
+ * - [MangaRecommendations](https://docs.api.jikan.moe/#tag/manga/operation/getMangaRecommendations)
18
+ *
19
+ * See also: [JikanAPI Documentation](https://docs.api.jikan.moe/)
20
+ */
21
+ class MangaClient extends base_client_1.BaseClient {
22
+ /**
23
+ * @argument clientOptions Options for the client.
24
+ */
25
+ constructor(clientOptions) {
26
+ super(clientOptions);
27
+ }
28
+ /**
29
+ * Get all the filtered Mangas. Returns all the Mangas if no filters are given.
30
+ * @param searchParams Filter parameters
31
+ * @returns A JikanResponse with Manga data
32
+ */
33
+ getMangaSearch(searchParams) {
34
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ return new Promise((resolve, reject) => {
36
+ const endpoint = `${constants_1.MangaEndpoints.MangaSearch}`;
37
+ this.api
38
+ .get(endpoint, { params: searchParams })
39
+ .then((response) => resolve(response.data))
40
+ .catch((error) => reject(error));
41
+ });
42
+ });
43
+ }
44
+ /**
45
+ * Get a Manga with full information by its ID
46
+ * @param mal_id The Manga ID
47
+ * @returns A JikanUniqueResponse with Manga data
48
+ */
49
+ getMangaFullById(mal_id) {
50
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
51
+ return new Promise((resolve, reject) => {
52
+ const endpoint = `${constants_1.MangaEndpoints.MangaFullById.replace('{id}', String(mal_id))}`;
53
+ this.api
54
+ .get(endpoint)
55
+ .then((response) => resolve(response.data))
56
+ .catch((error) => reject(error));
57
+ });
58
+ });
59
+ }
60
+ /**
61
+ * Get a Manga by its ID
62
+ * @param mal_id The Manga ID
63
+ * @returns A JikanUniqueResponse with Manga data
64
+ */
65
+ getMangaById(mal_id) {
66
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
67
+ return new Promise((resolve, reject) => {
68
+ const endpoint = `${constants_1.MangaEndpoints.MangaById.replace('{id}', String(mal_id))}`;
69
+ this.api
70
+ .get(endpoint)
71
+ .then((response) => resolve(response.data))
72
+ .catch((error) => reject(error));
73
+ });
74
+ });
75
+ }
76
+ /**
77
+ * Get Characters of a specific Manga
78
+ * @param mal_id The Manga ID
79
+ * @returns A JikanResponse with CommonCharacter data
80
+ */
81
+ getMangaCharacters(mal_id) {
82
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
83
+ return new Promise((resolve, reject) => {
84
+ const endpoint = `${constants_1.MangaEndpoints.MangaCharacters.replace('{id}', String(mal_id))}`;
85
+ this.api
86
+ .get(endpoint)
87
+ .then((response) => resolve(response.data))
88
+ .catch((error) => reject(error));
89
+ });
90
+ });
91
+ }
92
+ /**
93
+ * Get Pictures related to a specific Manga
94
+ * @param mal_id The Manga ID
95
+ * @returns A JikanResponse with JikanImages data
96
+ */
97
+ getMangaPictures(mal_id) {
98
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
99
+ return new Promise((resolve, reject) => {
100
+ const endpoint = `${constants_1.MangaEndpoints.MangaPictures.replace('{id}', String(mal_id))}`;
101
+ this.api
102
+ .get(endpoint)
103
+ .then((response) => resolve(response.data))
104
+ .catch((error) => reject(error));
105
+ });
106
+ });
107
+ }
108
+ /**
109
+ * Get Statistics related to a specific Manga
110
+ * @param mal_id The Manga ID
111
+ * @returns A JikanUniqueResponse with MangaStatistics data
112
+ */
113
+ getAnimeStatistics(mal_id) {
114
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
115
+ return new Promise((resolve, reject) => {
116
+ const endpoint = `${constants_1.MangaEndpoints.MangaStatistics.replace('{id}', String(mal_id))}`;
117
+ this.api
118
+ .get(endpoint)
119
+ .then((response) => resolve(response.data))
120
+ .catch((error) => reject(error));
121
+ });
122
+ });
123
+ }
124
+ /**
125
+ * Get Recommendations related to a specific Manga
126
+ * @param mal_id The Manga ID
127
+ * @returns A JikanResponse with Recommendation data
128
+ */
129
+ getMangaRecommendation(mal_id) {
130
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
131
+ return new Promise((resolve, reject) => {
132
+ const endpoint = `${constants_1.MangaEndpoints.MangaRecommendations.replace('{id}', String(mal_id))}`;
133
+ this.api
134
+ .get(endpoint)
135
+ .then((response) => resolve(response.data))
136
+ .catch((error) => reject(error));
137
+ });
138
+ });
139
+ }
140
+ }
141
+ exports.MangaClient = MangaClient;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TopClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const base_client_1 = require("./base.client");
6
+ const constants_1 = require("../constants");
7
+ /**
8
+ * **Anime Client**
9
+ *
10
+ * Client used to access the Top Endpoints:
11
+ * - [TopAnime](https://docs.api.jikan.moe/#tag/top/operation/getTopAnime)
12
+ * - [TopManga](https://docs.api.jikan.moe/#tag/top/operation/getTopManga)
13
+ *
14
+ * See also: [JikanAPI Documentation](https://docs.api.jikan.moe/)
15
+ */
16
+ class TopClient extends base_client_1.BaseClient {
17
+ /**
18
+ * @argument clientOptions Options for the client.
19
+ */
20
+ constructor(clientOptions) {
21
+ super(clientOptions);
22
+ }
23
+ /**
24
+ * Get the top Animes
25
+ * @returns A JikanResponse with Anime data
26
+ */
27
+ getTopAnime(searchParams) {
28
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
+ return new Promise((resolve, reject) => {
30
+ const endpoint = `${constants_1.TopEndpoints.TopAnime}`;
31
+ this.api
32
+ .get(endpoint, { params: searchParams })
33
+ .then((response) => resolve(response.data))
34
+ .catch((error) => reject(error));
35
+ });
36
+ });
37
+ }
38
+ /**
39
+ * Get the top Mangas
40
+ * @returns A JikanResponse with Manga data
41
+ */
42
+ getTopManga(searchParams) {
43
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
44
+ return new Promise((resolve, reject) => {
45
+ const endpoint = `${constants_1.TopEndpoints.TopManga}`;
46
+ this.api
47
+ .get(endpoint, { params: searchParams })
48
+ .then((response) => resolve(response.data))
49
+ .catch((error) => reject(error));
50
+ });
51
+ });
52
+ }
53
+ }
54
+ exports.TopClient = TopClient;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_CACHE_OPTIONS = void 0;
4
+ const axios_cache_interceptor_1 = require("axios-cache-interceptor");
5
+ exports.DEFAULT_CACHE_OPTIONS = {
6
+ storage: (0, axios_cache_interceptor_1.buildMemoryStorage)(),
7
+ generateKey: axios_cache_interceptor_1.defaultKeyGenerator,
8
+ headerInterpreter: axios_cache_interceptor_1.defaultHeaderInterpreter,
9
+ debug: undefined,
10
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./cache.config"), exports);
5
+ tslib_1.__exportStar(require("./logger.config"), exports);
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleResponseError = exports.handleResponse = exports.handleRequestError = exports.handleRequest = exports.createLogger = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pino_1 = tslib_1.__importDefault(require("pino"));
6
+ const createLogger = (options) => (0, pino_1.default)(options);
7
+ exports.createLogger = createLogger;
8
+ const handleRequest = (config, logger) => {
9
+ var _a;
10
+ logger.info(`[ Request Config ] ${((_a = config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || ''} | ${config.url || ''}`);
11
+ return config;
12
+ };
13
+ exports.handleRequest = handleRequest;
14
+ const handleRequestError = (error, logger) => {
15
+ logger.error(`[ Request Error] CODE ${error.code || 'UNKNOWN'} | ${error.message}`);
16
+ throw error;
17
+ };
18
+ exports.handleRequestError = handleRequestError;
19
+ const handleResponse = (response, logger) => {
20
+ logger.info(response.data);
21
+ return response;
22
+ };
23
+ exports.handleResponse = handleResponse;
24
+ const handleResponseError = (error, logger) => {
25
+ logger.error(`[ Response Error ] CODE ${error.code || 'UNKNOWN'} | ${error.message}`);
26
+ throw error;
27
+ };
28
+ exports.handleResponseError = handleResponseError;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseURL = void 0;
4
+ var BaseURL;
5
+ (function (BaseURL) {
6
+ BaseURL["REST"] = "https://api.jikan.moe/v4";
7
+ })(BaseURL = exports.BaseURL || (exports.BaseURL = {}));
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TopEndpoints = exports.MangaEndpoints = exports.AnimeEndpoints = void 0;
4
+ var AnimeEndpoints;
5
+ (function (AnimeEndpoints) {
6
+ AnimeEndpoints["AnimeSearch"] = "/anime";
7
+ AnimeEndpoints["AnimeFullById"] = "/anime/{id}/full";
8
+ AnimeEndpoints["AnimeById"] = "/anime/{id}";
9
+ AnimeEndpoints["AnimeCharacters"] = "/anime/{id}/characters";
10
+ AnimeEndpoints["AnimeStaff"] = "/anime/{id}/staff";
11
+ AnimeEndpoints["AnimeEpisodes"] = "/anime/{id}/episodes";
12
+ AnimeEndpoints["AnimeEpisodeById"] = "/anime/{id}/episodes/{episode}";
13
+ AnimeEndpoints["AnimeVideos"] = "/anime/{id}/videos";
14
+ AnimeEndpoints["AnimeVideosEpisodes"] = "/anime/{id}/videos/episodes";
15
+ AnimeEndpoints["AnimePictures"] = "/anime/{id}/pictures";
16
+ AnimeEndpoints["AnimeStatistics"] = "/anime/{id}/statistics";
17
+ AnimeEndpoints["AnimeRecommendations"] = "/anime/{id}/recommendations";
18
+ })(AnimeEndpoints = exports.AnimeEndpoints || (exports.AnimeEndpoints = {}));
19
+ var MangaEndpoints;
20
+ (function (MangaEndpoints) {
21
+ MangaEndpoints["MangaSearch"] = "/manga";
22
+ MangaEndpoints["MangaFullById"] = "/manga/{id}/full";
23
+ MangaEndpoints["MangaById"] = "/manga/{id}";
24
+ MangaEndpoints["MangaCharacters"] = "/manga/{id}/characters";
25
+ MangaEndpoints["MangaPictures"] = "/manga/{id}/pictures";
26
+ MangaEndpoints["MangaStatistics"] = "/manga/{id}/statistics";
27
+ MangaEndpoints["MangaRecommendations"] = "/manga/{id}/recommendations";
28
+ })(MangaEndpoints = exports.MangaEndpoints || (exports.MangaEndpoints = {}));
29
+ var TopEndpoints;
30
+ (function (TopEndpoints) {
31
+ TopEndpoints["TopAnime"] = "/top/anime";
32
+ TopEndpoints["TopManga"] = "/top/manga";
33
+ })(TopEndpoints = exports.TopEndpoints || (exports.TopEndpoints = {}));
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./base.constant"), exports);
5
+ tslib_1.__exportStar(require("./endpoints.constant"), exports);