rettiwt-api 6.0.8 → 6.1.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 (219) hide show
  1. package/.github/ISSUE_TEMPLATE/bug-report.yml +57 -0
  2. package/.github/ISSUE_TEMPLATE/feature-request.yml +20 -0
  3. package/.github/ISSUE_TEMPLATE/question.yml +15 -0
  4. package/.github/PULL_REQUEST_TEMPLATE.md +32 -0
  5. package/.github/workflows/ci.yml +33 -0
  6. package/.nvmrc +1 -0
  7. package/README.md +30 -6
  8. package/dist/Rettiwt.d.ts +3 -0
  9. package/dist/Rettiwt.js +4 -0
  10. package/dist/Rettiwt.js.map +1 -1
  11. package/dist/cli.js +2 -0
  12. package/dist/cli.js.map +1 -1
  13. package/dist/collections/Extractors.d.ts +24 -0
  14. package/dist/collections/Extractors.js +14 -0
  15. package/dist/collections/Extractors.js.map +1 -1
  16. package/dist/collections/Groups.js +11 -0
  17. package/dist/collections/Groups.js.map +1 -1
  18. package/dist/collections/Requests.js +12 -0
  19. package/dist/collections/Requests.js.map +1 -1
  20. package/dist/commands/DirectMessage.d.ts +10 -0
  21. package/dist/commands/DirectMessage.js +57 -0
  22. package/dist/commands/DirectMessage.js.map +1 -0
  23. package/dist/commands/List.js +44 -3
  24. package/dist/commands/List.js.map +1 -1
  25. package/dist/commands/Tweet.js +29 -1
  26. package/dist/commands/Tweet.js.map +1 -1
  27. package/dist/commands/User.js +39 -1
  28. package/dist/commands/User.js.map +1 -1
  29. package/dist/enums/Data.d.ts +3 -1
  30. package/dist/enums/Data.js +2 -0
  31. package/dist/enums/Data.js.map +1 -1
  32. package/dist/enums/Resource.d.ts +11 -0
  33. package/dist/enums/Resource.js +12 -0
  34. package/dist/enums/Resource.js.map +1 -1
  35. package/dist/enums/raw/Analytics.d.ts +6 -3
  36. package/dist/enums/raw/Analytics.js +5 -2
  37. package/dist/enums/raw/Analytics.js.map +1 -1
  38. package/dist/index.d.ts +15 -0
  39. package/dist/index.js +8 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/models/args/FetchArgs.d.ts +9 -0
  42. package/dist/models/args/FetchArgs.js +16 -0
  43. package/dist/models/args/FetchArgs.js.map +1 -1
  44. package/dist/models/args/PostArgs.d.ts +1 -0
  45. package/dist/models/args/PostArgs.js +2 -0
  46. package/dist/models/args/PostArgs.js.map +1 -1
  47. package/dist/models/data/Analytics.d.ts +43 -0
  48. package/dist/models/data/Analytics.js +92 -0
  49. package/dist/models/data/Analytics.js.map +1 -0
  50. package/dist/models/data/Conversation.d.ts +93 -0
  51. package/dist/models/data/Conversation.js +293 -0
  52. package/dist/models/data/Conversation.js.map +1 -0
  53. package/dist/models/data/CursoredData.d.ts +2 -1
  54. package/dist/models/data/CursoredData.js +6 -1
  55. package/dist/models/data/CursoredData.js.map +1 -1
  56. package/dist/models/data/DirectMessage.d.ts +105 -0
  57. package/dist/models/data/DirectMessage.js +284 -0
  58. package/dist/models/data/DirectMessage.js.map +1 -0
  59. package/dist/models/data/Inbox.d.ts +44 -0
  60. package/dist/models/data/Inbox.js +106 -0
  61. package/dist/models/data/Inbox.js.map +1 -0
  62. package/dist/models/data/List.d.ts +20 -0
  63. package/dist/models/data/List.js +50 -1
  64. package/dist/models/data/List.js.map +1 -1
  65. package/dist/models/data/Tweet.d.ts +6 -6
  66. package/dist/models/data/Tweet.js +4 -2
  67. package/dist/models/data/Tweet.js.map +1 -1
  68. package/dist/models/data/User.d.ts +2 -0
  69. package/dist/models/data/User.js +6 -0
  70. package/dist/models/data/User.js.map +1 -1
  71. package/dist/requests/DirectMessage.d.ts +28 -0
  72. package/dist/requests/DirectMessage.js +149 -0
  73. package/dist/requests/DirectMessage.js.map +1 -0
  74. package/dist/requests/List.d.ts +10 -0
  75. package/dist/requests/List.js +52 -0
  76. package/dist/requests/List.js.map +1 -1
  77. package/dist/requests/Tweet.d.ts +8 -0
  78. package/dist/requests/Tweet.js +30 -0
  79. package/dist/requests/Tweet.js.map +1 -1
  80. package/dist/requests/User.d.ts +8 -1
  81. package/dist/requests/User.js +67 -8
  82. package/dist/requests/User.js.map +1 -1
  83. package/dist/services/public/DirectMessageService.d.ts +100 -0
  84. package/dist/services/public/DirectMessageService.js +143 -0
  85. package/dist/services/public/DirectMessageService.js.map +1 -0
  86. package/dist/services/public/FetcherService.d.ts +2 -2
  87. package/dist/services/public/FetcherService.js +2 -2
  88. package/dist/services/public/ListService.d.ts +85 -0
  89. package/dist/services/public/ListService.js +111 -0
  90. package/dist/services/public/ListService.js.map +1 -1
  91. package/dist/services/public/TweetService.d.ts +56 -0
  92. package/dist/services/public/TweetService.js +72 -0
  93. package/dist/services/public/TweetService.js.map +1 -1
  94. package/dist/services/public/UserService.d.ts +61 -2
  95. package/dist/services/public/UserService.js +89 -0
  96. package/dist/services/public/UserService.js.map +1 -1
  97. package/dist/types/args/FetchArgs.d.ts +69 -12
  98. package/dist/types/args/PostArgs.d.ts +29 -11
  99. package/dist/types/data/Analytics.d.ts +42 -0
  100. package/dist/types/data/Analytics.js +3 -0
  101. package/dist/types/data/Analytics.js.map +1 -0
  102. package/dist/types/data/Conversation.d.ts +32 -0
  103. package/dist/types/data/Conversation.js +3 -0
  104. package/dist/types/data/Conversation.js.map +1 -0
  105. package/dist/types/data/CursoredData.d.ts +4 -1
  106. package/dist/types/data/DirectMessage.d.ts +25 -0
  107. package/dist/types/data/DirectMessage.js +3 -0
  108. package/dist/types/data/DirectMessage.js.map +1 -0
  109. package/dist/types/data/Inbox.d.ts +18 -0
  110. package/dist/types/data/Inbox.js +3 -0
  111. package/dist/types/data/Inbox.js.map +1 -0
  112. package/dist/types/data/List.d.ts +5 -1
  113. package/dist/types/data/Tweet.d.ts +6 -6
  114. package/dist/types/data/User.d.ts +4 -0
  115. package/dist/types/raw/base/Analytic.d.ts +6 -1
  116. package/dist/types/raw/base/Message.d.ts +16 -0
  117. package/dist/types/raw/base/Message.js +4 -0
  118. package/dist/types/raw/base/Message.js.map +1 -0
  119. package/dist/types/raw/base/Tweet.d.ts +6 -6
  120. package/dist/types/raw/base/User.d.ts +2 -1
  121. package/dist/types/raw/composite/TimelineList.d.ts +9 -0
  122. package/dist/types/raw/composite/TimelineList.js +3 -0
  123. package/dist/types/raw/composite/TimelineList.js.map +1 -0
  124. package/dist/types/raw/dm/Conversation.d.ts +55 -0
  125. package/dist/types/raw/dm/Conversation.js +4 -0
  126. package/dist/types/raw/dm/Conversation.js.map +1 -0
  127. package/dist/types/raw/dm/InboxInitial.d.ts +137 -0
  128. package/dist/types/raw/dm/InboxInitial.js +4 -0
  129. package/dist/types/raw/dm/InboxInitial.js.map +1 -0
  130. package/dist/types/raw/dm/InboxTimeline.d.ts +287 -0
  131. package/dist/types/raw/dm/InboxTimeline.js +4 -0
  132. package/dist/types/raw/dm/InboxTimeline.js.map +1 -0
  133. package/dist/types/raw/dm/UserUpdates.d.ts +41 -0
  134. package/dist/types/raw/dm/UserUpdates.js +4 -0
  135. package/dist/types/raw/dm/UserUpdates.js.map +1 -0
  136. package/dist/types/raw/list/AddMember.d.ts +151 -0
  137. package/dist/types/raw/list/AddMember.js +4 -0
  138. package/dist/types/raw/list/AddMember.js.map +1 -0
  139. package/dist/types/raw/list/Details.d.ts +44 -13
  140. package/dist/types/raw/list/RemoveMember.d.ts +150 -0
  141. package/dist/types/raw/list/RemoveMember.js +4 -0
  142. package/dist/types/raw/list/RemoveMember.js.map +1 -0
  143. package/dist/types/raw/tweet/Bookmark.d.ts +12 -0
  144. package/dist/types/raw/tweet/Bookmark.js +4 -0
  145. package/dist/types/raw/tweet/Bookmark.js.map +1 -0
  146. package/dist/types/raw/tweet/Unbookmark.d.ts +11 -0
  147. package/dist/types/raw/tweet/Unbookmark.js +4 -0
  148. package/dist/types/raw/tweet/Unbookmark.js.map +1 -0
  149. package/dist/types/raw/user/Analytics.d.ts +6 -18
  150. package/dist/types/raw/user/Analytics.js +0 -1
  151. package/dist/types/raw/user/Analytics.js.map +1 -1
  152. package/dist/types/raw/user/Lists.d.ts +319 -0
  153. package/dist/types/raw/user/Lists.js +4 -0
  154. package/dist/types/raw/user/Lists.js.map +1 -0
  155. package/eslint.config.mjs +1 -1
  156. package/package.json +11 -6
  157. package/playground/.env.example +1 -0
  158. package/playground/README.md +53 -0
  159. package/playground/index.js +15 -0
  160. package/playground/package.json +15 -0
  161. package/src/Rettiwt.ts +5 -0
  162. package/src/cli.ts +2 -0
  163. package/src/collections/Extractors.ts +29 -0
  164. package/src/collections/Groups.ts +11 -0
  165. package/src/collections/Requests.ts +20 -0
  166. package/src/commands/DirectMessage.ts +62 -0
  167. package/src/commands/List.ts +44 -3
  168. package/src/commands/Tweet.ts +29 -1
  169. package/src/commands/User.ts +65 -1
  170. package/src/enums/Data.ts +2 -0
  171. package/src/enums/Resource.ts +13 -0
  172. package/src/enums/raw/Analytics.ts +5 -2
  173. package/src/index.ts +15 -0
  174. package/src/models/args/FetchArgs.ts +17 -0
  175. package/src/models/args/PostArgs.ts +2 -0
  176. package/src/models/data/Analytics.ts +97 -0
  177. package/src/models/data/Conversation.ts +344 -0
  178. package/src/models/data/CursoredData.ts +7 -2
  179. package/src/models/data/DirectMessage.ts +335 -0
  180. package/src/models/data/Inbox.ts +124 -0
  181. package/src/models/data/List.ts +60 -1
  182. package/src/models/data/Tweet.ts +10 -8
  183. package/src/models/data/User.ts +6 -0
  184. package/src/requests/DirectMessage.ts +233 -0
  185. package/src/requests/List.ts +58 -0
  186. package/src/requests/Tweet.ts +32 -0
  187. package/src/requests/User.ts +70 -7
  188. package/src/services/public/DirectMessageService.ts +159 -0
  189. package/src/services/public/FetcherService.ts +2 -2
  190. package/src/services/public/ListService.ts +127 -0
  191. package/src/services/public/TweetService.ts +82 -0
  192. package/src/services/public/UserService.ts +110 -2
  193. package/src/types/args/FetchArgs.ts +77 -12
  194. package/src/types/args/PostArgs.ts +31 -11
  195. package/src/types/data/Analytics.ts +58 -0
  196. package/src/types/data/Conversation.ts +44 -0
  197. package/src/types/data/CursoredData.ts +4 -1
  198. package/src/types/data/DirectMessage.ts +33 -0
  199. package/src/types/data/Inbox.ts +23 -0
  200. package/src/types/data/List.ts +7 -1
  201. package/src/types/data/Tweet.ts +6 -6
  202. package/src/types/data/User.ts +6 -0
  203. package/src/types/raw/base/Analytic.ts +7 -1
  204. package/src/types/raw/base/Message.ts +22 -0
  205. package/src/types/raw/base/Tweet.ts +6 -6
  206. package/src/types/raw/base/User.ts +2 -1
  207. package/src/types/raw/composite/TimelineList.ts +10 -0
  208. package/src/types/raw/dm/Conversation.ts +59 -0
  209. package/src/types/raw/dm/InboxInitial.ts +155 -0
  210. package/src/types/raw/dm/InboxTimeline.ts +301 -0
  211. package/src/types/raw/dm/UserUpdates.ts +46 -0
  212. package/src/types/raw/list/AddMember.ts +175 -0
  213. package/src/types/raw/list/Details.ts +52 -13
  214. package/src/types/raw/list/RemoveMember.ts +174 -0
  215. package/src/types/raw/tweet/Bookmark.ts +14 -0
  216. package/src/types/raw/tweet/Unbookmark.ts +14 -0
  217. package/src/types/raw/user/Analytics.ts +6 -22
  218. package/src/types/raw/user/Lists.ts +378 -0
  219. package/tsconfig.json +1 -1
