anilink-api-wrapper 1.19.0 → 1.20.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/README.md CHANGED
@@ -49,11 +49,13 @@ You can also initialize AniLink without an authentication token
49
49
  const aniLink = new AniLink();
50
50
  ```
51
51
 
52
- ## Structure
52
+ ## AniList API
53
+
54
+ ### Structure
53
55
 
54
56
  AniLink for AniList is divided into two main sections: `anilist.query` and `anilist.mutation`. The `anilist.query` section contains methods for querying data from the AniList API, while the `anilist.mutation` section contains methods for mutating data.
55
57
 
56
- ### Query Methods
58
+ #### Query Methods
57
59
 
58
60
  The `anilist.query` section is further divided into main query methods and page query methods. The main query methods return a single piece of data, while the page query methods return pages of data.
59
61
 
@@ -106,17 +108,18 @@ List of page query methods in `anilist.query.page`:
106
108
  - recommendations
107
109
  - likes
108
110
 
109
- ### Mutation Methods
111
+ #### Mutation Methods
110
112
 
111
113
  List of methods in `anilist.mutation`:
112
114
 
113
115
  - updateUser
114
116
  - saveMediaListEntry
115
117
  - updateMediaListEntries
118
+ - deleteMediaListEntries
119
+ - deleteCustomLists
120
+ - saveTextActivity
116
121
 
117
- ## Error Handling
118
-
119
- ### Anilist Errors
122
+ ### Error Handling
120
123
 
121
124
  AniLink will throw an error if the AniList API returns an error. You can catch these errors using a try-catch block.
122
125
 
@@ -131,7 +134,7 @@ try {
131
134
 
132
135
  This includes status codes and error messages returned by the AniList API. Here is an example rate limit handler to catch the errors thrown by AniLink:
133
136
 
134
- #### Typescript
137
+ ##### Typescript
135
138
 
136
139
  ```typescript
