rettiwt-api 4.2.0 → 5.0.0-alpha.1

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 (179) hide show
  1. package/.eslintrc.js +2 -3
  2. package/.github/workflows/documentation.yml +1 -1
  3. package/.github/workflows/publish-alpha.yml +1 -1
  4. package/.github/workflows/publish.yml +1 -1
  5. package/.prettierignore +1 -1
  6. package/.tool-versions +1 -1
  7. package/README.md +100 -100
  8. package/dist/Rettiwt.d.ts +1 -1
  9. package/dist/Rettiwt.js +15 -8
  10. package/dist/Rettiwt.js.map +1 -1
  11. package/dist/cli.js +8 -11
  12. package/dist/cli.js.map +1 -1
  13. package/dist/collections/Extractors.d.ts +1 -0
  14. package/dist/collections/Extractors.js +38 -69
  15. package/dist/collections/Extractors.js.map +1 -1
  16. package/dist/collections/Groups.js +2 -1
  17. package/dist/collections/Groups.js.map +1 -1
  18. package/dist/collections/Requests.d.ts +3 -3
  19. package/dist/collections/Requests.js +36 -35
  20. package/dist/collections/Requests.js.map +1 -1
  21. package/dist/commands/List.js +21 -78
  22. package/dist/commands/List.js.map +1 -1
  23. package/dist/commands/Tweet.js +185 -370
  24. package/dist/commands/Tweet.js.map +1 -1
  25. package/dist/commands/User.js +129 -306
  26. package/dist/commands/User.js.map +1 -1
  27. package/dist/enums/Authentication.d.ts +18 -0
  28. package/dist/enums/Authentication.js +24 -0
  29. package/dist/enums/Authentication.js.map +1 -0
  30. package/dist/enums/Data.d.ts +12 -0
  31. package/dist/enums/Data.js +14 -1
  32. package/dist/enums/Data.js.map +1 -1
  33. package/dist/enums/Resource.d.ts +1 -0
  34. package/dist/enums/Resource.js +1 -0
  35. package/dist/enums/Resource.js.map +1 -1
  36. package/dist/helper/CliUtils.js +1 -2
  37. package/dist/helper/CliUtils.js.map +1 -1
  38. package/dist/helper/JsonUtils.js +6 -11
  39. package/dist/helper/JsonUtils.js.map +1 -1
  40. package/dist/index.d.ts +1 -2
  41. package/dist/index.js +1 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/models/args/FetchArgs.d.ts +4 -133
  44. package/dist/models/args/FetchArgs.js +12 -416
  45. package/dist/models/args/FetchArgs.js.map +1 -1
  46. package/dist/models/args/PostArgs.d.ts +16 -101
  47. package/dist/models/args/PostArgs.js +26 -258
  48. package/dist/models/args/PostArgs.js.map +1 -1
  49. package/dist/models/auth/AccountCredential.d.ts +13 -0
  50. package/dist/models/auth/AccountCredential.js +21 -0
  51. package/dist/models/auth/AccountCredential.js.map +1 -0
  52. package/dist/models/auth/AuthCookie.d.ts +19 -0
  53. package/dist/models/auth/AuthCookie.js +53 -0
  54. package/dist/models/auth/AuthCookie.js.map +1 -0
  55. package/dist/models/auth/AuthCredential.d.ts +28 -0
  56. package/dist/models/auth/AuthCredential.js +76 -0
  57. package/dist/models/auth/AuthCredential.js.map +1 -0
  58. package/dist/models/data/CursoredData.d.ts +3 -4
  59. package/dist/models/data/CursoredData.js +19 -19
  60. package/dist/models/data/CursoredData.js.map +1 -1
  61. package/dist/models/data/List.d.ts +2 -8
  62. package/dist/models/data/List.js +10 -4
  63. package/dist/models/data/List.js.map +1 -1
  64. package/dist/models/data/Notification.d.ts +5 -21
  65. package/dist/models/data/Notification.js +24 -33
  66. package/dist/models/data/Notification.js.map +1 -1
  67. package/dist/models/data/Tweet.d.ts +4 -17
  68. package/dist/models/data/Tweet.js +83 -73
  69. package/dist/models/data/Tweet.js.map +1 -1
  70. package/dist/models/data/User.d.ts +2 -15
  71. package/dist/models/data/User.js +33 -23
  72. package/dist/models/data/User.js.map +1 -1
  73. package/dist/models/errors/ApiError.js +8 -24
  74. package/dist/models/errors/ApiError.js.map +1 -1
  75. package/dist/models/errors/HttpError.js +8 -24
  76. package/dist/models/errors/HttpError.js.map +1 -1
  77. package/dist/models/errors/RettiwtError.js +5 -23
  78. package/dist/models/errors/RettiwtError.js.map +1 -1
  79. package/dist/models/errors/TimeoutError.js +5 -22
  80. package/dist/models/errors/TimeoutError.js.map +1 -1
  81. package/dist/services/{public → internal}/AuthService.d.ts +5 -34
  82. package/dist/services/internal/AuthService.js +109 -0
  83. package/dist/services/internal/AuthService.js.map +1 -0
  84. package/dist/services/internal/ErrorService.js +38 -40
  85. package/dist/services/internal/ErrorService.js.map +1 -1
  86. package/dist/services/internal/LogService.d.ts +0 -6
  87. package/dist/services/internal/LogService.js +12 -32
  88. package/dist/services/internal/LogService.js.map +1 -1
  89. package/dist/services/public/FetcherService.d.ts +5 -3
  90. package/dist/services/public/FetcherService.js +96 -141
  91. package/dist/services/public/FetcherService.js.map +1 -1
  92. package/dist/services/public/ListService.js +31 -100
  93. package/dist/services/public/ListService.js.map +1 -1
  94. package/dist/services/public/TweetService.d.ts +29 -4
  95. package/dist/services/public/TweetService.js +208 -386
  96. package/dist/services/public/TweetService.js.map +1 -1
  97. package/dist/services/public/UserService.js +186 -385
  98. package/dist/services/public/UserService.js.map +1 -1
  99. package/dist/types/RettiwtConfig.d.ts +8 -0
  100. package/dist/types/args/FetchArgs.d.ts +59 -0
  101. package/dist/types/args/FetchArgs.js +3 -0
  102. package/dist/types/args/FetchArgs.js.map +1 -0
  103. package/dist/types/args/PostArgs.d.ts +56 -0
  104. package/dist/types/args/PostArgs.js +3 -0
  105. package/dist/types/args/PostArgs.js.map +1 -0
  106. package/dist/types/auth/AccountCredential.d.ts +11 -0
  107. package/dist/types/auth/AccountCredential.js +3 -0
  108. package/dist/types/auth/AccountCredential.js.map +1 -0
  109. package/dist/types/auth/AuthCookie.d.ts +13 -0
  110. package/dist/types/auth/AuthCookie.js +3 -0
  111. package/dist/types/auth/AuthCookie.js.map +1 -0
  112. package/dist/types/auth/AuthCredential.d.ts +21 -0
  113. package/dist/types/auth/AuthCredential.js +3 -0
  114. package/dist/types/auth/AuthCredential.js.map +1 -0
  115. package/dist/types/data/CursoredData.d.ts +25 -0
  116. package/dist/types/data/CursoredData.js +3 -0
  117. package/dist/types/data/CursoredData.js.map +1 -0
  118. package/dist/types/data/List.d.ts +21 -0
  119. package/dist/types/data/List.js +3 -0
  120. package/dist/types/data/List.js.map +1 -0
  121. package/dist/types/data/Notification.d.ts +20 -0
  122. package/dist/types/data/Notification.js +3 -0
  123. package/dist/types/data/Notification.js.map +1 -0
  124. package/dist/types/data/Tweet.d.ts +71 -0
  125. package/dist/types/data/Tweet.js +3 -0
  126. package/dist/types/data/Tweet.js.map +1 -0
  127. package/dist/types/data/User.d.ts +35 -0
  128. package/dist/types/data/User.js +3 -0
  129. package/dist/types/data/User.js.map +1 -0
  130. package/eslint.config.mjs +17 -0
  131. package/package.json +22 -19
  132. package/src/Rettiwt.ts +1 -1
  133. package/src/cli.ts +0 -2
  134. package/src/collections/Extractors.ts +2 -0
  135. package/src/collections/Groups.ts +1 -0
  136. package/src/collections/Requests.ts +37 -36
  137. package/src/enums/Authentication.ts +19 -0
  138. package/src/enums/Data.ts +13 -0
  139. package/src/enums/Resource.ts +1 -0
  140. package/src/helper/JsonUtils.ts +1 -1
  141. package/src/index.ts +1 -2
  142. package/src/models/args/FetchArgs.ts +4 -470
  143. package/src/models/args/PostArgs.ts +20 -285
  144. package/src/models/auth/AccountCredential.ts +19 -0
  145. package/src/models/auth/AuthCookie.ts +56 -0
  146. package/src/models/auth/AuthCredential.ts +83 -0
  147. package/src/models/data/CursoredData.ts +12 -9
  148. package/src/models/data/List.ts +3 -14
  149. package/src/models/data/Notification.ts +6 -28
  150. package/src/models/data/Tweet.ts +17 -43
  151. package/src/models/data/User.ts +5 -31
  152. package/src/services/{public → internal}/AuthService.ts +28 -55
  153. package/src/services/internal/LogService.ts +4 -19
  154. package/src/services/public/FetcherService.ts +18 -8
  155. package/src/services/public/TweetService.ts +44 -4
  156. package/src/services/public/UserService.ts +2 -2
  157. package/src/types/RettiwtConfig.ts +7 -0
  158. package/src/types/args/FetchArgs.ts +64 -0
  159. package/src/types/args/PostArgs.ts +62 -0
  160. package/src/types/auth/AccountCredential.ts +13 -0
  161. package/src/types/auth/AuthCookie.ts +20 -0
  162. package/src/types/auth/AuthCredential.ts +26 -0
  163. package/src/types/data/CursoredData.ts +28 -0
  164. package/src/types/data/List.ts +27 -0
  165. package/src/types/data/Notification.ts +26 -0
  166. package/src/types/data/Tweet.ts +96 -0
  167. package/src/types/data/User.ts +48 -0
  168. package/tsconfig.json +7 -5
  169. package/.eslintignore +0 -3
  170. package/dist/commands/Auth.d.ts +0 -10
  171. package/dist/commands/Auth.js +0 -101
  172. package/dist/commands/Auth.js.map +0 -1
  173. package/dist/models/errors/DataValidationError.d.ts +0 -30
  174. package/dist/models/errors/DataValidationError.js +0 -34
  175. package/dist/models/errors/DataValidationError.js.map +0 -1
  176. package/dist/services/public/AuthService.js +0 -205
  177. package/dist/services/public/AuthService.js.map +0 -1
  178. package/src/commands/Auth.ts +0 -46
  179. package/src/models/errors/DataValidationError.ts +0 -44
