anilink-api-wrapper 1.0.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 (104) hide show
  1. package/.eslintignore +1 -0
  2. package/.github/workflows/code_quality.yml +32 -0
  3. package/.github/workflows/codeql.yml +33 -0
  4. package/.github/workflows/test.yml +30 -0
  5. package/LICENSE +21 -0
  6. package/README.md +1 -0
  7. package/__tests__/anilist.test.ts +268 -0
  8. package/babel.config.js +6 -0
  9. package/dist/AniLink.js +40 -0
  10. package/dist/apis/anilist/interfaces/ActivityHistory.js +2 -0
  11. package/dist/apis/anilist/interfaces/CoverImage.js +2 -0
  12. package/dist/apis/anilist/interfaces/Distribution.js +2 -0
  13. package/dist/apis/anilist/interfaces/ExternalLink.js +2 -0
  14. package/dist/apis/anilist/interfaces/Favoured.js +2 -0
  15. package/dist/apis/anilist/interfaces/FuzzyDate.js +2 -0
  16. package/dist/apis/anilist/interfaces/Image.js +2 -0
  17. package/dist/apis/anilist/interfaces/ListScores.js +2 -0
  18. package/dist/apis/anilist/interfaces/Media.js +2 -0
  19. package/dist/apis/anilist/interfaces/MediaListEntry.js +2 -0
  20. package/dist/apis/anilist/interfaces/MediaStatistics.js +2 -0
  21. package/dist/apis/anilist/interfaces/MediaStats.js +2 -0
  22. package/dist/apis/anilist/interfaces/Name.js +2 -0
  23. package/dist/apis/anilist/interfaces/NextAiringEpisode.js +2 -0
  24. package/dist/apis/anilist/interfaces/Ranking.js +2 -0
  25. package/dist/apis/anilist/interfaces/ScoreDistribution.js +2 -0
  26. package/dist/apis/anilist/interfaces/Staff.js +2 -0
  27. package/dist/apis/anilist/interfaces/Stat.js +2 -0
  28. package/dist/apis/anilist/interfaces/Statistics.js +2 -0
  29. package/dist/apis/anilist/interfaces/Stats.js +2 -0
  30. package/dist/apis/anilist/interfaces/StatusDistribution.js +2 -0
  31. package/dist/apis/anilist/interfaces/StreamingEpisode.js +2 -0
  32. package/dist/apis/anilist/interfaces/Studio.js +2 -0
  33. package/dist/apis/anilist/interfaces/Tag.js +2 -0
  34. package/dist/apis/anilist/interfaces/Title.js +2 -0
  35. package/dist/apis/anilist/interfaces/Trailer.js +2 -0
  36. package/dist/apis/anilist/interfaces/UserStats.js +2 -0
  37. package/dist/apis/anilist/interfaces/responses/AiringSchedule.js +2 -0
  38. package/dist/apis/anilist/interfaces/responses/Character.js +2 -0
  39. package/dist/apis/anilist/interfaces/responses/Media.js +2 -0
  40. package/dist/apis/anilist/interfaces/responses/MediaList.js +2 -0
  41. package/dist/apis/anilist/interfaces/responses/MediaListCollectionResponse.js +2 -0
  42. package/dist/apis/anilist/interfaces/responses/MediaTrend.js +2 -0
  43. package/dist/apis/anilist/interfaces/responses/Staff.js +2 -0
  44. package/dist/apis/anilist/interfaces/responses/User.js +2 -0
  45. package/dist/apis/anilist/mutation/UpdateUser.js +82 -0
  46. package/dist/apis/anilist/query/AiringSchedule.js +147 -0
  47. package/dist/apis/anilist/query/Character.js +69 -0
  48. package/dist/apis/anilist/query/Media.js +232 -0
  49. package/dist/apis/anilist/query/MediaList.js +170 -0
  50. package/dist/apis/anilist/query/MediaListCollection.js +650 -0
  51. package/dist/apis/anilist/query/MediaTrend.js +149 -0
  52. package/dist/apis/anilist/query/Staff.js +108 -0
  53. package/dist/apis/anilist/query/User.js +573 -0
  54. package/dist/base/APIWrapper.js +9 -0
  55. package/dist/base/RequestHandler.js +33 -0
  56. package/jest.config.js +11 -0
  57. package/package.json +31 -0
  58. package/src/AniLink.ts +80 -0
  59. package/src/apis/anilist/interfaces/ActivityHistory.ts +5 -0
  60. package/src/apis/anilist/interfaces/CoverImage.ts +6 -0
  61. package/src/apis/anilist/interfaces/Distribution.ts +4 -0
  62. package/src/apis/anilist/interfaces/ExternalLink.ts +5 -0
  63. package/src/apis/anilist/interfaces/Favoured.ts +15 -0
  64. package/src/apis/anilist/interfaces/FuzzyDate.ts +5 -0
  65. package/src/apis/anilist/interfaces/Image.ts +4 -0
  66. package/src/apis/anilist/interfaces/ListScores.ts +4 -0
  67. package/src/apis/anilist/interfaces/Media.ts +59 -0
  68. package/src/apis/anilist/interfaces/MediaListEntry.ts +4 -0
  69. package/src/apis/anilist/interfaces/MediaStatistics.ts +23 -0
  70. package/src/apis/anilist/interfaces/MediaStats.ts +7 -0
  71. package/src/apis/anilist/interfaces/Name.ts +8 -0
  72. package/src/apis/anilist/interfaces/NextAiringEpisode.ts +5 -0
  73. package/src/apis/anilist/interfaces/Ranking.ts +10 -0
  74. package/src/apis/anilist/interfaces/ScoreDistribution.ts +4 -0
  75. package/src/apis/anilist/interfaces/Staff.ts +6 -0
  76. package/src/apis/anilist/interfaces/Stat.ts +24 -0
  77. package/src/apis/anilist/interfaces/Statistics.ts +6 -0
  78. package/src/apis/anilist/interfaces/StatusDistribution.ts +4 -0
  79. package/src/apis/anilist/interfaces/StreamingEpisode.ts +6 -0
  80. package/src/apis/anilist/interfaces/Studio.ts +4 -0
  81. package/src/apis/anilist/interfaces/Tag.ts +10 -0
  82. package/src/apis/anilist/interfaces/Title.ts +6 -0
  83. package/src/apis/anilist/interfaces/Trailer.ts +5 -0
  84. package/src/apis/anilist/interfaces/UserStats.ts +25 -0
  85. package/src/apis/anilist/interfaces/responses/AiringSchedule.ts +10 -0
  86. package/src/apis/anilist/interfaces/responses/Character.ts +26 -0
  87. package/src/apis/anilist/interfaces/responses/Media.ts +118 -0
  88. package/src/apis/anilist/interfaces/responses/MediaList.ts +24 -0
  89. package/src/apis/anilist/interfaces/responses/MediaListCollectionResponse.ts +37 -0
  90. package/src/apis/anilist/interfaces/responses/MediaTrend.ts +13 -0
  91. package/src/apis/anilist/interfaces/responses/Staff.ts +53 -0
  92. package/src/apis/anilist/interfaces/responses/User.ts +72 -0
  93. package/src/apis/anilist/mutation/UpdateUser.ts +162 -0
  94. package/src/apis/anilist/query/AiringSchedule.ts +160 -0
  95. package/src/apis/anilist/query/Character.ts +75 -0
  96. package/src/apis/anilist/query/Media.ts +295 -0
  97. package/src/apis/anilist/query/MediaList.ts +192 -0
  98. package/src/apis/anilist/query/MediaListCollection.ts +673 -0
  99. package/src/apis/anilist/query/MediaTrend.ts +169 -0
  100. package/src/apis/anilist/query/Staff.ts +122 -0
  101. package/src/apis/anilist/query/User.ts +567 -0
  102. package/src/base/APIWrapper.ts +7 -0
  103. package/src/base/RequestHandler.ts +21 -0
  104. package/tsconfig.json +15 -0
