rettiwt-api 5.0.0-alpha.0 → 5.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -3
- package/.github/workflows/documentation.yml +1 -1
- package/.github/workflows/publish-alpha.yml +1 -1
- package/.github/workflows/publish.yml +1 -1
- package/.prettierignore +1 -1
- package/.tool-versions +1 -1
- package/README.md +100 -100
- package/dist/Rettiwt.d.ts +10 -3
- package/dist/Rettiwt.js +31 -12
- package/dist/Rettiwt.js.map +1 -1
- package/dist/cli.js +8 -11
- package/dist/cli.js.map +1 -1
- package/dist/collections/Extractors.d.ts +36 -2
- package/dist/collections/Extractors.js +41 -69
- package/dist/collections/Extractors.js.map +1 -1
- package/dist/collections/Groups.js +5 -1
- package/dist/collections/Groups.js.map +1 -1
- package/dist/collections/Requests.d.ts +3 -3
- package/dist/collections/Requests.js +41 -40
- package/dist/collections/Requests.js.map +1 -1
- package/dist/commands/List.js +21 -78
- package/dist/commands/List.js.map +1 -1
- package/dist/commands/Tweet.js +214 -373
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/commands/User.js +138 -305
- package/dist/commands/User.js.map +1 -1
- package/dist/enums/Authentication.d.ts +10 -0
- package/dist/enums/Authentication.js +15 -0
- package/dist/enums/Authentication.js.map +1 -0
- package/dist/enums/Data.d.ts +3 -3
- package/dist/enums/Data.js +3 -3
- package/dist/enums/Media.d.ts +10 -0
- package/dist/enums/Media.js +15 -0
- package/dist/enums/Media.js.map +1 -0
- package/dist/enums/Notification.d.ts +12 -0
- package/dist/enums/Notification.js +17 -0
- package/dist/enums/Notification.js.map +1 -0
- package/dist/enums/Resource.d.ts +4 -0
- package/dist/enums/Resource.js +4 -0
- package/dist/enums/Resource.js.map +1 -1
- package/dist/enums/raw/Analytics.d.ts +28 -0
- package/dist/enums/raw/Analytics.js +34 -0
- package/dist/enums/raw/Analytics.js.map +1 -0
- package/dist/enums/raw/Media.d.ts +10 -0
- package/dist/enums/raw/Media.js +15 -0
- package/dist/enums/raw/Media.js.map +1 -0
- package/dist/enums/raw/Notification.d.ts +11 -0
- package/dist/enums/raw/Notification.js +16 -0
- package/dist/enums/raw/Notification.js.map +1 -0
- package/dist/enums/raw/Tweet.d.ts +9 -0
- package/dist/enums/raw/Tweet.js +14 -0
- package/dist/enums/raw/Tweet.js.map +1 -0
- package/dist/helper/CliUtils.js +1 -2
- package/dist/helper/CliUtils.js.map +1 -1
- package/dist/helper/JsonUtils.js +6 -11
- package/dist/helper/JsonUtils.js.map +1 -1
- package/dist/helper/TidUtils.d.ts +2 -0
- package/dist/helper/TidUtils.js +162 -0
- package/dist/helper/TidUtils.js.map +1 -0
- package/dist/index.d.ts +75 -5
- package/dist/index.js +26 -6
- package/dist/index.js.map +1 -1
- package/dist/models/RettiwtConfig.d.ts +28 -0
- package/dist/models/RettiwtConfig.js +55 -0
- package/dist/models/RettiwtConfig.js.map +1 -0
- package/dist/models/args/FetchArgs.d.ts +16 -102
- package/dist/models/args/FetchArgs.js +105 -407
- package/dist/models/args/FetchArgs.js.map +1 -1
- package/dist/models/args/PostArgs.d.ts +16 -73
- package/dist/models/args/PostArgs.js +43 -236
- package/dist/models/args/PostArgs.js.map +1 -1
- package/dist/models/auth/AuthCookie.d.ts +21 -0
- package/dist/models/auth/AuthCookie.js +55 -0
- package/dist/models/auth/AuthCookie.js.map +1 -0
- package/dist/models/auth/AuthCredential.d.ts +30 -0
- package/dist/models/auth/AuthCredential.js +78 -0
- package/dist/models/auth/AuthCredential.js.map +1 -0
- package/dist/models/data/CursoredData.d.ts +5 -15
- package/dist/models/data/CursoredData.js +25 -32
- package/dist/models/data/CursoredData.js.map +1 -1
- package/dist/models/data/List.d.ts +7 -9
- package/dist/models/data/List.js +24 -4
- package/dist/models/data/List.js.map +1 -1
- package/dist/models/data/Notification.d.ts +10 -24
- package/dist/models/data/Notification.js +38 -36
- package/dist/models/data/Notification.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +34 -31
- package/dist/models/data/Tweet.js +186 -112
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.d.ts +19 -23
- package/dist/models/data/User.js +92 -32
- package/dist/models/data/User.js.map +1 -1
- package/dist/models/errors/ApiError.js +8 -24
- package/dist/models/errors/ApiError.js.map +1 -1
- package/dist/models/errors/HttpError.js +8 -24
- package/dist/models/errors/HttpError.js.map +1 -1
- package/dist/models/errors/RettiwtError.d.ts +3 -2
- package/dist/models/errors/RettiwtError.js +8 -25
- package/dist/models/errors/RettiwtError.js.map +1 -1
- package/dist/models/errors/TimeoutError.js +5 -22
- package/dist/models/errors/TimeoutError.js.map +1 -1
- package/dist/models/params/Variables.d.ts +41 -0
- package/dist/models/params/Variables.js +61 -0
- package/dist/models/params/Variables.js.map +1 -0
- package/dist/requests/List.d.ts +24 -0
- package/dist/requests/List.js +122 -0
- package/dist/requests/List.js.map +1 -0
- package/dist/requests/Media.d.ts +21 -0
- package/dist/requests/Media.js +70 -0
- package/dist/requests/Media.js.map +1 -0
- package/dist/requests/Tweet.d.ts +75 -0
- package/dist/requests/Tweet.js +480 -0
- package/dist/requests/Tweet.js.map +1 -0
- package/dist/requests/User.d.ts +111 -0
- package/dist/requests/User.js +762 -0
- package/dist/requests/User.js.map +1 -0
- package/dist/services/internal/AuthService.d.ts +60 -0
- package/dist/services/internal/AuthService.js +106 -0
- package/dist/services/internal/AuthService.js.map +1 -0
- package/dist/services/internal/ErrorService.js +38 -40
- package/dist/services/internal/ErrorService.js.map +1 -1
- package/dist/services/internal/LogService.d.ts +0 -6
- package/dist/services/internal/LogService.js +12 -32
- package/dist/services/internal/LogService.js.map +1 -1
- package/dist/services/internal/TidService.d.ts +44 -0
- package/dist/services/internal/TidService.js +162 -0
- package/dist/services/internal/TidService.js.map +1 -0
- package/dist/services/public/FetcherService.d.ts +22 -19
- package/dist/services/public/FetcherService.js +126 -153
- package/dist/services/public/FetcherService.js.map +1 -1
- package/dist/services/public/ListService.d.ts +2 -2
- package/dist/services/public/ListService.js +31 -100
- package/dist/services/public/ListService.js.map +1 -1
- package/dist/services/public/TweetService.d.ts +63 -10
- package/dist/services/public/TweetService.js +255 -387
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.d.ts +4 -4
- package/dist/services/public/UserService.js +199 -386
- package/dist/services/public/UserService.js.map +1 -1
- package/dist/types/RettiwtConfig.d.ts +17 -10
- package/dist/types/args/FetchArgs.d.ts +123 -0
- package/dist/types/{ReturnTypes.js → args/FetchArgs.js} +1 -1
- package/dist/types/args/FetchArgs.js.map +1 -0
- package/dist/types/args/PostArgs.d.ts +100 -0
- package/dist/types/args/PostArgs.js +3 -0
- package/dist/types/args/PostArgs.js.map +1 -0
- package/dist/types/auth/AuthCookie.d.ts +15 -0
- package/dist/types/auth/AuthCookie.js +3 -0
- package/dist/types/auth/AuthCookie.js.map +1 -0
- package/dist/types/auth/AuthCredential.d.ts +23 -0
- package/dist/types/auth/AuthCredential.js +3 -0
- package/dist/types/auth/AuthCredential.js.map +1 -0
- package/dist/types/auth/TidDynamicArgs.d.ts +10 -0
- package/dist/types/auth/TidDynamicArgs.js +3 -0
- package/dist/types/auth/TidDynamicArgs.js.map +1 -0
- package/dist/types/auth/TidHeader.d.ts +8 -0
- package/dist/types/auth/TidHeader.js +3 -0
- package/dist/types/auth/TidHeader.js.map +1 -0
- package/dist/types/auth/TidParams.d.ts +27 -0
- package/dist/types/auth/TidParams.js +3 -0
- package/dist/types/auth/TidParams.js.map +1 -0
- package/dist/types/auth/TidProvider.d.ts +18 -0
- package/dist/types/auth/TidProvider.js +3 -0
- package/dist/types/auth/TidProvider.js.map +1 -0
- package/dist/types/data/CursoredData.d.ts +16 -0
- package/dist/types/data/CursoredData.js +3 -0
- package/dist/types/data/CursoredData.js.map +1 -0
- package/dist/types/data/List.d.ts +21 -0
- package/dist/types/data/List.js +3 -0
- package/dist/types/data/List.js.map +1 -0
- package/dist/types/data/Notification.d.ts +20 -0
- package/dist/types/data/Notification.js +3 -0
- package/dist/types/data/Notification.js.map +1 -0
- package/dist/types/data/Tweet.d.ts +71 -0
- package/dist/types/data/Tweet.js +3 -0
- package/dist/types/data/Tweet.js.map +1 -0
- package/dist/types/data/User.d.ts +35 -0
- package/dist/types/data/User.js +3 -0
- package/dist/types/data/User.js.map +1 -0
- package/dist/types/params/Variables.d.ts +27 -0
- package/dist/types/params/Variables.js +3 -0
- package/dist/types/params/Variables.js.map +1 -0
- package/dist/types/raw/base/Analytic.d.ts +21 -0
- package/dist/types/raw/base/Analytic.js +4 -0
- package/dist/types/raw/base/Analytic.js.map +1 -0
- package/dist/types/raw/base/Cursor.d.ts +11 -0
- package/dist/types/raw/base/Cursor.js +4 -0
- package/dist/types/raw/base/Cursor.js.map +1 -0
- package/dist/types/raw/base/LimitedVisibilityTweet.d.ts +32 -0
- package/dist/types/raw/base/LimitedVisibilityTweet.js +4 -0
- package/dist/types/raw/base/LimitedVisibilityTweet.js.map +1 -0
- package/dist/types/raw/base/List.d.ts +43 -0
- package/dist/types/raw/base/List.js +4 -0
- package/dist/types/raw/base/List.js.map +1 -0
- package/dist/types/raw/base/Media.d.ts +43 -0
- package/dist/types/raw/base/Media.js +4 -0
- package/dist/types/raw/base/Media.js.map +1 -0
- package/dist/types/raw/base/Notification.d.ts +53 -0
- package/dist/types/raw/base/Notification.js +4 -0
- package/dist/types/raw/base/Notification.js.map +1 -0
- package/dist/types/raw/base/Space.d.ts +32 -0
- package/dist/types/raw/base/Space.js +4 -0
- package/dist/types/raw/base/Space.js.map +1 -0
- package/dist/types/raw/base/Tweet.d.ts +119 -0
- package/dist/types/raw/base/Tweet.js +4 -0
- package/dist/types/raw/base/Tweet.js.map +1 -0
- package/dist/types/raw/base/User.d.ts +140 -0
- package/dist/types/raw/base/User.js +4 -0
- package/dist/types/raw/base/User.js.map +1 -0
- package/dist/types/raw/composite/DataResult.d.ts +8 -0
- package/dist/types/raw/composite/DataResult.js +3 -0
- package/dist/types/raw/composite/DataResult.js.map +1 -0
- package/dist/types/raw/composite/TimelineTweet.d.ts +11 -0
- package/dist/types/raw/composite/TimelineTweet.js +4 -0
- package/dist/types/raw/composite/TimelineTweet.js.map +1 -0
- package/dist/types/raw/composite/TimelineUser.d.ts +10 -0
- package/dist/types/raw/composite/TimelineUser.js +4 -0
- package/dist/types/raw/composite/TimelineUser.js.map +1 -0
- package/dist/types/raw/generic/Error.d.ts +30 -0
- package/dist/types/raw/generic/Error.js +3 -0
- package/dist/types/raw/generic/Error.js.map +1 -0
- package/dist/types/raw/generic/Response.d.ts +12 -0
- package/dist/types/raw/generic/Response.js +3 -0
- package/dist/types/raw/generic/Response.js.map +1 -0
- package/dist/types/raw/list/Details.d.ts +122 -0
- package/dist/types/raw/list/Details.js +4 -0
- package/dist/types/raw/list/Details.js.map +1 -0
- package/dist/types/raw/list/Members.d.ts +134 -0
- package/dist/types/raw/list/Members.js +4 -0
- package/dist/types/raw/list/Members.js.map +1 -0
- package/dist/types/raw/list/Tweets.d.ts +1968 -0
- package/dist/types/raw/list/Tweets.js +4 -0
- package/dist/types/raw/list/Tweets.js.map +1 -0
- package/dist/types/raw/media/FinalizeUpload.d.ts +18 -0
- package/dist/types/raw/media/FinalizeUpload.js +4 -0
- package/dist/types/raw/media/FinalizeUpload.js.map +1 -0
- package/dist/types/raw/media/InitalizeUpload.d.ts +10 -0
- package/dist/types/raw/media/InitalizeUpload.js +4 -0
- package/dist/types/raw/media/InitalizeUpload.js.map +1 -0
- package/dist/types/raw/media/LiveVideoStream.d.ts +19 -0
- package/dist/types/raw/media/LiveVideoStream.js +4 -0
- package/dist/types/raw/media/LiveVideoStream.js.map +1 -0
- package/dist/types/raw/space/Details.d.ts +315 -0
- package/dist/types/raw/space/Details.js +4 -0
- package/dist/types/raw/space/Details.js.map +1 -0
- package/dist/types/raw/tweet/Details.d.ts +183 -0
- package/dist/types/raw/tweet/Details.js +4 -0
- package/dist/types/raw/tweet/Details.js.map +1 -0
- package/dist/types/raw/tweet/Like.d.ts +12 -0
- package/dist/types/raw/tweet/Like.js +4 -0
- package/dist/types/raw/tweet/Like.js.map +1 -0
- package/dist/types/raw/tweet/Likers.d.ts +170 -0
- package/dist/types/raw/tweet/Likers.js +4 -0
- package/dist/types/raw/tweet/Likers.js.map +1 -0
- package/dist/types/raw/tweet/Post.d.ts +133 -0
- package/dist/types/raw/tweet/Post.js +4 -0
- package/dist/types/raw/tweet/Post.js.map +1 -0
- package/dist/types/raw/tweet/Replies.d.ts +465 -0
- package/dist/types/raw/tweet/Replies.js +4 -0
- package/dist/types/raw/tweet/Replies.js.map +1 -0
- package/dist/types/raw/tweet/Retweet.d.ts +25 -0
- package/dist/types/raw/tweet/Retweet.js +4 -0
- package/dist/types/raw/tweet/Retweet.js.map +1 -0
- package/dist/types/raw/tweet/Retweeters.d.ts +177 -0
- package/dist/types/raw/tweet/Retweeters.js +4 -0
- package/dist/types/raw/tweet/Retweeters.js.map +1 -0
- package/dist/types/raw/tweet/Schedule.d.ts +15 -0
- package/dist/types/raw/tweet/Schedule.js +4 -0
- package/dist/types/raw/tweet/Schedule.js.map +1 -0
- package/dist/types/raw/tweet/Search.d.ts +518 -0
- package/dist/types/raw/tweet/Search.js +4 -0
- package/dist/types/raw/tweet/Search.js.map +1 -0
- package/dist/types/raw/tweet/Unlike.d.ts +12 -0
- package/dist/types/raw/tweet/Unlike.js +4 -0
- package/dist/types/raw/tweet/Unlike.js.map +1 -0
- package/dist/types/raw/tweet/Unpost.d.ts +17 -0
- package/dist/types/raw/tweet/Unpost.js +4 -0
- package/dist/types/raw/tweet/Unpost.js.map +1 -0
- package/dist/types/raw/tweet/Unretweet.d.ts +25 -0
- package/dist/types/raw/tweet/Unretweet.js +4 -0
- package/dist/types/raw/tweet/Unretweet.js.map +1 -0
- package/dist/types/raw/tweet/Unschedule.d.ts +12 -0
- package/dist/types/raw/tweet/Unschedule.js +4 -0
- package/dist/types/raw/tweet/Unschedule.js.map +1 -0
- package/dist/types/raw/user/Affiliates.d.ts +154 -0
- package/dist/types/raw/user/Affiliates.js +4 -0
- package/dist/types/raw/user/Affiliates.js.map +1 -0
- package/dist/types/raw/user/Analytics.d.ts +32 -0
- package/dist/types/raw/user/Analytics.js +4 -0
- package/dist/types/raw/user/Analytics.js.map +1 -0
- package/dist/types/raw/user/Bookmarks.d.ts +550 -0
- package/dist/types/raw/user/Bookmarks.js +4 -0
- package/dist/types/raw/user/Bookmarks.js.map +1 -0
- package/dist/types/raw/user/Details.d.ts +157 -0
- package/dist/types/raw/user/Details.js +4 -0
- package/dist/types/raw/user/Details.js.map +1 -0
- package/dist/types/raw/user/Follow.d.ts +248 -0
- package/dist/types/raw/user/Follow.js +4 -0
- package/dist/types/raw/user/Follow.js.map +1 -0
- package/dist/types/raw/user/Followed.d.ts +1666 -0
- package/dist/types/raw/user/Followed.js +4 -0
- package/dist/types/raw/user/Followed.js.map +1 -0
- package/dist/types/raw/user/Followers.d.ts +182 -0
- package/dist/types/raw/user/Followers.js +4 -0
- package/dist/types/raw/user/Followers.js.map +1 -0
- package/dist/types/raw/user/Following.d.ts +182 -0
- package/dist/types/raw/user/Following.js +4 -0
- package/dist/types/raw/user/Following.js.map +1 -0
- package/dist/types/raw/user/Highlights.d.ts +1106 -0
- package/dist/types/raw/user/Highlights.js +4 -0
- package/dist/types/raw/user/Highlights.js.map +1 -0
- package/dist/types/raw/user/Likes.d.ts +1065 -0
- package/dist/types/raw/user/Likes.js +4 -0
- package/dist/types/raw/user/Likes.js.map +1 -0
- package/dist/types/raw/user/Media.d.ts +1492 -0
- package/dist/types/raw/user/Media.js +4 -0
- package/dist/types/raw/user/Media.js.map +1 -0
- package/dist/types/raw/user/Notifications.d.ts +142 -0
- package/dist/types/raw/user/Notifications.js +4 -0
- package/dist/types/raw/user/Notifications.js.map +1 -0
- package/dist/types/raw/user/Recommended.d.ts +1991 -0
- package/dist/types/raw/user/Recommended.js +4 -0
- package/dist/types/raw/user/Recommended.js.map +1 -0
- package/dist/types/raw/user/Scheduled.d.ts +31 -0
- package/dist/types/raw/user/Scheduled.js +4 -0
- package/dist/types/raw/user/Scheduled.js.map +1 -0
- package/dist/types/raw/user/Subscriptions.d.ts +151 -0
- package/dist/types/raw/user/Subscriptions.js +4 -0
- package/dist/types/raw/user/Subscriptions.js.map +1 -0
- package/dist/types/raw/user/Tweets.d.ts +1065 -0
- package/dist/types/raw/user/Tweets.js +4 -0
- package/dist/types/raw/user/Tweets.js.map +1 -0
- package/dist/types/raw/user/TweetsAndReplies.d.ts +1065 -0
- package/dist/types/raw/user/TweetsAndReplies.js +4 -0
- package/dist/types/raw/user/TweetsAndReplies.js.map +1 -0
- package/dist/types/raw/user/Unfollow.d.ts +248 -0
- package/dist/types/raw/user/Unfollow.js +4 -0
- package/dist/types/raw/user/Unfollow.js.map +1 -0
- package/eslint.config.mjs +17 -0
- package/package.json +22 -19
- package/src/Rettiwt.ts +22 -7
- package/src/cli.ts +0 -2
- package/src/collections/Extractors.ts +40 -34
- package/src/collections/Groups.ts +4 -0
- package/src/collections/Requests.ts +46 -44
- package/src/commands/Tweet.ts +35 -7
- package/src/commands/User.ts +13 -2
- package/src/enums/Authentication.ts +10 -0
- package/src/enums/Data.ts +3 -3
- package/src/enums/Media.ts +10 -0
- package/src/enums/Notification.ts +12 -0
- package/src/enums/Resource.ts +4 -0
- package/src/enums/raw/Analytics.ts +29 -0
- package/src/enums/raw/Media.ts +10 -0
- package/src/enums/raw/Notification.ts +11 -0
- package/src/enums/raw/Tweet.ts +9 -0
- package/src/helper/JsonUtils.ts +1 -1
- package/src/helper/TidUtils.ts +189 -0
- package/src/index.ts +78 -44
- package/src/models/RettiwtConfig.ts +64 -0
- package/src/models/args/FetchArgs.ts +86 -436
- package/src/models/args/PostArgs.ts +24 -249
- package/src/models/auth/AuthCookie.ts +58 -0
- package/src/models/auth/AuthCredential.ts +85 -0
- package/src/models/data/CursoredData.ts +21 -26
- package/src/models/data/List.ts +18 -15
- package/src/models/data/Notification.ts +25 -38
- package/src/models/data/Tweet.ts +143 -104
- package/src/models/data/User.ts +74 -44
- package/src/models/errors/RettiwtError.ts +3 -2
- package/src/models/params/Variables.ts +62 -0
- package/src/requests/List.ts +121 -0
- package/src/requests/Media.ts +67 -0
- package/src/requests/Tweet.ts +496 -0
- package/src/requests/User.ts +783 -0
- package/src/services/{public → internal}/AuthService.ts +28 -60
- package/src/services/internal/LogService.ts +4 -19
- package/src/services/internal/TidService.ts +147 -0
- package/src/services/public/FetcherService.ts +89 -59
- package/src/services/public/ListService.ts +4 -4
- package/src/services/public/TweetService.ts +129 -42
- package/src/services/public/UserService.ts +49 -37
- package/src/types/RettiwtConfig.ts +18 -12
- package/src/types/args/FetchArgs.ts +148 -0
- package/src/types/args/PostArgs.ts +112 -0
- package/src/types/auth/AuthCookie.ts +22 -0
- package/src/types/auth/AuthCredential.ts +28 -0
- package/src/types/auth/TidDynamicArgs.ts +10 -0
- package/src/types/auth/TidHeader.ts +12 -0
- package/src/types/auth/TidParams.ts +36 -0
- package/src/types/auth/TidProvider.ts +19 -0
- package/src/types/data/CursoredData.ts +18 -0
- package/src/types/data/List.ts +27 -0
- package/src/types/data/Notification.ts +26 -0
- package/src/types/data/Tweet.ts +96 -0
- package/src/types/data/User.ts +48 -0
- package/src/types/params/Variables.ts +41 -0
- package/src/types/raw/base/Analytic.ts +26 -0
- package/src/types/raw/base/Cursor.ts +13 -0
- package/src/types/raw/base/LimitedVisibilityTweet.ts +40 -0
- package/src/types/raw/base/List.ts +50 -0
- package/src/types/raw/base/Media.ts +53 -0
- package/src/types/raw/base/Notification.ts +67 -0
- package/src/types/raw/base/Space.ts +35 -0
- package/src/types/raw/base/Tweet.ts +139 -0
- package/src/types/raw/base/User.ts +164 -0
- package/src/types/raw/composite/DataResult.ts +8 -0
- package/src/types/raw/composite/TimelineTweet.ts +14 -0
- package/src/types/raw/composite/TimelineUser.ts +13 -0
- package/src/types/raw/generic/Error.ts +35 -0
- package/src/types/raw/generic/Response.ts +13 -0
- package/src/types/raw/list/Details.ts +137 -0
- package/src/types/raw/list/Members.ts +154 -0
- package/src/types/raw/list/Tweets.ts +2296 -0
- package/src/types/raw/media/FinalizeUpload.ts +20 -0
- package/src/types/raw/media/InitalizeUpload.ts +12 -0
- package/src/types/raw/media/LiveVideoStream.ts +21 -0
- package/src/types/raw/space/Details.ts +359 -0
- package/src/types/raw/tweet/Details.ts +210 -0
- package/src/types/raw/tweet/Like.ts +14 -0
- package/src/types/raw/tweet/Likers.ts +200 -0
- package/src/types/raw/tweet/Post.ts +150 -0
- package/src/types/raw/tweet/Replies.ts +539 -0
- package/src/types/raw/tweet/Retweet.ts +31 -0
- package/src/types/raw/tweet/Retweeters.ts +208 -0
- package/src/types/raw/tweet/Schedule.ts +18 -0
- package/src/types/raw/tweet/Search.ts +597 -0
- package/src/types/raw/tweet/Unlike.ts +14 -0
- package/src/types/raw/tweet/Unpost.ts +20 -0
- package/src/types/raw/tweet/Unretweet.ts +31 -0
- package/src/types/raw/tweet/Unschedule.ts +14 -0
- package/src/types/raw/user/Affiliates.ts +179 -0
- package/src/types/raw/user/Analytics.ts +39 -0
- package/src/types/raw/user/Bookmarks.ts +637 -0
- package/src/types/raw/user/Details.ts +185 -0
- package/src/types/raw/user/Follow.ts +280 -0
- package/src/types/raw/user/Followed.ts +1942 -0
- package/src/types/raw/user/Followers.ts +215 -0
- package/src/types/raw/user/Following.ts +215 -0
- package/src/types/raw/user/Highlights.ts +1287 -0
- package/src/types/raw/user/Likes.ts +1254 -0
- package/src/types/raw/user/Media.ts +1738 -0
- package/src/types/raw/user/Notifications.ts +175 -0
- package/src/types/raw/user/Recommended.ts +2319 -0
- package/src/types/raw/user/Scheduled.ts +37 -0
- package/src/types/raw/user/Subscriptions.ts +176 -0
- package/src/types/raw/user/Tweets.ts +1254 -0
- package/src/types/raw/user/TweetsAndReplies.ts +1254 -0
- package/src/types/raw/user/Unfollow.ts +280 -0
- package/tsconfig.json +7 -5
- package/.eslintignore +0 -3
- package/dist/commands/Auth.d.ts +0 -10
- package/dist/commands/Auth.js +0 -101
- package/dist/commands/Auth.js.map +0 -1
- package/dist/models/errors/DataValidationError.d.ts +0 -30
- package/dist/models/errors/DataValidationError.js +0 -34
- package/dist/models/errors/DataValidationError.js.map +0 -1
- package/dist/services/public/AuthService.d.ts +0 -91
- package/dist/services/public/AuthService.js +0 -205
- package/dist/services/public/AuthService.js.map +0 -1
- package/dist/types/ReturnTypes.d.ts +0 -21
- package/dist/types/ReturnTypes.js.map +0 -1
- package/src/commands/Auth.ts +0 -46
- package/src/models/errors/DataValidationError.ts +0 -44
- package/src/types/ReturnTypes.ts +0 -24
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Agent } from 'https';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { IRettiwtConfig } from '../../types/RettiwtConfig';
|
|
3
|
+
import axios from 'axios';
|
|
5
4
|
|
|
6
|
-
import {
|
|
5
|
+
import { EApiErrors } from '../../enums/Api';
|
|
6
|
+
import { AuthCredential } from '../../models/auth/AuthCredential';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The services that handles authentication.
|
|
10
10
|
*
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
export class AuthService
|
|
13
|
+
export class AuthService {
|
|
14
|
+
/** The HTTPS Agent to use for requests to Twitter API. */
|
|
15
|
+
private readonly _httpsAgent: Agent;
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
|
-
* @param
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
+
* @param httpsAgent - The HTTPS agent to use. If none is provided, default is used.
|
|
18
19
|
*/
|
|
19
|
-
public constructor(
|
|
20
|
-
|
|
20
|
+
public constructor(httpsAgent?: Agent) {
|
|
21
|
+
this._httpsAgent = httpsAgent ?? new Agent();
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -94,57 +95,24 @@ export class AuthService extends FetcherService {
|
|
|
94
95
|
* });
|
|
95
96
|
* ```
|
|
96
97
|
*/
|
|
97
|
-
public async guest(): Promise<
|
|
98
|
-
//
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
return guestKey;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Login to twitter using account credentials.
|
|
106
|
-
*
|
|
107
|
-
* @param email - The email id associated with the Twitter account.
|
|
108
|
-
* @param userName - The username associated with the Twitter account.
|
|
109
|
-
* @param password - The password to the Twitter account.
|
|
110
|
-
*
|
|
111
|
-
* @returns The `API_KEY` for the Twitter account.
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```
|
|
115
|
-
* import { Rettiwt } from 'rettiwt-api';
|
|
116
|
-
*
|
|
117
|
-
* // Creating a new Rettiwt instance
|
|
118
|
-
* const rettiwt = new Rettiwt();
|
|
119
|
-
*
|
|
120
|
-
* // Logging in an getting the API_KEY
|
|
121
|
-
* rettiwt.auth.login("email@domain.com", "username", "password")
|
|
122
|
-
* .then(apiKey => {
|
|
123
|
-
* // Use the API_KEY
|
|
124
|
-
* ...
|
|
125
|
-
* })
|
|
126
|
-
* .catch(err => {
|
|
127
|
-
* console.log(err);
|
|
128
|
-
* });
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* @remarks
|
|
132
|
-
* Interchanging `email` and `userName` works too.
|
|
133
|
-
*/
|
|
134
|
-
public async login(email: string, userName: string, password: string): Promise<string> {
|
|
135
|
-
// Logging in and getting the credentials
|
|
136
|
-
let apiKey: string =
|
|
137
|
-
((
|
|
138
|
-
await new Auth({ proxyUrl: this.authProxyUrl }).getUserCredential({
|
|
139
|
-
email: email,
|
|
140
|
-
userName: userName,
|
|
141
|
-
password: password,
|
|
142
|
-
})
|
|
143
|
-
).toHeader().cookie as string) ?? '';
|
|
98
|
+
public async guest(): Promise<AuthCredential> {
|
|
99
|
+
// Creating a new blank credential
|
|
100
|
+
const cred: AuthCredential = new AuthCredential();
|
|
144
101
|
|
|
145
|
-
//
|
|
146
|
-
|
|
102
|
+
// Getting the guest token
|
|
103
|
+
await axios
|
|
104
|
+
.post<{
|
|
105
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
106
|
+
guest_token: string;
|
|
107
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
108
|
+
}>('https://api.twitter.com/1.1/guest/activate.json', undefined, {
|
|
109
|
+
headers: cred.toHeader(),
|
|
110
|
+
httpsAgent: this._httpsAgent,
|
|
111
|
+
})
|
|
112
|
+
.then((res) => {
|
|
113
|
+
cred.guestToken = res.data.guest_token;
|
|
114
|
+
});
|
|
147
115
|
|
|
148
|
-
return
|
|
116
|
+
return cred;
|
|
149
117
|
}
|
|
150
118
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
|
|
3
1
|
import { ELogActions } from '../../enums/Logging';
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -9,20 +7,7 @@ import { ELogActions } from '../../enums/Logging';
|
|
|
9
7
|
*/
|
|
10
8
|
export class LogService {
|
|
11
9
|
/** Whether logging is enabled or not. */
|
|
12
|
-
public static enabled
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param action - The action to be logged.
|
|
16
|
-
*
|
|
17
|
-
* @returns - The colored text representing the action.
|
|
18
|
-
*/
|
|
19
|
-
private static getColoredAction(action: ELogActions): string {
|
|
20
|
-
if (action == ELogActions.WARNING) {
|
|
21
|
-
return chalk.yellow(action);
|
|
22
|
-
} else {
|
|
23
|
-
return chalk.green(action);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
10
|
+
public static enabled = false;
|
|
26
11
|
|
|
27
12
|
/**
|
|
28
13
|
* Logs the given data.
|
|
@@ -35,12 +20,12 @@ export class LogService {
|
|
|
35
20
|
// Proceed to log only if logging is enabled
|
|
36
21
|
if (this.enabled) {
|
|
37
22
|
// Preparing the log message
|
|
38
|
-
const logPrefix
|
|
23
|
+
const logPrefix = 'Rettiwt-API';
|
|
39
24
|
const logTime: string = new Date().toISOString();
|
|
40
|
-
const logAction: string =
|
|
25
|
+
const logAction: string = action;
|
|
41
26
|
const logData: string = JSON.stringify(data);
|
|
42
27
|
|
|
43
|
-
const logMessage
|
|
28
|
+
const logMessage = `[${logPrefix}] [${logTime}] [${logAction}] ${logData}`;
|
|
44
29
|
|
|
45
30
|
// Logging
|
|
46
31
|
console.log(logMessage);
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Agent } from 'http';
|
|
2
|
+
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import * as htmlParser from 'node-html-parser';
|
|
5
|
+
|
|
6
|
+
import { ELogActions } from '../../enums/Logging';
|
|
7
|
+
|
|
8
|
+
import { calculateClientTransactionIdHeader } from '../../helper/TidUtils';
|
|
9
|
+
|
|
10
|
+
import { ITidDynamicArgs } from '../../types/auth/TidDynamicArgs';
|
|
11
|
+
import { ITidProvider } from '../../types/auth/TidProvider';
|
|
12
|
+
|
|
13
|
+
import { LogService } from './LogService';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Handles transaction ID generation for requests to Twitter.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export class TidService implements ITidProvider {
|
|
21
|
+
private readonly _cdnUrl: string;
|
|
22
|
+
private readonly _httpsAgent: Agent;
|
|
23
|
+
private readonly _requestHeaders: NonNullable<unknown>;
|
|
24
|
+
private _dynamicArgs?: ITidDynamicArgs;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param httpsAgent - The HTTPS agent to use. If none is provided, default is used.
|
|
28
|
+
*/
|
|
29
|
+
public constructor(httpsAgent?: Agent) {
|
|
30
|
+
this._cdnUrl = 'https://abs.twimg.com/responsive-web/client-web';
|
|
31
|
+
this._httpsAgent = httpsAgent ?? new Agent();
|
|
32
|
+
this._requestHeaders = {
|
|
33
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
34
|
+
|
|
35
|
+
Authority: 'x.com',
|
|
36
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
37
|
+
'Cache-Control': 'no-cache',
|
|
38
|
+
Referer: 'https://x.com',
|
|
39
|
+
'User-Agent':
|
|
40
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
|
|
41
|
+
'X-Twitter-Active-User': 'yes',
|
|
42
|
+
'X-Twitter-Client-Language': 'en',
|
|
43
|
+
|
|
44
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Fetches the dynamic args embedded in the homepage.
|
|
50
|
+
*
|
|
51
|
+
* @returns The new dynamic args.
|
|
52
|
+
*/
|
|
53
|
+
private async getDynamicArgs(): Promise<ITidDynamicArgs> {
|
|
54
|
+
const html = await this.getHomepageHtml();
|
|
55
|
+
const root = htmlParser.parse(html);
|
|
56
|
+
const keyElement = root.querySelector("[name='twitter-site-verification']");
|
|
57
|
+
const frameElements = root.querySelectorAll("[id^='loading-x-anim']");
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
verificationKey: keyElement?.getAttribute('content') ?? '',
|
|
61
|
+
frames: frameElements.map((el) => this.parseFrameElement(el)),
|
|
62
|
+
indices: await this.getKeyBytesIndices(html),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Fetches the HTML content of Twitter's homepage.
|
|
68
|
+
*
|
|
69
|
+
* @returns The stringified HTML content of the homepage.
|
|
70
|
+
*/
|
|
71
|
+
private async getHomepageHtml(): Promise<string> {
|
|
72
|
+
const response = await axios.get<string>('https://x.com', {
|
|
73
|
+
headers: this._requestHeaders,
|
|
74
|
+
httpAgent: this._httpsAgent,
|
|
75
|
+
httpsAgent: this._httpsAgent,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return response.data;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private async getKeyBytesIndices(html: string): Promise<number[]> {
|
|
82
|
+
const ondemandFileMatch = html.match(/ondemand\.s":"([^"]+)"/);
|
|
83
|
+
if (!ondemandFileMatch || !ondemandFileMatch[1]) {
|
|
84
|
+
LogService.log(ELogActions.WARNING, { message: 'ondemand.s file not found' });
|
|
85
|
+
|
|
86
|
+
return [0, 0, 0, 0];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const onDemandFileHash = ondemandFileMatch ? ondemandFileMatch[1] : '';
|
|
90
|
+
const response = await axios.get<string>(`${this._cdnUrl}/ondemand.s.${onDemandFileHash}a.js`, {
|
|
91
|
+
httpAgent: this._httpsAgent,
|
|
92
|
+
httpsAgent: this._httpsAgent,
|
|
93
|
+
});
|
|
94
|
+
const match = response.data.matchAll(/(\(\w\[(\d{1,2})],\s*16\))+?/gm);
|
|
95
|
+
|
|
96
|
+
return Array.from(match).map((m) => Number(m[2]));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private parseFrameElement(element: htmlParser.HTMLElement): number[][] {
|
|
100
|
+
const pathElement = element.children[0].children[1];
|
|
101
|
+
const value = pathElement.getAttribute('d');
|
|
102
|
+
if (!value) {
|
|
103
|
+
return [[]];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const rawFrames = value.substring(9).split('C');
|
|
107
|
+
|
|
108
|
+
return rawFrames.map((str) => str.replaceAll(/\D+/g, ' ').trim().split(' ')).map((arr) => arr.map(Number));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Generate an `x-client-transaction-id` for the specific URL method and path.
|
|
113
|
+
*
|
|
114
|
+
* @param method - The target method.
|
|
115
|
+
* @param path - The target path.
|
|
116
|
+
*
|
|
117
|
+
* @returns The specific `x-client-transaction-id` token.
|
|
118
|
+
*/
|
|
119
|
+
public async generate(method: string, path: string): Promise<string | undefined> {
|
|
120
|
+
try {
|
|
121
|
+
if (!this._dynamicArgs) {
|
|
122
|
+
this._dynamicArgs = await this.getDynamicArgs();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const { verificationKey, frames, indices } = this._dynamicArgs;
|
|
126
|
+
|
|
127
|
+
return calculateClientTransactionIdHeader({
|
|
128
|
+
keyword: 'obfiowerehiring',
|
|
129
|
+
method: method,
|
|
130
|
+
path: path,
|
|
131
|
+
verificationKey: verificationKey,
|
|
132
|
+
frames: frames,
|
|
133
|
+
indices: indices,
|
|
134
|
+
extraByte: 3,
|
|
135
|
+
});
|
|
136
|
+
} catch {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Refreshes the dynamic args from the homepage.
|
|
143
|
+
*/
|
|
144
|
+
public async refreshDynamicArgs(): Promise<void> {
|
|
145
|
+
this._dynamicArgs = await this.getDynamicArgs();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import https, { Agent } from 'https';
|
|
2
|
-
|
|
3
1
|
import axios from 'axios';
|
|
4
|
-
import {
|
|
5
|
-
import { Auth, AuthCredential } from 'rettiwt-auth';
|
|
2
|
+
import { Cookie } from 'cookiejar';
|
|
6
3
|
|
|
7
4
|
import { allowGuestAuthentication, fetchResources, postResources } from '../../collections/Groups';
|
|
8
5
|
import { requests } from '../../collections/Requests';
|
|
@@ -11,13 +8,18 @@ import { ELogActions } from '../../enums/Logging';
|
|
|
11
8
|
import { EResourceType } from '../../enums/Resource';
|
|
12
9
|
import { FetchArgs } from '../../models/args/FetchArgs';
|
|
13
10
|
import { PostArgs } from '../../models/args/PostArgs';
|
|
11
|
+
import { AuthCredential } from '../../models/auth/AuthCredential';
|
|
12
|
+
import { RettiwtConfig } from '../../models/RettiwtConfig';
|
|
13
|
+
import { IFetchArgs } from '../../types/args/FetchArgs';
|
|
14
|
+
import { IPostArgs } from '../../types/args/PostArgs';
|
|
15
|
+
import { ITidHeader } from '../../types/auth/TidHeader';
|
|
16
|
+
import { ITidProvider } from '../../types/auth/TidProvider';
|
|
14
17
|
import { IErrorHandler } from '../../types/ErrorHandler';
|
|
15
|
-
import { IRettiwtConfig } from '../../types/RettiwtConfig';
|
|
16
18
|
|
|
19
|
+
import { AuthService } from '../internal/AuthService';
|
|
17
20
|
import { ErrorService } from '../internal/ErrorService';
|
|
18
21
|
import { LogService } from '../internal/LogService';
|
|
19
|
-
|
|
20
|
-
import { AuthService } from './AuthService';
|
|
22
|
+
import { TidService } from '../internal/TidService';
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* The base service that handles all HTTP requests.
|
|
@@ -25,39 +27,35 @@ import { AuthService } from './AuthService';
|
|
|
25
27
|
* @public
|
|
26
28
|
*/
|
|
27
29
|
export class FetcherService {
|
|
28
|
-
/** The
|
|
29
|
-
private readonly
|
|
30
|
+
/** The AuthService instance to use. */
|
|
31
|
+
private readonly _auth: AuthService;
|
|
32
|
+
|
|
33
|
+
/** The delay/delay function to use (ms). */
|
|
34
|
+
private readonly _delay?: number | (() => number | Promise<number>);
|
|
30
35
|
|
|
31
36
|
/** The service used to handle HTTP and API errors */
|
|
32
37
|
private readonly _errorHandler: IErrorHandler;
|
|
33
38
|
|
|
34
|
-
/**
|
|
35
|
-
private readonly
|
|
36
|
-
|
|
37
|
-
/** The URL To the proxy server to use for all others. */
|
|
38
|
-
private readonly _proxyUrl?: URL;
|
|
39
|
+
/** Service responsible for generating the `x-client-transaction-id` header. */
|
|
40
|
+
private readonly _tidProvider: ITidProvider;
|
|
39
41
|
|
|
40
42
|
/** The max wait time for a response. */
|
|
41
43
|
private readonly _timeout: number;
|
|
42
44
|
|
|
43
|
-
/** The
|
|
44
|
-
protected readonly
|
|
45
|
-
|
|
46
|
-
/** The id of the authenticated user (if any). */
|
|
47
|
-
protected readonly userId?: string;
|
|
45
|
+
/** The config object. */
|
|
46
|
+
protected readonly config: RettiwtConfig;
|
|
48
47
|
|
|
49
48
|
/**
|
|
50
49
|
* @param config - The config object for configuring the Rettiwt instance.
|
|
51
50
|
*/
|
|
52
|
-
public constructor(config
|
|
53
|
-
LogService.enabled = config
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this._errorHandler = config?.errorHandler ?? new ErrorService();
|
|
51
|
+
public constructor(config: RettiwtConfig) {
|
|
52
|
+
LogService.enabled = config.logging ?? false;
|
|
53
|
+
this.config = config;
|
|
54
|
+
this._delay = config.delay;
|
|
55
|
+
this._errorHandler = config.errorHandler ?? new ErrorService();
|
|
56
|
+
this._tidProvider = config.tidProvider ?? new TidService(config.httpsAgent);
|
|
57
|
+
this._timeout = config.timeout ?? 0;
|
|
58
|
+
this._auth = new AuthService(config.httpsAgent);
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
/**
|
|
@@ -69,10 +67,10 @@ export class FetcherService {
|
|
|
69
67
|
*/
|
|
70
68
|
private checkAuthorization(resource: EResourceType): void {
|
|
71
69
|
// Logging
|
|
72
|
-
LogService.log(ELogActions.AUTHORIZATION, { authenticated: this.userId != undefined });
|
|
70
|
+
LogService.log(ELogActions.AUTHORIZATION, { authenticated: this.config.userId != undefined });
|
|
73
71
|
|
|
74
72
|
// Checking authorization status
|
|
75
|
-
if (!allowGuestAuthentication.includes(resource) && this.userId == undefined) {
|
|
73
|
+
if (!allowGuestAuthentication.includes(resource) && this.config.userId == undefined) {
|
|
76
74
|
throw new Error(EApiErrors.RESOURCE_NOT_ALLOWED);
|
|
77
75
|
}
|
|
78
76
|
}
|
|
@@ -83,42 +81,46 @@ export class FetcherService {
|
|
|
83
81
|
* @returns The generated AuthCredential
|
|
84
82
|
*/
|
|
85
83
|
private async getCredential(): Promise<AuthCredential> {
|
|
86
|
-
if (this.
|
|
84
|
+
if (this.config.apiKey) {
|
|
87
85
|
// Logging
|
|
88
86
|
LogService.log(ELogActions.GET, { target: 'USER_CREDENTIAL' });
|
|
89
87
|
|
|
90
|
-
return new AuthCredential(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return new AuthCredential(undefined, this._guestKey);
|
|
88
|
+
return new AuthCredential(
|
|
89
|
+
AuthService.decodeCookie(this.config.apiKey)
|
|
90
|
+
.split(';')
|
|
91
|
+
.map((item) => new Cookie(item)),
|
|
92
|
+
);
|
|
96
93
|
} else {
|
|
97
94
|
// Logging
|
|
98
95
|
LogService.log(ELogActions.GET, { target: 'NEW_GUEST_CREDENTIAL' });
|
|
99
96
|
|
|
100
|
-
return
|
|
97
|
+
return this._auth.guest();
|
|
101
98
|
}
|
|
102
99
|
}
|
|
103
100
|
|
|
104
101
|
/**
|
|
105
|
-
*
|
|
102
|
+
* Generates the header for the transaction ID.
|
|
106
103
|
*
|
|
107
|
-
* @param
|
|
104
|
+
* @param method - The target method.
|
|
105
|
+
* @param url - The target URL.
|
|
108
106
|
*
|
|
109
|
-
* @returns The
|
|
107
|
+
* @returns The header containing the transaction ID.
|
|
110
108
|
*/
|
|
111
|
-
private
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
private async getTransactionHeader(method: string, url: string): Promise<ITidHeader | undefined> {
|
|
110
|
+
// Getting the URL path excluding all params
|
|
111
|
+
const path = new URL(url).pathname.split('?')[0].trim();
|
|
112
|
+
|
|
113
|
+
// Generating the transaction ID
|
|
114
|
+
const tid = await this._tidProvider.generate(method.toUpperCase(), path);
|
|
115
|
+
|
|
116
|
+
if (tid) {
|
|
117
|
+
return {
|
|
118
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
119
|
+
'x-client-transaction-id': tid,
|
|
120
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
121
|
+
};
|
|
117
122
|
} else {
|
|
118
|
-
|
|
119
|
-
LogService.log(ELogActions.GET, { target: 'HTTPS_AGENT' });
|
|
120
|
-
|
|
121
|
-
return new https.Agent();
|
|
123
|
+
return undefined;
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
|
|
@@ -130,7 +132,7 @@ export class FetcherService {
|
|
|
130
132
|
*
|
|
131
133
|
* @returns The validated args.
|
|
132
134
|
*/
|
|
133
|
-
private validateArgs(resource: EResourceType, args:
|
|
135
|
+
private validateArgs(resource: EResourceType, args: IFetchArgs | IPostArgs): FetchArgs | PostArgs | undefined {
|
|
134
136
|
if (fetchResources.includes(resource)) {
|
|
135
137
|
// Logging
|
|
136
138
|
LogService.log(ELogActions.VALIDATE, { target: 'FETCH_ARGS' });
|
|
@@ -144,6 +146,29 @@ export class FetcherService {
|
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Introduces a delay using the configured delay/delay function.
|
|
151
|
+
*/
|
|
152
|
+
private async wait(): Promise<void> {
|
|
153
|
+
// If no delay is set, skip
|
|
154
|
+
if (this._delay == undefined) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The delay (in ms) to use. */
|
|
159
|
+
let delay = 0;
|
|
160
|
+
|
|
161
|
+
// Getting the delay
|
|
162
|
+
if (this._delay && typeof this._delay == 'number') {
|
|
163
|
+
delay = this._delay;
|
|
164
|
+
} else if (this._delay && typeof this._delay == 'function') {
|
|
165
|
+
delay = await this._delay();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Awaiting for the delay time
|
|
169
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
170
|
+
}
|
|
171
|
+
|
|
147
172
|
/**
|
|
148
173
|
* Makes an HTTP request according to the given parameters.
|
|
149
174
|
*
|
|
@@ -172,7 +197,7 @@ export class FetcherService {
|
|
|
172
197
|
* })
|
|
173
198
|
* ```
|
|
174
199
|
*/
|
|
175
|
-
public async request<T>(resource: EResourceType, args:
|
|
200
|
+
public async request<T = unknown>(resource: EResourceType, args: IFetchArgs | IPostArgs): Promise<T> {
|
|
176
201
|
// Logging
|
|
177
202
|
LogService.log(ELogActions.REQUEST, { resource: resource, args: args });
|
|
178
203
|
|
|
@@ -182,9 +207,6 @@ export class FetcherService {
|
|
|
182
207
|
// Validating args
|
|
183
208
|
args = this.validateArgs(resource, args)!;
|
|
184
209
|
|
|
185
|
-
// Getting HTTPS agent
|
|
186
|
-
const httpsAgent: Agent = this.getHttpsAgent(this._proxyUrl);
|
|
187
|
-
|
|
188
210
|
// Getting credentials from key
|
|
189
211
|
const cred: AuthCredential = await this.getCredential();
|
|
190
212
|
|
|
@@ -192,13 +214,21 @@ export class FetcherService {
|
|
|
192
214
|
const config = requests[resource](args);
|
|
193
215
|
|
|
194
216
|
// Setting additional request parameters
|
|
195
|
-
config.headers = {
|
|
196
|
-
|
|
197
|
-
|
|
217
|
+
config.headers = {
|
|
218
|
+
...config.headers,
|
|
219
|
+
...cred.toHeader(),
|
|
220
|
+
...(await this.getTransactionHeader(config.method ?? '', config.url ?? '')),
|
|
221
|
+
...this.config.headers,
|
|
222
|
+
};
|
|
223
|
+
config.httpAgent = this.config.httpsAgent;
|
|
224
|
+
config.httpsAgent = this.config.httpsAgent;
|
|
198
225
|
config.timeout = this._timeout;
|
|
199
226
|
|
|
200
227
|
// Sending the request
|
|
201
228
|
try {
|
|
229
|
+
// Introducing a delay
|
|
230
|
+
await this.wait();
|
|
231
|
+
|
|
202
232
|
// Returning the reponse body
|
|
203
233
|
return (await axios<T>(config)).data;
|
|
204
234
|
} catch (error) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { IListMembersResponse, IListTweetsResponse } from 'rettiwt-core';
|
|
2
|
-
|
|
3
1
|
import { extractors } from '../../collections/Extractors';
|
|
4
2
|
import { EResourceType } from '../../enums/Resource';
|
|
5
3
|
import { CursoredData } from '../../models/data/CursoredData';
|
|
6
4
|
import { Tweet } from '../../models/data/Tweet';
|
|
7
5
|
import { User } from '../../models/data/User';
|
|
8
|
-
import {
|
|
6
|
+
import { RettiwtConfig } from '../../models/RettiwtConfig';
|
|
7
|
+
import { IListMembersResponse } from '../../types/raw/list/Members';
|
|
8
|
+
import { IListTweetsResponse } from '../../types/raw/list/Tweets';
|
|
9
9
|
|
|
10
10
|
import { FetcherService } from './FetcherService';
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ export class ListService extends FetcherService {
|
|
|
15
15
|
*
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
|
-
public constructor(config
|
|
18
|
+
public constructor(config: RettiwtConfig) {
|
|
19
19
|
super(config);
|
|
20
20
|
}
|
|
21
21
|
|