@@ -2,8 +2,8 @@ import { AxiosRequestConfig } from 'axios';
2
2
  import { Request } from 'rettiwt-core';
3
3
 
4
4
  import { EResourceType } from '../enums/Resource';
5
- import { FetchArgs } from '../models/args/FetchArgs';
6
- import { PostArgs } from '../models/args/PostArgs';
5
+ import { IFetchArgs } from '../types/args/FetchArgs';
6
+ import { IPostArgs } from '../types/args/PostArgs';
7
7
 
8
8
  /**
9
9
  * The request generator from rettiwt-core.
@@ -17,43 +17,44 @@ const request = new Request();
17
17
  *
18
18
  * @internal
19
19
  */
20
- export const requests: { [key in keyof typeof EResourceType]: (args: FetchArgs | PostArgs) => AxiosRequestConfig } = {
20
+ export const requests: { [key in keyof typeof EResourceType]: (args: IFetchArgs | IPostArgs) => AxiosRequestConfig } = {
21
21
  /* eslint-disable @typescript-eslint/naming-convention */
22
- LIST_MEMBERS: (args: FetchArgs) => request.list.members(args.id!, args.count, args.cursor),
23
- LIST_TWEETS: (args: FetchArgs) => request.list.tweets(args.id!, args.count, args.cursor),
22
+ LIST_MEMBERS: (args: IFetchArgs) => request.list.members(args.id!, args.count, args.cursor),
23
+ LIST_TWEETS: (args: IFetchArgs) => request.list.tweets(args.id!, args.count, args.cursor),
24
24
 
25
- MEDIA_UPLOAD_APPEND: (args: PostArgs) => request.media.appendUpload(args.upload!.id!, args.upload!.media!),
26
- MEDIA_UPLOAD_FINALIZE: (args: PostArgs) => request.media.finalizeUpload(args.upload!.id!),
27
- MEDIA_UPLOAD_INITIALIZE: (args: PostArgs) => request.media.initializeUpload(args.upload!.size!),
25
+ MEDIA_UPLOAD_APPEND: (args: IPostArgs) => request.media.appendUpload(args.upload!.id!, args.upload!.media!),
26
+ MEDIA_UPLOAD_FINALIZE: (args: IPostArgs) => request.media.finalizeUpload(args.upload!.id!),
27
+ MEDIA_UPLOAD_INITIALIZE: (args: IPostArgs) => request.media.initializeUpload(args.upload!.size!),
28
28
 
29
- TWEET_DETAILS: (args: FetchArgs) => request.tweet.details(args.id!),
30
- TWEET_DETAILS_ALT: (args: FetchArgs) => request.tweet.replies(args.id!),
31
- TWEET_LIKE: (args: PostArgs) => request.tweet.like(args.id!),
32
- TWEET_POST: (args: PostArgs) => request.tweet.post(args.tweet!),
33
- TWEET_RETWEET: (args: PostArgs) => request.tweet.retweet(args.id!),
34
- TWEET_RETWEETERS: (args: FetchArgs) => request.tweet.retweeters(args.id!, args.count, args.cursor),
35
- TWEET_SCHEDULE: (args: PostArgs) => request.tweet.schedule(args.tweet!, args.tweet!.scheduleFor!),
36
- TWEET_SEARCH: (args: FetchArgs) => request.tweet.search(args.filter!, args.count, args.cursor),
37
- TWEET_UNLIKE: (args: PostArgs) => request.tweet.unlike(args.id!),
38
- TWEET_UNPOST: (args: PostArgs) => request.tweet.unpost(args.id!),
39
- TWEET_UNRETWEET: (args: PostArgs) => request.tweet.unretweet(args.id!),
40
- TWEET_UNSCHEDULE: (args: PostArgs) => request.tweet.unschedule(args.id!),
29
+ TWEET_DETAILS: (args: IFetchArgs) => request.tweet.details(args.id!),
30
+ TWEET_DETAILS_ALT: (args: IFetchArgs) => request.tweet.replies(args.id!),
31
+ TWEET_LIKE: (args: IPostArgs) => request.tweet.like(args.id!),
32
+ TWEET_POST: (args: IPostArgs) => request.tweet.post(args.tweet!),
33
+ TWEET_REPLIES: (args: IFetchArgs) => request.tweet.replies(args.id!, args.cursor),
34
+ TWEET_RETWEET: (args: IPostArgs) => request.tweet.retweet(args.id!),
35
+ TWEET_RETWEETERS: (args: IFetchArgs) => request.tweet.retweeters(args.id!, args.count, args.cursor),
36
+ TWEET_SCHEDULE: (args: IPostArgs) => request.tweet.schedule(args.tweet!),
37
+ TWEET_SEARCH: (args: IFetchArgs) => request.tweet.search(args.filter!, args.count, args.cursor),
38
+ TWEET_UNLIKE: (args: IPostArgs) => request.tweet.unlike(args.id!),
39
+ TWEET_UNPOST: (args: IPostArgs) => request.tweet.unpost(args.id!),
40
+ TWEET_UNRETWEET: (args: IPostArgs) => request.tweet.unretweet(args.id!),
41
+ TWEET_UNSCHEDULE: (args: IPostArgs) => request.tweet.unschedule(args.id!),
41
42
 
42
- USER_BOOKMARKS: (args: FetchArgs) => request.user.bookmarks(args.count, args.cursor),
43
- USER_DETAILS_BY_USERNAME: (args: FetchArgs) => request.user.detailsByUsername(args.id!),
44
- USER_DETAILS_BY_ID: (args: FetchArgs) => request.user.detailsById(args.id!),
45
- USER_FEED_FOLLOWED: (args: FetchArgs) => request.user.followed(args.count, args.cursor),
46
- USER_FEED_RECOMMENDED: (args: FetchArgs) => request.user.recommended(args.count, args.cursor),
47
- USER_FOLLOW: (args: PostArgs) => request.user.follow(args.id!),
48
- USER_FOLLOWING: (args: FetchArgs) => request.user.following(args.id!, args.count, args.cursor),
49
- USER_FOLLOWERS: (args: FetchArgs) => request.user.followers(args.id!, args.count, args.cursor),
50
- USER_HIGHLIGHTS: (args: FetchArgs) => request.user.highlights(args.id!, args.count, args.cursor),
51
- USER_LIKES: (args: FetchArgs) => request.user.likes(args.id!, args.count, args.cursor),
52
- USER_MEDIA: (args: FetchArgs) => request.user.media(args.id!, args.count, args.cursor),
53
- USER_NOTIFICATIONS: (args: FetchArgs) => request.user.notifications(args.count, args.cursor),
54
- USER_SUBSCRIPTIONS: (args: FetchArgs) => request.user.subscriptions(args.id!, args.count, args.cursor),
55
- USER_TIMELINE: (args: FetchArgs) => request.user.tweets(args.id!, args.count, args.cursor),
56
- USER_TIMELINE_AND_REPLIES: (args: FetchArgs) => request.user.tweetsAndReplies(args.id!, args.count, args.cursor),
57
- USER_UNFOLLOW: (args: PostArgs) => request.user.unfollow(args.id!),
43
+ USER_BOOKMARKS: (args: IFetchArgs) => request.user.bookmarks(args.count, args.cursor),
44
+ USER_DETAILS_BY_USERNAME: (args: IFetchArgs) => request.user.detailsByUsername(args.id!),
45
+ USER_DETAILS_BY_ID: (args: IFetchArgs) => request.user.detailsById(args.id!),
46
+ USER_FEED_FOLLOWED: (args: IFetchArgs) => request.user.followed(args.count, args.cursor),
47
+ USER_FEED_RECOMMENDED: (args: IFetchArgs) => request.user.recommended(args.count, args.cursor),
48
+ USER_FOLLOW: (args: IPostArgs) => request.user.follow(args.id!),
49
+ USER_FOLLOWING: (args: IFetchArgs) => request.user.following(args.id!, args.count, args.cursor),
50
+ USER_FOLLOWERS: (args: IFetchArgs) => request.user.followers(args.id!, args.count, args.cursor),
51
+ USER_HIGHLIGHTS: (args: IFetchArgs) => request.user.highlights(args.id!, args.count, args.cursor),
52
+ USER_LIKES: (args: IFetchArgs) => request.user.likes(args.id!, args.count, args.cursor),
53
+ USER_MEDIA: (args: IFetchArgs) => request.user.media(args.id!, args.count, args.cursor),
54
+ USER_NOTIFICATIONS: (args: IFetchArgs) => request.user.notifications(args.count, args.cursor),
55
+ USER_SUBSCRIPTIONS: (args: IFetchArgs) => request.user.subscriptions(args.id!, args.count, args.cursor),
56
+ USER_TIMELINE: (args: IFetchArgs) => request.user.tweets(args.id!, args.count, args.cursor),
57
+ USER_TIMELINE_AND_REPLIES: (args: IFetchArgs) => request.user.tweetsAndReplies(args.id!, args.count, args.cursor),
58
+ USER_UNFOLLOW: (args: IPostArgs) => request.user.unfollow(args.id!),
58
59
  /* eslint-enable @typescript-eslint/naming-convention */
59
60
  };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The different types of authentication for authenticating against Twitter.
3
+ */
4
+ export enum EAuthenticationType {
5
+ GUEST = 'GUEST',
6
+ USER = 'USER',
7
+ LOGIN = 'LOGIN',
8
+ }
9
+
10
+ /**
11
+ * Different types of error messages related to authentication returned by services.
12
+ */
13
+ export enum EAuthenticationErrors {
14
+ NOT_AUTHENTICATED = 'Cannot fetch this data without authentication',
15
+ INVALID_EMAIL = 'No Twitter account found for the given email address',
16
+ INVALID_USERNAME = 'Incorrect username given for the given Twitter account',
17
+ INVALID_PASSWORD = 'Incorrect password given for the given Twitter account',
18
+ AUTHENTICATION_FAILED = 'Failed to authenticate using the given account Credentials',
19
+ }
package/src/enums/Data.ts CHANGED
@@ -8,3 +8,16 @@ export enum EBaseType {
8
8
  TWEET = 'Tweet',
9
9
  USER = 'User',
10
10
  }
11
+
12
+ /**
13
+ * The different types of notifications.
14
+ *
15
+ * @public
16
+ */
17
+ export enum ENotificationType {
18
+ RECOMMENDATION = 'RECOMMENDATION',
19
+ INFORMATION = 'INFORMATION',
20
+ LIVE = 'LIVE',
21
+ ALERT = 'ALERT',
22
+ UNDEFINED = 'UNDEFINED',
23
+ }
@@ -18,6 +18,7 @@ export enum EResourceType {
18
18
  TWEET_DETAILS_ALT = 'TWEET_DETAILS_ALT',
19
19
  TWEET_LIKE = 'TWEET_LIKE',
20
20
  TWEET_POST = 'TWEET_POST',
21
+ TWEET_REPLIES = 'TWEET_REPLIES',
21
22
  TWEET_RETWEET = 'TWEET_RETWEET',
22
23
  TWEET_RETWEETERS = 'TWEET_RETWEETERS',
23
24
  TWEET_SCHEDULE = 'TWEET_SCHEDULE',
@@ -24,7 +24,7 @@ export function findByFilter<T>(data: NonNullable<unknown>, key: string, value:
24
24
  * Therefore, map(item =\> findByFilter(.......)) returns an array of arrays.
25
25
  * Therefore, using ... operator to spread the 2-D array in 1-D array.
26
26
  */
27
- res = res.concat(...data.map((item) => findByFilter<T>(item as NonNullable<unknown>, key, value)));
27
+ res = res.concat(...data.map((item: NonNullable<unknown>) => findByFilter<T>(item, key, value)));
28
28
  }
29
29
  // If the data is an object
30
30
  else if (data != null && typeof data == 'object') {
package/src/index.ts CHANGED
@@ -19,13 +19,12 @@ export * from './models/data/User';
19
19
 
20
20
  // ERROR MODELS
21
21
  export * from './models/errors/ApiError';
22
- export * from './models/errors/DataValidationError';
23
22
  export * from './models/errors/HttpError';
24
23
  export * from './models/errors/RettiwtError';
25
24
  export * from './models/errors/TimeoutError';
26
25
 
27
26
  // SERVICES
28
- export * from './services/public/AuthService';
27
+ export * from './services/internal/AuthService';
29
28
  export * from './services/public/FetcherService';
30
29
  export * from './services/public/TweetService';
31
30
  export * from './services/public/UserService';
@@ -1,495 +1,29 @@
1
- import {
2
- IsArray,
3
- IsBoolean,
4
- IsDate,
5
- IsEmpty,
6
- IsNotEmpty,
7
- IsNumber,
8
- IsNumberString,
9
- IsObject,
10
- IsOptional,
11
- IsString,
12
- Max,
13
- Min,
14
- validateSync,
15
- } from 'class-validator';
16
-
17
- import { ESearchResultType, TweetFilter as TweetFilterCore } from 'rettiwt-core';
1
+ import { ESearchResultType, TweetFilter } from 'rettiwt-core';
18
2
 
19
3
  import { EResourceType } from '../../enums/Resource';
20
- import { DataValidationError } from '../errors/DataValidationError';
4
+ import { IFetchArgs } from '../../types/args/FetchArgs';
21
5
 
22
6
  /**
23
7
  * Options specifying the data that is to be fetched.
24
8
  *
25
9
  * @public
26
10
  */
27
- export class FetchArgs {
28
- /**
29
- * The number of data items to fetch.
30
- *
31
- * @remarks
32
- * - Works only for cursored resources.
33
- * - Must be \<= 20 for:
34
- * - {@link EResourceType.USER_TIMELINE}
35
- * - {@link EResourceType.USER_TIMELINE}
36
- * - {@link EResourceType.USER_TIMELINE_AND_REPLIES}
37
- * - Must be \<= 100 for all other cursored resources.
38
- * - Due a bug on Twitter's end, count does not work for {@link EResourceType.USER_FOLLOWERS} and {@link EResourceType.USER_FOLLOWING}.
39
- * - Has not effect for:
40
- * - {@link EResourceType.USER_FEED_FOLLOWED}
41
- * - {@link EResourceType.USER_FEED_RECOMMENDED}
42
- */
43
- @IsEmpty({
44
- groups: [
45
- EResourceType.TWEET_DETAILS,
46
- EResourceType.TWEET_DETAILS_ALT,
47
- EResourceType.USER_DETAILS_BY_ID,
48
- EResourceType.USER_DETAILS_BY_USERNAME,
49
- EResourceType.USER_FEED_FOLLOWED,
50
- EResourceType.USER_FEED_RECOMMENDED,
51
- ],
52
- })
53
- @IsOptional({
54
- groups: [
55
- EResourceType.LIST_MEMBERS,
56
- EResourceType.LIST_TWEETS,
57
- EResourceType.TWEET_RETWEETERS,
58
- EResourceType.TWEET_SEARCH,
59
- EResourceType.USER_BOOKMARKS,
60
- EResourceType.USER_FOLLOWERS,
61
- EResourceType.USER_FOLLOWING,
62
- EResourceType.USER_HIGHLIGHTS,
63
- EResourceType.USER_LIKES,
64
- EResourceType.USER_MEDIA,
65
- EResourceType.USER_NOTIFICATIONS,
66
- EResourceType.USER_SUBSCRIPTIONS,
67
- EResourceType.USER_TIMELINE,
68
- EResourceType.USER_TIMELINE_AND_REPLIES,
69
- ],
70
- })
71
- @Min(1, {
72
- groups: [
73
- EResourceType.LIST_MEMBERS,
74
- EResourceType.LIST_TWEETS,
75
- EResourceType.TWEET_RETWEETERS,
76
- EResourceType.TWEET_SEARCH,
77
- EResourceType.USER_BOOKMARKS,
78
- EResourceType.USER_FOLLOWERS,
79
- EResourceType.USER_FOLLOWING,
80
- EResourceType.USER_HIGHLIGHTS,
81
- EResourceType.USER_LIKES,
82
- EResourceType.USER_MEDIA,
83
- EResourceType.USER_NOTIFICATIONS,
84
- EResourceType.USER_SUBSCRIPTIONS,
85
- EResourceType.USER_TIMELINE,
86
- EResourceType.USER_TIMELINE_AND_REPLIES,
87
- ],
88
- })
89
- @Max(100, {
90
- groups: [
91
- EResourceType.LIST_MEMBERS,
92
- EResourceType.LIST_TWEETS,
93
- EResourceType.TWEET_RETWEETERS,
94
- EResourceType.USER_BOOKMARKS,
95
- EResourceType.USER_FOLLOWERS,
96
- EResourceType.USER_FOLLOWING,
97
- EResourceType.USER_HIGHLIGHTS,
98
- EResourceType.USER_LIKES,
99
- EResourceType.USER_MEDIA,
100
- EResourceType.USER_SUBSCRIPTIONS,
101
- ],
102
- })
103
- @Max(40, {
104
- groups: [EResourceType.USER_NOTIFICATIONS],
105
- })
106
- @Max(20, {
107
- groups: [EResourceType.TWEET_SEARCH, EResourceType.USER_TIMELINE, EResourceType.USER_TIMELINE_AND_REPLIES],
108
- })
11
+ export class FetchArgs implements IFetchArgs {
109
12
  public count?: number;
110
-
111
- /**
112
- * The cursor to the batch of data to fetch.
113
- *
114
- * @remarks
115
- * - May be used for cursored resources.
116
- * - Has no effect for other resources.
117
- */
118
- @IsEmpty({
119
- groups: [
120
- EResourceType.TWEET_DETAILS,
121
- EResourceType.TWEET_DETAILS_ALT,
122
- EResourceType.USER_DETAILS_BY_ID,
123
- EResourceType.USER_DETAILS_BY_USERNAME,
124
- ],
125
- })
126
- @IsOptional({
127
- groups: [
128
- EResourceType.LIST_MEMBERS,
129
- EResourceType.LIST_TWEETS,
130
- EResourceType.TWEET_RETWEETERS,
131
- EResourceType.TWEET_SEARCH,
132
- EResourceType.USER_BOOKMARKS,
133
- EResourceType.USER_FEED_FOLLOWED,
134
- EResourceType.USER_FEED_RECOMMENDED,
135
- EResourceType.USER_FOLLOWING,
136
- EResourceType.USER_FOLLOWERS,
137
- EResourceType.USER_HIGHLIGHTS,
138
- EResourceType.USER_LIKES,
139
- EResourceType.USER_MEDIA,
140
- EResourceType.USER_NOTIFICATIONS,
141
- EResourceType.USER_SUBSCRIPTIONS,
142
- EResourceType.USER_TIMELINE,
143
- EResourceType.USER_TIMELINE_AND_REPLIES,
144
- ],
145
- })
146
- @IsString({
147
- groups: [
148
- EResourceType.LIST_MEMBERS,
149
- EResourceType.LIST_TWEETS,
150
- EResourceType.TWEET_RETWEETERS,
151
- EResourceType.TWEET_SEARCH,
152
- EResourceType.USER_BOOKMARKS,
153
- EResourceType.USER_FEED_FOLLOWED,
154
- EResourceType.USER_FEED_RECOMMENDED,
155
- EResourceType.USER_FOLLOWING,
156
- EResourceType.USER_FOLLOWERS,
157
- EResourceType.USER_HIGHLIGHTS,
158
- EResourceType.USER_LIKES,
159
- EResourceType.USER_MEDIA,
160
- EResourceType.USER_NOTIFICATIONS,
161
- EResourceType.USER_SUBSCRIPTIONS,
162
- EResourceType.USER_TIMELINE,
163
- EResourceType.USER_TIMELINE_AND_REPLIES,
164
- ],
165
- })
166
13
  public cursor?: string;
167
-
168
- /**
169
- * The filter for searching tweets.
170
- *
171
- * @remarks
172
- * Required when searching for tweets using {@link EResourceType.TWEET_SEARCH}.
173
- */
174
- @IsEmpty({
175
- groups: [
176
- EResourceType.LIST_MEMBERS,
177
- EResourceType.LIST_TWEETS,
178
- EResourceType.TWEET_DETAILS,
179
- EResourceType.TWEET_DETAILS_ALT,
180
- EResourceType.TWEET_RETWEETERS,
181
- EResourceType.USER_BOOKMARKS,
182
- EResourceType.USER_DETAILS_BY_USERNAME,
183
- EResourceType.USER_DETAILS_BY_ID,
184
- EResourceType.USER_FEED_FOLLOWED,
185
- EResourceType.USER_FEED_RECOMMENDED,
186
- EResourceType.USER_FOLLOWING,
187
- EResourceType.USER_FOLLOWERS,
188
- EResourceType.USER_HIGHLIGHTS,
189
- EResourceType.USER_LIKES,
190
- EResourceType.USER_MEDIA,
191
- EResourceType.USER_NOTIFICATIONS,
192
- EResourceType.USER_SUBSCRIPTIONS,
193
- EResourceType.USER_TIMELINE,
194
- EResourceType.USER_TIMELINE_AND_REPLIES,
195
- ],
196
- })
197
- @IsNotEmpty({ groups: [EResourceType.TWEET_SEARCH] })
198
- @IsObject({ groups: [EResourceType.TWEET_SEARCH] })
199
14
  public filter?: TweetFilter;
200
-
201
- /**
202
- * The id of the target resource.
203
- *
204
- * @remarks
205
- * - Required for all resources except {@link EResourceType.TWEET_SEARCH} and {@link EResourceType.USER_TIMELINE_RECOMMENDED}.
206
- * - For {@link EResourceType.USER_DETAILS_BY_USERNAME}, can be alphanumeric, while for others, is strictly numeric.
207
- */
208
- @IsEmpty({
209
- groups: [
210
- EResourceType.USER_BOOKMARKS,
211
- EResourceType.USER_FEED_FOLLOWED,
212
- EResourceType.USER_FEED_RECOMMENDED,
213
- EResourceType.USER_NOTIFICATIONS,
214
- ],
215
- })
216
- @IsNotEmpty({
217
- groups: [
218
- EResourceType.LIST_MEMBERS,
219
- EResourceType.LIST_TWEETS,
220
- EResourceType.TWEET_DETAILS,
221
- EResourceType.TWEET_DETAILS_ALT,
222
- EResourceType.TWEET_RETWEETERS,
223
- EResourceType.USER_DETAILS_BY_USERNAME,
224
- EResourceType.USER_DETAILS_BY_ID,
225
- EResourceType.USER_FOLLOWERS,
226
- EResourceType.USER_FOLLOWING,
227
- EResourceType.USER_HIGHLIGHTS,
228
- EResourceType.USER_LIKES,
229
- EResourceType.USER_MEDIA,
230
- EResourceType.USER_SUBSCRIPTIONS,
231
- EResourceType.USER_TIMELINE,
232
- EResourceType.USER_TIMELINE_AND_REPLIES,
233
- ],
234
- })
235
- @IsString({
236
- groups: [
237
- EResourceType.LIST_MEMBERS,
238
- EResourceType.LIST_TWEETS,
239
- EResourceType.TWEET_DETAILS,
240
- EResourceType.TWEET_DETAILS_ALT,
241
- EResourceType.TWEET_RETWEETERS,
242
- EResourceType.USER_DETAILS_BY_USERNAME,
243
- EResourceType.USER_DETAILS_BY_ID,
244
- EResourceType.USER_FOLLOWING,
245
- EResourceType.USER_FOLLOWERS,
246
- EResourceType.USER_HIGHLIGHTS,
247
- EResourceType.USER_LIKES,
248
- EResourceType.USER_MEDIA,
249
- EResourceType.USER_SUBSCRIPTIONS,
250
- EResourceType.USER_TIMELINE,
251
- EResourceType.USER_TIMELINE_AND_REPLIES,
252
- ],
253
- })
254
- @IsNumberString(undefined, {
255
- groups: [
256
- EResourceType.LIST_MEMBERS,
257
- EResourceType.LIST_TWEETS,
258
- EResourceType.TWEET_DETAILS,
259
- EResourceType.TWEET_DETAILS_ALT,
260
- EResourceType.TWEET_RETWEETERS,
261
- EResourceType.USER_DETAILS_BY_ID,
262
- EResourceType.USER_FOLLOWERS,
263
- EResourceType.USER_FOLLOWING,
264
- EResourceType.USER_HIGHLIGHTS,
265
- EResourceType.USER_LIKES,
266
- EResourceType.USER_MEDIA,
267
- EResourceType.USER_SUBSCRIPTIONS,
268
- EResourceType.USER_TIMELINE,
269
- EResourceType.USER_TIMELINE_AND_REPLIES,
270
- ],
271
- })
272
15
  public id?: string;
273
-
274
- /**
275
- * The type of search results to fetch. Can be one of:
276
- * - {@link EResourceType.LATEST}, for latest search results.
277
- * - {@link EResourceType.TOP}, for top search results.
278
- *
279
- * @defaultValue {@link ESearchResultType.LATEST}.
280
- *
281
- * @remarks
282
- * - Applicable only for {@link EResourceType.TWEET_SEARCH}.
283
- */
284
- @IsEmpty({
285
- groups: [
286
- EResourceType.LIST_MEMBERS,
287
- EResourceType.LIST_TWEETS,
288
- EResourceType.TWEET_DETAILS,
289
- EResourceType.TWEET_DETAILS_ALT,
290
- EResourceType.TWEET_RETWEETERS,
291
- EResourceType.USER_BOOKMARKS,
292
- EResourceType.USER_DETAILS_BY_USERNAME,
293
- EResourceType.USER_DETAILS_BY_ID,
294
- EResourceType.USER_FEED_FOLLOWED,
295
- EResourceType.USER_FEED_RECOMMENDED,
296
- EResourceType.USER_FOLLOWING,
297
- EResourceType.USER_FOLLOWERS,
298
- EResourceType.USER_HIGHLIGHTS,
299
- EResourceType.USER_LIKES,
300
- EResourceType.USER_MEDIA,
301
- EResourceType.USER_NOTIFICATIONS,
302
- EResourceType.USER_SUBSCRIPTIONS,
303
- EResourceType.USER_TIMELINE,
304
- EResourceType.USER_TIMELINE_AND_REPLIES,
305
- ],
306
- })
307
- @IsOptional({ groups: [EResourceType.TWEET_SEARCH] })
308
16
  public results?: ESearchResultType;
309
17
 
310
18
  /**
311
19
  * @param resource - The resource to be fetched.
312
20
  * @param args - Additional user-defined arguments for fetching the resource.
313
21
  */
314
- public constructor(resource: EResourceType, args: FetchArgs) {
22
+ public constructor(resource: EResourceType, args: IFetchArgs) {
315
23
  this.id = args.id;
316
24
  this.count = args.count;
317
25
  this.cursor = args.cursor;
318
26
  this.filter = args.filter ? new TweetFilter(args.filter) : undefined;
319
27
  this.results = args.results;
320
-
321
- // Validating this object
322
- const validationResult = validateSync(this, { groups: [resource] });
323
-
324
- // If valiation error occured
325
- if (validationResult.length) {
326
- throw new DataValidationError(validationResult);
327
- }
328
- }
329
- }
330
-
331
- /**
332
- * The filter to be used for searching tweets.
333
- *
334
- * @public
335
- */
336
- export class TweetFilter extends TweetFilterCore {
337
- /** The date upto which tweets are to be searched. */
338
- @IsOptional()
339
- @IsDate()
340
- public endDate?: Date;
341
-
342
- /** The list of words to exclude from search. */
343
- @IsOptional()
344
- @IsArray()
345
- @IsString({ each: true })
346
- public excludeWords?: string[];
347
-
348
- /**
349
- * The list of usernames whose tweets are to be searched.
350
- *
351
- * @remarks
352
- * '\@' must be excluded from the username!
353
- */
354
- @IsOptional()
355
- @IsArray()
356
- @IsString({ each: true })
357
- public fromUsers?: string[];
358
-
359
- /**
360
- * The list of hashtags to search.
361
- *
362
- * @remarks
363
- * '#' must be excluded from the hashtag!
364
- */
365
- @IsOptional()
366
- @IsArray()
367
- @IsString({ each: true })
368
- public hashtags?: string[];
369
-
370
- /** The exact phrase to search. */
371
- @IsOptional()
372
- @IsString()
373
- public includePhrase?: string;
374
-
375
- /** The list of words to search. */
376
- @IsOptional()
377
- @IsArray()
378
- @IsString({ each: true })
379
- public includeWords?: string[];
380
-
381
- /** The language of the tweets to search. */
382
- @IsOptional()
383
- @IsString()
384
- public language?: string;
385
-
386
- /**
387
- * Whether to fetch tweets that are links or not.
388
- *
389
- * @defaultValue true
390
- */
391
- @IsOptional()
392
- @IsBoolean()
393
- public links?: boolean;
394
-
395
- /** The list from which tweets are to be searched. */
396
- @IsOptional()
397
- @IsNumberString()
398
- public list?: string;
399
-
400
- /** The id of the tweet, before which the tweets are to be searched. */
401
- @IsOptional()
402
- @IsNumberString()
403
- public maxId?: string;
404
-
405
- /**
406
- * The list of username mentioned in the tweets to search.
407
- *
408
- * @remarks
409
- * '\@' must be excluded from the username!
410
- */
411
- @IsOptional()
412
- @IsArray()
413
- @IsString({ each: true })
414
- public mentions?: string[];
415
-
416
- /** The minimun number of likes to search by. */
417
- @IsOptional()
418
- @IsNumber()
419
- public minLikes?: number;
420
-
421
- /** The minimum number of replies to search by. */
422
- @IsOptional()
423
- @IsNumber()
424
- public minReplies?: number;
425
-
426
- /** The minimum number of retweets to search by. */
427
- @IsOptional()
428
- @IsNumber()
429
- public minRetweets?: number;
430
-
431
- /** The optional words to search. */
432
- @IsOptional()
433
- @IsArray()
434
- @IsString({ each: true })
435
- public optionalWords?: string[];
436
-
437
- /** The id of the tweet which is quoted in the tweets to search. */
438
- @IsOptional()
439
- @IsNumberString()
440
- public quoted?: string;
441
-
442
- /**
443
- * Whether to fetch tweets that are replies or not.
444
- *
445
- * @defaultValue true
446
- */
447
- @IsOptional()
448
- @IsBoolean()
449
- public replies?: boolean;
450
-
451
- /** The id of the tweet, after which the tweets are to be searched. */
452
- @IsOptional()
453
- @IsNumberString()
454
- public sinceId?: string;
455
-
456
- /** The date starting from which tweets are to be searched. */
457
- @IsOptional()
458
- @IsDate()
459
- public startDate?: Date;
460
-
461
- /**
462
- * The list of username to whom the tweets to be searched, are adressed.
463
- *
464
- * @remarks
465
- * '\@' must be excluded from the username!
466
- */
467
- @IsOptional()
468
- @IsArray()
469
- @IsString({ each: true })
470
- public toUsers?: string[];
471
-
472
- /**
473
- * Whether to fetch top or not.
474
- *
475
- * @defaultValue true
476
- */
477
- @IsOptional()
478
- @IsBoolean()
479
- public top?: boolean;
480
-
481
- /**
482
- * @param filter - The filter to use for searching tweets.
483
- */
484
- public constructor(filter: TweetFilter) {
485
- super(filter);
486
-
487
- // Validating this object
488
- const validationResult = validateSync(this);
489
-
490
- // If valiation error occured
491
- if (validationResult.length) {
492
- throw new DataValidationError(validationResult);
493
- }
494
28
  }
495
29
  }