@@ -1,10 +1,14 @@
1
1
  import { Extractors } from '../../collections/Extractors';
2
2
  import { ResourceType } from '../../enums/Resource';
3
3
  import { CursoredData } from '../../models/data/CursoredData';
4
+ import { List } from '../../models/data/List';
4
5
  import { Tweet } from '../../models/data/Tweet';
5
6
  import { User } from '../../models/data/User';
6
7
  import { RettiwtConfig } from '../../models/RettiwtConfig';
8
+ import { IListMemberAddResponse } from '../../types/raw/list/AddMember';
9
+ import { IListDetailsResponse } from '../../types/raw/list/Details';
7
10
  import { IListMembersResponse } from '../../types/raw/list/Members';
11
+ import { IListMemberRemoveResponse } from '../../types/raw/list/RemoveMember';
8
12
  import { IListTweetsResponse } from '../../types/raw/list/Tweets';
9
13
 
10
14
  import { FetcherService } from './FetcherService';
@@ -19,6 +23,88 @@ export class ListService extends FetcherService {
19
23
  super(config);
20
24
  }
21
25
 
26
+ /**
27
+ * Add a user as a member of a list.
28
+ *
29
+ * @param listId - The ID of the target list.
30
+ * @param userId - The ID of the target user to be added as a member.
31
+ *
32
+ * @returns The new member count of the list. If adding was unsuccessful, return `undefined`.
33
+ *
34
+ * @example
35
+ *
36
+ * ```ts
37
+ * import { Rettiwt } from 'rettiwt-api';
38
+ *
39
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
40
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
41
+ *
42
+ * // Adding a user with ID '123456789' as a member to the list with ID '987654321'
43
+ * rettiwt.list.addMember('987654321', '123456789')
44
+ * .then(res => {
45
+ * console.log(res);
46
+ * })
47
+ * .catch(err => {
48
+ * console.log(err);
49
+ * });
50
+ * ```
51
+ */
52
+ public async addMember(listId: string, userId: string): Promise<number | undefined> {
53
+ const resource: ResourceType = ResourceType.LIST_MEMBER_ADD;
54
+
55
+ // Adding the user as a member
56
+ const response = await this.request<IListMemberAddResponse>(resource, {
57
+ id: listId,
58
+ userId: userId,
59
+ });
60
+
61
+ // Deserializing response
62
+ const data = Extractors[resource](response);
63
+
64
+ return data;
65
+ }
66
+
67
+ /**
68
+ * Get the details of a list.
69
+ *
70
+ * @param id - The ID of the target list.
71
+ *
72
+ * @returns
73
+ * The details of the target list.
74
+ *
75
+ * If list not found, returns undefined.
76
+ *
77
+ * @example
78
+ *
79
+ * #### Fetching the details of a list
80
+ * ```ts
81
+ * import { Rettiwt } from 'rettiwt-api';
82
+ *
83
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
84
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
85
+ *
86
+ * // Fetching the details of the list with the id '1234567890'
87
+ * rettiwt.list.details('1234567890')
88
+ * .then(res => {
89
+ * console.log(res);
90
+ * })
91
+ * .catch(err => {
92
+ * console.log(err);
93
+ * });
94
+ * ```
95
+ */
96
+ public async details(id: string): Promise<List | undefined> {
97
+ const resource: ResourceType = ResourceType.LIST_DETAILS;
98
+
99
+ // Getting the details of the list
100
+ const response = await this.request<IListDetailsResponse>(resource, { id: id });
101
+
102
+ // Deserializing response
103
+ const data = Extractors[resource](response, id);
104
+
105
+ return data;
106
+ }
107
+
22
108
  /**
23
109
  * Get the list of members of a tweet list.
24
110
  *
@@ -64,6 +150,47 @@ export class ListService extends FetcherService {
64
150
  return data;
65
151
  }
66
152
 
153
+ /**
154
+ * Remove a member from a list.
155
+ *
156
+ * @param listId - The ID of the target list.
157
+ * @param userId - The ID of the target user to removed from the members.
158
+ *
159
+ * @returns The new member count of the list. If removal was unsuccessful, return `undefined`.
160
+ *
161
+ * @example
162
+ *
163
+ * ```ts
164
+ * import { Rettiwt } from 'rettiwt-api';
165
+ *
166
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
167
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
168
+ *
169
+ * // Removing a user with ID '123456789' from the member of the list with ID '987654321'
170
+ * rettiwt.list.removeMember('987654321', '123456789')
171
+ * .then(res => {
172
+ * console.log(res);
173
+ * })
174
+ * .catch(err => {
175
+ * console.log(err);
176
+ * });
177
+ * ```
178
+ */
179
+ public async removeMember(listId: string, userId: string): Promise<number | undefined> {
180
+ const resource: ResourceType = ResourceType.LIST_MEMBER_REMOVE;
181
+
182
+ // Removing the member
183
+ const response = await this.request<IListMemberRemoveResponse>(resource, {
184
+ id: listId,
185
+ userId: userId,
186
+ });
187
+
188
+ // Deserializing response
189
+ const data = Extractors[resource](response);
190
+
191
+ return data;
192
+ }
193
+
67
194
  /**
68
195
  * Get the list of tweets from a tweet list.
69
196
  *
@@ -12,6 +12,7 @@ import { ITweetFilter } from '../../types/args/FetchArgs';
12
12
  import { INewTweet } from '../../types/args/PostArgs';
13
13
  import { IMediaInitializeUploadResponse } from '../../types/raw/media/InitalizeUpload';
14
14
 
15
+ import { ITweetBookmarkResponse } from '../../types/raw/tweet/Bookmark';
15
16
  import { ITweetDetailsResponse } from '../../types/raw/tweet/Details';
16
17
  import { ITweetDetailsBulkResponse } from '../../types/raw/tweet/DetailsBulk';
17
18
  import { ITweetLikeResponse } from '../../types/raw/tweet/Like';
@@ -22,6 +23,7 @@ import { ITweetRetweetResponse } from '../../types/raw/tweet/Retweet';
22
23
  import { ITweetRetweetersResponse } from '../../types/raw/tweet/Retweeters';
23
24
  import { ITweetScheduleResponse } from '../../types/raw/tweet/Schedule';
24
25
  import { ITweetSearchResponse } from '../../types/raw/tweet/Search';
26
+ import { ITweetUnbookmarkResponse } from '../../types/raw/tweet/Unbookmark';
25
27
  import { ITweetUnlikeResponse } from '../../types/raw/tweet/Unlike';
26
28
  import { ITweetUnpostResponse } from '../../types/raw/tweet/Unpost';
27
29
  import { ITweetUnretweetResponse } from '../../types/raw/tweet/Unretweet';
@@ -44,6 +46,45 @@ export class TweetService extends FetcherService {
44
46
  super(config);
45
47
  }
46
48
 
49
+ /**
50
+ * Bookmark a tweet.
51
+ *
52
+ * @param id - The ID of the tweet to be bookmarked.
53
+ *
54
+ * @returns Whether bookmarking was successful or not.
55
+ *
56
+ * @example
57
+ *
58
+ * ```ts
59
+ * import { Rettiwt } from 'rettiwt-api';
60
+ *
61
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
62
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
63
+ *
64
+ * // Bookmarking the Tweet with id '1234567890'
65
+ * rettiwt.tweet.bookmark('1234567890')
66
+ * .then(res => {
67
+ * console.log(res);
68
+ * })
69
+ * .catch(err => {
70
+ * console.log(err);
71
+ * });
72
+ * ```
73
+ */
74
+ public async bookmark(id: string): Promise<boolean> {
75
+ const resource = ResourceType.TWEET_BOOKMARK;
76
+
77
+ // Favoriting the tweet
78
+ const response = await this.request<ITweetBookmarkResponse>(resource, {
79
+ id: id,
80
+ });
81
+
82
+ // Deserializing response
83
+ const data = Extractors[resource](response) ?? false;
84
+
85
+ return data;
86
+ }
87
+
47
88
  /**
48
89
  * Get the details of one or more tweets.
49
90
  *
@@ -315,6 +356,10 @@ export class TweetService extends FetcherService {
315
356
  /**
316
357
  * Get the list of replies to a tweet.
317
358
  *
359
+ * If the target tweet is a thread,
360
+ * the first batch always contains all the tweets in the thread,
361
+ * if `sortBy` is set to {@link TweetRepliesSortType.RELEVANCE}.
362
+ *
318
363
  * @param id - The ID of the target tweet.
319
364
  * @param cursor - The cursor to the batch of replies to fetch.
320
365
  * @param sortBy - The sorting order of the replies to fetch. Default is {@link TweetRepliesSortType.RECENT}.
@@ -605,6 +650,43 @@ export class TweetService extends FetcherService {
605
650
  }
606
651
  }
607
652
 
653
+ /**
654
+ * Unbookmark a tweet.
655
+ *
656
+ * @param id - The ID of the target tweet.
657
+ *
658
+ * @returns Whether unbookmarking was successful or not.
659
+ *
660
+ * @example
661
+ *
662
+ * ```ts
663
+ * import { Rettiwt } from 'rettiwt-api';
664
+ *
665
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
666
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
667
+ *
668
+ * // Unbookmarking the tweet with id '1234567890'
669
+ * rettiwt.tweet.unbookmark('1234567890')
670
+ * .then(res => {
671
+ * console.log(res);
672
+ * })
673
+ * .catch(err => {
674
+ * console.log(err);
675
+ * });
676
+ * ```
677
+ */
678
+ public async unbookmark(id: string): Promise<boolean> {
679
+ const resource = ResourceType.TWEET_UNBOOKMARK;
680
+
681
+ // Unliking the tweet
682
+ const response = await this.request<ITweetUnbookmarkResponse>(resource, { id: id });
683
+
684
+ // Deserializing the response
685
+ const data = Extractors[resource](response) ?? false;
686
+
687
+ return data;
688
+ }
689
+
608
690
  /**
609
691
  * Unlike a tweet.
610
692
  *
@@ -1,11 +1,15 @@
1
1
  import { Extractors } from '../../collections/Extractors';
2
+ import { RawAnalyticsGranularity, RawAnalyticsMetric } from '../../enums/raw/Analytics';
2
3
  import { ResourceType } from '../../enums/Resource';
4
+ import { Analytics } from '../../models/data/Analytics';
3
5
  import { CursoredData } from '../../models/data/CursoredData';
6
+ import { List } from '../../models/data/List';
4
7
  import { Notification } from '../../models/data/Notification';
5
8
  import { Tweet } from '../../models/data/Tweet';
6
9
  import { User } from '../../models/data/User';
7
10
  import { RettiwtConfig } from '../../models/RettiwtConfig';
8
11
  import { IUserAffiliatesResponse } from '../../types/raw/user/Affiliates';
12
+ import { IUserAnalyticsResponse } from '../../types/raw/user/Analytics';
9
13
  import { IUserBookmarksResponse } from '../../types/raw/user/Bookmarks';
10
14
  import { IUserDetailsResponse } from '../../types/raw/user/Details';
11
15
  import { IUserDetailsBulkResponse } from '../../types/raw/user/DetailsBulk';
@@ -15,6 +19,7 @@ import { IUserFollowersResponse } from '../../types/raw/user/Followers';
15
19
  import { IUserFollowingResponse } from '../../types/raw/user/Following';
16
20
  import { IUserHighlightsResponse } from '../../types/raw/user/Highlights';
17
21
  import { IUserLikesResponse } from '../../types/raw/user/Likes';
22
+ import { IUserListsResponse } from '../../types/raw/user/Lists';
18
23
  import { IUserMediaResponse } from '../../types/raw/user/Media';
19
24
  import { IUserNotificationsResponse } from '../../types/raw/user/Notifications';
20
25
  import { IUserRecommendedResponse } from '../../types/raw/user/Recommended';
@@ -83,6 +88,64 @@ export class UserService extends FetcherService {
83
88
  return data;
84
89
  }
85
90
 
91
+ /**
92
+ * Get the analytics overview of the logged in user.
93
+ *
94
+ * @param fromTime - The start time of the analytics period. Defaults to 7 days ago.
95
+ * @param toTime - The end time of the analytics period. Defaults to now.
96
+ * @param granularity - The granularity of the analytics data. Defaults to daily.
97
+ * @param metrics - The metrics to include in the analytics data. Defaults to all available metrics available.
98
+ * @param showVerifiedFollowers - Whether to include verified follower count and relationship counts in the response. Defaults to true.
99
+ *
100
+ * @returns The raw analytics data of the user.
101
+ *
102
+ * @example
103
+ *
104
+ * ```ts
105
+ * import { Rettiwt } from 'rettiwt-api';
106
+ *
107
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
108
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
109
+ *
110
+ * // Fetching the analytics overview of the logged in user
111
+ * rettiwt.user.analytics().then(res => {
112
+ * console.log(res);
113
+ * })
114
+ * .catch(err => {
115
+ * console.log(err);
116
+ * });
117
+ * ```
118
+ */
119
+ public async analytics(
120
+ fromTime?: Date,
121
+ toTime?: Date,
122
+ granularity?: RawAnalyticsGranularity,
123
+ metrics?: RawAnalyticsMetric[],
124
+ showVerifiedFollowers?: boolean,
125
+ ): Promise<Analytics> {
126
+ const resource = ResourceType.USER_ANALYTICS;
127
+
128
+ // Define default values if not provided
129
+ fromTime = fromTime ?? new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
130
+ toTime = toTime ?? new Date();
131
+ granularity = granularity ?? RawAnalyticsGranularity.DAILY;
132
+ metrics = metrics ?? Object.values(RawAnalyticsMetric);
133
+ showVerifiedFollowers = showVerifiedFollowers ?? true;
134
+
135
+ // Fetching raw analytics
136
+ const response = await this.request<IUserAnalyticsResponse>(resource, {
137
+ fromTime,
138
+ toTime,
139
+ granularity,
140
+ metrics,
141
+ showVerifiedFollowers,
142
+ });
143
+
144
+ const data = Extractors[resource](response);
145
+
146
+ return data;
147
+ }
148
+
86
149
  /**
87
150
  * Get the list of bookmarks of the logged in user.
88
151
  *
@@ -165,8 +228,8 @@ export class UserService extends FetcherService {
165
228
  * // Creating a new Rettiwt instance using the given 'API_KEY'
166
229
  * const rettiwt = new Rettiwt({ apiKey: API_KEY });
167
230
  *
168
- * // Fetching the details of the User with username 'user1'
169
- * rettiwt.user.details('user1')
231
+ * // Fetching the details of the User with username 'user1' or '@user1'
232
+ * rettiwt.user.details('user1') // or @user1
170
233
  * .then(res => {
171
234
  * console.log(res);
172
235
  * })
@@ -243,6 +306,9 @@ export class UserService extends FetcherService {
243
306
  // If username is given
244
307
  if (id && isNaN(Number(id))) {
245
308
  resource = ResourceType.USER_DETAILS_BY_USERNAME;
309
+ if (id?.startsWith('@')) {
310
+ id = id.slice(1);
311
+ }
246
312
  }
247
313
  // If id is given (or not, for self details)
248
314
  else {
@@ -515,6 +581,48 @@ export class UserService extends FetcherService {
515
581
  return data;
516
582
  }
517
583
 
584
+ /**
585
+ * Get the list of of the the logged in user. Includes both followed and owned.
586
+ *
587
+ * @param count - The number of lists to fetch, must be \<= 100.
588
+ * @param cursor - The cursor to the batch of likes to fetch.
589
+ *
590
+ * @returns The list of tweets liked by the target user.
591
+ *
592
+ * @example
593
+ *
594
+ * ```ts
595
+ * import { Rettiwt } from 'rettiwt-api';
596
+ *
597
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
598
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
599
+ *
600
+ * // Fetching the first 100 Lists of the logged in User
601
+ * rettiwt.user.lists()
602
+ * .then(res => {
603
+ * console.log(res);
604
+ * })
605
+ * .catch(err => {
606
+ * console.log(err);
607
+ * });
608
+ * ```
609
+ */
610
+ public async lists(count?: number, cursor?: string): Promise<CursoredData<List>> {
611
+ const resource = ResourceType.USER_LISTS;
612
+
613
+ // Fetching raw list of lists
614
+ const response = await this.request<IUserListsResponse>(resource, {
615
+ id: this.config.userId,
616
+ count: count,
617
+ cursor: cursor,
618
+ });
619
+
620
+ // Deserializing response
621
+ const data = Extractors[resource](response);
622
+
623
+ return data;
624
+ }
625
+
518
626
  /**
519
627
  * Get the media timeline of a user.
520
628
  *
@@ -1,3 +1,4 @@
1
+ import { RawAnalyticsGranularity, RawAnalyticsMetric } from '../../enums/raw/Analytics';
1
2
  import { TweetRepliesSortType } from '../../enums/Tweet';
2
3
 
3
4
  /**
@@ -6,21 +7,45 @@ import { TweetRepliesSortType } from '../../enums/Tweet';
6
7
  * @public
7
8
  */