137
140
  async function handleRateLimit(apiCall: () => Promise<any>, retryAfter = 60) {
@@ -161,7 +164,7 @@ async function handleRateLimit(apiCall: () => Promise<any>, retryAfter = 60) {
161
164
  }
162
165
  ```
163
166
 
164
- #### Javascript
167
+ ##### Javascript
165
168
 
166
169
  ```javascript
167
170
  async function handleRateLimit(apiCall, retryAfter = 60) {
@@ -176,7 +179,7 @@ The possible error codes returned by the AniList API are:
176
179
  - 429: Too Many Requests (e.g. rate limit exceeded)
177
180
  - 500: Internal Server Error (e.g. AniList server error)
178
181
 
179
- ### Missing or Invalid Variables
182
+ #### Missing or Invalid Variables
180
183
 
181
184
  AniLink will also throw an error if any variables are missing or invalid. For example, if you try to query a user providing a string instead of a number for ID, AniLink will throw an error. Most variables are optional however there a few that are required.
182
185
  ```typescript
@@ -194,11 +197,11 @@ Example Error Thrown:
194
197
  Invalid id: 542244. Expected type: number
195
198
  ```
196
199
 
197
- ## Examples
200
+ ### Examples
198
201
 
199
202
  Here are examples of how to use AniLink to interact with the AniList API:
200
203
 
201
- ### Querying user data
204
+ #### Querying user data
202
205
 
203
206
  ```typescript
204
207
  // Querying user data
@@ -364,7 +367,7 @@ aniLink.anilist.query.page.likes({likeableId: 723422275, type: 'ACTIVITY', asHtm
364
367
  });
365
368
  ```
366
369
 
367
- ### Mutating user data
370
+ #### Mutating user data
368
371
 
369
372
  ```typescript
370
373
  // Updating a user
@@ -380,8 +383,8 @@ aniLink.anilist.mutation.updateUser({
380
383
  notificationOptions: [{type: 'AIRING', enabled: true}],
381
384
  timezone: '-06:00',
382
385
  activityMergeTime: 30,
383
- animeListOptions: {sectionOrder: ['title'], customLists: [], advancedScoring: [], advancedScoringEnabled: false},
384
- mangaListOptions: {sectionOrder: ['title'], customLists: [], advancedScoring: [], advancedScoringEnabled: false},
386
+ animeListOptions: {sectionOrder: ['title'], customLists: ['test'], advancedScoring: [], advancedScoringEnabled: false},
387
+ mangaListOptions: {sectionOrder: ['title'], customLists: ['test'], advancedScoring: [], advancedScoringEnabled: false},
385
388
  staffNameLanguage: 'ROMAJI',
386
389
  restrictMessagesToFollowing: false,
387
390
  disabledListActivity: [{type: 'CURRENT', disabled: false}]
@@ -389,7 +392,7 @@ aniLink.anilist.mutation.updateUser({
389
392
 
390
393
  // Saving media list entries
391
394
  aniLink.anilist.mutation.saveMediaListEntry({
392
- mediaId: 1,
395
+ mediaId: 143271,
393
396
  status: 'CURRENT',
394
397
  score: 8.5,
395
398
  progress: 3,
@@ -402,4 +405,27 @@ aniLink.anilist.mutation.updateMediaListEntries({
402
405
  progress: 3,
403
406
  ids: [143271, 156822, 170890],
404
407
  });
405
- ```
408
+
409
+ // Deleting custom list
410
+ aniLink.anilist.mutation.deleteCustomLists({customList: 'test'});
411
+
412
+ // Deleting media list entry
413
+ const entryId = (
414
+ await handleRateLimit(() => aniLink.anilist.query.mediaList(
415
+ {
416
+ userId: 6503722,
417
+ mediaId: 143271
418
+ }
419
+ ))).data.MediaList.id;
420
+ aniLink.anilist.mutation.deleteMediaListEntry({id: entryId});
421
+
422
+ // Create text activity
423
+ aniLink.anilist.mutation.saveTextActivity({text: 'test'})
424
+
425
+ // Update text activity
426
+ aniLink.anilist.mutation.saveTextActivity({id: 725254160, text: 'Updated Text'})
427
+ ```
428
+
429
+ ## License
430
+
431
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/dist/AniLink.js CHANGED
@@ -47,6 +47,9 @@ const UpdateUser_1 = require("./apis/anilist/mutation/UpdateUser");
47
47
  const User_1 = require("./apis/anilist/query/User");
48
48
  const Users_1 = require("./apis/anilist/query/page/Users");
49
49
  const Viewer_1 = require("./apis/anilist/query/Viewer");
50
+ const DeleteMediaListEntry_1 = require("./apis/anilist/mutation/DeleteMediaListEntry");
51
+ const DeleteCustomList_1 = require("./apis/anilist/mutation/DeleteCustomList");
52
+ const SaveTextActivity_1 = require("./apis/anilist/mutation/SaveTextActivity");
50
53
  /**
51
54
  * `AniLink` is a class for interacting with the APIs.
52
55
  * It provides methods for querying and mutating data.
@@ -103,6 +106,9 @@ class AniLink {
103
106
  const updateUserMutationInstance = new UpdateUser_1.UpdateUserMutation(authToken);
104
107
  const saveMediaListEntryMutationInstance = new SaveMediaListEntry_1.SaveMediaListEntryMutation(authToken);
105
108
  const updateMediaListEntriesMutationInstance = new UpdateMediaListEntries_1.UpdateMediaListEntriesMutation(authToken);
109
+ const deleteMediaListEntryMutationInstance = new DeleteMediaListEntry_1.DeleteMediaListEntryMutation(authToken);
110
+ const deleteCustomListMutationInstance = new DeleteCustomList_1.DeleteCustomListMutation(authToken);
111
+ const saveTextActivityMutationInstance = new SaveTextActivity_1.SaveTextActivityMutation(authToken);
106
112
  this.anilist = {
107
113
  query: {
108
114
  user: userQueryInstance.user.bind(userQueryInstance),
@@ -154,7 +160,10 @@ class AniLink {
154
160
  mutation: {
155
161
  updateUser: updateUserMutationInstance.updateUser.bind(updateUserMutationInstance),
156
162
  saveMediaListEntry: saveMediaListEntryMutationInstance.saveMediaListEntry.bind(saveMediaListEntryMutationInstance),
157
- updateMediaListEntries: updateMediaListEntriesMutationInstance.updateMediaListEntries.bind(updateMediaListEntriesMutationInstance)
163
+ updateMediaListEntries: updateMediaListEntriesMutationInstance.updateMediaListEntries.bind(updateMediaListEntriesMutationInstance),
164
+ deleteMediaListEntry: deleteMediaListEntryMutationInstance.deleteMediaListEntry.bind(deleteMediaListEntryMutationInstance),
165
+ deleteCustomList: deleteCustomListMutationInstance.deleteCustomList.bind(deleteCustomListMutationInstance),
166
+ saveTextActivity: saveTextActivityMutationInstance.saveTextActivity.bind(saveTextActivityMutationInstance)
158
167
  }
159
168
  };
160
169
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActivityWithRepliesSchema = exports.ActivitySchema = void 0;
3
+ exports.TextActivitySchema = exports.ActivityWithRepliesSchema = exports.ActivitySchema = void 0;
4
4
  const BasicUser_1 = require("./BasicUser");
5
5
  const ActivityReply_1 = require("./ActivityReply");
6
6
  /**
@@ -149,3 +149,30 @@ exports.ActivityWithRepliesSchema = `
149
149
  }
150
150
  }
