rettiwt-api 1.1.2 → 1.1.7
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/README.md +32 -7
- package/dist/endpoints/Endpoints.d.ts +14 -0
- package/dist/endpoints/Endpoints.js +20 -0
- package/dist/endpoints/Endpoints.js.map +1 -0
- package/dist/endpoints/Url.d.ts +5 -0
- package/dist/endpoints/Url.js +12 -0
- package/dist/endpoints/Url.js.map +1 -0
- package/dist/enums/Endpoints.d.ts +25 -0
- package/dist/enums/Endpoints.js +31 -0
- package/dist/enums/Endpoints.js.map +1 -0
- package/dist/enums/Errors.d.ts +20 -0
- package/dist/enums/Errors.js +28 -0
- package/dist/enums/Errors.js.map +1 -0
- package/dist/enums/HTTP.d.ts +17 -0
- package/dist/enums/HTTP.js +23 -0
- package/dist/enums/HTTP.js.map +1 -0
- package/dist/graphql/enums/Errors.d.ts +21 -0
- package/dist/graphql/enums/Errors.js +29 -0
- package/dist/graphql/enums/Errors.js.map +1 -0
- package/dist/graphql/queries/RootQuery.js +10 -3
- package/dist/graphql/queries/RootQuery.js.map +1 -1
- package/dist/graphql/resolvers/AccountResolver.d.ts +3 -3
- package/dist/graphql/resolvers/AccountResolver.js.map +1 -1
- package/dist/graphql/resolvers/ResolverBase.d.ts +14 -3
- package/dist/graphql/resolvers/ResolverBase.js +13 -1
- package/dist/graphql/resolvers/ResolverBase.js.map +1 -1
- package/dist/graphql/resolvers/TweetResolver.d.ts +3 -3
- package/dist/graphql/resolvers/TweetResolver.js +30 -18
- package/dist/graphql/resolvers/TweetResolver.js.map +1 -1
- package/dist/graphql/resolvers/UserResolver.d.ts +13 -4
- package/dist/graphql/resolvers/UserResolver.js +83 -18
- package/dist/graphql/resolvers/UserResolver.js.map +1 -1
- package/dist/graphql/types/Errors.d.ts +20 -0
- package/dist/graphql/types/Errors.js +28 -0
- package/dist/graphql/types/Errors.js.map +1 -0
- package/dist/graphql/types/TweetTypes.js +2 -2
- package/dist/graphql/types/TweetTypes.js.map +1 -1
- package/dist/graphql/types/UserTypes.js +1 -1
- package/dist/graphql/types/UserTypes.js.map +1 -1
- package/dist/index.d.ts +31 -15
- package/dist/index.js +32 -17
- package/dist/index.js.map +1 -1
- package/dist/middlewares/Authentication.d.ts +0 -0
- package/dist/middlewares/Authentication.js +2 -0
- package/dist/middlewares/Authentication.js.map +1 -0
- package/dist/models/args/TweetFilter.d.ts +59 -0
- package/dist/models/args/TweetFilter.js +101 -0
- package/dist/models/args/TweetFilter.js.map +1 -0
- package/dist/models/args/TweetListArgs.d.ts +21 -0
- package/dist/models/args/TweetListArgs.js +54 -0
- package/dist/models/args/TweetListArgs.js.map +1 -0
- package/dist/models/args/UserListArgs.d.ts +21 -0
- package/dist/models/args/UserListArgs.js +54 -0
- package/dist/models/args/UserListArgs.js.map +1 -0
- package/dist/models/auth/AuthCookie.d.ts +21 -0
- package/dist/models/auth/AuthCookie.js +33 -0
- package/dist/models/auth/AuthCookie.js.map +1 -0
- package/dist/models/data/CursoredData.d.ts +34 -0
- package/dist/models/data/CursoredData.js +42 -0
- package/dist/models/data/CursoredData.js.map +1 -0
- package/dist/models/data/DataValidationError.d.ts +18 -0
- package/dist/models/data/DataValidationError.js +21 -0
- package/dist/models/data/DataValidationError.js.map +1 -0
- package/dist/models/data/Errors.d.ts +18 -0
- package/dist/models/data/Errors.js +21 -0
- package/dist/models/data/Errors.js.map +1 -0
- package/dist/models/data/Service.d.ts +33 -0
- package/dist/models/data/Service.js +41 -0
- package/dist/models/data/Service.js.map +1 -0
- package/dist/models/data/Tweet.d.ts +53 -0
- package/dist/models/data/Tweet.js +104 -0
- package/dist/models/data/Tweet.js.map +1 -0
- package/dist/models/data/User.d.ts +41 -0
- package/dist/models/data/User.js +32 -0
- package/dist/models/data/User.js.map +1 -0
- package/dist/models/errors/DataValidationError.d.ts +20 -0
- package/dist/models/errors/DataValidationError.js +23 -0
- package/dist/models/errors/DataValidationError.js.map +1 -0
- package/dist/models/query/Variables.d.ts +2 -0
- package/dist/models/query/Variables.js +10 -0
- package/dist/models/query/Variables.js.map +1 -0
- package/dist/requests/Url.d.ts +5 -0
- package/dist/requests/Url.js +12 -0
- package/dist/requests/Url.js.map +1 -0
- package/dist/requests/payloads/Variables.d.ts +23 -0
- package/dist/requests/payloads/Variables.js +24 -0
- package/dist/requests/payloads/Variables.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +9 -10
- package/dist/server.js.map +1 -1
- package/dist/services/accounts/AccountService.d.ts +6 -0
- package/dist/services/accounts/AccountService.js +6 -0
- package/dist/services/accounts/AccountService.js.map +1 -1
- package/dist/services/auth/AccountService.d.ts +88 -0
- package/dist/services/auth/AccountService.js +392 -0
- package/dist/services/auth/AccountService.js.map +1 -0
- package/dist/services/auth/AuthService.d.ts +31 -0
- package/dist/services/auth/AuthService.js +118 -0
- package/dist/services/auth/AuthService.js.map +1 -0
- package/dist/services/auth/LoginFlows.d.ts +77 -0
- package/dist/services/auth/LoginFlows.js +92 -0
- package/dist/services/auth/LoginFlows.js.map +1 -0
- package/dist/services/data/TweetService.d.ts +46 -16
- package/dist/services/data/TweetService.js +71 -54
- package/dist/services/data/TweetService.js.map +1 -1
- package/dist/services/data/UserService.d.ts +58 -19
- package/dist/services/data/UserService.js +104 -68
- package/dist/services/data/UserService.js.map +1 -1
- package/dist/services/helper/Headers.d.ts +4 -4
- package/dist/services/helper/Headers.js.map +1 -1
- package/dist/services/helper/Parser.d.ts +2 -2
- package/dist/services/helper/Parser.js.map +1 -1
- package/dist/services/helper/extractors/Tweets.d.ts +6 -6
- package/dist/services/helper/extractors/Tweets.js +1 -1
- package/dist/services/helper/extractors/Tweets.js.map +1 -1
- package/dist/services/helper/extractors/Users.d.ts +10 -4
- package/dist/services/helper/extractors/Users.js +54 -2
- package/dist/services/helper/extractors/Users.js.map +1 -1
- package/dist/services/helper/payloads/LoginFlows.d.ts +77 -0
- package/dist/services/helper/payloads/LoginFlows.js +92 -0
- package/dist/services/helper/payloads/LoginFlows.js.map +1 -0
- package/dist/services/helper/urls/Users.d.ts +8 -1
- package/dist/services/helper/urls/Users.js +12 -2
- package/dist/services/helper/urls/Users.js.map +1 -1
- package/dist/services/util/CacheService.d.ts +33 -0
- package/dist/services/util/CacheService.js +96 -0
- package/dist/services/util/CacheService.js.map +1 -0
- package/dist/services/util/FetcherService.d.ts +65 -0
- package/dist/services/util/FetcherService.js +214 -0
- package/dist/services/util/FetcherService.js.map +1 -0
- package/dist/types/Args.d.ts +38 -0
- package/dist/types/Args.js +5 -0
- package/dist/types/Args.js.map +1 -0
- package/dist/types/Authentication.d.ts +17 -2
- package/dist/types/Authentication.js +1 -0
- package/dist/types/Authentication.js.map +1 -1
- package/dist/types/Query.d.ts +80 -0
- package/dist/types/Query.js +3 -0
- package/dist/types/Query.js.map +1 -0
- package/dist/types/Resolvers.d.ts +5 -4
- package/dist/types/Rettiwt.d.ts +16 -0
- package/dist/types/Rettiwt.js +3 -0
- package/dist/types/Rettiwt.js.map +1 -0
- package/dist/types/Service.d.ts +15 -23
- package/dist/types/Service.js +2 -16
- package/dist/types/Service.js.map +1 -1
- package/dist/types/Tweet.d.ts +25 -19
- package/dist/types/Tweet.js +0 -2
- package/dist/types/Tweet.js.map +1 -1
- package/dist/types/User.d.ts +35 -0
- package/dist/types/User.js +3 -0
- package/dist/types/User.js.map +1 -0
- package/dist/types/args/TweetFilter.d.ts +54 -0
- package/dist/types/args/TweetFilter.js +96 -0
- package/dist/types/args/TweetFilter.js.map +1 -0
- package/dist/types/args/TweetListArg.d.ts +10 -0
- package/dist/types/args/TweetListArg.js +42 -0
- package/dist/types/args/TweetListArg.js.map +1 -0
- package/dist/types/args/TweetListArgs.d.ts +20 -0
- package/dist/types/args/TweetListArgs.js +52 -0
- package/dist/types/args/TweetListArgs.js.map +1 -0
- package/dist/types/args/UserListArgs.d.ts +16 -0
- package/dist/types/args/UserListArgs.js +48 -0
- package/dist/types/args/UserListArgs.js.map +1 -0
- package/dist/types/data/TweetFilter.d.ts +49 -0
- package/dist/types/data/TweetFilter.js +63 -0
- package/dist/types/data/TweetFilter.js.map +1 -0
- package/dist/types/interfaces/Args.d.ts +38 -0
- package/dist/types/interfaces/Args.js +5 -0
- package/dist/types/interfaces/Args.js.map +1 -0
- package/dist/types/interfaces/Authentication.d.ts +40 -0
- package/dist/types/interfaces/Authentication.js +5 -0
- package/dist/types/interfaces/Authentication.js.map +1 -0
- package/dist/types/interfaces/Resolvers.d.ts +14 -0
- package/dist/types/interfaces/Resolvers.js +3 -0
- package/dist/types/interfaces/Resolvers.js.map +1 -0
- package/dist/types/interfaces/Rettiwt.d.ts +16 -0
- package/dist/types/interfaces/Rettiwt.js +3 -0
- package/dist/types/interfaces/Rettiwt.js.map +1 -0
- package/dist/types/interfaces/Service.d.ts +13 -0
- package/dist/types/interfaces/Service.js +3 -0
- package/dist/types/interfaces/Service.js.map +1 -0
- package/dist/types/interfaces/Services.d.ts +13 -0
- package/dist/types/interfaces/Services.js +3 -0
- package/dist/types/interfaces/Services.js.map +1 -0
- package/dist/types/interfaces/Tweet.d.ts +46 -0
- package/dist/types/interfaces/Tweet.js +3 -0
- package/dist/types/interfaces/Tweet.js.map +1 -0
- package/dist/types/interfaces/TweetFilter.d.ts +0 -0
- package/dist/types/interfaces/TweetFilter.js +2 -0
- package/dist/types/interfaces/TweetFilter.js.map +1 -0
- package/{src/types/data/User.ts → dist/types/interfaces/User.d.ts} +35 -51
- package/dist/types/interfaces/User.js +3 -0
- package/dist/types/interfaces/User.js.map +1 -0
- package/dist/types/raw/data/tweet/Favouriters.d.ts +164 -0
- package/dist/types/raw/data/tweet/Favouriters.js +3 -0
- package/dist/types/raw/data/tweet/Favouriters.js.map +1 -0
- package/dist/types/raw/data/tweet/Retweeters.d.ts +171 -0
- package/dist/types/raw/data/tweet/Retweeters.js +3 -0
- package/dist/types/raw/data/tweet/Retweeters.js.map +1 -0
- package/dist/types/raw/data/tweet/Tweet.d.ts +746 -0
- package/dist/types/raw/data/tweet/Tweet.js +3 -0
- package/dist/types/raw/data/tweet/Tweet.js.map +1 -0
- package/dist/types/raw/data/tweet/Tweets.d.ts +386 -0
- package/dist/types/raw/data/tweet/Tweets.js +3 -0
- package/dist/types/raw/data/tweet/Tweets.js.map +1 -0
- package/dist/types/raw/data/user/Followers.d.ts +176 -0
- package/dist/types/raw/data/user/Followers.js +3 -0
- package/dist/types/raw/data/user/Followers.js.map +1 -0
- package/dist/types/raw/data/user/Following.d.ts +176 -0
- package/dist/types/raw/data/user/Following.js +3 -0
- package/dist/types/raw/data/user/Following.js.map +1 -0
- package/dist/types/raw/data/user/Likes.d.ts +1059 -0
- package/dist/types/raw/data/user/Likes.js +3 -0
- package/dist/types/raw/data/user/Likes.js.map +1 -0
- package/dist/types/raw/data/user/User.d.ts +117 -0
- package/dist/types/raw/data/user/User.js +3 -0
- package/dist/types/raw/data/user/User.js.map +1 -0
- package/dist/types/raw/query/tweet/Details.d.ts +80 -0
- package/dist/types/raw/query/tweet/Details.js +5 -0
- package/dist/types/raw/query/tweet/Details.js.map +1 -0
- package/dist/types/raw/query/tweet/Engagements.d.ts +29 -0
- package/dist/types/raw/query/tweet/Engagements.js +3 -0
- package/dist/types/raw/query/tweet/Engagements.js.map +1 -0
- package/dist/types/raw/query/tweet/Likes.d.ts +29 -0
- package/dist/types/raw/query/tweet/Likes.js +3 -0
- package/dist/types/raw/query/tweet/Likes.js.map +1 -0
- package/dist/types/raw/query/tweet/Retweets.d.ts +29 -0
- package/dist/types/raw/query/tweet/Retweets.js +3 -0
- package/dist/types/raw/query/tweet/Retweets.js.map +1 -0
- package/dist/types/raw/query/tweet/Search.d.ts +40 -0
- package/dist/types/raw/query/tweet/Search.js +3 -0
- package/dist/types/raw/query/tweet/Search.js.map +1 -0
- package/dist/types/raw/query/tweet/TweetDetails.d.ts +34 -0
- package/dist/types/raw/query/tweet/TweetDetails.js +5 -0
- package/dist/types/raw/query/tweet/TweetDetails.js.map +1 -0
- package/dist/types/raw/query/tweet/TweetLike.d.ts +29 -0
- package/dist/types/raw/query/tweet/TweetLike.js +3 -0
- package/dist/types/raw/query/tweet/TweetLike.js.map +1 -0
- package/dist/types/raw/query/tweet/TweetLikes.d.ts +29 -0
- package/dist/types/raw/query/tweet/TweetLikes.js +3 -0
- package/dist/types/raw/query/tweet/TweetLikes.js.map +1 -0
- package/dist/types/raw/query/tweet/TweetRetweets.d.ts +0 -0
- package/dist/types/raw/query/tweet/TweetRetweets.js +2 -0
- package/dist/types/raw/query/tweet/TweetRetweets.js.map +1 -0
- package/dist/types/raw/query/user/Details.d.ts +34 -0
- package/dist/types/raw/query/user/Details.js +3 -0
- package/dist/types/raw/query/user/Details.js.map +1 -0
- package/dist/types/raw/user/Tweets.d.ts +668 -1584
- package/dist/types/services/args/TweetFilter.d.ts +50 -0
- package/dist/types/services/args/TweetFilter.js +76 -0
- package/dist/types/services/args/TweetFilter.js.map +1 -0
- package/package.json +6 -3
- package/src/enums/Errors.ts +21 -0
- package/src/graphql/enums/Errors.ts +22 -0
- package/src/graphql/queries/RootQuery.ts +11 -4
- package/src/graphql/resolvers/AccountResolver.ts +3 -3
- package/src/graphql/resolvers/ResolverBase.ts +19 -5
- package/src/graphql/resolvers/TweetResolver.ts +26 -17
- package/src/graphql/resolvers/UserResolver.ts +75 -20
- package/src/graphql/types/TweetTypes.ts +2 -2
- package/src/graphql/types/UserTypes.ts +4 -4
- package/src/index.ts +39 -17
- package/src/models/args/TweetFilter.ts +119 -0
- package/src/models/args/TweetListArgs.ts +47 -0
- package/src/models/args/UserListArgs.ts +47 -0
- package/src/models/auth/AuthCookie.ts +43 -0
- package/src/models/data/CursoredData.ts +45 -0
- package/src/models/data/Tweet.ts +118 -0
- package/src/models/data/User.ts +72 -0
- package/src/models/errors/DataValidationError.ts +29 -0
- package/src/server.ts +9 -10
- package/src/services/{accounts → auth}/AccountService.ts +71 -19
- package/src/services/auth/AuthService.ts +81 -0
- package/src/services/data/TweetService.ts +81 -62
- package/src/services/data/UserService.ts +118 -80
- package/src/services/helper/Headers.ts +4 -4
- package/src/services/helper/Parser.ts +2 -2
- package/src/services/helper/extractors/Tweets.ts +7 -7
- package/src/services/helper/extractors/Users.ts +60 -5
- package/src/services/helper/urls/Users.ts +39 -23
- package/src/services/{CacheService.ts → util/CacheService.ts} +4 -1
- package/src/services/{FetcherService.ts → util/FetcherService.ts} +19 -11
- package/src/types/Args.ts +49 -0
- package/src/types/Authentication.ts +29 -7
- package/src/types/Resolvers.ts +5 -4
- package/src/types/Rettiwt.ts +20 -0
- package/src/types/Service.ts +24 -0
- package/src/types/Tweet.ts +61 -0
- package/src/types/User.ts +48 -0
- package/src/types/raw/user/Tweets.ts +1747 -0
- package/tsconfig.json +2 -2
- package/src/services/AuthService.ts +0 -68
- package/src/services/helper/deserializers/Tweets.ts +0 -70
- package/src/services/helper/deserializers/Users.ts +0 -26
- package/src/types/data/Errors.ts +0 -37
- package/src/types/data/Service.ts +0 -55
- package/src/types/data/Tweet.ts +0 -123
- package/src/types/raw/auth/Cookie.ts +0 -16
- /package/src/{types → enums}/HTTP.ts +0 -0
- /package/src/services/{accounts → helper/payloads}/LoginFlows.ts +0 -0
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
import { curly, CurlyResult } from 'node-libcurl';
|
|
3
3
|
|
|
4
4
|
// SERVICES
|
|
5
|
-
import { AuthService } from '
|
|
5
|
+
import { AuthService } from './AuthService';
|
|
6
6
|
|
|
7
7
|
// TYPES
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { IGuestCredentials, IAuthCookie } from '../../types/Authentication';
|
|
9
|
+
|
|
10
|
+
// ENUMS
|
|
11
|
+
import { HttpStatus } from '../../enums/HTTP';
|
|
12
|
+
import { AuthenticationErrors } from '../../enums/Errors';
|
|
11
13
|
|
|
12
14
|
// HELPERS
|
|
13
|
-
import LoginFlows from '
|
|
15
|
+
import LoginFlows from '../helper/payloads/LoginFlows';
|
|
14
16
|
import { loginHeader } from '../helper/Headers';
|
|
15
17
|
import { Cookie, CookieJar } from 'cookiejar';
|
|
16
18
|
|
|
@@ -19,12 +21,11 @@ import { Cookie, CookieJar } from 'cookiejar';
|
|
|
19
21
|
* @public
|
|
20
22
|
*/
|
|
21
23
|
export class AccountService {
|
|
22
|
-
// MEMBER DATA
|
|
23
24
|
/** The AuthService instance to use for authentication. */
|
|
24
25
|
private auth: AuthService;
|
|
25
26
|
|
|
26
27
|
/** The current guest credentials to use. */
|
|
27
|
-
private guestCreds:
|
|
28
|
+
private guestCreds: IGuestCredentials;
|
|
28
29
|
|
|
29
30
|
/** The cookies received from Twitter after logging in. */
|
|
30
31
|
private cookies: Cookie[];
|
|
@@ -32,7 +33,6 @@ export class AccountService {
|
|
|
32
33
|
/** The flow token received after execution of current flow. */
|
|
33
34
|
private flowToken: string;
|
|
34
35
|
|
|
35
|
-
// MEMBER METHODS
|
|
36
36
|
constructor() {
|
|
37
37
|
this.auth = new AuthService();
|
|
38
38
|
this.guestCreds = { authToken: '', guestToken: '' };
|
|
@@ -43,7 +43,7 @@ export class AccountService {
|
|
|
43
43
|
/**
|
|
44
44
|
* @returns The current guest credentials to use. If if does not exists, then a new one is created
|
|
45
45
|
*/
|
|
46
|
-
private async getGuestCredentials(): Promise<
|
|
46
|
+
private async getGuestCredentials(): Promise<IGuestCredentials> {
|
|
47
47
|
// If a guest credential has not been already set, get a new one
|
|
48
48
|
if (!this.guestCreds.guestToken) {
|
|
49
49
|
this.guestCreds = await this.auth.getGuestCredentials();
|
|
@@ -176,15 +176,15 @@ export class AccountService {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
179
|
+
* Execute all the flows required to login to Twitter, using the given credentials, then set the response cookies.
|
|
180
|
+
*
|
|
181
|
+
* @internal
|
|
181
182
|
*
|
|
182
|
-
* @param email The email of the account to be logged into
|
|
183
|
-
* @param userName The username associated with the given account
|
|
184
|
-
* @param password The password to the account
|
|
185
|
-
* @returns The cookies for authenticating with the given account
|
|
183
|
+
* @param email The email of the account to be logged into.
|
|
184
|
+
* @param userName The username associated with the given account.
|
|
185
|
+
* @param password The password to the account.
|
|
186
186
|
*/
|
|
187
|
-
|
|
187
|
+
private async executeLoginFlows(email: string, userName: string, password: string): Promise<void> {
|
|
188
188
|
/**
|
|
189
189
|
* This works by sending a chain of request that are required for login to twitter.
|
|
190
190
|
* Each method in the chain returns a flow token that must be provied as payload in the next method in the chain.
|
|
@@ -197,9 +197,61 @@ export class AccountService {
|
|
|
197
197
|
await this.enterUserIdentifier(email);
|
|
198
198
|
await this.enterAlternateUserIdentifier(userName);
|
|
199
199
|
await this.enterPassword(password);
|
|
200
|
-
await this.accountDuplicationCheck();
|
|
200
|
+
await this.accountDuplicationCheck();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Parse the authentication cookies recieved from Twitter into known format.
|
|
205
|
+
*
|
|
206
|
+
* @internal
|
|
207
|
+
*
|
|
208
|
+
* @param cookies The raw cookies received from Twitter.
|
|
209
|
+
*
|
|
210
|
+
* @returns The parsed cookies of type {@link AuthCookie}
|
|
211
|
+
*/
|
|
212
|
+
private parseCookies(cookies: Cookie[]): IAuthCookie {
|
|
213
|
+
/** The tempoorary parsed cookies. */
|
|
214
|
+
let tempCookies: any = {};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Parsing the cookies into a standard JSON format.
|
|
218
|
+
* The format is 'cookie_name': 'cookie_value'.
|
|
219
|
+
* All other cookie parameters like expiry, etc are dropped.
|
|
220
|
+
*/
|
|
221
|
+
cookies.forEach(cookie => {
|
|
222
|
+
tempCookies[cookie.name] = cookie.value;
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
kdt: tempCookies['kdt'],
|
|
227
|
+
twid: tempCookies['twid'],
|
|
228
|
+
ct0: tempCookies['ct0'],
|
|
229
|
+
auth_token: tempCookies['auth_token']
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Login to Twitter using the given credentials and get back the cookies.
|
|
235
|
+
*
|
|
236
|
+
* @public
|
|
237
|
+
*
|
|
238
|
+
* @param email The email of the account to be logged into.
|
|
239
|
+
* @param userName The username associated with the given account.
|
|
240
|
+
* @param password The password to the account.
|
|
241
|
+
*
|
|
242
|
+
* @returns The cookies for authenticating with the given account.
|
|
243
|
+
*/
|
|
244
|
+
public async login(email: string, userName: string, password: string): Promise<IAuthCookie> {
|
|
245
|
+
/** The parsed cookies that will be returned. */
|
|
246
|
+
let parsedCookies: IAuthCookie;
|
|
247
|
+
|
|
248
|
+
// Executing all login flows
|
|
249
|
+
await this.executeLoginFlows(email, userName, password);
|
|
250
|
+
|
|
251
|
+
// Parsing the cookies
|
|
252
|
+
parsedCookies = this.parseCookies(this.cookies);
|
|
201
253
|
|
|
202
|
-
// Returning the final cookies
|
|
203
|
-
return
|
|
254
|
+
// Returning the final parsed cookies
|
|
255
|
+
return parsedCookies;
|
|
204
256
|
}
|
|
205
257
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// PACKAGE
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
// URLS
|
|
5
|
+
import { guestTokenUrl } from '../helper/urls/Authentication';
|
|
6
|
+
|
|
7
|
+
// MODELS
|
|
8
|
+
import { AuthCookie } from '../../models/auth/AuthCookie';
|
|
9
|
+
|
|
10
|
+
// TYPES
|
|
11
|
+
import { IGuestCredentials, IAuthCredentials } from '../../types/Authentication';
|
|
12
|
+
|
|
13
|
+
// CONFIGS
|
|
14
|
+
import { config } from '../../config/env';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Handles authentication of http requests and other authentication related tasks.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export class AuthService {
|
|
22
|
+
/** The common bearer token for authentication. */
|
|
23
|
+
private authToken: string;
|
|
24
|
+
|
|
25
|
+
/** The current authentication credentials. */
|
|
26
|
+
private credentials: IAuthCredentials;
|
|
27
|
+
|
|
28
|
+
/** Whether instance has been authenticated or not. */
|
|
29
|
+
public isAuthenticated: boolean;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param cookie The cookie to be used for authenticating.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
*
|
|
36
|
+
* If no cookie is supplied, then guest authentication is used.
|
|
37
|
+
*/
|
|
38
|
+
constructor(cookie?: AuthCookie) {
|
|
39
|
+
// Reading the auth token from the config, since it's always the same
|
|
40
|
+
this.authToken = config.twitter_auth_token;
|
|
41
|
+
|
|
42
|
+
// Setting authentication status
|
|
43
|
+
this.isAuthenticated = (cookie?.auth_token && cookie?.ct0 && cookie?.kdt && cookie?.twid) ? true : false;
|
|
44
|
+
|
|
45
|
+
// If a cookies is supplied, initializing authenticated credentials
|
|
46
|
+
if (this.isAuthenticated) {
|
|
47
|
+
// Converting the cookie from JSON to object
|
|
48
|
+
cookie = new AuthCookie(cookie);
|
|
49
|
+
|
|
50
|
+
// Setting up the authenticated credentials
|
|
51
|
+
this.credentials = { authToken: this.authToken, csrfToken: cookie.ct0, cookie: cookie.toString() };
|
|
52
|
+
}
|
|
53
|
+
// If no cookie has been supplied, initializing empty credentials
|
|
54
|
+
else {
|
|
55
|
+
// Setting up the authenticated credentials
|
|
56
|
+
this.credentials = { authToken: this.authToken, csrfToken: '', cookie: '' };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @returns The current authentication credentials. A different credential is returned each time this is invoked
|
|
62
|
+
*/
|
|
63
|
+
async getAuthCredentials(): Promise<IAuthCredentials> {
|
|
64
|
+
return this.credentials;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @returns The guest credentials fetched from twitter.
|
|
69
|
+
*/
|
|
70
|
+
async getGuestCredentials(): Promise<IGuestCredentials> {
|
|
71
|
+
// Getting the guest credentials from twitter
|
|
72
|
+
return await axios.post<{ guest_token: string }>(guestTokenUrl(), null, {
|
|
73
|
+
headers: {
|
|
74
|
+
'Authorization': this.authToken
|
|
75
|
+
}
|
|
76
|
+
}).then(res => ({
|
|
77
|
+
authToken: this.authToken,
|
|
78
|
+
guestToken: res.data.guest_token
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
// SERVICES
|
|
2
|
-
import { FetcherService } from "../FetcherService";
|
|
3
|
-
import { AuthService } from "../AuthService";
|
|
2
|
+
import { FetcherService } from "../util/FetcherService";
|
|
3
|
+
import { AuthService } from "../auth/AuthService";
|
|
4
|
+
|
|
5
|
+
// MODELS
|
|
6
|
+
import { Tweet } from "../../models/data/Tweet";
|
|
7
|
+
import { User } from "../../models/data/User";
|
|
8
|
+
import { TweetListArgs } from "../../models/args/TweetListArgs";
|
|
9
|
+
import { TweetFilter } from "../../models/args/TweetFilter";
|
|
10
|
+
import { CursoredData } from '../../models/data/CursoredData';
|
|
4
11
|
|
|
5
12
|
// TYPES
|
|
6
|
-
import { TweetFilter, Tweet } from "../../types/data/Tweet";
|
|
7
|
-
import { User } from "../../types/data/User";
|
|
8
|
-
import { CursoredData } from '../../types/data/Service';
|
|
9
13
|
import RawTweet, { Result as TweetData } from '../../types/raw/tweet/Tweet';
|
|
10
14
|
import { Result as UserData } from "../../types/raw/user/User";
|
|
11
15
|
import RawTweets from '../../types/raw/tweet/Tweets';
|
|
12
16
|
import RawLikers from '../../types/raw/tweet/Favouriters';
|
|
13
17
|
import RawRetweeters from '../../types/raw/tweet/Retweeters';
|
|
14
|
-
|
|
18
|
+
|
|
19
|
+
// ENUMS
|
|
20
|
+
import { AuthenticationErrors } from '../../enums/Errors';
|
|
15
21
|
|
|
16
22
|
// URLS
|
|
17
23
|
import * as TweetUrls from '../helper/urls/Tweets';
|
|
@@ -19,10 +25,6 @@ import * as TweetUrls from '../helper/urls/Tweets';
|
|
|
19
25
|
// EXTRACTORS
|
|
20
26
|
import * as TweetExtractors from "../helper/extractors/Tweets";
|
|
21
27
|
|
|
22
|
-
// DESERIALIZERS
|
|
23
|
-
import * as UserDeserializers from '../helper/deserializers/Users';
|
|
24
|
-
import * as TweetDeserializers from '../helper/deserializers/Tweets';
|
|
25
|
-
|
|
26
28
|
// PARSERS
|
|
27
29
|
import { toQueryString } from '../helper/Parser';
|
|
28
30
|
|
|
@@ -31,7 +33,6 @@ import { toQueryString } from '../helper/Parser';
|
|
|
31
33
|
* @public
|
|
32
34
|
*/
|
|
33
35
|
export class TweetService extends FetcherService {
|
|
34
|
-
// MEMBER METHODS
|
|
35
36
|
/**
|
|
36
37
|
* @param auth The AuthService instance to use for authentication.
|
|
37
38
|
*/
|
|
@@ -41,19 +42,24 @@ export class TweetService extends FetcherService {
|
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* @param filter The filter be used for searching the tweets.
|
|
44
|
-
* @param count The number of tweets to fetch
|
|
45
|
+
* @param count The number of tweets to fetch, must be >= 10 and <= 20
|
|
45
46
|
* @param cursor The cursor to the next batch of tweets. If blank, first batch is fetched.
|
|
47
|
+
*
|
|
46
48
|
* @returns The list of tweets that match the given filter.
|
|
47
|
-
*
|
|
49
|
+
*
|
|
50
|
+
* @throws {@link Errors.ValidationErrors.InvalidCount} error, if an invalid count has been provided.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
*
|
|
54
|
+
* Cookies are required to use this method!
|
|
48
55
|
*/
|
|
49
|
-
async getTweets(
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
56
|
+
async getTweets(query: TweetFilter, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
57
|
+
// Objectifying parameters
|
|
58
|
+
let filter: TweetFilter = new TweetFilter(query);
|
|
59
|
+
let args: TweetListArgs = new TweetListArgs(count, cursor);
|
|
54
60
|
|
|
55
61
|
// Getting the raw data
|
|
56
|
-
let res = await this.request<RawTweets>(TweetUrls.tweetsUrl(toQueryString(filter), count, cursor),
|
|
62
|
+
let res = await this.request<RawTweets>(TweetUrls.tweetsUrl(toQueryString(filter), args.count, args.cursor), this.isAuthenticated).then(res => res.data);
|
|
57
63
|
|
|
58
64
|
// Extracting data
|
|
59
65
|
let data = TweetExtractors.extractTweets(res);
|
|
@@ -62,62 +68,75 @@ export class TweetService extends FetcherService {
|
|
|
62
68
|
this.cacheData(data);
|
|
63
69
|
|
|
64
70
|
// Parsing data
|
|
65
|
-
let tweets = data.required.map((item: TweetData) =>
|
|
71
|
+
let tweets = data.required.map((item: TweetData) => new Tweet(item));
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
// Sorting the tweets by date, from recent to oldest
|
|
74
|
+
tweets.sort((a, b) => new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf());
|
|
75
|
+
|
|
76
|
+
return new CursoredData<Tweet>(tweets, data.cursor);
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
/**
|
|
74
|
-
* @param
|
|
80
|
+
* @param id The id of the target tweet.
|
|
81
|
+
*
|
|
75
82
|
* @returns The details of a single tweet with the given tweet id.
|
|
83
|
+
*
|
|
84
|
+
* @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
*
|
|
88
|
+
* No cookies are required to use this method.
|
|
76
89
|
*/
|
|
77
|
-
async
|
|
90
|
+
async getTweetDetails(id: string): Promise<Tweet> {
|
|
78
91
|
// Getting data from cache
|
|
79
|
-
let cachedData = await this.readData(
|
|
92
|
+
let cachedData = await this.readData(id);
|
|
80
93
|
|
|
81
94
|
// If data exists in cache
|
|
82
95
|
if (cachedData) {
|
|
83
96
|
return cachedData;
|
|
84
97
|
}
|
|
85
|
-
|
|
98
|
+
|
|
86
99
|
// Fetching the raw data
|
|
87
|
-
let res = await this.request<RawTweet>(TweetUrls.tweetDetailsUrl(
|
|
100
|
+
let res = await this.request<RawTweet>(TweetUrls.tweetDetailsUrl(id), false).then(res => res.data);
|
|
88
101
|
|
|
89
102
|
// Extracting data
|
|
90
|
-
let data = TweetExtractors.extractTweet(res,
|
|
103
|
+
let data = TweetExtractors.extractTweet(res, id);
|
|
91
104
|
|
|
92
105
|
// Caching data
|
|
93
106
|
this.cacheData(data);
|
|
94
107
|
|
|
95
108
|
// Parsing data
|
|
96
|
-
let tweet =
|
|
109
|
+
let tweet = new Tweet(data.required[0]);
|
|
97
110
|
|
|
98
111
|
return tweet;
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
/**
|
|
102
115
|
* @param tweetId The rest id of the target tweet.
|
|
103
|
-
* @param count The batch size of the list.
|
|
116
|
+
* @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 20.
|
|
104
117
|
* @param cursor The cursor to the next batch of users. If blank, first batch is fetched.
|
|
118
|
+
*
|
|
105
119
|
* @returns The list of users who liked the given tweet.
|
|
106
|
-
*
|
|
120
|
+
*
|
|
121
|
+
* @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
|
|
122
|
+
* @throws {@link Errors.ValidationErrors.InvalidCount} error, if invalid count is provided.
|
|
123
|
+
* @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
*
|
|
127
|
+
* Cookies are required to use this method!
|
|
107
128
|
*/
|
|
108
|
-
async getTweetLikers(tweetId: string, count
|
|
129
|
+
async getTweetLikers(tweetId: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
109
130
|
// If user is not authenticated, abort
|
|
110
|
-
if(!this.isAuthenticated) {
|
|
111
|
-
throw new Error(
|
|
131
|
+
if (!this.isAuthenticated) {
|
|
132
|
+
throw new Error(AuthenticationErrors.NotAuthenticated);
|
|
112
133
|
}
|
|
113
134
|
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
135
|
+
// Objectifying parameters
|
|
136
|
+
let args: TweetListArgs = new TweetListArgs(count, cursor);
|
|
137
|
+
|
|
119
138
|
// Fetching the raw data
|
|
120
|
-
let res = await this.request<RawLikers>(TweetUrls.tweetLikesUrl(tweetId, count, cursor)).then(res => res.data);
|
|
139
|
+
let res = await this.request<RawLikers>(TweetUrls.tweetLikesUrl(tweetId, args.count, args.cursor)).then(res => res.data);
|
|
121
140
|
|
|
122
141
|
// Extracting data
|
|
123
142
|
let data = TweetExtractors.extractTweetLikers(res);
|
|
@@ -126,34 +145,37 @@ export class TweetService extends FetcherService {
|
|
|
126
145
|
this.cacheData(data);
|
|
127
146
|
|
|
128
147
|
// Parsing data
|
|
129
|
-
let users = data.required.map((item: UserData) =>
|
|
148
|
+
let users = data.required.map((item: UserData) => new User(item));
|
|
130
149
|
|
|
131
|
-
return
|
|
132
|
-
list: users,
|
|
133
|
-
next: { value: data.cursor }
|
|
134
|
-
};
|
|
150
|
+
return new CursoredData<User>(users, data.cursor);
|
|
135
151
|
}
|
|
136
152
|
|
|
137
153
|
/**
|
|
138
154
|
* @param tweetId The rest id of the target tweet.
|
|
139
|
-
* @param count The batch size of the list.
|
|
155
|
+
* @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 100.
|
|
140
156
|
* @param cursor The cursor to the next batch of users. If blank, first batch is fetched.
|
|
157
|
+
*
|
|
141
158
|
* @returns The list of users who retweeted the given tweet.
|
|
142
|
-
*
|
|
159
|
+
*
|
|
160
|
+
* @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
|
|
161
|
+
* @throws {@link Errors.ValidationErrors.InvalidCount} error, if invalid count is provided.
|
|
162
|
+
* @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
*
|
|
166
|
+
* Cookies are required to use this method!
|
|
143
167
|
*/
|
|
144
|
-
async getTweetRetweeters(tweetId: string, count
|
|
168
|
+
async getTweetRetweeters(tweetId: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
145
169
|
// If user is not authenticated, abort
|
|
146
|
-
if(!this.isAuthenticated) {
|
|
147
|
-
throw new Error(
|
|
170
|
+
if (!this.isAuthenticated) {
|
|
171
|
+
throw new Error(AuthenticationErrors.NotAuthenticated);
|
|
148
172
|
}
|
|
149
173
|
|
|
150
|
-
//
|
|
151
|
-
|
|
152
|
-
throw new Error(Errors.ValidationErrors.InvalidCount);
|
|
153
|
-
}
|
|
174
|
+
// Objectifying parameters
|
|
175
|
+
let args: TweetListArgs = new TweetListArgs(count, cursor);
|
|
154
176
|
|
|
155
177
|
// Fetching the raw data
|
|
156
|
-
let res = await this.request<RawRetweeters>(TweetUrls.tweetRetweetUrl(tweetId, count, cursor)).then(res => res.data);
|
|
178
|
+
let res = await this.request<RawRetweeters>(TweetUrls.tweetRetweetUrl(tweetId, args.count, args.cursor)).then(res => res.data);
|
|
157
179
|
|
|
158
180
|
// Extracting data
|
|
159
181
|
let data = TweetExtractors.extractTweetRetweeters(res);
|
|
@@ -162,12 +184,9 @@ export class TweetService extends FetcherService {
|
|
|
162
184
|
this.cacheData(data);
|
|
163
185
|
|
|
164
186
|
// Parsing data
|
|
165
|
-
let users = data.required.map((item: UserData) =>
|
|
187
|
+
let users = data.required.map((item: UserData) => new User(item));
|
|
166
188
|
|
|
167
|
-
return
|
|
168
|
-
list: users,
|
|
169
|
-
next: { value: data.cursor }
|
|
170
|
-
};
|
|
189
|
+
return new CursoredData<User>(users, data.cursor);
|
|
171
190
|
}
|
|
172
191
|
|
|
173
192
|
/**
|