@@ -0,0 +1,567 @@
1
+ import { APIWrapper } from '../../../base/APIWrapper'
2
+ import { sendRequest } from '../../../base/RequestHandler'
3
+ import { UserResponse } from '../interfaces/responses/User'
4
+
5
+ interface UserVariables {
6
+ id?: number
7
+ name?: string
8
+ isModerator?: boolean
9
+ search?: string
10
+ sort?: string[]
11
+ isHTML?: boolean
12
+ animeStatLimit?: number
13
+ mangaStatLimit?: number
14
+ animeStatSort?: string[]
15
+ mangaStatSort?: string[]
16
+ }
17
+
18
+ export class UserQuery extends APIWrapper {
19
+ private readonly authToken: string
20
+
21
+ constructor (authToken: string) {
22
+ super('https://graphql.anilist.co')
23
+ this.authToken = authToken
24
+ }
25
+
26
+ async user (variables?: UserVariables): Promise<UserResponse> {
27
+ // If isHTML is not provided in variables, default it to true
28
+ const { isHTML = true, ...rest } = variables != null ? variables : {}
29
+
30
+ const query = `
31
+ query ($id: Int, $name: String, $isModerator: Boolean, $search: String, $sort: [UserSort], $isHTML: Boolean, $animeStatLimit: Int, $mangaStatLimit: Int, $animeStatSort: [UserStatisticsSort], $mangaStatSort: [UserStatisticsSort]) {
32
+ User (id: $id, name: $name, isModerator: $isModerator, search: $search, sort: $sort) {
33
+ id
34
+ name
35
+ about(asHtml: $isHTML)
36
+ avatar {
37
+ large
38
+ medium
39
+ }
40
+ bannerImage
41
+ isFollowing
42
+ isFollower
43
+ isBlocked
44
+ bans
45
+ options {
46
+ titleLanguage
47
+ displayAdultContent
48
+ airingNotifications
49
+ profileColor
50
+ notificationOptions {
51
+ type
52
+ enabled
53
+ }
54
+ timezone
55
+ activityMergeTime
56
+ staffNameLanguage
57
+ restrictMessagesToFollowing
58
+ disabledListActivity {
59
+ disabled
60
+ type
61
+ }
62
+ }
63
+ mediaListOptions {
64
+ scoreFormat
65
+ rowOrder
66
+ animeList {
67
+ sectionOrder
68
+ splitCompletedSectionByFormat
69
+ customLists
70
+ advancedScoring
71
+ advancedScoringEnabled
72
+ }
73
+ mangaList {
74
+ sectionOrder
75
+ splitCompletedSectionByFormat
76
+ customLists
77
+ advancedScoring
78
+ advancedScoringEnabled
79
+ }
80
+ }
81
+ favourites {
82
+ anime (perPage: 50) {
83
+ edges {
84
+ node {
85
+ id
86
+ title {
87
+ romaji
88
+ english
89
+ native
90
+ userPreferred
91
+ }
92
+ }
93
+ }
94
+ nodes {
95
+ id
96
+ title {
97
+ romaji
98
+ english
99
+ native
100
+ userPreferred
101
+ }
102
+ }
103
+ }
104
+ manga (perPage: 50) {
105
+ edges {
106
+ node {
107
+ id
108
+ title {
109
+ romaji
110
+ english
111
+ native
112
+ userPreferred
113
+ }
114
+ }
115
+ }
116
+ nodes {
117
+ id
118
+ title {
119
+ romaji
120
+ english
121
+ native
122
+ userPreferred
123
+ }
124
+ }
125
+ }
126
+ characters (perPage: 50) {
127
+ edges {
128
+ id
129
+ role
130
+ name
131
+ voiceActors {
132
+ id
133
+ name {
134
+ first
135
+ last
136
+ full
137
+ native
138
+ }
139
+ image {
140
+ large
141
+ }
142
+ }
143
+ media {
144
+ id
145
+ title {
146
+ romaji
147
+ english
148
+ native
149
+ userPreferred
150
+ }
151
+ coverImage {
152
+ extraLarge
153
+ large
154
+ medium
155
+ color
156
+ }
157
+ }
158
+ favouriteOrder
159
+ node {
160
+ id
161
+ name {
162
+ first
163
+ last
164
+ full
165
+ native
166
+ }
167
+ image {
168
+ large
169
+ }
170
+ }
171
+ }
172
+ }
173
+ staff (perPage: 50) {
174
+ edges {
175
+ id
176
+ role
177
+ favouriteOrder
178
+ node {
179
+ id
180
+ name {
181
+ first
182
+ last
183
+ full
184
+ native
185
+ }
186
+ image {
187
+ large
188
+ }
189
+ }
190
+ }
191
+ }
192
+ studios (perPage: 50) {
193
+ edges {
194
+ id
195
+ isMain
196
+ favouriteOrder
197
+ node {
198
+ id
199
+ name
200
+ isAnimationStudio
201
+ siteUrl
202
+ }
203
+ }
204
+ }
205
+ }
206
+ statistics {
207
+ anime {
208
+ count
209
+ meanScore
210
+ standardDeviation
211
+ minutesWatched
212
+ episodesWatched
213
+ formats (limit: $animeStatLimit, sort: $animeStatSort) {
214
+ count
215
+ meanScore
216
+ minutesWatched
217
+ mediaIds
218
+ format
219
+ }
220
+ statuses (limit: $animeStatLimit, sort: $animeStatSort) {
221
+ count
222
+ meanScore
223
+ minutesWatched
224
+ mediaIds
225
+ status
226
+ }
227
+ scores (limit: $animeStatLimit, sort: $animeStatSort) {
228
+ count
229
+ meanScore
230
+ minutesWatched
231
+ mediaIds
232
+ score
233
+ }
234
+ lengths (limit: $animeStatLimit, sort: $animeStatSort) {
235
+ count
236
+ meanScore
237
+ minutesWatched
238
+ mediaIds
239
+ length
240
+ }
241
+ releaseYears (limit: $animeStatLimit, sort: $animeStatSort) {
242
+ count
243
+ meanScore
244
+ minutesWatched
245
+ mediaIds
246
+ releaseYear
247
+ }
248
+ startYears (limit: $animeStatLimit, sort: $animeStatSort) {
249
+ count
250
+ meanScore
251
+ minutesWatched
252
+ mediaIds
253
+ startYear
254
+ }
255
+ genres (limit: $animeStatLimit, sort: $animeStatSort) {
256
+ count
257
+ meanScore
258
+ minutesWatched
259
+ mediaIds
260
+ genre
261
+ }
262
+ tags (limit: $animeStatLimit, sort: $animeStatSort) {
263
+ count
264
+ meanScore
265
+ minutesWatched
266
+ mediaIds
267
+ tag {
268
+ id
269
+ name
270
+ description
271
+ category
272
+ rank
273
+ isGeneralSpoiler
274
+ isMediaSpoiler
275
+ isAdult
276
+ }
277
+ }
278
+ countries (limit: $animeStatLimit, sort: $animeStatSort) {
279
+ count
280
+ meanScore
281
+ minutesWatched
282
+ mediaIds
283
+ country
284
+ }
285
+ voiceActors (limit: $animeStatLimit, sort: $animeStatSort) {
286
+ count
287
+ meanScore
288
+ minutesWatched
289
+ mediaIds
290
+ voiceActor {
291
+ id
292
+ name {
293
+ first
294
+ last
295
+ full
296
+ native
297
+ alternative
298
+ userPreferred
299
+ }
300
+ }
301
+ characterIds
302
+ }
303
+ staff (limit: $animeStatLimit, sort: $animeStatSort) {
304
+ count
305
+ meanScore
306
+ minutesWatched
307
+ mediaIds
308
+ staff {
309
+ id
310
+ name {
311
+ first
312
+ last
313
+ full
314
+ native
315
+ alternative
316
+ userPreferred
317
+ }
318
+ }
319
+ }
320
+ studios (limit: $animeStatLimit, sort: $animeStatSort) {
321
+ count
322
+ meanScore
323
+ minutesWatched
324
+ mediaIds
325
+ studio {
326
+ id
327
+ name
328
+ }
329
+ }
330
+ }
331
+ manga {
332
+ count
333
+ meanScore
334
+ standardDeviation
335
+ chaptersRead
336
+ volumesRead
337
+ formats (limit: $mangaStatLimit, sort: $mangaStatSort) {
338
+ count
339
+ meanScore
340
+ chaptersRead
341
+ mediaIds
342
+ format
343
+ }
344
+ statuses (limit: $mangaStatLimit, sort: $mangaStatSort) {
345
+ count
346
+ meanScore
347
+ chaptersRead
348
+ mediaIds
349
+ status
350
+ }
351
+ scores (limit: $mangaStatLimit, sort: $mangaStatSort) {
352
+ count
353
+ meanScore
354
+ chaptersRead
355
+ mediaIds
356
+ score
357
+ }
358
+ lengths (limit: $mangaStatLimit, sort: $mangaStatSort) {
359
+ count
360
+ meanScore
361
+ chaptersRead
362
+ mediaIds
363
+ length
364
+ }
365
+ releaseYears (limit: $mangaStatLimit, sort: $mangaStatSort) {
366
+ count
367
+ meanScore
368
+ chaptersRead
369
+ mediaIds
370
+ releaseYear
371
+ }
372
+ startYears (limit: $mangaStatLimit, sort: $mangaStatSort) {
373
+ count
374
+ meanScore
375
+ chaptersRead
376
+ mediaIds
377
+ startYear
378
+ }
379
+ genres (limit: $mangaStatLimit, sort: $mangaStatSort) {
380
+ count
381
+ meanScore
382
+ chaptersRead
383
+ mediaIds
384
+ genre
385
+ }
386
+ tags (limit: $mangaStatLimit, sort: $mangaStatSort) {
387
+ count
388
+ meanScore
389
+ chaptersRead
390
+ mediaIds
391
+ tag {
392
+ id
393
+ name
394
+ description
395
+ category
396
+ rank
397
+ isGeneralSpoiler
398
+ isMediaSpoiler
399
+ isAdult
400
+ }
401
+ }
402
+ countries (limit: $mangaStatLimit, sort: $mangaStatSort) {
403
+ count
404
+ meanScore
405
+ chaptersRead
406
+ mediaIds
407
+ country
408
+ }
409
+ staff (limit: $mangaStatLimit, sort: $mangaStatSort) {
410
+ count
411
+ meanScore
412
+ chaptersRead
413
+ mediaIds
414
+ staff {
415
+ id
416
+ name {
417
+ first
418
+ last
419
+ full
420
+ native
421
+ alternative
422
+ userPreferred
423
+ }
424
+ }
425
+ }
426
+ studios (limit: $mangaStatLimit, sort: $mangaStatSort) {
427
+ count
428
+ meanScore
429
+ chaptersRead
430
+ mediaIds
431
+ studio {
432
+ id
433
+ name
434
+ }
435
+ }
436
+ }
437
+ }
438
+ stats {
439
+ watchedTime
440
+ chaptersRead
441
+ activityHistory {
442
+ date
443
+ amount
444
+ level
445
+ }
446
+ animeStatusDistribution {
447
+ status
448
+ amount
449
+ }
450
+ mangaStatusDistribution {
451
+ status
452
+ amount
453
+ }
454
+ animeScoreDistribution {
455
+ score
456
+ amount
457
+ }
458
+ mangaScoreDistribution {
459
+ score
460
+ amount
461
+ }
462
+ animeListScores {
463
+ meanScore
464
+ standardDeviation
465
+ }
466
+ mangaListScores {
467
+ meanScore
468
+ standardDeviation
469
+ }
470
+ favouredGenresOverview {
471
+ genre
472
+ amount
473
+ meanScore
474
+ timeWatched
475
+ }
476
+ favouredGenres {
477
+ genre
478
+ amount
479
+ meanScore
480
+ timeWatched
481
+ }
482
+ favouredTags {
483
+ tag {
484
+ id
485
+ name
486
+ description
487
+ category
488
+ rank
489
+ isGeneralSpoiler
490
+ isMediaSpoiler
491
+ isAdult
492
+ }
493
+ amount
494
+ meanScore
495
+ timeWatched
496
+ }
497
+ favouredActors {
498
+ staff {
499
+ id
500
+ name {
501
+ first
502
+ last
503
+ full
504
+ native
505
+ alternative
506
+ userPreferred
507
+ }
508
+ }
509
+ amount
510
+ meanScore
511
+ timeWatched
512
+ }
513
+ favouredStaff {
514
+ staff {
515
+ id
516
+ name {
517
+ first
518
+ last
519
+ full
520
+ native
521
+ alternative
522
+ userPreferred
523
+ }
524
+ }
525
+ amount
526
+ meanScore
527
+ timeWatched
528
+ }
529
+ favouredStudios {
530
+ studio {
531
+ id
532
+ name
533
+ }
534
+ amount
535
+ meanScore
536
+ timeWatched
537
+ }
538
+ favouredYears {
539
+ year
540
+ amount
541
+ meanScore
542
+ }
543
+ favouredFormats {
544
+ format
545
+ amount
546
+ }
547
+ }
548
+ unreadNotificationCount
549
+ siteUrl
550
+ donatorTier
551
+ donatorBadge
552
+ moderatorRoles
553
+ createdAt
554
+ updatedAt
555
+ previousNames {
556
+ name
557
+ createdAt
558
+ updatedAt
559
+ }
560
+ }
561
+ }
562
+ `
563
+
564
+ const data = { query, variables: { isHTML, ...rest } }
565
+ return await sendRequest(this.baseURL, 'POST', data, this.authToken)
566
+ }
567
+ }
@@ -0,0 +1,7 @@
1
+ export class APIWrapper {
2
+ protected baseURL: string
3
+
4
+ constructor (baseURL: string) {
5
+ this.baseURL = baseURL
6
+ }
7
+ }
@@ -0,0 +1,21 @@
1
+ import axios, { AxiosResponse } from 'axios'
2
+
3
+ export const sendRequest = async (url: string, method: 'GET' | 'POST', data?: object, token?: string): Promise<any> => {
4
+ const headers: { [key: string]: string } = {
5
+ 'Content-Type': 'application/json',
6
+ Accept: 'application/json'
7
+ }
8
+
9
+ if (token !== null && token !== undefined && token !== '') {
10
+ headers.Authorization = `Bearer ${token}`
11
+ }
12
+
13
+ const response: AxiosResponse = await axios({
14
+ url,
15
+ method,
16
+ data,
17
+ headers
18
+ })
19
+
20
+ return response.data
21
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "target": "es6",
5
+ "module": "commonjs",
6
+ "outDir": "./dist",
7
+ "strict": true,
8
+ "esModuleInterop": true
9
+ },
10
+ "include": ["src/**/*.ts"],
11
+ "exclude": [
12
+ "node_modules",
13
+ "__tests__"
14
+ ]
15
+ }