rettiwt-api 3.1.1 → 4.1.0-alpha.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 (80) hide show
  1. package/.github/FUNDING.yml +4 -0
  2. package/.github/workflows/documentation.yml +5 -0
  3. package/.github/workflows/publish-alpha.yml +29 -0
  4. package/.github/workflows/publish.yml +3 -0
  5. package/.yarnrc.yml +1 -0
  6. package/README.md +50 -10
  7. package/dist/collections/Extractors.d.ts +6 -2
  8. package/dist/collections/Extractors.js +6 -3
  9. package/dist/collections/Extractors.js.map +1 -1
  10. package/dist/collections/Groups.js +4 -1
  11. package/dist/collections/Groups.js.map +1 -1
  12. package/dist/collections/Requests.js +4 -1
  13. package/dist/collections/Requests.js.map +1 -1
  14. package/dist/commands/Tweet.js +73 -41
  15. package/dist/commands/Tweet.js.map +1 -1
  16. package/dist/commands/User.js +42 -19
  17. package/dist/commands/User.js.map +1 -1
  18. package/dist/enums/Data.d.ts +1 -0
  19. package/dist/enums/Data.js +1 -0
  20. package/dist/enums/Data.js.map +1 -1
  21. package/dist/enums/Resource.d.ts +4 -1
  22. package/dist/enums/Resource.js +4 -1
  23. package/dist/enums/Resource.js.map +1 -1
  24. package/dist/helper/CliUtils.d.ts +2 -0
  25. package/dist/helper/CliUtils.js +2 -0
  26. package/dist/helper/CliUtils.js.map +1 -1
  27. package/dist/helper/JsonUtils.d.ts +2 -0
  28. package/dist/helper/JsonUtils.js +3 -1
  29. package/dist/helper/JsonUtils.js.map +1 -1
  30. package/dist/index.d.ts +2 -2
  31. package/dist/models/args/FetchArgs.d.ts +0 -2
  32. package/dist/models/args/FetchArgs.js +138 -10
  33. package/dist/models/args/FetchArgs.js.map +1 -1
  34. package/dist/models/args/PostArgs.d.ts +3 -1
  35. package/dist/models/args/PostArgs.js +62 -24
  36. package/dist/models/args/PostArgs.js.map +1 -1
  37. package/dist/models/data/CursoredData.d.ts +3 -3
  38. package/dist/models/data/CursoredData.js +5 -1
  39. package/dist/models/data/CursoredData.js.map +1 -1
  40. package/dist/models/data/Notification.d.ts +46 -0
  41. package/dist/models/data/Notification.js +69 -0
  42. package/dist/models/data/Notification.js.map +1 -0
  43. package/dist/models/data/Tweet.d.ts +6 -6
  44. package/dist/models/data/Tweet.js +1 -1
  45. package/dist/models/data/Tweet.js.map +1 -1
  46. package/dist/models/data/User.d.ts +3 -3
  47. package/dist/models/data/User.js.map +1 -1
  48. package/dist/services/public/AuthService.d.ts +21 -0
  49. package/dist/services/public/AuthService.js +44 -1
  50. package/dist/services/public/AuthService.js.map +1 -1
  51. package/dist/services/public/FetcherService.d.ts +2 -2
  52. package/dist/services/public/FetcherService.js +5 -6
  53. package/dist/services/public/FetcherService.js.map +1 -1
  54. package/dist/services/public/TweetService.d.ts +55 -32
  55. package/dist/services/public/TweetService.js +96 -55
  56. package/dist/services/public/TweetService.js.map +1 -1
  57. package/dist/services/public/UserService.d.ts +32 -6
  58. package/dist/services/public/UserService.js +52 -7
  59. package/dist/services/public/UserService.js.map +1 -1
  60. package/package.json +3 -2
  61. package/src/collections/Extractors.ts +10 -3
  62. package/src/collections/Groups.ts +4 -1
  63. package/src/collections/Requests.ts +4 -1
  64. package/src/commands/Tweet.ts +43 -18
  65. package/src/commands/User.ts +17 -4
  66. package/src/enums/Data.ts +1 -0
  67. package/src/enums/Resource.ts +4 -1
  68. package/src/helper/CliUtils.ts +2 -0
  69. package/src/helper/JsonUtils.ts +3 -1
  70. package/src/index.ts +5 -1
  71. package/src/models/args/FetchArgs.ts +140 -11
  72. package/src/models/args/PostArgs.ts +65 -24
  73. package/src/models/data/CursoredData.ts +7 -4
  74. package/src/models/data/Notification.ts +91 -0
  75. package/src/models/data/Tweet.ts +6 -7
  76. package/src/models/data/User.ts +3 -3
  77. package/src/services/public/AuthService.ts +51 -1
  78. package/src/services/public/FetcherService.ts +9 -8
  79. package/src/services/public/TweetService.ts +103 -60
  80. package/src/services/public/UserService.ts +51 -7
