rettiwt-api 5.0.0-alpha.4 → 5.0.1

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 (96) hide show
  1. package/.github/workflows/documentation.yml +3 -3
  2. package/README.md +160 -87
  3. package/dist/collections/Requests.d.ts +1 -1
  4. package/dist/collections/Requests.js +3 -2
  5. package/dist/collections/Requests.js.map +1 -1
  6. package/dist/collections/Tweet.d.ts +10 -0
  7. package/dist/collections/Tweet.js +17 -0
  8. package/dist/collections/Tweet.js.map +1 -0
  9. package/dist/commands/Tweet.js +0 -16
  10. package/dist/commands/Tweet.js.map +1 -1
  11. package/dist/commands/User.js +0 -15
  12. package/dist/commands/User.js.map +1 -1
  13. package/dist/enums/Tweet.d.ts +8 -0
  14. package/dist/enums/Tweet.js +13 -0
  15. package/dist/enums/Tweet.js.map +1 -0
  16. package/dist/enums/raw/Tweet.d.ts +11 -1
  17. package/dist/enums/raw/Tweet.js +13 -2
  18. package/dist/enums/raw/Tweet.js.map +1 -1
  19. package/dist/helper/TidUtils.d.ts +2 -0
  20. package/dist/helper/TidUtils.js +10 -1
  21. package/dist/helper/TidUtils.js.map +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/models/RettiwtConfig.d.ts +27 -3
  26. package/dist/models/RettiwtConfig.js +37 -4
  27. package/dist/models/RettiwtConfig.js.map +1 -1
  28. package/dist/models/args/FetchArgs.d.ts +3 -3
  29. package/dist/models/args/FetchArgs.js +3 -2
  30. package/dist/models/args/FetchArgs.js.map +1 -1
  31. package/dist/models/args/PostArgs.d.ts +2 -3
  32. package/dist/models/args/PostArgs.js +3 -3
  33. package/dist/models/args/PostArgs.js.map +1 -1
  34. package/dist/models/auth/AuthCookie.d.ts +1 -1
  35. package/dist/models/auth/AuthCookie.js +1 -1
  36. package/dist/models/auth/AuthCredential.d.ts +1 -1
  37. package/dist/models/auth/AuthCredential.js +1 -1
  38. package/dist/models/data/List.d.ts +1 -1
  39. package/dist/models/data/List.js +1 -1
  40. package/dist/models/data/List.js.map +1 -1
  41. package/dist/models/data/Notification.d.ts +1 -1
  42. package/dist/models/data/Notification.js +1 -1
  43. package/dist/models/data/Notification.js.map +1 -1
  44. package/dist/models/data/Tweet.d.ts +1 -1
  45. package/dist/models/data/Tweet.js +1 -1
  46. package/dist/models/data/Tweet.js.map +1 -1
  47. package/dist/models/data/User.d.ts +1 -1
  48. package/dist/models/data/User.js +1 -1
  49. package/dist/models/data/User.js.map +1 -1
  50. package/dist/requests/Tweet.d.ts +2 -1
  51. package/dist/requests/Tweet.js +3 -4
  52. package/dist/requests/Tweet.js.map +1 -1
  53. package/dist/services/internal/AuthService.d.ts +1 -1
  54. package/dist/services/internal/AuthService.js +1 -1
  55. package/dist/services/internal/TidService.d.ts +0 -1
  56. package/dist/services/internal/TidService.js +10 -15
  57. package/dist/services/internal/TidService.js.map +1 -1
  58. package/dist/services/public/FetcherService.d.ts +4 -3
  59. package/dist/services/public/FetcherService.js +6 -5
  60. package/dist/services/public/FetcherService.js.map +1 -1
  61. package/dist/services/public/ListService.d.ts +6 -4
  62. package/dist/services/public/ListService.js +6 -4
  63. package/dist/services/public/ListService.js.map +1 -1
  64. package/dist/services/public/TweetService.d.ts +96 -74
  65. package/dist/services/public/TweetService.js +97 -87
  66. package/dist/services/public/TweetService.js.map +1 -1
  67. package/dist/services/public/UserService.d.ts +80 -39
  68. package/dist/services/public/UserService.js +84 -43
  69. package/dist/services/public/UserService.js.map +1 -1
  70. package/dist/types/args/FetchArgs.d.ts +8 -0
  71. package/package.json +1 -1
  72. package/src/collections/Requests.ts +5 -2
  73. package/src/collections/Tweet.ts +17 -0
  74. package/src/commands/Tweet.ts +0 -16
  75. package/src/commands/User.ts +0 -15
  76. package/src/enums/Tweet.ts +8 -0
  77. package/src/enums/raw/Tweet.ts +12 -1
  78. package/src/helper/TidUtils.ts +10 -1
  79. package/src/index.ts +1 -0
  80. package/src/models/RettiwtConfig.ts +43 -4
  81. package/src/models/args/FetchArgs.ts +4 -3
  82. package/src/models/args/PostArgs.ts +3 -4
  83. package/src/models/auth/AuthCookie.ts +1 -1
  84. package/src/models/auth/AuthCredential.ts +1 -1
  85. package/src/models/data/List.ts +1 -1
  86. package/src/models/data/Notification.ts +1 -1
  87. package/src/models/data/Tweet.ts +1 -1
  88. package/src/models/data/User.ts +1 -1
  89. package/src/requests/Tweet.ts +4 -5
  90. package/src/services/internal/AuthService.ts +1 -1
  91. package/src/services/internal/TidService.ts +12 -18
  92. package/src/services/public/FetcherService.ts +6 -5
  93. package/src/services/public/ListService.ts +6 -4
  94. package/src/services/public/TweetService.ts +101 -93
  95. package/src/services/public/UserService.ts +88 -47
  96. package/src/types/args/FetchArgs.ts +10 -0
