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.
- package/.eslintignore +1 -0
- package/.github/workflows/code_quality.yml +32 -0
- package/.github/workflows/codeql.yml +33 -0
- package/.github/workflows/test.yml +30 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/__tests__/anilist.test.ts +268 -0
- package/babel.config.js +6 -0
- package/dist/AniLink.js +40 -0
- package/dist/apis/anilist/interfaces/ActivityHistory.js +2 -0
- package/dist/apis/anilist/interfaces/CoverImage.js +2 -0
- package/dist/apis/anilist/interfaces/Distribution.js +2 -0
- package/dist/apis/anilist/interfaces/ExternalLink.js +2 -0
- package/dist/apis/anilist/interfaces/Favoured.js +2 -0
- package/dist/apis/anilist/interfaces/FuzzyDate.js +2 -0
- package/dist/apis/anilist/interfaces/Image.js +2 -0
- package/dist/apis/anilist/interfaces/ListScores.js +2 -0
- package/dist/apis/anilist/interfaces/Media.js +2 -0
- package/dist/apis/anilist/interfaces/MediaListEntry.js +2 -0
- package/dist/apis/anilist/interfaces/MediaStatistics.js +2 -0
- package/dist/apis/anilist/interfaces/MediaStats.js +2 -0
- package/dist/apis/anilist/interfaces/Name.js +2 -0
- package/dist/apis/anilist/interfaces/NextAiringEpisode.js +2 -0
- package/dist/apis/anilist/interfaces/Ranking.js +2 -0
- package/dist/apis/anilist/interfaces/ScoreDistribution.js +2 -0
- package/dist/apis/anilist/interfaces/Staff.js +2 -0
- package/dist/apis/anilist/interfaces/Stat.js +2 -0
- package/dist/apis/anilist/interfaces/Statistics.js +2 -0
- package/dist/apis/anilist/interfaces/Stats.js +2 -0
- package/dist/apis/anilist/interfaces/StatusDistribution.js +2 -0
- package/dist/apis/anilist/interfaces/StreamingEpisode.js +2 -0
- package/dist/apis/anilist/interfaces/Studio.js +2 -0
- package/dist/apis/anilist/interfaces/Tag.js +2 -0
- package/dist/apis/anilist/interfaces/Title.js +2 -0
- package/dist/apis/anilist/interfaces/Trailer.js +2 -0
- package/dist/apis/anilist/interfaces/UserStats.js +2 -0
- package/dist/apis/anilist/interfaces/responses/AiringSchedule.js +2 -0
- package/dist/apis/anilist/interfaces/responses/Character.js +2 -0
- package/dist/apis/anilist/interfaces/responses/Media.js +2 -0
- package/dist/apis/anilist/interfaces/responses/MediaList.js +2 -0
- package/dist/apis/anilist/interfaces/responses/MediaListCollectionResponse.js +2 -0
- package/dist/apis/anilist/interfaces/responses/MediaTrend.js +2 -0
- package/dist/apis/anilist/interfaces/responses/Staff.js +2 -0
- package/dist/apis/anilist/interfaces/responses/User.js +2 -0
- package/dist/apis/anilist/mutation/UpdateUser.js +82 -0
- package/dist/apis/anilist/query/AiringSchedule.js +147 -0
- package/dist/apis/anilist/query/Character.js +69 -0
- package/dist/apis/anilist/query/Media.js +232 -0
- package/dist/apis/anilist/query/MediaList.js +170 -0
- package/dist/apis/anilist/query/MediaListCollection.js +650 -0
- package/dist/apis/anilist/query/MediaTrend.js +149 -0
- package/dist/apis/anilist/query/Staff.js +108 -0
- package/dist/apis/anilist/query/User.js +573 -0
- package/dist/base/APIWrapper.js +9 -0
- package/dist/base/RequestHandler.js +33 -0
- package/jest.config.js +11 -0
- package/package.json +31 -0
- package/src/AniLink.ts +80 -0
- package/src/apis/anilist/interfaces/ActivityHistory.ts +5 -0
- package/src/apis/anilist/interfaces/CoverImage.ts +6 -0
- package/src/apis/anilist/interfaces/Distribution.ts +4 -0
- package/src/apis/anilist/interfaces/ExternalLink.ts +5 -0
- package/src/apis/anilist/interfaces/Favoured.ts +15 -0
- package/src/apis/anilist/interfaces/FuzzyDate.ts +5 -0
- package/src/apis/anilist/interfaces/Image.ts +4 -0
- package/src/apis/anilist/interfaces/ListScores.ts +4 -0
- package/src/apis/anilist/interfaces/Media.ts +59 -0
- package/src/apis/anilist/interfaces/MediaListEntry.ts +4 -0
- package/src/apis/anilist/interfaces/MediaStatistics.ts +23 -0
- package/src/apis/anilist/interfaces/MediaStats.ts +7 -0
- package/src/apis/anilist/interfaces/Name.ts +8 -0
- package/src/apis/anilist/interfaces/NextAiringEpisode.ts +5 -0
- package/src/apis/anilist/interfaces/Ranking.ts +10 -0
- package/src/apis/anilist/interfaces/ScoreDistribution.ts +4 -0
- package/src/apis/anilist/interfaces/Staff.ts +6 -0
- package/src/apis/anilist/interfaces/Stat.ts +24 -0
- package/src/apis/anilist/interfaces/Statistics.ts +6 -0
- package/src/apis/anilist/interfaces/StatusDistribution.ts +4 -0
- package/src/apis/anilist/interfaces/StreamingEpisode.ts +6 -0
- package/src/apis/anilist/interfaces/Studio.ts +4 -0
- package/src/apis/anilist/interfaces/Tag.ts +10 -0
- package/src/apis/anilist/interfaces/Title.ts +6 -0
- package/src/apis/anilist/interfaces/Trailer.ts +5 -0
- package/src/apis/anilist/interfaces/UserStats.ts +25 -0
- package/src/apis/anilist/interfaces/responses/AiringSchedule.ts +10 -0
- package/src/apis/anilist/interfaces/responses/Character.ts +26 -0
- package/src/apis/anilist/interfaces/responses/Media.ts +118 -0
- package/src/apis/anilist/interfaces/responses/MediaList.ts +24 -0
- package/src/apis/anilist/interfaces/responses/MediaListCollectionResponse.ts +37 -0
- package/src/apis/anilist/interfaces/responses/MediaTrend.ts +13 -0
- package/src/apis/anilist/interfaces/responses/Staff.ts +53 -0
- package/src/apis/anilist/interfaces/responses/User.ts +72 -0
- package/src/apis/anilist/mutation/UpdateUser.ts +162 -0
- package/src/apis/anilist/query/AiringSchedule.ts +160 -0
- package/src/apis/anilist/query/Character.ts +75 -0
- package/src/apis/anilist/query/Media.ts +295 -0
- package/src/apis/anilist/query/MediaList.ts +192 -0
- package/src/apis/anilist/query/MediaListCollection.ts +673 -0
- package/src/apis/anilist/query/MediaTrend.ts +169 -0
- package/src/apis/anilist/query/Staff.ts +122 -0
- package/src/apis/anilist/query/User.ts +567 -0
- package/src/base/APIWrapper.ts +7 -0
- package/src/base/RequestHandler.ts +21 -0
- package/tsconfig.json +15 -0
package/.eslintignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/__tests__/*
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Qodana
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
pull_request:
|
|
6
|
+
push:
|
|
7
|
+
branches:
|
|
8
|
+
- master
|
|
9
|
+
- 'releases/*'
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
qodana:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
pull-requests: write
|
|
17
|
+
checks: write
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
with:
|
|
21
|
+
ref: ${{ github.event.pull_request.head.sha }}
|
|
22
|
+
fetch-depth: 0
|
|
23
|
+
- name: Setup Node.js environment
|
|
24
|
+
uses: actions/setup-node@v4.0.2
|
|
25
|
+
with:
|
|
26
|
+
node-version: '21'
|
|
27
|
+
cache: 'npm'
|
|
28
|
+
- run: npm ci
|
|
29
|
+
- name: 'Qodana Scan'
|
|
30
|
+
uses: JetBrains/qodana-action@v2023.3.1
|
|
31
|
+
env:
|
|
32
|
+
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "CodeQL"
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["master"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["master"]
|
|
8
|
+
schedule:
|
|
9
|
+
- cron: '0 7 * * 1'
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
analyze:
|
|
13
|
+
name: Analyze
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
security-events: write
|
|
17
|
+
actions: read
|
|
18
|
+
contents: read
|
|
19
|
+
strategy:
|
|
20
|
+
fail-fast: false
|
|
21
|
+
matrix:
|
|
22
|
+
language: ['javascript-typescript']
|
|
23
|
+
steps:
|
|
24
|
+
- name: Checkout repository
|
|
25
|
+
uses: actions/checkout@v4
|
|
26
|
+
- name: Initialize CodeQL
|
|
27
|
+
uses: github/codeql-action/init@v3
|
|
28
|
+
with:
|
|
29
|
+
languages: ${{ matrix.language }}
|
|
30
|
+
- name: Perform CodeQL Analysis
|
|
31
|
+
uses: github/codeql-action/analyze@v3
|
|
32
|
+
with:
|
|
33
|
+
category: "/language:${{matrix.language}}"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Run Jest Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["master"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["master"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Use Node.js
|
|
17
|
+
uses: actions/setup-node@v4
|
|
18
|
+
with:
|
|
19
|
+
node-version: '21'
|
|
20
|
+
|
|
21
|
+
- name: Install Dependencies
|
|
22
|
+
run: npm ci
|
|
23
|
+
|
|
24
|
+
- name: Build Project
|
|
25
|
+
run: npm run build
|
|
26
|
+
|
|
27
|
+
- name: Run Jest
|
|
28
|
+
run: npm run test
|
|
29
|
+
env:
|
|
30
|
+
ANILIST_TOKEN: ${{ secrets.ANILIST_TOKEN }}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 RLAlpha49
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# AniLink
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
require('dotenv').config()
|
|
2
|
+
import AniLink from '../dist/AniLink.js'
|
|
3
|
+
// import AniLink from '../src/AniLink'
|
|
4
|
+
|
|
5
|
+
async function handleRateLimit(apiCall: () => Promise<any>, retryAfter = 60) {
|
|
6
|
+
try {
|
|
7
|
+
return await apiCall();
|
|
8
|
+
} catch (error: any) {
|
|
9
|
+
if (error.response && error.response.status === 429) {
|
|
10
|
+
console.log('Rate limit exceeded, waiting for 1 minute before retrying...');
|
|
11
|
+
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
|
|
12
|
+
console.log('Retrying...');
|
|
13
|
+
return handleRateLimit(apiCall, retryAfter);
|
|
14
|
+
} else {
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('Anilist API Query', () => {
|
|
21
|
+
let aniLink: AniLink
|
|
22
|
+
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
const token = process.env.ANILIST_TOKEN
|
|
25
|
+
aniLink = new AniLink(token)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('user query', async () => {
|
|
29
|
+
try {
|
|
30
|
+
const response = await handleRateLimit(() => aniLink.anilist.query.user({ id: 542244, isHTML: true }))
|
|
31
|
+
console.log(response)
|
|
32
|
+
expect(response).toBeDefined()
|
|
33
|
+
} catch (error: any) {
|
|
34
|
+
if (error.response.data) {
|
|
35
|
+
throw error.response.data
|
|
36
|
+
} else {
|
|
37
|
+
throw error.response
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('user query should handle errors', async () => {
|
|
43
|
+
try {
|
|
44
|
+
await handleRateLimit(() => aniLink.anilist.query.user({ id: 'invalid', isHTML: false }))
|
|
45
|
+
} catch (error: any) {
|
|
46
|
+
expect(error).toBeDefined()
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('media query', async () => {
|
|
51
|
+
try {
|
|
52
|
+
const response = await handleRateLimit(() => aniLink.anilist.query.media({ id: 1, type: 'ANIME' }))
|
|
53
|
+
console.log(response)
|
|
54
|
+
expect(response).toBeDefined()
|
|
55
|
+
} catch (error: any) {
|
|
56
|
+
if (error.response.data) {
|
|
57
|
+
throw error.response.data
|
|
58
|
+
} else {
|
|
59
|
+
throw error.response
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('media query should handle errors', async () => {
|
|
65
|
+
try {
|
|
66
|
+
await handleRateLimit(() => aniLink.anilist.query.media({ id: 'invalid', type: 'ANIME' }))
|
|
67
|
+
} catch (error: any) {
|
|
68
|
+
expect(error).toBeDefined()
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('media trend query', async () => {
|
|
73
|
+
try {
|
|
74
|
+
const response = await handleRateLimit(() => aniLink.anilist.query.mediaTrend({ mediaId: 1, type: 'ANIME' }))
|
|
75
|
+
console.log(response)
|
|
76
|
+
expect(response).toBeDefined()
|
|
77
|
+
} catch (error: any) {
|
|
78
|
+
if (error.response.data) {
|
|
79
|
+
throw error.response.data
|
|
80
|
+
} else {
|
|
81
|
+
throw error.response
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('media trend query should handle errors', async () => {
|
|
87
|
+
try {
|
|
88
|
+
await handleRateLimit(() => aniLink.anilist.query.mediaTrend({ mediaId: 'invalid', type: 'ANIME' }))
|
|
89
|
+
} catch (error: any) {
|
|
90
|
+
expect(error).toBeDefined()
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('airing schedule query should return a response', async () => {
|
|
95
|
+
try {
|
|
96
|
+
const response = await handleRateLimit(() => aniLink.anilist.query.airingSchedule({ mediaId: 130590 })) // id needs to be an airing anime
|
|
97
|
+
console.log(response)
|
|
98
|
+
expect(response).toBeDefined()
|
|
99
|
+
} catch (error: any) {
|
|
100
|
+
if (error.response.data) {
|
|
101
|
+
throw error.response.data
|
|
102
|
+
} else {
|
|
103
|
+
throw error.response
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('airing schedule query should handle errors', async () => {
|
|
109
|
+
try {
|
|
110
|
+
await handleRateLimit(() => aniLink.anilist.query.airingSchedule({ mediaId: 'invalid' }))
|
|
111
|
+
} catch (error) {
|
|
112
|
+
expect(error).toBeDefined()
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('character query should return a response', async () => {
|
|
117
|
+
try {
|
|
118
|
+
const response = await handleRateLimit(() => aniLink.anilist.query.character({ id: 1, asHtml: true, mediaSort: ['POPULARITY_DESC'], mediaType: 'ANIME', mediaOnList: true, mediaPage: 1, mediaPerPage: 10 }))
|
|
119
|
+
console.log(response)
|
|
120
|
+
expect(response).toBeDefined()
|
|
121
|
+
} catch (error: any) {
|
|
122
|
+
if (error.response.data) {
|
|
123
|
+
throw error.response.data
|
|
124
|
+
} else {
|
|
125
|
+
throw error.response
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('character query should handle errors', async () => {
|
|
131
|
+
try {
|
|
132
|
+
await handleRateLimit(() => aniLink.anilist.query.character({ id: 'invalid', asHtml: true, mediaSort: ['POPULARITY_DESC'], mediaOnList: true, mediaPage: 1, mediaPerPage: 10 }))
|
|
133
|
+
} catch (error) {
|
|
134
|
+
expect(error).toBeDefined()
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('staff query should return a response', async () => {
|
|
139
|
+
try {
|
|
140
|
+
const response = await handleRateLimit(() => aniLink.anilist.query.staff({
|
|
141
|
+
id: 132186,
|
|
142
|
+
asHtml: true,
|
|
143
|
+
staffMediaSort: ['POPULARITY_DESC'],
|
|
144
|
+
staffMediaType: 'ANIME',
|
|
145
|
+
staffMediaOnList: true,
|
|
146
|
+
staffMediaPage: 1,
|
|
147
|
+
staffMediaPerPage: 10,
|
|
148
|
+
charactersSort: ['ID'],
|
|
149
|
+
charactersPage: 1,
|
|
150
|
+
charactersPerPage: 10,
|
|
151
|
+
characterMediaSort: ['POPULARITY_DESC'],
|
|
152
|
+
characterMediaOnList: true,
|
|
153
|
+
characterMediaPage: 1,
|
|
154
|
+
characterMediaPerPage: 10
|
|
155
|
+
}))
|
|
156
|
+
console.log(response)
|
|
157
|
+
expect(response).toBeDefined()
|
|
158
|
+
} catch (error: any) {
|
|
159
|
+
if (error.response.data) {
|
|
160
|
+
throw error.response.data
|
|
161
|
+
} else {
|
|
162
|
+
throw error.response
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('staff query should handle errors', async () => {
|
|
168
|
+
try {
|
|
169
|
+
await handleRateLimit(() => aniLink.anilist.query.staff({
|
|
170
|
+
id: 'invalid'
|
|
171
|
+
}))
|
|
172
|
+
} catch (error) {
|
|
173
|
+
expect(error).toBeDefined()
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('media list query should return a response', async () => {
|
|
178
|
+
try {
|
|
179
|
+
const response = await handleRateLimit(() => aniLink.anilist.query.mediaList({ userId: 542244 }))
|
|
180
|
+
console.log(response)
|
|
181
|
+
expect(response).toBeDefined()
|
|
182
|
+
} catch (error: any) {
|
|
183
|
+
if (error.response.data) {
|
|
184
|
+
throw error.response.data
|
|
185
|
+
} else {
|
|
186
|
+
throw error.response
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
test('media list query should handle errors', async () => {
|
|
192
|
+
try {
|
|
193
|
+
await handleRateLimit(() => aniLink.anilist.query.mediaList({ userId: 'invalid' }))
|
|
194
|
+
} catch (error) {
|
|
195
|
+
expect(error).toBeDefined()
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('media list collection query should return a response', async () => {
|
|
200
|
+
try {
|
|
201
|
+
const response = await handleRateLimit(() => aniLink.anilist.query.mediaListCollection({
|
|
202
|
+
userId: 542244,
|
|
203
|
+
type: 'ANIME',
|
|
204
|
+
status: 'COMPLETED',
|
|
205
|
+
chunk: 1,
|
|
206
|
+
perChunk: 10
|
|
207
|
+
}))
|
|
208
|
+
console.log(response)
|
|
209
|
+
expect(response).toBeDefined()
|
|
210
|
+
} catch (error: any) {
|
|
211
|
+
if (error.response.data) {
|
|
212
|
+
throw error.response.data
|
|
213
|
+
} else {
|
|
214
|
+
throw error.response
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
test('media list collection query should handle errors', async () => {
|
|
220
|
+
try {
|
|
221
|
+
await handleRateLimit(() => aniLink.anilist.query.mediaListCollection({
|
|
222
|
+
userId: 'invalid'
|
|
223
|
+
}))
|
|
224
|
+
} catch (error) {
|
|
225
|
+
expect(error).toBeDefined()
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
describe('Anilist API Mutation', () => {
|
|
231
|
+
let aniLink: AniLink
|
|
232
|
+
|
|
233
|
+
beforeAll(() => {
|
|
234
|
+
const token = process.env.ANILIST_TOKEN
|
|
235
|
+
aniLink = new AniLink(token)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
test('update user', async () => {
|
|
239
|
+
try {
|
|
240
|
+
const response = await handleRateLimit(() => aniLink.anilist.mutation.updateUser({
|
|
241
|
+
about: 'New about text',
|
|
242
|
+
titleLanguage: 'ENGLISH',
|
|
243
|
+
displayAdultContent: true,
|
|
244
|
+
airingNotifications: true,
|
|
245
|
+
scoreFormat: 'POINT_10',
|
|
246
|
+
rowOrder: 'title',
|
|
247
|
+
profileColor: 'blue',
|
|
248
|
+
donatorBadge: 'Supporter',
|
|
249
|
+
notificationOptions: [{ type: 'AIRING', enabled: true }],
|
|
250
|
+
timezone: '-06:00',
|
|
251
|
+
activityMergeTime: 30,
|
|
252
|
+
animeListOptions: { sectionOrder: ['title'], customLists: [], advancedScoring: [], advancedScoringEnabled: false },
|
|
253
|
+
mangaListOptions: { sectionOrder: ['title'], customLists: [], advancedScoring: [], advancedScoringEnabled: false },
|
|
254
|
+
staffNameLanguage: 'ROMAJI',
|
|
255
|
+
restrictMessagesToFollowing: false,
|
|
256
|
+
disabledListActivity: [{ type: 'CURRENT', disabled: false }]
|
|
257
|
+
}))
|
|
258
|
+
console.log(response)
|
|
259
|
+
expect(response).toBeDefined()
|
|
260
|
+
} catch (error: any) {
|
|
261
|
+
if (error.response.data) {
|
|
262
|
+
throw error.response.data
|
|
263
|
+
} else {
|
|
264
|
+
throw error.response
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
})
|
package/babel.config.js
ADDED
package/dist/AniLink.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const User_1 = require("./apis/anilist/query/User");
|
|
4
|
+
const Media_1 = require("./apis/anilist/query/Media");
|
|
5
|
+
const MediaTrend_1 = require("./apis/anilist/query/MediaTrend");
|
|
6
|
+
const AiringSchedule_1 = require("./apis/anilist/query/AiringSchedule");
|
|
7
|
+
const Character_1 = require("./apis/anilist/query/Character");
|
|
8
|
+
const MediaList_1 = require("./apis/anilist/query/MediaList");
|
|
9
|
+
const Staff_1 = require("./apis/anilist/query/Staff");
|
|
10
|
+
const MediaListCollection_1 = require("./apis/anilist/query/MediaListCollection");
|
|
11
|
+
const UpdateUser_1 = require("./apis/anilist/mutation/UpdateUser");
|
|
12
|
+
class AniLink {
|
|
13
|
+
constructor(authToken) {
|
|
14
|
+
const userQueryInstance = new User_1.UserQuery(authToken);
|
|
15
|
+
const mediaQueryInstance = new Media_1.MediaQuery(authToken);
|
|
16
|
+
const mediaTrendQueryInstance = new MediaTrend_1.MediaTrendQuery(authToken);
|
|
17
|
+
const airingScheduleQueryInstance = new AiringSchedule_1.AiringScheduleQuery(authToken);
|
|
18
|
+
const characterQueryInstance = new Character_1.CharacterQuery(authToken);
|
|
19
|
+
const staffQueryInstance = new Staff_1.StaffQuery(authToken);
|
|
20
|
+
const mediaListQueryInstance = new MediaList_1.MediaListQuery(authToken);
|
|
21
|
+
const mediaListCollectionQueryInstance = new MediaListCollection_1.MediaListCollectionQuery(authToken);
|
|
22
|
+
const updateUserMutationInstance = new UpdateUser_1.UpdateUserMutation(authToken);
|
|
23
|
+
this.anilist = {
|
|
24
|
+
query: {
|
|
25
|
+
user: userQueryInstance.user.bind(userQueryInstance),
|
|
26
|
+
media: mediaQueryInstance.media.bind(mediaQueryInstance),
|
|
27
|
+
mediaTrend: mediaTrendQueryInstance.mediaTrend.bind(mediaTrendQueryInstance),
|
|
28
|
+
airingSchedule: airingScheduleQueryInstance.airingSchedule.bind(airingScheduleQueryInstance),
|
|
29
|
+
character: characterQueryInstance.character.bind(characterQueryInstance),
|
|
30
|
+
staff: staffQueryInstance.staff.bind(staffQueryInstance),
|
|
31
|
+
mediaList: mediaListQueryInstance.mediaList.bind(mediaListQueryInstance),
|
|
32
|
+
mediaListCollection: mediaListCollectionQueryInstance.mediaListCollection.bind(mediaListQueryInstance)
|
|
33
|
+
},
|
|
34
|
+
mutation: {
|
|
35
|
+
updateUser: updateUserMutationInstance.updateUser.bind(updateUserMutationInstance)
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
module.exports = AniLink;
|