@@ -5,14 +5,16 @@ import {
5
5
  IListTweetsResponse,
6
6
  ITweetDetailsResponse,
7
7
  ITweetLikeResponse,
8
- ITweetLikersResponse,
9
8
  ITweetPostResponse,
9
+ ITweetRepliesResponse,
10
10
  ITweetRetweetersResponse,
11
11
  ITweetRetweetResponse,
12
+ ITweetScheduleResponse,
12
13
  ITweetSearchResponse,
13
14
  ITweetUnlikeResponse,
14
15
  ITweetUnpostResponse,
15
16
  ITweetUnretweetResponse,
17
+ ITweetUnscheduleResponse,
16
18
  TweetFilter,
17
19
  } from 'rettiwt-core';
18
20
 
@@ -68,15 +70,32 @@ export class TweetService extends FetcherService {
68
70
  * ```
69
71
  */
70
72
  public async details(id: string): Promise<Tweet | undefined> {
71
- const resource = EResourceType.TWEET_DETAILS;
73
+ let resource: EResourceType;
72
74
 
73
- // Fetching raw tweet details
74
- const response = await this.request<ITweetDetailsResponse>(resource, { id: id });
75
+ // If user is authenticated
76
+ if (this.userId != undefined) {
77
+ resource = EResourceType.TWEET_DETAILS_ALT;
75
78
 
76
- // Deserializing response
77
- const data = extractors[resource](response, id);
79
+ // Fetching raw tweet details
80
+ const response = await this.request<ITweetRepliesResponse>(resource, { id: id });
78
81
 
79
- return data;
82
+ // Deserializing response
83
+ const data = extractors[resource](response, id);
84
+
85
+ return data;
86
+ }
87
+ // If user is not authenticated
88
+ else {
89
+ resource = EResourceType.TWEET_DETAILS;
90
+
91
+ // Fetching raw tweet details
92
+ const response = await this.request<ITweetDetailsResponse>(resource, { id: id });
93
+
94
+ // Deserializing response
95
+ const data = extractors[resource](response, id);
96
+
97
+ return data;
98
+ }
80
99
  }
81
100
 
82
101
  /**
@@ -117,58 +136,6 @@ export class TweetService extends FetcherService {
117
136
  return data;
118
137
  }
119
138
 
120
- /**
121
- * @deprecated
122
- * The method will be removed in the next release following the removal of the ability to see tweet likers by Twitter.
123
- * Currently, the method does not work.
124
- *
125
- * Get the list of users who liked a tweet.
126
- *
127
- * @param id - The id of the target tweet.
128
- * @param count - The number of likers to fetch, must be \<= 100.
129
- * @param cursor - The cursor to the batch of likers to fetch.
130
- *
131
- * @returns The list of users who liked the given tweet.
132
- *
133
- * @example
134
- * ```
135
- * import { Rettiwt } from 'rettiwt-api';
136
- *
137
- * // Creating a new Rettiwt instance using the given 'API_KEY'
138
- * const rettiwt = new Rettiwt({ apiKey: API_KEY });
139
- *
140
- * // Fetching the most recent 100 likers of the Tweet with id '1234567890'
141
- * rettiwt.tweet.likers('1234567890')
142
- * .then(res => {
143
- * console.log(res);
144
- * })
145
- * .catch(err => {
146
- * console.log(err);
147
- * });
148
- * ```
149
- */
150
- public async likers(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
151
- // Deprecation warning
152
- console.log(`
153
- This method has been deprecated following the removal of the ability to see tweet liksers by Twitter.
154
- Currently, the method does not work.
155
- `);
156
-
157
- const resource = EResourceType.TWEET_LIKERS;
158
-
159
- // Fetching raw likers
160
- const response = await this.request<ITweetLikersResponse>(resource, {
161
- id: id,
162
- count: count,
163
- cursor: cursor,
164
- });
165
-
166
- // Deserializing response
167
- const data = extractors[resource](response);
168
-
169
- return data;
170
- }
171
-
172
139
  /**
173
140
  * Get the list of tweets from a tweet list.
174
141
  *
@@ -221,7 +188,7 @@ export class TweetService extends FetcherService {
221
188
  *
222
189
  * @param options - The options describing the tweet to be posted. Check {@link TweetArgs} for available options.
223
190
  *
224
- * @returns Whether posting was successful or not.
191
+ * @returns The id of the posted tweet.
225
192
  *
226
193
  * @example
227
194
  * Posting a simple text
@@ -385,6 +352,46 @@ export class TweetService extends FetcherService {
385
352
  return data;
386
353
  }
387
354
 
355
+ /**
356
+ * Schedule a tweet.
357
+ *
358
+ * @param options - The options describing the tweet to be posted. Check {@link TweetArgs} for available options.
359
+ *
360
+ * @returns The id of the schedule.
361
+ *
362
+ * @example
363
+ * Scheduling a simple text
364
+ * ```
365
+ * import { Rettiwt } from 'rettiwt-api';
366
+ *
367
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
368
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
369
+ *
370
+ * // Scheduling a tweet to posted at 19th of August, 2024, at 11:59:00 AM, in local time
371
+ * rettiwt.tweet.schedule({ text: 'Hello World!', scheduleFor: new Date('2024-08-19 23:59:00') })
372
+ * .then(res => {
373
+ * console.log(res);
374
+ * })
375
+ * .catch(err => {
376
+ * console.log(err);
377
+ * });
378
+ * ```
379
+ *
380
+ * @remarks
381
+ * Scheduling a tweet is similar to {@link post}ing, except that an extra parameter called `scheduleFor` is used.
382
+ */
383
+ public async schedule(options: TweetArgs): Promise<string | undefined> {
384
+ const resource = EResourceType.TWEET_SCHEDULE;
385
+
386
+ // Scheduling the tweet
387
+ const response = await this.request<ITweetScheduleResponse>(resource, { tweet: options });
388
+
389
+ // Deserializing response
390
+ const data = extractors[resource](response);
391
+
392
+ return data;
393
+ }
394
+
388
395
  /**
389
396
  * Search for tweets using a filter.
390
397
  *
@@ -604,6 +611,42 @@ export class TweetService extends FetcherService {
604
611
  return data;
605
612
  }
606
613
 
614
+ /**
615
+ * Unschedule a tweet.
616
+ *
617
+ * @param id - The id of the scheduled tweet.
618
+ *
619
+ * @returns Whether unscheduling was successful or not.
620
+ *
621
+ * @example
622
+ * ```
623
+ * import { Rettiwt } from 'rettiwt-api';
624
+ *
625
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
626
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
627
+ *
628
+ * // Unscheduling the Tweet with id '1234567890'
629
+ * rettiwt.tweet.unschedule('1234567890')
630
+ * .then(res => {
631
+ * console.log(res);
632
+ * })
633
+ * .catch(err => {
634
+ * console.log(err);
635
+ * });
636
+ * ```
637
+ */
638
+ public async unschedule(id: string): Promise<boolean> {
639
+ const resource = EResourceType.TWEET_UNSCHEDULE;
640
+
641
+ // Unscheduling the tweet
642
+ const response = await this.request<ITweetUnscheduleResponse>(resource, { id: id });
643
+
644
+ // Deserializing the response
645
+ const data = extractors[resource](response) ?? false;
646
+
647
+ return data;
648
+ }
649
+
607
650
  /**
608
651
  * Upload a media file to Twitter.
609
652
  *
@@ -7,6 +7,7 @@ import {
7
7
  IUserHighlightsResponse,
8
8
  IUserLikesResponse,
9
9
  IUserMediaResponse,
10
+ IUserNotifications as IUserNotificationsResponse,
10
11
  IUserRecommendedResponse,
11
12
  IUserSubscriptionsResponse,
12
13
  IUserTweetsAndRepliesResponse,
@@ -17,6 +18,7 @@ import {
17
18
  import { extractors } from '../../collections/Extractors';
18
19
  import { EResourceType } from '../../enums/Resource';
19
20
  import { CursoredData } from '../../models/data/CursoredData';
21
+ import { Notification } from '../../models/data/Notification';
20
22
  import { Tweet } from '../../models/data/Tweet';
21
23
  import { User } from '../../models/data/User';
22
24
  import { IRettiwtConfig } from '../../types/RettiwtConfig';
@@ -309,9 +311,8 @@ export class UserService extends FetcherService {
309
311
  }
310
312
 
311
313
  /**
312
- * Get the list of tweets liked by a user.
314
+ * Get the list of tweets liked by the logged in user.
313
315
  *
314
- * @param id - The id of the target user.
315
316
  * @param count - The number of likes to fetch, must be \<= 100.
316
317
  * @param cursor - The cursor to the batch of likes to fetch.
317
318
  *
@@ -324,8 +325,8 @@ export class UserService extends FetcherService {
324
325
  * // Creating a new Rettiwt instance using the given 'API_KEY'
325
326
  * const rettiwt = new Rettiwt({ apiKey: API_KEY });
326
327
  *
327
- * // Fetching the most recent 100 liked Tweets of the User with id '1234567890'
328
- * rettiwt.user.likes('1234567890')
328
+ * // Fetching the most recent 100 liked Tweets of the logged in User
329
+ * rettiwt.user.likes()
329
330
  * .then(res => {
330
331
  * console.log(res);
331
332
  * })
@@ -334,12 +335,12 @@ export class UserService extends FetcherService {
334
335
  * });
335
336
  * ```
336
337
  */
337
- public async likes(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
338
+ public async likes(count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
338
339
  const resource = EResourceType.USER_LIKES;
339
340
 
340
341
  // Fetching raw list of likes
341
342
  const response = await this.request<IUserLikesResponse>(resource, {
342
- id: id,
343
+ id: this.userId,
343
344
  count: count,
344
345
  cursor: cursor,
345
346
  });
@@ -351,7 +352,7 @@ export class UserService extends FetcherService {
351
352
  }
352
353
 
353
354
  /**
354
- * Get the media timeline of a user
355
+ * Get the media timeline of a user.
355
356
  *
356
357
  * @param id - The id of the target user.
357
358
  * @param count - The number of media to fetch, must be \<= 100.
@@ -392,6 +393,49 @@ export class UserService extends FetcherService {
392
393
  return data;
393
394
  }
394
395
 
396
+ /**
397
+ * Get the list of notifications of the logged in user.
398
+ *
399
+ * @param count - The number of notifications to fetch, must be \<= 40.
400
+ * @param cursor - The cursor to the batch of notifications to fetch
401
+ *
402
+ * @returns The list of notifications of the target user.
403
+ *
404
+ * @example
405
+ * ```
406
+ * import { Rettiwt } from 'rettiwt-api';
407
+ *
408
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
409
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
410
+ *
411
+ * // Fetching the recent 40 Notifications of the logged in user
412
+ * rettiwt.user.notifications(40)
413
+ * .then(res => {
414
+ * console.log(res);
415
+ * })
416
+ * .catch(err => {
417
+ * console.log(err);
418
+ * });
419
+ * ```
420
+ */
421
+ public async notifications(count?: number, cursor?: string): Promise<CursoredData<Notification>> {
422
+ const resource = EResourceType.USER_NOTIFICATIONS;
423
+
424
+ // Fetching raw list of notifications
425
+ const response = await this.request<IUserNotificationsResponse>(resource, {
426
+ count: count,
427
+ cursor: cursor,
428
+ });
429
+
430
+ // Deserializing response
431
+ const data = extractors[resource](response);
432
+
433
+ // Sorting the notifications by time, from recent to oldest
434
+ data.list.sort((a, b) => new Date(b.receivedAt).valueOf() - new Date(a.receivedAt).valueOf());
435
+
436
+ return data;
437
+ }
438
+
395
439
  /**
396
440
  * Get the recommended feed of the logged in user.
397
441
  *