rettiwt-api 5.0.1 → 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 +48 -12
- 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 +7 -5
- package/dist/models/args/FetchArgs.js +15 -9
- 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 +14 -6
- 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 +49 -12
- 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 +17 -11
- 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 +18 -8
- 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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseType } from '../enums/Data';
|
|
2
2
|
import { CursoredData } from '../models/data/CursoredData';
|
|
3
3
|
import { Notification } from '../models/data/Notification';
|
|
4
4
|
import { Tweet } from '../models/data/Tweet';
|
|
@@ -43,13 +43,13 @@ import { IUserUnfollowResponse } from '../types/raw/user/Unfollow';
|
|
|
43
43
|
*
|
|
44
44
|
* @internal
|
|
45
45
|
*/
|
|
46
|
-
export const
|
|
46
|
+
export const Extractors = {
|
|
47
47
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
48
48
|
|
|
49
49
|
LIST_MEMBERS: (response: IListMembersResponse): CursoredData<User> =>
|
|
50
|
-
new CursoredData<User>(response,
|
|
50
|
+
new CursoredData<User>(response, BaseType.USER),
|
|
51
51
|
LIST_TWEETS: (response: IListTweetsResponse): CursoredData<Tweet> =>
|
|
52
|
-
new CursoredData<Tweet>(response,
|
|
52
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
53
53
|
|
|
54
54
|
MEDIA_UPLOAD_APPEND: (): void => undefined,
|
|
55
55
|
MEDIA_UPLOAD_FINALIZE: (): void => undefined,
|
|
@@ -61,17 +61,17 @@ export const extractors = {
|
|
|
61
61
|
TWEET_DETAILS_BULK: (response: ITweetDetailsBulkResponse, ids: string[]): Tweet[] => Tweet.multiple(response, ids),
|
|
62
62
|
TWEET_LIKE: (response: ITweetLikeResponse): boolean => (response?.data?.favorite_tweet ? true : false),
|
|
63
63
|
TWEET_LIKERS: (response: ITweetLikersResponse): CursoredData<User> =>
|
|
64
|
-
new CursoredData<User>(response,
|
|
64
|
+
new CursoredData<User>(response, BaseType.USER),
|
|
65
65
|
TWEET_POST: (response: ITweetPostResponse): string =>
|
|
66
66
|
response?.data?.create_tweet?.tweet_results?.result?.rest_id ?? undefined,
|
|
67
67
|
TWEET_REPLIES: (response: ITweetDetailsResponse): CursoredData<Tweet> =>
|
|
68
|
-
new CursoredData<Tweet>(response,
|
|
68
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
69
69
|
TWEET_RETWEET: (response: ITweetRetweetResponse): boolean => (response?.data?.create_retweet ? true : false),
|
|
70
70
|
TWEET_RETWEETERS: (response: ITweetRetweetersResponse): CursoredData<User> =>
|
|
71
|
-
new CursoredData<User>(response,
|
|
71
|
+
new CursoredData<User>(response, BaseType.USER),
|
|
72
72
|
TWEET_SCHEDULE: (response: ITweetScheduleResponse): string => response?.data?.tweet?.rest_id ?? undefined,
|
|
73
73
|
TWEET_SEARCH: (response: ITweetSearchResponse): CursoredData<Tweet> =>
|
|
74
|
-
new CursoredData<Tweet>(response,
|
|
74
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
75
75
|
TWEET_UNLIKE: (response: ITweetUnlikeResponse): boolean => (response?.data?.unfavorite_tweet ? true : false),
|
|
76
76
|
TWEET_UNPOST: (response: ITweetUnpostResponse): boolean => (response?.data?.delete_tweet ? true : false),
|
|
77
77
|
TWEET_UNRETWEET: (response: ITweetUnretweetResponse): boolean =>
|
|
@@ -79,36 +79,36 @@ export const extractors = {
|
|
|
79
79
|
TWEET_UNSCHEDULE: (response: ITweetUnscheduleResponse): boolean => response?.data?.scheduledtweet_delete == 'Done',
|
|
80
80
|
|
|
81
81
|
USER_AFFILIATES: (response: IUserAffiliatesResponse): CursoredData<User> =>
|
|
82
|
-
new CursoredData<User>(response,
|
|
82
|
+
new CursoredData<User>(response, BaseType.USER),
|
|
83
83
|
USER_BOOKMARKS: (response: IUserBookmarksResponse): CursoredData<Tweet> =>
|
|
84
|
-
new CursoredData<Tweet>(response,
|
|
84
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
85
85
|
USER_DETAILS_BY_USERNAME: (response: IUserDetailsResponse): User | undefined => User.single(response),
|
|
86
86
|
USER_DETAILS_BY_ID: (response: IUserDetailsResponse): User | undefined => User.single(response),
|
|
87
87
|
USER_DETAILS_BY_IDS_BULK: (response: IUserDetailsBulkResponse, ids: string[]): User[] =>
|
|
88
88
|
User.multiple(response, ids),
|
|
89
89
|
USER_FEED_FOLLOWED: (response: IUserFollowedResponse): CursoredData<Tweet> =>
|
|
90
|
-
new CursoredData<Tweet>(response,
|
|
90
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
91
91
|
USER_FEED_RECOMMENDED: (response: IUserRecommendedResponse): CursoredData<Tweet> =>
|
|
92
|
-
new CursoredData<Tweet>(response,
|
|
92
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
93
93
|
USER_FOLLOW: (response: IUserFollowResponse): boolean => (response?.id ? true : false),
|
|
94
94
|
USER_FOLLOWING: (response: IUserFollowingResponse): CursoredData<User> =>
|
|
95
|
-
new CursoredData<User>(response,
|
|
95
|
+
new CursoredData<User>(response, BaseType.USER),
|
|
96
96
|
USER_FOLLOWERS: (response: IUserFollowersResponse): CursoredData<User> =>
|
|
97
|
-
new CursoredData<User>(response,
|
|
97
|
+
new CursoredData<User>(response, BaseType.USER),
|
|
98
98
|
USER_HIGHLIGHTS: (response: IUserHighlightsResponse): CursoredData<Tweet> =>
|
|
99
|
-
new CursoredData<Tweet>(response,
|
|
99
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
100
100
|
USER_LIKES: (response: IUserLikesResponse): CursoredData<Tweet> =>
|
|
101
|
-
new CursoredData<Tweet>(response,
|
|
101
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
102
102
|
USER_MEDIA: (response: IUserMediaResponse): CursoredData<Tweet> =>
|
|
103
|
-
new CursoredData<Tweet>(response,
|
|
103
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
104
104
|
USER_NOTIFICATIONS: (response: IUserNotificationsResponse): CursoredData<Notification> =>
|
|
105
|
-
new CursoredData<Notification>(response,
|
|
105
|
+
new CursoredData<Notification>(response, BaseType.NOTIFICATION),
|
|
106
106
|
USER_SUBSCRIPTIONS: (response: IUserSubscriptionsResponse): CursoredData<User> =>
|
|
107
|
-
new CursoredData<User>(response,
|
|
107
|
+
new CursoredData<User>(response, BaseType.USER),
|
|
108
108
|
USER_TIMELINE: (response: IUserTweetsResponse): CursoredData<Tweet> =>
|
|
109
|
-
new CursoredData<Tweet>(response,
|
|
109
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
110
110
|
USER_TIMELINE_AND_REPLIES: (response: IUserTweetsAndRepliesResponse): CursoredData<Tweet> =>
|
|
111
|
-
new CursoredData<Tweet>(response,
|
|
111
|
+
new CursoredData<Tweet>(response, BaseType.TWEET),
|
|
112
112
|
USER_UNFOLLOW: (response: IUserUnfollowResponse): boolean => (response?.id ? true : false),
|
|
113
113
|
|
|
114
114
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResourceType } from '../enums/Resource';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Collection of resources that allow guest authentication.
|
|
5
5
|
*
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export const AllowGuestAuthenticationGroup = [
|
|
9
|
+
ResourceType.TWEET_DETAILS,
|
|
10
|
+
ResourceType.USER_DETAILS_BY_USERNAME,
|
|
11
|
+
ResourceType.USER_TIMELINE,
|
|
12
12
|
];
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -16,32 +16,32 @@ export const allowGuestAuthentication = [
|
|
|
16
16
|
*
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
|
-
export const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
19
|
+
export const FetchResourcesGroup = [
|
|
20
|
+
ResourceType.LIST_MEMBERS,
|
|
21
|
+
ResourceType.LIST_TWEETS,
|
|
22
|
+
ResourceType.TWEET_DETAILS,
|
|
23
|
+
ResourceType.TWEET_DETAILS_ALT,
|
|
24
|
+
ResourceType.TWEET_DETAILS_BULK,
|
|
25
|
+
ResourceType.TWEET_LIKERS,
|
|
26
|
+
ResourceType.TWEET_REPLIES,
|
|
27
|
+
ResourceType.TWEET_RETWEETERS,
|
|
28
|
+
ResourceType.TWEET_SEARCH,
|
|
29
|
+
ResourceType.USER_AFFILIATES,
|
|
30
|
+
ResourceType.USER_BOOKMARKS,
|
|
31
|
+
ResourceType.USER_DETAILS_BY_USERNAME,
|
|
32
|
+
ResourceType.USER_DETAILS_BY_ID,
|
|
33
|
+
ResourceType.USER_DETAILS_BY_IDS_BULK,
|
|
34
|
+
ResourceType.USER_FEED_FOLLOWED,
|
|
35
|
+
ResourceType.USER_FEED_RECOMMENDED,
|
|
36
|
+
ResourceType.USER_FOLLOWING,
|
|
37
|
+
ResourceType.USER_FOLLOWERS,
|
|
38
|
+
ResourceType.USER_HIGHLIGHTS,
|
|
39
|
+
ResourceType.USER_LIKES,
|
|
40
|
+
ResourceType.USER_MEDIA,
|
|
41
|
+
ResourceType.USER_NOTIFICATIONS,
|
|
42
|
+
ResourceType.USER_SUBSCRIPTIONS,
|
|
43
|
+
ResourceType.USER_TIMELINE,
|
|
44
|
+
ResourceType.USER_TIMELINE_AND_REPLIES,
|
|
45
45
|
];
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -49,18 +49,18 @@ export const fetchResources = [
|
|
|
49
49
|
*
|
|
50
50
|
* @internal
|
|
51
51
|
*/
|
|
52
|
-
export const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
export const PostResourcesGroup = [
|
|
53
|
+
ResourceType.MEDIA_UPLOAD_APPEND,
|
|
54
|
+
ResourceType.MEDIA_UPLOAD_FINALIZE,
|
|
55
|
+
ResourceType.MEDIA_UPLOAD_INITIALIZE,
|
|
56
|
+
ResourceType.TWEET_LIKE,
|
|
57
|
+
ResourceType.TWEET_POST,
|
|
58
|
+
ResourceType.TWEET_RETWEET,
|
|
59
|
+
ResourceType.TWEET_SCHEDULE,
|
|
60
|
+
ResourceType.TWEET_UNLIKE,
|
|
61
|
+
ResourceType.TWEET_UNPOST,
|
|
62
|
+
ResourceType.TWEET_UNRETWEET,
|
|
63
|
+
ResourceType.TWEET_UNSCHEDULE,
|
|
64
|
+
ResourceType.USER_FOLLOW,
|
|
65
|
+
ResourceType.USER_UNFOLLOW,
|
|
66
66
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { ResourceType } from '../enums/Resource';
|
|
4
4
|
import { ListRequests } from '../requests/List';
|
|
5
5
|
import { MediaRequests } from '../requests/Media';
|
|
6
6
|
import { TweetRequests } from '../requests/Tweet';
|
|
@@ -8,14 +8,14 @@ import { UserRequests } from '../requests/User';
|
|
|
8
8
|
import { IFetchArgs } from '../types/args/FetchArgs';
|
|
9
9
|
import { IPostArgs } from '../types/args/PostArgs';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { TweetRepliesSortTypeMap } from './Tweet';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Collection of requests to various resources.
|
|
15
15
|
*
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
|
-
export const
|
|
18
|
+
export const Requests: { [key in keyof typeof ResourceType]: (args: IFetchArgs | IPostArgs) => AxiosRequestConfig } = {
|
|
19
19
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
20
20
|
|
|
21
21
|
LIST_MEMBERS: (args: IFetchArgs) => ListRequests.members(args.id!, args.count, args.cursor),
|
|
@@ -32,7 +32,7 @@ export const requests: { [key in keyof typeof EResourceType]: (args: IFetchArgs
|
|
|
32
32
|
TWEET_LIKERS: (args: IFetchArgs) => TweetRequests.likers(args.id!, args.count, args.cursor),
|
|
33
33
|
TWEET_POST: (args: IPostArgs) => TweetRequests.post(args.tweet!),
|
|
34
34
|
TWEET_REPLIES: (args: IFetchArgs) =>
|
|
35
|
-
TweetRequests.replies(args.id!, args.cursor, args.sortBy ?
|
|
35
|
+
TweetRequests.replies(args.id!, args.cursor, args.sortBy ? TweetRepliesSortTypeMap[args.sortBy] : undefined),
|
|
36
36
|
TWEET_RETWEET: (args: IPostArgs) => TweetRequests.retweet(args.id!),
|
|
37
37
|
TWEET_RETWEETERS: (args: IFetchArgs) => TweetRequests.retweeters(args.id!, args.count, args.cursor),
|
|
38
38
|
TWEET_SCHEDULE: (args: IPostArgs) => TweetRequests.schedule(args.tweet!),
|
package/src/collections/Tweet.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { RawTweetRepliesSortType } from '../enums/raw/Tweet';
|
|
2
|
+
import { TweetRepliesSortType } from '../enums/Tweet';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Collection of mapping from parsed reply sort type to raw reply sort type.
|
|
6
6
|
*
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const TweetRepliesSortTypeMap: { [key in keyof typeof TweetRepliesSortType]: RawTweetRepliesSortType } = {
|
|
10
10
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
11
11
|
|
|
12
|
-
LATEST:
|
|
13
|
-
LIKES:
|
|
14
|
-
RELEVANCE:
|
|
12
|
+
LATEST: RawTweetRepliesSortType.LATEST,
|
|
13
|
+
LIKES: RawTweetRepliesSortType.LIKES,
|
|
14
|
+
RELEVANCE: RawTweetRepliesSortType.RELEVACE,
|
|
15
15
|
|
|
16
16
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
17
17
|
};
|
package/src/commands/Tweet.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Command, createCommand } from 'commander';
|
|
2
2
|
|
|
3
|
+
import { TweetRepliesSortType } from '../enums/Tweet';
|
|
3
4
|
import { output } from '../helper/CliUtils';
|
|
4
5
|
import { TweetFilter } from '../models/args/FetchArgs';
|
|
5
6
|
import { Rettiwt } from '../Rettiwt';
|
|
@@ -63,8 +64,8 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
63
64
|
.argument('[cursor]', 'The cursor to the batch of likers to fetch')
|
|
64
65
|
.action(async (id: string, count?: string, cursor?: string) => {
|
|
65
66
|
try {
|
|
66
|
-
const
|
|
67
|
-
output(
|
|
67
|
+
const users = await rettiwt.tweet.likers(id, count ? parseInt(count) : undefined, cursor);
|
|
68
|
+
output(users);
|
|
68
69
|
} catch (error) {
|
|
69
70
|
output(error);
|
|
70
71
|
}
|
|
@@ -95,6 +96,34 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
98
|
|
|
99
|
+
// Replies
|
|
100
|
+
tweet
|
|
101
|
+
.command('replies')
|
|
102
|
+
.description(
|
|
103
|
+
'Fetch the list of replies to a tweet, with the first batch containing the whole thread, if the tweet is/part of a thread',
|
|
104
|
+
)
|
|
105
|
+
.argument('<id>', 'The id of the tweet')
|
|
106
|
+
.argument('[cursor]', 'The cursor to the batch of replies to fetch')
|
|
107
|
+
.option('-s, --sort-by <string>', 'Sort the tweets by likes, latest or relevance, default is latest')
|
|
108
|
+
.action(async (id: string, cursor?: string, options?: { sortBy: string }) => {
|
|
109
|
+
try {
|
|
110
|
+
// Determining the sort type
|
|
111
|
+
let sortType: TweetRepliesSortType | undefined = undefined;
|
|
112
|
+
if (options?.sortBy === 'likes') {
|
|
113
|
+
sortType = TweetRepliesSortType.LIKES;
|
|
114
|
+
} else if (options?.sortBy === 'latest') {
|
|
115
|
+
sortType = TweetRepliesSortType.LATEST;
|
|
116
|
+
} else if (options?.sortBy === 'relevance') {
|
|
117
|
+
sortType = TweetRepliesSortType.RELEVANCE;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const tweets = await rettiwt.tweet.replies(id, cursor, sortType);
|
|
121
|
+
output(tweets);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
output(error);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
98
127
|
// Retweet
|
|
99
128
|
tweet
|
|
100
129
|
.command('retweet')
|
|
@@ -118,8 +147,8 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
118
147
|
.argument('[cursor]', 'The cursor to the batch of retweeters to fetch')
|
|
119
148
|
.action(async (id: string, count?: string, cursor?: string) => {
|
|
120
149
|
try {
|
|
121
|
-
const
|
|
122
|
-
output(
|
|
150
|
+
const users = await rettiwt.tweet.retweeters(id, count ? parseInt(count) : undefined, cursor);
|
|
151
|
+
output(users);
|
|
123
152
|
} catch (error) {
|
|
124
153
|
output(error);
|
|
125
154
|
}
|
|
@@ -180,8 +209,10 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
180
209
|
.option('-l, --min-likes <number>', 'Matches the tweets that have a minimum of given number of likes')
|
|
181
210
|
.option('-x, --min-retweets <number>', 'Matches the tweets that have a minimum of given number of retweets')
|
|
182
211
|
.option('-q, --quoted <string>', 'Matches the tweets that quote the tweet with the given id')
|
|
183
|
-
.option('--
|
|
184
|
-
.option('--
|
|
212
|
+
.option('--only-original', 'Matches tweets are original posts')
|
|
213
|
+
.option('--only-replies', 'Matches tweets that are replies')
|
|
214
|
+
.option('--only-text', 'Matches tweets that are only text')
|
|
215
|
+
.option('--only-links', 'Matches tweets that only contain links like media, quotes, etc')
|
|
185
216
|
.option('-s, --start <string>', 'Matches the tweets made since the given date (valid date/time string)')
|
|
186
217
|
.option('-e, --end <string>', 'Matches the tweets made upto the given date (valid date/time string)')
|
|
187
218
|
.option('--top', 'Matches top tweets instead of latest')
|
|
@@ -292,8 +323,6 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
292
323
|
*/
|
|
293
324
|
class TweetSearchOptions {
|
|
294
325
|
public end?: string;
|
|
295
|
-
public excludeLinks?: boolean = false;
|
|
296
|
-
public excludeReplies?: boolean = false;
|
|
297
326
|
public excludeWords?: string;
|
|
298
327
|
public from?: string;
|
|
299
328
|
public hashtags?: string;
|
|
@@ -303,6 +332,10 @@ class TweetSearchOptions {
|
|
|
303
332
|
public minLikes?: number;
|
|
304
333
|
public minReplies?: number;
|
|
305
334
|
public minRetweets?: number;
|
|
335
|
+
public onlyLinks?: boolean = false;
|
|
336
|
+
public onlyOriginal?: boolean = false;
|
|
337
|
+
public onlyReplies?: boolean = false;
|
|
338
|
+
public onlyText?: boolean = false;
|
|
306
339
|
public optionalWords?: string;
|
|
307
340
|
public phrase?: string;
|
|
308
341
|
public quoted?: string;
|
|
@@ -330,9 +363,11 @@ class TweetSearchOptions {
|
|
|
330
363
|
this.minReplies = options?.minReplies;
|
|
331
364
|
this.minLikes = options?.minLikes;
|
|
332
365
|
this.minRetweets = options?.minRetweets;
|
|
366
|
+
this.onlyLinks = options?.onlyLinks;
|
|
367
|
+
this.onlyOriginal = options?.onlyOriginal;
|
|
368
|
+
this.onlyReplies = options?.onlyReplies;
|
|
369
|
+
this.onlyText = options?.onlyText;
|
|
333
370
|
this.quoted = options?.quoted;
|
|
334
|
-
this.excludeLinks = options?.excludeLinks;
|
|
335
|
-
this.excludeReplies = options?.excludeReplies;
|
|
336
371
|
this.start = options?.start;
|
|
337
372
|
this.end = options?.end;
|
|
338
373
|
this.stream = options?.stream;
|
|
@@ -359,9 +394,11 @@ class TweetSearchOptions {
|
|
|
359
394
|
minReplies: this.minReplies,
|
|
360
395
|
minLikes: this.minLikes,
|
|
361
396
|
minRetweets: this.minRetweets,
|
|
397
|
+
onlyLinks: this.onlyLinks,
|
|
398
|
+
onlyOriginal: this.onlyOriginal,
|
|
399
|
+
onlyReplies: this.onlyReplies,
|
|
400
|
+
onlyText: this.onlyText,
|
|
362
401
|
quoted: this.quoted,
|
|
363
|
-
links: !this.excludeLinks,
|
|
364
|
-
replies: !this.excludeReplies,
|
|
365
402
|
startDate: this.start ? new Date(this.start) : undefined,
|
|
366
403
|
top: this.top,
|
|
367
404
|
endDate: this.end ? new Date(this.end) : undefined,
|
package/src/enums/Api.ts
CHANGED
package/src/enums/Data.ts
CHANGED
package/src/enums/Logging.ts
CHANGED
package/src/enums/Media.ts
CHANGED
package/src/enums/Resource.ts
CHANGED
package/src/enums/Tweet.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export enum
|
|
6
|
+
export enum RawAnalyticsGranularity {
|
|
7
7
|
DAILY = 'Daily',
|
|
8
8
|
WEEKLY = 'Weekly',
|
|
9
9
|
MONTHLY = 'Monthly',
|
|
@@ -14,7 +14,7 @@ export enum ERawAnalyticsGranularity {
|
|
|
14
14
|
*
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
|
-
export enum
|
|
17
|
+
export enum RawAnalyticsMetric {
|
|
18
18
|
ENGAGEMENTS = 'Engagements',
|
|
19
19
|
IMPRESSIONS = 'Impressions',
|
|
20
20
|
PROFILE_VISITS = 'ProfileVisits',
|
package/src/enums/raw/Media.ts
CHANGED
package/src/enums/raw/Tweet.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export enum
|
|
6
|
+
export enum RawTweetSearchResultType {
|
|
7
7
|
LATEST = 'Latest',
|
|
8
8
|
TOP = 'Top',
|
|
9
9
|
}
|
|
@@ -13,7 +13,7 @@ export enum ERawTweetSearchResultType {
|
|
|
13
13
|
*
|
|
14
14
|
* @public
|
|
15
15
|
*/
|
|
16
|
-
export enum
|
|
16
|
+
export enum RawTweetRepliesSortType {
|
|
17
17
|
RELEVACE = 'Relevance',
|
|
18
18
|
LATEST = 'Recency',
|
|
19
19
|
LIKES = 'Likes',
|
|
@@ -12,7 +12,7 @@ import { IRettiwtConfig } from '../types/RettiwtConfig';
|
|
|
12
12
|
*
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
|
-
const
|
|
15
|
+
const DefaultHeaders = {
|
|
16
16
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
17
17
|
|
|
18
18
|
Authority: 'x.com',
|
|
@@ -43,6 +43,7 @@ export class RettiwtConfig implements IRettiwtConfig {
|
|
|
43
43
|
public readonly delay?: number | (() => number | Promise<number>);
|
|
44
44
|
public readonly errorHandler?: IErrorHandler;
|
|
45
45
|
public readonly logging?: boolean;
|
|
46
|
+
public readonly maxRetries: number;
|
|
46
47
|
public readonly tidProvider?: ITidProvider;
|
|
47
48
|
public readonly timeout?: number;
|
|
48
49
|
|
|
@@ -53,14 +54,15 @@ export class RettiwtConfig implements IRettiwtConfig {
|
|
|
53
54
|
this._apiKey = config?.apiKey;
|
|
54
55
|
this._httpsAgent = config?.proxyUrl ? new HttpsProxyAgent(config?.proxyUrl) : new Agent();
|
|
55
56
|
this._userId = config?.apiKey ? AuthService.getUserId(config?.apiKey) : undefined;
|
|
56
|
-
this.delay = config?.delay;
|
|
57
|
+
this.delay = config?.delay ?? 1000;
|
|
58
|
+
this.maxRetries = config?.maxRetries ?? 5;
|
|
57
59
|
this.errorHandler = config?.errorHandler;
|
|
58
60
|
this.logging = config?.logging;
|
|
59
61
|
this.tidProvider = config?.tidProvider;
|
|
60
62
|
this.timeout = config?.timeout;
|
|
61
63
|
this.apiKey = config?.apiKey;
|
|
62
64
|
this._headers = {
|
|
63
|
-
...
|
|
65
|
+
...DefaultHeaders,
|
|
64
66
|
...config?.headers,
|
|
65
67
|
};
|
|
66
68
|
}
|
|
@@ -90,7 +92,7 @@ export class RettiwtConfig implements IRettiwtConfig {
|
|
|
90
92
|
|
|
91
93
|
public set headers(headers: { [key: string]: string } | undefined) {
|
|
92
94
|
this._headers = {
|
|
93
|
-
...
|
|
95
|
+
...DefaultHeaders,
|
|
94
96
|
...headers,
|
|
95
97
|
};
|
|
96
98
|
}
|
|
@@ -100,4 +102,4 @@ export class RettiwtConfig implements IRettiwtConfig {
|
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
export {
|
|
105
|
+
export { DefaultHeaders as DefaultRettiwtHeaders };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TweetRepliesSortType } from '../../enums/Tweet';
|
|
2
2
|
import { IFetchArgs, ITweetFilter } from '../../types/args/FetchArgs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -12,7 +12,7 @@ export class FetchArgs implements IFetchArgs {
|
|
|
12
12
|
public filter?: TweetFilter;
|
|
13
13
|
public id?: string;
|
|
14
14
|
public ids?: string[];
|
|
15
|
-
public sortBy?:
|
|
15
|
+
public sortBy?: TweetRepliesSortType;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @param args - Additional user-defined arguments for fetching the resource.
|
|
@@ -40,16 +40,18 @@ export class TweetFilter implements ITweetFilter {
|
|
|
40
40
|
public includePhrase?: string;
|
|
41
41
|
public includeWords?: string[];
|
|
42
42
|
public language?: string;
|
|
43
|
-
public links?: boolean;
|
|
44
43
|
public list?: string;
|
|
45
44
|
public maxId?: string;
|
|
46
45
|
public mentions?: string[];
|
|
47
46
|
public minLikes?: number;
|
|
48
47
|
public minReplies?: number;
|
|
49
48
|
public minRetweets?: number;
|
|
49
|
+
public onlyLinks?: boolean;
|
|
50
|
+
public onlyOriginal?: boolean;
|
|
51
|
+
public onlyReplies?: boolean;
|
|
52
|
+
public onlyText?: boolean;
|
|
50
53
|
public optionalWords?: string[];
|
|
51
54
|
public quoted?: string;
|
|
52
|
-
public replies?: boolean;
|
|
53
55
|
public sinceId?: string;
|
|
54
56
|
public startDate?: Date;
|
|
55
57
|
public toUsers?: string[];
|
|
@@ -65,9 +67,7 @@ export class TweetFilter implements ITweetFilter {
|
|
|
65
67
|
this.hashtags = filter.hashtags;
|
|
66
68
|
this.includePhrase = filter.includePhrase;
|
|
67
69
|
this.language = filter.language;
|
|
68
|
-
this.links = filter.links;
|
|
69
70
|
this.list = filter.list;
|
|
70
|
-
this.replies = filter.replies;
|
|
71
71
|
this.mentions = filter.mentions;
|
|
72
72
|
this.quoted = filter.quoted;
|
|
73
73
|
this.sinceId = filter.sinceId;
|
|
@@ -75,6 +75,10 @@ export class TweetFilter implements ITweetFilter {
|
|
|
75
75
|
this.minLikes = filter.minLikes;
|
|
76
76
|
this.minReplies = filter.minReplies;
|
|
77
77
|
this.minRetweets = filter.minRetweets;
|
|
78
|
+
this.onlyLinks = filter.onlyLinks;
|
|
79
|
+
this.onlyOriginal = filter.onlyOriginal;
|
|
80
|
+
this.onlyReplies = filter.onlyReplies;
|
|
81
|
+
this.onlyText = filter.onlyText;
|
|
78
82
|
this.optionalWords = filter.optionalWords;
|
|
79
83
|
this.startDate = filter.startDate;
|
|
80
84
|
this.toUsers = filter.toUsers;
|
|
@@ -89,7 +93,7 @@ export class TweetFilter implements ITweetFilter {
|
|
|
89
93
|
* @param date - The date object to convert.
|
|
90
94
|
* @returns The Twitter string representation of the date.
|
|
91
95
|
*/
|
|
92
|
-
private static
|
|
96
|
+
private static _dateToTwitterString(date: Date): string {
|
|
93
97
|
// Converting localized date to UTC date
|
|
94
98
|
const utc = new Date(
|
|
95
99
|
Date.UTC(
|
|
@@ -131,16 +135,18 @@ export class TweetFilter implements ITweetFilter {
|
|
|
131
135
|
this.minLikes ? `min_faves:${this.minLikes}` : '',
|
|
132
136
|
this.minRetweets ? `min_retweets:${this.minRetweets}` : '',
|
|
133
137
|
this.language ? `lang:${this.language}` : '',
|
|
134
|
-
this.startDate ? `since:${TweetFilter.
|
|
135
|
-
this.endDate ? `until:${TweetFilter.
|
|
138
|
+
this.startDate ? `since:${TweetFilter._dateToTwitterString(this.startDate)}` : '',
|
|
139
|
+
this.endDate ? `until:${TweetFilter._dateToTwitterString(this.endDate)}` : '',
|
|
136
140
|
this.sinceId ? `since_id:${this.sinceId}` : '',
|
|
137
141
|
this.maxId ? `max_id:${this.maxId}` : '',
|
|
138
142
|
this.quoted ? `quoted_tweet_id:${this.quoted}` : '',
|
|
139
143
|
]
|
|
140
144
|
.filter((item) => item !== '()' && item !== '')
|
|
141
145
|
.join(' ') +
|
|
142
|
-
(this.
|
|
143
|
-
(this.
|
|
146
|
+
(this.onlyText === true ? ' -filter:links' : '') +
|
|
147
|
+
(this.onlyOriginal === true ? ' -filter:replies' : '') +
|
|
148
|
+
(this.onlyLinks === true ? ' filter:links' : '') +
|
|
149
|
+
(this.onlyReplies === true ? ' filter:replies' : '')
|
|
144
150
|
);
|
|
145
151
|
}
|
|
146
152
|
}
|