@@ -43,14 +43,15 @@ export class UserService extends FetcherService {
43
43
  /**
44
44
  * Get the list affiliates of a user.
45
45
  *
46
- * @param id - The id of the target user.
46
+ * @param id - The ID of the target user. If no id is provided, the logged-in user's id is used.
47
47
  * @param count - The number of affiliates to fetch, must be \<= 100.
48
48
  * @param cursor - The cursor to the batch of affiliates to fetch.
49
49
  *
50
50
  * @returns The list of users affiliated to the target user.
51
51
  *
52
52
  * @example
53
- * ```
53
+ *
54
+ * ```ts
54
55
  * import { Rettiwt } from 'rettiwt-api';
55
56
  *
56
57
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -71,7 +72,7 @@ export class UserService extends FetcherService {
71
72
 
72
73
  // Fetching raw list of affiliates
73
74
  const response = await this.request<IUserAffiliatesResponse>(resource, {
74
- id: id,
75
+ id: id ?? this.config.userId,
75
76
  count: count,
76
77
  cursor: cursor,
77
78
  });
@@ -91,7 +92,8 @@ export class UserService extends FetcherService {
91
92
  * @returns The list of tweets bookmarked by the target user.
92
93
  *
93
94
  * @example
94
- * ```
95
+ *
96
+ * ```ts
95
97
  * import { Rettiwt } from 'rettiwt-api';
96
98
  *
97
99
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -125,15 +127,19 @@ export class UserService extends FetcherService {
125
127
  /**
126
128
  * Get the details of a user.
127
129
  *
128
- * @param id - The username/id(s) of the target user/users. If no ID is provided, uses ID of authenticated user.
130
+ * @param id - The username/ID/IDs of the target user/users. If no ID is provided, the logged-in user's ID is used.
129
131
  *
130
132
  * @returns
131
133
  * The details of the given user.
134
+ *
135
+ * If more than one ID is provided, returns a list.
136
+ *
132
137
  * If no user matches the given id, returns `undefined`.
133
138
  *
134
139
  * @example
135
- * Fetching the details using username
136
- * ```
140
+ *
141
+ * #### Fetching the details of a single user using username
142
+ * ```ts
137
143
  * import { Rettiwt } from 'rettiwt-api';
138
144
  *
139
145
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -150,8 +156,9 @@ export class UserService extends FetcherService {
150
156
  * ```
151
157
  *
152
158
  * @example
153
- * Fetching the details using id
154
- * ```
159
+ *
160
+ * #### Fetching the details of a single user using ID
161
+ * ```ts
155
162
  * import { Rettiwt } from 'rettiwt-api';
156
163
  *
157
164
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -160,7 +167,25 @@ export class UserService extends FetcherService {
160
167
  * // Fetching the details of the User with id '1234567890'
161
168
  * rettiwt.user.details('1234567890')
162
169
  * .then(res => {
163
- * console.log(res);
170
+ * console.log(res); # 'res' is a single tweet
171
+ * })
172
+ * .catch(err => {
173
+ * console.log(err);
174
+ * });
175
+ * ```
176
+ * * @example
177
+ *
178
+ * #### Fetching the details of multiple users
179
+ * ```ts
180
+ * import { Rettiwt } from 'rettiwt-api';
181
+ *
182
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
183
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
184
+ *
185
+ * // Fetching the details of the users with IDs '123', '456', '789'
186
+ * rettiwt.user.details(['123', '456', '789'])
187
+ * .then(res => {
188
+ * console.log(res); # 'res' is an array of users
164
189
  * })
165
190
  * .catch(err => {
166
191
  * console.log(err);
@@ -213,14 +238,15 @@ export class UserService extends FetcherService {
213
238
  /**
214
239
  * Follow a user.
215
240
  *
216
- * @param id - The id the user to be followed.
241
+ * @param id - The ID the user to be followed.
217
242
  *
218
243
  * @returns Whether following was successful or not.
219
244
  *
220
245
  * @throws Code 108 if given user id is invalid.
221
246
  *
222
247
  * @example
223
- * ```
248
+ *
249
+ * ```ts
224
250
  * import { Rettiwt } from 'rettiwt-api';
225
251
  *
226
252
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -256,7 +282,8 @@ export class UserService extends FetcherService {
256
282
  * @returns - The followed feed of the logged-in user.
257
283
  *
258
284
  * @example
259
- * ```
285
+ *
286
+ * ```ts
260
287
  * import { Rettiwt } from 'rettiwt-api';
261
288
  *
262
289
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -291,14 +318,15 @@ export class UserService extends FetcherService {
291
318
  /**
292
319
  * Get the list followers of a user.
293
320
  *
294
- * @param id - The id of the target user.
321
+ * @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
295
322
  * @param count - The number of followers to fetch, must be \<= 100.
296
323
  * @param cursor - The cursor to the batch of followers to fetch.
297
324
  *
298
325
  * @returns The list of users following the target user.
299
326
  *
300
327
  * @example
301
- * ```
328
+ *
329
+ * ```ts
302
330
  * import { Rettiwt } from 'rettiwt-api';
303
331
  *
304
332
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -314,12 +342,12 @@ export class UserService extends FetcherService {
314
342
  * });
315
343
  * ```
316
344
  */
317
- public async followers(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
345
+ public async followers(id?: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
318
346
  const resource = EResourceType.USER_FOLLOWERS;
319
347
 
320
348
  // Fetching raw list of followers
321
349
  const response = await this.request<IUserFollowersResponse>(resource, {
322
- id: id,
350
+ id: id ?? this.config.userId,
323
351
  count: count,
324
352
  cursor: cursor,
325
353
  });
@@ -333,14 +361,15 @@ export class UserService extends FetcherService {
333
361
  /**
334
362
  * Get the list of users who are followed by a user.
335
363
  *
336
- * @param id - The id of the target user.
364
+ * @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
337
365
  * @param count - The number of following to fetch, must be \<= 100.
338
366
  * @param cursor - The cursor to the batch of following to fetch.
339
367
  *
340
368
  * @returns The list of users followed by the target user.
341
369
  *
342
370
  * @example
343
- * ```
371
+ *
372
+ * ```ts
344
373
  * import { Rettiwt } from 'rettiwt-api';
345
374
  *
346
375
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -356,12 +385,12 @@ export class UserService extends FetcherService {
356
385
  * });
357
386
  * ```
358
387
  */
359
- public async following(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
388
+ public async following(id?: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
360
389
  const resource = EResourceType.USER_FOLLOWING;
361
390
 
362
391
  // Fetching raw list of following
363
392
  const response = await this.request<IUserFollowingResponse>(resource, {
364
- id: id,
393
+ id: id ?? this.config.userId,
365
394
  count: count,
366
395
  cursor: cursor,
367
396
  });
@@ -375,14 +404,15 @@ export class UserService extends FetcherService {
375
404
  /**
376
405
  * Get the highlighted tweets of a user.
377
406
  *
378
- * @param id - The id of the target user.
407
+ * @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
379
408
  * @param count - The number of followers to fetch, must be \<= 100.
380
409
  * @param cursor - The cursor to the batch of followers to fetch.
381
410
  *
382
411
  * @returns The list of highlighted tweets of the target user.
383
412
  *
384
413
  * @example
385
- * ```
414
+ *
415
+ * ```ts
386
416
  * import { Rettiwt } from 'rettiwt-api';
387
417
  *
388
418
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -403,7 +433,7 @@ export class UserService extends FetcherService {
403
433
 
404
434
  // Fetching raw list of highlights
405
435
  const response = await this.request<IUserHighlightsResponse>(resource, {
406
- id: id,
436
+ id: id ?? this.config.userId,
407
437
  count: count,
408
438
  cursor: cursor,
409
439
  });
@@ -423,7 +453,8 @@ export class UserService extends FetcherService {
423
453
  * @returns The list of tweets liked by the target user.
424
454
  *
425
455
  * @example
426
- * ```
456
+ *
457
+ * ```ts
427
458
  * import { Rettiwt } from 'rettiwt-api';
428
459
  *
429
460
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -458,14 +489,15 @@ export class UserService extends FetcherService {
458
489
  /**
459
490
  * Get the media timeline of a user.
460
491
  *
461
- * @param id - The id of the target user.
492
+ * @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
462
493
  * @param count - The number of media to fetch, must be \<= 100.
463
494
  * @param cursor - The cursor to the batch of media to fetch
464
495
  *
465
496
  * @returns The media timeline of the target user.
466
497
  *
467
498
  * @example
468
- * ```
499
+ *
500
+ * ```ts
469
501
  * import { Rettiwt } from 'rettiwt-api';
470
502
  *
471
503
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -481,12 +513,12 @@ export class UserService extends FetcherService {
481
513
  * });
482
514
  * ```
483
515
  */
484
- public async media(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
516
+ public async media(id?: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
485
517
  const resource = EResourceType.USER_MEDIA;
486
518
 
487
519
  // Fetching raw list of media
488
520
  const response = await this.request<IUserMediaResponse>(resource, {
489
- id: id,
521
+ id: id ?? this.config.userId,
490
522
  count: count,
491
523
  cursor: cursor,
492
524
  });
@@ -505,7 +537,8 @@ export class UserService extends FetcherService {
505
537
  * @returns An async generator that yields new notifications as they are received.
506
538
  *
507
539
  * @example
508
- * ```
540
+ *
541
+ * ```ts
509
542
  * import { Rettiwt } from 'rettiwt-api';
510
543
  *
511
544
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -515,7 +548,7 @@ export class UserService extends FetcherService {
515
548
  * async function streamNotifications() {
516
549
  * try {
517
550
  * // Awaiting for the notifications returned by the AsyncGenerator returned by the method
518
- * for await (const notification of rettiwt.user.notifications(1000)) {
551
+ * for await (const notification of rettiwt.user.notifications(5000)) {
519
552
  * console.log(notification.message);
520
553
  * }
521
554
  * }
@@ -577,7 +610,8 @@ export class UserService extends FetcherService {
577
610
  * @returns - The recommended feed of the logged-in user.
578
611
  *
579
612
  * @example
580
- * ```
613
+ *
614
+ * ```ts
581
615
  * import { Rettiwt } from 'rettiwt-api';
582
616
  *
583
617
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -612,14 +646,15 @@ export class UserService extends FetcherService {
612
646
  /**
613
647
  * Get the reply timeline of a user.
614
648
  *
615
- * @param id - The id of the target user.
649
+ * @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
616
650
  * @param count - The number of replies to fetch, must be \<= 20.
617
651
  * @param cursor - The cursor to the batch of replies to fetch.
618
652
  *
619
653
  * @returns The reply timeline of the target user.
620
654
  *
621
655
  * @example
622
- * ```
656
+ *
657
+ * ```ts
623
658
  * import { Rettiwt } from 'rettiwt-api';
624
659
  *
625
660
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -635,14 +670,16 @@ export class UserService extends FetcherService {
635
670
  * });
636
671
  * ```
637
672
  *
638
- * @remarks If the target user has a pinned tweet, the returned reply timeline has one item extra and this is always the pinned tweet.
673
+ * @remarks
674
+ *
675
+ * If the target user has a pinned tweet, the returned reply timeline has one item extra and this is always the pinned tweet.
639
676
  */
640
- public async replies(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
677
+ public async replies(id?: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
641
678
  const resource = EResourceType.USER_TIMELINE_AND_REPLIES;
642
679
 
643
680
  // Fetching raw list of replies
644
681
  const response = await this.request<IUserTweetsAndRepliesResponse>(resource, {
645
- id: id,
682
+ id: id ?? this.config.userId,
646
683
  count: count,
647
684
  cursor: cursor,
648
685
  });
@@ -656,14 +693,17 @@ export class UserService extends FetcherService {
656
693
  /**
657
694
  * Get the list of subscriptions of a user.
658
695
  *
659
- * @param id - The id of the target user.
696
+ * @deprecated Currently not working.
697
+ *
698
+ * @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
660
699
  * @param count - The number of subscriptions to fetch, must be \<= 100.
661
700
  * @param cursor - The cursor to the batch of subscriptions to fetch.
662
701
  *
663
702
  * @returns The list of subscriptions by the target user.
664
703
  *
665
704
  * @example
666
- * ```
705
+ *
706
+ * ```ts
667
707
  * import { Rettiwt } from 'rettiwt-api';
668
708
  *
669
709
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -684,7 +724,7 @@ export class UserService extends FetcherService {
684
724
 
685
725
  // Fetching raw list of subscriptions
686
726
  const response = await this.request<IUserSubscriptionsResponse>(resource, {
687
- id: id,
727
+ id: id ?? this.config.userId,
688
728
  count: count,
689
729
  cursor: cursor,
690
730
  });
@@ -698,14 +738,15 @@ export class UserService extends FetcherService {
698
738
  /**
699
739
  * Get the tweet timeline of a user.
700
740
  *
701
- * @param id - The id of the target user.
741
+ * @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
702
742
  * @param count - The number of timeline items to fetch, must be \<= 20.
703
743
  * @param cursor - The cursor to the batch of timeline items to fetch.
704
744
  *
705
745
  * @returns The timeline of the target user.
706
746
  *
707
747
  * @example
708
- * ```
748
+ *
749
+ * ```ts
709
750
  * import { Rettiwt } from 'rettiwt-api';
710
751
  *
711
752
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -722,6 +763,7 @@ export class UserService extends FetcherService {
722
763
  * ```
723
764
  *
724
765
  * @remarks
766
+ *
725
767
  * - If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
726
768
  * - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
727
769
  */
@@ -730,7 +772,7 @@ export class UserService extends FetcherService {
730
772
 
731
773
  // Fetching raw list of tweets
732
774
  const response = await this.request<IUserTweetsResponse>(resource, {
733
- id: id,
775
+ id: id ?? this.config.userId,
734
776
  count: count,
735
777
  cursor: cursor,
736
778
  });
@@ -744,14 +786,13 @@ export class UserService extends FetcherService {
744
786
  /**
745
787
  * Unfollow a user.
746
788
  *
747
- * @param id - The id the user to be unfollowed.
789
+ * @param id - The ID the user to be unfollowed.
748
790
  *
749
791
  * @returns Whether unfollowing was successful or not.
750
792
  *
751
- * @throws Code 34 if given user id is invalid.
752
- *
753
793
  * @example
754
- * ```
794
+ *
795
+ * ```ts
755
796
  * import { Rettiwt } from 'rettiwt-api';
756
797
  *
757
798
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -1,3 +1,5 @@
1
+ import { ETweetRepliesSortType } from '../../enums/Tweet';
2
+
1
3
  /**
2
4
  * Options specifying the data that is to be fetched.
3
5
  *
@@ -55,6 +57,14 @@ export interface IFetchArgs {
55
57
  * - Required only for {@link EResourceType.TWEET_DETAILS_BULK} and {@link EResourceType.USER_DETAILS_BY_IDS_BULK}.
56
58
  */
57
59
  ids?: string[];
60
+
61
+ /**
62
+ * The sorting to use for tweet results.
63
+ *
64
+ * @remarks
65
+ * - Only works for {@link EResourceType.TWEET_REPLIES}.
66
+ */
67
+ sortBy?: ETweetRepliesSortType;
58
68
  }
59
69
 
60
70
  /**