@irfanshadikrishad/anilist 2.0.0-forbidden.1 → 3.0.1-forbidden.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/.husky/pre-commit CHANGED
@@ -1,3 +1,3 @@
1
- npm run format
1
+ npm run build
2
2
  npm run test
3
- git add .
3
+ npx lint-staged
@@ -0,0 +1,4 @@
1
+ {
2
+ "*.{js,jsx,ts,tsx}": ["prettier --write"],
3
+ "*.{json,md,yml,yaml}": ["prettier --write"]
4
+ }
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Minimalist unofficial AniList CLI for Anime and Manga Enthusiasts.
4
4
 
5
- ![NPM Version](https://img.shields.io/npm/v/%40irfanshadikrishad%2Fanilist?style=for-the-badge&color=%23adc178)
6
- ![NPM Downloads](https://img.shields.io/npm/dw/%40irfanshadikrishad%2Fanilist?style=for-the-badge&color=%23eaac8b)
7
- ![NPM License](https://img.shields.io/npm/l/%40irfanshadikrishad%2Fanilist?style=for-the-badge&color=%23f2d0a4)
5
+ ![NPM Version](https://img.shields.io/npm/v/%40irfanshadikrishad%2Fanilist%2Fforbidden?style=for-the-badge&labelColor=141b23&color=%2385c1dc)
6
+ ![NPM Downloads](https://img.shields.io/npm/dw/%40irfanshadikrishad%2Fanilist?style=for-the-badge&labelColor=141b23&color=%2385c1dc)
7
+ ![NPM License](https://img.shields.io/npm/l/%40irfanshadikrishad%2Fanilist?style=for-the-badge&labelColor=141b23&color=%2385c1dc)
8
8
 
9
9
  #### How to install?
10
10
 
@@ -20,7 +20,7 @@ If you see the version then its installed. Otherwise install nodejs and npm shou
20
20
  Then install the package by running
21
21
 
22
22
  ```bash
23
- npm install -g @irfanshadikrishad/anilist
23
+ npm install -g @irfanshadikrishad/anilist@forbidden
24
24
  ```
25
25
 
26
26
  This will install the package globally. And you have to use commands like
@@ -18,11 +18,13 @@ import { exit } from 'process';
18
18
  import Spinner from 'tiny-spinner';
19
19
  import { fetcher } from './fetcher.js';
20
20
  import { colorize } from './lib/colorize.js';
21
+ import { rate_limit_time_ms, symbol_done, symbol_fail, symbol_neutral, } from './lib/constants.js';
22
+ import { renderUserProfile } from './lib/render.js';
21
23
  import { AniDB, AniList, MyAnimeList } from './lists.js';
22
- import { deleteActivityMutation, deleteMangaEntryMutation, deleteMediaEntryMutation, likeActivityMutation, saveTextActivityMutation, toggleFollowMutation, } from './mutations.js';
24
+ import { deleteMangaEntryMutation, deleteMediaEntryMutation, likeActivityMutation, saveTextActivityMutation, toggleFollowMutation, } from './mutations.js';
23
25
  import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, followingActivitiesQuery, globalActivitiesQuery, specificUserActivitiesQuery, userActivityQuery, userFollowersQuery, userFollowingQuery, userQuery, } from './queries.js';
24
26
  import { responsiveOutput } from './truncate.js';
25
- import { activityBy, aniListEndpoint, getTitle, redirectUri, sleep, timestampToTimeAgo, } from './workers.js';
27
+ import { activityBy, aniListEndpoint, deleteActivities, getTitle, redirectUri, sleep, timestampToTimeAgo, } from './workers.js';
26
28
  const home_dir = os.homedir();
27
29
  const save_path = path.join(home_dir, '.anilist_token');
28
30
  const spinner = new Spinner();
@@ -70,12 +72,10 @@ class Auth {
70
72
  static RetriveAccessToken() {
71
73
  return __awaiter(this, void 0, void 0, function* () {
72
74
  try {
73
- if (fs.existsSync(save_path)) {
74
- return vigenere.decrypt(fs.readFileSync(save_path, { encoding: 'utf8' }));
75
- }
76
- else {
75
+ if (!fs.existsSync(save_path)) {
77
76
  return null;
78
77
  }
78
+ return vigenere.decrypt(fs.readFileSync(save_path, { encoding: 'utf8' }));
79
79
  }
80
80
  catch (error) {
81
81
  console.error(`\nError retriving acess-token. ${error.message}`);
@@ -105,19 +105,13 @@ class Auth {
105
105
  }),
106
106
  });
107
107
  const token_Data = yield tokenResponse.json();
108
- if (token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token) {
109
- yield Auth.StoreAccessToken(token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token);
110
- const name = yield Auth.MyUserName();
111
- if (name) {
112
- console.log(`\nWelcome Back, ${name}!`);
113
- }
114
- else {
115
- console.log(`\nLogged in successfull!`);
116
- }
117
- }
118
- else {
108
+ if (!(token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token)) {
119
109
  console.error('\nFailed to get access token:', token_Data);
110
+ return;
120
111
  }
112
+ yield Auth.StoreAccessToken(token_Data.access_token);
113
+ const name = yield Auth.MyUserName();
114
+ console.log(name ? `\nWelcome Back, ${name}!` : '\nLogged in successfully!');
121
115
  }
122
116
  catch (error) {
123
117
  console.error(`\nFailed logging in. ${error.message}`);
@@ -126,81 +120,53 @@ class Auth {
126
120
  }
127
121
  static Myself() {
128
122
  return __awaiter(this, void 0, void 0, function* () {
129
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
123
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
130
124
  try {
131
- if (yield Auth.isLoggedIn()) {
132
- const headers = {
125
+ if (!(yield Auth.isLoggedIn())) {
126
+ console.error('\nPlease login first to use this feature.');
127
+ return null;
128
+ }
129
+ const accessToken = yield Auth.RetriveAccessToken();
130
+ const request = yield fetch(aniListEndpoint, {
131
+ method: 'POST',
132
+ headers: {
133
133
  'Content-Type': 'application/json',
134
- 'Authorization': `Bearer ${yield Auth.RetriveAccessToken()}`,
135
- };
136
- const request = yield fetch(aniListEndpoint, {
137
- method: 'POST',
138
- headers: headers,
139
- body: JSON.stringify({ query: currentUserQuery }),
140
- });
141
- const { data, errors } = yield request.json();
142
- if (request.status === 200) {
143
- const user = data === null || data === void 0 ? void 0 : data.Viewer;
144
- const activiResponse = yield fetcher(userActivityQuery, {
145
- id: user === null || user === void 0 ? void 0 : user.id,
146
- page: 1,
147
- perPage: 10,
148
- });
149
- const activities = (_b = (_a = activiResponse === null || activiResponse === void 0 ? void 0 : activiResponse.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities;
150
- // Get follower/following information
151
- const req_followers = yield fetcher(userFollowersQuery, {
152
- userId: user === null || user === void 0 ? void 0 : user.id,
153
- });
154
- const req_following = yield fetcher(userFollowingQuery, {
155
- userId: user === null || user === void 0 ? void 0 : user.id,
156
- });
157
- const followersCount = ((_e = (_d = (_c = req_followers === null || req_followers === void 0 ? void 0 : req_followers.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.pageInfo) === null || _e === void 0 ? void 0 : _e.total) || 0;
158
- const followingCount = ((_h = (_g = (_f = req_following === null || req_following === void 0 ? void 0 : req_following.data) === null || _f === void 0 ? void 0 : _f.Page) === null || _g === void 0 ? void 0 : _g.pageInfo) === null || _h === void 0 ? void 0 : _h.total) || 0;
159
- console.log(`
160
- ID: ${user === null || user === void 0 ? void 0 : user.id}
161
- Name: ${user === null || user === void 0 ? void 0 : user.name}
162
- siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
163
- profileColor: ${(_j = user === null || user === void 0 ? void 0 : user.options) === null || _j === void 0 ? void 0 : _j.profileColor}
164
- timeZone: ${(_k = user === null || user === void 0 ? void 0 : user.options) === null || _k === void 0 ? void 0 : _k.timezone}
165
- activityMergeTime: ${(_l = user === null || user === void 0 ? void 0 : user.options) === null || _l === void 0 ? void 0 : _l.activityMergeTime}
166
- donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
167
- donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
168
- unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
169
- Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
170
- Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
171
-
172
- Followers: ${followersCount}
173
- Following: ${followingCount}
174
-
175
- Statistics (Anime):
176
- Count: ${(_o = (_m = user === null || user === void 0 ? void 0 : user.statistics) === null || _m === void 0 ? void 0 : _m.anime) === null || _o === void 0 ? void 0 : _o.count}
177
- Mean Score: ${(_q = (_p = user === null || user === void 0 ? void 0 : user.statistics) === null || _p === void 0 ? void 0 : _p.anime) === null || _q === void 0 ? void 0 : _q.meanScore}
178
- Minutes Watched: ${(_s = (_r = user === null || user === void 0 ? void 0 : user.statistics) === null || _r === void 0 ? void 0 : _r.anime) === null || _s === void 0 ? void 0 : _s.minutesWatched}
179
- Episodes Watched: ${(_u = (_t = user === null || user === void 0 ? void 0 : user.statistics) === null || _t === void 0 ? void 0 : _t.anime) === null || _u === void 0 ? void 0 : _u.episodesWatched}
180
-
181
- Statistics (Manga):
182
- Count: ${(_w = (_v = user === null || user === void 0 ? void 0 : user.statistics) === null || _v === void 0 ? void 0 : _v.manga) === null || _w === void 0 ? void 0 : _w.count}
183
- Mean Score: ${(_y = (_x = user === null || user === void 0 ? void 0 : user.statistics) === null || _x === void 0 ? void 0 : _x.manga) === null || _y === void 0 ? void 0 : _y.meanScore}
184
- Chapters Read: ${(_0 = (_z = user === null || user === void 0 ? void 0 : user.statistics) === null || _z === void 0 ? void 0 : _z.manga) === null || _0 === void 0 ? void 0 : _0.chaptersRead}
185
- Volumes Read: ${(_2 = (_1 = user === null || user === void 0 ? void 0 : user.statistics) === null || _1 === void 0 ? void 0 : _1.manga) === null || _2 === void 0 ? void 0 : _2.volumesRead}
186
- `);
187
- console.log(`\nRecent Activities:`);
188
- if (activities.length > 0) {
189
- activities.map(({ status, progress, media, createdAt }) => {
190
- responsiveOutput(`${timestampToTimeAgo(createdAt)}\t${status} ${progress ? `${progress} of ` : ''}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
191
- });
192
- }
193
- return user;
194
- }
195
- else {
196
- console.error(`\nSomething went wrong. Please log in again. ${errors[0].message}`);
197
- return null;
198
- }
134
+ 'Authorization': `Bearer ${accessToken}`,
135
+ },
136
+ body: JSON.stringify({ query: currentUserQuery }),
137
+ });
138
+ const { data, errors } = yield request.json();
139
+ if (!request.ok) {
140
+ console.error(`\nSomething went wrong. Please log in again. ${(_b = (_a = errors === null || errors === void 0 ? void 0 : errors[0]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Unknown error'}`);
141
+ return null;
199
142
  }
200
- else {
201
- console.error(`\nPlease login first to use this feature.`);
143
+ const user = data === null || data === void 0 ? void 0 : data.Viewer;
144
+ if (!user) {
145
+ console.error('\nUnable to retrieve user information.');
202
146
  return null;
203
147
  }
148
+ const [activityResponse, followersResponse, followingResponse] = yield Promise.all([
149
+ fetcher(userActivityQuery, {
150
+ id: user.id,
151
+ page: 1,
152
+ perPage: 10,
153
+ }),
154
+ fetcher(userFollowersQuery, {
155
+ userId: user.id,
156
+ }),
157
+ fetcher(userFollowingQuery, {
158
+ userId: user.id,
159
+ }),
160
+ ]);
161
+ const activities = (_e = (_d = (_c = activityResponse === null || activityResponse === void 0 ? void 0 : activityResponse.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities) !== null && _e !== void 0 ? _e : [];
162
+ const followersCount = (_j = (_h = (_g = (_f = followersResponse === null || followersResponse === void 0 ? void 0 : followersResponse.data) === null || _f === void 0 ? void 0 : _f.Page) === null || _g === void 0 ? void 0 : _g.pageInfo) === null || _h === void 0 ? void 0 : _h.total) !== null && _j !== void 0 ? _j : 0;
163
+ const followingCount = (_o = (_m = (_l = (_k = followingResponse === null || followingResponse === void 0 ? void 0 : followingResponse.data) === null || _k === void 0 ? void 0 : _k.Page) === null || _l === void 0 ? void 0 : _l.pageInfo) === null || _m === void 0 ? void 0 : _m.total) !== null && _o !== void 0 ? _o : 0;
164
+ renderUserProfile(user, followersCount, followingCount);
165
+ console.log('\nRecent Activities:');
166
+ activities.forEach(({ status, progress, media, createdAt }) => {
167
+ responsiveOutput(`${timestampToTimeAgo(createdAt)}\t${status} ${progress ? `${progress} of ` : ''}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
168
+ });
169
+ return user;
204
170
  }
205
171
  catch (error) {
206
172
  console.error(`\nError from Myself. ${error.message}`);
@@ -265,7 +231,7 @@ Statistics (Manga):
265
231
  }
266
232
  static DeleteMyActivities() {
267
233
  return __awaiter(this, void 0, void 0, function* () {
268
- var _a, _b, _c, _d, _e, _f;
234
+ var _a, _b;
269
235
  try {
270
236
  if (!(yield Auth.isLoggedIn())) {
271
237
  console.error(`\nPlease log in to delete your activities.`);
@@ -303,34 +269,19 @@ Statistics (Manga):
303
269
  perPage: 50,
304
270
  userId: yield Auth.MyUserId(),
305
271
  });
306
- if ((_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities) {
307
- let count = 0;
308
- const activities = (_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities;
309
- if (!activities || activities.length === 0) {
310
- console.log(`\nNo more activities available.`);
311
- hasMoreActivities = false;
312
- }
313
- else {
314
- for (const act of activities) {
315
- if (act === null || act === void 0 ? void 0 : act.id) {
316
- const deleteResponse = yield fetcher(deleteActivityMutation, {
317
- id: act === null || act === void 0 ? void 0 : act.id,
318
- });
319
- const isDeleted = (_f = (_e = deleteResponse === null || deleteResponse === void 0 ? void 0 : deleteResponse.data) === null || _e === void 0 ? void 0 : _e.DeleteActivity) === null || _f === void 0 ? void 0 : _f.deleted;
320
- count++;
321
- totalCount++;
322
- console.log(`[${count}/${activities.length}/${totalCount}]\t${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? colorize.Green('✔') : colorize.Red('✘')}`);
323
- // Avoiding rate-limit
324
- yield sleep(1100);
325
- }
326
- }
327
- }
328
- }
329
- else {
272
+ const activities = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities;
273
+ if (!activities) {
330
274
  // In case of an unexpected null response, exit the loop
331
275
  console.log(`\nProbably deleted all the activities of this type.`);
332
276
  hasMoreActivities = false;
333
277
  }
278
+ else if (activities.length === 0) {
279
+ console.log(`\nNo more activities available.`);
280
+ hasMoreActivities = false;
281
+ }
282
+ else {
283
+ totalCount = yield deleteActivities(activities, totalCount);
284
+ }
334
285
  }
335
286
  }
336
287
  catch (error) {
@@ -345,7 +296,7 @@ Statistics (Manga):
345
296
  const response = yield fetcher(mutation, { id });
346
297
  if (response === null || response === void 0 ? void 0 : response.data) {
347
298
  const deleted = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.DeleteMediaListEntry) === null || _b === void 0 ? void 0 : _b.deleted;
348
- console.log(`del ${title ? getTitle(title) : ''} ${deleted ? colorize.Green('✔') : colorize.Red('✘')}`);
299
+ console.log(`del ${title ? getTitle(title) : ''} ${deleted ? symbol_done : symbol_fail}`);
349
300
  }
350
301
  else {
351
302
  console.error(`\nError deleting entry. ${(_d = (_c = response === null || response === void 0 ? void 0 : response.errors) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message}`);
@@ -408,7 +359,7 @@ Statistics (Manga):
408
359
  for (const [, entry] of selectedEntries.entries.entries()) {
409
360
  if (entry === null || entry === void 0 ? void 0 : entry.id) {
410
361
  yield deleteByIdFn(entry === null || entry === void 0 ? void 0 : entry.id, (_e = entry === null || entry === void 0 ? void 0 : entry.media) === null || _e === void 0 ? void 0 : _e.title);
411
- yield sleep(1100);
362
+ yield sleep(rate_limit_time_ms);
412
363
  }
413
364
  else {
414
365
  console.log(`No id in entry.`);
@@ -567,13 +518,13 @@ Statistics (Manga):
567
518
  likedCount++;
568
519
  }
569
520
  if (result === 'liked' || result === 'failed') {
570
- responsiveOutput(`${result === 'liked' ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, likedCount)}`);
521
+ responsiveOutput(`${result === 'liked' ? symbol_done : symbol_fail} ${activityBy(activ, likedCount)}`);
571
522
  }
572
523
  else if (result === 'skipped') {
573
- responsiveOutput(`${colorize.Yellow('⚉')} ${activityBy(activ, likedCount)}`);
524
+ responsiveOutput(`${symbol_neutral} ${activityBy(activ, likedCount)}`);
574
525
  }
575
526
  // avoiding rate-limit
576
- yield sleep(2000);
527
+ yield sleep(rate_limit_time_ms);
577
528
  }
578
529
  page++;
579
530
  }
@@ -582,7 +533,7 @@ Statistics (Manga):
582
533
  spinner.start('Getting activities...');
583
534
  retryCount++;
584
535
  spinner.update(`Empty activities returned. Retrying... (${retryCount}/${maxRetries})`);
585
- yield sleep(2000);
536
+ yield sleep(rate_limit_time_ms);
586
537
  }
587
538
  else {
588
539
  spinner.error(`Probably the end of activities after ${maxRetries} retries.`);
@@ -616,13 +567,13 @@ Statistics (Manga):
616
567
  const result = yield Auth.attemptLikeActivity(activ);
617
568
  if (result === 'liked' || result === 'failed') {
618
569
  likedCount++;
619
- responsiveOutput(`${result === 'liked' ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, likedCount)}`);
570
+ responsiveOutput(`${result === 'liked' ? symbol_done : symbol_fail} ${activityBy(activ, likedCount)}`);
620
571
  }
621
572
  else if (result === 'skipped') {
622
- responsiveOutput(`${colorize.Yellow('⚉')} ${activityBy(activ, likedCount)}`);
573
+ responsiveOutput(`${symbol_neutral} ${activityBy(activ, likedCount)}`);
623
574
  }
624
575
  // avoiding rate-limit
625
- yield sleep(1500);
576
+ yield sleep(rate_limit_time_ms);
626
577
  }
627
578
  page++;
628
579
  }
@@ -679,14 +630,14 @@ Statistics (Manga):
679
630
  const result = yield Auth.attemptLikeActivity(activ);
680
631
  if (result === 'liked' || result === 'failed') {
681
632
  likedCount++;
682
- responsiveOutput(`${result === 'liked' ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, likedCount)}`);
633
+ responsiveOutput(`${result === 'liked' ? symbol_done : symbol_fail} ${activityBy(activ, likedCount)}`);
683
634
  if (likedCount >= toLikeAmount) {
684
635
  spinner.success(`Finished liking ${likedCount} activities of ${username}.`);
685
636
  return;
686
637
  }
687
638
  }
688
639
  else if (result === 'skipped') {
689
- responsiveOutput(`${colorize.Yellow('⚉')} ${activityBy(activ, likedCount)}`);
640
+ responsiveOutput(`${symbol_neutral} ${activityBy(activ, likedCount)}`);
690
641
  }
691
642
  }
692
643
  page += 1;
@@ -776,19 +727,19 @@ Statistics (Manga):
776
727
  const activ = activiti[i];
777
728
  const result = yield Auth.attemptLikeActivity(activ);
778
729
  if (result === 'liked' || result === 'failed') {
779
- responsiveOutput(`${result === 'liked' ? colorize.Green('✔') : colorize.Red('✘')} ${activityBy(activ, i + 1)}`);
730
+ responsiveOutput(`${result === 'liked' ? symbol_done : symbol_fail} ${activityBy(activ, i + 1)}`);
780
731
  if (result === 'liked') {
781
732
  liked++;
782
733
  }
783
734
  }
784
735
  else if (result === 'skipped') {
785
- responsiveOutput(`${colorize.Yellow('⚉')} ${activityBy(activ, i + 1)}`);
736
+ responsiveOutput(`${symbol_neutral} ${activityBy(activ, i + 1)}`);
786
737
  }
787
738
  // Avoid rate-limiting
788
- yield sleep(1200);
739
+ yield sleep(rate_limit_time_ms);
789
740
  }
790
741
  }
791
- console.log(`\n${colorize.Green('✔')} All ${liked} activities liked successfully.`);
742
+ console.log(`\n${symbol_done} All ${liked} activities liked successfully.`);
792
743
  }
793
744
  catch (error) {
794
745
  console.error(`\nError in LikeFollowingActivityV2: ${error.message}`);
@@ -883,7 +834,7 @@ class Social {
883
834
  for (const user of users) {
884
835
  try {
885
836
  const response = yield fetcher(toggleFollowMutation, { userId: user.id });
886
- console.log(`${String(`[${user.id}]`).padEnd(maxIdLength)}\t${String(`[${(_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.ToggleFollow) === null || _b === void 0 ? void 0 : _b.name}]`).padEnd(maxNameLength)}\t${((_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.ToggleFollow) === null || _d === void 0 ? void 0 : _d.id) ? colorize.Green('✔') : colorize.Red('✘')}`);
837
+ console.log(`${String(`[${user.id}]`).padEnd(maxIdLength)}\t${String(`[${(_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.ToggleFollow) === null || _b === void 0 ? void 0 : _b.name}]`).padEnd(maxNameLength)}\t${((_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.ToggleFollow) === null || _d === void 0 ? void 0 : _d.id) ? symbol_done : symbol_fail}`);
887
838
  if ((_f = (_e = response === null || response === void 0 ? void 0 : response.data) === null || _e === void 0 ? void 0 : _e.ToggleFollow) === null || _f === void 0 ? void 0 : _f.id) {
888
839
  toggled++;
889
840
  }
@@ -921,7 +872,7 @@ class Social {
921
872
  return;
922
873
  }
923
874
  const followedBack = yield Social.toggleFollowBatch(notFollowing);
924
- console.log(`\n${colorize.Green('✔')} Followed back ${followedBack} users.`);
875
+ console.log(`\n${symbol_done} Followed back ${followedBack} users.`);
925
876
  }
926
877
  catch (error) {
927
878
  console.log(`\nautomate_follow ${error.message}`);
@@ -954,8 +905,8 @@ class Social {
954
905
  }
955
906
  spinner.stop(`Unfollow process activated with ${notFollowingMe.length} users.`);
956
907
  console.log(`\n`);
957
- const unfollowedUsers = yield Social.toggleFollowBatch(notFollowingMe);
958
- console.log(`\n${colorize.Green('✔')} Total Unfollowed: ${unfollowedUsers} of ${notFollowingMe.length} users.`);
908
+ const unfollowed_users = yield Social.toggleFollowBatch(notFollowingMe);
909
+ console.log(`\n${symbol_done} Total Unfollowed: ${unfollowed_users} of ${notFollowingMe.length} users.`);
959
910
  }
960
911
  catch (error) {
961
912
  console.error(`\nautomate_unfollow: ${error.message}`);
@@ -1013,15 +964,15 @@ class Social {
1013
964
  staleUsers.push({ id: user.id, name: user.name });
1014
965
  }
1015
966
  // avoiding rate-limit
1016
- yield sleep(1100);
967
+ yield sleep(rate_limit_time_ms);
1017
968
  }
1018
969
  console.log(`\nFound ${staleUsers.length} user(s) inactive for ${months}+ month(s).`);
1019
970
  if (staleUsers.length <= 0) {
1020
971
  console.log(`No stale accounts to unfollow.`);
1021
972
  return;
1022
973
  }
1023
- const unfollowedUsers = yield Social.toggleFollowBatch(staleUsers);
1024
- console.log(`\n${colorize.Green('✔')} Unfollowed ${unfollowedUsers} of ${staleUsers.length} inactive user(s).`);
974
+ const unfollowed_users = yield Social.toggleFollowBatch(staleUsers);
975
+ console.log(`\n${symbol_done} Unfollowed ${unfollowed_users} of ${staleUsers.length} inactive user(s).`);
1025
976
  }
1026
977
  catch (error) {
1027
978
  console.error(`\nautomate_unfollow_inactive: ${error.message}`);
@@ -1,13 +1,9 @@
1
1
  /**
2
2
  * Sends a GraphQL request to the AniList API.
3
3
  *
4
- * This function constructs a request with the provided query and variables,
5
- * handles authorization, and processes the API response. If a rate-limit error (429) is returned,
6
- * it waits for 1 minute and retries the request.
7
- *
8
- * @param {string} query - The AniList GraphQL query to be executed.
9
- * @param {object} variables - An object containing the variables for the query.
10
- * @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
4
+ * @param query - The GraphQL query to execute.
5
+ * @param variables - Variables for the GraphQL query.
6
+ * @returns The API response if successful; otherwise, null.
11
7
  */
12
- declare function fetcher(query: string, variables: object): Promise<object | null>;
8
+ declare function fetcher<T = Record<string, unknown>>(query: string, variables: object): Promise<T | null>;
13
9
  export { fetcher };
@@ -13,13 +13,9 @@ import { aniListEndpoint, handleRateLimitRetry } from './workers.js';
13
13
  /**
14
14
  * Sends a GraphQL request to the AniList API.
15
15
  *
16
- * This function constructs a request with the provided query and variables,
17
- * handles authorization, and processes the API response. If a rate-limit error (429) is returned,
18
- * it waits for 1 minute and retries the request.
19
- *
20
- * @param {string} query - The AniList GraphQL query to be executed.
21
- * @param {object} variables - An object containing the variables for the query.
22
- * @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
16
+ * @param query - The GraphQL query to execute.
17
+ * @param variables - Variables for the GraphQL query.
18
+ * @returns The API response if successful; otherwise, null.
23
19
  */
24
20
  function fetcher(query, variables) {
25
21
  return __awaiter(this, void 0, void 0, function* () {
@@ -35,24 +31,22 @@ function fetcher(query, variables) {
35
31
  headers['Authorization'] = `Bearer ${token}`;
36
32
  const request = yield fetch(aniListEndpoint, {
37
33
  method: 'POST',
38
- headers: headers,
34
+ headers,
39
35
  body: JSON.stringify({ query, variables }),
40
36
  });
41
- const response = yield request.json();
37
+ const response = (yield request.json());
42
38
  if (request.status === 200) {
43
39
  return response;
44
40
  }
45
- else if (request.status === 429) {
41
+ if (request.status === 429) {
46
42
  yield handleRateLimitRetry(60);
47
- return yield fetcher(query, variables);
48
- }
49
- else {
50
- console.error(`\n${request.status} ${((_b = (_a = response === null || response === void 0 ? void 0 : response.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) || 'Unknown error'}.`);
51
- return null;
43
+ return fetcher(query, variables);
52
44
  }
45
+ console.error(`\n${request.status} ${((_b = (_a = response === null || response === void 0 ? void 0 : response.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) || 'Unknown error'}.`);
46
+ return null;
53
47
  }
54
48
  catch (error) {
55
- console.error(`\nSomething went wrong. ${error.message}.`);
49
+ console.error(`\nSomething went wrong. ${error instanceof Error ? error.message : String(error)}.`);
56
50
  return null;
57
51
  }
58
52
  });
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Symbol indicating a successful operation, rendered in green.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * console.log(`${symbol_done} Build finished`)
7
+ * // ✔ Build finished (with ✔ in green)
8
+ * ```
9
+ */
10
+ export declare const symbol_done: string;
11
+ /**
12
+ * Symbol indicating a failed operation, rendered in red.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * console.error(`${symbol_fail} Build failed`)
17
+ * // ✘ Build failed (with ✘ in red)
18
+ * ```
19
+ */
20
+ export declare const symbol_fail: string;
21
+ /**
22
+ * Symbol for a neutral / informational state, rendered in yellow.
23
+ *
24
+ * Useful for warnings, skips, or notices that are neither pass nor fail.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * console.log(`${symbol_neutral} Skipping optional step`)
29
+ * // 🙼 Skipping optional step (with 🙼 in yellow)
30
+ * ```
31
+ */
32
+ export declare const symbol_neutral: string;
33
+ /**
34
+ * Rate limit time in milisecond
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * await sleep(rate_limit_time_ms)
39
+ * ```
40
+ */
41
+ export declare const rate_limit_time_ms = 1100;
@@ -0,0 +1,42 @@
1
+ import { colorize } from './colorize.js';
2
+ /**
3
+ * Symbol indicating a successful operation, rendered in green.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * console.log(`${symbol_done} Build finished`)
8
+ * // ✔ Build finished (with ✔ in green)
9
+ * ```
10
+ */
11
+ export const symbol_done = colorize.Green('✔');
12
+ /**
13
+ * Symbol indicating a failed operation, rendered in red.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * console.error(`${symbol_fail} Build failed`)
18
+ * // ✘ Build failed (with ✘ in red)
19
+ * ```
20
+ */
21
+ export const symbol_fail = colorize.Red('✘');
22
+ /**
23
+ * Symbol for a neutral / informational state, rendered in yellow.
24
+ *
25
+ * Useful for warnings, skips, or notices that are neither pass nor fail.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * console.log(`${symbol_neutral} Skipping optional step`)
30
+ * // 🙼 Skipping optional step (with 🙼 in yellow)
31
+ * ```
32
+ */
33
+ export const symbol_neutral = colorize.Yellow('🙼');
34
+ /**
35
+ * Rate limit time in milisecond
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * await sleep(rate_limit_time_ms)
40
+ * ```
41
+ */
42
+ export const rate_limit_time_ms = 1100;
@@ -0,0 +1,2 @@
1
+ import { User } from '../types.js';
2
+ export declare function renderUserProfile(user: User, followersCount: number, followingCount: number): void;
@@ -0,0 +1,35 @@
1
+ import Table from 'cli-table3';
2
+ export function renderUserProfile(user, followersCount, followingCount) {
3
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
4
+ const table = new Table({
5
+ chars: {
6
+ 'top': '',
7
+ 'top-mid': '',
8
+ 'top-left': '',
9
+ 'top-right': '',
10
+ 'bottom': '',
11
+ 'bottom-mid': '',
12
+ 'bottom-left': '',
13
+ 'bottom-right': '',
14
+ 'left': '',
15
+ 'left-mid': '',
16
+ 'mid': '',
17
+ 'mid-mid': '',
18
+ 'right': '',
19
+ 'right-mid': '',
20
+ 'middle': '',
21
+ },
22
+ style: {
23
+ 'padding-left': 0,
24
+ 'padding-right': 0,
25
+ 'head': [],
26
+ 'border': [],
27
+ },
28
+ });
29
+ const row = (label, value) => [
30
+ label.padEnd(30),
31
+ String(value !== null && value !== void 0 ? value : 'null'),
32
+ ];
33
+ table.push(row('ID:', user.id), row('Name:', user.name), row('siteUrl:', user.siteUrl), row('profileColor:', (_a = user.options) === null || _a === void 0 ? void 0 : _a.profileColor), row('timeZone:', (_b = user.options) === null || _b === void 0 ? void 0 : _b.timezone), row('activityMergeTime:', (_c = user.options) === null || _c === void 0 ? void 0 : _c.activityMergeTime), row('donatorTier:', user.donatorTier), row('donatorBadge:', user.donatorBadge), row('unreadNotificationCount:', user.unreadNotificationCount), row('Account Created:', new Date(user.createdAt * 1000).toUTCString()), row('Account Updated:', new Date(user.updatedAt * 1000).toUTCString()), ['', ''], row('Followers:', followersCount), row('Following:', followingCount), ['', ''], ['Statistics (Anime):', ''], row(' Count:', (_e = (_d = user.statistics) === null || _d === void 0 ? void 0 : _d.anime) === null || _e === void 0 ? void 0 : _e.count), row(' Mean Score:', (_g = (_f = user.statistics) === null || _f === void 0 ? void 0 : _f.anime) === null || _g === void 0 ? void 0 : _g.meanScore), row(' Minutes Watched:', (_j = (_h = user.statistics) === null || _h === void 0 ? void 0 : _h.anime) === null || _j === void 0 ? void 0 : _j.minutesWatched), row(' Episodes Watched:', (_l = (_k = user.statistics) === null || _k === void 0 ? void 0 : _k.anime) === null || _l === void 0 ? void 0 : _l.episodesWatched), ['', ''], ['Statistics (Manga):', ''], row(' Count:', (_o = (_m = user.statistics) === null || _m === void 0 ? void 0 : _m.manga) === null || _o === void 0 ? void 0 : _o.count), row(' Mean Score:', (_q = (_p = user.statistics) === null || _p === void 0 ? void 0 : _p.manga) === null || _q === void 0 ? void 0 : _q.meanScore), row(' Chapters Read:', (_s = (_r = user.statistics) === null || _r === void 0 ? void 0 : _r.manga) === null || _s === void 0 ? void 0 : _s.chaptersRead), row(' Volumes Read:', (_u = (_t = user.statistics) === null || _t === void 0 ? void 0 : _t.manga) === null || _u === void 0 ? void 0 : _u.volumesRead));
34
+ console.log(`\n${table.toString()}`);
35
+ }