rettiwt-api 4.2.0-alpha.2 → 4.2.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/.github/workflows/documentation.yml +1 -4
- package/.github/workflows/publish-alpha.yml +1 -4
- package/.github/workflows/publish.yml +1 -4
- package/.tool-versions +1 -1
- package/README.md +14 -8
- package/dist/collections/Extractors.d.ts +2 -1
- package/dist/collections/Extractors.js +3 -0
- package/dist/collections/Extractors.js.map +1 -1
- package/dist/collections/Groups.js +1 -0
- package/dist/collections/Groups.js.map +1 -1
- package/dist/collections/Requests.js +2 -1
- package/dist/collections/Requests.js.map +1 -1
- package/dist/commands/Tweet.js +2 -1
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/commands/User.js +62 -39
- package/dist/commands/User.js.map +1 -1
- package/dist/enums/Resource.d.ts +1 -0
- package/dist/enums/Resource.js +1 -0
- package/dist/enums/Resource.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/models/args/FetchArgs.d.ts +6 -0
- package/dist/models/args/FetchArgs.js +13 -0
- package/dist/models/args/FetchArgs.js.map +1 -1
- package/dist/models/data/Tweet.js +23 -8
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.js +1 -1
- package/dist/models/data/User.js.map +1 -1
- package/dist/services/public/AuthService.js +1 -1
- package/dist/services/public/AuthService.js.map +1 -1
- package/dist/services/public/UserService.d.ts +26 -0
- package/dist/services/public/UserService.js +44 -0
- package/dist/services/public/UserService.js.map +1 -1
- package/package.json +3 -4
- package/src/collections/Extractors.ts +4 -1
- package/src/collections/Groups.ts +1 -0
- package/src/collections/Requests.ts +2 -1
- package/src/commands/Tweet.ts +2 -2
- package/src/commands/User.ts +13 -0
- package/src/enums/Resource.ts +1 -0
- package/src/index.ts +1 -2
- package/src/models/args/FetchArgs.ts +17 -0
- package/src/models/data/Notification.ts +1 -1
- package/src/models/data/Tweet.ts +30 -10
- package/src/models/data/User.ts +1 -1
- package/src/services/public/AuthService.ts +3 -1
- package/src/services/public/UserService.ts +42 -1
- package/.yarnrc.yml +0 -1
|
@@ -56,6 +56,7 @@ export class FetchArgs {
|
|
|
56
56
|
EResourceType.LIST_TWEETS,
|
|
57
57
|
EResourceType.TWEET_RETWEETERS,
|
|
58
58
|
EResourceType.TWEET_SEARCH,
|
|
59
|
+
EResourceType.USER_BOOKMARKS,
|
|
59
60
|
EResourceType.USER_FOLLOWERS,
|
|
60
61
|
EResourceType.USER_FOLLOWING,
|
|
61
62
|
EResourceType.USER_HIGHLIGHTS,
|
|
@@ -73,6 +74,7 @@ export class FetchArgs {
|
|
|
73
74
|
EResourceType.LIST_TWEETS,
|
|
74
75
|
EResourceType.TWEET_RETWEETERS,
|
|
75
76
|
EResourceType.TWEET_SEARCH,
|
|
77
|
+
EResourceType.USER_BOOKMARKS,
|
|
76
78
|
EResourceType.USER_FOLLOWERS,
|
|
77
79
|
EResourceType.USER_FOLLOWING,
|
|
78
80
|
EResourceType.USER_HIGHLIGHTS,
|
|
@@ -89,6 +91,7 @@ export class FetchArgs {
|
|
|
89
91
|
EResourceType.LIST_MEMBERS,
|
|
90
92
|
EResourceType.LIST_TWEETS,
|
|
91
93
|
EResourceType.TWEET_RETWEETERS,
|
|
94
|
+
EResourceType.USER_BOOKMARKS,
|
|
92
95
|
EResourceType.USER_FOLLOWERS,
|
|
93
96
|
EResourceType.USER_FOLLOWING,
|
|
94
97
|
EResourceType.USER_HIGHLIGHTS,
|
|
@@ -126,6 +129,7 @@ export class FetchArgs {
|
|
|
126
129
|
EResourceType.LIST_TWEETS,
|
|
127
130
|
EResourceType.TWEET_RETWEETERS,
|
|
128
131
|
EResourceType.TWEET_SEARCH,
|
|
132
|
+
EResourceType.USER_BOOKMARKS,
|
|
129
133
|
EResourceType.USER_FEED_FOLLOWED,
|
|
130
134
|
EResourceType.USER_FEED_RECOMMENDED,
|
|
131
135
|
EResourceType.USER_FOLLOWING,
|
|
@@ -145,6 +149,7 @@ export class FetchArgs {
|
|
|
145
149
|
EResourceType.LIST_TWEETS,
|
|
146
150
|
EResourceType.TWEET_RETWEETERS,
|
|
147
151
|
EResourceType.TWEET_SEARCH,
|
|
152
|
+
EResourceType.USER_BOOKMARKS,
|
|
148
153
|
EResourceType.USER_FEED_FOLLOWED,
|
|
149
154
|
EResourceType.USER_FEED_RECOMMENDED,
|
|
150
155
|
EResourceType.USER_FOLLOWING,
|
|
@@ -173,6 +178,7 @@ export class FetchArgs {
|
|
|
173
178
|
EResourceType.TWEET_DETAILS,
|
|
174
179
|
EResourceType.TWEET_DETAILS_ALT,
|
|
175
180
|
EResourceType.TWEET_RETWEETERS,
|
|
181
|
+
EResourceType.USER_BOOKMARKS,
|
|
176
182
|
EResourceType.USER_DETAILS_BY_USERNAME,
|
|
177
183
|
EResourceType.USER_DETAILS_BY_ID,
|
|
178
184
|
EResourceType.USER_FEED_FOLLOWED,
|
|
@@ -201,6 +207,7 @@ export class FetchArgs {
|
|
|
201
207
|
*/
|
|
202
208
|
@IsEmpty({
|
|
203
209
|
groups: [
|
|
210
|
+
EResourceType.USER_BOOKMARKS,
|
|
204
211
|
EResourceType.USER_FEED_FOLLOWED,
|
|
205
212
|
EResourceType.USER_FEED_RECOMMENDED,
|
|
206
213
|
EResourceType.USER_NOTIFICATIONS,
|
|
@@ -281,6 +288,7 @@ export class FetchArgs {
|
|
|
281
288
|
EResourceType.TWEET_DETAILS,
|
|
282
289
|
EResourceType.TWEET_DETAILS_ALT,
|
|
283
290
|
EResourceType.TWEET_RETWEETERS,
|
|
291
|
+
EResourceType.USER_BOOKMARKS,
|
|
284
292
|
EResourceType.USER_DETAILS_BY_USERNAME,
|
|
285
293
|
EResourceType.USER_DETAILS_BY_ID,
|
|
286
294
|
EResourceType.USER_FEED_FOLLOWED,
|
|
@@ -461,6 +469,15 @@ export class TweetFilter extends TweetFilterCore {
|
|
|
461
469
|
@IsString({ each: true })
|
|
462
470
|
public toUsers?: string[];
|
|
463
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Whether to fetch top or not.
|
|
474
|
+
*
|
|
475
|
+
* @defaultValue true
|
|
476
|
+
*/
|
|
477
|
+
@IsOptional()
|
|
478
|
+
@IsBoolean()
|
|
479
|
+
public top?: boolean;
|
|
480
|
+
|
|
464
481
|
/**
|
|
465
482
|
* @param filter - The filter to use for searching tweets.
|
|
466
483
|
*/
|
package/src/models/data/Tweet.ts
CHANGED
|
@@ -102,13 +102,13 @@ export class Tweet {
|
|
|
102
102
|
// If tweet with limited visibility
|
|
103
103
|
if (
|
|
104
104
|
tweet.quoted_status_result &&
|
|
105
|
-
|
|
106
|
-
tweet.quoted_status_result.result
|
|
105
|
+
tweet.quoted_status_result?.result?.__typename == 'TweetWithVisibilityResults' &&
|
|
106
|
+
(tweet.quoted_status_result.result as ILimitedVisibilityTweet)?.tweet?.legacy
|
|
107
107
|
) {
|
|
108
108
|
return new Tweet((tweet.quoted_status_result.result as ILimitedVisibilityTweet).tweet);
|
|
109
109
|
}
|
|
110
110
|
// If normal tweet
|
|
111
|
-
else if (tweet.quoted_status_result
|
|
111
|
+
else if ((tweet.quoted_status_result?.result as ITweet)?.rest_id) {
|
|
112
112
|
return new Tweet(tweet.quoted_status_result.result as ITweet);
|
|
113
113
|
}
|
|
114
114
|
// Else, skip
|
|
@@ -125,9 +125,17 @@ export class Tweet {
|
|
|
125
125
|
* @returns - The deserialized original retweeted tweet.
|
|
126
126
|
*/
|
|
127
127
|
private getRetweetedTweet(tweet: IRawTweet): Tweet | undefined {
|
|
128
|
-
// If
|
|
129
|
-
if (
|
|
130
|
-
|
|
128
|
+
// If retweet with limited visibility
|
|
129
|
+
if (
|
|
130
|
+
tweet.legacy?.retweeted_status_result &&
|
|
131
|
+
tweet.legacy?.retweeted_status_result?.result?.__typename == 'TweetWithVisibilityResults' &&
|
|
132
|
+
(tweet.legacy?.retweeted_status_result?.result as ILimitedVisibilityTweet)?.tweet?.legacy
|
|
133
|
+
) {
|
|
134
|
+
return new Tweet((tweet.legacy.retweeted_status_result.result as ILimitedVisibilityTweet).tweet);
|
|
135
|
+
}
|
|
136
|
+
// If normal tweet
|
|
137
|
+
else if ((tweet.legacy?.retweeted_status_result?.result as ITweet)?.rest_id) {
|
|
138
|
+
return new Tweet(tweet.legacy.retweeted_status_result.result as ITweet);
|
|
131
139
|
}
|
|
132
140
|
// Else, skip
|
|
133
141
|
else {
|
|
@@ -152,11 +160,23 @@ export class Tweet {
|
|
|
152
160
|
|
|
153
161
|
// Deserializing valid data
|
|
154
162
|
for (const item of extract) {
|
|
155
|
-
|
|
163
|
+
// If tweet with limited visibility
|
|
164
|
+
if (
|
|
165
|
+
item.tweet_results?.result &&
|
|
166
|
+
item.tweet_results?.result?.__typename == 'TweetWithVisibilityResults' &&
|
|
167
|
+
(item.tweet_results?.result as ILimitedVisibilityTweet)?.tweet?.legacy
|
|
168
|
+
) {
|
|
169
|
+
tweets.push(new Tweet((item.tweet_results.result as ILimitedVisibilityTweet).tweet));
|
|
170
|
+
}
|
|
171
|
+
// If normal tweet
|
|
172
|
+
else if ((item.tweet_results?.result as ITweet)?.legacy) {
|
|
156
173
|
// Logging
|
|
157
|
-
LogService.log(ELogActions.DESERIALIZE, { id: item.tweet_results.result.rest_id });
|
|
158
|
-
|
|
159
|
-
|
|
174
|
+
LogService.log(ELogActions.DESERIALIZE, { id: (item.tweet_results.result as ITweet).rest_id });
|
|
175
|
+
|
|
176
|
+
tweets.push(new Tweet(item.tweet_results.result as ITweet));
|
|
177
|
+
}
|
|
178
|
+
// If invalid/unrecognized tweet
|
|
179
|
+
else {
|
|
160
180
|
// Logging
|
|
161
181
|
LogService.log(ELogActions.WARNING, {
|
|
162
182
|
action: ELogActions.DESERIALIZE,
|
package/src/models/data/User.ts
CHANGED
|
@@ -57,7 +57,9 @@ export class AuthService extends FetcherService {
|
|
|
57
57
|
const cookieString: string = AuthService.decodeCookie(apiKey);
|
|
58
58
|
|
|
59
59
|
// Searching for the user id in the cookie string
|
|
60
|
-
const searchResults: string[] | null = cookieString.match(
|
|
60
|
+
const searchResults: string[] | null = cookieString.match(
|
|
61
|
+
/((?<=twid="u=)(\d+)(?="))|((?<=twid=u%3D)(\d+)(?=;))/,
|
|
62
|
+
);
|
|
61
63
|
|
|
62
64
|
// If user id was found
|
|
63
65
|
if (searchResults) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
IUserBookmarksResponse,
|
|
2
3
|
IUserDetailsResponse,
|
|
3
4
|
IUserFollowedResponse,
|
|
4
5
|
IUserFollowersResponse,
|
|
@@ -7,7 +8,7 @@ import {
|
|
|
7
8
|
IUserHighlightsResponse,
|
|
8
9
|
IUserLikesResponse,
|
|
9
10
|
IUserMediaResponse,
|
|
10
|
-
|
|
11
|
+
IUserNotificationsResponse,
|
|
11
12
|
IUserRecommendedResponse,
|
|
12
13
|
IUserSubscriptionsResponse,
|
|
13
14
|
IUserTweetsAndRepliesResponse,
|
|
@@ -40,6 +41,46 @@ export class UserService extends FetcherService {
|
|
|
40
41
|
super(config);
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Get the list of bookmarks of the logged in user.
|
|
46
|
+
*
|
|
47
|
+
* @param count - The number of bookmakrs to fetch, must be \<= 100.
|
|
48
|
+
* @param cursor - The cursor to the batch of bookmarks to fetch.
|
|
49
|
+
*
|
|
50
|
+
* @returns The list of tweets bookmarked by the target user.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```
|
|
54
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
55
|
+
*
|
|
56
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
57
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
58
|
+
*
|
|
59
|
+
* // Fetching the most recent 100 liked Tweets of the logged in User
|
|
60
|
+
* rettiwt.user.bookmarks()
|
|
61
|
+
* .then(res => {
|
|
62
|
+
* console.log(res);
|
|
63
|
+
* })
|
|
64
|
+
* .catch(err => {
|
|
65
|
+
* console.log(err);
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
public async bookmarks(count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
70
|
+
const resource = EResourceType.USER_BOOKMARKS;
|
|
71
|
+
|
|
72
|
+
// Fetching raw list of likes
|
|
73
|
+
const response = await this.request<IUserBookmarksResponse>(resource, {
|
|
74
|
+
count: count,
|
|
75
|
+
cursor: cursor,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Deserializing response
|
|
79
|
+
const data = extractors[resource](response);
|
|
80
|
+
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
|
|
43
84
|
/**
|
|
44
85
|
* Get the details of a user.
|
|
45
86
|
*
|
package/.yarnrc.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
nodeLinker: node-modules
|