rettiwt-api 5.1.0-alpha.0 → 6.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/.eslintrc.js +13 -8
- package/README.md +8 -1
- package/dist/cli.js +17 -14
- package/dist/cli.js.map +1 -1
- package/dist/collections/Extractors.d.ts +1 -1
- package/dist/collections/Extractors.js +21 -21
- package/dist/collections/Extractors.js.map +1 -1
- package/dist/collections/Groups.d.ts +4 -4
- package/dist/collections/Groups.js +45 -45
- package/dist/collections/Groups.js.map +1 -1
- package/dist/collections/Requests.d.ts +3 -3
- package/dist/collections/Requests.js +3 -3
- package/dist/collections/Requests.js.map +1 -1
- package/dist/collections/Tweet.d.ts +4 -4
- package/dist/collections/Tweet.js +5 -5
- package/dist/collections/Tweet.js.map +1 -1
- package/dist/commands/Tweet.js +32 -4
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/enums/Api.d.ts +1 -1
- package/dist/enums/Api.js +7 -7
- package/dist/enums/Api.js.map +1 -1
- package/dist/enums/Authentication.d.ts +1 -1
- package/dist/enums/Authentication.js +7 -7
- package/dist/enums/Authentication.js.map +1 -1
- package/dist/enums/Data.d.ts +1 -1
- package/dist/enums/Data.js +7 -7
- package/dist/enums/Data.js.map +1 -1
- package/dist/enums/Logging.d.ts +1 -1
- package/dist/enums/Logging.js +11 -11
- package/dist/enums/Logging.js.map +1 -1
- package/dist/enums/Media.d.ts +1 -1
- package/dist/enums/Media.js +7 -7
- package/dist/enums/Media.js.map +1 -1
- package/dist/enums/Notification.d.ts +1 -1
- package/dist/enums/Notification.js +9 -9
- package/dist/enums/Notification.js.map +1 -1
- package/dist/enums/Resource.d.ts +1 -1
- package/dist/enums/Resource.js +42 -42
- package/dist/enums/Resource.js.map +1 -1
- package/dist/enums/Tweet.d.ts +1 -1
- package/dist/enums/Tweet.js +7 -7
- package/dist/enums/Tweet.js.map +1 -1
- package/dist/enums/raw/Analytics.d.ts +2 -2
- package/dist/enums/raw/Analytics.js +21 -21
- package/dist/enums/raw/Analytics.js.map +1 -1
- package/dist/enums/raw/Media.d.ts +1 -1
- package/dist/enums/raw/Media.js +7 -7
- package/dist/enums/raw/Media.js.map +1 -1
- package/dist/enums/raw/Notification.d.ts +1 -1
- package/dist/enums/raw/Notification.js +8 -8
- package/dist/enums/raw/Notification.js.map +1 -1
- package/dist/enums/raw/Tweet.d.ts +2 -2
- package/dist/enums/raw/Tweet.js +12 -12
- package/dist/enums/raw/Tweet.js.map +1 -1
- package/dist/models/RettiwtConfig.d.ts +3 -2
- package/dist/models/RettiwtConfig.js +7 -5
- package/dist/models/RettiwtConfig.js.map +1 -1
- package/dist/models/args/FetchArgs.d.ts +3 -3
- package/dist/models/args/FetchArgs.js +3 -3
- package/dist/models/args/FetchArgs.js.map +1 -1
- package/dist/models/auth/AuthCredential.d.ts +2 -2
- package/dist/models/auth/AuthCredential.js +3 -3
- package/dist/models/auth/AuthCredential.js.map +1 -1
- package/dist/models/data/CursoredData.d.ts +2 -2
- package/dist/models/data/CursoredData.js +3 -3
- package/dist/models/data/CursoredData.js.map +1 -1
- package/dist/models/data/Notification.d.ts +2 -2
- package/dist/models/data/Notification.js +3 -3
- package/dist/models/data/Notification.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +4 -4
- package/dist/models/data/Tweet.js +18 -18
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.js +9 -9
- package/dist/models/data/User.js.map +1 -1
- package/dist/requests/Tweet.d.ts +2 -2
- package/dist/requests/Tweet.js +2 -2
- package/dist/requests/Tweet.js.map +1 -1
- package/dist/requests/User.d.ts +2 -2
- package/dist/requests/User.js.map +1 -1
- package/dist/services/internal/AuthService.js +1 -1
- package/dist/services/internal/AuthService.js.map +1 -1
- package/dist/services/internal/ErrorService.d.ts +2 -2
- package/dist/services/internal/ErrorService.js +4 -4
- package/dist/services/internal/ErrorService.js.map +1 -1
- package/dist/services/internal/LogService.d.ts +2 -2
- package/dist/services/internal/LogService.js.map +1 -1
- package/dist/services/internal/TidService.d.ts +4 -4
- package/dist/services/internal/TidService.js +10 -10
- package/dist/services/internal/TidService.js.map +1 -1
- package/dist/services/public/FetcherService.d.ts +7 -7
- package/dist/services/public/FetcherService.js +79 -35
- package/dist/services/public/FetcherService.js.map +1 -1
- package/dist/services/public/ListService.js +4 -4
- package/dist/services/public/ListService.js.map +1 -1
- package/dist/services/public/TweetService.d.ts +3 -3
- package/dist/services/public/TweetService.js +35 -35
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.js +37 -37
- package/dist/services/public/UserService.js.map +1 -1
- package/dist/types/RettiwtConfig.d.ts +6 -0
- package/dist/types/args/FetchArgs.d.ts +2 -2
- package/dist/types/auth/AuthCredential.d.ts +2 -2
- package/dist/types/data/Notification.d.ts +2 -2
- package/dist/types/data/Tweet.d.ts +2 -2
- package/dist/types/raw/base/Media.d.ts +2 -2
- package/dist/types/raw/base/Notification.d.ts +2 -2
- package/package.json +18 -18
- package/src/cli.ts +20 -14
- package/src/collections/Extractors.ts +21 -21
- package/src/collections/Groups.ts +45 -45
- package/src/collections/Requests.ts +4 -4
- package/src/collections/Tweet.ts +6 -6
- package/src/commands/Tweet.ts +33 -4
- package/src/enums/Api.ts +1 -1
- package/src/enums/Authentication.ts +1 -1
- package/src/enums/Data.ts +1 -1
- package/src/enums/Logging.ts +1 -1
- package/src/enums/Media.ts +1 -1
- package/src/enums/Notification.ts +1 -1
- package/src/enums/Resource.ts +1 -1
- package/src/enums/Tweet.ts +1 -1
- package/src/enums/raw/Analytics.ts +2 -2
- package/src/enums/raw/Media.ts +1 -1
- package/src/enums/raw/Notification.ts +1 -1
- package/src/enums/raw/Tweet.ts +2 -2
- package/src/models/RettiwtConfig.ts +7 -5
- package/src/models/args/FetchArgs.ts +5 -5
- package/src/models/auth/AuthCredential.ts +5 -5
- package/src/models/data/CursoredData.ts +5 -5
- package/src/models/data/Notification.ts +6 -6
- package/src/models/data/Tweet.ts +22 -22
- package/src/models/data/User.ts +10 -10
- package/src/requests/Tweet.ts +4 -4
- package/src/requests/User.ts +3 -3
- package/src/services/internal/AuthService.ts +2 -2
- package/src/services/internal/ErrorService.ts +4 -4
- package/src/services/internal/LogService.ts +2 -2
- package/src/services/internal/TidService.ts +11 -11
- package/src/services/public/FetcherService.ts +54 -38
- package/src/services/public/ListService.ts +6 -6
- package/src/services/public/TweetService.ts +39 -39
- package/src/services/public/UserService.ts +40 -40
- package/src/types/RettiwtConfig.ts +7 -0
- package/src/types/args/FetchArgs.ts +2 -2
- package/src/types/auth/AuthCredential.ts +2 -2
- package/src/types/data/Notification.ts +2 -2
- package/src/types/data/Tweet.ts +2 -2
- package/src/types/raw/base/Media.ts +2 -2
- package/src/types/raw/base/Notification.ts +2 -2
- package/.tool-versions +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { statSync } from 'fs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { Extractors } from '../../collections/Extractors';
|
|
4
|
+
import { ResourceType } from '../../enums/Resource';
|
|
5
|
+
import { TweetRepliesSortType } from '../../enums/Tweet';
|
|
6
6
|
import { CursoredData } from '../../models/data/CursoredData';
|
|
7
7
|
import { Tweet } from '../../models/data/Tweet';
|
|
8
8
|
import { User } from '../../models/data/User';
|
|
@@ -95,41 +95,41 @@ export class TweetService extends FetcherService {
|
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
97
|
public async details<T extends string | string[]>(id: T): Promise<T extends string ? Tweet | undefined : Tweet[]> {
|
|
98
|
-
let resource:
|
|
98
|
+
let resource: ResourceType;
|
|
99
99
|
|
|
100
100
|
// If user is authenticated and details of single tweet required
|
|
101
101
|
if (this.config.userId != undefined && typeof id == 'string') {
|
|
102
|
-
resource =
|
|
102
|
+
resource = ResourceType.TWEET_DETAILS_ALT;
|
|
103
103
|
|
|
104
104
|
// Fetching raw tweet details
|
|
105
105
|
const response = await this.request<ITweetRepliesResponse>(resource, { id: id });
|
|
106
106
|
|
|
107
107
|
// Deserializing response
|
|
108
|
-
const data =
|
|
108
|
+
const data = Extractors[resource](response, id);
|
|
109
109
|
|
|
110
110
|
return data as T extends string ? Tweet | undefined : Tweet[];
|
|
111
111
|
}
|
|
112
112
|
// If user is authenticated and details of multiple tweets required
|
|
113
113
|
else if (this.config.userId != undefined && Array.isArray(id)) {
|
|
114
|
-
resource =
|
|
114
|
+
resource = ResourceType.TWEET_DETAILS_BULK;
|
|
115
115
|
|
|
116
116
|
// Fetching raw tweet details
|
|
117
117
|
const response = await this.request<ITweetDetailsBulkResponse>(resource, { ids: id });
|
|
118
118
|
|
|
119
119
|
// Deserializing response
|
|
120
|
-
const data =
|
|
120
|
+
const data = Extractors[resource](response, id);
|
|
121
121
|
|
|
122
122
|
return data as T extends string ? Tweet | undefined : Tweet[];
|
|
123
123
|
}
|
|
124
124
|
// If user is not authenticated
|
|
125
125
|
else {
|
|
126
|
-
resource =
|
|
126
|
+
resource = ResourceType.TWEET_DETAILS;
|
|
127
127
|
|
|
128
128
|
// Fetching raw tweet details
|
|
129
129
|
const response = await this.request<ITweetDetailsResponse>(resource, { id: String(id) });
|
|
130
130
|
|
|
131
131
|
// Deserializing response
|
|
132
|
-
const data =
|
|
132
|
+
const data = Extractors[resource](response, String(id));
|
|
133
133
|
|
|
134
134
|
return data as T extends string ? Tweet | undefined : Tweet[];
|
|
135
135
|
}
|
|
@@ -161,7 +161,7 @@ export class TweetService extends FetcherService {
|
|
|
161
161
|
* ```
|
|
162
162
|
*/
|
|
163
163
|
public async like(id: string): Promise<boolean> {
|
|
164
|
-
const resource =
|
|
164
|
+
const resource = ResourceType.TWEET_LIKE;
|
|
165
165
|
|
|
166
166
|
// Favoriting the tweet
|
|
167
167
|
const response = await this.request<ITweetLikeResponse>(resource, {
|
|
@@ -169,7 +169,7 @@ export class TweetService extends FetcherService {
|
|
|
169
169
|
});
|
|
170
170
|
|
|
171
171
|
// Deserializing response
|
|
172
|
-
const data =
|
|
172
|
+
const data = Extractors[resource](response) ?? false;
|
|
173
173
|
|
|
174
174
|
return data;
|
|
175
175
|
}
|
|
@@ -202,7 +202,7 @@ export class TweetService extends FetcherService {
|
|
|
202
202
|
* ```
|
|
203
203
|
*/
|
|
204
204
|
public async likers(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
205
|
-
const resource =
|
|
205
|
+
const resource = ResourceType.TWEET_LIKERS;
|
|
206
206
|
|
|
207
207
|
// Fetching raw likers
|
|
208
208
|
const response = await this.request<ITweetLikersResponse>(resource, {
|
|
@@ -212,7 +212,7 @@ export class TweetService extends FetcherService {
|
|
|
212
212
|
});
|
|
213
213
|
|
|
214
214
|
// Deserializing response
|
|
215
|
-
const data =
|
|
215
|
+
const data = Extractors[resource](response);
|
|
216
216
|
|
|
217
217
|
return data;
|
|
218
218
|
}
|
|
@@ -301,13 +301,13 @@ export class TweetService extends FetcherService {
|
|
|
301
301
|
* ```
|
|
302
302
|
*/
|
|
303
303
|
public async post(options: INewTweet): Promise<string | undefined> {
|
|
304
|
-
const resource =
|
|
304
|
+
const resource = ResourceType.TWEET_POST;
|
|
305
305
|
|
|
306
306
|
// Posting the tweet
|
|
307
307
|
const response = await this.request<ITweetPostResponse>(resource, { tweet: options });
|
|
308
308
|
|
|
309
309
|
// Deserializing response
|
|
310
|
-
const data =
|
|
310
|
+
const data = Extractors[resource](response);
|
|
311
311
|
|
|
312
312
|
return data;
|
|
313
313
|
}
|
|
@@ -317,7 +317,7 @@ export class TweetService extends FetcherService {
|
|
|
317
317
|
*
|
|
318
318
|
* @param id - The ID of the target tweet.
|
|
319
319
|
* @param cursor - The cursor to the batch of replies to fetch.
|
|
320
|
-
* @param sortBy - The sorting order of the replies to fetch. Default is {@link
|
|
320
|
+
* @param sortBy - The sorting order of the replies to fetch. Default is {@link TweetRepliesSortType.RECENT}.
|
|
321
321
|
*
|
|
322
322
|
* @returns The list of replies to the given tweet.
|
|
323
323
|
*
|
|
@@ -346,9 +346,9 @@ export class TweetService extends FetcherService {
|
|
|
346
346
|
public async replies(
|
|
347
347
|
id: string,
|
|
348
348
|
cursor?: string,
|
|
349
|
-
sortBy:
|
|
349
|
+
sortBy: TweetRepliesSortType = TweetRepliesSortType.LATEST,
|
|
350
350
|
): Promise<CursoredData<Tweet>> {
|
|
351
|
-
const resource =
|
|
351
|
+
const resource = ResourceType.TWEET_REPLIES;
|
|
352
352
|
|
|
353
353
|
// Fetching raw list of replies
|
|
354
354
|
const response = await this.request<ITweetDetailsResponse>(resource, {
|
|
@@ -358,7 +358,7 @@ export class TweetService extends FetcherService {
|
|
|
358
358
|
});
|
|
359
359
|
|
|
360
360
|
// Deserializing response
|
|
361
|
-
const data =
|
|
361
|
+
const data = Extractors[resource](response);
|
|
362
362
|
|
|
363
363
|
return data;
|
|
364
364
|
}
|
|
@@ -389,13 +389,13 @@ export class TweetService extends FetcherService {
|
|
|
389
389
|
* ```
|
|
390
390
|
*/
|
|
391
391
|
public async retweet(id: string): Promise<boolean> {
|
|
392
|
-
const resource =
|
|
392
|
+
const resource = ResourceType.TWEET_RETWEET;
|
|
393
393
|
|
|
394
394
|
// Retweeting the tweet
|
|
395
395
|
const response = await this.request<ITweetRetweetResponse>(resource, { id: id });
|
|
396
396
|
|
|
397
397
|
// Deserializing response
|
|
398
|
-
const data =
|
|
398
|
+
const data = Extractors[resource](response) ?? false;
|
|
399
399
|
|
|
400
400
|
return data;
|
|
401
401
|
}
|
|
@@ -428,7 +428,7 @@ export class TweetService extends FetcherService {
|
|
|
428
428
|
* ```
|
|
429
429
|
*/
|
|
430
430
|
public async retweeters(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
431
|
-
const resource =
|
|
431
|
+
const resource = ResourceType.TWEET_RETWEETERS;
|
|
432
432
|
|
|
433
433
|
// Fetching raw list of retweeters
|
|
434
434
|
const response = await this.request<ITweetRetweetersResponse>(resource, {
|
|
@@ -438,7 +438,7 @@ export class TweetService extends FetcherService {
|
|
|
438
438
|
});
|
|
439
439
|
|
|
440
440
|
// Deserializing response
|
|
441
|
-
const data =
|
|
441
|
+
const data = Extractors[resource](response);
|
|
442
442
|
|
|
443
443
|
return data;
|
|
444
444
|
}
|
|
@@ -474,13 +474,13 @@ export class TweetService extends FetcherService {
|
|
|
474
474
|
* Scheduling a tweet is similar to {@link post}ing, except that an extra parameter called `scheduleFor` is used.
|
|
475
475
|
*/
|
|
476
476
|
public async schedule(options: INewTweet): Promise<string | undefined> {
|
|
477
|
-
const resource =
|
|
477
|
+
const resource = ResourceType.TWEET_SCHEDULE;
|
|
478
478
|
|
|
479
479
|
// Scheduling the tweet
|
|
480
480
|
const response = await this.request<ITweetScheduleResponse>(resource, { tweet: options });
|
|
481
481
|
|
|
482
482
|
// Deserializing response
|
|
483
|
-
const data =
|
|
483
|
+
const data = Extractors[resource](response);
|
|
484
484
|
|
|
485
485
|
return data;
|
|
486
486
|
}
|
|
@@ -518,7 +518,7 @@ export class TweetService extends FetcherService {
|
|
|
518
518
|
* For details about available filters, refer to {@link TweetFilter}
|
|
519
519
|
*/
|
|
520
520
|
public async search(filter: ITweetFilter, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
521
|
-
const resource =
|
|
521
|
+
const resource = ResourceType.TWEET_SEARCH;
|
|
522
522
|
|
|
523
523
|
// Fetching raw list of filtered tweets
|
|
524
524
|
const response = await this.request<ITweetSearchResponse>(resource, {
|
|
@@ -528,7 +528,7 @@ export class TweetService extends FetcherService {
|
|
|
528
528
|
});
|
|
529
529
|
|
|
530
530
|
// Deserializing response
|
|
531
|
-
const data =
|
|
531
|
+
const data = Extractors[resource](response);
|
|
532
532
|
|
|
533
533
|
// Sorting the tweets by date, from recent to oldest
|
|
534
534
|
data.list.sort((a, b) => new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf());
|
|
@@ -631,13 +631,13 @@ export class TweetService extends FetcherService {
|
|
|
631
631
|
* ```
|
|
632
632
|
*/
|
|
633
633
|
public async unlike(id: string): Promise<boolean> {
|
|
634
|
-
const resource =
|
|
634
|
+
const resource = ResourceType.TWEET_UNLIKE;
|
|
635
635
|
|
|
636
636
|
// Unliking the tweet
|
|
637
637
|
const response = await this.request<ITweetUnlikeResponse>(resource, { id: id });
|
|
638
638
|
|
|
639
639
|
// Deserializing the response
|
|
640
|
-
const data =
|
|
640
|
+
const data = Extractors[resource](response) ?? false;
|
|
641
641
|
|
|
642
642
|
return data;
|
|
643
643
|
}
|
|
@@ -668,13 +668,13 @@ export class TweetService extends FetcherService {
|
|
|
668
668
|
* ```
|
|
669
669
|
*/
|
|
670
670
|
public async unpost(id: string): Promise<boolean> {
|
|
671
|
-
const resource =
|
|
671
|
+
const resource = ResourceType.TWEET_UNPOST;
|
|
672
672
|
|
|
673
673
|
// Unposting the tweet
|
|
674
674
|
const response = await this.request<ITweetUnpostResponse>(resource, { id: id });
|
|
675
675
|
|
|
676
676
|
// Deserializing the response
|
|
677
|
-
const data =
|
|
677
|
+
const data = Extractors[resource](response) ?? false;
|
|
678
678
|
|
|
679
679
|
return data;
|
|
680
680
|
}
|
|
@@ -705,13 +705,13 @@ export class TweetService extends FetcherService {
|
|
|
705
705
|
* ```
|
|
706
706
|
*/
|
|
707
707
|
public async unretweet(id: string): Promise<boolean> {
|
|
708
|
-
const resource =
|
|
708
|
+
const resource = ResourceType.TWEET_UNRETWEET;
|
|
709
709
|
|
|
710
710
|
// Unretweeting the tweet
|
|
711
711
|
const response = await this.request<ITweetUnretweetResponse>(resource, { id: id });
|
|
712
712
|
|
|
713
713
|
// Deserializing the response
|
|
714
|
-
const data =
|
|
714
|
+
const data = Extractors[resource](response) ?? false;
|
|
715
715
|
|
|
716
716
|
return data;
|
|
717
717
|
}
|
|
@@ -742,13 +742,13 @@ export class TweetService extends FetcherService {
|
|
|
742
742
|
* ```
|
|
743
743
|
*/
|
|
744
744
|
public async unschedule(id: string): Promise<boolean> {
|
|
745
|
-
const resource =
|
|
745
|
+
const resource = ResourceType.TWEET_UNSCHEDULE;
|
|
746
746
|
|
|
747
747
|
// Unscheduling the tweet
|
|
748
748
|
const response = await this.request<ITweetUnscheduleResponse>(resource, { id: id });
|
|
749
749
|
|
|
750
750
|
// Deserializing the response
|
|
751
|
-
const data =
|
|
751
|
+
const data = Extractors[resource](response) ?? false;
|
|
752
752
|
|
|
753
753
|
return data;
|
|
754
754
|
}
|
|
@@ -788,16 +788,16 @@ export class TweetService extends FetcherService {
|
|
|
788
788
|
// INITIALIZE
|
|
789
789
|
const size = typeof media == 'string' ? statSync(media).size : media.byteLength;
|
|
790
790
|
const id: string = (
|
|
791
|
-
await this.request<IMediaInitializeUploadResponse>(
|
|
791
|
+
await this.request<IMediaInitializeUploadResponse>(ResourceType.MEDIA_UPLOAD_INITIALIZE, {
|
|
792
792
|
upload: { size: size },
|
|
793
793
|
})
|
|
794
794
|
).media_id_string;
|
|
795
795
|
|
|
796
796
|
// APPEND
|
|
797
|
-
await this.request<unknown>(
|
|
797
|
+
await this.request<unknown>(ResourceType.MEDIA_UPLOAD_APPEND, { upload: { id: id, media: media } });
|
|
798
798
|
|
|
799
799
|
// FINALIZE
|
|
800
|
-
await this.request<unknown>(
|
|
800
|
+
await this.request<unknown>(ResourceType.MEDIA_UPLOAD_FINALIZE, { upload: { id: id } });
|
|
801
801
|
|
|
802
802
|
return id;
|
|
803
803
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Extractors } from '../../collections/Extractors';
|
|
2
|
+
import { ResourceType } from '../../enums/Resource';
|
|
3
3
|
import { CursoredData } from '../../models/data/CursoredData';
|
|
4
4
|
import { Notification } from '../../models/data/Notification';
|
|
5
5
|
import { Tweet } from '../../models/data/Tweet';
|
|
@@ -68,7 +68,7 @@ export class UserService extends FetcherService {
|
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
70
|
public async affiliates(id?: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
71
|
-
const resource =
|
|
71
|
+
const resource = ResourceType.USER_AFFILIATES;
|
|
72
72
|
|
|
73
73
|
// Fetching raw list of affiliates
|
|
74
74
|
const response = await this.request<IUserAffiliatesResponse>(resource, {
|
|
@@ -78,7 +78,7 @@ export class UserService extends FetcherService {
|
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
// Deserializing response
|
|
81
|
-
const data =
|
|
81
|
+
const data = Extractors[resource](response);
|
|
82
82
|
|
|
83
83
|
return data;
|
|
84
84
|
}
|
|
@@ -110,7 +110,7 @@ export class UserService extends FetcherService {
|
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
112
|
public async bookmarks(count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
113
|
-
const resource =
|
|
113
|
+
const resource = ResourceType.USER_BOOKMARKS;
|
|
114
114
|
|
|
115
115
|
// Fetching raw list of likes
|
|
116
116
|
const response = await this.request<IUserBookmarksResponse>(resource, {
|
|
@@ -119,7 +119,7 @@ export class UserService extends FetcherService {
|
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
// Deserializing response
|
|
122
|
-
const data =
|
|
122
|
+
const data = Extractors[resource](response);
|
|
123
123
|
|
|
124
124
|
return data;
|
|
125
125
|
}
|
|
@@ -195,17 +195,17 @@ export class UserService extends FetcherService {
|
|
|
195
195
|
public async details<T extends string | string[] | undefined>(
|
|
196
196
|
id: T,
|
|
197
197
|
): Promise<T extends string | undefined ? User | undefined : User[]> {
|
|
198
|
-
let resource:
|
|
198
|
+
let resource: ResourceType;
|
|
199
199
|
|
|
200
200
|
// If details of multiple users required
|
|
201
201
|
if (Array.isArray(id)) {
|
|
202
|
-
resource =
|
|
202
|
+
resource = ResourceType.USER_DETAILS_BY_IDS_BULK;
|
|
203
203
|
|
|
204
204
|
// Fetching raw details
|
|
205
205
|
const response = await this.request<IUserDetailsBulkResponse>(resource, { ids: id });
|
|
206
206
|
|
|
207
207
|
// Deserializing response
|
|
208
|
-
const data =
|
|
208
|
+
const data = Extractors[resource](response, id);
|
|
209
209
|
|
|
210
210
|
return data as T extends string | undefined ? User | undefined : User[];
|
|
211
211
|
}
|
|
@@ -213,11 +213,11 @@ export class UserService extends FetcherService {
|
|
|
213
213
|
else {
|
|
214
214
|
// If username is given
|
|
215
215
|
if (id && isNaN(Number(id))) {
|
|
216
|
-
resource =
|
|
216
|
+
resource = ResourceType.USER_DETAILS_BY_USERNAME;
|
|
217
217
|
}
|
|
218
218
|
// If id is given (or not, for self details)
|
|
219
219
|
else {
|
|
220
|
-
resource =
|
|
220
|
+
resource = ResourceType.USER_DETAILS_BY_ID;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
// If no ID is given, and not authenticated, skip
|
|
@@ -229,7 +229,7 @@ export class UserService extends FetcherService {
|
|
|
229
229
|
const response = await this.request<IUserDetailsResponse>(resource, { id: id ?? this.config.userId });
|
|
230
230
|
|
|
231
231
|
// Deserializing response
|
|
232
|
-
const data =
|
|
232
|
+
const data = Extractors[resource](response);
|
|
233
233
|
|
|
234
234
|
return data as T extends string | undefined ? User | undefined : User[];
|
|
235
235
|
}
|
|
@@ -263,13 +263,13 @@ export class UserService extends FetcherService {
|
|
|
263
263
|
* ```
|
|
264
264
|
*/
|
|
265
265
|
public async follow(id: string): Promise<boolean> {
|
|
266
|
-
const resource =
|
|
266
|
+
const resource = ResourceType.USER_FOLLOW;
|
|
267
267
|
|
|
268
268
|
// Following the user
|
|
269
|
-
const response = await this.request<IUserFollowResponse>(
|
|
269
|
+
const response = await this.request<IUserFollowResponse>(ResourceType.USER_FOLLOW, { id: id });
|
|
270
270
|
|
|
271
271
|
// Deserializing the response
|
|
272
|
-
const data =
|
|
272
|
+
const data = Extractors[resource](response) ?? false;
|
|
273
273
|
|
|
274
274
|
return data;
|
|
275
275
|
}
|
|
@@ -302,7 +302,7 @@ export class UserService extends FetcherService {
|
|
|
302
302
|
* @remarks Always returns 35 feed items, with no way to customize the count.
|
|
303
303
|
*/
|
|
304
304
|
public async followed(cursor?: string): Promise<CursoredData<Tweet>> {
|
|
305
|
-
const resource =
|
|
305
|
+
const resource = ResourceType.USER_FEED_FOLLOWED;
|
|
306
306
|
|
|
307
307
|
// Fetching raw list of tweets
|
|
308
308
|
const response = await this.request<IUserFollowedResponse>(resource, {
|
|
@@ -310,7 +310,7 @@ export class UserService extends FetcherService {
|
|
|
310
310
|
});
|
|
311
311
|
|
|
312
312
|
// Deserializing response
|
|
313
|
-
const data =
|
|
313
|
+
const data = Extractors[resource](response);
|
|
314
314
|
|
|
315
315
|
return data;
|
|
316
316
|
}
|
|
@@ -343,7 +343,7 @@ export class UserService extends FetcherService {
|
|
|
343
343
|
* ```
|
|
344
344
|
*/
|
|
345
345
|
public async followers(id?: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
346
|
-
const resource =
|
|
346
|
+
const resource = ResourceType.USER_FOLLOWERS;
|
|
347
347
|
|
|
348
348
|
// Fetching raw list of followers
|
|
349
349
|
const response = await this.request<IUserFollowersResponse>(resource, {
|
|
@@ -353,7 +353,7 @@ export class UserService extends FetcherService {
|
|
|
353
353
|
});
|
|
354
354
|
|
|
355
355
|
// Deserializing response
|
|
356
|
-
const data =
|
|
356
|
+
const data = Extractors[resource](response);
|
|
357
357
|
|
|
358
358
|
return data;
|
|
359
359
|
}
|
|
@@ -386,7 +386,7 @@ export class UserService extends FetcherService {
|
|
|
386
386
|
* ```
|
|
387
387
|
*/
|
|
388
388
|
public async following(id?: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
389
|
-
const resource =
|
|
389
|
+
const resource = ResourceType.USER_FOLLOWING;
|
|
390
390
|
|
|
391
391
|
// Fetching raw list of following
|
|
392
392
|
const response = await this.request<IUserFollowingResponse>(resource, {
|
|
@@ -396,7 +396,7 @@ export class UserService extends FetcherService {
|
|
|
396
396
|
});
|
|
397
397
|
|
|
398
398
|
// Deserializing response
|
|
399
|
-
const data =
|
|
399
|
+
const data = Extractors[resource](response);
|
|
400
400
|
|
|
401
401
|
return data;
|
|
402
402
|
}
|
|
@@ -429,7 +429,7 @@ export class UserService extends FetcherService {
|
|
|
429
429
|
* ```
|
|
430
430
|
*/
|
|
431
431
|
public async highlights(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
432
|
-
const resource =
|
|
432
|
+
const resource = ResourceType.USER_HIGHLIGHTS;
|
|
433
433
|
|
|
434
434
|
// Fetching raw list of highlights
|
|
435
435
|
const response = await this.request<IUserHighlightsResponse>(resource, {
|
|
@@ -439,7 +439,7 @@ export class UserService extends FetcherService {
|
|
|
439
439
|
});
|
|
440
440
|
|
|
441
441
|
// Deserializing response
|
|
442
|
-
const data =
|
|
442
|
+
const data = Extractors[resource](response);
|
|
443
443
|
|
|
444
444
|
return data;
|
|
445
445
|
}
|
|
@@ -471,7 +471,7 @@ export class UserService extends FetcherService {
|
|
|
471
471
|
* ```
|
|
472
472
|
*/
|
|
473
473
|
public async likes(count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
474
|
-
const resource =
|
|
474
|
+
const resource = ResourceType.USER_LIKES;
|
|
475
475
|
|
|
476
476
|
// Fetching raw list of likes
|
|
477
477
|
const response = await this.request<IUserLikesResponse>(resource, {
|
|
@@ -481,7 +481,7 @@ export class UserService extends FetcherService {
|
|
|
481
481
|
});
|
|
482
482
|
|
|
483
483
|
// Deserializing response
|
|
484
|
-
const data =
|
|
484
|
+
const data = Extractors[resource](response);
|
|
485
485
|
|
|
486
486
|
return data;
|
|
487
487
|
}
|
|
@@ -514,7 +514,7 @@ export class UserService extends FetcherService {
|
|
|
514
514
|
* ```
|
|
515
515
|
*/
|
|
516
516
|
public async media(id?: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
517
|
-
const resource =
|
|
517
|
+
const resource = ResourceType.USER_MEDIA;
|
|
518
518
|
|
|
519
519
|
// Fetching raw list of media
|
|
520
520
|
const response = await this.request<IUserMediaResponse>(resource, {
|
|
@@ -524,7 +524,7 @@ export class UserService extends FetcherService {
|
|
|
524
524
|
});
|
|
525
525
|
|
|
526
526
|
// Deserializing response
|
|
527
|
-
const data =
|
|
527
|
+
const data = Extractors[resource](response);
|
|
528
528
|
|
|
529
529
|
return data;
|
|
530
530
|
}
|
|
@@ -562,7 +562,7 @@ export class UserService extends FetcherService {
|
|
|
562
562
|
* ```
|
|
563
563
|
*/
|
|
564
564
|
public async *notifications(pollingInterval = 60000): AsyncGenerator<Notification> {
|
|
565
|
-
const resource =
|
|
565
|
+
const resource = ResourceType.USER_NOTIFICATIONS;
|
|
566
566
|
|
|
567
567
|
/** Whether it's the first batch of notifications or not. */
|
|
568
568
|
let first = true;
|
|
@@ -581,7 +581,7 @@ export class UserService extends FetcherService {
|
|
|
581
581
|
});
|
|
582
582
|
|
|
583
583
|
// Deserializing response
|
|
584
|
-
const notifications =
|
|
584
|
+
const notifications = Extractors[resource](response);
|
|
585
585
|
|
|
586
586
|
// Sorting the notifications by time, from oldest to recent
|
|
587
587
|
notifications.list.sort((a, b) => new Date(a.receivedAt).valueOf() - new Date(b.receivedAt).valueOf());
|
|
@@ -630,7 +630,7 @@ export class UserService extends FetcherService {
|
|
|
630
630
|
* @remarks Always returns 35 feed items, with no way to customize the count.
|
|
631
631
|
*/
|
|
632
632
|
public async recommended(cursor?: string): Promise<CursoredData<Tweet>> {
|
|
633
|
-
const resource =
|
|
633
|
+
const resource = ResourceType.USER_FEED_RECOMMENDED;
|
|
634
634
|
|
|
635
635
|
// Fetching raw list of tweets
|
|
636
636
|
const response = await this.request<IUserRecommendedResponse>(resource, {
|
|
@@ -638,7 +638,7 @@ export class UserService extends FetcherService {
|
|
|
638
638
|
});
|
|
639
639
|
|
|
640
640
|
// Deserializing response
|
|
641
|
-
const data =
|
|
641
|
+
const data = Extractors[resource](response);
|
|
642
642
|
|
|
643
643
|
return data;
|
|
644
644
|
}
|
|
@@ -675,7 +675,7 @@ export class UserService extends FetcherService {
|
|
|
675
675
|
* If the target user has a pinned tweet, the returned reply timeline has one item extra and this is always the pinned tweet.
|
|
676
676
|
*/
|
|
677
677
|
public async replies(id?: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
678
|
-
const resource =
|
|
678
|
+
const resource = ResourceType.USER_TIMELINE_AND_REPLIES;
|
|
679
679
|
|
|
680
680
|
// Fetching raw list of replies
|
|
681
681
|
const response = await this.request<IUserTweetsAndRepliesResponse>(resource, {
|
|
@@ -685,7 +685,7 @@ export class UserService extends FetcherService {
|
|
|
685
685
|
});
|
|
686
686
|
|
|
687
687
|
// Deserializing response
|
|
688
|
-
const data =
|
|
688
|
+
const data = Extractors[resource](response);
|
|
689
689
|
|
|
690
690
|
return data;
|
|
691
691
|
}
|
|
@@ -720,7 +720,7 @@ export class UserService extends FetcherService {
|
|
|
720
720
|
* ```
|
|
721
721
|
*/
|
|
722
722
|
public async subscriptions(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
723
|
-
const resource =
|
|
723
|
+
const resource = ResourceType.USER_SUBSCRIPTIONS;
|
|
724
724
|
|
|
725
725
|
// Fetching raw list of subscriptions
|
|
726
726
|
const response = await this.request<IUserSubscriptionsResponse>(resource, {
|
|
@@ -730,7 +730,7 @@ export class UserService extends FetcherService {
|
|
|
730
730
|
});
|
|
731
731
|
|
|
732
732
|
// Deserializing response
|
|
733
|
-
const data =
|
|
733
|
+
const data = Extractors[resource](response);
|
|
734
734
|
|
|
735
735
|
return data;
|
|
736
736
|
}
|
|
@@ -768,7 +768,7 @@ export class UserService extends FetcherService {
|
|
|
768
768
|
* - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
|
|
769
769
|
*/
|
|
770
770
|
public async timeline(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
771
|
-
const resource =
|
|
771
|
+
const resource = ResourceType.USER_TIMELINE;
|
|
772
772
|
|
|
773
773
|
// Fetching raw list of tweets
|
|
774
774
|
const response = await this.request<IUserTweetsResponse>(resource, {
|
|
@@ -778,7 +778,7 @@ export class UserService extends FetcherService {
|
|
|
778
778
|
});
|
|
779
779
|
|
|
780
780
|
// Deserializing response
|
|
781
|
-
const data =
|
|
781
|
+
const data = Extractors[resource](response);
|
|
782
782
|
|
|
783
783
|
return data;
|
|
784
784
|
}
|
|
@@ -809,13 +809,13 @@ export class UserService extends FetcherService {
|
|
|
809
809
|
* ```
|
|
810
810
|
*/
|
|
811
811
|
public async unfollow(id: string): Promise<boolean> {
|
|
812
|
-
const resource =
|
|
812
|
+
const resource = ResourceType.USER_UNFOLLOW;
|
|
813
813
|
|
|
814
814
|
// Unfollowing the user
|
|
815
|
-
const response = await this.request<IUserUnfollowResponse>(
|
|
815
|
+
const response = await this.request<IUserUnfollowResponse>(ResourceType.USER_UNFOLLOW, { id: id });
|
|
816
816
|
|
|
817
817
|
// Deserializing the response
|
|
818
|
-
const data =
|
|
818
|
+
const data = Extractors[resource](response) ?? false;
|
|
819
819
|
|
|
820
820
|
return data;
|
|
821
821
|
}
|
|
@@ -42,4 +42,11 @@ export interface IRettiwtConfig {
|
|
|
42
42
|
* Can either be a number or a function that returns a number synchronously or asynchronously.
|
|
43
43
|
*/
|
|
44
44
|
delay?: number | (() => number | Promise<number>);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The maximum number of retries to use.
|
|
48
|
+
*
|
|
49
|
+
* @remarks Recommended to use a value of 5 combined with a `delay` of 1000 to prevent error 404.
|
|
50
|
+
*/
|
|
51
|
+
maxRetries?: number;
|
|
45
52
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TweetRepliesSortType } from '../../enums/Tweet';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Options specifying the data that is to be fetched.
|
|
@@ -64,7 +64,7 @@ export interface IFetchArgs {
|
|
|
64
64
|
* @remarks
|
|
65
65
|
* - Only works for {@link EResourceType.TWEET_REPLIES}.
|
|
66
66
|
*/
|
|
67
|
-
sortBy?:
|
|
67
|
+
sortBy?: TweetRepliesSortType;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AuthenticationType } from '../../enums/Authentication';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The credentials for authenticating against Twitter.
|
|
@@ -15,7 +15,7 @@ export interface IAuthCredential {
|
|
|
15
15
|
authToken?: string;
|
|
16
16
|
|
|
17
17
|
/** The type of authentication. */
|
|
18
|
-
authenticationType?:
|
|
18
|
+
authenticationType?: AuthenticationType;
|
|
19
19
|
|
|
20
20
|
/** The cookie of the twitter account, which is used to authenticate against twitter. */
|
|
21
21
|
cookies?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NotificationType } from '../../enums/Notification';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The details of a single notification.
|
|
@@ -22,5 +22,5 @@ export interface INotification {
|
|
|
22
22
|
target: string[];
|
|
23
23
|
|
|
24
24
|
/** The type of notification. */
|
|
25
|
-
type?:
|
|
25
|
+
type?: NotificationType;
|
|
26
26
|
}
|
package/src/types/data/Tweet.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MediaType } from '../../enums/Media';
|
|
2
2
|
|
|
3
3
|
import { IUser } from './User';
|
|
4
4
|
|
|
@@ -89,7 +89,7 @@ export interface ITweetMedia {
|
|
|
89
89
|
thumbnailUrl?: string;
|
|
90
90
|
|
|
91
91
|
/** The type of media. */
|
|
92
|
-
type:
|
|
92
|
+
type: MediaType;
|
|
93
93
|
|
|
94
94
|
/** The direct URL to the media. */
|
|
95
95
|
url: string;
|