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.
Files changed (49) hide show
  1. package/.github/workflows/documentation.yml +1 -4
  2. package/.github/workflows/publish-alpha.yml +1 -4
  3. package/.github/workflows/publish.yml +1 -4
  4. package/.tool-versions +1 -1
  5. package/README.md +14 -8
  6. package/dist/collections/Extractors.d.ts +2 -1
  7. package/dist/collections/Extractors.js +3 -0
  8. package/dist/collections/Extractors.js.map +1 -1
  9. package/dist/collections/Groups.js +1 -0
  10. package/dist/collections/Groups.js.map +1 -1
  11. package/dist/collections/Requests.js +2 -1
  12. package/dist/collections/Requests.js.map +1 -1
  13. package/dist/commands/Tweet.js +2 -1
  14. package/dist/commands/Tweet.js.map +1 -1
  15. package/dist/commands/User.js +62 -39
  16. package/dist/commands/User.js.map +1 -1
  17. package/dist/enums/Resource.d.ts +1 -0
  18. package/dist/enums/Resource.js +1 -0
  19. package/dist/enums/Resource.js.map +1 -1
  20. package/dist/index.d.ts +1 -2
  21. package/dist/index.js +0 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/models/args/FetchArgs.d.ts +6 -0
  24. package/dist/models/args/FetchArgs.js +13 -0
  25. package/dist/models/args/FetchArgs.js.map +1 -1
  26. package/dist/models/data/Tweet.js +23 -8
  27. package/dist/models/data/Tweet.js.map +1 -1
  28. package/dist/models/data/User.js +1 -1
  29. package/dist/models/data/User.js.map +1 -1
  30. package/dist/services/public/AuthService.js +1 -1
  31. package/dist/services/public/AuthService.js.map +1 -1
  32. package/dist/services/public/UserService.d.ts +26 -0
  33. package/dist/services/public/UserService.js +44 -0
  34. package/dist/services/public/UserService.js.map +1 -1
  35. package/package.json +3 -4
  36. package/src/collections/Extractors.ts +4 -1
  37. package/src/collections/Groups.ts +1 -0
  38. package/src/collections/Requests.ts +2 -1
  39. package/src/commands/Tweet.ts +2 -2
  40. package/src/commands/User.ts +13 -0
  41. package/src/enums/Resource.ts +1 -0
  42. package/src/index.ts +1 -2
  43. package/src/models/args/FetchArgs.ts +17 -0
  44. package/src/models/data/Notification.ts +1 -1
  45. package/src/models/data/Tweet.ts +30 -10
  46. package/src/models/data/User.ts +1 -1
  47. package/src/services/public/AuthService.ts +3 -1
  48. package/src/services/public/UserService.ts +42 -1
  49. 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
  */
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ENotificationType as ENotificationTypeOriginal,
3
3
  INotification,
4
- IUserNotifications as IUserNotificationsResponse,
4
+ IUserNotificationsResponse,
5
5
  } from 'rettiwt-core';
6
6
 
7
7
  import { findKeyByValue } from '../../helper/JsonUtils';
@@ -102,13 +102,13 @@ export class Tweet {
102
102
  // If tweet with limited visibility
103
103
  if (
104
104
  tweet.quoted_status_result &&
105
- Object.entries(tweet.quoted_status_result).length &&
106
- tweet.quoted_status_result.result.__typename == 'TweetWithVisibilityResults'
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 && Object.entries(tweet.quoted_status_result).length) {
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 valid retweeted tweet
129
- if (tweet.legacy.retweeted_status_result?.result?.rest_id) {
130
- return new Tweet(tweet.legacy.retweeted_status_result.result);
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
- if (item.tweet_results?.result?.legacy) {
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
- tweets.push(new Tweet(item.tweet_results.result));
159
- } else {
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,
@@ -123,7 +123,7 @@ export class User {
123
123
 
124
124
  // Deserializing valid data
125
125
  for (const item of extract) {
126
- if (item.legacy) {
126
+ if (item.legacy && item.legacy.created_at) {
127
127
  // Logging
128
128
  LogService.log(ELogActions.DESERIALIZE, { id: item.rest_id });
129
129
 
@@ -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(/((?<=twid="u=)(.*)(?="))|((?<=twid=u%3D)(.*)(?=;))/);
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
- IUserNotifications as IUserNotificationsResponse,
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