151
151
  `;
152
+ /**
153
+ * `TextActivity` is an object representing a text activity.
154
+ * It includes the id, user id, type, reply count, text, site url, lock status, subscription status, like count, like status, pin status, creation date, user details, replies, and likes.
155
+ */
156
+ exports.TextActivitySchema = `
157
+ id
158
+ userId
159
+ type
160
+ replyCount
161
+ text (asHtml: $asHtml)
162
+ siteUrl
163
+ isLocked
164
+ isSubscribed
165
+ likeCount
166
+ isLiked
167
+ isPinned
168
+ createdAt
169
+ user {
170
+ ${BasicUser_1.BasicUserSchema}
171
+ }
172
+ replies {
173
+ ${ActivityReply_1.ActivityReplySchema}
174
+ }
175
+ likes {
176
+ ${BasicUser_1.BasicUserSchema}
177
+ }
178
+ `;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DeleteCustomListMutation = void 0;
13
+ const APIWrapper_1 = require("../../../base/APIWrapper");
14
+ const RequestHandler_1 = require("../../../base/RequestHandler");
15
+ const ValidateVariables_1 = require("../../../base/ValidateVariables");
16
+ const Type_1 = require("../types/Type");
17
+ /**
18
+ * `DeleteCustomListMutation` is a class representing a mutation to delete a custom list.
19
+ * It includes a method to delete a custom list
20
+ */
21
+ class DeleteCustomListMutation extends APIWrapper_1.APIWrapper {
22
+ /**
23
+ * Constructs a new `DeleteCustomListMutation` instance.
24
+ *
25
+ * @param authToken - The authentication token.
26
+ */
27
+ constructor(authToken) {
28
+ super('https://graphql.anilist.co');
29
+ this.authToken = authToken;
30
+ }
31
+ /**
32
+ * `deleteMediaListEntry` is a method that sends a mutation request to delete a custom list.
33
+ *
34
+ * @param variables - An object of type `DeleteCustomListVariables` representing the variables for the mutation.
35
+ * @returns A Promise that resolves to the response from the mutation request.
36
+ * @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
37
+ * */
38
+ deleteCustomList(variables) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ if (!variables.customList || !variables.type) {
41
+ throw new Error('customList & type variables are required');
42
+ }
43
+ const variableTypeMappings = {
44
+ customList: 'string',
45
+ type: Type_1.MediaTypeMappings
46
+ };
47
+ (0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
48
+ const mutation = `
49
+ mutation ($customList: String, $type: MediaType) {
50
+ DeleteCustomList(customList: $customList, type: $type) {
51
+ deleted
52
+ }
53
+ }
54
+ `;
55
+ const data = { query: mutation, variables };
56
+ return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
57
+ });
58
+ }
59
+ }
60
+ exports.DeleteCustomListMutation = DeleteCustomListMutation;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DeleteMediaListEntryMutation = void 0;
13
+ const APIWrapper_1 = require("../../../base/APIWrapper");
14
+ const RequestHandler_1 = require("../../../base/RequestHandler");
15
+ const ValidateVariables_1 = require("../../../base/ValidateVariables");
16
+ /**
17
+ * `DeleteMediaListEntryMutation` is a class representing a mutation to delete a media list entry.
18
+ * It includes a method to delete a media list entry.
19
+ */
20
+ class DeleteMediaListEntryMutation extends APIWrapper_1.APIWrapper {
21
+ /**
22
+ * Constructs a new `DeleteMediaListEntryMutation` instance.
23
+ *
24
+ * @param authToken - The authentication token.
25
+ */
26
+ constructor(authToken) {
27
+ super('https://graphql.anilist.co');
28
+ this.authToken = authToken;
29
+ }
30
+ /**
31
+ * `deleteMediaListEntry` is a method that sends a mutation request to delete a media list entry.
32
+ *
33
+ * @param variables - An object of type `DeleteMediaListEntryVariables` representing the variables for the mutation.
34
+ * @returns A Promise that resolves to the response from the mutation request.
35
+ * @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
36
+ * */
37
+ deleteMediaListEntry(variables) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (!variables.id) {
40
+ throw new Error('id variable is required');
41
+ }
42
+ const variableTypeMappings = {
43
+ id: 'number'
44
+ };
45
+ (0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
46
+ const mutation = `
47
+ mutation ($id: Int) {
48
+ DeleteMediaListEntry(id: $id) {
49
+ deleted
50
+ }
51
+ }
52
+ `;
53
+ const data = { query: mutation, variables };
54
+ return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
55
+ });
56
+ }
57
+ }
58
+ exports.DeleteMediaListEntryMutation = DeleteMediaListEntryMutation;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SaveTextActivityMutation = void 0;
13
+ const APIWrapper_1 = require("../../../base/APIWrapper");
14
+ const RequestHandler_1 = require("../../../base/RequestHandler");
15
+ const ValidateVariables_1 = require("../../../base/ValidateVariables");
16
+ const Activity_1 = require("../interfaces/Activity");
17
+ /**
18
+ * `SaveTextActivityMutation` is a class representing a mutation to save a text activity.
19
+ * It includes a method to save a text activity
20
+ */
21
+ class SaveTextActivityMutation extends APIWrapper_1.APIWrapper {
22
+ /**
23
+ * Constructs a new `SaveTextActivityMutation` instance.
24
+ *
25
+ * @param authToken - The authentication token.
26
+ */
27
+ constructor(authToken) {
28
+ super('https://graphql.anilist.co');
29
+ this.authToken = authToken;
30
+ }
31
+ /**
32
+ * `saveTextActivity` is a method that sends a mutation request to save a text activity.
33
+ *
34
+ * @param variables - An object of type `SaveTextActivityVariables` representing the variables for the mutation.
35
+ * @returns A Promise that resolves to the response from the mutation request.
36
+ * @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
37
+ * */
38
+ saveTextActivity(variables) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ if (!variables.id && !variables.text) {
41
+ throw new Error('id or text variable is required');
42
+ }
43
+ const variableTypeMappings = {
44
+ id: 'number',
45
+ text: 'string',
46
+ locked: 'boolean',
47
+ asHtml: 'boolean'
48
+ };
49
+ (0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
50
+ const mutation = `
51
+ mutation ($id: Int, $text: String, $locked: Boolean, $asHtml: Boolean) {
52
+ SaveTextActivity(id: $id, text: $text, locked:$locked) {
53
+ ${Activity_1.TextActivitySchema}
54
+ }
55
+ }
56
+ `;
57
+ const data = { query: mutation, variables };
58
+ return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
59
+ });
60
+ }
61
+ }
62
+ exports.SaveTextActivityMutation = SaveTextActivityMutation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anilink-api-wrapper",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "Anilist API Wrapper",
5
5
  "main": "dist/AniLink.js",
6
6
  "scripts": {