8
9
  export interface IFetchArgs {
10
+ /**
11
+ * The id of the active conversation.
12
+ *
13
+ * @remarks
14
+ * - Required only for {@link ResourceType.DM_USER_UPDATES}.
15
+ */
16
+ activeConversationId?: string;
17
+
18
+ /**
19
+ * The maximum id of the data to fetch.
20
+ *
21
+ * @remarks
22
+ * - May be used for {@link ResourceType.DM_INBOX_TIMELINE} and {@link ResourceType.DM_CONVERSATION}.
23
+ */
24
+ maxId?: string;
25
+
26
+ /**
27
+ * The id of the conversation to fetch.
28
+ *
29
+ * @remarks
30
+ * - Required only for {@link ResourceType.DM_CONVERSATION} and {@link ResourceType.DM_DELETE_CONVERSATION}.
31
+ */
32
+ conversationId?: string;
33
+
9
34
  /**
10
35
  * The number of data items to fetch.
11
36
  *
12
37
  * @remarks
13
38
  * - Works only for cursored resources.
14
- * - Does not work for {@link EResourceType.TWEET_REPLIES}.
39
+ * - Does not work for {@link ResourceType.TWEET_REPLIES}.
15
40
  * - Must be \<= 20 for:
16
- * - {@link EResourceType.USER_TIMELINE}
17
- * - {@link EResourceType.USER_TIMELINE}
18
- * - {@link EResourceType.USER_TIMELINE_AND_REPLIES}
41
+ * - {@link ResourceType.USER_TIMELINE}
42
+ * - {@link ResourceType.USER_TIMELINE}
43
+ * - {@link ResourceType.USER_TIMELINE_AND_REPLIES}
19
44
  * - Must be \<= 100 for all other cursored resources.
20
- * - Due a bug on Twitter's end, count does not work for {@link EResourceType.USER_FOLLOWERS} and {@link EResourceType.USER_FOLLOWING}.
45
+ * - Due a bug on Twitter's end, count does not work for {@link ResourceType.USER_FOLLOWERS} and {@link ResourceType.USER_FOLLOWING}.
21
46
  * - Has not effect for:
22
- * - {@link EResourceType.USER_FEED_FOLLOWED}
23
- * - {@link EResourceType.USER_FEED_RECOMMENDED}
47
+ * - {@link ResourceType.USER_FEED_FOLLOWED}
48
+ * - {@link ResourceType.USER_FEED_RECOMMENDED}
24
49
  */
25
50
  count?: number;
26
51
 
@@ -37,7 +62,7 @@ export interface IFetchArgs {
37
62
  * The filter for searching tweets.
38
63
  *
39
64
  * @remarks
40
- * Required when searching for tweets using {@link EResourceType.TWEET_SEARCH}.
65
+ * Required when searching for tweets using {@link ResourceType.TWEET_SEARCH}.
41
66
  */
42
67
  filter?: ITweetFilter;
43
68
 
@@ -45,8 +70,8 @@ export interface IFetchArgs {
45
70
  * The id of the target resource.
46
71
  *
47
72
  * @remarks
48
- * - Required for all resources except {@link EResourceType.TWEET_SEARCH} and {@link EResourceType.USER_TIMELINE_RECOMMENDED}.
49
- * - For {@link EResourceType.USER_DETAILS_BY_USERNAME}, can be alphanumeric, while for others, is strictly numeric.
73
+ * - Required for all resources except {@link ResourceType.TWEET_SEARCH} and {@link ResourceType.USER_TIMELINE_RECOMMENDED}.
74
+ * - For {@link ResourceType.USER_DETAILS_BY_USERNAME}, can be alphanumeric, while for others, is strictly numeric.
50
75
  */
51
76
  id?: string;
52
77
 
@@ -54,7 +79,7 @@ export interface IFetchArgs {
54
79
  * The IDs of the target resources.
55
80
  *
56
81
  * @remarks
57
- * - Required only for {@link EResourceType.TWEET_DETAILS_BULK} and {@link EResourceType.USER_DETAILS_BY_IDS_BULK}.
82
+ * - Required only for {@link ResourceType.TWEET_DETAILS_BULK} and {@link ResourceType.USER_DETAILS_BY_IDS_BULK}.
58
83
  */
59
84
  ids?: string[];
60
85
 
@@ -62,9 +87,49 @@ export interface IFetchArgs {
62
87
  * The sorting to use for tweet results.
63
88
  *
64
89
  * @remarks
65
- * - Only works for {@link EResourceType.TWEET_REPLIES}.
90
+ * - Only works for {@link ResourceType.TWEET_REPLIES}.
66
91
  */
67
92
  sortBy?: TweetRepliesSortType;
93
+
94
+ /**
95
+ * The date to start fetching data from.
96
+ *
97
+ * @remarks
98
+ * - Only works for {@link EResourceType.USER_ANALYTICS}.
99
+ */
100
+ fromTime?: Date;
101
+
102
+ /**
103
+ * The date to end fetching data at.
104
+ *
105
+ * @remarks
106
+ * - Only works for {@link EResourceType.USER_ANALYTICS}.
107
+ */
108
+ toTime?: Date;
109
+
110
+ /**
111
+ * The granularity of the data to fetch.
112
+ *
113
+ * @remarks
114
+ * - Only works for {@link EResourceType.USER_ANALYTICS}.
115
+ */
116
+ granularity?: RawAnalyticsGranularity;
117
+
118
+ /**
119
+ * The metrics to fetch.
120
+ *
121
+ * @remarks
122
+ * - Only works for {@link EResourceType.USER_ANALYTICS}.
123
+ */
124
+ metrics?: RawAnalyticsMetric[];
125
+
126
+ /**
127
+ * Show the verified follower count and relationship counts in the response.
128
+ *
129
+ * @remarks
130
+ * - Only works for {@link EResourceType.USER_ANALYTICS}.
131
+ */
132
+ showVerifiedFollowers?: boolean;
68
133
  }
69
134
 
70
135
  /**
@@ -9,13 +9,15 @@ export interface IPostArgs {
9
9
  *
10
10
  * @remarks
11
11
  * Required only when posting using the following resources:
12
- * - {@link EResourceType.TWEET_LIKE}
13
- * - {@link EResourceType.TWEET_RETWEET}
14
- * - {@link EResourceType.TWEET_UNLIKE}
15
- * - {@link EResourceType.TWEET_UNPOST}
16
- * - {@link EResourceType.TWEET_UNRETWEET}
17
- * - {@link EResourceType.USER_FOLLOW}
18
- * - {@link EResourceType.USER_UNFOLLOW}
12
+ * - {@link ResourceType.TWEET_BOOKMARK}
13
+ * - {@link ResourceType.TWEET_LIKE}
14
+ * - {@link ResourceType.TWEET_RETWEET}
15
+ * - {@link ResourceType.TWEET_UNBOOKMARK}
16
+ * - {@link ResourceType.TWEET_UNLIKE}
17
+ * - {@link ResourceType.TWEET_UNPOST}
18
+ * - {@link ResourceType.TWEET_UNRETWEET}
19
+ * - {@link ResourceType.USER_FOLLOW}
20
+ * - {@link ResourceType.USER_UNFOLLOW}
19
21
  */
20
22
  id?: string;
21
23
 
@@ -23,7 +25,7 @@ export interface IPostArgs {
23
25
  * The tweet that is to be posted.
24
26
  *
25
27
  * @remarks
26
- * Required only when posting a tweet using {@link EResourceType.TWEET_POST}
28
+ * Required only when posting a tweet using {@link ResourceType.TWEET_POST}
27
29
  */
28
30
  tweet?: INewTweet;
29
31
 
@@ -32,11 +34,29 @@ export interface IPostArgs {
32
34
  *
33
35
  * @remarks
34
36
  * Required only when uploading a media using the following resources:
35
- * - {@link EResourceType.MEDIA_UPLOAD_APPEND}
36
- * - {@link EResourceType.MEDIA_UPLOAD_FINALIZE}
37
- * - {@link EResourceType.MEDIA_UPLOAD_INITIALIZE}
37
+ * - {@link ResourceType.MEDIA_UPLOAD_APPEND}
38
+ * - {@link ResourceType.MEDIA_UPLOAD_FINALIZE}
39
+ * - {@link ResourceType.MEDIA_UPLOAD_INITIALIZE}
38
40
  */
39
41
  upload?: IUploadArgs;
42
+
43
+ /**
44
+ * The id of the target user.
45
+ *
46
+ * @remarks
47
+ * Required only for the following resources:
48
+ * - {@link ResourceType.LIST_MEMBER_ADD}
49
+ * - {@link ResourceType.LIST_MEMBER_REMOVE}
50
+ */
51
+ userId?: string;
52
+
53
+ /**
54
+ * The id of the conversation to delete.
55
+ *
56
+ * @remarks
57
+ * Required only when deleting a conversation using {@link ResourceType.DM_DELETE_CONVERSATION}
58
+ */
59
+ conversationId?: string;
40
60
  }
41
61
 
42
62
  /**
@@ -0,0 +1,58 @@
1
+ import type { IAnalyticsMetric } from '../../types/raw/base/Analytic';
2
+ /**
3
+ * The details of the analytic result of the connected User.
4
+ *
5
+ * @public
6
+ */
7
+ export interface IAnalytics {
8
+ /** The creation date of user's account. */
9
+ createdAt: string;
10
+
11
+ /** Total followers number */
12
+ followers: number;
13
+
14
+ /** Total verified followers */
15
+ verifiedFollowers: number;
16
+
17
+ /** Total impressions on the given period */
18
+ impressions: number;
19
+
20
+ /** Total profile visits on the given period */
21
+ profileVisits: number;
22
+
23
+ /** Total Engagements on the given period */
24
+ engagements: number;
25
+
26
+ /** Total Follows on the given period */
27
+ follows: number;
28
+
29
+ /** Total Replies on the given period */
30
+ replies: number;
31
+
32
+ /** Total Likes on the given period */
33
+ likes: number;
34
+
35
+ /** Total Retweets on the given period */
36
+ retweets: number;
37
+
38
+ /** Total Bookmark on the given period */
39
+ bookmarks: number;
40
+
41
+ /** Total Shares on the given period */
42
+ shares: number;
43
+
44
+ /** Total CreateTweets on the given period */
45
+ createTweets: number;
46
+
47
+ /** Total CreateQuote on the given period */
48
+ createQuote: number;
49
+
50
+ /** Total Unfollows on the given period */
51
+ unfollows: number;
52
+
53
+ /** Total CreateReply on the given period */
54
+ createReply: number;
55
+
56
+ /** Organic metrics times series */
57
+ organicMetricsTimeSeries: IAnalyticsMetric[];
58
+ }